<?xml version="1.0" encoding="utf-8"?>
<posts>
  <row Id="1" PostTypeId="1" CreationDate="2015-08-04T18:05:05.010" Score="8" ViewCount="250" Body="&lt;p&gt;I saw a &lt;a href=&quot;https://www.youtube.com/watch?v=7YWTtCsvgvg&quot; rel=&quot;noreferrer&quot;&gt;video&lt;/a&gt; on YouTube where a person uses a transparant, knotted pyramid to display &quot;holograms&quot; using their smartphone. (I have not been able to reproduce this yet, so I can't tell for sure if it works).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering, given a model, which transformations I should apply to get the different projections needed to produce this effect?&lt;/p&gt;&#xA;" OwnerUserId="21" LastEditorUserId="30" LastEditDate="2015-08-08T11:28:35.067" LastActivityDate="2018-09-19T04:14:12.783" Title="What transformations should I apply to a model to produce this 3D effect?" Tags="&lt;projections&gt;&lt;transformations&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2" PostTypeId="1" AcceptedAnswerId="11" CreationDate="2015-08-04T18:10:11.117" Score="11" ViewCount="693" Body="&lt;p&gt;The convention in graphics is that performing fewer state changes is better than performing more state changes (switching shaders, binding buffers, binding textures, etc.). For textures, it is faster to render many polygons using a single atlas (for rendering sprites/text) than to individually bind a new texture for each polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this hold true if I am continually painting to a texture via &lt;code&gt;glTexSubImage2D&lt;/code&gt;? I have a stream of data coming in (over a network) that undergoes processing and is then painted to a texture one row at a time. The data is presented visually in an endless scroll.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would I be better off painting to one texture rendered on one large rectangle (scrolling the painted data into view)? The idea here is that I would have one (or two) textures bound at any given time while I just continue to paint to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or should I paint lots of little rectangles (only revealing the rectangle when painting is done)? I assume I would bind one texture per rectangle.&lt;/p&gt;&#xA;" OwnerUserId="36" LastEditorUserId="36" LastEditDate="2015-08-04T18:21:59.540" LastActivityDate="2015-08-04T19:19:15.453" Title="Is modifying a texture (painting on it) considered a &quot;state change&quot;?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3" PostTypeId="1" AcceptedAnswerId="10" CreationDate="2015-08-04T18:13:47.903" Score="20" ViewCount="3162" Body="&lt;p&gt;Sometimes I use vector graphics, simply because they look just &lt;em&gt;slightly&lt;/em&gt; nicer in some cases, and other times, I use bitmap/raster graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering, are there any significant performance differences between these two options?&lt;/p&gt;&#xA;" OwnerUserId="17" LastEditorUserId="17" LastEditDate="2016-04-25T15:46:40.090" LastActivityDate="2016-04-25T15:46:40.090" Title="Performance of vector graphics versus bitmap or raster graphics" Tags="&lt;texture&gt;&lt;bitmap-graphics&gt;&lt;vector-graphics&gt;&lt;performance&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4" PostTypeId="1" AcceptedAnswerId="29" CreationDate="2015-08-04T18:15:49.023" Score="11" ViewCount="596" Body="&lt;p&gt;I just implemented some interpolated texture sampling by sampling the 4x4 nearest pixels then doing Lagrange interpolation across the x axis to get four values to use Lagrange interpolation on across the y axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this the same as bicubic interpolation or is it different?  Or are there different kinds of bicubic interpolation, and this is just one of them perhaps?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Webgl Shadertoy implementation here and relevant GLSL (WebGL) code below: &lt;a href=&quot;https://www.shadertoy.com/view/MllSzX&quot; rel=&quot;nofollow&quot;&gt;https://www.shadertoy.com/view/MllSzX&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;float c_textureSize = 64.0;&#xA;&#xA;float c_onePixel = 1.0 / c_textureSize;&#xA;float c_twoPixels = 2.0 / c_textureSize;&#xA;&#xA;float c_x0 = -1.0;&#xA;float c_x1 =  0.0;&#xA;float c_x2 =  1.0;&#xA;float c_x3 =  2.0;&#xA;&#xA;//=======================================================================================&#xA;vec3 CubicLagrange (vec3 A, vec3 B, vec3 C, vec3 D, float t)&#xA;{&#xA;    return&#xA;        A * &#xA;        (&#xA;            (t - c_x1) / (c_x0 - c_x1) * &#xA;            (t - c_x2) / (c_x0 - c_x2) *&#xA;            (t - c_x3) / (c_x0 - c_x3)&#xA;        ) +&#xA;        B * &#xA;        (&#xA;            (t - c_x0) / (c_x1 - c_x0) * &#xA;            (t - c_x2) / (c_x1 - c_x2) *&#xA;            (t - c_x3) / (c_x1 - c_x3)&#xA;        ) +&#xA;        C * &#xA;        (&#xA;            (t - c_x0) / (c_x2 - c_x0) * &#xA;            (t - c_x1) / (c_x2 - c_x1) *&#xA;            (t - c_x3) / (c_x2 - c_x3)&#xA;        ) +       &#xA;        D * &#xA;        (&#xA;            (t - c_x0) / (c_x3 - c_x0) * &#xA;            (t - c_x1) / (c_x3 - c_x1) *&#xA;            (t - c_x2) / (c_x3 - c_x2)&#xA;        );&#xA;}&#xA;&#xA;//=======================================================================================&#xA;vec3 BicubicTextureSample (vec2 P)&#xA;{&#xA;    vec2 pixel = P * c_textureSize + 0.5;&#xA;&#xA;    vec2 frac = fract(pixel);&#xA;    pixel = floor(pixel) / c_textureSize - vec2(c_onePixel/2.0);&#xA;&#xA;    vec3 C00 = texture2D(iChannel0, pixel + vec2(-c_onePixel ,-c_onePixel)).rgb;&#xA;    vec3 C10 = texture2D(iChannel0, pixel + vec2( 0.0        ,-c_onePixel)).rgb;&#xA;    vec3 C20 = texture2D(iChannel0, pixel + vec2( c_onePixel ,-c_onePixel)).rgb;&#xA;    vec3 C30 = texture2D(iChannel0, pixel + vec2( c_twoPixels,-c_onePixel)).rgb;&#xA;&#xA;    vec3 C01 = texture2D(iChannel0, pixel + vec2(-c_onePixel , 0.0)).rgb;&#xA;    vec3 C11 = texture2D(iChannel0, pixel + vec2( 0.0        , 0.0)).rgb;&#xA;    vec3 C21 = texture2D(iChannel0, pixel + vec2( c_onePixel , 0.0)).rgb;&#xA;    vec3 C31 = texture2D(iChannel0, pixel + vec2( c_twoPixels, 0.0)).rgb;    &#xA;&#xA;    vec3 C02 = texture2D(iChannel0, pixel + vec2(-c_onePixel , c_onePixel)).rgb;&#xA;    vec3 C12 = texture2D(iChannel0, pixel + vec2( 0.0        , c_onePixel)).rgb;&#xA;    vec3 C22 = texture2D(iChannel0, pixel + vec2( c_onePixel , c_onePixel)).rgb;&#xA;    vec3 C32 = texture2D(iChannel0, pixel + vec2( c_twoPixels, c_onePixel)).rgb;    &#xA;&#xA;    vec3 C03 = texture2D(iChannel0, pixel + vec2(-c_onePixel , c_twoPixels)).rgb;&#xA;    vec3 C13 = texture2D(iChannel0, pixel + vec2( 0.0        , c_twoPixels)).rgb;&#xA;    vec3 C23 = texture2D(iChannel0, pixel + vec2( c_onePixel , c_twoPixels)).rgb;&#xA;    vec3 C33 = texture2D(iChannel0, pixel + vec2( c_twoPixels, c_twoPixels)).rgb;    &#xA;&#xA;    vec3 CP0X = CubicLagrange(C00, C10, C20, C30, frac.x);&#xA;    vec3 CP1X = CubicLagrange(C01, C11, C21, C31, frac.x);&#xA;    vec3 CP2X = CubicLagrange(C02, C12, C22, C32, frac.x);&#xA;    vec3 CP3X = CubicLagrange(C03, C13, C23, C33, frac.x);&#xA;&#xA;    return CubicLagrange(CP0X, CP1X, CP2X, CP3X, frac.y);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="56" LastEditorUserId="231" LastEditDate="2015-08-10T05:07:39.443" LastActivityDate="2015-08-10T10:40:04.633" Title="Is a cubic Lagrange interpolation tensor product the same as bicubic interpolation?" Tags="&lt;texture&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5" PostTypeId="1" AcceptedAnswerId="87" CreationDate="2015-08-04T18:25:11.677" Score="11" ViewCount="674" Body="&lt;p&gt;I have an OpenGL application which uses stencil tests quite extensively to render irregular shapes (a bit like a simple 2-D &lt;a href=&quot;https://en.wikipedia.org/wiki/Constructive_solid_geometry&quot;&gt;CSG&lt;/a&gt;). If I could find out how many fragments passed the stencil test and were actually rendered, this would be very helpful in simplifying some computations down the line. Specifically, it would allow me to determine the area of the rendered shape for free instead of having to approximate it with a Monte Carlo simulation later on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that there is a similar concept for primitives emitted from the geometry shader, called &lt;a href=&quot;https://www.opengl.org/wiki/Transform_Feedback&quot;&gt;transform feedback&lt;/a&gt;. I'd like to know if a similar concept exists for fragments and the stencil test.&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2015-08-07T09:06:45.063" Title="Is it possible to find out how many fragments made it through the stencil test?" Tags="&lt;opengl&gt;&lt;stencil-test&gt;" AnswerCount="2" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6" PostTypeId="1" AcceptedAnswerId="18" CreationDate="2015-08-04T18:31:07.350" Score="34" ViewCount="12520" Body="&lt;p&gt;I've heard that the quality of a monte carlo ray tracer (based on path tracing algorithms) is much more realistic than a distributed (stochastic) engine. I try to understand why, but I'm just at the beginning. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to dive into this topic and understand the basics, can someone point me into the right direction? What part of the algorithm leads into a more realistic render result? &lt;/p&gt;&#xA;" OwnerUserId="18" LastEditorUserId="18" LastEditDate="2015-08-11T09:22:47.723" LastActivityDate="2019-12-06T11:36:49.733" Title="Why does monte carlo ray tracing perform better than distributed ray tracing?" Tags="&lt;raytracing&gt;&lt;algorithm&gt;&lt;monte-carlo&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="8" PostTypeId="2" ParentId="3" CreationDate="2015-08-04T18:37:00.853" Score="8" Body="&lt;p&gt;There might be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Less technical answer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're building a website or another application where you have nothing to do with the graphics programming then the answer is probably yes. The underlying APIs will try to guess how to render them and cache them efficiently. However, as your application runs and the API sometimes guesses incorrectly it may have to re-render things and affect performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More technical:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that unless you're using one of the newest GPUs and a library for drawing the vector paths on the GPU then it's all bitmap textures being rendered by the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll consider the typical case where vector graphics are rendered to textures. Here the performance would depend on your toolchain, whether your application is dynamically creating textures from the vector assets, and whether the graphics are viewed at various zoom levels. There are two issues involved: resources and texture generation. If you're only displaying the graphics at a static size then I would say there is no difference and perhaps your toolchain can convert the assets into bitmap graphics before runtime. However, if they are being displayed in various sizes or in a 3D world then you'll need mip mapped textures which take more memory. They'll take a lot of memory if you really want to see their fidelity 'up close' with a larger texture. Having your application dynamically create the larger textures only when necessary will save memory but is costly at runtime and will affect performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps.&lt;/p&gt;&#xA;" OwnerUserId="59" LastActivityDate="2015-08-04T18:37:00.853" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="9" PostTypeId="1" AcceptedAnswerId="14" CreationDate="2015-08-04T18:39:29.303" Score="17" ViewCount="1878" Body="&lt;p&gt;A few years ago I tried to implement &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems3/gpugems3_ch01.html&quot;&gt;this GPU Gem&lt;/a&gt; in OpenGL to generate 3D procedural terrain using &lt;a href=&quot;https://en.wikipedia.org/wiki/Marching_cubes&quot;&gt;Marching Cubes&lt;/a&gt;. The article suggests to implement Marching Cubes in a geometry shader to maximum efficiency. This means I need to run the shader once for every voxel in the domain, and it'll generate the entire geometry in that cell.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One problem I stumbled upon was how to get the geometry shader running without actually having anything to render outside of that shader. My solution (which seemed rather hacky) was to render a point in each cell, discard it with the geometry shader and emit my triangles instead. I never found a proper solution and this workaround remained in the final code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is there anyway to tell OpenGL to start a rendering pass from the geometry shader without any input geometry? Or will I always have to send some dummy points to the GPU to get things running.&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2015-08-04T19:20:23.330" Title="Is there any way to generate primitives in a geometry shader without any input geometry?" Tags="&lt;opengl&gt;&lt;geometry-shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="10" PostTypeId="2" ParentId="3" CreationDate="2015-08-04T18:40:58.597" Score="15" Body="&lt;p&gt;As TheBuzzSaw said, it does depend on lots of things, including implementations of the rasterized graphics vs the vector graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some high performance vector graphics methods that are rendered using traditionally rasterization methods.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Loop and Blinn show how to render a vector graphics quadratic bezier curve by rendering a single triangle, and using the texture coordinates in a pixel shader to say whether a pixel is above or below the curve:&#xA;&lt;a href=&quot;http://www.msr-waypoint.net/en-us/um/people/cloop/LoopBlinn05.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://www.msr-waypoint.net/en-us/um/people/cloop/LoopBlinn05.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic idea is that you set your triangle corner positions to be the 3 control point positions, and you set the texture coordinates at each corner to be (0,0), (0.5,0) and (1,1) respectively.  In your shader, if the interpolated texture coordinate (x*x-y) is &amp;lt; 0, the pixel is underneath the curve, else it's above the curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see a faux implementation of it on shadertoy here:&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/4tj3Dy&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/4tj3Dy&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the second method, here's a method from Valve, where distances to a shape are stored in a texture, instead of pixel data, allowing vector graphics to be drawn by using texture sampling.  The decoding is so simple, it could be implemented even on fixed function hardware using only an alpha test!&#xA;&lt;a href=&quot;http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To give you an idea of how well the second technique works, this 1024x768 mustache image was generated from a 64x32 source image that had a single color channel! (aka 2KB uncompressed)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wlC0y.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wlC0y.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also wrote some stuff about it on my blog:&#xA;&lt;a href=&quot;http://blog.demofox.org/2014/06/30/distance-field-textures/&quot; rel=&quot;noreferrer&quot;&gt;http://blog.demofox.org/2014/06/30/distance-field-textures/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is some sample OpenCL code to show just how simple it is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float alpha = read_imagef(tex3dIn, g_textureSampler, textureCoords).w;&#xA;float3 color = (alpha &amp;lt; 0.5f) ? (float3)(1.0f) : (float3)(0.0f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Both of these techniques are super fast, and blur the line between vector and rasterized graphics a bit.  They are rendered using rasterization techniques, but have zooming / scaling properties like vector graphics techniques.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-08-04T18:58:30.893" LastActivityDate="2015-08-04T18:58:30.893" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="11" PostTypeId="2" ParentId="2" CreationDate="2015-08-04T18:44:21.417" Score="11" Body="&lt;p&gt;Updating an area of memory in the graphics device (a texture, buffer, and the like) is not quite the same as changing a rendering state. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What makes a render state change expensive is the amount of work the driver has to do to validate the new state(s) and reorder the pipeline. This will most likely also incur some synchronization between CPU and graphics device. However, the amount of data transferred between the devices should be small for a state change (probably just a few commands).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a texture/buffer update on the other hand, the main cost lies in the data transfer itself. In theory, unless you're reading the texture data back to the CPU after the update, there should be no synchronization or pipeline stalls. However, another aspect should be considered: API overhead. Even if the amount of data you're sending to the graphics device is small, if you do that often enough, eventually the cost of communicating with the driver/device will become greater then the cost of the data transfer. That's another reason why batching is so important when optimizing a renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in your case, the best approach, it seems to me, would be to keep a system-memory copy of the texture that you update whenever new data arrives. Set a dirty flag and consolidate as much updates as possible into one &lt;code&gt;glTexSubImage&lt;/code&gt; for the whole texture (or a large sequential portion of it). You can also play with &lt;a href=&quot;https://www.opengl.org/wiki/Pixel_Buffer_Object&quot;&gt;Pixel Buffer Objects&lt;/a&gt; and try to do asynchronous data transfer to reduce pipeline stalls as much as possible. If you can implement some kind of double buffering, then you can write to one copy of the texture while the other is being rendered with. &lt;a href=&quot;http://www.songho.ca/opengl/gl_pbo.html#unpack&quot;&gt;This tutorial&lt;/a&gt; explores that scenario. That's my intuitive approach, I'd try to reduce the number of API calls and &quot;batch&quot; the texture updates. That being said, this is very speculative, and you'd have to profile and compare that to other approaches, like doing several small updates, to know for sure which is the most performant in your usage case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a side note, this presentation by NVidia is also relevant and provides a lot of good insights: &lt;a href=&quot;http://gdcvault.com/play/1020791/&quot;&gt;Approaching Zero Driver Overhead in OpenGL&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="54" LastEditDate="2015-08-04T19:19:15.453" LastActivityDate="2015-08-04T19:19:15.453" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="12" PostTypeId="1" AcceptedAnswerId="21" CreationDate="2015-08-04T18:50:16.343" Score="28" ViewCount="14930" Body="&lt;p&gt;Wikipedia &lt;a href=&quot;https://en.wikipedia.org/wiki/Stencil_buffer&quot;&gt;states&lt;/a&gt; that a stencil buffer is some arbitrary buffer a shader can use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, it hints that it's used for clipping, or otherwise &quot;tightly binding&quot; the depth and pixel buffers, slightly contradicting itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does the stencil buffer &lt;em&gt;really&lt;/em&gt; do, and how is it practically used in modern applications?&lt;/p&gt;&#xA;" OwnerUserId="71" LastActivityDate="2018-03-04T19:56:47.600" Title="What is a stencil buffer?" Tags="&lt;stencil-buffer&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="13" PostTypeId="2" ParentId="6" CreationDate="2015-08-04T18:57:38.277" Score="6" Body="&lt;p&gt;In &lt;strong&gt;Distributed ray tracing&lt;/strong&gt;, You stochastically sample many rays in directions which &lt;em&gt;may or may not&lt;/em&gt; be preferred by the BRDF. Whereas, in &lt;strong&gt;Monte Carlo ray tracing&lt;/strong&gt; or simply path tracing, you sample only one ray &lt;em&gt;in a direction preferred by the BRDF&lt;/em&gt;. So, there are two obvious advantages Path Tracing would have:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Computationally less expensive. Which means with the same computing power you have the freedom of calculating over more object hits as compared to distributed ray tracing where there are multiple rays.&lt;/li&gt;&#xA;&lt;li&gt;Less noise. Distributed ray tracing samples rays in directions that might not be preferred by the BRDF, therefore introducing unwanted artifacts. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And so, path tracing would give you better results.&lt;/p&gt;&#xA;" OwnerUserId="77" LastActivityDate="2015-08-04T18:57:38.277" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="14" PostTypeId="2" ParentId="9" CreationDate="2015-08-04T18:58:03.393" Score="16" Body="&lt;p&gt;No, there is not really a way to do that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A geometry shader invocation requires an input primitive and generates 0 or more output primitives. &lt;strong&gt;Without an input primitive, there is not really a way to actually &lt;em&gt;invoke&lt;/em&gt; the geometry shader&lt;/strong&gt;. Of course you can stretch the limits of the geometry shader's maximum number of output primitives for each input primitive (don't know the practical limits right now, should be on the order of thousands maybe). So you maybe could generate 1024 triangles for each point, but you always have to have &lt;em&gt;some&lt;/em&gt; input primitives.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you &lt;em&gt;don't need&lt;/em&gt; however is an actual notion of geometry. You don't really have to render 3D points at any reasonable location, they could as well have just some abstract index or texture coordinates or whatever as attributes and not necessarily a meaningful 3D position. &lt;strong&gt;Noone dictates what attributes your vertices have. And you can even render vertices &lt;em&gt;without any&lt;/em&gt; attributes&lt;/strong&gt;. But you have to render &lt;em&gt;some&lt;/em&gt; primitives to invoke the geometry shader on them, even if those primitives don't have any actual attributes (how you then compute your output geometry in the geometry shader is a different question, though).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what you actually did, rendering a point for each grid cell and generating the marching cubes triangles for that cell from it, is exactly the straight-forward approach. Of course what attributes this cell contains is up to you, it could be a 3D position, a texcoord into a 3D texture, whatever, but those are the grid cells you render. Purely semantically spoken, you don't actually &quot;discard&quot; those points and then &quot;replace&quot; them by triangles, you &quot;convert&quot; each point into a set of triangles. That's exactly what the geometry shader is for and there's nothing &quot;hacky&quot; or &quot;improper&quot; about it. &lt;strong&gt;Noone says the geometry shader has to generate the same output primitive type as was input to be &quot;proper&quot;&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;What you can do to achieve a largely input-less way of rendering your voxel grid (and this might be what you were actually asking for) would be to just draw a set of attributeless points. This means you don't need any attribute arrays at all and just disable them all and invoke a simple &lt;code&gt;glDrawArrays&lt;/code&gt; with the number of cells you need. Then in the vertex shader or the geometry shader you can generate the necessary 3D grid cell index with a little index magic from the input vertex ID (i.e. &lt;code&gt;gl_VertexID&lt;/code&gt;, which is the only information you have) and then compute your marching cubes geometry from a lookup into the 3D volume texture (or whatever datastructure).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, in retrospect I should relativate my statement from the beginning: &lt;strong&gt;You can't generate primitives without any input &lt;em&gt;primitives&lt;/em&gt;, but you can generate them without any input &lt;em&gt;geometry&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2015-08-04T19:20:23.330" LastActivityDate="2015-08-04T19:20:23.330" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="15" PostTypeId="1" AcceptedAnswerId="1508" CreationDate="2015-08-04T18:58:36.040" Score="17" ViewCount="409" Body="&lt;p&gt;In 1978 Edwin Catmull and Jim Clark defined the recursive subdivision process that bears their names, and although those principles are applicable still today, what advances have occurred as far as optimization and accuracy?&lt;/p&gt;&#xA;" OwnerUserId="70" LastActivityDate="2015-09-16T06:05:56.157" Title="What subdivision algorithm advances have occurred since Catmull-Clark?" Tags="&lt;subdivision&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="16" PostTypeId="2" ParentId="12" CreationDate="2015-08-04T19:18:52.277" Score="6" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;A stencil buffer contains per-pixel integer data which is used to add&#xA;  more control over which pixels are rendered.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;A stencil buffer operates similarly to a depth buffer. So similarly,&#xA;  that stencil data is stored in a depth buffer. While depth data&#xA;  determines which pixel is closest to the camera, stencil data can be&#xA;  used as a more general purpose per-pixel mask for saving or discarding&#xA;  pixels. To create the mask, use a stencil function to compare a&#xA;  reference stencil value -- a global value -- to the value in the&#xA;  stencil buffer each time a pixel is rendered.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Source: &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/bb976074.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;What Is a Stencil Buffer? | Microsoft Developer Network&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The general idea is that you can set a value for each pixel and then set the operation (&lt;code&gt;GREATER&lt;/code&gt;, &lt;code&gt;SMALLER&lt;/code&gt;, &lt;code&gt;EQUAL&lt;/code&gt; etc), when this evaluates to true the pixel is shaded and shown.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One application is realtime reflection, when rendering the reflection texture the stencil buffer is used to create a mask for where the reflection is applied. For example only apply the reflection to the glass material shaded triangles. It can also be used to create arbitrary two dimensional masks for the whole framebuffer.&lt;/p&gt;&#xA;" OwnerUserId="64" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:56:47.600" LastActivityDate="2018-03-04T19:56:47.600" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="18" PostTypeId="2" ParentId="6" CreationDate="2015-08-04T19:33:04.573" Score="37" Body="&lt;p&gt;The term &quot;distributed ray tracing&quot; was originally coined by Robert Cook in &lt;a href=&quot;http://artis.inrialpes.fr/Enseignement/TRSA/CookDistributed84.pdf&quot;&gt;this 1984 paper&lt;/a&gt;. His observation was that in order to perform anti-aliasing in a ray-tracer, the renderer needs to perform spatial upsampling - that is, to take more samples (i.e. shoot more rays) than the number of pixels in the image and combine their results. One way to do this is to shoot multiple rays within a pixel and average their color values, for example. However, if the renderer is already tracing multiple rays per pixel anyway to obtain an anti-aliased image, then these rays can also be &quot;distributed&quot; among additional dimensions than just the pixel position to sample effects that could not be captured by a single ray. The important bit is that this comes without any additional cost on top of spatial upsampling, since you're already tracing those additional rays anyway. For example, if you shoot multiple rays within your pixel to compute an anti-aliased result, you can get motion blur absolutely for free if you also use a different time value for each ray (or soft shadows if they connect to a different point on the light source, or depth of field if they use a different starting point on the aperture, etc.).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Monte Carlo ray tracing is a term that is slightly ambiguous. In most cases, it refers to rendering techniques that solve the &lt;a href=&quot;http://www.dca.fee.unicamp.br/~leopini/DISCIPLINAS/IA725/ia725-12010/kajiya-SIG86-p143.pdf&quot;&gt;rendering equation&lt;/a&gt;, introduced by Jim Kajiya in 1986, using Monte Carlo integration. Practically all modern rendering techniques that solve the rendering equation, such as path tracing, bidirectional path tracing, progressive photon mapping and VCM, can be classified as Monte Carlo ray tracing techniques. The idea of Monte Carlo integration is that we can compute the integral of any function by randomly choosing points in the integration domain and averaging the value of the function at these points. At a high level, in Monte Carlo ray tracing we can use this technique to integrate the amount of light arriving at the camera within a pixel in order to compute the pixel value. For example, a path tracer does this by randomly picking a point within the pixel to shoot the first ray, and then continues to randomly pick a direction to continue on the surface it lands on, and so forth. We could also randomly pick a position on the time axis if we want to do motion blur, or randomly pick a point on the aperture if wanted to do depth of field, or...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this sounds very similar to distributed ray tracing, that's because it is! We can think of distributed ray tracing as a very informal description of a Monte Carlo algorithm that samples certain effects like soft shadows. Cook's paper lacks the mathematical framework to really reason about it properly, but you could certainly implement distributed ray tracing using a simple Monte Carlo renderer. It's worth noting that distributed ray tracing lacks any description of global illumination effects, which are naturally modeled in the rendering equation (it should be mentioned that Kajiya's paper was published two years after Cook's paper).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can think of Monte Carlo ray tracing as being a more general version of distributed ray tracing. Monte Carlo ray tracing contains a general mathematical framework that allows you to handle practically any effect, including those mentioned in the distributed ray tracing paper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These days, &quot;distributed ray tracing&quot; is not really a term that's used to refer to the original algorithm. More often you will hear it in conjunction with &quot;distribution effects&quot;, which are simply effects such as motion blur, depth of field or soft shadows that cannot be handled with a single-sample raytracer.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-04T19:33:04.573" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="19" PostTypeId="1" AcceptedAnswerId="26" CreationDate="2015-08-04T19:40:54.970" Score="29" ViewCount="2984" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Perlin_noise&quot;&gt;Perlin noise&lt;/a&gt; is one of the most popular procedural noise functions. Perlin later developed &lt;a href=&quot;https://en.wikipedia.org/wiki/Simplex_noise&quot;&gt;Simplex noise&lt;/a&gt; which improves on some of the shortcomings of Perlin noise, notably its inefficiency in higher dimensions and directional artefacts (Wikipedia lists five advantages of Simplex noise). Still, Perlin noise appears to be widely used. I can imagine that the main reason is that Simplex noise is conceptually much more difficult to understand, but by now there should be enough implementations so that you don't have to re-implement it yourself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does Perlin noise have any advantages over Simplex noise? When picking a noise function, would I ever choose Perlin instead of Simplex?&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2015-08-04T21:35:01.103" Title="Does the original Perlin noise ever have any advantage over Simplex noise?" Tags="&lt;noise&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="20" PostTypeId="2" ParentId="12" CreationDate="2015-08-04T19:44:03.353" Score="13" Body="&lt;p&gt;The stencil buffer is an unsigned integer buffer, usually 8-bit nowadays, where you can fill per-pixel infomation as you wish based on the use of various operations (&lt;a href=&quot;https://www.opengl.org/wiki/Stencil_Test#Stencil_operations&quot;&gt;OpenGL Ops here for example&lt;/a&gt;) following a stencil test. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stencil test is simply a per-pixel operation in which the current pixel stencil value is tested against the content of the stencil buffer. You set the condition to which the stencil test is passed ( e.g. ALWAYS, LESS etc. ). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can decide what happens to the stencil value depending on the outcome of the test (in OpenGL using the operation I linked you above) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stencil buffer has quite a few uses, the first ones that come to mind being:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It can be used as a mask to selectively render certain part of the framebuffer and discard the rest. This, for example, is useful for reflections, but also lots more. When dealing with multiple resolution rendering it can be used to mark up edges that need to be rendered at an higher res. There are plenty of masking usages really. &lt;/li&gt;&#xA;&lt;li&gt;A very simple overdraw filter for example. You can set the stencil test to always pass and always increment the value. The value you end up with in the stencil buffer represents your overdraw. [*] &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;In the past it has been used also for shadowing techniques such as Shadow volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The poor stencil buffer is often quite underestimated, but can be a good weapon in a graphics programmer's armory. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;[*] Value to be read back in a post-process using the right SRV! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: &#xA;Also, worth mentioning that in Shader Model 5.1 (so D3D11.3 and D3D12) you have access to the stencil reference value via &lt;code&gt;SV_StencilRef&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-08-04T20:21:59.477" LastActivityDate="2015-08-04T20:21:59.477" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="21" PostTypeId="2" ParentId="12" CreationDate="2015-08-04T19:45:33.780" Score="36" Body="&lt;p&gt;The stencil buffer definition by Wikipedia is indeed not great, it focuses too much on the details of modern implementations (OpenGL). I find &lt;a href=&quot;https://en.wikipedia.org/wiki/Stencil_(disambiguation)&quot; rel=&quot;noreferrer&quot;&gt;the disambiguated version&lt;/a&gt; easier to understand:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A stencil is a template used to draw or paint identical letters, symbols, shapes, or patterns every time it is used. The design produced by such a template is also called a stencil.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That's what stencil meant before Computer Graphics. If you type &lt;em&gt;stencil&lt;/em&gt; on Google Images, this is one of the first results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bHD7z.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bHD7z.jpg&quot; alt=&quot;Stencil mask&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, it is simply a mask or pattern that can be used to &quot;paint&quot; the negative of the pattern onto something.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;em&gt;stencil buffer&lt;/em&gt; works in the exact same way. One can fill the stencil buffer with a selected pattern by doing a stencil render pass, then set the appropriate stencil function which will define how the pattern is to be interpreted on subsequent drawings, then render the final scene. Pixels that fall into the rejected areas of the stencil mask, according to the compare function, are not drawn.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;When it comes to implementing the stencil buffer, sometimes it is indeed coupled with the depth buffer. Most graphics hardware uses a 1 byte (8 bits) stencil buffer, which is enough for most applications. Depth buffers are usually implemented using 3 bytes (24 bits), which again is normally enough for most kinds of 3D rendering. So it is only logical to pack the 8 bits of the stencil buffer with the other 24 of the depth buffer, making it possible to store each depth + stencil pixel into a 32 bit integer. That's what Wikipedia meant by:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The depth buffer and stencil buffer often share the same area in the RAM of the graphics hardware.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;One application in which the stencil buffer used to be king was for shadow rendering, in a technique called &lt;a href=&quot;https://en.wikipedia.org/wiki/Shadow_volume&quot; rel=&quot;noreferrer&quot;&gt;&lt;em&gt;shadow volumes&lt;/em&gt;&lt;/a&gt;, or sometimes also appropriately called &lt;em&gt;stencil shadows&lt;/em&gt;. This was a very clever use of the buffer, but nowadays most of the rendering field seems to have shifted towards depth-based shadow maps.&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="231" LastEditDate="2015-08-09T17:31:32.827" LastActivityDate="2015-08-09T17:31:32.827" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="22" PostTypeId="2" ParentId="3" CreationDate="2015-08-04T19:48:16.840" Score="6" Body="&lt;p&gt;There are a few ways of rendering vector graphics. As TheBuzzSaw mentions, NVIDIA has an extension that can render general paths quite quickly (but of course it only works on NVIDIA GPUs). And Alan Wolfe mentions the implicit surface methods (Loop-Blinn/distance fields), which define a function which says whether you're inside or outside a shape, and color the pixels based on that function.  Another method is stencil-and-cover, where you render the path into a stencil buffer and use the even-odd count to determine whether the path covers a pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, however, the tradeoff is that rendering raster will be faster, but is more susceptible to aliasing (even distance fields break down at low and high scales). Rendering paths requires a lot of setup but in theory can be scaled to any resolution.&lt;/p&gt;&#xA;" OwnerUserId="1" LastActivityDate="2015-08-04T19:48:16.840" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="23" PostTypeId="1" AcceptedAnswerId="25" CreationDate="2015-08-04T20:05:43.820" Score="17" ViewCount="5219" Body="&lt;p&gt;I have a point cloud that is being rendered to the screen. Each point has its position and color as well as an ID.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was asked to render the IDs for each point to a texture so I created a FBO and attached two textures, one for color and one for depth. I created the necessary VAO and VBO for this off-screen rendering and uploaded for each point its position and ID.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once the rendering to the FBO is done, I read the pixels of the color-texture with &lt;code&gt;glReadPixels()&lt;/code&gt; to see what the values are, but they seem to be all cleared out, i.e., the value they have is the same as &lt;code&gt;glClearColor()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way I can debug what it is being render to the color texture of my FBO? Any tips that you may provide are very welcomed.&lt;/p&gt;&#xA;" OwnerUserId="116" LastEditorUserId="16" LastEditDate="2015-08-07T15:58:52.093" LastActivityDate="2015-08-07T15:58:52.093" Title="How can I debug what is being rendered to a Frame Buffer Object in OpenGL?" Tags="&lt;opengl&gt;&lt;debugging&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="24" PostTypeId="2" ParentId="1" CreationDate="2015-08-04T20:08:24.347" Score="5" Body="&lt;p&gt;Assuming your optimal viewing angle is parallel to the surface of the display and the pyramid is made from faces that are 45 degrees to its virtual (non-existant) base, it's actually just a simple non-transformed image (besides the reflection).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1:1 projection. No transformations. No scaling. &lt;/p&gt;&#xA;" OwnerUserId="20" LastActivityDate="2015-08-04T20:08:24.347" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="25" PostTypeId="2" ParentId="23" CreationDate="2015-08-04T20:15:17.410" Score="21" Body="&lt;p&gt;Generally to see what is being rendered in the various steps of your pipeline I'd suggest the use of a tool for frame analysis. These usually provide you with a view on the content of each buffer for each API call and this can help you in your situation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A very good one is &lt;a href=&quot;https://github.com/baldurk/renderdoc&quot;&gt;Renderdoc&lt;/a&gt; which is both completely free and opensource. Also it is actively supported. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another one is &lt;a href=&quot;https://software.intel.com/en-us/gpa/details&quot;&gt;Intel GPA&lt;/a&gt; that unfortunately, according to its webpage, support up to OGL 3.3 Core. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just for the sake of adding one more, I used to use &lt;a href=&quot;http://www.gremedy.com/&quot;&gt;gDEBugger&lt;/a&gt;, but it has passed long since the last update. This has evolved into &lt;a href=&quot;http://developer.amd.com/tools-and-sdks/opencl-zone/codexl/&quot;&gt;AMD CodeXL&lt;/a&gt; that unfortunately I never used.&lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-08-04T21:18:32.987" LastActivityDate="2015-08-04T21:18:32.987" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="26" PostTypeId="2" ParentId="19" CreationDate="2015-08-04T21:35:01.103" Score="27" Body="&lt;p&gt;To directly answer the question: Simplex noise is &lt;a href=&quot;https://www.google.com/patents/US6867776&quot;&gt;patented&lt;/a&gt;, whereas Perlin noise is not. Other than that, Simplex noise has many advantages that are already mentioned in your question, and apart from the slightly increased implementation difficulty, it is the better algorithm of the two.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe the reason why many people still pick Perlin noise is simply because it's more widely known. It's also worth noting that Perlin noise is very frequently confused with a combination of &lt;a href=&quot;https://en.wikipedia.org/wiki/Value_noise&quot;&gt;value noise&lt;/a&gt; and Fractal Brownian Motion (FBM).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perlin noise, Simplex noise and value noise are all methods for synthesizing coherent noise. On the other hand, FBM (sometimes called &quot;FBM noise&quot;), is what is used when adding multiple layers of noise on top of each other at different scales to obtain more complex functions. The combination of FBM and value noise is simple to implement and can be very useful for terrain synthesis, procedural clouds and friends, and it is quite popular. However, it tends to be mistakenly labelled Perlin noise, misleadingly adding to its popularity.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-04T21:35:01.103" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="27" PostTypeId="1" CreationDate="2015-08-04T21:47:25.783" Score="21" ViewCount="845" Body="&lt;p&gt;Both Vulkan and DirectX12 are claimed to be usable in a thread-safe manner. People seem to be excited about that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is this considered such a huge feature? The &quot;real&quot; processing gets thrown over the memory bridge on a separate processing unit anyway. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also if it is so big, why is it not until now that a thread safe Graphics API came out?&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2018-06-20T09:11:58.230" LastActivityDate="2018-06-20T09:11:58.230" Title="Why is thread safety such a huge deal for Graphics APIs?" Tags="&lt;vulkan&gt;&lt;directx12&gt;&lt;multithreading&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="28" PostTypeId="2" ParentId="27" CreationDate="2015-08-04T22:20:07.923" Score="13" Body="&lt;p&gt;The main gain would be that it would be easier to divide CPU tasks into multiple threads, without having to solve all the difficult issues with accessing the graphics API. Normally you either would have to make the context current (which might have bad performance implications) or provide a queue and call the graphics api in a single thread. I don't think that any performance is gained this way, because the GPU indeed processes them sequentially anyway, but it makes the developer job a lot easier.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason that it was not done until now probably is because directx and opengl were created in a time where multithreading was not really apparent. Also the Khronos board is very conservative in changing the API. Their view on Vulkan is also that it will coexist next to OpenGL, because both serve different purposes. It probably was not until recently that paralism became so important, as consumers get access to more and more processors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: I don't mean that no performance is gained from doing work in multiple CPUs, it is not useful to split your calls into multiple threads to create textures/shaders faster. Rather the performance is gained due to having more processors busy and keeping the gpu busy with things to perform.&lt;/p&gt;&#xA;" OwnerUserId="64" LastEditorUserId="64" LastEditDate="2015-08-04T22:29:59.053" LastActivityDate="2015-08-04T22:29:59.053" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="29" PostTypeId="2" ParentId="4" CreationDate="2015-08-04T23:00:18.923" Score="8" Body="&lt;p&gt;It turns out that no, while you can use bicubic Lagrange interpolation for bicubic texture sampling, it isn't the highest quality option, and probably not actually likely to be used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cubic hermite splines are a better tool for the job.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lagrange interpolation will make a curve that passes through the data points, thus preserving C0 continuity, but hermite splines preserve the derivatives at the edges while also passing through the data points, thus preserving C1 continuity and looking much better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This question has some great info on cubic hermite splines:&#xA;&lt;a href=&quot;https://dsp.stackexchange.com/questions/18265/bicubic-interpolation&quot;&gt;https://dsp.stackexchange.com/questions/18265/bicubic-interpolation&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the cubic hermite version of the code I posted in the question:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;//=======================================================================================&#xA;vec3 CubicHermite (vec3 A, vec3 B, vec3 C, vec3 D, float t)&#xA;{&#xA;    float t2 = t*t;&#xA;    float t3 = t*t*t;&#xA;    vec3 a = -A/2.0 + (3.0*B)/2.0 - (3.0*C)/2.0 + D/2.0;&#xA;    vec3 b = A - (5.0*B)/2.0 + 2.0*C - D / 2.0;&#xA;    vec3 c = -A/2.0 + C/2.0;&#xA;    vec3 d = B;&#xA;&#xA;    return a*t3 + b*t2 + c*t + d;&#xA;}&#xA;&#xA;//=======================================================================================&#xA;vec3 BicubicHermiteTextureSample (vec2 P)&#xA;{&#xA;    vec2 pixel = P * c_textureSize + 0.5;&#xA;&#xA;    vec2 frac = fract(pixel);&#xA;    pixel = floor(pixel) / c_textureSize - vec2(c_onePixel/2.0);&#xA;&#xA;    vec3 C00 = texture2D(iChannel0, pixel + vec2(-c_onePixel ,-c_onePixel)).rgb;&#xA;    vec3 C10 = texture2D(iChannel0, pixel + vec2( 0.0        ,-c_onePixel)).rgb;&#xA;    vec3 C20 = texture2D(iChannel0, pixel + vec2( c_onePixel ,-c_onePixel)).rgb;&#xA;    vec3 C30 = texture2D(iChannel0, pixel + vec2( c_twoPixels,-c_onePixel)).rgb;&#xA;&#xA;    vec3 C01 = texture2D(iChannel0, pixel + vec2(-c_onePixel , 0.0)).rgb;&#xA;    vec3 C11 = texture2D(iChannel0, pixel + vec2( 0.0        , 0.0)).rgb;&#xA;    vec3 C21 = texture2D(iChannel0, pixel + vec2( c_onePixel , 0.0)).rgb;&#xA;    vec3 C31 = texture2D(iChannel0, pixel + vec2( c_twoPixels, 0.0)).rgb;    &#xA;&#xA;    vec3 C02 = texture2D(iChannel0, pixel + vec2(-c_onePixel , c_onePixel)).rgb;&#xA;    vec3 C12 = texture2D(iChannel0, pixel + vec2( 0.0        , c_onePixel)).rgb;&#xA;    vec3 C22 = texture2D(iChannel0, pixel + vec2( c_onePixel , c_onePixel)).rgb;&#xA;    vec3 C32 = texture2D(iChannel0, pixel + vec2( c_twoPixels, c_onePixel)).rgb;    &#xA;&#xA;    vec3 C03 = texture2D(iChannel0, pixel + vec2(-c_onePixel , c_twoPixels)).rgb;&#xA;    vec3 C13 = texture2D(iChannel0, pixel + vec2( 0.0        , c_twoPixels)).rgb;&#xA;    vec3 C23 = texture2D(iChannel0, pixel + vec2( c_onePixel , c_twoPixels)).rgb;&#xA;    vec3 C33 = texture2D(iChannel0, pixel + vec2( c_twoPixels, c_twoPixels)).rgb;    &#xA;&#xA;    vec3 CP0X = CubicHermite(C00, C10, C20, C30, frac.x);&#xA;    vec3 CP1X = CubicHermite(C01, C11, C21, C31, frac.x);&#xA;    vec3 CP2X = CubicHermite(C02, C12, C22, C32, frac.x);&#xA;    vec3 CP3X = CubicHermite(C03, C13, C23, C33, frac.x);&#xA;&#xA;    return CubicHermite(CP0X, CP1X, CP2X, CP3X, frac.y);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is a picture showing the difference between sampling methods.  From left to right: Nearest Neighbor, Bilinear, Lagrange Bicubic, Hermite Bicubic&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/h0Ot0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/h0Ot0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-04-13T12:47:29.743" LastActivityDate="2015-08-10T10:40:04.633" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="30" PostTypeId="2" ParentId="23" CreationDate="2015-08-04T23:43:22.107" Score="7" Body="&lt;p&gt;In addition to cifz's response, another way to visualise FBOs which doesn't cost very much code is to use glBlitFramebuffer() to transfer pixels from a framebuffer to a window.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// XXX WARNING: Untested code follows&#xA;&#xA;// Blit from fbo...&#xA;glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);&#xA;// ...to the front buffer.&#xA;glBindFramebuffer(GL_WRITE_FRAMEBUFFER, GL_FRONT);&#xA;&#xA;GLsizei HalfWindowWidth = (GLsizei)(WindowWidth / 2.0f);&#xA;GLsizei HalfWindowHeight = (GLsizei)(WindowHeight / 2.0f);&#xA;&#xA;// Blit attachment 0 to the lower-left quadrant of the window&#xA;glReadBuffer(GL_COLOR_ATTACHMENT0);&#xA;glBlitFramebuffer(0, 0, FboWidth, FboHeight,&#xA;                  0, 0, HalfWindowWidth, HalfWindowHeight,&#xA;                  GL_COLOR_BUFFER_BIT, GL_LINEAR);&#xA;&#xA;// Blit attachment 1 to the lower-right quadrant of the window&#xA;glReadBuffer(GL_COLOR_ATTACHMENT1);&#xA;glBlitFramebuffer(0, 0, FboWidth, FboHeight,&#xA;                  HalfWindowWidth, 0, WindowWidth, HalfWindowHeight,&#xA;                  GL_COLOR_BUFFER_BIT, GL_LINEAR);&#xA;&#xA;// ...and so on. You can switch FBOs if you have more than one to read from.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There are a few obvious &quot;gotchas&quot;, in that HDR buffers probably won't visualise the way you expect them to, you probably can't &quot;see&quot; depth/stencil buffers in the obvious way, and if the size of the FBO doesn't match the area being blitted to, the magnification/minification method might be extremely naive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But as quick 'n dirty hacks go, it's pretty good.&lt;/p&gt;&#xA;" OwnerUserId="159" LastEditorUserId="159" LastEditDate="2015-08-05T00:26:44.483" LastActivityDate="2015-08-05T00:26:44.483" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="31" PostTypeId="1" AcceptedAnswerId="48" CreationDate="2015-08-05T00:01:57.733" Score="10" ViewCount="241" Body="&lt;p&gt;There are 2 main factors that seem to lead to &lt;a href=&quot;https://en.wikipedia.org/wiki/Digital_artifact&quot; rel=&quot;noreferrer&quot;&gt;digital artifacts&lt;/a&gt; when creating JPEG images: Aliasing and Compression.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Converting a PNG with characters on it to a JPEG or placing vector images over a photograph, will result in pixelization on their edges. The antialiasing generally creates a kind of blur around them, but if the image is &lt;a href=&quot;https://en.wikipedia.org/wiki/Lossy_compression&quot; rel=&quot;noreferrer&quot;&gt;lossy compressed&lt;/a&gt;, part of the details are also lost, therefore the blur and the pixelization may become less noticeable.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Is this the right thing to do? I.e. since a lossless compression generates a highly detailed image, the artifacts resulting from aliasing will be more noticeable, so a balance may be found by using the right compression, although compromising the image quality.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Edit&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I just saved this JPEG in mspaint (3.46KB):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uPlhy.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uPlhy.jpg&quot; alt=&quot;Lossless&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the same JPEG with maximum compression (lowest quality, 0.5KB):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5HPZJ.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5HPZJ.jpg&quot; alt=&quot;Lossy&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's yet the same JPEG with 50% compression (notice the difference in size, 1.29KB):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kS88V.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kS88V.jpg&quot; alt=&quot;Half-no-options&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same 50% compression but saved as &quot;progressive JPG&quot;, kept the original EXIF and XMP data, and &quot;tried to save with original JPG quality&quot; (you can notice that there are no grey pixels around, 2.96KB):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/i5A7q.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/i5A7q.jpg&quot; alt=&quot;Half-options&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally the same as before with &lt;strong&gt;chroma subsampling disabled&lt;/strong&gt; (same file size, 2.96KB):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V8FMk.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V8FMk.jpg&quot; alt=&quot;Half-no-chroma&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="157" LastEditDate="2015-08-05T10:55:35.593" LastActivityDate="2015-08-05T10:55:35.593" Title="When creating a JPEG, how can I minimize the occurence of artifacts?" Tags="&lt;image&gt;&lt;compression&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="32" PostTypeId="1" AcceptedAnswerId="33" CreationDate="2015-08-05T01:13:26.897" Score="10" ViewCount="2037" Body="&lt;p&gt;From my basic understanding, a Vertex Buffer Object works something like this (pseudo code):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normally, if one wanted to say, draw a square, one could issue line drawing commands.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;line (0, 0) -&amp;gt; (1, 0)&#xA;line (1, 0) -&amp;gt; (1, 1)&#xA;line (1, 1) -&amp;gt; (0, 1)&#xA;line (0, 1) -&amp;gt; (0, 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Using a VBO, if I understand correctly, would load the vertices into a VBO.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;define VBO&#xA;load (0,0) -&amp;gt; VBO&#xA;load (1,0) -&amp;gt; VBO&#xA;load (1,1) -&amp;gt; VBO&#xA;load (0,1) -&amp;gt; VBO&#xA;load (0,0) -&amp;gt; VBO&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then you can issue one drawing command.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;draw VBO vertices&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;While I understand how VBOs work, I don't know why they improve performance. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do they improve performance?&lt;/p&gt;&#xA;" OwnerUserId="17" LastEditorUserId="231" LastEditDate="2016-05-28T15:15:22.093" LastActivityDate="2016-05-28T15:15:22.093" Title="Why do Vertex Buffer Objects improve performance?" Tags="&lt;performance&gt;&lt;rendering&gt;&lt;vertex-buffer-object&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="33" PostTypeId="2" ParentId="32" CreationDate="2015-08-05T01:34:47.203" Score="11" Body="&lt;p&gt;In general, when you render an object in an immediate mode—issuing line drawing commands for instance—you build up a series of commands that you submit to the graphics card to draw. If you're drawing a lot of data, or drawing very frequently, you can waste a lot of time sending this data over and over again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A vertex buffer allows you to produce a single object that you submit to the graphics card once. If you don't need to change your geometry, you can leave it on the graphics card and simply send the graphics card a request to draw that object. Since it avoids the copy every time you draw, there's much less overhead for each draw.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that using a vertex buffer object doesn't always provide a very significant speedup. If you're only drawing the object once per frame, and you're replacing the geometry in between each frame, then you don't get the benefits of avoiding the copy each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of my experience comes from writing programs using graphics APIs like OpenGL, so someone who's messed with the backend of a graphics driver can probably provide a more detailed answer, but I hope this makes things a bit clearer.&lt;/p&gt;&#xA;" OwnerUserId="174" LastActivityDate="2015-08-05T01:34:47.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="34" PostTypeId="2" ParentId="32" CreationDate="2015-08-05T01:36:09.247" Score="6" Body="&lt;p&gt;By using an immediate mode interface (e.g. old style OpenGL glBegin()/glEnd()/glVertex()) you're effectively drip feeding data to the driver one piece at a time. It then has to take that single piece of data, reformat it and pass it on to the hardware (which these days means putting it into a command buffer).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By using a vertex buffer object, you're providing a (hopefully) large block of data to the driver ahead of when it needs to be used. It can perform a number of optimizations (reformatting, placing into video memory) as well as not having to feed the GPU piecemeal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice if you're only drawing a small number of primitives then it probably won't make much difference, however if you're drawing a multi-million triangle mesh then VBOs in video memory are the way to go.&lt;/p&gt;&#xA;" OwnerUserId="144" LastActivityDate="2015-08-05T01:36:09.247" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="35" PostTypeId="2" ParentId="5" CreationDate="2015-08-05T02:23:49.107" Score="2" Body="&lt;p&gt;If what you are interested in is the area, you could downsize the stencil buffer until you reach one pixel and deduce that area from its color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Steps would be:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Copy the stencil to a texture, using a format with enough precision.&lt;/li&gt;&#xA;&lt;li&gt;Load a shader that outputs a color proportional to the number of texels with a given color.&lt;/li&gt;&#xA;&lt;li&gt;Ping-pong between to framebuffers to reduce the size by half until reaching one pixel.&lt;/li&gt;&#xA;&lt;li&gt;The color of the pixel is the percentage of the viewport covered by the area: just multiply it by the area of the viewport.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="182" LastActivityDate="2015-08-05T02:23:49.107" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="36" PostTypeId="2" ParentId="32" CreationDate="2015-08-05T02:55:44.850" Score="10" Body="&lt;p&gt;There are two steps that make the VBO more efficient than immediate mode.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Immediate mode&lt;/strong&gt; (&lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml&quot; rel=&quot;nofollow&quot;&gt;glBegin/glEnd&lt;/a&gt;, &lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glVertex.xml&quot; rel=&quot;nofollow&quot;&gt;glVertex*&lt;/a&gt;, etc.) means that at each frame, you spoon feed the vertices, attribute per attribute (position, normal, color, etc.), to the driver, which then reformats them and finally sends the whole package as a command to the GPU. That a lot of function calls per vertex on each frame.&lt;br/&gt;&#xA;(Note that &lt;a href=&quot;https://www.opengl.org/wiki/History_of_OpenGL#Deprecation_Model&quot; rel=&quot;nofollow&quot;&gt;immediate mode is deprecated since OpenGL 3.0&lt;/a&gt;, and is entirely &lt;a href=&quot;https://www.opengl.org/registry/doc/glspec32.core.20091207.pdf&quot; rel=&quot;nofollow&quot;&gt;removed from 3.2&lt;/a&gt;.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;By using &lt;strong&gt;vertex arrays&lt;/strong&gt; (see &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glDrawArrays.xhtml&quot; rel=&quot;nofollow&quot;&gt;glDrawArrays&lt;/a&gt;, &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glDrawElements.xhtml&quot; rel=&quot;nofollow&quot;&gt;glDrawElements&lt;/a&gt;, &lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glVertexPointer.xml&quot; rel=&quot;nofollow&quot;&gt;glVertexPointer&lt;/a&gt;, etc.), you can give the driver the whole thing at once and save it the burden of reformatting the vertices. You're effectively replacing several function calls per vertex by just a handful of calls for the whole mesh. But you still need to do that once a frame.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Specification#Vertex_Buffer_Object&quot; rel=&quot;nofollow&quot;&gt;Vertex Buffer Object&lt;/a&gt;&lt;/strong&gt;, or &lt;strong&gt;VBO&lt;/strong&gt; (see &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glGenBuffers.xhtml&quot; rel=&quot;nofollow&quot;&gt;glGenBuffers&lt;/a&gt;, &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glBindBuffer.xhtml&quot; rel=&quot;nofollow&quot;&gt;glBindBuffer&lt;/a&gt;, etc.) go one step further and store the data on the GPU side: you send it only once, and then just refer to it by a handle. You save bandwidth by not sending the same data over and over at each frame.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-04-08T05:37:52.483" LastActivityDate="2016-04-08T05:37:52.483" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="37" PostTypeId="1" AcceptedAnswerId="46" CreationDate="2015-08-05T03:23:24.500" Score="29" ViewCount="8923" Body="&lt;p&gt;Programmers are supposed to have a fairly good idea of the cost of certain operations: for example the cost of an instruction on CPU, the cost of a L1, L2, or L3 cache miss, the cost of a LHS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it comes to graphics, I realize I have little to no idea what they are. I have in mind that if we order them by cost, state changes are something like:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Shader uniform change.&lt;/li&gt;&#xA;&lt;li&gt;Active vertex buffer change.&lt;/li&gt;&#xA;&lt;li&gt;Active texture unit change.&lt;/li&gt;&#xA;&lt;li&gt;Active shader program change.&lt;/li&gt;&#xA;&lt;li&gt;Active frame buffer change.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;But that is a very rough rule of thumb, it might not even be correct, and I have no idea what are the orders of magnitude. If we try to put units, ns, clock cycles or number of instructions, how much are we talking about?&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="17" LastEditDate="2015-08-05T03:51:09.420" LastActivityDate="2015-08-05T06:06:19.940" Title="What is the cost of changing state?" Tags="&lt;performance&gt;&lt;gpu&gt;&lt;optimisation&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="15" ContentLicense="CC BY-SA 3.0" />
  <row Id="38" PostTypeId="1" AcceptedAnswerId="78" CreationDate="2015-08-05T03:41:52.363" Score="18" ViewCount="904" Body="&lt;p&gt;Tiled rendering is used in modern mobile GPU architectures to increase the coherency of memory access by subdividing image space into a regular grid of small (e.g., 32x32 pixel) tiles. Information is scarce on the types of data structures used to track the primitives that are associated with each tile, considering that arbitrarily many primitives may overlap any given tile. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the perspective of a driver developer, what data structures are commonly used to represent the primitive sets that belong to a tile, and are such structures dynamically allocated/resized according to the geometry that overlaps a particular tile?&lt;/p&gt;&#xA;" OwnerUserId="104" LastActivityDate="2015-08-05T22:23:19.080" Title="Data structures for tile-based (deferred) rendering" Tags="&lt;tile-based-rendering&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="39" PostTypeId="1" AcceptedAnswerId="41" CreationDate="2015-08-05T03:58:22.973" Score="46" ViewCount="61692" Body="&lt;p&gt;I've read that blur is done in real time graphics by doing it on one axis and then the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've done a bit of convolution in 1D in the past but I am not super comfortable with it, nor know what to convolve in this case exactly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain in plain terms how a 2D Gaussian Blur of an image is done?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also heard that the radius of the Blur can impact the performance. Is that due to having to do a larger convolution?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="6" LastEditDate="2017-10-28T19:17:23.423" LastActivityDate="2017-10-28T19:17:23.423" Title="How is Gaussian Blur Implemented?" Tags="&lt;image-processing&gt;&lt;gaussian-blur&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="33" ContentLicense="CC BY-SA 3.0" />
  <row Id="40" PostTypeId="2" ParentId="39" CreationDate="2015-08-05T04:32:27.193" Score="14" Body="&lt;p&gt;In general, a convolution is performed by taking the integral of the product of two functions in a sliding window, but if you're not from a math background, that's not a very helpful explanation, and certainly won't give you a useful intuition for it. More intuitively, a convolution allows multiple points in an input signal to affect a single point on an output signal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you're not super comfortable with convolutions, let's first review  what a convolution means in a discrete context like this, and then go over a simpler blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In our discrete context, we can multiply our two signals by simply multiplying each corresponding sample. The integral is also simple to do discretely, we just add up each sample in the interval we're integrating over. One simple discrete convolution is computing a moving average. If you want to take the moving average of 10 samples, this can be thought of as convolving your signal by a distribution 10 samples long and 0.1 tall, each sample in the window first gets multiplied by 0.1, then all 10 are added together to produce the average. This also reveals an interesting and important distinction, when you're blurring with a convolution, the distribution that you use should sum to 1.0 over all its samples, otherwise it will increase or decrease the overall brightness of the image when you apply it. If the distribution for our average had been 1 over its whole interval, then the total signal would be 10x brighter after the convolution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that we've looked at convolutions, we can move on to blurs. A Gaussian blur is implemented by convolving an image by a Gaussian distribution. Other blurs are generally implemented by convolving the image by other distributions. The simplest blur is the box blur, and it uses the same distribution we described above, a box with unit area. If we want to blur a 10x10 area, then we multiply each sample in the box by 0.01, and then sum them all together to produce the center pixel. We still need to ensure that the total sum of all the samples in our blur distribution are 1.0 to make sure the image doesn't get brighter or darker.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A Gaussian blur follows the same broad procedure as a box blur, but it uses a more complex formula to determine the weights. The distribution can be computed based on the distance from the center &lt;code&gt;r&lt;/code&gt;, by evaluating $$\frac{e^{-x^2/2}}{\sqrt{2\pi}}$$ The sum of all the samples in a Gaussian will eventually be approximately 1.0 if you sample every single pixel, but the fact that a Gaussian has infinite support (it has values everywhere) means that you need to use a slightly modified version that sums to 1.0 using only a few values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course both of these processes can be very expensive if you perform them on a very large radius, since you need to sample a lot of pixels in order to compute the blur. This is where the final trick comes in: both a Gaussian blur and a box blur are what's called a &quot;separable&quot; blur. This means that if you perform the blur along one axis, and then perform it along the other axis, it produces the exact same result as if you'd performed it along both axes at the same time. This can be tremendously important. If your blur is 10px across, it requires 100 samples in the naive form, but only 20 when separated. The difference only gets bigger, since the combined blur is $O(n^2)$, while the separated form is $O(n)$.&lt;/p&gt;&#xA;" OwnerUserId="174" LastEditorUserId="231" LastEditDate="2015-11-07T23:21:50.137" LastActivityDate="2015-11-07T23:21:50.137" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="41" PostTypeId="2" ParentId="39" CreationDate="2015-08-05T04:46:43.567" Score="51" Body="&lt;p&gt;In convolution, two mathematical functions are combined to produce a third function. In image processing functions are usually called kernels. A kernel is nothing more than a (square) array of pixels (a small image so to speak). Usually, the values in the kernel add up to one. This is to make sure no energy is added or removed from the image after the operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically, a Gaussian kernel (used for Gaussian blur) is a square array of pixels where the pixel values correspond to the values of a Gaussian curve (in 2D).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Qc4Mq.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Qc4Mq.gif&quot; alt=&quot;Image linked from http://homepages.inf.ed.ac.uk/rbf/HIPR2/gsmooth.htm&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each pixel in the image gets multiplied by the Gaussian kernel. This is done by placing the center pixel of the kernel on the image pixel and multiplying the values in the original image with the pixels in the kernel that overlap. The values resulting from these multiplications are added up and that result is used for the value at the destination pixel. Looking at the image, you would multiply the value at (0,0) in the input array by the value at (i) in the kernel array, the value at (1,0) in the input array by the value at (h) in the kernel array, and so on. and then add all these values to get the value for (1,1) at the output image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bRN2c.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bRN2c.jpg&quot; alt=&quot;Image linked from http://www.songho.ca/dsp/convolution/convolution.html&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer your second question first, the larger the kernel, the more expensive the operation. So, the larger the radius of the blur, the longer the operation will take.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer your first question, as explained above, convolution can be done by multiplying each input pixel with the entire kernel. However, if the kernel is symmetrical (which a Gaussian kernel is) you can also multiply each axis (x and y) independently, which will decrease the total number of multiplications. In proper mathematical terms, if a matrix is separable it can be decomposed into (M×1) and (1×N) matrices. For the Gaussian kernel above this means you can also use the following kernels:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac1{256}\cdot\begin{bmatrix}&#xA;1&amp;amp;4&amp;amp;6&amp;amp;4&amp;amp;1\\&#xA;4&amp;amp;16&amp;amp;24&amp;amp;16&amp;amp;4\\&#xA;6&amp;amp;24&amp;amp;36&amp;amp;24&amp;amp;6\\&#xA;4&amp;amp;16&amp;amp;24&amp;amp;16&amp;amp;4\\&#xA;1&amp;amp;4&amp;amp;6&amp;amp;4&amp;amp;1&#xA;\end{bmatrix}&#xA;=&#xA;\frac1{256}\cdot\begin{bmatrix}&#xA;1\\4\\6\\4\\1&#xA;\end{bmatrix}\cdot\begin{bmatrix}&#xA;1&amp;amp;4&amp;amp;6&amp;amp;4&amp;amp;1&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You would now multiply each pixel in the input image with both kernels and add the resulting values to get the value for the output pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information on how to see if a kernel is separable, follow this &lt;a href=&quot;https://stackoverflow.com/questions/5886529/how-can-i-determine-if-my-convolution-is-separable&quot;&gt;link&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: the two kernels shown above use slightly different values. This is because the (sigma) parameter used for the Gaussian curve to create these kernels were slightly different in both cases. For an explanation on which parameters influence the shape of the Gaussian curve and thus the values in the kernel follow this &lt;a href=&quot;http://dev.theomader.com/gaussian-kernel-calculator/&quot; rel=&quot;noreferrer&quot;&gt;link&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: in the second image above it says the kernel that is used is flipped. This of course only makes any difference if the kernel you use is not symmetric. The reason why you need to flip the kernel has to do with the mathematical properties of the convolution operation (see &lt;a href=&quot;http://songho.ca/dsp/convolution/convolution.html&quot; rel=&quot;noreferrer&quot;&gt;link&lt;/a&gt; for a more in depth explanation on convolution). Simply put: if you would not flip the kernel, the result of the convolution operation will be flipped. By flipping the kernel, you get the correct result.&lt;/p&gt;&#xA;" OwnerUserId="194" LastEditorUserId="5108" LastEditDate="2017-10-27T03:31:26.673" LastActivityDate="2017-10-27T03:31:26.673" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="42" PostTypeId="2" ParentId="39" CreationDate="2015-08-05T05:11:19.993" Score="16" Body="&lt;p&gt;Here is the best article I've read on the topic:&#xA;&lt;a href=&quot;http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/&quot; rel=&quot;noreferrer&quot;&gt;&lt;em&gt;Efficient Gaussian blur with linear sampling&lt;/em&gt;&lt;/a&gt;. It addresses all your questions and is really accessible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the layman very short explanation: Gaussian is a function with the nice property of being separable, which means that a 2D Gaussian function can be computed by combining two 1D Gaussian functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So for a $n \times n$ size ($O(n^2)$), you only need to evaluate $2 \times n$ values ($O(n)$), which is significantly less. If your operation consists in reading a texture element (commonly called a &lt;em&gt;&quot;tap&quot;&lt;/em&gt;), it is good news: less taps is cheaper because a texture fetch has a cost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's why blurring algorithms use that property by doing two passes, one to blur horizontally by gathering the $n$ horizontal pixels, and one to blur vertically by gathering the $n$ vertical pixels. The result is the final blurred pixel color.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="174" LastEditDate="2015-11-09T04:32:25.737" LastActivityDate="2015-11-09T04:32:25.737" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="43" PostTypeId="2" ParentId="37" CreationDate="2015-08-05T05:38:47.300" Score="29" Body="&lt;p&gt;The actual cost of any particular state change varies with so many factors that a general answer is nigh impossible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, every state change can potentially have both a CPU-side cost and a GPU-side cost. The CPU cost may, depending on your driver and graphics API, be paid entirely on the main thread or partially on a background thread.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, the GPU cost may depend on the amount of work in flight. Modern GPUs are very pipelined and love to get lots of work in flight at once, and the biggest slowdown you can get is from stalling the pipeline so that everything that's currently in flight must retire before the state changes. What can cause a pipeline stall? Well, it depends on your GPU!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing you actually need to know to understand the performance here is: what does the driver and GPU need to do to process your state change? This of course depends on your GPU, and also on details that ISVs often don't share publicly. However, there are some &lt;strong&gt;general principles&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPUs generally are split into a frontend and a backend. The frontend handles a stream of commands generated by the driver, while the backend does all the real work. Like I said before, the backend loves to have lots of work in flight, but it needs some information to store information about that work (perhaps filled in by the frontend). If you kick enough small batches and use up all the silicon keeping track of the work, then the frontend will have to stall even if there's lots of unused horsepower sitting around. So a principle here: &lt;strong&gt;the more state changes (and small draws), the more likely you are to starve the GPU backend&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While a draw is actually being processed, you're basically just running shader programs, which are doing memory accesses to fetch your uniforms, your vertex buffer data, your textures, but also the control structures that tell the shader units where your vertex buffers and your textures are. And the GPU has caches in front of those memory accesses as well. So whenever you throw new uniforms or new texture/buffer bindings at the GPU, it'll likely suffer a cache miss the first time it has to read them. Another principle: &lt;strong&gt;most state changes will cause a GPU cache miss.&lt;/strong&gt; (This is most meaningful when you are managing constant buffers yourself: if you keep constant buffers the same between draws, then they are more likely to stay in cache on the GPU.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A big part of the cost for state changes for shader resources is the CPU side. Whenever you set a new constant buffer, the driver is most likely copying the contents of that constant buffer into a command stream for the GPU. If you set a single uniform, the driver is very likely turning that into a big constant buffer behind your back, so it has to go look up the offset for that uniform in the constant buffer, copy the value in, then mark the constant buffer as dirty so it can get copied into the command stream before the next draw call. If you bind a new texture or vertex buffer, the driver is probably copying a control structure for that resource around. Also, if you're using a discrete GPU on a multitasking OS, the driver needs to track every resource you use and when you start using it so that the kernel's GPU memory manager can guarantee that the memory for that resource is resident in the GPU's VRAM when the draw happens. Principle: &lt;strong&gt;state changes make the driver shuffle memory around to generate a minimal command stream for the GPU.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you change the current shader, you're probably causing a GPU cache miss (they have an instruction cache too!). In principle, the CPU work should be limited to putting a new command in the command stream saying &quot;use the shader.&quot; In reality, though, there's a whole mess of shader compilation to deal with. GPU drivers very often lazily compile shaders, even if you've created the shader ahead of time. More relevant to this topic, though, some states are not supported natively by the GPU hardware and are instead compiled into the shader program. One popular example is vertex formats: these may be compiled into the vertex shader instead of being separate state on the chip. So if you use vertex formats that you haven't used with a particular vertex shader before, you may now be paying a bunch of CPU cost to patch the shader and copy the shader program up to the GPU. Additionally, the driver and shader compiler may conspire to do all sorts of things to optimize the execution of the shader program. This might mean optimizing the memory layout of your uniforms and resource control structures so that they are nicely packed into adjacent memory or shader registers. So when you change shaders, it may cause the driver to look at everything you have already bound to the pipeline and repack it into an entirely different format for the new shader, and then copy that into the command stream. Principle: &lt;strong&gt;changing shaders can cause a lot of CPU memory shuffling.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Frame buffer changes are probably the most implementation-dependent, but are generally pretty expensive on the GPU. Your GPU may not be able to handle multiple draw calls to different render targets at the same time, so it may need to stall the pipeline between those two draw calls. It may need to flush caches so that the render target can be read later. It may need to resolve work that it has postponed during the drawing. (It is very common to be accumulating a separate data structure along with depth buffers, MSAA render targets, and more. This may need to be finalized when you switch away from that render target. If you are on a GPU that is tile-based, like many mobile GPUs, a fairly large amount of actual shading work might need to be flushed when you switch away from a frame buffer.) Principle: &lt;strong&gt;changing render targets is expensive on the GPU.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm sure that's all very confusing, and unfortunately it's hard to get too specific because details are often not public, but I'm hoping it's a half-decent overview of some of the things that are actually going on when you call some state changing function in your favorite graphics API.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-05T05:38:47.300" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="44" PostTypeId="1" AcceptedAnswerId="53" CreationDate="2015-08-05T05:47:39.463" Score="13" ViewCount="1458" Body="&lt;p&gt;I've heard a lot of people working on VR talk about scanline racing and that it's supposed  to help improve latency for motion-to-photon. However, it isn't clear to me how this can be done with OpenGL. Could someone explain how scanline racing works, and how it can be implemented on modern GPUs.&lt;/p&gt;&#xA;" OwnerUserId="197" LastActivityDate="2018-03-28T08:01:55.717" Title="What is &quot;Scanline Racing&quot;" Tags="&lt;virtual-reality&gt;&lt;scanline&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="45" PostTypeId="2" ParentId="27" CreationDate="2015-08-05T05:55:08.537" Score="5" Body="&lt;p&gt;Modern GPUs generally have a single frontend section that processes an entirely linear stream of commands from the CPU. Whether this is a natural hardware design or if it simply evolved out of the days when there was a single CPU core generating commands for the GPU is debatable, but it's the reality for now. So if you generate a single linear stream of stateful commands, of course it makes sense to generate that stream linearly on a single thread on the CPU! Right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, modern GPUs also generally have a very flexible unified backend that can work on lots of different things at once. Generally speaking, the GPU works on vertices and pixels at fairly fine granularity. There's not a whole lot of difference between a GPU processing 1024 vertices in one draw and 512+512 vertices in two different draws.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That suggests a fairly natural way to do less work: instead of throwing huge number of vertices at the GPU in a single draw call, split your model into sections, do cheap coarse culling on those sections, and submit each chunk individually if it passes the culling test. If you do it at the right granularity you should get a nice speedup!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, in the current graphics API reality, draw calls are extremely expensive on the CPU. A simplified explanation of why: state changes on the GPU may not directly correspond to graphics API calls, so many graphics API calls simply set some state inside the driver, and the draw call that would depend on this new state goes and looks at all the state that is marked as having changed since the last draw, writes it into the command stream for the GPU, then actually initiates the draw. This is all work that is done in an attempt to get a lean and mean command stream for the GPU frontend unit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What this boils down to is that you have a &lt;strong&gt;budget for draw calls which is entirely imposed by the overhead of the driver&lt;/strong&gt;. (I think I heard that these days you can get away with about 5,000 per frame for a 60 FPS title.) You can increase that by a large percentage by building this command stream in parallel chunks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are other reasons too (for example, asynchronous timewarp for VR latency improvements), but this is a big one for graphics-bound games and other drawcall-heavy software (like 3D modeling packages).&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-05T05:55:08.537" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="46" PostTypeId="2" ParentId="37" CreationDate="2015-08-05T06:06:19.940" Score="31" Body="&lt;p&gt;The most data I've seen is on the relative expense of various state changes is from Cass Everitt and John McDonald's &lt;a href=&quot;https://www.youtube.com/watch?v=-bCeNzgiJ8I&amp;amp;list=PLckFgM6dUP2hc4iy-IdKFtqR9TeZWMPjm&quot; rel=&quot;noreferrer&quot;&gt;talk on reducing OpenGL API overhead&lt;/a&gt; from January 2014.  Their talk included this slide (at 31:55):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JgrSc.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JgrSc.jpg&quot; alt=&quot;Relative costs of state changes&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The talk doesn't give any more info on how they measured this (or even whether they're measuring CPU or GPU cost, or both!).  But at least it dovetails with the conventional wisdom: render target and shader program changes are the most expensive, uniform updates the least, with vertex buffers and texture changes somewhere in the middle.  The rest of their talk also has a lot of interesting wisdom about reducing state-change overhead.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-05T06:06:19.940" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="48" PostTypeId="2" ParentId="31" CreationDate="2015-08-05T07:23:16.503" Score="9" Body="&lt;p&gt;JPEG compression involves three main steps:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Chroma_subsampling&quot;&gt;Chroma subsampling&lt;/a&gt;. The image is converted from RGB into YCbCr color space, in which the &lt;em&gt;luma&lt;/em&gt; or brightness (Y) is stored separately from the &lt;em&gt;chroma&lt;/em&gt; or color components, Cb and Cr.  The Y component is kept at full resolution, but Cb and Cr are downsampled, typically to half resolution on each axis.  This exploits the fact that the human visual system is more sensitive to fine details of brightness than of color.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Quantization_%28image_processing%29#Frequency_quantization_for_image_compression&quot;&gt;Frequency quantization.&lt;/a&gt; The Y, Cb, and Cr images are converted into a frequency representation, by breaking them up into 8x8 blocks and applying the &lt;a href=&quot;https://en.wikipedia.org/wiki/Discrete_cosine_transform&quot;&gt;discrete cosine transform&lt;/a&gt; (a variant of the Fourier transform) to each block.  The result is a matrix of numbers that describe the amplitudes of different spatial frequencies in the block.  These numbers can then be quantized (rounded off to a chosen number of bits of precision). Different levels of quantization are used for different frequencies, exploiting our visual system's relatively lower sensitivity to high frequencies.  This is where the JPEG encoder's quality setting comes into play: lower qualities use coarser quantization.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Entropy_encoding&quot;&gt;Entropy coding&lt;/a&gt;. The  quantized DCT values are passed through an entropy coder, which losslessly compresses the bit stream by using fewer bits to represent the more common values, sort of like a zip file.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Steps 1 and 2 are the lossy ones, and each produces its own type of artifacts (though there is some overlap).  Chroma subsampling tends to blur sharp edges between regions of different colors.  This is particularly visible in vector art, where brightly colored shapes pick up vicious jaggies around their edges. Frequency quantization blurs fine details in general, and also creates block-shaped artifacts at low quality settings, because the DCT is done on a block-by-block basis.  It is particularly visible on text.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why JPEG usually isn't used for images containing vector graphics or text&amp;mdash;its compression algorithms are poorly suited for those cases, although they work well for photographs and other images with complex texture and not-too-sharp edges.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-05T07:23:16.503" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="49" PostTypeId="2" ParentId="27" CreationDate="2015-08-05T08:07:39.323" Score="9" Body="&lt;p&gt;There's a lot of work needed on the CPU to set up a frame for the GPU, and a good chunk of that work is inside the graphics driver.  Prior to DX12 / Vulkan, that graphics driver work was essentially forced to be single-threaded by the design of the API.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The hope is that DX12 / Vulkan lift that restriction, allowing driver work to be performed in parallel on multiple CPU threads within a frame.  This will enable more efficient use of multicore CPUs, allowing game engines to push more complex scenes without becoming CPU-bound.  That's the hope&amp;mdash;whether it will be realized in practice is something we'll have to wait to see over the next few years.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To elaborate a bit: the output of a game engine renderer is a stream of DX/GL API calls that describe the sequence of operations to render a frame.  However, there's a great distance between the stream of API calls and the actual binary command buffers that the GPU hardware consumes.  The driver has to &quot;compile&quot; the API calls into the GPU's machine language, so to speak.  That isn't a trivial process&amp;mdash;it involves a lot of translation of API concepts into low-level hardware realities, validation to make sure the GPU is never set into an invalid state, wrangling memory allocations and data, tracking state changes to issue the correct low-level commands, and so on and on.  The graphics driver is responsible for all this stuff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In DX11 / GL4 and earlier APIs, this work is typically done by a single driver thread.  Even if you call the API from multiple threads (which you can do using DX11 deferred command lists, for example), it just adds some work to a queue for the driver thread to chew through later.  One big reason for this is the state tracking I mentioned before.  Many of the hardware-level GPU configuration details require knowledge of the current graphics pipeline state, so there's no good way to break up the command list into chunks that can be processed in parallel&amp;mdash;each chunk would have to know exactly what state it should start with, even though the previous chunk hasn't been processed yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's one of the big things that changed in DX12 / Vulkan.  For one thing, they incorporate almost all the graphics pipeline state into one object, and for another (at least in DX12) when you start creating a command list you &lt;em&gt;must&lt;/em&gt; provide an initial pipeline state; the state isn't inherited from one command list to the next.  In principle, this allows the driver not to have to know anything about previous command lists before it can start compiling&amp;mdash;and that in turn allows the application to break up its rendering into parallelizable chunks, producing fully-compiled command lists, which can then be concatenated together and sent to the GPU with a minimum of fuss.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, there are many other changes in the new APIs, but as far as multithreading goes, that's the most important part.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-05T08:07:39.323" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="50" PostTypeId="1" AcceptedAnswerId="52" CreationDate="2015-08-05T08:13:38.827" Score="9" ViewCount="1323" Body="&lt;p&gt;In traditional computer graphics, most 3D models are rendered by rasterizing or ray tracing against a subdivided mesh of primitives, usually triangles or quads. &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/RayTracedDistanceFieldShadowing/index.html&quot;&gt;More recently&lt;/a&gt;, some real-time techniques have been predicated on ray-tracing against signed distance fields (SDFs). Intuitively, these distance fields cannot be the same triangles and quads of traditional rendering and must be something like 3D geometric primitives (cubes, spheres, etc.) in order to get proper shading. Is this true? If not, can complex scenes of &quot;traditional&quot; 3D models be represented using SDFs? If it is true, then how do artists create high-detail models used in SDF renderers?&lt;/p&gt;&#xA;" OwnerUserId="197" LastActivityDate="2015-08-05T08:40:01.477" Title="Asset creation for signed distance field rendering?" Tags="&lt;raytracing&gt;&lt;signed-distance-field&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="51" PostTypeId="1" AcceptedAnswerId="62" CreationDate="2015-08-05T08:19:21.280" Score="16" ViewCount="3043" Body="&lt;p&gt;I would like to generate procedural noise on the surface of a sphere (e.g. to procedurally generate planets or marble-textured balls). Of course, I could just take a standard noise algorithm and map it onto the sphere, but this has all the issues of projecting a plane onto a sphere, like distortions on the poles or elsewhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suppose I could generate volume noise and &quot;cut out&quot; the sphere, but this seems unnecessarily inefficient - and if the noise has some grid-based artefacts, these would still not appear uniformly on the sphere. Furthermore, at least in the case of Simplex noise, cutting 2D slices out of 3D noise generally looks different than generating 2D noise right away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way to avoid these issues, e.g. by generating noise natively on the sphere? The noise should have at least the quality of &lt;a href=&quot;https://en.wikipedia.org/wiki/Perlin_noise&quot;&gt;Perlin noise&lt;/a&gt;, ideally that of &lt;a href=&quot;https://en.wikipedia.org/wiki/Simplex_noise&quot;&gt;Simplex noise&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2015-11-03T16:14:57.213" Title="How can I generate procedural noise on a sphere?" Tags="&lt;projections&gt;&lt;noise&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="52" PostTypeId="2" ParentId="50" CreationDate="2015-08-05T08:40:01.477" Score="8" Body="&lt;p&gt;Signed distance fields are popular in minimal graphics applications, such as the demo scene, where interesting objects can be synthesized from few simple analytic primitives such as spheres or cubes. However, signed distance fields are not restricted to these simple objects, and they do not necessarily need to be designed by a human. For example, you can synthesize the analytic signed distance field of a triangle mesh without any artist interaction - the SDF is just the signed distance to the closest triangle after all, which can be easily computed. This allows you to keep using your traditional mesh pipeline while also using SDFs in the background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of the Unreal Engine, the SDF is precomputed automatically once for all static meshes and is then sampled into a low-resolution 3D texture. It can then be cheaply evaluated everywhere using a simple texture lookup, allowing them to do soft shadows and similar at runtime. &lt;a href=&quot;http://www.nvidia.com/content/pdf/gdc2011/epic.pdf&quot;&gt;This Unreal presentation&lt;/a&gt; at GDC 2011 mentions the 3D textures briefly (slide 27).&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-05T08:40:01.477" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="53" PostTypeId="2" ParentId="44" CreationDate="2015-08-05T09:04:59.070" Score="14" Body="&lt;p&gt;When your GPU displays a new frame on the screen, it transfers the image over the HDMI cable (or whatever kind) in a process called &quot;scanout&quot;.  The pixels are sent out in linear order, usually left-to-right and top-to-bottom.  The process is timed so that it takes most of the duration of a refresh interval to do this.  For instance, at 60Hz, one frame is ~17 ms.  Each scanout will take probably around 15-16 ms, with 1-2 ms of vblank in between (the exact values vary according to the display and video mode).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Traditionally, rendering is double-buffered, which means there are two buffers stored in GPU memory: one that is currently being scanned out (&quot;front buffer&quot;), and one that is being rendered to (&quot;back buffer&quot;).  Each frame, the two are swapped.  The GPU never renders to the same buffer that's being scanned out, which prevents artifacts due to potentially seeing parts of an incomplete frame.  However, a side effect of this is increased latency, since each frame may sit around in the buffer for several ms before it starts being scanned out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VR is very latency-sensitive, so this isn't desirable. An alternative approach is to render directly to the front buffer, but time things out very carefully so that you have rendered each line of the image shortly before the scanout gets there. That's called &quot;scanline racing&quot; or &quot;racing the beam&quot; (the &quot;beam&quot; harkening back to the CRT days of yore). This more or less requires that you render the image in scanline order, i.e. the same order that the pixels get scanned out.  It doesn't literally have to be rendered one line at a time&amp;mdash;it could be rendered in thin strips a few pixels high, but it does have to be done in order, as you can't go back and edit pixels that have already been scanned out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a lot of disadvantages to this approach; it has very stringent performance requirements, has to be timed very carefully against vsync, and it greatly complicates the rendering process. But in principle it can shave milliseconds off your latency, which why VR folks are interested in it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-05T09:04:59.070" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="54" PostTypeId="1" AcceptedAnswerId="60" CreationDate="2015-08-05T09:30:30.980" Score="47" ViewCount="25672" Body="&lt;p&gt;Image filtering operations such as blurs, SSAO, bloom and so forth are usually done using pixel shaders and &quot;gather&quot; operations, where each pixel shader invocation issues a number of texture fetches to access the neighboring pixel values, and computes a single pixel's worth of the result.  This approach has a theoretical inefficiency in that many redundant fetches are done: nearby shader invocations will re-fetch many of the same texels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way to do it is with compute shaders. These have the potential advantage of being able to share a small amount of memory across a group of shader invocations. For instance, you could have each invocation fetch one texel and store it in shared memory, then calculate the results from there.  This might or might not be faster.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is under what circumstances (if ever) is the compute-shader method &lt;em&gt;actually&lt;/em&gt; faster than the pixel-shader method?  Does it depend on the size of the kernel, what kind of filtering operation it is, etc.?  Clearly the answer will vary from one model of GPU to another, but I'm interested in hearing if there are any general trends.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-05-06T02:21:41.590" Title="When is a compute shader more efficient than a pixel shader for image filtering?" Tags="&lt;performance&gt;&lt;rendering&gt;&lt;compute-shader&gt;&lt;pixel-shader&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="16" ContentLicense="CC BY-SA 3.0" />
  <row Id="55" PostTypeId="2" ParentId="39" CreationDate="2015-08-05T09:42:12.257" Score="12" Body="&lt;p&gt;The most important thing to consider when implementing the Gaussian blur is, as others have pointed out, to separate the 2D convolution filter into two 1D convolutions because it brings the complexity down from $O(n^2)$ to $O(n)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But there are two more tricks you might want to consider in an actual implementation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The filter has a certain radius and because of that, at the very borders, you will need to calculate with pixels which fall outside of the image. In such case, you could try one of the following: for the outside pixels you simply take the last possible value (i.e. the pixel at the very border, as in &lt;code&gt;max(x, 0)&lt;/code&gt;. Or you could &quot;reflect&quot; the image towards outside (as in &lt;code&gt;x &amp;lt; 0 ? -x : x&lt;/code&gt;). Or you could simply stop at the border but then you would need to adjust the denominator in convolution filter so that it sums up to 1. For example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\operatorname{sum}&#xA;\frac{1}{256}&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 4  &amp;amp; 6  &amp;amp; 4  &amp;amp; 1 \\&#xA;4 &amp;amp; 16 &amp;amp; 24 &amp;amp; 16 &amp;amp; 4 \\&#xA;6 &amp;amp; 24 &amp;amp; 36 &amp;amp; 24 &amp;amp; 6 \\&#xA;4 &amp;amp; 16 &amp;amp; 24 &amp;amp; 16 &amp;amp; 4 \\&#xA;1 &amp;amp; 4  &amp;amp; 6  &amp;amp; 4  &amp;amp; 1 \\&#xA;\end{bmatrix}&#xA;=&#xA;\operatorname{sum}&#xA;\frac{1}{225}&#xA;\begin{bmatrix}&#xA;0 &amp;amp; 0  &amp;amp; 0  &amp;amp; 0  &amp;amp; 0 \\&#xA;0 &amp;amp; 16 &amp;amp; 24 &amp;amp; 16 &amp;amp; 0 \\&#xA;0 &amp;amp; 24 &amp;amp; 36 &amp;amp; 16 &amp;amp; 0 \\&#xA;0 &amp;amp; 16 &amp;amp; 24 &amp;amp; 16 &amp;amp; 0 \\&#xA;0 &amp;amp; 0  &amp;amp; 0  &amp;amp; 0  &amp;amp; 0 \\&#xA;\end{bmatrix}&#xA;= 1.&#xA;$$&#xA;Another trick concerns how to calculate the actual coefficients of the kernel. Obviously you could try to implement the &lt;a href=&quot;https://en.wikipedia.org/wiki/Gaussian_function&quot; rel=&quot;noreferrer&quot;&gt;Gaussian function&lt;/a&gt; but much faster way is to observe that the 1D kernel reassembles &lt;a href=&quot;https://en.wikipedia.org/wiki/Pascal%27s_triangle&quot; rel=&quot;noreferrer&quot;&gt;Pascal's triangle&lt;/a&gt;. For example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;     1&#xA;    1 1&#xA;   1 2 1&#xA;  1 3 3 1&#xA;[1 4 6 4 1]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="141" LastEditorUserId="174" LastEditDate="2015-11-09T04:32:44.627" LastActivityDate="2015-11-09T04:32:44.627" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="56" PostTypeId="1" AcceptedAnswerId="59" CreationDate="2015-08-05T10:50:13.490" Score="13" ViewCount="1382" Body="&lt;p&gt;In GLSL, perspective correct interpolation of vertex attributes is the default setting - one can disable it for specific vertex attributes by using the &lt;em&gt;noperspective&lt;/em&gt; qualifier. Other than in post-processing shaders, I've never seen the perspective correct interpolation disabled - are there any other use cases? Also, does it even make a difference, performance-wise?&lt;/p&gt;&#xA;" OwnerUserId="215" LastEditorUserId="6546" LastEditDate="2017-05-02T00:25:41.647" LastActivityDate="2017-05-02T00:25:41.647" Title="When to disable perspective correct interpolation ( noperspective )" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="57" PostTypeId="1" CreationDate="2015-08-05T11:25:51.847" Score="11" ViewCount="393" Body="&lt;p&gt;How can I distribute points over an implicit surface, to concentrate them more densely in areas of higher curvature?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've considered adding points randomly and rejecting points not required based on the curvature, but I'd like to know if there is a better approach giving a more even distribution over areas of similar curvature, while still giving the higher density required in high curvature regions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking specifically at using these points for a triangulation of the surface, and I don't want to create more triangles than I need for relatively flat parts.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This will be applied to shapes with a known derivative so the curvature at a given point can be calculated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This does not need to be a real-time approach.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-11T11:30:46.930" LastActivityDate="2017-05-19T08:22:56.183" Title="How can I concentrate points in areas of higher curvature?" Tags="&lt;algorithm&gt;&lt;triangulation&gt;" AnswerCount="3" CommentCount="7" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="58" PostTypeId="1" AcceptedAnswerId="77" CreationDate="2015-08-05T11:31:47.607" Score="8" ViewCount="112" Body="&lt;p&gt;I want to model rays with a continuous range of frequencies so that I can get raytraced images with colour separation on refraction. I can model a light source with a specified frequency distribution by using the distribution to affect the probability of a random ray lying in a given frequency range, or alternatively I can choose frequencies from a uniform random distribution and make the brightness of each ray proportional to the frequency distribution at its particular frequency. I see the first as more physically accurate, but I suspect the second will give images that look &quot;finished&quot; with fewer rays. Is this intuitive suspicion correct? Are there any features that will be lost from the image with the second approach? Is there a way to get some of the speed increase without compromising the image?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-05T22:04:17.097" Title="What are the side effects of biasing brightness in continuous spectrum raytracing?" Tags="&lt;raytracing&gt;&lt;color&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="59" PostTypeId="2" ParentId="56" CreationDate="2015-08-05T14:03:44.697" Score="15" Body="&lt;p&gt;Use cases are only limited by your imagination! &lt;code&gt;noperspective&lt;/code&gt; means that the attribute is interpolated across the triangle as though the triangle was completely flat on the surface of the screen. You can do &lt;a href=&quot;http://orbit.dtu.dk/fedora/objects/orbit:55459/datastreams/file_3735323/content&quot;&gt;antialiased wireframe rendering&lt;/a&gt; with this: output a screen-space distance to the nearest edge as a &lt;code&gt;noperspective&lt;/code&gt; varying and use that as coverage in the pixel shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or if you're doing non-photorealistic rendering and want a pattern in screen-space like &lt;a href=&quot;https://en.wikipedia.org/wiki/Halftone&quot;&gt;halftoning&lt;/a&gt;, you can enable &lt;code&gt;noperspective&lt;/code&gt; on your UVs used for texturing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does it make a performance difference? Probably, but you probably won't notice (with the potential exception of less powerful graphics hardware). Most GPUs are composed of a series of pipeline stages that execute in parallel, and in some sense you only pay the cost for the most expensive stage. If rasterization is the most limiting part for you, then you may see a difference from the divisions that you're skipping per-pixel. I would guess that is most likely when rendering a shadow map or a depth prepass, but those also have the fewest attributes to interpolate.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-05T14:03:44.697" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="60" PostTypeId="2" ParentId="54" CreationDate="2015-08-05T14:30:50.343" Score="29" Body="&lt;p&gt;An architectural &lt;em&gt;advantage&lt;/em&gt; of compute shaders for image processing is that they skip the &lt;a href=&quot;https://en.wikipedia.org/wiki/Render_output_unit&quot; rel=&quot;noreferrer&quot;&gt;ROP&lt;/a&gt; step. It's very likely that writes from pixel shaders go through all the regular blending hardware even if you don't use it. Generally speaking compute shaders go through a different (and often more direct) path to memory, so you may avoid a bottleneck that you would otherwise have. I've heard of fairly sizable performance wins attributed to this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An architectural &lt;em&gt;disadvantage&lt;/em&gt; of compute shaders is that the GPU no longer knows which work items retire to which pixels. If you are using the pixel shading pipeline, the GPU has the opportunity to pack work into a warp/wavefront that write to an area of the render target which is contiguous in memory (which may be &lt;a href=&quot;https://en.wikipedia.org/wiki/Z-order_curve&quot; rel=&quot;noreferrer&quot;&gt;Z-order tiled&lt;/a&gt; or something like that for performance reasons). If you are using a compute pipeline, the GPU may no longer kick work in optimal batches, leading to more bandwidth use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may be able to turn that altered warp/wavefront packing into an advantage again, though, if you know that your particular operation has a substructure that you can exploit by packing related work into the same thread group. Like you said, you could in theory give the sampling hardware a break by sampling one value per lane and putting the result in groupshared memory for other lanes to access without sampling. Whether this is a win depends on how expensive your groupshared memory is: if it's cheaper than the lowest-level texture cache, then this may be a win, but there's no guarantee of that. GPUs already deal pretty well with highly local texture fetches (by necessity).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have an intermediate stages in the operation where you want to share results, it may make more sense to use groupshared memory (since you can't fall back on the texture sampling hardware without having actually written out your intermediate result to memory). Unfortunately you also can't depend on having results from any other thread group, so the second stage would have to limit itself to only what is available in the same tile. I think the canonical example here is computing the average luminance of the screen for auto-exposure. I could also imagine combining texture upsampling with some other operation (since upsampling, unlike downsampling and blurs, doesn't depend on any values outside a given tile).&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2017-09-09T18:54:14.380" LastActivityDate="2017-09-09T18:54:14.380" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="61" PostTypeId="1" AcceptedAnswerId="63" CreationDate="2015-08-05T14:56:21.613" Score="21" ViewCount="13060" Body="&lt;p&gt;The &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/fwidth.xhtml&quot;&gt;OpenGL documentation&lt;/a&gt; states that fwidth &lt;code&gt;returns the sum of the absolute value of derivatives in x and y&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does this mean in less mathematical terms, and is there a way to visualize it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Based on my understanding of the function, &lt;code&gt;fwidth(p)&lt;/code&gt; has access to the value of &lt;code&gt;p&lt;/code&gt; in neighboring pixels. How does this work on the GPU without drastically impacting performance, and does it work reliably and uniformly across all pixels?&lt;/p&gt;&#xA;" OwnerUserId="88" LastActivityDate="2015-08-18T12:17:27.583" Title="What is fwidth and how does it work?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="62" PostTypeId="2" ParentId="51" CreationDate="2015-08-05T14:56:45.127" Score="17" Body="&lt;p&gt;I'd consider just going with 3D noise and evaluating it on the surface of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For gradient noise which is naturally in the domain of the surface of the sphere, you need a regular pattern of sample points on the surface that have natural connectivity information, with roughly equal area in each cell, so you can interpolate or sum adjacent values. I wonder if something like a &lt;a href=&quot;http://onlinelibrary.wiley.com/doi/10.1256/qj.05.227/epdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fibonacci grid&lt;/a&gt; might work:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sQQb3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sQQb3.png&quot; alt=&quot;Fibonacci grid on the surface of a sphere&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't chewed through the math to determine how much work it would be to figure out the indices of and distance to your four neighbors (I don't even know if you end up having four well-defined neighbors in all cases), and I suspect it may be less efficient than simply using 3D noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; Someone else has chewed through the math! See this new paper on &lt;a href=&quot;http://lgdv.cs.fau.de/uploads/publications/spherical_fibonacci_mapping.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Spherical Fibonacci Mapping&lt;/a&gt;. It seems that it would be straightforward to adapt it to sphere noise.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If you are rendering a sphere, not just evaluating noise on the surface of a sphere, and are fine with tessellating your sphere to the resolution of your noise lattice, you can create a &lt;a href=&quot;https://en.wikipedia.org/wiki/Geodesic_grid&quot; rel=&quot;nofollow noreferrer&quot;&gt;geodesic grid&lt;/a&gt; on the surface of the sphere (a subdivided icosahedron, usually):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pjVBA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pjVBA.png&quot; alt=&quot;Geodesic sphere&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each vertex of the sphere can have a randomly generated gradient for gradient noise. To get this information to the pixel shader (unless you want straightforward interpolation like value noise), you may need a technique like this article's &lt;a href=&quot;http://codeflow.org/entries/2012/aug/02/easy-wireframe-display-with-barycentric-coordinates/&quot; rel=&quot;nofollow noreferrer&quot;&gt;wireframe rendering with barycentric coordinates&lt;/a&gt;: do unindexed rendering, with each vertex containing the barycentric coordinates of that vertex in the triangle. You can then read from &lt;code&gt;SV_PrimitiveID&lt;/code&gt; (or the OpenGL equivalent) in the pixel shader, read the three noise gradients from the vertices based on what triangle you are on, and use whatever noise calculation you like using the interpolated barycentric coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the most difficult part of this method is coming up with a scheme to map your triangle ID to three samples in order to look up the noise values at each vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need multiple octaves of noise or noise at a finer resolution than your sphere model, you may be able to do a coarse geodesic grid with vertices and do a few levels of subdivision in the pixel shader. i.e. from the barycentric coordinates, figure out which subdivided triangle you &lt;em&gt;would&lt;/em&gt; be in if the mesh was further tessellated, and then figure out what the primitive ID and barycentric coordinates would be for that triangle.&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2015-11-03T16:14:57.213" LastActivityDate="2015-11-03T16:14:57.213" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="63" PostTypeId="2" ParentId="61" CreationDate="2015-08-05T15:10:50.933" Score="21" Body="&lt;p&gt;Pixel screen-space derivatives &lt;em&gt;do&lt;/em&gt; drastically impact performance, but they impact performance whether you use them or not, so from a certain point of view they're free!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Every GPU in recent history packs a quad of four pixels together and puts them in the same warp/wavefront, which essentially means that they're running right next to each other on the GPU, so accessing values from them is very cheap. Because warps/wavefronts are run in lockstep, the other pixels will also be at exactly the same place in the shader as you are, so the value of &lt;code&gt;p&lt;/code&gt; for those pixels will just be sitting in a register waiting for you. These other three pixels will &lt;em&gt;always&lt;/em&gt; be executed, even if their results will be thrown away. So a triangle that covers a single pixel will always shade four pixels and throw away the results of three of them, just so that these derivative features work!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is considered an acceptable cost (for current hardware) because it isn't just functions like &lt;code&gt;fwidth&lt;/code&gt; that use these derivatives: every single texture sample does as well, in order to pick what mipmap of your texture to read from. Consider: if you are very close to a surface, the UV coordinate you are using to sample the texture will have a very small derivative in screen space, meaning you need to use a larger mipmap, and if you are farther the UV coordinate will have a larger derivative in screen space, meaning you need to use a smaller mipmap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as what it means in less mathematical terms: &lt;code&gt;fwidth&lt;/code&gt; is equivalent to &lt;code&gt;abs(dFdx(p)) + abs(dFdy(p))&lt;/code&gt;. &lt;code&gt;dFdx(p)&lt;/code&gt; is simply the difference between the value of &lt;code&gt;p&lt;/code&gt; at pixel x+1 and the value of &lt;code&gt;p&lt;/code&gt; at pixel x, and similarly for &lt;code&gt;dFdy(p)&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-05T15:10:50.933" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="64" PostTypeId="2" ParentId="61" CreationDate="2015-08-05T15:13:45.657" Score="11" Body="&lt;p&gt;In entirely technical terms, &lt;code&gt;fwidth(p)&lt;/code&gt; is defined as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fwidth(p) := abs(dFdx(p)) + abs(dFdy(p))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And &lt;code&gt;dFdx(p)&lt;/code&gt;/&lt;code&gt;dFdy(p)&lt;/code&gt; are the partial derivates of the value &lt;code&gt;p&lt;/code&gt; with respect to the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; screen dimensions. So they denote how the value of &lt;code&gt;p&lt;/code&gt; behaves when going one pixel to the right (&lt;code&gt;x&lt;/code&gt;) or one pixel up (&lt;code&gt;y&lt;/code&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now how can they be practically computed? Well, if you know the neighbour pixels' values for &lt;code&gt;p&lt;/code&gt;, you can just compute those derivates as direct &lt;strong&gt;finite differences&lt;/strong&gt; as an approximation for their actual mathematical derivatives (which might not have an exact analytical solution at all):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;dFdx(p) := p(x+1) - p(x)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But of course now you may ask, how do we even know the values of &lt;code&gt;p&lt;/code&gt; (which could afterall be any arbitrarily computed value inside the shader program) for the neighbouring pixels? How do we compute those values without incurring major overhead by doing the whole shader computation two (or three) times?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, you know what, those neighbouring values are computed anyway, since for the neighbouring pixel you also run a fragment shader. So all that you need is access to this neighbouring fragment shader invocation when run for the neighbouring pixel. But it's even easier, because those neighbouring values are also computed at the exact same time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern rasterizers call fragment shaders in larger tiles of more than one neighbouring pixels. At the smallest those would be a 2x2 grid of pixels. And for each such a pixel block the fragment shader is invoked for each pixel and those invocations run &lt;strong&gt;in perfectly parallel lock-step&lt;/strong&gt; so that all computations are done in the exact same order and at the exact same time for each of those pixels in the block (which is also why branching in the fragment shader, while not deadly, should be avoided if possible, since each invocation of a block would have to explore every branch that is taken by at least one of the invocations, even if it just throws away the results afterwards, as also adressed in the answers to &lt;a href=&quot;https://computergraphics.stackexchange.com/q/259/6&quot;&gt;this related question&lt;/a&gt;). So at any moment, a fragment shader theoretically has access to its neighbouring pixels' fragment shader values. And while you don't have direct access to those values, you have access to values computed from them, like the derivative functions &lt;code&gt;dFdx&lt;/code&gt;, &lt;code&gt;dFdy&lt;/code&gt;, &lt;code&gt;fwidth&lt;/code&gt;, ...&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-18T12:17:27.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="65" PostTypeId="1" AcceptedAnswerId="75" CreationDate="2015-08-05T15:36:21.923" Score="10" ViewCount="584" Body="&lt;p&gt;Using a gaussian distribution of points on an image plane to calculate a pixel value, what radius/standard deviation will give the most information in the final image? Too large a radius gives a blurred image, and too small a radius neglects information that is smaller than a pixel so that it does not contribute to the final image. Where is the optimal compromise? Is there a single answer to this question or are there circumstances under which it can vary?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm thinking of this in relation to raytracing but I imagine it will apply equally to things like downsizing an image. Where the answers would differ, I am interested in what applies when sampling a continuous image plane, so that the positions of pixels in a larger image cannot be used to determine an optimal radius.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-05T16:25:31.173" LastActivityDate="2016-03-25T21:41:43.557" Title="What is the optimal radius of gaussian distribution for determining pixel colour?" Tags="&lt;sampling&gt;&lt;pixels&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="66" PostTypeId="1" AcceptedAnswerId="70" CreationDate="2015-08-05T16:03:41.260" Score="10" ViewCount="3593" Body="&lt;p&gt;I know that depth of field involves blurring.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's some great information about how to do a Gaussian blur in the question &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/39/how-is-gaussian-blur-implemented&quot;&gt;How is Gaussian Blur Implemented?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, other than that, how is depth of field implemented?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the rules about how you blur each pixel, and how do you handle the case of when there is a pixel that wants to blur a lot next to a pixel that doesn't want to blur as much?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also heard of the &quot;circle of confusion&quot; but have no idea what that is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain DOF in a plain, easy to understand way?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-05T21:07:18.557" Title="How is Depth of Field Implemented?" Tags="&lt;blur&gt;&lt;post-processing&gt;&lt;depth-of-field&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="67" PostTypeId="1" CreationDate="2015-08-05T16:28:50.313" Score="11" ViewCount="1904" Body="&lt;p&gt;Most computer monitors and televisions have a rectangular array of pixels arranged on a square (or nearly square) lattice. Would a hexagonal lattice give better image quality for the same number of pixels? In other words, would the same amount of memory allow storage of more detail?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have an intuitive feeling that (at least slightly) more detail should be possible from the same number of pixels with a hexagonal lattice because (for a fixed area image) the average distance to the nearest pixel centre will be lower than with a square lattice. I'd like to see the difference defined more concretely.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Even if the answer is &quot;yes&quot;, I don't expect monitor manufacturers to suddenly start making hexagonally arranged pixels. However, I ask the question because I wonder whether there would be anything to be gained from storing images as hexagonal lattices of pixels, even if they are translated to square lattices of pixels for display purposes.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-05T19:57:24.753" LastActivityDate="2016-03-25T21:25:36.990" Title="Could a hexagonal pixel array store an image more efficiently?" Tags="&lt;pixels&gt;&lt;memory&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="68" PostTypeId="1" AcceptedAnswerId="72" CreationDate="2015-08-05T16:33:33.160" Score="17" ViewCount="533" Body="&lt;p&gt;Do different monitors (including mobile screens) still use significantly different gamma functions when displaying colour images? Is there a standardised way to represent colour that can then be translated according to the gamma of the monitor, or are they all sufficiently similar to preclude the need for this nowadays?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2018-08-19T20:03:44.570" Title="Is gamma still important to take into account?" Tags="&lt;color&gt;&lt;gamma&gt;&lt;compatibility&gt;" AnswerCount="2" CommentCount="10" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="69" PostTypeId="1" AcceptedAnswerId="71" CreationDate="2015-08-05T16:40:58.147" Score="10" ViewCount="141" Body="&lt;p&gt;If rendering an image in 2D, adding depth of field effects (blurring objects further from the focal distance) adds realism and draws the eye to the object of the image. With a 3D (i.e. stereo) image, looking at an object in the image at a given depth will makes objects at all other depths defocused (not blurred, but incorrectly aligned by the eyes, giving a double image). This means that if depth of field effects are used, there will be conflicting results: looking at an object that is at a different depth will cause that depth to be the only depth not having a double image, but it is also a depth that is blurred. This gives the object a property of being focused upon, and a property of not being focused upon. In a 3d still image, are depth of field effects detrimental to the acceptance of the image by the eye, or are there ways around this?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-05T16:56:09.080" LastActivityDate="2015-08-05T17:39:24.690" Title="Is depth of field incongruous in a 3D still image?" Tags="&lt;depth-of-field&gt;&lt;3d&gt;&lt;stereo-rendering&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="70" PostTypeId="2" ParentId="66" CreationDate="2015-08-05T17:03:21.057" Score="20" Body="&lt;p&gt;The depth of field is a characteristic of a camera lens setting, although the name &quot;Depth of Field&quot; is commonly used to describe the effect caused by such characteristic. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Camera lenses can only perfectly focus on one single point, but there is a distance for which the image will still look reasonably sharp. Such distance is what actually the Depth Of Field is. This distance is variable depending on various factors, but let's say for the sake of brevity that the easiest way to adjust it is by changing your camera aperture. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ezhSb.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ezhSb.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the circle of confusion it is helpful to look a pic from wikipedia: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/g7MnD.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g7MnD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In all of the three cases a single point is &quot;projected&quot; onto our image plane, but as you can see that is at different distances from the lens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically because, as I said, not everything is perfectly in focus (that is the focal point is on the image plane), a point can be projected to our image plane not to a single point but to an area. This, as it is clear from the pic, is because the focal point is either before or after the image plane. This &quot;circle&quot; that is created on the image plane is what is called the circle of confusion. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now from this should be clear that varying the depth of field you vary the CoC size, hence it can be used as a measure of the DoF itself and an intuitive one when thinking in terms of blurring. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As per how it is implemented in rendering there are really lots of methods out there. Usually in games is done as a post process using the depth information to split your scene in different &quot;planes&quot;; for example a focus plane that does not need to be blurred, a near plane and a far/background plane that need to be blurred. Once you blurred your planes you can composite them back together to get your final image. &#xA;How much you blur the various planes it is dependent on the effect you want to achieve. Advanced system usually implement this and other &quot;lenses&quot; effect using appropriate parameters coming from the photography world like the aperture. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that there are many ways to implement the effect, the one I described is just one way that also has variations (for example performing the whole thing at lower res). The limit is dependent on what your target is and how much you budgeted for this effect. You can go from adopting the &quot;3 planes&quot; method at extremely low res to computing the circle of confusion for each pixel and applying the consequent ad-hoc blur to that pixel. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;EDIT: The comment from @NathanReed needs to be more in evidence as part of the answer: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Matt Pettineo's blog posts &lt;a href=&quot;https://mynameismjp.wordpress.com/2011/02/28/bokeh/&quot; rel=&quot;noreferrer&quot;&gt;How To Fake Bokeh&lt;/a&gt; and &lt;a href=&quot;https://mynameismjp.wordpress.com/2011/04/19/bokeh-ii-the-sequel/&quot; rel=&quot;noreferrer&quot;&gt;Bokeh II: The Sequel&lt;/a&gt; are great introductions to how to practically implement post-process DoF and address the typical artifacts you get from it. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-08-05T21:07:18.557" LastActivityDate="2015-08-05T21:07:18.557" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="71" PostTypeId="2" ParentId="69" CreationDate="2015-08-05T17:39:24.690" Score="6" Body="&lt;p&gt;In traditional stereo 3D, I don't believe that there is a way to make a fixed focal plane feel natural to the viewer. When looking at an out-of-focus object in stereo 3D, the object remains out-of-focus, causing conflicting cues. The lens in the eye tries to adjust to bring the object into focus, but of course it won't succeed, causing eye strain and headaches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there is hope outside stereo 3D: Lightfield displays, such as &lt;a href=&quot;https://research.nvidia.com/publication/near-eye-light-field-displays&quot;&gt;this nvidia prototype&lt;/a&gt;, go a different route. In stereo 3D, the light in the scene is already captured by two virtual (or physical) cameras, &quot;baking&quot; in the focal plane. Head-mounted displays like Oculus Rift then attempt to tape two displays in front of your eyes in such a way that the retina receives the exact same image that was captured by the camera. Lightfield displays go a different route: Instead of capturing two images ahead of time, they reproduce the entire 4D light field in front of your eyes, allowing your eyes to capture the image as if they were sitting directly inside the virtual scene. This has a number of benefits, including much smaller and lighter hardware as well as giving your eyes the ability to refocus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there is a way to make lightfield displays technically and commercially viable, then I believe they can remove the need for depth of field and fixed focal planes entirely and make VR feel a whole lot more comfortable for the viewer. However, it is likely not possible to construct lightfield screens, so televisions and cinemas won't be able to use this technology.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-05T17:39:24.690" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="72" PostTypeId="2" ParentId="68" CreationDate="2015-08-05T17:53:18.857" Score="15" Body="&lt;p&gt;Yes, while many screens and OS operations are using a gamma of 2.2 your hardware and computation result still need to be corrected. There are also special mediums such as broadcast TV's that have a different gamma. Sensor equipment like cameras are mostly linear so they need to be adjusted accordingly. Besides this the user can set their system to whatever gamma they like. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In computer graphics primary reason to account for gamma is that your computation is most likely done in linear space* or summing light contributions becomes unnecessarily complicated. In any case gamma is really a simplification of things, you'd be much much better of doing profile to profile conversions if its possible to invest the computational time to do so.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Mathematical explanation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;This may be a simpler to understand. Your monitor has a display error of $g(x)$ which is no problem if your data is conforming to $g(x)$, however if you want to calculate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ a+b+c+d $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and $a$, $b$, $c$, $d$, have the error of $g(x)$ you would actually need to calculate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ g(g^{-1}(a)+g^{-1}(b)+g^{-1}(c)+g^{-1}(d)) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You would need to do this for each sub element over and over again. Therefore instead of running the transform each time you transform all once to linear and then once back. &lt;/p&gt;&#xA;&#xA;&lt;h2&gt;And finally a artistic reason&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;It may just look better with a different gamma. Many games have a gamma adjustment for this reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* Worst case is that you think your computations as linear but do not compensate for the monitors nonlinear output charachteristics.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="16" LastEditDate="2015-11-03T12:45:56.093" LastActivityDate="2015-11-03T12:45:56.093" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="73" PostTypeId="2" ParentId="57" CreationDate="2015-08-05T18:15:47.057" Score="11" Body="&lt;p&gt;The idea I would try to apply would be the following: I make the example for the curve, but it should be straightforward for the application for the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say we have a curve $\gamma$ uniformly parametrized. Let's say the parameter of the curve is $s$. Your goal is to sample point corresponding to value of $s$ such that the curvature is high.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you get the magnitude of the curvature $c$, this will be function of $s$ too. So, if you normalize the function $|c|$, you will get a probability distribution. If you get the integral of such distribution, you will have the cumulative distribution. Let's call this cumulative function $C(s)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sampling problem from a distribution given by the cumulative function is well known, so basically once you have sampled a set of value $s_0,s_1,\dots,s_n$, such value will be related to the points of interest.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The application of this method to the case of surface should be straight, since basically you have a two dimensional cumulative distribution function, but the sampling problem is exactly the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just to give some detail, it is basically sampling from a distribution given the cumulative function involves two steps:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;take a random value in the interval $[0,1]$, let's say $k$ &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;solve the equation $C(s) = k$.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This approach is exact, of course it is expensive, but if you like such approach you can work on optimization.&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="171" LastEditDate="2017-05-19T08:22:56.183" LastActivityDate="2017-05-19T08:22:56.183" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="74" PostTypeId="2" ParentId="67" CreationDate="2015-08-05T18:53:15.353" Score="8" Body="&lt;p&gt;Here's my take on it.  A pixel is not a square, and it isn't even a rectangle.  A pixel is a point (infinitely small) that has a color associated with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only way I personally have ever seen pixels viewed (interpreted) by a display is to use &quot;nearest neighbor&quot; sampling where the pixels were on a rectangular grid, which means that the color of any given space on a display is the color of the pixel that it is nearest to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a fancy way of saying &quot;pixels are rectangular and laid out on a grid&quot;, but stay with me on this :P&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a result, image formats have their pixels stored in a grid as well, with the assumption that nearest neighbor in a grid will also be used to display it.  For instance, many images will have anti aliasing built into them so that they will look good when displayed on a &quot;nearest neighbor grid&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Interactive applications (games), may use textures that are not meant to be displayed as is on nearest neighbor grids so are kind of an exception to that rule.  They do this because as part of their execution, they do anti aliasing, bilinear texture sampling, etc, so that whatever picture they push out to the display will look good, when the display shows it as a nearest neighbor grid!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, getting closer to your question: would a hexagonal grid have any advantages?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that yes, it would!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First off, I think nearest neighbor would look better.  I don't have any real proof of that sorry, but the hexagon more closely approximates a circle, and since it isn't a regular grid of data, i think your eye is getting a better distribution of data.  Sorry, that is a little hand wavey.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the big part of why it would look better though is that linear filtering would be taking information from 6 neighbors instead of 4, and would be interpolating on 3 axis instead of 2.  More information from less regularly spaced samples than a grid gives you = better resulting image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing cubic interpolation would also be better than cubic interpolation on a grid, so the quality scales up as you scale up the quality of your algorithm too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as whether it stores data more efficiently, the fact that it can do better filtering with less data means to me that yes, it could store data more efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And i guess lastly... maybe you could use these properties to your advantage.  Maybe you could have an image format stored in a lower res hexagonal format, and then before you needed to display the image at runtime, you could use sampling algorithms to convert it back to a grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe there'd even be a good way to do this efficiently in a pixel shader, so it would use less memory at runtime too?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's an interesting idea (:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS - how cool would it be to have an analog display (no individual pixels, but a continuous colored surface) that looked at the pixel data you sent not as rectangles, but instead as sample points on a continuous surface.  Maybe a bit out there though....&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-05T18:53:15.353" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="75" PostTypeId="2" ParentId="65" CreationDate="2015-08-05T20:52:43.003" Score="7" Body="&lt;p&gt;I'm not sure that there's a truly &lt;em&gt;optimal&lt;/em&gt; radius&amp;mdash;it's going to be a subjective matter based on what the image looks like.  As you say, too large a radius results in blurring and too small a radius results in aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I like to set sigma = 0.5 px, so that the overall radius is about 1.5 px (since the Gaussian has the majority of its weight within ±3 sigma of its mean).  In my experience that gives a good trade-off between blurring and aliasing, but that's just my taste, not based on any objective considerations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, as part of &lt;a href=&quot;http://www.reedbeta.com/blog/2014/11/15/antialiasing-to-splat-or-not/&quot;&gt;a blog post on antialiasing&lt;/a&gt; I wrote last year (which was based on an answer I posted on the previous incarnation of this site!), I tested a variety of antialiasing kernels against a synthetic test image and came out with 0.5 px Gaussian as my subjective favorite.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-05T20:52:43.003" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="76" PostTypeId="2" ParentId="65" CreationDate="2015-08-05T20:58:28.940" Score="2" Body="&lt;p&gt;In my opinion and experience i don't think there exists an univocal answer... since basically in literature you can easily find example of adaptive filters too (i.e. of variable size). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the actual answer should be related to the both context of applications (i.e. hardware or sofware, real time or not) and kind of scene you're going to synthesize (some scenes usually involves different kind of aliasing when are synthetized (i use this general term on purpose)). Basically computer graphics is the study of algorithms and data structure for image synthesis, and such definition isn't stricly related to any kind of application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course an important factor is even the goal to be achieved by a filtering process (i.e. not necessary an excessive blurring could be bad...).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're speaking of &quot;nice to see&quot; i think you could agree with me when i say that there's no specific measure of &quot;pleasant image&quot;.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2015-08-05T20:58:28.940" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="77" PostTypeId="2" ParentId="58" CreationDate="2015-08-05T22:04:17.097" Score="8" Body="&lt;p&gt;Generally, uniformly-weighted samples with a variable distribution (importance sampling) gives lower variance in the final average than uniformly-distributed samples with variable weights.  This is a common rule of thumb in Monte Carlo raytracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, another thing to consider is that you'll eventually be converting the images to RGB for display (I assume).  So a potential problem might be that if a light source has very little energy in the blue part of the spectrum, for instance, then you'll put few samples in the blue frequencies, and the blue channel of the final RGB image could end up excessively noisy compared to the other channels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to resolve this might be to consider the product of the light source's spectrum with the RGB color-matching curves used to generate the output.  You could normalize the three against each other to ensure you get enough samples in all three channels, but still distribute the samples to the most important frequencies for each channel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On balance, I suspect that simply using a uniform frequency distribution of samples will be simpler and give good results as long as the light source spectra are fairly smooth.  But if you have spectra with sharp spikes (e.g. LEDs, lasers, fluorescent lamps) then spectral importance sampling will probably be necessary.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-05T22:04:17.097" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="78" PostTypeId="2" ParentId="38" CreationDate="2015-08-05T22:23:19.080" Score="11" Body="&lt;p&gt;That blog post that John mentions is a pretty good start (if I do say so myself!), but there's a bit of extra detail that might be helpful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the PowerVR architecture, the intermediate data structure -- variously called the primitive list or parameter buffer (PB) -- that stores the per-tile data, after all vertex shading and the tiling process is complete, is actually mostly generated and managed by the hardware, rather than the driver.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The PB's in-memory structures are physically split into two. First, blocks of transformed vertex data, including vertex attributes. The blocks are compressed, and as you can imagine they're just packed and compressed floating point data for the most part. The second in-memory structure is the tiling data, which is effectively a list of lists.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The top level list in that data structure is called a region, and it can encode a set of tiles rather than single tile at a time, for a given primitive block. A region is therefore a set of locations of screen tiles, tile states, and then a list of the compressed blocks that hold geometry in that region. Regions are what the rasteriser works on, and you can imagine that empty tiles are just automatically skipped, although there's a good reason in some cases for the rasteriser to visit empty regions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The memory the GPU uses for the PB is dynamically allocated in all modern PowerVR implementations. A pointer to that memory is provided by the driver, and the driver, with the GPU's help, will size it as required. That mechanism is a tradeoff between having to reallocate frequently and minimising the amount of allocated PB space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern GPUs try really hard to minimise memory indirection, but walking the PB to feed the rasterisation stage is one of those cases where it's really difficult and there's no other choice. Thankfully the pointer chasing wraps up large blocks that cache well and are streamed into the core.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other architectures don't work exactly the same as PowerVR, because part of the reason the PB is the way it is in our architecture is to help the fully deferred pixel shading concept we implement, but the general concept applies to all other tilers in the mobile space that I'm aware of.&lt;/p&gt;&#xA;" OwnerUserId="259" LastActivityDate="2015-08-05T22:23:19.080" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="79" PostTypeId="2" ParentId="23" CreationDate="2015-08-06T04:25:20.727" Score="11" Body="&lt;p&gt;I tested several applications/APIs/libraries to get data from FBOs in applications which use gbuffer for example. After months of suffering I discovered &lt;a href=&quot;https://apitrace.github.io/&quot;&gt;apitrace&lt;/a&gt; available on Github to debug OpenGL, Direct3D and WebGL. I used in Windows and Linux without problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that could be useful for you.&lt;/p&gt;&#xA;" OwnerUserId="262" LastEditorUserId="260" LastEditDate="2015-08-06T04:28:51.917" LastActivityDate="2015-08-06T04:28:51.917" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="80" PostTypeId="2" ParentId="68" CreationDate="2015-08-06T06:12:42.647" Score="11" Body="&lt;p&gt;The de facto standard color space for digital images these days is &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB&quot;&gt;sRGB&lt;/a&gt;.  sRGB is a good default assumption if working with a display whose exact color space is not known (i.e. most random displays someone might run your app on), or images whose color space encoding is not known (i.e. most random image files you might encounter).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sRGB standard defines the &lt;a href=&quot;https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_xy_chromaticity_diagram_and_the_CIE_xyY_color_space&quot;&gt;CIE chromaticity&lt;/a&gt; of the pure red, green, and blue primaries and the white point&amp;mdash;in other words, it defines what those primaries and white should perceptually look like relative to pure wavelengths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;sRGB also defines a gamma curve that's used for encoding the RGB values.  The gamma curve is the part that graphics programmers are usually concerned with, as we have to convert colors back and forth between sRGB and linear to do lighting math physically-correctly.  All modern GPUs have sRGB support built in: they can automatically apply the gamma transformations in hardware when sampling a texture, or writing a pixel value to a render target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as monitors are concerned, with a high-quality one it should be possible to calibrate its settings (or it may come pre-calibrated) so that its output matches sRGB as faithfully as possible.  In case the monitor itself can't do it, a limited amount of color correction can also be done on the GPU during scan-out; there are some small hardware lookup tables that the RGB values are mapped through before being sent out over the wire.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might also come across &lt;a href=&quot;https://en.wikipedia.org/wiki/Rec._709&quot;&gt;Rec. 709&lt;/a&gt;, which is the standard color space for HDTVs; it's very similar to sRGB, using the same primaries and white point, but a slightly different gamma curve.  Some high-end monitors use the &lt;a href=&quot;https://en.wikipedia.org/wiki/Adobe_RGB_color_space&quot;&gt;Adobe RGB&lt;/a&gt; color space, which is somewhat wider-gamut than sRGB; photographers tend to like those because they more faithfully represent what photos will look like when printed.  The next generation of HDR TVs coming out (hopefully) in the next few years will use &lt;a href=&quot;https://en.wikipedia.org/wiki/Rec._2020&quot;&gt;Rec. 2020&lt;/a&gt;, which has a huge gamut and requires 10 or 12 bits per component rather than 8.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to come back to your question whether you need to worry about different monitors having different gamma: not much.  For gaming and general PC graphics you can pretty much assume sRGB, and figure that if the user really cares about color accuracy, they'll have a good, calibrated monitor.  If you're producing software for photographers or print media, or for next-gen HDR video standards, then you might have to start worrying about wide-gamut color spaces.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-06T06:12:42.647" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="81" PostTypeId="1" AcceptedAnswerId="82" CreationDate="2015-08-06T06:34:33.160" Score="18" ViewCount="2618" Body="&lt;p&gt;If you read papers about subsurface scattering, you'll frequently come across references to something called the &quot;dipole approximation&quot;.  This term seems to go back to the paper &lt;a href=&quot;https://graphics.stanford.edu/papers/bssrdf/bssrdf.pdf&quot;&gt;A Practical Model for Subsurface Light Transport&lt;/a&gt; by Henrik Wann Jensen et al, but this paper is pretty difficult to understand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain in relatively simple terms what the dipole approximation is and how it's used in rendering subsurface scattering?&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-02-23T18:43:31.500" Title="What is the &quot;dipole approximation&quot; for subsurface scattering?" Tags="&lt;rendering&gt;&lt;subsurface-scattering&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="82" PostTypeId="2" ParentId="81" CreationDate="2015-08-06T07:31:40.703" Score="23" Body="&lt;p&gt;The assumption underlying such model is the same as lots of other models for skin rendering; the subsurface scattering can be approximated as a diffusion phenomenon. This is good because in highly scattering media, the distribution of light loses dependency from the angle and tends to isotropy. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The dipole approximation is a formulation for the resolution of such diffusion problem in an analytical fashion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically they start by approximating the BSSRDF as a multiple scattering and single scattering component. The multiple scattering is then defined as: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3OivX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3OivX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $F_t$ are Fresnel terms and $R$ is the diffusion profile expressed as function of the distance between the entry and exit point.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This $R$ is referred to as diffusion profile and they formulate this profile via a dipole approximation. The contribution of the incoming light ray is considered to be the one of two virtual sources: one negative beneath the surface and one positive above it (that's why dipole) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CJQLF.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CJQLF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here in the picture r is the $\|x_i - x_o\|$ above.  The contribution of those light sources is dependent on various factors such as the distance of the light from the surface, scattering coefficient etc. (See below for a more detailed description of the formula itself). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This model only account for multiple scattering events, but that's fine enough for skin. It must be noticed though that for some translucent materials (e.g. smoke and marble) the single scattering is fundamental. That paper propose a single scattering formulation, but is expensive. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The diffusion profile is usually approximated for real-time application as a series of gaussian blurs (like in the seminal works of D'Eon et al. in GPU Gems 3 then used for the Jimenez's SSSSS) so to make it practical for real time scenarios. In &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems3/gpugems3_ch14.html&quot; rel=&quot;noreferrer&quot;&gt;this wonderful paper&lt;/a&gt; there are details on such approximation. &#xA;A picture from that paper show actually how good is this formulation: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0GcPn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0GcPn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As side note the dipole approximation assumes that the material is semi-infinite, however this assumption doesn’t hold with thin slabs and multi-layered material such as the skin. Building on the dipole work, Donner and Jensen [2005] proposed the multi-pole approximation that accounts for the dipole problems. &#xA;With this model instead of a single dipole, the authors use a set of them to describe the scattering phenomenon. In such formulation the reflectance and transmittance profiles can be obtained by summing up the contribution of the different dipoles involved&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;EDIT: &#xA;I am putting here the answers to a couple of @NathanReed 's questions in the comment section:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Even with the diffusion profile approximation, the BSSRDF model still requires integrating over a radius of nearby points on the surface to gather incoming light, correct? How is that accomplished in, say, a path tracer? Do you have to build some data structure so you can sample points on the surface nearby a given point?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The BSSRDF approximation still need to be integrated over a certain area, yes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the paper linked they used a Montecarlo ray-tracer randomly sampling around a point with a density defined as: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\sigma_{tr}e^{-\sigma_{tr}d}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where that sigma value is the effective extinction coefficient defined below ( it is dependent on scattering and absorbing coefficient, which are properties of the material) and d is the distance to the point we are evaluating. This density is this way defined because the diffusion term has exponential fall-off. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In &lt;a href=&quot;http://graphics.ucsd.edu/~henrik/papers/fast_bssrdf/fast_bssrdf.pdf&quot; rel=&quot;noreferrer&quot;&gt;[Jensen and Buhler 2002]&lt;/a&gt; they proposed an acceleration technique. One of the main concepts was to decouple the sampling from the evaluation of the diffusion term. This way they perform a hierarchical evaluation of the information computed during the sampling phase to cluster together distant samples when it comes to evaluating the diffusion. The implementation described in the paper uses an octree as structure. &#xA;This technique, according to the paper, is order of magnitude faster than the full Monte Carlo integration.&lt;br&gt;&#xA;Unfortunately I never got myself into an off-line implementation, so I can't help more than this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the real-time sum-of-Gaussians approximations the correct radius is implicitly set when defining the variance of the Gaussian blurs that need to be applied.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Why one positive and one negative light? Is the goal for them to cancel each other in some way?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, the dipole source method (which dates way before Jensen's paper) is such defined to satisfy some boundary condition. Specifically the fluence must be zero at a certain extrapolated boundary that has a distance from the surface of $2AD$ where &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rOdqD.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rOdqD.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Being $F_{dr}$ the fresnel reflectivity of the slab considered and that sigma value is the reduced extinction coefficient described below. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;EDIT2: I have expanded (a tiny bit) some of the concepts in this answer in a blog post: &lt;a href=&quot;http://bit.ly/1Q82rqT&quot; rel=&quot;noreferrer&quot;&gt;http://bit.ly/1Q82rqT&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;For those who are not scared by lots of greek letters in a formula, here's an extract from my thesis where the reflectance profile is briefly described in each term: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xtQG8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xtQG8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2016-02-10T21:56:10.297" LastActivityDate="2016-02-10T21:56:10.297" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="83" PostTypeId="1" CreationDate="2015-08-06T13:41:45.743" Score="7" ViewCount="268" Body="&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/68/is-gamma-still-important-to-take-into-account&quot;&gt;Trichoplax question&lt;/a&gt; aroused my curiosity and &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/11445/gamma-vs-brightness-any-difference&quot;&gt;the answers in this question&lt;/a&gt; also reminded me why I sometimes use different gamma &quot;amounts&quot; to enhance images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, is it possible to determine the amount of gamma applied to an image by knowing its source (the original image)? I.e. can the mathematical formula be applied to compare two images and determine the difference in gamma &quot;amount&quot;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example: which of the following have a different gamma amount (I'll give you a non-edible cookie if you find out, and sorry trichoplax for snatching &lt;a href=&quot;https://i.stack.imgur.com/iukw5.png?s=328&amp;amp;g=1&quot; rel=&quot;nofollow noreferrer&quot;&gt;your ball&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/msMpT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/msMpT.png&quot; alt=&quot;t_1&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/qMPrK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qMPrK.png&quot; alt=&quot;t_2&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/5GsqI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5GsqI.png&quot; alt=&quot;t_3&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/NxJLB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NxJLB.png&quot; alt=&quot;t_4&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-11-03T14:47:58.327" Title="Brightness and contrast VS Gamma, is it possible to identify the gamma &quot;correction amount&quot;?" Tags="&lt;color&gt;&lt;gamma&gt;&lt;brightness&gt;&lt;image-comparison&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="84" PostTypeId="2" ParentId="83" CreationDate="2015-08-06T14:04:38.327" Score="6" Body="&lt;p&gt;If I get correctly what you are asking you basically just need to find the G in this equation: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$Image_{out} = Image_{in}^G$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This could be easily solved as &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$G = \frac{\log{Image_{out}}}{\log{Image_{in}}}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because usually gamma is applied in a uniform fashion on the image, you can just pick any two non zero pixel values (one for source and one for destination) to find out the gamma value applied.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: As @ChristianRau pointed out, if you don't actually know if the image has been modified with gamma correction, you have to take an higher amount of samples and trying to fit a gamma function on those. If a fit to a gamma function results in too many significant outliers, then probably gamma correction wasn't the function applied. &lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="137" LastEditDate="2015-11-03T14:47:58.327" LastActivityDate="2015-11-03T14:47:58.327" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="85" PostTypeId="1" AcceptedAnswerId="86" CreationDate="2015-08-06T14:53:38.463" Score="10" ViewCount="1297" Body="&lt;p&gt;Bicubic sampling is pretty good for up sampling an image and making it larger,  but is it a good choice for down sampling as well? Are there better choices?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-06T18:02:02.100" Title="Algorithms for down sampling an image?" Tags="&lt;texture&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="86" PostTypeId="2" ParentId="85" CreationDate="2015-08-06T15:07:23.013" Score="12" Body="&lt;p&gt;When Sean and I wrote &lt;a href=&quot;https://github.com/nothings/stb/blob/master/stb_image_resize.h&quot;&gt;stb_image_resize&lt;/a&gt; we chose Mitchell for downsizing. Mitchell is similar to Cubic, you can read about the cubic class of sampling filters in &lt;a href=&quot;http://www.cs.utexas.edu/~fussell/courses/cs384g-fall2013/lectures/mitchell/Mitchell.pdf&quot;&gt;Mitchell Netravali 1988&lt;/a&gt;. They are all pretty similar and will get you very similar results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't find any written record between Sean and I of why we decided to go with Mitchell, but if memory serves we just resampled a bunch of images and used the algorithm that we thought looked best. I wouldn't say that there is one authoritative or best filter, you should use the one that looks best on your data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: Like joojaa says, a windowed sinc filter is also good, if not quite as cheap. You can find some implementations &lt;a href=&quot;https://code.google.com/p/imageresampler/source/browse/trunk/resampler.cpp#266&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="125" LastEditorUserId="125" LastEditDate="2015-08-06T18:02:02.100" LastActivityDate="2015-08-06T18:02:02.100" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="87" PostTypeId="2" ParentId="5" CreationDate="2015-08-06T19:04:26.033" Score="10" Body="&lt;p&gt;One possible approach could be the use of Hardware Occlusion Query.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can use the facts that, by specification, the Stencil Test is executed before the depth test, and only the fragments that pass the depth test are counted by the Occlusion Query.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple example (not tested) would be like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    GLuint samples_query = 0;&#xA;    GLuint samples_passed = 0;&#xA;    glGenQueries(1, &amp;amp;samples_query);&#xA;    // Initialize your buffers and textures ...&#xA;    glEnable(GL_DEPTH_TEST);&#xA;    glEnable(GL_STENCIL_TEST);&#xA;&#xA;    // Set up the values on the stencil buffer ...&#xA;&#xA;    // Now we count the fragments that pass the stencil test&#xA;    glDepthFunc(GL_ALWAYS); // Set up the depth test to always pass&#xA;    glBeginQuery(GL_SAMPLES_PASSED, samples_query);&#xA;    // Render your meshes here&#xA;    glEndQuery(GL_SAMPLES_PASSED);&#xA;    glGetQueryObjectuiv(samples_query, GL_QUERY_RESULT, &amp;amp;samples_passed);&#xA;    // samples_passed holds the number of fragments that passed the stencil test (if any)&#xA;&#xA;    // Release your resources ...&#xA;    glDeleteQueries(1, &amp;amp;samples_query);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that the call to obtain the number of samples will call forcibly the flush of the pipeline and wait for the query to finish.&#xA;If you need a more asynchronous approach you can query wether the occlusion query is done or not by using:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    GLuint query_done = 0;&#xA;    glGetQueryObjectuiv(samples_query, GL_QUERY_RESULT_AVAILABLE, &amp;amp;query_done);&#xA;    if (query_done != 0)&#xA;        // Your query result is ready&#xA;    else&#xA;        // Maybe check the next frame?&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="281" LastEditorUserId="281" LastEditDate="2015-08-07T09:06:45.063" LastActivityDate="2015-08-07T09:06:45.063" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="88" PostTypeId="1" AcceptedAnswerId="108" CreationDate="2015-08-06T21:21:07.490" Score="3" ViewCount="275" Body="&lt;p&gt;Start with a precalculated &quot;ray cloud&quot; - the starting point and direction of a large number of rays, most of which will not contribute to the image. The image plane's position and orientation are then specified, and the task is to search the ray cloud for rays that intersect the image plane without occlusion by other objects, and output the resulting pixel values. No ray reflections would be required, as all of the work has already been done in generating the ray cloud. The only step left is to convert the rays to an image. This means that a single ray cloud can be used to generate images from arbitrary view angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How could I go about accelerating this process using a GPU? The decision for each ray of whether it intersects the image plane is parallelisable as these decisions are independent, but each requires access to the objects in the scene as some rays will reach some potential image planes but not others. The final step of sampling the relevant rays across the pixels of the image requires each ray to contribute to a number of the surrounding pixels. Is this also parallelisable using a GPU?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To clarify, &lt;a href=&quot;https://computergraphics.stackexchange.com/users/310/richiesams&quot;&gt;RichieSams&lt;/a&gt;' understanding is correct:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Start with a set of rays pointing in arbitrary directions.&lt;/li&gt;&#xA;&lt;li&gt;Find which of these rays intersect with the image plane, taking into account occlusion. &lt;/li&gt;&#xA;&lt;li&gt;Calculate the colour of each pixel based on the rays that hit the image plane.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Ideally I would like to be able to accelerate this process sufficiently to move around a scene in real time, given a precomputed ray cloud over the whole scene.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-11T12:14:14.533" Title="Can I accelerate rendering an image from a ray cloud using a GPU?" Tags="&lt;raytracing&gt;&lt;gpu&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="89" PostTypeId="1" AcceptedAnswerId="195" CreationDate="2015-08-06T21:41:28.387" Score="12" ViewCount="316" Body="&lt;p&gt;I want to render realistic images of water in an orbiting space habitat. The image does not need to be generated in real time, although I wouldn't want it to take weeks either. I'm looking for an approach that can generate realistic images in hours or days.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The habitat is cylindrical with the curved inner surface being the living space. Rotation of the cylinder about it's axis provides an approximation of gravity. I'm not looking for details of simulating the physics of this, just the rendering of an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The specific aspect I want to know about is polarisation. Light reflected from the surface of water is polarised, leaving the light that passed into the water polarised perpendicularly to the reflected light. Ignoring this effect and simply modelling the proportions of light that are reflected and transmitted works reasonably well when there is only one water surface, but if the cylindrical habitat has bodies of water that take up large proportions of the curved surface then a given ray will make multiple reflections at a wide range of different angles. This means the proportion of light that is reflected will depend on the polarisation angle previously applied to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there existing approaches that incorporate such effects that could give realistic images of multiple reflections from a curved water surface? They would also need to model refraction with polarisation. The water will be shallow in places so I'm expecting polarised refraction to influence the results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If not, could I adapt an existing ray tracer or would this need an approach starting from scratch?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking for realism in order to discover unexpected effects, not just to pass as realistic to a casual observer. Obviously most observers (including me) won't know the effects to look for since they aren't familiar from everyday life, so I'm looking for &quot;reasonably physically correct&quot; rather than just &quot;convincing&quot;.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-11T05:45:18.720" Title="Polarising reflection and refraction for a wrap around water surface" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;reflection&gt;&lt;refraction&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="90" PostTypeId="1" AcceptedAnswerId="92" CreationDate="2015-08-06T21:47:38.553" Score="9" ViewCount="719" Body="&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Double-slit_experiment&quot;&gt;Young's double slit experiment&lt;/a&gt; is very simple to set up and simple to explain, but it is an example of both diffraction and interference, neither of which are modelled by conventional raytracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is straightforward to render an approximation of the result using textures, but that would require knowing in advance what the result should be. For an arbitrary set up, where the number and arrangement of slits is not known in advance, are there any existing algorithms for modelling the effect in order to generate the correct resulting image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If not, what would a model need to include in order to accurately produce these effects? Can ray tracing be adapted to use rays carrying additional information, or would an entirely new approach be required?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="30" LastEditDate="2015-08-07T16:52:10.167" LastActivityDate="2015-08-07T16:52:10.167" Title="Modelling Young's double slit experiment" Tags="&lt;raytracing&gt;&lt;algorithm&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="91" PostTypeId="1" AcceptedAnswerId="113" CreationDate="2015-08-06T22:03:19.767" Score="7" ViewCount="196" Body="&lt;p&gt;Is it realistic to render a super-high resolution image over an array of 3 by 3 or 5 by 5 (for example) stacked screens? Could I do this by combining several different GPUs, or would the only way be to use a GPU per screen and simply divide the image to be rendered?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally I'd like to be able to use fewer GPUs than screens. Even though one GPU is insufficient I'm hoping I won't need n GPUs for n screens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this is possible I'd also need to know whether this requires using the same make and model of GPU or whether unrelated ones could still share processing.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-07T08:46:51.577" LastActivityDate="2015-08-08T07:46:26.633" Title="Can I use several GPUs for a grid multi screen image?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="92" PostTypeId="2" ParentId="90" CreationDate="2015-08-06T22:12:49.037" Score="9" Body="&lt;p&gt;It is in fact possible to augment a ray tracer to make it capable of simulating wave effects. The paper &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.369.2189&amp;amp;rep=rep1&amp;amp;type=pdf&quot;&gt;Rendering Wave Effects with Augmented Light Field&#xA;&lt;/a&gt; describes one way to do it. In summary, they introduce a framework called Augmented Light Field that allows them to model wave effects with a ray-based representation. In this framework, rays can carry negative radiance in addition to positive radiance; intuitively, rays carrying negative radiance can &quot;subtract&quot; light from surfaces that it cannot reach because of interference effects, for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't implemented it personally, and I can't speak for its implementation complexity, but I believe it is a good starting point.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-06T22:12:49.037" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="93" PostTypeId="2" ParentId="88" CreationDate="2015-08-07T04:01:49.707" Score="2" Body="&lt;p&gt;It sounds like the tricky part is that last step where each ray affects neighboring pixels. I would consider an approach where you do the first steps as normal (parallelized as on the CPU) without the last step, and then you do that last bit in a new pass. I'm not sure exactly how your ray contributions work so it's tough to say, but it seems like you should be able to use the results from the first part as input and then do your operation in a second pass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blur is done in a similar manner. The blur is done in one dimension, and then the output of that pass is used as the input of the second pass to blur the other dimension. The result is that the value of some pixel ends up contributing to neighboring pixels, so it's similar to your problem.&lt;/p&gt;&#xA;" OwnerUserId="125" LastActivityDate="2015-08-07T04:01:49.707" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="94" PostTypeId="1" AcceptedAnswerId="111" CreationDate="2015-08-07T05:02:41.923" Score="9" ViewCount="1203" Body="&lt;p&gt;Say I have render targets 0 through N and RT 0 happens to have in its fourth component an alpha channel specified by a material or mask or something.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to have the hardware compositor blend render targets 1 through N using the alpha of the first render target?&lt;/p&gt;&#xA;" OwnerUserId="87" LastActivityDate="2015-08-08T06:30:49.560" Title="Is it possible to alpha blend multiple render targets using a specified alpha?" Tags="&lt;opengl&gt;&lt;directx11&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="95" PostTypeId="1" CreationDate="2015-08-07T07:38:01.290" Score="29" ViewCount="4723" Body="&lt;p&gt;When rendering two overlapping co-planar surfaces, a common issue is &quot;z-fighting&quot;, where the renderer can't decide which of the two surfaces is closer to the camera, giving visual artifacts in the area of overlap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The standard solution to this is to give the surfaces a slight offset when designing the model.  Is there any other solution?&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2017-09-13T19:23:35.453" Title="Avoiding z-fighting with coincident surfaces" Tags="&lt;rendering&gt;" AnswerCount="3" CommentCount="5" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="96" PostTypeId="1" AcceptedAnswerId="101" CreationDate="2015-08-07T08:24:33.827" Score="61" ViewCount="41073" Body="&lt;p&gt;When writing non-trivial shaders (just as when writing any other piece of non-trivial code), people make mistakes.&lt;sup&gt;[citation needed]&lt;/sup&gt; However, I can't just debug it like any other code - you can't just attach gdb or the Visual Studio debugger after all. You can't even do printf debugging, because there's no form of console output. What I usually do is render the data I want to look at as colour, but that is a very rudimentary and amateurish solution. I'm sure people have come up with better solutions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how can I actually debug a shader? Is there a way to step through a shader? Can I look at the execution of the shader on a specific vertex/primitive/fragment?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(This question is specifically about how to debug shader code akin to how one would debug &quot;normal&quot; code, not about debugging things like state changes.)&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2021-04-15T09:13:43.097" Title="How can I debug GLSL shaders?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;debugging&gt;" AnswerCount="6" CommentCount="6" FavoriteCount="12" ContentLicense="CC BY-SA 3.0" />
  <row Id="97" PostTypeId="2" ParentId="96" CreationDate="2015-08-07T09:39:47.633" Score="5" Body="&lt;p&gt;While it doesn't seem to be possible to actually step through an OpenGL shader, it is possible to get the compilation results.&lt;br&gt;&#xA;The following is taken from the &lt;a href=&quot;https://github.com/googlesamples/cardboard-java/blob/master/CardboardSample/src/main/java/com/google/vrtoolkit/cardboard/samples/treasurehunt/MainActivity.java&quot;&gt;Android Cardboard Sample&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {&#xA;    Log.e(TAG, label + &quot;: glError &quot; + error);&#xA;    throw new RuntimeException(label + &quot;: glError &quot; + error);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If your code compiles properly, then you have little choice but to try out a different way of communicating the program's state to you. You could signal that a part of the code was reached by, for example, changing the color of a vertex or using a different texture. Which is awkward, but seems to be the only way for now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: For WebGL, I am looking at &lt;a href=&quot;http://benvanik.github.io/WebGL-Inspector/&quot;&gt;this project&lt;/a&gt;, but I've only just found it... can't vouch for it. &lt;/p&gt;&#xA;" OwnerUserId="21" LastActivityDate="2015-08-07T09:39:47.633" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="98" PostTypeId="1" AcceptedAnswerId="105" CreationDate="2015-08-07T10:27:48.687" Score="8" ViewCount="1373" Body="&lt;p&gt;I'm looking to use my GPU for non-graphical calculations (artificial life simulations) but ideally I would like to leave this running for weeks at a time, 24 hours a day.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there anything I should take into account before trying this? Is a GPU subject to overheating or shortening of its lifespan by continuous use?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What about the computer in general (it's a laptop in my case, but I'm interested in the differences in case it's worth me getting a desktop computer for this)? Will running the GPU non-stop place any strain on connected parts of the computer? Are there known problems that result from this?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-07T18:57:35.670" Title="Is long term continuous use of GPGPU safe for my GPU?" Tags="&lt;gpu&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="99" PostTypeId="2" ParentId="98" CreationDate="2015-08-07T10:43:06.360" Score="4" Body="&lt;p&gt;No, and yes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You're well advised to stay away from stress testing your GPU, or CPU, or any tool for that matter that can be exhausted. In this case it's your GPU, and it definitely can be exhausted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, if you are using a GPU as a GPU, it's much like using a car as a car. If you use it appropriately it will last a long time and do it's functions, vice versa for inappropriate use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the GPU a lot will put strain on the motherboard, i.e. physical connectors, PCI-e bus, etc. But so will using it once a week for a year.&#xA;Overheating will only be a problem if your simulation is spending most if not all of the GPU's resources and a fault occurs in the cooling.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;it's a laptop in my case, &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I definitely would not run a laptop more than 12 hours a day without expecting a fast and hot demise.&lt;/p&gt;&#xA;" OwnerUserId="296" LastActivityDate="2015-08-07T10:43:06.360" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="100" PostTypeId="1" AcceptedAnswerId="109" CreationDate="2015-08-07T12:37:50.097" Score="35" ViewCount="16040" Body="&lt;p&gt;I often find myself copy-pasting code between several shaders. This includes both certain computations or data shared between all shaders in a single pipeline, and common computations which all of my vertex shaders need (or any other stage).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, that's horrible practice: if I need to change the code anywhere, I need to make sure I change it everywhere else.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an accepted best practice for keeping &lt;a href=&quot;https://en.wikipedia.org/wiki/Don%27t_repeat_yourself&quot;&gt;DRY&lt;/a&gt;? Do people just prepend a single common file to all their shaders? Do they write their own rudimentary C-style preprocessor which parses &lt;code&gt;#include&lt;/code&gt; directives? If there are accepted patterns in the industry, I'd like to follow them.&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2015-08-10T19:16:27.473" Title="Sharing code between multiple GLSL shaders" Tags="&lt;glsl&gt;" AnswerCount="4" CommentCount="7" FavoriteCount="15" ContentLicense="CC BY-SA 3.0" />
  <row Id="101" PostTypeId="2" ParentId="96" CreationDate="2015-08-07T13:14:59.983" Score="33" Body="&lt;p&gt;As far as I know there are no tools that allows you to steps through code in a shader (also, in that case you would have to be able to select just a pixel/vertex you want to &amp;quot;debug&amp;quot;, the execution is likely to vary depending on that).&#xA;(NOTE: Renderdoc allows you to do so by selecting a specific thread/pixel)&lt;/p&gt;&#xA;&lt;p&gt;What I personally do is a very hacky &amp;quot;colourful debugging&amp;quot;. So I sprinkle a bunch of dynamic branches with &lt;code&gt;#if DEBUG / #endif&lt;/code&gt; guards that basically say&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#if DEBUG&#xA;if( condition ) &#xA;    outDebugColour = aColorSignal;&#xA;#endif&#xA;&#xA;.. rest of code .. &#xA;&#xA;// Last line of the pixel shader&#xA;#if DEBUG&#xA;OutColor = outDebugColour;&#xA;#endif&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So you can &amp;quot;observe&amp;quot; debug info this way. I usually do various tricks like lerping or blending between various &amp;quot;colour codes&amp;quot; to test various more complex events or non-binary stuff.&lt;/p&gt;&#xA;&lt;p&gt;In this &amp;quot;framework&amp;quot; I also find useful to have a set of fixed conventions for common cases so that if I don't have to constantly go back and check what colour I associated with what.&#xA;The important thing is have a good support for hot-reloading of shader code, so you can almost interactively change your tracked data/event and switch easily on/off the debug visualization.&lt;/p&gt;&#xA;&lt;p&gt;If need to debug something that you cannot display on screen easily, you can always do the same and use one frame analyser tool to inspect your results. I've listed a couple of them &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/23/how-can-i-debug-what-is-being-rendered-to-a-frame-buffer-object-in-opengl/25#25&quot;&gt;as answer of this other question.&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Obv, it goes without saying that if I am not &amp;quot;debugging&amp;quot; a pixel shader or compute shader, I pass this &amp;quot;debugColor&amp;quot; info throughout the pipeline without interpolating it (in GLSL with &lt;code&gt; flat &lt;/code&gt; keyword )&lt;/p&gt;&#xA;&lt;p&gt;Again, this is very hacky and far from proper debugging, but is what I am stuck with not knowing any proper alternative.&lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2021-04-15T09:13:43.097" LastActivityDate="2021-04-15T09:13:43.097" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="102" PostTypeId="2" ParentId="100" CreationDate="2015-08-07T14:26:32.683" Score="11" Body="&lt;p&gt;I generally just use the fact that glShaderSource(...) accepts an array of strings as it's input.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use a json-based shader definition file, which specifies how a shader (or a program to be more correct) is composed, and there I specify the preprocessor defines I may need, the uniforms it uses, the vertex/fragment shaders file, and all the additional &quot;dependency&quot; files.&#xA;These are just collections of functions that gets appended to the source before the actual shader source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just to add, AFAIK, the Unreal Engine 4 uses an #include directive that gets parsed and append all the relevant files, before the compilation, as you were suggesting.&lt;/p&gt;&#xA;" OwnerUserId="281" LastActivityDate="2015-08-07T14:26:32.683" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="103" PostTypeId="1" AcceptedAnswerId="112" CreationDate="2015-08-07T14:42:38.660" Score="8" ViewCount="291" Body="&lt;p&gt;Apparently bicubic pixel interpolation is good for scaling up or down an image (in real time or not).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it recommended to use a lowpass filter before downsizing though, or does the bicubic sampling handle aliasing problems at all?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-08T07:11:05.800" Title="Do you need to use a lowpass filter before downsizing an image?" Tags="&lt;texture&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="104" PostTypeId="2" ParentId="96" CreationDate="2015-08-07T18:39:26.880" Score="10" Body="&lt;p&gt;There is also &lt;a href=&quot;https://github.com/GLSL-Debugger/GLSL-Debugger&quot;&gt;GLSL-Debugger&lt;/a&gt;. It is a debugger used to be known as &quot;GLSL Devil&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Debugger itself is super handy not only for GLSL code, but for OpenGL itself as well. You have the ability to jump between draw calls and break on Shader switches. It also shows you error messages communicated by OpenGL back to the application itself.&lt;/p&gt;&#xA;" OwnerUserId="307" LastActivityDate="2015-08-07T18:39:26.880" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="105" PostTypeId="2" ParentId="98" CreationDate="2015-08-07T18:57:35.670" Score="7" Body="&lt;p&gt;Running a GPU at full capacity will reduce its lifespan through &lt;a href=&quot;https://en.wikipedia.org/wiki/Electromigration&quot;&gt;electromigration&lt;/a&gt;; the speed at which the chips are damaged depends on how hot it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A desktop computer has enough room that the designer can put in a cooling system to handle the worst-case thermal situation.  Running your GPU at continuous full load won't overheat it too badly, and you can expect it to last several years.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A laptop, on the other hand, is strongly space-constrained.  Typically, the cooling system is designed to handle brief bursts of heat interspersed with long periods of near-idle operation.  You may not be &lt;em&gt;able&lt;/em&gt; to run it at full load 24/7: the BIOS or operating system will slow things down to keep from overheating.  In any case, running at full capacity will likely cause things to burn out in a year or less.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-07T18:57:35.670" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="106" PostTypeId="2" ParentId="100" CreationDate="2015-08-07T19:11:21.303" Score="5" Body="&lt;p&gt;I don't think there is a common convention, but if I'd take a guess, I'd say that almost everyone implements some simple form of textual inclusion as a preprocessing step (an &lt;code&gt;#include&lt;/code&gt; extension), because it is very easy to do so. (In JavaScript/WebGL, you can do that with a simple regular-expression, for example). The upside of this is that you can perform the preprocessing in an offline step for &quot;release&quot; builds, when the shader code no longer needs to be changed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact, an indication that this approach is common is the fact that an ARB extension was introduced for that: &lt;a href=&quot;https://www.opengl.org/registry/specs/ARB/shading_language_include.txt&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;GL_ARB_shading_language_include&lt;/code&gt;&lt;/a&gt;.&#xA;I'm not sure if this became a core feature by now or not, but the extension was written against OpenGL 3.2.&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="54" LastEditDate="2015-08-07T23:09:16.677" LastActivityDate="2015-08-07T23:09:16.677" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="107" PostTypeId="2" ParentId="95" CreationDate="2015-08-07T20:33:07.803" Score="11" Body="&lt;p&gt;If the surfaces are exactly co-planer, your fate is up to the FPU gods; you'll more than likely have Z-fighting. If the triangles are &lt;em&gt;identical&lt;/em&gt; and you do the &lt;em&gt;exact&lt;/em&gt; same math to each, you &lt;em&gt;will&lt;/em&gt; end up with the same Z-values for both. But again, this will only happen if your math operations are identical for both. (Since, in general, FPU operations are not commutative)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One possible solution is to not use the Z-buffer at all. Rather you can use the &lt;a href=&quot;https://en.wikipedia.org/wiki/Painter%27s_algorithm&quot;&gt;Painter's Algorithm&lt;/a&gt;. Granted, this comes with all the problems of the painters algorithm as well. But, it would solve the Z-fighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your example case of Screen Space Decals (SSDs), the common solution is to use an offset, aka a simple thin cube. See Warhammer 40k's &lt;a href=&quot;http://www.slideshare.net/blindrenderer/screen-space-decals-in-warhammer-40000-space-marine-14699854&quot;&gt;presentation&lt;/a&gt; about SSDs for reference. Or Bart Wronski's &lt;a href=&quot;http://bartwronski.com/2015/03/12/fixing-screen-space-deferred-decals/&quot;&gt;post&lt;/a&gt; which addresses some other issues with decals, but also links to a few other presentations about SSDs&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2015-08-09T18:44:10.750" LastActivityDate="2015-08-09T18:44:10.750" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="108" PostTypeId="2" ParentId="88" CreationDate="2015-08-08T01:15:07.103" Score="3" Body="&lt;p&gt;I'm not quite sure I fully understand the problem, this is what I think you're asking:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You start with a set of rays pointing a all sorts of directions&lt;/li&gt;&#xA;&lt;li&gt;You want to know which of these rays intersect with the image plane, taking into account occlusion. &lt;/li&gt;&#xA;&lt;li&gt;I'm going to assume these rays carry some kind of color information along with them. IE. when they hit the image plane, they will accumulate color.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With that goal in mind, I would do the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create 2 image buffers&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;For accumulated color&lt;/li&gt;&#xA;&lt;li&gt;To keep track of the number of hits&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;li&gt;Clear the accumulation buffer to black, and the hitCount buffer to all zeros&lt;/li&gt;&#xA;&lt;li&gt;Create a kernel per ray&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Use classic ray tracing math to find the nearest intersection&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Here you can do anything from a simple 'iterate through all the object in the scene' to something like BVHs, or kd-trees.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;If the closest intersection is the image plane, use the WorldView matrix for the image plane to transform the intersection point from world coordinates to view space coordinates.&lt;/li&gt;&#xA;&lt;li&gt;Use the x, y coordinates of the image space intersection point to get the pixel coordinates of the image buffer&lt;/li&gt;&#xA;&lt;li&gt;Add the color of the ray to the corresponding pixel in the accumulation buffer&lt;/li&gt;&#xA;&lt;li&gt;Increment the value of the corresponding pixel in the hitCount buffer&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For 4 and 5 you could also use a filter in order to apply the color to multiple pixels, rather than just one. In that case, you would add a value less than 1 to the hitCount buffer&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;li&gt;On the CPU, or in another pass per pixel: &#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Divide the accumulated color buffer by the hitCount buffer&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't see any problem with doing these steps on the GPU. Any of the compute languages should handle it fine. You might get some divergence in the actual ray tracing code, but it should be ok. The biggest potential problem is that you have to store the entire scene in VRAM.&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2015-08-08T01:15:07.103" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="109" PostTypeId="2" ParentId="100" CreationDate="2015-08-08T01:33:56.490" Score="21" Body="&lt;p&gt;There's a bunch of a approaches, but none is perfect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's possible to share code by using &lt;code&gt;glAttachShader&lt;/code&gt; to combine shaders, but this doesn't make it possible to share things like struct declarations or &lt;code&gt;#define&lt;/code&gt;-d constants. It does work for sharing functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some people like to use the array of strings passed to &lt;code&gt;glShaderSource&lt;/code&gt; as a way to prepend common definitions before your code, but this has some disadvantages:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;It's harder to control what needs to be included from within the shader (you need a separate system for this.)&lt;/li&gt;&#xA;&lt;li&gt;It means the shader author cannot specify the GLSL &lt;code&gt;#version&lt;/code&gt;, due to the following statement in the GLSL spec:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The &lt;strong&gt;#version&lt;/strong&gt; directive must occur in a shader before anything else, except for comments and white space.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Due to this statement, &lt;code&gt;glShaderSource&lt;/code&gt; cannot be used to prepend text before the &lt;code&gt;#version&lt;/code&gt; declarations. This means that the &lt;code&gt;#version&lt;/code&gt; line needs to be included in your &lt;code&gt;glShaderSource&lt;/code&gt; arguments, which means that your GLSL compiler interface needs to somehow be told what version of GLSL is expected to be used. Additionally, not specifying a &lt;code&gt;#version&lt;/code&gt; will make the GLSL compiler default to using GLSL version 1.10. If you want to let shader authors specify the &lt;code&gt;#version&lt;/code&gt; within the script in a standard way, then you need to somehow insert &lt;code&gt;#include&lt;/code&gt;-s after the &lt;code&gt;#version&lt;/code&gt; statement. This could be done by explicitly parsing the GLSL shader to find the &lt;code&gt;#version&lt;/code&gt; string (if present) and make your inclusions after it, but having access to an &lt;code&gt;#include&lt;/code&gt; directive might be preferable to control more easily when those inclusions need to be made. On the other hand, since GLSL ignores comments before the &lt;code&gt;#version&lt;/code&gt; line, you could add metadata for includes within comments at the top of your file (yuck.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question now is: Is there a standard solution for &lt;code&gt;#include&lt;/code&gt;, or do you need to roll your own preprocessor extension?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is the &lt;code&gt;GL_ARB_shading_language_include&lt;/code&gt; extension, but it has some drawbacks:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;It is only supported by NVIDIA (&lt;a href=&quot;http://delphigl.de/glcapsviewer/listreports2.php?listreportsbyextension=GL_ARB_shading_language_include&quot; rel=&quot;noreferrer&quot;&gt;http://delphigl.de/glcapsviewer/listreports2.php?listreportsbyextension=GL_ARB_shading_language_include&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;It works by specifying the include strings ahead of time. Therefore, before compiling, you need to specify that the string &lt;code&gt;&quot;/buffers.glsl&quot;&lt;/code&gt; (as used in &lt;code&gt;#include &quot;/buffers.glsl&quot;&lt;/code&gt;) corresponds to the contents of the file &lt;code&gt;buffer.glsl&lt;/code&gt; (which you have loaded previously).&lt;/li&gt;&#xA;&lt;li&gt;As you may have noticed in point (2), your paths need to start with &lt;code&gt;&quot;/&quot;&lt;/code&gt;, like Linux-style absolute paths. This notation is generally unfamiliar to C programmers, and means you can't specify relative paths.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;A common design is to implement your own &lt;code&gt;#include&lt;/code&gt; mechanism, but this can be tricky since you also need to parse (and evaluate) other preprocessor instructions like &lt;code&gt;#if&lt;/code&gt; in order to properly handle conditional compilation (like header guards.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you implement your own &lt;code&gt;#include&lt;/code&gt;, you also have some liberties in how you want to implement it:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You could pass strings ahead of time (like &lt;code&gt;GL_ARB_shading_language_include&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;li&gt;You could specify an include callback (this is done by DirectX's D3DCompiler library.)&lt;/li&gt;&#xA;&lt;li&gt;You could implement a system that always reads directly from the filesystem, as done in typical C applications.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;As a simplification, you can automatically insert header guards for each include in your preprocessing layer, so your processor layer looks like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (#include and not_included_yet) include_file();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(Credit to Trent Reed for showing me the above technique.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In conclusion&lt;/strong&gt;, there exists no automatic, standard, and simple solution. In a future solution, you could use some SPIR-V OpenGL interface, in which case the GLSL to SPIR-V compiler could be outside of the GL API. Having the compiler outside the OpenGL runtime greatly simplifies implementing things like &lt;code&gt;#include&lt;/code&gt; since it's a more appropriate place to interface with the filesystem. I believe the current widespread method is to just implement a custom preprocessor that works in a way any C programmer should be familiar with.&lt;/p&gt;&#xA;" OwnerUserId="311" LastEditorUserId="311" LastEditDate="2015-08-10T19:16:27.473" LastActivityDate="2015-08-10T19:16:27.473" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="110" PostTypeId="2" ParentId="100" CreationDate="2015-08-08T05:31:58.103" Score="4" Body="&lt;p&gt;Some people have already pointed out that &lt;code&gt;glShaderSource&lt;/code&gt; can take an array of strings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On top of that, in GLSL the compilation (&lt;code&gt;glShaderSource&lt;/code&gt;, &lt;code&gt;glCompileShader&lt;/code&gt;) and linking (&lt;code&gt;glAttachShader&lt;/code&gt;, &lt;code&gt;glLinkProgram&lt;/code&gt;) of shader is separate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have used that in some projects to split shaders between the specific part, and the parts common to most shaders, which is then compiled and shared with all shader programs. This works and is not difficult to implement: you just have to maintain a dependency list.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In terms of maintainability though, I am not sure it is a win. The observation was the same, let's try to factorize. While it indeed avoids repetition, the overhead of the technique feels significant. Moreover, the final shader is more difficult to extract: you cannot just concatenate the shader sources, as the declarations end in an order that some compilers will reject, or will be duplicated. So it makes it more difficult to do a quick shader test in a separate tool.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end this technique addresses some DRY issues, but it's far from ideal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a side topic, I am not sure if this approach has any impact in terms of compilation time; I have read that some drivers only really compile the shader program on linking, but I haven't measured.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2015-08-08T05:31:58.103" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="111" PostTypeId="2" ParentId="94" CreationDate="2015-08-08T06:30:49.560" Score="5" Body="&lt;p&gt;As far as I'm aware there's no way in either DX or GL to re-use RT 0's alpha for all the blending operations.  Unfortunately, it doesn't seem to be something that's supported by hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can configure different blend modes for each render target, or enable blending for some and disable for others; however, if blending is enabled for a render target, it always uses its own alpha.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's also a mode called &quot;dual-source blending&quot; (see &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/bb205120.aspx#dual_source&quot; rel=&quot;noreferrer&quot;&gt;DX11 doc&lt;/a&gt; and &lt;a href=&quot;https://www.opengl.org/wiki/Blending#Dual_Source_Blending&quot; rel=&quot;noreferrer&quot;&gt;OGL doc&lt;/a&gt;), which allows you to specify the alpha for blending with an entirely separate output from the pixel shader, not the render target's alpha channel.  However, this mode only works with one render target on current hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So as far as I can tell, the only options for blending several render targets with the same alpha are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Output the same alpha on all render targets (sacrificing the ability to store other values to the alpha channel as you would in deferred shading, for instance).&lt;/li&gt;&#xA;&lt;li&gt;Repeat the rendering in a separate pass for each render target, using dual-source blending.&lt;/li&gt;&#xA;&lt;li&gt;Use UAVs / image load-store to execute the blending in the pixel shader (only works if geometry is non-self-overlapping in screen space, because there's no protection against race conditions; also probably kinda slow).&lt;/li&gt;&#xA;&lt;li&gt;On hardware that supports it, &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn914601.aspx&quot; rel=&quot;noreferrer&quot;&gt;DX11.3/DX12 Rasterizer-Order Views&lt;/a&gt;, &lt;a href=&quot;https://www.opengl.org/registry/specs/NV/fragment_shader_interlock.txt&quot; rel=&quot;noreferrer&quot;&gt;NV_fragment_shader_interlock&lt;/a&gt;, or &lt;a href=&quot;https://www.opengl.org/registry/specs/INTEL/fragment_shader_ordering.txt&quot; rel=&quot;noreferrer&quot;&gt;INTEL_fragment_shader_ordering&lt;/a&gt; (the latter also exposed by AMD GPUs).  These are three names for the same thing: basically a &quot;critical section&quot; in the pixel shader that lets you read-modify-write a texture atomically with respect to other pixel shader invocations. It essentially enables arbitrary programmable blending, but it's probably fairly slow, and only available on recent hardware.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-08T06:30:49.560" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="112" PostTypeId="2" ParentId="103" CreationDate="2015-08-08T07:11:05.800" Score="7" Body="&lt;p&gt;If the downsampling pass is properly designed, it will effectively perform low-pass filtering as part of the downsampling.  There is no need for a separate low-pass filter operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Essentially, when you downsample, you are performing a filter over the source (high-res) image pixels, but only evaluating it at the locations of the destination (low-res) pixels.  The footprint of this filter needs to be approximately the spacing between destination pixels, to avoid missing information by skipping over in-between source pixels.  But that means the filter footprint will be several source pixels wide, so it will effectively low-pass the source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, let's suppose you downsample an image by exactly 10x on each axis.  With a box filter (for example's sake), you would set each destination pixel to the average of a 10x10 box of source pixels.  That would wipe out any features smaller than 10px, so it's effectively a low-pass filter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You mention bicubic interpolation; we have to make a distinction between filtering and interpolation here.  Interpolation is appropriate for upsampling, not downsampling.  Bicubic interpolation works by fitting a bicubic spline patch to a 4x4 neighborhood of pixels, then evaluating the patch at interpolated points. While it may work well enough for downsampling images by a small factor (up to 2x or so), it will fail if you go much further than that.  For instance, if downsampling by 10x as in the previous example, you can see that bicubic will miss the majority of the source pixels, and the result may be quite aliased.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, bicubic &lt;em&gt;filtering&lt;/em&gt; is just standard filtering, using a kernel that's a bicubic function (as opposed to a box, triangle, Gaussian, Lanczos, etc. kernel).  The Mitchell-Netravali kernel is the classic example of this type.  If used for downsampling, the kernel should be sized appropriately for the destination pixel spacing as discussed earlier, and you would sum over all the pixels in the footprint, not just a 4x4 or other fixed-size neighborhood.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-08T07:11:05.800" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="113" PostTypeId="2" ParentId="91" CreationDate="2015-08-08T07:46:26.633" Score="3" Body="&lt;p&gt;Yes, it's certainly possible to do this kind of thing.  First of all, you can typically connect 3 or 4 displays to each GPU, and (with an appropriate motherboard) you can have up to 4 GPUs per machine.  That would give you 16 screens.  With multiple machines, you could have even more.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rendering to multiple displays from a single GPU is no big deal.  You can create a single window that stretches across all the displays, render to it, and it should &quot;just work&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rendering the same scene on multiple GPUs is a bit trickier.  One way is to create a separate rendering context on each GPU, and essentially repeat all the rendering&amp;mdash;re-upload all buffers and textures to each GPU, and re-submit the draw calls to each one every frame.  Another possibility is to use the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn933253.aspx&quot; rel=&quot;nofollow&quot;&gt;built-in multi-GPU support in DX12&lt;/a&gt;, which allows you to manage several GPUs in one rendering context.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-08T07:46:26.633" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="115" PostTypeId="5" CreationDate="2015-08-08T18:28:16.773" Score="0" Body="&lt;p&gt;Transformations are the mathematical operations that can be applied to an object (often a set of vertices that belong together) to move it, rotate it, or otherwise transform it.&lt;br&gt;&#xA;Transformations are usually applied using a matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Transformations are not necessarily bijective; data may be lost, for example, in a projection from a 3D object to it's 2D representation on a screen.&lt;/p&gt;&#xA;" OwnerUserId="21" LastEditorUserId="21" LastEditDate="2015-08-11T04:40:02.740" LastActivityDate="2015-08-11T04:40:02.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="116" PostTypeId="4" CreationDate="2015-08-08T18:28:16.773" Score="0" Body="Transformations are mathematical operations that can be applied to an object to change its scale, position and orientation. " OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-02-18T02:08:04.167" LastActivityDate="2016-02-18T02:08:04.167" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="117" PostTypeId="1" AcceptedAnswerId="118" CreationDate="2015-08-08T18:33:55.790" Score="6" ViewCount="270" Body="&lt;p&gt;How would one do a color separation if there are more than 3 color primaries, or the primaries are nonstandard. In Standard  CMYK conversion K is relatively easy conceptually to figure out. Its just a constant value off all the channels. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How would one construct a CMY + orange for instance. Or in the case of a led array with say Red, Yellow, Blue and Violet for example. How would one approach this problem. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm fine with a conceptual answer no need to do LAB to end result conversion for example. Though that would be nice.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="316" LastEditDate="2015-08-09T07:16:48.483" LastActivityDate="2015-11-03T13:53:01.553" Title="How to do a color separation with more than 3 primary colors" Tags="&lt;color&gt;&lt;color-separation&gt;&lt;conversion&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="118" PostTypeId="2" ParentId="117" CreationDate="2015-08-08T19:51:13.280" Score="5" Body="&lt;p&gt;The mathematical approach to this is to represent the other colors/light sources in terms of your standard primaries in the color space. Represent your target color and available light sources as vectors with, say, the RGB color space as the basis. Figuring out how to display your target color using your available sources then becomes a &lt;a href=&quot;https://math.stackexchange.com/a/340991/166490&quot;&gt;change of basis&lt;/a&gt;, a standard linear algebra operation, where the target basis consists of your LEDs/nonstandard primaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the dimensions of the source and destination bases are different, the change of basis matrix won't be square and thus won't be invertible. In that case, you need to solve a system of linear equations, expressed in matrix form:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$c_{RGB} = [r, y, b, v] \cdot c_{RYBV}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $c_{RGB}$ and $c_{RYBV}$ are the coordinate vectors of your desired color expressed in terms of RGB and custom primaries, respectively, and $r$, $y$, $b$ and $v$ are your custom primaries (basis vectors) in RGB coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solving this system is another common linear algebra operation, and there are a variety of numerical and symbolical algorithms to do so. The system is over-constrained, so solutions will likely have a free variable, however since we can't physically produce negative light, nor do the primaries have infinite dynamic range, for most practical purposes each coefficient will have to be limited to be within the $[0, 1]$ range. This will render many colors unrepresentable under certain sets of primaries.&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="-1" LastEditDate="2017-04-13T12:19:38.027" LastActivityDate="2015-11-03T13:53:01.553" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="119" PostTypeId="1" AcceptedAnswerId="120" CreationDate="2015-08-09T01:57:50.783" Score="10" ViewCount="5391" Body="&lt;p&gt;Temporal anti aliasing (and other temporal algorithms) work by matching pixels this frame with pixels from the last frame and then using that information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get that you can use the last and current frame matrices along with motion vector information to match the pixels between frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I don't get though is how do you know whether the reprojected pixel is valid or not?  For instance the old pixel may now be hidden behind a different object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it by color only? If so, how are animated textures or changing light conditions handled?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-08-09T03:34:13.070" LastActivityDate="2015-08-09T06:39:28.673" Title="How does temporal reprojection work?" Tags="&lt;post-processing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="120" PostTypeId="2" ParentId="119" CreationDate="2015-08-09T06:39:28.673" Score="4" Body="&lt;p&gt;One strategy mentioned in &lt;a href=&quot;http://advances.realtimerendering.com/s2014/epic/TemporalAA.pptx&quot; rel=&quot;nofollow&quot;&gt;Brian Karis's talk about TAA&lt;/a&gt; is neighborhood clamping. The general idea is that, for the previous frame's pixel to be valid, its color should be in the color range found in the neighborhood (say 3x3 pixels) of the current pixel this frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This rejects history from changing light conditions, which is probably what you want anyway if you don't want moving shadows to produce ghosting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Animated textures, depending on the speed of the animation, could also be handled with a motion vector, if you have a predictable UV mapping or can guess reasonably well.)&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-09T06:39:28.673" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="121" PostTypeId="1" AcceptedAnswerId="128" CreationDate="2015-08-09T08:29:04.527" Score="14" ViewCount="4420" Body="&lt;p&gt;Alpha blending can be turned on to make surfaces transparent, like so:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDisable(GL_DEPTH_TEST); //or glDepthMask(GL_FALSE)? depth tests break blending&#xA;glEnable(GL_BLEND);&#xA;glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this only works if objects are rendered in back to front order. Otherwise things in the background appear in front of closer objects, like the floor in the image below. For particles and GUI elements sorting would be OK, but for triangle meshes it seems like it'd be too much effort and slow, as discussed here: &lt;a href=&quot;https://www.opengl.org/wiki/Transparency_Sorting&quot; rel=&quot;noreferrer&quot;&gt;https://www.opengl.org/wiki/Transparency_Sorting&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the common methods to deal with this? I know this is quite broad and am not after in-depth implementation details, just a brief description of some approaches and what might be involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/G3Ybm.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/G3Ybm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="198" LastEditorUserId="100" LastEditDate="2015-08-09T09:40:54.873" LastActivityDate="2015-08-11T16:46:35.160" Title="What are some methods to render transparency in OpenGL" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;transparency&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="122" PostTypeId="1" AcceptedAnswerId="137" CreationDate="2015-08-09T08:46:52.920" Score="7" ViewCount="234" Body="&lt;p&gt;I'm looking for an algorithm that can identify edges across which colour is changing sharply, rather than just finding changes in brightness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this just a matter of using a different colour space with existing edge detection algorithms, or is there a better approach?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-09T17:03:58.693" Title="How can I detect edges between different colours of the same brightness?" Tags="&lt;color&gt;&lt;algorithm&gt;&lt;edge-detection&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="123" PostTypeId="1" AcceptedAnswerId="135" CreationDate="2015-08-09T08:56:08.447" Score="8" ViewCount="438" Body="&lt;p&gt;I'm aware of glFog, which blends between the fog and surface colour based on distance to the camera, like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2pERbm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2pERbm.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The equations are even given in the &lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glFog.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;docs&lt;/a&gt;.&#xA;But the fog is applied immediately in front of the camera. I'm trying to render a water surface and want it to have some depth, for example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uEXcwm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uEXcwm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the moment I'm just rendering the water surface with alpha blending, as below. What I need is to have the fog based on the distance from the water surface to the bottom of the water. How can I get this distance? For the moment I'm assuming the camera will always be above the water.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GsYC5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GsYC5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="198" LastEditorUserId="38" LastEditDate="2015-08-09T14:27:04.993" LastActivityDate="2015-08-09T14:27:04.993" Title="Rendering fog underneath water" Tags="&lt;opengl&gt;&lt;fog&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="124" PostTypeId="2" ParentId="121" CreationDate="2015-08-09T08:57:55.630" Score="6" Body="&lt;p&gt;One option is to use depth peeling. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Essentially, one processes the scene a set number of times (say, &lt;code&gt;n&lt;/code&gt; times) in order to determine the closest, second-closest, all the way to &lt;code&gt;n&lt;/code&gt;th-closest fragments of the scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This processing is done by first applying a regular depth test to the entire scene (which naturally returns the closest surface). One then uses the result of the depth test to filter out the first layer, by ignoring everything with a lesser depth than returned in the depth test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying the depth test again will then return the second layer. Repeat as needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have the layers, you can just draw all the layers in reverse order (assuming you kept track of the RGBA colors for each layer), blending normally, since the layers are in front-to-back order.&lt;/p&gt;&#xA;" OwnerUserId="170" LastActivityDate="2015-08-09T08:57:55.630" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="125" PostTypeId="1" AcceptedAnswerId="152" CreationDate="2015-08-09T08:58:52.810" Score="6" ViewCount="87" Body="&lt;p&gt;Raytracing an image can be performed in parallel by calculating the colour of different pixels on different machines. However, this still requires each machine to have access to the entire scene to be rendered. Is there a way of also subdividing the scene so that different machines have access to different parts of it but can still calculate their assigned pixels correctly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I cannot imagine a way in which this could be possible in general. Are there any particular circumstances in which this can be achieved?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-09T22:09:49.603" Title="Can I parallelise the scene for a raytraced image, rather than just the pixels?" Tags="&lt;raytracing&gt;&lt;scene-description&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="126" PostTypeId="1" AcceptedAnswerId="153" CreationDate="2015-08-09T09:07:37.560" Score="13" ViewCount="554" Body="&lt;p&gt;If the scene to be raytraced cannot be stored in memory, then without adding more RAM to the machine it seems unrealistic to render it in a practical time span, due to the need to load different parts of the scene from disk potentially several times per pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way around this? I'm trying to think of some way of performing a large number of the calculations involving a particular subset of the scene all at once, to reduce the number of times it needs to be loaded into memory. Is there any other way of improving the speed in such a case?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2020-05-25T07:56:21.213" Title="How can I raytrace a scene that does not fit into memory?" Tags="&lt;raytracing&gt;&lt;memory&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="127" PostTypeId="2" ParentId="125" CreationDate="2015-08-09T09:07:40.690" Score="3" Body="&lt;p&gt;In the general case, no.  Reflection, refraction, and shadows can all generate secondary rays that could go anywhere, requiring the entire scene to be available.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the special case of rendering with no secondary rays, you can quickly generate a vista buffer (essentially a mapping of your acceleration hierarchy to the screen) to figure out which objects are potentially visible from each pixel and distribute portions of the scene accordingly.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-09T09:07:40.690" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="128" PostTypeId="2" ParentId="121" CreationDate="2015-08-09T09:31:04.153" Score="11" Body="&lt;p&gt;A set of techniques to avoid explicit ordering go under the name of Order Independent Transparency (OIT for short). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are lots of OIT techniques. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Historically one is &lt;strong&gt;Depth Peeling&lt;/strong&gt;. In this approach you first render the front-most fragments/pixels, then you find the closest to the one found in the previous step and so forth, going on with as many &quot;layer&quot; as you need. &#xA;It is called depth peeling because at each pass you &quot;peel&quot; one layer of depth. All your layer can be then normally recombined from back to front. &#xA;To implement this algorithm you need to have a copy of the depth buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another set of techniques are the blendend OIT ones. One the most recent and interesting one is the &lt;strong&gt;Weighted Blended OIT&lt;/strong&gt; proposed by &lt;a href=&quot;http://jcgt.org/published/0002/02/09/&quot;&gt;McGuire and Bavoil&lt;/a&gt;. It basically apply a weighted sum for all the surfaces that occupies a given a fragment.  The weighting scheme they propose is based on camera-space Z (as an approximation to occlusion) and opacity.&lt;br&gt;&#xA;The idea is that if you can reduce the problem to a weighted sum, you don't really care about ordering. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other than the original paper, a great resource for implementation details and problems of Weighted Blended OIT is in &lt;a href=&quot;https://mynameismjp.wordpress.com/2014/02/03/weighted-blended-oit/&quot;&gt;Matt Pettineo's blog&lt;/a&gt;.  As you can read from his post this technique is not a silver bullet. The main problem is that the weighting scheme is central and it needs to be tuned according to your scene/content. &#xA;From his experiments, whilst the technique seems to work fine for relatively low and medium opacity, it is failing when opacity approaches 1 and so could not be used from materials where big part of the surface is opaque (he makes the example of foliage). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Again, all come down to how you tune your depth-weights and finding the ones that fit perfectly your use-cases is not necessarily trivial. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for what is needed to for the Weighted Blended OIT, nothing more than two extra render targets. One that you fill with the premultiplied alpha color ( color * alpha) and alpha, both weighted accordingly. The other one for the weights only.  &lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-08-09T10:01:50.560" LastActivityDate="2015-08-09T10:01:50.560" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="129" PostTypeId="1" AcceptedAnswerId="131" CreationDate="2015-08-09T10:15:53.817" Score="10" ViewCount="2026" Body="&lt;p&gt;To render a scene with a single light source using phong shading, one can calculate the final color of each fragment passed into the fragment shader based on the ambient/diffuse/specular components of both the material and the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be easily extended to accommodate for multiple light sources by adding together the results of applying each individual light source onto the fragment as such:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;final_color = (0, 0, 0, 1)&#xA;for each light:&#xA;    final_color += apply_light(material, light)&#xA;final_color = clamp(final_color, (0,0,0,1), (1,1,1,1))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, with a very large number of light sources, this process is quite slow; with &lt;code&gt;N&lt;/code&gt; lights, this approach requires calculations for phong shading to be done &lt;code&gt;N&lt;/code&gt; times per fragment. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a better approach to rendering scenes with a very large number of light sources (hundreds, thousands, etc.)?&lt;/p&gt;&#xA;" OwnerUserId="170" LastActivityDate="2015-08-09T11:36:54.697" Title="Efficient rendering with many light sources" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="130" PostTypeId="1" AcceptedAnswerId="202" CreationDate="2015-08-09T10:18:03.970" Score="9" ViewCount="781" Body="&lt;p&gt;I am trying to implement microfacet BRDF model. I am reading &lt;a href=&quot;http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf&quot; rel=&quot;noreferrer&quot;&gt;Sebastien Lagarde's slides&lt;/a&gt;. I implemented formulas to my code but i think result image is wrong. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yellow is base color of material. Specular color is red to see properly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Fragment Shader&#xA;#version 330 core&#xA;&#xA;in vec3 Position;&#xA;in vec2 TexCoord0;&#xA;in vec3 Normal;&#xA;in vec3 Tangent;&#xA;out vec4 FinalColor;&#xA;&#xA;uniform vec3 uCameraPosition; // init value: vec3(0, 0, 5)&#xA;&#xA;#define PI 3.1415926f&#xA;#define EPSILON 10e-5f&#xA;#define saturate(value) clamp(value, 0.0f, 1.0f);&#xA;&#xA;float BRDF_Lambert(float NdotL)&#xA;{&#xA;    return NdotL;&#xA;}&#xA;&#xA;// Got these BRDF formulas Moving Frostbite to PBR slide by Sebastien Lagarde &amp;amp; Charles de Rousiers &#xA;// http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf&#xA;float BRDF_D_GGX(float NdotH, float Roughness)&#xA;{&#xA;    float Roughness2 = Roughness * Roughness;&#xA;    float f = (NdotH * Roughness2 - NdotH) * NdotH + 1.0f;&#xA;    return Roughness2 / (f * f + EPSILON);&#xA;}&#xA;&#xA;&#xA;float BRDF_F_FresnelSchlick(float LdotH, float F0)&#xA;{&#xA;    float f = F0 + (1.0f - F0) * pow((1.0f - LdotH), 5);&#xA;    return f;&#xA;}&#xA;&#xA;float BRDF_G_SmithGGXCorrelated(float NdotL, float NdotV, float Roughness)&#xA;{&#xA;    float Roughness2 = Roughness * Roughness;&#xA;    float GV = NdotL * sqrt((-NdotV * Roughness2 + NdotV) * NdotV + Roughness2);&#xA;    float GL = NdotV * sqrt((-NdotL * Roughness2 + NdotL) * NdotL + Roughness2);&#xA;&#xA;    return 0.5f / (GV + GL + EPSILON);&#xA;}&#xA;&#xA;float BRDF_Specular(float NdotV, float NdotL, float NdotH, float LdotH, float Roughness, float F0)&#xA;{&#xA;    float D = BRDF_D_GGX(NdotH, Roughness);&#xA;    float F = BRDF_F_FresnelSchlick(LdotH, F0);&#xA;    float G = BRDF_G_SmithGGXCorrelated(NdotL, NdotV, Roughness);&#xA;    return (D * F * G) / PI;&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;    FinalColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);&#xA;    vec4 BaseColor = vec4(1.0f, 1.0f, 0.0f, 1.0f);&#xA;    vec4 SpecularColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);&#xA;    vec3 LightDirection = normalize(vec3(0, 4, 4));&#xA;    vec3 ViewDirection = normalize(Position - uCameraPosition);&#xA;    vec3 HalfVector = normalize(ViewDirection + LightDirection);&#xA;    float Roughness = 0.9f; // [0.04 - 0.1f] -&amp;gt; Dielectric, [0.7, 1.0f] -&amp;gt; Metallic&#xA;&#xA;    float RefractiveIndex = 0.27049f; // RI for Gold materials. I got this from http://refractiveindex.info/&#xA;    float F0 = pow(((1.0f - RefractiveIndex) / (1.0f + RefractiveIndex)), 2);&#xA;&#xA;    float NdotL = saturate(dot(LightDirection, Normal));&#xA;    float NdotV = abs(dot(ViewDirection, Normal)) + EPSILON; // Avoid artifact - Ref: SIGGRAPH14 - Moving Frosbite to PBR&#xA;    float LdotH = saturate(dot(LightDirection, HalfVector));&#xA;    float NdotH = saturate(dot(Normal, HalfVector));&#xA;&#xA;    float DiffuseFactor = BRDF_Lambert(NdotL);&#xA;    float SpecularFactor = BRDF_Specular(NdotV, NdotL, NdotH, LdotH, Roughness, F0);&#xA;&#xA;    FinalColor = BaseColor * DiffuseFactor + SpecularColor * SpecularFactor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vwRZ8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vwRZ8.png&quot; alt=&quot;Wrong result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Roughness = 0.2f;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/89aAW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/89aAW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Roughness = 0.04f;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SlEtb.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SlEtb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="83" LastEditorUserId="83" LastEditDate="2015-08-09T20:20:02.463" LastActivityDate="2015-08-11T07:53:30.297" Title="Trying to implement Microfacet BRDF but my result images are wrong" Tags="&lt;rendering&gt;&lt;glsl&gt;&lt;shading&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="131" PostTypeId="2" ParentId="129" CreationDate="2015-08-09T11:23:55.003" Score="15" Body="&lt;p&gt;Yes, but you need a paradigm shift. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you are accustomed is called forward rendering. You submit your geometry and then you proceed immediately with the shading pass. In the basic forward rendering you can either loop inside the shader for each light or perform one pass per light and blend the result together (with additive blending). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But things have evolved quite a lot. Enters: &lt;strong&gt;Deferred Rendering&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that are so many variants that describe them all in details will take way more than acceptable for an answer here. So here I am just going to describe the gist of Deferred shading, there are plenty of other resources that you can easily find using google, hopefully after reading this you'll have the right keywords to find what you need. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic idea is to defer the shading to after down the pipeline. You have two main steps: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render your geometry and all the information needed for shading into multiple render targets. This means that typically in a basic implementation you would have a depth buffer, a buffer containing the normals of your geometry and the albedo colour. You'll soon find that you need other information of the materials (e.g. roughness, &quot;metallic&quot; factor etc.). &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This image from wikipedia shows three buffer (color, depth and normals) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fmaeF.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fmaeF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Again, the amount, type and content of the buffers used varies quite a lot among different projects. You will find the set of buffers with the name of GBuffers.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;After this is the time of applying the actual lighting. During the lighting pass for each light you want to draw a light volume that depends on the type of light:&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For a directional light you render a full screen quad. &lt;/li&gt;&#xA;&lt;li&gt;For a point light you render a sphere where the radius is based on the attenuation of your point light. &lt;/li&gt;&#xA;&lt;li&gt;For a spot-light you render a cone which dimensions again depend on the characteristics of your light. &lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In the pixel shader of this pass you pass your GBuffers and perform your lighting and shading using the information in them. This way you process only the pixels affected by each of the lights having a sensible speed-up if compared to the classical forward rendering. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It has also various disadvantages, most notably the handling of transparent  objects and higher consumption of bandwidth and video memory. But also it is trickier to handle various models for materials. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You have other side-advantages (as having lots of info ready for post-processing) and is also pretty easy to implement. But this is not the coolest thing around for lots of lights anymore. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Newer techniques are for example &lt;strong&gt;Tiled rendering&lt;/strong&gt; ones. The main idea of those is to subdivide the scene in screen space &quot;tiles&quot; and assign to each tile the lights affecting it. This exists both in a deferred and forward fashion.  These techniques lead to some problems when you have various depth discontinuities in a tile, but is generally faster than the classical deferred and it solves various problems of it. For example, among the advantages, with tiled deferred you read the GBuffers once per lit fragment and pixels in the same tile coherently process the same lights. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further evolution on this side is the &lt;strong&gt;&lt;a href=&quot;http://www.cse.chalmers.se/~uffe/clustered_shading_preprint.pdf&quot; rel=&quot;noreferrer&quot;&gt;Clustered shading&lt;/a&gt;&lt;/strong&gt; which is conceptually similar to the tiled based approaches, having instead of screen space tiles, clusters with a 3D extent. This method handles better the depth discontinuities problem and generally performs better than the tiled methods. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;IMPORTANT NOTE:&lt;/strong&gt; I have described the basics of the deferred shading. There are multiple variations, optimizations and improvements around so I urge you to experiment with a simple version and then do some researches on other techniques such the one I mentioned above. &lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-08-09T11:36:54.697" LastActivityDate="2015-08-09T11:36:54.697" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="132" PostTypeId="2" ParentId="122" CreationDate="2015-08-09T11:28:28.467" Score="2" Body="&lt;p&gt;Color difference is a difference in brightness, in some color channel. So while the sum of individual channels stay the same, there is a intensity difference if there is a color difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the basic algorithms do not really specify how you should hadle the multi channel data. So there is nothing wrong with using a different color space. On the other hand nothing says you can not apply the convolution on all channels and then pick the result that is most contrasting.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-08-09T11:28:28.467" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="133" PostTypeId="2" ParentId="126" CreationDate="2015-08-09T11:38:54.363" Score="7" Body="&lt;p&gt;If you organize your scene in a spatial structure (the usual way being a &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume_hierarchy&quot;&gt;Bounding Volume Hierarchy&lt;/a&gt;), you can use a sort of virtual scene (I am making up this term, in reference to &lt;a href=&quot;https://developer.nvidia.com/sites/default/files/akamai/gameworks/events/gdc14/GDC_14_Real%20Virtual%20Texturing%20-%20Taking%20Advantage%20of%20DirectX%2011.2%20Tiled%20Resources.pdf&quot;&gt;virtual textures&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A memory manager would keep only a limited number of bounding boxes loaded at a time, and abstract the operation consisting in retrieving one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This way, a box would be loaded only as needed: when a ray hits a bounding box, the box get loaded to resolve the collision. Later on when another box needs to be loaded, the unused one is deleted to make room for the new one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With all these boxes getting loaded and deleted, the ray coherency would be a major factor in speed. I suppose a further improvement could be to defer loading, by reordering rays to treat first the boxes that are already loaded.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2015-08-09T11:38:54.363" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="134" PostTypeId="2" ParentId="126" CreationDate="2015-08-09T11:39:04.653" Score="1" Body="&lt;p&gt;What you do is you load triangles into memory from disk based on what has been hit previously. You can begin with triangles in close proximity first. The reasoning is that in one area the rays are likely to hit same triangles repeatedly. And eventually you will be somewhat efficient. (For this reason it is a good idea to cache last hit triangle in occlusion tracing that dont care of order)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second you store the triangles in a spatial tree that allows you to do quick searching from the disk, to renew what portions you are having in memory by proximity. So load only branches that will be in the way of the ray. If its some kind of voxel tree, like a octree you can even sort secondary rays and solve them by coherence. A BSP tree is also somewhat good at pruning areas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are cases where this fails but its reasonably efficient in most scene buckets if your not rendering noise...&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-09T11:59:09.313" LastActivityDate="2015-08-09T11:59:09.313" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="135" PostTypeId="2" ParentId="123" CreationDate="2015-08-09T11:52:38.473" Score="5" Body="&lt;p&gt;You can ray trace the distance to the second surface. This may be conceptually easiest, but not necessarily fastest method*.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But there is a neat trick, you can multi pass render a depth map to the water surface from the camera. The distance in water is now pixel depth minus the depth map depth. This does not work in all situations such as when you exit water and re-enter later. But should work in many cases, like the one depicted. You can even use same technique for Boolean operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UcYKY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UcYKY.png&quot; alt=&quot;dmap&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Render depth map, consult depth map when shading the bottom of your pond.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* It might be in certain cases.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-09T12:54:20.610" LastActivityDate="2015-08-09T12:54:20.610" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="137" PostTypeId="2" ParentId="122" CreationDate="2015-08-09T12:13:20.517" Score="3" Body="&lt;p&gt;I think you can convert from the RGB space to the HSV one, or whatever color space has the HUE in a single channel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Take the HUE channel, and make the edge detection on that one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here a simple Matlab script to achieve the result.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;I = imread('image.png');&#xA;hsv = rgb2hsv(I);&#xA;hue = hsv(:,:,1);&#xA;edges = edge(uint8(hue),'sobel');&#xA;imshow(edges);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="316" LastEditorUserId="316" LastEditDate="2015-08-09T17:03:58.693" LastActivityDate="2015-08-09T17:03:58.693" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="138" PostTypeId="1" CreationDate="2015-08-09T12:39:35.540" Score="13" ViewCount="3848" Body="&lt;p&gt;Quaternions (a four-dimensional extension of complex numbers) can used to represent rotation and scaling of a 3D vector, and the application of a quaternion onto a 3D vector involves two quaternion multiplications, thus requiring fewer operations than multiplication by the corresponding transformation matrix. However, linear and affine transformation matrixes are often used instead, especially in shader code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When is it appropriate and preferable (due to speed, stability, etc.) to use a quaternion to represent scaling and rotation in three dimensions, instead of the corresponding transformation matrix?&lt;/p&gt;&#xA;" OwnerUserId="170" LastActivityDate="2015-08-09T17:22:51.250" Title="When should quaternions be used to represent rotation and scaling in 3D?" Tags="&lt;transformations&gt;" AnswerCount="4" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="140" PostTypeId="2" ParentId="138" CreationDate="2015-08-09T13:16:41.053" Score="3" Body="&lt;p&gt;Matrices offer more possible transforms than quaternions, it is possible to skew, mirror and non uniformly scale the matrix. There is nothing that states you can not make your engine do just quaternion based transforms, if you have no need for the additional transform features.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Matrices are just very convenient when you need to build spaces where you know the basis vectors. Such as when doing projections into orthographic. Also doing perspective transform in a matrix space is easy. Matrices are superior when it comes to projecting stuff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a way matrices are usually used because they represent the most common denomination and aren't too complicated to master and understand. The benefits of standardization far outweighs the benefit you get form a custom workflow. Its well known how to do the matrix operations. Whereas quats are not something most get immediate introduction to in uni. Just ask around how many know how to invert a quaternion, whereas you dont find many students in higher education who dont know how to invert a matrix. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that graphics cards also have dedicated pipes for matrix operations.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-09T13:30:27.103" LastActivityDate="2015-08-09T13:30:27.103" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="141" PostTypeId="2" ParentId="138" CreationDate="2015-08-09T13:27:07.007" Score="3" Body="&lt;p&gt;A quaternion can only represent uniform scaling and rotation so if you need anything else you would need to add something to represent that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Translation can be done with a single additional vec3 (or using &lt;a href=&quot;https://en.wikipedia.org/wiki/Dual_quaternion&quot; rel=&quot;nofollow&quot;&gt;dual quaternions&lt;/a&gt;). However non-uniform scaling and sheering is represented better by a mat4. Projection transforms (essentially non-uniform scaling and swapping z and w) cannot be represented by a quaternion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quaternions have a major advantage when interpolating. The slerp is most easily calculated using quaternions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying a quaternion (or dual quaternion) is not built into the GPU so you would need to implement that using the vector operations. Most quaternion libraries assume that you won't be using the quaternion to represent scale so that's something to look out for.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2015-08-09T16:44:50.557" LastActivityDate="2015-08-09T16:44:50.557" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="143" PostTypeId="2" ParentId="138" CreationDate="2015-08-09T15:58:55.490" Score="4" Body="&lt;p&gt;(A lot of information here I shamelessly borrowed from joojaa's and ratchet freak's answers, with some notes of my own.)&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Matrix Advantages&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Non uniform scaling and rotation, skewing, projection&lt;/li&gt;&#xA;&lt;li&gt;Translation (unless using dual quaternions)&lt;/li&gt;&#xA;&lt;li&gt;Native hardware support&lt;/li&gt;&#xA;&lt;li&gt;Quaternions often require transcendental functions to construct&lt;/li&gt;&#xA;&lt;li&gt;Easier to understand&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2&gt;Quaternion Advantages&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Transforming a vector requires fewer operations (Or not - See John's answer)&lt;/li&gt;&#xA;&lt;li&gt;Transforming by another quat requires many fewer operations&lt;/li&gt;&#xA;&lt;li&gt;Quaternions occupy 4 floats, (8 if it's a dual) but Matrices occupy 9-16 floats&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If you know you're only going to be doing uniform rigid body transforms, a vector/quat pair is usually a solid win on a 3x4 matrix in terms of storage space (vector/quat: 7 or 8 floats vs mat3x4: 12 floats) and processing speed. If Quaternions are still mystical voodoo to you, try &lt;a href=&quot;https://www.youtube.com/playlist?list=PLW3Zl3wyJwWNWsJIPZrmY19urkYHXOH3N&quot; rel=&quot;nofollow&quot;&gt;this web series on them&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="125" LastEditorUserId="125" LastEditDate="2015-08-09T17:20:16.970" LastActivityDate="2015-08-09T17:20:16.970" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="144" PostTypeId="2" ParentId="138" CreationDate="2015-08-09T17:16:24.560" Score="8" Body="&lt;p&gt;I want to start with misconceptions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern GPUs (NVIDIA for quite a while, and AMD since Southern Islands) do not meaningfully support vector/matrix operations natively in hardware. They are vector architectures in a different direction: each component of a vector (x, y, z) are generally 32- or 64-valued, containing values for each element in a lane. So a 3D dot product is not usually an instruction, it is a multiply and two multiply-adds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, counting primitive operations like multiply-add, transforming a vector by a quaternion is more expensive than transforming a vector by a matrix. Transforming a vector by a 3x3 matrix is 3 multiplies and 6 multiply-adds, and transforming a vector by a quaternion is two quaternion multiplies, each of which consist of 4 multiplies and 12 multiply-adds. (You can get less naïve than this—&lt;a href=&quot;https://molecularmusings.wordpress.com/2013/05/24/a-faster-quaternion-vector-multiplication/&quot; rel=&quot;noreferrer&quot;&gt;here's a writeup on a faster way&lt;/a&gt;—but it's still not as cheap as multiplying a vector by a matrix.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, performance is not always determined simply by counting the number of ALU operations it performs. Quaternions require less space than the equivalent matrix (assuming you are only doing pure rotation/scale), and that means less storage space and less memory traffic. This is often important in animation (which is conveniently also often where the nice interpolation properties of quaternions show up).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other than that:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Matrices use more space because they support more operations. A 3x3 matrix can contain nonuniform scale, skew, reflection, and orthogonal projection.&lt;/li&gt;&#xA;&lt;li&gt;Matrices can be naturally thought of as basis vectors, and easily constructed from those vectors.&lt;/li&gt;&#xA;&lt;li&gt;Multiplying one quaternion by another (composing two rotations) is less operations than multiplying one matrix by another.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2015-08-09T17:22:51.250" LastActivityDate="2015-08-09T17:22:51.250" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="145" PostTypeId="1" AcceptedAnswerId="156" CreationDate="2015-08-09T18:05:02.017" Score="11" ViewCount="334" Body="&lt;p&gt;Literature on rendering volumetric materials and effects tends to use a lot of mathematical physics terminology. Let's say that I have a decent handle on the concepts involved in surface rendering. What concepts do I need to understand for volumetric rendering? (Both real-time and offline rendering.)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;What exactly is meant by light scattering in the context of volumetric rendering? (And why is it split into in-scattering and out-scattering?)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What is the relationship between transmission, attenuation, and absorption?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What is a phase function and how does it play into volumetric rendering? (In particular, the Henyey-Greenstein phase function.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What is the Beer-Lambert law and how is it related to light scattering?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Basically, how do I make sense out of diagrams like this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TZ5vY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TZ5vY.png&quot; alt=&quot;Confusing diagram&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-09T23:37:56.080" Title="Volumetric rendering fundamental concepts and terminology" Tags="&lt;volumetric&gt;&lt;atmospherics&gt;&lt;scattering&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="146" PostTypeId="1" AcceptedAnswerId="147" CreationDate="2015-08-09T19:33:44.087" Score="10" ViewCount="2622" Body="&lt;p&gt;Forward rendering is the process of computing a radiance value for a surface fragment directly from input geometry and lighting information. Deferred rendering splits that process into two steps: first producing a screen-space buffer containing material properties (a geometry buffer, or G-buffer) built by rasterizing the input geometry, and second producing a radiance value for each pixel by combining the G-buffer with lighting information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Deferred rendering is often presented as an optimization of forward rendering. One explanation is that lighting is fairly expensive and if you have any overdraw then you are lighting pixels that will never be seen on screen, whereas if you store material properties into a G-buffer and light afterwards, you are only lighting a pixel that will actually appear on-screen. Is this actually an advantage of deferred, given that you can also do a depth pre-pass and then do a forward rendering pass with depth test set to &lt;code&gt;D3D11_COMPARISON_EQUAL&lt;/code&gt; or &lt;code&gt;GL_EQUAL&lt;/code&gt; or the equivalent?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Deferred rendering also has the potential to schedule better on the GPU. Splitting one large warp/wavefront into a smaller geometry wavefront and then smaller lighting wavefronts later improves occupancy (more wavefronts in flight simultaneously). But you also end up with a lot more bandwidth use (writing out a large number of channels to the G-buffer, then reading them back in during lighting). Obviously the specifics here depend a lot on your GPU, but what are the general principles?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there other practical performance considerations when deciding between forward and deferred rendering? (Assume that we can use variations of each technique if necessary: i.e. we can compare tiled forward to tiled deferred as well.)&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-09T19:33:44.087" Title="What is the performance tradeoff between forward and deferred rendering?" Tags="&lt;performance&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="147" PostTypeId="2" ParentId="146" CreationDate="2015-08-09T19:33:44.087" Score="11" Body="&lt;p&gt;It is possible to avoid overdraw from opaque objects even with forward rendering by doing a depth pre-pass and using that information to reject any pixel that is not actually visible. However, depending on the vertex cost of your scene, a depth pre-pass may add an unacceptable amount of performance overhead. Additionally, rendering using the pixel shading pipeline of the GPU means that you don't pay a cost per pixel that is rendered, you pay a cost per 2x2 pixel &lt;em&gt;quad&lt;/em&gt; that is rendered. So even doing a depth pre-pass still causes triangle edges to waste work shading pixels that will be discarded.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPU scheduling is a complex topic, and the tradeoff between forward and deferred does not boil down simply to &quot;runs faster but uses more bandwidth.&quot; If you have two equally cheap operations that run in sequence and each use the same number of resources, there's no reason to split them into separate shaders: two small wavefronts that each use X resources don't fundamentally work better than a single longer wavefront that also uses X resources. If you have a cheap operation and an expensive operation to run in sequence, though, it may benefit from splitting into separate shaders: the shader in general will reserve the maximum amount of resources that it might use at any point. It's conceivable that forward rendering may not be able to use all the bandwidth of your GPU because there are so few wavefronts in flight that it cannot issue enough operations to saturate the bandwidth. But if you &lt;em&gt;are&lt;/em&gt; bandwidth limited, there may be no advantage to deferred rendering (since it will probably use more bandwidth).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An additional performance concern is that forward rendering supports different material types (different BRDFs, say) simply by using a different shader for that object. A straightforward deferred renderer needs to handle different material types in a different way (potentially a branch in the shader), since work is no longer grouped into warps/wavefronts coherently depending on the object being rendered. This can be mitigated with a tiled renderer—if only specific areas of the screen use an alternate material type (say, for hair), then you can use the shader variation with a material type branch only for tiles that contain any pixels with that material.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-09T19:33:44.087" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="148" PostTypeId="1" AcceptedAnswerId="150" CreationDate="2015-08-09T20:02:43.317" Score="10" ViewCount="528" Body="&lt;p&gt;Antialiasing of 2D shapes boils down to computing the fraction of a pixel that is covered by the shape. For simple non-overlapping shapes, this is not too difficult: clip the shape against the pixel rectangle and calculate the resulting shape's area. But it becomes more difficult if multiple shapes overlap the same pixel. Simply summing areas can cause the computed coverage to be too high, if it neglects the amount that one shape covers another shape. For example, see &lt;a href=&quot;http://nothings.org/gamedev/rasterize/&quot;&gt;the Limitations section of this article on font rendering&lt;/a&gt;. You might also be in a situation where the two curves come from different objects with different colors (so it's not about the total coverage for the union of the two shapes, but the coverage of each one separately).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How would this be computed if you cared about complete accuracy? Even trickier, how do you compute coverage accurately for overlapping non-polygonal shapes like curves? Is there some point when you have no choice but to fall back to multisampling or stochastic techniques?&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-14T07:36:33.963" Title="How do I accurately compute coverage of overlapping analytical curves?" Tags="&lt;antialiasing&gt;&lt;curve&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="149" PostTypeId="1" CreationDate="2015-08-09T20:27:41.297" Score="15" ViewCount="1779" Body="&lt;p&gt;It is common knowledge that hair simulation and rendering is particularly challenging and in fact rare are the examples in games that propose believable hairs. It is pretty easy to imagine how hard it is to actually simulate the high amount of fibres and to simulate the various scattering events that may happen between so many strands, let alone the fact that each of them is translucent. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone formalize what are the main challenges in hair rendering, especially for real time scenarios? How these are overcome by state-of-art techniques? Are there some de-facto standard theoretical models used? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify, for real time I don't necessarily mean in a game context. &lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="36" LastEditDate="2015-08-10T07:13:13.427" LastActivityDate="2015-08-14T22:40:35.007" Title="How does state of the art real time hair rendering work?" Tags="&lt;shading&gt;&lt;real-time&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="150" PostTypeId="2" ParentId="148" CreationDate="2015-08-09T21:07:03.407" Score="10" Body="&lt;p&gt;There is really no good way of doing this efficiently analytically for all corner cases. Most or all commercial 2D renderers that attempt to do analytic coverage calculation make predictable errors that multisampling methods do not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A typical problem is two overlapping shapes that share the same edge. The common situation is that alpha channels sum up to a too thick alpha edge that aliases slightly. Or if shapes are differently colored the system confuses what color the background is. This is extremely annoying.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Tfs4k.png&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: The rendering engine confuses the coverage and makes a thin white outline where no outline should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second perfect coverage amounts to box filtering. We can certainly do better. Considering that there are so many special corner cases that would require boolean operations on the shapes to do right, super sampling is still superior. In fact the coverage estimates may be used to concentrate sampling where it's most likely needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The situation could be simplified to polygons at sub pixel levels then the discrete analytical solution could be solved. But this at the expense of flexibility. For example its not out of the question that future vector systems might want to allow for variable width blurred lines which pose a problem for analytic solutions, as do other variably colored objects.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;How to do it analytically&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/CihEg.png&quot; alt=&quot;Analytic scene&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Suppose you have this scene, exploded view on right&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can not just do this analytically, each piece separately and then merge the data. Because it results in wrong data. See alpha blending would let the blue shine trough the gaps if you did so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you have to so is split the scene up so that each shape eliminates what is under the other:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/rJu1X.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 3&lt;/strong&gt;: You need to cut the underlying surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if everything is opaque then this is all straight forward. just calculate the area of each piece and multiply that by color and sum them together. Now you can use something like &lt;a href=&quot;https://stackoverflow.com/questions/10039679/how-can-i-calculate-the-area-of-a-bezier-curve&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This all breaks down if your individual shapes aren't opaque off course but even that can be done at some level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;AA calculation need to be done in linear color space, and converted back to use space.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2015-08-14T07:36:33.963" CommentCount="2" CommunityOwnedDate="2015-08-09T21:07:03.407" ContentLicense="CC BY-SA 3.0" />
  <row Id="151" PostTypeId="1" AcceptedAnswerId="168" CreationDate="2015-08-09T22:06:50.547" Score="15" ViewCount="11029" Body="&lt;p&gt;After so much reading about transformations it is time to implement a trackball for my app.&#xA;I understand I have to create a vector from the origin to where the mouse is clicked and then another from the origin to where the mouse is released.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, do I have to transfor the (x,y) pixel coords to world-coords or should I just do everything in image space (considering image space is the 2D projection of the scene measured in pixels)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Richie Sams' answer is a very good one. However, I think I'm following a slightly different approach, please correct me if I'm wrong or I'm misunderstanding something.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my application I have a &lt;code&gt;SimplePerspectiveCamera&lt;/code&gt; class that receives the &lt;code&gt;position&lt;/code&gt; of the camera, the &lt;code&gt;position of the target&lt;/code&gt; we are looking at, the &lt;code&gt;up&lt;/code&gt; vector, the &lt;code&gt;fovy&lt;/code&gt;, &lt;code&gt;aspectRatio&lt;/code&gt;, &lt;code&gt;near&lt;/code&gt; and &lt;code&gt;far&lt;/code&gt; distances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With those I build my View and Projection matrices. Now, If I want to zoom in/out I update the field of view and update my projection matrix. If I want to pan I move the position of the camera and look at by the delta the mouse produces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, for rotations I can use either angle-axis transformation or quaternions. For this, I save the pixel-coords where the mouse was pressed and then when the mouse moves I also save the pixel-coords.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each pair of coords I can compute the Z-value given the formula for a sphere, i.e., sqrt(1-x^2-y^2), then compute to vectors that go from the &lt;code&gt;target&lt;/code&gt; to &lt;code&gt;PointMousePressed&lt;/code&gt; and from &lt;code&gt;target&lt;/code&gt; to &lt;code&gt;PointMouseMoved&lt;/code&gt;, do cross product to get the axis of rotation and use any method to compute the new camera position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, my biggest doubt is that the (x,y,z) values are given in pixel-coords, and when computing the vectors I'm using &lt;code&gt;target&lt;/code&gt; which is a point in world-coords. Isn't this mixing of coordinate system affecting the result of the rotation I'm trying to do?&lt;/p&gt;&#xA;" OwnerUserId="116" LastEditorUserId="116" LastEditDate="2015-08-12T00:55:29.510" LastActivityDate="2016-02-09T06:19:09.250" Title="How to implement a trackball in OpenGL?" Tags="&lt;opengl&gt;&lt;trackball&gt;" AnswerCount="2" CommentCount="6" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="152" PostTypeId="2" ParentId="125" CreationDate="2015-08-09T22:09:49.603" Score="6" Body="&lt;p&gt;Yes, such a thing is possible. There are a few different ways of doing it, but the basic idea is to split up the scene into chunks and assign these chunks to different machines. Each machine then traces rays locally within their assigned chunk.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The tricky bit is of course when rays leave a chunk, in which case machines need to synchronize and exchange rays that cross the local chunk boundaries. A recent paper from this year's EGSR, &lt;a href=&quot;http://vc.cs.ovgu.de/files/publications/2014/Guenther_2014_CGF.pdf&quot;&gt;Distributed Out-of-Core&#xA;Stochastic Progressive Photon Mapping&lt;/a&gt;, describes how to do this efficiently for Progressive Photon Mapping, although other light transport methods might be feasible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although such distributed ray tracing is possible, it is certainly not the most efficient form of parallelization, and non-uniform lighting directly translates into non-uniform distribution of the workload. It is really only beneficial when the size of the scene far exceeds the memory of a single machine.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-09T22:09:49.603" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="153" PostTypeId="2" ParentId="126" CreationDate="2015-08-09T22:47:46.967" Score="12" Body="&lt;p&gt;If the scene does not entirely fit into memory, you are entering the field of out-of-core rendering. There are essentially two approaches here: a) Generate your scene on-demand b) Load your scene on-demand&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The former approach aligns well with most animation workflows, where models are heavily subdivided using e.g. Catmull-Clark and can become very memory-intensive, but the base meshes themselves easily fit into memory. Pixar have a few papers about this (e.g. &lt;a href=&quot;http://www.pixar.com/companyinfo/research/per/eg03.pdf&quot;&gt;Ray Differentials and Multiresolution Geometry Caching&#xA;for Distribution Ray Tracing in Complex Scenes&lt;/a&gt;), but the gist of it is that models are only subdivided when they are hit by a ray, and only subdivided as much as is reasonable for such a ray (e.g. diffuse interreflection need less accuracy than mirror reflections). The rest is handled by a geometry cache, which keeps the subdivided models in memory and hopefully makes the process efficient by a good eviction strategy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As long as all your base meshes comfortably fit into memory, you can easily go out-of-core and render meshes at subdivision levels that would never fit into memory. The geometry cache also scales nicely with the amount of memory you have, allowing you to weigh RAM vs. render times. This was also used in &lt;a href=&quot;http://graphics.pixar.com/library/RayTracingCars/paper.pdf&quot;&gt;Cars&lt;/a&gt; I believe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second approach is more general and does not rely on heavy use of subdivision. Instead, it relies on the fact that your scene was most likely made by an artist and already comes partitioned into reasonably small objects that fit into memory individually. The idea is then to keep two hierarchies (kD-tree or bounding volume hierarchy): A top-level hierarchy that only stores bounding boxes of the objects in your scene, and a low-level hierarchy that stores the actual geometry. There is one such low-level hierarchy for each object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this approach, you ideally already store a bounding box along with each object on disk. As the scene is loaded, you only build the top-level hierarchy initially, meaning you only have to look at the bounding boxes and not the geometry. You then start tracing rays and traverse them through the hierarchy. Whenever a ray hits a leaf node in the top-level hierarchy (i.e. it hits the bounding box of an object), that object is loaded into memory and its low-level hierarchy is built. The ray then continues down into tracing that object. Combined with an object cache that keeps as much of the low-level hierarchy in memory as possible, this can perform reasonably well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first benefit of such an approach is that objects that are never hit are never loaded, meaning that it automatically adapts to the visibility in your scene. The second benefit is that if you are tracing many rays, you don't have to load an object immediately as it is hit by a ray; instead, you can hold that ray and wait until enough rays have hit that object, amortizing the load over multiple ray hits.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also combine this approach with a ray sorting algorithm such as &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/uploads/production/publication_asset/70/asset/Sorted_Deferred_Shading_For_Production_Path_Tracing.pdf&quot;&gt;Sorted Deferred Shading for Production Path Tracing&lt;/a&gt; to avoid thrashing due to incoherent rays. The mentioned paper describes the architecture of Disney's Hyperion renderer, used for Big Hero 6 I believe, so it most likely can handle scenes at production scale.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-09T22:47:46.967" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="154" PostTypeId="1" AcceptedAnswerId="157" CreationDate="2015-08-09T23:11:11.807" Score="8" ViewCount="662" Body="&lt;p&gt;I'd like to be able to render a large population of small independently moving objects in real time. They may move in a swarm-like manner, but their relative positions will not be coherent - their position may change arbitrarily within a swarm and swarms may break up and reform at any point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What approach to building a bounding volume hierarchy would best suit this situation? Is there a way to maintain a hierarchy which is sub-optimal but good enough, that only requires a partial update each frame? Or is there a way of building a hierarchy from scratch each frame that is fast enough for smooth animation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The number of objects will be too large to render without a hierarchy, but for the same reason I expect building the hierarchy to be time consuming. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Following the comment from John Calsbeek, if my focus on bounding volume hierarchies is misguided, and there is a better space partitioning approach for this situation, please answer accordingly. I'm looking for something that can deal with what I describe, including anything I haven't thought of.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-09T23:32:10.547" LastActivityDate="2020-12-14T06:38:46.077" Title="How can I create a bounding volume hierarchy for constantly moving objects?" Tags="&lt;real-time&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="3" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="155" PostTypeId="2" ParentId="154" CreationDate="2015-08-09T23:26:06.717" Score="3" Body="&lt;p&gt;You could try to simply make the bounding volumes a bit larger than necessary so that the objects don't cross their boundaries on every move but then again, you would have to rebuild the structure now-and-then anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, there is &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_interval_hierarchy&quot; rel=&quot;nofollow&quot;&gt;Bounding interval hierarchy&lt;/a&gt; which tries to address precisely this scenario.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, the paper by Ingo Wald, Solomon Boulos and Peter Shirley titled &lt;a href=&quot;http://www.cs.cmu.edu/afs/cs/academic/class/15869-f11/www/readings/wald07_packetbvh.pdf&quot; rel=&quot;nofollow&quot;&gt;Ray Tracing Deformable Scenes Using Dynamic Bounding Volume Hierarchies&lt;/a&gt; might be of interest.&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="141" LastEditDate="2015-08-09T23:36:06.820" LastActivityDate="2015-08-09T23:36:06.820" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="156" PostTypeId="2" ParentId="145" CreationDate="2015-08-09T23:37:56.080" Score="6" Body="&lt;p&gt;When I was first reading about all of this I stumbled upon this &lt;a href=&quot;http://www.scratchapixel.com/old/lessons/3d-advanced-lessons/volume-rendering/volume-rendering-for-artists/&quot; rel=&quot;noreferrer&quot;&gt;link&lt;/a&gt; which helped me better understand this large subject.  Also &lt;a href=&quot;http://www.cs.dartmouth.edu/%7Ewjarosz/publications/dissertation/chapter4.pdf&quot; rel=&quot;noreferrer&quot;&gt;this&lt;/a&gt; goes into some more detail on things mentioned here.&lt;/p&gt;&#xA;&lt;p&gt;Light scattering is a natural phenomenon which arises when light interacts with particles distributed in a media as it travels through it.  From &lt;a href=&quot;https://en.wikipedia.org/wiki/Light_scattering&quot; rel=&quot;noreferrer&quot;&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Light scattering can be thought of as the deflection of a ray from a straight path, for example by irregularities in the propagation medium, particles, or in the interface between two media&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;In computer graphics there are models that have been developed to simulate the effect of light traversing volume objects from an entry point (&lt;em&gt;Point A&lt;/em&gt;) to an exit point (&lt;em&gt;Point B&lt;/em&gt;).  As the light travels from &lt;em&gt;A&lt;/em&gt; to &lt;em&gt;B&lt;/em&gt; it is changed due to interactions with particles and these interactions are often referred to as &lt;strong&gt;Absorption&lt;/strong&gt;, &lt;strong&gt;Out Scattering&lt;/strong&gt; and &lt;strong&gt;In Scattering&lt;/strong&gt;.  Often you will see these split into two groups; &lt;em&gt;Transmittance&lt;/em&gt; (Absorption and Out Scattering) which I like to think of as 'light lost' and &lt;em&gt;In-Scattering&lt;/em&gt; ('light gained').&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Absorption&lt;/strong&gt; is basically incident light energy that is transformed into some other form of energy and therefore 'lost'.&lt;/p&gt;&#xA;&lt;h3&gt;Transmittance&lt;/h3&gt;&#xA;&lt;p&gt;Transmittance describes how light reflected behind a volume will be attenuated due to Absorption as it travels through a medium from &lt;em&gt;A&lt;/em&gt; to &lt;em&gt;B&lt;/em&gt;.  This is usually calculated with the Beer-Lambert law which relates the attenuation of light to the properties of the material through which it is travelling.&lt;/p&gt;&#xA;&lt;p&gt;As the light travels through the medium there is a chance that the photons can be scattered away from their incident direction and therefore not make it to the eye of the observer and this is referred to as Out-Scattering.  In most models the Transmittance equation is changed slightly to introduce the concept of Out-Scattering.&lt;/p&gt;&#xA;&lt;h3&gt;In Scattering&lt;/h3&gt;&#xA;&lt;p&gt;Above we have seen how light can be lost due to photons been scattered away from the viewing direction.  At the same time light can be scattered back into the viewing direction as it is travelling from &lt;em&gt;A&lt;/em&gt; to &lt;em&gt;B&lt;/em&gt; and this is called In-Scattering.&lt;/p&gt;&#xA;&lt;p&gt;Particle In-Scattering itself is a pretty complex topic but basically you can split it into Isotropic and Anisotropic scattering.  Modelling Anisotropic scattering would take a considerable amount of time so usually in computer graphics this is simplified by using a Phase Function which describes the amount of light from the incident light direction that is scattered into the viewing direction as it travels from &lt;em&gt;A&lt;/em&gt; to &lt;em&gt;B&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;One commonly used non-isotropic Phase Function is called the Henyey-Greenstein phase function which can model Backward and Forward scattering.  It usually has a single parameter, g ∈ [−1,1], that determines the relative strength of forward and backward scattering.&lt;/p&gt;&#xA;" OwnerUserId="329" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-08-09T23:37:56.080" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="157" PostTypeId="2" ParentId="154" CreationDate="2015-08-09T23:50:26.667" Score="5" Body="&lt;p&gt;Consider using spatial hashing, especially if your objects are similarly sized.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, divide your world into uniformly-sized grid cells (2D and 3D are both valid possibilities depending on the amount of vertical motion). Each update, assign your object to each bin that it overlaps—if the cells are decently sized relative to the objects, most objects should end up in a single bin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each bin is inserted into a hash table, with the key being the coordinates of the bin. (You can also think of it as a hash table with multiple values for the same key, and inserting an object once for every cell that it overlaps.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's no hierarchy to rebuild in this scheme, which makes it well suited for dynamic scenes. You can still test the cell's dimensions against the frustum or against occluders at a coarse level and discard many objects at once. Also, it's easier to manage this structure incrementally—you can keep the hash table the same from frame to frame and only move objects from one bin to another when they cross the boundary of a cell.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-09T23:50:26.667" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="158" PostTypeId="2" ParentId="149" CreationDate="2015-08-10T01:11:41.027" Score="7" Body="&lt;p&gt;&lt;em&gt;Sorry for the bad quality of my answer. I do not have access to a computer currently and editing from my phone is not a straightforward task. In particular I would love to be able to paste images.&lt;/em&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would say that the main challenges of simulating hair are:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;replicating their very specific reaction to lighting (as a material)  &lt;/li&gt;&#xA;&lt;li&gt;replicating their volumetric property (as a geometry)  &lt;/li&gt;&#xA;&lt;li&gt;animating them in a realistic manner  &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here is a list of references I gathered on the subject, ordered chronologically &lt;em&gt;(mainly about the rendering part)&lt;/em&gt;:  &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;JAMES T. KAJIYA, TIMOTHY L. KAY, &lt;a href=&quot;https://www.cs.drexel.edu/~david/Classes/CS586/Papers/p271-kajiya.pdf&quot; rel=&quot;nofollow&quot;&gt;Rendering Fur With Three Dimensional Textures&lt;/a&gt;, 1989  &lt;/li&gt;&#xA;&lt;li&gt;JEROME LENGYEL, EMIL PRAUN, ADAM FINKELSTEIN, HUGUES HOPPE, &lt;a href=&quot;http://research.microsoft.com/en-us/um/people/hoppe/fur.pdf&quot; rel=&quot;nofollow&quot;&gt;Real-Time Fur over Arbitrary Surfaces&lt;/a&gt;, 2000  &lt;/li&gt;&#xA;&lt;li&gt;STEPHEN R. MARSCHNER, HENRIK WANN JENSEN, MIKE CAMMARANO, &lt;a href=&quot;http://www.graphics.stanford.edu/papers/hair/hair-sg03final.pdf&quot; rel=&quot;nofollow&quot;&gt;Light Scattering from Human Hair Fibers&lt;/a&gt;, 2003  &lt;/li&gt;&#xA;&lt;li&gt;ARMIN BRUDERLIN, SUNIL HADAP, TAE-YONG KIM, NADIA MAGNENAT-THALMANN , ULRICH NEUMANN, YIZHOU YU, STEVE WORLEY, &lt;a href=&quot;http://www.graphics.stanford.edu/courses/cs448-05-winter/papers/course34.pdf&quot; rel=&quot;nofollow&quot;&gt;Photorealistic Hair Modeling, Animation, and Rendering&lt;/a&gt;, Siggraph 2003 Course  &lt;/li&gt;&#xA;&lt;li&gt;THORSTEN SCHEUERMANN, &lt;a href=&quot;http://bookzz.org/book/487747/b3254e&quot; rel=&quot;nofollow&quot;&gt;Hair Rendering and Shading&lt;/a&gt;, ShaderX3, 2004  &lt;/li&gt;&#xA;&lt;li&gt;THORSTEN SCHEUERMANN, &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Scheuermann_HairRendering.pdf&quot; rel=&quot;nofollow&quot;&gt;Hair Rendering and Shading&lt;/a&gt;, ATI / GDC 2004  &lt;/li&gt;&#xA;&lt;li&gt;THORSTEN SCHEUERMANN, &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Scheuermann_HairSketch.pdf&quot; rel=&quot;nofollow&quot;&gt;Practical Real-Time Hair Rendering and Shading&lt;/a&gt;, ATI / Siggraph 2004  &lt;/li&gt;&#xA;&lt;li&gt;THORSTEN SCHEUERMANN, &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Scheuermann_HairSketchSlides.pdf&quot; rel=&quot;nofollow&quot;&gt;Practical Real-Time Hair Rendering and Shading&lt;/a&gt;, ATI / Siggraph 2004 (slides)  &lt;/li&gt;&#xA;&lt;li&gt;MARTIN KOSTER, JORG HABER, HANS-PETER SEIDEL, &lt;a href=&quot;http://resources.mpi-inf.mpg.de/FAM/publ/cgi2004.pdf&quot; rel=&quot;nofollow&quot;&gt;Real-Time Rendering of Human Hair using Programmable Graphics Hardware&lt;/a&gt;, 2004  &lt;/li&gt;&#xA;&lt;li&gt;HUBERT NGUYEN, WILLIAM DONNELLY, &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter23.html&quot; rel=&quot;nofollow&quot;&gt;Hair Animation and Rendering in the Nalu Demo&lt;/a&gt;, GPU Gems 2 (Chapter 23), 2005  &lt;/li&gt;&#xA;&lt;li&gt;LENA PETROVIC, MARK HENNE, JOHN ANDERSON, &lt;a href=&quot;http://graphics.pixar.com/library/Hair/paper.pdf&quot; rel=&quot;nofollow&quot;&gt;Volumetric Methods for Simulation and Rendering of Hair&lt;/a&gt;, Pixar 2006  &lt;/li&gt;&#xA;&lt;li&gt;CHRISTOPHE HERY, RAVI RAMAMOORTHI, &lt;a href=&quot;http://graphics.pixar.com/library/ImportanceSamplingHair/paper.pdf&quot; rel=&quot;nofollow&quot;&gt;Importance Sampling of Reflections from Hair Fibers&lt;/a&gt;, Pixar 2007  &lt;/li&gt;&#xA;&lt;li&gt;SARAH TARIQ, LOUIS BAVOIL, &lt;a href=&quot;http://www.nvidia.com/object/siggraph-2008-hair.html&quot; rel=&quot;nofollow&quot;&gt;Real-Time Hair Rendering on the GPU&lt;/a&gt;, Siggraph 2008. &lt;/li&gt;&#xA;&lt;li&gt;ARNO ZINKE, CEM YUKSEL, ANDREAS WEBER, JOHN KEYSER, &lt;a href=&quot;http://research.cs.tamu.edu/keyser/Papers/Siggraph08_dualscattering.pdf&quot; rel=&quot;nofollow&quot;&gt;Dual Scattering Approximation for Fast Multiple Scattering in Hair&lt;/a&gt;, Siggraph 2008  &lt;/li&gt;&#xA;&lt;li&gt;IMAN SADEGHI, HEATHER PRITCHETT, HENRIK WANN JENSEN, RASMUS TAMSTORF, &lt;a href=&quot;http://graphics.ucsd.edu/~henrik/papers/artist_hair.pdf&quot; rel=&quot;nofollow&quot;&gt;An Artist Friendly Hair Shading System&lt;/a&gt;, 2010  &lt;/li&gt;&#xA;&lt;li&gt;EUGENE D’EON, GUILLAUME FRANCOIS, MARTIN HILL, JOE LETTERI, JEAN-MARIE AUBRY, &lt;a href=&quot;http://www.eugenedeon.com/project/an-energy-conserving-hair-reflectance-model/&quot; rel=&quot;nofollow&quot;&gt;An Energy-Conserving Hair Reflectance Model&lt;/a&gt;, 2011  &lt;/li&gt;&#xA;&lt;li&gt;XUAN YU, JASON C. YANG, JUSTIN HENSLEY, TAKAHIRO HARADA, JINGYI YU, &lt;a href=&quot;http://www.eecis.udel.edu/~xyu/publications/frameworkhair124.pdf&quot; rel=&quot;nofollow&quot;&gt;A Framework for Rendering Complex Scattering Effects on Hair&lt;/a&gt;, 2012  &lt;/li&gt;&#xA;&lt;li&gt;JIAWEI OU, FENG XIE, PARASHAR KRISHNAMACHARI, FABIO PELLACINI, &lt;a href=&quot;http://pellacini.di.uniroma1.it/publications/ishair12/ishair12-paper.pdf&quot; rel=&quot;nofollow&quot;&gt;ISHair: Importance Sampling for Hair Scattering&lt;/a&gt;, 2012  &lt;/li&gt;&#xA;&lt;li&gt;SARAH INVERNIZZI, &lt;a href=&quot;http://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc13/07/MSc_thesis_On_physically_based_hair_rendering.pdf&quot; rel=&quot;nofollow&quot;&gt;On Physically Based Hair Rendering&lt;/a&gt;, 2013  &lt;/li&gt;&#xA;&lt;li&gt;WOLFGANG ENGEL, &lt;a href=&quot;http://www.slideshare.net/WolfgangEngel/hair-intombraider-final&quot; rel=&quot;nofollow&quot;&gt;Hair Rendering in Tomb Raider&lt;/a&gt;, 2013  &lt;/li&gt;&#xA;&lt;li&gt;EUGENE D’EON, STEVE MARSCHNER, JOHANNES HANIKA, &lt;a href=&quot;https://cg.ivd.kit.edu/publications/pubhanika/2013_hairbrief.pdf&quot; rel=&quot;nofollow&quot;&gt;Importance Sampling for Physically-Based Hair Fiber Models&lt;/a&gt;, 2013  &lt;/li&gt;&#xA;&lt;li&gt;TIMOTHY MARTIN, WOLFGANG ENGEL, NICOLAS THIBIEROZ, JASON YANG, AND JASON LACROIX, &lt;a href=&quot;http://bookzz.org/book/2373940/c298ee&quot; rel=&quot;nofollow&quot;&gt;TressFX: Advanced Real-Time Hair Rendering&lt;/a&gt;, GPU Pro 5, 2015  &lt;/li&gt;&#xA;&lt;li&gt;LEONID PEKELIS, CHRISTOPHE HERY, RYUSUKE VILLEMIN, JUNYI LING, &lt;a href=&quot;http://graphics.pixar.com/library/DataDrivenHairScattering/paper.pdf&quot; rel=&quot;nofollow&quot;&gt;A Data-Driven Light Scattering Model for Hair&lt;/a&gt;, Pixar 2015  &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I did not read all of these material yet, but here is a little of what I remember (I am more interested by the real-time solutions) :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Kajiya-kay laid the basis for realistic hair / fur rendering  &lt;/li&gt;&#xA;&lt;li&gt;Marschner proposed an improved model, and noted that hair has two distinct specular highlights (one white due to direct reflection, the other colored and sparkling due to reflection inside of the hair fiber)  &lt;/li&gt;&#xA;&lt;li&gt;Scheuermann proposed approximations to simulate the behaviour described by Marschner, approximations suited for real-time (using tricks such as two separate specular highlights, artist-designed specular offset and exponent, noise textures). He also proposed using three rendering passes (opaque, transparent back and front) of polygons to simulate the &quot;volumetric&quot; qualities of hair  &lt;/li&gt;&#xA;&lt;li&gt;Most of the games I heard of seem to use Scheuermann approaches for hair shading. However, this is not an energy-conserving solution. Nevertheless, I think d'Eon attempts to fix this problem in the 2011 paper.&lt;br&gt;&#xA;An other topic of interest is the use of tessellation, that has also been used recently to replace the polygonal approach and simulate hair strands individually.     &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The offline rendering world attempts to solve more advanced challenges. I think most of them are described in the references above.  &lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="110" LastEditDate="2015-08-14T22:40:35.007" LastActivityDate="2015-08-14T22:40:35.007" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="159" PostTypeId="1" CreationDate="2015-08-10T01:52:02.447" Score="11" ViewCount="302" Body="&lt;p&gt;The iris (the colourful ring surrounding the pupil of the eye) is covered in a layer of water, and appears to have opaque elements embedded in transparent and translucent elements. What effects do I need to model in order for the iris to appear realistic close up (the iris taking up over 20% of the image area)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is sub surface scattering necessary or is transparency sufficient? Is it necessary to take into account light from within the eye that entered via the pupil, or can the back of the iris be regarded as completely opaque? Are there other effects that I haven't considered?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking to produce still images offline - the approach does not need to work in real time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've tried covering the eye in a thin transparent film to simulate a water layer, and treating the iris as a section of a transparent ball with coloured transparent radially arranged strands, offset as they are layered front to back. To prevent unwanted effects from light that gets all the way through, I have backed the iris with a matt black sphere section. This still seems to give an eye that looks somewhat artificial (inorganic) and disconnected though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to make this work with geometric primitives such as spheres, cones and cylinders, but I'm open to an approach using triangle meshes if that opens up new possibilities.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-11T13:47:10.233" LastActivityDate="2015-09-23T16:24:11.350" Title="Which effects do I need to take into account for the iris of the eye?" Tags="&lt;photo-realistic&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="160" PostTypeId="1" AcceptedAnswerId="164" CreationDate="2015-08-10T02:02:02.570" Score="14" ViewCount="210" Body="&lt;p&gt;Close up, rain can be modeled as transparent balls of water with appropriate motion blur. This seems impractical for large volumes, which would be necessary for scenes of rain in the distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At distances for which the human eye cannot resolve individual raindrops, how can the effect of rain-filled atmosphere be modeled? This does not need to be efficient enough for real time use, but it does need to allow multiple frames to be produced offline for animation without jarring discontinuities or flickering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What approaches are available for this?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="198" LastEditDate="2015-08-10T09:12:33.097" LastActivityDate="2015-08-10T09:12:33.097" Title="How can I model distant rain?" Tags="&lt;atmospherics&gt;&lt;offline&gt;&lt;animation&gt;&lt;fog&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="161" PostTypeId="1" AcceptedAnswerId="163" CreationDate="2015-08-10T06:26:07.000" Score="37" ViewCount="35179" Body="&lt;p&gt;A lot of ShaderToy demos share the Ray Marching algorithm to render the scene, but they are often written with a very compact style and i can't find any straightforward examples or explanation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what is Ray Marching? Some comments suggests that it is a variation of Sphere Tracing. What are the computational advantages of a such approach?&lt;/p&gt;&#xA;" OwnerUserId="316" LastActivityDate="2019-09-03T15:01:21.987" Title="What is Ray Marching? Is Sphere Tracing the same thing?" Tags="&lt;raytracing&gt;&lt;demoscene&gt;&lt;raymarching&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="14" ContentLicense="CC BY-SA 3.0" />
  <row Id="162" PostTypeId="2" ParentId="161" CreationDate="2015-08-10T07:34:19.733" Score="16" Body="&lt;p&gt;Ray marching is an iterative ray intersection test in which you step along a ray and test for intersections, normally used to find intersections with &lt;em&gt;solid&lt;/em&gt; geometry, where inside/outside tests are fast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JhSP2.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JhSP2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;br/&gt;&lt;sup&gt;Images from &lt;a href=&quot;http://artis.imag.fr/Publications/2006/BD06/relief05.pdf&quot; rel=&quot;noreferrer&quot;&gt;Rendering Geometry with Relief Textures&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A fixed step size is pretty common if you really have no idea where an intersection may occur, but sometimes root finding methods such as a binary or secant search are used instead. Often a fixed step size is used to find the first intersection, followed by a binary search. I first came across ray marching in per-pixel displacement mapping techniques. &lt;a href=&quot;http://www.inf.ufrgs.br/~oliveira/pubs_files/Policarpo_Oliveira_RTM_multilayer_I3D2006.pdf&quot; rel=&quot;noreferrer&quot;&gt;Relief Mapping of Non-Height-Field Surface Details&lt;/a&gt; is a good read!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/msLZp.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/msLZp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's commonly used with space leaping, an acceleration technique where some preprocessing gives a safety distance that you can move along the ray without intersecting geometry, or better yet, without intersecting and then leaving geometry so that you miss it. For example, cone step mapping, and relaxed cone step mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strike&gt;Sphere tracing may refer to an implicit ray-sphere intersection test,&lt;/strike&gt; but it's also the name of a space leaping technique by John Hart, as @joojaa mentions, and used by William Donnelly (&lt;a href=&quot;http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter08.html&quot; rel=&quot;noreferrer&quot;&gt;&lt;em&gt;Per-Pixel Displacement Mapping with Distance Functions&lt;/em&gt;&lt;/a&gt;), where a 3D texture encodes spheres radii in which no geometry exists.&lt;/p&gt;&#xA;" OwnerUserId="198" LastEditorUserId="198" LastEditDate="2015-08-10T07:41:52.513" LastActivityDate="2015-08-10T07:41:52.513" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="163" PostTypeId="2" ParentId="161" CreationDate="2015-08-10T07:35:06.200" Score="42" Body="&lt;h3&gt;TL;DR&lt;/h3&gt;&#xA;&lt;p&gt;They belong to the same family of solvers, where sphere tracing is one method of ray marching, which is the family name.&lt;/p&gt;&#xA;&lt;h3&gt;Raymarching a definition&lt;/h3&gt;&#xA;&lt;p&gt;Raymarching is a technique a bit like traditional raytracing where the surface function is not easy to solve (or impossible without numeric iterative methods). In raytracing you just look up the ray intersection, whereas in ray marching you march forward (or back and forth) until you find the intersection, have enough samples or whatever it is your trying to solve. Try to think of it like a newton-raphson method for surface finding, or summing for integrating a varying function.&lt;/p&gt;&#xA;&lt;p&gt;This can be useful if you:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Need to render volumetrics that arenot uniform&lt;/li&gt;&#xA;&lt;li&gt;Rendering implicit functions, fractals&lt;/li&gt;&#xA;&lt;li&gt;Rendering other kinds of parametric surfaces where intersection is not known ahead of time, like paralax mapping&lt;/li&gt;&#xA;&lt;li&gt;Etc&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/bc4D5.png&quot; alt=&quot;Traditional raymarching&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Traditional ray marching for surface finding&lt;/p&gt;&#xA;&lt;p&gt;Related posts:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://gamedev.stackexchange.com/questions/67719/how-do-raymarch-shaders-work&quot;&gt;how-do-raymarch-shaders-work&lt;/a&gt; (GameDev.SE)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3&gt;Sphere tracing&lt;/h3&gt;&#xA;&lt;p&gt;Sphere tracing is one possible Ray marching algorithm. Not all raymarching uses benefit form this method, as they can not be converted into this kind of scheme.&lt;/p&gt;&#xA;&lt;p&gt;Sphere tracing is used for rendering &lt;a href=&quot;https://en.wikipedia.org/wiki/Implicit_surface&quot; rel=&quot;noreferrer&quot;&gt;implicit surfaces&lt;/a&gt;. Implicit surfaces are formed at some level of a continuous function. In essence solving the equation&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;F(X,Y,Z) = 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Because of how this function can be solved at each point, one can go ahead and estimate the biggest possible sphere that can fit the current march step (or if not exactly reasonably safely). You then know that next march distance is at least this big. This way you can have adaptive ray marching steps speeding up the process.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/dFHFY.png&quot; alt=&quot;Sphere tracing has a adaptive step size&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Sphere tracing* in action note how the step size is adaptive&lt;/p&gt;&#xA;&lt;p&gt;For more info see:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://graphics.cs.illinois.edu/sites/default/files/zeno.pdf&quot; rel=&quot;noreferrer&quot;&gt;Sphere tracing: a geometric method for the antialiased ray tracing of implicit surfaces&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;* Perhaps in 2d it's should be called circle tracing :)&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-08-10T13:44:05.627" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="164" PostTypeId="2" ParentId="160" CreationDate="2015-08-10T08:09:19.900" Score="8" Body="&lt;p&gt;When you think about rain in the distance (generally), you will have rain at several different depths from the camera, some close up, some very far away, all of which will look slightly different as you won't be able to focus on all of them. But the effect of them all layering on top of each other as they go off into the distance is what helps give the look you're aiming for, you need to recreate that depth and layering to really give the look of rain further in the distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Particle emitters are the general method of creating rain, as usually they use very small meshes, or even just a texture sprite of a drop. This keeps them pretty efficient - to a degree as the more particles you use and have on-screen at a time will change how heavy or resource dependant the effect becomes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally you would only use large detailed meshes for rain, when you have a close up of a puddle and wanted to animate the splash, or even a close up of the single drop for some reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be combined with distance fog to further increase the sense of depth in your scene by occluding the objects in the far distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Again you could use another particle emitter to create dark, heavy clouds that go off into the distance, as having clouds in the scene will help to sell the look.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A lot of this will depend on what software you're using, as well as its intended platform, as different software have different solutions but particles and fog are pretty commonplace.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;tldr: Particle Effects &amp;amp; Distance Fog&lt;/p&gt;&#xA;" OwnerUserId="118" LastActivityDate="2015-08-10T08:09:19.900" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="165" PostTypeId="1" AcceptedAnswerId="8788" CreationDate="2015-08-10T09:39:33.647" Score="12" ViewCount="1720" Body="&lt;p&gt;I recently had an &lt;a href=&quot;https://superuser.com/q/930036/264276&quot;&gt;issue with sub-pixel anti-aliasing of text&lt;/a&gt;, which produces very harsh colours and made me wonder how it is meant to be done properly:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SQWSI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SQWSI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I've drawn some cases of a black tile covering thirds of pixels below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CE16y.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CE16y.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The colours match the ones I'm seeing, however when I look at properly antialiased text, the result is not nearly as bright and distracting:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Vrfz.png&quot; alt=&quot;from www.lagom.nl&quot;&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I assume there has to be a balance between a good light intensity and the right colour. What methods are used for sub-pixel anti-aliasing that give such good results?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Update:&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've rendered a white teapot to an image with 3x width and with multisampling. Below I compare averaging every 3 pixels with assigning each to RGB. The colours still seem overly bright in some cases (especially compared to the example above from &lt;a href=&quot;http://www.lagom.nl/lcd-test/subpixel.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;), not that my phone captures them well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/19ABb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/19ABb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/RE5Jv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RE5Jv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BZxjL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BZxjL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/WT6ci.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WT6ci.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qveN5m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qveN5m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/wPGG7m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wPGG7m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;sup&gt;OK, so my monitor needs a little dusting&lt;/sup&gt;&lt;/p&gt;&#xA;" OwnerUserId="198" LastEditorUserId="-1" LastEditDate="2017-03-20T10:18:35.050" LastActivityDate="2019-04-21T01:40:39.120" Title="Sub-pixel antialiasing rules" Tags="&lt;antialiasing&gt;" AnswerCount="2" CommentCount="11" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="166" PostTypeId="1" CreationDate="2015-08-10T10:05:56.743" Score="11" ViewCount="1230" Body="&lt;p&gt;How to quickly draw a curved shape?&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;by &quot;quickly&quot; I presume one should use hardware facilities as much as possible&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;by &quot;curved&quot; I mean boundaries defined by either quadratic or cubic Bezier curves&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;by &quot;shape&quot; I mean either a &quot;fat&quot; stroke (i.e. more than 1px wide) or even-odd/non-zero filled &quot;2D curved polygon&quot;, possibly with holes (i.e. letter &quot;O&quot;)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I'm asking because the options I know of have several drawbacks:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;triangulating the shape and sending it to OpenGL - does the most difficult work on CPU and might use too many/few triangles (i.e. wasteful/coarse)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;texture atlas - has to recompute/upload the texture on every change (shape, scale, rotation, ...)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Signed distance field - on large scales the details don't look pretty or has to recompute/upload the texture&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;NV_path_rendering - could be it, if it was not working only on Nvidia's cards&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;OpenVG - could be it, if it was not working only on mobile&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;* It seems to me that OpenVG is not exactly moving forward, to put it mildly. Does anyone know anything about its future prospects? Is it worth at all to keep an eye on in the present day?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;** OpenGL 4+ provides means of on-fly tessellation of polygons. Could it be somehow used to refine the the mesh from the &quot;triangulating&quot; option so that the shape boundary at least wont look &quot;angled&quot;?&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2015-11-15T12:17:42.913" Title="Hardware-accelerated drawing of curved shapes" Tags="&lt;drawing&gt;&lt;2d&gt;&lt;bezier-curve&gt;" AnswerCount="2" CommentCount="7" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="167" PostTypeId="2" ParentId="165" CreationDate="2015-08-10T10:38:50.383" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;What methods are used for sub-pixel anti-aliasing that give such good results?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You simply rasterize the letters as if they were 3x as wide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The results differ in the way you rasterize the curves, most notably what kind of anti-aliasing/sampling scheme does it use and whether it makes use of &lt;a href=&quot;https://en.wikipedia.org/wiki/Font_hinting&quot; rel=&quot;nofollow&quot;&gt;font hinting&lt;/a&gt;. For great overview see &lt;a href=&quot;http://www.antigrain.com/research/font_rasterization/&quot; rel=&quot;nofollow&quot;&gt;Texts Rasterization Exposures&lt;/a&gt; by Anti-Grain Geometry (IIRC this is what Chromium/PDFium uses) or &lt;a href=&quot;https://en.wikipedia.org/wiki/Subpixel_rendering&quot; rel=&quot;nofollow&quot;&gt;Subpixel rendering&lt;/a&gt; on Wikipedia.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What the attached image goes, I don't believe it has anything to do with sub-pixel rendering. It could be anything: wrong &lt;a href=&quot;https://en.wikipedia.org/wiki/Pixel_geometry&quot; rel=&quot;nofollow&quot;&gt;pixel geometry&lt;/a&gt;, wrong gamma, wrong color space conversion, ...&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2015-08-10T10:38:50.383" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="168" PostTypeId="2" ParentId="151" CreationDate="2015-08-10T12:07:14.027" Score="16" Body="&lt;p&gt;Assuming you mean a camera that rotates based on mouse movement:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to implement it is to keep track of the camera position and its rotation in space. Spherical coordinates happen to be convenient for this, since you can represent the angles directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9kXOr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9kXOr.png&quot; alt=&quot;Spherical Coordinates Image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float m_theta;&#xA;float m_phi;&#xA;float m_radius;&#xA;&#xA;float3 m_target;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The camera is located at &lt;em&gt;P&lt;/em&gt; which is defined by m_theta, m_phi, and m_radius. We can rotate and move freely wherever we want by changing those three values. However, we always look at, and rotate around, m_target. m_target is the local origin of the sphere. However, we are free to move this origin wherever we want in world space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are three main camera functions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Rotate(float dTheta, float dPhi);&#xA;void Zoom(float distance);&#xA;void Pan(float dx, float dy);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In their simplest forms, Rotate() and Zoom() are trivial. The just modify m_theta, m_phi, and m_radius respectively:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Camera::Rotate(float dTheta, float dPhi) {&#xA;    m_theta += dTheta;&#xA;    m_phi += dPhi;&#xA;}&#xA;&#xA;void Camera::Zoom(float distance) {&#xA;    m_radius -= distance;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Panning is a bit more complicated. A camera pan is defined as moving the camera to the left/right and/or up/down respective to the current camera view. The easiest way we can accomplish this is to convert our current camera view from spherical coordinates to cartesian coordinates. This will give us an &lt;em&gt;up&lt;/em&gt; and &lt;em&gt;right&lt;/em&gt; vectors.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Camera::Pan(float dx, float dy) {&#xA;    float3 look = normalize(ToCartesian());&#xA;    float3 worldUp = float3(0.0f, 1.0f, 0.0f, 0.0f);&#xA;&#xA;    float3 right = cross(look, worldUp);&#xA;    float3 up = cross(look, right);&#xA;&#xA;    m_target = m_target + (right * dx) + (up * dy);&#xA;}&#xA;&#xA;inline float3 ToCartesian() {&#xA;    float x = m_radius * sinf(m_phi) * sinf(m_theta);&#xA;    float y = m_radius * cosf(m_phi);&#xA;    float z = m_radius * sinf(m_phi) * cosf(m_theta);&#xA;    float w = 1.0f;&#xA;&#xA;    return float3(x, y, z, w);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So, first, we convert our spherical coordinate system to cartesian to get our &lt;em&gt;look&lt;/em&gt; vector. Next, we do the vector cross product with the world &lt;em&gt;up&lt;/em&gt; vector, in order to get a &lt;em&gt;right&lt;/em&gt; vector. This is a vector that points directly right of the camera view. Lastly, we do another vector cross product to get the camera &lt;em&gt;up&lt;/em&gt; vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To finish the pan, we move m_target along the &lt;em&gt;up&lt;/em&gt; and &lt;em&gt;right&lt;/em&gt; vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One question you might be asking is: Why convert between cartesian and spherical all the time (you will also have to convert in order to create the View matrix). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Good question. I too had this question and tried to exclusively use cartesian. You end up with problems with rotations. Since floating point operations are not exactly precise, multiple rotations end up accumulating errors, which corresponded to the camera slowly, and unintentionally rolling. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1OFpX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1OFpX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, in the end, I stuck with spherical coordinates. In order to counter the extra calculations, I ended up caching the view matrix, and only calculate it when the camera moves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last step is to &lt;em&gt;use&lt;/em&gt; this Camera class. Just call the appropriate member function inside your app's MouseDown/Up/Scroll functions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void MouseDown(WPARAM buttonState, int x, int y) {&#xA;    m_mouseLastPos.x = x;&#xA;    m_mouseLastPos.y = y;&#xA;&#xA;    SetCapture(m_hwnd);&#xA;}&#xA;&#xA;void MouseUp(WPARAM buttonState, int x, int y) {&#xA;    ReleaseCapture();&#xA;}&#xA;&#xA;void MouseMove(WPARAM buttonState, int x, int y) {&#xA;    if ((buttonState &amp;amp; MK_LBUTTON) != 0) {&#xA;        if (GetKeyState(VK_MENU) &amp;amp; 0x8000) {&#xA;            // Calculate the new phi and theta based on mouse position relative to where the user clicked&#xA;            float dPhi = ((float)(m_mouseLastPos.y - y) / 300);&#xA;            float dTheta = ((float)(m_mouseLastPos.x - x) / 300);&#xA;&#xA;            m_camera.Rotate(-dTheta, dPhi);&#xA;        }&#xA;    } else if ((buttonState &amp;amp; MK_MBUTTON) != 0) {&#xA;        if (GetKeyState(VK_MENU) &amp;amp; 0x8000) {&#xA;            float dx = ((float)(m_mouseLastPos.x - x));&#xA;            float dy = ((float)(m_mouseLastPos.y - y));&#xA;&#xA;            m_camera.Pan(-dx * m_cameraPanFactor, dy * m_cameraPanFactor);&#xA;        }&#xA;    }&#xA;&#xA;    m_mouseLastPos.x = x;&#xA;    m_mouseLastPos.y = y;&#xA;}&#xA;&#xA;void MouseWheel(int zDelta) {&#xA;    // Make each wheel dedent correspond to a size based on the scene&#xA;    m_camera.Zoom((float)zDelta * m_cameraScrollFactor);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The m_camera*Factor variables are just scale factors that change how quickly your camera rotates/pans/scrolls&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code I have above is a simplified pseudo-code version of the camera system I made for a side project: &lt;a href=&quot;https://github.com/RichieSams/thehalflingproject/blob/master/source/scene/camera.h&quot; rel=&quot;noreferrer&quot;&gt;camera.h&lt;/a&gt; and &lt;a href=&quot;https://github.com/RichieSams/thehalflingproject/blob/master/source/scene/camera.cpp&quot; rel=&quot;noreferrer&quot;&gt;camera.cpp&lt;/a&gt;. The camera tries to imitate the Maya camera system. The code is free and open source, so feel free to use it in your own project. &lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2016-02-09T06:19:09.250" LastActivityDate="2016-02-09T06:19:09.250" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="169" PostTypeId="1" AcceptedAnswerId="194" CreationDate="2015-08-10T13:00:41.330" Score="8" ViewCount="185" Body="&lt;p&gt;Different screens can have different &lt;a href=&quot;https://en.wikipedia.org/wiki/Pixel_geometry&quot;&gt;pixel geometry&lt;/a&gt;, so that the red, green and blue components are arranged in different patterns. Using sub-pixel rendering to give a higher apparent resolution is only possible if the pixel geometry is known (what will give an improvement in clarity on one type of monitor will make things worse on another).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is particularly relevant if an application needs to run on both a desktop/laptop and a mobile screen, as different pixel geometry is quite common in mobile screens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to determine which geometry the screen uses at runtime, without having to ask the user? I'm interested in whether this is possible in general, but ideally I'd like to know whether this is possible when using JavaScript with WebGL.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-11T05:26:44.280" Title="Can I determine the pixel geometry programmatically?" Tags="&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="170" PostTypeId="1" AcceptedAnswerId="171" CreationDate="2015-08-10T13:03:23.800" Score="7" ViewCount="2898" Body="&lt;p&gt;It is no secret that according to the &lt;a href=&quot;http://developer.android.com/reference/android/opengl/package-summary.html&quot;&gt;official documentation&lt;/a&gt; extensions are not available under OpenGL ES 2.0. Nevertheless, the &lt;em&gt;glext.h&lt;/em&gt; file present in the NDK platform-include directories makes me think that extensions are indeed available. I know that working with OpenGL under NDK doesn't differ from working with standalone OpenGL. So, if I make something like a JNI bridge between my java engine interface and these extensions, I could use them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is: what architectural solution should I use if I want to use available OpenGL ES extensions on ES2.0 devices?&lt;/p&gt;&#xA;" OwnerUserId="333" LastEditorUserId="231" LastEditDate="2015-08-10T13:08:42.690" LastActivityDate="2015-08-10T13:15:04.140" Title="Using extensions in Android OpenGL ES 2.0" Tags="&lt;opengl&gt;&lt;android&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="171" PostTypeId="2" ParentId="170" CreationDate="2015-08-10T13:15:04.140" Score="5" Body="&lt;p&gt;I have encountered devices that advertise certain extensions via glGetString(GL_EXTENSIONS) and do not expose the entry points. I have also encountered the opposite, the extension was not in the extension strings but the entry points were there and it worked. It depends on whether the vendor has disabled any features in the driver from the GPU provider.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You will need to check both the extension strings and check if the entry point is not NULL via &lt;a href=&quot;https://www.khronos.org/registry/egl/sdk/docs/man/html/eglGetProcAddress.xhtml&quot; rel=&quot;nofollow&quot;&gt;eglGetProcAddress&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apart from that, each extension should conform to the &lt;a href=&quot;https://www.khronos.org/registry/gles/#headers2&quot; rel=&quot;nofollow&quot;&gt;Khronos registry of extensions&lt;/a&gt; so you can include gl2ext.h directly from there if you wanted.&lt;/p&gt;&#xA;" OwnerUserId="135" LastActivityDate="2015-08-10T13:15:04.140" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="173" PostTypeId="5" CreationDate="2015-08-10T13:21:38.380" Score="0" Body="&lt;p&gt;&lt;strong&gt;OpenGL&lt;/strong&gt; (Open Graphics Library) is an API used to interact with GPUs (Graphics Processing Units). Originally developed by &lt;a href=&quot;http://www.sgi.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SGI (Silicon Graphics Inc.)&lt;/a&gt; in the early '90s, the current API is being developed by the &lt;a href=&quot;http://www.khronos.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Khronos Group&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;OpenGL is platform-independent and available for desktop, workstation and mobile devices. It is designed to provide hardware-accelerated rendering and is typically used for applications such as CAD software and computer games.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;a href=&quot;/questions/tagged/opengl&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;opengl&amp;#39;&quot; rel=&quot;tag&quot;&gt;opengl&lt;/a&gt; tag should only be used for questions about desktop OpenGL. OpenGL ES (OpenGL for Embedded Systems) and WebGL have their own tags - &lt;a href=&quot;/questions/tagged/opengl-es&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;opengl-es&amp;#39;&quot; rel=&quot;tag&quot;&gt;opengl-es&lt;/a&gt; and &lt;a href=&quot;/questions/tagged/webgl&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;webgl&amp;#39;&quot; rel=&quot;tag&quot;&gt;webgl&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h3&gt;Official Documentation&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The Red Book - Tutorial GL&lt;/li&gt;&#xA;&lt;li&gt;The Orange Book - Tutorial for GLSL&lt;/li&gt;&#xA;&lt;li&gt;The Green Book - Tutorial for GLX&lt;/li&gt;&#xA;&lt;li&gt;The Blue Book - API references for GL (out of print; replaced by &lt;a href=&quot;http://www.opengl.org/sdk/docs/man/&quot; rel=&quot;nofollow noreferrer&quot;&gt;online reference pages&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;The White Book - Tutorial for WGL&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3&gt;Successor&lt;/h3&gt;&#xA;&lt;p&gt;Khronos Group announced &lt;a href=&quot;/questions/tagged/vulkan&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;vulkan&amp;#39;&quot; rel=&quot;tag&quot;&gt;vulkan&lt;/a&gt; API at GDC (Game Developers Conference) 2015. Vulkan, previously known as glNext or the &amp;quot;Next Generation OpenGL Initiative&amp;quot;, is widely thought of as the successor to OpenGL and shares many similarities to the &lt;a href=&quot;/questions/tagged/mantle&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;mantle&amp;#39;&quot; rel=&quot;tag&quot;&gt;mantle&lt;/a&gt; API. It is a complete redesign aimed to unify the OpenGL and OpenGL-ES API's into one common API that will not be backward compatible.&lt;/p&gt;&#xA;&lt;h3&gt;External resources&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.opengl.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL.org&lt;/a&gt;, the home of OpenGL.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.opengl.org/registry&quot; rel=&quot;nofollow noreferrer&quot;&gt;The OpenGL Registry&lt;/a&gt; is the source for OpenGL headers and specifications.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.opengl.org/wiki/Main_Page&quot; rel=&quot;nofollow noreferrer&quot;&gt;The OpenGL Wiki&lt;/a&gt;, a wiki that contains OpenGL tutorials and documentation.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.khronos.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Khronos group&lt;/a&gt;, the consortium that controls the OpenGL standard.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/OpenGL&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Wikipedia Article&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.khronos.org/vulkan/&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Vulkan API (OpenGL successor)&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3&gt;Unofficial Tutorials&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://alfonse.bitbucket.io/oldtut/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Learning Modern 3D Graphics Programming&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://learnopengl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Learn OpenGL&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://ogldev.atspace.co.uk/&quot; rel=&quot;nofollow noreferrer&quot;&gt;ogldev modern OpenGL tutorial&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Overv's &lt;a href=&quot;http://open.gl/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL guide&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Joe Groff's &lt;a href=&quot;http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Intro to modern OpenGL&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://openglbook.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Yet another modern OpenGL tutorial&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.lighthouse3d.com/tutorials/glsl-core-tutorial/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lighthouse3D GLSL core tutorial&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3&gt;Books&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/0321773039&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3 (8th Edition)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/0321637631&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Shading Language (3rd Edition)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://www.openglsuperbible.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Superbible: Comprehensive Tutorial and Reference (7th Edition)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.packtpub.com/application-development/opengl-data-visualization-cookbook&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Data Visualization Cookbook&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.crcpress.com/Computer-Graphics-Through-OpenGL-From-Theory-to-Experiments-Second-Edition/Guha/p/book/9781482258394&quot; rel=&quot;nofollow noreferrer&quot;&gt;Computer Graphics Through OpenGL: From Theory to Experiments, Second Edition&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.packtpub.com/game-development/opengl-development-cookbook&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Development Cookbook&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/1848000227&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Graphics Through Applications&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/0136053580&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;Computer Graphics with Open GL (4th Edition) &lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/159863528X&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;Beginning OpenGL Game Programming, Second Edition&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3&gt;Release Dates&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;OpenGL 1.0 - January 1992&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 1.1 - January 1997&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 1.2.1 - October 1998&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 1.3 - August 2001&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 1.4 - July 2002&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 1.5 - July 2003&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 2.0 - September 2004&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 2.1 - July 2006&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 3.0 - August 2008&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 3.1 - March 2009&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 3.2 - August 2009&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 3.3 - March 2010&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.0 - March 2010&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.1 - July 2010&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.2 - August 2011&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.3 - August 2012&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.4 - July 2013&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.5 - August 2014&lt;/li&gt;&#xA;&lt;li&gt;OpenGL 4.6 - July 31, 2017&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="-1" LastEditorUserId="13095" LastEditDate="2020-09-22T07:57:17.580" LastActivityDate="2020-09-22T07:57:17.580" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="174" PostTypeId="4" CreationDate="2015-08-10T13:21:38.380" Score="0" Body="OpenGL (Open Graphics Library) is a graphics standard and API which is platform-independent and available for desktop, workstation and mobile devices. It is designed to provide hardware-accelerated rendering, and hence gives greatly improved performance over traditional software rendering.&#xD;&#xA;OpenGL is used for applications like CAD software and computer games. The OpenGL standard, as well as OpenGL ES, is controlled by the Khronos group." OwnerUserId="231" LastEditorUserId="13095" LastEditDate="2020-09-22T07:57:17.580" LastActivityDate="2020-09-22T07:57:17.580" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="175" PostTypeId="1" CreationDate="2015-08-10T14:38:40.183" Score="3" ViewCount="89" Body="&lt;p&gt;If I were to analyze or change an &lt;a href=&quot;https://en.wikipedia.org/wiki/ICC_profile&quot; rel=&quot;nofollow noreferrer&quot;&gt;ICC profile&lt;/a&gt; embedded in an image, how should I proceed?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd also be glad to understand how an &quot;end-user&quot; is able to create these with a &lt;a href=&quot;https://en.wikipedia.org/wiki/Tristimulus_colorimeter&quot; rel=&quot;nofollow noreferrer&quot;&gt;tristimulus colorimeter&lt;/a&gt; or a &lt;a href=&quot;https://en.wikipedia.org/wiki/Spectrophotometer&quot; rel=&quot;nofollow noreferrer&quot;&gt;spectrophotometer&lt;/a&gt; and if/how this new profile can be added to a color capturing device (i.e. a camera).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My curiosity comes from images that were taken by a professional photographer. When I open them in GIMP, there's a pop-up referring &quot;there is an embedded ICC profile&quot; and if I &quot;would like to convert the image to RGB (sRGB built-in)&quot;. I always convert all of them before using them, since the colors are slightly improved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the image as it was provided by the photographer:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Y4TQL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y4TQL.jpg&quot; alt=&quot;No ICC&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is after the embedded ICC profile was applied:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M1Dt0.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M1Dt0.jpg&quot; alt=&quot;With ICC&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="157" LastEditDate="2015-08-10T14:46:49.100" LastActivityDate="2015-08-16T18:15:33.757" Title="How is an ICC profile embedded or built into an image?" Tags="&lt;color&gt;&lt;color-management&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="176" PostTypeId="1" AcceptedAnswerId="193" CreationDate="2015-08-10T17:43:35.103" Score="7" ViewCount="607" Body="&lt;p&gt;While rendering my scene with OpenGL, I sometimes add an overlay which contains information, settings and a few draggable items. Currently, the overlay has a slightly transparent background to make text easily readable while still allowing the scene to shine through and to let the user see the scene behind/through the overlay.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to replace the transparent background with a translucent background, which (as far as I know) requires the clear image of the scene to be heavily blurred*. And especially on mobile devices (e.g. iPad) with high resolutions and limited processing power, lots of texture lookups and real-time rendering don't work well together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to make real-time translucency feasible on mobile devices like the iPad? Or is there a way to avoid the need to heavily blur the scene in every frame?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As suggested in the comments, here is an image I just found in the Wikipedia that describes the difference between transparency (right column) and translucency (middle column). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iKXOo.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iKXOo.png&quot; alt=&quot;Opacity, translucency and transparency&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Image source: &lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Opacity_Translucency_Transparency.svg&quot; rel=&quot;noreferrer&quot;&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;hr /&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;*I know there is the two-pass blur (first blur in one and then in the other direction) to reduce texture lookups. But for translucency this still requires quite a large number of texture lookups.&lt;/sup&gt;&lt;/p&gt;&#xA;" OwnerUserId="127" LastEditorUserId="127" LastEditDate="2015-08-10T20:41:17.287" LastActivityDate="2015-08-11T05:07:01.950" Title="Real-time translucency effect" Tags="&lt;opengl&gt;&lt;real-time&gt;&lt;mobile&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="177" PostTypeId="1" AcceptedAnswerId="179" CreationDate="2015-08-10T19:59:58.817" Score="11" ViewCount="555" Body="&lt;p&gt;I can model ice cubes as slightly misshapen transparent cubes with the refractive index of water, but they don't look convincing. They look like lumps of glass rather than ice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at real ice cubes I can intuitively describe some differences but I don't know what physical properties to change to match them:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Ice cubes are wet. Mine look like dry glass.&lt;/li&gt;&#xA;&lt;li&gt;Ice cubes are transparent in places and not in others.&lt;/li&gt;&#xA;&lt;li&gt;Ice cubes often have cracks that are visible despite not separating.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;In this instance I am trying to model ice cubes on a surface (in air, not floating in water).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What techniques do I need to include in order to increase the realism?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not looking for real time techniques, just to produce still images. I would like the ice to be photorealistic even close up, and to cast realistic caustics and shadows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried using curved edges and coating my ice cubes with a thin layer of transparent material to simulate a melted layer of water, but it doesn't seem to give the impression of being wet. I've also tried embedding a transparent sphere half the size of the cube at its centre, with a fog effect, but it doesn't blend into the cube naturally - it just looks embedded. Even a series of nested spheres with gradually increasing fog still doesn't look right.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-11T14:03:55.660" LastActivityDate="2015-08-11T23:20:59.580" Title="How can I make my ice cubes look real?" Tags="&lt;refraction&gt;&lt;transparency&gt;&lt;photo-realistic&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="178" PostTypeId="2" ParentId="177" CreationDate="2015-08-10T20:16:23.327" Score="4" Body="&lt;p&gt;Two big ones you're missing:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;nofollow&quot;&gt;Angle-dependent reflection&lt;/a&gt;.  This is one possible cause of your &quot;transparent in places and not in others&quot; effect, and the most likely cause of the missing wetness.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Ice cubes usually have air bubbles trapped inside.  This shows up as a white volumetric haze denser in the center of the cube (for small bubbles) or distinct bubbles (for large ones).  This is the other likely cause of your &quot;transparent in places and not in others&quot;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The techniques for modeling these depend on what rendering method you're using.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-10T20:16:23.327" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="179" PostTypeId="2" ParentId="177" CreationDate="2015-08-10T20:17:10.753" Score="3" Body="&lt;p&gt;According to &lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_refractive_indices&quot; rel=&quot;nofollow&quot;&gt;Wikipedia&lt;/a&gt;, ice has a slightly lower IOR than non-frozen water, though I don't know how much that difference would affect the results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &quot;opaque&quot;-looking parts of an ice cube are caused by clusters of microscopic bubbles formed during freezing. You might be able to model those using geometry, but given the scale and number I suspect that some kind of participating media model would probably be a better fit. (Though I don't know of any.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, remember that most non-submerged ice you'll see is going to very soon form a thin layer of liquid water interfacing it with the air, so this might significantly alter its appearance too.&lt;/p&gt;&#xA;" OwnerUserId="327" LastActivityDate="2015-08-10T20:17:10.753" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="180" PostTypeId="2" ParentId="176" CreationDate="2015-08-10T20:30:20.923" Score="4" Body="&lt;p&gt;There's no way around it. If you want the area behind the textboxes to appear blurry... you're gonna have to blur it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to mitigate the performance cost is to be sure to use a 2-pass separable blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another measure that will probably help (depending on how much of the screen your textboxes cover) is to use scissoring or a stencil test to only compute the blur in the areas of the screen that will later be covered by textboxes. If you do this, be sure to leave an extra vertical padding of at least half the width of your blur kernel, otherwise, the second blurring pass will try to sample uncomputed texels in the intermediate texture, leading to artifacts or darkening of the blur near the edges of the textbox areas. (This isn't an issue for the first pass since you'll be sampling from the original unmasked texture there.)&lt;/p&gt;&#xA;" OwnerUserId="327" LastActivityDate="2015-08-10T20:30:20.923" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="181" PostTypeId="1" CreationDate="2015-08-10T20:40:17.313" Score="5" ViewCount="240" Body="&lt;p&gt;I'm currently preparing to implement variance shadow mapping based on &lt;a href=&quot;https://a248.e.akamai.net/f/1890/806/6/http.developer.nvidia.com/GPUGems3/gpugems3_ch08.html&quot; rel=&quot;noreferrer&quot;&gt;this article&lt;/a&gt;. However, one point it makes concerns me:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Rendering only casters (and not receivers) into the variance shadow map is incorrect! For the interpolation to work properly, the receiving surface must be represented in the depth distribution. If it is not, shadow penumbrae will be improperly sized and fail to fade smoothly from light to dark.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This means that the naive method of rendering an object that does not cast a shadow, but can recieve shadows from other objects - simply skip rendering it into the shadow map - will not work. How else can this be accomplished?&lt;/p&gt;&#xA;" OwnerUserId="349" LastActivityDate="2015-08-11T04:49:54.333" Title="How to render an object that recieves shadows but does not cast them in a variance shadow mapping system?" Tags="&lt;opengl&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="183" PostTypeId="1" AcceptedAnswerId="184" CreationDate="2015-08-10T21:39:52.303" Score="4" ViewCount="210" Body="&lt;p&gt;I want to be able to model an opaque liquid being dropped into a transparent liquid with sufficient velocity to cause turbulence and the resulting chaotic mixing. Assuming the two liquids are of the same density and viscosity, how could I model this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This doesn't need to be rendered in real time. I would like the turbulent flow to gradually settle down as the two fluids mix, but it will not be required to interact with other objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried modelling an expanding interface between the two fluids, and accelerating the vertices of the interface based on the local curvature, adding new vertices as they move apart. This seemed to work in the early stages, giving a constant exaggeration of small surface imperfections to create at least the appearance of turbulence, but it ran into problems very early which seemed to result from the interface self-intersecting. I've been trying to think of ways to redirect vertices that are near to causing a surface self-intersection, but I wonder if I would be better off starting from scratch with a more amenable method.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-11T14:45:32.540" LastActivityDate="2015-08-11T14:45:32.540" Title="How can I model ink dropped into still water?" Tags="&lt;simulation&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="184" PostTypeId="2" ParentId="183" CreationDate="2015-08-10T23:21:28.050" Score="10" Body="&lt;p&gt;Simulating drops of ink is probably one of the best applications of the &lt;a href=&quot;http://doc.utwente.nl/56247/1/K227____.pdf&quot;&gt;Vorton Method&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unlike fluid solvers based on the velocity form of the Navier-Stokes equations, which track the density and velocity of a fluid, the Vorton Method tracks vorticity instead. It does so by simulating a large number of vortons, each carrying a small amount of vorticity; you can think of a vorton as being a tiny particle that induces a small spinning vortex around itself. The sum of velocities caused by each vortex defines a velocity field in the fluid, which is used to in turn advect the vortons themselves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vorton methods are difficult to combine with boundary conditions and have a few efficiency caveats, but for fluid flow where intricate turbulance is the key feature and boundaries can be avoided, the Vorton method far outshines e.g. Eulerian grid solvers, which would need a large resolution to simulate turbulence at a comparable scale.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Michael Gourlay has a very accessible &lt;a href=&quot;http://www.mijagourlay.com/fluid&quot;&gt;article series&lt;/a&gt; on the vorton method. Although his articles are targeted at video games, they hold up similarly for off-line simulation. Here's also an &lt;a href=&quot;https://www.youtube.com/watch?v=LD6JfO41JIE&quot;&gt;example video&lt;/a&gt; of a drop of ink simulated using the vorton method.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-10T23:21:28.050" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="185" PostTypeId="1" AcceptedAnswerId="1471" CreationDate="2015-08-10T23:43:46.900" Score="19" ViewCount="731" Body="&lt;p&gt;Most descriptions of Monte Carlo rendering methods, such as path tracing or bidirectional path tracing, assume that samples are generated independently; that is, a standard random number generator is used that generates a stream of independent, uniformly distributed numbers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We know that samples that are not chosen independently can be beneficial in terms of noise. For example, stratified sampling and low-discrepancy sequences are two examples of correlated sampling schemes that almost always improve render times.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there are many cases where the impact of sample correlation is not as clear-cut. For example, Markov Chain Monte Carlo methods such as &lt;a href=&quot;https://graphics.stanford.edu/papers/metro/metro.pdf&quot;&gt;Metropolis Light Transport&lt;/a&gt; generate a stream of correlated samples using a Markov chain; &lt;a href=&quot;http://www.csie.ntu.edu.tw/~cyy/courses/rendering/13fall/lectures/handouts/ManyLight-I.pdf&quot;&gt;many-light methods&lt;/a&gt; reuse a small set of light paths for many camera paths, creating many correlated shadow connections; even &lt;a href=&quot;http://graphics.stanford.edu/~henrik/papers/ewr7/egwr96.pdf&quot;&gt;photon mapping&lt;/a&gt; gains its efficiency from reusing light paths across many pixels, also increasing sample correlation (although in a biased way).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of these rendering methods can prove beneficial in certain scenes, but seem to make things worse in others. It's not clear how to quantify the quality of error introduced by these techniques, other than rendering a scene with different rendering algorithms and eyeballing whether one looks better than the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is: How does sample correlation influence the variance and the convergence of a Monte Carlo estimator? Can we somehow mathematically quantify which kind of sample correlation is better than others? Are there any other considerations that could influence whether sample correlation is beneficial or detrimental (e.g. perceptual error, animation flicker)?&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-09-10T12:27:27.860" Title="How do correlated samples influence the behavior of a Monte Carlo renderer?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;monte-carlo&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="186" PostTypeId="1" AcceptedAnswerId="187" CreationDate="2015-08-11T00:37:44.757" Score="12" ViewCount="673" Body="&lt;p&gt;I'm reading a &lt;a href=&quot;https://books.google.com.br/books/about/Computer_graphics_for_Java_programmers.html?id=vY5RAAAAMAAJ&amp;amp;redir_esc=y&quot;&gt;book on computer graphics&lt;/a&gt;, and at some point, it shows a 3D model, created from a .dat file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are a few rules for the .dat file creation:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Made of a list of vertex positions / faces&lt;/li&gt;&#xA;&lt;li&gt;Written counter-clockwise&lt;/li&gt;&#xA;&lt;li&gt;Faces end with a dot (.)&lt;/li&gt;&#xA;&lt;li&gt;Fractions are also acceptable&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I want to know if this is the standard, and if not, what is the standard way of defining a 3D object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, if there is a specification, who defined it and where to find it?&lt;/p&gt;&#xA;" OwnerUserId="96" LastActivityDate="2018-07-08T15:17:42.233" Title="Is there a standard specification for 3D graphic representation?" Tags="&lt;3d&gt;" AnswerCount="5" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="187" PostTypeId="2" ParentId="186" CreationDate="2015-08-11T02:49:30.960" Score="8" Body="&lt;p&gt;When talking about file formats, we are talking about persisting some data related to a 3D model/geometry. There is no universal standard on file formats for persisting 3D geometry. There are only a few formats more dominant than others.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just as it is with image file formats, the PNGs and JPEGs are the most common formats out there today, but there is no universal agreement between applications on using one or the other. Each app uses the best fit for its purposes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same happens with file formats storing 3D data. Each 3D modeling software will generally have one or a set of preferred formats. Most actually define custom formats that only work with the specific version of the tool. This can happen for many reasons, from simplifying the inner workings of the application, or making loading of files faster, to binding the user to a given tool on purpose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This &lt;code&gt;.dat&lt;/code&gt; format you describe is a custom format created by the authors of the book, which was probably designed with simplicity in mind. It seems to be a text file similar to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Wavefront_.obj_file&quot;&gt;Wavefront OBJ&lt;/a&gt; format, which in turn is a very popular format for storing static geometry, though a bit outdated by now. One could say that the &lt;code&gt;.OBJ&lt;/code&gt; format is the &lt;code&gt;.BMP&lt;/code&gt; of 3D model formats.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other popular 3D model formats include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/COLLADA&quot;&gt;Collada&lt;/a&gt; format.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/.3ds&quot;&gt;3DS&lt;/a&gt; format.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/PLY_(file_format)&quot;&gt;PLY&lt;/a&gt; format.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And many others. More general explanation &lt;a href=&quot;https://en.wikipedia.org/wiki/Polygon_mesh&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note that I said at the beginning that these are formats for storing/persisting a 3D model or geometry on an offline storage. It doesn't mean (and it usually isn't the case) that the applications that use them will store the data internally in memory using the same layout as the file. Normally, this kind of data will undergo a lot of processing after being loaded from a file until it is, for instance, displayed on the screen.&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="54" LastEditDate="2015-08-11T03:01:33.010" LastActivityDate="2015-08-11T03:01:33.010" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="188" PostTypeId="2" ParentId="186" CreationDate="2015-08-11T02:57:02.380" Score="4" Body="&lt;p&gt;There is not a single standard that defines the storage of 3D models. The graphics API only cares about triangles, which are defined by vertices and indices indicating which vertices form a triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many companies have created their own model formats with different features and goals. One of the simplest is the .obj (Wavefront Object) format. Which contains lists of vertex positions, normals and texture coordinates and a list of indices that make up the triangles. It also contains materials, with some basic properties as textures, diffuse and specular colors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More advanced model formats, such as .fbx (FilmBox) used by Autodesk contain additional information required by the modeling software. These might include bones, hierarchies and even more vertex properties used for skinning etc. So there are &quot;standards&quot;, but they are not really unified as every program might require different information. But wavefront is a very good choice, because many modelling applications can export to it and it is easy to write (find) an importer for.&lt;/p&gt;&#xA;" OwnerUserId="64" LastActivityDate="2015-08-11T02:57:02.380" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="189" PostTypeId="2" ParentId="186" CreationDate="2015-08-11T03:00:43.867" Score="5" Body="&lt;p&gt;There is no standard format for 3D models. Some common ones are listed in glampert's answer, more can be found &lt;a href=&quot;https://stackoverflow.com/questions/13600158/recommended-file-formats-and-graphics-libraries-for-importing-3d-model-into-open&quot;&gt;in this SE answer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are designing your own format for your own purposes, (a fairly common thing to do, actually) it's a good first step to look at how you are using your model data. For example, if you are focused on rendering, you can use the format that the graphics library expects. If you want to reduce the load time of your software as much as possible then reducing the amount of parsing and processing you have to do can help. A simple utility that can output a file in the format that your engine expects will mean you can simply map the file into memory and then pass a pointer into your graphics library.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, if rendering is not your main concern and editing is more important to you, you might consider a format more amenable to editing, such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Winged_edge&quot; rel=&quot;nofollow noreferrer&quot;&gt;winged edge&lt;/a&gt;. Using a general purpose model format may suit your purposes at the beginning of a project, but ultimately there are many things you can do with 3D models and each format has its own benefits and drawbacks, so you can choose the one that works best for you.&lt;/p&gt;&#xA;" OwnerUserId="125" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2015-08-11T03:00:43.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="190" PostTypeId="2" ParentId="181" CreationDate="2015-08-11T04:49:54.333" Score="2" Body="&lt;p&gt;Not rendering a shadow caster could work but your mileage can vary. When variance is &quot;large&quot; a VSM is not able to exactly localize the occluders, which causes light leaks. Not rendering a large receiver (let say the floor of a room, a road, etc..) can dramatically increase the variance of the depth samples within a region of the shadow map that include the missing receiver(s) (e.g. the receiver depth is replaced by something much more distant, like the far plane).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, if you skip rendering in the VSM some little object that is unlikely to ever be the most distant receiver in the scene, then you have some hope that things will work out (compatibly with the limitations of variance shadow maps). If you can afford the cost I suggest you to use something more robust like exponential variance shadow maps (see this work: &lt;a href=&quot;https://software.intel.com/en-us/articles/sample-distribution-shadow-maps&quot; rel=&quot;nofollow&quot;&gt;https://software.intel.com/en-us/articles/sample-distribution-shadow-maps&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="355" LastActivityDate="2015-08-11T04:49:54.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="191" PostTypeId="5" CreationDate="2015-08-11T04:50:21.863" Score="0" Body="&lt;p&gt;See also:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Ray_tracing_%28graphics%29&quot; rel=&quot;nofollow&quot;&gt;Ray tracing on Wikipedia&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/tagged/raytracing&quot;&gt;Raytracing implementation questions on Stack Overflow&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-19T08:50:06.257" LastActivityDate="2015-11-19T08:50:06.257" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="192" PostTypeId="4" CreationDate="2015-08-11T04:50:21.863" Score="0" Body="Questions specific to raytracing (as opposed to scanline rendering), the 3D graphics technique of intersecting rays from the camera with objects in the scene." OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-16T15:47:42.347" LastActivityDate="2015-11-16T15:47:42.347" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="193" PostTypeId="2" ParentId="176" CreationDate="2015-08-11T05:07:01.950" Score="6" Body="&lt;p&gt;I think you may want to take another look at the iOS user interface if you consider real-time blurs to be out of range of mobile hardware:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dRT54.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dRT54.png&quot; alt=&quot;iOS control center&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Dt2Sg.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Dt2Sg.png&quot; alt=&quot;iOS notification center&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blurs are totally in range of mobile hardware. Yes, you need a fairly large number of texture samples for a blur with a large kernel, but the texture samples are also cached very well, and you can use a &lt;a href=&quot;https://en.wikipedia.org/wiki/Separable_filter&quot; rel=&quot;noreferrer&quot;&gt;separable blur&lt;/a&gt;, which effectively means that an MxN blur requires M + N samples, not M * N samples. You can also take advantage of hardware bilinear sampling to &lt;a href=&quot;http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/&quot; rel=&quot;noreferrer&quot;&gt;reduce the number of samples&lt;/a&gt; that your blur requires.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-11T05:07:01.950" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="194" PostTypeId="2" ParentId="169" CreationDate="2015-08-11T05:26:44.280" Score="1" Body="&lt;p&gt;It appears that Microsoft has punted on this in Windows 7:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KbzW2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KbzW2.png&quot; alt=&quot;ClearType Text Tuner&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the method available in the control panel for selecting what layout ClearType uses.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, it seems that iOS and the Windows modern UI style de-emphasize subpixel antialiasing heavily, due to the prevalence of animations and screen rotations. As a result I expect the OS vendors to not spend a lot of effort trying to figure out the subpixel layout of every screen.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-11T05:26:44.280" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="195" PostTypeId="2" ParentId="89" CreationDate="2015-08-11T05:45:18.720" Score="9" Body="&lt;p&gt;The most commonly suggested method seems to be &lt;a href=&quot;https://en.wikipedia.org/wiki/Mueller_calculus&quot;&gt;Mueller calculus&lt;/a&gt;, which boils down to tracking the &lt;a href=&quot;https://en.wikipedia.org/wiki/Stokes_parameters&quot;&gt;Stokes parameters&lt;/a&gt; of a light ray to represent the polarization of light transmitted along that ray. A ray might be unpolarized—Stokes parameters of (1, 0, 0, 0)—or it may be circularly or linearly polarized in various directions, which is a property of light in the aggregate. At the surface light is scattered according to the polarization and the Stokes vector is propagated by multiplying it by the Mueller matrix of the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a &lt;a href=&quot;http://cs.au.dk/~toshiya/mcp.pdf&quot;&gt;writeup by Toshiya Hachisuka&lt;/a&gt; about ray tracing while tracking light polarization. It seems like a good introduction, and there are several references that seem promising. The article argues for &lt;em&gt;direct tracking&lt;/em&gt; of the polarization state of the ray: instead of an aggregate representation, individually tracking the direction and frequency of the two harmonic oscillations of a given light ray. This may have the disadvantage that you need more samples to reproduce the polarization effects accurately, but it may be able to reproduce more effects (in the article, thin-film interference).&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-11T05:45:18.720" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="196" PostTypeId="2" ParentId="177" CreationDate="2015-08-11T05:57:28.187" Score="4" Body="&lt;p&gt;I've found that bump mapping when calculating lighting and refraction rays can add a lot to the look of ice. It makes the ice look textured and imperfect, like a melting ice cube would look.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I sort of wonder if maybe animating a bump map could help make it look wet, as water sheets / droplets ran down it's surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The images below look pretty nice, but they would probably look even better with the internal imperfections that other people are talking about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/t5t5K.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t5t5K.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4NJbX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4NJbX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sPo4R.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sPo4R.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my shadertoy where I got the screenshots from: &lt;a href=&quot;https://www.shadertoy.com/view/ldj3zz#&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/ldj3zz#&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-08-11T23:20:59.580" LastActivityDate="2015-08-11T23:20:59.580" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="197" PostTypeId="5" CreationDate="2015-08-11T05:57:44.960" Score="0" Body="&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/OpenGL_Shading_Language&quot; rel=&quot;nofollow&quot;&gt;OpenGL shading language&lt;/a&gt; is a high-level language that can be used to write &lt;a href=&quot;https://en.wikipedia.org/wiki/Shader&quot; rel=&quot;nofollow&quot;&gt;shader programs&lt;/a&gt; that can execute on a GPU.&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2015-08-11T09:06:48.117" LastActivityDate="2015-08-11T09:06:48.117" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="198" PostTypeId="4" CreationDate="2015-08-11T05:57:44.960" Score="0" Body="GLSL is the OpenGL shading language. Use this tag for questions which are specifically about shaders written in this language. For generic shader questions use [shader] instead." OwnerUserId="196" LastEditorUserId="16" LastEditDate="2015-08-16T12:49:01.910" LastActivityDate="2015-08-16T12:49:01.910" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="199" PostTypeId="2" ParentId="183" CreationDate="2015-08-11T06:25:24.990" Score="0" Body="&lt;p&gt;As an alternative you could also check Jon Stam's paper &lt;a href=&quot;http://dx.doi.org/10.1145/311535.311548&quot; rel=&quot;nofollow&quot;&gt;&quot;Stable Fluids&quot;&lt;/a&gt;, that method is usually called the semi-Lagrangian approach to fluid simulations. You can find several implementations of it. You said that you don't need it to be real time, so this might do the work.&lt;/p&gt;&#xA;" OwnerUserId="168" LastActivityDate="2015-08-11T06:25:24.990" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="200" PostTypeId="2" ParentId="186" CreationDate="2015-08-11T07:10:16.647" Score="2" Body="&lt;p&gt;To add to other answers, there are actually two kinds of formats, intermediate and runtime. Intermediate formats (example: COLLADA) are more verbose/slower and are converted between tools ultimately to the custom runtime format that is optimized for a specific application/hardware. Simple applications that do not care much about performance can directly use intermediate formats.&lt;/p&gt;&#xA;" OwnerUserId="67" LastActivityDate="2015-08-11T07:10:16.647" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="201" PostTypeId="1" AcceptedAnswerId="206" CreationDate="2015-08-11T07:12:44.110" Score="7" ViewCount="90" Body="&lt;p&gt;I'm working on a program to use randomly-selected images as a desktop background.  Now, not all images are the same shape as a computer monitor.  One idea I had for dealing with this is to set a background color that is perceptually similar to the image.  How would I go about finding this color?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simple RGB averaging doesn't take into account nonlinearities such as monitor gamma, and doesn't deal with the human vision system.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-11T15:45:12.683" Title="Finding a color perceptually similar to an image" Tags="&lt;color&gt;&lt;human-vision&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="202" PostTypeId="2" ParentId="130" CreationDate="2015-08-11T07:53:30.297" Score="3" Body="&lt;p&gt;Problem fixed by RichieSams, trichoplax and xpicox. Thanks all of you for the answers. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I lower the roughness, change the color of material and reversed the ViewDirection then finally I start to see proper specular :).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fixed Code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;in vec3 Position;&#xA;in vec2 TexCoord0;&#xA;in vec3 Normal;&#xA;in vec3 Tangent;&#xA;out vec4 FinalColor;&#xA;&#xA;uniform vec3 uCameraPosition;&#xA;&#xA;#define PI 3.1415926f&#xA;#define EPSILON 10e-5f&#xA;#define saturate(value) clamp(value, 0.0f, 1.0f);&#xA;&#xA;float BRDF_Lambert(float NdotL)&#xA;{&#xA;    return NdotL;&#xA;}&#xA;&#xA;// Got these BRDF formulas Moving Frostbite to PBR slide by Sebastien Lagarde &amp;amp; Charles de Rousiers &#xA;// http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf&#xA;float BRDF_D_GGX(float NdotH, float Roughness)&#xA;{&#xA;    float Roughness2 = Roughness * Roughness;&#xA;    float f = (NdotH * Roughness2 - NdotH) * NdotH + 1.0f;&#xA;    return Roughness2 / (f * f + EPSILON);&#xA;}&#xA;&#xA;&#xA;float BRDF_F_FresnelSchlick(float LdotH, float F0)&#xA;{&#xA;    float f = F0 + (1.0f - F0) * pow((1.0f - LdotH), 5);&#xA;    return f;&#xA;}&#xA;&#xA;float BRDF_G_SmithGGXCorrelated(float NdotL, float NdotV, float Roughness)&#xA;{&#xA;    float Roughness2 = Roughness * Roughness;&#xA;    float GV = NdotL * sqrt((-NdotV * Roughness2 + NdotV) * NdotV + Roughness2);&#xA;    float GL = NdotV * sqrt((-NdotL * Roughness2 + NdotL) * NdotL + Roughness2);&#xA;&#xA;    return 0.5f / (GV + GL + EPSILON);&#xA;}&#xA;&#xA;float BRDF_Specular(float NdotV, float NdotL, float NdotH, float LdotH, float Roughness, float F0)&#xA;{&#xA;    float D = BRDF_D_GGX(NdotH, Roughness);&#xA;    float F = BRDF_F_FresnelSchlick(LdotH, F0);&#xA;    float G = BRDF_G_SmithGGXCorrelated(NdotL, NdotV, Roughness);&#xA;    return (D * F * G) / PI;&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;    vec3 normal = normalize(Normal);&#xA;&#xA;    vec4 BaseColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);&#xA;    vec4 SpecularColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);&#xA;&#xA;    vec3 LightDirection = normalize(vec3(0, 4, 4) - Position);&#xA;    vec3 ViewDirection = normalize(uCameraPosition - Position);&#xA;    vec3 HalfVector = normalize(ViewDirection + LightDirection);&#xA;    float Roughness = 0.04f;&#xA;&#xA;    float RefractiveIndex = 0.24f; // RI for Gold materials. I got this from http://refractiveindex.info/&#xA;    float F0 = pow(((1.0f - RefractiveIndex) / (1.0f + RefractiveIndex)), 2);&#xA;&#xA;    float NdotL = saturate(dot(LightDirection, normal));&#xA;    float NdotV = abs(dot(ViewDirection, normal)) + EPSILON; // Avoid artifact - Ref: SIGGRAPH14 - Moving Frosbite to PBR&#xA;    float LdotH = saturate(dot(LightDirection, HalfVector));&#xA;    float NdotH = saturate(dot(normal, HalfVector));&#xA;&#xA;    float DiffuseFactor = BRDF_Lambert(NdotL);&#xA;    float SpecularFactor = 0.0f;&#xA;    if(DiffuseFactor &amp;gt; 0.0f)&#xA;    {&#xA;        SpecularFactor = BRDF_Specular(NdotV, NdotL, NdotH, LdotH, Roughness, F0);&#xA;    }&#xA;    FinalColor = BaseColor * DiffuseFactor + SpecularColor * SpecularFactor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Final Image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/j7Ft6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j7Ft6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="83" LastActivityDate="2015-08-11T07:53:30.297" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="203" PostTypeId="1" CreationDate="2015-08-11T11:24:41.203" Score="34" ViewCount="1588" Body="&lt;p&gt;In graphics we use RGB and other color spaces as an approximation to the full spectrum of light wavelengths. This evidently works pretty well in general, but are there any reasonably common objects/materials/phenomena, things you might encounter in your everyday life, whose appearance isn't represented well by RGB rendering due to having a complex emission/reflection/absorption spectrum?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While the current answers are focusing mainly on colors outside a given RGB gamut, I'm also interested in hearing if there are examples where, for instance, the color of an object appears &quot;wrong&quot; when rendered in RGB because of an interaction between the light source spectrum and the object's reflection spectrum. In other words, a case where a spectral renderer would give you more correct results.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Credit: I liked this question in the previous private beta so I'm reproducing it here. It was originally asked by &lt;a href=&quot;https://computergraphics.stackexchange.com/users/48/nathan-reed&quot;&gt;Nathan Reed&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-30T20:19:56.160" Title="Are there common materials that aren't represented well by RGB?" Tags="&lt;color&gt;" AnswerCount="4" CommentCount="4" FavoriteCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="204" PostTypeId="2" ParentId="203" CreationDate="2015-08-11T13:05:13.567" Score="15" Body="&lt;p&gt;I believe the most prominent spectral effect that can't be faithfully reproduced with RGB is &lt;a href=&quot;https://en.wikipedia.org/wiki/Dispersion_(optics)&quot;&gt;dispersion&lt;/a&gt;, caused by dielectrics with spectrally varying index of refraction (usually modelled with the &lt;a href=&quot;https://en.wikipedia.org/wiki/Sellmeier_equation&quot;&gt;Sellmeier equation&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other spectral phenomena are usually caused by wave effects. One example that is encountered in real life every now and then is &lt;a href=&quot;https://en.wikipedia.org/wiki/Thin-film_interference&quot;&gt;thin-film interference&lt;/a&gt;, which is caused by one or more reflective surfaces layered closely on top of each other (e.g. oil slicks, soap bubbles). Another wave effect that can sometimes be observed is &lt;a href=&quot;https://en.wikipedia.org/wiki/Diffraction&quot;&gt;diffraction&lt;/a&gt;, caused e.g. by &lt;a href=&quot;https://en.wikipedia.org/wiki/Diffraction_grating&quot;&gt;diffraction gratings&lt;/a&gt;, which is what causes the funky appearance of CDs.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-11T13:05:13.567" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="206" PostTypeId="2" ParentId="201" CreationDate="2015-08-11T15:45:12.683" Score="3" Body="&lt;p&gt;You could try some form of color quantization algorithm, which generally extract the most dominant N colors. The one I've seen referenced most is &lt;a href=&quot;http://www.leptonica.com/papers/mediancut.pdf&quot; rel=&quot;nofollow&quot;&gt;modified median cut quantization&lt;/a&gt; [.pdf], which is based on &lt;a href=&quot;http://dcis.uohyd.ernet.in/~mravi/downloads/CIP/OLD-CIP/Median-cut.doc&quot; rel=&quot;nofollow&quot;&gt;median cut quantization&lt;/a&gt; [.doc]. The benefit to this kind of algorithm is that instead of simply averaging every color in the image, it extracts and discards other highly prominent colors instead of allowing them to pollute the average.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The concept is that color space (RGB space) is partitioned into 3D axis-aligned rectangular regions (the paper calls them vboxes) and iteratively subdivided by splitting vboxes, attempting to leave half of the pixels on each side of the split. The result is color clusters that should correspond to color clusters in the image. The largest color has a strong likelihood of being &quot;perceptually similar&quot; to the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a &lt;a href=&quot;http://lokeshdhakar.com/projects/color-thief/&quot; rel=&quot;nofollow&quot;&gt;JavaScript implementation and demo of this algorithm called Color Thief&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-11T15:45:12.683" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="207" PostTypeId="2" ParentId="203" CreationDate="2015-08-11T15:46:12.543" Score="7" Body="&lt;p&gt;RGB works because that's how our sensory apparatus works. Ina addition to dispersion, some man made materials and insect bodies sometimes have surfaces that have very tight color bands. These might benefit from a wide spectrum rendering. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However since many of these  effects are pretty localized, you can often get away with making the shader just work weird. This does not work right in reflections and refractions but nobody is likely to notice. Unless you are doing some physics simulation its not really a big deal. But if you design optics this might be a big deal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some materials, like snow, also convert incoming ultraviolet into visible light. Again this kind of effect can usually be handled by shaders/ special light groups.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Butterfly wings are also a curiosity as they manipulate the waves phases and the forms of the incoming light. So if you want to do physics simulation on those then its a big deal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Polarisation of light is also a big factor in insects and water effects.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-08-11T15:46:12.543" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="208" PostTypeId="2" ParentId="121" CreationDate="2015-08-11T16:46:35.160" Score="1" Body="&lt;p&gt;The creme de la creme of single-pass no (or few) compromises transparency in OpenGL is an A-buffer. With modern OpenGL, it is possible to implement:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.icare3d.org/2010/06/fast-and-accurate-single-pass-buffer.html&quot; rel=&quot;nofollow&quot;&gt;http://blog.icare3d.org/2010/06/fast-and-accurate-single-pass-buffer.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It avoids the multiple passes of depth peeling and doesn't require onerous sorting.&lt;/p&gt;&#xA;" OwnerUserId="363" LastActivityDate="2015-08-11T16:46:35.160" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="209" PostTypeId="1" AcceptedAnswerId="398" CreationDate="2015-08-11T21:54:24.663" Score="12" ViewCount="5942" Body="&lt;p&gt;Bresenham's line algorithm is a way of drawing straight lines using only fast integer operations (addition, subtraction, and multiplication by 2).  However, it generates aliased lines.  Is there a similarly fast way to draw antialiased lines?&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2021-02-17T08:50:19.343" Title="Fast antialiased line drawing" Tags="&lt;antialiasing&gt;&lt;pixel-graphics&gt;&lt;line-drawing&gt;" AnswerCount="2" CommentCount="9" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="210" PostTypeId="1" AcceptedAnswerId="211" CreationDate="2015-08-11T23:25:16.290" Score="7" ViewCount="1761" Body="&lt;p&gt;I'm trying to implement ambient occlusion in Python 3 and I'm seeing shadows beneath my reflective spheres but they seem very faint. I'm not sure if that means I've missed something, or if I just have a false impression of how much shadow results from ambient occlusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/etDFe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/etDFe.png&quot; alt=&quot;4 reflective spheres under a uniform white sky&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is modeled as spheres (rather than triangle meshes). The 4 yellowish mirror spheres are hovering just above a very large sphere to approximate a plane, and the whole scene is surrounded by a very large white emissive sphere that provides the ambient sky light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each pixel sample rays are chosen with a Gaussian distribution around the pixel centre and more samples are chosen until the variance is sufficiently low. Rays reflect in the single specular reflection direction from the mirror spheres, and in any direction from the hemisphere of possible directions when hitting the floor. All rays eventually hit the white sky sphere and the colour is determined based on the losses along the way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some vital step I'm overlooking?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-10-08T21:30:05.937" LastActivityDate="2015-10-09T01:44:16.853" Title="Am I missing something for ambient occlusion?" Tags="&lt;raytracing&gt;&lt;ambient-occlusion&gt;&lt;shadow&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="211" PostTypeId="2" ParentId="210" CreationDate="2015-08-11T23:41:33.870" Score="6" Body="&lt;p&gt;It's a bit hard to tell from your image, but it does look a bit faint. When debugging these kinds of things, it's always useful to strip down your scene as much as possible to remove any unnecessary complexity from the picture. In your case, try only creating a single diffuse sphere that touches the ground in one point. Give the ground and the sphere an albedo of 1. If ambient occlusion is implemented correctly, the point where the sphere touches the ground should have a pixel value of 0; the further away from the sphere you get, the closer the pixel values should go to 1 (not above - make sure nothing gets clamped when you output the image). Make sure to gamma correct your images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The one thing that sticks out from your description is &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Rays reflect [...] in any direction from the hemisphere of possible directions when hitting the floor&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That by itself is fine, but you need to make sure to multiply the rays by the Lambertian BRDF (i.e. dot(normal, ray)/Pi). Even better is to directly sample from a cosine hemisphere, in which case all factors cancel out. &lt;a href=&quot;http://www.rorydriscoll.com/2009/01/07/better-sampling/&quot;&gt;This blog post&lt;/a&gt; has all the important info in one place.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-08-11T23:41:33.870" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="212" PostTypeId="1" AcceptedAnswerId="220" CreationDate="2015-08-12T00:31:52.567" Score="6" ViewCount="1264" Body="&lt;p&gt;When computing ray-object intersections against a transformed object, most raytracers apply the inverse transform to each ray and compute the intersection against a non-transformed object.  Wouldn't applying the forward transform, putting the object into a flat world-space, be faster and more efficient, because you only need to compute the transform once?&lt;/p&gt;&#xA;" OwnerUserId="158" LastEditorUserId="6" LastEditDate="2015-08-12T09:31:56.920" LastActivityDate="2015-08-12T14:27:25.487" Title="Why are inverse transformations applied to rays rather than forward transformations to objects?" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="213" PostTypeId="2" ParentId="212" CreationDate="2015-08-12T00:44:23.180" Score="4" Body="&lt;p&gt;Most ray intersection algorithms can be greatly simplified if you can assume the shape you're intersecting is at the origin, unrotated and with unit size. There are a few exceptions (Like spheres, which have rotational symmetry.) but the more general versions of the algorithms mathematically usually end up basically translating both the shape and ray to the origin before calculating the intersection. With that in mind it's simpler and more consistent to simply transform rays so that the intersection always happens in object-space.&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-08-12T00:54:41.007" LastActivityDate="2015-08-12T00:54:41.007" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="214" PostTypeId="1" CreationDate="2015-08-12T00:46:42.240" Score="6" ViewCount="557" Body="&lt;p&gt;&lt;em&gt;I'm trying to learn about raytracing by implementing things in Python 3. I know this is always going to be slower than something like C++, and I know the speed could also be improved by using GPU raytracing, but for this question I'm not looking for general ways of speeding up, but specifically ways of reducing the number of samples required, which will then be useful for any language I may work with in future.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I have a partly formed idea which I'd like to work on, but first I wanted to run this past the experts to see if this is a pre-existing technique so I don't repeat work that has already been done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've searched for &quot;sampling solid angle&quot; and &quot;voronoi sphere sampling&quot; but I can't see any sign of prior work. I'll describe my idea in case it goes by a name I can't think of.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Example image&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FzJUi.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FzJUi.jpg&quot; alt=&quot;3 spheres on a plane&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is an image of three spheres on a plane (which is actually a very large sphere). One is emissive, one is reflective, and one is matt (as is the floor). Sampling is adaptive so that pixels that quickly reach a stable colour do not take up much time. I limit the total number of samples per pixel to avoid the rendering continuing for too long. Even allowed to run overnight, the resulting image is very grainy, and experimenting with smaller images suggests this size image (1366 by 768) would take weeks to converge with my current approach.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;My idea: concentrating samples along colour boundaries&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;I'd like to be able to concentrate samples where they are needed, and to do this adaptively based on previous samples for the same intersection point or pixel. This will give an unknown bias in the distribution of samples, which means taking the average of the samples will give an inaccurate result. Instead I would like to consider the size of the voronoi cell on the surface of the unit hemisphere centred on the point of intersection (for sampling light incident at a point on a matt surface) or on the surface of a small circle (for sampling around a pixel).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume that all points within that voronoi cell are receiving rays of the same colour as the centre of the voronoi cell. Now an estimate of the average colour can be obtained by weighting according to the area of each voronoi cell. Choosing new samples on the boundary between the two voronoi cells with the greatest difference in colour leads to an improvement in the estimate without needing to sample the entire hemisphere. Samples should end up more densely concentrated in areas of higher colour gradient. Areas of flat colour should end up being ignored once they have a few points near their boundary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The extra complication is that in both cases (sampling from a point on a matt surface, or sampling over a circle around a pixel centre) the simplified approach I have described is roughly equivalent to a large number of samples distributed uniformly. To make this work I would need to be able to bias the average by both the voronoi cell areas &lt;em&gt;and&lt;/em&gt; the required distribution (cosine around the surface normal for a matt surface or gaussian around a pixel centre).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I have some more thinking to do before I could test this idea, but I wanted to check first if this has either already been done, or already ruled out as unworkable.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-09-02T01:54:45.520" Title="Speeding up convergence: am I reinventing the wheel?" Tags="&lt;raytracing&gt;&lt;sampling&gt;&lt;efficiency&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="215" PostTypeId="1" CreationDate="2015-08-12T01:30:57.970" Score="4" ViewCount="997" Body="&lt;p&gt;(Note: This has been cross posted from my &lt;a href=&quot;http://ompf2.com/viewtopic.php?f=15&amp;amp;t=1977&quot; rel=&quot;nofollow noreferrer&quot;&gt;ompf2 post&lt;/a&gt;.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recently I've implemented Multiple Importance Sampling for the sampling of surfaces in my ray tracer. I do this by, on each intersection, sampling both a random direction from the BRDF and also sampling a random light, then combining both using the power heuristic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I have only a single light, the results are beautiful. Whereas previously I had this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/rdpdig3.png&quot; alt=&quot;BRDF sampling only&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have this, with the same amount (1024 per pixel) of samples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/kgCgBrA.png&quot; alt=&quot;BRDF+Light sampling&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the algorithm seems to work well. The problem is when I add a second light source to the scene, the noise comes back! This is a render with a second light source added:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zVdm7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zVdm7.png&quot; alt=&quot;BRDF+Light with 2 lights&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am probably using the technique incorrectly. Perhaps I need to sample all light sources at once, instead of randomly picking one like I'm doing now? That doesn't seem like it would scale well as the number of lights go up, however. The implementation was loosely based on pbrt's DirectLightingIntegrator, and I suspect the reason why it doesn't work properly is that I also have multi-bounce indirect lighting. This is my core integration function:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;vec3 calc_light_incidence(const Scene&amp;amp; scene, Rng&amp;amp; rng, const Ray&amp;amp; ray, int depth) {&#xA;    float ray_weight = 1.0f;&#xA;&#xA;    depth += 1;&#xA;    if (depth &amp;gt; 2) {&#xA;        const float live_probability = 0.75f;&#xA;&#xA;        if (rng.canonical() &amp;gt; live_probability) {&#xA;            return vec3_0;&#xA;        } else {&#xA;            ray_weight = 1.0f / live_probability;&#xA;        }&#xA;    }&#xA;&#xA;    vec3 color = vec3_0;&#xA;&#xA;    const Optional&amp;lt;Intersection&amp;gt; surface_hit = find_nearest_intersection(scene, ray);&#xA;    if (surface_hit) {&#xA;        const vec3 out_dir = -normalized(ray.direction);&#xA;&#xA;        const size_t light_index = (size_t)(rng.canonical() * scene.lights.size());&#xA;        const SceneObject* light = &amp;amp;scene.objects[scene.lights[light_index]];&#xA;        const float light_weight = (float)scene.lights.size();&#xA;&#xA;        // Sample BRDF&#xA;        {&#xA;            const vec3 in_dir = cosine_weighted_point_on_hemisphere(rng.canonical(), rng.canonical(), surface_hit-&amp;gt;normal);&#xA;            const vec3 reflectance = surface_hit-&amp;gt;object-&amp;gt;material.diffuse_brdf(*surface_hit, in_dir, out_dir);&#xA;            const float cos_term = dot(in_dir, surface_hit-&amp;gt;normal);&#xA;&#xA;            const float brdf_pdf = cos_term / pi;&#xA;&#xA;            const Optional&amp;lt;Intersection&amp;gt; light_hit = light-&amp;gt;shape-&amp;gt;intersect(ray_from_surface(*surface_hit, in_dir));&#xA;            const float light_pdf = (light_hit ? light-&amp;gt;shape-&amp;gt;areaPdf(surface_hit-&amp;gt;position, in_dir) : 0.f);&#xA;&#xA;            if (brdf_pdf != 0.f &amp;amp;&amp;amp; reflectance != vec3_0) {&#xA;                const vec3 illuminance = calc_light_incidence(scene, rng, ray_from_surface(*surface_hit, in_dir), depth);&#xA;                color += (1.0f / brdf_pdf) * cos_term * reflectance * illuminance * power_heuristic(brdf_pdf, light_pdf);&#xA;            }&#xA;        }&#xA;&#xA;        // Sample lights&#xA;        {&#xA;            const ShapeSample light_sample = light-&amp;gt;shape-&amp;gt;sampleArea(rng, surface_hit-&amp;gt;position);&#xA;            const vec3 light_vec = light_sample.point - surface_hit-&amp;gt;position;&#xA;            const vec3 in_dir = normalized(light_vec);&#xA;            const float cos_term = vmax(0.f, dot(in_dir, surface_hit-&amp;gt;normal));&#xA;&#xA;            const Optional&amp;lt;Intersection&amp;gt; light_hit = find_nearest_intersection(scene, ray_from_surface(*surface_hit, light_vec));&#xA;            bool occluded = !light_hit || light_hit-&amp;gt;object != light;&#xA;            const float light_pdf = light_weight * light_sample.pdf;&#xA;&#xA;            const float brdf_pdf = cos_term / pi;&#xA;&#xA;            const vec3 reflectance = surface_hit-&amp;gt;object-&amp;gt;material.diffuse_brdf(*surface_hit, in_dir, out_dir);&#xA;            if (!occluded &amp;amp;&amp;amp; light_pdf != 0.f &amp;amp;&amp;amp; reflectance != vec3_0) {&#xA;                const vec3 illuminance = calc_light_incidence(scene, rng, ray_from_surface(*surface_hit, in_dir), depth);&#xA;                const float differential_area = -dot(light_hit-&amp;gt;normal, in_dir) / length_sqr(light_vec);&#xA;                color += light_weight * (1.0f / light_pdf) * differential_area * cos_term * reflectance * illuminance * power_heuristic(light_pdf, brdf_pdf);&#xA;            }&#xA;        }&#xA;&#xA;        if (dot(out_dir, surface_hit-&amp;gt;normal) &amp;gt;= 0.f) {&#xA;            color += surface_hit-&amp;gt;object-&amp;gt;material.emmision-&amp;gt;getValue(*surface_hit);&#xA;        }&#xA;    } else {&#xA;        //color = lerp(mvec3(1.0f, 0.2f, 0.0f), mvec3(0.35f, 0.9f, 1.0f), 1.0f - std::pow(1.0f - vmax(0.0f, dot(ray.direction, vec3_y)), 2)) * 0.5f;&#xA;        color = lerp(mvec3(0.02f, 0.06f, 0.36f), mvec3(0.0f, 0.0f, 0.0f), 1.0f - std::pow(1.0f - vmax(0.0f, dot(ray.direction, vec3_y)), 2)) * 0.5f;&#xA;    }&#xA;&#xA;    return color * ray_weight;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-08-12T17:10:01.963" LastActivityDate="2015-08-12T17:10:01.963" Title="Multiple Importance Sampling with more than one light" Tags="&lt;raytracing&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="216" PostTypeId="2" ParentId="203" CreationDate="2015-08-12T07:12:46.860" Score="3" Body="&lt;p&gt;Just to add to the excellent suggestions above, it occurred to me that, without an ultraviolet channel, fluorescent materials would be tricky to model.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2015-08-12T07:12:46.860" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="217" PostTypeId="2" ParentId="215" CreationDate="2015-08-12T08:17:24.157" Score="3" Body="&lt;p&gt;It seems that the answer to my question is that my approach inherently can't work. After doing thinking about it some more and researching existing renderers, none seem to implement what I'm doing, and I think the noise comes from contributions from lights other than the one randomly picked will not be estimated with the PDF. To do it correctly I would need to loop through all the lights, which gives me essentially path tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Note however, that at Mitsuba and PBRT implement a Direct Illumination integrator which uses the approach I do, but only works when excluding indirect illumination, which is also true of my approach.)&lt;/p&gt;&#xA;" OwnerUserId="327" LastActivityDate="2015-08-12T08:17:24.157" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="218" PostTypeId="1" AcceptedAnswerId="224" CreationDate="2015-08-12T08:55:30.060" Score="7" ViewCount="137" Body="&lt;p&gt;How can I overlay graphics on particle simulations? For instance if I am representing a liquid or gas with tons of little points how can I make those points look like a liquid or gas? Take Nvidia Flex for instance, they simulate liquids and gases with tons of small points but can render them as realistic liquids and gases instead of small balls.&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="6" LastEditDate="2015-08-12T09:32:44.950" LastActivityDate="2015-08-12T17:01:00.427" Title="Overlaying graphics on particle simulation" Tags="&lt;simulation&gt;&lt;physics&gt;&lt;particles&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="219" PostTypeId="2" ParentId="218" CreationDate="2015-08-12T10:17:33.037" Score="-1" Body="&lt;p&gt;A good reference for game physics is &lt;a href=&quot;https://books.google.it/books?id=ynQZBwAAQBAJ&amp;amp;printsec=frontcover&amp;amp;dq=game+physics+eberly&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0CCAQ6AEwAGoVChMIkKr24aSjxwIVwS4aCh3nrg55#v=onepage&amp;amp;q=game%20physics%20eberly&amp;amp;f=false&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; chapter 4 describes the basic free deformable surfaces (nurbs and bspline are of course cited and treated enough well) fluid and gases are instead treated in chapter five (basically the author derivate simplified model of navier stokes equations, suitable for real time applications).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So actually i guess what i've written commenting your post was correct, i.e. combine the physical deformation of the point that controls the shape of the surface with a ffd computations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The book i cited should provide somewhere/somehow on the web source code, and itself it cites some example involving the technique i cited. If that is what you need let me know for a more specific explanation.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2015-08-12T10:17:33.037" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="220" PostTypeId="2" ParentId="212" CreationDate="2015-08-12T14:27:25.487" Score="6" Body="&lt;p&gt;Most raytracers do both!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have you ever seen a ray-triangle intersection test where the triangle is transformed so that one vertex is at the origin and the triangle is flat along one of the axes? That would simplify the test, but storing the inverse transformation to apply it to the ray takes more space than the triangle itself. So you could say that almost all ray-triangle tests &lt;em&gt;do&lt;/em&gt; apply the forward transformation to the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And yet most of the time you are rendering a mesh of many triangles, and &quot;most raytracers&quot; don't transform every vertex in the mesh by the object's transform matrix, they inverse transform the ray into object space. There isn't necessarily a good reason for this—it can definitely be more performant in some cases to preprocess the mesh and put every vertex in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But then say you're doing animation studio-scale path tracing. Now your scene geometry might not all fit in RAM at once. It's no longer a performance win to pre-transform all your vertices/control points, because (a) you need one copy of the object per instance, and (b) you need to transform it each time you read it into RAM. When data bound, the cost of two matrix multiplies per ray is insignificant anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Floating point precision is a potential reason as well: when you have an object a long way from the origin, you get more error from floating point positions, and if you pre-transform the object you apply that error in different directions to each vertex, whereas if you inverse transform the ray you have one fixed error amount from the imprecise position of the ray, but your vertices have less error relative to each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although I suspect the real answer to &quot;why do most raytracers inverse transform the ray&quot; is that most raytracers with public source code implement a wide range of geometric primitives, either for educational purposes or as a proof-of-concept, and it's easier to implement one cheap ray inverse transform than N shape forward transforms. (Plus, as has been mentioned, some intersection algorithms are much simpler if the object is in its canonical space.)&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-12T14:27:25.487" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="221" PostTypeId="1" AcceptedAnswerId="223" CreationDate="2015-08-12T16:16:49.647" Score="14" ViewCount="747" Body="&lt;p&gt;I know in the not so long ago (5-10 years?) that it was popular / efficient to bake data out into textures and then read the data from the textures, often using the built in texture interpolation to get linear interpolation of the baked out data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that computing time is cheaper compared to texture lookup time, this practice has definitely lessened if not all together disappeared.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, are baked out textures still used for anything?  Does anyone have any usage cases for them in modern architecture?  Does it seem likely they will ever make a come back? (say, if memory technology or basic GPU architecture changes)&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-12T16:42:14.817" Title="Are lookup textures still used for anything?" Tags="&lt;texture&gt;&lt;gpu&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="222" PostTypeId="1" AcceptedAnswerId="231" CreationDate="2015-08-12T16:19:26.997" Score="6" ViewCount="641" Body="&lt;p&gt;I've seen mention of tiled raytracing, but haven't been able to find much on google about it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain what it is and how it works?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-13T19:05:22.927" Title="What is &quot;tiled&quot; raytracing?" Tags="&lt;raytracing&gt;&lt;tile-based-rendering&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="223" PostTypeId="2" ParentId="221" CreationDate="2015-08-12T16:42:14.817" Score="17" Body="&lt;p&gt;Yes, lookup textures are still used. For example, pre-integrated BRDFs (for ambient lighting, say), or arbitrarily complicated curves baked down to a 1D texture, or a 3D lookup texture for color grading, or a noise texture instead of a PRNG in the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ALU is generally cheaper than a texture sample, true, but you still have a limited amount of ALU per frame. GPUs are good at latency hiding and small lookup textures are likely to be in the cache. If your function is complicated enough, it may still be worth using a lookup texture.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-12T16:42:14.817" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="224" PostTypeId="2" ParentId="218" CreationDate="2015-08-12T16:55:26.340" Score="4" Body="&lt;p&gt;For rendering of gases, I think the usual approach is to simply render each particle as a tiny disc. Gases don't really coalesce into surfaces like liquids do, so this should produce acceptable results. You could perhaps apply a light blur over the gas layer afterwards to soften it and hide the fact that it is made of discrete elements.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Liquids, on the other hand, tend to coalesce together to form droplets and smooth surfaces, so you need to derive a surface from the particles somehow. One way to do this is to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Metaballs&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metaballs&lt;/a&gt;, which also display this behavior and can be tweaked to suit different liquids and particle densities. By interpreting each particle as a metaball, you will have an implicit equation representing your liquid surface. To render this implicit surface you can then use an algorithm like &lt;a href=&quot;https://en.wikipedia.org/wiki/Marching_tetrahedra&quot; rel=&quot;nofollow noreferrer&quot;&gt;Marching Tetrahedra&lt;/a&gt; to convert it to triangles, or utilize &lt;a href=&quot;https://gamedev.stackexchange.com/a/67745/5337&quot;&gt;Ray Marching&lt;/a&gt; to directly render it. (Ray marching can be easily done in realtime in a fragment shader these days.) You can also use this approach for gases if you want a somewhat softer look.&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2015-08-12T17:01:00.427" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="225" PostTypeId="1" CreationDate="2015-08-12T19:34:12.640" Score="5" ViewCount="158" Body="&lt;p&gt;There are a number of terms for rendering techniques based on the particle model of light: forward ray-tracing, reverse ray-tracing, ray-casting, ray-marching, and possibly others.  What's the difference between them?&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-13T00:20:04.227" Title="Ray-based rendering terms" Tags="&lt;raytracing&gt;&lt;raymarching&gt;&lt;terminology&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2015-08-26T10:41:38.667" ContentLicense="CC BY-SA 3.0" />
  <row Id="226" PostTypeId="2" ParentId="225" CreationDate="2015-08-13T00:20:04.227" Score="4" Body="&lt;p&gt;Forward ray-tracing means that rays starts from the light source and are traced towards the eye (light-surface-eye), this is a highly inefficient but accurate method. Reverse raytracing is simply starting in the eye and then trace them towards the light source. These are two classes of ray tracers.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Ray casting is the use of ray-surface intersection tests to solve a variety of problems in computer graphics and computational geometry. The distinction is that ray casting is a rendering algorithm that never recursively traces secondary rays, whereas other ray tracing-based rendering algorithms may do so. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Ray-marching is an implementation of a ray tracer, often used to visualize volumes. Normally ray casting uses a formulae to determine the point of intersection with the surface. In ray marching such a function is not required, instead the intersection is evaluated at several points along the ray. Either these points have a fixed distance between them or every iteration the distance to the next point is based on the distance to the closest surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference between those are that ray-tracing is a concept to solve the rendering equation, in the end resulting in a certain color for each pixel. Forward and reverse ray-tracing are classes of ray-tracers, ray-casting is a simple algorithm to do ray-tracing and ray-marching is another algorithm to do ray-tracing. As by the comment many other algorithms have been developed to solve the problem with different advantages and disadvantages.&lt;/p&gt;&#xA;" OwnerUserId="64" LastActivityDate="2015-08-13T00:20:04.227" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="227" PostTypeId="1" AcceptedAnswerId="236" CreationDate="2015-08-13T01:10:15.263" Score="11" ViewCount="5275" Body="&lt;p&gt;How are volumetric effects such as smoke, fog, or clouds rendered by a raytracer?  Unlike solid objects, these don't have a well-defined surface to compute an intersection with.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-11-03T13:56:14.140" Title="How are volumetric effects handled in raytracing?" Tags="&lt;raytracing&gt;&lt;volumetric&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="228" PostTypeId="2" ParentId="227" CreationDate="2015-08-13T02:04:11.007" Score="4" Body="&lt;p&gt;One way to do it - which isn't exactly the &quot;go to&quot; solution, but can work nicely, is to find the distance that the ray traveled through the volume and use integration of some density function to calculate how much &quot;stuff&quot; was hit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a link with an example implementation:&#xA;&lt;a href=&quot;http://blog.demofox.org/2014/06/22/analytic-fog-density/&quot; rel=&quot;nofollow&quot;&gt;http://blog.demofox.org/2014/06/22/analytic-fog-density/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-08-13T03:31:06.013" LastActivityDate="2015-08-13T03:31:06.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="229" PostTypeId="2" ParentId="222" CreationDate="2015-08-13T02:32:23.337" Score="5" Body="&lt;p&gt;I believe it's where you batch it and do a block of pixels at once, or a &quot;tile&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means calculating the final color for multiple pixels at a time. Imagine breaking up your window of pixels into squares containing the pixels, usually around 2x2 pixels per square. Then simply work through them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This causes speed boosts for lots of different reasons, depending on your implementation and hardware. If you can, check out Ingo Wald's PhD thesis about real time raytracing, he makes a lot of references to batching to get speed using things like AVX (advanced vectoring extensions) in the processor. These provide speed boosts when you calculate the color for a certain amount of similar pixels. It's all cool and definitely worth looking into, and you can read more here: &lt;a href=&quot;https://en.wikipedia.org/wiki/Advanced_Vector_Extensions&quot; rel=&quot;nofollow&quot;&gt;https://en.wikipedia.org/wiki/Advanced_Vector_Extensions&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically you represent similar data for similar pixels using a vector of floats and do the same calculations to all at once, saving cycles. Picture Bart Simpson writing out the same words on the chalkboard all at once instead of line-by-line in the Simpsons opening :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also when doing real time raytracing, you may be using the graphics card and sending all the data over the bus is a large bottleneck. You don't want to send all the data over to the card to calculate the value of only one pixel because of the bus overhead - so you want to send a reasonable amount of data to chew on while you work on getting the next chunk ready. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, to me at least, &quot;tiled&quot; raytracing is just &quot;batched&quot; raytracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps.&lt;/p&gt;&#xA;" OwnerUserId="377" LastEditorUserId="377" LastEditDate="2015-08-13T19:05:22.927" LastActivityDate="2015-08-13T19:05:22.927" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="230" PostTypeId="1" AcceptedAnswerId="238" CreationDate="2015-08-13T03:32:42.397" Score="7" ViewCount="142" Body="&lt;p&gt;I know how to program directional lights, point lights and spot lights.  Sometimes though, people have lights that are shaped - like bars, or even a torus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does that work from either a ray based or rasterization perspective?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-13T20:48:19.837" Title="How do shaped lights work?" Tags="&lt;lighting&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="231" PostTypeId="2" ParentId="222" CreationDate="2015-08-13T03:36:58.337" Score="7" Body="&lt;p&gt;Tiled raytracing is a way of speeding up rendering.  Instead of rendering pixels on a row-by-row basis down the entire image, you render them in 2D groups (say, 32x32 tiles).  Since adjacent rays tend to intersect the same objects, this improves the cache hit rate at the CPU level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At a smaller scale, tiling at the 2x2 level lets you use SSE/AVX/etc to compute four rays with a single CPU instruction, further speeding things up.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-13T03:36:58.337" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="232" PostTypeId="2" ParentId="230" CreationDate="2015-08-13T04:33:04.053" Score="10" Body="&lt;p&gt;In a path tracer, when tracing a ray to a light with a shape other than a point (&quot;area light&quot; is the usual terminology), you generally select a random point on the surface of the light. When enough samples are taken, this results in both softer specular highlights and softer shadow penumbras: light will be reflected off a surface from a random distribution of incoming directions, and rays cast towards an area light with an obstruction in the way may or may not intersect the obstruction depending on which point on the light was sampled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In real time, approximations to area lights are used. This &lt;a href=&quot;http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&quot;&gt;Unreal Engine 4 white paper&lt;/a&gt; describes some of the considerations. One possibility is the &quot;representative point&quot; method, which per-pixel selects a point in the light's volume (brightest or nearest) and uses that as though it was a point light. Another option is modifying the roughness that is fed into the specular calculation based on a cone that approximates the area light (in the paper as &quot;Specular D Modification&quot;).&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-13T04:33:04.053" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="233" PostTypeId="1" AcceptedAnswerId="244" CreationDate="2015-08-13T05:24:10.437" Score="21" ViewCount="8943" Body="&lt;p&gt;Looking at a light probe texture, it looks like a blurry environment map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the difference between the two, how is a light probe made, and what is the benefit of it being blurry?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2021-03-10T20:23:23.297" Title="How is a light probe different than an environmental cube map?" Tags="&lt;lighting&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="234" PostTypeId="2" ParentId="227" CreationDate="2015-08-13T05:50:52.547" Score="3" Body="&lt;p&gt;Depends on the volume efffect. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniform volume effects that do not belong do scattering can be simulated by just calculating ray enter and ray exit distances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Otherwise you need to do integration of the ray path, also known as ray marching. To avoid needing to shoot secondary rays the raymarching is often coupled with some sort of cache, like depthmap, deepmaps, brick maps or voxel clouds for light shadowing, etc. This way you dont necceserily need to march the whole scene. Similar caching is often done to the volume procedural texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also possible to convert the texture to surface primitives like boxes, spheres or planes that have some suitable soft edged texture. You can then use normal rendering techniques to solve the volumetric effect. The problem with this is that you usually need lots of primitives. Additionally the shape of the primitive may show up as too uniform sampling.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-13T06:04:53.237" LastActivityDate="2015-08-13T06:04:53.237" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="235" PostTypeId="1" AcceptedAnswerId="237" CreationDate="2015-08-13T07:33:20.873" Score="7" ViewCount="289" Body="&lt;p&gt;Say I've got a photograph of a scene, and measurements for part of it (eg. a room where I know the dimensions of the walls).  Assuming a rectilinear lens, how would I go about setting up a virtual camera so that 3D objects are rendered as if they were in the physical scene?&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-13T12:25:00.457" Title="Matching a virtual camera to a physical camera" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="236" PostTypeId="2" ParentId="227" CreationDate="2015-08-13T11:51:27.977" Score="12" Body="&lt;h2&gt;Overview&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The appearance of volumes (also called participating media) in nature is caused by tiny particles, such as dust, water droplets or plankton, that are suspended in the surrounding fluid, such as air or water. These particles are solid objects, and light refracts or reflects off of these objects as it would on a normal surface. In theory, participating media could therefore be handled by a traditional ray tracer with only surface intersections.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Statistical Model&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Of course, the &lt;em&gt;sheer number&lt;/em&gt; of these particles makes it infeasible to actually raytrace them individually. Instead, they are approximated with a statistical model: Because the particles are very small, and the distance between the particles is much larger than the particle size, individual interactions of light with the particles can be modeled as statistically independent. Therefore, it is a reasonable approximation to replace the individual particles with continuous quantities that describe the &quot;average&quot; light-particle interaction at that certain region in space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For physically based volumetric light transport, we replace the inconceivably many particles with a continuous participating medium that has two properties: The absorption coefficient, and the scattering coefficient. These coefficients are very convenient for ray tracing, as they allow us to compute the probability of a ray interacting with the medium - that is, the probability of striking one of the particles - as a function of distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The absorption coefficient is denoted $\sigma_a$. Say a ray of light wants to travel $t$ meters inside the participating medium; the probability of making it through unabsorbed -- i.e. not hitting one of the particles and being absorbed by it -- is $e^{-t\cdot\sigma_a}$`. As t increases, we can see that this probability goes to zero, that is, the longer we travel through the medium, the more likely it is to hit something and be absorbed. Very similar things hold for the scattering coefficient $\sigma_s$: The probability of the ray not hitting a particle and being scattered is $e^{-t\cdot\sigma_s}$; that is, the longer we travel through a medium, the more likely it is that we hit a particle and are scattered into a different direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually, these two quantities are folded into a single extinction coefficient, $\sigma_t = \sigma_a + \sigma_s$. The probability of traveling $t$ meters through a medium without interacting with it (neither being absorbed or scattered) is then $e^{-t\cdot\sigma_t}$. On the other hand, the probability of interacting with a medium after $t$ meters is $1 - e^{-t\cdot\sigma_t}$.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Rendering with Participating Media&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The way this is used in physically based renderers is as follows: When a ray enters a medium, we probabilistically stop it inside the medium and have it interact with a particle. Importance sampling the interaction probability$1 - e^{-t\cdot\sigma_t}$ yields a distance $t$; this tells us that the ray traveled $t$ meters in the medium before striking a particle, and now one of two things happens: Either the ray gets absorbed by the particle (with probability $\frac{\sigma_a}{\sigma_t}$), or it gets scattered (with probability $\frac{\sigma_s}{\sigma_t}$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How the ray is scattered is described by the &lt;em&gt;phase function&lt;/em&gt; and depends on the nature of the particles; the Rayleigh phase function describes scattering from spherical particles smaller than the wavelength of light (e.g. our atmosphere); the Mie phase function describes scattering from spherical particles of similar size than the wavelength (e.g. water droplets); in graphics, usually the &lt;a href=&quot;http://www.astro.umd.edu/~jph/HG_note.pdf&quot; rel=&quot;noreferrer&quot;&gt;Henyey-Greenstein&lt;/a&gt; phase function is used, originally applied to scattering from interstellar dust.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, in graphics, we don't normally render pictures of an infinite medium, but render media inside a scene consisting of hard surfaces as well. In that case, we first fully trace the ray until it hits the next surface, completely ignoring the participating medium; this gives us the distance to the next surface, $t_{Max}$. We then sample an interaction distance $t$ in the medium as described before. If $t \lt t_{Max}$, the ray hit a particle on the way to the next surface and we either absorb it or scatter it. If $t \geq t_{Max}$, the ray made it through unscathed and interacts with the surface as usual.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Outlook&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;This post was only a small introduction to rendering with participating media; among other things, I completely ignored spatially varying coefficients (which you need for clouds, smoke, etc.). &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf&quot; rel=&quot;noreferrer&quot;&gt;Steve Marschner's notes&lt;/a&gt; are a good resource, if you're interested. In general, participating media are very difficult to render efficiently, and you can go a lot more sophisticated than what I described here; there's &lt;a href=&quot;http://www.cs.dartmouth.edu/~wjarosz/publications/jarosz08beam.pdf&quot; rel=&quot;noreferrer&quot;&gt;Volumetric Photon Mapping&lt;/a&gt;, &lt;a href=&quot;http://www.cs.dartmouth.edu/~wjarosz/publications/jarosz11progressive.pdf&quot; rel=&quot;noreferrer&quot;&gt;Photon Beams&lt;/a&gt;, &lt;a href=&quot;https://graphics.stanford.edu/papers/bssrdf/bssrdf.pdf&quot; rel=&quot;noreferrer&quot;&gt;Diffusion approximations&lt;/a&gt;, &lt;a href=&quot;http://www.cs.dartmouth.edu/~wjarosz/publications/georgiev13joint.pdf&quot; rel=&quot;noreferrer&quot;&gt;Joint Importance Sampling&lt;/a&gt; and more. There's also interesting work on &lt;a href=&quot;http://www.cs.dartmouth.edu/~wjarosz/publications/meng15granular.pdf&quot; rel=&quot;noreferrer&quot;&gt;granular media&lt;/a&gt; that describes what to do when the statistical model breaks down, i.e. particle interactions are no longer statistically independent.&lt;/p&gt;&#xA;" OwnerUserId="79" LastEditorUserId="137" LastEditDate="2015-11-03T13:56:14.140" LastActivityDate="2015-11-03T13:56:14.140" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="237" PostTypeId="2" ParentId="235" CreationDate="2015-08-13T12:25:00.457" Score="5" Body="&lt;p&gt;This is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Camera_resectioning&quot; rel=&quot;nofollow noreferrer&quot;&gt;Camera re-sectioning problem&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;We need to have a few points, like the end points of the walls, to take the roles of x&lt;sub&gt;w&lt;/sub&gt;, y&lt;sub&gt;w&lt;/sub&gt; and z&lt;sub&gt;w&lt;/sub&gt; in the following equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qXr4W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qXr4W.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here A is defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xs4BR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xs4BR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These are the values of the camera itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;R and T are defined as the Rotation and Translation matrices for the camera, and are the values we need to solve for. The position, C, of the camera expressed in world coordinates is C = -R&lt;sup&gt;-1&lt;/sup&gt;T = -R&lt;sup&gt;T&lt;/sup&gt; T .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The linked Wikipedia article mentions a few algorithms to solve these equations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example of a practical application of these is also found on &lt;a href=&quot;https://math.stackexchange.com/questions/82602/how-to-find-camera-position-and-rotation-from-a-4x4-matrix&quot;&gt;Math Stack Exchange&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another example, with some code samples that you may want to use, is found &lt;a href=&quot;https://stackoverflow.com/questions/76134/how-do-i-reverse-project-2d-points-into-3d&quot;&gt;Stack Overflow&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="21" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2015-08-13T12:25:00.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="238" PostTypeId="2" ParentId="230" CreationDate="2015-08-13T12:38:56.643" Score="2" Body="&lt;p&gt;In my torus light implementation(Unity3D) I use the same real-time method &lt;a href=&quot;https://computergraphics.stackexchange.com/a/232/376&quot;&gt;described in @JohnCalsbeek's answer&lt;/a&gt;. Just treat it the same way you treat your regular point/spot light and calculate a single direction and distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use the torus distance equation from &lt;a href=&quot;http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Inigo Quilez's site&lt;/a&gt; and&#xA;here's the function I made to get the direction to a torus&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;float3 torusDirection(float3 p) {&#xA;float3 torusRel;&#xA;torusRel.xz = normalize(p.xz-_TorusLocation.xz);&#xA;torusRel.y = 0;&#xA;&#xA;return -normalize(p-(TorusLocation+torusRel*TorusCenterRadius));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Overall I think it works well minus a few areas that look off where the torus loops around &lt;a href=&quot;https://i.stack.imgur.com/gBzMT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gBzMT.png&quot; alt=&quot;Example scene lit by a torus&quot;&gt;&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The specular hint is also off but @JohnCalsbeek's point of modifying the roughness seems like it should fix that :). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The hardest challenge for me with the light right now is making a forward shader that supports different kinds of area lights and multiple lights. I don't know how I would do this besides just having a whole bunch of shader properties for all the different lights though. Currently I apply the light as a deferred pass so it only works with opaque objects but soon I'll need to make a forward version for transparent objects. That's the real challenge I think, getting multiple area lights in a forward shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here's a &lt;a href=&quot;https://www.shadertoy.com/view/MllSWS&quot; rel=&quot;nofollow noreferrer&quot;&gt;Shadertoy demo&lt;/a&gt; of a torus light I made to test mine, its based off of BeyondTheStatics shape light demo.&lt;/p&gt;&#xA;" OwnerUserId="376" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-13T20:48:19.837" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="239" PostTypeId="1" CreationDate="2015-08-13T18:55:38.310" Score="8" ViewCount="2268" Body="&lt;p&gt;Given an arbitrary triangle mesh, is it possible to automatically generate a UV mapping for it, and if so, how is it done?&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-13T21:25:01.247" Title="Automatic generation of UV maps" Tags="&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="240" PostTypeId="2" ParentId="239" CreationDate="2015-08-13T19:10:59.400" Score="7" Body="&lt;p&gt;Short answer: Yes, but it won't be pretty.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Explaination: While there &lt;em&gt;are&lt;/em&gt; &lt;a href=&quot;http://knowledge.autodesk.com/support/maya-lt/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/MayaLT/files/Create-UVs--Automatic-Mapping-htm.html&quot; rel=&quot;nofollow&quot;&gt;algorithms&lt;/a&gt; to automagically UV map polygon soup, the mapping probably wont be ideal. UV mapping is an art really. Choosing where to hide the seams and where to put them to limit stretching and optimize texture space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, there &lt;em&gt;are&lt;/em&gt; lots of tools that can make manual UV mapping a heck of a lot easier. For example: &lt;a href=&quot;http://knowledge.autodesk.com/support/maya-lt/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/MayaLT/files/Create-UVs--Automatic-Mapping-htm.html&quot; rel=&quot;nofollow&quot;&gt;http://knowledge.autodesk.com/support/maya-lt/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/MayaLT/files/Create-UVs--Automatic-Mapping-htm.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2015-08-13T21:25:01.247" LastActivityDate="2015-08-13T21:25:01.247" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="241" PostTypeId="1" AcceptedAnswerId="1483" CreationDate="2015-08-13T19:20:21.843" Score="7" ViewCount="272" Body="&lt;p&gt;In chromaticity charts the CMYK color space is usually four-sided. I've lately had to read quite a few charts and it suddenly dawned to me that I don't really understand why. It has just not been something I've needed to think about until now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/pfP8P.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: A sample CIE31 chromaticity graph showing the spaces*.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of my working hypotheses is that it is actually a triangle. This triangle just clips for some reason. But there might be other reasons such as non-ideality of the color primaries, or bad plane. So why is it squarish?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* This image is not so clearly a polygon, like it's usually depicted as, but it's the best one I had at hand.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="48" LastEditDate="2015-08-13T19:59:48.217" LastActivityDate="2019-06-23T21:33:22.090" Title="Why is the CMYK space four sided in chromaticity charts" Tags="&lt;color&gt;&lt;color-management&gt;&lt;color-science&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="242" PostTypeId="2" ParentId="241" CreationDate="2015-08-13T21:08:56.523" Score="3" Body="&lt;p&gt;There are two aspects to this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The traditional chromaticity graph is actually a two-dimensional slice of a three-dimensional volume.  The slice usually used is one that matches up (more or less) to the fully-saturated primaries of an RGB-based colorspace; the full RGB colorspace is a tetrahedron.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;CMYK is a four-primary colorspace, with primaries that are not linearly independent.  This makes the full volume a complex shape.  Further, at least one (black) and possibly all four of the primaries don't lie on the plane of the 2D chromaticity graph.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The CMYK space is four-sided because it's a 2D slice of a complex 3D shape that (probably) doesn't lie on any of the surfaces of that shape.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-13T21:08:56.523" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="243" PostTypeId="1" AcceptedAnswerId="253" CreationDate="2015-08-14T02:19:08.863" Score="4" ViewCount="471" Body="&lt;p&gt;The Gimp has two different options in how you can perform Gaussian blur: &quot;IIR&quot; and &quot;RLE&quot;.  What's the difference between them?&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-15T10:35:37.133" Title="Different types of Gaussian blur?" Tags="&lt;2d&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="244" PostTypeId="2" ParentId="233" CreationDate="2015-08-14T05:31:08.123" Score="22" Body="&lt;p&gt;There are two different common meanings of &quot;light probe&quot; that I'm aware of. Both of them represent the light around a single point in a scene, i.e. what you would see around you in all directions if you were shrunk down to a tiny size and stood at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One meaning is a spherical harmonic representation of the light around a point.  &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_harmonics&quot;&gt;Spherical harmonics&lt;/a&gt; are a collection of functions defined over a spherical domain, which are analogous to sine waves that oscillate a certain number of times around the equator and from pole to pole on the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Spherical harmonics can be used to create a smooth, low-res approximation of any spherical function, by scaling and adding together some number of spherical harmonics&amp;mdash;usually 4 (known as linear, first-degree, or one-band SH) or 9 (called quadratic, second-degree, or two-band SH). This is very compact because you only have to store the scaling factors. For instance, for quadratic SH with RGB data, you only need 9*3 = 27 values per probe. So SH makes a very compact, but also necessarily very soft and blurry, representation of the light around a point. This is suitable for diffuse lighting, and perhaps specular with a high roughness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This screenshot from &lt;a href=&quot;http://simonstechblog.blogspot.com/2014_10_01_archive.html&quot;&gt;Simon's Tech Blog&lt;/a&gt; shows an array of SH light probes spaced throughout a scene, each one showing the indirect lighting received at that point:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xgMCf.jpg&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xgMCf.jpg&quot; alt=&quot;SH light probe array&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other currently common meaning of &quot;light probe&quot; is an environment cube-map whose mip levels have been pre-blurred to different extends so it can be used for specular lighting with varying levels of roughness. This image from &lt;a href=&quot;https://seblagarde.wordpress.com/2011/08/17/hello-world/&quot;&gt;Seb Lagarde's blog&lt;/a&gt; shows the basic idea:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/y2ICS.jpg&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/y2ICS.jpg&quot; alt=&quot;Prefiltered cubemap mip levels&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The higher-resolution mips (toward the left) are used for highly polished surfaces where you need a detailed reflected image. Toward the right, the lower-res mip levels are increasingly blurred, and are used for reflections from rougher surfaces. In a shader, when sampling this cubemap, you can calculate your requested mip level based on the material roughness, and take advantage of the trilinear filtering hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both of these types of light probes are used in real-time graphics to approximate indirect lighting. While direct lighting can be calculated in real-time (or at least approximated well for area lights), indirect lighting is usually still baked in an offline preprocess due to its complexity and computational overhead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Traditionally, the result of the baking process would be lightmaps, but lightmaps only work for diffuse lighting on static geometry, and they take up a lot of memory besides. Baking a bunch of SH light probes (you can afford a lot of them because they're very compact), plus a sparser sprinkling of cubemap light probes, allows you to get decent diffuse and specular indirect lighting on both static and dynamic objects. They're a popular option in games today.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-14T05:31:08.123" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="245" PostTypeId="1" AcceptedAnswerId="4096" CreationDate="2015-08-14T17:42:22.480" Score="13" ViewCount="1527" Body="&lt;p&gt;I've played with real time raytracing (and raymarching etc) quite a bit, but haven't spent that much time on non real time raytracing - for higher quality images or for pre-rendering videos and the like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know one common technique to improve image quality in the non real time case is to just cast A LOT more rays per pixel and average the results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any other techniques which stand out as good ways to improve image quality in the non real time case, over what you would normally do in the real time case?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-06T19:37:04.423" Title="Non Real Time Raytracing" Tags="&lt;raytracing&gt;&lt;photo-realistic&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="246" PostTypeId="1" AcceptedAnswerId="248" CreationDate="2015-08-14T17:45:21.800" Score="14" ViewCount="1586" Body="&lt;p&gt;I have written a small path-tracer after learning and experimenting on &lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot;&gt;smallpt&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only thing that I did not write (and understood) myself is how the initial rays are computed and fired from the camera. I got the principle right, but I'm looking for some resources describing how to:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Compute the initial direction of rays&lt;/li&gt;&#xA;&lt;li&gt;Modelize a real lens (as opposed to pinhole camera), supposedly allowing effects like depth of field ?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;State of the art maths and physics are not required, but OK if explained thoroughly.&lt;/p&gt;&#xA;" OwnerUserId="34" LastActivityDate="2015-08-18T02:02:18.880" Title="How to build a decent lens/camera objective model for path tracing?" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;monte-carlo&gt;&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="247" PostTypeId="2" ParentId="245" CreationDate="2015-08-14T17:58:47.153" Score="6" Body="&lt;p&gt;One of the big ones is the use of &lt;a href=&quot;https://en.wikipedia.org/wiki/Constructive_solid_geometry&quot;&gt;constructive solid geometry&lt;/a&gt; rather than triangle meshes.  Ray-triangle intersections are faster than almost any other ray-shape intersection, but it takes huge numbers of triangles to approximate the surface of a cylinder or torus, not to mention some of the really exotic shapes such as julia fractals or generalized parametric functions that some renderers support.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another is the use of render-time &lt;a href=&quot;https://en.wikipedia.org/wiki/Photon_mapping&quot;&gt;photon mapping&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Diffuse_reflection&quot;&gt;diffuse interreflection&lt;/a&gt; calculations: this lets you get accurate lighting effects in a changing scene.  In realtime raytracing, these are too expensive to compute, so either light sources and major geometry elements are forced to be stationary (to permit pre-calculation), or the effects are omitted entirely.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-14T17:58:47.153" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="248" PostTypeId="2" ParentId="246" CreationDate="2015-08-14T21:24:23.393" Score="14" Body="&lt;p&gt;The next step up from a pinhole camera model is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Thin_lens&quot; rel=&quot;noreferrer&quot;&gt;thin lens&lt;/a&gt; model, where we model the lens as being an infinitely thin disc. This is still an idealization that pretty far from modeling a real camera, but it will give you basic depth of field effects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7QOTx.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7QOTx.jpg&quot; alt=&quot;Thin lens model&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image above, from &lt;a href=&quot;http://www.panohelp.com/thinlensformula.html&quot; rel=&quot;noreferrer&quot;&gt;panohelp.com&lt;/a&gt;, shows the basic idea. For each point on the image, there are multiple rays arriving at that image point, via every point on the 2D lens surface. Therefore, generating an image like this using Monte Carlo will require picking, for each ray, both a 2D sample point on the image plane and an independent 2D sample point on the lens surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The user-facing parameters to set will be the lens radius (as a physical radius in scene units), which controls how shallow the focus range is (larger lens = shallower focus range), and the distance at which you want objects to be in focus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To generate eye rays into the scene, you can calculate the position and direction of rays leaving the lens surface; in this model there's no need to explicitly simulate the image plane and the refraction through the lens.  Basically, think of the lens as centered at the camera position and oriented to face the camera direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Based on the image location, construct a ray from the camera position (lens center) into the scene, just as you would in the pinhole model; then find its intersection with the focal plane. That's where all the rays from that image location should converge.  Now you can offset the starting point of the ray to a randomly chosen point on the lens, and set its direction to be toward the convergence point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can generalize this a bit by allowing the focal plane to be something other than a plane, or the lens to be something other than a circular disc, and following the same process. That can produce some interesting if not-quite-physical effects.  It's also possible to go beyond this simple model with a more physically realistic simulation of a camera's lens elements&amp;mdash;but that's beyond my expertise.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-14T21:24:23.393" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="249" PostTypeId="2" ParentId="203" CreationDate="2015-08-14T21:40:51.403" Score="26" Body="&lt;p&gt;There are various different types of limitation to take into consideration.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Effects for which the path of a ray is dependent on its wavelength&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;These are a class of effects for which spectral rendering is required, and a number of interesting examples have already been given in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/204/231&quot;&gt;Benedikt Bitterli's answer&lt;/a&gt;. A simple example is a prism splitting white light into a spectrum, giving rainbow colours. Rays of different wavelength are refracted by different angles as they pass through the prism, resulting in the light striking the wall behind the prism being split into its constituent colours.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that in real life, shining monochromatic yellow light through a prism will result in yellow light coming out, but shining a mixture of red and green light that approximates yellow will result in separate red and green light emerging. When rendering using only 3 primary colours, white light will split into only those three colours, giving rainbow effects that look discontinuous, and monochromatic light that should not split at all will split into its approximating primary colour components. The splitting of white light can be improved by using a larger number of primary colours, but this will still give discontinuities close up, and the results for monochromatic light will still be split, albeit more narrowly. For accurate results a continuous spectrum must be sampled, with wavelengths distributed according to the light source being simulated.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Surface effects that cannot be captured in a single still image&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Iridescence&quot; rel=&quot;noreferrer&quot;&gt;Iridescence&lt;/a&gt;, for example, shows a different colour to each eye so that a still image will not look the same as the original object. There are many everyday examples that you might not notice at first. Many common birds have iridescent feathers even though they appear black or grey from a distance. Close up they are surprisingly colourful. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A renderer using only 3 primary colours will not be able to produce the spreading of light based on wavelength required for this effect. A spectral renderer can simulate the spreading correctly, but the full effect still cannot be captured in a single image. Even a 2d photograph cannot capture this correctly, whereas a 3d photograph of an iridescent object will give that shimmering effect as the photographs corresponding to left and right eyes will be coloured differently. This is a limitation of 2d images rather than the RGB colour space itself. However, even in a 3d image there will be colours in the iridescent object that are not displayed correctly, due to the inability of RGB to display monochromatic colours as described below.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Colours that the human eye can detect that cannot be displayed in RGB&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;RGB was historically device dependent and therefore unreliable between platforms. There are device independent perceptually uniform improvements such as the colour space &lt;a href=&quot;http://en.wikipedia.org/wiki/Lab_color_space&quot; rel=&quot;noreferrer&quot;&gt;Lab&lt;/a&gt;, but these are still trichromatic (having 3 components). It is not immediately obvious why three components is insufficient to display all the colours that can be perceived by a trichromatic eye, but &lt;a href=&quot;http://www.babelcolor.com/download/A%20review%20of%20RGB%20color%20spaces.pdf&quot; rel=&quot;noreferrer&quot;&gt;this paper&lt;/a&gt; explains it well, and accessibly. From page 7:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;For example, using a modern laser-display system with monochromatic primaries at 635 nm (red), 532 nm (green), and 447 nm (blue), lets see if we can simulate the perception of a monochromatic light at 580 nm (an orange color). Since the monochromatic orange stimulus excites the greenish and reddish cones, a contribution is required by both the green and red primaries, while no contribution is required from the blue primary. The problem is that the green primary also excites the bluish cones, making it impossible to exactly replicate the orange stimulus&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The diagram of human eye cones sensitivities (also on page 7) shows how wide the overlap is and helps to visualise this explanation. I've included a similar graph from Wikipedia here: (click on the graph for the Wikipedia location)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Spectral_sensitivity#/media/File:Cones_SMJ2_E.svg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/1/1e/Cones_SMJ2_E.svg&quot; alt=&quot;Graph of the sensitivities of the 3 different cones in the human eye&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, the overlap between the range of colours that can be picked up by each of the three different cones (colour sensors) of the human eye means that a monochromatic colour can be distinguished from an approximating mixture of primary colours, and therefore mixing primary colours can never accurately display all monochromatic colours.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This difference is not usually noticeable in everyday life as most of our surroundings emit or reflect light across a wide range of frequencies rather than single monochromatic colours. However, a notable exception is sodium lamps. If you live in a part of the world that uses these yellow-orange street lights, the light emitted is monochromatic and will look subtly different from a printed photograph or an image on a screen. The wavelength of sodium light happens to be the 580 nm from the example quoted above. If you don't live somewhere that has sodium street lights, you can see the same single wavelength light by sprinkling finely crushed table salt (sodium chloride) over a flame. The scintillating yellow points of light cannot be accurately captured on film or displayed on a screen. Whatever three primary colours you choose, there will always be a range of monochromatic colours that cannot be displayed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this limitation applies equally to mixing 3 primary colours of paint, using 3 photoreactive chemicals on a camera film, or taking a photograph with a digital camera with 3 different colour sensors, or a single sensor with 3 different primary colour filters. It isn't just a digital problem, and isn't just restricted to the RGB colour space. Even the improvements introduced by the Lab colour space and its variants cannot recover the missing colours.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Miscellaneous effects&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;Multiple diffuse reflections (colour bleeding)&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If a brightly coloured matt surface is near a white matt surface, the white surface will show some of the colour of the other surface. This can be modeled reasonably well using purely red, green and blue components. The same combination of red, green and blue that gave the colour of the coloured surface can reflect off the white surface and show some of that colour again. However, this only works if the second surface is white. If the second surface is also coloured, then the colour bleeding will be inaccurate, in some cases drastically.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine two surfaces that look a similar colour. One reflects a narrow range of wavelengths around yellow. The other reflects a wide range of wavelengths between red and green, and as a result also looks yellow. In real life, the light showing on one surface due to the other will not be symmetrical. Most of the light reaching the wide wavelength range surface from the other will be reflected again, as the narrow range of incoming wavelengths are all within the wider range. However, most of the light reaching the narrow wavelength range surface from the other will be outside the narrow range, and will not be reflected. In an RGB renderer, both surfaces will be modelled as a mixture of monochromatic red and monochromatic green, giving no difference in reflected light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is an extreme example where the difference will be instantly noticeable to the eye, but there will be at least a subtle difference in most images that include colour bleeding.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Materials that absorb one wavelength and emit another&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/a/207/231&quot;&gt;joojaa's answer&lt;/a&gt; describes the absorption of ultraviolet light by snow, to be re-emitted as visible light. I hadn't heard of this happening with snow before (and frustratingly I've been unable to find any evidence to support it - although it would explain why snow is &quot;whiter than white&quot;). However, there is plenty of evidence of it happening with a wide range of other materials, some of which are added to clothes washing detergents and paper, to give extra bright whites. This allows the total visible light outgoing from a surface to be more than the total visible light received by that surface, which again is not modelled well using only RGB. If you want to read more about it, the term to search for is &lt;a href=&quot;https://en.wikipedia.org/wiki/Fluorescence&quot; rel=&quot;noreferrer&quot;&gt;Fluorescence&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Eyes with more than 3 primary colours&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;There are animals that have more than 3 types of cones in their eyes, allowing them to perceive more than 3 primary colours. For example, many birds, insects and fish are &lt;a href=&quot;https://en.wikipedia.org/wiki/Tetrachromacy&quot; rel=&quot;noreferrer&quot;&gt;tetrachromats&lt;/a&gt;, perceiving four primary colours. Some are even &lt;a href=&quot;https://en.wikipedia.org/wiki/Pentachromacy&quot; rel=&quot;noreferrer&quot;&gt;pentachromats&lt;/a&gt;, perceiving five. The range of colours that such creatures can see dwarfs the range displayable using only RGB. Far beyond them is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Mantis_shrimp#Eyes&quot; rel=&quot;noreferrer&quot;&gt;mantis shrimp&lt;/a&gt;, which is a dodecachromat, seeing colours based on 12 different cones. None of these animals would be satisfied by an RGB display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But more seriously, even for images intended for human eyes, there are believed to be &lt;a href=&quot;https://en.wikipedia.org/wiki/Tetrachromacy#Human_tetrachromats&quot; rel=&quot;noreferrer&quot;&gt;human tetrachromats&lt;/a&gt; who see in 4 primary colours, and possibly some who see as many as 5 or 6. At present, such people don't seem to be present in sufficient numbers to make displays with more than 3 primary colours commercially viable, but if in future it becomes easier to identify how many primary colours a person can see, this may become an attractive trait leading to it spreading throughout the population in future generations. So if you want your great grandchildren to appreciate your work you may need to make it compatible with a hexachromatic monitor...&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Not really relevant to this question, but related: If you want to see colours that are not available in either the real world&lt;/em&gt; &lt;strong&gt;or&lt;/strong&gt; &lt;em&gt;RGB images, have a look at &lt;a href=&quot;https://en.wikipedia.org/wiki/Impossible_color#Chimerical_colors&quot; rel=&quot;noreferrer&quot;&gt;Chimerical Colours&lt;/a&gt;...&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-14T21:40:51.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="250" PostTypeId="1" AcceptedAnswerId="252" CreationDate="2015-08-14T22:11:19.027" Score="13" ViewCount="587" Body="&lt;p&gt;I've seen in several places that making Perlin noise loop seamlessly requires calculating it twice in slightly different ways, and summing the two results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html#loop&quot; rel=&quot;nofollow&quot;&gt;This Perlin noise math FAQ&lt;/a&gt; gives a formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$F_{loop}(x, y, z) = \frac{ (t - z) \cdot F(x, y, z) + z \cdot F(x, y, z - t) }{ t}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;to make a noise function $F$ loop in the $z$ direction. It also mentions that extending this, to loop in 2 dimensions would take 4 evaluations of $F$ and to loop in 3 dimensions would take 8 evaluations of $F$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that this gives a seamless join between tiles that is not only continuous but continuously differentiable, but I intuitively expect that to be the case if the noise function is simply evaluated once with grid points reduced modulo the required tile size. If the noise function is only ever based on the immediately surrounding grid points (4 for 2D noise, 8 for 3D noise) then surely just using the leftmost grid points when the point to calculate gets past the right hand edge of the tile will give the same quality of noise as between any other grid points?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I've seen this multiple calculation approach in several places I assume it must have some advantage, but I'm struggling to see the disadvantage with simply wrapping the grid points back to the start when they get too big. What am I missing?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="127" LastEditDate="2015-11-03T14:51:01.303" LastActivityDate="2015-11-03T14:51:01.303" Title="Why is it twice as expensive to make a noise function that can be tiled?" Tags="&lt;algorithm&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="251" PostTypeId="2" ParentId="57" CreationDate="2015-08-15T00:14:29.170" Score="2" Body="&lt;p&gt;A good starting point is the classic paper &lt;a href=&quot;http://dl.acm.org/citation.cfm?id=192227&quot; rel=&quot;nofollow&quot;&gt;Using particles to sample and control implicit surfaces&lt;/a&gt;, published in SIGGRAPH 1994.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple particle simulation described in the paper &lt;a href=&quot;http://dx.doi.org/10.1016/0097-8493(96)00005-2&quot; rel=&quot;nofollow&quot;&gt;Sampling implicit objects with physically-based particle systems&#xA;&lt;/a&gt; (&lt;em&gt;Computers &amp;amp; Graphics&lt;/em&gt;, 1996) for curves works for surfaces as well; see &lt;a href=&quot;http://www.visgraf.impa.br/Projects/dtexture/&quot; rel=&quot;nofollow&quot;&gt;Dynamic Texture for Implicit Surfaces&lt;/a&gt; for examples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a more recent example, see &lt;a href=&quot;http://dx.doi.org/10.1016/j.cag.2010.09.017&quot; rel=&quot;nofollow&quot;&gt;Shape and tone depiction for implicit surfaces&lt;/a&gt; (&lt;em&gt;Computers &amp;amp; Graphics&lt;/em&gt;, 2011). &lt;/p&gt;&#xA;" OwnerUserId="192" LastEditorUserId="192" LastEditDate="2015-08-18T18:26:56.627" LastActivityDate="2015-08-18T18:26:56.627" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="252" PostTypeId="2" ParentId="250" CreationDate="2015-08-15T05:55:52.820" Score="20" Body="&lt;p&gt;It's unfortunate that people commonly recommend this.  Blending between two (or four, etc.) translated copies of a noise function in that way is a pretty bad idea. Not only is it expensive, it doesn't even produce correct-looking results!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/DgnQE.png&quot; alt=&quot;Perlin noise&quot;&gt; &lt;img src=&quot;https://i.stack.imgur.com/949SB.png&quot; alt=&quot;Blended Perlin noise&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the left is some Perlin noise. On the right is two instances of Perlin noise, stacked and blended left-to-right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference is kind of subtle, but you can see that the second image has lower contrast in a vertical column running down the middle.  That's where it's a 50% blend between two different instances of the noise function. Such a blend doesn't look like the original noise function: it just looks like a muddy mess.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OK, so it's not quite &lt;em&gt;that&lt;/em&gt; bad just looking at the raw noise...but if you then do any nonlinear transformations on the image, the nonuniform contrast can cause issues. For instance, here are those images thresholded at 60%. (Think of generating islands in an ocean, for instance.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/elyF1.png&quot; alt=&quot;Thresholded Perlin noise&quot;&gt; &lt;img src=&quot;https://i.stack.imgur.com/Micts.png&quot; alt=&quot;Thresholded blended Perlin noise&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can plainly see how the image on the right has fewer, smaller white areas in the middle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Like you mentioned, for grid-based noise like Perlin, a better way is to tile the pseudorandom gradients at the grid points. That's easy and cheap to do, and then you can apply the interpolation algorithm to the gradients as usual (much like bilinear interpolation of a tiling texture). This produces tiling noise without any weird artifacts, because it works &lt;em&gt;with&lt;/em&gt; the underlying noise algorithm rather than over the top of it. You can use a similar strategy with Worley noise (cellular noise) by tiling the random feature points it uses as a basis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With multiple octaves of noise it's not always so easy, though. If the relative scale between the octaves (aka &quot;lacunarity&quot;) isn't an integer or simple rational number, then you may not be able to find a convenient tiling point where all the octaves' grids match up. You could tile each octave independently, but the overall noise would still not be tilable in that case.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-15T05:55:52.820" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="253" PostTypeId="2" ParentId="243" CreationDate="2015-08-15T10:35:37.133" Score="5" Body="&lt;p&gt;From the &lt;a href=&quot;http://docs.gimp.org/en/plug-in-gauss.html&quot; rel=&quot;noreferrer&quot;&gt;GIMP docs&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;h3&gt;IIR&lt;/h3&gt;&#xA;&lt;p&gt;IIR stands for “infinite impulse response”. This blur works best for large radius values and for images which are not computer generated.&lt;/p&gt;&#xA;&lt;h3&gt;RLE&lt;/h3&gt;&#xA;&lt;p&gt;RLE stands for “run-length encoding”. RLE Gaussian Blur is best used on computer-generated images or those with large areas of constant intensity.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;and also&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;They both produce the same results, but each one can be faster in some cases.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So the short answer is that IIR is optimised for photographs, and RLE is optimised for images with areas of flat colour.&lt;/p&gt;&#xA;&lt;p&gt;The claim seems to be that the only difference is the time taken to calculate the blur, and that the end results are identical. I haven't tested this, so if you need to rely on that claim you should test both and check for any differences in the results.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-08-15T10:35:37.133" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="254" PostTypeId="5" CreationDate="2015-08-15T13:07:08.230" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2015-08-15T13:07:08.230" LastActivityDate="2015-08-15T13:07:08.230" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="255" PostTypeId="4" CreationDate="2015-08-15T13:07:08.230" Score="0" Body="For questions about creating or working with noise functions (in 1D, 2D, 3D or more)." OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-08-16T05:02:48.720" LastActivityDate="2015-08-16T05:02:48.720" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="256" PostTypeId="1" AcceptedAnswerId="258" CreationDate="2015-08-15T18:33:42.943" Score="10" ViewCount="3110" Body="&lt;p&gt;To make Gaussian blurring a 2d image faster, I know that you can do one axis and then the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm wondering though, if I did two Gaussian blurs of size $N$, would that be the same mathematically as doing one Gaussian blur of size $2N$?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="16" LastEditDate="2015-11-03T15:21:02.520" LastActivityDate="2020-02-25T08:43:59.617" Title="Is doing multiple Gaussian blurs the same as doing one larger blur?" Tags="&lt;real-time&gt;&lt;post-processing&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="257" PostTypeId="1" AcceptedAnswerId="263" CreationDate="2015-08-15T18:38:26.450" Score="4" ViewCount="798" Body="&lt;p&gt;In image editing software, you often have the ability to do a directional blur where you can choose and angle and a magnitude of a blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does this actually work in practice with Gaussian blurring?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could see possibly doing something like making the blur go across the axis specified by the angle and use some sort of texture sampling to find the appropriate sample (bilinear or bicubic sampling), but that seems like it probably isn't correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does directional blurring usually work?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would say this is in fact motion blur, but I'm asking specifically about the blurring portion, not the whole set up for motion blur within a renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance before and after:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://docs.gimp.org/en_GB/images/filters/examples/taj_orig.jpg&quot; alt=&quot;enter image description here&quot;&gt;&#xA;&lt;img src=&quot;https://docs.gimp.org/en_GB/images/filters/examples/blur-taj-mblur-linear.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-03-10T09:42:35.270" LastActivityDate="2015-08-16T12:54:36.177" Title="How does directional Gaussian blurring work?" Tags="&lt;real-time&gt;&lt;post-processing&gt;&lt;gaussian-blur&gt;&lt;blur&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="258" PostTypeId="2" ParentId="256" CreationDate="2015-08-15T19:40:53.283" Score="13" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;If I did two Gaussian blurs of size N, would that be the same mathematically as doing one Gaussian blur of size 2N?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Almost. Applying two Gaussian blurs &lt;em&gt;is&lt;/em&gt; equivalent to doing one Gaussian blur, but with a slightly different size calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying a Gaussian blur to an image means doing a &lt;a href=&quot;https://en.wikipedia.org/wiki/Convolution&quot; rel=&quot;nofollow noreferrer&quot;&gt;convolution&lt;/a&gt; of the Gaussian with the image. Convolution is associative: Applying two Gaussian blurs to an image is equivalent to convolving the two Gaussians with each other, and convolving the resulting function with the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As it happens, the convolution of two Gaussians with each other is another Gaussian, whose variance is the sum of variances of the two original Gaussians. A Gaussian of N pixel width has variance &lt;span class=&quot;math-container&quot;&gt;$N^2$&lt;/span&gt;; applying it twice is equivalent to a Gaussian with variance &lt;span class=&quot;math-container&quot;&gt;$2\cdot N^2$&lt;/span&gt;, which corresponds to a width of &lt;span class=&quot;math-container&quot;&gt;$\sqrt{2}\cdot N$&lt;/span&gt; pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the same vein, applying a Gaussian of width &lt;span class=&quot;math-container&quot;&gt;$2\cdot N$&lt;/span&gt; is equivalent to applying a Gaussian of width &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; four times.&lt;/p&gt;&#xA;" OwnerUserId="79" LastEditorUserId="209" LastEditDate="2020-02-25T08:43:59.617" LastActivityDate="2020-02-25T08:43:59.617" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="259" PostTypeId="1" AcceptedAnswerId="260" CreationDate="2015-08-15T21:28:31.733" Score="19" ViewCount="2104" Body="&lt;p&gt;I have set up some FPS-measuring code in WebGL (based on &lt;a href=&quot;https://stackoverflow.com/a/16447895/1633117&quot;&gt;this SO answer&lt;/a&gt;) and have discovered some oddities with the performance of my fragment shader. The code just renders a single quad (or rather two triangles) over a 1024x1024 canvas, so all the magic happens in the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider this simple shader (GLSL; the vertex shader is just a pass-through):&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;// some definitions&#xA;&#xA;void main() {&#xA;    float seed = uSeed;&#xA;    float x = vPos.x;&#xA;    float y = vPos.y;&#xA;&#xA;    float value = 1.0;&#xA;&#xA;    // Nothing to see here...&#xA;&#xA;    gl_FragColor = vec4(value, value, value, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So this just renders a white canvas. It averages around 30 fps on my machine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let's ramp up the number crunching and compute each fragment based on a few octaves of position-dependent noise:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;void main() {&#xA;    float seed = uSeed;&#xA;    float x = vPos.x;&#xA;    float y = vPos.y;&#xA;&#xA;    float value = 1.0;&#xA;&#xA;      float noise;&#xA;      for ( int j=0; j&amp;lt;10; ++j)&#xA;      {&#xA;        noise = 0.0;&#xA;        for ( int i=4; i&amp;gt;0; i-- )&#xA;        {&#xA;            float oct = pow(2.0,float(i));&#xA;            noise += snoise(vec2(mod(seed,13.0)+x*oct,mod(seed*seed,11.0)+y*oct))/oct*4.0;&#xA;        }&#xA;      }&#xA;&#xA;      value = noise/2.0+0.5;&#xA;&#xA;    gl_FragColor = vec4(value, value, value, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;If you want to run the above code, I've been using &lt;a href=&quot;https://github.com/ashima/webgl-noise&quot; rel=&quot;nofollow noreferrer&quot;&gt;this implementation of &lt;code&gt;snoise&lt;/code&gt;&lt;/a&gt;.&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This brings down the fps to something like 7. That makes sense.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the weird part... let's compute only one of every 16 fragments as noise and leave the others white, by wrapping the noise computation in the following conditional:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;if (int(mod(x*512.0,4.0)) == 0 &amp;amp;&amp;amp; int(mod(y*512.0,4.0)) == 0)) {&#xA;    // same noise computation&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You'd expect this to be much faster, but it's still only 7 fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For one more test, let's instead filter the pixels with the following conditional:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cplusplus prettyprint-override&quot;&gt;&lt;code&gt;if (x &amp;gt; 0.5 &amp;amp;&amp;amp; y &amp;gt; 0.5) {&#xA;    // same noise computation&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This gives the exact same number of noise pixels as before, but now we're back up to almost 30 fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What is going on here?&lt;/strong&gt; Shouldn't the two ways to filter out a 16th of the pixels give the exact same number of cycles? And why is the slower one as slow as rendering &lt;em&gt;all&lt;/em&gt; pixels as noise?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bonus question: &lt;strong&gt;What can I do about this?&lt;/strong&gt; Is there any way to work around the horrible performance if I actually &lt;em&gt;do&lt;/em&gt; want to speckle my canvas with only a few expensive fragments?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Just to be sure, I have confirmed that the actual modulo computation does not affect the frame rate at all, by rendering every 16th pixel black instead of white.)&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2015-08-16T14:51:28.630" Title="Why is this conditional in my fragment shader so slow?" Tags="&lt;performance&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="260" PostTypeId="2" ParentId="259" CreationDate="2015-08-15T21:51:02.300" Score="22" Body="&lt;p&gt;Pixels get grouped into little squares (how big depends on the hardware) and computed together in a single &lt;a href=&quot;https://en.wikipedia.org/wiki/SIMD&quot;&gt;SIMD&lt;/a&gt; pipeline. (struct of arrays type of SIMD)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This pipeline (which has several different names depending on the vendor: warps, wavefronts) will execute operations for each pixel/fragment in lockstep. This means that if 1 pixel needs a computation done then all pixels will compute it and the ones that don't need the result will throw it away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all fragments follow the same path through a shader then the other branches won't get executed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that your first method of computing every 16th pixel will be worst case branching. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to still down size your image then just render to a smaller texture and then upscale it. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-08-15T21:51:02.300" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="261" PostTypeId="1" AcceptedAnswerId="262" CreationDate="2015-08-16T03:50:54.883" Score="7" ViewCount="3303" Body="&lt;p&gt;When realtime renderers (such as 3d games) have motion blur, how is it usually implemented?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think I've heard something about needing to have motion vectors for each pixel but I'm not sure about that and not sure how it would be used.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-16T07:33:01.567" Title="How is motion blur implemented in modern realtime renderers?" Tags="&lt;real-time&gt;&lt;post-processing&gt;&lt;blur&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="262" PostTypeId="2" ParentId="261" CreationDate="2015-08-16T07:33:01.567" Score="8" Body="&lt;p&gt;There are several techniques used. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple, but limited, &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html&quot; rel=&quot;noreferrer&quot;&gt; post-process approach&lt;/a&gt; that is not really used any more consists in reconstructing the world space position of a pixel using both the view projection matrix from current and previous frame. Using these two values you can compute the velocity at a pixel and blur accordingly, sampling along the velocity vector with how many samples you want ( the more sample the blurrier, but the more expensive as well). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This method unfortunately takes into account just the camera movement and therefore is not accurate enough if you have a dynamic scene with fast moving objects. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you mentioned, other more modern techniques use a velocity buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This velocity buffer can be created during the base pass in the deferred pipeline transforming each vertex using the world-view-projection matrix of the previous frame and then computing in the pixel shader the velocity vector using the screen space position of both frames.&lt;br&gt;&#xA;With this velocity buffer you can, in a post-process step, sample across the per-pixel velocity direction like in the approach I described above.  The motion blur that you will get is obviously not camera-only; however you get an overhead in terms of memory (you need to keep an extra buffer) and time (you need to render additional info per pixel). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One technique based on velocity buffer that I particularly like is &lt;a href=&quot;http://graphics.cs.williams.edu/papers/MotionBlurI3D12/McGuire12Blur.pdf&quot; rel=&quot;noreferrer&quot;&gt;McGuire et al.&lt;/a&gt; that IIRC, is used with some variations in Unreal Engine 4 and many other games. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pXpdE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pXpdE.png&quot; alt=&quot; From McGuire et al. 2012 &quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;From [McGuire et al. 2012]&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They divide the scene in tiles, assuming that each of these have a dominant velocity. Then, starting from the full res velocity buffer, they locate the velocity vector with higher magnitude for each tile, producing a downsampled version of the velocity buffer where 1 pixel = 1 tile.&lt;br&gt;&#xA;Using this buffer, in another pass, they can generate a buffer that stores for each pixel/tile the dominant velocity among the neighbourhood pixels.&#xA;Note that the tile size is based on the max blur radius. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using these buffers they then proceed with the gathering step sampling in the neighbourhood dominant velocity direction as this is the most plausible direction of the blur for each sample (as I said, the tile size is the max-blur radius). The weighting used for the blur takes into account the full res velocity and depth informations. Note that the paper propose three different weighting for three different scenarios (blurry over sharp, sharp over blurry and blurry over blurry). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another important advantage of the method is that you can early-out if the dominant velocity in the neighbourhood is smaller than a certain threshold. &lt;/p&gt;&#xA;" OwnerUserId="100" LastActivityDate="2015-08-16T07:33:01.567" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="263" PostTypeId="2" ParentId="257" CreationDate="2015-08-16T10:57:32.917" Score="4" Body="&lt;p&gt;If I understand your question, you are asking how to actually perform said directional blur in code? A Gaussian blur is typically done by sampling your image in all directions around your current point (or if in 2 passes, one vertical and one horizontal which equates to the same thing), with a specific set of weights for the falloff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a directional blur you just need to change the shape of your kernel to &quot;not be round&quot;, for lack of better words.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say you wanted to smear the image to the left only, you could just accumulate samples (with whatever weights you want) with &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;currentPixelUV.xy + float2( -1.f * someOffsetScale, 0.f) * invScreenRes.xy * currentIteration;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Bilinear texture filtering will be required for this to work when your resulting &lt;em&gt;uv&lt;/em&gt;s are not hitting pixel centers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The magnitude of the blur is controlled by how far you sample from your original pixel.&lt;/p&gt;&#xA;" OwnerUserId="406" LastEditorUserId="406" LastEditDate="2015-08-16T12:54:36.177" LastActivityDate="2015-08-16T12:54:36.177" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="264" PostTypeId="5" CreationDate="2015-08-16T12:10:39.143" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Shader&quot; rel=&quot;nofollow&quot;&gt;Shaders&lt;/a&gt; are programs which are written to customise a programmable GPU pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most common shader languages are &lt;a href=&quot;https://en.wikipedia.org/wiki/OpenGL_Shading_Language&quot; rel=&quot;nofollow&quot;&gt;GLSL&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/High-Level_Shading_Language&quot; rel=&quot;nofollow&quot;&gt;HLSL&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-08-16T12:48:12.710" LastActivityDate="2015-08-16T12:48:12.710" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="265" PostTypeId="4" CreationDate="2015-08-16T12:10:39.143" Score="0" Body="For all questions related to shaders, i.e. the programmable part of the GPU pipeline. For language-specific shader questions, see also the [glsl] and [hlsl] tags." OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-08-16T12:48:36.057" LastActivityDate="2015-08-16T12:48:36.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="266" PostTypeId="1" AcceptedAnswerId="275" CreationDate="2015-08-16T13:49:05.607" Score="11" ViewCount="7516" Body="&lt;p&gt;When using textures in GLSL, it is best to calculate the final texture coordinates in the vertex shader and hand them over to the fragment shader using &lt;code&gt;varying&lt;/code&gt;s. Example with a simple flip in the y coordinate:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Vertex shader&#xA;attribute vec2 texture;&#xA;varying highp vec2 texCoord;&#xA;// ...&#xA;void main() {&#xA;    texCoord = vec2(texture.x, 1.0-texture.y);&#xA;    // ...&#xA;}&#xA;&#xA;// Fragment shader&#xA;varying highp vec2 textureCoordinates;&#xA;uniform sampler2D tex;&#xA;// ...&#xA;void main() {&#xA;    highp vec4 texColor = texture2D(tex, texCoord);&#xA;    // ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the flip in the y coordinate, or an even simpler operation like adding &lt;code&gt;vec2(0.5)&lt;/code&gt; to the texture coordinate is performed in the fragment shader the texture access is much slower. Why?&lt;/p&gt;&#xA;&#xA;&lt;hr /&gt;&#xA;&#xA;&lt;p&gt;As a note, e.g. blending two textures, using a weighted sum of them, is much cheaper in terms of time and also needs to be done for each pixel, so the computation of the texture coordinate itself does not seem to be that costly.&lt;/p&gt;&#xA;" OwnerUserId="127" LastActivityDate="2015-08-17T00:31:23.877" Title="Why is accessing textures much slower when calculating the texture coordinate in the fragment shader?" Tags="&lt;performance&gt;&lt;glsl&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="267" PostTypeId="5" CreationDate="2015-08-16T14:31:07.893" Score="0" Body="&lt;p&gt;Use this tag for questions about computations subject to real-time constraints. The minimum framerate for a real-time illusion is usually considered to be around 24 frames per second, at which the human will perceive a sequence of similar frames as fluid motion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information, &lt;a href=&quot;https://en.wikipedia.org/wiki/Real-time_computer_graphics&quot; rel=&quot;nofollow&quot;&gt;see Wikipedia&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See also &lt;a href=&quot;/questions/tagged/interactive&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;interactive&amp;#39;&quot; rel=&quot;tag&quot;&gt;interactive&lt;/a&gt; for less strict constraints and &lt;a href=&quot;/questions/tagged/offline&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;offline&amp;#39;&quot; rel=&quot;tag&quot;&gt;offline&lt;/a&gt; for computations which will take significantly longer.&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-08-16T16:50:42.327" LastActivityDate="2015-08-16T16:50:42.327" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="268" PostTypeId="4" CreationDate="2015-08-16T14:31:07.893" Score="0" Body="For questions about computations subject to real-time constraints. The minimum framerate for a real-time illusion is usually considered to be around 24 frames per second. See also [interactive] for less strict constraints and [offline] for computations which will take significantly longer." OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-08-16T16:50:55.587" LastActivityDate="2015-08-16T16:50:55.587" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="269" PostTypeId="5" CreationDate="2015-08-16T14:37:22.753" Score="0" Body="&lt;p&gt;Use this tag for questions about computations with no or loose time constraints, which may take minutes, hours or days to complete.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Offline computations are commonly used as pre-computations for real-time applications or rendering of films. They usually allow for vastly superior and more realistic effects to be incorporated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For computations with time constraints, see &lt;a href=&quot;/questions/tagged/real-time&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;real-time&amp;#39;&quot; rel=&quot;tag&quot;&gt;real-time&lt;/a&gt; and &lt;a href=&quot;/questions/tagged/interactive&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;interactive&amp;#39;&quot; rel=&quot;tag&quot;&gt;interactive&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-08-16T16:51:11.287" LastActivityDate="2015-08-16T16:51:11.287" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="270" PostTypeId="4" CreationDate="2015-08-16T14:37:22.753" Score="0" Body="For questions about computations with no or loose time constraints, which may take minutes, hours or days to complete. For computations with time constraints, see [real-time] and [interactive]." OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-08-16T16:51:16.567" LastActivityDate="2015-08-16T16:51:16.567" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="271" PostTypeId="1" AcceptedAnswerId="274" CreationDate="2015-08-16T16:26:37.870" Score="5" ViewCount="2975" Body="&lt;p&gt;Especially when rendering particle effects, the same object needs to be rendered several times with slightly modified properties. But these changes are often limited to properties like pose or textures, and are not in the geometry of the object itself. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A different pose (translation, rotation) is merely a matrix multiplication with the vertices, and a different texture with an applied texture atlas are merely different texture coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nevertheless each of the particles needs to be drawn and I currently do that by calling &lt;code&gt;glDrawElements&lt;/code&gt; for every particle, while setting uniforms appropriately. Until now this is sufficient for rendering the scene in real-time, but for more complex scenes or simply for more particles emitted by the particle system this could easily lead to dropping frame rates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is there a way to reduce the number of draw calls for very similar objects? &lt;/p&gt;&#xA;" OwnerUserId="127" LastActivityDate="2015-08-16T18:37:46.270" Title="How to reduce the number of draw calls when rendering one object multiple times?" Tags="&lt;opengl&gt;&lt;performance&gt;&lt;real-time&gt;&lt;mobile&gt;&lt;opengl-es&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="272" PostTypeId="2" ParentId="271" CreationDate="2015-08-16T16:26:37.870" Score="4" Body="&lt;p&gt;In OpenGL ES there is Instancing which provides allows for rendering one object multiple times. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using Instancing, you can use uniform arrays to provide different information, e.g. a transformation matrix, for each of the particles. In the shader you can then use &lt;code&gt;gl_InstanceID&lt;/code&gt; to distinguish between the individual particles and pick the appropriate index from the uniform array.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;attribute vec4 position;&#xA;uniform mat4 transformations[16];&#xA;// other attributes, uniforms, etc&#xA;void main() {&#xA;    // ...&#xA;    gl_Position = ... * transformations[gl_InstanceID] * position;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And you need to draw your objects using &lt;code&gt;glDrawElementsInstanced&lt;/code&gt; which takes the number of objects as an additional parameter (compared to &lt;code&gt;glDrawElements&lt;/code&gt;).&lt;/p&gt;&#xA;&#xA;&lt;hr /&gt;&#xA;&#xA;&lt;p&gt;Note: In OpenGL ES 2, you need to use &lt;code&gt;gl_InstanceIDEXT&lt;/code&gt; and &lt;code&gt;glDrawElementsInstancedEXT&lt;/code&gt; as it is an &lt;a href=&quot;https://www.khronos.org/registry/gles/extensions/EXT/draw_instanced.txt&quot; rel=&quot;nofollow&quot;&gt;extension&lt;/a&gt; there. Also you have to enable it in the shader using&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#extension GL_EXT_draw_instanced : enable&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="127" LastActivityDate="2015-08-16T16:26:37.870" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="273" PostTypeId="2" ParentId="175" CreationDate="2015-08-16T18:15:33.757" Score="2" Body="&lt;p&gt;I realized that littlecms, &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/175/how-is-an-icc-profile-embedded-or-built-into-an-image#comment247_175&quot;&gt;suggested by &lt;em&gt;joojaa&lt;/em&gt; in a comment above&lt;/a&gt; is very complete in dealing with the ICC profiles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did a few tests in their color translator program with different destination color spaces and the differences are great as you can see:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Original&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xe6IM.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xe6IM.jpg&quot; alt=&quot;Original&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;sRGB-like&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NbIee.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NbIee.jpg&quot; alt=&quot;sRGB&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;adobeRGB1998 (it seems it's the original color space)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P7aGm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P7aGm.jpg&quot; alt=&quot;adobeRGB&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;appleRGB&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iAmh5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iAmh5.jpg&quot; alt=&quot;apple&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the most desirable results in my case are within the ProPhotoRGB color space:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gp5GS.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gp5GS.jpg&quot; alt=&quot;prophoto&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;linearProPhotoRGB&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MIJk4.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MIJk4.jpg&quot; alt=&quot;linearProPhoto&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of the above were following an automatic &lt;em&gt;rendering intent&lt;/em&gt; but other &lt;em&gt;intents&lt;/em&gt; bring slight variations (samples applied together with linearProPhotoRGB destination color space):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Absolute Colorimetric&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ik2TL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ik2TL.jpg&quot; alt=&quot;ICC absolute colorimetric&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Legacy Unadapted Absolute Colorimetric&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vUR7g.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vUR7g.jpg&quot; alt=&quot;Legacy&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also realized that GIMP was actually restoring the original profile (not the opposite as I thought, i.e. instead of applying an embedded ICC profile, it was taking it off) and with this littlecms, now it does seem much simpler to &quot;translate&quot; color spaces than I thought.&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-16T18:15:33.757" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="274" PostTypeId="2" ParentId="271" CreationDate="2015-08-16T18:37:46.270" Score="8" Body="&lt;p&gt;There are many, many ways to draw things in OpenGL, so this is naturally confusing sometimes. The first method you describe, setting the shader parameters and issuing one draw call per object is usually the most inefficient, due to the high API overhead. The second one, using instanced drawing is a much smarter approach for objects with the same parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it comes to particles, specifically, there are two other methods which I'm aware of and have tested: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;The first one, more traditional and easier to implement, is to generate a unique quadrilateral for each particle in the application code. Then use one of the &lt;a href=&quot;https://www.opengl.org/wiki/Buffer_Object_Streaming&quot;&gt;several optimized buffer streaming&lt;/a&gt; paths of OpenGL to upload this data and issue a single draw call. This is the most straightforward method and provides good results. It will involve very few API calls if you can map the vertex/index buffers (&lt;code&gt;glMapBuffer/MapBufferRange&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Another method is to move the whole thing to a shader program, using &lt;a href=&quot;https://www.opengl.org/wiki/Transform_Feedback&quot;&gt;Transform Feedback&lt;/a&gt;. This method is a little more complicated to get up and running, but you can find a lot of references on the subject, &lt;a href=&quot;http://ogldev.atspace.co.uk/www/tutorial28/tutorial28.html&quot;&gt;such as this tutorial&lt;/a&gt;. This one should be the optimal path, since it moves the whole simulation to the GPU.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Those are some of the optimized ways of rendering particle effects. But OpenGL provides several other rendering paths that are better for different cases, one of such is &lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Rendering#Indirect_rendering&quot;&gt;indirect draw&lt;/a&gt;, which isn't available on ES at the moment, but is probably one of the fastest drawing paths available on modern PC OpenGL. Transform Feedback also requires a geometry shader, so it is not available for current OpenGL-ES.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more on the optimized rendering paths of OpenGL, I recommend watching this very good presentation by NVidia: &lt;a href=&quot;http://gdcvault.com/play/1020791/&quot;&gt;Approaching Zero Driver Overhead in OpenGL&lt;/a&gt;. At the end of the talk, they show a very interesting benchmark of several methods and how they compare with the Direct3D equivalents.&lt;/p&gt;&#xA;" OwnerUserId="54" LastActivityDate="2015-08-16T18:37:46.270" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="275" PostTypeId="2" ParentId="266" CreationDate="2015-08-17T00:31:23.877" Score="11" Body="&lt;p&gt;What you're talking about is commonly called &quot;dependent texture reads&quot; in the mobile development community. It's an implementation detail of certain hardware, and therefore it really depends on the GPU as to whether or not it has any performance implications. Typically it's something you see brought up for PowerVR GPU's in Apple hardware, since it was explicitly mentioned in both &lt;a href=&quot;http://cdn.imgtec.com/sdk-documentation/PowerVR.Performance%20Recommendations.pdf&quot;&gt;Imagination&lt;/a&gt; and &lt;a href=&quot;https://developer.apple.com/library/ios/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/BestPracticesforShaders/BestPracticesforShaders.html&quot;&gt;Apple&lt;/a&gt; documentation. If I recall correctly, the issue basically came from hardware in the GPU that would start to pre-fetch textures before the fragment shader even began running, so that it could do a better job of hiding the latency. The docs I linked mention that it's no longer an issue on Series6 hardware, so at least on newer Apple hardware it's not something that you have to worry about. I'm honestly not sure about other mobile GPU's, since that's not my area of expertise. You should try and consult their documentation to find out for sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you decide to do some Google searches on this issue, be aware that you'll probably find some older material that's talking about dependent texture fetches on older desktop hardware. Basic in the early days of pixel/fragment shaders, the term &quot;dependent texture fetch&quot; referred to using a UV address that relied on a previous texture fetch. The classic example was bump-mapped environment map rendering, where you wanted to use a reflection vector based on the normal map in order to sample the environment map. On this older hardware there was some major performance implications, and I think it wasn't even supported on some very old GPU's. With modern GPU's the hardware and the shader ISA is much more generalized, and so the performance situation is much more complicated. &lt;/p&gt;&#xA;" OwnerUserId="207" LastActivityDate="2015-08-17T00:31:23.877" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="276" PostTypeId="2" ParentId="246" CreationDate="2015-08-17T06:28:22.107" Score="4" Body="&lt;p&gt;See Kolb, et al., &lt;a href=&quot;http://www.cs.virginia.edu/~gfx/Courses/2003/ImageSynthesis/papers/Cameras/Realistic%20Camera%20Model.pdf&quot; rel=&quot;nofollow&quot;&gt;&lt;em&gt;A Realistic Camera Model for Computer Graphics&lt;/em&gt;&lt;/a&gt;, SIGGRAPH 95.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, do bear in mind that camera models which mimic real-world cameras aren't necessarily what you want for the rendering phase. In a visual effects/post-production scenario, the more blur/vignetting/distortion that the camera model introduces, the worse it is for the compositor/colour timer. It's often better to do it as a post-pass.&lt;/p&gt;&#xA;" OwnerUserId="159" LastEditorUserId="159" LastEditDate="2015-08-18T02:02:18.880" LastActivityDate="2015-08-18T02:02:18.880" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="277" PostTypeId="1" AcceptedAnswerId="289" CreationDate="2015-08-17T14:11:11.453" Score="9" ViewCount="1560" Body="&lt;p&gt;Applying multiple Gaussian blurs can result in an effect that is equivalent to a stronger Gaussian blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance this question says that: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/256/is-doing-multiple-gaussian-blurs-the-same-as-doing-one-larger-blur&quot;&gt;Is doing multiple Gaussian blurs the same as doing one larger blur?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wikipedia also says it, but says that it will always be just as many calculations or more to do it in multiple blurs versus doing it in a single blur.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Applying multiple, successive gaussian blurs to an image has the same effect as applying a single, larger gaussian blur, whose radius is the square root of the sum of the squares of the blur radii that were actually applied. For example, applying successive gaussian blurs with radii of 6 and 8 gives the same results as applying a single gaussian blur of radius 10, since \sqrt{6^2 + 8^2} = 10. Because of this relationship, processing time cannot be saved by simulating a gaussian blur with successive, smaller blurs — the time required will be at least as great as performing the single large blur.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Source: &lt;a href=&quot;https://en.wikipedia.org/wiki/Gaussian_blur#Mechanics&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Gaussian_blur#Mechanics&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I've heard and read about people doing multiple blurs in realtime graphics to achieve a stronger blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What benefit is there if it isn't a reduction in computation?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2018-06-01T23:44:06.937" Title="Why do multiple Gaussian Blurs?" Tags="&lt;real-time&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="278" PostTypeId="1" CreationDate="2015-08-17T16:09:06.873" Score="8" ViewCount="123" Body="&lt;p&gt;Intuitively, dust settles onto surfaces at a higher rate in areas where the air flow is slower. This means instead of a surface gathering an even layer of dust, there will be more in corners - corners of a room/shelf, corners formed by the placement of objects on a surface, concavities in a surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can get an increase in realism simply by making the thickness/density of dust reduce with distance from an object, and combine that effect for several objects including walls. This naturally gives the expected ordering of thicknesses - the edges of a floor have more dust than the centre, the corners where the edges meet have more dust then the centre of the edges. However, the increase in realism from getting the order correct still leaves the problem of getting the ratio right. There is more dust in the places you expect to have more dust, but not necessarily the right amount more.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an established method of approximating a realistic ratio of thickness between different points on a surface? I don't need this to be completely physically accurate (that would need to take into account objects that move through the environment during the long period taken for dust to accumulate). I'm just looking for average behaviour that will look believable to the human eye.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In searching online I've mostly found atmospheric models for suspended dust, rather than a way of modelling dust deposition on a surface.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;My attempts - linear and exponential distributions&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Here is some code in Python 3 using pillow (the PIL fork) that demonstrates a couple of distributions I have experimented with:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;from PIL import Image&#xA;from math import exp&#xA;&#xA;&#xA;def linear(distance, scale):&#xA;    return max(0, 64 - distance * scale)&#xA;&#xA;&#xA;def exponential(distance, scale):&#xA;    return 64 * exp(-distance * scale)&#xA;&#xA;&#xA;def exponential_squared(distance, scale):&#xA;    return 64 * exp(-distance * distance * scale)&#xA;&#xA;&#xA;def gamma_corrected(value):&#xA;    corrected_value = int((value/255)**(1/2.2)*255)&#xA;    return corrected_value&#xA;&#xA;&#xA;def produce_image(image_size=(1024,1024),&#xA;                  glasses=(((100,300),90),((300,300),110)),&#xA;                  distribution=exponential,&#xA;                  scale=0.1,&#xA;                  background_level=0,&#xA;                  gamma=2.2,&#xA;                  filename='dusttest.png'&#xA;                  ):&#xA;    width, height = image_size&#xA;    pixels = []&#xA;    for y in range(height):&#xA;        for x in range(width):&#xA;            red, green, blue = pixel_value(x, y, image_size, glasses,&#xA;                                           distribution, scale,&#xA;                                           background_level&#xA;                                           )&#xA;            pixels.append((red, green, blue))&#xA;&#xA;    image = Image.new('RGB', image_size, color=None)&#xA;    image.putdata(pixels)&#xA;    image.save(filename)&#xA;&#xA;&#xA;def pixel_value(x, y, image_size, glasses, distribution, scale,&#xA;                background_level&#xA;                ):&#xA;    width, height = image_size&#xA;    value = background_level&#xA;    value += distribution(x, scale)&#xA;    value += distribution(width-x, scale)&#xA;    value += distribution(y, scale)&#xA;    for glass in glasses:&#xA;        coords, radius = glass&#xA;        a, b = coords&#xA;        distance = ((x-a) ** 2 + (y-b) ** 2) ** 0.5 - radius&#xA;        if distance &amp;lt; 0:&#xA;            value = 0&#xA;            break&#xA;        value += distribution(distance, scale)&#xA;    value = 255 - gamma_corrected(value)&#xA;    return ((value, value, value))&#xA;&#xA;&#xA;if __name__ == '__main__':&#xA;    for scale in [0.1, 0.2, 0.4, 0.8]:&#xA;        produce_image(distribution=linear,&#xA;                      scale=scale,&#xA;                      background_level=20,&#xA;                      filename='linear-' + str(scale) + '-dusttest.png'&#xA;                      )&#xA;    for scale in [0.1, 0.05, 0.03, 0.01]:&#xA;        produce_image(distribution=exponential,&#xA;                      scale=scale,&#xA;                      background_level=0,&#xA;                      filename='exponential-' + str(scale) + '-dusttest.png'&#xA;                      )&#xA;    for scale in [0.01, 0.001, 0.0001, 0.00001]:&#xA;        produce_image(distribution=exponential_squared,&#xA;                      scale=scale,&#xA;                      background_level=0,&#xA;                      filename='exponential-squared-' + str(scale) + '-dusttest.png'&#xA;                      )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Imagine looking down from above on a white shelf that has had drinking glasses placed on it. Some time later the glasses are removed to leave dust free circular regions and a distribution of dust over the rest of the shelf. The dust is affected by the positions of the glasses and the back and side walls. The front of the shelf (bottom of the image) is open, with no wall to increase dust.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Output&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;(Click for larger images)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Linear reduction in dust density plus constant background level of dust:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4FtgD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4FtgDm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cnyaS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cnyaSm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/RXWlg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RXWlgm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/IgPu0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IgPu0m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Exponential reduction in dust density (zero background level):&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4Td7b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Td7bm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/KUdEn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KUdEnm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/hbgk3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hbgk3m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/X29hi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X29him.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I expected the exponential version to be closer to reality, and I prefer the result visually. However, I still don't know if this is close enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Following &lt;a href=&quot;https://computergraphics.stackexchange.com/users/56/alan-wolfe&quot;&gt;Alan Wolfe&lt;/a&gt;'s suggestion of the normal distribution, I've also added images using &lt;code&gt;exp(-distance ** 2)&lt;/code&gt; at a variety of scales.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/n1oOr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n1oOrm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2SJD9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2SJD9m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/LVfCg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LVfCgm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M0N8o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M0N8om.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I quite like this too, but I still couldn't guess which of this and exponential (&lt;code&gt;exp(-distance)&lt;/code&gt;) is best.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking for feedback in two ways:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Do any of these distributions look right/natural to you? I want input from a wider range of human eyes, ideally with specific problems/inconsistencies.&lt;/li&gt;&#xA;&lt;li&gt;Is there a physical interpretation that would justify using one of these distributions, or that would suggest a better one?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-18T18:22:01.660" Title="Is there an established method of approximating dust distribution on surfaces?" Tags="&lt;distribution&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="279" PostTypeId="2" ParentId="278" CreationDate="2015-08-18T05:30:15.183" Score="2" Body="&lt;p&gt;See the paper &lt;a href=&quot;http://dx.doi.org/10.1145/344779.344809&quot; rel=&quot;nofollow&quot;&gt;Computer Modelling of Fallen Snow&lt;/a&gt; published in SIGGRAPH 2000:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In this paper, we present a new model of snow accumulation and stability for computer graphics. Our contribution is divided into two major components, each essential for modelling the appearance of a thick layer of snowfall on the ground. Our accumulation model determines how much snow a particular surface receives, allowing for such phenomena as flake flutter, flake dusting and wind-blown snow. We compute snow accumulation by shooting particles upwards towards the sky, giving each source surface independent control over its own sampling density, accuracy and computation time. Importance ordering minimises sampling effort while maximising visual information, generating smoothly improving global results that can be interrupted at any point. Once snow lands on the ground, our stability model moves material away from physically unstable areas in a series of small, simultaneous avalanches. We use a simple local stability test that handles very steep surfaces, obstacles, edges, and wind transit. Our stability algorithm also handles other materials, such as flour, sand, and flowing water.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Its &lt;a href=&quot;http://www.cs.ubc.ca/nest/imager/contributions/fearing/snow/snow.html&quot; rel=&quot;nofollow&quot;&gt;project page&lt;/a&gt; contains explanations and example images. A PDF is &lt;a href=&quot;https://graphics.stanford.edu/courses/cs448-01-spring/papers/fearing.pdf&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An older paper is &lt;a href=&quot;http://www.cse.cuhk.edu.hk/~ttwong/papers/dust/dust.html&quot; rel=&quot;nofollow&quot;&gt;Simulating Dust Accumulation&lt;/a&gt;, published in &lt;em&gt;IEEE Computer Graphics &amp;amp; Applications&lt;/em&gt; in 1995:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;This paper describes a dust modeling technique. An empirical method is used to visually simulate the effect of dust accumulation on object surfaces. The dust amount is first predicted based on the properties of the surfaces: the surface inclination and stickiness. This predicted amount is then adjusted according to some external factors: surface exposure to wind and scraping off by other objects. The calculated dust amount is finally perturbed by a noise function on rendering to give a fuzzy visual effect.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="192" LastEditorUserId="192" LastEditDate="2015-08-18T18:22:01.660" LastActivityDate="2015-08-18T18:22:01.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="280" PostTypeId="1" AcceptedAnswerId="281" CreationDate="2015-08-18T08:24:37.133" Score="15" ViewCount="874" Body="&lt;p&gt;In general, branching in shaders is not a good idea. But now I have a shader with a condition that is constant with respect to the entire draw call. So the branch that is executed is always the same for one draw call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is such kind of branching still more costly than having multiple shaders without these branches and switch between them?&lt;/p&gt;&#xA;" OwnerUserId="386" LastEditorUserId="127" LastEditDate="2015-08-20T23:30:50.320" LastActivityDate="2016-01-21T10:12:02.363" Title="Is a constant condition more costly than switching shaders?" Tags="&lt;performance&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="10" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="281" PostTypeId="2" ParentId="280" CreationDate="2015-08-18T09:16:17.933" Score="13" Body="&lt;p&gt;On modern hardware if all invocations in a group follow the same path then the unused path doesn't get evaluated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;in pseudo code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(cond){&#xA;   res = ...&#xA;}else{&#xA;   res = ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;becomes&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(anyInvocationARB(cond)){&#xA;    res1 = ...&#xA;}&#xA;if(anyInvocationARB(!cond)){&#xA;    res2 = ...&#xA;}&#xA;res = cond?res1:res2;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;anyInvocationARB&lt;/code&gt; will be true if any invocation of the shader will have true as &lt;code&gt;cond&lt;/code&gt; (from the opengl extension &lt;a href=&quot;https://www.opengl.org/registry/specs/ARB/shader_group_vote.txt&quot; rel=&quot;nofollow&quot;&gt;ARB_shader_group_vote&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If cond is derivable from uniforms alone then the driver may optimize and evaluate the condition before starting the render and replace the if with a goto to the correct branch. OpenGL has a feature called uniform subroutines that makes it explicit.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2016-01-21T10:12:02.363" LastActivityDate="2016-01-21T10:12:02.363" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="283" PostTypeId="1" CreationDate="2015-08-18T17:52:08.047" Score="15" ViewCount="381" Body="&lt;p&gt;&lt;em&gt;I'm interested in how this applies to higher numbers of dimensions too, but for this question I will focus solely on 2D grids.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I know that Perlin noise is not isotropic (direction invariant), and that the underlying square grid shows up enough to be able to identify its orientation. Simplex noise is an improvement on this but its underlying equilateral triangle grid is still not completely obscured.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My intuition is that any attempt to make noise of a particular frequency on a grid will result in a lower frequency in directions not aligned to the grid. So while attempts can be made to disguise this, the noise cannot in principle be isotropic unless it is generated without reference to a grid, allowing the average frequency to be the same in all directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, with a square grid without noise, with square side length $n$, the frequency of vertices horizontally or vertically is $\frac1n$, whereas the frequency of vertices at 45 degrees (through opposite corners of the squares) is $\frac1{\sqrt{2}n}$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Uzc5Y.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Uzc5Y.png&quot; alt=&quot;Square grid showing length of edge and diagonal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a random distribution that could be applied to offset the vertex positions that would result in the frequency becoming identical in all directions? My suspicion is that there is no such distribution, but I don't have a way of proving either way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, is there a way of making perfect grid based noise of a given frequency, or should I be focused on other approaches (non-grid based noise or ways of disguising artifacts)?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="137" LastEditDate="2015-11-03T14:48:52.220" LastActivityDate="2015-11-03T14:48:52.220" Title="Is all grid based noise inevitably anisotropic?" Tags="&lt;noise&gt;&lt;grid&gt;" AnswerCount="1" CommentCount="11" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="284" PostTypeId="1" AcceptedAnswerId="290" CreationDate="2015-08-19T11:08:31.647" Score="6" ViewCount="1295" Body="&lt;p&gt;Suppose we already have UV coordinates assigned for mesh vertices,&#xA;how is texture baking implemented?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess it will be something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for each coordinate (u, v) in parameter space:&#xA;    (x, y, z) = inverse(u, v) # Get the geometric space coordinate.&#xA;    f = faces(x, y, z) # Get the corresponding face. We may need face's normal for rendering.&#xA;    pixels[u, v] = render(x, y, z, f)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What is the &lt;code&gt;inverse&lt;/code&gt; function? Is it a projective transformation, or a bilinear transformation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And how to get the corresponding face of one coordinate (u, v) efficiently?&lt;/p&gt;&#xA;" OwnerUserId="120" LastActivityDate="2015-08-20T05:53:23.373" Title="How is texture baking implemented?" Tags="&lt;rendering&gt;&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="285" PostTypeId="2" ParentId="284" CreationDate="2015-08-19T14:31:40.733" Score="1" Body="&lt;p&gt;The inverse coordinate is not entirely trivial in all cases. But basically, for a basic triangle mesh with nothing exotic and has non overlapping UV's, you need something like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;For the UV coordinate you need to find the corresponding  UV triangle. (step can be eliminated see below)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Then calculate the barycentric triangle coordinate. Most raytracers have simple implementations for this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;From bary coordinate  to 3d its just&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;b1*p1_3d + b2*p2_3d+ b3*p3_3d&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where b are barycentric cords from step 2. and p's triangle point vectors&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h2&gt;How to accelerate the triangle finding.&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;You can do a a sweeping search in O(log(n)) time. You can also use a a bsp tree to do much the same. This would produce a  O(m*log(n)) algorithm where m is number of samples and n triangles. Sounds good.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Wait&lt;/strong&gt;, we can do better! What if instead of baking each pixel in order we bake each triangle in order. Then you dont have to go find the triangle. Finding the points in a triangle should be trivial. So you get something more akin to a theoretical O(m) algorithm. Which should be both conceptually easier and at least theoretically faster as you eliminate step 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also in the second case you can forego barycentric calculation if you so wish and use an alternate formulation if you wish.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5FXdd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5FXdd.png&quot; alt=&quot;Sweeping one polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Sweeping one polygon at a time is easier and needs not search for polygon in question.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-19T19:29:59.697" LastActivityDate="2015-08-19T19:29:59.697" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="286" PostTypeId="1" AcceptedAnswerId="303" CreationDate="2015-08-19T14:36:39.547" Score="7" ViewCount="1320" Body="&lt;p&gt;I was looking into ways to implement multiple lights shading and I've noticed &lt;a href=&quot;http://docs.unity3d.com/Manual/RenderTech-ForwardRendering.html&quot;&gt;Unity uses multiple passes to achieve it&lt;/a&gt;. It performs a base pass to apply the brightest directional pixel light + 4 vertex lights + SHs and an additional pass for each pixel light, up to a limit defined by the user on the editor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm wondering, since I previously know how many pixels lights I need to shade, why not doing it in a single pass like vertex lights are done? What are the problems of doing so?&lt;/p&gt;&#xA;" OwnerUserId="250" LastEditorUserId="54" LastEditDate="2015-08-19T17:39:10.050" LastActivityDate="2015-08-21T10:07:42.677" Title="Multiple Lights Shading - One Pass vs Multiple Passes" Tags="&lt;lighting&gt;&lt;shader&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="287" PostTypeId="1" AcceptedAnswerId="348" CreationDate="2015-08-19T22:52:54.560" Score="12" ViewCount="1001" Body="&lt;p&gt;I understand how a 1D Fourier transform separates a signal into its component frequencies, but I'm having difficulty understanding how a 2D Fourier transform affects a 2D image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/283/is-all-grid-based-noise-inevitably-anisotropic&quot; title=&quot;Is all grid based noise inevitably anisotropic?&quot;&gt;another question&lt;/a&gt;, &lt;a href=&quot;https://computergraphics.stackexchange.com/users/196/john-calsbeek&quot;&gt;John Calsbeek&lt;/a&gt; linked to an &lt;a href=&quot;http://www.cs.utah.edu/~aek/research/noise.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;interesting paper about measuring the quality of noise functions&lt;/a&gt;. This showed various noise functions and the Fourier transform of each.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this a discrete transform of the pixel data, or a continuous transform of the continuous interpolating function which is used to generate the noise at arbitrary points?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the annular shape analagous to taking 1D Fourier transforms of the line through the centre of the image at every possible angle? Or is the transform for each possible angle also measured across the whole 2D space rather than only along a line through the centre? I'm trying to get an intuitive feel for what changes in the input image correspond to what changes in the Fourier transform.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-11-03T19:18:26.903" Title="How does a 2D Fourier Transform of an image work?" Tags="&lt;noise&gt;&lt;fourier-transform&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="289" PostTypeId="2" ParentId="277" CreationDate="2015-08-20T05:35:41.600" Score="14" Body="&lt;p&gt;There are two cases I can think of where multiple blurs would be performed in succession on a single image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, when performing a large-radius blur, it may reduce the total computation if you first downsample the image (which is a blur) and then perform a smaller-radius blur on the downsampled image.  For example, downsampling an image by 4x and then performing a 10px-wide Gaussian blur on the result would approximate performing a 40px-wide Gaussian blur on the original&amp;mdash;but is likely to be significantly faster due to improved locality in sampling and fewer samples taken overall.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/ugYom.png&quot; alt=&quot;Box approximation of a wide Gaussian&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The initial downsampling filter is often simply a box (as shown above), but it can also itself be something more sophisticated, such as a triangle or bicubic filter, in order to improve the approximation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/xdbOo.png&quot; alt=&quot;Mitchell-Netravali approximation of a wide Gaussian&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a Mitchell-Netravali (cubic) downsample followed by a Gaussian. Interestingly, it turns out that using a Gaussian for the initial downsampling doesn't make such a great approximation if your goal is to use it to produce a larger Gaussian.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An initial downsampling step is also frequently used when implementing visual effects like depth of field and motion blur, for similar reasons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A second reason to perform multiple Gaussian blurs is to approximate a non-separable filter by blending between various Gaussians of different radii.  This is commonly used in bloom, for example.  The standard bloom effect works by first thresholding to extract bright objects from the image, then creating several blurred copies of the bright objects (usually using the downsample-then-blur technique just discussed), and finally weighting and summing them together.  This allows artists a greater level of control over the final shape and appearance of the bloom.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZzS3i.png&quot; alt=&quot;Sum of three Gaussians creates a &amp;quot;heavy-tailed&amp;quot; function&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here, for example, is a weighted sum of three Gaussians (red line) which produces a shape that's more narrowly peaked and heavier-tailed than a single Gaussian (blue line).  This is a popular sort of configuration to use for bloom, as the combination of a narrow, bright center with a wide, diffuse halo is visually appealing.  But since this kind of filter shape isn't separable, it's cheaper to make it out of a mixture of Gaussians than to try to filter with it directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another variation on this idea is the concept of a diffusion profile used with subsurface scattering for skin rendering. Different blur radii may be used for the red, green, and blue channels to approximate the way different wavelengths of light scatter differently, as in &lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch14.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;GPU Gems 3 skin shading chapter&lt;/a&gt; by Eugene d'Eon and Dave Luebke.  In fact, that paper uses a mixture of seven different Gaussians, with different R, G, and B weights for each, to approximate the complicated non-separable, wavelength-dependent scattering response of human skin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch14.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YYAga.jpg&quot; alt=&quot;Diffusion profiles from GPU Gems 3 article on skin shading&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2018-06-01T23:44:06.937" LastActivityDate="2018-06-01T23:44:06.937" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="290" PostTypeId="2" ParentId="284" CreationDate="2015-08-20T05:53:23.373" Score="5" Body="&lt;p&gt;Texture baking can be accomplished by simply rendering the mesh in texture space.  In other words, you set up a render target matching the size of your texture, and draw the mesh with a vertex shader that sets the output position to the vertex's UV coordinate (appropriately remapped from [0, 1] UV space to [&amp;minus;1, 1] post-projective space).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vertex shader can still calculate the world-space position, normals, and whatever else it needs and send those down to the pixel shader.  Then the pixel shader can do its thing without even being aware that it's rendering into texture space instead of the usual screen space.  Lighting and shading calculations will work as usual as long as the pixel shader inputs are hooked up correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You don't have to do any complicated inversion operation; you just take advantage of the GPU rasterization hardware, which is happy to draw your triangles at any coordinates you choose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Naturally, this requires that your mesh already has a non-overlapping UV mapping that fits within the unit square, but texture baking doesn't really make sense without that.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-20T05:53:23.373" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="291" PostTypeId="2" ParentId="57" CreationDate="2015-08-20T07:48:41.177" Score="2" Body="&lt;p&gt;The following naïve approach will probably not yield as nicely distributed points as the &lt;a href=&quot;https://computergraphics.stackexchange.com/a/251/394&quot;&gt;ones given by Lhf&lt;/a&gt;, but it should be much easier to implement and computationally faster:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For two points $x$ and $y$ let $d(x,y)$ denote the average distance you want points with the average curvature of $x$ and $y$ to have, e.g., some constant multiplied with the inverse of the average curvature of $x$ and $y$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now build up your collection of points $A$ successively:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Select a random point $x$ and add two points, such that all three points form a equilateral triangle with edge length $d(x,x)$.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Add all points to $A$ and mark them as adjacent.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Repeatedly do the following until there are no adjacencies in $A$ anymore:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Select two adjacent points $x$ and $y$ from $A$. Mark them as non-adjacent.&lt;/li&gt;&#xA;&lt;li&gt;Consider a point $z$ that has a distance of $d(x,y)$ from both these points. Of the two possible such points select the one pointing outwards of $A$ (this needs some work, but should be straightforward).&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Check whether $z$ is closer than $d(x,y)$ to any point from $A$ that is still adjacent to another point.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;if yes, discard it.&lt;/li&gt;&#xA;&lt;li&gt;if no, mark $x$ and $z$ as well as $y$ and $z$ as adjacent and add $z$ to $A$.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;At the end, $A$ should be a collection of points matching your criteria. You sort-of just created a triangulation but it may be pathological and thus you should probably triangulate the points afresh.&lt;/p&gt;&#xA;" OwnerUserId="394" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-11-03T17:35:30.317" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="292" PostTypeId="1" CreationDate="2015-08-20T10:52:25.733" Score="6" ViewCount="535" Body="&lt;p&gt;I don't know any shader languages. I've heard of GLSL and HLSL, and I'm interested in learning one or both.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there significant differences between them that would make one or other better in certain situations? Is it useful to know both or would either cover most needs?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't want vague answers indicating personal preference. I'm looking for specific measurable differences so that I can decide for myself which will suit me best. I don't have a specific task in mind - I'm hoping to discover whether there is one or other that I can learn and then apply to any future tasks, rather than having to learn a new language for each new task.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there are other shader languages which I have not mentioned I would be interested to hear the comparison for those too, provided they are not dependent on any particular GPU manufacturer. I want my code to be portable across different graphics cards.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-20T18:34:36.977" Title="What factors affect which shader language to learn?" Tags="&lt;gpu&gt;&lt;glsl&gt;&lt;shader&gt;&lt;hlsl&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="293" PostTypeId="2" ParentId="292" CreationDate="2015-08-20T11:02:54.187" Score="7" Body="&lt;p&gt;The shader language is bound to the APIs/engines that support it (glsl to openGL &amp;amp; WebGL and hlsl to D3D). There are tools to translate from one to the other but they aren't perfect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means the main reason to pick one over the other is which platform you will be working on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However by the end of the year a new binary shader representation will come out called Spir-V designed for Vulkan and an OpenGL extension for it is expected to follow shortly. This will allow you to write shaders in many languages as long as a translation tool to Spir-V exists (several are in the works including a Python and Haskell tool).&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-08-20T11:02:54.187" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="295" PostTypeId="1" CreationDate="2015-08-20T11:42:45.213" Score="11" ViewCount="1748" Body="&lt;p&gt;Are the differences between these two APIs minor implementation details that mean once I have learned one I can use it for everything? Or are there reasons for learning one rather than the other if I want to be able to use it in general without having to relearn another API in future? Is one or other more general?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particular I would like to be able to write for any graphics card, so code is not restricted to only running on a particular manuafacturer's cards or a specific model. I'd also like to be able to write code that still works in the absence of a graphics card (albeit slower).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a difference in how portable code will be across different platforms (operating systems/architectures)? I'm interested in the availability of other libraries that work with these, and whether one or the other leads to fewer licensing restrictions in its wider environment. Anything measurable that would make a difference to whether one of these could be the only one I learn without restricting me.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-05-30T17:48:43.137" Title="Does it matter whether I learn OpenGL or Direct3D?" Tags="&lt;opengl&gt;&lt;api&gt;&lt;direct3d&gt;" AnswerCount="4" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="296" PostTypeId="2" ParentId="295" CreationDate="2015-08-20T13:41:44.590" Score="9" Body="&lt;p&gt;I don't think it matters much, which API you want to use when leaning to &quot;program graphics&quot;. The more important things to learn are the typical concepts you use when working with 3D scenes. For example you want to learn how to write a simple (and later more sophisticated) Scene Graph. These concepts are much more important than the specific API method names you have to call. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compare it when learning how to write programs. If you are quite good at writing programs in e.g. Java, you won't have that much trouble learning C++, Objective-C, Swift, or some other object-oriented language. Because it's the concepts and the &lt;em&gt;thinking&lt;/em&gt; which you learn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The choice between OpenGL, Direct3D and Metal is primarily the choice, which operating system you target. Direct3D is primarily available on Windows, Metal on OS X and iOS, and OpenGL is supported on most systems including OS X, iOS, Windows and Linux.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The graphics card probably has little to no influence on this decision as I don't know a card that supports only one or two. If you have no dedicated graphics card, then rendering in real time will be a problem soon. Although a Intel HD Graphics and the AMD companion can already do quite much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, choose your platform.&lt;/p&gt;&#xA;&#xA;&lt;hr /&gt;&#xA;&#xA;&lt;p&gt;Disclaimer: As of now, I did neither use Direct3D nor Metal.&lt;/p&gt;&#xA;" OwnerUserId="127" LastActivityDate="2015-08-20T13:41:44.590" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="297" PostTypeId="1" AcceptedAnswerId="414" CreationDate="2015-08-20T14:20:02.697" Score="11" ViewCount="793" Body="&lt;p&gt;When I implement Beer's law (color absorption over distance through an object), it never looks very good for some reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When i have the color behind the object, I calculate the adjusted color like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const vec3 c_absorb = vec3(0.2,1.8,1.8);&#xA;vec3 absorb = exp(-c_absorb * (distanceInObject));&#xA;behindColor *= absorb;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That will give me something that looks like this (note a little bit of refraction applied):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XQbjV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XQbjV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here it is without refraction:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/gOPZn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gOPZn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this is implemented as a shader toy &lt;a href=&quot;https://www.shadertoy.com/view/4lXSDf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That fulfills the description of what Beer's law does, but it doesn't look very good, not when compared to shots like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nchoX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nchoX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specular highlights aside, I'm trying to figure out the difference.  Could it just be that my geometry is too simple to really show it off very well? Or am I implementing it incorrectly?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="171" LastEditDate="2017-05-19T08:22:41.087" LastActivityDate="2017-05-19T08:22:41.087" Title="Is this the correct way to implement Beer's Law?" Tags="&lt;3d&gt;&lt;refraction&gt;&lt;transparency&gt;" AnswerCount="1" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="298" PostTypeId="2" ParentId="295" CreationDate="2015-08-20T14:31:24.183" Score="9" Body="&lt;p&gt;We are currently in a transition of API paradigms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The old school method of binding buffers, uniforms, attribute, layout and programs as (implicit) global state and dispatching draws with that state is common across D3D11 and OpenGL. However it has a large amount of overhead (in verifying state and not knowing what the program wants to do until the last minute). They are also not thread safe (for the most part).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why new apis have come up (or are coming soon) D3D12, vulkan and Metal being the most prominent. These APIs give more control to the program and lets it declare in advance what it want to do using command buffers. They also let you manage your own resources (vertex data, textures, ...) much more directly. Using them with multiple is much more straight forward.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The choice between old and new is based on how well you can manage the video memory you allocate and build the command buffer. &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;If you want something that &quot;just works&quot; even on older hardware then the old school APIs are better; they also are better known and you will get more help on them online.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;On the other hand if you can handle the asynchronous nature of dispatching commands and don't mind having to track all the buffers you allocate. Then the new APIs may be something for you. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-08-20T14:31:24.183" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="299" PostTypeId="2" ParentId="292" CreationDate="2015-08-20T15:55:56.167" Score="4" Body="&lt;p&gt;The HLSL shader language is used in DirectX family APIs and GLSL for the OpenGL family APIs. This means that the choice of graphics API will limit the shader language as well, so if cross platform is a concern then GLSL will be the choice. However, this comes with some caveats as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One difference is that in OpenGL the shading language is compiled on driver level, this means that the binary representation is not stable and can change with driver updates. In HLSL it is compiled to a hardware independent representation that can be used on multiple GPUs. This should really be a problem for writing shaders, but it sometimes means that certain things work different with other drivers and especially operating systems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another thing to take note is that OpenGL features extensions, these can be enabled inside GLSL to utilize extra functionality. With newer OpenGL versions some of these extensions might be added to the core profile. Vendors then have to implement these extensions to be compliant, which sometimes results in things working different. The HLSL shading language syntax only changes with new introduction of DirectX APIs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some syntactic differences are that HLSL can use #include, in GLSL this is not default. When searching for GLSL tutorials you might find different syntax, because it has changed quite a lot as of OpenGL 3 and 4. GLSL shaders have a void main() as shader entry point. In HLSL this entry point can be named and have input (vertex data) and output (pixel shader input).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Learning either of these will introduce you to some common ground which will make it easy to learn to other one. HLSL is more standardized, but it also only works on a single operating system. There are also other attempts of shader languages that compile to both OpenGL and DirectX, one example is &lt;a href=&quot;https://developer.nvidia.com/cg-toolkit&quot; rel=&quot;nofollow&quot;&gt;Cg&lt;/a&gt; which is deprecated by now. Many game engines (Unity, Unreal Engine) also have their own flavors, but their syntax is like HLSL or GLSL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As already mentioned Vulkan will introduce an open intermediate language representation called Spir-V. This means that if a language can be compiled to this representation it can be used to write shaders.&lt;/p&gt;&#xA;" OwnerUserId="64" LastEditorUserId="64" LastEditDate="2015-08-20T18:34:36.977" LastActivityDate="2015-08-20T18:34:36.977" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="300" PostTypeId="1" AcceptedAnswerId="304" CreationDate="2015-08-20T17:35:29.830" Score="5" ViewCount="67" Body="&lt;p&gt;Imagine you have a 3D level format consisting of an arbitrary number of convex polytope brushes (or we can simplify and consider just oriented-bounding boxes) and several point entities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to find an algorithm to determine&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If the level is water-tight. That is, the brushes are adjacent to each other and fit together to form a hull without gaps or holes.&lt;/li&gt;&#xA;&lt;li&gt;If the level is disjoint, identify the set of brushes in each section.&lt;/li&gt;&#xA;&lt;li&gt;If all entities are inside the water-tight level, and in which section (from (2)) they are in.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;(1) isn't strictly necessary, but it seems necessary to ensure that (2) and (3) are well defined.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All engines I know that use this kind of level format (Doom, Quake, Source) seem to use a BSP algorithm for these tasks. However, they also use the resulting BSP tree as an acceleration structure for rendering, which I'm not interested in using.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is anyone aware of any other possible alternative algorithms, or is BSP the only choice?&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-08-20T18:02:34.843" LastActivityDate="2015-08-20T20:45:56.550" Title="Determining level connectivity" Tags="&lt;space-partitioning&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="301" PostTypeId="1" AcceptedAnswerId="302" CreationDate="2015-08-20T18:41:21.510" Score="6" ViewCount="119" Body="&lt;p&gt;Why do we not calibrate all devices to sRGB in the factory? The assumption is that every monitor is sRGB anyway. So why not calibrate them to that? That would make people see same color as intended on a wide range of devices.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-08-21T06:22:23.667" Title="Why not calibrate all display devices to sRGB?" Tags="&lt;color-management&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="302" PostTypeId="2" ParentId="301" CreationDate="2015-08-20T19:05:38.003" Score="6" Body="&lt;p&gt;Simple answer: because it costs. :) Some higher-end monitor models &lt;em&gt;are&lt;/em&gt; indeed calibrated at the factory (and come with a calibration report sheet) but it would not be cost-effective to do so for all models in the product line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Color reproduction varies even between batches of the exact same panel model, so it isn't possible to just use a set calibration for a given monitor model, it need to be done on a unit-by-unit basis. So to save costs, they instead determine the color reproduction curves of the &quot;average&quot; panel and use that for an ok but inconsistent result.&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-08-20T19:42:59.837" LastActivityDate="2015-08-20T19:42:59.837" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="303" PostTypeId="2" ParentId="286" CreationDate="2015-08-20T20:34:15.230" Score="2" Body="&lt;p&gt;It's completely possible to do all pixel lights in the fragment shader (or, say, do 4 at a time) by looping over an array. However, this comes at a great performance cost: You're going to be calculating lighting for every light on every fragment of the scene, even if that geometry isn't actually affected by the light's influence.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect that is reason why Unity doesn't do so: it probably culls the objects and submits only geometry that might be influenced by the respective light on each pass, meaning that shading for a light is only evaluated in the fragments where it may have an effect. This is a trade off between processing less fragments but duplicating the geometry cost.&lt;/p&gt;&#xA;" OwnerUserId="327" LastActivityDate="2015-08-20T20:34:15.230" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="304" PostTypeId="2" ParentId="300" CreationDate="2015-08-20T20:45:56.550" Score="2" Body="&lt;p&gt;BSP is a classic for computational geometry tasks involving polygons. However, polygonal meshes are subject to a dismaying list of pathologies such as degenerate polygons, inconsistent winding order, T-junctions, coincident vertices, cracks or holes, self-intersecting geometry, loss of coplanarity or collinearity due to roundoff error, and other such things. Making computational geometry robust on arbitrary polygon meshes is Quite Difficult™.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It worked in Doom/Quake/Half-Life days because the base level geometry (made of brushes and constructed in a level editor, as opposed to a 3D modeling tool), was relatively simple, mostly axis-aligned, and all vertices were snapped to grids. More recently, the trend seems to be for level design seems to be done by creating mesh pieces in 3D modeling tools, then sticking together a bunch of instances of them to form a level. This kind of construction is a &lt;em&gt;lot&lt;/em&gt; less friendly to BSP-type algorithms&amp;mdash;especially as the geometric complexity rises.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An alternative approach for connectivity questions is voxelization. In short, you voxelize all your level geometry at some reasonably small resolution, like 10&amp;ndash;30 cm per voxel or so. The voxelization wipes away any geometric errors smaller than the voxel size, and it gets rid of all those annoying pathologies mentioned earlier. You can use an octree or brickmap etc. to avoid voxelizing empty space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have the voxel representation of the level, you can then do all sorts of connectivity queries on it very easily because of the regular structure of the voxels. For instance, determining if a level is watertight or finding connected-components at the voxel level is basically a flood-fill. These kinds of algorithms can also be done hierarchically using the octree etc. to avoid the expense of a global flood-fill over a huge number of voxels. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more reading, there was a 2011 SIGGRAPH talk &lt;a href=&quot;http://advances.realtimerendering.com/s2011/Chen,%20Silvennoinen,%20Tatarchuk%20-%20Polygon%20Soup%20Worlds%20(Siggraph%202011%20Advances%20in%20Real-Time%20Rendering%20Course).pptx&quot; rel=&quot;nofollow&quot;&gt;Making Game Worlds From Polygon Soup&lt;/a&gt;, from some engineers at Bungie who used voxelization techniques on Halo Reach levels to build nav meshes, precompute visibility cells and portals, and so on.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-20T20:45:56.550" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="305" PostTypeId="1" AcceptedAnswerId="307" CreationDate="2015-08-20T20:49:17.700" Score="12" ViewCount="3416" Body="&lt;p&gt;Rendering the scene usually involves more than one shader program which, in my case, all use the same attributes and share at least some of the uniforms. To have them working properly, I currently play safe, meaning I rebind the attributes and get the appropriate uniform locations every time I switch between shader programs. So basically multiple times in every frame, which is probably not the best approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is it (in general) necessary to rebind attributes and uniforms after switching shader programs? And why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so, is there a way to do this once at start of the program and never have to touch them again (except for setting the uniform values)?&lt;/p&gt;&#xA;" OwnerUserId="127" LastActivityDate="2015-08-20T22:56:54.543" Title="Do I need to rebind uniforms or attributes when changing shader programs?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="306" PostTypeId="1" AcceptedAnswerId="316" CreationDate="2015-08-20T21:04:22.240" Score="50" ViewCount="21264" Body="&lt;p&gt;Signed Distance Fields (SDFs) was presented as a fast solution to achieve resolution independent font rendering by Valve &lt;a href=&quot;http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&quot;&gt;in this paper&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already have the Valve solution working but I'd like to preserve sharpness around corners. Valve states that their method can achieve sharp corners by using a second texture channels ANDed with the base one, but lacks to explain how this second channel would be generated. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact there's a lot of implementation details left out of this paper. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to know if any of you could point me out a direction to get SDFs font rendering with sharp corners.&lt;/p&gt;&#xA;" OwnerUserId="250" LastActivityDate="2018-03-25T18:41:47.993" Title="Sharp Corners with Signed Distance Fields Fonts" Tags="&lt;texture&gt;&lt;signed-distance-field&gt;&lt;font-rendering&gt;" AnswerCount="5" CommentCount="5" FavoriteCount="42" ContentLicense="CC BY-SA 3.0" />
  <row Id="307" PostTypeId="2" ParentId="305" CreationDate="2015-08-20T21:17:33.460" Score="13" Body="&lt;p&gt;You don't need to rebind the attributes, so long as you ensure that their location stays the same in both shaders. (Usually using the &lt;code&gt;layout(location = X)&lt;/code&gt; syntax in GLSL, but can also be done with &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glBindAttribLocation.xhtml&quot;&gt;&lt;code&gt;glBindAttribLocation&lt;/code&gt;&lt;/a&gt; if former is not available.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniforms, however, are part of the Shader Object state, and so will need to be set at least once for every shader. One way to minimize the cost of this is to use a &lt;a href=&quot;https://www.opengl.org/wiki/Uniform_Buffer_Object&quot;&gt;Uniform Buffer Object&lt;/a&gt;, which will contain all your uniform values and can then be bound to a shader with a single call.&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-08-20T22:56:54.543" LastActivityDate="2015-08-20T22:56:54.543" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="308" PostTypeId="2" ParentId="301" CreationDate="2015-08-21T06:16:49.357" Score="0" Body="&lt;p&gt;There are 2 major factor to this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While it would certainly be possible to calibrate or profile each screen this would add cost to the process. Most users simply aren't that sensitive to this issue so it makes no economic sense to do so. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Its also worth noting that color reproduction is a function of several factors. Such as panel use age, operating temperature etc., but also ambient surroundings. So while this could be done it would be less than stellarly useful for the user in the long run, unless they operate in standardized lighting conditions and never use the monitor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Certainly there is value in factory calibration. It simply means that the monitor can be calibrated to sRGB. And in some usecases the drift caused by age is acceptable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second problem is that is not technically desireable for the panel manufacturers. Forcing something like this on the manufacturers would be a bit like telling people that the the only graphics available graphics api from now on is opengl 2.0 no innovation allowed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Business dictates that the manufacturers need to be able to innovate. Calibrating everything to sRGB would slow down development of panels that are significantly bettter in gamut than sRGB to evolve. Second not all display panels can reach sRGB. Developping ultra cheap panels also has a market function. No need to restrict innovation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Calibrating to sRGB would ultimately not solve all color problems. Convoluted profile to profile conversions would still &#xA;be needed. Display panels are precicion instruments and need to be handled like that if accuracy is drsired. If not then no big deal.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-21T06:22:23.667" LastActivityDate="2015-08-21T06:22:23.667" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="309" PostTypeId="1" CreationDate="2015-08-21T07:04:56.937" Score="8" ViewCount="1189" Body="&lt;p&gt;I'm trying to figure out what the best way is to generate an OpenGL texture using a compute shader. So far, I've read that pixel buffer objects are good for non-blocking CPU -&gt; GPU transfers, and that compute shaders are capable of reading and writing buffers regardless of how they're bound. Ideally, I'd like to avoid as many copies as possible. In other words, I'd like to allocate a buffer on the GPU, write compressed texture data to it, and then use that buffer as a texture object in a shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, my code looks something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint buffer;&#xA;glGenBuffers(1, &amp;amp;buffer);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);&#xA;glBufferStorage(GL_SHADER_STORAGE_BUFFER, tex_size_in_bytes, 0, 0);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);&#xA;&#xA;// Bind buffer to resource in compute shader&#xA;// execute compute shader&#xA;&#xA;glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);&#xA;glCompressedTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, tex_size_in_bytes, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is this correct? I read somewhere about guaranteeing synchronization, too. What do I need to add to make sure that my compute shader completes execution prior to copying from the buffer object?&lt;/p&gt;&#xA;" OwnerUserId="197" LastEditorUserId="48" LastEditDate="2015-08-21T18:33:30.647" LastActivityDate="2015-09-19T01:13:41.147" Title="Writing to a compressed texture using a compute shader, with no extra copies" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;compression&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="310" PostTypeId="2" ParentId="286" CreationDate="2015-08-21T10:07:42.677" Score="1" Body="&lt;p&gt;If you would do all lights in a single pass then you would need to loop over all lights in the shader. You would also need to get all information to the GPU at the same time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPUs are limited in the number of uniforms you can pass into an invocation. This limitation has lessened with UBOs and SSBOs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However you are still limited with how many textures you can bind for shadow mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lights often only affect a small portion of the screen so the engine may only render geometry that is close to the light or adjust the viewport to only render the area the light would affect.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-08-21T10:07:42.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="311" PostTypeId="1" CreationDate="2015-08-21T13:02:45.887" Score="8" ViewCount="84" Body="&lt;p&gt;Although simulation models like &lt;a href=&quot;https://en.wikipedia.org/wiki/Boids&quot;&gt;Boids&lt;/a&gt; give good results for bird flocks or fish shoals on a small scale, simulating every single member in real time becomes unrealistic for huge numbers. Is there a way I can model a flock in the distance where only the density of birds is visible? I'd like to have that flowing, changing density gradient with a much smaller number of variables to process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried using a much smaller population and displaying each boid as a blurred area with Gaussian density so that as they overlap the density rises and falls through their interaction. This is reasonably cheap but it never leads to sharp changes in density, either spatially or temporally, which makes it look too uniform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any other way of getting away with a much smaller number of individuals? Or is the only way to get realistic results to prerender?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-22T08:02:39.787" Title="Is there a way to achieve the look of a distant flock or shoal without full simulation?" Tags="&lt;real-time&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="312" PostTypeId="1" AcceptedAnswerId="313" CreationDate="2015-08-21T14:51:37.063" Score="17" ViewCount="491" Body="&lt;p&gt;In most text books that I have seen, this is how the rendering equation is written:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_0( \omega_0)= L_e(\omega_0)+\int_{\Omega}{f(\omega_i, \omega_0)L_i(\omega_i)\,\mathrm{d}\omega_i}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $\Omega$ is defined to be a hemisphere (and all those functions depend on more variables, omitted here for simplicity's sake).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now suppose the surface being rendered is some kind of glass, or some transparent plastic. Why would it make sense to only integrate over a hemisphere? I would imagine that there can be incoming light from any direction, and thus the integration domain should be the entire sphere. How is the light coming from behind the glass accounted for?&lt;/p&gt;&#xA;" OwnerUserId="433" LastEditorUserId="137" LastEditDate="2015-11-03T17:35:49.767" LastActivityDate="2015-11-03T17:35:49.767" Title="Why integrate over a hemisphere (and not a sphere) to solve the rendering equation?" Tags="&lt;transparency&gt;&lt;theory&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="313" PostTypeId="2" ParentId="312" CreationDate="2015-08-21T15:11:24.357" Score="20" Body="&lt;p&gt;The form of the rendering equation that uses only the BRDF ($f$ in your example, often called $f_r$) and integrates over one hemisphere does not account for transmission.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When adding in transmission, it's fairly common to add a second integral over the opposite hemisphere, using a different BTDF function (bidirectional &lt;em&gt;transmission&lt;/em&gt; distribution function). This is equivalent to an integral over the full sphere of directions with a BSDF function, but since that function would usually have to be defined as a piecewise function, writing it as two integrals can be more straightforward.&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="137" LastEditDate="2015-11-03T17:19:11.853" LastActivityDate="2015-11-03T17:19:11.853" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="314" PostTypeId="2" ParentId="311" CreationDate="2015-08-21T15:41:40.173" Score="4" Body="&lt;p&gt;One way that might work is to have boids but render each boid as a group of birds.  This way the simulation is still simple but the rendering makes it seem complex.  You might even allow a little drift per bird in the boid to make it look so obviously rigid.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-08-21T15:52:48.360" LastActivityDate="2015-08-21T15:52:48.360" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="315" PostTypeId="1" CreationDate="2015-08-21T20:00:04.647" Score="7" ViewCount="519" Body="&lt;p&gt;I wrote a 2D fluid-solver in OpenGL (&lt;a href=&quot;https://github.com/nilspin/SDL_OpenGL_Project&quot; rel=&quot;noreferrer&quot;&gt;code here&lt;/a&gt;) some time back. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;While it runs flawlessly on my onboard Intel GPU, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RPBpF.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RPBpF.png&quot; alt=&quot;when running on Intel GPU&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the simulation very quickly &quot;blows-up&quot; when same code is run using nvidia card :  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xs5Sm.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xs5Sm.png&quot; alt=&quot;mere half a second into the program&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the second picture, the fluid is being &quot;added&quot; to the system and &quot;diffusing away&quot; too, but unlike the 1st picture there is no advection.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to know what might possibly cause this. Could this be because different vendors might be interpreting the standard differently?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS : The &quot;red&quot; and &quot;green&quot; colors represent magnitude of vector-field in &lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; directions respectively.&lt;/p&gt;&#xA;" OwnerUserId="437" LastActivityDate="2015-08-21T20:00:04.647" Title="Code runs differently on different hardware" Tags="&lt;opengl&gt;&lt;fluid-sim&gt;" AnswerCount="0" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="316" PostTypeId="2" ParentId="306" CreationDate="2015-08-21T21:26:46.043" Score="7" Body="&lt;p&gt;Adam Simmons has done some interesting work in this area. I don't know specifically how he's achieving it, but his SDF-based vector rendering is the sharpest I've seen in practice outside of Valve. &lt;a href=&quot;http://twitter.com/adamjsimmons/status/611677036545863680&quot;&gt;http://twitter.com/adamjsimmons/status/611677036545863680&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="104" LastActivityDate="2015-08-21T21:26:46.043" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="317" PostTypeId="2" ParentId="295" CreationDate="2015-08-22T04:54:36.683" Score="3" Body="&lt;p&gt;I do not personally think it matters much. Just pick one that suits your project. I have used both D3D and OpenGL in the past. It is the concepts that matter. Whichever you grab, you need to understand (for example):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What textures are and how they are used by GPU.&lt;/li&gt;&#xA;&lt;li&gt;Basic concepts of Graphics Development (Vertices, Primitives, Fragments, etc.)&lt;/li&gt;&#xA;&lt;li&gt;How does the camera system work (MVP matrices in OpenGL for example).&lt;/li&gt;&#xA;&lt;li&gt;What shaders are and how to use them properly.&lt;/li&gt;&#xA;&lt;li&gt;How different a GPU works versus the CPU on your machine.&lt;/li&gt;&#xA;&lt;li&gt;What are the differences between GPU's memory model and CPU's memory model.&lt;/li&gt;&#xA;&lt;li&gt;What should be done on CPU and what should be offloaded to GPU for processing.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;As others mentioned here, we are in the middle of a transition to a new set of APIs (Vulkan, Metal, etc.) so at this point if you are completely new to Graphics Development, probably focusing on GLSL is a good idea since Vulkan is going to take advantage of it as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding portability, D3D is Windows only (There are rumors that the &lt;a href=&quot;http://winehq.com/&quot; rel=&quot;nofollow&quot;&gt;Wine&lt;/a&gt; project is trying to get D3D working under Linux but nothing feasible so far). OpenGL is cross-platform. If you want to go mobile, then OpenGL ES is an available option. Of course both OpenGL and OpenGL ES have different versions which are not supported by all platforms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the end of the day, all APIs access the same hardware on your machine, it is just a matter of &quot;how&quot; they access it.&lt;/p&gt;&#xA;" OwnerUserId="307" LastEditorUserId="307" LastEditDate="2015-08-22T05:00:20.590" LastActivityDate="2015-08-22T05:00:20.590" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="318" PostTypeId="1" AcceptedAnswerId="353" CreationDate="2015-08-22T07:21:29.817" Score="7" ViewCount="1500" Body="&lt;p&gt;It is a well known &quot;standard&quot; to use bilateral upscaling when it comes to comes to combine a low resolution target and an higher res one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have personally noticed that using the basic algorithm (with weights based on depth differences between high and low res depth values) is far from perfect in situations where high res and low res are blended, say for example an high res object inside a low res effect.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Jagged edges are still noticeable&lt;/li&gt;&#xA;&lt;li&gt;&quot;haloes&quot; around edges start to appear when the objects/effects in low res occupy a smaller area on the target. By this I mean holes around the silouhette. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I am well aware that there is no way to eliminate completely these problems, but is there a way to improve bilateral upsampling to partially improve on one of the two points above? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And as side question, is there an equivalently good algorithm or variation that is cheaper?&lt;/p&gt;&#xA;" OwnerUserId="100" LastActivityDate="2015-08-26T22:00:26.977" Title="How to improve on bilateral upsampling in real time scenarios" Tags="&lt;real-time&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="319" PostTypeId="2" ParentId="311" CreationDate="2015-08-22T08:02:39.787" Score="4" Body="&lt;p&gt;I'm not sure if this counts, but you can use fluid dynamics to render large crowds (of birds, people, etc). With SPH (smoothed particle hydrodynamics) to model the &quot;fluid&quot;, you aren't really describing the motion of each bird per-se, since you can sample the crowd of birds with a representative set, and then draw birds around your samples. Take a look at this paper that compares the different methods:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://gamma.cs.unc.edu/lookahead/golas-2013-hybridcrowd.pdf&quot; rel=&quot;nofollow&quot;&gt;http://gamma.cs.unc.edu/lookahead/golas-2013-hybridcrowd.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="197" LastActivityDate="2015-08-22T08:02:39.787" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="320" PostTypeId="1" AcceptedAnswerId="1477" CreationDate="2015-08-22T08:13:25.317" Score="11" ViewCount="1014" Body="&lt;p&gt;When an image is encoded using JPEG, the RGB pixels are first encoded into YUV, and then the UV channels are downsampled. Before actually doing the DCT and encoding the coefficients, JPEG &lt;a href=&quot;http://www.w3.org/Graphics/JPEG/jfif3.pdf&quot;&gt;doesn't gamma correct&lt;/a&gt; the Y channel. Is this correct? Shouldn't we determine the DCT coefficients that will most affect our viewed result?&lt;/p&gt;&#xA;" OwnerUserId="197" LastActivityDate="2015-09-11T08:22:01.553" Title="Should JPEG encoding take into account gamma?" Tags="&lt;compression&gt;&lt;gamma&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="321" PostTypeId="2" ParentId="320" CreationDate="2015-08-23T04:25:08.513" Score="7" Body="&lt;p&gt;The short answer is &quot;no&quot;, for reasons covered in &lt;a href=&quot;http://www.alvyray.com/memos/CG/Microsoft/9_gamma.pdf&quot;&gt;Alvy Ray Smith's memo, &lt;em&gt;Gamma Correction&lt;/em&gt;&lt;/a&gt;. Gamma is not about nonlinearity in human perception, it's about nonlinearity in display devices (and, I suppose, acquisition devices too).&lt;/p&gt;&#xA;" OwnerUserId="159" LastActivityDate="2015-08-23T04:25:08.513" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="323" PostTypeId="1" CreationDate="2015-08-23T13:42:45.053" Score="11" ViewCount="535" Body="&lt;p&gt;I'd like to simulate the magnification of very distant objects by the lensing effect of a less distant galaxy. Will I need to model large numbers of point masses or can I get away with just a single average point mass?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can see how to raytrace using hyperbolae for the rays influenced by a single point mass, but I wouldn't know where to begin with multiple point masses. So before I attempt to build this raytracer I'd like to know whether I'm going to be able to avoid multiple masses, and still have believable results.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-09-01T16:29:40.593" Title="Can I raytrace gravitational lensing using only a single point source of gravity?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="324" PostTypeId="1" AcceptedAnswerId="412" CreationDate="2015-08-23T19:38:23.123" Score="4" ViewCount="261" Body="&lt;p&gt;I've seen a number of 2D Poisson disc sampling algorithms online that use a grid to accelerate checking for existing points within the minimum radius [![r][r image]][r link] of a candidate point. For example:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://devmag.org.za/2009/05/03/poisson-disk-sampling/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dev.Mag&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://bl.ocks.org/mbostock/dbb02448b0f93e4c82c3&quot; rel=&quot;nofollow noreferrer&quot;&gt;mbostock&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;They use a grid of squares of side $\frac{r}{\sqrt2}$, which is the same side length that I intuitively came up with when implementing this myself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can see the reason - that is the largest square that cannot contain more than 1 point (assuming the minimum is not attainable - the distance between two points must be &lt;em&gt;strictly&lt;/em&gt; greater than $r$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, having thought about it further, I adjusted the grid size to $\frac{r}2$ instead. This finer grid means 4 additional squares need to be checked (the 4 corner squares are now within the radius), but the total area covered by the required squares is less, so that on average fewer points will need to go through the Euclidean distance check. The difference can be visualized using the same style as the diagram in the first linked article.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cE5KI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cE5KI.png&quot; alt=&quot;Grid with side length r over root 2&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/r3PJ9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/r3PJ9.png&quot; alt=&quot;Grid with side length r over 2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a candidate new point, existing points must be checked in all squares that are within a radius $r$ of the corners of the candidate's square. Here the two grid sizes are shown side by side, to scale, for the same radius $r$. This shows clearly that a significantly smaller area is being checked. Each square is exactly half the area of the previous approach, and even if the 4 outer corner squares are excluded in the previous approach (left image), this still gives an area $2 \cdot \frac{21}{25} = 1.68$ times larger than in the new approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main question is this: &lt;strong&gt;Is this approach still correct, and does it give identical results?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm also interested to know whether there is any reason to favor the $\frac{r}{\sqrt2}$ approach. Using $\frac{r}{2}$ seems more efficient in time, which seems worth the cost in space efficiency. Is there anything I'm missing?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;em&gt;Images produced with this &lt;a href=&quot;https://jsfiddle.net/wkneysgj/&quot; rel=&quot;nofollow noreferrer&quot;&gt;jsfiddle&lt;/a&gt; (in case I need to edit them later).&lt;/em&gt;&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="137" LastEditDate="2015-11-03T17:35:05.190" LastActivityDate="2015-11-03T17:35:05.190" Title="Is this smaller grid for Poisson disc sampling still correct?" Tags="&lt;grid&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="325" PostTypeId="1" CreationDate="2015-08-24T16:52:15.143" Score="8" ViewCount="686" Body="&lt;p&gt;I'd like to know if there's any performance impact based on how I struct my shader uniforms. For instance, is passing 4 floats worse than passing a single vec4?&lt;/p&gt;&#xA;" OwnerUserId="250" LastActivityDate="2015-08-25T05:19:19.273" Title="Shader uniform performance" Tags="&lt;performance&gt;&lt;glsl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="326" PostTypeId="1" AcceptedAnswerId="425" CreationDate="2015-08-24T17:59:01.563" Score="4" ViewCount="126" Body="&lt;p&gt;To render an image for use with red &amp;amp; blue 3d glasses, the usual way to do it is to render from one point of view, convert it to a single intensity (greyscale) value per pixel, and then put that into the red color channel.  Render from a slightly different point of view, convert that to greyscale again and put that into the blue channel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be prohibitive when rendering a single time is already very costly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any methods by which you could take a single render, and corresponding depth buffer, and come up with something suitable for both red and blue channels?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-09-03T15:09:52.093" Title="Is it possible to render red / blue 3d from one image and a depth buffer?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;stereo-rendering&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="327" PostTypeId="1" AcceptedAnswerId="328" CreationDate="2015-08-25T00:01:43.080" Score="9" ViewCount="1636" Body="&lt;p&gt;When applying multiple textures to a mesh, like for bump-mapping, I usually bind the textures to the first few fixed texture units, e.g.: diffuse = unit 0, bump = unit 1, specular = unit 2, then keep reusing those to each different mesh with different textures. But I've always wondered why &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glActiveTexture.xhtml&quot;&gt;&lt;code&gt;glActiveTexture&lt;/code&gt;&lt;/a&gt; supports so many texture units (in the previous link, it says at least 80).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it occurred to me that one possible way of managing textures is to bind distinct textures to each available unit and leave them enabled, just updating the uniform sampler index. That should improve rendering perf by reducing the number of textures switches. If you have less textures than the max texture units, you never have to unbind a texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this standard practice on real-time OpenGL applications (I believe this also applies to D3D)? And are there any non obvious performance implications of taking this approach? Memory overhead perhaps?&lt;/p&gt;&#xA;" OwnerUserId="54" LastActivityDate="2015-08-25T04:34:12.847" Title="Is it good practice to use all the available texture units?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="328" PostTypeId="2" ParentId="327" CreationDate="2015-08-25T00:33:25.640" Score="12" Body="&lt;p&gt;Modern hardware doesn't really have the concept of texture binding points as exposed by OpenGL. Rather, the shader unit uses a descriptor (which is just some kind of fat pointer) which can potentially address any texture as long as it's resident in video memory. This is what makes things like &lt;a href=&quot;https://www.opengl.org/registry/specs/ARB/bindless_texture.txt&quot;&gt;bindless textures&lt;/a&gt; possible. So the large amount of &quot;texture units&quot; available in current implementations is simply trying to handwave this now-irrelevant part of the API.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, the recommended way of implementing what you're trying to do (avoiding re-binding of textures) is to use &lt;a href=&quot;https://www.opengl.org/wiki/Array_Texture&quot;&gt;texture arrays&lt;/a&gt;, which allow you to dynamically index into a set of textures in the shader, as long as they all have the same format and size. This presentation contains more details about these and other techniques for reducing driver overhead when rendering with modern OpenGL: &lt;a href=&quot;http://www.slideshare.net/CassEveritt/approaching-zero-driver-overhead&quot;&gt;Approaching Zero Driver Overhead&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-08-25T04:34:12.847" LastActivityDate="2015-08-25T04:34:12.847" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="329" PostTypeId="1" AcceptedAnswerId="331" CreationDate="2015-08-25T04:14:15.283" Score="3" ViewCount="76" Body="&lt;p&gt;I am implementing a trackball, i.e. a camera orbiting about a fixed point, in my case the origin. When I do left click with the mouse and start moving it, I compute delta values for the angles of a sphere centered at the origin given the displacement in x and y directions of the mouse. My implementation is as follows&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void SimplePerspectiveCamera::&#xA;mouseMove(const double&amp;amp; mouseX, const double&amp;amp; mouseY)&#xA;{&#xA;    if(m_setPan)&#xA;    {&#xA;        float sensitivity = 0.0075f;&#xA;        float newX = (mouseX - m_prevX) * sensitivity;&#xA;        float newY = (mouseY - m_prevY) * sensitivity;&#xA;        // TODO: Understand if it is necessary to reset the up vector to (0,1,0)&#xA;        m_up = Vector(0.0f, 1.0f, 0.0f);&#xA;        setLookAt(m_lookAt + Vector(-newX, newY, 0.0f));&#xA;        setPosition(m_position + Vector(-newX, newY, 0.0f));&#xA;        m_prevX = mouseX;&#xA;        m_prevY = mouseY;&#xA;    }&#xA;    if(m_setRotate)&#xA;    {&#xA;        float sensitivity = 0.005f;&#xA;        float newPhi = (mouseX - m_prevX) * sensitivity;&#xA;        float newTheta = (mouseY - m_prevY) * sensitivity;&#xA;        // Transform to spherical coordinates to use mouse move as deltas for&#xA;        // the angles.&#xA;        float r = m_position.norm();&#xA;        float theta = std::acos(m_position.y / r);&#xA;        float phi = std::atan(m_position.x / m_position.z);&#xA;&#xA;        theta += newTheta;&#xA;        phi += newPhi;&#xA;&#xA;        m_up = Vector(0.0f, 1.0f, 0.0f);&#xA;        Vector newPosition(r*std::sin(theta)*std::sin(phi), r*std::cos(theta),&#xA;                r*std::sin(theta)*std::cos(phi));&#xA;        setPosition(newPosition);&#xA;        m_prevX = mouseX;&#xA;        m_prevY = mouseY;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What I was expecting is to be able to rotate the camera around the cube in the scene so that I can see all around it. My code almost achieves this, but I don't understand why after rotating a certain amount the camera jumps to the exact opposite side of the cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can check what weird swap I am talking about &lt;a href=&quot;https://vimeo.com/137210181&quot; rel=&quot;nofollow&quot;&gt;this link&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I missing so that the rotation around the object goes all the way around it?&lt;/p&gt;&#xA;" OwnerUserId="116" LastEditorUserId="116" LastEditDate="2015-08-25T04:46:15.257" LastActivityDate="2015-08-25T05:04:30.273" Title="Why is the color in the cube being weirdly swapped?" Tags="&lt;transformations&gt;&lt;trackball&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="330" PostTypeId="2" ParentId="326" CreationDate="2015-08-25T04:59:24.840" Score="4" Body="&lt;p&gt;Yes, this is essentially the same problem that occours in paralax mapping. What you basically have is a colored height field. That needs to be rendered from a second view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are several ways in which you can approach this. You could cheat and just shift pixels by their depth and ignore occlusion. Or you could just render a textured height map as if every pixel would be opaque. Or you could use any of the available paralax mapping methods to eliminate occlusion. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How well this works depends on the. A scene multiple transparent surfaces wouldnt work very well without some deep map.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-25T05:06:26.757" LastActivityDate="2015-08-25T05:06:26.757" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="331" PostTypeId="2" ParentId="329" CreationDate="2015-08-25T05:04:30.273" Score="6" Body="&lt;p&gt;It is likely that your specific problem arises from a singularity in &lt;code&gt;atan&lt;/code&gt; when &lt;code&gt;m_position.z&lt;/code&gt; goes to 0. Rather than try to debug that, I'll point out that you don't need to transform your camera position into an angle to then modify it: rather, just create a rotation from your &lt;code&gt;newPhi&lt;/code&gt; and &lt;code&gt;newTheta&lt;/code&gt; angles, in the form of a rotation matrix or quaternion, and then apply it to your vector, directly rotating it without doing the perilous round-trip to an angle.&lt;/p&gt;&#xA;" OwnerUserId="327" LastActivityDate="2015-08-25T05:04:30.273" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="332" PostTypeId="2" ParentId="325" CreationDate="2015-08-25T05:19:19.273" Score="2" Body="&lt;p&gt;In any modern desktop hardware, there shouldn't be: uniform buffers will just be memory blobs read by the shader. (See also: &lt;a href=&quot;https://www.opengl.org/wiki/Uniform_Buffer_Object&quot; rel=&quot;nofollow&quot;&gt;Uniform Buffer Objects&lt;/a&gt;)&lt;/p&gt;&#xA;" OwnerUserId="327" LastActivityDate="2015-08-25T05:19:19.273" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="333" PostTypeId="1" AcceptedAnswerId="334" CreationDate="2015-08-25T05:32:18.040" Score="3" ViewCount="96" Body="&lt;p&gt;Im developing a deep texture processing engine. Right now I have a software renderer to generate the raster samples. Now, for bigger renders it would be nice to do this on hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a standard mechanism on how to capture the data of each shader evaluation in OpenGL? I could do some sort of depth peeling but it seems to me as a bit too brute forcelike approach. I don't mind the time cost just as long as it does not take ages to implement the infrastructure needed.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="127" LastEditDate="2015-08-25T06:12:31.683" LastActivityDate="2015-08-25T06:53:55.193" Title="Is there a way for me to record every shading sample for a deep texture" Tags="&lt;opengl&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="334" PostTypeId="2" ParentId="333" CreationDate="2015-08-25T06:53:55.193" Score="4" Body="&lt;p&gt;If you really want to obtain every fragment (shading sample) within the camera frustum, regardless of occlusion, one way to do it would be to disable depth testing, and then use a large &lt;a href=&quot;https://www.opengl.org/wiki/Shader_Storage_Buffer_Object&quot; rel=&quot;nofollow&quot;&gt;SSBO&lt;/a&gt; together with an &lt;a href=&quot;https://www.opengl.org/wiki/Atomic_Counter&quot; rel=&quot;nofollow&quot;&gt;atomic counter&lt;/a&gt; to append data into the buffer from the fragment shader.  Each fragment could then store a record of its screen position, depth, color, and any other desired information into the buffer to be read out later.  The buffer has to be large enough to store every fragment rendered, as it will throw away any extra data once it's full.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using one huge SSBO for the whole screen likely isn't ideal, as there will be huge contention on its counter with every fragment trying to increment it.  A better way might be to slice up the screen in tiles with an SSBO+counter per tile.  There is a limit of 16 bound SSBOs on all current GPUs, and on AMD GPUs, there is a further limit of 8 atomic counters (source: Sascha Willem's &lt;a href=&quot;http://delphigl.de/glcapsviewer/gl_listreports&quot; rel=&quot;nofollow&quot;&gt;OpenGL Hardware Database&lt;/a&gt;).  Those limits will determine how many tiles you can create. This will reduce contention and also ensure that even if you run out of memory in one tile, you'll still have valid data in the others.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-25T06:53:55.193" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="335" PostTypeId="1" AcceptedAnswerId="343" CreationDate="2015-08-25T10:58:31.680" Score="9" ViewCount="1937" Body="&lt;p&gt;I'm trying to understand NURBS curves (surfaces later!) but I have some trouble understanding the very basics of its inner workings. Could someone please explain a few things to me? As I come from Bezier curves, a comparison between these two would be especially useful.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline#Technical_specifications&quot;&gt;&quot;rational basis function&quot;&lt;/a&gt; looks a tiny bit like Bernstein polynomial of (rational) Bezier curve. Does the parameter &lt;code&gt;u&lt;/code&gt; also go from 0 to 1?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How to &quot;add detail&quot; to a curve? I mean, with Beziers if I needed to describe a more complicated shape I would simply &quot;stitch&quot; several Beziers together. Or less often, increase the degree. I understand I can increase the degree of NURBS as well and put several NURBS curves side-by-side, but is this how it should be done?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The Wikipedia article, at least to me, seems not very clear about this &quot;knot vector&quot;. What is it anyway?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="141" LastEditorUserId="38" LastEditDate="2015-08-25T15:31:50.937" LastActivityDate="2019-01-08T09:08:00.950" Title="Non-uniform rational B-spline (NURBS) Basics" Tags="&lt;nurbs&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="336" PostTypeId="1" AcceptedAnswerId="347" CreationDate="2015-08-25T13:58:27.733" Score="6" ViewCount="3022" Body="&lt;p&gt;I'm not sure how practical this might be but is it possible to use Fast Fourier Transform to rotate a raster image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be honest, I never really understood FFT, but I saw it being used for JPEG, for example. What I try to say is let's pretend I can grab some FFT library, what do I do next?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I read that there is this &lt;a href=&quot;https://en.wikipedia.org/wiki/Gibbs_phenomenon&quot; rel=&quot;noreferrer&quot;&gt;Gibbs phenomenon&lt;/a&gt; which causes ringing artifacts. Would it be a problem here as well?&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2017-03-13T02:41:03.990" Title="Image rotation using FFT" Tags="&lt;transformations&gt;&lt;fourier-transform&gt;&lt;raster-image&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="337" PostTypeId="1" AcceptedAnswerId="344" CreationDate="2015-08-25T14:04:58.757" Score="14" ViewCount="9094" Body="&lt;p&gt;Radiosity is basically what allows this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/j9CFM.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j9CFM.jpg&quot; alt=&quot;Direct Illumination VS Radiosity&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In a tutorial of &lt;a href=&quot;http://www.graphics.cornell.edu/online/tutorial/radiosity/&quot; rel=&quot;noreferrer&quot;&gt;Cornell University about Radiosity&lt;/a&gt; it is mentioned that:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;A ray-traced version of the image shows only the light reaching the viewer by direct reflection -- hence misses the color effects.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;However in &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiosity_%28computer_graphics%29&quot; rel=&quot;noreferrer&quot;&gt;Wikipedia&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Radiosity is a global illumination algorithm in the sense that the illumination arriving on a surface comes not just directly from the light sources, but also from other surfaces reflecting light.&lt;/p&gt;&#xA;&lt;p&gt;...&lt;/p&gt;&#xA;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiosity_(computer_graphics)#Confusion_about_terminology&quot; rel=&quot;noreferrer&quot;&gt;radiosity method&lt;/a&gt; in the current computer graphics context derives from (and is fundamentally the same as) the radiosity method in heat transfer.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;And if &lt;a href=&quot;https://en.wikipedia.org/wiki/Ray_tracing_%28graphics%29&quot; rel=&quot;noreferrer&quot;&gt;ray tracing&lt;/a&gt; is capable of:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;simulating a wide variety of optical effects, such as reflection (&lt;a href=&quot;https://en.wikipedia.org/wiki/Diffuse_reflection&quot; rel=&quot;noreferrer&quot;&gt;diffuse reflection&lt;/a&gt;) and &lt;a href=&quot;https://en.wikipedia.org/wiki/Light_scattering&quot; rel=&quot;noreferrer&quot;&gt;&lt;strong&gt;scattering&lt;/strong&gt; (i.e. the deflection of a ray from a straight path, for example by irregularities in the propagation medium, particles, or in the interface between two media)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Has that tutorial not considered these effects or are there radiosity methods that can be used in ray tracing in order to enable them?&lt;/p&gt;&#xA;&lt;p&gt;If not, couldn't these optical effects simulate radiosity entirely or is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiosity_(computer_graphics)#Overview_of_the_radiosity_algorithm&quot; rel=&quot;noreferrer&quot;&gt;radiosity algorithm&lt;/a&gt; more efficient in solving the diffuse reflection problem?&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-08-25T22:00:23.613" Title="Radiosity VS Ray tracing" Tags="&lt;raytracing&gt;&lt;reflection&gt;&lt;scattering&gt;&lt;radiosity&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="338" PostTypeId="1" CreationDate="2015-08-25T14:05:06.773" Score="5" ViewCount="384" Body="&lt;p&gt;One of the benefits of NURBS curve over, say Bezier curve, is the ability to create offset curves exactly. How to proceed with such computation? Do I just translate the control points?&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="141" LastEditDate="2015-08-25T14:17:11.867" LastActivityDate="2015-09-23T20:49:14.113" Title="NURBS curve offset" Tags="&lt;nurbs&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="339" PostTypeId="1" AcceptedAnswerId="341" CreationDate="2015-08-25T14:07:20.570" Score="6" ViewCount="593" Body="&lt;p&gt;How to draw a NURBS curve?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compared with Bezier curve, I just evaluate the Bernstein polynomial, multiply it with control point positions and that's it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at the &quot;General form of a NURBS curve&quot; paragraph of &lt;a href=&quot;https://en.wikipedia.org/wiki/Non-uniform_rational_B-spline#Technical_specifications&quot;&gt;NURBS Wikipedia page&lt;/a&gt; I have a hard time seeing a polynomial in it. Maybe this &quot;basis function&quot; is a polynomial in the end? Is there an efficient way of constructing the basis function and evaluating it?&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2015-08-25T17:05:45.507" Title="NURBS curve drawing" Tags="&lt;nurbs&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="340" PostTypeId="1" AcceptedAnswerId="352" CreationDate="2015-08-25T14:08:56.157" Score="8" ViewCount="1292" Body="&lt;p&gt;Splitting Bezier curve into two parts at some parameter &lt;code&gt;t&lt;/code&gt; is easy thanks to &lt;a href=&quot;https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm&quot;&gt;De Casteljau's algorithm&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a similar algorithm for NURBS curves? How to split a NURBS curve?&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="141" LastEditDate="2015-08-25T14:18:49.773" LastActivityDate="2019-05-09T06:46:24.227" Title="Splitting of NURBS curves" Tags="&lt;nurbs&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="341" PostTypeId="2" ParentId="339" CreationDate="2015-08-25T14:24:03.697" Score="7" Body="&lt;p&gt;A NURBS differs from a Bezier curve in two ways...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) It's rational which means that it's one curve divided by another. (rational comes from &quot;ratio&quot;, not anything to do with it's temperament!)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Being rational is not an issue though for being simple to evaluate.  There are even such things as rational Bezier curves, where again, you just divide one Bezier curve by another to get the final result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This allows you to make shapes with Bezier curves that you wouldn't be able to otherwise, for instance, rational Bezier curves can EXACTLY represent conic sections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an HTML5 demo where you can play with a rational Bezier curve:&#xA;&lt;a href=&quot;http://demofox.org/bezquadrational.html&quot; rel=&quot;noreferrer&quot;&gt;http://demofox.org/bezquadrational.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, here is a shadertoy which uses a rational Bezier curve to calculate sin!&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/XtfSRH&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/XtfSRH&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) The second difference is the one that makes it more difficult to evaluate, at least for me.  The second difference is that a NURBS, like a B-spline, can have any number of control points, but has a fixed degree.  How this works is that any given point on the curve is only influenced by a specific number of control points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could have for example a quadratic curve with 8 control points,  where each point on the curve was only defined by 3 of the control points at a time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where the influence of the control points begin and end is called the knot vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So basically, if you can evaluate a rational curve, and you can evaluate a b-spline, you will then know how to evaluate a NURBS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Explaining how to evaluate a b-spline is too long for an answer I think, and there is lots of info on the web, and in text books, so i'll link to a couple things that might help you!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Read up on De Boor's algorithm, its the b-spline equivalent of De Casteljeau's algorithm:&#xA;&lt;a href=&quot;https://en.m.wikipedia.org/wiki/De_Boor%27s_algorithm&quot; rel=&quot;noreferrer&quot;&gt;https://en.m.wikipedia.org/wiki/De_Boor%27s_algorithm&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a shadertoy rendering a b-spline in a pixel shader:&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/MtfSRN&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/MtfSRN&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is info on how to evaluate a b-spline:&#xA;&lt;a href=&quot;http://web.mit.edu/hyperbook/Patrikalakis-Maekawa-Cho/node18.html&quot; rel=&quot;noreferrer&quot;&gt;http://web.mit.edu/hyperbook/Patrikalakis-Maekawa-Cho/node18.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, here is some code (GLSL) that shows how to evaluate an 8 control point cubic B-spline:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float N_i_1 (in float t, in float i)&#xA;{&#xA;    // return 1 if i &amp;lt; t &amp;lt; i+1, else return 0&#xA;    return step(i, t) * step(t,i+1.0);&#xA;}&#xA;&#xA;float N_i_2 (in float t, in float i)&#xA;{&#xA;    return&#xA;        N_i_1(t, i)       * (t - i) +&#xA;        N_i_1(t, i + 1.0) * (i + 2.0 - t);&#xA;}&#xA;&#xA;float N_i_3 (in float t, in float i)&#xA;{&#xA;    return&#xA;        N_i_2(t, i)       * (t - i) / 2.0 +&#xA;        N_i_2(t, i + 1.0) * (i + 3.0 - t) / 2.0;&#xA;}&#xA;&#xA;float N_i_4 (in float t, in float i)&#xA;{&#xA;    return&#xA;        N_i_3(t, i)       * (t - i) / 3.0 +&#xA;        N_i_3(t, i + 1.0) * (i + 4.0 - t) / 3.0;&#xA;}&#xA;&#xA;float SplineValue(in float t)&#xA;{&#xA;    return&#xA;        P0 * N_i_4(t, 0.0) +&#xA;        P1 * N_i_4(t, 1.0) +&#xA;        P2 * N_i_4(t, 2.0) +&#xA;        P3 * N_i_4(t, 3.0) +&#xA;        P4 * N_i_4(t, 4.0) +&#xA;        P5 * N_i_4(t, 5.0) +&#xA;        P6 * N_i_4(t, 6.0) +&#xA;        P7 * N_i_4(t, 7.0);   &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I guess your question boils down to:  Is there a way to do De Boor's algorithm as an equivalent equation, the same way Bernstein polynomials are an equation form of De Casteljeau's algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure, but since there are &quot;branches&quot; (see N_i_1 in the glsl code), it seems like it'd be difficult.  Maybe someone else will have a more direct answer to that part of it though.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-08-25T17:05:45.507" LastActivityDate="2015-08-25T17:05:45.507" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="342" PostTypeId="1" CreationDate="2015-08-25T14:55:49.330" Score="4" ViewCount="145" Body="&lt;p&gt;I thought of this after my &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/337/radiosity-vs-ray-tracing&quot;&gt;radiosity vs ray tracing question&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A radiosity algorithm seems to require &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiosity_%28computer_graphics%29&quot; rel=&quot;nofollow noreferrer&quot;&gt;increased calculations because it's viewpoint independent&lt;/a&gt; and therefore, &lt;a href=&quot;https://en.wikipedia.org/wiki/False_radiosity&quot; rel=&quot;nofollow noreferrer&quot;&gt;false radiosity&lt;/a&gt; was born (at least it's the way it was explained). It is mentioned that in order to simulate radiosity, changes were done directly in texture maps (in PS for example) or omni-type lights are placed where radiosity effects occur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wonder if false radiosity is still used nowadays (I'm assuming this may happen more often in games development). If so, are these techniques currently used or are there others methods to achieve the same purpose? Any examples would be a plus.&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-10-13T06:34:33.383" Title="Are there specific techniques for generating False Radiosity in surfaces?" Tags="&lt;radiosity&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="343" PostTypeId="2" ParentId="335" CreationDate="2015-08-25T16:12:23.277" Score="8" Body="&lt;p&gt;B-Splines and Beziers are parallel inventions of more or less the same thing. Where Beziers try to start from the idea of fitting tangents. B-Splines start with the idea of basis functions. NURB Splines (or the rational part in fact) are just generalizations of B-Splines so you can describe accurate conic sections*, as they are of special interest in engineering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First let us start with a simple NURB Spline terminology. The rationale of these curves is a bit different than for Beziers. First there is the concept of a span. A span would roughly be equivalent to a whole Bezier spline except in nurbs you can have any number of spans. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/mHFPu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: One cubic NURBS span. This is a bit atypical in formulation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each span is formed by the curve degree + 1  control points**. Each curve can consist of any number of points. Each consecutive span reuses the points form previous span by dropping one point and taking one point more in the list. So making more complex curves is as easy as just appending more points to the curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: The images curves are a bit atypically parametrized, ill explain what this means in the next section. When i take the concept of knots up. This is just a easier way to explain how the curves glue together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/PzKKi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: 2 cubic spans after each other, each span uses 4 points. together they form one curve. They share most points with each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By now we have probably answered the 2 question about adding complexity. But I would like to add that this scheme ensures better continuity than a bezier curve. Additionally you can make the point array that forms the hull cyclic. Forming a closed curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/rolEZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 3&lt;/strong&gt;: A closed cubic NURBS surface has as many spans as it has points. Each color is one span.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Parametrization&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Up until this point one could just say that the stringing together the spans is a trick just as &quot;sewing&quot; the Bezier curves. But there is a difference. The curve is parametrisized along its length. So the curves are not separate they do not interpolate form 0 to 1 on each span like Beziers do. Instead the underlying curve has a cusomizable parameter range. The parameter is stored in something called a knot, and each knot can have a arbitrary increasing value in the sequence. So you can parametrize the entire curves u range to 0 - 1 or 0 to 12. The parametrization also does not have to be uniform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This parametrization changes how the curve is shaped. Why would this be useful? Well you can adjust the tension along the curve for one. Or you could encode the length of the curve into to the U parameter. One peculiar use is to make the NURBS curve act like a Bezier curve either fully or just partially (bezier like in the ends but not in the middle for example).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/w7sHM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 4&lt;/strong&gt;: Same points different knot sequences. The green NURBS curve corresponds to a Bezier curve that has a parameter range of 0-2 instead of 0-1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Ok so what are the knots?&lt;/strong&gt; They are simply the ranges of the basis functions. Since the cubic b-spline with 4 points has 4 interpolating functions it needs 8 knots. Only areas where 3 functions overlap and sum up to 1.0 can a line be drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/GnJeM.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 5&lt;/strong&gt;: 2 different basis functions, a bezier like and a uniform segment parametrisation, spread to 0-1 range. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And now we have mostly described the answer to question 1. The range is not defined you can stretch the basis functions as you see fit. And finally the knot vector simply produces the parameter ranges for the basis functions. Theres still one more thing that governs the shape of the curve and that is the weight vector. But that another story to be told elsewhere.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;* This rational in this case means that a NURBS curve does not have to be a polynomial, as you cant describe a circle with polynomials. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;** One can define other types of points.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="209" LastEditDate="2019-01-08T09:08:00.950" LastActivityDate="2019-01-08T09:08:00.950" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="344" PostTypeId="2" ParentId="337" CreationDate="2015-08-25T16:47:01.460" Score="15" Body="&lt;p&gt;Radiosity does not account for specular reflections (i.e. it only handles diffuse reflections). Whitted's ray-tracing only considers glossy or diffuse reflection, possibly mirror-reflected. And finally, Kajiya's path-tracing is the most general one [2], handling any number of diffuse, glossy and specular reflections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I think it depends on what you means by &quot;ray-tracing&quot;: the technique developed by Whitted or any kind of &quot;tracing rays&quot;...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Side-note: Heckbert [1] (or Shirley?) devised a classification of light scattering events which took place as the light traveled from the luminaire to the eye. In general it has the following form:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;L(S|D)*E&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&quot;L&quot; stands for luminaire, &quot;D&quot; for diffuse reflection, &quot;S&quot; for specular reflection or refraction, &quot;E&quot; for eye, and the symbols &quot;*&quot;, &quot;|&quot;, &quot;()&quot;, &quot;[]&quot; come from regular expressions notation and denote &quot;zero or more&quot;, &quot;or&quot;, &quot;grouping&quot;, &quot;one of&quot;, respectively. Veach [3] extended the notation in his famous dissertation by &quot;D&quot; for Lambertian, &quot;S&quot; for specular and &quot;G&quot; for glossy reflection, and &quot;T&quot; for transmission.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particular, the following techniques are classified as:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;OpenGL shading: &lt;code&gt;EDL&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Appel's ray-casting: &lt;code&gt;E(D|G)L&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Whitted's ray-tracing: &lt;code&gt;E[S*](D|G)L&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Kajiya's path-tracing: &lt;code&gt;E[(D|G|S)+(D|G)]L&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Golar's radiosity: &lt;code&gt;ED*L&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;[1] Paul S. Heckbert. Adaptive radiosity textures for bidirectional ray tracing. SIGGRAPH Computer Graphics, Volume 24, Number 4, August 1990&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[2] The Siggraph 2001 course &quot;State of the Art in Monte Carlo Ray Tracing for Realistic Image Synthesis&quot; says the following: &quot;Distributed ray tracing and path tracing&#xA;includes multiple bounces involving non-specular scattering such as &lt;code&gt;E(D|G)*L&lt;/code&gt;. However, even these methods ignore paths of the form &lt;code&gt;E(D|G)S*L&lt;/code&gt;; that is, multiple specular bounces from the light source as in a caustic.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[3] Eric Veach. Robust Monte Carlo Methods for Light Transport Simulation. Ph.D. dissertation, Stanford University, December 1997&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="141" LastEditDate="2015-08-25T22:00:23.613" LastActivityDate="2015-08-25T22:00:23.613" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="346" PostTypeId="1" AcceptedAnswerId="349" CreationDate="2015-08-25T19:42:26.127" Score="8" ViewCount="229" Body="&lt;p&gt;As of now, when rendering my scene and while iterating through the scene graph, for each node its model matrix is calculated from the parent's model matrix and the scene node's pose. This is quite simple and already reduces the number of matrix multiplications to one multiplication per node and frame. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But all these matrix multiplications have to be done on the CPU and in every frame to be able to perform (multiple consecutive) movements of scene nodes very fast. The GPU, however, is probably much better suited to perform lots of matrix multiplications, so I'm thinking about sending multiple partial model matrices to the vertex shader instead of computing everything on the CPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sending every single part (so the pose of every node) to the GPU probably does not make much sense, as in this case all the computations are done for every vertex instead of every node, which would actually decrease performance. But maybe scene nodes with lots of children or only non-moving children (relative to its parent) could be a place to split the model matrix and shift the multiplications to the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, when is it better to send partial model matrices to the shader and move the multiplication to the GPU? Or is it simply a bad idea to to this?&lt;/p&gt;&#xA;" OwnerUserId="127" LastEditorUserId="127" LastEditDate="2015-08-27T09:10:02.950" LastActivityDate="2015-08-28T04:03:06.527" Title="When is it better to upload partial model matrices to the vertex shader?" Tags="&lt;opengl&gt;&lt;performance&gt;&lt;transformations&gt;&lt;scene-graph&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="347" PostTypeId="2" ParentId="336" CreationDate="2015-08-25T21:30:55.597" Score="8" Body="&lt;p&gt;Fourier transforms wouldn't help you with a rotation. You'd just end up having to rotate the matrix of Fourier coefficients, instead of rotating the original image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider for example an image made of a perfect sine wave along the x-axis with wave-vector $(k, 0)$.  (The wave-vector is the spacial frequencies along the $x$ and $y$ axes).  The Fourier transform of this would be all black, with a single white pixel at position $(k, 0)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you rotate the image by an angle $\theta$, you'll get a perfect sine wave along an oblique axis.  If you draw a diagram and do a little trigonometry, you can see that the new wave-vector will be $(k \cos \theta, k \sin \theta)$.  (It helps for this part to know that the frequency $k$ is one over the period.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, the Fourier transform of the rotated result would be all black, with a single white pixel at position $(k \cos \theta, k \sin \theta)$.  But that's just what you'd get if you rotated the Fourier transform of the original wave by $\theta$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the Gibbs phenomenon, it's an issue when downsampling an image, or compressing it by frequency quantization (as in JPEG). But simply taking the Fourier transform of an image doesn't introduce any Gibbs ringing. The Fourier transform is lossless and perfectly reversible if done properly: it represents all the information in the original image.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2015-11-03T19:15:29.400" LastActivityDate="2015-11-03T19:15:29.400" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="348" PostTypeId="2" ParentId="287" CreationDate="2015-08-25T22:04:13.903" Score="7" Body="&lt;p&gt;A 2D Fourier transform is performed by first doing a 1D Fourier transform on each row of the image, then taking the result and doing a 1D Fourier transform on each column.  Or vice versa; it doesn't matter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just as a 1D Fourier transform allows you to decompose a function into a sum of (1D) sine waves at various frequencies, a 2D Fourier transform decomposes a function as a sum of 2D sine waves.  These waves can have different frequencies along the x and y axes.  They generically have the form:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \exp \bigl(i \cdot (k_x x + k_y y) \bigr) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $k_x$ and $k_y$ are the frequencies along the $x$ and $y$ axes. These two values form a vector called the wave-vector.  In the spatial domain, the wave is oriented along the $(k_x, k_y)$ vector with a frequency along its axis of $\sqrt{k_x^2 + k_y^2}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just as for the 1D Fourier transform, there exist both discrete and continuous versions.  The result of a discrete 2D Fourier transform is a matrix of complex amplitudes for a set of discrete $(k_x, k_y)$ values.  This is commonly visualized (like in the paper you linked to) as an image where the pixel at coordinates $(k_x, k_y)$ represents the amplitude of that wave-vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, an annular shape in a 2D Fourier transform indicates rotational invariance of the distribution of frequencies (i.e. just as much amplitude for waves in every direction), with a narrow range of magnitudes (from the inside of the annulus to the outside).  In other words, the paper is using the Fourier transform to demonstrate that their noise is reasonably isotropic and band-limited.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2015-11-03T19:18:26.903" LastActivityDate="2015-11-03T19:18:26.903" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="349" PostTypeId="2" ParentId="346" CreationDate="2015-08-26T05:11:33.353" Score="9" Body="&lt;p&gt;Doing math with uniforms is a shader won't usually get you any performance over doing it on the CPU. A CPU isn't slower than a GPU at doing matrix math, it just isn't structured so as to do large amounts of math in parallel. But you have to actually do that large amount of math to get a win. Sending extra data to the GPU just to have the GPU multiply two matrices together will rarely net you anything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, say you have a buffer of skinning matrices. It &lt;em&gt;might&lt;/em&gt; start to matter whether you transform them all into world space on the CPU or just pass an extra model-to-world-space matrix to the GPU. But even then it depends on your ratio of vertices to bones.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-08-26T05:11:33.353" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="350" PostTypeId="1" AcceptedAnswerId="351" CreationDate="2015-08-26T20:05:29.413" Score="41" ViewCount="28359" Body="&lt;p&gt;Every time I think I understand the relationship between the two terms, I get more information that confuses me. I thought they were synonymous, but now I'm not sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the difference between &quot;diffuse&quot; and &quot;albedo&quot;? Are they interchangeable terms or are they used to mean different things in practice?&lt;/p&gt;&#xA;" OwnerUserId="423" LastActivityDate="2017-06-29T14:51:23.273" Title="Albedo vs Diffuse" Tags="&lt;rendering&gt;&lt;shading&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="18" ContentLicense="CC BY-SA 3.0" />
  <row Id="351" PostTypeId="2" ParentId="350" CreationDate="2015-08-26T20:57:03.073" Score="32" Body="&lt;p&gt;The short answer: They are not interchangeable, but their meaning can sometimes appear to overlap in computer graphics literature, giving the potential for confusion.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Albedo&lt;/em&gt;&lt;/strong&gt; is the proportion of incident light that is reflected away from a surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Diffuse reflection&lt;/em&gt;&lt;/strong&gt; is the reflection of light in many directions, rather than in just one direction like a mirror (&lt;a href=&quot;https://en.wikipedia.org/wiki/Specular_reflection&quot; rel=&quot;noreferrer&quot;&gt;specular reflection&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of ideal diffuse reflection (&lt;a href=&quot;https://en.wikipedia.org/wiki/Lambertian_reflectance&quot; rel=&quot;noreferrer&quot;&gt;Lambertian reflectance&lt;/a&gt;), incident light is reflected in all directions independently of the angle at which it arrived. Since in computer graphics rendering literature there is sometimes a &quot;diffuse coefficient&quot; when calculating the colour of a pixel, which indicates the proportion of light reflected diffusely, there is an opportunity for confusion with the term &lt;em&gt;albedo&lt;/em&gt;, which also means the proportion of light reflected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are rendering a material which only has ideal diffuse reflectance, then the albedo will be equal to the diffuse coefficient. However, in general a surface may reflect some light diffusely and other light specularly or in other direction-dependent ways, so that the diffuse coefficient is only a fraction of the albedo.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Note that &lt;a href=&quot;https://en.wikipedia.org/wiki/Albedo&quot; rel=&quot;noreferrer&quot;&gt;albedo&lt;/a&gt; is a term from observation of planets, moons and other large scale bodies, and is an average over the surface, and often an average over time. The albedo is thus not a useful value in itself for rendering a surface, where you need the specific, current surface property at any given location on the surface. Also note that in astronomy the term albedo can refer to different parts of the spectrum in different contexts - it will not always be refering to human visible light.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Another difference, as &lt;a href=&quot;https://computergraphics.stackexchange.com/users/48/nathan-reed&quot;&gt;Nathan Reed&lt;/a&gt; points out in a comment, is that albedo is a single average value, which gives you no colour information. For basic rendering the diffuse coefficient gives proportions for red, green and blue components separately, so albedo would only allow you to render greyscale images. For more realistic images, spectral rendering requires the reflectance of a surface as a function of the whole visible spectrum - far more than a single average value.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-26T22:28:28.447" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="352" PostTypeId="2" ParentId="340" CreationDate="2015-08-26T21:57:14.240" Score="5" Body="&lt;p&gt;The way that NURBS curves are typically split at an arbitrary point is by &lt;a href=&quot;http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/NURBS-knot-insert.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;knot insertion&lt;/a&gt;. You insert knots at the split point until it is at maximum multiplicity, at which point you can just read off the two split curves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, you may not want to split at an arbitrary point. If the ultimate goal is to draw the curves or something like that, then it's worth splitting the curve at the existing knot points (that is, performing knot insertion until all knots are at maximum multiplicity) rather than inserting new ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This process splits the NURBS into &lt;em&gt;uniform&lt;/em&gt; rational B-splines. Once you have that, you can use &lt;a href=&quot;https://en.wikipedia.org/wiki/De_Boor%27s_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;de Boor's algorithm&lt;/a&gt; to split further.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The number of knots in the knot vector is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;numKnots = degreeOfCurve + numControlPoints + 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;or if you prefer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;numKnots = orderOfCurve + numControlPoints&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Inserting a knot thus increases the number of control points by one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you travel along a NURBS curve, each knot represents a place where one control point &quot;drops out&quot; and another one &quot;enters&quot;. If a knot value is repeated, this means that more than one control point is replaced at this place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a curve of degree greater than 1, the and last knots are repeated multiple times for one simple reason: you need to bring in more than one point to start and you need to eject more than one point to end.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's think about cubic curves for the moment, just to keep things simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A curve with the knot vector [0,0,1,1] is a uniform B-spline curve. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A curve with the knot vector [0,0,1,1,2,2] is non-uniform, but can be thought of as two uniform B-spline curves which connect at t=1, one corresponding to [0,0,1,1] and one corresponding to [1,1,2,2]. You can do this because the multiplicity of the knots is enough to &quot;start&quot; and &quot;end&quot; a cubic curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're faced with a curve with a knot vector like [0,0,1,2,2], you can insert a knot at 1 without changing the shape of the curve (this is the knot insertion procedure). This increases the number of control points by one; the knot insertion procedure adjusts the points around the new knot to accommodate it. But once you've done that, you have two uniform B-spline curves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Knot insertion won't create overlapping control points unless you insert too many knots at the same place, and by &quot;too many&quot;, I mean the degree of the curve. So for a non-uniform cubic curve, you'd insert knots so that every knot had multiplicity 2. That gives you a number of abutting uniform cubic curves, which you can then use de Boor's algorithm to split further.&lt;/p&gt;&#xA;" OwnerUserId="159" LastEditorUserId="10617" LastEditDate="2019-05-09T06:46:24.227" LastActivityDate="2019-05-09T06:46:24.227" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="353" PostTypeId="2" ParentId="318" CreationDate="2015-08-26T22:00:26.977" Score="6" Body="&lt;p&gt;&lt;a href=&quot;http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/OpacityMappingSDKWhitePaper.pdf&quot;&gt;Nearest-depth filtering&lt;/a&gt; is an alternative to bilaterial filtering that was specifically developed for upsampling low-resolution transparent rendering. It's a bit simpler than bilateral sampling, in that it only requires one sample from your low-resolution texture. However it can still have issues, particularly with high-frequency geometry that isn't well-represented in your low-resolution depth buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At SIGGRAPH 2013, Bungie presented a new approach for handling very-low-resolution particles using what they called a &quot;variance depth map&quot;. You can find the slides &lt;a href=&quot;http://advances.realtimerendering.com/s2013/index.html&quot;&gt;here&lt;/a&gt; in PDF and PPTX format. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One interesting approach that hasn't been used yet (at least, to my knowledge) would be to leverage MSAA. The idea is that you take your full-resolution depth buffer, and then alias it (or convert it, if the API doesn't allow you to do so) as a 4xMSAA depth buffer with half the width and height. You could then render your low-resolution transparents to a half-resolution render target with 4xMSAA, using your &quot;4xMSAA&quot; depth buffer for depth testing. Then to upscale, for each high-resolution pixel you would access the corresponding subsample from your low-resolution MSAA render target, and blend it on top. This would give you full-resolution depth testing, but half-resolution shading (with framebuffer bandwidth somewhere in between full-res and half-res due to compression). The catch here is that you need programmable MSAA sample points to do this, since you'll want to use an ordered grid sampling pattern for your low-resolution rendering instead of the typical rotated grid pattern. Newer GPU's (Maxwell from Nvidia, GCN from AMD) support doing this through vendor extensions in &lt;a href=&quot;https://developer.nvidia.com/nvapi&quot;&gt;D3D11&lt;/a&gt; and &lt;a href=&quot;https://developer.nvidia.com/sites/default/files/akamai/opengl/specs/GL_NV_sample_locations.txt&quot;&gt;OpenGL&lt;/a&gt;, and it can be done natively on consoles.&lt;/p&gt;&#xA;" OwnerUserId="207" LastActivityDate="2015-08-26T22:00:26.977" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="354" PostTypeId="1" CreationDate="2015-08-26T22:13:24.200" Score="4" ViewCount="661" Body="&lt;p&gt;I know GPU prefetches textures and that's why dependent texture reads are slower, but how does it work and at what point that happens?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;EDIT: Split the content of this question into others as suggested by trichoplax&#xA;Here's a link to other questions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/355/how-does-texture-cache-work-considering-multiple-shader-units&quot;&gt;How does Texture Cache work considering multiple shader units&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/356/how-does-texture-cache-work-in-tile-based-rendering-gpu&quot;&gt;How does Texture Cache work in Tile Based Rendering GPU&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/357/is-using-many-texture-maps-bad-for-caching&quot;&gt;Is using many texture maps bad for caching?&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="250" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-08-26T22:53:30.343" Title="How Texture Prefetch works?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;gpu&gt;&lt;optimisation&gt;" AnswerCount="0" CommentCount="3" ClosedDate="2015-08-30T18:52:08.443" ContentLicense="CC BY-SA 3.0" />
  <row Id="355" PostTypeId="1" AcceptedAnswerId="365" CreationDate="2015-08-26T22:43:22.360" Score="11" ViewCount="3968" Body="&lt;p&gt;Modern GPUs have many parallel shading units. I'd like to know how texture cache is managed in that scenario. &lt;/p&gt;&#xA;" OwnerUserId="250" LastActivityDate="2015-08-28T06:49:13.630" Title="How does Texture Cache work considering multiple shader units" Tags="&lt;texture&gt;&lt;gpu&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="356" PostTypeId="1" AcceptedAnswerId="386" CreationDate="2015-08-26T22:44:44.380" Score="9" ViewCount="1533" Body="&lt;p&gt;How does cache work with tile based rendering? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any tips on how to improve cache hit ratio for it? (for instance, if tiles are processed horizontally and I have vertical segments of triangles with the same texture, does it work worse for cache than if I had triangles layout out horizontally?)&lt;/p&gt;&#xA;" OwnerUserId="250" LastActivityDate="2015-09-09T21:13:03.580" Title="How does Texture Cache work in Tile Based Rendering GPU" Tags="&lt;texture&gt;&lt;gpu&gt;&lt;shader&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="357" PostTypeId="1" AcceptedAnswerId="419" CreationDate="2015-08-26T22:47:25.997" Score="10" ViewCount="1337" Body="&lt;p&gt;If I have many textures (say 5+ maps) bound to the same texture unit, does it work worse for cache than if I had only 2 or 3 textures?&lt;/p&gt;&#xA;" OwnerUserId="250" LastActivityDate="2017-10-02T11:05:33.717" Title="Is using many texture maps bad for caching?" Tags="&lt;texture&gt;&lt;shader&gt;&lt;optimisation&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="358" PostTypeId="1" AcceptedAnswerId="360" CreationDate="2015-08-27T11:20:20.270" Score="7" ViewCount="931" Body="&lt;p&gt;In &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/340/splitting-of-nurbs-curves&quot;&gt;Splitting of NURBS curves&lt;/a&gt; there the answer relied on &quot;maximum knot multiplicity&quot;. In order not to mix-up different topics I would like to kindly ask to answer it in another question: what is this &quot;knot multiplicity&quot; all about?&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-05-04T07:03:12.220" Title="NURBS knot multiplicity" Tags="&lt;nurbs&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="359" PostTypeId="1" CreationDate="2015-08-27T11:33:54.510" Score="8" ViewCount="176" Body="&lt;p&gt;I'm interested to know whether the demoscene has historically introduced new techniques that would have otherwise taken longer to discover, contributing to the progress of computer graphics. Has it become more or less relevant over the years?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that some of the early demos took advantage of known hardware errors and went beyond what was considered possible at the time, but what I'm interested in is whether any of the new techniques introduced were then taken up by researchers or professional programmers to become part of the mainstream accepted way of doing things.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-28T15:05:33.153" Title="Is the demoscene a source of advancements in computer graphics?" Tags="&lt;demoscene&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ClosedDate="2015-08-30T18:51:12.580" ContentLicense="CC BY-SA 3.0" />
  <row Id="360" PostTypeId="2" ParentId="358" CreationDate="2015-08-27T11:55:04.603" Score="5" Body="&lt;p&gt;When you have a curve you can adjust the knots so that they lie on top of each other. This is essentially a bit like having several control points on top of each other, except there's only one point. This is sometimes known as multiplicity or duplicity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you have as many knots on top of each other as you have degrees in the curve smoothness, you end up with a cusp, also known as as sharp corner. Once you have a sharp corner you can just go and delete the points on the opposite side as they no longer affect points no the other side of the corner. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/6DWhc.png&quot; alt=&quot;Curve with cusp&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Curve and control cage (Top) and basis functions (bottom). In this case the curve acts as 2 adjoining bezier curves, The image is using the knot vector [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we look at a knot vector then the multiplicity looks like a seqence of n knots that have the same number. Note if you do not add ecactly as many knots on top as there is smoothness then you get a partially sharp corner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/iuSp4.gif&quot; alt=&quot;Animation&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Animation with interpolation of knot form [0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2] to  [0, 0, 0, 0, 0.34, 1, 1.66, 2, 2, 2, 2] and back. If you do proper point insertion then the curve does not change. Just talking about what multiplicity is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively to changing parametrization you can just add points on top of each other. This is equivalent although slight misuse of resources, but useful in surface modeling. Having many control points on top could also be useful for the uniform nature of the knot distribution.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-27T13:02:58.983" LastActivityDate="2015-08-27T13:02:58.983" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="361" PostTypeId="1" CreationDate="2015-08-27T12:43:44.723" Score="12" ViewCount="393" Body="&lt;p&gt;In reading about &lt;a href=&quot;https://en.wikipedia.org/wiki/Lambertian_reflectance#Use_in_computer_graphics&quot; rel=&quot;nofollow&quot;&gt;Lambertian reflectance&lt;/a&gt; on Wikipedia I found the following phrase (in bold) which doesn't sound right to me:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In computer graphics, Lambertian reflection is often used as a model for diffuse reflection. This technique causes all closed polygons (such as a triangle within a 3D mesh) to reflect light equally in all directions when rendered. In effect, a point rotated around its normal vector will not change the way it reflects light. However, the point will change the way it reflects light if it is tilted away from its initial normal vector &lt;strong&gt;since the area is illuminated by a smaller fraction of the incident radiation.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The way I picture the situation described in the paragraph, only tilting away from the light source would cause  less light to be incident in a given area. In general, tilting away from the initial normal vector could lead to either an increase &lt;strong&gt;&lt;em&gt;or&lt;/em&gt;&lt;/strong&gt; a decrease in incident light per area, as this says nothing about the location of the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have I misunderstood the context, or is this something that should be rewritten on Wikipedia?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="2041" LastEditDate="2015-11-23T13:16:19.920" LastActivityDate="2015-11-23T13:16:19.920" Title="Is a Lambertian reflector illuminated by a smaller fraction of the incident radiation when it's tilted?" Tags="&lt;shading&gt;" AnswerCount="3" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="362" PostTypeId="1" AcceptedAnswerId="364" CreationDate="2015-08-28T02:22:47.113" Score="13" ViewCount="737" Body="&lt;p&gt;I've been reading the following article on how to do a parallel scan in CUDA:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the article, there is an emphasis on making the scan &quot;work efficient&quot;. In other words, a GPU algorithm should perform no more additions than a CPU algorithm, O(n). The authors present two algorithms, one &quot;naive&quot; that does O(nlogn) additions, and one that they consider &quot;work efficient&quot;. However, the work efficient algorithm does twice as many loop iterations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From my understanding, GPUs are simply giant SIMD processors and should operate in lock-step. Doing twice as many loops in the &quot;work efficient&quot; algorithm seems to imply that many threads will be idle and decrease performance in the long run. What am I  missing?&lt;/p&gt;&#xA;" OwnerUserId="197" LastEditorUserId="4647" LastEditDate="2018-04-29T14:50:38.500" LastActivityDate="2018-04-29T14:50:38.500" Title="Why is work-efficiency desired in GPU programming?" Tags="&lt;gpu&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="363" PostTypeId="2" ParentId="346" CreationDate="2015-08-28T04:03:06.527" Score="5" Body="&lt;p&gt;Rarely, if ever. You half-answered it in your own question: a vertex shader runs once per-vertex, a fragment shader once per-fragment. If you're not doing something that's unique to that vertex or fragment, then you're doing literally the exact same thing every time you invoke a shader. That doesn't sound more efficient to me.&lt;/p&gt;&#xA;" OwnerUserId="197" LastActivityDate="2015-08-28T04:03:06.527" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="364" PostTypeId="2" ParentId="362" CreationDate="2015-08-28T05:27:35.067" Score="21" Body="&lt;p&gt;First of all, re: &quot;GPUs are simply giant SIMD processors and should operate in lock-step&quot;, it's a bit more complicated than that. The &lt;em&gt;entire&lt;/em&gt; GPU does not run in lockstep. Shader threads are organized into groups of 32 called &quot;warps&quot; (on NVIDIA; on AMD they're groups of 64 called &quot;wavefronts&quot;, but same concept).  Within a warp, all the threads do run in lockstep as a SIMD array. However, different warps are not in lockstep with each other. In addition, some warps may be actively running while others may be suspended, much like CPU threads.  Warps can be suspended either because they're waiting for something (such as memory transactions to return or barriers to clear), or because there isn't a slot available for them (since the GPU can only actively run a certain number of warps at a time).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, back to your question. I can see two ways that the &quot;work-efficient&quot; algorithm from that paper looks like it would be more efficient than the &quot;naive&quot; algorithm.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The work-efficient version requires half as many threads to begin with. In the naive algorithm, they have one thread per array element; but in the work-efficient version, each thread operates on two adjacent elements of the array and so they need only half as many threads as array elements. Fewer threads means fewer warps, and so a larger fraction of the warps can be actively running.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Although the work-efficient version requires more steps, this is offset by the fact that the number of active threads decreases faster, and the total number of active threads over all the iterations is considerably smaller. If a warp has no active threads during an iteration, that warp will just skip to the following barrier and get suspended, allowing other warps to run. So, having fewer active warps can often pay off in execution time. (Implicit in this is that GPU code needs to be designed in such a way that active threads are packed together into as few warps as possible&amp;mdash;you don't want them to be sparsely scattered, as even one active thread will force the whole warp to stay active.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the number of active threads in the naive algorithm.  Looking at Figure 2 in the article, you can see that all the threads are active &lt;em&gt;except&lt;/em&gt; for the first 2&lt;sup&gt;&lt;em&gt;k&lt;/em&gt;&lt;/sup&gt; on the &lt;em&gt;k&lt;/em&gt;​th iteration.  So with &lt;em&gt;N&lt;/em&gt; threads, the number of active threads goes like &lt;em&gt;N&lt;/em&gt; ​− 2&lt;sup&gt;&lt;em&gt;k&lt;/em&gt;&lt;/sup&gt;. For example, with &lt;em&gt;N&lt;/em&gt; = 1024, the number of active threads per iteration is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1023, 1022, 1020, 1016, 1008, 992, 960, 896, 768, 512&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I convert this to number of active warps (by dividing by 32 and rounding up), I get:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;32, 32, 32, 32, 32, 31, 30, 28, 24, 16&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;for a sum of 289.  On the other hand, the work-efficient algorithm starts with half as many threads, then it halves the number of active ones on each iteration until it gets down to 1, then starts doubling until it gets back up to half the array size again:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Converting this to active warps:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;16, 8, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 4, 8, 16&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The sum is 71, which is only a quarter as many. So you can see that over the course of the entire operation, the number of active warps is much smaller with the work-efficient algorithm. (In fact, for a lengthy run in the middle there are only a handful of active warps, which means most of the chip is not occupied. If there are additional compute tasks running, e.g. from other CUDA streams, they could expand to fill that unoccupied space.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;All that being said, it's unfortunate that the GPU Gems article does not clearly explain any of this, instead focusing on big-O &quot;number of additions&quot; analysis that, while not entirely irrelevant, misses a lot of the details about why this algorithm is faster.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-28T05:27:35.067" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="365" PostTypeId="2" ParentId="355" CreationDate="2015-08-28T06:49:13.630" Score="16" Body="&lt;p&gt;At the top level, a GPU is subdivided into a number of shader cores.  A small GPU in a notebook or tablet may have only a few cores while a high-end desktop GPU may have dozens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition to the shader cores there are also texture units. They may be grouped together with one texture unit per shader core, or one texture unit shared among two or three shader cores, depending on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The whole chip shares a single L2 cache, but the different units will have individual L1 caches.  Texture units have texture caches, and shader units have caches for instructions and constants/uniforms, and maybe a separate cache for buffer data depending on whether buffer loads are a separate path from texture loads or not (varies by GPU architecture).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Texture units operate independently and asynchronously from shader cores. When a shader performs a texture read, it sends a request to the texture unit across a little bus between them; the shader can then continue executing if possible, or it may get suspended and allow other shader threads to run while it waits for the texture read to finish.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The texture unit batches up a bunch of requests and performs the addressing math on them&amp;mdash;selecting mip levels and anisotropy, converting UVs to texel coordinates, applying clamp/wrap modes, etc. Once it knows which texels it needs, it reads them through the cache hierarchy, the same way that memory reads work on a CPU (look in L1 first, if not there then L2, then DRAM). If many pending texture requests all want the same or nearby texels (as they often do), then you get a lot of efficiency here, as you can satisfy many pending requests with only a few memory transactions.  All these operations are pipelined, so while the texture unit is waiting for memory on one batch it can be doing the addressing math for another batch of requests, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once the data comes back, the texture unit will decode compressed formats, do sRGB conversion and filtering as necessary, then return the results back to the shader core.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-28T06:49:13.630" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="366" PostTypeId="2" ParentId="359" CreationDate="2015-08-28T15:05:33.153" Score="7" Body="&lt;p&gt;The demo scene has been doing Ray marching for a long time, but only recently have main stream AAA games started using it.  The main use I've seen it for is for screenspace reflections, raymarching against the zbuffer (killzone, call of duty).  Also, shadertoy was made by inigo quillez, who is from the demo scene.  People are now using shadertoy to prototype and share graphics technique research.  So I'd say the answer is yes, but I'd like to hear more examples if other people have any (:&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-08-28T15:05:33.153" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="367" PostTypeId="1" AcceptedAnswerId="368" CreationDate="2015-08-28T18:47:48.083" Score="17" ViewCount="5186" Body="&lt;p&gt;I'd like to use OpenCL to accelerate rendering of raytraced images, but I notice that the &lt;a href=&quot;https://en.wikipedia.org/wiki/OpenCL#OpenCL_C_language&quot;&gt;Wikipedia page&lt;/a&gt; claims that recursion is forbidden in Open CL. Is this true? As I make extensive use of recursion when raytracing, this will require a considerable amount of redesign in order to benefit from the speed up. What is the underlying restriction that prevents recursion? Is there any way around it?&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-29T02:17:36.830" Title="Why is recursion forbidden in OpenCL?" Tags="&lt;raytracing&gt;&lt;opencl&gt;&lt;gpgpu&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="368" PostTypeId="2" ParentId="367" CreationDate="2015-08-29T02:17:36.830" Score="25" Body="&lt;p&gt;It's essentially because not all GPUs can support function calls&amp;mdash;and even if they can, function calls may be quite slow or have limitations such as a very small stack depth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shader code and GPU compute code may appear to have function calls all over the place, but under normal circumstances they're all 100% inlined by the compiler. The machine code executed by the GPU contains branches and loops, but no function calls. However, recursive function calls cannot be inlined for obvious reasons. (Unless some of the arguments are compile-time constants, in such a way that the compiler can fold them and inline the entire tree of calls.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to implement true function calls, you need a stack.  Most of the time, shader code doesn't use a stack at all&amp;mdash;GPUs have large register files and shaders can keep all their data in registers the whole time.  It's difficult to make a stack work because (a) you would need a lot of stack space to provide for all the many warps that can be in flight at a time, and (b) the GPU memory system is optimized for batching together a lot of memory transactions to achieve high throughput, but this comes at the expense of latency, so my guess is stack operations like saving/restoring local variables would be awfully slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Historically, hardware-level function calls haven't been too useful on the GPU, as it has made more sense to inline everything in the compiler.  So GPU architects haven't focused on making them fast.  Probably some different tradeoffs could be made, if there is a demand for efficient hardware-level calls in the future, but (as with everything in engineering) it will incur a cost somewhere else.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as raytracing is concerned, the way people usually handle this sort of thing is by creating queues of rays that are in the process of being traced.  Instead of recursing, you add a ray to a queue, and at the high level somewhere you have a loop that keeps processing until all the queues are empty.  It does require significant reorganization of your rendering code if you're starting from a classic recursive raytracer, though.  For more info, a good paper to read on this is &lt;a href=&quot;https://research.nvidia.com/publication/megakernels-considered-harmful-wavefront-path-tracing-gpus&quot;&gt;Wavefront Path Tracing&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-08-29T02:17:36.830" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="369" PostTypeId="1" CreationDate="2015-08-29T07:00:30.047" Score="9" ViewCount="148" Body="&lt;p&gt;My postscript interpreter currently implements the &lt;a href=&quot;https://github.com/luser-dr00g/xpost/blob/master/data/clip.ps&quot; rel=&quot;nofollow&quot;&gt;Hodgeman-Sutherland clipping algorithm&lt;/a&gt; but this is limited to simpler shapes and doesn't have a provision for utilizing various winding-number rules. So it doesn't help me to implement even-odd filling or handle complex self-intersecting shapes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/w/index.php?title=Weiler%E2%80%93Atherton_clipping_algorithm&quot; rel=&quot;nofollow&quot;&gt;Weiler-Atherton algorithm&lt;/a&gt; promises to offer all these features, but every time I sit down with it, I get hung up on implementing the basic constructs. Specifically it requires making bi-directional associations between nodes which can then be traversed in either direction. But, how do you do that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I implement my path lists in Postscript (or any dynamic object-based language) as an array of points, the points themselves implemented as an array of coordinates, do I make a list of index pairs and do a linear search for traversing? Or can I use an associative array to make a mapping, and is it sufficient to add both (node1-&gt;node2) and (node2-&gt;node1)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or what if the paths are in a linked-list in a C like language with pointers to the next vertex and a NULL pointer designating the end, do you just add more links (pointers) to the nodes?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You don't need to address all my questions here, it should be sufficient to describe the strategy for building this data structure for any 1 language (not necessarily Postscript or C), and I should be able to apply it to my specific case which is usually to prototype in Postscript and translate to C if necessary for speed.&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="482" LastEditDate="2015-08-30T20:53:57.460" LastActivityDate="2015-08-30T20:53:57.460" Title="How to describe the bi-directional links for the Weiler-Atherton algorithm?" Tags="&lt;polygon&gt;&lt;clipping&gt;&lt;data-structure&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="370" PostTypeId="1" AcceptedAnswerId="371" CreationDate="2015-08-29T15:15:24.327" Score="8" ViewCount="1552" Body="&lt;p&gt;Looking at &lt;a href=&quot;http://www.oxidegames.com/star-swarm/&quot;&gt;Star Swarm&lt;/a&gt;, a demo for the Nitrous engine, I found this little line:&#xA;&quot;Nitrous uses Object Space Lighting, the same techniques used in film, including real-time film-quality motion blur.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried looking around for anything on &quot;object space lighting&quot; or &quot;object space rendering&quot; but couldn't come up with anything. When I hear &quot;object space&quot; I think of doing it per-object but I was hoping to find a more detailed description of the method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know anything about &quot;object space lighting&quot; and if so could you go into some technical details(how its done, pros, cons, etc)?&lt;/p&gt;&#xA;" OwnerUserId="376" LastActivityDate="2015-08-29T19:29:17.383" Title="What is &quot;Object Space Lighting&quot;?" Tags="&lt;rendering&gt;&lt;real-time&gt;&lt;lighting&gt;&lt;space&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="371" PostTypeId="2" ParentId="370" CreationDate="2015-08-29T19:29:17.383" Score="6" Body="&lt;p&gt;According to the Star Swarm developers this helps them with LOD and enables greater shading scaling. Based on this I guess its simply texture space lighting.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Because we do what we’re calling object space lighting, we calculate the projected size of each of those objects on screen, and based on that we shade it in a priority manner based on how large they are. We can scale the shading quality at a different frequency than we scale the geometry level or something else.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://venturebeat.com/2014/01/21/a-deep-dive-into-the-making-of-the-eye-popping-star-swarm-demo-interview/view-all/&quot;&gt; A deep dive into the making of the eye-popping Star Swarm demo (interview)&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="93" LastActivityDate="2015-08-29T19:29:17.383" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="372" PostTypeId="1" AcceptedAnswerId="383" CreationDate="2015-08-30T15:46:52.053" Score="8" ViewCount="1152" Body="&lt;p&gt;I've been playing around with shadow mapping in OpenGL using depth textures. The depth texture is fine and I can map it onto the scene but I have some strange artefacts on the back of the object:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/V4oJ8fq.png&quot; alt=&quot;Sphere casting a shadow, with artefacts on rear&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is what is causing this and how can I fix it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fragment shader I'm using is fairly straightforward (I stripped out the colour for simplicity in case you're wondering why there's no blue here):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;in vec4 vShadowCoord;&#xA;&#xA;uniform sampler2DShadow shadowMap;&#xA;&#xA;out vec4 fragColor;&#xA;&#xA;void main()&#xA;{&#xA;    float bias = 0.005;&#xA;    float visibility = 1.0;&#xA;    if (texture(shadowMap, vec3(vShadowCoord.xy, vShadowCoord.z / vShadowCoord.w)) &amp;lt; (vShadowCoord.z - bias) / vShadowCoord.w)&#xA;        visibility = 0.25;&#xA;&#xA;    fragColor = vec4(visibility);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Edit: As requested, minimum working example screenshot that uses only the above code (no colour).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/K69JKyS.png&quot; alt=&quot;Same sphere, minus colour&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="193" LastEditorUserId="193" LastEditDate="2015-08-31T13:33:46.303" LastActivityDate="2015-08-31T22:01:39.200" Title="Shadow Mapping artefacts" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;shadow-mapping&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="374" PostTypeId="1" AcceptedAnswerId="378" CreationDate="2015-08-30T21:59:24.907" Score="19" ViewCount="3091" Body="&lt;p&gt;I tried &lt;a href=&quot;https://math.stackexchange.com/questions/348806/intersect-a-line-with-a-bicubic-bezier-surface-patch&quot;&gt;this question on math.SE&lt;/a&gt; and surprisingly, the answer was &quot;the equations are too nasty, just feed the function it to a numerical root-finder&quot;. But if you consider yourself &quot;a graphics guy&quot; like me, and have played extensively with Bezier curves for design work, I got to believe that better can be done. There is a published algorithm by Kajiya that I don't have the background to understand (Sylvester Matrices), but the related advice on math.SE was that the result is a degree-18 polynomial in t, and you still need to solve that numerically. &lt;a href=&quot;https://math.stackexchange.com/questions/1083240/can-a-bicubic-bezier-surface-be-represented-as-a-bernstein-polynomial&quot;&gt;I had another idea with similar result&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is it a total pipe dream to hope to solve the Ray/Bezier-surface intersection algebraically, thus making it possible to code explicitly and have super-fast super-smoothness?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Barring that, what's the fastest method for performing this calculation? Can you &quot;find the wiggles&quot; to get a tight bound (and target) for recursive subdivision? If you have to use a numerical root-finder (sigh), what properties does it need and is there a best choice for speed?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My original thought was about preparing for a specific surface, similar to Laplace expansion as described in the answer to my &lt;a href=&quot;https://math.stackexchange.com/questions/297588/for-bsp-generation-how-to-intersect-or-locate-a-triangle-with-a-plane-defined-b&quot;&gt;other math question about triangles&lt;/a&gt;. But I'd be interested in general methods, too. I'm just thinking of a fixed set of shapes, like &lt;a href=&quot;https://stackoverflow.com/questions/14807341/how-to-do-a-space-partitioning-of-the-utah-teapot&quot;&gt;the Utah teapot&lt;/a&gt;. But I'd be very interested in ways of optimizing for temporal coherence across animated frames.&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2020-07-21T17:00:27.490" Title="How to raytrace Bezier surfaces?" Tags="&lt;raytracing&gt;&lt;bezier-curve&gt;" AnswerCount="5" CommentCount="2" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="375" PostTypeId="1" AcceptedAnswerId="379" CreationDate="2015-08-31T01:30:55.070" Score="11" ViewCount="7465" Body="&lt;p&gt;Wikipedia &lt;a href=&quot;https://en.wikipedia.org/wiki/Shading#Ambient_lighting&quot; rel=&quot;nofollow&quot;&gt;says&lt;/a&gt;: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;An ambient light source represents a fixed-intensity and fixed-color light source that affects all objects in the scene equally.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;By saying &quot;affects all objects equally&quot; they mean all objects get the same amount of light? So if you have three houses in your scene, you would need to calculate a specific position for the ambient lighting source, in order that every object gets the same amount of light? If not, you would not have an ambient light source? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the difference between &quot;normal&quot; lighting from the sun and ambient lighting?&lt;/p&gt;&#xA;" OwnerUserId="480" LastEditorUserId="127" LastEditDate="2015-10-18T14:48:44.737" LastActivityDate="2015-10-18T14:48:44.737" Title="What is ambient lighting?" Tags="&lt;lighting&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="376" PostTypeId="1" AcceptedAnswerId="2173" CreationDate="2015-08-31T01:48:27.043" Score="11" ViewCount="1933" Body="&lt;p&gt;I do not understand the &lt;a href=&quot;https://en.wikipedia.org/wiki/Screen_space_ambient_occlusion#Implementation&quot;&gt;explanation&lt;/a&gt; from wikipedia.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;For every pixel on the screen, the pixel shader samples the depth values around the current pixel and tries to compute the amount of occlusion from each of the sampled points.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;How can depth values of surrounding pixels tell you something about occlusion? &lt;strong&gt;Occlusion&lt;/strong&gt;, as I understand, happens when an object A stands in front of another object B, so you cannot see the object B. But why would you now look at the depth pixels of &lt;strong&gt;surrounding&lt;/strong&gt; pixels? I mean you can see those pixels, so there is no occlusion. Maybe I understood occlusion wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And what I also did not understand is the term kernel in some other tutorials. What is a kernel and why would you use it for ssao?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone make a detailed explanation of the algorithm, with regard to my questions?&lt;/p&gt;&#xA;" OwnerUserId="480" LastEditorUserId="127" LastEditDate="2015-08-31T07:00:54.113" LastActivityDate="2016-03-12T00:10:18.600" Title="How is screen space ambient occlusion implemented?" Tags="&lt;algorithm&gt;&lt;lighting&gt;&lt;shading&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="377" PostTypeId="1" AcceptedAnswerId="382" CreationDate="2015-08-31T01:58:54.870" Score="9" ViewCount="16311" Body="&lt;p&gt;How do they work and what are the differences between them? In what scenario should you use which one?&lt;/p&gt;&#xA;" OwnerUserId="480" LastActivityDate="2015-08-31T08:46:16.797" Title="Shading: Phong vs Gouraud vs Flat" Tags="&lt;algorithm&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="378" PostTypeId="2" ParentId="374" CreationDate="2015-08-31T02:12:03.533" Score="15" Body="&lt;p&gt;First off, here's the Kajiya method I think you're thinking of: Kajiya, &lt;em&gt;Ray Tracing Parametric Patches&lt;/em&gt;, SIGGRAPH 82. &lt;a href=&quot;http://core.ac.uk/download/pdf/4891798.pdf&quot;&gt;The tech report version&lt;/a&gt; might be more informative.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I hope you get from that is that it's not impossible and it's not conceptually difficult if you don't mind getting your hands dirty with some algebraic geometry and complex numbers. However, doing it directly is absurdly expensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Real&quot; ray tracers tend to do some combination of two things:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Placing a bounding hierarchy (e.g. AABBs) on the patch to get a good &quot;initial value&quot; for a numeric root finder. If you do this well, you can avoid the &quot;wrinkle&quot; problem.&lt;/li&gt;&#xA;&lt;li&gt;Tesselating the patch into &lt;a href=&quot;http://ddg.cs.columbia.edu&quot;&gt;DDG shells&lt;/a&gt; and ray tracing them like polygon meshes.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;That last point sounds like it kills the &quot;super-smoothness&quot; requirement, but it isn't nearly as bad as that if you're using &lt;a href=&quot;https://graphics.stanford.edu/papers/trd/&quot;&gt;ray differentials&lt;/a&gt;. Matching the tessellation level to the &quot;size&quot; of the ray bounds the error nicely. Besides, you probably need differentials for texture coordinates anyway, so you might as well use it to control the accuracy of the intersection test too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Exploiting temporal coherence isn't a bad idea, but exactly how you'd do that depends a lot on your scene graph representation. You might want to look at ray coherence. Ask your favourite search engine about &lt;a href=&quot;http://cseweb.ucsd.edu/~ravir/whitted.pdf&quot;&gt;ray packet tracing&lt;/a&gt; and &lt;a href=&quot;https://graphics.stanford.edu/~boulos/papers/reorder_rt08.pdf&quot;&gt;ray reordering&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="159" LastActivityDate="2015-08-31T02:12:03.533" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="379" PostTypeId="2" ParentId="375" CreationDate="2015-08-31T04:28:42.567" Score="13" Body="&lt;p&gt;In this context, &lt;code&gt;Ambient lighting&lt;/code&gt; refers to a very crude approximation of indirect lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Direct lighting from a direct source is relatively simple to evaluate and model, even in real-time. But the light that is not absorbed will bounce all over the place and cause indirect lighting. This is why for example a lamp will a lampshade will light a whole room and not only the narrow area underneath.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But modeling indirect lighting is difficult and costly. So an approximation is to consider that lighting to be &lt;strong&gt;constant and independent from position&lt;/strong&gt;: that's ambient lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of outdoor scene, ambient lighting would represent the blue light coming from the sky dome, as opposed to the orange direct light coming from the Sun.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2015-08-31T04:28:42.567" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="380" PostTypeId="2" ParentId="375" CreationDate="2015-08-31T04:42:14.127" Score="14" Body="&lt;p&gt;Traditional rendering solutions do not do account for secondary light bounces (called indirect light). Even with strategically placed fill lights you still have areas where none of the direct light hits.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambient light tries to solve this problem by shining by a constant amount in all directions. In practice this means that light position or surface normal has no meaning, one just adds some of the shaders color multiplied by ambient light color to the shading result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambient light has a tendency to look artificial when overused. But the opposite problem is that surfaces look like they are on outer space. Ambient light also makes the difference between dark materials and light materials more apparent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eQWU1.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eQWU1.gif&quot; alt=&quot;Ambient light&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1:&lt;/strong&gt; Image without ambient light (left) looks like it was shot in space. Image with ambient (right) looks more natural, although possibly a bit flat if overused.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The real problem is that ambient light does not really exist. Even if youd argue that its useful model, it certainly is not uniform. Its just a quick fix. Therefore all kinds of tricks, like ambient occlusion, have been proposed to enhance the quality of ambient light.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-08-31T11:31:51.543" LastActivityDate="2015-08-31T11:31:51.543" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="382" PostTypeId="2" ParentId="377" CreationDate="2015-08-31T08:46:16.797" Score="13" Body="&lt;p&gt;Flat shading is the simplest shading model.  Each rendered polygon has a single normal vector; shading for the entire polygon is constant across the surface of the polygon.  With a small polygon count, this gives curved surfaces a faceted look.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Phong shading is the most sophisticated of the three methods you list.  Each rendered polygon has one normal vector per vertex; shading is performed by interpolating the vectors across the surface and computing the color for each point of interest.  Interpolating the normal vectors gives a reasonable approximation to a smoothly-curved surface while using a limited number of polygons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gourard shading is in between the two: like Phong shading, each polygon has one normal vector per vertex, but instead of interpolating the vectors, the color of each vertex is computed and then interpolated across the surface of the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On modern hardware, you should either use flat shading (if speed is everything) or Phong shading (if quality is important).  Or you can use a programmable-pipeline shader and avoid the whole question.&lt;/p&gt;&#xA;" OwnerUserId="158" LastActivityDate="2015-08-31T08:46:16.797" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="383" PostTypeId="2" ParentId="372" CreationDate="2015-08-31T19:56:41.090" Score="11" Body="&lt;p&gt;This issue looks like standard shadow map acne artifacts. Additionally your's lighting equation is incomplete or wrong. Light shouldn't influence faces with normals facing away from it. This also means that with a proper equation the &quot;dark&quot; side of the sphere shouldn't have any acne artifacts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are three sources of acne artifacts:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;First acne source is shadow map precision. Make sure that near and far planes of shadow casting light are as tight as possible. All objects before the near plane can be pancaked, as their exact depth isn't important.&lt;/li&gt;&#xA;&lt;li&gt;Second acne source is shadow map resolution. For a directional light you should be doing cascaded shadow maps with at least 3 1024x1012 cascades for ~100-200m of shadow distance. It's hard to cover similar shadow distance with one shadow map with uniform projection.&lt;/li&gt;&#xA;&lt;li&gt;Third acne source is wide shadow map filter like PCF, as using a single depth depth comparison value across a wide kernel is insufficient. There are many methods to fix it, but none of them is robust.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;To sum up, a tight frustum with a few cascades and some bias tweaking is enough to get the general case working (directional light). Start tweaking by disabling shadow filtering and tweak for filtering only when basic shadow maps are robust enough. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally apart from the constant depth bias (which you currently use) you should also add slope depth bias and max slope depth bias. Both can be be implemented either as render state or as shader code during shadowmap rendering. Slope depth bias is simply a magic bias value scaled by dot( normal, lightDir ).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are some additional interesting methods and most of them are implemented in the excellent demo: &lt;a href=&quot;https://mynameismjp.wordpress.com/2013/09/10/shadow-maps/&quot;&gt;Matt Pettineo - &quot;A sampling of shadow techniques&quot;&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Flip culling during shadow map rendering (trades acne for Peter panning).&lt;/li&gt;&#xA;&lt;li&gt;Normal offset shadow mapping does wonders for bias issues, but requires to have vertex normals around during shading.&lt;/li&gt;&#xA;&lt;li&gt;Variance based methods (ESM, VSM, EVSM) completely remove bias issues, but have other drawbacks (light leaking and/or performance issues).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="93" LastEditorUserId="93" LastEditDate="2015-08-31T22:01:39.200" LastActivityDate="2015-08-31T22:01:39.200" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="385" PostTypeId="2" ParentId="376" CreationDate="2015-08-31T21:43:48.277" Score="5" Body="&lt;p&gt;As Alan and trichoplax mention in the comments, the effect that ambient occlusion simulates is not the occlusion of a surface from the camera but the surface’s occlusion from its surroundings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think of it this way: say you have even illumination coming from every direction, so that the total incoming light at any point sums up to a value of 1. If you place a flat plane in that environment and look at one side of it, that side is going to receive 50% of that illumination, or 0.5, because the other half is blocked by the plane itself. In other words, any point on the plane’s surface can only “see” the light coming from half of the environment, so it’s half as brightly illuminated. If you fold that plane towards your viewpoint (a “valley” fold), then you decrease the incoming illumination to that side of the plane further, to some value below 0.5, because, again, each point on the plane “sees” a bit less of the light coming from the surroundings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Screen-space ambient occlusion works more or less by looking for these “folds”—areas where the depth changes sharply, as defined by comparing the depths of neighboring pixels—and darkening them to simulate the decreased illumination from the points’ environment.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2015-08-31T23:07:44.043" LastActivityDate="2015-08-31T23:07:44.043" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="386" PostTypeId="2" ParentId="356" CreationDate="2015-08-31T22:03:38.707" Score="19" Body="&lt;p&gt;Whether it's a tile based GPU or not doesn't really affect the texture cache architecture. The memory layout of texture will look like some flavor of &lt;a href=&quot;https://en.wikipedia.org/wiki/Z-order_curve&quot;&gt;Morton order&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Hilbert_curve&quot;&gt;Hilbert curve&lt;/a&gt; in all GPUs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a result, it's more efficient to render triangles that are close to equilateral triangles because GPU memory system fetches cache lines of texels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So obviously on tile borders, it may happen that you have to fetch texels twice. This has a small cost as tile borders are only &quot;few&quot; pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Arguably desktop GPUs behave identically to tile based GPUs as experiments such as the following demonstrate:&#xA;&lt;a href=&quot;http://www.g-truc.net/post-0597.html&quot;&gt;http://www.g-truc.net/post-0597.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The size of the tiles differ but both architecture actually process fragments into a hierarchy of tiles of different sizes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When coding for tile based GPUs my recommendation is to always have in mind:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Don't switch framebuffer objects unless you &lt;em&gt;really&lt;/em&gt; need to.&lt;/li&gt;&#xA;&lt;li&gt;When binding a new framebuffer object, if you don't need to save the content of the current framebuffer, discard it. If don't want to load content of the new framebuffer, then you should clear the framebuffer.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="511" LastEditorUserId="511" LastEditDate="2015-09-09T21:13:03.580" LastActivityDate="2015-09-09T21:13:03.580" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="387" PostTypeId="1" AcceptedAnswerId="390" CreationDate="2015-08-31T22:59:35.523" Score="8" ViewCount="463" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Ambient_occlusion&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ambient occlusion&lt;/a&gt; &quot;is a shading and rendering technique used to calculate &lt;strong&gt;how exposed&lt;/strong&gt; each point in a scene is &lt;strong&gt;to ambient lighting&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambient lighting is regarding to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/375/what-is-ambient-lighting/&quot;&gt;What is ambient lighting?&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;... lighting to be constant and independent from position: that's ambient&#xA;  lighting.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If ambient lighting has no fixed position, how can points then be more or less &lt;strong&gt;exposed&lt;/strong&gt; to it? Ambient lighting is &quot;&lt;a href=&quot;https://computergraphics.stackexchange.com/a/380/480&quot;&gt;shining by a constant amount in all directions.&lt;/a&gt;&quot; So if the light is coming from &lt;strong&gt;all directions&lt;/strong&gt;, every point should be exposed by &lt;strong&gt;the same factor&lt;/strong&gt; to the ambient lighting.&lt;/p&gt;&#xA;" OwnerUserId="480" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-09-01T11:26:19.687" Title="What is ambient occlusion?" Tags="&lt;shading&gt;&lt;ambient-occlusion&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="388" PostTypeId="1" AcceptedAnswerId="389" CreationDate="2015-08-31T23:13:35.870" Score="6" ViewCount="3264" Body="&lt;p&gt;&lt;a href=&quot;http://whatis.techtarget.com/definition/occlusion&quot; rel=&quot;noreferrer&quot;&gt;Occlusion&lt;/a&gt; &quot;is the effect of one object in a 3-D space blocking another object from view.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With this definiton in mind I cannot understand sentences like:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The interior of a tube is typically &lt;strong&gt;more occluded&lt;/strong&gt; (and hence darker)&#xA;  than the exposed outer surfaces, and the deeper you go inside the&#xA;  tube, &lt;strong&gt;the more occluded&lt;/strong&gt; (and darker) the lighting becomes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Occlusion is for me a question of &lt;strong&gt;yes or no&lt;/strong&gt;. Yes an object/point is in front of another, or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how can some points be &lt;strong&gt;more&lt;/strong&gt; or &lt;strong&gt;less&lt;/strong&gt; occluded then others? I think I need another definiton for occlusion. &lt;/p&gt;&#xA;" OwnerUserId="480" LastEditorUserId="480" LastEditDate="2015-08-31T23:32:18.633" LastActivityDate="2015-08-31T23:39:22.343" Title="What is occlusion?" Tags="&lt;occlusion&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="389" PostTypeId="2" ParentId="388" CreationDate="2015-08-31T23:39:22.343" Score="8" Body="&lt;p&gt;This quote sounds like it may relate to &lt;a href=&quot;https://en.wikipedia.org/wiki/Ambient_occlusion&quot;&gt;ambient occlusion&lt;/a&gt;, which is the shielding of a surface from the light approaching from all angles. Direct lighting requires that the light source have a straight line route to the surface being lit, whereas ambient lighting is the result of light approaching along many different paths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine the whole of a cloudy sky as a light source. Each point on a surface is lit according to the proportion of the sky that can directly light it. The floor next to a wall might only be able to be lit by half the sky, so will be half as bright. In this situation you could say that half of the sky is occluded, leaving only half to light the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly with a tube. At the entrance of the tube, 50% of the sky may be able to light it. Further inside the tube only the small patch of sky visible through the end of the tube can light it, and that patch becomes smaller the further you go into the tube. The lighting in the tube therefore diminishes the further you go in.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-31T23:39:22.343" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="390" PostTypeId="2" ParentId="387" CreationDate="2015-08-31T23:55:57.460" Score="6" Body="&lt;p&gt;Your point is correct when applied to &lt;a href=&quot;https://en.wikipedia.org/wiki/Shading#Ambient_lighting&quot;&gt;ambient lighting&lt;/a&gt; as an approximation technique. This crude approach does indeed give the same lighting level to all surfaces regardless of their surroundings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, &lt;a href=&quot;https://en.wikipedia.org/wiki/Ambient_occlusion&quot;&gt;ambient occlusion&lt;/a&gt; is a different (less crude) approach, that models how the light levels in a real scene vary depending on how much reflected light can reach a surface. The confusion is due to two very different approaches having similar names.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambient occlusion is a much better approximation of what in real life is described as ambient light - light that arrives from the background rather than directly from a light source.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If ambient lighting has no fixed position, how can points then be more or less exposed to it?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;When used in the context of ambient occlusion, the term &quot;ambient lighting&quot; still means background light approximated as being the same in all directions, but the surface is lit based on how many of those directions are not occluded by objects in the scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This gives subtly varying light levels that give much more realistic images than with a single level of ambient lighting. This gives the effects seen in real life such as the corners of a room being slightly darker than elsewhere.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2015-08-31T23:55:57.460" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="391" PostTypeId="1" AcceptedAnswerId="392" CreationDate="2015-09-01T00:39:04.890" Score="21" ViewCount="9696" Body="&lt;p&gt;What are Affine Tranformations? Do they apply just to points or to other shapes as well? What does it mean that they can be &quot;composed&quot;?&lt;/p&gt;&#xA;" OwnerUserId="482" LastActivityDate="2016-10-03T18:00:25.803" Title="What are Affine Transformations?" Tags="&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="392" PostTypeId="2" ParentId="391" CreationDate="2015-09-01T00:39:04.890" Score="23" Body="&lt;p&gt;An Affine Transform is a Linear Transform + a Translation Vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}x'&amp;amp; y'\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}x&amp;amp; y\end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix}a&amp;amp; b \\ c&amp;amp;d\end{bmatrix}&#xA;+&#xA;\begin{bmatrix}e&amp;amp; f\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It can be applied to individual points or to lines or even Bezier curves. For lines, it preserves the property that parallel lines remain parallel. For Bezier curves, it preserves the convex-hull property of the control points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Multiplied-out, it produces 2 equations for yielding a &quot;transformed&quot; coordinate pair $(x', y')$ from the original pair $(x, y)$ and a list of constants $(a, b, c, d, e, f)$.&#xA;$$&#xA;    x' =  a\cdot x + c\cdot y + e \\&#xA;    y' =  b\cdot x + d\cdot y + f&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Conveniently, the Linear transform and the Translation vector can be put together into a 3D matrix which can operate over 2D homogeneous coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}x'&amp;amp; y'&amp;amp;1\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}x&amp;amp; y&amp;amp;1\end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix}a&amp;amp; b &amp;amp;0\\ c&amp;amp;d&amp;amp;0 \\ e&amp;amp;f&amp;amp;1\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which yields the same 2 equations above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Very conveniently&lt;/em&gt;, the matrices themselves can be multiplied together to produce a third matrix (of constants) which performs the same transformation as the original 2 would perform in sequence. Put simply, the matrix multiplications are associative.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{matrix}&#xA;\begin{bmatrix}x''&amp;amp; y''&amp;amp;1\end{bmatrix}&#xA;&amp;amp; = &amp;amp;&#xA;\left(&#xA;\begin{bmatrix}x&amp;amp; y&amp;amp;1\end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix}a&amp;amp; b &amp;amp;0\\ c&amp;amp;d&amp;amp;0 \\ e&amp;amp;f&amp;amp;1\end{bmatrix}\right)&#xA;\cdot&#xA;\begin{bmatrix}g&amp;amp; h &amp;amp;0\\ i&amp;amp;j&amp;amp;0 \\ k&amp;amp;m&amp;amp;1\end{bmatrix}&#xA;\\&#xA;&amp;amp; = &amp;amp;&#xA;\begin{bmatrix}a \cdot x + c \cdot y+e &amp;amp; b \cdot x + d \cdot y+f &amp;amp;1 \end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix}g&amp;amp; h &amp;amp;0\\ i&amp;amp;j&amp;amp;0 \\ k&amp;amp;m&amp;amp;1\end{bmatrix}&#xA;\\&#xA;&amp;amp;=&amp;amp;&#xA;\begin{bmatrix}g(a \cdot x + c \cdot y+e) + i( b \cdot x + d \cdot y+f) + k &#xA;\\&#xA;h(a \cdot x + c \cdot y+e) + j( b \cdot x + d \cdot y+f) + m&#xA;\\1 \end{bmatrix}^T&#xA;\\&#xA;&amp;amp;=&amp;amp;&#xA;\begin{bmatrix}x&amp;amp; y&amp;amp;1\end{bmatrix} \cdot&#xA;\left(&#xA;\begin{bmatrix}a&amp;amp; b &amp;amp;0\\ c&amp;amp;d&amp;amp;0 \\ e&amp;amp;f&amp;amp;1\end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix}g&amp;amp; h &amp;amp;0\\ i&amp;amp;j&amp;amp;0 \\ k&amp;amp;m&amp;amp;1\end{bmatrix}&#xA;\right)&#xA;\\&#xA;&amp;amp;=&amp;amp;&#xA;\begin{bmatrix}x&amp;amp; y&amp;amp;1\end{bmatrix} \cdot&#xA;\begin{bmatrix}ag+bi&amp;amp; ah+bj &amp;amp;0\\ cg+di&amp;amp;ch+dj&amp;amp;0 \\ eg+fi+k&amp;amp;eh+fj+m&amp;amp;1\end{bmatrix}&#xA;\end{matrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively you can consider a few basic transform types and compose any more complex transform by combining these (multiplying them together).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Identity transform&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/icgx0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/icgx0.png&quot; alt=&quot;identity transform&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;    1 &amp;amp; 0 &amp;amp; 0 \\&#xA;    0 &amp;amp; 1 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Scaling&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YVdBw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YVdBw.png&quot; alt=&quot;scaling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;    S_x &amp;amp; 0 &amp;amp; 0 \\&#xA;    0  &amp;amp; S_y &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;*Note: a reflection can be performed with scaling parameters $(S_x, S_y) = (-1,1)$ or $(1,-1)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Translation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kH8uS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kH8uS.png&quot; alt=&quot;translation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;    1 &amp;amp; 0 &amp;amp; 0 \\&#xA;    0 &amp;amp; 1 &amp;amp; 0 \\&#xA;    T_x &amp;amp; T_y &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Skew x by y&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gyZCZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gyZCZ.png&quot; alt=&quot;skew x by y&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;    1  &amp;amp; Q_x &amp;amp; 0 \\&#xA;    0 &amp;amp; 1 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Skew y by x&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7zEWw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7zEWw.png&quot; alt=&quot;skew y by x&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;    1  &amp;amp; 0 &amp;amp; 0 \\&#xA;    Q_y &amp;amp; 1 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rotation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ltr0w.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ltr0w.png&quot; alt=&quot;rotation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;    \cos\theta &amp;amp; -sin\theta &amp;amp; 0\\&#xA;    \sin\theta &amp;amp; \cos\theta &amp;amp; 0\\&#xA;    0  &amp;amp;  0 &amp;amp;  1&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[Note I've shown the form of Matrix here which accepts a row vector on the &lt;em&gt;left&lt;/em&gt;. The transpose of these matrices will work with a column vector on the right.]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A matrix composed purely from scaling, rotation, and translation can be &lt;a href=&quot;https://stackoverflow.com/a/11942636/733077&quot;&gt;decomposed back into these three components&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-10-03T18:00:25.803" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="393" PostTypeId="1" AcceptedAnswerId="395" CreationDate="2015-09-01T07:14:36.680" Score="7" ViewCount="485" Body="&lt;p&gt;Last time I see a lot of papers which operates on this words, i.e. &lt;em&gt;stochastic AA&lt;/em&gt;, &lt;em&gt;temporal coherence&lt;/em&gt; etc. What does that means? Can you provide examples with explanations in plain English?&lt;/p&gt;&#xA;" OwnerUserId="386" LastActivityDate="2015-09-01T07:55:02.207" Title="What is the meaning of words 'stochastic', 'temporal' in computer graphics?" Tags="&lt;terminology&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="394" PostTypeId="2" ParentId="393" CreationDate="2015-09-01T07:48:57.517" Score="6" Body="&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Stochastic = Random. Stochastic AA, Anti-aliasing technique based on randomized sample distribution (as opposed to fixed sample pattern). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also see: &lt;a href=&quot;https://en.wikipedia.org/wiki/Monte_Carlo_method&quot;&gt;Monte Carlo Method&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Temporal = depends on time. Temporal coherence, how consistent X is over time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Typically you hear of temporal aliasing, temporal artefacts etc.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-09-01T07:48:57.517" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="395" PostTypeId="2" ParentId="393" CreationDate="2015-09-01T07:55:02.207" Score="7" Body="&lt;ul&gt;&#xA;&lt;li&gt;A stochastic process is one where you gather your samples randomly. So stochastic AA is antialiasing where you gather multiple samples for the same pixel with small random changes.&lt;/li&gt;&#xA;&lt;li&gt;Temporal refers to a process over time. Temporal coherence is for instance mentioned when you have no flickering artifacts, or aliasing that you see during movement. It means that frames are coherent in a certain time window.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="343" LastActivityDate="2015-09-01T07:55:02.207" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="396" PostTypeId="2" ParentId="387" CreationDate="2015-09-01T11:26:19.687" Score="5" Body="&lt;p&gt;Ambient light does not really exist, if we do not talk about cosmology. What we call ambient is just light form many secondary reflections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/b1FF5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/b1FF5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: No ambient light (left) and ambient light (right). Both look artificial.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can approximate ambient light by a constant factor. But this looks slightly washed out as ambient light is not constant over the scene. To make the ambient look better we can use a trick. If we make a hemispherical probe for object coverage (occlusion), we get an estimate of how much the pixel lies inside a cavity. The less you live in cavity the more likely the ambient light is going to hit here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/g57I5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g57I5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: By modulating the ambient light with local geometric occlusion we get a much nicer and realistic contribution of ambient light. Final color and contribution also tweaked slightly (right). Just plain ambient (left).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NOTE: Ambient occlusion component is also used by other phenomena so it can also simulate dirt packing etc. In any case your NOT supposed to multiply ambient occlusion by everything. Quite many tutorials make this mistake. You should add the ambient occlusion to existing image, that is if you only estimate ambient light with it.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-09-01T11:26:19.687" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="397" PostTypeId="1" CreationDate="2015-09-01T13:07:44.900" Score="7" ViewCount="300" Body="&lt;p&gt;Video noise is random and not correlated in time. I assume, the best method is using &lt;strong&gt;wavelet denoise&lt;/strong&gt; in this case, right? If yes, how is wavelet denoise implemented for video? Is there something to consider in order to apply the calculation to the whole image sequence?&lt;/p&gt;&#xA;" OwnerUserId="18" LastActivityDate="2015-09-15T23:13:13.823" Title="How to denoise video?" Tags="&lt;image&gt;&lt;denoise&gt;&lt;video&gt;&lt;image-processing&gt;" AnswerCount="3" CommentCount="7" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="398" PostTypeId="2" ParentId="209" CreationDate="2015-09-01T16:16:10.817" Score="10" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is there a similarly fast way to draw antialiased lines?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, because by definition an anti-aliased line touches more pixels.  Such algorithms will be slower.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In a software rasterizer, the ubiquitous way to draw anti-aliased lines is &lt;a href=&quot;https://en.wikipedia.org/wiki/Xiaolin_Wu&amp;#39;s_line_algorithm&quot;&gt;Xiaolin Wu's line algorithm&lt;/a&gt;.  It's not hard to implement, and anyway there's unusually high-quality pseudocode at that link.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a hardware raster pipe, the line primitive is expanded to a screen-space quad by the default (or user-provided) geometry shader, and then drawn as two triangles, which can then be anti-aliased in the usual ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a raytracer, there are a variety of options.  It's worth thinking about how you actually want to draw a 1D object.  Maybe as a cylinder (woo shadows!).  Note that this introduces issues of perspective/foreshortening which may (or may not) be what you want.  There isn't a clear generalization.  Then, obviously, whatever you do, you just supersample it.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-09-01T16:16:10.817" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="399" PostTypeId="2" ParentId="323" CreationDate="2015-09-01T16:29:40.593" Score="10" Body="&lt;p&gt;As you have probably observed, in general, you cannot solve in closed-form the equations for ray trajectories around multiple distorting objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The standard approach for such things is just to discretize it.  This looks like Eulerian integration.  Just step your ray a little bit toward the object, calculate gravity from all sources and bend it, then step it more, und so weiter.  This is called &lt;em&gt;raymarching&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you're interested in problems on an astrophysical scale, you can assume the ray is linear far enough away from the object, with minimal error.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here's a scene I rendered a while ago using a homebrew photonmapper (no QMC) using this raymarching technique.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I present: relativistic photon mapping: black hole in a Cornell box!&#xA;&lt;a href=&quot;https://i.stack.imgur.com/0rxaX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0rxaX.png&quot; alt=&quot;black hole in a Cornell box&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-09-01T16:29:40.593" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="400" PostTypeId="1" AcceptedAnswerId="402" CreationDate="2015-09-01T18:18:11.607" Score="13" ViewCount="2299" Body="&lt;p&gt;I have a couple of compute shaders that need to be executed in a certain order and whose outputs depend on previous inputs. Ideally, I'll never need to copy a buffer client-side and do all of my work on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider I have two compute shaders compiled and linked as &lt;code&gt;program_one&lt;/code&gt; and &lt;code&gt;program_two&lt;/code&gt;. Suppose I also have a &lt;code&gt;GL_SHADER_STORAGE_BUFFER&lt;/code&gt; that contains the data that is written to by &lt;code&gt;program_one&lt;/code&gt; and read by &lt;code&gt;program_two&lt;/code&gt;. Can I simply do the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glUseProgram(program_one);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer);&#xA;glDispatchCompute(16, 16, 1);&#xA;&#xA;glUseProgram(program_two);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, index, buffer);&#xA;glDispatchCompute(16, 16, 1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is it guaranteed that all invocations of the first compute shader will finish before any invocations of the second (to avoid data races between reading and writing &lt;code&gt;buffer&lt;/code&gt;)? If not, how do I synchronize them?&lt;/p&gt;&#xA;" OwnerUserId="197" LastActivityDate="2015-09-01T20:07:25.123" Title="Synchronizing successive OpenGL Compute Shader invocations" Tags="&lt;opengl&gt;&lt;compute-shader&gt;&lt;gpgpu&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="401" PostTypeId="2" ParentId="397" CreationDate="2015-09-01T19:15:45.790" Score="3" Body="&lt;p&gt;Elaboration on temporal solve:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't have much concrete info for you, but I'm drawing from the idea of &quot;temporal anti aliasing&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, if a camera was stationary, you could average pixel values over the last N frames, possibly using harmonic mean or something else like that to help filter out spikes.  The result would be a cleaner, less noisy, more correct image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But not all cameras (or objects!) are stationary, so what then?  Well, if you have some way of identifying where a pixel this frame matches a pixel on the previous N frames, you could average them in the same way.  If a current pixel has no matching previous pixel (due to something previously occluding becoming visible) you just show the raw current value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Games use this for antialiasing by simulating super sampling over time, but they have the benefit of per pixel motion vectors as well as the current and previous camera matrix, so it's a lot harder in your situation!&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-09-01T20:03:34.453" LastActivityDate="2015-09-01T20:03:34.453" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="402" PostTypeId="2" ParentId="400" CreationDate="2015-09-01T20:07:25.123" Score="13" Body="&lt;p&gt;No it is not guaranteed, since the OpenGL specification allows that two Compute Shader run concurrently or even in different order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You need to call &lt;code&gt;glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT)&lt;/code&gt; before the second &lt;code&gt;glDispatchCompute&lt;/code&gt; to ensure visibility of the writes from &lt;code&gt;program_one&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/wiki/Memory_Model&quot;&gt;From the OpenGL.org wiki article on the memory model&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;[...] invocations between stages may be executed in any order. &lt;strong&gt;This includes invocations launched by different rendering commands.&lt;/strong&gt; While it is perhaps unlikely that two vertex shaders from different rendering operations could be running at the same time, it is also possible, so OpenGL provides &lt;strong&gt;no guarantees&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/wiki/Shader_Storage_Buffer_Object&quot;&gt;From the Opengl.org wiki article on Shader Storage Buffer&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;SSBOs reads and writes use incoherent memory accesses, so they need the appropriate barriers, just as Image Load Store operations.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="528" LastActivityDate="2015-09-01T20:07:25.123" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="403" PostTypeId="2" ParentId="214" CreationDate="2015-09-02T01:54:45.520" Score="5" Body="&lt;p&gt;It sounds like you're trying to do adaptive subdivision on the surface of a hemisphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This has indeed been tried before, although perhaps not in the exact way you're thinking.  Usually for hemispheric integration, people use some well-distributed, pre-defined sampling density over the hemisphere and forget about adaptive subdivision.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;But you may be missing the point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The whole idea of doing such things is to get a better estimate of the integral.  But it's not the integral over the hemisphere you care about.  You're integrating over the pixel to get AA, over the aperture to get depth-of-field, over the lights to get soft-shadowing, over the hemisphere to get GI, over time to get motion blur, over wavelength to get dispersion, and so on.  You're integrating over all that.  This is an absurdly high-dimensional space, and decades of development have shown that you need to be exploring it not more carefully, but &lt;em&gt;faster&lt;/em&gt;.  That is, you get better results from breadth, not depth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All very abstract.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The point is this: you don't want to sample over the hemisphere with lots of samples.  You want to sample over your hemisphere with &lt;em&gt;one&lt;/em&gt; sample and then &lt;em&gt;move on&lt;/em&gt;.  This is called path tracing.  It differs from ray tracing in that the maximum width of the ray tree is 1 (or maybe 2).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The key insight is that if your random samples are well-distributed with respect to all dimensions, other rays will &quot;fill-in&quot; the rest of your missing tree.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For an intuitive example: say you're doing 4x AA.  So you shoot four rays through a pixel.  Probably, they hit in very similar points (creating similar reflectance hemispheres).  Then, they each shoot exactly one recursive ray.  But, since the four hemispheres are in almost the same place, the recursive rays (kindof) count for &lt;em&gt;all&lt;/em&gt; the hemispheres.  So each of the four paths gets some of the benefit of the other three.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's sortof handwavy math, but since each path is actually independent of the others, and the color you get is an unbiased estimate of the entire scene's illumination, averaging them together is unbiased.  It just converges much faster in practice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously, if a cheap estimate of the hemisphere's integral is available, you can just use that--this is preintegration (cone tracing, etc.), importance sampling (next event estimation, light sampling), or better paths (BDPT, photon mapping)--but for a simple approach, it's basically always better to use path tracing instead of stochastic ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;Also &lt;code&gt;matt&lt;/code&gt; -&gt; &lt;code&gt;matte&lt;/code&gt; (or &lt;code&gt;mat&lt;/code&gt;, in a pinch).  It's a French loanword, not a person's name, and I don't care what the American dictionaries say.&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-09-02T01:54:45.520" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="404" PostTypeId="2" ParentId="357" CreationDate="2015-09-02T01:59:37.613" Score="8" Body="&lt;p&gt;The answer depends on what you mean.  Modern hardware (e.g. with bindless textures) really doesn't care too much how many textures are &quot;bound&quot;.  The real question is &lt;em&gt;how many you use&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Textures generally store data in a cache-friendly way (a Morton curve, I believe).  If you use more textures, you'll get more cache misses, since now the textures compete with each other for space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This really just comes down to the well-known, old shader programming heuristic: texture taps are slow; don't use too many.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-09-02T01:59:37.613" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="405" PostTypeId="1" CreationDate="2015-09-02T03:23:51.497" Score="14" ViewCount="628" Body="&lt;p&gt;In my answer about &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/391/what-are-affine-transformations/392#392&quot;&gt;Affine Transformations&lt;/a&gt; I made some little illustrations to help the explanation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ltr0w.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do you make an upload-able PNG quickly which expresses a geometrical or mathematical idea?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;This question was contrived to support my postscript answer but is intended to solicit other solutions that may benefit the SE network more generally. But for credibility, an answer must link to a post where this technique has in fact been used, as well as a sufficient &quot;howto&quot; portion if it involves more than something obvious like &quot;Select export from menu&quot;.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;There are two meta questions &lt;a href=&quot;https://computergraphics.meta.stackexchange.com/questions/147/simple-2d-illustrations-question-main-or-meta&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://computergraphics.meta.stackexchange.com/questions/150/2d-illustrations-question-help-crafting-the-question&quot;&gt;here&lt;/a&gt; concerning how to scope this question in light of the precedences it may set for our site.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2018-03-20T15:55:51.140" Title="How to produce simple 2D illustrations to accompany geometry answers?" Tags="&lt;2d&gt;" AnswerCount="6" CommentCount="9" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="406" PostTypeId="2" ParentId="405" CreationDate="2015-09-02T03:23:51.497" Score="4" Body="&lt;h1&gt;PostScript+ps2eps+mogrify&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;For the &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/391/what-are-affine-transformations/392#392&quot;&gt;Affine Transformations answer&lt;/a&gt;, I wrote a very small postscript program and then saved several copies under different names and edited each one to do each different task: scale, translate, rotate. For example, here's the basic one, &lt;code&gt;ident.ps&lt;/code&gt; which does nothing to change the coordinates between the red drawing and the black drawing. I made the red lines a little larger and always draw it first, so the two show up nicely superposed and visible (IMO). I previewed with ghostscript with the vi (ex) command &lt;code&gt;:!gs %&lt;/code&gt;. (&lt;a href=&quot;https://groups.google.com/d/topic/comp.lang.postscript/m2QqV4QFFaM/discussion&quot; rel=&quot;nofollow noreferrer&quot;&gt;all source files&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;%!&#xA;/axis {&#xA;    currentpoint 4 { &#xA;        2 copy moveto&#xA;            50 0 lineto&#xA;            90 rotate&#xA;    } repeat pop pop &#xA;} def &#xA;/shape {&#xA;    20 0 moveto&#xA;    30 20 lineto&#xA;    40 0 lineto&#xA;    closepath&#xA;} def &#xA;&#xA;100 100 translate&#xA;&#xA;gsave&#xA;% do transform here&#xA;currentlinewidth 1.5 mul setlinewidth&#xA;1 0 0 setrgbcolor&#xA;0 0 moveto axis shape stroke&#xA;grestore&#xA;&#xA;0 0 moveto axis shape stroke&#xA;&#xA;showpage&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I then used the &lt;code&gt;ps2eps&lt;/code&gt; command from &lt;code&gt;psutils&lt;/code&gt; to calculate bounding-boxes automatically&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ ps2eps -f *.ps&#xA;Input files: ident.ps rotate.ps scale.ps skewx.ps skewy.ps translate.ps&#xA;Processing: ident.ps&#xA;Calculating Bounding Box...ready. %%BoundingBox: 50 50 150 150&#xA;Creating output file ident.eps ... ** Warning **: Weird heading line -- %! -- ready.&#xA;Processing: rotate.ps&#xA;Calculating Bounding Box...ready. %%BoundingBox: 50 50 150 150&#xA;Creating output file rotate.eps ... ** Warning **: Weird heading line -- %! -- ready.&#xA;Processing: scale.ps&#xA;Calculating Bounding Box...ready. %%BoundingBox: 25 25 175 175&#xA;Creating output file scale.eps ... ** Warning **: Weird heading line -- %! -- ready.&#xA;Processing: skewx.ps&#xA;Calculating Bounding Box...ready. %%BoundingBox: 50 49 150 151&#xA;Creating output file skewx.eps ... ** Warning **: Weird heading line -- %! -- ready.&#xA;Processing: skewy.ps&#xA;Calculating Bounding Box...ready. %%BoundingBox: 49 50 151 150&#xA;Creating output file skewy.eps ... ** Warning **: Weird heading line -- %! -- ready.&#xA;Processing: translate.ps&#xA;Calculating Bounding Box...ready. %%BoundingBox: 50 50 165 165&#xA;Creating output file translate.eps ... ** Warning **: Weird heading line -- %! -- ready.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And finally used imagemagick's &lt;code&gt;convert&lt;/code&gt; command to produce cropped png images. (I didn't think of a quick way to automate this part. &lt;em&gt;Edit:&lt;/em&gt; as commented, this can be done with &lt;code&gt;mogrify -format png *.eps&lt;/code&gt;. Thanks, joojaa!)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ convert ident.eps ident.png&#xA;&#xA;josh@cadabra ~/affine&#xA;$ convert scale.eps scale.png&#xA;&#xA;josh@cadabra ~/affine&#xA;$ convert rotate.eps rotate.png&#xA;&#xA;josh@cadabra ~/affine&#xA;$ convert skewx.eps skewx.png&#xA;&#xA;josh@cadabra ~/affine&#xA;$ convert translate.eps translate.png&#xA;&#xA;josh@cadabra ~/affine&#xA;$ convert skewy.eps skewy.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which produces PNGs, ready to upload.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ ls -l *.png&#xA;-rw-r--r-- 1 josh None  587 Sep  1 21:16 ident.png&#xA;-rw-r--r-- 1 josh None 1431 Sep  1 21:21 rotate.png&#xA;-rw-r--r-- 1 josh None  798 Sep  1 21:19 scale.png&#xA;-rw-r--r-- 1 josh None 1133 Sep  1 21:22 skewx.png&#xA;-rw-r--r-- 1 josh None 1197 Sep  1 21:23 skewy.png&#xA;-rw-r--r-- 1 josh None  756 Sep  1 21:23 translate.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/gyZCZ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-09-02T21:26:53.980" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="407" PostTypeId="1" AcceptedAnswerId="422" CreationDate="2015-09-02T11:40:47.137" Score="7" ViewCount="305" Body="&lt;p&gt;I am currently working on some simple pixel shader in HLSL. I send to shader texture and I want to make it more colorful (something like in the picture below). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AvcUu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AvcUu.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the picture 1 there is original texture. Picture 2 shows an effect that I want to achieve. Is there some mathematical formula to do that? My input is the RGBA value of each pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;I'll try to write more concrete. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say I want to make that garden texture more red. I suppose that what I need to do is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;OutputR = InputR * X,&#xA;&#xA;OuputG = InputG * Y,&#xA;&#xA;OutputB = InpputB * Z&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But how do I find X, Y and Z?&lt;/p&gt;&#xA;" OwnerUserId="205" LastEditorUserId="171" LastEditDate="2017-05-18T18:45:01.277" LastActivityDate="2017-05-18T18:45:01.277" Title="Changing image so it would look like through colorful glasses" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;image-processing&gt;&lt;hlsl&gt;&lt;pixel-shader&gt;" AnswerCount="3" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="408" PostTypeId="2" ParentId="407" CreationDate="2015-09-02T11:58:46.027" Score="3" Body="&lt;p&gt;Choose the color RGB of your colorful glasses and choose how transparent they are by choosing an alpha value A. Then &lt;a href=&quot;https://en.wikipedia.org/wiki/Alpha_compositing&quot; rel=&quot;nofollow&quot;&gt;alpha composite&lt;/a&gt; the glasses on top of the input image:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;OutputR = R * A + InputR * (1-A)&#xA;OutputG = G * A + InputG * (1-A)&#xA;OutputB = B * A + InputB * (1-A)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="192" LastEditorUserId="192" LastEditDate="2015-09-02T12:01:17.487" LastActivityDate="2015-09-02T12:01:17.487" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="409" PostTypeId="2" ParentId="374" CreationDate="2015-09-02T12:40:38.147" Score="5" Body="&lt;p&gt;Another option, which I used a couple of decades ago (yikes!), is to use  &lt;a href=&quot;https://www.cs.drexel.edu/~david/Classes/CS586/Papers/p171-toth.pdf&quot; rel=&quot;nofollow&quot;&gt;Toth's scheme from 1985&lt;/a&gt; that employed interval arithmetic to narrow down the search space. IIRC, eventually it will resort to Newton-Rhapson but, again IIRC, I think it rarely required more than one or two steps to get to a good solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though I haven't looked at it (well, apart from a quick glance) &lt;a href=&quot;http://mentallandscape.com/Papers_graphicsinterface90b.pdf&quot; rel=&quot;nofollow&quot;&gt;Mitchell&lt;/a&gt; has published some more recent work on ray tracing with interval maths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;(I should add that, if you are only doing Bezier surfaces, then the interval method might be a bit &quot;overkill&quot; since you can use tricks like blossoming to get bounds and derivatives. If, however, you combine Bezier curves with other functions, e.g. rotation around an axis, then its generality is more useful.)&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2015-09-03T16:41:57.353" LastActivityDate="2015-09-03T16:41:57.353" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="410" PostTypeId="2" ParentId="407" CreationDate="2015-09-02T13:47:43.743" Score="13" Body="&lt;p&gt;(XYZ) can be the RGB colour you want to tint your scene by. For the above scene it can be a red colour (1.0, 0.0, 0.0) or something similar with a strong red component. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bear in mind that since you are applying the colour in a multiplicative way it will act as a filter suppressing original colour components. So if your scene is mostly green but you apply (i.e. multiply it with) a red filter (1,0,0) the resulting scene will be very dark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A trick you could potentially do in such cases is to desaturate the original scene and then multiply it by the tint colour. That way you will keep the overall image intensity and achieve the colour tint you require.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, here is the image multiplied by (1, 0, 0), (1, 0.2, 0.2), and (1, 0.5, 0.5) from left to right:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/N4YCV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N4YCV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/95LBW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/95LBW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/mkIgR.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mkIgR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="270" LastEditorUserId="48" LastEditDate="2015-09-03T05:29:26.583" LastActivityDate="2015-09-03T05:29:26.583" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="411" PostTypeId="1" CreationDate="2015-09-02T15:02:06.727" Score="3" ViewCount="162" Body="&lt;p&gt;I've inherited a system which animates a humanoid avatar by loading various models and manually calculating transformations for each one. I'm in the process of porting part of this system to Three.js, and rather than port the manual calculations across I'd prefer to pre-compose an articulated model and let the engine handle the transformations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any software which would let me import the existing models, define the bone hierarchy and the model which corresponds to each bone, and export a single articulated model in T-pose?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For what it's worth, I have access to both Windows and Linux, and if really necessary I can probably obtain access to OS X. The original models are in FBX format, but I have managed to export them to Three.js files, so I could import from either format.&lt;/p&gt;&#xA;" OwnerUserId="540" LastEditorUserId="540" LastEditDate="2015-09-02T15:11:55.147" LastActivityDate="2018-04-09T08:58:15.113" Title="Software to compose separate models into an articulated model?" Tags="&lt;transformations&gt;&lt;3d&gt;&lt;animation&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="412" PostTypeId="2" ParentId="324" CreationDate="2015-09-02T21:44:15.287" Score="5" Body="&lt;p&gt;You approach will work, and in general any square of size &amp;lt; &lt;a href=&quot;https://i.stack.imgur.com/sYEU8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sYEU8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; will work fine because the invariant &quot;at most 1 point per square&quot; is valid. Extrapolating from your idea, it means that one should get the best reduction in area checks for infinitesimally small squares. But we don't want to do that, right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two reasons why &lt;a href=&quot;https://i.stack.imgur.com/SnBBv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SnBBv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; is usually better than &lt;a href=&quot;https://i.stack.imgur.com/qH0GY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qH0GY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;How much state do you want to manage? Each square can either be &quot;occupied&quot; or &quot;unoccupied&quot; and contains a pointer to its sample point (if any).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For very large domains with small r, storage costs can be hard to manage. The problem is much worse if you're working with many dimensions. See &lt;a href=&quot;http://staffwww.dcs.shef.ac.uk/people/S.Maddock/research/gamito/papers/poisson.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Gamito et al.'s paper&lt;/a&gt;, Figure 12. Even in 4D you can be severely storage limited.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;In your proposed grid size, each candidate points checks 24 squares, as opposed to 20 in the usual method. There is a per-square cost (e.g. checking whether square is occupied and fetching sample point if it is) which increases the overall cost in your method.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Basically, your method works, but it is usually not more efficient.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the state of the art in unbiased Poisson-disk sampling techniques actually successively reduces the grid size as the uncovered area reduces. In addition to &lt;a href=&quot;http://staffwww.dcs.shef.ac.uk/people/S.Maddock/research/gamito/papers/poisson.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Gamito et al.'s paper&lt;/a&gt;, also see &lt;a href=&quot;http://www.sandia.gov/~samitch/papers/eurographics_mps-final-with-appendix.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ebeida et al.'s paper&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. Sorry, I don't know how to do math formatting in Stack Exchange.&lt;/p&gt;&#xA;" OwnerUserId="14" LastEditorUserId="14" LastEditDate="2015-09-08T18:22:51.277" LastActivityDate="2015-09-08T18:22:51.277" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="413" PostTypeId="2" ParentId="405" CreationDate="2015-09-02T21:57:49.120" Score="4" Body="&lt;p&gt;I just use Powerpoint to make such diagrams and it works great as soon as you're comfortable with its basic primitives. It supports all simple operations like rotation, translation, etc. and recent revisions also have shear and 3D transforms. Examples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Hzmcd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Hzmcd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ESDaY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ESDaY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1487/14&quot;&gt;example of a Powerpoint diagram&lt;/a&gt; I made for an answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more complicated diagrams, especially in 3D, I sometimes use Blender with shadeless materials. I can elaborate and show examples if it is relevant to your question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looks like &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/324/is-this-smaller-grid-for-poisson-disc-sampling-still-correct&quot;&gt;jsfiddle&lt;/a&gt; is also popular around here.&lt;/p&gt;&#xA;" OwnerUserId="14" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-09-13T17:20:53.280" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="414" PostTypeId="2" ParentId="297" CreationDate="2015-09-03T01:44:56.440" Score="13" Body="&lt;p&gt;Your image definitely does not look correct, and it appears that you are not correctly computing the internal path of light rays as they travel through your mesh. From the looks of it, I would say that you are computing the distance between the point where the view ray first enters the cube and where it first hits the interior wall, and using that as your absorption distance. This essentially assumes that light will always exit the glass the first time it hits a wall, which is a poor assumption.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In reality, When light enters glass from air, it often does not immediately exit the glass. This is because when the light strikes the glass/air interface, a phenomenon known as &lt;a href=&quot;https://en.wikipedia.org/wiki/Total_internal_reflection&quot; rel=&quot;noreferrer&quot;&gt;total internal reflection&lt;/a&gt; (TIR) can occur. TIR occurs when light travels from a medium with a higher index of refraction (IOR) to one with a lower IOR, which is precisely what happens in the case of light hitting the interior wall of a glass object. This image from Wikipedia is a good visual demonstration of what it looks like when it occurs:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4lSRl.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4lSRl.jpg&quot; alt=&quot;total internal reflection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In basic terms, what it means is that if the light hits at a shallow angle, the light will completely reflect off of the interior of the medium. To account for this, you need to evaluate the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;noreferrer&quot;&gt;Fresnel equations&lt;/a&gt; every time that your light ray hits a glass/air interface (AKA the interior surface of your mesh). The Fresnel equations will tell you the ratio of reflected light to the amount of refracted light, while will be 1 in the case of TIR. You can then compute the appropriate reflected and refracted light directions, and continue to trace the light's path either through the medium or outside of it. If you assume a simple convex mesh with a uniform scattering coefficient, then the the distance to use for Beer's law will be the sum of all internal path lengths before exiting the medium. Here is what a cube looks like with your scattering coefficients and IOR of 1.526 (soda lime glass), rendered using my own path tracer that accounts for both internal and external reflections and refractions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7MOow.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7MOow.png&quot; alt=&quot;path-traced glass cube&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ultimately the internal reflections and refractions are a major part of what makes glass look like glass. Simple approximations really don't cut it, as you've already found out. It gets even worse if you add multiple meshes and/or non-convex meshes, as you not not only have to account for internal reflections but must also account for rays that leave the medium and enter it at a different point.&lt;/p&gt;&#xA;" OwnerUserId="207" LastActivityDate="2015-09-03T01:44:56.440" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="416" PostTypeId="1" AcceptedAnswerId="1453" CreationDate="2015-09-03T08:16:51.817" Score="3" ViewCount="3365" Body="&lt;p&gt;I'm currently researching my options on effeciently exchanging data for a webgl application. I understand the gltf format is still being &lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/master/specification/README.md&quot; rel=&quot;nofollow&quot;&gt;drafted&lt;/a&gt; but I need some example data to understand whether this format is really useful for my application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently using JSON data and I need to figure out whether there are any benefits to using data formats which are closer to the hardware. As far as I understand gltf also uses some JSON structures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any gltf example datasets available already?&lt;/p&gt;&#xA;" OwnerUserId="361" LastEditorUserId="361" LastEditDate="2016-04-19T09:09:34.377" LastActivityDate="2016-06-15T19:04:57.963" Title="Are there any gltf example datasets available?" Tags="&lt;webgl&gt;&lt;vertex-buffer-object&gt;&lt;data-structure&gt;&lt;gltf&gt;&lt;buffers&gt;" AnswerCount="2" CommentCount="2" ClosedDate="2016-06-15T21:51:05.390" ContentLicense="CC BY-SA 3.0" />
  <row Id="417" PostTypeId="2" ParentId="416" CreationDate="2015-09-03T08:26:17.907" Score="2" Body="&lt;p&gt;Ok sometimes you have to ask a question to figure out the answer already.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example datasets are available in the same repository as linked in the question already. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/e9cf7b0de2d1daed58317f5e6c8b9a2b7d543375/model/SuperMurdoch/SuperMurdoch.gltf&quot; rel=&quot;nofollow&quot;&gt;supermurdoc.gltf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/e9cf7b0de2d1daed58317f5e6c8b9a2b7d543375/model/duck/duck.gltf&quot; rel=&quot;nofollow&quot;&gt;duck.gltf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF/tree/master/sampleModels&quot; rel=&quot;nofollow&quot;&gt;etc. pp.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="361" LastEditorUserId="361" LastEditDate="2016-06-15T19:04:57.963" LastActivityDate="2016-06-15T19:04:57.963" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="418" PostTypeId="2" ParentId="405" CreationDate="2015-09-03T09:18:23.187" Score="12" Body="&lt;p&gt;Personally my choice of poison is Adobe Illustrator. Other apps such as inkscape, Corel Draw, Xara Designer will also do. In a pinch even PowerPoint will work. Though I do not personally recommend PowerPoint due to severe issues with its data model, even tough is possibly worlds most deployed drawing app.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It can also be a good idea to have a graphing application at hand. I personally use Mathematica for this although many other apps would work too. Or if you want you can use Wolfram alpha that's a free online version of mathematica.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Disclaimer: Because examples are mine and shameless self endorsement take with a pinch of salt.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Illustrator&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The first thing you should do in any vector drawing app is to &lt;em&gt;enable the snapping grid&lt;/em&gt;. This reduces the tediousness of accurately placing lines. One of the big reasons i do not like to use Inkscape is the inferior way it implements this snapping. PowerPoint actually comes with grid snapping on by default. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not really satisfied by Illustrator as it does not fill all my needs. But no software so far does (Maya used to fill this niche but then autodesk happened).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second reason i choose Illustrator is that it understands postscript natively. So if i need to program something i can do so quickly and existing documents update as my code matures Image 3 is done this way.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/37998/how-to-create-a-vector-curve-programmatically/38010#38010&quot;&gt;Resource&lt;/a&gt; showing snap, postscript and java script access to illustrator and links forward.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Here are  some examples of drawings that I have done across the network with Illustrator, mostly by power of grid snap:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/dFHFY.png&quot; alt=&quot;Circle march&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: One of many images i drew in illustrator on this site. Note: I am a quite experienced Illustrator (sometimes commercial) and this is extremely simple by my standards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Circle march image in is fairly simple to do. Just draw a random shape by clicking around. After this disable snap and let the smart guides do your work for you. Draw lines to closest point on the line, make circles to the line and (i deleted the guide lines after i was done). Rinse and repeat. It took me about 3-5 minutes to draw the image once i got my workspace started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wg2jD.png&quot; alt=&quot;Continuation wave&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: GD.SE &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/45929/what-is-this-design-pattern-called-continuation-wave/45936#45936&quot;&gt;Continuation wave&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While this image seems quite more elaborate, its not much more work than the first image. It is more technical so in addition to grid snap I and now using the shift key to constrain lines to 45 degree angles. Hatch fills are easily just assigned to regions with the shape builder tool of illustrator. (example of &lt;a href=&quot;https://graphicdesign.stackexchange.com/a/57267/18306&quot;&gt;shape builder in use&lt;/a&gt;, screen capture)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/fSG6X1l.png&quot; alt=&quot;tetra image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 3&lt;/strong&gt;: Sometimes its easier to start from scratch in postscript. Image added to post on &lt;a href=&quot;https://engineering.stackexchange.com/questions/2949/minimum-number-of-tetra-elements-required-to-represent-a-cube&quot;&gt;ENG.SE&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally a image that really is easier to do by typing the values in postscript. It is relatively easy to do in postscript. Ive still done the typography in illustrator. While drawing this by hand is not a big deal i prefer not to, but i will do it if i must do judgement call by eye.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Mathematica&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Mathematica is wonderful if you want to explore things a bit more. The only drawback to Mathematica is that it is NOT cheap. But it can do nearly anything quickly. Ive used Mathematica for some of my pictures on of &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/358/nurbs-knot-multiplicity&quot;&gt;nurbs basis&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of Mathematicas core competencies s that its easy to develop even fairly complex pictures without much hassle. It can also easily animate your simple picture &lt;em&gt;within you editor&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Graphics[{&#xA;    orig = {&#xA;        Table[&#xA;            GeometricTransformation[&#xA;                Line[{{0, 0}, {50, 0}}],&#xA;            RotationTransform[ang]],&#xA;            {ang, 0, 3 Pi/2, Pi/2}&#xA;        ],&#xA;        Line[{{20, 0}, {30, 20}, {40, 0}}]&#xA;    },&#xA;    Red,&#xA;    GeometricTransformation[&#xA;        orig,&#xA;        RotationTransform[Pi/6]&#xA;    ]&#xA;}]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Results in same picture as others have. Wrapping it inside a table &lt;a href=&quot;https://stackoverflow.com/questions/6109786/how-to-generate-animated-gif-of-a-manipulate-8-0-1&quot;&gt;as per&lt;/a&gt; results in:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/5lcbX.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 4&lt;/strong&gt;: Animation is simple to do inside the code editor using Mathematica.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorDisplayName="user7220" LastEditDate="2018-03-20T15:55:51.140" LastActivityDate="2018-03-20T15:55:51.140" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="419" PostTypeId="2" ParentId="357" CreationDate="2015-09-03T09:20:31.290" Score="16" Body="&lt;p&gt;Just adding to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/357/is-using-many-texture-maps-bad-for-caching/404#404&quot;&gt;imallett's answer&lt;/a&gt;, it is true that increasing the number of accesses to different texture data in a shader will increase pressure on the GPU cache(s), but there are several other factors that can significantly influence the effect. It's also possibly complicated by the fact that, like CPU caches, there may be several layers of cache in a GPU, ie. Texture Unit &amp;lt;= L0 &amp;lt;= L1 &amp;lt;= ..Memory&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Avoid aliasing -&gt; Use MIP maps&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;If you have a scene that has minification of texture data, be it due to perspective or simple scaling and you aren't using MIP mapping, then you will get aliasing. This is not just going to produce visual artefacts; it is very likely to be a performance problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As soon as you get aliasing, the address accesses to the texture will become incoherent which will not only end up thrashing the caches but introduce a lot of DRAM &quot;page breaks&quot; (more correctly, row breaks) which can be costly. MIP mapping helps reduce the incoherency.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Texture compression&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Perhaps a bit of an obvious option, but if you can use texture compression (e.g. DXTn|ETC*|PVRTC*|etc) targeting from 8bpp down to, say, 2bpp, you can greatly increase the effectiveness of the memory bandwidth/cache by factors of 4x through to 16x.&#xA;Now I can't speak for all GPUs, but &lt;em&gt;some&lt;/em&gt; texture compression schemes (e.g. those listed above) are so simple to decode in hardware, that the data &lt;em&gt;could&lt;/em&gt; stay compressed throughout the entire cache hierarchy and only be decompressed in the texture unit, thus effectively multiplying the size of those caches. &lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Data size&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Obviously, some data, e.g. render targets used as texture data in subsequent renders, can't employ texture compression. Whenever you can, use the smallest pixel format that will do the job, i.e, if 32/16bpp (A)RGB will do, don't use 4x32 float formats!&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Sparse access&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;This is somewhat related to the aliasing example above, but we've seen cases where large render targets are created, but then only very sparsely sampled. Cache lines, be it in CPUs or GPUs, are quite long so if you are only using one pixel in each cache line, you will be wasting transfers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, WRT compressed textures, these achieve compression by effectively sharing data between a local region of texels. If you don't have coherent access then, apart from the memory footprint reduction, the compression probably won't help.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Dependent Texture Reads&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Not so much of a cache issue (well, unless the computed accesses are quite incoherent), but texture accesses that aren't directly defined by the UV coordinates supplied with vertices &lt;em&gt;might&lt;/em&gt; be slower than those that are directly defined.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Tiled/Morton VS Strided textures&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Although I suspect most textures these days will be stored in either a tiled or Morton-like (aka Twiddled/Swizzled) order (or even a combination of both), some textures &lt;em&gt;might&lt;/em&gt; still be in scan-line order, which means that rotation of the texture is likely to lead to a significant number of cache misses/page breaks. Unfortunately, I don't really know how to spot if a particular format is arranged in such a way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(For background reading, try Blinn's &lt;a href=&quot;http://ieeexplore.ieee.org/document/50676/&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Truth About Texture Mapping&lt;/a&gt;. FWIW, taking that a few steps further led to the use of Twiddled-order (i.e. Morton order) textures in &lt;a href=&quot;http://worldwide.espacenet.com/publicationDetails/originalDocument?FT=D&amp;amp;date=19960814&amp;amp;DB=EPODOC&amp;amp;locale=en_ep&amp;amp;CC=GB&amp;amp;NR=2297886A&amp;amp;KC=A&amp;amp;ND=4&quot; rel=&quot;nofollow noreferrer&quot;&gt;at least some early PC hardware&lt;/a&gt;). &lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-10-02T11:05:33.717" LastActivityDate="2017-10-02T11:05:33.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="420" PostTypeId="2" ParentId="151" CreationDate="2015-09-03T09:38:08.500" Score="-2" Body="&lt;p&gt;In case you want to take a look into a ready solution.I have &lt;a href=&quot;https://github.com/sasmaster/TrackballControls&quot; rel=&quot;nofollow&quot;&gt;a port&lt;/a&gt; of THREE.JS TrackBall controlls in C++ and C#&lt;/p&gt;&#xA;" OwnerUserId="213" LastActivityDate="2015-09-03T09:38:08.500" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="421" PostTypeId="1" AcceptedAnswerId="427" CreationDate="2015-09-03T13:15:11.750" Score="10" ViewCount="1734" Body="&lt;p&gt;In his classic paper &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.32.6170&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing with Cones&lt;/a&gt;, John Amanatides describes a variation on classical ray tracing. By extending the concept of a &lt;em&gt;ray&lt;/em&gt; by an &lt;em&gt;aperture angle&lt;/em&gt;, making it a cone, aliasing effects (including those originating from too few Monte Carlo samples) can be reduced.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;During cone-triangle intersection, a scalar coverage value is calculated. This value represents the fraction of the cone that is covered by the triangle. If it is less than $1$, it means that the triangle doesn't fully cover the cone. Further tests are required. Without the usage of more advanced techniques however, we only know how much of the cone is covered, but not which parts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Amanatides states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Since at present only the fractional coverage value is used in mixing&#xA;  the contributions from the various objects, overlapping surfaces will&#xA;  be calculated correctly but abutting surfaces will not.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This does not make sense to me. From my point of view it is the other way around. Let's take an example: We have two &lt;em&gt;abutting&lt;/em&gt; triangles, a green and a blue one, each of which covers exactly 50% of our cone. They are at the same distance from the viewer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/n5JTo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n5JTo.png&quot; alt=&quot;Green and blue triangle&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The green triangle is tested first. It has a coverage value of 0.5, so the blue triangle is tested next. With the blue one's coverage value of 0.5 our cone is fully covered, so we're done and end up with a 50:50 green-blue mixture. Great!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now imagine that we kill the blue triangle and add a red one some distance behind the green one - &lt;em&gt;overlapping&lt;/em&gt;. Greeny gives us a coverage value of 0.5 again. Since we don't have the blue one to test anymore we look further down the cone and soon find the red one. This too returns some coverage value greater than 0, which it shouldn't because it is &lt;em&gt;behind&lt;/em&gt; the green one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, from this I conclude that abutting triangles work fine, while overlapping triangles would need some more magic like coverage masks to be correct. This is the opposite of what Amanatides says. Did I misunderstand something or is this a slip in the paper?&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2016-07-13T11:31:33.590" LastActivityDate="2016-07-13T11:31:33.590" Title="Ray Tracing with Cones: coverage, overlapping and abutting triangles" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="422" PostTypeId="2" ParentId="407" CreationDate="2015-09-03T13:53:39.800" Score="6" Body="&lt;p&gt;Extending Kostas Anagnostou's answer, a commonly used formula for desaturation is&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float value = 0.3 * InputR + 0.59 * InputG + 0.11 * InputB;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This accomodates the fact that different color hues are perceived with a different intensity by a human observer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further following the example, you would then define some tint color that is multiplied with the desaturated value. Also you could mix the tinted image with your original to get a less drastic effect. In this case, we're mixing 80% of the desaturated image tinted with (1.0, 0.2, 0.2) with 20% of the original:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 tint = float3(1.0, 0.2, 0.2);&#xA;float tintMix = 0.8;&#xA;OutputR = tintMix * value * tint.r + (1.0 - tintMix) * InputR;&#xA;OutputG = tintMix * value * tint.g + (1.0 - tintMix) * InputG;&#xA;OutputB = tintMix * value * tint.b + (1.0 - tintMix) * InputB;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2015-09-07T07:59:28.727" LastActivityDate="2015-09-07T07:59:28.727" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="423" PostTypeId="2" ParentId="185" CreationDate="2015-09-03T14:12:49.450" Score="4" Body="&lt;p&gt;The hemispherical intensity function, i.e. the hemispherical function of incident light multiplied by the BRDF, correlates to the number of samples required per solid angle. Take the sample distribution of any method and compare it to that hemispherical function. The more similar they are, the better the method is in that particular case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that since this intensity function is typically &lt;em&gt;unknown&lt;/em&gt;, all of those methods use heuristics. If the assumptions of the heuristics are met, the distribution is better (= closer to the desired function) than a random distribution. If not, it's worse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, importance sampling uses the BRDF to distribute samples, which is simple but only uses a part of the intensity function. A very strong light source illuminating a diffuse surface at shallow angle will get few samples, although its influence might still be huge. Metropolis Light Transport generates new samples from previous one's with high intensity, which is good for few strong light sources, but doesn't help if light arrives evenly from all directions.&lt;/p&gt;&#xA;" OwnerUserId="385" LastActivityDate="2015-09-03T14:12:49.450" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="424" PostTypeId="1" CreationDate="2015-09-03T15:00:16.987" Score="16" ViewCount="1118" Body="&lt;p&gt;In font rendering, it is common to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Subpixel_rendering&quot;&gt;subpixel rendering&lt;/a&gt;.  The basic idea here is to break the pixel into its RGB components and then compute a value for each separately.  Since each component is smaller than the entire pixel, higher quality antialiasing is possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is an obviously analogous way to do the same for a ray tracer.  You do reconstruction filtering on each subchannel separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was surprised that, however, I couldn't really find reference to ray tracers doing this.  Especially if you're already doing spectral rendering, this seems like an obvious thing to do.  There's &lt;a href=&quot;http://wscg.zcu.cz/wscg2012/full/E03-full.pdf&quot;&gt;this paper&lt;/a&gt; from a journal I've never heard of which seems to be related.  But overall, subpixel rendering just doesn't seem to be a common thing to do.  My question: &lt;strong&gt;why not&lt;/strong&gt;?&lt;/p&gt;&#xA;" OwnerUserId="523" LastEditorUserId="506" LastEditDate="2015-09-05T19:34:22.307" LastActivityDate="2015-09-09T01:43:39.973" Title="Subpixel Rendering for a Ray Tracer" Tags="&lt;raytracing&gt;&lt;antialiasing&gt;&lt;subpixel-rendering&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="425" PostTypeId="2" ParentId="326" CreationDate="2015-09-03T15:09:52.093" Score="2" Body="&lt;p&gt;I've done some VR research; this comes up a lot since rendering the scene multiple times (especially at predicted VR resolutions) is expensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic problem is that two views provide more information than only one.  In particular, you have two slices of the light field instead of one.  It's related to depth-of-field: screen-space methods fundamentally are incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There has been some work in this area, most related to reprojection techniques that try to do some kind of geometry-aware holefilling in the final image.  This sortof works.  As far as I know, the best approach so far is to render the scene directly for the dominant eye, and then reproject it to the other one.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-09-03T15:09:52.093" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="427" PostTypeId="2" ParentId="421" CreationDate="2015-09-03T16:11:42.543" Score="3" Body="&lt;p&gt;I did implement a ray tracer based on Amantides' work but, as that was  years ago, my memory of the paper is a little rusty.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, ignoring this particular case, in general when it comes to working with fractional coverage e.g. Alpha compositing, (see &lt;a href=&quot;https://en.wikipedia.org/wiki/Alpha_compositing#Description&quot; rel=&quot;nofollow&quot;&gt;&quot;A over B&quot;&lt;/a&gt;) my understanding is that the usual assumption is that the items being composited are uncorrelated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus if A with X% coverage is on top of B with Y% coverage and C in the background, then it's assumed that one will see&lt;br&gt;&#xA;    X%*A + (100-X%)*Y% * B + (100-X%)(100-Y%)*C&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does that make sense? Obviously this will give &quot;leaks&quot; in the case where A and B are strongly correlated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I &lt;em&gt;think&lt;/em&gt; I might have put a small bit mask on the rays to avoid these problems, but it was a very long time ago.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2015-09-05T10:03:50.143" LastActivityDate="2015-09-05T10:03:50.143" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="428" PostTypeId="2" ParentId="424" CreationDate="2015-09-03T17:28:50.833" Score="14" Body="&lt;h2&gt;This is perfectly possible&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Although the difference may not especially noticeable, I would expect sampling taking into account the exact &lt;a href=&quot;https://en.wikipedia.org/wiki/Pixel_geometry&quot; rel=&quot;noreferrer&quot;&gt;pixel geometry&lt;/a&gt; to give a slightly more accurate image. You just need to offset your pixel centres per colour component according to the (average) location of the subpixel(s) of that colour. Note that not all pixel layouts have a one to one correspondence between pixels and sub pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, &lt;a href=&quot;https://en.wikipedia.org/wiki/PenTile_matrix_family#PenTile_RGBG&quot; rel=&quot;noreferrer&quot;&gt;penTile RGBG&lt;/a&gt; has twice as many green subpixels as red and blue, as this image from Wikipedia shows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/PenTile_matrix_family#/media/File:Nexus_one_screen_microscope.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oB5Rn.png&quot; alt=&quot;Close up image of RGBG pixel geometry&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not aware of any technical reason that would prevent this being used to produce arbitrary full colour images. In fact a colourful scene will have less noticeable colour artefacts than black on white text, which makes the colour differences hardest to camouflage.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Fonts are rendered on demand&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The relevant difference between rendering a raytraced scene and rendering fonts is that fonts tend to be rendered on demand, and can take into account the screen being used. Contrasting with this, a raytraced scene is often prerendered and then displayed on many different types of screen (with different pixel geometry). For example, displaying your raytraced image on a webpage will prevent tailoring it to a specific monitor type.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you were designing a realtime raytracing program and you had access to check the pixel geometry of the monitor, then you could raytrace to the specific sub pixel layout. However, offline raytracing that produces a still image can only be tailored to a single type of pixel geometry, which will then make the image look &lt;em&gt;worse&lt;/em&gt; on any other pixel geometry. You could work around this by rendering a set of different images and choosing the appropriate one when it is later displayed on a particular type of monitor.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;There is unlikely to be a long term benefit&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;So there is no reason you couldn't develop sub pixel rendering for a raytracer, but it means taking into account an aspect of the monitor that is not always known. Another thing to bear in mind is that you will be developing this software for a shrinking market. Sub pixel rendering is useful for screens that have relatively low resolution. As more and more screens (even mobile screens) are approaching such high resolution that the human eye cannot detect the difference made by sub pixel rendering, your work is likely to be more of theoretical interest than practical use.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-09-03T17:43:37.623" LastActivityDate="2015-09-03T17:43:37.623" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="429" PostTypeId="2" ParentId="405" CreationDate="2015-09-03T19:04:15.140" Score="13" Body="&lt;p&gt;I use a variety of tools depending on the particular needs of the moment. I have a bias toward free tools, as I don't have access to things like Illustrator or Mathematica.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For general vector art purposes I use the free &lt;a href=&quot;https://inkscape.org/en/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Inkscape&lt;/a&gt;. It operates on .svg files and can also render them out as high-quality .pngs or other bitmap formats. For example, here's a diagram I made in Inkscape &lt;a href=&quot;https://gamedev.stackexchange.com/questions/22103/confusion-with-the-texture-coordinate-system-in-xna&quot;&gt;to explain UV mapping&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/t99e7.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For 2D function graphs, I often use the online graphing calculator &lt;a href=&quot;https://www.desmos.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Desmos&lt;/a&gt;, which has the handy capability of letting you share graphs online so others can view and modify them. You can also create sliders that can be varied to play with curve parameters in real time. For example, here is a &lt;a href=&quot;https://www.desmos.com/calculator/id7k8wn7ud&quot; rel=&quot;nofollow noreferrer&quot;&gt;configurable sharpening function&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more complex graphing tasks that involve a bit of programming, I use &lt;a href=&quot;http://maxima.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Maxima&lt;/a&gt;, a free computer algebra system that also has graphing features. I used Maxima to create the graphs in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/289/48&quot;&gt;this answer about Gaussian blurs&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/ugYom.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This was a bit too complex for Desmos, since it involved programmatically creating a piecewise approximation of a Gaussian.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For really odd graphing tasks that aren't handled well by anything else, I've used Python with the &lt;a href=&quot;https://pypi.python.org/pypi/svgwrite/&quot; rel=&quot;nofollow noreferrer&quot;&gt;svgwrite&lt;/a&gt; package to programmatically generate diagrams into .svg files. These can then be touched up in Inkscape if desired and rendered to bitmaps using Inkscape or ImageMagick. I used that workflow to create the images in &lt;a href=&quot;http://www.reedbeta.com/blog/2015/07/03/depth-precision-visualized/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this blog post on depth precision&lt;/a&gt;, like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/MVLUh.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case I wanted to not only graph a function, but place tick marks programmatically and nonuniformly along both the axes and the graph, to illustrate discrete depth buffer values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally, if nothing else suffices, I'll use Python with &lt;a href=&quot;http://www.numpy.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;numpy&lt;/a&gt; and &lt;a href=&quot;https://python-pillow.github.io/&quot; rel=&quot;nofollow noreferrer&quot;&gt;pillow&lt;/a&gt; to render images pixel-by-pixel. That's how I created the Perlin noise images in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/252/48&quot;&gt;this answer&lt;/a&gt; (with the help of the &lt;a href=&quot;https://pypi.python.org/pypi/noise/&quot; rel=&quot;nofollow noreferrer&quot;&gt;noise&lt;/a&gt; package too, in this case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Micts.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-09-03T20:43:56.083" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="430" PostTypeId="2" ParentId="424" CreationDate="2015-09-03T21:46:36.893" Score="9" Body="&lt;p&gt;Sure, you &lt;a href=&quot;http://new.ics.ele.tue.nl/~dehaan/pdf/90_jsid2003.pdf&quot;&gt;can use subpixel rendering for arbitrary images.&lt;/a&gt;  However, subpixel rendering is really a generic 2D image processing technique &amp;mdash; it has nothing to do with ray tracing specifically.  You could just as well use it with any other 3D rendering method, or even with a simple 2D drawing, photograph or even video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, I'd say that &quot;subpixel rendering for ray tracing&quot; is really conflating two distinct problem domains that are best treated separately.  About the only relevant connection is that, if you're ray tracing the scene in real time and know that the resulting image is going to be drawn on the screen using subpixel rendering, you can use this information to optimize the pixel density (and aspect ratio) of the intermediate image (e.g. using 3x horizontal pixel density for a typical RGB LCD screen).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;A potential source of confusion may be that, on current computer system, subpixel rendering is commonly used only for text, and is typically integrated into the font rendering code.  The main reasons for this are arguably historical, but it's also where the biggest payoffs (in terms of visual improvement and readability) typically are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, due to the way text tends to consist of simple and repetitive vector shapes, integrating the subpixel rendering into the font renderer offers some extra optimization opportunities over just rendering the text into a high-resolution buffer and then postprocessing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, I fully expect that eventually, as technology matures, we'll move to a system where subpixel rendering is simply done transparently by the GPU, or possibly by the screen itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(This will most likely require applications that want to make full use of this feature to deal with physical pixels that are smaller, and not necessarily the same shape as, the &quot;logical pixels&quot;.  But then again, we're already moving in that direction with high-DPI screens.)&lt;/p&gt;&#xA;" OwnerUserId="525" LastActivityDate="2015-09-03T21:46:36.893" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="431" PostTypeId="1" AcceptedAnswerId="1431" CreationDate="2015-09-04T00:22:06.640" Score="5" ViewCount="289" Body="&lt;p&gt;Subpixel rendering is used most commonly to anti alias fonts. It works by leveraging the physical layout of the color components of a display to give geometry details to an image that are smaller than a pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, this font has a height of 3 pixels but can easily be read:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cq392.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cq392.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;from: &lt;a href=&quot;http://www.sitepoint.com/two-teeny-tiny-fonts/&quot; rel=&quot;noreferrer&quot;&gt;http://www.sitepoint.com/two-teeny-tiny-fonts/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a monochromatic case, and i could see this possibly working in a greyscale case, but it seems like it always has to be used in situations where you have high contrast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to use sub pixel rendering in a full color situation, such as those you'd find while doing a 3d render of a scene?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that it must not be, since it won't be high contrast enough, but does anyone have examples to the contrary?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-09-04T05:59:27.147" Title="Is colorized subpixel rendering possible?" Tags="&lt;color&gt;&lt;subpixel-rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="432" PostTypeId="2" ParentId="361" CreationDate="2015-09-04T00:53:07.067" Score="3" Body="&lt;p&gt;You are correct, it's badly worded. Illumination falls off with the cosine of the angle between the surface normal and the inverse light direction, so the wording implies the light is shining down the original surface normal, and so any tilting away would be tilting away from the lighting direction.&lt;/p&gt;&#xA;" OwnerUserId="554" LastActivityDate="2015-09-04T00:53:07.067" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1431" PostTypeId="2" ParentId="431" CreationDate="2015-09-04T05:13:15.667" Score="5" Body="&lt;p&gt;Here's an example of a downsampling filter that takes pixel geometry into account: &lt;a href=&quot;http://journals.cambridge.org/article_S2048770312000030&quot; rel=&quot;noreferrer&quot;&gt;Increasing image resolution on portable displays by subpixel rendering&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Image (a) below is an image downsampled using pixel-based downsampling. Image (b) is downsampled using direct subpixel-based downsampling, which (as far as I can tell) effectively downsamples the R, G, and B planes of the image independently. Image (c) is downsampled using diagonal direct subpixel-based downsampling, which uses a diagonal pattern to improve apparent resolution in both horizontal and vertical directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kZlsj.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z4bmt.jpg&quot; alt=&quot;Figure 11 from the paper&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see that the last two images look sharper, but also have the characteristic color fringing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the downsampling pattern used for the last image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/cWk6g.jpg&quot; alt=&quot;DDSD downsampling pattern&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2015-09-04T05:59:27.147" LastActivityDate="2015-09-04T05:59:27.147" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1432" PostTypeId="1" CreationDate="2015-09-04T06:14:31.387" Score="14" ViewCount="5312" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Anisotropic_filtering&quot;&gt;Anisotropic filtering&lt;/a&gt; &quot;retains the sharpness of a texture normally lost by MIP map texture's attempts to avoid aliasing&quot;. The Wikipedia article gives hints about how it can be implemented (&quot;probe the texture (...) for any orientation of anisotropy&quot;), but it does't read very clear to me.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There seem to be various implementations, as suggested by the tests illustrated in the &lt;a href=&quot;https://dl.dropboxusercontent.com/u/6809780/BLOG_HOSTING/sig2015_approx_models_PBR_notes_DRAFT.pdf&quot;&gt;notes&lt;/a&gt; of the presentation &lt;a href=&quot;http://c0de517e.blogspot.jp/2016/07/siggraph-2015-notes-for-approximate.html&quot;&gt;Approximate Models For Physically Based Rendering&lt;/a&gt;:&#xA;&lt;a href=&quot;https://dl.dropboxusercontent.com/u/6809780/BLOG_HOSTING/sig2015_approx_models_PBR_notes_DRAFT.pdf#page=37&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9NAa0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the concrete computations performed by (modern) GPUs to choose the correct MIP level when using anisotropic filtering?&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="110" LastEditDate="2016-08-04T14:57:25.730" LastActivityDate="2016-08-04T14:57:25.730" Title="How is anisotropic filtering typically implemented in modern GPUs?" Tags="&lt;texture&gt;&lt;gpu&gt;&lt;algorithm&gt;&lt;implementation&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1433" PostTypeId="2" ParentId="361" CreationDate="2015-09-04T07:40:47.200" Score="5" Body="&lt;p&gt;I see some problems in the quote you posted.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In effect, a point rotated around its normal vector will not change&#xA;  the way it reflects light.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is true, because a Lambertian reflector will &lt;strong&gt;never&lt;/strong&gt; change the &lt;em&gt;way&lt;/em&gt; it reflects light. The underlying principle stays the same. Also, Lambertian surfaces are isotropic, so the &lt;em&gt;amount&lt;/em&gt; of reflected light won't change either (which is probably what this sentence is aiming for).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;However, the point will change the way it reflects light if it is tilted away from its initial normal vector since the area is illuminated by a smaller fraction of the incident radiation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Again not true, because the principle doesn't change. The amount &lt;em&gt;may&lt;/em&gt; change, except for the special case that the cosine is &amp;lt;= 0 before and after the tilting. The amount does not necessarily &lt;em&gt;grow&lt;/em&gt;, except if we define that the cosine equals 1 before, i.e. that the normal points directly towards the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This whole paragraph should probably be rewritten to be less ambiguous. Including isotropy could make it more complete.&lt;/p&gt;&#xA;" OwnerUserId="385" LastActivityDate="2015-09-04T07:40:47.200" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1434" PostTypeId="1" AcceptedAnswerId="1440" CreationDate="2015-09-04T08:18:09.100" Score="8" ViewCount="254" Body="&lt;p&gt;In the style of &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/361/is-this-a-mistake-in-the-wikipedia-article-for-lambertian-reflectance&quot;&gt;trichoplax' question&lt;/a&gt;, I want to talk about yet another Wikipedia article: &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiosity_%28computer_graphics%29&quot; rel=&quot;nofollow noreferrer&quot;&gt;Radiosity (computer graphics)&lt;/a&gt;. The article states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Radiosity is viewpoint independent, which increases the calculations involved, but makes them useful for all viewpoints.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The technique works with diffuse surfaces only. This way, form factors can be precalculated and are independent of the viewer. The lighting needs to be updated only if some light source changed. If, on the other hand, the technique would support specular reflection, the form factors would depend on the viewer. Form factors and lighting would need to be updated constantly when the camera moves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does the limitation to diffuse surfaces &lt;em&gt;increase&lt;/em&gt; calculations? Diffuse surfaces need to take light from all directions into account, which is more complex than taking light only from a smaller specular lobe. Is this what this sentence means? Is it just me or should this be rephrased?&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-11-23T13:17:09.853" Title="How does the view-independence of radiosity increase the calculations involved?" Tags="&lt;radiosity&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1436" PostTypeId="2" ParentId="1432" CreationDate="2015-09-04T09:18:52.440" Score="15" Body="&lt;p&gt;The texture filtering hardware takes several samples of the various mipmap levels (the maximum amount of samples is indicated by the anisotropic filtering level, though the exact amount of samples taken in a given filtering operation will depend on the proportion between the derivatives on the fragment.) If you project the cone viewing a surface at an oblique angle onto the texture space, it will result in approximately an oval shaped projection, which is more elongated for more oblique angles. Extra samples are taken along the axis of this oval (from the correct mip levels, to take advantage of the pre-filtering they offer) and combined to give a sharper texture sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another technique know as &lt;a href=&quot;https://en.wikipedia.org/wiki/Mipmap&quot; rel=&quot;nofollow&quot;&gt;rip-mapping&lt;/a&gt; (mentioned in the Wikipedia article on Mipmapping), which is &lt;em&gt;not&lt;/em&gt; commonly found in contemporary GPUs, uses prefiltering of textures. In contrast to mips, the texture is not scaled down uniformly but using various height-width-ratios (up to a ratio dependent on your chosen anisotropic filtering level). The variant - or maybe two variants if using trilinear filtering - of the texture is then chosen based on the angle of the surface to minimize distortion. Pixel values are fetched using default filtering techniques (bilinear or trilinear). Rip-maps are not used in any hardware that I know of due to their prohibitive size: while mipmaps use additional 33% storage, ripmaps use 300%. This can be verified by noting that texture usage requirements don't increase when using AF, rather, only bandwidth does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For futher reading, you might want to take a look at the specification for the &lt;a href=&quot;https://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt&quot; rel=&quot;nofollow&quot;&gt;EXT_texture_filter_anisotropic&lt;/a&gt; OpenGL extension. It details the formulas used to calculate samples and how to combine them when using anisotropic filtering.&lt;/p&gt;&#xA;" OwnerUserId="327" LastEditorUserId="327" LastEditDate="2015-09-09T18:33:28.380" LastActivityDate="2015-09-09T18:33:28.380" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1437" PostTypeId="2" ParentId="1432" CreationDate="2015-09-04T21:38:10.823" Score="9" Body="&lt;p&gt;The API requirements can be found in any of the specs or extensions. Here is one: &lt;a href=&quot;https://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt&quot;&gt;https://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All GPU vendors likely deviate from the spec because AF-quality used to be a part of many benchmarks. And current implementations will continue to keep on evolving as new workloads stress the existing approximations. Unfortunately, to know exactly what either does, you will need to be a part of one of the companies. But you can gauge the spectrum of possibilities from the following papers, listed in increasing order of quality and implementation cost:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.researchgate.net/publication/3208533_Texram_a_smart_memory_for_texturing&quot;&gt;TexRam&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.hpl.hp.com/techreports/Compaq-DEC/WRL-99-1.pdf&quot;&gt;FELINE&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=4056910&amp;amp;tag=1&quot;&gt;EWA&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Quoting from the spec:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; Anisotropic texture filtering substantially changes Section 3.8.5.&#xA; Previously a single scale factor P was determined based on the&#xA; pixel's projection into texture space.  Now two scale factors,&#xA; Px and Py, are computed.&#xA;&#xA;   Px = sqrt(dudx^2 + dvdx^2)&#xA;   Py = sqrt(dudy^2 + dvdy^2)&#xA;&#xA;   Pmax = max(Px,Py)&#xA;   Pmin = min(Px,Py)&#xA;&#xA;   N = min(ceil(Pmax/Pmin),maxAniso)&#xA;   Lamda' = log2(Pmax/N)&#xA;&#xA; where maxAniso is the smaller of the texture's value of&#xA; TEXTURE_MAX_ANISOTROPY_EXT or the implementation-defined value of&#xA; MAX_TEXTURE_MAX_ANISOTROPY_EXT.&#xA;&#xA; It is acceptable for implementation to round 'N' up to the nearest&#xA; supported sampling rate.  For example an implementation may only&#xA; support power-of-two sampling rates.&#xA;&#xA; It is also acceptable for an implementation to approximate the ideal&#xA; functions Px and Py with functions Fx and Fy subject to the following&#xA; conditions:&#xA;&#xA;   1.  Fx is continuous and monotonically increasing in |du/dx| and |dv/dx|.&#xA;       Fy is continuous and monotonically increasing in |du/dy| and |dv/dy|.&#xA;&#xA;   2.  max(|du/dx|,|dv/dx|} &amp;lt;= Fx &amp;lt;= |du/dx| + |dv/dx|.&#xA;       max(|du/dy|,|dv/dy|} &amp;lt;= Fy &amp;lt;= |du/dy| + |dv/dy|.&#xA;&#xA; Instead of a single sample, Tau, at (u,v,Lamda), 'N' locations in the mipmap&#xA; at LOD Lamda, are sampled within the texture footprint of the pixel.&#xA;&#xA; Instead of a single sample, Tau, at (u,v,lambda), 'N' locations in&#xA; the mipmap at LOD Lamda are sampled within the texture footprint of&#xA; the pixel.  This sum TauAniso is defined using the single sample Tau.&#xA; When the texture's value of TEXTURE_MAX_ANISOTROPHY_EXT is greater&#xA; than 1.0, use TauAniso instead of Tau to determine the fragment's&#xA; texture value.&#xA;&#xA;                i=N&#xA;                ---&#xA; TauAniso = 1/N \ Tau(u(x - 1/2 + i/(N+1), y), v(x - 1/2 + i/(N+1), y)),  Px &amp;gt; Py&#xA;                /&#xA;                ---&#xA;                i=1&#xA;&#xA;                i=N&#xA;                ---&#xA; TauAniso = 1/N \ Tau(u(x, y - 1/2 + i/(N+1)), v(x, y - 1/2 + i/(N+1))),  Py &amp;gt;= Px&#xA;                /&#xA;                ---&#xA;                i=1&#xA;&#xA;&#xA; It is acceptable to approximate the u and v functions with equally spaced&#xA; samples in texture space at LOD Lamda:&#xA;&#xA;                i=N&#xA;                ---&#xA; TauAniso = 1/N \ Tau(u(x,y)+dudx(i/(N+1)-1/2), v(x,y)+dvdx(i/(N+1)-1/2)), Px &amp;gt; Py&#xA;                /&#xA;                ---&#xA;                i=1&#xA;&#xA;                i=N&#xA;                ---&#xA; TauAniso = 1/N \ Tau(u(x,y)+dudy(i/(N+1)-1/2), v(x,y)+dvdy(i/(N+1)-1/2)), Py &amp;gt;= Px&#xA;                /&#xA;                ---&#xA;                i=1 &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-09-04T21:38:10.823" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1438" PostTypeId="1" AcceptedAnswerId="1451" CreationDate="2015-09-05T01:37:17.573" Score="15" ViewCount="5010" Body="&lt;p&gt;How do modern games do geometry level-of-detail for object meshes like characters, terrain, and foliage? There are two parts to my question:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;What does the asset pipeline look like? Do artists make a high-poly model which is later decimated? If so, what decimation algorithms are most popular? Are LOD meshes sometimes done by hand?&lt;/li&gt;&#xA;&lt;li&gt;How do engines transition between different object LODs at run time? Are there any smooth or progressive transitions?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The answer might be &quot;different studios use different techniques.&quot; If so, please identify some of the most common practices. It would also be great if you could point me to whitepapers/slides that cover specific examples.&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2018-03-05T21:23:07.313" Title="What is the state of art in geometric LOD in games?" Tags="&lt;geometry&gt;" AnswerCount="3" CommentCount="5" FavoriteCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="1439" PostTypeId="1" CreationDate="2015-09-05T03:54:59.473" Score="7" ViewCount="438" Body="&lt;p&gt;Do modern GPUs support anisotropic filtering for 3D textures? If yes, how can one use it? The OpenGL spec doesn't seem to be very precise on this. From &lt;a href=&quot;https://www.opengl.org/registry/specs/EXT/texture_filter_anisotropic.txt&quot;&gt;this link&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Should anything particular be said about anisotropic 3D texture filtering?&#xA;&#xA;  Not sure.  Does the implementation example shown in the spec for&#xA;  2D anisotropic texture filtering readily extend to 3D anisotropic&#xA;  texture filtering?&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-09-07T01:22:17.117" Title="Can we use anisotropic filtering on 3D textures?" Tags="&lt;texture&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1440" PostTypeId="2" ParentId="1434" CreationDate="2015-09-05T12:12:49.197" Score="8" Body="&lt;p&gt;While it may not entirely clear from the formulation of the wikipedia article, the author raises an important issue: In contrast to many other approaches, Radiosity needs to perform its calculations &lt;strong&gt;for all existing patches, not only the visible ones&lt;/strong&gt;.&#xA;It is not the limitation to diffuse surfaces that increases the involved computations, but the fact that radiance is computed for all surfaces in the entire scene, not only the visible ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is in strong contrast to other global illumination techniques like path-tracing, where radiance is computed only for visible samples. While the view-paths may still reach every point of the scene, there might be parts of a scene that are never reached by any view-rays/paths. Therefore, there are no computations at all. Comparing with local GI the &quot;problem of viewpoint independence&quot; its even more apparent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, as the Wikipedia article suggests, this may also be seen as a very useful property, since the computations do not need to be performed for each different viewpoint. This is not the case for most other techniques.&lt;/p&gt;&#xA;" OwnerUserId="528" LastActivityDate="2015-09-05T12:12:49.197" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1441" PostTypeId="1" AcceptedAnswerId="1444" CreationDate="2015-09-05T14:53:31.797" Score="13" ViewCount="4256" Body="&lt;p&gt;I have heard that recent GPUs all support non-power-of-2 textures and all features just work. However, I don't understand how mip-mapping would work in such a scenario. Can someone explain?&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2016-05-02T22:40:12.990" Title="How does mip-mapping work with non-power-of-2 textures?" Tags="&lt;texture&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1442" PostTypeId="2" ParentId="1441" CreationDate="2015-09-05T22:42:13.970" Score="4" Body="&lt;p&gt;One way to think of it is that graphics cards often implement non-power-of-2 textures simply by padding them until they are a power of 2 in each direction. This makes most things &quot;just work&quot;: tiling and hardware filtering, for example. The only thing that needs to change is the conversion from texture coordinates to image coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If implemented like that, it's obvious how to do mipmapping: nothing changes. Even if you have a GPU that supports non-power-of-2 textures without padding, the mipmap levels would end up with &quot;padding&quot;. e.g. a 3x3 texture would have a 2x2 texture as lod 1.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-09-05T22:42:13.970" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1444" PostTypeId="2" ParentId="1441" CreationDate="2015-09-06T05:18:09.663" Score="13" Body="&lt;p&gt;The rule is that to compute the next mipmap size, you divide by two and round down to the nearest integer (unless it rounds down to 0, in which case, it's 1 instead). For example, a 57x43 image would have mipmaps like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;level 0: 57x43&#xA;level 1: 28x21&#xA;level 2: 14x10&#xA;level 3: 7x5&#xA;level 4: 3x2&#xA;level 5: 1x1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;UV mapping, LOD selection, and filtering work just the same way as for power-of-two texture sizes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generating good quality mips for a non-power-of-two texture is a little trickier, as you can't simply average a 2x2 box of pixels to downsample in all cases. However, a 2x2 box filter wasn't that great to begin with, so using a better downsampling filter such as Mitchell-Netravali is recommended regardless of the texture size.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-05-02T22:40:12.990" LastActivityDate="2016-05-02T22:40:12.990" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1445" PostTypeId="1" AcceptedAnswerId="1448" CreationDate="2015-09-06T05:41:42.837" Score="7" ViewCount="494" Body="&lt;p&gt;I recently started to read about spherical harmonics. I have a question about this spherical harmonics basis function equation which is mentioned in this StupidSH article:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sBx4G.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sBx4G.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are those lm() and Re() used for?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The article can be found here: &lt;a href=&quot;http://www.ppsloan.org/publications/StupidSH36.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.ppsloan.org/publications/StupidSH36.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1571" LastEditorUserId="6546" LastEditDate="2017-05-02T08:29:33.817" LastActivityDate="2017-05-02T08:29:33.817" Title="Legendre Polynomial equation in Spherical Harmonics" Tags="&lt;lighting&gt;&lt;spherical-harmonics&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1446" PostTypeId="2" ParentId="1438" CreationDate="2015-09-06T06:44:25.300" Score="3" Body="&lt;p&gt;LOD (Level of Detail) means managing objects in different display scales, which could be devided by two parts. However, you may use one of them and that would be enough for most cases.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Show/hide layers ( group of objects of same type) depending on magnitude (display scale).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Algebraic Geomery based method, called Generalization (which is an algorithm to simplify polygons). look at the following picture&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/salks3K.jpg&quot; alt=&quot;generalization&quot; /&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The most famous and efficient method to generalize (simplify) a polygon mesh is known as &lt;a href=&quot;https://books.google.com/books?isbn=0080477267&quot; rel=&quot;nofollow noreferrer&quot;&gt;Descartes-Euler polyhedron theorem&lt;/a&gt; (Equation 4.5 sorry if I am refering to a book, that was best I can do) and is used by most of the spatial databases for example PostGIS modules in PostgreSQL. It simply removes smaller sides of a polygon and makes a very rounded one.(above picture)&lt;/p&gt;&#xA;&lt;p&gt;To implement LOD in a game you need to save and manage the scale of your map (scene) during th zoom in/out operations. The scale changes from zero to infinity and you have to divide this into a particular number of ranges for example something like this:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;1/zero = infinity to 1/50&lt;/li&gt;&#xA;&lt;li&gt;1/50 to 1/100&lt;/li&gt;&#xA;&lt;li&gt;1/100 to 1/1000&lt;/li&gt;&#xA;&lt;li&gt;1/1000 to 1/infinity = 0&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Then you need to define which types of your objects (layers) should be visible or invisible in each of the above ranges. For example a small type of object like a hydrant valve should not be visible when the user is in the fourth range because it will be very small at that scale and can not be discriminated so it doesn't matter if you skip drawing it on the screen.&lt;/p&gt;&#xA;&lt;p&gt;So when a user uses zoom in and zoom out to change the magnification he moves through the above limits from one to the other range, and your game uses these display scales to manage level of details by showing or hiding objects on the scene. This makes a discrete solution that objects suddenly fade during your zoom out operation, however having the display scales and magnification ranges defined carefully, the user woudn't feel anything.&lt;/p&gt;&#xA;&lt;p&gt;The above group of 4 ranges are just an example and you need to find the best for your own case by trial and error. There is no rule for that.&lt;/p&gt;&#xA;&lt;p&gt;Sometimes the games use their own LOD methods, Subway Surfer for instant, shows a small, without texture rectangle to show a building at far, and by getting close suddenly it gets texture,  gamer feels it. You didnt talk about your projection system which is very important also didn't talk about what kind of game you are creating.&lt;/p&gt;&#xA;&lt;p&gt;However suppose you are implementing a full 3D game with openGl and you wish to filter some mesh before transfering them to graphic hardware, I am sure this will help you to reduce binding/unbinding operations with buffer objects and vertex arrays (VBO,VAO) while dealing with OpenGl.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Using only a layer managment or just implement Euler's Generalization&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;In most cases it is not necessary to implement a generalization algorithm, and filtering objects just works and gets you to the efficiency(refresh rate) you need, however it totally depends, case by case. Although it is an easy algorithm that just removes the small sides of a polygon, you need to define a threshold which is the product of magnitude and a constant number, so bigger sides get filtered in a much farther point of view.&lt;/p&gt;&#xA;&lt;p&gt;Forgeting the layer manamgment and only implementing Eulers generalization algorithm, provides a very neat and continuous method in which you just check each sides and lines against a pre-defined threshold and show them only in case they are big enough to be discriminated on the screen.&lt;/p&gt;&#xA;&lt;p&gt;P.S : magnification is a float number &amp;gt; 0 which is equal to 1/scale and the scale is usually &amp;lt; 1 since a 1:1 scale means you have real world lengths in your game.&lt;/p&gt;&#xA;" OwnerUserId="537" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-09-06T13:03:40.150" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1448" PostTypeId="2" ParentId="1445" CreationDate="2015-09-06T08:03:12.167" Score="4" Body="&lt;p&gt;The notation Re() and Im() refer to the real and imaginary parts of a complex number.  Mathematicians and physicists are accustomed to using spherical harmonics (and Fourier transforms too) that are complex-valued, due to the factor $e^{im\phi}$.  You would then also have complex coefficients, in general, in the spherical harmonic expansion of a (real or complex) function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &lt;a href=&quot;https://en.wikipedia.org/wiki/Euler&amp;#39;s_formula&quot; rel=&quot;nofollow&quot;&gt;Euler's formula&lt;/a&gt;, $e^{im\phi} = \cos(m\phi) + i\sin(m\phi)$.  So that factor encodes cosine and sine waves  (that oscillate $m$ times as you move around the equator of the sphere) in its real and imaginary parts, respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When we know we're going to be working strictly with real-valued functions, it may be more convenient to use real-valued variants of the spherical harmonics, where $e^{im\phi}$ is replaced by either $\cos(m\phi)$ or $\sin(m\phi)$, and using real coefficients instead of complex ones.  We trade a single complex coefficient for two real coefficients, so we haven't lost any information or flexibility; it's essentially a change of basis.  This formulation just explicitly ensures that everything always comes out real.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2015-11-03T20:25:54.380" LastActivityDate="2015-11-03T20:25:54.380" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1449" PostTypeId="2" ParentId="1438" CreationDate="2015-09-06T13:21:32.750" Score="3" Body="&lt;p&gt;Iman already prepared a complete answer but I wish to add something to it&lt;/p&gt;&#xA;&#xA;&lt;p&gt;LOD can be done in two different way&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Continous which is called CLOD and is a polygon mesh optimization&lt;/li&gt;&#xA;&lt;li&gt;Discrete which almost every other algorithm than polygon mesh optimization, considered to be in this group.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For example mipmaping is a good,fast but heavy one that belongs to secound group at the above &lt;/p&gt;&#xA;&#xA;&lt;p&gt;here you may find a good explanation to mipmaping and implementation code with OpenGl.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://people.cs.clemson.edu/~dhouse/courses/405/notes/OpenGL-mipmaps.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Multiple Levels of Detail&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="1575" LastEditorDisplayName="user7220" LastEditDate="2018-03-05T21:23:07.313" LastActivityDate="2018-03-05T21:23:07.313" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1450" PostTypeId="1" AcceptedAnswerId="1452" CreationDate="2015-09-06T17:16:09.613" Score="6" ViewCount="342" Body="&lt;p&gt;I'm making a voxel engine in OpenGL and wondering how many 3D textures I can have at once. They are fairly large (256x256x256 in GL_R32UI format). I want it to be able to run on any graphics card supporting OpenGL 3.3, if possible. I'm accessing them all from the same fragment shader, by the way. So how many can I have? Will 8 work? Thanks!&lt;/p&gt;&#xA;" OwnerUserId="1578" LastActivityDate="2015-09-06T20:52:27.517" Title="How many 3D textures does OpenGL support" Tags="&lt;opengl&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1451" PostTypeId="2" ParentId="1438" CreationDate="2015-09-06T17:57:59.280" Score="23" Body="&lt;p&gt;For the geometry LOD most games simply switch between a number of predefined LOD meshes. For example &quot;Infamous: Second Son&quot; uses 3 LOD meshes (&lt;a href=&quot;http://suckerpunch.playstation.com/images/stories/GDC14_infamous_second_son_engine_postmortem.pdf&quot;&gt;Adrian Bentley - &quot;inFAMOUS: Second Son engine postmortem&quot;, GDC 2014&lt;/a&gt;) and &quot;Killzone: Shadow Fall&quot; uses 7 LOD meshes per character (&lt;a href=&quot;http://www.guerrilla-games.com/presentations/Valient_Killzone_Shadow_Fall_Demo_Postmortem.pdf&quot;&gt;Michal Valient - &quot;Killzone: Shadow fall demo postmortem&quot;, Devstation2013&lt;/a&gt;). Most of them are generated, but more important ones (like main character) can be hand made. Meshes are often generated using a popular Simplygon middleware, but sometimes they are simply generated by graphics artists in their favorite 3D package.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Games with a large draw distance additionally use imposters for foliage, trees and high buildings (&lt;a href=&quot;http://suckerpunch.playstation.com/images/stories/GDC14_infamous_second_son_engine_postmortem.pdf&quot;&gt;Adrian Bentley - &quot;inFAMOUS: Second Son engine postmortem&quot;, GDC 2014&lt;/a&gt;). They also employ hierarchical LODs, which replace a set of objects with one. For example in &quot;Just Cause 2&quot; trees are first rendered individually as normal LOD meshes, then individually as imposters and finally as a single merged forest mesh (&lt;a href=&quot;http://www.humus.name/Articles/PopulatingAMassiveGameWorld.pptx&quot;&gt;Emil Persson, Joel de Vahl - &quot;Populating a Massive Game World&quot;, Siggraph2013&lt;/a&gt;) and in &quot;Sunset Overdrive&quot; distant parts of the world are replaced by single automatically offline generated mesh (&lt;a href=&quot;http://s3.crashworks.org/gdc15/ElanRuskin_SunsetOverdrive_Streaming_notes.pdf&quot;&gt;Elan Ruskin - &quot;Streaming Sunset Overdrive's Open World&quot;, GDC2015&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another component of a LOD system is simplification of materials and shaders. For example &quot;Killzone: Shadow Fall&quot; disables tangent space and normal mapping for the distant LODs (&lt;a href=&quot;http://www.guerrilla-games.com/presentations/Valient_Killzone_Shadow_Fall_Demo_Postmortem.pdf&quot;&gt;Michal Valient - &quot;Killzone: Shadow fall demo postmortem&quot;, Devstation2013&lt;/a&gt;). This usually is implemented by disabling globally a set of shader features per LOD, but for engines with shader graphs, where artists can create custom shaders, this needs to be done manually.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the LOD transitions some games simply switch meshes and some use dithering for smooth LOD transitions - at the LOD switch two meshes are rendered: first gradually fades out and second fades in (&lt;a href=&quot;http://simonschreibt.de/gat/assassins-creed-3-lod-blending/&quot;&gt;Simon schreibt Blog - &quot;Assassins Creed 3 – LoD Blending&quot;&lt;/a&gt;). Classic CPU progressive mesh techniques aren't used as they require a costly mesh update and upload to GPU. Hardware Tessellation is used in a few titles, but only for the refinement of a most detailed LOD, as it's slow and in general case it can't replace predefined geometry LODs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Terrain LODs are handled separately in order to exploit it's specific properties. Terrain geometry LOD is usually implemented using clipmaps (&lt;a href=&quot;http://gdcvault.com/play/1020197/Landscape-Creation-and-Rendering-in&quot;&gt;Marcin Gollent - &quot;Landscape creation and rendering in REDengine 3&quot;&lt;/a&gt;). Terrain material LODs either are handled similarly to mesh LODs or using some kind of a virtual texture &lt;a href=&quot;http://twvideo01.ubm-us.net/o1/vault/gdc2015/presentations/Chen_Ka_AdaptiveVirtualTexture.pdf&quot;&gt;Ka Chen - &quot;Adaptive Virtual Texture Rendering In Far Cry 4&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally if you are interested to see real game LOD pipelines then just browse through documentation of any of the modern games engines: &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Content/Types/StaticMeshes/HowTo/LODs/index.html&quot;&gt;Unreal Engine 4 - &quot;Creating and Using LODs&quot;&lt;/a&gt;, &lt;a href=&quot;http://docs.cryengine.com/pages/viewpage.action?pageId=15012200&quot;&gt;CryEgnine - Static LOD&lt;/a&gt; and &lt;a href=&quot;http://docs.unity3d.com/Manual/LevelOfDetail.html&quot;&gt;Unity - LOD&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="93" LastActivityDate="2015-09-06T17:57:59.280" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1452" PostTypeId="2" ParentId="1450" CreationDate="2015-09-06T20:31:32.580" Score="6" Body="&lt;p&gt;As gllampert pointed out in the comments the value is hardware dependent. You can retrieve it with &lt;a href=&quot;https://www.opengl.org/sdk/docs/man3/xhtml/glGet.xml&quot;&gt;glGet&lt;/a&gt;, using &lt;code&gt;GL_MAX_COMBINED_TEXTURE_IMAGE_UNIT&lt;/code&gt;. You can find how different hardware performs &lt;a href=&quot;http://delphigl.de/glcapsviewer/gl_stats_caps_single.php?listreportsbycap=GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in OpenGL 3 there is a lower bound of &lt;strong&gt;at least 48 simultaneously used textures&lt;/strong&gt;, no matter which type. [&lt;a href=&quot;https://www.opengl.org/sdk/docs/man3/xhtml/glActiveTexture.xml&quot;&gt;source&lt;/a&gt;]&lt;/p&gt;&#xA;" OwnerUserId="528" LastEditorUserId="528" LastEditDate="2015-09-06T20:52:27.517" LastActivityDate="2015-09-06T20:52:27.517" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1453" PostTypeId="2" ParentId="416" CreationDate="2015-09-06T21:08:56.360" Score="3" Body="&lt;p&gt;Also check out the glTF models used in Cesium:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Apps/SampleData/models&quot; rel=&quot;nofollow&quot;&gt;https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Apps/SampleData/models&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Specs/Data/Models&quot; rel=&quot;nofollow&quot;&gt;https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Specs/Data/Models&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Patrick&lt;/p&gt;&#xA;" OwnerUserId="1580" LastActivityDate="2015-09-06T21:08:56.360" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1454" PostTypeId="2" ParentId="1439" CreationDate="2015-09-07T01:22:17.117" Score="4" Body="&lt;p&gt;I am not aware of hardware support for 3D anisotropic filtering.  I could be wrong about its existence though.  I believe it has been tried.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The motivation for 2D anisotropic filtering is to prefilter the texture function over the screen area it falls under in a more accurate way than doing a box filter in texture space (usually, anisotropic filtering does &lt;em&gt;several&lt;/em&gt; box filters in texture space).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This definition is key.  2D anisotropic filtering tries to:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Integrate over the part of a flat surface that you can see&lt;br/&gt;(within a single pixel on the screen).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What does 3D anisotropic filtering mean?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Integrate over the part of  a . . . &lt;em&gt;volume?&lt;/em&gt; . . .  that you can . . . &lt;em&gt;see?&lt;/em&gt;&lt;br/&gt;(within a single . . . &lt;em&gt;voxel?&lt;/em&gt; . . . on the screen)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The best analogue I can think of would be doing some sort of 3D texture lookup anisotropically along the viewing ray.  This isn't quite a direct analogy.  Anyway, the problem with this is that when you're doing volume rendering, you actually care about how this integration is done a lot more than in the 2D case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you want absorption?  Emission?  (You need to do some kind of exponential to integrate.)  Do you want scattering?  (You need to do some kind of recursion or approximating blur to integrate).  And this doesn't even get into what kind of data the 3D texture stores.  Does this texture mean &lt;em&gt;opacity&lt;/em&gt;, or does it mean &lt;em&gt;density&lt;/em&gt;?  Is it &lt;em&gt;diffuse&lt;/em&gt; or is it &lt;em&gt;emission&lt;/em&gt;?  All of these need to be integrated differently.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;New developments in volume rendering are happening all the time, and in any case there are so many variously suboptimal ways you could try to generalize 2D anisotropic filtering, the doubt expressed by the specification makes sense to me:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Does the implementation . . . for 2D anisotropic texture filtering readily extend to 3D anisotropic texture filtering?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-09-07T01:22:17.117" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1455" PostTypeId="1" CreationDate="2015-09-07T11:53:53.267" Score="4" ViewCount="3984" Body="&lt;p&gt;I know that there are 3 techniques to draw 3D objects:&#xA;(1) Wireframe Modeling and rendering&#xA;(2) Additive Modeling&#xA;(3) Subtractive Modeling&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What formula or algorithm can I use to draw a 3D Sphere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using a low-level library named &lt;a href=&quot;http://winbgim.codecutter.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;WinBGIm from colorado university&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, how to draw this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/35GPL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/35GPL.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And, this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1zy5r.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1zy5r.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user464" LastEditorDisplayName="user464" LastEditDate="2015-12-22T00:24:07.023" LastActivityDate="2015-12-22T00:24:07.023" Title="What formula or algorithm can I use to draw a 3D Sphere without using OpenGL?" Tags="&lt;3d&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="10" FavoriteCount="1" ClosedDate="2015-09-11T12:10:57.173" ContentLicense="CC BY-SA 3.0" />
  <row Id="1456" PostTypeId="2" ParentId="1455" CreationDate="2015-09-07T23:16:56.550" Score="7" Body="&lt;p&gt;Scratchapixel has a nice tutorial on writing a basic rasterizer &lt;a href=&quot;http://scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation&quot;&gt;here&lt;/a&gt;. Also, you could use the projection algorithm &lt;a href=&quot;http://www.dreamincode.net/forums/topic/239174-3d-perspective-projection/&quot;&gt;here&lt;/a&gt; to get the position of the vertices in screen space, then use Bresenham's algorithm or DDA to draw lines in between. If you want to fill them too you can use scanline (you can find it on Wikipedia).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For ellipsoids, you can either just turn them into a triangle mesh, or the approach &lt;a href=&quot;http://comp.graphics.algorithms.narkive.com/0JsT26Rp/efficiently-rasterize-ellipsoid&quot;&gt;here&lt;/a&gt; might work, although I haven't tried it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Z-Buffer algorithm is very straightforward, just calculate the distance from the point to the camera and store that somewhere for each pixel, then make sure that that's less than whatever was already there.&lt;/p&gt;&#xA;" OwnerUserId="1578" LastActivityDate="2015-09-07T23:16:56.550" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1458" PostTypeId="2" ParentId="411" CreationDate="2015-09-08T03:52:28.850" Score="1" Body="&lt;p&gt;FBX is a pretty common interchange format for 3D animation software. The format is originally made for a software called filmbox which handled motion capture data (since renamed to Motion Builder). Currently the format is owned by Autodesk who make and maintain a sdk for the format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Bone structures and mesh bindings are pretty basic functions within 3D modellimg and animation applications. Possible applications are (in alphabetic order):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;3DS Max&lt;/li&gt;&#xA;&lt;li&gt;Blender&lt;/li&gt;&#xA;&lt;li&gt;Cinema 4D&lt;/li&gt;&#xA;&lt;li&gt;Lightwave3D&lt;/li&gt;&#xA;&lt;li&gt;Maya&lt;/li&gt;&#xA;&lt;li&gt;Modo&lt;/li&gt;&#xA;&lt;li&gt;Motion Builder (this is the software the format is built for)&lt;/li&gt;&#xA;&lt;li&gt;SoftImage3D&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What app to choose depends on your exact needs*. For example do you need to retarget a existing animation to the new bone structure?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many of the game engines also suppprt FBX and possibly limited tweaking within their editor. Atleast Unreal and Unity support fbx. And if you do not try to do anything really invasive you might be able to use these tools.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* using these apps is outside the scope of this forum.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-09-08T03:58:26.653" LastActivityDate="2015-09-08T03:58:26.653" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1459" PostTypeId="1" CreationDate="2015-09-08T11:56:20.203" Score="6" ViewCount="2338" Body="&lt;p&gt;What is the practical difference between 3D Graphics Engine (OGRE), 3D Game Engine (Quake), 3D Software Rendering Engine, 3D Graphics API (OpenGL/DirectX)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is OpenGL/DirectX a 3D Graphics API or a 3D Software Rendering Engine?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I want to start learning 3D computer graphics and geometric modeling, which one do I need?&lt;/p&gt;&#xA;" OwnerDisplayName="user464" LastEditorUserId="528" LastEditDate="2015-09-16T13:05:43.533" LastActivityDate="2015-09-16T13:05:43.533" Title="What is the practical difference between 3D Graphics Engine, 3D Game Engine, 3D ........?" Tags="&lt;terminology&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1460" PostTypeId="2" ParentId="1459" CreationDate="2015-09-08T12:35:15.227" Score="13" Body="&lt;p&gt;At the base, &lt;strong&gt;rendering APIs&lt;/strong&gt; like OpenGL or Direct3D provide a unified interface to communicate with graphics adapters at a low level. Differences in hardware are hidden behind the abstraction which simplifies development a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The low-level APIs provide basic functionality, which gives you total control but leaves you without a lot of desired features. &lt;strong&gt;3D Rendering Frameworks&lt;/strong&gt; like OGRE or Irrlicht introduce the more understandable concept of 3D objects that can be moved in space (without having to worry about transformation matrices most of the time), introduce light sources and algorithms for shadow casting (e.g. shadow mapping), loading of common mesh formats, and the list goes on. I call this a &lt;em&gt;framework&lt;/em&gt;, because you still need to develop the application yourself using actual code, while an &lt;em&gt;engine&lt;/em&gt; provides you with an application to develop your software in. This is just my personal distinction and both terms are used differently in a variety of contexts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a &lt;strong&gt;3D Authoring / Rendering Software&lt;/strong&gt; like Blender or Autodesk Maya (offline) or 3DExcite DeltaGen (real-time) you can load, display or create meshes using the built-in functionality. These applications target the creation of 3D data, images or movies, and usually you can't create interactive applications easily with it. Be aware that some 3D Authoring have modules specifically targeting this, e.g. Blender and the integrated Blender Game Engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A &lt;strong&gt;3D Game Engine&lt;/strong&gt; finally provides you with all the tools to make it easy for you to develop a game. You will usually be provided with a level editor, a material editor and maybe a visible scripting language (like Unreal's Blueprint or earlier Kismet) to implement dynamic behavior and interactivity. You don't have to worry about rendering algorithms, because they are already implemented for you. Your engine of choice may for example feature &lt;a href=&quot;http://people.mpi-inf.mpg.de/~ritschel/Papers/SSDO.pdf&quot;&gt;SSAO&lt;/a&gt; and &lt;a href=&quot;http://developer.download.nvidia.com/SDK/10.5/opengl/src/cascaded_shadow_maps/doc/cascaded_shadow_maps.pdf&quot;&gt;cascaded shadow maps&lt;/a&gt; for dynamic objects and a solution to bake global illumination for static geometry. Also, a game engine includes way more than only rendering, e.g. artificial intelligence, sound, loading of assets, exporting your content into a ready-to-install package etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, each software package generally puts another layer of abstraction on, ideally making your life simpler. Each has its own purpose and allows you to do different things. Note that said terms are very broad and people have different opinions and sometimes even debates about where one category ends and the next one begins. My advice is to not lose sleep over it.&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2015-09-10T09:25:22.543" LastActivityDate="2015-09-10T09:25:22.543" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1461" PostTypeId="1" AcceptedAnswerId="1464" CreationDate="2015-09-08T23:27:42.983" Score="22" ViewCount="6072" Body="&lt;p&gt;I have heard from many sources that having T-junctions in 3D meshes is a bad idea because it could result in cracks during rendering. Can someone explain why that happens, and what one can do to avoid them?&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-09-28T10:31:28.150" Title="Why do T-junctions in meshes result in cracks?" Tags="&lt;mesh&gt;" AnswerCount="4" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1462" PostTypeId="2" ParentId="1461" CreationDate="2015-09-09T01:44:12.587" Score="9" Body="&lt;p&gt;When modeling parametric surfaces with a mesh in the parameter domain, T-junctions will most probably appear as &lt;em&gt;discontinuities&lt;/em&gt; in the surface. These will show up as gaps in the rendering. See below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More generally, T-junctions in triangle meshes will probably result in discontinuities of interpolated attributes, such as color and normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5U2ei.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5U2ei.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/d2248.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d2248.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="192" LastEditorUserId="192" LastEditDate="2015-09-09T01:52:32.200" LastActivityDate="2015-09-09T01:52:32.200" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1463" PostTypeId="2" ParentId="1461" CreationDate="2015-09-09T08:04:11.530" Score="5" Body="&lt;p&gt;Floating-point rounding error.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After you transform the T junction and the point in the T can get rounded away from the edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then it can happen that a fragment that gets sampled for a pixel lies in the gap between the 2 surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be fixed by not having a T-junction in the first place.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-09-09T08:04:11.530" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1464" PostTypeId="2" ParentId="1461" CreationDate="2015-09-09T08:38:29.530" Score="23" Body="&lt;p&gt;lhf's answer is good from the perspective of tessellation, but these can occur with simpler triangle mesh use cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Take this trivial example of three, &lt;em&gt;screen-space&lt;/em&gt; triangles, ABC, ADE and DBE...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sFxmG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sFxmG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although point E was, mathematically, intended to be exactly on the line segment AB, the pipeline won't be using fully precise values, such as rational numbers (e.g. &lt;a href=&quot;https://gmplib.org/&quot; rel=&quot;noreferrer&quot;&gt;https://gmplib.org/&lt;/a&gt;). Instead, it will likely be using floats, and so some approximation/error will be introduced. The result is probably going to be something like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2QYZw.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2QYZw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that &lt;em&gt;all&lt;/em&gt; of the vertices may have inaccuracies. Although the example above shows a crack, the T-junction may instead result in overlap along the edge causing pixels to be drawn twice. This might not seem as bad, but it can cause problems with transparency or stencil operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You &lt;em&gt;might&lt;/em&gt; then think that with floating-point the error introduced will be insignificant, but in a renderer, the screen-space vertex (X,Y) values &lt;em&gt;are nearly always represented by fixed-point numbers&lt;/em&gt; and so the displacement from the ideal location will usually be much greater. Further, as the rendering hardware &quot;interpolates&quot; the line segment pixel-by-pixel with its own internal precision, there is even more chance it will diverge from the rounded location of E.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the T-junction is &quot;removed&quot; by, say, also dividing triangle ABC into two, i.e. AEC and EBC, the problem will go away as the shifts introduced by the errors will all be consistent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, you might ask why do renderers (especially HW) use fixed-point maths for the vertex XY coordinates? Why don't they use floating-point in order to reduce the problem? Although some did (e.g. Sega's Dreamcast) it can lead to another problem where the triangle set-up maths becomes catastrophically inaccurate, particularly for long-thin triangles, and they change size in unpleasant ways.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2015-09-28T10:31:28.150" LastActivityDate="2015-09-28T10:31:28.150" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1465" PostTypeId="2" ParentId="1461" CreationDate="2015-09-09T09:04:21.967" Score="2" Body="&lt;p&gt;The simple way to avoid this is to ensure that all your vertices are welded&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You issue is that you have cuts along edges with a vertex, but you do not have a corresponding vertex on the adjacent edge to weld/connect it to, if you think of it like a button on a shirt, you've sown on a button to the edge, but haven't given it a hole so the fabric is open.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the picture below, the red dots represent correctly welded vertices, the blue dots all need an additional vertex to be cut in to the adjacent edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xy7f2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xy7f2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally speaking it is good practice to keep your modelling in quad's &amp;amp; tri's, this helps to alleviate this issue as you should always have a corresponding vertex to weld too. It also helps to keep to quads if you plan to use any subdivision methods on the mesh.&lt;/p&gt;&#xA;" OwnerUserId="118" LastActivityDate="2015-09-09T09:04:21.967" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1466" PostTypeId="1" AcceptedAnswerId="1468" CreationDate="2015-09-09T09:08:28.230" Score="11" ViewCount="4328" Body="&lt;p&gt;I've got a lot of confusion and I need to clarify some terminology and put together the knowledge.&lt;br&gt;&#xA;If I say that an engine is a ray tracer (so it uses the ray tracing algorithm to render the scene), is it automatically a physically based engine? I mean, ray tracing is by its definition physically based or there could be some ray tracers that are not physically based? (and, symmetrically, are there some non-ray tracers that are physically based?)&lt;br&gt;&#xA;Also, is it true that &quot;physically based&quot; means also that &quot;resolves the light transport equation&quot; ?&lt;/p&gt;&#xA;" OwnerUserId="1605" OwnerDisplayName="Marina Cooper" LastActivityDate="2015-09-10T06:14:22.217" Title="Physically based rendering and ray tracing" Tags="&lt;rendering&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1467" PostTypeId="1" CreationDate="2015-09-09T14:23:46.073" Score="4" ViewCount="311" Body="&lt;p&gt;I am looking for a good introduction to Lane-Riesenfeld algorithms, which are a family of subdivision methods for generating uniform B-splines. Any suggestions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Note.&lt;/em&gt; This is a copy of &lt;a href=&quot;https://math.stackexchange.com/questions/1428101/an-introduction-to-lane-riesenfeld-algorithms&quot;&gt;the question I asked on Mathematics StackExchange&lt;/a&gt;. One of the users there suggested this site might have more answers to offer.&lt;/p&gt;&#xA;" OwnerUserId="1606" LastEditorUserId="-1" LastEditDate="2017-04-13T12:19:38.027" LastActivityDate="2015-09-09T15:59:58.710" Title="An introduction to Lane-Riesenfeld algorithms" Tags="&lt;algorithm&gt;&lt;geometry&gt;&lt;subdivision&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2017-06-17T19:18:11.903" ContentLicense="CC BY-SA 3.0" />
  <row Id="1468" PostTypeId="2" ParentId="1466" CreationDate="2015-09-09T16:46:00.053" Score="16" Body="&lt;p&gt;&quot;Physically based&quot; is not a very well defined term, so it's difficult to answer this question exactly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, &quot;physically based&quot; refers to the fact that the algorithm in question is derived from physically based principles. It's not physically correct (because we can't afford that) and some approximations usually have to be made, but it's well known what those approximations are and ideally there is some intuition as to what kind of error it introduces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is in contrast to ad hoc models, which are usually made by an artist who observes an effect in real life and tries to write a shader or similar that somehow mimics the look of it. Usually ad hoc models are simpler and cheaper and tend to be the first solutions to turn up for a given problem, but they don't offer any particular insight into what's actually happening. It's also practically impossible to say how accurately such a model is able to reproduce the effect that it attempts to simulate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the context of rendering, a &quot;physically based renderer&quot; would therefore be simply something that renders an image using physically based principles, which is a very vague classification. A ray tracer is not inherently physically based, and most early ray tracers in fact used ad hoc models for lighting and similar. From my personal experience, &quot;physically based rendering&quot; used to usually refer to solving the rendering equation. However, it seems that in recent years, many game engines have claimed this term as well to mean &quot;we do energy conservation&quot; or &quot;we no longer use phong&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So really, there's no hard classification of what &quot;physically based rendering&quot; means, and using ray tracing by itself does not make a renderer physically based. In offline rendering, this term is still mostly used to refer to renderers that solve the rendering equation, whereas in real-time rendering, it more likely refers to the use of microfacet models or similar. But it's possible that the meaning of this term will change over the years.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-09-09T16:46:00.053" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1469" PostTypeId="2" ParentId="1466" CreationDate="2015-09-10T05:55:21.797" Score="2" Body="&lt;p&gt;No, simply:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Physically based rendering does not necessitate raytracing. One can use other means.*&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Raytracing can be used to do other effects than physically based rendering. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Raytracing is often easiest to implement and think out. Therefore its widely deployed for physically based rendering. But for same reason many nonrealistic renders use raytracing tricks to get what they need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* Personally ive been toying with unstructured FEM for rendering images&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-09-10T06:14:22.217" LastActivityDate="2015-09-10T06:14:22.217" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1470" PostTypeId="1" CreationDate="2015-09-10T08:28:52.850" Score="12" ViewCount="516" Body="&lt;p&gt;When I was reading theory behind physical based rendering I noticed that definition of BSDF and radiance has some problems. For example BSDF of purely specular surfaces is zero almost everywhere and infinite in one point or radiance of directional light is zero for almost all directions except for one where it is again infinite.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This causes problems in rendering equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_0(x, \omega_0)= \int_{S^2}{\rho(x, \omega_i,\omega_0)L(x, \omega_i)\,\mathrm{d}\sigma_\perp(\omega_i)}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For purely specular surface this integral has to be zero, from strict mathematical point of view. This is because the BSDF is zero (solid angle)-almost everywhere. You can argue that BSDF is infinite in one point and you have to take this point into account. But how do you know what is the reflectance of the surface at that point? From the infinity you can really tell. Furthermore from mathematical standpoint of view you cannot integrate infinite valued function, even if you could than the only sensible answers would be zero or infinity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know these are subtle problems and in practice can be solved with few &lt;code&gt;if&lt;/code&gt;s but I would like to have theory without holes. I believe that if you embrace these problems in theory than it helps you with placing those &lt;code&gt;if&lt;/code&gt;s in the right place.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;How to deal with this problem? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not sure entirely but as I can remember Erich Veach &lt;a href=&quot;https://graphics.stanford.edu/papers/veach_thesis/&quot; rel=&quot;nofollow&quot;&gt;in his thesis&lt;/a&gt; address this problem only slightly and tries to get away with it by saying that BSDF and radiance are &lt;a href=&quot;https://en.wikipedia.org/wiki/Distribution_(mathematics)&quot; rel=&quot;nofollow&quot;&gt;distributions&lt;/a&gt;. This is problematic, you cannot multiply two distributions, which is needed in rendering equation. For example when a light from  directional light hits specular surface than you need to multiply two Dirac delta functions together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is: Is there any work which reformulates rendering equation, BSDF and radiance in such a way that it does not suffer from mentioned problems?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the state of the art theory behind raytracing? Is is still Erich Veach's thesis?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I'm only aware of &lt;a href=&quot;http://cybertron.cg.tu-berlin.de/lessig/projects/dissertation/index.html&quot; rel=&quot;nofollow&quot;&gt;work&lt;/a&gt; of Christian Lessig, but his work is still beyond my mathematical reach.)&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I already have &lt;a href=&quot;http://tomsmathjourneys.blogspot.cz/2015/09/better-code-with-radiance-and-bsdf-as.html&quot; rel=&quot;nofollow&quot;&gt;proposal&lt;/a&gt; how to deal with this problem. I define BSDF and radiance as measure. The basic idea works fine, but the whole theory of light transport needs to be redone to find out if it really works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main purpose of this question is to find out if someone else already did it, so I can read it and then focus my energy somewhere else.&lt;/p&gt;&#xA;" OwnerUserId="1613" LastEditorUserId="16" LastEditDate="2015-11-03T15:19:40.177" LastActivityDate="2015-11-03T15:19:40.177" Title="Problem with definition of BSDF and radiance" Tags="&lt;raytracing&gt;&lt;radiosity&gt;&lt;theory&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1471" PostTypeId="2" ParentId="185" CreationDate="2015-09-10T11:11:54.013" Score="8" Body="&lt;p&gt;There is one important distinction to make. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Markov Chain Monte Carlo (such as Metropolis Light Transport) methods fully acknowledge the fact that they produce lots of highly correlated, it is actually the backbone of the algorithm. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;On other hand there are algorithms as Bidirectional Path Tracing, Many Light Method, Photon Mapping where the crucial role plays Multiple Importance Sampling and its balance heuristics. Optimality of balance heuristic is proven only for samples that are independent. Many modern algorithms have correlated samples and for some of them this causes troubles and for some it doesn't.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with correlated samples was acknowledged in the paper &lt;a href=&quot;https://scholar.google.com/citations?view_op=view_citation&amp;amp;hl=en&amp;amp;user=Glq3dWkAAAAJ&amp;amp;citation_for_view=Glq3dWkAAAAJ:WF5omc3nYNoC&quot; rel=&quot;noreferrer&quot;&gt;Probabilistic Connections for Bidirectional Path Tracing&lt;/a&gt;. Where they have altered balance heuristics to take into account the correlation. Have a look at figure 17 in the paper to see the result.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I would like to point out that correlation is &quot;always&quot; bad. If you can afford to make brand new sample than do it. But most of the time you can't afford it so you hope that the error due to the correlation is small.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit to explain the &quot;always&quot;&lt;/strong&gt;: I mean this in the context of MC integration&#xA;&lt;a href=&quot;https://i.stack.imgur.com/st1XC.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/st1XC.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where you measure the error with variance of the estimator&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wEs1y.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wEs1y.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the samples are independent that the covariance term is zero. Correlated samples make always this term nonzero thus increasing variance of the final estimator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is at first sight somewhat contradictory what we encounter with stratified sampling because stratification lowers the error. But you can't prove that stratified sampling converges to the desired result just from the probabilistic point of view, because in the core of stratified sampling there is no probability involved.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;And the deal with stratified sampling is that it is basically not a Monte Carlo method. Stratified sampling comes from standard quadrature rules for numerical integration which works great for integrating smooth function in low dimensions. This is why it is used for handling direct illumination which is low dimensional problem, but its smoothness is disputable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So stratified sampling is yet different kind of correlation than for example correlation in Many Light methods.&lt;/p&gt;&#xA;" OwnerUserId="1613" LastEditorUserId="1613" LastEditDate="2015-09-10T12:27:27.860" LastActivityDate="2015-09-10T12:27:27.860" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1472" PostTypeId="1" AcceptedAnswerId="1476" CreationDate="2015-09-10T13:20:30.943" Score="5" ViewCount="394" Body="&lt;p&gt;I have an issue with rendering my textures in Silverlight. When I look at it from above everything looks fine:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zjAeu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zjAeu.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But if I only change angle of watching it it looks terrible:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4b2AU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4b2AU.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am using very simple pixel shader (hlsl):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float4 main(VsOutput vertex) : COLOR&#xA;{&#xA;        float4 texColor = tex2D(textureSampler, texCoord);&#xA;&#xA;        return texColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If I don' t use that pixel shader and load texture via BasicEffect like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;BasicEffect.texture = myTexture&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Everything looks fine. Why my pixel shader affects texture so bad?&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;I expect that it might be somehow connected with mipmapping, but I am not sure - my texture is pretty small so I guess it shouldn' t have such a big effect. Anyway I need some advices :).&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;" OwnerUserId="205" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-09-11T08:28:29.850" Title="Texture glitch when using simple pixel shader" Tags="&lt;texture&gt;&lt;rendering&gt;&lt;pixel-shader&gt;&lt;hlsl&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1473" PostTypeId="1" CreationDate="2015-09-10T16:45:30.430" Score="12" ViewCount="2564" Body="&lt;p&gt;DirectX 12 exposes command queues for either graphics (called &quot;Direct&quot;), compute or copy tasks. In terms of provided functionality, each one is a super-set of the following one. The &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn899124%28v=vs.85%29.aspx&quot;&gt;specification&lt;/a&gt; states that command queues can be executed concurrently by the device.  However, the API does not limit the number of command queues in any way (at least I am not aware any limitation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apparently, different vendors handle this very different:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Intel states in a &lt;a href=&quot;https://software.intel.com/sites/default/files/managed/4a/38/Efficient-Rendering-with-DirectX-12-on-Intel-Graphics.pdf&quot;&gt;recent presentation&lt;/a&gt; (slide 23) that currently their GPUs are not able to handle Graphics &amp;amp; Compute in parallel and that the copy engine has a weak throughput. They advise against the use of multiple graphics/compute queues.&lt;/li&gt;&#xA;&lt;li&gt;AMD started &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Asynchronous-Shaders-White-Paper-FINAL.pdf&quot;&gt;long time ago&lt;/a&gt; to advertise the use of queues / &quot;asynchronous shaders&quot; starting with Mantle and the current gen consoles. There are also some developers (&lt;a href=&quot;http://fumufumu.q-games.com/archives/TheTechnologyOfTomorrowsChildrenFinal.pdf&quot;&gt;example&lt;/a&gt;) that confirm significant performance gains by executing compute and graphics tasks in parallel.&lt;/li&gt;&#xA;&lt;li&gt;There has been recently &lt;a href=&quot;http://www.guru3d.com/news-story/nvidia-wanted-oxide-dev-dx12-benchmark-to-disable-certain-settings.html&quot;&gt;some fuss&lt;/a&gt; about Nvidia not supporting asynchronous shader in the hardware: Using separate Graphics and Compute queue at once seems to make things slower which indicates driver emulation. Parallel copy operations, on the other hand, have been supported by CUDA for a very long time, which makes it clear that the DMA engine can work independently.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is there any way to decide at runtime if it is meaningful to commit CommandLists to multiple CommandQueues instead of a single one?&lt;/strong&gt; (given that former case does not involve much engineering-overhead)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While I can easily see how it is useful to perform memory operations parallel to compute/graphics operations, it strikes me as unnecessarily complicated to run multiple compute and graphics processes in parallel (unless there is no major perf. benefit).&#xA;It is also not clear to me, how this can lead to significantly better performance anyways; except for pathological cases where many small sequential tasks are not able to generate enough GPU load.&lt;/p&gt;&#xA;" OwnerUserId="528" LastActivityDate="2016-05-04T22:38:30.980" Title="How many Direct/Compute/Copy Queues are meaningful?" Tags="&lt;directx12&gt;&lt;api&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1476" PostTypeId="2" ParentId="1472" CreationDate="2015-09-11T06:22:54.503" Score="5" Body="&lt;p&gt;So I followed Alan Wolfe suggestion (in comment to my question) And turned out he was right. I was using &lt;code&gt;SamplerState.LinearWrap&lt;/code&gt; and that was the issue. When I changed this to &lt;code&gt;AnisotropicWrap&lt;/code&gt; it looked much better. Below are some examples of different sampling types and how they affect texture:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;graphicsDevice.SamplerStates[0] = SamplerState.PointWrap;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/p7YQk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/p7YQk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pldvb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pldvb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;graphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xNkBM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xNkBM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="205" LastEditorUserId="385" LastEditDate="2015-09-11T08:28:29.850" LastActivityDate="2015-09-11T08:28:29.850" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1477" PostTypeId="2" ParentId="320" CreationDate="2015-09-11T08:22:01.553" Score="2" Body="&lt;p&gt;According to Wikipedia (insert standard disclaimer RE accuracy):&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;JPEG does not define which color encoding is to be used for images. JFIF&#xA;  defines the color model to be used: either Y for greyscale, or YCbCr as&#xA;  defined by CCIR 601.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;YCbCr is a non-linear format. As I mentioned earlier, &quot;Video Demystified&quot; states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&quot;YCbCr is the color space originally defined by BT.601, and now used for&#xA;  all digital component video formats. .... The technically correct notation&#xA;  is Y'Cb'Cr' since all three components are derived from R'G'B'.&quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;and Charles' Poynton's &lt;a href=&quot;http://poynton.com/notes/colour_and_gamma/ColorFAQ.html&quot; rel=&quot;nofollow&quot;&gt;Colour FAQ&lt;/a&gt; states&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Video systems approximate the lightness response of vision using R'G'B'&#xA;  signals that are each subject to a 0.45 power function.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;With compression we are after the best visual representation per bit and, as the eye is non-linear in approximately this way, it makes sense to use non-linear representations.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2015-09-11T08:22:01.553" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1478" PostTypeId="1" CreationDate="2015-09-11T13:43:28.783" Score="1" ViewCount="224" Body="&lt;p&gt;There's a thing called &lt;a href=&quot;http://enbdev.com/&quot; rel=&quot;nofollow&quot;&gt;ENB&lt;/a&gt; for PC which works by modifying render functions calls of the games and applying additional effects. I wonder if there is a similar way for console games.&lt;/p&gt;&#xA;" OwnerUserId="1622" LastActivityDate="2015-09-11T13:43:28.783" Title="Is it possible to modify a console game graphics (Xbox 360)?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;direct3d&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1479" PostTypeId="1" AcceptedAnswerId="1480" CreationDate="2015-09-11T18:12:10.897" Score="15" ViewCount="3530" Body="&lt;p&gt;Space-filling curves are important in many graphics applications because they help expose spatial locality. We often hear about different algorithms using Z-curves, Morton codes, Hilbert curves, etc. What are the differences between some of these different curves and how do they apply to various applications?&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-09-12T06:03:22.127" Title="What is the difference between various space-filling curves?" Tags="&lt;space-filling&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1480" PostTypeId="2" ParentId="1479" CreationDate="2015-09-11T21:24:34.860" Score="14" Body="&lt;p&gt;The difference is how well a mapping preserves locality and how easy it is to encode/decode the keys. The paper &quot;Linear Clustering of Objects with Multiple Attributes&quot; by H V Jagadish says: &quot;Through algebraic analysis, and through computer simulation, we showed that under most circumstances, the Hilbert mapping performed as well as or better than the best of alternative mappings suggested in the literature&quot;. On the other hand, z-order is a bit simpler to use, for example compare the various methods listed in &lt;a href=&quot;https://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableObvious&quot;&gt;Bit Twiddling Hacks&lt;/a&gt; for z-order and &lt;a href=&quot;https://en.wikipedia.org/wiki/Hilbert_curve#Applications_and_mapping_algorithms&quot;&gt;Wikipedia&lt;/a&gt; for Hilbert-order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the applications, I think the main advantage in using space filling curves is that they map points from higher dimensional space to space of lower dimension. For example, they make it possible to window query for points using traditional B-tree database index. Again, on the other hand, the disadvantage is that one needs to know the bounds of the input in advance as it is difficult to &quot;resize&quot; the mapping later.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: &quot;Z-curve&quot; is the same as &quot;Morton code&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PPS: Additional mappings include &lt;a href=&quot;https://en.wikipedia.org/wiki/Peano_curve&quot;&gt;Peano curve&lt;/a&gt; and for applications see also &lt;a href=&quot;https://en.wikipedia.org/wiki/Geohash&quot;&gt;Geohash&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="141" LastEditDate="2015-09-11T21:36:23.550" LastActivityDate="2015-09-11T21:36:23.550" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1481" PostTypeId="2" ParentId="1479" CreationDate="2015-09-12T05:55:26.723" Score="10" Body="&lt;p&gt;Those space filling curves allow to keep locality in multiple dimensions when you &quot;walk&quot; linearly along the curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I have seen, Z-Order (also known as Morton code) is the most employed because of its computational cost which is constant (and cheap) to access any point of the curve directly. (And easy to implement in hardware with 0 cycle penalty, as it corresponds to &quot;just switching&quot; address wires).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A concrete example of Z-Order curve is texture swizzling : which is basically increasing the cache-hit rate for texture read on GPUs.&#xA;(See images in the article about Z-Curve &lt;a href=&quot;https://en.wikipedia.org/wiki/Z-order_curve&quot;&gt;https://en.wikipedia.org/wiki/Z-order_curve&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the texture is simply stored linearly, you get the maximum cache hit if you render just the texture as 2D image, but if you rotated it by 90 degree on screen, you get into the worst case scenario (cache miss for every texture read).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a result, it is better to trade off a little and lower your best case scenario and have better cache hit for most of the patterns.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a personal note, from what I have seen, other curves may require recursive step for their computation and result in bigger cost than Z-Curve with a minimal gain in term of locality coherence. So, I have not heard about those curve used with a practical purpose, except as a research subject in mathematic or creative/funny rendering.&lt;/p&gt;&#xA;" OwnerUserId="105" LastEditorUserId="105" LastEditDate="2015-09-12T06:03:22.127" LastActivityDate="2015-09-12T06:03:22.127" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1482" PostTypeId="2" ParentId="342" CreationDate="2015-09-13T06:13:54.857" Score="1" Body="&lt;p&gt;Gobal illumination, radiosity, etc is not a mutually exclusive set with using a fill light to adjust the feeling. Sometimes the artist can do wonders with a few well placed lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So yes they are used, each game and situation is different. Perhaps they are just going for a unrealistic mood or the artist wants to tweak the result a bit.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-09-13T06:13:54.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1483" PostTypeId="2" ParentId="241" CreationDate="2015-09-13T07:36:40.457" Score="2" Body="&lt;p&gt;It turns out that the chromaticity chart is harder to read than I anticipated. The CMYK slice is actually triangular of sorts its just that the chromaticity chart is not really linear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The chromaticity chart is made with the assumption that light is a spectra. The curved arc is the pure spectral color of the rainbow. Everything in between is interpolated edge values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/COa4K.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/COa4K.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Visible specturm on the edge, interpolations on surface. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now magentas are a bit peculiar. They only exist in our brains interpretation, thus they can not be measured. Magentas are sort of virtual colors that make the color circle full. This means that when you move from absence of blue towards absence of green your line kinks since the graph has no well defined direction for magenta's. This makes a 4th corner where none should be located.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Magentas are thus a bit of virtual colors that only exist in our brain. Not in physics, they are 2 spectra interleaved. There are off course many such metamers.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-09-13T11:52:18.847" LastActivityDate="2015-09-13T11:52:18.847" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1484" PostTypeId="1" CreationDate="2015-09-13T12:04:33.700" Score="5" ViewCount="91" Body="&lt;p&gt;How do I go about defining this area without using a piecewise function?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think it has something to do with Bilinear Surfaces but I'm not sure how to get started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MpA53.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MpA53.png&quot; alt=&quot;Graph showing an area composed of a square region adjoining a triangular region&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1630" LastEditorUserId="231" LastEditDate="2015-09-13T15:45:49.400" LastActivityDate="2015-11-03T15:12:26.733" Title="Two-dimensional bounded area defined parametrically" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1485" PostTypeId="1" CreationDate="2015-09-13T14:07:26.800" Score="8" ViewCount="296" Body="&lt;p&gt;Assume my 3D model is a pyramid with a rectangular base and I numerate four corners of the base with 1, 2, 3, 4 and give 5 to the top point. If I project this pyramid into a 2D star-shaped object, would not all four outer points of the star be associated with the point number 5 in the 3D model? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4jnxw.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4jnxw.jpg&quot; alt=&quot;Hand drawn image of a square base pyramid and its star shaped 2D net&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1628" LastEditorUserId="231" LastEditDate="2015-09-13T15:56:23.850" LastActivityDate="2015-09-15T02:18:19.527" Title="Does UV-mapping generate for some points of the 3D model several points in the 2D projection?" Tags="&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1486" PostTypeId="2" ParentId="1484" CreationDate="2015-09-13T14:24:06.633" Score="4" Body="&lt;p&gt;One solution is bilinear mapping, which works for every convex quadrilateral.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let $A, B, C, D$ be the vertices of a quadrilateral $Q$ in the plane, in this order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then $f(u,v)=(1-u)(1-v)A + u(1-v)B + uvC + (1-u)vD$ maps the square $[0,1] \times [0,1]$ to $Q$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DKYWs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DKYWs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3OIsg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3OIsg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="192" LastEditorUserId="137" LastEditDate="2015-11-03T15:12:26.733" LastActivityDate="2015-11-03T15:12:26.733" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1487" PostTypeId="2" ParentId="1485" CreationDate="2015-09-13T17:18:59.183" Score="10" Body="&lt;p&gt;The way it is usually defined, every vertex in a mesh corresponds to a UV-coordinate, and there must be exactly one such coordinate per vertex, because that is how a renderer would fetch texels. So it is impossible to have multiple UV coordinates for a single vertex unless you have multiple parameterizations for your mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, meshes often get split up during parameterizations and the same vertices can end up in multiple locations, just like in your example. Most often, those vertices are simply replicated while loading/rendering so the vertex-to-uv mapping remains 1-to-1 or many-to-1. So a renderer will likely interpret your example as the following (v5 is split into 4):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gqVkk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gqVkk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="14" LastEditorUserId="14" LastEditDate="2015-09-13T17:26:02.537" LastActivityDate="2015-09-13T17:26:02.537" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1488" PostTypeId="1" CreationDate="2015-09-13T17:41:06.043" Score="-4" ViewCount="4162" Body="&lt;p&gt;I'm using Unity 5 to make a small game (I'm a beginner) and I want to make a 3D model of a character. I'm not sure what software there is to do this and if there is some, I would like it to be preferably free, but if anyone can help or give advice I would appreciate it. I want to be able to make a 3D model and then import it to Unity 5. Thank you.&lt;/p&gt;&#xA;" OwnerUserId="1632" LastEditorUserId="6546" LastEditDate="2017-05-02T08:27:43.637" LastActivityDate="2017-05-02T08:27:43.637" Title="How to make a 3D model for Unity 5" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2015-09-18T11:02:08.207" ContentLicense="CC BY-SA 3.0" />
  <row Id="1489" PostTypeId="2" ParentId="1488" CreationDate="2015-09-13T18:04:12.780" Score="2" Body="&lt;p&gt;&lt;a href=&quot;https://www.blender.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender&lt;/a&gt; likely meets your requirements. I have used it in the past to make 3D models and export to model files which Unity can import.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would highly recommend watching some tutorial videos before using it:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=gF6qkByl-_M&quot; rel=&quot;nofollow noreferrer&quot;&gt;one&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=y__uzGKmxt8&quot; rel=&quot;nofollow noreferrer&quot;&gt;two&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=2zd1AI198I8&quot; rel=&quot;nofollow noreferrer&quot;&gt;three&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://blender.stackexchange.com/&quot;&gt;Blender StackExchange&lt;/a&gt; can help answer more questions about Blender.&lt;/p&gt;&#xA;" OwnerUserId="14" LastEditorUserId="-1" LastEditDate="2017-04-13T12:57:46.990" LastActivityDate="2015-09-13T23:39:40.247" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1490" PostTypeId="1" CreationDate="2015-09-14T06:51:06.910" Score="6" ViewCount="393" Body="&lt;p&gt;In all computer graphics books there are algorithms for scan converting simple primitives like lines, circles, ellipse,...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't find algorithms for more advanced curves like bezier curves, b-spline, nurbs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where can I find the references ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also another doubt: are scan converting and rastering the same thing ?&lt;/p&gt;&#xA;" OwnerUserId="1636" LastActivityDate="2015-09-14T13:18:08.537" Title="Algorithms for scan converting b-spline and nurbs" Tags="&lt;curve&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1491" PostTypeId="2" ParentId="1490" CreationDate="2015-09-14T13:10:41.883" Score="6" Body="&lt;p&gt;Ignoring Non-uniform B-splines (rational or not), I have had some experience with rasterisation of Beziers and, since there is a trivial mapping from &lt;em&gt;Uniform&lt;/em&gt; B-Splines to Beziers, those too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have used two different techniques: The first was a scan-line renderer that used Newton-Rhapson to compute the intersection of the current scanline with the curve. This requires the first derivative but, as that can be trivially derived, again as a Bezier representation, from the control points of the parent curve, it's easy to obtain. Further, the bounding box of the control points of the 1st derivative can be useful to detect if the region might have more than 1 intersection with the scan line.&#xA;The current scanline can use the previous scanline's solution as a starting point - usually that gives a highly accurate solution with one iteration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, a second approach is to simply apply binary subdivision of the curve and render it as series of straight line segments with your favourite polygonal renderer. If I recall correctly, at least with cubic Beziers, with each subdivision the error between the line segment joining the end points of the (sub)Bezier and the true curve decreases by a factor of 4. In most cases it therefore doesn't take many subdivisions before the difference between the polygonal approximation and the true curve is insignificant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, if you need info on derivatives of Beziers (or almost everything else related to them), &lt;a href=&quot;https://pomax.github.io/bezierinfo/&quot;&gt;this astounding web-page appeared&lt;/a&gt; in my twitter feed recently.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2015-09-14T13:18:08.537" LastActivityDate="2015-09-14T13:18:08.537" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1492" PostTypeId="2" ParentId="1485" CreationDate="2015-09-15T02:18:19.527" Score="4" Body="&lt;p&gt;I just need to add a bit to ap_'s answer.&lt;br&gt;&#xA;Of course you can have multiple UV for one vertex, this is called UV layers. This is how engines have displayed lightmaps and albedo maps on the same time, since the advent of lightmaps. (quake engine in 1996 maybe ?)&lt;br&gt;&#xA;You can have more UV layers, if you want to do multitexturing like for terrains, lightmap, albedo large, albedo detail, normal map...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the rasterizer will never chose a UV layer depending on the primitive it is rendering. Such a renderer could be done with a supplementary index buffer (primitive to UV layer mapping buffer) but no graphic cards and no graphics API supports this. This is an unnecessary violation to KISS anyway.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, what one would do in this case is to separate your pyramid apex into 4 distinct vertices during design time. Anyway the first reason for this, not being UV unwrapping but mostly normal definition. If you want sharp edges, you need to break the shading, therefore you need to have different normals, they too, like UV, are usually defined 1-1 in the vertex stream.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Final suggestion, maybe you dont really want to use this unwrapping, I would rather suggest this:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/r1OYC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/r1OYC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This way you have seamless continuity for filtering and looks on the edges and on the apex.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2015-09-15T02:18:19.527" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1493" PostTypeId="1" AcceptedAnswerId="1498" CreationDate="2015-09-15T11:55:18.913" Score="26" ViewCount="10532" Body="&lt;p&gt;My intuition has always been that when any sphere is projected into 2D space that the result will always mathematically be an ellipse (or a circle in degenerate cases).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the past when I was actively doing my own graphics programming and brought this up with other people they were adamant that I was wrong. If I recall correctly they believed the result could be something vaguely &quot;egg shaped&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Who was correct?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Since there is already one answer submitted, I don't wish to totally change my question but I realize I left out important details due to losing familiarity with the field over the years.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I intended to ask specifically about &lt;strong&gt;perspective projection where the projection is a linear application&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other projections are of course interesting for many uses so I wouldn't want them removed at this point. But it would be great if answers could have perspective projection as their most prominent section.&lt;/p&gt;&#xA;" OwnerUserId="1647" LastEditorUserId="231" LastEditDate="2015-09-18T08:03:39.967" LastActivityDate="2018-04-11T09:18:58.903" Title="Does a sphere projected into 2D space always result in an ellipse?" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="5" CommentCount="10" FavoriteCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1494" PostTypeId="2" ParentId="397" CreationDate="2015-09-15T12:01:59.980" Score="1" Body="&lt;p&gt;In 2009 it seems there was a development of an hierarchical and comparison motion detection algorithm that was proposed in this paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://perso.ensta-paristech.fr/~manzaner/Publis/icip09.pdf&quot; rel=&quot;nofollow&quot;&gt;Motion detection: fast and robust algorithms for embedded systems&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They managed to get a decent reduction of noise, as you can see in the last image of the paper. It seems it's the &quot;morphological post-processing&quot; that removes stand-alone pixels (section &lt;strong&gt;2.4 New hierarchical algorithm&lt;/strong&gt;). Perhaps a similar technique can be applied to denoise the video.&lt;/p&gt;&#xA;" OwnerUserId="157" LastActivityDate="2015-09-15T12:01:59.980" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1495" PostTypeId="1" CreationDate="2015-09-15T12:02:02.450" Score="4" ViewCount="447" Body="&lt;p&gt;I first read &lt;a href=&quot;https://computergraphics.stackexchange.com/a/401/157&quot;&gt;Alan's answer about video noise removal&lt;/a&gt; which lead me to this question. I found later &lt;a href=&quot;http://www.codeproject.com/Articles/10248/Motion-Detection-Algorithms&quot; rel=&quot;nofollow noreferrer&quot;&gt;some algorithms ideas&lt;/a&gt; which capture motion in a similar way (frame comparison, as Alan described).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then I found this &lt;a href=&quot;http://perso.ensta-paristech.fr/~manzaner/Publis/icip09.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;motion detection: fast and robust algorithms&quot; paper&lt;/a&gt; where they propose a hierarchical and conditional motion detection algorithm... I didn't read it throughly, but they seem to have isolated well all the objects in motion, since noise was almost completely removed (last image of the paper). However they say:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;As its complexity remains low, this algorithm is well suited for very&#xA;  light embedded systems. Future work will consider other difficult&#xA;  sequences with the presence of clutter like snow, rain or moving&#xA;  trees.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What if my intention was actually use their &quot;morphological post-processing&quot; technique to remove the detection of small objects instead of &quot;stand-alone pixels&quot; (their size would be defined according to the frame resolution)? This paper was published in 2009 and I found &lt;a href=&quot;http://link.springer.com/article/10.1007%2Fs11554-008-0096-7&quot; rel=&quot;nofollow noreferrer&quot;&gt;this related paper&lt;/a&gt;, also from 2009... Are there any newer updates on this or different techniques?&lt;/p&gt;&#xA;" OwnerUserId="157" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-09-15T12:02:02.450" Title="How to ignore rain or smaller objects movements in motion detection?" Tags="&lt;algorithm&gt;&lt;denoise&gt;&lt;motion&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ClosedDate="2016-04-07T15:23:12.463" ContentLicense="CC BY-SA 3.0" />
  <row Id="1496" PostTypeId="1" CreationDate="2015-09-15T12:06:48.257" Score="6" ViewCount="1262" Body="&lt;p&gt;Back in the day when you often had to write your own low level rendering algorithms we all used to learn the Bresenham algorithms for lines and circles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It was almost trivially easy to extend the Bresenham circle algorithm to cover ellipses whose axes were parallel to the X and Y axes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it always eluded me if there was some Bresenham-style way to render an arbitrary ellipse whose axes were at some arbitrary angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does such a scanline method for rotated ellipses exist?&lt;/p&gt;&#xA;" OwnerUserId="1647" LastEditorUserId="231" LastEditDate="2015-09-26T21:37:14.117" LastActivityDate="2015-09-29T15:00:23.567" Title="Is there some kind of Bresenham algorithm or equivalent for scanline rendering a rotated ellipse?" Tags="&lt;rendering&gt;&lt;algorithm&gt;&lt;curve&gt;&lt;scanline&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1497" PostTypeId="2" ParentId="1493" CreationDate="2015-09-15T14:39:41.883" Score="14" Body="&lt;p&gt;Projection systems are used to convert a 3D shape to a planar (2D) shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to the type of projection system, different results and shapes like rectangles, pies, ellipses, circles, ... can be produced out of a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Projection systems can be classified by the characteristics of the result they generate. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To continue, I would like to use a very touchable and common example that we have all seen before, Earth sphere and global wide maps, they are everywhere.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Suppose your sphere is the earth!&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Imagine the earth as your sphere and a planar world map that is created from the spherical shape of the earth. In most of the world maps you see the countries near to the poles are getting much bigger than they are in reality, like Iceland which is 1/14 of Africa continent in reality but the map shows them both as equal. This is because when we are omitting one dimension we loose one characteristic of our shapes.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Different projection systems and their results&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;This is a planar projection which doesn't conserve distance, angles or area. The red circles show the amount of exaggeration that is the product of this projection.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/oOdDDuk.jpg&quot; alt=&quot;First&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Equal-Area, look at Iceland and Africa in this one and compare with above.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/SE2kwxL.jpg&quot; alt=&quot;Second&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Projection systems can be classified by what they preserve.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Equal area.&lt;/li&gt;&#xA;&lt;li&gt;Equal angle which preserve the shape without distortion (conformal).&lt;/li&gt;&#xA;&lt;li&gt;Equal distance.&lt;/li&gt;&#xA;&lt;li&gt;......&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Conformal projections preserve the shapes but area will not be preserved (the first above picture) this one is the most famous projection system that is used in many applications. Your sphere is a rectangle here!&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h3&gt;So you cannot say a sphere will be projected to an ellipse always. As mentioned above a sphere can be projected to a rectangle (first shape) or can be an ellipse but with different characteristics (equal angle, distance, shape, area - see the following picture), or you may also project a sphere into a conic and then open the conic so you will have a pie.&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Each of the above projection systems can be applied with iterative or direct algorithms that can be found on the internet. I didn't talk about the formula and transformations because you didn't ask. Although I wish you to find this answer useful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/o1rYfhh.jpg&quot; alt=&quot;Third&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h3&gt;In perspective projections I say yes only ellipses will be produced out of spheres&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Cutting a conic with a horizontal plane creates a circle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cutting with an oblique plane creates a bevel which would be an ellipse or a hyperbola depending on the cutting angle, and when this angle inclines to be vertical in will create a parabola (following picture).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/1FYpdUj.jpg&quot; alt=&quot;Ellipse&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe this is obvious but take a look at their equations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For simplicity I assumed all geometries are origin centered.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Equations:&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Circle: $x^2+y^2=r^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ellipse: $x^2/a^2+y^2/b^2=1$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hyperbola: $x^2/a^2-y^2/b^2=1$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Parabola: $y^2=4ax$&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Morphology :&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;An ellipse has two foci obviously. A circle as a special kind of ellipsis has two foci too but they are coincident. A hyperbola however is a y axis mirror of its equal ellipsis and it has two foci too. A parabola has one focus but actually it has two because the second one is at infinity: when the cutting plane inclines to 90 degrees (bearing angle), second focus goes to infinity.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Conclusion&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;As you see all are ellipses, however you may name them differently to describe special cases, but if you are going to implement it in a game, you need to assume an ellipse equation and it is enough. I can't tell which one of you guys are right, you or your friend, because both could be right.&lt;/p&gt;&#xA;" OwnerUserId="537" LastEditorUserId="137" LastEditDate="2015-11-03T15:17:54.333" LastActivityDate="2015-11-03T15:17:54.333" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1498" PostTypeId="2" ParentId="1493" CreationDate="2015-09-15T15:22:22.677" Score="20" Body="&lt;p&gt;Assuming a perspective projection and a view point external to the sphere, then the 'boundary' formed by the view point and the circle on the sphere which forms the horizon WRT the view point, will be a cone. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing a perspective projection (onto a plane) is then equivalent to intersecting this cone with the plane which thus produces a conic section. FYI the four, non-degenerate, cases are shown in this image from Wikipedia &lt;a href=&quot;https://i.stack.imgur.com/RAwDQ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RAwDQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An ellipse/circle is thus a possibility, but not the only one - unbounded parabolas or hyperbolas (and I guess if the plane passes through the eye, even degenerate cases ) are possible.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-02-02T10:36:32.350" LastActivityDate="2016-02-02T10:36:32.350" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1499" PostTypeId="2" ParentId="1496" CreationDate="2015-09-15T16:14:06.920" Score="9" Body="&lt;p&gt;The classic book &lt;em&gt;Computer Graphics: Principles and Practice&lt;/em&gt; (second edition) by Foley, van Dam, et al. describes such an algorithm in section 19.2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The explanation in the book seems to come from an MSc thesis, &lt;a href=&quot;http://cs.brown.edu/research/pubs/theses/masters/1989/dasilva.pdf&quot;&gt;Raster Algorithms for 2D Primitives&lt;/a&gt; by Dilip Da Silva. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;See also these papers:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://dx.doi.org/10.1145/282918.282943&quot;&gt;Curve-drawing algorithms for raster displays&lt;/a&gt; by Van Aken and Novak (&lt;em&gt;ACM TOG&lt;/em&gt;, 1985). &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://doi.ieeecomputersociety.org/10.1109/38.506&quot;&gt;A tracking algorithm for implicitly defined curves&lt;/a&gt; by Chandler (&lt;em&gt;IEEE Computer Graphics and Applications&lt;/em&gt;, 1988).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="192" LastEditorUserId="192" LastEditDate="2015-09-15T16:31:12.100" LastActivityDate="2015-09-15T16:31:12.100" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1500" PostTypeId="2" ParentId="1493" CreationDate="2015-09-15T19:36:41.750" Score="15" Body="&lt;p&gt;This is more like a long comment to @SimonF's answer that I'm trying to make somewhat self contained.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All cuts of cone are possible, hyperbola, parabola and ovals. This is easy to test by drawing images in a 3D engine by a extremely wide angle camera. Rotate the camera to say in 30 degree angle so the object is not in the middle of your focus. Then gradually move the camera closer to the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zi6eX.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zi6eX.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1:&lt;/strong&gt; Flying very close to a sphere looking slightly sideways. Notice how we suddenly puncture the surface form inside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to recap when the sphere is very close so it exits the picture in wide image it can be a parabola or hyperbola. But the shape will just exit the frame to do so.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-09-15T19:36:41.750" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1501" PostTypeId="2" ParentId="1493" CreationDate="2015-09-15T20:39:57.047" Score="11" Body="&lt;p&gt;SimonF's reasoning basically convinced me, but I decided to do a sanity check. I loaded up a UE4 level that happens to have some spheres, like this one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RQ16v.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RQ16v.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I set the camera FOV up to 160 degrees to give lots of perspective distortion, and positioned it so the sphere was near the corner of the image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yzF3C.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yzF3C.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I took this into Inkscape and used the ellipse tool to draw on it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LuSyP.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LuSyP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Surprise! It's a perfect fit!&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-09-15T20:39:57.047" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1502" PostTypeId="1" AcceptedAnswerId="1506" CreationDate="2015-09-15T21:08:13.860" Score="25" ViewCount="9989" Body="&lt;p&gt;When rendering 3D scenes with transformations applied to the objects, normals have to be transformed with the transposed inverse of the model view matrix. So, with a normal $n$, modelViewMatrix $M$, the transformed normal $n'$ is &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$n' = (M^{-1})^{T} \cdot n $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When transforming the objects, it is clear that the normals need to be transformed accordingly. But why, mathematically, is this the corresponding transformation matrix?&lt;/p&gt;&#xA;" OwnerUserId="127" LastEditorUserId="127" LastEditDate="2015-11-03T16:02:39.780" LastActivityDate="2017-10-01T23:52:53.853" Title="Why is the transposed inverse of the model view matrix used to transform the normal vectors?" Tags="&lt;transformations&gt;&lt;geometry&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="12" ContentLicense="CC BY-SA 3.0" />
  <row Id="1503" PostTypeId="2" ParentId="1502" CreationDate="2015-09-15T21:15:36.447" Score="7" Body="&lt;p&gt;This is simply because normals are not really vectors! They are created by cross products, which results in &lt;a href=&quot;https://en.wikipedia.org/wiki/Bivector&quot; rel=&quot;noreferrer&quot;&gt;bivectors&lt;/a&gt;, not vectors. Algebra works much different for these coordinates, and geometric transformation is just one operation that behaves differently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A great resource for learning more about this is &lt;a href=&quot;http://www.terathon.com/gdc12_lengyel.pdf&quot; rel=&quot;noreferrer&quot;&gt;Eric Lengyel's presentation on Grassman Algebra&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-09-15T21:15:36.447" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1505" PostTypeId="2" ParentId="397" CreationDate="2015-09-15T23:13:13.823" Score="2" Body="&lt;p&gt;A fairly basic but effective technique is &lt;a href=&quot;https://en.wikipedia.org/wiki/Median_filter&quot; rel=&quot;nofollow noreferrer&quot;&gt;median filtering&lt;/a&gt;.  For video, you can apply it (spatio)temporally by replacing the value of each pixel in each frame by the median of the values of the pixel (and its neighbors) in the current and the &lt;em&gt;N&lt;/em&gt; previous and later frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A nice feature of median filtering is that it preserves linear edges (and, when used temporally, edges that move at a steady rate).  It does, however, tend to erode sharp corners and narrow ridges (and, temporally, narrow fast-moving features).  When overused, spatial median filtering has a tendency to create an over-smooth &quot;plastic&quot; appearance, while excessive temporal median filtering can even make small, fast-moving objects disappear completely.  (&lt;a href=&quot;https://photo.stackexchange.com/a/20960&quot;&gt;Sometimes&lt;/a&gt; this is considered a &lt;a href=&quot;http://www.deke.com/content/dekes-techniques-022-removing-people-with-image-stacks&quot; rel=&quot;nofollow noreferrer&quot;&gt;feature.&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's possible to fine-tune and improve median filtering further with advanced techniques like motion tracking and threshold detection, but those also introduce an extra layer of complexity, and thus extra opportunities for unwanted artifacts if applied carelessly.  For many purposes, a simple median filter &lt;em&gt;of moderate size and strength&lt;/em&gt; is often all you really need.&lt;/p&gt;&#xA;" OwnerUserId="525" LastEditorUserId="-1" LastEditDate="2017-04-13T12:44:05.773" LastActivityDate="2015-09-15T23:13:13.823" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1506" PostTypeId="2" ParentId="1502" CreationDate="2015-09-15T23:32:23.543" Score="25" Body="&lt;p&gt;Here's a simple proof that the inverse transpose is required. Suppose we have a plane, defined by a plane equation $n \cdot x + d = 0$, where $n$ is the normal. Now I want to transform this plane by some matrix $M$. In other words, I want to find a new plane equation $n' \cdot Mx + d' = 0$ that is satisfied for exactly the same $x$ values that satisfy the previous plane equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do this, it suffices to set the two plane equations equal. (This gives up the ability to rescale the plane equations arbitrarily, but that's not important to the argument.) Then we can set $d' = d$ and subtract it out. What we have left is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$n' \cdot Mx = n \cdot x$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll rewrite this with the dot products expressed in matrix notation (thinking of the vectors as 1-column matrices):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$${n'}^T Mx = n^T x$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now to satisfy this for &lt;em&gt;all&lt;/em&gt; $x$, we must have:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$${n'}^T M = n^T$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now solving for $n'$ in terms of $n$,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{aligned}{n'}^T &amp;amp;= n^T M^{-1} \\&#xA;n' &amp;amp;= (n^T M^{-1})^T\\&#xA;n' &amp;amp;= (M^{-1})^T n\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Presto! If points $x$ are transformed by a matrix $M$, then plane normals must transform by the inverse transpose of $M$ in order to preserve the plane equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is basically a property of the dot product. In order for the dot product to remain invariant when a transformation is applied, the two vectors being dotted have to transform in corresponding but different ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematically, this can be described by saying that the normal vector isn't an ordinary vector, but a thing called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Linear_form&quot; rel=&quot;noreferrer&quot;&gt;covector&lt;/a&gt; (aka covariant vector, dual vector, or linear form). A covector is basically defined as &quot;a thing that can be dotted with a vector to produce an invariant scalar&quot;. In order to achieve that, it has to transform using the inverse transpose of whatever matrix is operating on ordinary vectors. This holds in any number of dimensions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that in 3D specifically, a bivector is similar to a covector. They're not &lt;em&gt;quite&lt;/em&gt; the same since they have different units: a covector has units of inverse length while a bivector has units of length squared (area), so they behave differently under scaling. However, they do transform the same way with respect to their orientation, which is what matters for normals. We usually don't care about the magnitude of a normal (we always normalize them to unit length anyway), so we usually don't need to worry about the difference between a bivector and a covector.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2015-11-03T19:14:57.103" LastActivityDate="2015-11-03T19:14:57.103" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1507" PostTypeId="1" AcceptedAnswerId="1510" CreationDate="2015-09-16T06:04:16.483" Score="15" ViewCount="2581" Body="&lt;p&gt;I notice that most photorealistic renderers have very similar material test scenes. Here are a few examples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blender&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3uG1m.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3uG1m.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mitsuba&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EJIHh.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EJIHh.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vray&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dlDd6.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dlDd6.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: why is this specific model / style chosen to test materials? Does it have some advantage over &lt;a href=&quot;http://i9.photobucket.com/albums/a90/thatsmessedup/teapot74hoursl24.png&quot; rel=&quot;noreferrer&quot;&gt;teapots&lt;/a&gt;, spheres, and &lt;a href=&quot;http://www.flickr.com/photos/thomasberglund/5215885180/&quot; rel=&quot;noreferrer&quot;&gt;suzannes&lt;/a&gt;? Are there other common scenes for material testing?&lt;/p&gt;&#xA;" OwnerUserId="14" LastEditorUserId="38" LastEditDate="2015-09-16T13:37:34.167" LastActivityDate="2015-09-17T10:55:21.367" Title="Why do most photorealistic renderers have similar material test scenes?" Tags="&lt;material&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1508" PostTypeId="2" ParentId="15" CreationDate="2015-09-16T06:05:56.157" Score="5" Body="&lt;p&gt;More of an extended comment than an answer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do you mean by &quot;optimization and accuracy&quot;? Do you mean computational efficiency for some particular application, like ray tracing, physical simulation, CAD modeling, ....?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the idea of &quot;accuracy&quot; for a subdivision scheme is not well-posed. Different schemes will have different limit surfaces, but there is no canonical way of declaring one limit surface to be &quot;more accurate&quot; than any another. One can pose some constraints on the type of limit surface one desires, but these constraints are again very application-dependent: one person might ask for $G^n$ everywhere, the next will complain because this precludes preserving sharp creases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Catmull-Clark (and Loop, for triangle meshes) remains popular because of its simplicity, which in many cases outweigh its weaknesses (no handling of sharp features; loss of regularity at extraordinary vertices). Countless alternative schemes (which may or may not be improvements over Catmull-Clark, depending on the specific application) have been proposed -- if you have a &lt;em&gt;specific&lt;/em&gt; application in mind, with specific requirements, we may be better able to help you navigate your options.&lt;/p&gt;&#xA;" OwnerUserId="1657" LastActivityDate="2015-09-16T06:05:56.157" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1509" PostTypeId="2" ParentId="405" CreationDate="2015-09-16T06:48:47.123" Score="4" Body="&lt;p&gt;Not the definitive toolbox you might be looking for, but just an extra tool I use myself: for 3d graphics, Blender might come in handy. Especially if you use the Export_SVG plugin (available from &lt;a href=&quot;http://dl.dropbox.com/u/16486113/Blender/archivos/temp/SVG/export_svg.py&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://dl.dropbox.com/u/16486113/Blender/archivos/temp/SVG/export_svg.py&lt;/a&gt; and &lt;a href=&quot;http://blenderartists.org/forum/showthread.php?282824-SVG-output-script&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blenderartists.org/forum/showthread.php?282824-SVG-output-script&lt;/a&gt; )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This allows you to get Blenders 3d objects as vector graphics in Illustrator or Inkscape. I find it gives me a nice quick start for creating &lt;strong&gt;simple&lt;/strong&gt; 3d illustrations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Allow  me to paste an example. (In this example I use a lot of colors, but ofcourse, it can be all made black-and-red-on-white instead)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dIyo9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dIyo9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1659" LastEditorUserId="1659" LastEditDate="2015-09-16T08:30:31.280" LastActivityDate="2015-09-16T08:30:31.280" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1510" PostTypeId="2" ParentId="1507" CreationDate="2015-09-16T07:47:23.190" Score="15" Body="&lt;p&gt;While teapot, spheres and trusty Suzanne are not per se bad test scenes for materials, here are some things to consider. You can apply them to said examples to forge your own opinion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First and foremost, the viewer needs to be able to examine the behavior of the BRDF. Since it is dependent on both the direction of incident light and the direction from surface to viewer, you need to have as many combinations as possible in your test scene. A spheroid nicely covers all possible viewer angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Notice that all three scenes feature some sharper edges or creases too. Differences in reflective behavior across a smooth surface (like a sphere) may be hard to conceive, so these edges put emphasis on this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the observed brightness and color is a combination of the material (i.e. the BRDF) and the lighting environment, it may be hard to tell one from another. The Vray test scene takes care of this. The 100% white 'core' and the 25% black floor help you get an idea of what the lighting in the scene is like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blender and Vray both feature a grid that helps you estimate the total size of the scene. This helps with evaluating grain or surface texture.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here is a side-by-side comparison of a cube, notched sphere and Suzanne for a glossy test material with a slight normal map (rendered in Blender with Cycles, lit with the &lt;a href=&quot;http://www.hdrlabs.com/sibl/archive.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dutch Skies 360 - Free 002&lt;/a&gt; HDR):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wtFVi.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wtFVi.jpg&quot; alt=&quot;Material test scene comparing cube, spheroid and Suzanne&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cube does a pretty good job on depicting the normal map. The sphere, as expected, is reasonably good for normals and gloss. Suzanne, arguably, makes both a bit harder to perceive than the spheroid.&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2015-09-17T10:55:21.367" LastActivityDate="2015-09-17T10:55:21.367" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1511" PostTypeId="2" ParentId="1507" CreationDate="2015-09-16T07:58:58.323" Score="9" Body="&lt;p&gt;You can choose whatever you want offcourse. A good material sample ideally has a few properties.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;It needs to show how the light falls of as the angle between light and surface normal changes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A sphere is pretty good for this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;It needs to show how any possible environment, maps, reflects, refraction etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A sphere is pretty good for this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;It may need to show how nonlocal effects happen such as global lightning, incandescence, subsurface scattering work&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some cavities and variation would be nice. A sphere is abysmal for this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The sample should be able to show how displacement looks like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple shape demonstrates this better. Complex shapes can cause displacements to self intersect. And its hard to know what is modeling and what is not.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Also it would be nice to see, different surface thicknesses, sharp corners, one way curved surfaces and doublecurvature surfaces. A neutral but nonuniform  environment would be nice too. Object should have a reasonable uv map. Apparent scale might be needed in some projects.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-09-16T08:06:13.643" LastActivityDate="2015-09-16T08:06:13.643" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1513" PostTypeId="1" AcceptedAnswerId="1514" CreationDate="2015-09-17T12:29:48.510" Score="34" ViewCount="5190" Body="&lt;p&gt;The classical way of shading surfaces in real-time computer graphics is a combination of a (Lambertian) diffuse term and a specular term, most likely Phong or Blinn-Phong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VOfxv.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VOfxv.png&quot; alt=&quot;Image from Wikipedia&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now with the trend going towards physically-based rendering and thus material models in engines such as &lt;a href=&quot;http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf&quot; rel=&quot;noreferrer&quot;&gt;Frostbite&lt;/a&gt;, &lt;a href=&quot;http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf&quot; rel=&quot;noreferrer&quot;&gt;Unreal Engine&lt;/a&gt; or &lt;a href=&quot;http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf&quot; rel=&quot;noreferrer&quot;&gt;Unity 3D&lt;/a&gt; these BRDFs have changed. For example (a pretty universal one at that), the latest Unreal Engine still uses Lambertian diffuse, but in combination with the Cook-Torrance microfacet model for specular reflection (specifically using GGX/Trowbridge-Reitz and a modified Slick approximation for the Fresnel term). Furthermore, a 'Metalness' value is being used to distinguish between conductor and dielectric.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For dielectrics, diffuse is colored using the albedo of the material, while specular is always colorless. For metals, diffuse is not used and the specular term is multiplied with the albedo of the material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding real-world physical materials, does the strict separation between diffuse and specular exist and if so, where does it come from? Why is one colored while the other is not? Why do conductors behave differently?&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2018-05-04T08:45:36.440" LastActivityDate="2020-01-02T07:13:47.620" Title="How physically-based is the diffuse and specular distinction?" Tags="&lt;physically-based&gt;&lt;physics&gt;&lt;brdf&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="20" ContentLicense="CC BY-SA 4.0" />
  <row Id="1514" PostTypeId="2" ParentId="1513" CreationDate="2015-09-17T17:02:42.913" Score="29" Body="&lt;p&gt;To start, I highly suggest reading Naty Hoffman's Siggraph &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&quot; rel=&quot;noreferrer&quot;&gt;presentation&lt;/a&gt; covering the physics of rendering. That said, I will try to answer your specific questions, borrowing images from his presentation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at a single light particle hitting a point on the surface of a material, it can do 2 things: reflect, or refract. Reflected light will bounce away from the surface, similar to a mirror. Refracted light bounces around inside the material, and may exit the material some distance away from where it entered. Finally, every time the light interacts with the molecules of the material, it loses some energy. If it loses enough of its energy, we consider it to be fully absorbed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To quote Naty, &quot;Light is composed of electromagnetic waves. So the optical properties of a substance are closely linked to its electric properties.&quot; This is why we group materials as metals or non-metals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Non metals will exhibit both reflection and refraction.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ECwfp.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ECwfp.png&quot; alt=&quot;Non-Metals&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Metallic materials only have reflection. All refracted light is absorbed.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/JyBy3.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JyBy3.png&quot; alt=&quot;Metals&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would be prohibitively expensive to try to model the light particle's interaction with the molecules of the material. We instead, make some assumptions and simplifications.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PXEQW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PXEQW.png&quot; alt=&quot;Simplifying refraction&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the pixel size or shading area is large compared to the entry-exit distances, we can make the assumption that the distances are effectively zero.&#xA;For convenience, we split the light interactions into two different terms. We call the surface reflection term &quot;specular&quot; and the term resulting from refraction, absorption, scattering, and re-refraction we call &quot;diffuse&quot;.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/85Pmg.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/85Pmg.png&quot; alt=&quot;Splitting into diffuse and specular&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this is a pretty large assumption. For most opaque materials, this assumption is ok and doesn't differ too much from real-life. However, for materials with any kind of transparency, the assumption fails. For example, milk, skin, soap, etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A material's observed color is the light that is not absorbed. This is a combination of both the reflected light, as well as any refracted light that exits the material. For example, a pure green material will absorb all light that is not green, so the only light to reach our eyes is the green light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore an artist models the color of a material by giving us the attenuation function for the material, ie how the light will be absorbed by the material. In our simplified diffuse/specular model, this can be represented by two colors, the diffuse color, and the specular color. Back before physically-based materials were used, the artist would arbitrarily choose each of these colors. However, it should seem obvious that these two colors should be related. This is where the albedo color comes in. For example, in UE4, they calculate diffuse and specular color as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;DiffuseColor = AlbedoColor - AlbedoColor * Metallic;&#xA;SpecColor = lerp(0.08 * Specular.xxx, AlbedoColor, Metallic)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where Metallic is 0 for non-metals and 1 for metals. The 'Specular' parameter controls the specularity of an object (but it's usually a constant 0.5 for 99% of materials)&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2015-09-17T21:52:08.073" LastActivityDate="2015-09-17T21:52:08.073" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1515" PostTypeId="1" AcceptedAnswerId="1517" CreationDate="2015-09-18T04:29:45.047" Score="13" ViewCount="4270" Body="&lt;p&gt;Most modern renderers use physically-based materials and their models are often parameterized over roughness. Since this wasn't always the case with renderers, conventional assets often don't have a notion of roughness. Instead, we see &quot;shininess&quot; or &quot;specular power&quot; as a common material parameter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that there is no exact conversion between the two, but is there a rule-of-thumb / approximate way to get roughness for a material whose specular power or shininess is known?&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-09-18T16:01:43.147" Title="What is the accepted method of converting shininess to roughness, and vice versa?" Tags="&lt;specular&gt;&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1517" PostTypeId="2" ParentId="1515" CreationDate="2015-09-18T07:30:54.973" Score="11" Body="&lt;p&gt;As you already note, there is no clear cut interpretation/conversion for these values. I think it is even much worse: Depending on your BRDF and internal limitations (like having defined exponents ranging from 2-2048) the interpretation is &lt;em&gt;completely&lt;/em&gt; different. Like suggested in the comments, it might be the best to render a series with different values and fit a conversion curve until the value looks intuitive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few examples I was able to find some blog posts that mention something about that topic:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;At Dontnod entertainment they use a &quot;perceptual linear distribution&quot;. &#xA;Sébastien Lagarde acknowledges the problem in &lt;a href=&quot;https://seblagarde.wordpress.com/2011/08/17/feeding-a-physical-based-lighting-mode/&quot; rel=&quot;noreferrer&quot;&gt;this blog post&lt;/a&gt; and writes a few notes on that.&lt;/li&gt;&#xA;&lt;li&gt;Brian Karis uses a squared roughness values in this &lt;a href=&quot;http://graphicrants.blogspot.de/2013/08/specular-brdf-reference.html&quot; rel=&quot;noreferrer&quot;&gt;Microfacet BRDF overview&lt;/a&gt;. This illustrates also nicely how differently  roughness is used in different Normal Distribution Functions. Blinn-Phong power is here defined as &lt;code&gt;2/roughness^4 - 2&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Frostbite uses a squared remapping. ie. Roughness =  (1 − Smoothness)^2&#xA;Details about it and their entire material system is explained in section 3.2 of Sebastien Lagarde's &lt;a href=&quot;http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf&quot; rel=&quot;noreferrer&quot;&gt;writeup&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://simonstechblog.blogspot.de/2011/12/microfacet-brdf.html&quot; rel=&quot;noreferrer&quot;&gt;This blog post&lt;/a&gt; suggests to define the roughness for a Beckmann distribution from the roughness alpha as:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1NWdA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1NWdA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="528" LastEditorUserId="310" LastEditDate="2015-09-18T16:01:43.147" LastActivityDate="2015-09-18T16:01:43.147" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1518" PostTypeId="2" ParentId="309" CreationDate="2015-09-19T00:23:24.103" Score="3" Body="&lt;p&gt;After looking into this for a while, I found out a couple of things:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;You cannot avoid a memcpy&lt;/strong&gt;: You cannot write directly into texture storage allocated for a compressed texture using only OpenGL API calls. This means that you cannot avoid the call to &lt;code&gt;glCompressedTexImage2D&lt;/code&gt; with a bound PBO. That being said, you may be able to use a 16-bit RGBA texture and a GLSL image type in your compute shader.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;You do need to synchronize memory&lt;/strong&gt;: In order to make sure that your compute shader finishes writing to your storage buffer, you must make sure that all reads and writes to it finish. This is done by calling &lt;code&gt;glMemoryBarrier&lt;/code&gt; with &lt;code&gt;GL_SHADER_STORAGE_BARRIER_BIT&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The full code for something that writes into a buffer to be used as a compressed texture looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint buffer;&#xA;glGenBuffers(1, &amp;amp;buffer);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer);&#xA;glBufferStorage(GL_SHADER_STORAGE_BUFFER, tex_size_in_bytes, 0, 0);&#xA;&#xA;glUseProgram(compute_shader_prog);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, compute_shader_bind_point, buffer);&#xA;glDispatchCompute(wg_x, wg_y, wg_z);&#xA;glMemoryBarrier(GL_SHADER_STORAGE_BUFFER_BIT);&#xA;&#xA;glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer);&#xA;glCompressedTexImage2D(GL_TEXTURE_2D, 0, fmt, w, h, 0, tex_size_in_bytes, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="197" LastEditorUserId="197" LastEditDate="2015-09-19T01:13:41.147" LastActivityDate="2015-09-19T01:13:41.147" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1519" PostTypeId="2" ParentId="1513" CreationDate="2015-09-21T04:47:42.927" Score="23" Body="&lt;p&gt;I was actually wondering about exactly this a few days ago.  Not finding any resources within the graphics community, I actually walked over to the Physics department at my university and &lt;em&gt;asked&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It turns out that there are a lot of lies we graphics people believe.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;First, when light hits a surface, the Fresnel equations apply.  The proportions of reflected/refracted light depend on them.  You probably knew this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;There's no such thing as a &quot;specular color&quot;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you might not have known is that the Fresnel equations vary based on wavelength, because the &lt;em&gt;refractive index&lt;/em&gt; varies based on wavelength.  The variation is relatively small for dielectrics (dispersion, anyone?), but can be enormous for metals (I presume this has to do with these materials' differing electric structures).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, the Fresnel reflection term varies by wavelength, and therefore &lt;em&gt;different wavelengths are reflected preferentially&lt;/em&gt;.  Seen under broad-spectrum illumination, this is what leads to specular color.  But in particular, there is &lt;em&gt;no absorption&lt;/em&gt; that magically happens at the surface (the other colors are just refracted).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;There's no such thing as &quot;diffuse reflection&quot;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Naty Hoffman says in the talk linked in the other answer, this is really an approximation to outscattered subsurface scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Metals DO transmit light&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Naty Hoffman is wrong (more precisely, simplifying).  Light does &lt;em&gt;not&lt;/em&gt; get absorbed immediately by metals.  In fact, it will pass quite handily through materials several nanometers thick.  (For example, for gold, it takes 11.6633nm to attenuate 587.6nm light (yellow) by half.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Absorption, as in dielectrics, is due to the Beer-Lambert Law.  For metals, the absorption coefficient is just much larger (α=4πκ/λ, where κ is the imaginary component of the refractive index (for metals ~0.5 and up), and λ is given in &lt;em&gt;meters&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This transmission (or more accurately the &lt;a href=&quot;https://en.wikipedia.org/wiki/Subsurface_scattering&quot;&gt;SSS&lt;/a&gt; it produces) is actually responsible for a significant portion of metals' colors (although it is true that metals' appearances are dominated by their specular).&lt;/p&gt;&#xA;" OwnerUserId="523" LastEditorUserId="231" LastEditDate="2015-09-22T09:51:46.387" LastActivityDate="2015-09-22T09:51:46.387" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1521" PostTypeId="1" AcceptedAnswerId="1527" CreationDate="2015-09-21T16:16:37.923" Score="4" ViewCount="197" Body="&lt;p&gt;I encountered this problem doing my project. Suppose there is a 3D mesh model, e.g. a human face, I need the 3D visibility map at each of the vertices of this model. By the &quot;3D visibility map&quot;, I mean the binary image covering the spherical surface indicating whether the point is visible from each spherical angle(different from ambient occlusion). So, it is like a mask image. For example, the visibility map for any point on a convex surface is all ones (occlusion by other objects is ignored, only self-occlusion). See the following figure for illustration &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iPtZq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iPtZq.jpg&quot; alt=&quot;spherical visibility map in two cases&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know is there some efficient ways solving this problem? I need to apply it to all vertices. All I have in mind is doing brute force verification for all sampling directions. What's more, is there any existing software or tool (e.g. pbrt, Unity, Blender) that is capable of this functionality? Any suggestions and links are welcome. Thanks!&lt;/p&gt;&#xA;" OwnerUserId="1692" LastEditorUserId="1692" LastEditDate="2015-09-22T01:52:57.000" LastActivityDate="2015-09-23T15:57:04.210" Title="How can I get a spherical visibility mask map for a point on a concave surface?" Tags="&lt;lighting&gt;&lt;occlusion&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1523" PostTypeId="1" AcceptedAnswerId="1545" CreationDate="2015-09-21T20:41:30.860" Score="15" ViewCount="3643" Body="&lt;p&gt;That it compresses the data compared to the pixel array is obvious.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what makes it different from from normal compression (like png, jpeg)? &lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2015-09-21T21:22:30.087" LastActivityDate="2018-04-23T07:55:03.983" Title="How does hardware texture compression work?" Tags="&lt;texture&gt;&lt;compression&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1524" PostTypeId="1" AcceptedAnswerId="1525" CreationDate="2015-09-22T09:04:58.360" Score="9" ViewCount="223" Body="&lt;p&gt;I wrote a particle based fluid simulating program. It's hard to tell if I get the right result. The visualized result seems reasonable, but some part of it looks weird. I don't know wether it's a feature of fluid. Is there some accurate method to verify if my program is right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Amending some details：&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My program is a 2D particle-based simulating program. The fluid is compressible. The implementation is almost based on a classical paper:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Müller, Matthias, David Charypar, and Markus Gross. &quot;Particle-based fluid simulation for interactive applications.&quot; Proceedings of the 2003 ACM SIGGRAPH&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I solved the Navier-Stokes equation with iteration method. It only considered pressure, gravity, viscosity and surface tension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://latex.codecogs.com/gif.latex?%5Crho&amp;space;(%5Cfrac%7B%5Cmathbf%7B%5Cpartial&amp;space;v%7D%7D%7B%5Cpartial&amp;space;t%7D&amp;space;&amp;plus;&amp;space;%5Cmathbf%7Bv%7D&amp;space;%5Ccdot&amp;space;%5Cbigtriangledown&amp;space;%5Cmathbf%7Bv%7D)&amp;space;=&amp;space;-%5Cbigtriangledown&amp;space;p&amp;space;&amp;plus;&amp;space;%5Crho%5Cmathbf%7Bg%7D&amp;space;&amp;plus;&amp;space;%5Cmu&amp;space;%5Cbigtriangledown%5E2&amp;space;%5Cmathbf%7Bv%7D&quot; title=&quot;\rho (\frac{\mathbf{\partial v}}{\partial t} + \mathbf{v} \cdot \bigtriangledown \mathbf{v}) = -\bigtriangledown p + \rho\mathbf{g} + \mu \bigtriangledown^2 \mathbf{v}&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="1697" LastEditorUserId="-1" LastEditDate="2017-03-10T09:42:35.410" LastActivityDate="2015-09-22T14:29:58.353" Title="How could I check the correctness of my result of fluid simulation?" Tags="&lt;physics&gt;&lt;simulation&gt;&lt;fluid-sim&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1525" PostTypeId="2" ParentId="1524" CreationDate="2015-09-22T11:30:06.133" Score="2" Body="&lt;p&gt;Compare it with someone else's software. Run some standardized test and find out if you get roughly the same answer as others. If you get the same answer, than the probability of having your code right is quite high.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some tests:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Flow past cylinder. In 2d take rectangular domain, cylinder in the middle, inflow on the left, outflow on the fight and calculate the force on the cylinder. Here is &lt;a href=&quot;http://www.karlin.mff.cuni.cz/~hron/NMMO403/dfg_benchmark_results.pdf&quot; rel=&quot;nofollow&quot;&gt;benchmark&lt;/a&gt; comparing handful of codes.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Buoyancy flow. Closed box, hot plate on bottom, cold plate on top, hot fluid starts to rise due to the buoyancy force. Here is &lt;a href=&quot;http://www.karlin.mff.cuni.cz/~hron/NMMO403/mit_bench.pdf&quot; rel=&quot;nofollow&quot;&gt;benchmark&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Rising bubble, &lt;a href=&quot;http://www.karlin.mff.cuni.cz/~hron/NMMO403/1934_ftp.pdf&quot; rel=&quot;nofollow&quot;&gt;benchmark&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;But unfortunately it might be quite difficult to compare your code to scientific codes in those benchmarks. I guess you implemented something as SPH or stable fluids which are not made for accuracy but for stability. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Take for example the flow past a cylinder. I would start the test with very small Reynolds number and then measure the force on cylinder as you increase accuracy of your simulation(lower time step, increase subdivision or increase number of particles). Does the force converges to some number? If no, than you have a problem, if yes, than have a look at the benchmark paper and compare your result with others.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This method is very similar technique to one I use for testing my raytracer. I just render test scene with someone else's renderer and compare it with my result. Do they converge to the same result? If yes than I have it right, if no, than I have it wrong.&lt;/p&gt;&#xA;" OwnerUserId="1613" LastActivityDate="2015-09-22T11:30:06.133" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="1526" PostTypeId="2" ParentId="159" CreationDate="2015-09-22T12:22:01.213" Score="12" Body="&lt;p&gt;For a realistic Iris, you need:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Geometry&lt;/strong&gt;: Irides are very different for different people and their appearance changes drastically depending on whether the pupil is dilated (sphicter muscle relaxed) or not. You will not get anywhere with primitives only. The whole structure is like a thick stretchy wrinkly cloth suspended in water. Wrinkles appear and disappear as it moves. Use a sculpting software and an anatomy textbook.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Material&lt;/strong&gt;: There is almost no specular on the iris since it is suspended in (basically) water which has a similar refractive index as tissue. I do not know the roughness values since I have never seen a dry Iris. With the &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow&quot; title=&quot;Microfacet Models for Refraction through Rough Surfaces (2007)&quot;&gt;GGX specular model&lt;/a&gt;, roughness 0.4 looks okay. Brown irides seem to be more rough, almost like very fine sand. A shading model that uses roughness in the diffuse component would be nice.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Textures&lt;/strong&gt;: While some are colorful, the vast majority of irides in the world are brown. You don't need too much variation inside the texture, it can be quite uniform. Make it relatively saturated and don't try to hint at geometry inside the texture by drawing dark areas for shadows or occlusion. Have a normal map. If the eye is animated, you need to blend between at least two normal maps for the dilated and undilated pupil. I don't think you need a roughness map, but especially for blue irides it might help.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Refraction and reflection&lt;/strong&gt; at the cornea: The cornea (the fluid layer coating it) acts as a lens. This distorts the image of the iris as seen by the camera. Without this, it will not look real, especially when looking at the eye from the side. The unusual thing about the eye is that, from a graphics point of view, the object is &lt;em&gt;inside&lt;/em&gt; the lens. So there's no thin lens equation going to come to your rescue. You have to refract light once, at the interface between the tear layer and air.&#xA;The other interfaces (tear layer to outside of cornea, layers and membranes inside the cornea, inside of cornea to chamber fluid) are not relevant since the indices of refraction are all very similar or the structures are extremely thin. The only other optically important structure is the lens, which is behind the iris and can be ignored.&#xA;The shape of the cornea is critical, as it will distort everything. People with cornea deformations such as a keratoconus have weird-looking eyes. Also the whole scene must reflect on the cornea/liquid. We expect to see reflections of light sources over the iris/pupil.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;strong&gt;limbus&lt;/strong&gt;: Looking frontally at the eye, there is a greyish ring around the Iris. This is the part where the cornea merges into the sclera (the &quot;white&quot; of the eye), transitioning from transparent to nontransparent. Behind the limbus, anatomically, is the iridocorneal angle, where the iris meets the rest of the eye. This area is impossible to see due to the refraction mentioned above, it is literally a place that has never seen any light. Light emitted from there experiences total internal refraction at the interface of the cornea, you can't look at it from the outside. Thus, it looks very very weird when the transition from iris to the rest of the eye is visible. You need both the refraction and the gradual transition from cornea to sclera to get this transition right.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Subsurface scattering&lt;/strong&gt;: You might possibly get away without it on the iris itself since there will never be light coming from the back, especially with a brown iris (more heavily pigmented -&gt; more attenuation during scattering). For some light directions, it will make a difference though. And you need it on the surrounding skin and sclera anyway. But it is not the most important effect.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ambient occlusion&lt;/strong&gt;: You need good &lt;a href=&quot;https://en.wikipedia.org/wiki/Screen_space_ambient_occlusion&quot; rel=&quot;nofollow&quot; title=&quot;Screen Space Ambient Occlusion&quot;&gt;SSAO&lt;/a&gt; (or &lt;a href=&quot;https://en.wikipedia.org/wiki/Global_illumination&quot; rel=&quot;nofollow&quot; title=&quot;Global Illumination&quot;&gt;GI&lt;/a&gt;) to make the fine structure stand out. There's almost no specular, so you need other visual cues for the geometry. Choose a method that uses your normals from the normal map. &lt;a href=&quot;http://www.twistedsanity.org/rdimitrov/HBAO_SIGGRAPH08.pdf&quot; rel=&quot;nofollow&quot; title=&quot;Image-Space Horizon-Based Ambient Occlusion&quot;&gt;HBAO&lt;/a&gt; will work well. For offline rendering, the GI will be done by your renderer of choice.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lighting&lt;/strong&gt;: Using some physically based method goes without saying. Image based lighting, especially for the cornea reflection. Under certain angles, refraction of the light at the cornea may become relevant as well (only for analytic lights). Postprocessing (bloom), especially for the cornea reflex.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Backscattered light from the retina, although it can be seen through the iris in very extreme viewing conditions during some medical examinations, is completely irrelevant for normal purposes. Basically, paint the retina black. If you want to go that far, you can add a little orange-red to the retina color whenever a strong light comes from a direction very very similar to the camera and the pupil is dilated (like a flash from a camera). But it will still not be strong enough to shine through the iris, by far. Black is an okay approximation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That list looks big, but you asked for photorealism ;) It will still look good if you only do the easy half and fake the rest.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Source: I do graphics programming for medical simulations with a focus on the human eye)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Material:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://hal.inria.fr/inria-00166304/&quot; rel=&quot;nofollow&quot;&gt;Anatomically accurate modeling and rendering of the human eye&lt;/a&gt; (2007)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.disneyresearch.com/publication/high-quality-capture-of-eyes/&quot; rel=&quot;nofollow&quot;&gt;High-Quality Capture of Eyes&lt;/a&gt; (Disney Research, Siggraph Asia 2014)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="1699" LastEditorUserId="231" LastEditDate="2015-09-23T16:24:11.350" LastActivityDate="2015-09-23T16:24:11.350" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1527" PostTypeId="2" ParentId="1521" CreationDate="2015-09-22T17:04:29.490" Score="3" Body="&lt;p&gt;This can be done analytically at least for polygonal meshes. You can convert points into polar coordinates and project on a sphere. Edges form planes that pass through projection circles center forming circles on the sphere. These lines are all great circles, because they must pass sphere center. Great circles form linear interpolations in polar coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JZHaM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JZHaM.png&quot; alt=&quot;Project triangle on sphere&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Projecting a geometry on a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Converting these great circles into either Cartesian coordinates is quite well known math. Projecting them onto 2d representation by Mercator projection is well known math on account fo this being central to map making. Since overlap is not a  problem you can just slap these triangles on top of each other and merge the vector results. Or use the polar coordinates for pixel graphics and even use z buffered overlap just like a normal camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only problematic point is the one where your sphere is generated (if its on a open face edge). You can simply project the point on center into its inverse normal direction on the projection sphere. Or if for example Mercator projection is desired, you can align the sphere with surface normal. then just project them to a point on the south pole.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can even interpolate the results of individual polygons positions to get any point on the triangle. And a analytic surface coverage for the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't implemented this, but Ive done it manually a few times* so i know its possible. Should be pretty easy to do as the maths involved aren't all that complicated only problem is solving which side of the problem to keep.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/j6qF1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j6qF1.png&quot; alt=&quot;Local horizon map&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Horizon map of a simple all local geometry.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Comparison with raytracing&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Both sampling triangles analytically is O(N) algorithm, if vector data is sufficient. Conditioning this data may push you over to O(N^2). Raytracing is O(N log(N)). Raytracing algorithms are easier to find of the shelf so implementing analytic polygon to sphere rendering is harder. In terms of speed analytical rendering is faster as long as theres a limited number of triangles, much like how scanline rendering is still sometimes faster than tracing despite being algorithmically more complex. This similarity is not just a coincidence it can be shown that this method can be turned into a scanline renderer.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Resources for drawing great circles in Mercator projection:&lt;/h3&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://demonstrations.wolfram.com/GreatCirclesOnMercatorsChart/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wolfram demonstration&lt;/a&gt; on subject.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://adsabs.harvard.edu/full/1932JRASC..26..161G&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Projection of Circles on a Mercator Map&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;* About 20-25 times. I also did it for this image (yes in 3d), its as accurate as a single span Bezier curve can represent a circle. Ive also done this in map making software a few times.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-09-23T15:57:04.210" LastActivityDate="2015-09-23T15:57:04.210" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1528" PostTypeId="2" ParentId="1496" CreationDate="2015-09-22T22:09:32.430" Score="9" Body="&lt;p&gt;All conics (including rotated ellipses) can be described by an implicit equation of the form&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;H(x, y) = A x² + B xy + C y² + D x + E y + F = 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The basic principle of the incremental line tracing algorithms (I wouldn't call them scanline) is to follow the pixels that fulfill the equation as much as possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on the local slope of the line, you progress more in the x or y direction, following either a lateral or diagonal move. This decision is made so that you minimize the absolute value of H(x, y).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of a straight line, the slope is a constant so that lateral and diagonal moves are always in the same direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of a circular arc, the slope varies and one can distinguish 8 cases corresponding to 8 octants of the curve (there are four possible lateral moves and for each two diagonal moves).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the ellipse and other conics, you can generalize the octant decomposition. This leads to a rather tedious discussion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can avoid the octant discussion and modify the algorithm to look at all neighbors of the current pixel. This leads to a general contour tracing algorithm like &lt;a href=&quot;http://www.imageprocessingplace.com/downloads_V3/root_downloads/tutorials/contour_tracing_Abeer_George_Ghuneim/moore.html&quot; rel=&quot;nofollow&quot;&gt;Moore's neighborhood&lt;/a&gt;, where you will follow the outline of the area &lt;code&gt;H(x, y) &amp;gt;= 0&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that lines, circles and axis-aligned ellipses can be described by an implicit equation with integer coefficients. This is no more possible with general conics and you will need to resort to floating-point, or good rational approximations.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Lastly, note that incremental computation saves work when evaluating H, on the line of&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;H(x+1, y) = H(x, y) + A.(2x+1) + B.y + D = H(x, y) + (2A).x + (A + B.y + D)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;A true scanline solution is also possible. Let &lt;code&gt;y&lt;/code&gt; vary incrementally, and solve the &lt;code&gt;H&lt;/code&gt; equation for &lt;code&gt;x&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;H(x, y) = A x² + (B y + D) x + (C y² + E y + F) = 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This will yield two &lt;code&gt;x&lt;/code&gt; values for each &lt;code&gt;y&lt;/code&gt;. The resulting curve will be much less pleasant as it will always count two pixels per row, which will leave holes when the slope is below &lt;code&gt;1&lt;/code&gt;. You can cope by filling the stretch of pixels between the roots on the successive rows.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastEditorUserId="1703" LastEditDate="2015-09-29T15:00:23.567" LastActivityDate="2015-09-29T15:00:23.567" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1529" PostTypeId="1" CreationDate="2015-09-23T04:09:55.423" Score="2" ViewCount="4502" Body="&lt;p&gt;I recently noticed that in some locations you could switch to a 3d mapping mode in Google Street View.&lt;br&gt;&#xA;Which algorithm(s) did they use to generate the 3d models of the streets? I assume it was more than just capture, given the huge amount of data that would be necessary to produce an accurate representation of the streets.&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2015-10-07T20:34:05.963" Title="What algorithm(s) are behind Google Street View's 3d mapping mode?" Tags="&lt;algorithm&gt;&lt;3d&gt;&lt;mapping&gt;&lt;model&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1531" PostTypeId="1" CreationDate="2015-09-23T16:46:18.353" Score="2" ViewCount="1012" Body="&lt;p&gt;I'm working on an assignment and I need to draw using only GL_POINTS. I realize this is an expensive approach but it's for the homework, so no GL_TRIANGLES / GL_POLYGON / GL_LINES etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I'm trying to understand the concept of using only points. Say I want to draw a square that's 100 x 100 pixels. Would I need four for-loops drawing 100 pixels each in straight lines to create the square? What if I want to fill the square with color?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand drawing a square using GL_POLYGON as that's fairly straight forward. We're using the GLUT library just to draw shapes with points.&lt;/p&gt;&#xA;" OwnerUserId="1705" LastActivityDate="2015-09-29T07:42:29.213" Title="GLUT OpenGL - Drawing Shapes using only GL_POINTS" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1533" PostTypeId="2" ParentId="338" CreationDate="2015-09-23T20:49:14.113" Score="1" Body="&lt;p&gt;Quickly Googling produces:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/4148831/how-to-offset-a-cubic-bezier-curve&quot;&gt;This related question&lt;/a&gt; on StackOverflow&lt;/li&gt;&#xA;&lt;li&gt;&quot;Computing offsets of NURBS curves and surfaces&quot; (paper)&lt;/li&gt;&#xA;&lt;li&gt;Discussions of 2.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;To summarize them:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Suggests that this is impossible to do exactly.&lt;/li&gt;&#xA;&lt;li&gt;Gives an algorithm to compute an offset curve approximately (though to within a tiny epsilon).  If you can't access the paper, then:&lt;/li&gt;&#xA;&lt;li&gt;Look at any of these.  &lt;a href=&quot;https://www.google.com/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=7&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=0CDwQFjAGahUKEwiihLzeg47IAhVHN4gKHfsmCaM&amp;amp;url=http%3A%2F%2Fwww.math.zju.edu.cn%2Fcagd%2FSeminar%2F2005_AutumnWinter%2F2005_Master_LH.ppt&amp;amp;usg=AFQjCNGlb556TMftSL8d4xU7kT1x7Q9G7Q&amp;amp;sig2=9rYaCjpqD-VMKu94ke5O7w&quot; rel=&quot;nofollow noreferrer&quot;&gt;This presentation&lt;/a&gt; for example seems to cover it.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="523" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2015-09-23T20:49:14.113" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1535" PostTypeId="1" AcceptedAnswerId="1548" CreationDate="2015-09-24T10:41:59.760" Score="10" ViewCount="744" Body="&lt;p&gt;&lt;a href=&quot;http://www.ppsloan.org/publications/StupidSH36.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Spherical Harmonics&lt;/a&gt; (SH) are a way to represent low-frequency spherical functions with only a handful of coefficients. They have some nice mathematical properties, e.g. a convolution with a kernel function &lt;em&gt;h(x)&lt;/em&gt; (that has circular symmetry) can be calculated as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oh3mt.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oh3mt.gif&quot; alt=&quot;(h * f)^m_l = \sqrt{\frac{4\pi}{2l+1}} h^0_l f^m_l&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of a &lt;a href=&quot;https://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/&quot; rel=&quot;nofollow noreferrer&quot;&gt;convolution with a cosine lobe&lt;/a&gt; for rank 3 SH this results in a simple scaling of the bands with the factors&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tIf94.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tIf94.gif&quot; alt=&quot;[\pi, \frac{2\pi}{3}, \frac{\pi}{4}]&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In many cases, e.g. incident light for a given point on an opaque surface, full spherical information is not needed, since half of the sphere is zero / undefined / unused anyway. Thus, &lt;a href=&quot;http://www.cs.ucf.edu/~ceh/Publications/Papers/Rendering/EGSR04GautronEtAl.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hemispherical Harmonics&lt;/a&gt; (HSH) were born.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does convolution with an arbitrary kernel (with circular symmetry) work for HSH? Can the convolution from SH be extended or is there any paper that goes into details on this?&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="231" LastEditDate="2016-06-16T11:23:43.593" LastActivityDate="2016-06-16T11:23:43.593" Title="Convolution of Hemispherical Harmonics" Tags="&lt;hemisphere&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1536" PostTypeId="1" CreationDate="2015-09-25T00:13:21.510" Score="16" ViewCount="31140" Body="&lt;p&gt;Why are Homogeneous Coordinates used in Computer Graphics?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What would be the problem if Homogeneous Coordinates were not used in matrix transformations?&lt;/p&gt;&#xA;" OwnerDisplayName="user464" LastActivityDate="2017-12-22T20:59:56.793" Title="Why are Homogeneous Coordinates used in Computer Graphics?" Tags="&lt;transformations&gt;" AnswerCount="7" CommentCount="1" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="1537" PostTypeId="2" ParentId="1536" CreationDate="2015-09-25T01:49:44.247" Score="14" Body="&lt;p&gt;They simplify and unify the mathematics used in graphics:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;They allow you to represent translations with matrices.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;They allow you to represent the division by depth in perspective projections.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The first one is related to affine geometry.&#xA;The second one is related to projective geometry.&lt;/p&gt;&#xA;" OwnerUserId="192" LastActivityDate="2015-09-25T01:49:44.247" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1538" PostTypeId="1" CreationDate="2015-09-25T03:16:41.270" Score="4" ViewCount="132" Body="&lt;p&gt;For normalization purposes, how to &quot;extract&quot; a BRDF function from an ad-hoc piece of pixel shading code ?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we have a shader function like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 MyShadingFunction(float3 incomingLightDirection, float incomingRadiance)&#xA;{&#xA;    float4 lightContributionToPixelColor;&#xA;&#xA;    // ...&#xA;    // several complicated formulas (to which we have access)&#xA;    // ...&#xA;&#xA;    return lightContributionToPixelColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What is the procedure to translate the &quot;complicated formulas&quot; into a BRDF function f that can then be mathematically integrated ?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;For example to use f in an expression such as:&lt;/em&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/InSPM.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/InSPM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2015-09-25T03:16:41.270" Title="How to extract a BRDF from a shader" Tags="&lt;shader&gt;&lt;brdf&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2015-09-30T07:48:52.413" ContentLicense="CC BY-SA 3.0" />
  <row Id="1539" PostTypeId="2" ParentId="1536" CreationDate="2015-09-25T04:08:40.117" Score="1" Body="&lt;p&gt;Calculations in affine coordinates often require divisions, which are expensive as compared to additions or multiplications. One usually does not need to divide when using projective coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using projective coordinates (and more generally, projective geometry) tends to eliminate special cases too, making everything simpler and more uniform.&lt;/p&gt;&#xA;" OwnerDisplayName="user1713" LastActivityDate="2015-09-25T04:08:40.117" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1540" PostTypeId="2" ParentId="1536" CreationDate="2015-09-25T07:03:11.327" Score="3" Body="&lt;p&gt;As a personal taste I have always abstained (when possible) from using homogeneous coordinates and preferred the plain Cartesian formulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Main reason is the fact that homogeneous coordinates uses 4 trivial entries in the transformation matrices (0, 0, 0, 1), involving useless storage and computation (also the overhead of general-purpose matrix computation routines which are &quot;by default&quot; used in this case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The downside is that you need more care when writing the equations and lose support of matrix theory, but so far I have survived.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastEditorUserId="1703" LastEditDate="2015-09-25T07:09:26.657" LastActivityDate="2015-09-25T07:09:26.657" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1541" PostTypeId="2" ParentId="1536" CreationDate="2015-09-25T08:28:40.463" Score="6" Body="&lt;p&gt;It's in the name: Homogeneous coordinates are well ... homogeneous.&#xA;Being homogeneous means a uniform representation of rotation, translation, scaling and other transformations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A uniform representation allows for optimizations. 3D graphics hardware can be specialized to perform matrix multiplications on 4x4 matrices. It can even be specialized to recognize and save on multiplications by 0 or 1, because those are often used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not using homogeneous coordinates may make it hard to use strongly optimized hardware to its fullest. Whatever program recognizes that optimized instructions of the hardware can be used (typically a compiler but things are more complicated sometimes) for homogeneous coordinates will have a hard time with optimizing for other representations. It will choose less optimized instructions and thus not use the potential of the hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As there were calls for examples:&#xA;Sony's PS4 can perform massive matrix multiplications. It's so good at it that it was sold out for some time, because clusters of them were used instead of more expensive super-computers. Sony subsequently demanded that their hardware may not be used for military purposes. Yes, super-computers are military equipment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It has become quite usual for researchers to use graphic cards to calculate their matrix multiplications even if no graphic is involved. Simply because they are magnitudes better in it than general purpose CPUs.&#xA;For comparison modern multi-core CPUs have on the order of 16 pipelines (x0.5 or x2 doesn't matter so much) while GPUs have on the order of 1024 pipelines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's not so much the cores than the pipelines that allow for actual parallel processing. Cores work on threads. Threads have to be programmed explicitly. Pipelines work on instruction level. The chip can parallelize instructions more or less on its own.&lt;/p&gt;&#xA;" OwnerUserId="1714" LastActivityDate="2015-09-25T08:28:40.463" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1542" PostTypeId="1" AcceptedAnswerId="1543" CreationDate="2015-09-26T04:38:14.037" Score="4" ViewCount="3134" Body="&lt;p&gt;Forgive me in advance for my ignorance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the PHP function imagecolorat, I have a solution that presently delivers a set of the most dominant hex color codes available inside of an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a known library that will allow me to then take the hex color code, RGB code (or any other standard color code) and simplify them down, or rather &quot;match&quot; them to a limited set of &quot;common colors&quot;, such as red, brown, green, yellow, grey, blue, etc?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, #944D70, which is a shade of purple, would be matched to the color 'purple'.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Alternatively:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a particular pattern or range to RGB colors that would allow me to write such a library myself?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, 0,0,0 thru 20,20,20 might all be considered a &quot;black&quot; color. However, it seems as if organizing such a library would be very exhausting if done manually.&lt;/p&gt;&#xA;" OwnerUserId="1723" LastActivityDate="2015-09-26T14:34:19.023" Title="Convert RGB, Hex or any other color format to &quot;Standard Color&quot; Programmatically" Tags="&lt;conversion&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1543" PostTypeId="2" ParentId="1542" CreationDate="2015-09-26T09:19:28.477" Score="6" Body="&lt;p&gt;Problem is that people do not really agree on a 1:1 mapping of color names. But yes such tools exists, this is a simple nearest neighborhood test. You could use any spatial query module to do this. Here is a simple (naive) python example: &lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;from __future__ import print_function&#xA;import webcolors&#xA;from scipy.spatial import KDTree&#xA;&#xA;# lets populate some names into spatial name database&#xA;hexnames = webcolors.css3_hex_to_names&#xA;names = []&#xA;positions = []&#xA;&#xA;for hex, name in hexnames.iteritems():&#xA;    names.append(name)&#xA;    positions.append(webcolors.hex_to_rgb(hex))&#xA;&#xA;spacedb = KDTree(positions)&#xA;&#xA;# query nearest point&#xA;querycolor = (10,88, 200)&#xA;dist, index = spacedb.query(querycolor)&#xA;&#xA;print('The color %r is closest to %s.'%(querycolor, names[index]))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which results in: &lt;code&gt;The color (10, 88, 200) is closest to royalblue.&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using here the 140 css3 defined colors. Bigger and more comprehensive lists can be found &lt;a href=&quot;https://en.wikipedia.org/wiki/Lists_of_colors&quot; rel=&quot;nofollow&quot;&gt;online&lt;/a&gt;, if you want a smallerlist that would also work. Theres all kinds of possible things you could do, you could for example linearize the sRGB space before calculating distances to name. You could ask for 3 closest names and give double names if the names are halfway.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-09-26T14:34:19.023" LastActivityDate="2015-09-26T14:34:19.023" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="1545" PostTypeId="2" ParentId="1523" CreationDate="2015-09-27T02:32:20.067" Score="27" Body="&lt;p&gt;As Simon's comment alluded to, one major difference between hardware texture compression and other commonly used image compression is that the former does not use entropy coding. Entropy coding is the use of shorter bit-strings to represent commonly-occurring or repeating patterns in the source data&amp;mdash;as seen in container formats like ZIP, many common image formats such as GIF, JPEG, and PNG, and also in many common audio and video formats.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Entropy coding is good at compressing all sorts of data, but it intrinsically produces a variable compression ratio. Some areas of the image may have little detail (or the detail is predicted well by the coding model you're using) and require very few bits, but other areas may have complex detail that requires more bits to encode. This makes it difficult to implement random access, as there is no straightforward way to calculate where in the compressed data you can find the pixel at given (&lt;em&gt;x&lt;/em&gt;,&amp;nbsp;&lt;em&gt;y&lt;/em&gt;) coordinates. Also, most entropy coding schemes are stateful, so it's not possible to simply start decoding at an arbitrary place in the stream; you have to start from the beginning to build up the correct state. However, random access is necessary for texture sampling, since a shader may sample from any location in a texture at any time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, rather than entropy coding, hardware compression uses fixed-ratio, block-based schemes.  For example, in &lt;a href=&quot;http://www.reedbeta.com/blog/2012/02/12/understanding-bcn-texture-compression-formats/&quot;&gt;DXT / BCn compression&lt;/a&gt;, the texture is sliced up into 4&amp;times;4 pixel blocks, each of which is encoded in either 64 or 128 bits (depending on which format is picked); in &lt;a href=&quot;https://en.wikipedia.org/wiki/Adaptive_Scalable_Texture_Compression&quot;&gt;ASTC&lt;/a&gt;, different formats use block sizes from 4&amp;times;4 up to 12&amp;times;12, and all blocks are encoded in 128 bits. The details of how the bits represent the image data vary between formats (and may even vary from one block to the next within the same image), but because the ratio is fixed, it's easy for hardware to calculate where in memory to find the block containing a given (&lt;em&gt;x&lt;/em&gt;, &lt;em&gt;y&lt;/em&gt;) pixel, and each block is self-contained, so it can be decoded independently of any other blocks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another consideration in hardware texture compression is that the decoding should be efficiently implementable in hardware. This means that heavy math operations and complex dataflow are strongly disfavored. The BCn formats, for instance, can be decoded by doing a handful of 8-bit integer math operations per block to populate a small lookup table, then just looking up the appropriate table entry per pixel.  This requires very little area on-chip, which is important because you probably want to decode several blocks in parallel, and thus need several copies of the decode hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In contrast, DCT-based formats like JPEG require a nontrivial amount of math per pixel, not to mention a complex dataflow that swaps and broadcasts various intermediate values across pixels within a block. (Look at &lt;a href=&quot;https://fgiesen.wordpress.com/2013/11/04/bink-2-2-integer-dct-design-part-1/&quot;&gt;this article&lt;/a&gt; for some of the gory details of DCT decoding.) This would be a lot grosser for hardware implementation, which I'm guessing is why AFAICT, no GPU hardware has ever implemented DCT-based or wavelet-based texture compression.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-09-27T02:32:20.067" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1546" PostTypeId="1" CreationDate="2015-09-27T05:14:24.863" Score="9" ViewCount="1176" Body="&lt;p&gt;Suppose we have a 64-bit word-addressable computer and we want to program it to output a 5x7 character stored as a binary image bitmap (such as the one below) to a memory-mapped display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LfHfE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LfHfE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/jaPjM.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jaPjM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since we have 5 x 7 = 35 pixels per character, we could store a character using 35 bits in a single word. With the least significant bit starting on the left side of the word and with each pixel in the image being represented by the &lt;em&gt;n&lt;/em&gt;th bit as shown above, the number &quot;3&quot; above would be stored in memory as: 01110100010000100110000011000101110, followed by 29 unused bits set to 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this how characters were/are stored in old/modern computers? Or do they use a single byte/word per pixel instead?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If they are stored in this manner, what would the routine in assembly/machine-code (using nothing more than elementary instructions such as bitwise, arithmetic and data transport operations from the computer's Instruction Set Architecture) used to convert this data into an image on the display look like? Would it be something like:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Store the x and y display coordinate for the current pixel to be updated in a certain register.&lt;/li&gt;&#xA;&lt;li&gt;Store the two chosen RGB values (in this case 0,255,0 for green and 0,0,0 for black) in two other separate registers.&lt;/li&gt;&#xA;&lt;li&gt;Have two further registers act as counters initialized to 5 and 7 to keep track of the current row and column of the image being rendered.&lt;/li&gt;&#xA;&lt;li&gt;Test if the column register is not 0. If it isn't, test if the LSB of the bitmap is set to 1, then AND the respective RGB value register with the x and y coordinate register depending on the result, then MOV that result to the display output register.&lt;/li&gt;&#xA;&lt;li&gt;Decrement the row counter register by 1, test to see if it is 0. If it is, then set it back to 5 and increment the y coordinate by 1 and decrement the column counter by 1.&lt;/li&gt;&#xA;&lt;li&gt;Shift the register holding the bitmap 1 bit to the left.&lt;/li&gt;&#xA;&lt;li&gt;JMP to instruction 4.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Is there a simpler or more efficient way to do this? It seems as though even something as simple as rendering a single small text character takes quite a large number of operations and would take around 200 CPU cycles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, are there any good books or resources on machine-level code for displaying images from scratch, because I haven't been able to find any as they either gloss over this particular subject or the code is written in a high level language or an assembler using macros, all of which are &quot;cheating&quot; and don't explain what is fundamentally going on at the lowest level.&lt;/p&gt;&#xA;" OwnerUserId="1735" LastActivityDate="2015-09-30T10:08:55.720" Title="Fundamentally, how are 2D bitmaps rendered?" Tags="&lt;rendering&gt;&lt;2d&gt;&lt;bitmap-graphics&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1547" PostTypeId="2" ParentId="1546" CreationDate="2015-09-27T19:22:57.333" Score="7" Body="&lt;p&gt;You have to distinguish the text and graphical modes of the graphics board of your machine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the old days, mostly the text mode was supported. In this mode the board took care of storing the bitmap definition of the characters and displaying them at the current cursor position. All you had to do was to provide the ASCII code of the character (one byte per character) in a small text buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nowadays, a high-resolution raster buffer is provided, which is pixel accessible and to which you write color information in some supported format (in the &quot;highest&quot; mode, 3 bytes (RGB) per pixel, for a megapixel or more).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Originally, simple (packed) binary bitmaps of different sizes were used and &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Bit_blit&quot;&gt;blittted&lt;/a&gt;&quot; to the raster memory via a request to the device driver, with possible format translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nowadays, characters are mostly defined as &lt;a href=&quot;https://en.wikipedia.org/wiki/Vector_graphics&quot;&gt;vector drawings&lt;/a&gt;, which are a resolution-independent description of the outlines, and need to undergo a complex rendering process that includes &lt;a href=&quot;https://en.wikipedia.org/wiki/Spatial_anti-aliasing&quot;&gt;antialiasing&lt;/a&gt; for smooth results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rendered output can be cached for fast display, again by blitting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The overall process is complex, can be hardware accelerated, and is handled by the operating system (GUI management) in a transparent way, together with other graphical primitive drawing operations.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastEditorUserId="1703" LastEditDate="2015-09-27T20:29:01.950" LastActivityDate="2015-09-27T20:29:01.950" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1548" PostTypeId="2" ParentId="1535" CreationDate="2015-09-28T22:41:47.203" Score="3" Body="&lt;p&gt;This answer tries to give a short overview over some important aspects. Since the HSH definition is rather complex and I couldn't find an overview over some pre-evaluated functions, I didn't provide examples simply because it would take me too much time right now.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Problem Description &amp;amp; Brute Force&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;To determine the convolution any with any set of basis function and thus computing the coefficients we generally need to compute the integral over the domain (= sphere for SH, hemisphere for HSH). Everything we need to do, to represent the hemispherical function &lt;em&gt;f&lt;/em&gt;, which is defined over the angles &lt;em&gt;theta&lt;/em&gt; (&quot;up/down&quot;) and &lt;em&gt;phi&lt;/em&gt; (&quot;left/right&quot;), via a coefficient &lt;em&gt;c&lt;/em&gt; for HSH basis functions &lt;em&gt;H&lt;/em&gt; is the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gkb7K.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gkb7K.gif&quot; alt=&quot;\int_0^{2\pi}\int_0^{\frac{2}{\pi}} f(\theta,\phi) \cdot H_l^m(\theta,\phi) \cdot sin(\theta) \,\, \mathrm{d}\theta\mathrm{d}\phi&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;em&gt;sin(theta)&lt;/em&gt; is there because we integrate over the surface of a (hemi-)sphere. Conceptually, the size of a piece of area that comes from changing &lt;em&gt;phi&lt;/em&gt; is bigger or smaller on the current theta. More on this &lt;a href=&quot;http://tutorial.math.lamar.edu/Classes/CalcIII/TISphericalCoords.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we don't care too much about accuracy or computing time we can solve this simply by sampling: Generate equally distributed (!) directions on the hemisphere, compute the product of f and H and average the outcomes (if you have truly equally distributed points you don't need the &lt;em&gt;sin(theta)&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Get Started with an Analytical Solution&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Of course we would love to have an analytical solution for our function, but this is where things can get very difficult. As a first step we may need to convert a function that is given on Cartesian directions into spherical coordinates. This part is still easy, just replace all your x, y and z as following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/m0jJv.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/m0jJv.gif&quot; alt=&quot;(x,y,z) \rightarrow (\sin\theta \cos\phi, \sin\theta \sin\phi, \cos\theta)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this gives us a system where the z-axis is the &quot;up&quot; of the hemisphere (theta=0) which should be represented by the HSH. After that it may already be possible to insert everything into a computer algebra system and solve the equation. Do not try to solve for all &lt;em&gt;m&lt;/em&gt; &amp;amp; &lt;em&gt;l&lt;/em&gt; but rather try one coefficient at a time, since it is unlikely that there is a compact expression that describes all of them at once. The definition of HSH is relatively complex, which makes it very tedious to evaluate these functions. In &lt;a href=&quot;http://www.researchgate.net/publication/221121831_On_the_use_of_hemispherical_harmonics_for_modeling_images_of_objects_under_unknown_distant_illumination&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; the zero and 1st order HSH basis functions are mentioned in cartesian coordinates.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Notes on Rotations &amp;amp; Zonal Harmonics&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Functions that are rotational symmetric around this z-axis are very good candidates for a successful analytic derivation, since they only affect the &lt;em&gt;zonal&lt;/em&gt; coefficients, which are all coefficients with index &lt;em&gt;m&lt;/em&gt; equals zero. This is especially helpful for the more general Spherical Harmonics where an easy formula exists that allows to rotate any Zonal Spherical Harmonics representation to an arbitrary direction, resulting in a Spherical Harmonics representation without any data loss (see &lt;a href=&quot;http://simonstechblog.blogspot.de/2011/12/spherical-harmonic-lighting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;). This means that you can derive ZSH coefficients by assuming that your radial symmetric &quot;function points to z&quot; and rotate it then it into any desired direction. This works perfectly for example with various cosine lobe variations and also gives you the factors you mentioned in the question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the bad news: For HSH, any rotation of a function around another axis than z is lossy, since your function will &quot;touch&quot; the lower undefined hemisphere after the rotation. Therefore, there is also no convenient &quot;Hemi Zonal to HSH&quot; rotation formula. Instead, there are multiple ways to do it with different drawbacks. For more details see the &lt;a href=&quot;http://www.cs.ucf.edu/~ceh/Publications/Papers/Rendering/EGSR04GautronEtAl.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; and the &lt;a href=&quot;https://www.google.de/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=2&amp;amp;ved=0CDEQFjABahUKEwj6joP13ZrIAhVFVxQKHQliBik&amp;amp;url=http%3A%2F%2Fcgg.mff.cuni.cz%2F~jaroslav%2Fpapers%2Fegsr2004%2Fgautron-egsr2004-hemispherical.ppt&amp;amp;usg=AFQjCNG7U0b1JYorPpGQ3qTkr8C4AOqDpg&amp;amp;sig2=yHEuWgzlvroc65C7wxD2uA&amp;amp;cad=rja&quot; rel=&quot;nofollow noreferrer&quot;&gt;presentation&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;By the way: All this is easier with the &lt;a href=&quot;https://www.cg.tuwien.ac.at/research/publications/2010/Habel-2010-EIN/&quot; rel=&quot;nofollow noreferrer&quot;&gt;H-Basis&lt;/a&gt;, which is hemispherical as well (but originally only defined for a limited number of frequency-bands).&lt;/p&gt;&#xA;" OwnerUserId="528" LastActivityDate="2015-09-28T22:41:47.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1550" PostTypeId="2" ParentId="1531" CreationDate="2015-09-29T07:42:29.213" Score="2" Body="&lt;p&gt;I reckon your instructor is encouraging you to implement low-level rendering algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The obstacle to draw shapes using just points is the contradiction between continuous and discrete. Shapes are logically continuous if in its area every pixel is shaded. But you can not draw an actually continuous line using discrete points because infinite points are needed. If you draw points directly in the &quot;world&quot;, you can not guarantee every pixel on the screen can be covered after projection, unless you set the interval small enough(which may be of quite low performance).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My advice is to maintain the world coordinates of the vertices of the shape but not draw it. Get the &quot;projected&quot; coordinates on screen and fill the area later using &lt;a href=&quot;https://en.wikipedia.org/wiki/Digital_differential_analyzer_%28graphics_algorithm%29&quot; rel=&quot;nofollow&quot;&gt;DDA&lt;/a&gt; or some other interpolation algorithms. &quot;Projected&quot; is the coordinates obtained by the three matrices(Projection, View, Model), I think you've heard of these. So in the filling process GLUT is used to draw points on the 2D screen, and cover every pixel in the area.&lt;/p&gt;&#xA;" OwnerUserId="1752" LastActivityDate="2015-09-29T07:42:29.213" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1551" PostTypeId="2" ParentId="1523" CreationDate="2015-09-29T13:36:53.633" Score="32" Body="&lt;p&gt;&lt;em&gt;&quot;How (hardware) texture compression works&quot;&lt;/em&gt; is a large topic. Hopefully I can provide some insights without duplicating the content of &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1523/how-does-hardware-texture-compression-work/1545#1545&quot;&gt;Nathan's answer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Requirements&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Texture compression typically differs from 'standard' image compression techniques e.g. JPEG/PNG in four main ways, as outlined in Beers et al's &lt;a href=&quot;https://graphics.stanford.edu/projects/flashg/papers/texture_compression/&quot; rel=&quot;noreferrer&quot;&gt;Rendering from Compressed Textures&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;Decoding Speed&lt;/em&gt;: You don't want texture compression to be slower (at least not noticeably so) than using uncompressed textures. It should also be relatively simple to decompress since that can help achieve fast decompression without excessive hardware and power costs.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;Random Access&lt;/em&gt;: You can't easily predict which texels will be required during a given render. If some subset, &lt;em&gt;M&lt;/em&gt;, of the accessed texels come from, say, the middle of the image, it's essential that you don't have to decode all of the 'previous' lines of the texture in order to determine &lt;em&gt;M&lt;/em&gt;; with JPEG and PNG this is necessary as pixel decoding depends on the previously decoded data.&lt;br&gt;&#xA;Note, having said this, just because you have &quot;random&quot; access, &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/357/is-using-many-texture-maps-bad-for-caching/419#419&quot;&gt;doesn't mean you should try to sample completely arbitrarily&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;Compression Rate and Visual Quality&lt;/em&gt;: Beers et al argue (convincingly) that losing some quality in the compressed result in order to improve compression rate is a worthwhile trade-off. In 3D rendering, the data is probably going to be manipulated (e.g. filtered &amp;amp; shaded etc) and so some loss of quality may well be masked.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;Asymmetric encoding/decoding&lt;/em&gt;: Though perhaps slightly more contentious, they argue that it is acceptable to have the encoding process much slower than the decoding. Given that the decoding needs to be at HW fill rates, this is generally acceptable. (I will admit that compression of PVRTC, ETC2 and some others at maximum quality could be faster)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h2&gt;Early History &amp;amp; Techniques&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;It may surprise some to learn that texture compression has been around for over three decades. Flight simulators from the 70s and 80s needed access to &lt;em&gt;relatively&lt;/em&gt; large amounts of texture data and given that &lt;a href=&quot;http://www.jcmit.com/memoryprice.htm&quot; rel=&quot;noreferrer&quot;&gt;1MB of RAM in 1980 was &gt; $6000&lt;/a&gt;, reducing the texture footprint was essential. As another example, in the mid 70s, even a small amount of high speed memory and logic, e.g. enough for &lt;a href=&quot;https://en.wikipedia.org/wiki/Framebuffer#History&quot; rel=&quot;noreferrer&quot;&gt;a modest 512x512 RGB frame buffer&lt;/a&gt;) could set you back the price of small house.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though, AFAIK, not explicitly referred to as texture compression, in the literature and patents you can find references to techniques including:&lt;br&gt;&#xA; a. simple forms of mathematical/procedural texture synthesis,&lt;br&gt;&#xA; b. use of a single channel texture (e.g. 4bpp) that is then multiplied by a per-texture RGB value,&lt;br&gt;&#xA; c. YUV, and&lt;br&gt;&#xA; d. palettes (the literature suggesting use of &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.38.1334&quot; rel=&quot;noreferrer&quot;&gt;Heckbert's approach&lt;/a&gt; to do the compression) &lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Modelling Image Data&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;As noted above, texture compression is nearly always lossy and thus the problem becomes one of trying to represent the important data in a compact way whilst disposing of the less significant information. The various schemes that will be described below all have an implicit 'parameterised' model that approximates the typical behaviour of texture data and of the eye's response. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further, since texture compression tends to use fixed-rate encoding, the compression process usually includes a search step to find the set of parameters which, when fed in to the model, will generate a good approximation of the original texture. That search step, however, can be time consuming.&lt;br&gt;&#xA;&lt;em&gt;(With the possible exception of tools such as &lt;a href=&quot;http://optipng.sourceforge.net/&quot; rel=&quot;noreferrer&quot;&gt;optipng&lt;/a&gt;, this is another area where typical use of PNG &amp;amp; JPEG differ from texture compression schemes)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before progressing further, to help with further understanding of TC it's worth taking a look at &lt;a href=&quot;https://en.wikipedia.org/wiki/Principal_component_analysis&quot; rel=&quot;noreferrer&quot;&gt;Principal Component Analysis (PCA)&lt;/a&gt; - a very useful mathematical tool for data compression.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Example texture&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;To compare the various methods, we'll use the following image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SM000.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SM000.png&quot; alt=&quot;small lorikeet+text&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Note that this is a fairly tough image, especially for palette and VQTC methods as it spans much of the RGB colour cube and only 15% of the texels use repeated colours.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;PC and (post mid 90s) Console Texture compression&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;To reduce data costs, some PC games and early games consoles also made use of palette images, which is a form of Vector Quantisation (VQ).&#xA;Palette-based approaches make the assumption that a given image only uses relatively small portions of the RGB(A) colour cube.  A problem with palette textures is that the compression rates for the achieved quality is generally rather modest. The example texture compressed to &quot;4bpp&quot; (using GIMP) produced&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Vpv0t.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Vpv0t.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Note again that this is a relatively tough image for VQ schemes.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;VQ with larger vectors (e.g. 2bpp ARGB)&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Inspired by Beers et al, the Dreamcast console used VQ to encode 2x2  or even 2x4 pixel blocks with single bytes. While the &quot;vectors&quot; in the palette textures are 3 or 4 dimensional, the 2x2 pixel blocks can be considered to be 16 dimensional. The compression scheme assumes there is sufficient, approximate repetition of these vectors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even though VQ can achieve satisfactory quality with ~2bpp, the problem with these schemes is that it requires dependent memory reads: An initial read from the index map to determine the code for the pixel is followed by a second to actually fetch the pixel data associated with that code. Additional caches can help alleviate some of the incurred latency, but adds complexity to the hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The example image compressed with the 2bpp Dreamcast scheme is &#xA;&lt;a href=&quot;https://i.stack.imgur.com/8tnag.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8tnag.png&quot; alt=&quot;2bpp VQ result&quot;&gt;&lt;/a&gt;. &#xA;The index map is: &lt;a href=&quot;https://i.stack.imgur.com/YNJww.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YNJww.png&quot; alt=&quot;2bpp VQ index map&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compression of VQ data can be done in various ways however, &lt;em&gt;IIRC&lt;/em&gt;, the above was done using PCA to derive and then partition the 16D vectors along the principal vector into 2 sets such that two representative vectors minimised the mean squared error. The process then recursed until 256 candidate vectors were produced. &#xA;A global &lt;a href=&quot;https://en.wikipedia.org/wiki/K-means_clustering#Standard_algorithm&quot; rel=&quot;noreferrer&quot;&gt;k-means/Lloyd's algorithm&lt;/a&gt; approach was then applied to improve the representatives.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Colour Space Transformations&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Colour space transformations also make use of PCA noting that the global distribution of colour is often spread along a major axis with far less spread along the other axes. For YUV representations, the assumptions are that a) the major axis is often in the luma direction and that b) the eye is more sensitive to changes in this direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 3dfx Voodoo system provided &lt;a href=&quot;http://www.gamers.org/dEngine/xf3D/glide/glidepgm.htm&quot; rel=&quot;noreferrer&quot;&gt;&quot;YAB&quot;&lt;/a&gt;, an 8bpp, &quot;Narrow Channel&quot; compression system that split each 8 bit texel into a 322 format, and applied a user selected colour transform to that data to map it into RGB. The main axis thus had 8 levels and the smaller axes, 4 each.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The S3 Virge chip had a slightly simpler, 4bpp, scheme that allowed the user to specify, for &lt;em&gt;the entire texture&lt;/em&gt;, two end colours, which should lie on the principal axis, along with a 4bpp monochrome texture. The per-pixel value then blended the end colours with appropriate weights to produce the RGB result.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;BTC-based schemes&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Rewinding some number of years, Delp and Mitchell designed a simple (monochrome) image compression scheme called &lt;a href=&quot;http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=1094560&quot; rel=&quot;noreferrer&quot;&gt;&lt;em&gt;Block Truncation Coding&lt;/em&gt;, (BTC)&lt;/a&gt;. This paper also included a compression algorithm but, for our purposes, we are mainly interested in the resulting compressed data and of the decompression process.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this scheme, images are broken into, typically, 4x4 pixel blocks, which can be compressed independently with, in effect, a localised VQ algorithm. Each block is represented by two &quot;values&quot;, &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt;, and a 4x4 set of index bits, which identify which of the two values to use for each pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;S3TC&lt;/em&gt;:  4bpp RGB (+1bit alpha)&lt;br&gt;&#xA;Although several colour-variants of BTC for image compression were proposed, of interest to us is &lt;a href=&quot;http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&amp;amp;Sect2=HITOFF&amp;amp;d=PALL&amp;amp;p=1&amp;amp;u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&amp;amp;r=1&amp;amp;f=G&amp;amp;l=50&amp;amp;s1=5,956,431.PN.&amp;amp;OS=PN/5,956,431&amp;amp;RS=PN/5,956,431&quot; rel=&quot;noreferrer&quot;&gt;Iourcha et al's S3TC&lt;/a&gt;, some of which appears to be a rediscovery of the somewhat forgotten work of &lt;a href=&quot;http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&amp;amp;Sect2=HITOFF&amp;amp;d=PALL&amp;amp;p=1&amp;amp;u=%2Fnetahtml%2FPTO%2Fsrchnum.htm&amp;amp;r=1&amp;amp;f=G&amp;amp;l=50&amp;amp;s1=5046119.PN.&amp;amp;OS=PN/5046119&amp;amp;RS=PN/5046119&quot; rel=&quot;noreferrer&quot;&gt;Hoffert et al&lt;/a&gt; that was used in Apple's Quicktime.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The original S3TC, without the DirectX variants, compresses blocks of either RGB or RGB+1bit Alpha to 4bpp. Each 4x4 block in the texture is replaced by two end colours, &lt;em&gt;A&lt;/em&gt; and &lt;em&gt;B&lt;/em&gt;, from which up to two other colours are derived by fixed-weight, linear blends. Further, each texel in the block has a 2-bit index that determines how to select one of these four colours. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example the following is a 4x4 pixel section of the test image compressed with the AMD/ATI Compressenator tool. (&lt;em&gt;Technically it's taken from a 512x512 version of the test image but forgive my lack of time to update the examples&lt;/em&gt;).&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YCI3n.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YCI3n.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;This illustrates the compression process: The average and the principal axis of the colours are calculated.  A best fit is then performed to find two end points that 'lie on' the axis which, along with the two derived 1:2 and 2:1 blends (or in some cases a 50:50 blend) of those end points, that minimises the error.  Each original pixel is then mapped to one of those colours to produce the result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If, as in this case, the colours are reasonable approximated by the principal axis, the error will be relatively low. However if, like in the neighbouring 4x4 block shown below, the colours are more diverse, the error will be higher.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/d5dZ8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d5dZ8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The example image, compressed with the &lt;a href=&quot;http://developer.amd.com/tools-and-sdks/archive/legacy-cpu-gpu-tools/the-compressonator/&quot; rel=&quot;noreferrer&quot;&gt;AMD Compressonator&lt;/a&gt; produces:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZFrSa.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZFrSa.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the colours are determined independently per-block, there can be discontinuities at block boundaries but, as long as the resolution is kept sufficiently high, these block artefacts may go unnoticed:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Fa779.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Fa779.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;ETC1&lt;/em&gt;:  4bpp RGB&lt;br&gt;&#xA;Ericsson Texture Compression also works with 4x4 blocks of texels but makes the assumption that, much like YUV, the principal axis of a local set of texels is often very strongly correlated with &quot;luma&quot;. The set of texels can then be represented by just an average colour and a highly quantised, scalar 'length' of the projection of the texels onto that assumed axis.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since this reduces the data storage costs relative to say, S3TC, it allows ETC to introduce a partitioning scheme, whereby the 4x4 block is subdivided into a pair of horizontal 4x2 or vertical 2x4 sub-blocks. These each have their own average colour. &#xA;The example image produces:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cYOmr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cYOmr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;The area around the beak also illustrates the horizontal and vertical partitioning of the 4x4 blocks.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Uwd5F.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Uwd5F.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;    &lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Global+Local&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;There are some texture compression systems that are a cross between global and local schemes, such as that of the distributed palettes of &lt;a href=&quot;http://onlinelibrary.wiley.com/doi/10.1111/1467-8659.00420/abstract&quot; rel=&quot;noreferrer&quot;&gt;Ivanov and Kuzmin&lt;/a&gt; or the method of &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.61.7956&quot; rel=&quot;noreferrer&quot;&gt;PVRTC&lt;/a&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;PVRTC&lt;/em&gt;:  4 &amp;amp; 2 bpp RGBA&lt;br&gt;&#xA;PVRTC assumes that an (in practice, bilinearly) upscaled image is a good approximation to the full-resolution target and that the difference between the approximation and the target, i.e. the delta image, is locally monochromatic, i.e. has a dominant principal axis. Further, it assumes the local principal axis can be interpolated across the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(to do: Add images showing breakdown)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The example texture, compressed with PVRTC1 4bpp produces:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5jKnQ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5jKnQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;with the area around the beak:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ODTd4.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ODTd4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Compared to BTC-schemes, the block artefacts typically are eliminated but there can sometimes be &quot;overshoot&quot; if there are strong discontinuities in the source image, for example around the silhouette of the lorikeet's head.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 2bpp variant has, naturally, higher error than the 4bpp (note loss of precision around the blue, high frequency areas near the neck) but arguably still of reasonably quality:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ASiRE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ASiRE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;A note on decompression costs&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Although the compression algorithms for the schemes described above have a moderate to high evaluation cost, the decompression algorithms, especially for hardware implementations, are relatively inexpensive. ETC1, for example, requires little more than a few MUXes and low-precision adders; S3TC effectively slightly more addition units to perform the blending; and PVRTC, slightly more again.  In theory, these simple TC schemes could allow a GPU architecture to avoid decompression until just prior to the filtering stage, thus maximising the effectiveness of internal caches.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Other Schemes&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Other common TC modes that should be mentioned are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;ETC2 - is a (4bpp) superset of ETC1 that improves the handling of regions with colour distributions that don't align well with 'luma'. There are also a 4bpp variant that supports 1 bit alpha, and an 8bpp format for RGBA.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;ATC - Is effectively a small &lt;a href=&quot;http://www.guildsoftware.com/papers/2012.Converting.DXTC.to.ATC.pdf&quot; rel=&quot;noreferrer&quot;&gt;variation on S3TC&lt;/a&gt;.  &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;FXT1 (3dfx) was a more ambitious &lt;a href=&quot;https://www.opengl.org/registry/specs/3DFX/texture_compression_FXT1.txt&quot; rel=&quot;noreferrer&quot;&gt;variant of the S3TC theme&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;BC6 &amp;amp; BC7 : An 8bpp, block-based system supporting ARGB. Apart from HDR modes, these use a more complex partitioning system than that of ETC to attempt to better model image colour distribution.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;PVRTC2 : 2&amp;amp;4bpp ARGB. This introduces additional modes including one to overcome limitations with strong boundaries in the images.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;ASTC : This is also a block based system but is somewhat more complicated in that it has a large number of possible block sizes targeting a wide range of bpp. It also includes features such as up to 4 partition regions with a pseudo-random partition generator, and variable resolution for the index data and/or colour precision and colour models.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-04-23T07:55:03.983" LastActivityDate="2018-04-23T07:55:03.983" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1552" PostTypeId="1" AcceptedAnswerId="1553" CreationDate="2015-09-30T05:40:15.270" Score="1" ViewCount="789" Body="&lt;p&gt;&lt;em&gt;[I got a warning that the question will be closed].&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have identified that CG is the place where all the advanced algorithms and computations are taking place. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the best way to start from rudimentary and progress gradually in CG programming?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please express language choices (C, C++, etc.) and other topics you find relevant. I also found out  Michael Abrash's book.&lt;/p&gt;&#xA;" OwnerUserId="1695" LastActivityDate="2015-09-30T07:17:01.497" Title="What are the best ways to start graphics programming?" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ClosedDate="2015-09-30T20:21:58.790" ContentLicense="CC BY-SA 3.0" />
  <row Id="1553" PostTypeId="2" ParentId="1552" CreationDate="2015-09-30T07:17:01.497" Score="1" Body="&lt;p&gt;There are many possible answers depending on your OS, goals and wanted level of abstraction. For low-level programming you can start by learning OpenGL, Metal or Direct3D. Most used shader languages are HLSL based. For higher level there are things like ShaderToy and engines like Unity (C#) or Unreal (C++) where you can experiment with graphics coding.&lt;/p&gt;&#xA;" OwnerUserId="67" LastActivityDate="2015-09-30T07:17:01.497" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1554" PostTypeId="2" ParentId="1546" CreationDate="2015-09-30T09:46:04.110" Score="1" Body="&lt;p&gt;The short answer is YES, you can not avoid doing a lot of bit manipulation if your format needs it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Drawing a bitmap basically mean copy a pixel from a source to a destination and you have to do what it takes to do it. (Quoting Captain Obvious)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A longer answer is that if you write a software rasterizer, you can have some algorithm and trick to save you cpu time (by knowing which part you DO NOT NEED TO DRAW (transparency optimization), by having a pixel format of the source the same as the destination (directly or in a form of cache), optimally perform memcopy, etc... Basically consider the drawing loop of your rasterizer and see how you can restructure them to save CPU time. (ex : you could generate at runtime a piece of assembler code just specifically to print the letter A or have meta to your source bitmap info to tell you how to skip transparent area, etc..)&#xA;Each use case may have a different solution based on CPU instruction set, buffer format, the algorithm of your rendering primitive (rotating ? stretching bitmaps ? what kind of filtering ? etc...), CPU register and cache etc...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So yes anyway, it TOOK a lot of CPU cycle to write single pixel in the old days when weird encoding &amp;amp; small memory were the norm. :-)&#xA;But it didn't forbid 16 / 32 bit machines with 8 MHZ CPU to do things like that : &lt;a href=&quot;https://www.youtube.com/watch?v=GWwPJU6pp30&quot; rel=&quot;nofollow&quot;&gt;https://www.youtube.com/watch?v=GWwPJU6pp30&lt;/a&gt; (And a big chunk of the CPU was used also for the music)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of HW rendering, HW will perform the conversion from the source format to destination format and while it will not use much of the tricks available to SW rasterizer, its generic implementation in HW will most likely beat most of the SW implementation.&lt;/p&gt;&#xA;" OwnerUserId="105" LastEditorUserId="105" LastEditDate="2015-09-30T10:08:55.720" LastActivityDate="2015-09-30T10:08:55.720" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1555" PostTypeId="1" CreationDate="2015-09-30T10:57:29.540" Score="4" ViewCount="285" Body="&lt;p&gt;Asking it here and not on SO as it seems to be appropriate question for CG.&#xA;I am learning &lt;a href=&quot;https://developer.nvidia.com/nvidia-video-codec-sdk&quot; rel=&quot;nofollow&quot;&gt;NVIDIA NVENC&lt;/a&gt; API.The SDK supplies a sampled called &quot;NvEncoderCudaInterop&quot; .There is a chunk of code which copies YUV plane arrays from CPU to GPU buffers.&#xA;This is the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; // copy luma&#xA; CUDA_MEMCPY2D copyParam;&#xA;memset(&amp;amp;copyParam, 0, sizeof(copyParam));&#xA;copyParam.dstMemoryType = CU_MEMORYTYPE_DEVICE;&#xA;copyParam.dstDevice = pEncodeBuffer-&amp;gt;stInputBfr.pNV12devPtr;&#xA;copyParam.dstPitch = pEncodeBuffer-&amp;gt;stInputBfr.uNV12Stride;&#xA;copyParam.srcMemoryType = CU_MEMORYTYPE_HOST;&#xA;copyParam.srcHost = yuv[0];&#xA;copyParam.srcPitch = width;&#xA;copyParam.WidthInBytes = width;&#xA;copyParam.Height = height;&#xA;__cu(cuMemcpy2D(&amp;amp;copyParam));&#xA;&#xA;// copy chroma&#xA;&#xA;__cu(cuMemcpyHtoD(m_ChromaDevPtr[0], yuv[1], width*height / 4));&#xA;__cu(cuMemcpyHtoD(m_ChromaDevPtr[1], yuv[2], width*height / 4));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I do understand the rationale behind the procedure.The memory is copied to GPU  for the kernel to process it.What I don't understand is why,in order to copy Y plane, cuMemcpy2D is used and for UV &lt;a href=&quot;http://developer.download.nvidia.com/compute/cuda/4_1/rel/toolkit/docs/online/group__CUDA__MEM_g4d32266788c440b0220b1a9ba5795169.html&quot; rel=&quot;nofollow&quot;&gt;cuMemcpyHtoD&lt;/a&gt;?Why Y can't be copied using cuMemcpyHtoD as well?As far as I understand,YUV planes have the same linear memory layout.The only difference is their size.&lt;/p&gt;&#xA;" OwnerUserId="213" LastEditorUserId="385" LastEditDate="2015-09-30T14:26:47.203" LastActivityDate="2015-09-30T14:26:47.203" Title="CUDA cuMemcpuHtoD vs cuMemcpy2D" Tags="&lt;gpu&gt;&lt;gpgpu&gt;&lt;cuda&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1556" PostTypeId="1" AcceptedAnswerId="1560" CreationDate="2015-09-30T11:27:36.453" Score="14" ViewCount="784" Body="&lt;p&gt;I've been trying to understand some of the &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1513/how-physically-based-is-the-diffuse-and-specular-distinction&quot;&gt;physical principles&lt;/a&gt; behind light and material interaction lately. In his talk &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physics and Math of Shading&lt;/a&gt;, Naty Hoffman explains Fresnel reflectance and defines the characteristic specular color &lt;strong&gt;F&lt;sub&gt;0&lt;/sub&gt;&lt;/strong&gt; of a material as the Fresnel reflectance at 0° incident light angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On slide 65, &lt;strong&gt;F&lt;sub&gt;0&lt;/sub&gt;&lt;/strong&gt; of gold is given as &lt;em&gt;1.022, 0.782, 0.344&lt;/em&gt; (linear). Hoffman adds: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;its red channel value is greater than 1 (it’s outside sRGB gamut)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;All of this doesn't make too much sense to me. A value greater than 1 would mean that in the wavelengths contributing to the red channel, &lt;em&gt;more energy is reflected than is received&lt;/em&gt;. Does this really happen, and if so, how and why?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In addition, here is a reflectance curve from &lt;a href=&quot;https://en.wikipedia.org/wiki/Reflectance&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt; for some materials including gold (Au). The curve is certainly high for red wavelengths around 600nm but does not seem to go over 100%.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P2Vwr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P2Vwr.png&quot; alt=&quot;Reflectance (Au)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-10-07T07:53:43.003" Title="Fresnel reflectance of gold: red channel greater than 1?" Tags="&lt;physics&gt;&lt;brdf&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1557" PostTypeId="1" CreationDate="2015-09-30T13:21:43.827" Score="12" ViewCount="221" Body="&lt;p&gt;&lt;strong&gt;Photorealistic rendering&lt;/strong&gt; has the goal of rendering an image as a &lt;em&gt;real camera&lt;/em&gt; would capture it. While this is already an ambitious goal, for certain scenarios you might want to take it further: render an image as the &lt;em&gt;human eye&lt;/em&gt; would capture it or even as the &lt;em&gt;human being&lt;/em&gt; would perceive it. You could call it &lt;em&gt;visiorealistic&lt;/em&gt; or &lt;em&gt;perceptiorealistic rendering&lt;/em&gt;, but if anyone could come up with a catchier term (or tell me that there is one already in existence) I'd appreciate that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some examples to make my point clear. When you take a picture with a camera at a low illumination level, you either have a good lens or get a noisy image. For a human observer, &lt;a href=&quot;https://en.wikipedia.org/wiki/Scotopic_vision&quot; rel=&quot;noreferrer&quot;&gt;scotopic vision&lt;/a&gt; kicks in and gives rise to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Purkinje_effect&quot; rel=&quot;noreferrer&quot;&gt;Purkinje effect&lt;/a&gt; (colors are shifted towards blue). This effect depends on the HDR luminance information, which are lost when I display the image on a LDR display. In addition, the human brain may use depth information to 'filter' the perceived image - information which are lost in a final (non-stereo) rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assembling an exhaustive list is probably an elusive goal. Could you suggest some of the effects of the eye and the brain that I would need to consider?&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2015-10-01T08:34:38.210" LastActivityDate="2015-10-16T08:20:53.373" Title="Realistic rendering: which processes of the human eye and brain do I need to consider?" Tags="&lt;human-vision&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1560" PostTypeId="2" ParentId="1556" CreationDate="2015-10-01T05:34:20.937" Score="10" Body="&lt;p&gt;RGB color is a bit more complicated a subject than readily seems apparent. The reflectance wavelength diagram shows the reason quite well actually.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;RGB color model has several central problems:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What the colors represent: They represent 3 spikes in a continuous spectrum. The R, G and B aren't energetically equivalent let alone evenly spaced.&lt;/li&gt;&#xA;&lt;li&gt;What their range is: The colors do not actually mean anything without information of what space they span. In the assumed sRGB color space the space does not span the entire sensable range. So energetically equal but more vivid colors exist.&lt;/li&gt;&#xA;&lt;li&gt;Human sensory apparatus isn't actually reading 3 color spikes but the sensors nonlinearly overlap.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;As a result one can not draw the conclusion that a reflectance color channel of greater than 1 automatically means that energy is inserted into the system. That is simply one of the possible interpretations. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another interpretation is that the color is more intense than your color space allows. As a result your color vector component could be over 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Human eyes may also bleed color from one sensor to another due to overlap of the sensors. Such things happen with the sky which seems light blue, but is actually far darker blue but so intense that we see it as light blue. But in 50% reflections it would look wrong if we wouldn't account for this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, it can also mean energy is inserted into the system. Either the energy comes from elsewhere or is generated by the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rendering is often not a scientific measure of things. No energy principle needs to be broken to achieve this.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Summa summarum (tl;dr)&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Color is often a compound attribute at the same time as it measures energy levels it also measures something other. Namely the location in the color space. Thus you can not differentiate the two signals (energy and color intensity) easily.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case it is a more intense color because the source says so: Outside of sRGB gamut = more intense color than the color space can make.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2015-10-07T07:53:43.003" LastActivityDate="2015-10-07T07:53:43.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1561" PostTypeId="2" ParentId="1556" CreationDate="2015-10-01T05:35:46.373" Score="10" Body="&lt;p&gt;Here's a chromaticity diagram that includes a projection of the sRGB color space: a triangle whose vertices are red (1,0,0), green (0,1,0), and blue (0,0,1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eYuuN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eYuuN.png&quot; alt=&quot;CIE chart with sRGB gamut from Wikipedia&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Encoding the reflectance of a surface as the color at &lt;strong&gt;F&lt;sub&gt;0&lt;/sub&gt;&lt;/strong&gt; and getting a value that is outside of the (somewhat arbitrary chosen) sRGB gamut is totally reasonable. It just means that gold is &quot;more red&quot; than sRGB can represent, because it reserves valuable area of its dynamic range for other colors.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-10-01T05:35:46.373" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1562" PostTypeId="1" AcceptedAnswerId="1563" CreationDate="2015-10-02T00:14:52.133" Score="14" ViewCount="9914" Body="&lt;p&gt;I have a class that generates a 3D shape based on inputs from the calling code. The inputs are things like length, depth, arc, etc. My code generates the geometry perfectly, however I am running into trouble when calculating the surface normals. When lit, my shape has very bizarre coloring/texture from the incorrect surface normals that are being calculated. From all my research I believe my math is correct, it seems that something is wrong with my technique or method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At a high level how does one go about programmatically calculating the surface normals for a generated shape? I am using Swift/SceneKit on iOS for my code but a generic answer is fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have two arrays that represent my shape. One is an array of 3D points that represents the vertices that make up the shape. The other array is a list of indexes of the first array that map the vertices into triangles. I need to take that data and generate a 3rd array that is a set of surface normals that aid in the lighting of the shape. (see &lt;a href=&quot;https://developer.apple.com/library/prerelease/ios/documentation/SceneKit/Reference/SceneKit_Constants/index.html#//apple_ref/c/data/SCNGeometrySourceSemanticNormal&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;SCNGeometrySourceSemanticNormal&lt;/code&gt; in SceneKit`&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The list of vertices and indexes is always different depending on the inputs to the class so I cannot pre-calculate or hard code the surface normals.&lt;/p&gt;&#xA;" OwnerUserId="1774" LastEditorUserId="182" LastEditDate="2017-07-13T10:27:55.247" LastActivityDate="2021-01-29T15:15:15.120" Title="How to Calculate Surface Normals for Generated Geometry" Tags="&lt;lighting&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="2" CommentCount="7" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1563" PostTypeId="2" ParentId="1562" CreationDate="2015-10-02T06:01:39.200" Score="11" Body="&lt;p&gt;You simply dont want fully smooth results. While the commented method by Nathan Reed: &quot;Calculate each vertex to face normal, sum them, normalize sum&quot;, generally works it sometimes fails spectacularly. But that is of no importance here, we can use that method by adding a rejection clause to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case you simply want certain parts not to be smoothed against certain other parts. You want selective hard edges. So for example the flat top and bottom is separate form the triangle strip on the side, as is each flat area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JLntk.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JLntk.png&quot; alt=&quot;Image we are after&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: The result you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In effect you only want to average the vertices of the curved area all others can use the normal they get form their triangle alone. So you are better of thinking of the mesh as 9 separate regions that are handled without the others.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ityq6.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ityq6.png&quot; alt=&quot;Showing mesh and normals]&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Image showing the mesh structure and the normals. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can certainly automatically deduce this by not including normals that are outside certain angle from the primary vertexes normal. Pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;For vertex in faceVertex:&#xA;    normal = vertex.normal&#xA;    For adjVertex in adjacentVertices:&#xA;        if anglebetween(vertex.normal, adjVertex.normal )  &amp;lt; treshold:&#xA;            normal += adjVertex.normal&#xA;    normal = normalize(normal)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That works, but you can simply avoid all of this at creation time because you understand that separate planes are working differently. So only the curved sides need normal direction merging. And in fact you can just directly calulate them from the underlying mathematical shape.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-10-02T08:59:22.163" LastActivityDate="2015-10-02T08:59:22.163" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1564" PostTypeId="1" AcceptedAnswerId="1565" CreationDate="2015-10-02T08:10:48.497" Score="5" ViewCount="65" Body="&lt;p&gt;I have a shader which has several uniform variables:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform vec4 a;&#xA;uniform vec4 b;&#xA;uniform vec4 c;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm getting these handles using &lt;code&gt;glGetUniformLocation()&lt;/code&gt; and storing them in the array. The game was suspended, then resumed and &lt;a href=&quot;http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html&quot; rel=&quot;noreferrer&quot;&gt;onSurfaceCreated()&lt;/a&gt; has been called. The question is: whether these handles will be valid or I need to re-get them using &lt;code&gt;glGetUniformLocation()&lt;/code&gt; once again?&lt;/p&gt;&#xA;" OwnerUserId="333" LastEditorUserId="231" LastEditDate="2015-10-07T07:15:14.157" LastActivityDate="2015-10-07T07:15:14.157" Title="Can the uniform id be changed from run to run on the same machine?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;android&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1565" PostTypeId="2" ParentId="1564" CreationDate="2015-10-02T08:53:07.807" Score="6" Body="&lt;p&gt;The uniform locations are set when the program is linked and are tied to the program.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that when you create a new program then the uniform locations can change. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-10-02T08:53:07.807" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1566" PostTypeId="1" AcceptedAnswerId="1567" CreationDate="2015-10-02T09:36:58.310" Score="8" ViewCount="200" Body="&lt;p&gt;I'm in the process of making a tool that requires rendered texture to follow the contours of a piece of clothing. An example would be this website &lt;a href=&quot;https://knyttan.com/editor/jumper-editor/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://knyttan.com/editor/jumper-editor/&lt;/a&gt;. The effect here is achieved by using a colour map:&lt;a href=&quot;https://i.stack.imgur.com/pcCgx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pcCgx.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I looked at the shaders that are used for this and it seems that the texture offset is calculated based on the colour channels from this map. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I was wondering if this is a complete bespoke way of doing this, or if this is a known technique and if it is what is it called ?&lt;/p&gt;&#xA;" OwnerUserId="1778" LastEditorUserId="231" LastEditDate="2015-10-07T07:13:04.297" LastActivityDate="2015-10-07T07:13:04.297" Title="Help me find out what this texture mapping technique is called" Tags="&lt;texture&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1567" PostTypeId="2" ParentId="1566" CreationDate="2015-10-02T11:00:20.730" Score="8" Body="&lt;p&gt;What you see in the image called a &lt;a href=&quot;https://en.wikipedia.org/wiki/UV_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;UV map&lt;/a&gt;. That is, it is simply texture coordinates to be looked up encoded in a image. Same thing happens in all texture lookup in 3D there is a underlying sampler that picks where to pick texture color from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BhNr6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BhNr6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Image showing UV map of two overlapped triangles and sampled texture with same UV coords&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are the sources for those images, please do not overwrite the sources.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://webglplayground.net/saved/CZTXXQeZFH&quot; rel=&quot;nofollow noreferrer&quot;&gt;Demo&lt;/a&gt; showing the UV map&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://webglplayground.net/saved/tTnh7zvUc6&quot; rel=&quot;nofollow noreferrer&quot;&gt;Demo&lt;/a&gt; showing the texture&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-10-02T11:39:23.227" LastActivityDate="2015-10-02T11:39:23.227" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1568" PostTypeId="1" AcceptedAnswerId="1569" CreationDate="2015-10-03T15:44:17.840" Score="7" ViewCount="3185" Body="&lt;p&gt;I am wondering if the various PBR models used in modern game engines for real time are heavier in terms of computation, that more classic approaches to rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Worded differently, is PBR just a different way to organize one's rendering pipeline, or does it add serious complexity (especially in regards to lighting) ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on the answer, what would be the bottleneck for a low-resource implementation ?&lt;/p&gt;&#xA;" OwnerUserId="34" LastActivityDate="2015-10-05T20:55:39.827" Title="Does PBR incur a performance penalty by design?" Tags="&lt;rendering&gt;&lt;real-time&gt;&lt;lighting&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1569" PostTypeId="2" ParentId="1568" CreationDate="2015-10-03T18:06:30.183" Score="8" Body="&lt;p&gt;As mentioned in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1468/310&quot;&gt;this&lt;/a&gt; answer, Physically-Based Rendering isn't a set number of things. It's a &lt;em&gt;concept&lt;/em&gt;. It's akin to saying something is 'Environmentally Friendly'. There are many different techniques to be environmentally friendly &lt;em&gt;and&lt;/em&gt; someone can implement those techniques to varying degrees. The same is for PBR.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, Physically Based Rendering is just that, based on Physics in some way, shape, or form. One of the most basic 'physical' rendering techniques I can think of is using &lt;a href=&quot;https://en.wikipedia.org/wiki/Lambertian_reflectance&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lambert shading&lt;/a&gt;. While you may say, &quot;Well that doesn't take into account specular light, or etc, etc. etc.&quot;, I agree. Lambert shading is a crude representation of the physics of light. But, pedantically, it &lt;em&gt;is&lt;/em&gt; PBR, because it is based off the physical observation that light intensity decreases with viewing angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A renderer can implement as many, or as few PBR techniques as they choose. Some can be very computationally expensive, others, quite cheap. They can also choose to enable or disable certain techniques for different targets. For example, UE4 has a different set of techniques for mobile games, than for high end PC games. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, that all said, when today's modern renderers talk about being &quot;Physically-based&quot;, they are generally referring to using a modern BRDF, generally some form of &lt;a href=&quot;http://ruh.li/GraphicsCookTorrance.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cook-Torrance&lt;/a&gt;, and physically plausible inputs. Inputs being: materials with physically-plausible color values and lights with physically based intensity values. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using a modern BRDF can be very computationally expensive, but, there are many approximations that can make it more friendly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using physically-plausible inputs is generally not that difficult to implement on the renderer side, rather it's more difficult for artists. IE. teaching them what the different material values mean, and what are physically plausible values. This can be a huge task, depending on your artists, as seen in the presentations &lt;a href=&quot;http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, and &lt;a href=&quot;http://www.slideshare.net/guerrillagames/lighting-of-killzone-shadow-fall&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, for example. In my opinion, this is the hardest task in switching a studio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One last issue, as brought up by @NathanReed in the comments:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Implementing a modern BRDF in the shader doesn't necessarily immediately make the rendering better. In many cases, it can make other parts of the pipeline a glaring issue. Below are some additional things that are important in getting the most out of a modern BRDF:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;HDR lights and doing all rendering calculations in HDR&lt;/li&gt;&#xA;&lt;li&gt;Gamma correct rendering&lt;/li&gt;&#xA;&lt;li&gt;Indirect lighting of some kind (skybox lighting, static environment probes, screen space reflections, etc)&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;This is huge for metals. &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metals have no diffuse reflectance&lt;/a&gt;, so most of the surface of the metal will be black if you don't have indirect reflections&lt;/li&gt;&#xA;&lt;li&gt;This is also one of the more difficult things to get real-time, especially for dynamic scenes. &lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="310" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-10-05T20:55:39.827" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1571" PostTypeId="2" ParentId="1557" CreationDate="2015-10-05T05:25:54.713" Score="6" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;you might want to take it further: render an image as the human eye would capture it or even as the human being would perceive it.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There are two ways to interpret this.  I'll do both.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Interpretation 1: Render an image that looks perceptually realistic.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the end of the day, your image still needs to be &lt;em&gt;displayed&lt;/em&gt; somewhere.  Here's the key: you want to &lt;em&gt;render your image in such a way that when you *display* that image on a particular display device, it will produce the same sensation the original radiometric image would have produced.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's how to unpack that idea.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the real world, radiometric spectra (i.e., real distributions of light) enter your eye and stimulate approximately&lt;sup&gt;1&lt;/sup&gt; four light receptors.  The stimulations of the receptors produce the sensations of color we associate with images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In rendering, we don't have arbitrary control over the spectra we produce.  Fortunately, since we (usually) have only three cones, each of which produces only a scalar value, color vision can be reproduced by using exactly three primaries.  The bottom line is you can &lt;em&gt;produce any color sensation by using a linear combination of three wavelengths only&lt;/em&gt; (up to a few colors that might have to be negative, in which case, you just use different primaries).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You don't have a choice of primaries.  Almost all color display devices use the sRGB standard, which provides three primaries (which actually usually don't have a single wavelength).  That's fine because it turns out it's all abstracted and you don't have to care.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify the mess that is perceptually accurate rendering, here's the algorithm:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render your image using correct radiometric calculations.  You trace individual wavelengths of light or buckets of wavelengths.  Whatever.  In the end, you have an image that has a representation of the spectrum received at every point.&lt;/li&gt;&#xA;&lt;li&gt;At each pixel, you take the spectrum you rendered, and convert it to the &lt;a href=&quot;https://en.wikipedia.org/wiki/CIE_1931_color_space&quot;&gt;CIE XYZ color space&lt;/a&gt;.  This works out to be integrating the product of the spectrum with the &lt;a href=&quot;https://en.wikipedia.org/wiki/CIE_1931_color_space#Color_matching_functions&quot;&gt;standard observer functions (see CIE XYZ definition)&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;This produces three scalar values, which are the CIE XYZ colors.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29&quot;&gt;Use a matrix transform to convert this to linear RGB, and then from there use a linear/power transform to convert linear RGB to sRGB&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Convert from floating point to uint8 and save, clamping values out of range (your monitor can't represent them).&lt;/li&gt;&#xA;&lt;li&gt;Send the uint8 pixels to the framebuffer.&lt;/li&gt;&#xA;&lt;li&gt;The display takes the sRGB colors, does the inverse transform to produce three primaries of particular intensities.  Each scales the output of whatever picture element it is responsible for.  The picture elements light up, producing a spectrum.  This spectrum will be (hopefully) a &lt;a href=&quot;https://en.wikipedia.org/wiki/Metamerism_%28color%29&quot;&gt;metamer&lt;/a&gt; for the original spectrum you rendered.&lt;/li&gt;&#xA;&lt;li&gt;You perceive the spectrum as you would have perceived the rendered spectrum.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Interpretation 2: Attempt to simulate the end data the human eye might receive for visualization purposes or compensation for LDR displays.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This one has a less useful meaning, I think.  Essentially, you're trying to produce an image that tweaks the way the brain perceives it for fun/profit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, there was a &lt;a href=&quot;http://graphics.stanford.edu/papers/gazehdr/&quot;&gt;paper at SIGGRAPH this year&lt;/a&gt; where they simulated afterimages and color reduction to make images appear perceptually different.  Of course, the only reason they do this at all is because the displays we're working with are all low-dynamic range (LDR).  The point is to simulate the effects someone might see if exposed to a real high-dynamic range (HDR) display as actual image data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice, this turns out to not work very well.  For afterimages, for example, we see afterimages because of a very bright stimulus exhausting color cells.  If you instead try to stimulate the effect with a fake afterimage, it might look kindof similar--but since it's a completely different mechanism, it's not very convincing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This sort of graphics is actually underexplored in the literature if you want to make a go at it.  The mentioned paper is an example of more-or-less the most state-of-the-art approaches we have.  I think the current consensus, though, is that it is not really worth trying to simulate (at least at this time), since at best you'd only be approximating real vision effects by substituting different ones, and that this doesn't really work.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;Rod+3*cones, the usual case.  Approximate because humans may have as few as zero functional light receptors up to a conjectured maximum of seven (with the highest ever observed being five).&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-10-05T05:25:54.713" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1572" PostTypeId="1" AcceptedAnswerId="1573" CreationDate="2015-10-05T09:16:15.527" Score="10" ViewCount="1673" Body="&lt;p&gt;Display lists were an OpenGL feature that could, in theory, accelerate any part of the API by storing a group of commands for later use. In my understanding, this makes a lot of sense with regards to the current effort to reduce the driver overhead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Display lists were deprecated in version 3.1 though. What is the modern API equivalent and does DirectX expose a similar feature? If there is no such functionality anymore, what is the rationale?&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-11-07T09:59:51.000" Title="What is the modern equivalent of display lists?" Tags="&lt;opengl&gt;&lt;display-lists&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1573" PostTypeId="2" ParentId="1572" CreationDate="2015-10-05T09:30:15.083" Score="13" Body="&lt;p&gt;Nvidia has an &lt;a href=&quot;http://developer.download.nvidia.com/opengl/specs/GL_NV_command_list.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;extension for creating command buffers in modern GL&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason for the lack of similar functionality is that there is a lot of state involved regarding how to render and the display list be affected by a lot of different state. For example changing the blend state requires patching the fragment shader on some hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NVidia solved it by capturing &lt;em&gt;all&lt;/em&gt; state and reseting to the state after a dispatch:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;1) What motivates the design?&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;The primary goal is to be able to reuse pre-validated command buffers.&#xA;  Other APIs and proposals have addressed this with various incarnations&#xA;  of command  lists or state objects, but a recurring problem is that&#xA;  interactions between various stages of the pipeline prevent this&#xA;  prevalidation and reuse. These  interactions are often&#xA;  hardware-specific (and differ from vendor to vendor  or even&#xA;  generation to generation) and new interactions are introduced by  new&#xA;  features that were not imagined when the prevalidation scheme was &#xA;  proposed.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;We attempt to address this by having a monolithic state object that &#xA;  encompasses (almost) the entire state of the pipeline. This should&#xA;  provide enough information for all implementations to do any needed&#xA;  cross- validation. We try to create these in a way that minimizes the&#xA;  new API  footprint - since we want ALL state (including any added in&#xA;  the future), we just capture it from the current state of the context.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;[...]&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;23) In what condition is the state left, that is modified by tokens,&#xA;  after the dispatch call?&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;RESOLVED: state is reset.  &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;(from the extension text linked above)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However the true successor is the command buffer functionality in DX12 and vulkan. Those will also capture all render state into a single object to use when creating and filling the command buffer. The NVidia extension is based on that architecture as a result of NVidia's involvement in the Vulkan design.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2016-11-07T09:59:51.000" LastActivityDate="2016-11-07T09:59:51.000" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1574" PostTypeId="1" CreationDate="2015-10-05T14:41:15.337" Score="1" ViewCount="185" Body="&lt;p&gt;I'd like to know (if it is possible), how I would go about getting at the rendered frames from an application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, say I am using some 3D modelling tool (eg Blender, 3DS Max, Maya) and I have my model (eg a coffee mug that rotates constantly). Animation rendering has completed remotely (perhaps on AWS EC2) and so this coffee mug is rotating... &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I were to log into the remote server using some remote desktop application, I'd see the cup rotating, however, I'd like to rather grab the output from that application (the frames) and stream it to my laptop (or another client).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know of NVidia's AppStream, but I'd like to know how to get at that rendered frames on the remote server and pipe them to a client, without using some remote desktop software.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I realise my question may seem vague (possibly even not making sense), but I'm very new to this and so any help or pointers would be great.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="1800" LastEditorUserId="48" LastEditDate="2015-10-05T18:35:52.187" LastActivityDate="2015-10-05T18:35:52.187" Title="How to capture rendered frames from an application and stream over network" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1575" PostTypeId="2" ParentId="1574" CreationDate="2015-10-05T17:05:33.907" Score="1" Body="&lt;p&gt;I think you're confused on how rendering and animation work. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A traditional model is nothing more than a bunch of triangles. So a model file coming from say Blender, etc. is just a list of vertices for the triangles. (with some added stuff if you want)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rendering takes the scene definition and transforms a 3D scene (aka the models oriented somewhere in space) and creates a 2D picture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Animation creates the illusion of movement by showing static pictures very fast (24 frames per second or more). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, to have a spinning mug, your application would render each frame, then present them, at, say 30 fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, to stream the data, you can take two paths:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render each frame on the server and stream them to the client with something like H.264&lt;/li&gt;&#xA;&lt;li&gt;Stream the graphics commands to the client, and let them render them.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The first option is what something like OBS or Fraps and (maybe) Nvidia GameStream is doing. &#xA;There's a paper that covers the 2nd option &lt;a href=&quot;https://www.informatik.hu-berlin.de/de/forschung/gebiete/viscom/papers/icip08a.pdf&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2015-10-05T17:05:33.907" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1576" PostTypeId="2" ParentId="1562" CreationDate="2015-10-06T02:53:06.210" Score="12" Body="&lt;p&gt;I see mainly three ways of computing normals for a generated shape.&lt;/p&gt;&#xA;&lt;h1&gt;Analytic normals&lt;/h1&gt;&#xA;&lt;p&gt;In some cases you have enough information about the surface to generate the normals. For example, the normal of any point on a sphere is trivial to compute. Put simply, when you know the derivative of the function, you also know the normal.&lt;/p&gt;&#xA;&lt;p&gt;If your case is narrow enough to allow you to use analytic normals, they will probably give the best result in terms of precision. The technique doesn't scale too well though: if you also need to handle cases where you cannot use analytic normals, it may be easier to keep the technique that handles the general case and drop the analytic one altogether.&lt;/p&gt;&#xA;&lt;h1&gt;Vertex normals&lt;/h1&gt;&#xA;&lt;p&gt;The cross product of two vectors gives a vector perpendicular to the plane they belong to. So getting the normal of a triangle is straightforward:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 computeNormal(vec3 a, vec3 b, vec3 c)&#xA;{&#xA;    return normalize(crossProduct(b - a, c - a));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Moreover, in the above example, the length of the cross product is proportional to the area inside &lt;em&gt;abc&lt;/em&gt;. So the smoothed normal at a vertex shared by several triangles can be computed by summing up the cross products and normalizing as a last step, thus weighting each triangle by its area.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 computeNormal(vertex a)&#xA;{&#xA;    vec3 sum = vec3(0, 0, 0);&#xA;    list&amp;lt;vertex&amp;gt; adjacentVertices = getAdjacentVertices(a);&#xA;    for (int i = 1; i &amp;lt; adjacentVertices; ++i)&#xA;    {&#xA;        vec3 b = adjacentVertices[i - 1];&#xA;        vec3 c = adjacentVertices[i];&#xA;        sum += crossProduct(b - a, c - a);&#xA;    }&#xA;    if (norm(sum) == 0)&#xA;    {&#xA;        // Degenerate case&#xA;        return sum;&#xA;    }&#xA;    return normalize(sum);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If you are working with quads, there is a nice trick you can use: for a quad &lt;em&gt;abcd&lt;/em&gt;, use &lt;code&gt;crossProduct(c - a, d - b)&lt;/code&gt; and it will handle nicely cases where the quad is in fact a triangle.&lt;/p&gt;&#xA;&lt;p&gt;Iñigo quilez wrote a few short articles on the topic: &lt;a href=&quot;http://www.iquilezles.org/www/articles/normals/normals.htm&quot; rel=&quot;noreferrer&quot;&gt;clever normalization of a mesh&lt;/a&gt;, and &lt;a href=&quot;http://iquilezles.org/www/articles/areas/areas.htm&quot; rel=&quot;noreferrer&quot;&gt;normal and area of n sided polygons&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h1&gt;Normals from partial derivatives&lt;/h1&gt;&#xA;&lt;p&gt;Normals can be computed in the fragment shader from the partial derivatives. The math behind is the same, except this time it is done in screen space. This article by Angelo Pesce describes the technique: &lt;a href=&quot;http://c0de517e.blogspot.jp/2008/10/normals-without-normals.html&quot; rel=&quot;noreferrer&quot;&gt;Normals without normals&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-10-14T11:43:16.537" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1578" PostTypeId="1" AcceptedAnswerId="1582" CreationDate="2015-10-06T06:56:25.257" Score="10" ViewCount="232" Body="&lt;p&gt;In the section &lt;em&gt;6.4 Constant Buffers&lt;/em&gt; of the book &lt;a href=&quot;http://rads.stackoverflow.com/amzn/click/B00DIKUB7G&quot;&gt;&lt;em&gt;Practical Rendering &amp;amp; Computation with Direct3D 11&lt;/em&gt;&lt;/a&gt; (pages 325, 326) it is mentioned:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;By default, the HLSL compiler will attempt to align constants such that they don't span multiple float4 registers. [...] The packing for an HLSL constant buffer can also be manually specified through the packoffset keyword.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I assume a similar rule will apply to the OpenGL equivalent, Uniform Buffer Objects, since they map to the same hardware feature.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What about vanilla uniforms though? What are the rules that apply when declaring uniforms?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform vec2 xy; // Can we expect the compiler to pack xy&#xA;uniform vec2 zw; // into a same four component register?&#xA;&#xA;uniform vec2 rg;&#xA;uniform float foo; // Will this prevent from packing rg and ba?&#xA;uniform vec2 ba;   // If so, will foo eat up a full four components register?&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the compiler can do such optimizations, how good are they? Can we explicitly tell the compiler to pack or not, and when should we?&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2015-10-06T15:52:54.030" Title="Do the alignement and declaration order of uniforms matter?" Tags="&lt;opengl&gt;&lt;directx11&gt;&lt;constant-buffer&gt;&lt;uniform-buffer-object&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1579" PostTypeId="1" CreationDate="2015-10-06T10:43:35.327" Score="3" ViewCount="297" Body="&lt;p&gt;Raytracing &quot;sees&quot; the pixel on the other side of the screen;&#xA;but doesn't this mean the rays traced can be computationally reflected and refracted imitating the properties of actual light?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It'd be exciting if it were possible. Any visual scene possible outside computer graphics will be possible just using physics equations.&lt;/p&gt;&#xA;" OwnerUserId="1792" LastActivityDate="2015-10-06T22:06:01.717" Title="Can raytracing be used to imitate the behavior of light to a higher degree?" Tags="&lt;raytracing&gt;&lt;reflection&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1581" PostTypeId="1" AcceptedAnswerId="1586" CreationDate="2015-10-06T15:50:25.017" Score="7" ViewCount="167" Body="&lt;p&gt;Computer graphics files are in Windows rendered by components such as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Graphics_Device_Interface&quot;&gt;Graphics Device Interface&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Direct2D&quot;&gt;Direct2D&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to create a graphic file that, besides displaying a graphic also utilizes custom code inside the graphic file?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With custom code I am referring to functionality such as:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Incrementing a counter or date that is displayed on the graphic.&lt;/li&gt;&#xA;&lt;li&gt;Accessing a web URL to retrieve data that is displayed on the graphic.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="1806" LastActivityDate="2015-10-13T05:32:32.323" Title="To what degree, if at all, can custom code be embedded in a PNG, GIF, or JPG?" Tags="&lt;rendering&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1582" PostTypeId="2" ParentId="1578" CreationDate="2015-10-06T15:52:54.030" Score="4" Body="&lt;p&gt;I went looking for an answer, so I downloaded AMD's shader analyzer to view the assembly produced when compiled for GCN. In the assembly below vector registers are v# and scalar registers are s#.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would appear that the uniforms even vector uniforms are passed into the shader as separate scalars, so a vec3 would use 3 scalar registers. The bit I found confusing was the v0 to v4, I'm not sure if v0 is a full 4 float register or a single float in a register, with a full vector register spanning v0 to v3. One way or another it didn't appear to change between the two versions so I can assume the definition order didn't affect the assembly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/07/AMD_GCN3_Instruction_Set_Architecture.pdf&quot; rel=&quot;nofollow&quot;&gt;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/07/AMD_GCN3_Instruction_Set_Architecture.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;uniform vec2 xy; &#xA;uniform vec2 zw;&#xA;&#xA;out vec4 v;&#xA;&#xA;void main(){ &#xA;    v.xy = xy; &#xA;    v.zw = zw; &#xA;}&#xA;&#xA;shader &#xA;  asic(VI)&#xA;  type(VS)&#xA;&#xA;  v_cndmask_b32  v0, s0, v0, vcc               &#xA;  v_mov_b32     v0, 0                          &#xA;  v_mov_b32     v1, 1.0                        &#xA;  exp           pos0, v0, v0, v0, v1 done      &#xA;  s_andn2_b32   s0, s5, 0x3fff0000             &#xA;  s_mov_b32     s1, s0                         &#xA;  s_mov_b32     s2, s6                         &#xA;  s_mov_b32     s3, s7                         &#xA;  s_mov_b32     s0, s4                         &#xA;  s_buffer_load_dwordx2  s[4:5], s[0:3], 0x00  &#xA;  s_buffer_load_dwordx2  s[0:1], s[0:3], 0x10  &#xA;  s_waitcnt     expcnt(0) &amp;amp; lgkmcnt(0)         &#xA;  v_mov_b32     v0, s4                         &#xA;  v_mov_b32     v1, s5                         &#xA;  v_mov_b32     v2, s0                         &#xA;  v_mov_b32     v3, s1                         &#xA;  exp           param0, v0, v1, v2, v3         &#xA;end&#xA;&#xA;#version 450&#xA;&#xA;uniform vec2 xy;&#xA;uniform float z;&#xA;uniform vec2 zw;&#xA;&#xA;out vec4 v;&#xA;&#xA;void main(){ &#xA;    v.xy = xy; &#xA;    v.zw = zw;&#xA;    v.w += z;&#xA;}&#xA;&#xA;shader &#xA;  asic(VI)&#xA;  type(VS)&#xA;&#xA;  v_cndmask_b32  v0, s0, v0, vcc              &#xA;  v_mov_b32     v0, 0                         &#xA;  v_mov_b32     v1, 1.0                       &#xA;  s_andn2_b32   s0, s5, 0x3fff0000            &#xA;  exp           pos0, v0, v0, v0, v1 done     &#xA;  s_mov_b32     s1, s0                        &#xA;  s_mov_b32     s2, s6                        &#xA;  s_mov_b32     s3, s7                        &#xA;  s_mov_b32     s0, s4                        &#xA;  s_buffer_load_dword  s4, s[0:3], 0x10       &#xA;  s_buffer_load_dwordx2  s[6:7], s[0:3], 0x00 &#xA;  s_buffer_load_dwordx2  s[0:1], s[0:3], 0x20 &#xA;  s_waitcnt     expcnt(0) &amp;amp; lgkmcnt(0)        &#xA;  v_mov_b32     v0, s4                        &#xA;  v_add_f32     v0, s1, v0                    &#xA;  v_mov_b32     v1, s6                        &#xA;  v_mov_b32     v2, s7                        &#xA;  v_mov_b32     v3, s0                        &#xA;  exp           param0, v1, v2, v3, v0        &#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1801" LastActivityDate="2015-10-06T15:52:54.030" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1583" PostTypeId="2" ParentId="1536" CreationDate="2015-10-06T19:25:49.710" Score="4" Body="&lt;p&gt;complement: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;homogeneous coordinates also allows to represent infinity: $(x,y, z, 0) = \frac{x,y,z}0$ in 3D, i.e., the point at infinity in direction $x,y,z$. Typically, light sources at finite or infinite position can be represented the same way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About perspective transform, it even allows to interpolate correctly with no perspective distortion (contrary to early graphics hardware on PC ).&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="137" LastEditDate="2015-11-03T15:15:14.507" LastActivityDate="2015-11-03T15:15:14.507" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1584" PostTypeId="2" ParentId="1579" CreationDate="2015-10-06T19:49:41.333" Score="2" Body="&lt;p&gt;Raytracing is one of the techniques that trace the light as it moves through the scene.&#xA;This can, depending on the implementation, also include effects such as refraction, reflection and scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Raytracing and similar techniques (see Monte-Carlo Pathtracing for example) all are based on the idea to solve the so called rendering equation.&#xA;The equation is a long known equation that describes the physically correct amount of light we can see for at each point (this means mathematical infinitesimal point, not pixel!).&#xA;By (approximally) solving this equation the mentioned rendering techniques are indeed able to render &quot;all&quot; scenes. The only real limiting factors are that it is hard to solve the equation for some effects and the huge amount of computation you need to solve it.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2015-10-06T19:49:41.333" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1585" PostTypeId="2" ParentId="1579" CreationDate="2015-10-06T22:06:01.717" Score="7" Body="&lt;p&gt;You are late by about 35 years. This was addressed in the historical paper &quot;Whitted, T., An improved illumination model for shaded display. Communications of the ACM, Volume 23 Issue 6, June 1980, Pages 343-349&quot;, using  ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qKlTI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qKlTI.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since then radiosity has been introduced to better deal with diffuse phenomena. Correct physical modeling of the image formation process was discussed six years later in the seminal &quot;Kajiya, James T. (1986), &quot;The rendering equation&quot;, Siggraph 1986: 143&quot;.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastActivityDate="2015-10-06T22:06:01.717" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1586" PostTypeId="2" ParentId="1581" CreationDate="2015-10-06T22:34:12.600" Score="7" Body="&lt;p&gt;Common graphics formats such as JPEG, PNG and GIF are not designed to have any form of code inside them. They just store a compressed array of pixels&amp;mdash;they can't generate anything on command or contact a web service, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(There have occasionally been vulnerabilities discovered in image decoders, that would allow a maliciously constructed image to cause code execution when viewed, via a buffer overflow exploit or similar. But this is of course not part of the design of the format.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some vector graphics formats such as EPS and SVG actually do allow embedding code. However, being vector formats instead of bitmap ones, these formats often aren't supported by ordinary image viewers (although SVG is supported by browsers), and can't be edited in ordinary paint programs. One needs specialized vector graphics programs to work with them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to generate an image that updates with new data, you could create a web service that regenerates the image on the server each time it's requested. However, if a client caches the resulting image rather than re-requesting it each time it's viewed, they would see old data.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-10-06T22:34:12.600" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1587" PostTypeId="1" AcceptedAnswerId="1588" CreationDate="2015-10-07T00:07:08.770" Score="6" ViewCount="1144" Body="&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=LKnqECcg6Gw&quot; rel=&quot;nofollow&quot;&gt;In this video&lt;/a&gt; from about 1:15, it is stated that if you have an RGB value of (0.5,0.5,0.5) it is only 22% as bright as (1,1,1) rather than the expected 50% as bright.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this mean that RGB is adjusted for a logarithmic scale so that we perceive the (0.5,0.5,0.5) to be half as bright, or have a misunderstood the video?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Despite searching around a lot I can not find any other source of information that discusses this.&lt;/p&gt;&#xA;" OwnerUserId="1812" LastEditorUserId="54" LastEditDate="2015-10-07T08:36:47.367" LastActivityDate="2015-11-03T13:56:29.593" Title="Actual vs Perceived Brightness of RGB Colour" Tags="&lt;color&gt;&lt;brightness&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1588" PostTypeId="2" ParentId="1587" CreationDate="2015-10-07T02:46:58.663" Score="9" Body="&lt;p&gt;Two different effects are causing the observation mentioned in the video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On one side, the vast majority of screens have a non linear response: if the RGB value is half as much, the emitted light intensity is not half as much. This behavior originally comes from &lt;a href=&quot;https://en.wikipedia.org/wiki/Cathode_ray_tube&quot; rel=&quot;nofollow&quot;&gt;cathode ray tube (CRT)&lt;/a&gt; displays, which produced different light intensities by varying the voltage used to generate the electron beam. From the article:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;CRTs have a pronounced triode characteristic, which results in significant gamma (a nonlinear relationship in an electron gun between applied video voltage and beam intensity).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As CRT became ubiquitous, systems assumed this behavior to be present and took it into account. Nowadays CRT have mostly been replaced by LCD technology, which emulate this behavior for compatibility.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gamma is usually considered to be around $2.2$, which means the light intensity follows a function $I=x^{2.2}$. This is where the 22% mentioned in the video comes from: ($0.5^{2.2} \approx 0.218$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other side, the human vision is not linear either. &lt;a href=&quot;https://en.wikipedia.org/wiki/Lux#Illuminance&quot; rel=&quot;nofollow&quot;&gt;According to Wikipedia&lt;/a&gt;, a typical sunset on a clear day is about 400 lux, and clear sky daylight is about 10000 to 25000 lux. Yet the latter doesn't feel over 25 times as bright as the former.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, the non linear response of screens is a good thing, because it gives more precision where it is needed. Note that it is not logarithmic though, but closer to a square function. If you want to read more on the topic, you can look for articles on &lt;em&gt;&quot;gamma correction&quot;&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="137" LastEditDate="2015-11-03T13:56:29.593" LastActivityDate="2015-11-03T13:56:29.593" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1589" PostTypeId="1" CreationDate="2015-10-07T08:36:55.203" Score="1" ViewCount="51" Body="&lt;p&gt;Say I am running a game in the cloud and I am playing that game on my client (the game is being streamed from the cloud to the client), be it a laptop, phone or calculator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I work out how long a frame (of the game being played) takes to arrive at the client?&lt;/p&gt;&#xA;" OwnerUserId="1800" LastEditorUserId="1800" LastEditDate="2015-10-07T11:30:11.603" LastActivityDate="2015-10-07T11:30:11.603" Title="Measure how long a rendered frame takes to arrive on a client from the cloud" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2015-10-09T19:18:07.210" ContentLicense="CC BY-SA 3.0" />
  <row Id="1590" PostTypeId="2" ParentId="1589" CreationDate="2015-10-07T11:11:51.073" Score="1" Body="&lt;p&gt;Try putting a timestamp over some key frames as the last step on your render pipeline. Then compare it to the local systems time. If both clocks are correct you should get a delay in ms (using unix rime-stamps).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another idea to measure the round-trip-delay (might be important for UX reasons):&#xA;input to server,&#xA;server render,&#xA;result from to server on your screen&#xA;is to have a bot give an input than measure the time till the result is back&lt;/p&gt;&#xA;" OwnerUserId="1818" LastActivityDate="2015-10-07T11:11:51.073" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1591" PostTypeId="2" ParentId="283" CreationDate="2015-10-07T12:12:45.563" Score="11" Body="&lt;p&gt;As usual with numerical methods and samplings, it also depends of your quality threshold of what you consider &amp;quot;isotropic&amp;quot;. And of what you would consider as a being or not a &amp;quot;grid-based noise algorithm&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;For instance Gabor Noise reproduces a target spectrum, for instance blue noise, which in Fourier domain is a simple isotropic ring.&#xA;Now if you consider that this ring is not analytic but rasterized, as such it is not perfectly symmetrical. Also if the ring radius (i.e., frequency) get too close to the window size (i.e., maximum frequency), it will be truncated (and thus no longer symmetrical). Up to you to accept or not these as anisotropic ;-)&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vFj2M.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vFj2M.png&quot; alt=&quot;&amp;quot;this is not a circle&amp;quot; - Magritte&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/c4Xaj.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c4Xaj.png&quot; alt=&quot;&amp;quot;this is not a circle&amp;quot; - Nyquist&quot; /&gt;&lt;/a&gt;&#xA;&lt;em&gt;&amp;quot;This is not a circle&amp;quot; - Magritte . . . . . . . . . . . . . . . .   &amp;quot;This is not a circle&amp;quot; - Nyquist&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;You might or might not accept a rasterized ring in Fourier space to be &amp;quot;isotropic&amp;quot;. Still, in the extreme cases where the ring get thinner than the resolution, or larger than the window, isotropy is objectively lost.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-10-08T08:08:20.757" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1592" PostTypeId="1" AcceptedAnswerId="1593" CreationDate="2015-10-07T13:15:33.013" Score="7" ViewCount="746" Body="&lt;p&gt;I am working on Silverlight app. I am trying to render floor covered with tiles. Although I am using mip maps I am still getting awful Moire patterns, when trying to render big area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I am doing is creating cuboid and then cover it with single tile:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fZhKQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fZhKQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my pixel shader I am multiplying texture coordinates in order to create tiled floor (otherwise I would get one tile stretched over my cuboid). Pixel shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Width                 : register(c3);                  //Width of cuboid&#xA;float Height                : register(c4);                  //Height of cuboid&#xA;&#xA;texture texTexture;&#xA;sampler textureSampler  : register(s0) = sampler_state {&#xA;    Texture = (texTexture);&#xA;};&#xA;&#xA;struct VsOutput&#xA;{&#xA;    float4 position : POSITION;&#xA;    float3 dirLightPosition : COLOR;&#xA;    float2 texCoord : TEXCOORD0;&#xA;    float3 normal   : TEXCOORD1;&#xA;    float3 view : TEXCOORD2;&#xA;};&#xA;&#xA;float4 main(VsOutput IN) : COLOR&#xA;{&#xA;    float2 texCoord = float2(IN.texCoord.x * Width / 4.0f, &#xA;                             IN.texCoord.y * Height / 4.0f); //multiplying texture coordinates&#xA;&#xA;&#xA;    float4 texColor = tex2D(textureSampler, texCoord);&#xA;&#xA;    return float4(color.r, color.g, color.b, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My output is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pPOY1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pPOY1.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What else can I do to prevent from creating Moires patterns on texture?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="205" LastEditorUserId="205" LastEditDate="2015-10-09T15:56:02.890" LastActivityDate="2015-10-09T15:56:19.853" Title="Moires patterns despite using mipmaps" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;pixel-shader&gt;&lt;artifacts&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="1593" PostTypeId="2" ParentId="1592" CreationDate="2015-10-07T13:54:55.197" Score="5" Body="&lt;p&gt;Two things come to mind:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;When generating your smaller mip map levels try to avoid using a simple 2x2 box filter because, though cheap and cheerful, they do a really poor job of removing high frequency information (that exceeds the Nyquist limit) as well as &lt;em&gt;over filtering&lt;/em&gt; some of the lower frequency information you need to keep. (Also, as an aside, you need to perform the MIP map generation in linear space. If your source data is sRGB, you thus need to map to and from linear).  FWIW, In Williams' original paper on MIP mapping, he said he used a &quot;box (Fourier) window&quot; to generate the prefiltered levels, which would be a sinc function in image space.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Standard Trilinear filtering will also over- and under-filter parts of the texture. If you don't like the aliasing you may have to a) adjust the bias to increase the filtering (which will increase blurring) and/or b) try using anisotropic filtering.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2015-10-07T14:21:16.043" LastActivityDate="2015-10-07T14:21:16.043" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1594" PostTypeId="2" ParentId="1557" CreationDate="2015-10-07T16:59:14.693" Score="5" Body="&lt;p&gt;When it comes to perception, there is also the issue of what we are almost blind to (in terms of properties or artifacts), and what we have enforced perception of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance as for sound, you have contrast or frequencies that make you less or not aware of other contents (an old SIGGRAPH paper illustrated how texture can mask mesh resolution), plus all the time aspects (google for &quot;change blindness&quot;). Similarly, details of surface, normals, BRDF might or might not be seen depending of values and relative values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also since our perceptive system tends to adapt locally and globally, for low frequency values it is important to have maxima and minima at the right places, but their exact value won't really be noticed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sometimes cognition might be there to, like you allow a lot of errors in clouds and trees but surely less in human faces. (Sometimes you might downgrade this to statistics of parameter for a given category.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's why I prefer using the word &quot;plausible&quot; rather than &quot;photorealistic&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Contrarily, we are ultra-sensitive to artifacts such as false pixels or flickering pixels, ultra-sensitive to correlations like fronts of error of 1 grey level only, unwanted patterns such as Moiré, aliasing or bad random, etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way it's one of the reasons that optimization-based solutions summing everything in a simple energy can be a very bad idea perceptively speaking as in all paradoxical situations this can be prone to concentration of errors in lines or points. For the same reason early global illumination people were really disappointed that energy exact solutions were less accepted than anti-aliased approximate shadows (and then came from quad-tree based to mesh-based adaptive methods).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A (quite general) overview about perception for graphics can be found in this SigAsia'11 course on &lt;a href=&quot;http://dl.acm.org/citation.cfm?id=2077448&quot; rel=&quot;nofollow&quot;&gt;&quot;Perception in Graphics, Visualization, Virtual Environments and Animation&quot;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="231" LastEditDate="2015-10-16T08:20:53.373" LastActivityDate="2015-10-16T08:20:53.373" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1595" PostTypeId="1" AcceptedAnswerId="1599" CreationDate="2015-10-07T18:10:08.277" Score="7" ViewCount="3344" Body="&lt;p&gt;Is there any strategy to detect the region of an image that is sharp and in-focus, in order to separate the out-of-focus background? I've tried using &lt;a href=&quot;https://en.wikipedia.org/wiki/Edge_detection&quot; rel=&quot;nofollow&quot;&gt;edge detection&lt;/a&gt; methods but without any success. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, is it possible to determine if an area of an image is blurred (out of focus) or not?&lt;/p&gt;&#xA;" OwnerUserId="18" LastEditorUserId="48" LastEditDate="2015-10-09T18:36:05.377" LastActivityDate="2015-10-09T18:36:05.377" Title="Detect in-focus regions of an image" Tags="&lt;algorithm&gt;&lt;blur&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1597" PostTypeId="2" ParentId="1434" CreationDate="2015-10-07T18:53:23.187" Score="4" Body="&lt;p&gt;Radiosity, by definition, handles only the diffuse component. You cannot 'limit' Radiosity to diffuse, because it already is handling just that diffuse component (remember - the diffuse lighting is just one (albeit popular) application of the energy distribution).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, you just misinterpreted the quote.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, contrary to popular misconception, you &lt;strong&gt;do &lt;em&gt;not&lt;/em&gt; have to distribute all energy&lt;/strong&gt; to get great results. Look into &lt;strong&gt;Progressive Refinement method&lt;/strong&gt;, which only processes the largest emitors, thus allowing to converge to 'close enough' solution much sooner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually, you set some threshold (e.g. I want to redistribute 85% if all energy) and before processing the next Shooter patch, you do a simple check for the running total of the distributed energy (and quit the loop). This is usually few orders of magnitude faster (for a very minor implementation cost) than the reference brute-force method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, to get true benefits of Radiosity (e.g. color bleeding) it's best to redistribute as much as possible (given the resources available).&lt;/p&gt;&#xA;" OwnerUserId="1820" LastActivityDate="2015-10-07T18:53:23.187" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1598" PostTypeId="2" ParentId="1529" CreationDate="2015-10-07T20:34:05.963" Score="3" Body="&lt;p&gt;Google said how in 2012, avoiding explaining too many details&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://googleblog.blogspot.it/2012/06/never-ending-quest-for-perfect-map.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;The never-ending quest for the perfect map&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;...new imagery rendering techniques and computer vision that let us&#xA;  automatically create 3D cityscapes, complete with buildings, terrain&#xA;  and even landscaping, from 45-degree aerial imagery&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;and here it's a &lt;a href=&quot;https://www.youtube.com/watch?t=44&amp;amp;v=N6Douyfa7l8&quot; rel=&quot;nofollow noreferrer&quot;&gt;video&lt;/a&gt; of the feature.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So we know that &quot;Computer Vision&quot; is used. I guess the edges are detected, along with the shadows, to build the elevation of the object. Then the segmented image is used as a texture on the built mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, i saw &lt;a href=&quot;http://iris.usc.edu/outlines/papers/1998/lin-cviu98.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; linked, and i think a similar technique is used in Google to extract the 3d mesh from different 45° images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a lot of papers (a book too) about &quot;building extraction/detection&quot;.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.asprs.org/a/publications/proceedings/Louisville2014/Jabari_1.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Detection of buildings in urban and suburban areas using very high resolution satellite&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://scholar.google.it/scholar?q=Building+Detection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Google Scholar: Building Detection&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://scholar.google.it/scholar?q=Building%20Detection%20from%20Satellite%20Images&amp;amp;btnG=&amp;amp;hl=en&amp;amp;as_sdt=0%2C5&amp;amp;as_vis=1&quot; rel=&quot;nofollow noreferrer&quot;&gt;Google Scholar: Building Detection from Satellite Images&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;src: &lt;a href=&quot;https://softwareengineering.stackexchange.com/questions/202599/how-does-the-new-google-maps-make-buildings-and-cityscapes-3d&quot;&gt;How does the new google maps make buildings and cityscapes 3D?&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="316" LastEditorUserId="-1" LastEditDate="2017-04-12T07:32:01.480" LastActivityDate="2015-10-07T20:34:05.963" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1599" PostTypeId="2" ParentId="1595" CreationDate="2015-10-07T21:07:45.853" Score="9" Body="&lt;p&gt;it is quite easy to measure the local max frequency in an image (at least as a low resolution mask, with some regularization).&#xA;Several papers of the MIT graphics group have been around detecting and processing from this kind of clue, with regular or coded aperture cameras.&#xA;e.g. &lt;a href=&quot;http://people.csail.mit.edu/soonmin/dof/&quot;&gt;Defocus Magnification&lt;/a&gt; and &lt;a href=&quot;http://groups.csail.mit.edu/graphics/CodedAperture/&quot;&gt;Image and Depth from a Conventional Camera with a Coded Aperture&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2015-10-07T21:07:45.853" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1601" PostTypeId="2" ParentId="1434" CreationDate="2015-10-08T07:48:39.857" Score="1" Body="&lt;p&gt;The sentence says it: radiosity precomputes an &quot;image&quot; for all potential viewpoints at the same time, i.e. it doesn't focus on just the rays that hit a particular observer. Hence there are naturally many more rays to consider, as you are actually rendering a multitude of views simultaneously.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whether the surfaces are specular or diffuse isn't really relevant in regard to this statement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make the approach viable, radiosity performs very gross rendering, as if using large beams instead of thin rays.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastEditorUserId="1703" LastEditDate="2015-10-08T08:19:00.467" LastActivityDate="2015-10-08T08:19:00.467" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1602" PostTypeId="2" ParentId="361" CreationDate="2015-10-08T08:27:22.417" Score="2" Body="&lt;p&gt;What one has to do in this matter is first define the quantities that are physically at play here, so that everybody speaks about the same thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;radiance (&lt;a href=&quot;https://en.wikipedia.org/wiki/Radiance&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;)&lt;br&gt;&#xA;Flux emitted by a surface per solid angle per projected area.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/N2ziI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N2ziI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Unit is &lt;strong&gt;W·sr−1·m−2&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;radiant intensity (&lt;a href=&quot;https://en.wikipedia.org/wiki/Radiant_intensity&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;)&lt;br&gt;&#xA;Origin of radiance, you take the surface area out of the unit.&lt;br&gt;&#xA;Unit is &lt;strong&gt;W·sr−1&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;intensity (&lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_intensity&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;)&lt;br&gt;&#xA;A perception-based unit of power per solid angle.&lt;br&gt;&#xA;Unit is &lt;strong&gt;candela&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;luminance (&lt;a href=&quot;https://en.wikipedia.org/wiki/Luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;)&lt;br&gt;&#xA;&lt;em&gt;The luminance is normally obtained by dividing the luminous intensity by the light source area&lt;/em&gt; (&lt;a href=&quot;http://www.rohm.com/web/eu/faq_search/-/faq_search/FaqId/260&quot; rel=&quot;nofollow noreferrer&quot;&gt;source&lt;/a&gt;)&lt;br&gt;&#xA;therefore this is also perception based.&lt;br&gt;&#xA;Unit is &lt;strong&gt;cd·m−2&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;luminuous flux (&lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_flux&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;)&lt;br&gt;&#xA;Same thing but not related to solid angle.&lt;br&gt;&#xA;quote:&lt;br&gt;&#xA;&lt;em&gt;Luminous flux is a measure of the total amount of light a lamp puts out. The luminous intensity (in candelas) is a measure of how bright the beam in a particular direction is&lt;/em&gt;&lt;br&gt;&#xA;Unit is &lt;strong&gt;lumen&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can also talk of irradiance (&lt;a href=&quot;https://en.wikipedia.org/wiki/Irradiance&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt;) when speaking of received radiance.&lt;br&gt;&#xA;And one can also talk of total-irradiance when speaking of the irradiance taken for the whole hemisphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;refer to: &lt;a href=&quot;http://www.crompton.com/light/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.crompton.com/light/index.html&lt;/a&gt;&lt;br&gt;&#xA;and: &lt;a href=&quot;https://pathtracing.wordpress.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pathtracing.wordpress.com/&lt;/a&gt;&lt;br&gt;&#xA;and why not: &lt;a href=&quot;http://www.nvc-lighting.com/showuseInfo.Aspx?typeID=42&amp;amp;ID=94&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.nvc-lighting.com/showuseInfo.Aspx?typeID=42&amp;amp;ID=94&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, there are two classes of units, the perception based and the absolute physical units.&lt;br&gt;&#xA;the &lt;strong&gt;radiance&lt;/strong&gt; is the measure you want to look at to understand Lambert, you can actually see the cosine falloff directly in the formula.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see the intuition of this in this blog: &lt;a href=&quot;https://pathtracing.wordpress.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pathtracing.wordpress.com/&lt;/a&gt; chapter &quot;Lambert's cosine law&quot;&lt;/p&gt;&#xA;" OwnerUserId="1614" LastEditorUserId="1614" LastEditDate="2015-10-09T01:49:20.690" LastActivityDate="2015-10-09T01:49:20.690" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1604" PostTypeId="2" ParentId="210" CreationDate="2015-10-09T01:44:16.853" Score="3" Body="&lt;p&gt;I'll add some guidelines to help readers understand Benedikt Bitterli's statement &quot;Make sure to gamma correct your images&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gamma correcting images does not mean applying a power filter at the end.&#xA;It means working in linear space during all calculations, and finally encoding the output into gamma space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gamma space is the color space into which all display machines of this age expect RGB values to be presented to them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Linear space in opposition, is the fact of working with values which are proportional to physical emissions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, when the artist edit the values of the albedos colors of the world surfaces, and the colors of the lights of the scene, he does it in gamma space because no edition software dare to modify what the user has input and just saves as-is. So the artist was looking at something that looked good for him, while stored in gamma space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the first step of all rendering engine, should be to convert all human edited input to linear space first. In your case that means all sphere colors and emissions values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, you do your usual raytracing, brdf evaluation, monte carlo sampling, whatever process, in HDR if possible using &lt;code&gt;float32&lt;/code&gt; components if possible. (usually works nice with 128 bits SIMD as &lt;code&gt;r,g,b,a&lt;/code&gt; vectors).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally you tone filter the HDR image according to the exposure value you choose, heuristically or manually. This operation could be very simple like a &lt;code&gt;clamp&lt;/code&gt;. And then and only then, you encode the final image to gamma space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The base is: a monitor will take an input value x and apply the formula x^2.2 to create the physical radiance on the output pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, the conversion formulas goes as follow:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;linear to gamma: x^(1/2.2)&lt;br&gt;&#xA;gamma to linear: x^2.2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please note as trivia that sRGB space has a complex formula, a &lt;code&gt;if&lt;/code&gt;, and some offset. But viewed from afar the curve is very very close to simple gamma.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second thing to take into account, are you sure your sampling is fair ?&lt;br&gt;&#xA;You could be sampling too much in the directions that privileges more rays to reach the sky. check the uniformity of your sampling. You said you use a gaussian that seems to me like you are going to ask for bias. Just use the classic Lambert distribution sampling: &lt;a href=&quot;https://pathtracing.wordpress.com/&quot; rel=&quot;nofollow&quot;&gt;https://pathtracing.wordpress.com/&lt;/a&gt;&#xA;this way you reduce the number of samples necessary to get a variance equivalent with a purely uniform sphere. and you also save the cosine evaluation because its embedded in the distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, if your spheres are really mirrors and your GI is supposedly actually working, it will accumulate reflected energy on the ground, therefore compensating your shadows from occlusion. I even expect to see more energy than darkening in such cases.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2015-10-09T01:44:16.853" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1605" PostTypeId="2" ParentId="1592" CreationDate="2015-10-09T15:56:19.853" Score="2" Body="&lt;p&gt;&lt;strong&gt;SOLUTION&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I managed to solve my problem by increacing size of texture 2048x2048px so there would be generated more mipmaps. Also it seems like changing my SamplerState form anisotropic to something like that helped:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;SamplerState MirrorTexCoord = new SamplerState()&#xA;        {&#xA;            AddressU = TextureAddressMode.Mirror,&#xA;            AddressV = TextureAddressMode.Mirror,&#xA;            .&#xA;            .&#xA;            .&#xA;        };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Actually I don' t know what is TextureAdressMode.Mirror, but it helped a lot, now it looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2acRT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2acRT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="205" LastActivityDate="2015-10-09T15:56:19.853" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1606" PostTypeId="1" CreationDate="2015-10-09T18:03:51.633" Score="2" ViewCount="243" Body="&lt;p&gt;I have the following problem:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Give a matrix that will transform the point $(x,y,z)$ into the point $(\frac{2}{x+y}, \frac{5y + z}{2x + 2y}, 3)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been reading my book to find a way to solve it without success. I will very much appreciate your feedback about how to solve it.&lt;/p&gt;&#xA;" OwnerUserId="1836" LastEditorUserId="16" LastEditDate="2015-11-03T12:56:46.733" LastActivityDate="2015-11-04T09:32:20.727" Title="Transform a point into another point" Tags="&lt;transformations&gt;" AnswerCount="3" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1607" PostTypeId="2" ParentId="1606" CreationDate="2015-10-09T18:37:37.273" Score="2" Body="&lt;p&gt;The hint is to use the perspective divide inherent in homegeneous coordinate. So the resulting point you are looking for is $(2, (5y+z)/2, 3x+3y, x+y)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That matrix then ends up as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;    0 &amp;amp;  0 &amp;amp;  0 &amp;amp;  2  \\&#xA;    0 &amp;amp;  2.5&amp;amp; 0.5&amp;amp; 0  \\&#xA;    3 &amp;amp;  3 &amp;amp;  0 &amp;amp;  0  \\&#xA;    1 &amp;amp;  1 &amp;amp;  0 &amp;amp;  0  \\&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2015-11-03T12:54:16.087" LastActivityDate="2015-11-03T12:54:16.087" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1608" PostTypeId="1" CreationDate="2015-10-09T19:40:42.943" Score="8" ViewCount="13653" Body="&lt;p&gt;I already know about the matrices I have to use in order to perform rotations. If I have to rotate in z-axis and then in x-axis, I would do it in 2 steps. My question is, is it possible to combine both rotations into a single matrix? I will appreciate your feedback.&lt;/p&gt;&#xA;" OwnerUserId="1836" LastActivityDate="2015-10-18T06:09:20.450" Title="How to combine rotation in 2 axis into one matrix" Tags="&lt;transformations&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1609" PostTypeId="2" ParentId="1608" CreationDate="2015-10-09T19:58:32.230" Score="6" Body="&lt;p&gt;Yes, just multiply them in reverse order:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix myrotation = Matrix.CreateRotationX(xrot) * Matrix.CreateRotationZ(zrot);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT.&lt;/strong&gt; &#xA;My answer only applies if you are using column vectors. Please see Martin Büttner detailed answer.&lt;/p&gt;&#xA;" OwnerUserId="1826" LastEditorUserId="1826" LastEditDate="2015-10-13T11:58:18.750" LastActivityDate="2015-10-13T11:58:18.750" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1610" PostTypeId="1" CreationDate="2015-10-10T17:25:56.540" Score="3" ViewCount="109" Body="&lt;p&gt;I have the following question in an exam review and I am looking for feedback about how to approach the solution. Any advice will be highly appreciated.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&quot;Using a parametric line intersection test, give the parameter values of the endpoints of a line from (3,3,4) to (11,8,7) clipped to the cube extending from 0 to 5 in x, y, and z&quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="1836" LastEditorUserId="4" LastEditDate="2015-10-12T16:31:21.303" LastActivityDate="2015-11-03T15:15:16.903" Title="Parametric line intersection test" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1611" PostTypeId="2" ParentId="1610" CreationDate="2015-10-11T08:59:56.547" Score="4" Body="&lt;p&gt;&lt;strong&gt;Hint&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The three coordinates can be handled independently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance in $x$, you need to solve&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$x_0 + t (x_1-x_0) = 0$$&#xA; and&lt;br&gt;&#xA;$$x_0 + t (x_1-x_0) = x_{max}$$&lt;/p&gt;&#xA;" OwnerUserId="1703" LastEditorUserId="1703" LastEditDate="2015-11-03T15:15:16.903" LastActivityDate="2015-11-03T15:15:16.903" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1613" PostTypeId="2" ParentId="1608" CreationDate="2015-10-12T15:17:48.963" Score="8" Body="&lt;p&gt;(This answer is essentially the same as Stefan's but I wanted to add some detail about row and column vectors, and how to determine which you are using.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, this is possible, but the details depend on whether you represent your vectors as rows or columns.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Column vectors&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If you are using &lt;em&gt;column&lt;/em&gt; vectors, you will normally transform them by &lt;em&gt;left&lt;/em&gt;-multiplying your matrices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vector = mRotateZ * vector;&#xA;vector = mRotateX * vector;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Of course, you can also do this in one step:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vector = mRotateX * mRotateZ * vector;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But matrix multiplication is associative, which means it doesn't matter which multiplication is performed first:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;A * B * C = (A * B) * C = A * (B * C)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So we can write&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix mRotate = mRotateX * mRotateZ;&#xA;vector = mRotate * vector;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We have now created a single matrix, which is equivalent to &lt;em&gt;first&lt;/em&gt; rotating about &lt;code&gt;Z&lt;/code&gt; and &lt;em&gt;second&lt;/em&gt; about &lt;code&gt;X&lt;/code&gt;. This generalises trivially for any number of transformations. Notice that transformations are applied from right to left.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Row vectors&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If, on the other hand, you are using &lt;em&gt;row&lt;/em&gt; vectors, you will normally &lt;em&gt;right&lt;/em&gt;-multiply your matrices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vector = vector * mRotateZ;&#xA;vector = vector * mRotateX;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Again, writing it in one step, we get&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vector = vector * mRotateZ * mRotateX;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which can be rewritten as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix mRotate = mRotateZ * mRotateX;&#xA;vector = vector * mRotate;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Notice that in this case, the transformations applied from left to right.&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2015-10-13T07:36:02.573" LastActivityDate="2015-10-13T07:36:02.573" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1614" PostTypeId="1" AcceptedAnswerId="1616" CreationDate="2015-10-12T21:04:12.770" Score="7" ViewCount="1309" Body="&lt;p&gt;I have a sequence of compute shaders that generates an indexed mesh.The last one of those writes the generated indices like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void addTriangle (uint i0, uint i1, uint i2) {&#xA;    uint ic = atomicCounterIncrement(indirectIndexCount);&#xA;    meshIndices[ic*3+0] = i0;&#xA;    meshIndices[ic*3+1] = i1;&#xA;    meshIndices[ic*3+2] = i2;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After the mesh has been generated, it is drawn with &lt;a href=&quot;http://docs.gl/gl4/glDrawElementsIndirect&quot;&gt;glDrawElementsIndirect&lt;/a&gt;. The &lt;em&gt;indirectIndexCount&lt;/em&gt; in the code above is an &lt;em&gt;atomic_uint&lt;/em&gt; counter at position 0 inside the &lt;em&gt;GL_DRAW_INDIRECT_BUFFER&lt;/em&gt; (see the struct called &lt;em&gt;DrawElementsIndirectCommand&lt;/em&gt;). This counter is now obviously too small by a factor of three, since it was incremented only once for each triangle. Currently, I multiply it by 3 afterwards just before issuing the draw call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(At the moment this is done by mapping the buffer and multiplying on the CPU, which is of course nonsense, but shows that the whole thing basically works. Everything is drawn correctly. I could do it with an invocation of a single 1x1x1x1x1x1 compute shader, but that seems only slightly less silly.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I get rid of this extra multiplication step?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since this seems to be an obvious problem whenever meshes with variable index count are generated, I guess there must be some easy solution that I'm overlooking?&lt;/p&gt;&#xA;" OwnerUserId="1699" LastActivityDate="2015-10-13T14:44:20.010" Title="OpenGL Compute Shader generating triangle indices: How to get correct element count for glDrawElementsIndirect?" Tags="&lt;opengl&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1615" PostTypeId="2" ParentId="1581" CreationDate="2015-10-13T05:32:32.323" Score="0" Body="&lt;p&gt;I don't know if you would consider this to be a stretch for an answer to your question seeing as how I am a bit unsure how it was intended to be interpreted. That being considered, 2d barcodes can be graphics with which store code and interact with variable data elements defined throughout such symbologies as PDF417, DataMatrix, etc. &lt;/p&gt;&#xA;" OwnerUserId="1846" LastActivityDate="2015-10-13T05:32:32.323" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1616" PostTypeId="2" ParentId="1614" CreationDate="2015-10-13T08:36:08.430" Score="7" Body="&lt;p&gt;If you have access to glsl 4.3+ (or glsl ES 3.1) you can use &lt;a href=&quot;http://docs.gl/sl4/atomicAdd&quot; rel=&quot;noreferrer&quot;&gt;atomicAdd&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next option is to use a &lt;code&gt;barrier()&lt;/code&gt; after all vertices are generated in the compute and then multiplying the value in the counter:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;main(){&#xA;&#xA;    // generate vertices&#xA;&#xA;    barrier();&#xA;    if(gl_localInvocationID == vec3(0)){&#xA;        indirectCount = atomicCounter(indirectIndexCount)*3;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This emulates running another 1x1x1 compute shader to multiply the index.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Otherwise you can use a second atomic to hold the vertexcount:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void addTriangle (uint i0, uint i1, uint i2) {&#xA;    uint ic = atomicCounterIncrement(indirectIndex);&#xA;    meshIndices[ic*3+0] = i0;&#xA;    meshIndices[ic*3+1] = i1;&#xA;    meshIndices[ic*3+2] = i2;&#xA;    atomicCounterIncrement(indirectIndexCount);&#xA;    atomicCounterIncrement(indirectIndexCount);&#xA;    atomicCounterIncrement(indirectIndexCount);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Both &lt;code&gt;indirectIndex&lt;/code&gt; and &lt;code&gt;indirectIndexCount&lt;/code&gt; are initialized to 0 and &lt;code&gt;indirectIndexCount&lt;/code&gt; is what is passed through to  &lt;code&gt;glDrawElementsIndirect&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2015-10-13T14:44:20.010" LastActivityDate="2015-10-13T14:44:20.010" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1618" PostTypeId="1" AcceptedAnswerId="1619" CreationDate="2015-10-14T16:51:06.533" Score="12" ViewCount="396" Body="&lt;p&gt;My raytracer supports a wide variety of objects.  To intersect them, I use the standard technique of transforming rays into object-space.  This works fantastically until I add motion blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I model motion blur as a sequence of transforms (to simplify discussion, let's say exactly two) instead of one.  My approach is to take the inverse transform of the ray at both keyframes and lerp the positions/directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems to work fine for translations, but it breaks down for rotations.  E.g. here are two triangles undergoing 30 and 90 degree rotations:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DRHf1.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DRHf1.png&quot; alt=&quot;rotation1&quot;&gt;&lt;/a&gt;&lt;br/&gt;&#xA;&lt;sup&gt;(4 samples, MN reconstruction, the red samples came from near the two keyframes)&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the corners, I would expect the lerped samples to lie on a straight line between the the two vertices.  Instead, they bulge outward.  This is wrong.  In more interesting scenes with more interesting transformations, it causes a variety of failure modes.  E.g. here's a propeller undergoing a 45 rotation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8kcIi.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8kcIi.png&quot; alt=&quot;rotation 2&quot;&gt;&lt;/a&gt;&lt;br/&gt;&#xA;&lt;sup&gt;(100 samples, normals visualized)&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some problems are due to the BVH breaking (it assumes the extrema of objects lie at keyframes), but even a brute force render is incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can fix all this by doing forward transforms only (transform object, not the ray), but this only works for objects where that is possible (only triangles, really).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How can I make my raytracer produce linear approximations to transformation (especially rotation) by transforming rays, not objects?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="523" LastEditorUserId="523" LastEditDate="2015-10-14T20:56:33.537" LastActivityDate="2015-10-14T20:56:33.537" Title="Ray Transformation to Object Space for Motion Blur" Tags="&lt;raytracing&gt;&lt;transformations&gt;&lt;motion&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1619" PostTypeId="2" ParentId="1618" CreationDate="2015-10-14T17:48:09.203" Score="7" Body="&lt;p&gt;Lerping the ray positions/directions between keyframes should be equivalent to lerping the inverse matrices between keyframes and transforming by the lerped matrix. Trouble is, if the keyframes have different rotations, that lerped matrix will in general be something &quot;weird&quot;, with shearing, nonuniform scale, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wouldn't be surprised if some of your intersection and shading routines don't work properly in such a distorted coordinate system, unless you've specifically tested and hardened them against such cases. (For example, taking the dot product of two unit vectors doesn't give the same answer in a sheared coordinate system as in an orthonormal one.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is just a guess, but it might work better if you choose an interpolation method where the translation, rotation, and scale (if applicable) are lerped separately (using quaternions for the rotation part) and re-combined.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-10-14T17:48:09.203" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1620" PostTypeId="2" ParentId="1618" CreationDate="2015-10-14T17:56:16.040" Score="3" Body="&lt;p&gt;I don't think you'll get terribly far with, AFAICS, a single linear approximation to a rather non-linear interpolation, but perhaps this &lt;a href=&quot;http://fileadmin.cs.lth.se/graphics/research/papers/2013/highorder/&quot; rel=&quot;nofollow&quot;&gt;paper / presentation&lt;/a&gt; by Gribel et al on motion blur in rasterisation may help.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2015-10-14T17:56:16.040" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1621" PostTypeId="2" ParentId="1606" CreationDate="2015-10-14T18:02:21.180" Score="5" Body="&lt;p&gt;The hint with the perspective division was already &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1607/127&quot;&gt;mentioned by ratchet freak&lt;/a&gt;, but I'd like to add some explanation of how to come up with the solution.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;First of all, remember that homogenous coordinates add a fourth value $w$ to your 3D vector. For points in the 3D space, $w \neq 0$ holds and $[x, y, z, w] = [n*x, n*y, n*z, n*w]$ also holds for every $n$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the goal is to find a transformation matrix $T$, which solves&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;    \begin{bmatrix} \frac{2}{x + y} \\ \frac{5y + z}{2x + 2y} \\ 3 \\ 1 \end{bmatrix}&#xA;= T \cdot &#xA;\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}&#xA;=&#xA;\begin{bmatrix} t_{11} &amp;amp; t_{21} &amp;amp; t_{31} &amp;amp; t_{41}  \\ t_{12} &amp;amp; t_{22} &amp;amp; t_{32} &amp;amp; t_{42} \\ t_{13} &amp;amp; t_{23} &amp;amp; t_{33} &amp;amp; t_{43} \\ t_{14} &amp;amp; t_{24} &amp;amp; t_{34} &amp;amp; t_{44} \end{bmatrix}&#xA;\cdot \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These are basically four equations, but having a look at the first row, being&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac{2}{x + y} = t_{11}\cdot x + t_{21}\cdot y + t_{31} \cdot z + t_{41}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and trying to find values for the $t$s, you'll see that this is not possible without further restructuring. The main problems are the $x$ and $y$ in the denominator. But as we can make use of the fourth value in the vector, we can expand the $w$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix} \frac{2}{x + y} \\ \frac{5y + z}{2x + 2y} \\ 3 \\ 1 \end{bmatrix}&#xA;=&#xA;\begin{bmatrix} \frac{2}{x + y} \\ \frac{2.5y + 0.5z}{x + y} \\ 3 \\ 1 \end{bmatrix}&#xA;=&#xA;\begin{bmatrix} 2 \\ 2.5y + 0.5z \\ 3(x + y) \\ x + y \end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first step, I removed the factor of $2$ from the second values denominator, leading to every values denominator either being $1$ or $(x + y)$. In the second step, I made use of the above mentioned rule ($[x, y, z, w] = [n\cdot x, n\cdot y, n\cdot z, n\cdot w]$), setting $n = (x + y)$, thus eliminating the denominator of the first two values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we've got&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix} 2 \\ 2.5y + 0.5z \\ 3(x + y) \\ x + y \end{bmatrix}&#xA;=&#xA;\begin{bmatrix} t_{11} &amp;amp; t_{21} &amp;amp; t_{31} &amp;amp; t_{41}  \\ t_{12} &amp;amp; t_{22} &amp;amp; t_{32} &amp;amp; t_{42} \\ t_{13} &amp;amp; t_{23} &amp;amp; t_{33} &amp;amp; t_{43} \\ t_{14} &amp;amp; t_{24} &amp;amp; t_{34} &amp;amp; t_{44} \end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is not that hard anymore.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix} 2 \\ 2.5y + 0.5z \\ 3(x + y) \\ x + y \end{bmatrix}&#xA;=&#xA;\begin{bmatrix} 0  &amp;amp;  0 &amp;amp;   0  &amp;amp;  2   \\ 0 &amp;amp;  2.5 &amp;amp; 0.5 &amp;amp;  0 \\ 3 &amp;amp;   3  &amp;amp;  0 &amp;amp;   0 \\ 1  &amp;amp;  1  &amp;amp;  0  &amp;amp;  0 \end{bmatrix}&#xA;\cdot&#xA;\begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2&gt;TL;DR&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Remember the advantage of homogenous coordinates $w$.&lt;/li&gt;&#xA;&lt;li&gt;$[x, y, z, w] = [n\cdot x, n\cdot y, n\cdot z, n\cdot w]$ is the key.&lt;/li&gt;&#xA;&lt;li&gt;Push everything that's in the denominator to the $w$ coordinate.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="127" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-11-03T15:32:59.350" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1622" PostTypeId="1" AcceptedAnswerId="1643" CreationDate="2015-10-15T07:33:36.113" Score="5" ViewCount="358" Body="&lt;p&gt;I'm trying to learn GLSL, I'm following &lt;a href=&quot;https://www.youtube.com/playlist?list=PLRwVmtr-pp06qT6ckboaOhnm9FxmzHpbY&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; tutorial. I've done everything according to the tutorials but I can't get any output from my code. As you see I'm checking for both compile errors and linker errors and everything is fine, GLSL code compiles and links fine but there is no output but a red window. Here is my code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;main.cpp &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;QApplication&amp;gt;&#xA;#include &amp;lt;GlWindow.h&amp;gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;int main(int argc, char *argv[]){&#xA;    QApplication app(argc, argv);&#xA;&#xA;    GlWindow glWindow;&#xA;    glWindow.show();&#xA;&#xA;    return app.exec();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;GLWindow.h&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifndef GLWINDOW_H&#xA;#define GLWINDOW_H&#xA;#include &amp;lt;QtOpenGL/QGLWidget&amp;gt;&#xA;#include &amp;lt;QOpenGLWidget&amp;gt;&#xA;&#xA;class GlWindow : public QGLWidget{&#xA;public:&#xA;&#xA;protected:&#xA;    void initializeGL();&#xA;    void paintGL();&#xA;};&#xA;&#xA;#endif // GLWINDOW_H&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;GLWindow.cpp&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;GL/glew.h&amp;gt;&#xA;#include &quot;GlWindow.h&quot;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;extern const char* vertexShaderCode;&#xA;extern const char* fragmentShaderCode;&#xA;&#xA;void sendDataToOpenGL(){&#xA;    GLfloat verts[] = {&#xA;        +0.0f, +0.0f,&#xA;             1.0f, 0.0f, 0.0f,&#xA;        +1.0f, +1.0f,&#xA;             1.0f, 0.0f, 0.0f,&#xA;        -1.0f, +1.0f,&#xA;             1.0f, 0.0f, 0.0f,&#xA;        -1.0f, -1.0f,&#xA;             1.0f, 0.0f, 0.0f,&#xA;        +1.0f, -1.0f,&#xA;             1.0f, 0.0f, 0.0f,&#xA;&#xA;    };&#xA;&#xA;    GLuint verexBufferID;&#xA;    glGenBuffers(1, &amp;amp;verexBufferID);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, verexBufferID);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(verts), verts, GL_STATIC_DRAW);&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0,2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5,0);&#xA;    glEnableVertexAttribArray(1);&#xA;    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 5, (char*)(sizeof(GLfloat) * 2));&#xA;&#xA;    GLuint indices [] = {0,1,2, 0,3,4};&#xA;    GLuint indexBufferID;&#xA;    glGenBuffers(1,&amp;amp;indexBufferID);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);&#xA;}&#xA;&#xA;&#xA;bool checkShaderStatus(GLuint shaderID){&#xA;    GLint compileStatus;&#xA;    glGetShaderiv(shaderID, GL_COMPILE_STATUS, &amp;amp;compileStatus);&#xA;&#xA;&#xA;    if(compileStatus != GL_TRUE){&#xA;        std::cerr&amp;lt;&amp;lt;&quot;failed&quot;&amp;lt;&amp;lt;std::endl;&#xA;        GLint infoLogLength;&#xA;        glGetShaderiv(shaderID, GL_INFO_LOG_LENGTH, &amp;amp;infoLogLength);&#xA;        GLchar* buffer = new GLchar [infoLogLength];&#xA;&#xA;        GLsizei bufferSize;&#xA;        glGetShaderInfoLog(shaderID, infoLogLength, &amp;amp;bufferSize, buffer);&#xA;        std::cout&amp;lt;&amp;lt;buffer&amp;lt;&amp;lt;std::endl;&#xA;        return false;&#xA;        delete []buffer;&#xA;    }&#xA;    return true;&#xA;}&#xA;&#xA;bool checkProgramStatus(GLuint programID){&#xA;    GLint linkStatus;&#xA;    glGetProgramiv(programID, GL_LINK_STATUS, &amp;amp;linkStatus);&#xA;&#xA;&#xA;    if(linkStatus != GL_TRUE){&#xA;        std::cerr&amp;lt;&amp;lt;&quot;failed&quot;&amp;lt;&amp;lt;std::endl;&#xA;        GLint infoLogLength;&#xA;        glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &amp;amp;infoLogLength);&#xA;        GLchar* buffer = new GLchar [infoLogLength];&#xA;&#xA;        GLsizei bufferSize;&#xA;        glGetProgramInfoLog(programID, infoLogLength, &amp;amp;bufferSize, buffer);&#xA;        std::cout&amp;lt;&amp;lt;buffer&amp;lt;&amp;lt;std::endl;&#xA;        return false;&#xA;&#xA;        delete []buffer;&#xA;    }&#xA;    return true;&#xA;}&#xA;&#xA;&#xA;void installShaders(){&#xA;&#xA;    GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);&#xA;    GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);&#xA;&#xA;    const char *adapter[1];&#xA;    adapter[0] = vertexShaderCode;&#xA;&#xA;    glShaderSource(vertexShaderID, 1, adapter, 0);&#xA;    adapter[0] = fragmentShaderCode;&#xA;    glShaderSource(fragmentShaderID, 1, adapter, 0);&#xA;&#xA;&#xA;&#xA;    glCompileShader(vertexShaderID);&#xA;    glCompileShader(fragmentShaderID);&#xA;&#xA;    if(!checkShaderStatus(vertexShaderID)){&#xA;        std::cerr&amp;lt;&amp;lt;&quot;Sth wrong with vertex shader&quot;&amp;lt;&amp;lt;std::endl;&#xA;        return;&#xA;    }&#xA;&#xA;    if(!checkShaderStatus(fragmentShaderID)){&#xA;       std::cerr&amp;lt;&amp;lt;&quot;Sth wrong with fragment shader&quot;&amp;lt;&amp;lt;std::endl;&#xA;       return;&#xA;    }&#xA;&#xA;&#xA;    GLuint programID = glCreateProgram();&#xA;    glAttachShader(programID, vertexShaderID);&#xA;    glAttachShader(programID, fragmentShaderID);&#xA;&#xA;    glLinkProgram(programID);&#xA;&#xA;    if(!checkProgramStatus(programID)){&#xA;        std::cerr&amp;lt;&amp;lt;&quot;failed to link&quot;&amp;lt;&amp;lt;std::endl;&#xA;        return;&#xA;    }&#xA;&#xA;    glUseProgram(programID);&#xA;}&#xA;&#xA;void GlWindow::paintGL(){&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    glClearColor(1.0f, 0.0f, 0.0f, 1.0f);&#xA;    glViewport(0,0,width(), height());&#xA;&#xA;    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0);&#xA;&#xA;}&#xA;&#xA;&#xA;void GlWindow::initializeGL(){&#xA;    glewInit();&#xA;&#xA;    const GLubyte *shaderVersion = glGetString(GL_SHADING_LANGUAGE_VERSION);&#xA;    std::cout&amp;lt;&amp;lt;shaderVersion&amp;lt;&amp;lt;std::endl;&#xA;&#xA;    sendDataToOpenGL();&#xA;    installShaders();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and finally my shader code: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const char* vertexShaderCode  =&#xA;        &quot;#version 430\r\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;in layout(location=0) vec2 position;\n&quot;&#xA;        &quot;in layout(location=1) vec3 vertexColor;\n&quot;&#xA;        &quot;&quot;&#xA;        &quot;out vec3 theColor;\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;void main()\n&quot;&#xA;        &quot;{\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;gl_Position = vec4(position, 0.0, 1.0);\n&quot;&#xA;        &quot;theColor = vertexColor; \n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;}\n&quot;&#xA;        ;&#xA;&#xA;&#xA;const char* fragmentShaderCode =&#xA;        &quot;#version 430\r\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;out vec4 daColor;\n&quot;&#xA;        &quot;in vec3 theColor;\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot;void main()\n&quot;&#xA;        &quot;{\n&quot;&#xA;        &quot;\n&quot;&#xA;        &quot; daColor = vec4(theColor,1.0);\n&quot;&#xA;        &quot;}\n&quot;&#xA;        ;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I know that my shader code looks stupid but I'm just trying to learn. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; I don't know if thats relevant, but I'm using Ubuntu 15.0 and &lt;code&gt;glGetString(GL_SHADING_LANGUAGE_VERSION)&lt;/code&gt; returns: &lt;code&gt;4.4 nvidia via cg compiler&lt;/code&gt;.  &lt;/p&gt;&#xA;" OwnerUserId="1861" LastEditorUserId="127" LastEditDate="2015-10-15T15:12:19.413" LastActivityDate="2015-10-20T21:21:24.110" Title="Can't get output from a GLSL code" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1623" PostTypeId="1" CreationDate="2015-10-15T08:06:54.277" Score="13" ViewCount="118" Body="&lt;p&gt;Spherical harmonics appear in several computer graphics techniques.&#xA;I feel that in order to be a better computer graphics developer, I need to have a deep understanding of what they are and how they are used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems that the reference most often recommended to understand Spherical Harmonics is &lt;a href=&quot;http://www.ppsloan.org/publications/StupidSH36.pdf&quot;&gt;&quot;Stupid Spherical Harmonics Tricks&quot; by Peter-Pike Sloan&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I started reading it but did not find a &quot;satisfying&quot; definition of SH, it seems like the document mostly relies on other references for the &quot;basics&quot;.&#xA;Other references introduce the Fourier Basis functions as a &quot;simpler version&quot; of SH, but once again it seems hard to find good material explaining them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are thorough, accessible references to understand Fourier basis functions and Spherical Harmonics ?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2015-10-16T06:07:31.000" Title="Thorough, accessible material about Fourier basis functions and Spherical Harmonics?" Tags="&lt;mathematics&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1624" PostTypeId="1" CreationDate="2015-10-15T09:09:14.390" Score="1" ViewCount="41" Body="&lt;p&gt;So I need to print out &lt;a href=&quot;https://www.myminifactory.com/object/engine-1406&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; model, however with default sizes, one of the pieces is too large for my printer (M3D). I will need to scale it down.. the question is, do I need to scale the rest of the individual objects (pieces) in the same proportions, so I will be able to assemble all the parts afterwards ? This might be a bit of a stupid question, but I don't have any experience with 3D printing yet.. thank you.&lt;/p&gt;&#xA;" OwnerUserId="1863" LastActivityDate="2015-10-15T11:16:19.893" Title="Scaling models for 3D print" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2015-10-16T20:22:49.063" ContentLicense="CC BY-SA 3.0" />
  <row Id="1625" PostTypeId="2" ParentId="1624" CreationDate="2015-10-15T11:16:19.893" Score="1" Body="&lt;p&gt;Just like for any reduction or drawing, if you scale one part and not the other, their relative proportion is changed, so yes, aesthetic, matching, functionality are affected: scale everything in the same proportion. Nothing specific to 3D printing here.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2015-10-15T11:16:19.893" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1626" PostTypeId="1" CreationDate="2015-10-15T20:44:30.027" Score="8" ViewCount="312" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Sketchpad&quot;&gt;Scratchpad was a constraint-based graphics system.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does it mean  by a Constraint-based Graphics System?&lt;/p&gt;&#xA;" OwnerDisplayName="user464" LastEditorDisplayName="user246" LastEditDate="2019-01-26T19:46:45.933" LastActivityDate="2019-01-26T19:46:45.933" Title="What does it mean by a Constraint-based Graphics System?" Tags="&lt;terminology&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1627" PostTypeId="1" CreationDate="2015-10-15T22:31:29.023" Score="2" ViewCount="219" Body="&lt;p&gt;What is the basic difference between Radar Screen, PC CRT Monitor, and, Oscilloscope displays?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of them use CRT. So, what is the difference?&lt;/p&gt;&#xA;" OwnerDisplayName="user464" LastActivityDate="2015-10-16T21:05:01.800" Title="What is the basic difference between Radar Screen, CRT and Oscilloscope displays?" Tags="&lt;display-lists&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2015-10-16T20:22:59.230" ContentLicense="CC BY-SA 3.0" />
  <row Id="1628" PostTypeId="2" ParentId="1626" CreationDate="2015-10-16T02:54:45.827" Score="5" Body="&lt;p&gt;Sketchpad was a system that allowed you to draw simple shapes using lines and curves in 2D.  It maintained constraints between the shapes. For example, an endpoint of one line could be constrained to lie on another line. Also, as mentioned in the Wikipedia article, the user could set a fixed length for a line, or an angle between two connected lines. These constraints would be automatically applied by the system while editing the diagrams&amp;mdash;e.g., when moving one line, other lines would be adjusted to maintain the constraints.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-10-16T02:54:45.827" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1629" PostTypeId="2" ParentId="1623" CreationDate="2015-10-16T06:07:31.000" Score="4" Body="&lt;p&gt;wil, you largely have enough scholar background, you must have done Fourier and Laplace transforms in second year, and maybe in your engineering school again as part of signal processing classes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you read &quot;stupid tricks&quot; there is not much more you can do to find a condensed course at this point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second most famous paper that goes with SH for graphics is by Robin Green called &quot;the gritty details&quot;:&lt;br&gt;&#xA;&lt;strong&gt;&lt;a href=&quot;http://www.research.scea.com/gdc2003/spherical-harmonic-lighting.pdf&quot; rel=&quot;nofollow&quot;&gt;http://www.research.scea.com/gdc2003/spherical-harmonic-lighting.pdf&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the third most important is the one by Ramamoorthi (the original paper preceding &quot;&lt;a href=&quot;http://graphics.stanford.edu/papers/envmap/&quot; rel=&quot;nofollow&quot;&gt;An Efficient Representation for Irradiance Environment Maps&lt;/a&gt;&quot;), which was called &lt;a href=&quot;http://graphics.stanford.edu/papers/invlamb/josa.pdf&quot; rel=&quot;nofollow&quot;&gt;&lt;strong&gt;On the relationship between radiance and&#xA;irradiance: determining&#xA;the illumination from&#xA;images of a convex Lambertian object&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I think they mention somewhere that SH were previously most used by another science field, forgot which one, physics maybe, and that most of their base material came from these papers. So if you want to dig in the roots, you've got to pull out these mid last century references.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2015-10-16T06:07:31.000" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1630" PostTypeId="2" ParentId="1626" CreationDate="2015-10-16T15:13:25.457" Score="11" Body="&lt;p&gt;If you have a geometric drawing with measurements you can solve what the shape has to be. This is valuable for example in engineering as it allows you specify the requirements and the computer can then solve the constrained drawing via a solver. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/80tMB.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/80tMB.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Constraint solver in action, red constraints are fixed while blue ones are free to change.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are several ways how the solver might work, it could be a numeric nonlinear based on gradient descent. Or it can be fully algebraic. Usually its a gradient descent solver as this is easier to implement, and possibly faster.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-10-16T15:13:25.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1631" PostTypeId="2" ParentId="1627" CreationDate="2015-10-16T18:55:16.347" Score="4" Body="&lt;p&gt;At many places in CG hardwares and algorithms you have the choice between vector description and raster description. Oscilloscops, radar, lasers shows, plotting tables, laser cuts directly follow lines and curves; these are the vectorials devices. LCD, inkjet and laser printers, stereolithographic 3D printing, follow pixels and voxels; these are the raster devices. The CRT, but also some laser shows, use the oscilloscope technology to implement raster: the &quot;curve&quot; is a repeated Z narrowly sweeping the screen line after line, with intensity modulation making the &quot;pixels&quot;. Radars are indeed between this and pure vectors since rotation angle is swept. Details about various forms of radar display and oscilloscope is available on the &lt;a href=&quot;https://en.wikipedia.org/wiki/Radar_display&quot; rel=&quot;nofollow&quot;&gt;wikipedia page&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;( About representations, the vector/raster dichotomy corresponds to inkscape/illustrator vs gimp/photoshop, 3D meshes vs 3D voxels, list of lobes vs angular or SH decomposition, Lagrangian animation vs Eulerian animation, etc. )&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2015-10-16T21:05:01.800" LastActivityDate="2015-10-16T21:05:01.800" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1632" PostTypeId="1" AcceptedAnswerId="1635" CreationDate="2015-10-16T19:54:28.523" Score="7" ViewCount="1919" Body="&lt;p&gt;I am trying to sample from the Blinn-Phong BRDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For testing, I use a spherical light source (Lambertian emission) sitting on a specular plane.  Here's a reference image using energy-conserving Phong with exponent &lt;code&gt;30000&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/R3uLF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/R3uLF.png&quot; alt=&quot;Phong&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Notice that no energy is lost.  &lt;strong&gt;I would now like to achieve the same thing for Blinn-Phong&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my attempt (same exponent, but on Blinn-Phong BRDF):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xKlyz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xKlyz.png&quot; alt=&quot;Blinn-Phong&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, a substantial portion of energy is lost.  The normalization term I am using comes from &lt;a href=&quot;http://www.thetenthplanet.de/archives/255&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; and is $\frac{n+1}{2 \pi}$.  The problem is this is a &lt;em&gt;normalization&lt;/em&gt; term, not a &lt;em&gt;conservation&lt;/em&gt; term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe this is the expected result.  It is common in graphics to make BRDFs reflect less than the input amount of energy, as opposed to exactly the right amount, as this is usually less difficult.&lt;sup&gt;1, 2&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there a version that conserves all energy exactly?&lt;/li&gt;&#xA;&lt;li&gt;Iff not, can someone at least confirm this is expected?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;N.B. I am fairly confident this is not a ray generation/PDF issue.  These images were importance sampled using a method given in the PBRT book pg. 695 - pg. 699.  Moreover, a non-importance sampled version looks very similar (though I had to use a lower exponent to get it to converge fast enough, and it still took 10,000 s/p).&lt;/sub&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;sup&gt;1&lt;/sup&gt;This can be argued from a shadowing/masking argument on microfacets.  Unfortunately, it ignores multiple scattering.  The correct answer is somewhere in-between.&lt;/sub&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;sup&gt;2&lt;/sup&gt;Indeed, I had to derive the Phong conservation term myself.&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="523" LastEditorUserId="137" LastEditDate="2015-11-03T15:18:26.990" LastActivityDate="2015-11-03T15:18:26.990" Title="Energy Conservation for Blinn-Phong BRDF" Tags="&lt;raytracing&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1633" PostTypeId="1" AcceptedAnswerId="1634" CreationDate="2015-10-17T02:04:20.943" Score="6" ViewCount="357" Body="&lt;p&gt;In PC game development, after loading models, textures, shaders, etc in a loading screen, some games will render the models once to an off screen target to make sure the driver and gpu have done all the work required to keep there from being a hitch the first time the models render.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know how much that actually helps? Does it only affect certain cards and drivers?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-10-17T20:38:19.193" Title="Does prerendering actually help performance?" Tags="&lt;gpu&gt;&lt;real-time&gt;&lt;direct3d&gt;&lt;directx11&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1634" PostTypeId="2" ParentId="1633" CreationDate="2015-10-17T07:29:49.867" Score="11" Body="&lt;p&gt;As far as I know, this sort of thing is mainly about shader compilation. One of the main reasons why a game may experience hitches the first time something renders is that the shaders necessary to render it haven't finished compiling yet, and the driver has to finish that work before the frame can proceed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A little bit of background. When you write shaders in HLSL, you compile them with Microsoft's HLSL compiler (fxc.exe), which outputs a hardware-independent bytecode. When you call CreateVertexShader etc. in D3D, that bytecode gets passed to the underlying driver, which ultimately compiles it into the machine code for the specific GPU you're running on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This internal compilation step isn't trivial&amp;mdash;it's a full-blown optimizing compiler. So it can take a little while on a complicated shader. Because of this, when you call D3D's CreateVertexShader, the driver doesn't necessarily &lt;em&gt;finish&lt;/em&gt; compiling the shader right then and there; it may add it to a queue, then return control to the application. Meanwhile, a background thread (perhaps more than one) consumes the queue and compiles the shaders. (The driver may also have a disk cache of previously-compiled shaders, so that it doesn't have to redo all this work every time the game is launched.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This background-thread compilation means the main game thread can get on with other work, e.g. loading other data or building a scene graph or what-have-you, so it's generally a win for overall loading times. But the consequence of it is that the shaders may not all be finished compiling when the game starts rendering. Unfortunately, there is no way with DX11 and earlier APIs for the app to tell when the shaders are done. The best you can do is to render something with the shader&amp;mdash;this effectively makes the app wait for the compiler to finish. That's why games sometimes do this offscreen pre-rendering business.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't have any hard numbers handy, but qualitatively, one can reduce the impact of shader compilation by front-loading it during loading. Create all your shaders first, then the compiler will run through those while you load everything else. However, with real-time streaming  (e.g. open-world games) it can still be quite difficult to ensure no hitches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also worth noting that there are some cases where state changes can cause a shader recompile. Things like vertex buffer formats, render target formats, and shader linking details (e.g. re-using the same pixel shader with different vertex shaders, or with tessellation shaders) can potentially cause the driver to have to generate different versions of the shader under the hood. The details vary by vendor and hardware. This isn't necessarily a full from-scratch recompile&amp;mdash;often it's just sticking on some prologue or epilogue code&amp;mdash;but it's something to be aware of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is one place where the new APIs (DX12, Metal, and Vulkan) are in a good position to solve the problem. These APIs have &quot;pipeline state&quot; objects where all shader stages and all possibly relevant states are rolled up into a single object, and when you create one of these, the driver has all the information it needs to actually and completely finalize all the shaders. DX12 also makes shader caching explicit. Also, at least for NVIDIA DX12 drivers (I don't know about others), shader compilation is done fully inside the pipeline state creation method, and the app can use multiple threads itself in order to parallelize shader compilation and other work. So, the practice of offscreen pre-rendering to ensure shaders are finalized should no longer be necessary in DX12.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="504" LastEditDate="2015-10-17T20:38:19.193" LastActivityDate="2015-10-17T20:38:19.193" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1635" PostTypeId="2" ParentId="1632" CreationDate="2015-10-17T09:22:33.657" Score="9" Body="&lt;p&gt;First off, this is probably not the best way of testing energy conservation, because not all incident inclinations are visible in the image. Most of the environment is also black, so a less &quot;peaky&quot; BRDF such as Lambert would come out very dark with no way of telling whether it's energy conserving or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is more commonly used is a so-called &quot;furnace test&quot;, where you place a single sphere into a white environment map. When you render this sphere using the BRDF of interest, it should blend into the environment perfectly if the BRDF is energy conserving (make sure no color channels are clipping). Because it is a sphere, you will be able to see the BRDF at all incident inclinations. Additionally, the sphere is convex, so lacking any other objects in the scene, no reflected ray will be occluded, and every pixel of the sphere in the image will be an integral over the BRDF at a different inclination.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you did this test, you would also notice that your Phong BRDF is most likely not energy conserving. The commonly used normalization term of $\frac{n+1}{2 \pi}$ (or $\frac{n+2}{2 \pi}$, depending on who you ask) only holds at normal incidence. At other inclinations, and particularly at grazing angle, up to half of the reflected rays will land below the surface and are usually terminated (because transmitting through a reflective surface does not make sense).&lt;br&gt;&#xA;The correct normalization term that accounts for the part of the Phong lobe that is clipped below the hemisphere is very difficult to compute. Jim Arvo derived a closed-form solution for integer exponents using double-axis moments, summarised in the &lt;a href=&quot;http://people.cs.kuleuven.be/~philip.dutre/GI/TotalCompendium.pdf&quot; rel=&quot;nofollow&quot;&gt;Global Illumination Compendium&lt;/a&gt;, paragraph 31a) and 31b) (page 17/18). These formulas are not very practical for use in a renderer though and I don't suggest implementing them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It should be clear that if a simple model such as Phong is already this difficult to normalize, then Blinn-Phong is even more difficult. First of all, the $\frac{n+1}{2 \pi}$ normalization term you mention is only correct if you use Blinn-Phong as a microfacet distribution inside a full microfacet BRDF (e.g. Torrance-Sparrow or Walter). If you directly use the Blinn-Phong BRDF, then a more correct normalization term is $\frac{(n+2)(n+4)}{(8 \pi 2^{-n/2} + n)}$, derived in &lt;a href=&quot;http://www.farbrausch.de/~fg/stuff/phong.pdf&quot; rel=&quot;nofollow&quot;&gt;this short article&lt;/a&gt; by Fabian Giesen (second page) and also listed on the page you mention. However, this normalization term is again only correct at normal incidence and will not be exact at other inclinations. From what I can tell, no exact normalization term exists.&lt;/p&gt;&#xA;" OwnerUserId="79" LastEditorUserId="137" LastEditDate="2015-11-03T15:18:17.490" LastActivityDate="2015-11-03T15:18:17.490" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1636" PostTypeId="2" ParentId="1608" CreationDate="2015-10-18T06:09:20.450" Score="3" Body="&lt;p&gt;From math:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;There is a 2:1 homomorphism from the unit &lt;a href=&quot;https://en.wikipedia.org/wiki/Quaternion&quot; rel=&quot;nofollow&quot;&gt;quaternions&lt;/a&gt; to &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_group_SO%283%29&quot; rel=&quot;nofollow&quot;&gt;SO(3)&lt;/a&gt; (the rotation group).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What this (essentially) means is that:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Every orientation can be represented as a quaternion&lt;/li&gt;&#xA;&lt;li&gt;Quaternions represent a single rotation&lt;/li&gt;&#xA;&lt;li&gt;Multiplication of quaternions produces another quaternion (closure), and is equivalent to composing the rotations.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Therefore &lt;em&gt;any&lt;/em&gt; number of rotations can be represented as a single rotation!&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Think about that.  Starting from object space, you can rotate your object into &lt;em&gt;any&lt;/em&gt; orientation using only a &lt;em&gt;single&lt;/em&gt; rotation.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I would like to point out that bringing quaternions in wasn't just random math-ese.  In contrast to the other answers, the &lt;em&gt;favored&lt;/em&gt; approach in graphics is actually to represent rotations as quaternions, since they take up less space and are faster to combine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are easily-Googleable ways to convert between rotation matrices and quaternions, depending on which you prefer.  The point is that rotations &lt;em&gt;are&lt;/em&gt; the quaternions in a mathematical sense, so combinations thereof are also single rotations.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2015-10-18T06:09:20.450" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1637" PostTypeId="1" AcceptedAnswerId="1639" CreationDate="2015-10-19T04:39:43.037" Score="3" ViewCount="118" Body="&lt;p&gt;Given a 3D space and a light source, I use ray casting to determine the shadows generated in the scene. If I'm to store the shadow data (boundary of the shadow, object which cast the shadow, etc.) what is an efficient way to go about it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Its basically for an application where I want to be able to move the shadow around manually to see the change in the 3d objects position. Say I apply a force to the shadow of a ball, I can actually see the ball move and also the change in the shadow. So I need to be able to set up colliders for the shadow and hence need a way to be able to store the boundary of the shadow and information about the object that cast it to carry out the actions.&lt;/p&gt;&#xA;" OwnerUserId="1879" LastEditorUserId="1879" LastEditDate="2015-11-03T19:03:47.043" LastActivityDate="2015-11-03T19:03:47.043" Title="Storing shadow data" Tags="&lt;shadow-mapping&gt;&lt;shadow&gt;" AnswerCount="2" CommentCount="6" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1639" PostTypeId="2" ParentId="1637" CreationDate="2015-10-20T08:45:52.520" Score="3" Body="&lt;p&gt;If the goal is mouse interactivity, you can do with a simple &quot;shadow buffer&quot;, i.e. an image that holds the identity of the occluding object (if any) on every rendered pixel. You will compute this map during the casting process as you shoot the rays to the source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case there are several occluding objects, it is up to you to choose which one to consider (or keep a linked list of all occluding objects). If there are several sources, you can keep one map per source.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastActivityDate="2015-10-20T08:45:52.520" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1640" PostTypeId="1" AcceptedAnswerId="1642" CreationDate="2015-10-20T13:38:20.027" Score="5" ViewCount="1588" Body="&lt;p&gt;I've written an implementation of the sphere tracing algorithm in OpenGL 4+.&#xA;As an experiment/toy project, I'm re-implementing it using the OpenGL 4.3 compute shader, but I'm having trouble with the whole local/global invocation ID thing.&#xA;The basic idea is to use the compute shader to calculate the image and output it in a texture, then use a trivial program to copy it onto the framebuffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the compute shader I'm using:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (binding = 0, rgba32f) writeonly uniform image2D output_image;&#xA;layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;&#xA;&#xA;void main()&#xA;{&#xA;    ivec2 coord = ivec2(gl_GlobalInvocationID.xy);&#xA;    imageStore(output_image, coord, vec4(0.0, 0.0, 1.0, 1.0));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is how I initialize the texture:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint offscreen_texture;&#xA;glGenTextures(1, &amp;amp;offscreen_texture);&#xA;&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D, offscreen_texture);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, WINDOW_WIDTH, WINDOW_HEIGHT, 0, GL_RGBA, GL_FLOAT, nullptr);&#xA;glBindImageTexture(0, offscreen_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And these are the trivial vertex shader I'm using:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;void main()&#xA;{&#xA;    const vec4 verts[4] = vec4[4](vec4(-1.0, -1.0, 0.5, 1.0),&#xA;                                  vec4( 1.0, -1.0, 0.5, 1.0),&#xA;                                  vec4(-1.0,  1.0, 0.5, 1.0),&#xA;                                  vec4( 1.0,  1.0, 0.5, 1.0));&#xA;&#xA;    gl_Position = verts[gl_VertexID];&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And fragment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (location = 0) out vec4 color_out;&#xA;layout(binding = 0) uniform sampler2D source_image;&#xA;&#xA;void main()&#xA;{&#xA;    color_out = texture(source_image, gl_FragCoord.xy);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this is the render code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;compute_program.use();&#xA;glDispatchCompute(WINDOW_WIDTH / 16, WINDOW_HEIGHT / 16, 1);&#xA;glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);&#xA;&#xA;copy_program.use();&#xA;glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Up to this point everything works correctly and I see my screen completely blue instead of the usual clear color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things start to break down when I try to use the Invocation ID to generate actual data (like the rays from the camera).&#xA;I tried to switch to a compute shader like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (binding = 0, rgba32f) writeonly uniform image2D output_image;&#xA;layout (local_size_x = 16, local_size_y = 16, local_size_z = 1) in;&#xA;&#xA;void main()&#xA;{&#xA;    ivec2 coord = ivec2(gl_GlobalInvocationID.xy);&#xA;    imageStore(output_image, coord, vec4(0.0, 0.0, coord.x / 1280.0, 1.0));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which uses the global ID to generate the blue tint of the pixel.&#xA;As I understand from the OpenGL Suberbible book and the OpenGL wiki, I should be able to use the global ID as screen space coordinates (it's pretty easy to do the math using local IDs and work groups IDs and confirm that), much like gl_FragCoord, and this is confirmed by the previous trivial compute shader which paint every pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would expect a sort of horizontal gradient going from black to blue as an output of this compute shader, but instead everything turns black.&#xA;I've tried several combination of &quot;painting&quot; based on the local/global IDs of the threads, but I haven't got any luck no matter what.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Did I misunderstand the way the whole threads ID work?&#xA;What is the correct way to use them/map them to screen space coordinates like gl_FragCoord?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: Just to add, I've tested this with both my integrated Intel HD 5100 and my discrete Nvidia 765M GPUs and the result is the same, so there is clearly something wrong on my side.&lt;/p&gt;&#xA;" OwnerUserId="281" LastEditorUserId="6546" LastEditDate="2017-05-02T00:25:59.583" LastActivityDate="2017-05-02T00:25:59.583" Title="How to convert a thread ID into Screen Space Coord in an OpenGL Compute Shader?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;compute-shader&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1641" PostTypeId="1" CreationDate="2015-10-20T15:04:28.460" Score="9" ViewCount="1314" Body="&lt;p&gt;I would like to implement a Maya plugin (this question is independent from Maya) to create 3D Voronoi patterns, Something like &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8RYgU.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8RYgU.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I just know that I have to start from point sampling (I implemented the adaptive poisson sampling algorithm described in &lt;a href=&quot;http://link.springer.com/article/10.1007%2Fs11432-011-4322-8#/page-1&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought that, from those points, I should create the 3D wire of the mesh applying Voronoi (I tried to use (Python) scipy.spatial.Voronoi but the result was something different from what I expected).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am missing something? Can anyone suggest the proper pipeline and algorithms I have to implement to create such patterns?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[EDIT] Here are a few example of what I get handling the result i get from scipy.spatial.Voronoi like this (as suggested &lt;a href=&quot;https://stackoverflow.com/questions/23658776/voronoi-diagram-edges-how-to-get-edges-in-the-form-point1-point2-from-a-scip&quot;&gt;here&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vor = Voronoi(points)&#xA;for vpair in vor.ridge_vertices:&#xA;    for i in range(len(vpair) - 1):&#xA;        if all(x &amp;gt;= 0 for x in vpair):&#xA;            v0 = vor.vertices[vpair[i]]&#xA;            v1 = vor.vertices[vpair[i+1]]&#xA;            create_line(v0.tolist(), v1.tolist())&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The grey vertices are the sampled points (the original shape was a simple sphere):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/gz8hD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gz8hD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a more complex shape (an arm)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/mCkPm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mCkPm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1895" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-09-28T22:25:13.647" Title="Pipeline to create Voronoi Meshes" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="1642" PostTypeId="2" ParentId="1640" CreationDate="2015-10-20T20:06:11.753" Score="6" Body="&lt;p&gt;The problem is actually in your fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color_out = texture(source_image, gl_FragCoord.xy);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The texture() function accepts normalized coordinates which range from 0.0 to 1.0. The gl_FragCoord built in contains window coordinates which range from (0.0, 0.0) to (window width, window height).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this, change the fragment shader to this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color_out = texture(source_image, gl_FragCoord.xy / vec2(1280.0, 720.0));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That is assuming your window is 1280x720, change as necessary.&lt;/p&gt;&#xA;" OwnerUserId="40" LastActivityDate="2015-10-20T20:06:11.753" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1643" PostTypeId="2" ParentId="1622" CreationDate="2015-10-20T21:21:24.110" Score="3" Body="&lt;p&gt;There are two problems:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Your indices are unsigned integers (4 bytes per index) but the call to glDrawElements specifies GL_UNSIGNED_SHORT. You need to change this to GL_UNSIGNED_INT.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You are drawing two red triangles onto a buffer that has been cleared to red.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="40" LastActivityDate="2015-10-20T21:21:24.110" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1644" PostTypeId="1" CreationDate="2015-10-21T15:46:02.827" Score="2" ViewCount="450" Body="&lt;p&gt;Most information about memory mapped displays on the net are about those in which there is essentially a location in main memory for each pixel on the display. A hypothetical 1024 x 512 display would therefore have 524,288 locations each mapped to a unique pixel. To set a pixel to a particular color, all you basically need to do is write an RGB value into the corresponding memory location for that pixel, eg: MOV 0xFF3C0A, 0x00BB75. The first argument in that instruction is the address holding the RGB value and the second is the address of the pixel you are copying it to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this can use up a quite a lot of main memory, which might not be ideal for certain systems. In a machine with a 32 bit or higher word size, it could instead be possible to have a single &quot;display output register&quot; into which you would write a single word of data containing the X and Y coordinates as well as the RGB value for the pixel you want to set. For a 1024 x 512 display with a 12-bit color depth, 31 bits would suffice to specify all this. The data 'written' into that register would either be sent to a display adapter or sent directly to the display and decoded there. This would save over half a megabyte of memory while still retaining the memory-mapped model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is this actually a thing or not?&lt;/p&gt;&#xA;" OwnerUserId="1902" LastActivityDate="2015-10-23T17:33:02.260" Title="Does this type of memory-mapping for a display exist?" Tags="&lt;pixels&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1648" PostTypeId="2" ParentId="1644" CreationDate="2015-10-23T17:26:14.500" Score="2" Body="&lt;p&gt;In your 31 bit solution, the thing most likely to happen there is that you'd give an extra bit to green and make a 32 bit solution.  In 16 bit color for instance, r and b get 5 bits while g gets 6 bits, because your eye can distinguish more greens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or maybe you'd use that extra bit to have 1 bit alpha? Not sure if that'd be very useful though...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as the rest, whether you have a gpu or not, writing to single pixels at a time is bad form.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, you ideally want to do block operations that either fill or copy large strips of memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For some things, like alpha blending, that isn't able to be done as a block operation very easily so is a more expensive operation in general.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a solution to this, modern computers have a processor that is closer to the video memory, so there isn't too much latency when pushing pixels back and forth across the main bus to do things like calculate alpha blended values involving the source and destination pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, instead of fewer more powerful cores, there are many less powerful cores, which helps address the situation of needing &quot;one off&quot; pixel operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That processor I'm referring to is the gpu and the programs you write for it are called shaders (;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you are asking about doesn't exist to my knowledge and seems like a bad usage pattern, so seems unlikely to exist IMO.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-10-23T17:33:02.260" LastActivityDate="2015-10-23T17:33:02.260" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1649" PostTypeId="1" AcceptedAnswerId="1650" CreationDate="2015-10-24T02:42:58.883" Score="4" ViewCount="773" Body="&lt;p&gt;I'm playing around with directX 12 and I'm having some problems loading geometry in. I have a std::vector vertices definition and I do exactly what the dx12 template does with it.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  const UINT vertexBufferSize = sizeof(vertices);&#xA;&#xA;  // Create the vertex buffer resource in the GPU's default heap and copy vertex data into it using the upload heap.&#xA;  // The upload resource must not be released until after the GPU has finished using it.&#xA;  Microsoft::WRL::ComPtr&amp;lt;ID3D12Resource&amp;gt; vertexBufferUpload;&#xA;&#xA;  CD3DX12_HEAP_PROPERTIES defaultHeapProperties(D3D12_HEAP_TYPE_DEFAULT);&#xA;  CD3DX12_RESOURCE_DESC vertexBufferDesc = CD3DX12_RESOURCE_DESC::Buffer(vertexBufferSize);&#xA;  DX::ThrowIfFailed(d3dDevice-&amp;gt;CreateCommittedResource(&#xA;     &amp;amp;defaultHeapProperties,&#xA;     D3D12_HEAP_FLAG_NONE,&#xA;     &amp;amp;vertexBufferDesc,&#xA;     D3D12_RESOURCE_STATE_COPY_DEST,&#xA;     nullptr,&#xA;     IID_PPV_ARGS(&amp;amp;mVertexBuffer)));&#xA;&#xA;  CD3DX12_HEAP_PROPERTIES uploadHeapProperties(D3D12_HEAP_TYPE_UPLOAD);&#xA;  DX::ThrowIfFailed(d3dDevice-&amp;gt;CreateCommittedResource(&#xA;     &amp;amp;uploadHeapProperties,&#xA;     D3D12_HEAP_FLAG_NONE,&#xA;     &amp;amp;vertexBufferDesc,&#xA;     D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;     nullptr,&#xA;     IID_PPV_ARGS(&amp;amp;vertexBufferUpload)));&#xA;&#xA;  mVertexBuffer-&amp;gt;SetName(L&quot;Vertex Buffer Resource&quot;);&#xA;  vertexBufferUpload-&amp;gt;SetName(L&quot;Vertex Buffer Upload Resource&quot;);&#xA;&#xA;  // Upload the vertex buffer to the GPU.&#xA;  {&#xA;     D3D12_SUBRESOURCE_DATA vertexData = {};&#xA;     vertexData.pData = reinterpret_cast&amp;lt;BYTE*&amp;gt;(vertices.data());&#xA;     vertexData.RowPitch = vertexBufferSize;&#xA;     vertexData.SlicePitch = vertexData.RowPitch;&#xA;&#xA;     UpdateSubresources(mCommandList.Get(), mVertexBuffer.Get(), vertexBufferUpload.Get(), 0, 0, 1, &amp;amp;vertexData);&#xA;&#xA;     CD3DX12_RESOURCE_BARRIER vertexBufferResourceBarrier =&#xA;        CD3DX12_RESOURCE_BARRIER::Transition(mVertexBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);&#xA;     mCommandList-&amp;gt;ResourceBarrier(1, &amp;amp;vertexBufferResourceBarrier);&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this is what I get in the graphics debugger when it was suppossed to be a sphere. I can confirm that the data in vertices is correct.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/a6cL7.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a6cL7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I change vertices to be what the template code had it works and renders the default cube. The only real difference mine is using a vector instead of an array.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;VertexPositionColor cubeVertices[] =&#xA;{&#xA;    { XMFLOAT3(-0.5f, -0.5f, -0.5f), XMFLOAT3(0.0f, 0.0f, 0.0f) },&#xA;    { XMFLOAT3(-0.5f, -0.5f,  0.5f), XMFLOAT3(0.0f, 0.0f, 1.0f) },&#xA;    { XMFLOAT3(-0.5f,  0.5f, -0.5f), XMFLOAT3(0.0f, 1.0f, 0.0f) },&#xA;    { XMFLOAT3(-0.5f,  0.5f,  0.5f), XMFLOAT3(0.0f, 1.0f, 1.0f) },&#xA;    { XMFLOAT3(0.5f, -0.5f, -0.5f), XMFLOAT3(1.0f, 0.0f, 0.0f) },&#xA;    { XMFLOAT3(0.5f, -0.5f,  0.5f), XMFLOAT3(1.0f, 0.0f, 1.0f) },&#xA;    { XMFLOAT3(0.5f,  0.5f, -0.5f), XMFLOAT3(1.0f, 1.0f, 0.0f) },&#xA;    { XMFLOAT3(0.5f,  0.5f,  0.5f), XMFLOAT3(1.0f, 1.0f, 1.0f) },&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="113" LastActivityDate="2016-01-16T16:32:24.677" Title="Dx12 Vertex Buffer incorrect" Tags="&lt;directx12&gt;&lt;vertex-buffer-object&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1650" PostTypeId="2" ParentId="1649" CreationDate="2015-10-24T03:58:23.510" Score="5" Body="&lt;p&gt;Vector has a few different semantics from static arrays. For one it's a struct containing a pointer a capacity and a length (at the very least). That means that &lt;code&gt;sizeof&lt;/code&gt; will not reflect how much data is actually stored in there (that only works on static arrays).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need to get the size in bytes of the data then you need&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const UINT vertexBufferSize = sizeof(vertices::value_type) * vertices.size();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2016-01-16T16:32:24.677" LastActivityDate="2016-01-16T16:32:24.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1651" PostTypeId="1" AcceptedAnswerId="1652" CreationDate="2015-10-24T15:06:21.040" Score="9" ViewCount="2646" Body="&lt;p&gt;I'd like to &quot;hook&quot; into a running game, say Mario Bros, and capture each frame rendered... saving that frame to an image file. A good example of something similar is FRAPS. --Note: I don't want to capture the whole screen/desktop. I want to capture a targeted window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have had a look at &lt;a href=&quot;https://obsproject.com/&quot; rel=&quot;noreferrer&quot;&gt;OBS&lt;/a&gt; (Open Broadcasting Software) but it is not particularly fast. Don't get me wrong, it's great software, but unfortunately there is no/poor documentation, making a massive project written in c and c++ nearly inaccessible for a new-to-c++ programmer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also had a look at &lt;a href=&quot;http://gaminganywhere.org/perf.html&quot; rel=&quot;noreferrer&quot;&gt;GamingAnywhere&lt;/a&gt;, but unfortunately, I am unable to get it to work, there is very little/no documentation, runs in VS2010 only and is messy (with poor variable naming). However, it is a research project and so it is understandably undocumented and messy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that this can be done with OpenGL, GDI and with Direct3D, but I am unable to find some good examples on the net. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read that glReadlPixels (using OpenGL) can be used and I've read the &lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glReadPixels.xml&quot; rel=&quot;noreferrer&quot;&gt;documentation&lt;/a&gt;, but the post mentioned nothing about hooking into a running game/application graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Questions:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Can I hook into the graphics of a game developed with OpenGL, using,&#xA;say, Direct3D? Does the library used for hooking have to be the same&#xA;as the one used by the game?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How do I hook into the game's rendered frames so that I can output&#xA;those frames to image files or to a video file? (Just some links or&#xA;brief explanation of what I need to do would be great)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;BackBuffer - I read that it is very fast accessing the BackBuffer to&#xA;retrieve the frames. Does someone have an example for me on how to&#xA;do this with the latest libraries? I have found that most examples&#xA;are out of date.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;For my purposes, is there any clearly &quot;this is faster than that&quot;? What I mean is, would, say, OpenGL, be faster for my purposes? &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;If someone knows of an open-source project (that does essentially what I need) that is actively developed and well documented, I'd love to know about it.&lt;/p&gt;&#xA;" OwnerUserId="1800" LastEditorUserId="1800" LastEditDate="2015-10-25T17:07:58.357" LastActivityDate="2015-10-25T17:07:58.357" Title="Screen capture of game video" Tags="&lt;opengl&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1652" PostTypeId="2" ParentId="1651" CreationDate="2015-10-24T17:49:58.717" Score="9" Body="&lt;p&gt;It is possible to do what you describe, but I'm afraid it is not a trivial process. Actually, this will be very tied to the Operating Systems you are targeting and possibly also requiring specific tweaks for the given game/application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would start looking into &lt;a href=&quot;https://en.wikipedia.org/wiki/DLL_injection&quot;&gt;DLL injection&lt;/a&gt; techniques, which should allow, for instance, intercepting calls to the Direct3D (Windows) or OpenGL APIs, which you can then use to copy de framebuffers of the application. A quick Internet search turns up &lt;a href=&quot;http://blog.opensecurityresearch.com/2013/01/windows-dll-injection-basics.html&quot;&gt;this&lt;/a&gt; and &lt;a href=&quot;http://www.evilsocket.net/2015/05/01/dynamically-inject-a-shared-library-into-a-running-process-on-androidarm/&quot;&gt;this&lt;/a&gt; with detailed explanation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I once wrote a small-scale OpenGL interceptor on MacOS by injecting a custom shared module, but it was under very controlled circumstances and making a lot of assumptions, such as having root privileges in the system, so for a production tool, it would be a lot more complicated. You can find another very interesting project &lt;a href=&quot;https://graphics.stanford.edu/~mdfisher/D3D9Interceptor.html&quot;&gt;here&lt;/a&gt; about intercepting the D3D API to install an automated AI bot on Starcraft, which should touch on very similar concepts to what you are looking for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you manage to intercept the underlying rendering API, you could then perhaps hook your code into each &lt;code&gt;SwapBuffers&lt;/code&gt; or equivalent call to just copy the previous framebuffer before the swap, then save it (this is where something like &lt;code&gt;glReadPixels&lt;/code&gt; would come into play).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Copying and saving the framebuffer in an efficient manner is also challenging. The easy way is to just dump each frame as an uncompressed RGB image, but then you'll wind up with hundreds of gigabytes of data for just a couple of minutes of gameplay, so unless you have a nice HDD array sitting at the corner of your table &lt;code&gt;;)&lt;/code&gt;, you'll need to look into compressing the frames somehow. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The downside of compressing the frames now is that it takes a lot of processing, so a naive approach might turn the once interactive application you are trying to record into an interactive slide-show &lt;code&gt;:(&lt;/code&gt;. So at this stage you'd have to start thinking about optimizations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't know of any projects out there providing a library for efficient frame capture for games, but this would certainly be something nice to have! I think one thing that might be holding such project back is, like I mentioned at the beginning, that this is a very system dependent thing, so cases of use will most likely be limited to a single platform or OS.&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="54" LastEditDate="2015-10-24T17:57:52.740" LastActivityDate="2015-10-24T17:57:52.740" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="1656" PostTypeId="1" AcceptedAnswerId="1659" CreationDate="2015-10-25T21:03:06.477" Score="4" ViewCount="507" Body="&lt;p&gt;I'm trying to use &lt;code&gt;glMultiDrawArraysIndirect&lt;/code&gt; to render a batch of object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my example I have a cube and a sphere &lt;strong&gt;(in this order)&lt;/strong&gt; in a &lt;code&gt;VBO&lt;/code&gt; and a &lt;code&gt;GL_SHADER_STORAGE_BUFFER (SSBO)&lt;/code&gt; that contains matrix transforms as well as a &lt;code&gt;GL_DRAW_INDIRECT_BUFFER (DIB)&lt;/code&gt; that contains the draw commands.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The allocation of both the &lt;code&gt;SSBO&lt;/code&gt; and &lt;code&gt;DIB&lt;/code&gt; are managed by a custom class.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can currently render both objects successfully, each using their own transform. The problem I'm encountering is rendering just the sphere by specifying an offset. As per the OpenGL spec:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If a buffer is bound to the &lt;code&gt;GL_DRAW_INDIRECT_BUFFER&lt;/code&gt; binding at the&#xA;  time of a call to &lt;strong&gt;glMultiDrawArraysIndirect&lt;/strong&gt;, &lt;em&gt;indirect&lt;/em&gt; is interpreted&#xA;  as an offset, in basic machine units, into that buffer and the&#xA;  parameter data is read from the buffer rather than from client memory.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;but doing the following code to render results in nothing being rendered:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Calculates the offset &amp;amp; size and calls BindBufferRange &#xA;this-&amp;gt;_indrMatrixBuffer.BindBufferRange(0, 1, 1);&#xA;// A simple call to glBindBuffer, binding to GL_DRAW_INDIRECT_BUFFER&#xA;this-&amp;gt;_indrBuffer.BindBuffer();&#xA;// Render&#xA;glMultiDrawArraysIndirect(GL_TRIANGLES, (void*)sizeof(DAICmd), 1, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;The &lt;code&gt;DAICmd&lt;/code&gt; is a struct of four &lt;code&gt;unsigned int&lt;/code&gt; (as per the &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glMultiDrawArraysIndirect.xhtml&quot; rel=&quot;nofollow&quot;&gt;spec&lt;/a&gt;)&lt;/sub&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At first I though it might be my custom class but calling &lt;code&gt;glMultiDrawArraysIndirect(GL_TRIANGLES, 0, 1, 0);&lt;/code&gt; and keeping the matrix buffer offset renders the cube in the spheres position!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I missing to get this to work?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Extra notes&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Both the &lt;code&gt;SSBO&lt;/code&gt; &amp;amp; &lt;code&gt;DIB&lt;/code&gt; are mapped using the flags &lt;code&gt;GL_MAP_WRITE_BIT, GL_MAP_PERSISTENT_BIT and GL_MAP_COHERENT_BIT&lt;/code&gt; and are created with the same flags plus &lt;code&gt;GL_DYNAMIC_STORAGE_BIT&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;I'm using OpenGL 4.5&lt;/li&gt;&#xA;&lt;li&gt;Using &lt;code&gt;glMultiDrawArraysIndirect(GL_TRIANGLES, (void*)sizeof(DAICmd), 1, 0);&lt;/code&gt; does not produce an error when using &lt;code&gt;glGetError()&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Using KHR_debug produces no errors either&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="214" LastEditorUserId="214" LastEditDate="2015-10-26T09:10:22.040" LastActivityDate="2015-10-26T16:24:09.740" Title="glMultiDrawArraysIndirect does not work when specifying an offset" Tags="&lt;opengl&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1657" PostTypeId="1" CreationDate="2015-10-26T01:10:09.947" Score="2" ViewCount="130" Body="&lt;p&gt;3D math covers vector algebra and matrix algebra, which are easily calculated on paper, but not so easy when coding them effectively. I only leant some basic algorithms on matrix in my Data Structure course, which is not enough when it comes to accurate and effective operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some books on this topic?&lt;/p&gt;&#xA;" OwnerUserId="1886" LastActivityDate="2015-10-26T07:07:56.683" Title="Is there some book about how to design a 3D math lib?" Tags="&lt;algorithm&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2015-10-28T05:37:33.750" ContentLicense="CC BY-SA 3.0" />
  <row Id="1658" PostTypeId="2" ParentId="1657" CreationDate="2015-10-26T06:33:58.150" Score="3" Body="&lt;p&gt;Books: &lt;a href=&quot;http://www.essentialmath.com/book.htm&quot; rel=&quot;nofollow&quot;&gt;http://www.essentialmath.com/book.htm&lt;/a&gt; is the one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best algos on the real 3D topics (and some tricky 2D like image resize and premult-alpha ), explained and with source most of the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The website is very nice too, the &quot;tutorial&quot; full of gems&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Adding &lt;a href=&quot;http://www.geometrictools.com/index.html&quot; rel=&quot;nofollow&quot;&gt;http://www.geometrictools.com/index.html&lt;/a&gt; which is the most complete source code repository on the topic, with loads of very precise algos implemented.&lt;/p&gt;&#xA;" OwnerUserId="212" LastEditorUserId="212" LastEditDate="2015-10-26T07:07:56.683" LastActivityDate="2015-10-26T07:07:56.683" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1659" PostTypeId="2" ParentId="1656" CreationDate="2015-10-26T16:24:09.740" Score="2" Body="&lt;p&gt;The problem was my class handling the population fo the &lt;code&gt;draw indirect commands&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each time I added a new command to the indirect buffer I also incremented the &lt;code&gt;baseInstance&lt;/code&gt;, so the cube had &lt;code&gt;baseInstance = 0&lt;/code&gt; and the sphere had &lt;code&gt;baseInstance = 1&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason why it doesn't render the sphere is because &lt;code&gt;glMultiDrawArraysIndirect&lt;/code&gt; pretty much evaluates as &lt;code&gt;glDrawArraysInstancedBaseInstance(mode,  cmd-&amp;gt;first,  cmd-&amp;gt;count,  cmd-&amp;gt;instanceCount, cmd-&amp;gt;baseInstance);&lt;/code&gt; (as per the &lt;a href=&quot;https://www.opengl.org/wiki/GLAPI/glMultiDrawArraysIndirect&quot; rel=&quot;nofollow&quot;&gt;OGL wiki&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The drawID is calculated as &lt;code&gt;(gl_InstanceID / divisor) +&lt;/code&gt;&lt;strong&gt;&lt;code&gt;baseInstance&lt;/code&gt;&lt;/strong&gt; (&lt;a href=&quot;https://www.opengl.org/wiki/GLAPI/glDrawArraysInstancedBaseInstance&quot; rel=&quot;nofollow&quot;&gt;link&lt;/a&gt;), which means that the drawID is out of range when trying to render with an offset, as the sphere now appears as the first element in the indirect buffer.&lt;/p&gt;&#xA;" OwnerUserId="214" LastActivityDate="2015-10-26T16:24:09.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1660" PostTypeId="5" CreationDate="2015-10-26T20:29:26.973" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2015-10-26T20:29:26.973" LastActivityDate="2015-10-26T20:29:26.973" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1661" PostTypeId="4" CreationDate="2015-10-26T20:29:26.973" Score="0" Body="For questions related to textures: procedural generation, encodings, aspect characterisation, filtering, mapping, storage..." OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2015-10-27T08:33:48.850" LastActivityDate="2015-10-27T08:33:48.850" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1662" PostTypeId="1" AcceptedAnswerId="2465" CreationDate="2015-10-27T06:52:32.947" Score="9" ViewCount="1329" Body="&lt;p&gt;I'm exploring isosurface algorithms on GPU for a bachelor's project (specifically concentrating on just binary in/out voxel data rather than real-valued fields). So I have a CPU implementation of good old marching cubes up and running in OpenFrameworks, and now at the stage of trying to port it to GLSL compute shaders, and considering the pitfalls before I dive in. I've only written vert and frag shaders before so it's all new to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first issue is how to efficiently use a lookup table across dozens or hundreds of threads in a workgroup? I understand a GPU has different kinds of memory for different tasks but not fully sure on how each operates or which type to use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Paul Bourke's classic copypasta table is a 256*16 array so if using a scalar byte type this can presumably be packed into a 4kb texture or SSBO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is, how to stop the different threads from tripping each other up? Many cubes in each work group can potentially have the same configuration therefore trying to access the same location in the buffer at the same time. Is there a workaround or optimization to deal with this?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="385" LastEditDate="2015-10-28T13:29:36.397" LastActivityDate="2016-05-19T22:40:47.670" Title="Optimal memory access when using lookup tables on GPU?" Tags="&lt;opengl&gt;&lt;algorithm&gt;&lt;gpgpu&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1663" PostTypeId="1" CreationDate="2015-10-27T08:05:36.913" Score="4" ViewCount="339" Body="&lt;p&gt;Previously, to render a bunch of quads, I was simply using a few uniforms (one for a model matrix and another for the texture layer ID). However, I'd rather not have to loop through each quad and set both uniforms each time, each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I went ahead and looked for better alternatives with which I could render everything with a single call. Now I'm using instanced rendering:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// In VAO definition            &#xA;glGenBuffers(1, &amp;amp;instanceVBO);&#xA;glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);&#xA;glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;glEnableVertexAttribArray(3);&#xA;glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(RenderingData), nullptr);&#xA;glVertexAttribDivisor(3, 1);&#xA;glEnableVertexAttribArray(4);&#xA;glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(RenderingData), (GLvoid*)(sizeof(glm::vec4)));&#xA;glVertexAttribDivisor(4, 1);&#xA;glEnableVertexAttribArray(5);&#xA;glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(RenderingData), (GLvoid*)(sizeof(glm::vec4) * 2));&#xA;glVertexAttribDivisor(5, 1);&#xA;glEnableVertexAttribArray(6);&#xA;glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(RenderingData), (GLvoid*)(sizeof(glm::vec4) * 3));&#xA;glVertexAttribDivisor(6, 1);&#xA;glEnableVertexAttribArray(7);&#xA;glVertexAttribIPointer(7, 1, GL_UNSIGNED_INT, sizeof(RenderingData), (GLvoid*)(sizeof(glm::mat4)));&#xA;glVertexAttribDivisor(7, 1);&#xA;&#xA;// In quad adding function&#xA;instanceData.push_back(quad-&amp;gt;data);&#xA;glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(RenderingData) * quads.size(), &amp;amp;instanceData[0], GL_DYNAMIC_DRAW);&#xA;&#xA;// Rendering&#xA;glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0, quads.size());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm using 2 VBOs: one for per-vertex data (position, normal, etc vectors) and another for per-instance data (model matrix and texture layer ID).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9UAOQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9UAOQ.png&quot; alt=&quot;middle one is way too stretched, whereas bottom one&amp;#39;s UV are incorrect, since they aren&amp;#39;t filling the whole quad&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the middle and bottom images aren't rendering correctly (middle one is way too stretched, whereas bottom one's UV are incorrect, since they aren't filling the whole quad), however, I'm 98% sure both my vertex and instance data are correct, since when I was using the previously mentioned uniforms, they were rendering correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I &lt;strong&gt;&lt;em&gt;might&lt;/em&gt;&lt;/strong&gt; 've spotted the problem: the indices. Somehow, if I change my &lt;code&gt;glDrawElementsInstanced&lt;/code&gt;'s count value to say, 12 indices, the middle one renders correctly, whereas the other 2, do not (see picture below). Same thing happens if I change them to 18 (the last one renders correctly and the other 2, do not).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2QSBs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2QSBs.png&quot; alt=&quot;middle one renders correctly, whereas the other 2, do not&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What might the problem be?&lt;/p&gt;&#xA;" OwnerUserId="1938" LastEditorUserId="127" LastEditDate="2015-11-01T14:29:34.893" LastActivityDate="2015-11-01T14:29:34.893" Title="Incorrect instanced rendering" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;c++&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1664" PostTypeId="1" AcceptedAnswerId="1665" CreationDate="2015-10-27T21:03:54.563" Score="5" ViewCount="1915" Body="&lt;p&gt;I'm developing with OpenGL 4.1 and have good understanding of the modern pipeline. I was thinking on doing it with GL_LINE_LOOP for each face, but I think this will require several draw calls which certainly is not optimal. What could be a better approach?&lt;/p&gt;&#xA;" OwnerUserId="116" LastActivityDate="2015-10-27T22:11:26.847" Title="How to render the wireframe of a cube without the diagonals on the faces?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1665" PostTypeId="2" ParentId="1664" CreationDate="2015-10-27T22:11:26.847" Score="5" Body="&lt;p&gt;Things like that are usually done using an &lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Specification#Index_buffers&quot;&gt;index buffer&lt;/a&gt;. The idea is that you have you have two buffers: One for all the vertices and one that determines the topology of what to draw. Then you can draw all the lines at once with a single &lt;a href=&quot;https://www.opengl.org/wiki/GLAPI/glDrawElements&quot;&gt;glDrawElements&lt;/a&gt; call, using GL_LINES as mode.&lt;/p&gt;&#xA;" OwnerUserId="528" LastActivityDate="2015-10-27T22:11:26.847" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1666" PostTypeId="1" CreationDate="2015-10-28T06:18:44.837" Score="11" ViewCount="1051" Body="&lt;p&gt;I can't understand math equations. I'm a graphic designer.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;What is &quot;importance sampling&quot;?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What is &quot;multiple importance sampling&quot;?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Could you explain easily, using illustrations and no math equations? What is the difference between &quot;importance sampling&quot; and &quot;multiple importance sampling&quot;?&lt;/p&gt;&#xA;" OwnerUserId="1944" LastEditorUserId="231" LastEditDate="2015-10-28T10:11:30.387" LastActivityDate="2015-10-28T13:37:44.837" Title="What is the difference between importance sampling and mutiple importance sampling?" Tags="&lt;raytracing&gt;&lt;sampling&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1667" PostTypeId="2" ParentId="1666" CreationDate="2015-10-28T10:12:19.223" Score="12" Body="&lt;p&gt;When shading a point on an opaque surface, you need to gather incoming light and weight it with the bidirectional reflectance distribution function (BRDF) of the material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The naive approach is to distribute samples equally over the hemisphere and probe all directions equally for incoming light. This is called &lt;strong&gt;uniform sampling&lt;/strong&gt; (Fig. 1). While this works in most cases, it can take a long time to converge towards the correct result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sG2z5.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sG2z5.jpg&quot; alt=&quot;Uniform sampling on the hemisphere&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;&lt;strong&gt;Figure 1:&lt;/strong&gt; Uniform sampling on the hemisphere&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To speed things up, let's consider the properties of the surface in question. A diffuse surface needs to take light from all directions on the hemisphere into account, where light coming from flat angles has less influence. A perfect mirror only needs a single direction according to the law of reflection. &lt;strong&gt;Importance sampling&lt;/strong&gt; takes this into account and distributes samples where light is expected to have a greater influence, judging from the BRDF. For the diffuse surface, a cosine sampling would be used (Fig. 2), resulting in fewer samples at flat angles that presumably have a lower influence. For the perfect mirror, only a single ray is shot because all other directions have zero influence anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uJksp.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uJksp.jpg&quot; alt=&quot;Cosine sampling on the hemisphere&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;&lt;strong&gt;Figure 2:&lt;/strong&gt; Cosine sampling on the hemisphere&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the BRDF is not the only thing that can be taken into account. When you have known light sources with strong intensity, it is often desirable to direct more rays towards these light sources, as these directions presumably have a greater impact on the result (i.e. there is more light coming from these directions). The idea to combine various different importance sampling strategies into one is called &lt;strong&gt;multiple importance sampling&lt;/strong&gt;. This technique is not limited to the given example of BRDF + known lights, but can be used with any kind of sensible heuristic you can come up with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Images were generated using Holger Dammertz' &lt;a href=&quot;http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html&quot; rel=&quot;noreferrer&quot;&gt;Hammersley Points on the Hemisphere&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2015-10-28T13:37:44.837" LastActivityDate="2015-10-28T13:37:44.837" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1669" PostTypeId="1" CreationDate="2015-10-30T14:08:45.240" Score="10" ViewCount="302" Body="&lt;p&gt;Why for perfect reflections a surface must have G2 continuity (class A surface)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like a mathematical answer.&lt;/p&gt;&#xA;" OwnerUserId="1636" LastActivityDate="2016-07-03T00:12:28.800" Title="Why for perfect reflections a surface must have G2 continuity?" Tags="&lt;rendering&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1670" PostTypeId="2" ParentId="1669" CreationDate="2015-10-30T20:11:09.003" Score="8" Body="&lt;p&gt;What you see on reflects is the n-continuity of normals, which are the derivative of positions. -&gt; a G1-only surface would have G0-only normal field, i.e.,  with sudden change of gradient in the normals (and thus, the reflects), that the eyes can notice. G2 surfaces have G1 normals fields, which is smooth enough for your eyes.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2015-10-30T20:11:09.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1671" PostTypeId="1" CreationDate="2015-10-31T06:50:49.570" Score="3" ViewCount="64" Body="&lt;p&gt;I am pursuing my research in Texture Interpolation. After digging deep into it, I'm stuck at a point. It is proven that textures can be modeled as Markov Random Fields and that each texture can be synthesized from a collection of neighborhoods. How exactly do we get these neighborhoods that can characterize a texture and if we have them, how can we synthesize the texture back ? And, how does MRF help in any of the above ? Can anyone please provide me with a explanation that helps a layman understand concepts above ?&lt;/p&gt;&#xA;" OwnerUserId="1957" LastActivityDate="2015-10-31T06:50:49.570" Title="MRF and Textures" Tags="&lt;texture&gt;&lt;interpolation&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1672" PostTypeId="1" CreationDate="2015-10-31T11:10:42.477" Score="1" ViewCount="64" Body="&lt;p&gt;How are objects moved smoothly from point A to point B given  matrix transformations that describe next position? &lt;/p&gt;&#xA;" OwnerUserId="1958" LastEditorUserId="137" LastEditDate="2015-10-31T21:10:16.213" LastActivityDate="2015-10-31T21:10:16.213" Title="How is smooth animation accomplished?" Tags="&lt;transformations&gt;&lt;animation&gt;" AnswerCount="0" CommentCount="4" ClosedDate="2015-10-31T14:54:48.140" ContentLicense="CC BY-SA 3.0" />
  <row Id="1673" PostTypeId="1" AcceptedAnswerId="1680" CreationDate="2015-11-01T07:12:43.850" Score="2" ViewCount="190" Body="&lt;p&gt;I had posted about this issue in a &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1663/incorrect-instanced-rendering&quot;&gt;previous question&lt;/a&gt;, however, I thought instancing was causing it, whereas even using normal uniforms or a SSBO (which's what I'm using right now) causes it, which means the problem is elsewhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been trying to figure out the cause, and I might've found out something: only the first quad's vertex data seems to be uploaded / used, somehow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if I were to place random position and texcoord vectors to my other quads, they would still render somewhat correctly. I said &lt;strong&gt;somewhat&lt;/strong&gt; because the output is the following: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ULWbw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ULWbw.png&quot; alt=&quot;middle one is way too stretched and the last one&amp;#39;s UV coords are wrong&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The middle one is way too stretched and the last one's UV coords are wrong, since they aren't filling the whole quad, as you can see by the white background. So long as the first quad's were right, and whenever I changed the first quad's vertex data, it was propagated to the other ones as well, leading me to believe the other quads' vertex data are getting ignored and the first quad is being re-used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// VAO definition&#xA;glGenVertexArrays(1, &amp;amp;VAO);&#xA;glBindVertexArray(VAO);&#xA;/*** VBO ***/&#xA;glGenBuffers(1, &amp;amp;VBO);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;/*** Vertex Format ***/&#xA;//Position Vertex&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);&#xA;//Normal Vertex&#xA;glEnableVertexAttribArray(1);&#xA;glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec3)));&#xA;//Texture Coordinate Vertex&#xA;glEnableVertexAttribArray(2);&#xA;glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec3) * 2));&#xA;/*** EBO ***/&#xA;glGenBuffers(1, &amp;amp;EBO);&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;glBufferData(GL_ELEMENT_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;/*** SSBO ***/&#xA;glGenBuffers(1, &amp;amp;SSBO);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;&#xA;// Quad adding function&#xA;auto iter = std::find(quads.begin(), quads.end(), quad);&#xA;&#xA;if(iter == quads.end())&#xA;{&#xA;    quads.push_back(quad);&#xA;&#xA;    for(unsigned int i = 0; i &amp;lt; 4; i++)&#xA;        vertices.push_back(quad-&amp;gt;vertices[i]);&#xA;&#xA;    GLuint start = (indices.empty()) ? 0 : indices[indices.size() - 1] + 1;&#xA;&#xA;    GLuint newIndices[] = {&#xA;        start, start + 1, start + 2,&#xA;        start, start + 2, start + 3&#xA;    };&#xA;&#xA;    for(unsigned int i = 0; i &amp;lt; 6; i++)&#xA;        indices.push_back(newIndices[i]);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), &amp;amp;vertices[0], GL_DYNAMIC_DRAW);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * indices.size(), &amp;amp;indices[0], GL_DYNAMIC_DRAW);&#xA;&#xA;    instanceData.push_back(quad-&amp;gt;data);&#xA;    glBindBuffer(GL_SHADER_STORAGE_BUFFER, SSBO);&#xA;    glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(RenderingData) * quads.size(), &amp;amp;instanceData[0], GL_DYNAMIC_DRAW);&#xA;    glBindBufferRange(GL_SHADER_STORAGE_BUFFER, 0, SSBO, 0, sizeof(RenderingData) * quads.size());&#xA;}&#xA;&#xA;&#xA;// Rendering&#xA;program-&amp;gt;Use();&#xA;&#xA;program-&amp;gt;SetStorageBlock(&quot;RenderingData&quot;, 0);&#xA;&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D_ARRAY, texture-&amp;gt;GetTexture());&#xA;program-&amp;gt;SetInteger(&quot;diffuseTextureArray&quot;, 0);&#xA;&#xA;glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0, quads.size());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; I also tried to limit the vertex data uploading to the first quad, effectively making it the only one with valid data, a part from the per-instance data (&lt;em&gt;RenderingData&lt;/em&gt; struct: a model matrix and an uint), which were all fed to the SSBO. This still lead to 3 quads being rendered, which shouldn't be the case under normal circumstances, right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; I made a sample code which replicates the problem; it should render a green quad and a red quad, however, it just renders 2 red quads. Also, even if you try to change the second quads' attributes (even like placing all 0s), it'll still just render. Somehow only the first quads' vertices are getting read and used for each subsequent quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;C++ code:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;string&amp;gt;&#xA;#include &amp;lt;sstream&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;#define GLEW_STATIC&#xA;#include &quot;GL/glew.h&quot;&#xA;#include &quot;GLFW/glfw3.h&quot;&#xA;#include &amp;lt;IL/il.h&amp;gt;&#xA;#include &amp;lt;IL/ilu.h&amp;gt;&#xA;#include &amp;lt;glm/glm.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/matrix_transform.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/type_ptr.hpp&amp;gt;&#xA;&#xA;struct Vertex{&#xA;    glm::vec2 pos, tex;&#xA;    glm::vec3 color;&#xA;};&#xA;&#xA;struct Quad{&#xA;    std::vector&amp;lt;Vertex&amp;gt; vertices;&#xA;    glm::mat4 model;&#xA;&#xA;    Quad(glm::vec2 pos, glm::vec2 size, const std::vector&amp;lt;Vertex&amp;gt; &amp;amp;v){&#xA;        vertices = v;&#xA;        model = glm::mat4();&#xA;        model = glm::translate(model, glm::vec3(pos, 0.f));&#xA;        model = glm::scale(model, glm::vec3(size, 1.f));&#xA;    }&#xA;};&#xA;&#xA;class Renderer{&#xA;    private:&#xA;        GLuint VAO, VBO, instanceVBO, EBO;&#xA;        std::vector&amp;lt;Quad*&amp;gt; quads;&#xA;        std::vector&amp;lt;Vertex&amp;gt; vertices;&#xA;        std::vector&amp;lt;glm::mat4&amp;gt; models;&#xA;        std::vector&amp;lt;GLuint&amp;gt; indices;&#xA;&#xA;    public:&#xA;        Renderer(){&#xA;            /*** VAO ***/&#xA;            glGenVertexArrays(1, &amp;amp;VAO);&#xA;            glBindVertexArray(VAO);&#xA;            /*** Per-vertex VBO ***/&#xA;            glGenBuffers(1, &amp;amp;VBO);&#xA;            glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;            glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;            glEnableVertexAttribArray(0);   // Position&#xA;            glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), nullptr);&#xA;            glEnableVertexAttribArray(1);   // Tex Coord&#xA;            glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec2)));&#xA;            glEnableVertexAttribArray(2);   // Color&#xA;            glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(sizeof(glm::vec2) * 2));&#xA;            /*** Per-instance VBO ***/&#xA;            glGenBuffers(1, &amp;amp;instanceVBO);&#xA;            glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);&#xA;            glBufferData(GL_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;            glEnableVertexAttribArray(3);   // Model matrix - row1&#xA;            glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), nullptr);&#xA;            glVertexAttribDivisor(3, 1);&#xA;            glEnableVertexAttribArray(4);   // Model matrix - row2&#xA;            glVertexAttribPointer(4, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)(sizeof(glm::vec4)));&#xA;            glVertexAttribDivisor(4, 1);&#xA;            glEnableVertexAttribArray(5);   // Model matrix - row3&#xA;            glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)(sizeof(glm::vec4) * 2));&#xA;            glVertexAttribDivisor(5, 1);&#xA;            glEnableVertexAttribArray(6);   // Model matrix - row4&#xA;            glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(glm::mat4), (GLvoid*)(sizeof(glm::vec4) * 3));&#xA;            glVertexAttribDivisor(6, 1);&#xA;            /*** EBO ***/&#xA;            glGenBuffers(1, &amp;amp;EBO);&#xA;            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;            glBufferData(GL_ELEMENT_ARRAY_BUFFER, 0, nullptr, GL_DYNAMIC_DRAW);&#xA;        }&#xA;        ~Renderer(){&#xA;            glDeleteBuffers(1, &amp;amp;VBO);&#xA;            glDeleteBuffers(1, &amp;amp;instanceVBO);&#xA;            glDeleteBuffers(1, &amp;amp;EBO);&#xA;            glDeleteVertexArrays(1, &amp;amp;VAO);&#xA;        }&#xA;        void AddQuad(Quad *const quad){&#xA;            quads.push_back(quad);&#xA;&#xA;            for(unsigned int i = 0; i &amp;lt; 4; i++)&#xA;                vertices.push_back(quad-&amp;gt;vertices[i]);&#xA;&#xA;            models.push_back(quad-&amp;gt;model);&#xA;&#xA;            GLuint start = ((indices.empty()) ? 0 : indices[indices.size() - 1] + 1);&#xA;&#xA;            GLuint newIndices[] = {&#xA;                start,  start + 1,  start + 2,&#xA;                start,  start + 3,  start + 2&#xA;            };&#xA;&#xA;            for(unsigned int i = 0; i &amp;lt; 6; i++)&#xA;                indices.push_back(newIndices[i]);&#xA;&#xA;            glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;            glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * vertices.size(), &amp;amp;vertices[0], GL_DYNAMIC_DRAW);&#xA;&#xA;            glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);&#xA;            glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * quads.size(), &amp;amp;models[0], GL_DYNAMIC_DRAW);&#xA;&#xA;            glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;            glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * indices.size(), &amp;amp;indices[0], GL_DYNAMIC_DRAW);&#xA;        }&#xA;        void Render(GLuint &amp;amp;program){&#xA;            glUseProgram(program);&#xA;&#xA;            glDrawElementsInstanced(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0, quads.size());&#xA;        }&#xA;        void CheckQuads(){&#xA;            for(unsigned int i = 0; i &amp;lt; quads.size(); i++)&#xA;            {&#xA;                std::cout &amp;lt;&amp;lt; &quot;Quad n.&quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &quot;\n&quot;;&#xA;                for(unsigned int j = 0; j &amp;lt; 4; j++)&#xA;                {&#xA;                    std::cout &amp;lt;&amp;lt; &quot;\tVert &quot; &amp;lt;&amp;lt; j &amp;lt;&amp;lt; &quot;:\n&quot;;&#xA;                    std::cout &amp;lt;&amp;lt; &quot;\t&quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].pos.x &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].pos.y &amp;lt;&amp;lt; &quot;\n&quot;;&#xA;                    std::cout &amp;lt;&amp;lt; &quot;\t&quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].tex.x &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].tex.y &amp;lt;&amp;lt; &quot;\n&quot;;&#xA;                    std::cout &amp;lt;&amp;lt; &quot;\t&quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].color.r &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].color.g &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; quads[i]-&amp;gt;vertices[j].color.b &amp;lt;&amp;lt; &quot;\n&quot;;&#xA;                }&#xA;            }&#xA;        }&#xA;};&#xA;&#xA;GLuint GenerateShader(const std::string &amp;amp;filename, GLenum shaderType)&#xA;{&#xA;    GLuint shader;&#xA;    std::ifstream file(filename.c_str());&#xA;    std::stringstream ss;&#xA;    ss &amp;lt;&amp;lt; file.rdbuf();&#xA;    file.close();&#xA;    const GLchar *source = ss.str().c_str();&#xA;    shader = glCreateShader(shaderType);&#xA;    glShaderSource(shader, 1, &amp;amp;source, nullptr);&#xA;    glCompileShader(shader);&#xA;    return shader;&#xA;}&#xA;&#xA;int main()&#xA;{&#xA;    /*** Window + Context ***/&#xA;    glfwInit();&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);&#xA;    GLFWwindow *window = glfwCreateWindow(640, 480, &quot;OpenGL Incorrect Rendering Test&quot;, nullptr, nullptr);&#xA;    glfwMakeContextCurrent(window);&#xA;    glewExperimental = GL_TRUE;&#xA;    glewInit();&#xA;    glViewport(0, 0, 640, 480);&#xA;    glClearColor(0.f, 0.f, 0.f, 1.f);&#xA;&#xA;    glm::mat4 projection = glm::ortho(0.f, 640.f, 480.f, 0.f, -1.f, 1.f);&#xA;&#xA;    /*** Shader Program ***/&#xA;    GLuint program = glCreateProgram();&#xA;    glAttachShader(program, GenerateShader(&quot;vertex_shader.glsl&quot;, GL_VERTEX_SHADER));&#xA;    glAttachShader(program, GenerateShader(&quot;fragment_shader.glsl&quot;, GL_FRAGMENT_SHADER));&#xA;    glLinkProgram(program);&#xA;&#xA;    glUseProgram(program);&#xA;    glUniformMatrix4fv(glGetUniformLocation(program, &quot;projection&quot;), 1, GL_FALSE, glm::value_ptr(projection));&#xA;    /*** Renderer ***/&#xA;    Renderer *renderer = new Renderer();&#xA;    // Quad 1&#xA;    Vertex v1 = {glm::vec2(0.f, 0.f), glm::vec2(0.f, 0.f), glm::vec3(1.f, 0.f, 0.f)};&#xA;    Vertex v2 = {glm::vec2(1.f, 0.f), glm::vec2(0.f, 0.f), glm::vec3(1.f, 0.f, 0.f)};&#xA;    Vertex v3 = {glm::vec2(1.f, 1.f), glm::vec2(0.f, 0.f), glm::vec3(1.f, 0.f, 0.f)};&#xA;    Vertex v4 = {glm::vec2(0.f, 1.f), glm::vec2(0.f, 0.f), glm::vec3(1.f, 0.f, 0.f)};&#xA;    renderer-&amp;gt;AddQuad(new Quad(glm::vec2(300, 10), glm::vec2(150, 150), {v1, v2, v3, v4}));&#xA;    // Quad 2&#xA;    Vertex v5 = {glm::vec2(0.f, 0.f), glm::vec2(0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)};&#xA;    Vertex v6 = {glm::vec2(1.f, 0.f), glm::vec2(0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)};&#xA;    Vertex v7 = {glm::vec2(1.f, 1.f), glm::vec2(0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)};&#xA;    Vertex v8 = {glm::vec2(0.f, 1.f), glm::vec2(0.f, 0.f), glm::vec3(0.f, 1.f, 0.f)};&#xA;    renderer-&amp;gt;AddQuad(new Quad(glm::vec2(30, 10), glm::vec2(150, 150), {v5, v6, v7, v8}));&#xA;&#xA;    while(!glfwWindowShouldClose(window))&#xA;    {&#xA;        glfwPollEvents();&#xA;&#xA;        if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)&#xA;            glfwSetWindowShouldClose(window, true);&#xA;&#xA;        glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;        renderer-&amp;gt;Render(program);&#xA;&#xA;        glfwSwapBuffers(window);&#xA;    }&#xA;&#xA;    delete renderer;&#xA;&#xA;    glfwDestroyWindow(window);&#xA;    glfwTerminate();&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;vertex_shader.glsl:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (location = 0) in vec2 position;&#xA;layout (location = 1) in vec2 texCoord;&#xA;layout (location = 2) in vec3 color;&#xA;layout (location = 3) in mat4 model;&#xA;&#xA;out vec2 uv;&#xA;out vec3 col;&#xA;&#xA;uniform mat4 projection;&#xA;&#xA;void main()&#xA;{&#xA;    uv = texCoord;&#xA;    col = color;&#xA;&#xA;    gl_Position = projection * model * vec4(position, 0.f, 1.f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;fragment_shader.glsl:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;in vec2 uv;&#xA;in vec3 col;&#xA;out vec4 color;&#xA;&#xA;void main()&#xA;{&#xA;    color = vec4(col, 1.f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1938" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:45:54.910" LastActivityDate="2018-04-24T07:45:54.910" Title="First quad being re-used?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1674" PostTypeId="2" ParentId="1669" CreationDate="2015-11-01T12:56:51.173" Score="7" Body="&lt;ul&gt;&#xA;&lt;li&gt;G0 Continuity means that the separate surfaces meet,&lt;/li&gt;&#xA;&lt;li&gt;G1 Continuity that the surfaces meet at same angle,&lt;/li&gt;&#xA;&lt;li&gt;G2 Continuity means that the change in angle matches in point of contact.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The G2 requirement does not mean that the surface is good quality. Just means that without this the surface is not going to have a continuous reflection flow so humans can see the difference. That may or may not be a good thing depends on what you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematically the surface normal is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f(u,v) \frac{\partial}{\partial u} \times f(u,v) \frac{\partial}{\partial v}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since both sides are derived that means that the function field of the surface normal has one degree less than the original surface. So for the reflection to be first degree continuous it has to have a second degree continuity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far we have established the relationship between the continuity of the surface and the continuity of the reflection. Nothing thus far proves that the surface reflection needs to be first degree continuous. To understand why we must exit the realm of mathematics and enter the realm of biology.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The eye is equipped with an edge detection algorithm on a structural level right on the retina. This edge detection algorithm in essence works as a discrete derivative of the input signal. So, if your surface is not G2 continuous then the human edge detection kicks in and shows itself up. For references read on &lt;a href=&quot;https://en.wikipedia.org/wiki/Mach_bands&quot; rel=&quot;nofollow&quot;&gt;Mach Bands&lt;/a&gt; and so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the edge detection is discrete G2 continuity is not enough. The change has to not only be locally satisfied but also satisfied on the retina. So the change should still be shallow enough not to cause problems.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-07-03T00:12:28.800" LastActivityDate="2016-07-03T00:12:28.800" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1675" PostTypeId="1" CreationDate="2015-11-02T11:05:12.347" Score="1" ViewCount="73" Body="&lt;p&gt;I am very eager to know what technology might been used to implement this piece of wonder:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MFCAK.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MFCAK.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think, it's ray tracing. What do you think?&lt;/p&gt;&#xA;" OwnerUserId="1970" LastActivityDate="2015-11-03T02:18:02.977" Title="How to design something like this?" Tags="&lt;animation&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2015-11-03T08:57:47.263" ContentLicense="CC BY-SA 3.0" />
  <row Id="1678" PostTypeId="2" ParentId="1675" CreationDate="2015-11-03T02:18:02.977" Score="2" Body="&lt;p&gt;It does look like raytracing to me as well.  It could also possibly be ray marching, which would be easier to make the tubes with since ray marching is all based on distances from things (center of tube in this case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Refraction is what's used to bend the light that goes through the tubes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You are then just left with how to model the tubes. One way could be to use 3d bezier curves (: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This may not have been made in real time, but may have been rendered frame by frame and then assembled into the smooth &quot;movie&quot; you are showing.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-11-03T02:18:02.977" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1679" PostTypeId="2" ParentId="1637" CreationDate="2015-11-03T03:12:17.680" Score="0" Body="&lt;p&gt;You might want to look into signed distance field textures.  They are very efficient and high quality for monochromatic images like shadows.  They work by storing a clamped, signed distance from the pixel to the shape.  Working this way, the distances play nicely with the bilinear interpolation of texture sampling, so you can have very nice results for very low resolution.  You can also give them a soft edge to have a soft shadow look.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-11-03T03:12:17.680" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1680" PostTypeId="2" ParentId="1673" CreationDate="2015-11-03T09:05:16.970" Score="1" Body="&lt;p&gt;Seems like I had misunderstood instancing, that's why my code was acting strange: I was trying to use instancing while also trying to render different quads using different vertex data.&lt;/p&gt;&#xA;" OwnerUserId="1938" LastEditorUserId="1938" LastEditDate="2015-11-03T10:01:38.730" LastActivityDate="2015-11-03T10:01:38.730" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1681" PostTypeId="1" AcceptedAnswerId="1682" CreationDate="2015-11-03T20:49:40.587" Score="13" ViewCount="1033" Body="&lt;p&gt;I'm trying to implement an ocean scene with C++ and DirectX11. Currently I have a projected grid, Gerstner waves and a basic shading. My problem is that when I aim my camera horizontally, so I can see the water horizon, in the distance, the projected grid becomes insufficient, even at high vertex numbers. These screenshots illustrate the problem:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F1Nqx.jpg&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F1Nqx.jpg&quot; alt=&quot;shaded water surface&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1qsKc.jpg&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1qsKc.jpg&quot; alt=&quot;wireframe water surface&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know the cause of the problem is in the concept of the projected grid (the grid is detailed near the camera, rough far from it), but there has to be a best practice to solve this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="1987" LastActivityDate="2017-02-25T13:49:26.930" Title="Projected grid water horizon detail" Tags="&lt;real-time&gt;&lt;geometry&gt;&lt;c++&gt;&lt;directx11&gt;&lt;grid&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1682" PostTypeId="2" ParentId="1681" CreationDate="2015-11-04T02:55:53.690" Score="7" Body="&lt;p&gt;I believe a common solution is to split the camera transform used to project the grid from the camera transform that is used to render the grid. At perspectives close to top-down, the two cameras coincide, but as the viewing camera gets close to a horizontal perspective, the projection camera deviates and tries to keep a minimum inclination, i.e. it hovers somewhere above the view camera and looks down slightly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The tricky bit is making sure that the field of view of the projection camera always covers the region of the scene seen from the render camera. I don't have a resource at hand that details how to compute the appropriate transforms, and it might be tedious to derive by hand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A different solution is to grab the signal processing toolbox: The artifacts seen in your image are essentially aliasing, caused by insufficient sampling of the wave heightfield by the projected grid. Therefore, one solution is to filter the heightfield appropriately, depending on the projected area of a grid cell. I believe this is used in offline rendering of oceans, and it essentially makes sure that waves at the horizon go flat. However, I'm not sure how feasible this is in real-time rendering, since you would need high-quality anisotropic filtering to make this approach look reasonable.&lt;/p&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-11-04T02:55:53.690" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1683" PostTypeId="2" ParentId="1681" CreationDate="2015-11-04T05:25:47.107" Score="3" Body="&lt;p&gt;Some software like Maya, solve this by using a polar (or actually cartesian that turns polar at a distance) much in the same way as you grid centered on the camera position. This setup adds more detail where it counts most Then they rely on the shaders normal processing at further ranges. There is room for improvemenet offcourse. You cold modify this approach a bit, and have any other shape that increases the mesh density towards the camera. The benefit of this is you can stretch the  effect up to the horizon without worrying about the seam. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The trick to not get the displacenent jumbled up in this case is that you gradually reduce the displacement as you move further away. You then just use normal modification in the pixel shader as you get further. This is easier to filter than having to filter an accurate shiluette edge. Also if you can see that far away then your vawes are likely sufficiently flat anyway.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-11-04T21:52:47.867" LastActivityDate="2015-11-04T21:52:47.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1685" PostTypeId="2" ParentId="1606" CreationDate="2015-11-04T09:32:20.727" Score="1" Body="&lt;p&gt;In homogeneous coordinates i would do something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\vec{p} = \left(\frac{2}{x+y}, \frac{5y + z}{2x + 2y}, 3\right)^T = \left(\frac{2}{x+y}, \frac{\frac{5y + z}{2}}{x + y}, \frac{3x + 3y}{x + y}\right)^T$$ adding the fourth coordinate&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\vec{p}^H = \left(2, \frac{5y + z}{2}, 3x + 3y, x + y\right)^T = &#xA;\begin{pmatrix} &#xA; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 2 \\ &#xA; 0 &amp;amp; \frac{5}{2} &amp;amp; \frac{1}{2} &amp;amp; 0 \\&#xA; 3 &amp;amp; 3 &amp;amp; 0 &amp;amp; 0 \\&#xA; 1 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0&#xA;\end{pmatrix} \cdot \begin{pmatrix}x \\ y \\ z \\ 1\end{pmatrix}$$,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want a systematic way, since a linear transformation is completely characterized from the transformation of a basis, take the canonical bases i.e.&#xA;($\vec{e}^H_0 = (1,0,0,0), \vec{e}^H_1 = (0,1,0,0),...$) apply the transformation in $\vec{p}^H$ it will give you for $i = 0,...,3$ the columns of the matrix.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2015-11-04T09:32:20.727" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1686" PostTypeId="1" AcceptedAnswerId="1689" CreationDate="2015-11-04T15:47:36.557" Score="8" ViewCount="416" Body="&lt;p&gt;The &lt;a href=&quot;https://eheitzresearch.wordpress.com/240-2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Multiple Scattering Microfacet BSDFs with the Smith Model&lt;/a&gt; paper describes a statistical model for replacing the masking-shadowing functions in microfacet BSDFs (which account for paths with more than one surface intersection by setting their contribution to 0) with a distribution which can be path traced and allows the a ray to intersect a microfacet surface several times before exiting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They do this by modifying a volumetric (microflake) model to behave like a heightfield: to never collide with anything &quot;above&quot; the surface and to always collide with anything &quot;below&quot; the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kTAw4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kTAw4.png&quot; alt=&quot;Microsurface vs modified microflake volume&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result, using wording from their slides, is that &quot;the ray can never go through the Smith volume; the model creates an opaque surface-like interface.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this model compatible with traditional diffuse subsurface scattering, where a path can travel a perceptible (macro-scale) distance through a surface before exiting? Or is this simply a specular BSDF with no intention of modeling long paths internal to a surface, to be combined with a diffuse BSDF that adds that component?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Does the microflake model of volumetric rendering normally separate diffuse and specular, or is &quot;diffuse&quot; simply a path that bounces around so many times that the outgoing direction is uniformly distributed?)&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-11-05T01:57:04.717" Title="How does Smith multiple scattering interact with diffuse subsurface scattering?" Tags="&lt;brdf&gt;&lt;scattering&gt;&lt;subsurface-scattering&gt;&lt;microfacet&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1687" PostTypeId="1" AcceptedAnswerId="1688" CreationDate="2015-11-04T21:41:15.603" Score="4" ViewCount="99" Body="&lt;p&gt;I need a source code that takes as input a COLLADA file and/or an OBJ file, and gives as output basic information about the file, such as file size, model dimension, volume and if possible texture issues.&lt;/p&gt;&#xA;" OwnerUserId="1994" LastActivityDate="2016-11-17T21:17:42.587" Title="Is there any open code to get information about COLLADA or OBJ files?" Tags="&lt;implementation&gt;" AnswerCount="2" CommentCount="2" ClosedDate="2016-11-16T14:37:43.380" ContentLicense="CC BY-SA 3.0" />
  <row Id="1688" PostTypeId="2" ParentId="1687" CreationDate="2015-11-04T22:31:27.753" Score="6" Body="&lt;p&gt;&lt;strong&gt;For OBJ Files&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Free tools like &lt;a href=&quot;http://meshlab.sourceforge.net/&quot;&gt;MeshLab&lt;/a&gt;, &lt;a href=&quot;https://www.blender.org/&quot;&gt;Blender&lt;/a&gt;, and &lt;a href=&quot;http://www.glc-player.net/&quot;&gt;GLC_Player&lt;/a&gt; are able to load OBJ files and give you basic information about their content.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apparently, GLC_Player can also load COLLADA.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In code you can use the following standard tools:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/assimp/assimp&quot;&gt;Assimp&lt;/a&gt; - Library for loading many common formats including OBJ&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/syoyo/tinyobjloader&quot;&gt;TinyObjLoader&lt;/a&gt; - .h/.cc only, no external dependencies&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="14" LastActivityDate="2015-11-04T22:31:27.753" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1689" PostTypeId="2" ParentId="1686" CreationDate="2015-11-05T01:57:04.717" Score="6" Body="&lt;p&gt;The goal of Heitz et al.'s model is pretty much the opposite of subsurface scattering: They only consider surface scattering, i.e. the ray can never enter the material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because microfacets are statistical in nature, they can recast their problem in such a way that it can be solved by microflakes, which allows them to compute properties such as the mean free path to derive a heightfield sampling procedure. However, even though they use microflake theory, they still solve the same problem of multiple scattering on microfacets, and their result is still a BSDF, not a subsurface scattering model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because it is a BSDF, the path exits at the same location as it hit the surface. This is also mentioned in the introduction:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Note that our volume-scattering process models the interaction with a surface, but its application in rendering is virtual in that no displacements occur, i.e. the incident and exitant location are the same and the resulting plane-parallel radiometry produces a BSDF.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="79" LastActivityDate="2015-11-05T01:57:04.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1691" PostTypeId="1" CreationDate="2015-11-05T10:08:52.910" Score="11" ViewCount="676" Body="&lt;p&gt;I have a spectral power distribution (SPD, 5 nm steps) for all light sources in the scene and SPDs for the reflectance of all surfaces under any light / viewer angle in question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm going to calculate in floating point precision and not clamp any values. Except for pathological cases like monochromatic light or special things like dispersion effects, does it make a difference whether I render using the spectrum, XYZ color space or linear RGB color space? Note that I will convert the result to sRGB as a last step in any case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically, is it invariant at which point (before or after multiplication of surface BRDF with light intensity) I integrate to convert spectrum to XYZ? Does the introduction of reference white in XYZ / RGB distort the colors when working with light sources of a different color / SPD?&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2015-11-05T11:36:46.390" LastActivityDate="2020-05-19T09:43:40.490" Title="How correct is rendering in XYZ / linear RGB space?" Tags="&lt;rendering&gt;&lt;physically-based&gt;&lt;mathematics&gt;" AnswerCount="0" CommentCount="9" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1692" PostTypeId="1" AcceptedAnswerId="1693" CreationDate="2015-11-05T12:57:12.430" Score="8" ViewCount="1536" Body="&lt;p&gt;This a follow up for a question I answered on GameDev SE. The question was simply &lt;a href=&quot;https://gamedev.stackexchange.com/questions/110781/is-gldrawarraysinstanced-in-opengl-parallel-when-drawing-those-instances&quot;&gt;Is glDrawArraysInstanced in OpenGL parallel when drawing those instances?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My answer was in the lines of &quot;the GPU might execute multiple draw calls in parallel depending on multiple things, for instance if two draw calls use the same vertex shaders.&quot; &lt;a href=&quot;https://gamedev.stackexchange.com/questions/110781/is-gldrawarraysinstanced-in-opengl-parallel-when-drawing-those-instances/110806#110806&quot;&gt;Here is the full answer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the comments the OP mentioned, &quot;I think it should be sequential. After all, some of blending mode depends of sequence&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I am little bit confused. Is my answer of &lt;em&gt;it will still parallelize them when it can&lt;/em&gt; valid? Can someone clarify this?&lt;/p&gt;&#xA;" OwnerUserId="8" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2015-11-05T20:20:08.097" Title="Are draw calls executed in parallel or sequentially or both?" Tags="&lt;opengl&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1693" PostTypeId="2" ParentId="1692" CreationDate="2015-11-05T13:30:39.553" Score="9" Body="&lt;p&gt;The result should be &lt;em&gt;as if&lt;/em&gt; it was executed sequentially one triangle at a time. This is important so that each frame is deterministic. If it wasn't then drawing the same frame multiple times could create different results and create a flickering image on screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However that &lt;em&gt;does not mean parallelization is impossible&lt;/em&gt;. Vertices can be computed in parallel. Their results will be ordered and fed to the rasterizer which will feed the fragment shader stage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same happens with pixels. Typically a group of pixels from a triangle can be computed in parallel and blended. A non-overlapping triangle can then also be filled at the same time however if triangle overlaps one currently busy then the result of the fragment shader must be buffered until the corresponding pixels of the previous triangle are done so blending can happen in the correct order.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2015-11-05T14:46:13.837" LastActivityDate="2015-11-05T14:46:13.837" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1694" PostTypeId="1" AcceptedAnswerId="1717" CreationDate="2015-11-06T09:26:09.643" Score="4" ViewCount="150" Body="&lt;p&gt;I have some material which I want to represent as a collection of spheres (atoms) and a particle of light (photon). I'm firing this particle and checking for the collision against atoms. What should happen if collision occurs? I see two possible solutions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Light particle can be either absorbed or reflected, depends on some probability.&lt;/li&gt;&#xA;&lt;li&gt;Light particle reflected, but loses some part of it's energy. When the energy is zero, particle is absorbed.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Update: I want to see the general behavior of the particle. The particle itself I want to simulate as a ray. Also I want to simulate a variety of materials - I think small spheres placed near each other can lead to specular material. Big spheres placed far from each other can lead to Lambertian material and subsurface scattering. The light transport is nor stochastic nor full valuated - a ray after collision will reflect correctly, not randomly. In the end I want to see the number of photons reflected, transmitted, scattered and their direction.&lt;/p&gt;&#xA;" OwnerUserId="386" LastEditorUserId="386" LastEditDate="2015-11-06T16:25:41.327" LastActivityDate="2015-11-13T16:50:33.490" Title="Does light particle loses energy when it hits something?" Tags="&lt;lighting&gt;&lt;material&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1696" PostTypeId="2" ParentId="1681" CreationDate="2015-11-06T15:49:43.377" Score="6" Body="&lt;p&gt;You can be both realistical and real-time. the secret is to change representation each time the information get under the Shannon-Nyquist (i.e. grid) scale: from geometry to normal maps to shading models. This paper is made for you: &lt;a href=&quot;http://maverick.inria.fr/Publications/2010/BNH10/index.php&quot;&gt;http://maverick.inria.fr/Publications/2010/BNH10/index.php&lt;/a&gt; (see also Yoube videos)&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2015-11-06T15:49:43.377" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1698" PostTypeId="1" AcceptedAnswerId="1699" CreationDate="2015-11-07T10:17:34.330" Score="3" ViewCount="3731" Body="&lt;p&gt;I can't really seem to figure out how to bind two constant buffers to my shaders. I have them described like so. One in slot b0 and the other in slot b1.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;cbuffer WVPData : register(b0)&#xA;{&#xA;    matrix model;&#xA;    matrix view;&#xA;    matrix projection;&#xA;};&#xA;&#xA;cbuffer DirLightData : register(b1)&#xA;{&#xA;   float4 Ambient;&#xA;   float4 Diffuse;&#xA;   float4 Specular;&#xA;   float3 Direction;&#xA;   float pad;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then for the root signature it's described like so.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;CD3DX12_DESCRIPTOR_RANGE range[2];&#xA;CD3DX12_ROOT_PARAMETER parameter[1];&#xA;&#xA;range[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 0);&#xA;range[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 1, 1);&#xA;parameter[0].InitAsDescriptorTable(_countof(range), range, D3D12_SHADER_VISIBILITY_ALL);&#xA;&#xA;D3D12_ROOT_SIGNATURE_FLAGS rootSignatureFlags =&#xA;D3D12_ROOT_SIGNATURE_FLAG_ALLOW_INPUT_ASSEMBLER_INPUT_LAYOUT | // Only the input assembler stage needs access to the constant buffer.&#xA;D3D12_ROOT_SIGNATURE_FLAG_DENY_DOMAIN_SHADER_ROOT_ACCESS |&#xA;D3D12_ROOT_SIGNATURE_FLAG_DENY_GEOMETRY_SHADER_ROOT_ACCESS |&#xA;D3D12_ROOT_SIGNATURE_FLAG_DENY_HULL_SHADER_ROOT_ACCESS;&#xA;&#xA;CD3DX12_ROOT_SIGNATURE_DESC descRootSignature;&#xA;descRootSignature.Init(_countof(parameter), parameter, 0, nullptr, rootSignatureFlags);&#xA;&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; pSignature;&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; pError;&#xA;DX::ThrowIfFailed(D3D12SerializeRootSignature(&amp;amp;descRootSignature, D3D_ROOT_SIGNATURE_VERSION_1, pSignature.GetAddressOf(), pError.GetAddressOf()));&#xA;DX::ThrowIfFailed(d3dDevice-&amp;gt;CreateRootSignature(0, pSignature-&amp;gt;GetBufferPointer(), pSignature-&amp;gt;GetBufferSize(), IID_PPV_ARGS(&amp;amp;mRootSignature)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I believe that's correct. I think the problem I have is when I create the constant buffer and the cbv below. Specifically right under the &quot;Describe and create the constant buffer view.&quot; comment. I don't really understand what's going on.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Create a descriptor heap for the constant buffers.&#xA;{&#xA;    D3D12_DESCRIPTOR_HEAP_DESC heapDesc = {};&#xA;    heapDesc.NumDescriptors = 2;&#xA;    heapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;&#xA;    // This flag indicates that this descriptor heap can be bound to the pipeline and that descriptors contained in it can be referenced by a root table.&#xA;    heapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;&#xA;    DX::ThrowIfFailed(d3dDevice-&amp;gt;CreateDescriptorHeap(&amp;amp;heapDesc, IID_PPV_ARGS(&amp;amp;mCbvHeap)));&#xA;&#xA;    mCbvHeap-&amp;gt;SetName(L&quot;Constant Buffer View Descriptor Heap&quot;);&#xA;}&#xA;&#xA;// Create the constant buffer.&#xA;DX::ThrowIfFailed(d3dDevice-&amp;gt;CreateCommittedResource(&#xA;  &amp;amp;uploadHeapProperties,&#xA;  D3D12_HEAP_FLAG_NONE,&#xA;  &amp;amp;CD3DX12_RESOURCE_DESC::Buffer(CAlignedWVPDataSize),&#xA;  D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;  nullptr,&#xA;  IID_PPV_ARGS(&amp;amp;mWVPConstantBuffer)));&#xA;&#xA;DX::ThrowIfFailed(d3dDevice-&amp;gt;CreateCommittedResource(&#xA;  &amp;amp;uploadHeapProperties,&#xA;  D3D12_HEAP_FLAG_NONE,&#xA;  &amp;amp;CD3DX12_RESOURCE_DESC::Buffer(CAlignedDirLightDataSize),&#xA;  D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;  nullptr,&#xA;  IID_PPV_ARGS(&amp;amp;mDirLightConstantBuffer)));&#xA;&#xA;// Describe and create a constant buffer view.&#xA;D3D12_CONSTANT_BUFFER_VIEW_DESC cbvDesc[2];// = {};&#xA;cbvDesc[0].BufferLocation = mWVPConstantBuffer-&amp;gt;GetGPUVirtualAddress();&#xA;cbvDesc[0].SizeInBytes = CAlignedWVPDataSize;&#xA;cbvDesc[1].BufferLocation = mDirLightConstantBuffer-&amp;gt;GetGPUVirtualAddress();&#xA;cbvDesc[1].SizeInBytes = CAlignedDirLightDataSize;&#xA;&#xA;CD3DX12_CPU_DESCRIPTOR_HANDLE cbvHandle0(mCbvHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart(), 0, 0);&#xA;d3dDevice-&amp;gt;CreateConstantBufferView(cbvDesc, cbvHandle0);&#xA;&#xA;CD3DX12_CPU_DESCRIPTOR_HANDLE cbvHandle1(mCbvHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart(), d3dDevice-&amp;gt;GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV), 1);&#xA;d3dDevice-&amp;gt;CreateConstantBufferView(cbvDesc, cbvHandle1);&#xA;&#xA;// Initialize and map the constant buffers. We don't unmap this until the&#xA;// app closes. Keeping things mapped for the lifetime of the resource is okay.&#xA;DX::ThrowIfFailed(mWVPConstantBuffer-&amp;gt;Map(0, nullptr, reinterpret_cast&amp;lt;void**&amp;gt;(&amp;amp;mMappedWVPBuffer)));&#xA;memcpy(mMappedWVPBuffer, &amp;amp;mWVPData, sizeof(mWVPData));  &#xA;&#xA;DX::ThrowIfFailed(mDirLightConstantBuffer-&amp;gt;Map(0, nullptr, reinterpret_cast&amp;lt;void**&amp;gt;(&amp;amp;mMappedDirLightBuffer)));&#xA;memcpy(mMappedDirLightBuffer, &amp;amp;mDirLightData, sizeof(mDirLightData));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note: Slot b0 works perfect. I can change world view projection data just fine. But b1 does not work at all. What am I doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="113" LastActivityDate="2015-11-07T18:26:36.093" Title="DirectX 12 Constant Buffer Binding" Tags="&lt;c++&gt;&lt;directx12&gt;&lt;constant-buffer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1699" PostTypeId="2" ParentId="1698" CreationDate="2015-11-07T18:26:36.093" Score="4" Body="&lt;p&gt;The problem looks like it's in this line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;d3dDevice-&amp;gt;CreateConstantBufferView(cbvDesc, cbvHandle1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first parameter should be &lt;code&gt;&amp;amp;cbvDesc[1]&lt;/code&gt;. As it is now, you're setting up two copies of &lt;code&gt;cbvDesc[0]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, it looks like you've reversed the second and third arguments to the &lt;code&gt;cbvHandle1&lt;/code&gt; constructor: the second argument should be the offset (1) and the third should be the increment size. Not that it really matters, since those two values just get multiplied together anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, I don't think you need to set up two separate descriptor ranges when creating the root signature; since they're contiguous, you could just use a single range of two descriptors. But it shouldn't make a difference to the results.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-11-07T18:26:36.093" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1700" PostTypeId="1" CreationDate="2015-11-08T23:43:16.020" Score="3" ViewCount="331" Body="&lt;p&gt;If I want to model a large environment, how can I solve the problem of earth curvature and horizon?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use an environment map for the sky, but for the ground what can I do?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I have to model the ground with a big plane, disk or a spherical cap?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a general procedure to solve this problem in computer graphics?&lt;/p&gt;&#xA;" OwnerUserId="1636" LastEditorUserId="127" LastEditDate="2015-11-10T16:57:18.720" LastActivityDate="2015-11-10T16:57:18.720" Title="Earth curvature and horizon in modeling large scenes" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1701" PostTypeId="2" ParentId="1700" CreationDate="2015-11-09T00:13:20.613" Score="6" Body="&lt;p&gt;Having the horizon fall off is simply dropping the ground in the distance down somewhat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A point $x$ km away if you follow the curve of the planet will be $r-r\cdot \cos \frac{x}{r}$ down and $r\cdot \sin \frac{x}{r}$ out horizontally where $r$ is the radius of the planet you are modeling (~6.3k km for earth). In the vertex shader you can account for that before you apply the view and projection matrix.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2015-11-09T00:13:20.613" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1702" PostTypeId="1" CreationDate="2015-11-10T06:18:54.503" Score="4" ViewCount="618" Body="&lt;p&gt;Could anyone please explain to me how drawing works with respect to scrolling?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose there is a window, which has an area where one can draw to (a &quot;canvas&quot;). Are there two copies of this canvas? One for CPU and one for GPU? I mean, I know one could copy from main memory to graphic card memory very quickly with OpenGL (PBO) so one way to draw is first draw with software in main memory and the &quot;blit&quot; it to GPU, right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I would assume that when the window scrolls there is some GPU functionality which would rapidly copy over the non-dirty parts in the appropriate positions without leaving GPU-land and then ask the CPU for redrawing the dirty/missing parts. But now I have two un-synced copies of the canvas! So how does it work? Do I do the scrolling in main memory in software and upload the whole canvas to GPU as the first time? Or perhaps I scroll the canvas in GPU and &quot;download&quot; then download it to CPU-land and &quot;repair&quot; it there? Or something else entirely? Perhaps somehow I don't have to care that the copies are unsynchronized?&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2015-11-13T10:38:50.640" Title="Blit and scroll" Tags="&lt;gpu&gt;&lt;drawing&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1703" PostTypeId="1" CreationDate="2015-11-10T15:27:38.280" Score="8" ViewCount="299" Body="&lt;p&gt;I am trying to implement (in C#) an image perturbation algorithm presented in the book &quot;Texturing and modeling - K. Perlin et al&quot; (page 91 if anyone has it), which distorts an image.&#xA;The following code is in Renderman language:&#xA;The texture access&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Ct = texture(&quot;example.tx&quot;, s, t);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is replaced by&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;point Psh;&#xA;float ss, tt;&#xA;Psh = transform(&quot;shader&quot;, P);&#xA;ss = s + 0.2 * snoise(Psh);&#xA;tt = t + 0.2 * snoise(Psh+(l.5,6.7,3.4));&#xA;Ct = texture(&quot;example.tx&quot;, ss, tt);&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;transforming the image on the left to that on the right.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/vxxJX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vxxJX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I undestood, instead of accessing coordinate $(s,t)\in[0,1]$ we access slighty perturbed coordinates $(ss,tt)$ and display them at place $(s,t)$, thus creating an image that looks slightly perturbed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$snoise(x)$ is defined as $(noise(x)*2)-1$, mapping noise from $[0,1]$ to $[-1,1]$, and in the RenderMan documentation $noise(P)$ where P is a point, returns a value based on some noise (most likely perlin or lattice).&#xA;(&lt;a href=&quot;http://renderman.pixar.com/resources/current/RenderMan/noiseFunctions.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://renderman.pixar.com/resources/current/RenderMan/noiseFunctions.html&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I don't understand is what the transform function does, which is supposed to map the 3d point P into the &quot;shader&quot; space, and how can it be implemented.&#xA;Also, I'm not sure whether noise(x) returns a 3d point, a float (would make more sense) and if I can use a simple 2d implementation of Perlin's noise to reach the same desired effect.&lt;/p&gt;&#xA;" OwnerUserId="2024" LastEditorUserId="2041" LastEditDate="2017-01-05T10:45:29.997" LastActivityDate="2017-01-05T10:45:29.997" Title="Perturbed image texture implementation from renderman language" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1704" PostTypeId="2" ParentId="1702" CreationDate="2015-11-10T16:52:41.847" Score="2" Body="&lt;p&gt;Traditionally, there are two ways to display something on the screen:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Re-draw it from scratch every frame (or, every time something changes)&lt;/li&gt;&#xA;&lt;li&gt;Track the sections of the screen (ie. &quot;dirty rectangles&quot;) that change each frame, and update only those portions.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The first option is what most modern games / animations will do. Each frame, you re-submit all the draw calls / re-upload any textures to the GPU that have changed, then ask the GPU to draw everything and show it on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second option is what most old 2D games did, as well as most window applications (ie. GUI programs that don't have a lot of change going on). One implementation would be to have a local CPU copy of the screen, a GPU copy, and a series of buffers to transfer data between them.&#xA;So for every frame where there were changes:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Blit pixel data of the dirty rectangle areas to one of the data transfer buffers. &lt;/li&gt;&#xA;&lt;li&gt;Copy the buffer to the GPU&lt;/li&gt;&#xA;&lt;li&gt;Use the GPU to blit the pixel data from the data transfer buffer to the GPU copy.&lt;/li&gt;&#xA;&lt;li&gt;Present&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For more info, I suggest looking up how some window managers do compositing. There is a decent explaination of how WPF works &lt;a href=&quot;https://jeremiahmorrill.wordpress.com/2011/02/14/a-critical-deep-dive-into-the-wpf-rendering-system/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. And an excellent post about how Chrome accelerates their browser rendering &lt;a href=&quot;https://www.chromium.org/developers/design-documents/gpu-accelerated-compositing-in-chrome&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2015-11-10T16:52:41.847" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1706" PostTypeId="1" CreationDate="2015-11-11T04:18:18.883" Score="7" ViewCount="758" Body="&lt;p&gt;With directX12 they introduced heap descriptors. A way for us to describe the table for resources we wanted to send to the shaders. I'm admittedly very new at computer graphics and only tinkered a bit in directX11. I have not toyed with instancing or any more complicated things right now so I have a object for every mesh that has these defintions.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Microsoft::WRL::ComPtr&amp;lt;ID3D12Resource&amp;gt; mVertexBuffer;&#xA;D3D12_VERTEX_BUFFER_VIEW mVertexBufferView;&#xA;&#xA;// Index Buffer&#xA;Microsoft::WRL::ComPtr&amp;lt;ID3D12Resource&amp;gt; mIndexBuffer;&#xA;D3D12_INDEX_BUFFER_VIEW mIndexBufferView;&#xA;&#xA;// World View Projection Constant Buffer&#xA;Microsoft::WRL::ComPtr&amp;lt;ID3D12Resource&amp;gt; mWVPConstantBuffer;&#xA;WVPData mWVPData;      &#xA;UINT8* mMappedWVPBuffer;&#xA;&#xA;// Directional Light Constant Buffer&#xA;Microsoft::WRL::ComPtr&amp;lt;ID3D12Resource&amp;gt; mDirLightConstantBuffer;&#xA;DirLightData mDirLightData;&#xA;UINT8* mMappedDirLightBuffer;&#xA;&#xA;// CBVHeap&#xA;Microsoft::WRL::ComPtr&amp;lt;ID3D12DescriptorHeap&amp;gt; mCbvHeap;&#xA;UINT mCbvDescriptorSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A vertex buffer, index buffer, the cbvHeap, and two constant buffers. One for the transformation matrices and one for the directional light data. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wasn't really sure what the cbvHeap (constant buffer view heap) was really doing. I just knew how to use it to my content to the screen. So I experimented. I took the cbvHeap and mCbvDescriptorSize out of the mesh object and put it in the scene object (where the array of meshes were contained) and then used the same cbvheap across all my meshes. This did not work as it gave one consistent color across the whole mesh. (ie: The same constant buffer was used for every mesh giving them the same diffuse and ambient light data.) What exactly is the descriptor heap doing that caused this? And are my definitions right per mesh?&lt;/p&gt;&#xA;" OwnerUserId="113" LastActivityDate="2016-10-06T00:59:46.477" Title="DirectX12 CbvHeap" Tags="&lt;c++&gt;&lt;directx12&gt;&lt;constant-buffer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1707" PostTypeId="2" ParentId="1706" CreationDate="2015-11-11T22:47:47.257" Score="10" Body="&lt;p&gt;In DX12, a descriptor is a small record, basically a pointer, that tells the GPU where to find some data such as a constant buffer. Since each object is going to have its own constant buffer data with its own particular transforms, lighting/material properties, etc., each object also has to end up with a separate set of descriptors to point to its individual data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a couple of ways to set up descriptors in DX12. First, you can add commands in a command list that update descriptors directly in the root table. For example, you can use &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn903911.aspx&quot;&gt;&lt;code&gt;SetGraphicsRootConstantBufferView()&lt;/code&gt;&lt;/a&gt; to set up descriptors for an object's constant buffers, then draw the object. Repeat for multiple objects. These descriptors will be saved in the command list, and will get applied in-order as the command list is executed on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other way to do it is use descriptor heaps. A descriptor heap is basically a buffer that stores an array of descriptors. With this approach, the command list doesn't save descriptors for you; you have to manage them yourself. If you overwrite any descriptors before the GPU consumes them, then you'll get wrong results. This sounds like what's happening in your program: you're likely overwriting the same descriptor in the heap every time you issue an object's draw commands on the CPU, so by the time the GPU executes the command list, only the last descriptor written is still there, and that descriptor gets applied to all of the objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this, you have to allocate enough space in the descriptor heap to store all the descriptors you're going to use for the frame. Write all the objects' descriptors to the heap. Then when drawing each object, point the shader at the that object's data using &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn903912.aspx&quot;&gt;&lt;code&gt;SetGraphicsRootDescriptorTable()&lt;/code&gt;&lt;/a&gt; with an offset handle that points to the spot in the heap where that object's descriptors live.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As long as you're still just trying to learn and get a simple app running, I would probably stick with the root table approach as much as possible. For a more serious high-performance app, there are probably optimizations you can do with descriptor heaps, such as keeping all the constants and textures for a given material together so you can reuse them across many objects and bind them all in one call. You'd probably also want to avoid having a constant buffer and descriptor heap per object, but rather aggregate many objects' data into a few large buffers; this will be more efficient when you have lots of objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also worth noting that a serious 3D app will want to have multiple frames' command lists in flight at the same time, to obtain CPU/GPU parallelism, and this will require constant buffers and descriptor heaps to be lengthened to store multiple frames' worth of data. Again, this is something you can gloss over for learning/bringup purposes by just building a single command list at a time, submitting it, and waiting for it to finish before going on to the next frame.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-11-11T22:47:47.257" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1708" PostTypeId="1" AcceptedAnswerId="1709" CreationDate="2015-11-12T10:42:17.850" Score="2" ViewCount="2491" Body="&lt;p&gt;Let's say I have an image of an object against a white background. I want to crop so that the image fills the available space.&#xA;This takes 10px off:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;convert original.png -shave 10x10 shaved.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How would I implement something like this that detects the edges of the object, thus cropping a variable number of pixels from each side?&lt;/p&gt;&#xA;" OwnerUserId="2040" LastActivityDate="2015-11-12T13:36:52.010" Title="How to crop with edge-detection using imagemagick" Tags="&lt;edge-detection&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2015-11-16T09:49:11.447" ContentLicense="CC BY-SA 3.0" />
  <row Id="1709" PostTypeId="2" ParentId="1708" CreationDate="2015-11-12T13:36:52.010" Score="1" Body="&lt;p&gt;Try &lt;code&gt;-trim&lt;/code&gt; instead of &lt;code&gt;-shave&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;convert original.png -trim trimmed.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;See the &lt;a href=&quot;http://www.imagemagick.org/Usage/crop/#trim&quot; rel=&quot;nofollow&quot;&gt;docs&lt;/a&gt; for this and other options.&lt;/p&gt;&#xA;" OwnerUserId="192" LastActivityDate="2015-11-12T13:36:52.010" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1710" PostTypeId="2" ParentId="1703" CreationDate="2015-11-12T13:40:36.583" Score="6" Body="&lt;p&gt;As you've surmised, the &lt;code&gt;transform()&lt;/code&gt; function transforms points from one co-ordinate space to another. (There are also &lt;code&gt;vtransform()&lt;/code&gt; and &lt;code&gt;ntransform()&lt;/code&gt; for transforming direction vectors and normal vectors, respectively.) The string argument names the co-ordinate space to transform into.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;http://renderman.pixar.com/resources/current/RenderMan/rslGuidelines97.html#part-2-coordinate-spaces&quot;&gt;Renderman Shading Guidelines&lt;/a&gt; have this to say about it:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;At the start of shader execution, all point, vector, normal, and matrix variables are expressed in the &quot;current&quot; coordinate system. Exactly which coordinate system is &quot;current&quot; is implementation-dependent. It just so happens to be that &quot;current&quot; is &quot;camera&quot; for PRMan*, but you should never count on this behavior - it is entirely possible that other RenderMan compliant renderers (including future renderers from Pixar) may use some other space (like &quot;world&quot;) as &quot;current&quot; space.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It goes on to give a case like this as an example. Most lighting calculations should be done in camera space, but evaluating a noise function should be in the object's co-ordinate system, because you want the noise to stay the same as the object moves through world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your C# implementation, you'll also need to transform the point being shaded from camera space to the object's co-ordinate system. Maybe you've done this already before computing the texture co-ordinates. If not, you'll need to multiply by the object's transformation matrix. Remember that the only use of this transformed point is as an input (like a seed) to the Perlin noise generator. It sets the domain that the noise varies over: world space co-ordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In RSL, the &lt;code&gt;noise()&lt;/code&gt; function can return any type you like: a &lt;code&gt;float&lt;/code&gt;, a &lt;code&gt;color&lt;/code&gt;, a &lt;code&gt;point&lt;/code&gt;, or a &lt;code&gt;vector&lt;/code&gt;. As you're adding it to another &lt;code&gt;float&lt;/code&gt; (&lt;code&gt;u&lt;/code&gt; or &lt;code&gt;v&lt;/code&gt;), you'll get a &lt;code&gt;float&lt;/code&gt; in this code. Really, the two &lt;code&gt;noise()&lt;/code&gt; calls, added to &lt;code&gt;s&lt;/code&gt; and &lt;code&gt;t&lt;/code&gt;, are acting to generate a single 2D noise vector. In your own code, if you are using a 2D vector to store your texture co-ordinates, you can use a single noise function that returns a 2D vector, to get the same effect in one line of code.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If you're interested in making a nice noise generator, &lt;a href=&quot;https://www.shadertoy.com/results?query=noise&quot;&gt;Shadertoy&lt;/a&gt; has a lot of noise shaders featuring different variants of Perlin noise with different properties (isotropic or not, configurable smoothness and bandwidth) and is worth looking at for inspiration as well as implementation hints.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2015-11-12T13:40:36.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1711" PostTypeId="2" ParentId="166" CreationDate="2015-11-12T17:01:58.687" Score="2" Body="&lt;p&gt;You can use OpenGl 4.x tessellation shaders to convert Bezier control points into polygons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A google search for &quot;tessellation shader bezier&quot; found this outline describing the tessellation of Bezier surfaces and curves:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://web.engr.oregonstate.edu/~mjb/cs519/Handouts/tessellation.1pp.pdf&quot; rel=&quot;nofollow&quot;&gt;http://web.engr.oregonstate.edu/~mjb/cs519/Handouts/tessellation.1pp.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This offloads the Bezier evaluation from the CPU to the GPU and reduces the data flow across the bus.&lt;/p&gt;&#xA;" OwnerUserId="2049" LastEditorUserId="2049" LastEditDate="2015-11-13T19:53:20.723" LastActivityDate="2015-11-13T19:53:20.723" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1713" PostTypeId="1" CreationDate="2015-11-13T06:01:34.150" Score="1" ViewCount="212" Body="&lt;p&gt;Please help me tackle the below question:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Explain THREE forms of affine transformations using relevant examples for each case.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The answers I want to see are scaling, rotation and reflection.&lt;/p&gt;&#xA;" OwnerUserId="2055" LastEditorUserId="231" LastEditDate="2015-11-13T09:52:29.547" LastActivityDate="2015-11-13T13:08:52.040" Title="What are forms of affine transformations?" Tags="&lt;vector-graphics&gt;&lt;affine-transformations&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1714" PostTypeId="2" ParentId="1713" CreationDate="2015-11-13T09:32:27.343" Score="6" Body="&lt;p&gt;&lt;em&gt;Note: I have answered before the edit from trichoplax and I thought you were searching for other transformations other than the one you mentioned. The informations below are still useful so I will keep the answer here, but it does not directly answer your question.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Affine transformations (surprise!) map affine spaces to affine spaces. An affine space is substantially a vector space where you can establish an origin and define points as tuples of their coordinates. This is far from a formal definition, if you are interested in one I can edit the answer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now an affine transformation $T$ transform points into points and must preserve affine combinations: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$T(\lambda_1 P_1 + \lambda_2 P_2 + ...  +  \lambda_n P_n) = \lambda_1 T(P_1) + \lambda_2 T(P_2) + ... + \lambda_n T(P_n)  $   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given $\sum_{i}^{n} \lambda_i = 1 $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However these transformations can't be arbitrary as the following must be preserved: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Parallelism is preserved&lt;/em&gt;&lt;/strong&gt;. This means that if you transform parallel lines they remain parallel after the affine transformation.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Relative ratios are preserved&lt;/em&gt;&lt;/strong&gt;. This means that if you have $R = (1-\beta) P + \beta Q$  then $T(R) = (1 - \beta) T(P) + \beta T(Q)$ &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Addition between vector and points are preserved&lt;/em&gt;&lt;/strong&gt;. Meaning that $T( P + \vec{v} ) = T(P) + T(\vec{v})$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;With these properties in mind you can come up with a very big number of affine transforms yourself. A couple of obvious ones other the ones you mentioned are: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Translation&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$T_vp = &#xA;\begin{bmatrix}&#xA;1&amp;amp;0&amp;amp;0&amp;amp;v_x\\0&amp;amp;1&amp;amp;0&amp;amp;v_y\\0&amp;amp;0&amp;amp;1&amp;amp;v_z\\0&amp;amp;0&amp;amp;0&amp;amp;1\end{bmatrix}&#xA;\begin{bmatrix}&#xA;p_x+v_x\\p_x+v_y\\p_z+v_z\\1\end{bmatrix}=p+v$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That moves a point into a specific direction by a specific amount specified by a displacement vector. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Shearing&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fpg2D.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fpg2D.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;image from wikipedia&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is a transform that displace all points in a given direction by an amount that is proportional to their perpendicular distance to a line parallel to that direction. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example the transform matrix for an horizontal shear in a 2D space is given by: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}x'\\y'\end{bmatrix} = \begin{bmatrix}x+my\\y\end{bmatrix} = &#xA;\begin{bmatrix}1&amp;amp;m\\0&amp;amp;1\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Again, these two are just example, the important information you should really keep is the definition (and properties) of an affine transform; with that in mind it shouldn't be too hard to recognize an affine transform.  Also note that combining affine transforms will give you an affine transform! &lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-11-13T13:08:52.040" LastActivityDate="2015-11-13T13:08:52.040" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1715" PostTypeId="2" ParentId="1702" CreationDate="2015-11-13T10:38:50.640" Score="2" Body="&lt;p&gt;Let's take web browsers as an example. On mobile, both Chrome and Firefox draw the page content on the GPU, and they typically have a lot of scrolling, so it's a relevant example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They work a little like Google Maps or Open Street Map's tileserver. They slice the page up into tiles and draw each tile into a texture. (The textures may well be in a texture atlas; I'm afraid I don't know the specifics.) Drawing the final screen simply consists of drawing a small number of textured squares in the correct positions. This approach makes scrolling very easy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you scroll, it doesn't have to regenerate the whole page starting from the DOM (the web page equivalent of the scene graph): it just moves the quads around so that each textured tile moves around the viewport. When a new row or column of tiles is about to come into view, the page renderer has to draw the new tiles before you want to see them. At the other end of the screen, you can keep tiles that are no longer in view, but they can be disposed of if you start to run out of texture memory. Because all the tiles are the same size, you can simply draw the new tiles over old textures you don't want any more.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's just the same as in Google Maps: when you scroll in that, you can usually see a placeholder texture if new tiles are visible before they've finished downloading. And the page keeps a cache of tiles you've looked at before, but it can destroy any that are no longer visible in order to free some memory if necessary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The tile technique also allows progressive refinement, which is important to let you scroll at 60 fps on a mobile platform without enough compute power. If it's rendering the tiles too slowly, it can draw the textures at lower resolution first (while you're scrolling), and then redraw them at full resolution later, if they stay on screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, there isn't any special functionality for blitting some of the last frame into a new position in the new frame, but by rendering to texture, we can access the same texture from the next frame, throwing away any parts that are no longer useful. Some games also use this technique for mostly static content backgrounds, 2D world maps, &amp;amp;c.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have to update small portions of the scrolling content, it's easy: just redraw the tiles that changed. The code that updates the tiles doesn't care what screen position they're being displayed, because the final frame renderer puts each tile in the right place. You don't have &quot;two un-synced copies of the canvas&quot; and it doesn't matter whether you're drawing each tile on the CPU or GPU (or both).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The word &quot;static&quot; there was important. If much of the background is changing every frame, you don't get any advantage from tiles, because you have to update every tile every frame. In that case, you should just throw away the old frame and draw the new frame from scratch. That's why many 2D games don't use this technique even if they show scrolling content (e.g. a Mario game).&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;In summary:&lt;/h3&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If your scrolling content is completely static and small enough to fit in memory, draw it in a big texture and render a textured quad per-frame.&lt;/li&gt;&#xA;&lt;li&gt;If your scrolling content is too big to fit in memory, or small regions of it need updating sometimes, draw it in tiles, render all the visible tiles per-frame, and add something to load and unload tiles when necessary.&lt;/li&gt;&#xA;&lt;li&gt;If most tiles change most frames, just draw the visible region every frame.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Knowing which case you're in, and being able to separate out the static parts from the changing parts, constitutes a lot of the work of the graphics developer :-)&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2015-11-13T10:38:50.640" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1716" PostTypeId="1" AcceptedAnswerId="1724" CreationDate="2015-11-13T10:48:15.710" Score="3" ViewCount="178" Body="&lt;p&gt;I have a small project that needs to extract the perceptually-salient colors of an image, in javascript. There are a few libraries out there (color-thief.js, vibrant.js). The trouble is, I'm finding that &lt;a href=&quot;https://color.adobe.com/create/image/&quot; rel=&quot;nofollow&quot;&gt;adobe color's&lt;/a&gt; image extraction does a noticeably better job of recognizing the little high-contrast highlight colors which make a big visual aesthetic difference, even though they represent a small number of pixels. (This is the &quot;color mood&quot; option). For example, the color of lipstick a person wears, or small decorations on a big cake.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think (?) Adobe doesn't provide an API for their Color CC any more, but in any case I'd rather not rely on it. Is there a javascript library out there with similar functionality that provides access to some sort of functionality that maximizes dissimilarity between hues?&lt;/p&gt;&#xA;" OwnerUserId="2040" LastEditorUserId="2040" LastEditDate="2015-11-13T10:59:19.023" LastActivityDate="2015-11-16T10:33:47.740" Title="Javascript color extraction library" Tags="&lt;color&gt;&lt;color-separation&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1717" PostTypeId="2" ParentId="1694" CreationDate="2015-11-13T16:50:33.490" Score="3" Body="&lt;p&gt;Both of your two proposed solutions are valid, with different properties. Which you choose is purely a design issue. The difference is that your probabilistic rays/particles (1) don't need to store their energy: they all have the same amount of energy, so you can just count particles to sum the energy. Your partial particles (2) need to store an energy so you can split them up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The advantage of 1 is that each ray is smaller. Also, it's easy to keep track of where the energy ended up, because you can use the intersections where the ray was dropped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because you're only reflecting or discarding rays, the number of in-flight rays will decrease with each bounce, so you might find it harder to keep batches of rays together for better SIMD or parallel performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, because you're probabilistically discarding rays, you'll get a lot more noise in your results for the same number of rays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second solution is closer to a traditional ray-tracer, so you may find it easier to use existing algorithms and code. You can use fewer primary rays, and the number of rays in each batch is constant at first (but gets worse when the brightnesses start to reach zero).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also a lot more efficient to track multiple frequencies this way. If you give each ray a spectrum or RGB energies, the material can have a different effect on different colours without you having to fire multiple batches of rays (duplicating the ray intersection work).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, you'll need a second data structure to count up where energy was absorbed, if you want to track that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your place, I'd probably use the second solution, but it depends on what other software you're trying to integrate with e.g. an existing ray-tracing library or photon representation, and what you need to do with the output/results.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2015-11-13T16:50:33.490" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1718" PostTypeId="1" AcceptedAnswerId="1719" CreationDate="2015-11-13T17:38:28.863" Score="23" ViewCount="17272" Body="&lt;p&gt;I have a mesh and in the region around each triangle, I want to compute an estimate of the principal curvature directions. I have never done this sort of thing before and &lt;a href=&quot;https://en.wikipedia.org/wiki/Principal_curvature&quot;&gt;Wikipedia&lt;/a&gt; does not help a lot. Can you describe or point me to a simple algorithm that can help me compute this estimate?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume that I know positions and normals of all vertices.&lt;/p&gt;&#xA;" OwnerUserId="14" LastActivityDate="2019-11-13T17:19:46.943" Title="What is the simplest way to compute principal curvature for a mesh triangle?" Tags="&lt;mesh&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="14" ContentLicense="CC BY-SA 3.0" />
  <row Id="1719" PostTypeId="2" ParentId="1718" CreationDate="2015-11-14T00:43:02.683" Score="28" Body="&lt;p&gt;When I needed an estimate of mesh curvature for a skin shader, the algorithm I ended up settling on was this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I computed a scalar curvature for each edge in the mesh. If the edge has positions $p_1, p_2$ and normals $n_1, n_2$, then I estimated its curvature as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\text{curvature} = \frac{(n_2 - n_1) \cdot (p_2 - p_1)}{|p_2 - p_1|^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This calculates the difference in normals, projected along the edge, as a fraction of the length of the edge. (See below for how I came up with this formula.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, for each vertex I looked at the curvatures of all the edges touching it. In my case, I just wanted a scalar estimate of &quot;average curvature&quot;, so I ended up taking the geometric mean of the absolute values of all the edge curvatures at each vertex. For your case, you might find the minimum and maximum curvatures, and take those edges to be the principal curvature directions (maybe orthonormalizing them with the vertex normal). That's a bit rough, but it might give you a good enough result for what you want to do.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The motivation for this formula is looking at what happens in 2D when applied to a circle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/PL8jY.png&quot; alt=&quot;curvature formula applied to two points on a circle&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose you have a circle of radius $r$ (so its curvature is $1/r$), and you have two points on the circle, with their normals $n_1, n_2$. The positions of the points, relative to the circle's center, are going to be $p_1 = rn_1$ and $p_2 = rn_2$, due to the property that a circle or sphere's normals always point directly out from its center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore you can recover the radius as $r = |p_1| / |n_1|$ or $|p_2| / |n_2|$. But in general, the vertex positions won't be relative to the circle's center. We can work around this by subtracting the two:&#xA;$$\begin{aligned}&#xA;p_2 - p_1 &amp;amp;= rn_2 - rn_1 \\&#xA;&amp;amp;= r(n_2 - n_1) \\&#xA;r &amp;amp;= \frac{|p_2 - p_1|}{|n_2 - n_1|} \\&#xA;\text{curvature} = \frac{1}{r} &amp;amp;= \frac{|n_2 - n_1|}{|p_2 - p_1|}&#xA;\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result is exact only for circles and spheres. However, we can extend it to make it a bit more &quot;tolerant&quot;, and use it on arbitrary 3D meshes, and it seems to work reasonably well. We can make the formula more &quot;tolerant&quot; by first projecting the vector $n_2 - n_1$ onto the direction of the edge, $p_2 - p_1$. This allows for these two vectors not being exactly parallel (as they are in the circle case); we'll just project away any component that's not parallel. We can do this by dotting with the normalized edge vector:&#xA;$$\begin{aligned}&#xA;\text{curvature} &amp;amp;= \frac{(n_2 - n_1) \cdot \text{normalize}(p_2 - p_1)}{|p_2 - p_1|} \\&#xA;&amp;amp;= \frac{(n_2 - n_1) \cdot (p_2 - p_1)/|p_2 - p_1|}{|p_2 - p_1|} \\&#xA;&amp;amp;= \frac{(n_2 - n_1) \cdot (p_2 - p_1)}{|p_2 - p_1|^2}&#xA;\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Et voilà, there's the formula that appeared at the top of this answer. By the way, a nice side benefit of using the &lt;em&gt;signed&lt;/em&gt; projection (the dot product) is that the formula then gives a signed curvature: positive for convex, and negative for concave surfaces.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Another approach I can imagine using, but haven't tried, would be to estimate the &lt;a href=&quot;https://en.wikipedia.org/wiki/Second_fundamental_form&quot; rel=&quot;noreferrer&quot;&gt;second fundamental form&lt;/a&gt; of the surface at each vertex. This could be done by setting up a tangent basis at the vertex, then converting all neighboring vertices into that tangent space, and using least-squares to find the best-fit 2FF matrix. Then the principal curvature directions would be the eigenvectors of that matrix. This seems interesting as it could let you find curvature directions &quot;implied&quot; by the neighboring vertices without any edges explicitly pointing in those directions, but on the other hand is a lot more code, more computation, and perhaps less numerically robust.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A paper that takes this approach is &lt;a href=&quot;http://gfx.cs.princeton.edu/pubs/_2004_ECA/curvpaper.pdf&quot; rel=&quot;noreferrer&quot;&gt;Rusinkiewicz, &quot;Estimating Curvatures and Their Derivatives on Triangle Meshes&quot;&lt;/a&gt;. It works by estimating the best-fit 2FF matrix per triangle, then averaging the matrices per-vertex (similar to how smooth normals are calculated).&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2017-09-21T20:03:44.847" LastActivityDate="2017-09-21T20:03:44.847" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1720" PostTypeId="1" AcceptedAnswerId="1722" CreationDate="2015-11-14T03:57:21.970" Score="13" ViewCount="370" Body="&lt;p&gt;I am trying to understand why meshes that are smoothed in 3D studio (Modifiers/Smoother) end up having the same amount of vertices/faces before or after that process, as well as the exact same geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the following example, both meshes have 32 vertices and 60 faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JQ1KW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JQ1KW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dvqdb.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dvqdb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although I have experience working with programming (c++ and c#), I am quite a beginner with computer graphics. Thus my expectation was that the smoothed look of a smoothed mesh would require additional vertices, i.e. subdivision of triangles, in order to end up having a more detailed final mesh. However, that seems to be not the case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore I ask:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) how is the smoothing possible without increasing the detailing of the mesh geometry?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) does the smoothing at least increase the memory allocated/used for storing the new mesh in comparison to the original one?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Explanations are super welcome, but references (academic or not) are also appreciated.&lt;/p&gt;&#xA;" OwnerUserId="2061" LastActivityDate="2020-06-18T16:07:05.937" Title="Why smoothed meshes in 3D studio end up with the same number of vertices/triangles? How then can they be smoothed with the same geometry?" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;memory&gt;&lt;model&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1721" PostTypeId="2" ParentId="1718" CreationDate="2015-11-14T09:36:56.117" Score="21" Body="&lt;p&gt;Just to an add another way to the excellent @NathanReed answer, you can use mean and gaussian curvature that can be obtained with a discrete Laplace-Beltrami.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So suppose that the 1-ring neighbourhood of $v_i$ in your mesh looks like this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=&quot;https://i.stack.imgur.com/aWaSm.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aWaSm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$A(v_i)$ can be simply a $\frac{1}{3}$ of the areas of the triangles that form this ring and the indicated $v_j$ is one of the neighbouring vertices. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let's call $f(v_i)$ the function defined by your mesh (must be a differentiable manifold) at a certain point. The most popular discretization of the Laplace-Beltrami operator that I know is the cotangent discretization and is given by: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\Delta_S f(v_i) = \frac{1}{2A(v_i)} \sum_{v_j \in N_1(v_i)} (cot \alpha_{ij} + cot \beta_{ij}) (f(v_j) - f(v_i)) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $v_j \in N_1(v_i)$ means every vertex in the one ring neighbourhood of $v_i$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;With this is pretty simple to compute the mean curvature (now for simplicity let's call the function of your mesh at the vertex of interest simply $v$ ) is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$H = \frac{1}{2} || \Delta_S v || $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let's introduce the angle $\theta_j$ as &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;https://i.stack.imgur.com/ysAHy.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ysAHy.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Gaussian curvature is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$K = (2\pi - \sum_j \theta_j) / A$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After all of this pain, the principal discrete curvatures are given by: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$k_1 = H + \sqrt{H^2 - K} \ \  \text{and} \ \  k_2 = H - \sqrt{H^2 - K}$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If you are interested in the subject (and to add some reference to this post) an excellent read is:   &lt;a href=&quot;http://http.cs.berkeley.edu/~jrs/meshpapers/MeyerDesbrunSchroderBarr.pdf&quot; rel=&quot;noreferrer&quot;&gt;Discrete Differential-Geometry Operators&#xA;for Triangulated 2-Manifolds&lt;/a&gt; [Meyer et al. 2003]. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the images I thank my ex-professor Niloy Mitra as I found them in some notes I took for his lectures.&lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2015-11-14T09:54:46.410" LastActivityDate="2015-11-14T09:54:46.410" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1722" PostTypeId="2" ParentId="1720" CreationDate="2015-11-14T13:52:00.097" Score="16" Body="&lt;p&gt;Smooth in this case just makes the surface normals at vertices point the same way, when interpolated it looks smooth. Meshsmooth would add vertices.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;1) how is the smoothing possible without increasing the detailing of the mesh geometry?&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Human eyes cant actually see curvature except on the edges of objects. All they can do is approximate the smoothness and process the gradient slope. So having a continuous field does give a air of smoothness. The eye however is extremely sensitive to abrupt changes in color, and interprets that as a hard crease.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By interpolating the vertex normals your surface will get the appearance of smooth flowing. Since this normal is used to calculate the final reflected color you get a smooth color field.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EqJkQ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EqJkQ.png&quot; alt=&quot;Flat shaded vs smooth shaded&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: a flat shaded normal versus the normals of a smooth interplation. The black normal's lie on a vertex. The colored ones are interpolated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is nothing that says we need to do a linear interpolation. In fact by perturbing the normals we can cause the flat surface to change appearance. This is how bump mapping and normal mapping works. The effect can be convincing unless the surfaces edge plays a too big part in which place the illusion breaks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/l62Ov.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/l62Ov.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: a flat shaded surface (back), Smooth shaded (middle) and a mapped smooth normal. The illusion of a wavy surface breaks because the edge plays so prominent part in the image, you could instead increase the normals&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;2) does the smoothing at least increase the memory allocated&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Hard to say definitive things about the underlying graphics engine. The normals need to be emitted to the graphics card anyway, most likely this data is cached, but could be calculated on the fly (in both cases).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since Max uses smoothing groups it seems to me that memory usage is constant regardless. Hard to say, even if its not cached then it wouldn't make a big difference. It makes the shader tiny a bit more complicated, but only just most likely this complexity is present use it or not.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2015-11-14T13:52:00.097" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1723" PostTypeId="2" ParentId="166" CreationDate="2015-11-15T12:12:19.667" Score="0" Body="&lt;p&gt;One can do curved drawing with hardware. There is a method described in &lt;strong&gt;GPU Gems 3&lt;/strong&gt; that describes how to do this. User @yuriks actually comments this. I have actually made a quick a dirty demo for you to take a look at.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/D9F9k.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/D9F9k.png&quot; alt=&quot;curve&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: HW accelerated curve shapen (drawn usung a triangle) and &lt;a href=&quot;http://webglplayground.net/saved/9ZD4Uoi72Q&quot; rel=&quot;nofollow noreferrer&quot;&gt;webgl source&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-11-15T12:17:42.913" LastActivityDate="2015-11-15T12:17:42.913" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1724" PostTypeId="2" ParentId="1716" CreationDate="2015-11-16T10:33:47.740" Score="1" Body="&lt;p&gt;In the end I decided to use Leon Sorokin's RGBQuant.js for quantization, because it offered better flexibility over the color histogram/clustering method. I'm probably going to convert the quantized palette RGB output to HSV and implement custom clustering that picks out the &quot;highlight&quot; colors, favoring diversity of hue for colors with high value and saturation, and low occurrence frequency.&lt;/p&gt;&#xA;" OwnerUserId="2040" LastActivityDate="2015-11-16T10:33:47.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1725" PostTypeId="1" AcceptedAnswerId="2004" CreationDate="2015-11-16T15:25:18.107" Score="17" ViewCount="3041" Body="&lt;p&gt;There have been lots of papers over the years on different techniques for drawing height-field terrain in a ray-tracer. Some algorithms ray-march the grid directly (or via a quadtree); others transform the terrain into a polygon mesh and use a standard ray-triangle intersection test. The research seems to have moved on in the last few years, and it's hard to find papers written in the last decade, but the balance between memory and compute (both CPU and GPU) is still changing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What kind of algorithm gives best performance on high-end desktop machines nowadays? Or if there isn't a single answer, how do the performance characteristics of the current best algorithms differ?&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-10-26T10:32:07.660" Title="What's the current state-of-the-art algorithm for ray-tracing height-fields?" Tags="&lt;raytracing&gt;&lt;height-field&gt;" AnswerCount="3" CommentCount="5" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1726" PostTypeId="5" CreationDate="2015-11-16T15:46:10.380" Score="0" Body="&lt;p&gt;A height-field is a way of defining a surface with an image, where the co-ordinates of the image represent co-ordinates on a plane, and the intensity of the image at each point represents the height of the surface from the plane at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's a compact representation of 2.5D surfaces such as mountainous terrain, and is easier to create and modify in use than a polygon-based representation, but can't represent holes in the height field (such as a cave system or bridge).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compare &lt;em&gt;displacement map&lt;/em&gt;, which is essentially a height field on a smaller scale to represent microgeometry on a polygon mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See also:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Heightmap&quot; rel=&quot;nofollow&quot;&gt;Heightmap on Wikipedia&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-16T15:51:57.453" LastActivityDate="2015-11-16T15:51:57.453" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1727" PostTypeId="4" CreationDate="2015-11-16T15:46:10.380" Score="0" Body="Questions about image-based height-field representations, commonly used to represent a terrain." OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-16T15:52:11.630" LastActivityDate="2015-11-16T15:52:11.630" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1728" PostTypeId="2" ParentId="1725" CreationDate="2015-11-16T18:19:51.997" Score="4" Body="&lt;p&gt;The best I've personally seen is the stuff inigo quillez does, which is used in demoscene stuff. Ray March the terrain, taking larger steps the farther you get from the camera since (usually) detail matters less at a distance (exception = thin walls!). He uses penetration info and other easily gotten metrics to simulate ambient occlusion and other sophisticated lighting techniques.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a demo of the stuff in action:&#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=_YWMGuh15nE&quot; rel=&quot;nofollow&quot;&gt;https://www.youtube.com/watch?v=_YWMGuh15nE&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is IQ's page on the terrain raymarching which is a pretty interesting read:&#xA;&lt;a href=&quot;http://www.iquilezles.org/www/articles/terrainmarching/terrainmarching.htm&quot; rel=&quot;nofollow&quot;&gt;http://www.iquilezles.org/www/articles/terrainmarching/terrainmarching.htm&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, in modern games, the technique of &quot;screen space reflection&quot; often is just a ray march against the Z buffer of the rendered scene.  The Z buffer is really just a heightfield.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I saw some talks on this at siggraph 2014, and while some of the people were using similar techniques as IQ, a few were doing things not even as well as IQ, which was interesting to see :P&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2015-11-16T19:00:24.480" LastActivityDate="2015-11-16T19:00:24.480" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1729" PostTypeId="1" CreationDate="2015-11-16T22:52:48.660" Score="4" ViewCount="273" Body="&lt;p&gt;I'm using hardware tessellation to render a terrain mesh with variable LOD.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have this snippet on my tessellation control shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int edge1 = gl_InvocationID;&#xA;int edge2 = (gl_InvocationID + 1) % 3;&#xA;tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[edge1], gl_TessLevelOuter[edge2]), 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This should compute a color for the control point based on the tessellation level of the two edges that intersect on the point (using quad patches).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's all working fine except for this: &lt;code&gt;gl_TessLevelOuter[edge1]&lt;/code&gt; and &lt;code&gt;gl_TessLevelOuter[edge1]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This indexing always return 0 (I've tried using it directly as a color). To test the problem, I tried this: &lt;code&gt;gl_TessLevelOuter[gl_InvocationID]&lt;/code&gt;. It also has the same behavior.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I do something like this: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(gl_InvocationID == 0) {&#xA;    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[0], gl_TessLevelOuter[1]), 1.0);&#xA;}&#xA;else if(gl_InvocationID == 1) {&#xA;    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[1], gl_TessLevelOuter[2]), 1.0);&#xA;}&#xA;else if(gl_InvocationID == 2) {&#xA;    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[2], gl_TessLevelOuter[3]), 1.0);&#xA;}&#xA;else if(gl_InvocationID == 3) {&#xA;    tcs_out[gl_InvocationID].color = vec4(computeLODColor(gl_TessLevelOuter[3], gl_TessLevelOuter[0]), 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then it all works as expected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've checked the OpenGL specification and couldn't find anything about undefined behavior when indexing &lt;code&gt;gl_TessLevelOuter&lt;/code&gt; by a non-constant value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is, am I misunderstanding something, doing something against the specification or is it a GL implementation bug?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using an AMD Radeon HD 6700 with updated drivers, and there are no warnings compiling the shaders. (I've never seen a single shader compiler warning  though, so not sure if that's another problem)&lt;/p&gt;&#xA;" OwnerUserId="2064" LastActivityDate="2015-11-16T22:52:48.660" Title="Indexing gl_TessLevelOuter[] with gl_InvocationID on a tessellation control shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1730" PostTypeId="1" CreationDate="2015-11-17T16:21:39.400" Score="3" ViewCount="664" Body="&lt;p&gt;I have been trying to implement the following functionality in my code:&#xA;&lt;br&gt;There are 2 flags editMode and deleteMode, both set to zero.&#xA;&lt;br&gt;with the help of keys function in glutKeyBoardFunc(keys) the user can press keys ( 'c' and 'd' respectively) to set editMode and deleteMode to 1.The following is the algo for my mouse fucntion.:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;when ( editMode == 0)&#xA;       left click plots the point&#xA;       right click plots beizer curve&#xA;when ( editMode == 1)&#xA;       left click to displace the point to new postion and draw new beizer curve&#xA;       right click to exit editMode(i.e set editMode to 0)&#xA;when (deleteMode = 1)&#xA;       left click to click any point to delete it and draw new beizer curve&#xA;       right click to exit delete mode(i.e set deleteMode to 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem is when I am in editMode == 1, on first instance of left click my delete function is called to delete a point in beizer curve.&#xA;&lt;br&gt; Is there anything specific to the mouse listener which I am missing?&#xA;&lt;br&gt; Any new way to set controls for the above functions is welcome..&#xA;&lt;br&gt; Thank you.. &#xA;&lt;br&gt; EDIT  1:&#xA;&lt;br&gt; I modified the logic a bit. So I have:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;when( deleteMode == 0)&#xA;{       when (editMode == 0)&#xA;           left click to plot points &#xA;           right click to plot beizer&#xA;        else when (editFlag == 1)&#xA;           left click to displace points and draw new beizer curve&#xA;           right click to exit editMode(i.e set editMode to 0)&#xA;}&#xA;else&#xA;{&#xA;       when ( left_mouse_button == TRUE)&#xA;       { if(editMode == 0 ) delete chosen point and draw new beizer curve}&#xA;       when ( right_mouse_button == TRUE)&#xA;       { exit deleteMode e(i.e set deleteMode to 0) }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This works fairly for most of the time.And is serving my purpose for now.I have the assumption that the user goes to one mode and exits from that mode before going into other mode.&lt;/p&gt;&#xA;" OwnerUserId="1588" LastEditorUserId="1588" LastEditDate="2015-11-19T07:41:36.640" LastActivityDate="2015-11-19T07:41:36.640" Title="How does function for mouse in glutMouseFunc(mouse) work in openGL?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="7" ClosedDate="2015-12-02T18:12:39.340" ContentLicense="CC BY-SA 3.0" />
  <row Id="1731" PostTypeId="1" AcceptedAnswerId="1732" CreationDate="2015-11-17T21:51:32.030" Score="6" ViewCount="558" Body="&lt;p&gt;I have two rectangles — one with a fill (blue) and one with a stroke (red). The red rectangle is being offset (depending on the stroke width) so that it appears snug and outside the edge of the blue rectangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This set up works great except when I need to round the corners. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see I'm getting gaps between the rectangles and I'm stuck trying to figure out the math to calculate the right roundness amount for the outside rectangle (red).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://dl.dropboxusercontent.com/u/1414976/rectangles.png&quot; alt=&quot;Rectangles&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="2076" LastEditorUserId="127" LastEditDate="2015-11-18T08:22:57.373" LastActivityDate="2015-11-18T08:22:57.373" Title="How to calculate matching roundness of two offset rectangles?" Tags="&lt;curve&gt;&lt;2d&gt;&lt;bezier-curve&gt;&lt;vector-graphics&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1732" PostTypeId="2" ParentId="1731" CreationDate="2015-11-18T07:56:05.453" Score="7" Body="&lt;p&gt;What you (probably) want to achieve is something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Y1crM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y1crM.png&quot; alt=&quot;box&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When having a closer look at one of the corners and add a few lines, we see this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4w6mA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4w6mA.png&quot; alt=&quot;corner&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The black lines indicate that the center points of the circles along the borders of the red and blue boxes is the same. If the outer radius of the red box, for example, is $50px$, and the distance between the outer borders of the red and blue boxes is $25px$, this leads to a border radius of $50px - 25px = 25px$ for the blue box. The distance, obviously, is dependent on the stroke width of your red stroke.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Note: When creating the above images, I simply drew two filled boxes with rounded corners. So first a filled red box and then a smaller filled blue box above it. This also avoids some pixels being left white due to rounding errors (no pun intended).&lt;/p&gt;&#xA;" OwnerUserId="127" LastActivityDate="2015-11-18T07:56:05.453" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1734" PostTypeId="1" AcceptedAnswerId="1738" CreationDate="2015-11-19T01:58:30.133" Score="6" ViewCount="4839" Body="&lt;p&gt;After spending a few days making very little headway with a simple Raytracing program that implements Phong illumination (with shadows and no attenuation), I'm convinced I've made a logic error that I'm overlooking.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I understand it, the pseudo-code should look like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ambient light&#xA;for each light source&#xA;    direction of light = light point - point on the object&#xA;    test for an intersection starting at the point on the object, until you hit something&#xA;    if (the intersection test returned a distance &amp;gt; distance from point on object to light point)&#xA;    (do  diffuse and specular shading)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A one quick thing to mention about my implementation: the intersection test will return 9999999 if there is no intersection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some of the things I've tried are: inverting the direction of the shadow ray - no effect. Making the comparison intersection distance - light distance &gt; (some small epsilon value) - no change.  Manually moving the light source to the opposite side - the specular reflection moved to a new spot, but otherwise, no change.   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a picture of my most recent output, I'm trying to get a shadow in the bottom left corner of the light gray plane.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jnsiR.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jnsiR.jpg&quot; alt=&quot;The shadow should be in the lower left corner of the plane&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help would be greatly appreciated.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the relevant part of my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    //iterate through all lights&#xA;    if (myLights.size() &amp;gt; 0)&#xA;    {&#xA;        for (int i = 0; i &amp;lt; myLights.size(); i++)&#xA;        {&#xA;            //calculate the direction of the light&#xA;            glm::vec3 ldir = (myLights[i].position - surfacePoint);&#xA;            //this the length of the distance between the light and the surface&#xA;            float ldist= sqrt(pow(ldir.x, 2.0f) + pow(ldir.y, 2.0f) + pow(ldir.z, 2.0f)); &#xA;//check if the light can see the surface point&#xA;            float intersections = myObjGroup-&amp;gt;testIntersections(surfacePoint, normalize(ldir));&#xA;            if (abs(intersections-ldist)  &amp;gt; 0.0000001f)&#xA;            {&#xA;                //diffuse and specular shading have been cut for brevity&#xA;            }&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;edit: New image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2pAxT.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2pAxT.jpg&quot; alt=&quot;New image!&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2084" LastEditorUserId="2084" LastEditDate="2015-11-19T23:55:07.770" LastActivityDate="2015-11-20T09:15:00.770" Title="Shadow rays in Raytracing" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1736" PostTypeId="1" AcceptedAnswerId="1737" CreationDate="2015-11-19T04:10:30.597" Score="13" ViewCount="1828" Body="&lt;p&gt;When rendering VR ( stereo view ) environments, do you guys recommend just doing 2 frustum checks for determining what is to be drawn during the frustum culling pass or is there some other check that would be able to combine both frusta?&lt;/p&gt;&#xA;" OwnerUserId="288" LastActivityDate="2019-01-10T18:05:53.947" Title="VR and frustum culling" Tags="&lt;virtual-reality&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1737" PostTypeId="2" ParentId="1736" CreationDate="2015-11-19T05:09:30.257" Score="13" Body="&lt;p&gt;It's pretty easy to create a single frustum that encloses both of the individual eye frusta, as shown in this diagram created by Cass Everitt at Oculus. You just have to place the vertex of this frustum between the eyes and behind them a little bit. You can also increase the near plane distance to match the original near plane of the eye frusta.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TpHYa.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TpHYa.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Such a frustum includes a little space that wasn't in the union of the original two frusta. There's a small volume horizontally between the two eyes; also, the diagram doesn't show the vertical dimension, but pulling the frustum vertex back makes it include some space above and below the original frusta. However, for practical culling purposes it probably doesn't matter. Frustum culling is usually conservative anyway, and the extra space is only a few centimeters in thickness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also possible to simply cull against the original frustum top and bottom planes (which are shared between eyes) together with the outer side planes. These planes don't form a frustum, technically, but if using &quot;the usual&quot; culling algorithm that tests against one plane at a time, the algorithm will happily work on any set of planes you care to give it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sharing frustum culling, LOD selection, etc. between eyes, rather than re-doing it twice every frame, is a great way to optimize the CPU cost of stereo rendering. This is also a prerequisite if you want to use a rendering method that draws both eyes in a single pass, such as &lt;a href=&quot;https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/&quot; rel=&quot;noreferrer&quot;&gt;instanced stereo rendering&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-11-19T05:09:30.257" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1738" PostTypeId="2" ParentId="1734" CreationDate="2015-11-19T10:11:47.387" Score="6" Body="&lt;p&gt;Your &lt;code&gt;if&lt;/code&gt; condition makes me suspicious. You should include the diffuse and specular shading if the intersection test &lt;strong&gt;didn't&lt;/strong&gt; hit an object; that is, if &lt;code&gt;intersections &amp;gt; ldist&lt;/code&gt;. So, your code should look as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (intersections &amp;gt; ldist)&#xA;{&#xA;    colour += diffuse(...);&#xA;    colour += specular(...);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Your comparison with 0.0000001f suggests that you've also been having trouble with self-intersections (that is, with the ray intersecting the object being shaded). In a one-hit tracer, you can't fix that problem by simply discarding the intersection, because you still don't know whether the shadow ray would have intersected another object further along. To avoid self-intersections, you need to push the start point of the ray along its direction by epsilon:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 direction = normalize(ldir);&#xA;glm::vec3 start = surfacePoint + epsilon * direction;&#xA;float intersections = myObjGroup-&amp;gt;testIntersections(start, direction);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;One more thing: don't forget to test that the light is in front of the surface that you're illuminating. You can do this with the dot product of &lt;code&gt;ldir&lt;/code&gt; and the surface normal: if the dot product is positive, the light is on the correct side; if it's negative, the light is behind the surface and thus shadowed before you even cast a ray.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-20T09:15:00.770" LastActivityDate="2015-11-20T09:15:00.770" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1739" PostTypeId="5" CreationDate="2015-11-19T13:01:01.153" Score="0" Body="&lt;p&gt;A shadow is a dark region caused when light from an emitter is blocked by a shadowing object, causing a contrast between the dark region and the surrounding region which is fully lit. The emitter might be a point, cone, cylindrical light, an area light or image-based light. The shadowing object might be fully opaque or partially transparent, in which case it will cast coloured shadows (like stained glass). The dark region might be the lighting on another surface (the shadowed object), or it might be an environment shadow in some kind of volumetric medium.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This tag is appropriate whatever technique you're using to simulate shadows, whether by shadow rays in a raytracer, some kind of shadow maps or volumes, or something else completely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your problem is with shadowing indirect light in a global illumination system, you probably want a more specific tag. If your problem is with self-shadowing of micro-geometry, e.g. in the derivation of a shader, you should use a tag about that.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-19T13:48:46.187" LastActivityDate="2015-11-19T13:48:46.187" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1740" PostTypeId="4" CreationDate="2015-11-19T13:01:01.153" Score="0" Body="Shadows cast by objects in front of lights, whether raytraced, shadow maps, shadow volumes, or any other technique" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2015-11-19T13:48:52.383" LastActivityDate="2015-11-19T13:48:52.383" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1741" PostTypeId="1" CreationDate="2015-11-19T18:17:37.720" Score="7" ViewCount="279" Body="&lt;p&gt;I'm doing a quick and dirty automated deformation routine on a polygon body.  If it was a tree, and my axis was in the center of the tree, I would like to bend the body by bending the axis.  I would use a simple influencing algorithm to determine vertex point xyz displacement.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the concave side of the bend, how can I check for polygons that have overlapped or passed through each other, and how can I fix such polygons?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ObYbr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ObYbr.png&quot; alt=&quot;Rough Illustration of concept&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2091" LastEditorUserId="2091" LastEditDate="2015-11-20T18:26:08.183" LastActivityDate="2017-12-28T20:47:20.027" Title="After a deformation operation on polygons, how can I check for and fix inverted polys?" Tags="&lt;algorithm&gt;&lt;3d&gt;&lt;transformations&gt;&lt;mesh&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1743" PostTypeId="1" CreationDate="2015-11-19T22:31:31.463" Score="5" ViewCount="1051" Body="&lt;p&gt;I've been trying to implement the &lt;a href=&quot;https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm&quot; rel=&quot;nofollow&quot;&gt;Moller-Trumbore ray-triangle intersection algorithm&lt;/a&gt; in my raytracing code. The code is supposed to read in a mesh and light sources, fire off rays from the light source, and return the triangle from the mesh which each ray intersects. Here is my implementation of the algorithm:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Moller-Trumbore intersection algorithm&#xA;void getFaceIntersect(modelStruct m, ray r, hitFaceStruct&amp;amp; hitFaces)&#xA;{&#xA;    // Constant thoughout loop&#xA;    point origin = r.p0;&#xA;    point direction = r.u;&#xA;    hitFaces.isHit = false;&#xA;&#xA;    for (int i = 0; i &amp;lt; m.faces; i++)&#xA;    {&#xA;        // Get face vertices&#xA;        point v1 = m.vertList[m.faceList[i].v1];&#xA;        point v2 = m.vertList[m.faceList[i].v2];&#xA;        point v3 = m.vertList[m.faceList[i].v3];&#xA;&#xA;        // Get two edgess&#xA;        point edge1 = v2 - v1;&#xA;        point edge2 = v3 - v1;&#xA;&#xA;        // Get p&#xA;        point p = direction.cross(direction, edge2);&#xA;        // Use p to find determinant&#xA;        double det = p.dot(edge1, p);&#xA;&#xA;        // If the determinant is about 0, the ray lies in the plane of the triangle&#xA;        if (abs(det) &amp;lt; 0.00000000001)&#xA;        {&#xA;            continue;&#xA;        }&#xA;&#xA;        double inverseDet = 1 / det;&#xA;&#xA;        point v1ToOrigin = (origin - v1);&#xA;&#xA;        double u = v1ToOrigin.dot(v1ToOrigin, p) * inverseDet;&#xA;&#xA;        // If u is not between 0 and 1, no hit&#xA;        if (u &amp;lt; 0 || u &amp;gt; 1)&#xA;        {&#xA;            continue;&#xA;        }&#xA;&#xA;        // Used for calculating v&#xA;        point q = v1ToOrigin.cross(v1ToOrigin, edge1);&#xA;        double v = direction.dot(direction, q) * inverseDet;&#xA;&#xA;        if (v &amp;lt; 0 || (u + v) &amp;gt; 1)&#xA;        {&#xA;            continue;&#xA;        }&#xA;&#xA;        double t = q.dot(edge2, q) * inverseDet;&#xA;&#xA;        // gets closest face&#xA;        if (t &amp;lt; abs(hitFaces.s)) &#xA;        {&#xA;            hitFaceStruct goodStruct = hitFaceStruct();&#xA;            goodStruct.face = i;&#xA;            goodStruct.hitPoint = p;&#xA;            goodStruct.isHit = true;&#xA;            goodStruct.s = t;&#xA;            hitFaces = goodStruct;&#xA;            break;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The relevant code for hitFaceStruct and modelStruct is as follows:       &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef struct _hitFaceStruct&#xA;{&#xA;    int face; //the index of the sphere in question in the list of faces&#xA;    float s; //the distance from the ray that hit it&#xA;    bool isHit;&#xA;    point hitPoint;&#xA;} hitFaceStruct;&#xA;&#xA;typedef struct _modelStruct {&#xA;    char *fileName;&#xA;    float scale;&#xA;    float rot_x, rot_y, rot_z;&#xA;    float x, y, z;&#xA;    float r_amb, g_amb, b_amb;&#xA;    float r_dif, g_dif, b_dif;&#xA;    float r_spec, g_spec, b_spec;&#xA;    float k_amb, k_dif, k_spec, k_reflective, k_refractive;&#xA;    float spec_exp, index_refraction;&#xA;    int verts, faces, norms = 0;    // Number of vertices, faces, normals, and spheres in the system&#xA;    point *vertList, *normList; // Vertex and Normal Lists&#xA;    faceStruct *faceList;       // Face List&#xA;} modelStruct;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Whenever I shoot a ray, the values of &lt;code&gt;u&lt;/code&gt; or &lt;code&gt;v&lt;/code&gt; in the algorithm code always come out to a large negative number, rather than the expected small, positive one. The direction vector of the ray is normalized before I pass it on to the intersection code, and I'm positive I'm firing rays that would normally hit the mesh. Can anyone please help me spot my error here?&lt;/p&gt;&#xA;" OwnerUserId="2092" LastEditorUserId="127" LastEditDate="2015-12-04T21:46:16.450" LastActivityDate="2015-12-04T21:46:16.450" Title="Ray-triangle intersection algorithm not intersecting (C++)" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;algorithm&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1744" PostTypeId="1" CreationDate="2015-11-20T12:41:12.840" Score="1" ViewCount="74" Body="&lt;p&gt;I am looking for smooth way to enhance scans of golden emboss on. For now it takes sometimes hours to select out the golden part and then manipulate into suitable color. But I hope to learn some more neat way to do it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So here I provide 2 sample images, one before and other after:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vQvZi.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vQvZi.jpg&quot; alt=&quot;image after scan&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LFW5N.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LFW5N.jpg&quot; alt=&quot;image with enhanced golden emboss&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, after lot of annoying work to select out the golden part from background it still looks out clumsy. So, how it might work out smoothly? Is there some tutorial for that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basicly, what I did now? &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;made duplicate layer of background&lt;/li&gt;&#xA;&lt;li&gt;selected and erased background on duplicate layer with different tools (most work of which I'd like to get rid of)&lt;/li&gt;&#xA;&lt;li&gt;selected background and inverted selection&lt;/li&gt;&#xA;&lt;li&gt;feathered selection 5px&lt;/li&gt;&#xA;&lt;li&gt;with Colorize got it to some goldish tone&lt;/li&gt;&#xA;&lt;li&gt;slide layer opacity ca 60%&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2100" LastEditorUserId="16" LastEditDate="2015-11-20T15:53:18.737" LastActivityDate="2015-11-20T15:53:18.737" Title="How to enhance scans of golden emboss?" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1745" PostTypeId="1" AcceptedAnswerId="1746" CreationDate="2015-11-19T16:45:14.177" Score="12" ViewCount="1716" Body="&lt;p&gt;I'm trying to make a HSV representation of the xyY color space. To calculate hue from an $(x, y)$ color, I use the angle between that color and red (wavelength 745) on the xy chromacity diagram, with white $(\frac{1}{3}, \frac{1}{3})$ as the center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The saturation is the ratio between the distance between white and $(x, y)$, and white and a fully-saturated version of $(x, y)$ (which is the intersection between the line between $(\frac{1}{3}, \frac{1}{3})$ and $(x, y)$ and the edge of the chromacity diagram).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;xy chromacity diagram:&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/SzQiv.png&quot; width=&quot;300&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem that I'm having is that when I plot my color space (at value=1) and compare it to the HSV representation of RGB, the saturation (distance from center) doesn't seem to match how &quot;colorful&quot; the color actually is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;My color space (saturation seems wrong):&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/t1rfO.png&quot; width=&quot;300&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;HSV color space of RGB:&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/g0a9x.png&quot; width=&quot;300&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I calculate saturation instead?&lt;/p&gt;&#xA;" OwnerUserId="2110" OwnerDisplayName="abcd5555" LastEditorUserId="127" LastEditDate="2015-11-21T08:33:17.890" LastActivityDate="2018-03-06T05:35:38.617" Title="What would be the correct way to calculate saturation in this case?" Tags="&lt;color&gt;&lt;color-science&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1746" PostTypeId="2" ParentId="1745" CreationDate="2015-11-21T12:04:06.943" Score="5" Body="&lt;p&gt;There is unfortunately no good answer to this question. Simply it wont work. There is no good way to define colorful, it this context. Cie is trying to capture the physical measurement. It however does not succeed very well in relating the colors to each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Colors on the very outer arc represent spectral distributions of close to &lt;a href=&quot;https://en.wikipedia.org/wiki/Dirac_delta_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dirac delta function&lt;/a&gt;. So one could construct a model that says that a color is very colorful when it is a Dirac delta. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a unforeseen consequence of this definition though. Namely the magenta colors do not exist as Dirac Deltas. As these colors do not exist in the spectrum. So they consist of mixture of 2 wavelengths only. This would mean they are less colorful than most other colors.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Other problems&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, xyY is not perceptually uniform. So a straight line on the xyY does not represent interpolations between 2 color mixtures. Therefore making a polar transformation means you will have different color bases on same coordinates. Also precieved color do not really move over to your model. To do this properly you would need to do a extremely sophisticated transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many problems with converting color to a polar coordinates in that that is exactly contrary how vision works. White is also a bit problematic in this context. The distance to full saturated signal is different for each of the 3 different cones in the eye. Hell, even what is while depends on the surrounding colors and ambient color conditions. So aim afraid your trying to force a worldview that does not exist.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Finally&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;What would this be useful for? &lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2018-03-06T05:35:38.617" LastActivityDate="2018-03-06T05:35:38.617" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1747" PostTypeId="1" AcceptedAnswerId="1751" CreationDate="2015-11-22T04:39:39.110" Score="10" ViewCount="462" Body="&lt;p&gt;For example, while it's the current top-of-the-line GPU, the GTX 980 has a staggering 72.1 gigapixels/second fillrate, which with back-to-front rendering and/or Z buffer checks, seems almost ridiculously large, possibly even at 4k resolutions. As far as polygon counts go, modern GPUs can do tens to hundreds of millions of textured triangles without a hitch if you batch and/or instantiate them properly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With forward rendering, the amount of fragments that shaders will run on can quickly become overwhelming, but with deferred rendering, the cost is usually more-or-less constant, depending on the resolution, and we long since passed a point where most shading or post-processing effects can be done in realtime in 1080p.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either way, the limiting factors nowadays are most commonly draw call counts, and shading costs, both of which are kept relatively low by proper deferred rendering and geometry batching, so with that in mind, is culling more than just backfaces and out-of-frustrum polygons of any substantial benefit? Wouldn't the costs(CPU/GPU time, programmer time) outweight the benefits, a lot of the time?&lt;/p&gt;&#xA;" OwnerUserId="2111" LastEditorUserId="127" LastEditDate="2015-11-22T08:37:40.507" LastActivityDate="2015-11-23T07:36:55.853" Title="With modern fillrates and deferred rendering, is occlussion culling still relevant?" Tags="&lt;performance&gt;&lt;occlusion&gt;&lt;space-filling&gt;&lt;deferred-rendering&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1748" PostTypeId="1" AcceptedAnswerId="1749" CreationDate="2015-11-22T09:00:02.117" Score="7" ViewCount="1239" Body="&lt;p&gt;I'm trying to create a RYB color wheel with a smooth-looking gradient across the RYB spectrum. The angles of the HSV wheel are incorrect (yellow at 60deg instead of 120deg etc).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0u3Ea.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0u3Ea.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I just do a few linear transformations the results is still not appropriate; perceptually red occupies too many angles and yellow not enough. Even if I do a bit of a hack and try a non-linear polynomial gradient it's difficult to get the right &quot;spread&quot;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bq1cd.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bq1cd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an &quot;official&quot; function that maps HSV hue angle to RYB hue angle?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Update: Reading &lt;a href=&quot;http://blufiro.blogspot.fr/2013/02/ryb-color-wheel.html&quot; rel=&quot;noreferrer&quot;&gt;this&lt;/a&gt; gives some ideas, but the part about excluding cyan confused me more because of Adobe's RYB color wheel: Is this true RYB or is it CMY with hue angles shifted in the blue range?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/U7kPu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/U7kPu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2040" LastEditorUserId="2040" LastEditDate="2015-11-22T09:23:12.730" LastActivityDate="2015-11-22T15:21:37.757" Title="Function to convert HSV angle to RYB angle" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1749" PostTypeId="2" ParentId="1748" CreationDate="2015-11-22T14:56:34.147" Score="7" Body="&lt;p&gt;I just discovered that Adobe color source includes HSV-RYB hue mapping functions (replicated in Ben Knight's Kuler-d3). Apparently Adobe uses uses piecewise linear gradients rather than the polynomial that I was trying to use (and technically it is a CMY wheel not a RBY one, I believe). Here are the relevant stops:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RYBstop HSVstop&#xA;60      35&#xA;122     60&#xA;165     120&#xA;218     180&#xA;275     240&#xA;330     300&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the graph of these showing the perceptual mapping:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PGcnP.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PGcnP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So there'll be artifacts at the junctions where the mapping function is not smooth (which can be seen in the original Adobe image). And here is an imagemagick script for creating the color wheel.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#!/bin/bash&#xA;#assemble gradient pieces (pre-caculated stops), then join them all&#xA;convert -size 600x300 gradient:#000000-#181818 -rotate -90 grad1.png&#xA;convert -size 600x310 gradient:#181818-#2A2A2A -rotate -90 grad2.png&#xA;convert -size 600x215 gradient:#2A2A2A-#555555 -rotate -90 grad3.png&#xA;convert -size 600x265 gradient:#555555-#7F7F7F -rotate -90 grad4.png&#xA;convert -size 600x285 gradient:#7F7F7F-#AAAAAA -rotate -90 grad5.png&#xA;convert -size 600x275 gradient:#AAAAAA-#D4D4D4 -rotate -90 grad6.png&#xA;convert -size 600x150 gradient:#D4D4D4-#FFFFFF -rotate -90 grad7.png&#xA;convert grad?.png +append grad.png&#xA;#create hue&#xA;convert grad.png -alpha set -virtual-pixel Transparent -rotate 180 -distort Arc '360 -90 300' +repage -gravity center -crop 600x600+0+0 +repage h.png&#xA;#create saturation&#xA;convert -size 600x600 -alpha on radial-gradient:white-none s.png&#xA;#create value&#xA;convert -size 600x600 -alpha on radial-gradient:none-white v.png&#xA;#combine h,s,v in hsv colorspace&#xA;convert h.png s.png v.png -combine -set colorspace HSV -colorspace sRGB ryb.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ds5KS.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ds5KS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2040" LastEditorUserId="2040" LastEditDate="2015-11-22T15:21:37.757" LastActivityDate="2015-11-22T15:21:37.757" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1750" PostTypeId="2" ParentId="1747" CreationDate="2015-11-22T16:08:24.660" Score="2" Body="&lt;p&gt;It depends on the game style just how much culling is needed. For instance first person shooters benefit from this a lot, having a lot of stuff in the frustrum at any one time, while an overhead view RTS does not since you are effectively looking at a plane with things on that plane.  Even in an RTS though, doing a &quot;depth only render&quot; to eliminate overdraw is still useful.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2015-11-22T16:08:24.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1751" PostTypeId="2" ParentId="1747" CreationDate="2015-11-23T07:36:55.853" Score="9" Body="&lt;p&gt;Yes, occlusion culling is still worth it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At minimum, a draw call that you skipped due to culling is a draw call that doesn't have to run the vertex shader. Triangle count goes up as quickly as GPUs start supporting more triangles, because why not? With unified architectures, vertex shaders use the exact same hardware that pixel shaders do, so every vertex that you skip because of culling is more compute time for the stuff that you &lt;em&gt;can&lt;/em&gt; see. Not to mention all the other stuff you're skipping (CPU draw call processing, and throwing the tris far enough through the pipeline that the rasterizer realizes that it doesn't need to shade them).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There was a &lt;a href=&quot;http://advances.realtimerendering.com/s2015/aaltonenhaar_siggraph2015_combined_final_footer_220dpi.pdf&quot;&gt;great presentation from two Ubisoft studios at SIGGRAPH 2015&lt;/a&gt; about GPU-driven rendering pipelines. On the surface it's about some of the things you mentioned: batching and instancing, reducing draw call counts. But one of the major advantages they get out of a GPU-driven pipeline is incredibly fine-grained occlusion culling: better culling than you would normally see at the draw-call level. It's all in the service of asymptotically approaching the goal: processing only what you can see, which means that what you can see looks better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Also: consider console, mobile, VR, and desktop-without-the-latest-and-greatest-GPU-that-money-can-buy. Even if all your tris disappear into the gaping maw of your top-of-the-line GPU, you may not be the primary target.)&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2015-11-23T07:36:55.853" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1753" PostTypeId="1" CreationDate="2015-11-23T19:04:20.070" Score="2" ViewCount="80" Body="&lt;p&gt;I have an analysis management web system developed using Ruby on Rails and I need to analyse an uploaded image in my system. Using Java I used to have ImageJ included im my projects. Since I'm new in Ruby on Rails I don't know any library/gem to manage Image processing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you know any image processing gem for Rails like ImageJ on Java?&lt;/p&gt;&#xA;" OwnerUserId="2123" LastEditorUserId="231" LastEditDate="2015-11-28T16:58:17.920" LastActivityDate="2015-11-28T16:58:17.920" Title="ImageJ alternative for Ruby on Rails Development" Tags="&lt;image-processing&gt;&lt;image-comparison&gt;" AnswerCount="0" CommentCount="0" ClosedDate="2015-12-12T11:44:58.767" ContentLicense="CC BY-SA 3.0" />
  <row Id="1754" PostTypeId="1" AcceptedAnswerId="1760" CreationDate="2015-11-25T19:09:52.097" Score="5" ViewCount="119" Body="&lt;p&gt;I am currently doing a research on projection on a sphere, specifically for NOAA's project Science on a Sphere. What I'm trying to do is to find out how exactly do you create a video material for such a device, because it's not as simple as making a regular video since the projection on the sphere warps the final image a lot etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I'm struggling with finding any reasonable material source. I only found NOAA's creation guidelines, and even though they do describe all the problems with warping and having a seamless video pretty well, they do not describe specific methods, or the whole process of creating this kind of a video. They only mention several programs and plugins for Adobe's AE, but that's it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Link: &lt;a href=&quot;http://sos.noaa.gov/_downloads/docs/sos-content-creation-guidelines.pdf&quot; rel=&quot;nofollow&quot;&gt;http://sos.noaa.gov/_downloads/docs/sos-content-creation-guidelines.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't get any reasonable source from Google either, since all links are directing me to topics related to projecting a sphere (Earth) onto a plane, which is not what I'm trying to find at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I decided to give this site a shot and ask you whether you know any source/tutorial that could help me with this issue, or whether is here someone who understands this topic better than I do.&lt;/p&gt;&#xA;" OwnerUserId="2138" LastEditorUserId="16" LastEditDate="2015-11-26T09:16:59.913" LastActivityDate="2015-11-28T20:44:34.907" Title="Materials for research on spherical projection" Tags="&lt;projections&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1755" PostTypeId="1" CreationDate="2015-11-26T03:08:06.657" Score="14" ViewCount="678" Body="&lt;p&gt;I am interested in duplicating a figure (shown below, ch 1 fig 1.21) in the book Algorithmic Beauty of Plants. The book is available here&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://algorithmicbotany.org/papers/#abop&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://algorithmicbotany.org/papers/#abop&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V6EHc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V6EHc.png&quot; alt=&quot;Plant generated with an axial L-system&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This image appears in several resources but I have been unable to find the exact rules for the axial system that produced it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the book, this figure is presented in the context of L-systems and is referenced in the text as follows.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Of special interest are methods proposed by Horton [70, 71] and Strahler, &#xA;  which served as a basis for synthesizing botanical trees [37, 152] (Figure &#xA;  1.21).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I am unable to find a copy of the PhD thesis (ref 37) and ref 152 does not produce this figure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Performing a Google image search with this image points to material related to the book, such as slides.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Has anyone here reproduced this figure?&lt;/p&gt;&#xA;" OwnerUserId="2141" LastEditorUserId="5778" LastEditDate="2018-07-17T06:10:48.847" LastActivityDate="2018-12-12T06:58:40.710" Title="What exact algorithm and parameters reproduce L-system plant growth figure in Algorithmic Beauty of Plants" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1756" PostTypeId="1" AcceptedAnswerId="1757" CreationDate="2015-11-26T05:11:59.980" Score="7" ViewCount="340" Body="&lt;p&gt;In what sense is it true that a NURBS surface can only have the topology of a plane, cylinder or torus?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example I can do a NURBS sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the sphere homeomorphic to one of the above surfaces?&lt;/p&gt;&#xA;" OwnerUserId="1636" LastEditorUserId="231" LastEditDate="2015-11-28T16:41:47.460" LastActivityDate="2015-11-28T16:48:14.650" Title="NURBS topology classification" Tags="&lt;3d&gt;&lt;nurbs&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1757" PostTypeId="2" ParentId="1756" CreationDate="2015-11-26T08:04:16.070" Score="5" Body="&lt;p&gt;Before we begin, let us differentiate between two things:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The shape of a sphere,&lt;/li&gt;&#xA;&lt;li&gt;and the topology of a sphere.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;A NURBS surface can make the &lt;em&gt;shape&lt;/em&gt; of a sphere. In a typical configuration, it will be 'open' at the poles. That is the mathematical function of the surface does not wrap over the pole in that it is not a true sphere (it has the shape of a sphere). Topologically the sphere is in this typical configuration a cylinder. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is possible to leave the other direction open too in which case it is topologically a plane. Several CAD applications choose this approach. A torus is also possible if you allow a thin no volume sliver at the center of your sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kP30Z.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kP30Z.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Turning cylinder to sphere. Note this is not a topological sphere it is still a cylinder as the top is open (even though infinitesimally small).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is the sphere homeomorphic to one of the above surfaces?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, but you can still have a spherical shape even if it does not satisfy the topology condition of mathematics.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Why only 3 topological families?&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Simply, a NURBS surface has only 4 possible configurations of wrapping around the parameter space:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It does not wrap at all. Topology: Plane.&lt;/li&gt;&#xA;&lt;li&gt;It wraps around the U direction. Topology: Cylinder.&lt;/li&gt;&#xA;&lt;li&gt;It wraps around V direction. Same as above. Topology: Cylinder.&lt;/li&gt;&#xA;&lt;li&gt;It wraps around both U and V. Topology: Torus.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;A wrap is always periodic so it goes from - direction to + direction. It can not arbitrarily connect (on a mathematical level).&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2015-11-28T16:48:14.650" LastActivityDate="2015-11-28T16:48:14.650" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1758" PostTypeId="1" CreationDate="2015-11-26T13:10:01.193" Score="3" ViewCount="74" Body="&lt;p&gt;Is there a library to do mesh processing (slicing, repairing, etc.) on big models in a distributed way using Hadoop?&lt;/p&gt;&#xA;" OwnerUserId="2144" LastActivityDate="2015-11-26T13:10:01.193" Title="Distributed Mesh Processing with Hadoop" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2016-03-12T12:23:42.047" ContentLicense="CC BY-SA 3.0" />
  <row Id="1759" PostTypeId="1" AcceptedAnswerId="3948" CreationDate="2015-11-27T10:59:41.930" Score="24" ViewCount="856" Body="&lt;p&gt;I've got a homework in which I have to calculate and plot some points using a pespective transformation, but I'm not sure my results are correct, since the 3d plot using Camera coordinates looks very different from the 2d plot using the image coordinates. Can you help me understand what's wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what is given:&#xA;The camera is at the point $_WT^C = [−1, 1, 5]^T$, specified in world coordinates (in meters). The camera coordinate system is rotated around the Y axis of the world reference by $\theta = 160^o$, so it's rotation matrix is $^wR_c = \begin{bmatrix}cos(\theta) &amp;amp; 0 &amp;amp; sin(\theta)\\ 0 &amp;amp; 1 &amp;amp; 0 \\ -sin(\theta) &amp;amp; 0 &amp;amp; cos(\theta)\end{bmatrix}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Camera parameter are: $f = 16mm$, $s_x = s_y = 0.01 mm/px$, $o_x = 320 px$, $o_y = 240px$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sample points (in world coordinates):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$^WP_1 = [1, 1, 0.5]^T$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$^WP_2 = [1, 1.5, 0.5]^T$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$^WP_3 = [1.5, 1.5, 0.5]^T$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$^WP_4 = [1.5, 1, 0.5]^T$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have to calculate and plot the points in camera coordinates and in image coordinates, so I wrote the following code in Octave:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-matlab prettyprint-override&quot;&gt;&lt;code&gt;%camera intrinsic parameters&#xA;f = 16&#xA;Sx = 0.01&#xA;Sy = 0.01&#xA;Ox = 320&#xA;Oy = 240&#xA;&#xA;%given points, in world coordinate&#xA;wP1 = transpose([1, 1, 0.5])&#xA;wP2 = transpose([1, 1.5, 0.5])&#xA;wP3 = transpose([1.5, 1.5, 0.5])&#xA;wP4 = transpose([1.5, 1, 0.5])&#xA;&#xA;% camera translation matrix&#xA;wTc = transpose([-1, 1, 5])&#xA;&#xA;% rotation angle converted to rad&#xA;theta = 160 / 180 * pi&#xA;&#xA;%camera rotation matrix&#xA;wRc = transpose([cos(theta), 0, sin(theta); 0, 1, 0; -sin(theta), 0, cos(theta)])&#xA;&#xA;%transform the points to homogeneous coordinates&#xA;wP1h = [wP1; 1]&#xA;wP2h = [wP2; 1]&#xA;wP3h = [wP3; 1]&#xA;wP4h = [wP4; 1]&#xA;&#xA;%separate each line of the rotation matrix&#xA;R1 = transpose(wRc(1 , :))&#xA;R2 = transpose(wRc(2 , :))&#xA;R3 = transpose(wRc(3 , :))&#xA;&#xA;%generate the extrinsic parameters matrix&#xA;Mext = [wRc, [-transpose(R1) * wTc; -transpose(R2) * wTc; -transpose(R3) * wTc]]&#xA;&#xA;%intrinsic parameters matrix&#xA;Mint = [-f/Sx, 0, Ox; 0, -f/Sy, Oy; 0, 0, 1]&#xA;&#xA;% calculate coordinates in camera coordinates&#xA;cP1 = wRc * (wP1 - wTc)&#xA;cP2 = wRc * (wP2 - wTc)&#xA;cP3 = wRc * (wP3 - wTc)&#xA;cP4 = wRc * (wP4 - wTc)&#xA;&#xA;% put coordinates in a list for plotting&#xA;&#xA;x = [cP1(1), cP2(1), cP3(1), cP4(1), cP1(1)]&#xA;y = [cP1(2), cP2(2), cP3(2), cP4(2), cP1(2)]&#xA;z = [cP1(3), cP2(3), cP3(3), cP4(3), cP1(3)]&#xA;&#xA;%plot the points in 3D using camera coordinates&#xA;plot3(x, y, z, &quot;o-r&quot;)&#xA;&#xA;pause()&#xA;&#xA;% calculate the points in image coordinates&#xA;iP1 = Mint * (Mext * wP1h)&#xA;iP2 = Mint * (Mext * wP2h)&#xA;iP3 = Mint * (Mext * wP3h)&#xA;iP4 = Mint * (Mext * wP4h)&#xA;&#xA;%generate a list of points for plotting&#xA;x = [iP1(1) / iP1(3), iP2(1) / iP2(3), iP3(1) / iP3(3), iP4(1) / iP4(3), iP1(1) / iP1(3)]&#xA;y = [iP1(2) / iP1(3), iP2(2) / iP2(3), iP3(2) / iP3(3), iP4(2) / iP4(3), iP1(2) / iP1(3)]&#xA;&#xA;plot(x, y, &quot;o-r&quot;)&#xA;&#xA;pause()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And these are the plots I've got from the script:&#xA;I was expecting they were somewhat similar, but they don't look so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AkLN0.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AkLN0.png&quot; alt=&quot;3D plot&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Plot in camera coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/p83mD.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/p83mD.png&quot; alt=&quot;2D plot&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Plot in image coordinates&lt;/p&gt;&#xA;" OwnerUserId="2154" LastActivityDate="2016-09-04T23:51:57.767" Title="Is my perspective math correct?" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1760" PostTypeId="2" ParentId="1754" CreationDate="2015-11-28T09:51:24.587" Score="2" Body="&lt;p&gt;You need to use a cylindrical projection. So the key issue is how to prepare data for a cylindrical projection. Basically what you do is: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;You project your data on a sphere, it may be that this process was already done for you.&lt;/li&gt;&#xA;&lt;li&gt;And then you project it back to a cylinder&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Both steps can be easily taken care of by your cartography software. Will the data distort... yes but since you project information onto a sphere from whatever source onto a sphere and to cylindrical coordinates it will just interpolate the distortion away. If anything your just going to have slight over resolution at poles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quite a lot of data is in fact in this format to begin with. But nearly all 3D applications can use projected textures and texture baking to do these steps for you. Also most 2D applications like Photoshop have tools for turning rectangular coordinates to polar coordinates which do the same thing&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The real question is what your original image data is like?&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-11-28T20:44:34.907" LastActivityDate="2015-11-28T20:44:34.907" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1761" PostTypeId="1" CreationDate="2015-11-29T12:55:29.020" Score="9" ViewCount="1086" Body="&lt;p&gt;I have to connect point pairs without intersection. &#xA;Let's say I have two given points that I connect with a segment of a curve. Then again two new endpoints are selected and these new points have to be connected as well however without intersecting previously drawn curves and so on for any number of given point pairs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the easiest way of finding and drawing these segments of curves?&lt;/p&gt;&#xA;" OwnerUserId="2161" LastEditorUserId="2161" LastEditDate="2015-11-29T22:30:35.507" LastActivityDate="2015-11-30T03:58:02.933" Title="Strategy for connecting 2 points without intersecting previously drawn segments of curves" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1762" PostTypeId="1" AcceptedAnswerId="1763" CreationDate="2015-11-29T15:00:13.707" Score="8" ViewCount="679" Body="&lt;p&gt;Given the 4 coordinates of a 2D shape in a 3D space I want to calculate its aspect ratio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 3D space is created with 2 vanishing points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 4 coordinates - marked blue - are the 2D coordinates on the display.&#xA;in the example they should be roughly (14, 5.5), (19, 5), (20.3, 7.3), (25.3, 6).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if this is possible at all, if someone could find proof that for 2 different aspect ratios the 2D coordinates are the same this problem would be unsolvable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My exapmle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/omyRz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/omyRz.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2162" LastEditorUserId="2162" LastEditDate="2015-12-09T21:59:15.067" LastActivityDate="2015-12-09T21:59:15.067" Title="Calculate aspect ratio from 2D shape in 3D space" Tags="&lt;transformations&gt;&lt;geometry&gt;&lt;projections&gt;&lt;perspective&gt;&lt;space&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1763" PostTypeId="2" ParentId="1762" CreationDate="2015-11-29T20:19:22.653" Score="5" Body="&lt;p&gt;The ratio is with a quick and dirty visual measurement $665:501$ which is approximately $5:4$. You can measure it by taking the ratio of the vanishing angles $\alpha/\beta$ (&lt;em&gt;see picture 1&lt;/em&gt;) because we are so close to the center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IeTey.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IeTey.png&quot; alt=&quot;Angles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Ratio of the inbound angles&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can check the situation visually by drawing a 2 point perspective grid. For this we need the center line between the vanishing points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9gjvk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9gjvk.png&quot; alt=&quot;Perspective grid&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Seems about right.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-11-29T20:30:21.200" LastActivityDate="2015-11-29T20:30:21.200" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1764" PostTypeId="2" ParentId="1761" CreationDate="2015-11-30T00:51:28.830" Score="6" Body="&lt;p&gt;The general problem is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Graph_drawing&quot; rel=&quot;noreferrer&quot;&gt;graph drawing&lt;/a&gt; and is not an easy problem.&lt;/p&gt;&#xA;&lt;p&gt;The graphs that can be drawn on the plane without crossings are called &lt;a href=&quot;https://en.wikipedia.org/wiki/Planar_graph&quot; rel=&quot;noreferrer&quot;&gt;planar&lt;/a&gt;, but not all graphs are planar: the typical graphs that are not planar are the complete graph on &lt;span class=&quot;math-container&quot;&gt;$5$&lt;/span&gt; vertices &lt;span class=&quot;math-container&quot;&gt;$K_5$&lt;/span&gt; and the complete bipartite graph on 6 vertices &lt;span class=&quot;math-container&quot;&gt;$K_{3,3}$&lt;/span&gt;, famous because of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Three_utilities_problem&quot; rel=&quot;noreferrer&quot;&gt;three utilities problem&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;You may want to try &lt;a href=&quot;http://www.graphviz.org/&quot; rel=&quot;noreferrer&quot;&gt;Graphviz - Graph Visualization Software&lt;/a&gt; to produce nice drawings.&lt;/p&gt;&#xA;&lt;p&gt;See also&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Szirmay-Kalos, László, &lt;a href=&quot;http://www.iit.bme.hu/%7Eszirmay/lsgraph.ps.gz&quot; rel=&quot;noreferrer&quot;&gt;Dynamic layout algorithm to display general graphs&lt;/a&gt;, in &lt;em&gt;Graphics Gems IV&lt;/em&gt;, 1994. &lt;a href=&quot;http://www.realtimerendering.com/resources/GraphicsGems/gemsiv/graph_layout/&quot; rel=&quot;noreferrer&quot;&gt;code&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Rosati, Claudio, A simple connection algorithm for 2-d drawing, &lt;em&gt;Graphics Gems III&lt;/em&gt;, 1992, &lt;a href=&quot;http://www.realtimerendering.com/resources/GraphicsGems/gemsiii/con2d.c&quot; rel=&quot;noreferrer&quot;&gt;code&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="192" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-11-30T03:58:02.933" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1765" PostTypeId="1" AcceptedAnswerId="1882" CreationDate="2015-11-30T15:36:34.443" Score="4" ViewCount="194" Body="&lt;p&gt;I am working on the move tool in a 3D modeling software. I need to know how much to move when the user drags an axis of the &lt;a href=&quot;http://www.finalclap.com/ressources/images/3dsmax-tracking6.jpg&quot; rel=&quot;nofollow&quot;&gt;gizmo&lt;/a&gt; (for example along the x axis). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have the 2D vector describing how much the mouse moved on the screen &lt;code&gt;MouseDelta&lt;/code&gt;, and the vector corresponding to the selected axis &lt;code&gt;AxisVector&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to know the best way to compute the amount of extrusion I should apply. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I try to project the &lt;code&gt;AxisVector&lt;/code&gt; in screen space, project &lt;code&gt;MouseDelta&lt;/code&gt; on it and get the ratio between the size of the &lt;code&gt;AxisVectorOnScreen&lt;/code&gt; and the computed projection. Then I have to clamp the result and multiply it by a factor. Here is a pseudo code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector3 AxisVectorOnScreen = GetViewProjMatrix().TransformVector(AxisVector);&#xA;Vector2 AxisVectorOnScreen2D(AxisVectorOnScreen .X * 0.5f * Screen.Width(), AxisVectorOnScreen .Y * 0.5f * Screen.Height());&#xA;Vector2 MouseDelta = EndMousePosition - BeginMousePosition;&#xA;float Size = AxisVectorOnScreen2D.Length();&#xA;float ProjectionLength = MouseDelta | AxisVectorOnScreen2D.GetSafeNormal();&#xA;float Ratio = Size / ProjectionLength;&#xA;float Amount = 10.f * FMath::Clamp(Ratio, -2.5f, 2.5f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I think I could also project my mouse vector on a plane perpendicular to the camera and do the same maths on this plane. What is the best solution?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Note: I have the same problem to get the amount of extrusion I should apply with my extrude tool (along the normal of a face).&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="2173" LastEditorUserId="2173" LastEditDate="2015-12-02T12:16:51.070" LastActivityDate="2016-01-09T12:41:12.300" Title="How to get the transform amount from a screen vector and a direction vector?" Tags="&lt;algorithm&gt;&lt;3d&gt;&lt;transformations&gt;&lt;projections&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1766" PostTypeId="1" AcceptedAnswerId="1772" CreationDate="2015-11-30T16:12:56.893" Score="3" ViewCount="882" Body="&lt;p&gt;I try to project a 3D vector (a direction, not a position) in screen space, but it does not return satisfying results:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; FVector LineDirectionOnScreen = &#xA;   EdMode-&amp;gt;ViewMatrices.GetViewProjMatrix().TransformVector(LineDirection);&#xA; FVector2D LineDirectionOnScreen2D(&#xA;   LineDirectionOnScreen.X * 0.5f * (float)EdMode-&amp;gt;ViewRect.Width(), &#xA;   LineDirectionOnScreen.Y * 0.5f * (float)EdMode-&amp;gt;ViewRect.Height());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When &lt;code&gt;LineDirection&lt;/code&gt; is (0,0,1) it always returns a something like (0,Y) (Y can be anything), no matter how the camera is rotated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is wrong with my code?&lt;/p&gt;&#xA;" OwnerUserId="2173" LastEditorUserId="2173" LastEditDate="2015-12-02T09:58:57.457" LastActivityDate="2015-12-02T22:52:08.860" Title="How to use GetViewProjMatrix().TransformVector(LineDirection) in UE4?" Tags="&lt;projections&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1767" PostTypeId="1" CreationDate="2015-12-01T08:06:23.860" Score="4" ViewCount="150" Body="&lt;p&gt;I have three points P&lt;sub&gt;0&lt;/sub&gt;, P&lt;sub&gt;1&lt;/sub&gt;, P&lt;sub&gt;2&lt;/sub&gt;, which are located on an arbitrarily oriented ellipse in 3D space. I have a square texture map with a circle on it. I would like to render a textured quad (with the obvious UV mapping) so that the circle in the texture map projects onto the ellipse that P&lt;sub&gt;0&lt;/sub&gt;, P&lt;sub&gt;1&lt;/sub&gt;, P&lt;sub&gt;2&lt;/sub&gt; are on. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I calculate the vertices of the quad to project the ellipse correctly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Alternately, in addition to P&lt;sub&gt;0&lt;/sub&gt;, P&lt;sub&gt;1&lt;/sub&gt;, P&lt;sub&gt;2&lt;/sub&gt;, I have the &lt;a href=&quot;https://en.wikipedia.org/wiki/Orbital_elements#Keplerian_elements&quot; rel=&quot;nofollow&quot;&gt;Keplerian elements&lt;/a&gt; of an elliptical orbit, if that's more straightforward.)&lt;/p&gt;&#xA;" OwnerUserId="1634" LastEditorUserId="1634" LastEditDate="2015-12-01T08:34:20.093" LastActivityDate="2016-01-04T15:21:26.153" Title="Project quad onto ellipse in 3D" Tags="&lt;3d&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1768" PostTypeId="1" AcceptedAnswerId="1773" CreationDate="2015-12-02T10:07:54.247" Score="29" ViewCount="16020" Body="&lt;p&gt;For reference, what I'm referring to is the &quot;generic name&quot; for the technique first(I believe) introduced with idTech 5's &lt;a href=&quot;https://en.wikipedia.org/wiki/MegaTexture&quot;&gt;MegaTexture&lt;/a&gt; technology. See the video &lt;a href=&quot;http://holger.dammertz.org/stuff/notes_VirtualTexturing.html&quot;&gt;here&lt;/a&gt; for a quick glance on how it works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been skimming some papers and publications related to it lately, and what I don't understand is how it can possibly be efficient. Doesn't it require constant recalculation of UV coordinates from the &quot;global texture page&quot; space into the virtual texture coordinates? And how doesn't that curb most attempts at batching geometry altogether? How can it allow arbitrary zooming in? Wouldn't it at some point require subdividing polygons?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There just is so much I don't understand, and I have been unable to find any actually easily approachable resources on the topic.&lt;/p&gt;&#xA;" OwnerUserId="2111" LastEditorUserId="2111" LastEditDate="2015-12-02T18:54:07.313" LastActivityDate="2018-12-30T21:49:30.093" Title="How can virtual texturing actually be efficient?" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;optimisation&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="14" ContentLicense="CC BY-SA 3.0" />
  <row Id="1769" PostTypeId="1" AcceptedAnswerId="1771" CreationDate="2015-12-02T13:32:22.497" Score="17" ViewCount="15311" Body="&lt;p&gt;Can I get to know the difference between the three? A good example would add up too.&lt;/p&gt;&#xA;" OwnerUserId="2179" LastEditorUserId="8434" LastEditDate="2020-11-13T18:04:46.110" LastActivityDate="2020-11-13T18:04:46.110" Title="World coordinates, Normalised device coordinates and device coordinates" Tags="&lt;3d&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="1770" PostTypeId="2" ParentId="1768" CreationDate="2015-12-02T18:08:11.140" Score="12" Body="&lt;p&gt;Virtual Texturing is the logical extreme of texture atlases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A texture atlas is a single giant texture that contains textures for individual meshes inside it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/2h1hm.jpg&quot; alt=&quot;Texture Atlas Example&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Texture atlases became popular due to the fact that changing textures causes a full pipeline flush on the GPU. When creating the meshes, the UVs are compressed/shifted so that they represent the correct 'portion' of the whole texture atlas. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As @nathan-reed mentioned in the comments, one of the main drawbacks of texture atlases is losing wrap modes such as repeat, clamp, border, etc. In addition, if the textures don't have enough border around them, you can accidentally sample from an adjacent texture when doing filtering. This can lead to bleeding artifacts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Texture Atlases do have one major limitation: size. Graphics APIs place a soft limit on how big a texture can be. That said, graphics memory is only so big. So there is also a hard limit on texture size, given by the size of your v-ram. Virtual textures solve this problem, by borrowing concepts from &lt;a href=&quot;https://en.wikipedia.org/wiki/Virtual_memory&quot; rel=&quot;noreferrer&quot;&gt;virtual memory&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Virtual textures exploit the fact that in most scenes, you only see a small portion of all the textures. So, only that subset of textures need to be in vram. The rest can be in main RAM, or on disk.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a few ways to implement it, but I will explain the implementation described by Sean Barrett in his &lt;a href=&quot;https://www.youtube.com/watch?v=MejJL87yNgI&quot; rel=&quot;noreferrer&quot;&gt;GDC talk&lt;/a&gt;. (which I highly recommend watching)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have three main elements: the virtual texture, the physical texture, and the lookup table.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/8gLuaq6.jpg&quot; alt=&quot;Virtual Texture&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The virtual texture represents the theoretical mega atlas we would have if we had enough vram to fit everything. It doesn't actually exist in memory anywhere. The physical texture represents what pixel data we actually have in vram. The lookup table is the mapping between the two. For convenience, we break all three elements into equal sized tiles, or pages. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The lookup table stores the location of the top-left corner of the tile in the physical texture. So, given a UV to the entire virtual texture, how do we get the corresponding UV for the physical texture?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, we need to find the location of the page within the physical texture. Then we need to calculate the location of the UV within the page. Finally we can add these two offsets together to get the location of the UV within the physical texture&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 pageLocInPhysicalTex = ...&#xA;float2 inPageLocation = ...&#xA;float2 physicalTexUV = pageLocationInPhysicalTex + inPageLocation;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Calculating pageLocInPhysicalTex&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we make the lookup table the same size as the number of tiles in the virtual texture, we can just sample the lookup table with nearest neighbor sampling and we will get the location of the top-left corner of the page within the physical texture.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 pageLocInPhysicalTex = lookupTable.Sample(virtTexUV, nearestNeighborSampler);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Calculating inPageLocation&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;inPageLocation is a UV coordinate that is relative to the top-left of the page, rather than to the top-left of the whole texture. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to calculate this is by subtracting off the UV of the top left of the page, then scaling to the size of the page. However, this is quite a bit of math. Instead, we can exploit how IEEE floating point is represented. IEEE floating point stores the fractional part of a number by a series of base 2 fractions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/48VfH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/48VfH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this example, the number is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;number = 0 + (1/2) + (1/8) + (1/16) = 0.6875&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now lets look at a simplified version of the virtual texture:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Jj8K9.png&quot; alt=&quot;Simple Virtual Texture&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 1/2 bit tells us if we're in the left half of the texture or the right. The 1/4 bit tells us which quarter of the half we're in. In this example, since the texture is split into 16, or 4 to a side, these first two bits tell us what page we're in. The remaining bits tell us the location inside the page.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can get the remaining bits by shifting the float with exp2() and stripping them out with fract()&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 inPageLocation = virtTexUV * exp2(sqrt(numTiles));&#xA;inPageLocation = fract(inPageLocation);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where numTiles is a int2 giving the number of tiles per side of the texture. In our example, this would be (4, 4)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So let's calculate the inPageLocation for the green point, (x,y) = (0.6875, 0.375)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;inPageLocation = float2(0.6875, 0.375) * exp2(sqrt(int2(4, 4));&#xA;               = float2(0.6875, 0.375) * int2(2, 2);&#xA;               = float2(1.375, 0.75);&#xA;&#xA;inPageLocation = fract(float2(1.375, 0.75));&#xA;               = float2(0.375, 0.75);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;One last thing to do before we're done. Currently, inPageLocation is a UV coordinate in the virtual texture 'space'. However, we want a UV coordinate in the physical texture 'space'. To do this we just have to scale inPageLocation by the ratio of virtual texture size to physical texture size&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;inPageLocation *= physicalTextureSize / virtualTextureSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&#xA;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the finished function is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 CalculatePhysicalTexUV(float2 virtTexUV, Texture2D&amp;lt;float2&amp;gt; lookupTable, uint2 physicalTexSize, uint2 virtualTexSize, uint2 numTiles) {&#xA;    float2 pageLocInPhysicalTex = lookupTable.Sample(virtTexUV, nearestNeighborSampler);&#xA;&#xA;    float2 inPageLocation = virtTexUV * exp2(sqrt(numTiles));&#xA;    inPageLocation = fract(inPageLocation);&#xA;    inPageLocation *= physicalTexSize / virtualTexSize;&#xA;&#xA;    return pageLocInPhysicalTex + inPageLocation;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="310" LastEditorUserId="5778" LastEditDate="2018-12-30T21:49:30.093" LastActivityDate="2018-12-30T21:49:30.093" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="1771" PostTypeId="2" ParentId="1769" CreationDate="2015-12-02T22:27:09.273" Score="26" Body="&lt;p&gt;&lt;strong&gt;World coordinates&lt;/strong&gt; are at the bedrock of your game world. The 3D positions of all objects are ultimately specified in world space, either directly or through a node hierarchy. The ground, buildings, trees, and other stationary things will be fixed in world space. Gameplay calculations and physics will be done in world space (perhaps with some local recentering for precision purposes, if the world is large). The axes of world coordinates are often taken to represent compass directions, such as X = east, Y = north, Z = up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Local coordinates&lt;/strong&gt; are attached to an object (there is one local coordinate space for each object). The axes may represent something meaningful to the object, for instance X = forward, Y = left, Z = up for an object such as a character, vehicle, gun, etc. that has an inherent orientation. As the object moves around, the relationship between local and world space (as expressed by a transformation matrix) will change. For instance if you flip your car upside down, its local Z axis (&quot;up&quot; in local space) will now be pointing &quot;down&quot; in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Camera or view coordinates&lt;/strong&gt; are local coordinates attached to the camera. This is still a 3D coordinate system, without any projection or anything, but with the axes aligned to match the screen orientation: usually X = right, Y = up, Z = backward. The transformation from world to view space is often known as the &quot;view matrix&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Clip space coordinates&lt;/strong&gt; are the coordinates output by a vertex shader: coordinates to which the projection matrix has been applied, but not the perspective divide. This is a 4D (homogeneous) space. (World, local, and view space are 3D with an implicit w = 1.) It's so named because this is the space in which view frustum clipping and culling takes place (conceptually, at least).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Normalized device coordinates&lt;/strong&gt;, also commonly known as &quot;screen space&quot; although that term is a little loose, are what you get after applying the perspective divide to clip space coordinates. The 3D coordinates now represent the 2D positions of points on screen, with X and Y in [−1, 1], together with the depth within the depth buffer range, Z in [0, 1] for D3D or [−1, 1] for OpenGL. The axis orientation is X = right, Y = up, and Z can be either forward or backward depending on the depth buffer configuration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Device coordinates&lt;/strong&gt; are 2D pixel coordinates within the render target, with (0, 0) in the upper-left corner, X = right, Y = down. One arrives at device coordinates by applying the viewport transform to the normalized device coordinates; the viewport controls at what pixel offset and resolution the image appears in the render target. One thing that's important to note is that device coordinates are not integer values; they aren't indices of pixels. They're a continuous 2D coordinate system, using pixel-sized units, but in which fractional (subpixel) values are perfectly valid. Pixel centers lie at 0.5 offsets (like 0.5, 1.5, 2.5, ...) in this coordinate system.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-02T22:27:09.273" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1772" PostTypeId="2" ParentId="1766" CreationDate="2015-12-02T22:52:08.860" Score="3" Body="&lt;p&gt;I don't think you can simply use &lt;code&gt;TransformVector&lt;/code&gt; when the matrix you're transforming by involves a projection matrix. To fully project to screen space, you have to divide by W, which &lt;code&gt;TransformVector&lt;/code&gt; doesn't do (it simply multiplies by the matrix without translation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, because of the divide by W, transforming &lt;em&gt;vectors&lt;/em&gt; (as opposed to &lt;em&gt;points&lt;/em&gt;) by a projection matrix is probably not what you actually want. If what you want is the screen-space vector between two points, you should transform and divide-by-W each point, then subtract them to get a screen-space vector. Otherwise the vector will likely be inaccurate.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-02T22:52:08.860" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="1773" PostTypeId="2" ParentId="1768" CreationDate="2015-12-03T04:05:20.233" Score="24" Body="&lt;h2&gt;Overview&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The main reason for Virtual Texturing (VT), or &lt;em&gt;Sparse Virtual Textures&lt;/em&gt;, as it is sometimes called, is as a memory optimization. The gist of the thing is to only move into video memory the actual texels (generalized as pages/tiles) that you might need for a rendered frame. So it will allow you to have much more texture data in offline or slow storage (HDD, Optical-Disk, Cloud) than it would otherwise fit on video memory or even main memory. If you understand the concept of &lt;a href=&quot;https://en.wikipedia.org/wiki/Virtual_memory&quot; rel=&quot;noreferrer&quot;&gt;Virtual Memory&lt;/a&gt; used by modern Operating Systems, it is the same thing in its essence (the name is not given by accident).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VT does not require recomputing UVs in the sense that you'd do that each frame before rendering a mesh, then resubmit vertex data, but it does require some substantial work in the Vertex and Fragment shaders to perform the indirect lookup from the incoming UVs. In a good implementation however, it should be completely transparent for the application if it is using a virtual texture or a traditional one. Actually, most of the time an application will mix both types of texturing, virtual and traditional.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Batching can in theory work very well, though I have never looked into the details of this. Since the usual criteria for grouping geometry are the textures, and with VT, every polygon in the scene can share the same &quot;infinitely large&quot; texture, theoretically, you could achieve full scene drawing with 1 draw call. But in reality, other factors come into play making this impractical.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Issues with VT&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Zooming in/out and abrupt camera movement are the hardest things to handle in a VT setup. It can look very appealing for a static scene, but once things start moving, more texture pages/tiles will be requested than you can stream for external storage. Async file IO and threading can help, but if it is a real-time system, like in a game, you'll just have to render for a few frames with lower resolution tiles until the hi-res ones arrive, every now and then, resulting in a blurry texture. There's no silver bullet here and that's the biggest issue with the technique, IMO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Virtual Texturing also doesn't handle transparency in an easy way, so transparent polygons need a separate traditional rendering path for them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All in all, VT is interesting, but I wouldn't recommend it for everyone. It can work well, but it is hard to implement and optimize, plus there's just too many corner cases and case-specific tweaks needed for my taste. But for large open-world games or data visualization apps, it might be the only possible approach to fit all the content into the available hardware. With a lot of work, it can be made to run fairly efficiently even on limited hardware, like we can see in the PS3 and XBOX360 versions of id's &lt;em&gt;Rage&lt;/em&gt;. &lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Implementation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I have managed to get VT working on iOS with OpenGL-ES, to a certain degree. My implementation is not &quot;shippable&quot;, but I could conceivably make it so if I wanted and had the resources. &lt;a href=&quot;https://bitbucket.org/glampert/vt-mobile&quot; rel=&quot;noreferrer&quot;&gt;You can view the source code here&lt;/a&gt;, it might help getting a better idea of how the pieces fit together. &lt;a href=&quot;https://youtu.be/sWz45m0QKj4&quot; rel=&quot;noreferrer&quot;&gt;Here's a video&lt;/a&gt; of a demo running on the iOS Sim. It looks very laggy because the simulator is terrible at emulating shaders, but it runs smoothly on a device.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following diagram outlines the main components of the system in my implementation. It differs quite a bit from Sean's SVT demo (link down bellow), but it is closer in architecture to the one presented by the paper &lt;em&gt;Accelerating Virtual Texturing Using CUDA&lt;/em&gt;, found in the first GPU Pro book (link bellow).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F3liK.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F3liK.jpg&quot; alt=&quot;virtual texturing system&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;code&gt;Page Files&lt;/code&gt; are the virtual textures, already cut into tiles (AKA pages) as a preprocessing step, so they are ready to be moved from disk into video memory whenever needed. A page file also contains the whole set of mipmaps, also called &lt;em&gt;virtual mipmaps&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;code&gt;Page Cache Manager&lt;/code&gt; keeps an application-side representation of the &lt;code&gt;Page Table&lt;/code&gt; and &lt;code&gt;Page Indirection&lt;/code&gt; textures. Since moving a page from offline storage to memory is expensive, we need a cache to avoid reloading what is already available. This cache is a very simple &lt;em&gt;Least Recently Used&lt;/em&gt; (LRU) cache. The cache is also the component responsible for keeping the physical textures up-to-date with its own local representation of the data.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;code&gt;Page Provider&lt;/code&gt; is an async job queue that will fetch the pages needed for a given view of the scene and send them to the cache.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;code&gt;Page Indirection&lt;/code&gt; texture is a texture with one pixel for each page/tile in the virtual texture, that will map the incoming UVs to the &lt;code&gt;Page Table&lt;/code&gt; cache texture that has the actual texel data. This texture can get quite large, so it must use some compact format, like RGBA 8:8:8:8 or RGB 5:6:5.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;But we are still missing a key piece here, and that's how to determine which pages must be loaded from storage into the cache and consequently into the &lt;code&gt;Page Table&lt;/code&gt;. That's where the &lt;em&gt;Feedback Pass&lt;/em&gt; and the &lt;code&gt;Page Resolver&lt;/code&gt; enter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Feedback Pass is a pre-render of the view, with a custom shader and at a much lower resolution, that will write the ids of the required pages to the color framebuffer. That colorful patchwork of the cube and sphere above are actual page indexes encoded as an RGBA color. This pre-pass rendering is then read into main memory and processed by the &lt;code&gt;Page Resolver&lt;/code&gt; to decode the page indexes and fire the new requests with the &lt;code&gt;Page Provider&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After the Feedback pre-pass, the scene can be rendered normally with the VT lookup shaders. But note that we don't wait for new page request to finish, that would be terrible, because we'd simply block on synchronous file IO. The requests are asynchronous and might or might not be ready by the time the final view is rendered. If they are ready, sweet, but if not, we always keep a locked page of a low-res mipmap in the cache as a fallback, so we have some texture data in there to use, but it is going to be blurry.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Others resources worth checking out&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;The first book in the &lt;a href=&quot;http://gpupro.blogspot.com.br/&quot; rel=&quot;noreferrer&quot;&gt;GPU Pro series&lt;/a&gt;. It has two very good articles on VT.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Mandatory paper by MrElusive: &lt;a href=&quot;http://www.mrelusive.com/publications/papers/Software-Virtual-Textures.pdf&quot; rel=&quot;noreferrer&quot;&gt;Software Virtual Textures&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The Crytek paper by Martin Mittring: &lt;a href=&quot;http://developer.amd.com/wordpress/media/2013/01/Chapter02-Mittring-Advanced_Virtual_Texture_Topics.pdf&quot; rel=&quot;noreferrer&quot;&gt;Advanced Virtual Texture Topics&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;And &lt;a href=&quot;http://silverspaceship.com/src/svt/&quot; rel=&quot;noreferrer&quot;&gt;Sean's presentation on youtube&lt;/a&gt;, which I see you've already found. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;VT is still a somewhat hot topic on Computer Graphics, so there's tons of good material available, you should be able to find a lot more. If there's anything else I can add to this answer, please feel free to ask. I'm a bit rusty on the topic, haven't read much about it for the past year, but it is alway good for the memory to revisit stuff :)&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="54" LastEditDate="2015-12-03T18:43:24.437" LastActivityDate="2015-12-03T18:43:24.437" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="1774" PostTypeId="1" CreationDate="2015-12-03T09:47:23.183" Score="5" ViewCount="122" Body="&lt;p&gt;For example, let's assume I'm rendering cascaded shadow mapping, but for whatever reason, instead of one of the typical approach, I do the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Render the lowest resolution shadowmap&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Copy part of the shadowmap to the next shadowmap, covering a smaller area(and thus more dense)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Compute a stencil mask based on different points' distance from camera, e.g. more detail on edges, and on points closer to the camera, reusing the old shadowmap elsewhere.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Render the next, higher-density shadowmap with the aforementioned stencil.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What performance can I realistically expect from that? If only 50% of the pixels(or should I say fragments here?) pass the stencil test, do I save 50% of the rendering time, less, none?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this is a poor example, my fallback question scenario is a static scene, where the previous frame's result is reprojected, with an error accumulator in alpha, and a stencil mask is computed based on misses or too high error rates(e.g. position of the previous frame's reprojected pixel is too far from the new target pixel).&lt;/p&gt;&#xA;" OwnerUserId="2111" LastActivityDate="2015-12-03T09:47:23.183" Title="How much processing power does stenciling actually save?" Tags="&lt;optimisation&gt;&lt;stencil-test&gt;&lt;stencil-buffer&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1775" PostTypeId="1" CreationDate="2015-12-03T19:44:36.010" Score="2" ViewCount="62" Body="&lt;p&gt;I am trying to draw an angled line in a raster grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is to create a function that given a start point, a length and an angle, would give me the pixel positions that combined would give me a line at the specified angle, in a raster grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to implement this in C++ but I seem to get some weird points... &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I do it, is I compute the equation of the line, and thereby also the endpoint, and then use Bresenham's line algorithm to find the pixel positions that create the line between the start point and the end point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some of the points though, don't seem right. Some of the traversing points make no sense, or go to infinity. What is wrong with my implementation? &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;math.h&amp;gt;&#xA;using namespace std;&#xA;&#xA;int sign(double x ){ return (x &amp;gt; 0) ? 1 : ((x &amp;lt; 0) ? -1 : 0); }&#xA;&#xA;std::pair&amp;lt;int,int&amp;gt; endpoint(double angle, int x1 , int y1, int lenght)&#xA;{&#xA;&#xA;    if(angle == 90)&#xA;    {&#xA;        double y2 = y1+lenght;&#xA;        return std::make_pair(x1, -y2);&#xA;    }&#xA;    if(angle == 180)&#xA;    {&#xA;        double x2 = x1+lenght;&#xA;        return std::make_pair(-x2, y1);&#xA;    }&#xA;    if(angle == 270)&#xA;    {&#xA;        double y2 = y1+lenght;&#xA;        return std::make_pair(x1, y2);&#xA;    }&#xA;&#xA;&#xA;    double x2 = x1 + (lenght * cos(angle));&#xA;    double y2 = y1 + (lenght * sin(angle));&#xA;    return std::make_pair(x2,y2);&#xA;}&#xA;&#xA;&#xA;void bresenham(int x0, int y0, int x1, int y1)&#xA;{&#xA;    int dx = x1-x0;&#xA;    int dy = y1 - y0;&#xA;    if (abs(dx) &amp;gt; abs(dy))&#xA;    {&#xA;        // x-axis&#xA;        int j = y0;&#xA;        double e = dy - dx;&#xA;&#xA;        for (int i = x0; i&amp;lt;x1; i++)&#xA;        {&#xA;            std::cout &amp;lt;&amp;lt; &quot;marked: &quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &quot;,&quot;&amp;lt;&amp;lt; j &amp;lt;&amp;lt; std::endl;&#xA;            if( e &amp;gt;= 0)&#xA;            {&#xA;                j += 1;&#xA;                e -= dx;&#xA;            }&#xA;            e += dy;&#xA;&#xA;        }&#xA;    }&#xA;    else if(abs(dx)&amp;lt;abs(dy))&#xA;    {&#xA;        // y-axis&#xA;&#xA;        int j = x0;&#xA;        double e = dx - dy;&#xA;&#xA;        for (int i = y0; i&amp;lt;y1; i++)&#xA;        {&#xA;            std::cout &amp;lt;&amp;lt; &quot;marked: &quot; &amp;lt;&amp;lt; j&amp;lt;&amp;lt; &quot;,&quot;&amp;lt;&amp;lt; i &amp;lt;&amp;lt; std::endl;&#xA;            if( e &amp;gt;= 0)&#xA;            {&#xA;                j += 1;&#xA;                e -= dy;&#xA;            }&#xA;            e += dx;&#xA;&#xA;        }&#xA;&#xA;&#xA;    }&#xA;&#xA;}&#xA;&#xA;&#xA;void line(int x0, int y0, int x1, int y1)&#xA;{&#xA;&#xA;    if(x1 &amp;lt; x0)&#xA;    {&#xA;        swap(x1, x0);&#xA;    }&#xA;&#xA;    if(y1 &amp;lt; y0)&#xA;    {&#xA;        swap(y1, y0);&#xA;    }&#xA;&#xA;&#xA;    int dx = x1-x0;&#xA;    int dy = y1-y0;&#xA;    double e = 0;&#xA;    if(dx == 0)&#xA;    {&#xA;        if (sign(dy) == -1)&#xA;        {&#xA;            cout &amp;lt;&amp;lt; &quot;new&quot; &amp;lt;&amp;lt; endl;&#xA;            for (int y = y0; y != y1; y--)&#xA;            {&#xA;                cout &amp;lt;&amp;lt; &quot;mark&quot; &amp;lt;&amp;lt; x1 &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&#xA;            }&#xA;&#xA;        }&#xA;        else&#xA;        {&#xA;            for (int y = y0; y != y1; y++)&#xA;            {&#xA;                cout &amp;lt;&amp;lt; &quot;mark&quot; &amp;lt;&amp;lt; x1 &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&#xA;            }&#xA;        }&#xA;        return;&#xA;    }&#xA;&#xA;    else if(dy == 0)&#xA;    {&#xA;&#xA;        if (sign(dx) == -1)&#xA;        {&#xA;            cout &amp;lt;&amp;lt; &quot;new&quot; &amp;lt;&amp;lt; endl;&#xA;&#xA;            for (int x = x0; x != x1; x--)&#xA;            {&#xA;                cout &amp;lt;&amp;lt; &quot;mark&quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y1 &amp;lt;&amp;lt; endl;&#xA;            }&#xA;&#xA;        }&#xA;        else&#xA;        {&#xA;            for (int y = y0; y != y1; y++)&#xA;            {&#xA;                cout &amp;lt;&amp;lt; &quot;mark&quot; &amp;lt;&amp;lt; x1 &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&#xA;            }&#xA;        }&#xA;        return;&#xA;    }&#xA;    cout &amp;lt;&amp;lt; &quot;bressenham: &quot; &amp;lt;&amp;lt; endl;&#xA;    double de = abs(dy/dx);&#xA;    int y = y0;&#xA;    for (int x = x0; x != x1; x++)&#xA;    {&#xA;        cout &amp;lt;&amp;lt; &quot;mark: &quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&#xA;        e = e + de;&#xA;        while (e &amp;gt;= 0.5)&#xA;        {&#xA;            cout &amp;lt;&amp;lt; &quot;mark: &quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&#xA;            y = y + sign(y1-y0);&#xA;            e = e -1;&#xA;        }&#xA;    }&#xA;&#xA;&#xA;}&#xA;&#xA;int main(int argc, const char * argv[])&#xA;{&#xA;    for (int angle = 0; angle &amp;lt; 180; angle++)&#xA;    {&#xA;        cout &amp;lt;&amp;lt; &quot;angle: &quot; &amp;lt;&amp;lt; angle &amp;lt;&amp;lt; endl;&#xA;        pair&amp;lt;int, int&amp;gt; end = endpoint(angle, 3, 3, 20);&#xA;        cout &amp;lt;&amp;lt; end.first &amp;lt;&amp;lt; end.second &amp;lt;&amp;lt; endl;&#xA;        line(3, 3, end.first, end.second);&#xA;        cout &amp;lt;&amp;lt; end.first &amp;lt;&amp;lt; end.second &amp;lt;&amp;lt; endl;&#xA;&#xA;    }&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2187" LastEditorUserId="231" LastEditDate="2015-12-07T11:38:35.267" LastActivityDate="2015-12-07T11:38:35.267" Title="Draw lines angled from 0 to 2 pi in a raster grid" Tags="&lt;c++&gt;&lt;grid&gt;&lt;line-drawing&gt;&lt;raster-image&gt;" AnswerCount="0" CommentCount="2" ClosedDate="2015-12-11T12:34:54.760" ContentLicense="CC BY-SA 3.0" />
  <row Id="1776" PostTypeId="1" CreationDate="2015-12-04T08:30:44.973" Score="8" ViewCount="654" Body="&lt;p&gt;Code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;math.h&amp;gt;&#xA;#include &amp;lt;GL/glut.h&amp;gt;&#xA;#pragma comment(lib, &quot;opengl32&quot;)&#xA;#include &amp;lt;gl/gl.h&amp;gt;&#xA;#include &amp;lt;gl/glu.h&amp;gt;&#xA;&#xA;//Initialize OpenGL &#xA;void init(void) {&#xA;    glClearColor(0, 0, 0, 0);&#xA;&#xA;    glViewport(0, 0, 500, 500);&#xA;&#xA;    glMatrixMode(GL_PROJECTION);&#xA;    glLoadIdentity();&#xA;&#xA;    glOrtho(0, 500, 0, 500, 1, -1);&#xA;&#xA;    glMatrixMode(GL_MODELVIEW);&#xA;    glLoadIdentity();&#xA;} &#xA;&#xA;void drawLines(void) {&#xA;    glClear(GL_COLOR_BUFFER_BIT);  &#xA;    glColor3f(1.0,1.0,1.0); &#xA;&#xA;    glBegin(GL_LINES);&#xA;&#xA;    glVertex3d(0.5,         0.999,  0.0f);&#xA;    glVertex3d(499.501,     0.999,  0.0f);&#xA;&#xA;    glEnd();&#xA;&#xA;    glFlush();&#xA;} &#xA;&#xA;&#xA;int _tmain(int argc, _TCHAR* argv[])&#xA;{&#xA;    glutInit(&amp;amp;argc, argv);  &#xA;    glutInitWindowPosition(10,10); &#xA;    glutInitWindowSize(500,500); &#xA;    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); &#xA;&#xA;    glutCreateWindow(&quot;Example&quot;); &#xA;    init(); &#xA;    glutDisplayFunc(drawLines); &#xA;    glutMainLoop();&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Problem description:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Above code will put the entire bottom row pixels of the window client area to white.&lt;/li&gt;&#xA;&lt;li&gt;If I swap the command order, from &lt;code&gt;glVertex3d(0.5, 0.999, 0.0f);glVertex3d(499.501, 0.999, 0.0f);&lt;/code&gt; to &lt;code&gt;glVertex3d(499.501, 0.999, 0.0f);glVertex3d(0.5, 0.999, 0.0f);&lt;/code&gt;, then only the left bottom pixel will not draw.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My understandings:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The two vertices will be finally transformed to 2D pixel center coordinate which are (0.0, 0.499) and (499.001, 0.499).&lt;/li&gt;&#xA;&lt;li&gt;The line drawing algorithm only accept pixel center integer points as input.&lt;/li&gt;&#xA;&lt;li&gt;So the two vertices will using int(x + 0.5) and will be (0, 0) and (499 , 0). This conforms to first result but contradict to the result when input order changed. Why?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2190" LastEditorUserId="38" LastEditDate="2016-09-29T08:33:07.017" LastActivityDate="2016-09-29T08:33:07.017" Title="Why different result when change input order in GL_LINES?" Tags="&lt;opengl&gt;&lt;line-drawing&gt;&lt;legacy-opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1777" PostTypeId="2" ParentId="1743" CreationDate="2015-12-04T11:19:36.937" Score="3" Body="&lt;p&gt;The syntax for your dot- and cross-product are a bit strange.&#xA;The methods are members of a vector, but still take two arguments. Are they static methods? Or are you really sure they do what you would expect?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Otherwise the only real difference in your implementation and the one you linked that I can see is your test against the parameter t.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The implementation you linked tests for&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(t &amp;gt; EPSILON)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;your code tests for&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(t &amp;lt; abs(hitFaces.s))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't see in your code how you set the value for hitFaces.s since you fire this ray against a model and don't know jet if it has hit anything.&#xA;My understanding would be, that you first test if t is large enough to signal a hit ( &gt; EPSILON ) and then in a second step sort for the smallest t (closest to the ray origin).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my head you can't get a value for hitFaces.s without calculating this intersection test as you wrote it, and the intersection test needs the hitFaces.s to determine if an intersection was made. But I could be in the wrong here.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2015-12-04T11:19:36.937" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1778" PostTypeId="5" CreationDate="2015-12-04T14:12:45.167" Score="0" Body="&lt;p&gt;WebGL is &lt;a href=&quot;http://en.wikipedia.org/wiki/OpenGL&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL ES 2.0&lt;/a&gt; graphics for web pages. It extends the capability of the &lt;a href=&quot;http://en.wikipedia.org/wiki/Canvas_element&quot; rel=&quot;nofollow noreferrer&quot;&gt;HTML canvas element&lt;/a&gt; to allow it to render accelerated 3D graphics in any compatible web browser. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;WebGL is based on &lt;a href=&quot;http://en.wikipedia.org/wiki/OpenGL_ES&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL ES 2.0&lt;/a&gt; and is driven via a JavaScript API. It does not require the use of plug-ins. Official specifications and additional information can be found at &lt;a href=&quot;http://www.khronos.org/webgl/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Khronos&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Engines:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also many different webGL based 3D engines available:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://threejs.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Three.js&lt;/a&gt; - the most popular and the most used&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.gooengine.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Goo Engine&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://scenejs.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SceneJS&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.babylonjs.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;BabylonJS&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.glge.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLGE&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.sencha.com/blog/introducing-philogl-a-webgl-javascript-library-from-sencha-labs/&quot; rel=&quot;nofollow noreferrer&quot;&gt;PhiloGL&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.ambiera.com/copperlicht/&quot; rel=&quot;nofollow noreferrer&quot;&gt;CopperLicht&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.kickjs.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;KickJS&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.aerotwist.com/a3/&quot; rel=&quot;nofollow noreferrer&quot;&gt;A3&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.cubicvr.org/cubicvr-js/webgl-cubicvr&quot; rel=&quot;nofollow noreferrer&quot;&gt;CubicVR&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.c3dl.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;C3DL&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://code.google.com/p/kuda/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Kuda&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://code.google.com/p/o3d/&quot; rel=&quot;nofollow noreferrer&quot;&gt;O3D&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.spidergl.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SpiderGL&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Getting started with webGL:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Start with &lt;a href=&quot;http://webglfundamentals.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;WebGLFundamentals.org&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other resources include &lt;a href=&quot;http://learningwebgl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;LearningWebGL&lt;/a&gt;. LearningWebGL has basic tutorials.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't want to learn WebGL and you just want to use a library that makes it easy to display 3d three.js is the most popular 3d library and there are plenty of Three.js tutorials and examples here - &lt;a href=&quot;http://learningthreejs.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;LearningThreeJS&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastEditorUserId="4766" LastEditDate="2017-05-11T05:20:34.097" LastActivityDate="2017-05-11T05:20:34.097" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1779" PostTypeId="4" CreationDate="2015-12-04T14:12:45.167" Score="0" Body="WebGL extends the capability of the HTML canvas element to allow it to render accelerated 3D graphics in any compatible web browser." OwnerUserId="1908" LastEditorUserId="1908" LastEditDate="2015-12-04T15:40:12.640" LastActivityDate="2015-12-04T15:40:12.640" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1781" PostTypeId="2" ParentId="1767" CreationDate="2015-12-05T15:20:54.810" Score="1" Body="&lt;p&gt;I assume that your texture is deemed to belong to the plane of the trajectory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at the unprojected ellipse, you can map the circle to it by an anisotropic scaling. If necessary, rotate the texture first if there is any orientation requirement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To achieve this first mapping, you will compute the four corners of a rectangle, presumably related to the frame formed by the ellipse axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then transform those vertices to the global scene coordinates, the same way to transform the ellipse.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastActivityDate="2015-12-05T15:20:54.810" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1782" PostTypeId="2" ParentId="1776" CreationDate="2015-12-05T22:17:50.043" Score="10" Body="&lt;p&gt;The difference in which pixels are covered depending on the vertex order is related to &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/cc627092.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;rasterization rules&lt;/a&gt;. They're the rules that the GPU hardware uses to determine exactly which pixels are covered by a primitive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rasterization rules are a bit subtle. One of their goals is to ensure that whenever you draw multiple primitives that are connected water-tightly, the rasterization never produces any cracks between them, nor are any pixels covered twice (that's important for blending). To achieve that, the rules have some very specific edge and corner cases. Literally...they're cases having to do with primitive edges and corners. :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of lines, it works as follows. There's a diamond-shaped region around each pixel center, as shown in this snippet of the diagram from the MSDN article linked above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/GJ5Zw.png&quot; alt=&quot;diamond rule for line rasterization&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rule is that a pixel is covered if the line &lt;em&gt;exits&lt;/em&gt; the diamond, when tracing from the start to the end of the line. Note that a pixel doesn't get covered if the line enters, but doesn't exit, the diamond. This ensures that if you have two line segments connected end to end, that the pixel at their shared endpoint only belongs to one of the segments and thus doesn't get rasterized twice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also see in the above diagram how changing the order of the vertices can affect which pixels are covered (which doesn't happen with triangles, BTW). The diagram shows two line segments that are identical except for swapping the endpoint order, and you can see it makes a difference which pixel gets covered. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your line segment is somewhat analogous to this. The left end, at (0.5, 0.999) is inside the diamond of the (0, 0) pixel, so it gets covered when it's the first vertex (the line starts inside the diamond, then exits it) and not when it's the second vertex (the line enters the diamond, and ends inside it, so it never exits). &lt;sub&gt;Actually, the vertices are snapped to fixed-point with 8 subpixel bits before rasterization, so this one ends up rounded to (0.5, 1.0), which is exactly on the top corner of the diamond. Depending on the rasterization rules, this might or might not be considered inside the diamond; it seems as if on your GPU it's considered inside, but this can vary between implementations, as the GL spec doesn't nail down the rules entirely.&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2015-12-05T22:57:33.030" LastActivityDate="2015-12-05T22:57:33.030" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1784" PostTypeId="1" AcceptedAnswerId="1792" CreationDate="2015-12-07T12:04:58.077" Score="4" ViewCount="2756" Body="&lt;p&gt;In my SharpGL application I do a very simple, mouse controlled rotation of the scene.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.Rotate(cameraRotation.X, cameraRotation.Y, 0.0f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;cameraRotation.Y += MousePosition.X - previousMousePositionX;&#xA;cameraRotation.X += MousePosition.Y - previousMousePositionY;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem with this is that the x rotation always comes first, so if I rotate the object around the x axis by 180° and then move my mouse left, the object will rotate to the right instead of left (since the y axis is now inverted). Is there a way to change this so that the object always rotates into the mouse movement direction, regardless of its current position? (like netfabb does it for example)&lt;/p&gt;&#xA;" OwnerUserId="2219" LastEditorUserId="127" LastEditDate="2015-12-08T22:52:52.573" LastActivityDate="2015-12-09T21:44:33.037" Title="Always rotate in the direction of mouse movement" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1785" PostTypeId="1" AcceptedAnswerId="1795" CreationDate="2015-12-08T13:03:25.073" Score="4" ViewCount="1837" Body="&lt;p&gt;I at the moment trying to draw some angled lines using bresenham line algorithm which can circulate a 2d array of size 21x21, as a line angled from 0 - 2pi. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/c3X52.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c3X52.png&quot; alt=&quot;Angled line&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the idea is that the program has to output the values which the lines pass through in the grid.. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So an example with 5x5&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Angle:0&#xA;     _ _ _ _ _ &#xA;    |_|_|_|_|_|&#xA;    |_|_|_|_|_|&#xA;    |_|_|.|.|.|&#xA;    |_|_|_|_|_|&#xA;    |_|_|_|_|_|&#xA;&#xA;Angle: 45&#xA;     _ _ _ _ _ &#xA;    |_|_|_|_|.|&#xA;    |_|_|_|.|_|&#xA;    |_|_|.|_|_|&#xA;    |_|_|_|_|_|&#xA;    |_|_|_|_|_|&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and so on..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem here is that it doesn't look like that my program does that.. The endpoint lies within the given radius length.. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am sure am might that I might be messing up with the math.. So i hope some of you could help me here.. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;math.h&amp;gt;&#xA;using namespace std;&#xA;typedef std::pair&amp;lt;int,int&amp;gt; coordinate;&#xA;&#xA;int sign(double x ){ return (x &amp;gt; 0) ? 1 : ((x &amp;lt; 0) ? -1 : 0); }&#xA;&#xA;coordinate endpoint(double angle, int x1 , int y1, int lenght)&#xA;{&#xA;    double radians = (M_PI/180)*angle;&#xA;&#xA;    double x2 = x1 + (lenght * cos(radians));&#xA;    double y2 = y1 + (lenght * sin(radians));&#xA;&#xA;    return std::make_pair(round(x2),round(y2));&#xA;}&#xA;&#xA;void bresenham(coordinate start, coordinate end)&#xA;{&#xA;    //restriction a.x &amp;lt; b.x  and 0 &amp;lt; H/W &amp;lt; 1&#xA;    int y =  start.second;&#xA;    int w = end.first - start.first;&#xA;    int h = end.second - start.second;&#xA;    int f = 2*h-w; // current error term&#xA;&#xA;    for (int x = start.first; x&amp;lt;= end.first; x++)&#xA;    {&#xA;        cout &amp;lt;&amp;lt; &quot;mark: &quot; &amp;lt;&amp;lt; x &amp;lt;&amp;lt; &quot;,&quot; &amp;lt;&amp;lt; y &amp;lt;&amp;lt; endl;&#xA;        if (f &amp;lt; 0)&#xA;        {&#xA;            f = f + 2*h;&#xA;        }&#xA;        else&#xA;        {&#xA;            y++;&#xA;            f=f+2*(h-w);&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;&#xA;int main(int argc, const char * argv[])&#xA;{&#xA;&#xA;    coordinate start = make_pair(0,0);&#xA;    for (int i = 0; i &amp;lt;= 45; i++)&#xA;    {&#xA;        coordinate end = endpoint(i,0,0,10);&#xA;        cout &amp;lt;&amp;lt; &quot;    endPos: &quot;&amp;lt;&amp;lt; &quot;(&quot; &amp;lt;&amp;lt; end.first &amp;lt;&amp;lt;&quot;,&quot;  &amp;lt;&amp;lt; end.second   &amp;lt;&amp;lt;&quot;)&quot;    &amp;lt;&amp;lt; &quot; Angle: &quot; &amp;lt;&amp;lt; i &amp;lt;&amp;lt; &quot;       &quot; &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; &quot;--------------------------------------------&quot; &amp;lt;&amp;lt; endl;&#xA;        bresenham(start, end);&#xA;        cout &amp;lt;&amp;lt; &quot;--------------------------------------------&quot; &amp;lt;&amp;lt; endl;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the output. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    endPos: (10,0) Angle: 0       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,0&#xA;mark: 6,0&#xA;mark: 7,0&#xA;mark: 8,0&#xA;mark: 9,0&#xA;mark: 10,0&#xA;--------------------------------------------&#xA;    endPos: (10,0) Angle: 1       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,0&#xA;mark: 6,0&#xA;mark: 7,0&#xA;mark: 8,0&#xA;mark: 9,0&#xA;mark: 10,0&#xA;--------------------------------------------&#xA;    endPos: (10,0) Angle: 2       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,0&#xA;mark: 6,0&#xA;mark: 7,0&#xA;mark: 8,0&#xA;mark: 9,0&#xA;mark: 10,0&#xA;--------------------------------------------&#xA;    endPos: (10,1) Angle: 3       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,1&#xA;mark: 9,1&#xA;mark: 10,1&#xA;--------------------------------------------&#xA;    endPos: (10,1) Angle: 4       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,1&#xA;mark: 9,1&#xA;mark: 10,1&#xA;--------------------------------------------&#xA;    endPos: (10,1) Angle: 5       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,1&#xA;mark: 9,1&#xA;mark: 10,1&#xA;--------------------------------------------&#xA;    endPos: (10,1) Angle: 6       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,1&#xA;mark: 9,1&#xA;mark: 10,1&#xA;--------------------------------------------&#xA;    endPos: (10,1) Angle: 7       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,1&#xA;mark: 9,1&#xA;mark: 10,1&#xA;--------------------------------------------&#xA;    endPos: (10,1) Angle: 8       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,0&#xA;mark: 4,0&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,1&#xA;mark: 9,1&#xA;mark: 10,1&#xA;--------------------------------------------&#xA;    endPos: (10,2) Angle: 9       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,2&#xA;mark: 9,2&#xA;mark: 10,2&#xA;--------------------------------------------&#xA;    endPos: (10,2) Angle: 10       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,2&#xA;mark: 9,2&#xA;mark: 10,2&#xA;--------------------------------------------&#xA;    endPos: (10,2) Angle: 11       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,2&#xA;mark: 9,2&#xA;mark: 10,2&#xA;--------------------------------------------&#xA;    endPos: (10,2) Angle: 12       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,2&#xA;mark: 9,2&#xA;mark: 10,2&#xA;--------------------------------------------&#xA;    endPos: (10,2) Angle: 13       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,2&#xA;mark: 9,2&#xA;mark: 10,2&#xA;--------------------------------------------&#xA;    endPos: (10,2) Angle: 14       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,0&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,1&#xA;mark: 6,1&#xA;mark: 7,1&#xA;mark: 8,2&#xA;mark: 9,2&#xA;mark: 10,2&#xA;--------------------------------------------&#xA;    endPos: (10,3) Angle: 15       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,2&#xA;mark: 6,2&#xA;mark: 7,2&#xA;mark: 8,2&#xA;mark: 9,3&#xA;mark: 10,3&#xA;--------------------------------------------&#xA;    endPos: (10,3) Angle: 16       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,2&#xA;mark: 6,2&#xA;mark: 7,2&#xA;mark: 8,2&#xA;mark: 9,3&#xA;mark: 10,3&#xA;--------------------------------------------&#xA;    endPos: (10,3) Angle: 17       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,2&#xA;mark: 6,2&#xA;mark: 7,2&#xA;mark: 8,2&#xA;mark: 9,3&#xA;mark: 10,3&#xA;--------------------------------------------&#xA;    endPos: (10,3) Angle: 18       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,2&#xA;mark: 6,2&#xA;mark: 7,2&#xA;mark: 8,2&#xA;mark: 9,3&#xA;mark: 10,3&#xA;--------------------------------------------&#xA;    endPos: (9,3) Angle: 19       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,2&#xA;mark: 6,2&#xA;mark: 7,2&#xA;mark: 8,3&#xA;mark: 9,3&#xA;--------------------------------------------&#xA;    endPos: (9,3) Angle: 20       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,1&#xA;mark: 5,2&#xA;mark: 6,2&#xA;mark: 7,2&#xA;mark: 8,3&#xA;mark: 9,3&#xA;--------------------------------------------&#xA;    endPos: (9,4) Angle: 21       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,2&#xA;mark: 5,2&#xA;mark: 6,3&#xA;mark: 7,3&#xA;mark: 8,4&#xA;mark: 9,4&#xA;--------------------------------------------&#xA;    endPos: (9,4) Angle: 22       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,2&#xA;mark: 5,2&#xA;mark: 6,3&#xA;mark: 7,3&#xA;mark: 8,4&#xA;mark: 9,4&#xA;--------------------------------------------&#xA;    endPos: (9,4) Angle: 23       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,2&#xA;mark: 5,2&#xA;mark: 6,3&#xA;mark: 7,3&#xA;mark: 8,4&#xA;mark: 9,4&#xA;--------------------------------------------&#xA;    endPos: (9,4) Angle: 24       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,2&#xA;mark: 5,2&#xA;mark: 6,3&#xA;mark: 7,3&#xA;mark: 8,4&#xA;mark: 9,4&#xA;--------------------------------------------&#xA;    endPos: (9,4) Angle: 25       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,2&#xA;mark: 5,2&#xA;mark: 6,3&#xA;mark: 7,3&#xA;mark: 8,4&#xA;mark: 9,4&#xA;--------------------------------------------&#xA;    endPos: (9,4) Angle: 26       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,0&#xA;mark: 2,1&#xA;mark: 3,1&#xA;mark: 4,2&#xA;mark: 5,2&#xA;mark: 6,3&#xA;mark: 7,3&#xA;mark: 8,4&#xA;mark: 9,4&#xA;--------------------------------------------&#xA;    endPos: (9,5) Angle: 27       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,2&#xA;mark: 5,3&#xA;mark: 6,3&#xA;mark: 7,4&#xA;mark: 8,4&#xA;mark: 9,5&#xA;--------------------------------------------&#xA;    endPos: (9,5) Angle: 28       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,2&#xA;mark: 5,3&#xA;mark: 6,3&#xA;mark: 7,4&#xA;mark: 8,4&#xA;mark: 9,5&#xA;--------------------------------------------&#xA;    endPos: (9,5) Angle: 29       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,2&#xA;mark: 5,3&#xA;mark: 6,3&#xA;mark: 7,4&#xA;mark: 8,4&#xA;mark: 9,5&#xA;--------------------------------------------&#xA;    endPos: (9,5) Angle: 30       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,2&#xA;mark: 5,3&#xA;mark: 6,3&#xA;mark: 7,4&#xA;mark: 8,4&#xA;mark: 9,5&#xA;--------------------------------------------&#xA;    endPos: (9,5) Angle: 31       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,2&#xA;mark: 5,3&#xA;mark: 6,3&#xA;mark: 7,4&#xA;mark: 8,4&#xA;mark: 9,5&#xA;--------------------------------------------&#xA;    endPos: (8,5) Angle: 32       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,3&#xA;mark: 6,4&#xA;mark: 7,4&#xA;mark: 8,5&#xA;--------------------------------------------&#xA;    endPos: (8,5) Angle: 33       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,1&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,3&#xA;mark: 6,4&#xA;mark: 7,4&#xA;mark: 8,5&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 34       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 35       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 36       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 37       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 38       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 39       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,6) Angle: 40       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,2&#xA;mark: 4,3&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,5&#xA;mark: 8,6&#xA;--------------------------------------------&#xA;    endPos: (8,7) Angle: 41       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,3&#xA;mark: 4,4&#xA;mark: 5,4&#xA;mark: 6,5&#xA;mark: 7,6&#xA;mark: 8,7&#xA;--------------------------------------------&#xA;    endPos: (7,7) Angle: 42       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,3&#xA;mark: 4,4&#xA;mark: 5,5&#xA;mark: 6,6&#xA;mark: 7,7&#xA;--------------------------------------------&#xA;    endPos: (7,7) Angle: 43       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,3&#xA;mark: 4,4&#xA;mark: 5,5&#xA;mark: 6,6&#xA;mark: 7,7&#xA;--------------------------------------------&#xA;    endPos: (7,7) Angle: 44       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,3&#xA;mark: 4,4&#xA;mark: 5,5&#xA;mark: 6,6&#xA;mark: 7,7&#xA;--------------------------------------------&#xA;    endPos: (7,7) Angle: 45       &#xA;--------------------------------------------&#xA;mark: 0,0&#xA;mark: 1,1&#xA;mark: 2,2&#xA;mark: 3,3&#xA;mark: 4,4&#xA;mark: 5,5&#xA;mark: 6,6&#xA;mark: 7,7&#xA;--------------------------------------------&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What am i doing wrong?... I know that the bresenham algorithm might have to be modified to overcome slopes greater 1 and lower that 0. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Clarifying the problem&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying the iterate the 2d array in a circular manner, using bresenham line algorithm . &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm should start from the center of the 2d array, and &quot;shoot out&quot; a beam at angles between 0 - 2pi. The beam has to start from the center and end at the edge of the matrix, Hope it makes more sense..&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; _ _ _ _ _ _ _ _ _ _ _ &#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|.|.|.|.|.|.|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;&#xA; _ _ _ _ _ _ _ _ _ _ _ &#xA;|_|_|_|_|_|_|_|_|_|.|.|&#xA;|_|_|_|_|_|_|_|_|.|_|_|&#xA;|_|_|_|_|_|_|_|.|_|_|_|&#xA;|_|_|_|_|_|_|.|_|_|_|_|&#xA;|_|_|_|_|_|.|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;|_|_|_|_|_|_|_|_|_|_|_|&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I want to output the values the beam hits on the matrix, at each angle..  Which i don't get..  I want to sample the points which the beam intersect in the matrix.. &lt;/p&gt;&#xA;" OwnerUserId="2226" LastEditorUserId="2226" LastEditDate="2015-12-09T16:44:25.213" LastActivityDate="2015-12-09T18:40:17.690" Title="Draw angles lines in raster graphics using bresenham line algorithm" Tags="&lt;c++&gt;&lt;line-drawing&gt;&lt;mathematics&gt;&lt;raster-image&gt;&lt;triangulation&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1786" PostTypeId="1" CreationDate="2015-12-08T14:23:11.243" Score="8" ViewCount="197" Body="&lt;p&gt;Whew, that was a long title.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either way, I'm asking this question, since I like to think about various things, and it occurred to me that there isn't really any simple, open source layers on top of GLSL, even if only to add simple things such as includes, or commonly used functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As research of sorts, I'm asking this question, since my own awareness of such languages is minuscule to say the least - I know of bgfx's shading language, and Unity's ShaderLab, but I don't really know what they accomplish - or why - being a relative newbie to computer graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, what would your wishlist for a shading language like this be? Mine so far is includes, some compatibility between versions, optional &quot;hidden&quot; inputs that allow easily accessing textures at pixel offsets, or image sizes, etc. and probably passes - for, say, two-pass gaussian blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thoughts?&lt;/p&gt;&#xA;" OwnerUserId="2111" LastActivityDate="2015-12-10T03:11:35.820" Title="There are many shading languages built on top of GLSL or HLSL - what problems do they typically solve, and what worthwhile advancements do they make?" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1788" PostTypeId="1" AcceptedAnswerId="1807" CreationDate="2015-12-08T18:48:35.203" Score="9" ViewCount="928" Body="&lt;p&gt;First of all, I want to say that I've read a lot of post about shadow mapping using depth maps and cubemaps and I understand how they work and also, I have working experience with them using OpenGL, but, I have an issue implementing Omnidirectional Shadow Mapping technique using a single point light source in my 3D graphics engine named &quot;EZ3&quot;. My engine uses WebGL as a 3D graphics API and JavaScript as programming language, this is for my bachelor's thesis in Computer Science. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically this is how I've implemented my shadow mapping algorithm, but I'll only focus on point lights case because with them I can archive omnidirectional shadow mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I active front-face culling like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (this.state.faceCulling !== Material.FRONT) {&#xA;    if (this.state.faceCulling === Material.NONE)&#xA;      gl.enable(gl.CULL_FACE);&#xA;&#xA;    gl.cullFace(gl.FRONT);&#xA;    this.state.faceCulling = Material.FRONT;&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Second, I create a depth program in order to record depth values for each cubemap face, this is my depth program code in GLSL 1.0:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;attribute vec3 position;&#xA;&#xA;uniform mat4 uModelView;&#xA;uniform mat4 uProjection;&#xA;&#xA;void main() {&#xA;  gl_Position = uProjection * uModelView * vec4(position, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;vec4 packDepth(const in float depth) {&#xA;  const vec4 bitShift = vec4(256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0);&#xA;  const vec4 bitMask = vec4(0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0);&#xA;  vec4 res = mod(depth * bitShift * vec4(255), vec4(256)) / vec4(255);&#xA;  res -= res.xxyz * bitMask;&#xA;  return res;&#xA;}&#xA;&#xA;void main() {&#xA;  gl_FragData[0] = packDepth(gl_FragCoord.z);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Third, this is my JavaScript function's body that &quot;archives&quot; omnidirectional shadow mapping&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;program.bind(gl);&#xA;&#xA;  for (i = 0; i &amp;lt; lights.length; i++) {&#xA;    light = lights[i];&#xA;&#xA;    // Updates pointlight's projection matrix&#xA;&#xA;    light.updateProjection();&#xA;&#xA;    // Binds point light's depth framebuffer&#xA;&#xA;    light.depthFramebuffer.bind(gl);&#xA;&#xA;    // Updates point light's framebuffer in order to create it &#xA;    // or if it's resolution changes, it'll be created again.&#xA;&#xA;    light.depthFramebuffer.update(gl);&#xA;&#xA;    // Sets viewport dimensions with depth framebuffer's dimensions&#xA;&#xA;    this.viewport(new Vector2(), light.depthFramebuffer.size);&#xA;&#xA;    if (light instanceof PointLight) {&#xA;&#xA;      up = new Vector3();&#xA;      view = new Matrix4();&#xA;      origin = new Vector3();&#xA;      target = new Vector3();&#xA;&#xA;      for (j = 0; j &amp;lt; 6; j++) {&#xA;&#xA;    // Check in which cubemap's face we are ...&#xA;&#xA;        switch (j) {&#xA;          case Cubemap.POSITIVE_X:&#xA;            target.set(1, 0, 0);&#xA;            up.set(0, -1, 0);&#xA;            break;&#xA;          case Cubemap.NEGATIVE_X:&#xA;            target.set(-1, 0, 0);&#xA;            up.set(0, -1, 0);&#xA;            break;&#xA;          case Cubemap.POSITIVE_Y:&#xA;            target.set(0, 1, 0);&#xA;            up.set(0, 0, 1);&#xA;            break;&#xA;          case Cubemap.NEGATIVE_Y:&#xA;            target.set(0, -1, 0);&#xA;            up.set(0, 0, -1);&#xA;            break;&#xA;          case Cubemap.POSITIVE_Z:&#xA;            target.set(0, 0, 1);&#xA;            up.set(0, -1, 0);&#xA;            break;&#xA;          case Cubemap.NEGATIVE_Z:&#xA;            target.set(0, 0, -1);&#xA;            up.set(0, -1, 0);&#xA;            break;&#xA;        }&#xA;&#xA;    // Creates a view matrix using target and up vectors according to each face of pointlight's&#xA;    // cubemap. Furthermore, I translate it in minus light position in order to place&#xA;    // the point light in the world's origin and render each cubemap's face at this &#xA;    // point of view&#xA;&#xA;        view.lookAt(origin, target, up);&#xA;        view.mul(new EZ3.Matrix4().translate(light.position.clone().negate()));&#xA;&#xA;    // Flips the Y-coordinate of each cubemap face&#xA;    // scaling the projection matrix by (1, -1, 1).&#xA;&#xA;    // This is a perspective projection matrix which has:&#xA;    // 90 degress of FOV.&#xA;    // 1.0 of aspect ratio.&#xA;    // Near clipping plane at 0.01.&#xA;    // Far clipping plane at 2000.0.&#xA;&#xA;        projection = light.projection.clone();&#xA;        projection.scale(new EZ3.Vector3(1, -1, 1));&#xA;&#xA;    // Attaches a cubemap face to current framebuffer in order to record depth values for the face with this line&#xA;    // gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + j, id, 0);&#xA;&#xA;        light.depthFramebuffer.texture.attach(gl, j);&#xA;&#xA;    // Clears current framebuffer's color with these lines:&#xA;    // gl.clearColor(1.0,1.0,1.0,1.0);&#xA;    // gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);&#xA;&#xA;        this.clear(color);&#xA;&#xA;    // Renders shadow caster meshes using the depth program&#xA;&#xA;        for (k = 0; k &amp;lt; shadowCasters.length; k++)&#xA;          this._renderShadowCaster(shadowCasters[k], program, view, projection);&#xA;      }&#xA;    } else {&#xA;       // Directional light &amp;amp; Spotlight case ...&#xA;    }&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fourth, this is how I compute Omnidirectional Shadow Mapping using my depth cubemap in my main Vertex Shader &amp;amp; Fragment Shader:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;attribute vec3 position;&#xA;&#xA;uniform mat4 uModel;&#xA;uniform mat4 uModelView;&#xA;uniform mat4 uProjection;&#xA;&#xA;varying vec3 vPosition;&#xA;&#xA;void main() {&#xA;  vPosition = vec3(uModel * vec4(position, 1.0));&#xA;&#xA;  gl_Position = uProjection * uModelView * vec4(position, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float unpackDepth(in vec4 color) {&#xA;    return dot(color, vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0 ));&#xA;}&#xA;&#xA;float pointShadow(const in PointLight light, const in samplerCube shadowSampler) {&#xA;    vec3 direction = vPosition - light.position;&#xA;    float vertexDepth = clamp(length(direction), 0.0, 1.0);&#xA;    float shadowMapDepth = unpackDepth(textureCube(shadowSampler, direction));&#xA;&#xA;    return (vertexDepth &amp;gt; shadowMapDepth) ? light.shadowDarkness : 1.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Finally, this is the result that I'm getting , my scene has a plane, a cube and a sphere. Besides, the red bright sphere is the point light source:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YM04V.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YM04V.jpg&quot; alt=&quot;Omnidirectional Shadow Mapping Issue&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, I seems like point light depth framebuffer's cubemap it is not doing a good interpolation among their faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Until now, I've no idea how to solve this.&lt;/p&gt;&#xA;" OwnerUserId="2228" LastEditorUserId="2228" LastEditDate="2015-12-15T02:12:45.093" LastActivityDate="2015-12-21T15:05:18.920" Title="WebGL Omnidirectional Shadow Mapping Issue" Tags="&lt;glsl&gt;&lt;webgl&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1789" PostTypeId="2" ParentId="1784" CreationDate="2015-12-08T22:46:58.063" Score="1" Body="&lt;p&gt;Transformations, and especially rotations, may have different visual effects, depending on the order they are applied to the target object. For example, using a rotation $M_R$ and a translation $M_T$ to the object's vertices $v_i$, $M_R \cdot M_T \cdot v_i$ will usually&lt;sup&gt;1&lt;/sup&gt; result in a different pose than $M_T \cdot M_R \cdot v_i$ does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lE2zn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lE2zn.png&quot; alt=&quot;rotation and translation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;sup&gt;90 degree rotation and translation along the x axis applied to the box. Left: translation first ($M_R \cdot M_T \cdot v_i$). Right: rotation first ($M_T \cdot M_R \cdot v_i$).&lt;/sup&gt;&lt;/sub&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The key here is to keep in mind to which coordinate system the transformation is applied. Assuming that your to be rotated object initially is in the origin without transformations applied, the first rotation will always yield the desired effect. This is because you're applying the first transformation to the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But once your object is already transformed (rotated, translated, whatever) by $M_1$, technically you can already apply the next transformation $M_2$ in two places. Namely, &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;$M_1 \cdot M_2 \cdot v_i$ or &lt;/li&gt;&#xA;&lt;li&gt;$M_2 \cdot M_1 \cdot v_i$&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;You describe that &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;so if I rotate the object around the x axis by 180° and then move my mouse left, the object will rotate to the right instead of left (since the y axis is now inverted).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is, because the second rotation is applied to the object itself, which is case 1 of the above. But you want to have the second case, so you need to apply the rotations the other way around. That way, the new rotation will be applied to the already rotated object, i.e. the outer coordinate system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally, as long as the user holds the mouse button down you adjust that transformation $M_2$. Calculate the distance the mouse moved from the point the user pressed the button, recalculate the whole rotation ($M_2$) and drop whatever you calculated in the time between the mouse-down event and the previous frame. So for the ongoing rotation, pretend that the user moved the mouse instantly from the start to the current position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once the mouse button is released, you can finalize the transformation and multiply it into $M_1$, which is the identity matrix in the beginning. (Assuming you always want to rotate around the world's center.)&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;sup&gt;1&lt;/sup&gt; There are some special cases where the result is the same, e.g. if the translation direction matches the rotation axis.&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="127" LastEditorUserId="127" LastEditDate="2015-12-09T21:44:33.037" LastActivityDate="2015-12-09T21:44:33.037" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1790" PostTypeId="1" AcceptedAnswerId="1791" CreationDate="2015-12-08T23:04:42.087" Score="12" ViewCount="515" Body="&lt;p&gt;I was reading &lt;a href=&quot;https://research.nvidia.com/sites/default/files/publications/voxel-pipe.pdf&quot;&gt;this paper&lt;/a&gt; about Voxelpipe, a voxelization library from NVIDIA and I found on section 2 Voxelization the terms &lt;strong&gt;&lt;em&gt;6-separating&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;26-separating&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found &lt;a href=&quot;http://labs.cs.sunysb.edu/labs/projects/volume/Papers/Voxel/&quot;&gt;this website&lt;/a&gt; that tries to explain the basic ideas on voxelization but it wasn't very much helpful understanding the terms mentioned.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anybody explain or point out to some other resource that can help me understand?&lt;/p&gt;&#xA;" OwnerUserId="116" LastActivityDate="2015-12-09T18:19:15.953" Title="What does &quot;6-separating&quot; and &quot;26-separating&quot; voxelization mean?" Tags="&lt;voxelization&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1791" PostTypeId="2" ParentId="1790" CreationDate="2015-12-09T00:20:05.397" Score="18" Body="&lt;p&gt;The terms have to do with the &quot;thickness&quot; of the voxelization. I'll illustrate with the help of a diagram about 2D line rasterization (from &lt;a href=&quot;https://stackoverflow.com/questions/4381269/line-rasterisation-cover-all-pixels-regardless-of-line-gradient&quot;&gt;this unrelated question&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7911d.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7911d.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the right is the typical line rasterization: the algorithm finds the one pixel nearest the line within each row (or column, depending on slope). This produces what we usually think of as a &quot;1-pixel-thick&quot; line. On the left is a conservative rasterization, which finds every pixel whose rectangle is touched by the line, and it produces a thicker line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;6-separating voxelization is like the thin line on the right, and 26-separating is like the thick line on the left, but in 3D. If you imagine the line is actually a triangle viewed on-edge, this is analogous to what the voxelization would look like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Different types of voxelization may be better depending on what you're going to do with the voxelized data later. If you're using the voxels as a spatial hierarchy to find triangles that intersect a given region, you probably want the thick voxelization, as it's conservative. The thick voxelization might also be preferable for ray-marching, as the thin voxelization could be missed by a diagonal ray. On the other hand, the thin voxelization is a more faithful representation of the original surface, which is probably better for visibility tests, collision detection, fluid simulation, and suchlike.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &quot;n-separating&quot; terminology is a bit unfortunate, but here's what it's getting at. Imagine you're doing a 3D flood-fill in the voxel grid, but in the flood-fill you only look at the 6 direct neighbors of each voxel (±1 step along each axis). Then the &quot;6-separating&quot; (thin) voxelization will stop the flood-fill: it suffices to separate the two sides of the surface, if only 6 neighbors are considered. On the other hand, suppose your flood-fill was allowed to go to diagonal neighbors as well—26 neighbors in all (3×3×3 neighborhood of voxels). Then the 6-separating voxelization wouldn't stop the flood fill, but the 26-separating (thick) one would.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2015-12-09T18:19:15.953" LastActivityDate="2015-12-09T18:19:15.953" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1792" PostTypeId="2" ParentId="1784" CreationDate="2015-12-09T12:11:36.917" Score="0" Body="&lt;p&gt;Alright, using ArcBall in SharpGL.SceneGraph.Core for my mouse controlled rotations fixed the problem. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just had to edit the following&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (length &amp;gt; 1.0f)&#xA;        {&#xA;            //  Get normalising factor.&#xA;            float norm = 1.0f / (float)Math.Sqrt(length);&#xA;&#xA;            //  Return normalised vector, a point on the sphere.&#xA;            newVector = new Vertex(scaledX * norm, scaledY * norm, 0);&#xA;        }&#xA;        else&#xA;        {&#xA;            //  Return a vector to a point mapped inside the sphere.&#xA;            newVector = new Vertex(scaledX, scaledY, (float)Math.Sqrt(1.0f - length));&#xA;        }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;in ArcBall.MapToSphere so side movements rotate the object around the y axis instead of the z axis. Works as intended now.&lt;/p&gt;&#xA;" OwnerUserId="2219" LastActivityDate="2015-12-09T12:11:36.917" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1793" PostTypeId="1" CreationDate="2015-12-09T17:40:28.850" Score="14" ViewCount="17764" Body="&lt;p&gt;A fairly basic, in some ways, question, but one that many people, myself included, don't really know the answer to. GPU manufacturers often cite extremely high numbers, and the spread between polygon counts that various game engines claim to support often spans multiple orders of magnitude, and then still depends heavily on a lot of variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm aware that this is a broad, pretty much open-ended question, and I apologize for that, I just thought that it would be a valuable question to have on here nonetheless.&lt;/p&gt;&#xA;" OwnerUserId="2111" LastActivityDate="2021-02-05T19:50:28.920" Title="How many polygons in a scene can modern hardware reach while maintaining realtime, and how to get there?" Tags="&lt;gpu&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1794" PostTypeId="1" CreationDate="2015-12-09T18:29:56.273" Score="7" ViewCount="807" Body="&lt;p&gt;I'm new to computer graphics. These days I've been trying to understand how ray tracing using an acceleration data structure works. I came across the term &quot;early ray termination&quot; several times, I looked it over the internet several times too, but I haven't been able to find a satisfactory explanation of it.&#xA;What does it mean to terminate a ray early, and why do we have to do it?&lt;br/&gt;&#xA;Besides, I noticed that the term &quot;front-to-back traversal&quot; is mentioned almost every time there's a mention of &quot;early ray termination&quot;.&#xA;Concretely how does front-to-back traversal work (in the case of a kd-tree for example) ?&lt;/p&gt;&#xA;" OwnerUserId="2233" LastActivityDate="2015-12-10T05:20:02.120" Title="The meaning of early ray termination and front-to-back traversal in ray tracing" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;optimisation&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1795" PostTypeId="2" ParentId="1785" CreationDate="2015-12-09T18:40:17.690" Score="1" Body="&lt;p&gt;The endpoint of the line doesn't extend out to the edge of the box because you're using the circle equation with a fixed radius:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double x2 = x1 + (lenght * cos(radians));&#xA;double y2 = y1 + (lenght * sin(radians));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This makes the endpoint trace out a circle as the angle is changed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want the endpoint to be on the edge of the box, one way is to set up a ray from the center of the box at the desired angle, then calculate the intersection point of the ray with the box. &lt;a href=&quot;http://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection&quot; rel=&quot;nofollow&quot;&gt;This article shows how to calculate ray/box intersections&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way is to loop over the points around the sides of the box, rather than looping over angles. You would have four separate loops, one for each side, and holding one of x or y fixed while iterating the other. For example, holding x = 10 and iterating y from -10 to +10 would go up the right side.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the slopes outside [0, 1], you must extend your Bresenham algorithm for it. This can be found in any tutorial or sample of Bresenham, for example &lt;a href=&quot;http://rosettacode.org/wiki/Bitmap/Bresenham&amp;#39;s_line_algorithm#C.2B.2B&quot; rel=&quot;nofollow&quot;&gt;the implementations here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-09T18:40:17.690" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1796" PostTypeId="1" CreationDate="2015-12-09T22:37:12.460" Score="2" ViewCount="57" Body="&lt;p&gt;I am at the moment having some issues with computing an endpoint in a raster grid that is also a valid position in a graph. &#xA;I am trying to draw a line between these two points, but as the point I am computing becomes negative, its position becomes invalid. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I compute the right endpoint value within a 20x20 matrix where my start point is $(10,10)$, and the endpoint has to be 10 steps away from the center at any angle?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how I compute the angle now: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;coordinate endpoint(double angle, coordinate start, int lenght)&#xA;{&#xA;    double radians = (M_PI/180)*angle;&#xA;&#xA;    double x2 = start.first + (lenght * cos(radians));&#xA;    double y2 = start.second + (lenght * sin(radians));&#xA;&#xA;    return std::make_pair(round(x2),round(y2));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2226" LastEditorUserId="127" LastEditDate="2015-12-10T16:14:28.097" LastActivityDate="2015-12-10T16:14:28.097" Title="Compute angles and thereby endpoints in a raster grid?" Tags="&lt;mathematics&gt;&lt;raster-image&gt;&lt;triangulation&gt;&lt;debugging&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1797" PostTypeId="2" ParentId="1786" CreationDate="2015-12-10T03:11:35.820" Score="2" Body="&lt;p&gt;I think it is fair to say that the reason there are so many niche variations of GLSL/HLSL/Cg/whatnot is because no programming language is nor will ever be a one size fits all tool. Different problems require different tools, so sometimes it is worth the effort of developing a custom built tool if it is going to pay off in the long run.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Stock GLSL is by itself pretty much unusable. It hasn't even acquired much stability across versions, so for a program that targets more than one OpenGL version, some sort of preprocessing is a must. HLSL is a bit more stable across versions, but again, if targeting more than one D3D version, some work will need to done to get good portability.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The kinds of things people usually do are pretty much what you said, like a adding support for basic programming features such as modules and uniform syntax across versions, or even portability across different APIs (GL/D3D) without having to rewrite the shader code. More sophisticated things include fully fledged material systems or things like &lt;a href=&quot;http://gameangst.com/?p=441&quot; rel=&quot;nofollow&quot;&gt;generating shader programs on-the-fly&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shading languages will probably get better and more generic in the future, incorporating things that today are commonly hand-rolled as core features. The new &lt;a href=&quot;https://en.wikipedia.org/wiki/Graphics_Core_Next&quot; rel=&quot;nofollow&quot;&gt;GCN architecture&lt;/a&gt; is a sign of that. So shading languages will be more usable out-of-the-box a while from now, but custom built solutions will never go away because there's only so much you can generalize.&lt;/p&gt;&#xA;" OwnerUserId="54" LastActivityDate="2015-12-10T03:11:35.820" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1798" PostTypeId="2" ParentId="1794" CreationDate="2015-12-10T05:20:02.120" Score="5" Body="&lt;p&gt;Front-to-back traversal is the idea that when traversing a ray through the acceleration structure, we want to examine nodes that are in front, i.e. closer to the camera, before other nodes. If you only want the first intersection with a surface (as usual in ray tracing), then if you get an intersection in the front node you don't need to traverse any nodes behind it; as any possible intersection there would be later than the one you already found. This saves time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, in a kd-tree, at each node you have a splitting plane dividing space into two child nodes. You would first descend to the child closer to the camera, and only if no intersections are found there do you descend to the other child.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Early ray termination seems to be a term used in the context of volume rendering. When you're traversing a ray through a medium that attenuates light, such as fog, smoke, cloudy liquids, etc., then beyond a certain distance there is no possibility of the ray having any more effect on the image. If you have thick fog with a visibility of 10 meters, then an object 11 meters away cannot be seen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can precalculate the distance at which the attenuation reaches 99% or so (it never quite reaches 100%, but approaches it exponentially). There is no reason to intersect the ray against objects farther than that, so when using the acceleration structure, you can simply discard any nodes beyond that distance. In effect, the ray becomes a line segment terminated at a fixed length. If it doesn't hit anything within that length, there's no point checking further. (Another case where limited-length rays are handy is for shadow rays. You only want to trace them back to the originating light source; any intersections beyond that are irrelevant for the shadow.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-10T05:20:02.120" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1799" PostTypeId="1" AcceptedAnswerId="1800" CreationDate="2015-12-10T13:00:04.673" Score="6" ViewCount="1578" Body="&lt;p&gt;I developed a ray tracer that use standard phong/blinn phong lighting model. Now I'm modifying it to support physically based rendering, so I'm implementing various BRDF models. At the moment I'm focused on Oren-Nayar and Torrance-Sparrow model. Each one of these is based on spherical coordinates used to express incident wi and outgoing wo light direction. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My question is: which way is the right one convert wi and wo from cartesian coordinate to spherical coordinate?&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm applying the standard formula reported here &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_coordinate_system#Coordinate_system_conversions&quot; rel=&quot;nofollow&quot;&gt;https://en.wikipedia.org/wiki/Spherical_coordinate_system#Coordinate_system_conversions&lt;/a&gt; but I'm not sure I'm doing the right thing, &lt;strong&gt;because my vector are not with tail at the origin of the cartesian coordinate system, but are centered on the intersection point of the ray with the object.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here you can find my current implementation:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/chicio/Multispectral-Ray-tracing/tree/brdf/RayTracing/RayTracer/Objects/BRDF&quot; rel=&quot;nofollow&quot;&gt;https://github.com/chicio/Multispectral-Ray-tracing/tree/brdf/RayTracing/RayTracer/Objects/BRDF&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/chicio/Multispectral-Ray-tracing/blob/brdf/RayTracing/RayTracer/Math/Vector3D.cpp&quot; rel=&quot;nofollow&quot;&gt;https://github.com/chicio/Multispectral-Ray-tracing/blob/brdf/RayTracing/RayTracer/Math/Vector3D.cpp&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Can anyone help me giving an explanation of the correct way to convert the wi and wo vector from cartesian to spherical coordinate?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I copy here the relevant part of code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;spherical coordinate calculation&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Vector3D::sphericalTheta() const {&#xA;&#xA;    float sphericalTheta = acosf(Utils::clamp(y, -1.f, 1.f));&#xA;&#xA;    return sphericalTheta;&#xA;}&#xA;&#xA;float Vector3D::sphericalPhi() const {&#xA;&#xA;    float phi = atan2f(z, x);&#xA;&#xA;    return (phi &amp;lt; 0.f) ? phi + 2.f * M_PI : phi;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Oren Nayar&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;OrenNayar::OrenNayar(Spectrum&amp;lt;constant::spectrumSamples&amp;gt; reflectanceSpectrum, float degree) : reflectanceSpectrum{reflectanceSpectrum} {&#xA;&#xA;    float sigma = Utils::degreeToRadian(degree);&#xA;    float sigmaPowerTwo = sigma * sigma;&#xA;&#xA;    A = 1.0f - (sigmaPowerTwo / 2.0f * (sigmaPowerTwo + 0.33f));&#xA;    B = 0.45f * sigmaPowerTwo / (sigmaPowerTwo + 0.09f);&#xA;};&#xA;&#xA;Spectrum&amp;lt;constant::spectrumSamples&amp;gt; OrenNayar::f(const Vector3D&amp;amp; wi, const Vector3D&amp;amp; wo, const Intersection* intersection) const {&#xA;&#xA;    float thetaI = wi.sphericalTheta();&#xA;    float phiI = wi.sphericalPhi();&#xA;&#xA;    float thetaO = wo.sphericalTheta();&#xA;    float phiO = wo.sphericalPhi();&#xA;&#xA;    float alpha = std::fmaxf(thetaI, thetaO);&#xA;    float beta = std::fminf(thetaI, thetaO);&#xA;&#xA;    Spectrum&amp;lt;constant::spectrumSamples&amp;gt; orenNayar = reflectanceSpectrum * constant::inversePi * (A + B * std::fmaxf(0, cosf(phiI - phiO) * sinf(alpha) * tanf(beta)));&#xA;&#xA;    return orenNayar;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Torrance-Sparrow&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float TorranceSparrow::G(const Vector3D&amp;amp; wi, const Vector3D&amp;amp; wo, const Vector3D&amp;amp; wh, const Intersection* intersection) const {&#xA;&#xA;    Vector3D normal = intersection-&amp;gt;normal;&#xA;    normal.normalize();&#xA;&#xA;    float normalDotWh = fabsf(normal.dot(wh));&#xA;    float normalDotWo = fabsf(normal.dot(wo));&#xA;    float normalDotWi = fabsf(normal.dot(wi));&#xA;    float woDotWh = fabsf(wo.dot(wh));&#xA;&#xA;    float G = fminf(1.0f, std::fminf((2.0f * normalDotWh * normalDotWo)/woDotWh, (2.0f * normalDotWh * normalDotWi)/woDotWh));&#xA;&#xA;    return G;&#xA;}&#xA;&#xA;float TorranceSparrow::D(const Vector3D&amp;amp; wh, const Intersection* intersection) const {&#xA;&#xA;    Vector3D normal = intersection-&amp;gt;normal;&#xA;    normal.normalize();&#xA;&#xA;    float cosThetaH = fabsf(wh.dot(normal));&#xA;&#xA;    float Dd = (exponent + 2) * constant::inverseTwoPi * powf(cosThetaH, exponent);&#xA;&#xA;    return Dd;&#xA;}&#xA;&#xA;Spectrum&amp;lt;constant::spectrumSamples&amp;gt; TorranceSparrow::f(const Vector3D&amp;amp; wi, const Vector3D&amp;amp; wo, const Intersection* intersection) const {&#xA;&#xA;    Vector3D normal = intersection-&amp;gt;normal;&#xA;    normal.normalize();&#xA;&#xA;    float thetaI = wi.sphericalTheta();&#xA;    float thetaO = wo.sphericalTheta();&#xA;&#xA;    float cosThetaO = fabsf(cosf(thetaO));&#xA;    float cosThetaI = fabsf(cosf(thetaI));&#xA;&#xA;    if(cosThetaI == 0 || cosThetaO == 0) {&#xA;&#xA;        return reflectanceSpectrum * 0.0f;&#xA;    }&#xA;&#xA;    Vector3D wh = (wi + wo);&#xA;    wh.normalize();&#xA;&#xA;    float cosThetaH = wi.dot(wh);&#xA;&#xA;    float F = Fresnel::dieletricFresnel(cosThetaH, refractiveIndex);&#xA;    float g = G(wi, wo, wh, intersection);&#xA;    float d = D(wh, intersection);&#xA;&#xA;    printf(&quot;f %f g %f d %f \n&quot;, F, g, d);&#xA;    printf(&quot;result %f \n&quot;, ((d * g * F) / (4.0f * cosThetaI * cosThetaO)));&#xA;&#xA;    Spectrum&amp;lt;constant::spectrumSamples&amp;gt; torranceSparrow = reflectanceSpectrum * ((d * g * F) / (4.0f * cosThetaI * cosThetaO));&#xA;&#xA;    return torranceSparrow;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE 2&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some search I found this implementation of Oren-Nayar BRDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://content.gpwiki.org/index.php/D3DBook:(Lighting)_Oren-Nayar&quot; rel=&quot;nofollow&quot;&gt;http://content.gpwiki.org/index.php/D3DBook:(Lighting)_Oren-Nayar&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the implementation above theta for wi and wo is obtained simply doing arccos(wo.dotProduct(Normal)) and arccos(wi.dotProduct(Normal)). This seems reasonable to me, as we can use the normal of the intersection point as the zenith direction for our spherical coordinate system and do the calculation. The calculation of gamma = cos(phi_wi - phi_wo) do some sort of projection of wi and wo on what it calls &quot;tangent space&quot;. Assuming everything is correct in this implementation, can i just use the formulas |View - Normal x (View.dotProduct(Normal))| and |Light - Normal x (Light.dotProduct(Normal))| to obtain the phi coordinate (instead of using arctan(&quot;something&quot;))? &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;N.B.: I'm also reading &quot;Physically based rendering: from theory to implementation&quot;, that is the book released to pbrt (&lt;a href=&quot;http://www.pbrt.org&quot; rel=&quot;nofollow&quot;&gt;http://www.pbrt.org&lt;/a&gt;). In this implementation there's some sort of change of coordinate system for the point of intersection (using partial derivates and the parametric coordinate of the surface) (I'm reading it now so what I'm saying could not be accurate). I want to find a straight way (maybe the one above in UPDATE 2 is what I'm searching for, if anyone could confirm it).&lt;/p&gt;&#xA;" OwnerUserId="2237" LastEditorUserId="231" LastEditDate="2016-01-19T13:04:54.080" LastActivityDate="2016-01-19T13:04:54.080" Title="BRDF and Spherical coordinate in ray tracing" Tags="&lt;raytracing&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1800" PostTypeId="2" ParentId="1799" CreationDate="2015-12-11T06:18:50.267" Score="9" Body="&lt;p&gt;The polar coordinate system commonly used in BRDF definitions is set up relative to the surface being shaded, i.e. in tangent space. The &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; angle measures how far you are from the surface normal while &lt;span class=&quot;math-container&quot;&gt;$\phi$&lt;/span&gt; is the azimuth around the plane of the surface relative to some reference direction (which doesn't matter unless the BRDF is anisotropic). So if you want to convert to these coordinates, you have to first get your vector in tangent space (with the origin at the intersection point and two of the axes aligned with the surface), then apply the usual Cartesian-to-spherical transformation.&lt;/p&gt;&#xA;&lt;p&gt;However, normally you can and should evaluate BRDFs &lt;em&gt;without&lt;/em&gt; using polar coordinates, trigonometric functions, or angles at all, but just using vector math primitives such as dot products. This is usually more efficient &lt;em&gt;and&lt;/em&gt; it's more robust, as you don't have to deal with angle wraparound, factors of pi, out-of-range arguments to inverse trig functions and so on. For instance, you probably know that the cosine of the angle between vectors can be obtained by just dotting the (normalized) vectors. The sine and tangent can be obtained through trig identities from the cosine (i.e. from the dot product).&lt;/p&gt;&#xA;&lt;p&gt;Fabian Giesen wrote an article on this topic, &lt;a href=&quot;https://fgiesen.wordpress.com/2010/10/21/finish-your-derivations-please/&quot; rel=&quot;noreferrer&quot;&gt;Finish your derivations, please&lt;/a&gt;, that refers to the exact Oren-Nayar article you linked and gives an alternate, trig-free form:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Time to brush up your trigonometric identities. A particularly bad offender can be found here – the relevant section from the simplified shader is this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float alpha = max( acos( dot( v, n ) ), acos( dot( l, n ) ) );&#xA;float beta  = min( acos( dot( v, n ) ), acos( dot( l, n ) ) );&#xA;C = sin(alpha) * tan(beta);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Ouch! If you use some trig identities and the fact that acos is monotonically decreasing over its domain, this reduces to:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float vdotn = dot(v, n);&#xA;float ldotn = dot(l, n);&#xA;C = sqrt((1.0 - vdotn*vdotn) * (1.0 - ldotn*ldotn))&#xA;  / max(vdotn, ldotn);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;..and suddenly there’s no need to use a lookup texture anymore (and by the way, this has way higher accuracy too).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;And note that this formulation only has one transcendental function (&lt;code&gt;sqrt&lt;/code&gt;) in place of four (two &lt;code&gt;acos&lt;/code&gt;, a &lt;code&gt;sin&lt;/code&gt;, and a &lt;code&gt;tan&lt;/code&gt;).&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-12-11T06:27:07.310" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1801" PostTypeId="1" AcceptedAnswerId="1803" CreationDate="2015-12-11T11:00:40.783" Score="9" ViewCount="220" Body="&lt;p&gt;Thinking about hybrid raytracing, hence the following question:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose I have two solid spheres $s_1$ and $s_2$. We know their centres and radii, and we know that they have some overlapping volume in space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have a typical 3D graphics setup: assume eye is at the origin, and we are projecting the spheres onto a view plane at $z = f$ for some positive $f$. The spheres are beyond the view plane and don't intersect it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let $c$ be the circle in space that is points on the surface of both spheres, i.e. the visible (from some angles) 'join' of their overlapping volumes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to calculate if any of $c$ is visible when projected onto our view plane. It might not be, if $s_1$ or $s_2$ get completely in the way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas for approaching this?&lt;/p&gt;&#xA;" OwnerUserId="2244" LastEditorUserId="127" LastEditDate="2015-12-12T11:31:30.270" LastActivityDate="2015-12-12T11:31:30.270" Title="Sphere intersection occlusion (for hybrid raytracing)" Tags="&lt;raytracing&gt;&lt;3d&gt;&lt;occlusion&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1803" PostTypeId="2" ParentId="1801" CreationDate="2015-12-12T11:23:46.880" Score="7" Body="&lt;p&gt;Given that I didn't miss anything, you can probably cut this down to a problem in the 2D space. Viewing onto the plane defined by the center points of the spheres and your camera origin, the scene looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IhbVx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IhbVx.png&quot; alt=&quot;scene with visible intersection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The spheres become circles with the center points $C_1$ and $C_2$, and the intersection circle is now only 2 points with only the closer one $P$ being interesting. The camera/eye is arbitrarily set to the point $E$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Calculating if one point on the spheres is visible or not is easy: Simply check whether or not the angles at point $P$ between $E$ and $C_1$ respectively $E$ and $C_2$ are both greater (or equal to) 90 degree&lt;sup&gt;1&lt;/sup&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If $P$ is visible, some part (e.g. at least that point) of the intersection circle is visible. Otherwise the whole intersection circle must be occluded by one of your spheres, namely the one which creates an angle of less than 90 degree.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is how it looks if $P$ is not visible from $E$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tAnbC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tAnbC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can clearly see how that point is occluded by the circle around $C_2$ and that the angle between $E$ and $C_2$ in $P$ is less than 90 degree.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;sup&gt;1&lt;/sup&gt; Having an angle of exactly 90 degree means that the line between $E$ and $P$ just touches the respective circle/sphere in point $P$ as a tangent.&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="127" LastEditorUserId="127" LastEditDate="2015-12-12T11:29:06.757" LastActivityDate="2015-12-12T11:29:06.757" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1806" PostTypeId="2" ParentId="1793" CreationDate="2015-12-14T02:15:36.533" Score="7" Body="&lt;p&gt;I think it is commonly accepted that real time is everything that is above interactive. And interactive is defined as &quot;responds to input but is not smooth in the fact that the animation seems jaggy&quot;.&lt;br&gt;&#xA;So real time will depend on the speed of the movements one needs to represent. Cinema projects at 24 FPS and is sufficiently real time for many cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then how many polygons a machine can deal with is easily verifiable by checking for yourself. Just create a little VBO patch as a simple test and a FPS counter, many DirectX or OpenGL samples will give you the perfect test bed for this benchmark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll find if you have a high end graphics card that you can display about 1 million polygons in real time. However, as you said, engines will not claim support so easily because real world scene data will cause a number of performance hogs that are unrelated to polygon count.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You have:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;fill rate&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;texture sampling&lt;/li&gt;&#xA;&lt;li&gt;ROP output&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;draw calls&lt;/li&gt;&#xA;&lt;li&gt;render target switches&lt;/li&gt;&#xA;&lt;li&gt;buffer updates (uniform or other)&lt;/li&gt;&#xA;&lt;li&gt;overdraw&lt;/li&gt;&#xA;&lt;li&gt;shader complexity&lt;/li&gt;&#xA;&lt;li&gt;pipeline complexity (any feedback used? iterative geometry shading? occlusion?)&lt;/li&gt;&#xA;&lt;li&gt;synch points with CPU (pixel readback?)&lt;/li&gt;&#xA;&lt;li&gt;polygon richness&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Depending on the weak and strong points of a particular graphic card, one or another of these points is going to be the bottleneck. It's not like you can say for sure &quot;there, that's the one&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wanted to add that, one cannot use the GFlops spec figure of one specific card and map it linearly to polygon pushing capacity. Because of the fact that polygon treatment has to go through a sequential bottleneck in the graphics pipeline as explained in great detail here:  &lt;a href=&quot;https://fgiesen.wordpress.com/2011/07/03/a-trip-through-the-graphics-pipeline-2011-part-3/&quot; rel=&quot;nofollow&quot;&gt;https://fgiesen.wordpress.com/2011/07/03/a-trip-through-the-graphics-pipeline-2011-part-3/&lt;/a&gt;&lt;br&gt;&#xA;TLDR: the vertices have to fit into a small cache before primitive assembly which is natively a sequential thing (the vertex buffer order matters).  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you compare the GeForce 7800 (9yr old?) to this year's 980, it seems the number of operations per second it is capable of has increased one thousand fold. But you can bet that it's not going to push polygons a thousand times faster (which would be around 200 billion a second by this simple metric).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT2:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer the question &quot;what can one do to optimize an engine&quot;, as in &quot;not to lose too much efficiency in state switches and other overheads&quot;.&lt;br&gt;&#xA;That is a question as old as engines themselves. And is becoming more complex as history progress.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Indeed in real world situation, typical scene data will contain many materials, many textures, many different shaders, many render targets and passes, and many vertex buffers and so on. One engine I worked with worked with the notion of packets:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One packet is what can be rendered with one draw call.&lt;br&gt;&#xA;It contains identifiers to:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;vertex buffer&lt;/li&gt;&#xA;&lt;li&gt;index buffer&lt;/li&gt;&#xA;&lt;li&gt;camera (gives the pass and render target)&lt;/li&gt;&#xA;&lt;li&gt;material id (gives shader, textures and UBO)&lt;/li&gt;&#xA;&lt;li&gt;distance to eye&lt;/li&gt;&#xA;&lt;li&gt;is visible&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So the first step of each frame is to run a quick sort on the packet list using a sort function with an operator that gives priority to visibility, then pass, then material, then geometry and finally distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Drawing close objects gets prirority to maximize early Z culling.&lt;br&gt;&#xA;Passes are fixed steps, so we have no choice but to respect them.&lt;br&gt;&#xA;Material is the most expensive thing to state-switch after render targets.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even in-between different materials IDs, a sub-ordering can been made using a heuristical criterion to diminish the number of shader changes (most expensive within material state-switch operations), and secondly texture binding changes.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;After all this ordering, one can apply mega texturing, virtual texturing, and attribute-less rendering (&lt;a href=&quot;http://renderingpipeline.com/2012/03/are-vertex-shaders-obsolete/&quot; rel=&quot;nofollow&quot;&gt;link&lt;/a&gt;) if deemed necessary.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;About engine API also one common thing is to defer the issuing of the state-setting commands required by the client. If a client requests &quot;set camera 0&quot;, it is best to just store this request and if later the client calls &quot;set camera 1&quot; but with no other commands in between, the engine can detect the uselessness of the first command and drop it. This is redundancy elimination, which is possible by using a &quot;fully retained&quot; paradigm. By opposition to &quot;immediate&quot; paradigm, which would be just a wrapper above the native API and issue the commands right as ordered by client code. (&lt;a href=&quot;http://virtrev.git.sourceforge.net/git/gitweb.cgi?p=virtrev/virtrev;a=tree;f=coding/opencl_opengl_sharing/src;hb=HEAD&quot; rel=&quot;nofollow&quot;&gt;example: virtrev&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally, with modern hardware, a very expensive (to develop), but potentially highly rewarding step to take is to switch API to metal/mantle/vulkan/DX12-style and preparing the rendering commands by hand.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An engine that prepares rendering commands creates a buffer that holds a &quot;command list&quot; that is overwritten at each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually there is a notion of frame &quot;budget&quot;, a game can afford. You need to do everything in 16 milliseconds, so you clearly partition GPU time &quot;2 ms for lightpre pass&quot;, &quot;4 ms for materials pass&quot;, &quot;6 ms for indirect lighting&quot;, &quot;4 ms for postprocesses&quot;...&lt;/p&gt;&#xA;" OwnerUserId="1614" LastEditorUserId="5314" LastEditDate="2016-10-18T13:38:34.603" LastActivityDate="2016-10-18T13:38:34.603" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1807" PostTypeId="2" ParentId="1788" CreationDate="2015-12-15T00:12:41.023" Score="7" Body="&lt;p&gt;&lt;strong&gt;SOLUTION&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After a couple of days I realized that &lt;strong&gt;I was computing my projection matrix using a FOV angle in degrees and It should be in radians&lt;/strong&gt;. I made the conversion and now everything works great. The interpolation among faces of my depth framebuffer's cubemap is now perfect. For this reason, It is important to handle every single trigonometric function's angle in radians.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, I realized that you can compute your view matrix either as I said in the question and in this way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;view.lookAt(position, target.add(position.clone()), up);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This approach means that your point of view is placed in pointlight's center and you just render in each direction of your cubemap, but which are these directions? well, &lt;strong&gt;these directions are computed adding each target that I've in the switch block (according to each cubemap's face) with your pointlight's position&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, &lt;strong&gt;It is not necessary to flip Y-Coordinate of the projection matrix&lt;/strong&gt;, In this case, It is ok dispatch pointlight's perspective projection matrix to your GLSL shader without scaling It by (1, -1, 1) because &lt;strong&gt;I'm working with textures that don't have a flipped Y-Coordinate&lt;/strong&gt;, I think you should flip Y-Coordinate of your pointlight's projection matrix &lt;strong&gt;only if you are working with a flipped texture's Y-Coordinate&lt;/strong&gt;, this in order to have a correct omnidirectional shadow mapping effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, I'll leave here the final version of my Omnidirectional Shadow Mapping algorithm on CPU/GPU side. On CPU side I'll explain every step that you have to do in order to compute a correct shadow map for each cubemap's face. On the other hand in GPU side, I'll explain my depth program's vertex/fragment shader and omnidirectional shadow mapping function in my main fragment shader, this in order to help somebody who could be learning this technique, or solve future doubts about this algorithm:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;CPU&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  // Disable blending and enable front face culling.&#xA;&#xA;  this.state.disable(gl.BLEND);&#xA;&#xA;  this.state.enable(gl.CULL_FACE);&#xA;  this.state.cullFace(gl.FRONT);&#xA;&#xA;  // Binds depth program&#xA;&#xA;  program.bind(gl);&#xA;&#xA;  // For each pointlight source do&#xA;&#xA;  for (i = 0; i &amp;lt; lights.length; i++) {&#xA;    light = lights[i];&#xA;&#xA;    // Get each pointlight's world position&#xA;&#xA;    position = light.worldPosition();&#xA;&#xA;    // Binds pointlight's depth framebuffer. Besides, in this function,&#xA;    // viewport's dimensions are set according to depth framebuffer's dimension.&#xA;&#xA;    light.depthFramebuffer.bind(gl, this.state);&#xA;&#xA;    // Updates point light's framebuffer in order to create it &#xA;    // or if it's resolution have changed, it'll be created again.&#xA;&#xA;    light.depthFramebuffer.update(gl);&#xA;&#xA;    // Check in which cubemap's face we are ...&#xA;&#xA;    for (j = 0; j &amp;lt; 6; j++) {&#xA;      switch (j) {&#xA;        case Cubemap.POSITIVE_X:&#xA;          target.set(1, 0, 0);&#xA;          up.set(0, -1, 0);&#xA;          break;&#xA;        case Cubemap.NEGATIVE_X:&#xA;          target.set(-1, 0, 0);&#xA;          up.set(0, -1, 0);&#xA;          break;&#xA;        case Cubemap.POSITIVE_Y:&#xA;          target.set(0, 1, 0);&#xA;          up.set(0, 0, 1);&#xA;          break;&#xA;        case Cubemap.NEGATIVE_Y:&#xA;          target.set(0, -1, 0);&#xA;          up.set(0, 0, -1);&#xA;          break;&#xA;        case Cubemap.POSITIVE_Z:&#xA;          target.set(0, 0, 1);&#xA;          up.set(0, -1, 0);&#xA;          break;&#xA;        case Cubemap.NEGATIVE_Z:&#xA;          target.set(0, 0, -1);&#xA;          up.set(0, -1, 0);&#xA;          break;&#xA;      }&#xA;&#xA;      // Creates a view matrix using target and up vectors &#xA;      // according to each face of pointlight's cubemap.&#xA;&#xA;      view.lookAt(position, target.add(position.clone()), up);&#xA;&#xA;      // Attaches cubemap's face to current framebuffer &#xA;      // in order to record depth values in that direction.&#xA;&#xA;      light.depthFramebuffer.texture.attach(gl, j);&#xA;&#xA;      // Clears color &amp;amp; depth buffers of your current framebuffer&#xA;&#xA;      this.clear();&#xA;&#xA;      // Render each shadow caster mesh using your depth program&#xA;&#xA;      for (k = 0; k &amp;lt; meshes.length; k++)&#xA;        this._renderMeshDepth(program, meshes[k], view, light.projection);&#xA;    }&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;On renderMeshDepth function I've:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  // Computes pointlight's model-view matrix &#xA;&#xA;  modelView.mul(view, mesh.world);&#xA;&#xA;  // Dispatch each matrix to the GLSL depth program&#xA;&#xA;  program.loadUniformMatrix(gl, 'uModelView', modelView);&#xA;  program.loadUniformMatrix(gl, 'uProjection', projection);&#xA;&#xA;  // Renders a mesh using vertex buffer objects (VBO)&#xA;&#xA;  mesh.render(gl, program.attributes, this.state, this.extensions);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;GPU&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depth Program Vertex Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;attribute vec3 position;&#xA;&#xA;uniform mat4 uModelView;&#xA;uniform mat4 uProjection;&#xA;&#xA;void main() {&#xA;  gl_Position = uProjection * uModelView * vec4(position, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Depth Program Fragment Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;// The pack function distributes fragment's depth precision storing &#xA;// it throughout (R,G,B,A) color channels and not just R color channel &#xA;// as usual in shadow mapping algorithms. This is because I'm working&#xA;// with 8-bit textures and one color channel hasn't enough precision &#xA;// to store a depth value.&#xA;&#xA;vec4 pack(const in float depth) {&#xA;  const vec4 bitShift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);&#xA;  const vec4 bitMask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);&#xA;&#xA;  vec4 res = fract(depth * bitShift);&#xA;  res -= res.xxyz * bitMask;&#xA;&#xA;  return res;&#xA;}&#xA;&#xA;void main() {&#xA;  // Packs normalized fragment's Z-Coordinate which is in [0,1] interval.&#xA;&#xA;  gl_FragColor = pack(gl_FragCoord.z);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Omnidirectional Shadow Mapping function in my main fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Unpacks fragment's Z-Coordinate which was packed &#xA;// on the depth program's fragment shader.&#xA;&#xA;float unpack(in vec4 color) {&#xA;   const vec4 bitShift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);&#xA;   return dot(color, bitShift);&#xA;}&#xA;&#xA;// Computes Omnidirectional Shadow Mapping technique using a samplerCube&#xA;// vec3 lightPosition is your pointlight's position in world coordinates.&#xA;// vec3 vPosition is your vertex's position in world coordinates, in code&#xA;// I mean this -&amp;gt; vPosition = vec3(uModel * vec4(position, 1.0));&#xA;// where uModel is your World/Model matrix.&#xA;&#xA;float omnidirectionalShadow(in vec3 lightPosition, in float bias, in float darkness, in samplerCube sampler) {&#xA;    vec3 direction = vPosition - lightPosition;&#xA;    float vertexDepth = clamp(length(direction), 0.0, 1.0);&#xA;    float shadowMapDepth = unpack(textureCube(sampler, direction)) + bias;&#xA;&#xA;    return (vertexDepth &amp;gt; shadowMapDepth) ? darkness : 1.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here you have a final render of the algorithm&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AvMHa.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AvMHa.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have fun coding beautiful graphics, good luck :) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;C.Z.&lt;/p&gt;&#xA;" OwnerUserId="2228" LastEditorUserId="2228" LastEditDate="2015-12-21T15:05:18.920" LastActivityDate="2015-12-21T15:05:18.920" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1809" PostTypeId="1" AcceptedAnswerId="1811" CreationDate="2015-12-15T18:51:57.800" Score="14" ViewCount="1971" Body="&lt;p&gt;I thought I had formed a general understanding of how OpenGL naming conventions and extensions worked, until I stumbled upon a case that confused me.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here's my understanding so far:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;No suffix&lt;/strong&gt; -- e.g. &lt;code&gt;glGenBuffers()&lt;/code&gt;. This function is a part of the core profile. The &lt;a href=&quot;https://www.opengl.org/wiki/GLAPI/glGenBuffers&quot;&gt;wiki page&lt;/a&gt; tells me that this was added to the core profile starting from version 1.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;ARB&lt;/strong&gt; -- e.g. &lt;code&gt;glGenBuffersARB()&lt;/code&gt;. This function is part of the standardized &lt;code&gt;GL_ARB_vertex_buffer_object&lt;/code&gt; extension. The &lt;a href=&quot;https://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt&quot;&gt;spec&lt;/a&gt; of this extension clearly declares &lt;code&gt;GenBuffersARB()&lt;/code&gt; in the &quot;New Procedures and Functions&quot; section. The &quot;Dependencies&quot; section tells me that I can potentially access this from a 1.4+ context, if the hardware supports the extension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EXT&lt;/strong&gt; -- These are vendor-specific extensions and functions that only some vendors may support. Vertex buffer object doesn't seem to have an EXT extension in the registry.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here's where my understanding breaks down:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;glGenFramebuffers&lt;/code&gt;, as the &lt;a href=&quot;https://www.opengl.org/wiki/GLAPI/glGenFramebuffers&quot;&gt;wiki&lt;/a&gt; shows, was added to the core in 3.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I want to access the frame buffer features at a lower core profile version than 3.0. So I want to use it as an extension. The spec registry tells me that there are two available extensions - &lt;a href=&quot;https://www.opengl.org/registry/specs/ARB/framebuffer_object.txt&quot;&gt;ARB&lt;/a&gt; and &lt;a href=&quot;https://www.opengl.org/registry/specs/EXT/framebuffer_object.txt&quot;&gt;EXT&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 1&lt;/strong&gt; -- If an ARB extension exists, why does an EXT extension exist? Wouldn't you always choose the standardized one over the vendor-specific one?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A look at the ARB spec in the &quot;New procedures and functions&quot; section tells me that the extension defines the &lt;code&gt;GenRenderbuffers()&lt;/code&gt; function. No ARB suffix this time. GLEW doesn't have a function prototype for &lt;code&gt;glGenRenderbuffersARB()&lt;/code&gt; at all. Weird.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The EXT spec does however have a &lt;code&gt;GenRenderbuffersEXT()&lt;/code&gt; function in the new functions section, and GLEW also has&lt;code&gt;glGenRenderbuffersEXT()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 2&lt;/strong&gt; -- Why no ARB suffix if there's an EXT suffix? How does this work for ARB, given that the names of the ARB function and the core function are the same? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 3&lt;/strong&gt; -- I ultimately want Framebuffer features from a 1.4 profile. Which extension and which function-set should I use so that I get maximum hardware compatibility coverage?&lt;/p&gt;&#xA;" OwnerUserId="88" LastEditorUserId="88" LastEditDate="2015-12-15T18:58:07.407" LastActivityDate="2015-12-16T01:03:39.430" Title="OpenGL compatibility, naming conventions and ARB vs EXT" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1811" PostTypeId="2" ParentId="1809" CreationDate="2015-12-16T01:03:39.430" Score="9" Body="&lt;p&gt;&lt;strong&gt;Question 1&lt;/strong&gt; -- Usually the EXT version comes first as a collaboration between two or more vendors. ARB extensions require more discussion among voting members of Khronos and can have changes from the EXT version before getting approved. See the GL_ARB_direct_state_access extension which has many changes compared to GL_EXT_direct_state_access.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 2&lt;/strong&gt; --&#xA;The Issues section of the GL_ARB_framebuffer_object extension states why the functions do not have ARB suffixes:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;(8) Why don't the new tokens and entry points in this extension have suffixes like other ARB extensions?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   RESOLVED: Unlike most ARB extensions, this is a strict subset of&#xA;   functionality already approved in OpenGL 3.0. This extension&#xA;   exists only to support that functionality on older hardware that&#xA;   cannot implement a full OpenGL 3.0 driver. Since there are no&#xA;   possible behavior changes between the ARB extension and core&#xA;   features, source code compatibility is improved by not using&#xA;   suffixes on the extension.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 3&lt;/strong&gt; --&#xA;If you want to use framebuffer objects on a context where the GL version is less than 3.0 you need to look at the extension string:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If GL_ARB_framebuffer_object is supported, use the non ARB functions.&lt;/li&gt;&#xA;&lt;li&gt;If only GL_EXT_framebuffer_object is supported, use the EXT functions.&lt;/li&gt;&#xA;&lt;li&gt;If neither extension are supported, you need to fall back to OS level offscreen rendering like pbuffers.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="40" LastActivityDate="2015-12-16T01:03:39.430" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1815" PostTypeId="1" AcceptedAnswerId="1816" CreationDate="2015-12-18T13:45:43.347" Score="13" ViewCount="2184" Body="&lt;p&gt;I computed a Voronoï diagram from a set of points (with &lt;a href=&quot;http://www.boost.org/doc/libs/1_60_0/libs/polygon/doc/voronoi_diagram.htm&quot; rel=&quot;noreferrer&quot;&gt;Boost.polygon&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I try to find a Delaunay triangulation, connecting each cell center for each Voronoï edge, but I miss some edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the following image, the red dots are my initial points, the blue lines are the Voronoï edges (I ignored infinite edges), and the green lines are the triangulation edges (one green edge for each blue edge, connecting two cell origins).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can see that diagonal edges are missing. What am I missing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JXNcc.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JXNcc.png&quot; alt=&quot;voronoi diagram&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2173" LastEditorUserId="231" LastEditDate="2015-12-18T17:47:13.000" LastActivityDate="2016-11-30T16:02:01.873" Title="How to triangulate from a Voronoï diagram?" Tags="&lt;triangulation&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1816" PostTypeId="2" ParentId="1815" CreationDate="2015-12-18T20:44:40.927" Score="19" Body="&lt;p&gt;The centre point in your diagram is a degenerate edge of the Voronoi diagram. If you generate a Voronoi diagram for an irregular point cloud, every vertex will have degree 3. A vertex with degree 4 (or more) can only happen when two (or more) vertices coincide. That means there is a zero-length edge between them. But that edge should still have a corresponding edge in the Delaunay triangulation. The issue is that it's arbitrary which of the two possible edges you pick, because the zero-length edge has no associated direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To visualise what I'm talking about, consider starting with four less regularly spaced points (such that we start off with only degree-3 vertices) and gradually translating them into their regular positions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can do this in two different ways, which both lead to the degenerate case in your diagram. You will see that you end up with two different Delaunay triangulations, which are both valid limits for the degenerate case:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eu33Z.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eu33Z.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/6S6oX.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6S6oX.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume that your code is missing this degenerate case for one reason or another, but without actually seeing how you compute the Delaunay triangulation from the Voronoi diagram it's impossible to point you any further than this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note that having even higher degeneracies (by more than four points distributed at equal angles around a circle) would probably require additional attention:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5DgNy.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5DgNy.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/AddyS.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AddyS.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These animations also show that (even in a non-degenerate case), the corresponding Voronoi and Delaunay edges do not necessarily actually cross within their finite extent. That might make it harder to see that the 2 (or 3) edges that triangulate the regular polygon at the end actually correspond to several degenerate edges which are all at the centre. Also note that in total there are 5 different triangulations of the pentagon and 14 triangulations of the hexagon (although I don't know whether all 14 can be obtained by deforming a non-degenerate triangulation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt; (by OP)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Voronoi diagrams computed with &lt;a href=&quot;http://www.boost.org/doc/libs/1_60_0/libs/polygon/doc/index.htm&quot; rel=&quot;noreferrer&quot;&gt;Boost.polygon&lt;/a&gt; enable to walk through each Voronoi vertex, and each edge linked to those vertices (clockwise or counter-clockwise). In this way, it is possible to create one triangle for each pair of edges (two connected edges will link to 3 cells).&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2016-11-30T16:02:01.873" LastActivityDate="2016-11-30T16:02:01.873" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1818" PostTypeId="1" AcceptedAnswerId="1819" CreationDate="2015-12-21T07:14:25.690" Score="18" ViewCount="5040" Body="&lt;p&gt;With OpenGL and such I can render some pretty amazing looking things in &quot;real time&quot; 60 FPS.  However, if I try to make a video of that same scene in let's say Maya, or 3ds Max it would take MUCH MUCH longer for it to render even though it is the same resolution and FPS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why do these two types of rendering take different periods of time for the same result?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: Yes I do realize that 3D animation software can produce highly superior images to what could be done real time. But for this question I am referring to a scene of equal complexity.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="127" LastEditDate="2015-12-21T10:50:34.440" LastActivityDate="2015-12-23T05:00:45.190" Title="Difference between rendering in OpenGL and 3D animation software" Tags="&lt;rendering&gt;&lt;performance&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1819" PostTypeId="2" ParentId="1818" CreationDate="2015-12-21T09:30:23.303" Score="9" Body="&lt;p&gt;The main difference would be that with OpenGL in let's say a video game you will have a process called &lt;em&gt;rasterization&lt;/em&gt; which basically takes care of determining what part of the scene you see.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It needs to be fast so we can experience it as realtime.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore the algorithm does a few simple steps.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;check if a certain part of the scene is in my view frustum&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TqkCF.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TqkCF.jpg&quot; alt=&quot;Frustum Culling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;check if something is in front of it which may needs to be rendered later using a depth buffer&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7N5cL.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7N5cL.gif&quot; alt=&quot;Depth Buffer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;order the objects we found to draw&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;draw them&lt;/em&gt; by projecting them on the screen&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;shade them&lt;/em&gt; based on textures / shaders / lights / ...&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;On the other hand a rendering software (Blender/Max/Maya/...) most likely uses some kind of &lt;em&gt;raytracing&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This involves alot more math to achieve a higher degree of realism.&#xA;It basically works in the same way:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;create a camera and an image plane infront of it&lt;/li&gt;&#xA;&lt;li&gt;shoot one ray (or multiple sample rays) through each pixel&lt;/li&gt;&#xA;&lt;li&gt;check if the ray hits anything in the scene&lt;/li&gt;&#xA;&lt;li&gt;closest hit is the one to be drawn in the pixel finally (like depth buffer)&lt;/li&gt;&#xA;&lt;li&gt;calculate the light for the given point&#xA;&lt;a href=&quot;https://i.stack.imgur.com/jmB0K.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jmB0K.png&quot; alt=&quot;Light Calculation&quot;&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;....&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll stopped listing here since this is the point where raytracing takes off.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of only checking if a point is hit, most raytracer now begins to calculate: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the amount of light a surface penetrates&lt;/li&gt;&#xA;&lt;li&gt;how much light gets reflected&lt;/li&gt;&#xA;&lt;li&gt;cast new rays from the hitpoint into the scene until it may hit a light source&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There are a ton of techniques with different degrees of realism which can be used to calculate the light of a certain point in the scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&#xA;The gist would be that a raytracer mostly tries to be physically accurate when it comes the lighting and therefore has a lot of more calculations to do per pixel (sometimes shoot thousands of rays) and on the other hand games get their speed by drawing bigger chunks of the screen with simpler light calculations and a lot of shader tricks which let it look realistic.&lt;/p&gt;&#xA;" OwnerUserId="239" LastEditorUserId="127" LastEditDate="2015-12-21T10:57:34.817" LastActivityDate="2015-12-21T10:57:34.817" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1820" PostTypeId="1" AcceptedAnswerId="1821" CreationDate="2015-12-21T11:58:38.770" Score="8" ViewCount="6240" Body="&lt;p&gt;Im trying to plot the x and y positions of an &lt;a href=&quot;https://en.wikipedia.org/wiki/Archimedean_spiral&quot; rel=&quot;nofollow noreferrer&quot;&gt;Archimedean spiral&lt;/a&gt; in C++.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wSmFI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wSmFI.png&quot; alt=&quot;Archimedean spiral&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've been trying something like this, but no luck:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;int dx = 0;&#xA;int dy = 0;&#xA;int x = 0;&#xA;int y = 0;&#xA;&#xA;for (int i = 0; i &amp;lt; maxPoints; i++)&#xA;{&#xA;    dx = sin(i * PI / 2);&#xA;    dy = cos(-i * PI / 2);&#xA;    x += dx;&#xA;    y += dy;&#xA;&#xA;    plot(x, y);    &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;EDIT: More info&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm developing a 3D game application that demonstrates the use of the &lt;a href=&quot;http://bulletphysics.org/wordpress/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bullet&lt;/a&gt; physics engine by simulating dominos. Instead of placing the dominos in the scene manually I want to use some math to do it for me :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For anyone who is interested here it is on &lt;a href=&quot;https://github.com/damorton/bullet-dominos&quot; rel=&quot;nofollow noreferrer&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2248" LastEditorUserId="2248" LastEditDate="2015-12-22T21:28:53.727" LastActivityDate="2015-12-26T15:50:42.340" Title="Archimedean spiral in C++" Tags="&lt;c++&gt;&lt;geometry&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1821" PostTypeId="2" ParentId="1820" CreationDate="2015-12-21T12:24:56.043" Score="7" Body="&lt;p&gt;Figured it out :) The dominos are now being placed along the X and Y coordinates generated by the function. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The original code in the question was plotting a wave of points outwards from the centre position or origin and was not what I wanted. What I needed was for each point to follow the &lt;code&gt;Archimedean spiral&lt;/code&gt; with a certain space between the spirals. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Initially I used &lt;code&gt;integer&lt;/code&gt; values to store the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; coordinates but this was causing a precision error by truncating the &lt;code&gt;floating point&lt;/code&gt; value in order to store it in the &lt;code&gt;integer&lt;/code&gt; data type.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The below example generates points along the spiral continuously, relative to the &lt;code&gt;maxPoints&lt;/code&gt; value. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float x = 0;&#xA;float y = 0;&#xA;float angle = 0.0f;&#xA;&#xA;// Space between the spirals&#xA;int a = 2, b = 2;&#xA;&#xA;for (int i = 0; i &amp;lt; maxPoints; i++)&#xA;{&#xA;    angle = 0.1 * i;&#xA;    x = (a + b * angle) * cos(angle);&#xA;    y = (a + b * angle) * sin(angle);&#xA;&#xA;    plot(x, y);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Code for the project is on &lt;a href=&quot;https://github.com/damorton/bullet-dominos/blob/master/CAPhysics/Chapter4.2/BasicDemo.cpp&quot; rel=&quot;nofollow&quot;&gt;GitHub&lt;/a&gt;, you will need &lt;a href=&quot;http://bulletphysics.org/wordpress/&quot; rel=&quot;nofollow&quot;&gt;Bullet&lt;/a&gt; and &lt;a href=&quot;http://freeglut.sourceforge.net/&quot; rel=&quot;nofollow&quot;&gt;freeglut&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2248" LastEditorUserId="2248" LastEditDate="2015-12-22T21:48:24.973" LastActivityDate="2015-12-22T21:48:24.973" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1822" PostTypeId="2" ParentId="1818" CreationDate="2015-12-21T13:15:35.117" Score="7" Body="&lt;h3&gt;You're comparing apples to oranges&lt;/h3&gt;&#xA;&lt;p&gt;The game is like the view port in your modelling app. You can use the viewport for render and you will get same 60fps speeds.&lt;/p&gt;&#xA;&lt;p&gt;There is no reason why you can not get realtime graphics that are very good out of modelling software like Maya or 3DS Max. Results that are par with many games. They have viewport shaders just like games do. There is also a viewport rendering option that chunks frames to disk as fast as it allows (I've done full HD renders at 30 fps from Maya). All you have to do is stop using the provided software raytracers.&lt;/p&gt;&#xA;&lt;p&gt;There are some differences though. The primary difference is that you as a user do not optimize stuff as much as game developers do (optimization is using all the tricks in the book). Second your animation primitives work on the CPU because you need the flexibility. In games one can afford to do optimizations. All in all you pay for not having a programming team next to you.&lt;/p&gt;&#xA;&lt;p&gt;Many of the things may in fact have been precomputed, so they aren't so much faster just better organized. Baking your indirect illumination will beat non baked results every day.&lt;/p&gt;&#xA;&lt;h3&gt;Why are the raytracers slower?&lt;/h3&gt;&#xA;&lt;p&gt;They aren't*, one just tends to do more work on a ray tracer because its easy. Feature by feature they aren't much slower in computation cycles. For example theres no need for a ray tracer to cast secondary rays (life reflections in that case the ray tracer will cull geometry away, or not even load it, in fact mental ray does just that). Its just usually done because it trivial to do so and that's the clear advantage of ray tracers. You can even configure them to run on the CPU in some cases. They are just optimized for different things:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Emitting data to disk, not just frames but all data. Something which would break most games speediness instantly.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Working on general hardware. The GPU is much faster for certain things once you optimize for the GPU. But it does not work for all loads, in fact a Intel CPU is faster at computing in general than the GPU. The GPU is just massively parallel which the CPU is not. The architecture wins if you can stay in the GPU and minimize transfer and optimize for the GPU architecture.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;So you pay for flexibility and ease of use. But yes ill admit both Maya and Max suffer from extreme old age. So they could be faster.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; The difference is mostly in optimization (read lots of tricks) and available external resources.&lt;/p&gt;&#xA;&lt;p&gt;PS: There is a misconception that this is because it is more physically correct. It certainly can be but the ray tracer is not inherently more physically correct than your average game or any other computation. In fact many games use really good models while quite many modelers do not.&lt;/p&gt;&#xA;&lt;p&gt;* See &lt;a href=&quot;http://www.graphics.cornell.edu/%7Ebjw/mca.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://www.graphics.cornell.edu/~bjw/mca.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2015-12-22T10:05:13.287" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1824" PostTypeId="1" AcceptedAnswerId="1825" CreationDate="2015-12-22T02:47:08.040" Score="19" ViewCount="2680" Body="&lt;p&gt;I am currently trying to understand a few things about vector graphics rasterization and the different ways it is implemented in various application types.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tested and compared a few programs and noticed that there is a major difference in the way &lt;strong&gt;anti-aliasing&lt;/strong&gt; behaves in the rasterization process. &lt;strong&gt;I am especially interested in the rendering behavior in Illustrator&lt;/strong&gt;. You will see why by reading further.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/J4ocR.png&quot; alt=&quot;Base image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For my testing, I used a really simple composition of triangles organized in an irregular hexagon with different colors.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Vector graphics softwares&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Here are three renders of the same vector graphic in Illustrator, Affinity and Inkscape. (The image produced in Affinity and Inkscape are exactly the same.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/OCJdY.png&quot; alt=&quot;Images rendered in popular graphic editing tools&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see there is an undesired white line on each of the edges in the image rendered with Affinity and Inkscape. The anti-aliasing does not fill this area with a solid color which results in a small gap between adjacent shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although there is no gap in the Illustrator render, the edges of the shapes look as smooth as the Affinity render.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an image showing the same area of each image upscaled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/6DBZt.png&quot; alt=&quot;Upscale render showing anti-aliasing&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a very subtle difference between the two images. The Affinity render is a tiny bit smoother but it is almost impossible to see the difference when looking at the images in their original sizes.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Browsers&lt;/h2&gt;&#xA;&#xA;&lt;h3&gt;SVG rendering&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Displaying the same graphics exported as SVG in a browser looks very similar to the raster image produced by both Affinity and Inkscape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/wUHjQ.png&quot; alt=&quot;SVG file rendered in browser&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are very tiny differences in edges anti-aliasing (that are not really worth showing here) but SVG rasterization in common browsers behaves pretty much the same.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Decomposed render&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Testing Illustrator rendering a bit further, I tried splitting parts of my graphics and exporting them individually then composing them back together with a raster editing software.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/iXbo2.png&quot; alt=&quot;Image recomposition scheme&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In theory it would result in the same image as having it in a single piece, but the result is slightly different using this method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/qq7Gr.png&quot; alt=&quot;Result of recomposed image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As shown, when the two parts are composed, there is a tiny gap between them. Though it is more subtle, it is very similar to the graphic rendered in Affinity.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Polygon rendering&lt;/h2&gt;&#xA;&#xA;&lt;h3&gt;Blender (3D software)&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/oOwG9.png&quot; alt=&quot;SVG in Blender viewport&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blender allows you to import SVG files and manipulate them as curve objects. Here is the imported graphic shown in the 3D viewport. (By default material will be affected by lights in the scene. Checking the shadeless property in the material property panel will allow the shapes to be rendered with their original colors.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a render made of the SVG inside Blender.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/2NZfe.png&quot; alt=&quot;Actual render in Blender&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It does not have any gap between the triangles. Other 3D softwares are very likely to work the same way. So Blender behaves just like &lt;strong&gt;Illustrator&lt;/strong&gt;, or does it? Maybe it is the other way around?&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;The real questions&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Which vector drawing library does Illustrator use behind the scenes?&lt;/li&gt;&#xA;&lt;li&gt;Could it be possible that Illustrator makes use of a sort of 3D rendering engine? Is it open source? (probably not?)&lt;/li&gt;&#xA;&lt;li&gt;Can any of the well known vector drawing libraries such as Cairo and Skia achieve the same rendering behavior? (No gap between shapes)&lt;/li&gt;&#xA;&lt;li&gt;Is there any less known vector drawing library out there that has the same behavior?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2319" LastEditorUserId="231" LastEditDate="2015-12-22T12:30:04.157" LastActivityDate="2016-01-06T21:44:45.993" Title="What is Illustrator's vector rasterization process?" Tags="&lt;antialiasing&gt;&lt;vector-graphics&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1825" PostTypeId="2" ParentId="1824" CreationDate="2015-12-22T08:01:30.097" Score="11" Body="&lt;p&gt;As as far as I can tell Illustrator has 2 or 3 different rasterizer. The onscreen preview is also prone to the same gap artifacting as your show though its tuned to minimize the effect. Your post seems to imply that your interested in the &quot;&lt;em&gt;art optimized&lt;/em&gt;&quot; output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tf7V4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tf7V4.png&quot; alt=&quot;Art optimized versus screen preview of illustrator&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: The different render modes of illustrator. Art optimized on left and hinted on right. Note that hinted shows slight background through. I dont have the new CC version so i can not show the third.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;How does art optimized work then&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Art optimized render mode is simply a un-antialiased image rendered at higher resolution, that has then been subjected to a &lt;strong&gt;box filtering&lt;/strong&gt;. This is called super sampling which is costly. A box filter is simply the mean value of the samples in the box (pixel). This is indeed a similar technology as what the multi pixel filter used in your blender render uses. You can do the same thing manually and get same results. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact the render you get form illustrator is not really good. Its rendered in nonlinear space and not corrected for and you can get better results by swapping to higher order filters and computing in linear color space. All multi sample methods exhibit the same correct rendering (given enough samples even mathematically correct).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EfM61.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EfM61.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Multi pixel filtering, on left illustrator native 'Art Optimized'. On right same image at 16x16 pixels with multi lobed &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/58162/how-to-draw-smooth-curved-shapes-in-illustrator/58175#58175&quot;&gt;Lanczos filter in linear space&lt;/a&gt;. Make sure your zoom is 1:1.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;The problem&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;You have in fact come at terms with the real problem of current generation of onscreen renderers. They try to avoid multi sampling in favor for coverage calculation. But it simply can not work perfectly! Simply because alpha blend is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$c_0= c_1*\alpha + c_2*(1-\alpha)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When chained never reaches 0 when chained over semitransparent surfaces so background show trough. Also it does not know how the coverage is distributed so it will do it wrong. There's simply no way around this in a non-overlapping case like this. but if you allow the shapes overlap then the coverage calculation can be solved (See &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/47342/space-between-2-paths-illustrator&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Other questions&lt;/strong&gt; You can get same result in any other engine by just simply multisampling a non-antialiased image. You can not get the effect in on screen renderings without doing the overlap trick because they optimize for speed. Does illustrator use 3D? New CC might depends on your interpretation of what 3D is. This issue has nothing to do with 3D just about signal reconstruction methods so its not applicable to the question really.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Related post &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/148/how-do-i-accurately-compute-coverage-of-overlapping-analytical-curves/150#150&quot;&gt;how-do-i-accurately-compute-coverage-of-overlapping-analytical-curves&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2015-12-22T09:11:41.397" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1827" PostTypeId="2" ParentId="1818" CreationDate="2015-12-23T00:17:52.060" Score="6" Body="&lt;p&gt;&lt;strong&gt;Real-Time Preview&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Working in the VFX side of the industry, if you're talking about real-time viewport previews and not production rendering, then Maya and 3DS Max typically also use OpenGL (or possibly DirectX -- pretty much the same).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of the main conceptual differences between VFX animation software and games is the level of assumptions they can make. For example, in VFX software, it's not uncommon for the artist to load a single, seamless character mesh that spans hundreds of thousands to millions of polygons. Games tend to optimize most for a large scene consisting of a boatload of simple, optimized meshes (thousands of triangles each).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Production Rendering and Path Tracing&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VFX software also places the emphasis not on the real-time preview but on production rendering where light rays are actually simulated one at a time. The real-time preview often is just that, a &quot;preview&quot; of the higher-quality production result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Games are doing a beautiful job of approximating a lot of those effects lately like real-time depth of field, soft shadows, diffuse reflections, etc., but they're in the heavy-duty approximation category (ex: blurry cube maps for diffuse reflections instead of actually simulating light rays).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Content&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Coming back to this subject, the content assumptions between a VFX software and game wildly differ. A VFX software's main focus is to allow any possible kind of content to be created (at least that's the ideal, although in practically it's often nowhere close). Games focus on content with a lot more heavier assumptions (all models should be in the range of thousands of triangles, normal maps should be applied to fake details, we shouldn't actually have 13 billion particles, characters aren't actually animated by muscle rigs and tension maps, etc).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Due to those assumptions, game engines can often more easily apply acceleration techniques like frustum culling which enable them to maintain a high, interactive frame rate. They can make assumptions that some content is going to be static, baked down in advance. VFX software can't easily make those kinds of assumptions given the much higher degree of flexibility in content creation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Games Do it Better&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This might be kind of a controversial view, but the game industry is a much more lucrative industry than VFX software. Their budgets for a single game can span in the hundreds of millions of dollars, and they can afford to keep releasing next-generation engines every few years. Their R&amp;amp;D efforts are amazing, and there are hundreds upon hundreds of game titles being released all the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VFX and CAD software, on the other hand, is nowhere near as lucrative. R&amp;amp;D is often outsourced by researchers working in academic settings, with a lot of the industry often implementing techniques published many years before as though it's something new. So VFX software, even coming from companies as large as AutoDesk, often isn't quite as &quot;state-of-the-art&quot; as the latest AAA game engines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They also tend to have a much longer legacy. Maya is a 17-year old product, for example. It's been refurbished a lot, but its core architecture is still the same. This might be analogous to trying to take Quake 2 and keep updating and updating it all the way up until 2015. The efforts can be great but probably won't match Unreal Engine 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So anyway, that's a little take on that side of the topic. I couldn't make out whether you were talking about real-time previews in viewports or production rendering, so I tried to cover a bit of both.&lt;/p&gt;&#xA;" OwnerUserId="2247" LastEditorUserId="2247" LastEditDate="2015-12-23T05:00:45.190" LastActivityDate="2015-12-23T05:00:45.190" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1828" PostTypeId="2" ParentId="1820" CreationDate="2015-12-23T13:22:21.527" Score="4" Body="&lt;p&gt;This isn't really a direct answer to this question (that already has an answer anyway), but might interest people who want to implement this algorithm in 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had to try implementing this algorithm to generate 3D spirals in blender using Python (could easily be converted to drawing with PIL or Matplotlib in 2D). So here's the algorithm and result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dcoM7.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dcoM7.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import bpy&#xA;from math import cos, sin&#xA;S = bpy.context.scene&#xA;&#xA;def add_archimedian_spiral( size = 0.1, length = 500, height = 1, name = 'archispiral' ):&#xA;    mesh = bpy.data.meshes.new( name = name )&#xA;&#xA;    o = bpy.data.objects.new(name, mesh)&#xA;    o.location = (0,0,0) # place at object origin&#xA;    S.objects.link( o )&#xA;&#xA;    z     = 0&#xA;    verts = []  &#xA;    for i in range( length ):&#xA;        angle = 0.1 * i&#xA;        x     = ( 2 * size * angle ) * cos( angle )&#xA;        y     = ( 2 * size * angle ) * sin( angle )&#xA;        z    += i / 10000 * height&#xA;        verts.append((x,y,z))&#xA;&#xA;    edges = []&#xA;    for i in range( len( verts ) ):&#xA;        if i == len( verts ) - 1: break&#xA;        edges.append((i, i+1))&#xA;&#xA;    mesh.from_pydata( verts, edges, [] )&#xA;&#xA;add_archimedian_spiral( size = 0.2, length = 500, height = 6 )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2317" LastEditorUserId="127" LastEditDate="2015-12-26T15:50:42.340" LastActivityDate="2015-12-26T15:50:42.340" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1829" PostTypeId="1" CreationDate="2015-12-23T23:52:07.863" Score="4" ViewCount="186" Body="&lt;p&gt;I need to be able to click on this polygon in 2d. This polygons set of vertices aren't in the same space as the screen. (Ie: the edge of the screen may be a value of 20 in one space but 1920 in the other) the scale is different. How can I convert the vertices of the polygon to the screen space so that I can use the mouse coordinates to click on it. (This is only 2d)&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2015-12-26T18:50:11.920" LastActivityDate="2015-12-26T22:21:54.680" Title="How to get polygon coordinates in screen space" Tags="&lt;transformations&gt;&lt;2d&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1830" PostTypeId="1" CreationDate="2015-12-24T13:10:00.983" Score="6" ViewCount="1775" Body="&lt;p&gt;Suppose i have a 400*300 gray scale image.Now I want to scan each line horizontally and make the average of that line 128,such that the values get scaled as per their difference from mean(128) which will not cause any distortion to image.&lt;/p&gt;&#xA;" OwnerUserId="2335" LastActivityDate="2016-01-01T07:45:53.923" Title="Average intensity of an gray image" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1831" PostTypeId="2" ParentId="1830" CreationDate="2015-12-24T14:41:00.023" Score="3" Body="&lt;p&gt;Here's an example on how to do this with Python, Numpy and Matplotlib.&#xA;Image on the right has been averaged (row by row), while the left is the original.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V4wFH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V4wFH.png&quot; alt=&quot;Before-After-Edited&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDITED&lt;/strong&gt;: As suggested by @Nathan Reed, I avoided flipping colors when row average is 0. Rows with an average of 0 now get a value of 0.5 (128). The dark image encountered previously was due to values higher than 1 (255) due to scaling, that were represented as white in matplotlib's image renderer. I fixed this by setting the max value in any pixel to be 1.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;import numpy as np&#xA;from matplotlib import image as mpimg&#xA;from matplotlib import pyplot as plt&#xA;&#xA;def rgb2gray(rgb):&#xA;    return np.dot( rgb[...,:3], [0.299, 0.587, 0.144] )&#xA;&#xA;imgPath = &quot;C:/myImg.jpg&quot;&#xA;&#xA;im = mpimg.imread( imgPath )&#xA;gs = rgb2gray( im )&#xA;&#xA;averaged = gs.copy()&#xA;&#xA;for row in averaged:&#xA;    rowAvg = sum( row ) / len( row )&#xA;    if rowAvg == 0:&#xA;        row = 0.5&#xA;    else:&#xA;        # Scale each row by ratio between 128 and current row avg&#xA;        row *= 0.5 / rowAvg&#xA;&#xA;    # Make sure that no pixel has a higher value than 1&#xA;    if rowAvg &amp;gt; 0: row[row&amp;gt;1] = 1&#xA;&#xA;plt.subplot( 1, 2, 1 ), plt.imshow( gs,       'gray' )&#xA;plt.subplot( 1, 2, 2 ), plt.imshow( averaged, 'gray' )&#xA;&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here's another test with a simple gradient image (left is the original):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/DhczR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DhczR.png&quot; alt=&quot;Before-After2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2317" LastEditorUserId="2317" LastEditDate="2015-12-25T22:48:07.470" LastActivityDate="2015-12-25T22:48:07.470" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1832" PostTypeId="1" CreationDate="2015-12-24T23:16:22.657" Score="6" ViewCount="615" Body="&lt;p&gt;I'm not too versed in computer graphics so my question may be vague.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm given a sequence of GPS coordinates which I draw on an iOS map, and they define bus routes. Some of the bus routes happen to share sections of certain streets however, and when multiple routes are being drawn on the map the colored line segments are just being overlapped currently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently looking into computationally separating the lines from each other before drawing, but I'm not sure that will get any success. So my backup is: are there any good techniques to draw the lines in a way that somehow does not hide the lower line segments, and retains at least partially their color?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Again as a disclosure, I'm not very knowledgable in this area. I know from Photoshop there are different color modes on the layers that have different effects when overlapped. Would something of that sort help in this situation? Or maybe there's a way to dash the lines such that it alternates each color, but I imagine that would be fairly difficult.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm just probing around for different techniques for this problem.&lt;/p&gt;&#xA;" OwnerUserId="2339" LastEditorUserId="127" LastEditDate="2015-12-26T18:34:47.877" LastActivityDate="2015-12-26T23:34:56.133" Title="Best technique to draw overlapping colored line segments that follow the same route" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;color&gt;&lt;line-drawing&gt;&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1833" PostTypeId="1" AcceptedAnswerId="1844" CreationDate="2015-12-25T03:54:51.673" Score="4" ViewCount="745" Body="&lt;p&gt;What is the pixel-level explanation of the fade effect, that was first popularized by Instagram? I want to implement this effect programmatically—that is, I want to understand what this effect is doing to each pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IVdTT.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IVdTT.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, if anyone could point me to resources from which I can learn more about how image filters are implemented, that would be great.&lt;/p&gt;&#xA;" OwnerUserId="2341" LastEditorUserId="231" LastEditDate="2015-12-27T13:35:16.263" LastActivityDate="2015-12-28T00:38:29.163" Title="Instagram's fade effect" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1834" PostTypeId="2" ParentId="1829" CreationDate="2015-12-25T12:28:38.090" Score="3" Body="&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; This answer is only helpful in 3D&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;If you want to do it geometrically...&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The inverse of the view-projection matrix, $K^{-1}$ is the matrix you want. Where $K = View * Projection$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If $\vec{v}$ is a point in homogeneous screen coordinates, $[x, y, 1]$ where $x$ and $y$ are whatever coordinates your $K$ matrix projects onto. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\vec{d} = K^{-1} * \vec{v}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $\vec{d}$ now represents a &lt;strong&gt;line&lt;/strong&gt; in homogeneous coordinates, coming out of your camera origin. Now you'd iterate through the objects in view, and choose the closest one in front of the camera that this line intersects with.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;But there are other ways!&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;Color Picking&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Here, we render (into a buffer) each object in view with a slightly different color, which corresponds to the object ID. We then read it using &lt;code&gt;glReadPixels(mouse_coordinates...)&lt;/code&gt; and decide which object we clicked. This is pretty easy to do in the new pipeline - you just write a color passthrough shader. Would not recommend pre OpenGL 3.0 (You'll have to do shenanigans to render the scene without interference)&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Selection Buffer (Old pipeline)&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If you're on the fixed pipeline, you get a nice little toy called the &lt;a href=&quot;http://www.glprogramming.com/red/chapter13.html&quot; rel=&quot;nofollow&quot;&gt;selection buffer&lt;/a&gt; to do the work for you.&lt;/p&gt;&#xA;" OwnerUserId="1988" LastEditorUserId="1988" LastEditDate="2015-12-26T22:21:54.680" LastActivityDate="2015-12-26T22:21:54.680" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1835" PostTypeId="1" CreationDate="2015-12-25T15:40:21.760" Score="5" ViewCount="289" Body="&lt;p&gt;I need to build terrain using one cube with dimensions 1x1x1, the coordinates are provided in a .txt file and there are about 11M triplets.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that using my current code I can only draw about 60k of them, then the browser tab is resetted and a prompt to stop an unresponsive script comes out, so I use too much memory and time to generate them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the chunk of code I use to draw them:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;function generateCubes(data) {&#xA;    var cubeGeometry = new THREE.CubeGeometry(cubeSize, cubeSize, cubeSize);&#xA;    var material = new THREE.MeshLambertMaterial({color: 0x587058});&#xA;    var mesh = new THREE.Mesh(cubeGeometry, material);&#xA;    var mergedGeo = new THREE.Geometry();&#xA;    var instance;&#xA;    var line = data[0].split(';');&#xA;    var translateX = line[0], translateY = line[1], translateZ = line[2];&#xA;    //var group = new THREE.Object3d();&#xA;    for(var i = 0; i &amp;lt; 100000; i++) { // should go to data.length&#xA;        line = data[i].split(';');&#xA;        //instance = mesh.clone();&#xA;        //instance.position.set(line[0] - translateX, line[2] - translateZ, line[1] - translateY);&#xA;        //group.add(instance);&#xA;        mesh.position.x = Number(line[0]) - translateX;&#xA;        mesh.position.y = Math.round(Number(line[2]) - translateZ);&#xA;        mesh.position.z = Number(line[1]) - translateY;&#xA;        mesh.updateMatrix();&#xA;        mergedGeo.merge(instance.geometry, instance.matrix);&#xA;    }&#xA;    group = new THREE.Mesh(mergedGeo, material);&#xA;    scene.add(group);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The function is called from a success in an &lt;code&gt;$.ajax&lt;/code&gt; call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The commented parts are used without merged geometry, that way I can draw around 100k of the data.&lt;/p&gt;&#xA;" OwnerUserId="2343" LastEditorUserId="127" LastEditDate="2015-12-26T16:10:07.643" LastActivityDate="2017-10-01T20:39:57.980" Title="Drawing a cube a million times" Tags="&lt;geometry&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1836" PostTypeId="2" ParentId="1832" CreationDate="2015-12-26T02:28:48.480" Score="2" Body="&lt;p&gt;You could:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Draw them all with different widths and make each transparent (fiddling with alpha blend to make it look nice). Or make the depth proportional to the width, so the widest is always drawn at the bottom of the pyramid. The naive implementation would suffer with many routes.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Not do anything special at intersections, and expect the user to infer what is going on from context.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&quot;PWM&quot; the colors of the lines, one way to do this might be to make a chessboard-like grid texture of 0's and 1's, and depending on whether there is a zero or a one where the road falls, choose the color to draw. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You could use the above technique for multiple line colors by further subdividing the grid with multiple colors. This would be tedious to do in a shader, but is trivial using a normal CPU image manipulation library.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Here is a bus routing app (Transloc Rider) that does this pretty well. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LFHFj.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LFHFj.jpg&quot; alt=&quot;transloc rider&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1988" LastActivityDate="2015-12-26T02:28:48.480" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1837" PostTypeId="2" ParentId="1832" CreationDate="2015-12-26T14:05:08.853" Score="4" Body="&lt;p&gt;This question should most probably be asked on &lt;a href=&quot;https://graphicdesign.stackexchange.com/&quot;&gt;GD.SE&lt;/a&gt; or &lt;a href=&quot;https://ux.stackexchange.com/&quot;&gt;UX.SE&lt;/a&gt;. These sites specialize in how to design the graphics and how to choose the graphics for your purpose. But since you are here basic options are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Routes dont overlap but are parallel like electronic layouts (image 1, A), Works well unless you have many overlapping things.&lt;/li&gt;&#xA;&lt;li&gt;Space interleaved lines, differently colored line regions (image 1, B). Such as dashed lines, however many other interleaved shapes are possible. &lt;/li&gt;&#xA;&lt;li&gt;Spatial solutions, lines on top of each other but laid over in 3d (image 1, C), Works well in isometric drawing.&lt;/li&gt;&#xA;&lt;li&gt;Different line widths (image 1, D)&lt;/li&gt;&#xA;&lt;li&gt;User suggested, overlay (image 1, E).&lt;/li&gt;&#xA;&lt;li&gt;Same color but labels on segments (image 1, F), note not all segments need to be labeled as humans can interpolate values somewhat. This has benefit of being able to be paired with any other effect and works well with selection highlights with info intact. &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8ZfX0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8ZfX0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Different overlay methods.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: None, except the labeling works well when there are very many different lines as humans capability to see different colors in this kind of context as differing data is not very good (ask &lt;a href=&quot;https://ux.stackexchange.com/&quot;&gt;UX.SE&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for what is best depends. None of these are particularity hard to do in code or vector drawing application (but that is out of scope ask &lt;a href=&quot;https://graphicdesign.stackexchange.com/&quot;&gt;GD.SE&lt;/a&gt;). Whichever is best for the user or the design is also not within the scope of this software (ask  &lt;a href=&quot;https://graphicdesign.stackexchange.com/&quot;&gt;GD.SE&lt;/a&gt; or &lt;a href=&quot;https://ux.stackexchange.com/&quot;&gt;UX.SE&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-04-13T12:46:19.383" LastActivityDate="2015-12-26T23:34:56.133" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1839" PostTypeId="1" AcceptedAnswerId="1840" CreationDate="2015-12-27T13:29:16.620" Score="3" ViewCount="698" Body="&lt;p&gt;I'm trying to rotate a rectangle so that it faces another rectangle in a spiral.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Im using the Bullet pyhics library and freeglut for the 3d application, for anyone interested &lt;a href=&quot;https://github.com/damorton/bullet-dominos&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/damorton/bullet-dominos&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/I300x.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/I300x.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float x = 0;&#xA;float z = 0;&#xA;float angle = 0.0f;&#xA;int a = 2, b = 2;&#xA;float previousX = 0.0f;&#xA;float previousZ = 0.0f;&#xA;&#xA;for (int i = 4; i &amp;lt; maxPoints; i++)&#xA;{&#xA;    angle = 0.1 * i;&#xA;    x = (a + b * angle) * cos(angle);&#xA;    z = (a + b * angle) * sin(angle);&#xA;&#xA;    GameObject* temp = CreateGameObject(x, 0, z);&#xA;&#xA;    float newAngle = atan2(previousZ - z, previousX - x) * 180 / PI;&#xA;    temp-&amp;gt;setRotationYaw(newAngle);&#xA;&#xA;    previousX = x;&#xA;    previousZ = z;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can see from the top view that the rectangles are not pointing towards the previous rectangles position. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sk2W2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sk2W2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: After trying the below code&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float x = 0;&#xA;float z = 0;&#xA;float angle = 0.0f;&#xA;int a = 2, b = 2;&#xA;float previousX = 0.0f;&#xA;float previousZ = 0.0f;&#xA;&#xA;for (int i = 0; i &amp;lt; maxPoints; i++)&#xA;{&#xA;    angle = 0.1 * i;&#xA;    x = (a + b * angle) * cos(angle);&#xA;    z = (a + b * angle) * sin(angle);&#xA;&#xA;    GameObject* temp = CreateGameObject(x, 0, z);&#xA;&#xA;    float dirX = -(a + b * angle) * sin(angle) + b * cos(angle);&#xA;    float dirZ = (a + b * angle) * cos(angle) + b * sin(angle);&#xA;    float newAngle = atan2(dirZ, dirX) * 180 / PI;&#xA;    temp-&amp;gt;setRotationYaw(newAngle);&#xA;&#xA;    previousX = x;&#xA;    previousZ = z;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The result is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ypk6t.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ypk6t.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Console output:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LFkYQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LFkYQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: Solution. Some things to note are that the result of &lt;code&gt;atan2()&lt;/code&gt; was not converted to degrees using &lt;code&gt;atan2() * 180 / PI&lt;/code&gt;. Also that I passed in &lt;code&gt;atan2(X, Z)&lt;/code&gt; compared to &lt;code&gt;atan2(Z, X)&lt;/code&gt; that is sometimes done for hysterical raisins &lt;a href=&quot;http://www2.tcl.tk/10814&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www2.tcl.tk/10814&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// create spiral dominos&#xA;float x = 0;&#xA;float z = 0;&#xA;float angle = 0.0f;&#xA;int a = 2, b = 2;&#xA;float previousX = 0.0f;&#xA;float previousZ = 0.0f;&#xA;&#xA;float dominoHeight = 2.0f;&#xA;&#xA;for (int i = 2; i &amp;lt; maxPoints; i++)&#xA;{&#xA;    if (i % 30 == 0) dominoHeight++;&#xA;&#xA;    angle = 0.15 * i;&#xA;    x = (a + b * angle) * cos(angle);&#xA;    z = (a + b * angle) * sin(angle);&#xA;&#xA;    GameObject* temp = CreateGameObject(x, 0, z);&#xA;&#xA;    float dirX = -(a + b * angle) * sin(angle) + (b * cos(angle));&#xA;    float dirZ = (a + b * angle) * cos(angle) + (b * sin(angle));&#xA;    float newAngle = atan2(dirX, dirZ);&#xA;    printf(&quot;dirX: %f - dirZ: %f - angle: %f\n&quot;, dirX, dirZ, newAngle);&#xA;    temp-&amp;gt;setRotationYaw(newAngle);&#xA;&#xA;    previousX = x;&#xA;    previousZ = z;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KmM1S.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KmM1S.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2248" LastEditorUserId="127" LastEditDate="2015-12-29T23:04:42.653" LastActivityDate="2015-12-29T23:04:42.653" Title="Angle between two points in Cartesian coordinate system C++" Tags="&lt;transformations&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1840" PostTypeId="2" ParentId="1839" CreationDate="2015-12-27T14:20:42.503" Score="5" Body="&lt;p&gt;The parametric equation for a spiral is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{eqnarray}&#xA;\begin{aligned}&#xA;    x &amp;amp;= &amp;amp;(a + b \theta) \times \cos(\theta)\\&#xA;    z &amp;amp;= &amp;amp;(a + b \theta) \times \sin(\theta)&#xA;\end{aligned}&#xA;\end{eqnarray}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The direction on the spiral point is simply the derivative of the system with respect to $\theta$. Thus the direction is: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{eqnarray}&#xA;\begin{aligned}&#xA; x_{dir} &amp;amp;=&amp;amp;-(a + b \theta) \times \sin(\theta) + b \times \cos(\theta)\\&#xA; z_{dir} &amp;amp;=&amp;amp;(a + b \theta) \times \cos(\theta) + b \times \sin(\theta)&#xA;\end{aligned}&#xA;\end{eqnarray}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally angle is is simply atan2 of the direction equation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bcKzY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bcKzY.png&quot; alt=&quot;Spiral&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: This is what I get when i plot squares at $(x, z)$ with direction $(x_{dir}, z_{dir})$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematica &lt;a href=&quot;http://pastebin.com/ukNFUiPc&quot; rel=&quot;nofollow noreferrer&quot;&gt;source&lt;/a&gt; for image&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2015-12-27T15:16:17.587" LastActivityDate="2015-12-27T15:16:17.587" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1842" PostTypeId="1" CreationDate="2015-12-27T23:25:14.957" Score="4" ViewCount="197" Body="&lt;p&gt;I'm programming on a Mac and I'm learning OpenGL in the library GLFW. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is that my Mac supports OpenGL up to version 4.1, but when I try to compile the shaders with &lt;code&gt;version 410&lt;/code&gt; it says &lt;code&gt;ERROR: 0:1: '' :  version '410' is not supported&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I set the version that GLFW should use?&lt;/p&gt;&#xA;" OwnerUserId="2355" LastEditorUserId="127" LastEditDate="2015-12-29T23:16:44.810" LastActivityDate="2016-01-29T00:15:32.870" Title="How to set the GLFW OpenGL target?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1843" PostTypeId="2" ParentId="1842" CreationDate="2015-12-28T00:35:18.687" Score="1" Body="&lt;p&gt;I changed the core profile to &lt;code&gt;4.1&lt;/code&gt; by setting the window hints.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);&#xA;glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);&#xA;glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2355" LastActivityDate="2015-12-28T00:35:18.687" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1844" PostTypeId="2" ParentId="1833" CreationDate="2015-12-28T00:38:29.163" Score="5" Body="&lt;p&gt;The effect in the photo is very close to a simple scale-bias per pixel. After a bit of tweaking, I found that applying the transformation: $x' = 0.77x + 38$ to the raw pixel values (as bytes) gives something quite close to your output:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ti9Pv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ti9Pvm.png&quot; alt=&quot;transformed image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case the effect of the scale-bias is to reduce the contrast (scale factor &amp;lt; 1) while keeping the overall brightness about the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example Python code (with numpy and pillow) to do this transformation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;from PIL import Image&#xA;a = np.array(Image.open(&quot;input.png&quot;), dtype=np.float32)&#xA;b = a * 0.77 + 38&#xA;Image.fromarray(np.uint8(np.rint(b))).save(&quot;output.png&quot;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For learning how to implement many basic image processing operations, I've found these &lt;a href=&quot;http://homepages.inf.ed.ac.uk/rbf/HIPR2/wksheets.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Image Processing Operator Worksheets&lt;/a&gt; from the University of Edinburgh helpful.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-28T00:38:29.163" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1845" PostTypeId="1" AcceptedAnswerId="1925" CreationDate="2015-12-28T03:59:31.130" Score="6" ViewCount="731" Body="&lt;p&gt;A friend got an MSI GTX 950 2GD5T graphics card for xmas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I said &quot;yeah, graphics cards are super fast now, that thing probably processes 2 billion triangles per second&quot;. Then I tried to look it up to check if that was even in the right ballpark, but I was unable to find a &quot;triangles per second&quot; stat for that card, and actually for many cards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is &quot;triangles per second&quot; even a meaningful stat? If so, what is the approximate number for this card? (given otherwise average conditions)&lt;/p&gt;&#xA;" OwnerUserId="2358" LastEditorUserId="231" LastEditDate="2016-01-19T13:04:35.450" LastActivityDate="2016-01-23T03:16:54.280" Title="MSI GTX 950 2GD5T triangles per second" Tags="&lt;efficiency&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1846" PostTypeId="1" AcceptedAnswerId="1847" CreationDate="2015-12-28T15:43:36.270" Score="3" ViewCount="802" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KbrW7m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KbrW7m.png&quot; alt=&quot;ray tracing pseudocode&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I don't understand the &lt;code&gt;if (depth &amp;gt; MAX) return Black&lt;/code&gt; part. Does it have something to do with shadows, because in other algorithms they shoot a shadow ray towards the light source to check for shadows but they don't have it here?&lt;/p&gt;&#xA;" OwnerUserId="2359" LastEditorUserId="5778" LastEditDate="2020-07-03T07:35:30.447" LastActivityDate="2020-07-03T07:35:30.447" Title="Ray tracing pseudocode shadow" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="1847" PostTypeId="2" ParentId="1846" CreationDate="2015-12-28T16:30:32.037" Score="7" Body="&lt;p&gt;This is a recursive function (it calls itself). Each time it calls itself it does so with &lt;code&gt;depth + 1&lt;/code&gt; instead of &lt;code&gt;depth&lt;/code&gt;. When it is called with &lt;code&gt;depth &amp;gt; MAX&lt;/code&gt;, it simply returns &lt;code&gt;Black&lt;/code&gt; rather than call itself again. This ensures that the function will eventually stop recursing and return a value. It is the colour equivalent of returning zero.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can visualise this as a light ray reflecting from multiple surfaces successively. Each time the ray reflects from a surface the same function is used to calculate the colour of the light in that direction. If you set &lt;code&gt;MAX&lt;/code&gt; to 0, there will be no reflections in your resulting image. If you set &lt;code&gt;MAX&lt;/code&gt; to 2, there will be reflections of reflections which will look more realistic, but take longer to calculate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intuitively, MAX is the number of surfaces the ray will bounce off before it is decided what colour should be displayed.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2015-12-28T16:36:12.337" LastActivityDate="2015-12-28T16:36:12.337" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1848" PostTypeId="1" AcceptedAnswerId="1849" CreationDate="2015-12-28T20:04:35.557" Score="6" ViewCount="572" Body="&lt;p&gt;I am not looking for textbooks and related how-tos, though I'm sure they can color the answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to understand how we handle the rendering of caustic effects — and particularly time-saving models, as different from physical simulation.&lt;/p&gt;&#xA;" OwnerUserId="2360" LastEditorUserId="2360" LastEditDate="2015-12-29T20:08:54.957" LastActivityDate="2015-12-29T20:08:54.957" Title="What is the basis of rendering light caustics?" Tags="&lt;lighting&gt;&lt;photo-realistic&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1849" PostTypeId="2" ParentId="1848" CreationDate="2015-12-28T22:57:25.847" Score="5" Body="&lt;p&gt;For offline rendering, caustics and dispersion effects (different colors of light separating, as in a prism) are usually calculated using some form of &lt;a href=&quot;https://en.wikipedia.org/wiki/Photon_mapping&quot;&gt;photon mapping&lt;/a&gt;. That's a fairly expensive technique, even by the standards of offline rendering, and it falls more under the &quot;physical simulation&quot; side of things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're looking for more approximate techniques suitable for real-time rendering, &lt;a href=&quot;http://cwyman.appspot.com/papers.html&quot;&gt;Chris Wyman's papers&lt;/a&gt; are a good place to look. He wrote several papers on caustics between 2006 and 2009. The one to start with is &lt;a href=&quot;http://cwyman.appspot.com/papers/i3d06_imgSpaceCaustics.pdf&quot;&gt;Interactive Image-Space Techniques for Approximating Caustics&lt;/a&gt; (I3D 2006), #25 on that page. This paper re-uses a GPU refraction rendering technique he developed earlier, #28 on that page, so you'll want to look at that as well for background. Later papers build on these two.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic idea of these papers is to use GPU rasterization to perform a limited, approximate analogue of photon mapping. The scene is rendered from the light's point of view, similar to a shadow map, and each pixel is treated as a photon; its refraction through transparent objects is calculated approximately (usually considering only 1 or 2 layers of refraction), and its final location is stored in a texture. Then, one can render each photon as a small splat into a &quot;caustic map&quot;, which finally gets projected onto the scene, similar to a shadow map.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-28T22:57:25.847" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1850" PostTypeId="1" AcceptedAnswerId="1852" CreationDate="2015-12-29T03:12:26.573" Score="6" ViewCount="147" Body="&lt;p&gt;I have a game that has simple particles (basically dots) moving around the screen leaving a trail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My ultimate goal&lt;/strong&gt; is to be able to change the opacity of the solid black fading texture each drawing call in a way so that I can keep the length of a particle with trails (using a accumulation buffer) is the same even though the particle movement might move with time-stepping.  The way I render my particles is I render the current frame based on the particles position, lets call this texture A.  Then I take the previous frame and draw a solid black texture over it with set opacity in order to fade this, lets call this texture B.  Then I draw texture A over texture B.  This way the particle leaves a trail based on where it has been.  I am currently time-stepping the movement of the particles so that no-mater how much latency their is it always moves the same speed (considering real-world time).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In essence I want to be able to say say that the particle trial will always be 100 pixels (considering the particle moves 60 pixels in a second) , and have it be that way even if the frame-rate drops.  Currently when the frame rate drops the accumulation buffer gets run less times and thus the trail is longer the more latency their is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The information I need to know to do this&lt;/strong&gt; is how exactly does fading work. Because I need to change the opacity of the black texture in a way that allows it to fade more when the accumulation buffer is called less times per second, and fade less when it is called many times per second.  Right now I really dont understand what happens to a pixel when a black texture with a specific opacity is on it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is some data I collected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Data 1:&lt;/em&gt;&#xA;This is a chart of the particle trails.  The x axis represents the FPS it was running at, and the y axis is how many pixels long the trail was.  On the left it says what opacity the black texture used in the accumulation buffer was.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/iGLTQ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iGLTQ.png&quot; alt=&quot;Graph&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://www.desmos.com/calculator/lbrpdkrpjo&quot; rel=&quot;noreferrer&quot;&gt;You can find all the data, and some best fit line formulas at here (on desmos)&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is important to note I stopped counting after V was lower then 20 since the difference between colors starts getting really small.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;some things I noticed about this is that their seems to be either a exponential or division relationship between the numbers.  Also I noticed that their were segments for each frame before it was faded, and that the amount of them that were visible were about the same no-mater the fps when considering the same opacity of the black texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Data 2:&lt;/em&gt;&#xA;I recreated what I thought was going on with a fading texture with paint.net.  I made a 100x100 picture and colored it red. I then added a layer with one black pixel at an opacity of 25/255 then I duplicated this and added another pixel, basically I created a gradient.  Then I went through and labeled each pixel considering its rounded darkness (in hsv color space).  Then labeled the difference between the darkness values.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/y4YqY.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/y4YqY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HZ89o.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HZ89o.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Unfortunately from this I didnt learn much.  Just reaffirmed that it is a non linear relationship. And I also noticed if I did the fade one more time that all the darkness values shifted to the square next to them.  So I could predict the darkness values if I knew how many times the fade had been applied.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;So&lt;/strong&gt; what happens when a semitransparent black texture is blended over another one?&lt;/li&gt;&#xA;&lt;li&gt;If you are willing to put in some extra thought what would a formula&#xA;be that would give me the opacity the black texture needs to be in&#xA;order to make the particle trail be about 'N' pixels long, given the&#xA;dt since last frame?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2015-12-29T06:39:30.607" LastActivityDate="2015-12-29T06:39:30.607" Title="Please help me understand what happens as an image is faded to black in order to time-step particle fading" Tags="&lt;opengl&gt;&lt;transparency&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1852" PostTypeId="2" ParentId="1850" CreationDate="2015-12-29T06:35:14.433" Score="6" Body="&lt;p&gt;The basic equation for alpha blending is as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ c_\text{final} = c_\text{source} \cdot \alpha + c_\text{dest} \cdot (1 - \alpha) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here, $c_\text{source}$ is the color of the thing being blended, $c_\text{dest}$ is the background onto which you're blending it, and $\alpha$ is between 0 and 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case, $c_\text{source} = 0$ (black fading texture), so blending black $n$ times over a background reduces to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ c_\text{final} = c_\text{dest} \cdot (1 - \alpha)^n $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is indeed an exponential falloff as you guessed. You can plug this formula in and get numbers pretty similar to those you posted (although when I did it, my results were off by one or two—maybe due to rounding differences; I'm not sure).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding your problem of making the trails appear the same regardless of framerate, a simple approach is to run the accumulation buffer passes multiple times per frame if necessary, so that there's effectively a fixed timestep for the trail regardless of framerate. That will probably give better-looking results than attempting to fiddle with the alpha based on the framerate. It might be too slow, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A potentially more efficient approach would be to have the particles spawn a new &quot;trail particle&quot; every so often, where each trail particle stays fixed in position, with its alpha going from 100% to 0 over some length of time (and then it gets recycled). You have to re-render all the particles every frame, but it could end up being faster overall if the overhead of the full-screen blending passes for the accumulation buffer get to be too high.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I should point out though that all of these approaches actually perform &lt;em&gt;time-based&lt;/em&gt; fading, not distance-based as you asked for (100-pixel trails). If all the particles move at the same speed, you can just tweak the fade time to make the trails the desired length, but if different particles move at different speeds, then you would need to account for that when setting the fade times for their trails. There's also no trivial way to do that with the accumulation buffer approach, since it implicitly uses the same fade time for everything on the screen.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2015-12-29T06:35:14.433" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1854" PostTypeId="1" CreationDate="2015-12-29T20:24:41.790" Score="9" ViewCount="1126" Body="&lt;p&gt;Is all &lt;a href=&quot;https://en.wikipedia.org/wiki/Spectral_rendering&quot;&gt;spectral rendering&lt;/a&gt; handled as simulation?  Are there technique more tailored to 'consumer' rendering, such as for real-time or even just 'realistic looking without solving full physical equations'?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to understand how we handle the rendering of spectral effects.  It seems like a photon needs to be described as a range of wavelengths, and incidence with a surface either &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;replaces the original, and resolves multiple new photons across the spectral function, each with their own new vector &lt;/li&gt;&#xA;&lt;li&gt;maintains the original (or marginally modified) photon, given a threshold&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I would prefer to be pointed in the direction of existing work, but appreciate any &lt;em&gt;coloring&lt;/em&gt; of this topic.&lt;/p&gt;&#xA;" OwnerUserId="2360" LastActivityDate="2016-01-06T20:48:37.160" Title="How is spectral rendering handled?" Tags="&lt;lighting&gt;&lt;photo-realistic&gt;&lt;color-science&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1857" PostTypeId="1" AcceptedAnswerId="1863" CreationDate="2016-01-01T00:05:16.793" Score="5" ViewCount="217" Body="&lt;p&gt;I'm trying to find the angle it would take for me to rotate a polygon so that a specific side is completely horizontal and on the bottom.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, a shape like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/duCe7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/duCe7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Needs to be rotated so the side with the red square on it is on the bottom and completely horizontal, like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/210Ot.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/210Ot.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've tried several approaches but all end up having strange edge cases where the angle is incorrect.&lt;/p&gt;&#xA;" OwnerUserId="2381" LastEditorUserId="231" LastEditDate="2016-01-19T13:04:21.223" LastActivityDate="2016-01-19T13:04:21.223" Title="Finding the angle of any side of a polygon" Tags="&lt;transformations&gt;&lt;vector-graphics&gt;&lt;polygon&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1859" PostTypeId="2" ParentId="1857" CreationDate="2016-01-01T08:31:35.117" Score="2" Body="&lt;p&gt;This algorithm is based on &lt;a href=&quot;https://stackoverflow.com/questions/2827393/angles-between-two-n-dimensional-vectors-in-python&quot;&gt;this answer for finding the angle between vectors&lt;/a&gt;, and &lt;a href=&quot;https://stackoverflow.com/questions/20023209/python-function-for-rotating-2d-objects&quot;&gt;this answer for rotating polygon points&lt;/a&gt;. It's written in Python, and assumes you want to align an edge with the X axis (horizontal axis). If you want to align it with the Y axis, replace the &lt;code&gt;xVec&lt;/code&gt; in the code below with a &lt;code&gt;yVec = [0,1]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDITED&lt;/strong&gt;: Added code for rotating the polygon and displaying the original and rotated polygons. Result of this script is displayed in the image below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oeSfK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oeSfK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;from PIL import Image, ImageDraw&#xA;from matplotlib import pyplot as plt&#xA;from math import radians, degrees, sqrt, acos, cos, sin&#xA;&#xA;def dotproduct(v1, v2):&#xA;  return sum( (a*b) for a, b in zip(v1, v2) )&#xA;&#xA;def length(v):&#xA;  return sqrt( dotproduct(v, v) )&#xA;&#xA;def angle(v1, v2):&#xA;  return acos( dotproduct(v1, v2) / ( length(v1) * length(v2) ) )&#xA;&#xA;def vec_subtraction( v1, v2 ):&#xA;    return [ e1 - e2 for e1, e2 in zip( v1, v2 ) ]&#xA;&#xA;def calc_edge_vec( poly, edge ):&#xA;    p1 = poly['points'][ edge[0] ]&#xA;    p2 = poly['points'][ edge[1] ]&#xA;&#xA;    return vec_subtraction( p2, p1 )&#xA;&#xA;def rotatePolygon( poly, theta ):&#xA;    ''' Rotates the given polygon which consists of corners represented&#xA;        as (x,y), around the ORIGIN, clock-wise, theta degrees&#xA;    '''&#xA;&#xA;    rotatedPolygon = []&#xA;    for corner in poly:&#xA;        rotatedPolygon.append((&#xA;            corner[0] * cos( theta ) - corner[1] * sin( theta ), # x&#xA;            corner[0] * sin( theta ) + corner[1] * cos( theta )  # y&#xA;        ))&#xA;&#xA;    # Make sure rotated polygon coordinates are within image boundaries&#xA;    minX = min( [ c[0] for c in rotatedPolygon ] ) * -1&#xA;    minX = minX if minX &amp;gt; 0 else 0&#xA;    minY = min( [ c[1] for c in rotatedPolygon ] ) * -1&#xA;    minY = minY if minY &amp;gt; 0 else 0&#xA;&#xA;    rotatedPolygon = [ ( x + minX, y + minY ) for x, y in rotatedPolygon ]&#xA;&#xA;    return rotatedPolygon&#xA;&#xA;def draw_and_plot_polygon( im, poly, color, plotTitle, plotIndex ):&#xA;    draw = ImageDraw.Draw( im )&#xA;&#xA;    for e in poly['edges']:&#xA;        p1 = tuple( poly['points'][ e[0] ] )&#xA;        p2 = tuple( poly['points'][ e[1] ] )&#xA;        draw.line( [p1, p2], fill = color )&#xA;&#xA;    del draw&#xA;&#xA;    plt.subplot( 3, 2, plotIndex ),&#xA;    plt.imshow( im ),&#xA;    plt.title( plotTitle ),&#xA;    plt.xticks([]), plt.yticks([])&#xA;&#xA;    # Draw point names (ABCD)&#xA;    for i, c in enumerate( poly['points'] ):&#xA;        plt.text( c[0], c[1], &quot;ABCD&quot;[i], color = 'white' )&#xA;&#xA;# Define polygon as dictionary of point coordinates and edges&#xA;# each edge is a pair of point indices&#xA;p = {&#xA;    'points' : [ (50,10), (95,30), (80,20), (62,48) ],&#xA;    'edges'  : [ (3,0), (3,1), (1,2), (2,0) ]&#xA;}&#xA;&#xA;xVec = [1,0] # Horizontal axis&#xA;&#xA;# Draw original poly in white&#xA;im = Image.new( 'RGB', (100,100) )&#xA;draw_and_plot_polygon( im, p, (255,255,255), 'Original', 1 )&#xA;&#xA;colors = [ (50,50,255), (255,0,0), (0,255,0), (200, 150, 50) ]&#xA;&#xA;i = 2&#xA;for e, color in zip( p['edges'], colors ):&#xA;    edgeVec = calc_edge_vec( p, e )&#xA;    a       = angle( edgeVec, xVec )&#xA;&#xA;    rotPol = p.copy()&#xA;    rotPol['points'] = rotatePolygon( p['points'], a )&#xA;&#xA;    im = Image.new( 'RGB', (100,100) )&#xA;&#xA;    # Place aligned edge at bottom&#xA;    alingedEdgeY = im.size[1] - rotPol['points'][ e[0] ][ 1 ] # Current edge height&#xA;    rotPol['points'] = [ ( p[0], p[1] + alingedEdgeY ) for p in rotPol['points'] ]&#xA;&#xA;    # Draw rotated polygon&#xA;    angleTitle = &quot;Angle: &quot; + str( round( degrees(a), 2 ) )&#xA;    draw_and_plot_polygon( im, rotPol, color, angleTitle, i )&#xA;&#xA;    i += 1&#xA;&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDITED 2&lt;/strong&gt;: Added some code to position the rotated polygon so that the aligned edge is on the floor (lines 90-91). Here's the result:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SRPg3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SRPg3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2317" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-01-03T05:34:40.750" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1860" PostTypeId="1" CreationDate="2016-01-02T08:46:03.247" Score="6" ViewCount="128" Body="&lt;p&gt;I am currently trying to implement &lt;a href=&quot;http://www.crytek.com/download/Light_Propagation_Volumes.pdf&quot;&gt;light propagation volumes&lt;/a&gt; in DirectX 11 and I have already done the RSM part which contains position, normal, depth and flux map generation. But for Injecting Virtual point lights into light propagation volumes, we have to inject lights into an x,y,z grid for which each element consists of 3 vectors for each of red, green and blue channels and each vector consists of four coefficients of a two-band spherical harmonic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do this, here are my steps:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Prepare 3 texture arrays. Each slice is a slice of the grid.&lt;/li&gt;&#xA;&lt;li&gt;Inject RSM into the texture array by calculating grid space position.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Can someone briefly explain how this injection can be done and how each virtual point light can be used inside each grid unit?&lt;/p&gt;&#xA;" OwnerUserId="1571" LastEditorUserId="231" LastEditDate="2016-01-02T23:38:25.120" LastActivityDate="2016-01-02T23:38:25.120" Title="Injecting Virtual point lights into 3D Grid" Tags="&lt;lighting&gt;&lt;directx11&gt;&lt;hlsl&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1861" PostTypeId="1" CreationDate="2016-01-02T13:46:45.817" Score="2" ViewCount="261" Body="&lt;p&gt;I am wondering how professional light visualizer software (like Capture Argo - WYSIWYG - Realizzer - LightConverse) project the lights on the objects (like stage, floor, people), even projecting the various &lt;a href=&quot;https://en.wikipedia.org/wiki/Gobo_%28lighting%29&quot; rel=&quot;nofollow&quot; title=&quot;a physical stencil or template slotted inside, or placed in front of, a lighting source, used to control the shape of emitted light.&quot;&gt;gobos&lt;/a&gt; (shapes).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some screenshots:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.diversitronics.de/tl_files/Bilder/Produkte/Capture/renderings/capture1.jpg&quot; rel=&quot;nofollow&quot;&gt;http://www.diversitronics.de/tl_files/Bilder/Produkte/Capture/renderings/capture1.jpg&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.selightingdesign.co.uk/images/portfolio/capture%20hairspray/production%20photos/fullscreen/01.jpg&quot; rel=&quot;nofollow&quot;&gt;http://www.selightingdesign.co.uk/images/portfolio/capture%20hairspray/production%20photos/fullscreen/01.jpg&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do they calculate the various intersections, and project beams for so many light sources in an efficient way? What's the simplest way?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume they are projecting a texture but how?&lt;/p&gt;&#xA;" OwnerUserId="2388" LastEditorUserId="231" LastEditDate="2016-01-02T23:24:23.343" LastActivityDate="2016-01-02T23:24:23.343" Title="Projecting light shapes" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;texture&gt;&lt;performance&gt;&lt;real-time&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1862" PostTypeId="1" CreationDate="2016-01-02T22:38:07.437" Score="8" ViewCount="1805" Body="&lt;p&gt;Without there being black bars I mean. 1080 isn't any multiple of 768 so is there some sort of data loss?&lt;/p&gt;&#xA;" OwnerUserId="2393" LastActivityDate="2016-05-06T01:23:24.967" Title="How does a computer upscale 1024x768 resolution to 1920x1080?" Tags="&lt;pixel-graphics&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1863" PostTypeId="2" ParentId="1857" CreationDate="2016-01-03T18:02:07.997" Score="3" Body="&lt;p&gt;Deducing the angle and rotating by that angle works quite well in 2D (describe in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1859/38&quot;&gt;TLousky's post&lt;/a&gt;). This strategy, does not extend very well into three-dimensional realm. I will provide an alternative solution that shows a general strategy that works in a larger set of cases. As a bonus this without needing to think of trigonometry as it can be encoded away.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;First identify the vector that you want to be transformed to orientation in your reference space. Let us call this vector $\vec{a}$, or a along vector.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Next you will need to identify a vector that is perpendicular to this vector. Let us call this vector $\vec{b}$, it is sometimes also called a up vector. In three-dimensions you need 3 vectors but once you identify 2 you can compute the third.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finding out the $\vec{b}$ in 2-D realm is especially easy you could just rotate the vector by $90^{\circ}$ or simply swap the coordinates and make the x coordinate negative (see 1). Alternatively you can use the same procedure as in 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\vec{b} = rotate(90^{\circ})\cdot\vec{a} =&#xA;      \begin{bmatrix} &#xA;         \cos(\pi/2) &amp;amp; -\sin(\pi/2) \\ &#xA;         \sin(\pi/2) &amp;amp; \cos(\pi/2) &#xA;      \end{bmatrix}&#xA;      \begin{bmatrix} &#xA;         x \\ &#xA;         y &#xA;      \end{bmatrix}&#xA;         =       &#xA;      \begin{bmatrix} &#xA;         -y \\ &#xA;         x &#xA;      \end{bmatrix} &#xA;     \tag{1}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 3-D this usually requires a trick. Since each triangle is flat, one can use this to ones advantage. This gives us a perpendicular direction, now we still need a third one and we can get it by cross product of the 2 known vectors. You now have 3 vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BcxhU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BcxhU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Vector $\vec{a}$ and derived $\vec{b}$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Normalize the vectors&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Use these vectors to produce a a rotation matrix (or a affine matrix wich allows you to specify point to be at zero, your choice). This matrix represents the local coordinate of the rotated object. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;All you now need is to invert this matrix and point matrix multiply your polygon corner vectors for a aligned version of the polygon.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;What is especially nifty is the sidestepping of trigonometrical operations. Now i see no point i defining basic matrix operations but i see value in code. So i will use numpy.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;import numpy as np, pylab&#xA;&#xA;pts = np.array([&#xA;        [0.,0.],[10.,1.],[12.,12.],[-2.,11.],[0.,0.]&#xA;      ]).transpose()&#xA;&#xA;f = pylab.figure(facecolor=&quot;1.&quot;)     &#xA;pylab.axis('off')&#xA;pylab.axis('equal')&#xA;pylab.plot(pts[0], pts[1])  &#xA;&#xA;# 1. Get the vector&#xA;vec_a = np.copy(pts[:,2]) - np.copy(pts[:,1])&#xA;&#xA;# 2. up vector&#xA;vec_b = np.copy(vec_a[::-1])&#xA;vec_b[0] *= -1&#xA;&#xA;# 3. normalize&#xA;vec_a /= np.linalg.norm(vec_a)&#xA;vec_b /= np.linalg.norm(vec_b)&#xA;&#xA;# 4. build rotation matrix&#xA;mtx_R = np.concatenate(([vec_a], [vec_b])).transpose()&#xA;mtx_R = np.linalg.inv(mtx_R)&#xA;&#xA;# 5. transform, or set hierarchy transform&#xA;pts2 = np.copy(pts)&#xA;for i in range(len(pts2[0])):&#xA;    pts2[:,i] =  np.dot(mtx_R, pts2[:,i])&#xA;&#xA;pylab.plot(pts2[0],pts2[1])&#xA;pylab.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I admit it cold be have slightly shorter by refactoring the code and eliminate redundant manipulations but its a demo only so... &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xkgLB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xkgLB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Polygon, in blue axis fixed in green.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Same method works well for straightening, skew and other problems such as perspective correction. You can extend this to affine matrices that way you can encode the translation into the calculation with just 1 more lines. In essence you specify what point is at origin and with 2 more operations one could define around what to rotate. Now it just just rotates about the origin.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-01-04T12:03:57.130" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1865" PostTypeId="2" ParentId="1854" CreationDate="2016-01-05T01:14:34.330" Score="1" Body="&lt;p&gt;One hacky method I've seen in real time raytracers / ray marching is to cast a ray per color channel (rgb) and do things Iike have different refraction indices per color channel.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-01-05T01:14:34.330" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1866" PostTypeId="1" AcceptedAnswerId="1867" CreationDate="2016-01-05T15:53:46.143" Score="13" ViewCount="8753" Body="&lt;p&gt;I want to find the texture coordinates for point P. I have the vertices of the triangle and their corresponding uv coordinates. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The numbers in the little squares in the texture represent color values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the steps of computing the uv coordinates of P?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cVDiT.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cVDiT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2214" LastActivityDate="2016-01-06T13:48:06.523" Title="How to map square texture to triangle?" Tags="&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1867" PostTypeId="2" ParentId="1866" CreationDate="2016-01-05T17:45:59.417" Score="14" Body="&lt;p&gt;This is achieved via &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Barycentric_coordinate_system&quot; rel=&quot;noreferrer&quot;&gt;Barycentric&lt;/a&gt; Interpolation&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, we find the barycentric coordinates of $P$. Barycentric coordinates represent how much weight each vertex contributes to the point, and can be used to interpolate any value which is known at the vertices across the face of a triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the 3 inner triangles $ABP$, $PBC$ and $PCA$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ob83U.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ob83U.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can say that the barycentric coordinate, or weight of the vertex $A$ on the point $P$ is proportional to the ratio of the area of inner triangle $PBC$ to the area of the whole triangle $ABC$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is intuitively evident if we consider that as $P$ approaches $A$ the triangle $PBC$ grows larger and the other two become smaller. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also intuitively evident should be that the sum of the barycentric coordinates of a point &lt;strong&gt;inside a triangle&lt;/strong&gt; always equals $1$. So, it is enough to find only two of the coordinates to derive the 3rd.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The method for computing the barycentric coordinates is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{aligned}&#xA;{Bary}_A &amp;amp;= \frac{(B_y-C_y)(P_x-C_x) + (C_x-B_x)(P_y-C_y)}{(B_y-C_y)(A_x-C_x) + (C_x-B_x)(A_y-C_y)}\\&#xA;{Bary}_B &amp;amp;= \frac{(C_y-A_y)(P_x-C_x) + (A_x-C_x)(P_y-C_y)}{(B_y-C_y)(A_x-C_x) + (C_x-B_x)(A_y-C_y)}\\&#xA;{Bary}_C &amp;amp;= 1 - {Bary}_A - {Bary}_B&#xA;\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The derivation and reasoning is explained in the &lt;a href=&quot;https://en.wikipedia.org/wiki/Barycentric_coordinate_system&quot; rel=&quot;noreferrer&quot;&gt;wikipedia article&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have coordinates, you can determine the texture coordinates of $P$ by interpolating the values at the vertices using the barycentric coordinates as weights:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;$$P_{uv} = {Bary}_A \cdot A_{uv} + {Bary}_B \cdot B_{uv} + {Bary}_C \cdot C_{uv}$$&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The reasoning is also explained very nicely in &lt;a href=&quot;https://classes.soe.ucsc.edu/cmps160/Fall10/resources/barycentricInterpolation.pdf&quot; rel=&quot;noreferrer&quot;&gt;this&lt;/a&gt; presentation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also see &lt;a href=&quot;https://gamedev.stackexchange.com/questions/23743/whats-the-most-efficient-way-to-find-barycentric-coordinates&quot;&gt;this question&lt;/a&gt; for efficient methods of computation.&lt;/p&gt;&#xA;" OwnerUserId="457" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2016-01-06T13:48:06.523" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1869" PostTypeId="2" ParentId="1862" CreationDate="2016-01-06T07:59:53.697" Score="5" Body="&lt;p&gt;There are numerous upscaling and downscaling algorithms available to scale images from any resolution to any other arbitrary resolution. Each algorithm typically involves a trade-off between efficiency, smoothness and sharpness, with varying degrees of each trade-off for different algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check out &lt;a href=&quot;https://en.wikipedia.org/wiki/Image_scaling#Scaling_methods&quot; rel=&quot;nofollow&quot;&gt;this Wikipedia article&lt;/a&gt; for such algorithms and examples of such algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most popularly known (and used) algorithm is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bicubic_interpolation&quot; rel=&quot;nofollow&quot;&gt;Bicubic interpolation&lt;/a&gt; algorithm. It interpolates between 2D points on a rectangular grid. Using &lt;a href=&quot;https://en.wikipedia.org/wiki/Cubic_Hermite_spline&quot; rel=&quot;nofollow&quot;&gt;Cubic Splines&lt;/a&gt; (or Cubic Interpolation), It first interpolates on one dimension (finds the interpolated row/column), then interpolates the interpolated row/column in the other dimension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bilinear interpolation is similar to Bicubic interpolation, except the former interpolates using a linear function and can interpolate only between two values and the latter uses a cubic function and can interpolate between four values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simple function for Bicubic interpolation is as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f(f(p00, p01, p02, p03, y),&#xA;  f(p10, p11, p12, p13, y),&#xA;  f(p20, p21, p22, p23, y),&#xA;  f(p30, p31, p32, p33, y),&#xA;  x)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where (x, y) is the interpolated position and p[][] is the 2d array representing the 4 * 4 grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check &lt;a href=&quot;http://www.paulinternet.nl/?page=bicubic&quot; rel=&quot;nofollow&quot;&gt;this link&lt;/a&gt; for more information and example code, which really helps a lot!&lt;/p&gt;&#xA;" OwnerUserId="1683" LastEditorUserId="174" LastEditDate="2016-05-03T16:13:54.833" LastActivityDate="2016-05-03T16:13:54.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1870" PostTypeId="2" ParentId="1862" CreationDate="2016-01-06T18:56:31.283" Score="8" Body="&lt;p&gt;In essence a image is  a group of point samples (read &lt;a href=&quot;http://alvyray.com/Memos/CG/Microsoft/6_pixel.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;A pixel is not a little square&lt;sup&gt;3&lt;/sup&gt;&lt;/a&gt;). When you transform or scale the image you need to resample it. So what you do, theoretically, is take the point samples and convert them into a continuous function. Then you sample that continuous function and reconstruct a signal. So, there are two or three different phases here.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Converting the samples to a continuous function, (function reconstruction).&lt;/li&gt;&#xA;&lt;li&gt;(Transforming)&lt;/li&gt;&#xA;&lt;li&gt;Re-sampling the signal&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Note that none of these steps have a fixed form. In practice, when optimized, it's impossible to tell that there are steps. The transformation does not really have to be simple it could be mapping the shape into a spiral etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WWaeC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WWaeC.png&quot; alt=&quot;Reconstruction of signal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: A 1-D signal reconstructed by different filters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice, quite a bit of lore is known about signal reconstruction in the signal processing field. Designing these filters and choosing the right one is a art form on its own. But, in essence, the choice of filter is a tradeoff between blurring and &lt;a href=&quot;https://en.wikipedia.org/wiki/Ringing_artifacts&quot; rel=&quot;nofollow noreferrer&quot;&gt;ringing&lt;/a&gt;. Of course the algorithm also has other qualities such as how many instructions it takes to implement and how fast and how much memory it needs etc. Which can be very important in realtime or embedded applications.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XNqUx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XNqUx.png&quot; alt=&quot;The process&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Overview of entire process.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="310" LastEditDate="2016-05-05T14:56:32.470" LastActivityDate="2016-05-05T14:56:32.470" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1871" PostTypeId="2" ParentId="1854" CreationDate="2016-01-06T20:48:37.160" Score="2" Body="&lt;p&gt;The most common way I saw is to have photons of several different wavelengths. One then renders with each wavelength and blends the results into the final image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Existing work&quot;: &lt;a href=&quot;http://psychopath.io/spectral-rendering/&quot; rel=&quot;nofollow&quot;&gt;Psychopath Renderer&lt;/a&gt; and &lt;a href=&quot;http://benedikt-bitterli.me/tantalum/&quot; rel=&quot;nofollow&quot;&gt;The Secret Life of Photons&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2016-01-06T20:48:37.160" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1872" PostTypeId="2" ParentId="1824" CreationDate="2016-01-06T21:44:45.993" Score="5" Body="&lt;p&gt;And just to add: it is called &quot;conflation&quot; artifact and this is what AntiGrain Geometry used the &lt;a href=&quot;http://agg.sourceforge.net/antigrain.com/news/release_notes/v24.agdoc.html#toc0007&quot; rel=&quot;noreferrer&quot;&gt;compound shapes&lt;/a&gt; rasterizer for, see:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://agg.sourceforge.net/antigrain.com/demo/flash_rasterizer.png&quot; rel=&quot;noreferrer&quot;&gt;flash_rasterizer.png http://agg.sourceforge.net/antigrain.com/demo/flash_rasterizer.png&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, this is what NV Path Rendering claims to improve on:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://developer.download.nvidia.com/assets/gamedev/files/An_Introduction_to_NV_path_rendering.pdf&quot; rel=&quot;noreferrer&quot;&gt;An Introduction to&#xA;NV_path_rendering&lt;/a&gt; (p. 67) or &lt;a href=&quot;http://developer.download.nvidia.com/assets/gamedev/files/NV_path_rendering_FAQ.pdf&quot; rel=&quot;noreferrer&quot;&gt;NV_path_rendering FAQ&lt;/a&gt; (#29).&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2016-01-06T21:44:45.993" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1873" PostTypeId="1" AcceptedAnswerId="1875" CreationDate="2016-01-07T07:42:51.627" Score="9" ViewCount="855" Body="&lt;p&gt;I am taking a Computer Graphics course this quarter.&#xA;One of our lab project is about software rasterization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I am planing the project proposal and&#xA;thinking about how to make it useful for other people in contemporary game development.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some brief search,&#xA;I learned a technique called Software Occlusion Culling.&#xA;It does software rasterization on buffers of various resolutions.&#xA;And we can query for occlusion using the hierarchical z buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My question&lt;/strong&gt;: What are the usages of software rasterization&#xA;in &lt;em&gt;modern&lt;/em&gt; game engines besides the Software Occlusion Culling?&lt;/p&gt;&#xA;" OwnerUserId="120" LastActivityDate="2016-01-10T01:38:35.283" Title="What are the usages of software rasterization in modern game engines?" Tags="&lt;rendering&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1874" PostTypeId="2" ParentId="1873" CreationDate="2016-01-07T12:26:55.137" Score="-2" Body="&lt;p&gt;Rasterization is a huge topic with many parts and I'm no engine programmer, but I'll do my best to give some sort of overview (this will be far from a complete list!). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some very basic, lowlevel stuff include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Frustrum culling:&lt;/strong&gt; throws away everything outside the camera's frustrum (think of it as the viewing area of the camera).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Backface culling:&lt;/strong&gt; throw away every polygon not directing to the camera.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Painter's algorithm:&lt;/strong&gt; draw objects in order of their distance to the camera, start with objects far away, then go toward to the camera.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;More advaned stuff used in games include things like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Tesselation&lt;/strong&gt;: actually pretty much like LOD (see below), but now the latest DirectX Versions introduced tesselation, which provides automatic mesh division or reduction. This gives huge boost in graphics performance, because you can get polys if you need them and get rid of them if you don't want them any more. &lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;LOD&lt;/strong&gt;: A level-of-detail system replaces the mesh of an object based on the distance between object and camera. for example, your character has three meshes: one with 10,000, one whith 5,000 and another with 1,000 polys. if you stay right in front of him, the high resolution mesh (10,000 polys) is shown, if you move away, after 100m the character is replaced by the medium mesh and after another 100m it is replaced by the low resolution mesh. Instead of replacing the mesh you can reduce it, but this would be more complex to code. &lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;binary space partitions&lt;/strong&gt;: the space is divided into two volumes. this will be repeated until you reach your goal, e.g. until the space does contain only polys that should be drawn on screen&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Portals and cells&lt;/strong&gt;: (aka Portal culling) is used in indoor scenes and/or first person shooters. The scene is divided into cells (e.g. rooms of a building) that are connected throw portals (e.g. doors). you can set portals to be open and closed.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Assuming you have a basic understanding of the graphics pipeline, I tried to focus on rasterization. you may also take a look at lighting and shading or other stuff..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These include just a few possible technologies to include into your project. since i have not enough reputation on stackexchange, I cannot provide many links, but you'll find all that stuff in google :)&lt;/p&gt;&#xA;" OwnerUserId="2417" LastActivityDate="2016-01-07T12:26:55.137" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1875" PostTypeId="2" ParentId="1873" CreationDate="2016-01-07T13:09:28.180" Score="4" Body="&lt;p&gt;To my knowledge, &lt;a href=&quot;https://software.intel.com/en-us/articles/software-occlusion-culling&quot; rel=&quot;noreferrer&quot;&gt;Software Occlusion Culling&lt;/a&gt; (which you already mentioned), is pretty much the only thing a software rasterizer would still be used for. &lt;a href=&quot;http://procworld.blogspot.fr/2015/08/voxel-occlusion.html&quot; rel=&quot;noreferrer&quot;&gt;Procworld&lt;/a&gt; makes use of a similar technique to display its huge voxel environments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most other culling methods like frustum culling do work on the CPU, but, to stick with the example, the test against the frustum happens on object level, probably with an axis-aligned bounding box (AABB). This intersection test is way simpler than using a full-blown software rasterizer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In certain cases, software rasterization could be used for mouse picking of objects. In game engines, this is often solved using a physics engine and ray-triangle collision with a simplified mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With the CPU being idle while waiting for the GPU in modern interactive 3D applications, one could think that it might be beneficial to use these idle cycles to render on the CPU using a software rasterizer. The problem here, besides the rendering getting horribly complex and convoluted, will often be the bandwidth. Images rendered on the CPU need to be transferred to the GPU before getting displayed, which might cancel out the benefit.&lt;/p&gt;&#xA;" OwnerUserId="385" LastActivityDate="2016-01-07T13:09:28.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1876" PostTypeId="2" ParentId="1873" CreationDate="2016-01-07T13:49:57.700" Score="0" Body="&lt;p&gt;Games with the concept of &quot;fog of war&quot; often have a visibility grid to define the state of the fog of war at each location.  Rasterization is sometimes used to modify the fog of war state for specific shapes on the grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, using an ability that reveals a circle of the map with a specific radius, or perhaps something that reveals a square.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not strictly graphics related, but definitely a use of rasterization in modern games, and a technique ive seen used in RTSs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other grid based data in games could use rasterization for similar situations.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-01-10T01:38:35.283" LastActivityDate="2016-01-10T01:38:35.283" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1878" PostTypeId="1" AcceptedAnswerId="1879" CreationDate="2016-01-08T14:03:31.510" Score="3" ViewCount="171" Body="&lt;p&gt;I have wirtten a fragment shader that works just fine with a single light. Now I am trying to adpat it to work with 8 lights, the implement it in Processing. Clearly I am doing something wrong in the math and I cannot see what it is... I have read other posts about this and try to adapt the answer to my problem, no luck though...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9u1P9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9u1P9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;////Fragment/////&#xA;&#xA;    #ifdef GL_ES&#xA;precision mediump float;&#xA;precision mediump int;&#xA;#endif&#xA;&#xA;varying vec4 vertColor;&#xA;varying vec3 ecNormal;&#xA;varying vec3 lightDir;&#xA;&#xA;void main() {  &#xA;  vec3 direction = normalize(lightDir);&#xA;  vec3 normal = normalize(ecNormal);&#xA;  float intensity = max(0.0, dot(direction, normal));&#xA;  gl_FragColor = vec4(intensity, intensity, intensity, 1) * vertColor;&#xA;}&#xA;&#xA;////vertex/////&#xA;&#xA;        #define PROCESSING_LIGHT_SHADER&#xA;&#xA;uniform mat4 modelview;&#xA;uniform mat4 transform;&#xA;uniform mat3 normalMatrix;&#xA;&#xA;uniform vec4 lightPosition;&#xA;uniform vec3 lightNormal;&#xA;&#xA;attribute vec4 vertex;&#xA;attribute vec4 color;&#xA;attribute vec3 normal;&#xA;&#xA;varying vec4 vertColor;&#xA;varying vec3 ecNormal;&#xA;varying vec3 lightDir;&#xA;&#xA;void main() {&#xA;  gl_Position = transform * vertex;    &#xA;  vec3 ecVertex = vec3(modelview * vertex);  &#xA;&#xA;  ecNormal = normalize(normalMatrix * normal);&#xA;  lightDir = normalize(lightPosition.xyz - ecVertex);  &#xA;  vertColor = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2425" LastEditorUserId="2425" LastEditDate="2016-01-08T15:35:27.393" LastActivityDate="2016-01-08T15:35:27.393" Title="Multiple light pixel Shader in GLSL" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1879" PostTypeId="2" ParentId="1878" CreationDate="2016-01-08T15:22:36.260" Score="2" Body="&lt;p&gt;From the error message the problem is in line 24 of your fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 transformedNormal = normalize(normalMatrix * normal);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;normalMatrix&lt;/code&gt; is a &lt;code&gt;mat4&lt;/code&gt; but &lt;code&gt;normal&lt;/code&gt; is a &lt;code&gt;vec3&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The solution is to make normalMatrix a mat3 instead.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-01-08T15:22:36.260" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1880" PostTypeId="1" CreationDate="2016-01-08T19:44:45.150" Score="6" ViewCount="183" Body="&lt;p&gt;TWO PART QUESTION - We've all seen the movies/TV shows where the police/feds/spies use computer software to take a grainy photo and do a &quot;clean-up&quot; to see a better picture and more details. I assume the concept is executed by some sort of &lt;strong&gt;uber-power&lt;/strong&gt; pixel-smoothing or anti-aliasing type of algorithms to fill in the blanks based on deductive processing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PART 1: How &lt;em&gt;real&lt;/em&gt; is this technology in the public/commercial software world? I'm not asking about any &lt;em&gt;speculation&lt;/em&gt; on alleged secret gov software or such, I just want to know where we actually are with this concept today? How much is fully automated vs human-assisted. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PART 2: Assuming there actually is &lt;em&gt;some&lt;/em&gt; reality with this technology for photographs the second part of this question is how (if at all) has this been applied to videos? Again the issue of fully automated vs human assisted is of interest here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the heart of this post is the ultimate question of how viable is today's software for being able to take an old VHS or DVD recording and process the frames to create a new HD-resolution remaster. Considering that doing this would mean cleaning up tens-of-thousands of frames for even a simple wedding video I am &lt;strong&gt;not&lt;/strong&gt; expecting this technology to be fast of course.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;NOTE: Per in-topic and meta discussions I went ahead and cross-posted this in two other suggested SE forums to acquire their viewpoints and expertise on this matter. So far (it is still a little &quot;early in the day&quot; so to speak) I have received some pretty interesting information in 2 of the 3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When this is all done (when good answers have been selected) I would appreciate a way to merge these &lt;strong&gt;for the benefit of all three SE communities&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Computer Graphics: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1880&quot;&gt;What is the state-of-the-art on using computers to &amp;quot;clean-up&amp;quot; images?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Signal Processing: &lt;a href=&quot;https://dsp.stackexchange.com/questions/28168&quot;&gt;https://dsp.stackexchange.com/questions/28168&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Video Production: &lt;a href=&quot;https://video.stackexchange.com/questions/17363&quot;&gt;https://video.stackexchange.com/questions/17363&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2427" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-01-09T16:11:12.893" Title="What is the state-of-the-art on using computers to &quot;clean-up&quot; images?" Tags="&lt;image-processing&gt;&lt;photo-realistic&gt;&lt;video&gt;" AnswerCount="1" CommentCount="17" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1881" PostTypeId="2" ParentId="1880" CreationDate="2016-01-08T22:50:50.167" Score="2" Body="&lt;p&gt;The closest thing I know of to the &quot;&lt;em&gt;computer: enhance!&lt;/em&gt;&quot; trope in real life is the family of &lt;a href=&quot;http://www.wisdom.weizmann.ac.il/~vision/SingleImageSR.html&quot; rel=&quot;nofollow&quot;&gt;Single Image Super-Resolution&lt;/a&gt; techniques. That page shows a number of examples of the results on various images. You can see that while it improves the visual quality of the enlarged images, it's a long way from what you see on TV where they can read the text on a letter that's reflected in a wine glass, or recognize the face of someone standing in the shadows, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The technique basically works by observing that a single image often contains recurring instances of the same patterns or structures. When you have multiple copies of the same pattern, they often occur at different sub-pixel offsets, i.e. aligned differently to the pixel grid, which means that each copy contains slightly different information about the underlying pattern, and by putting them together you can recover (really, guess at) a higher-resolution version of that pattern. This can then be used to &quot;fill in the missing detail&quot; wherever that pattern occurs. This is a very handwavy explanation, but you can see the paper (linked from the above site) for more details. Most of it is automated, but I'd guess it still requires a fair amount of human parameter-tuning to get good results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper is from 2009, and it looks like there have been a few follow-ups since then, but only incremental improvements.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note that if you have a specific use case such as reading vehicle license plates, I'd guess it's possible to use machine-learning techniques to get much better results than you can in general. In that case, you have a concrete, known set of possible shapes (the characters that can appear on a license plate, in the particular font used for license plates), and rather than &quot;enhancing&quot; an image of literally anything, you're just trying to find the set of characters that best matches the image you're looking at. That's not my area of expertise, though.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-08T22:50:50.167" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1882" PostTypeId="2" ParentId="1765" CreationDate="2016-01-09T12:40:33.980" Score="1" Body="&lt;p&gt;This is a good solution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I just had a problem transforming &lt;code&gt;AxisVector&lt;/code&gt; in screen coordinates, it turns out I must project two points from this vector on the screen, as explained in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1772/2173&quot;&gt;this answer&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2173" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-01-09T12:40:33.980" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1883" PostTypeId="2" ParentId="1765" CreationDate="2016-01-09T12:41:12.300" Score="4" Body="&lt;p&gt;I would not recommend to correlate the extrusion direction with its screen projection because of the asymptotic behaviour in case the axis points toward the screen or the resulting extrusion crosses the focal point of the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One consistent way of doing it would be computing the extrusion height independently of the axis direction:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Find a virtual construction plane of your operation which is parallel to the screen. For example, in the real world, this plane would be a plane of your computer monitor screen reachable by hand as you sit at your computer.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Usually, you have some kind of central point which serves as a center of screen camera rotation as you navigate your viewport. You can draw your construction plane through this point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way is drawing your construction plane through the intersection of the mouse cursor and your object as you start your extrusion operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either way, the construction plane must be parallel to the screen and in front of your camera view for this method to work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are using an orthogonal projection (camera without a Field of View) then you can draw the construction plane through any point.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;Compute the length of the projection of mouse motion on the construction plane your figured out in point (1). This is your desired extrusion height.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Provide a means of moving the construction plane back and forth along the view axis, if the current viewport has FOV. You don't need to display and the move the construction plane if your viewport uses orthogonal projection.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Using this method your extrusion operation height would be visually consistent with what user expects with mouse motion, and the user would not experience any asymptotic and singularity issues as with the axis projection method.&lt;/p&gt;&#xA;" OwnerUserId="2433" LastActivityDate="2016-01-09T12:41:12.300" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1884" PostTypeId="1" CreationDate="2016-01-09T16:08:47.323" Score="3" ViewCount="560" Body="&lt;p&gt;Why do I need to specify the same name for color input in fragment shader and output color from vertex shader?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Vertex shader&#xA;out vec3 vertex_color;&#xA;&#xA;void main()&#xA;{&#xA;    vertex_color=vec3(1.0,0.0,0.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Fragment shader &#xA;in vec3 vertex_color;&#xA;out vec4 frag_color;&#xA;&#xA;void main()&#xA;{&#xA;    frag_color=vec4(vertex_color,1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Since we already hand the color value from vertex shader to fragment shader, why do we need same names?&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="127" LastEditDate="2016-01-09T17:22:14.240" LastActivityDate="2016-01-09T23:16:32.433" Title="OpenGL vertex color" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1885" PostTypeId="2" ParentId="1884" CreationDate="2016-01-09T20:12:41.833" Score="4" Body="&lt;p&gt;Using the same name is exactly how you tell OpenGL that you want the value passed through from vertex to fragment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You say &quot;we already hand the color value from vertex shader to fragment shader&quot;, but that's not correct. Usually, the only value that's passed between shaders &lt;em&gt;automatically&lt;/em&gt; is position, and that's only because it feeds into the GPU's rasterization hardware to draw the triangle on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any other values such as color, normal, texture coordinates, etc. that you want passed between shader stages have to be explicitly hooked up by the shader author. And the way you do that in GLSL is to create an &lt;code&gt;out&lt;/code&gt; variable in one stage, and an &lt;code&gt;in&lt;/code&gt; variable in the next stage, with the same name.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-09T20:12:41.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1886" PostTypeId="2" ParentId="1884" CreationDate="2016-01-09T23:16:32.433" Score="3" Body="&lt;p&gt;Because you may want to pass more than one attribute through to the fragment shader. 2 which are essential are normal vector and the texture coordinates once you start doing lighting and textured meshes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can in newer openGL versions give a numbered location to the attributes you pass through using &lt;code&gt;layout(location=1)&lt;/code&gt;. Then the names don't have to match.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-01-09T23:16:32.433" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1887" PostTypeId="1" CreationDate="2016-01-10T04:54:51.350" Score="7" ViewCount="702" Body="&lt;p&gt;Since long ago I wanted to implement a 2D lightning algorithm based on an &lt;a href=&quot;https://www.youtube.com/watch?v=74uXA7SmDqE&quot; rel=&quot;noreferrer&quot;&gt;idea I saw on YouTube&lt;/a&gt;. The video is realtime, but it runs on the CPU and the resolution is pretty low. I'm curious if anyone has an idea how to do this on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm works the following way:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;We have light data maps, these hold the color of the material (e.g. a red glass has 0xFF0000) and how transparent that pixel is.    &lt;/li&gt;&#xA;&lt;li&gt;Work out the light values of each pixel in growing circles from a light source. In other words, first calculate values right next to the light (8 pixels), then the neighbours of these pixels and so on. The color of a pixel is its value from the lightning data map, its alpha equals: (alpha of the pixel next to it closest to the light source - own alpha). So it is some kind of ray casting algorithm that calculates value for each pixel and can handle colored glass and fog/smoke.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So the CPU implementation is pretty trivial. My problem is that I want to use this in a mobile game, but I don't know how this would work as a shader.&#xA;How can this be implemented on the GPU (that would run on mobile, so with OpenGL ES 2.0/3.0, maybe with Metal - if this is not possible then with OpenCL/CUDA)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: I am not looking for full implementations, just ideas/shader pseudocode how this would be possible.&lt;/p&gt;&#xA;" OwnerUserId="2437" LastEditorUserId="2437" LastEditDate="2016-01-10T17:59:21.980" LastActivityDate="2016-01-11T17:39:42.400" Title="How to implement a realtime 2D light renderer with fog/colored light on the GPU?" Tags="&lt;raytracing&gt;&lt;algorithm&gt;&lt;shader&gt;&lt;real-time&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1888" PostTypeId="1" CreationDate="2016-01-10T12:25:09.853" Score="6" ViewCount="661" Body="&lt;p&gt;I'm trying to figure out how to properly implement flat shading for meshes containing non-planar polygons (using OpenGL/GLSL). The aim is to obtain something similar to the result &lt;em&gt;Blender&lt;/em&gt; gives (all polygons below are non-planar):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2Whne.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2Whne.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To provide a bit of context — the non-planar polygons (e.g. quads, pentagons, ...) are either present in the mesh I load or appear as a result of applying a subdivision scheme (such as Catmull-Clark) to the mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case of a triangle mesh, I'm aware of the following approaches to implement flat shading —&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Compute the cross product of &lt;code&gt;dFdx&lt;/code&gt; and &lt;code&gt;dFdy&lt;/code&gt; in the fragment shader&lt;/li&gt;&#xA;&lt;li&gt;Use the geometry shader to compute the triangle normal by taking the cross product of two sides of the triangle&lt;/li&gt;&#xA;&lt;li&gt;When using &lt;code&gt;glDrawElements&lt;/code&gt;, use the &lt;code&gt;flat&lt;/code&gt; interpolation qualifier (which basically uses the normal associated with the provoking vertex for all fragments)&lt;/li&gt;&#xA;&lt;li&gt;When using &lt;code&gt;glDrawArrays&lt;/code&gt;, most vertices (usually all of them) are copied to the GPU multiple times. Therefore, a different normal can be used each time&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For a mesh containing non-planar polygons the first three options don't yield the result I'm after. In my implementation (using the Qt framework) I use &lt;code&gt;GL_TRIANGLE_FAN&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4ujWL.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4ujWL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fourth option could work, but isn't very elegant — I'd like to use either &lt;code&gt;glDrawElements&lt;/code&gt; or &lt;code&gt;glDrawMultiElements&lt;/code&gt;. One other option would be to use &lt;code&gt;glDrawElements&lt;/code&gt; while looping over the faces one by one (instead of invoking it once using &lt;code&gt;glPrimitiveRestartIndex&lt;/code&gt;). In that case, one could upload a &lt;code&gt;uniform&lt;/code&gt; normal for each face. However, this does not seem very efficient. Any other ideas?&lt;/p&gt;&#xA;" OwnerUserId="2440" LastEditorUserId="2440" LastEditDate="2016-01-10T18:16:30.373" LastActivityDate="2016-01-13T14:29:53.797" Title="Flat shading for non-planar polygons" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1889" PostTypeId="2" ParentId="1887" CreationDate="2016-01-10T17:37:36.223" Score="6" Body="&lt;p&gt;If your wall geometry is vector graphics you can simply extrude the segment away from the light position. This means 2 triangles per draw call, all the extrusion offsets can  can be handled in the vertex shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/u80e2.png&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u80e2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: For each wall generate a shadow volume extrusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quick and extremely dirty sample implementation of shadow volumes here:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://webglplayground.net/saved/AeN6yoNGih&quot;&gt;http://webglplayground.net/saved/AeN6yoNGih&lt;/a&gt; (please do not save your own version, fork instead)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Now since your shader can color the triangles as they see fit you can apply a shader on the triangles that is colored. Just like you would render transparent surfaces. To do this proper you may need a offscreen buffer for getting a proper color accumulation mode.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/o2KTd.png&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o2KTd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Coloring the volumes based on distance to light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Certainly the coloring algorithm may be whatever you like. for example the color could become darker the nearer you are to the extrude edge etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is very quickly done &lt;em&gt;extremely dirty&lt;/em&gt; live example of colored shadow volumes:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://webglplayground.net/saved/9xgxDbtY7f&quot;&gt;http://webglplayground.net/saved/9xgxDbtY7f&lt;/a&gt; (please do not save your own version, fork instead), very bad code style done on the run (and on my phone).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This is just one way hopefully others will elborate. You can also use the exact same methods as you would in 3d. As for nonuniform fog, you could just use a raymarcher.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-01-11T17:39:42.400" LastActivityDate="2016-01-11T17:39:42.400" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1890" PostTypeId="1" AcceptedAnswerId="1891" CreationDate="2016-01-10T22:15:57.840" Score="5" ViewCount="163" Body="&lt;p&gt;I'm working on implementing &lt;a href=&quot;http://www-ljk.imag.fr/Publications/Basilic/com.lmc.publi.PUBLI_Inproceedings@117681e94b6_1e9c7f4/clouds.pdf&quot;&gt;Bruneton's cloud rendering paper&lt;/a&gt;, which requires one to render a pair of depth maps, similar to how shadow mapping works. In this case, my light source is the sun (or possibly the moon), which I represent in my rendering engine as a normalized vector pointing in the direction of the sun or moon, which is essentially located at infinity from the current camera position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the light source doesn't have a traditional &quot;position,&quot; I'm having a little trouble determining how best to create the viewpoint transformations for the source. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I would also essentially use the same transformation for sun/moon shadowing, it'd kill two birds with one stone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is thus:&#xA;&lt;strong&gt;How can I generate a view transform for generating depth maps of area light sources located at infinity?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="2408" LastActivityDate="2016-01-10T22:54:46.133" Title="How should I generate the view position for a light at infinity when creating depth maps?" Tags="&lt;c++&gt;&lt;shadow-mapping&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1891" PostTypeId="2" ParentId="1890" CreationDate="2016-01-10T22:54:46.133" Score="5" Body="&lt;p&gt;Instead of using a perspective projection you would use a &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection&quot;&gt;orthographic projection&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the trick is to position the bounding box to in front of the normal camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An additional option is to add a &lt;a href=&quot;https://en.wikipedia.org/wiki/Shear_mapping&quot;&gt;skew/shear operation&lt;/a&gt; so it maps the light direction to the vertical and keeps the horizontal ground plane horizontal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This avoids leaving a large dead zone underground near the light source.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-01-10T22:54:46.133" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1892" PostTypeId="1" CreationDate="2016-01-11T00:14:00.453" Score="4" ViewCount="313" Body="&lt;p&gt;I've recently rebuild shaders for my program and it stopped &quot;working&quot; ( black screen ) on OS X ( El Capitan ), but &lt;strong&gt;it's ok on Linux on GTX 660&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tested it on another Apple hardware and &lt;strong&gt;it worked on OS X on R9 395&lt;/strong&gt; ( but super slow, because of double ). So I suppose it's problem with my &lt;strong&gt;Intel HD Graphics 5000&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are no shader compilation errors, and here is my shader code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Marqin/YuriaViewer/blob/4241e384da0f27d26cbf5557518db905a9d40039/vertex.glsl&quot; rel=&quot;nofollow&quot;&gt;https://github.com/Marqin/YuriaViewer/blob/4241e384da0f27d26cbf5557518db905a9d40039/vertex.glsl&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that this software worked on El Capitan with OpenGL 4.1 before shader rewrite. Here are my glfw hints:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);&#xA;glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);&#xA;glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My program also is checking for &lt;code&gt;GL_ARB_gpu_shader_fp64&lt;/code&gt; and it's available on my Macbook ( Macbook Air 2013 mid ).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've &quot;debugged&quot; it a little and it looks that &lt;code&gt;i&lt;/code&gt; is always lesser than &lt;code&gt;vis&lt;/code&gt; on OS X, that's why it's black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also made a simple test - I've typed all uniform values in shader by hand and now it wasn't black, but I've got some gibberish on screen. Then I've changed every &lt;code&gt;dvec3&lt;/code&gt; and &lt;code&gt;dvec2&lt;/code&gt; to float versions and it showed nice fractal. So it looks like &lt;code&gt;double&lt;/code&gt; is not working on OS X. But how can it be? It's saying that &lt;code&gt;GL_ARB_gpu_shader_fp64&lt;/code&gt; is available and it even doesn't complain when I request it in vertex shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I make it work on OS X Macbook?&lt;/p&gt;&#xA;" OwnerUserId="2413" LastEditorUserId="2413" LastEditDate="2016-03-30T22:06:29.490" LastActivityDate="2016-03-30T22:06:29.490" Title="How to make double working in OpenGL 4.1 on OS X ( Intel HD Graphics 5000 )?" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="0" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="1893" PostTypeId="1" CreationDate="2016-01-11T14:52:59.460" Score="0" ViewCount="105" Body="&lt;p&gt;I want to select a pixel within a circle of a certain radius. But the radius is expressed in a decimal form (0.12). What does it mean to have a radius equal to 0.12? And concretely how to pick a pixel within a circle having such a radius?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ksGCK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ksGCK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2233" LastActivityDate="2016-01-11T14:52:59.460" Title="Selecting pixels within a circle having a decimal (non integer) radius" Tags="&lt;c++&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1894" PostTypeId="1" CreationDate="2016-01-11T19:51:14.097" Score="3" ViewCount="242" Body="&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=twUz99ek5do&amp;amp;list=WL&amp;amp;index=5&quot; rel=&quot;nofollow&quot;&gt;https://www.youtube.com/watch?v=twUz99ek5do&amp;amp;list=WL&amp;amp;index=5&lt;/a&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a process from 1:51, where the guy start making polygons around the bodyparts. I think this is this part is where (with later transformations) you can make a single draw like a 3D animation (with transforming the triangles). What is the name of the process, and is this effect available in other animation softver? &#xA;I'm thinking about mostly maya, spriter or unity.&#xA;Ty &lt;/p&gt;&#xA;" OwnerUserId="2451" LastActivityDate="2016-01-11T22:22:05.730" Title="Spine. What is the name of the process?" Tags="&lt;3d&gt;&lt;animation&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1895" PostTypeId="1" AcceptedAnswerId="1899" CreationDate="2016-01-11T20:09:00.557" Score="8" ViewCount="879" Body="&lt;p&gt;I have been working on a graphics library for some time now and have gotten to the point where I have to draw Bezier and line based fonts. Up to this point I am stuck with this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://cdn.discordapp.com/attachments/132932473242910720/136193149239427073/unknown.png&quot; alt=&quot;i&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://cdn.discordapp.com/attachments/132932473242910720/136196291146285056/unknown.png&quot; alt=&quot;a&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The green lines are the Bezier paths, and the white part is what gets rendered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code I use for Beziers is &lt;a href=&quot;http://pastebin.com/s8qDC4NH&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;. The one for lines is &lt;a href=&quot;http://pastebin.com/bKv55tch&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;. For those who don't know that is Lua. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Path rendering (lines) : 32 - 39&#xA;  The algorithm is as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Iterating from 0 to 1 at certain intervals&lt;/li&gt;&#xA;&lt;li&gt;calculating the x and y with this formula: &lt;code&gt;(1-index)^2*x1+2*(1-index)*index*x2+index^2*x3&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Up to this point everything works fine. The green lines are generated using the path method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The white part is rendered in a completely different way:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I get the x coordinates of the Beziers and lines at a particular Y, the put them into a table.&lt;/li&gt;&#xA;&lt;li&gt;I iterate through the table and each time I encounter a point I change the value of state. In the same for loop is also check whether state is on. If it is, I draw a pixel to the screen.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;To find the x values of a y, I use the getX method (line 46 in Bezier and line 31 in Line).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code I use for the drawing itself is this one:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;local xBuffer = {}&#xA;local state = false&#xA;&#xA;for i=0,500 do&#xA;    for k,v in pairs(beziers) do&#xA;        a,b = v.getX(i)&#xA;        if a then&#xA;            xBuffer[round(a)] = 1&#xA;            if b then&#xA;                xBuffer[round(a)] = 1&#xA;            end&#xA;        end&#xA;    end&#xA;    for k,v in pairs(lines) do&#xA;        a = v.getX(i)&#xA;        if a then&#xA;            xBuffer[round(a)] = 1&#xA;        end&#xA;    end&#xA;    state = false&#xA;    for x=0,600 do&#xA;        if xBuffer[x] then&#xA;            state = not state&#xA;        end&#xA;        if state then&#xA;            love.graphics.points(x,i)&#xA;        end&#xA;    end&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Quick explanation: for i,v in pairs iterates through the table given as an argument to pairs. love.graphics.points(x,y) sets a point at x,y.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="2447" LastEditorUserId="5349" LastEditDate="2017-05-20T08:43:52.837" LastActivityDate="2017-05-31T07:26:51.043" Title="How should I fill a shape consisting of Bezier curves and straight lines?" Tags="&lt;rendering&gt;&lt;algorithm&gt;&lt;geometry&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1896" PostTypeId="1" AcceptedAnswerId="1900" CreationDate="2016-01-11T21:47:54.283" Score="3" ViewCount="513" Body="&lt;p&gt;I have managed to implement a garoud shader with specular lighting efects in Processing 3.0 . Now I am trying with a fragment Phong shader but cannot make it work. I can´t find where is the error. It should just implent the phong illumination model, with specular and diffuse components.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eKOTe.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eKOTe.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex Shader: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define PROCESSING_LIGHT_SHADER&#xA;&#xA;uniform mat4 modelview;&#xA;uniform mat4 transform;&#xA;uniform mat3 normalMatrix;&#xA;&#xA;&#xA;&#xA;attribute vec4 vertex;&#xA;attribute vec4 color;&#xA;attribute vec3 normal;&#xA;&#xA;varying vec4 vertColor;&#xA;&#xA;varying vec3 transformedNormal;&#xA;varying vec3 vertexCamera;&#xA;&#xA;void main() {&#xA;  gl_Position = transform * vertex;    &#xA;&#xA;  vertexCamera = vec3(modelview * vertex);  &#xA;  transformedNormal = normalize(normalMatrix * normal);&#xA;  vertColor = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragement Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifdef GL_ES&#xA;precision mediump float;&#xA;precision mediump int;&#xA;#endif&#xA;&#xA;uniform vec3 lightPosition;&#xA;uniform vec3 eye_Position;&#xA;&#xA;varying vec4 vertColor;&#xA;varying vec3 lightDir;&#xA;&#xA;varying vec3 transformedNormal; //world pos&#xA;varying vec3 vertexCamera; // world normal&#xA;&#xA;void main() {  &#xA;&#xA; vec3 normalizedPos =  normalize(lightPosition.xyz -vertexCamera);&#xA; vec3 direction = normalize(eye_Position - vertexCamera); &#xA;&#xA;&#xA; float intensity = 0.0;&#xA; float specular = 0.0;&#xA;&#xA;&#xA; float LdotN = max(0, dot(normalizedPos,direction));&#xA; float diffuse = 1 * LdotN;&#xA;&#xA; vec3 R = -normalize(reflect(normalizedPos,transformedNormal));&#xA; specular = pow( max(0, dot( R, direction)), 16);&#xA;&#xA;&#xA;  intensity += (diffuse + specular);&#xA;&#xA;  gl_FragColor = vec4(intensity, intensity, intensity, 1) * vertColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2425" LastEditorUserId="2425" LastEditDate="2016-01-11T22:15:05.193" LastActivityDate="2016-01-12T16:36:27.080" Title="Shader won't work" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1897" PostTypeId="2" ParentId="1894" CreationDate="2016-01-11T22:22:05.730" Score="3" Body="&lt;p&gt;This appears to be simply &lt;a href=&quot;https://en.wikipedia.org/wiki/Skeletal_animation&quot; rel=&quot;nofollow&quot;&gt;skeletal animation&lt;/a&gt;, which is a standard technique that is available in all modern animation packages. Whether applied to 3D meshes or (as here) 2D ones, the principle is the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The pseudo-3D effect on the sprites is created by using a mesh where vertices are placed along the contours of the sprite texture, then animated to squash and stretch parts the image in such a way that it creates the illusion of 3D motion, even though the sprite images are authored in 2D. There's &lt;a href=&quot;http://esotericsoftware.com/spine-meshes#Deformation&quot; rel=&quot;nofollow&quot;&gt;a description of the technique in the Spine docs&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-11T22:22:05.730" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1899" PostTypeId="2" ParentId="1895" CreationDate="2016-01-12T12:53:59.170" Score="6" Body="&lt;p&gt;If you are in a hurry to get your renderer working &lt;em&gt;and&lt;/em&gt; you already have the filled polygonal routine &lt;em&gt;functioning correctly&lt;/em&gt;, can I suggest an alternative, possibly easier approach? Though I'm not familiar with Lua, it seems you are solving for the exact intersection of a scan line with the quadratic Bezier which, though admirable, is possibly overkill.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, tessellate your Beziers into line segments and then throw those into the polygon scan converter. I suggest just using (recursive) binary subdivision: i.e. the quadratic Bezier with control points, $(\overline {A} , \overline {B} , \overline {C})$ can be split into two Beziers, $(\overline {A} , \overline {D} , \overline {E})$ and $(\overline {E} , \overline {F} , \overline {C})$ &#xA;where&#xA;$$&#xA;\begin{align*} &amp;amp; \overline {D}=\dfrac {\overline {A}+\overline {B}} {2}\\ &amp;amp; &#xA;\overline {E} =\dfrac {\overline {A}+2\overline {B}+\overline {C}}{4}\\ &amp;amp;&#xA;\overline {F}=\dfrac {\overline {B}+\overline {C}} {2}&#xA;\end{align*}&#xA;$$&#xA;(which is also great if you only have fixed point maths).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IIRC, each time you subdivide, the error between the Bezier and just a straight line segment joining the end points goes down by a factor of ~4x, so it doesn't take many subdivisions before the piecewise linear approximation will be indistinguishable from the true curve. You can also use the bounding box of the control points to decide if you can skip out of the subdivision process early since that will also be a conservative bound on the curve.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-05-31T07:26:51.043" LastActivityDate="2017-05-31T07:26:51.043" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1900" PostTypeId="2" ParentId="1896" CreationDate="2016-01-12T16:36:27.080" Score="2" Body="&lt;p&gt;If you are using Processing the variable &lt;code&gt;lightPosition&lt;/code&gt; must be declared as a &lt;code&gt;vec4&lt;/code&gt;, otherwise it won't be passed in, and will be always 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then your diffuse computation is not correct, the dot product we want it's between the normal and the light direction:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float LdotN = max(0, dot(normalizedPos,transformedNormal));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm not sure about the uniform &lt;code&gt;eye_Position&lt;/code&gt;, I believe it's always 0 as nobody is setting it. Anyway, it is not needed. Since the fragment position it's already on camera space, the camera direction is simply: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 direction = -normalize(vertexCamera);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The complete fragment shader should be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifdef GL_ES&#xA;precision mediump float;&#xA;precision mediump int;&#xA;#endif&#xA;&#xA;uniform vec4 lightPosition;&#xA;&#xA;varying vec4 vertColor;&#xA;varying vec3 transformedNormal;&#xA;varying vec3 vertexCamera;&#xA;&#xA;void main() {  &#xA;&#xA; vec3 normalizedPos =  normalize(lightPosition.xyz -vertexCamera);&#xA; vec3 direction = -normalize(vertexCamera); &#xA;&#xA; float intensity = 0.0;&#xA; float specular = 0.0;&#xA;&#xA; float LdotN = max(0, dot(normalizedPos,transformedNormal));&#xA; float diffuse = 1 * LdotN;&#xA;&#xA; vec3 R = -normalize(reflect(normalizedPos,transformedNormal));&#xA; specular = pow( max(0, dot( R, direction)), 16);&#xA;&#xA;  intensity += (diffuse + specular);&#xA;&#xA;  gl_FragColor = vec4(intensity, intensity, intensity, 1) * vertColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2064" LastActivityDate="2016-01-12T16:36:27.080" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1901" PostTypeId="1" AcceptedAnswerId="2012" CreationDate="2016-01-12T22:43:34.653" Score="5" ViewCount="516" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MZosQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MZosQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm working on a shadertoy &quot;snake&quot; game, using the new multi pass rendering abilities to save game state between frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using raytracing to render the board (an AABB), and am planning on using spheres to render sections of the snake's body.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The game board is a 16x16 grid and each grid can either have a sphere there (a segment of the snake's body) or not.  Snake body segments don't move, they are just either there on the grid or not.  When the snake moves, a new sphere appears in the front and an old sphere disappears from the back.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I'm trying to solve is how to render the snake body spheres.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, a naive approach would be to store a 16x16 grid in pixels specifying whether there was a snake body in that grid cell or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would then do a ray vs sphere check for up to 256 different spheres within my pixel shader, which seems like a no go.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another method might be to figure out where the ray begins and ends on the game board (when it's between the high and low height values of where the spheres are) and then use something like bressenham line algorithm to go from the start to the end of the line the ray takes on the board, and check only the grid cells that the ray hits.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem there is that it requires a dynamic loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe a more practical solution would be to make the camera have a nearly top down view and where the ray enters the playable game world, test any sphere in the cell it hits as well as the 8 neighboring cells.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm betting there are some much better solutions that I'm not thinking of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know of any interesting techniques or creative solutions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: here is an older version of this game i made, which was CPU / software rendered, to give an idea of what I'm planning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/y7OLJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/y7OLJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-01-12T22:53:49.307" LastActivityDate="2016-02-08T02:09:01.450" Title="Methods for grid traversal in a glsl pixel shader?" Tags="&lt;raytracing&gt;&lt;real-time&gt;&lt;glsl&gt;&lt;pixel-shader&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1903" PostTypeId="1" CreationDate="2016-01-13T08:17:56.753" Score="2" ViewCount="1528" Body="&lt;p&gt;In R software, I want to plot a graph by using cox regression with the restricted cubic spline method. However, I can't quite get it to work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the code I'm using:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;library(rms); require(rms); library(Hmisc)&#xA;d&amp;lt;-curve.men&#xA;dd &amp;lt;- datadist(d)&#xA;options(datadist=&quot;dd&quot;)&#xA;fit &amp;lt;- cph(Surv(time,death) ~ rcs(bmi,4)&#xA;           + systolic +glucose + l_chol + age &#xA;           + edu_g2 + smoke_s + l_chol + drink + activity_l+activity_w,&#xA;             data=d, nk=5)&#xA;plot(Predict(fit,bmi), xlab=&quot;bmi&quot;, ylab=&quot;Relative Risk&quot;, lty=1, lwd=2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which creates the following plot &lt;strong&gt;(A)&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MoyLw.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MoyLw.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I want to plot the following graph &lt;strong&gt;(B)&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Fx5Qx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Fx5Qx.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How do I set the reference point? (for example: &lt;code&gt;bmi = 24.21429&lt;/code&gt; as the reference point)&lt;/li&gt;&#xA;&lt;li&gt;I want to add the horizontal line. I tried using &lt;code&gt;abline(h=1)&lt;/code&gt;, but it did not work.&lt;/li&gt;&#xA;&lt;li&gt;All in all, how do I make the graph look like (B)?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2459" LastEditorUserId="231" LastEditDate="2016-01-19T13:07:28.377" LastActivityDate="2016-01-19T13:07:28.377" Title="Problems in using cox regression with restricted cubic spline plot with R software" Tags="&lt;line-drawing&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1904" PostTypeId="1" AcceptedAnswerId="1907" CreationDate="2016-01-13T09:47:21.997" Score="10" ViewCount="665" Body="&lt;p&gt;I want to extract colors from images like in Adobe Kuler. When I select colorful or muted corresponding colors are shown. But what is the definition for colorful or muted colors? What do the words &quot;colorful&quot;, &quot;deep&quot; and &quot;muted&quot; refer to? &lt;/p&gt;&#xA;" OwnerUserId="2383" LastEditorUserId="231" LastEditDate="2016-01-19T13:03:05.540" LastActivityDate="2016-01-19T13:03:05.540" Title="What does &quot;muted&quot; mean in the context of color?" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1906" PostTypeId="2" ParentId="1888" CreationDate="2016-01-13T14:29:53.797" Score="7" Body="&lt;p&gt;Without knowing the internals of Blender, I would say it uses shared normals for the quads, splitting the normals only on edges between the quads, not between the triangles. So your idea of uploading a normal per quad is probably close to the result you are looking for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you load the mesh as quads, you are set. If you are using an old version of OpenGL where quads still exist, you may even be able to use solution 3).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you load the mesh as triangles, you will have to figure out which triangles originated in quads. You can likely do this simply by enforcing split normals beyond a fixed angle between adjacent triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not sure there is a simple dynamic solution, where you just render any mesh. You may be able to use the geometry shader to look at the adjacent vertices, but the easiest version is to smooth the normals once before upload.&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2016-01-13T14:29:53.797" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1907" PostTypeId="2" ParentId="1904" CreationDate="2016-01-13T22:52:26.323" Score="10" Body="&lt;p&gt;In terms of the HSV color space, &lt;a href=&quot;http://designshack.net/articles/graphics/the-evolution-of-flat-design-muted-colors/&quot;&gt;&quot;muted&quot; colors are those with lower saturation and/or value&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Deep&quot; colors are saturated but not too high in value (e.g. &lt;a href=&quot;https://www.google.com/search?q=deep+red&amp;amp;tbm=isch&quot;&gt;deep red&lt;/a&gt;) while colors with both high saturation and value might be called &quot;bright&quot; (e.g. &lt;a href=&quot;https://www.google.com/search?q=bright+red&amp;amp;tbm=isch&quot;&gt;bright red&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Colorful&quot; is somewhat more vague; it might mean bright colors, but it also might mean having a range of different hues within an image or palette, such as including complementary colors or analogous colors rather than just variations on a single hue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that these are general terms that would be understood by any graphic designer or artist, but the specific algorithms that Adobe Kuler attaches to these words are proprietary and only known to Adobe.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-13T22:52:26.323" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1909" PostTypeId="1" AcceptedAnswerId="1915" CreationDate="2016-01-14T22:55:11.760" Score="6" ViewCount="224" Body="&lt;p&gt;I am using Unity but this question might not be proper to this engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have projected the shadow map onto this sphere but there are grazing shadows. Is it possible to avoid it or to correct it as I am using the raw depth data of the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sGOqR.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sGOqR.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the pseudo-shader code.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler2D _ShadowMap;&#xA;float4 shadowCoord : TEXCOORD1;&#xA;&#xA;// vertex shader&#xA;o.shadowCoord = mul(unity_World2Shadow[0], mul(_Object2World, v.vertex));&#xA;&#xA;// fragment shader&#xA;color.rgb = tex2D(_ShadowMap, i.shadowCoord);&#xA;return color;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-01-15T07:26:34.417" LastActivityDate="2016-01-18T13:40:31.857" Title="Shadow map projection issue" Tags="&lt;opengl&gt;&lt;algorithm&gt;&lt;shader&gt;&lt;glsl&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1911" PostTypeId="1" CreationDate="2016-01-15T22:37:17.597" Score="1" ViewCount="765" Body="&lt;p&gt;What advantages do the outcodes offer in &lt;a href=&quot;https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm&quot; rel=&quot;nofollow&quot;&gt;this algorithm&lt;/a&gt; ? Do they help in simplifying the algorithm ? Do they decrease the number of calculations ?&lt;/p&gt;&#xA;" OwnerUserId="2214" LastEditorUserId="457" LastEditDate="2016-01-16T09:46:49.020" LastActivityDate="2016-01-18T11:58:50.560" Title="Outcodes in Cohen-Sutherland Clipping Algorithm" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1912" PostTypeId="1" AcceptedAnswerId="1933" CreationDate="2016-01-16T14:05:16.673" Score="9" ViewCount="200" Body="&lt;p&gt;I try to implement a position based cloth simulation using hardware tesselation.&#xA;This means I want to just upload a control quad to the graphics card and then use tesselation and geometry shading to create the nodes in the cloth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This idea follows the paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Huynh, David, &quot;Cloth simulation using hardware tessellation&quot; (2011). Thesis. Rochester Institute of Technology&#xA;&lt;a href=&quot;http://scholarworks.rit.edu/theses/265/&quot;&gt;http://scholarworks.rit.edu/theses/265/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know how to use tesselation to create the simulated points.&#xA;What I don't know is how to store the computated information into a framebuffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The geometry and also the tesselation evaluation shaders have informations needed for the per-vertex computations. But can they directly write into the framebuffer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fragment-shader I know can write to the framebuffer, but my information would be interpolated and I would no longer know what to write at which position.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-01-21T12:20:38.830" Title="Per Vertex Computation in OpenGL Tesselation" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;gpgpu&gt;&lt;simulation&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1914" PostTypeId="2" ParentId="1911" CreationDate="2016-01-18T11:58:50.560" Score="3" Body="&lt;p&gt;The outcodes just represent four boolean flags as a bitfield. Codewise it is easier to move a bitfield around than four booleans. Functionality-wise it becomes very easy to check if &lt;em&gt;any&lt;/em&gt; bits are set (just check if zero), and combining outcodes is as simple as a bitwise OR.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a side-note: Since bit-operations are fast, it is not a performance issue that the individual bits need to be extracted (e.g. outcode &amp;amp; BOTTOM).&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2016-01-18T11:58:50.560" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1915" PostTypeId="2" ParentId="1909" CreationDate="2016-01-18T13:40:31.857" Score="2" Body="&lt;p&gt;One of the downsides to shadowmapping is that you need to offset, or bias, the point used for shadowmap-lookups. This is done in a variety of ways - typically by a constant (shadowmap-depth) distance or based on the slope of the casting triangle. Both of these tend to be done during the shadowmap-rendering pass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think what you need to solve your sphere-problem, is to offset the point you are shading a bit along its surface normal, before doing the shadowmap-lookup. This happens during shading, when sampling the shadowmap, not during shadowmap-rendering. Incidentally it is also part of the Unity standard rendering pipeline, so you can steal it from the shader include-files.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ref &lt;a href=&quot;http://www.dissidentlogic.com/old/images/NormalOffsetShadows/GDC_Poster_NormalOffset.png&quot; rel=&quot;nofollow&quot;&gt;http://www.dissidentlogic.com/old/images/NormalOffsetShadows/GDC_Poster_NormalOffset.png&lt;/a&gt;&#xA;ref &lt;a href=&quot;http://www.digitalrune.com/Blog/Post/1765/Shadow-Acne&quot; rel=&quot;nofollow&quot;&gt;http://www.digitalrune.com/Blog/Post/1765/Shadow-Acne&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2016-01-18T13:40:31.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1916" PostTypeId="1" AcceptedAnswerId="1930" CreationDate="2016-01-18T13:43:31.223" Score="1" ViewCount="1028" Body="&lt;p&gt;I've stumbled upon this question on a CG exam:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Which of the following techniques/optimizations doesn't apply to ray tracing?&lt;/p&gt;&#xA;&lt;p&gt;A: Back-face culling&lt;/p&gt;&#xA;&lt;p&gt;B: &amp;quot;Shadow-feeler&amp;quot; rays&lt;/p&gt;&#xA;&lt;p&gt;C: Recursive tracing of rays&lt;/p&gt;&#xA;&lt;p&gt;D: Calculation of refraction rays&lt;/p&gt;&#xA;&lt;p&gt;E: None of the above&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;B, C and D are obviously false, but what about A? &lt;a href=&quot;http://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/single-vs-double-sided-triangle-backface-culling&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;, is says that &amp;quot;with ray tracing, this feature is not as useful. Generally with ray tracing, we want geometry in the scene to cast shadows for example, regardless of the orientation of the object's surface with respect to the ray direction however the backface culling option might still be desired for primary rays&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;I feel that the question is a bit ambiguous, since back-face culling can be applied to ray tracing but it's not (correct me if I'm wrong) a &amp;quot;native&amp;quot; feature as the other techniques.&lt;/p&gt;&#xA;" OwnerUserId="2489" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-08-16T02:25:16.983" Title="Is back-face culling considered a technique/optimization of ray tracing?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1919" PostTypeId="1" AcceptedAnswerId="1931" CreationDate="2016-01-18T23:03:14.117" Score="6" ViewCount="107" Body="&lt;p&gt;&lt;a href=&quot;http://renderman.pixar.com/view/implementing-a-skin-bssrdf&quot;&gt;http://renderman.pixar.com/view/implementing-a-skin-bssrdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this paper on subsurface scattering, I'm trying to understand how importance sampling is used to compute single scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It says that the outscattered radiance for the single term, $L_o$, can be rewritten as the product of the exponential falloff in $s'_o$ with another function:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;$L_o(x_o,\vec{\omega}_o) = \bigg[&#xA; L_i(x_i,\vec{\omega}_i)\cfrac{\sigma_s(x_o)F_p(\vec{\omega}'_i \cdotp&#xA; \vec{\omega}'_o )}{\sigma_{tc}}e^{-s'_i \sigma_t(x_i)} \bigg]&#xA; e^{-s_o\sigma(x_o)}$&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;By picking samples according to $x \sim \sigma_t e^{-\sigma_t x}$, the&#xA;  integration in $L_o$ can be approximated by a summation by applying&#xA;  importance sampling. Also by choosing $s'_o =&#xA; \cfrac{-\mathbb{log(random())}}{\sigma_{tr}}$, you can sum up all&#xA;  contributions without computing the falloff term in $s_o$.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;br&gt;&lt;br&gt;&#xA;I understand you can approximate an integral using importance sampling, but I didn't follow how it applies to the rendering equation. Please could you describe how this works in greater detail?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$E[f(x)]=\int f(x)p(x) = \int f(x)\cfrac{p(x)}{q(x)}q(x) \approx \cfrac{1}{n}\sum \limits_{i=1}^n  f(x_i)\cfrac{p(x_i)}{q(x_i)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, where does single scattering fit into the general rendering equation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_{\text{o}}(\mathbf x,\, \omega_{\text{o}}) \,=\, L_e(\mathbf x,\, \omega_{\text{o}}) \ +\, \int_\Omega f_r(\mathbf x,\, \omega_{\text{i}},\, \omega_{\text{o}})\, L_{\text{i}}(\mathbf x,\, \omega_{\text{i}})\, (\omega_{\text{i}}\,\cdot\,\mathbf n)\, \operatorname d \omega_{\text{i}}$&lt;/p&gt;&#xA;" OwnerUserId="2457" LastEditorUserId="231" LastEditDate="2016-01-18T23:26:41.137" LastActivityDate="2016-01-21T07:44:20.010" Title="using importance sampling to reduce the error of outscattered radiance" Tags="&lt;rendering&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1920" PostTypeId="1" AcceptedAnswerId="1921" CreationDate="2016-01-19T07:19:41.533" Score="9" ViewCount="174" Body="&lt;p&gt;The paper &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt; (among others) reminds us the following assumptions about the microfacet distribution function D:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Microfacet density is positive valued&lt;/li&gt;&#xA;&lt;li&gt;Total microsurface area is at least as large as the corresponding&#xA;macrosurface’s area&lt;/li&gt;&#xA;&lt;li&gt;The (signed) projected area of the microsurface is the&#xA;same as the projected area of the macrosurface for any&#xA;direction v&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I can see why 1) a distribution density is a positive value, and intuitively believe that 2) means that the total area of sloped microfacets cannot be smaller than their projection.&lt;br&gt;&#xA;However I am not sure to understand the justification for 3). What does the third condition mean mean?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2016-01-19T13:10:44.163" Title="Reasons of the assumptions for the microfacet distribution function?" Tags="&lt;brdf&gt;&lt;distribution&gt;&lt;function&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1921" PostTypeId="2" ParentId="1920" CreationDate="2016-01-19T13:10:44.163" Score="9" Body="&lt;p&gt;It's a geometric assumption like the other two. Consider a flat macrosurface. Its projected area in any direction $v$ is just $v\dot\ \hat N$ times its area (where $\hat N$ is the surface normal). In particular, the case where you're looking at it along the normal is simplest: the projected area is equal to the area of the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now split the macrosurface into microfacets. The total area of the microfacets is at least as much (assumption 2), but each 'kink' in the surface bends the normals of the separate microfacets away from the original normal. Whatever the shape of the microfacets, the sum of their projected areas doesn't change. In the case where you're looking along the normal, it's easy to see that the total projected area is the same: the surface would have to get larger or smaller for it to change.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For any direction, the microfacet has to cover a portion of the original projected area of the surface. Changing the orientation of the microfacet while still filling that portion doesn't change its projected area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's one tricky case, which is where the microfacets overhang each other. In this case, the total area is greater, because some area is covered by more than one microfacet. But in this case, at least one of the microfacets has to end up pointing away from the view direction, back into the surface. In this case, the dot product is negative, so this cancels out the area covered by more than one microfacet. This is why the text is careful to single out that it's the &lt;strong&gt;signed&lt;/strong&gt; projected area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's one more tricky case, which is where the microfacets extend past the silhouette of the object. This might happen when you're looking from very glancing angles, or where overhanging facets overhang outside the perimeter of the surface. In this case, the projected area of the microfacets will be greater, violating the third assumption. We don't generally consider this case. Intuitively, it matches up with the fact that techniques like bump-mapping don't change the shape of the silhouette of the object.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-01-19T13:10:44.163" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1922" PostTypeId="5" CreationDate="2016-01-19T13:12:59.820" Score="0" Body="" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-01-19T13:12:59.820" LastActivityDate="2016-01-19T13:12:59.820" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1923" PostTypeId="4" CreationDate="2016-01-19T13:12:59.820" Score="0" Body="This tag is scheduled for deletion. It is not to be used." OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-01-19T13:12:59.820" LastActivityDate="2016-01-19T13:12:59.820" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1924" PostTypeId="1" CreationDate="2016-01-19T22:34:16.603" Score="5" ViewCount="279" Body="&lt;p&gt;I wrote a ray tracer that implements various BRDF models (Oren Nayar, Lamber, Torrance Sparrow and so on). &#xA;Now I'm trying to implement a BRDF from measured data.&#xA;I choose the Cornell database data available here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.graphics.cornell.edu/online/measurements/reflectance/spraypaints/index.html&quot; rel=&quot;nofollow&quot;&gt;http://www.graphics.cornell.edu/online/measurements/reflectance/spraypaints/index.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to use them because there's a representation of the data as spectrum with 31 sample (my ray tracer use spectral data for light calculation and then convert them to CIE XYZ and then RGB values for the final image rendering).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Which is the correct way to use this data?&lt;/li&gt;&#xA;&lt;li&gt;Which sample technique must be used? &lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Why phi_out has all negative value?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Can I calculate phi_out using the same approximation as the one I used in Oren Nayar, so ||View - Normal * (View.dot(normal)||&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2237" LastEditorUserId="2237" LastEditDate="2016-01-23T00:14:44.033" LastActivityDate="2016-01-23T00:14:44.033" Title="Ray tracing - BRDF using Cornell measured spectral data" Tags="&lt;raytracing&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1925" PostTypeId="2" ParentId="1845" CreationDate="2016-01-20T05:42:51.430" Score="3" Body="&lt;p&gt;Yes, it's a meaningful stat: GPUs have dedicated triangle setup HW and the rate is measured in triangles/GPU clock. According to white papers available on NV's website, the 680 (Kepler) could issue one triangle per SM every other clock - with 8 SMs, this yielded 4 triangles/clock. The Maxwell white paper doesn't indicate a change in this rate per SM - the 980 has 16 SMs so, if there is really is no rate change per SM, it can produce 8 triangles/clock. While the 980 has 2048 CUDA cores, the 950 has 768, implying 6 SMs and 3 triangles/clock. The chip runs around 1 Ghz, so the 950 is probably limited to 3 billion triangles per second.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-01-23T03:16:54.280" LastActivityDate="2016-01-23T03:16:54.280" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1926" PostTypeId="2" ParentId="1924" CreationDate="2016-01-20T06:15:29.523" Score="3" Body="&lt;p&gt;The MATLab data file has 3 arrays&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Input vector - aka, the light source (In Cartesian coordinates)&lt;/li&gt;&#xA;&lt;li&gt;Output vector - aka, the eye (Also in Cartesian coordinates)&lt;/li&gt;&#xA;&lt;li&gt;Spectral data (spectral data is discretized into 31 bins)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So input[n], with output[n] results in spectral[n]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ASTM file is a flattened version of the MATLab data file, with one major difference: the input and output vectors are in spherical coordinates, specifically the traditional physics notation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yQqTA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yQqTA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The data is defined in the following range:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For input vector, $\theta$ (theta) varies from $0$ to $\frac{\pi}{2}$, and $\phi$ (phi) is always a constant $0$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output vectors are uniformally distributed across the hemisphere. Since $\phi$ is periodic on $2\pi$, mathematically you can define the bounds of $\phi$  in an infinite number of ways. In this data set they chose:&#xA;$$\phi = [-\pi, \pi]$$&#xA;but it would be perfectly fine to choose&#xA;$$\phi = [0, 2\pi]$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, in order to use the data:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Since the input vectors only vary over a quarter circle ($\theta = [0, \frac{\pi}{2}]$ and $\phi = 0$), not the whole hemisphere, you will need to find the matrix transform that transforms your input vector to the quarter circle.&lt;/li&gt;&#xA;&lt;li&gt;Apply the same transform to the output vector.&lt;/li&gt;&#xA;&lt;li&gt;Using the transformed input and output vectors, look up the spectral response of the BRDF.&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I'm not sure of the best way to do this. I defer to others' opinions. I'm sure there is some kind of data structure / algorithm to do the search.&lt;/li&gt;&#xA;&lt;li&gt;The naive way would be to do a O(n) search of all the input and output directions to find the two or three that are closest, then LERP between them.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Use the spectral values as the BRDF in the rendering equation&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2016-01-20T06:21:05.277" LastActivityDate="2016-01-20T06:21:05.277" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1927" PostTypeId="1" CreationDate="2016-01-20T18:38:14.507" Score="2" ViewCount="93" Body="&lt;p&gt;I'm using NASA WorldWind to place a rectangle on the Earth ('sphere'). When I drag the rectangle on the sphere, the rectangle changes shape and size but the dimensions should be preserved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is needed to preserve the rectangle's original dimensions when it is dragged along the Earth/sphere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like most of the code in use was copied from this example: &lt;a href=&quot;http://worldwind31.arc.nasa.gov/svn/trunk/WorldWind/src/gov/nasa/worldwind/util/BasicDragger.java&quot; rel=&quot;nofollow&quot;&gt;http://worldwind31.arc.nasa.gov/svn/trunk/WorldWind/src/gov/nasa/worldwind/util/BasicDragger.java&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The line of code in the example that confuses me the most is&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double y = event.getMouseEvent().getComponent().getSize().height -&#xA;                                       this.dragRefObjectPoint.y + dy - 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The resulting behavior is the 'rectangle' that is mapped to the globe changes shape and size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also want to point out my experience with computer graphics and NASA worldwind are limited. I'm especially rusty on linear algebra and very weak with geomtery. I'd appreciate suggestions on resources (outside of the obvious NASA WorldWind reference).&lt;/p&gt;&#xA;" OwnerUserId="2506" LastEditorUserId="2506" LastEditDate="2016-01-21T15:39:20.490" LastActivityDate="2016-01-21T15:39:20.490" Title="Slide a rectangle along a sphere" Tags="&lt;rendering&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1928" PostTypeId="1" CreationDate="2016-01-20T22:21:47.147" Score="5" ViewCount="224" Body="&lt;p&gt;I've set up a test project for learning Metal on iOS to do some rendering, but I'm a bit stumped on how to get a prism rotating correctly about its y axis. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the prism rendered without depth testing so all sides can be seen, so it looks like this part is at least correct:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Tz8CE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Tz8CE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These are the vertices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static const float vertexData[] = {&#xA;     0.f,  1.f,  0.5f,&#xA;     1.f, -1.f,  0.f,&#xA;    -1.f, -1.f,  0.f,&#xA;&#xA;     0.f,  1.f,  0.5f,&#xA;     1.f, -1.f,  1.f,&#xA;     1.f, -1.f,  0.f,&#xA;&#xA;     0.f,  1.f,  0.5f,&#xA;    -1.f, -1.f,  1.f,&#xA;     1.f, -1.f,  1.f,&#xA;&#xA;     0.f,  1.f,  0.5f,&#xA;    -1.f, -1.f,  0.f,&#xA;    -1.f, -1.f,  1.f&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, when I turn on rotation, this is what happens:&#xA;&lt;a href=&quot;https://www.dropbox.com/s/esg41j3ibncofox/prism_rotate.mov?dl=0&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.dropbox.com/s/esg41j3ibncofox/prism_rotate.mov?dl=0&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(The video has depth testing turned on). Why is the prism clipping like that (and/or &lt;em&gt;what&lt;/em&gt; is it clipping through)? And it's not rotating about it's centre.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are how the MVP matrices are being calculated:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static simd::float3 viewEye = {0.f, 0.f, -2.f};&#xA;static simd::float3 viewCenter = {0.f, 0.f, 1.f};&#xA;static simd::float3 viewUp = {0.f, 1.f, 0.f};&#xA;static float fov = 45.f;&#xA;&#xA;CGSize size = self.view.bounds.size;&#xA;Uniforms *uniforms = (Uniforms *)[uniformBuffer contents];&#xA;uniforms-&amp;gt;view = AAPL::lookAt(viewEye, viewCenter, viewUp);&#xA;uniforms-&amp;gt;projection = AAPL::perspective_fov(fov, size.width, size.height, 0.1f, 100.f);&#xA;&#xA;uniforms-&amp;gt;model = AAPL::translate(0.f, 0.f, 12.f) * AAPL::rotate(tAngle, 0.f, 1.f, 0.f);&#xA;tAngle += 0.5f;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;transform&lt;/code&gt;, &lt;code&gt;lookAt&lt;/code&gt;, &lt;code&gt;rotate&lt;/code&gt;, and &lt;code&gt;perspective_fov&lt;/code&gt; functions are lifted straight from Apple sample code I used as reference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef struct {&#xA;    float4 pos [[ position ]];&#xA;    half4 color;&#xA;    float mod;&#xA;} VertexOut;&#xA;&#xA;vertex VertexOut basic_vertex(const device packed_float3* vertex_array [[ buffer(0) ]],&#xA;                              const device packed_float3* colors [[ buffer(1) ]],&#xA;                              constant Uniforms&amp;amp; uniform [[ buffer(2) ]],&#xA;                              uint vid [[ vertex_id ]],&#xA;                              uint iid [[ instance_id ]])&#xA;{&#xA;    float4 v = float4(vertex_array[vid], 1.f);&#xA;    float4x4 mvp_matrix = uniform.projection * uniform.view * uniform.model;&#xA;&#xA;    VertexOut out;&#xA;    out.pos = v * mvp_matrix;&#xA;    uint colorIndex = vid / 3;&#xA;    out.color = half4(half3(colors[colorIndex]), 1.f);&#xA;    return out;&#xA;}&#xA;&#xA;fragment half4 basic_fragment(VertexOut f [[ stage_in ]]) {&#xA;    return f.color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any help/tips would be appreciated!&lt;/p&gt;&#xA;" OwnerUserId="2507" LastEditorUserId="127" LastEditDate="2016-01-21T06:22:40.970" LastActivityDate="2016-01-21T06:22:40.970" Title="Why is rotating this prism in iOS Metal not rendering correctly?" Tags="&lt;shader&gt;&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1929" PostTypeId="2" ParentId="1928" CreationDate="2016-01-21T00:41:04.463" Score="3" Body="&lt;p&gt;The problem was in the shader, and I had the order of multiplication wrong with the MVP matrix. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So this: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;out.pos = v * mvp_matrix;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;should be: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;out.pos = mvp_matrix * v;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For whatever reason, I'm used to dealing with row vectors and had myself convinced the problem was due to the matrices themselves and the clip region..&lt;/p&gt;&#xA;" OwnerUserId="2507" LastActivityDate="2016-01-21T00:41:04.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1930" PostTypeId="2" ParentId="1916" CreationDate="2016-01-21T06:38:18.427" Score="3" Body="&lt;p&gt;I would exclude (A) for the following reasons:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;In any modern ray-tracer, the acceleration structure (BVH, k-d tree, etc) holding your geometry is the primary source of culling. The final list of primitives to trace for a given ray may include non-visible triangles, but ideally there should be very few with good acceleration structures.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Ray tracers support many more primitives than just triangles. (How do you back-face cull a sphere?)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The following problems with back-face culling in general are also more relevant to ray tracing:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Transparent materials (such as glass) will make certain objects render incorrectly with back-face culling applied.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Non-closed meshes (like plants) need to render the back-facing triangles.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="197" LastActivityDate="2016-01-21T06:38:18.427" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1931" PostTypeId="2" ParentId="1919" CreationDate="2016-01-21T07:44:20.010" Score="2" Body="&lt;p&gt;In general, the idea of importance sampling is to distribute samples in a way that matches the function being integrated (or more practically, matching some factor in it). This reduces the variance of the output values, allowing the Monte Carlo integration to converge faster.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In volume scattering, when a medium is homogeneous, we have the &lt;a href=&quot;https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law&quot; rel=&quot;nofollow noreferrer&quot;&gt;Beer–Lambert law&lt;/a&gt;, which states that the transmittance falls off exponentially with depth. That's the source of factors like $e^{-\sigma x}$ in those equations. So when raymarching through a medium, the regions closer to the start of the ray generally contribute more light to the output, while the farther regions have more of their light absorbed along the way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if you sample points along the ray from an &lt;a href=&quot;https://en.wikipedia.org/wiki/Exponential_distribution&quot; rel=&quot;nofollow noreferrer&quot;&gt;exponential distribution&lt;/a&gt;, the samples cluster toward the closer, more important regions. Then you just have to evaluate the scattering at those points and average over them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, importance sampling in the context of &lt;em&gt;surface&lt;/em&gt; scattering is explained pretty well by &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1667/48&quot;&gt;this answer&lt;/a&gt; to another question.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;On your second question, &quot;where does single scattering fit into the general rendering equation?&quot;, well, it doesn't! What people call the &quot;general rendering equation&quot; actually only includes surface scattering, not volume scattering. So it's not really that &quot;general&quot;. A general rendering equation for volume scattering might look something like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \nabla_\omega \, L(x, \omega) = \sigma_e(x) L_e(x, \omega) - \sigma_t(x) L(x, \omega) + \sigma_s(x) \int p(\omega, \omega') \, L(x, \omega') \, d\omega' $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This states that the derivative of radiance as you move along a ray is given by the sum of emitted light from the volume, minus extinction, plus in-scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To combine surface and volume scattering, we usually just say that the surface version of the equation applies at points on surfaces, and the volume version applies everywhere else.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-01-21T07:44:20.010" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1932" PostTypeId="2" ParentId="1927" CreationDate="2016-01-21T12:07:46.430" Score="1" Body="&lt;p&gt;If I understand you correctly, the problem could be defined as the (edge) intersection of a cube with a sphere. In that case, you could shade the edges by calculating the distance to the edges of the cube.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//note: from http://iquilezles.org/www/articles/distfunctions/distfunctions.htm&#xA;float udBox( vec3 p, vec3 b )&#xA;{&#xA;  return length(max(abs(p)-b,0.0));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Aligning the cube poses another &quot;interesting&quot; issue - you probably want to use the sphere-normal and screen-up to generate a basis.&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2016-01-21T12:07:46.430" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1933" PostTypeId="2" ParentId="1912" CreationDate="2016-01-21T12:20:38.830" Score="3" Body="&lt;p&gt;Based on the comment of &quot;ratchet freak&quot; I researched Transform Feedback Buffers and solved my problem that way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I now generate the simulated points on the CPU and put them into a VertexBufferObject.&#xA;I generate a second VBO for the points (along with some others for velocity).&#xA;The connectivity of the cloth is given as an vertex-attribute in ivec4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the transform feedback buffers and a Double-buffering trick using the two VBOs i can always read from the last step (using the connectivity info) and write to another buffer. This is in order to solve problems with concurrency. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The calculations are done in the vertex-shader as GL_POINTS.&#xA;Binding the output of the first shader into another regular shader using additional index-buffer to generate triangles I can without trouble render the cloth any way I want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This idea follows the transform feedback buffer example made in the book &quot;OpenGL Superbible&quot; &lt;a href=&quot;http://www.openglsuperbible.com/&quot; rel=&quot;nofollow&quot;&gt;http://www.openglsuperbible.com/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-01-21T12:20:38.830" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1934" PostTypeId="1" AcceptedAnswerId="3628" CreationDate="2016-01-21T13:11:14.720" Score="5" ViewCount="2791" Body="&lt;p&gt;I am currently looking into &lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/master/specification/README.md&quot; rel=&quot;nofollow&quot;&gt;glTF&lt;/a&gt; to use as a transfer format for my WebGL project. I already have the geometries I wish to render on my WebGL client available as preprocessed vertex and index buffers (and color buffers, but let's ignore them for now).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[       // vertex buffer&#xA;  0,0,0,&#xA;  0,1,0,&#xA;  1,0,0,&#xA;  1,1,0,&#xA;]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And to draw simple &lt;code&gt;LINES&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[       // index buffer&#xA;  0,2,&#xA;  2,4,&#xA;  4,0,&#xA;  0,1,&#xA;  1,4,&#xA;]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I wonder how to create glTF files containing these buffers? Is this possible?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to avoid using COLLADA and &lt;a href=&quot;https://github.com/KhronosGroup/glTF/wiki/converter&quot; rel=&quot;nofollow&quot;&gt;COLLADA2GLTF&lt;/a&gt; as this would only add an additional step and might just bloat the resulting glTF files.&lt;/p&gt;&#xA;" OwnerUserId="361" LastEditorUserId="231" LastEditDate="2016-06-18T11:19:39.657" LastActivityDate="2017-11-29T22:03:23.673" Title="Is it possible to create minimal glTF files with vertex and index buffers?" Tags="&lt;webgl&gt;&lt;vertex-buffer-object&gt;&lt;gltf&gt;&lt;buffers&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1935" PostTypeId="1" AcceptedAnswerId="1938" CreationDate="2016-01-21T17:47:18.833" Score="5" ViewCount="227" Body="&lt;p&gt;Is it possible that low pass filtering can be applied to Ray tracing ? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My guess is that since after the algorithm runs we have an image then low pass filtering helps in order to prevent aliasing from happening. Yet, I am not sure about this. Can someone elaborate on that?&lt;/p&gt;&#xA;" OwnerUserId="2214" LastActivityDate="2016-01-22T14:28:31.440" Title="Low Pass filtering" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1936" PostTypeId="2" ParentId="1935" CreationDate="2016-01-22T06:19:21.960" Score="5" Body="&lt;p&gt;David Kuri's answer yields a modern approach, but a simple-to-implement solution is to explicitly supersample with jittering. Classic paper: &lt;a href=&quot;http://www.cs.cmu.edu/afs/cs/academic/class/15869-f11/www/readings/cook86_sampling.pdf&quot; rel=&quot;nofollow&quot;&gt;http://www.cs.cmu.edu/afs/cs/academic/class/15869-f11/www/readings/cook86_sampling.pdf&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-01-22T14:28:31.440" LastActivityDate="2016-01-22T14:28:31.440" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1937" PostTypeId="1" CreationDate="2016-01-22T06:50:48.907" Score="3" ViewCount="785" Body="&lt;p&gt;I'm currently working working on a unbiased path tracer. To test how accurate it is. I created a scene in my path tracer and LuxRender then compare the rendered image. I found that the shadow in the image that my path tracer rendered is too dark. Why? Any possible reason?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I have implemented Gamma 2.2 in my renderer. So it won't be the issue of gamma correction. And, recursive path tracing IS enabled. both image are rendered in global illumination.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are the rendering result from LuxRender and my own renderer.(Please ignore the back triangle(light source) in Lux. It's how Lux behaves.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;---- Edit ----&lt;br&gt;&#xA;Edit: Here are the trace() function(get radiance)&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c++ prettyprint-override&quot;&gt;&lt;code&gt;float4 Renderer::trace(Ray ray, Scene* scene)&#xA;{&#xA;    const int BOUNCE_DEPTH = getBounceDepth();&#xA;    //Russian roulette: starting at depth 5&#xA;    const int RUSSIAN_ROULETTE_START_DEPTH = 16;&#xA;    const float FACTOR_CUT_OFF = 1e-5;&#xA;&#xA;    float4 factor(1.0f,1.0f,1.0f,1.0f);&#xA;    float4 renderedColor;&#xA;    Ray currentRay = ray;&#xA;    float4 lastNormal = ray.direction;&#xA;    float rrFactor = 1.0f;&#xA;&#xA;    for(int i=0;i&amp;lt;BOUNCE_DEPTH||BOUNCE_DEPTH &amp;lt; 0;i++)//To ignore bounce limit. set bounceDepth to -1&#xA;    {&#xA;        if(i &amp;gt;= RUSSIAN_ROULETTE_START_DEPTH)&#xA;        {&#xA;            const float stopProbability = 0.1f;&#xA;            if(((float)rand()/RAND_MAX) &amp;lt; (1.0-stopProbability))&#xA;                break;&#xA;            vrrFactor *= 1.0f/(1.0f-stopProbability);&#xA;            //cout &amp;lt;&amp;lt; rrFactor &amp;lt;&amp;lt; endl;&#xA;        }&#xA;&#xA;        //stop bouncing if factor is too small.&#xA;        //This is a biased method. Remove this if you want unbiased rendering&#xA;        if(factor.x + factor.y + factor.z &amp;lt;= FACTOR_CUT_OFF)&#xA;            break;&#xA;&#xA;        RayHit hit = acclerator-&amp;gt;raycast(currentRay);&#xA;        if(hit.distance &amp;gt; 0)&#xA;        {&#xA;            int index = hit.index;&#xA;            Triangle emit(scene-&amp;gt;emitColor[scene-&amp;gt;indices[index*3]],&#xA;                scene-&amp;gt;emitColor[scene-&amp;gt;indices[index*3+1]],&#xA;                scene-&amp;gt;emitColor[scene-&amp;gt;indices[index*3+2]]);&#xA;            Triangle triangle(scene-&amp;gt;vertices[scene-&amp;gt;indices[index*3]],&#xA;                scene-&amp;gt;vertices[scene-&amp;gt;indices[index*3+1]],&#xA;                scene-&amp;gt;vertices[scene-&amp;gt;indices[index*3+2]]);&#xA;            Triangle reflectColor(scene-&amp;gt;reflectColor[scene-&amp;gt;indices[index*3]],&#xA;                scene-&amp;gt;reflectColor[scene-&amp;gt;indices[index*3+1]],&#xA;                scene-&amp;gt;reflectColor[scene-&amp;gt;indices[index*3+2]]);&#xA;&#xA;            //if(i &amp;gt; 1)//Only collect indirect lighting&#xA;            renderedColor += factor*emit.interpolation(hit.u,hit.v)*rrFactor;&#xA;            factor *= reflectColor.interpolation(hit.u,hit.v);&#xA;&#xA;            //randomly sample on a hemisphere&#xA;            Ray reflecRay;&#xA;            reflecRay = createRandomReflect(currentRay, triangle,&#xA;                currentRay.origin + normalize(currentRay.direction)*hit.distance);&#xA;&#xA;            float4 triangleNormal = triangle.normal();&#xA;            if(dot(triangleNormal,currentRay.direction) &amp;lt; 0)&#xA;                triangleNormal = -triangleNormal;&#xA;&#xA;            currentRay = reflecRay;&#xA;            lastNormal = triangle.normal();&#xA;            if(dot(currentRay.direction,lastNormal) &amp;lt; 0)&#xA;                lastNormal = -lastNormal;&#xA;            factor *= dot(normalize(currentRay.direction),lastNormal);//Difduse BRDF&#xA;&#xA;    }&#xA;    else&#xA;        break;&#xA;    }&#xA;&#xA;    return renderedColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the render() function (generate image)&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c++ prettyprint-override&quot;&gt;&lt;code&gt;void Renderer::render(Scene* scene)&#xA;{&#xA;    //srand(5000);&#xA;    memset(frameBuffer,0,bufferWidth*bufferHeight*sizeof(float4));&#xA;    int pixelCount = bufferWidth*bufferHeight;&#xA;&#xA;    high_resolution_clock::time_point t1 = high_resolution_clock::now();&#xA;&#xA;    int renderIndex = 0;&#xA;&#xA;    acclerator-&amp;gt;setScene(scene);&#xA;    acclerator-&amp;gt;build();&#xA;&#xA;    const int SAMPLE_NUM = getSampleNum();&#xA;&#xA;    float4 origin = scene-&amp;gt;camera.position&#xA;        + 2.0f*scene-&amp;gt;camera.right/(float)scene-&amp;gt;camera.width&#xA;        + 2.0f*scene-&amp;gt;camera.up/(float)scene-&amp;gt;camera.height;&#xA;&#xA;    #pragma omp parallel for schedule(dynamic)&#xA;    for(int i=0;i&amp;lt;pixelCount;i++)&#xA;    {&#xA;        float4 renderedColor = float4(0.0f,0.0f,0.0f,0.0f);&#xA;        //Create camera ray&#xA;        int x = i % bufferWidth;&#xA;        int y = i / bufferWidth;&#xA;&#xA;        float4 rayVec = (x/(float)scene-&amp;gt;camera.width-0.5f)*scene-&amp;gt;camera.right*scene-&amp;gt;camera.pixelAspectRatio&#xA;            + (0.5f-y/(float)scene-&amp;gt;camera.height)*scene-&amp;gt;camera.up&#xA;            + scene-&amp;gt;camera.direction;&#xA;        for(int j=0;j&amp;lt;SAMPLE_NUM;j++)&#xA;        {&#xA;            Ray ray(origin, rayVec);&#xA;            renderedColor += trace(ray,scene);&#xA;        }&#xA;        renderedColor /= (float)SAMPLE_NUM;&#xA;&#xA;        //simple gamma correction&#xA;        const float gamma = 2.2;&#xA;        const float inversedGamma = 1.0f/gamma;&#xA;        float4 correctedColor = pow(renderedColor,float4(inversedGamma,inversedGamma,inversedGamma,0));&#xA;        ((float4*)frameBuffer)[i] = correctedColor;&#xA;&#xA;&#xA;        #pragma omp atomic&#xA;            renderIndex++;&#xA;&#xA;        #pragma omp critical&#xA;        if(renderIndex%500 == 0)&#xA;            cout &amp;lt;&amp;lt; &quot;Rendering &quot; &amp;lt;&amp;lt; renderIndex &amp;lt;&amp;lt; &quot;/&quot; &amp;lt;&amp;lt; pixelCount &amp;lt;&amp;lt; &quot;. &quot; &amp;lt;&amp;lt; (float)renderIndex*100.0/pixelCount &amp;lt;&amp;lt; &quot;\r&quot;;&#xA;    }&#xA;&#xA;    high_resolution_clock::time_point t2 = high_resolution_clock::now();&#xA;    double elapsed = duration_cast&amp;lt;duration&amp;lt;double&amp;gt;&amp;gt;( t2 - t1 ).count();&#xA;    cout &amp;lt;&amp;lt; endl &amp;lt;&amp;lt; &quot;elapsed: &quot; &amp;lt;&amp;lt; elapsed &amp;lt;&amp;lt; &quot; ,&quot; &amp;lt;&amp;lt; pixelCount*SAMPLE_NUM/elapsed/1000/1000 &amp;lt;&amp;lt; &quot; MSamples/s&quot;&amp;lt;&amp;lt; endl;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;---- End Edit ----&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Scene Rendered by LuxRender (PBRT gives me the same result)&lt;br&gt;&#xA;Renderer: Sampler, Sampler : metropolis, (Other settings are defalut)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/tsd5v.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tsd5v.png&quot; alt=&quot;Scene Rendered by LuxRender&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same scene rendered my by renderer. Note the scene is a bit darker and shadow is way too dark.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/A2knm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A2knm.png&quot; alt=&quot;Same Scene rendered my by renderer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="2448" LastEditDate="2016-01-22T15:12:34.297" LastActivityDate="2016-01-28T13:24:04.733" Title="Shadow appears to be too dark in my ray tracer" Tags="&lt;raytracing&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1938" PostTypeId="2" ParentId="1935" CreationDate="2016-01-22T10:47:42.003" Score="10" Body="&lt;p&gt;Low-pass filtering is a classic tool from signal theory that will effectively remove noise, as you suggested, but will also cancel out desired high-frequency information in the image such as sharp edges. The image will look blurry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Post-filtering Monte Carlo rendering results is an open field of research and many advances have been made over the years, and overview of which can be found in the &lt;em&gt;Denoising Your Monte Carlo Renders: Recent Advances in Image-Space Adaptive Sampling and Reconstruction&lt;/em&gt; SIGGRAPH Course &lt;a href=&quot;http://cgg.unibe.ch/publications/denoising-your-monte-carlo-renders&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="385" LastActivityDate="2016-01-22T10:47:42.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1939" PostTypeId="1" AcceptedAnswerId="1968" CreationDate="2016-01-22T13:10:24.747" Score="3" ViewCount="926" Body="&lt;p&gt;I writing the this video process app which requires the each video frame to be processed such that parts of the video are enlarged. As a reference, one of the snapchat lens filter enlarges the eyes of a person in the video. This is the exact effect I want to achieve. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I achieve this effect?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Update:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have attached an example of eye enlargement from the web.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XESgE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XESgE.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2520" LastEditorUserId="2520" LastEditDate="2016-01-23T04:52:36.790" LastActivityDate="2016-01-26T15:37:28.180" Title="How enlarge parts of a video like snapchat lens filter" Tags="&lt;image-processing&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1940" PostTypeId="1" CreationDate="2016-01-22T14:41:41.680" Score="1" ViewCount="32" Body="&lt;p&gt;I'm drawing a contour map representing gravity. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each point on the screen (1 pixel per point) I calculate the gravitational pull for each object and combine (using Newtons law of universal gravitation) where M1 is a unit point mass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next I get the min and max values and create a palette of 10 colors scaled over this range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I then generate a texture from this data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For resolutions such as 1024 * 768 or greater this is expensive (takes &gt; 1sec)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to be able to move the masses and see the contour map change in real time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any suggestions on how to optimise?&lt;/p&gt;&#xA;" OwnerUserId="2524" LastActivityDate="2016-01-22T14:41:41.680" Title="Optimise drawing contour maps representing gravity" Tags="&lt;optimisation&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1941" PostTypeId="2" ParentId="96" CreationDate="2016-01-22T14:59:56.743" Score="9" Body="&lt;p&gt;There are several offerings by GPU vendors like AMD's &lt;a href=&quot;http://developer.amd.com/tools-and-sdks/opencl-zone/codexl/&quot; rel=&quot;noreferrer&quot;&gt;CodeXL&lt;/a&gt; or NVIDIA's &lt;a href=&quot;https://www.nvidia.com/object/nsight.html&quot; rel=&quot;noreferrer&quot;&gt;nSight&lt;/a&gt;/&lt;a href=&quot;https://developer.nvidia.com/linux-graphics-debugger&quot; rel=&quot;noreferrer&quot;&gt;Linux GFX Debugger&lt;/a&gt; which allow stepping through shaders but are tied to the respective vendor's hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let me note that, although they are available under Linux, I always had very little success with using them there. I can't comment on the situation under Windows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The option which I have come to use recently, is to modularize my shader code via &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/100/sharing-code-between-multiple-glsl-shaders&quot;&gt;&lt;code&gt;#includes&lt;/code&gt;&lt;/a&gt; and restrict the included code to a common subset of GLSL and C++&amp;amp;&lt;a href=&quot;http://glm.g-truc.net&quot; rel=&quot;noreferrer&quot;&gt;glm&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I hit a problem I try to reproduce it on another device to see if the problem is the same which hints at a logic error (instead of a driver problem/undefined behavior). There is also the chance of passing wrong data to the GPU (e.g. by incorrectly bound buffers etc.) which I usually rule out either by output debugging like in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/101&quot;&gt;cifz answer&lt;/a&gt; or by inspecting the data via &lt;a href=&quot;https://apitrace.github.io/&quot; rel=&quot;noreferrer&quot;&gt;apitrace&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it is a logic error I try to rebuild the situation from the GPU on CPU by calling the included code on CPU with the same data.&#xA;Then I can step through it on CPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Building upon the modularity of the code you can also try to write unittest for it and compare the results between a GPU run and a CPU run. However, you have to be aware that there are corner cases where C++ might behave differently than GLSL, thus giving you false positives in these comparisons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, when you can't reproduce the problem on another device, you can only start to dig down where the difference comes from. Unittests might help you to narrow down where that happens but in the end you will probably need to write out additional debug information from the shader like in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/101&quot;&gt;cifz answer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And to give you an overview here is a flowchart of my debugging process:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/S1jUQ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S1jUQ.png&quot; alt=&quot;Flow chart of the procedure described in the text&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To round this off here is a list of random pros and cons:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;pro&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;step through with usual debugger&lt;/li&gt;&#xA;&lt;li&gt;additional (often better) compiler diagnostics&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;con&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;subtle differences in some mathematic primitives (e.g. &lt;a href=&quot;https://stackoverflow.com/questions/31915601/pow1-inf-nan&quot;&gt;different return values in corner cases&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;additional code to reproduce call environment on CPU&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2521" LastEditorUserId="2521" LastEditDate="2016-01-26T11:23:57.880" LastActivityDate="2016-01-26T11:23:57.880" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1943" PostTypeId="2" ParentId="1939" CreationDate="2016-01-22T16:25:27.713" Score="1" Body="&lt;p&gt;In a post processing step instead of sampling the origin pixel directly from where the target pixel is you instead sample the origin pixel slightly offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where you get the offset can differ. For example you could provide an extra texture with the offsets encoded in the red and green channels.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-01-22T16:25:27.713" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1945" PostTypeId="1" AcceptedAnswerId="1946" CreationDate="2016-01-22T19:21:10.987" Score="1" ViewCount="711" Body="&lt;p&gt;In a ray tracer, given a point on a sphere (point_of_intersection with a ray) and its normal for that point (point_of_intersection - center_of_sphere) &lt;strong&gt;how do I calculate the tangent space for that point? Do I need other data to calculate the tangent space?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="2237" LastActivityDate="2016-01-22T20:41:40.293" Title="Ray tracing - tangent space for a point on a sphere" Tags="&lt;raytracing&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1946" PostTypeId="2" ParentId="1945" CreationDate="2016-01-22T20:15:57.553" Score="3" Body="&lt;p&gt;The tangent space is spanned by the tangent to the point and the bitangent (which is orthogonal to both tangent and normal).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you need to calculate the tangent which is achieved by calculating the cross-product of the ray-direction and the normal. $T = N \times DIR$&#xA;The resulting vector will be orthogonal to the normal and thereby be the tangent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now calculate the cross-product of the tangent and the normal $BT = T \times N$ to create a vector orthogonal to both. This vector is the bitangent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Tangent $T$ and bitangent $BT$ span a plane which is the tangent-space of your intersection-point.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="127" LastEditDate="2016-01-22T20:41:40.293" LastActivityDate="2016-01-22T20:41:40.293" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1947" PostTypeId="1" CreationDate="2016-01-23T14:39:03.033" Score="2" ViewCount="952" Body="&lt;p&gt;For each of major vendor's latest GPU architectures, is there a clear maximum &quot;triangles/second&quot; bottleneck? If so, what is it architecturally and what is the performance?&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-01-26T00:17:15.313" Title="GPU Architecture: What are the theoretical limits on triangle throughput in modern GPUs?" Tags="&lt;gpu&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1948" PostTypeId="2" ParentId="1947" CreationDate="2016-01-23T15:42:58.707" Score="3" Body="&lt;p&gt;Your question is not that easy to answer, as there is no standard definition of what &quot;triangles/second&quot; actually means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What shading is used? What calculations are done? How are the triangles represented? This and much more has to be taken into account when looking for benchmarks on GPU-performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To actually compare the performance of GPUs you would have to look at a range of different measurements. GFlop/s and memory-speed as some basic ones, but also look at full benchmark scores (of which there are I am sure many).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are websites that compile these measurements and display them in a comparison mode. A quick search brought me to &lt;a href=&quot;http://gpuboss.com/gpus/GeForce-GTX-760-vs-GeForce-GTX-750&quot; rel=&quot;nofollow&quot; title=&quot;gpuboss.com/gpus/GeForce-GTX-760-vs-GeForce-GTX-750&quot;&gt;this page which seems to have everything needed&lt;/a&gt; (I entered an example search).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This helps to compare the performance of two GPUs but if you want to know if a specific GPU is able to do the specific thing you want it to do, that may be very hard to answer and impossible without much more knowledge about what you want to do.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Calculating the maximum performance is also very hard because I believe the GPU vendors do not share everything they do on their GPUs so it can be hard to estimate the actual performance.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="231" LastEditDate="2016-01-24T12:17:00.900" LastActivityDate="2016-01-24T12:17:00.900" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1950" PostTypeId="1" AcceptedAnswerId="1951" CreationDate="2016-01-23T22:59:21.727" Score="2" ViewCount="149" Body="&lt;p&gt;I am facing a though challange - I need to perform repetitive Image formating. Firstly, I need resize picture A so that it has some fixed width in pixels. Then, I need to place picture A in the middle of picture B. I need to perform this task repetitively for hundreds of images. Is there any way to script this, so that I can just type in for example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;perform pictureA.png pictureB.png output.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any help is more than welcome!&lt;/p&gt;&#xA;" OwnerUserId="2537" LastActivityDate="2016-01-23T23:59:51.367" Title="Is there a way to script image creation?" Tags="&lt;transformations&gt;&lt;image&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1951" PostTypeId="2" ParentId="1950" CreationDate="2016-01-23T23:59:51.367" Score="7" Body="&lt;p&gt;&lt;a href=&quot;http://www.imagemagick.org&quot;&gt;ImageMagick&lt;/a&gt; is a set of command-line tools that can do the sort of things you describe. For example, this command line will overlay picture B with a centered copy of picture A, resized to 100 pixels wide (keeping aspect ratio):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;convert pictureB.png ( pictureA.png -resize 100 ) -gravity center -composite output.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;See &lt;a href=&quot;http://www.imagemagick.org/script/command-line-processing.php&quot;&gt;the ImageMagick docs&lt;/a&gt; for more info about its command lines are structured...it's a powerful piece of software, but it takes a bit of work to get the hang of how to use it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-23T23:59:51.367" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1952" PostTypeId="1" CreationDate="2016-01-24T13:34:51.840" Score="2" ViewCount="362" Body="&lt;p&gt;Raster scan display forms an image with pixel whereas a Random scan display works with Geometric primitives, but even a geometric primitve( a line) is made up of pixels so what is the difference?&lt;/p&gt;&#xA;" OwnerUserId="2540" LastEditorUserId="2540" LastEditDate="2016-01-24T14:38:09.480" LastActivityDate="2016-01-26T18:38:52.100" Title="How is Raster and Random Scan Display different?" Tags="&lt;raster-image&gt;&lt;display-lists&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1953" PostTypeId="2" ParentId="1952" CreationDate="2016-01-24T13:51:51.840" Score="1" Body="&lt;p&gt;A raster display draws every pixel on the screen in every frame whether there is something to show or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A random scan display activates only those pixel which are occupied by an geometric primitive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So yes, they both use pixels, but the difference is in how they draw the pixels onto the screen.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-01-24T13:51:51.840" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1954" PostTypeId="1" AcceptedAnswerId="1955" CreationDate="2016-01-24T21:15:17.677" Score="10" ViewCount="799" Body="&lt;p&gt;Right now I'm trying to implement some sort of depth buffer in software and I have a huge problem when I'm writing to it. Having one mutex is absolute overkill. So I created a number of mutexes equal to the number of threads. I'm locking a mutex based on current pixel (pixel_index % mutexes_number) and this works better, but still very very slow. And I wonder how it's done in a real GPU? Is there a clever algorithm or hardware handles it?&lt;/p&gt;&#xA;" OwnerUserId="386" LastEditorUserId="5778" LastEditDate="2018-07-25T06:09:57.107" LastActivityDate="2018-07-25T06:09:57.107" Title="How updating a depth buffer works in GPU?" Tags="&lt;buffers&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1955" PostTypeId="2" ParentId="1954" CreationDate="2016-01-24T22:50:29.833" Score="10" Body="&lt;p&gt;Highly specialized hardware handles it. A typical strategy is for a GPU to tile rasterization and store depth information in compressed formats (e.g. the z-equation when a polygon completely covers a tile). This allows testing across an entire tile at once; other cool HW tricks include depth testing before the pixel shader is run (assuming conditions permit - the shader cannot write a depth value). You might consider something similar in software, such as having each thread &quot;own&quot; a subset of tiles and walk each primitive independently, or mimic multi-gpu strategies such as alternate frames or alternate raster lines.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-01-24T22:50:29.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1956" PostTypeId="2" ParentId="1954" CreationDate="2016-01-25T01:50:49.570" Score="11" Body="&lt;p&gt;In a real GPU, instead of having multiple cores trying to read/write the same region of the depth buffer and attempting to synchronize between them, the depth buffer is divided into tiles (such as 16×16 or 32×32), and each tile is assigned to a single core. That core is then responsible for all rasterization in that tile: any triangles that touch that tile will be rasterized (within that tile) by the owning core. Then there is no interference between cores, and no need for them to synchronize when accessing their part of the framebuffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This implies that triangles that touch multiple tiles will need to be rasterized by multiple cores. So, there is a work redistribution step between geometry processing (operations on vertices and triangles) and pixel processing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the geometry stage, each core might process a chunk of input primitives; then for each primitive, it can quickly determine which tiles the primitive touches (this is called &quot;coarse rasterization&quot;), and add the primitive to a queue for each core that owns one of the affected tiles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, in the pixel stage, each core can read out the list of primitives in its queue, calculate pixel coverage for the tiles the core owns, and proceed to depth testing, pixel shading and updating the framebuffer, with no need of any further coordination with other cores.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-25T01:50:49.570" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1957" PostTypeId="1" AcceptedAnswerId="1958" CreationDate="2016-01-25T06:33:01.137" Score="3" ViewCount="331" Body="&lt;p&gt;[Please (kindly) let me know if this is not the place for this question]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm hoping to learn about GPU programming, but as a college student, I've a quite limited budget.  I'm wondering whether I should buy a modestly more expensive GPU that uses GDDR5 memory, or if DDR3 memory is sufficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can see some potential pros and cons:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;GDDR5 is standard in nearly all but the lowest-end GPUs, so I'd be getting experience that would transfer to most popular cards&lt;/li&gt;&#xA;&lt;li&gt;However, is it possible that learning with DDR3 memory will only help me learn to be more efficient, thus my skills would translate (probably with a bit more difficulty) to even better programming abilities on a higher-end GPU&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Any advice or words of wisdom?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that I don't want the card for gaming purposes (although I would gladly use it in such a capacity, but that would be a happy by-product of having it around to learn to program on).  I also don't really care too much about being able to run programs faster on the GPU; I mainly want the ability to learn how to program on a GPU.  I'm currently considering only NVIDIA GPUs, as I've learned a smidgen about CUDA programming.&lt;/p&gt;&#xA;" OwnerUserId="1870" LastActivityDate="2016-01-25T07:34:55.527" Title="GDDR5 vs. DDR3 for learning GPU programming on a limited budget?" Tags="&lt;gpu&gt;&lt;memory&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1958" PostTypeId="2" ParentId="1957" CreationDate="2016-01-25T07:34:55.527" Score="3" Body="&lt;p&gt;If your goal is to learn GPU programming, it doesn't matter at all whether you have DDR3 or GDDR5 memory. The way you program it isn't going to change based on how fast the memory is. It will affect performance, but if that's not a primary consideration for you, then you don't need to worry about it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do make sure that you get a GPU that supports the latest graphics APIs (DX12 and OpenGL 4.5). I think that's essentially all GPUs made in the past 5 years or so.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-25T07:34:55.527" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1959" PostTypeId="1" CreationDate="2016-01-25T09:04:13.653" Score="10" ViewCount="2206" Body="&lt;p&gt;I'm implementing &lt;a href=&quot;http://mrl.nyu.edu/~perlin/noise/&quot; rel=&quot;noreferrer&quot;&gt;improved Perlin noise&lt;/a&gt;. Its key feature for randomisation is the hardcoded permutation table, which gives essentially random but reproducible gradients at the cells of the grid. The permutation table is just a permutation of the integers &lt;code&gt;0..255&lt;/code&gt;, and is usually the following table (copied straight from Perlin's original implementation):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;{151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7,&#xA;225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247,&#xA;120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,&#xA;88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134,&#xA;139, 48, 27, 166, 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220,&#xA;105, 92, 41, 55, 46, 245, 40, 244, 102, 143, 54, 65, 25, 63, 161, 1, 216, 80,&#xA;73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196, 135, 130, 116, 188, 159, 86,&#xA;164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123, 5, 202, 38,&#xA;147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189,&#xA;28, 42, 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101,&#xA;155, 167, 43, 172, 9, 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232,&#xA;178, 185, 112, 104, 218, 246, 97, 228, 251, 34, 242, 193, 238, 210, 144, 12,&#xA;191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107, 49, 192, 214, 31, 181,&#xA;199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254, 138, 236,&#xA;205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For reference, a small patch drawn from the noise generated by this table looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Gyuqs.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Gyuqs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I would like the code to be a bit more flexible and allow this table to be reshuffled so that I can create a completely new noise field (instead of just sampling it at a different offset). But not all permutations are equally well shuffled. In the unlikely event that the random permutation is just the sorted array from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;255&lt;/code&gt;, the noise would look like this instead:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3uC8M.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3uC8M.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's kinda bad. Of course, at a chance of $1$ in $256!$, this is not a case I need to be worried about. But surely, this is not the only permutation that yields very noticeable artefacts. Reverse sorted and almost sorted permutations would likely have the same problems. So how many other permutations are unsuitable? Say the code would be used in a popular game to generate a random world up front, it would still be annoying if every 100,000th generated world would look remotely regular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is, what exactly makes a good (or a bad) permutation table, and how do I assess the quality of a permutation table programmatically, such that I can reshuffle the table once more in the unlikely event that I roll a &quot;bad&quot; table?&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2016-01-25T09:11:09.293" LastActivityDate="2016-01-25T14:06:52.043" Title="What makes a good permutation table?" Tags="&lt;noise&gt;&lt;mathematics&gt;&lt;procedural-generation&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1960" PostTypeId="2" ParentId="1959" CreationDate="2016-01-25T11:25:51.673" Score="5" Body="&lt;p&gt;&lt;strong&gt;First of all&lt;/strong&gt; - a number must not occur twice, that is implied since we're talking about permutations. So filling the table with a simple random(255) function won't work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Secondly&lt;/strong&gt;, you need to ensure that there are no premature recurrence patterns:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the values 1,2,3,4 - the permutation table 4,3,2,1 is not a very good one because of its short cyclic properties, i.e. 1 -&gt; 4, 4 -&gt; 1. Likewise with 4,2,3,1 or 1,2,3,4. The optimal tables take you all the way through all positions: 3,1,4,2 or 2,4,1,3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This property becomes increasingly  important as you increase the number of dimensions and perform recursive lookups.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However this approach alone may create clusters of too similar values, which may or may not be wanted, which leads me to next point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Thirdly&lt;/strong&gt;, When you generate a table with the non cyclic properties, you need to step through remaining unassigned indices in a random manner. When possible constrain the random step distance here to a certain min and max range, e.g. 5..120 to avoid clustered groups of similar values. These numbers are worth experimenting with. &lt;/p&gt;&#xA;" OwnerUserId="1790" LastEditorUserId="1790" LastEditDate="2016-01-25T11:51:00.367" LastActivityDate="2016-01-25T11:51:00.367" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1961" PostTypeId="2" ParentId="1959" CreationDate="2016-01-25T13:09:10.607" Score="1" Body="&lt;p&gt;One possibility might be to borrow from the cryptographic community and, in particular, the 8-bit to 8-bit substitution used in the AES/Rijndael cipher. &#xA;The table and code to generate it &lt;a href=&quot;https://en.wikipedia.org/wiki/Rijndael_S-box&quot; rel=&quot;nofollow&quot;&gt;can be found on wikipedia.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd guess that, in order to generate up to 256 additional tables, you could just do something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Func(U8 input, U8 TableNum) = SBox( (TableNum + Sbox(input)) Mod256 )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(since the SBox function is quite non-linear)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said that, (and please forgive me if I've got some of the details wrong) in a past life I implemented Perlin noise using a relatively simple RNG/Hash function but found the correlation in X/Y/Z due to my simple mapping of 2 or 3 dimensions to a scalar value was problematic.  I found that a very simple fix was just to use a CRC, eg. &lt;em&gt;something like&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;InputToRNGHash = CRC(Z xor CRC( Y xor CRC(X))). &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Given CRCs intrinsics may be built in to CPU HW, this can be fast approach.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-01-25T14:06:52.043" LastActivityDate="2016-01-25T14:06:52.043" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1962" PostTypeId="1" AcceptedAnswerId="1964" CreationDate="2016-01-25T19:25:52.957" Score="5" ViewCount="1023" Body="&lt;p&gt;If I have a &lt;code&gt;std::vector&amp;lt;Foo&amp;gt;&lt;/code&gt; and want to store its size in a &lt;code&gt;GLuint&lt;/code&gt;, my compiler gives a warning that there is possible loss of data.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint size = vec.size(); // &quot;conversion from 'size_t' to 'GLuint', possible loss of data&quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How do I correctly do this type of casting?&#xA;Are there more pitfalls of this kind with for example &lt;code&gt;float&lt;/code&gt; to &lt;code&gt;GLfloat&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="16" LastEditDate="2016-01-25T19:31:30.200" LastActivityDate="2016-01-25T22:47:38.023" Title="Type conversion to GL-types" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;types&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1963" PostTypeId="1" CreationDate="2016-01-25T19:39:23.373" Score="8" ViewCount="269" Body="&lt;p&gt;Assume there is some value &lt;code&gt;p&lt;/code&gt;, calculated per-frame, that varies continuously over the surface of an object. The value of &lt;code&gt;p&lt;/code&gt; determines the density of some pattern on the surface. For example, in a case with only two possible densities if &lt;code&gt;p &amp;lt; 0.3&lt;/code&gt; it is high density, otherwise it is low.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've thought of a simple high-level solution: create two textures, each of different densities, and based on the value of &lt;code&gt;p&lt;/code&gt; sample from the appropriate one. However, there's a problem with the boundary between high- and low-densities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example to illustrate the problem (note my problem is NOT exclusive to this example pattern of dots. I describe the patterns I'm working with later on):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/krVHY.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/krVHY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is the threshold between low- and high- (displayed on the high density texture but that's not relevant.) If under the line, it implies the high-density texture should be sampled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6WmhA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6WmhA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally here is the comparison between what is desired and what would actually happen using this method:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DFsgY.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DFsgY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that when a high-density-only circle crosses the line, it will be ignored when &lt;code&gt;p&lt;/code&gt; indicates the low-density texture to be sampled, resulting in a truncated circle. I don't know how to solve this problem because &lt;code&gt;p&lt;/code&gt; varies every frame, so I can't just 'bake' a boundary between the two densities. It's easy to prevent the reverse problem by creating the high-density texture from the lower one (i.e. if a circle is on the low-density texture ensure it is on the high-density texture.) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm interested if anyone has a way to improve my solution or even has another method entirely. The constraint here is that &lt;code&gt;p&lt;/code&gt; is calculated per-frame in real-time. Another constraint is related to the pattern texture: the pattern is black and white, where black is the pattern and white is the background (like the circles in the example). The pattern may not just be identical shapes repeated, but any arrangement of arbitrary black shapes over a white background. (Maybe pattern is the wrong choice of word.)   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not familiar with the research in this field so I wasn't sure which keywords to search, so I'd even appreciate if anyone could point me in the right direction.&lt;/p&gt;&#xA;" OwnerUserId="31" LastEditorUserId="31" LastEditDate="2016-01-27T04:24:43.543" LastActivityDate="2016-03-14T10:32:47.963" Title="How to create a patterned object with variable pattern density in real-time?" Tags="&lt;texture&gt;&lt;shader&gt;&lt;real-time&gt;" AnswerCount="2" CommentCount="8" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1964" PostTypeId="2" ParentId="1962" CreationDate="2016-01-25T21:35:09.860" Score="6" Body="&lt;p&gt;Practically speaking, probably not - try printing the size of each type using sizeof. Probably GLuint is 32 bits and size_t is 64 bits - so 32 bits are thrown out; but float and GLfloat are probably both 32 bit IEEE 754 numbers. &quot;Probably&quot; sprinkled above, because technically speaking the sizes of C ints, floats and the float format are compiler dependent, but GL type sizes (and formats) should be standard (see &lt;a href=&quot;https://www.opengl.org/wiki/OpenGL_Type&quot;&gt;https://www.opengl.org/wiki/OpenGL_Type&lt;/a&gt;). Chances are, GLfloat is just typedef'd as a float.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may be able to turn off this warning in your compiler - I choose to explicitly cast (&quot;GLuint size = GLuint(vec.size())&quot; works) so I am reminded of what's happening.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-01-25T22:47:38.023" LastActivityDate="2016-01-25T22:47:38.023" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1965" PostTypeId="2" ParentId="1947" CreationDate="2016-01-26T00:17:15.313" Score="3" Body="&lt;p&gt;NV Maxwell: According to the NVIDIA GeForce GTX 680 white paper, each Streaming Multiprocessor (called an SMX in Kepler) in the Kepler architecture could process 1 polygon every other clock. The 680 has 8 SMX units, yielding 4 polygons/clock. The NVIDIA GeForce GTX 980 white paper only mentions that geometry performance of 980 should be double that of the 680; the 980 has twice as many Streaming Multiprocessors (called a SMM in Maxwell), implying each Maxwell SMM has the same polygon throughput per clock as a Kepler SMX. The number of SMMs in a particular GPU isn't always easy to find, but the number of cuda cores is usually publicized; since Maxwell has 128 cuda cores per SMM (there are 192 in a Kepler SMX), we can conclude that Maxwell based GPUs can handle 1 polygon/clock for each 256 cuda cores.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-01-26T00:17:15.313" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1967" PostTypeId="1" AcceptedAnswerId="1971" CreationDate="2016-01-26T14:39:09.130" Score="0" ViewCount="93" Body="&lt;p&gt;I have a video that record the drawing sequence with a pencil by a painter.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/D9UbO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/D9UbO.png&quot; alt=&quot;video screen&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to reconstruction the sequence from the video.&#xA;And I have google some keywords like &lt;em&gt;drawing sequence reconstruction&lt;/em&gt;, &lt;em&gt;sketch reconstruction&lt;/em&gt;, and have searched like &lt;em&gt;moving object detection&lt;/em&gt; but cannot found what I want to find.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know how to detect and recognize the drawing between different frames. I have thought the &lt;em&gt;line detect&lt;/em&gt; algorithm may work but fail. And pixel comparison seems to be bad idea. Because that the new drawing may overlap the old ones. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you give me some information that I can read or some keywords to search? Sorry about that because I am not familiar with Computer Image Processing.&lt;/p&gt;&#xA;" OwnerUserId="2551" LastEditorUserId="2041" LastEditDate="2016-01-27T08:58:35.977" LastActivityDate="2016-01-27T08:58:35.977" Title="reconstruction drawing sequence from video" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="1968" PostTypeId="2" ParentId="1939" CreationDate="2016-01-26T15:37:28.180" Score="2" Body="&lt;p&gt;The answer is surprisingly simple: You move the vertices of the face-geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To elaborate, the white wireframe mesh on the left of your image is placed so the geometry aligns with the photo. It is then texture-mapped with the photo, meaning that for each vertex in the mesh, a texture-coordinate is assigned (the point on the photo that should map to the vertex).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With every vertex assigned a texture-coordinate you can deform the mesh, doing ordinary texture-sampling at the interpolated texture-coordinates to have the image stretch - as if it was painted onto the head.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need to do this in realtime, you can use your graphics-card to do this; texture mapping is one of the things GPUs are really good at.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if you want to do this on a video, you need to track the facial features to continuously align the geometry to the video. This is not an easy task, but you can probably find a wealth of libraries to help you out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am a bit uncertain which of the above would be difficult, so please feel free to ask any questions.&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2016-01-26T15:37:28.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1969" PostTypeId="2" ParentId="1952" CreationDate="2016-01-26T18:25:00.073" Score="0" Body="&lt;p&gt;True random scan displays aren't used anymore. They were based on cathode-ray tubes where the electron beam wasn't driven in a scanline pattern but as arbitrary line segments, with &quot;direct access&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The early devices were similar to oscilloscopes, requiring frequent refreshing of the trace. Later appeared the memory devices, able to retain the image without refreshing, so that they could render arbitrarily complex drawings (with the drawback that modifying a part of the image wasn't possible).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They indeed didn't really suffer from jaggies, as they were analogic devices, anyway because of digital-to-analog limitations, they had a finite resolution in practice (typically 1K x 1K, a wonder at the time). They allowed monochrome line drawings only.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These dinosaurs have been superseded by digital frame buffers and raster displays. But sometimes the concepts of random scan and display list are mixed up.&lt;/p&gt;&#xA;" OwnerUserId="1703" LastEditorUserId="1703" LastEditDate="2016-01-26T18:38:52.100" LastActivityDate="2016-01-26T18:38:52.100" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1971" PostTypeId="2" ParentId="1967" CreationDate="2016-01-27T00:08:04.783" Score="2" Body="&lt;p&gt;This is more a Computer vision question I think.&#xA;I don't know how exactly you can achieve that but some ideas and keywords you may use to find additional resources:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Feature tracking of hand and pen can yield the movement of said things. Assuming you know that the camera is not moving I think that would give you good results. Related is maybe motion tracking. Any information you have about the hand and the camera can in some way be used to make more accurate estimates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Removing the hand from the video could be much harder. I don't remember that part from my lecture. We copied parts of the image onto the part we want to remove and used image metrics to make sure it fits best possible... But since the hand covers a drawing we don't know much about this could be very hard to do in an convincing way.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-01-27T00:08:04.783" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1972" PostTypeId="1" AcceptedAnswerId="1973" CreationDate="2016-01-27T03:28:11.743" Score="3" ViewCount="1261" Body="&lt;p&gt;I have been reading this paper by Timothy Wilson &lt;a href=&quot;https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/edit#slide=id.p&quot; rel=&quot;noreferrer&quot;&gt;Fast Stereo Rendering for VR&lt;/a&gt;&#xA;and it would suit our game engine (DirectX 11) to use this method of stereo rendering. I have managed to get the game rendering Instanced and the screen squished into left and right areas like he mentions but am unable to get the SV_ClipDistance working correctly, when I use his methods or the method the jMonkeyEngine uses I get 4 views of the world! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is does anyone know if you can write SV_RenderTargetArrayIndex in a pixel shader according to MSDN it says it can be read and written by the pixel shader but in all my experimentation I am unable to get the shader to compile, it complains about too many outputs. If I could get this to work the instancing would work by just setting the SV_RenderTargetArrayIndex to SV_InstanceId. Any help would be much appreciated.&lt;/p&gt;&#xA;" OwnerUserId="288" LastActivityDate="2016-01-27T07:15:21.190" Title="VR stereo rendering with Instancing" Tags="&lt;directx11&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1973" PostTypeId="2" ParentId="1972" CreationDate="2016-01-27T07:15:21.190" Score="5" Body="&lt;p&gt;While &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/bb509647%28v=vs.85%29.aspx&quot;&gt;this MSDN page&lt;/a&gt; does claim that SV_RenderTargetArrayIndex can be written in a pixel shader, I believe this is incorrect. Viewport array index and RT array index values are both intended to be output by the geometry shader stage. They can then be read by the pixel shader (and have a constant value per-primitive, based on the GS output). However, it is not possible to set these values from the pixel shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stereo instancing approach detailed in those slides is interesting precisely because it avoids using slow geometry shaders. However, if you're not using GS, you can't use multiple viewports or render target arrays. That's why the stereo instancing approach uses one large viewport and bakes each eye's viewport transform into its projection matrix, and requires clip planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clip planes should work, so if you're having problems with them, you could post another question detailing the specific issues (preferably with screenshots) and we can try to figure that out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(For completeness, note that if you're using OpenGL, the &lt;a href=&quot;https://www.opengl.org/registry/specs/AMD/vertex_shader_viewport_index.txt&quot;&gt;GL_AMD_vertex_shader_viewport_index&lt;/a&gt; extension is available on &lt;a href=&quot;http://delphigl.de/glcapsviewer/listreports2.php?listreportsbyextension=GL_AMD_vertex_shader_viewport_index&quot;&gt;recent GPUs from all three IHVs&lt;/a&gt; and allows setting the viewport index from the vertex shader.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-27T07:15:21.190" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1974" PostTypeId="1" CreationDate="2016-01-28T12:31:35.720" Score="9" ViewCount="470" Body="&lt;p&gt;How to reliably find out whether two planar Bezier curves intersect? By &quot;reliably&quot; I mean the test will answer &quot;yes&quot; only when the curves intersect, and &quot;no&quot; only when they don't intersect. I don't need to know what parameters the intersection was found at. I also would like to use floating-point numbers in the implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found several answers on StackOverflow which use the curves' bounding-boxes for the test: this is not what I'm after as such test may report intersection even if the curves don't intersect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The closest thing I found so far is the &quot;&lt;a href=&quot;http://dl.acm.org/citation.cfm?id=49188&quot; rel=&quot;nofollow&quot;&gt;bounding wedge&lt;/a&gt;&quot; by Sederberg and Meyers but it &quot;only&quot; distinguishes between at-most-one and two-or-more intersection, whereas I want to know if there is at-most-zero and one-or-more intersections.&lt;/p&gt;&#xA;" OwnerUserId="141" LastEditorUserId="141" LastEditDate="2016-01-29T09:47:24.390" LastActivityDate="2016-02-11T08:42:57.343" Title="Reliable test for intersection of two Bezier curves" Tags="&lt;computational-geometry&gt;&lt;bezier-curve&gt;&lt;cad&gt;" AnswerCount="2" CommentCount="11" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1975" PostTypeId="2" ParentId="1937" CreationDate="2016-01-28T13:15:28.897" Score="2" Body="&lt;p&gt;I don't know whether this is the only cause of your problems, but the Russian roulette is messed up for sure. stopProbability acts as the survivalProbability in your code; therefore, you compensate the estimate with a different factor than you should, which makes the result heavily biased.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would put the code as follows to make it more comprehensible:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const float survivalProbability = 0.9f;&#xA;if(((float)rand()/RAND_MAX) &amp;gt; survivalProbability)&#xA;    break;&#xA;rrFactor *= 1.0f/survivalProbability;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-01-28T13:24:04.733" LastActivityDate="2016-01-28T13:24:04.733" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1976" PostTypeId="1" AcceptedAnswerId="1977" CreationDate="2016-01-28T18:47:33.133" Score="3" ViewCount="2453" Body="&lt;p&gt;I want to ray trace a triangular mesh that I load from a file. The vertices' coordinates are expressed in the reference frame associated with the object  (i.e the mesh) and I don't know the object-to-world matrix. Is there a way to calculate this matrix given these coordinates? If no, how can I ensure that the mesh's triangles are transformed to the world's reference frame? &lt;/p&gt;&#xA;" OwnerUserId="2233" LastActivityDate="2016-01-29T03:35:00.793" Title="How to determine the object-to-world matrix" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;transformations&gt;&lt;mesh&gt;&lt;triangulation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1977" PostTypeId="2" ParentId="1976" CreationDate="2016-01-28T18:56:25.217" Score="4" Body="&lt;p&gt;No! If you dont have this info and must have a extra frame, just assume the reference frame is a identity matrix*. The point of the extra reference frame is just to be able to move the object but if you have no info about how the object should relate to other objects it does not really matter operator can move it where they want. Everything is relative, if theres no relation then no problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* choosing identity is like choosing a arbitrary constant to be 1, its numerically easy to work with.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-01-28T18:56:25.217" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1978" PostTypeId="2" ParentId="1976" CreationDate="2016-01-28T20:06:48.473" Score="2" Body="&lt;p&gt;The Object-To-World matrix is often called &quot;model-matrix&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This martix tells us how the object relates to some &quot;World&quot;. This world is relative and arbitrary but really convenient because we can place all our objects and even the camera in it and the math works out pretty well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The short answer is, that you imagine that the model is defined in the origin of the world, so that the center of gravity of the object lies exactly in the $(0.0, 0.0, 0.0)$ position of the world.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you want to place multiple objects in the same scene, you have to give them a position, and it is really convenient to give all objects a position relative to this world-origin. So you just create a matrix for each object that tells you how you move the object in relation to the world-origin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example translating an object is $\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; x \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; y \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; z \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} $ then your object will have the world-relative position of $(x, y, z)$ (I will omit the useage of homogeneous coordinates which would be better suited for another question).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a similar fashion you can use translation, scaling and rotation (take care of what order you apply these transformations)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things get a bit complicated if you want to do camera-space computations and projections and stuff like that, but in the simplest version you can just build your model-matrix this way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Multiplying each point of your model with this model-matrix gives you the position of the point in world-space (meaning relative to the origin of the world!) and for meshes this moves the whole model just as you would expect.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="2500" LastEditDate="2016-01-29T03:35:00.793" LastActivityDate="2016-01-29T03:35:00.793" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="1979" PostTypeId="1" CreationDate="2016-01-29T01:04:29.930" Score="3" ViewCount="2732" Body="&lt;p&gt;I'm a Computer Science student who's been getting into bitmaps &amp;amp; pixmaps recently. I clearly understand what pixmaps do. A pixmap, as I understand, defines each pixel individually. So, maybe I could write a pixmap filelike this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;255,0,0 0,255,0 0,0,255&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which would give me a red pixel, a green pixel, and a blue pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Seems pretty straightforward.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I fail to understand exactly how bitmaps work. I mean, I understand that a bitmap simply maps a bit to some color at some point on the screen. I watched a YouTube video on how to create a bitmap file, but the guy's explanation of what a bitmap file is went over my head.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I feel I now have a better conceptual grasp of what a bitmap is. Well, maybe not. Each bit in a bitmap corresponds to a certain color that is defined somewhere in the file. But how does the computer know which bit corresponds to which color?&lt;/p&gt;&#xA;" OwnerUserId="2572" LastEditorUserId="2572" LastEditDate="2016-01-29T01:26:15.110" LastActivityDate="2016-02-01T13:48:14.220" Title="How do I create my own bitmap using a text editor?" Tags="&lt;bitmap-graphics&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1980" PostTypeId="2" ParentId="1979" CreationDate="2016-01-29T02:57:40.227" Score="8" Body="&lt;p&gt;In addition to the pixel values, the width and height of the image are also required, and the colour depth (how many colours are available per pixel). Some formats also specify an alpha value, for transparency, which may be defined per pixel in addition to the red, green and blue components.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many different image file formats but a simple one to experiment with to gain understanding is ppm, one of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Netpbm_format&quot;&gt;Netpbm formats&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Netpbm defines the following file types:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;PBM:&lt;/strong&gt; portable bitmap (pixels are either on or off)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;PGM:&lt;/strong&gt; portable graymap (grayscale pixels)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;PPM:&lt;/strong&gt; portable pixmap (full colour pixels)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;These have the advantages of being simple to understand, and easy to generate in a text editor for working with simple examples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, a PPM file is simply the characters &quot;P3&quot; to identify it as PPM, followed by the width, height, maximum colour value and the pixel values in English reading order (left to right then top to bottom). Each pixel colour is a red value, a green value, and a blue value. All these values are space separated and human readable. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;P3                         # Indicates an ASCII PPM file&#xA;2 2                        # Width and height of the image&#xA;255                        # Maximum colour value&#xA;255 0 0     0   255 0      # A red pixel (255 0 0) followed by a green pixel&#xA;0   0 255   255 255 255    # A blue pixel followed by a white pixel&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;While this makes the format very easy to work with for small examples, it will also make the file size much larger than other formats which use bytes to represent colour components instead of writing out the human readable numbers. Many formats also include compression (either lossless or lossy).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you are accustomed to writing PPM files in ASCII characters, indicated by the file starting with &quot;P3&quot;, you can move on to PPM files using bytes, indicated by the file starting with &quot;P6&quot;. This is a similar format to what many programs use internally, but is no longer human readable in a text editor as not every byte will correspond to a printable ASCII character.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;You also mention that a pixmap can have pixel values that refer to colours stored elsewhere in the file. I have avoided this format as it is not necessary for understanding how a pixmap works. This is known as using a palette (a list of predefined colours so each pixel is represented by an index of a colour in the palette). This is necessary for formats that only allow a small number of distinct colours, but for full colour images there is no need for a palette - each pixel is defined as red, green and blue components without having to refer to anything else.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-01-29T03:33:40.947" LastActivityDate="2016-01-29T03:33:40.947" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1981" PostTypeId="2" ParentId="1979" CreationDate="2016-01-29T09:03:42.017" Score="3" Body="&lt;p&gt;Bitmap is simply means to convert a data range to bits. How that internally works and what the conversion function is, is application dependent. Each format can work differently. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simplest possible bitmaps just store the values directly in the bits themselves. Think of the the simplest form, a pixmap but instead of ASCII values you are using full byte per color. Off course the data does not need to be byte aligned so 3 values may be crammed to 2 bytes for example. Some formats may be using indexed colors (which is what you describe in your edit), this is a form of a compression scheme.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/j130t.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j130t.gif&quot; alt=&quot;A hypothethical bitmap&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: A hypothetical bitmap with 15 bits per pixel (for 5 bits per color), similar arrangement is used by some bitmap formats (this actual pattern is available in BMP). For a actual format read for example about the &lt;a href=&quot;https://en.wikipedia.org/wiki/BMP_file_format&quot; rel=&quot;nofollow noreferrer&quot;&gt;BMP format&lt;/a&gt; on wikipedia.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because the lower bit depths have very little space for color values these formats are often accompanied by a lookup table instead. This allows you to store a custom set of colors very tightly packed while allowing for a sensible variance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iurjI.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iurjI.gif&quot; alt=&quot;indexed bitmap&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Indexed bitmaps store a lookup array from where they take the actual color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that some formats may have pretty sophisticated transforms, or the data is compressed further by some more elaborate compression scheme. But even so a compression of $2/3$ and especially the indexed $1/6$ is pretty good for something that naturally tends to take up space. Off course if we compare with a ASCII pixmap those compression ratios are already quite significantly higher.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many such formats that you could type in with a text editor if you must. However, since your dealing with individual bits its much easier to do this with a &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Hex_editor&quot; rel=&quot;nofollow noreferrer&quot;&gt;hex editor&lt;/a&gt;&lt;/strong&gt; instead as the data is essentially binary. In practice it is easier to write a script to dump full values in the file, except perhaps in the 1 byte is one channel scenario where a hex editor works fine.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-01-29T09:22:36.483" LastActivityDate="2016-01-29T09:22:36.483" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1982" PostTypeId="2" ParentId="1974" CreationDate="2016-01-29T14:04:26.613" Score="5" Body="&lt;p&gt;[Disclaimer: I think the following should work but have not actually coded it myself]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I couldn't think of a &quot;trivial&quot; method of producing a yes/no answer but the following would be a reasonable approach to a practical solution to the question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume our curves are &lt;em&gt;A(s)&lt;/em&gt; and &lt;em&gt;B(t)&lt;/em&gt; with control points {&lt;em&gt;A0, A1..An&lt;/em&gt;} and {&lt;em&gt;B0,..Bm&lt;/em&gt;} respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems to me that, given a pair of 2D Beziers for which we wish to determine do or don't intersect, there are six cases to consider:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Case where we can &quot;trivially&quot; determine they do &lt;em&gt;not&lt;/em&gt; intersect.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Case where they intersect a finite number of times and we can &quot;easily&quot; determine they definitely intersect at least once (but we don't actually care where those intersections occur)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;One of the Beziers is degenerate, i.e. a point (which will occur if all the control points are identical). We can assume we've already handled the case where both are points.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;One or more of the curves are closed, e.g.. A0==An. To make life simpler, we'll subdivide such curves and start again.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;There are an infinite number of points of intersection because each is subset of a &quot;parent&quot; Bezier and they overlap.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;We aren't certain about the above cases and need further investigation&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For the moment we'll ignore 3 and 4, but come back to them later.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Case 1&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;As you hint in your question, if the respective bounding boxes of the control points of &lt;em&gt;A&lt;/em&gt; and &lt;em&gt;B&lt;/em&gt;), don't intersect, then the curves can't intersect. Obviously this is a quick reject test but it's overly conservative.&#xA;As you probably know, with a Bezier curve, the convex hull of its control points forms a (tighter) bound on the curve. We can thus use the separating axis technique to decide if the hulls of &lt;em&gt;A&lt;/em&gt; and &lt;em&gt;B&lt;/em&gt; don't intersect. (e.g. as shown in Wikipedia:)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/u4AxW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u4AxW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Case 2&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If the case 1 test fails, you could then check for the &quot;trivial&quot; existence of an intersection. Now there are probably better ways to do this, but the following, relatively cheap, approach occurred to me:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider just curve A:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2An9z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2An9z.png&quot; alt=&quot;&amp;quot;Fat line&amp;quot; bounds of a Bezier&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We know the curve starts at $A_0$, terminates at $A_n$, and will lie inside the convex hull. For simplicity let us compute the direction of the line segment $\overline{A_0A_n} $ and the compute the bounds on either side (i.e. take dot products of the remaining control points against the perpendicular to $\overline{A_0A_n}$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we do the same with curve B we get the following (possible) case:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dX6l0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dX6l0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we find $A_0$ and $A_n$ are outside opposite bounds of B &lt;em&gt;and&lt;/em&gt; that $B_0$ and $B_m$ are on the outsides of the bounds of A, then, by the continuity of Beziers, there must be at least one intersection.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Case 6&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If we can't immediately show either of the above cases, then split each of the Beziers into two &quot;halves&quot;, i.e. $A^1, A^2, B^1, B^2$. This is relatively straightforward (left as an exercise to the reader) but is &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1895/how-should-i-fill-a-shape-consisting-of-bezier-cures-and-straight-lines/1899#1899&quot;&gt;particularly trivial for quadratic Beziers&lt;/a&gt;: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recursively compare the 4 combinations: $(A^1,B^1), (A^2, B^1)...(A^2, B^2)$.&#xA;Clearly if all pass case 1, there is no intersection.&#xA;If any fail 1, then continue with the rest of the tests with that reduced subset.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Case 3 &amp;amp; 5&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;This is where it becomes slightly more tedious.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &quot;case 3&quot; gets past the &quot;case 1&quot; test, it seems to me that you need to solve for an actual intersection. Given that there is a simple process to map the N control points of a Bezier, A(s), to the N-1 points of the Bezier, A'(s), representing its 1st derivative then (provided care is taken for the relatively rare, so-called &quot;degenerate&quot; situations where the 1st derivative does to zero), then Newton iteration (on one dimension) could be used to find potential solutions.&lt;br&gt;&#xA;Note also that, since the control points of A'(s) are a bound on the derivative values, there is the potential to do early elimination of some cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Case 5 seems relatively unlikely, so perhaps only if after a few recursions there is no conclusive proof, one could try each end point of A against curve B and vice versa. This would only give a proof of intersection - not a proof of non-intersection.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-02-11T08:42:57.343" LastActivityDate="2016-02-11T08:42:57.343" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1983" PostTypeId="1" CreationDate="2016-01-29T19:14:03.043" Score="13" ViewCount="450" Body="&lt;p&gt;&lt;strong&gt;What I'm asking for&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I stress that I am &lt;strong&gt;not asking for the formula&lt;/strong&gt;---I know the formula, and how to derive it. Several different versions of it are reproduced near the end of the post. In fact, someone else has not only derived it as well, but also nicely presented one of the derivations &lt;a href=&quot;https://goo.gl/FJjkHQ&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I need is a &lt;strong&gt;&lt;em&gt;reputable source&lt;/em&gt;&lt;/strong&gt; for the formula so that, for example, one could put it on Wikipedia without violating its &lt;a href=&quot;https://en.wikipedia.org/wiki/Wikipedia:No_original_research&quot; rel=&quot;nofollow noreferrer&quot;&gt;ban on reporting original research.&lt;/a&gt; [People have &lt;a href=&quot;https://en.wikipedia.org/wiki/Talk:Horizon#About_the_.22curvature_of_the_horizon.22_section&quot; rel=&quot;nofollow noreferrer&quot;&gt;actually tried&lt;/a&gt;... But the &lt;a href=&quot;https://en.wikipedia.org/wiki/Horizon&quot; rel=&quot;nofollow noreferrer&quot;&gt;relevant article&lt;/a&gt; has some very conscientious editor who deleted the section on the grounds of it being original research... and, well, unfortunately, the editor is correct, so there's not much point in trying to fight it.]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The reason I'm posting in Computer Graphics stackexchange&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since someone here might have modeled the way the Earth looks form orbit, perhaps he or she might know if this formula (or, more likely, some generalization of it) is published in some book, or journal, or conference proceedings, or class notes, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;I've done the &quot;due googling&quot;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please understand that I'm not asking anyone to go searching for the answer on my behalf. I've done &lt;em&gt;lots&lt;/em&gt; of googling already, and am only posting here as a last resort. My (far-fetched) hope is that someone here will simply &lt;em&gt;know&lt;/em&gt; a reference right off the bat; if not... well, I hope at least you enjoyed the pretty picture below (if I do say so myself, with full awareness I'm talking to people interested in &lt;em&gt;computer graphics&lt;/em&gt; of all things) before you moved on to bigger and better things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Two sources that come close&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;D. K. Lynch, &quot;Visually discerning the curvature of the Earth,&quot; Applied Optics vol. 47, H39 (2008). It is freely available &lt;a href=&quot;http://thulescientific.com/Lynch%20Curvature%202008.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. Unfortunately, instead of doing it the right way (which is not that hard), the author opted for a hack, which (a) I don't completely understand, and (b) which doesn't agree with what I know to be the correct formula.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;R. Hartley and A. Zisserman, &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/0521540518&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Multiple View Geometry in Computer Vision,&lt;/em&gt;&lt;/a&gt; 2nd ed. (Cambridge University Press, Cambridge UK, 2004). In Sec. 8.3, &quot;Action of a projective camera on quadrics,&quot; we &lt;a href=&quot;https://goo.gl/IHvX2d&quot; rel=&quot;nofollow noreferrer&quot;&gt;read&lt;/a&gt;:&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Suppose the quadric is a sphere, then the cone of rays between the&#xA;  camera centre and quadric is right-circular, i.e. the contour&#xA;  generator is a circle, with the plane of the circle orthogonal to the&#xA;  line joining the camera and sphere centres. This can be seen from the&#xA;  rotational symmetry of the geometry about this line. The image of the&#xA;  sphere is obtained by intersecting the cone with the image plane. It&#xA;  is clear that this is a classical conic section, so that the apparent&#xA;  contour of a sphere is a conic.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In principle, this would be exactly what is needed, if only just a bit more information were included---at least an expression for the eccentricity of the conic as a function of the distance to the sphere and the sphere radius (in the case when the image plane is perpendicular to a &lt;a href=&quot;https://en.wikipedia.org/wiki/Generatrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;generatrix&lt;/a&gt; of the cone, as is the case when the pinhole camera is directed at a point on the horizon).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Details about the formula for which I need a scholarly reference&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We assume a perfectly spherical, perfectly smooth Earth with no atmosphere. We point an idealized pinhole camera at the horizon, and, using straightforward central projection, compute the shape of the image of the horizon on the back of the camera (i.e. the shape it will have on film---the &quot;film plane&quot;). Here's a graphic (made in &lt;a href=&quot;http://asymptote.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Asymptote&lt;/a&gt;, for those interested) that should make this clearer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Shaud.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Shaud.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As we saw above, the image of the horizon is a portion of a conic section. Let $\varepsilon$ be the eccentricity of the conic; the derivation &lt;a href=&quot;https://goo.gl/FJjkHQ&quot; rel=&quot;nofollow noreferrer&quot;&gt;I mentioned above&lt;/a&gt; instead uses a parameter $k$, which is just the inverse eccentricity: $k=1/\varepsilon$. The eccentricity itself is given as $\varepsilon=1/\sqrt{\epsilon(2+\epsilon)}$, where $\epsilon=h/R$ is the ratio of the altitude $h$ of the pinhole above the surface of the Earth and the Earth radius $R$. [Instead of using $\epsilon$, which is the ratio  of the &lt;em&gt;altitude&lt;/em&gt; to $R$, it may be useful to use $\eta$, the ratio of &lt;em&gt;the pinhole's distance to the Earth's center&lt;/em&gt;, $h+R$, to the Earth's radius: $\eta=(R+h)/R=1+\epsilon$. In terms of $\eta$, we have $\varepsilon=1/\sqrt{\eta^{2}-1}$.]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The distance from the pinhole (point $P$ in the graphic) to the film plane is taken to be one unit length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The $y$-axis in the film plane is chosen to be parallel to the line joining the center of the Earth $C$ (not shown in the image) and the point on the horizon (labeled $V$ in the image) at which the camera is trained. This choice is well-defined because the line $CV$ must be parallel to the film plane. The reason for this is that both $CV$ and the film plane are perpendicular to the line of sight $PV$ (the line joining $P$ and $V$). And &lt;em&gt;that&lt;/em&gt; is because 1. the line $PV$ is tangent to the Earth at $V$, thus perpendicular to $CV$, and 2. $PV$ is perpendicular to the film plane because the camera is trained at $V$. The $x$ axis is of course perpendicular to the $y$ axis and lies in the film plane, and the origin is chosen as the projection of the point $V$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With these definitions out of the way, we are ready to write down a representation of the conic section that is the image of the Earth's horizon. This can be written in many ways, some of which are given below. &lt;strong&gt;&lt;em&gt;What I need is a reputable reference for any one of these formulas, or for a formula equivalent to them.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1. The explicit formula given in the derivation mentioned above&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The derivation &lt;a href=&quot;https://goo.gl/FJjkHQ&quot; rel=&quot;nofollow noreferrer&quot;&gt;I mentioned above&lt;/a&gt; gives this as the final version:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[\,y\,(1/\varepsilon-\varepsilon)-1\,]^{2}+x^{2}(1/\varepsilon^{2}-1)=1.$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's represent this in a couple of additional ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2. Expression in terms of the canonical equation of a conic section&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, the equation takes &lt;a href=&quot;https://goo.gl/wIPjWs&quot; rel=&quot;nofollow noreferrer&quot;&gt;the following form&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x^2=2\mu y-(1-\varepsilon^{2}) y^2$,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where, in our case, $\mu=\varepsilon$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The advantage of the canonical form is that it can deal with all conics on an equal footing, including in particular the case of the parabola, $\varepsilon=1$. In the ``standard'' formulation (see below), the case of the parabola can only be dealt with by taking the limit $\varepsilon\to 1$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Details: the above formula holds in the case of a right circular cone, whose sides subtend an angle of $2\theta$, being intersected---at a distance $d$ from the vertex of the cone---by a plane at an angle $\omega$ relative to the cone axis. (To clarify: $d$ is the distance from the cone vertex to the point on the ellipse that is the closest to the cone vertex; that point is always one of the ends of the major axis of the ellipse). In this general case, the eccentricity is given as $\varepsilon=\cos \omega/\cos \theta$, while $\mu=d(\varepsilon-\cos|\omega+\theta|)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In terms of the above graphic: $d$ is the distance from $P$ to the film plane (i.e., the distance along the dotted red line); $\theta$ is the angle between the dotted red line and the axis of the cone (which is the line joining $P$ and the center of the Earth---the extension of the black line labeled $h$ in the graphic); the angle $\omega$ is the angle between the axis of the cone and the film plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given that the film plane is perpendicular to the dotted red line, we have $\omega+\theta=\pi/2$; in addition, we take $d=1$, which then together give that $\mu=\varepsilon$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3. Expression in terms of the ``standard form' of a conic section&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This form is perhaps the most familiar:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{(x-x_{0})^{2}}{p^2}+\frac{(y-y_{0})^{2}}{q^2}=1$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is related to the parameters entering the canonical equation (see 2., above) as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x_{0}=0$;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$y_{0}=q=\frac{\mu}{1-\varepsilon^{2}}$ (which is $\frac{\varepsilon}{1-\varepsilon^{2}}$ in our case&amp;mdash;note that $y_{0}=q$ follows from the fact that the ellipse passes through the origin); and&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p=q\smash[b]{\sqrt{|1-\varepsilon^{2}|}}=\frac{\mu}{\smash[b]{\sqrt{|1-\varepsilon^{2}|}}}$ (which is $\frac{\varepsilon}{\smash[b]{\sqrt{|1-\varepsilon^{2}|}}}$ in our case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is obvious that the parabolic case, $\varepsilon=1$, will create problems; as mentioned above, that case must be dealt with through taking the limit $\varepsilon\to 1$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;4. Expression in terms of a parametric curve&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x=\frac{(\epsilon+1) \cos (\alpha )}{\sin (\alpha )+\epsilon(\epsilon+2)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$y=\frac{\sqrt{\epsilon (\epsilon+2)} (\sin (\alpha )-1)}{\sin (\alpha )+\epsilon (\epsilon+2)},$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $\alpha$ is the longitude of a point on the horizon, defined so that $\alpha=\pi/2$ corresponds to the point $V$ in the image above (i.e. to the point at which the pinhole camera is trained).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For how one might use these formulas, see &lt;a href=&quot;https://imgur.com/gallery/Bi5cT&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In conclusion...&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Has anyone seen the formulas above in some reputable source, possibly in the context of modeling how the Earth looks from space? If so, could you let me know what this source was?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="2574" LastEditorUserId="2574" LastEditDate="2018-03-25T17:28:29.650" LastActivityDate="2018-03-25T17:28:29.650" Title="Need a reputable source for the formula for the shape of Earth's horizon" Tags="&lt;projections&gt;&lt;simulation&gt;" AnswerCount="1" CommentCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="1984" PostTypeId="1" CreationDate="2016-01-29T20:54:03.493" Score="5" ViewCount="263" Body="&lt;p&gt;I am trying to figure out how to convert a flat representation of a curve into the silhouette of a surface of revolution in a isometric projection. In essence in want the planar cut of the surface edge to be converted to the silhouette.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NV4V3.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NV4V3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Starting point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The geometry in this case is a Bézier curve although if somebody has solutions for any functions or higher order curves would be fine. So in essence im open to conics and NURBS also. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gWxcs.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gWxcs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: End result. How to transform the magenta curves?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I've done this now is by sampling several forms and in this case draw the new curve over the points. But id like to do this automatically and more precise. Please note: I am perfectly aware on how to do this with discrete data, I am looking for a more analytical solution if possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CsvkZ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CsvkZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 3&lt;/strong&gt;: The shape was derived using an old draftsman's trick.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please note: Most applications polygonize NURBS or Bézier surface for rendering. Also trivial root finding does not really work well as result should not be pixels but a curve. Let us to avoid this, as I am perfectly capable of discretisizing the solution and project the edges on the back face culling edge, and doing a secondary fitting, or even fitting on the NURBS underworld and then to 2d*. That is exactly the same solution as I am using now. Seem to me there should be a somewhat analytical transformation possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2qJA5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2qJA5.png&quot; alt=&quot;im perfectly capable of solving this with discretionary of the domain&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 4&lt;/strong&gt;: I am perfectly capable of doing this with subdivision/discretisation of the domain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* Though if you know a robust way to do the projection to a curve on surface I'm interested in that too.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-01-30T08:18:57.707" LastActivityDate="2017-07-11T00:20:45.700" Title="Silhouette curve for isometric surface of revolution" Tags="&lt;bezier-curve&gt;&lt;silhouette&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="1986" PostTypeId="2" ParentId="1974" CreationDate="2016-01-31T18:20:40.643" Score="6" Body="&lt;p&gt;An alternative way to formulate the problem is to define a function that gives the distance between points on the two curves, as a function of the curves' parameters. Then attempt to find the global minimum of this function. If the curves intersect, the minimum will be zero; otherwise the minimum will be some positive distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be explicit, given a pair of 2D curves defined by $c_1, c_2 : [0, 1] \to \mathbb{R}^2$, define the distance-squared as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ f(u,v) : [0,1]^2 \to \mathbb{R}_{\geq 0} \equiv \bigl|c_2(v) - c_1(u)\bigr|^2 $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For cubic curves, the function $f$ is then a sixth-degree polynomial in two variables. You can then apply numerical optimization techniques such as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method&quot;&gt;simplex method&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Conjugate_gradient_method&quot;&gt;conjugate gradient descent&lt;/a&gt;. Unfortunately the function can have several local minima (it's not convex), so optimization isn't easy. There may well be more specialized optimization methods available for polynomials, but this isn't an area of expertise for me.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-01-31T18:20:40.643" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1987" PostTypeId="1" AcceptedAnswerId="1989" CreationDate="2016-02-01T05:07:20.643" Score="6" ViewCount="2537" Body="&lt;p&gt;A &lt;a href=&quot;http://www2.imm.dtu.dk/pubdb/views/edoc_download.php/6816/pdf/imm6816.pdf&quot; rel=&quot;nofollow&quot;&gt;paper$^1$&lt;/a&gt; I'm reading says fluence measures the incoming radiance from all directions and that fluence is similar to irradiance. It's defined by $\phi(x) = \int_{4 \pi} L(x, \vec{\omega'}) d\omega' $ (The tick mark seems to emphasize $\vec{\omega'}$ varies over the integration, rather than being a fixed direction.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intuitively, radiance is the amount of light given off in a direction but attenuated by how far off the surface is from being perpendicular to the light direction. $L=\frac{d^2\Phi}{d\omega dA \cos \theta}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Irradiance is the area light density of a surface. $E=\frac{d\Phi}{dA}=\int_{2 \pi } L_i(\vec{\omega}) \cos \theta d\omega$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intensity is the amount of light hitting a surface from a particular direction. $I(\vec{\omega})=\frac{d\Phi}{d\omega}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It also looks like you can write the radiance as irradiance times intensity. &#xA;$L=E\cdot I(\vec{\omega})$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at the formulas, it seems like irradiance sums radiance over the hemisphere over a surface point and attenuated by how much the surface orients toward the light source, while fluence sums up radiance over the whole sphere surrounding a point (to measure inscattering).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wikipedia says, &quot;radiant fluence is the radiant energy received by a surface per unit area, or equivalently the irradiance of a surface integrated over time of irradiation.&quot; But this definition doesn't seem to match the one given above since there's no time involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.researchgate.net/post/What_is_the_definition_and_difference_between_light_dose_and_light_fluence_rate&quot; rel=&quot;nofollow&quot;&gt;https://www.researchgate.net/post/What_is_the_definition_and_difference_between_light_dose_and_light_fluence_rate&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://omlc.org/education/ece532/class1/irradiance.html&quot; rel=&quot;nofollow&quot;&gt;http://omlc.org/education/ece532/class1/irradiance.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Real-Time Rendering of Translucent Materials with Directional Subsurface Scattering, Alessandro Dal Corso, 2014&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2457" LastEditorUserId="2457" LastEditDate="2016-02-02T05:03:34.853" LastActivityDate="2016-02-02T05:03:34.853" Title="What's the difference between irradiance and fluence/radiant exposure?" Tags="&lt;rendering&gt;&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1989" PostTypeId="2" ParentId="1987" CreationDate="2016-02-01T21:28:59.743" Score="3" Body="&lt;p&gt;I can only cite what I have learned in my lecture on Global Illumination techniques which was unfortunately some time ago:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Radiant Power : The amount of energy emitted by a light source in unit time. denoted by $\Phi$ and is measured in Watt which equals to Joules per second. (This does not specify any area!)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Irradiance: The irradiance denotes the incident radiant energy on a surface. It is defined as $E=\frac{d\Phi}{dA}$ - This quantity denotes the incoming energy per area and is measure ind $\frac{W}{m^2}$ Note here: radiant energy is measured in Watt which is Joules &lt;strong&gt;per second&lt;/strong&gt;!&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Radiant exitance: This is the reverse direction of Irradiance and is the energy an area emits in unit time and has the same definiton and units as Irradiance only with reverse direction $M = B = \frac{d\Phi}{dA}$. This is also often called radiosity B.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Radiance: Is the power per projected area per solid angle. It is defined as $L=\frac{d²\Phi}{d \omega * dA * cos\theta}=[\frac{W}{sr*m^2}]$ where $\omega$ denotes the solid angle, $\theta$ denotes the angle between emitting surface normal and the direction the energy is traveling to. So this is not attenuated by the distance but by the angles.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;In general as I learned the distance between emitting and receiving surface is only important for Radiance because the projected area will be smaller if they are farther apart.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The time you are missing in your definitions seem to come from the conversion of Watt to Joules Per Second.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-02-01T21:28:59.743" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1990" PostTypeId="1" CreationDate="2016-02-02T10:20:07.647" Score="6" ViewCount="15640" Body="&lt;p&gt;I installed AMD APP SDK and here my problem. The OpenCL samples do not detect the GPU. HelloWorld give me this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[thomas@Clemence:/opt/AMDAPP/samples/opencl/bin/x86_64]$ ./HelloWorld&#xA;No GPU device available.&#xA;Choose CPU as default device.&#xA;input string:&#xA;GdkknVnqkc&#xA;&#xA;output string:&#xA;HelloWorld&#xA;Passed!&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here the clinfo output&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[thomas@Clemence:~/Documents/radeontop]$ clinfo&#xA;Number of platforms:                 1&#xA;Platform Profile:                FULL_PROFILE&#xA;Platform Version:                OpenCL 1.2 AMD-APP (1214.3)&#xA;Platform Name:               AMD Accelerated Parallel Processing&#xA;Platform Vendor:                 Advanced Micro Devices, Inc.&#xA;Platform Extensions:                 cl_khr_icd cl_amd_event_callback      cl_amd_offline_devices&#xA;&#xA;&#xA;Platform Name:               AMD Accelerated Parallel Processing&#xA;Number of devices:               1&#xA;Device Type:                     CL_DEVICE_TYPE_CPU&#xA;Device ID:                   4098&#xA;Board name:                  &#xA;Max compute units:               8&#xA;Max work items dimensions:           3&#xA;Max work items[0]:               1024&#xA;Max work items[1]:               1024&#xA;Max work items[2]:               1024&#xA;Max work group size:                 1024&#xA;Preferred vector width char:             16&#xA;Preferred vector width short:            8&#xA;Preferred vector width int:          4&#xA;Preferred vector width long:             2&#xA;Preferred vector width float:            8&#xA;Preferred vector width double:       4&#xA;Native vector width char:            16&#xA;Native vector width short:           8&#xA;Native vector width int:             4&#xA;Native vector width long:            2&#xA;Native vector width float:           8&#xA;Native vector width double:          4&#xA;Max clock frequency:                 3633Mhz&#xA;Address bits:                    64&#xA;Max memory allocation:           4182872064&#xA;Image support:               Yes&#xA;Max number of images read arguments:         128&#xA;Max number of images write arguments:        8&#xA;Max image 2D width:              8192&#xA;Max image 2D height:                 8192&#xA;Max image 3D width:              2048&#xA;Max image 3D height:                 2048&#xA;Max image 3D depth:              2048&#xA;Max samplers within kernel:          16&#xA;Max size of kernel argument:             4096&#xA;Alignment (bits) of base address:        1024&#xA;Minimum alignment (bytes) for any datatype:  128&#xA;Single precision floating point capability&#xA;Denorms:                     Yes&#xA;Quiet NaNs:                  Yes&#xA;Round to nearest even:           Yes&#xA;Round to zero:               Yes&#xA;Round to +ve and infinity:           Yes&#xA;IEEE754-2008 fused multiply-add:         Yes&#xA;Cache type:                  Read/Write&#xA;Cache line size:                 64&#xA;Cache size:                  32768&#xA;Global memory size:              16731488256&#xA;Constant buffer size:                65536&#xA;Max number of constant args:             8&#xA;Local memory type:               Global&#xA;Local memory size:               32768&#xA;Kernel Preferred work group size multiple:   1&#xA;Error correction support:            0&#xA;Unified memory for Host and Device:      1&#xA;Profiling timer resolution:          1&#xA;Device endianess:                Little&#xA;Available:                   Yes&#xA;Compiler available:              Yes&#xA;Execution capabilities:              &#xA;Execute OpenCL kernels:          Yes&#xA;Execute native function:             Yes&#xA;Queue properties:                &#xA;Out-of-Order:                No&#xA;Profiling :                  Yes&#xA;Platform ID:                     0x00007f4ef63f0fc0&#xA;Name:                        Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz&#xA;Vendor:                  GenuineIntel&#xA;Device OpenCL C version:             OpenCL C 1.2 &#xA;Driver version:              1214.3 (sse2,avx)&#xA;Profile:                     FULL_PROFILE&#xA;Version:                     OpenCL 1.2 AMD-APP (1214.3)&#xA;Extensions:                  cl_khr_fp64 cl_amd_fp64     cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_gl_sharing cl_ext_device_fission cl_amd_device_attribute_query cl_amd_vec3 cl_amd_printf cl_amd_media_ops cl_amd_media_ops2 cl_amd_popcnt &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What should I do in order to have access to the GPU? Thanks in advance. I'm working on Ubuntu 14.04.3 LTS Trusty Kernel 3.9&lt;/p&gt;&#xA;&#xA;&lt;p&gt;here my graphics card:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[thomas@elsa:~]$ lspci | grep -i --color 'vga'&#xA;00:02.0 VGA compatible controller: Intel Corporation Xeon E3-1200 v3/4th &#xA;Gen Core Processor Integrated Graphics Controller (rev 06)&#xA;01:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] &#xA;Oland XT [Radeon HD 8670 / R7 250/350]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2592" LastActivityDate="2017-02-11T17:21:45.813" Title="OpenCL doesn't detect GPU" Tags="&lt;gpu&gt;&lt;opencl&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1991" PostTypeId="1" AcceptedAnswerId="2050" CreationDate="2016-02-02T12:04:47.037" Score="5" ViewCount="209" Body="&lt;p&gt;I encountered some problems when implementing the cloth simulation algorithm from Baraff &amp;amp; Witkin 98's &lt;a href=&quot;http://www.cs.cmu.edu/~baraff/papers/sig98.pdf&quot; rel=&quot;nofollow&quot;&gt;Large Steps in Cloth Simulation&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Baraff &amp;amp; Witkin 98&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the cloth as a particle system in 3D, which consists of N particles.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Equation of motion&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In each time step, the implicit integration of particle system is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{pmatrix} \Delta \mathbf x \\ \Delta \mathbf v \\ \end{pmatrix} = h\begin{pmatrix} \mathbf v_0 + \Delta \mathbf v \\ \mathbf M^{-1} \mathbf f(\mathbf x_0 + \Delta \mathbf x, \mathbf v_0 + \Delta \mathbf v) \\ \end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $h$ is the time step (scalar)&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;The partial derivative equation&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Rewrite the aforementioned equality of motion into $\mathbf A \Delta \mathbf v = \mathbf b$ form, (&#xA;Take the 1st order Taylor expansion of $\mathbf f(\mathbf x_0 + \Delta \mathbf x, \mathbf v_0 + \Delta \mathbf v)$, and introduce constraint matrix $\mathbf S$, which make mass matrix from $\mathbf M^{-1}$ to $\mathbf M^{-1}\mathbf S$), we have: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;(\mathbf I - h\mathbf M^{-1} \mathbf S\frac{\partial \mathbf f}{\partial \mathbf v} - h^2\mathbf M^{-1} \mathbf S\frac{\partial \mathbf f}{\partial \mathbf x})\Delta \mathbf v = h\mathbf M^{-1} \mathbf S(\mathbf f_0 + h\frac{\partial \mathbf f}{\partial \mathbf x} \mathbf v_0) + \mathbf z&#xA;$$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where all of the matrices are treated as $N\times N $ block matrices, eack block sizes $3\times 3 $; vectors as $N$ block vector, each sized $3$ (with N number of 3D forces/positions/velocities).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;$\mathbf I$ is identical matrix&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$ \mathbf M = diag(\mathbf M_1, \mathbf M_2, ..., \mathbf M_N) $, $\mathbf M_i = diag(m_i, m_i, m_i)$, mass of each particle&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$ \mathbf S = diag(\mathbf S_1, \mathbf S_2, ..., \mathbf S_N) $, &#xA;$  \mathbf S_i = \begin{cases}  \mathbf I,  &amp;amp; \text{$ndof(i) = 3$} \\ \mathbf I - \mathbf p_i \mathbf p_i^T,  &amp;amp; \text{$ndof(i) = 2$} \\ \mathbf I - \mathbf p_i \mathbf p_i^T - \mathbf q_i \mathbf q_i^T,  &amp;amp; \text{$ndof(i) = 1$} \\ \mathbf 0,  &amp;amp; \text{$ndof(i) = 0$} \end{cases}$, $\mathbf p$ and $\mathbf q$ are two oithogonal constraint direction, $\mathbf S$ is constraint matrix (Baraff98 chapter 5.1)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$\frac{\partial \mathbf f}{\partial \mathbf v}$ and $\frac{\partial \mathbf f}{\partial \mathbf x}$ are force derivatives, which are symmetrical matrices&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;solve the PDE&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The paper solves the aforementioned PDE by &lt;strong&gt;Modified Preconditioning Conjugate Gradient Method&lt;/strong&gt; (Baraff98 chapter 5.2) for $\Delta \mathbf v$, then update the velocity $\mathbf v$ and position $\mathbf x$ of each particle.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My Questions&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solve $\mathbf A\mathbf x=\mathbf b$ with PCG method requires the matrix $\mathbf A$ to be symmetrical and positive-definite, where according to the aforementioned PDE, $\mathbf A = (\mathbf I - h\mathbf M^{-1} \mathbf S\frac{\partial \mathbf f}{\partial \mathbf v} - h^2\mathbf M^{-1} \mathbf S\frac{\partial \mathbf f}{\partial \mathbf x})$.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;symmentrical&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In block view: treat $\mathbf A$ as an $N\times N$ block matrix, $\mathbf M^{-1}$ and $\mathbf S$ are both block diagonal matrices, makes $\mathbf A$ a block symmetrical matrix. While in normal view: $\mathbf A$ as $3N\times 3N$ matrix, $\mathbf S$ is symmetrical, but product of $\mathbf M^{-1} \mathbf S$ and $\frac{\partial \mathbf f}{\partial \mathbf v}$ (or $\frac{\partial \mathbf f}{\partial \mathbf x}$) makes $\mathbf A$ not symmetrical. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 1&lt;/strong&gt;: should I treat $\mathbf A\mathbf x=\mathbf b$ as a block matrix rather than normal matrix? If not, how to make $\mathbf A$ symmetrical?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I then modified the PDE as $\mathbf A^T\mathbf A\mathbf x=\mathbf A^T\mathbf b$, $\mathbf A^T\mathbf A$ is symmetrical.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 2&lt;/strong&gt;: How to make the &lt;code&gt;fliter&lt;/code&gt; procedure (Baraff98 chapter 5.3) compatible with $\mathbf A^T\mathbf A\mathbf x=\mathbf A^T\mathbf b$?&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;positive-definite&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The blocks $\mathbf S_i$ in $\mathbf S$ may become zero block when $ndof(i) = 0$, which makes $\mathbf A^T\mathbf A$ a positive-semidefinite matrix. To apply PCG method, according to Baraff98 chapter 5.3:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The CG method (technically, the preconditioned CG method) takes a symmetric &lt;strong&gt;positive semi-definite&lt;/strong&gt; matrix $\mathbf A$, a &lt;strong&gt;symmetric positive definite&lt;/strong&gt; preconditioning matrix $\mathbf P$ of the same dimension as $\mathbf A$ ,a vector $\mathbf b$ and iteratively solves $\mathbf A \Delta \mathbf v = \mathbf b$.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 3&lt;/strong&gt;: How to find the symmetrical and positive-definite preconditioning matrix $\mathbf P$, with $\mathbf A^T\mathbf A$ symmetrical and semi PD?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Some docs I also refered:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.cs.ubc.ca/~ascher/papers/ab.pdf&quot; rel=&quot;nofollow&quot;&gt;On the modified conjugate gradient method in cloth simulation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://davidpritchard.org/freecloth/docs/report-single/&quot; rel=&quot;nofollow&quot;&gt;freecloth&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://cg.informatik.uni-freiburg.de/course_notes/sim_03_cloth1.pdf&quot; rel=&quot;nofollow&quot;&gt;Cloth Simulation slides&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2593" LastEditorUserId="2593" LastEditDate="2016-02-13T04:02:09.840" LastActivityDate="2016-02-15T21:30:17.253" Title="Questions about Preconditioning Conjugate Gradient method in Baraff &amp; Witkin 98?" Tags="&lt;real-time&gt;&lt;mesh&gt;&lt;physically-based&gt;&lt;animation&gt;&lt;simulation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="1992" PostTypeId="1" AcceptedAnswerId="1994" CreationDate="2016-02-02T20:01:54.463" Score="10" ViewCount="518" Body="&lt;p&gt;In traditional rendering, it is typical to do all the calculations with radiometric units, either as full spectral rendering, or component-wise (XYZ, RGB, etc).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, as modern rendering adds more physically based models, it's convenient for artists to be able to specify values in the more familiar photometric units, for example, intensity of a light in lumens. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jOg65.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jOg65.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to keep the pipeline all in one type of unit, you can do one of the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Convert photometric units to radiometric units using &lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_efficacy&quot; rel=&quot;noreferrer&quot;&gt;luminous efficacy&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Keep the entire render pipeline in photometric units&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Sébastian Lagarde presents this idea very well in the course notes of his Siggraph 2014 presentation &lt;a href=&quot;http://www.frostbite.com/2014/11/moving-frostbite-to-pbr/&quot; rel=&quot;noreferrer&quot;&gt;Moving Frostbite to PBR&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;My questions then are these:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Are there any disadvantages to rendering exclusively in photometric units? &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;As far as I can tell, photometric units are just radiometric units biased to the human eye. Considering that we will view the final image with our eye, I don't see this as a problem.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Frostbite is a RGB component-wise engine. Would a spectral renderer have any additional disadvantages by rendering exclusively in photometric units?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-02-03T07:55:00.923" Title="Rendering in radiometric units or photometric?" Tags="&lt;pbr&gt;&lt;render&gt;&lt;photometric&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="1993" PostTypeId="2" ParentId="1990" CreationDate="2016-02-02T20:30:54.753" Score="3" Body="&lt;p&gt;I should warn you that I don't really know anything about linux or programming or device drivers, but I had your exact problem once.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It could be a udev rule problem. Your usergroup might not have permission to write to the gpu device or whatever libOpenCL.so does. Does &lt;code&gt;$ sudo clinfo&lt;/code&gt; find the gpu?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your program might not be using the right opencl library. I think that there is some ubuntu packages that provide libopencl.so. You don't want to use those, they won't know how to talk to your gpu. Could you post:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ ldd /opt/AMDAPP/samples/opencl/bin/x86_64/HelloWorld&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the libOpenCL.so* line (sometimes libcl.so*) doesn't point to a AMD library, you need to find the AMD libOpenCL.so library and make sure that it is found first before whatever you're using at runtime. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would do &lt;code&gt;$ sudo updatedb&lt;/code&gt; then,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ locate libOpenCL.so&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ locate libcl.so&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;depending on which your &lt;code&gt;./HelloWorld&lt;/code&gt; is trying to link to. Then set the &lt;code&gt;LD_LIBRARY_PATH&lt;/code&gt; to the parent folder of the preferred library.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;$ export LD_LIBRARY_PATH=/path to lib*cl.so* that was installed by AMD driver/ &#xA;$ clinfo&#xA;$ ./HelloWorld&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2597" LastActivityDate="2016-02-02T20:30:54.753" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1994" PostTypeId="2" ParentId="1992" CreationDate="2016-02-03T07:55:00.923" Score="9" Body="&lt;p&gt;It's fine to use photometric units as an overall scale for setting light brightnesses. However, there's a technical subtlety you should be aware of. I'll quote from &lt;a href=&quot;http://www.reedbeta.com/blog/2014/08/17/radiometry-versus-photometry/&quot; rel=&quot;noreferrer&quot;&gt;a blog post I wrote on the subject last year&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;With RGB images, it’s important to recognize that our display devices behave more radiometrically than photometrically. A red pixel value of 255, and a green pixel value of 255, both result in about equal amounts of &lt;em&gt;radiant&lt;/em&gt; flux (watts) being generated by a pixel on a screen—&lt;em&gt;not&lt;/em&gt; equal amounts of luminous flux. By the same token, digital cameras capture pixel values that correspond to radiant flux, not luminous flux.&lt;/p&gt;&#xA;&lt;p&gt;That’s why we need to use luma coefficients when converting images to grayscale, or calculating the brightness of a pixel, to get a perceptually accurate result; and it also means that rendering RGB images proceeds more naturally in radiometric units than in photometric ones.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;In other words, the wavelength dependence of photometric units is different to what you might be expecting. In ordinary RGB color spaces, white is (1, 1, 1) and has a roughly flat radiometric spectrum; but in a supposed &amp;quot;photometric RGB&amp;quot;, (1, 1, 1) would not be white; it would be a purpleish color, with less energy in the green range and more in the red and blue ranges. A similar problem would afflict spectral renderers trying to measure all their bins in wavelength-dependent photometric units, but even worse, as the radiance needed to generate a given luminance &lt;em&gt;diverges&lt;/em&gt; toward either end of the visible spectrum, where the human luminous efficiency function goes to zero.&lt;/p&gt;&#xA;&lt;p&gt;So, if you wish to use photometric units, IMO it's better to &amp;quot;cheat&amp;quot; a bit and not use &lt;em&gt;true&lt;/em&gt; wavelength-dependent photometric units, but just use some fixed wavelength (such as 555 nm green, which is the peak of the human luminous efficiency function), or perhaps an average over the spectrum, as a reference unit, and apply that single unit to measure all wavelengths. This will get you in less trouble when importing RGB colors and spectra from other sources, and when generating them as outputs.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-02-03T07:55:00.923" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1995" PostTypeId="1" CreationDate="2016-02-03T12:23:28.790" Score="4" ViewCount="814" Body="&lt;p&gt;I need to do planar reflection mapping in OpenGL. By using a virtual camera (with a reversed camera ray) at the back of reflective plane (a mirror), I rendered the scene to texture, which is then texture mapped to the mirror. The uvs of four corners of the mirror is specified then (using the result of gluProjection). The problem is by default, the uv coordinates are perspective-correctly interpolated, which is not desirable in this case. Is there any way to disable the perspective correction (without using GLSL)?&lt;/p&gt;&#xA;" OwnerUserId="2600" LastActivityDate="2016-02-03T12:23:28.790" Title="How to disable Perspective Correction in Texture Coordinates Interpolation in OpenGL(without using shaders)?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="1997" PostTypeId="1" CreationDate="2016-02-03T19:38:55.693" Score="2" ViewCount="111" Body="&lt;p&gt;I am implementing foveated rendering. My &lt;a href=&quot;https://en.wikipedia.org/wiki/Framebuffer_Object&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Framebuffer Object&quot;&gt;FBO&lt;/a&gt; is divided into 2 layers which are concentric. The first layer covers 1/3 of the Framebuffer whereas the second one covers the rest of the screen. Now I want to avoid rendering meshes in the outer layer which are already in the inner layer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have implemented the following culling algorithm which is only concerned with culling between the layers:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I create rectangles with min and max corners from the radii of the 2 layers. Now these coordinates are in &lt;a href=&quot;https://www.ncl.ucar.edu/Document/Graphics/ndc.shtml&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Normalized Device Coordinates&quot;&gt;NDC&lt;/a&gt;. &lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I have the min and max corner of each mesh in the local coordinate system. So I transform them into NDC using:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 min = mvp * vec4(min_corner, 1.0);&#xA;min = min.xyzw / min.w;&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I create a bounding box using min and max corners.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;I check whether 2 rectangles overlap or not.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Now, when I transform into clip space, the x or y coordinates of the min are sometimes greater than the max corner. The same issue occurs when I divide them by w. What's going wrong here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;Okay. I found the problem. Now I iterate over all the vertices, transform each of them into NDC using &lt;a href=&quot;https://stackoverflow.com/questions/5550620/the-purpose-of-model-view-projection-matrix&quot; title=&quot;Model View Projection matrix&quot;&gt;MVP&lt;/a&gt; and then calculate the min and max corners which works perfect. But this is much more overhead for each frame. Is there any optimization I can do here?&lt;/p&gt;&#xA;" OwnerUserId="2602" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-02-06T21:04:52.903" Title="culling meshes across mulitple layers" Tags="&lt;opengl&gt;&lt;algorithm&gt;&lt;3d&gt;&lt;transformations&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="1998" PostTypeId="1" AcceptedAnswerId="2000" CreationDate="2016-02-03T20:13:24.137" Score="7" ViewCount="108" Body="&lt;p&gt;In a webgl pixel shader, all functions are inlined as i understand it, however you can have parameters that are marked as &lt;strong&gt;&lt;em&gt;in&lt;/em&gt;&lt;/strong&gt; versus being &lt;strong&gt;&lt;em&gt;inout&lt;/em&gt;&lt;/strong&gt; meaning that their value can change but the value won't persist outside of the function call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this mean that the shader must make a copy of the value for the function to work with when it is an &lt;strong&gt;&lt;em&gt;in&lt;/em&gt;&lt;/strong&gt; value?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are shader compilers/optimizers smart enough to know when they don't need to make a copy, or is it best to really just mark up all parameters as &lt;strong&gt;&lt;em&gt;inout&lt;/em&gt;&lt;/strong&gt; and make sure and not modify the ones you don't want modified, if performance is the primary concern?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-02-05T04:32:08.370" Title="Cost of parameter passing in webgl pixel shaders?" Tags="&lt;webgl&gt;&lt;pixel-shader&gt;&lt;efficiency&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="1999" PostTypeId="1" AcceptedAnswerId="2001" CreationDate="2016-02-04T05:55:44.517" Score="5" ViewCount="980" Body="&lt;p&gt;Geometry shaders appear to have been introduced in 3.2, which makes me wonder how common 3.2-enabled cards are, including support for Geometry shaders within WebGL contexts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will I be cutting out a large portion of viewers by requiring the use of a geometry shader?&lt;/p&gt;&#xA;" OwnerUserId="71" LastActivityDate="2016-02-04T09:29:22.403" Title="How much should I rely on Geometry shaders in WebGL?" Tags="&lt;webgl&gt;&lt;geometry-shader&gt;&lt;compatibility&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2000" PostTypeId="2" ParentId="1998" CreationDate="2016-02-04T06:25:05.953" Score="6" Body="&lt;p&gt;My experience working with shader compiler stacks a few years back is that they are extremely aggressive, and I doubt you will see any perf difference, but I would suggest testing as much as you can.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would generally recommend providing the compiler (and human readers) with more information where the language allows it, marking parameters according to their usage. Treating an in-only parameter as in/out is more error prone for humans than compilers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some detail: shaders run almost entirely using registers for variables (I worked with architectures that supported up to 256 32 bit registers) - spilling is hugely expensive. Physical registers are shared between shader invocations - think of this as threads in a HyperThread sense sharing a register pool - and if the shader can be complied to use fewer registers there's greater parallelism. The result is shader compilers work very hard to minimize the number of registers used - without spilling, of course. Thus inlining is common since it's desirable to optimize register allocation across the whole shader anyway.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-02-05T04:32:08.370" LastActivityDate="2016-02-05T04:32:08.370" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2001" PostTypeId="2" ParentId="1999" CreationDate="2016-02-04T09:29:22.403" Score="9" Body="&lt;p&gt;WebGL doesn't even currently support geometry shaders, so to directly answer the question: 100% of all users.&lt;/p&gt;&#xA;" OwnerUserId="71" LastActivityDate="2016-02-04T09:29:22.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2003" PostTypeId="1" CreationDate="2016-02-04T16:38:11.167" Score="8" ViewCount="435" Body="&lt;p&gt;I am developing the algorithm reported in this article:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.cs.jhu.edu/~misha/Fall09/Levy02.pdf&quot;&gt;Least square conformal mapping&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is presented an algorithm to flat a 3d mesh on the parametric space, but i don't understand the segmentation step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know an alternative segmentation approach simpler than the algorithm presented in that article?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other word, do you know a simple and efficient mesh segmentation algorithm?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The requirements are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;charts boundaries should be positioned in such a way that most&#xA;of the discontinuities between the charts will be located in zones&#xA;where they will not cause texture artifacts,&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;boundary curves corresponding to high curvature zones of the model.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Thank you for your help in advance.&lt;/p&gt;&#xA;" OwnerUserId="2606" LastActivityDate="2017-09-13T16:56:21.313" Title="3D mesh segmentation simple algorithm" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2004" PostTypeId="2" ParentId="1725" CreationDate="2016-02-05T08:07:12.037" Score="12" Body="&lt;p&gt;For the current state-of-the-art, look for this paper:&#xA;&quot;Maximum Mipmaps for Fast, Accurate, and Scalable Dynamic Height Field&#xA;Rendering&quot;, Tevs et al. 2008&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic idea is to skip a lot of space by having knowledge of the maximum value over large areas of terrain. If the ray stays above that, skip to the next large area. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at Figure 8, you'll see a comparison of basic linear stepping vs. maximum mipmaps. Linear stepping results in 200 steps, which can be done real-time on modern gpus but is still actually slow. Max mipmaps do the same in about 10 steps, all in shader.&lt;/p&gt;&#xA;" OwnerUserId="2609" LastActivityDate="2016-02-05T08:07:12.037" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2007" PostTypeId="2" ParentId="1997" CreationDate="2016-02-06T17:36:28.740" Score="1" Body="&lt;p&gt;Regarding optimizations:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you calculate the min and max corners in modelspace beforehand? Then you could check on the CPU-side the NDCs of these two points and skip the processing of the whole mesh if it is outside of the desired range. This needs only two matrix-vector multiplications on cpu side. And since for rigid bodies these two points do not change over time, you don't have to iterate the meshes in each frame.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="273" LastEditDate="2016-02-06T21:04:52.903" LastActivityDate="2016-02-06T21:04:52.903" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2008" PostTypeId="1" AcceptedAnswerId="2280" CreationDate="2016-02-07T02:38:23.367" Score="2" ViewCount="540" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8UV6b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8UV6b.png&quot; alt=&quot;As you can see the back face is lighting as well&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a problem with lighting calculations.&#xA;I am rotating the camera around a cube which was supposed to be illuminated by the light but the resulting lighting is very weird.&#xA;Check out the image above, fragment shader and vertex shader below.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Vertex shader&#xA;&#xA;#version 330 core&#xA;&#xA;layout (location = 0) in vec3 pos;&#xA;layout (location = 1) in vec3 norm;&#xA;&#xA;uniform mat4 model;&#xA;uniform mat4 view;&#xA;uniform mat4 projection;&#xA;uniform vec3 lightPos;&#xA;&#xA;&#xA;out vec3 ourNormal;&#xA;out vec3 fragPos;&#xA;out vec3 ourLightPos;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position = projection*view*model*vec4(pos,1.0);&#xA;    fragPos = vec3(view * model * vec4(pos, 1.0f));&#xA;    ourNormal = mat3(transpose(inverse(view * model))) * norm;&#xA;    ourLightPos = vec3(view * vec4(lightPos, 1.0));&#xA;}&#xA;&#xA;&#xA;&#xA;//fragment shader&#xA;&#xA;#version 330 core&#xA;&#xA;//Output variables&#xA;out vec4 finalColor;&#xA;&#xA;//Input variables&#xA;in vec3 ourNormal;&#xA;in vec3 fragPos;&#xA;in vec3 ourLightPos;&#xA;&#xA;//Uniform variables&#xA;&#xA;struct Material&#xA;{&#xA;    vec3 ambient;&#xA;    vec3 diffuse;&#xA;    vec3 specular;&#xA;    float shininess;&#xA;};&#xA;&#xA;struct Light&#xA;{&#xA;    vec3 ambient;&#xA;    vec3 diffuse;&#xA;    vec3 specular;&#xA;};&#xA;&#xA;uniform Light light;&#xA;uniform Material material;&#xA;uniform vec3 viewPos;&#xA;&#xA;void main()&#xA;{&#xA;    //Ambient&#xA;    vec3 ambient = light.ambient*material.ambient;&#xA;&#xA;    //Diffuse&#xA;    vec3 normal = normalize(ourNormal);&#xA;    vec3 lightDir = normalize(ourLightPos - fragPos);&#xA;    float diffuseStrength = max(dot(lightDir,normal),0.0);&#xA;    vec3 diffuse = light.diffuse*(diffuseStrength*material.diffuse);&#xA;&#xA;    //Specular&#xA;    vec3 viewDir = normalize(viewPos - fragPos);&#xA;    vec3 reflectDir = reflect(-lightDir,normal);&#xA;    float specularStrength =         pow(max(dot(viewDir,reflectDir),0.0),material.shininess);&#xA;    vec3 specular = light.specular * (specularStrength*material.specular);&#xA;&#xA;    //Last step&#xA;    vec3 result = (ambient+diffuse+specular);&#xA;    finalColor = vec4(result,1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can see, I transformed all the positions, normals and light source position in view space, i.e camera space, but I don't know why it's not working.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="127" LastEditDate="2016-04-07T12:19:34.177" LastActivityDate="2016-04-07T14:59:33.647" Title="Why does my lighting look incorrect?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2009" PostTypeId="1" AcceptedAnswerId="3687" CreationDate="2016-02-07T17:31:50.120" Score="6" ViewCount="101" Body="&lt;p&gt;I am trying to plug in a 3D game engine as the rendering engine for an existing graphic API system that uses a right-handed coordinate system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Game engines often uses a left handed coordinate system internally.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how can I convert the API parameters, 3d vectors, transformation matrices, and quaternions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The right handed versions at the API boundary have to be converted to left handed equivalents before passing to the engine's APIs at a lower layer, and then the output parameters from the engine have to be converted back to the right hand representations for the higher level APIs.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both coordinate systems I am referring to here are, x pointing to the right, y pointing to the top, and z point away from the eye (left hand) and towards or behinds the eye (right hand), with the eye at the origin or some distance behind the xy plane to allow the origin to be in the camera view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example: For simple 3d-points, the conversion step would be just to flip the sign of the z value.&lt;/p&gt;&#xA;" OwnerUserId="2621" LastEditorUserId="231" LastEditDate="2016-02-07T19:48:24.747" LastActivityDate="2018-03-07T02:58:00.457" Title="implementing right handed coord system APIs on top of a left-handed rendering engine" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2010" PostTypeId="1" CreationDate="2016-02-07T22:50:50.250" Score="5" ViewCount="129" Body="&lt;p&gt;In a modern day desktop or mobile computer, you got the CPU, the RAM, the GPU and it's own video RAM. When a modern OS renderes an image to the screen, where is the actual image data for that screen located? (Talking about a default HDMI output port)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it within the memory of the OS Kernel in RAM, fetching the rendered image of an onscreen window from the GPU when preparing the next frame?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it within the GPUs VRAM, accessed and manipulated by low level CPU instructions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it within the GPUs VRAM, mapped via DMA to the CPUs adress space?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And also, where can I read up on implementing some of these basic access patterns for a custom written science project OS? A friend of mine managed to get the SVGA mode running in assembly, but I guess one can do more.&lt;/p&gt;&#xA;" OwnerUserId="2623" LastActivityDate="2016-04-08T06:34:40.257" Title="Where is the shown display image actually stored and accessed?" Tags="&lt;memory&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2011" PostTypeId="1" CreationDate="2016-02-07T23:01:51.920" Score="3" ViewCount="1818" Body="&lt;p&gt;I am using a single VBO to store vertices in the follow format:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;v1X, v1Y, v1Z, v1R, v1G, v1B, v2A,&#xA;v2X, ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex positioning is fine, shapes show up where expected, however instead of using the colour provided, all shapes show up red.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code given below simply draws two triangles to form one square ground shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Buffer data preparation method&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void prepare(float[] data) {&#xA;    glBindBuffer(GL_ARRAY_BUFFER, vboID);&#xA;    FloatBuffer dataBuffer = RenderUtils.fArrayToBuffer(data);&#xA;    if(dataLength != data.length) {&#xA;        glBufferData(GL_ARRAY_BUFFER, dataBuffer, GL_STATIC_DRAW);&#xA;        dataLength = data.length;&#xA;    } else {&#xA;        glBufferSubData(GL_ARRAY_BUFFER, 0, dataBuffer);&#xA;    }&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, false, 7*4, 0);&#xA;    glVertexAttribPointer(3, 4, GL_FLOAT, false, 7*4, 3*4);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Render code&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;floorObj.prepare(new float[]{&#xA;    -5, 0, -5,   1, 0, 0, 1,&#xA;    5, 0, -5,   0, 1, 0, 1,&#xA;    -5, 0, 5,   0, 0, 1, 1,&#xA;&#xA;    5, 0, -5,   1, 0, 0, 1,&#xA;    5, 0, 5,   0, 1, 0, 1,&#xA;    -5, 0, 5,   0, 0, 1, 1,&#xA;});&#xA;glDrawArrays(GL_TRIANGLES, 0, 6);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vertex shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;in vec3 position;&#xA;in vec4 i_color;&#xA;out vec4 color;&#xA;&#xA;uniform mat4 transform;&#xA;&#xA;void main(){&#xA;    gl_Position = transform * vec4(position, 1);&#xA;    color = i_color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;in vec4 color;&#xA;out vec4 f_color;&#xA;&#xA;void main(){&#xA;    f_color = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As previously stated, vertex positions work fine, however colour does not.&#xA;Just ask if any other code would be useful to determine the problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks, - Jasper&lt;/p&gt;&#xA;" OwnerUserId="2622" LastActivityDate="2016-08-31T14:45:32.937" Title="OpenGL - Colours not working properly" Tags="&lt;opengl&gt;&lt;color&gt;" AnswerCount="3" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2012" PostTypeId="2" ParentId="1901" CreationDate="2016-02-08T02:09:01.450" Score="1" Body="&lt;p&gt;why not building a bounding box (or spheres) hierarchy ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(but for a shadertoy implementation, the lack of dynamic loop length might spoil the gain ).&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-02-08T02:09:01.450" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2013" PostTypeId="1" CreationDate="2016-02-08T12:46:04.260" Score="4" ViewCount="127" Body="&lt;p&gt;The documentation of &lt;code&gt;glFramebufferRenderbuffer&lt;/code&gt; only says that &lt;code&gt;renderbuffertarget&lt;/code&gt; needs to be &lt;code&gt;GL_RENDERBUFFER&lt;/code&gt;, though it does not specify that the attached renderbuffer, that is also given to the function, needs to be bound to &lt;code&gt;GL_RENDERBUFFER&lt;/code&gt; beforehand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I deem it not having to be so, because why would I have to specify the renderbuffer again if it should be bound beforehand?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Especially since the glNamedFramebufferRenderbuffer was introduced, it should not be nesseccary to bind anything.&lt;/p&gt;&#xA;" OwnerUserId="2623" LastActivityDate="2016-12-16T16:20:27.710" Title="Renderbuffer needs to be bound before glFramebufferRenderbuffer?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2014" PostTypeId="1" CreationDate="2016-02-08T13:56:57.303" Score="5" ViewCount="316" Body="&lt;p&gt;I am implementing a simple Phong shader in OpenGL GLSL, and the test object is the utah teapot. However on the bottom I get a solid red circle, and on the top there is are sharp sectors that are coloured incorrectly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way to fix these issues? What would be the issue in the first place?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yn0z3.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yn0z3.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dlC2c.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dlC2c.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2630" LastActivityDate="2016-02-11T17:05:52.757" Title="Artefacts on top and bottom of utah teapot" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="2016" PostTypeId="1" CreationDate="2016-02-09T07:58:32.120" Score="2" ViewCount="135" Body="&lt;p&gt;I recently started to create a shadow mapping system in OpenTK.&#xA;I ran into a problem: The depthtexture is always completly white -&gt; no depth. Even if the color from the shader is changed (I know it shouldn't effect anything.).&#xA;Here is my shadow mapper class:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class ShadowMapper&#xA;{&#xA;    static int frameBuffer = 0;&#xA;    static int depthTexture;&#xA;    static readonly int shadowMapResolution = 1024;&#xA;    static ShadowShader shader;&#xA;    public static void Init()&#xA;    {&#xA;        shader = new ShadowShader();&#xA;&#xA;        frameBuffer = GL.GenFramebuffer();&#xA;        GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);&#xA;        depthTexture = GL.GenTexture();&#xA;        GL.BindTexture(TextureTarget.Texture2D, depthTexture);&#xA;        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent16, shadowMapResolution, shadowMapResolution, 0, PixelFormat.DepthComponent, PixelType.Float, (IntPtr)null);&#xA;        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);&#xA;        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);&#xA;        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);&#xA;        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);&#xA;&#xA;        GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, depthTexture, 0);&#xA;&#xA;        GL.DrawBuffer(DrawBufferMode.None);&#xA;        Console.WriteLine(GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) == FramebufferErrorCode.FramebufferComplete);&#xA;        GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);&#xA;    }&#xA;&#xA;    public static void Render(Dictionary&amp;lt;TexturedModel, List&amp;lt;Entity&amp;gt;&amp;gt; entities, Light sun)&#xA;    {&#xA;        Matrix4 depthProjectionMatrix = Matrix4.CreateOrthographic(-10, 10, -10, 10);&#xA;        Matrix4 depthViewMatrix = Matrix4.LookAt(sun.Position, sun.ToLookPosition, new Vector3(0, 1, 0));&#xA;&#xA;        GL.BindTexture(TextureTarget.Texture2D, 0);&#xA;        GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer);&#xA;        GL.Viewport(0, 0, shadowMapResolution, shadowMapResolution);&#xA;&#xA;        GL.Enable(EnableCap.DepthTest);&#xA;        GL.Clear(ClearBufferMask.DepthBufferBit);&#xA;        shader.Start();&#xA;        foreach (TexturedModel model in entities.Keys)&#xA;        {&#xA;            RawModel rawModel = model.Model;&#xA;            GL.BindVertexArray(rawModel.VaoID);&#xA;            GL.EnableVertexAttribArray(0);&#xA;            foreach (Entity entity in entities[model])&#xA;            {&#xA;                Matrix4 depthModelMatrix = Maths.CreateTransformationMatrix(entity.Position, entity.RotationX, entity.RotationY, entity.RotationZ, entity.Scale);&#xA;                Matrix4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix;&#xA;                shader.LoadMvpMatrix(depthMVP);&#xA;&#xA;                GL.DrawElements(PrimitiveType.Triangles, rawModel.VertexCount, DrawElementsType.UnsignedInt, 0);&#xA;            }&#xA;        }&#xA;&#xA;        GL.DisableVertexAttribArray(0);&#xA;        GL.BindVertexArray(0);&#xA;        GL.Disable(EnableCap.DepthTest);&#xA;        shader.Stop();&#xA;        GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);&#xA;        GL.Viewport(0, 0, Window.Instance.Width, Window.Instance.Height);&#xA;    }&#xA;&#xA;    public static int DepthTexture&#xA;    {&#xA;        get&#xA;        {&#xA;            return depthTexture;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And my vertex/fragment shaders:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; Vertex Shader:&#xA; #version 330 core&#xA;&#xA;// Input vertex data, different for all executions of this shader.&#xA;in vec3 vertexPosition_modelspace;&#xA;&#xA;// Values that stay constant for the whole mesh.&#xA;&#xA;uniform mat4 depthMVP;&#xA;&#xA;void main(){&#xA;&#xA;gl_Position =  depthMVP * vec4(vertexPosition_modelspace,1);&#xA;&#xA;}&#xA;&#xA;&#xA;Fragment Shader:&#xA; #version 330 core&#xA;&#xA;&#xA;&#xA; // Ouput data&#xA;&#xA; out float fragmentdepth;&#xA; out vec4 out_colour;&#xA;&#xA;&#xA; void main(){&#xA;&#xA; // Not really needed, OpenGL does it anyway&#xA;&#xA; fragmentdepth = gl_FragCoord.z;&#xA; out_colour = vec4(1.0, 0.0, 0.0, 0.0);&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any help?&lt;/p&gt;&#xA;" OwnerUserId="2637" LastActivityDate="2016-02-09T07:58:32.120" Title="Shadow Mapping Errors" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;shadow&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2017" PostTypeId="2" ParentId="2014" CreationDate="2016-02-09T09:34:49.827" Score="4" Body="&lt;p&gt;I'm fairly certain your problem lies in not handling so-called &lt;em&gt;degenerate&lt;/em&gt; Bezier patches correctly, in particular (as &lt;a href=&quot;https://computergraphics.stackexchange.com/users/38/joojaa&quot;&gt;Joojaa&lt;/a&gt; noted), the computation of the surface normal.  I say &lt;em&gt;&quot;so-called degenerate&quot;&lt;/em&gt; because, geometrically, the surfaces are often perfectly well behaved. It's just that some assumptions people frequently make regarding the parametric equations may not hold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Books such as Gerald Farin's, snappily titled, &lt;em&gt;&quot;Curves and Surfaces for CAGD. A Practical Guide&quot;&lt;/em&gt; will give more details, but I'll try to summarise two simple cases. Now assuming your Bezier is defined as $\bar{B}(u,v)$ the usual two causes of problems are:&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Zero derivatives:&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;To compute the normal at $(a,b)$ one normally (pardon the pun) computes the two derivatives,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{\partial }{\partial v}\bar{B}(a,b)$ and $\frac{\partial }{\partial u}\bar{B}(a,b)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;or scaled versions thereof&lt;/em&gt;, to obtain two tangents and then take the cross product. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(&lt;em&gt;Implementation note: Since we can use a scaled version of the tangent in the calculation, we really don't have to calculate the actual derivative. For example, especially at the corners, differences of control points can yield a scaled tangent. However for brevity in this discussion we will assume the actual derivatives&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A common occurrence, at least at the corners, is that the 1st partial derivatives at the location can be zero, which leads to an incorrect normal, i.e. a zero vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of the tops and bottoms of the teapot, one whole edge of a number of the (bicubic) Bezier patches has been collapsed to a point, i.e. all 4 control points are the same, and thus, say &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\bar{B}(0,v)==\bar{B}(1,v)$   and   $\frac{\partial }{\partial u}\bar{B}(0,0)=\bar{0}$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The surface, however, is completely well behaved so you can simply choose another derivative that starts at that collapsed point. In this case, say, choosing&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{\partial }{\partial v}\bar{B}(1,0)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for the second tangent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said this, you &lt;em&gt;still&lt;/em&gt; have to check that your first derivatives are not zero for another reason (e.g 2 or 3 coincident control points), in which case, you can fall back (thanks to L'Hopital's rule) on the second (or if that's zero, even the third!) derivative(s) to obtain valid tangents.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Parallel tangents:&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Another similar problem can arise if your two tangents, are &lt;em&gt;parallel&lt;/em&gt;. - Farin has a good example in his book. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, I &lt;em&gt;think&lt;/em&gt; you may need to look at using something like $\frac{\partial^2 }{\partial u \partial v}\bar{B}$ or, possibly, just fall back to using a small UV offset to approximate a vector.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-02-11T17:05:52.757" LastActivityDate="2016-02-11T17:05:52.757" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2018" PostTypeId="1" AcceptedAnswerId="2020" CreationDate="2016-02-09T12:07:56.817" Score="17" ViewCount="11749" Body="&lt;p&gt;In recent games I have noticed something called Tessellation, Turning the thing ON destroys my frame rate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have noticed that it when turned on it looks like Anti - Aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone give me further information on what exactly the GPU does.&lt;/p&gt;&#xA;" OwnerUserId="2641" LastActivityDate="2016-02-09T23:53:36.433" Title="What is Tessellation in computer graphics" Tags="&lt;pixel-graphics&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2019" PostTypeId="2" ParentId="2018" CreationDate="2016-02-09T12:59:18.023" Score="7" Body="&lt;p&gt;It activate 3 stages in the pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first is the tessellation control shader (hull shader in D3D) which looks at a set of vertices and then outputs how it should be divided up in separate triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second is a fixed function stage that will generate the requested triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The third stage the tessellation evalutation shader (domain shader in D3D) which is run per generated vertex and will put it in the correct place based on the barycentric coordinates of the generated vertex. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is used for level of detail to generate more triangles when the mesh is closer to the camera.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-02-09T12:59:18.023" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2020" PostTypeId="2" ParentId="2018" CreationDate="2016-02-09T13:14:58.337" Score="27" Body="&lt;p&gt;Tesselation is a technique that allows you to generate primitives (triangles, lines, points and such) on the graphics-card. Specifically, it lets you repeatedly subdivide the current geometry into a finer mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This allows you to load a relatively coarse mesh on your graphics card, generate more vertices and triangles dynamically and then have a mesh on the screen that looks much smoother.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uT6do.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uT6do.jpg&quot; alt=&quot;Tessellation example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the time this tesselation is done anew in each single frame and this could be the reason that your frame-rate drops once you enable this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Tesselation is done in multiple stages, and it is done AFTER the vertex shader. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/31tTU.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/31tTU.png&quot; alt=&quot;Stages&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The terms for each stage varies based on the API. In DirectX, it is the Hull Shader, Hardware Tessellation, and the Domain Shader. In OpenGL, they are called the Tessellation Control Shader, Tesselation Primitive Generation, and the Tessellation Evaluation Shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first and the last stage is programmable, the actual tesselation is done by the hardware in a fixed function stage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the Tesselation Control shader you set the type and number of subdivisions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the hardware tessellator divides the geometry according to the Control Shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, the Tessellation Evaluation Shader is called for each newly generated vertex. In this shader, you set the type of primitive you want to generate and how the vertices are spaced and many other things. This shader can also be used to do all sorts of per-vertex calculations just like a vertex shader. It is guaranteed to be called at least once for each generated vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to do any further work on the primitives, you can add a Geometry shader.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="273" LastEditDate="2016-02-09T23:53:36.433" LastActivityDate="2016-02-09T23:53:36.433" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2021" PostTypeId="1" CreationDate="2016-02-09T17:21:34.743" Score="6" ViewCount="1390" Body="&lt;p&gt;Completely stuck on how to do this. Yes, it is a homework problem, but its the first we've had in the class so not too familiar with graphics. Also, seeing as its homework, please don't just give the answer, just some pointers in the right direction would be great.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried to do it as a triangle fan, and as a polygon but that just ends up in really weird shapes.&lt;/p&gt;&#xA;" OwnerUserId="2645" LastActivityDate="2016-02-10T15:22:58.323" Title="OpenGL with SFML, create an n-pointed star?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2023" PostTypeId="1" AcceptedAnswerId="2028" CreationDate="2016-02-09T18:48:52.057" Score="5" ViewCount="321" Body="&lt;p&gt;I'm attempting to model a simple graphics pipeline - using Matlab at the moment as a modelling tool to get the transformations correct. I appreciate there are software tools that would make this easier - but I'm looking to understand the maths behind it and hence am looking to mostly use simple functions &amp;amp; matrices that I'm learning from a &lt;a href=&quot;http://www.amazon.co.uk/3D-Computer-Graphics-Alan-Watt/dp/0201398559&quot; rel=&quot;nofollow noreferrer&quot;&gt;book&lt;/a&gt; (very retro!).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've successfully got through the stages of defining simple objects and converting them into a universal world space - but have come unstuck with the mathematics required to convert an object into view space and the back face culling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe my view space transformation is correct because when I plot the composite vectors they appear correct - but - when I do the back-face culling, it seems to fail to remove the correct triangles. Given that it depends only on two things, the line-of-sight vector and face normals, I can't work out what I'm doing wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When defining the triangles in local definition space, I did it so that all the normals pointed outwards. I've put my results into the image below&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XeAiI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XeAiI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My questions are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Have I gone wrong, or are my expectations incorrect?&lt;/li&gt;&#xA;&lt;li&gt;If so where, and how do I fix?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2&gt;Progress&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I've plotted the normal's of all the shapes when in view space. They have all been inverted and now point inwards. Is this a property of the transformation and could it be responsible - or should this have no effect because all the polygons are affected the same?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Have changed the code to show this)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;clc; clear all; close all;&#xA;%============Initial verticies &amp;amp; Faces of the shape===========&#xA;[s1_vtx,s1_fcs] = Pyramid();&#xA;[s2_vtx,s2_fcs] = Cube();&#xA;%==============Transform Shape 1 ======================&#xA;Tx = 0; Ty = 0; Tz = 0; %Translation vectors for x,y,z axes&#xA;Sx = 2; Sy = 2; Sz = 2;%Scaling factors in x,y,z dimensions&#xA;Rx = pi/2; Ry = pi/4; Rz = pi/4; %Rotating factors in x,y,z dimensions&#xA;transform = scale(Sx,Sy,Sz)*rotate(Rx,0,0)*translate(Tx,Ty,Tz); %Merge transforms together&#xA;s1_vtx = transform*vertcat(s1_vtx,(ones(1,length(s1_vtx)))); %Add row of ones to end for multiplication&#xA;s1_vtx = s1_vtx(1:3,:); %And remove afterwards&#xA;%==============Transform Shape 2 ======================&#xA;Tx = 0.5; Ty = 0; Tz = 0.5;&#xA;transform = scale(1,2,1)*translate(Tx,Ty,Tz);&#xA;s2_vtx = transform*vertcat(s2_vtx,(ones(1,length(s2_vtx))));&#xA;s2_vtx = s2_vtx(1:3,:);&#xA;%======Create World Space ===========&#xA;ws_vtx = horzcat(s1_vtx(1:3,:), s2_vtx(1:3,:)); %remove homogenous column for patching&#xA;ws_fcs = horzcat(s1_fcs,(s2_fcs+(length(s1_vtx))));&#xA;%======Plot World Space ===========&#xA;grid on; hold on;&#xA;scatter3(ws_vtx(1,:),ws_vtx(2,:),ws_vtx(3,:)) %Plot all the points&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx','Facecolor', 'none');&#xA;for i = 1:length(ws_vtx)&#xA;    str = sprintf('%d',i);&#xA;    text(ws_vtx(1,i),ws_vtx(2,i),ws_vtx(3,i), str,'FontSize',16, 'Color','r', 'FontWeight','b');&#xA;end&#xA;points = zeros(3,3); %Contains 1 triangle&#xA;for i = 1:length(ws_fcs); %For each triangle&#xA;    points(:,1:3) = ws_vtx(:,ws_fcs(1:3,i));&#xA;    U = points(:,2) - points(:,1); %Get two non-parallel vectors&#xA;    V = points(:,3) - points(:,1);&#xA;    average = [0,0,0];&#xA;    for j = 1:length(points)&#xA;        average(j) = (points(j,1) + points(j,2) + points(j,3))/3;&#xA;    end&#xA;    N = cross(U,V)/norm(cross(U,V)); %Normal, normalised to mag 1&#xA;    scatter3(average(1),average(2),average(3));&#xA;    plot3([average(1), average(1)+N(1)],[average(2), average(2)+N(2)],[average(3), average(3)+N(3)]);&#xA;end&#xA;%==================Create view matrix===================&#xA;focus = [1.5,0,1.5]; %The point we're looking at&#xA;Cx = 3; Cy = -3; Cz = 3; %Position of camera&#xA;Vspec = [0;0;1]; %Specified up direction&#xA;T = viewMat(focus, [Cx,Cy,Cz],Vspec); %Create viewspace transform matrix&#xA;p = norm(focus - [Cx,Cy,Cz]);&#xA;U = T(1,1:3); V = T(2,1:3); N = T(3,1:3); %New Up, Right &amp;amp; View direction vectors&#xA;%============Plot the camera vectors=================&#xA;scatter3(Cx,Cy,Cz,'s') %Plot the camera position&#xA;plot3([Cx, Cx+p*N(1)],[Cy, Cy+p*N(2)],[Cz, Cz+p*N(3)]);&#xA;plot3([Cx, Cx+V(1)],[Cy, Cy+V(2)],[Cz, Cz+V(3)]);&#xA;plot3([Cx, Cx+U(1)],[Cy, Cy+U(2)],[Cz, Cz+U(3)]);&#xA;%==================Transform into View Space===================&#xA;ws_vtx = T*vertcat(ws_vtx,(ones(1, length(ws_vtx)))); %Transform matrix&#xA;ws_vtx = ws_vtx(1:3,:); %Remove homogenous dimension&#xA;origin = T*[Cx;Cy;Cz;1]; %Transform origin&#xA;Cx = origin(1); Cy = origin(2); Cz = origin(3); %remove homogenous dimension&#xA;focus = (T*horzcat(focus,1)')';%Transform focus point&#xA;focus = focus(:,1:3);%remove homogenous dimension&#xA;%==================Plot View Space=================&#xA;figure(); hold on; grid on;&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx','Facecolor', 'none');&#xA;scatter3(Cx, Cy, Cz, 's');&#xA;scatter3(focus(1), focus(2), focus(3), 's');&#xA;plot3([Cx, focus(1)],[Cy, focus(2)],[Cz,focus(3)], 'g');&#xA;for i = 1:length(ws_vtx)&#xA;    str = sprintf('%d',i);&#xA;    text(ws_vtx(1,i),ws_vtx(2,i),ws_vtx(3,i), str,'FontSize',16, 'Color','r', 'FontWeight','b');&#xA;end&#xA;%================Plot normals of world space==============&#xA;for i = 1:length(ws_fcs); %For each triangle&#xA;    points(:,1:3) = ws_vtx(:,ws_fcs(1:3,i));&#xA;&#xA;    U = points(:,2) - points(:,1); %Get two non-parallel vectors&#xA;    V = points(:,3) - points(:,1);&#xA;&#xA;    average = [0,0,0];&#xA;    for j = 1:length(points)&#xA;        average(j) = (points(j,1) + points(j,2) + points(j,3))/3;&#xA;    end&#xA;    N = cross(U,V)/norm(cross(U,V)); %Normal, normalised to mag 1&#xA;    scatter3(average(1),average(2),average(3));&#xA;    plot3([average(1), average(1)+N(1)],[average(2), average(2)+N(2)],[average(3), average(3)+N(3)]);&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2646" LastEditorUserId="231" LastEditDate="2016-02-13T01:12:51.580" LastActivityDate="2016-02-13T01:12:51.580" Title="Graphics Pipeline: Viewspace &amp; Back face culling incorrectly" Tags="&lt;transformations&gt;&lt;3d&gt;&lt;matrix&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2024" PostTypeId="2" ParentId="2021" CreationDate="2016-02-09T19:57:51.373" Score="2" Body="&lt;p&gt;A simple way would be to think about how you can decompose your star into triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then just draw these triangles. Not as a triangle-fan since those may be a bit strange to use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since triangles are one of the most basic and standard ways to draw all kinds of meshes and shapes (every polygon can be triangulated as far as I know), I suggest du don't use the polygon draw as a beginner. Begin with the basic stuff everyone uses.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-02-09T19:57:51.373" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2026" PostTypeId="2" ParentId="2021" CreationDate="2016-02-09T21:44:18.417" Score="3" Body="&lt;p&gt;Try starting at the origin, then dividing 360 degrees by n to find some useful angles for the points of your star.&#xA;I hope this drawing will help you to find a solution.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CCGsh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CCGsh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that you have the angle theta, and the values of alpha and x are chosen by you, you have the tools to calculate all required vertices to make the star using trigonometry.&lt;/p&gt;&#xA;" OwnerUserId="2651" LastEditorUserId="2651" LastEditDate="2016-02-10T15:22:58.323" LastActivityDate="2016-02-10T15:22:58.323" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2028" PostTypeId="2" ParentId="2023" CreationDate="2016-02-10T13:29:37.180" Score="6" Body="&lt;p&gt;I (believe) I've solved this (even if it has taken 2 days). My problem was essentially I wanted to take the dot product of the face normal, and line-of-sight vector like below&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zf6LH.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zf6LH.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And determine the angle to see if the face was looking towards or away from the view point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My erroneous step was that I was doing this AFTER transforming from world-space to view-space - hence the line-of-sight vector I was using was no longer valid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence, to solve this, I simply performed the back-face culling in world-space, prior to the world-view space transformation!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've included functioning code showing the back face culling, but not the view-space transform.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;clear; clc; close all;&#xA;%======Create World Space (hard-coded values for demo) ===========&#xA;ws_vtx = [0,2,0,2,1,0.5,1.5,0.5,1.5,0.5,1.5,0.5,1.5;&#xA;    0,0,0,0,-2,0,0,2,2,0,0,2,2;&#xA;    0,0,2,2,1,0.5,0.5,0.5,0.5,1.5,1.5,1.5,1.5];&#xA;ws_fcs = [1,2,4,3,3,1,6,6,6,6,7,7,9,8,8,8,10,10;&#xA;    2,4,3,1,4,4,9,8,7,11,9,13,8,12,10,6,11,13;&#xA;    5,5,5,5,1,2,7,9,11,10,13,11,13,13,12,10,13,12];&#xA;%==================Create view matrix===================&#xA;focus = [1.5,0,1.5]; %The point we're looking at&#xA;Cx = 3; Cy = -3; Cz = 3; %Position of camera&#xA;Vspec = [0;0;1]; %Specified up direction&#xA;T = viewMat(focus, [Cx,Cy,Cz],Vspec); %Create viewspace transform matrix&#xA;p = norm(focus - [Cx,Cy,Cz]);&#xA;U = T(1,1:3); V = T(2,1:3); N = T(3,1:3); %New Up, Right &amp;amp; View direction vectors&#xA;%============Plot the camera vectors=================&#xA;grid on; hold on; scatter3(Cx,Cy,Cz,'s'); %Plot the camera position&#xA;plot3([Cx, Cx+p*N(1)],[Cy, Cy+p*N(2)],[Cz, Cz+p*N(3)],'g');&#xA;plot3([Cx, Cx+V(1)],[Cy, Cy+V(2)],[Cz, Cz+V(3)],'g');&#xA;plot3([Cx, Cx+U(1)],[Cy, Cy+U(2)],[Cz, Cz+U(3)],'g');&#xA;%===========Get Face Normals============================&#xA;norm_fcs = zeros(3,length(ws_fcs)); &#xA;    for i = 1:length(ws_fcs); %For each triangle&#xA;        points = zeros(3,3); %Contains 1 triangle&#xA;        points(:,1:3) = ws_vtx(:,ws_fcs(1:3,i)); %Get points for triangle&#xA;        U = points(:,2) - points(:,1); %Get two non-parallel vectors&#xA;        V = points(:,3) - points(:,1);&#xA;        norm_fcs(:,i) = cross(U,V); %Normal, normalised to mag 1&#xA;    end&#xA;%=================Back Face Culling======================&#xA;null_vals = 0;&#xA;for i = 1:length(ws_fcs) %Take each triangle &amp;amp; calculate normal&#xA;    if dot(norm_fcs(:,i), N) &amp;gt; 0 %Dot product line of sight &amp;amp; normal of faces&#xA;        ws_fcs(:,i) = [0;0;0]; %If &amp;gt; 0, not visible &amp;amp; remove&#xA;        null_vals = null_vals + 1; %And increment counter&#xA;    end&#xA;end&#xA;ws_fcs_cat = zeros(3, length(ws_fcs) - null_vals); %Create new array&#xA;null_vals = 0;&#xA;for i = 1:length(ws_fcs)&#xA;    if norm(ws_fcs(:,i)) == 0&#xA;        null_vals = null_vals + 1;&#xA;    else&#xA;        ws_fcs_cat(:,i - null_vals) = ws_fcs(:,i);&#xA;    end&#xA;end&#xA;ws_fcs = ws_fcs_cat;&#xA;%======Plot World Space ===========&#xA;scatter3(ws_vtx(1,:),ws_vtx(2,:),ws_vtx(3,:)) %Plot all the points&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx','Facecolor', 'r', 'FaceAlpha', 0.5);&#xA;for i = 1:length(ws_vtx)&#xA;    str = sprintf('%d',i);&#xA;    text(ws_vtx(1,i),ws_vtx(2,i),ws_vtx(3,i), str,'FontSize',16, 'Color','r', 'FontWeight','b');&#xA;end&#xA;points = zeros(3,3); %Contains 1 triangle&#xA;for i = 1:length(ws_fcs); %For each triangle&#xA;    points(:,1:3) = ws_vtx(:,ws_fcs(1:3,i));&#xA;    U = points(:,2) - points(:,1); %Get two non-parallel vectors&#xA;    V = points(:,3) - points(:,1);&#xA;    average = [0,0,0];&#xA;    for j = 1:length(points)&#xA;        average(j) = (points(j,1) + points(j,2) + points(j,3))/3;&#xA;    end&#xA;    N = cross(U,V)/norm(cross(U,V)); %Normal, normalised to mag 1&#xA;    scatter3(average(1),average(2),average(3));&#xA;    plot3([average(1), average(1)+N(1)],[average(2), average(2)+N(2)],[average(3), average(3)+N(3)]);&#xA;end&#xA;xlabel('x'); ylabel('y'); zlabel('z');&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2646" LastActivityDate="2016-02-10T13:29:37.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2029" PostTypeId="1" CreationDate="2016-02-11T04:07:50.647" Score="7" ViewCount="552" Body="&lt;p&gt;I'm a beginner in OpenGL and I've been doing some research on the topic of shaders and attributes. Most places I go say that explicit attribute binding (whether it be in the shader itself with &lt;code&gt;layout(location=x)&lt;/code&gt; or with &lt;code&gt;glBindAttribLocation&lt;/code&gt;) is better than letting OpenGL generate some attribute number. However, I didn't completely understand WHY explicit attribute binding is better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I guess my question is, what are the pros/cons to explicit/automatic attribute binding, and which one is more conducive to better program design overall?&lt;/p&gt;&#xA;" OwnerUserId="2651" LastActivityDate="2018-08-08T08:35:00.123" Title="Explicit vs Automatic Attribute Binding" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2030" PostTypeId="1" CreationDate="2016-02-11T10:06:35.107" Score="6" ViewCount="199" Body="&lt;p&gt;I am implementing a simple ray tracer with OpenGL. I have a shader storage buffer with all the triangles so I can test them for intersections in a compute shader. It works fine up to a certain buffer size. But if I have more than a certain amount, it stops working and I get the following message:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;OpenGL: Buffer usage warning: Discarding a video memory only buffer object. The data store will be reallocated on next usage of the buffer object.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The program does not crash however.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;GL_MAX_SHADER_STORAGE_BLOCK_SIZE&lt;/code&gt; is 2147483647, so 2GB. The size of the buffer when it doesn't work anymore is just a couple of MB, around 6 to 7 MB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I overlooking something? Are there other limits I don't know about?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My specs: Linux Mint 17.2, GTX 980Ti with 6GB of VRAM&lt;/p&gt;&#xA;" OwnerUserId="2666" LastEditorUserId="2666" LastEditDate="2016-03-31T11:34:58.573" LastActivityDate="2016-03-31T18:59:31.903" Title="Cannot use more than a couple of MB in a shader storage buffer" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="16" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2031" PostTypeId="1" AcceptedAnswerId="2032" CreationDate="2016-02-11T12:57:13.237" Score="6" ViewCount="1632" Body="&lt;p&gt;What 3D scene reconstruction methods does the term &quot;multi-view stereo&quot; encompass? Is it only used for methods that apply binocular stereo algorithms (taking 2 views as input) in a pairwise manner? Or only methods based on disparity estimation? If not why is the term &quot;stereo&quot; used?&lt;/p&gt;&#xA;" OwnerUserId="2670" LastEditorUserId="231" LastEditDate="2016-02-11T19:48:54.940" LastActivityDate="2016-02-11T19:48:54.940" Title="What is stereo about multi-view stereo?" Tags="&lt;3d&gt;&lt;depth-map&gt;&lt;photometric&gt;&lt;scene-description&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2032" PostTypeId="2" ParentId="2031" CreationDate="2016-02-11T15:08:51.003" Score="5" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Multi-view stereo (MVS) is the general term&#xA;given to a group of techniques that use stereo correspondence as their&#xA;main cue and use more than two images.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;A quote from &lt;a href=&quot;http://www.cse.wustl.edu/%7Efurukawa/papers/fnt_mvs.pdf&quot; rel=&quot;noreferrer&quot;&gt;'Multi-View Stereo: A Tutorial'&lt;/a&gt; by Yasutaka Furukawa and Carlos Hernández.&lt;/p&gt;&#xA;&lt;p&gt;So to paraphrase: We have a set of images that is larger than two, and use them in a pairwise manner by applying techniques that finde stereo correspondences to reconstruct the object shown in them.&lt;/p&gt;&#xA;&lt;p&gt;If you want to know more about MVS algorithms that paper I linked seems to be pretty good and at least Furukawa is a name that I know and have read papers from, so he seems to know the topic.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-02-11T15:08:51.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2034" PostTypeId="1" AcceptedAnswerId="2038" CreationDate="2016-02-12T08:05:05.823" Score="16" ViewCount="2327" Body="&lt;p&gt;Why is it that when you zoom in to some black text you find that it is made up of orange, slightly black and blue pixels like the picture below. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0gIia.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0gIia.png&quot; alt=&quot;Black text zoomed in&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2673" LastEditorUserId="38" LastEditDate="2016-02-12T20:14:59.897" LastActivityDate="2018-08-21T09:45:54.990" Title="why does black text have orange and blue pixels" Tags="&lt;antialiasing&gt;&lt;font-rendering&gt;&lt;subpixel-rendering&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2035" PostTypeId="1" AcceptedAnswerId="2036" CreationDate="2016-02-12T13:32:56.290" Score="6" ViewCount="1790" Body="&lt;p&gt;For a non-computer graphics expert, what happens technically when you do this? Are multiple pixels merged to one to compensate for the lower resolution? And in how far will this affect the image quality?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would a high resolution image look sharper on a low resolution display than if the same image would have the exact same resolution as the screen?&lt;/p&gt;&#xA;" OwnerUserId="2633" LastActivityDate="2016-02-12T13:50:28.900" Title="What happens when you display a high resolution image on a low resolution screen?" Tags="&lt;texture&gt;&lt;image&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2036" PostTypeId="2" ParentId="2035" CreationDate="2016-02-12T13:50:28.900" Score="2" Body="&lt;p&gt;If you scale an image down to a screen that has a lower resolution than yout image, you have to descide what you do, there is no single way of doing this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many different techniques that yield very different results.&#xA;This is very similar to displaying a low resolution image on a high resolution display where do the inverse thing by desciding how to fill the &quot;more&quot; pixels on the screen. There are also many techniques for doing this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YQKdg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YQKdg.png&quot; alt=&quot;Image scaling comparison. Nearest-neighbor scaling (left) and 2*Sal scaling (right).&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image shows two upscaling-techniques and shows how different the results can look if different techniques are used. (A nearest-neighbor scaling on the left and a 2*Sal on the right.) Imagine that there are also such differences if you downscale an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find a nice overview on different scaling techniques on the wikipedia page for &lt;a href=&quot;https://en.wikipedia.org/wiki/Image_scaling&quot; rel=&quot;nofollow noreferrer&quot;&gt;Image scaling&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-02-12T13:50:28.900" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2037" PostTypeId="1" AcceptedAnswerId="2047" CreationDate="2016-02-12T18:22:24.593" Score="3" ViewCount="1118" Body="&lt;p&gt;I am attempting to model a simple graphics pipeline (i.e. Local-&gt;Word-&gt;View-&gt;Screen-&gt;2D spaces).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been looking at the algorithm required to transform from world to view-space and using the following transform&lt;a href=&quot;https://i.stack.imgur.com/NKmCc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NKmCc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although I have been using U,V,N,C notation rather than Xc,Yc,Zc,e.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And my matrix transformation at first glance, appears correct: When I plot the vectors onto world space, I get a vector from the camera position to the point we're looking at, and two correctly placed new X and Y vectors (see the left hand image below).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RavTO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RavTO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By looking along the line of sight vector (such that it disappears,and the focus &amp;amp; camera points overlap), as in the middle figure, should (I believe?) give an accurate example of what the resultant viewspace transformation should look like, with the green vertical and right-pointing vectors showing the new X &amp;amp; Y vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However - when I actually do the view space transform I don't get the middle figure, instead, the resultant transform seems to be looking at the object from a different position possibly aligned with one of the axes? This is shown in the right hand figure - which is actually looking at the object from a slightly lower perspective &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is essentially what have I done wrong, or am I misunderstanding both the transform and thus my results?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks very much,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;David&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATES&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After stepping through the code - I discovered that my &lt;a href=&quot;https://books.google.co.uk/books/about/3D_Computer_Graphics.html?id=tQJEAQAAIAAJ&amp;amp;redir_esc=y&quot; rel=&quot;nofollow noreferrer&quot;&gt;source&lt;/a&gt; book was having me convert the line-of-sight vector to spherical coords and then they were being converted straight back again to create R (viewspace coordination matrix). I've eliminated this redundancy (and potential source of errors) but it hasn't solved the problem...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;clear; clc; close all;&#xA;%======Create World Space (hard-coded values for demo) ===========&#xA;ws_vtx = [0,2,0,2,1,0.5,1.5,0.5,1.5,0.5,1.5,0.5,1.5;&#xA;    0,0,0,0,-2,0,0,2,2,0,0,2,2;&#xA;    0,0,2,2,1,0.5,0.5,0.5,0.5,1.5,1.5,1.5,1.5];&#xA;ws_fcs = [1,2,4,3,3,1,6,6,6,6,7,7,9,8,8,8,10,10;&#xA;    2,4,3,1,4,4,9,8,7,11,9,13,8,12,10,6,11,13;&#xA;    5,5,5,5,1,2,7,9,11,10,13,11,13,13,12,10,13,12];&#xA;%==================Create view matrix===================&#xA;focus = [1.5,0,1.5]; %The point we're looking at&#xA;Cx = 3; Cy = -3; Cz = 3; %Position of camera&#xA;Vspec = [0;0;1]; %Specified up direction for view space (i.e. camera orientation)&#xA;vector = focus - [Cx,Cy,Cz]; %Vector camera to focus point &#xA;p = sqrt(vector(1)^2 + vector(2)^2 + vector(3)^2); %Total magnitude of vector&#xA;N = vector'/p;&#xA;V = Vspec - cross(cross(Vspec,N),N); %Create new &quot;up&quot; direction&#xA;U = cross(N,V); %Create new x-axis&#xA;%Create rotational matrix to view space&#xA;R= [U(1),U(2),U(3),0; % U is direction of camera space X axis&#xA;    V(1),V(2),V(3),0; % V is direction of camera space Y axis&#xA;    N(1),N(2),N(3),0;&#xA;    0   ,   0,   0,1];&#xA;Tr = [1,0,0,-Cx;&#xA;      0,1,0,-Cy;&#xA;      0,0,1,-Cz;&#xA;      0,0,0,  1];&#xA;T = R*Tr; %Total view transform = rotation * translation&#xA;%============Plot the camera vectors &amp;amp; World Space=================&#xA;grid on; hold on; xlabel('x'); ylabel('y'); zlabel('z');&#xA;scatter3(Cx,Cy,Cz,'s'); %Plot the camera position&#xA;plot3([Cx, Cx+p*N(1)],[Cy, Cy+p*N(2)],[Cz, Cz+p*N(3)],'g'); %Plot camera vectors&#xA;plot3([Cx, Cx+V(1)],[Cy, Cy+V(2)],[Cz, Cz+V(3)],'g');&#xA;plot3([Cx, Cx+U(1)],[Cy, Cy+U(2)],[Cz, Cz+U(3)],'g');&#xA;scatter3(ws_vtx(1,:),ws_vtx(2,:),ws_vtx(3,:)) %Plot all the points&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx','Facecolor', 'none');&#xA;for i = 1:length(ws_vtx)&#xA;    str = sprintf('%d',i);&#xA;    text(ws_vtx(1,i),ws_vtx(2,i),ws_vtx(3,i), str,'FontSize',14, 'Color','r');&#xA;end&#xA;%====================Viewspace Transform===========================&#xA;ws_vtx = T*vertcat(ws_vtx,(ones(1,length(ws_vtx)))); %Transform worldspace&#xA;ws_vtx = ws_vtx(1:3,:); %Remove homogenous column&#xA;position = T*[Cx;Cy;Cz;1]; focus = T*horzcat(focus,1)'; %Transform set points&#xA;position = position(1:3,:); focus = focus(1:3,:); %Remove homogenous columns&#xA;%================Plot new viewspace===============================&#xA;figure(); grid on; hold on; xlabel('x'); ylabel('y'); zlabel('z');&#xA;scatter3(position(1),position(2),position(3),'s'); %Plot new camera vectors&#xA;scatter3([position(1); position(1)+focus(1)],...&#xA;    [position(2); position(2)+focus(2)],[position(3); position(3)+focus(3)],'s');&#xA;plot3([position(1), focus(1)],[position(2), focus(2)],[position(3), focus(3)],'g');&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx','Facecolor', 'none');&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2646" LastEditorUserId="2646" LastEditDate="2016-02-13T11:12:12.727" LastActivityDate="2016-02-18T22:21:47.970" Title="Correct view-space transform" Tags="&lt;transformations&gt;&lt;matrix&gt;&lt;matlab&gt;&lt;vectors&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2038" PostTypeId="2" ParentId="2034" CreationDate="2016-02-12T20:50:25.683" Score="12" Body="&lt;p&gt;This is called subpixel rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The different primary colors in your monitor are not stacked on top of each other. Instead they are arranged near each other. Different monitors have different patterns but most commonly they are aligned so that the colors are side by side. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you know the physical arrangement, then you can prepare the image so that you have calculated a different sample position for each color channel. In essence your boosting the resolution of your image so that you are treating each individual color as a separate pixel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This, of course, means that you need to know the display orientation and have some data that can be shifted. The image wouldn't be all that useful on other monitors with different pixel alignments. So this is reserved for things that are dynamically generated, most often fonts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It also means that when zoomed or presented on a medium with different or no subpixels, the effect will register as a blur. So zooming in on the pixels of a subpixel rendered image is not very good idea. For this reason it migth be a good idea to disable the effect if you make images for others to use and the subpixel alignment is unknown.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="209" LastEditDate="2018-08-21T09:45:54.990" LastActivityDate="2018-08-21T09:45:54.990" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="2039" PostTypeId="5" CreationDate="2016-02-13T01:11:18.203" Score="0" Body="" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-02-13T01:11:18.203" LastActivityDate="2016-02-13T01:11:18.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2040" PostTypeId="4" CreationDate="2016-02-13T01:11:18.203" Score="0" Body="For questions about scalable 2D graphics based on vector operations, as opposed to raster graphics. For example, polygons, Bézier curves and ellipses." OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-02-13T01:11:18.203" LastActivityDate="2016-02-13T01:11:18.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2041" PostTypeId="1" AcceptedAnswerId="2045" CreationDate="2016-02-13T21:08:08.733" Score="3" ViewCount="176" Body="&lt;p&gt;Open GL and other graphics APIs support floating point formats smaller than 32 bits (e.g. see &lt;a href=&quot;https://www.opengl.org/wiki/Small_Float_Formats&quot; rel=&quot;noreferrer&quot;&gt;https://www.opengl.org/wiki/Small_Float_Formats&lt;/a&gt;). While GPUs seem to handle these formats natively, CPUs have limited support (x86 architecture chips can convert to/from 16 bit floats using the AVX instructions). It is sometimes convenient to pack/unpack these formats on the CPU , but it is not obvious how to do so efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the fastest techniques to convert between 32 bit floating point and the small float formats on the CPU? Are libraries or sample implementations available?&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2018-04-28T03:07:14.553" Title="What are the most efficient ways to convert between f32 and smaller float formats on the CPU?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2042" PostTypeId="1" CreationDate="2016-02-13T22:37:18.643" Score="7" ViewCount="1851" Body="&lt;p&gt;I'm reading Cook's paper &quot;Stochastic Sampling and Distributed Ray Tracing&quot;, I don't understand how the rays are generated. He says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Determine the focal point by constructing a ray from the eye point&#xA;  (center of the lens) through the screen location of the ray. The focal&#xA;  point is located on this ray so its distance from the eye point is&#xA;  equal to the focal distance.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mxQ6c.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mxQ6c.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't parse this image. Where is my screen plane located according to this image? What is the focal point? If you see some optics picture of a thin lens, the focal point is always in the same place, where all the rays converge. If it is always the same point, why do have I to calculate it for each ray?&lt;/p&gt;&#xA;" OwnerUserId="2684" LastEditorUserId="231" LastEditDate="2016-02-14T01:00:16.963" LastActivityDate="2016-02-16T18:38:54.543" Title="Ray tracing with thin lens camera" Tags="&lt;raytracing&gt;&lt;vectors&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2043" PostTypeId="1" AcceptedAnswerId="2054" CreationDate="2016-02-14T07:51:07.610" Score="9" ViewCount="3402" Body="&lt;p&gt;For mesh representation, what is the benefit of using Half Edge over Winged Edge data structure?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand both mesh representations, the only difference is that half edge uses directional edge and winged edge uses undirectional edge. So far, I cannot think of what is the usefulness of using directional edge, yet it only gives more memory consumption.&lt;/p&gt;&#xA;" OwnerUserId="2687" LastEditorUserId="2687" LastEditDate="2016-02-15T09:16:27.533" LastActivityDate="2016-02-16T19:47:22.990" Title="What is the benefit of using Half Edge over Winged Edge?" Tags="&lt;mesh&gt;&lt;polygon&gt;&lt;data-structure&gt;&lt;scene-graph&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2044" PostTypeId="2" ParentId="2042" CreationDate="2016-02-14T16:54:51.157" Score="3" Body="&lt;p&gt;Instead of a screen plane in front of the eye, it describes a film plane, where the image is projected, to explicitly model camera optics. You don't need to compute the focal point in doing ray tracing - it's just a way to find the plane of focus for depth of field effects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For depth of field effects I use a standard perspective projection but jitter the position of the eye on a circle parallel to the focal plane -  and I make sure all my rays for a given pixel go through the same spot on the focal plane making it sharp while stuff in front of or behind that plane ends up blurry. It's a simple model of something like an aperture, and gives pretty good results.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-02-15T02:20:39.040" LastActivityDate="2016-02-15T02:20:39.040" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2045" PostTypeId="2" ParentId="2041" CreationDate="2016-02-14T20:02:18.807" Score="6" Body="&lt;p&gt;You definitely want to check out meticulous half to float and float to half implementations by Fabian Giesen. I don't think there is anything faster than those:&#xA;&lt;a href=&quot;https://gist.github.com/rygorous/2144712&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gist.github.com/rygorous/2144712&lt;/a&gt;&#xA;&lt;a href=&quot;https://gist.github.com/rygorous/2156668&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gist.github.com/rygorous/2156668&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For other formats you will find an implementation in DirectXMath (part of WindowsSDK), Mesa and similar libraries. For example, R11G11B10_Float conversions are implemented by DirectXMath in &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.xmfloat3pk(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;XMFLOAT3PK&lt;/a&gt; and by Mesa in &lt;a href=&quot;https://github.com/grate-driver/mesa/blob/master/src/gallium/auxiliary/util/u_format_other.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;u_format_other.c&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="93" LastEditorUserId="93" LastEditDate="2018-04-28T03:07:14.553" LastActivityDate="2018-04-28T03:07:14.553" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2046" PostTypeId="1" CreationDate="2016-02-15T11:08:29.323" Score="4" ViewCount="1005" Body="&lt;p&gt;In the program I need to create, the user should specify the hull geometry of an aircraft wing and fuselage using cubic bezier polycurves. &#xA;But to get to &lt;code&gt;m&lt;/code&gt; bezier patch surfaces the user would need to introduce &lt;code&gt;4 * m&lt;/code&gt; additional control points. It's not as simple a task as outlining sections in Inkscape. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is whether there is a way to create a bicubic bezier surface having only its edge curves (or maybe any additional curves the user could draw)? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it isn't possible with bezier curves, is there any way to create a 3d model by specifying only section curves? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the answer is no, what way would you suggest to create hull geometry (maybe a bit rough) from another 3D model? &lt;/p&gt;&#xA;" OwnerUserId="2694" LastEditorUserId="231" LastEditDate="2016-02-16T01:33:33.340" LastActivityDate="2016-02-16T17:58:09.817" Title="Bicubic bezier surface from 4 bezier curves" Tags="&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2047" PostTypeId="2" ParentId="2037" CreationDate="2016-02-15T13:39:47.217" Score="2" Body="&lt;p&gt;Your transform looks correct. To transform from world to eye coordinates, I I always use a &quot;lookat&quot; transform, defined by 3 vectors: $\bf{e}$, $\bf{a}$ and $\bf{u}$; in english, the eye position, the point it's looking at, and an up vector, which must not be in the same direction as $\bf{a} - \bf{e}$ (more specifically, not a multiple of it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The space is defined using $\bf{z} = {{(\bf{e} - \bf{a})}\over{|\bf{e} - \bf{a}}|}$, which means the negative z axis points in the direction of what I'm looking at (this works well for OpenGL); $\bf{x} = {{\bf{u} \times \bf{z}}\over{|\bf{u} \times \bf{z}|}}$ and $\bf{y} = \bf{z} \times \bf{x}$, which, again, for OpenGL, makes $\bf{x}$ rightward on the screen and $\bf{y}$ upward.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To transform into eye coordinates is a matter of subtracting they eye's position, then projecting into the space defined by the vectors above:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix} \bf{x}_x &amp;amp; \bf{x}_y &amp;amp; \bf{x}_z &amp;amp; 0 \\ \bf{y}_x &amp;amp; \bf{y}_y &amp;amp; \bf{y}_z &amp;amp; 0 \\ \bf{z}_x &amp;amp; \bf{z}_y &amp;amp; \bf{z}_z &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}\begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; -\bf{e}_x \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; -\bf{e}_y \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -\bf{e}_z \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is exactly what you have to begin with.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-02-16T04:09:53.407" LastActivityDate="2016-02-16T04:09:53.407" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2048" PostTypeId="2" ParentId="2046" CreationDate="2016-02-15T17:23:09.787" Score="3" Body="&lt;p&gt;Yes, its pretty standard stuff. Most 3D applications our there can do this. Since the nomenclature of 3d applications is not standardized, the tool has different names in different applications: Loft (Maya, 3DSMax), Blend (Creo, Catia...) and so on.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zeKrH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zeKrH.png&quot; alt=&quot;Blend&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Blend between 3 curves, not closed but same principle applies. Open curves are easier as they clearly define the boundary conditions. (software used is Creo because that's what I had open)&lt;/p&gt;&#xA;&lt;p&gt;You usually want the first edge be from a surface edge because otherwise you will lose the tangency info. But nothing prevents you from using a natural tangent direction, you just lose control. Also you need to pay attention to how you intend the curves to connect (what point connects to what point).&lt;/p&gt;&#xA;&lt;p&gt;Personally I prefer drawing the hull or using some of the network based tools. This way allow you to specify control curves in 2 directions, thus giving control of what to connect where and how it should work mid run.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Qm5Bk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Qm5Bk.png&quot; alt=&quot;Image 2&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Curve network.&lt;/p&gt;&#xA;&lt;p&gt;There are many ways to do this, infinite ways in fact. Also if you want to be compatible with other mainstream CAD apps use NURBS instead of beziers than its easier for you to write a exporter/importer if your data set is rich enough. Beziers are just special cases of NURBS after all so your code itself should not need to change all that much (fitting also gets easier).&lt;/p&gt;&#xA;&lt;p&gt;What you do is simply fit a curve trough your points in the second direction this will then give you the corresponding hull in the other direction. In your case you could just make a Bezier patch for each segment and then try to deduce a natural tangent direction.&lt;/p&gt;&#xA;&lt;h3&gt;One way&lt;/h3&gt;&#xA;&lt;p&gt;Like I said theres a infinite ways of constructing these, you have an artistic freedom of doing whatever you see fit it's a over constrained problem. One way of constructing this would be to have a patch for each consecutive cross section. This is nice and tidy as it generalizes works well with an arbitrary number of cross sections.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ES0Mq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ES0Mq.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image 3&lt;/strong&gt;: Example of deriving one row for 2 consecutive bezier spans.&lt;/p&gt;&#xA;&lt;p&gt;First recognize there are 3 cases (ill cover 2):&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Free edges,&lt;/li&gt;&#xA;&lt;li&gt;Internal edges,&lt;/li&gt;&#xA;&lt;li&gt;External constraint.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I'll cover 1 and 2. First the Internal edge as its simple you want it to be smooth so the tangent length and direction in both patches must match. If that's not true then its not sufficiently continuous. You could simply take that this is the furthest point from the surrounding patches control points and due to mean value theorem it should have a tangent direction perpendicular to these (Line A-C is parallel with D-E). The tangent length should be about 1/3 of the length of the distance to the adjoining vertices (A-B or A-C, in this case the shorter of the spans. It could be longer or average. though that could pose problems). Obviously if you have more spans just repeat for one span forward and after for more internal spans if needed.&lt;/p&gt;&#xA;&lt;p&gt;For free edges find the point on the perpendicular line that is as far from the point as half distance between the points (length B-D is equal to length (A-B)/2 and length B-E is equal to length (B-D)/2). The free tangent points towards this point. The length of the tangent is as long as one third of corresponding point difference (length (A-B)/3 and (B-C)/3). Obviously the distances and points could be arbitrary but these are somewhat natural.&lt;/p&gt;&#xA;&lt;p&gt;Repeat for next point sequence in line and next and next. You end up with 2 spans that means 2 times 16 points.  There are other ways but this is relatively easy to convert into a visual form without going into deeper maths. But this is pretty well known math you can find many ways to form these by searching in literature.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-02-16T17:58:09.817" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2049" PostTypeId="1" AcceptedAnswerId="2052" CreationDate="2016-02-15T18:47:24.553" Score="2" ViewCount="893" Body="&lt;p&gt;I'm looking into the graphics pipeline processes and at the moment in particular, perspective projection matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After looking in several different sources, and across the breadth of previous questions such as &lt;a href=&quot;https://stackoverflow.com/questions/25659623/how-does-a-projection-matrix-work&quot;&gt;How does a projection Matrix work? | Stack Overflow&lt;/a&gt;, I've found that most solutions seem to use the following two matrices;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/adExB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/adExB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/EG3Iu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EG3Iu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far, I've been expecting these matrices to take the view frustum and convert it into a unit sized cube - however this doesn't seem to be happening.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Taking the left matrix first (which I attempted to use first), I assumed the parameters were as such;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;n/f = &lt;strong&gt;z&lt;/strong&gt; value of near and far planes&lt;/p&gt;&#xA;&#xA;&lt;p&gt;r/l = &lt;strong&gt;x&lt;/strong&gt; values of left and right planes&lt;/p&gt;&#xA;&#xA;&lt;p&gt;t/b = &lt;strong&gt;y&lt;/strong&gt; values of top and bottom planes&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the right hand matrix, my book is very vague, and the only parameters that seem to fit are&lt;/p&gt;&#xA;&#xA;&lt;p&gt;d/f - distances to near/far planes (but not necessarily the &lt;strong&gt;z&lt;/strong&gt; values?)&#xA;h - height of the near clip plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My initial method of experimentation has been to plot the vertices of the frustum and using the transforms get a resultant that the X, Y values can be used to display the image in 2D and with Z values that can be used to decide what polygons overlay others.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, whilst I've been expecting a cube with dimensions of 1 -&gt; -1 along all axes, instead I've been getting just an inverted frustrum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I feel I'm either making an elementary mistake or am missing something key - would appreciate any help in clearing up both my uncertainties in what I need to do to convert my shape from the 3D to the 2D, and what I should be expecting. So far, my results are below. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The left hand picture shows the shape in a view frustum - and the right shows the original frustum and transformed frustum in green after applying the perspective transform which I believe should be transformed to a unit sized cube and not just a reflected frustum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W4xni.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W4xni.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've put my code below, and tried to simplify it as much as possible to make it easier to evaluate!. Thanks very much!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Updates&lt;/strong&gt;&#xA;I've updated my coordinates for view space coordinates - using a different method generates view space coordinates that go 'back' towards negative z values. Not sure if that makes it more correct but I hope it helps (but as per the comment).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Following the answer below I've added an attempt to perform perspective division. I've added the following code below the main bulk. Any further recommendations would be massively appreciated&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;clc; clear all; close all;&#xA;%======Create View Space (hard-coded values for demo) &amp;amp; Plot  ===========&#xA;ws_fcs = [1,2,4,3,3,1,6,6,6,6,7,7,9,8,8,8,10,10;&#xA;    2,4,3,1,4,4,9,8,7,11,9,13,8,12,10,6,11,13;&#xA;    5,5,5,5,1,2,7,9,11,10,13,11,13,13,12,10,13,12];&#xA;ws_vtx = [-1.3416,0.4472,-1.3416,0.4472,-1.3416,-0.8944,0,0,0.8944,-0.8944,0,0,0.8944;&#xA;          -1.0954,-1.4606,0.7303,0.3651,-1.0954,-0.7303,-0.9129,0,-0.1826,0.1826,0,0.9129,0.7303;&#xA;          -4.899,-4.0825,-4.0825,-3.266,-2.4495,-4.4907,-4.0825,-6.1237,-5.7155,-4.0825,-3.6742,-5.7155,-5.3072];&#xA;&#xA;position = [0;0;0;1]; focus = [0;0;-3.6742]; %Transformed set points&#xA;&#xA;figure(); grid on; hold on; xlabel('x'); ylabel('y'); zlabel('z');&#xA;scatter3(position(1),position(2),position(3),'s');&#xA;scatter3([position(1); position(1)+focus(1)],[position(2); position(2)+focus(2)],...&#xA;    [position(3); position(3)+focus(3)],'s');&#xA;plot3([position(1), focus(1)],[position(2), focus(2)],[position(3), focus(3)],'g');&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx','Facecolor', 'r', 'FaceAlpha', 0.1);&#xA;%====================Create View Volume===========================&#xA;asp_rat = 0.75; %Most displays arent square&#xA;focus = focus/norm(focus); %Normalise focus vector&#xA;nheight = 1; %height of near clip plane&#xA;hoz_angle = 2*pi/3;&#xA;ndistance = 1/tan(hoz_angle/2); %distance of near view plane from origin&#xA;fdistance = 5.5; %Define a far distance&#xA;&#xA;nc = ndistance*focus; %Centre point is focus vector * distance&#xA;ntr = nc + [asp_rat*nheight; nheight; 0]; %Go from centre to TL corner&#xA;nbr = ntr + [0; -2*nheight;0]; %Go down 2* height to bottom&#xA;nbl = nbr + [-2*asp_rat*nheight; 0; 0];&#xA;ntl = nbl + [0; 2*nheight;0];&#xA;nr_plan = [ntr, nbr, nbl, ntl]; %Generate near plane points&#xA;&#xA;fc = fdistance*focus;&#xA;fheight = tan(hoz_angle/2)*fdistance; %Find far plane height by trig&#xA;ftr = fc + [asp_rat*fheight; fheight; 0]; %Go from centre to TL corner&#xA;fbr = ftr + [0; -2*fheight;0]; %Go down 2* height to bottom&#xA;fbl = fbr + [-2*asp_rat*fheight; 0; 0];&#xA;ftl = fbl + [0; 2*fheight;0];&#xA;fr_plan = [ftr, fbr, fbl, ftl]; %Generate near plane points&#xA;&#xA;frust_vtx = horzcat(nr_plan, fr_plan); %Create frustum vertex array&#xA;frust_fcs = [1,8,5,6,4,5;  %Faces defined with normals inwards&#xA;             4,5,1,2,8,8;&#xA;             3,6,2,3,7,4;&#xA;             2,7,6,7,3,1];&#xA;patch('Faces',frust_fcs','Vertices',frust_vtx', 'FaceAlpha', 0.05);&#xA;xlabel('x'); ylabel('y'); zlabel('z');&#xA;%=============Create Perspective Matrix ==============================&#xA;figure(); grid on; hold on; xlabel('x'); ylabel('y'); zlabel('z');&#xA;scatter3(frust_vtx(1,:),frust_vtx(2,:),frust_vtx(3,:)); %Plot orig frustrum &#xA;patch('Faces',frust_fcs','Vertices',frust_vtx', 'FaceAlpha', 0.05);&#xA;&#xA;left = nc(1) - asp_rat*nheight; %Get values for projection matrix&#xA;right = nc(1) + asp_rat*nheight;&#xA;top = nc(2) + nheight;&#xA;bottom = nc(2) -nheight;&#xA;near = ndistance;&#xA;far = fdistance;&#xA;&#xA;proj_mat = [2*near/(right - left),0,(right + left)/(right - left),0;&#xA;    0, 2*near/(top-bottom),(top+bottom)/(top-bottom),0;&#xA;    0,0, -(far+near)/(far-near), -2*far*near/(far-near);&#xA;    0,0,-1,0];&#xA;%====================Perspective Projection Transformation=============&#xA;frust_vtx = proj_mat*vertcat(frust_vtx,(ones(1,length(frust_vtx)))); &#xA;scatter3(frust_vtx(1,:),frust_vtx(2,:),frust_vtx(3,:)); %Plot frustrum points&#xA;patch('Faces',frust_fcs','Vertices',frust_vtx(1:3,:)','FaceColor','g','FaceAlpha', 0.05);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Perspective Division&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;%========================Perspective Division==========================&#xA;for i = 1:length(frust_vtx) &#xA;    frust_vtx(:,i) = frust_vtx(:,i)/frust_vtx(4,i);&#xA;end&#xA;for i = 1:length(ws_vtx) &#xA;    ws_vtx(:,i) = ws_vtx(:,i)/ws_vtx(4,i);&#xA;end&#xA;scatter3(ws_vtx(1,:),ws_vtx(2,:),ws_vtx(3,:)); %Plot shape points&#xA;patch('Faces',ws_fcs','Vertices',ws_vtx(1:3,:)','FaceColor','r','FaceAlpha', 0.05); &#xA;scatter3(frust_vtx(1,:),frust_vtx(2,:),frust_vtx(3,:)); %Plot frustrum points&#xA;patch('Faces',frust_fcs','Vertices',frust_vtx(1:3,:)','FaceColor','g','FaceAlpha', 0.05);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2646" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:44:55.540" LastActivityDate="2018-04-24T07:44:55.540" Title="Choosing &amp; Using a Projection Matrix" Tags="&lt;transformations&gt;&lt;3d&gt;&lt;vector-graphics&gt;&lt;matrix&gt;&lt;matlab&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2050" PostTypeId="2" ParentId="1991" CreationDate="2016-02-15T21:30:17.253" Score="3" Body="&lt;p&gt;Baraff and Witkin propose to incorporate constraints by modifying the linear system by the constraints matrices $\mathbf S_i$. As they state in the beginning of Section 5.2, the resulting system is not symmetric anymore. Therefore, the modified linear system must be computed with a linear solver that can treat non-symmetric systems (as - if I got you correctly - you proposed with the normal matrix $\mathbf A^T \mathbf A$). However, Baraff and Witkin introduce the modified conjugate gradient method, which is a variant of the original conjugate gradient method, that computes a solution of the initial linear system with considering the constraints at the same time, without the need to take care of the non-symmetry. In their paper they do not solve the normal equations ($\mathbf A^T \mathbf A$), but rather the original system $\mathbf A \Delta \mathbf v = \mathbf b$, so your questions ask something which is beyond of the paper.&lt;/p&gt;&#xA;" OwnerUserId="2695" LastActivityDate="2016-02-15T21:30:17.253" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2052" PostTypeId="2" ParentId="2049" CreationDate="2016-02-15T23:56:58.973" Score="2" Body="&lt;p&gt;The values will only form a cube after performing the perspective divide, which I don't see happening in your code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is, you take a vector $[x, y, z, 1]$ and transform it by the projection matrix, resulting in a new vector $[x', y', z', w']$. Then divide out the fourth component to get a 3D vector, $[x'/w', y'/w', z'/w']$. This last is the one that should be within a $[-1, 1]$ cube, if the original point was within the view frustum (and if it's an OpenGL-style projection matrix—Direct3D-style ones have $[0,1]$ for the post-projective Z range, instead of $[-1, 1]$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Without the divide by $w'$, if you just look at $[x', y', z']$, indeed you'll just get a scaled and possibly reflected frustum. Matrix multiplication alone can't transform a frustum into a cube, as it's not a linear or affine transformation; instead, it's a projective transformation, and the divide by $w'$ accomplishes that.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-02-15T23:56:58.973" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2053" PostTypeId="2" ParentId="2042" CreationDate="2016-02-16T18:38:54.543" Score="5" Body="&lt;p&gt;In a traditional camera, the photons from the scene travel through the lens of the camera, then hit the sensor at the focal length. A consequence of the lens is that the image is upside down and backwards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/e4pu7.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e4pu7.gif&quot; alt=&quot;Camera&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In ray tracing, we can optimize this by imagining the focal plane is in front of the camera. You can think that the photons from the scene travel towards the camera hole, and resolve on the image plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iOrm3.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iOrm3.png&quot; alt=&quot;Photons hit image plane&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another optimization in ray tracing to to trace rays from the camera into the scene, rather than tracing them from light sources and hoping they hit the camera. Therefore, the first rays we shoot out are the ones that go from the eye through each pixel on the virtual screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BW8Vy.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BW8Vy.png&quot; alt=&quot;Shooting a Ray&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to create the ray, we need to know the distances a and b in world units. Therefore, we need to convert pixel units into world units. To do this we need a define a camera. Let's define an example camera as follows:&#xA;$$origin = \begin{bmatrix} 0 &amp;amp; 0 &amp;amp; 0 \end{bmatrix}$$&#xA;$$coordinateSystem = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0\\ 0 &amp;amp; 1 &amp;amp; 0\\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$$&#xA;$$fov_{x} = 90^{\circ}$$&#xA;$$fov_{y} = \frac{fov_{x}}{aspectRatio}$$&#xA;$$focalDist = 1$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The field of view, or fov is an indirect way of specifying the ratio of pixel units to view units. Specifically, it is the viewing angle that is seen by the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OyYfj.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OyYfj.png&quot; alt=&quot;FOV Eye Plane&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The higher the angle, the more of the scene is seen. But remember, changing the fov does not change the size of the screen, it merely squishes more or less of the scene into the same number of pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PBEBi.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PBEBi.png&quot; alt=&quot;FOV Explaination&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's look at the triangle formed by fovx and the x-axis:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sSUA1.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sSUA1.png&quot; alt=&quot;Triangle&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can use the definition of tangent to calculate the screenWidth in view units&#xA;$$\tan \left (\theta  \right) = \frac{opposite}{adjacent}$$&#xA;$$screenWidth_{view}= 2 \: \cdot \: focalDist \: \cdot \: \tan \left (\frac{fov_{x}}{2}  \right)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using that, we can calculate the view units of the pixel.&#xA;$$x_{homogenous}= 2 \: \cdot \: \frac{x}{width} \: - \: 1$$&#xA;$$x_{view} = focalDist \: \cdot \: x_{homogenous} \: \cdot \: \tan \left (\frac{fov_{x}}{2}  \right)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last thing to do to get the ray is to transform from view space to world space. This boils down to a simple matrix transform. We negate yview because pixel coordinates go from the top left of the screen to the bottom right, but homogeneous coordinates go from (-1, -1) at the bottom left to (1, 1) at the top right.&#xA;$$ray_{world}= \begin{bmatrix} x_{view} &amp;amp; -y_{view} &amp;amp; d\end{bmatrix}\begin{bmatrix} &amp;amp;  &amp;amp; \\ &amp;amp; cameraCoordinateSystem &amp;amp; \\ &amp;amp;  &amp;amp; \end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see an implementation of this &lt;a href=&quot;https://github.com/RichieSams/lantern/blob/669e6c9ccd33f455961a96c5cfe0a5bc3f2af59c/source/scene/camera.cpp#L86&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt; (In the code, I assume the focalDist is 1, so it cancels out)&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-02-16T18:38:54.543" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2054" PostTypeId="2" ParentId="2043" CreationDate="2016-02-16T19:42:22.413" Score="7" Body="&lt;p&gt;As far as I can tell, the main advantage of half-edge is that traversal can be a bit simpler due to a guarantee of edges having a consistent orientation within each face.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the problem of iterating over all the vertices or edges of a given face, in counterclockwise order. In the half-edge structure, this can be done by starting with an arbitrary half-edge of that face and simply following the &quot;next&quot; pointers until you get back where you started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In contrast, doing this in a winged-edge structure is a bit annoying, because the edges are oriented arbitrarily; any given edge that you encounter might point either clockwise or counterclockwise relative to the face you're trying to iterate around, so you have to do an extra conditional check at each step to see if you should traverse the current edge forward or backward.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other kinds of connectivity queries behave similarly: the half-edge version lets you follow links in a consistent sequence while the winged-edge version requires orientation checks at each step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whether the conditionals are actually a performance problem for winged-edge will probably depend on other factors. For a &quot;naive&quot; implementation with pointers every which way and data scattered across memory, I'd expect cache miss overhead to swamp any effect of the conditionals. On the other hand, if you have a tightly packed data structure with everything hot in the cache, you might see some effects from the conditionals due to incorrect branch predictions, etc. It's hard to say.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Leaving performance alone, I'd prefer half-edge just because it seems easier to reason about and write correct code for, even if it results in a slight memory overhead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, there are a couple of other design choices with mesh data structures that often seem to get confused with this one. A commenter mentioned single vs double linking, but naturally you can do either single or double linking with either half-edge or winged-edge. (Although I don't see how single linking with winged-edge would even work, since as mentioned above, you might have to traverse edges either backward or forward in the course of a query.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, there's the question of whether the vertex and face structures store a list of all their edges, or just one (and require you to traverse the edges to find the rest). Having a variable-length list of edges per vertex/face considerably complicates the logic if you want to do it efficiently (i.e. not having a separate heap allocation per vertex/face), but again this is independent of whether the edges are half-edge or winged-edge.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-02-16T19:47:22.990" LastActivityDate="2016-02-16T19:47:22.990" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2055" PostTypeId="1" CreationDate="2016-02-16T20:49:14.753" Score="6" ViewCount="735" Body="&lt;p&gt;I have to use a propriertary graphics-engine for drawing a line. I can rotate the whole drawing by its origin point (P1). What I want, is to rotate it around its center point(M). So basically that it looks like the green line (L_correct instead of L_wrong).&lt;/p&gt;&#xA;&lt;p&gt;I think, it should be possible to correct it, by moving it from P1 to P2. But I cannot figure out what formula could be used, to determine the distance. It must probably involve the angle, with and height... Can anyone give me a hint?&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/ovWo0Gg.jpg&quot; alt=&quot;1&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="2701" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-02-17T09:34:32.137" Title="Rotate line around center" Tags="&lt;transformations&gt;&lt;line-drawing&gt;&lt;mathematics&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2056" PostTypeId="2" ParentId="2055" CreationDate="2016-02-16T21:18:00.447" Score="6" Body="&lt;p&gt;Trick is, to move the entire object so that the point about which you want to rotate is at the center. Then rotate and after that counter move it so that the point is were it was.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact this is not so much of a trick, as such, nearly all graphics engines work this way. It is just abstracted away in many cases. Most often you will see it done in matrix notation like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ T^{-1} R T $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where T is to transformation from world to pivot and R is the rotation matrix. Since it can be easily packaged this way you end up with a function called rotate about the pivot point. This is usually the reason why drawing API's allow for a transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kIH24.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kIH24.png&quot; alt=&quot;Rotate about a pivot&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Rotate about a pivot point, &lt;a href=&quot;http://pastebin.com/L2XpvfeG&quot; rel=&quot;nofollow noreferrer&quot;&gt;image source&lt;/a&gt; available for investigation. Sub images in RTL reading order: Original, inverse transform, inverse and rotate, inverse rotate and move back.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-02-17T09:22:41.763" LastActivityDate="2016-02-17T09:22:41.763" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2057" PostTypeId="1" AcceptedAnswerId="2059" CreationDate="2016-02-16T22:09:03.930" Score="3" ViewCount="397" Body="&lt;p&gt;I am currently reading the awesome paper by Jorge Jimenez about Character rendering : &lt;a href=&quot;http://www.iryoku.com/stare-into-the-future&quot; rel=&quot;noreferrer&quot;&gt;Next Generation Character Rendering&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the part about multi-sampled transmittance he uses some Poisson offsets and a jitter texture which contains &lt;em&gt;[cos(x), sin(x)]&lt;/em&gt; and is used to rotate the the Poisson disk samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I am wondering how do you generate such texture ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the part of the ppt which talks about this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/21iCO.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/21iCO.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2016-02-17T08:11:53.453" Title="Jitter texture generation" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;texture&gt;&lt;sampling&gt;&lt;hlsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2058" PostTypeId="2" ParentId="2055" CreationDate="2016-02-16T23:26:31.237" Score="1" Body="&lt;p&gt;I am a bit unsure if my calculations are correct, but on my scribbling paper it seemed to work out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P1 and P2 lie on a circle around M.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This allows us to measure the distance of the two points by just taking the radius (which is half the line length) of the circle and constructing two rectangular triangles. The accepted answer &lt;a href=&quot;https://math.stackexchange.com/questions/134606/distance-between-any-two-points-on-a-unit-circle&quot;&gt;here&lt;/a&gt; provides a sketch for this construction.&#xA;So given your rotation angle is $\gamma$ and the line is $l$ long it follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x = 2* sin(\frac{\gamma}{2}) * \frac{l}{2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The lines M to P1 and M to P2 form a isosceles triangle with the third side being the line segment between P1 and P2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The angle at point M is known to be the rotation angle $\gamma$ so the remaining two angles in this triangle are given by&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\alpha = \frac{180 - \gamma}{2}$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And therefore the angle between the wrong line and the needed translation vector is just &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\beta = \alpha + \gamma$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now you rotate a unit vector that starts along the wrong line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You rotate it around P1 for $\beta$ and scale it to length x.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This yields the translation vector from P1 to P2. The rotation of the line should indeed be correct.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="-1" LastEditDate="2017-04-13T12:19:38.027" LastActivityDate="2016-02-16T23:26:31.237" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2059" PostTypeId="2" ParentId="2057" CreationDate="2016-02-17T08:11:53.453" Score="6" Body="&lt;p&gt;The texture is probably generated by picking a random angle per pixel, and populating the image with its sine and cosine, remapped into [0, 1]:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\theta \sim [0, 2\pi] \quad \to \quad \begin{bmatrix} \tfrac{1}{2} \cos \theta + \tfrac{1}{2} \\ \tfrac{1}{2} \sin \theta + \tfrac{1}{2} \\ 0 \end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did a quick test and generated something that looks pretty similar (enlarged 4x):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/4ySjS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to be extra fancy, then instead of picking independent random angles for every pixel, you might try stratified sampling or a low-discrepancy sequence. That may give better final results for whatever effect you're using the jitter texture for, due to better local sample distribution.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-02-17T08:11:53.453" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2060" PostTypeId="1" CreationDate="2016-02-17T14:59:49.933" Score="1" ViewCount="1019" Body="&lt;p&gt;I have been playing with voxelization for a little time, I'm still very new to this technique.&#xA;I am trying to use it for ray tracing but I've been stuck with one problem. There are some codes out there in the web that already perform voxelization however, for ray tracing I need to check the intersection between a ray and a triangle.&#xA;Therefore, I've been thinking about what would be a good approach to create a list of triangles for each voxel in order to query the triangles once I know a ray hits a particular voxel? Should I try to modify the code of the voxelizer to benefit from the overlap-test or is it better to create a space-partitioning structure?&lt;/p&gt;&#xA;" OwnerUserId="116" LastActivityDate="2017-01-25T09:12:49.897" Title="How to build a triangle-voxel list from a triangle mesh?" Tags="&lt;space-partitioning&gt;&lt;voxelization&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2061" PostTypeId="1" AcceptedAnswerId="2062" CreationDate="2016-02-18T01:47:02.473" Score="5" ViewCount="4284" Body="&lt;p&gt;Mainly talking about dual-SLI here for consistency. With past DirectX (and OpenGL) APIs, VRAM was mirrored across graphics cards. With dual-SLI, this was possible by rendering one frame with one graphics card and another frame with another one. There was also a rendering option in which one graphics card would render part of the screen. Unfortunately, there doesn't seem to be much technical information on how VRAM stacking would work. What possible techniques could graphics cards or DirectX 12 be using to allow for this?&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2019-09-14T23:49:50.660" Title="How does DirectX 12 SLI VRAM stacking work?" Tags="&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2062" PostTypeId="2" ParentId="2061" CreationDate="2016-02-18T03:27:47.513" Score="8" Body="&lt;p&gt;In DX12, there is no implicit driver-implemented SLI as there was in DX11. Instead, multiple GPUs are exposed to the application as separate &quot;nodes&quot; within a single DX12 device, and each VRAM resource lives on a single node, specified at creation time. There is no implicit mirroring of resources to both GPUs as in DX11 SLI.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the game engine or application has full control and responsibility over how data and work are distributed between the GPUs. It's up to the app developers to implement patterns like alternating frames between GPUs, or splitting the frame across GPUs, if they wish. For example, to implement alternating frames, the app would have to allocate all buffers, textures, render targets etc. on both GPUs and populate both of them. Then, when rendering a frame, it would generate a command list for the current GPU using its local copies of all resources. Any inter-GPU transfers needed (for temporal effects, for instance) would also be the app's responsibility.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More information on this topic can be found on &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3d12/multi-engine&quot; rel=&quot;nofollow noreferrer&quot;&gt;this MSDN article on DX12 multi-GPU support&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2019-09-14T23:49:50.660" LastActivityDate="2019-09-14T23:49:50.660" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="2063" PostTypeId="1" AcceptedAnswerId="2064" CreationDate="2016-02-18T04:08:25.213" Score="6" ViewCount="1068" Body="&lt;p&gt;I'm a newcomer to OpenGL and I was playing around with drawing triangles with different z-coordinates. From what I understand, the z axis point out of the screen, and the -z axis points into the screen. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I draw a square with 3 corners at a 0.0 z-coordinate, and the last corner at, say, 3.0 z-coordinate, I get this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GL2Mu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GL2Mu.png&quot; alt=&quot;wat&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand how it's making this shape... I thought it would be something like this, since the 4th vertex is just 'far away'.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Dmw2A.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Dmw2A.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone explain?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; This is my vertex data&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// vertex array&#xA;float vertices[] = {&#xA;    -0.5f,  0.5f,  0.0f, 1.0f, 0.0f, 0.0f, // top left, first 3 are location, last 3 are color&#xA;     0.5f,  0.5f,  0.0f, 0.0f, 1.0f, 0.0f, // top right&#xA;    -0.5f, -0.5f,  -2.0f, 0.0f, 0.0f, 1.0f, // bottom left&#xA;     0.5f, -0.5f,  0.0f, 1.0f, 1.0f, 1.0f // bottom right&#xA;};&#xA;&#xA;// element buffer array&#xA;GLuint elements[] = {&#xA;    0, 1, 2,&#xA;    2, 1, 3&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I am calling the draw like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawElements(GL_TRIANGLES, 6,GL_UNSIGNED_INT,0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2651" LastEditorUserId="2651" LastEditDate="2016-02-18T04:24:59.147" LastActivityDate="2016-02-18T04:35:46.963" Title="Confused about z-axis behaviour" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2064" PostTypeId="2" ParentId="2063" CreationDate="2016-02-18T04:35:46.963" Score="5" Body="&lt;p&gt;The post-projective Z range in OpenGL extends between &amp;minus;1 and 1. So, a Z-value of 2 is out of range and will be clipped by the far plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason the square appears with a quadrant missing is that it's split into triangles from bottom left to top right, and so each triangle has two vertices with Z = 0 and one vertex with Z = 2. So, interpolating along the triangle, it hits Z = 1 (the far plane) halfway across, and everything beyond that is clipped. This results in half of each triangle disappearing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, you'll need a perspective projection matrix in order for far-away objects to appear smaller on screen. With no projection matrix, you're effectively using a parallel projection.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-02-18T04:35:46.963" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2067" PostTypeId="1" AcceptedAnswerId="2069" CreationDate="2016-02-18T17:38:27.070" Score="3" ViewCount="1625" Body="&lt;p&gt;So I want to render a buttload of quads by using a single 4 point vertex array and change the position of the quad. What is quicker:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &lt;code&gt;glBufferSubData&lt;/code&gt; to change the positional data or&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &lt;code&gt;glMapBufferRange&lt;/code&gt; to DMA the buffer and &lt;code&gt;glUnmapBuffer&lt;/code&gt; to push the data back to the GPU?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using the vertex buffer data, I need to also call &lt;code&gt;glVertexAttribArray&lt;/code&gt; to reassociate the data with the vertexArrayObject.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using uniform buffers and do it with shader magic I only need to change the uniform buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is quicker?&lt;/p&gt;&#xA;" OwnerUserId="2623" LastActivityDate="2016-02-19T20:06:51.320" Title="Uniform Buffers: What is quicker?" Tags="&lt;opengl&gt;&lt;mapping&gt;&lt;uniform-buffer-object&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2068" PostTypeId="2" ParentId="2037" CreationDate="2016-02-18T22:21:47.970" Score="4" Body="&lt;p&gt;I've done some small changes to how I usually construct my view matrix, here is what I've modified:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// put it after N = ...&#xA;U = cross(N, Vspec);&#xA;U = U / sqrt(dot(U,U)); % normalize&#xA;V = cross(U, N);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then I also set N vector as -N to R matrix, like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;R= [U(1),U(2),U(3),0; % U is direction of camera space X axis&#xA;    V(1),V(2),V(3),0; % V is direction of camera space Y axis&#xA;    -N(1),-N(2),-N(3),0;&#xA;    0   ,   0,   0,1];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/wiki/GluLookAt_code&quot; rel=&quot;nofollow noreferrer&quot;&gt;as shown e.g. in the code for lookAt matrix for OpenGL&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can orient your first graph, as if you look through your camera, this will give you a reference of how it should look on the second graph.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then orient second graph so that you look through -Z axis, Y looks up, and X from left to right. Because your camera view vector is -Z, up is Y and right is X. Once you orient your second graph like this, you'll see that arrow looks identically to the first graph, ray on graph 2 will be drawn as point, because it is directed along -Z (your view direction), and in camera space end and start points will fall on a same pixels (another hint that it is correct).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also modified a bit camera pos, view direction and axes (just to make it easier to observe for myself).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are the values, that I've used:&#xA;    focus = [1.2,0,1.5]; %The point we're looking at&#xA;    Cx = 3; Cy = -3; Cz = 3; %Position of camera&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And for the axes:&#xA;    axis([-5,5,-6,6,-7,7]);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/izEmQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/izEmQ.png&quot; alt=&quot;Here is what I&amp;#39;ve got&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can send you whole code if you need.&lt;/p&gt;&#xA;" OwnerUserId="43" LastActivityDate="2016-02-18T22:21:47.970" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2069" PostTypeId="2" ParentId="2067" CreationDate="2016-02-18T23:29:45.807" Score="6" Body="&lt;p&gt;A key rule of thumb for high-performance code in general, and graphics in particular, is to batch large amounts of work together rather than doing it in small chunks. In your case, rather than sending one quad's worth of data at a time and drawing one quad at a time, it will be far more efficient to send many quads' data in a large batch, and draw many quads together in a single draw call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A good way to accomplish both is &lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Rendering#Instancing&quot; rel=&quot;nofollow&quot;&gt;instancing&lt;/a&gt;. You would have a 4-point vertex buffer for the corners of a quad, and a second vertex buffer for the values that are per-quad (what you're putting in your uniform buffer now). This second buffer would be large enough to hold the data for all the quads at once, not just one quad. To populate the vertex buffer, you can map the whole thing, write all the data, and unmap. Then do a single instanced draw call to render all the quads at once.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if instancing can't be used for some reason (for instance if each quad needs a different texture, and it's not possible or desirable to put them together in an atlas), you can still upload all the data in one batch. Create a uniform buffer large enough to hold an array of all the quads' data; map/write/unmap it all in one big batch as before; then before each draw call, use &lt;a href=&quot;http://docs.gl/gl4/glBindBufferRange&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;glBindBufferRange&lt;/code&gt;&lt;/a&gt; to select one quad's data from that large buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Batching can also be used when you don't know the number of quads in advance. Just pick a &quot;reasonably large&quot; batch size (say, 1024 quads) and size your buffers for that number. Accumulate quads into the buffer until you reach the size limit, then draw them all, and start over (using the &lt;code&gt;GL_MAP_INVALIDATE_BUFFER_BIT&lt;/code&gt; flag with &lt;code&gt;glMapBufferRange&lt;/code&gt; to get a fresh copy of the buffer). You'll also need to do a partial draw at the end of this process to handle any left-over quads that didn't reach the size limit.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-02-19T20:06:51.320" LastActivityDate="2016-02-19T20:06:51.320" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2070" PostTypeId="1" AcceptedAnswerId="2071" CreationDate="2016-02-19T02:32:49.933" Score="4" ViewCount="442" Body="&lt;p&gt;I'm working on a webgl pixel shader which is writing to a 16 bit floating point buffer (each color channel r,g,b,a is a 16 bit floating point number).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to figure out if there are any decent ways to pack the following info into those 16 bits per color channel:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;normal (x,y,z where z is always negative)&lt;/li&gt;&#xA;&lt;li&gt;uv coordinates (x,y between 0 and 1)&lt;/li&gt;&#xA;&lt;li&gt;material index (an integer. 0 to 3 would be plenty)&lt;/li&gt;&#xA;&lt;li&gt;distance (a positive float)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I could live without distance if needed but the others are required.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that I can store just x,y of the normal and calculate z as needed since its always negative (the normal is in screenspace).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That still leaves 5 values to store in four 16 bit floats: normal.xy, uv.xy, material index.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone have any good methods for making this happen? It would be nice to have the distance too, otherwise I am limited to directional lighting instead of getting point lights as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is in shadertoy if that context changes any answers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll be sampling this buffer with nearest neighbor sampling, so you don't have to worry about it being stored in a way that interpolates well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-02-19T05:15:35.553" LastActivityDate="2016-02-19T05:15:35.553" Title="Bitpacking into buffers with webgl (shadertoy)" Tags="&lt;webgl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2071" PostTypeId="2" ParentId="2070" CreationDate="2016-02-19T05:00:16.637" Score="3" Body="&lt;p&gt;Assuming you are not going to filter the buffer using HW texture filtering: since you only need 4 values for the material index, pack it in the sign bits of uv x and y.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-02-19T05:00:16.637" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2072" PostTypeId="1" AcceptedAnswerId="2073" CreationDate="2016-02-19T05:30:18.017" Score="4" ViewCount="1156" Body="&lt;p&gt;If you have values on a grid and you want to find the value of a point within one of the cells, you can use techniques like bilinear or bicubic interpolation to get the data at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What technique(s) would be used if the data on the grid was a vector (a surface normal specifically)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that quaternions are good for slerping, which I think could be good in this case to do a &quot;bilinear slerp&quot;, but quaternions require basis vectors that represent an orientation, not just a single vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I'm not sure how you'd use quaternions to apply something like bicubic interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What methods would be good in this case, to interpolate vectors on a grid?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-02-20T20:09:48.967" Title="Interpolating vectors on a grid" Tags="&lt;vectors&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2073" PostTypeId="2" ParentId="2072" CreationDate="2016-02-19T18:31:02.727" Score="5" Body="&lt;p&gt;I did some research and found the answer I was looking for.  The three most common ways to interpolate vectors are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Slerp - short for &quot;spherical interpolation&quot;, this is the most correct way, but is also the costliest.  In practice you likely do not need the precision.&lt;/li&gt;&#xA;&lt;li&gt;lerp - short for &quot;linear interpolation&quot;, you just do a regular linear interpolation between the vectors and use that as a result.&lt;/li&gt;&#xA;&lt;li&gt;nlerp - short for &quot;normalized linear interpolation&quot; you just normalize the result of a lerp.  Useful if you need your interpolated vector to be a normalized vector.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In practice, lerp/nlerp are pretty good at getting a pretty close interpolated direction so long as the angle they are interpolating between is sufficiently small (say, 90 degrees, or 120 like Simon mentions in his comment), and nlerp is of course good at keeping the right length, if you need a normalized vector.  If you want to preserve the length while interpolating between non normalized vectors, you could always interpolate the length and direction separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example of the three interpolations on a large angle.  Dark grey = start vector, light grey = end vector.  Green = slerp, blue = lerp, orange = nlerp.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/LaV6S.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LaV6S.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example of a medium sized angle (~90 degrees) interpolating the same time t between the angles:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2gjmE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2gjmE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, here's a smaller angle (~35 degrees).  You can see that the results of lerp / nlerp are more accurate as the angle between the interpolated vectors gets smaller.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/mrUqf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mrUqf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do lerp or nlerp, you can definitely do both bilinear as well as bicubic interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using slerp, you can do bilinear interpolation, but I'm not sure how bicubic would translate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I generated these images by taking screenshots from an interactive shadertoy demo I made to demonstrate these differences.  You can see that shadertoy here:&lt;br&gt;&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/4sV3zt&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/4sV3zt&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-02-20T20:09:48.967" LastActivityDate="2016-02-20T20:09:48.967" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2074" PostTypeId="1" CreationDate="2016-02-19T23:18:25.597" Score="6" ViewCount="2756" Body="&lt;p&gt;I'm struggling with a problem with image rotation. I'm using the idea of &quot;Rotation by area mapping&quot; in the following link:&#xA;&lt;a href=&quot;http://www.leptonica.com/rotation.html&quot; rel=&quot;noreferrer&quot;&gt;http://www.leptonica.com/rotation.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My c# codes are as follows. The idea is first to find the dimension of the rotated image, then find the gray level of each pixel in the rotated image. To find the gray level for each pixel, the pixel coordinates are transformed back to the coordinates in the original image (called original pixel). The original pixel has fractional coordinate values, then the bilinear interpolation method in the link is used to obtain the gray level of the pixel in the rotated image. My codes did most of the job, except there are some clipping at the corners in the rotated image. I put the rotated images of a 16*16 image, we can clearly see the effect: The bottom line in the 45 degree rotated has no gray data; in the 90 degree rotated one, the vertical line in the left has no gray data; and in the 180 degree rotated one, both the vertical line in the left and the horizontal line on the top have no gray. I believe it's caused by the coordinate computation, and I could modify my code by subtracting one of the coordinates by 1 to achieve correct rotation by a certain angle, but it doesn't work for the other case. So I guess there must be something I ignored in my codes. Any suggestions and comments are appreciated!&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void RotateImageClockwise(double degree)&#xA;{&#xA;    Image&amp;lt;double&amp;gt; image = (Image&amp;lt;double&amp;gt;)(PreservedRawImage.Clone());      &#xA;        double sinAngle = Math.Sin(Math.PI * degree / 180.0);&#xA;        double cosAngle = Math.Cos(Math.PI * degree / 180.0);&#xA;        double newHeightRaw, newWidthRaw;&#xA;&#xA;        ////Find the new dimensions of the rotated image.&#xA;        if (Math.Abs(degree) &amp;lt;= 90)&#xA;        {&#xA;            newHeightRaw = image.Width * sinAngle + image.Height * cosAngle;&#xA;            newWidthRaw = image.Width * cosAngle + image.Height * sinAngle;&#xA;        }&#xA;        else if (Math.Abs(degree) &amp;lt;= 180)&#xA;        {&#xA;            newHeightRaw = image.Width * Math.Sin(Math.PI * (180 - degree) / 180.0) + image.Height * Math.Sin(Math.PI * (degree - 90) / 180.0);&#xA;            newWidthRaw = image.Width * Math.Cos(Math.PI * (180 - degree) / 180.0) + image.Height * Math.Cos(Math.PI * (degree - 90) / 180.0);&#xA;        }&#xA;        else&#xA;            throw new Exception(&quot;Rotation angle is not right.&quot;);&#xA;        ////Done with finding the new dimensions&#xA;&#xA;        double newWidthHalf = newWidthRaw / 2;&#xA;        double newHeightHalf = newHeightRaw / 2;&#xA;&#xA;        int newWidth = (int)Math.Round(newWidthRaw);&#xA;        int newHeight = (int)Math.Round(newHeightRaw);&#xA;        Image&amp;lt;double&amp;gt; newImage = new Image&amp;lt;double&amp;gt;(newWidth, newHeight);&#xA;        byte[] bitmap = new byte[newWidth * newHeight];&#xA;        double newMax = double.MinValue, newMin = double.MaxValue;&#xA;        for (int x = 0; x &amp;lt; newHeight; x++)&#xA;        {&#xA;            for (int y = 0; y &amp;lt; newWidth; y++)&#xA;            {&#xA;                ////Transform the coordinates to be centered at the center of the image&#xA;                double xt = x - newHeightHalf;&#xA;                double yt = y - newWidthHalf;&#xA;&#xA;                double originalX = xt * cosAngle - yt * sinAngle + image.Height / 2.0;&#xA;                double originalY = xt * sinAngle + yt * cosAngle + image.Width / 2.0;&#xA;&#xA;                double fractionX = Math.Abs(originalX - (int)Math.Round(originalX));&#xA;                double fractionY = Math.Abs(originalY - (int)Math.Round(originalY));&#xA;&#xA;                ////Find the neighbors of the pixel in the original image&#xA;                IList&amp;lt;Point&amp;lt;int&amp;gt;&amp;gt; neighbors = new List&amp;lt;Point&amp;lt;int&amp;gt;&amp;gt; { new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX), y = (int)Math.Round(originalY), weight = (1 - fractionX) * (1 - fractionY)}, &#xA;                                                           new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX), y = (int)Math.Round(originalY) + 1, weight = fractionX * (1 - fractionY)},&#xA;                                                           new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX) + 1, y = (int)Math.Round(originalY), weight = (1 - fractionX) * fractionY},&#xA;                                                           new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX) + 1, y = (int)Math.Round(originalY) + 1, weight = fractionX * fractionY}&#xA;                                                         };&#xA;                bool hasData = false;&#xA;                double newData = 0;&#xA;                double weight = 0;&#xA;                foreach (var neighbor in neighbors)&#xA;                {&#xA;                    if (neighbor.x &amp;gt;= 0 &amp;amp;&amp;amp; neighbor.x &amp;lt; image.Height&#xA;                        &amp;amp;&amp;amp; neighbor.y &amp;gt;= 0 &amp;amp;&amp;amp; neighbor.y &amp;lt; image.Width&#xA;                       )&#xA;                    {&#xA;                        hasData = true;&#xA;                        newData += neighbor.weight * image.Data[(neighbor.x) * image.Width + neighbor.y];&#xA;                        weight += neighbor.weight;&#xA;                    }&#xA;                }                    &#xA;                if (hasData &amp;amp;&amp;amp; weight != 0)&#xA;                {&#xA;                    newData /= weight;&#xA;                    newImage.Data[x * newWidth + y] = newData;&#xA;                }&#xA;            }                &#xA;        }            &#xA;    } &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dyDw6.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dyDw6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2719" LastActivityDate="2016-02-22T21:48:31.237" Title="Rotate image around its center" Tags="&lt;image-processing&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2075" PostTypeId="2" ParentId="2074" CreationDate="2016-02-20T07:18:32.540" Score="3" Body="&lt;p&gt;This is more of a long comment, with an image, than an answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Seems to me, at a quick glance, that you consider your pixels sample point to be at integer values. Instead in reality sample is located offset 0.5 pixels of this location.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0UGXJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0UGXJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Is the pixel sample located at its integer coordinate? Or is it located offset by 0.5 pixels?&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-02-20T07:24:04.553" LastActivityDate="2016-02-20T07:24:04.553" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2076" PostTypeId="1" CreationDate="2016-02-20T11:38:53.557" Score="9" ViewCount="495" Body="&lt;p&gt;I've mostly succeeded at porting an implementation of Marching Cubes from CPU over to OpenGL compute shaders, but I haven't tackled normals yet and wondering the best way to go about it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My implementation deals specifically with binary valued fields (I'm trying to model 3D fractal functions that don't have a distance estimator yet), so gradient and forward differences methods won't work. I have shared vertices working, and my CPU implementation uses Quilez's method described &lt;a href=&quot;http://www.iquilezles.org/www/articles/normals/normals.htm&quot;&gt;here&lt;/a&gt; to accumulate face normals onto each neighbouring vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could just port this implementation over to another shader, but the problem I see with this is the massive number of atomics needed. Since we can only use atomics on scalar integer types, and I cant think of a way to pack 3 signed ints into 1 in a summable way, that means 3 axes * 3 vertices = 9 atomic adds per shader invocation. They'll be spread throughout memory of course so it's not like hitting a single atomic counter 9 times, but it still seems like a hell of a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other alternative is to run a shader invocation per-polygon and build the face normal list (i could probably pack to x10y10z10 this way), then a shader per-vertex to accumulate all the normals of neighbouring faces. This would be an enormous memory hog though, the storage space of the face indices would need 12 int per vertex to deal with the worst case. There's also the problem of how to write into this storage without again resorting to atomics to work out how many faces have already been written to a particular vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone have any better ideas on how to do this?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-03-06T08:54:24.783" Title="Creating shared vertex normals on GPU" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;mesh&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2077" PostTypeId="1" AcceptedAnswerId="2079" CreationDate="2016-02-20T19:08:41.227" Score="6" ViewCount="799" Body="&lt;p&gt;I've recently made the switch to Visual 2015 and the .fx files have been depreciated. My project contained .fx files for the shaders so I've been switching over.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Only during the switch have I changed to using deferred rendering for lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only shader I've made so far is the Pixel Shader that is used on the 2nd Pass, the shader that does the Per Pixel x Per Light calculations, sums them, and outputs final color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, whenever I compile (I'm not actually using the shader in runtime, I'm just getting it all setup, the window is still just cleared to a color every frame, no actual rendering) I get a failure that says....&lt;/p&gt;&#xA;&#xA;&lt;p&gt;error X4502: Shader model ps_4_0_level_9_3 doesn't allow reading from position semantics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the only shader I have in the project that is causing this error.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I omitted the getGBufferAttributes and calculateLighting methods because I know they are not the issue. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Texture2D NormalTexture                 : register(t0);&#xA;Texture2D DiffuseAlbedoTexture          : register(t1);&#xA;Texture2D SpecularAlbedoTexture         : register(t2);&#xA;Texture2D PositionTexture               : register(t3);&#xA;&#xA;cbuffer LightParams&#xA;{&#xA;    float3 LightPos;&#xA;    float3 LightColor;&#xA;    float3 LightDirection;&#xA;    float2 SpotlightAngles;&#xA;    float4 LightRange;&#xA;};&#xA;&#xA;cbuffer CameraParams&#xA;{&#xA;    float3 CameraPos;&#xA;};&#xA;&#xA;float4 main(in float4 screenPos : SV_Position) : SV_Target0&#xA;{&#xA;    float3 normal;&#xA;    float3 position;&#xA;    float3 diffuseAlbedo;&#xA;    float3 specularAlbedo;&#xA;    float specularPower;&#xA;&#xA;    getGBufferAttributes(screenPos.xy, normal, position, diffuseAlbedo, specularAlbedo, specularPower);&#xA;&#xA;    float3 lighting = calculateLighting(normal, position, diffuseAlbedo, specularAlbedo, specularPower);&#xA;&#xA;    return float4(lighting, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The code used for this shader is highly based off the code used as the deferred rendering example in the book, Practical Rendering with Direct3D 11 by Jason Zink, Matt Pettineo, and Jack Hoxley.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand why they would give source code that doesn't work. Does it have something to do with the new compiler in Visual 2015 and the Runtime?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, since I'm going from only using effects before to now raw HLSL shaders, is there anything I should be aware of that might trip somebody like me up?&lt;/p&gt;&#xA;" OwnerUserId="2726" LastActivityDate="2016-02-20T20:40:35.193" Title="HLSL Deferred Rendering" Tags="&lt;shader&gt;&lt;directx11&gt;&lt;pixel-shader&gt;&lt;hlsl&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2078" PostTypeId="1" CreationDate="2016-02-20T19:43:53.280" Score="5" ViewCount="290" Body="&lt;p&gt;I am going throug the topic scan line conversion where the scan line parallel to the x-axis is put through the intersection test with all the edges of the polygon. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would there be any large theoretical differences if we take a small line segment instead, between (x1,y1) and (x2,y2) that is parallel to the x-axis or y-axis and test for intersection with the polygon edges ? The usual case the y = a ( parallel to x-axis) and what I am asking is also parallel to x-axis or y-axis,but constrained between two points instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to develop a tool-path for 3D printing and looking forward to implement HIlbert curve as a tool-path. Generally the very same scan-line concept is used in 3D printing techniques whenever it comes to tool-path generation where parallel scan line to x-axis is used for scanline and polygon edges interesection. I have already got the typical linear scan line for 3D printing and looking forward to implement another way to maneuever the printing head according to the Hilbert curve. In Hilbert curve you have a line segments that change its orientation in such a calculated manner it never self-intersects and simple it follows the FASS characteristics. Hilbert curve containes several small line segments that are parallel to x-axis or y-axis. I am trying to narrow it down to the one line segment of Hilbert curve where the intersection test is to be conducted between one line segment [ (x1,y1) and (x2,y2) ] and the polygon edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that I explained the issue well enough to get some hints to the question asked. Please do ask if anything that I have explained so far is not clear enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks    &lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="2712" LastEditDate="2016-02-21T12:06:38.850" LastActivityDate="2016-02-21T12:06:38.850" Title="scan line conversion" Tags="&lt;vector-graphics&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2079" PostTypeId="2" ParentId="2077" CreationDate="2016-02-20T20:40:35.193" Score="3" Body="&lt;p&gt;A very novice mistake, I was compiling with the old HLSL compiler. But why would that be the default? Very strange.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For anybody wondering, just right click the HLSL file in the solution explorer and go to properties -&gt; HLSL Compiler -&gt; General, and switch Shader Model to the one you want which was newest one for me (5.0)&lt;/p&gt;&#xA;" OwnerUserId="2726" LastActivityDate="2016-02-20T20:40:35.193" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2080" PostTypeId="1" CreationDate="2016-02-20T23:40:52.130" Score="6" ViewCount="197" Body="&lt;p&gt;I am looking for a explanation about volume rendering in simple words, a step by step kind of, like ray tracing: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;for every pixel in the screen plane, trace a ray starting from the eye&#xA;  point to the screen pixel location, a compute the nearest objet&#xA;  intersection in the scene, calculate the pixel color, and so on.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;something like that&lt;/p&gt;&#xA;" OwnerUserId="2684" LastActivityDate="2016-02-21T09:41:26.677" Title="Volume Rendering in simple words" Tags="&lt;volumetric&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2081" PostTypeId="2" ParentId="2080" CreationDate="2016-02-21T00:44:30.847" Score="6" Body="&lt;p&gt;Volume rendering is not like ray-tracing, it is like &quot;scene rendering&quot;. i.e. there exists several algorithms to render volumes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One close to ray-tracing is ray-marching, and has may variants. The simplest:&#xA;&lt;em&gt;for every pixel in the screen plane, trace a ray starting from the eye point to the screen pixel location, and advance along the ray by constant steps. At each voxel calculate the pixel color and transparency, blend it to the pixel value, and so on.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blend = &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;$C_{pix} += T_{pix}*C_{vox}*(1-T_{vox})$ &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$T_{pix} *= T_{vox}$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;with $C_{vox},T_{vox}$ the color and transparency of the current voxel, and $C_{pix},T_{pix}$ the cumulated color and transparency of the pixel.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2016-02-21T09:41:26.677" LastActivityDate="2016-02-21T09:41:26.677" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2082" PostTypeId="2" ParentId="2060" CreationDate="2016-02-21T17:39:54.433" Score="2" Body="&lt;p&gt;You could do this. Basically what you would do is generate a cube for each voxel (or actually nearby voxels could share the edges). Not exactly sure what benefit you would get form this, unless your intersection algorithm is somehow extremely finely tuned. It could be useful for real time rendering or some sort of sparse structure. While your at it why not dispense of the voxel concept altogether and go all FEM on the problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing is you want a more uniform sampling across the volumes density function. Because your integrating over a volume functions you want the step size to be somewhat equally spaced so you can control the integration better. Random or pseudo random solution converges often better, but mainly you do not do cube oriented sampling this way as it will make the structure obvious which is not your goal in most cases. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HaXGH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HaXGH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Different sampling strategies. Images in RTL reading order samples along voxel grids,  Uniforms sampling and jittered ray length sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think of this as solving a ODE you sample the function uniformly and if your value changes too much you might do additional samples. This is probably the reason why you wouldn't really do collision to the voxels.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-02-21T17:39:54.433" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2083" PostTypeId="1" CreationDate="2016-02-21T21:44:14.300" Score="8" ViewCount="469" Body="&lt;p&gt;I know that by now it might be considered as a kind of sad recurrent joke, but by chance, does anyone here has the least information about the colorspace of RGB values in the MERL BRDF measurement database ? &lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-03-29T22:08:33.460" Title="Color space of MERL BRDF database?" Tags="&lt;color-management&gt;&lt;capture&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2085" PostTypeId="2" ParentId="2074" CreationDate="2016-02-22T21:48:31.237" Score="3" Body="&lt;p&gt;Thanks for the replies. According to joojaa's comments, I modified my codes as below,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void RotateImageClockwise(double degree)&#xA;    {&#xA;        Image&amp;lt;double&amp;gt; image = (Image&amp;lt;double&amp;gt;)(PreservedRawImage.Clone());      &#xA;        double sinAngle = Math.Sin(Math.PI * degree / 180.0);&#xA;        double cosAngle = Math.Cos(Math.PI * degree / 180.0);&#xA;        double newHeightRaw, newWidthRaw;&#xA;&#xA;        if (Math.Abs(degree) &amp;lt;= 90)&#xA;        {&#xA;            newHeightRaw = image.Width * Math.Sin(Math.PI * (Math.Abs(degree)) / 180.0) + image.Height * Math.Cos(Math.PI * Math.Abs(degree) / 180.0);&#xA;            newWidthRaw = image.Width * Math.Cos(Math.PI * Math.Abs(degree) / 180.0) + image.Height * Math.Sin(Math.PI * (Math.Abs(degree)) / 180.0);&#xA;        }&#xA;        else if (Math.Abs(degree) &amp;lt;= 180)&#xA;        {&#xA;            newHeightRaw = image.Width * Math.Sin(Math.PI * (180 - Math.Abs(degree)) / 180.0) + image.Height * Math.Sin(Math.PI * (Math.Abs(degree) - 90) / 180.0);&#xA;            newWidthRaw = image.Width * Math.Cos(Math.PI * (180 - Math.Abs(degree)) / 180.0) + image.Height * Math.Cos(Math.PI * (Math.Abs(degree) - 90) / 180.0);&#xA;        }&#xA;&#xA;        int newWidth = (int)Math.Round(newWidthRaw);&#xA;        int newHeight = (int)Math.Round(newHeightRaw);&#xA;        Image&amp;lt;double&amp;gt; newImage = new Image&amp;lt;double&amp;gt;(newWidth, newHeight);&#xA;        for (int x = 0; x &amp;lt; newHeight; x++)&#xA;        {&#xA;            for (int y = 0; y &amp;lt; newWidth; y++)&#xA;            {&#xA;                double xt = x - (newHeightRaw - 1) / 2.0;&#xA;                double yt = y - (newWidthRaw - 1) / 2.0;&#xA;&#xA;                double originalX = xt * cosAngle - yt * sinAngle + (image.Height - 1) / 2.0;&#xA;                double originalY = xt * sinAngle + yt * cosAngle + (image.Width - 1) / 2.0;&#xA;&#xA;                double fractionX = Math.Abs(originalX - (int)Math.Round(originalX));&#xA;                double fractionY = Math.Abs(originalY - (int)Math.Round(originalY));&#xA;&#xA;                IList&amp;lt;Point&amp;lt;int&amp;gt;&amp;gt; neighbors = new List&amp;lt;Point&amp;lt;int&amp;gt;&amp;gt; { new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX), y = (int)Math.Round(originalY), weight = (1 - fractionX) * (1 - fractionY)}, &#xA;                                                           new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX), y = (int)Math.Round(originalY) + 1, weight = fractionX * (1 - fractionY)},&#xA;                                                           new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX) + 1, y = (int)Math.Round(originalY), weight = (1 - fractionX) * fractionY},&#xA;                                                           new Point&amp;lt;int&amp;gt;{x = (int)Math.Round(originalX) + 1, y = (int)Math.Round(originalY) + 1, weight = fractionX * fractionY}&#xA;                                                         };&#xA;                bool hasData = false;&#xA;                double newData = 0;&#xA;                double weight = 0;&#xA;                foreach (var neighbor in neighbors)&#xA;                {&#xA;                    if (neighbor.x &amp;gt;= 0 &amp;amp;&amp;amp; neighbor.x &amp;lt; image.Height&#xA;                        &amp;amp;&amp;amp; neighbor.y &amp;gt;= 0 &amp;amp;&amp;amp; neighbor.y &amp;lt; image.Width&#xA;                        &amp;amp;&amp;amp; (neighbor.x) * image.Width + neighbor.y &amp;lt; m_preservedImageValidDataBitmap.Length &amp;amp;&amp;amp; m_preservedImageValidDataBitmap[(neighbor.x) * image.Width + neighbor.y] == 'T')&#xA;                    {&#xA;                        hasData = true;&#xA;                        newData += neighbor.weight * image.Data[(neighbor.x) * image.Width + neighbor.y];&#xA;                        weight += neighbor.weight;&#xA;                    }&#xA;                }                    &#xA;                if (hasData &amp;amp;&amp;amp; weight != 0)&#xA;                {&#xA;                    newData /= weight;&#xA;                    newImage.Data[x * newWidth + y] = newData;                        &#xA;                }&#xA;            }                &#xA;        }&#xA;    } &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now it's working for 90 and 180 degree rotations. But for 45 degree rotation, the bottom line is still blank, which makes me crazy. I'm guessing it's due to the computation inaccuracy when the new image width and height are computed, but I still can't figure it out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OQB9E.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OQB9E.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2720" LastActivityDate="2016-02-22T21:48:31.237" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2086" PostTypeId="1" AcceptedAnswerId="2092" CreationDate="2016-02-23T09:43:40.470" Score="3" ViewCount="779" Body="&lt;p&gt;As explained in Holger Dammetz page &lt;a href=&quot;http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html&quot; rel=&quot;noreferrer&quot;&gt;Hammersley Points on the Hemisphere&lt;/a&gt;, the 2D coordinates (u,v) are usually mapped to the spherical coordinates (θ, φ).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/zOAcc.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zOAcc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;As a result, the coordinate &quot;uniformly distributed&quot; - u in the 2D case - is the polar angle θ. This looks counter-intuitive to me, I would have mapped regularly spaced u values to regularly spaced azimuth φ values. To avoid &quot;empty areas&quot; like in this example:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/R0lK7.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/R0lK7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;which is generated by the mapping of the following 2D set:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/9DZEr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9DZEr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;What is the reason not to map (u, v) to (φ, θ) ?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2016-03-10T09:11:45.747" Title="Why map Hammersley 2D set's (u,v) to sphere's (θ, φ) coordinates (and not to (φ, θ) )?" Tags="&lt;2d&gt;&lt;sampling&gt;&lt;mapping&gt;&lt;distribution&gt;&lt;hemisphere&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2087" PostTypeId="1" AcceptedAnswerId="2290" CreationDate="2016-02-23T12:55:57.477" Score="2" ViewCount="123" Body="&lt;p&gt;So, recently I followed this &lt;a href=&quot;http://www.paulsprojects.net/tutorials/smt/smt.html&quot; rel=&quot;nofollow&quot;&gt;tutorial&lt;/a&gt; about shadow mapping, but in the tutorial it doesn't texture the object.. When I try to add a texture, it's distorted by the &lt;code&gt;TexGen&lt;/code&gt;. Also I've tried to use &lt;code&gt;glActiveTexture()&lt;/code&gt; with no success(dunno exactly how &lt;code&gt;glActiveTexture()&lt;/code&gt; work).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So can anyone help me by adding textures into above code base? From there, I can learn how to use &lt;code&gt;glActiveTexture()&lt;/code&gt; and overcome that &lt;code&gt;TexGen&lt;/code&gt; issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.. To note, I'm not using GLSL.&lt;/p&gt;&#xA;" OwnerUserId="2687" LastActivityDate="2016-04-08T12:52:30.253" Title="How can I use multiple texturing with shadow mapping?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2088" PostTypeId="1" CreationDate="2016-02-23T15:33:31.027" Score="9" ViewCount="1818" Body="&lt;p&gt;I have a set of 3D points (which I recover from a library that performs the tessellation of a solid body) that belong to a curve (i.e., an edge of the solid). That means that the curve surely passes by each of these points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nevertheless, the point set is unordered so I need to sort them in order to be able to draw this curve correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any known approach for these type of problem?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some additional information:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The curves are parametric in general (splines/bezier, circle slices.. ). &lt;/li&gt;&#xA;&lt;li&gt;The points are given as floating point coordinates.&lt;/li&gt;&#xA;&lt;li&gt;The points are packed very densely (but they can be as dense as I want it to be). To give you an idea, for a curve which occupies 19 units in x, 10 units in x and 5 units in z, I quote a sequence of points in a segment of curve: (20.7622, 25.8676, 0) (20.6573, 25.856, 0) (20.5529, 25.8444, 0) (20.4489, 25.8329, 0) (20.3454, 25.8213, 0)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2562" LastEditorUserId="2562" LastEditDate="2016-02-23T16:48:57.977" LastActivityDate="2016-02-23T17:59:07.243" Title="Ordering a set of unorganized points along a curve" Tags="&lt;geometry&gt;&lt;mesh&gt;&lt;curve&gt;" AnswerCount="3" CommentCount="6" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2089" PostTypeId="2" ParentId="2088" CreationDate="2016-02-23T16:09:39.853" Score="3" Body="&lt;p&gt;Since you've only got floating-point representations of the points, there is no guarantee that these still lie exactly on the curve, due to rounding errors. So I think the only generic approach is to approximate where on the curve they were, by finding the closest point on the curve to your sample $(X,Y,Z)$. E.g. if your parametric curve is $(x(t), y(t), z(t))$ then you could try to minimise&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;(X-x(t))^2+(Y-y(t))^2+(Z-z(t))^2&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;with respect to $t$. If you know what type of curve you're dealing with there might be nice analytic solutions to this, otherwise you'll have to resort to some numerical algorithm. Since your points should be very close to the curve, this method should be reliable (provided the minimisation algorithm is), unless you have a sample exactly where the curve (almost) crosses itself. In that case you're probably out of luck anyway, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have that $t$ for each of your points, you can simply sort them by $t$. Of course, if you have any control over how you receive the points you might be able to sidestep all of this trouble by returning $t$ along with the point's coordinates right away while generating them.&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2016-02-23T16:09:39.853" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2090" PostTypeId="2" ParentId="2088" CreationDate="2016-02-23T16:48:34.430" Score="4" Body="&lt;p&gt;After some clarifications, there is probably a much better approach that doesn't even require knowing the parametric form of the curve, and also avoids the potentially problematic numeric minimisation step. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the curve does not intersect itself and the points are sufficiently densely packed on the curve (and by that I mean they have to be closer than any two points on the curve that &lt;em&gt;don't&lt;/em&gt; belong to the same segment, e.g. by the curve wrapping around on itself), then you can easily determine the previous and next point to each sample:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Determine the two nearest neighbours to each point. &lt;a href=&quot;https://en.wikipedia.org/wiki/Nearest_neighbor_search#All_nearest_neighbors&quot; rel=&quot;nofollow&quot;&gt;That's an $O(n \log n)$ operation&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;You'll have to do some special treatment for the endpoints. Their two nearest neighbours will be the next &lt;em&gt;two&lt;/em&gt; points along the curve instead of one on each side. You can either detect these heuristically if the ratio  of the distances to the two neighbours differs by more than some threshold (1.5 say, depends on the smoothness of your curve and how densely the points are packed). Or you can treat your nearest-neighbour data as a graph, in which you'll find that the endpoints' two neighbours point at each other (which shouldn't happen anywhere else in the graph).&lt;/li&gt;&#xA;&lt;li&gt;Now you can simply pick one end point, and walk along the nearest neighbours (always choosing the one you didn't arrive from) to traverse the points along the curve.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Especially if you can make the points very dense this should be the most reliable option unless the curve self-intersects. Even in that case, this approach might be salvageable provided the self-intersection is at a sufficiently large angle the curve smooth enough (in that case you can choose the correct neighbours based on some constraint that successive steps cannot make an angle greater than some threshold $\theta$).&lt;/p&gt;&#xA;" OwnerUserId="16" LastActivityDate="2016-02-23T16:48:34.430" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2091" PostTypeId="2" ParentId="2088" CreationDate="2016-02-23T17:59:07.243" Score="6" Body="&lt;p&gt;You have an instance of a problem called &lt;em&gt;curve reconstruction from unorganized points&lt;/em&gt;. Now that you know what to search for you'll find several methods, such as the crust, NN-crust, etc. Here are a few links:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://sarielhp.org/research/CG/applets/Crust/Crust.html&quot;&gt;The Crust Curve Reconstruction Applet&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://web.cse.ohio-state.edu/~tamaldey/curverecon.htm&quot;&gt;Curve Reconstruction&lt;/a&gt; by Tamal Dey&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.cambridge.org/catalogue/catalogue.asp?isbn=9780521863704&quot;&gt;Curve and Surface Reconstruction: Algorithms with Mathematical Analysis&lt;/a&gt;, book by Tamal K. Dey, Cambridge University Press, 2006&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Since you're dealing with curves and the samples are dense, I suggest you compute an Euclidean minimal spanning tree.&lt;/p&gt;&#xA;" OwnerUserId="192" LastActivityDate="2016-02-23T17:59:07.243" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2092" PostTypeId="2" ParentId="2086" CreationDate="2016-02-24T14:37:14.710" Score="4" Body="&lt;p&gt;You can of course, as you suggested, map (u, v) to (φ, θ). Unfortunately, it does not solve the problem for 5 points:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/csMKn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/csMKn.png&quot; alt=&quot;Switched mapping&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've changed Holger Dammertz' code a bit (switched u and v), and you see that the problem still persists. For a higher number of points, it really doesn't seem to make a (visual) difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Hammersley point set is a way to &lt;strong&gt;very quickly&lt;/strong&gt; determine points on a sphere that have good, but don't need to have a perfect distribution. In the problematic case of very few points, Hammersley might just not be the tool for the job. Pre-calculating and storing points sounds like a better option to me.&lt;/p&gt;&#xA;" OwnerUserId="385" LastActivityDate="2016-02-24T14:37:14.710" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2093" PostTypeId="1" AcceptedAnswerId="5807" CreationDate="2016-02-25T17:22:44.533" Score="3" ViewCount="852" Body="&lt;p&gt;I have a 3D model, which consists of ~50 thousand vertices and 100 thousand triangles. Format is: there's array of vertices' coordinates and array of triangles, which has numbers of vertices (e.g., [1, 2, 5] -- triangle, which consists of first, second and fifth vertex from vertices' array).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I calculate color of each triangle and rotate the model by myself.&#xA;Also I &quot;render&quot; it manually, putting vertices as pixels on &lt;code&gt;PIL&lt;/code&gt; image, but matrix with colors is enough for my purpose (I need only the matrix).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know, whether I will implement robust and correct rendering function, but I cannot find light-weight library as well.&#xA;All I need is to display the set of triangles with specified colors and  background image fast (far less than for a second).&lt;/p&gt;&#xA;" OwnerUserId="2750" LastEditorUserId="2750" LastEditDate="2017-07-27T05:46:46.710" LastActivityDate="2017-11-01T18:50:48.140" Title="Triangulated model rasterization: light-weight Python library" Tags="&lt;3d&gt;&lt;raster-image&gt;&lt;render&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2094" PostTypeId="1" AcceptedAnswerId="2101" CreationDate="2016-02-25T22:53:01.660" Score="1" ViewCount="211" Body="&lt;p&gt;&lt;strong&gt;Some possible things that might be the issue and could be explained by someone who is knowledgeable&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Order of my indices, In all I've read, your array of indices for a triangle list is just clockwise order, see below how I ordered it for proof. &lt;strong&gt;EDIT - I have changed my indices according to Jason Allen's comment, no change&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;Keep in mind that my code runs fine, no errors, no warnings(that I know of) related to my issue.&lt;/li&gt;&#xA;&lt;li&gt;Can these warnings be an issue?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UJYGI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UJYGI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been banging my head over this issue for far too long. I know the answer is going to be ridiculously simple but somehow it has successfully evaded me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been implementing deferred rendering into my engine and my second pass, the one that actually renders to the swap chain buffer, is staying black (or whatever color I clear it to before rendering).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I know the issue has nothing to do with anything associated with the first pass/gBuffer because I am completely bypassing that part, literally commented out the call to it in the game loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My 2nd Pass Deferred Vertex Shader is as follows... &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 main( float4 pos : POSITION ) : SV_POSITION&#xA;{&#xA;     return pos;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My 2nd Pass Pixel Shader is as follows... &#xA;I have omitted the actual lighting code because it is all commented out until I fix the issue. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; float4 main(in float4 screenPos : SV_Position) : SV_Target&#xA; {&#xA;     return float4(1.0f,1.0f,1.0f, 1.0f);&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can see I am not doing anything related to lighting or anything, all I'm trying to do is set every pixel to white, I want to see it work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my renderSecondPass function. this is what I call every frame. Irrelevant code has been omitted.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; void DirectX::renderSecondPass()&#xA; {&#xA; nullShaders();&#xA;&#xA; d3d11DeviceContext-&amp;gt;VSSetShader(deferredVertexShader, NULL, 0);&#xA; d3d11DeviceContext-&amp;gt;PSSetShader(deferredPixelShader, NULL, 0);&#xA;&#xA; HRESULT hr;&#xA; float clear[] = { 1.0, 0.5, 0.0, 1.0 };&#xA;&#xA; d3d11DeviceContext-&amp;gt;OMSetRenderTargets(1, &amp;amp;d3d11RenderTargetView, NULL);&#xA; d3d11DeviceContext-&amp;gt;ClearRenderTargetView(d3d11RenderTargetView, clear);&#xA;&#xA; d3d11DeviceContext-&amp;gt;IASetInputLayout(InputLayout::Deferred);&#xA; d3d11DeviceContext-&amp;gt;IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);&#xA;&#xA;&#xA; for (unsigned int i = 0; i &amp;lt; lightBuffer.size(); i++)&#xA; {&#xA;    UINT stride = sizeof(Vertex::Deferred);&#xA;    UINT offset = 0;&#xA;&#xA;    d3d11DeviceContext-&amp;gt;IASetVertexBuffers(0, 1, &amp;amp;deferredQuadVB, &amp;amp;stride, &amp;amp;offset);&#xA;    d3d11DeviceContext-&amp;gt;IASetIndexBuffer(deferredQuadIB, DXGI_FORMAT_R32_UINT, 0);&#xA;&#xA;    d3d11DeviceContext-&amp;gt;DrawIndexed(deferredQuadIndiceCount, 0, 0);&#xA; }&#xA;&#xA; hr = swapChain-&amp;gt;Present(0, 0);&#xA;&#xA; if (FAILED(hr))&#xA; {&#xA;     MessageBox(0, L&quot;Swap Chain Present Error.&quot;, 0, 0);&#xA; }&#xA;&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the Input Layout...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; namespace Vertex&#xA; {&#xA;     struct Deferred&#xA;     {&#xA;         VECTOR&amp;lt;float&amp;gt; Position;&#xA;         float Position_W;&#xA;     };&#xA; }&#xA; // C++ side above &#xA;&#xA; // Shaderside below&#xA; namespace InputLayout&#xA; {&#xA;     static ID3D11InputLayout* Deferred;&#xA; }&#xA;&#xA; const D3D11_INPUT_ELEMENT_DESC InputLayoutDesc::DEFERRED_VS_INPUTLAYOUT_DESC[] =&#xA; {&#xA;     { &quot;POSITION&quot;,  0, DXGI_FORMAT_R32G32B32A32_FLOAT,  0, 0,   D3D11_INPUT_PER_VERTEX_DATA, 0 }&#xA; };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Creation of the Input Layouts and Loading of the shaders themselves from file. &#xA;Irrelevant code has been omitted.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool DirectX::initShaders()&#xA;{&#xA;std::vector&amp;lt;char&amp;gt; shaderBuffer;&#xA;std::string filename;&#xA;HRESULT hr;&#xA;&#xA;// deferredVS&#xA;filename = &quot;Shaders\\deferredVS.cso&quot;;&#xA;if (!shaderFileToMemory(filename, shaderBuffer))&#xA;{&#xA;    MessageBox(0, L&quot;Load defaultVS Shader Into Memory Error.&quot;, 0, 0);&#xA;    return false;&#xA;}&#xA;hr = d3d11Device-&amp;gt;CreateVertexShader(&amp;amp;shaderBuffer[0], shaderBuffer.size(), NULL, &amp;amp;deferredVertexShader);&#xA;hr = d3d11Device-&amp;gt;CreateInputLayout(InputLayoutDesc::DEFERRED_VS_INPUTLAYOUT_DESC, 1, &amp;amp;shaderBuffer[0], shaderBuffer.size(), &amp;amp;InputLayout::Deferred);&#xA;&#xA;// deferredPS&#xA;filename = &quot;Shaders\\deferredPS.cso&quot;;&#xA;if (!shaderFileToMemory(filename, shaderBuffer))&#xA;{&#xA;    MessageBox(0, L&quot;Load deferredPS Shader Into Memory Error.&quot;, 0, 0);&#xA;    return false;&#xA;}&#xA;hr = d3d11Device-&amp;gt;CreatePixelShader(&amp;amp;shaderBuffer[0], shaderBuffer.size(), NULL, &amp;amp;deferredPixelShader);&#xA;&#xA;return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The Vertex and Index Buffer were created using the following...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; bool DirectX::initDeferredQuad()&#xA; {&#xA;std::vector&amp;lt;Vertex::Deferred&amp;gt; deferredQuadVertices;&#xA;std::vector&amp;lt;unsigned int&amp;gt; deferredQuadIndices;&#xA;&#xA;Vertex::Deferred quadVertices[4];&#xA;Vertex::Deferred quadVertice;&#xA;&#xA;quadVertice.Position_W  = 1.0;&#xA;quadVertice.Position = VECTOR&amp;lt;float&amp;gt;(-1.0, 1.0, 0.0);&#xA;quadVertices[0] = quadVertice;&#xA;quadVertice.Position = VECTOR&amp;lt;float&amp;gt;(1.0, 1.0, 0.0);&#xA;quadVertices[1] = quadVertice;&#xA;quadVertice.Position = VECTOR&amp;lt;float&amp;gt;(-1.0, -1.0, 0.0);&#xA;quadVertices[2] = quadVertice;&#xA;quadVertice.Position = VECTOR&amp;lt;float&amp;gt;(1.0, -1.0, 0.0);&#xA;quadVertices[3] = quadVertice;&#xA;&#xA;D3D11_BUFFER_DESC vbd;&#xA;D3D11_SUBRESOURCE_DATA vinitData;&#xA;HRESULT hr;&#xA;&#xA;vbd.Usage               = D3D11_USAGE_IMMUTABLE;&#xA;vbd.ByteWidth           = sizeof(Vertex::Deferred) * 4;&#xA;vbd.BindFlags           = D3D11_BIND_VERTEX_BUFFER;&#xA;vbd.CPUAccessFlags      = 0;&#xA;vbd.MiscFlags           = 0;&#xA;vbd.StructureByteStride = 0;&#xA;&#xA;vinitData.pSysMem       = &amp;amp;quadVertices;&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateBuffer(&amp;amp;vbd, &amp;amp;vinitData, &amp;amp;deferredQuadVB);&#xA;&#xA;if (FAILED(hr))&#xA;{&#xA;    MessageBox(0, L&quot;Quad Vertex Buffer Creation Error.&quot;, 0, 0);&#xA;    return false;&#xA;}&#xA;&#xA;unsigned int quadIndices[] =&#xA;{   0, 1, 2,&#xA;    2, 1, 3 };&#xA;&#xA;deferredQuadIndiceCount = 6;&#xA;&#xA;D3D11_BUFFER_DESC ibd;&#xA;D3D11_SUBRESOURCE_DATA iinitData;&#xA;&#xA;ibd.Usage               = D3D11_USAGE_IMMUTABLE;&#xA;ibd.ByteWidth           = sizeof(unsigned int) * 6;&#xA;ibd.BindFlags           = D3D11_BIND_INDEX_BUFFER;&#xA;ibd.CPUAccessFlags      = 0;&#xA;ibd.MiscFlags           = 0;&#xA;&#xA;iinitData.pSysMem       = &amp;amp;deferredQuadIndices;&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateBuffer(&amp;amp;ibd, &amp;amp;iinitData, &amp;amp;deferredQuadIB);&#xA;&#xA;if (FAILED(hr))&#xA;{&#xA;    MessageBox(0, L&quot;QuadIndex Buffer Creation Error.&quot;, 0, 0);&#xA;    return false;&#xA;}&#xA;&#xA;return true;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I thought the issue was here. Since my Vertex Shader is feeding the Rasterizer data directly, the Vertex Shader has to output SV_Position in Clip Space. Wouldn't the coordinates I've made for my vertices be correct for a quad composed of 2 triangles that would take up the entire screen? (I've tried changing the z values, no change)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is resizeSwapChain, I've been bulding/rebuild the viewport in here.&#xA;This function is called at initialization and whenever the window size changes after the window adjustment has been released (WM_EXITSIZEMOVE).&#xA;Irrelevant code has been omitted.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; void DirectX::resizeSwapChain()&#xA; {&#xA;const unsigned int clientWidth = uClient-&amp;gt;getAppScreenWidth();&#xA;const unsigned int clientHeight = uClient-&amp;gt;getAppScreenHeight();&#xA;HRESULT hr;&#xA;&#xA;if (!(d3d11RenderTargetView == NULL))&#xA;{&#xA;    d3d11RenderTargetView-&amp;gt;Release();&#xA;    d3d11RenderTargetView = 0;&#xA;}&#xA;&#xA;if (!(d3d11DepthStencilView) == NULL)&#xA;{&#xA;    d3d11DepthStencilView-&amp;gt;Release();&#xA;    d3d11DepthStencilView = 0;&#xA;}&#xA;&#xA;if (!(d3d11StencilBuffer) == NULL)&#xA;{&#xA;    d3d11StencilBuffer-&amp;gt;Release();&#xA;    d3d11StencilBuffer = 0;&#xA;}&#xA;&#xA;hr = swapChain-&amp;gt;ResizeBuffers(1, clientWidth, clientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0);&#xA;&#xA;ID3D11Texture2D* backBuffer;&#xA;&#xA;hr = swapChain-&amp;gt;GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast&amp;lt;void**&amp;gt;(&amp;amp;backBuffer));&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateRenderTargetView(backBuffer, 0, &amp;amp;d3d11RenderTargetView);&#xA;&#xA;backBuffer-&amp;gt;Release();&#xA;backBuffer = 0;&#xA;&#xA;D3D11_TEXTURE2D_DESC depthStencilDesc;&#xA;&#xA;depthStencilDesc.Width = clientWidth;&#xA;depthStencilDesc.Height = clientHeight;&#xA;depthStencilDesc.MipLevels = 1;&#xA;depthStencilDesc.ArraySize = 1;&#xA;depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;&#xA;&#xA;if (msaaEnabled)&#xA;{&#xA;    depthStencilDesc.SampleDesc.Count = 4;&#xA;    depthStencilDesc.SampleDesc.Quality = msaaQuality - 1;&#xA;}&#xA;else&#xA;{&#xA;    depthStencilDesc.SampleDesc.Count = 1;&#xA;    depthStencilDesc.SampleDesc.Quality = 0;&#xA;}&#xA;&#xA;depthStencilDesc.Usage = D3D11_USAGE_DEFAULT;&#xA;depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL;&#xA;depthStencilDesc.CPUAccessFlags = 0;&#xA;depthStencilDesc.MiscFlags = 0;&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateTexture2D(&amp;amp;depthStencilDesc, 0, &amp;amp;d3d11StencilBuffer);&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateDepthStencilView(d3d11StencilBuffer, 0, &amp;amp;d3d11DepthStencilView);&#xA;&#xA;d3d11ScreenViewport.TopLeftX = 0;&#xA;d3d11ScreenViewport.TopLeftY = 0;&#xA;d3d11ScreenViewport.Width = static_cast&amp;lt;float&amp;gt;(clientWidth);&#xA;d3d11ScreenViewport.Height = static_cast&amp;lt;float&amp;gt;(clientHeight);&#xA;d3d11ScreenViewport.MinDepth = 0.0f;&#xA;d3d11ScreenViewport.MaxDepth = 1.0f;&#xA;&#xA;d3d11DeviceContext-&amp;gt;RSSetViewports(1, &amp;amp;d3d11ScreenViewport);&#xA;&#xA;mainCamera-&amp;gt;setProjectionMatrix(MATRIX4X4&amp;lt;float&amp;gt;::perspectiveFieldOfViewLeftHandMatrix(0.25 * GenericMath::PI, GenericMath::aspectRatio(clientWidth, clientHeight), 0.001, 1000.0));&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is my D3D11 Initialization function, this is where I create my Rasterization states.&#xA;Irrelevant code has been omitted.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; bool DirectX::initDirectX()&#xA; {&#xA;D3D_FEATURE_LEVEL featureLevel;&#xA;&#xA;HRESULT hr = D3D11CreateDevice(NULL, driverType, NULL, NULL, NULL, 0, D3D11_SDK_VERSION, &amp;amp;d3d11Device, &amp;amp;featureLevel, &amp;amp;d3d11DeviceContext);&#xA;&#xA;hr = d3d11Device-&amp;gt;CheckMultisampleQualityLevels( DXGI_FORMAT_R8G8B8A8_UNORM, 4, &amp;amp;msaaQuality);&#xA;&#xA;DXGI_SWAP_CHAIN_DESC swapChainDesc;&#xA;swapChainDesc.BufferDesc.Width = uClient-&amp;gt;getAppScreenWidth();&#xA;swapChainDesc.BufferDesc.Height = uClient-&amp;gt;getAppScreenHeight();&#xA;swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;&#xA;swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;&#xA;swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;&#xA;swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;&#xA;&#xA;if (msaaEnabled)&#xA;{&#xA;    swapChainDesc.SampleDesc.Count = 4;&#xA;    swapChainDesc.SampleDesc.Quality = msaaQuality - 1;&#xA;}&#xA;else&#xA;{&#xA;    swapChainDesc.SampleDesc.Count = 1;&#xA;    swapChainDesc.SampleDesc.Quality = 0;&#xA;}&#xA;&#xA;swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;&#xA;swapChainDesc.BufferCount = 1;&#xA;swapChainDesc.OutputWindow = *windowsHandle;&#xA;swapChainDesc.Windowed = true;&#xA;swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;&#xA;swapChainDesc.Flags = 0;&#xA;&#xA;IDXGIDevice* dxgiDevice = 0;&#xA;hr = d3d11Device-&amp;gt;QueryInterface(__uuidof(IDXGIDevice), (void**)&amp;amp;dxgiDevice);&#xA;&#xA;IDXGIAdapter* dxgiAdapter = 0;&#xA;hr = dxgiDevice-&amp;gt;GetParent(__uuidof(IDXGIAdapter), (void**)&amp;amp;dxgiAdapter);&#xA;&#xA;IDXGIFactory* dxgiFactory = 0;&#xA;hr = dxgiAdapter-&amp;gt;GetParent(__uuidof(IDXGIFactory), (void**)&amp;amp;dxgiFactory);&#xA;&#xA;hr = dxgiFactory-&amp;gt;CreateSwapChain(d3d11Device, &amp;amp;swapChainDesc, &amp;amp;swapChain);&#xA;&#xA;dxgiDevice-&amp;gt;Release();&#xA;dxgiDevice = 0;&#xA;&#xA;dxgiAdapter-&amp;gt;Release();&#xA;dxgiAdapter = 0;&#xA;&#xA;dxgiFactory-&amp;gt;Release();&#xA;dxgiFactory = 0;&#xA;&#xA;resizeGBuffers();&#xA;resizeSwapChain();&#xA;&#xA;D3D11_RASTERIZER_DESC rasterizerDesc;&#xA;ZeroMemory(&amp;amp;rasterizerDesc, sizeof(D3D11_RASTERIZER_DESC));&#xA;rasterizerDesc.FillMode = D3D11_FILL_SOLID;&#xA;rasterizerDesc.CullMode = D3D11_CULL_BACK;&#xA;rasterizerDesc.FrontCounterClockwise = false;&#xA;rasterizerDesc.DepthClipEnable = true;&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateRasterizerState( &amp;amp;rasterizerDesc, &amp;amp;d3d11SolidRS);\&#xA;&#xA;ZeroMemory(&amp;amp;rasterizerDesc, sizeof(D3D11_RASTERIZER_DESC));&#xA;&#xA;rasterizerDesc.FillMode = D3D11_FILL_WIREFRAME;&#xA;rasterizerDesc.CullMode = D3D11_CULL_BACK;&#xA;rasterizerDesc.FrontCounterClockwise = false;&#xA;rasterizerDesc.DepthClipEnable = true;&#xA;&#xA;hr = d3d11Device-&amp;gt;CreateRasterizerState( &amp;amp;rasterizerDesc, &amp;amp;d3d11WireframeRS);&#xA;&#xA;d3d11DeviceContext-&amp;gt;RSSetState(d3d11SolidRS);&#xA;&#xA;return true;&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If anyone needs more info, just ask. Thanks&lt;/p&gt;&#xA;" OwnerUserId="2726" LastEditorUserId="2726" LastEditDate="2016-02-26T12:17:57.383" LastActivityDate="2016-02-26T16:05:40.143" Title="Trouble Finding Simple 2D DirecX11/HLSL Issue" Tags="&lt;directx11&gt;&lt;pixel-shader&gt;&lt;hlsl&gt;&lt;deferred-rendering&gt;" AnswerCount="3" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2095" PostTypeId="2" ParentId="2094" CreationDate="2016-02-26T00:06:17.400" Score="1" Body="&lt;p&gt;Your indices are wrong, they should start at 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Correct indices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned int quadIndices[] =&#xA;{   0, 1, 2,&#xA;    2, 1, 3 };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="40" LastActivityDate="2016-02-26T00:06:17.400" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2096" PostTypeId="2" ParentId="2094" CreationDate="2016-02-26T00:18:30.017" Score="3" Body="&lt;p&gt;You have not set a viewport with RSSetViewports. You need to set this to the pixel dimensions of your render target. Without this the viewport will be set to 0,0,0,0 meaning no pixels will be touched.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally you have not set a raster state or blend state. It is good practice to set these and can be helpful early on to set the winding order in the raster state to not cull, this can come in handy if you are working out the vertex positions by hand.&lt;/p&gt;&#xA;" OwnerUserId="2752" LastActivityDate="2016-02-26T00:18:30.017" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2099" PostTypeId="1" AcceptedAnswerId="2104" CreationDate="2016-02-26T13:34:28.383" Score="4" ViewCount="387" Body="&lt;p&gt;I'm beginner in OpenGL and I stumbled into a problem. I'm in OpenGL 2.1 for the time being, if that's of any help. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I set my Frustum as such:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glFrustum(-1366, 1366, -768, 768, 1, 20000);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now, when I create a cube from quads like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.0, 500.0, 0.0&#xA;500.0, 500.0, 0.0&#xA;500.0, 0.0, 0.0&#xA;0.0, 0.0, 0.0&#xA;0.0, 500.0, 500.0&#xA;500.0, 500.0, 500.0&#xA;500.0, 0.0, 500.0&#xA;etc.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It is not a cube, as I expected. It's extremely stretched along the z axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a screenshot of how it looks now: &lt;a href=&quot;https://www.dropbox.com/s/diznfumtev7g259/Screenshot%20from%202016-02-26%2017%3A01%3A58.png?dl=0&quot; rel=&quot;nofollow&quot;&gt;https://www.dropbox.com/s/diznfumtev7g259/Screenshot%20from%202016-02-26%2017%3A01%3A58.png?dl=0&lt;/a&gt; (I removed one of the faces temporarily)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shape starts to resemble a cube a bit when I change the vertices to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.0, 500.0, 0.0&#xA;500.0, 500.0, 0.0&#xA;500.0, 0.0, 0.0&#xA;0.0, 0.0, 0.0&#xA;0.0, 500.0, 0.3&#xA;500.0, 500.0, 0.3&#xA;500.0, 0.0, 0.3&#xA;etc.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Code related to this (I am translating this from assembly which I am actually using).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Matrices setup on initialization:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glMatrixMode(GL_PROJECTION);&#xA;glLoadIdentity();&#xA;glFrustum(-1366.0, 1366.0, -768.0, 768.0, 1.0, 20000.0);&#xA;&#xA;glMatrixMode(GL_MODELVIEW);&#xA;glLoadIdentity();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Transformations of the cube inside the &quot;render()&quot; function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glLoadIdentity();&#xA;glTranslated(1000.0, 500.0, 0.0);&#xA;glRotated(degrees, 0.0, 0.0, 1.0); // degrees is +=2 every frame&#xA;glTranslated(-250.0, -250.0, distance); // distance is -=0.001 every frame&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There are no other matrix operations in the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code uses GLUT to initialize a window with double buffer and depth buffer. Depth testing is enabled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It all seems to work as expected, the rotation is ok, movement also. I am only troubled by the fact that when I define a 500.0x500.0x500.0 cube, the actual output is not a cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I doing wrong? How to fix this?&lt;/p&gt;&#xA;" OwnerUserId="2508" LastEditorUserId="2508" LastEditDate="2016-02-26T16:00:45.180" LastActivityDate="2016-02-26T22:46:50.040" Title="Frustum - problem with z dimension" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2101" PostTypeId="2" ParentId="2094" CreationDate="2016-02-26T16:05:40.143" Score="2" Body="&lt;p&gt;I can't believe it has taken me this long to find this...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the array I was giving the Index Buffer Desc that contains the data was the wrong one... It was a blank one that I forgot I didn't need, the vector if you look at the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ruxiT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ruxiT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Look at that garbage. Those are supposed to be the indices...&#xA;Well at least I know how to use the debugger now, thanks guys got it working.&lt;/p&gt;&#xA;" OwnerUserId="2726" LastActivityDate="2016-02-26T16:05:40.143" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2102" PostTypeId="1" AcceptedAnswerId="2119" CreationDate="2016-02-26T17:49:05.657" Score="11" ViewCount="1140" Body="&lt;p&gt;JFA (the algorithm described here: &lt;a href=&quot;http://www.comp.nus.edu.sg/~tants/jfa/i3d06.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://www.comp.nus.edu.sg/~tants/jfa/i3d06.pdf&lt;/a&gt;) can be used to get an approximation of a Voronoi diagram, or a distance transform.  It does so in logarithmic time based on the size of the resulting image, not on the number of seeds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do you do if your image is not the same size on each axis though?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If they were similar sizes, I'm sure you could just let the shorter axis have extra JFA steps of size 1, while the larger axis finished it work (like having a 512 x 256 sized image).  For vastly different sized axis dimensions this could be a lot more inefficient though - say that you had a volume texture that was 512 x 512 x 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to run JFA on each axis separately and still get decent results?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or at that point is a different algorithm more appropriate to use? If so, what algorithm might that be?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my situation ideally I'm looking to support both single point seeds, as well as arbitrary shaped seeds.  Possibly even weighted seeds, where the distance to a seed is adjusted by a multiplier and/or an adder to give it more or less influence.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-02-29T21:47:32.867" LastActivityDate="2016-02-29T22:40:15.907" Title="Is Jump Flood Algorithm Separable?" Tags="&lt;signed-distance-field&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2103" PostTypeId="2" ParentId="2083" CreationDate="2016-02-26T19:58:08.587" Score="-1" Body="&lt;p&gt;Disney have a tool that analyses the database. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.disneyanimation.com/technology/brdf.html&quot; rel=&quot;nofollow&quot;&gt;http://www.disneyanimation.com/technology/brdf.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is browsing the source code for this an option?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/wdas/brdf&quot; rel=&quot;nofollow&quot;&gt;https://github.com/wdas/brdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could contact the authors perhaps?&lt;/p&gt;&#xA;" OwnerUserId="2748" LastActivityDate="2016-02-26T19:58:08.587" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2104" PostTypeId="2" ParentId="2099" CreationDate="2016-02-26T22:46:50.040" Score="2" Body="&lt;p&gt;Okay. So after 6 hours of tinkering with my code, trying different approaches and googling for solutions, I found this page:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.glprogramming.com/red/chapter03.html&quot; rel=&quot;nofollow&quot;&gt;http://www.glprogramming.com/red/chapter03.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a short C listing which put me on the right track to solve this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I did wrong was that I should have set the frustum to something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLdouble x0 = -(1366/768);&#xA;GLdouble x1 = 1366/768;&#xA;glFrustum(x0, x1, -1, 1, 1, 100);&#xA;// the last two values aren't critical, as long as they are positive&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But before that, I should have set the &lt;strong&gt;glViewport&lt;/strong&gt; properly, before setting up the frustum:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glViewport(0, 0, 1366, 768);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;I didn't do it and that's why my code produced such weird results.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I can create a unit cube with following vertices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.0, 1.0, 0.0&#xA;1.0, 1.0, 0.0&#xA;1.0, 0.0, 0.0&#xA;0.0, 0.0, 0.0&#xA;0.0, 1.0, 1.0&#xA;1.0, 1.0, 1.0&#xA;1.0, 0.0, 1.0&#xA;0.0, 0.0, 1.0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And it will display properly as a cube of size 1 in every direction.&lt;/p&gt;&#xA;" OwnerUserId="2508" LastActivityDate="2016-02-26T22:46:50.040" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2105" PostTypeId="1" CreationDate="2016-02-27T18:39:16.277" Score="4" ViewCount="551" Body="&lt;p&gt;I have a line segment defined by two end points. And I have another randomly chosen third point and I want to find out if the third point is on the line segment or not. By &quot;On the line segment&quot;, I mean that exactly on the line segment, not intersecting the line segment and end up on the other side of the line segment. I hope I explained the issue. Some mathematical explanation along with algorithm to it  is earnestly requested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-02-29T16:23:22.420" Title="Test if a point is on a line segment" Tags="&lt;vectors&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2106" PostTypeId="1" CreationDate="2016-02-27T22:40:53.963" Score="1" ViewCount="67" Body="&lt;p&gt;I have the world point positions of two objects, and would like to test if there is an intersection between the two objects from this information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What methods can I use to test this, especially at the boundaries. &lt;/p&gt;&#xA;" OwnerUserId="2748" LastActivityDate="2016-02-28T05:45:40.427" Title="How to test if one object A intersects and is therefore partly or wholly inside object B" Tags="&lt;algorithm&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2107" PostTypeId="2" ParentId="2083" CreationDate="2016-02-27T22:48:44.553" Score="2" Body="&lt;p&gt;Was interested in this myself and did some digging, I was wondering if they where spectral, but it appears not (although some interesting work on spectral BRDF is here &lt;a href=&quot;http://web.cs.wpi.edu/~emmanuel/courses/cs563/write_ups/cliffl/cliffl_spectral_brdf.html&quot; rel=&quot;nofollow&quot;&gt;http://web.cs.wpi.edu/~emmanuel/courses/cs563/write_ups/cliffl/cliffl_spectral_brdf.html&lt;/a&gt; )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This chat seems to indicate they are camera native linear, probably with sRGB primaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://groups.google.com/forum/#!msg/pbrt/p9zMvZlaodA/4RD7-We8h4gJ&quot; rel=&quot;nofollow&quot;&gt;https://groups.google.com/forum/#!msg/pbrt/p9zMvZlaodA/4RD7-We8h4gJ&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2748" LastActivityDate="2016-02-27T22:48:44.553" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2108" PostTypeId="2" ParentId="2105" CreationDate="2016-02-28T04:47:55.957" Score="5" Body="&lt;p&gt;Let's say you have your two points that define the line segment: $A$ and $B$, and a point $P$ that you are testing to see if it is on the line segment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Firstly, you get a normalized vector from $A$ to $B$, as well as the distance from $A$ to $B$.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;direction = normalize(B - A);&#xA;length = length(B-A);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Next, you use dot product to project the point $P$ onto the line segment defined by $A$ and $B$, by first getting the vector from $A$ to $P$ and then dot producting that against the direction vector.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PRelative = P-A;&#xA;projection = dot(PRelative, direction);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This projection value represents how far down the line segment from $A$ to $B$ that the closest point to $P$ is.  It may be a negative distance, or it might be farther from $A$ than $B$ is, so you next clamp this value to the line segment.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;projection = clamp(projection, 0.0, length);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that in your case, instead of clamping, you could just detect when the projection was out of bounds and return false at this point as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Continuing on, you now have the distance from $A$ to $B$ that the closest point to $P$ is, as the value in $projection$.  You calculate that actual point:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;closestPoint = A + projection * direction;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If $closestPoint$ == $P$, you know that $P$ lies on the line segment defined by $A$ and $B$ because the closest point on that line segment is the point $P$ itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in practice, you might run into some numerical precision problems due to having limited accuracy in computer calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get around this, instead of checking if $closestPoint$ and $P$ are the same, you should probably instead consider them the same if the distance between them is smaller than some threshold value.  This way, if precision issues come up, you'll still get the answers you want in the cases you want them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Too large of a threshold value, and you will get points being considered on the line that you really wouldn't consider on the line (if this happens, make your threshold smaller).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Too small of a threshold value, and some points that you would consider being on the line will not register as being on the line (if this happens, make your threshold larger).&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-02-29T16:23:22.420" LastActivityDate="2016-02-29T16:23:22.420" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="2109" PostTypeId="2" ParentId="2106" CreationDate="2016-02-28T05:45:40.427" Score="2" Body="&lt;p&gt;Do you need exact triangle - triangle intersection test that is do you need to know exactly the points of intersection of each object? If you just need a simple yes / no they have intersected then you could get away with creating an AABB ( &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume&quot; rel=&quot;nofollow&quot;&gt;https://en.wikipedia.org/wiki/Bounding_volume&lt;/a&gt; ) that encompasses each object and do a AABB -&gt; AABB ( good info here &lt;a href=&quot;https://studiofreya.com/3d-math-and-physics/simple-aabb-vs-aabb-collision-detection/&quot; rel=&quot;nofollow&quot;&gt;https://studiofreya.com/3d-math-and-physics/simple-aabb-vs-aabb-collision-detection/&lt;/a&gt; ) intersection test? even if you need a more complex collision check Triangle -&gt; Triangle it is always a good idea to do a simple collision check first to make sure its worth doing the complex Triangle -&gt; Triangle intersection tests. Look here ( &lt;a href=&quot;http://www.realtimerendering.com/intersections.html&quot; rel=&quot;nofollow&quot;&gt;http://www.realtimerendering.com/intersections.html&lt;/a&gt; ) for all the normal object -&gt; object intersection tests you could possibly need &lt;/p&gt;&#xA;" OwnerUserId="288" LastActivityDate="2016-02-28T05:45:40.427" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2110" PostTypeId="1" AcceptedAnswerId="2112" CreationDate="2016-02-28T15:05:52.690" Score="10" ViewCount="754" Body="&lt;p&gt;Single-scattering microfacet-based surface models like the original &lt;a href=&quot;http://www.graphics.cornell.edu/~westin/pubs/TorranceSparrowJOSA1967.pdf&quot; rel=&quot;noreferrer&quot;&gt;Torrance-Sparrow BRDF&lt;/a&gt; or derived models like &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;noreferrer&quot;&gt;the BSDF for rough dielectric surfaces&lt;/a&gt; by Walter et al. neglect inter-reflection of light between microfacets, which results in energy loss causing darkening especially at higher roughness values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem can be easily demonstrated using the furnace test. The following images show the behaviour of my implementation of a conductive microfacet BRDF using the Smith model and GGX distribution for roughness parameters from 0.2 to 1.0 (the Fresnel coefficient is deliberately set to 1 here to make the problem easier to see):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZmLm3.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZmLm3.jpg&quot; alt=&quot;roughness 0.2&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/lIxSc.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lIxSc.jpg&quot; alt=&quot;roughness 0.4&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/autib.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/autib.jpg&quot; alt=&quot;roughness 0.6&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Ij2yS.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ij2yS.jpg&quot; alt=&quot;roughness 0.8&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/eP5XW.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eP5XW.jpg&quot; alt=&quot;roughness 1.0&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furnace test of rough dielectric (IoR 1.51) BSDF using the Smith model and GGX microfacet distribution for roughness parameters from 0.2 to 1.0:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EZWNf.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EZWNf.jpg&quot; alt=&quot;roughness 0.2&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wtcLq.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wtcLq.jpg&quot; alt=&quot;roughness 0.4&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YisLW.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YisLW.jpg&quot; alt=&quot;roughness 0.6&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SdaAG.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SdaAG.jpg&quot; alt=&quot;roughness 0.8&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5PdTb.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5PdTb.jpg&quot; alt=&quot;roughness 1.0&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Eric Heitz et al. have just recently proposed a &lt;a href=&quot;https://eheitzresearch.wordpress.com/240-2/&quot; rel=&quot;noreferrer&quot;&gt;multiple-scattering model&lt;/a&gt; which solves the darkening problem by solving the light interaction completely, but there are performance issues due to stochastic nature of its evaluation routine as metioned by Heitz himself in the &lt;a href=&quot;http://www.luxrender.net/forum/viewtopic.php?f=36&amp;amp;t=12534#p118797&quot; rel=&quot;noreferrer&quot;&gt;LuxRender forum&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a known compensation method for recovering the lost energy of single-scattering models? Not necessarily physically correct, but at least not breaking physical plausibility (Helmholtz reciprocity and energy conservation) too much and, ideally, without the necessity of hand tuning parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the &lt;a href=&quot;http://blog.selfshadow.com/publications/s2012-shading-course/burley/s2012_pbs_disney_brdf_notes_v3.pdf&quot; rel=&quot;noreferrer&quot;&gt;Disney BSDF&lt;/a&gt;, there is a parametrized component called “sheen” (basically a Fresnel-based glossy lobe) which can be used for compensation of darkening at edges, but as they mention in their &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf&quot; rel=&quot;noreferrer&quot;&gt;Siggraph 2015 course&lt;/a&gt; it is very ad hoc method: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;“...this is very approximate, and doesn't work as well for other&#xA;  roughness values...”&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;http://www.luxrender.net/forum/viewtopic.php?f=36&amp;amp;t=12534#p118797&quot; rel=&quot;noreferrer&quot;&gt;aforementioned comment&lt;/a&gt; from Eric Heitz in the LuxRender forum also suggests using some compensation hack, but, unfortunately, doesn't go into any details:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;To my knowledge, you can use some simpler hacks to improve energy conservation in the single scattering models (like tweaking albedo). However, if you do that, you cannot get a perfectly energy conserving material (for instance perfect white rough glass) without breaking the reciprocity of the BSDF.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2017-11-25T21:15:30.373" LastActivityDate="2017-11-25T21:15:30.373" Title="Compensation for energy loss in single-scattering microfacet BSDF models" Tags="&lt;rendering&gt;&lt;brdf&gt;&lt;physically-based&gt;&lt;microfacet&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2111" PostTypeId="2" ParentId="2083" CreationDate="2016-02-28T21:56:21.483" Score="1" Body="&lt;p&gt;Someone points me that &lt;em&gt;&lt;a href=&quot;http://white.stanford.edu/~brian/papers/pdc/ColorBalanceSPIE03.pdf&quot; rel=&quot;nofollow&quot;&gt;this article&lt;/a&gt;  describes the spectral response of the camera the MERL paper used, and even provides colour transform matrices at the end. Unfortunately, using those transforms result in even worse results than assuming sRGB primaries.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-02-28T21:56:21.483" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2112" PostTypeId="2" ParentId="2110" CreationDate="2016-02-28T22:16:11.020" Score="8" Body="&lt;p&gt;To my knowledge, there is no easy and analytic way of recovering the energy lost in single-scattering models. The previous techniques precompute the energy loss and reinject it in the BRDF as a diffuse-like component:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://sirkan.iit.bme.hu/~szirmay/scook.pdf&quot;&gt;http://sirkan.iit.bme.hu/~szirmay/scook.pdf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.cs.cornell.edu/projects/layered-sg14/layered.pdf&quot;&gt;http://www.cs.cornell.edu/projects/layered-sg14/layered.pdf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What they propose is energy conservative and reciprocal, and it is probably the simplest way of fixing the visual darkening due to the energy loss. The main drawback is that since the energy loss does not have an analytic expression, it has to be precomputed and stored in a look-up table. &lt;/p&gt;&#xA;" OwnerUserId="2769" LastActivityDate="2016-02-28T22:16:11.020" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2115" PostTypeId="1" CreationDate="2016-02-29T16:13:22.317" Score="7" ViewCount="814" Body="&lt;p&gt;So I was tasked to create a model of the Cornell Box. I've managed to do everything up until casting shadows, in which case some shadows are cast when there should not be any. Here are pictures of what it looks like now and a larger picture of what it should look like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dSgxY.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dSgxY.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've found that for some reason, the box walls are also casting shadows. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A quick run-down of how it works: we have a pinhole camera which casts rays out and finds the nearest collision point, which is everything you're seeing. It saves these points as well as the distance from some start pt (camera in this case) to the collision point in a pre-defined data structure called an Intersection. It then uses this data to calculate the distance away from the light to create the intensities in lighting. The same method that is used to find the nearest collision point is used to find the nearest object for shadows as well using the original collision point as the start and the light source as the direction of the ray vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've narrowed down the problem to raytracing; when checking to see if there are any objects to cast shadows from from say the upper-right region of the back gray wall, the cyan ceiling is picked up at a point from the same side of the light. E.g. say the light source is in the middle and the original point is on our right side of the light. The method somehow picks up a point that is on the same side of the light when the vector should be going straight through the light source and end somewhere on our left side.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my source code for the functions in question:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool ClosestIntersection( vec3 start, vec3 dir, const vector&amp;lt;Triangle&amp;gt;&amp;amp; triangles, Intersection&amp;amp; it ) {&#xA;&#xA;    vec3 least;&#xA;    vec3 e1, e2, b, v0;&#xA;    mat3 A;&#xA;&#xA;    least[0] = m;&#xA;&#xA;    int index = triangles.size()-1;&#xA;&#xA;    for(int i = 0; i &amp;lt; int(triangles.size()); i++) {&#xA;&#xA;        v0 = triangles[i].v0;&#xA;        e1 = triangles[i].v1 - v0;&#xA;        e2 = triangles[i].v2 - v0;&#xA;        b = start - v0;&#xA;&#xA;        A = mat3( -dir, e1, e2);&#xA;&#xA;        if(!getInverse(A,b)) {continue;}&#xA;&#xA;        vec3 x = A * b;&#xA;&#xA;        if(x[0] &amp;lt;= least[0] &amp;amp;&amp;amp; x[1] + x[2] &amp;lt;= 1.f &amp;amp;&amp;amp; x[1] &amp;gt;= 0.f &amp;amp;&amp;amp; x[2] &amp;gt;= 0.f &amp;amp;&amp;amp; x[0] &amp;gt;= 0.00001f) {&#xA;            least = x;&#xA;            index = i;&#xA;        }&#xA;    }&#xA;&#xA;    if (least[0] == m) {&#xA;        return false;&#xA;    }&#xA;    else {&#xA;        it.position = least[0] * dir + start;&#xA;        const vec3 t = it.position-start;&#xA;        it.distance = sqrt(t[0]*t[0] + t[1]*t[1] + t[2]*t[2]);&#xA;        it.triangleIndex = index;&#xA;        return true;&#xA;    }&#xA;}&#xA;&#xA;vec3 DirectLight( const Intersection&amp;amp; i ){&#xA;    const Triangle T = triangles[i.triangleIndex];&#xA;    const vec3 r = lightPos - i.position;&#xA;    const float dist = sqrt(r[0]*r[0] + r[1]*r[1] + r[2]*r[2]);&#xA;&#xA;    Intersection t;&#xA;    t.distance = dist;&#xA;    t.position = i.position;&#xA;    t.triangleIndex = i.triangleIndex; &#xA;&#xA;    //ClosestIntersection( i.position, lightPos, triangles, t);&#xA;&#xA;    /*&#xA;    if(!ClosestIntersection( lightPos, i.position, triangles, t)) {return vec3(1,0,0);}&#xA;    else { return vec3(0,0,0); } */&#xA;&#xA;    if(ClosestIntersection( i.position, lightPos, triangles, t) &amp;amp;&amp;amp; (dist-t.distance &amp;gt; 1.f)) {&#xA;&#xA;        return vec3(0,0,0);&#xA;    } else {&#xA;        const vec3 B = 14.f * T.color * (float(max(dot(r,T.normal),float(0)) / float(4*3.14 * dist* dist)));&#xA;&#xA;        return B; &#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have spent over twelve hours trying to find this problem. Even my lecturer can't figure out the problem. Any help would be much appreciated!&lt;/p&gt;&#xA;" OwnerUserId="2771" LastActivityDate="2016-03-01T15:43:38.867" Title="Raytracing Problem - Casting Shadows" Tags="&lt;raytracing&gt;&lt;shadow&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2117" PostTypeId="1" AcceptedAnswerId="2118" CreationDate="2016-02-29T19:19:41.820" Score="9" ViewCount="342" Body="&lt;p&gt;I've been stuck on how to approach this for a while, so any suggestions would be gratefully appreciated!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to map a texture in the form of a lower right euclidean triangle to a hyperbolic triangle on the Poincare Disk.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the texture (the top left triangle of the texture is transparent and unused). You might recognise this as part of Escher's Circle Limit I&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry, see the comment as I am not allowed to post more than two links it seems! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is what my polygon looks like (it's centred at the origin, which means that two edges are straight lines, however in general all three edges will be circular arcs):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1QB1E.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1QB1E.png&quot; alt=&quot;Wireframe Polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The centre of the polygon is the incentre of the euclidean triangle formed by its vertices and I'm UV mapping the texture using it's incentre, dividing it into the same number of faces as the polygon has and mapping each face onto the corresponding polygon face. However the the result looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3Jw9I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3Jw9I.png&quot; alt=&quot;Textured Polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anybody thinks this is solvable using UV mapping I'd be happy to provide some example code, however I'm beginning to think this might not be possible and I'll have to write my own mapping functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SOLVED with some refinement of @Nathan's answer below since the lines AB, AC, BC may actually be arcs not lines. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Method: pick the longest side, say BC, then subdivide this into an even number of parts. Subdivide the other two side into the same number of parts. Then the lines connecting these (DE in the answer below) must actually also be arcs, not straight lines. Subdivide these new arcs as required, add the new triangles as faces then UV map the lower right triangle of the texture to these new faces. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simple? Not at all. But it worked. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/90UQF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/90UQF.jpg&quot; alt=&quot;Fish 1&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/bJ08M.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bJ08M.jpg&quot; alt=&quot;Fish 2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2775" LastEditorUserId="2775" LastEditDate="2016-03-04T17:15:19.837" LastActivityDate="2016-03-04T17:15:19.837" Title="Map a texture onto a hyperbolic triangle" Tags="&lt;texture&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2118" PostTypeId="2" ParentId="2117" CreationDate="2016-02-29T20:21:54.260" Score="8" Body="&lt;p&gt;My guess is that to get the texture to look right, you'll have to subdivide the interior of the triangle as well, and approximate the non-linear UV mapping within it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, it looks like you're subdividing around the edges of the triangle, and forming a fan of smaller triangles between the edge and the incenter. This would be fine if you were just rendering the triangle in a solid color. But when applying a texture, you're getting discontinuities at the boundaries of those subdivisions, because the texture is just stretched linearly across each subdivided triangle and not correctly approximating the hyperbolic mapping along the radial direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll need to subdivide along both axes, something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/jhKX2.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and position all the vertices appropriately in screen space and UV space to approximate the hyperbolic coordinates in the interior of the triangle. If you subdivide finely enough, this should produce the illusion of a continuously curving texture mapping.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-02-29T20:21:54.260" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2119" PostTypeId="2" ParentId="2102" CreationDate="2016-02-29T20:29:24.230" Score="8" Body="&lt;h1&gt;Quick answers to your individual questions&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;What do you do if your image is not the same size on each axis though?&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The paper uses square images with side lengths that are a power of 2. This is for ease of explanation, but is not necessary for the algorithm to work. See section 3.1:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Without loss of generality, we can assume n is a power of 2.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That is, this assumption is not required in order for the algorithm to work.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Is it possible to run JFA on each axis separately and still get decent results?&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Running on each axis separately is likely to give more incorrect pixel results, &lt;em&gt;and&lt;/em&gt; take longer to run in most cases. In extreme cases where one of the image side lengths is less than 8 (the number of jump directions), it may be faster as the algorithm treats those 8 directions sequentially, but for any wider image, separating the axes loses the advantage of treating them in parallel.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;In my situation ideally I'm looking to support both single point seeds, as well as arbitrary shaped seeds&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The paper mentions arbitrary shaped seeds in section 6 under the subheading &quot;Generalized Voronoi Diagram&quot;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;...our algorithms treat such generalized seeds as collections of point seeds and thus expect to inherit the good performance obtained for point seeds.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So provided it suits your purpose to model arbitrary shapes as collections of pixels, you don't need to make any adjustment to the algorithm. Simply feed in a texture that labels all pixels in an arbitrary shaped seed with the same seed number, but different locations.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Possibly even weighted seeds, where the distance to a seed is adjusted by a multiplier and/or an adder to give it more or less influence&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;For &quot;weighting on seeds such as multiplicative and additive&quot;, the paper only mentions the possibility in passing in section 8, as potential future work. However, this should be straightforward to implement provided your desired weighting can be included in the seed data that is passed from pixel to pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The current algorithm passes &lt;code&gt;&amp;lt;s, position(s)&amp;gt;&lt;/code&gt; to specify a seed and its position, and only one seed is stored per pixel at any one time. Extending this to store &lt;code&gt;&amp;lt;s, position(s), weight(s)&amp;gt;&lt;/code&gt; provides all the information required to weight the distance function and calculate whether the new seed being passed to a pixel is closer to it than the one it is currently storing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could even include two weights, one multiplicative and one additive, and just set the multiplicative one to 1 and the additive one to 0 when not required. Then your algorithm would include the possibility of being used for multiplicatively weighted seeds, additively weighted seeds, or even a combination of both at once or some of each. This would just need&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;&amp;lt;s, position(s), multiplicative(s), additive(s)&amp;gt;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and the current algorithm would be equivalent to this new algorithm using &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;&amp;lt;s, position(s), 1, 0&amp;gt;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;Detailed explanation of why&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;As in the paper, all uses of $\log()$ refer to the base 2 logarithm.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;The algorithm does not need to be adapted for different side lengths&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If the side lengths are not equal, and are not powers of 2, there is no need to adapt the algorithm. It already deals with pixels on the edge of the image for which some of the jump directions lead outside the image. Since the algorithm already omits the seed information for directions that lead outside the image, a width or height that is not a power of 2 will not be a problem. For an image of width W and height H, the maximum jump size required will be&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\large2^{\lceil\log(\max(W,H))\rceil-1}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the case of equal width and height N, this reduces to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\large2^{\lceil\log(N)\rceil-1}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of a side length N that is a power of 2, this reduces to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\large2^{\log(N)-1}=N/2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as used in the paper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In more intuitive terms, round the maximum side length up to the next power of 2, and then halve that to get the maximum jump size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is always enough to cover every pixel in the image from every other pixel in the image, as the offset to any pixel will be in the range 0 to N-1 if the longest side length is N. Combinations of the powers of 2 from 0 to N/2 will cover every integer up to N-1 if N is a power of 2, and if N is not a power of 2 the range covered can only be larger than required, due to taking the ceiling of the logarithm (rounding up to the next power of 2).&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Images with sides not a power of 2 will not be drastically less efficient&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The number of jumps depends on the longest side length, say L. If L is a power of 2 then the number of jumps is $\log(L)$. If L is not a power of 2 then the number of jumps is $\lceil\log(L)\rceil$. For a reasonably large image this will not be a large difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, a 1024 by 1024 image will require 10 jump iterations. A 512 by 512 image will require 9 jump iterations. Anything between the two sizes will also require 10 iterations. Even in the worst case of an image only just over a power of 2, like a 513 by 513 image, it will only require 1 additional iteration, which at this scale is approximately 11% more (10 instead of 9).&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Non-square images are less efficient per area&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Since the number of iterations required is determined by the longest side length, the time taken for a 1024 by 1024 image will be the same as for a 1024 by 16 image. A square image allows a larger area to be covered in the same number of iterations.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Separating axes is likely to reduce quality&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Section 5 of the paper describes possible errors. Every pixel is reachable by a path from every other pixel, but some paths do not bring the correct nearest seed, due to that seed not being the nearest to a previous pixel in the path. A pixel that does not allow a seed to propagate past it is said to have &quot;killed&quot; that seed. If the nearest seed to a pixel is killed on all paths to that pixel, then the pixel will record some other seed and there will be an incorrect colour in the final image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Only one path needs to exist that does not kill the seed in order for the final result to be correct. Incorrect colours only occur when &lt;em&gt;all&lt;/em&gt; paths from the correct seed to a given pixel are blocked.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If a path involves alternating horizontal and vertical jumps, separating axes will make this path impossible (all horizontal jumps will be taken before all vertical jumps, making alternating impossible). Diagonal jumps will not be possible at all. So any path that alternates or contains diagonal jumps will be excluded. Every pixel will still have a path to every other pixel, but since there are now fewer paths there is more chance of a given pixel being blocked from receiving the correct seed, so the final result will be more error prone.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Separating axes is likely to make the algorithm take longer&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The efficiency would probably be reduced by separating axes, as the flooding would no longer be done in parallel, but would instead be repeated for each axis. For 2D this would likely take approximately twice as long, and for 3D approximately 3 times as long.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This may be somewhat mitigated by the lack of diagonal jumps, but I would still expect an overall reduction in efficiency.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-02-29T22:40:15.907" LastActivityDate="2016-02-29T22:40:15.907" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2120" PostTypeId="2" ParentId="2115" CreationDate="2016-03-01T04:28:38.383" Score="3" Body="&lt;p&gt;are you sure you are not re-intersecting the same surface when checking for light occluder ? this is a classical precision issue. There are many way to tackle it:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;First, have a good conditioning of the intersection point, by reintersecting a second time: consider your first hit distance d as approximate, create the point E' = Eye + (d-eps)*ray, recompute the intersection from here. (variant: for the first intersection, just use the bounding box).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Second, for grazing angle, depending on your shape representation, storage and computation precision and scales, tessellation, you might have dangerous imprecision here too, and must still ensure you won't reintersect the same surface. If flat or convex or tesselated, you can tag it an non-intersectable for the shadow-ray test. &#xA;A simpler trick (more approximate) is to displace the start of the shadow ray by epsilon in the normal direction. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2016-03-01T05:24:10.303" LastActivityDate="2016-03-01T05:24:10.303" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2122" PostTypeId="1" CreationDate="2016-03-01T09:25:42.057" Score="17" ViewCount="12671" Body="&lt;p&gt;I am quite confused over how GLM library is behaving or I am using it improperly.  &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec2 testVec(6,-4);&#xA;&#xA;float len = testVec.length();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I get the value &lt;code&gt;2&lt;/code&gt; with the above code snippet. I believe I am trying to get the length of the vector defined by &lt;code&gt;testVec&lt;/code&gt;. You know very well that it is not the correct length of the vector. What am I missing here?&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="16" LastEditDate="2016-03-01T09:49:42.487" LastActivityDate="2016-03-01T12:20:14.087" Title="Get vector length with GLM" Tags="&lt;c++&gt;&lt;vectors&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2123" PostTypeId="2" ParentId="2122" CreationDate="2016-03-01T09:47:35.483" Score="20" Body="&lt;p&gt;Sorry folks for posting such a trivial issue! The issue is solved. I was using the wrong function. Here goes the correct one:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec2 testVec(6,-4);&#xA;float len  = glm::length(testVec);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The member function of the same name returns the number of components instead (i.e. &lt;code&gt;vec2::length&lt;/code&gt; will always yield &lt;code&gt;2&lt;/code&gt;, &lt;code&gt;vec3::length&lt;/code&gt; will always yield &lt;code&gt;3&lt;/code&gt;, etc.).&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="16" LastEditDate="2016-03-01T12:20:14.087" LastActivityDate="2016-03-01T12:20:14.087" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2125" PostTypeId="2" ParentId="2115" CreationDate="2016-03-01T15:43:38.867" Score="1" Body="&lt;p&gt;There is a trick that many in fact let you sidestep the issue altogether*. The scene and the set of things to be raytraced does not have to be the same. Most ray tracers allow for objects to not participate in shadow casting, reflections, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case you could just take the outside walls of from shadow casting and therefore they would not self shadow allowing you to put lights outside the box with no problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway you could add a slight bias to the sampling and consider the objects slightly further than your calculation result gives, for shadow casting this avoids all kinds of problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* Yes you have a problem you should fix that. But sometimes quick and done is all thats needed&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-03-01T15:43:38.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2126" PostTypeId="1" AcceptedAnswerId="2127" CreationDate="2016-03-02T09:34:14.927" Score="4" ViewCount="311" Body="&lt;p&gt;I am trying to implement svg rendering by opengl using meshes. &#xA;In paths with opacity less than 1, the color of overlapping strokes add up. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rarVy.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rarVy.png&quot; alt=&quot;![enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it should be like this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/M9PbX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M9PbX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the opengl calls are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    glDepthMask(false);&#xA;    glEnable(GL20.GL_BLEND);&#xA;    glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);&#xA;    ....&#xA;    glDrawArrays(....);&#xA;    ....&#xA;    glDepthMask(true);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;is there any opengl calls, shader or other method to have same transparent value around the whole stroke without modifying the geometry of the shape?&lt;/p&gt;&#xA;" OwnerUserId="2784" LastActivityDate="2016-03-02T09:51:44.850" Title="SVG opengl implementation - strokes overlap on transparency" Tags="&lt;opengl&gt;&lt;image-processing&gt;&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2127" PostTypeId="2" ParentId="2126" CreationDate="2016-03-02T09:51:44.850" Score="3" Body="&lt;p&gt;You can use the depth buffer to ensure that the second time you get on a point the pixels aren't written. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You start with the maximum depth value and each new path (that you want to add to the existing drawn image) you decrement the depth.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-03-02T09:51:44.850" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2128" PostTypeId="1" CreationDate="2016-03-02T11:03:45.360" Score="2" ViewCount="70" Body="&lt;p&gt;I have a line segment defined by two coordinate values and I need to check if the line segment is parallel to the x-axis or y-axis. I believe that it is not that difficult to find. When it comes to test for parallelism against x-axis, we just need to check if the both the end points of the line segments has the equivalent y-value, whereas parallelism test against y-axis can be found if both the coordinate point ends have the same x-value. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any other better way do it is most welcome.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-03-03T11:41:25.397" Title="vertical or horizontal line test" Tags="&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2130" PostTypeId="1" AcceptedAnswerId="2132" CreationDate="2016-03-02T15:28:59.727" Score="21" ViewCount="3164" Body="&lt;p&gt;In ray tracing / path tracing, one of the simplest way to anti-alias the image is to supersample the pixel values and average the results. IE. instead of shooting every sample through the center of the pixel, you offset the samples by some amount.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In searching around the internet, I've found two somewhat different methods to do this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Generate samples however you want and weigh the result with a filter&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;One example is &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/master/src/core/film.h#L114&quot; rel=&quot;noreferrer&quot;&gt;PBRT&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Generate the samples with a distribution equal to the shape of a filter&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Two examples are &lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot; rel=&quot;noreferrer&quot;&gt;smallpt&lt;/a&gt; and &lt;a href=&quot;https://computergraphics.stackexchange.com/users/79/benedikt-bitterli&quot;&gt;Benedikt Bitterli&lt;/a&gt;'s &lt;a href=&quot;https://github.com/tunabrain/tungsten/blob/master/src/core/cameras/ReconstructionFilter.hpp&quot; rel=&quot;noreferrer&quot;&gt;Tungsten Renderer&lt;/a&gt; &lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Generate and Weigh&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic process is:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create samples however you want (randomly, stratified, low-discrepancy sequences, etc.) &lt;/li&gt;&#xA;&lt;li&gt;Offset the camera ray using two samples (x and y)&lt;/li&gt;&#xA;&lt;li&gt;Render the scene with the ray&lt;/li&gt;&#xA;&lt;li&gt;Calculate a weight using a filter function and the distance of the sample in reference to the pixel center. For example, Box Filter, Tent Filter, Gaussian Filter, etc.)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/gz7Bg.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gz7Bg.png&quot; alt=&quot;Filter Shapes&quot;&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Apply the weight to the color from the render&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Generate in the shape of a filter&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic premise is to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Inverse_transform_sampling&quot; rel=&quot;noreferrer&quot;&gt;Inverse Transform Sampling&lt;/a&gt; to create samples that are distributed according to the shape of a filter. For example a histogram of a samples distributed in the shape of a Gaussian would be:&lt;br/&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7pGFS.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7pGFS.png&quot; alt=&quot;Gaussian Histogram&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can either be done exactly, or by binning the function into a discrete pdf/cdf. &lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot; rel=&quot;noreferrer&quot;&gt;smallpt&lt;/a&gt; uses the exact inverse cdf of a tent filter. Examples of binning method can be found &lt;a href=&quot;https://gist.github.com/RichieSams/ce2ca2a201227c1de543&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Questions&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the pros and cons of each method? And why would you use one over the other? I can think of a few things:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generate and Weigh seems to be the most robust, allowing any combination of any sampling method with any filter. However, it requires you to track the weights in the ImageBuffer and then do a final resolve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generate in the Shape of a Filter can only support positive filter shapes (ie. no Mitchell, Catmull Rom, or Lanczos), since you can not have a negative pdf. But, as mentioned above, it's easier to implement, since you don't need to track any weights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though, in the end, I guess you can think of method 2 as a simplification of method 1, since it's essentially using an implicit Box Filter weight.&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-09-14T19:37:35.923" Title="Anti-aliasing / Filtering in Ray Tracing" Tags="&lt;raytracing&gt;&lt;antialiasing&gt;&lt;pathtracing&gt;&lt;filtering&gt;&lt;supersampling&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="2131" PostTypeId="1" CreationDate="2016-03-02T22:58:02.173" Score="8" ViewCount="174" Body="&lt;p&gt;I am trying to implement a 2D version of Foster and Fedkiw's paper, &quot;Practical Animation of Liquids&quot; here: &lt;a href=&quot;http://physbam.stanford.edu/~fedkiw/papers/stanford2001-02.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://physbam.stanford.edu/~fedkiw/papers/stanford2001-02.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mostly everything works, except for section 8: &quot;Conservation of Mass.&quot; There, we set up a matrix of equations to compute the pressures needed to make the liquid divergent free. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe my code matches the paper, however I am getting an unsolvable matrix during the conservation of mass step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are my steps for generating the matrix A:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Set the diagonal entries $A_{i,i}$ to the negative of number of adjacent liquid cells to cell i.&lt;/li&gt;&#xA;&lt;li&gt;Set the entries $A_{i,j}$ and $A_{j,i}$ to 1 if both cells i and j have liquid.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Note that, in my implementation, cell $i$,$j$ in the liquid grid corresponds to row $i + $gridWidth$ * j$ in the matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper mentions, &quot;Static object and empty cells don’t disrupt this&#xA;structure. In that case pressure and velocity terms can disappear&#xA;from both sides&quot;, so I delete the columns and rows for cells that have no liquid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is: Why is my matrix singular? Am I missing some kind of boundary condition in some other place in the paper? Is it the fact that my implementation is 2D?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example matrix from my implementation for a 2x2 grid where the cell at 0,0 has no liquid:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;-1   0   1&#xA;&#xA; 0  -1   1&#xA;&#xA; 1   1  -2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My research has led me to believe that I'm not properly handling the boundary conditions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all, at this point I can say that my matrix represents the discrete pressure Poisson equation. It is the discrete analog of applying the Laplacian operator coupling local pressure changes to cell divergence.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I can understand, since we're dealing with pressure differences, boundary conditions are needed to &quot;anchor&quot; the pressures to an absolute reference value. Otherwise there may be an infinite number of solutions to the set of equations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In &lt;a href=&quot;http://www.math.toronto.edu/mpugh/Teaching/Mat1062/notes2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;these notes&lt;/a&gt;, 3 different ways are given to apply boundary conditions, to the best of my understanding:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Dirichlet - specifies absolute values at the boundaries.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Neummann - specifies the derivative at the boundaries.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Robin - specifies some kind of linear combination of the absolute value and the derivative at the boundaries.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Foster and Fedki's paper does not mention any of these, but I believe that they enforce Dirichlet boundary conditions, notable because of this statement at the end of 7.1.2, &quot;The pressure in a surface cell is set to atmospheric pressure.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read the notes I linked a few times and still don't quite understand the math going on. How exactly do we enforce these boundary conditions? Looking at other implementations, there seems to be some kind of notion of a &quot;Ghost&quot; cells that lie at the boundary. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here I've linked to a few sources that may be helpful to others reading this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.math.toronto.edu/mpugh/Teaching/Mat1062/notes2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Notes on boundary conditions for Poisson Matrices&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://scicomp.stackexchange.com/questions/5355/writing-the-poisson-equation-finite-difference-matrix-with-neumann-boundary-cond&quot;&gt;Computational Science StackExchange post on Neumann boundary conditions&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://scicomp.stackexchange.com/questions/19485/2d-poisson-solver-for-taylor-green-vortex-problem&quot;&gt;Computational Science StackExchange post on Poisson Solver&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://physbam.stanford.edu/~mlentine/project.html#water&quot; rel=&quot;nofollow noreferrer&quot;&gt;Water Physbam Implementation&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here is the code I use to generate the matrix. Note that, instead of explicitly deleting columns and rows, I generate and use a map from liquid cell indices to the final matrix columns/rows.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; cells.length; i++) {&#xA;  for (int j = 0; j &amp;lt; cells[i].length; j++) {&#xA;    FluidGridCell cell = cells[i][j];&#xA;&#xA;    if (!cell.hasLiquid)&#xA;      continue;&#xA;&#xA;    // get indices for the grid and matrix&#xA;    int gridIndex = i + cells.length * j;&#xA;    int matrixIndex = gridIndexToMatrixIndex.get((Integer)gridIndex);&#xA;&#xA;    // count the number of adjacent liquid cells&#xA;    int adjacentLiquidCellCount = 0;&#xA;    if (i != 0) {&#xA;      if (cells[i-1][j].hasLiquid)&#xA;        adjacentLiquidCellCount++;&#xA;    }&#xA;    if (i != cells.length-1) {&#xA;      if (cells[i+1][j].hasLiquid)&#xA;        adjacentLiquidCellCount++;&#xA;    }&#xA;    if (j != 0) {&#xA;      if (cells[i][j-1].hasLiquid)&#xA;      adjacentLiquidCellCount++;&#xA;    }&#xA;    if (j != cells[0].length-1) {&#xA;      if (cells[i][j+1].hasLiquid)&#xA;        adjacentLiquidCellCount++;&#xA;    }&#xA;&#xA;    // the diagonal entries are the negative count of liquid cells&#xA;    liquidMatrix.setEntry(matrixIndex, // column&#xA;                          matrixIndex, // row&#xA;                          -adjacentLiquidCellCount); // value&#xA;&#xA;    // set off-diagonal values of the pressure matrix&#xA;    if (cell.hasLiquid) {&#xA;      if (i != 0) {&#xA;        if (cells[i-1][j].hasLiquid) {&#xA;          int adjacentGridIndex = (i-1) + j * cells.length;&#xA;          int adjacentMatrixIndex = gridIndexToMatrixIndex.get((Integer)adjacentGridIndex);&#xA;          liquidMatrix.setEntry(matrixIndex, // column&#xA;                                adjacentMatrixIndex, // row&#xA;                                1.0); // value&#xA;          liquidMatrix.setEntry(adjacentMatrixIndex, // column&#xA;                                matrixIndex, // row&#xA;                                1.0); // value&#xA;        }&#xA;      }&#xA;      if (i != cells.length-1) {&#xA;        if (cells[i+1][j].hasLiquid) {&#xA;          int adjacentGridIndex = (i+1) + j * cells.length;&#xA;          int adjacentMatrixIndex = gridIndexToMatrixIndex.get((Integer)adjacentGridIndex);&#xA;          liquidMatrix.setEntry(matrixIndex, // column&#xA;                                adjacentMatrixIndex, // row&#xA;                                1.0); // value&#xA;          liquidMatrix.setEntry(adjacentMatrixIndex, // column&#xA;                                matrixIndex, // row&#xA;                                1.0); // value&#xA;        }&#xA;      }&#xA;      if (j != 0) {&#xA;        if (cells[i][j-1].hasLiquid) {&#xA;          int adjacentGridIndex = i + (j-1) * cells.length;&#xA;          int adjacentMatrixIndex = gridIndexToMatrixIndex.get((Integer)adjacentGridIndex);&#xA;          liquidMatrix.setEntry(matrixIndex, // column&#xA;                                adjacentMatrixIndex, // row&#xA;                                1.0); // value&#xA;          liquidMatrix.setEntry(adjacentMatrixIndex, // column&#xA;                                matrixIndex, // row&#xA;                                1.0); // value&#xA;        }&#xA;      }&#xA;      if (j != cells[0].length-1) {&#xA;        if (cells[i][j+1].hasLiquid) {&#xA;          int adjacentGridIndex = i + (j+1) * cells.length;&#xA;          int adjacentMatrixIndex = gridIndexToMatrixIndex.get((Integer)adjacentGridIndex);&#xA;          liquidMatrix.setEntry(matrixIndex, // column&#xA;                                adjacentMatrixIndex, // row&#xA;                                1.0); // value&#xA;          liquidMatrix.setEntry(adjacentMatrixIndex, // column&#xA;                                matrixIndex, // row&#xA;                                1.0); // value&#xA;        }&#xA;      }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2786" LastEditorUserId="-1" LastEditDate="2017-04-13T12:53:56.223" LastActivityDate="2019-02-21T03:08:51.373" Title="Conserving Mass in Liquid Simulation" Tags="&lt;simulation&gt;&lt;fluid-sim&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2132" PostTypeId="2" ParentId="2130" CreationDate="2016-03-03T04:59:18.810" Score="10" Body="&lt;p&gt;There is a great paper from 2006 on this topic, &lt;a href=&quot;http://lgdv.cs.fau.de/publications/publication/Pub.2006.tech.IMMD.IMMD9.filter/&quot;&gt;Filter Importance Sampling&lt;/a&gt;. They propose your method 2, study the properties, and come out generally in favor of it. They claim that this method gives smoother rendering results because it weights all samples that contribute to a pixel equally, thereby reducing variance in the final pixel values. This makes some sense, as it's a general maxim in Monte Carlo rendering that importance-sampling will give lower variance than weighted samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Method 2 also has the advantage of being slightly easier to parallelize because each pixel's computations are independent of all other pixels, while in method 1, sample results are shared across neighboring pixels (and therefore have to be synchronized/communicated somehow when pixels are parallelized across multiple processors). For the same reason, it's easier to do adaptive sampling (more samples in high-variance areas of the image) with method 2 than method 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the paper, they also experimented with a Mitchell filter, sampling from abs() of the filter and then weighting each sample with either +1 or &amp;minus;1, like @trichoplax suggested. But this ended up actually increasing the variance and being worse than method 1, so they conclude that method 2 is only usable for positive filters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, the results from this paper may not be universally applicable, and it may be somewhat scene-dependent which sampling method is better. I wrote &lt;a href=&quot;http://www.reedbeta.com/blog/2014/11/15/antialiasing-to-splat-or-not/&quot;&gt;a blog post investigating this question&lt;/a&gt; independently in 2014, using a synthetic &quot;image function&quot; rather than full rendering, and found method 1 to give more visually pleasing results due to smoothing high-contrast edges more nicely. Benedikt Bitterli also commented on that post reporting a similar issue with his renderer (excess high-frequency noise around light sources when using method 2). Beyond that, I found the main difference between the methods was the frequency of the resulting noise: method 2 gives higher-frequency, &quot;pixel-sized&quot; noise, while method 1 gives noise &quot;grains&quot; that are 2-3 pixels across, but the amplitude of noise was similar for both, so which kind of noise looks less bad is probably a matter of personal preference.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-03T04:59:18.810" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2133" PostTypeId="1" AcceptedAnswerId="2142" CreationDate="2016-03-03T09:54:09.387" Score="8" ViewCount="372" Body="&lt;p&gt;I'm aware that most modern GPUs, although designed for floating point, are more or less equivalent in integer performance these days, with a few caveats like the lack of a fused multiply add. I'm not sure how this applies to shift operations though. I'm doing Marching Cubes on GPU, initially writing out a 32-bit packed position for each surface cube then unpacking these in a later pass to the actual vertices in that cube, like this : &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ivec3 unpackedPos = ivec3( packedPos &amp;gt;&amp;gt; 20 &amp;amp; 0x3FF,&#xA;                         packedPos &amp;gt;&amp;gt; 10 &amp;amp; 0x3FF,&#xA;                         packedPos &amp;amp; 0x3FF);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It just occurred to me to wonder if shader units have barrel shifters in them these days? Am I doing 2 shifts here or 30?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT&gt;&gt;&#xA;I'm an idiot... Thanks for the answers guys, useful to know, but I've been going about this all wrong. I should just be using the RGB10_A2UI texture format then packing/ unpacking with a single image load/store instruction instead of messing around with bitshifts myself. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;RE_EDIT&gt;&gt; Or not... This method apparently works on red boxes but not on green ones, so it's back to bit-shifts.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="1937" LastEditDate="2016-03-11T15:10:33.287" LastActivityDate="2016-03-11T15:10:33.287" Title="Do modern GPUs contain barrel shifters?" Tags="&lt;gpu&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2134" PostTypeId="1" CreationDate="2016-03-03T11:11:21.640" Score="2" ViewCount="511" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/I60wq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/I60wq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use template matching to detect a specific pattern in image.The shift determined is very shaky. Currently I apply it to R,G,B channel separately and average the result to obtain float values.Please, suggest how to obtain subpixel accuracy. I was planning to resize the image and then return the data in original scale, please suggest any other better method &lt;/p&gt;&#xA;" OwnerUserId="2788" LastActivityDate="2016-03-03T11:11:21.640" Title="Template matching subpixel accuracy" Tags="&lt;algorithm&gt;&lt;image-processing&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2135" PostTypeId="1" CreationDate="2016-03-03T11:18:33.500" Score="1" ViewCount="200" Body="&lt;p&gt;I want to visualize a scene with simple shapes (e.g. boxes, pyramides, etc.) and I am looking for a tool or framework in C/C++ to do this. Focus of the application is to parameterize the relative coordinates (position+rotation) of the scene objects. Also defined camera view support would be much welcomed. What I actually would want is the VRML World Editor from Simulink. However I need something thats free for company in-house use. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anybody give suggest me something suitable? &lt;/p&gt;&#xA;" OwnerUserId="2789" LastActivityDate="2016-03-05T17:52:07.293" Title="Free 3D Scene Simulation Framework" Tags="&lt;3d&gt;&lt;c++&gt;&lt;virtual-reality&gt;&lt;scene-description&gt;" AnswerCount="0" CommentCount="5" ClosedDate="2016-03-12T11:39:19.993" ContentLicense="CC BY-SA 3.0" />
  <row Id="2136" PostTypeId="2" ParentId="2128" CreationDate="2016-03-03T11:41:25.397" Score="4" Body="&lt;p&gt;It is not generally useful to try to optimise small parts of a program before you have profiled the program to see where the most benefit can be gained by optimisation. Make sure everything is correct and working first, and then profile to decide where to optimise (if optimisation turns out to be necessary).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematically, your approach is already correct for all lines. It will correctly identify all lines parallel to either axis, and it will not incorrectly identify any lines that are not parallel to an axis. However, for use in a practical setting, it's worth asking yourself about near-parallel cases and any odd exceptions. Consider all this before even thinking about optimisation, otherwise you may have to repeat all the optimisation later if something you have to change for correctness breaks your initial optimisation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One case to consider is when both the coordinates are identical. That is, the end points have the same x coordinate &lt;em&gt;and&lt;/em&gt; the same y coordinate. This is a  degenerate case that doesn't define a line (it could have any direction). Check your implementation with this case and make sure it gives the output that you want it to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on your purpose, you may want to detect only exactly parallel lines, or you may want to detect lines that are sufficiently near to parallel. In some cases lines near to parallel may satisfy your purpose, and in other cases it may be essential to accept lines near to parallel, if for example there is the possibility of small inaccuracies in the coordinates.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-03-03T11:41:25.397" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2137" PostTypeId="1" CreationDate="2016-03-03T11:43:44.337" Score="4" ViewCount="110" Body="&lt;p&gt;I'm wondering what is the best way to achieve an effect like here: &lt;a href=&quot;https://matterport.com/try/&quot; rel=&quot;noreferrer&quot;&gt;https://matterport.com/try/&lt;/a&gt; when the camera is traveling between points in space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apart from simple color crossfade there seems to be some sort of perspective reprojection giving the illusion of movement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea how to do this? All data I have is environment cube maps with color + linear depth at each pixel (so I can reconstruct view space position).&lt;/p&gt;&#xA;" OwnerUserId="304" LastActivityDate="2016-03-03T18:41:14.743" Title="Seamlessly transitioning between nearby environment maps" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2138" PostTypeId="2" ParentId="2137" CreationDate="2016-03-03T18:41:14.743" Score="3" Body="&lt;p&gt;It looks to me like they have a coarse polygon model of the room, and texture the model by projecting the cubemaps onto it. The model seems to include the rough shapes of the walls and furniture, but not fine details such as table legs, door handles or items on shelves. When the camera moves, the geometry gives you more-or-less-correct parallax, and the crossfade between cubemaps updates the textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also see the model clearly when the walkthrough first loads. Note that the camera starts outside of the house, letting you see the whole thing (much as you'd see a game level if you noclip the camera outside it), then it moves the camera into the living room. You can also get back to this view by selecting &quot;Dollhouse&quot; in their toolbar.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Their model may have been constructed by an artist, but in your case if you have depth information in the cubemaps, it's probably possible to programmatically extract some geometry from them and stitch the cubemaps together to form a coherent model. I don't know much about that subject, though.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-03T18:41:14.743" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2139" PostTypeId="1" AcceptedAnswerId="2143" CreationDate="2016-03-04T08:49:24.877" Score="7" ViewCount="559" Body="&lt;p&gt;I'm using an affine transformation matrix to transform 2D coordinates from screen (magnitude 10e3) to small parts of fractal sets (magnitude as little as 10e-15).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also need to map the other way round, so I simply invert the matrix. It works when the magnitudes are not too far apart, but it fails when the determinant gets too close to zero to be represented with standard double numbers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The matrices I use are of the form:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;a c e&#xA;b d f&#xA;0 0 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the inversion algorithm I have is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var dt = a * d - b * c;&#xA;return new Matrix(d/dt, -b/dt, -c/dt, a/dt, (c * f - d * e) / dt, -(a * f - b * e) / dt);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there an alternate way of inverting the matrix? I'm not very good at mathematics, so I would need a simple solution, and one I could find the code, or an algorithm, for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example of such a matrix:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 3.26091378894248e-9   -1.882689453850103e-9   -0.7172216437740687&#xA;-1.882689453814925e-9  -3.2609137888815494e-9  -0.23371832131832268&#xA; 0                      0                       1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2792" LastEditorUserId="231" LastEditDate="2016-03-05T08:29:31.863" LastActivityDate="2016-03-05T08:29:31.863" Title="How to invert an affine matrix with small values?" Tags="&lt;transformations&gt;&lt;mathematics&gt;&lt;2d&gt;&lt;affine-transformations&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2140" PostTypeId="1" CreationDate="2016-03-04T11:53:48.777" Score="3" ViewCount="152" Body="&lt;p&gt;I believe that the issue may already have been discussed here. I want to find if two line segments does intersect and if they do then find and store and intesection points. Now it is already confirmed that one of the line segments will always be parallel to x-axis or y-axis. &#xA;So in that case how should we reformulate the basic algorithm that checks the line segments intersection?&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="16" LastEditDate="2016-03-04T12:39:24.380" LastActivityDate="2016-03-04T21:23:22.713" Title="intersection between line segments - narrowed precondition" Tags="&lt;geometry&gt;&lt;mathematics&gt;&lt;vectors&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2141" PostTypeId="2" ParentId="2140" CreationDate="2016-03-04T16:28:17.557" Score="1" Body="&lt;p&gt;The arbitrary line can be expressed as &lt;code&gt;y = a*x+b&lt;/code&gt; (assuming it's not parallel to the y axis). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the other line is parallel to the y axis then you can simply fill in the x coordinate of any point on the line into the formula of the first line. Then you can check whether they intersect by ensuring the result lies between the endpoints of the second line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the second line parallel to the x axis you just flip the x and y coordinates.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-03-04T16:28:17.557" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2142" PostTypeId="2" ParentId="2133" CreationDate="2016-03-04T20:43:42.453" Score="6" Body="&lt;p&gt;Yes ( with 50% of the FMA 32b throughput on nVIDIA Maxwell).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See &#xA;&lt;a href=&quot;https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#arithmetic-instructions&quot;&gt;https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#arithmetic-instructions&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2016-03-04T21:03:29.910" LastActivityDate="2016-03-04T21:03:29.910" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2143" PostTypeId="2" ParentId="2139" CreationDate="2016-03-04T21:10:52.300" Score="7" Body="&lt;p&gt;I found a solution to my specific problem. Instead of computing the determinant and hitting the precision wall, I use the Gauss-Jordan method step by step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my specific case of affine transformation matrices and the range of values I use, I don't hit any precision problem this way.&lt;/p&gt;&#xA;" OwnerUserId="2792" LastActivityDate="2016-03-04T21:10:52.300" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2144" PostTypeId="2" ParentId="2140" CreationDate="2016-03-04T21:23:22.713" Score="1" Body="&lt;p&gt;the arbitrary line can be represented as $P = (x,y) = P_0 + \lambda. \vec{dir}$ (works in n dimensions, no special case).&#xA;If your other line is $x=x_1$ simply inject this in to solve for $\lambda$ and get $y$: $y=y_0+(x_1-x_0).\frac{{dir}_y}{{dir}_x}$.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-03-04T21:23:22.713" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2146" PostTypeId="1" CreationDate="2016-03-06T11:51:59.727" Score="2" ViewCount="425" Body="&lt;p&gt;Problem Description:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Reference:&lt;br&gt;&#xA;&lt;a href=&quot;http://www.terathon.com/lengyel/Lengyel-Oblique.pdf&quot; rel=&quot;nofollow&quot;&gt;Oblique View Frustum Depth Projection and Clipping&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Mathematics for 3D Game Programming and Computer Graphics&quot; 3rd edition, chapter 5.6.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;M is the original projection matrix. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Plane C is the modified near plane, and C'=transpose(inverse(M))*C is the projected plane by M.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Why in NDC the corner Q' of the view frustum lying opposite the plane C' is given by Q'=(Cx, Cy, 1, 1)?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2190" LastEditorUserId="2190" LastEditDate="2016-03-07T02:58:54.323" LastActivityDate="2021-04-18T08:46:44.733" Title="A question about derivation in oblique view frustum" Tags="&lt;transformations&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2147" PostTypeId="1" AcceptedAnswerId="2148" CreationDate="2016-03-07T07:52:07.727" Score="8" ViewCount="272" Body="&lt;p&gt;So let assume that I have some convex smooth and unclosed surface.&#xA;I'm moving each point of it in a normal direction by some constant factor (This factor is same for all points on surface).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I replace this operation by Uniform or Non-uniform Scaling + Translate? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will resulting surfaces be mathematically identical in these cases?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I want to transform this surface (side view):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JuAlC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JuAlC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2644" LastEditorUserId="171" LastEditDate="2017-05-19T07:39:42.760" LastActivityDate="2017-05-19T07:39:42.760" Title="Moving each point of a surface in direction of corresponding normal" Tags="&lt;transformations&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2148" PostTypeId="2" ParentId="2147" CreationDate="2016-03-07T08:23:15.437" Score="7" Body="&lt;p&gt;No this cannot be modelled by (non-uniform) scaling. It's fairly easy to construct a counterexample:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CWujH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CWujH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is that the amount a section of the curve/surface grows depends on its curvature, not its orientation in space. Notice here that the circular arc grows uniformly in all directions (by a factor of $3/2$) whereas the length of the horizontal segments remains unchanged at a length of $2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, if your surface is not only convex but also has constant curvature, then it's just a circular arc, and for circles your transformation is equivalent to uniform scaling. You can probably also construct curves of varying curvature where your transformation happens to correspond to non-uniform scaling, but for general convex surfaces, that's not the case.&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2016-03-07T10:48:23.870" LastActivityDate="2016-03-07T10:48:23.870" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2149" PostTypeId="1" CreationDate="2016-03-07T11:09:43.583" Score="1" ViewCount="83" Body="&lt;p&gt;There is an web-interface that load geometric models and show it inside the bounding volume. WebGL is used to generate it. So far no scene graph technique is used to organize the elements in the scene. Is there any javascript api that does support the scene graph technique ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there is, I am also required to know more if there is any mechanism to transfer the scene graph related information from the javascript to C++ based API. As of right now the scene that is developed without scenegraph technique stores that scene as an .stl file and C++ based API read the .stl file and process further. I believe that it is not the optimal way to deal with it. It would have much faster and optimal if we have the scene graph system support in javascript to organize the scene and the direct scene related data transfer from javascript to C++ for further processing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let me know if I have not explained the issue well enough. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-03-09T16:14:24.720" Title="Get data from javascript" Tags="&lt;javascript&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2150" PostTypeId="1" CreationDate="2016-03-07T12:04:51.657" Score="3" ViewCount="54" Body="&lt;p&gt;I have bunch of surfaces, like in these two images:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/0Bu6o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0Bu6o.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EY43g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EY43g.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently to make single surface with common parametrization I sample points uniformly from all source surfaces, and fit single NURBS surface from these points. And in most cases it works, but in some rare cases (When surfaces are more curved) this single surface fails to maintain acceptable accuracy at source regions. I tried to increase number of samples, and number of control points for NURBS, but it doesn't help. And btw, solution for images above will be simple planes, because source surfaces are trimmed planes too, but in general case source surfaces will be curvy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additional info:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Source surfaces are trimmed NURBS surfaces, but I can convert them to any other discrete format and work with it.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I don't care about free space between surfaces, values of a resulting surface in this space can be linear interpolation between nearby source surfaces, or even some constant value.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Source surfaces cannot overlap or coincide.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Resulting surface must contain all source regions inside (With some arbitrary tolerance), with common parametrization, also it must not have self-intersections.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Is there any other possible solution to this problem? Maybe some algorithm to order such surfaces in parameter space, or at least name of this problem to google it easily?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for any help.&lt;/p&gt;&#xA;" OwnerUserId="2644" LastActivityDate="2016-03-07T12:04:51.657" Title="Making surface with common parametrization from bunch of other surfaces" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;nurbs&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2151" PostTypeId="2" ParentId="306" CreationDate="2016-03-07T12:10:32.883" Score="73" Body="&lt;p&gt;&lt;strong&gt;EDIT: Please see my other answer with a concrete solution.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have actually solved this exact problem over a year ago for my master's thesis. In the Valve paper, they show that you can AND two distance fields to achieve this, which works as long as you only have one convex corner. For concave corners, you also need the OR operation. &lt;a href=&quot;https://lambdacube3d.wordpress.com/2014/11/12/playing-around-with-font-rendering/&quot; rel=&quot;noreferrer&quot;&gt;This guy&lt;/a&gt; actually developed some obscure system to switch between the two operations using four texture channels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there is a much simpler operation that can facilitate both AND and OR depending on the situation, and this is the principal idea of my thesis: &lt;strong&gt;the median of three&lt;/strong&gt;. So basically, you use exactly three channels (ideal for RGB), which are completely interchangeable, and combine them using the median operation (choose the middle value out of the three).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To accomodate anti-aliasing, we don't work with just booleans, but floating point values, and the AND operation becomes the minimum, and the OR becomes the maximum of two values. The median of three can indeed do both: if &lt;em&gt;a&lt;/em&gt; &amp;lt; &lt;em&gt;b&lt;/em&gt;, for (&lt;em&gt;a&lt;/em&gt;, &lt;em&gt;a&lt;/em&gt;, &lt;em&gt;b&lt;/em&gt;), the median is the minimum, and for (&lt;em&gt;a&lt;/em&gt;, &lt;em&gt;b&lt;/em&gt;, &lt;em&gt;b&lt;/em&gt;), it is the maximum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rendering process is still extremely simple. The entire fragment shader including anti-aliasing can look something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int main() {&#xA;    // Bilinear sampling of the distance field&#xA;    vec3 s = texture2D(sdf, p).rgb;&#xA;    // Acquire the signed distance&#xA;    float d = median(s.r, s.g, s.b) - 0.5;&#xA;    // Weight between inside and outside (anti-aliasing)&#xA;    float w = clamp(d/fwidth(d) + 0.5, 0.0, 1.0);&#xA;    // Combining the background and foreground color&#xA;    gl_FragColor = mix(outsideColor, insideColor, w);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So the only difference from the original method is computing the median right after sampling the texture. You will have to implement the median function though, &lt;a href=&quot;https://stackoverflow.com/a/19045659/1189488&quot;&gt;which can be done with just 4 min/max operations&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now of course, the question is, &lt;strong&gt;how do I build such a three-channel distance field?&lt;/strong&gt; And this is the tricky part. The most obvious approach that I took in the beginning was to perform a decomposition of the input shape/glyph into three components, and then generate a conventional distance field out of each. The rules for this decomposition aren't that complicated. Firstly , the area with at least 2 out of 3 channels on is the inside. Then, if you imagine this as the RGB color channels, convex corners must be made of a secondary color, and its two primary components continue outward. Concave corners are the inverse: Two secondary colors enclose their common primary color, and the wedge between where both edges continue inward is white. I also found that some padding is necessary where two primary or two secondary colors would otherwise touch to avoid artifacts (for example, in the middle stroke of the &quot;N&quot; in the picture).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following image is an example decomposition generated by the program from my thesis:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2fVah.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2fVah.png&quot; alt=&quot;Multi-channel decomposition of glyphs&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This approach however has some drawbacks. One of them is that the special effects, such as outlines and shadows will no longer work correctly. Fortunatelly, I also came up with a second, much more elegant method, which generates the distance fields directly, and even supports all of the graphical effects. It is also included in my thesis and so is also over a year old. I am not going to give any more details right now, because I am currently writing a paper that describes this second technique in detail, but I will post it here as soon as it's finished.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, here is an example of the difference in quality. The texture resolution is the same in each image, but the left one uses a regular texture, the middle one uses an ordinary distance field, and the right one uses my three-channel distance field. The performance overhead is only the difference between sampling an RGB texture versus a monochrome one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aG1NR.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aG1NR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2811" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-04-25T07:59:45.870" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="2152" PostTypeId="2" ParentId="2086" CreationDate="2016-03-08T13:10:25.380" Score="1" Body="&lt;p&gt;&lt;strike&gt;The &amp;quot;Uniform Mapping&amp;quot; here is incorrect.  It does not transform to a uniform distribution on the sphere.&lt;/strike&gt;&lt;/p&gt;&#xA;&lt;p&gt;Very very bad me.  I misread the equation AND I didn't even consult my own reference [1], if I had I would have seen my mistake.&lt;/p&gt;&#xA;&lt;p&gt;Still the method from [2] is interesting and is described below.&lt;/p&gt;&#xA;&lt;h1&gt;Additional note:&lt;/h1&gt;&#xA;&lt;p&gt;To map a uniform point set from the unit square to the sphere or half sphere requires an area-preserving map.  That will maintain the uniform property.  For pseudo-random that's sufficient (points are independent), however low-discrepancy point set will have its discrepancy measure effected by distortions in area introduced by the map.  I'm not aware of any references with respect to this point.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;The method from [2] starts by mapping unit square to the unit disk.  One way we can do this is by using a rejection method.  Pseudo-code looks like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;d = 0;&#xA;&#xA;do {&#xA;  p = uniform2d(...);  // [0,1) x [0,1)   given to be uniform&#xA;  p = 2p;              // [0,2) x [0,2)   scaling (area-preserving)&#xA;  p = p-1;             // (-1,1) x (-1,1) translating (area-preserving)&#xA;  d = dot(p,p);        // is p in disk?&#xA;} while(d &amp;gt;= 1);       //   if not rinse-and-repeat&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;the area of the transformed square is &lt;span class=&quot;math-container&quot;&gt;$4$&lt;/span&gt; and the unit disk is &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt;, so the acceptance rate is &lt;span class=&quot;math-container&quot;&gt;$\frac{\pi }{4}$&lt;/span&gt; (~.785) so on average requires &lt;span class=&quot;math-container&quot;&gt;$\frac{4}{\pi}$&lt;/span&gt; (~1.273) iterations.&lt;/p&gt;&#xA;&lt;p&gt;Also non-rejection based methods exist, for example [3] which requires one square root and one trig operation. Note that the rejection method does not distort areas so the discrepancy measure remains the same.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Once we have &lt;span class=&quot;math-container&quot;&gt;$ p = \left(u_0, u_1 \right) $&lt;/span&gt; uniformly distributed in the unit disk, we have:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ u_0, u_1 \in \left(-1,1\right) $$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ d = p\cdot p = u_0^2+u_1^2,\; d &amp;lt; 1 $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;then the transform to the sphere is:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ s=2\sqrt{1-d} $$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ p = \left\{s\thinspace u_0,\thinspace s\thinspace u_1, 1-2d\right\} $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;or if you wanted a half-sphere, say positive Z, (just to state the obvious):&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$p = \left\{s\thinspace u_0,\thinspace s\thinspace u_1, d\right\} $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;There is a Stackexchange: Mathematics thread that discusses this method ([4],[5]).&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Also if you want to procedurally generate a LDS the additive recurrence formulation of the Weyl sequence is very cheap.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;References:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://mathworld.wolfram.com/SpherePointPicking.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wolfram MathWorld: Sphere Point Picking&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&amp;quot;Choosing a Point from the Surface of a Sphere.&amp;quot;, George Marsaglia, 1972. (&lt;a href=&quot;http://projecteuclid.org/euclid.aoms/1177692644;&quot; rel=&quot;nofollow noreferrer&quot;&gt;PDF&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://mathworld.wolfram.com/DiskPointPicking.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wolfram MathWorld: Disk Point Picking&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://math.stackexchange.com/questions/838326/3-random-numbers-to-describe-point-on-a-sphere/838336#838336&quot;&gt;SE Mathematics&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://math.stackexchange.com/questions/838326/3-random-numbers-to-describe-point-on-a-sphere/838882#838882&quot;&gt;SE Mathematics&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2831" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-03-10T09:11:45.747" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2153" PostTypeId="1" AcceptedAnswerId="2154" CreationDate="2016-03-08T15:42:51.960" Score="11" ViewCount="4230" Body="&lt;p&gt;I am wondering what's the best way to integrate a dynamic loop function in a shader?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, it seems that dynamic arrays are not possible. So, is it better to create a maximum size array and only fill a part of it or define arrays with predefined sizes?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, what's the best way to iterate over this array?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it better to use an unrolled loop or a dynamic loop for something between 4 to 128 iterations?&#xA;I've also seen that it's possible to unroll it to a maximum predefined number of iterations then stop it with a condition such as &lt;code&gt;if (i == myCurrentMaximumIterationNumber)&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="127" LastEditDate="2016-03-08T21:40:08.187" LastActivityDate="2016-03-10T11:49:50.090" Title="Loop performance in a shader" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;glsl&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2154" PostTypeId="2" ParentId="2153" CreationDate="2016-03-08T17:43:45.363" Score="6" Body="&lt;p&gt;Shader compilers are extremely aggressive about unrolling since early HW often didn't have flow control and the cost on more recent HW can vary. If you have a benchmark you are actively testing against and a range of relevant hardware, then try things to see what happens. Your dynamic loop is more amenable to developer intervention than a static loop - but leaving it to the compiler is still good advice unless you have a benchmark available. With a benchmark, exploration is worthwhile (and fun).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, the biggest loss with a dynamic loop on a GPU is that individual &quot;threads&quot; in a wavefront/warp will finish at different times. The threads that stop later force all the ones that finish early to execute NOPs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nested loops should be carefully thought through: I implemented a block based entropy decoder that encoded runs of zeros (for JPEG like compression). The natural implementation was to decode the runs in a tight inner loop - which meant often only one thread was making progress; by flattening the loop and explicitly testing in each thread if it was currently decoding a run or not, I kept all threads active through the fixed length loop (the decoded blocks were all the same size). If the threads were like CPU threads, the change would have been terrible, but on the GPU I was running on, I got a 6 fold increase in performance (which was still terrible - there weren't enough blocks to keep the GPU busy - but it was a proof of concept).&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-03-10T11:49:50.090" LastActivityDate="2016-03-10T11:49:50.090" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2155" PostTypeId="1" AcceptedAnswerId="2156" CreationDate="2016-03-08T20:27:51.557" Score="6" ViewCount="553" Body="&lt;p&gt;I've never written shaders before, and now I'm trying to implement SSAO with SceneKit on OS X and iOS. I'm trying different SSAO shaders that I find, e.g. from Three.js, &lt;a href=&quot;http://theorangeduck.com/page/pure-depth-ssao&quot; rel=&quot;noreferrer&quot;&gt;this one&lt;/a&gt;, and &lt;a href=&quot;https://www.shadertoy.com/view/Ms33WB&quot; rel=&quot;noreferrer&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On OS X they all work as they should, but on iPhone &lt;em&gt;all&lt;/em&gt; of them giving me the same artefacts (images show SSAO pass only). The lines move when I move the camera. So it must be because of some differences of OpenGL ES. Anyone knows what's wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/C1NhL.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/C1NhL.png&quot; alt=&quot;img1&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/3FQYE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3FQYE.png&quot; alt=&quot;img2&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;" OwnerUserId="2840" LastActivityDate="2016-03-09T21:19:12.457" Title="SSAO artefacts on iPhone (OpenGL ES)" Tags="&lt;shader&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2156" PostTypeId="2" ParentId="2155" CreationDate="2016-03-08T23:20:07.050" Score="6" Body="&lt;p&gt;Resolved by adding &lt;code&gt;precision highp sampler2D&lt;/code&gt; to my shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About default precision settings on ES - &lt;a href=&quot;https://www.khronos.org/files/opengles_shading_language.pdf&quot;&gt;https://www.khronos.org/files/opengles_shading_language.pdf&lt;/a&gt; page 36.&lt;/p&gt;&#xA;" OwnerUserId="2840" LastEditorUserId="2840" LastEditDate="2016-03-09T21:19:12.457" LastActivityDate="2016-03-09T21:19:12.457" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2158" PostTypeId="1" CreationDate="2016-03-09T14:17:54.727" Score="3" ViewCount="433" Body="&lt;p&gt;Ok guys, tricky one!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to modify &lt;a href=&quot;http://wiki.unity3d.com/index.php?title=MirrorReflection2&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; Unity script + shader to include normal mapping. The tl;dr is, it uses a single texture rather than a cubemap as it is only for reflecting in a planar surface. So it doesn't use the standard ray bounce onto an axis aligned cube. Instead it :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;creates a reflection matrix from the plane (pos and normal)&lt;/li&gt;&#xA;&lt;li&gt;reflects the camera position and view matrix through the plane&lt;/li&gt;&#xA;&lt;li&gt;renders to texture from the reflected camera (with oblique near clipping plane set to cull everything behind the mirror)&lt;/li&gt;&#xA;&lt;li&gt;creates a projection matrix and sends it as uniform to the shader (basically just a standard MVP matrix but with scale cancelled, and biased from [-1, 1] to [0, 1]&lt;/li&gt;&#xA;&lt;li&gt;multiplies the object space coordinate by the projection matrix to get a texcoord and then looks up the mirror texture with this&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So there are no normals actually used in the shader at all at present. I know how to construct a TBN matrix and use this to warp the per-pixel normals, but I have no idea how this translates into a texture offset in this case. I have a feeling I might need screen-space normals like in the question &lt;a href=&quot;https://stackoverflow.com/questions/14317350/transform-world-space-normals-to-screen-space-normals&quot;&gt;here&lt;/a&gt; but pretty stumped beyond that. Any ideas?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT -- Here's the script&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;using UnityEngine;&#xA;using System.Collections;&#xA;&#xA;[ExecuteInEditMode()]&#xA;public class PlanarRealtimeReflection : MonoBehaviour&#xA;{&#xA;    public bool m_DisablePixelLights = true;&#xA;    public int m_TextureResolution = 1024;&#xA;    public float m_clipPlaneOffset = 0.07f;&#xA;    private float m_finalClipPlaneOffset = 0.0f;&#xA;    public bool m_NormalsFromMesh = false;&#xA;    public bool m_BaseClipOffsetFromMesh = false;&#xA;    public bool m_BaseClipOffsetFromMeshInverted = false;&#xA;    private Vector3 m_calculatedNormal = Vector3.zero;&#xA;    private Vector3 m_calculatedTangent = Vector4.zero;&#xA;    public LayerMask m_ReflectLayers = -1;&#xA;&#xA;    private Hashtable m_ReflectionCameras = new Hashtable(); //Camera -&amp;gt; Camera table&#xA;&#xA;    private RenderTexture m_ReflectionTexture = null;&#xA;    private int m_OldReflectionTextureSize = 0;&#xA;&#xA;    private static bool s_InsideRendering = false;&#xA;&#xA;    //This is called when it's known that the object will be rendered by some&#xA;    //camera. We render reflections and do other updates here.&#xA;    //Because the script executes in edit mode, reflections for the scene view&#xA;    //camera will just work!&#xA;    public void OnWillRenderObject()&#xA;    {&#xA;        if(!enabled || !renderer || !renderer.sharedMaterial || !renderer.enabled)&#xA;            return;&#xA;&#xA;        Camera cam = Camera.current;&#xA;        if(!cam)&#xA;            return;&#xA;&#xA;        if(m_NormalsFromMesh &amp;amp;&amp;amp; GetComponent&amp;lt;MeshFilter&amp;gt;() != null)&#xA;            m_calculatedNormal = transform.TransformDirection(GetComponent&amp;lt;MeshFilter&amp;gt;().sharedMesh.normals[0]);&#xA;            m_calculatedTangent = transform.TransformDirection(GetComponent&amp;lt;MeshFilter&amp;gt;().sharedMesh.tangents[0]);&#xA;&#xA;        if(m_BaseClipOffsetFromMesh &amp;amp;&amp;amp; GetComponent&amp;lt;MeshFilter&amp;gt;() != null)&#xA;            m_finalClipPlaneOffset = (transform.position - transform.TransformPoint(GetComponent&amp;lt;MeshFilter&amp;gt;().sharedMesh.vertices[0])).magnitude + m_clipPlaneOffset;&#xA;        else if(m_BaseClipOffsetFromMeshInverted &amp;amp;&amp;amp; GetComponent&amp;lt;MeshFilter&amp;gt;() != null)&#xA;            m_finalClipPlaneOffset = -(transform.position - transform.TransformPoint(GetComponent&amp;lt;MeshFilter&amp;gt;().sharedMesh.vertices[0])).magnitude + m_clipPlaneOffset;&#xA;        else&#xA;            m_finalClipPlaneOffset = m_clipPlaneOffset;&#xA;&#xA;        //Safeguard from recursive reflections.        &#xA;        if(s_InsideRendering)&#xA;            return;&#xA;        s_InsideRendering = true;&#xA;&#xA;        Camera reflectionCamera;&#xA;        CreateSurfaceObjects(cam, out reflectionCamera);&#xA;&#xA;        //Find out the reflection plane: position and normal in world space&#xA;        Vector3 pos = transform.position;&#xA;        Vector3 normal = m_NormalsFromMesh &amp;amp;&amp;amp; GetComponent&amp;lt;MeshFilter&amp;gt;() != null ? m_calculatedNormal : transform.up;&#xA;        Vector3 tangent = m_NormalsFromMesh &amp;amp;&amp;amp; GetComponent&amp;lt;MeshFilter&amp;gt;() != null ? m_calculatedTangent : transform.right;&#xA;        Vector3 bitangent = Vector3.Cross(normal, tangent);&#xA;&#xA;        //Optionally disable pixel lights for reflection&#xA;        int oldPixelLightCount = QualitySettings.pixelLightCount;&#xA;        if(m_DisablePixelLights)&#xA;            QualitySettings.pixelLightCount = 0;&#xA;&#xA;        UpdateCameraModes(cam, reflectionCamera);&#xA;&#xA;        //Render reflection&#xA;        //Reflect camera around reflection plane&#xA;        float d = -Vector3.Dot (normal, pos) - m_finalClipPlaneOffset;&#xA;        Vector4 reflectionPlane = new Vector4 (normal.x, normal.y, normal.z, d);&#xA;        Matrix4x4 reflection = Matrix4x4.zero;&#xA;        CalculateReflectionMatrix (ref reflection, reflectionPlane);&#xA;        Vector3 oldpos = cam.transform.position;&#xA;        Vector3 newpos = reflection.MultiplyPoint(oldpos);&#xA;        reflectionCamera.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;&#xA;&#xA;        //Setup oblique projection matrix so that near plane is our reflection plane.&#xA;        //This way we clip everything below/above it for free.&#xA;        Vector4 clipPlane = CameraSpacePlane(reflectionCamera, pos, normal, 1.0f);&#xA;        Matrix4x4 projection = cam.projectionMatrix;&#xA;        CalculateObliqueMatrix (ref projection, clipPlane);&#xA;        reflectionCamera.projectionMatrix = projection;&#xA;&#xA;        reflectionCamera.cullingMask = ~(1&amp;lt;&amp;lt;4) &amp;amp; m_ReflectLayers.value; //never render water layer&#xA;        reflectionCamera.targetTexture = m_ReflectionTexture;&#xA;        GL.SetRevertBackfacing (true);&#xA;        reflectionCamera.transform.position = newpos;&#xA;        //Vector3 euler = cam.transform.eulerAngles;&#xA;        //reflectionCamera.transform.eulerAngles = euler; // new Vector3(0, euler.y, euler.z);&#xA;        reflectionCamera.Render();&#xA;        reflectionCamera.transform.position = oldpos;&#xA;        GL.SetRevertBackfacing (false);&#xA;        Material[] materials = renderer.sharedMaterials;&#xA;        foreach(Material mat in materials)&#xA;        {&#xA;            if (mat.HasProperty(&quot;_ReflectionTex&quot;))  &#xA;                mat.SetTexture(&quot;_ReflectionTex&quot;, m_ReflectionTexture);&#xA;            mat.SetVector(&quot;_Normal&quot;, new Vector4(normal.x,normal.y,normal.z,0));&#xA;            mat.SetVector(&quot;_Tangent&quot;, new Vector4(tangent.x, tangent.y, tangent.z));&#xA;            mat.SetVector(&quot;_Bitangent&quot;, new Vector4(bitangent.x, bitangent.y, bitangent.z));&#xA;        }&#xA;&#xA;        //Set matrix on the shader that transforms UVs from object space into screen&#xA;        //space. We want to just project reflection texture on screen.&#xA;        Matrix4x4 scaleOffset = Matrix4x4.TRS(&#xA;            new Vector3(0.5f,0.5f,0.5f), Quaternion.identity, new Vector3(0.5f,0.5f,0.5f));&#xA;        Vector3 scale = transform.localScale;//.lossyScale;&#xA;        Matrix4x4 mtx = transform.localToWorldMatrix * Matrix4x4.Scale(new Vector3(1.0f/scale.x, 1.0f/scale.y, 1.0f/scale.z));&#xA;        mtx = scaleOffset *  cam.projectionMatrix * cam.worldToCameraMatrix * mtx;&#xA;        foreach(Material mat in materials)&#xA;            mat.SetMatrix(&quot;_ProjMatrix&quot;, mtx);&#xA;        //Restore pixel light count&#xA;        if(m_DisablePixelLights)&#xA;            QualitySettings.pixelLightCount = oldPixelLightCount;&#xA;&#xA;        s_InsideRendering = false;&#xA;    }&#xA;&#xA;&#xA;    //Cleanup all the objects we possibly have created&#xA;    void OnDisable()&#xA;    {&#xA;        if(m_ReflectionTexture)&#xA;        {&#xA;            DestroyImmediate(m_ReflectionTexture);&#xA;            m_ReflectionTexture = null;&#xA;        }&#xA;        foreach(DictionaryEntry kvp in m_ReflectionCameras)&#xA;            DestroyImmediate(((Camera)kvp.Value).gameObject);&#xA;        m_ReflectionCameras.Clear();&#xA;    }&#xA;&#xA;&#xA;    private void UpdateCameraModes(Camera src, Camera dest)&#xA;    {&#xA;        if(dest == null)&#xA;            return;&#xA;        //set camera to clear the same way as current camera&#xA;        dest.clearFlags = src.clearFlags;&#xA;        dest.backgroundColor = src.backgroundColor;        &#xA;        if(src.clearFlags == CameraClearFlags.Skybox)&#xA;        {&#xA;            Skybox sky = src.GetComponent(typeof(Skybox)) as Skybox;&#xA;            Skybox mysky = dest.GetComponent(typeof(Skybox)) as Skybox;&#xA;            if(!sky || !sky.material)&#xA;            {&#xA;                mysky.enabled = false;&#xA;            }&#xA;            else&#xA;            {&#xA;                mysky.enabled = true;&#xA;                mysky.material = sky.material;&#xA;            }&#xA;        }&#xA;        //update other values to match current camera.&#xA;        //even if we are supplying custom camera&amp;amp;projection matrices,&#xA;        //some of values are used elsewhere (e.g. skybox uses far plane)&#xA;        dest.farClipPlane = src.farClipPlane;&#xA;        dest.nearClipPlane = src.nearClipPlane;&#xA;        dest.orthographic = src.orthographic;&#xA;        dest.fieldOfView = src.fieldOfView;&#xA;        dest.aspect = src.aspect;&#xA;        dest.orthographicSize = src.orthographicSize;&#xA;    }&#xA;&#xA;    //On-demand create any objects we need&#xA;    private void CreateSurfaceObjects(Camera currentCamera, out Camera reflectionCamera)&#xA;    {&#xA;        reflectionCamera = null;&#xA;&#xA;        //Reflection render texture&#xA;        if(!m_ReflectionTexture || m_OldReflectionTextureSize != m_TextureResolution)&#xA;        {&#xA;            if(m_ReflectionTexture)&#xA;                DestroyImmediate(m_ReflectionTexture);&#xA;            m_ReflectionTexture = new RenderTexture(m_TextureResolution, m_TextureResolution, 16);&#xA;            m_ReflectionTexture.name = &quot;__SurfaceReflection&quot; + GetInstanceID();&#xA;            m_ReflectionTexture.isPowerOfTwo = true;&#xA;            m_ReflectionTexture.hideFlags = HideFlags.DontSave;&#xA;            m_OldReflectionTextureSize = m_TextureResolution;&#xA;        }&#xA;&#xA;        //Camera for reflection&#xA;        reflectionCamera = m_ReflectionCameras[currentCamera] as Camera;&#xA;        if(!reflectionCamera) //catch both not-in-dictionary and in-dictionary-but-deleted-GO&#xA;        {&#xA;            GameObject go = new GameObject(&quot;Surface Refl Camera id&quot; + GetInstanceID() + &quot; for &quot; + currentCamera.GetInstanceID(), typeof(Camera), typeof(Skybox));&#xA;            reflectionCamera = go.camera;&#xA;            reflectionCamera.enabled = false;&#xA;            reflectionCamera.transform.position = transform.position;&#xA;            reflectionCamera.transform.rotation = transform.rotation;&#xA;            reflectionCamera.gameObject.AddComponent(&quot;FlareLayer&quot;);&#xA;            go.hideFlags = HideFlags.HideAndDontSave;&#xA;            m_ReflectionCameras[currentCamera] = reflectionCamera;&#xA;        }        &#xA;    }&#xA;&#xA;    //Extended sign: returns -1, 0 or 1 based on sign of a&#xA;    private static float sgn(float a)&#xA;    {&#xA;        if (a &amp;gt; 0.0f) return 1.0f;&#xA;        if (a &amp;lt; 0.0f) return -1.0f;&#xA;        return 0.0f;&#xA;    }&#xA;&#xA;    //Given position/normal of the plane, calculates plane in camera space.&#xA;    private Vector4 CameraSpacePlane (Camera cam, Vector3 pos, Vector3 normal, float sideSign)&#xA;    {&#xA;        Vector3 offsetPos = pos + normal * m_finalClipPlaneOffset;&#xA;        Matrix4x4 m = cam.worldToCameraMatrix;&#xA;        Vector3 cpos = m.MultiplyPoint(offsetPos);&#xA;        Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign;&#xA;        return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos,cnormal));&#xA;    }&#xA;&#xA;    //Adjusts the given projection matrix so that near plane is the given clipPlane&#xA;    //clipPlane is given in camera space. See article in Game Programming Gems 5 and&#xA;    //http://aras-p.info/texts/obliqueortho.html&#xA;    private static void CalculateObliqueMatrix (ref Matrix4x4 projection, Vector4 clipPlane)&#xA;    {&#xA;        Vector4 q = projection.inverse * new Vector4(&#xA;            sgn(clipPlane.x),&#xA;            sgn(clipPlane.y),&#xA;            1.0f,&#xA;            1.0f&#xA;            );&#xA;        Vector4 c = clipPlane * (2.0F / (Vector4.Dot (clipPlane, q)));&#xA;        //third row = clip plane - fourth row&#xA;        projection[2] = c.x - projection[3];&#xA;        projection[6] = c.y - projection[7];&#xA;        projection[10] = c.z - projection[11];&#xA;        projection[14] = c.w - projection[15];&#xA;    }&#xA;&#xA;    //Calculates reflection matrix around the given plane&#xA;    private static void CalculateReflectionMatrix (ref Matrix4x4 reflectionMat, Vector4 plane)&#xA;    {&#xA;        reflectionMat.m00 = (1F - 2F*plane[0]*plane[0]);&#xA;        reflectionMat.m01 = (  - 2F*plane[0]*plane[1]);&#xA;        reflectionMat.m02 = (  - 2F*plane[0]*plane[2]);&#xA;        reflectionMat.m03 = (  - 2F*plane[3]*plane[0]);&#xA;&#xA;        reflectionMat.m10 = (  - 2F*plane[1]*plane[0]);&#xA;        reflectionMat.m11 = (1F - 2F*plane[1]*plane[1]);&#xA;        reflectionMat.m12 = (  - 2F*plane[1]*plane[2]);&#xA;        reflectionMat.m13 = (  - 2F*plane[3]*plane[1]);&#xA;&#xA;        reflectionMat.m20 = (  - 2F*plane[2]*plane[0]);&#xA;        reflectionMat.m21 = (  - 2F*plane[2]*plane[1]);&#xA;        reflectionMat.m22 = (1F - 2F*plane[2]*plane[2]);&#xA;        reflectionMat.m23 = (  - 2F*plane[3]*plane[2]);&#xA;&#xA;        reflectionMat.m30 = 0F;&#xA;        reflectionMat.m31 = 0F;&#xA;        reflectionMat.m32 = 0F;&#xA;        reflectionMat.m33 = 1F;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the shader so far&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Shader &quot;Realtime Reflections/New Shader&quot;&#xA;{&#xA;    Properties {        &#xA;        _MainAlpha(&quot;MainAlpha&quot;, Range(0, 1)) = 1&#xA;        _MapAmount(&quot;Distortion Amount&quot;, Range(0, 0.05)) = 0&#xA;        _MainTex (&quot;Base (RGB) Gloss (A)&quot;, 2D) = &quot;white&quot; {}&#xA;        _ReflectionTex (&quot;Reflection&quot;, 2D) = &quot;white&quot; {}&#xA;        _NormalMap (&quot;Normal Map&quot;, 2D) = &quot;white&quot; {}&#xA;        _RefColor(&quot;Color&quot;,Color) = (1,1,1,1)&#xA;    }&#xA;    SubShader {&#xA;        Tags {&#xA;            &quot;RenderType&quot;=&quot;Opaque&quot;}&#xA;        LOD 100&#xA;        Pass {&#xA;            CGPROGRAM&#xA;            #pragma vertex vert&#xA;            #pragma fragment frag&#xA;            #include &quot;UnityCG.cginc&quot;&#xA;&#xA;            uniform float4x4    _ProjMatrix;&#xA;            uniform float       _RefType;&#xA;            uniform float4      _Normal;&#xA;            uniform float4      _Tangent;&#xA;            uniform float4      _Bitangent;&#xA;            sampler2D           _ReflectionTex;&#xA;            sampler2D           _MainTex;&#xA;            sampler2D           _NormalMap;&#xA;            float4              _MainTex_ST;&#xA;            float4              _NormalMap_ST;       &#xA;            float4              _RefColor;&#xA;            float               _MainAlpha;&#xA;            float               _MapAmount;&#xA;&#xA;            struct outvertex {&#xA;                float4 pos :        SV_POSITION;&#xA;                float2 colorUV :    TEXCOORD0;&#xA;                float2 bumpUV :     TEXCOORD1;&#xA;                float4 varyingPos : TEXCOORD2;&#xA;            };&#xA;&#xA;            outvertex vert(appdata_full v) {&#xA;&#xA;                outvertex o;&#xA;                o.pos = mul (UNITY_MATRIX_MVP,v.vertex);&#xA;                o.colorUV = TRANSFORM_TEX(v.texcoord.xy,_MainTex);&#xA;                o.bumpUV = TRANSFORM_TEX(v.texcoord1.xy,_NormalMap);&#xA;                o.varyingPos = v.vertex;    &#xA;                o. color = fixed4(mul(float3x3(UNITY_MATRIX_IT_MV),v.normal),1);&#xA;                return o;&#xA;            }&#xA;&#xA;            float4 frag(outvertex i) : COLOR {          &#xA;                float4 posProj = mul(_ProjMatrix, i.varyingPos);      &#xA;                float2 normPosProj = posProj.xy / posProj.w;&#xA;                float3 bump = (float3(tex2D(_NormalMap, i.bumpUV));&#xA;                //normPosProj += ?????????&#xA;                half4 flecol = tex2D(_ReflectionTex, normPosProj);  &#xA;                half4 maincol =  tex2D(_MainTex, i.colorUV);                                    &#xA;                half4 outcolor = half4(1,1,1,1);                &#xA;                outcolor = maincol*_MainAlpha+flecol*(1-_MainAlpha);&#xA;                return outcolor*_RefColor;&#xA;            }&#xA;            ENDCG&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I had the idea to get the normal in screen space (so z is always toward camera) then simply find the delta between the regular normal and the warped one in x,y and use this as the texture offset, but I have no idea if this is feasible or how to do it.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-03-09T14:42:48.583" Title="Normal mapping for planar reflections" Tags="&lt;reflection&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2159" PostTypeId="2" ParentId="2149" CreationDate="2016-03-09T16:14:24.720" Score="2" Body="&lt;p&gt;There does not seem to be a single answer for this question, but I will try to give some directions in possible solutions. First of all I presume that &quot;the scene graph technique&quot; means storing the object data in some kind of data structure (I know what a scenegraph is, but there are many different possibilities for indoor/outdoor scenes etc). There seem to be some Javascript libraries, but they do much more then simply providing the datastructure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For defining the scenegraph structure you could look at glTF(&lt;a href=&quot;https://github.com/KhronosGroup/glTF&quot; rel=&quot;nofollow&quot;&gt;https://github.com/KhronosGroup/glTF&lt;/a&gt;) defined by Khronos themselves. This really depends on what kind of features your scene graph requires.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the C++ library is required for the processing you can look into providing Javascript bindings for it. You can either try to compile the library to javascript using emscripten (&lt;a href=&quot;https://github.com/kripken/emscripten&quot; rel=&quot;nofollow&quot;&gt;https://github.com/kripken/emscripten&lt;/a&gt;). Otherwise provide a C-interface and call it directly using ccall(). This way you can directly share this datastructure via parameters.&lt;/p&gt;&#xA;" OwnerUserId="64" LastActivityDate="2016-03-09T16:14:24.720" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2160" PostTypeId="1" AcceptedAnswerId="2162" CreationDate="2016-03-09T18:34:38.510" Score="1" ViewCount="75" Body="&lt;p&gt;Does anyone out there know of any software for developing real time visualisations and analysis of real time sound, say using a mike? I've found a few but none allow the user to build up their own visualisations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for any ideas, Jonathan&lt;/p&gt;&#xA;" OwnerUserId="2848" LastActivityDate="2016-03-22T13:34:43.987" Title="live music visualisation" Tags="&lt;real-time&gt;" AnswerCount="2" CommentCount="1" ClosedDate="2016-03-22T17:20:14.490" ContentLicense="CC BY-SA 3.0" />
  <row Id="2161" PostTypeId="1" AcceptedAnswerId="2278" CreationDate="2016-03-09T20:58:55.873" Score="4" ViewCount="668" Body="&lt;p&gt;Down the road, I'm planning to implement one or another GPU based ambient occlusion technique. My goal will be to approximate a physically based offline renderer, so I was pretty happy when Wikipedia led me to &lt;a href=&quot;http://people.mpi-inf.mpg.de/~ritschel/Papers/SSDO.pdf&quot; rel=&quot;noreferrer&quot;&gt;Approximating Dynamic Global Illumination in Image Space&lt;/a&gt;, which describes SSDO. Based on the references, it looks to be from the 2008 era. Are there more modern approaches with similar accuracy goals?&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-04-07T02:45:58.850" Title="Modern Screen Space Ambient Occlusion Techniques" Tags="&lt;gpu&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2162" PostTypeId="2" ParentId="2160" CreationDate="2016-03-09T22:28:11.673" Score="1" Body="&lt;p&gt;One tool I've seen people use for this sort of thing is &lt;a href=&quot;https://processing.org/&quot; rel=&quot;nofollow&quot;&gt;Processing&lt;/a&gt;, a Java-based language for real-time artsy stuff that supports graphics and audio. I haven't ever worked with it myself, but apparently it's pretty easy to use it for programming visualizations. &lt;a href=&quot;https://www.youtube.com/watch?v=a-Ht7d-tECY&quot; rel=&quot;nofollow&quot;&gt;Here's an example&lt;/a&gt; of a simple visualization someone made; look in the video description for a link to their code&amp;mdash;it's quite short. Their example loads an mp3 file, but Processing also supports real-time input from a mic.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-09T22:28:11.673" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2163" PostTypeId="1" CreationDate="2016-03-10T03:43:14.837" Score="0" ViewCount="2305" Body="&lt;p&gt;I've been researching for quite a while and I couldn't find any explanation or at least a how to create a vector graphic application (specifically in windows) where I can create a 3D vector shape, say a box. I know there is OpenGL and DirectX for that and the new Vulkan API but I don't wan't to use those APIs and libraries. What I am asking is where can I find examples or at least tutorials for creating custom made API graphics library for the C++ language. If there is not a way in C++ language then any other way to do it. By example masm or nasm Assembly language.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If my question is too broad please specify any additional information you need to be able to answer my question.&lt;/p&gt;&#xA;" OwnerUserId="2853" LastEditorUserId="6546" LastEditDate="2017-05-05T07:44:19.203" LastActivityDate="2017-05-05T07:44:19.203" Title="Creating vector shapes using only C++" Tags="&lt;c++&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="10" ClosedDate="2016-03-14T15:53:57.133" ContentLicense="CC BY-SA 3.0" />
  <row Id="2164" PostTypeId="1" AcceptedAnswerId="2165" CreationDate="2016-03-10T12:44:09.337" Score="3" ViewCount="95" Body="&lt;p&gt;I'm new to graphics and want to implement algorithms like dda,scan-line, clipping,etc. I'm confused which library to use. OpenGl, graphics in turbo c,or any other. Please suggest.&lt;/p&gt;&#xA;" OwnerUserId="2855" LastActivityDate="2016-03-10T13:05:29.447" Title="library / tool for implementing algorithms" Tags="&lt;opengl&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2165" PostTypeId="2" ParentId="2164" CreationDate="2016-03-10T13:05:29.447" Score="4" Body="&lt;p&gt;If you're completely new to graphics programming I would start with Processing. It's based on Java and JOGL but comes with a whole bunch of drawing commands built in, and its own basic IDE. It's very good for prototyping algorithms and getting quick visual feedback without having to write a ton of boilerplate code, and it insulates you from the underlying API (OpenGL in this case). Presumably you're not going for high performance, since the algorithms you mention are efficiently implemented in hardware, and you just want to familiarize yourself with how they work? If so it's a great place to start.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you've got the hang of Processing you can move over to OpenFrameworks, which is very similar but in C++, with the option to 'drill down' and call the underlying OpenGL commands directly. From there, the sky's the limit. :-)&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2016-03-10T13:05:29.447" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2166" PostTypeId="1" AcceptedAnswerId="2296" CreationDate="2016-03-10T14:09:49.317" Score="5" ViewCount="4930" Body="&lt;p&gt;I know that if you turn of vsync, it synchronizes rendering with the vertical redraw cycle to prevent tearing, and that doing so caps your rendering rate (FPS) at the monitor refresh rate, which is commonly 60hz / 60 fps, although other rates exist as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when you are not running at a full 60fps how does vsync affect your frame rate?  I've heard people say that you will be limited to a multiple of 60fps (well, ~16ms to be precise), but from observation, fps can fluctuate wildly.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-04-10T02:55:44.603" Title="How does vsync affect fps exactly when not at full vsync fps?" Tags="&lt;real-time&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2167" PostTypeId="1" CreationDate="2016-03-10T14:17:37.640" Score="9" ViewCount="275" Body="&lt;p&gt;A signed distance field texture is a technique where you store the distance from a pixel to the surface of a shape within the color information for that pixel, allowing almost vector graphics quality rendering using textures (&lt;a href=&quot;http://blog.demofox.org/2014/06/30/distance-field-textures/&quot;&gt;http://blog.demofox.org/2014/06/30/distance-field-textures/&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When reading the texture data in a shader, you get values between 0 and 1, which is meant to map between -1 and 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The distance data is essentially &quot;normalized&quot; when creating the shader, which means that instead of storing a true positive or negative distance value in the texture, you instead multiply (divide) the real distance by some constant value, clamp it to be between 0 and 1 and then store that distance value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That constant value essentially controls the width in pixels of the &quot;gradient&quot; band, where the surface of the shape goes from 0 to 1 (-1 to 1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an optimal value for this based on the output texture resolution or anything else?  I always use trial and error until it looks right but feel there must be a better way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, is there a way to choose an optimal output texture size?  Or should you just always use a texture size smaller than the size you intend to render it at?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-03-10T14:17:37.640" Title="Choosing width of data for signed distance field texture" Tags="&lt;texture&gt;&lt;2d&gt;&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2168" PostTypeId="2" ParentId="2166" CreationDate="2016-03-10T14:17:41.987" Score="6" Body="&lt;p&gt;It depends on how a missed frame is handled by the driver.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One option is to just wait until the next vsync, causing a hitch of 32 ms and if the application is just at the limit of 16 ms can cause fluctuations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next option is to queue the frame for display next frame but don't wait on it. This will still cause a visual hitch but the application can then immediately start on the next frame instead of being forced to wait 16 ms. If the next frame is done faster then the late frame may even never be shown. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The final option is to not block and push the late frame to the display immediately which can cause tearing.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-03-10T14:17:41.987" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2170" PostTypeId="1" CreationDate="2016-03-11T17:56:09.000" Score="6" ViewCount="1003" Body="&lt;p&gt;I have a convoluted polyline composed of vertices and straight segments and a separate point that is independent of the polyline. I am trying draw a straight new line from the point at a given angle and determine if the new line intersects the polyline and get the location of that intersection. If there are multiple intersections I want the location of the closest intersection. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently doing this by drawing a line an arbitrary (long) distance from the point at the desired angle and then intersecting it with the polyline using a python gis toolkit (shapely). If there are multiple intersections I sort them by distance and select the closest one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This method works but is somewhat clumsy. Is there a more efficient method of calculating the closest intersection? It almost seems like ray tracing (of which I have minimal knowledge) but I can't find much online that applies to my case. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other method that I contemplated was to iterate over every line segment in the polyline and use y = mx+b to see if the segment intersects the new line from the point. The polyline is potentially quite long with many segments, but I've also seen some sorting tricks online to make this method more efficient. Is there a method that I'm missing?&lt;/p&gt;&#xA;" OwnerUserId="2863" LastEditorUserId="2863" LastEditDate="2016-03-11T18:30:49.033" LastActivityDate="2016-03-13T08:09:05.523" Title="Calculating intersection of polyline and line" Tags="&lt;geometry&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2172" PostTypeId="1" CreationDate="2016-03-11T21:16:34.320" Score="1" ViewCount="86" Body="&lt;p&gt;Can an algorithm be derived to classify digital images according to how they were generated, i.e. the classes would be:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Real-world photograph captured with an actual camera.&lt;/li&gt;&#xA;&lt;li&gt;A Computer-Generated realistic scene.&lt;/li&gt;&#xA;&lt;li&gt;A hand-drawn image or a painting.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Could perhaps a Machine Learning approach, geared towards analyzing statistics of the signal provide sufficient insight on the problem ?&#xA;In that case, is there any known implementation of such algorithm publicly available ?&lt;/p&gt;&#xA;" OwnerUserId="2865" LastEditorUserId="2828" LastEditDate="2016-03-14T05:19:00.283" LastActivityDate="2016-03-14T05:19:00.283" Title="Separating photos from other images algorithmically?" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="5" ClosedDate="2016-03-12T11:28:35.130" ContentLicense="CC BY-SA 3.0" />
  <row Id="2173" PostTypeId="2" ParentId="376" CreationDate="2016-03-12T00:10:18.600" Score="5" Body="&lt;p&gt;The motivation behind ambient occlusion (AO) in general is to approximate the way crevices and corners are often shadowed, because less indirect light bounces into them. An example from a photo of my office&amp;mdash;note the darkening along the edges where walls and ceiling meet. The room is lit only by the light coming in through the window and bouncing around.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1JZDi.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1JZDi.jpg&quot; alt=&quot;photo demonstrating AO-like effect in the corner of a room&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To accurately simulate this phenomenon, offline renderers use techniques like path tracing and photon mapping. For real-time purposes, we either precalculate it offline, or we approximate it somehow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Screen-space ambient occlusion (SSAO) is based on the observation that you can detect corners and crevices by looking at the depth buffer (and possibly also the normal vectors) of a rendered image, and so you can calculate approximate AO as a post-pass. The depth buffer is a coarse representation of the geometry in the scene, so by sampling depth buffer values in the neighborhood of a target pixel, you can get an idea of the shape of the surrounding geometry, and make a guess how darkened by AO it should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qFOoX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qFOoX.png&quot; alt=&quot;diagram of how depth buffer represents geometry, from Bavoil and Sainz (2008)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This diagram, from &lt;a href=&quot;http://developer.download.nvidia.com/presentations/2008/SIGGRAPH/HBAO_SIG08b.pdf&quot; rel=&quot;noreferrer&quot;&gt;Bavoil and Sainz (2008)&lt;/a&gt;, shows how depth buffer values, interpreted as a heightfield of sorts, represent a discretized version of some geometry. In calculating SSAO for the center pixel, you'd look at the depth values of the surrounding pixels and plug them into some formula, designed to produce a darker value when the geometry is more concave (like that in the diagram), and a lighter value when the geometry is flat or convex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula that the depth values go into is called the &quot;kernel&quot; by analogy with &lt;a href=&quot;https://en.wikipedia.org/wiki/Kernel_%28image_processing%29&quot; rel=&quot;noreferrer&quot;&gt;filter kernels&lt;/a&gt; used for blurs, edge detection and suchlike. However, SSAO is more complicated than just a linear convolution of the depth values. The devil is in the details. The distribution of samples, and the formula processing them to generate the occlusion value, has been the subject of much research over the last decade, trying to improve the realism and reduce artifacts while maintaining good performance.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-12T00:10:18.600" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2174" PostTypeId="2" ParentId="2172" CreationDate="2016-03-12T00:13:16.267" Score="0" Body="&lt;p&gt;Difficulty depends on what you really want to classify, i.e. what exactly your data base of images is made ok.&#xA;For simple hand-drawn or computer art, I would think of just looking the color histogram (but for complex art with gradients; but still these gradients are likely to induce a very smooth colormap).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the other extreme, distinguishing realistic computer graphics image from reality is probably impossible.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-03-12T00:13:16.267" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2175" PostTypeId="2" ParentId="1963" CreationDate="2016-03-12T02:40:28.083" Score="6" Body="&lt;p&gt;In order to ensure that the pattern shapes are always either wholly present or absent, never cut off, it's necessary to ensure that the same &lt;code&gt;p&lt;/code&gt; value is used for all texels within the shape. In your example of circles, all the texels in a given circle need to agree on &lt;code&gt;p&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume that you have some way of evaluating &lt;code&gt;p&lt;/code&gt; at a given point on the surface (whether it is looked up from a texture or calculated from some function). Then one way to ensure a group of texels all get the same &lt;code&gt;p&lt;/code&gt; value is to ensure they all look it up from the same point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The UVs of this evaluation point could be stored in extra channels of the pattern texture. For instance, you could have the red and green channels store the UV coordinates at which to evaluate &lt;code&gt;p&lt;/code&gt;, the blue channel store the threshold at which to turn on that pattern element, and the alpha store the antialiased gray level of the pattern to display. The UV+threshold data could also be in a separate, secondary texture if desired.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To generate this UV+threshold texture, starting from an input pattern texture, you could programmatically find connected components (e.g. by searching for black pixels and flood-filling). Set the evaluation point for all texels in each component to the UV of the component's center, and generate a random threshold for it. Then, when rendering, use a pixel shader that first samples this texture, then looks up &lt;code&gt;p&lt;/code&gt; at the given evaluation point and compares it to the given threshold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That way, each pattern shape will see a uniform &lt;code&gt;p&lt;/code&gt; value and threshold, and will either turn on or turn off fully. As &lt;code&gt;p&lt;/code&gt; increases, more of the shapes will pass their threshold and appear, giving the impression of a continuously varying density.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-12T02:40:28.083" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2176" PostTypeId="2" ParentId="2163" CreationDate="2016-03-12T20:11:20.327" Score="4" Body="&lt;p&gt;What you are looking for is a way to get access to individual pixels in an image, in a way that you can modify those pixels with CPU code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have that you'll want to find software rendering / software rasterization methods.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A great place to start would be reading up in the various bresenham algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a lot of info out there on that. Here is one article for instance:&#xA;&lt;a href=&quot;http://blog.demofox.org/2015/01/17/bresenhams-drawing-algorithms/&quot; rel=&quot;nofollow&quot;&gt;http://blog.demofox.org/2015/01/17/bresenhams-drawing-algorithms/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-03-12T20:11:20.327" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2177" PostTypeId="2" ParentId="2170" CreationDate="2016-03-13T08:09:05.523" Score="3" Body="&lt;p&gt;Given that you want to test for intersection against rays with many different starting points and directions, it's worth investigating raytracing-style acceleration structures, such as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume_hierarchy&quot; rel=&quot;nofollow noreferrer&quot;&gt;bounding volume hierarchy (BVH)&lt;/a&gt;. In 2D, this would look like a tree of axis-aligned bounding boxes that divide up the space. Each leaf node of this tree would store a reference to a small list of nearby segments of the polyline, as well as a bounding box that contains them. Higher nodes would store a bounding box that contains all their children.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a ton of material on BVH construction and traversal out there, so I'd recommend doing a few searches and reading up. It's not too difficult to implement a top-down construction method, by starting with the bounding box of the whole polyline and recursive splitting. Then, to use it for acceleration, when you do a ray query you can find which BVH nodes the ray touches and test only the segments in those nodes for intersections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, all that being said, I'd like to propose a different approach to your original problem of working with contour lines. It seems to me that this is a place where &lt;a href=&quot;https://en.wikipedia.org/wiki/Delaunay_triangulation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Delaunay triangulation&lt;/a&gt; can probably be very helpful. It basically constructs a triangle mesh that connects a set of input vertices and edges. For example, here is a contour map I found on the internet:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nEET2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nEET2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And now here it is with a constrained Delaunay triangulation, calculating using &lt;a href=&quot;https://www.cs.cmu.edu/~quake/triangle.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jonathan Shewchuk's &quot;Triangle&quot; program&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EElJb.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EElJb.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the triangulation gives you a lot of information about neighboring regions in the contour map, so I suspect that you could find a way to get what you want from it somehow. For instance, you could find all the triangles that touch the two contour lines you're interested in, and look at their edges, midpoints, and so on.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-13T08:09:05.523" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2178" PostTypeId="1" AcceptedAnswerId="2191" CreationDate="2016-03-13T11:40:41.090" Score="3" ViewCount="558" Body="&lt;p&gt;I was trying to draw a plane and cubes in a framebuffer but nothing is drawing in that framebuffer besides clearing it with a color.&#xA;Here's the code...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//C++ Headers&#xA;#include&amp;lt;cassert&amp;gt;&#xA;&#xA;//Third party Headers&#xA;#include&amp;lt;GL/glew.h&amp;gt;&#xA;#include&amp;lt;GLFW/glfw3.h&amp;gt;&#xA;#include&amp;lt;SOIL.h&amp;gt;&#xA;&#xA;//My Headers&#xA;#include&quot;SLMath/SLMath.hpp&quot;&#xA;#include&quot;GLOBALS.h&quot;&#xA;&#xA;&#xA;//Author Headers&#xA;#include&quot;Shader.h&quot;&#xA;#include&quot;Texture.h&quot;&#xA;&#xA;&#xA;//linking libraries&#xA;&#xA;#pragma comment(lib,&quot;OpenGL32.lib&quot;)&#xA;#pragma comment(lib,&quot;glfw3.lib&quot;)&#xA;#pragma comment(lib,&quot;glew32.lib&quot;)&#xA;#pragma comment(lib,&quot;SOIL.lib&quot;)&#xA;&#xA;&#xA;void main()&#xA;{&#xA;glfwInit();&#xA;glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);&#xA;glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;glfwWindowHint(GLFW_SAMPLES,4);&#xA;&#xA;GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, &quot;fUNKY CUBE&quot;, 0, 0);&#xA;glfwMakeContextCurrent(window);&#xA;&#xA;glewExperimental = GL_TRUE;&#xA;glewInit();&#xA;&#xA;glfwSetKeyCallback(window, keyCallback);&#xA;&#xA;assert(glGetError()!=GL_NO_ERROR);&#xA;&#xA;glGenVertexArrays(1,&amp;amp;VAOplane);&#xA;glGenVertexArrays(1,&amp;amp;VAOcube);&#xA;glGenVertexArrays(1,&amp;amp;VAOquad);&#xA;glGenBuffers(1,&amp;amp;VBOplane);&#xA;glGenBuffers(1,&amp;amp;VBOcube);&#xA;glGenBuffers(1, &amp;amp;VBOquad);&#xA;&#xA;glBindBuffer(GL_ARRAY_BUFFER,VBOplane);&#xA;glBufferData(GL_ARRAY_BUFFER,sizeof(plane),plane,GL_STATIC_DRAW);&#xA;&#xA;glBindBuffer(GL_ARRAY_BUFFER,VBOcube);&#xA;glBufferData(GL_ARRAY_BUFFER,sizeof(cube),cube,GL_STATIC_DRAW);&#xA;&#xA;glBindBuffer(GL_ARRAY_BUFFER,VBOquad);&#xA;glBufferData(GL_ARRAY_BUFFER,sizeof(quad),quad,GL_STATIC_DRAW);&#xA;&#xA;glBindVertexArray(VAOplane);&#xA;{&#xA;    glBindBuffer(GL_ARRAY_BUFFER,VBOplane);&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(GLvoid*)(0));&#xA;&#xA;    glEnableVertexAttribArray(1);&#xA;    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*5,(GLvoid*)(sizeof(GLfloat)*3));&#xA;}&#xA;glBindVertexArray(0);&#xA;&#xA;&#xA;glBindVertexArray(VAOcube);&#xA;{&#xA;    glBindBuffer(GL_ARRAY_BUFFER,VBOcube);&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*8,(GLvoid*)(0));&#xA;&#xA;    glEnableVertexAttribArray(1);&#xA;    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GLfloat)*8,(GLvoid*)(sizeof(GLfloat)*6));&#xA;}&#xA;glBindVertexArray(0);&#xA;&#xA;glBindVertexArray(VAOquad);&#xA;{&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBOquad);&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (GLvoid*)(0));&#xA;&#xA;    glEnableVertexAttribArray(1);&#xA;    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4, (GLvoid*)(sizeof(GLfloat) * 2));&#xA;}&#xA;glBindVertexArray(0);&#xA;&#xA;&#xA;&#xA;&#xA;/*Setting up framebuffer*/&#xA;&#xA;GLuint fbo;&#xA;glGenFramebuffers(1,&amp;amp;fbo);&#xA;glBindFramebuffer(GL_FRAMEBUFFER,fbo);&#xA;&#xA;//Our color attachement&#xA;GLuint texColorBuffer;&#xA;glGenTextures(1,&amp;amp;texColorBuffer);&#xA;glBindTexture(GL_TEXTURE_2D,texColorBuffer);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);&#xA;glBindTexture(GL_TEXTURE_2D,0);&#xA;&#xA;&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,texColorBuffer,0);&#xA;&#xA;//our depth attachment&#xA;GLuint depthRenderbuffer;&#xA;glGenRenderbuffers(1,&amp;amp;depthRenderbuffer);&#xA;glBindRenderbuffer(GL_RENDERBUFFER,depthRenderbuffer);&#xA;glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, WIDTH, HEIGHT);&#xA;glBindRenderbuffer(GL_RENDERBUFFER,0);&#xA;&#xA;&#xA;glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,depthRenderbuffer);&#xA;&#xA;if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)&#xA;    assert(0);&#xA;&#xA;&#xA;glBindFramebuffer(GL_FRAMEBUFFER,0);&#xA;&#xA;glViewport(0,0,WIDTH,HEIGHT);&#xA;&#xA;Texture floorTex(&quot;textures/floortexture1.jpg&quot;);&#xA;Texture cubeTex(&quot;textures/cubetexture1.jpg&quot;);&#xA;&#xA;Shader shader(&quot;vs.txt&quot;,&quot;fs.txt&quot;);&#xA;Shader shader2(&quot;vs2.txt&quot;,&quot;fs2.txt&quot;);&#xA;&#xA;//glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);&#xA;&#xA;while(!glfwWindowShouldClose(window))&#xA;{&#xA;    glfwPollEvents();&#xA;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, fbo);&#xA;&#xA;&#xA;    glClearColor(0.1,0.0,0.0,0.0);&#xA;    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;    glEnable(GL_DEPTH_TEST);&#xA;    //float radius = 5.0f;&#xA;    //cameraPos.z = cos(SLMath::radians(glfwGetTime()*30.0f))*radius;&#xA;    //cameraPos.x = sin(SLMath::radians(glfwGetTime()*30.0f))*radius;&#xA;&#xA;    SLMath::Mat4 projection;&#xA;    SLMath::Mat4 view;&#xA;    SLMath::Mat4 model;&#xA;&#xA;    GLint projLoc = glGetUniformLocation(shader.program,&quot;projection&quot;);&#xA;    GLint viewLoc = glGetUniformLocation(shader.program,&quot;view&quot;);&#xA;    GLint modelLoc = glGetUniformLocation(shader.program,&quot;model&quot;);&#xA;&#xA;    SLMath::perspective(projection,45.0f,(float)WIDTH/(float)HEIGHT,0.1f,100.0f);&#xA;    SLMath::lookAt(view,cameraPos,cameraDir,cameraUp);&#xA;&#xA;    glUniformMatrix4fv(projLoc,1,GL_FALSE,projection.valuePtr());&#xA;    glUniformMatrix4fv(viewLoc,1,GL_FALSE,view.valuePtr());&#xA;    glUniformMatrix4fv(modelLoc,1,GL_FALSE,model.valuePtr());&#xA;&#xA;&#xA;    floorTex.bind();&#xA;    shader.Use();&#xA;    glBindVertexArray(VAOplane);&#xA;    glDrawArrays(GL_TRIANGLES,0,6);&#xA;    glBindVertexArray(0);&#xA;&#xA;    cubeTex.bind();&#xA;&#xA;    for(int i=0;i&amp;lt;3;i++)&#xA;    {&#xA;        model.reset();&#xA;        SLMath::translate(model,cubePositions[i]);&#xA;        glUniformMatrix4fv(modelLoc,1,GL_FALSE,model.valuePtr());&#xA;&#xA;        glBindVertexArray(VAOcube);&#xA;        glDrawArrays(GL_TRIANGLES,0,36);&#xA;        glBindVertexArray(0);&#xA;&#xA;    }&#xA;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER,0);&#xA;&#xA;    glClearColor(1.0f,1.0f,1.0f,1.0);&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    glDisable(GL_DEPTH_TEST);&#xA;&#xA;    shader2.Use();&#xA;    glBindTexture(GL_TEXTURE_2D, texColorBuffer);&#xA;    glBindVertexArray(VAOquad);&#xA;    glDrawArrays(GL_TRIANGLES,0,6);&#xA;    glBindVertexArray(0);&#xA;&#xA;&#xA;&#xA;&#xA;    glfwSwapBuffers(window);&#xA;}&#xA;&#xA;&#xA;glDeleteBuffers(1, &amp;amp;VBOquad);&#xA;glDeleteBuffers(1, &amp;amp;VBOcube);&#xA;glDeleteBuffers(1,&amp;amp;VBOplane);&#xA;glDeleteVertexArrays(1, &amp;amp;VAOquad);&#xA;glDeleteVertexArrays(1, &amp;amp;VAOcube);&#xA;glDeleteVertexArrays(1,&amp;amp;VAOplane);&#xA;glfwDestroyWindow(window);&#xA;glfwTerminate();&#xA;exit(EXIT_SUCCESS);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am getting this...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cAx72.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cAx72.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;instead of this...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H3p6i.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H3p6i.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have checked my code several times....what is wrong??&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="2096" LastEditDate="2016-03-13T11:58:24.033" LastActivityDate="2016-03-16T16:01:20.923" Title="Clearing but not drawing objects" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2180" PostTypeId="1" AcceptedAnswerId="2181" CreationDate="2016-03-13T22:52:45.323" Score="5" ViewCount="247" Body="&lt;p&gt;I am a beginner in digital image processing and computer graphics. I would like to program a similar behavior than the Shadermap 3 normal editor (displacement layer more specifically).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As shown in this &lt;a href=&quot;https://youtu.be/NIHpBNnYYU8?t=34s&quot; rel=&quot;noreferrer&quot;&gt;Shadermap 3 demonstration video&lt;/a&gt;, the displacement brush allows the user to paint a &lt;strong&gt;displacement map (grayscale)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/sliKgEI.png&quot; alt=&quot;Shadermap 3&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The brush strokes produce shapes with a smooth value transitioning from the middle of the shape to its edge, in this case giving the shape a slightly curved profile. As it is also shown, the shape's profile can be fine-tuned with the brush curve editor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What combination of filters and/or algorithms could Shadermap 3 possibly use to convert a pixel blob or shape to displacement map with a given width and curve?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/C7o1bbM.png&quot; alt=&quot;Combination&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="2319" LastActivityDate="2016-03-14T02:55:34.097" Title="Converting raster shape/blob into displacement map" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;curve&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2181" PostTypeId="2" ParentId="2180" CreationDate="2016-03-14T02:55:34.097" Score="5" Body="&lt;p&gt;One way I can think of is to make a &quot;signed distance transform&quot; of the image where there is information for each pixel about how far the pixel is to the closest surface of the shape.  Since it's signed, youll be able to know if the pixel is inside or outside he shape, and by how much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using this knowledge, you could easily make a new image, where the pixel is black if the distance is greater than -10, else it is white.  That would make the shape shrink by 10 pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can use smoothstep or other curves to transition between black and white over a number of pixels, to soften it anti alias the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can make the distance transform by brute force, but another method would be to make a voronoi diagram first and then turn that into a distance transform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is lots of info out there on both voronoi diagrams as well as (signed) distance transforms but these two links will probably be helpful to get you started:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.demofox.org/2016/02/29/fast-voronoi-diagrams-and-distance-dield-textures-on-the-gpu-with-the-jump-flooding-algorithm/&quot;&gt;http://blog.demofox.org/2016/02/29/fast-voronoi-diagrams-and-distance-dield-textures-on-the-gpu-with-the-jump-flooding-algorithm/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.demofox.org/2016/03/02/actually-making-signed-distance-field-textures-with-jfa/&quot;&gt;http://blog.demofox.org/2016/03/02/actually-making-signed-distance-field-textures-with-jfa/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-03-14T02:55:34.097" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="2182" PostTypeId="2" ParentId="1963" CreationDate="2016-03-14T10:32:47.963" Score="0" Body="&lt;p&gt;Another thought is along these lines.  If you have a uniform point set defined on the plane and a mapping function from the plane to the target surface then the density function on the surface is how areas map from the plane surface to the target.  So an area preserving map would result in a uniform points on the target.&lt;/p&gt;&#xA;" OwnerUserId="2831" LastActivityDate="2016-03-14T10:32:47.963" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2183" PostTypeId="2" ParentId="2178" CreationDate="2016-03-14T18:22:33.197" Score="1" Body="&lt;p&gt;You would want to provide us with the implementation of the shaders you use, or at the very least the result of shader compilation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple typo in a shader obviously prevents compilation and therefore successful rasterization of the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, check your shader !&lt;/p&gt;&#xA;" OwnerUserId="2828" LastActivityDate="2016-03-14T18:22:33.197" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2184" PostTypeId="1" CreationDate="2016-03-14T18:38:52.403" Score="3" ViewCount="1062" Body="&lt;p&gt;I'm trying to achieve the same effect in OpenGL/GLSL as what Blender does when you add a texture, set to &quot;Reflection&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This ultimately is a way to fake specularity, or &quot;metallicness&quot; if I get it right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I followed this tutorial (Mid-page, &quot;Sphere Mapping&quot; section):&#xA;&lt;a href=&quot;http://www.ozone3d.net/tutorials/glsl_texturing_p04.php&quot; rel=&quot;nofollow&quot;&gt;http://www.ozone3d.net/tutorials/glsl_texturing_p04.php&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the problem(some serious artifacts):&#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=hx66_xWhVu4&amp;amp;feature=youtu.be&quot; rel=&quot;nofollow&quot;&gt;https://www.youtube.com/watch?v=hx66_xWhVu4&amp;amp;feature=youtu.be&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Everything's happening at the bottom of the Vertex Sahder:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;layout(location = 0) in vec3 vertexPosition_modelspace;&#xA;layout(location = 1) in vec2 vertexUV;&#xA;layout(location = 2) in vec3 vertexNormal_modelspace;&#xA;layout(location = 3) in vec3 vertexTangent_modelspace;&#xA;&#xA;out vec2 uv;&#xA;out vec3 toLightVector[4];&#xA;out vec3 toCameraVector;&#xA;out float fog_Visibility;&#xA;&#xA;uniform mat4 FTM;&#xA;uniform mat4 P;&#xA;uniform mat4 V;&#xA;uniform vec3 LP[4];&#xA;&#xA;const float fog_Density = 0.2;&#xA;const float fog_Gradient = 0.9;&#xA;&#xA;void main(){&#xA;&#xA;    vec4 worldPosition = FTM * vec4(vertexPosition_modelspace, 1.0);&#xA;    uv = vertexUV;&#xA;&#xA;    vec3 surfaceNormal = (FTM * vec4(vertexNormal_modelspace, 0.0)).xyz;&#xA;&#xA;    vec3 norm = normalize(surfaceNormal);&#xA;    vec3 tang = normalize((FTM * vec4(vertexTangent_modelspace, 0.0)).xyz);&#xA;    vec3 bitang = normalize(cross(norm, tang));&#xA;&#xA;    mat3 toTangentSpace = mat3(tang.x, bitang.x, norm.x, tang.y, bitang.y, norm.y, tang.z, bitang.z, norm.z);&#xA;&#xA;    for (int i = 0; i &amp;lt; 4; i++) {&#xA;        toLightVector[i] = toTangentSpace * (LP[i] - worldPosition.xyz);&#xA;    }&#xA;&#xA;    toCameraVector = toTangentSpace * ((inverse(V) * vec4(0.0, 0.0, 0.0, 1.0)).xyz - worldPosition.xyz);&#xA;&#xA;    vec4 positionRelativeToCam = V * worldPosition;&#xA;    gl_Position = P * positionRelativeToCam;&#xA;&#xA;    // Fog&#xA;    float fog_Distance = length(positionRelativeToCam.xyz);&#xA;    fog_Visibility = exp(-pow((fog_Distance * fog_Density), fog_Gradient));&#xA;    fog_Visibility = clamp(fog_Visibility, 0.0, 1.0);&#xA;&#xA;    // Reflection Map&#xA;    vec3 u = normalize(toCameraVector);&#xA;    vec3 r = reflect(u, norm);&#xA;    float m = 2.0 * sqrt(r.x*r.x + r.y*r.y + (r.z + 1.0)*(r.z + 1.0));&#xA;&#xA;    gl_TexCoord[0].s = r.x / m + 0.5;&#xA;    gl_TexCoord[0].t = r.y / m + 0.5;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And in the Fragment Shader, all I do is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;out_color = texture(reflectionSampler, gl_TexCoord[0].st);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The reflection map seems to do it's thing similarly to the way it's seen in Blender, but not quite.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to be able to do this without calculating lights. Thats how Blender does it, it works Shadeless mode so all it should take is the camera's vector...&lt;/p&gt;&#xA;" OwnerUserId="2879" LastActivityDate="2016-04-14T10:33:20.317" Title="Guidance with Sphere-Map calculation in GLSL" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2185" PostTypeId="2" ParentId="2184" CreationDate="2016-03-14T21:29:39.643" Score="3" Body="&lt;p&gt;You probably need to calculate the reflection vector per pixel, not per vertex. The calculation is non-linear, so doing it per vertex and interpolating will not give good results unless the model is finely tesselated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Send &lt;code&gt;norm&lt;/code&gt; and &lt;code&gt;toCameraVector&lt;/code&gt; down to the pixel shader, normalize them both and move all your calculations under &lt;code&gt;// Reflection Map&lt;/code&gt; to the pixel shader. That should give you some better results.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-14T21:29:39.643" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2187" PostTypeId="1" CreationDate="2016-03-15T05:20:10.700" Score="5" ViewCount="98" Body="&lt;p&gt;Color spaces issues are such a pain, especially when you create color data at the middle of the chain, and a pile of libs and apps separate this to the display... Here I only worry about gamma transform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://shadertoy.com&quot;&gt;Shadertoy&lt;/a&gt; addicts are coding in this web site webGLSL shaders, which in my case are rendered through google chrome on linux ubuntu and displayed on a calibrated monitor. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is one layer already doing the gamma transform, or should I do pow(color,1./2.2) at the end of my rendering ?&#xA;For me (linux,etc), it seems I must do it. Is it also true on windows, mac OS, whether Angle or Native OpenGL is used (windows), whatever the browser ?&#xA;The point is that often shaders look ok on windows and very dark on linux, for instance, both people being sure of their settings and qualibration.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-03-28T08:47:03.953" Title="gamma transform in webGLSL: when already done or yet to be done?" Tags="&lt;glsl&gt;&lt;webgl&gt;&lt;gamma&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2188" PostTypeId="1" CreationDate="2016-03-15T10:18:23.130" Score="4" ViewCount="197" Body="&lt;p&gt;I am trying to model an organic object using OpenSCAD. However this will need to be ported over to older software. This restricts the primitives I can use (only cone, cylinder, torus, sphere and cubes) and the operations I can perform (difference, union, intersection, scaling and transformation). However modeling with these restrictions gives very unnatural looking objects. I need to somehow implement by hand, using only these primitives/operations the hull and minkowski operations to give my models a more organic look. Does anybody know how this could be done?&lt;/p&gt;&#xA;" OwnerUserId="2858" LastActivityDate="2016-03-15T10:18:23.130" Title="OpenSCAD Hull/Minkowski function by hand?" Tags="&lt;transformations&gt;&lt;3d&gt;&lt;model&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="2189" PostTypeId="1" CreationDate="2016-03-15T13:40:03.177" Score="5" ViewCount="742" Body="&lt;p&gt;I am doing exercises from the OpenGL SuperBible 6th Ed. I have managed to set up rendering into a framebuffer texture and then rendering from that texture to a cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But for some reason, &lt;strong&gt;when the texture gets applied to the cube, it is rendered incorrectly. I was expecting to see an entire rotating cube on a green background on each face of the main cube, but instead the faces have a texture applied as if split in half.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a screenshot of my current situation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KCtjJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KCtjJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've spent a lot of time trying to fix this. I mean, the last 5 hours or so. I rewrote most of the code once and it fixed some of my previous erros, but now I'm stuck with this last part. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used the SB sources as reference (&lt;a href=&quot;https://github.com/openglsuperbible/sb6code/blob/master/src/basicfbo/basicfbo.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/openglsuperbible/sb6code/blob/master/src/basicfbo/basicfbo.cpp&lt;/a&gt;), but I can't find the reason why it looks like this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also read this &lt;a href=&quot;https://www.opengl.org/wiki/Framebuffer_Object_Examples&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.opengl.org/wiki/Framebuffer_Object_Examples&lt;/a&gt; but can't find a solution there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What did I miss?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my current code (the most important App class which does most of the work):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &quot;config.h&quot;&#xA;&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;#include &amp;lt;GL/freeglut.h&amp;gt;&#xA;#include &amp;lt;glm/glm.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/matrix_transform.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/type_ptr.hpp&amp;gt;&#xA;&#xA;#include &quot;App.h&quot;&#xA;#include &quot;GLSLProgram.h&quot;&#xA;&#xA;void App::renderToFramebuffer() {&#xA;    float clearColor[] = { 0.0f, 0.5f, 0.0f, 1.0f };&#xA;    float one = 1.0f;&#xA;&#xA;    m_rotation += 1.0f;&#xA;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);&#xA;&#xA;    glViewport(0, 0, 512, 512);&#xA;    glClearBufferfv(GL_COLOR, 0, clearColor);&#xA;    glClearBufferfv(GL_DEPTH, 0, &amp;amp;one);&#xA;&#xA;    glm::mat4 modelView = glm::translate(glm::mat4(), glm::vec3(-1.0f, -0.0f, -5.0f));&#xA;    glm::vec3 rotationY = glm::vec3(0.0f, 1.0f, 0.0f);&#xA;    modelView = glm::rotate(modelView, glm::radians(45.0f), rotationY);&#xA;    glm::vec3 rotationX = glm::vec3(1.0f, 0.0f, 0.0f);&#xA;    modelView = glm::rotate(modelView, glm::radians(m_rotation), rotationX);&#xA;&#xA;    glm::mat4 projectionMatrix = glm::perspective(50.0f, 1.0f, 1.0f, 1000.0f);&#xA;&#xA;    m_shaderNotTextured-&amp;gt;start();&#xA;    m_shaderNotTextured-&amp;gt;setMatrix(projectionMatrix, GL_PROJECTION_MATRIX);&#xA;    m_shaderNotTextured-&amp;gt;setMatrix(modelView, GL_MODELVIEW_MATRIX);&#xA;&#xA;    glDrawArrays(GL_TRIANGLES, 0, 36);&#xA;&#xA;    m_shaderNotTextured-&amp;gt;stop();&#xA;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;}&#xA;&#xA;void App::renderToScreen() {&#xA;    glBindVertexArray(m_VAO);&#xA;&#xA;    glViewport(0, 0, SCREEN_X, SCREEN_Y);&#xA;    glClearBufferfv(GL_COLOR, 0, glm::value_ptr(m_clearColor));&#xA;    glClearBufferfv(GL_DEPTH, 0, &amp;amp;m_depthBufferDefault);&#xA;&#xA;    glBindTexture(GL_TEXTURE_2D, m_TBO);&#xA;&#xA;    glm::mat4 modelView = glm::translate(glm::mat4(), glm::vec3(0.0f, 0.0f, -5.0f));&#xA;    glm::vec3 rotation = glm::vec3(0.0f, 1.0f, 0.0f);&#xA;    modelView = glm::rotate(modelView, glm::radians(45.0f), rotation);&#xA;    glm::vec3 rotationX = glm::vec3(1.0f, 0.0f, 0.0f);&#xA;    modelView = glm::rotate(modelView, glm::radians(45.0f), rotationX);&#xA;&#xA;    m_shaderTextured-&amp;gt;start();&#xA;    m_shaderTextured-&amp;gt;setMatrix(m_projectionMatrix, GL_PROJECTION_MATRIX);&#xA;    m_shaderTextured-&amp;gt;setMatrix(modelView, GL_MODELVIEW_MATRIX);&#xA;&#xA;    glDrawArrays(GL_TRIANGLES, 0, 36);&#xA;&#xA;    glBindTexture(GL_TEXTURE_2D, 0);&#xA;&#xA;    m_shaderTextured-&amp;gt;stop();&#xA;}&#xA;&#xA;void App::render() {&#xA;    renderToFramebuffer();&#xA;    renderToScreen();&#xA;    glutSwapBuffers();&#xA;}&#xA;&#xA;App::App() {&#xA;    glEnable(GL_TEXTURE_2D);&#xA;&#xA;    glEnable(GL_CULL_FACE);&#xA;    glEnable(GL_DEPTH_TEST);&#xA;    glDepthFunc(GL_LEQUAL);&#xA;&#xA;    m_clearColor = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);&#xA;    m_depthBufferDefault = 1.0f;&#xA;    m_projectionMatrix = glm::perspective(50.0f, (float) SCREEN_X / (float) SCREEN_Y, 1.0f, 1000.0f);&#xA;&#xA;    m_shaderNotTextured = new GLSLProgram();&#xA;    m_shaderNotTextured-&amp;gt;addVertexShader(&quot;shaders/notex.vs.glsl&quot;);&#xA;    m_shaderNotTextured-&amp;gt;addFragmentShader(&quot;shaders/notex.fs.glsl&quot;);&#xA;    m_shaderNotTextured-&amp;gt;compile();&#xA;&#xA;    m_shaderTextured = new GLSLProgram();&#xA;    m_shaderTextured-&amp;gt;addVertexShader(&quot;shaders/tex.vs.glsl&quot;);&#xA;    m_shaderTextured-&amp;gt;addFragmentShader(&quot;shaders/tex.fs.glsl&quot;);&#xA;    m_shaderTextured-&amp;gt;compile();&#xA;&#xA;    glGenVertexArrays(1, &amp;amp;m_VAO);&#xA;    glGenBuffers(NUM_BUFFERS, m_buffers);&#xA;&#xA;    glGenTextures(1, &amp;amp;m_TBO);&#xA;    glGenTextures(1, &amp;amp;m_TDBO);&#xA;&#xA;    glGenFramebuffers(1, &amp;amp;m_FBO);&#xA;&#xA;    glBindVertexArray(m_VAO);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, m_buffers[VBO]);&#xA;        static const GLfloat vertex_data[] =&#xA;        {&#xA;             // Position                 Tex Coord&#xA;            -0.25f, -0.25f,  0.25f,      0.0f, 1.0f,&#xA;            -0.25f, -0.25f, -0.25f,      0.0f, 0.0f,&#xA;             0.25f, -0.25f, -0.25f,      1.0f, 0.0f,&#xA;&#xA;             0.25f, -0.25f, -0.25f,      1.0f, 0.0f,&#xA;             0.25f, -0.25f,  0.25f,      1.0f, 1.0f,&#xA;            -0.25f, -0.25f,  0.25f,      0.0f, 1.0f,&#xA;&#xA;             0.25f, -0.25f, -0.25f,      0.0f, 0.0f,&#xA;             0.25f,  0.25f, -0.25f,      1.0f, 0.0f,&#xA;             0.25f, -0.25f,  0.25f,      0.0f, 1.0f,&#xA;&#xA;             0.25f,  0.25f, -0.25f,      1.0f, 0.0f,&#xA;             0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;             0.25f, -0.25f,  0.25f,      0.0f, 1.0f,&#xA;&#xA;             0.25f,  0.25f, -0.25f,      1.0f, 0.0f,&#xA;            -0.25f,  0.25f, -0.25f,      0.0f, 0.0f,&#xA;             0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;&#xA;            -0.25f,  0.25f, -0.25f,      0.0f, 0.0f,&#xA;            -0.25f,  0.25f,  0.25f,      0.0f, 1.0f,&#xA;             0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;&#xA;            -0.25f,  0.25f, -0.25f,      1.0f, 0.0f,&#xA;            -0.25f, -0.25f, -0.25f,      0.0f, 0.0f,&#xA;            -0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;&#xA;            -0.25f, -0.25f, -0.25f,      0.0f, 0.0f,&#xA;            -0.25f, -0.25f,  0.25f,      0.0f, 1.0f,&#xA;            -0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;&#xA;            -0.25f,  0.25f, -0.25f,      0.0f, 1.0f,&#xA;             0.25f,  0.25f, -0.25f,      1.0f, 1.0f,&#xA;             0.25f, -0.25f, -0.25f,      1.0f, 0.0f,&#xA;&#xA;             0.25f, -0.25f, -0.25f,      1.0f, 0.0f,&#xA;            -0.25f, -0.25f, -0.25f,      0.0f, 0.0f,&#xA;            -0.25f,  0.25f, -0.25f,      0.0f, 1.0f,&#xA;&#xA;            -0.25f, -0.25f,  0.25f,      0.0f, 0.0f,&#xA;             0.25f, -0.25f,  0.25f,      1.0f, 0.0f,&#xA;             0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;&#xA;             0.25f,  0.25f,  0.25f,      1.0f, 1.0f,&#xA;            -0.25f,  0.25f,  0.25f,      0.0f, 1.0f,&#xA;            -0.25f, -0.25f,  0.25f,      0.0f, 0.0f,&#xA;        };&#xA;&#xA;        glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW);&#xA;&#xA;        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);&#xA;        glEnableVertexAttribArray(0);&#xA;&#xA;        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid *) (2 * sizeof(GLfloat)));&#xA;        glEnableVertexAttribArray(1);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, m_FBO);&#xA;&#xA;        glBindTexture(GL_TEXTURE_2D, m_TBO);&#xA;            glTexStorage2D(GL_TEXTURE_2D, 9, GL_RGBA8, 512, 512);&#xA;&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;&#xA;        glBindTexture(GL_TEXTURE_2D, m_TDBO);&#xA;            glTexStorage2D(GL_TEXTURE_2D, 9, GL_DEPTH_COMPONENT32F, 512, 512);&#xA;&#xA;        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_TBO, 0);&#xA;        glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, m_TDBO, 0);&#xA;&#xA;        GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };&#xA;        glDrawBuffers(1, drawBuffers);&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_buffers[IBO]);&#xA;&#xA;        static const GLushort vertex_indices[] =&#xA;        {&#xA;            0, 1, 2,&#xA;            2, 1, 3,&#xA;            2, 3, 4,&#xA;            4, 3, 5,&#xA;            4, 5, 6,&#xA;            6, 5, 7,&#xA;            6, 7, 0,&#xA;            0, 7, 1,&#xA;            6, 0, 2,&#xA;            2, 4, 6,&#xA;            7, 5, 3,&#xA;            7, 3, 1&#xA;        };&#xA;&#xA;        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(vertex_indices), vertex_indices, GL_STATIC_DRAW);&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);&#xA;&#xA;}&#xA;&#xA;App::~App() {&#xA;    delete m_shaderNotTextured;&#xA;    delete m_shaderTextured;&#xA;    glDeleteBuffers(NUM_BUFFERS, m_buffers);&#xA;}&#xA;&#xA;&#xA;void App::update() {&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also, I have no idea why in SB6 code they are creating an array of indices and then not using it. I copied the part of the code with vertex data, initialized everything and then realized the indices aren't used. But I didn't remove them yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: and here is the framebuffer cube colored to show more of how it is being displayed (you may notice how on most faces the texture is applied in halves):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BvEAn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BvEAn.png&quot; alt=&quot;the cube when colored&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit2: and this is what I get when I don't bind the framebuffer and instead draw to screen after changing cubes to quads&lt;/strong&gt; - so the image texture is being drawn correctly to the FB:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SVXWI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SVXWI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am thinking - maybe this has something to do with the size of the texture or the size of viewport when rendering? I'm still completely baffled by this...&lt;/p&gt;&#xA;" OwnerUserId="2508" LastEditorUserId="2508" LastEditDate="2016-03-19T14:53:34.067" LastActivityDate="2016-03-19T14:53:34.067" Title="Drawing to framebuffer texture - texture then split in half" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2190" PostTypeId="1" AcceptedAnswerId="2194" CreationDate="2016-03-16T04:00:38.943" Score="6" ViewCount="311" Body="&lt;p&gt;Different BRDFs are usually used to compute diffuse and specular reflection.&lt;br&gt;&#xA;Some of the most often used include for example the Lambert BRDF for diffuse reflection and the Cook-Torrance BRDF for specular reflection.&lt;br&gt;&#xA;Cook-Torrance BRDFs are parametrized by the surface roughness: the rougher the surface, the &quot;blurrier&quot; the reflection.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;From a conceptual point of view, should we consider that for an extremely rough surface, the specular reflection must look like a diffuse reflection? Can there be a continuity between both components of the reflection?&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="127" LastEditDate="2016-03-18T15:01:56.223" LastActivityDate="2016-03-19T04:42:47.883" Title="Should not specular reflection on a rough surface be similar to diffuse reflection?" Tags="&lt;reflection&gt;&lt;specular&gt;&lt;diffuse&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2191" PostTypeId="2" ParentId="2178" CreationDate="2016-03-16T16:01:20.923" Score="1" Body="&lt;p&gt;Answering my own question!&#xA;The reason for this behaviour is that I forgot to activate shader program before passing matrices to it!&lt;/p&gt;&#xA;" OwnerUserId="2096" LastActivityDate="2016-03-16T16:01:20.923" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2192" PostTypeId="1" AcceptedAnswerId="2193" CreationDate="2016-03-16T16:05:17.363" Score="12" ViewCount="7601" Body="&lt;p&gt;I know how shadow mapping works but I am not getting the cause of shadow acne!&#xA;Can anyone tell me cause of shadow acne in a simple way and how is it related to depth map resolution? &lt;/p&gt;&#xA;" OwnerUserId="2096" LastActivityDate="2016-03-17T13:44:31.807" Title="Cause of shadow acne" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;rendering&gt;&lt;shader&gt;&lt;transformations&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2193" PostTypeId="2" ParentId="2192" CreationDate="2016-03-16T18:49:36.300" Score="13" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/o7MUP.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o7MUP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: A bad case of shadow acne. (Synthetic and a bit exaggerated)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shadow acne is caused by the discrete nature of the shadow map. A shadow map is composed of samples, a surface is continuous. Thus, there can be a spot on the surface where the discrete surface is further than the sample. The problem does persist even if you multi sample, but you can sample smarter in ways that can nearly eliminate this at significant cost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5HSkc.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5HSkc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2:&lt;/strong&gt; A side cutaway of a shadow function and its discrete samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The canonical way to solve this is to offset the shadow map slightly so the object no longer self shadows itself. This offset is called a bias. One can use more smart offsets than just a fixed value but a fixed value works quite well and has minimal overhead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SyZdy.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SyZdy.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 3:&lt;/strong&gt; Shadow function biased (offset) forward.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-03-16T20:05:24.677" LastActivityDate="2016-03-16T20:05:24.677" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="2194" PostTypeId="2" ParentId="2190" CreationDate="2016-03-17T08:34:35.613" Score="9" Body="&lt;p&gt;No, because the underlying physics is not the same, nor the lobe shape - not to speak of their parameters such as color and Fresnel term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specular is really true surface interaction with the interface material/air, so it has Fresnel modulation and the internal medium has no influence on colors. But the surface condition strongly influence the reflectance, of course. Think of it as the reflections on ocean surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Diffuse is due to the subsurface scattering, light entering the medium, and thus gains the color characteristic and loose directionality. Think of it as the green color of the water turbidity. If depth of penetration is less than pixel size CG people don't call it &quot;subsurface&quot; but the physics is the same. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course diffuse input is what specular let pass, which is angle (and polarization) dependant. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Beside, there exist transparent medium with internal interfaces (e.g. thin shells), so case exists were light goes inside but still acts specularely (or even wavely) and not diffusely. Oppositely, most plastics and paints/varnishs and biological medium are intrinsically transparent, but contain pigments (often based on a metal atom) that cause the opacity (diffusion or specular on these &quot;objects in the object&quot;). Think of them as the fishes in clear water :-) .&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2016-03-19T04:42:47.883" LastActivityDate="2016-03-19T04:42:47.883" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2197" PostTypeId="2" ParentId="2192" CreationDate="2016-03-17T13:44:31.807" Score="6" Body="&lt;p&gt;As an addition to the answer of joojaa:&#xA;Using a bias to offset the shadow function does indeed solve the problem with shadow acne, but it can introduce an additional problem: Peter Panning&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mdoX0.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mdoX0.png&quot; alt=&quot;Sample image that has Peter Panning&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you see in the picture on the left the shadow is disconnected from the shadow casting wall. This gives the impression that the geometry hovers over the ground (just like Peter Pan can hover, hence the name Peter Panning).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To solve this problem you have to use &quot;thick&quot; geometry that has a volume and then render the shadow map using the back-faces. If the offset is smaller than the thickness of the geometry there will be no Peter Panning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TwFxZ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TwFxZ.png&quot; alt=&quot;Scene with thick geometry and thereby no Peter Panning&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both images are taken from &lt;a href=&quot;http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/&quot; rel=&quot;noreferrer&quot;&gt;this tutorial&lt;/a&gt; where you can also learn more about how shadow mapping works, how shadow acne is created and solved and what Peter Panning is.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-03-17T13:44:31.807" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2198" PostTypeId="1" AcceptedAnswerId="2253" CreationDate="2016-03-17T16:15:53.137" Score="4" ViewCount="105" Body="&lt;p&gt;I have a set of closed loops on the surface of a non-self-intersecting triangle mesh, and I need to create inset versions of them on the surface of the mesh. In other words, I want to generate a &lt;a href=&quot;https://en.wikipedia.org/wiki/Straight_skeleton&quot; rel=&quot;noreferrer&quot;&gt;straight skeleton&lt;/a&gt; from them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Within each single triangle of the mesh, this algorithm should behave just like a 2D straight skeleton.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've found several tools for offsetting loops of edges in a mesh, or generating loops equidistant from a point on the mesh, but I need to be able to input arbitrary loops of my own and offset them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I ran through various corner cases by hand on some graph paper, and it seems to me the algorithm described by &lt;a href=&quot;http://www.dma.fi.upm.es/personal/mabellanas/tfcs/skeleton/html/documentacion/Straight%20Skeletons%20Implementation.pdf&quot; rel=&quot;noreferrer&quot;&gt;Felkel and Obdrzalek&lt;/a&gt; should be perfectly applicable, except the wavefront may at times have to switch between contracting and expanding when it encounters geometries that give it more space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This algorithm seems like it would be useful in several CAM applications, does anyone know of an existing implementation?&lt;/p&gt;&#xA;" OwnerUserId="2896" LastActivityDate="2016-03-30T18:15:13.220" Title="Can I run polygon insetting on the surface of a mesh?" Tags="&lt;geometry&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2201" PostTypeId="1" AcceptedAnswerId="2204" CreationDate="2016-03-18T09:08:55.750" Score="1" ViewCount="160" Body="&lt;p&gt;Given a 3D object in Computer graphics, whose surface is represented as a 3D triangular mesh (mesh of 3D triangle objects), I need to find the maximum continual Convex patches on the surface of the given 3D object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using OpenGl to render the graphics within a C++ program. What kind of methods or algorithms should I use to find the convex patches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have to apply different colors to the different convex patches on the object to signify the selection. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say I have a sphere then the whole sphere is one maximal convex patch. Any portion of the sphere surface will be a convex patch, by maximal I mean the maximum continuous convex patches that can be found. Well in the rendering, depending on the viewing angles, the maximal convex patches visible to the viewer will have to colored. I have to report all the convex patches, each patch being the maximal in that area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using &quot;maximal&quot; to mean a convex surface which is not a subset of a larger convex surface, rather than to mean the largest convex surface that exists in the triangle mesh. The patches need to be strictly convex (never flat).&lt;/p&gt;&#xA;" OwnerUserId="2898" LastEditorUserId="2898" LastEditDate="2016-04-03T08:45:59.447" LastActivityDate="2016-04-03T08:45:59.447" Title="maximal convex patching in Computer graphics" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;computational-geometry&gt;&lt;triangulation&gt;" AnswerCount="1" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="2204" PostTypeId="2" ParentId="2201" CreationDate="2016-03-20T03:54:01.847" Score="1" Body="&lt;p&gt;Start from any triangle. Traverse it's edge's and check that the angle between the two triangles is less than 180deg. If it is add it to the current selection and continue expanding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The check is actually really simple if you use vector geometry. Say A - B is the common edge with C on the selected side and D on the other. Then just check if &lt;code&gt;dot((D-B), cross((A-B), (C-B)) &amp;lt; 0&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Single triangle patches should be ruled out, as for us to determine convexity, it has to span across several triangles.&#xA;We have to keep sampling until we've tested everything.  When a convex patch continues further, it's size keeps on increasing by including the neighbouring triangles that satisfy convexity, until the patch reaches the maximum size it can attain.&lt;/p&gt;&#xA;" OwnerUserId="2898" LastEditorUserId="2898" LastEditDate="2016-04-01T09:31:26.370" LastActivityDate="2016-04-01T09:31:26.370" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2206" PostTypeId="1" CreationDate="2016-03-20T21:24:10.253" Score="1" ViewCount="1022" Body="&lt;p&gt;I implemented a spectral path tracing using physically base BRDF models such as Oren-Nayar,Specular Reflection and Transmission, Lambertian. All calculation in the path tracer uses standard illuminant and macbeth color checker SPD, spectral power distribution. The result of the path tracer for each pixel is the SPD obtained as a sum of SPD obtained from each sample calculated by the pat tracer. This SPD is then converted to CIE XYZ color and to RGB. The result scene obtained is the following one (in this example taking 500 samples per pixel):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8CdNZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8CdNZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, everything seems fine, except for the brightness/luminance of the scene. Every object in the scene is darker than it have to be. The floor and the front wall of the cornell box in the scene must be white and neutral8 (from macbeth color checker), but they are dark gray.&#xA;The following method is the one that trace the samples for a pixel of the path tracer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector3D PathTracer::getPixelColor(const Ray&amp;amp; ray, int bounce) {&#xA;&#xA;    Spectrum&amp;lt;constant::spectrumSamples&amp;gt; L(0.0f);&#xA;    int numberOfSamples = 500;&#xA;    float sampleWeight = 1.0f/(float)numberOfSamples;&#xA;&#xA;    for (int i = 0; i &amp;lt; numberOfSamples; i++) {&#xA;&#xA;        Spectrum&amp;lt;constant::spectrumSamples&amp;gt; spectrumSample = trace(ray, bounce);&#xA;        L = L + spectrumSample * sampleWeight;&#xA;    }&#xA;&#xA;    Spectrum&amp;lt;constant::spectrumSamples&amp;gt; Li = scene-&amp;gt;light-&amp;gt;spectrum;&#xA;&#xA;    ColorMatchingFunction* colorMatchingFunction = new Standard2ObserverColorMatchingFunction();&#xA;&#xA;    //Get tristimulus values.&#xA;    Vector3D tristimulus = CIE1931XYZ::tristimulusValues(L, Li, colorMatchingFunction);&#xA;&#xA;    //Convert tristimulus to sRGB.&#xA;    Vector3D color = CIE1931XYZ::tristimulusTosRGB(tristimulus);&#xA;&#xA;    //Apply sRGB gamma correction.&#xA;    sRGB::sRGBGammaCorrection(color, GammaCompanding);&#xA;&#xA;    //Convert to standard 0 - 255 RGB value.&#xA;    sRGB::sRGBStandardRange(color);&#xA;&#xA;    delete colorMatchingFunction;&#xA;&#xA;    return color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can seen, I already apply a gamma correction to the color obtained. &#xA;Do you have any idea why my image rendered is so dark? My concerns are in the part where I convert the SPD sum, obtained from the samples, into RGB color. Do you see any error? Am I missing something? Do I need other operation to execute a correct conversion from the SPD obtained from the sampling to an RGB color?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To avoid to write a too long question, I will link the main classes used by the path tracer for the calculation:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Lighting/shading class used to recursive calculate the rendering equation &lt;a href=&quot;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/blob/luminance/SCLT/Shading/PathBRDF.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/blob/luminance/SCLT/Shading/PathBRDF.cpp&lt;/a&gt; &lt;/li&gt;&#xA;&lt;li&gt;CIE XYZ conversion &lt;a href=&quot;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/blob/luminance/SCLT/Color/CIEColorSpaces/CIEXYZ.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/blob/luminance/SCLT/Color/CIEColorSpaces/CIEXYZ.cpp&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;sRGB utils &lt;a href=&quot;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/blob/luminance/SCLT/Color/sRGB.hpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/blob/luminance/SCLT/Color/sRGB.hpp&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The other files/classes used are all on this repository (branch luminance)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/tree/luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/chicio/Spectrum-Clara-Lux-Tracer/tree/luminance&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Thanks you all guys, I hope someone could help me.&lt;/p&gt;&#xA;" OwnerUserId="2237" LastEditorUserId="2237" LastEditDate="2016-03-20T23:21:29.253" LastActivityDate="2016-03-21T14:18:13.233" Title="Spectral path tracing - image color/brightness incorrect" Tags="&lt;color&gt;&lt;color-science&gt;&lt;brightness&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="15" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2208" PostTypeId="1" CreationDate="2016-03-21T10:34:33.770" Score="0" ViewCount="92" Body="&lt;p&gt;I have an .STL file (ascii and binary format) that contains several different CAD models. How can I read the file and create separate .stl files for each of the single different models. Even some hints/reference would be helpful.&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="231" LastEditDate="2016-04-21T11:19:54.067" LastActivityDate="2016-04-21T11:19:54.067" Title="Model Separation - Several models reside in a single .stl file" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2209" PostTypeId="2" ParentId="2208" CreationDate="2016-03-21T10:58:05.043" Score="1" Body="&lt;p&gt;Software recommendation are not on topic. Instead I will explain how you separate the shapes. Each object is a separate volume so you can just extract all the continuous shells. You can do this simply by picking a vertex marking it as visited and then picking all connected vertices and marking them visited. You continue this visiting to new un-visited vertices until you no longer can find a connected vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a shell, in most cases a shell is a separate object. Unless there is a empty non connected cavity inside the object. This is rare but possible in 3d printing though not most other manufacturing methods. In this case you need to check that the shells do not intersect (they shouldn't or it means your model is broken anyway, nothing to fix) and if a shell lies inside another. You can do this by picking a point on the suspected interior shell and shooting a ray in a arbitrary direction. The shells that you hit a odd number of times are surrounding your main shell.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-03-21T10:58:05.043" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2210" PostTypeId="1" AcceptedAnswerId="2211" CreationDate="2016-03-21T12:18:35.620" Score="17" ViewCount="3260" Body="&lt;p&gt;Apparently Macintosh computers cannot handle the Oculus Rift, because of their 'inferior' graphics cards. But should VR not just be like an external monitor? And concerning computer graphics, how are VR games any different from other games the Macintosh can run easily?&#xA;Where is the problem?&lt;/p&gt;&#xA;" OwnerUserId="2915" LastEditorUserId="48" LastEditDate="2016-03-21T17:59:26.230" LastActivityDate="2016-03-22T11:34:42.403" Title="How is VR different from a monitor" Tags="&lt;virtual-reality&gt;" AnswerCount="4" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2211" PostTypeId="2" ParentId="2210" CreationDate="2016-03-21T12:25:53.360" Score="16" Body="&lt;p&gt;VR requires a much higher resolution and framerate, and a much lower latency (start of draw to showing on screen).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If any of those things are missing then people tend to get nauseated. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of those require much higher bandwidth and compute power than Apple's cards are supposed to be able to handle.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="-1" LastEditDate="2016-03-22T00:21:05.530" LastActivityDate="2016-03-22T00:21:05.530" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2212" PostTypeId="2" ParentId="2206" CreationDate="2016-03-21T14:18:13.233" Score="6" Body="&lt;p&gt;The problem lies mainly in &lt;code&gt;CIE1931XYZ::tristimulusValues()&lt;/code&gt; function, where you normalize the resulting color to the luminance of your illuminant which causes that directly observed light source has luminance 1, but everything else is much darker. That is a nice thing to do if you just want to visualize colours of various reflectance spectra under a given illumination, but is probably not the best thing to do in a global illumination renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be more specific, you cannot expect a reflectance profile to be rendered always completely white just because it reflects all incident energy (constant spectral reflectance equal to 1 everywhere). Neglecting the material directional properties (BSDF, etc.), the properties of the light reflected from a point depend both on reflectance spectral profile of the material, and on the spectral and angular properties of the incident light. The incident light therefore depends not only on the SPD of the illuminant used for your light source, but also on its size and distance from the shaded point. The points closer to the light source will be brighter, while distant points will be darker.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would suggest removing the luminance normalization in your Spectrum-to-XYZ conversion completely and then adjusting the overall brightness of your scene by multiplying the normalized SPD of the used illuminant (D65 in your case) with some brightness parameter. Whether you multiply it before rendering, during rendering or during the XYZ conversion step is completely up to you. The choice shouldn't affect the result.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastActivityDate="2016-03-21T14:18:13.233" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="2213" PostTypeId="2" ParentId="2210" CreationDate="2016-03-21T15:43:27.157" Score="4" Body="&lt;p&gt;A external monitor in most cases is only one viewport. Means you have a monoscopic image displayed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having a HMD (Head-Mounted Display) like Oculus Rift requires you to render your virtual scene for both eyes in order to have stereoscopic 3D. This is essential for the immersion and having immersion is the only reason to use a HMD.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But rendering two viewports (one for each eye) does take additional computational power. Taking into account what ratchet freak already said it is even harder to maintain the high framerate and resolution at a low latency.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To overcome this you need serious computational power and well some people think the hardware used by Apple does not provide enough of it.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="-1" LastEditDate="2016-03-22T05:38:25.193" LastActivityDate="2016-03-22T05:38:25.193" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2214" PostTypeId="2" ParentId="2210" CreationDate="2016-03-21T20:19:13.870" Score="7" Body="&lt;p&gt;A VR headset is a monitor in terms of connections that just requires special software, but the issue is more of software and the capabilities of Mac hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You are most likely referring to the founder of Oculus, Palmer Luckeey, and his comment on Macs. He said:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;You can buy a $6,000 Mac Pro with the top of the line AMD FirePro&#xA;  D700, and it still doesn't match our recommended specs. So if they&#xA;  prioritize higher-end GPUs like they used to for a while back in the&#xA;  day, we'd love to support Mac. But right now, there's just not a&#xA;  single machine out there that supports it.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What he means is that not a single Mac has the high end gaming hardware necessary to provide the performance needed for a quality VR experience like the Rift.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VR requires a very tight coupling of high performance hardware to provide low latency imagery. Macs have actually been behind other computers in terms of computer graphics performance and quality. A VR game requires a higher framerate than the average game, with minimums being much higher than the 30 or 60 frames per second that most normal games aim for. VR games need lower latency than the 60 Hz latency of 16.67 ms to be immersive and help prevent motion sickness. These requirements are not flexible. 60 Hz is doable, but it's often seen as the minimum, with many reporting sickness and physical symptoms from framerates of 60 Hz or lower that are reduced or minimized with higher framerates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another factor is simply of market size. The percentage of the Mac market that has hardware capable of handling higher end games at all is an even smaller segment of an already smaller market. Apple's most popular products do not contain high end graphics chips, and instead use lower end integrated or mobile chips.&lt;/p&gt;&#xA;" OwnerUserId="2920" LastEditorUserId="2920" LastEditDate="2016-03-21T21:00:52.663" LastActivityDate="2016-03-21T21:00:52.663" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2217" PostTypeId="2" ParentId="2210" CreationDate="2016-03-22T11:34:42.403" Score="10" Body="&lt;p&gt;Macs are not gaming machines.  They never have been.  There was a time maybe 10-15 years ago when you could build a mid-tier gaming Mac, at significantly higher expense than a PC, but Macs have never catered to anything more than very casual gamers.  They don't run other games &amp;quot;easily&amp;quot; - they just adequately run &lt;em&gt;some&lt;/em&gt; games, &lt;em&gt;barely&lt;/em&gt; run others, and simply can't run a lot of popular titles (if they exist at all).&lt;/p&gt;&#xA;&lt;p&gt;Every Mac, with two exceptions, uses integrated graphics on their Intel chips.&lt;/p&gt;&#xA;&lt;p&gt;The MacBookPro can optionally can be fitted with a Radeon R9 370X, and the MacPro has the FirePro option above.  Let's look at 3D performance of these various options (The FirePro D700 is a Mac special - it's roughly in line with the specs of the W9000 PC variant):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fiOdu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fiOdu.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The multi-thousand dollar FirePro is sitting there next to an old GTX 670 that you can pick up in used bargain bins these days.  So what gives?&lt;/p&gt;&#xA;&lt;p&gt;The FirePro is a professional GPU - it competes with NVidia's Quadro and Tesla line of cards.  It is designed specifically for precision workstation GPU tasks, particularly for double-precision calculations.  These are important for CAD/Architechtural and Engineering applications as well as for scientific computing.  The cards &lt;strong&gt;can&lt;/strong&gt; be used just fine to play 3D games, but they are not optimized for that task and naturally underperform when compared to high end gaming GPUs like the GTX970/980, etc.&lt;/p&gt;&#xA;&lt;p&gt;Gaming GPUs dedicate resources to lower precision calculations (which they can do more of, and more quickly) and eye-candy goodies.  The tasks which they set themselves to are largely at odds with each other in terms of the style of hardware that is needed to get the job done.&lt;/p&gt;&#xA;&lt;p&gt;If you wanted to build a gaming mac right now, you really can't.  None of the systems available even have slots anymore to add in aftermarket GPUs (and they were twice the price of PC GPUs back in the days when you could, and came out months and months later than their PC counterparts so were always behind the cutting edge).  The only expandable Mac right now is the MacPro, and it is so ludicrously expensive that you would be crazy to try to make a gaming machine out of it (in fact, the hardware simply can't be had).  With expensive Xeon processors and FirePro graphics, the system is a highly specialized workstation that is firmly aimed at creative, scientific, and engineering professionals.&lt;/p&gt;&#xA;&lt;p&gt;So where does that leave the Mac?  Absolutely, completely out of the gaming arena - full stop.  It's got enough juice to run a few very casual games at very modest quality for home users, but that's just about it.  The Oculus Rift needs major GPU horsepower.  For 3D it needs to compute every scene from two unique perspectives (one for each eye), instantly doubling the amount of pre-rendering calculation it needs to do.  It then needs to render each of these independent scenes to two independent displays and keep everything moving fast and smooth enough to not make you want to vomit or have some sort of seizure.  That means it needs a powerful gaming GPU, and these just aren't available for the Mac anywhere.&lt;/p&gt;&#xA;" OwnerUserId="2936" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-03-22T11:34:42.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2218" PostTypeId="2" ParentId="2160" CreationDate="2016-03-22T13:34:43.987" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/&quot; rel=&quot;nofollow&quot;&gt;Shadertoy&lt;/a&gt; is a good website for playing with real-time visualizations. It uses WebGL and an in-page code editor, so you can edit a fragment shader and then run it live in your browser. One feature that was added (relatively) recently is the ability to connect a shader input to an audio stream - either from a pre-defined source, or from your microphone. You can also output sound from your shader by writing to a special &lt;code&gt;vec2&lt;/code&gt; output. Here's &lt;a href=&quot;https://www.shadertoy.com/results?query=&amp;amp;sort=popular&amp;amp;filter=soundinput&quot; rel=&quot;nofollow&quot;&gt;a list of examples that use mic input&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-03-22T13:34:43.987" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2219" PostTypeId="1" AcceptedAnswerId="2220" CreationDate="2016-03-22T18:44:38.660" Score="7" ViewCount="828" Body="&lt;p&gt;I clip a 3D triangle against a 3D Axis-Aligned Bounding Box (AABB) to obtain the largest planar polygon of the triangle contained in the AABB. My clipping algorithm is a (slightly modified) version of the robust (e.g. clipping planes have a small finite thickness) Sutherland-Hodgman algorithm as described in C. Ericson's Real-Time Collision Detection. I clip the triangle against each of the 6 planes constituting the AABB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to avoid heap (de)allocation, I allocated a fixed size point buffer on the stack in advance for all the vertices of the obtained planar polygon. My question now is: what is the maximum number of vertices possible one can obtain after clipping a triangle against an AABB? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Based on the control flow, every examined vertex can result in two vertices during a polygon plane clipping. Thus $3*2^6$ vertices. Due to symmetry this becomes $3*2^3=24$ vertices. However, I always obtain less vertices in practice.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="127" LastEditDate="2016-03-22T20:09:13.100" LastActivityDate="2016-03-22T20:09:13.100" Title="Maximum number of vertices after clipping a triangle against an AABB" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2220" PostTypeId="2" ParentId="2219" CreationDate="2016-03-22T19:22:55.100" Score="8" Body="&lt;p&gt;Funnily enough, I asked this exact question on Math.SE a couple years ago: &lt;a href=&quot;https://math.stackexchange.com/questions/859454/maximum-number-of-vertices-in-intersection-of-triangle-with-box/&quot;&gt;Maximum number of vertices in intersection of triangle with box&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The answer is 9 vertices, because each of the 6 planes of the box can cut off one corner of the polygon, replacing one vertex with two. So 3 vertices + 6 added vertices due to clipping = 9 total.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2017-04-13T12:19:38.027" LastActivityDate="2016-03-22T19:22:55.100" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2221" PostTypeId="1" AcceptedAnswerId="2294" CreationDate="2016-03-23T14:26:57.420" Score="1" ViewCount="1054" Body="&lt;p&gt;Currently for a university assignment I have been given a 3D rendering engine, capable of rendering a 3D world. One task is to create a first person camera for it (I know with OpenGL you don't have a camera, you have to effect the modelview). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, I have managed to get a first person camera working, however rotation is becoming a bit of a problem. I have spent a good few hours trying to fix the problem, but can't seem to find a solution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rotation works perfectly, until you move forward about -10 into the z axis. When you do, the camera rotation seemingly rotates around a set point, so it orbits the actual model, rather than just changing the direction the camera is looking at. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if you move out, then rotate, the camera will move around the object, not just move the object out of sight. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not sure what code you'll need to see to help, but here's some: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Camera Rotation:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Camera::RotateCamera(float yaw, float pitch, float roll)&#xA;{&#xA;//left and right rotation&#xA;Quaternion a;&#xA;Quaternion b;&#xA;Quaternion c;&#xA;Quaternion up;&#xA;Quaternion right;&#xA;Quaternion temp;&#xA;float s;&#xA;float vx;&#xA;float vy;&#xA;float vz;&#xA;&#xA;if (yaw != 0)&#xA;{&#xA;    s = cos(yaw / 2);&#xA;    c.SetQuaternion(m_direction, s);&#xA;    vx = m_upVector[0] * sin(yaw / 2);&#xA;    vy = m_upVector[1] * sin(yaw / 2);&#xA;    vz = m_upVector[2] * sin(yaw / 2);&#xA;    a.SetQuaternion(vx, vy, vz, s);&#xA;    b.SetQuaternion(vx, -vy, -vz, s);&#xA;&#xA;    up = a*c*b;&#xA;&#xA;    m_direction.SetVector(up[0], up[1], up[2]);&#xA;}&#xA;&#xA;//up and down rotation&#xA;if (pitch != 0 &amp;amp;&amp;amp; curDown &amp;lt; maxDown &amp;amp;&amp;amp; curDown &amp;gt; -maxDown)&#xA;{&#xA;    curDown += pitch;&#xA;    s = cos(pitch / 2);&#xA;&#xA;    a.SetQuaternion(m_direction, s);&#xA;    vx = m_rightVector[0] * sin(pitch / 2);&#xA;    vy = m_rightVector[1] * sin(pitch / 2);&#xA;    vz = m_rightVector[2] * sin(pitch / 2);&#xA;    b.SetQuaternion(vx, vy, vz, s);&#xA;    c.SetQuaternion(-vx, -vy, -vz, s);&#xA;&#xA;    right;&#xA;    temp;&#xA;    right = b * a * c;&#xA;    m_direction.SetVector(right[0], right[1], right[2]);&#xA;}&#xA;m_direction.Normalise();&#xA;m_rightVector = m_direction.CrossProduct(m_upVector);&#xA;m_upVector = m_rightVector.CrossProduct(m_direction);&#xA;&#xA;m_rightVector.Normalise();&#xA;m_upVector.Normalise();&#xA;UpdateViewMatrix();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The quaternion class is correct (so I'm assuming as it was already created for us). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Camera rotation code&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (x - ox &amp;gt; 0)&#xA;{&#xA;    cam_pos-&amp;gt;RotateCamera(0.05, 0, 0);&#xA;}&#xA;else if (x - ox &amp;lt; 0)&#xA;{&#xA;    cam_pos-&amp;gt;RotateCamera(-0.05, 0, 0);&#xA;}&#xA;&#xA;ox = x;&#xA;oy = y;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Applying the camera&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;modelview = (*cam_pos-&amp;gt;GetViewMatrix()) * modelview;&#xA;modelview = modelview*translation;&#xA;&#xA;float aspect_ratio = (float)m_width / (float)m_height;&#xA;projection.SetPerspective(60.0f, aspect_ratio, 1.0f, 1000.0f);&#xA;&#xA;glUniformMatrix4fv( m_uniform_projection, 1, GL_FALSE, projection.ToPtr() );&#xA;glBindSampler(0, m_texDefaultSampler);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;*cam_pos&lt;/code&gt; is the actual camera. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code works, just rotation goes off.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what currently happens on rotation: &#xA;&lt;a href=&quot;https://i.stack.imgur.com/5ptng.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5ptng.jpg&quot; alt=&quot;weird rotation effect&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2953" LastEditorUserId="2953" LastEditDate="2016-03-23T19:39:30.300" LastActivityDate="2016-04-08T19:21:25.237" Title="OpenGL C++ Camera Rotation Problem" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;c++&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2222" PostTypeId="1" AcceptedAnswerId="2225" CreationDate="2016-03-23T20:28:13.507" Score="4" ViewCount="1005" Body="&lt;p&gt;I am trying to write a ray tracer to render boxes that are arbitrarily rotated, i.e. not necessarily axis aligned. While I am reasonably comfortable ray tracing axis-aligned bounding boxes (AABB), I don't know how to handle non-axis aligned objects. The geometry becomes quite difficult. I've looked through a textbook (&lt;em&gt;Ray Tracing from the Ground Up&lt;/em&gt;) but couldn't find an answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I do it? Detailed suggestions would be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="2954" LastEditorUserId="209" LastEditDate="2016-03-24T15:38:23.423" LastActivityDate="2016-03-24T15:38:23.423" Title="How to convert Non-Axis Aligned Bounding Boxes to AABB" Tags="&lt;raytracing&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2223" PostTypeId="1" AcceptedAnswerId="2244" CreationDate="2016-03-24T01:21:13.737" Score="0" ViewCount="639" Body="&lt;p&gt;Windows 10 ships with &quot;3D Builder&quot;, a Universal App that contains utility functions to prepare STL, OBJ, 3DS, and other files that represent geometries for 3D printing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The utility looks like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/N3VXd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N3VXd.png&quot; alt=&quot;3D Builder&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particular, they have triangle mesh functions there that:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&quot;Detect&quot; when a mesh is not suitable for 3D printing;&lt;/li&gt;&#xA;&lt;li&gt;&quot;Repair&quot; so that the mesh isn't right it prepares it, by removing internal faces, closing &quot;holes&quot; in the outer surface, etc.;&lt;/li&gt;&#xA;&lt;li&gt;&quot;Simplify&quot; by removing redundant triangles, such as those found to be adjacent and co-planar; and&lt;/li&gt;&#xA;&lt;li&gt;&quot;Plane Cut&quot;, slicing a mesh through an arbitrarily positioned plane and filling in a surface on that plane to re-enclose the geometry, sometimes followed by a &quot;Detect&quot; and &quot;Repair&quot;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Every copy of Windows 8.1 and 10 has this utility at no additional cost. That says to me that the functions are well-known and as far as I've been able to test, reliable for virtually all inputs to the 3D printing use case. I used some of the messiest STL files I could find to prove this thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Which algorithms did they use for those functions? Where are they found for a .NET/WPF/UWP environment?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More to the point, did they expose the functions in an API I can use for a slightly dissimilar use case? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the builder the functions look like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simplify (the tractor top and sides have fewer facets):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qAAr2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qAAr2.png&quot; alt=&quot;Simplify Output&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Slice, UI before processing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GYHQV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GYHQV.png&quot; alt=&quot;Slice, UI before processing&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Slice, after processing and then one &quot;Simplify&quot; pass:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PDt95.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PDt95.png&quot; alt=&quot;Slice, after processing&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2957" LastEditorUserId="48" LastEditDate="2016-03-24T18:45:08.370" LastActivityDate="2016-04-27T09:59:41.317" Title="Which 3D algorithms does Windows 10's &quot;3D Builder&quot; application use?" Tags="&lt;algorithm&gt;&lt;3d&gt;&lt;mesh&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2224" PostTypeId="1" CreationDate="2016-03-24T01:30:05.193" Score="3" ViewCount="157" Body="&lt;p&gt;I need to find an approach to the problem of generating texture maps for non-convex polyhedrons without using a design tool like Maya. Specifically, I am mapping simulation results data onto a 3D surface, and I need to write code which generates the maps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One generic approach uses a gradient color brush as an overall texture to just map colors, but if the facets in the polyhedron are very narrow or the mapped (u,v) coordinates are very far apart on the same facet, the image gets noisy. Another approach employs Phong or Gouraud Shading, but those features are missing in some 3D libraries which favor texturing over specifying colors at each vertex. So, I'm looking for a way to get a good texture map generated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it helps in identifying a correct algorithm, all of the surfaces entirely enclose a 3-D space, there is no facet normal data, and I'll be able to identify a &quot;parting line&quot; which segregates one part of the surface from the other, as one might in order to create a mold for the shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simulation results are uniform (non-sparse) 3D arrays containing single precision values. There is a neighboring array of short integers which approximates the 3D mesh; a &quot;1&quot; value in that array corresponds to a part of the enclosed region of the polyhedron. I'm mapping to non-convex 3D surfaces more complex than can be mapped with a simple unrolling texture mapper or a spherical ray casting approach. Think of an American gallon milk jug or similar shapes that can be produced in plastic or metal molds.&lt;/p&gt;&#xA;" OwnerUserId="2957" LastEditorUserId="48" LastEditDate="2016-03-24T18:45:05.230" LastActivityDate="2016-03-24T18:45:05.230" Title="Generate complex (non-convex) polyhedron UV mapping" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;3d&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2225" PostTypeId="2" ParentId="2222" CreationDate="2016-03-24T07:59:15.040" Score="5" Body="&lt;p&gt;You can assign a coordinate system to each nAABB in such a way that the nAABB becomes an AABB in its own coordinate system. We call this a &lt;em&gt;local coordinate system&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume rays are expressed in a &lt;em&gt;world&lt;/em&gt; or &lt;em&gt;global coordinate system&lt;/em&gt;. In order to test an nAABB for intersection, one first needs to apply the &lt;em&gt;world-to-local transformation&lt;/em&gt; on the ray (origin and direction). This way we obtain a transformed ray which we can intersect with an AABB. Once an intersection point is found, we need to transform this back to world space via the inverse transformation (i.e. &lt;em&gt;local-to-world transformation&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice an nAABB is thus expressed as an AABB with a pair of world-to-local and local-to-world transformation matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If one applies a scaling ($S$) or translation ($T$) on an AABB, one obtains another AABB. If one applies a rotation ($R$) on an AABB, one obtains a nAABB.&#xA;Typically the corresponding transformation matrices are multiplied as follows $T * R * S$. Thus translation is applied after rotation. Since the $R$ component must be included in the world-to-local transformation, you need to include the $T$ component as well. The $S$ component can be included or directly applied to a unit AABB centered at the origin of the world-coordinate system. Including a $T$ component requires your world-to-local and local-to-world transformation matrices to be of size $4$x$4$ (expressed in &lt;em&gt;homogeneous coordinates&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/mmp/pbrt-v2/blob/master/src/core/transform.cpp&quot;&gt;Here&lt;/a&gt; you can find C++ code to construct all the $4$x$4$ world-to-local matrices and their inverses you probably need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this approach works for other geometrical objects as well (if the transformations involve scaling, rotation and translation).&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2016-03-24T08:24:24.030" LastActivityDate="2016-03-24T08:24:24.030" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2226" PostTypeId="5" CreationDate="2016-03-24T19:00:26.560" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Computational_geometry&quot; rel=&quot;nofollow&quot;&gt;Computational geometry&lt;/a&gt; encompasses a wide variety of topics, including:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Modeling surfaces and solids using meshes, splines, and other geometry representations&lt;/li&gt;&#xA;&lt;li&gt;Generating geometry from implicit or parametric functions, point sets, or other data&lt;/li&gt;&#xA;&lt;li&gt;Processing geometry to extract information about orientation, topology, curvature, or other quantities&lt;/li&gt;&#xA;&lt;li&gt;Performing operations on geometry such as tessellation or triangulation, simplification, CSG operations, feature extraction, UV mapping, and cleaning up mesh errors&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-03-24T19:00:26.560" LastActivityDate="2016-03-24T19:00:26.560" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2227" PostTypeId="4" CreationDate="2016-03-24T19:00:26.560" Score="0" Body="Problems involving meshes and other geometry representations, and manipulating, transforming, or extracting information from them; algorithms for solving geometrical problems such as computing intersections, filling holes, triangulating a shape, etc." OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-03-24T19:00:26.560" LastActivityDate="2016-03-24T19:00:26.560" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2228" PostTypeId="5" CreationDate="2016-03-24T19:02:43.390" Score="0" Body="" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-03-24T19:02:43.390" LastActivityDate="2016-03-24T19:02:43.390" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2229" PostTypeId="4" CreationDate="2016-03-24T19:02:43.390" Score="0" Body="Questions and problems dealing with three-dimensional space, including 3D meshes and other data structures, vector math, transformations, etc." OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-03-24T19:02:43.390" LastActivityDate="2016-03-24T19:02:43.390" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2231" PostTypeId="1" AcceptedAnswerId="2232" CreationDate="2016-03-25T02:13:12.723" Score="16" ViewCount="4753" Body="&lt;p&gt;Games and other graphically intensive applications use frameworks like OpenGL and DirectX. Also they require features like pixel shader and DX12.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But why would we need all these frameworks and GPU features when we could just draw everything pixel by pixel?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, the game would have to be compiling in a way so it is drawn pixel by pixel. This is likely to make the game executable big, but will it be faster and work on any 32-bit color GPU (even old ones)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that the first 3D games were drawn pixel by pixel, but why aren't they doing it now?&lt;/p&gt;&#xA;" OwnerUserId="2964" LastEditorUserId="127" LastEditDate="2016-03-25T09:40:55.547" LastActivityDate="2016-03-27T12:44:07.743" Title="Why do we have graphics frameworks like OpenGL and DirectX, when games could just draw pixels directly?" Tags="&lt;3d&gt;&lt;gpu&gt;&lt;performance&gt;&lt;pixel-shader&gt;&lt;pixels&gt;" AnswerCount="3" CommentCount="5" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2232" PostTypeId="2" ParentId="2231" CreationDate="2016-03-25T06:40:42.843" Score="23" Body="&lt;p&gt;Speed is the most common reason why this is &lt;strong&gt;not&lt;/strong&gt; done. In fact you can do what you propose, if you make your own operating system, its just going to be very slow for architectural reasons. So the assumption that its faster is a bit flawed. Even if it would be faster, it would be less efficient in terms of development (like 1% speed increase for 10 times the work).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Copying the data over from the CPU to the graphics card is a relatively slow operation. The less you copy the faster your update speed can be. So ideally you would have most of the data on your GPU and only update small chunks of data. There is a world of difference between copying over 320x200 pixels compared to 1920x1200 or more. See the number of pixels you need to update grows quadratically when the sides grow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example: It's cheaper to tell the GPU to move the image 10 pixels right than copy the pixels manually to the video memory in different locations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why do you have to go trough an API? Simply because it's not your system. The operating system can not allow you to do whatever you want for safety reasons. Secondly because the operating system needs to abstract hardware away, even the OS is talking to the driver trough some abstracted system, an API if you will.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact I would rate the likelihood that your system would be faster, if you just did all the work yourself, close to near zero. It's a bit like comparing C and assembly. Sure you can write assembly, but compilers are pretty smart these days and optimize better and better all the time. It's hard to be better manually, even if you can your productivity will be down the drains.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: An API does not make it impossible to do this update just like old games did it. It's just inefficient that's all. Not because of the API mind but because it is inefficient period.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PPS: This is why they are rolling out Vulkan.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="137" LastEditDate="2016-03-25T15:48:11.280" LastActivityDate="2016-03-25T15:48:11.280" CommentCount="17" ContentLicense="CC BY-SA 3.0" />
  <row Id="2233" PostTypeId="2" ParentId="2231" CreationDate="2016-03-25T08:14:09.057" Score="14" Body="&lt;p&gt;Just to add to &lt;a href=&quot;https://computergraphics.stackexchange.com/a/2232/&quot;&gt;joojaa's answer&lt;/a&gt;, things &lt;em&gt;are&lt;/em&gt; still being drawn pixel by pixel. You're just generating the pixels using a vertex shader/assembler/rasterizer, then texturing and lighting them using a fragment shader. This was all done in software in the 90's when your video card wasn't much more than a blitter and a frame buffer, but it was slow as hell. Hence the invention of modern GPUs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The drawing maths that's happening is basically the same as it was back in the Doom days, but now it's running on hundreds/thousands of shader ALUs rather than a handful of CPU cores. The APIs map down to basically the same set of GPU instructions behind the scenes. They're just there to stop you having to write a ton of gnarly GPU assembly across multiple vendor platforms.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-03-25T09:32:34.763" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2234" PostTypeId="2" ParentId="2231" CreationDate="2016-03-25T13:04:06.423" Score="15" Body="&lt;p&gt;&lt;em&gt;work on any 32-bit color GPU (even old ones)?&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bit of history here: this is how games were done on PC up until graphical accelerators started to become available in the mid-90s. It did indeed work on all hardware, because the hardware wasn't doing much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A graphical accelerator allows the drawing of pixels considerably &lt;em&gt;faster&lt;/em&gt; than a CPU can, by using specialized hardware and parallelism. The accelerator contains a number of processor cores. A desktop PC will have between 1-8 cores depending on age. My GTX970Ti graphics card has 1664 (one thousand six hundred and sixty-four!) cores. This obviously beats the PC for raw speed by a long way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, accelerators aren't standardized, and often include weird computer architecture tricks in order to achieve their speed. In order to write a game which isn't customized to a specific make and model of the card, an API needs to exist. And that's what DirectX, GL and the shader languages are used for. In fact, writing shaders &lt;em&gt;is&lt;/em&gt; the closest thing to writing a program that draws pixels directly - it's just that the card will run a thousand copies of that program for you in parallel, one per pixel.&lt;/p&gt;&#xA;" OwnerUserId="2971" LastActivityDate="2016-03-25T13:04:06.423" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="2235" PostTypeId="2" ParentId="67" CreationDate="2016-03-25T21:25:36.990" Score="4" Body="&lt;p&gt;If one examines old CRT television displays, one will observe red, green, and blue phosphor dots in a triangular lattice.  Some LCD television sets had a somewhat similar arrangement; pixels were rectangular rather than square, but successive rows of pixels were staggered so that the horizontal position of a red pixel on one row would be halfway between the positions of the nearest red pixels on the row above, and would match the position of a red pixel two rows up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When showing &quot;analog&quot; pictures, such arrangements will improve the visual quality of image that can be obtained with a given number of pixels.  On computer displays, however, there are a lot of lines that should appear perfectly horizontal, and a lot of lines that should appear perfectly vertical.  A rectangular grid can accommodate both easily.  A hexagonal grid, however, can only accommodate one or the other, and the one which isn't accommodated will appear rather nastily jagged.&lt;/p&gt;&#xA;" OwnerUserId="2984" LastActivityDate="2016-03-25T21:25:36.990" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2236" PostTypeId="2" ParentId="65" CreationDate="2016-03-25T21:41:43.557" Score="4" Body="&lt;p&gt;Imagine that one is rendering a picture of a flat floor with a uniform black and white checkerboard pattern that extends to the horizon; the checkers are large enough that they should be clearly visible at points near the camera but not large enough to be distinguishable near the horizon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Near the horizon, the floor should simply appear as uniform gray.  Near the camera, the checkers should appear distinct.  Between the camera and the horizon the appearance of the floor must somehow transition between those two extremes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the scene is rendered a spacial filter that has a very sheep cut-off, there will be a certain distance where the floor goes from being checkered to being gray.  If one uses a shallower filter, the transition will be much more gradual, but things near the original &quot;cut-off&quot; distance will be less sharp than they would have been otherwise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If one were to add a &quot;wall&quot; or crop the scene to hide the distant parts of the floor, such that there was no need to have any parts of the checkered floor blurred to gray, the best results would be obtained by using the steepest filter, yielding the sharpest image.  Using a shallower filter would give up image sharpness for the purpose of preventing a nasty transition that wasn't going to be visible anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Figuring out what kind of filtering to use thus requires that one know something about the spacial frequency content of the information to be displayed.  If the image contains nothing of interest that would approach Nyquist, using a steep filter will produce the sharpest results.  If, however, image content exceeds Nyquist, using a gradual filter will avoid ugly &quot;transitions&quot;.  No single approach will be optimal for all cases.&lt;/p&gt;&#xA;" OwnerUserId="2984" LastActivityDate="2016-03-25T21:41:43.557" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2237" PostTypeId="1" CreationDate="2016-03-26T16:57:36.530" Score="5" ViewCount="3768" Body="&lt;p&gt;I did a quick investigation about the topic but there doesn't seem a decent resource to find related problems without digging into latest CG papers (unlike CS problems you can easily find a Wikipedia list)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With open problems I mean phenomenas that still do not have a tractable solution/approximation to find its way into CG and better yet real time CG.&lt;/p&gt;&#xA;" OwnerUserId="8" LastEditorUserId="2287" LastEditDate="2016-03-28T07:28:02.187" LastActivityDate="2020-02-26T07:12:19.787" Title="What are the current open problems in Computer Graphics?" Tags="&lt;real-time&gt;&lt;physically-based&gt;&lt;render&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2239" PostTypeId="2" ParentId="2237" CreationDate="2016-03-26T17:45:40.710" Score="5" Body="&lt;p&gt;Computer Graphics can be divided in multiple subdomains of which I will only talk about physically-based rendering (the one I am the most familiar with and probably the one you are referring to based on the tags of the question). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Physically-based rendering&lt;/strong&gt; (also referred to as global illumination) is &lt;em&gt;generally&lt;/em&gt; far from real time at the moment. The speed we achieve is in fact no way close to what we actually try to simulate: the propagation of light through scenes (see &lt;a href=&quot;https://waskul.tv/portfolio/steve-waskul-ravi-ramamoorthi-2013/&quot; rel=&quot;nofollow&quot;&gt;interview with prof. Ravi Ramamoorthi&lt;/a&gt;). Scenes are rendered for over multiple hours or even days, far below the actual speed of light. Current research in this domain does however not aim at these speeds, a non-flickering framerate perceived by a human observer will do. Since the equations we try to solve are defined a long time ago, effort is mostly put in optimizing current algorithms which can be at a very high (introducing new formalisms) or low level (changing the right 1s to 0s and vice versa).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the ones who actually want to dive in the literature, see this wonderful up-to-date &lt;a href=&quot;http://kesen.realtimerendering.com/&quot; rel=&quot;nofollow&quot;&gt;site&lt;/a&gt; of the papers accepted at the most important conferences in the field of computer graphics.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2016-03-26T18:18:42.260" LastActivityDate="2016-03-26T18:18:42.260" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2240" PostTypeId="1" AcceptedAnswerId="2249" CreationDate="2016-03-26T23:22:58.243" Score="2" ViewCount="597" Body="&lt;p&gt;I'm stuck on this question asking me to calculate the intensity of a pixel using Ray Tracing. It gives values such as $I_i$ but doesn't give any coordinates. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know for the diffuse component, $I_ik_d(n,l)$ can be written as $I_ik_d(\cos\theta)$ but for the specular component $I_ik_s(h\cdot n)$ is there any other way to write it so that it doesn't require any vectors such as $h$ and $n$?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the question:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3s0AC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3s0AC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2359" LastEditorDisplayName="user246" LastEditDate="2017-04-28T04:33:33.773" LastActivityDate="2017-04-28T04:33:33.773" Title="phong equation of illumination specular component" Tags="&lt;raytracing&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2242" PostTypeId="2" ParentId="2237" CreationDate="2016-03-27T15:48:30.603" Score="10" Body="&lt;p&gt;There is a vast amount of open problems in real-time graphics: shadows, aliasing, reflections, global illumination, transparencies (blending order and lighting) etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SIGGRAPH annually hosts a course called &quot;Open Problems in Real-Time Rendering&quot;, which describes current issues in real-time graphics (mostly game dev industry standpoint). You can find last year's materials here: &lt;a href=&quot;http://openproblems.realtimerendering.com&quot;&gt;http://openproblems.realtimerendering.com&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="93" LastActivityDate="2016-03-27T15:48:30.603" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2243" PostTypeId="2" ParentId="2187" CreationDate="2016-03-28T08:47:03.953" Score="1" Body="&lt;p&gt;This is a hard problem since the systems do not in fact tell you how it should operate. The problem is that there are several ways to address this issue:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Apply a LUT to all output&lt;/li&gt;&#xA;&lt;li&gt;Let the system color manage&lt;/li&gt;&#xA;&lt;li&gt;Let each application color manage&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Nearly all of our color management systems are borderline braindead. There is really no sane way to ensure that you are doing the proper thing without extensively testing the system. You can not ask or specify your intent. In case of multi operating system situations. If there is reason for me to color manage something myself im at the mercy of each operating system peculiarities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a alternate discussion on this see this &lt;a href=&quot;https://stackoverflow.com/questions/23026151/do-i-need-to-gamma-correct-the-final-color-output-on-a-modern-computer-monitor&quot;&gt;stackoverflow post&lt;/a&gt;. But its not really a robust enough talk to cover all cases.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-03-28T08:47:03.953" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2244" PostTypeId="2" ParentId="2223" CreationDate="2016-03-28T09:55:53.623" Score="1" Body="&lt;p&gt;Well obviously nobody except the makers of this program can answer the exact algorithms used. I have done a quick explanation on each. Each separate task really deserves its own question and answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just iterate each polygon, for each vertex check if all of them are above the cut line eliminate the face. To make this check easy you can transom each vertex to the plane orientation. If not all vertices are above the cut line then the triangle is split along one of the edge that has a eliminated vertex. Then use the internal face closing algorithm. &lt;a href=&quot;http://geomalgorithms.com/a06-_intersect-2.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Heres some math&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Face closing algorithm works by finding open edges and then tessellating the new polygon closed. Please note: That this produces somewhat erratic results if the open holes are not planar. See &lt;a href=&quot;https://en.wikipedia.org/wiki/Polygon_triangulation&quot; rel=&quot;nofollow noreferrer&quot;&gt;polygon triangulation&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simplifying planar regions is basically the same face closing algorithm except they you first build up polygons out of regions. Also decimation might come to play. There is a lot of lore, and different algorithms for simplification and going trough all of it its way too bread for a post like this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Self intersection is a sorting problem. Quite a bit of lore on this exists too. The one that i mostly do is putting the polygons one by one into a BSP self organizing tree and checking against polygons against items in that tree to reduce the check complexity to &lt;em&gt;n&lt;/em&gt; log &lt;em&gt;n&lt;/em&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Internal cavities can be detected by splitting each mesh into shells and then for each shell check if the other shell is contained within each other. See &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2208/model-separation-several-models-reside-in-a-single-stl-file/2209#2209&quot;&gt;this post&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-03-28T09:55:53.623" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2245" PostTypeId="1" CreationDate="2016-03-29T11:19:37.950" Score="4" ViewCount="151" Body="&lt;p&gt;In my graphics engine, based on OpenGL ES 2.0 I am using standardized name for shader attributes like it is done in libGDX (such as a_position, a_normal, etc.).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When 'activating' my vertex buffer for drawing, just before I call &lt;code&gt;glVertexAttribPointer()&lt;/code&gt; I need to enable an attribute I'm going to use by calling &lt;code&gt;glEnableVertexAttribArray()&lt;/code&gt;, and then disable unused ones. Let's say there's two shaders I'm gonna use:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Shader1 is simple texture shader, which single attribute is &lt;code&gt;a_position_uv&lt;/code&gt; which is vec4, &lt;code&gt;xy&lt;/code&gt; are for position, and the remaining &lt;code&gt;zw&lt;/code&gt; are for texture coordinates (attribute location is bound by name to 0).&lt;/li&gt;&#xA;&lt;li&gt;Shader2 is solid shader, which single attribute is &lt;code&gt;a_position&lt;/code&gt; which is &lt;code&gt;vec2&lt;/code&gt; (attribute location is bound by name to 1).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Then something strange happens. When I'm drawing with Shader1, I'm enabling 0th, and disabling 1st attribute, and it worked just fine. But then, when I'm drawing with Shader2 (and obviously I'm enabling 1st, and disabling 0th attributes) it draws nothing. Just nothing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact: when I'm not disabling 0th attribute for solid shader it works fine. In both cases the remaining code is identical.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact (2): this happens only when deploying game on devices (iPhone simulator too).  I'm not a newbie in graphics programming and OpenGL, but in this case the behaviour is very strange for me.&lt;/p&gt;&#xA;" OwnerUserId="333" LastActivityDate="2016-03-29T11:19:37.950" Title="Strange behaviour of glDisableVertexAttribArray() on devices" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;opengl-es&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2246" PostTypeId="1" CreationDate="2016-03-29T12:48:44.053" Score="3" ViewCount="1255" Body="&lt;p&gt;I was about to scale this image down to 64x64 pixels:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jAk2Z.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jAk2Z.jpg&quot; alt=&quot;this&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result I got on MS Paint on Windows 7 was surprisingly good (i.e. crisp edges):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RaQLu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RaQLu.png&quot; alt=&quot;ms paint rescaled&quot;&gt;&lt;/a&gt; , whereas scaling it with GIMP resulted in &lt;a href=&quot;https://i.stack.imgur.com/8rPmx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8rPmx.png&quot; alt=&quot;cubic GIMP&quot;&gt;&lt;/a&gt; for cubic and &lt;a href=&quot;https://i.stack.imgur.com/EQ33f.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EQ33f.png&quot; alt=&quot;lanczos3 GIMP&quot;&gt;&lt;/a&gt; for Lanczos3 interpolation, both of which look significantly worse to me. Linear and nearest-neighbor was obviously much worse still.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also written a small program to check all of the interpolation modes available &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.interpolationmode.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;in the System.Drawing.Drawing2D.InterpolationMode enumeration&lt;/a&gt;, to no avail. Unfortunately, most web search results on the topic of interpolation in MS Paint are still from the days before Vista, when nearest neighbor was the only option.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know which interpolation algorithm the Windows 7 version of MS Paint uses?&lt;/p&gt;&#xA;" OwnerUserId="3019" LastActivityDate="2021-05-03T10:16:31.813" Title="Which interpolation algorithm does MS Paint on Windows 7 use for image rescaling?" Tags="&lt;algorithm&gt;&lt;interpolation&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2247" PostTypeId="1" AcceptedAnswerId="2254" CreationDate="2016-03-29T13:24:36.920" Score="3" ViewCount="66" Body="&lt;p&gt;I'm making a game that is supposed to like like a early 90s 3D game, so i'm rendering in software on an 8-bit indexed bitmap, using lookup tables for translucency and lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have to draw a translucent, lit sprite in front of an already-lit background (the light level of said background is lost at that point). I'm unsure whether to first darken all the pixels and then average them with the background or the other way round.&lt;/p&gt;&#xA;" OwnerUserId="3020" LastActivityDate="2016-03-30T18:16:14.740" Title="In what order to apply lighting and translucency?" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;real-time&gt;&lt;lighting&gt;&lt;transparency&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2249" PostTypeId="2" ParentId="2240" CreationDate="2016-03-29T17:20:31.733" Score="5" Body="&lt;p&gt;Assuming that the classic Phong model is desired here, the dot product that goes into the specular calculation should be R·L, rather than N·H (which was introduced by Blinn). That is, Phong calculates specular using the angle between the reflected eye vector and the light vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the diagram you posted, these vectors are shown and the angle is given as 15&amp;deg;. So, R·L = cos(15&amp;deg;) = 0.96 according to the table below the diagram.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-29T17:20:31.733" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2251" PostTypeId="1" AcceptedAnswerId="2252" CreationDate="2016-03-30T11:16:43.963" Score="4" ViewCount="315" Body="&lt;p&gt;This question bothers me since the first time I got to know about derivatives in pixel shader. Suppose we have a 2d texture:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;5   10  20  30&#xA;6   11  50  100&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I correctly understand, the derivatives for the pixel [0, 0] will be:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;dx = pixel[1, 0] - pixel[0, 0] = 10 - 5 = 5&lt;/li&gt;&#xA;&lt;li&gt;dy = pixel[0, 1] - pixel[0, 0] = 6 - 5 = 1&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And this will be 100% guaranteed because gpu executes pixels in 2x2 block. But what is the &lt;strong&gt;dx-derivative&lt;/strong&gt; for the pixel[1, 0]? The pixel right to it is from another block which maybe not executed yet? And what about pixel[3, 0]? It doesn't have a right neighbor at all!&lt;/p&gt;&#xA;" OwnerUserId="386" LastActivityDate="2016-03-30T11:35:24.423" Title="Gpu derivatives. How it's done across 2x2 boundary?" Tags="&lt;gpu&gt;&lt;pixel-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2252" PostTypeId="2" ParentId="2251" CreationDate="2016-03-30T11:35:24.423" Score="6" Body="&lt;p&gt;In Vulkan the shader only looks at each 2x2 and won't attempt to look beyond the neighbourhood: &lt;a href=&quot;http://vulkan-spec-chunked.ahcox.com/ch15s05.html&quot;&gt;http://vulkan-spec-chunked.ahcox.com/ch15s05.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$dPdx_{0,0}=dPdx_{1, 0} = P_{1,0}−P_{0,0}\\&#xA;dPdx_{2,0}=dPdx_{3, 0} = P_{3,0}−P_{2,0}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For times when a pixel would fall off the geometry the shader is invoked for the values it would have if the triangle extended a pixel further. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-03-30T11:35:24.423" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2253" PostTypeId="2" ParentId="2198" CreationDate="2016-03-30T16:43:19.203" Score="3" Body="&lt;p&gt;This is more of a long comment&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes you can do this. The problem lies in how you measure the surface. I tried to do this manually by progressively extruding tubes along the edges, and finding their intersection with the surface. It would work but is a bit hard to compute. Obviously you may want to take more steps than i did for a more accurate solution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IbXPj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IbXPj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt; Straight skeleton (magenta)  and insets by finding the intersection of tubes along edges, and then the created edges on mesh (blue) &#xA;From this experiment I can conclude that are many complex cases to consider.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-03-30T18:15:13.220" LastActivityDate="2016-03-30T18:15:13.220" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2254" PostTypeId="2" ParentId="2247" CreationDate="2016-03-30T18:16:14.740" Score="3" Body="&lt;p&gt;When blending multiple layers, physically the &quot;right&quot; thing to do is calculating lighting on each layer separately, then composite the lit layers together. This way, for instance, you can have a translucent sprite standing in a spotlight, in front of a dark background, and the sprite will be well-lit while the background visible through it stays dark. Or conversely, you can have a dark sprite silhouetted against a brightly lit background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you blended the sprite with the background before lighting, it wouldn't be clear which lighting environment you should use if the sprite and background have different ones.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-03-30T18:16:14.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2255" PostTypeId="1" CreationDate="2016-03-30T19:32:11.707" Score="7" ViewCount="234" Body="&lt;p&gt;My goal is to create 3D meshes without the use of a 3D editor.  So I want to know what representation languages and formats there are that are designed for this or otherwise that would be good for this.  I would prefer one that is open and widely supported.  Something like a 3D version of SVG or Postscript would be ideal.&lt;/p&gt;&#xA;" OwnerUserId="3031" LastEditorUserId="3031" LastEditDate="2016-03-30T21:44:32.470" LastActivityDate="2016-03-31T14:28:35.870" Title="Human Readable/Writable 3D Representation Formats/Languages?" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2256" PostTypeId="2" ParentId="2255" CreationDate="2016-03-30T21:35:06.380" Score="6" Body="&lt;p&gt;There are a number of formats that might fit the bill. Depends on what you want to achieve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most likely your looking for a scene description language for renderers. Many of them are for that one renderer but at least one is a standard. So you might be looking for something like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;RIB, &lt;a href=&quot;https://renderman.pixar.com/products/rispec/rispec_pdf/RISpec3_2.pdf&quot; rel=&quot;nofollow&quot;&gt;Renderman Bytestream&lt;/a&gt; although it comes with as a programming api as well. This is a based on a standard set by Pixar and is used by a number of render engines some of which are open source.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Most other rendering solutions also have textual formats I'm somewhat familiar with the mi (mental ray text or binary stream) formats and the now archaic Povray formats. But many others exist.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;It is a bit debatable whether these really are human readable but given that you specify SVG then I guess they are at least and readable as that. Just more complex. Note like SVG these describe scenes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have &lt;code&gt;dae&lt;/code&gt; also known as &lt;a href=&quot;https://www.khronos.org/collada/&quot; rel=&quot;nofollow&quot;&gt;collada&lt;/a&gt;. Which is sort of human readable has a similar niche as &lt;code&gt;RIB&lt;/code&gt; but is aimed for game assets. A number of other somewhat similar formats exist like the mostly deprecated &lt;a href=&quot;http://gun.teipir.gr/VRML-amgem/spec/index.html&quot; rel=&quot;nofollow&quot;&gt;VRML&lt;/a&gt; format, and its successors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have a bunch of polygon formats, many of them are binary. But atleast &lt;code&gt;obj&lt;/code&gt; and &lt;code&gt;ply&lt;/code&gt; are human readable and widely accepted. Obj is a very simple format. Although polygon meshes are seldom really easy to understand or craft manually if they are more complex. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have a bunch of application specific formats. For example the &lt;code&gt;ma&lt;/code&gt;, Maya ascii, format which is human readable if you understand how maya node hierarchy works. Cant say much of the others.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have the CAD transport formats &lt;code&gt;IGES&lt;/code&gt; and &lt;code&gt;STEP&lt;/code&gt;. I wouldn't go and claim either to be human readable. But I have hand crafted both on a occasion. Both of these are ISO standards, although STEP is insanely big and was in fact the biggest of ISO standards in page count last time I checked.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are quite many of these formats because 3D is not as uniform as 2D is. But, yes, I have hand crafted all of these at one point or another. Does not mean i would consider doing so as a productivity tool. Unlike EPS or SVG, which I craft bi weekly by hand. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I would have to guess your motives then i would say RIB is probably what you want. Or then your looking to use obj.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-03-31T14:28:35.870" LastActivityDate="2016-03-31T14:28:35.870" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2258" PostTypeId="1" CreationDate="2016-03-31T10:35:49.703" Score="2" ViewCount="287" Body="&lt;p&gt;I am trying to align two motion capture files from different sources.&#xA;The motion capture file consist of a skeleton specified as a hierarchy of joints. Each joint i.e. &quot;shoulder&quot; has three pieces of data: rotation order (XYZ), a translation plus direction from a parent joint (the bone vector) and an axis, which is a 3-tuple of rotations $(X, Y, Z)$ that describe the transformation from the parent coordinate system to the local coordinate system. For each frame, a local rotation 3-tuple $m_x, m_y, m_z$ is specified which describes how the bone vector changes from frame to frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To calculate the position of a particular bone for a single frame, I calculate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$M = M_x \times M_y \times M_z$ where $M_x$, $M_y$, $M_z$ are the rotation matrices correspond to $m_x$, $m_y$ and $m_z$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L = C^{-1} \times M \times C$, where $C$ is the multiplication of 3 $X$, $Y$, $Z$ rotation matrices corresponding to the bone axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is done for each bone in the hierarchy (i.e shoulder -&gt; clavicle -&gt; spine -&gt; root) and multiplied together to get the global rotation matrix for a particular bone. The bone vector is then multiplied by this rotation matrix to get the $x, y, z$ position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is now I have two motion capture files with corresponding joints: say, &lt;code&gt;shoulderA&lt;/code&gt; and &lt;code&gt;shoulderB&lt;/code&gt;. Since the joint axes are different, the local per-frame rotations are also different, which means I can't use the frame data for file B for skeleton A. I would like to &quot;refer&quot; &lt;code&gt;shoulderB&lt;/code&gt; to &lt;code&gt;shoulderA&lt;/code&gt;, so I'm wondering how I can change the per-frame rotations to do so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Reference: &#xA;&lt;a href=&quot;http://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/ASF-AMC.html&quot; rel=&quot;nofollow&quot;&gt;http://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/ASF-AMC.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3036" LastEditorUserId="182" LastEditDate="2016-04-09T09:27:12.450" LastActivityDate="2016-04-09T09:27:12.450" Title="Coordinate system transformation in motion capture files" Tags="&lt;animation&gt;&lt;motion&gt;&lt;capture&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2259" PostTypeId="1" CreationDate="2016-03-31T15:38:59.380" Score="2" ViewCount="103" Body="&lt;p&gt;What I am interested in doing is taking a 360 degree stereo video (Oculus Rift etc), and a description of how the viewing direction changes with time (rather than reading from gyroscopes) and then rendering that to a simple side by side rectangular video (so that you can stick the result on a smartphone and view it with the inbuilt video viewer).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will naturally involve something like sphere mapping the source, and rendering the result, as the smartphone apps do. I am interested in doing this transformation offline. Is there software around that already does this? Or what are the most suitable libraries to use if I want to program it myself?&lt;/p&gt;&#xA;" OwnerUserId="3038" LastActivityDate="2016-03-31T15:38:59.380" Title="Converting from 360 degree vr to rectangular" Tags="&lt;virtual-reality&gt;&lt;conversion&gt;&lt;video&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2262" PostTypeId="5" CreationDate="2016-04-03T18:04:03.003" Score="0" Body="" OwnerUserId="127" LastEditorUserId="127" LastEditDate="2016-04-03T18:04:03.003" LastActivityDate="2016-04-03T18:04:03.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2263" PostTypeId="4" CreationDate="2016-04-03T18:04:03.003" Score="0" Body="For questions specifically about the Geometry Shader stage in the GPU pipeline." OwnerUserId="127" LastEditorUserId="127" LastEditDate="2016-04-03T18:04:03.003" LastActivityDate="2016-04-03T18:04:03.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2264" PostTypeId="1" AcceptedAnswerId="2266" CreationDate="2016-04-03T20:15:54.950" Score="7" ViewCount="1071" Body="&lt;p&gt;I recently watched &lt;a href=&quot;https://www.youtube.com/watch?v=LKnqECcg6Gw&quot;&gt;this&lt;/a&gt; video that talked from a physics perspective how most of the ways we deal with color on the computer is incorrect because brightness is on a logarithmic not linear scale.  Being a novice graphics programmer I want to know how to deal with the information to make my graphics even better. I figure ray-tracers but for rasterizing, blur, grading, and light adjusting like HDR what am I supposed to do with this information?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I guess I have some questions. (sorry its a lot)&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Most texture data is stored in a format where the rgb brightness is incorrect because it has not been square rooted (right?) therefore if we want to display it correctly &lt;/li&gt;&#xA;&lt;li&gt;When using textures is the gaussian formula technically incorrect? If so what would be the mathematically correct method.&lt;/li&gt;&#xA;&lt;li&gt;What part of this problem is the monitor responsible for? Does it square or squareroot the values it gets?&lt;/li&gt;&#xA;&lt;li&gt;What part of the problem is the GPU responsible for when you ask it to sample a color at a point? Does it square or squareroot the values it gets?&lt;/li&gt;&#xA;&lt;li&gt;Do people know about this property and just not act on it because square rooting a number is an expensive computation? If so do we have a good way to quickly approximate the squareroot of numbers from 0-1?&lt;/li&gt;&#xA;&lt;li&gt;How do you apply the knowledge from that video in your graphics?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="48" LastEditDate="2016-11-12T22:44:59.610" LastActivityDate="2016-11-12T22:44:59.610" Title="How are we supposed to fix brightness with square roots?" Tags="&lt;color-science&gt;&lt;gamma&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2266" PostTypeId="2" ParentId="2264" CreationDate="2016-04-04T05:41:06.400" Score="12" Body="&lt;p&gt;What the video is talking about is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_correction&quot; rel=&quot;noreferrer&quot;&gt;gamma correction&lt;/a&gt; and it's a very familiar topic for graphics programmers. The first 30 minutes of John Hable's &lt;a href=&quot;http://www.gdcvault.com/play/1012351/Uncharted-2-HDR&quot; rel=&quot;noreferrer&quot;&gt;talk on Uncharted 2 rendering&lt;/a&gt; is my favorite introduction to &amp;quot;why graphics programmers should care about gamma&amp;quot;, as well as being a good introduction to HDR rendering. If you don't want to watch the talk (though I highly recommend it), &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html&quot; rel=&quot;noreferrer&quot;&gt;The Importance of Being Linear&lt;/a&gt; is also a good article, and Charles Poynton has a &lt;a href=&quot;http://www.poynton.com/notes/colour_and_gamma/GammaFAQ.html&quot; rel=&quot;noreferrer&quot;&gt;Gamma FAQ&lt;/a&gt; that goes into more technical detail and explains the terminology used.&lt;/p&gt;&#xA;&lt;p&gt;By the way, square/squareroot is only an approximation; the &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB&quot; rel=&quot;noreferrer&quot;&gt;sRGB gamma curve&lt;/a&gt; is what's most commonly used in practice (see the formulas there mentioning &lt;span class=&quot;math-container&quot;&gt;$C_\text{srgb}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$C_\text{linear}$&lt;/span&gt;). See also &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/68/is-gamma-still-important-to-take-into-account&quot;&gt;this related question&lt;/a&gt; about gamma and color spaces. It's a bit more complicated of a topic than the video makes it sound. :)&lt;/p&gt;&#xA;&lt;p&gt;To answer your specific questions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Yes, most image data is stored in gamma format, so the pixel values do &lt;em&gt;not&lt;/em&gt; represent linear luminance. I wouldn't describe it as &amp;quot;incorrect&amp;quot;, since gamma encoding has the useful property of putting more values in the darks, which is better for perceptual precision (as mentioned in the video). Gamma encoding is absolutely necessary to make good-looking images with only 8 bits per RGB component; if you stored linear values you would need more like 12 bits per component to get enough precision in the darks.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;To be more physically correct, when blurring an image, one should convert it to linear luminance, then do the blur (Gaussian or otherwise), then convert it back to the original color space.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The monitor accepts image data in gamma format. So the pixel values do not represent linear luminance, and the output brightness is not linearly proportional to the pixel values.&lt;/p&gt;&#xA;&lt;p&gt;If it's a good-quality, calibrated monitor, then it accepts data in a specific color space such as sRGB or Adobe RGB and reproduces the colors accurately based on the definition of that color space. If it's a crap uncalibrated monitor, then who knows what you'll get, but it'll be something &lt;em&gt;kinda&lt;/em&gt; like sRGB.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;GPUs can be configured to do various things here. Modern GPUs have hardware support to automatically convert values between gamma and linear when sampling a texture, or storing a value out to the framebuffer, but the programmer has to explicitly enable that using an API such as Direct3D or OpenGL.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Computer graphics people certainly do know about this topic, and it's critical to get it right when building a realistic renderer for film, AAA games, and so on. However, a lot of more &amp;quot;everyday&amp;quot; apps like web browsers and image editors (even Photoshop, as the video mentions) don't really handle gamma correctly.&lt;/p&gt;&#xA;&lt;p&gt;It's not an issue of processing power; maybe that was a problem 20 years ago, but today even mobile phones have ample processing power to convert images between gamma and linear. The reason why web browsers and image editors still don't get this right is some combination of (a) ignorance, (b) not believing that gamma is important enough to be worth getting right, and (c) simply being stuck with bad behavior because it's been that way for a long time and users have come to expect it, so they freak out if something changes.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;As mentioned, we have to think a lot about gamma when building a renderer. Most computations (e.g. lighting) should be done in linear space, but the input textures and output image should be in gamma space. Also, maybe some parts of rendering such as UI compositing should happen in gamma space because it's more familiar to artists (it works more like Photoshop layer compositing and such). Also, we have to decide if internal render targets are going to be stored in linear or gamma space, as it will affect precision. And we have to get all the conversions right, so that data gets converted between linear and gamma at the right spots in the rendering process.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-04-04T05:41:06.400" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2267" PostTypeId="1" AcceptedAnswerId="2269" CreationDate="2016-04-04T12:16:01.040" Score="4" ViewCount="122" Body="&lt;p&gt;In &lt;a href=&quot;https://hal.inria.fr/hal-01024289/document#page=8&quot; rel=&quot;noreferrer&quot;&gt;Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs, Section 2.2&lt;/a&gt;, Mr Eric Heitz defines the distribution of normals as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zgYQM.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zgYQM.png&quot; alt=&quot;Definition of D&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then, he goes on with the following assertion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cDXlW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cDXlW.png&quot; alt=&quot;Property of D&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I fail to understand how can D have such a property. Is it an assumption based on common sense or on geometrical considerations? Or can this equality be proven by manipulating the formulation of the integral?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2016-04-05T05:46:47.927" Title="Why does the integral of NDF over a solid angle equals the area where micronormals belong to that angle?" Tags="&lt;distribution&gt;&lt;integral&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2269" PostTypeId="2" ParentId="2267" CreationDate="2016-04-05T05:15:23.133" Score="3" Body="&lt;p&gt;$D(\omega)$ is defined as the area ($m^2$ unit in the numerator) of the microsurface with normals pointing in the direction $\omega$. $\mathcal{M}'$ is defined as the portion of the microsurface with normals point in the direction $\omega \in \Omega'$. So it's natural that the integral of $D(\omega)$ over $\Omega'$ gives the area of $\mathcal{M}'$.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Substituting the definition of $D$ into (4) gives:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\int_{\Omega'} D(\omega_m) d\omega_m = \int_{\Omega'} \int_{\mathcal{M}} \delta_{\omega}(\omega_m(p_m)) d p_m d\omega_m$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A fundamental property of the Dirac delta function is that it integrates to 1 over its domain. Unfortunately, we are integrating over $\Omega'$, not $\Omega$. Here I will stop pretending that I am actually able to use formal mathematical terms, and I will just note that the integrand has non-zero values only where both $d p_m \in \mathcal{M'}$ and $d\omega_m \in \Omega'$, which is what (3) says. As long as at least one of our integration domains is restricted to the set we care about, we will get the same result. So I'll just move the prime around a tad:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\int_{\Omega'} D(\omega_m) d\omega_m = \int_{\Omega} \int_{\mathcal{M}'} \delta_{\omega}(\omega_m(p_m)) d p_m d\omega_m$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we can apply the Dirac delta identity, since we're integrating over the whole domain:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\int_{\Omega'} D(\omega_m) d\omega_m = \int_{\mathcal{M}'} d p_m$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ta-da!&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2016-04-05T05:46:47.927" LastActivityDate="2016-04-05T05:46:47.927" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2270" PostTypeId="1" AcceptedAnswerId="2272" CreationDate="2016-04-05T08:42:57.990" Score="1" ViewCount="157" Body="&lt;p&gt;1) Update the front buffer will cause screen tearing, every one knows it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) But V-Sync, I think it still get the same issue. Why I get this idea? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.1) When GPU flips to the back buffer, current screen displays the old image which was in previous front buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.2) Now GPU sends image from &quot;current front buffer&quot; (previous back buffer) to monitor. This will last 16.7ms (60Hz). During this period, Human eyes will see half &quot;current front buffer&quot; and half &quot;previous front buffer&quot;. Is it right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.3) If it is right, it would be same as non-V-sync.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) But, in fact, when I switch &quot;V-sync&quot; on, I can't see screen tearing. Why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot for the answers.&lt;/p&gt;&#xA;" OwnerUserId="3058" LastActivityDate="2016-04-05T09:18:37.017" Title="Can V-Sync avoid tearing? I think it can't. Am I wrong?" Tags="&lt;rendering&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2271" PostTypeId="1" CreationDate="2016-04-05T09:09:45.963" Score="3" ViewCount="1264" Body="&lt;p&gt;According to the following assumptions, I think Cloud based VR would be the future:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Real world scene rendering needs ray tracing or other complex computing graphics technologies. It needs a lot of computing power.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Single GPU can't afford enough GFLOPS for that. And the powerful GPU is costly and hot. Since the moore's law is ending soon, the process of GPU will also end evolution, that means GPU can't get much faster than needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) Mobility is the king. But mobile GPU speed will be limited by the power and process. It won't get much faster too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;4) Cloud gaming would be promise for that. The network bandwidth and latency would be the biggest issues. Since Google Fiber has been deployed, I don't think network is the issue in the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;5) Rendering a real world needs unlimited computing power, but human eye resolution is limited. Limited resolution means limited network bandwidth consumption. For example, 1Gbps is enough to transmite 8K/16K H265 streaming video in stereo format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I believe Cloud based VR (Rendering in Cloud and stream to the client) would be the future. Am I correct?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;added more detail @20160406&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did some research on it. The motion-to-photon has to be less than 20ms. Maybe only 5ms is left for round trip network. So that the Cloud DC has to be very close to the client. In case optical fiber access, only two hops ( switch and BRAS ) to local router and then to local Cloud DC. (Transmission speed in optical is 200K KM/s, so 100KM radius would take only 0.5ms. That means Cloud DC would cover 30K square KM area.)If no network congestion with good QoS policy, the network latency would be very low. At the mean time, use distributed GPU clusters to render the VR content and then stream it to the client in parallel to reduce the time further. Let's count the time consumptions during each stages. 1.5ms for head tracking and local cpu processing. 1.5ms for network transmission to Cloud. 1.5 ms for distributed GPU cluster rendering and encoding. 5ms for network transmission to client. 1ms for decoding with special decoder since current video decoder designed for video playing not for VR. 5ms for transmission to monitor (equal 200Hz monitor, or very high bandwidth transmission as display port 1.4). The total time is 1.5+1.5+1.5+5+1+5 = 15.5ms. Of course, if using Foveated Rendering technology, addition 3ms for eye tracking delay, but the network bandwidth and latency will be reduced.&lt;/p&gt;&#xA;" OwnerUserId="3058" LastEditorUserId="3058" LastEditDate="2016-04-06T01:03:53.073" LastActivityDate="2020-06-01T13:56:12.403" Title="Cloud based VR would be the future?" Tags="&lt;gpu&gt;&lt;virtual-reality&gt;" AnswerCount="5" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2272" PostTypeId="2" ParentId="2270" CreationDate="2016-04-05T09:18:37.017" Score="3" Body="&lt;p&gt;V-sync means that the GPU won't switch buffer until the current frame is done showing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you tell to swap the buffer with V-Sync enabled the actual swap doesn't happen until V-Blank, a small window between frames where nothing is being sent to the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason I think you cannot see the update tear is that it moves across the screen during the update. While a non v-sync tear stays in the same place on the screen for 16 milliseconds.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-04-05T09:18:37.017" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2273" PostTypeId="2" ParentId="2271" CreationDate="2016-04-05T11:06:05.663" Score="3" Body="&lt;p&gt;Strictly speaking I think that the latency coming from transferring data over the network will not be low enough for VR. The device will need to send all the head tracking data and the user input over the network to the cloud based rendering farm. Then that data and input would need to be processed, rendered and the video streamed back to the user. Can you imagine playing a game and the the actual game stopping for buffering?&lt;/p&gt;&#xA;" OwnerUserId="204" LastActivityDate="2016-04-05T11:06:05.663" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2275" PostTypeId="1" AcceptedAnswerId="2277" CreationDate="2016-04-06T09:16:19.873" Score="0" ViewCount="649" Body="&lt;p&gt;In virtual reality, the motion-to-photon time is very important. Oculus says it has to be less than 20ms. Maybe 10~15ms is better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some people try to introduce Frameless rendering technology into VR. I think it's good to reduce the latency. But I don't know how the display quality is. According to the paper: &lt;a href=&quot;http://www.cs.virginia.edu/~luebke/publications/pdf/afr.egsr.pdf&quot; rel=&quot;nofollow&quot;&gt;&quot;Adaptive Frameless Rendering&quot;&lt;/a&gt; and the video (&lt;a href=&quot;https://www.youtube.com/watch?v=ycSpSSt-yVs&quot; rel=&quot;nofollow&quot;&gt;https://www.youtube.com/watch?v=ycSpSSt-yVs&lt;/a&gt;), it seems not very good. But, in this paper &quot;&lt;a href=&quot;http://discovery.ucl.ac.uk/1474834/1/Construction%20and%20Evaluation%20of%20an%20Ultra%20Low%20Latency%20Frameless%20Renderer%20for%20VR.pdf&quot; rel=&quot;nofollow&quot;&gt;Construction and Evaluation of an Ultra Low Latency Frameless Renderer for VR&lt;/a&gt;&quot;, the authors used FPGA instead of GPU to render and used Frameless Rendering to reduce the latency to 1ms. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my mind, FPGA is very hard to replace GPU in 3D rendering area. And, Frameless Rendering needs &quot;racing the beam&quot;, it is also very hard to program. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do you think? Is it realistic to use FPGA and frameless rendering?&lt;/p&gt;&#xA;" OwnerUserId="3058" LastEditorUserId="48" LastEditDate="2016-04-06T17:23:15.133" LastActivityDate="2016-04-06T17:52:49.340" Title="Can Frameless rendering reduce latency? And, can FPGA do 3D rendering instead of GPU?" Tags="&lt;rendering&gt;&lt;gpu&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2276" PostTypeId="2" ParentId="2271" CreationDate="2016-04-06T17:07:41.003" Score="8" Body="&lt;p&gt;As other people have mentioned, due to network latency issues, I think that full rendering on a cloud server and streaming video to a client device is unlikely to be workable. Even if the latency can be kept low enough in a best-case scenario, it would only work for a very limited number of users with very high-quality internet connections. (Don't forget that e.g. in the USA, there are still tens of millions of people on dialup or DSL, with no access to cable internet, let alone fiber. It will be decades still before fiber is widespread.) Also, note that many &lt;a href=&quot;https://en.wikipedia.org/wiki/Cloud_gaming&quot;&gt;cloud gaming services&lt;/a&gt; do exist, but that according to players, input latency is noticeably worse on these services than playing locally on a PC.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, all that being said, rendering entirely on a cloud server is not the only way to approach the problem. The most latency-sensitive aspect of VR is head tracking. Oculus's &lt;a href=&quot;https://developer.oculus.com/blog/asynchronous-timewarp-examined/&quot;&gt;&quot;timewarp&quot;&lt;/a&gt; technology shows that you can quickly and cheaply update a previously rendered image to respond to head rotation, as a 2D image operation: if the user turns their head to the right, you shift the image to the left, and so on. With a depth buffer, you can do positional timewarp as well, although this creates various artifacts with parallax because it's based on a single-layered 2D image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Timewarp is certainly cheap enough to run on a mobile device. So, one approach is to render frames in the cloud, stream the video to the client, then timewarp the video on the client device to obtain very low-latency head tracking. This wouldn't help the latency of other inputs such as keyboard/mouse/controller inputs, but those don't induce nausea when they're delayed, the way delayed head-tracking does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also other possibilities along the lines of splitting rendering between the cloud and the client. For example, object-space lighting and shading could be done on the cloud and streamed to the client as textures; then the client only needs to render simple textured geometry. This would work better than positional timewarp for getting correct parallax when you move your head around, though you'd still have some artifacts with specular shading and reflections. There are a lot of possibilities for offloading rendering to the cloud in VR-friendly ways.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-06T17:07:41.003" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2277" PostTypeId="2" ParentId="2275" CreationDate="2016-04-06T17:52:49.340" Score="5" Body="&lt;p&gt;First of all, the &quot;frameless rendering&quot; technique is in the context of raytracing, not rasterization. It's not obvious how it could be made to work effectively with rasterization, given that the basic idea of it is to update an image by a combination of temporal reprojection plus firing rays specifically at areas where the algorithm thinks the image is undersampled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So this technique is, prima facie, not compatible with rasterization-based graphics applications. But if you're already doing raytracing for other reasons, this technique would be interesting to look at; it certainly appears to improve quality relative to an image raytraced from scratch each frame, with the same number of rays per second.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Raytracing on a GPU is certainly possible; you don't need an FPGA for that. I've only skimmed the second paper, but my reading of it is that the main reason for the FPGA is to get a close coupling between the display scanout and the rendering activity: namely they &quot;race the beam&quot; and evaluate pixels just before they're about to be scanned out, thus obtaining low latency.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The GPU equivalent of this is probably to split the image in thin horizontal strips, and kick off a compute dispatch to render each strip just before it starts to be scanned out. Today, this is difficult to accomplish as it requires either millisecond-precise scheduling that desktop OSes are not currently set up for, or it requires the GPU to be able to dispatch based on an interrupt from the scanout unit&amp;mdash;a hardware feature that doesn't currently exist AFAIK (or if it does, it isn't exposed in any graphics APIs). Or you might be able to make it work with a long-running asynchronous compute dispatch, if you can find a way to stay in sync with scanout.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, there are obstacles, but they aren't insurmountable, and I think if there was sufficient interest in racing-the-beam-style rendering, then OS and GPU vendors could come up with a way to do it in the future. So I don't think an FPGA is required for this kind of technique to work. On the other hand, the fact that it's based on raytracing is a much bigger obstacle to using it in &quot;real-world&quot; apps and games.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-06T17:52:49.340" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2278" PostTypeId="2" ParentId="2161" CreationDate="2016-04-07T02:45:58.850" Score="5" Body="&lt;p&gt;This bachelor thesis briefly reviews six SSAO techniques. It could be a good start.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;CryEngine 2 AO&lt;/li&gt;&#xA;&lt;li&gt;StarCraft II AO&lt;/li&gt;&#xA;&lt;li&gt;HBAO&lt;/li&gt;&#xA;&lt;li&gt;Volumetric Obscurance&lt;/li&gt;&#xA;&lt;li&gt;Alchemy AO&lt;/li&gt;&#xA;&lt;li&gt;Unreal Engine 4 AO&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://frederikaalund.com/a-comparative-study-of-screen-space-ambient-occlusion-methods/&quot; rel=&quot;noreferrer&quot;&gt;http://frederikaalund.com/a-comparative-study-of-screen-space-ambient-occlusion-methods/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-04-07T02:45:58.850" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2279" PostTypeId="1" AcceptedAnswerId="2291" CreationDate="2016-04-07T12:47:27.967" Score="4" ViewCount="675" Body="&lt;p&gt;I am trying to implement for research purposes a gradient-domain path tracer. In order to achieve this step I first need a working Path tracer. I have been creating one so far but results are wrong and I will explain you why. Some concepts:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am working on paths that are generated before sampling them. I mean that the first step of my algorithm consists in calculating a path for a certain pixel (x,y). This path will perform some bounces within the scene and, if terminates on the light, will be considered valid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all: the following is the definition of a struct (will be declared and initialized later), containing some scene info needed to cast ray from the camera into the scene.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct RenderData&#xA;{&#xA;    vec3 E;&#xA;    vec3 p1;&#xA;    vec3 dx;&#xA;    vec3 dy;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It is initialized in the InitializeScene method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void InitializeScene(){ // setup virtual screen plane&#xA;  vec3 E( 2, 8, -26 ); //Eye position&#xA;  vec3 V( 0, 0, 1 ); //LookAt vector&#xA;  float d = 0.5f, ratio = SCRWIDTH / SCRHEIGHT, focal = 18.0f;&#xA;  vec3 p1(E + V * focal + vec3(-d * ratio * focal, d * focal, 0)); // top-left screen corner in SCREEN SPACE&#xA;  vec3 p2(E + V * focal + vec3(d * ratio * focal, d * focal, 0)); // top-right screen corner&#xA;  vec3 p3(E + V * focal + vec3(-d * ratio * focal, -d * focal, 0)); // bottom-left screen corner&#xA;  mat4 M = rotate( mat4( 1 ), r, vec3( 0, 1, 0 ) );&#xA;  p1 = vec3(M * vec4(p1, 1.0f)); //rotating the above points&#xA;  p2 = vec3(M * vec4(p2, 1.0f));&#xA;  p3 = vec3(M * vec4(p3, 1.0f));&#xA;  renderData.dx = (p2 - p1) / (float)SCRWIDTH;&#xA;  renderData.dy = (p3 - p1) / (float)SCRHEIGHT;&#xA;  renderData.E = vec3(M * vec4(E, 1.0f));&#xA;  renderData.p1 = p1;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The code above is to make you understand how I initialized the scene.&#xA;I also have structs to store informations about my paths:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct PathVert {&#xA;   vec3 p; vec3 n; //hit point and normal of the surface hit &#xA;};&#xA;&#xA;struct Path {&#xA;   PathVert verts[MAX_DEPTH]; //maxDepth is 15 for now&#xA;   int vertCount;&#xA;   int x, y; //which pixel this path is referring to&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;therefore I start consider pixel after pixel.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int y = 0; y &amp;lt; SCRHEIGHT; y++) for (int x = 0; x &amp;lt; SCRWIDTH; x++)&#xA;{     &#xA;   Path path;&#xA;   if(generatePath(x,y, path)){&#xA;      Sample(path);&#xA;   }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;generatePath()&lt;/strong&gt; method indeed tracks the path into the scene and checks all the vertices it hits. The &lt;strong&gt;checkIfRayIntersectSomething(t)&lt;/strong&gt; method you will see used, it's just a pseudo method implemented in my framework and that I omit posting cause of its length. I use it to check if my ray hits something in the scene, if it does, it update the &quot;t&quot; with the distance to that object. NOTE: the light is not considered an object itself. Hence, I also have a &lt;strong&gt;checkRayLightIntersection(hitLightPoint)&lt;/strong&gt; which checks the intersection with the light, if there is any, the hitLightPoint is updated with the point on the light I have been hitting.&#xA;The light is a 2D surface.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec lightPos = Vec(5, 15, 2); //hard coded position of the light&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the light, as said, is a surface, but exactly a square surface, whose 4 angles are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec P1 = Vec(lightPos.x - 20, lightPos.y, lightPos.z + 20);&#xA;Vec P2 = Vec(lightPos.x + 20, lightPos.y, lightPos.z + 20);&#xA;Vec P3 = Vec(lightPos.x + 20, lightPos.y, lightPos.z - 20);&#xA;Vec P4 = Vec(lightPos.x - 20, lightPos.y, lightPos.z - 20);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Quite big, I know, so the first question relies on this aspect, is it correct having such a big light?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But let's go to the main methods. Hereby you can see the GeneratePath method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool GeneratePath(int x, int y, Path &amp;amp;path){&#xA;   path.x = x;&#xA;   path.y = y;&#xA;   path.vertCount = 0;&#xA;&#xA;   vec3 P = renderData.p1 + renderData.dx * ((float)(x) + Rand(1)) +  renderData.dy * ((float)(y) + Rand(1));&#xA;   vec3 O = renderData.E + vec3(Rand(0.4f) - 0.2f, Rand(0.4f) - 0.2f, Rand(0.4f) - 0.2f);&#xA;   vec3 D = normalize(P - O); //direction of the first ray, the one from the camera towards the pixel we are considering&#xA;&#xA;   for (int depth = 1; depth &amp;lt;= MAXDEPTH; depth++){&#xA;    float t;&#xA;    Vec hitLightPoint;&#xA;    PathVert vert;&#xA;    if (!checkIfRayIntersectSomething(t)){&#xA;        //we didn't find any object.. but we still may have found the light which is an object non represented in the scene&#xA;        //the depth check avoids me rendering the light as a white plane&#xA;        if (depth &amp;gt; 1 &amp;amp;&amp;amp; checkRayLightIntersection(O, D, hitLightPoint)){&#xA;            //update the vertex since we realized it's the light&#xA;            vert.p = hitLightPoint;&#xA;            vert.n = Vec(0, -1, 0);//cause the light is pointing down&#xA;            path.verts[depth - 1] = vert;&#xA;            path.vertCount++;&#xA;            return true; //light hit, path completed    &#xA;        }&#xA;        return false; //nothing hit, path non valid&#xA;    }&#xA;    //otherwise I got a hit into the scene&#xA;    vert.p = O + D * t; //reach the hitPoint&#xA;    vert.n = methodToFindTheNormal();&#xA;    vert.color = CalculateColor(vert.p); //according to the material properties (only diffuse objects so far)&#xA;    path.verts[depth - 1] = vert;&#xA;    path.vertCount++;&#xA;&#xA;    //since I have the light, and a path terminates when it hits the light, I have to check out also if my ray hits this light,&#xA;    //and if does, I have to check whether it first hits the light or the object just calculated above&#xA;    //moreover with the &quot;depth &amp;gt; 1&quot; check, I avoid again rendering the light which otherwise would be visible as a white plane&#xA;&#xA;    if (depth &amp;gt; 1 &amp;amp;&amp;amp; checkRayLightIntersection(O, D, hitLightPoint)){&#xA;        float distFromObj = length(vert.p);&#xA;        float distFromLight = length(hitLightPoint);&#xA;        if (distFromLight &amp;lt; distFromObj){&#xA;            //update the vertex since we realized it's the light&#xA;            vert.p = hitLightPoint;&#xA;            vert.n = Vec(0, -1, 0);&#xA;            vert.color = Vec(1, 1, 1);// TODO light color? or light emission?&#xA;&#xA;            path.verts[depth - 1] = vert;&#xA;            return true; //light hit, path completed&#xA;        }&#xA;    }&#xA;    if (depth == MAXDEPTH) return false;&#xA;       Vec newDir = BSDFDiffuseReflectionCosineWeighted(vert.n, D);//explained later&#xA;       D = newDir;&#xA;       O = vert.p;&#xA;   }&#xA;   return false;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The BSDFDiffuseReflectionCosineWeighted() just calculate the new directions, tested and working. What remains last is the Sample method which calculates the final color of the pixel.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec Sampling(Path &amp;amp;path){&#xA;&#xA;   Vec color(1, 1, 1);&#xA;&#xA;   for (int vert = 0; vert &amp;lt; path.vertCount - 1; vert++) { //considers the last vertex as the light&#xA;      const PathVert &amp;amp;currVert = path.verts[vert];&#xA;      const PathVert &amp;amp;nextVert = path.verts[vert + 1];&#xA;      Vec wo = (nextVert.p - currVert.p).norm();&#xA;      double cosTheta = fabs(wo.dot(currVert.n));&#xA;      float PDF = cosTheta/PI;&#xA;      if (cosTheta &amp;lt;= 1e-6) return Vec();&#xA;      //considering only DIFFUSE objects&#xA;      color = color.mult(currVert.color * (cosTheta / M_PI) / PDF);&#xA;   }&#xA;   return color.mult(Vec(10.0f, 10.0f, 10.0f)); //multiplication for the light emission?&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Result with 16SPP is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HNOah.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HNOah.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the results are not that bad but there is one main problem: shadows are missing.. tried many combinations but no improvements. There is some error in the algorithm itself. Can you help me understanding why? Thanks in advance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: this is my target reference:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QHG2z.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QHG2z.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 2: this is what happens in case the &lt;strong&gt;depth &gt; 1&lt;/strong&gt; check is omitted:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hiqEY.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hiqEY.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 3: after fixing the &lt;strong&gt;distFromLight&lt;/strong&gt; and &lt;strong&gt;distFromObj&lt;/strong&gt; I got the following results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JvGhf.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JvGhf.jpg&quot; alt=&quot;some clue of shadows&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of the 2 problems as suggested by @trichoplax could be too soft shadows. So I tried to lower the size of the light, increasing his power to compensate. Results are not good and shown here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8aYPH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8aYPH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover as requested I can post some more code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool checkRayLightIntersection(Vec O, Vec D, Vec &amp;amp; hitLightPoint){&#xA;  //getting the 4 corners of my light&#xA;  Vec P1 = Vec(lightPos.x - 20, lightPos.y, lightPos.z + 10);&#xA;  Vec P2 = Vec(lightPos.x + 20, lightPos.y, lightPos.z + 10);&#xA;  Vec P3 = Vec(lightPos.x + 20, lightPos.y, lightPos.z - 10);&#xA;  Vec P4 = Vec(lightPos.x - 20, lightPos.y, lightPos.z - 10);&#xA;&#xA;  //the majority of the methods first find out where the ray intersects the plane that the rectangle lies on Ax + By + Cz + D = 0&#xA;  //in our case the equation of that plane is easy -&amp;gt; D = 20&#xA;  // answers.google.com/answers/threadview?id=18979&#xA;&#xA;  float t = -(-O.y + lightPos.y) / (-D.y);&#xA;  if (t &amp;gt; 0){&#xA;    Vec hitPoint = O + D * t;&#xA;    Vec V1 = (P2 - P1).norm();&#xA;    Vec V2 = (P3 - P2).norm();&#xA;    Vec V3 = (P4 - P3).norm();&#xA;    Vec V4 = (P1 - P4).norm();&#xA;    Vec V5 = (hitPoint - P1).norm();&#xA;    Vec V6 = (hitPoint - P2).norm();&#xA;    Vec V7 = (hitPoint - P3).norm();&#xA;    Vec V8 = (hitPoint - P4).norm();&#xA;&#xA;    if (V1.dot(V5) &amp;gt; 0.0 &amp;amp;&amp;amp; V2.dot(V6) &amp;gt; 0.0 &amp;amp;&amp;amp; V3.dot(V7) &amp;gt; 0.0 &amp;amp;&amp;amp; V4.dot(V8) &amp;gt; 0.0){&#xA;        hitLightPoint = hitPoint;&#xA;        return true;&#xA;    }&#xA;  }&#xA;  return false;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Instead, the &lt;strong&gt;checkIfRayIntersectSomething&lt;/strong&gt; method is part of the framework itself (it has just another name), it's not done by me but it's tested and working.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 4: tried to render a small part of the scene with high number of spp. Tried 512 spp for the bottom right corner where should appear shadows according to the target image. Results show that shadows are not there:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ohZJu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ohZJu.png&quot; alt=&quot;Bottom right corner at 512spp&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 5:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hereby post the code used to render the target image, it does at the same time my &lt;strong&gt;Sampling()&lt;/strong&gt; and &lt;strong&gt;GeneratePath()&lt;/strong&gt; methods using a recursive structure.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec Sample(vec3 O, vec3 D, int depth)&#xA;{&#xA;  vec3 color(0, 0, 0);&#xA;  float t;&#xA;  if (checkIfIntersectSomething(D, t))&#xA;  {&#xA;&#xA;    vec3 I = O + t * D; //get to the intersection point on the object&#xA;    vec3 diffuse = getMaterial(I);&#xA;&#xA;    vec3 L = vec3(-1 + Rand(2.0f), 20, 9 + Rand(2.0f)) - I; //(-1,20,9) is Hard-code of the light position, and I add Rand(2.0f) on X and Z axis&#xA;    //so that I have an area light instead of a point light&#xA;    L = normalize(L);&#xA;    float ndotl = dot(I.getNormal(), L); //the closer the dotProdutc is to 1.0, the more the light and surface face each other&#xA;    if (ndotl &amp;gt; 0)&#xA;    {&#xA;        if (!checkRayLightIntersection(L)) {&#xA;            float dist = distFromLight(I);&#xA;            color += diffuse * ndotl * vec3(1000.0f, 1000.0f, 850.0f) * (1.0f / (dist * dist));&#xA;        }&#xA;    }&#xA;&#xA;    // russian roulette&#xA;    float Psurvival = CLAMP((diffuse.r + diffuse.g + diffuse.b) * 0.33333f, 0.2f, 0.8f);&#xA;&#xA;    // continue random walk &#xA;    float rand = Rand(1.0f);&#xA;    if (depth &amp;lt; 10 &amp;amp;&amp;amp; rand &amp;lt; Psurvival)&#xA;    {&#xA;        //Besides russian roulette, I also do another weight, because rays that go towards the horizon will bring back very little energy&#xA;        //so I make a random distribution that favours those rays who are close to the normal of the hit point, this is DiffuseReflectionCosineWeighted(). It creates a Random bounce but proportional to N dot R&#xA;        vec3 R = DiffuseReflectionCosineWeighted(I.getNormal());//there is a weight&#xA;&#xA;        float prob = 1.0;&#xA;        float cosTheta = fabs(dot(I.getNormal(), R));&#xA;        if (cosTheta &amp;gt; 1e-6) prob = cosTheta / M_PI;&#xA;&#xA;        color += diffuse * Sample(I + R * EPSILON, R, depth + 1) * (1.0f / Psurvival); //the cosTheta() of the attenuation of the rendering equation gets simplified with the cosTheta of the &quot;prob&quot;&#xA;        //the PI of the prob gets simplified with the BRDF where we are using the ideal BRDF = diffuse/PI&#xA;    }&#xA;}&#xA;return color;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 6: Trichoplax was right, I had a problem calculating the &lt;strong&gt;distanceFromObject&lt;/strong&gt; and &lt;strong&gt;distanceFromLight&lt;/strong&gt;. After solving this, we realized that some sort of shadows appeared (shown in one of the images above). He then suggested that such a broad light might have been washing out the shadows, and so it was. By reducing the light size and by using a high amount of SPP we realized that shadows are there and visibile: &lt;a href=&quot;https://imgur.com/y88zgAZ&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://imgur.com/y88zgAZ&lt;/a&gt; . As a drawback tho, way less rays reach the light, giving back an image with high noise, but this is another kind of problem and I created another question for it. Thanks to @trichoplax and @julien for their help&lt;/p&gt;&#xA;" OwnerUserId="3069" LastEditorUserId="3069" LastEditDate="2016-04-17T15:19:19.143" LastActivityDate="2016-04-17T15:19:19.143" Title="Path tracer not rendering shadows" Tags="&lt;c++&gt;&lt;lighting&gt;&lt;shadow&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;" AnswerCount="2" CommentCount="9" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2280" PostTypeId="2" ParentId="2008" CreationDate="2016-04-07T14:59:33.647" Score="5" Body="&lt;p&gt;The problem with your calculations is that you use a uniform for &lt;em&gt;viewPos&lt;/em&gt; which is the camera position.&#xA;The rest of your calculations is in Camera-Space, so the &lt;em&gt;viewPos&lt;/em&gt; should always be $(0.0, 0.0, 0.0)$ and thereby the $viewDir$ becomes $-1*\text{fragPos}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general: Always be careful about the different reference frames your calculations can be done in and aim to keep this consistent.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-04-07T14:59:33.647" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2281" PostTypeId="2" ParentId="2279" CreationDate="2016-04-07T16:55:14.700" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;is it correct having such a big light?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I don't see any problem with having a big area light. That said, it also depends on the scale of your scene. If the light is large compared to it, shadows will tend to be more diffuse, like under an overcast sky.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;shadows are missing.. [...] Can you help me understanding why?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I haven't found any blatant mistake, but there are two elements that look suspicious to me.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (depth &amp;gt; 1 &amp;amp;&amp;amp; checkRayLightIntersection(O, D, hitLightPoint)) {&#xA;    // ...&#xA;    return true; //light hit, path completed&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Although this part seems to be correct as far as I can tell, I would try to make sure there is no bug introducing a bias. For every bounce, it checks if there is a ray hitting the light first, and if so it breaks out of the loop: in case the code is incorrect and it happens to hit the light more often than it should, the shadows will disappear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, in the first if:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;return false; //nothing hit, path non valid&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and the related loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int y = 0; y &amp;lt; SCRHEIGHT; y++) for (int x = 0; x &amp;lt; SCRWIDTH; x++)&#xA;{     &#xA;  Path path;&#xA;   if(generatePath(x,y, path)){&#xA;      Sample(path);&#xA;   }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Make sure you still take the paths that hit nothing into account when averaging the color of the pixel, otherwise this will also introduce a bias.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As joojaa said in the comment, you should try using a simpler scene: a few spheres or cubes, no texture. You can also reduce the number of bounces to one or two to see only direct lighting. If necessary, maybe even use a constant sky dome first instead of a light area.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Other remarks:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Path {&#xA;   PathVert verts[MAX_DEPTH]; //maxDepth is 15 for now&#xA;   int vertCount;&#xA;   int x, y; //which pixel this path is referring to&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Do you need to store x and y?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float distFromObj = length(vert.p);&#xA;float distFromLight = length(hitLightPoint);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Don't you already have two &lt;code&gt;t&lt;/code&gt; that you can compare?&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-04-11T01:58:24.743" LastActivityDate="2016-04-11T01:58:24.743" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2283" PostTypeId="1" AcceptedAnswerId="2284" CreationDate="2016-04-07T22:22:11.080" Score="5" ViewCount="234" Body="&lt;p&gt;I am trying to implement this formula to generate bump but I am facing some issue. The result doesn't look the same it's much darker.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kUWt5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kUWt5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my result (without same parameters) but it is much darker and I don't get why.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9GUF2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9GUF2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is the associated code.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// randx, randy and frequencies are array with some random values for each sin wave.&#xA;for (int x = 0; x &amp;lt; _width; ++x)&#xA;{&#xA;    for (int y = 0; y &amp;lt; _height; ++y)&#xA;    {&#xA;        float color = 0.0f;&#xA;        for (int i = 0; i &amp;lt; _iterations; ++i)&#xA;        {&#xA;            val += Mathf.Sin(Mathf.Sqrt(Mathf.Pow(x - randx[i], 2.0f) + Mathf.Pow(y - randy[i], 2.0f)) * 1.0f / (2.08f + 5.0f * frequencies[i]));&#xA;        }&#xA;        color /= (float)_iterations;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any idea why I am getting this result ?&lt;br&gt;&#xA;Thanks a lot !&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: Thanks to @trichoplax it works by doing this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float tmp = Mathf.Sin(Mathf.Sqrt(Mathf.Pow(x - randx[i], 2.0f) + Mathf.Pow(y - randy[i], 2.0f)) * 1.0f / (2.08f + 5.0f * frequencies[i]));&#xA;tmp = tmp * 0.5f + 0.5f;&#xA;val += tmp;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-04-08T12:17:27.073" LastActivityDate="2016-04-08T12:17:27.073" Title="Sine-based Tiled Procedural Bump" Tags="&lt;texture&gt;&lt;shader&gt;&lt;mathematics&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2284" PostTypeId="2" ParentId="2283" CreationDate="2016-04-07T23:10:28.537" Score="8" Body="&lt;p&gt;As you are taking the mean of a number of sine waves, your colour values will range from -1 to 1. From your example image, it looks like only the top half of this range of values (from 0 to 1) is resulting in colour, with everywhere else remaining black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If whatever you are using to display the result can only handle positive values, then you will need to convert the result to the correct range of values. For example, to convert from the range [-1 to 1] into the range [0 to 1], you would add 1 and divide by 2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the context of your example code, this could be by following the line&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color /= (float)_iterations;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color += 1;&#xA;color /= 2;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-04-07T23:10:28.537" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2285" PostTypeId="1" AcceptedAnswerId="2289" CreationDate="2016-04-08T05:13:10.747" Score="19" ViewCount="6362" Body="&lt;p&gt;As far as I understand, in a BRDF the Fresnel term is telling us the probability for a photon to be reflected or refracted when it hits a surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reflected photons will contribute to the specular term, while the refracted ones will contribute to the diffuse term. Therefore when determining, in a physically based manner, the contribution of a light to the color of material, I feel tempted to just write:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Assuming for example:&#xA;//   diffuse = dot(L, N);&#xA;//   specular = pow(dot(H, N), alpha) * (alpha + 2.0) / 8.0;&#xA;//   fresnel = f0 + (1.0 - f0) * pow(1.0 - dot(E, H), 5.0);&#xA;color = lightIntensity * Lerp(diffuse * albedo, specular, fresnel);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Yet, I don't think I've ever seen it written this way. I have seen the specular term being weighted according to the Fresnel term, but not the diffuse one. In his largely referenced &lt;a href=&quot;https://seblagarde.wordpress.com/2011/08/17/hello-world/&quot;&gt;article on PBR&lt;/a&gt;, Sébastien Lagarde even states that using $(1 - F)$ to weight the diffuse term is incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I missing?&lt;br/&gt;&#xA;I would much welcome an explanation that highlights in an obvious manner why this would be incorrect.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-04-11T20:25:29.450" Title="How to properly combine the diffuse and specular terms?" Tags="&lt;brdf&gt;&lt;specular&gt;&lt;pbr&gt;&lt;diffuse&gt;&lt;fresnel&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="2286" PostTypeId="2" ParentId="2285" CreationDate="2016-04-08T05:19:06.857" Score="8" Body="&lt;p&gt;While browsing to properly write my question, I actually &lt;a href=&quot;https://seblagarde.wordpress.com/2011/08/17/hello-world/#comment-2405&quot;&gt;found the answer&lt;/a&gt;, which happens to be very simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another Fresnel term is also going to weight in as the photons make their way out of the material (so being refracted into the air) and become the diffuse term. Thus the correct factor for the diffuse term would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(1 - F_{in}) * (1 - F_{out})$$&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-04-08T05:19:06.857" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2287" PostTypeId="2" ParentId="2010" CreationDate="2016-04-08T06:34:40.257" Score="4" Body="&lt;p&gt;For modern GPUs it's commonly stored in VRAM which for discrete GPUs are separate from the CPU memory. This usually means there is a penalty associated with letting the CPU access this as the data typically has to be copied across some bus. Mobile devices tend to use shared RAM for both GPU and CPU.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2016-04-08T06:34:40.257" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2288" PostTypeId="1" AcceptedAnswerId="2295" CreationDate="2016-04-08T10:13:43.037" Score="4" ViewCount="1024" Body="&lt;p&gt;I want to generate video similar to OSX Flurry screensaver (&lt;a href=&quot;https://i.imgur.com/yEFvLTr.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;screenshot&lt;/a&gt;, &lt;a href=&quot;https://youtu.be/JWzBK87t19U&quot; rel=&quot;nofollow noreferrer&quot;&gt;video&lt;/a&gt;), but I have no idea how it is made. Does anyone here has an idea about how it's made, its algorithm and method?&lt;/p&gt;&#xA;" OwnerUserId="3074" LastEditorUserId="3074" LastEditDate="2016-04-08T10:24:24.723" LastActivityDate="2018-11-02T21:08:20.193" Title="How to generate OSX Flurry screensaver" Tags="&lt;algorithm&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2289" PostTypeId="2" ParentId="2285" CreationDate="2016-04-08T11:41:51.023" Score="15" Body="&lt;p&gt;Using two Fresnel terms is correct in the sense that any given diffuse path will pass through the surface twice. If you're solving diffusion by tracing a path through the medium until it bounces out again then that you will get two (or more) Fresnel terms for that path as it interacts with the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, that's not what you're doing with a diffuse BRDF. A diffuse BRDF is intended to represent the average of all those possible diffusion paths. In the case of an Lambertian that average is modeled as uniform reflection and a single albedo value measuring the internal energy loss during diffusion, but more complicated models are possible. Crucially: a diffuse BRDF will already include the aggregate effect of some paths being reflected back into the medium to diffuse further and some passing out immediately. $1 - F_{out}$ is already &quot;baked in&quot; to the BRDF¹ and you do not need factor it in again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What the Lambertian term does not include is the portion of energy that is lost by being reflected before light enters the medium of diffusion. This is view-dependent, but depends on the precise glossy lobe above it. There is no energy loss at a (non-metallic) surface interface so everything that isn't reflected will be refracted, meaning that what you actually want is to integrate the total energy loss at the surface over all outgoing directions, i.e. $1 - \int \texttt{glossy_bsdf}(\texttt{in}, \texttt{out}) \: \mathrm{d} \texttt{out}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's possible to pre-compute approximations to that integral for specific BRDFs. The end result will in general depend on view direction, material roughness and IOR at least. As a first approximation you can assume that the glossy lobe is a perfectly specular reflector. That gives a weighting of $1 - \int \texttt{glossy} \: \mathrm{d}\texttt{out} = 1 - F_{in}$, which is exactly what you first suggested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, note that the Lambertian BRDF is the albedo divided by $\pi$ and that the cosine term is a measure of how attenuated the incoming light is on the surface; it applies to both glossy and diffuse reflectance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, roughly:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Assuming for example:&#xA;//   diffuse = albedo / PI;&#xA;//   specular = my_favorite_glossy_brdf(in_dir, out_dir, roughness);&#xA;//   fresnel = f0 + (1.0 - f0) * pow(1.0 - dot(E, H), 5.0);&#xA;//   total_surface_reflection = fresnel&#xA;color = lightIntensity * dot(L, N) * Lerp(diffuse, specular, total_surface_reflection);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;¹ &lt;em&gt;Really the integral of $F$ over all possible incident internal diffusion exit paths that result in your out direction, but I digress.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="3075" LastEditorUserId="3075" LastEditDate="2016-04-11T20:25:29.450" LastActivityDate="2016-04-11T20:25:29.450" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2290" PostTypeId="2" ParentId="2087" CreationDate="2016-04-08T12:52:30.253" Score="0" Body="&lt;p&gt;If multi-texturing is supported, texture coordinate generation will affect the active texture unit (quote from the documentation, emphasis is mine):&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;When the ARB_multitexture extension is supported, &lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glTexGen.xml&quot; rel=&quot;nofollow&quot;&gt;glTexGen&lt;/a&gt; sets the texture generation parameters &lt;strong&gt;for the currently active texture unit, selected with glActiveTexture&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So you simply need to make sure texture coordinates generation is disabled for the color texture, but enabled for the shadow texture. As you guessed, this is done with &lt;a href=&quot;https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;glActiveTexture()&lt;/code&gt;&lt;/a&gt;, by writing for example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glActiveTexture(GL_TEXTURE0); // Assuming the color texture to be #0&#xA;glDisable(GL_TEXTURE_GEN_S);&#xA;glDisable(GL_TEXTURE_GEN_T);&#xA;glDisable(GL_TEXTURE_GEN_R);&#xA;glDisable(GL_TEXTURE_GEN_Q);&#xA;&#xA;glActiveTexture(GL_TEXTURE1); // Assuming the shadow texture to be #1&#xA;glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);&#xA;glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));&#xA;glEnable(GL_TEXTURE_GEN_S);&#xA;// [...]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This being said, you're adding to yourself a lot of trouble by sticking with fixed pipeline instead of using GLSL.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-04-08T12:52:30.253" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2291" PostTypeId="2" ParentId="2279" CreationDate="2016-04-08T14:06:10.073" Score="6" Body="&lt;h2&gt;The problem appears to be unintentionally transparent surfaces&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Although the image is grainy, it is sufficiently clear to estimate that all of the darker regions are due to surfaces facing away from the light, rather than due to shadows cast onto surfaces facing towards the light. So it does seem that there is a problem, and the lack of shadows is not just due to having soft shadows from a large area light that don't show up well, or excessively reflective surfaces that provide too much ambient light. Somehow light is getting through your surfaces.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;The probable source of this problem&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Since you check for intersection with the light and the objects separately, the crucial point where this could go wrong is where you check&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (distFromLight &amp;lt; distFromObj)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You correctly terminate the path and return the light colour if this check is true (that is, if the light is closer than the nearest object in that direction). So the problem is likely to be with one of the two variables you are comparing. If they were both correct, then you would see shadows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These are calculated on the preceding lines&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float distFromObj = length(vert.p);&#xA;float distFromLight = length(hitLightPoint);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As pointed out in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/2281/231&quot;&gt;Julien Guertault's answer&lt;/a&gt;, these calculations may be redundant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;length(vert.p)&lt;/code&gt; should still be available as &lt;code&gt;t&lt;/code&gt;, used 11 lines previously in the calculation of &lt;code&gt;vert.p&lt;/code&gt;. This not only avoids unnecessary calculation, but eliminates a potential source of error. Then this length is likely to be correct unless there is a problem with &lt;code&gt;checkIfRayIntersectSomething()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This leaves only &lt;code&gt;length(hitLightPoint)&lt;/code&gt; as a source of error, unless there is a more subtle problem. It would be useful to be able to eliminate the possibility of problems with &lt;code&gt;length()&lt;/code&gt; or &lt;code&gt;hitLightPoint&lt;/code&gt;, which is calculated by &lt;code&gt;checkRayLightIntersection()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;We need to see the code to be able to help&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;length()&lt;/code&gt;, &lt;code&gt;checkIfRayIntersectSomething()&lt;/code&gt; and &lt;code&gt;checkRayLightIntersection()&lt;/code&gt; are not currently included with the code in your question, so we can't analyse these. If you are able to share these that would help narrow down the source of the problem.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;A simple way to check whether this is the real problem&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;You could also verify whether this analysis of the problem is correct by rendering a scene which will eliminate the other possibilities (shadows too soft to distinguish, or shadows washed out by too much reflected light from the rest of the scene). If the light getting through the surfaces is the source of your problem, then it will apply even if there is no path from the light to a surface, provided that surface is facing the light. So render a simple scene that has a light with a plane beneath it, and another plane beneath that, separated by a gap big enough to easily be seen. The lower plane is completely occluded by the upper plane, so should receive no light (no soft shadows and no reflected light from elsewhere). If the lower plane is lit, then you know that this is indeed the problem and you can focus your efforts here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the lower plane is &lt;em&gt;not&lt;/em&gt; lit, then either this is not the problem, or there is a problem with the scale and the occluding plane may need to be at a different distance from the light in order for the problem to show up. You can use your existing scene as a source of estimated distances for which this problem occurs, and you can use inclined planes in order to see the effect for a variety of ratios of object distance to light distance within a single image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sharing the images resulting from such simple scenes may help us identify the problem more precisely.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I notice that in a comment on the question you mention that you do not have a straightforward way of generating scenes yourself. Perhaps there are much simpler scenes already publicly available in the same file format, that you can use to test this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If not, it sounds like the only thing you have control over is the light. In that case, you could try putting the light underground. If surfaces are not transparent, the scene should be uniformly black. If surfaces are being lit despite an occluding surface, you may see evidence for it this way that would be hard to discern when there is lots of secondary light bouncing around.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-04-10T22:48:51.737" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2294" PostTypeId="2" ParentId="2221" CreationDate="2016-04-08T19:21:25.237" Score="1" Body="&lt;p&gt;A common mistake that causes this behavior is to first apply the translation and then the rotation when rendering the scene. I think that's what's happening. If you apply the rotation first and then the translation it should behave as expected. Give that a try&lt;/p&gt;&#xA;" OwnerUserId="3083" LastActivityDate="2016-04-08T19:21:25.237" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2295" PostTypeId="2" ParentId="2288" CreationDate="2016-04-09T09:10:49.433" Score="6" Body="&lt;p&gt;Looking at the video you provided, I would tend to think it's something along those lines:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A particle emitter, to which all threads are attached, is moving around. I haven't really figured what its motion is dictated by.&lt;/li&gt;&#xA;&lt;li&gt;Each thread is made of particles flowing away from the emitter. The thread has a direction, used for the initial speed of the particles. Once created,  they are independent from the emitter.&lt;/li&gt;&#xA;&lt;li&gt;The particles use a quad or a rectangle textured with a fuzzy ellipse shape (you can see them individually when a thread suddenly changes direction) oriented in the direction of the motion. Their color is based on the duration since their creation, and they use additive alpha blending (the saturation to white is typical). After a certain duration, they fade out and die, only to be recycled into new particles.&lt;/li&gt;&#xA;&lt;li&gt;I suspect the whole thing might be in a vector field, or something similar blowing wind onto the particles, which would explain why the threads sometimes suddenly change direction.&lt;/li&gt;&#xA;&lt;li&gt;There might be some feedback post-processing effect to smooth everything out.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-04-09T09:10:49.433" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2296" PostTypeId="2" ParentId="2166" CreationDate="2016-04-10T02:55:44.603" Score="5" Body="&lt;p&gt;The short answer is It's Complicated™. :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A lot of factors can affect frame timing (and the associated problem of animation juddering, due to the game's animation delta-times not matching actual frame delivery times). Some of the factors are: how CPU-limited versus GPU-limited the game is, how the game's code measures time, how much variability there is in frame time on both the CPU and GPU, how many frames of queue-ahead the CPU is allowed to build up, double versus triple buffering, and driver behavior.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the specific question of whether you get locked to a divisor of 60 fps (30, 20, 15, etc), this seems to depend mainly on whether the application is GPU-limited or CPU-limited. If you're GPU-limited, then assuming the application is running steadily (not producing any hitches or rapid performance shifts in itself), it does lock to the highest divisor of the vsync rate that it can sustain. This timing diagram shows how it works:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Rm3tV.png&quot; alt=&quot;vsync in GPU limited case&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Time runs from left to right and the width of each block represents the duration of one frame's work. After the first few frames, the system settles into a state where the frames are turned out at a steady rate, one every two vsync periods (i.e. if vsync was 60 Hz, the game would be running at exactly 30 fps).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note the empty spaces (idle time) in both CPU and GPU rows. That indicates that the game could run faster if vsync were turned off. However, with vsync on, the swapchain puts back-pressure on the GPU&amp;mdash;the GPU can't start rendering the next frame until vsync releases a backbuffer for it to render into. The GPU in turn puts back-pressure on the CPU via the command queue, as the driver won't return from &lt;code&gt;Present()&lt;/code&gt; / &lt;code&gt;SwapBuffers()&lt;/code&gt; until the GPU starts rendering the next frame, and opens a queue slot for the CPU to continue issuing commands. The result is that everything runs at a steady 30 fps rate, and everyone's happy (except maybe the 60fps purist gamer ).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compare this to what happens when the application is CPU-limited:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/mXZJo.png&quot; alt=&quot;vsync in CPU-limited case&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This time we ended up with the game running at 36 fps, the maximum speed possible given the CPU load in this case. But this isn't a divisor of the refresh rate, so we get uneven frame delivery to the display, with some frames shown for two vsync periods and some for only one. This will cause judder.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here the GPU goes idle because it's waiting for the CPU to give it more work&amp;mdash;not because it's waiting for a backbuffer to be available to render into. The swapchain thus doesn't put back-pressure on the GPU (or at least doesn't do so consistently), and the GPU in turn doesn't put back-pressure on the CPU. So the CPU just runs as fast as it can, oblivious to the irregular frame times appearing on the display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's possible to &quot;fix&quot; this so that the game still discretizes to vsync-friendly rates even in the CPU-limited case. The game code could try to recognize this situation and compensate by sleeping its CPU thread to artificially lock itself to 30 fps, or by increasing its swap interval to 2. Alternatively, the driver could do the same thing by inserting extra sleeps in &lt;code&gt;Present()&lt;/code&gt; / &lt;code&gt;SwapBuffers()&lt;/code&gt; (the NVIDIA drivers do have this as a control panel option; I don't know about others). But in any case, &lt;em&gt;someone&lt;/em&gt; has to detect the problem and do something about it; the game won't naturally settle on a vsync-friendly rate the way it does when it's GPU-limited.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This was all a simplified case in which both CPU and GPU workloads are perfectly steady. In real life, of course, there's variability in the workloads and frame times, which can cause even more interesting things to happen. The CPU render-ahead queue and triple buffering can come into play then.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-10T02:55:44.603" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2300" PostTypeId="1" CreationDate="2016-04-10T17:26:45.990" Score="3" ViewCount="1520" Body="&lt;p&gt;I am new to OpenGL and Computer Graphics in general. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lately I was learning how to model a camera, specifically how to model the rotation of camera. I was introduced to Euler angles for this purpose. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I got a rough idea about how to use Euler angles to model camera rotation from this &lt;a href=&quot;https://www.opengl.org/discussion_boards/showthread.php/133072-Camera-Position-Camera-Angle-Camera-Target-Position?p=986100&amp;amp;viewfull=1#post986100&quot; rel=&quot;nofollow&quot;&gt;post&lt;/a&gt;. Based on that, I wrote something like below:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat yaw, pitch;&#xA;...&#xA;void mouse_callback(GLFWwindow* window, double xpos, double ypos)&#xA;{&#xA;        /* &#xA;           Here I am updating the yaw, and pitch values &#xA;           based on mouse movement and previous mouse position&#xA;        */&#xA;&#xA;        glm::mat4 yawPitchRotMat;&#xA;        /* We want to do yaw * pitch. */&#xA;&#xA;        //y-axis as yaw axis&#xA;        yawPitchRotMat = glm::rotate(yawPitchRotMat, glm::radians(yaw), &#xA;                         glm::vec3(0.0f, 1.0f, 0.0f));&#xA;&#xA;        //x-axis as pitch axis&#xA;        yawPitchRotMat = glm::rotate(yawPitchRotMat, glm::radians(pitch), &#xA;                         glm::vec3(1.0f, 0.0f, 0.0f));&#xA;&#xA;        cameraFrontDirection = glm::normalize(-1.0f * &#xA;                 glm::vec3(yawPitchRotMat[2].x, yawPitchRotMat[2].y, yawPitchRotMat[2].z));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The above code seems to work. However, I would like to hear your opinion about this approach. Specially as my math is not really very strong, so any mathematical insight regarding Euler angles would be very helpful. Also appreciate any reference to online resource on the same, that is easy to understand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Though later I also came to know about certain limitation of modelling rotation using Euler angles and use quaternions instead. However I would like to save that topic for future discussion, as I am yet to read about that in details.&lt;/p&gt;&#xA;" OwnerUserId="3098" LastEditorUserId="3098" LastEditDate="2016-04-10T20:37:38.120" LastActivityDate="2016-04-12T14:35:32.873" Title="Computing camera front direction from Euler angles" Tags="&lt;opengl&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2301" PostTypeId="1" CreationDate="2016-04-10T22:53:17.550" Score="1" ViewCount="46" Body="&lt;p&gt;Hello everybody i have a trouble making datatransmition with mine program just to give the idea im trying to move this blocks when i move mine cars&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hiOLG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hiOLG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here I leave the encoding of mine server/client program &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;package com.mygdx.Xrace;&#xA;&#xA;import java.io.BufferedReader;&#xA;&#xA;import java.io.IOException;&#xA;&#xA;import java.io.InputStreamReader;&#xA;&#xA;import java.io.PrintWriter;&#xA;&#xA;import java.net.ServerSocket;&#xA;&#xA;import java.net.Socket;&#xA;&#xA;public class ScreenServidor extends Pantallabase{&#xA;&#xA;        ScreenCarrera carrera;&#xA;        MyTextInputListener listener;&#xA;        ServerSocket server ;&#xA;        float delta = 0.01f;&#xA;        int puerto=9600;&#xA;        public ScreenServidor(Main game) {&#xA;            super(game);&#xA;        }&#xA;        @Override       &#xA;        public void show()&#xA;        {&#xA;            carrera=new ScreenCarrera(game);&#xA;            carrera.show();&#xA;&#xA;            try {&#xA;                server = new ServerSocket(puerto);&#xA;                new User(server.accept()).start();&#xA;            } catch (IOException e) {&#xA;                 System.out.println(e);&#xA;                }finally{&#xA;                        try {&#xA;                            server.close();&#xA;                        } catch (IOException e) {&#xA;                             System.out.println(e);&#xA;                        }&#xA;                }&#xA;&#xA;        }   &#xA;&#xA;&#xA;        @Override&#xA;        public void render(float delta)&#xA;        {&#xA;            carrera.render(delta);&#xA;        }&#xA;        @Override&#xA;        public void dispose(){&#xA;            carrera.dispose();&#xA;            }&#xA;        @Override&#xA;        public void resize(int width, int height) {}&#xA;        @Override&#xA;        public void pause() {}&#xA;        @Override&#xA;        public void resume() {}&#xA;        @Override&#xA;        public void hide() {&#xA;        }&#xA;}&#xA;class User extends Thread{&#xA;&#xA;    BufferedReader in;&#xA;    PrintWriter out;&#xA;    Socket conexion;&#xA;    ScreenCarrera carrera;&#xA;    public User(Socket serv)&#xA;    {&#xA;        this.conexion=serv;&#xA;    }&#xA;    public void run() {&#xA;&#xA;        try {&#xA;&#xA;            in = new BufferedReader(new InputStreamReader(conexion.getInputStream())); &#xA;            out=new PrintWriter(conexion.getOutputStream(),true);&#xA;            **carrera.m.posx2=in.read();** //receiving data&#xA;            **out.print(carrera.m.posx1);**//sending data&#xA;            } catch (IOException e) {&#xA;                 System.out.println(e);&#xA;        }finally{&#xA;            try {&#xA;            in.close();&#xA;            out.close();&#xA;            conexion.close();&#xA;            } catch (IOException e) {}&#xA;    }&#xA;&#xA;    }&#xA;&#xA;}&#xA;&#xA;package com.mygdx.Xrace;&#xA;&#xA;import java.net.*;&#xA;&#xA;import java.io.*;&#xA;&#xA;import com.badlogic.gdx.Gdx;&#xA;&#xA;public class ScreenCliente extends Pantallabase{&#xA;&#xA;    Socket conexion;&#xA;    ScreenCarrera carrera;&#xA;    PrintStream out ;&#xA;    MyTextInputListener listener;&#xA;    BufferedReader in;&#xA;    float delta = 0.01f;&#xA;    int puerto=9600;&#xA;&#xA;    static String ip;&#xA;&#xA;    public ScreenCliente(Main game) {&#xA;        super(game);&#xA;    }&#xA;&#xA;    @Override&#xA;    public void show() {&#xA;        carrera=new ScreenCarrera(game);&#xA;        carrera.show();&#xA;        conexion=new Socket();&#xA;        listener = new MyTextInputListener();&#xA;        Gdx.input.getTextInput(listener, &quot;ingrese ip&quot;, ip, ip);&#xA;        try {&#xA;&#xA;            conexion =new Socket(ip,puerto);&#xA;            out = new PrintStream(conexion.getOutputStream(),true);&#xA;            in = new BufferedReader(new InputStreamReader(conexion.getInputStream()));&#xA;&#xA;        }catch(Exception e){e.printStackTrace();}&#xA;    }&#xA;    @Override&#xA;    public void render(float delta) {&#xA;        carrera.render(delta);&#xA;        try{&#xA;        **carrera.m.posx2=in.read()**;&#xA;        } catch (IOException e) {&#xA;            e.printStackTrace();&#xA;            game.m.mensaje=&quot;error de conexion&quot;;&#xA;            game.setScreen(game.m);&#xA;        }try {&#xA;            run();&#xA;        } catch (IOException e) {&#xA;            e.printStackTrace();&#xA;        }&#xA;&#xA;    }&#xA;    private void run() throws IOException{&#xA;&#xA;         **out.print(carrera.m.posx1);**&#xA;    }&#xA;&#xA;    @Override&#xA;    public void resize(int width, int height) {&#xA;    }&#xA;    @Override&#xA;    public void pause() {&#xA;    }&#xA;    @Override&#xA;    public void resume() {&#xA;    }&#xA;    @Override&#xA;    public void hide() {&#xA;    }&#xA;    @Override&#xA;    public void dispose() {&#xA;        carrera.dispose();&#xA;        try {&#xA;            in.close();&#xA;            out.close();&#xA;            conexion.close();&#xA;    } catch (IOException e) {&#xA;        e.printStackTrace();&#xA;    }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3101" LastEditorUserId="16" LastEditDate="2016-04-11T07:01:07.523" LastActivityDate="2016-04-11T07:01:07.523" Title="Trouble using java connectivity and data transmition on libgdx" Tags="&lt;javascript&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2016-04-16T06:49:49.237" ContentLicense="CC BY-SA 3.0" />
  <row Id="2302" PostTypeId="2" ParentId="2300" CreationDate="2016-04-12T14:35:32.873" Score="4" Body="&lt;p&gt;This kind of navigation works well for situations that are centered about objects. It keeps the up vector always pointing upward which makes it less possible for confusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bringing quaternions into this mix is not necessarily a good idea. People often totally exaggerate the problems of Euler angles (or taint Tait–Bryan angles). Its true that Euler did not even consider the implications in interpolating the angles. True you can get into big problems if you rotate angles into certain positions and interpolate angle by angle. But this didn't bother Euler so much as he did mathematical modeling where the problem cancels itself out.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;So Euler angles are perfectly fine for storing the rotation, also ok in differential rotation. And in case as no gimbal lock can really happen anyway, you get other problems before it. Euler angles are just not good at linear interpolation in a curved space. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;In this case there should not be any bigger problems. Euler angles are much easier to understand. Unless you need to interpolate between 2 recorded positions. However this is a no issue as your collection and interpolation dont need to be based on the same model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Its possible to look at this model in another light, you can think of it as a vector that records camera position in relation to a center as long as you keep the vector equal length you achieve same thing. You can then just form the matrix by multiplying by up vector and then that by front to get new up. This is even easier to interpolate unless you move trough the actual center but again you can keep normalizing the vector to a length.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-04-12T14:35:32.873" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2303" PostTypeId="1" AcceptedAnswerId="2304" CreationDate="2016-04-13T12:09:54.340" Score="13" ViewCount="8214" Body="&lt;p&gt;I have a vertex buffer like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.0, 0.0,&#xA;1.0, 0.0,&#xA;0.0, 0.6,&#xA;1.0, 0.6,&#xA;0.5, 1.0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have the following index buffer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0, 2,&#xA;2, 4,&#xA;4, 3,&#xA;3, 2,&#xA;2, 1,&#xA;1, 0,&#xA;0, 3,&#xA;3, 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I know I want to draw &lt;code&gt;gl.LINES&lt;/code&gt; using WebGL, means multiple seperated line segments.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.drawElements(gl.LINES, 16, gl.UNSIGNED_SHORT, indexBuffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It seems to enable drawing of multiple line segments in a single draw call in WebGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone ELI5 to me, what is an index buffer and how is it related to vertex buffers? How to generate index buffers from my primitives?&lt;/p&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-04-14T17:27:49.293" Title="What is an index buffer and how is it related to vertex buffers?" Tags="&lt;webgl&gt;&lt;line-drawing&gt;&lt;mapping&gt;&lt;vertex-buffer-object&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2304" PostTypeId="2" ParentId="2303" CreationDate="2016-04-13T12:42:50.983" Score="15" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Could someone ELI5 to me, what is an index buffer and how is it&#xA;  related to vertex buffers&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Your vertex buffer contains the X and Y coordinates of 5 vertices. They are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;index |  X  |  Y&#xA;  0   | 0.0 | 0.0 &#xA;  1   | 1.0 | 0.0&#xA;  2   | 0.0 | 0.6&#xA;  3   | 1.0 | 0.6&#xA;  4   | 0.5 | 1.0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Your index buffer contains information about which lines to draw between these vertices. It uses the index of each vertex in the vertex buffer as a value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you are drawing lines, each pair of consecutive values in your index buffer indicate a line segment. For example, if the index buffer starts with &lt;code&gt;0, 2&lt;/code&gt;, it means draw a line between the 0th and 2nd vertices in the vertex array, which in this case would draw a line going from &lt;code&gt;[0.0, 0.0]&lt;/code&gt; to &lt;code&gt;[0.0, 0.6]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the following graphic each pair of indices is color coordinated with the line it indicates:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0H9FS.png&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0H9FS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, if you were drawing triangles instead of lines, you would need to supply an index buffer where each 3 consecutive values indicate the indices of three vertices in the vertex buffer, e.g. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0, 1, 2,&#xA;2, 1, 3,&#xA;2, 3, 4,&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="457" LastEditorUserId="457" LastEditDate="2016-04-14T17:27:49.293" LastActivityDate="2016-04-14T17:27:49.293" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2305" PostTypeId="2" ParentId="2303" CreationDate="2016-04-13T12:48:19.650" Score="6" Body="&lt;p&gt;If you have a vertex buffer like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var vertices = [&#xA;  0.0, 0.0, 0.0,&#xA;  1.0, 0.0, 0.0,&#xA;  0.0, 0.6, 0.0,&#xA;  1.0, 0.6, 0.0,&#xA;  0.5, 1.0, 0.0&#xA;]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And simply draw it as it is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Create an empty buffer object&#xA;var vertex_buffer = gl.createBuffer();&#xA;&#xA;// Bind appropriate array buffer to it&#xA;gl.bindBuffer(gl.ARRAY_BUFFER, vertex_buffer);&#xA;&#xA;// Pass the vertex data to the buffer&#xA;gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);&#xA;&#xA;/* [...] */&#xA;&#xA;// Draw the lines&#xA;gl.drawArrays(gl.LINES, 0, 5);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It would require two dedicated coordinates for each line segment. With the &lt;code&gt;vertices&lt;/code&gt; as defined above, it would only be possible two draw &lt;strong&gt;two lines&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HTDG6.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HTDG6.png&quot; alt=&quot;two lines&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have the following indices defined:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var indices = [&#xA;  0, 2,&#xA;  2, 4,&#xA;  4, 3,&#xA;  3, 2,&#xA;  2, 1,&#xA;  1, 0,&#xA;  0, 3,&#xA;  3, 1&#xA;]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It is possible to draw lines which intersect the same vertices again and again. This reduces redundancy. If you bind the index buffer and tell the GPU to draw line segments connecting the vertices by the order specified in the indecies array:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var index_buffer = gl.createBuffer();&#xA;&#xA;gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, index_buffer);&#xA;&#xA;gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indices), gl.STATIC_DRAW);&#xA;&#xA;// draw geometry lines by indices&#xA;gl.drawElements(gl.LINES, 16, gl.UNSIGNED_SHORT, index_buffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;One can draw complexer figures without redefining the same vertices over and over again. This is the result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oBLfK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oBLfK.png&quot; alt=&quot;a house&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To achieve the same result without indices, the vertex buffer should look like the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var vertices = [&#xA;  0.0, 0.0, 0.0,&#xA;  0.0, 0.6, 0.0,&#xA;  0.0, 0.6, 0.0,&#xA;  0.5, 1.0, 0.0,&#xA;  0.5, 1.0, 0.0,&#xA;  1.0, 0.6, 0.0,&#xA;  1.0, 0.6, 0.0,&#xA;  0.0, 0.6, 0.0,&#xA;  0.0, 0.6, 0.0,&#xA;  1.0, 0.0, 0.0,&#xA;  1.0, 0.0, 0.0,&#xA;  0.0, 0.0, 0.0,&#xA;  0.0, 0.0, 0.0,&#xA;  1.0, 0.6, 0.0,&#xA;  1.0, 0.6, 0.0,&#xA;  1.0, 0.0, 0.0&#xA;]&#xA;&#xA;/* [...] */&#xA;&#xA;// Draw the lines&#xA;gl.drawArrays(gl.LINES, 0, 16);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which results in the same image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QOezA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QOezA.png&quot; alt=&quot;yet another house&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note the huge redundancy in stored vertices. &lt;/p&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-04-13T12:48:19.650" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2306" PostTypeId="1" AcceptedAnswerId="2307" CreationDate="2016-04-13T21:53:50.753" Score="5" ViewCount="226" Body="&lt;p&gt;What is the best way to draw unlit objects with deferred? Like skybox, particles or just glowing objects?&#xA;I thought about mask in alpha channel, check it in light pass and just set diffuse color but it won't work with light blending.&#xA;My second idea was stencil buffer with pass after light pass that only fill unlit space. But switching pso (dx12) only for color copy doesn't sound like a good idea.&#xA;And of course pass only for unlit objects after light pass, but I don't want to create another list only for this (and again, i have to switch pso).&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2016-04-14T03:21:57.747" Title="Unlit objects in deferred rendering" Tags="&lt;lighting&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2307" PostTypeId="2" ParentId="2306" CreationDate="2016-04-14T03:21:57.747" Score="7" Body="&lt;p&gt;Typically in a deferred engine, you would render unlit objects directly to the color buffer, bypassing the lighting system entirely. You would likely also output zeroes to the G-buffer so that deferred lights don't add anything to those pixels (and possibly also mark them in the stencil buffer, to avoid running the lighting shaders on them, for efficiency).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't worry about switching PSOs for this. I'm guessing you're worried about the performance, but it's not a big deal. Game engines typically switch PSOs (or switch shaders, in DX11/GL) hundreds or thousands of times per frame. Switching a couple of times for an extra color rendering pass isn't even a blip on the radar.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you want to really simplify your code (possibly at the expense of performance), you could just bind the color buffer together with your G-buffers and render to it all the time, as if it were an extra G-buffer. Ordinary deferred shaders would output zero to it, while unlit objects would output their color to it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-14T03:21:57.747" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2308" PostTypeId="1" CreationDate="2016-04-14T07:02:25.657" Score="4" ViewCount="153" Body="&lt;p&gt;A 3D model is sliced against a plane and the resulting 2D contour is projected onto the plane. I am looking for an efficient algorithm to identify the inside and outside region of the contour. Simultaneously I need to identify outer and inner loops within the contours. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any references from articles/books is earnestly requested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-04-14T08:11:28.427" Title="inside and outside region identification from 2D contour" Tags="&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2309" PostTypeId="2" ParentId="2308" CreationDate="2016-04-14T08:11:28.427" Score="3" Body="&lt;p&gt;In general, I recommend the book &lt;a href=&quot;http://realtimecollisiondetection.net/&quot; rel=&quot;nofollow&quot;&gt;Real-Time Collision Detection&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your particular case, my first choice would be to use the 3D test for point-inside-mesh. I assume that the contour is a sequence of 2D segments (a sequence of vertices, essentially) and that the model mesh is &quot;sealed&quot;, i.e. there are no holes in its surfaces that would make distinguishing the &quot;inside&quot; and &quot;outside&quot; of it impossible.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Find a bounding box for your mesh.&lt;/li&gt;&#xA;&lt;li&gt;Cast rays from an edge of the bounding box to the tested point. In your case, the ray would be coplanar with the slicing plane, and the point would be one of the vertices of the contour.&lt;/li&gt;&#xA;&lt;li&gt;Count how many times the ray crosses mesh triangles.&lt;/li&gt;&#xA;&lt;li&gt;Odd number of crossings means that the point is on the inside; even number means it's on the outside.&lt;/li&gt;&#xA;&lt;li&gt;Repeat points 2-4 for all contour vertices.&lt;/li&gt;&#xA;&lt;li&gt;Classify contour regions by whether their vertices are on the inside or outside.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-04-14T08:11:28.427" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2310" PostTypeId="1" AcceptedAnswerId="2323" CreationDate="2016-04-14T09:15:04.660" Score="4" ViewCount="1111" Body="&lt;p&gt;Would it be, at least theoretically, possible to render without a near clipping plane? Could raytracing ignore this perchance? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quite many budding 3d artists have a &lt;em&gt;WTF&lt;/em&gt; moment the first time they encounter the clipping plane. If this could be avoided then it would be a big win for usability of 3D authoring apps. Its not one of those things a normal artist would think about until explained.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-04-17T19:31:05.250" Title="Could we dispense the near clipping plane?" Tags="&lt;raytracing&gt;&lt;clipping&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2311" PostTypeId="2" ParentId="2310" CreationDate="2016-04-14T10:15:00.100" Score="5" Body="&lt;p&gt;The near clipping plane in rasterizing setups with perspective projection is there to avoid a divide by 0 and bound the possible depths for orthogonal projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With a bit of extra math you can make the depth stored in the depth buffer linear again. However you still need the guard against the divide by 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In raytracing the near plane can be at 0 no problem. There is nothing technical stopping you from putting it at -10 however (besides that it would be very odd).&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-04-14T10:15:00.100" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2314" PostTypeId="1" AcceptedAnswerId="2341" CreationDate="2016-04-15T14:29:35.037" Score="4" ViewCount="2341" Body="&lt;p&gt;This might be a general question but I have some difficulties about understanding baked bent normal maps and how to use it inside a shader in Unity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I understand, bent normals are especially used with occlusion but I don't really get what they contain and how to use them.&#xA;The other strange thing is that when baking them with different tools, it gives me different output, so it's hard for me to interpret them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some examples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tHXeT.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tHXeT.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;This is made from Substance Designer in World Space. Seems really close to a simple normal map in World Space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1AAcV.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1AAcV.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;This is made from Substance Designer in Tangent Space. It doesn't seem to contain really relevant informations as the one above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Zenrb.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Zenrb.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;This is made from Maya Turtle. It seems to contain interesting information but... what space is that ?!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BCZmP.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BCZmP.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;This is the same as the one above but converted to Unity using Handplane. What can I do with this...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems that Unity is using tangent space normal maps but I don't have any control on the import process and I don't know what they are doing. Regular normals are then unpacked in converted into world space normals using TBN matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fact is that at this point, any clue or advice should be really useful.&#xA;I don't know if my baked maps are right or usable and I don't know how to use them inside my shader.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-04-15T15:16:12.770" LastActivityDate="2016-04-20T05:44:23.073" Title="How could I use bent normal map" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;texture&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2315" PostTypeId="1" CreationDate="2016-04-16T11:26:50.253" Score="0" ViewCount="4495" Body="&lt;p&gt;I need to load a model &quot;somemodel.json&quot; into my &quot;movie.js&quot;.Can someone tell me where i am going wrong.I followed the steps given &lt;a href=&quot;http://threejs.org/docs/#Reference/Loaders/ObjectLoader&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-html prettyprint-override&quot;&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&#xA;&amp;lt;html&amp;gt;&#xA;    &amp;lt;head&amp;gt;&#xA;         &amp;lt;meta charset=utf-8&amp;gt;&#xA;         &amp;lt;title&amp;gt;Test&amp;lt;/title&amp;gt;&#xA;         &amp;lt;style&amp;gt;&#xA;            body { margin: 0; }&#xA;            canvas { width: 100%; height: 100% }&#xA;         &amp;lt;/style&amp;gt;&#xA;    &amp;lt;/head&amp;gt;&#xA;    &amp;lt;body&amp;gt;&#xA;        &amp;lt;script src=&quot;three.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;        &amp;lt;script src=&quot;ObjectLoader.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;        &amp;lt;script src=&quot;movie.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;    &amp;lt;/body&amp;gt;&#xA;&amp;lt;/html&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;movie.js&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;var camera;&#xA;var scene;&#xA;var renderer;&#xA;var loader;&#xA;&#xA;frame();&#xA;animate();&#xA;&#xA;function frame() {&#xA;&#xA;scene = new THREE.Scene();&#xA;camera = new THREE.PerspectiveCamera( 45, window.innerWidth /     window.innerHeight, 0.1, 1000);&#xA;camera.position.y = 0;&#xA;camera.position.z = 10;&#xA;camera.rotation.x = 0;&#xA;&#xA;var loader = new THREE.ObjectLoader();&#xA;loader.load(&#xA;'somemodel.json',&#xA;function () {&#xA;    var geometry = new THREE.SphereGeometry(3,32,32);&#xA;    var material = new THREE.MeshBasicMaterial();&#xA;    var object = new THREE.Mesh( geometry, material );&#xA;    scene.add( object );&#xA;}&#xA;);&#xA;&#xA;renderer = new THREE.WebGLRenderer();&#xA;renderer.setSize( window.innerWidth, window.innerHeight );&#xA;document.body.appendChild( renderer.domElement );&#xA;render();&#xA;}&#xA;&#xA;function animate() {&#xA;render();&#xA;requestAnimationFrame( animate );&#xA;}&#xA;&#xA;function render() {&#xA;renderer.render( scene, camera );&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Or can your give an example with a sample model ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When i run my file it raises an error in the console saying &lt;code&gt;not well-formed        male.json&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="3141" LastEditorUserId="3141" LastEditDate="2016-04-16T12:10:44.253" LastActivityDate="2020-01-06T03:51:50.203" Title="How to load a model in .json in three.js" Tags="&lt;webgl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2316" PostTypeId="1" CreationDate="2016-04-16T21:40:19.773" Score="22" ViewCount="7406" Body="&lt;p&gt;I have seen that in some implementations of Path Tracing, an approach called Russian Roulette is used to cull some of the paths and share their contribution among the other paths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that rather than following a path until it drops below a certain threshold value of contribution, and then abandoning it, a different threshold is used and paths whose contribution is below that threshold are only terminated with some small probability. The other paths have their contribution increased by an amount corresponding to sharing the lost energy from the terminated path. It isn't clear to me whether this is to correct a bias introduced by the technique, or whether the whole technique is itself necessary to avoid bias.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Does Russian Roulette give an unbiased result?&lt;/li&gt;&#xA;&lt;li&gt;Is Russian Roulette &lt;em&gt;necessary&lt;/em&gt; for an unbiased result?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;That is, would using a tiny threshold and just terminating a path the moment it drops below that threshold give a more biased or less biased result?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given an arbitrarily large number of samples, would both approaches converge on an unbiased resulting image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking to understand the underlying reason for using the Russian Roulette approach. Is there a significant difference in speed or quality?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I understand that the energy is redistributed among other rays in order to preserve total energy. However, could this redistribution not still be done if the ray were terminated on dropping below a fixed threshold, rather than having a randomly determined life span after reaching that threshold?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Conversely, if the energy that would be lost by terminating a ray without redistributing its energy is eventually lost anyway (as the rays to which it is redistributed are also eventually terminated), how does this improve the situation?&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-04-17T13:07:37.037" LastActivityDate="2017-11-02T00:35:37.813" Title="Is Russian Roulette really the answer?" Tags="&lt;monte-carlo&gt;&lt;pathtracing&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="16" ContentLicense="CC BY-SA 3.0" />
  <row Id="2317" PostTypeId="2" ParentId="2315" CreationDate="2016-04-16T23:14:54.010" Score="2" Body="&lt;p&gt;The error &lt;code&gt;not well-formed        male.json&lt;/code&gt; doesn't appear to have anything to do with the code you've posted. I don't see any references to a JSON file called &lt;code&gt;male.json&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this file is in your code somewhere, the error is telling you the problem. It is malformed. Paste the contents of the file into an online validation tool such as &lt;a href=&quot;http://jsonlint.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;JSONLint&lt;/a&gt;. It will tell you what is making it malformed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, you're passing JSON into &lt;code&gt;ObjectLoader.load&lt;/code&gt; but you don't do anything with the results. Instead try this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var loader = new THREE.ObjectLoader();&#xA;loader.load('somemodel.json', function (object) {&#xA;    scene.add(object);&#xA;});&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Check out &lt;a href=&quot;https://threejs.org/docs/#api/en/loaders/ObjectLoader&quot; rel=&quot;nofollow noreferrer&quot;&gt;the documentation&lt;/a&gt; for more information.&lt;/p&gt;&#xA;" OwnerUserId="3143" LastEditorUserId="-1" LastEditDate="2020-01-06T03:51:50.203" LastActivityDate="2020-01-06T03:51:50.203" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="2318" PostTypeId="1" AcceptedAnswerId="2319" CreationDate="2016-04-16T23:42:21.557" Score="1" ViewCount="295" Body="&lt;p&gt;I found many sites, books and articles, all about especifics algorithms, I listed some of them (like &lt;em&gt;bounding boxes&lt;/em&gt;, &lt;em&gt;bounding spheres&lt;/em&gt;, &lt;em&gt;octrees&lt;/em&gt; and &lt;em&gt;KD-tree&lt;/em&gt;), but any of these founds lists every algorithm for collision detection, and thats what I need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Someone knows the name of all algorithms (or at least some of them, any other algorithm would help) for collision detection, or knows where I can find it?&lt;/p&gt;&#xA;" OwnerUserId="3144" LastActivityDate="2016-04-16T23:53:54.400" Title="Collision detection methods for 2D and 3D environments" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2016-04-17T08:43:38.453" ContentLicense="CC BY-SA 3.0" />
  <row Id="2319" PostTypeId="2" ParentId="2318" CreationDate="2016-04-16T23:53:54.400" Score="2" Body="&lt;p&gt;There is a book about real-time collision detection that contains a variety of algorithms for all sorts of intersection tests and lists a large number of collision detection algorithms. It's a decent overview if that's what you are looking for:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://realtimecollisiondetection.net&quot; rel=&quot;nofollow&quot;&gt;http://realtimecollisiondetection.net&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://books.google.com/books?isbn=0080474144&quot; rel=&quot;nofollow&quot;&gt;https://books.google.com/books?isbn=0080474144&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3145" LastActivityDate="2016-04-16T23:53:54.400" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2320" PostTypeId="1" CreationDate="2016-04-17T11:42:57.663" Score="5" ViewCount="860" Body="&lt;p&gt;I am trying to implement for research purposes a path tracer, but so far but results are not so good and I will explain you why. The general idea before getting to the code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am working on paths that are generated before sampling them. I mean that the first step of my algorithm consists in calculating a path for a certain pixel (x,y). This path will perform some bounces within the scene and, if terminates on the light, will be considered valid, which means that I can calculate its contribution for the pixel (x,y) which otherwise will be black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But first, my aim is to reach an &quot;acceptable&quot; image with a few number of SPP (around 16-32 spp). This is because I am following the code of a target framework, easy implemented, that manages to reach such good results in few steps (explained later). The following is the  target image that I want to reach, produced by the target framework:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QHG2z.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QHG2z.jpg&quot; alt=&quot;Target image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's rendered with 16SPP. The core code behind it is quite straightforward. It just implements the rendering equation and it is shown and commented below:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec Sample(vec3 O, vec3 D, int depth)//oriding, direction, depth of the recursive step&#xA;{&#xA;  vec3 color(0, 0, 0);&#xA;  float t;&#xA;  if (checkIfIntersectSomething(D, t))&#xA;  {&#xA;&#xA;    vec3 I = O + t * D; //get to the intersection point on the object&#xA;    vec3 diffuse = getMaterial(I);&#xA;&#xA;    vec3 L = vec3(-1 + Rand(2.0f), 20, 9 + Rand(2.0f)) - I; //(-1,20,9) is Hard-code of the light position, and I add Rand(2.0f) on X and Z axis&#xA;    //so that I have an area light instead of a point light&#xA;    L = normalize(L);&#xA;    float ndotl = dot(I.getNormal(), L); //the closer the dotProdutc is to 1.0, the more the light and surface face each other&#xA;    if (ndotl &amp;gt; 0)&#xA;    {&#xA;        if (!checkRayLightIntersection(L)) {&#xA;            float dist = distFromLight(I);&#xA;            color += diffuse * ndotl * vec3(1000.0f, 1000.0f, 850.0f) * (1.0f / (dist * dist));&#xA;        }&#xA;    }&#xA;&#xA;    // russian roulette&#xA;    float Psurvival = CLAMP((diffuse.r + diffuse.g + diffuse.b) * 0.33333f, 0.2f, 0.8f);&#xA;&#xA;    // continue random walk &#xA;    float rand = Rand(1.0f);&#xA;    if (depth &amp;lt; 10 &amp;amp;&amp;amp; rand &amp;lt; Psurvival)&#xA;    {&#xA;        //Besides russian roulette, I also do another weight, because rays that go towards the horizon will bring back very little energy&#xA;        //so I make a random distribution that favours those rays who are close to the normal of the hit point, this is DiffuseReflectionCosineWeighted(). It creates a Random bounce but proportional to N dot R&#xA;        vec3 R = DiffuseReflectionCosineWeighted(I.getNormal());//there is a weight&#xA;&#xA;        float prob = 1.0;&#xA;        float cosTheta = fabs(dot(I.getNormal(), R));&#xA;        if (cosTheta &amp;gt; 1e-6) prob = cosTheta / M_PI;&#xA;&#xA;        color += diffuse * Sample(I + R * EPSILON, R, depth + 1) * (1.0f / Psurvival); //the cosTheta() of the attenuation of the rendering equation gets simplified with the cosTheta of the &quot;prob&quot;&#xA;        //the PI of the prob gets simplified with the BRDF where we are using the ideal BRDF = diffuse/PI&#xA;    }&#xA;  }&#xA;return color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;DiffuseReflectionCosineWeighted&lt;/strong&gt; implies that we have to apply a PDF to our recursive step. This PDF is &lt;strong&gt;cosTheta/PI&lt;/strong&gt; and we have to divide for it in:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color += diffuse * Sample(I + R * EPSILON, R, depth + 1) * (1.0f / Psurvival);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can't see it in the code because it gets simplified witht the &lt;strong&gt;cosTheta&lt;/strong&gt; attenuation term of the rendering equation and &lt;strong&gt;PI&lt;/strong&gt; of the diffuse BRDF where my BRDF is indeed &lt;strong&gt;diffuse/PI&lt;/strong&gt; because we want to consider only DIFFUSE objects.&#xA;(For any question about the code do not hesitate to ask.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to emulate this code with the difference that I don't calculate the path at the moment I want to calculate the color of a pixel (like the target framework does above), but I calculate a path beforehand:&#xA;My &lt;strong&gt;generatePath()&lt;/strong&gt; method indeed tracks the path into the scene and checks all the vertices it hits. The &lt;strong&gt;checkIfRayIntersectSomething(t)&lt;/strong&gt; method you will see used, it's just a pseudo method implemented in my framework and that I omit posting cause of its length. I use it to check if my ray hits something in the scene, if it does, it update the &quot;t&quot; with the distance to that object. NOTE: the light is not considered an object itself. Hence, I also have a &lt;strong&gt;checkRayLightIntersection(hitLightPoint)&lt;/strong&gt; which checks the intersection with the light, if there is any, the hitLightPoint is updated with the point on the light I have been hitting.&#xA;The light is a 2D surface of area 2x2 placed at the same position (-1,20,9), as the target framework does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First the definition of a couple of struct to store some info:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct PathVert {&#xA;   vec3 p; vec3 n; //hit point and normal of the surface hit &#xA;};&#xA;&#xA;struct Path {&#xA;   PathVert verts[MAX_DEPTH]; //maxDepth is 15 for now&#xA;   int vertCount;&#xA;   int x, y; //which pixel this path is referring to&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And now the main code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool GeneratePath(int x, int y, Path &amp;amp;path){&#xA;   path.x = x;&#xA;   path.y = y;&#xA;   path.vertCount = 0;&#xA;&#xA;   vec3 P = renderData.p1 + renderData.dx * ((float)(x) + Rand(1)) +  renderData.dy * ((float)(y) + Rand(1));&#xA;   vec3 O = renderData.E + vec3(Rand(0.4f) - 0.2f, Rand(0.4f) - 0.2f, Rand(0.4f) - 0.2f);&#xA;   vec3 D = normalize(P - O); //direction of the first ray, the one from the camera towards the pixel we are considering&#xA;&#xA;   for (int depth = 1; depth &amp;lt;= MAXDEPTH; depth++){&#xA;    float t;&#xA;    Vec hitLightPoint;&#xA;    PathVert vert;&#xA;    if (!checkIfRayIntersectSomething(t)){&#xA;        //we didn't find any object.. but we still may have found the light which is an object non represented in the scene&#xA;        //the depth check avoids me rendering the light as a white plane&#xA;        if (depth &amp;gt; 1 &amp;amp;&amp;amp; checkRayLightIntersection(O, D, hitLightPoint)){&#xA;            //update the vertex since we realized it's the light&#xA;            vert.p = hitLightPoint;&#xA;            vert.n = Vec(0, -1, 0);//cause the light is pointing down&#xA;            path.verts[depth - 1] = vert;&#xA;            path.vertCount++;&#xA;            return true; //light hit, path completed    &#xA;        }&#xA;        return false; //nothing hit, path non valid&#xA;    }&#xA;    //otherwise I got a hit into the scene&#xA;    vert.p = O + D * t; //reach the hitPoint&#xA;    vert.n = methodToFindTheNormal();&#xA;    vert.color = CalculateColor(vert.p); //according to the material properties (only diffuse objects so far)&#xA;    path.verts[depth - 1] = vert;&#xA;    path.vertCount++;&#xA;&#xA;    //since I have the light, and a path terminates when it hits the light, I have to check out also if my ray hits this light,&#xA;    //and if does, I have to check whether it first hits the light or the object just calculated above&#xA;    //moreover with the &quot;depth &amp;gt; 1&quot; check, I avoid again rendering the light which otherwise would be visible as a white plane&#xA;&#xA;    if (depth &amp;gt; 1 &amp;amp;&amp;amp; checkRayLightIntersection(O, D, hitLightPoint)){&#xA;        float distFromObj = length(vert.p - O);&#xA;        float distFromLight = length(hitLightPoint - O);&#xA;        if (distFromLight &amp;lt; distFromObj){&#xA;            //update the vertex since we realized it's the light&#xA;            vert.p = hitLightPoint;&#xA;            vert.n = Vec(0, -1, 0);&#xA;            vert.color = Vec(1, 1, 1);// TODO light color? or light emission?&#xA;&#xA;            path.verts[depth - 1] = vert;&#xA;            return true; //light hit, path completed&#xA;        }&#xA;    }&#xA;    if (depth == MAXDEPTH) return false;&#xA;       Vec newDir = BSDFDiffuseReflectionCosineWeighted(vert.n, D);//explained later&#xA;       D = newDir;&#xA;       O = vert.p;&#xA;   }&#xA;   return false;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;BSDFDiffuseReflectionCosineWeighted()&lt;/strong&gt; just calculates the new direction like in the target framework, tested and working. What remains last is the Sample method which calculates the final color of the pixel using the path calculated right above:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec Sampling(Path &amp;amp;path){&#xA;&#xA;   Vec color(1, 1, 1);&#xA;&#xA;   for (int vert = 0; vert &amp;lt; path.vertCount - 1; vert++) { //considers the last vertex as the light&#xA;      const PathVert &amp;amp;currVert = path.verts[vert];&#xA;      const PathVert &amp;amp;nextVert = path.verts[vert + 1];&#xA;      Vec wo = (nextVert.p - currVert.p).norm();&#xA;      double cosTheta = fabs(wo.dot(currVert.n));&#xA;      float PDF = cosTheta/PI;&#xA;      if (cosTheta &amp;lt;= 1e-6) return Vec();&#xA;      //considering only DIFFUSE objects&#xA;      color = color.mult(currVert.color * (cosTheta / M_PI) / PDF);&#xA;   }&#xA;   return color.mult(Vec(10.0f, 10.0f, 10.0f)); //multiplication for the light emission?&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem is that the image is really dark, you can see how small the light is, but somehow in the target framework it works correctly while in mine:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8aYPH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8aYPH.png&quot; alt=&quot;Dark render&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is because not many rays reach the light, so many paths are not considered valid. If instead I make my light broad (20x20) results are better but I lose the shadows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JvGhf.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JvGhf.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am sure that less rays reach the light cause I have been calculating them in both cases: small area light and big area light. I also tried to compensate the dark image by increasing the light contribution when reached by the path, but it brings to white pixels (for paths that reach the light) and the black ones (cause of invalid path) keep remaining black, so not a good approach. It seems that (as far as my understanding arrives) the target framework applies direct lighting, that's why such a good image BUT according to theory direct lighting only decrease variance, reducing the noise.. which means that using or not direct lighting shouldn't change the resulting image so much. Is there a way according to you to fix this problem? Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="3069" LastActivityDate="2016-04-18T04:49:34.327" Title="How to compensate low amount of rays reaching the light in a Path Tracer" Tags="&lt;c++&gt;&lt;lighting&gt;&lt;shadow&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2322" PostTypeId="2" ParentId="2316" CreationDate="2016-04-17T17:40:13.913" Score="9" Body="&lt;p&gt;The Russian roulette technique itself is a way of terminating paths without introducing systemic bias. The principle is fairly straightforward: if at a particular vertex you have a 10% chance of arbitrarily replacing the energy with 0, and if you do that an infinite number of times, you will see 10% less energy. The energy boost just compensates for that. If you did not compensate for the energy lost due to path termination, then Russian roulette would be biased, but the whole technique is a useful method of avoiding bias.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I was an adversary looking to prove that the &quot;terminate paths whose contribution is less than some small fixed value&quot; technique is biased, I would construct a scene with lights so dim that the contributing paths are &lt;em&gt;always&lt;/em&gt; less than that value. Perhaps I'm simulating a low-light camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But of course you could always expose the fixed value as a tweakable parameter to the user, so they can drop it even further if their scene happens to be low-light. So let's disregard that example for a minute.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What happens if I consider an object that is illuminated by a lot of very low-energy paths that are collected by a &lt;a href=&quot;https://en.wikipedia.org/wiki/Parabolic_reflector&quot;&gt;parabolic reflector&lt;/a&gt;? Low energy paths don't &lt;em&gt;necessarily&lt;/em&gt; bounce around indiscriminately in a manner that you can completely neglect. Similarly reasoning applies for, e.g., cutting off paths after a fixed number of bounces: you can construct a scene with a path that bounces off a series of 20 mirrors before hitting an object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way of looking at it: if you set the contribution of a path to 0 after it falls below some fixed epsilon, how do you correct for that energy loss? You aren't simply reducing the total energy by some fraction. You don't know anything about how much energy you are neglecting, because you are cutting off at some &lt;em&gt;contribution&lt;/em&gt; threshold before you know the other factor: the incident energy.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2016-04-17T17:40:13.913" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2323" PostTypeId="2" ParentId="2310" CreationDate="2016-04-17T18:17:05.423" Score="4" Body="&lt;p&gt;The near clipping plane is a fundamental feature of projective rasterization. To borrow a diagram from Eric Lengyel's &lt;a href=&quot;http://www.terathon.com/gdc07_lengyel.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Projection Matrix Tricks&lt;/a&gt; presentation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wd9gx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wd9gx.png&quot; alt=&quot;Diagram of camera space to NDC transform&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The displayed region of clip space (that you can think of rasterization as happening in) is a box which has a &quot;near&quot; face. This is associated with the near clip plane. But we can push the far clip plane out to infinity, so can we pull the near clip plane in to zero?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematically, you absolutely can! The only point that presents a problem is the eye itself: you can get infinitely close to the eye and still resolve to a single point in clip space. However, if you have a triangle that passes through the eye, you still need to clip it, and to clip it you need an actual plane, not a concept like &quot;infinitely close to the eye.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More critically for the current rasterization pipeline, the perspective divide does fun things with numerical precision. See the line at NDC 0 in the diagram above? It's halfway through the viewing volume in clip space, but not at all near halfway through the view frustum in camera space. In fact, its position depends on the near clip plane's distance to the eye! This means that over half of the depth range in clip space is in that region near the eye. As you get the near clip plane closer and closer to the eye, that plane pulls in even closer and you waste more and more depth range. This isn't necessarily fundamental—you don't have to store z/w in the depth buffer—but it is convenient. Here's an &lt;a href=&quot;https://developer.nvidia.com/content/depth-precision-visualized&quot; rel=&quot;nofollow noreferrer&quot;&gt;article from Nathan Reed&lt;/a&gt; about depth precision, and a few notes about &lt;a href=&quot;http://www.humus.name/index.php?ID=255&quot; rel=&quot;nofollow noreferrer&quot;&gt;why the projected z/w depth is useful&lt;/a&gt; from Emil Persson.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, I'll plug &lt;a href=&quot;https://fgiesen.wordpress.com/2011/07/05/a-trip-through-the-graphics-pipeline-2011-part-5/&quot; rel=&quot;nofollow noreferrer&quot;&gt;a post in the excellent &quot;A trip through the Graphics Pipeline&quot;&lt;/a&gt; series, which is very interesting and references homogeneous rasterization algorithms which, in theory, could avoid the need to do clipping in projected clip space, which would totally avoid some of these traps.&lt;/p&gt;&#xA;" OwnerUserId="196" LastEditorUserId="196" LastEditDate="2016-04-17T19:31:05.250" LastActivityDate="2016-04-17T19:31:05.250" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2324" PostTypeId="1" AcceptedAnswerId="2327" CreationDate="2016-04-17T18:31:13.193" Score="2" ViewCount="564" Body="&lt;p&gt;So I have a vector of &lt;code&gt;glm::vec3&lt;/code&gt; containing the triangles for the classic Cornell Box called triangles. The Draw method casts a ray for each pixel on the screen and calls &lt;code&gt;ClosestIntersection&lt;/code&gt; which returns true or false and updates a struct containing things like colour and the point of that intersection. Then I simply draw the pixels based on the colours (black for no intersection). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result is very inconsistent and I can't find the error:&#xA;&lt;a href=&quot;https://i.imgur.com/nQlyeC4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/nQlyeC4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Draw()&#xA;{&#xA;    if (SDL_MUSTLOCK(screen))&#xA;        SDL_LockSurface(screen);&#xA;&#xA;    // Loop through each pixel and cast ray&#xA;    for (int y = 0; y&amp;lt;SCREEN_HEIGHT; ++y)&#xA;    {&#xA;        for (int x = 0; x&amp;lt;SCREEN_WIDTH; ++x)&#xA;        {&#xA;            vec3 dir(x - SCREEN_WIDTH / 2, y - SCREEN_HEIGHT / 2, focalLength);&#xA;            Intersection isect;&#xA;            if (ClosestIntersection(cameraPos, dir, triangles, isect))&#xA;            {&#xA;                vec3 color = triangles[isect.triangleIndex].color;&#xA;                PutPixelSDL(screen, x, y, color);&#xA;            }&#xA;            else&#xA;            {&#xA;                PutPixelSDL(screen, x, y, vec3(1, 1, 1));&#xA;            }&#xA;        }&#xA;    }&#xA;&#xA;    if (SDL_MUSTLOCK(screen))&#xA;        SDL_UnlockSurface(screen);&#xA;&#xA;    SDL_UpdateRect(screen, 0, 0, 0, 0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is the function called from Draw:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool ClosestIntersection(vec3 start,&#xA;    vec3 dir,&#xA;    const vector&amp;lt;Triangle&amp;gt;&amp;amp; triangles,&#xA;    Intersection&amp;amp; closestIntersection)&#xA;{&#xA;    bool foundIntersection = false;&#xA;&#xA;    // Loop through all the triangles and check for intersection with ray&#xA;    for (size_t i = 0; i &amp;lt; triangles.size(); i++)&#xA;    {&#xA;        vec3 v0 = triangles[i].v0;&#xA;        vec3 v1 = triangles[i].v1;&#xA;        vec3 v2 = triangles[i].v2;&#xA;        vec3 e1 = v1 - v0;&#xA;        vec3 e2 = v2 - v0;&#xA;        vec3 b = start - v0;&#xA;        mat3 A(-dir, e1, e2);&#xA;        vec3 x = glm::inverse(A) * b;&#xA;&#xA;        // Check that found scalars are within bounds&#xA;        if ((x.x &amp;gt;= 0) &amp;amp;&amp;amp; (x.y &amp;gt; 0) &amp;amp;&amp;amp; (x.z &amp;gt; 0) &amp;amp;&amp;amp; (x.y + x.z &amp;lt; 1))&#xA;        {&#xA;            if (foundIntersection)  // If there's a previvous intersection for this ray check that new one is closer to camera&#xA;            {&#xA;                if (glm::distance(start, x) &amp;lt; closestIntersection.distance)&#xA;                {&#xA;                    closestIntersection.distance = glm::distance(start, x);&#xA;                    closestIntersection.triangleIndex = i;&#xA;                    closestIntersection.position = x;&#xA;                }&#xA;            }&#xA;            else&#xA;            {&#xA;                foundIntersection = true;&#xA;                closestIntersection.distance = glm::distance(start, x);&#xA;                closestIntersection.triangleIndex = i;&#xA;                closestIntersection.position = x;&#xA;            }&#xA;        }&#xA;    }&#xA;    return foundIntersection;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3153" LastEditorUserId="182" LastEditDate="2016-04-18T05:40:09.957" LastActivityDate="2016-04-18T05:40:09.957" Title="Ray-tracing the Cornell Box results in really inconsistent image" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2325" PostTypeId="2" ParentId="2316" CreationDate="2016-04-17T18:59:48.360" Score="29" Body="&lt;p&gt;In order to understand Russian Roulette, let's look at a very basic backward path tracer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) {&#xA;    Ray ray = m_scene-&amp;gt;Camera.CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;&#xA;    // Bounce the ray around the scene&#xA;    for (uint bounces = 0; bounces &amp;lt; 10; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.geomID == RTC_INVALID_GEOMETRY_ID) {&#xA;            color += throughput * float3(0.846f, 0.933f, 0.949f);&#xA;            break;&#xA;        }&#xA;&#xA;        // We hit an object&#xA;&#xA;        // Fetch the material&#xA;        Material *material = m_scene-&amp;gt;GetMaterial(ray.geomID);&#xA;        // The object might be emissive. If so, it will have a corresponding light&#xA;        // Otherwise, GetLight will return nullptr&#xA;        Light *light = m_scene-&amp;gt;GetLight(ray.geomID);&#xA;&#xA;        // If we hit a light, add the emmisive light&#xA;        if (light != nullptr) {&#xA;            color += throughput * light-&amp;gt;Le();&#xA;        }&#xA;&#xA;        float3 normal = normalize(ray.Ng);&#xA;        float3 wo = normalize(-ray.dir);&#xA;        float3 surfacePos = ray.org + ray.dir * ray.tfar;&#xA;&#xA;        // Get the new ray direction&#xA;        // Choose the direction based on the material&#xA;        float3 wi = material-&amp;gt;Sample(wo, normal, sampler);&#xA;        float pdf = material-&amp;gt;Pdf(wi, normal);&#xA;&#xA;        // Accumulate the brdf attenuation&#xA;        throughput = throughput * material-&amp;gt;Eval(wi, wo, normal) / pdf;&#xA;&#xA;&#xA;        // Shoot a new ray&#xA;&#xA;        // Set the origin at the intersection point&#xA;        ray.org = surfacePos;&#xA;&#xA;        // Reset the other ray properties&#xA;        ray.dir = wi;&#xA;        ray.tnear = 0.001f;&#xA;        ray.tfar = embree::inf;&#xA;        ray.geomID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.primID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.instID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.mask = 0xFFFFFFFF;&#xA;        ray.time = 0.0f;&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera.FrameBuffer.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;IE. we bounce around the scene, accumulating color and light attenuation as we go. In order to be completely mathematically unbiased, bounces &lt;em&gt;should&lt;/em&gt; go to infinity. But this is unrealistic, and as you noted, not visually necessary; for most scenes, after a certain number of bounces, say 10, the amount of contribution to the final color is very very minimal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in order to save computing resources, many path tracers have a hard limit to the number of bounces. This adds bias.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, it's hard to choose what that hard limit should be. Some scenes look great after 2 bounces; others (say with transmission or SSS) may take up to 10 or 20. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/ikXSo.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ikXSo.jpg&quot; alt=&quot;2 Bounces from Disney&amp;#39;s Big Hero 6&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/BPiZ7.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BPiZ7.jpg&quot; alt=&quot;9 Bounces from Disney&amp;#39;s Big Hero 6&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we choose too low, the image will be visibly biased. But if we choose too high, we're wasting computation energy and time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to solve this, as you noted, is to terminate the path after we reach some threshold of attenuation. This also adds bias. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clamping after a threshold, will &lt;em&gt;work&lt;/em&gt;, but again, how do we choose the threshold? If we choose too large, the image will be visibly biased, too small, and we're wasting resources.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Russian Roulette attempts to solve these problems in an unbiased way. First, here is the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) {&#xA;    Ray ray = m_scene-&amp;gt;Camera.CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;&#xA;    // Bounce the ray around the scene&#xA;    for (uint bounces = 0; bounces &amp;lt; 10; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.geomID == RTC_INVALID_GEOMETRY_ID) {&#xA;            color += throughput * float3(0.846f, 0.933f, 0.949f);&#xA;            break;&#xA;        }&#xA;&#xA;        // We hit an object&#xA;&#xA;        // Fetch the material&#xA;        Material *material = m_scene-&amp;gt;GetMaterial(ray.geomID);&#xA;        // The object might be emissive. If so, it will have a corresponding light&#xA;        // Otherwise, GetLight will return nullptr&#xA;        Light *light = m_scene-&amp;gt;GetLight(ray.geomID);&#xA;&#xA;        // If we hit a light, add the emmisive light&#xA;        if (light != nullptr) {&#xA;            color += throughput * light-&amp;gt;Le();&#xA;        }&#xA;&#xA;        float3 normal = normalize(ray.Ng);&#xA;        float3 wo = normalize(-ray.dir);&#xA;        float3 surfacePos = ray.org + ray.dir * ray.tfar;&#xA;&#xA;        // Get the new ray direction&#xA;        // Choose the direction based on the material&#xA;        float3 wi = material-&amp;gt;Sample(wo, normal, sampler);&#xA;        float pdf = material-&amp;gt;Pdf(wi, normal);&#xA;&#xA;        // Accumulate the brdf attenuation&#xA;        throughput = throughput * material-&amp;gt;Eval(wi, wo, normal) / pdf;&#xA;&#xA;&#xA;        // Russian Roulette&#xA;        // Randomly terminate a path with a probability inversely equal to the throughput&#xA;        float p = std::max(throughput.x, std::max(throughput.y, throughput.z));&#xA;        if (sampler-&amp;gt;NextFloat() &amp;gt; p) {&#xA;            break;&#xA;        }&#xA;&#xA;        // Add the energy we 'lose' by randomly terminating paths&#xA;        throughput *= 1 / p;&#xA;&#xA;&#xA;        // Shoot a new ray&#xA;&#xA;        // Set the origin at the intersection point&#xA;        ray.org = surfacePos;&#xA;&#xA;        // Reset the other ray properties&#xA;        ray.dir = wi;&#xA;        ray.tnear = 0.001f;&#xA;        ray.tfar = embree::inf;&#xA;        ray.geomID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.primID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.instID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.mask = 0xFFFFFFFF;&#xA;        ray.time = 0.0f;&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera.FrameBuffer.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Russian Roulette randomly terminates a path with a probability inversely equal to the throughput. So paths with low throughput that won't contribute much to the scene are more likely to be terminated. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we stop there, we're still biased. We 'lose' the energy of the path we randomly terminate. To make it unbiased, we boost the energy of the non-terminated paths by their probability to be terminated. This, along with being random, makes Russian Roulette unbiased.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer your last questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Does Russian Roulette give an unbiased result?&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Yes&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Is Russian Roulette necessary for an unbiased result?&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Depends on what you mean by unbiased. If you mean mathematically, then yes. However, if you mean visually, then no. You just have to choose you max path depth and cutoff threshold very very carefully. This can be very tedious since it can change from scene to scene.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Can you use a fixed probability (cut-off), and then redistribute the 'lost' energy. Is this unbiased?&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If you use a fixed probability, you are adding bias. By redistributing the 'lost' energy, you reduce the bias, but it is still mathematically biased. To be completely unbiased, it must be random.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;If the energy that would be lost by terminating a ray without redistributing its energy is eventually lost anyway (as the rays to which it is redistributed are also eventually terminated), how does this improve the situation?&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Russian Roulette only stops the bouncing. It doesn't remove the sample completely. Also, the 'lost' energy is accounted for in the bounces up to the termination. So the only way for the the energy to be 'eventually lost anyway' would be to have a completely black room.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In the end, Russian Roulette is a very simple algorithm that uses a very small amount of extra computational resources. In exchange, it can save a large amount of computational resources. Therefore, I can't really see a reason &lt;em&gt;not&lt;/em&gt; to use it.&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2017-10-28T03:54:50.013" LastActivityDate="2017-10-28T03:54:50.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2326" PostTypeId="1" AcceptedAnswerId="2329" CreationDate="2016-04-17T23:05:46.197" Score="7" ViewCount="257" Body="&lt;p&gt;I'm interested in virtual reality, but according to some sources, less than 1% of computers in use today have the necessary performance to run modern VR games, granted many of them are not intended for gaming, that's still a huge barrier for the widespread adoption of VR headsets into the market. So I was wondering what could be done to reduce the performance requirements of a VR game that hasn't been implemented with such optimizations in mind.&lt;/p&gt;&#xA;&lt;p&gt;I'm talking about technologies like foveated rendering, which (ab)uses the fact that we only ever perceive a few degrees in the center of our field of vision as sharp while everything else is blurry. This can be combined with eye tracking so that only the areas where the player is looking are rendered in full quality, while we can reduce the render quality and therefore the performance requirements everywhere else.&#xA;This seems like a great advantage and I honestly wonder why none of the major VR companies have implemented eye tracking into their headsets and foveated rendering into their SDKs into their headsets. The technology exists and I can't imagine that it would add much to the price tag.&#xA;&lt;a href=&quot;https://www.microsoft.com/en-us/research/publication/foveated-3d-graphics/?from=http://research.microsoft.com/pubs/176610/foveated_final15.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Paper about foveated rendering&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;There's also instanced stereo rendering which basically renders things to both eyes at the same time rather than rendering it for each eye individually.&#xA;&lt;a href=&quot;https://web.archive.org/web/20160712094453/https://docs.unrealengine.com/latest/images/Support/Builds/ReleaseNotes/2016/4_11/image_16.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://web.archive.org/web/20160712094453/https://docs.unrealengine.com/latest/images/Support/Builds/ReleaseNotes/2016/4_11/image_16.gif&quot; alt=&quot;Example gif for Instanced Stero Rendering - Epic Games, Unreal Engine 4.11 release notes&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It's also possible to use just one frustum for both eyes rather than two as discussed here.&#xA;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1736/vr-and-frustum-culling&quot;&gt;VR and frustum culling&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But are there other approaches to the performane problem?&lt;/p&gt;&#xA;" OwnerUserId="3156" LastEditorUserId="5778" LastEditDate="2020-12-20T21:48:55.710" LastActivityDate="2020-12-20T21:48:55.710" Title="What methods/technologies to reduce required performance for virtual reality are there?" Tags="&lt;rendering&gt;&lt;performance&gt;&lt;optimisation&gt;&lt;virtual-reality&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="2327" PostTypeId="2" ParentId="2324" CreationDate="2016-04-17T23:24:54.573" Score="4" Body="&lt;h1&gt;Two symptoms&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;There appear to be two problems with the image.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The background is showing through along the line between adjacent triangles.&lt;/li&gt;&#xA;&lt;li&gt;The colour displayed is not always from the closest intersection.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Note that the background colour is white, rather than black, due to the line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;                PutPixelSDL(screen, x, y, vec3(1, 1, 1));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Why this background shows through at the triangle edges I do not know. However, the second problem is identified below, so I recommend you fix that first and then the first problem can be analysed in isolation without the additional distractions.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;Cause of the problem with &lt;code&gt;ClosestIntersection&lt;/code&gt;&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;ClosestIntesection&lt;/code&gt; function returns &lt;code&gt;true&lt;/code&gt; when an intersection is found, and updates an &lt;code&gt;Intersection&lt;/code&gt; object called &lt;code&gt;closestIntersection&lt;/code&gt;. However, the intersection stored here is not always the closest to the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason for this is here:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;                closestIntersection.distance = glm::distance(start, x);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This appears in two places so it will need to be fixed in both.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;start&lt;/code&gt; is &lt;code&gt;cameraPos&lt;/code&gt;, presumably in world coordinates. &lt;code&gt;x&lt;/code&gt; appears to be in the local coordinates of the triangle being intersected (one of the triangle vertices being the origin). The distance between two points in different coordinate systems is meaningless, so that in different regions of a triangle it will appear to be behind or in front of another triangle for no immediately apparent reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &lt;code&gt;x&lt;/code&gt; is first converted to world coordinates then the distance will be correct and the intersection chosen will be the closest to the camera.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-04-17T23:24:54.573" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2328" PostTypeId="2" ParentId="2320" CreationDate="2016-04-18T04:49:34.327" Score="4" Body="&lt;h3&gt;A note first&lt;/h3&gt;&#xA;&lt;p&gt;From the look of your screen capture, I suspect there might still be a bug in your code. Noise is to be expected with only 16 spp, but your picture still looks surprisingly dark to me. For comparison, here is what my implementation of SmallPT looks like with 16 spp, 15 bounces, and no next event prediction:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zFFjC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zFFjC.png&quot; alt=&quot;SmallPT, 16 spp, 15 bounces, no next event predicition&quot; /&gt;&lt;/a&gt;&#xA;(&lt;a href=&quot;https://www.shadertoy.com/view/4sfGDB&quot; rel=&quot;nofollow noreferrer&quot;&gt;here it is on ShaderToy&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;Noisy, but not nearly as dark as your picture. It is very different scene, but considering the that the shape is similar (a box with one side open and only one light source), I would expect to get a similar luminosity/noise appearance.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;The rest of this answer assumes your code to be correct.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h2&gt;Path tracing and reducing noise&lt;/h2&gt;&#xA;&lt;p&gt;The balance between light source size, noise and SPP is a classic problem, to which there is no magical solution. From easiest to hardest, you could:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Use a scene that is more suitable to your algorithm:&lt;/p&gt;&#xA;&lt;p&gt;Rendering algorithms have limitations, may shine in certain cases and poorly handle other cases. Knowing the limitations of yours, you can choose to restrict its use to a case that works best for it: a large light source, a sky dome, many light sources, a scene with less occlusion, etc.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Implement next event prediction:&lt;/p&gt;&#xA;&lt;p&gt;When you know where your light sources are, at each bounce you can try and shoot rays directly toward them. If the ray doesn't hit other geometry first, you get a path that contributes. Since doing so biases the randomness, you will need to use proper factors to take it into account.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Implement &lt;a href=&quot;http://www.graphics.cornell.edu/%7Eeric/Portugal.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bi-Directional Path Tracing&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;p&gt;When tracing rays from the camera, if the light source is small, a large number of paths will never reach it. This is the problem you are having. On the opposite, when tracing rays from the light, many of them will never reach the camera. BDPT consists in first shooting rays both from the camera and from the light source, then trying to connect them. Each pair that can be connected is a contributing path. BDPT will significantly reduce noise.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Implement &lt;a href=&quot;http://graphics.stanford.edu/papers/metro/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metropolis Light Transport&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;p&gt;If there is a path between the camera and a light source, it is likely there will be a similar path between them. MLT consists in searching for those contributing paths in the neighborhood of paths that are already known to contribute by mutating them (adding, removing or changing one or more bounces). This is a lot less trivial already, as the math to keep it unbiased gets a bit hairy.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The problem of reducing noise is still under active research though, and there is no silver bullet. At this point you will need to read what are the latest developments.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-04-18T04:49:34.327" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2329" PostTypeId="2" ParentId="2326" CreationDate="2016-04-18T05:05:56.010" Score="9" Body="&lt;h2&gt;Avoid stereo when possible&lt;/h2&gt;&#xA;&lt;p&gt;There was some research published recently measuring when users can or cannot tell whether the specular contribution, which is view point dependent, is different between eyes.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://software.intel.com/en-us/articles/perception-of-highlight-disparity-at-a-distance-in-consumer-head-mounted-displays&quot; rel=&quot;noreferrer&quot;&gt;Perception of Highlight Disparity at a Distance in Consumer Head-Mounted Displays&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In the future, this could be use to share some computation between the two eye renders. Unfortunately this sounds hard to take advantage of in a typical rasterization pipeline.&lt;/p&gt;&#xA;&lt;p&gt;Some games already avoid stereo when rendering far objects and background.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h2&gt;Reduce shading when possible&lt;/h2&gt;&#xA;&lt;h3&gt;Lens distortion&lt;/h3&gt;&#xA;&lt;p&gt;Part of the NVidia VRWorks SDK is a feature, &lt;a href=&quot;https://blogs.nvidia.com/blog/2016/04/20/ue-4/&quot; rel=&quot;noreferrer&quot;&gt;Multi-Res Shading&lt;/a&gt;, that allow to reduce the amount of shading, to take into account the fact that some pixels contribute less to the final image due to lens distortion.&lt;/p&gt;&#xA;&lt;p&gt;In &lt;a href=&quot;http://media.steampowered.com/apps/valve/2015/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf&quot; rel=&quot;noreferrer&quot;&gt;Alex Vlachos' GDC 2015 presentation&lt;/a&gt;, he also mentions the idea of rendering the image in two parts of different resolution, to achieve the same goal.&lt;/p&gt;&#xA;&lt;h3&gt;Foveated rendering&lt;/h3&gt;&#xA;&lt;p&gt;Finally, like your question mentions, foveated rendering aims at scaling the resolution to take into account the fact that eyes have more precision in the fovea and less in the periphery. There is some &lt;a href=&quot;http://research.lighttransport.com/foveated-real-time-ray-tracing-for-virtual-reality-headset/&quot; rel=&quot;noreferrer&quot;&gt;research on the topic&lt;/a&gt;, but this requires eye tracking like in the &lt;a href=&quot;http://www.getfove.com/&quot; rel=&quot;noreferrer&quot;&gt;Fove&lt;/a&gt; HMD.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-04-22T07:13:59.907" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2330" PostTypeId="2" ParentId="2326" CreationDate="2016-04-18T07:56:36.613" Score="7" Body="&lt;p&gt;Alex Vlachos from Valve has had two great GDC talks about this:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://media.steampowered.com/apps/valve/2015/Alex_Vlachos_Advanced_VR_Rendering_GDC2015.pdf&quot;&gt;the one from 2015&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.gdcvault.com/play/1021771/Advanced-VR&quot;&gt;the one from 2016&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Other than that (and what you have linked yourself), there isn't much left to do than to simply optimize your app until you spend at most 10 ms per frame (100 Hz, targeting a 90 Hz display + margin). Standard rendering optimizations apply. Apply a technique, profile, determine its impact on performance, rinse, repeat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may also exercise caution with that UE4 stereo instancing from Epic. In my experience, its performance boost depends heavily on the game's rendering workload. I had a statically lit game with lots of instanced foliage and this feature has actually been a net loss, probably due to the overhead of left/right eye dynamic branching in the shaders; while a fully dynamically-lit scene may benefit from it all right. As I said before: profile to ensure that a technique actually helps performance.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-04-18T07:56:36.613" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2331" PostTypeId="1" CreationDate="2016-04-18T07:59:10.987" Score="4" ViewCount="45" Body="&lt;p&gt;In &lt;a href=&quot;https://hal.inria.fr/hal-01024289/document&quot; rel=&quot;nofollow noreferrer&quot;&gt;Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs&lt;/a&gt;, Eric Heitz derives the Separable Masking and Shadowing function as (P.83-84):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1F17w.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1F17w.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the mentioned &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt; by Walter et al., Smith term is computed as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Sxwgo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Sxwgo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't see a parameterisation of Λ that could make appear the generic form (Heitz version) from the specific form derived by Walter. What am I missing?&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="231" LastEditDate="2016-04-18T13:51:41.537" LastActivityDate="2016-04-18T13:51:41.537" Title="Why does the G1 term have a 2 in the numerator in Walter's formula, but not in Heitz's generalized formula?" Tags="&lt;function&gt;&lt;masking&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2332" PostTypeId="1" CreationDate="2016-04-18T08:53:27.960" Score="0" ViewCount="890" Body="&lt;p&gt;Suppose i have a image and I want to convert the portion of image that is red to blue(or any other color). One way to do this is extract red part of image using HSV or other color values and convert red hsv value to corresponding blue. Is there any other methods(better) for this. What sort of algorithms do Photoshop color replacement tool use?&lt;/p&gt;&#xA;" OwnerUserId="2383" LastActivityDate="2018-04-15T10:01:56.963" Title="Change particular color in an image" Tags="&lt;color&gt;&lt;color-science&gt;&lt;color-management&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2333" PostTypeId="2" ParentId="2331" CreationDate="2016-04-18T08:58:40.510" Score="2" Body="&lt;p&gt;Actually I just had to solve the following equation to find a solution, consistent with the presence of the &quot;2&quot; in the numerator:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{1}{1+\Lambda (m)}=\frac{2}{1+\sqrt{1+\alpha ^{2}tan_{2}\theta_{m} }}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$1+\Lambda (m)=\frac{1+\sqrt{1+\alpha ^{2}tan_{2}\theta_{m} }}{2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\Lambda (m)=\frac{-1+\sqrt{1+\alpha ^{2}tan_{2}\theta_{m} }}{2}$&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="110" LastEditDate="2016-04-18T10:21:12.167" LastActivityDate="2016-04-18T10:21:12.167" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2334" PostTypeId="2" ParentId="2332" CreationDate="2016-04-18T14:39:31.007" Score="2" Body="&lt;p&gt;Assuming you are looking to transform a particular component (r, g or b) of any color, this can be easily done by simple vector/matrix multiplication.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The introduction on this page (Chapter 6.1) - from the most excellent immersivemath.com site - illustrates this perfectly:&#xA;&lt;a href=&quot;http://immersivemath.com/ila/ch06_matrices/ch06.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Chapter 6: The Matrix (Immersive Linear Algebra) | immersivemath.com&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think of it as the &quot;Channel Mixer&quot; command in PhotoShop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I described above is one of many ways of changing a given color. The PS Color Replacement Tool simply applies that to any pixel that matches certain conditions defined by the user (source color, destination color, tolerance, etc...). The nifty thing they did is put it in the form of a brush tool, allowing the user artistic control over where to apply the color transform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically it boils down to this: if a pixel under the brush matches the conditions set by the user the color transform is applied. If not, leave the pixel as is.&lt;/p&gt;&#xA;" OwnerUserId="3128" LastEditorDisplayName="user7220" LastEditDate="2018-04-15T10:01:56.963" LastActivityDate="2018-04-15T10:01:56.963" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2336" PostTypeId="1" AcceptedAnswerId="2344" CreationDate="2016-04-19T08:12:14.370" Score="5" ViewCount="192" Body="&lt;p&gt;When I saw an implementation of normal mapping that computed the &lt;em&gt;TBN matrix&lt;/em&gt; in the vertex shader and converted everything (in particular the view vector and light vector) to tangent space at that stage, it seemed like the proper way to do. This way there is no matrix-vector multiplication left to do in the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Enters image based lighting: for each fragment we want to fetch from an image, typically one or more cube map textures, the light intensity coming from certain directions. I assume this data is in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: is it possible to use IBL while retaining the vertex shader transform optimization mentioned above?&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It seems to me we still need to transform our fetch direction from tangent space to world space (or whichever space the cube map is in).&lt;/li&gt;&#xA;&lt;li&gt;Conversely, if we want to work in world space, like with deferred shading, we need to transform the normal for each fragment.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Does IBL necessarily imply at least one matrix vector multiplication per fragment and the optimization I mentioned is an uncommon case, or am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-04-19T14:32:18.870" Title="Image based lighting, tangent space coordinates, and optimization" Tags="&lt;optimisation&gt;&lt;matrix&gt;&lt;ibl&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2337" PostTypeId="1" AcceptedAnswerId="3624" CreationDate="2016-04-19T09:07:32.807" Score="3" ViewCount="984" Body="&lt;p&gt;The GL Transmission Format comes along with a JSON styled main file which basicly describes the scene and binary files which contain the buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RtFrg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RtFrg.png&quot; alt=&quot;gltf basic structure&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently writing a WebGL library and I need to work alot with the vertex and index buffers. So, my question now is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would it be possible to store plain text array buffers in the gltf (e.g., as JSON) instead of generating binary blobs always when the buffers are adjusted?&lt;/p&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-06-15T18:57:12.357" Title="Is it possible to store the plain buffer data in gltf files?" Tags="&lt;webgl&gt;&lt;data-structure&gt;&lt;vertex-buffer-object&gt;&lt;gltf&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2338" PostTypeId="1" AcceptedAnswerId="3625" CreationDate="2016-04-19T09:18:40.673" Score="2" ViewCount="1106" Body="&lt;p&gt;I'm looking for any way which enables me to quickly generate gltf files including the conversion of plain array buffers (vertex, index, color, etc.) into binary (bgltf, glb, bin) files.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm asking because it currently looks like there are only high level applications like Maya, Blender available which can do that or converters to indirectly write glTF from COLLADA.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any way to generate binary gltf array buffers using low level / command line utilities?&lt;/p&gt;&#xA;" OwnerUserId="361" LastEditorUserId="361" LastEditDate="2016-04-20T08:15:42.833" LastActivityDate="2016-06-15T19:03:36.683" Title="How to generate binary gltf array buffers?" Tags="&lt;data-structure&gt;&lt;gltf&gt;&lt;buffers&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2339" PostTypeId="2" ParentId="2337" CreationDate="2016-04-19T09:40:01.340" Score="3" Body="&lt;p&gt;Embedding human readable data is not supported. However you can put the data into a &lt;a href=&quot;https://tools.ietf.org/html/rfc2397&quot; rel=&quot;nofollow&quot;&gt;data uri&lt;/a&gt; to store the data inline in base64 format.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;buffers&quot;: {&#xA;    &quot;a-buffer-id&quot;: {&#xA;        &quot;byteLength&quot;: 1024,&#xA;        &quot;type&quot;: &quot;arraybuffer&quot;,&#xA;        &quot;uri&quot;=&quot;data:application/octet-stream;base64,...&quot;&#xA;    }&#xA;},&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-04-19T09:40:01.340" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2340" PostTypeId="2" ParentId="2338" CreationDate="2016-04-19T09:53:41.033" Score="2" Body="&lt;p&gt;Technically any file format where you can dump the entire file into a VBO and then render from that will work for the .bin files. Unfortunately those formats are less well known than they should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you only need to adjust the bufferview elements to reference the proper subset of the file&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-04-19T09:53:41.033" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2341" PostTypeId="2" ParentId="2314" CreationDate="2016-04-19T12:00:41.240" Score="2" Body="&lt;p&gt;Here is an interesting answer from Styves on gamedev.net.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Calculating bent normals is just an extension of AO calculation where&#xA;  the direction of each sample is also averaged along with the occlusion&#xA;  amount.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HH0zw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HH0zw.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;The bent normals from substance painter seem correct. In any region&#xA;  that there is no AO, your normal won't be bent in any direction,&#xA;  therefore in tangent space it's pointing straight up along the surface&#xA;  normal. This is why you only see details in the ears.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;I have no idea how Unity handles the bent normals but the usual way is&#xA;  to, instead of applying AO as a standard multiplier onto the lighting&#xA;  result (which gives this weird muddy look), use the dot product of the&#xA;  bent normal and the light instead. This is how we handle SSDO in&#xA;  CryENGINE for example.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;I've only ever used a texture-based version of this technique once,&#xA;  however in this version the bent normals also contained information&#xA;  from the original tangent space normal map, and was used directly&#xA;  during lighting in place of the original.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-04-20T05:44:23.073" LastActivityDate="2016-04-20T05:44:23.073" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2342" PostTypeId="1" AcceptedAnswerId="2353" CreationDate="2016-04-19T12:20:54.443" Score="2" ViewCount="1113" Body="&lt;p&gt;I am trying to blend two world space normals inside a shader. One comes from a tangent space normal map converted into world space using a classic TBN matrix and the other one is a mesh normal map in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found some interesting resources here :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://blog.selfshadow.com/publications/blending-in-detail/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blending in Detail&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.shadertoy.com/view/4t2SzR#&quot; rel=&quot;nofollow noreferrer&quot;&gt;Shadertoy - Normal Map Blending&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;But those blending technics seem to be only available for tangent space normals, especially the Reoriented Normal Mapping (RNM).&#xA;I tried to apply the RNM technic with unpack already done.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;n1 += vec3(0, 0, 1);&#xA;n2 *= vec3(-1, -1, 1);&#xA;&#xA;return n1 * dot(n1, n2) / n1.z - n2;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this doesn't give expected results and I don't get why. Is there a way to apply the RNM blending on world space normals ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; Here are some output and the result I am having with RNM. The A normal is not disturbed by the B normal, it gives some strange massively reoriented results.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 nv = dot(normal, viewDir);&#xA;color.rgb = nv;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iFPZp.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iFPZp.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-04-19T20:02:38.247" LastActivityDate="2016-04-21T18:09:25.737" Title="How to blend World Space Normals" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;texture&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2343" PostTypeId="1" CreationDate="2016-04-19T13:48:31.713" Score="7" ViewCount="130" Body="&lt;p&gt;Let's assume that we have some set of points in 3d space sampled from some arbitrary surface, without self intersections and mostly flat. Is it possible to get any parametrization over this set of points?  And if it is - how?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first idea was to find a plane (Maybe through PCA), or more sophisticated smooth surface which approximate this set of points, project each of these points on this fitted plane/surface and get corresponding parameters. But maybe there is better solutions for this problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for any help.&lt;/p&gt;&#xA;" OwnerUserId="2644" LastEditorUserId="2644" LastEditDate="2016-04-19T14:10:26.560" LastActivityDate="2017-11-24T15:09:23.990" Title="Parametrize set of unordered points in 3d space" Tags="&lt;algorithm&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2344" PostTypeId="2" ParentId="2336" CreationDate="2016-04-19T14:32:18.870" Score="4" Body="&lt;p&gt;Yes, you do need to transform the fetch direction into the space of the cubemap. If you could somehow figure out the fetch direction in the vertex shader, then you could do the transformation there instead, but that would produce worse lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It also may be worth optimizing for a smaller number of interpolants between the vertex and pixel shaders (rather than a smaller number of matrix-vector multiplications in the pixel shader). As soon as you have one transformed view vector and two transformed light vectors that must be interpolated (which would otherwise be constant), you've matched the size of the tangent/bitangent/normal matrix that you would otherwise be interpolating. That has the potential to have more performance impact than doing extra matrix multiplications in the shader.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2016-04-19T14:32:18.870" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2345" PostTypeId="2" ParentId="1934" CreationDate="2016-04-19T14:59:49.760" Score="4" Body="&lt;p&gt;You can put the data into a data uri to store the data inline in base64 format.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;buffers&quot;: {&#xA;    &quot;a-buffer-id&quot;: {&#xA;        &quot;byteLength&quot;: 1024,&#xA;        &quot;type&quot;: &quot;arraybuffer&quot;,&#xA;        &quot;uri&quot;=&quot;data:application/octet-stream;base64,...&quot;&#xA;    }&#xA;},&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It's still a bit bloated compared to storing the data in a binary file though.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-04-19T14:59:49.760" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2346" PostTypeId="1" CreationDate="2016-04-19T18:18:33.913" Score="2" ViewCount="463" Body="&lt;p&gt;I'm a newbie to OpenGL and I was following a series by &quot;thebennybox&quot; on Youtube. Specifically his series on modern opengl programming. I thought I would try to implement his Mesh wrapper using the vector in C++ rather than using arrays of data and passing that to OpenGL. It works, but I cant' seem to render multiple meshes?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I making an obvious mistake somewhere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is I do to setup my mesh:&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenVertexArrays(1, &amp;amp;vao);&#xA;glBindVertexArray(vao);&#xA;&#xA;glGenBuffers(BUFFER_COUNT, vbo);&#xA;&#xA;// vertices buffer&#xA;glBindBuffer(GL_ARRAY_BUFFER, vbo[BUFFER_POSITION]);&#xA;glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(positions.front()), &amp;amp;positions.front(), GL_STATIC_DRAW);&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);&#xA;&#xA;// texture buffer&#xA;glBindBuffer(GL_ARRAY_BUFFER, vbo[BUFFER_TEXCOORD]);&#xA;glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(texes.front()), &amp;amp;texes.front(), GL_STATIC_DRAW);&#xA;glEnableVertexAttribArray(1);&#xA;glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);&#xA;&#xA;// index buffer&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[BUFFER_INDEX]);&#xA;glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(indices.front()), &amp;amp;indices.front(), GL_STATIC_DRAW);&#xA;&#xA;glBindVertexArray(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then to render it I bind the VAO and draw the elements:&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(vao);&#xA;glDrawElementsBaseVertex(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0, 0);&#xA;glBindVertexArray(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And finally I can send it some data:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;std::vector&amp;lt;Vertex&amp;gt; vertices = {&#xA;    Vertex(glm::vec3(0, 0, 0), glm::vec2(0, 0)),&#xA;    Vertex(glm::vec3(0, 1, 0), glm::vec2(1, 0)),&#xA;    Vertex(glm::vec3(0, 1, 1), glm::vec2(1, 1)),&#xA;    Vertex(glm::vec3(0, 0, 1), glm::vec2(0, 1)),&#xA;};&#xA;&#xA;std::vector&amp;lt;unsigned int&amp;gt; indices = {&#xA;    0, 1, 2, 2, 3, 0&#xA;};&#xA;&#xA;shape = new Mesh(vertices, indices);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The weird thing is that this works perfectly, but as soon as I try render another mesh it wont render the previous mesh. The weird thing is that say I had mesh A and mesh B. I can render mesh A, then I &lt;em&gt;setup&lt;/em&gt; mesh B, and even if I don't render it, nothing renders at all. Not even mesh A. I assume this is due to the state-based-ness of OpenGL.&lt;/p&gt;&#xA;" OwnerUserId="3173" LastEditorUserId="3437" LastEditDate="2016-06-17T00:55:55.473" LastActivityDate="2016-06-17T00:55:55.473" Title="Can't render multiple VAO's?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2347" PostTypeId="1" CreationDate="2016-04-19T20:58:44.273" Score="3" ViewCount="885" Body="&lt;p&gt;Another code review question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to draw an arrow to represent a vector. I have started with an unit arrow with vertices defined as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//vertex data for vector with arrow    &#xA;GLfloat vertices[] = {&#xA;    //line&#xA;    0.0f, 0.0f, 0.0f,&#xA;    1.0f, 0.0f, 0.0f,&#xA;&#xA;    //arrow bases&#xA;    0.95f, 0.01f, 0.0f,&#xA;    0.95f,-0.01f, 0.0f&#xA;};&#xA;&#xA;GLuint indices[] = {&#xA;    0, 1,       // Line&#xA;    1, 2, 3    // Arrow Triangle&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have another array that contains the actual vector start and end positions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat lineVertices[] = {&#xA;&#xA;    1.0f, 2.0f, 3.0f, //v1 start&#xA;    3.0f, 5.0f,-5.0f, //v1 end&#xA;&#xA;   -1.0f,-1.0f,-1.0f, //v2 start&#xA;   -3.0f, 5.0f,-10.0f //v2 end&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am trying to construct the &lt;code&gt;model&lt;/code&gt; matrix to apply the transformation from &lt;code&gt;lineVertices&lt;/code&gt; for each vectors on the unit arrow.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//'view', and 'projection' matrix is set out side of the loop&#xA;for (GLint i = 0; i &amp;lt; sizeof(lineVertices) / sizeof(GLfloat); i += 6)&#xA;{&#xA;    glm::mat4 model;&#xA;&#xA;    //apply transformation&#xA;    glm::vec3 start(lineVertices[i], lineVertices[i + 1], lineVertices[i + 2]);&#xA;    glm::vec3 end(lineVertices[i + 3], lineVertices[i + 4], lineVertices[i + 5]);&#xA;    glm::vec3 startToEnd = end - start;&#xA;    GLfloat length = glm::length(startToEnd);&#xA;&#xA;    //translate&#xA;    model = glm::translate(model, start);&#xA;&#xA;    //rotate&#xA;    //GLfloat xyAngle = glm::atan(startToEnd.z, length);&#xA;    //GLfloat xzAngle = glm::atan(startToEnd.y, length);&#xA;    //GLfloat yzAngle = glm::atan(startToEnd.x, length);&#xA;&#xA;    //model = glm::rotate(model, xyAngle, glm::vec3(1.0f, 1.0f, 0.0f));&#xA;    //model = glm::rotate(model, xzAngle, glm::vec3(1.0f, 0.0f, 1.0f));&#xA;    //model = glm::rotate(model, yzAngle, glm::vec3(0.0f, 1.0f, 1.0f));&#xA;&#xA;    //rotate&#xA;    GLfloat angleWithZ = glm::acos(startToEnd.z/length);&#xA;    GLfloat angleWithY = glm::acos(startToEnd.y/length);&#xA;    GLfloat angleWithX = glm::acos(startToEnd.x/length);&#xA;&#xA;    model = glm::rotate(model, angleWithX, glm::vec3(0.0f, 0.0f, 1.0f));&#xA;    model = glm::rotate(model, angleWithY, glm::vec3(0.0f, 0.0f, 1.0f));&#xA;    model = glm::rotate(model, angleWithZ, glm::vec3(1.0f, 0.0f, 0.0f));&#xA;&#xA;    //scale&#xA;    model = glm::scale(model, glm::vec3(length));&#xA;&#xA;    glUniformMatrix4fv(glGetUniformLocation(ourShader.Program, &quot;model&quot;), 1, GL_FALSE, glm::value_ptr(model));&#xA;&#xA;    glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, 0);&#xA;    glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, BUFFER_OFFSET(2));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Though this seems to work, as I can see all those arrows, however, I am not sure whether this is the right implementation or not. Please let me know, if this is correct and/or there is room for improvement, or there are easier ways to achieve this, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; updated my code sample (only the rotation part) based on &lt;a href=&quot;https://en.wikipedia.org/wiki/Direction_cosine&quot; rel=&quot;nofollow noreferrer&quot;&gt;Direction cosine (wikipedia)&lt;/a&gt;. Old code is still kept commented. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S.: this implementation is based on following stack exchange discussions: &lt;a href=&quot;https://gamedev.stackexchange.com/a/96960/82355&quot;&gt;1&lt;/a&gt;, &lt;a href=&quot;https://math.stackexchange.com/a/799812/298948&quot;&gt;2&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3098" LastEditorUserId="-1" LastEditDate="2017-04-13T12:19:38.027" LastActivityDate="2016-06-11T08:24:30.833" Title="Represent vector with arrow" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;vectors&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2348" PostTypeId="1" CreationDate="2016-04-20T06:59:31.810" Score="11" ViewCount="1641" Body="&lt;p&gt;There are many references related to the physically-based rendering of several natural features of the numan body, such as skin, hair, eyes.&lt;br&gt;&#xA;However, I could not find specific information about the simulation of visually realistic nails. For example, I did not find specificities of the characteristics of the reaction of human nails to light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://upload.wikimedia.org/wikipedia/commons/a/aa/Daumennagel_mit_Nagelhaut_und_Niednagel.jpg&quot; alt=&quot;Image from the Wikipedia article&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few ideas I had:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;According to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Nail_(anatomy)&quot;&gt;Wikipedia article&lt;/a&gt;, nails are &quot;made of a tough protective protein called keratin. (...) It is made up of dead skin cells&quot;.&lt;br&gt;&#xA;Hair is also &lt;a href=&quot;https://en.wikipedia.org/wiki/Hair&quot;&gt;composed of keratin&lt;/a&gt;, so nail rendering might have a few similarities with hair rendering? However I think the main feature of hair rendering is the coloring of specular highlights due to internal reflections inside the hair fiber. Is that phenomenon significant or does it even happen for nails?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Examination indicates that nails are transparent and that they host sub-surface scattering effects. Are there models combining these phenomenons?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The proximity to skin also seems to suggest that the skin under nails has singular appearance properties. Should this layer require some specific techniques to be simulated too?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;What kind of technology would be involved to simulate accurately the rendering of human nails?&lt;br&gt;&#xA;What kind of tricks digital artists use to simulate the appearance of human nails?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2016-04-20T17:58:44.800" Title="What kind of technology would be involved in the rendering of human nails?" Tags="&lt;rendering&gt;&lt;realistic&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2349" PostTypeId="2" ParentId="2348" CreationDate="2016-04-20T07:22:17.570" Score="8" Body="&lt;p&gt;I'm not aware of any rendering technology designed specially for fingernails. Just eyeballing it, I would suggest that a combination of subsurface scattering with a relatively smooth glossy specular surface would get you most of the way there. In other words, you could use the same shader as you do for skin, but with different textures and different specular parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wouldn't guess that a hair shader would be too useful. Nails are not in the shape of fibers, nor do they have the kind of complex occlusion and shadowing that hair does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, if the scattering properties of the nails are different enough from that of skin, it might make sense to use a different shader (for instance, doing some sort of volumetric scattering instead of a dipole approximation). I don't know of any references on skin scattering that have investigated nails specifically, though.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-20T07:22:17.570" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2350" PostTypeId="2" ParentId="2348" CreationDate="2016-04-20T07:48:13.090" Score="7" Body="&lt;p&gt;I don't know of any specific technology for rendering fingernails, but I agree that using subsurface scattering with some specular would be a good starting point. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A couple of things I'd take into account are that most natural nails without any coatings or nail polish aren't that shiny and have some ridges, so there should be some anisotropy to the highlights. I think a hair shader might be overkill for that though. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few things I think would be interesting to look at would be things like inclusions from injury/disease/etc., discoloration, and varying thickness; there's probably some work to be done on how light scatters between the soft tissue of the nailbed and the nail itself. Another interesting thing to look at would be nails with nail polish on them; I bet you could do some cool stuff with car paint effects and long distance scattering (like with a backlit manicured nail).&lt;/p&gt;&#xA;" OwnerUserId="3178" LastActivityDate="2016-04-20T07:48:13.090" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2353" PostTypeId="2" ParentId="2342" CreationDate="2016-04-21T18:09:25.737" Score="2" Body="&lt;p&gt;Huge thanks to @MJP who answered this.&lt;br&gt;&#xA;The aim is to avoid the simplification made when using tangent space normals.&#xA;Here is the paper : &lt;a href=&quot;http://blog.selfshadow.com/publications/blending-in-detail/&quot; rel=&quot;nofollow&quot;&gt;Blending in detail&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But only implement equation (&lt;a href=&quot;http://blog.selfshadow.com/publications/blending-in-detail/#mjx-eqn-eqrotation&quot; rel=&quot;nofollow&quot;&gt;4&lt;/a&gt;) which gives you this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 ReorientNormal(in float3 u, in float3 t, in float3 s)&#xA;{&#xA;    // Build the shortest-arc quaternion&#xA;    float4 q = float4(cross(s, t), dot(s, t) + 1) / sqrt(2 * (dot(s, t) + 1));&#xA;    // Rotate the normal&#xA;    return u * (q.w * q.w - dot(q.xyz, q.xyz)) + 2 * q.xyz * dot(q.xyz, u) + 2 * q.w * cross(q.xyz, u);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Original answer is &lt;a href=&quot;http://www.gamedev.net/topic/678043-how-to-blend-world-space-normals/?view=findpost&amp;amp;p=5287707&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2016-04-21T18:09:25.737" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2354" PostTypeId="2" ParentId="2332" CreationDate="2016-04-22T05:32:42.897" Score="4" Body="&lt;p&gt;In order to replace a color with another color, you need some sort of &lt;a href=&quot;https://en.wikipedia.org/wiki/Metric_(mathematics)&quot; rel=&quot;nofollow noreferrer&quot;&gt;distance metric&lt;/a&gt; between the colors and a function for calculating the &lt;a href=&quot;https://en.wikipedia.org/wiki/Blend_modes&quot; rel=&quot;nofollow noreferrer&quot;&gt;blending&lt;/a&gt; based on that distance. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finding a distance between 2 colors can be tricky. RGB is a bad color space to measure the distance between colors for perceptual uses. HSV or YCbCr are better. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have the colors in a color space you like, you need to decide how to calculate the distance. I generally calculate the hue distance for starters. If the hue of the color I'm considering replacing is within +/- some threshold (possibly set by the user), then I check to see if the saturation and value are within a certain range, too. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once I've found a color that's within the ranges specified, I calculate a blending amount. Usually this will be 100% if the color in the image exactly matches the color I want to replace, and will fall off to 0 at the thresholds of hue, saturation and brightness. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You then need to calculate the color you're going to use as a replacement color. It's useful to offset the hue, saturation and value (or Y, Cb, and Cr components) by the same amount as the color in the image differs from the replacement color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now you have the original color in the image, the color to replace it with, and a blending amount. You still need to figure out which blend mode you want to use. I would start with what Photoshop calls &quot;Normal&quot; or &quot;Over&quot;. That would be a linear mix of the two. If you have colors A and B with a mix amount of 25%, it would be calculated like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;newColor = A * .25 + B * (1.0 - .25);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some relevant answers I gave to similar questions on Stack Overflow:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/9234724/how-to-change-hue-of-a-texture-with-glsl/9234854#9234854&quot;&gt;How to Change the Hue of a Texture with GLSL&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/9064556/better-image-coloring-logic-algorithm/9075340#9075340&quot;&gt;Better Image Coloring Logic/Algorithm&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-04-22T05:32:42.897" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2355" PostTypeId="1" CreationDate="2016-04-22T09:39:17.053" Score="8" ViewCount="254" Body="&lt;p&gt;My shape is a slightly concave polygon, and I'd like to know the maximal diameter. I imagine a straight line between two points on the surface of the polygon, such that the line does not pass outside the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a general algorithm for this? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my case I am interested in 2D. My shapes are tumors in medical images. So we can also assume:&#xA;1 the centroid is always inside the polygon. &#xA;2 a high vertex density, i.e. the next vertex is always close to the previous one. &lt;/p&gt;&#xA;" OwnerUserId="3204" LastEditorUserId="3204" LastEditDate="2016-04-23T05:39:47.663" LastActivityDate="2018-08-16T10:39:15.173" Title="Find the longest straight line between two points on surface of polygon" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="11" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2356" PostTypeId="1" CreationDate="2016-04-24T14:21:39.993" Score="3" ViewCount="180" Body="&lt;p&gt;I'm attempting to test out the maths behind bounding volume algorithms (prior to ray tracing) using MATLAB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far, I have successfully created the relatively trivial axis aligned bounding volume, and I believe I have successfully created a bounding sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've attempted to then create an object aligned bounding volume - but although I believe I have got the principle axes correct because the box appears to be a suitable shape - I have been unable to translate it correctly &quot;onto&quot; the shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Essentially my question is - what am I doing wrong in my algorithm &amp;amp; how do I translate my bounding volume onto the shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The two sources I have been using are &lt;a href=&quot;https://github.com/tl3shi/books/blob/master/GameDev/Math/Mathematics.for.3D.Game.Programming.and.Computer.Graphics,.Lengyel,.3rd,.2011.pdf&quot; rel=&quot;nofollow&quot;&gt;Maths for 3D Games&lt;/a&gt;, as well as a &lt;a href=&quot;http://jamesgregson.blogspot.co.uk/2011/03/latex-test.html&quot; rel=&quot;nofollow&quot;&gt;blog&lt;/a&gt; which gives some indication on to do the translation - but doesn't seem to have worked very well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have put my source code below - thanks very much!&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;%//===================Declare vertices and faces===================&#xA;vp_vtx = [379.379,684.302,319.752,711.497,215.956,439.237,600,600,732.938,418.084,600,600,747.081;&#xA;    225.836,158.305,394.208,337.480,84.834,245.958,212.858,342.251,322.344,330.576,300,416.190,398.885;&#xA;    0.933,0.917,0.904,0.878,0.854,0.923,0.914,0.949,0.943,0.908,0.896,0.940,0.933;&#xA;    1,1,1,1,1,1,1,1,1,1,1,1,1];&#xA;ws_fcs = [2,4,3,6,6,7,7,10,10; %//Faces forming shape&#xA;    4,3,1,7,11,9,13,11,13;&#xA;    5,5,5,11,10,13,11,13,12];&#xA;%//===================Create an AA bounding box===================&#xA;x = vp_vtx(1,:);y = vp_vtx(2,:);z = vp_vtx(3,:); %//Seperate vertex coordinates&#xA;bb_vtx = [min(x),max(x),min(x),max(x),min(x),max(x),min(x),max(x); %//Take min/max from each&#xA;    min(y),min(y),max(y),max(y),min(y),min(y),max(y),max(y); %//To form enclosing box&#xA;    min(z),min(z),min(z),min(z),max(z),max(z),max(z),max(z)];&#xA;&#xA;bb_fcs = [1,2,6,1,1,3; 2,4,5,5,2,4;4,8,7,7,6,8; 3,6,8,3,5,7]; %//Allocate faces of box&#xA;&#xA;figure(); grid on; hold on; xlabel('x'); ylabel('y'); zlabel('z');&#xA;scatter3(vp_vtx(1,:),vp_vtx(2,:),vp_vtx(3,:),'r'); %//Plot shape&#xA;patch('Faces',ws_fcs','Vertices',vp_vtx(1:3,:)', 'Facecolor', 'r','FaceAlpha', 0.1)&#xA;patch('Faces',bb_fcs', 'Vertices',bb_vtx','FaceColor','g','FaceAlpha', 0.05);%//Plot enclosing box&#xA;&#xA;mean_point = sum(vp_vtx,2)/length(vp_vtx);&#xA;C = zeros(4,4); %//Create 4x4 empty matrix&#xA;for i = 1:length(vp_vtx)&#xA;    C = C+(vp_vtx(:,i)-mean_point)*(vp_vtx(:,i)-mean_point)'; %//Sum to get covarience matrix&#xA;end;&#xA;C = C/length(vp_vtx); %//Scale by the number of samples&#xA;&#xA;[y,v] = eig(C(1:3,1:3)) ;%//Get eigenvalues &amp;amp; eigen vectors&#xA;&#xA;R = y(:,1); %//Eigen vectors &amp;amp; values form object aligned axes&#xA;S = y(:,2);&#xA;T = y(:,3);%//T is principle axis as derived from largest eigenvalue&#xA;&#xA;%//========Create an Object Orientated Bounding Box=========&#xA;dot_arr = zeros(size(vp_vtx));&#xA;for i = 1:length(vp_vtx)  %//Create array of dot products with each OO axis&#xA;    dot_arr(1,i) = dot(vp_vtx(1:3,i),T);&#xA;    dot_arr(2,i) = dot(vp_vtx(1:3,i),R);&#xA;    dot_arr(3,i) = dot(vp_vtx(1:3,i),S);&#xA;end&#xA;%//Get min/max variation in each OO axis&#xA;a = 0.5*(min(dot_arr(1,:)) + max(dot_arr(1,:)));&#xA;b = 0.5*(min(dot_arr(2,:)) + max(dot_arr(2,:)));&#xA;c = 0.5*(min(dot_arr(3,:)) + max(dot_arr(3,:)));&#xA;%//Centre is point where the 3 planes of the box intersect? (from book)&#xA;q = a*T + b*R + c*S;&#xA;&#xA;Tr = vertcat(horzcat(T,S,R,q),[0,0,0,1]); %//Transform &amp;amp; translate original AA box&#xA;bb_vtx = Tr*vertcat(bb_vtx, ones(1,length(bb_vtx)));&#xA;patch('Faces',bb_fcs', 'Vertices',bb_vtx(1:3,:)','FaceColor','g','FaceAlpha', 0.05);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2646" LastEditorUserId="2646" LastEditDate="2016-04-25T13:47:39.697" LastActivityDate="2016-04-27T09:34:58.197" Title="Creating an Object Orientated Bounding Volume" Tags="&lt;raytracing&gt;&lt;transformations&gt;&lt;bounding-volume-hierarchy&gt;&lt;matlab&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2357" PostTypeId="1" AcceptedAnswerId="2389" CreationDate="2016-04-25T07:39:59.417" Score="7" ViewCount="413" Body="&lt;p&gt;Whenever I try to adjust gamma settings in a game, I am shown three different icons and usually asked to make sure the left-most one is barely visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tetOP.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tetOP.png&quot; alt=&quot;Image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the other two icons for?&lt;/p&gt;&#xA;" OwnerUserId="3220" LastActivityDate="2016-05-03T13:17:41.510" Title="Gamma setting in games - Why 3 icons?" Tags="&lt;gamma&gt;&lt;brightness&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2358" PostTypeId="2" ParentId="306" CreationDate="2016-04-25T07:55:10.327" Score="46" Body="&lt;p&gt;Sorry about the long wait, but it has become obvious that although the article I have promised is basically complete, the publishing process will take some time. Therefore, I have instead prepared an open source program with my new multi-channel distance field construction algorithm, &lt;strong&gt;msdfgen&lt;/strong&gt;, which you can try out right now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is available on GitHub: &lt;a href=&quot;https://github.com/Chlumsky/msdfgen&quot; rel=&quot;noreferrer&quot;&gt;https://github.com/Chlumsky/msdfgen&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I am new to this, so please let me know if there is anything wrong with the repository.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Someone also asked about how it compares to a larger monochrome distance field, so here is a teaser of the quality difference. However, it really depends on the particular font, and I would not say it is always worth the extra data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dhhiy.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dhhiy.png&quot; alt=&quot;Multi-channel distance field 16x16&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ExmTZ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ExmTZ.png&quot; alt=&quot;Monochrome distance field 32x32&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2811" LastActivityDate="2016-04-25T07:55:10.327" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2359" PostTypeId="1" CreationDate="2016-04-26T11:54:22.140" Score="3" ViewCount="421" Body="&lt;p&gt;I have an application in which I am using an octree to store a volume mesh of axis-aligned bounding boxes (AABBs).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given a water-tight manifold triangle mesh, I need to:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;find if an AABB is intersected by or completely inside/outside of the surface mesh,&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;clip the surface mesh with the intersected AABBs to generate triangles that completely lie within each AABB.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The triangulation and the octree containing the AABBs are both dynamic. The number of leaf nodes in the octree is huge. The number of triangles in the surface mesh is much smaller (O(10^9 - 10^13) octree nodes, vs O(10^6) triangles).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which data-structures and algorithm are suitable for my problem?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now I:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;store the triangles in the same octree as the volume mesh,&lt;/li&gt;&#xA;&lt;li&gt;store each triangle in the smallest octree node that contains it,&lt;/li&gt;&#xA;&lt;li&gt;clip the triangle mesh with a single AABB by traversing from that AABB to both the root node and its leafs clipping each triangle contained in the nodes with the AABB. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The triangles in the nodes until the leafs are fully contained within the AABB and don't need any &quot;clipping&quot; (the AABB just contains those triangles), while the ones contained in the nodes from the AABB to the root need clipping. However:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;due to the way I am storing the triangles (in the smallest octree node that fully contains them) I don't have an upper bound in the maximum number of triangles that can be stored within each single octree node, so I don't have an upper bound in the number of triangles that have to be tested against a single AABB.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;if I just want to test if an AABB is intersected by the triangle mesh, I have to test all triangles between that AABB and the root node which might be expensive. Ideally I would like to have a very fast way to test, and then clip the mesh if the test is true.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;currently I have no fast way of determining if a node is inside/outside/intersected by the mesh. I could construct a signed distance field (which is expensive), or perform some ray casting (which is also expensive), maybe there is a better solution or maybe I just need to precompute something to speed this up every time I move the triangle mesh.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;moving the triangle mesh requires manipulating the octree (I don't know if this can be avoided). Ideally I would like to generate an octree for the triangle mesh once, and then just move the mesh using a single transformation matrix. However, then I would need to have some sort of mapping between &quot;the octree containing the triangle mesh&quot; and &quot;the octree of my volume mesh&quot;. Maybe this mapping is trivial but I haven't figured it out yet. This would save me from manipulating the octree when I move the mesh and maybe the coordinate transformations that would be required are negligible with the cost of clipping.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="3225" LastEditorUserId="3225" LastEditDate="2016-05-04T14:12:42.043" LastActivityDate="2016-05-05T06:44:32.243" Title="Data structure and algorithm for clipping triangulation with leaf nodes of an octree" Tags="&lt;algorithm&gt;&lt;geometry&gt;&lt;performance&gt;&lt;data-structure&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2360" PostTypeId="1" AcceptedAnswerId="2361" CreationDate="2016-04-26T17:11:05.690" Score="1" ViewCount="151" Body="&lt;p&gt;Say I have rendered an HDR ray traced image with dimensions 1920x1080 (width x height) pixels and I want to instead represent it with dimensions 960x540. Assume as well that the image has not yet been gamma corrected (i.e. it is still in linear space). How should I go about downsampling the image such that I don't need to re-render the image in the new dimensions?&lt;/p&gt;&#xA;" OwnerUserId="1924" LastActivityDate="2016-04-26T23:27:46.947" Title="How can I resize a rendered ray traced image?" Tags="&lt;raytracing&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2361" PostTypeId="2" ParentId="2360" CreationDate="2016-04-26T23:27:46.947" Score="5" Body="&lt;p&gt;Since you want to downsample the image by a factor of 2 along each axis, a simple and easy thing to do is just average a 2&amp;times;2 box of source pixels to generate each destination pixel. In pseudocode this would look like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for dest_y = 0 to 540&#xA;    src_y = dest_y*2&#xA;    for dest_x = 0 to 960&#xA;        src_x = dest_x*2&#xA;        average = 0.25 * (src[src_y][src_x] + src[src_y][src_x+1] +&#xA;                          src[src_y+1][src_x] + src[src_y+1][src_x+1])&#xA;        dest[dest_y][dest_x] = average&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This will do an okay job, but for higher-quality downsampling or resizing images to any size (not just neat integer factors), I suggest looking at the &lt;a href=&quot;https://github.com/nothings/stb/blob/master/stb_image_resize.h&quot;&gt;stb_image_resize&lt;/a&gt; library. It's quite easy to use, supports either 8-bit or floating-point images with any number of channels, and gives good results.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-26T23:27:46.947" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2362" PostTypeId="1" CreationDate="2016-04-27T10:12:31.790" Score="1" ViewCount="715" Body="&lt;p&gt;Thanks for the &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2140/intersection-between-line-segments-narrowed-precondition&quot;&gt;suggestions&lt;/a&gt;. Now I am doing it as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First off it is identified if two line segments intersect or not. And I am using the algorithm described in the book - &quot;Introduction to Algorithms&quot; chapter 33 (Computational Geometry). &lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;int orientation(glm::i16vec2 &amp;amp;p1,&#xA;                glm::i16vec2 &amp;amp;p2,&#xA;                glm::i16vec2 &amp;amp;p3)&#xA;{&#xA;   return (((p3.x - p1.x) * (p2.y - p1.y)) - ((p2.x - p1.x) * (p3.y - p1.y)));&#xA;}&#xA;&#xA;&#xA;bool onSegment(const glm::i16vec2 &amp;amp;pi,&#xA;                 const glm::i16vec2 &amp;amp;pj,&#xA;                 const glm::i16vec2 &amp;amp;pk)&#xA;{&#xA;    if((std::min(pi.x,pj.x) &amp;lt;= pk.x &amp;amp;&amp;amp; pk.x &amp;lt;= std::max(pi.x,pj.x))  &amp;amp;&amp;amp;&#xA;    (std::min(pi.y,pj.y) &amp;lt;= pk.y &amp;amp;&amp;amp; pk.y &amp;lt;= std::max(pi.y,pj.y)))&#xA;        return true;&#xA;    else&#xA;        return false;&#xA;}&#xA;&#xA;bool intersects(const glm::i16vec2 &amp;amp;p1,const glm::i16vec2 &amp;amp;p2,&#xA;                const glm::i16vec2 &amp;amp;p3,const glm::i16vec2 &amp;amp;p4)&#xA;{&#xA;&#xA;    int d1 = orientation(p1,p2,p3);&#xA;    int d2 = orientation(p1,p2,p4);&#xA;    int d3 = orientation(p3,p4,p1);&#xA;    int d4 = orientation(p3,p4,p2);&#xA;&#xA;    if(((d1 &amp;gt; 0 &amp;amp;&amp;amp; d2 &amp;lt; 0) || (d1 &amp;lt; 0 &amp;amp;&amp;amp; d2 &amp;gt; 0)) &amp;amp;&amp;amp;&#xA;        ((d3 &amp;gt; 0 &amp;amp;&amp;amp; d4 &amp;lt; 0) || (d3 &amp;lt; 0 &amp;amp;&amp;amp; d4 &amp;gt; 0)))&#xA;          return true;&#xA;    else if(d1 == 0 &amp;amp;&amp;amp; onSegment(p3,p4,p1))&#xA;          return true;&#xA;    else if(d2 == 0 &amp;amp;&amp;amp; onSegment(p3,p4,p2))&#xA;          return true;&#xA;    else if(d3 == 0 &amp;amp;&amp;amp; onSegment(p1,p2,p3))&#xA;          return true;&#xA;    else if(d4 == 0 &amp;amp;&amp;amp; onSegment(p1,p2,p4))&#xA;          return true;&#xA;    else&#xA;          return false;    &#xA;}&#xA;&#xA;int main()&#xA;{&#xA;    glm::i16vec2 hs(5,1);  // p1&#xA;    glm::i16vec2 he(5,3); // p2&#xA;&#xA;    glm::i16vec2 cs(5,1);   // p3&#xA;    glm::i16vec2 ce(5,3); // p4&#xA;&#xA;    if(intersects(hs,he,cs,ce))&#xA;      std::cout &amp;lt;&amp;lt; &quot;It has intersection&quot; &amp;lt;&amp;lt; std::endl;&#xA;    else&#xA;      std::cout &amp;lt;&amp;lt; &quot;No intersection&quot; &amp;lt;&amp;lt; std::endl;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Once the boolean flag mentions that the intersection point is found, then the exact intersection point is extracted as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;short int getXIntersection(float x1,&#xA;                           float y1,&#xA;                           float x2,&#xA;                           float y2,&#xA;                           float yPos)&#xA;{&#xA;    float t = (x2 - x1) / (y2 - y1);&#xA;&#xA;    float xDbl = (static_cast&amp;lt;double&amp;gt;(yPos) - y1) * t + x1;&#xA;&#xA;    return static_cast&amp;lt;short int&amp;gt;(std::floor(0.5+xDbl));&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The above function snippet is for the case when one of the line segments is parallel to the X-axis and the other segment is of arbitrary orientation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other case is when one of the line segments is parallel to Y-axis and the other segment is of arbitrary orientation. For the sake of brevity, the code snippet is not written here. I hope you can imagine how it will be? Yet it is included in the following snippet as for some coordinate values I am having wrong output:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;short int getYIntersection(float x1,&#xA;                           float y1,&#xA;                           float x2,&#xA;                           float y2,&#xA;                           float xPos)&#xA;{&#xA;    float t = (y2 - y1)/(x2 - x1);&#xA;&#xA;    float yDbl = (static_cast&amp;lt;double&amp;gt;(xPos) - x1) * t + y1;&#xA;&#xA;    return static_cast&amp;lt;short int&amp;gt;(std::floor(0.5+yDbl));&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;RECENT : Lets a line segment that is parallel to the Y-axis and it has the following coordinates as start and end point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;hs(3124,-3168)&#xA;he(3124,-3094)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other arbitrarily oriented line segment has the following coordinates:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;cs(3124,-3168)&#xA;ce(3125,-3116)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the line segment parallel to Y-axis has the constant X-value, should not the function getYIntersection() get the correct Y-value . But I am not getting it- instead I am getting -3213 as the Y-intersection value. Is there anything I am missing here ? The Y-value of the intersection must be within both the line segment, unfortunately it is not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you imagine any loop hole in this overall algorithm? In practice, I am getting some huge intersection point value that is way out of the region.&#xA;The intersection point is saved as&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;    short int&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I am getting the  X-intersection value -32768. This value is way out of the bounding area where all the intersection points must lie within.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any thoughts?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After several comments and one answer , some adjustments is made within the code. It is found that with overlapping line segments the algorithm return true. It is not intended in my case, all overlapping line segments must not be flagged as intersection. Some hint would be nice. The issue of getting the intersection point is still in the pipeline. I believe that I missed the part that must be done after the initial true/false algorithm - that is to test if the calculated intersectin point lies within both the line segments or not. If it does, only then we eventually have the true intersection otherwise no intersection at all. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some feed-back would be great! &lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-05-10T15:17:40.067" Title="Line segment intersection test and find the point of intersection" Tags="&lt;mathematics&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="2364" PostTypeId="1" AcceptedAnswerId="2376" CreationDate="2016-04-28T11:41:14.680" Score="2" ViewCount="951" Body="&lt;p&gt;I have implemented line segments &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2362/line-segment-intersection-test-and-find-the-point-of-intersection&quot;&gt;intersetion test&lt;/a&gt; and at the very same test I want to include the fact that if two line segments overlap each other partially or fully , it will be flagged as no intersection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some hint to it would be great to have!&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-04-30T01:13:58.043" Title="Line segments overlapping" Tags="&lt;2d-graphics&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2365" PostTypeId="1" CreationDate="2016-04-28T16:18:55.477" Score="11" ViewCount="474" Body="&lt;p&gt;I am writing an OpenCL program for use with my AMD Radeon HD 7800 series GPU. According to AMD's &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/07/AMD_Accelerated_Parallel_Processing_OpenCL_Programming_Guide-rev-2.7.pdf&quot; rel=&quot;noreferrer&quot;&gt;OpenCL programming guide&lt;/a&gt;, this generation of GPU has two hardware queues that can operate asynchronously.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;strong&gt;5.5.6 Command Queue&lt;/strong&gt;&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;For Southern Islands and later, devices support at least two hardware compute&#xA;  queues. That allows an application to increase the throughput of small dispatches&#xA;  with two command queues for asynchronous submission and possibly execution.&#xA;  The hardware compute queues are selected in the following order: first queue =&#xA;  even OCL command queues, second queue = odd OCL queues.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;To do this, I've created two separate OpenCL command queues to feed data to the GPU. Roughly, &lt;a href=&quot;https://github.com/Mokosha/GenTC/blob/master/codec/codec.cpp#L242&quot; rel=&quot;noreferrer&quot;&gt;the program running on the host thread&lt;/a&gt; looks something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static const int kNumQueues = 2;&#xA;cl_command_queue default_queue;&#xA;cl_command_queue work_queue[kNumQueues];&#xA;&#xA;static const int N = 256;&#xA;cl_mem gl_buffers[N];&#xA;cl_event finish_events[N];&#xA;&#xA;clEnqueueAcquireGLObjects(default_queue, gl_buffers, N);&#xA;&#xA;int queue_idx = 0;&#xA;for (int i = 0; i &amp;lt; N; ++i) {&#xA;  cl_command_queue queue = work_queue[queue_idx];&#xA;&#xA;  cl_mem src = clCreateBuffer(CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, ...);&#xA;&#xA;  // Enqueue a few kernels&#xA;  cl_mem tmp1 = clCreateBuffer(CL_READ_WRITE);&#xA;  clEnqueueNDRangeKernel(kernel1, queue, src, tmp1);&#xA;&#xA;  clEnqueueNDRangeKernel(kernel2, queue, tmp1, tmp1);&#xA;&#xA;  cl_mem tmp2 = clCreateBuffer(CL_READ_WRITE);&#xA;  clEnqueueNDRangeKernel(kernel2, queue, tmp1, tmp2);&#xA;&#xA;  clEnqueueNDRangeKernel(kernel3, queue, tmp2, gl_buffer[i], finish_events + i);&#xA;&#xA;  queue_idx = (queue_idx + 1) % kNumQueues;&#xA;}&#xA;&#xA;clEnqueueReleaseGLObjects(default_queue, gl_buffers, N);&#xA;clWaitForEvents(N, finish_events);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With &lt;code&gt;kNumQueues = 1&lt;/code&gt;, this application pretty much works as intended: it collects all of the work into a single command queue that then runs to completion with the GPU being fairly busy the whole time. I'm able to see this by looking at the output of the CodeXL profiler:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IP41r.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IP41r.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when I set &lt;code&gt;kNumQueues = 2&lt;/code&gt;, I expect the same thing to happen but with the work evenly split across two queues. If anything, I expect each queue to have the same characteristics individually as the one queue: that it starts work sequentially until everything is done. However, when using two queues, I can see that not all of the work is split across the two hardware queues:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eDhDI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eDhDI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the beginning of the GPU's work, the queues do manage to run some kernels asynchronously, although it seems like neither ever fully occupies the hardware queues (unless my understanding is mistaken). Near the end of the GPU work, it seems like the queues are adding work sequentially to only one of the hardware queues, but there are even times that no kernels are running. What gives? Do I have some fundamental misunderstanding of how the runtime is supposed to behave?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a few theories as to why this is happening:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The interspersed &lt;code&gt;clCreateBuffer&lt;/code&gt; calls are forcing the GPU to allocate device resources from a shared memory pool synchronously which stalls the execution of individual kernels.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The underlying OpenCL implementation does not map logical queues to physical queues, and only decides where to place objects at runtime.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Because I'm using GL objects, the GPU needs to synchronize access to specially allocated memory during writes.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Are any of these assumptions true? Does anyone know what could be causing the GPU to wait in the two-queue scenario? Any and all insight would be appreciated!&lt;/p&gt;&#xA;" OwnerUserId="197" LastEditorUserId="197" LastEditDate="2016-05-03T03:51:59.007" LastActivityDate="2018-12-02T04:12:48.333" Title="What is my GPU waiting on?" Tags="&lt;gpgpu&gt;&lt;opencl&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2366" PostTypeId="1" AcceptedAnswerId="2367" CreationDate="2016-04-28T18:11:12.010" Score="2" ViewCount="332" Body="&lt;p&gt;I'm currently trying to develop a game using Cocos2d-x using C++.&#xA;I really need to generate this burst or (donut-shaped) pulse.&#xA;I'm having a difficult time how to generate such shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At first, I was thinking of scaling the image but that didn't work out because the line or &quot;diameter&quot; of the donut shape gets bigger accordingly.&#xA;Any experienced coders who can provide an equation of this thing? or maybe &quot;mathematics&quot; is more exact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/t5yOY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t5yOY.png&quot; alt=&quot;c++ code sample&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=ewnEE5mt1ZM&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=ewnEE5mt1ZM&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3248" LastEditorDisplayName="user246" LastEditDate="2017-04-28T08:15:44.547" LastActivityDate="2017-04-28T08:15:44.547" Title="Generate this kind of 2d burst or pulse algorithm?" Tags="&lt;c++&gt;&lt;2d&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2367" PostTypeId="2" ParentId="2366" CreationDate="2016-04-28T19:49:11.807" Score="7" Body="&lt;p&gt;Rather than using an image, I would suggest doing this kind of effect using a shader. I'm not familiar with Cocos2d-x, but some quick googling suggests that it can work with shaders. You'd use a pixel shader that calculates the distance of each pixel to the center of the pulse effect, then applies a function based on that distance to define the shape and appearance of the pulse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I made a &lt;a href=&quot;https://www.shadertoy.com/view/MdtXWX&quot; rel=&quot;noreferrer&quot;&gt;quick shadertoy&lt;/a&gt; as a proof of concept and example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/49koo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-28T19:49:11.807" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2368" PostTypeId="1" AcceptedAnswerId="2374" CreationDate="2016-04-28T20:24:24.297" Score="6" ViewCount="111" Body="&lt;p&gt;I have a 3D scene I use to generate some images which I then process in Matlab. I noticed that when global illumination (GI) is not enabled, rendering always generates exactly the same pixel-for-pixel image (as far as I can tell). However, when I enable GI, the image is not exactly the same. I have been told (I originally accidentally posted &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/70432/gi-leading-to-image-variation/70480#70480&quot;&gt;here&lt;/a&gt;) that GI is stochastic and so this is to be somewhat expected. However, I am curious if there's any way to avoid it (while still using GI).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="3251" LastEditorUserId="-1" LastEditDate="2017-04-13T12:46:19.383" LastActivityDate="2016-04-29T07:25:08.900" Title="Global illumination leading to image variation" Tags="&lt;rendering&gt;&lt;global-illumination&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2369" PostTypeId="2" ParentId="2368" CreationDate="2016-04-28T20:43:54.790" Score="5" Body="&lt;p&gt;If you can make your samples deterministic (the same from run to run - don't base random sample points on time or any other non deterministic value), it will be a stable rendering that you get every time.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-04-28T22:08:45.650" LastActivityDate="2016-04-28T22:08:45.650" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2370" PostTypeId="1" AcceptedAnswerId="2375" CreationDate="2016-04-28T20:50:53.533" Score="4" ViewCount="1183" Body="&lt;p&gt;What I'm trying to do is to simulate refraction through biconcave lens described by spheres &lt;code&gt;A&lt;/code&gt;, &lt;code&gt;B&lt;/code&gt;, &lt;code&gt;C&lt;/code&gt; where &lt;code&gt;C&lt;/code&gt; is a sphere in between &lt;code&gt;A&lt;/code&gt; and &lt;code&gt;B&lt;/code&gt;. So far I've gathered that a good approach would be to use CSG when it comes to modeling such object. I'm failing to understand how to implement this though. There are mentions of using Interval Arithmetics but I don't understand how exactly are they supposed to help me.&lt;/p&gt;&#xA;" OwnerUserId="3233" LastActivityDate="2016-04-29T13:54:57.470" Title="How to implement Constructive Solid Geometry in ray tracing with implicit surfaces (spheres)?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2372" PostTypeId="2" ParentId="2364" CreationDate="2016-04-29T03:32:36.057" Score="0" Body="&lt;p&gt;If you're working in 2D, it should be enough to just take the dot product of the normals of the lines and if it is -1 or 1 then the lines are parallel, and either don't overlap or fully overlap. 2 lines cannot &quot;partially overlap&quot;. They either meet at a single point, at every point, or no points.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-04-29T03:32:36.057" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2374" PostTypeId="2" ParentId="2368" CreationDate="2016-04-29T07:08:27.200" Score="2" Body="&lt;p&gt;Yes, computation of global illumination is usually done in a stochastic way and as such it relies on randomly generated numbers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Typically pseudo random generators are employed, which generate deterministic sequences, and usually have so called &quot;seed&quot; parameter. The seed basically says where to start in the sequence, which in turn affects the noise pattern of your rendered image. If you can use the same seed for each run, there is a high chance of getting identical results. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is whether the software that you use allows you to do that. In the rendering settings, I would suggest looking for for words like seed, random or deterministic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; Since you said you use Vray, it seems to me that using &quot;Deterministic Monte Carlo&quot; engine should be the way to go.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-04-29T07:25:08.900" LastActivityDate="2016-04-29T07:25:08.900" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2375" PostTypeId="2" ParentId="2370" CreationDate="2016-04-29T13:54:57.470" Score="6" Body="&lt;p&gt;I'm not sure what exactly you are asking but, IIRC, to do CSG with ray tracing, you maintain not just the closest intersection with an object, but a list of ordered pairs of [Inpoint, OutPoint] 'interval' distances. With a single sphere test (or any solid convex primitive for that matter), this list would have at most one [Inpoint, OutPoint] entry &lt;em&gt;or&lt;/em&gt; is empty if there is a miss.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To implement CSG you then apply the binary operator to a pair of lists, which in turn means applying them to the entries in the lists in a manner akin to merge-sorting two lists. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, for intersection, if you had  [a,b] in one list and [c,d] in the other, compute  e=Max(a,c) f=Min(b,d).  If e &gt; f there's no intersection else return the intersection, [e,f].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does that help?&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2016-04-29T13:54:57.470" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2376" PostTypeId="2" ParentId="2364" CreationDate="2016-04-30T01:06:36.060" Score="1" Body="&lt;p&gt;The first step in your existing code calculates the orientations of one line segment relative to each of the two end points of the other line segment, using the cross product. This allows testing whether the other line segment has one end point anticlockwise and the other end point clockwise from the first line segment, indicating that the line on which the first segment lies cuts the other segment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rather than writing a new test, you can use these same orientations to test for line segments that overlap (including partial overlap). If both segments lie on the same line, then all four orientations calculated in your first step will be zero, because none of the end points are either clockwise or anticlockwise from the line, since they are on the line. Then it remains only to check whether the two segments on the same line overlap, by checking whether either of them has an end point between the end points of the other segment.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-04-30T01:13:58.043" LastActivityDate="2016-04-30T01:13:58.043" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2377" PostTypeId="1" AcceptedAnswerId="2380" CreationDate="2016-04-30T10:43:15.217" Score="8" ViewCount="1057" Body="&lt;p&gt;Recently I'm developing a Monte-Carlo path tracer. To measure my tracer's performance, I decided to implement a simple mechanism to count how many rays can it trace in a second. Then here comes the problem, there are two ways to define a single ray:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;ol&gt;&#xA;  &lt;li&gt;&lt;p&gt;A complete ray, i.e., starting from camera and bouncing around the scene until it terminates.&lt;/p&gt;&lt;/li&gt;&#xA;  &lt;li&gt;&lt;p&gt;The ray originated from each intersection point.&lt;/p&gt;&lt;/li&gt;&#xA;  &lt;/ol&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Although many people use &quot;Rays per Second&quot; to measure ray/path tracer's performance, how they recognize &quot;rays&quot; is unclear to me. Perhaps anybody knows?&lt;/p&gt;&#xA;" OwnerUserId="3267" LastEditorUserId="3267" LastEditDate="2016-04-30T18:59:36.110" LastActivityDate="2016-04-30T22:55:42.313" Title="How does everyone count &quot;Rays per Second&quot;?" Tags="&lt;raytracing&gt;&lt;performance&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2378" PostTypeId="1" AcceptedAnswerId="2379" CreationDate="2016-04-30T19:06:49.000" Score="3" ViewCount="252" Body="&lt;p&gt;We have a matrix      &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix} a_{11} &amp;amp; a_{12} &amp;amp; a_{13} \\ a_{21} &amp;amp; a_{22} &amp;amp; a_{23} \\ a_{31} &amp;amp; a_{32} &amp;amp; a_{33} \end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This matrix represents a transformation in homogeneous coordinates.&#xA;My question is whether the above matrix is affine or not and an example too for this.                  &lt;/p&gt;&#xA;" OwnerUserId="3271" LastEditorUserId="48" LastEditDate="2016-04-30T22:02:29.723" LastActivityDate="2016-04-30T22:02:29.723" Title="Affine Transformation" Tags="&lt;transformations&gt;&lt;affine-transformations&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2379" PostTypeId="2" ParentId="2378" CreationDate="2016-04-30T22:00:59.013" Score="4" Body="&lt;p&gt;It is not necessarily affine. An affine matrix in homogeneous coordinates has a form like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix} a_{11} &amp;amp; a_{12} &amp;amp; a_{13} \\ a_{21} &amp;amp; a_{22} &amp;amp; a_{23} \\ 0 &amp;amp; 0 &amp;amp; 1 \end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(assuming you use a column vector convention). Here, the upper-left 2&amp;times;2 submatrix is the linear part, and $(a_{13}, a_{23})$ is the translation vector of the affine transform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the lower row of the matrix has some values other than $[0, 0, 1]$, then it is in general a projective transform, not an affine one.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-04-30T22:00:59.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2380" PostTypeId="2" ParentId="2377" CreationDate="2016-04-30T22:55:42.313" Score="4" Body="&lt;p&gt;I've seen both, unfortunately. I'm not fond of rays per second as meaning exclusively primary rays and I'd suggest &quot;paths per second&quot; or better yet &quot;samples per second&quot; instead. &quot;Complete ray&quot; is not a common term: a ray is a (potentially unbounded) line segment and a sequence of rays is a path.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rays per second in your second sense of total ray casts is not well-specified for a path tracer: do shadow rays count, for instance? It's a useful metric for evaluating an acceleration structure or intersection testing framework (i.e. Embree or OptiX) but I'd avoid it for a renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, be aware that samples per second still isn't a great metric of actual performance since sample quality will vary wildly depending on implementation details. It's probably the best thing you can do starting out though, as the better solutions involve fairly complex variance estimates.&lt;/p&gt;&#xA;" OwnerUserId="3075" LastActivityDate="2016-04-30T22:55:42.313" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2381" PostTypeId="1" CreationDate="2016-05-01T03:48:18.253" Score="2" ViewCount="85" Body="&lt;p&gt;In a plane, we have a &lt;strong&gt;convex&lt;/strong&gt; polygon with n sides. What would be the maximum number of disconnected pieces / fragments if this polygon is clipped against a square?&lt;/p&gt;&#xA;" OwnerUserId="3271" LastEditorUserId="3304" LastEditDate="2016-05-06T21:11:45.187" LastActivityDate="2016-05-08T20:18:18.947" Title="Finding the maximum number of disconnected fragments" Tags="&lt;polygon&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2383" PostTypeId="1" AcceptedAnswerId="2385" CreationDate="2016-05-01T22:02:24.773" Score="9" ViewCount="18804" Body="&lt;p&gt;I have been studying computer graphics, from the book &lt;a href=&quot;http://rads.stackoverflow.com/amzn/click/1482229390&quot;&gt;Fundamentals of Computer Graphic&lt;/a&gt; (but the third edition), and I lastly read about projections. Though, I didn't exactly understand what's the difference between orthographic and perspective projection? Why do we need both of them, where are they used? I also would like to learn what is &lt;em&gt;perspective transform&lt;/em&gt; that is applied before orthographic projection in perspective projection. Lastly, why do we need the viewport transformation? I mean we use view transformation if the camera/viewer is not looking at $-z$-direction, but what about the viewport?&lt;/p&gt;&#xA;" OwnerUserId="3277" LastActivityDate="2016-05-03T15:32:59.583" Title="What's the difference between orthographic and perspective projection?" Tags="&lt;3d&gt;&lt;projections&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2385" PostTypeId="2" ParentId="2383" CreationDate="2016-05-02T10:18:12.757" Score="8" Body="&lt;p&gt;Orthographic projections are parallel projections. Each line that is originally parallel will be parallel after this transformation. The orthographic projection can be represented by a affine transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In contrast a perspective projection is not a parallel projection and originally parallel lines will no longer be parallel after this operation. Thus perspective projection can not be done by a affine transform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why would you need orthographic projections? It is useful for several artistic and technical reasons. Orthographic projections are used in CAD drawings and other technical documentations. One of the primary reasons is to verify that your part actually fits in the space that has been reserved for it on a floor plan for example. Orthographic projections are often chosen so that the dimensions are easy to measure. In many cases this is just a convenient way to represent a problem in a different basis so that coordinates are easier to figure out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5zqm3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5zqm3.png&quot; alt=&quot;ortho&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: A number of useful orthographic projections for same object (and projection rule). The last on on the right is a special case called isometric having the property that cardinal axe directions are all in same scale.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A perspective projection is needed to be able to do 2 and 3 point perspectives, which is how we experience the world. A specific perspective projection can be decomposed as being a combination of a orthographic projection and a perspective divide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/urTYN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/urTYN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: 2 point perspective note how the lines in prespective direction no longer are parallel&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Viewport transformation allows you to pan/rotate/scale the resulting projection. Maybe because you want a off center projection like in cameras with film offset, or you have a anisotropic medium for example. It can also be convenient for the end user to zoom into image without changing the perspective in the process.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-05-03T15:32:59.583" LastActivityDate="2016-05-03T15:32:59.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2386" PostTypeId="1" AcceptedAnswerId="2387" CreationDate="2016-05-02T19:56:03.910" Score="2" ViewCount="972" Body="&lt;p&gt;I have been studying computer graphics, from the book &lt;a href=&quot;http://rads.stackoverflow.com/amzn/click/1482229390&quot; rel=&quot;nofollow&quot;&gt;Fundamentals of Computer Graphic&lt;/a&gt; (but the third edition), and I lastly read about texture mapping and shadow maps. Though, I didn't exactly understand how they function. I know there is also another type of texture map called projective texture map which allows to cast hard shadows, but how they function? On the other hand, how are soft shadows cast? And what's exactly the difference between hard and soft shadows?&lt;/p&gt;&#xA;" OwnerUserId="3277" LastActivityDate="2016-05-03T03:27:35.803" Title="How are hard and soft shadows cast?" Tags="&lt;texture&gt;&lt;3d&gt;&lt;shadow&gt;&lt;shadow-mapping&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2387" PostTypeId="2" ParentId="2386" CreationDate="2016-05-02T20:16:32.843" Score="3" Body="&lt;p&gt;Hard shadows are simple that only needs a point light. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How it's done is by rendering the scene from the point of view of the light and only keep only the depth information. This is the shadow map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then when doing the actual rendering you calculate the point on the triangle in world space and find where it would be on the shadow map. Then you sample the depth from the shadowmap at that point and compare it to the distance to the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Soft shadows are harder. They require figuring out how close you are to the edge of what would be a hard shadow and adjusting the light value based on that. There are several techniques for that. One of which is simply sampling multiple times. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-05-02T20:16:32.843" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2388" PostTypeId="2" ParentId="2386" CreationDate="2016-05-03T03:27:35.803" Score="1" Body="&lt;p&gt;@ratchetfreak's answer describes shadow mapping, however, there's another not so difficult to implement way of drawing hard shadows. The &lt;a href=&quot;https://en.wikipedia.org/wiki/Shadow_volume&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;shadow volume&lt;/em&gt;&lt;/a&gt; technique uses extruded geometry plus some &lt;a href=&quot;https://computergraphics.stackexchange.com/q/12/54&quot;&gt;stencil buffer&lt;/a&gt; tricks to simulate the area occluded by an object. The idea behind it is to generate a volume from the light source's perspective and then render it as you would render other geometry. The resulting shadow geometry will be as accurate as your graphics hardware is capable of rendering it, so the shadows will be very clear cut. There's no simple way of producing soft shadow edges with this technique though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sRO84.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sRO84.png&quot; alt=&quot;shadow volume&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="54" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-05-03T03:27:35.803" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2389" PostTypeId="2" ParentId="2357" CreationDate="2016-05-03T13:17:41.510" Score="3" Body="&lt;p&gt;This has to do with gamma correction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If one pixel has red component with value of 1 (where 255 is max), the next pixel has value for red that is 2, there no guarantee that exactly twice as much photons are exiting from the second pixel. Displays have different curves that predict what's the expected brightness. It also has to do with how our eyes work: they're more sensitive for darker shades than brighter shades.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To read more about these phenomena:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://gamedevdaily.io/the-srgb-learning-curve-773b7f68cf7a#.di88vr58t&quot; rel=&quot;nofollow&quot;&gt;https://gamedevdaily.io/the-srgb-learning-curve-773b7f68cf7a#.di88vr58t&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://marcinignac.com/blog/pragmatic-pbr-setup-and-gamma/&quot; rel=&quot;nofollow&quot;&gt;http://marcinignac.com/blog/pragmatic-pbr-setup-and-gamma/&lt;/a&gt; (gamma section)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://colour-science.org/posts/the-importance-of-terminology-and-srgb-uncertainty/&quot; rel=&quot;nofollow&quot;&gt;http://colour-science.org/posts/the-importance-of-terminology-and-srgb-uncertainty/&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.essentialmath.com/GDC2015/VanVerth_Jim_DoingMathwRGB.pdf&quot; rel=&quot;nofollow&quot;&gt;http://www.essentialmath.com/GDC2015/VanVerth_Jim_DoingMathwRGB.pdf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The three images are used as low value, medium grey and bright examples. Indeed, the lowest brightness is used so you are able do see the difference between the black background and &quot;barely lit&quot; object, and the other two images are just used to display other important values for the set gamma curve.&lt;/p&gt;&#xA;" OwnerUserId="2838" LastActivityDate="2016-05-03T13:17:41.510" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2391" PostTypeId="1" CreationDate="2016-05-04T21:54:04.517" Score="15" ViewCount="2247" Body="&lt;p&gt;What is the best currently known and ideally also production-verified approach for sampling environment maps (EM) in a MIS-based uni-directional path tracer and similar types of renderers? I would prefer solutions which are reasonably complicated while reasonably functional to those which provide perfect sampling at cost of super complicated and hard-to-understand implementation.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;What I know so far&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;There are some easy ways of sampling EMs. One can sample the needed hemisphere in a cosine-weighted manner,&#xA;   which ignores both the BSDF and the EM function shapes. As a result,&#xA;   it doesn't work for dynamic EMs:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TBYYn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TBYYn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To improve&#xA;   the sampling to a usable level, one can sample the luminance of the EM&#xA;   over the whole sphere. It is relatively easily implemented and the&#xA;   results are quite good. However, the sampling strategy is still&#xA;   ignoring the hemispherical visibility information and the cosine&#xA;   factor (and also the BSDF), resulting in high noise on the surfaces&#xA;   which are not directly lit by high-intensity areas of the EM:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1DOSr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1DOSr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Papers&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I have found a few papers on the topic, but have not read them yet. Is any of these worth reading and implementing in a forward uni-directional path tracer, or is there something even better?&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://cseweb.ucsd.edu/~ravir/papers/structured/&quot; rel=&quot;noreferrer&quot;&gt;Structured Importance Sampling of Environment Maps&lt;/a&gt; (2003) by&#xA;Agarwal et al.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://home.eps.hw.ac.uk/~ks400/research.html#SteerableImportance&quot; rel=&quot;noreferrer&quot;&gt;Steerable Importance Sampling&lt;/a&gt; (2007) by&#xA;Kartic Subr and Jim Arvo. They claim to present “...an algorithm for&#xA;efficient stratified importance sampling of environment maps that&#xA;generates samples in the positive hemi-sphere defined by local&#xA;orientation of arbitrary surfaces while accounting for cosine&#xA;weighting. “ The paper “Importance Sampling Spherical Harmonics”&#xA;comments on it: ”They create a triangulated representation of the&#xA;environment map and store the illumination premultiplied by each of&#xA;the first nine spherical harmonic basis functions at every vertex.&#xA;This forms a steerable basis where the clamped-cosine can be&#xA;efficiently rotated to any orientation.”&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://fileadmin.cs.lth.se/graphics/research/papers/2008/pps/&quot; rel=&quot;noreferrer&quot;&gt;Practical Product Importance Sampling for Direct Illumination&lt;/a&gt; (2008) by&#xA;Petrik Clarberg and Tomas Akenine-Möller. An algorithm for sampling&#xA;the product of environment map lighting and surface reflectance. Uses&#xA;wavelet-based importance sampling.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.cs.dartmouth.edu/~wjarosz/publications/jarosz09importance.html&quot; rel=&quot;noreferrer&quot;&gt;Importance Sampling Spherical Harmonics&lt;/a&gt; (2009)&#xA;by Jarosz, Carr, and Jensenn. The abstract says: “...we present the&#xA;first practical method for importance sampling functions represented&#xA;as spherical harmonics (SH)...”&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;http://www.ncbi.nlm.nih.gov/pubmed/26584494&quot; rel=&quot;noreferrer&quot;&gt;Tone-Mapped Mean-shift Based Environment Map Sampling&lt;/a&gt; (2015) by Feng&#xA;et al. This is pretty new and I have found neither a reference to it&#xA;nor the paper itself.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-05-14T11:03:35.480" LastActivityDate="2016-05-21T19:29:57.323" Title="Importance Sampling of Environment Maps" Tags="&lt;rendering&gt;&lt;sampling&gt;&lt;pathtracing&gt;&lt;importance-sampling&gt;&lt;ibl&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2392" PostTypeId="2" ParentId="1473" CreationDate="2016-05-04T22:38:30.980" Score="1" Body="&lt;p&gt;Ship your application with a benchmarking sequence testing the actual platform. (Possible answer for many questions I guess...)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect the performance is highly dependent on &lt;strong&gt;how&lt;/strong&gt; you use the hardware. Since the hardware is unlikely to somehow instrument your application backwards, telling you what to do, I´d go with whatever looks good in your design.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&quot;...command queues can be executed concurrently by the device...&quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Keyword is CAN. I see no reason why any vendor would screw this up. In the end it is the platform provider (Intel/AMD/Nvidia) who is responsible of making you a good enough driver for you not to consider switching vendor. If they do have a &quot;know issue&quot; with this functionality (which by the way has no functional meaning, only performance) then they &lt;strong&gt;should&lt;/strong&gt; also solve it using what they know. I mean for crying out loud, the fallback is something they have already implemented; synchrounous execution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hardware is enough voodoo as it is for us developers.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2016-05-04T22:38:30.980" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2393" PostTypeId="1" AcceptedAnswerId="2401" CreationDate="2016-05-05T06:44:00.977" Score="5" ViewCount="548" Body="&lt;p&gt;Tessellation has been touted as one of the major features in newer graphics APIs like DirecX 11, and it is shown as a standalone stage in a modern graphics pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compared to the amount of hardware and software attention given to this feature, it doesn't seem to be heavily used in real-time graphics. So this doesn't seem to be a feature that arose out of graphical demand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then why did tessellation become such a prominent feature? To cater to the demands of non-realtime rendering? As a side-effect of the increasing shift in GPU architecture as generalized parallel processors in heterogeneous computing? Or is this a forward-thinking feature that will be used in graphics as tessellation-capable GPUs become increasingly common?&lt;/p&gt;&#xA;" OwnerUserId="88" LastActivityDate="2016-05-06T17:16:17.913" Title="Why did tessellation come to be a prominent feature?" Tags="&lt;gpu&gt;&lt;directx11&gt;&lt;tesselation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2394" PostTypeId="2" ParentId="2359" CreationDate="2016-05-05T06:44:32.243" Score="1" Body="&lt;p&gt;Rather than making one spatial subdivision structure do double duty in representing both the voxels and the triangles, I would suggest creating a separate BVH for the mesh. You can find many articles and papers about BVH-building algorithms on the web. It's likely to be a more efficiently queryable representation of the mesh than the octree would be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given the BVH, it's easy to determine whether a given voxel might intersect the mesh by starting at the BVH root and traversing to child nodes that intersect the voxel box. Depending on the quality of the BVH, i.e. how tightly it fits the mesh, many voxels (or even higher-level octree nodes) may be able to be eliminated with only a few checks. For voxels that do intersect the mesh surface, the BVH traversal will reach down to the leaves, where you can accumulate the triangles into a list for clipping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the BVH is built in the mesh's local space, the mesh can easily be moved or transformed without needing to update the octree. (If translation is the only transform needed, then the BVH nodes will always be axis-aligned relative to the voxels, which simplifies the intersection test to an AABB overlap test; if more general transforms are needed, you'd have to use a more general OBB vs OBB test.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, note that a BVH doesn't lend itself that well to determining whether a things are inside versus outside a watertight mesh. If that's important to you (it wasn't clear to me whether it is), then you might want to look into using a BSP tree instead of a BVH. A BSP tree can be used for intersection testing similarly to a BVH, but additionally can represent the exact boundary of the mesh so that it can be used to determine whether a point (or voxel) is inside or outside. This property of BSP trees is widely used for collision detection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An alternate approach to determining inside/outsideness is to use raycasting and count the number of intersections with the mesh (even = outside, odd = inside). The raycasting can be accelerated by the BVH as well.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-05T06:44:32.243" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2395" PostTypeId="2" ParentId="2393" CreationDate="2016-05-05T14:49:18.677" Score="11" Body="&lt;p&gt;The main purpose of tesselation is to increase the resolution of the mesh, while only transferring a small amount of triangle data around. In addition, tessellation allows you to dynamically change the LOD of the mesh, so you can &lt;a href=&quot;http://www.g-truc.net/post-0662.html&quot;&gt;optimize your shader calls.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, we can pass the GPU, say, 3000 triangles, and have it tesselate it to 300000 triangles. We are essentially trading storage space/bandwidth for compute power. Since GPUs have lots and lots of compute, and memory is limited/slow, this is a pretty good tradeoff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for &quot;not being heavily used in real-time graphics&quot;. I somewhat disagree. Many AAA games have been using tessellation for a long time. That said, tessellation is &lt;em&gt;hard&lt;/em&gt; to get right. Done wrong, tesselation can lead to lots of problems, such as &lt;a href=&quot;https://developer.nvidia.com/content/dynamic-hardware-tessellation-basics&quot;&gt;cracking&lt;/a&gt;, or over tessellating to sub-pixel triangles, which &lt;a href=&quot;http://www.g-truc.net/post-0662.html&quot;&gt;destroys your fill rate&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Combined, these problems make it difficult to implement good and fast tessellation for your everyday person. Thus, most of the uses of tessellation you see nowadays are in AA or AAA games, game engines, and offline rendering tools.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, there is active research going on that is trying to better utilize the tessellation hardware, and make it easier to use. For example: &lt;a href=&quot;http://www.graphics.stanford.edu/~niessner/brainerd2016efficient.html&quot;&gt;Efficient GPU Rendering of Subdivision Surfaces using Adaptive Quadtrees&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, tessellation is a great feature, but is difficult to get right&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-05-05T14:49:18.677" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2397" PostTypeId="2" ParentId="1862" CreationDate="2016-05-06T01:23:24.967" Score="0" Body="&lt;p&gt;While the other answers given are correct I'm not sure they entirely answer your question. In order to not get black bars you have 2 options if the destination is not the same shape (or aspect ratio) as the source:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Fill the destination leaving some pixels from the source out of the destination.&lt;/strong&gt; In your example, the source is 1024x768 and the destination is 1920x1080. If you scale the original image up so the result is 1920x1440, you can then crop the top and/or bottom off to make it 1920x1080.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Stretch the destination image to fit.&lt;/strong&gt; So you'd scale vertically by 1080/768 = 1.40625, and scale horizontally by 1920/1024 = 1.875. This is almost never what you want, and looks terrible in most cases. (This is what makes people look much wider than they should, and turns circles into ovals and rotations into shears.)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;There's another option, but it doesn't fit your criteria - scale uniformly, but only until 1 dimension is as big as the destination. In this case you would scale both horizontally and vertically by 1.40625 to get a result of 1440x1080. This is usually referred to as &quot;scale to fit&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For any of these options you can use whichever scaling algorithm meets your needs.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-05-06T01:23:24.967" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2398" PostTypeId="1" CreationDate="2016-05-06T10:21:44.147" Score="2" ViewCount="76" Body="&lt;p&gt;I implemented &lt;a href=&quot;http://math.ewha.ac.kr/~jylee/SciComp/dip-crane/chapter8/list8_4.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;this algorithm&lt;/a&gt; to fit given image to specified quadrilateral but the output is blank.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I implemented it in C# as follows&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-csharp prettyprint-override&quot;&gt;&lt;code&gt;Bitmap inputImage = new Bitmap(&quot;D:\\Image\\A2.jpg&quot;);&#xA;Bitmap outputBitmap = new Bitmap(inputImage.Width, inputImage.Height);&#xA;double a11, a21, a31, a41;&#xA;double a12, a22, a32, a42;&#xA;double first, second;&#xA;double denom;&#xA;int u, v;&#xA;double floatu, floatv;&#xA;int i, j;&#xA;ulong sourcebase; /// this has been replaced by u,v i think its same&#xA;double x, y;&#xA;double A, B, C;&#xA;int x0 = 50, y0 = 100, x1 = 65, y1 = 110, x2 = 55, y2 = 120, x3 = 450, y3 = 110;// fix value quadrilaeral for checking purpose.&#xA;a11 = x0 - x1 - x3 + x2;&#xA;a21 = x1 - x0;&#xA;a31 = x3 - x0;&#xA;a41 = x0;&#xA;a12 = y0 - y1 - y3 + y2;&#xA;a22 = y1 - y0;&#xA;a32 = y3 - y0;&#xA;a42 = y0;&#xA;Console.WriteLine(&quot;inside of here&quot;);&#xA;A = a11 * a22 - a21 * a12;&#xA;if (A == 0)&#xA;    A = 0.00001;&#xA;int rows = inputImage.Height, cols = inputImage.Width;&#xA;for (i = 0; i &amp;lt; rows; i++)&#xA;{&#xA;    y = Convert.ToDouble(i) / Convert.ToDouble(rows);&#xA;    for (j = 0; j &amp;lt; cols; j++)&#xA;    {&#xA;        x = Convert.ToDouble(j) / Convert.ToDouble(cols);&#xA;        B = a12 * x - a11 * y + a11 * a42 - a41 * a12 + a31 * a22 - a21 * a32;&#xA;        C = a32 * x - a31 * y + a31 * a42 - a41 * a32;&#xA;        first = B * B;&#xA;        second = 4.0 * A * C;&#xA;        if (first &amp;lt; second)&#xA;            floatu = B / (-2.0 * A);&#xA;        else&#xA;            floatu = (-1.0 * B + Math.Sqrt(first - second)) / (2.0 * A);&#xA;        if((floatu &amp;lt; 0.0) | (floatu &amp;gt; 1.0))&#xA;        {&#xA;            if (first &amp;lt; second)&#xA;                floatu = B / -2.0 * A;&#xA;            else&#xA;                floatu = (1.0 * B - Math.Sqrt(first - second)) / (2.0 * A);&#xA;        }&#xA;        denom = (a11 * floatu + a31);&#xA;        if (denom == 0.0)&#xA;            denom = 0.000001;&#xA;        floatv = (x - a21 * floatu - a41) / denom;&#xA;        u = Convert.ToInt32(floatu * cols + 0.5);&#xA;        v = Convert.ToInt32(floatv * rows + 0.5);&#xA;        Color pixelColor;&#xA;        if ((u &amp;gt;= cols) | (u &amp;lt; 0) | (v &amp;gt;= rows) | (v &amp;lt; 0))&#xA;        {&#xA;            // Console.WriteLine(&quot;escapaed&quot;);&#xA;            pixelColor = Color.Black;&#xA;            continue;&#xA;        }&#xA;        else { /// program ne&#xA;            Console.WriteLine(&quot;here&quot;);&#xA;            //sourcebase = ((ulong)u * (ulong)cols + (ulong)v);&#xA;            pixelColor = inputImage.GetPixel((int)u, (int)v);&#xA;            outputBitmap.SetPixel(i, j, pixelColor);// =pixelColor;&#xA;            // pictureBox1.Image = outputBitmap;&#xA;        }&#xA;    }&#xA;    //  Console.WriteLine(i);&#xA;}&#xA;pictureBox1.Image = outputBitmap;&#xA;outputBitmap.Save(&quot;output.jpg&quot;);&#xA;Console.WriteLine(&quot;Out Of here&quot;);&#xA;pictureBox1.Invalidate();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2383" LastEditorUserId="231" LastEditDate="2018-04-15T10:00:33.150" LastActivityDate="2018-04-15T10:00:33.150" Title="Bilinear Transformation not working" Tags="&lt;image-processing&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2399" PostTypeId="1" AcceptedAnswerId="2404" CreationDate="2016-05-06T15:05:48.190" Score="2" ViewCount="2204" Body="&lt;p&gt;I am using matrix for performing 3D rotations. I know that in 3D space the matrix product order is important - changing the order of the matrices can effect the rotate result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I am interesting about how can I create a rotate matrix that perform rotation (clockwise) around some vector, say $(1, 0, 1)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought that $R_{(1,0,1)}(\theta) = R_X(\theta) \cdot R_Z(\theta)$ but it seems wrong because if I tries to rotate the $(1, 0, 1)$ with $45^{\circ}$ it moves out from $(1, 0, 1)$ but it should stay in place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how can I build such a rotation matrix as product of 3D trasformation matrices?&lt;/p&gt;&#xA;" OwnerUserId="3305" LastActivityDate="2016-05-06T21:01:50.843" Title="3D rotation matrix around vector" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2401" PostTypeId="2" ParentId="2393" CreationDate="2016-05-06T17:16:17.913" Score="0" Body="&lt;p&gt;History: ATI Introduced PN triangles (a basic approach to tessellation) in its first generation to include programmable HW - so it's been around about as long as programmable HW shaders. It was deprecated in ATI's next generation, but tessellation was revived in the HW that became the basis of the Xbox 360 (a few ATI demos showed it off on PCs). Microsoft then incorporated the feature into DX11 (although not compatible with ATI/AMD's existing HW), making tessellation support a de-facto requirement for all GPU makers.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-05-06T17:16:17.913" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2402" PostTypeId="1" CreationDate="2016-05-06T17:20:52.417" Score="1" ViewCount="48" Body="&lt;p&gt;I am trying to find an algorithm as mentioned in the subject. It is as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; int orientation(glm::i16vec2 &amp;amp;p1,&#xA;                 glm::i16vec2 &amp;amp;p2,&#xA;                 glm::i16vec2 &amp;amp;p3)&#xA; {&#xA;   return (((p3.x - p1.x) * (p2.y - p1.y)) - ((p2.x - p1.x) * (p3.y - p1.y)));&#xA; }&#xA;&#xA;&#xA; bool onSegment(const glm::i16vec2 &amp;amp;pi,&#xA;                const glm::i16vec2 &amp;amp;pj,&#xA;                const glm::i16vec2 &amp;amp;pk)&#xA; {&#xA;   if((std::min(pi.x,pj.x) &amp;lt;= pk.x &amp;amp;&amp;amp; pk.x &amp;lt;= std::max(pi.x,pj.x)) &amp;amp;&amp;amp;&#xA;      (std::min(pi.y,pj.y) &amp;lt;= pk.y &amp;amp;&amp;amp; pk.y &amp;lt;= std::max(pi.y,pj.y)))&#xA;    return true;&#xA;   else&#xA;    return false;&#xA; }&#xA;&#xA; int main()&#xA; {&#xA;   glm::i16vec2 hs(5,2);  // p1&#xA;   glm::i16vec2 he(5,3); // p2&#xA;&#xA;&#xA;   glm::i16vec2 cs(5,1);   // p3&#xA;   glm::i16vec2 ce(5,3); // p4&#xA;&#xA;   int d1 = orientation(cs,ce,hs);&#xA;   int d2 = orientation(cs,ce,he);&#xA;   int d3 = orientation(hs,he,cs);&#xA;   int d4 = orientation(hs,he,ce);&#xA;&#xA;   if((d1 == 0 &amp;amp;&amp;amp; d2 == 0 &amp;amp;&amp;amp; d3 == 0 &amp;amp;&amp;amp; d4 == 0) &amp;amp;&amp;amp;&#xA;        (onSegment(cs,ce,hs) &amp;amp;&amp;amp; onSegment(cs,ce,he)))&#xA;   {&#xA;    std::cout &amp;lt;&amp;lt; &quot;HPs is entirely inside CPs&quot; &amp;lt;&amp;lt; std::endl;&#xA;   }&#xA;&#xA;   return 0;&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So far it working fine. Is there any leak within procedure when it may not work as intended in some situations ? Would like  to know about those scenarios ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks &lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="5778" LastEditDate="2018-07-17T06:11:36.593" LastActivityDate="2018-07-17T06:11:36.593" Title="Check if one line segments is entirely on the other line segment" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2403" PostTypeId="2" ParentId="2399" CreationDate="2016-05-06T20:14:27.637" Score="1" Body="&lt;p&gt;Build a matrix with one of the vectors a=(1,0,1) now you need another vector to define the matrix vector say b=(1, 0, 0) take the cross product of a  and b lets call this c. Then take the cross product of a and c for a rectified b'. Normalize a, b' and c.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your matrix T is now [a b' c] plus any affine part you deem neccesery.  Then do T&lt;sup&gt;-1&lt;/sup&gt; * Rx(Angle) * T. where Rx(a) is a function that returns a rotation matrix around the x axis with a angle of a.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-05-06T20:14:27.637" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2404" PostTypeId="2" ParentId="2399" CreationDate="2016-05-06T21:01:50.843" Score="4" Body="&lt;p&gt;There is a direct formula for the rotation matrix for an arbitrary axis and angle. Given a unit vector $a = (a_x, a_y, a_z)$ and angle $\theta$, the matrix can be constructed as follows (derivation from &lt;a href=&quot;https://en.wikipedia.org/wiki/Rodrigues&amp;#39;_rotation_formula#Matrix_notation&quot; rel=&quot;noreferrer&quot;&gt;Wikipedia&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First build a matrix $C$ from the components of $a$ according to the following formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ C =&#xA;\begin{bmatrix}&#xA;  0 &amp;amp; -a_z &amp;amp; a_y \\&#xA;  a_z &amp;amp; 0 &amp;amp; -a_x \\&#xA;  -a_y &amp;amp; a_x &amp;amp; 0&#xA;\end{bmatrix} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can construct the rotation matrix from $C$ as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ R_a(\theta) = I + C \sin \theta + C^2 (1 - \cos \theta) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $I$ is the 3&amp;times;3 identity matrix. This assumes you're using a column-vector convention; if you're using row vectors instead, transpose $C$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, this formula has a neat geometric interpretation. The matrix $C$ has the effect of calculating cross products with $a$. In other words, for any vector $v$, $Cv = a \times v$. If you imagine rotating some vector $v$ about $a$, the tip of $v$ traces out a circle perpendicular to $a$; $Cv$ is a vector tangent to that circle, and $C^2 v$ (which equals $a \times (a \times v)$) is a vector normal to the circle. So with those two vectors, you have a basis for the plane of the circle; then you can apply a variation of the usual sine/cosine formula for points on a circle.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-06T21:01:50.843" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2405" PostTypeId="1" AcceptedAnswerId="2423" CreationDate="2016-05-06T21:46:39.237" Score="10" ViewCount="1330" Body="&lt;p&gt;So I been thinking about this for a while and tried to google for an answer but without any success.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all your textures are 8bit LDR images, like JPEGs, couldn't that potentially cause conflicts with exposure control/tone mapping when rendering. That is if you adjust the rendering exposure of your image that should expose detail in the textures that aren't really there, since they been clamped out by the low dynamic range. So wouldn't it make sense to also have the textures as HDR images, saved as .exr, in linear colour space with 16bit half-float to get a good colour representation (32bit &quot;full&quot; float might be overkill?). To have more detailed and correct colour values might also, I figure, have an effect on GI and how colour bleed is calculated?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or is it simply not necessary since the end result of the rendering we want is probably going to be similar to the exposure level of the texture when it was photographed any way? And since camera mostly shoot in 12-14bit you would have to take multiple exposures of the texture and do all that extra work to piece them all together to one HDRI. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; &lt;em&gt;To clarify, I'm mostly interested in this from a photo realistic rendering point of view, with ray trace renderers (like mental ray, V-Ray, Arnold, etc.) with full light simulations and global illumination, rather then for real-time game engines.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="2736" LastEditorUserId="2736" LastEditDate="2016-05-10T07:32:26.140" LastActivityDate="2016-05-10T18:27:56.747" Title="16bit half-float linear HDR images as (diffuse/albedo) textures?" Tags="&lt;texture&gt;&lt;physically-based&gt;&lt;pbr&gt;&lt;diffuse&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2406" PostTypeId="2" ParentId="2405" CreationDate="2016-05-07T06:17:59.660" Score="8" Body="&lt;p&gt;Yes, it's possible in some extreme cases for HDR lighting and tonemapping to expose banding issues in color textures. In those cases, having a higher bit depth for the textures could be useful. However, in my experience the majority of materials and ordinary lighting situations don't exhibit this problem, and most textures in a typical game are fine in 8-bit (or even less&amp;mdash;games often use BC1 compression, which reduces them to 5-6-5-bit).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;People use HDR render targets because a single scene can contain vastly different magnitudes of brightness, such as a dark room in which you can see through a window to a sunlit exterior 10&amp;ndash;100 times brighter than the room. However, color textures don't have such a wide range of magnitudes. They represent reflectances, which are inherently in the [0, 1] range, and in practice few everyday materials are lower than about 2&amp;ndash;5% reflectance. So an 8-bit image (with gamma encoding) can usually represent diffuse and specular colors with enough precision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's true that the combination of a quite dark texture with very bright lighting or an extremely overexposed camera setting can show banding in the final frame, but that would be a more unusual case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A case where you probably &lt;em&gt;would&lt;/em&gt; want an HDR texture is emissive materials, especially for neon signs and similar light sources. The texture would appear with its value amped up to appear as a bright light source in game, so in that case an 8-bit image could easily show banding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, it can still be useful to work at higher precision (e.g. 16-bit precision) if possible when capturing and creating textures, simply because it gives you more headroom to process the image without causing precision problems. For instance, if you need to adjust levels or color balance, you lose a little precision; that can introduce banding (especially if you do it multiple times) when starting from an 8-bit source image. A 16-bit source would be more resilient to such problems. However, the final texture used in the game would still probably be compressed to 8-bit.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-07T06:17:59.660" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2407" PostTypeId="2" ParentId="2381" CreationDate="2016-05-07T06:40:03.413" Score="3" Body="&lt;p&gt;A convex polygon has the property:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;A line drawn through a convex polygon will intersect the polygon exactly twice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From this follows that any line trough splits the convex polygon in 2 pieces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uyM6r.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uyM6r.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: convex polygon split by a line.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Using this, and assuming the inner piece is discarded we can craw the conclusion that there are five cases:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;When the lines of the square do not exit the polygon. You now have a piece with a hole or the entire polygon is contained and theres no hole and no piece.&lt;/li&gt;&#xA;&lt;li&gt;When the lines exit 2 times you have one fragment*&lt;/li&gt;&#xA;&lt;li&gt;when the lines exit 4 times you have two fragments*&lt;/li&gt;&#xA;&lt;li&gt;when the exits are 6 times you have three fragments* &lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;when the exits are 8 times you have four fragments *&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OwHAq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OwHAq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: the five cases, clipping rectangle and remaining shards in black. Even a squares has same cases if the polygons vary, just easier to draw this way.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The last case is the maximum so answer is &lt;strong&gt;four&lt;/strong&gt; or five if you count the clipped part as one piece. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;* Since we haven't tackled the cases very rigorously we know that this is the highest possible answer, there could be less for each case. There shouldn't be but I so far haven't given evidence for that. But thats okay it wasn't asked.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-05-08T20:18:18.947" LastActivityDate="2016-05-08T20:18:18.947" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2409" PostTypeId="1" AcceptedAnswerId="2439" CreationDate="2016-05-07T10:24:23.030" Score="3" ViewCount="138" Body="&lt;p&gt;I have a Optix Raycasting renderer which loads and renders VTK files.&#xA;For a single static model this works fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But now my dataset consists of multiple timesteps which I want to display in a animated fashion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each couple of frames or seconds the displayed model has to be switched out with the next one.&#xA;If possible I want to refrain from rebuilding the acceleration structure each time this happens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question: Can I just load all models at once, place them in the global acceleration structure and then just switch all off except the one currently displayed.&#xA;My hope is that this would be more efficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit 1:&#xA;I have now build a variant in which I create &lt;em&gt;optix::Acceleration&lt;/em&gt; and &lt;em&gt;optix::Group&lt;/em&gt; for each of the timesteps separate and each time the active timestep changes I just &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;_context[&quot;top_object&quot;]-&amp;gt;set(mesh_group[timestep]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But each this call takes nearly half a second. I think optix does quite some work in the background when I switch this object out.&#xA;This delay is not acceptable for me as it makes the playback of my &quot;animation&quot; stutter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Has anyone a idea how to do this more efficient?&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="273" LastEditDate="2016-05-09T11:45:01.930" LastActivityDate="2016-05-13T11:34:19.540" Title="Optix: Rendering time-variant data" Tags="&lt;vtk&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2410" PostTypeId="1" CreationDate="2016-05-07T12:46:39.143" Score="3" ViewCount="241" Body="&lt;p&gt;Specify individually the translation and scaling matrices required to transform a 2D&#xA;window of [Xmin=-234, Ymin=156] and [Xmax=66, Ymax=456] to a display viewport&#xA;of [Umin=45, Vmin=35] and [Umax=245, Vmax=185].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Ignore the question above since I solved the matrix, the information is just relevant for the question I'm stuck on&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was asked to compute the view-port positions (U1,V1) and (U2,V2) for two points A (-100,300)&#xA;and B (30,-40) in a 2D window and determine if these two points are inside the view-port.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Based on the transformation Matrix I found (U1,V1) to be (403/3, 407) and (U2,v2) to be (221, -103). It turns out that both these points are outside our view-port but part of the line between them is inside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I'm confused about this part below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apply a 2D clipping method to the line segment between the two points A and B as&#xA;given in above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My Attempt&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;delta x = 221-(403/3) = 260/3&lt;/p&gt;&#xA;&#xA;&lt;p&gt;delta y = -103 - 406 = -510&lt;/p&gt;&#xA;&#xA;&lt;p&gt;m = delta y / delta x = -5.88&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I started with U1,V1 since it is above our viewport:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Y = 185&lt;/p&gt;&#xA;&#xA;&lt;p&gt;X = 403/3 + (185-407)*(delta x/ delta y)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;X = 279.48&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Point 1 - (172, 185) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this correct? Since the point is now within the view-port. Do I then do the same for the second point?&lt;/p&gt;&#xA;" OwnerUserId="1971" LastActivityDate="2018-03-21T14:54:14.850" Title="Cohen-Sutherland Clipping" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2411" PostTypeId="1" AcceptedAnswerId="2413" CreationDate="2016-05-08T12:23:55.243" Score="8" ViewCount="476" Body="&lt;p&gt;This is how the rendering equation is written in the textbook&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L(p,\omega) = L_e(p,\omega) + \int f(p,\omega_i,\omega) \, L(p*,-\omega_i)\cos \theta \, d\omega_i$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which component of this equation handles the shadowing?&lt;/p&gt;&#xA;" OwnerUserId="2359" LastEditorUserId="48" LastEditDate="2016-05-08T18:31:34.063" LastActivityDate="2016-05-08T18:31:34.063" Title="How does the rendering equation incorporate shadowing" Tags="&lt;rendering&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2412" PostTypeId="1" AcceptedAnswerId="2414" CreationDate="2016-05-08T12:39:12.340" Score="2" ViewCount="4211" Body="&lt;p&gt;In perspective projection, group of parallel lines have the same vanishing point. I am interesting about the reverse calculation: Getting the group of parallel lines equations that their vanishing point specific point.&lt;/p&gt;&#xA;&lt;p&gt;Say I know that the camera is perspective camera at &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; and it's direction &lt;span class=&quot;math-container&quot;&gt;$(0,0,1)$&lt;/span&gt;, the view plane is &lt;span class=&quot;math-container&quot;&gt;$z = 1$&lt;/span&gt; and I am interesting about the lines in plane &lt;span class=&quot;math-container&quot;&gt;$y= y_0$&lt;/span&gt; that their vanishing point is &lt;span class=&quot;math-container&quot;&gt;$P = (p_x,p_y,p_z)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I have tried to calculate the projection point of some point &lt;span class=&quot;math-container&quot;&gt;$(x,y_0,z)$&lt;/span&gt; and get the equations:&lt;br /&gt;&#xA;(i) &lt;span class=&quot;math-container&quot;&gt;$p_x = x(\frac1z)$&lt;/span&gt;&lt;br /&gt;&#xA;(ii) &lt;span class=&quot;math-container&quot;&gt;$p_y = y_0(\frac1z)$&lt;/span&gt;&lt;br /&gt;&#xA;(iii) &lt;span class=&quot;math-container&quot;&gt;$p_z = 1$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;But it seems wrong because if the vanishing point is like &lt;span class=&quot;math-container&quot;&gt;$(x_0,0,*)$&lt;/span&gt; then form (ii) we will get &lt;span class=&quot;math-container&quot;&gt;$z\rightarrow \infty$&lt;/span&gt; but then (i) is wrong because &lt;span class=&quot;math-container&quot;&gt;$x(\frac1z)\rightarrow0$&lt;/span&gt; but it need to be equals to &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So how can I get the group of parallel lines have the same vanishing point in these conditions?&lt;/p&gt;&#xA;" OwnerUserId="3305" LastEditorUserId="3305" LastEditDate="2021-01-03T15:52:41.400" LastActivityDate="2021-01-03T15:52:41.400" Title="Calculate vanishing point" Tags="&lt;3d&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="2413" PostTypeId="2" ParentId="2411" CreationDate="2016-05-08T12:53:05.680" Score="11" Body="&lt;p&gt;Light that is blocked will mean that $L(p*, -w_i)$ under the integral is 0 plus how much light the blocking object itself reflects. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words the shadowing is embedded in the incoming light function.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2016-05-08T15:40:27.513" LastActivityDate="2016-05-08T15:40:27.513" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2414" PostTypeId="2" ParentId="2412" CreationDate="2016-05-08T13:42:24.037" Score="3" Body="&lt;p&gt;Here's a hint to get you started: Parallel lines include the line through the camera. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So really all you need is the direction from the camera to the vanishing point on the view plane. Then create lines parallel to that line.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-05-08T13:42:24.037" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2416" PostTypeId="1" CreationDate="2016-05-09T14:39:36.810" Score="2" ViewCount="287" Body="&lt;p&gt;Here's an odd intellectual puzzle.  Something I was daydreaming about on a train - but the maths are somewhat beyond me.  How would someone go about un-winding a spiral to produce a long flat image?  Like a rope on a spool, I'd want to uncoil the rope so that it lay long and flat.  The function would have to take in the image data (imageData) and the imageHeight (the height of the output strip - and hence also the thickness of the 'rope' on the spool).  Assumptions that could be made are that the input image is square, containing a circle whose top and bottom touch the top and bottom of the square - and left and right similarly.  The hub of circle would be in the absolute centre of the image.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(char*) unwindImage (char* imageData, int imageHeight)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Has anyone else puzzled over this?  And, if so, what solution did your come up with?&lt;/p&gt;&#xA;" OwnerUserId="3319" LastActivityDate="2016-05-12T14:40:56.900" Title="Unwinding an image on a spiral to make it long and flat" Tags="&lt;algorithm&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2417" PostTypeId="1" CreationDate="2016-05-09T16:45:13.933" Score="3" ViewCount="216" Body="&lt;p&gt;I'm searching a way to implement a linear gradient shader that behaves as the linear gradient in Photoshop (only the vertical case is necessary). It will be applied to 2D sprites.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I'm passing to the pixel shader these parameters:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;StartColor.&lt;/li&gt;&#xA;&lt;li&gt;EndColor.&lt;/li&gt;&#xA;&lt;li&gt;Offset: an offset applied to the gradient starting point.&lt;/li&gt;&#xA;&lt;li&gt;Length: the gradient length (the range inside where the colors will be&#xA;interpolated).&lt;/li&gt;&#xA;&lt;li&gt;isFixed: a boolean parameter that indicates if the&#xA;gradient must be influenced by the camera position or not.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Here a first attempt of the vertex shader and the pixel shader that I've implemented:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct VsInput&#xA;{&#xA;    float3 position : VES_POSITION;&#xA;    float2 uv       : VES_TEXCOORD0;&#xA;    float4 color    : VES_COLOR;&#xA;};&#xA;&#xA;struct VsOutput&#xA;{&#xA;    float4 position : HPOS;&#xA;    float2 uv       : TEXCOORD0;&#xA;    float4 color    : COLOR0;&#xA;    float4 outPos   : TEXCOORD1;&#xA;};&#xA;&#xA;VsOutput main(VsInput input)&#xA;{&#xA;    VsOutput vsOutput;&#xA;    vsOutput.position = MUL(float4(input.position, 1.0f), WorldViewProjection);&#xA;    vsOutput.uv = input.uv;&#xA;    vsOutput.color = input.color;&#xA;    vsOutput.outPos = vsOutput.position;&#xA;&#xA;    return vsOutput;&#xA;}&#xA;struct PsInput&#xA;{&#xA;    float4 Position : HPOS;&#xA;    float2 UV       : TEXCOORD0;&#xA;    float4 Color    : COLOR0;&#xA;    float4 outPos   : TEXCOORD1;&#xA;};&#xA;&#xA;float4 startColor;&#xA;float4 endColor;&#xA;float offset;&#xA;float len;&#xA;bool isFixed;&#xA;&#xA;float4 main(PsInput psInput) : COLOR&#xA;{&#xA;    psInput.outPos = psInput.outPos / psInput.outPos.w;&#xA;    float yScreenSize = 900.0f;&#xA;    float yPixelCoordinate = 0.0f;&#xA;    if (isFixed)&#xA;    {&#xA;        yPixelCoordinate = 0.5f * (1.0f - psInput.UV.y) * yScreenSize;&#xA;    }&#xA;    else&#xA;    {&#xA;        yPixelCoordinate = 0.5f * (psInput.outPos.y + 1.0f) * yScreenSize;&#xA;    }&#xA;&#xA;    float gradient = (yPixelCoordinate + offset) / len;&#xA;    gradient = clamp(gradient, 0.0f, 1.0f);&#xA;    return lerp(startColor, endColor, gradient);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When &lt;strong&gt;isFixed&lt;/strong&gt; is false I want the gradient influenced by the camera position. But my shader is wrong, since the starting point of the gradient is the bottom of the window instead of the bottom of the sprite.&#xA;The question is: how can I modify the shader in order to have the gradient starting from the bottom of the sprite? Maybe I need the size of the sprite in pixel? Or there are other convenient ways?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other question regards the &quot;fixed gradient&quot;: if I want the gradient not influenced by the camera position, what is the convenient way? It's possible to have these two behaviors in the same shader?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe the sentence &lt;em&gt;gradient influenced by the camera&lt;/em&gt;, it is not correct, so I'll try to be more clear with a few images (taken using the shaders above).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first image you can see a base sprite (in black) with an orange gradient applied to it. On top of the base you can see the player sprite; the camera is attached to this one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the second image the player has jumped and the camera follows him: the &lt;strong&gt;isFixed&lt;/strong&gt; attribute is false and, as you can see, the gradiend moves with the player and the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The third image shows the same situation of the second image, but the &lt;strong&gt;isFixed&lt;/strong&gt; attribute is true and, as you can see, the gradient don't moves with the player and the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IhsGb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IhsGb.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/PptVQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PptVQ.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/MzWOl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MzWOl.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="3323" LastActivityDate="2016-05-09T16:45:13.933" Title="Linear gradient shader ( Photoshop-like)" Tags="&lt;shader&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2419" PostTypeId="1" CreationDate="2016-05-09T21:54:21.997" Score="4" ViewCount="79" Body="&lt;p&gt;Once a 3D model is sliced against a plane and projected onto it, we get a contour curve at certain height. The contour curve I am generating in this process is made of several line segments in closed loop. Now I want to generate another contour curve with the following characteristics:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Each of the line segment of the newly generated inner contour curve must be parallel to the corresponding line segments at the outer contour curve.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Each of the parallel line segments on both outer and inner contour curve has an adjacent distance in between and defined by a constant value as shown in the attached picture (green mark) &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://imgur.com/YqRlHwL&quot; rel=&quot;nofollow noreferrer&quot;&gt;Image Link&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need some suggested algorithms to generate it . I hope that I have explained the issue properly. Please do let me know if it is not clear enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="127" LastEditDate="2016-05-17T15:35:18.937" LastActivityDate="2016-05-17T15:35:18.937" Title="generate multiple border contour" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2420" PostTypeId="2" ParentId="2405" CreationDate="2016-05-10T00:42:44.313" Score="5" Body="&lt;p&gt;I'd like to invite readers to read this article about &lt;a href=&quot;http://fabiensanglard.net/quake2/quake2_software_renderer.php&quot; rel=&quot;noreferrer&quot;&gt;Quake 2 engine rasterization technology explained in details&lt;/a&gt;, if they have the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If TLDR, please pay attention to this image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/j4i57.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j4i57.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What we see is the &lt;strong&gt;Albedo&lt;/strong&gt; channel, that's what you want to encode in 16 bits if I understand your question correctly.&lt;br&gt;&#xA;I'm not going to say &quot;&lt;em&gt;if it could be encoded in 256 colors for games in the past, why would we need 281474976710656 (that's 281 trillion) in new games?&lt;/em&gt;&quot; even if I want to but that sounds like pixar's grumpy guy from Up. More constructively, if you noted in this image, &lt;strong&gt;everything is at the same lighting level&lt;/strong&gt;. More particularly, the maximum intensity possible that preserves the desired saturation. (meaning in HSV space, V is maxed out)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The emphasis is key, we barely need any bits because albedo has no depth to encode anyway. The dynamic comes from the shading, it makes sense to work in &lt;code&gt;f32&lt;/code&gt; per components within shaders, and output to &lt;code&gt;f16&lt;/code&gt; render targets. But storing albedo textures in &lt;code&gt;f16&lt;/code&gt; that's not only overkill, that's a severe unjustified performance hog for our precious bandwidth.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2016-05-10T00:42:44.313" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2421" PostTypeId="1" CreationDate="2016-05-10T10:09:35.760" Score="3" ViewCount="110" Body="&lt;p&gt;I am reading &lt;a href=&quot;http://reality.cs.ucl.ac.uk/projects/two-shot-svbrdf/two-shot-svbrdf.pdf&quot; rel=&quot;nofollow&quot;&gt;two shot svbrdf capture&lt;/a&gt; . I want to understand the data fitting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I have my input image 3000x2000 pixels, and I divide it to create my source tiles of 192x192 pixels. The way I understand this paper is, each pixel of each tile will be the svbrdf. Now we have to find the BRDF parameters for each position with the L-M method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, we get svbrdf parameters for 192x192 pixels.&#xA;After the data fitting what did they do to obtain the normal map, specular albedo and diffuse albedo.&lt;/p&gt;&#xA;" OwnerUserId="3328" LastActivityDate="2019-07-15T17:01:15.100" Title="Data fitting SVBRDF with L-M" Tags="&lt;optimisation&gt;&lt;brdf&gt;&lt;specular&gt;&lt;diffuse&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2422" PostTypeId="1" CreationDate="2016-05-10T15:35:53.373" Score="6" ViewCount="489" Body="&lt;p&gt;I am working on a small rendering engine for a personal project and I am having issues with the texture mapping part of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems to work for some cases, but not for others. For example, when one of the vertices is behind the camera, the texture is stretched.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Seemingly&lt;/em&gt; &lt;strong&gt;Correct case&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/IJtuU.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IJtuU.png&quot; alt=&quot;Seemingly correct case&quot;&gt;&lt;/a&gt;&#xA;&lt;strong&gt;Incorrect case&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5M70C.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5M70C.png&quot; alt=&quot;Incorrect case&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am guessing that it has something to do with the texture mapping not being perspective-correct. I have tried various changes mainly involving the z-distance to the camera, but I could not find any quick fix to my code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my code for the perspective projection:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public double[] project(double x, double y, double z) {&#xA;    double tx = x - camera.x;&#xA;    double ty = z - camera.z;&#xA;    double tz = y - camera.y;&#xA;&#xA;    double cx = Math.cos(camera.pitch);&#xA;    double cy = Math.cos(camera.yaw);&#xA;    double cz = Math.cos(camera.roll);&#xA;&#xA;    double sx = Math.sin(camera.pitch);&#xA;    double sy = Math.sin(camera.yaw);&#xA;    double sz = Math.sin(camera.roll);&#xA;&#xA;    double dx = cy * (sz * ty + cz * tx) - sy * tz;&#xA;    double dy = sx * (cy * tz + sy * (sz * ty + cz * tx)) + cx * (cz * ty - sz * tx);&#xA;    double dz = cx * (cy * tz + sy * (sz * ty + cz * tx)) - sx * (cz * ty - sz * tx);&#xA;&#xA;    double ez = 1.0 / Math.tan(FOV / 2.0);&#xA;&#xA;    double bx = ez / dz * dx;&#xA;    double by = ez / dz * dy;&#xA;&#xA;    if (dz &amp;lt; 0.0) {&#xA;        bx = -bx;&#xA;        by = -by;&#xA;    }&#xA;&#xA;    int px = (int) (width + bx * height) / 2;&#xA;    int py = (int) (height + by * height) / 2;&#xA;&#xA;    return new double[] { px, py, dz };&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and here my code for the texture mapping:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public double[] map(double x, double y, double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3) {&#xA;    double A = (x0 - x) * (y0 - y2) - (y0 - y) * (x0 - x2);&#xA;    double B = ((x0 - x) * (y1 - y3) - (y0 - y) * (x1 - x3) + (x1 - x) * (y0 - y2) - (y1 - y) * (x0 - x2)) / 2.0;&#xA;    double C = (x1 - x) * (y1 - y3) - (y1 - y) * (x1 - x3);&#xA;&#xA;    double det = A - 2.0 * B + C;&#xA;&#xA;    double u;&#xA;    if (det == 0.0) {&#xA;        u = A / (A - C);&#xA;        if (Double.isNaN(u) || u &amp;lt; 0.0 || u &amp;gt; 1.0)&#xA;            return null;&#xA;    } else {&#xA;        double u1 = ((A - B) + Math.sqrt(B * B - A * C)) / det;&#xA;        boolean u1valid = !Double.isNaN(u1) &amp;amp;&amp;amp; u1 &amp;gt;= 0.0 &amp;amp;&amp;amp; 1.0 &amp;gt;= u1;&#xA;&#xA;        double u2 = ((A - B) - Math.sqrt(B * B - A * C)) / det;&#xA;        boolean u2valid = !Double.isNaN(u2) &amp;amp;&amp;amp; u2 &amp;gt;= 0.0 &amp;amp;&amp;amp; 1.0 &amp;gt;= u2;&#xA;&#xA;        if (u1valid &amp;amp;&amp;amp; u2valid)&#xA;            u = u1 &amp;lt; u2 ? u2 : u1;&#xA;        else if (u1valid)&#xA;            u = u1;&#xA;        else if (u2valid)&#xA;            u = u2;&#xA;        else&#xA;            return null;&#xA;    }&#xA;&#xA;    double v1 = ((1.0 - u) * (x0 - x) + u * (x1 - x)) / ((1.0 - u) * (x0 - x2) + u * (x1 - x3));&#xA;    boolean v1valid = !Double.isNaN(v1) &amp;amp;&amp;amp; v1 &amp;gt;= 0.0 &amp;amp;&amp;amp; 1.0 &amp;gt;= v1;&#xA;&#xA;    double v2 = ((1.0 - u) * (y0 - y) + u * (y1 - y)) / ((1.0 - u) * (y0 - y2) + u * (y1 - y3));&#xA;    boolean v2valid = !Double.isNaN(v2) &amp;amp;&amp;amp; v2 &amp;gt;= 0.0 &amp;amp;&amp;amp; 1.0 &amp;gt;= v2;&#xA;&#xA;    double v;&#xA;    if (v1valid &amp;amp;&amp;amp; v2valid)&#xA;        v = v1 &amp;lt; v2 ? v2 : v1;&#xA;    else if (v1valid)&#xA;        v = v1;&#xA;    else if (v2valid)&#xA;        v = v2;&#xA;    else&#xA;        return null;&#xA;&#xA;    return new double[] { u, v };&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and here is my quad drawing code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void renderFace(Screen screen, int x0, int y0, int z0, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3) {&#xA;    boolean render = true;&#xA;&#xA;    double[] p0 = screen.project(x0, y0, z0);&#xA;    int px0 = (int) p0[0], py0 = (int) p0[1];&#xA;    render |= p0[2] &amp;gt;= ZCLIP &amp;amp;&amp;amp; px0 &amp;gt;= 0 &amp;amp;&amp;amp; px0 &amp;lt; screen.width &amp;amp;&amp;amp; py0 &amp;gt;= 0 &amp;amp;&amp;amp; py0 &amp;lt; screen.height;&#xA;&#xA;    double[] p1 = screen.project(x1, y1, z1);&#xA;    int px1 = (int) p1[0], py1 = (int) p1[1];&#xA;    render |= p1[2] &amp;gt;= ZCLIP &amp;amp;&amp;amp; px1 &amp;gt;= 0 &amp;amp;&amp;amp; px1 &amp;lt; screen.width &amp;amp;&amp;amp; py1 &amp;gt;= 0 &amp;amp;&amp;amp; py1 &amp;lt; screen.height;&#xA;&#xA;    double[] p2 = screen.project(x2, y2, z2);&#xA;    int px2 = (int) p2[0], py2 = (int) p2[1];&#xA;    render |= p2[2] &amp;gt;= ZCLIP &amp;amp;&amp;amp; px2 &amp;gt;= 0 &amp;amp;&amp;amp; px2 &amp;lt; screen.width &amp;amp;&amp;amp; py2 &amp;gt;= 0 &amp;amp;&amp;amp; py2 &amp;lt; screen.height;&#xA;&#xA;    double[] p3 = screen.project(x3, y3, z3);&#xA;    int px3 = (int) p3[0], py3 = (int) p3[1];&#xA;    render |= p3[2] &amp;gt;= ZCLIP &amp;amp;&amp;amp; px3 &amp;gt;= 0 &amp;amp;&amp;amp; px3 &amp;lt; screen.width &amp;amp;&amp;amp; py3 &amp;gt;= 0 &amp;amp;&amp;amp; py3 &amp;lt; screen.height;&#xA;&#xA;    if (!render)&#xA;        return;&#xA;&#xA;    int minX = Math.min(Math.min(px0, px1), Math.min(px2, px3));&#xA;    if (minX &amp;lt; 0)&#xA;        minX = 0;&#xA;    if (minX &amp;gt; screen.width)&#xA;        minX = screen.width;&#xA;&#xA;    int minY = Math.min(Math.min(py0, py1), Math.min(py2, py3));&#xA;    if (minY &amp;lt; 0)&#xA;        minY = 0;&#xA;    if (minY &amp;gt; screen.height)&#xA;        minY = screen.height;&#xA;&#xA;    int maxX = Math.max(Math.max(px0, px1), Math.max(px2, px3));&#xA;    if (maxX &amp;lt; 0)&#xA;        maxX = 0;&#xA;    if (maxX &amp;gt; screen.width)&#xA;        maxX = screen.width;&#xA;&#xA;    int maxY = Math.max(Math.max(py0, py1), Math.max(py2, py3));&#xA;    if (maxY &amp;lt; 0)&#xA;        maxY = 0;&#xA;    if (maxY &amp;gt; screen.height)&#xA;        maxY = screen.height;&#xA;&#xA;    if (minX == maxX || minY == maxY)&#xA;        return;&#xA;&#xA;    for (int py = minY; py &amp;lt; maxY; ++py)&#xA;        for (int px = minX; px &amp;lt; maxX; ++px) {&#xA;            double[] uv = screen.map(px + 0.5, py + 0.5, px0, py0, px1, py1, px2, py2, px3, py3);&#xA;            if (uv == null)&#xA;                continue;&#xA;            double u = uv[0], v = uv[1];&#xA;&#xA;            double pz = (1 - u) * ((1 - v) * p0[2] + v * p2[2]) + u * ((1 - v) * p1[2] + v * p3[2]);&#xA;            if (pz &amp;lt; ZCLIP)&#xA;                continue;&#xA;&#xA;            int texX = 15 - Math.min(15, (int) (16 * u));&#xA;            int texY = 15 - Math.min(15, (int) (16 * v));&#xA;            screen.setPixel(px, py, pz, Art.WALLS.getPixel(texX, texY) * BRICKS);&#xA;        }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Can anyone point out what I am doing wrong? I am not very experienced as this is my first try at implementing a game engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you for any insight.&lt;/p&gt;&#xA;" OwnerUserId="3330" LastActivityDate="2016-05-10T15:35:53.373" Title="Perspective-Correct Texture Mapping" Tags="&lt;texture&gt;&lt;perspective&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2423" PostTypeId="2" ParentId="2405" CreationDate="2016-05-10T18:27:56.747" Score="9" Body="&lt;p&gt;In film production, we almost never use 8-bit textures for color/albedo, because of banding, etc. (JPEG is especially problematic since by spec, it's sRGB rather than linear values.) We either use 'half' (16 bit float) or 16-bit unsigned integer values for color/albedo textures.&lt;/p&gt;&#xA;" OwnerUserId="1781" LastActivityDate="2016-05-10T18:27:56.747" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2424" PostTypeId="1" CreationDate="2016-05-11T06:00:33.290" Score="7" ViewCount="597" Body="&lt;p&gt;I'm currently reading some books on radiometry. They mention that radiance is constant along a ray. It doesn't change with distance.&#xA;However, I've seen some raytracer and they put the 1/r² factor when they deal with point sources. I don't get why. I didn't find a great explanation on the Internet. &lt;/p&gt;&#xA;" OwnerUserId="3339" LastActivityDate="2016-05-25T18:45:30.017" Title="Why does the 1/r² term appear with point sources?" Tags="&lt;raytracing&gt;&lt;color&gt;&lt;brdf&gt;&lt;physics&gt;" AnswerCount="5" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2425" PostTypeId="2" ParentId="2424" CreationDate="2016-05-11T09:26:05.633" Score="5" Body="&lt;p&gt;It is the &lt;a href=&quot;http://hyperphysics.phy-astr.gsu.edu/hbase/vision/isql.html&quot;&gt;inverse square law of light&lt;/a&gt; for a pure point light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$E = \frac{I}{r^2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where E is illuminance and I is pointance or power/flux per unit solid angle.&lt;/p&gt;&#xA;" OwnerUserId="3331" LastActivityDate="2016-05-11T09:26:05.633" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2426" PostTypeId="1" AcceptedAnswerId="2440" CreationDate="2016-05-11T09:29:43.657" Score="4" ViewCount="172" Body="&lt;p&gt;The slicing algorithm is done on the STL model and it is ensured that the result is a series of simple polygons that do not intersect each other. In other words all of those polygons generate closed loops. I need to identify which of those loops are outer and inner loops. There have been some references suggesting tree depth can be used to identify external and internal loops, without any outline of the algorithm. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would be great if anyone can point to more detailed references where the tree depth can be utilized to filter out inner and outer contour lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following images will provide more information:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.imgur.com/so8C2Gl.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/so8C2Gl.jpg&quot; alt=&quot;Partition areas&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.imgur.com/rM661UP.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/rM661UP.jpg&quot; alt=&quot;Depth Tree Structure&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to the article that I am following - a, b, e, f, and j are outer loops, while the rest are inner loops. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the current situation, I am identifying the inner and outer loops while doing the scanline over each layer after the slicing operation. But I want to identify the inner and outer loops ahead of the scanline operation, so that I can create inner/outer offset for the identified loops and then run the scanline to generate the fill pattern.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The article that I am following is titled - &quot;Equidistant path generation for improving scanning efficiency in layered manufacturing&quot;. I googled up and I am afraid that it is not public. I downloaded the article through the university database.&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="231" LastEditDate="2016-05-13T00:59:24.057" LastActivityDate="2016-05-13T12:11:09.990" Title="Identify different contour cycle after model slicing" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2427" PostTypeId="1" AcceptedAnswerId="2428" CreationDate="2016-05-11T12:14:42.920" Score="0" ViewCount="174" Body="&lt;p&gt;Usually GearVR + SamsungPhone are used both for rendering and displaying but I would like to use it only for displaying when it is plugged to PC. The reason is to get performance similar to Oculus Rift or HTC Vive and not spend money for it. Is it possible?&lt;/p&gt;&#xA;" OwnerUserId="3341" LastActivityDate="2016-05-13T07:10:30.100" Title="Using GPU in PC for GearVR" Tags="&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2428" PostTypeId="2" ParentId="2427" CreationDate="2016-05-11T13:48:05.083" Score="1" Body="&lt;p&gt;Since you're asking in this Stack Exchange, I assume you intend to build a VR app yourself that utilizes this scenario.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While it is perfectly possible to utilize PC for rendering and stream the output to a mobile VR headset, it will come at the relatively high cost of increased latency (see e.g. &lt;a href=&quot;http://arstechnica.com/gaming/2013/01/how-fast-does-virtual-reality-have-to-be-to-look-like-actual-reality/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; for why this is important; the tl;dr is that high latency → nausea). This is because wireless networks have intrinsically higher latency than wired ones, and you need to do the following in a loop:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Collect head tracking (gyroscope/accelerometer) data from the VR headset.&lt;/li&gt;&#xA;&lt;li&gt;Send the head tracking data over the network to the PC.&lt;/li&gt;&#xA;&lt;li&gt;Render a frame on the PC.&lt;/li&gt;&#xA;&lt;li&gt;Stream the frame from the PC to the VR headset. This involves the following substeps:&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Encode video and audio on the PC.&lt;/li&gt;&#xA;&lt;li&gt;Transmit the encoded media frame to the VR headset over the network.&lt;/li&gt;&#xA;&lt;li&gt;Decode video and audio on the VR headset.&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;As I mentioned previously, steps 2 and 4 introduce additional latency (probably from several to a dozen milliseconds, from stream encoding/decoding and network transmission), which – depending on your specific application and the individual tolerance of the user – may or may not be a deal breaker.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastEditorUserId="2817" LastEditDate="2016-05-13T07:10:30.100" LastActivityDate="2016-05-13T07:10:30.100" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2429" PostTypeId="2" ParentId="2424" CreationDate="2016-05-11T17:49:05.713" Score="8" Body="&lt;p&gt;The concept of a point source is an approximation. Physically, light sources are extended objects and emit light from every point on their surface; but when you're far enough away (i.e. the distance to the source is large compared to its size) it's useful to approximate it as a point source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get the $1/r^2$ law out of it as follows. Imagine a spherical area light with some radius $r_\text{light}$, and you're looking at it from a distance $r$ away. Then, we can approximate the solid angle that it subtends from your point of view as the area of a circle of radius $r_\text{light}/r$ (just using similar triangles). This area will be $\pi (r_\text{light}/r)^2$, so it's proportional to $1/r^2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this approximation becomes exact in the limit $r_\text{light}/r \to 0$, i.e. when the light source is very far away or very small. It breaks down if the source is too large or too close.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the source emits a constant radiance from every point on its surface, then when you integrate over solid angle in the rendering equation, you'll get a total irradiance proportional to $1/r^2$. In order to approximate it as a point source in a renderer, we skip the integration and just add an irradiance proportional to $1/r^2$ directly.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-05-11T18:04:08.223" LastActivityDate="2016-05-11T18:04:08.223" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2430" PostTypeId="2" ParentId="2416" CreationDate="2016-05-12T07:43:31.303" Score="5" Body="&lt;p&gt;A quickly formulated method, read first one that popped in my brain (not best), could be. Find the closest points on a parametric spiral for each sample (read &lt;a href=&quot;http://alvyray.com/Memos/CG/Microsoft/6_pixel.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Pixel Is Not A Little Square&lt;sup&gt;3&lt;/sup&gt;&lt;/a&gt;). Then place the samples on a line by placing the pints in one axis by how far they are from your spiral line and the other by what the closest point is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/m8TYh.png&quot; alt=&quot;spiral[1&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can then use something like poisson disk sampling to reconstruct the image (maybe the didsk should be longer ovals the further away they are form the center line and less long as you progress further into the spiral).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that I think of the problem a bit more. A simpler approach could be to map the image on mesh, using UV mapping, then unwrap the mesh. A triangular mesh might exhibit some artifacts so using a B-spline interpolation could be better. Several image mesh algorithms exist and you even have these in Photoshop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Qc5qt.png&quot; alt=&quot;unwound spiral&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: A proof of concept of unwound spiral with the mesh method. Note i scaled the unwound spirals length to make it fit the site requirements better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From initial test in my 3D app of choice seems that a dense enough triangular mesh works fine.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-05-12T14:40:56.900" LastActivityDate="2016-05-12T14:40:56.900" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2431" PostTypeId="1" AcceptedAnswerId="2436" CreationDate="2016-05-12T09:58:02.670" Score="7" ViewCount="1497" Body="&lt;p&gt;I am trying to implement my own path tracer but before arriving to the question I want to give you a short overview:&lt;br&gt;&#xA;In the implementation of the rendering equation I use some particular technique in order to sample surfaces. For example: when one of my rays hits a diffuse surface, the next ray bouncing from that surface will be calculated using a &lt;em&gt;Cosine-weighted Random Direction&lt;/em&gt;. This implies that in my rendering equation I have to take into account the PDF that this specific random distribution implies and specifically divide for this PDF in my equation. So far everything is okey.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, my question. I want to implement a particular technique called &quot;next event estimation&quot; which simply samples the lights. In order to do so, I want to pick a &lt;strong&gt;random point&lt;/strong&gt; on my light, which is spherical, by using the following code (C++):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3&amp;lt;float&amp;gt; randomPoint() const&#xA;{&#xA;    float x;&#xA;    float y;&#xA;    float z;&#xA;&#xA;        // random vector in unit sphere&#xA;    do&#xA;    {&#xA;        x = ((float)rand() / (RAND_MAX)) * 2 - 1;           // random coordinates between -1 and 1&#xA;        y = ((float)rand() / (RAND_MAX)) * 2 - 1;&#xA;        z = ((float)rand() / (RAND_MAX)) * 2 - 1;&#xA;    } while (pow(x, 2) + pow(y, 2) + pow(z, 2) &amp;gt; 1);        // simple rejection sampling&#xA;&#xA;    return centerOfSphere + Vec3&amp;lt;float&amp;gt;(x, y, z) * radius;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As far as I understand (please correct me if wrong), this implements a &lt;strong&gt;uniformly random sampling&lt;/strong&gt;. Also, as far as I have read, this kind of sampling has a PDF = 1 / (b - a) . My question: do I have to use this PDF as well like I do for my &lt;em&gt;Cosine-weighted Random Distribution&lt;/em&gt; or not, since it is a uniform distribution? if yes, what's the range (b - a) that PDF talks about? Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="3069" LastActivityDate="2016-05-13T02:36:03.227" Title="Role of PDF of Uniform Random Sampling in a path tracer" Tags="&lt;rendering&gt;&lt;c++&gt;&lt;pathtracing&gt;&lt;distribution&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2432" PostTypeId="2" ParentId="2424" CreationDate="2016-05-12T11:33:27.583" Score="2" Body="&lt;p&gt;Say the point light is at $P_L$, the shading is happening at $P_S$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's true that the radiance is constant along a shadow ray $P_L \rightarrow P_S$, but that's not the key property for solving the rendering equation at $P_S$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rendering equation, somewhat simplified, is: $L_o(\omega_o) = L_e(\omega_o) + \int_{\Omega} \, f_r(\omega_i, \omega_o)\, L_i(\omega_i)\, (n \cdot \omega_i) \, d \omega_i $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While $L_o$ is expressed in radiance, you are actually integrating the &lt;em&gt;irradiance&lt;/em&gt; $L_i$ of the incoming light at $P_S$, which is expressed in $Wm^{-2}$. The incoming &lt;em&gt;radiance&lt;/em&gt; -- call it $\hat{L}_i$ -- is in $W m^{-2} sr^{-1}$ and, while constant along the shadow ray, it is not directly relevant. The difference between $\hat{L}_i$ and $L_i$ is a $1/r^2$ term since the area of 1 $sr$ increases quadratically with distance from $P_L$ .&lt;/p&gt;&#xA;" OwnerUserId="3075" LastEditorUserId="3075" LastEditDate="2016-05-16T21:29:20.397" LastActivityDate="2016-05-16T21:29:20.397" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2433" PostTypeId="2" ParentId="2419" CreationDate="2016-05-12T18:36:13.147" Score="4" Body="&lt;p&gt;Polygon offsetting is certainly possible to do yourself. It is not nearly as involved as Bezier or B-spline offsetting is. First you want to decide how to deal with:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Areas with no info, in essence how to deal with the joins. Do you just extend the line to the common intersection (miter join) or do you just connect the endpoints (bevel). You could also use round, parabolic or other join styles if you wish. Options here are unlimited. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the purposes of this discussion I will assume you will want a miter or bevel join.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How do you want to deal with sidedness. Is an open curve's offset closed or just on the other side. Other than that the convention is usually in 2D that outside is on the clockwise side of the path&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So lets look at what happens when 2 straight lines join and they are offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jagc9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jagc9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Situation in 2D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a beveled corner join vector, from any point to its offset is magnitude of $a$. Take the direction of the segment rotated counterclockwise 90 degrees then multiply that with the length of offset. Or in the case of the picture in mathematical notation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ &#xA; A' = A + a\bigg(\big|B-A\big|   \begin{bmatrix}&#xA;    0 &amp;amp; 1\\&#xA;    -1 &amp;amp; 0 &#xA;  \end{bmatrix}\bigg)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $a$ is the amount of offset. This assumes lines go from $A$ to $B$ to $C$. Connecting segments must be processed on both sides separately. The same formula can be used for all the points. Then just connect $B'^1$ to $B'^2$ with a line. In case you are matrix illiterate, the matrix says swap x and y coordinate and invert the x value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a miter join the following applies:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/r6eG1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/r6eG1.png&quot; alt=&quot;sss&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Situation of miter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ &#xA; B^{B-B'^{1}} = a\bigg(\big|B-A\big| \begin{bmatrix}&#xA;    0 &amp;amp; 1\\&#xA;    -1 &amp;amp; 0 &#xA;  \end{bmatrix}\bigg)&#xA;$$&#xA;$$&#xA;B' = B+\dfrac{ B^{B-B'^{1}}}{B^{B-B'^{1}}  \cdot (|B-A|-|C-B|)}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above can be heavily simplified but I'll leave that to the reader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the reason to use a library is that when the curves start to self intersect it gets a bit tedious to manage this. So just find a library that does this for you and you'll save a lot of time.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-05-14T11:16:23.827" LastActivityDate="2016-05-14T11:16:23.827" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2434" PostTypeId="1" AcceptedAnswerId="2438" CreationDate="2016-05-12T21:13:17.540" Score="2" ViewCount="90" Body="&lt;p&gt;I am making a 2d game in opengl es 2.0&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inside are tons of rectangles defined by 4 points and one 4 component color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using vertex buffer objects, and I have heard that it is efficent to interlace the data. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So like traditionally you would do&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Corner.x&#xA;Corner.y&#xA;Corner.z&#xA;Corner.rgba&#xA;(repeat for each corner) &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However in my situations two assumptions can be made that can probably make things faster&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1. All the rectangles z values are 0&#xA;2. All corners of the rectangle have the same color. &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is it possible, and what would it look like to have a buffer object structured like this. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Corner.xy&#xA;Corner.xy&#xA;Corner.xy&#xA;Corner.xy&#xA;Color.rgba? &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is it even possible to have opengl assume that the Z is always 0? Is it possible to reuse the color like to hat? &lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-05-13T09:27:56.793" Title="Interlacing vertex buffer data with extra efficiency" Tags="&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2436" PostTypeId="2" ParentId="2431" CreationDate="2016-05-12T21:31:21.500" Score="7" Body="&lt;p&gt;Firstly, as @trichoplax correctly pointed out, your randomPoint function calculates a point in a cube, then uses rejection sampling to return &lt;strong&gt;&lt;em&gt;all&lt;/em&gt;&lt;/strong&gt; points that are &lt;strong&gt;&lt;em&gt;inside&lt;/em&gt;&lt;/strong&gt; a unit sphere. In order to return points on a sphere, you would need to change the greater than to an equals. That said, rejection sampling is very inefficient. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A better way to sample a sphere, is to sample in spherical space, then transform to cartesian. ie:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float phi = PI * randf();&#xA;float theta = 2 * PI * randf();    &#xA;&#xA;float x = radius * std::sinf(phi) * std::sinf(theta);&#xA;float y = radius * std::cosf(phi);&#xA;float z = radius * std::sinf(phi) * std::cosf(theta);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, this is not uniform, and will cause samples to clump at the poles. To prevent this, we transform phi:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float phi = std::acosf(2.0f * randf() - 1.0f);&#xA;float theta = 2 * PI * randf();    &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We can use some trig identities to make it a bit more efficient to calculate with the computer:&#xA;$$\begin{align*}&#xA;\sin(\cos^{-1}(x)) \equiv&amp;amp; \ \sqrt{1 - x^2}\\&#xA;\cos(\cos^{-1}(x)) \equiv&amp;amp; \ x\\&#xA;\\&#xA;\phi =&amp;amp; \ \cos^{-1}(2\xi - 1)\\&#xA;\sin(\phi) =&amp;amp; \ sin(\cos^{-1}(2 \xi - 1))\\&#xA;=&amp;amp; \ \sqrt{1 - (2 \xi - 1)^2}\\&#xA;\cos(\phi) =&amp;amp; \ 2 \xi - 1&#xA;\end{align*}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the full change is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float cosPhi = 2.0f * randf() - 1.0f;&#xA;float sinPhi = std::sqrt(1.0f - cosPhi * cosPhi);&#xA;float theta = 2 * PI * randf();    &#xA;&#xA;float x = radius * sinPhi * std::sinf(theta);&#xA;float y = radius * cosPhi;&#xA;float z = radius * sinPhi * std::cosf(theta);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in the case of next event estimation, uniform sampling the whole sphere is inefficient, because a ray can only 'see' half of the sphere at a time. So if we generate a point on the 'back' of the sphere, the sphere will occlude the point, and your calculation will be wasted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, you generate samples in a cone, which covers the great circle of the sphere, as viewed from the starting point of the ray.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Sample sphere uniformly inside subtended cone&#xA;float rand1 = randf();&#xA;float rand2 = randf();&#xA;&#xA;// Compute theta and phi values for sample in cone&#xA;float distanceSquared = DistanceSquared(rayOrigin, sphereCenter);&#xA;&#xA;// We use geometry to calculate the angle of the cone (aka, the maximum phi can be when we sample)&#xA;// It's easier / cheaper to use geometry to calculate sin/cos phi directly, rather than generating phi and using sin/cos&#xA;float sinPhiMaxSquared = radius * radius / distanceSquared;&#xA;float cosPhiMax = std::sqrt(1.0f - sinPhiMaxSquared);&#xA;float cosPhi = (1.0f - rand1) + rand1 * cosPhiMax;&#xA;float sinPhi = std::sqrt(1.0f - cosPhi * cosPhi);&#xA;&#xA;// Phi can be anything in 2 PI&#xA;float theta = 2 * PI * rand2;&#xA;&#xA;float x = radius * sinPhi * std::sinf(theta);&#xA;float y = radius * cosPhi;&#xA;float z = radius * sinPhi * std::cosf(theta);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;NOTE: x, y, z are in LOCAL coordinate space.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So we need to transform to world coordinates:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 zAxis = normalize(sphereCenter - rayOrigin);&#xA;float3 xAxis;&#xA;if (std::abs(zAxis.x) &amp;gt; std::abs(zAxis.y))&#xA;    xAxis = float3(-zAxis.z, 0.0f, zAxis.x) / std::sqrt(zAxis.x * zAxis.x + zAxis.z * zAxis.z);&#xA;else&#xA;    xAxis = float3(0.0f, zAxis.z, -zAxis.y) / std::sqrt(zAxis.y * zAxis.y + zAxis.z * zAxis.z);&#xA;yAxis = cross(zAxis, xAxis);&#xA;&#xA;&#xA;float3 samplePoint = x * xAxis + y * yAxis + z * zAxis;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the pdf is calculated as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float pdf = 1 / (2 * PI * (1 - cosPhiMax));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The code here is heavily influenced / copied from &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/master/src/shapes/sphere.cpp&quot; rel=&quot;noreferrer&quot;&gt;PBRT v3&lt;/a&gt;. They have a series of classes and functions for sampling from shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, the pdf. In monte-carlo integration, we need to combine the pdf's of each integration we do. In path tracing, we can integrate over many many things. For example, the general rendering equation integrates the incoming light over the hemisphere, depth of field can be treated as an integration over a focal distance, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For next event estimation, you explicitly split the rendering equation into two integrands, direct lighting, and indirect lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Standard rendering equation:&#xA;$$ L_{\text{o}}(p, \omega_{\text{o}}) =  L_{e}(p, \omega_{\text{o}}) \ + \  \int_{\Omega} f(p, \omega_{\text{o}}, \omega_{\text{i}}) L_{\text{i}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next Event Estimation:&#xA;$$ L_{\text{o}}(p, \omega_{\text{o}}) =  L_{e}(p, \omega_{\text{o}}) \ + \ \int_{\Omega} f(p, \omega_{\text{o}}, \omega_{\text{i}}) L_{\text{i, direct}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}}\ \ + \ \int_{\Omega} f(p, \omega_{\text{o}}, \omega_{\text{i}}) L_{\text{i, indirect}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In simple naive forward path tracing, everything is is treated as indirect light. In next event estimation, we directly calculate the direct lighting and add it to the indirect lighting. And if we hit a light, we ignore the contribution, since we're calculating the direct lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since we have two integrations, each will have its own pdf. Aka:&#xA;$$L_{\text{o}}(p, \omega_{\text{o}}) =  L_{e}(p, \omega_{\text{o}}) \ \ + \ \sum_{k=0}^{\infty } \frac{f(p, \omega_{\text{o}}, \omega_{\text{i}}) L_{\text{i, direct}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | }{pdf_{direct}}\ \ + \ \sum_{k=0}^{\infty } \frac{f(p, \omega_{\text{o}}, \omega_{\text{i}}) L_{\text{i, indirect}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | }{pdf_{indirect}}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to see how this is implemented, you can check out my implementation &lt;a href=&quot;https://github.com/RichieSams/lantern/blob/master/source/renderer/renderer.cpp#L92&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;. Note: my light sampling is a bit more complicated, since it does multiple importance sampling. But it can be as simple as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 Renderer::EstimateDirect(Light *light, UniformSampler *sampler, float3a &amp;amp;surfacePos, float3a &amp;amp;surfaceNormal, float3a &amp;amp;wo, Material *material) const {&#xA;    float pdf;&#xA;    float3 wi;&#xA;&#xA;    // Sample a point on the light and get the pdf&#xA;    float3 Li = light-&amp;gt;SampleLi(sampler, m_scene, surfacePos, surfaceNormal, &amp;amp;wi, &amp;amp;pdf);&#xA;&#xA;    // Calculate the brdf value&#xA;    float f = material-&amp;gt;Eval(wi, wo, surfaceNormal);&#xA;    return f * Li * / pdf;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2016-05-13T02:36:03.227" LastActivityDate="2016-05-13T02:36:03.227" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2438" PostTypeId="2" ParentId="2434" CreationDate="2016-05-13T09:27:56.793" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it even possible to have opengl assume that the Z is always 0?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes it is. Just set the component count to 2 in &lt;code&gt;glVertexAttribPointer&lt;/code&gt; and the other 2 components (&lt;code&gt;z&lt;/code&gt; and &lt;code&gt;w&lt;/code&gt;) will be auto filled with 0 and 1 resp.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it possible to reuse the color like to hat? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No it is not. Opengl (and most other graphics apis) require that each vertex is referenced by only a single index.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-05-13T09:27:56.793" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2439" PostTypeId="2" ParentId="2409" CreationDate="2016-05-13T11:34:19.540" Score="3" Body="&lt;p&gt;With help from the Nvidia Forum and two very helpful and friendly Nvidia employees I found the perfect solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OptiX there is a so called selector node. This is a special scene-graph node that utilizes a user specified program to select which child a ray should traverse and which not.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;optix.h&amp;gt;&#xA;&#xA;rtDeclareVariable(unsigned int, timestep, , );&#xA;&#xA;RT_PROGRAM void animation_selector()&#xA;{&#xA;    rtIntersectChild(timestep);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is a simple version of such a selection program. From the CPP-API side the current timestep will be set and can be used to make the animation. And then when the scene graph is traversed the program just says &quot;Traverse only the child with index 'timestep'&quot;. This does not trigger a recompile or refit and therefore is nearly instant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The selector node is simply created in following way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;optix::Selector selector = context_-&amp;gt;createSelector();&#xA;&#xA;std::string path_to_ptx = VRTPtxFinder::GetPtxPath(&quot;VistaRayTracing_generated_animation_selector.cu.ptx&quot;);&#xA;&#xA;optix::Program selection_program = context_-&amp;gt;createProgramFromPTXFile(path_to_ptx, &quot;animation_selector&quot;);&#xA;selector[&quot;timestep&quot;]-&amp;gt;setUint(0u);&#xA;selector-&amp;gt;setVisitProgram(selection_program);&#xA;&#xA;for(auto group : groups)&#xA;{&#xA;  selector-&amp;gt;addChild(group);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The only cost is one additional method call for each traversal and thereby also a slightly bigger stack which caused me some problems with a stack overflow so when using this, keep an eye on the stack size.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-05-13T11:34:19.540" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2440" PostTypeId="2" ParentId="2426" CreationDate="2016-05-13T11:57:41.403" Score="2" Body="&lt;p&gt;Take a random vertex on your loop, shoot a ray trough all the other loops. For loops you crossed a odd number of times your inside for loops you crossed a even number of times your outside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The loops that are outside of all others is in the root of your tree. Then find loops that are inside that, but not inside some other. Then find next level and next level and so on. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eY5kH.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eY5kH.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Animation of arranging in tree by shooting rays&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can optimize this by using bounding boxes/ bsp trees for the test areas. But for a small number of areas that might be overkill. just sorting them left to right top to bottom should suffice. You can use the same algorithms as your scan line operators.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FGFVR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FGFVR.png&quot; alt=&quot;offset&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: And now you can offset the shape. But you need to recheck that there is no intersection left after this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the topology is somewhat stable across levels of slices so you can use that to your benefit. Just follow the 3D surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or you could do the offset in 3D on the polygons so you do not need this info. Also if you just need the winding for knowing which way to offset rule you can derive it from the 3d model itself, each vertex has a normal so project the normal for one triangle in each loop with your slicing algorithm per loop. That then gives you the direction of loops outside which is inside for nearly free. You wouldn't get the tree but then again you might not need it.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-05-13T12:11:09.990" LastActivityDate="2016-05-13T12:11:09.990" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2441" PostTypeId="1" CreationDate="2016-05-13T15:40:05.353" Score="8" ViewCount="558" Body="&lt;p&gt;I have a scalar function defined over the vertices of a surface mesh. I want to compute an approximate (and generalized, I suppose) &quot;Gaussian blur/convolution&quot; of this function over the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can imagine for each vertex, taking an average of the function at vertices in it's (multi-hop) neighborhood weighted according to the Gaussian of their Euclidean distance (in R3) from the current vertex multiplied by the local area they represent. This approximation would be good if the surface isn't too curved at the scale of the Gaussian kernel. However it would still be computationally prohibitive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a more efficient convolving algorithm, perhaps based on some kind of iterated &quot;flow&quot; or partial exchange through edges of the mesh?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The mesh can have either triangular or quadrilateral faces - whichever is more convenient in answering this question. But the edge lengths are not constant, so local neighborhood geometry differs between vertices.&lt;/p&gt;&#xA;" OwnerUserId="3294" LastEditorUserId="3294" LastEditDate="2016-05-16T18:21:30.267" LastActivityDate="2016-05-16T18:21:30.267" Title="Gaussian blurring a function defined over a surface mesh" Tags="&lt;mesh&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2443" PostTypeId="2" ParentId="2391" CreationDate="2016-05-13T22:34:31.890" Score="0" Body="&lt;p&gt;While the product sampling methods provides better (perfect) distribution for rays I would say that using MIS (multiple importance sampling) is a method verified in production. Since shadowing information is unknown product sampling doesn't become perfect anyway and it is quite hard to implmenet. Shooting more rays might be worth more! Depends on your situation and ray budgets of course!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Short description of MIS: In essence you trace both a BSDF-ray (as you would anyway for doing indirect lighting) and an explicit ray towards the EM. MIS give you weights so that you can combine them in a way that removes a lot of the noise. MIS is especially good at choosing &quot;technique&quot; (implicit or explicit sampling) based on the situation that arises. This happens naturally without the user having to make hard choices based on roughness etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Chapter 9 of &lt;a href=&quot;http://graphics.stanford.edu/papers/veach_thesis/&quot; rel=&quot;nofollow&quot;&gt;http://graphics.stanford.edu/papers/veach_thesis/&lt;/a&gt; covers this in detail. Also see &lt;a href=&quot;https://www.shadertoy.com/view/4sSXWt&quot; rel=&quot;nofollow&quot;&gt;https://www.shadertoy.com/view/4sSXWt&lt;/a&gt; for a demo of MIS in action with area lights.&lt;/p&gt;&#xA;" OwnerUserId="286" LastActivityDate="2016-05-13T22:34:31.890" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2444" PostTypeId="2" ParentId="2441" CreationDate="2016-05-14T12:59:19.210" Score="6" Body="&lt;h1&gt;A few different approaches&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I'll consider a few variations on your specific request, since you mention efficiency and I suspect your specific request may be the least efficient. I'll also suggest ways of improving the efficiency without varying from your intended approach, so you can weigh up the alternatives.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Blurring the volume instead of the surface&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you want the distance metric to be 3D Euclidean distance instead of 2D Euclidean distance within the surface, then you could perform the blur on a regular 3D grid to which the scalar function you have in mind has been applied. Then you can use the final result of your Difference of Gaussians to calculate the scalar values at the vertices of your irregular mesh. This avoids having to take into account the mesh shape for the bulk of the calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 3D grid is likely to have a much larger number of vertices than the 2D mesh, but they will all be equally spaced and the large kernel blur can be achieved by repeated application of a small kernel blur taking into account only the 6 nearest neighbours, which will always be at a constant distance away. This approach involves potentially more calculation, but the ease with which the regular grid could be GPU accelerated may appeal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will give a different result from performing the blur on the mesh vertices using 3D Euclidean distance. For example, the 3D grid approach will be affected by distinctive regions of the 3D scalar function that are near but not on the mesh. This may be desirable or not depending on your specific purpose.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Using 2D distance instead of 3D distance&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you find that you need the distance metric to be 2D Euclidean within the surface, then you can get a good approximation to a larger kernel Gaussian blur by repeatedly applying a smaller kernel Gaussian blur. If there is not too much variation in the edge lengths within your mesh you may be able to choose a kernel size which allows for only including vertices one edge away at each iteration. This allows for only using single edge lengths to calculate the size of the contribution of a vertex, rather than calculating a 2D multi-edge distance.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;3D distance using the surface without the volume&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you need the calculation to be precisely as described in your question, being calculated within the mesh rather than within the surrounding volume, but also using the 3D Euclidean distance, then using nearest neighbours and several iterations will not work. Unless the mesh is near to flat, the repeated application of a nearest neighbour blur will result in an approximation to the 2D Euclidean distance case, since the values will only be able to bleed from vertex to vertex, not directly along the shortest path as they would in a single pass. This will give less spread than would be achieved by a single pass that calculates the 3D distance to a vertex 10 edges away. (I have used 10 edges since you mention a 10-hop in your comment on the question.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Implementing the blur in a single pass will mean calculating the 3D Euclidean distance between every vertex and every other vertex within a 10 edge radius. This will be expensive, but perfectly possible. Since you mention efficiency, consider that there are some redundancies you can eliminate provided you have sufficient available memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The two blurs that you produce prior to taking the Difference of Gaussians will use the same set of 3D distances up to the edge radius of the smaller kernel blur. If you can save these then you only need to calculate them once, rather than once per blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, each distance will be used twice per blur - once in each direction as the length from vertex A to vertex B is the same as the length from B to A. Caching/memoising these distances will avoid calculating them twice.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Effects from arbitrarily many edges away&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If the surface curves such that some vertices which are many edges away are still near enough to affect each other in 3D distance, then rather than considering vertices within a certain number of edges away, you may need to consider all vertices within a certain 3D radius, regardless of how long the path via edges. In this case you can consider fewer vertices by using space partitioning, choosing a specific method which suits the mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't want parts of the surface which approach each other to influence each other, then you probably want a 2D distance metric rather than the 3D one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have a wide range of different edge lengths then you may find the same problem of not being able to define a set number of edges to traverse, even if the mesh is fairly flat. Again you may need to define a 3D distance instead of a number of edges, and consider all vertices that lie within that radius.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-05-14T13:09:26.750" LastActivityDate="2016-05-14T13:09:26.750" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="2445" PostTypeId="2" ParentId="2424" CreationDate="2016-05-14T14:27:20.423" Score="4" Body="&lt;p&gt;I'll give an intuitive idea of the reason in this answer. Once this intuitive idea is grasped, it can be easier to absorb the mathematical descriptions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other people find it easier the other way around, so look at all the answers and see which approach works for you personally.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;A spherical shell of photons&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Imagine a point light source. Picture an instant where it emits a million photons spread evenly in all directions. At that instant, they are all in the same position, at the central point. A moment later, they have all moved the same distance and are now arranged in a small sphere with the point at its centre. A short time later they are still arranged in a sphere, but now a much larger sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the sphere expands it always has the same number of photons, but they are spread out over the increasing area. Each photon has the same amount of energy it had when it first left the point source, but the photons are more spread out so a given area of the sphere now has less energy due to having fewer photons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When a photon hits a surface, it adds the same amount of energy whether it has traveled 1 metre or 100 metres. The reason the surface looks dimmer when it is further from the light source is that the photons are more spread out across that surface.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Source to eye ray tracing&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you wrote a ray tracer that started with rays being emitted from a point light source, and then followed them to see what they hit, you wouldn't need the $1/r^2$ term. Objects further from the light would naturally be hit by fewer rays due to the rays spreading out.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Eye to source ray tracing&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Most ray tracers don't start the rays from the light source, as this results in calculating the paths of all the rays that never reach the eye, which is very inefficient. Instead the rays start at the eye and are traced backwards, to see what surface they came from. If the ray was then bounced from that surface in a random direction to see if it hits the point light source, the fact that the light source is a point would make the probability of hitting it zero. So instead $1/r^2$ is used to give a measure of how many rays hit the surface.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Geometry of a point source&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;This isn't a property of light, it is a property of a point source. Light traveling in all directions from a point forms spherical shells of photons, and the surface area of a sphere increases in proportion to the radius squared.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you had light being emitted that was not in all directions then the rule would be different. For example, imagine a line light source instead of a point, with all the light being emitted radially (only in directions perpendicular to the line). Now the light forms cylindrical shells of photons, and the surface area of a cylinder increases in proportion to the radius, not the radius squared. Now you would use a $1/r$ term instead of a $1/r^2$ term, and an object would need to be moved significantly further from the light source before seeing a noticeable drop in brightness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In reality, nearly every light source is equivalent to a collection of point sources - every point on an area light source emits light in all directions. Even cylindrical lights like flourescent strip lights and neon signs still emit light in all directions, so the photons form spherical shells rather than cylindrical ones. So the reduction in light level will nearly always be with $1/r^2$.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-05-14T14:40:01.353" LastActivityDate="2016-05-14T14:40:01.353" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2446" PostTypeId="1" AcceptedAnswerId="2528" CreationDate="2016-05-15T04:39:01.593" Score="3" ViewCount="217" Body="&lt;p&gt;OK so I have a simple setup going on.  Basically I am just drawing some textures and shapes.  However sizing is going weird... let me show you how any maybe you can diagnose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically everything is broken into components that work fine by themselves, however when together it is disastrous.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Case #1 Section of actual texture appears with an enlarged resolution in the bottom left corner.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glViewport(0, 0, GLsizei(width), GLsizei(height))&#xA;layer_shapes.begin()&#xA;glViewport(0, 0, GLsizei(width), GLsizei(height))&#xA;checkFades()&#xA;drawShapes()&#xA;layer_shapes.end()&#xA;drawTexture(layer_shapes, alpha: 0.0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BQqGr.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BQqGr.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;strong&gt;Case #2 Image appears enlarged and full screen&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layer_shapes.begin()&#xA;checkFades()&#xA;drawShapes()&#xA;layer_shapes.end()&#xA;drawTexture(layer_shapes, alpha: 0.0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jfR7w.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jfR7w.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Case #3 proving that texture drawing works by drawing to front buffer (I put a texture into a fbo and never drew to the fbo)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;drawTexture(layer_shapes, alpha: 0.0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YvdOz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YvdOz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Case #4 Proving that shape drawing works (This is what it should look like, except with an accumulation effect)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;drawShapes()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9hlqX.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9hlqX.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;(Please note discoloration is due to a debugging thing in the fragment shader, not an error)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In summary&lt;/strong&gt; Cases 1 and 2 do not work as intended (they enlarge only part of the shape drawing and put it in the wrong proportion on the screen).  Cases 3 and 4 show the individual complnents (drawing shapes, and drawing textures) working when everything is drawn to the front buffer without any 'glViewport' calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The desired behavior is&lt;/strong&gt; that an image like case 4 would be drawn, however the image would be an accumulation of previous frames (Notice how i never clear the layer_shapes fbo) so the shapes (that are moving) would leave a trail.  The proportions are just being weird! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And Incase you want to see it here is how I set up my texture fbo's.  They get initialized and then have .load() called on them&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class TextureBuffer {&#xA;    var framebuffer:GLuint = 0&#xA;    var tex:GLuint = 0&#xA;    var old_fbo:GLint = 0&#xA;    var w:GLsizei = 0&#xA;    var h:GLsizei = 0&#xA;&#xA;&#xA;    init(widthi: GLsizei = 0, heighti: GLsizei = 0)&#xA;    {&#xA;        w = widthi&#xA;        h = heighti&#xA;    }&#xA;&#xA;    func begin()&#xA;    {&#xA;        glGetIntegerv(GLenum(GL_FRAMEBUFFER_BINDING), &amp;amp;old_fbo)&#xA;        glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer)&#xA;    }&#xA;&#xA;    func checkStatus()&#xA;    {&#xA;        let status = glCheckFramebufferStatus(GLenum(GL_FRAMEBUFFER))&#xA;        if (status != GLenum(GL_FRAMEBUFFER_COMPLETE))&#xA;        {&#xA;            print(&quot;DIDNT GO WELL WITH&quot;)&#xA;            print(status)&#xA;        }&#xA;    }&#xA;&#xA;    func end()&#xA;    {&#xA;        glBindFramebuffer(GLenum(GL_FRAMEBUFFER), GLenum(old_fbo))&#xA;    }&#xA;&#xA;    func loadTexture(name: String, type: String) -&amp;gt; GLuint&#xA;    {&#xA;        var it:GLKTextureInfo = GLKTextureInfo()&#xA;        let pic = UIImage(named: name + &quot;.&quot; + type)!.CGImage&#xA;        let path = NSBundle.mainBundle().pathForResource(name, ofType: type)&#xA;&#xA;        do&#xA;        {&#xA;            try it = GLKTextureLoader.textureWithContentsOfFile(path!, options: nil)&#xA;        }&#xA;        catch&#xA;        {&#xA;            do&#xA;            {&#xA;                //print(&quot;ERR Loading: &quot; + path!)&#xA;                try it = GLKTextureLoader.textureWithCGImage(pic!, options: nil)&#xA;            }&#xA;            catch&#xA;            {&#xA;                print(&quot;Error loading UIImage: &quot; +  pic.debugDescription)&#xA;                it = GLKTextureInfo()&#xA;            }&#xA;        }&#xA;        return it.name&#xA;    }&#xA;&#xA;    func load(width: CGFloat?, height: CGFloat?)&#xA;    {&#xA;        if let lwidth = width&#xA;        {&#xA;            w = GLsizei(lwidth)&#xA;        }&#xA;        if let lheight = height&#xA;        {&#xA;            h = GLsizei(lheight)&#xA;        }&#xA;        glBindTexture(GLenum(GL_TEXTURE_2D), 0)&#xA;        glGetIntegerv(GLenum(GL_FRAMEBUFFER_BINDING), &amp;amp;old_fbo)&#xA;&#xA;        glGenFramebuffers(1, &amp;amp;framebuffer)&#xA;        tex = loadTexture(&quot;Black&quot;, type: &quot;png&quot;)&#xA;&#xA;        glBindFramebuffer(GLenum(GL_FRAMEBUFFER), framebuffer)&#xA;&#xA;&#xA;        glBindTexture(GLenum(GL_TEXTURE_2D), tex)&#xA;        //------&amp;gt;&amp;gt;&amp;gt;&amp;gt;glTexImage2D(GLenum(GL_TEXTURE_2D), 0, GL_RGBA, GLsizei(w), GLsizei(h), 0, GLenum(GL_RGBA), GLenum(GL_UNSIGNED_BYTE), nil)&#xA;        glFramebufferTexture2D(GLenum(GL_FRAMEBUFFER), GLenum(GL_COLOR_ATTACHMENT0), GLenum(GL_TEXTURE_2D), tex, 0)&#xA;&#xA;&#xA;        let status = glCheckFramebufferStatus(GLenum(GL_FRAMEBUFFER))&#xA;        if (status != GLenum(GL_FRAMEBUFFER_COMPLETE))&#xA;        {&#xA;            print(&quot;DIDNT GO WELL WITH&quot;, width, &quot; &quot; , height)&#xA;            print(status)&#xA;        }&#xA;&#xA;        glBindFramebuffer(GLenum(GL_FRAMEBUFFER), GLenum(old_fbo))&#xA;    }&#xA;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A thought is there was a line near the end (I put an arrow pointing to it) that I had to remove to get the fbo to work properly.  Previously the code worked fine, however it is not working fine now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I do have a suspicion that since I have removed that line that caused nothing to work that the texture that is generated by it is the wrong size since the texture it is loading is of a non-device size.  However I do not know why that call causes everything not to work.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2016-05-15T16:33:53.343" LastActivityDate="2016-05-30T08:37:34.313" Title="What is causing this odd scaling behavior?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="2447" PostTypeId="1" AcceptedAnswerId="2449" CreationDate="2016-05-15T17:06:14.197" Score="21" ViewCount="3113" Body="&lt;p&gt;I tried to implement Perlin Noise &lt;em&gt;by myself&lt;/em&gt; using just the theory (following flafla2.github.io/2014/08/09/perlinnoise.html). Unfortunately I was unable to achieve the look of the &quot;original&quot; Perlin Noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the reason the code below renders a blocky version of Perlin Noise?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What should I improve/change in the code so that it renders Perlin Noise without the artifacts?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect there might be problem either in the way I interpolate or in the &lt;code&gt;grads&lt;/code&gt; vector. The &lt;code&gt;grads&lt;/code&gt; vector contains dot products of (random vector for lattice point) and (the size vector) – for all 4 nearby lattice points. (The random and size vectors are described in the very first link.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GLSL Sandbox: &lt;a href=&quot;http://glslsandbox.com/e#32663.0&quot; rel=&quot;noreferrer&quot;&gt;http://glslsandbox.com/e#32663.0&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.imgur.com/14reHUI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/14reHUI.png&quot; alt=&quot;Artifacts in the noise&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float fade(float t) { return t * t * t * (t * (t * 6. - 15.) + 10.); }&#xA;vec2 smooth(vec2 x) { return vec2(fade(x.x), fade(x.y)); }&#xA;&#xA;vec2 hash(vec2 co) {&#xA;    return fract (vec2(.5654654, -.65465) * dot (vec2(.654, 57.4), co));&#xA;}&#xA;&#xA;float perlinNoise(vec2 uv) {&#xA;    vec2 PT  = floor(uv);&#xA;    vec2 pt  = fract(uv);&#xA;    vec2 mmpt= smooth(pt);&#xA;&#xA;    vec4 grads = vec4(&#xA;        dot(hash(PT + vec2(.0, 1.)), pt-vec2(.0, 1.)),   dot(hash(PT + vec2(1., 1.)), pt-vec2(1., 1.)),&#xA;        dot(hash(PT + vec2(.0, .0)), pt-vec2(.0, .0)),   dot(hash(PT + vec2(1., .0)), pt-vec2(1., 0.))&#xA;    );&#xA;&#xA;    return 5.*mix (mix (grads.z, grads.w, mmpt.x), mix (grads.x, grads.y, mmpt.x), mmpt.y);&#xA;}&#xA;&#xA;float fbm(vec2 uv) {&#xA;    float finalNoise = 0.;&#xA;    finalNoise += .50000*perlinNoise(2.*uv);&#xA;    finalNoise += .25000*perlinNoise(4.*uv);&#xA;    finalNoise += .12500*perlinNoise(8.*uv);&#xA;    finalNoise += .06250*perlinNoise(16.*uv);&#xA;    finalNoise += .03125*perlinNoise(32.*uv);&#xA;&#xA;    return finalNoise;&#xA;}&#xA;&#xA;void main() {&#xA;    vec2 position = gl_FragCoord.xy / resolution.y;&#xA;    gl_FragColor = vec4( vec3( fbm(3.*position) ), 1.0 );&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3365" LastActivityDate="2016-05-16T21:52:56.627" Title="Why does my Perlin Noise look &quot;blocky&quot;?" Tags="&lt;glsl&gt;&lt;noise&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2449" PostTypeId="2" ParentId="2447" CreationDate="2016-05-15T18:38:14.730" Score="24" Body="&lt;p&gt;The interpolation looks fine. The main problem here is that the hash function you're using isn't very good. If I look at just one octave, and visualize the hash result by outputting &lt;code&gt;hash(PT).x&lt;/code&gt;, I get something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LcFJV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LcFJV.png&quot; alt=&quot;bad hash function&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is supposed to be completely random per grid square, but you can see that it has a lot of diagonal line patterns in it (it almost looks like a checkerboard), so it's not a very random hash, and those patterns will show up in the noise produced by it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other problem is that your hash only returns gradient vectors in [0, 1], while they should be in [&amp;minus;1, 1] to get gradients in all directions. That part's easy to fix by remapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix those problems, I switched the code to use this hash function (which I learned from Mikkel Gjoel, and &lt;a href=&quot;https://stackoverflow.com/questions/12964279/whats-the-origin-of-this-glsl-rand-one-liner/&quot;&gt;is probably due to a paper by W.J.J. Rey&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 hash(vec2 co) {&#xA;    float m = dot(co, vec2(12.9898, 78.233));&#xA;    return fract(vec2(sin(m),cos(m))* 43758.5453) * 2. - 1.;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that due to the trig functions it's going to be a bit more expensive than your version. However, it considerably improves the appearance of the resulting noise:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ND8Es.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ND8Es.png&quot; alt=&quot;fbm noise with better hash function&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-05-16T21:52:56.627" CommentCount="14" ContentLicense="CC BY-SA 3.0" />
  <row Id="2450" PostTypeId="1" AcceptedAnswerId="2452" CreationDate="2016-05-16T17:31:04.707" Score="12" ViewCount="7647" Body="&lt;p&gt;I'd like to load arbitrary meshes and draw thick black lines along the edges to get a toon-shading like look.&#xA;I managed to draw a black silhouette around the objects by using the stencil buffer. You can see the result here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rPEIz.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rPEIz.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what's missing are the black lines in the object itself. I thought about checking normal discontinuities: Checking if a neighbouring pixel has a different normal vector than the current one. If yes, an edge has been found. Unfortunately, I've no idea how I could implement this approach, neither in OpenGL nor in GLSL vertex/fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd be very happy for some help regarding this approach or any other regarding edge detection. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I do not use any textures for my meshes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Too be more precise, I would like to create a CAD/CAM solution that looks as much as possible like this (taken from Top Solid &lt;a href=&quot;https://www.youtube.com/watch?v=-qTJZtYUDB4&quot; rel=&quot;noreferrer&quot;&gt;https://www.youtube.com/watch?v=-qTJZtYUDB4&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uIZW7.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uIZW7.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;" OwnerUserId="3377" LastEditorUserId="3377" LastEditDate="2016-05-19T15:10:56.093" LastActivityDate="2016-08-08T21:12:17.303" Title="OpenGL - Detection of edges" Tags="&lt;opengl&gt;&lt;edge-detection&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2451" PostTypeId="2" ParentId="2391" CreationDate="2016-05-16T20:30:13.717" Score="4" Body="&lt;p&gt;Disclaimer: I have no idea what is the state of the art in the environmental map sampling. In fact, I have very little knowledge about this topic. So this will not be complete answer but I will formulate the problem mathematically and analyze it. I do this mainly for myself, so I make it clear for my self but I hope that OP and others will find it useful.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\newcommand{\w}{\omega}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We want to calculate direct illumination at a point i.e. we want to know the value of &lt;a href=&quot;https://en.wikipedia.org/wiki/Rendering_equation#Equation_form&quot; rel=&quot;nofollow&quot;&gt;the integral&lt;/a&gt;&#xA;$$&#xA;I =\int_{S^2} f(\omega_i,\omega_o,n) \, L(\omega_i) \,(\omega_i\cdot n)^+ d\omega_i&#xA;$$&#xA;where $f(\omega_i,\omega_o,n)$ is BSDF function(I explicitly state dependance on the normal which will be useful later), $L(\omega_i)$ is radiance of environmental map and $(\omega_i \cdot n)^+$ is the cosine term together with the visibility(&lt;a href=&quot;https://en.wikipedia.org/wiki/Positive_and_negative_parts&quot; rel=&quot;nofollow&quot;&gt;that what the $+$ is for&lt;/a&gt;) i.e. $(\omega_i \cdot n)^+=0$ if $(\omega_i \cdot n)&amp;lt;0$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We estimate this integral by generating $N$ samples  $\omega_i^1,\dots,\omega_i^N$ with the respect to the probability density function $p(\omega_i)$, the estimator is&#xA;$$&#xA;I \approx \frac1N \sum_{k=1}^N \frac{f(\omega_i^k,\omega_o,n) \, L(\omega_i^k) \,(\omega_i^k\cdot n)^+ }{p(\omega_i^k)}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is: How do we choose the pdf $p$ such that we are able to generate the samples in acceptable time and the variance of the above estimator is reasonably small.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;s&gt;Best&lt;/s&gt; method&lt;/strong&gt; Pick $p$ proportional to the integrand&#xA;$$&#xA;p(\omega_i) \sim f(\omega_i,\omega_o,n) \, L(\omega_i) \,(\omega_i\cdot n)^+ &#xA;$$&#xA;But most of the times it is very expensive to generate a sample according to this pdf, so it is not useful in practice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Methods suggested by OP:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Method one&lt;/strong&gt;: Choose $p$ proportional to the cosine term&#xA;$$&#xA;p(\omega_i) \sim (\omega_i\cdot n)^+&#xA;$$&#xA;&lt;strong&gt;Method two&lt;/strong&gt;: Choose $p$ proportional to the EM&#xA;$$&#xA;p(\omega_i) \sim L(\omega_i)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Based on the names of mentioned papers I can partially guess what they do(unfortunately I do not have the time and energy to read them right now). But before discussing what they most probably do, let's talk about power series a little bit :D&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If we have a function of one real variable e.g. $f(x)$. Then if it is well behaved then it can be expanded into a power series&#xA;$$&#xA;f(x) = \sum_{k=0}^\infty a_k x^k&#xA;$$&#xA;Where $a_k$ are constants. This can be used to approximate $f$ by truncating the sum at some step $n$&#xA;$$&#xA;f(x) \approx \sum_{k=0}^n a_k x^k&#xA;$$&#xA;If $n$ is sufficiently high then the error is really small.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if we have function in two variables e.g. $f(x,y)$ we can expand it only in the first argument&#xA;$$&#xA;f(x,y) = \sum_{k=0}^\infty b_k(y) \, x^k&#xA;$$&#xA;where  $b_k(y)$ are functions only in $y$. It can be also expanded in both arguments&#xA;$$&#xA;f(x,y) = \sum_{k,l=0}^\infty c_{kl} x^k y^l&#xA;$$&#xA;where $c_{kl}$ are constants. So function with real arguments can be expanded as sum of powers of that argument. Something similar can be done for functions defined on sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, let's have a function defined on sphere e.g. $f(\omega)$. Such a function can be also expanded in similar fashion as function of one real parameter&#xA;$$&#xA;f(\omega) =\sum_{k=0}^\infty \alpha_k S_k(\omega)&#xA;$$&#xA;where $\alpha_k$ are constants and $S_k(\omega)$ are &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_harmonics&quot; rel=&quot;nofollow&quot;&gt;spherical harmonics&lt;/a&gt;. Spherical harmonics are normally indexed by two indices and are written as function in spherical coordinates but that is not important here. The important thing is that $f$ can be written as a sum of some known functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now function which takes two points on sphere e.g. $f(\omega,\omega')$ can be expanded only in its first arguments&#xA;$$&#xA;f(\omega,\omega') = \sum_{k=0}^\infty \beta_k(\omega') \, S_k(\omega)&#xA;$$&#xA;or in both its arguments&#xA;$$&#xA;f(\omega,\omega') = \sum_{k,l=0}^\infty \gamma_{kl} \, S_k(\omega)S_l(\omega')&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;So how is this all useful?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I propose the  &lt;strong&gt;CMUNSM&lt;/strong&gt;(Crazy mental useless no sampling method):&#xA;Lets assume that we have expansions for all the function i.e.&#xA;\begin{align}&#xA;f(\omega_i,\omega_o,n) &amp;amp;= \sum_{k,l,m=0}^\infty \alpha_{klm} S_k(\omega_i)S_l(\omega_o) S_m(n) \\&#xA;L(\omega_i ) &amp;amp;= \sum_{n=0}^\infty \beta_n S_n(\omega) \\&#xA;(\omega_i\cdot n)^+ &amp;amp;= \sum_{p,q=0}^\infty \gamma_{pq} S_p(\omega_i)S_q(n)&#xA;\end{align}&#xA;If we plug this into the integral we get&#xA;$$&#xA;I = \sum_{k,l,m,n,p,q=0}^\infty \alpha_{klm} \beta_n  \gamma_{pq} S_l(\omega_o) S_m(n) S_q(n) \int_{S^2} S_k(\omega_i) S_n(\omega)  S_p(\omega_i) d\omega_i&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Actually we no longer need Monte Carlo because we can calculate values of the integrals $\int_{S^2} S_k(\omega_i) S_n(\omega)  S_p(\omega_i) d\omega_i$ beforehand and then evaluate the sum(actually approximate the sum, we would sum only first few terms) and we get desired result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is all nice &lt;strong&gt;but&lt;/strong&gt; we might not know the expansions of BSDF or environmental map or the expansions converge very slowly therefore we would have to take a lots of terms in the sum to get reasonably accurate answer.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;So the idea is not to expand in all arguments. One method which might be worth investigating would be to ignore BSDF and expand only the environmental map i.e.&#xA;$$&#xA;L(\omega_i) \approx \sum_{n=0}^K \beta_n S_n(\omega_i)&#xA;$$&#xA;this would lead to pdf:&#xA;$$&#xA;p(\omega_i) \sim \sum_{n=0}^K \beta_n S_n(\omega_i) (\omega \cdot n)^+&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We already know how to do this for $K=0$, this is nothing but the &lt;strong&gt;method one&lt;/strong&gt;. My guess is, it is done in one of the papers for higher $K$.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Further extensions. You can expand different functions in different arguments and do similar stuff as above. Another thing is, that you can expand in different basis, i.e. do not use spherical harmonics but different functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So this is my take on the topic, I hope you have found it at least a little bit useful and now I'm off to GoT and bed.&lt;/p&gt;&#xA;" OwnerUserId="1613" LastActivityDate="2016-05-16T20:30:13.717" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2452" PostTypeId="2" ParentId="2450" CreationDate="2016-05-16T21:02:48.873" Score="18" Body="&lt;p&gt;Generally edge detection boils down to detect areas of the image with high gradient value. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In our case we can crudely see the gradient as the derivative of the image function, therefore the magnitude of the gradient gives you an information on &lt;em&gt;how much&lt;/em&gt; your image changes locally (in regards of neighbouring pixels/texels).&lt;br/&gt; Now, an edge is as you say an indication of discontinuity, so now that we defined the gradient is clear that this info is all we need. Once we find the gradient of an image, it's just a matter of applying a threshold to it to obtain a binary value edge/non-edge. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do you find this gradient is really what you are asking and I am yet to answer :) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lots of ways! Here a couple :) &lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Built in shader functions&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Both hlsl and glsl offer derivative functions. In GLSL you have &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/dFdx.xhtml&quot; rel=&quot;noreferrer&quot;&gt;dFdx and dFdy&lt;/a&gt; that give you respectively gradient information in x and y direction. Typically these functions are evaluated in a block of 2x2 fragments.&lt;br&gt;&#xA;Unless you are interested in a single direction, a good way to have a compact result that indicates how strong is the gradient in the region is &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/fwidth.xhtml&quot; rel=&quot;noreferrer&quot;&gt;fwidth&lt;/a&gt; that gives you nothing else but the sum of the absolute value of dFdy and dFdy. &lt;br&gt;You are likely to be interested in an edge on the overall image rather than on a specific channel, so you might want to transform your image function to luma. With this in mind,when it comes to edge detection your shader could include something to the like of:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  float luminance = dot(yourFinalColour,vec3(0.2126, 0.7152, 0.0722));&#xA;  float gradient = fwidth(luminance );&#xA;  float isEdge = gradient &amp;gt; threshold;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With an high threshold you will find coarser edges and you might miss some, conversely, with a low threshold you might detect false edges. You have to experiment to find the threshold that better suits your needs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;The reason why these functions work is worth mentioning but I don't have time for it now, I am likely to update this answer later on :)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Screen space post-process&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;You could go fancier than this, now the field of Edge detection in image processing is immense. I could cite you tens of good ways to detect edge detection according to your needs, but let's keep it simple for now, if you are interested I can cite you more options!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the idea would be similar to the one above, with the difference that you could look at a wider neighbourhood and use a set of weights on sorrounding samples if you want. Typically, you run a convolution over your image with a kernel that gives you as a result a good gradient info. &lt;br&gt; A very common choice is the Sobel kernel&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=&quot;https://i.stack.imgur.com/kXrkd.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kXrkd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which respectively give you gradients in x and y directions: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;https://i.stack.imgur.com/gCQgw.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gCQgw.png&quot; alt=&quot;From an old pdf I wrote a long time ago.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get the single value out of the gradient as $ GradientMagnitude = \sqrt{ (Gradient_x) ^ 2 + (Gradient_y) ^ 2 } $ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can threshold as the same way I mentioned above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This kernel as you can see give more weight to the central pixel, so effectively is computing the gradient + a bit of smoothing which traditionally helps (often the image is gaussian blurred to eliminate small edges). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above works quite well, but if you don't like the smoothing you can use the Prewitt kernels: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;https://i.stack.imgur.com/tQ5WJ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tQ5WJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Note I am in a rush, will write proper formatted text instead of images soon! )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Really there are plenty more kernels and techniques to find edge detection in an image process-y way rather than real time graphics, so I have excluded more convoluted (pun not intended) methods as probably you'd be just fine with dFdx/y functions. &lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="100" LastEditDate="2016-05-16T21:49:48.597" LastActivityDate="2016-05-16T21:49:48.597" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2453" PostTypeId="1" AcceptedAnswerId="2458" CreationDate="2016-05-17T08:15:04.127" Score="3" ViewCount="369" Body="&lt;p&gt;I know that fragments are rasterized in a 2x2 quad. That's why the seam between two triangles can be rasterized twice. At least &lt;a href=&quot;http://www.humus.name/index.php?page=Comments&amp;amp;ID=228&quot; rel=&quot;nofollow&quot;&gt;that article&lt;/a&gt; states this. I wonder is it still true today on modern hardware?&lt;/p&gt;&#xA;" OwnerUserId="386" LastActivityDate="2016-05-18T03:34:20.290" Title="Double rasterization work on triangles edges." Tags="&lt;rasterizer&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2454" PostTypeId="2" ParentId="2453" CreationDate="2016-05-17T15:45:12.903" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;That's why the seam between two triangles can be rasterized twice.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The seam won't be &lt;em&gt;rasterized&lt;/em&gt; twice because of the OpenGL or D3D fill/rasterisation rules. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I think Humus is alluding to is that a fragment shader may be executed multiple times on pixels spanning the shared edge, which just implies wasted effort.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The moral of the story is &quot;avoid small or long/thin triangles if you want efficient rendering&quot;.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2016-05-17T15:45:12.903" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2455" PostTypeId="1" AcceptedAnswerId="2475" CreationDate="2016-05-17T15:48:32.090" Score="2" ViewCount="88" Body="&lt;p&gt;I am going through code snippet that reads in a triangular model, calculates &amp;amp; store the normal with each Triangle object and eventually check the consistencies of winding order. Let us define a triangle with the vertices v1, v2 and v3. The face normal of the triangle is calculated as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void calculateFaceNormal()&#xA;{&#xA;   //vector from v3 to v1&#xA;   double dx13, dy13, dz13;&#xA;&#xA;   //vector from v3 to v2&#xA;   double dx23, dy23, dz23;&#xA;&#xA;    dx13 = v1.x_ - v3.x_;&#xA;    dy13 = v1.y_ - v3.y_;&#xA;    dz13 = v1.z_ - v3.z_;&#xA;&#xA;    dx23 = v2.x_ - v3.x_;&#xA;    dy23 = v2.y_ - v3.y_;&#xA;    dz23 = v2.z_ - v3.z_;&#xA;&#xA;    // Cross product gives normal.&#xA;    x_ = dy13*dz23 - dy23*dz13;&#xA;    y_ = dz13*dx23 - dz23*dx13;&#xA;    z_ = dx13*dy23 - dx23*dy13;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Each Triangle object store the references of its neighboring triangles as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class Triangle()&#xA;{&#xA;  public:&#xA;    .......&#xA;    .......&#xA;&#xA;    const Triangle *edge12Granne_;&#xA;    const Triangle *edge23Granne_;&#xA;    const Triangle *edge31Granne_;&#xA;&#xA;    bool isGranne12NormalConsistent() const;&#xA;    bool isGranne23NormalConsistent() const;&#xA;    bool isGranne31NormalConsistent() const;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now I am writing down only one of the functions whose definition is not clear to me and I believe that if someone could explain the theories behind it,I shall be able to understand the rest of the other two functions.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Triangle::isGranne12NormalConsistent() const&#xA;{&#xA;    // Find opposing vertex in neighbour.&#xA;    if (edge12Granne_-&amp;gt;edge12Granne_ == this)&#xA;    {&#xA;        /*&#xA;         * two triangle are neighbors to each other by&#xA;         * the adjecent edge that constitutes both the&#xA;         * triangles.&#xA;         * */&#xA;&#xA;        // v2 | w1&#xA;        // v1 | w2&#xA;        if (v1_.id_ == edge12Granne_-&amp;gt;v2_.id_)&#xA;        {&#xA;            // Ok (reversed order compared to this.)&#xA;            return true;&#xA;        }&#xA;        else&#xA;        {&#xA;            // Not ok, same order!&#xA;            return false;&#xA;        }&#xA;    }&#xA;    else if (edge12Granne_-&amp;gt;edge23Granne_ == this)&#xA;    {&#xA;        // v2 | w2&#xA;        // v1 | w3&#xA;        if (v1_.id_ == edge12Granne_-&amp;gt;v3_.id_)&#xA;        {&#xA;            // Ok (reversed order compared to this.)&#xA;            return true;&#xA;        }&#xA;        else&#xA;        {&#xA;            // Not ok, same order!&#xA;            return false;&#xA;        }&#xA;    }&#xA;    else&#xA;    {&#xA;        // v2 | w3&#xA;        // v1 | w1&#xA;        if (v1_.id_ == edge12Granne_-&amp;gt;v1_.id_)&#xA;        {&#xA;            // Ok (reversed order compared to this.)&#xA;            return true;&#xA;        }&#xA;        else&#xA;        {&#xA;            // Not ok, same order!&#xA;            return false;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="48" LastEditDate="2018-04-18T18:40:59.207" LastActivityDate="2018-04-18T18:40:59.207" Title="face normal consistencies" Tags="&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2456" PostTypeId="1" AcceptedAnswerId="2463" CreationDate="2016-05-17T16:33:28.920" Score="8" ViewCount="650" Body="&lt;p&gt;I have some experience programming geometry and compute shaders - but never adventured myself in really playing with the fragment shaders. Currently, I am trying to better understand how they work and their potential. One of the things I have read in multiple places is that a fragment (i.e. a screen pixel) cannot extend beyond itself within the fragment shader. Which means, a given fragment being iterated can only affect itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, and for the sake of learning, I would like to know if the following is possible (and if it is, how, in general lines, can it be achieved). Suppose we have, for the sake of simplicity, a point-mesh consisting of only two vertices (located in the 3D World space). Can we program a shader in a way such that each of these two vertices would be painted on screen at their exact WorldToViewport position, but also that a circle around each of them of radius=R is also painted in the surrounding pixels even if they extend beyond the original mesh to which the shader is attached? Like in the figure below (where the red square inthe center of the circles represents the vertices painted on screen):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GV3QO.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GV3QO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If that is possible, can a shader also be programmed in such a way that these circles that extend beyond the vertices influence the color (RGBA) of each other? Like in the figure below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CtdIW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CtdIW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I said, if these are possible things, I would love to hear a bit of how to achieve such a thing - either in conceptual or practical terms. Is it done in the fragment shader, or has to be calculated before at the vertex or geometry shaders? How to calculate and pass &quot;additional fragments&quot; that extend beyond those fragments occupied by the mesh body?&lt;/p&gt;&#xA;" OwnerUserId="3383" LastActivityDate="2016-05-21T17:55:41.620" Title="Can (and how so) shaders paint screen pixels beyond those that occupied by the shaded mesh?" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;pixel-shader&gt;&lt;drawing&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2457" PostTypeId="1" AcceptedAnswerId="2460" CreationDate="2016-05-17T23:55:45.460" Score="5" ViewCount="992" Body="&lt;p&gt;So I have been wanting to make a rendering engine as a summer project. I'd like to shoot for photo-realism of static scenes rather than real time dynamic game like graphics. So in my research I came across two major techniques for going about this. One is to attempt to directly solve the rendering equation with specialized numeric methods like bidirectional path tracing. Another is the well known ray tracing technique. Ray tracing is a) much simpler and b) more efficient. Additionally it seems as though some kind of interpolation/de-noising is needed to make the images look properly smooth when path tracing techniques are used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand recursive ray tracing to be an algorithm in which rays are shot out from the eye and collide with objects in the space. When they do more rays are shot from that point to calculate the lighting at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand path tracing to be trying to find paths to the viewing plane from light sources. If enough of these paths are sampled without bias then you can use these paths to perform monte carlo integration over the space using the found paths as your sample points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What effects are captured by path tracing that are not captured by ray tracing&lt;/p&gt;&#xA;" OwnerUserId="3385" LastActivityDate="2016-05-18T13:39:55.867" Title="What effects does path tracing capture that recursive ray tracing does not?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2458" PostTypeId="2" ParentId="2453" CreationDate="2016-05-18T03:34:20.290" Score="3" Body="&lt;p&gt;It is true to on today's GPUs, unless one or more vendors has implemented a technique such as this:&#xA;&lt;a href=&quot;http://graphics.stanford.edu/papers/fragmerging/shade_sig10.pdf&quot; rel=&quot;nofollow&quot;&gt;http://graphics.stanford.edu/papers/fragmerging/shade_sig10.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify, rasterization is not being done multiple times, or redundantly - rather it is the shading work that is done redundantly. Each 2x2 quad will be shaded once for every triangle that covers at least one sub pixel sample in that 2x2 quad. So, for 4x MSAA, that could be as many as 16 times if every sample covers a different (very small) triangle.&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-05-18T03:34:20.290" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2460" PostTypeId="2" ParentId="2457" CreationDate="2016-05-18T13:39:55.867" Score="11" Body="&lt;p&gt;Generally speaking, &lt;strong&gt;path tracing&lt;/strong&gt; removes a number of assumptions that ray tracing makes. Ray tracing usually assumes that there is no &lt;strong&gt;indirect lighting&lt;/strong&gt; (or that indirect lighting can be approximated by a constant function), because handling indirect lighting would require casting many additional rays whenever you shade an intersection point. Ray tracing usually assumes that there is no such thing as &lt;strong&gt;non-glossy reflection&lt;/strong&gt;, because while it is fairly easy to handle glossy/mirror reflection (you reflect the ray and continue with the raycast), if you have non-glossy specular reflection you have a problem very much like indirect lighting: you need to trace a bunch more rays and then do lighting wherever those rays hit. Ray tracing also usually assumes that there are no &lt;strong&gt;area lights&lt;/strong&gt;, because it is very cheap to cast a single ray towards a light to determine if an intersection point is in shadow, but if you have an area light you generally need to cast multiple rays towards different points on that light to determine the &lt;em&gt;amount&lt;/em&gt; that the intersection point is shadowed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And as soon as you need to break any of those assumptions with ray tracing, you now have a &lt;strong&gt;sampling problem&lt;/strong&gt;: you need to decide how to distribute the many additional rays you need to trace in order to get an accurate result that doesn't have noticeable aliasing.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2016-05-18T13:39:55.867" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2461" PostTypeId="1" CreationDate="2016-05-18T14:35:29.327" Score="7" ViewCount="985" Body="&lt;p&gt;I am trying to implement my own Gradient Domain Path Tracer by following the code of this guy who already implemented it: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/BachiLi/4f5c6e5a4fef5773dab1&quot; rel=&quot;noreferrer&quot;&gt;https://gist.github.com/BachiLi/4f5c6e5a4fef5773dab1&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already managed to go through various steps but I wanted to do something more. I expanded the code of in the reference by implementing next event estimation and here are some results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normal Path Tracer image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qPe9r.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qPe9r.jpg&quot; alt=&quot;Basic Path Tracer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gradient Domain resulting image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UyaZB.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UyaZB.png&quot; alt=&quot;Gradient Domain image without Next Event Estimation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Results are already good.. but as said before, I wanted something more. So I implemented Next Event Estimation and here is the result of the basic Path Tracer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HdUSm.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HdUSm.jpg&quot; alt=&quot;Path Tracer with NEE&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private Vector3 SampleWithNEE( Ray ray )&#xA;{&#xA;  // prepare&#xA;  Vector3 T = (1,1,1), E = (0,0,0), NL = (0,-1,0);&#xA;  int depth = 0;&#xA;  // random walk&#xA;  while (depth++ &amp;lt; MAXDEPTH)&#xA;  {&#xA;    // find nearest ray/scene intersection&#xA;    Scene.Intersect( ray );&#xA;    if (ray.objIdx == -1) break; //if there is no intersection&#xA;    Vector3 I = ray.O + ray.t * ray.D; //go to the Hit Point on the scene&#xA;    Material material = scene.GetMaterial( ray.objIdx, I );&#xA;    if (material.emissive) //case of a light&#xA;    {&#xA;        E += material.diffuse;&#xA;        break;&#xA;    }&#xA;    // next event estimation&#xA;    Vector3 BRDF = material.diffuse * 1 / PI;&#xA;    float f = RTTools.RandomFloat();&#xA;    Vector3 L = Scene.RandomPointOnLight() - I;&#xA;    float dist = L.Length();&#xA;    L = Vector3.Normalize( L );&#xA;    float NLdotL = Math.Abs( Vector3.Dot( NL, -L ) );&#xA;    float NdotL = Vector3.Dot( ray.N, L );&#xA;    if (NdotL &amp;gt; 0)&#xA;    {&#xA;        Ray r = new Ray( I + L * EPSILON, L, dist - 2 * EPSILON ); //make it a tiny bit shorter otherwise I risk to hit my starting and destination point&#xA;        Scene.Intersect( r );&#xA;        if (r.objIdx == -1) //no occlusion towards the light&#xA;        {&#xA;            float solidAngle= (nldotl * light.getArea()) / (dist * dist);&#xA;            E += T * (NdotL) * solidAngle * BRDF * light.emission;&#xA;        }&#xA;    }&#xA;    // sample random direction on hemisphere&#xA;    Vector3 R = DiffuseReflectionCosWeighted( ray.N );&#xA;    float hemi_PDF = Vector3.Dot( R, ray.N ) / PI;&#xA;    T *= (Vector3.Dot( R, ray.N ) / hemiPDF) * BRDF;&#xA;    ray = new Ray( I + R * EPSILON, R, 1e34f );&#xA;  }&#xA;  return E;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Things work really fine and the results are shown with the picture above. One more thing: I have only diffuse surfaces in my scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the problem is that in this method I use 2 kind of PDF's:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;one is given by randomly sampling the light in the Direct Lighting of the Next Event Estimation, indeed that &lt;strong&gt;SolidAngle&lt;/strong&gt; is our PDF, or better 1/PDF. &lt;/li&gt;&#xA;&lt;li&gt;while the second PDF is the one led by the use of &lt;strong&gt;DiffuseReflectionCosWeighted&lt;/strong&gt; which brings a PDF equals to &lt;strong&gt;CosTheta/PI&lt;/strong&gt;. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Everything fine so far and for any implementation detail you can just look at my code but problems come with my Gradient Domain Path Tracer. Indeed, there, as also in the reference link above implemented by Tzu-Mao Li, I need the &lt;em&gt;final probability density of a whole path&lt;/em&gt; to compute the final gradient image. How did I calculate it in case without Next Event Estimation (NEE) ? In that case (since I have only Diffuse surfaces) this probability is the product of &lt;strong&gt;CosTheta / PI&lt;/strong&gt; at each bounce in the scene. Everything is fine and the resulting gradient image is shown above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, in case I use NEE things don't work anymore because the Probability Density of my whole path changes and I don't manage to understand how it is. The resulting Gradient Domain Image with Next Event Estimation is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uTMGA.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uTMGA.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to understand how to calculate the final density probability of a path. Can you help me doing it? Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="3069" LastActivityDate="2016-05-29T00:53:36.330" Title="Resulting Probabilty Density in Path Tracer for paths using Next Event Estimation" Tags="&lt;rendering&gt;&lt;c++&gt;&lt;physically-based&gt;&lt;physics&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2462" PostTypeId="1" CreationDate="2016-05-19T01:19:21.283" Score="2" ViewCount="59" Body="&lt;p&gt;I have mapped four rectangular point(R1-&gt;R4) to four quadrilateral points(Q1-&gt;Q4) to generate a perspective view.&#xA;Now I have to translate quadrilateral in x and y direction while maintaing perspective view. How can I achieve this?&lt;/p&gt;&#xA;" OwnerUserId="2383" LastActivityDate="2016-05-19T01:19:21.283" Title="Perspective Translation Of Quadrilateral" Tags="&lt;perspective&gt;&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2463" PostTypeId="2" ParentId="2456" CreationDate="2016-05-19T12:21:51.260" Score="6" Body="&lt;p&gt;When you use linewidth or line antialiasing or pointwidth or pointsprites, OpenGL creates for you a small rectangle instead of the line or point, with texture coordinates. Nowadays you can even program this yourself using geometry shaders ot even the tesselator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A totally different approach is to use defered shading, using one geometric pass just to store information in the RGBAZ buffer, then a second pass than you run on all the pixels of the screen to do some process. (to act on all pixels, simply draw one full-screen rectangle).&#xA;Nowadays you can even do the first pass as one or several &quot;render to texture&quot;, then MIPmap these textures, so that the final pass can easily access to less local values.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastEditorUserId="1810" LastEditDate="2016-05-20T07:07:12.043" LastActivityDate="2016-05-20T07:07:12.043" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2464" PostTypeId="2" ParentId="95" CreationDate="2016-05-19T17:41:41.510" Score="2" Body="&lt;p&gt;Here's how I've solved this in the past:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Draw the first object (the one that should appear behind the other object) by depth testing but &lt;strong&gt;not&lt;/strong&gt; depth writing&lt;/li&gt;&#xA;&lt;li&gt;Draw the second object by depth testing and depth writing.  This won't cause z-fighting since we didn't write any depth in step 1.  &lt;/li&gt;&#xA;&lt;li&gt;Draw the first object by only writing to the depth buffer and &lt;strong&gt;not&lt;/strong&gt; to the color buffer. This makes sure the depth buffer is up to date for any pixels that are covered by object 1 but not by object 2.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Note, the objects need to be drawn consecutively for this to work.&lt;/p&gt;&#xA;" OwnerUserId="3332" LastEditorUserId="3332" LastEditDate="2016-05-20T13:51:31.210" LastActivityDate="2016-05-20T13:51:31.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2465" PostTypeId="2" ParentId="1662" CreationDate="2016-05-19T22:40:47.670" Score="6" Body="&lt;p&gt;The best place to put a look up table for a GPU compute shader depends on the size of the lookup table, and the frequency/coherency of access. In your case (you mentioned 4kb), shared local memory would likely be best (assuming you do not need this memory for other purposes in the same kernel). This memory has different names in different APIs, but is the same architectural thing and follows the same performance guidelines:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;CUDA: threadgroup shared memory&lt;/li&gt;&#xA;&lt;li&gt;DirectCompute: groupshared memory&lt;/li&gt;&#xA;&lt;li&gt;OpenCL: local memory&lt;/li&gt;&#xA;&lt;li&gt;Metal: threadgroup memory&lt;/li&gt;&#xA;&lt;li&gt;OpenGL: shared memory&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Storing the lookup table in global memory as a read-only buffer may perform just as well, depending on the cache size(s) of the particular GPU you're running on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that I'm presuming this is a read-only lookup table. A read-write lookup table is a completely different beast, and you don't have any good options there.&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-05-19T22:40:47.670" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2466" PostTypeId="1" CreationDate="2016-05-20T07:51:38.263" Score="3" ViewCount="31" Body="&lt;p&gt;Given a triangle mesh, does there exist any algorithm to compute a base mesh (smaller in size than the triangle mesh) that could be subdivided multiple times to get back the original mesh (or an approximate of the original) ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="3401" LastEditorUserId="3401" LastEditDate="2016-05-20T09:43:18.833" LastActivityDate="2016-05-20T09:43:18.833" Title="Constructing base mesh for required subdivision surface" Tags="&lt;compression&gt;&lt;subdivision&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2467" PostTypeId="1" CreationDate="2016-05-20T14:02:05.440" Score="3" ViewCount="675" Body="&lt;p&gt;Is there a way to make a difference between a photo of an actual object and a photo of an object through a computer or smartphone screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example: how can I detect that the second image is taken from a screen?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6aTf2.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6aTf2.jpg&quot; alt=&quot;Actual dog&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/6nH7M.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6nH7M.jpg&quot; alt=&quot;Screen dog&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you very much!&lt;/p&gt;&#xA;" OwnerUserId="3404" LastActivityDate="2016-05-21T09:26:25.177" Title="How to detect a screen in a photo" Tags="&lt;texture&gt;&lt;lighting&gt;&lt;color&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2468" PostTypeId="1" AcceptedAnswerId="2469" CreationDate="2016-05-20T14:41:18.767" Score="3" ViewCount="54" Body="&lt;p&gt;I am going though a functional source that has the following class:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt; class Point3D&#xA; {&#xA;       int x ,y,z;&#xA;&#xA;       int vSize2() const&#xA;       {&#xA;           return x*x +&#xA;                  y*y +&#xA;                  z*z;&#xA;       }&#xA;&#xA;&#xA;       int vSize() const&#xA;       {&#xA;         return sqrt(vSize2());&#xA;       }           &#xA; };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It is hard to understand the functionalities of the above two functions (&lt;code&gt;vSize2()&lt;/code&gt; and &lt;code&gt;vSize()&lt;/code&gt;). It seems to me that it is calculating the length between the point and the origin. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any thoughts?&lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="231" LastEditDate="2016-05-20T15:31:28.283" LastActivityDate="2016-05-20T15:52:07.877" Title="Does a point have a length?" Tags="&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2469" PostTypeId="2" ParentId="2468" CreationDate="2016-05-20T14:55:55.117" Score="5" Body="&lt;p&gt;No, a point does not have a length. A point is only a location - it has no extent in any direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You are correct in guessing that the function &lt;code&gt;vSize()&lt;/code&gt; returns the distance from the origin to the point. The other function, &lt;code&gt;vSize2()&lt;/code&gt; returns the square of that distance. This is used in calculating the distance, and in some cases it may be useful to work directly with the square of the distance instead of the distance. This avoids calculating square roots, so can lead to improvements in speed and accuracy.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Note that as Nero points out, the functions are using only &lt;code&gt;int&lt;/code&gt;s (integer variables and return values). The distance between a point and the origin is not in general an integer value, even if the coordinates of the point are all integers. The distance squared returned by &lt;code&gt;vSize2()&lt;/code&gt; will be accurate, but the distance itself returned by &lt;code&gt;vSize()&lt;/code&gt; will be accurate only to the nearest integer.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-05-20T15:52:07.877" LastActivityDate="2016-05-20T15:52:07.877" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2470" PostTypeId="2" ParentId="2467" CreationDate="2016-05-21T09:26:25.177" Score="4" Body="&lt;p&gt;The first things I would try is to see if smartphone pixels are visible (if the photo is high res) or if strange aliasing occurs (your example image shows both). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another classical test (but not adapted to any scenes) is to detect perspective bias: if the camera is not exactly parallel to the smartphone screen, then 3D objects projected on the image on screen are projected again to the camera captor through a slightly different perspective. If the scene contains spheres, discs (physical or as reflects, for instance), perpendicular angles, or any similar invariant, then you can detect this.   (this kind of trick is also used to detect images photoshoped by composition of several images).&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-05-21T09:26:25.177" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2471" PostTypeId="1" CreationDate="2016-05-21T11:04:09.310" Score="1" ViewCount="680" Body="&lt;p&gt;I have some problem in OSG doing my model, which need an rectangular prism, that I do not know the parametric equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to search with the google, but no usable result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also tried to draw it by using this site: &lt;a href=&quot;http://www.math.uri.edu/~bkaskosz/flashmo/tools/parsur/&quot; rel=&quot;nofollow&quot;&gt;http://www.math.uri.edu/~bkaskosz/flashmo/tools/parsur/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could somebody help to find the parametric equation for (x,y,z) cordinates&lt;/p&gt;&#xA;" OwnerUserId="3408" LastActivityDate="2016-05-21T14:50:40.573" Title="Rectangular prism parametric equation" Tags="&lt;scene-graph&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2472" PostTypeId="1" CreationDate="2016-05-21T14:03:10.723" Score="2" ViewCount="658" Body="&lt;p&gt;I'm recently implementing Phong materials in my path tracer. My implementation of a randomly sampled Phong material works and looks fine. But it doesn't work well if the shininess(aka power) is too high. So I tried to implement an importance sampled Phong material. It also looks fine. &lt;br&gt;&#xA;However, when I compared the random sampled Phong material to the importance sampled one. Both material looks the same if the shininess is high, but the importance sampled one looks darker if the shininess is low. Why? Where am I doing wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Picture 1. Random sampled Phong surface(left)/importance sampled Phong surface(right), both shininess ware set to 0 (3500 SPP, naive path tracing). The importance sampled  surface is too dark.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/fqgRS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fqgRS.png&quot; alt=&quot;Random sampled vs Importance sampled, power = 0&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Picture 2. andom sampled Phong surface(left)/importance sampled Phong surface(right), both shininess ware set to 23 (6700 SPP, naive path tracing). Both surface looks identical.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/KW0ng.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KW0ng.png&quot; alt=&quot;Random sampled vs Importance sampled, power = 23&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code.&lt;br&gt;&#xA;1.The code that samples the Phong BRDF randomly&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void PhongMaterial::createSample(const Ray&amp;amp; ray, float4 normal, float4 intersection, Ray&amp;amp; sampleRay, float4&amp;amp; coefficient)&#xA;{&#xA;    sampleRay = createRandomReflect(normal,intersection);&#xA;    float4 reflectDirection = reflect(ray.direction,normal);&#xA;    coefficient = reflectColor * pow(dot(sampleRay.direction,reflectDirection),power+1)&#xA;        *(float)((power+1));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;2.The code that importance samples the Phong BRDF&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void PhongMaterial::createImportanceSample(const Ray&amp;amp; ray, float4 normal, float4 intersection, Ray&amp;amp; sampleRay, float4&amp;amp; coefficient)&#xA;{&#xA;    float4 reflectDirection = reflect(ray.direction,normal);&#xA;    float2 rnd(rand1(),rand1());&#xA;    float phi = 2.0f*M_PI*rnd.x;&#xA;    float theta = acos(pow(rnd.y,1.0f/(power+1.f)));&#xA;    float4 rotX,rotY;&#xA;    ons(reflectDirection,rotX,rotY);&#xA;    float4 result = cos(phi)*sin(theta)*rotX&#xA;        + sin(phi)*sin(theta)*rotY&#xA;        + cos(theta)*reflectDirection;&#xA;    sampleRay.origin = intersection + result*0.00001f;&#xA;    sampleRay.direction = result;&#xA;&#xA;    coefficient = reflectColor*(float)((power+1)/(power+2));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;ray&lt;/code&gt; is the incoming ray, &lt;code&gt;normal&lt;/code&gt; is the surface normal, &lt;code&gt;intersection&lt;/code&gt; is where the ray and the surface intersects, &lt;code&gt;coefficient&lt;/code&gt; is light transmit coefficient and &lt;code&gt;power&lt;/code&gt; is the shininess.&lt;br&gt;&#xA;Also, &lt;code&gt;ons&lt;/code&gt; creates two vector perpendicular to the rest from a single vector(the first parameter).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where am I doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="2448" LastEditDate="2016-05-21T15:46:22.470" LastActivityDate="2016-05-21T15:46:22.470" Title="How to properly implement Phong material and importance sample it in a path tracer?" Tags="&lt;brdf&gt;&lt;pathtracing&gt;&lt;sampling&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2474" PostTypeId="2" ParentId="2471" CreationDate="2016-05-21T14:34:32.753" Score="1" Body="&lt;p&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/Prism_%28geometry%29&quot; rel=&quot;nofollow&quot;&gt;prism&lt;/a&gt; is a polyhedron with a polygonal base, another parallel base of the same shape, and joining faces between corresponding edges of the two base faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The word &quot;prism&quot; is commonly used to describe a right prism with base faces perpendicular to the joining faces. In this case the joining faces are also rectangles, and so a rectangular right prism is simply a &lt;a href=&quot;https://en.wikipedia.org/wiki/Cuboid&quot; rel=&quot;nofollow&quot;&gt;cuboid&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A cuboid can be described directly, but a simple way to generate one is to start with a cube and use directional &lt;a href=&quot;https://en.wikipedia.org/wiki/Scaling_%28geometry%29&quot; rel=&quot;nofollow&quot;&gt;scaling&lt;/a&gt; to give the edges the required lengths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the base faces are not perpendicular to the joining faces, this oblique prism can be achieved by applying a &lt;a href=&quot;https://en.wikipedia.org/wiki/Shear_mapping&quot; rel=&quot;nofollow&quot;&gt;shear&lt;/a&gt; to a cuboid with the required edge lengths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So all you need is a parametric description of a cube, and you can go from there to any rectangular prism required.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;As joojaa points out, there isn't an easy way to describe a prism (including a cube) in just a single parametrisation. You will need to describe each face with a separate set of parametric equations. For example, using parameters u and v, you could describe one of the faces as follows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$  x=u  \\  y=v  \\  z=1  \\  0 \leq u \leq 1  \\  0 \leq v \leq 1  $$&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-05-21T14:50:40.573" LastActivityDate="2016-05-21T14:50:40.573" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2475" PostTypeId="2" ParentId="2455" CreationDate="2016-05-21T17:08:55.753" Score="2" Body="&lt;p&gt;The function in your third code snippet is checking for the winding order to be consistent between two neighboring triangles. It does this by looking at the order in which vertices are listed in their shared edge. If the two triangles have consistent winding (both counterclockwise for instance), they will have opposite orientations for the shared edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A diagram may help see this:&#xA;&lt;img src=&quot;https://i.stack.imgur.com/JSz6H.png&quot; alt=&quot;diagram of two triangles with vertex winding&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vertex order is indicated by the blue arrows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;t0: v0, v1, v2&#xA;t1: v1, v3, v2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you look at the shared edge (v1&amp;ndash;v2), it appears in the first triangle with order &lt;code&gt;v1, v2&lt;/code&gt;, and in the other with order &lt;code&gt;v2, v1&lt;/code&gt; (cycling around the end of the vertex list back to the beginning).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The function in your snippet takes a triangle and looks at one of its neighbors, checks all three possibilities for which edge in the second triangle is the shared one, and checks that the vertices in that (other triangle's) edge appear in the reverse order to the vertices in the current triangle's edge. It returns true if this is the case, and false otherwise.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-21T17:08:55.753" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2476" PostTypeId="2" ParentId="2456" CreationDate="2016-05-21T17:55:41.620" Score="3" Body="&lt;p&gt;One good way you can arrange for a circle (or other shape) to be drawn for each vertex in a mesh is to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Geometry_instancing&quot; rel=&quot;nofollow&quot;&gt;geometry instancing&lt;/a&gt;. This is a GPU feature that allows multiple instances (copies) of a mesh to be drawn at once, with the vertices/indices of the mesh given by one set of buffers, and another vertex buffer that can give additional data per-instance. The vertex shader can be used to combine the data from both buffers in whatever way you choose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be concrete, in your case you could create a mesh representing a circle of the desired radius, with its vertices specified directly in screen-space coordinates and centered at the origin. Then you'd use instancing to make the GPU render a new copy of the circle mesh for every vertex of your original point-mesh. In the vertex shader, you'd calculate the screen-space position of the point (using the world-view-projection transforms as usual), then translate the circle mesh to be centered at that position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the second part of your question, on how to have the circles influence each other's color: it depends on what you want to do, specifically. Hardware blending can be used to handle simple cases, such as adding or multiplying the colors, or alpha-blending. If you want something more complicated than that, then it might be possible to do it with a multi-pass algorithm, or (on the latest GPUs) programmable blending.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-21T17:55:41.620" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2477" PostTypeId="2" ParentId="2391" CreationDate="2016-05-21T18:24:35.543" Score="6" Body="&lt;p&gt;This is not a full answer, I would just like to share the knowledge I obtained by studying two of the papers mentioned in the question: &lt;a href=&quot;http://home.eps.hw.ac.uk/~ks400/research.html#SteerableImportance&quot; rel=&quot;noreferrer&quot;&gt;Steerable Importance Sampling&lt;/a&gt; and &lt;a href=&quot;http://fileadmin.cs.lth.se/graphics/research/papers/2008/pps/&quot; rel=&quot;noreferrer&quot;&gt;Practical Product Importance Sampling for Direct Illumination&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Steerable Importance Sampling&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;In this paper they propose a method for sampling the product of the clamped cosine component and environment map lighting:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;L_{EM}\left(\omega_{i}\right)\left(\omega_{i}\cdot n\right)^+&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They make use of the fact that a piece-wise linear approximation of the product function can be relatively well expressed and partially pre-computed using the first nine spherical harmonic bases. They build this approximation on top of an adaptively triangulated EM and use it as an importance function for sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They pre-compute and store approximation coefficients for each triangle vertex and also coefficients for computation of approximation integral over the triangle for each triangle. These coefficients are called vertex and triangle weights. Then they make use of the fact that is it possible to easily compute coefficients for an integral over a set of triangles just by summing the individual triangle weights without incorporating additional spherical harmonic bases. This allows them to build a balanced binary tree over the triangles where each node contains coefficients for computing approximation integral over the node's sub-tree triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sampling procedure consists of selecting a triangle and sampling its area:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A triangle is chosen by descending down the pre-built binary tree    with probability proportional to the sub-integral approximations. This costs $O\left(\log N_{\triangle}\right)$ on-the-fly computations of sub-integrals, each consisting of one inner product of clamped-cosine spherical harmonic coordinates with the pre-computed coefficients.   &lt;/li&gt;&#xA;&lt;li&gt;The chosen triangle surface is then sampled in $O\left(1\right)$ time in a    bi-linear fashion by a novel stratified sampling strategy proposed in    the paper.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;To me, this looks like a &lt;strong&gt;promising technique&lt;/strong&gt;, but the classical question with papers is how it will behave in the real life. On the one hand, there may be pathological cases when the EM is hard to approximate with triangulated piece-wise linear function, which can lead to an enormous amount of triangles and/or to poor sample quality. On the other hand, it can instantly provide a relatively good approximation of the whole EM contribution, which can be useful when sampling multiple light sources.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Practical Product Importance Sampling for Direct Illumination&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;In this paper they propose a method for sampling the product of environment map lighting and cosine-weighted surface reflectance:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;L_{EM}\left(\omega_{i}\right)f_{r}\left(\omega_{i},\omega_{o},n\right)\left(\omega_{i}\cdot n\right)^+&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only pre-processing in this method is computation of a hierarchical representation of the EM (either mipmap or wavelet based). The rest is done on the fly during the sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sampling procedure:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Building an on-the-fly BRDF approximation: They first draw several BRDF importance samples and evaluate $f_{r}\left(\omega_{i},\omega_{o},n\right)\left(\omega_{i}\cdot n\right)^+$. From these values they build a quadtree-based piece-wise constant approximation of the BRDF, where each leaf of the tree contains exactly one sample.&lt;/li&gt;&#xA;&lt;li&gt;Computing a product of the BRDF approximation and the EM: Multiplication is done at the BRDF quadtree leaves and averaged values are propagated to parents.&lt;/li&gt;&#xA;&lt;li&gt;Product sampling: uniform samples are fed through the product tree using simple sample warping.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The procedure should generate relatively good samples at the cost of heavy pre-computation &amp;ndash; they show that roughly 100&amp;ndash;200 BRDF samples are needed for BRDF approximation to achieve the best sampling performance. This may make it suitable for purely direct illumination computations, where one generates many samples per shading point, but is most probably &lt;strong&gt;too expensive for global illumination algorithms&lt;/strong&gt; (e.g. uni- or bi-directional path tracers), where you usually generate only a few samples per shading point.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-05-21T19:29:57.323" LastActivityDate="2016-05-21T19:29:57.323" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2478" PostTypeId="1" AcceptedAnswerId="2479" CreationDate="2016-05-21T21:56:59.703" Score="2" ViewCount="176" Body="&lt;p&gt;First of all, let me explain what I am really trying to achieve. In a post-effect shader acting on a camera-renderer, I want to change the color of each fragment  depending on how many green (RGBA = 0,~1,0,1) fragments there are nearby.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, for the sake of simplicity, let's imagine my screen is all black, with some (~10k) green points spread around. In the fragment shader, for each fragment I have to find how many green fragments there are within a given distance and then change the color of the current fragment being evaluated depending on that number of surrounding green fragments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I began with the most naïve approach one could think of: for each fragment, I calculated the coordinates of the 10th neighbor fragments to each side: right, left, up and down (which gives a surrounding square, then I discarded the corners from the computation to get a surrounding circle of radius ~10pixels, centered at the current fragment). Then I tested which of the fragments within such &quot;surrounding bounding circle&quot; was green (i.e. color.g &gt; 0.9f). In affirmative case, I increased a counter variable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my way of thinking, that would be doing a brute force and in order to visualize the result, I then painted each fragment with the RGBA color (counter*0.1f, 0, counter*0.1f, 1). Here is the code snippet:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler2D _MainTex;&#xA;static float2 _Pixels = float2(_ScreenParams.x, _ScreenParams.y); //gets the Screen width and height&#xA;static half sx = 1 / _ScreenParams.x; //defines the measure of a fragment at the X axis of the viewport&#xA;static half sy = 1 / _ScreenParams.y; //defines the measure of a fragment at the Y axis of the viewport&#xA;&#xA;float4 frag(v2f_img input) : COLOR{&#xA;fixed2 uv = round(input.uv * _Pixels) / _Pixels;&#xA;&#xA;float counter = 0.0f;&#xA;float i; float j;&#xA;float thrsh = 0.8f;&#xA;&#xA;[unroll(10)]for (i = zero; i&amp;lt;10;i++) //loop trough 10 fragments horizontally&#xA;{&#xA;    [unroll(10)]for (j = zero; j &amp;lt; 10; j++) //loop trough 10 fragments vertically&#xA;    {&#xA;        //the following lines cut (very roughly) the corners of the surrounding square ixj to approximate a surrounding circle of radius ~10fragments. But this is less important: if such lines are commented, the problem that I will show later will still happen, just with a surrounding square instead of a surrounding circle&#xA;        if ((i == 4 || i == 5) &amp;amp;&amp;amp; j &amp;gt; 9) j = 0; else if ((i == 6) &amp;amp;&amp;amp; j &amp;gt; 8) j = 0; else if ((i == 7) &amp;amp;&amp;amp; j &amp;gt; 7) j = 0;&#xA;        else if ((i == 8) &amp;amp;&amp;amp; j &amp;gt; 6) j = 0; else if ((i == 9) &amp;amp;&amp;amp; j &amp;gt; 5) j = 0; else if (i == 10 &amp;amp;&amp;amp; j &amp;gt; 4) j = 0;&#xA;&#xA;        else if (j &amp;gt; 0) { //so, let's continue only if current iteration does not relate to the corners of the surrounding square, i.e. outside the surrounding circle with radius ~10 fragments&#xA;&#xA;            float tl = tex2D(_MainTex, uv + fixed2(-sx*i, +sy*j)).g; //gets the top-left neighbor times i and j&#xA;            float cl = tex2D(_MainTex, uv + fixed2(-sx*i, 0)).g; //gets the center-left neighbor times i and j&#xA;            float bl = tex2D(_MainTex, uv + fixed2(-sx*i, -sy*j)).g; //gets the bottom-left neighbor times i and j&#xA;            float tc = tex2D(_MainTex, uv + fixed2(0, +sy*j)).g; //gets the top-center neighbor times i and j&#xA;            float cc = tex2D(_MainTex, uv + fixed2(0, 0)).g;  //gets the current fragment bein evaluated (i.e. center-center)&#xA;            float bc = tex2D(_MainTex, uv + fixed2(0, -sy*j)).g;  //gets the bottom-center neighbor times i and j&#xA;            float tr = tex2D(_MainTex, uv + fixed2(+sx*i, +sy*j)).g; //gets the top-right neighbor times i and j&#xA;            float cr = tex2D(_MainTex, uv + fixed2(+sx*i, 0)).g; //gets the center-right neighbor times i and j&#xA;            float br = tex2D(_MainTex, uv + fixed2(+sx*i, -sy*j)).g;  //gets the bottom-right neighbor times i and j&#xA;&#xA;            //Now, for each fragment surrounding that is above the Green threshold, we increase the counter&#xA;                if (tl &amp;gt; thrsh) counter++;&#xA;                if (cl &amp;gt; thrsh) counter++;&#xA;                if (bl &amp;gt; thrsh) counter++;&#xA;                if (tc &amp;gt; thrsh) counter++;&#xA;                if (bc &amp;gt; thrsh) counter++;&#xA;                if (tr &amp;gt; thrsh) counter++;&#xA;                if (cr &amp;gt; thrsh) counter++;&#xA;                if (br &amp;gt; thrsh) counter++;&#xA;&#xA;        }&#xA;    }&#xA;&#xA;}&#xA;&#xA;&#xA;if (counter &amp;gt; 0)&#xA;{&#xA;    return float4(counter *0.1f, 0, counter *0.1f, 1); //in case at least one surrounding fragment was green, paint the fragments pink-ish in proportion to how many green there were in the surrounding circle&#xA;} else {&#xA;    return tex2D(_MainTex, float4(0,0,0,1)); //otherwise, paint black&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, besides &lt;strong&gt;very&lt;/strong&gt; inefficient, the solution above is also not working correctly. Obvioulsy, I was expecting to get, around each green point at the screen, something like a pink-ish circle that is of stronger intensity when close to the center and fades away at the border, i.e. away from the center. Instead, this is what I get (in actual and zoomed sizes):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Tsef3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Tsef3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I tried everything I could think of but I don't get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) why it is not working properly. What am I doing wrong? Could anyone shed some light?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) also, if there is any obvious more performant way of achieving what I want, please do let me know too (the current solution is taking 12ms in a non HD resolution). Or if you prefer, I can come with a different question for that later, after the operational problem described above is solved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks anyways for your time.&lt;/p&gt;&#xA;" OwnerUserId="3410" LastActivityDate="2016-05-22T01:01:30.820" Title="Count number of green fragments that are within a given distance from each screen fragment" Tags="&lt;shader&gt;&lt;geometry&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2479" PostTypeId="2" ParentId="2478" CreationDate="2016-05-22T01:01:30.820" Score="3" Body="&lt;p&gt;You're getting a cross shape in the output because in your loop, you're counting pixels on the center row and column multiple times. For example the pixel at (0, 0) offset will be counted on every iteration of the inner loop, so 100 times. Similarly, (&amp;pm;i, 0) and (0, &amp;pm;i) will be counted on every iteration of the inner loop, so 10 times for each value of i.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A better way to write the loop is like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[unroll] for (int i = -10; i &amp;lt;= 10; i++)&#xA;{&#xA;    [unroll] for (int j = -10; j &amp;lt;= 10; j++)&#xA;    {&#xA;        float sample = tex2D(_MainTex, input.uv + float2(sx*i, sy*j)).g;&#xA;        if (sample &amp;gt; thrsh) counter++;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This will weight all pixels equally within a box. To make a more circular shape you can change the &lt;code&gt;j&lt;/code&gt; iteration bounds based on the value of &lt;code&gt;i&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I doubt you need or want to round off &lt;code&gt;uv&lt;/code&gt; to the nearest pixel as you're doing. The UVs coming into the fragment shader should already be correct, and moreover they are not multiples of the pixel size; they are the coordinates of pixel &lt;em&gt;centers&lt;/em&gt;, so they contain a half-pixel offset (which is exactly what you want for sampling a screen-sized texture).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a more efficient algorithm, you could downsample the original image 2x, then run a 5px-radius neighbor search on that one instead of a 10px-radius search on the original. This will make the circle shape somewhat less precise but depending on what you're doing, it may not matter that much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another approach that's less brute-force but still precise would be to build a spatial hierarchy of the green points. This could be as simple as a uniform grid where each grid square stores a list of the points inside it, or as complicated as a kd-tree. Your fragment shader could then walk this data structure to efficiently search the nodes within a radius of the fragment, and count the points it finds.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-22T01:01:30.820" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2480" PostTypeId="1" AcceptedAnswerId="2481" CreationDate="2016-05-22T15:05:30.210" Score="6" ViewCount="1103" Body="&lt;p&gt;So I have a game and I am trying to fake glow inside of it by using the hardwares capability to downsize textures causing them to blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The texture I wish to do this with is in a render buffer that is the size of the screen (not power of two)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What would be the quickest way to get these lower resolutions created?&#xA;Tricking the software to make minimaps?&#xA;Another fbo with the texture rendered on it in smaller size?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2017-11-21T20:24:39.830" Title="Generation of lower resolution textures" Tags="&lt;opengl&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2481" PostTypeId="2" ParentId="2480" CreationDate="2016-05-22T16:37:02.623" Score="6" Body="&lt;p&gt;I would think rendering to a downsampled FBO would be much faster than generating mipmaps.  glGenerateMipmap will generate the complete mipmap pyramid, which seems wasteful:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenerateMipmap.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGenerateMipmap.xml&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Besides, only OpenGL ES 3.0 lets you manually select mip level when texturing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengles/sdk/docs/man3/html/textureLod.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengles/sdk/docs/man3/html/textureLod.xhtml&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Artistically, this might not give you the look you want.  In my experience, simply downsampling gives a grainy look.  I would recommend also doing a pair of one-dimensional blurs, as described in this article from GPU Gems:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch21.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://developer.download.nvidia.com/books/HTML/gpugems/gpugems_ch21.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastEditorUserId="6172" LastEditDate="2017-11-21T20:24:39.830" LastActivityDate="2017-11-21T20:24:39.830" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2482" PostTypeId="1" AcceptedAnswerId="2483" CreationDate="2016-05-23T02:54:29.953" Score="14" ViewCount="2735" Body="&lt;p&gt;I am trying to implement refraction and transmission in my path tracer and I'm a bit unsure on how to implement it. First, some background:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When light hits a surface, a portion of it will reflect, and a portion will be refracted:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2oBo9.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2oBo9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How much light reflects vs. refracts is given by the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;noreferrer&quot;&gt;Fresnel Equations&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cYrKH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cYrKH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a recursive ray tracer, the simple implementation would be to shoot a ray for reflection and a ray for refraction, then do a weighted sum using the Fresnel.&#xA;$$\begin{align*}&#xA;R &amp;amp;= Fresnel()\\&#xA;T &amp;amp;= 1 - R\\&#xA;L_{\text{o}} &amp;amp;= R \cdot L_{\text{i,reflection}} + T \cdot L_{\text{i,refraction}}&#xA;\end{align*}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in path tracing, we only choose one path. This is my question:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I choose whether to reflect or refract in a non-biased way&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My first guess would be to randomly choose based on the Fresnel. Aka:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float p = randf();&#xA;float fresnel = Fresnel();&#xA;if (p &amp;lt;= fresnel) {&#xA;    // Reflect&#xA;} else {&#xA;    // Refract&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Would this be correct? Or do I need to have some kind of correction factor? Since I'm not taking both paths.&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-05-24T11:25:59.273" Title="Choosing Reflection or Refraction in Path Tracing" Tags="&lt;brdf&gt;&lt;pathtracing&gt;&lt;reflection&gt;&lt;refraction&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2483" PostTypeId="2" ParentId="2482" CreationDate="2016-05-23T08:04:39.000" Score="7" Body="&lt;h2&gt;TL;DR&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Yes, you can do it like that, you just have to divide the result by the probability of choosing the direction.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Full Answer&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The topic of sampling in path tracers allowing materials with both reflection and refraction is actually a little bit more complex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's start with some background first. If you allow BSDFs - not just BRDFs - in your path tracer, you have to integrate over the whole sphere instead of just the positive hemisphere. Monte Carlo samples can be generated by various strategies: for the direct illumination you can use BSDF and light sampling, for the indirect illumination the only meaningful strategy usually is the BSDF sampling. The sampling strategies themselves usually contain the decision about which hemisphere to sample (e.g. whether reflection or refraction is computed).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the simplest version, the light sampling usually doesn't take care much about reflection or refraction. It samples the light sources or the environment map (if present) with respect to the light properties. You can improve sampling of environment maps by picking just the hemisphere in which the material has non-zero contribution, but the rest of the material properties is usually ignored. Note that for and ideally smooth Fresnel material the light sampling doesn't work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For BSDF sampling, the situation is much more interesting. The case you described deals with an ideal Fresnel surface, where there are only two contributing directions (since Fresnel BSDF is in fact just a sum of two delta functions). You can easily split the integral into a sum of two parts - one reflection and one for refraction. Since, as you mentioned, we don’t want to go in both directions in a path tracer, we have to pick one. This means that we want to estimate the sum of numbers by picking just one of them. This can be done by discrete Monte Carlo estimation: pick one of the addends randomly and divide it by the probability of it being picked. In an ideal case you want to have the sampling probability proportional the the addends, but since we don't know their values (we wouldn't have to estimate the sum if we knew them), we just estimate them by neglecting some of the factors. In this case, we ignore the incoming light amount and use just the Fresnel reflectance/transmittance as our estimates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The BSDF sampling routine for the case of smooth Fresnel surface is, therefore, to pick one of the directions randomly with probability proportional to the the Fresnel reflectance and, at some point, divide the result for that direction by probability of picking the direction. The estimator will look like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\frac&#xA;   {L_{i}\left(\omega_{i}\right)F\left(\theta_{i}\right)}&#xA;   {P\left(\omega_{i}\right)} =&#xA;\frac&#xA;   {L_{i}\left(\omega_{i}\right)F\left(\theta_{i}\right)}&#xA;   {F\left(\theta_{i}\right)} =&#xA;L_{i}\left(\omega_{i}\right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $\omega_{i}=\left( \phi_{i}, \theta_{i} \right)$ is the chosen incident light direction, $L_{i}\left(\omega_{i}\right)$ is the amount of incident radiance, $F\left(\theta_{i}\right)$ is either the Fresnel reflectance for the reflection case or 1 - Fresnel reflectance for the refraction case, $P\left(\omega_{i}\right)$ is the discrete probability of picking the direction and is equal to $F\left(\theta_{i}\right)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case of more sophisticated BSDF models like those based on microfacet theory, the sampling is slightly more complex, but the idea of splitting the whole integral into a finite sum of sub-integrals and using discrete Monte Carlo afterwards can usually be applied too.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-05-24T11:25:59.273" LastActivityDate="2016-05-24T11:25:59.273" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="2484" PostTypeId="1" AcceptedAnswerId="2485" CreationDate="2016-05-23T11:32:16.083" Score="9" ViewCount="421" Body="&lt;p&gt;In &lt;a href=&quot;https://www.roiatalla.com/public/arcsynthesis/Basics/Intro%20Graphics%20and%20Rendering.html&quot; rel=&quot;noreferrer&quot;&gt;this tutorial&lt;/a&gt;,&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;It is very often the case that triangles are rendered that share&#xA;edges. OpenGL offers a guarantee that, so long as the shared edge&#xA;vertex positions are identical, there will be no sample gaps during&#xA;scan conversion.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;1 What exactly are sample gaps during scan conversion?&lt;/p&gt;&#xA;&lt;p&gt;2 Under what circumstances, will it happen?&lt;/p&gt;&#xA;&lt;p&gt;3 Does it happen when the line cross the center of the fragment?&lt;/p&gt;&#xA;" OwnerUserId="3416" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-01-12T04:28:05.290" Title="What are sample gaps during scan conversion?" Tags="&lt;opengl&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2485" PostTypeId="2" ParentId="2484" CreationDate="2016-05-23T11:55:20.703" Score="8" Body="&lt;p&gt;Sample gaps will occur if you don't do things &quot;properly&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL or D3D, assuming a consistent winding order, if you have triangles  ABC and CBD, then when a sample point - that is a test during scan conversion to determine if a point (read pixel) is inside a triangle - lies &lt;em&gt;exactly&lt;/em&gt; on the shared edge BC, then that sample will belong to &lt;em&gt;exactly one&lt;/em&gt; of those two triangles. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This avoids both gaps &lt;em&gt;and&lt;/em&gt; double filling. The latter would be problematic with, say, translucency or stencil operations.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-01-03T08:28:59.960" LastActivityDate="2018-01-03T08:28:59.960" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2486" PostTypeId="1" AcceptedAnswerId="2487" CreationDate="2016-05-24T04:25:05.057" Score="8" ViewCount="878" Body="&lt;p&gt;I have been studying hardware corporation GPU profilers in recent days (Qualcomm, PowerVR, Intel).  I've noticed that these tools seem to give more low-level details  than the GPU profilers I have used in the past -- XCode's OpenGL ES frame capture and apitrace -- which only listed which OpenGL calls were made and what the state of current resources are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I get started if I want to make a low-level tool that displays things like sampler cache misses and shader assembler code?&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastActivityDate="2016-05-24T05:06:18.593" Title="How to get started writing a low-level GPU profiler?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2487" PostTypeId="2" ParentId="2486" CreationDate="2016-05-24T05:06:18.593" Score="6" Body="&lt;p&gt;For basic GPU timing data, you can use &lt;a href=&quot;http://www.reedbeta.com/blog/2011/10/12/gpu-profiling-101/&quot;&gt;D3D timestamp queries&lt;/a&gt; or the equivalent &lt;a href=&quot;https://www.opengl.org/wiki/Query_Object#Timer_queries&quot;&gt;OpenGL timer queries&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any low-level hardware data like cache misses is going to be extremely vendor-specific. Each GPU vendor has its own custom API or extension for giving access to low-level performance data on its hardware. The APIs vary in how they work, and they don't necessarily all expose the same details. The available data may also vary between different chip models within the same vendor, so you probably need to know a bit about how the hardware works to make sense of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are links to the relevant APIs for most of the main GPU vendors.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;AMD: &lt;a href=&quot;http://developer.amd.com/tools-and-sdks/graphics-development/gpuperfapi/&quot;&gt;GPUPerfAPI&lt;/a&gt;; see also &lt;a href=&quot;https://www.opengl.org/registry/specs/AMD/performance_monitor.txt&quot;&gt;AMD_performance_monitor&lt;/a&gt; &lt;/li&gt;&#xA;&lt;li&gt;Intel: &lt;a href=&quot;https://software.intel.com/en-us/articles/intel-performance-counter-monitor&quot;&gt;Performance Counter Monitor&lt;/a&gt; (note: it's not clear to me whether this includes access to GPU counters, or only CPU ones); see also  &lt;a href=&quot;https://www.opengl.org/registry/specs/INTEL/performance_query.txt&quot;&gt;INTEL_performance_query&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;NVIDIA: &lt;a href=&quot;https://developer.nvidia.com/nvidia-perfkit&quot;&gt;PerfKit&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;PowerVR: &lt;a href=&quot;https://community.imgtec.com/developers/powervr/tools/pvrscope/&quot;&gt;PVRScope&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Qualcomm: &lt;a href=&quot;https://www.khronos.org/registry/gles/extensions/QCOM/QCOM_performance_monitor_global_mode.txt&quot;&gt;QCOM_performance_monitor_global_mode&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-24T05:06:18.593" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2488" PostTypeId="1" CreationDate="2016-05-24T08:54:32.497" Score="3" ViewCount="105" Body="&lt;p&gt;I am going through an undocumented function that takes in three points and a Z-value that projects three points on the plane defined by Z-value. I want to understand the mathematical theory behind it and I need your help to decode the function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;SlicerSegment project2D(Point3&amp;amp; p0, Point3&amp;amp; p1, Point3&amp;amp; p2, int32_t z) const&#xA;{&#xA;    SlicerSegment seg;&#xA;    seg.start.X = p0.x + int64_t(p1.x - p0.x) * int64_t(z - p0.z) / int64_t(p1.z - p0.z);&#xA;    seg.start.Y = p0.y + int64_t(p1.y - p0.y) * int64_t(z - p0.z) / int64_t(p1.z - p0.z);&#xA;&#xA;seg.end.X = p0.x + int64_t(p2.x - p0.x) * int64_t(z - p0.z) / int64_t(p2.z - p0.z);&#xA;    seg.end.Y = p0.y + int64_t(p2.y - p0.y) * int64_t(z - p0.z) / int64_t(p2.z - p0.z);&#xA;    return seg;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="231" LastEditDate="2016-05-28T15:11:04.637" LastActivityDate="2016-05-28T15:11:04.637" Title="2D projection from some points" Tags="&lt;projections&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2489" PostTypeId="1" AcceptedAnswerId="2519" CreationDate="2016-05-24T10:32:27.893" Score="10" ViewCount="4017" Body="&lt;p&gt;I'm trying to implement a microfacet BRDF in my raytracer but I'm running into some issues. A lot of the papers and articles I've read define the partial geometry term as a function of the view and half vectors: G1(v, h). However, when implementing this I got the following result: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VGIdx.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VGIdx.jpg&quot; alt=&quot;GGX Geometry term using the half vector&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Bottom row is dielectric with roughness 1.0 - 0.0, Top row is metallic with roughness 1.0 - 0.0)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a weird highlight around the edges and a cut-off around n.l == 0. I couldn't really figure out where this comes from. I'm using Unity as a reference to check my renders so I checked their shader source to see what they use and from what I can tell their geometry term is not parametrized by the half vector at all! So I tried the same code but used to macro surface normal instead of the half vector and got the following result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bnVxb.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bnVxb.jpg&quot; alt=&quot;GGX geometry term using the macro surface normal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To my untrained eye this seems way closer to the desired result. But I have the feeling this is not correct? The majority of the articles I read use the half vector but not all of them. Is there a reason for this difference?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use the following code as my geometry term:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float RayTracer::GeometryGGX(const Vector3&amp;amp; v, const Vector3&amp;amp; l, const Vector3&amp;amp; n, const Vector3&amp;amp; h, float a)&#xA;{&#xA;    return G1GGX(v, h, a) * G1GGX(l, h, a);&#xA;}&#xA;&#xA;float RayTracer::G1GGX(const Vector3&amp;amp; v, const Vector3&amp;amp; h, float a)&#xA;{&#xA;    float NoV = Util::Clamp01(cml::dot(v, h));&#xA;    float a2 = a * a;&#xA;&#xA;    return (2.0f * NoV) / std::max(NoV + sqrt(a2 + (1.0f - a2) * NoV * NoV), 1e-7f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And for reference, this is my normal distribution function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float RayTracer::DistributionGGX(const Vector3&amp;amp; n, const Vector3&amp;amp; h, float alpha)&#xA;{&#xA;    float alpha2 = alpha * alpha;&#xA;    float NoH = Util::Clamp01(cml::dot(n, h));&#xA;    float denom = (NoH * NoH * (alpha2 - 1.0f)) + 1.0f;&#xA;    return alpha2 / std::max((float)PI * denom * denom, 1e-7f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3424" LastActivityDate="2016-05-30T21:35:41.830" Title="Correct form of the GGX geometry term" Tags="&lt;shader&gt;&lt;brdf&gt;&lt;pbr&gt;&lt;microfacet&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2490" PostTypeId="1" CreationDate="2016-05-24T12:40:05.170" Score="4" ViewCount="133" Body="&lt;p&gt;I am going through some ideas that slice a 3D model and fill the area of the resulting polygon contour . Currently they are using the following concepts as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Every resulting line of the polygon after the slicing operation has a parent triangle, as the original model is made of triangle .&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Each of the triangle has a face normal.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;During scan conversion, when a scanline at a particular height intersect any of the polygon contour line, the normal information of the parent triangle is utilized to find out if the intersection is happening while getting into the contour or getting out of the contour. All these information are used to generate the region that are to be filled.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Then there is another way called the even-odd filling rule. I do not think it is necessary for me to describe it here. I believe that all of you are very well aware of it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is which one of it is better option to go with in terms of correctness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-05-24T12:40:05.170" Title="Polygon Filling rule - even odd OR orientation of the normal" Tags="&lt;rasterizer&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2491" PostTypeId="2" ParentId="2488" CreationDate="2016-05-24T19:11:52.377" Score="2" Body="&lt;p&gt;The function calculates the intersection points between two edges of a triangle and a plane that is assumed to cut it. It returns a line segment running along the cut.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or more generally, the function calculates where the intersection points with the two edges would be, if the edges were extended to infinite lines. Given that it's called &quot;project&quot;, that might be the intended use-case; hard to know without seeing how this gets used in context.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first two lines of math are calculating the intersection point of the $p_0 p_1$ edge with the z-plane. It works by linearly interpolating the $x, y$ values along the edge based on the proportion between $z$ values. The second two lines do the same thing for the $p_0 p_2$ edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One odd thing is that the function is using integers everywhere. Presumably it's because the program is using fixed-point coordinates (which makes good sense for a lot of geometry processing applications due to its uniform precision). However, the way it's done here seems oblivious to rounding: the integer divisions will truncate any fractional component instead of rounding to nearest.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-24T19:11:52.377" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2492" PostTypeId="2" ParentId="2488" CreationDate="2016-05-25T08:04:54.230" Score="1" Body="&lt;p&gt;Let us look at the first line in detail:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;int64_t(p1.x - p0.x)&lt;/code&gt; is the distance between p1 and p0 in the x (also y later) direction lets call this &lt;code&gt;dx&lt;/code&gt; for later discussion.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;int64_t(z - p0.z)&lt;/code&gt; is the distance from z and p0 for simplicity lets us call this &lt;code&gt;a&lt;/code&gt; later.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;int64_t(p1.z - p0.z)&lt;/code&gt; is the distance from p0 and p1 or vector length simplicity lets us call this &lt;code&gt;len&lt;/code&gt; later.&lt;/li&gt;&#xA;&lt;li&gt;lets look at &lt;code&gt;a/len&lt;/code&gt; well that is simply the length of the ratio of the each point to 0. This equals to how much the vector p1-p0 must be scaled to reach the plane intersection. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Finally the entire expression is can be read as follows:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;vector p0 + vector p0-1 * length to intersection&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And visually its as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iYnJb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iYnJb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: The vectors in the calculation, (blue lines sow offsets and projections for feeling of 3D)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the entire function gives the same for the two edges of your triangle. Please note that it is perfectly possible that the result is degenerate as the choice of what edges to use is not checked for so one edge MIGHT be parallel to the plane. Also selection of points to send changes what is being projected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZqBRW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZqBRW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: input blue triangle as 3 points (black), return value projected segment in orange on plane.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-05-26T18:38:36.873" LastActivityDate="2016-05-26T18:38:36.873" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2493" PostTypeId="1" CreationDate="2016-05-25T10:19:16.237" Score="1" ViewCount="351" Body="&lt;p&gt;I have a question about finding the symmetry plane that separate the left and the right halves of a point cloud. We scanned an object, say a human face, with a 3D scanner, such as Kinect, which gives a 3D point cloud. Now we want to find the plane that segments the face into symmetrical left and right halves. I found a paper like &lt;a href=&quot;https://hal.inria.fr/file/index/docid/331758/filename/cvpr2008CombesFinal.pdf&quot; rel=&quot;nofollow&quot;&gt;https://hal.inria.fr/file/index/docid/331758/filename/cvpr2008CombesFinal.pdf&lt;/a&gt;, but could not find any code. Though I found the C++ code &quot;CLARCS&quot; doing this work, but it is no longer available. Thank you.&lt;/p&gt;&#xA;" OwnerUserId="3426" LastEditorUserId="3426" LastEditDate="2016-05-25T10:26:46.230" LastActivityDate="2016-05-25T10:26:46.230" Title="Symmetry plane estimation for 3D point cloud" Tags="&lt;3d&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2494" PostTypeId="1" AcceptedAnswerId="2495" CreationDate="2016-05-25T13:24:03.887" Score="11" ViewCount="1963" Body="&lt;p&gt;The well known &lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick&amp;#39;s_approximation&quot;&gt;Schlick approximation&lt;/a&gt; of the Fresnel coefficient gives the equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$F=F_0+(1 - F_0)(1 - cos(\theta))^5$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And $cos(\theta)$ is equal to the dot product of the surface normal vector and the view vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is still unclear to me though if we should use the actual surface normal $N$ or the half vector $H$. Which should be used in a physically based BRDF and why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, as far as I understand the Fresnel coefficient gives the probability of a given ray to either get reflected or refracted. So I have trouble seeing why we can still use that formula in a BRDF, which is supposed to approximate the integral over all the hemisphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This observation would tend to make me think this is where $H$ would come, but it is not obvious to me that the Fresnel of a representative normal is equivalent to integrating the Fresnel of all the actual normals.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2019-02-01T22:16:01.837" Title="In a physically based BRDF, what vector should be used to compute the Fresnel coefficient?" Tags="&lt;brdf&gt;&lt;pbr&gt;&lt;integral&gt;&lt;fresnel&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2495" PostTypeId="2" ParentId="2494" CreationDate="2016-05-25T14:42:49.120" Score="9" Body="&lt;p&gt;In Schlick's 1994 paper, &lt;a href=&quot;http://www.cs.virginia.edu/%7Ejdl/bib/appearance/analytic%20models/schlick94b.pdf&quot; rel=&quot;noreferrer&quot;&gt;&amp;quot;An Inexpensive Model for Physically-Based Rendering&amp;quot;&lt;/a&gt;, where they derive the approximation, the formula is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$F_{\lambda}(u) = f_{\lambda} + (1 - f_{\lambda})(1 - u)^{5}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Where&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/xxyc2.png&quot; alt=&quot;Description of vectors&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;So, to answer your first question, &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; refers to the angle between the view vector and the half vector. Consider for a minute that the surface is a perfect mirror. So:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$V \equiv reflect(V')$$&lt;/span&gt;&#xA;In this case:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$N \equiv H$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;For microfacet-base BRDFs, the &lt;span class=&quot;math-container&quot;&gt;$D(h_{r})$&lt;/span&gt; term refers to the statistical percentage of microfacet normals that are oriented towards &lt;span class=&quot;math-container&quot;&gt;$H$&lt;/span&gt;. Aka, what percentage of the incoming light will bounce in the outgoing direction.&lt;/p&gt;&#xA;&lt;p&gt;As for why we use Fresnel in a BRDF, it has to do with the fact that a BRDF by itself is only a portion of the full BSDF. A BRDF attenuates the reflected portion of light and a BTDF attenuates the refracted. We use the Fresnel to calculate the amount of reflected vs. refracted light, so we can properly attenuate it with the BRDF and BTDF.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$BSDF = BRDF + BTDF\\&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{align*}&#xA;L_{\text{o}}(p, \omega_{\text{o}}) &amp;amp;=  L_{e}(p, \omega_{\text{o}}) \ + \  \int_{\Omega} BSDF * L_{\text{i}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}} \\&#xA; &amp;amp;= L_{e}(p, \omega_{\text{o}}) \ + \  \int_{\Omega} BRDF * L_{\text{i, reflected}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}}  \ + \  \int_{\Omega} BTDF * L_{\text{i, refracted}}(p, \omega_{\text{i}}) * \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}}&#xA;\end{align*}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So, in summary, we use &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; to get the percentage of light that will bounce in the outgoing direction, and &lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt;, to find out what percentage of the remaining light will reflect/refract. Both these use &lt;span class=&quot;math-container&quot;&gt;$H$&lt;/span&gt;, because that is the surface orientation that allows a mirror reflection between &lt;span class=&quot;math-container&quot;&gt;$V$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$V'$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-02-01T22:16:01.837" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="2496" PostTypeId="1" CreationDate="2016-05-25T15:27:13.490" Score="4" ViewCount="511" Body="&lt;p&gt;I was reading a paper on BRDF. I've come across this formula :&#xA;$$ f(\omega_i, \omega_o ) = \frac{FDG}{4(N.V)(N.L)}$$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The (N.L) term can be cancelled by the cosine term which appears in the rendering equation :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ L_o = \int f(\omega_i, \omega_o) L_i cos(\theta) d\omega_i $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What about the (N.V) term ? What happens if (N.V) = 0 ?&lt;/p&gt;&#xA;" OwnerUserId="3339" LastActivityDate="2016-05-25T17:08:37.117" Title="What is the effect of the BRDF denominator?" Tags="&lt;raytracing&gt;&lt;color&gt;&lt;brdf&gt;&lt;physics&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2497" PostTypeId="2" ParentId="2424" CreationDate="2016-05-25T15:38:02.133" Score="2" Body="&lt;p&gt;Thanks for your answers. That was helpfull.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how I understand the 1/r² term for point source (tell me if I'm wrong).&#xA;Let's take the BRDF definition :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ L_o = \int f(\omega, \omega_o) \, dE$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we have to answer this question : How is the Irradiance E distributed ?&#xA;For one point source, we have : $$ dE = \delta(\omega_i-\omega)E \, d\omega $$&#xA;The irradiance is only comming from one direction (the point source). Therfore, we can simplify the equation :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ L_o = \int f(\omega, \omega_o) \delta(\omega_i-\omega)E \, d\omega = f(\omega_i, \omega_o) E$$ &#xA;We can use the relation between the intensity I of the point source and E $$ E = cos(\theta_i)I/r^2 $$&#xA;Finally : $$ L_o = f(\omega_i, \omega_o) cos(\theta_i)I/r^2 $$&lt;/p&gt;&#xA;" OwnerUserId="3339" LastEditorUserId="48" LastEditDate="2016-05-25T18:45:30.017" LastActivityDate="2016-05-25T18:45:30.017" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2498" PostTypeId="2" ParentId="2496" CreationDate="2016-05-25T16:05:41.587" Score="0" Body="&lt;p&gt;Don't forget that at the end this is to be integrated in some cone (e.g. pixel footprint).&#xA;Then the visible cross section of differential surface dN is also be $(N\cdot V)$.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-05-25T16:05:41.587" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2499" PostTypeId="2" ParentId="2496" CreationDate="2016-05-25T17:08:37.117" Score="4" Body="&lt;p&gt;Firstly, I highly suggest reading Eric Heitz's paper &quot;&lt;a href=&quot;https://hal.inria.fr/hal-00942452v2/document&quot; rel=&quot;nofollow&quot;&gt;Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs&lt;/a&gt;&quot;, which covers the full derivation of microfacet-based BRDFs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The $\frac{1}{4(N \cdot V)(N \cdot L)}$ term is a side effect of the derivation of the BRDF for specular microfacets. Specifically, it comes from the Jacobian of the reflection transformation. See the paper and/or &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow&quot;&gt;Walter et. al's 2007 paper&lt;/a&gt; for more details.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for your concern for a divide by zero, the definition of the rendering equation prevents it. Let me explain:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For $(N \cdot V)$ to equal zero, they must be orthogonal. In this case, the visibility term of the rendering equation will cull the cases at / below the horizon.&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-05-25T17:08:37.117" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2500" PostTypeId="1" CreationDate="2016-05-25T18:49:13.150" Score="2" ViewCount="127" Body="&lt;p&gt;This is hard to explain but I am going to try, then I will explain it as pure mathematics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Look at this image.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/jBASF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jBASF.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;So basically this is a moving line, each frame a new segment is added and the previous frame is faded by an amount decided by fps. (There are dots to make things neat but I'm not showing them for simplicity).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So based on the FPS a number is calculated (0.05 if perfect FPS ) and as a result the previous frame gets a black plane drawn over it with an opacity of 0.05.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see this causes an issue because of the segments. My solution is to give each vertex a color, however I don't know how to calculate that color.  The line color is defined by HSV, and the fading is decided by RGB.  Furthermore I am pretty sure fading with the transparent plane creates an exponential effect, however HSV.V works linearly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is if I know on a given frame that the fading plane will have an opacity of 0.05 how can I calculate an equivalent HSV color to what the previous frame will be after fading? That way the bottom two vertices can be a darker color and interpolation can fix it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula that decides the opacity of the black is as follows. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(dt / (1 / 60)) * 0.5&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2308" LastEditorDisplayName="user246" LastEditDate="2016-10-08T20:42:42.353" LastActivityDate="2016-10-08T20:42:42.353" Title="Matching an HSV color with a blended color" Tags="&lt;opengl&gt;&lt;color&gt;&lt;color-science&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2501" PostTypeId="1" CreationDate="2016-05-25T20:40:55.557" Score="3" ViewCount="1208" Body="&lt;p&gt;Let's assume I have the following cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zyfHW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zyfHW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume the isovalue = 0. I would like to draw the resulting triangles of the isosurface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that first I define which values are inside or outside comparing them to the given isovalue and after that we correspond to a particular list of edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After that, we have somehow to linearly interpolate the points.&#xA;I have read on an article that using this formula $P = P_1 + \frac{(iso -V_1)(P_2-P_1)}{V_2-V_1}$ we can get the interpolated values. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone demonstrate to me how I can interpolate the points in this case ? &lt;/p&gt;&#xA;" OwnerUserId="2214" LastEditorUserId="2214" LastEditDate="2016-05-27T08:09:33.930" LastActivityDate="2016-05-27T08:44:03.607" Title="Linear interpolation on Plane (Marching Cubes)" Tags="&lt;algorithm&gt;&lt;interpolation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2502" PostTypeId="2" ParentId="2500" CreationDate="2016-05-25T20:55:50.740" Score="1" Body="&lt;p&gt;The opacity acts linearly through the colors, i.e. it affects R G B similarily, so it should affects the value V the same way.&#xA;You just want to have an intensity factor decay as $0.95^n$.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-05-25T20:55:50.740" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2503" PostTypeId="2" ParentId="2501" CreationDate="2016-05-25T21:01:16.457" Score="1" Body="&lt;p&gt;You can use this formula on each edge where one point is &amp;lt; isovalue and the other is &gt; .&#xA;Then you link together the points belonging to the same square to form the edges of your iso-mesh. &#xA;Then you make polygons by linking edges sharing a vertex. In case of more than 3 sides (could be up to 6), it's up to you to prefer spliting the polygon into triangles.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-05-25T21:01:16.457" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2505" PostTypeId="2" ParentId="2494" CreationDate="2016-05-25T22:43:42.677" Score="8" Body="&lt;p&gt;The Fresnel coefficient should be evaluated using $H$, not $N$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You wrote,&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I have trouble seeing why we can still use that formula in a BRDF, which is supposed to approximate the integral over all the hemisphere.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's not. The BRDF in itself does not approximate the integral over all the hemisphere. The rendering equation does that: you integrate over all incoming light directions, but each time the BRDF inside the integral is evaluated, it's for &lt;em&gt;one specific choice&lt;/em&gt; of incoming and outgoing ray directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For microfacet BRDFs, the usual simplifying assumption is that individual microfacets are perfect specular reflectors. Then, given the $L$ and $V$ at which to evaluate, the &lt;em&gt;only&lt;/em&gt; microfacets that can contribute are those that are aligned along $H = \text{normalize}(L+V)$, because that's the only way they can reflect light from the incoming to the outgoing ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The normal distribution function and the visibility factor in the BRDF together approximate the density of microfacets oriented along $H$ that are visible from both the $L$ and $V$ directions. The Fresnel factor is evaluated &lt;em&gt;for those microfacets&lt;/em&gt;, so the correct angle to use is the one between $L$ and $H$, or equivalently $V$ and $H$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a couple cases where this argument gets modified. One is if the microfacet model assumes something other than perfect specularity. For instance, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Oren%E2%80%93Nayar_reflectance_model&quot;&gt;Oren-Nayar BRDF&lt;/a&gt; assumes Lambertian microfacets. In this case the BRDF has to incorporate some kind of integral over all the possible microfacet orientations that can scatter light from $L$ to $V$. Then the BRDF won't have a standard Fresnel factor at all; it'll have some other formula that approximates the result of integrating the Fresnel factor over the normal hemisphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other case that comes up in real-time graphics is the reflection from an environment map. To be really correct, we should integrate the environment map multiplied by the BRDF over all incoming light directions, but in practice we often sample a prefiltered environment map using the dominant reflection vector $R = \text{reflect}(V, N)$ and then multiply it by some approximate Fresnel formula that depends on the angle between $R$ and $N$ (equivalently $V$ and $N$), as well as the surface roughness. This is very much an approximation, but often good enough for real-time use.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-05-25T22:43:42.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2506" PostTypeId="1" CreationDate="2016-05-26T08:59:25.520" Score="3" ViewCount="324" Body="&lt;p&gt;Let's assume that in a triangle we have computed the brightness on the vertices of a triangle and we have found that it is maximum. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can any other point which lies on that triangle have more brightness than the maximum brightness on those vertices ?&lt;/p&gt;&#xA;" OwnerUserId="2214" LastActivityDate="2016-05-28T14:58:48.403" Title="Surface shading on an triangle" Tags="&lt;shading&gt;&lt;brightness&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2507" PostTypeId="2" ParentId="2506" CreationDate="2016-05-26T09:09:22.663" Score="5" Body="&lt;p&gt;That completely depends on how you are computing the shading. If you are then just linearly interpolating the shaded colours across the triangle, i.e. &lt;a href=&quot;https://en.wikipedia.org/wiki/Gouraud_shading&quot;&gt;Gouraud shading&lt;/a&gt; then, clearly, the answer is &quot;no&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you are doing per-pixel shading by, say, interpolating normals and light directions, then you can easily get a brighter area away from the vertices.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2016-05-26T09:09:22.663" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2508" PostTypeId="1" AcceptedAnswerId="2509" CreationDate="2016-05-26T11:39:20.120" Score="4" ViewCount="1151" Body="&lt;p&gt;I'm working with &lt;code&gt;DirectCompute&lt;/code&gt;, but this question can be applied to general gpu programming I suppose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I know the threads in a group works in a lockstep. It means that every instruction for every thread executes at the same time, right? But what if one thread out of &lt;code&gt;1024&lt;/code&gt; entered &lt;code&gt;if/else&lt;/code&gt; condition? All other &lt;code&gt;1023&lt;/code&gt; will just wait or lockstep condition will be violated?&lt;/p&gt;&#xA;" OwnerUserId="386" LastActivityDate="2016-05-26T12:02:55.647" Title="Threads lockstep and conditions in compute shader" Tags="&lt;compute-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2509" PostTypeId="2" ParentId="2508" CreationDate="2016-05-26T12:02:55.647" Score="5" Body="&lt;p&gt;Not all threads will execute in lockstep but they are split into groups whose threads are locked to each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that if only 1 thread out of all threads enters a branch then only 1 group will need to enter that branch while all the others will skip it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In that group that has to execute both branches it will actually execute both branches but threads will throw away the result of the branch that it didn't need to go into.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information &lt;a href=&quot;https://computergraphics.stackexchange.com/q/280/137&quot;&gt;see this question&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-05-26T12:02:55.647" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="2510" PostTypeId="1" CreationDate="2016-05-26T13:04:36.520" Score="5" ViewCount="2412" Body="&lt;p&gt;I am going through the Vatti Arbitrary Polygon Clipping Algorithm, but got stuck at their very initial explanation. It says the following:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Call an edge of a polygon a left or right edge if the interior of the polygon is to the right or left, respectively. Horizontal edges are considered to be both left and right edges. A key fact that is used by the Vatti algorithm is that polygons can be represented via a set of left and right bounds which are connected lists of left and right edges, respectively, that come in pairs. Each of these bounds starts at a local minimum of the polygon and ends at a local maximum. Consider the &quot;polygon&quot; with vertices $\{p_0, p_1, ..., p_8\}$ shown in Figure 1(a). The two left bounds have vertices $\{p_0, p_8, p_7, p_6\}$ and $\{p_4, p_3, p_2\}$, respectively. The two right bounds have vertices $\{p_0, p_1, p_2\}$ and $\{p_4, p_5, p_6\}$.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The image it refers to is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://imgur.com/cWpcjyX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://imgur.com/cWpcjyX.png&quot; alt=&quot;Image showing polygon vertices&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I do not understand the vertices of the second left bound $\{p_4,p_3,p_2\}$. How are these vertices derived? &lt;/p&gt;&#xA;" OwnerUserId="2712" LastEditorUserId="231" LastEditDate="2016-05-26T13:43:45.090" LastActivityDate="2021-05-03T15:51:06.563" Title="Explanation of the Vatti clipping algorithm" Tags="&lt;algorithm&gt;&lt;polygon&gt;" AnswerCount="3" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2512" PostTypeId="2" ParentId="2501" CreationDate="2016-05-27T08:35:44.453" Score="2" Body="&lt;p&gt;P1 and P2 in this case represent the actual &lt;em&gt;coordinates&lt;/em&gt; of the vertices of the cube in your output mesh. These might be the same as the input coordinates of the function you're using, or they might not be, it's entirely up to you how you output them. A simple way to map them would be to just use integer coords, biased by half the resolution of your sample volume - so a mesh spanning 100^3 cubes would have coordinates from -50 to 50 on each axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in the formula you describe, (iso - V1) / (V2 - V1) gives you the amount to interpolate by, and (P2 - P1) is a vector representing a single cube lattice edge along the axis you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume we're using unit sized cubes, +Y is up, and +Z is 'into' the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your cube above, you will have crossings on the three edges coming from the left-bottom-front corner. On the X and Z edges you will interpolate by 0.25 : (0 - (-1)) / (3 - (-1)) , and on the Y edge you will interpolate by 0.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if the left-bottom-front corner is at the origin, your three mesh vertices will be at &#xA;&amp;lt;0.25, 0, 0&gt; , &#xA;&amp;lt;0, 0.5, 0&gt; and &#xA;&amp;lt;0, 0, 0.25&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apply the same formula to the right-top-back corner and you get &amp;lt;0.5, 1, 1&gt;, &amp;lt;1, 0.5, 1&gt; and &amp;lt;1, 1, 0.5&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only difference is the left-bottom-front corner values will be P1 and V1 in your formula as it is at the 'negative' end of the edges to be interpolated, and the right-top-back values will be P2 and V2 as it is at the 'positive' end.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope that all makes sense.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="1937" LastEditDate="2016-05-27T08:44:03.607" LastActivityDate="2016-05-27T08:44:03.607" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2514" PostTypeId="2" ParentId="2506" CreationDate="2016-05-27T19:44:48.500" Score="3" Body="&lt;p&gt;Assuming you have almost any lighting model at all:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You cannot bound the view irradiance (light reflected from a surface location towards the eye/camera) by computing the irradiance at the vertices and bounding those, even if the surface is completely diffuse Lambertian and has no view-angle term.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine a large floor triangle, and a point lighting near the center of the triangle, close to the surface.  The center of the triangle is very bright, while the vertices - which are far away from the light source - are dark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, if you are just asking if a linearly interpolated quantity can exceed the value at any/all of the end points - then the answer is simply 'no' - your bounds are accurate. The key issue here is that irradiance is a non-linear function over the surface, but interpolation is linear&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-05-27T19:44:48.500" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2515" PostTypeId="2" ParentId="2506" CreationDate="2016-05-27T21:04:34.613" Score="1" Body="&lt;p&gt;I am supplementing the answer of others by adding a picture showing a Blinn and Lambert material applied to a triangle (the triangle has normals in different directions at the corners to show the difference in shading). There is one distant directional light in the scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8Ly97.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8Ly97.png&quot; alt=&quot;Lighting on a triangle lit by directional light&quot;&gt;&lt;/a&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Image shows lighting on a triangle lit by directional light.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;By comparing the samples in image 1 we can see that the highest color value can be somewhere in the center of the triangle. Which shows that the assumption in your question is generally invalid. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So &lt;strong&gt;no&lt;/strong&gt; you can not generally assume that the corners are the maximum of a triangle. A shader with this property can be constructed but quite a few shaders have this property naturally.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-05-28T14:58:48.403" LastActivityDate="2016-05-28T14:58:48.403" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2516" PostTypeId="1" CreationDate="2016-05-28T07:08:27.267" Score="6" ViewCount="2135" Body="&lt;p&gt;I am writing a software and I need to represent an graph in a orthogonal manner from topological data (vector of edges,vertices and their connectivity data)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Graphs&lt;/strong&gt; consist of a set of &lt;strong&gt;vertices&lt;/strong&gt; and a set of &lt;strong&gt;edges&lt;/strong&gt;, each connecting two vertices.A vertex may have any number of connected edges so it makes the problem a lot more complicated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have read some articles and its looks like that the &lt;strong&gt;Kandinsky model&lt;/strong&gt; is the post popular one. However I just don't know the algorithm, any other solution (algorithm) that solve the problem is also very welcome.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Added after edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following picture shows a real world example for an electricity network which should be considered as raw data, in order to create a graph from this network, some preliminary tasks must be done. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Input Data:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pJofq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pJofq.jpg&quot; alt=&quot;Input Data&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result I am looking for is something like below, &#xA;there are some characteristics if you take a look much closer : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Red Polygon in the middle of the above picture(input data) represents an electricity substation which is a node itself and can be connected to more than 4 edges.&#xA;There are more red polygons but only one can be fit into the above picture however as you may see, the following picture could cover much more than a red polygon that means it can map a bigger area, so the following picture is much more denser.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Schematics diagrams, red polygons (Substations) usually maintain their position against each other relatively so if we manage to see beyond the extents of the above map by zooming out for example, we should almost see a triangle that is obviously can be seen at the below while having the left one at the left, the down one at the down ..... (this is not a rule, but I thought it could be a head start for desired algorithm)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Orthogonal Diagram:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5gffC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5gffC.png&quot; alt=&quot;Orthogonal Schematic&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="537" LastEditorUserId="537" LastEditDate="2018-11-12T09:50:09.613" LastActivityDate="2021-04-15T14:59:02.820" Title="How to draw an orthogonal graph from its edges and vertices data?" Tags="&lt;algorithm&gt;&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="2518" PostTypeId="1" CreationDate="2016-05-28T13:51:32.880" Score="3" ViewCount="1760" Body="&lt;p&gt;I would like to rotate a raster image by an arbitrary angle. I don't really care for speed: the rotation should be of highest quality possible. Could someone please suggest a suitable algorithm?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm familiar with the &lt;a href=&quot;http://www.leptonica.com/rotation.html#ROTATION-BY-SHEAR&quot; rel=&quot;noreferrer&quot;&gt;rotation by three shears&lt;/a&gt; but I'm not sure if the shears would not cause too much aliasing/blurring.&lt;/p&gt;&#xA;" OwnerUserId="141" LastActivityDate="2016-06-04T11:55:24.110" Title="Image rotation algorithm" Tags="&lt;algorithm&gt;&lt;transformations&gt;&lt;image-processing&gt;&lt;2d&gt;&lt;raster-image&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2519" PostTypeId="2" ParentId="2489" CreationDate="2016-05-28T14:49:53.177" Score="5" Body="&lt;p&gt;TL;DR: Your $G1$ formula is wrong. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Just to avoid confusion, I am assuming the isotropic version of the BRDF, the Smith microfacet model (as opposed to the V-cavity model), and the GGX microfacet distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://hal.inria.fr/hal-00996995&quot; rel=&quot;nofollow&quot;&gt;Heitz 2014&lt;/a&gt;, the masking/shadowing term $G1$ is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\chi^{+}\left(\omega_{v}\cdot\omega_{m}\right)&#xA;\frac{2}{1+\sqrt{1+\alpha_{o}^{2}\tan^{2}\theta_{v}}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and according to &lt;a href=&quot;http://dx.doi.org/10.2312/EGWR/EGSR07/195-206&quot; rel=&quot;nofollow&quot;&gt;Walter 2007&lt;/a&gt;, the formula is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\chi^{+}\left(\frac{\omega_{v}\cdot\omega_{g}}{\omega_{v}\cdot\omega_{m}}\right)\frac{2}{1+\sqrt{1+\alpha^{2}\tan^{2}\theta_{v}}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $\omega_{m}$ is the microfacet normal direction (halfway vector), $\omega_{g}$ is the main (geometric) normal direction (normal), $\omega_{v}$ is the incoming or outgoing direction, $\alpha$ is the isotropic roughness parameter, and $\chi^{+}\left(a\right)$ is the positive characteristic function, or the Heaviside step function (equals one if $a&amp;gt;0$ and zero otherwise).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can notice, the half vector $\omega_{m}$ is used only to make sure the $G1$ is zero if the geometrical configuration is forbidden. More precisely, it makes sure that the back surface of the microsurface is never visible from the $\omega_{v}$ direction on the front side of the macrosurface and vice versa (the latter case is meaningful only when also refractions are supported). If the calling code guarantees this, then you can obviously omit this parameter. That is probably the reason why they did so in Unity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your implementation, on the other hand, uses the half vector to compute the cosine of the $\omega_{v}$ direction with respect to the microfacet, which leads to computation of something else than the presented formulae.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it is of any help, then this is my implementation of the $G1$ factor:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float SmithMaskingFunctionGgx(&#xA;    const Vec3f &amp;amp;aDir,  // the direction to compute masking for (either incoming or outgoing)&#xA;    const Vec3f &amp;amp;aMicrofacetNormal,&#xA;    const float  aRoughnessAlpha)&#xA;{&#xA;    PG3_ASSERT_VEC3F_NORMALIZED(aDir);&#xA;    PG3_ASSERT_VEC3F_NORMALIZED(aMicrofacetNormal);&#xA;    PG3_ASSERT_FLOAT_NONNEGATIVE(aRoughnessAlpha);&#xA;&#xA;    if (aMicrofacetNormal.z &amp;lt;= 0)&#xA;        return 0.0f;&#xA;&#xA;    const float cosThetaVM = Dot(aDir, aMicrofacetNormal);&#xA;    if ((aDir.z * cosThetaVM) &amp;lt; 0.0f)&#xA;        return 0.0f; // up direction is below microfacet or vice versa&#xA;&#xA;    const float roughnessAlphaSqr = aRoughnessAlpha * aRoughnessAlpha;&#xA;    const float tanThetaSqr = Geom::TanThetaSqr(aDir);&#xA;    const float root = std::sqrt(1.0f + roughnessAlphaSqr * tanThetaSqr);&#xA;&#xA;    const float result = 2.0f / (1.0f + root);&#xA;&#xA;    PG3_ASSERT_FLOAT_IN_RANGE(result, 0.0f, 1.0f);&#xA;&#xA;    return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-05-30T21:35:41.830" LastActivityDate="2016-05-30T21:35:41.830" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="2521" PostTypeId="1" AcceptedAnswerId="2524" CreationDate="2016-05-28T22:01:49.243" Score="4" ViewCount="1154" Body="&lt;p&gt;I know how to draw lines with DDA, but I want to learn a more efficient way and Google suggests Bresenham's line drawing algorithm is better than DDA.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my implementation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int x0 = Math.round(m_start.getPosition().getX());&#xA;int y0 = Math.round(m_start.getPosition().getY());&#xA;int x1 = Math.round(m_end.getPosition().getX());&#xA;int y1 = Math.round(m_end.getPosition().getY());&#xA;&#xA;int dx = x1 - x0;&#xA;int dy = y1 - y0;&#xA;&#xA;int parameter = 2 * dy -  dx;&#xA;&#xA;Point k = new Point(new Vector2D(x0, y0), m_display, PixelData.white());&#xA;k.DrawPoint();&#xA;&#xA;for(int i = x0 + 1; i &amp;lt; x1; i++){&#xA;   if(parameter &amp;lt; 0){&#xA;       y0 += 1;&#xA;       Point p = new Point(new Vector2D(i, y0), m_display, PixelData.white());&#xA;       p.DrawPoint();&#xA;&#xA;       parameter += 2 * dy;&#xA;   }&#xA;   else{&#xA;       y0 += 1;&#xA;       Point p = new Point(new Vector2D(i, y0 + 1), m_display, PixelData.white());&#xA;       p.DrawPoint();&#xA;&#xA;       parameter += 2 * dy - 2 * dx;&#xA;   }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is the output:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BT5tA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BT5tA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the line is not ending at the desired coordinate. That small dot is where it should end.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I checked the slope, dx and dy.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;System.out.println(dx + &quot; &quot; + dy + &quot; &quot; + (dy/(float)dx));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Output:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;100 50 0.5&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The slope is below tan (pi/4).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I find the bug?&lt;/p&gt;&#xA;" OwnerUserId="3437" LastEditorUserId="231" LastEditDate="2016-06-26T17:04:50.810" LastActivityDate="2016-06-26T17:04:50.810" Title="Bug with the Bresenham's line drawing algorithm?" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;line-drawing&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2522" PostTypeId="2" ParentId="2521" CreationDate="2016-05-28T22:31:51.283" Score="1" Body="&lt;p&gt;Frankly, your implementation doesn't make much sense. It basically iterates x coordinate through &lt;code&gt;i&lt;/code&gt; variable and increments &lt;code&gt;y&lt;/code&gt; variable at each step. Since the &lt;code&gt;parameter&lt;/code&gt; doesn't cross the 0 boundary, it generates the diagonal points you can see on your picture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You also compute and update the &lt;code&gt;parameter&lt;/code&gt; variable somehow, but don't use it anywhere.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2016-05-29T07:12:32.357" LastActivityDate="2016-05-29T07:12:32.357" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2523" PostTypeId="2" ParentId="2461" CreationDate="2016-05-28T23:39:03.033" Score="4" Body="&lt;p&gt;I don't have any experience with Gradient Domain Path Tracing, but here are my thoughts:&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;There seems to be a different problem&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you look carefully at the little spikes of distortion in the final image, you will see that they are all lit from the same direction - on their top left side at a consistent 45 degrees. The sphere also appears to be lit from this angle, rather than from above by the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is unlikely to be explained by an incorrect probability estimation for a path. I would expect there to be a different problem with the code, that these distortions are hinting at.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will therefore address these two separate points:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;You want to know how to calculate the Probability Density of a path when using Next Event Estimation.&lt;/li&gt;&#xA;&lt;li&gt;There is evidence of some problem unrelated to this.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I'll also review the code for non-essential points - but I'll leave this until after the essentials.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Probability Density of a path when using Next Event Estimation&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Looking at the &lt;a href=&quot;https://mediatech.aalto.fi/publications/graphics/GPT/kettunen2015siggraph_paper.pdf&quot; rel=&quot;nofollow&quot;&gt;paper on which the code you are following was based&lt;/a&gt; it seems that the novel shift mapping described in section 5.2 is defined in terms of the reflective properties of the surfaces found at the vertices of the path. I must emphasise that I don't have a full understanding of this, but it suggests that Next Event Estimation may not require a change in this approach, as the surfaces encountered will be the same. Hopefully once the other problems are cleared up it will be easier to judge whether the image looks correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that section 5.2 of the paper already mentions (just below Figure 10) that they take into account sampling the emitter &quot;&lt;em&gt;either using BSDF or area sampling&lt;/em&gt;&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference with Next Event Estimation is that the area sampling happens at every vertex of the path, but it isn't obvious to me that this should cause a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fact that your scene uses only diffuse surfaces means that the offset path should in most cases rejoin the base path at the second vertex, so you would only need to recalculate the area sampling for the first vertex of the offset path.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;The cause of the incorrect lighting direction&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;In reading through the code to familiarise myself with how it works, I noticed that &lt;code&gt;NLdotL&lt;/code&gt; is calculated, but then not used. A text search revealed that the only other occurrence has a different case: &lt;code&gt;nldotl&lt;/code&gt;. Here are the two variables in context (first and ninth lines of this excerpt):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float NLdotL = Math.Abs( Vector3.Dot( NL, -L ) );&#xA;float NdotL = Vector3.Dot( ray.N, L );&#xA;if (NdotL &amp;gt; 0)&#xA;{&#xA;    Ray r = new Ray( I + L * EPSILON, L, dist - 2 * EPSILON ); //make it a tiny bit shorter otherwise I risk to hit my starting and destination point&#xA;    Scene.Intersect( r );&#xA;    if (r.objIdx == -1) //no occlusion towards the light&#xA;    {&#xA;        float solidAngle= (nldotl * light.getArea()) / (dist * dist);&#xA;        E += T * (NdotL) * solidAngle * BRDF * light.emission;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Since &lt;code&gt;nldotl&lt;/code&gt; is not defined, the result of the code is undefined behaviour. In practice, the program is likely to act as if &lt;code&gt;nldotl&lt;/code&gt; is zero, or for some compilers perhaps a constant arbitrary value, or even a different arbitrary value at each iteration. For your particular compiler it appears to be a constant value, and I strongly suspect this is the cause of the distinctive alignment of lighting angle on all the speckles and the sphere. If there is also another contributing problem it will be easier to analyse it in a separate question once this initial problem has been fixed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It may be worth considering using a compiler and/or flag setting that gives an error or at the very least a warning for undefined variables, as this type of mistake is both very easy to make, and very easy to overlook later.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Additional contribution of light source&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;There appears to be another problem that will cause results to be incorrect in a more subtle way, with no obvious distortion. Due to Next Event Estimation, the light source is contributing to each step along the path. This means it should not make a contribution if the path itself hits the light source directly. Otherwise, for that path the light source will be contributing twice. You can correct this by changing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (material.emissive) //case of a light&#xA;{&#xA;    E += material.diffuse;&#xA;    break;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (material.emissive) //case of a light&#xA;{&#xA;    break;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This will give a zero contribution from the intersection with the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that since I can only see this one function, I can't guess whether this will also make the light appear black in the image. You may or may not need to adjust for rays that start at the camera and hit the light directly.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;Code review&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;Doubly finite rays&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;I'm used to defining a ray as a half infinite line segment - having a starting point but no ending point. I notice that this code gives a ray both a starting point and a length. The only place I can see a reason for this is when testing a shadow ray against the light source: the code checks that there are no intersections on the way to the light, so intersections behind the light (or on the light itself) must be excluded. In all other places, the ray is defined with a pseudo-infinite length (&lt;code&gt;1e34f&lt;/code&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following suggestion won't affect the &lt;em&gt;correctness&lt;/em&gt; of your code, but it may be more readable and avoid you having to work around the need for infinity and having to account for epsilon twice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the ray is simply a starting point and a direction, then shadow rays can simply check that the first intersection is the light, rather than checking that there is no intersection. For example, by replacing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (r.objIdx == -1) //no occlusion towards the light&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (r.objIdx == LIGHT) // There is no object intersected before the light&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here I use &lt;code&gt;LIGHT&lt;/code&gt; as a placeholder for the id of the light source, since that part of the code is not included in the question.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;This will always give false if the light is occluded by a nearer object.&lt;/li&gt;&#xA;&lt;li&gt;This will always give true if the ray hits the light before any more distant objects.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This is therefore equivalent to the current code, but does not require the ray to store a length.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Lights that don't reflect&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The code currently models lights and surfaces separately. This means that if an object is a light then it is only emissive, and reflects no light from other objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This causes a negligible difference in the example scene in the question, which has a single bright light. However, if used with a number of dimmer lights, it would be more noticeable that they do not light each other. In many cases the difference will not be noticeable, so this is not a problem if it works for the scenes you wish to render.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-05-29T00:53:36.330" LastActivityDate="2016-05-29T00:53:36.330" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2524" PostTypeId="2" ParentId="2521" CreationDate="2016-05-29T01:45:44.823" Score="3" Body="&lt;p&gt;&lt;em&gt;Note that the approach you appear to be taking will only work for lines with a slope in a single octant. For the other seven octants the algorithm requires changing the approach, for example by changing the roles of x and y. Wikipedia gives a &lt;a href=&quot;https://en.wikipedia.org/wiki/Bresenham&amp;#39;s_line_algorithm#All_cases&quot; rel=&quot;nofollow&quot;&gt;table of cases&lt;/a&gt; that can be used for this conversion.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;For this answer I will assume you are simply trying to get the code working for the first octant.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int parameter = 2 * dy -  dx;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;parameter&lt;/code&gt; starts off negative only if &lt;code&gt;dx&lt;/code&gt; &gt; &lt;code&gt;2 * dy&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case the total horizontal distance to be covered by the line is more* than twice the vertical distance, which means the first step should be purely horizontal. So if &lt;code&gt;parameter&lt;/code&gt; is negative then &lt;code&gt;y0&lt;/code&gt; should not change.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the source of the problem:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(parameter &amp;lt; 0){&#xA;           y0 += 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;y0&lt;/code&gt; should only be incremented if &lt;code&gt;parameter&lt;/code&gt; is &lt;em&gt;not&lt;/em&gt; negative. This &lt;code&gt;y0 += 1&lt;/code&gt; is causing vertical movement even if the first step should be purely horizontal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same problem applies on later steps too. The code causes &lt;code&gt;parameter&lt;/code&gt; to switch back and for between negative and non-negative in proportion to the ratio between &lt;code&gt;2 * dx&lt;/code&gt; and &lt;code&gt;dy&lt;/code&gt;. &lt;code&gt;y0&lt;/code&gt; must only be incremented when &lt;code&gt;parameter&lt;/code&gt; is non-negative. That additional occurrence of &lt;code&gt;y0 += 1&lt;/code&gt; prevents &lt;code&gt;y0&lt;/code&gt; from ever staying still, causing a slope of 1 regardless of the inputs. Simply remove that line and it should work correctly.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;*If you are wondering why the algorithm only steps purely horizontally when the parameter is less than zero, rather than less than or equal to zero, bear in mind that the horizontal distance to be covered is one less than the number of pixel columns displayed. If x0 is 0 and x1 is 3, then dx is 3, but 4 columns of pixels will be displayed. So a line 4 pixels across and 2 pixels down actually has xd as 3 and yd as 1. In this case the number of pixels across is exactly twice the number of pixels down, but xd is &lt;em&gt;more&lt;/em&gt; than twice yd, so this still results in the parameter being negative and the line moving purely horizontally on the first step.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-05-29T02:29:31.397" LastActivityDate="2016-05-29T02:29:31.397" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2526" PostTypeId="1" CreationDate="2016-05-29T14:05:33.413" Score="5" ViewCount="71" Body="&lt;p&gt;After updating my graphics driver and trying to run &lt;a href=&quot;http://john-chapman-graphics.blogspot.al/2013/02/pseudo-lens-flare.html&quot;&gt;this&lt;/a&gt; example from John Chapman's blog I got this error&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vertex shader failed to compile with the following errors:&#xA;ERROR: 0:8: error(#105) #version must occur before any other program statement&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The way that the version is defined is by including a file containing this code&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifndef DEF_GLSL_&#xA;#define DEF_GLSL_&#xA;&#xA;#version 420&#xA;&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So inside all other shader files one can see that the first line is as follows&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &quot;common/def.glsl&quot;&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I remember this working perfectly a few months ago. So what exactly has changed and the &lt;code&gt;#include&lt;/code&gt; command is no longer valid?&lt;/p&gt;&#xA;" OwnerUserId="3452" LastEditorUserId="3452" LastEditDate="2016-05-29T14:53:12.817" LastActivityDate="2016-05-29T16:33:58.057" Title="Why cant I use `#include` after upgrading my driver" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2527" PostTypeId="2" ParentId="2526" CreationDate="2016-05-29T16:33:58.057" Score="4" Body="&lt;p&gt;The error message gives a clue in the wording:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version must occur before any other program statement&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there a reason that the previous 2 lines need to appear before the &lt;code&gt;#version&lt;/code&gt; line? If not, you can avoid the error by moving this line to the beginning, since the actions of the lines are independent of their order in this instance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;#version&lt;/code&gt; needing to be at the beginning of the file is not a new requirement. I don't know why you were able to run this code previously.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-05-29T16:33:58.057" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="2528" PostTypeId="2" ParentId="2446" CreationDate="2016-05-30T08:37:34.313" Score="3" Body="&lt;p&gt;Are you calling glViewport when switching drawing to FBO ? This should be called when switching into a different resolution render target. I say this because case #1 is a symptom of incorrect glViewport.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2016-05-30T08:37:34.313" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2529" PostTypeId="1" AcceptedAnswerId="2536" CreationDate="2016-05-30T12:43:29.830" Score="5" ViewCount="993" Body="&lt;p&gt;I'm using a Sobel filter to draw an outline in a shader. How do I control its thickness? Here's my outlining code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3x3 Kx = {&#xA;-1, 0, 1,&#xA;-2, 0, 2,&#xA;-1, 0, 1};&#xA;&#xA;float3x3 Ky = {&#xA;1, 2, 1,&#xA;0, 0, 0,&#xA;-1,-2,-1};&#xA;&#xA;float Lx = 0;&#xA;float Ly = 0;    &#xA;&#xA;for (int y = -1; y &amp;lt;= 1; ++y) {&#xA;    for (int x = -1; x&amp;lt;= 1; ++x) {&#xA;        float2 offset = float2( x, y );&#xA;        float3 tex = tex2D(sampler, uv + offset).rgb;&#xA;        float luminance = dot(tex, float3(0.3, 0.59, 0.11));&#xA;&#xA;        Lx += luminance * Kx[y+1][x+1];&#xA;        Ly += luminance * Ky[y+1][x+1];&#xA;    }&#xA;}&#xA;float color = sqrt(Lx*Lx + Ly*Ly);&#xA;return float4( color, color, color, color );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="67" LastActivityDate="2016-05-31T04:50:41.500" Title="Controlling Sobel edge thickness" Tags="&lt;shader&gt;&lt;edge-detection&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2530" PostTypeId="2" ParentId="2500" CreationDate="2016-05-30T16:47:25.703" Score="1" Body="&lt;p&gt;First off you want the start of each line to have the color of an already faded line, ie rgb_color*0.95. You already figured out how to do this so I stop there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the HSV you are interested in the Value component only when fading towards black. Basically you should do hsv_color.value*0.95.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I typed this on phone. Please edit if you get it and may explain better.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2016-05-30T16:47:25.703" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2531" PostTypeId="1" AcceptedAnswerId="2533" CreationDate="2016-05-30T17:38:15.047" Score="0" ViewCount="114" Body="&lt;p&gt;I am a some-what experienced programer, and I have been working on creating a 3D graphics engine utilizing the OpenGL system, primarily focused on use in games. However, I also want to do some work with functional programming, and wanted to create a clean UI for more functional programs, like a task manager. An example of the kind of effect that I want to create could be somewhat like the Visual Studio Code UI. My question is: is there a specific library that I should use for creating desktop programs, or should I continue to use OpenGL's 3D aspects, but keep everything in a single Z axis plane, effectively creating a 2D program? Or is there a better way to create normal program visuals, that wont be cheating out of a 3D graphical space?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for your help.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;I am currently using C++/C, but I am also happy to expand my knowledge base to include new languages.&lt;/p&gt;&#xA;" OwnerUserId="3459" LastEditorUserId="3459" LastEditDate="2016-05-30T18:58:14.850" LastActivityDate="2016-05-30T19:55:19.277" Title="Optimal 2D graphics resource" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2016-06-01T09:28:43.650" ContentLicense="CC BY-SA 3.0" />
  <row Id="2532" PostTypeId="2" ParentId="295" CreationDate="2016-05-30T17:48:43.137" Score="0" Body="&lt;p&gt;I'll say a few words about rendering without graphics cards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Niether OpenGL nor DirectX really need a graphics card. An implementation may be fully software accelerated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For OpenGL in Linux there is Mesa software rasterizer. In my experience it works ok as long as you don't push it too hard combining weird features (display list + indexed vertex arrays). I imagine their list of actual bugs is mile high. Make sure to do continous testing!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have less experience using OpenGL in Windows. Edit answer if you know anything!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;DirectX SDK is delivered with a software rasterizer called &quot;reference rasterizer&quot;. It is mostly for debugging in my opinion but I know of at least one friend using the reference rasterizer when developing DX11 on a DX10 only capable laptop. As mentioned in other answers DirectX is Microsoft only.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2016-05-30T17:48:43.137" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2533" PostTypeId="2" ParentId="2531" CreationDate="2016-05-30T19:55:19.277" Score="0" Body="&lt;p&gt;As you said you want to create something like this &lt;a href=&quot;https://i.stack.imgur.com/WOk2z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WOk2z.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you know these are not graphic intense rendering.&#xA;Thus, (i guess but not 100%) Windows do these rendering on CPU not on GPU.&#xA;GPU is for intense rendering with lighting, textures, 3D models, etc. Where you can take the benefit of algorithm built in GPU circuit, Which is what OpenGL does.&lt;/p&gt;&#xA;&lt;p&gt;So i would recommend to use built-in libraries that don't use GPU and use CPU for rendering, Although you can use OpenGL or Direct3D as well.&lt;/p&gt;&#xA;&lt;p&gt;Some libraries that are built in different programming languages are :-&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Java - Jframe, Graphics, Buffered image,  Canvas. (Note : all these libraries have different functionality and you have to use them together for software rendering &lt;a href=&quot;https://www.youtube.com/playlist?list=PLEETnX-uPtBUbVOok816vTl1K9vV1GgH5&quot; rel=&quot;nofollow noreferrer&quot;&gt;See this for more detail&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;C# - System.drawing,  (i don't have much experience of C#, So i can't name any more libraries), also C# form application.&lt;/p&gt;&#xA;&lt;p&gt;JavaScript - Canvas &lt;a href=&quot;https://www.youtube.com/playlist?list=PLh-MBXZEiyMhulEqYE3gn63idSAKG6Sx1&quot; rel=&quot;nofollow noreferrer&quot;&gt;check this out&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;C++ - you need third party libraries like QT, GTX etc. &lt;a href=&quot;https://www.youtube.com/watch?v=6KtOzh0StTc&amp;amp;list=PL2D1942A4688E9D63&quot; rel=&quot;nofollow noreferrer&quot;&gt;Qt learning resource&lt;/a&gt;, &lt;a href=&quot;https://www.youtube.com/watch?v=FxCC9Ces1Yg&amp;amp;list=PLSPw4ASQYyymu3PfG9gxywSPghnSMiOAW&quot; rel=&quot;nofollow noreferrer&quot;&gt;related resource&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Python - Pygame (No personnal eperience) &lt;a href=&quot;https://www.youtube.com/playlist?list=PLQVvvaa0QuDdLkP8MrOXLe_rKuf6r80KO&quot; rel=&quot;nofollow noreferrer&quot;&gt;See this for detail&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="3437" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-05-30T19:55:19.277" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2534" PostTypeId="1" CreationDate="2016-05-30T21:39:46.060" Score="1" ViewCount="192" Body="&lt;p&gt;I am going through one of the most basic line drawing algorithms and stuck with the following mathematical explanations. The implicit function of line equation is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f(x,y) = ax + by + c&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The Book(Computer Graphics , Principles  and practice) mentions that&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f(x,y) = 0 , when any point m is on line&#xA;f(x,y) &amp;lt; 0, when any point m is above the line, and &#xA;f(x,y) &amp;gt; 0, when any point m is below the line.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It would be great to have some explanation of the claim above. I tried to figure out the first one with the following example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;3x + 2y = 1&#xA;=&amp;gt; 3x + 2y -1 = 0, where a = 3, b = 2 and c = -1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;All I figure out that I need to plug in a (x,y) coordinate so that 3x + 2y - 1 = 0. I am not sure how to choose this coordinate value .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I am clueless about the next two cases. An example demonstrating all the three cases would be fantastic !&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks &lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-05-31T04:55:52.333" Title="Midpoint algorithm" Tags="&lt;midpoint&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2535" PostTypeId="2" ParentId="2534" CreationDate="2016-05-31T04:50:19.163" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TizJk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TizJk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I know i marked the coordinates of the second point wrong)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let $ax + by + c$ be any line such that $b &amp;gt; 0$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now pick point $(\alpha,\beta)$ on the line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus $\alpha *a + \beta*b + c = 0$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now pick a point $(\alpha, \gamma)$ such that $\gamma$ &gt; $\beta$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus $\alpha * a + \gamma * b + c$  &gt; 0&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus any point satisfying $ax+by +c$ &gt; 0 line above the line. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;your results can be deduced from the converse of the proof. &lt;/p&gt;&#xA;" OwnerUserId="3437" LastEditorUserId="3437" LastEditDate="2016-05-31T04:55:52.333" LastActivityDate="2016-05-31T04:55:52.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2536" PostTypeId="2" ParentId="2529" CreationDate="2016-05-31T04:50:41.500" Score="4" Body="&lt;p&gt;I've done this 2 different ways in the past:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Apply a pre-blur to the image before running the Sobel operator on it. This will have the side effect of getting rid of any noise that's smaller than the blur kernel, but it will also thicken the lines you end up drawing, too.&lt;/li&gt;&#xA;&lt;li&gt;Apply a post-process where you thicken the lines by either stamping a shape at every point that's an edge, or using some sort of &lt;a href=&quot;https://en.wikipedia.org/wiki/Mathematical_morphology&quot; rel=&quot;nofollow&quot;&gt;dilate process&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-05-31T04:50:41.500" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2537" PostTypeId="2" ParentId="2510" CreationDate="2016-05-31T09:12:46.230" Score="1" Body="&lt;p&gt;(Promoting &quot;comment&quot; to an answer)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks to me that it's just finding monotonic runs of edges. Given a defined winding order (in this case anticlockwise), then you can identify {P6, P7, P8, P0} as a decreasing run, as is {P2, P3, P4}. Since the left most vertex, P8, is in (**the middle of) a decreasing run, the decreasing runs define left boundaries and, therefore, increasing runs are right boundaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;**it just occurred to me that if the left most point is at the beginning/end of a monotonic run then a slightly more involved rule will need to be applied involving the edges entering/leaving that point.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-06-01T09:34:21.397" LastActivityDate="2016-06-01T09:34:21.397" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2538" PostTypeId="1" CreationDate="2016-05-31T10:13:37.447" Score="0" ViewCount="47" Body="&lt;p&gt;I have a bounding area of a contour after the slicing operation. Now to generate the tool-path over the contour, I need to distribute the bounding area into grid space so that each each cell maintain a certain precomputed width.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am doing the math as follows, but I am not sure if the whole area will be covered as there is floating point values concatenated to integer coordinates.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;       short int xDist = std::abs(xMax - xMin);&#xA;       short int yDist = std::abs(yMax - yMin);&#xA;&#xA;       short int xCells = (xDist/scanSpacingStep) + 1;&#xA;       short int yCells = (yDist/scanSpacingStep) + 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The indexing starts from (0,0). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2712" LastActivityDate="2016-05-31T10:13:37.447" Title="distribute the bounding area into grid space" Tags="&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="2540" PostTypeId="1" AcceptedAnswerId="2545" CreationDate="2016-05-31T19:43:47.037" Score="2" ViewCount="133" Body="&lt;p&gt;Is there any difference between registers types in hlsl?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example when using register &lt;code&gt;t0&lt;/code&gt; for &lt;code&gt;UAV&lt;/code&gt; will it be somehow precache like textures?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to microsoft's presentation about resource in DX12 and hlsl 5.1 this registers mean nothing, but maybe they only mean that there isn't any real registers like on CPU?&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorUserId="3123" LastEditDate="2016-06-01T06:51:53.277" LastActivityDate="2016-06-01T18:01:26.300" Title="Hlsl - registers type" Tags="&lt;gpu&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2541" PostTypeId="1" AcceptedAnswerId="2543" CreationDate="2016-05-31T19:58:37.443" Score="3" ViewCount="1397" Body="&lt;p&gt;Here is my function that does interpolation&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static public PixelData InterpolateColour(Point start, Point end ,float curLength, float totalLength){&#xA;&#xA;    float endPercent = curLength / totalLength;             // Calculates the percent of colour at the ending point of the line to be used in current pixel &#xA;    float startPercent = 1 - (curLength / totalLength);     // Calculates the percent of colour at the starting point of the line to be used in current pixel &#xA;&#xA;    float startHueInRadians[] = PixelData.PixelDataToHsbInRadians(start.getColour());   // Converting the ending point colour into a hsb colour model &#xA;    float endHueInRadians[] = PixelData.PixelDataToHsbInRadians(end.getColour());       // Converting the starting point colour into a hsb colour model&#xA;&#xA;&#xA;    startHueInRadians[0] = (startHueInRadians[0] == 0) ?                                            // if the start colour is red then then choosing the value to be zero or 2*pi&#xA;                           ((endHueInRadians[0] &amp;gt;= (Math.PI * 4)/3) ?  (float)(Math.PI * 2) : 0)    // if the end colour is red then then choosing the value to be zero or 2*pi&#xA;                           : startHueInRadians[0];&#xA;&#xA;    endHueInRadians[0] = (endHueInRadians[0] == 0) ? &#xA;                         ((startHueInRadians[0] &amp;gt;= (Math.PI * 4)/3) ?  (float)(Math.PI * 2) : 0)&#xA;                         : endHueInRadians[0];&#xA;&#xA;&#xA;&#xA;    float a = start.getColour().getAInInt() * endPercent + end.getColour().getAInInt() * startPercent;  //Interpolating alpha, which is not working :(                   &#xA;    float h = endHueInRadians[0] * endPercent + startHueInRadians[0] * startPercent;                    //Interpolating hue.&#xA;    float s = endHueInRadians[1] * endPercent + startHueInRadians[1] * startPercent;                    //Interpolating staturation, which is useless currently. :(&#xA;    float b = endHueInRadians[2] * endPercent + startHueInRadians[2] * startPercent;                    //Interpolating value, which is useless currently. :(&#xA;&#xA;    float f[] = {h,s,b};&#xA;&#xA;    PixelData p = PixelData.HsbinRadiansToPixelData(f);     // Converting interpolated hsb back to rgb&#xA;&#xA;    p.setAInInt((int)a);    //setting the alpha value &#xA;&#xA;    return p;               // returing the intepolated value &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It is working properly but it is giant bulky code that runs very slowly because it has all kind of Ternary operator, floating point arithmetic and also it runs once per pixel.   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am currently refactoring my code to be small and less hacky. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are some interpolation algorithm that are used in computer graphics ? because i came up with this code and it is just bad.  &lt;/p&gt;&#xA;" OwnerUserId="3437" LastActivityDate="2016-06-01T00:07:41.430" Title="Is there a way to interpolate color across the line with only integer calculation ?`" Tags="&lt;algorithm&gt;&lt;color&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2542" PostTypeId="1" CreationDate="2016-05-31T21:45:28.007" Score="5" ViewCount="332" Body="&lt;p&gt;I have a post-effect camera-shader in which I want to implement a simple spatial partitioning of the screen between two passes of the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first pass should divide the screen into cells of size = 30x30 pixels, and then for each green fragment, store &lt;strong&gt;somehow&lt;/strong&gt; which of those screen cells the coordinate of such green fragment  is located. That information should then be available for the second pass to work with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, merely dividing the screen into cells is trivial, considering that it's easy to calculate the row and column indexes of such screen-grid:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static float2 _Pixels = float2(_ScreenParams.x, _ScreenParams.y);&#xA;float2 griduv = round(input.uv * _Pixels) * _invPixels; //pixel-screen space coordinate of the current fragment being evaluated&#xA;half cellsize = 30.0f;&#xA;&#xA;float gridX = griduv .x/cellsize;&#xA;float gridY = griduv .y/cellsize;&#xA;&#xA;int gridrow = gridX  - frac(gridX);&#xA;int gridcol = gridY  - frac(gridY);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If that was not a shader task but rather a standard CPU code, it would be just a matter of saving the &lt;code&gt;i&lt;/code&gt;th &lt;code&gt;griduv&lt;/code&gt; into an array-of-list or array-of-array (e.g. &lt;code&gt;float2[][] grid = new float2[gridrow*gridcol][maxNfloat2]&lt;/code&gt;) at position &lt;code&gt;grid[gridrow*gridcol+gridrow][i]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in a shader, for most hardwares and most DirectX and OpenGL versions, it seems to me that 1) we can't have multi-dimensional arrays, 2) we can't have resizable containers like lists and 3) we also can't pass variables and containers from one pass to the next.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As one can easily see, this situation is also &lt;strong&gt;not&lt;/strong&gt; well suited for using a simple texture to store values from one pass to the next, since I would need multiple &lt;code&gt;float2&lt;/code&gt; into each grid cell and I can have quite many floats to store.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, how could I proceed in such a situation? In other words, how could I store the pixel-screen coordinates of given fragments in a spatial-partitioning of the screen (in this case a simple fixed size grid of the screen), to be passed from one shader pass to the next?&lt;/p&gt;&#xA;" OwnerUserId="3410" LastEditorUserId="3410" LastEditDate="2016-06-03T00:20:14.557" LastActivityDate="2017-10-01T11:46:53.130" Title="In a shader, how to store fragment coordinates in a spatial partitioning from one pass to the next?" Tags="&lt;shader&gt;&lt;gpu&gt;&lt;fragment-shader&gt;&lt;grid&gt;&lt;space-partitioning&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2543" PostTypeId="2" ParentId="2541" CreationDate="2016-05-31T22:55:46.933" Score="6" Body="&lt;p&gt;&lt;em&gt;Yes, it is possible to use only integer calculations. I will describe how, but bear in mind that the difference in speed between integer arithmetic and floating point arithmetic is not as great as it was historically. If you want your code to run faster, it is best to profile and identify which parts of the code are taking up most time, before considering whether to convert a particular aspect to use integers.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;A straight line through colour space&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Looking at the code, it appears you first convert from RGB to &lt;a href=&quot;https://en.wikipedia.org/wiki/HSL_and_HSV&quot;&gt;HSB&lt;/a&gt; then create a linear gradient, and convert it back to RGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A linear gradient is a straight line through the colour space, so you can use an integer based straight line algorithm to generate it without the need for floating point arithmetic. For example, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bresenham&amp;#39;s_line_algorithm&quot;&gt;integer based version of Bresenham's algorithm&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;H, S, and B are being treated independently, so you can calculate each one separately. For example, the H component can be calculated by treating the line as a straight line from (x0, H0) to (x1, H1), instead of the usual (x0, y0) to (x1, y1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the range of y values along the line is greater than the range of x values along the line then Bresenham's algorithm will step along integer y values instead of x values. The algorithm can still be applied in exactly the same way, just using (y0, H0) to (y1, H1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also combine all 4 calculations into a single loop, keeping track of a parameter each for determining y value, H value, S value and B value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only difference from plotting a line on the screen (using x and y) is that not every value of H, S, and B needs to be taken. If the x range is greater than the y range, the algorithm steps through each of the x values checking whether to increment y. If the y range is greater then it instead steps through the values of y checking whether to increment x. However, if the range of H is greater than the range of x, it makes no sense to step through H values, as many of them will correspond to the same x value, wasting calculations. If the range of H is smaller than the range of x then the algorithm can proceed as usual. If the range of H is often going to be larger than the range of x then it is worth considering a different approach. Similarly for S and B.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Fitting the colour space to your line&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;One way to eliminate this problem is to tailor your colour space to the x (or y if greater) range required for this specific line. Since your input colours and final output colours are in RGB, you are not constrained to a particular range for the HSB colours. You are free to convert from 256 levels of R, G, and B to 1000 levels of H, S, and B (or 1000000, or whatever you choose). If you choose to use a colour space where the range of H values used is the same integer as the range of x values used, then you won't even need to use a line drawing algorithm for the colours. Simply store the required values for converting back to RGB, and each of the H, S, and B values will be x plus a constant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will require modifying your conversion function, but this will probably be necessary anyway, as it currently uses radians, which are not going to help with keeping things integer.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;More accurate colour spaces&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Note that using a colour space like HSB will not give gradients which look as even as if using a more perceptually uniform color space such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Lab_color_space&quot;&gt;Lab&lt;/a&gt;. However, since such spaces require calculating roots and you are looking to keep to integer arithmetic as much as possible, I'm assuming you are happy with HSB. If you did want to use something like Lab, you could still potentially keep to integers by using look up tables.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;What inputs does this need to work for?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;You also mention having to make decisions in the code which also takes up time. I would question how much difference this makes since the decisions are outside the loops and therefore only performed once. If you really want to eliminate them, ask yourself which inputs the code needs to work for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently the code checks the start and end values of the hue and decides whether to change the hue clockwise or anticlockwise. If you eliminate this check the code will still work, but it may not always give the colour direction the user intended. Deciding this automatically also may not give the direction the user intended (since different users have different expectations, and the requirement may change from one use to the next). You could simply take the direction as an additional parameter, which would avoid having to make the decision.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Code review&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;Meaningful variable names&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The use of &quot;hue&quot; in the naming of variables that store all three of hue, saturation and brightness makes the code less intuitive to read, potentially causing the reader to wonder whether saturation and brightness have been overlooked. It also makes the code difficult to reason about, since &lt;code&gt;startHueInRadians[0]&lt;/code&gt; is a hue, while &lt;code&gt;startHueInRadians[1]&lt;/code&gt; is a saturation, which is not only not a hue, but also presumably not in radians.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition to making the code more accessible to others, you may also find it easier to work with it yourself if the naming is consistent, especially if you look back at the code after a few months.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;A potential bug&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If one end of the colour gradient is at hue zero (red), the code checks whether the other end is greater than or equal to two thirds of the way around the hue circle. This corresponds to blue. If it is less than blue, then the gradient proceeds from zero upwards (anticlockwise), otherwise it proceeds from 2 pi downwards (clockwise). This means that a gradient from red to a colour with hue just above blue will go from red to magenta to blue. A gradient from red to a colour with hue just below blue will go from red to yellow to green to cyan to blue, which may not be what is expected. Intuitively, I would expect the cut off to be half way around the circle rather than two thirds, so that the gradient always includes the fewest colours (taking the shorter, more direct route).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you did intend to have this asymmetry, note that choosing a similar red with hue just above or just below zero will override this behaviour, forcing the long route or the short route respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want the gradient to consistently take the shorter route, then the code will need to check which route to take for all values, not just zero. For example, currently choosing the start hue just above zero and the finish hue just below zero will give start and finish colours that both look red, but the gradient will pass through red, yellow, green, cyan, blue, magenta and back to red, rather than just fading subtly from one hue of red to another.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-06-01T00:07:41.430" LastActivityDate="2016-06-01T00:07:41.430" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2544" PostTypeId="1" AcceptedAnswerId="2546" CreationDate="2016-06-01T17:18:50.150" Score="1" ViewCount="42" Body="&lt;p&gt;I have a scene rendered entirely with objects with additive blend mode.  I have a value that is oscillating from 0, to 1.  When it is 1 the object is supposed to be invisible, 0 should be entirely visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I have noticed that something seems off about it, specifically it stays dark for too long.  It is not my oscillating function, I suspect it having something to do with light using a logarithmic scale.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How would I convert my linear 0-&gt;1 value into a properly scaled value between 0-&gt;1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fragment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;uniform sampler2D s_texture;&#xA;&#xA;varying vec2 v_texcoord;&#xA;varying float alpha;&#xA;&#xA;void main()&#xA;{&#xA;    vec4 col = texture2D(s_texture, v_texcoord);&#xA;    gl_FragColor = vec4( col.rgba  - alpha);&#xA;&#xA;    if (col.a &amp;lt; 0.001)&#xA;    {&#xA;        discard; //11.7-&amp;gt;12.2&#xA;    }&#xA;    //gl_FragColor = vec4(0.4);&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vertex:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;attribute vec2 pos;&#xA;attribute vec2 tc;&#xA;&#xA;uniform mat4 matrix;&#xA;uniform float time;&#xA;uniform float maxLeafs;&#xA;uniform vec2 position;&#xA;uniform float instance;&#xA;uniform vec2 anchorPoint;&#xA;&#xA;&#xA;varying vec2 v_texcoord;&#xA;varying float alpha;&#xA;&#xA;vec4 finalTranslate(vec3 pos)&#xA;{&#xA;    return vec4(pos + vec3(position, 0.0), 1.0);&#xA;}&#xA;vec3 rotate(vec3 pos, float angle)&#xA;{&#xA;    float s = sin(-angle);&#xA;    float c = cos(-angle);&#xA;    return vec3(c * pos.x - s * pos.y, s * pos.x + c * pos.y, 0.0);&#xA;}&#xA;vec3 translate(vec2 pos)&#xA;{&#xA;    return vec3(pos - anchorPoint, 0.0);&#xA;}&#xA;vec3 scale(vec3 pos, float amm)&#xA;{&#xA;    return pos * amm;&#xA;}&#xA;void main()&#xA;{&#xA;&#xA;    float v = log((time * 0.9) + 0.1);&#xA;    alpha = 0.0;&#xA;&#xA;    float leafCoverage = (3.14149 * 2.0);&#xA;    float goal = ((instance) / (maxLeafs + 1.0)) * leafCoverage;&#xA;    float timeFactor = smoothstep(0.0, 1.0, time);&#xA;    float calculation1 = goal * timeFactor;&#xA;    float calculation2 = clamp(timeFactor * leafCoverage, 0.0, goal);&#xA;&#xA;    float scaleFactor = clamp(smoothstep(0.0, 1.0, time * 1.2), 0.0, 1.0);&#xA;&#xA;    gl_Position = matrix * finalTranslate(rotate( scale(translate(pos) ,scaleFactor) ,  calculation1));&#xA;    v_texcoord = tc;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Right now I am just taking the oscillating float time and passing it in directly, but eventually I will put it on a function so it fades in, temporarily is extra bright, then goes to the source texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I solved my problem, to my surprise the GLSL log function is in base e rather then 10.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2016-06-01T18:55:46.843" LastActivityDate="2016-06-02T01:03:53.487" Title="Fading an object in add mode with correct color math" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2545" PostTypeId="2" ParentId="2540" CreationDate="2016-06-01T18:01:26.300" Score="3" Body="&lt;p&gt;You have to use the appropriate register type for the resource: &lt;code&gt;b&lt;/code&gt; registers for constant buffers, &lt;code&gt;t&lt;/code&gt; for textures, and &lt;code&gt;u&lt;/code&gt; for UAVs. AFAIK, it is not possible to bind a UAV to a texture slot, or otherwise mismatch registers and resources.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, a resource can have multiple views, so it is possible to have a resource bound as a UAV in one shader and as a regular texture (SRV) in another, which enables all the usual GPU texture sampling features to be used in the latter case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The details of how the DirectX API concepts of slots, registers, and resources map to the actual hardware are vendor-specific. On one GPU they may literally represent registers of some kind, while on another they may represent a small chunk of metadata in memory somewhere, which describes the resource to the hardware.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-06-01T18:01:26.300" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2546" PostTypeId="2" ParentId="2544" CreationDate="2016-06-02T01:03:53.487" Score="1" Body="&lt;p&gt;Turns this was not an issue with the scale of the values passed in, just that the log function in glsl is base e.  The solution was merely to do log(stuff)/log(10) and that got the result of a base 10 log.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-06-02T01:03:53.487" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2547" PostTypeId="1" AcceptedAnswerId="2550" CreationDate="2016-06-02T01:07:38.570" Score="3" ViewCount="221" Body="&lt;p&gt;So I am trying to make my shader efficient by lowing the amount of texture lookups. If I had a line of code with something like.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;step(1.0, x) * texture2D(pic1, uv);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where x is a value that ranges from 0 to 2 based on the fragment position.  Would the GPU see when step evaluates to 0 and thus not ever calculate texture2D? Or would it still lookup the texture because the 0 is not constant?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW I use the term &quot;short circuit&quot; because I have been told that is what happens when you have &lt;code&gt;false &amp;amp;&amp;amp; (bla)&lt;/code&gt; the computer sees the false and ignores the right.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2016-06-02T01:29:54.797" LastActivityDate="2016-06-02T05:54:21.460" Title="GPU short circuit when multiply by 0?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2548" PostTypeId="1" AcceptedAnswerId="2549" CreationDate="2016-06-02T05:13:34.250" Score="4" ViewCount="750" Body="&lt;p&gt;I've been reading several sources in the web about transforming world-space points into camera-space ones.&#xA;I am building my view-matrix from the following parameters&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1. Camera position&#xA;2. Point the camera is looking at&#xA;3. Up vector&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I perfectly understand the meaning of each of the parameters, however, there are still some doubts.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How is the direction vector built? We have camera position and lookat position, is it camPos-lookatPos or lookatPos-camPos? In other words, does the direction vector aligns with (goes in the same direction of) the world +z-axis or is opposite to it? &lt;em&gt;Direction&lt;/em&gt; is a bit confusing since it makes me think it goes the direction the camera lens is pointing to.&lt;/li&gt;&#xA;&lt;li&gt;What's the reasoning behind translating the camera to the origin? How does this simplifies math?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;My view matrix looks like follows&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$V = \begin{matrix}&#xA;  Rx &amp;amp; Ry &amp;amp; Rz &amp;amp; 0 \\&#xA;  Ux &amp;amp; Uy &amp;amp; Uz &amp;amp; 0 \\&#xA;  Fx &amp;amp; Fy &amp;amp; Fz &amp;amp; 0 \\&#xA;  -CamPosx &amp;amp; -CamPosy &amp;amp; -CamPosz &amp;amp; 1&#xA; \end{matrix}$$&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;Will this V matrix convert from camera to world or from world to camera coordinates? How can I understand which direction it is going?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="116" LastActivityDate="2016-06-02T05:43:25.093" Title="Understanding view matrix" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2549" PostTypeId="2" ParentId="2548" CreationDate="2016-06-02T05:43:25.093" Score="1" Body="&lt;p&gt;There is no relation between &lt;code&gt;direction&lt;/code&gt;'s direction and the world axis. And that's fortunate otherwise it would mean your camera is not a free view, it's some kind of a axis bound camera, which has its usages but most likely nothing in your mind right now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The default camera matrix is looking at +z when everything is Identity, that's most surely where you got confused. Know that this is purely a convention, but sticking to a widely adopted convention allows for easy compatibility with libraries like glm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the direction vector goes outward, so its &lt;code&gt;normalize(lookat - campos)&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The view matrix can be constructed directly with TBN vectors in rows 0 1 2 :)&lt;br&gt;&#xA;(that's your RUF)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Point 2. There is no translating of the camera to the origin, that's just how you chose to view (pun) it. There is translation of world objects toward the origin. Because the rasterizer will work in device coordinates (NDC) which is not configurable, so having a roaming camera (that travels) makes it necessary to indicate its translation in world as part of the last row (row 3), and in reverse since it's not a world matrix representing the camera position, it's the matrix that will bring back points into the view space. (by the way, incidentally meaning the actual camera world matrix is the inverse of the view matrix).&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;oh, that was the last phrase of pt 2.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2016-06-02T05:43:25.093" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="2550" PostTypeId="2" ParentId="2547" CreationDate="2016-06-02T05:54:21.460" Score="4" Body="&lt;p&gt;There is a difference between being able to determine value at compilation time and at runtime.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;false &amp;amp;&amp;amp; bla&lt;/code&gt;&lt;br&gt;&#xA;Gets eliminated because of C/C++ lazy operand evaluation rule which is standardized with left to right order.&lt;br&gt;&#xA;The compiler generates no code so the machine has no overhead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;step(1.0, x) * texture2D(pic1, uv);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That will depend if x is coming from a uniform value, in which case the drivers will compile an adjustment of the shader (and put it in a combinator cache). At some point before starting to render.&lt;br&gt;&#xA;(this can cause hiccups in framerate when new uniform values are encountered that cause massive shader rebuild)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if &lt;code&gt;x&lt;/code&gt; is &lt;strong&gt;dependant&lt;/strong&gt;, which means it comes from a previous calculation that comes from varying values or system values, the compiler will cut your expression in 2 parts, the &lt;code&gt;lerp&lt;/code&gt; calculus and the &lt;code&gt;sample&lt;/code&gt; call.&lt;br&gt;&#xA;It will move the sampling of the texture in the first instructions of the shader. (provided it's unconditional in the shader flow).&lt;br&gt;&#xA;So you're basically screwed when it's 0, you'll pay the sampling anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case (0-2 wrt frag pos), I would recommend using &lt;code&gt;if (inrect(0,0,1,1))&lt;/code&gt; because this is a low frequency &quot;step&quot; function, which means very good branch elimination in 3 quarters of the screen.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2016-06-02T05:54:21.460" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2551" PostTypeId="1" AcceptedAnswerId="2552" CreationDate="2016-06-02T08:25:26.957" Score="1" ViewCount="382" Body="&lt;p&gt;I am loading a texture in a WebGL fragment shader (GLSL version 1.00).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my working code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;uniform sampler2D u_texture;&#xA;varying float v_coord;&#xA;&#xA;void main(void) {&#xA;  float inv_coord;&#xA;  gl_FragColor = texture2D(u_texture, vec2(v_coord, 0.5));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;v_coord&lt;/code&gt; holds the texture coordinates for each vertex. What I'm trying now, is to invert the texture coordinates. I thought about something like &lt;code&gt;abs(v_coord - 1)&lt;/code&gt;. However, whenever I try to substract &lt;code&gt;- 1&lt;/code&gt; from &lt;code&gt;v_coord&lt;/code&gt;, my shader fails to compile.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;uniform sampler2D u_texture;&#xA;varying float v_coord;&#xA;&#xA;void main(void) {&#xA;  float inv_coord = v_coord - 1; // fails here&#xA;  inv_coord = abs(inv_coord);&#xA;  gl_FragColor = texture2D(u_texture, vec2(inv_coord, 0.5));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Why does substracting minus one in fragment shader fail for a float data type? How to invert the texture coordinate value correctly?&lt;/p&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-06-02T08:43:46.127" Title="Why does substracting -1 in shader fail for a float data type?" Tags="&lt;texture&gt;&lt;glsl&gt;&lt;mathematics&gt;&lt;webgl&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2552" PostTypeId="2" ParentId="2551" CreationDate="2016-06-02T08:43:46.127" Score="7" Body="&lt;p&gt;Without seeing the error message I can't be sure but I think it's failing on the 1 being int instead of a float. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float inv_coord = v_coord - 1.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There is a simpler method, you can do &lt;code&gt;1.0 - v_coord&lt;/code&gt; and do away with the abs.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-06-02T08:43:46.127" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2554" PostTypeId="1" CreationDate="2016-06-02T13:29:26.403" Score="4" ViewCount="554" Body="&lt;p&gt;I'm developing a simple educational project to study OpenGL ES.&#xA;I'm try to render some simple OBJ models using Blinn-Phong.&#xA;The first version of the of my implementation calculate all the lighting equation in this way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    #version 300 es&#xA;&#xA;struct material {&#xA;    vec4 ka;&#xA;    vec4 kd;&#xA;    vec4 ks;&#xA;    float sh;&#xA;};&#xA;&#xA;struct pointLight {&#xA;    vec3 position;&#xA;    vec4 color;&#xA;};&#xA;&#xA;uniform mat4 mvMatrix;&#xA;uniform mat4 mvpMatrix;&#xA;uniform mat4 normalMatrix;&#xA;uniform pointLight light;&#xA;uniform material surfaceMaterial;&#xA;&#xA;layout(location = 0) in vec3 inputPosition;&#xA;layout(location = 1) in vec3 inputNormal;&#xA;&#xA;out vec4 v_color;&#xA;&#xA;void main() {&#xA;&#xA;    //Convert vertex and normal to camera space.&#xA;    vec3 normal = vec3(normalize(normalMatrix * vec4(inputNormal, 0.0)));&#xA;    vec4 vertexPositionHomogeneous = mvMatrix * vec4(inputPosition, 1.0);&#xA;    vec3 vertexPosition = vec3(vertexPositionHomogeneous) / vertexPositionHomogeneous.w;&#xA;&#xA;    //Calculate light direction and view direction.&#xA;    vec3 lightDirection = normalize(light.position - vertexPosition);&#xA;    vec3 viewPosition = vec3(0.0, 0.0, 1.0);&#xA;    vec3 viewDirection = normalize(-1.0 *  vertexPosition);&#xA;&#xA;    //Cosine theta diffuse lambertian component.&#xA;    float cosTheta = max(0.0, dot(normal, normalize(lightDirection)));&#xA;&#xA;    //H vector for specular component.&#xA;    vec3 h = normalize(lightDirection + viewDirection);&#xA;&#xA;    vec4 ambient = surfaceMaterial.ka * light.color;&#xA;    vec4 diffuse = surfaceMaterial.kd * light.color * cosTheta;&#xA;    vec4 specular = surfaceMaterial.ks * light.color * pow(max(0.0, dot(h, normal)), surfaceMaterial.sh);&#xA;&#xA;    //Output position and color for fragment shader.&#xA;    v_color = specular;&#xA;    gl_Position = mvpMatrix * vec4(inputPosition, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This version doesn't work. This is what I obtain:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fMfeG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fMfeG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I move the calculation to the fragment shader it works. The is the result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZiDxG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZiDxG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This image is obtained using a fragment shader that contains the same lighting calculation that I used in the vertex shader above. So my question is: why the vertex shader only version is not working? Am I missing something about how vertex and fragment shaders works? &lt;/p&gt;&#xA;" OwnerUserId="2237" LastActivityDate="2016-06-02T13:29:26.403" Title="OpenGL ES vertex/fragment shaders - Blinn phong" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;opengl-es&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2555" PostTypeId="1" AcceptedAnswerId="2558" CreationDate="2016-06-02T14:07:28.077" Score="1" ViewCount="113" Body="&lt;p&gt;As a CG assignment with OpenGL and SDL, I want to create a clone of the videogame WipeOut instead of the classical car racing game. Examples of motion in 2D have been given and are rather simple to understand; the complexity in 3D is that the road is not planar - when the vehicle approaches a cliff or a vertical loop, it should be translated on the y-axis and rotated to be mantained parallel to the road. I have no idea on how to get and update such informations (translation and rotation for the road). I thought about creating a bezier curve with informations about its derivative (overlapping the road) and keeping track of the movements of the vehicle with respect to the curve, but I don't know if it's the right (simplest) way of doing this. By the way, being able to track the position of the vehicle relative to the curve would also solve some collision problems by limiting its distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, this feature is not mandatory - I could just keep a planar road - but I'd like to understand how to do it. Suggestions?&lt;/p&gt;&#xA;" OwnerUserId="3472" LastEditorUserId="38" LastEditDate="2016-06-03T04:07:00.677" LastActivityDate="2016-06-03T17:30:58.390" Title="&quot;Anchor&quot; vehicle to 3D path with OpenGL / SDL" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2556" PostTypeId="1" AcceptedAnswerId="2568" CreationDate="2016-06-03T06:48:37.310" Score="13" ViewCount="458" Body="&lt;p&gt;So I know that I'm basically asking to identify the main problem to be solved in creating realistic 3d Graphics, but as someone without much technical experience in the field, I'm curious that if these problems can be identified, what the issue is with implementing them programmatically.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The picture below from Hitman is what I would call &quot;ultra-realistic&quot;. But, it still definitely looks like a 3d model. If you were to put a photograph of the same scene with a real actor and background, there would probably be some differences obvious enough to be able to point out which is which.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is that? &amp;lt; 100% accurate subsurface scattering? Is the lighting ever-so-slightly off? etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UH2r1.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UH2r1.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS, sorry for tag choices. I am not familiar enough with this SE to know what to choose. Please edit better ones in, if you know any.&lt;/p&gt;&#xA;" OwnerUserId="3477" LastEditorUserId="2479" LastEditDate="2016-06-03T16:08:51.047" LastActivityDate="2016-06-05T17:05:28.107" Title="What physical properties are “lacking” to keep this 3D scene from looking like a real photograph?" Tags="&lt;rendering&gt;&lt;physics&gt;&lt;photo-realistic&gt;" AnswerCount="4" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2557" PostTypeId="2" ParentId="2556" CreationDate="2016-06-03T10:02:48.540" Score="4" Body="&lt;p&gt;Hard to say because we can not see the code. Subsurface scattering might be part of that equation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would just point out that human brains are extremely specialized in facial recognition. It has been postulated that the brain has a inbuilt defence mechanism to detect alien impostors/anomalous people. You are right in middle of what is known as &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Uncanny_valley&quot; rel=&quot;nofollow&quot;&gt;uncanny valley&lt;/a&gt; nothing sort of near perfect seems to get it right, it seems&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also worth noting that we do not really know what it is that is lacking that puts you in uncanny valley. So it seems to me we do not conclusively know what, if anything, is missing. So the entire thing might be because we are neglecting something important but as of yet unknown.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-06-03T11:43:21.333" LastActivityDate="2016-06-03T11:43:21.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2558" PostTypeId="2" ParentId="2555" CreationDate="2016-06-03T17:30:58.390" Score="1" Body="&lt;p&gt;I think the most common way to have a the &quot;up and down&quot; movement of a vehicle is to actually build a physics simulation.&#xA;It does not have to be a very sophisticated one and how much realism you want is up to you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But just in each frame update the velocity of the car in downward direction (gravity) until it hits the road. Then if the road has an upward slope it will also push the car up (by colliding with the car).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you have a new problem and that is the problem that the car remains parallel to the ground-plane. And the physical calculation behind this is a bit more complex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When detecting if your car hit the ground you would have to detect the exact position of the hit (which part of the car hit the floor?). Then using the gravity, mass and some material properties (all of which you could just set globally and assume as easy values for simplicity) you can calculate how the reaction force to the collision will be. And you know that the force will be exerted on the collision point.&#xA;Now when you have the center of mass of the car, and the collision point, and the force created by the ground-collision, you can calculate how to rotate the car.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is only a very rough sketch of how I learned to handle such things in a &quot;real&quot; way. I hope this was not too confusing, if you have additional questions I can rework the answer later.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-06-03T17:30:58.390" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="2559" PostTypeId="2" ParentId="2542" CreationDate="2016-06-03T17:38:05.737" Score="1" Body="&lt;p&gt;Though I have never used them myself OpenGL in modern versions gives you something called &quot;Shader Storage Buffer Object&quot; These are buffers that you can fill with your data. They are guaranteed to be able to hold up to 16 MB of data and most implementations seem to have no problem with them taking up the whole GRAM.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This feature is core since OpenGL version 4.3.&#xA;The SSBOs are basically just a buffer that you can put any datatype in (a struct for example) and a huge amount of them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I cannot really tell you how to use them, but I think with the name you will find some resource in the web.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-06-03T17:38:05.737" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2560" PostTypeId="5" CreationDate="2016-06-03T18:01:14.717" Score="0" Body="" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-06-03T18:01:14.717" LastActivityDate="2016-06-03T18:01:14.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2561" PostTypeId="4" CreationDate="2016-06-03T18:01:14.717" Score="0" Body="For questions about the path tracing Monte Carlo algorithm for physically accurate global illumination, or its variants." OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-06-03T18:01:14.717" LastActivityDate="2016-06-03T18:01:14.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2562" PostTypeId="2" ParentId="2556" CreationDate="2016-06-03T21:32:35.773" Score="4" Body="&lt;p&gt;I think you identified the problem yourself in your question :&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;it still definitely looks like a 3d model&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's obviously hard to tell and subjective, but while many things are off in this picture, the expression and the proportions of the character model are what I find most unrealistic. It is to the appreciation of the art director, but most of the time, realism is not the main drive in shaping and animating character models. Here we have all the clichés of bland character design, and a significant lack of effort put in the expressiveness of the character. It feels 100% designed as a game persona. As such, no matter how close to reality all visual phenomenons are transcribed, my brain just won't accept it, as no-one looks like that in real life.&lt;/p&gt;&#xA;" OwnerUserId="2828" LastActivityDate="2016-06-03T21:32:35.773" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="2563" PostTypeId="1" AcceptedAnswerId="3570" CreationDate="2016-06-04T00:56:18.453" Score="9" ViewCount="1484" Body="&lt;p&gt;I would like to add full monte-carlo volumetric scattering to my path tracer, but I'm having a hard time researching how to do it. Let me explain what I would like to do:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/tOp55.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tOp55.jpg&quot; alt=&quot;Monte Carlo Volumetric Scattering&quot;&gt;&lt;/a&gt;&#xA;A ray enters a material, and we apply the BTDF, then after some distance, a volumetric scattering event happens, after which (in the isotropic case), the ray scatters in any direction in the sphere. This repeats until the ray exits the material with another BTDF. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My questions are as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How do I choose the distance between scatter events? Intuition tells me there should be some kind of scatter pdf, which gives the probability to scatter after a certain distance? &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Would this be correct?&lt;/li&gt;&#xA;&lt;li&gt;Would the pdf be a linear function for isotropic materials?&lt;/li&gt;&#xA;&lt;li&gt;Does this function have a name or something I can Google?&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Would Beer-Lambert still apply between scatter events?&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I would think not. Since Beer-Lambert is a simplification of actual scattering calculations.&lt;/li&gt;&#xA;&lt;li&gt;Then again, perhaps Beer-Lambert is a calculation at the micro scale, and path tracing is on a macro scale.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;What is the volumetric equivalent to a BSDF? It looks like I can use a phase function such as Henyey-Greenstein to determine the new direction, but what do I use for attenuation?&lt;/li&gt;&#xA;&lt;li&gt;Lastly, what are some better Google phrases for Monte-Carlo volumetric scattering? &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Searching volumetric scattering, or SSS, ends up giving papers, methods, and blog posts about the simplfications of full Monte-Carlo simulation (Dipole, in-scattering, out-scattering, diffusion, etc.)&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2016-06-06T22:50:02.707" LastActivityDate="2016-06-07T03:54:51.840" Title="Full Monte-Carlo Volumetric Scattering" Tags="&lt;pathtracing&gt;&lt;monte-carlo&gt;&lt;volumetric-scattering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="2564" PostTypeId="2" ParentId="2556" CreationDate="2016-06-04T01:00:33.120" Score="2" Body="&lt;p&gt;I see several things that are off in addition to what others have said. He doesn't appear to be breathing. He's in a very cold place (it appears to be snowing), yet there's no breath in front of his nose or mouth. It's snowing, but none of the snow is in front of him. It's all behind him, or on his clothes, but not falling around him.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I feel like our brains pick up on the subtler things, too. Like the fact that his eyebrows are just a flat texture mapped onto the geometry of his face. They're not separate hairs. Even though you couldn't resolve them very well at this distance, I think we still notice it a little. There are no specular highlights on them, either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And to me his skin looks rubbery, not alive. I know that in the cold my skin gets a little blotchy - some parts get more pinkish than others. His coloring is very even.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-06-04T01:00:33.120" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2566" PostTypeId="2" ParentId="2518" CreationDate="2016-06-04T11:55:24.110" Score="4" Body="&lt;p&gt;It speed does not matter, I suggest to use a truncated sinc or a Lanczos isotropic kernel: to compute a target pixel, you back-rotate the filter and  convolve it with the image. Since it is isotropic, it is separable and you can even use a square filter parallel to the axis of the source image.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2016-06-04T11:55:24.110" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="2567" PostTypeId="1" CreationDate="2016-06-04T17:54:49.740" Score="2" ViewCount="230" Body="&lt;p&gt;I know that OpenGL uses a projection matrix to project the view frustum directly into the canoical volume [-1, 1]^3. But how would I project the frustum into an orthographic cuboid, which would then get projected by an orthographic matrix into the canonical volume? This is purely about the theory behind the workings, I don't intend to implement it. I hope somebody can help.&lt;/p&gt;&#xA;" OwnerUserId="3484" LastActivityDate="2016-06-04T17:54:49.740" Title="How to project a view frustum in an orthographic cuboid?" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="2568" PostTypeId="2" ParentId="2556" CreationDate="2016-06-05T00:44:00.993" Score="7" Body="&lt;p&gt;Few things, but usually this is what it takes to make the difference:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1- the material reflection at his head, he is bald, yet the diffuse texture shows color difference where the hair is, this means he has a shaved head, not a natural bald, this should translate in reflection, take a look at his head, top right (top left for the image), the reflection is very smooth, no bumps at all, there should be some indication in reflection to the tiny hairs that you can see in the texture map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2- the wrinkles in his face need to be emphasized, he looks like some kind of a worrier, yet he has very smooth skin like a 15 year old has, I'm not talking about deep scars, I am talking about skin texture and bumpiness due to rough way of life, skin bumps, moles, a minor infection that will affect both coloration and bumpiness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3- his mouth is off, the size and positioning, I know that many people has small mouths, and a relatively large distance between the nose and the mouth, but that drives the attention of the viewers, it feels wrong, even if it was a photo of a real person, you can spare this kind of dragging attention to extreme shapes if reality is what you're after.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;4- This is a minor thing, but it had a role to play, the background and outfit, they look fake, this drives the viewers automatically and subconsciously to feel that this is not real, try to put more effort in these, making the outfit less uniform, and the background to have more realistic pattern, with more hue variation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;5- And last, the eyes, there's no reflection, yet the lighting is low and the image is small, so I am not sure if this is due to lighting or to the material itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That all been said, all these remarks are minor, the artwork looks awesome, I don't think a CG artwork should look like a photo, a perfectly realistic CG artwork that looks exactly like a photo, will become just another photo to the viewer.&lt;/p&gt;&#xA;" OwnerUserId="3487" LastEditorUserId="3487" LastEditDate="2016-06-05T17:05:28.107" LastActivityDate="2016-06-05T17:05:28.107" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3569" PostTypeId="1" CreationDate="2016-06-06T18:10:06.110" Score="4" ViewCount="254" Body="&lt;p&gt;For a 3D scene in the World Coordinates, its View Reference Point is at c=(0,3,4), and&#xA;a viewer is looking towards its origin O (0,0,0). Construct a transform matrix which will&#xA;map World Coordinate points to a right-handed (UVN) viewing space, so that c is the&#xA;origin, the line joining c to O is the positive N axis, and the View-Up Vector is (0,0,1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My Attempt&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VRP = (0,3,4)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VUP = (0,0,1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VPN = (0,0,0,) - c = (0,-3,-4)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;n = VPN / |VPN| = (0,-0.6,-0.8)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Stuck Here&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;u = (n x VUP) / |(n x VUP)| = &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm confused how we would solve u now?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After we have found u, I can just find v easy and then sub those values into the relevant matrices&lt;/p&gt;&#xA;" OwnerUserId="1971" LastActivityDate="2016-06-06T18:10:06.110" Title="View Reference Coordinate System" Tags="&lt;matrix&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3570" PostTypeId="2" ParentId="2563" CreationDate="2016-06-07T03:47:47.680" Score="7" Body="&lt;p&gt;First of all, a good reference for Monte Carlo path tracing in participating media is &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf&quot;&gt;these course notes&lt;/a&gt; from Steve Marschner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I like to think about volume scattering is that a photon traveling through a medium has a certain probability per unit length of interacting (getting scattered or absorbed). As long as it doesn't interact, it just goes in a straight line unimpeded and without losing energy. The greater the distance, the greater the probability that it interacts somewhere in that distance. The interaction probability per unit length is the coefficient $\sigma$ that you see in the equations. We usually have separate coefficients for scattering and absorption probabilities, so $\sigma = \sigma_s + \sigma_a$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This probability per unit length is exactly the origin of the Beer-Lambert law. Slice a ray segment into infinitesimal intervals, treat each interval as an independent possible place to interact, then integrate along the ray; you get an &lt;a href=&quot;https://en.wikipedia.org/wiki/Exponential_distribution&quot;&gt;exponential distribution&lt;/a&gt; (with rate parameter $\sigma$) for the probability of interaction as a function of distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, to answer your questions directly:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;You &lt;em&gt;can&lt;/em&gt; technically choose the distance between events however you want, as long as you correctly weight the path for the probability that a photon can make it between two adjacent events without interacting with the medium. In other words, each path segment within the medium contributes a weight factor of $e^{-\sigma x}$, where $x$ is the length of the segment. (This is assuming a homogeneous medium, but see section 4.2 in the Marschner notes linked above for what to do if it's inhomogeneous.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given this, a usually good choice for the distance is to importance-sample it from the exponential distribution. In other words, you set $x = -(\ln \xi)/\sigma$ and then leave out the $e^{-\sigma x}$ factor from the path weight.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, to account for absorption, you can use Russian roulette to kill off a fraction $\sigma_a/\sigma$ of the paths at each event. This is particularly necessary for very large or infinite media (think atmospheric scattering) where the path could bounce around for an arbitrarily long time if it's not killed. If you're only dealing with small and not-too-dense media, then it might be better to just factor in a weight of $1 - \sigma_a/\sigma$ per event, rather than using Russian roulette.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;No, if you follow the importance-sampling procedure just described, Beer-Lambert is already incorporated implicitly in the sampling, so you don't want to apply it to the path weights.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The volumetric equivalent to a BSDF is the combination of the scattering and absorption coefficients $\sigma_s, \sigma_a$ and the phase function. By convention, the coefficients control the overall balance of transmission, scattering, and absorption, while the phase function is always normalized.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could do something like this for BSDFs too; you could factor out the overall albedo, and have the directional dependence always be normalized. It's mostly a matter of convention AFAICT.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Try &quot;participating media&quot; (that is, a volumetric &quot;medium&quot;&amp;mdash;plural &quot;media&quot;&amp;mdash;which &quot;participates&quot; in light transport), and &quot;volumetric path tracing&quot;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-06-07T03:54:51.840" LastActivityDate="2016-06-07T03:54:51.840" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3571" PostTypeId="1" AcceptedAnswerId="3572" CreationDate="2016-06-07T04:35:00.773" Score="2" ViewCount="694" Body="&lt;p&gt;I am implementing simple rotation but the object is not rotating around the local center instead it is rotating around world origin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix2D m = Matrix2D.Rotate((float) (Math.PI));&#xA;&#xA;Point p =  new Point(new Vector2D(-0.1f,0.7f),this, new PixelData(255, 255, 0, 0));&#xA;Point p2 = new Point(new Vector2D(0,0.8f),this, new PixelData(255, 255, 0, 0));&#xA;Point p3 = new Point(new Vector2D(0.1f,0.7f),this, new PixelData(255, 255, 0, 0));&#xA;&#xA;Vector2D v = Matrix2D.MatrixTimesVector2D(m, p.getPosition());&#xA;Vector2D v2 = Matrix2D.MatrixTimesVector2D(m, p2.getPosition());&#xA;Vector2D v3 = Matrix2D.MatrixTimesVector2D(m, p3.getPosition());&#xA;&#xA;Point z = new Point(v, this, p.getColour());&#xA;Point z2 = new Point(v2, this, p.getColour());&#xA;Point z3 = new Point(v3, this, p.getColour());&#xA;&#xA;new Triangle(z2.Transform(), z.Transform(), z3.Transform(),this).DrawTriangle();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I checked my matrices and matrix multiplication is correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result without rotation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CcoSg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CcoSg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And after rotation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3eTRX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3eTRX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why i am getting this weird rotation ?&lt;/p&gt;&#xA;" OwnerUserId="3437" LastEditorDisplayName="user7220" LastEditDate="2018-05-10T20:12:30.460" LastActivityDate="2018-05-10T20:12:30.460" Title="Object rotating around origin instead of object center?" Tags="&lt;transformations&gt;&lt;mathematics&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="3572" PostTypeId="2" ParentId="3571" CreationDate="2016-06-07T06:23:58.637" Score="3" Body="&lt;p&gt;Your triangle's coordinates: &#xA;(-0.1f,0.7f)&#xA;(0.0f,0.8f)&#xA;(0.1f,0.7f)&#xA;are defined with the origin at the center of the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Multiplying a rotation matrix by a vertex position will rotate around the point (0,0,0). In your case, that is the center of the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Possible solution:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Define the vertices as: (-0.1f,-0.5f) (0.0f,0.5f,) and (0.1f,-0.5f)&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Rotate the vertices with your rotation matrix (Like you did):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vector2D v = Matrix2D.MatrixTimesVector2D(m, p.getPosition());&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vector2D v2 = Matrix2D.MatrixTimesVector2D(m, p2.getPosition());&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vector2D v3 = Matrix2D.MatrixTimesVector2D(m, p3.getPosition());&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you want your triangle at the top of you screen, use a translation matrix:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XYXUs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XYXUs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I'm not sure what language/library you are using, but create a translation matrix by yourself or using a built in fuction. Above dx, dy and dz are the translations in x,y and z.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Multiply your positions v, v2 and v3 by the translation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Google tranlsation and rotation matrix and you will understand better! Good luck!&lt;/p&gt;&#xA;" OwnerUserId="3434" LastActivityDate="2016-06-07T06:23:58.637" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3573" PostTypeId="1" AcceptedAnswerId="3574" CreationDate="2016-06-07T13:37:24.170" Score="2" ViewCount="336" Body="&lt;p&gt;I have a program I wrote that allows chromakey (green screen) using a web cam. I wrote it using DirectShow - I created a custom filter to blend the web cam video with a graphic. It works fine but requires huge amounts of CPU. Also, from what I understand, DS is deprecated - or at least on its way out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I'm thinking about re-doing it with OpenGL and using OpenCV to grab the web cam video. I don't have a lot of experience with OpenGL, so my question is: If I create a chromakey shader will it be executed on the GPU and therefore be faster? Or is this something for which OpenGL is not useful?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like the input of someone with experience before I attempt this.&lt;/p&gt;&#xA;" OwnerUserId="4497" LastActivityDate="2016-06-07T14:35:14.047" Title="Chromakey Conversion" Tags="&lt;opengl&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3574" PostTypeId="2" ParentId="3573" CreationDate="2016-06-07T14:35:14.047" Score="1" Body="&lt;p&gt;It almost certainly depends on implementation. I have used CPU only keyers that had no problems keying full hd in real time. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But back to the question would a shader be faster? Most likely, especially if your chroma key is a classic color transform. Then the GPU would shine as it would get to use it massive multicore architecture to full potential.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-06-07T14:35:14.047" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3575" PostTypeId="1" AcceptedAnswerId="3576" CreationDate="2016-06-07T21:13:56.997" Score="61" ViewCount="39329" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Vulkan_(API)&quot;&gt;From the wiki&lt;/a&gt;: &quot;the Vulkan API was initially referred to as the 'next generation OpenGL initiative' by Khrono&quot;, &lt;a href=&quot;https://en.wikipedia.org/wiki/OpenGL#Vulkan&quot;&gt;and that it is&lt;/a&gt; &quot;a grounds-up redesign effort to unify OpenGL and OpenGL ES into one common API that will not be backwards compatible with existing OpenGL versions&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So should those now getting into graphics programming be better served to learn Vulkan instead of OpenGL? It seem they will serve the same purpose.&lt;/p&gt;&#xA;" OwnerUserId="3477" LastEditorUserId="2041" LastEditDate="2016-06-11T01:01:18.187" LastActivityDate="2020-01-13T06:29:17.227" Title="Should new graphics programmers be learning Vulkan instead of OpenGL?" Tags="&lt;opengl&gt;&lt;api&gt;&lt;vulkan&gt;" AnswerCount="9" CommentCount="1" FavoriteCount="22" ContentLicense="CC BY-SA 3.0" />
  <row Id="3576" PostTypeId="2" ParentId="3575" CreationDate="2016-06-07T21:20:37.550" Score="37" Body="&lt;p&gt;Hardly!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems a lot like asking &quot;Should new programmers learn C++ instead of C,&quot; or &quot;Should new artists be learning digital painting instead of physical painting.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Especially because it's NOT backward compatible, graphics programmers would be foolish to exclude the most common graphics API in the industry, simply because there's a new one. Additionally, OpenGL does different things differently. It's entirely possible that a company would choose OpenGL over Vulkan, especially this early in the game, and that company would not be interested in someone who doesn't know OpenGL, regardless of whether they know Vulkan or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specialization is rarely a marketable skill.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For those who don't need to market their skills as such, like indie developers, it'd be even MORE foolish to remove a tool from their toolbox. An indie dev is even more dependent on flexibility and being able to choose what works, over what's getting funded. Specializing in Vulkan only limits your options.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specialization is rarely an efficient paradigm.&lt;/p&gt;&#xA;" OwnerUserId="4494" LastEditorUserId="4494" LastEditDate="2016-06-07T21:25:46.773" LastActivityDate="2016-06-07T21:25:46.773" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="3577" PostTypeId="2" ParentId="3575" CreationDate="2016-06-08T01:02:11.473" Score="7" Body="&lt;p&gt;The primary appeal of OpenGL (at least to me) is that it works on many platforms. Currently, Vulkan does not work on OSX, and Apple has a competing API called Metal. It's very possible that it will be some time before Apple supports Vulkan, and when they do, Vulkan support may only come to their latest hardware. OpenGL already supports most hardware, and will continue to do so.&lt;/p&gt;&#xA;" OwnerUserId="4499" LastActivityDate="2016-06-08T01:02:11.473" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3578" PostTypeId="2" ParentId="3575" CreationDate="2016-06-08T07:27:09.513" Score="3" Body="&lt;p&gt;It depends on what you want to do. If you want to learn graphics programming only for yourself, it really doesn't matter what you choose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are thinking about professional work I recommend Vulkan. It is closer to hardware and I think knowledge about what hardware do is important for graphics programmers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan is closer to hardware because OpenGL does a lot of stuff under the hood which in Vulkan you do manually, like execute command queue.&#xA;Also memory management is up to application not driver. You need to worry about allocate memory for &lt;code&gt;uniforms&lt;/code&gt;(variable that you pass from CPU to GPU), about tracking them. You have more things to worry about but also it gives more freedom on usage of memory.&#xA;It can sound scary and overwhelming but it really isn't. It's only next API that you need to learn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Understanding this things also will help in understanding how GPU work. What will allow you to do some optimization both on Vulkan and OpenGL. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And one more thing that come to my mind, if you are starting to learn graphics programming probably when you look for a job as one Vulkan will be more popular (maybe more popular than OpenGL). Also, as far as I know most of companies that are using some graphics API write own functions around it so there is a chance that on the job you will not be writing in OpenGL nor in Vulkan but knowledge about GPU will be always useful.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorDisplayName="user246" LastEditDate="2017-04-24T10:19:22.833" LastActivityDate="2017-04-24T10:19:22.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3579" PostTypeId="2" ParentId="3575" CreationDate="2016-06-08T10:29:07.650" Score="46" Body="&lt;p&gt;If you're getting started now, and you want to do GPU work (as opposed to always using a game engine such as Unity), you should definitely start by learning Vulkan. Maybe you should learn GL later too, but there are a couple of reasons to think Vulkan-first.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;GL and GLES were designed many years ago, when GPUs worked quite differently. (The most obvious difference being immediate-mode draw calls vs tiling and command queues.) GL encourages you to think in an immediate-mode style, and has a lot of legacy cruft. Vulkan offers programming models that are much closer to how contemporary GPUs work, so if you learn Vulkan, you'll have a better understanding of how the technology really works, and of what is efficient and what is inefficient. I see lots of people who've started with GL or GLES and immediately get into bad habits like issuing separate draw calls per-object instead of using VBOs, or even worse, using display lists. It's hard for GL programmers to find out what is no longer encouraged.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;It's much easier to move from Vulkan to GL or GLES than vice-versa. Vulkan makes explicit a lot of things that were hidden or unpredictable in GL, such as concurrency control, sharing, and rendering state. It pushes a lot of complexity up from the driver to the application: but by doing so, it gives control to the application, and makes it simpler to get predictable performance and compatibility between different GPU vendors. If you have some code that works in Vulkan, it's quite easy to port that to GL or GLES instead, and you end up with something that uses good GL/GLES habits. If you have code that works in GL or GLES, you almost have to start again to make it work efficiently in Vulkan: especially if it was written in a legacy style (see point 1).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I was concerned at first that Vulkan is much harder to program against, and that while it would be OK for the experienced developers at larger companies, it would be a huge barrier to indies and hobbyists. I posed this question to some members of the Working Group, and they said they have some data points from people they've spoken to who've already moved to Vulkan. These people range from developers at Epic working on UE4 integration to hobbyist game developers. Their experience was that getting started (i.e. getting to having one triangle on the screen) involved learning more concepts and having longer boilerplate code, but it wasn't too complex, even for the indies. But after getting to that stage, they found it much easier to build up to a real, shippable application, because (a) the behaviour is a lot more predictable between different vendors' implementations, and (b) getting to something that performed well with all the effects turned on didn't involve as much trial-and-error. With these experiences from real developers, they convinced me that programming against Vulkan is viable even for a beginner in graphics, and that the overall complexity is less once you get past the tutorial and starting building demos or applications you can give to other people.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As others have said: GL is available on many platforms, WebGL is a nice delivery mechanism, there's a lot of existing software that uses GL, and there are many employers hiring for that skill. It's going to be around for the next few years while Vulkan ramps up and develops an ecosystem. For these reasons, you'd be foolish to rule out learning GL entirely. Even so, you'll have a much easier time with it, and become a better GL programmer (and a better GPU programmer in general), if you start off with something that helps you to understand the GPU, instead of understanding how they worked 20 years ago.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, there's one option more. I don't know whether this is relevant to you in particular, but I feel I should say it for the other visitors anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be an indie games developer, or a game designer, or to make VR experiences, you don't need to learn Vulkan or GL. Many people get started with a games engine (Unity or UE4 are popular at the moment). Using an engine like that will let you focus on the experience you want to create, instead of the technology behind it. It will hide the differences between GL and Vulkan from you, and you don't need to worry about which is supported on your platform. It'll let you learn about 3D co-ordinates, transforms, lighting, and animation without having to deal with all the gritty details at once. Some game or VR studios only work in an engine, and they don't have a full-time GL expert at all. Even in larger studios which write their own engines, the people who do the graphics programming are a minority, and most of the developers work on higher-level code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Learning about the details of how to interact with a GPU is certainly a useful skill, and one that many employers will value, but you shouldn't feel like you have to learn that to get into 3D programming; and even if you know it, it won't necessarily be something you use every day.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2016-06-10T16:00:06.960" LastActivityDate="2016-06-10T16:00:06.960" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3580" PostTypeId="1" AcceptedAnswerId="3590" CreationDate="2016-06-08T13:28:33.330" Score="8" ViewCount="2368" Body="&lt;p&gt;This question was originally asked on Physics, then moved to &lt;a href=&quot;https://cogsci.stackexchange.com/questions/15186/why-does-checkerboard-pattern-on-a-computer-screen-appear-with-a-yellowish-tint&quot;&gt;Cognitive Sciences&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the following image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/IxOzp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IxOzp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;You might want to display the image in a new page, in case it gets resized for mobile displays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the top half, there is a pixel-sized checkerboard pattern with alternating black and white pixels; on the bottom half, there's a black to white gradient. Now, I don't know if you see the same, but for me, when viewing from distance or defocusing my eyes and the top half blending into one color, I can't find any color in the gradient below which would match it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With simple arithmetics, I would guess at first guess the resulting color be either RGB $(0.5, 0.5, 0.5)$ or, with gamma, $(\sqrt{0.5}, \sqrt{0.5}, \sqrt{0.5})$. I cannot help myself, but the resulting color appears a lot warmer than the metallic gray which would appear if you for example zoomed this page or used a blur filter. I tried to add some yellow to the gradient, and the result looks more similar to the perceived color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, based on the comments, it appears some people perceive yellowish tint and some don't. And I do on my LCD computer screen but not on my mobile display. Thus I guess it's based on some property of the display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why don't we perceive the resulting color like real gray? Where does the yellow color come from?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a theory: Based on the &lt;a href=&quot;https://upload.wikimedia.org/wikipedia/commons/4/4d/Pixel_geometry_01_Pengo.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;color arrangement in a typical LCD pixel&lt;/a&gt;, one white pixel would contain the red and green color together and blue on the right side. Blue color appears darker to human eye than colors with the same physical intensity, so a white pixel is more green than red than blue. Green and red have roughy the same perceptional insensity, and mixing red and green color addivitely gives yellow, thus the yellow tint? Well, shouldn't then all white pixels on the display appear a bit yellow?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this possible? Are there any other explanations?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A side question: Do you know any computer image scaling algorithm or blur filter that tries to mimic this, simulating a blurry vision of a human eye correctly?&lt;/p&gt;&#xA;" OwnerUserId="4490" LastEditorUserId="-1" LastEditDate="2017-04-13T12:56:17.167" LastActivityDate="2016-06-09T16:20:01.487" Title="Why does checkerboard pattern on a computer screen appear with a yellowish tint?" Tags="&lt;color&gt;&lt;pixel-graphics&gt;&lt;color-management&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3581" PostTypeId="2" ParentId="3575" CreationDate="2016-06-08T16:04:31.510" Score="-1" Body="&lt;p&gt;You should be learning OpenGL first, as that is the standard for Graphics, across so many platforms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if there is a newer library, understanding the basics, and working with a language that is used all over the industry, is very important... Especially since Vulkan wont be used in Big Companies for awhile, since.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;No one wants to adapt right away and end up screwing themselves over with a non-stable Framework/Library.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;They would need to hire / re-train their current Open-GL programmers, and there is no need to.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Also, I've heard that OpenGL, and Vulkan, aren't exactly the same.  I hear Vulkan is a lower level API, and closer to machine code, than OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This answer I just found seems to have a lot of great info&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://gamedev.stackexchange.com/questions/96014/what-is-vulkan-and-how-does-it-differ-from-opengl&quot;&gt;https://gamedev.stackexchange.com/questions/96014/what-is-vulkan-and-how-does-it-differ-from-opengl&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Another thing that is something to consider is the issue that happened back with OpenGL 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL 1 to OpenGL 2 had MAJOR changes, and since many people were using OpenGL1, and hardware supported it, there is heavy backwards compatibility needed to be implemented in some applications/engines, and that sometimes is really painful for the devs to keep supporting it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Besides the support, the language shifted so much, that you had to learn new stuff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This has happened with frameworks such as JavaFX (from 1.x to 2.x) and Play! Framework (Also 1.x to 2.x).  Complete changes to the framework, meaning we have to relearn... everything...&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;So essentially what you should do is wait until Vulkan is STABLE.  That means wait until Probably the 2.0 patch.  IT doesn't mean you cannot learn about the basics of Vulkan, but just know this might change.  I would assume that a group like Kronos would provide a very stable API from the start, especially since there are multiple Nvidia and AMD engineers working on Vulkan, including a high up Nvidia person overseeing the project apparently, as well as The base of Mantle; however, like any software, we the coders will see how well it works from the start, but many are wary and waiting to see what happens.&lt;/p&gt;&#xA;" OwnerUserId="3420" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2016-06-09T16:13:28.647" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="3583" PostTypeId="2" ParentId="3575" CreationDate="2016-06-09T04:38:43.670" Score="2" Body="&lt;p&gt;I've been &quot;getting in to&quot; graphics programming for a few months now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now I'm still in High School, and I can tell you I am almost always looking to develop cross platform applications. This is in fact my number one problem with Vulkan - It isn't developed to work on all platforms. I work with OpenGL in Java and have for over 6 months.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another problem I have is with Vulkan's claims is how it claims to be better. While OpenGL certainly isn't updating their website very often. They continue to constantly release updates and I always look forward to new updates that run faster or work better with new hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, while I mostly work with OpenGL I understand basic principles of DirectX and Vulkan. While I don't work with them extensively, especially Vulkan as it's very hard to learn and not as well structured for programming as OpenGl and DirectX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, I'd like to add that specializing in a single field like I mostly use Java and OpenGL isn't amazingly marketable standalone. If I wanted to get a job at a company that made games, for the most part OpenGL would only be used to make games for Linux and Android development and possibly OSX. DirectX for Windows and Consoles &amp;lt; Which Vulkan can replace in some cases. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't hold out for OpenGL updates forever, and I wont. But it's my preference for developing.&lt;/p&gt;&#xA;" OwnerUserId="4522" LastActivityDate="2016-06-09T04:38:43.670" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3584" PostTypeId="1" AcceptedAnswerId="3585" CreationDate="2016-06-09T06:35:26.767" Score="2" ViewCount="515" Body="&lt;p&gt;This is my code of the algorithm for making triangles :-&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-java prettyprint-override&quot;&gt;&lt;code&gt;private void sort(){&#xA;    int temp = Math.round(m_Vertex1.getPosition().getX());&#xA;    int temp2 = Math.round(m_Vertex2.getPosition().getX());&#xA;    int temp3 = Math.round(m_Vertex3.getPosition().getX());&#xA;&#xA;    m_minX = Math.min(temp3, Math.min(temp, temp2));    //Sorting the X values&#xA;    m_maxX = Math.max(temp3, Math.max(temp, temp2));&#xA;&#xA;    temp = Math.round(m_Vertex1.getPosition().getY()); &#xA;    temp2 = Math.round(m_Vertex2.getPosition().getY());&#xA;    temp3 = Math.round(m_Vertex3.getPosition().getY());&#xA;&#xA;    m_minY = Math.min(temp3, Math.min(temp, temp2));    // Sorting the Y values&#xA;    m_maxY = Math.max(temp3, Math.max(temp, temp2));&#xA;}&#xA;&#xA;public void DrawTriangle(){ &#xA;    new Line(m_Vertex1, m_Vertex2, m_display).DrawLine(Optional.of(EdgeOnePoints));     //Getting all the points on the boundary of the triangle&#xA;    new Line(m_Vertex2, m_Vertex3, m_display).DrawLine(Optional.of(EdgeTwoPoints));&#xA;    new Line(m_Vertex1, m_Vertex3, m_display).DrawLine(Optional.of(EdgeThreePoints));&#xA;&#xA;    Vector2D start = Vector2D.zero();&#xA;    Vector2D end = Vector2D.zero();&#xA;&#xA;    for(float i = m_minY; i &amp;lt;= m_maxY ;i++){        //Iterating from top to bottom of the triangle&#xA;&#xA;        for(float j = m_minX; j &amp;lt;= m_maxX; j++){    //Iterating left to right of the triangle&#xA;            Vector2D temp = new Vector2D(j,i);&#xA;&#xA;            if(EdgeOnePoints.contains(temp) || EdgeTwoPoints.contains(temp) || EdgeThreePoints.contains(temp)){  &#xA;                if(start.equals(Vector2D.zero())){      // Getting the first point of intersection between the triangle and the scanline &#xA;                    start = temp;&#xA;                }else{&#xA;                    if(EdgeOnePoints.contains(start) &amp;amp;&amp;amp; !EdgeOnePoints.contains(temp)){     // Checking if start point and end point are on the same edge or not, if not then it is a valid point else not.&#xA;                        end = temp;&#xA;                        break;&#xA;                    }else if(EdgeTwoPoints.contains(start) &amp;amp;&amp;amp; !EdgeTwoPoints.contains(temp)){&#xA;                        end = temp;&#xA;                        break;&#xA;                    }else if(EdgeThreePoints.contains(start) &amp;amp;&amp;amp; !EdgeThreePoints.contains(temp)){&#xA;                        end = temp;&#xA;                        break;&#xA;                    }&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        if(!start.equals(Vector2D.zero()) &amp;amp;&amp;amp; !end.equals(Vector2D.zero())){ //if both start and end points are available then draw then fill all the points in between them.&#xA;            for(float j = start.getX(); j &amp;lt;= end.getX(); j++){&#xA;                new Point(new Vector2D(j, i), PixelData.white(), m_display).DrawPoint();&#xA;            }&#xA;        }&#xA;&#xA;        start = Vector2D.zero(); &#xA;        end = Vector2D.zero();   &#xA;    }&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now i have couple of problems with it :- &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;It is a tortoise, i have tested it on a old machine and just with 2 rotating triangles, the frame rate is below 30.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;i get this weird line in between the triangle at some specific position when rotating the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6KsEH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6KsEH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;   &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I don't care much about the second problem but can anyone help me making this algorithm fast. should i use something like flood fill or boundary fill algorithm ?&lt;/p&gt;&#xA;" OwnerUserId="3437" LastEditorUserId="182" LastEditDate="2016-06-13T08:18:36.273" LastActivityDate="2016-06-13T08:18:36.273" Title="scan line algorithm is too slow?" Tags="&lt;algorithm&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3585" PostTypeId="2" ParentId="3584" CreationDate="2016-06-09T07:15:28.370" Score="8" Body="&lt;p&gt;One red flag is the use of &lt;code&gt;new&lt;/code&gt; several times within the loop. Memory allocation doesn't belong in a rasterizer! :) Certainly you should not need to allocate a &lt;code&gt;Point&lt;/code&gt; object (which is used once and then immediately discarded) and do a method call on it, just in order to fill a single pixel! The pixels are hopefully stored as a flat array of bytes, so just write directly to the appropriate address in it. Similarly, don't allocate a &lt;code&gt;Vector2D&lt;/code&gt; every time through, just create one (ideally on the stack, if the language you're using allows for it), and re-use it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Secondly, the algorithm you're using doesn't seem to be a true scanline rasterizer. It iterates over the pixels in each line from left to right, performing edge tests on every single pixel to determine whether it's inside or outside, and recording when that state changes in the &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way a scanline rasterizer is supposed to work (which is much faster) is to &lt;em&gt;calculate&lt;/em&gt; the intersection points of each edge with the scanline (using good old school algebra line-line intersection math). Ideally you would have already categorized and sorted the three edges as left, right, or horizontal and therefore once you have the intersection points, it's easy to figure out the interval that the triangle covers on the scanline. Then you can iterate over that and shade or fill each pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, I'm not sure if this is a real issue or not, but there are a lot of method calls for relatively trivial things like checking whether vectors are equal, or doing an edge-vs-point test. Hopefully the compiler is inlining all those, but you might want to check the generated code to see. If it's not, you could see a fair speedup by manually inlining that stuff, and possibly manually &quot;destructuring&quot; the vectors (i.e. replace a Vector2D variable by two explicit x and y variables).&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-06-09T07:15:28.370" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3586" PostTypeId="1" CreationDate="2016-06-09T07:40:03.600" Score="3" ViewCount="6478" Body="&lt;p&gt;I have been reading a lot of debate on a new feature that will be available in the new version of the game engine Unity 5.4 - called GPU instancing. I understand the importance of instancing in general, both in terms of saving memory and draw calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, even after doing some reading, I still couldn't understand what exactly are the differences between GPU instancing and non-GPU instancing - and, more importantly, where the alleged GPU advantages in terms of performance come from in comparison to standard instancing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for your knowledge and for any references.&lt;/p&gt;&#xA;" OwnerUserId="2061" LastActivityDate="2018-04-09T09:41:17.210" Title="What are the differences between GPU instancing and standard instancing?" Tags="&lt;gpu&gt;&lt;performance&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3587" PostTypeId="1" AcceptedAnswerId="3598" CreationDate="2016-06-09T12:46:18.310" Score="1" ViewCount="54" Body="&lt;p&gt;I am trying to devise a GUI system that functions as a virtual patchbay, as seen in something like Logic Studio's environment editor, or seen in virtual synthesizers that use virtual patchcables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not much of a coder, so I've been experimenting with LiveCode.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The challenge seems to be part code, part graphical. I can't even fathom how a system like that works. What bitmaps should I produce (if any) and how should they be manipulated in code? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any assistance would be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="4528" LastActivityDate="2016-06-10T19:57:34.127" Title="How would I create a virtual cabling system?" Tags="&lt;line-drawing&gt;&lt;physics&gt;&lt;simulation&gt;&lt;edge-detection&gt;&lt;realistic&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3588" PostTypeId="1" AcceptedAnswerId="3591" CreationDate="2016-06-09T12:53:14.763" Score="0" ViewCount="85" Body="&lt;p&gt;I have made an 3d solar exposure analysis for a 3d city model that determines how long a surface receive direct sunlight throughout the year. Results are coloured surfaces and legend of coloures that explain how long the colour means. You can see the results in the attaching file. How can I report the results. How can I convert visualization into data? Because I want to query the results of analysis&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uwKxk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uwKxk.jpg&quot; alt=&quot;analysisi results&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4513" LastActivityDate="2016-06-09T16:33:53.057" Title="How to convert image results into data?" Tags="&lt;raytracing&gt;&lt;3d&gt;&lt;model&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3589" PostTypeId="2" ParentId="3575" CreationDate="2016-06-09T15:43:51.957" Score="35" Body="&lt;p&gt;Learning graphics programming is about more than just learning APIs. It's about learning how graphics works. Vertex transformations, lighting models, shadow techniques, texture mapping, deferred rendering, and so forth. These have absolutely nothing to do with the API you use to implement them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is this: do you want to learn how to use an API? Or do you want to learn &lt;em&gt;graphics&lt;/em&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to do stuff with hardware-accelerated graphics, you have to learn how to use an API to access that hardware. But once you have the ability to interface with the system, your graphics learning stops focusing on what the API does for you and instead focuses on graphics concepts. Lighting, shadows, bump-mapping, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your goal is to learn graphics concepts, the time you're spending with the API is time you're not spending &lt;em&gt;learning graphics concepts&lt;/em&gt;. How to compile shaders has nothing to do with graphics. Nor does how to send them uniforms, how to upload vertex data into buffers, etc. These are tools, and important tools for doing graphics work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But they aren't actually graphics concepts. They are a means to an end.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It takes a &lt;em&gt;lot&lt;/em&gt; of work and learning with Vulkan before you can reach the point where you're ready to start learning graphics concepts. Passing data to shaders requires explicit memory management and explicit synchronization of access. And so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By contrast, getting to that point with OpenGL requires less work. And yes, I'm talking about modern, shader-based core-profile OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just compare what it takes to do something as simple as clearing the screen. In Vulkan, this requires at least some understanding of a large number of concepts: command buffers, device queues, memory objects, images, and the various WSI constructs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL... it's three functions: &lt;code&gt;glClearColor&lt;/code&gt;, &lt;code&gt;glClear&lt;/code&gt;, and the platform-specific swap buffers call. If you're using more modern OpenGL, you can get it down to two: &lt;code&gt;glClearBufferuiv&lt;/code&gt; and swap buffers. You don't need to know what a framebuffer is or where its image comes from. You clear it and swap buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because OpenGL hides a lot from you, it takes a lot less effort to get to the point where you're actually learning graphics as opposed to learning the interface to graphics hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, OpenGL is a (relatively) safe API. It will issue errors when you do something wrong, usually. Vulkan is not. While there are debugging layers that you can use to help, the core Vulkan API will tell you almost nothing unless there is a hardware fault. If you do something wrong, you can get garbage rendering or crash the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Coupled with Vulkan's complexity, it becomes very easy to accidentally do the wrong thing. Forgetting to set a texture to the right layout may work under one implementation, but not another. Forgetting a sychronization point may work sometimes, but then suddenly fail for seemingly no reason. And so forth.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;All that being said, there is more to learning graphics than learning graphical techniques. There's one area in particular where Vulkan wins.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Graphical &lt;em&gt;performance&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Being a 3D graphics programmer usually requires some idea of how to optimize your code. And it is here where OpenGL's hiding of information and doing things behind your back becomes a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The OpenGL memory model is synchronous. The implementation is allowed to issue commands asynchronously so long as the user cannot tell the difference. So if you render to some image, then try to read from it, the implementation must issue an explicit synchronization event between these two tasks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in order to achieve performance in OpenGL, you have to know that implementations do this, so that you can &lt;em&gt;avoid it&lt;/em&gt;. You have to realize where the implementation is secretly issuing synchronization events, and then rewrite your code to avoid them as much as possible. But the API itself doesn't make this obvious; you have to have gained this knowledge from somewhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With Vulkan... &lt;em&gt;you&lt;/em&gt; are the one who has to issue those synchronization events. Therefore, you &lt;em&gt;must&lt;/em&gt; be aware of the fact that the hardware does not execute commands synchronously. You must know when you need to issue those events, and therefore you must be aware that they will probably slow your program down. So you do everything you can to avoid them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An explicit API like Vulkan forces you to make these kinds of performance decisions. And therefore, if you learn the Vulkan API, you already have a good idea about what things are going to be slow and what things are going to be fast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have to do some framebuffer work that forces you to create a new renderpass... odds are good that this will be slower than if you could fit it into a separate subpass of a renderpass. That doesn't mean you can't do that, but the API tells you up front that it could cause a performance problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL, the API basically invites you to change your framebuffer attachments willy-nilly. There's no guidance on which changes will be fast or slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in that case, learning Vulkan can help you better learn about how to make graphics faster. And it will certainly help you reduce CPU overhead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It'll still take much longer before you can get to the point where you can learn graphical rendering techniques.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-06-09T15:43:51.957" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="3590" PostTypeId="2" ParentId="3580" CreationDate="2016-06-09T16:20:01.487" Score="11" Body="&lt;p&gt;Because your monitor is not properly calibrated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On my screen at home the top and bottom parts have the same hue. At my office though, the top part tends to looks a bit yellow compared to the bottom part that looks more red.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference: my screen at home was from a series that was decently calibrated out of the factory, and on top of that I did calibrate it properly with a color calibration tool. That was quite some years ago and its colors have probably degraded since, but it still makes a difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A poorly calibrated monitor will not display exactly the color intensity requested for R, G and B, resulting in differences between the color that should be displayed and the one actually displayed. It can even vary depending the area of the screen (many consumer level LCD screens tend to have more light leaking near the edges for example).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image you included is a good example to highlight a calibration issue, because it allows to compare directly the average color at 50% intensity (combining two halves at 0% and 100% intensity) with the color displayed when requesting 50% intensity. Moreover, the gradient allows to see if the hue is constant from 0% to 100% intensity.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-06-09T16:20:01.487" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3591" PostTypeId="2" ParentId="3588" CreationDate="2016-06-09T16:33:53.057" Score="1" Body="&lt;p&gt;I think getting the real data with high precision is not easy without some API.&#xA;The first idea would be just to manually use some color based selection tool that you can tell to select all areas in the screenshots according to the lookup table.&#xA;But that would not result in some 3D data, but only segmented images where you can annotate the values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another method would be to make a UV-map of the mesh, and then by making screenshots from various regions try to extract the color-coded texture.&#xA;Then you could read the interpolated color-values of the texture and map them back to the actual values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last but maybe strangest idea would be to make a huge number of screenshots and then use some multiview object reconstruction algorithm (I don't know if there is software or if you have to write it yourself.). There are algorithms that not only reconstruct the geometry, but also the texture.&#xA;This would then give you a model with the color-texture that again you could map back to the values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But ideally there would be some export function in the software you used. Maybe this is a question you should ask the developer of the software. Maybe they have this function somehow but it is a bit hidden.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-06-09T16:33:53.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3593" PostTypeId="1" AcceptedAnswerId="3599" CreationDate="2016-06-10T13:59:01.767" Score="1" ViewCount="602" Body="&lt;p&gt;I know there are tons of questions about it, but I found nothing useful so far so, here I am.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to render a texture which is attached to a wavefront .obj mesh. I continued to fail (somehow, it was like textures were not correctly loaded), so I wrote a simple example code to see where I was wrong. The sample code follows, and the texture is &quot;correctly&quot; loaded and rendered. However, there are some problems in the render itself: the image is incomplete / blurry / repeated / distorted. I will also post the expected result and the actual result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Working on Linux Ubuntu 14.04, OpenGL 3.0 Mesa 10.5.9.&#xA;Any idea of what is happening?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Texture (copyright Angryfly @ Turbosquid) and result on the right:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/9VeLs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9VeLs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sample code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;math.h&amp;gt;&#xA;#include &amp;lt;GL/gl.h&amp;gt;&#xA;#include &amp;lt;GL/glu.h&amp;gt;&#xA;#include &amp;lt;SDL2/SDL.h&amp;gt;&#xA;#include &amp;lt;SDL2/SDL_image.h&amp;gt;&#xA;#include&amp;lt;iostream&amp;gt;&#xA;&#xA;int main(int argc, char* argv[]) {&#xA;    SDL_Init( SDL_INIT_VIDEO );&#xA;    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );&#xA;    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );&#xA;    // prepare the window&#xA;    SDL_Window *window = SDL_CreateWindow(argv[0], 0, 0,&#xA;            800, 600,&#xA;            SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);&#xA;    SDL_GLContext context = SDL_GL_CreateContext(window);&#xA;    // enable textures and bind a name (say 50)&#xA;    glEnable(GL_TEXTURE_2D);&#xA;    glBindTexture(GL_TEXTURE_2D, 50);&#xA;&#xA;    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,&#xA;                     GL_LINEAR_MIPMAP_NEAREST );&#xA;    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;&#xA;    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );&#xA;    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );&#xA;    // load image with SDL&#xA;    SDL_Surface *s = IMG_Load(&quot;texture.png&quot;);&#xA;    // the following doesn't work (white space)&#xA;    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, s-&amp;gt;w, s-&amp;gt;h, 0, GL_RGB, GL_UNSIGNED_BYTE, s-&amp;gt;pixels);&#xA;    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, s-&amp;gt;w, s-&amp;gt;h, GL_RGB, GL_UNSIGNED_BYTE, s-&amp;gt;pixels);&#xA;&#xA;    glViewport(0, 0, 800, 600);&#xA;    glClearColor(1,1,1,1);&#xA;    glMatrixMode(GL_PROJECTION);&#xA;    glLoadIdentity();&#xA;    gluPerspective(70, 0.75, 0.2, 1000);&#xA;&#xA;    glMatrixMode(GL_MODELVIEW);&#xA;    glLoadIdentity();&#xA;    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );&#xA;    gluLookAt(0, 10, 0, 0, 0, 0, 1, 0, 0);&#xA;&#xA;    glActiveTexture(50);&#xA;    // display texture as 2 triangles.&#xA;    glBegin(GL_TRIANGLES);&#xA;    glTexCoord2d(0,0); glVertex3d(-5, 0, -5);&#xA;    glTexCoord2d(0,1); glVertex3d(-5, 0, 5);&#xA;    glTexCoord2d(1,0); glVertex3d(5, 0, -5);&#xA;&#xA;    glTexCoord2d(0,1); glVertex3d(-5, 0, 5);&#xA;    glTexCoord2d(1,0); glVertex3d(5, 0, -5);&#xA;    glTexCoord2d(1,1); glVertex3d(5, 0, 5);&#xA;&#xA;    glEnd();&#xA;    glFinish();&#xA;    SDL_GL_SwapWindow(window);&#xA;    // wait for quit procedure&#xA;    SDL_Quit();&#xA;    return 0;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3472" LastEditorUserId="38" LastEditDate="2016-09-29T08:35:14.597" LastActivityDate="2016-09-29T08:35:14.597" Title="Texture rendering in OpenGL" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;legacy-opengl&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3594" PostTypeId="2" ParentId="1725" CreationDate="2016-06-10T14:16:48.143" Score="4" Body="&lt;p&gt;Cone Step Mapping and Relaxed Cone Step Mapping appear to be very decent algorithms. These rely on a bit of preprocessing of the height field to create a 2D map used for more efficient lookups.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.lonesock.net/files/ConeStepMapping.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.lonesock.net/files/ConeStepMapping.pdf&lt;/a&gt;&#xA;&lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch18.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch18.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4544" LastEditorUserId="506" LastEditDate="2017-10-26T10:32:07.660" LastActivityDate="2017-10-26T10:32:07.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3595" PostTypeId="1" CreationDate="2016-06-10T14:19:06.340" Score="4" ViewCount="237" Body="&lt;p&gt;I'm trying to write a mesh deformer that bends a Cube around an axis like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/iWZh7nR.png&quot; alt=&quot;3D Bend&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The bend degree in figure A is 90 and something like 35 in B. So if I know my desired bend degree how can I get alpha?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that the distance between the vertices v1 and v2 stays the same and that i basically just have to rotate the edge alpha degrees. I can't figure out where the center of the Circle has to be, so that the bend looks organic.&lt;/p&gt;&#xA;" OwnerUserId="4543" LastActivityDate="2016-06-13T10:28:12.603" Title="Implement own Bend function" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;model&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3596" PostTypeId="1" CreationDate="2016-06-10T16:17:59.203" Score="3" ViewCount="133" Body="&lt;p&gt;I want to develop a component for 3d shadow analysis of 3d city model. I decided to use ray tracing for this purpose. For every time step (for sun's dynamic position during the year) rays will be sent from sun (point light source) and with ray intersection tests surfaces which are and how long are in shadow will be determined. Are there any components for this purpose such as sun's position, ray tracing etc. or do I have to code everything from beginning to the end? Any answer would be very helpful.&lt;/p&gt;&#xA;" OwnerUserId="4513" LastEditorUserId="209" LastEditDate="2016-07-11T12:34:56.330" LastActivityDate="2016-10-09T13:58:13.297" Title="Components that can be used for 3d shadow analysis, sunhours of surfaces throughout the year in a 3d model?" Tags="&lt;raytracing&gt;&lt;shadow&gt;&lt;simulation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3597" PostTypeId="2" ParentId="3596" CreationDate="2016-06-10T16:52:28.663" Score="1" Body="&lt;p&gt;I use Nvidia OptiX for Ray casting and tracing purposes. It is based on CUDA and gives you a library that runs on GPU and is capable of building and traversing efficient acceleration structures. You just supply a few programs such as intersection tests and shading and OptiX does the rest.&#xA;I personally think it is really easy to work with it but your milage may vary.&#xA;With this it should be very doable to make your project and even with decent running speed.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-06-10T16:52:28.663" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3598" PostTypeId="2" ParentId="3587" CreationDate="2016-06-10T19:52:16.557" Score="4" Body="&lt;p&gt;The shape you’re trying to draw is called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Catenary&quot; rel=&quot;nofollow&quot;&gt;catenary&lt;/a&gt;: it’s the shape that a cable/cord of constant density takes when supported at each end. You’ll have to do some research to find a parametric equation for its shape—&lt;a href=&quot;http://mathworld.wolfram.com/Catenary.html&quot; rel=&quot;nofollow&quot;&gt;this page&lt;/a&gt; has a start, though it doesn’t let you substitute in the endpoints so you’ll need some additional work there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have an equation that gives you a point along the curve as a function &lt;code&gt;f(t) = (x,y)&lt;/code&gt;, where &lt;code&gt;t&lt;/code&gt; is in the range [0,1], you can draw it the same way you would any other parametric curve: step along the function from 0 to 1 in small increments, drawing individual line segments from the value of &lt;code&gt;f&lt;/code&gt; at the previous increment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For nicer-looking cables, you can follow that process with a wide line in a dark color followed by a narrow line in a lighter one to give the appearance of shading, draw a shadow with the same curve offset vertically in partially-transparent black, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to the patch ports themselves… you can make grids pretty easily by using an image for a single port and drawing it at regular intervals across the space you want to cover. To figure out which port a given screen position corresponds to (e.g. if the user clicks on a particular one), get that position, divide it by the size of the interval you drew the ports at, and take the ceiling of that value. In other words, if you’re drawing a port every 20 pixels and the user clicks on (42, 27), dividing each coordinate value by 20 gives you (2.1, 1.35), which ceils to (3, 2)—i.e. the third column and second row.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2016-06-10T19:57:34.127" LastActivityDate="2016-06-10T19:57:34.127" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3599" PostTypeId="2" ParentId="3593" CreationDate="2016-06-10T19:58:16.703" Score="7" Body="&lt;p&gt;This type of artifact is a tell-tale sign that you've messed up your texture image format at the byte level. It's hard to tell what exactly is wrong, but it's something along the lines of bad pitch or a component layout mismatch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have a read of &lt;a href=&quot;https://www.opengl.org/wiki/Image_Format&quot;&gt;this wiki page&lt;/a&gt; and try again. &lt;code&gt;glTexImage2D&lt;/code&gt; should work, keep trying until it does.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-06-10T19:58:16.703" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3600" PostTypeId="1" CreationDate="2016-06-11T04:39:32.547" Score="4" ViewCount="1050" Body="&lt;p&gt;When using a Compute Shader, is it possible to keep a buffer in the GPU memory during the whole run-time duration of the application, so whenever the original Compute Shader or other Compute Shaders are executed later they can access data from such buffer and/or update them?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so, what is the correct way of declaring/referencing buffers when one wants them to be permanent in GPU versus one-time-use only? If that helps, I am using CG in Unity, but an engine/language agnostic answer is fine.&lt;/p&gt;&#xA;" OwnerUserId="4545" LastEditorUserId="4545" LastEditDate="2016-06-11T04:47:32.840" LastActivityDate="2016-06-12T08:01:32.257" Title="Compute shaders: one-time-only versus persistent buffers" Tags="&lt;gpu&gt;&lt;compute-shader&gt;&lt;memory&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3602" PostTypeId="2" ParentId="3586" CreationDate="2016-06-11T15:13:56.427" Score="0" Body="&lt;p&gt;My understanding is that in 5.4, instancing will use API calls like glDrawElementsInstanced and shaders need to be modified for instance buffers like in this document: &lt;a href=&quot;https://docs.google.com/document/d/1RS6cVjE8mBVOKqQUuXbaZcPW3kmw3ZWySJwr-5rDwSs/edit&quot; rel=&quot;nofollow noreferrer&quot;&gt;Basic GPU Instancing Support | docs.google.com&lt;/a&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;UNITY_INSTANCING_CBUFFER_START (MyProperties)&lt;/p&gt;&#xA;&lt;p&gt;UNITY_DEFINE_INSTANCED_PROP (float4, _Color)&lt;/p&gt;&#xA;&lt;p&gt;UNITY_INSTANCING_CBUFFER_END&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="67" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-04-09T09:41:17.210" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3603" PostTypeId="2" ParentId="3600" CreationDate="2016-06-12T08:01:32.257" Score="5" Body="&lt;p&gt;Yes, it's totally possible, and in fact it's preferable to keep buffers in memory if you will be accessing them over the life of your program, rather than deallocating and reallocating them again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't speak for Unity's way of allocating persistent buffers - I work with Unity and do a lot of shader writing in Cg, but most of our stuff is on mobile so compute shaders aren't an option. However, from a recent project I did using OpenGL, a buffer will generally hang around until you tell it not to, and even then, it is not in any way guaranteed to release the memory in a timely manner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Allocating a buffer in modern OpenGL is done by calling glCreateBuffers and passing it a pointer to a GLuint array which will store your buffer 'names', then calling glBufferData or glBufferStorage to actually allocate and populate the VRAM for that buffer. Calling glBufferData a second time on the same buffer name will allocate new storage for that buffer, and the original storage will be 'orphaned'. It's kind of like reallocating an object in Java, the variable name will no longer point to that object, but other parts of the system may still have references to it (e.g. if it's still being used for a texture read somewhere), so it will not be eligible for cleanup until all references to it are gone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Calling glDeleteBuffers with the buffer name has a similar effect but without allocating new storage. In both cases, the storage will &lt;em&gt;not&lt;/em&gt; be deleted until absolutely all references to it within the system are gone. Even then, it is more like Java's garbage collection than C++'s delete, the system may well hold on to the memory for quite some time in order to reuse it for any future allocations you may make.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The upshot of all this is it's often better to allocate buffers once when you launch your app and cycle different data through them as needed. In OpenGL, a buffer will persist for the lifetime of the application unless you explicitly delete or reallocate it. Unity's rendering system has its own quirks as I'm sure you're aware, but in principle it should behave similarly.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2016-06-12T08:01:32.257" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3604" PostTypeId="2" ParentId="3595" CreationDate="2016-06-13T08:21:17.957" Score="2" Body="&lt;p&gt;It's easy to work out if you consider not that case but the angle at v3 (if the &quot;cube&quot; were continued past v3). By the time you get to v3, the angle is simply the desired bend angle. (That's not quite right, though: because you've got alpha on the decreasing side, it's 90 degrees minus the desired angle.) You have to split that angle equally among all the segments going along the bend direction, so the angle alpha is simply 90 degrees minus (the desired angle divided by the number of vertices). So for A, where the requested angle is 90 degrees, each vertex gets a third of that angle: alpha is (90 - 30) degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For cube B, if the total bend is 35 degrees, each vertex gets just over 11 degrees, so alpha is just under 79 degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This &lt;strong&gt;doesn't&lt;/strong&gt; generalise to an arbitrary axis, though. It only works for bends like those in your diagram. For a more general (and more useful!) tool, it makes more sense to simply apply a 2D rotation (about the axis) to each vertex independently. Exactly what rotation to apply depends on some design decisions about how the bend should behave when the axis goes through the mesh, and how strong a bend you want to allow. The crucial point is that it's not the same rotation for every vertex: the rotation is proportional to the perpendicular distance from the vertex to the neutral line of the transformation. In your example, the neutral line is the bottom edge of each cube.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-06-13T08:21:17.957" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3605" PostTypeId="1" AcceptedAnswerId="3606" CreationDate="2016-06-13T09:06:23.813" Score="6" ViewCount="638" Body="&lt;p&gt;At first: I already posted this on the stackoverflow community. I'm new and didn't know about this community here. I apologize.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I basically got the same question as the guy who asked here: &lt;a href=&quot;https://stackoverflow.com/questions/36457138/dynamically-sized-arrays-in-opengl-es-vertex-shader-used-for-blend-shapes-morph&quot;&gt;https://stackoverflow.com/questions/36457138/dynamically-sized-arrays-in-opengl-es-vertex-shader-used-for-blend-shapes-morph&lt;/a&gt;.&#xA;Especially his last unanswered question bothers me too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I also want to use an arbitrary number of blendshapes for each mesh I'm processing. At the moment I'm using a fixed number and treat the shapes as vertex attribute. The advantage here is that I always have the relevant data for the current vertex availiable. Now, if I want to use an arbitrary number of shapes, I figured I'd use SSBOs since their clue is exactly what I want: Dynamically sized data. However SSBOs are, as far as I understand it, static and for each processed vertex in the shader I have the blendshape data for the whole mesh availiable. That means I would have to introduce some kind of counter and try to pick the correct data piece out of my SSBO for each vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this understanding correct? I'm really not sure whether this is the optimal solution, maybe you can give me some hints.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you for your answers!&lt;/p&gt;&#xA;" OwnerUserId="4556" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2020-12-11T12:46:28.477" Title="Open GL Shader Storage Buffer Objects to replace Vertex Attributes" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3606" PostTypeId="2" ParentId="3605" CreationDate="2016-06-13T09:44:32.683" Score="6" Body="&lt;p&gt;The counter you want is built in the shader as &lt;code&gt;gl_VertexID&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However you have 16 attributes of 4 components each to work with. Take 2 components for the texture coordinates and you have 62 float values to play with. If you need 6 components per blend shape (3 pos + 3 normal) you get 10 blend shapes to work with per object per frame. If you leave off the normal as static then you get up to 19 shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Times when you want to blend between more than 10 shapes should be very rare. And even then you can probably get away with making another shape to get the resulting shape you want.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="2654" LastEditDate="2017-10-22T05:06:57.687" LastActivityDate="2017-10-22T05:06:57.687" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3607" PostTypeId="2" ParentId="3595" CreationDate="2016-06-13T10:28:12.603" Score="0" Body="&lt;h2&gt;α = 90° - β/4&lt;/h2&gt;&#xA;&lt;p&gt;Lets call the bend angle &lt;code&gt;β&lt;/code&gt;.&#xA;The math is quite easy after following observation:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xv0WO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xv0WO.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;We can draw a perpendicular bisector &lt;code&gt;middle-&amp;gt;w&lt;/code&gt; of the isoscles triangle &lt;code&gt;v1-&amp;gt;middle-&amp;gt;v2&lt;/code&gt;. Then the anlge at &lt;code&gt;v1&lt;/code&gt; is the desired &lt;code&gt;α&lt;/code&gt;, the angle at &lt;code&gt;w&lt;/code&gt; is &lt;code&gt;90°&lt;/code&gt; and the angle at &lt;code&gt;middle&lt;/code&gt; is just &lt;code&gt;β/4&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;By the &lt;a href=&quot;https://en.wikipedia.org/wiki/Sum_of_angles_of_a_triangle&quot; rel=&quot;nofollow noreferrer&quot;&gt;triangle postulate&lt;/a&gt; the sum of the interior angles of a triangle is &lt;code&gt;180°&lt;/code&gt;. By applying this to our new triangle we get&#xA;&lt;code&gt;180° = α + 90° + β/4&lt;/code&gt;, so we get&lt;/p&gt;&#xA;&lt;h2&gt;α = 90° - β/4&lt;/h2&gt;&#xA;" OwnerUserId="1981" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-06-13T10:28:12.603" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3608" PostTypeId="1" AcceptedAnswerId="3609" CreationDate="2016-06-13T16:31:08.373" Score="15" ViewCount="1858" Body="&lt;p&gt;While investigating the inner workings of perlin noise, I wondered why one would use perlin noise instead of simple value noise. As far as I understand it right, the following applies:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perlin noise is a lattice based noise function, which assigns a n-dimensional gradient (random for the original implementation, fixed for the improved one) for every point in the underlying noise space. Now you can query a value for every point in space by calculating the dot product between the distance vector and the gradient vector. After that you average all values calculated and get the queried value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But isn't value noise kind of the same without using gradient vectors but random values? Since I also interpolate between values in value noise I cannot see any benefits by using an additional calculation step (the dot product) in perlin noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So why would I use perlin noise instead of value noise? Why is perlin noise so popular?&lt;/p&gt;&#xA;" OwnerUserId="4558" LastActivityDate="2016-06-14T10:03:24.597" Title="benefit of perlin noise over value noise" Tags="&lt;noise&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3609" PostTypeId="2" ParentId="3608" CreationDate="2016-06-14T10:03:24.597" Score="11" Body="&lt;p&gt;The benefit of perlin noise is the overall distribution of frequencies. Since value noise uses simple values that are interpolated, there is a higher chance, that a row of several values only differs a little. The consequence is, that some regions of your picture may contain little changes and some regions a lot of changes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;By using gradients you are reducing this effect because the interpolation is not done by value but instead calculated between tangents. Now it's more difficult to have a flat curve (both tangents must be collinear).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7kSzR.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7kSzR.png&quot; alt=&quot;perlin noise vs value noise&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Source: As noted by Martin Ender the question was already posted on a different StackExchange community: see &lt;a href=&quot;https://math.stackexchange.com/q/184121/50421&quot;&gt;this Math.SE post&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="4558" LastEditorUserId="-1" LastEditDate="2017-04-13T12:19:38.027" LastActivityDate="2016-06-14T10:03:24.597" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3611" PostTypeId="1" AcceptedAnswerId="3613" CreationDate="2016-06-14T17:14:01.773" Score="4" ViewCount="169" Body="&lt;p&gt;I am decrementing/incrementing position x until it reaches y. However, this creates a rectangular-like path. I want position x to smoothly curve towards y (diagonally) on a 2D plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What kind of maths would I need to achieve this? &#xA;Example image attached.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MMbkN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MMbkN.png&quot; alt=&quot;Algorithm&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user4570" LastEditorDisplayName="user246" LastEditDate="2017-04-24T10:19:49.680" LastActivityDate="2017-04-24T10:19:49.680" Title="Move position in smooth gradient" Tags="&lt;algorithm&gt;&lt;curve&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3612" PostTypeId="1" AcceptedAnswerId="3756" CreationDate="2016-06-14T17:33:49.510" Score="6" ViewCount="549" Body="&lt;p&gt;I'm currently writing a software rasterizer and I'm at the point where I can draw arbitrary triangles with vertex colors and perspective correct texture mapping. I do point and directional lighting by linearly interpolating the vertex normals and it works fine, only on big triangles you can notice that the lighting is somehow distorted when viewed from a very flat angle. However, this is only visible when you're particularly looking for it but I was wondering if there is a way to have perspective correction on the normals too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the texture coordinates and other stuff this is being done by dividing the value by W or Z. But if you divide a vector by a single number you only change its magnitude, which is useless, as I'm normalizing the vector in the end for the lighting computation. So, is there a way to do it perspective correct?&lt;/p&gt;&#xA;" OwnerUserId="4571" LastActivityDate="2016-07-15T05:27:57.677" Title="Perspective correct interpolation of normal values" Tags="&lt;3d&gt;&lt;c++&gt;&lt;perspective&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3613" PostTypeId="2" ParentId="3611" CreationDate="2016-06-14T18:18:23.387" Score="5" Body="&lt;p&gt;The math you need is linear interpolation. I think of a player sprite which moves from position X to position Y. Pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;playerSprite.x = Y.x + t * (X.x - Y.x)&#xA;playerSprite.y = Y.y + t * (X.y - Y.y)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where t is a value between 0.0 and 1.0 (floating point). Instead of incrementing the position components of Y you increment t till it reaches 1. When it reaches 1 the playerSprite reached point X. If t is 0, then the playerSprite is at position Y.&lt;/p&gt;&#xA;" OwnerUserId="4558" LastActivityDate="2016-06-14T18:18:23.387" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3614" PostTypeId="2" ParentId="3611" CreationDate="2016-06-14T19:37:32.353" Score="5" Body="&lt;p&gt;What you want is linear interpolation like @Tim points out. However he uses a formula that is not so easily understandable form, we can refactor it differently. Basically linear interpolation is a weighted average where the weight of the first term is in range of &lt;em&gt;0-1&lt;/em&gt; and the weight of the other value is &lt;em&gt;1-weight&lt;/em&gt;. Literature usually uses t for the weight and y for input (y can be a scalar, vector, matrix or mostly any construct). A more understandable version of the formula in scientific form is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;y = t \cdot y_1 + (1-t) \cdot y_0     \quad \quad t \in [0,1]&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As code it looks like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;playerSprite.x = t * Y.x + (1-t) * X.x &#xA;playerSprite.y = t * Y.y + (1-t) * X.y &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There is a simple visual interpretation of this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Vkqaf.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Vkqaf.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Visual interpretation of weights (below) and the sum of vectors and position on line (above)&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-06-15T07:01:26.843" LastActivityDate="2016-06-15T07:01:26.843" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3615" PostTypeId="1" CreationDate="2016-06-15T08:32:02.530" Score="2" ViewCount="104" Body="&lt;p&gt;I have a base 3D mesh of an object that I want to texturize. I also have a 360 degrees video of the real-world object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are good ways to use the video to texturize the mesh? Are there existing tools to do that? (paid or free)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;: I have complete control over the camera and object positions, I can measure the distances and whatever needed. I can also put markers on the object.&lt;/p&gt;&#xA;" OwnerUserId="4574" LastEditorUserId="4574" LastEditDate="2016-06-15T09:18:37.760" LastActivityDate="2016-06-20T19:47:03.700" Title="How to texturize a 3D model from video?" Tags="&lt;algorithm&gt;&lt;3d&gt;&lt;3dtexture&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3616" PostTypeId="1" AcceptedAnswerId="3617" CreationDate="2016-06-15T09:15:41.350" Score="3" ViewCount="2735" Body="&lt;p&gt;I'm playing around with base64 embedded data URI's and tried to analyze the buffer data of the gltf box sample model, as defined in &lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/master/sampleModels/Box/glTF-Embedded/Box.gltf#L76&quot; rel=&quot;nofollow noreferrer&quot;&gt;this example here&lt;/a&gt; (line 76).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; &quot;uri&quot;: &quot;data:application/octet-stream;base64,AAABAAIAAwACAAEABAAFAAYABwAGAAUACAAJAAoACwAKAAkADAANAA4ADwAOAA0AEAARABIAEwASABEAFAAVABYAFwAWABUAAAAAvwAAAL8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAvwAAAL8AAAC/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAPwAAAD8AAAC/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/&quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is the buffer data for a simple cube, here's screenshot:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zZmqD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zZmqD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it's giving me a hard time to understand what's exactly in this buffer. As far as I know, it should contain the vertices, and maybe indices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to decode the base64 and the output is &lt;em&gt;binary&lt;/em&gt;. I'm lost since I have no clue how this binary is encoded or decoded. Can anyone point me how to write such buffers or at least how to read them?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I generate my own buffers?&lt;/p&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-06-15T18:51:57.920" Title="How to encode/decode buffer data in glTF?" Tags="&lt;vertex-buffer-object&gt;&lt;gltf&gt;&lt;buffers&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3617" PostTypeId="2" ParentId="3616" CreationDate="2016-06-15T10:11:34.690" Score="2" Body="&lt;p&gt;The information you're looking for is defined in the 'accessors' and 'bufferViews' near the top of the source file you linked. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bufferviews simply divide the buffer up into sub ranges and define broadly what kind of data lives there using some obscure shortcodes. In this case, target 34963 means index data and 34962 means vertex data. So from the other parameters in the bufferviews you can see that the first 72 bytes are indices and the remaining 576 bytes are vertex data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The accessors are what actually define the format of the data and again use weird codes for &quot;componentType&quot; - 5123 is an unsigned short (2 bytes) and 5126 is single precision float (4 bytes). They also define whether they should be read singly (&quot;SCALAR&quot;) or in vector groups (e.g. &quot;VEC3&quot;), and also a starting offset into the bufferview and &quot;stride&quot; between the start of data points like regular OpenGL vertex buffer bindings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Putting it all together, the first 72 bytes are 36 shorts representing the indices (3 * 12 triangles). The next 576 bytes are two consecutive sets of 24 vec3 (4 per square face, 12 bytes per vec3) representing vertex data. Since the first set are clamped to + or - 1/2 and the second set to + or - 1, I'm guessing first set are positions, second set are normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The base 64 encoding just takes the raw bit stream, splits it into groups of 6 rather than 8, and maps each unique 6-bit combination onto a character. You can see this is quite wasteful as each character takes at least 8 bits to store, quite possibly 16 or more depending on the encoding used. &lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2016-06-15T10:11:34.690" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3619" PostTypeId="1" AcceptedAnswerId="3620" CreationDate="2016-06-15T10:40:23.027" Score="11" ViewCount="922" Body="&lt;p&gt;Apologies for the following noob question, it's just I can't find a satisfactory answer anywhere...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I render a simple axis-aligned quad made up of two triangles, I don't understand why there's never any visible artefacts on the diagonal edge where those triangles meet. Some of those pixels must be in both triangles, right? So if my fragshader always emits a partially-transparent color - 50% black say - then shouldn't there be a visible dark diagonal line in the resulting quad?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously it's great that this isn't a real problem that has to be coded around, I just don't understand why it isn't. What GPU magic is it that makes this always work out?&lt;/p&gt;&#xA;" OwnerUserId="4577" LastEditorUserId="209" LastEditDate="2016-06-15T11:28:14.057" LastActivityDate="2020-11-16T14:08:35.710" Title="Why do adjacent triangles never overlap when rasterized?" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3620" PostTypeId="2" ParentId="3619" CreationDate="2016-06-15T10:58:46.450" Score="10" Body="&lt;p&gt;This is the same problem as discussed in &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2484/what-are-sample-gaps-during-scan-conversion&quot;&gt;What are sample gaps during scan conversion?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Briefly, rasterisation - at least with the majority of hardware systems - tests at a single 'infinitesimal' point for each pixel to determine if that pixel is inside a given triangle. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the sample point lies exactly on an edge, then additional tie-breaking rules, often referred to as &quot;fill rules&quot;, come in to play. Typically these will be something equivalent to, say, only consider the edge points on the top/left** edges of a triangle to be &quot;inside&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;**Other rules are available ;-)&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="231" LastEditDate="2016-06-15T14:44:42.670" LastActivityDate="2016-06-15T14:44:42.670" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3621" PostTypeId="1" AcceptedAnswerId="3692" CreationDate="2016-06-15T11:44:32.040" Score="10" ViewCount="624" Body="&lt;p&gt;I am reading the book Physically Based Rendering (Pharr, Humphreys). In the chapter on lights, they talk about approximating the total emitted power of different kinds of lights. For example, a point light's total power is &lt;code&gt;intensity * 4 * pi&lt;/code&gt;. Here 4pi represents a solid angle over the entire sphere.&#xA;This makes sense to me because intensity * solid angle = power (or radiant flux if you will). You can see this by the units as well. Intensity is W/sr and solid angle is sr, so &lt;code&gt;W/sr * sr = W&lt;/code&gt; and power is measured in watts. It checks out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I don't understand the corresponding calculation for the &lt;code&gt;DiffuseAreaLight&lt;/code&gt;. From my understanding of the book they calculate the total power emitted from a diffuse area light as &lt;code&gt;emitted radiance * area * pi&lt;/code&gt;.&#xA;Since the unit of radiance is W/(sr*m^2) multiplying area gives W/sr. This makes me think the pi factor represents solid angle - but why only 1pi? I would have guessed 2pi since each point on the area light would radiate in a complete hemisphere (corresponding to 2pi steradians).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find the actual code mentioned in the book &lt;a href=&quot;https://github.com/mmp/pbrt-v2/blob/master/src/lights/diffuse.cpp#L55&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I misunderstanding? Why does &lt;code&gt;total emitted power = emitted radiance * area * pi&lt;/code&gt; for diffuse area lights make sense?&lt;/p&gt;&#xA;" OwnerUserId="4578" LastActivityDate="2016-11-15T21:39:12.463" Title="Total emitted power of diffuse area light" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3622" PostTypeId="1" CreationDate="2016-06-15T15:47:01.427" Score="7" ViewCount="149" Body="&lt;p&gt;Which among Intel's integrated GPUs depart from their predecessors in a major way? Which are merely incremental improvements?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;BACKGROUND&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intel integrates GPUs with many of the processors they sell. With each generation of processors (Ivy Bridge, Haswell, Broadwell, Skylake, Kaby Lake, etc.), Intel updates the graphics architecture. Much is written in the popular press regarding each of these: does your favorite video game make only 98 frames per second on the latest, or does it achieve a previously unheard-of 99? Bar charts are published, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;None of the articles, or practically none, seems to grasp the underlying technology. I would be interested to learn whether Ivy Bridge, Haswell, Broadwell, Sklyake, Kaby Lake, and so on, are each merely incremental improvements in the same, basic graphics architecture, or whether, say, Broadwell (or Kaby Lake, or whatever) was an entirely new design.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would likewise be interested to learn if one generation had been upgraded over the previous in a way which made OpenCL-type usage much more practical or capable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apparently, Broadwell was the first capable of Vulkan, but I do not know whether this capability represents a fundamental architectural change or if it's just a driver issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the popular press seems pretty clueless at this technical level. Can you shed any light?&lt;/p&gt;&#xA;" OwnerUserId="4581" LastActivityDate="2016-06-29T05:56:39.997" Title="The generations of Intel's integrated graphics" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3623" PostTypeId="2" ParentId="3616" CreationDate="2016-06-15T18:51:57.920" Score="2" Body="&lt;p&gt;In addition to @russ' answer, I was able to decode the buffer with the &lt;a href=&quot;https://github.com/AnalyticalGraphicsInc/gltf-utilities&quot; rel=&quot;nofollow&quot;&gt;gltf Utilities&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let uri = &quot;data:application/octet-stream;base64,AAABAAIAAwACAAEABAAFAAYABwAGAAUACAAJAAoACwAKAAkADAANAA4ADwAOAA0AEAARABIAEwASABEAFAAVABYAFwAWABUAAAAAvwAAAL8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAvwAAAL8AAAA/AAAAPwAAAL8AAAC/AAAAvwAAAL8AAAC/AAAAPwAAAD8AAAA/AAAAPwAAAL8AAAA/AAAAPwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAvwAAAD8AAAA/AAAAPwAAAD8AAAA/AAAAvwAAAD8AAAC/AAAAPwAAAD8AAAC/AAAAvwAAAL8AAAA/AAAAvwAAAD8AAAA/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAvwAAAL8AAAC/AAAAvwAAAD8AAAC/AAAAPwAAAL8AAAC/AAAAPwAAAD8AAAC/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAAAAAAIA/AAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAAAAAAAAgL8AAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAAAAAAAAgD8AAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAACAvwAAAAAAAAAAAAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/AAAAAAAAAAAAAIC/&quot;;&#xA;&#xA;gltfUtilities.loadArrayBuffer(uri,&#xA;  function(buf) {&#xA;    let idx = new DataView(buf, 0, 72);&#xA;    for (var i = 0; i &amp;lt; 72; i += 2) {&#xA;      window.console.log(idx.getUint16(i, true));&#xA;    }&#xA;    let vtx = new DataView(buf, 72, 288);&#xA;    for (var v = 0; v &amp;lt; 288; v += 4) {&#xA;      window.console.log(vtx.getFloat32(v, true));&#xA;    }&#xA;  },&#xA;  function(xhr) {&#xA;    window.console.log(&quot;The ArrayBuffer failed to load&quot;);&#xA;  }&#xA;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is a &lt;a href=&quot;https://jsfiddle.net/s1bzc0zc/6/&quot; rel=&quot;nofollow&quot;&gt;JSfiddle&lt;/a&gt; to test. &lt;code&gt;loadArrayBuffer()&lt;/code&gt; creates a JavaScript &lt;code&gt;ArrayBuffer&lt;/code&gt; from the base64 encoded String.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Opening the ArrayBuffer with a JavaScript DataView allows to read the buffer data. Note the first 72 bytes are 36 unsigned short indeces (Uint16) and the following 288 bytes are the 72 float vertices (Float32).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I didn't read the normals (last 288 bytes), but that would work similar to the vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And to encode a base64 string with my custom buffers, I'll just do it vice versa. Here is a &lt;a href=&quot;https://jsfiddle.net/6cevt681/1/&quot; rel=&quot;nofollow&quot;&gt;JSfiddle&lt;/a&gt; for encoding.&lt;/p&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-06-15T18:51:57.920" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3624" PostTypeId="2" ParentId="2337" CreationDate="2016-06-15T18:57:12.357" Score="1" Body="&lt;p&gt;It's not possible to store the plain text array buffers in gltf, however, here is the code I use to generate buffers in JavaScript:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let vtx = [&#xA;  0.0857, 0.0759,&#xA;  0.0367, 0.9726,&#xA;  0.9678, 0.0318,&#xA;  0.9754, 0.9327&#xA;];&#xA;&#xA;let idx = [&#xA;  0, 2,&#xA;  2, 4,&#xA;  4, 0,&#xA;  0, 1,&#xA;  1, 4&#xA;];&#xA;&#xA;let buf = new ArrayBuffer(52);&#xA;let dat = new DataView(buf, 0, 52);&#xA;&#xA;for (var i = 0; i &amp;lt; 20; i += 2) {&#xA;  dat.setUint16(i, idx[i / 2], true);&#xA;}&#xA;&#xA;for (var v = 20; v &amp;lt; 52; v += 4) {&#xA;  dat.setFloat32(v, vtx[(v - 20) / 4], true);&#xA;}&#xA;&#xA;let b64 = btoa(String.fromCharCode(...new Uint8Array(buf)));&#xA;&#xA;window.console.log(&quot;data:application/octet-stream;base64,&quot; + b64);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;buf&lt;/code&gt; contains the binary data in a JavaScript ArrayBuffer object and &lt;code&gt;b64&lt;/code&gt; finally a base64 encoded string:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;data:application/octet-stream;base64,AAACAAIABAAEAAAAAAABAAEABAB7g689dnGbPb1SFj1Q/Hg/vsF3P7hAAj3Qs3k/bcVuPw==&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="361" LastActivityDate="2016-06-15T18:57:12.357" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3625" PostTypeId="2" ParentId="2338" CreationDate="2016-06-15T19:03:36.683" Score="1" Body="&lt;p&gt;I've finally managed to write the buffers myself using &lt;a href=&quot;https://jsfiddle.net/6cevt681/1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;JavaScript&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result is a base64 encoded String, like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;data:application/octet-stream;base64,AAACAAIABAAEAAAAAAABAAEABAB7g689dnGbPb1SFj1Q/Hg/vsF3P7hAAj3Qs3k/bcVuPw==&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you paste this Data URI into the browser, you can download a binary blob which is exactly what the glTF files can use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/x2dxF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/x2dxF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 52 bytes in this case contain 10 indices of 2 bytes size (&lt;code&gt;U_SHORT&lt;/code&gt;) and 8 vertices of 4 bytes size (&lt;code&gt;FLOAT&lt;/code&gt;), so &lt;code&gt;10 * 2 B + 8 * 4 B = 52 B&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See &lt;a href=&quot;https://computergraphics.stackexchange.com/a/3624/361&quot;&gt;this post&lt;/a&gt; to find out how I generated the buffer and see &lt;a href=&quot;https://computergraphics.stackexchange.com/a/3623/361&quot;&gt;this answer&lt;/a&gt; on how to read the data again.&lt;/p&gt;&#xA;" OwnerUserId="361" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-06-15T19:03:36.683" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3627" PostTypeId="1" CreationDate="2016-06-15T20:33:39.417" Score="4" ViewCount="2467" Body="&lt;p&gt;I know the philosophy of how a GPU works {many weak men doing a task (GPU) compared to one strong man doing the same task (CPU)}. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does the GPU manage all the ALUs and schedule the necessary calculation to an ALU?&lt;/p&gt;&#xA;" OwnerUserId="4583" LastEditorUserId="231" LastEditDate="2016-06-15T21:24:17.410" LastActivityDate="2016-06-21T08:19:30.473" Title="How does a GPU process a task by using multiple ALUs?" Tags="&lt;gpu&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3628" PostTypeId="2" ParentId="1934" CreationDate="2016-06-15T20:50:54.617" Score="3" Body="&lt;p&gt;After spending a hard time to understand the way &lt;a href=&quot;https://computergraphics.stackexchange.com/a/3624/361&quot;&gt;how the binary buffers work in the gltf files&lt;/a&gt; I finally managed to generate a truely &lt;em&gt;minimal&lt;/em&gt; gltf file. It's a single yellow triangle (&lt;a href=&quot;http://5chdn.github.io/gltf-tiles-loader-poc/&quot; rel=&quot;nofollow noreferrer&quot;&gt;demo&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kMZO0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kMZO0.png&quot; alt=&quot;minimal triangle&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to remove everything which is not needed from the gltf. This is what is required it seems (&lt;a href=&quot;https://github.com/5chdn/gltf-tiles-loader-poc/blob/8f25b30fed2324820e0a4a8958715fa2a424305d/data/Min/glTF-Embedded/Min.gltf&quot; rel=&quot;nofollow noreferrer&quot;&gt;github&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;{&#xA;    &quot;accessors&quot;: {&#xA;        &quot;accessor0&quot;: {&#xA;            &quot;bufferView&quot;: &quot;bufferView0&quot;,&#xA;            &quot;byteOffset&quot;: 0,&#xA;            &quot;componentType&quot;: 5123,&#xA;            &quot;count&quot;: 3,&#xA;            &quot;type&quot;: &quot;SCALAR&quot;&#xA;        },&#xA;        &quot;accessor1&quot;: {&#xA;            &quot;bufferView&quot;: &quot;bufferView1&quot;,&#xA;            &quot;byteOffset&quot;: 0,&#xA;            &quot;byteStride&quot;: 12,&#xA;            &quot;componentType&quot;: 5126,&#xA;            &quot;count&quot;: 3,&#xA;            &quot;max&quot;: [&#xA;                0.5,&#xA;                0.5,&#xA;                0.5&#xA;            ],&#xA;            &quot;min&quot;: [&#xA;                0.0,&#xA;                0.0,&#xA;                0.0&#xA;            ],&#xA;            &quot;type&quot;: &quot;VEC3&quot;&#xA;        }&#xA;    },&#xA;    &quot;asset&quot;: {&#xA;        &quot;generator&quot;: &quot;5chdn&quot;,&#xA;        &quot;profile&quot;: {&#xA;            &quot;api&quot;: &quot;WebGL&quot;,&#xA;            &quot;version&quot;: &quot;1.0.3&quot;&#xA;        },&#xA;        &quot;version&quot;: &quot;1.0&quot;,&#xA;        &quot;extras&quot;: {&#xA;            &quot;description&quot;: &quot;minimal gltf, single triangle&quot;,&#xA;            &quot;base64encoder&quot;: &quot;https://jsfiddle.net/opkxy0xb/&quot;,&#xA;            &quot;stackexchange&quot;: &quot;https://computergraphics.stackexchange.com/q/1934/361&quot;&#xA;        }&#xA;    },&#xA;    &quot;bufferViews&quot;: {&#xA;        &quot;bufferView0&quot;: {&#xA;            &quot;buffer&quot;: &quot;Min&quot;,&#xA;            &quot;byteLength&quot;: 6,&#xA;            &quot;byteOffset&quot;: 0,&#xA;            &quot;target&quot;: 34963&#xA;        },&#xA;        &quot;bufferView1&quot;: {&#xA;            &quot;buffer&quot;: &quot;Min&quot;,&#xA;            &quot;byteLength&quot;: 36,&#xA;            &quot;byteOffset&quot;: 6,&#xA;            &quot;target&quot;: 34962&#xA;        }&#xA;    },&#xA;    &quot;buffers&quot;: {&#xA;        &quot;Min&quot;: {&#xA;            &quot;bytelength&quot;: 42,&#xA;            &quot;type&quot;: &quot;arraybuffer&quot;,&#xA;            &quot;uri&quot;: &quot;data:application/octet-stream;base64,AAABAAIArK34PnZxmz29UhY9T6+UPXuD7z64QAI9UWuaPW/wBT3ysPA+&quot;&#xA;        }&#xA;    },&#xA;    &quot;materials&quot;: {&#xA;        &quot;effect0&quot;: {&#xA;            &quot;values&quot;: {&#xA;                &quot;emission&quot;: [&#xA;                    0.8,&#xA;                    0.8,&#xA;                    0.0,&#xA;                    1.0&#xA;                ]&#xA;            },&#xA;            &quot;technique&quot;: &quot;technique0&quot;&#xA;        }&#xA;    },&#xA;    &quot;meshes&quot;: {&#xA;        &quot;mesh0&quot;: {&#xA;            &quot;name&quot;: &quot;Triangle&quot;,&#xA;            &quot;primitives&quot;: [&#xA;                {&#xA;                    &quot;attributes&quot;: {&#xA;                        &quot;POSITION&quot;: &quot;accessor1&quot;&#xA;                    },&#xA;                    &quot;indices&quot;: &quot;accessor0&quot;,&#xA;                    &quot;material&quot;: &quot;effect0&quot;,&#xA;                    &quot;mode&quot;: 4&#xA;                }&#xA;            ]&#xA;        }&#xA;    },&#xA;    &quot;nodes&quot;: {&#xA;        &quot;node0&quot;: {&#xA;            &quot;matrix&quot;: [&#xA;                1,&#xA;                0,&#xA;                0,&#xA;                0,&#xA;                0,&#xA;                1,&#xA;                0,&#xA;                0,&#xA;                0,&#xA;                0,&#xA;                1,&#xA;                0,&#xA;                0,&#xA;                0,&#xA;                0,&#xA;                1&#xA;            ],&#xA;            &quot;meshes&quot;: [&#xA;                &quot;mesh0&quot;&#xA;            ],&#xA;            &quot;name&quot;: &quot;TriangleMesh&quot;&#xA;        }&#xA;    },&#xA;    &quot;programs&quot;: {&#xA;        &quot;program0&quot;: {&#xA;            &quot;attributes&quot;: [&#xA;                &quot;a_position&quot;&#xA;            ],&#xA;            &quot;fragmentShader&quot;: &quot;fragmentShader0&quot;,&#xA;            &quot;vertexShader&quot;: &quot;vertexShader0&quot;&#xA;        }&#xA;    },&#xA;    &quot;scenes&quot;: {&#xA;        &quot;scene0&quot;: {&#xA;            &quot;nodes&quot;: [&#xA;                &quot;node0&quot;&#xA;            ]&#xA;        }&#xA;    },&#xA;    &quot;shaders&quot;: {&#xA;        &quot;vertexShader0&quot;: {&#xA;            &quot;type&quot;: 35633,&#xA;            &quot;uri&quot;: &quot;data:text/plain;base64,cHJlY2lzaW9uIGhpZ2hwIGZsb2F0Ow0KdW5pZm9ybSBtYXQ0IHVfbW9kZWxWaWV3TWF0cml4Ow0KdW5pZm9ybSBtYXQ0IHVfcHJvamVjdGlvbk1hdHJpeDsNCmF0dHJpYnV0ZSB2ZWMzIGFfcG9zaXRpb247DQp2b2lkIG1haW4odm9pZCkNCnsNCmdsX1Bvc2l0aW9uID0gdV9wcm9qZWN0aW9uTWF0cml4ICogdV9tb2RlbFZpZXdNYXRyaXggKiB2ZWM0KGFfcG9zaXRpb24sMS4wKTsNCn0=&quot;&#xA;        },&#xA;        &quot;fragmentShader0&quot;: {&#xA;            &quot;type&quot;: 35632,&#xA;            &quot;uri&quot;: &quot;data:text/plain;base64,cHJlY2lzaW9uIGhpZ2hwIGZsb2F0Ow0KdW5pZm9ybSB2ZWM0IHVfZW1pc3Npb247DQp2b2lkIG1haW4odm9pZCkNCnsNCmdsX0ZyYWdDb2xvciA9IHVfZW1pc3Npb247DQp9&quot;&#xA;        }&#xA;    },&#xA;    &quot;techniques&quot;: {&#xA;        &quot;technique0&quot;: {&#xA;            &quot;attributes&quot;: {&#xA;                &quot;a_position&quot;: &quot;position&quot;&#xA;            },&#xA;            &quot;parameters&quot;: {&#xA;                &quot;modelViewMatrix&quot;: {&#xA;                    &quot;semantic&quot;: &quot;MODELVIEW&quot;,&#xA;                    &quot;type&quot;: 35676&#xA;                },&#xA;                &quot;projectionMatrix&quot;: {&#xA;                    &quot;semantic&quot;: &quot;PROJECTION&quot;,&#xA;                    &quot;type&quot;: 35676&#xA;                },&#xA;                &quot;emission&quot;: {&#xA;                    &quot;type&quot;: 35666&#xA;                },&#xA;                &quot;position&quot;: {&#xA;                    &quot;semantic&quot;: &quot;POSITION&quot;,&#xA;                    &quot;type&quot;: 35665&#xA;                }&#xA;            },&#xA;            &quot;program&quot;: &quot;program0&quot;,&#xA;            &quot;states&quot;: {&#xA;                &quot;enable&quot;: [&#xA;                    2884,&#xA;                    2929&#xA;                ]&#xA;            },&#xA;            &quot;uniforms&quot;: {&#xA;                &quot;u_modelViewMatrix&quot;: &quot;modelViewMatrix&quot;,&#xA;                &quot;u_projectionMatrix&quot;: &quot;projectionMatrix&quot;,&#xA;                &quot;u_emission&quot;: &quot;emission&quot;&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A good starting point was the &lt;a href=&quot;https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a&quot; rel=&quot;nofollow noreferrer&quot;&gt;Appendix A of the gltf Specification&lt;/a&gt; which defines a default material and shaders. All I had to do was adding the scene description and the buffers.&lt;/p&gt;&#xA;" OwnerUserId="361" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-11-28T09:01:59.490" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3629" PostTypeId="2" ParentId="3627" CreationDate="2016-06-16T01:47:03.613" Score="4" Body="&lt;h1&gt;Architecture Background&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;GPU don't schedule to individual ALUs, but rather groups of them. Terminology will vary based on GPU company (NVidia, ATI, and Intel), but I will stick with NVidia terminology since they all work somewhat similarly at the high level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NVidia has a concept of CUDA cores, each of which contains an ALU and/or FPU, which make up collections called Streaming Multiprocessors (SM). &lt;a href=&quot;https://en.wikipedia.org/wiki/Fermi_(microarchitecture)&quot; rel=&quot;nofollow&quot;&gt;The Fermi architecture&lt;/a&gt; has 32 CUDA cores per SM, for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPUs operate in a SIMD-like manner. This means that unlike a CPU, which traditionally has had one execution unit per instruction, GPUs have many execution units per instruction (CUDA core). These groups of execution are called warps.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Answer&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;GPUs contain scheduling units that attempt to reach maximal utilization. Warps are scheduled in a way to utilize as much of the GPU as possible. One way to do this is to use a &lt;a href=&quot;https://users.ece.cmu.edu/~omutlu/pub/large-gpu-warps_micro11.pdf&quot; rel=&quot;nofollow&quot;&gt;round-robin approach&lt;/a&gt;. Latency is something that a GPU struggles with compared to a CPU, so scheduling a process as soon as possible is often desirable. Like an OS (which controls CPU scheduling), however, simplicity and hiding latency are still desirable traits to an extent, although other tradeoffs may be deemed more important.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your workload will determine how scheduling is done. If you run a CUDA kernel or shader on 320 pieces of data (threads), you will need at least 10 warps to be scheduled (this depends on the type of data as well). If you have 1 thread that needs to be calculated, oh well, you still need to schedule one warp to do the calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, what ratchet freak said is true about GPU architectures and algorithms being proprietary, especially when compared to CPUs.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2016-06-16T01:47:03.613" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3630" PostTypeId="2" ParentId="3586" CreationDate="2016-06-16T02:15:29.827" Score="1" Body="&lt;p&gt;Unity provides a pretty clear description of &lt;a href=&quot;https://docs.unity3d.com/540/Documentation/Manual/GPUInstancing.html&quot; rel=&quot;nofollow&quot;&gt;GPU instancing&lt;/a&gt;. It is exactly the same as instancing. Employees of Unity even spell this out by initially &lt;a href=&quot;http://forum.unity3d.com/threads/gpu-mesh-instancing.19670/&quot; rel=&quot;nofollow&quot;&gt;arguing&lt;/a&gt; against it years ago before finally implementing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before this, Unity solely relied on &lt;a href=&quot;http://docs.unity3d.com/Manual/DrawCallBatching.html&quot; rel=&quot;nofollow&quot;&gt;batching&lt;/a&gt;, which was a technique that combined meshes together into one to reduce draw calls.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2016-06-16T02:15:29.827" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3631" PostTypeId="2" ParentId="3615" CreationDate="2016-06-16T04:04:10.187" Score="1" Body="&lt;p&gt;One method is to do &lt;a href=&quot;https://en.wikipedia.org/wiki/Projection_mapping&quot; rel=&quot;nofollow&quot;&gt;projection mapping&lt;/a&gt;. I understand that most 3D rendering applications can do that. I don't have much experience with them, but I have done it using AfterEffects using the Camera Mapper in &lt;a href=&quot;http://aescripts.com/buena-depth-cue/&quot; rel=&quot;nofollow&quot;&gt;Buena Depth Cue&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Algorithmically, it's achieved by projecting the geometry back onto the image to generate texture coordinates. So one way to do that is as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Line up the image of the scene in front of the corresponding geometry&lt;/li&gt;&#xA;&lt;li&gt;For each triangle in your geometry, project the 3 corners onto the image&lt;/li&gt;&#xA;&lt;li&gt;The coordinates where the projection hits your image are the texture coordinates you need for that triangle&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-06-16T04:04:10.187" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3633" PostTypeId="1" CreationDate="2016-06-16T13:43:20.917" Score="2" ViewCount="109" Body="&lt;p&gt;I am trying to implement the &lt;a href=&quot;https://en.wikipedia.org/wiki/Scale-invariant_feature_transform&quot; rel=&quot;nofollow&quot; title=&quot;Scale Invariant Feature Transform&quot;&gt;SIFT feature extraction algorithm&lt;/a&gt;. I have a few questions which are not very clear from the paper:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;When interpolating the extrema with 2nd order functions, do we upscale the downscaled images directly from &lt;a href=&quot;https://en.wikipedia.org/wiki/Difference_of_Gaussians&quot; rel=&quot;nofollow&quot; title=&quot;Difference of Gaussians&quot;&gt;DoG&lt;/a&gt; or interpolate in the original downsampled image then upscale for the subpixel accuracy pixel positions?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;At the description step, it is stated that&#xA;&quot;In order to achieve orientation invariance, the coordinates of the descriptor and the gradient orientations are rotated relative to the keypoint orientation&quot;.&#xA;I think the rotated thing is not the keypoint locations and it should be the window of descriptor and gradient orientations that are rotated after rotating the window. Do you think this is true? &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Should the image size stay the same after convolving with the Gaussian? This will affect the keypoint locations.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Vevaldi provided a &lt;a href=&quot;http://vision.ucla.edu/~vedaldi/code/sift.html&quot; rel=&quot;nofollow&quot;&gt;great implementation&lt;/a&gt;. Because it is in .mex format i can't see what is going on inside. Other open source codes' solutions also haven't satisfied me. Hence I am asking for your help.&lt;/p&gt;&#xA;" OwnerUserId="4589" LastEditorUserId="231" LastEditDate="2016-06-18T10:57:17.673" LastActivityDate="2016-06-18T10:57:17.673" Title="SIFT Feature Extraction" Tags="&lt;image-processing&gt;&lt;scene-description&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3634" PostTypeId="1" AcceptedAnswerId="3636" CreationDate="2016-06-16T22:11:13.730" Score="3" ViewCount="144" Body="&lt;p&gt;To compile shaders, I currently spin up a thread per core where each thread pulls a shader from a list and calls D3DX11CompileFromFile for dx11 and D3DXCompileShaderFromFile for dx9.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've heard it mentioned that spinning up multiple processes instead of multiple threads can be faster, since there is some sort of per process driver contention.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Has anyone tried this, or does anyone have any tips on how to speed up shader compilation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a modern machine w/ SSD drives.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-06-17T04:11:11.553" Title="Fastest shader compilation strategy on windows dx9 and dx11?" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3636" PostTypeId="2" ParentId="3634" CreationDate="2016-06-17T04:11:11.553" Score="4" Body="&lt;p&gt;From what I can find out (not having tried it myself), using a thread per core to do D3D compiles is &lt;a href=&quot;https://twitter.com/solid_angle/status/327572869699731457&quot;&gt;reported&lt;/a&gt; to be safe and gives a good perf speedup, and there &lt;a href=&quot;https://twitter.com/repi/status/327580478062333952&quot;&gt;doesn't seem to be any contention&lt;/a&gt; between threads in the compiler itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, &lt;a href=&quot;https://twitter.com/rygorous/status/327582029296324608&quot;&gt;Fabian Giesen notes&lt;/a&gt; that you might see lower perf when running under a debugger, due to contention in the Windows debug heap allocator, &lt;a href=&quot;http://preshing.com/20110717/the-windows-heap-is-slow-when-launched-from-the-debugger/&quot;&gt;which can (and probably should) be disabled&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, the functions you mentioned are both wrappers around &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dd607324.aspx&quot;&gt;&lt;code&gt;D3DCompile&lt;/code&gt;&lt;/a&gt;, and don't involve the driver per se at all; they only do the GPU-independent &quot;HLSL source to bytecode&quot; step, and not the GPU-specific &quot;bytecode to machine code&quot; step. So they're entirely Microsoft code, not GPU IHV code.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-06-17T04:11:11.553" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3637" PostTypeId="1" AcceptedAnswerId="3638" CreationDate="2016-06-17T11:42:59.457" Score="4" ViewCount="1696" Body="&lt;p&gt;WebGL 1.0 specification does not allow &lt;a href=&quot;https://www.khronos.org/webgl/public-mailing-list/archives/1102/msg00093.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;to create 32-bit index buffers&lt;/a&gt;. Now I'm in trouble, I'm trying to render huge objects with 100 thousands to 1 million indices. In OpenGL this is no issue at all, and I think it will be no issue in WebGL too, in most cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not able &lt;a href=&quot;https://stackoverflow.com/a/5189502/1260906&quot;&gt;to split my data into smaller subsets&lt;/a&gt; as I'm already working with split data sets and can't divide it further without breaking up my full program logic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I came across a new extension for WebGL from 2012, &lt;a href=&quot;https://www.khronos.org/registry/webgl/extensions/OES_element_index_uint/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OES_element_index_uint&lt;/a&gt;, which looks like it enables unsigned integers (32 bit) for &lt;code&gt;drawElements&lt;/code&gt; calls. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/* draw geometry lines by indices */&#xA;gl.drawElements(gl.LINES, getIndexBuffer().length, gl.UNSIGNED_INT, idxBuffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But when I try to use the &lt;code&gt;gl.UNSIGNED_INT&lt;/code&gt; I run into the following error:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Error: WebGL: drawElements: Invalid `type`: 0x1405&#xA;uncaught exception: gl.INVALID_ENUM was caused by call to drawElements&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How to use 32 bit Integers for Element Indices in WebGL 1.0? How to enable this extension in Chrome or Firefox?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this mean in general such a call won't be compatible with most devices running WebGL 1.0?&lt;/p&gt;&#xA;" OwnerUserId="361" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-06-18T10:23:14.050" Title="How to use 32 bit Integers for Element Indices in WebGL 1.0?" Tags="&lt;webgl&gt;&lt;drawing&gt;&lt;types&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3638" PostTypeId="2" ParentId="3637" CreationDate="2016-06-17T12:00:41.297" Score="5" Body="&lt;p&gt;Enabling the extension is as simple as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var uints_for_indices = gl.getExtension(&quot;OES_element_index_uint&quot;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;if &lt;code&gt;uints_for_indices&lt;/code&gt; is null then the extension is not available and you'll have to split your data anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it's not null then you can now pass &lt;code&gt;gl.UNSIGNED_INT&lt;/code&gt; for the index type into &lt;code&gt;gl.drawElements&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-06-17T12:00:41.297" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3639" PostTypeId="1" AcceptedAnswerId="3734" CreationDate="2016-06-17T12:28:27.927" Score="4" ViewCount="449" Body="&lt;p&gt;I have a mesh loaded by an obj file (wavefront), complete with normals and texture coordinates per face, and its relative texture available. In my C++ / OpenGL code (assignment for a computer graphics class) I bind correctly the texture, but fail at correctly mapping texture coordinates with face vertexes. Below I show the code for texture binding and the chain of calls to rasterize the object. I also show images for the expected result and the actual results (2 of them, one for each render setting). To be specific, it seems that the first render &quot;tessellates&quot; the plain image on the rasterized shape of the whole object, while the second maps the image once on the shape of the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is going on here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nQ2Ez.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nQ2Ez.png&quot; alt=&quot;Expected result&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/LEOSJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LEOSJ.png&quot; alt=&quot;Result #1&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/q7TXB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/q7TXB.png&quot; alt=&quot;Result #2 (don&amp;#39;t mind the background)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bind procedure:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;SDL_Surface *s = IMG_Load(filename.c_str());&#xA;&#xA;glBindTexture(GL_TEXTURE_2D, textureIndex);&#xA;gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB,&#xA;        s-&amp;gt;w, s-&amp;gt;h, GL_RGB, GL_UNSIGNED_BYTE, s-&amp;gt;pixels);&#xA;glTexParameteri(GL_TEXTURE_2D,&#xA;        GL_TEXTURE_MAG_FILTER,&#xA;        GL_LINEAR );&#xA;glTexParameteri(GL_TEXTURE_2D,&#xA;        GL_TEXTURE_MIN_FILTER,&#xA;        GL_LINEAR_MIPMAP_LINEAR );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Raster procedure (pseudo code intended):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// gl pushMatrix, Traslation and rotations;&#xA;glPushMatrix();&#xA;glEnable(GL_TEXTURE_2D);&#xA;glBindTexture(GL_TEXTURE_2D, textureIndex);&#xA;glColor3f(1,1,1);&#xA;glEnable(GL_TEXTURE_GEN_S);&#xA;glEnable(GL_TEXTURE_GEN_T);&#xA;glDisable(GL_LIGHTING);&#xA;glBegin(GL_TRIANGLES);&#xA;for (face f in faces) {&#xA;  glNormal3d(faceNormal.x, faceNormal.y, faceNormal.z);&#xA;  for (i = 0, i &amp;lt; 3, ++i) {&#xA;    glTexCoord3d(texturePoint[i].x, texturePoint[i].y, 0);&#xA;    glVertex3d(vertex[i].x, vertex[i].y, vertex[i].z);&#xA;  }&#xA;}&#xA;glEnd();&#xA;glPopMatrix();&#xA;// gl PopMatrix to exit from traslation / rotation context.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3472" LastEditorUserId="38" LastEditDate="2016-09-29T08:32:33.657" LastActivityDate="2016-09-29T08:32:33.657" Title="OpenGL Vertex - Texture Mapping" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;legacy-opengl&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3640" PostTypeId="2" ParentId="3639" CreationDate="2016-06-17T12:38:47.507" Score="2" Body="&lt;pre&gt;&lt;code&gt;for (i = 0, i &amp;lt; 3, ++i)&#xA;    glTexCoord3d(texturePoint[i].x, texturePoint[i].y, 0);&#xA;    glVertex3d(v[i]-&amp;gt;x(), v[i]-&amp;gt;y(), v[i]-&amp;gt;z());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code calls &lt;code&gt;glTexCoord3d&lt;/code&gt; three times and &lt;code&gt;glVertex3d&lt;/code&gt; only once. You need more braces around your &lt;code&gt;for&lt;/code&gt; loop.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-06-17T12:38:47.507" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3641" PostTypeId="1" AcceptedAnswerId="3642" CreationDate="2016-06-17T18:41:05.410" Score="5" ViewCount="933" Body="&lt;p&gt;I'm building an engine, which has Vulkan for its primary rendering engine. But to have at least some backwards compatibility with devices that don't have drivers for it (mainly mobile) I want to implement an OpenGL fallback. Now, how do I check what API's are available in the current system?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to check if Vulkan support exists, if not then if OpenGL support exists and if not that then crash.&lt;/p&gt;&#xA;" OwnerUserId="4603" LastEditorUserId="231" LastEditDate="2016-06-18T09:14:51.010" LastActivityDate="2016-06-18T09:14:51.010" Title="How to check which API's are available on a given machine?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;vulkan&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3642" PostTypeId="2" ParentId="3641" CreationDate="2016-06-17T19:46:24.013" Score="3" Body="&lt;p&gt;Basic Vulkan availability can be checked by the presence of the loader dynamic library. This will reside in a standard place where you can load it with &lt;code&gt;dlopen&lt;/code&gt; or &lt;code&gt;LoadLibrary&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it fails to load then vulkan is not installed. If it does load then you can get the vkGetInstanceProcAddr function pointer from it with &lt;code&gt;dlsym&lt;/code&gt;or &lt;code&gt;GetProcAddress&lt;/code&gt;. After that you can query the devices as normal and decide whether or not it's sufficient to support your app.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-06-17T19:46:24.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3643" PostTypeId="2" ParentId="3641" CreationDate="2016-06-17T19:49:16.273" Score="0" Body="&lt;p&gt;If i remember correctly i have read somewhere that all the graphic cards that supports OpenGL version 3.0 and on, will support Vulkan, just new drivers are required. You can get the OpenGL version with &lt;code&gt;glGetString(GL_VERSION)&lt;/code&gt;, read &lt;a href=&quot;https://www.opengl.org/wiki/Get_Context_Info#OpenGL_version_number&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://www.khronos.org/opengles/sdk/1.1/docs/man/glGetString.xml&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway i don't think comparing strings is a good way, i am sure there would be a better way of doing this and somebody will  point it out nor i know if this will work.&lt;/p&gt;&#xA;" OwnerUserId="3437" LastActivityDate="2016-06-17T19:49:16.273" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3645" PostTypeId="1" CreationDate="2016-06-19T06:55:39.910" Score="4" ViewCount="226" Body="&lt;p&gt;Using VTK 7.0 I have found that rendering a 20k triangle STL model takes approximately 17ms on my Nvidia GTX970. However, I am only interested in the silhouette of this model (like the image below) and was wondering if: a) such speeds are reasonable for this model size, and b) since I am not really interested in a full render, is there a much faster way to compute just that silhouette? I considered a ray tracing approach where I just compute whether or not each pixel hits the model, but since I am only interested in speed I do not know if this is a good route to pursue. As a side note, these questions need not be specific to VTK - I am really just conerned with the fastest way to utilize a GPU to compute a silhouette (suggestions algorithms, theory, or libraries are all all welcome!) and what reasonable times I can expect for such model sizes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CBp4P.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CBp4P.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4611" LastActivityDate="2018-04-20T16:53:12.957" Title="How fast should I expect to render the silhouette of a 20k triangle model?" Tags="&lt;rendering&gt;&lt;silhouette&gt;&lt;vtk&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3646" PostTypeId="1" AcceptedAnswerId="3647" CreationDate="2016-06-19T11:03:51.923" Score="10" ViewCount="14321" Body="&lt;p&gt;With respect to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2450/opengl-detection-of-edges&quot;&gt;this topic &lt;/a&gt; I've successfully implemented the &lt;a href=&quot;https://en.wikipedia.org/wiki/Sobel_operator&quot; rel=&quot;noreferrer&quot;&gt;Sobel Edge Detection&lt;/a&gt; filter in GLSL. Here is the fragment shader code of the filter:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;in vec2 TexCoords;&#xA;out vec4 color;&#xA;&#xA;uniform sampler2D screenTexture;&#xA;&#xA;mat3 sx = mat3( &#xA;    1.0, 2.0, 1.0, &#xA;    0.0, 0.0, 0.0, &#xA;   -1.0, -2.0, -1.0 &#xA;);&#xA;mat3 sy = mat3( &#xA;    1.0, 0.0, -1.0, &#xA;    2.0, 0.0, -2.0, &#xA;    1.0, 0.0, -1.0 &#xA;);&#xA;&#xA;void main()&#xA;{&#xA;    vec3 diffuse = texture(screenTexture, TexCoords.st).rgb;&#xA;    mat3 I;&#xA;    for (int i=0; i&amp;lt;3; i++) {&#xA;        for (int j=0; j&amp;lt;3; j++) {&#xA;            vec3 sample  = texelFetch(screenTexture, ivec2(gl_FragCoord) + ivec2(i-1,j-1), 0 ).rgb;&#xA;            I[i][j] = length(sample); &#xA;    }&#xA;}&#xA;&#xA;float gx = dot(sx[0], I[0]) + dot(sx[1], I[1]) + dot(sx[2], I[2]); &#xA;float gy = dot(sy[0], I[0]) + dot(sy[1], I[1]) + dot(sy[2], I[2]);&#xA;&#xA;float g = sqrt(pow(gx, 2.0)+pow(gy, 2.0));&#xA;color = vec4(diffuse - vec3(g), 1.0);&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is the result of a cube with Sobel edge detection:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PawMD.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PawMD.png&quot; alt=&quot;Cube with Sobel edge detection filter&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you enlarge the picture, you will see that there is a lot of &quot;noise&quot; produced by Sobel: &#xA;There are gray horizontal stripes all over the scene due to the blue/white gradient. Futhermore, the light cones produce an unwanted pattern on the cube. The black edges on the left of the cube also seem to fade because of the light cone on the left half of the cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I read &lt;a href=&quot;https://www.objc.io/issues/21-camera-and-photos/gpu-accelerated-machine-vision/&quot; rel=&quot;noreferrer&quot;&gt;this article&lt;/a&gt; which stated that one should grayscale the image first and use a Gaussian blur filter to make the edges more apparent. On the bottom of the article, there is also the canny edge detection filter which seem to produce better results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have two questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Are the following steps correct to produce the best possible edge detection results:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Grayscale&lt;/li&gt;&#xA;&lt;li&gt;Gaussian Blur&lt;/li&gt;&#xA;&lt;li&gt;Sobel/Canny edge detection&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If yes, how would I merge the original image with the processed image? I mean, after processing the steps stated above, I get an image that is either completely black with white edges or vice verca. How would I put the edges on my original image/texture?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Thanks for your help!&lt;/p&gt;&#xA;" OwnerUserId="3377" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-10-10T00:52:10.017" Title="OpenGL GLSL - Sobel Edge Detection Filter" Tags="&lt;opengl&gt;&lt;edge-detection&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3647" PostTypeId="2" ParentId="3646" CreationDate="2016-06-19T13:10:38.510" Score="9" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;The best results&lt;/em&gt; strongly depend on your use case. They also depend on what effect you want to achieve. Sobel is just an edge detection filter: the edges will depend on the input signal, choosing that input signal is up to you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here you are using the color image as an input, and the filter rightfully detects faint edges in the blue gradient, while the edges of the cube get interrupted where its color is too close from the background color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I assume your program is also responsible for drawing the cube, you have access to other information that you can feed to your Sobel filter. For example depth and normals are good candidates for edge detection. The albedo before lighting could be used to. Test with different inputs and decide which ones to use depending on the results you get.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Regarding your question about how to combine the edge information, I suggest you filter &lt;code&gt;g&lt;/code&gt; a little before using it. Then you can use it to interpolate between the original color and the wanted edge color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example you could try something like this:&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;    float g = sqrt(pow(gx, 2.0)+pow(gy, 2.0));&#xA;&#xA;    // Try different values and see what happens&#xA;    g = smoothstep(0.4, 0.6, g);&#xA;&#xA;    vec3 edgeColor = vec3(1., 0., 0.2);&#xA;    color = vec4(mix(diffuse, edgeColor, g), 1.);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h3&gt;Addendum&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;To use depth or normals, you would need to save them in a texture if that's not done already. When you create the frame buffer for your regular rendering pass, you can attach various textures to it (see &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glFramebufferTexture.xhtml&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;glFramebufferTexture2D&lt;/code&gt;&lt;/a&gt;) and write other information to them than just the color of the scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you attach a depth texture (with &lt;code&gt;GL_DEPTH_ATTACHMENT&lt;/code&gt;), it will be used automatically for depth. If you attach one or several color textures (with &lt;code&gt;GL_COLOR_ATTACHMENTi&lt;/code&gt;), you can write to them by declaring several outputs to your fragment shaders (this used to be done with &lt;code&gt;gl_FragData&lt;/code&gt;; either way, see &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glDrawBuffers.xhtml&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;glDrawBuffers&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information on the topic, look up &lt;em&gt;&quot;Multi Render Target&quot;&lt;/em&gt; (MRT).&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-06-22T12:27:08.380" LastActivityDate="2016-06-22T12:27:08.380" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3648" PostTypeId="1" CreationDate="2016-06-19T22:19:58.373" Score="1" ViewCount="66" Body="&lt;p&gt;I'm very confused about sampling and reconstruction of images.&#xA;I read that in the framebuffer there is a sampled representation of an image, for visualization the sampled representation is converted into a continuous one by the video hardware.&#xA;Which filter is used by an LCD display ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But isn't an LCD display already digital ?&lt;/p&gt;&#xA;" OwnerUserId="1636" LastActivityDate="2016-06-20T05:03:17.427" Title="Reconstruction filter of LCD monitor" Tags="&lt;sampling&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3649" PostTypeId="2" ParentId="3648" CreationDate="2016-06-20T05:03:17.427" Score="2" Body="&lt;p&gt;The output of an LCD or other display is continuous by virtue of its being a physical device, with pixels that have some size and shape, and emit some physical spectrum of light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/E8hHG.jpg&quot; alt=&quot;close up of an iPhone 4 display&quot;&gt;&lt;br/&gt;from &lt;a href=&quot;http://prometheus.med.utah.edu/~bwjones/2010/06/apple-retina-display/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Apple Retina Display by Bryan Jones&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My guess as to what's meant by the comment that &quot;the sampled representation is converted into a continuous one by the video hardware&quot; is just that the input to the hardware is a sampled digital signal that drives the physical pixels, while the output is a continuous light field such as the above. So the &quot;reconstruction filter&quot;, so to speak, is the physical pattern of light emitted when the display is turned on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Also note that displays often do additional digital processing of the input image before displaying it, e.g. to adjust brightness, contrast, color temperature, sharpness, and so forth. But those things wouldn't be called a reconstruction filter.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-06-20T05:03:17.427" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3650" PostTypeId="2" ParentId="3639" CreationDate="2016-06-20T07:43:31.553" Score="1" Body="&lt;p&gt;Your geometry may be prepared for Direct3D, which has texture space origin placed differently (top-left vs bottom-left corner). Try flipping either the texture's Y coordinates (i.e. load it from the bottom to the top), or the V texture coordinate (&lt;code&gt;glTexCoord3d(texturePoint[i].x, 1.0f - texturePoint[i].y, 0);&lt;/code&gt;).&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-06-20T07:43:31.553" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3651" PostTypeId="1" AcceptedAnswerId="3653" CreationDate="2016-06-20T16:46:02.933" Score="5" ViewCount="801" Body="&lt;p&gt;I am looking for the correct term for a type of problem solver. Since its hard to google for something without knowing its name, I hope that the good people of this stackexchange may be able to help me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When defining shapes in CAD systems based on constructive solid geometry, you start out with a (usually 2D) sketch, from which you extrude, rotate, or otherwise generate a 3D shape. You make this sketch by defining a set of curves (lines, arcs, bezier, etc.) and then defining a set of constraints. This is co-linear to that, this line is parallel to that line, the distance here is so and so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you define a valid combination of constraints, the CAD system can almost always find a configuration of the curves matching those constraints. What is the part of the CAD system called, that finds those solutions? Is there a good open-source implementation that I could use?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried search terms like &quot;geometry solver&quot; or &quot;geometric solver&quot;, but I couldn't find anything relevant.&lt;/p&gt;&#xA;" OwnerUserId="4620" LastEditorUserId="231" LastEditDate="2016-06-21T08:12:11.553" LastActivityDate="2016-06-21T08:12:11.553" Title="Solving a set of Geometry Constraints - What's that Method called?" Tags="&lt;computational-geometry&gt;&lt;cad&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3652" PostTypeId="1" AcceptedAnswerId="3655" CreationDate="2016-06-20T17:29:05.517" Score="9" ViewCount="3243" Body="&lt;p&gt;I've worked with various interpolation algorithms including linear, cubic (and bilinear and bicubic), other bezier (and nurbs, etc) based interpolations, lagrange interpolation and some others, but I haven't been able to find any basic info that explains what bilateral upsampling is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been able to find information on &lt;a href=&quot;http://johanneskopf.de/publications/jbu/&quot;&gt;Joint Bilateral Upsampling&lt;/a&gt; which as best as I can tell interpolates multiple pieces of data in parallel, using hints from each to help the other interpolate better, but am having trouble separating the info of BU and JBU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is anyone able to explain the basic ideas of what bilateral upsampling is about?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-06-21T08:50:29.780" Title="What is bilateral upsampling?" Tags="&lt;image-processing&gt;&lt;interpolation&gt;&lt;image&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3653" PostTypeId="2" ParentId="3651" CreationDate="2016-06-20T19:31:53.083" Score="3" Body="&lt;p&gt;Its called a &lt;strong&gt;geometric constraints solver&lt;/strong&gt; (a &lt;a href=&quot;https://www.cs.purdue.edu/homes/cmh/distribution/papers/Constraints/CAD95.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;good primer&lt;/a&gt; on subject). You can find a open source solver as part of &lt;a href=&quot;http://www.opencascade.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Open Cascade&lt;/a&gt; but its a bit convoluted to get going. A simpler solution for just solving, but also 3D solver capable, is &lt;a href=&quot;http://geosolver.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;geosolver&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Making your own (algebraic solution being easiest to write) is also not that hard, just a bit of work to make it automatically write the equations (and be efficient at solving). Take the following drawing as a example (made and solved with Mathematica):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hoDbc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hoDbc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can simply conclude that its a sum of vectors that has to loop back at the origin thus:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;7\begin{pmatrix}\sin(15^\circ)\\ \cos(15^\circ)\end{pmatrix}+5\begin{pmatrix}\sin(120^\circ)\\ \cos(120^\circ)\end{pmatrix}+2\begin{pmatrix}\sin(195^\circ)\\ \cos(195^\circ)\end{pmatrix}+4\begin{pmatrix}\sin(\delta)\\ \cos(\delta)\end{pmatrix}+x\begin{pmatrix}\sin(-90^\circ)\\ \cos(-90^\circ)\end{pmatrix}=0&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And solve the 2 unknowns from 2 equations, either algebraically or by using a gradient descent solver of some kind.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-06-21T06:38:59.667" LastActivityDate="2016-06-21T06:38:59.667" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3654" PostTypeId="2" ParentId="3615" CreationDate="2016-06-20T19:47:03.700" Score="0" Body="&lt;p&gt;If I understand you correctly, you have a 3D model, and a video of the real world object? This sounds like a job for photogrammetry. Using a photogrammetry plugin, you can derive a model of what is seen in the video, and a texture map of it. The derived model probably won't be exactly like your 3D model, but you may be able to remap the texture map back onto your 3D model. Doing a search on photogrammetry and blender should give you some good links.&lt;/p&gt;&#xA;" OwnerUserId="3184" LastActivityDate="2016-06-20T19:47:03.700" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3655" PostTypeId="2" ParentId="3652" CreationDate="2016-06-20T20:56:30.480" Score="9" Body="&lt;p&gt;It seems like you're asking two things.  I can't really speak technically about JBU, but I can give an overview of the necessary concepts and bilateral filtering generally.  You'll probably need to find more details yourself, but this should give a coherent structure to start from.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h2&gt;Fixing &amp;quot;Image&amp;quot;s&lt;/h2&gt;&#xA;&lt;p&gt;Many image-processing people view filtering as either something to be done as a post-process, or as a way to scale images.  The mathematician's perspective is more accurate, descriptive, and complex.&lt;/p&gt;&#xA;&lt;p&gt;When you have an image file, you don't have a real image.  You have pixel &amp;quot;values&amp;quot;, which are strictly valid &lt;em&gt;only&lt;/em&gt; at the center of pixels.  Roughly speaking, each pixel has an &lt;em&gt;area&lt;/em&gt; that takes on that color.  Mathematically, what you're doing is using a &lt;em&gt;nearest-neighbor reconstruction filter&lt;/em&gt; to reconstruct the true image from pixel values.  So &lt;strong&gt;an &amp;quot;image&amp;quot; is really a set of samples and a reconstruction filter, typically nearest-neighbor&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;h2&gt;Resampling&lt;/h2&gt;&#xA;&lt;p&gt;When you upscale an image, what you're really doing is &lt;em&gt;resampling&lt;/em&gt;.  How do you do this?  You take your signal, and generate a new set of samples from it.  But for an image, I just said we don't &lt;em&gt;have&lt;/em&gt; the real image; we have to reconstruct it first.  So a typical resampling procedure looks like this:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Take your pixel values.&lt;/li&gt;&#xA;&lt;li&gt;Reconstruct an image between the values, which live at pixel centers, by using reconstruction filtering.&lt;/li&gt;&#xA;&lt;li&gt;Measure a new set of samples from the reconstructed image, possibly spaced differently.&lt;/li&gt;&#xA;&lt;li&gt;Throw away the old samples and use the new ones.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;strong&gt;The key point is that the reconstruction filter used is the &amp;quot;filter&amp;quot; used for resampling.&lt;/strong&gt;  For example, a &amp;quot;bicubic upsample&amp;quot; would use a bicubic reconstruction filter.&lt;/p&gt;&#xA;&lt;p&gt;It turns out that if you use a sinc function for the reconstruction filter, and you don't shrink the image, you get (theoretically) the same image back.  In fact, if you upscale the image and then downscale it again, you'll get the same answer.  This isn't generally true for any other filter.&lt;/p&gt;&#xA;&lt;p&gt;Most filters approximate a sinc filter to more or lesser degrees.  Deviations result in image loss.&lt;/p&gt;&#xA;&lt;h2&gt;Filtering&lt;/h2&gt;&#xA;&lt;p&gt;If you use the same before/after sampling rate, you do something called &amp;quot;filtering&amp;quot;.  Formally, &lt;strong&gt;filtering is resampling without a change in sample rate.  Filtering is a special case of resampling.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The only possible purpose to filtering it to throw away information (e.g. a Gaussian) or possibly also to distort or add spurious information (e.g. a Sobel).&lt;/p&gt;&#xA;&lt;h1&gt;Bilateral Filtering&lt;/h1&gt;&#xA;&lt;p&gt;You can use many different filters for filtering.  Bilateral filtering is one of them.  I don't believe it's considered state-of-the-art for any purpose now (though I don't know what is; probably some newfangled machine-learning thing I expect).&lt;/p&gt;&#xA;&lt;p&gt;A bilateral filter is a non-linear filter, meaning it doesn't have a nice Fourier representation.  Conceptually, it is like a Gaussian, but the source colors themselves also factor into a pixel's &amp;quot;distance&amp;quot; from others.  This tends to smooth flat areas while preserving edges.&lt;/p&gt;&#xA;&lt;h1&gt;Bilateral Upscaling&lt;/h1&gt;&#xA;&lt;p&gt;By now, I hope you see where I'm going with this: any filter you can use for filtering, you can use for upscaling or downscaling, which are really the same thing (because all of it is resampling).&lt;/p&gt;&#xA;&lt;p&gt;If you've implemented a bilateral filter, you should be able to rather simply implement a bilateral filter resampler - just as, if you've implemented a Gaussian filter, you should be able to implement a Gaussian filter resampler.&lt;/p&gt;&#xA;&lt;p&gt;The only difficulty may be the definitions.  Unfortunately, the distinction between filtering and resampling is systemically muddied to occasional non-existence in the image-processing literature.  For implementing a bilateral-type filter, I would rely heavily on its similarities to Gaussian resampling.  IIRC (I haven't read the paper in years) bilateral filtering is posed in terms of pixels, not samples.&lt;/p&gt;&#xA;" OwnerUserId="523" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-06-21T08:35:13.940" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3656" PostTypeId="2" ParentId="3627" CreationDate="2016-06-21T01:25:58.780" Score="3" Body="&lt;p&gt;Maybe you need to write down the spec of what you want to do first, usually when you know the problem you know the solution. So mostly, life is a matter of finding the problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe in your case, what you want to do is replicate what GPUs were in 1996, that is, a brute force texture filler specialized hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPUs did nothing back then, no vertex transform, no 3d, they just took regions in 2d (triangles after projection) and filled them. The only 3d-like operation that the hardware could do, was the division by w during rasterization. Pretty handy to have dedicated hardware to do that, since CPUs suck at this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if you want to do wireframe, basically your hardware will be a &lt;a href=&quot;https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm&quot; rel=&quot;nofollow&quot;&gt;bresenham&lt;/a&gt; implementation but in FPGA. Are you sure this makes any sense?&lt;br&gt;&#xA;Bresenham parallelization will be an interesting job though, you can split your space into screen tiles and do grid-scheduling (eg &lt;code&gt;ALU[i], i = pixelX / 32 % numalu&lt;/code&gt; for 32 pixel wide tiles). You'll need to clip your lines to the tiles borders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though it seems to me that your biggest challenge will be to convert your frontbuffer to display port protocol. Or VGA if you still have that. maybe some ready to use chips exist for that (or FPGA schemas that you can load and append to your design?).&lt;/p&gt;&#xA;" OwnerUserId="1614" LastEditorUserId="231" LastEditDate="2016-06-21T08:19:30.473" LastActivityDate="2016-06-21T08:19:30.473" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3657" PostTypeId="2" ParentId="3652" CreationDate="2016-06-21T08:50:29.780" Score="3" Body="&lt;p&gt;This probably does not explore the full depth of the term, but the first thing that comes to my mind when I hear &quot;bilateral upsampling&quot; is depth-aware blending of low-resolution images onto high-resolution ones; for instance, when you render alpha-blended geometry to a half-resolution buffer (for performance savings) and then composite it back onto the main render target. Angelo Pesce &lt;a href=&quot;http://c0de517e.blogspot.com/2016/02/downsampled-effects-with-depth-aware.html&quot; rel=&quot;nofollow&quot;&gt;wrote a post&lt;/a&gt; that explains it well.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-06-21T08:50:29.780" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3659" PostTypeId="1" CreationDate="2016-06-21T22:25:47.030" Score="3" ViewCount="413" Body="&lt;p&gt;I am trying to pick objects on mouse click. For this I have followed &lt;a href=&quot;https://en.wikibooks.org/wiki/OpenGL_Programming/Object_selection#Using_the_stencil_buffer_to_identify_objects&quot; rel=&quot;nofollow&quot;&gt;this tutorial&lt;/a&gt;, and tried to use the stencil buffer for this purpose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inside &quot;game&quot; loop I am trying to draw 10 (5 pairs) 'pick'able triangles as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;...&#xA;&#xA;glClearColor(red, green, blue, 1.0f);&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);&#xA;&#xA;glClearStencil(0); // this is the default value&#xA;&#xA;/* Enable stencil operations */&#xA;glEnable(GL_STENCIL_TEST);&#xA;glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);&#xA;&#xA;/*Some other drawing not involving stencil buffer*/&#xA;&#xA;GLuint index = 1;&#xA;for (GLshort i = 0; i &amp;lt; 5; i++)&#xA;{&#xA;    //this returns 2 model matrices&#xA;    auto modelMatrices = trianglePairs[i].getModelMatrices(); &#xA;&#xA;    for (GLshort j = 0; j &amp;lt; 2; j++)&#xA;    {&#xA;        glStencilFunc(GL_ALWAYS, index, -1);&#xA;        glUniformMatrix4fv(glGetUniformLocation(ourShader.Program, &quot;model&quot;), 1, GL_FALSE, glm::value_ptr(modelMatrices[j]));&#xA;        glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, BUFFER_OFFSET(2));&#xA;        index++;&#xA;    }&#xA;    /*Some other drawing not involving stencil buffer*/&#xA;}&#xA;&#xA;/*Some other drawing not involving stencil buffer*/&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, when I am trying to read back the stencil values, I am getting wrong values. I am reading back the values as (this is also a &lt;a href=&quot;https://en.wikibooks.org/wiki/OpenGL_Programming/Object_selection#Reading_back_information_from_the_framebuffer&quot; rel=&quot;nofollow&quot;&gt;part of the above-mentioned tutorial&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint index;&#xA;glReadPixels(xpos, Height - ypos - 1, 1, 1, GL_STENCIL_INDEX, GL_UNSIGNED_INT, &amp;amp;index);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Whenever, I click the first triangle of the pair I am getting values as &lt;code&gt;i+1&lt;/code&gt;, whereas the correct value should have been &lt;code&gt;i&lt;/code&gt;, and for the second triangle of the pair, I am getting &lt;code&gt;0&lt;/code&gt; as &lt;code&gt;index&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please let me know what am I missing here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&#xA;I have found that stencil values can be applied on quads. When I tried to apply the stencil value on rectangle it worked correctly. Though it is not the solution I was looking at, still, I can live with that. However, I would still like to know what was the problem with triangles.&lt;/p&gt;&#xA;" OwnerUserId="3098" LastEditorUserId="3098" LastEditDate="2016-06-24T07:40:36.590" LastActivityDate="2016-06-24T18:10:04.783" Title="Incorrect values written in stencil buffer" Tags="&lt;opengl&gt;&lt;stencil-buffer&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3660" PostTypeId="1" AcceptedAnswerId="3710" CreationDate="2016-06-22T00:47:44.900" Score="6" ViewCount="1186" Body="&lt;p&gt;(I've largely revamped this entire question, though the motivation remains the same.)&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;revised question&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;I want to convert a raster of cartesian pixels into polar pixels.  Is there a sensible algorithm for doing this?  For example, how do I compute the value of the shaded (polar) pixel in the image below, given the value of the three (cartesian) pixels that it overlaps?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/c2Lh0.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c2Lh0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;h3&gt;original question&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Is there a reasonable way to compute the area of the intersection of a square and an annular section, as shown in the orange section below?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Tz312.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Tz312.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The motivation: I have a raster of square pixels, and I'm converting it to &quot;polar pixels&quot; -- I want to find out the contribution of each cartesian pixel to each polar pixel.&lt;/p&gt;&#xA;" OwnerUserId="4625" LastEditorUserId="4625" LastEditDate="2016-06-22T15:21:21.537" LastActivityDate="2016-07-02T07:02:48.307" Title="Converting cartesian pixels to polar pixels" Tags="&lt;polygon&gt;&lt;2d-graphics&gt;" AnswerCount="2" CommentCount="10" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3661" PostTypeId="1" AcceptedAnswerId="3714" CreationDate="2016-06-22T04:38:08.857" Score="3" ViewCount="4147" Body="&lt;p&gt;I am basically following &lt;a href=&quot;http://ogldev.atspace.co.uk/www/tutorial18/tutorial18.html&quot; rel=&quot;nofollow&quot;&gt;this tutorial&lt;/a&gt; about diffuse lighting in OpenGL.&#xA;I did some modifications but the idea is the same, at least that's what I think. However, my fragment shader is not showing any colors. I checked and rechecked my uniform variables and light properties and data is ok on CPU side (don't know how to check on GPU side, though).&#xA;Here are my shaders where I cannot spot any errors, maybe someone can help me out&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;VERTEX SHADER&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410&#xA;&#xA;in vec4 vposition;&#xA;in vec3 vnormal;&#xA;&#xA;uniform mat4 M;&#xA;uniform mat4 VP;&#xA;&#xA;out vec4 fcolor;&#xA;out vec3 fnormal;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position = vposition * M * VP;&#xA;    fcolor = vposition + vec4(0.5);&#xA;    fnormal = (M * vec4(vnormal, 0.0)).xyz;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;FRAGMENT SHADER&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410&#xA;&#xA;in vec4 fcolor;&#xA;in vec3 fnormal;&#xA;&#xA;out vec4 color;&#xA;&#xA;uniform vec3 lightColor;&#xA;uniform vec3 lightDirection;&#xA;uniform float lightIntensity;&#xA;&#xA;void main()&#xA;{&#xA;    vec3 N = normalize(fnormal);&#xA;    vec3 L = normalize(lightDirection);&#xA;    float visibility = clamp(dot(N, L), 0.0, 1.0);&#xA;    color = fcolor * vec4(lightColor, 1.0) * lightIntensity * visibility;&#xA;    //color = vec4(1.0); Not even this shows model in complete white&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The buffer for my mesh are created like follows, maybe it helps out detecting the problem&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Mesh::initBuffers()&#xA;{&#xA;    glGenVertexArrays(1, &amp;amp;m_verticesVao);&#xA;    glBindVertexArray(m_verticesVao);&#xA;&#xA;    glGenBuffers(1, &amp;amp;m_positionsVbo);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, m_positionsVbo);&#xA;    glBufferData(GL_ARRAY_BUFFER, m_numVertices * 3 * sizeof(float), &amp;amp;m_positions[0], GL_STATIC_DRAW);&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);&#xA;&#xA;    glGenBuffers(1, &amp;amp;m_normalsVbo);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, m_normalsVbo);&#xA;    glBufferData(GL_ARRAY_BUFFER, m_numVertices * 3 * sizeof(float), &amp;amp;m_normals[0], GL_STATIC_DRAW);&#xA;    glEnableVertexAttribArray(1);&#xA;    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);&#xA;&#xA;    glGenBuffers(1, &amp;amp;m_positionsEbo);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_positionsEbo);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_numIndices * 3 * sizeof(unsigned int), &amp;amp;m_indices[0], GL_STATIC_DRAW);&#xA;&#xA;    glBindVertexArray(0);&#xA;&#xA;    m_initBuffers = true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Commenting all the code related to the normal in shaders results in a correct rendered mesh with colors (or white)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it helps, you can checkout &lt;a href=&quot;https://github.com/BRabbit27/OGLPlayground.git&quot; rel=&quot;nofollow&quot;&gt;my code&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="116" LastEditorUserId="116" LastEditDate="2016-06-24T16:34:55.077" LastActivityDate="2016-07-02T21:12:19.577" Title="Why is my fragment shader not showing any colors?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3663" PostTypeId="1" AcceptedAnswerId="3665" CreationDate="2016-06-23T17:00:01.107" Score="3" ViewCount="404" Body="&lt;p&gt;I was under the impression that the frame buffer resolution always has to be the same as the physical screen resolution, so changing the software resolution settings would not affect rasterization. But after I made a demo and ran a profiler against it, the profiler told me that the frame buffer resolution changed according to my settings and fewer pixels were rasterized.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This brings up other questions I am unable to figure out. Which part of the rendering pipeline does re-sample the frame buffer to match the screen resolution? And the re-sampling stage does not show up in the profiler (Intel GPA for Android), is it so fast that I can safely ignore it or I am missing something that would cost me here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="4624" LastActivityDate="2016-06-24T01:28:27.813" Title="Is there a performance implication if the frame buffer resolution and the physical screen resolution are different?" Tags="&lt;rasterizer&gt;&lt;hardware&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3664" PostTypeId="2" ParentId="3663" CreationDate="2016-06-23T19:38:58.193" Score="1" Body="&lt;p&gt;This is the screen's &lt;a href=&quot;https://en.wikipedia.org/wiki/Video_scaler&quot; rel=&quot;nofollow&quot;&gt;video scaler module&lt;/a&gt;. &#xA;Essentially, it is a dedicated piece of silicon that allows the user to use non-native screen resolutions. &lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-06-23T19:38:58.193" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3665" PostTypeId="2" ParentId="3663" CreationDate="2016-06-24T01:28:27.813" Score="2" Body="&lt;p&gt;For PCs with discrete displays, the resampling to the screen resolution may happen either on the computer prior to the signal being sent to the display, as part of &lt;a href=&quot;https://en.wikipedia.org/wiki/Compositing_window_manager&quot; rel=&quot;nofollow&quot;&gt;window compositing&lt;/a&gt;, or on the display side. I don't think it's anything to worry about in terms of FPS, in either case, but it possibly could affect latency.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It depends whether you're in &quot;true&quot; fullscreen (exclusive) mode or not. If the app renders to a window, including a borderless fullscreen window, then the window compositor (part of the OS) will be running each frame, and any upsampling needed can happen &quot;for free&quot; as part of that operation. In other words, I wouldn't expect an upsample during compositing to cost noticeably more than it does to do compositing in general (which is very cheap).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, if you're in true fullscreen and your app has exclusive control of the display, it's possible to set the video mode to something non-native and send your rendered image directly to the display, in which case the display's scaler chip will handle it, again without performance cost to you, since it's happening in parallel to anything going on with the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You mentioned Android, so I assume you're working on a mobile device. In that case, I'm not sure if there is a scaler chip, or if the mobile GPU is just expected to always output at native resolution, in which case scaling would always be done on the GPU by the compositor software. (By the way, the reason the scaling doesn't show up in profiling is likely because it's being done by the OS rather than by your app.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, though upscaling is very cheap, it does imply an extra pass that could increase input latency. With a borderless fullscreen window, if no other windows are visible on top of your app, and no scaling is required, the compositor could be short-circuited so that your app writes directly to the display output rather than passing through the compositor. (This is an optimization that the OS would have to perform when it detects that all the conditions are right.) Similarly, on the display, if no extra image processing is required including scaling, color correction, etc. then some stages of the display hardware might be bypassed. In either case, you could see lower latency when you render directly to native resolution than when you require scaling. This is a matter of concern for VR in particular.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-06-24T01:28:27.813" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3666" PostTypeId="2" ParentId="3660" CreationDate="2016-06-24T06:02:30.477" Score="0" Body="&lt;p&gt;I called up an old officemate and CG expert, and after asking me a few questions he offered a simple solution.  I may have mangled a few details, but the basic idea follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Subsample the polar coordinates to whatever degree of accuracy needed, treating each subsample as a point.  It's then trivial to find the cartesian pixel that contains each point.  Sum up the sub-sampled points for each polar pixel to get its final value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's some subtlety in getting the weights right -- the guiding insight is that if the entire cartesian raster is flat gray, then each polar pixel should each have the same grayscale value.  And you could add on lots of other nuances, but the basic technique is intuitively and computationally straightforward.&lt;/p&gt;&#xA;" OwnerUserId="4625" LastActivityDate="2016-06-24T06:02:30.477" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3667" PostTypeId="2" ParentId="3659" CreationDate="2016-06-24T18:10:04.783" Score="2" Body="&lt;p&gt;OK, so this not really an answer, rather just sharing what I have learned. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify, shape of the object has nothing to do with this problem at all. Be it a triangle or rectangle, and wherever you click on that object, this method should work (the 'But' for this part is explained below).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think stencil buffer values are associated with each pixel &lt;em&gt;on screen&lt;/em&gt;, and it does not directly maps to the OpenGL window space. Initially I was using a window size that is smaller than my screen size and on top of that it was not full screen. Each time I started (debugging from VS 2015), the window appeared not exactly at &lt;code&gt;(0, 0)&lt;/code&gt; on the screen. Some of the screen space is also consumed by the window bar at the top. I think this is the reason for getting erratic values when reading back the data from stencil buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So as a simple solution to this problem what I did is to make the window full screen, and everything worked like charm. As I use &lt;code&gt;GLFW&lt;/code&gt;, here is how I have done it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glfwCreateWindow(Width, Height, &quot;Title&quot;, glfwGetPrimaryMonitor(), nullptr);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Just used &lt;code&gt;glfwGetPrimaryMonitor()&lt;/code&gt;, while creating the window. And that's it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And yes, it works for triangles too.&lt;/p&gt;&#xA;" OwnerUserId="3098" LastActivityDate="2016-06-24T18:10:04.783" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3668" PostTypeId="1" AcceptedAnswerId="3669" CreationDate="2016-06-24T18:42:43.210" Score="1" ViewCount="77" Body="&lt;p&gt;So I have a batch draw call I am doing with various squares. I have a 4x4 tile map with the numbers 1-16 going in right/down order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it gets to the fragment shader their is a varying float &quot;id&quot; that holds the number. In a perfect world if the id was 0, it would sample the top left and display &quot;0&quot;, if the id was 4 it would sample the top right and display &quot;4&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thankfully this is mostly working! However the numbers 5, 9, and 13 (which happen to be on the left of the tile map flicker! The values on these squares just change frequently. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have traced it down to being the fault of the sample location. And probably this function here: The goal is to take the id and return the proper row and column to texture map.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 getGrid()&#xA;{&#xA;    return vec2(float(int(mod(id, 4.0))), float(floor(id / 4.0)));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It appears that the flickering ones have a constantly changing x result from &quot;getGrid()&quot; and most of the squares have an occasionally changing y result from the &quot;getGrid()&quot; call. I really have no clue why this is happening!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It probably has something to do with the way glsl does math because id and everything else (I have checked) and they are constant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Incase it helps here is the tile map. The texture is actually 2000 x 2000 due to the size these need to be. It will be hard to see because the numbers are white and the background is grey.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/RHOzG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RHOzG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-06-24T19:14:01.930" Title="Flickering tile map" Tags="&lt;texture&gt;&lt;tile-based-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3669" PostTypeId="2" ParentId="3668" CreationDate="2016-06-24T19:14:01.930" Score="1" Body="&lt;p&gt;I realized that the problem was that I was sending the instance id to the fragment shader via a varying, somehow that was causing issues even though each vertex should have had the same id.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-06-24T19:14:01.930" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3671" PostTypeId="1" CreationDate="2016-06-25T06:18:30.003" Score="3" ViewCount="1373" Body="&lt;p&gt;Inspired by Minecraft and LEGOs, we created an app to promote creativity on smartphones. Many people like being creative but find a blank canvas daunting. &quot;Recipes&quot; inside the app let users create like the most talented individuals -- similar to how a cooking recipe lets anyone cook like Thomas Keller.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem so far is users say the app doesn't look &quot;3D&quot; enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the relevant code that creates the scene and creates blocks: &lt;a href=&quot;https://gist.github.com/panabee/dca88a591f94a3904023dacabd020ad9&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gist.github.com/panabee/dca88a591f94a3904023dacabd020ad9&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What they mean is they expect the app to look more like apps like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4Kh0S.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Kh0S.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/LMePj.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LMePj.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/mGfva.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mGfva.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;With encouragement from one of the admins, these screenshots from our app illustrate the disparity in &quot;3Dness&quot;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ntHkQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&#xA;  &lt;img src=&quot;https://i.stack.imgur.com/ntHkQ.jpg&quot; width=&quot;325&quot; alt=&quot;enter image description here&quot;/&gt;&#xA;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dodAZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&#xA;  &lt;img src=&quot;https://i.stack.imgur.com/dodAZ.png&quot; width=&quot;325&quot; alt=&quot;enter image description here&quot;/&gt;&#xA;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We're using SceneKit on iOS, but are having trouble identifying what is needed to make the app look more like the images above. We played with lighting and textures, but are new to 3D graphics as well as SceneKit and are unsure what to do.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have tried to find consultants on StackOverflow, LinkedIn, Github, but this expertise appears not so common.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few questions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) For iOS, is SceneKit capable of producing the images above, or do we need to use something like Metal?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) If SceneKit is capable, what are the key concepts to learn?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) (Happy to strike this question if it's considered off-topic) Which websites/forums could we find people to help provide advice if we get stuck?&lt;/p&gt;&#xA;" OwnerUserId="4638" LastEditorUserId="2785" LastEditDate="2017-03-06T09:28:38.470" LastActivityDate="2017-03-06T09:28:38.470" Title="How to determine if SceneKit can produce sufficiently 3D graphics like Minecraft?" Tags="&lt;voxelization&gt;" AnswerCount="3" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3672" PostTypeId="1" AcceptedAnswerId="3674" CreationDate="2016-06-25T06:53:20.210" Score="2" ViewCount="76" Body="&lt;p&gt;I'm struggling with this idea of creating two particles in 3d and draw a tube between them. I can't figure out how to properly set the angle of the tube. I've used two approaches:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;calculating the angle with the square root dot product divided by the length of the vectors.&lt;/li&gt;&#xA;&lt;li&gt;cartesian to polar function which calculates the y and z rotation values&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I'm obviously missing something (and I'm not that good in math). So what's my approach?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance! See below what I have so far.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YOwcg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YOwcg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4639" LastActivityDate="2016-06-25T23:33:50.490" Title="How can I draw a tube on basis of position and angle between two 3d points?" Tags="&lt;3d&gt;&lt;vectors&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3673" PostTypeId="2" ParentId="3671" CreationDate="2016-06-25T18:34:59.263" Score="1" Body="&lt;p&gt;1) Drawing a bunch of 3d cubes with simple textures? Yes, SceneKit can do that.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Way too broad a question... try &lt;a href=&quot;https://developer.apple.com/library/ios/documentation/SceneKit/Reference/SceneKit_Framework/&quot; rel=&quot;nofollow noreferrer&quot;&gt;reading the docs.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) Since this is a platform specific question try the &lt;strong&gt;scenekit&lt;/strong&gt; and &lt;strong&gt;scene-kit&lt;/strong&gt; tags on &lt;a href=&quot;https://stackoverflow.com/&quot;&gt;stackOverflow&lt;/a&gt; and &lt;a href=&quot;https://gamedev.stackexchange.com/&quot;&gt;Game Development&lt;/a&gt;, but see answer 2 first.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;good luck!&lt;/p&gt;&#xA;" OwnerUserId="4495" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-06-25T18:40:17.857" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3674" PostTypeId="2" ParentId="3672" CreationDate="2016-06-25T23:33:50.490" Score="1" Body="&lt;p&gt;The simplest solution is to use a lookat matrix. This is a matrix calculated from a &quot;eye&quot; point, a &quot;target&quot; point and an up vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The resulting matrix will then make the Z axis point from the eye to the target and the y axis in the general direction of up.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-06-25T23:33:50.490" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3675" PostTypeId="2" ParentId="3671" CreationDate="2016-06-25T23:36:23.003" Score="9" Body="&lt;h1&gt;What is missing?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Now that we can see images from your app, the difference that stands out most to me is the lack of shadows and &lt;a href=&quot;https://en.wikipedia.org/wiki/Ambient_occlusion&quot;&gt;ambient occlusion&lt;/a&gt;. This gives a very flat look as the colour of a surface does not vary according to its surroundings. This makes a big difference to how much an image appears to have depth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another effect which may be less important is that the surfaces are crystal clear all the way up to the horizon. Adding a mist/fog effect so that objects become gradually more obscured the further they are from the camera helps to give the impression of distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both these effects can be seen most obviously in the first example image in the question. The nearest building shows ambient occlusion on top of the stepped red roof, and also the grass is in partial shade near to the buildings and animals. The trees in the distance look more obviously far away due to the distance fog making them only partially visible.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Can SceneKit provide these?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I haven't used SceneKit myself, but a search online reveals that both ambient occlusion and distance fog effects are both possible using SceneKit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another effect not used in the example images, but that you might like to look into, is depth of field. The example images all have everything in focus at the same time, whereas photographs often have a focal distance at which everything is in clear focus, with anything nearer or farther being out of focus. It seems SceneKit can also handle this. Since your competitors don't appear to be using this, you could either view this as unimportant, or as a feature that could give you an advantage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd expect narrow depth of field to make a building app awkward, as parts of the object you are building would be out of focus. You may be interested in a wide depth of field that only creates a subtle blur for objects too distant to be part of what is currently being built, if that suits your purposes.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;As you guessed, asking for off site resources is off topic. However, you can ask further questions about computer graphics programming here on this site, if you run into any problems implementing these effects.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-06-25T23:41:30.230" LastActivityDate="2016-06-25T23:41:30.230" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3677" PostTypeId="1" CreationDate="2016-06-26T08:13:51.857" Score="0" ViewCount="233" Body="&lt;p&gt;I want to do keyframe interpolation in matlab.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I understand correctly, it uses splines to approximate the the motion of specific pixel points within the frames(through transforms). Correct me if I'm wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried looking but there are no toolboxes or any code for it. Where can I start?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will be working with video frames. At specific points (say after N frames, N~~100) the first frame encountered is labeled the keyframe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These frames are the equivalent to what animator artists draw and then animate by getting the computer to approximate frames in between.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm interpolating image frames. Literal image frame pixel values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine this, there are some pixel values I select, then I call those pixel values features and decide to track those pixel values against the frames. Those pixel values must have some sort of trajectory. I want to interpolate pixel values at various points of a trajectory such that the trajectory approximates a smooth motion between the pixel values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know the per pixel affine transform matrices between frames, the warps they perform on any single pixel in the image give rise to displacement in the pixel in a frame-time plot and end up being a trajectory. I smooth this thing somehow and have another set of matrices now describing the same thing but smoother.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Shqub.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Shqub.png&quot; alt=&quot;Image 1&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/noKVs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/noKVs.png&quot; alt=&quot;Image 2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/g4E46.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g4E46.png&quot; alt=&quot;Image 3&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4608" LastEditorUserId="231" LastEditDate="2016-07-09T13:25:03.277" LastActivityDate="2016-07-09T13:25:03.277" Title="How to do keyframe interpolation on matlab?" Tags="&lt;transformations&gt;&lt;interpolation&gt;&lt;animation&gt;&lt;matlab&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="3678" PostTypeId="1" AcceptedAnswerId="3679" CreationDate="2016-06-26T11:12:24.697" Score="3" ViewCount="238" Body="&lt;p&gt;I'm trying to figure this out for my Computer Graphics course, but I find it very hard to understand. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe the minimum number of angles obtained from clipping a convex polygon with n angles is 0, for example if the polygon is outside of the clipping rectangle, but I'm not sure if this makes sense.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the maximum number of angles, I believe it is 2n, as in if every angle tip gets outside of the rectangle. However, I'm not sure about this either.&lt;/p&gt;&#xA;" OwnerUserId="4646" LastActivityDate="2016-06-26T14:42:49.290" Title="Maximal and minimal no. of angles obtained from clipping a convex polygon with n angles" Tags="&lt;polygon&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3679" PostTypeId="2" ParentId="3678" CreationDate="2016-06-26T14:42:49.290" Score="3" Body="&lt;p&gt;&lt;em&gt;Since this is a homework question, I'll give hints rather than a numerical answer.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;Clipping a convex polygon&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Think about how many times the polygon can cross each edge of the rectangle. In general, a polygon can cross one of the edges of the rectangle an arbitrarily large number of times. How is this number reduced if the polygon is convex?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will give you the maximal number of new angles that can be added per rectangle edge, which should lead you to the answer.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Clipping a non-convex polygon&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;As for your guess of 2n, even for a non-convex polygon it may not be able to reach this high. If one vertex is outside the rectangle, then in order to create 2 new vertices both of its neighbouring vertices must be inside the rectangle. This means you cannot create 2n new vertices this way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The exception is when an edge of the polygon crosses 2 edges of the rectangle, for example at a corner of the rectangle. This allows creating two new vertices from a single edge. So for small enough n, it is possible to clip to a polygon with 2n vertices, but for larger n this is not possible.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-06-26T14:42:49.290" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3680" PostTypeId="2" ParentId="96" CreationDate="2016-06-26T15:07:15.097" Score="3" Body="&lt;p&gt;&lt;em&gt;This is a copy-paste of &lt;a href=&quot;https://stackoverflow.com/a/38039733/673852&quot;&gt;my answer&lt;/a&gt; to the same &lt;a href=&quot;https://stackoverflow.com/q/2508818/673852&quot;&gt;question at StackOverflow&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;At the bottom of this answer is an example of GLSL code which allows to output the full &lt;code&gt;float&lt;/code&gt; value as color, encoding IEEE 754 &lt;code&gt;binary32&lt;/code&gt;. I use it like follows (this snippet gives out &lt;code&gt;yy&lt;/code&gt; component of modelview matrix):&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;vec4 xAsColor=toColor(gl_ModelViewMatrix[1][1]);&#xA;if(bool(1)) // put 0 here to get lowest byte instead of three highest&#xA;    gl_FrontColor=vec4(xAsColor.rgb,1);&#xA;else&#xA;    gl_FrontColor=vec4(xAsColor.a,0,0,1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After you get this on screen, you can just take any color picker, format the color as HTML (appending &lt;code&gt;00&lt;/code&gt; to the &lt;code&gt;rgb&lt;/code&gt; value if you don't need higher precision, and doing a second pass to get the lower byte if you do), and you get the hexadecimal representation of the &lt;code&gt;float&lt;/code&gt; as IEEE 754 &lt;code&gt;binary32&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the actual implementation of &lt;code&gt;toColor()&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;const int emax=127;&#xA;// Input: x&amp;gt;=0&#xA;// Output: base 2 exponent of x if (x!=0 &amp;amp;&amp;amp; !isnan(x) &amp;amp;&amp;amp; !isinf(x))&#xA;//         -emax if x==0&#xA;//         emax+1 otherwise&#xA;int floorLog2(float x)&#xA;{&#xA;    if(x==0.) return -emax;&#xA;    // NOTE: there exist values of x, for which floor(log2(x)) will give wrong&#xA;    // (off by one) result as compared to the one calculated with infinite precision.&#xA;    // Thus we do it in a brute-force way.&#xA;    for(int e=emax;e&amp;gt;=1-emax;--e)&#xA;        if(x&amp;gt;=exp2(float(e))) return e;&#xA;    // If we are here, x must be infinity or NaN&#xA;    return emax+1;&#xA;}&#xA;&#xA;// Input: any x&#xA;// Output: IEEE 754 biased exponent with bias=emax&#xA;int biasedExp(float x) { return emax+floorLog2(abs(x)); }&#xA;&#xA;// Input: any x such that (!isnan(x) &amp;amp;&amp;amp; !isinf(x))&#xA;// Output: significand AKA mantissa of x if !isnan(x) &amp;amp;&amp;amp; !isinf(x)&#xA;//         undefined otherwise&#xA;float significand(float x)&#xA;{&#xA;    // converting int to float so that exp2(genType) gets correctly-typed value&#xA;    float expo=float(floorLog2(abs(x)));&#xA;    return abs(x)/exp2(expo);&#xA;}&#xA;&#xA;// Input: x\in[0,1)&#xA;//        N&amp;gt;=0&#xA;// Output: Nth byte as counted from the highest byte in the fraction&#xA;int part(float x,int N)&#xA;{&#xA;    // All comments about exactness here assume that underflow and overflow don't occur&#xA;    const float byteShift=256.;&#xA;    // Multiplication is exact since it's just an increase of exponent by 8&#xA;    for(int n=0;n&amp;lt;N;++n)&#xA;        x*=byteShift;&#xA;&#xA;    // Cut higher bits away.&#xA;    // $q \in [0,1) \cap \mathbb Q'.$&#xA;    float q=fract(x);&#xA;&#xA;    // Shift and cut lower bits away. Cutting lower bits prevents potentially unexpected&#xA;    // results of rounding by the GPU later in the pipeline when transforming to TrueColor&#xA;    // the resulting subpixel value.&#xA;    // $c \in [0,255] \cap \mathbb Z.$&#xA;    // Multiplication is exact since it's just and increase of exponent by 8&#xA;    float c=floor(byteShift*q);&#xA;    return int(c);&#xA;}&#xA;&#xA;// Input: any x acceptable to significand()&#xA;// Output: significand of x split to (8,8,8)-bit data vector&#xA;ivec3 significandAsIVec3(float x)&#xA;{&#xA;    ivec3 result;&#xA;    float sig=significand(x)/2.; // shift all bits to fractional part&#xA;    result.x=part(sig,0);&#xA;    result.y=part(sig,1);&#xA;    result.z=part(sig,2);&#xA;    return result;&#xA;}&#xA;&#xA;// Input: any x such that !isnan(x)&#xA;// Output: IEEE 754 defined binary32 number, packed as ivec4(byte3,byte2,byte1,byte0)&#xA;ivec4 packIEEE754binary32(float x)&#xA;{&#xA;    int e = biasedExp(x);&#xA;    // sign to bit 7&#xA;    int s = x&amp;lt;0. ? 128 : 0;&#xA;&#xA;    ivec4 binary32;&#xA;    binary32.yzw=significandAsIVec3(x);&#xA;    // clear the implicit integer bit of significand&#xA;    if(binary32.y&amp;gt;=128) binary32.y-=128;&#xA;    // put lowest bit of exponent into its position, replacing just cleared integer bit&#xA;    binary32.y+=128*int(mod(float(e),2.));&#xA;    // prepare high bits of exponent for fitting into their positions&#xA;    e/=2;&#xA;    // pack highest byte&#xA;    binary32.x=e+s;&#xA;&#xA;    return binary32;&#xA;}&#xA;&#xA;vec4 toColor(float x)&#xA;{&#xA;    ivec4 binary32=packIEEE754binary32(x);&#xA;    // Transform color components to [0,1] range.&#xA;    // Division is inexact, but works reliably for all integers from 0 to 255 if&#xA;    // the transformation to TrueColor by GPU uses rounding to nearest or upwards.&#xA;    // The result will be multiplied by 255 back when transformed&#xA;    // to TrueColor subpixel value by OpenGL.&#xA;    return vec4(binary32)/255.;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4647" LastEditorUserId="4647" LastEditDate="2018-04-11T19:25:35.810" LastActivityDate="2018-04-11T19:25:35.810" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3681" PostTypeId="1" AcceptedAnswerId="3682" CreationDate="2016-06-26T18:53:56.907" Score="3" ViewCount="166" Body="&lt;p&gt;My goal is to take a point that is inside of a circle with a given radius and put it on the circumference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recently I have been normalizing the vector between the point and the center of the circle then multiplying that by the radius.  However I need (if possible) a less computationally expensive method because the distance formula is expensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another thought I had was to use &quot;atan2&quot; to get the angle between the two points and then use sine and cosine multiplied by the radius to get the point on the circumference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which method do you think would be faster for the computer to process? Can you think of a faster method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Details about the simulation&lt;/strong&gt;&#xA;This is an ios application written in swift.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically there are a bunch of particles moving around randomly. And the user is putting down fingers. Each finger is a circle with a radius that grows as time goes on. The part that is inneficent is that if the dot is ever inside of any of the circles (attached to touchscreen touches) that it goes on the circumference of the circle.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2016-06-26T21:09:47.170" LastActivityDate="2016-06-26T22:53:24.400" Title="Fastest way to put a point on the circumference of a circle" Tags="&lt;mathematics&gt;" AnswerCount="1" CommentCount="14" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3682" PostTypeId="2" ParentId="3681" CreationDate="2016-06-26T22:53:24.400" Score="2" Body="&lt;p&gt;Before focusing on optimising the individual process of moving a point, consider how many points are being processed this way. This is likely to give a much more significant speed up if it hasn't yet been addressed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if every point on the screen is being tested against every circle, then most of the points are being checked needlessly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If instead you divide the screen into a grid, with each grid cell keeping a list of all points currently within it, then each circle only needs to be checked against the points that appear in the grid cells which that circle overlaps. This allows checking a few tens of points, instead of hundreds or thousands.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a much bigger speed up than you can hope to achieve by optimising the circumference calculation, and after this you may find that further optimisation is not needed.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-06-26T22:53:24.400" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3683" PostTypeId="1" AcceptedAnswerId="3685" CreationDate="2016-06-27T00:22:45.793" Score="1" ViewCount="179" Body="&lt;p&gt;I am trying to programmatically figure out how many &quot;texture2d &quot; calls the gpu can make before the fps drops below 60fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My current way of doing this is to have a fragment shader with a for loop that will run a specified number of times based on a passed in uniform. So each frame the for loop will run more times, each time sampling the texture more times.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then on the cpu I can monitor the fps and see when it drops.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is if this shader runs on more then one pixel then the test is worth nothing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I ensure from the cpu code and vertex shader that the fragment program only runs once?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-06-27T14:06:45.213" Title="How to ensure a fragment shader only runs once" Tags="&lt;gpu&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3684" PostTypeId="1" AcceptedAnswerId="3696" CreationDate="2016-06-27T12:43:05.767" Score="4" ViewCount="681" Body="&lt;p&gt;I'm implementing a simple Lamberitan BRDF in GLSL, using a point light source. My fragment shader simply returns &lt;code&gt;light_colour * 1.0/PI * cosine&lt;/code&gt;, which should model a fully diffuse white material. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, it looks rather dark... If I have a point light with colour (1,1,1), and no attenuation with distance, the maximum brightness of the material (at normal incidence) will be 1/3 (dark grey). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this just because I am using a physically incorrect point light with zero size? Is there any &quot;correct&quot; value for the light colour in this case, if I want the surface to be white at its brightest parts?&lt;/p&gt;&#xA;" OwnerUserId="4650" LastActivityDate="2016-06-27T21:20:34.373" Title="How to correctly implement Lambertian BRDF with point light" Tags="&lt;brdf&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3685" PostTypeId="2" ParentId="3683" CreationDate="2016-06-27T14:06:45.213" Score="6" Body="&lt;p&gt;I don't think your approach is viable for a variety of reasons.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;a GPU is heavily cache-dependent for performance. Pulling the same pixels over and over will just measure how fast a cache hit is. Sampling random pixels will only measure a cache miss. Neither are useful statistics. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;each texture2d call will pull in multiple pixels to leverage that, in a fragment shader, neighbouring fragments will want neighbouring pixels.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The driver could optimize your shader to pull out the loop if it sees that each iteration does the exact same computation or if the computed result is not used.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-06-27T14:06:45.213" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3686" PostTypeId="1" AcceptedAnswerId="3693" CreationDate="2016-06-27T14:23:47.803" Score="4" ViewCount="56" Body="&lt;p&gt;I´m new to the Processing language. Trying to do my first sketch I´m having trouble with the dimension of the display window width and height because even though I´ve tried putting a variety of values in the size() function, the size of the window doesn´t change at any time, it always has the same size (100px x 100px). The function fullScreen() has the same results. How could I resolve this problem?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It´s a simple visualization of a &quot;star field&quot;. First block, class Star, simply create a star and fill it with a color. Second block is where I´m trying to adjust the size of the display window but it doesn´t work.&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre class=&quot;lang-processing prettyprint-override&quot;&gt;&lt;code&gt;class Star {&#xA;  float x;&#xA;  float y;&#xA;  float z;&#xA;&#xA;  Star(){&#xA;    // Places the star in random X and Y coordinates&#xA;    x = random(0, width);&#xA;    y = random(0, height);&#xA;  }&#xA;&#xA;  /* Colors the star */&#xA;  void update(){&#xA;    fill(255);&#xA;    noStroke();&#xA;    ellipse(x, y, 8, 8);&#xA;  }&#xA;&#xA;  void show(){}&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;pre class=&quot;lang-processing prettyprint-override&quot;&gt;&lt;code&gt;// Array that contains all the amount of stars created (100 in this case)&#xA;Star[] stars = new Star[100];&#xA;&#xA;void Setup(){&#xA;  size(800, 800); // TROUBLE HERE. DOESN´T WORK&#xA;  for(int i = 0; i &amp;lt; stars.length; i++){&#xA;    stars[i] = new Star();&#xA;  }&#xA;}&#xA;&#xA;void Draw(){&#xA;  background(0); // Colors the background&#xA;  for(int i = 0; i &amp;lt; stars.length; i++){&#xA;    stars[i].update();&#xA;    stars[i].show();&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4653" LastEditorUserId="231" LastEditDate="2016-06-27T19:59:29.390" LastActivityDate="2016-06-27T20:59:48.117" Title="Issue with size() function in Processing language?" Tags="&lt;processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3687" PostTypeId="2" ParentId="2009" CreationDate="2016-06-27T14:43:51.540" Score="4" Body="&lt;p&gt;What you probably need is this 4 x 4 matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathtt{T} = \begin{bmatrix}1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\  \end{bmatrix}$$&#xA;which is flipping the z-axis. The inverse of this particular matrix is the matrix itself:&#xA;$\mathtt{T}^{-1} = \mathtt{T}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For 3D points $\mathbf{x}$ multiply it from the left:&#xA;$$\mathbf{x}' = \mathtt{T}\,\, \mathbf{x}$$&#xA;and for 3D transformations multiply it from the right:&#xA;$$\mathtt{P}' = \mathtt{P} \,\,\mathtt{T}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, you have not changed anything in the projection because:&#xA;$$\mathtt{P}'\,\,\mathbf{x}' = \mathtt{P} \,\,\mathtt{T} \, \,\mathtt{T}\,\,  \mathbf{x} =  \mathtt{P} \,\,(\mathtt{T}^{-1} \, \,\mathtt{T})\,\,  \mathbf{x} = \mathtt{P}\,\,\mathbf{x}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quaternions $q=(s,x,y,z)^\top$ could be convert into &#xA;a 3D transformation matrix with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathtt{P} = \begin{bmatrix} 1-2y^2-2z^2 &amp;amp; 2xy-2sz&amp;amp; 2xz+2ys &amp;amp; 0\\ &#xA;              2xy+2sz &amp;amp; 1-2x^2-2z^2&amp;amp; 2yz-2sx &amp;amp; 0\\ &#xA;              2xz-2sy &amp;amp; 2yz+2sx&amp;amp; 1-2x^2-2y^2 &amp;amp; 0\\  0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix}$$&#xA;and could then be treated like other 3D transformations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, 3D engines typically apply transformation in a transformation hierarchy. If this is the case, make sure you are only modifying the 3D transformation &quot;closest&quot; to the 3D point in the hierarchy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sources:&#xA;&lt;a href=&quot;http://www.mathematik.uni-marburg.de/~thormae/lectures/graphics1/graphics_5_2_eng_web.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Graphics Programming I - 3D Transformations | Thorsten Thormählen&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4652" LastEditorDisplayName="user7220" LastEditDate="2018-03-07T02:58:00.457" LastActivityDate="2018-03-07T02:58:00.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3688" PostTypeId="1" AcceptedAnswerId="3694" CreationDate="2016-06-27T15:05:43.860" Score="6" ViewCount="1072" Body="&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&#xA;I'm trying to draw a scene with a lot (about 10000) of similar objects (in my case bushes, but could be anything). For each bush I have three meshes with a different number of triangles and I want to use one of these meshes depending on the distance to the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;First approach:&lt;/strong&gt;&#xA;I can select the correct mesh on the CPU, update the model matrix after every bush and then draw the VBO with the correct mesh. The problem is that I need to update the model matrix 10000 times per frame ... you can guess what this means performance wise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Second Approach:&lt;/strong&gt;&#xA;Again select the correct mesh on the CPU, but this time use instanced rendering to draw all bushes with lowest lod in one draw call, then the bushes with middle lod and then the bushes with high lod. I have stored the bush positions already on the GPU. But my problem here is that I still need to send an array as uniform variable which contains the information which mesh has to be drawn at which position. With this approach i run into the limit of uniform variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt;&#xA;What I would like to do is to calculate the distance from the bush to the camera on the GPU (no problem for example in the vertex shader). And then draw only the VBO with the correct level of detail depending on the outcome. Therefore my question is if there is any possibility to select which VBO to draw on the GPU (I don't see any possibility to do this, since in the Vertex and Fragment shader I am a already to far down the pipeline)? Or do you have another idea that I could try?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best, Albert&lt;/p&gt;&#xA;" OwnerUserId="4654" LastActivityDate="2016-06-27T19:28:07.637" Title="OpenGL Instanced Rendering with Level of Detail" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3689" PostTypeId="2" ParentId="3621" CreationDate="2016-06-27T17:27:03.067" Score="2" Body="&lt;p&gt;I think the assumption (perhaps stated perhaps not, I dont' have the text handy) is that the radiance is emitted in a cosine-lobe distribution. This means that there's falloff in proportion to the cosine of the angle between the emitter's normal, and the direction of emission.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look in the &lt;a href=&quot;https://people.cs.kuleuven.be/~philip.dutre/GI/TotalCompendium.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;global illumination compendium&lt;/a&gt;, under Hemispherical Geometry, equation set (30), you'll see that the integral over the hemisphere, modulated by a cosine lobe, is exactly pi. &lt;/p&gt;&#xA;" OwnerUserId="3386" LastEditorUserId="2941" LastEditDate="2016-11-15T21:39:12.463" LastActivityDate="2016-11-15T21:39:12.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3690" PostTypeId="5" CreationDate="2016-06-27T18:30:48.547" Score="0" Body="" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-06-27T18:30:48.547" LastActivityDate="2016-06-27T18:30:48.547" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3691" PostTypeId="4" CreationDate="2016-06-27T18:30:48.547" Score="0" Body="Processing is an open source programming language and integrated development environment (IDE) built with the purpose of teaching the fundamentals of computer programming in a visual context." OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-06-27T18:30:48.547" LastActivityDate="2016-06-27T18:30:48.547" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3692" PostTypeId="2" ParentId="3621" CreationDate="2016-06-27T19:13:31.157" Score="4" Body="&lt;p&gt;Radiance (in terms of flux) has the following definition:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_o = \frac{\mathrm{d}\Phi}{\mathrm{d}\omega^\perp\mathrm{d}A}&#xA;= \frac{\mathrm{d}\Phi}{\cos{\theta} \mathrm{d}\omega \mathrm{d}A}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus in order to get the total emitted power we need to integrate over the area of the light and we need to integrate over the projected solid angle of the hemisphere (in the direction of the surface normal). The radiance for the area lights in pbrt is constant. This gives us:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\Phi = \int_A \int_{H^2(\mathbf{n})} L_o\mathrm{d}\omega^\perp \mathrm{d}A =&#xA;\int_A \int_{H^2(\mathbf{n})} L_o \cos\theta \mathrm{d}\omega \mathrm{d}A =&#xA;\int_A L_o \int_0^{2\pi} \int_0^{\pi/2} \sin\theta \cos\theta \mathrm{d}\theta \mathrm{d}\phi \mathrm{d}A =&#xA;\int_A L_o \pi \mathrm{d}A =&#xA;A \cdot L_o \cdot \pi$&lt;/p&gt;&#xA;" OwnerUserId="4655" LastActivityDate="2016-06-27T19:13:31.157" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3693" PostTypeId="2" ParentId="3686" CreationDate="2016-06-27T19:20:33.517" Score="1" Body="&lt;p&gt;The window is &lt;code&gt;100px, 100px&lt;/code&gt; because it is the default size and you are not changing it, as your&#xA;&lt;code&gt;size()&lt;/code&gt; is never being called because &lt;code&gt;Setup()&lt;/code&gt; is not a predefined function. &#xA;&lt;code&gt;setup()&lt;/code&gt; is the function, lower case &lt;code&gt;s&lt;/code&gt; not upper case &lt;code&gt;S&lt;/code&gt;. Same with &lt;code&gt;draw()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the working code.&#xA;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-processing prettyprint-override&quot;&gt;&lt;code&gt;class Star {&#xA;  float x;&#xA;  float y;&#xA;  float z;&#xA;&#xA;  Star(){&#xA;    // Places the star in random X and Y coordinates&#xA;    x = random(0, width);&#xA;    y = random(0, height);&#xA;  }&#xA;&#xA;  /* Colors the star */&#xA;  void update(){&#xA;    fill(255);&#xA;    noStroke();&#xA;    ellipse(x, y, 8, 8);&#xA;  }&#xA;&#xA;  void show(){}&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;pre class=&quot;lang-processing prettyprint-override&quot;&gt;&lt;code&gt;// Array that contains all the amount of stars created (100 in this case)&#xA;Star[] stars = new Star[100];&#xA;&#xA;void setup(){&#xA;  size(800, 800); // TROUBLE HERE. DOESN´T WORK&#xA;  for(int i = 0; i &amp;lt; stars.length; i++){&#xA;    stars[i] = new Star();&#xA;  }&#xA;}&#xA;&#xA;void draw(){&#xA;  background(0); // Colors the background&#xA;  for(int i = 0; i &amp;lt; stars.length; i++){&#xA;    stars[i].update();&#xA;    stars[i].show();&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3437" LastEditorUserId="231" LastEditDate="2016-06-27T20:59:48.117" LastActivityDate="2016-06-27T20:59:48.117" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3694" PostTypeId="2" ParentId="3688" CreationDate="2016-06-27T19:28:07.637" Score="2" Body="&lt;p&gt;IMO, a variation of your second approach is going to be the simplest, and could be quite fast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have you profiled anything yet? A CPU should chew through 10000 matrix multiplications extremely quickly. If you wanted to get even more performance, you could SIMD / thread the update. That said, the slowest part is probably going to be the bandwidth of sending 10000 matrices over the PCIE bus. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, again, this is all supposition. Try it out, and profile.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was thinking something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I apologize for the DX functions. I'm not super familiar with the corresponding OpenGL functions. That said, OpenGL &lt;em&gt;should&lt;/em&gt; be quite similar)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Variable definitions&#xA;&#xA;vector&amp;lt;matrix&amp;gt; lod0;&#xA;vector&amp;lt;matrix&amp;gt; lod1;&#xA;vector&amp;lt;matrix&amp;gt; lod2;&#xA;&#xA;ID3D11Buffer lod0VertexBuffer;&#xA;uint lod0VertexCount;&#xA;&#xA;ID3D11Buffer lod1VertexBuffer;&#xA;uint lod1VertexCount;&#xA;&#xA;ID3D11Buffer lod2VertexBuffer;&#xA;uint lod2VertexCount;&#xA;&#xA;ID3D11Buffer instanceBuffer;&#xA;&#xA;/// ..................&#xA;&#xA;&#xA;/// Per frame...&#xA;lod0.clear();&#xA;lod1.clear();&#xA;lod2.clear();&#xA;&#xA;for (uint i = 0; i &amp;lt; bushes.size(); ++i) {&#xA;    float distance = distance(bushes[i].pos, camera.origin);&#xA;    if (distance &amp;lt; 50.0f) {&#xA;        lod0.push_back(bushes[i].matrix);&#xA;    } else if (distance &amp;lt; 100.0f) {&#xA;        lod1.push_back(bushes[i].matrix);&#xA;    } else {&#xA;        lod2.push_back(bushes[i].matrix);&#xA;    }&#xA;}&#xA;&#xA;D3D11_MAPPED_SUBRESOURCE mappedResource;&#xA;ID3D11Buffer vertexBuffers[] = {&#xA;    lod0VertexBuffer,&#xA;    instanceBuffer&#xA;};&#xA;&#xA;// Update lod0 matrices&#xA;context-&amp;gt;Map(instanceBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &amp;amp;mappedResource);&#xA;memcpy(mappedResource.pData, &amp;amp;lod0[0], sizeof(matrix) * lod0.size());&#xA;context-&amp;gt;Unmap(instanceBuffer, 0);&#xA;&#xA;// Draw lod0&#xA;context-&amp;gt;IASetVertexBuffers(0, 2, vertexBuffers, nullptr, nullptr);&#xA;context-&amp;gt;DrawInstanced(lod0VertexCount, lod0.size(), 0, 0);&#xA;&#xA;&#xA;// Update lod1 matrices&#xA;context-&amp;gt;Map(instanceBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &amp;amp;mappedResource);&#xA;memcpy(mappedResource.pData, &amp;amp;lod1[0], sizeof(matrix) * lod1.size());&#xA;context-&amp;gt;Unmap(instanceBuffer, 0);&#xA;&#xA;// Draw lod1&#xA;vertexBuffers[0] = lod1VertexBuffer;&#xA;context-&amp;gt;IASetVertexBuffers(0, 2, vertexBuffers, nullptr, nullptr);&#xA;context-&amp;gt;DrawInstanced(lod1VertexCount, lod1.size(), 0, 0);&#xA;&#xA;&#xA;// Update lod2 matrices&#xA;context-&amp;gt;Map(instanceBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &amp;amp;mappedResource);&#xA;memcpy(mappedResource.pData, &amp;amp;lod2[0], sizeof(matrix) * lod1.size());&#xA;context-&amp;gt;Unmap(instanceBuffer, 0);&#xA;&#xA;// Draw lod2&#xA;vertexBuffers[0] = lod2VertexBuffer;&#xA;context-&amp;gt;IASetVertexBuffers(0, 2, vertexBuffers, nullptr, nullptr);&#xA;context-&amp;gt;DrawInstanced(lod1VertexCount, lod2.size(), 0, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If this ends up being too slow, you could try to do this calculation in a compute shader, then draw the result using an indirect draw call. See &lt;a href=&quot;http://www.gdcvault.com/play/1020791/Approaching-Zero-Driver-Overhead-in&quot; rel=&quot;nofollow&quot;&gt;AZDO&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2016-06-27T19:28:07.637" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3696" PostTypeId="2" ParentId="3684" CreationDate="2016-06-27T21:20:34.373" Score="2" Body="&lt;p&gt;It doesn’t matter that it’s a point light; the 1/π normalization factor is what’s causing your surface to be 1/π as bright as you’d like it to be. You can either up your light intensity so the maximum brightness is π or just get rid of the normalization factor. There’s a good article with some notes about this and how it interacts with more complex lighting techniques &lt;a href=&quot;https://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2016-06-27T21:20:34.373" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3697" PostTypeId="1" CreationDate="2016-06-27T21:34:46.570" Score="8" ViewCount="2077" Body="&lt;p&gt;I need to find the center of a Bezier curve to rotate it. I have a list of all points (control points, beginning and end, all points on the curve itself). How would I go about finding it's center?&lt;/p&gt;&#xA;" OwnerUserId="4656" LastActivityDate="2017-12-22T01:38:11.077" Title="Algorithm to find the center of a Bezier curve" Tags="&lt;algorithm&gt;&lt;bezier-curve&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3698" PostTypeId="2" ParentId="3622" CreationDate="2016-06-28T03:39:55.790" Score="2" Body="&lt;p&gt;You want to look up &quot;Intel Graphics Developer Guides&quot;, they are quite thorough.  Here's a link to the latest:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://software.intel.com/sites/default/files/managed/22/6d/6th_gen_graphics_api_dev_guide_dec_2015.pdf&quot; rel=&quot;nofollow&quot;&gt;https://software.intel.com/sites/default/files/managed/22/6d/6th_gen_graphics_api_dev_guide_dec_2015.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here's the architectural Cliff Notes for the past five generations of Intel GPUs:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;In several important respects, the 6th gen Intel Core processors' graphics hardware architecture is similar to that of 5th generation Intel® CoreTM processors&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;The graphics hardware architecture of the 5th gen Intel Core processors is similar to that of the 4th gen processors.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;The graphics hardware architecture in the 4th gen Intel Core processor is similar to that in the 3rd gen processor.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;The new generation of microarchitecture, codenamed Ivy Bridge, provides another jump in functionality and performance over Sandy Bridge microarchitecture.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;With the introduction of the Intel microarchitecture codenamed Sandy Bridge, the graphics processor has moved onto the same die as the CPU, and is now referred to as “processor graphics”. In addition, processor graphics has enjoyed numerous architectural improvements that yield significant performance improvements over previous generations of Intel® integrated graphics parts.&quot;&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastEditorDisplayName="user3412" LastEditDate="2016-06-29T05:56:39.997" LastActivityDate="2016-06-29T05:56:39.997" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3699" PostTypeId="2" ParentId="3697" CreationDate="2016-06-28T12:27:57.410" Score="14" Body="&lt;p&gt;Bézier curves are mathematical entities and have no clearly defined center. One can in fact define many different things as the center of the Bézier curve. I have tried to depict some of the possible centers in image 1. More than this do exist.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/N7tQj.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N7tQj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Some of the possible centers of a single span Bézier curve&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice nearly all graphics applications geared for drawing use the center of the local bounding box (BB) as their center. Animation software usually have an additional concept of pivot so they use the ask user approach, if no input is made they often revert to BB center or simply local coordinate center. This is probably because the BB needs to be calculated anyway and getting its center is pretty easy to do (see &lt;a href=&quot;http://pomax.github.io/bezierinfo/#boundingbox&quot; rel=&quot;noreferrer&quot;&gt;A Primer on Bézier Curves&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The center of gravity metrics are also somewhat natural especially in an animation context, though nastier to compute. Easiest being to discretize the data and do the computation on the discrete input. This said some closed form solutions are possible for the curve center of gravity, but it's not a very nice equation to formulate and simplify.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have the on the curve points: the midpoint by arc length and the point where the $t$ parameter is 0.5. In my mind the $t$ param is often problematic though easy to compute, and it loses meaning when you chain multiple Béziers after each other for a polybézier. The center of length of course is only natural as long as the curve is not closed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We also define other possible centers, the center could be at the curve center of gravity of the hull, the average of the control points or the control cage BB center. Although in practice these do not seem to work out very well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Please note&lt;/strong&gt;: Although the curve in picture 1 shows the BB center quite near to some natural centers this this is not always the case for more complex curves and especially polybéziers.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-06-28T14:15:23.593" LastActivityDate="2016-06-28T14:15:23.593" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3700" PostTypeId="1" AcceptedAnswerId="3702" CreationDate="2016-06-28T19:09:42.353" Score="11" ViewCount="35144" Body="&lt;p&gt;So I was reading &lt;a href=&quot;https://softwareengineering.stackexchange.com/questions/60544/why-do-game-developers-prefer-windows&quot;&gt;this&lt;/a&gt;, I sort of got the reason why there are a lot more games on Microsoft windows than on any other OS. The main issue presented was that Direct3D is preferred over OpenGL. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I don't understand is why would any developer sacrifice compatibility? That is simply a financial loss to the company. I understand that OpenGL is kind of a mess, but that should hardly be a issue for experts. Even if it is, I think that people would go a extra mile than to incur a financial loss. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also if I'm not wrong then many cross platform applications use both Direct3D and OpenGL. I think they switch between the APIs.     &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is weird as they can just use OpenGL, why even care about Direct3D? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is, are there any technical issues with OpenGL or is there any support that Direct3D provides that OpenGL lacks?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I am aware that this question might be closed as being off-topic or too broad, I tried my best to narrow it down.    &lt;/p&gt;&#xA;" OwnerUserId="3437" LastEditorUserId="6546" LastEditDate="2017-05-02T00:52:55.220" LastActivityDate="2018-04-08T18:33:21.340" Title="Is there any reason to prefer Direct3D over OpenGL?" Tags="&lt;opengl&gt;&lt;direct3d&gt;" AnswerCount="2" CommentCount="9" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3701" PostTypeId="2" ParentId="3700" CreationDate="2016-06-29T11:01:51.503" Score="1" Body="&lt;p&gt;A couple of possible reasons:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Historically, OpenGL driver quality has varied a lot, but I'm not sure that's the case any more.&lt;/li&gt;&#xA;&lt;li&gt;Xbox supports D3D so porting a game between it and PC is easier.&lt;/li&gt;&#xA;&lt;li&gt;Debugging tools for D3D have been better than for OpenGL. Luckily we now have &lt;a href=&quot;https://renderdoc.org&quot; rel=&quot;nofollow&quot;&gt;RenderDoc&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="67" LastActivityDate="2016-06-29T11:01:51.503" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3702" PostTypeId="2" ParentId="3700" CreationDate="2016-06-29T15:17:03.670" Score="9" Body="&lt;p&gt;About the fact that there are more games for Windows, some reasons are&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Windows has the majority of the market and in the past to develop cross platform games was more complicated than it is today.&lt;/li&gt;&#xA;&lt;li&gt;DirectX comes with way better tools for developing (e.g. debugging)&lt;/li&gt;&#xA;&lt;li&gt;Big innovations are generally first created/implemented in DirectX, and then ported to/implemented in OpenGL. &lt;/li&gt;&#xA;&lt;li&gt;As for Windows vs Linux, you have to consider that when there is an actual standard due to marketing and historical reasons (for that see &lt;a href=&quot;https://softwareengineering.stackexchange.com/questions/60544/why-do-game-developers-prefer-windows&quot;&gt;Why do game developers prefer Windows? | Software Engineering&lt;/a&gt;, as I said in the comments), it has its inertia.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The inertia thing is very important. If your team develop for DirectX, targeting 90% of the market (well... if you play games on pc you probaly have windows, so... 99% of the market?), why would you want to invest in OpenGL? If you already develop in OpenGL, again targeting 99% of the market, you will stick to it as long as you can. For exampe Id Tech by Id Software is an excellent game engine (powering the DOOM series) that uses OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;About the topic of your discussion, a comment.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As of today, there are many many APIs, and a common practice is to use a Game Engine that abstracts over them. For example, consider that&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;On most mobile platform you have to use OpenGl ES.&lt;/li&gt;&#xA;&lt;li&gt;On PC you can use both DirectX and OpenGL&lt;/li&gt;&#xA;&lt;li&gt;I think on XBOX you have to use DirectX.&lt;/li&gt;&#xA;&lt;li&gt;I think that on PS you use their own API. &lt;/li&gt;&#xA;&lt;li&gt;With old hardware you use DirectX9 or OpenGL 3, or OpenGL ES 2.&lt;/li&gt;&#xA;&lt;li&gt;With more recent hardware you can (and want to) use DirectX 11, OpenGL 4, OpenGL ES 3.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Recently, with the advent of the new low overhead APIs - whch is a major turning point for graphical programming - there are DirectX 12 for Windows and XBOX, Metal for iOS and Vulkan (the new OpenGL) for Windows and Linux (including Android and Tizen).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There still are games that only target Windows and XBOX, but IMHO today that can only be marketing choice.&lt;/p&gt;&#xA;" OwnerUserId="4665" LastEditorDisplayName="user7220" LastEditDate="2018-04-08T18:33:21.340" LastActivityDate="2018-04-08T18:33:21.340" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3704" PostTypeId="1" CreationDate="2016-06-29T23:38:17.307" Score="5" ViewCount="2014" Body="&lt;p&gt;Shading and shadowing are often mentioned in how to create realistic 3D graphics, but the distinction is not clear. Are both responsible for the generation of shadows, or do they refer to the same concept?&lt;/p&gt;&#xA;" OwnerUserId="4638" LastEditorUserId="3437" LastEditDate="2016-07-01T14:54:45.730" LastActivityDate="2016-07-09T05:52:30.027" Title="What is the difference between shading and shadowing?" Tags="&lt;lighting&gt;&lt;shadow&gt;&lt;shading&gt;&lt;ambient-occlusion&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3705" PostTypeId="2" ParentId="3704" CreationDate="2016-06-30T06:16:23.510" Score="5" Body="&lt;p&gt;In simplified terms, shading controls how object's surface's brightness changes when the angle between its normal and light vector changes. Shadows are areas where the light cannot reach because it's occluded by other objects. So no, they both are not responsible for creating shadows.&lt;/p&gt;&#xA;" OwnerUserId="67" LastActivityDate="2016-06-30T06:16:23.510" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3706" PostTypeId="1" AcceptedAnswerId="3718" CreationDate="2016-06-30T07:13:18.660" Score="9" ViewCount="642" Body="&lt;p&gt;I have a simple game and and subjects of it are these little lines. It is targeted for iOS and android so it has a HUGE range of processors that it could run on, right now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6CojT.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6CojT.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to add realtime glow to them for two reasons&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I am trying to hide the fact that I don't have the rendering time to process anti-aliasing on most devices.&lt;/li&gt;&#xA;&lt;li&gt;The subject of the game is supposed to be pure light, ergo that picture should look like those things are pure light.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I have been tweaking a separable gaussian blur shader for quite awhile and I have came up to a point of frustration, I just can't get it to look right, perhaps the issue is I am trying to futilely hide the jagged edges of the light meanwhile not making the light look blurry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My biggest problem is all the variables involved in making it look its best.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am very new to graphics/rendering and I am in no way an artist. Perhaps the most frustrating thing about rending to me is all the variables that seem to be involved. With glow I have seen so many possible changes.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A. Add blend mode, screen blend mode, or some other concoction  &lt;/li&gt;&#xA;&lt;li&gt;B.Weighting the blur, and normal differently before combination &lt;/li&gt;&#xA;&lt;li&gt;C. The&#xA;Sigma of the gaussian bell function (I have been using &lt;a href=&quot;http://dev.theomader.com/gaussian-kernel-calculator/&quot; rel=&quot;noreferrer&quot;&gt;this&lt;/a&gt;&#xA;confusing calculator but it doesn't seem to give the same values I&#xA;see other people have in) &lt;/li&gt;&#xA;&lt;li&gt;D. Scalars on the &quot;x&quot; values sent to the&#xA;sigma function &lt;/li&gt;&#xA;&lt;li&gt;E. Sample scale (making the blur radius smaller or&#xA;larger) &lt;/li&gt;&#xA;&lt;li&gt;F. Changing the resolution of the glow buffer&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;How does one find the &quot;best looking&quot; constants when working with so many variables like this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am also having issues because the time between me making a tweak and seeing it is a long that its hard to see changes, I would do it in shader toy however I can't load up this image or procedurally generate one like it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now I am really stuck on the sigma of the gaussian bell curve kernel, especially because I am coding in the numbers rather then the formula because I need the processor speed. &lt;a href=&quot;http://dev.theomader.com/gaussian-kernel-calculator/&quot; rel=&quot;noreferrer&quot;&gt;Can you suggest a good sigma to use&lt;/a&gt;?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="16" LastEditDate="2016-06-30T07:31:06.367" LastActivityDate="2016-07-04T00:34:46.920" Title="Tweaking a glow shader to make it look better" Tags="&lt;lighting&gt;&lt;pixel-shader&gt;&lt;blur&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3707" PostTypeId="1" AcceptedAnswerId="3715" CreationDate="2016-06-30T07:28:55.903" Score="9" ViewCount="257" Body="&lt;p&gt;I am trying to make a glow shader using separable gaussian blurring.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have recently been inspired by the short youtube video &lt;a href=&quot;https://www.youtube.com/watch?v=LKnqECcg6Gw&quot;&gt;&quot;computer color is broken&quot;&lt;/a&gt; and I have &lt;a href=&quot;https://www.shadertoy.com/view/MsGSR3&quot;&gt;messed with it with color interpolation&lt;/a&gt; and boy his suggestion is beautiful!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A big thing the video talks about is that this principal should be applied to blurring, however I am pretty confused.  I don't really know what to square when and what to sqrt when when values are being added. My current theory is each texture sample for the gaussian blur gets raised by the power of two weighted with a bell curve and added to a sum like usual. At the end the sum is square rooted, but i'm not sure if that is correct. Could someone please confirm? Would this make an appreciable difference that made things worth it?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="48" LastEditDate="2016-11-12T22:44:53.377" LastActivityDate="2016-11-12T22:44:53.377" Title="Applying correct light physics to gaussian blur formulas for glow" Tags="&lt;color-science&gt;&lt;blur&gt;&lt;gamma&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3709" PostTypeId="1" AcceptedAnswerId="3711" CreationDate="2016-07-01T15:29:33.447" Score="6" ViewCount="121" Body="&lt;p&gt;I have two circles, that I know are both tangential to a third (unknown) circle. I also know what quadrants of the circles the tangential points are in. It is as pictured below. I also know the arc angle that the third circle spans between the two tangential points (beta).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to know the location of the two tangential points, as well as one of the tangential directions, so I can draw the unknown (red) circle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I currently have a working solution for this involving a nonlinear equation solver. If at all possible I would like to have a solution that involves no non-linear equation solving, because I need to run very many of these problems and I need precise results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/anI6om.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/anI6om.png&quot; alt=&quot;Arrangement of the circles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4620" LastEditorUserId="4620" LastEditDate="2016-07-03T18:02:00.380" LastActivityDate="2016-07-03T18:02:00.380" Title="Closed form solution to a problem of tangent circles" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3710" PostTypeId="2" ParentId="3660" CreationDate="2016-07-01T21:08:00.613" Score="6" Body="&lt;p&gt;I have implemented the cartesian-to-polar-conversion and have used different interpolation methods:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) nearest neighbor&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) a subsampling approach, which averages 81 subpixel locations&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) bilinear interpolation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 2nd row in the image below shows detail magnifications of the output for the three approaches:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3o1vV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3o1vV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the GLSL shader code for approach 1 and 3:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;varying vec2 tc; // texture coordinate of current output pixel&#xA;uniform sampler2D inputImg; // input image&#xA;const float PI = 3.141592653589793238462643383;&#xA;void main() {&#xA;  float phi = tc.x; // phi is x-direction in output&#xA;  float r = tc.y;   // radius is y-direction in output&#xA;  float xx = r * cos(2.0 * PI * phi);  // unit circle in range [-1.0, 1.0]&#xA;  float yy = r * sin(2.0 * PI * phi);&#xA;  float x = xx * 0.5 + 0.5; // input texture coordinate in range [0.0, 1.0];&#xA;  float y = yy * 0.5 + 0.5;&#xA;  gl_FragColor = texture2D(inputImg, vec2(x,y));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is the GLSL shader code for approach 2:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;varying vec2 tc; // texture coordinate of current output pixel&#xA;uniform sampler2D inputImg; // input image&#xA;uniform int outputWidth; // width of output image&#xA;uniform int outputHeight; // height of output image&#xA;const float PI = 3.141592653589793238462643383;&#xA;const int samplesPerSide = 4;&#xA;void main() {&#xA;  int samplesPerDirection = samplesPerSide * 2 + 1;&#xA;  // compute size of subsample step in texture coordinates&#xA;  float sampleStepX = 1.0 / float(outputWidth * samplesPerDirection); &#xA;  float sampleStepY = 1.0 / float(outputHeight * samplesPerDirection);&#xA;  vec4 sampleSum = vec4(0); // init sum to zero&#xA;  for(int i = -samplesPerSide; i &amp;lt;= samplesPerSide; i++) {&#xA;    for(int j = -samplesPerSide; j &amp;lt;= samplesPerSide; j++) {&#xA;      float phi = tc.x + float(i) * sampleStepX; // phi is x-direction in output&#xA;      float r = tc.y + float(j) * sampleStepY;   // radius is y-direction in output&#xA;      float xx = r * cos(2.0 * PI * phi);  // unit circle in range [-1.0, 1.0]&#xA;      float yy = r * sin(2.0 * PI * phi);&#xA;      float x = xx * 0.5 + 0.5; // input texture coordinate in range [0.0, 1.0];&#xA;      float y = yy * 0.5 + 0.5;&#xA;      sampleSum += texture2D(inputImg, vec2(x,y));&#xA;    }&#xA;  }&#xA;  gl_FragColor += sampleSum / float(samplesPerDirection * samplesPerDirection);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Approach 2, which is approx. factor 81 slower than 1 and 3, is probably the one you are looking for but I also like the bilinear interpolation result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With a WebGL capable browser you can try out these implementations here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.gsn-lib.org/index.html#projectName=CartesianToPolar&amp;amp;graphName=CartesianToPolar&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.gsn-lib.org/index.html#projectName=CartesianToPolar&amp;amp;graphName=CartesianToPolar&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4652" LastEditorUserId="38" LastEditDate="2016-07-02T07:02:48.307" LastActivityDate="2016-07-02T07:02:48.307" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3711" PostTypeId="2" ParentId="3709" CreationDate="2016-07-02T08:25:52.297" Score="4" Body="&lt;p&gt;First let us solve the radius of your circle. You can see that the centers of the circles form a triangle. There are 8 possible triangles, of which 4 are mirror solutions across the line that connects the centers of your original circles.  The other solutions are permutations of inside tangent and outside tangent connections. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6XSpu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6XSpu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: All possible solutions&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So knowing the quadrant is hardly enough for the choice of solution.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Solving the triangles&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/S8qfp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S8qfp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So for eaxmple let the circle be on the inner outside of both circles (the sign changes for the other solutions). Now you need to solve the equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA; D^2=(x+r_1)^2+(x+r_2)^2-2(x+r_1)(x+r_2)\cos(\beta)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now this can be solved in a computer algebra system and gives 2 solutions with numerous corner constraints (do it yourself it's important for robust code and obviously you need 4 solutions to check.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;x=\frac{1}{2} \left(\pm\sqrt{\frac{\cos (\beta) (r_1-r_2)^2-2 D^2+(r_1-r_2)^2}{\cos (\beta)-1}}-r_1-r_2\right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have x solved you can solve the center. This can be done in many ways but I would proceed by solving angle $\alpha$ and some vector rotation, normalization and scalar multiplication. Same calculation can be used to find the intersection point and the tangent is just this vector rotated by 90 degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could also use an alternate formulation with 2 angles and a vector sum of $a+b-c=0$, with 2 unknowns and 2 equations.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-07-02T17:46:29.030" LastActivityDate="2016-07-02T17:46:29.030" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3712" PostTypeId="1" CreationDate="2016-07-02T10:59:43.413" Score="1" ViewCount="161" Body="&lt;p&gt;Curves fairness is a strange problem in Computer Aided Geometric Design and every author gives his personal definition.&#xA;One of the simplest is the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A curve is said to be fair if&#xA;(1) it is G2 continuous,&#xA;(2) it has no undesirable inflection points, and&#xA;(3) its curvature varies in an even way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, but why is a curve with these properties fair ? It is only a definition and I can define what I want. I need a theorem to state something in mathematics.&#xA;Where are theorems about fairness ?&#xA;The problem is that in mathematics I can speak about sets,functions and other mathematical objects, but not about fairness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can you solve this problem ?&lt;/p&gt;&#xA;" OwnerUserId="1636" LastActivityDate="2016-07-02T10:59:43.413" Title="Curves fairness" Tags="&lt;curve&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3713" PostTypeId="1" CreationDate="2016-07-02T17:48:29.317" Score="12" ViewCount="1146" Body="&lt;p&gt;I am trying to get &lt;a href=&quot;https://www.shadertoy.com/view/lsKSDt&quot; rel=&quot;noreferrer&quot;&gt;this shader&lt;/a&gt; to run on a really old iDevice, as well as eventually Androids.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even when I reduce the code down to 2 sine functions per fragment the shader runs at about 20fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have considered taking a leaf out of the book of old shading techniques and creating an array that holds a bunch of predefined trig values and somehow using those to approximate the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the shader I linked above I am already simulating that by rounding the values sent to the trig function the further left the mouse (while down) goes the less quality of the shader. It's actually pretty cool because really close to the left side it looks like a completely different and pretty cool shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway I have two dilemmas:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I don't know what the most efficient way to have an array of like 360 values in it in a GLSL shader, constant or uniform?&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I can't figure out how to put a number in a range like usually if I wanted an angle between 0 and 360 (yes I know GPUs use radians) I would do it like so.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;func range(float angle)&#xA;{&#xA;   float temp = angle&#xA;   while (temp &amp;gt; 360) {temp -= 360;}&#xA;   while (temp &amp;lt; 0)   {temp += 360;}&#xA;   return temp;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However GLSL does not allow while loops or recursive functions.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2308" LastEditorDisplayName="user246" LastEditDate="2017-01-03T00:15:42.073" LastActivityDate="2018-03-13T10:54:25.730" Title="Using a LUT to speed up a trig heavy shader for mobile devices" Tags="&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="13" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3714" PostTypeId="2" ParentId="3661" CreationDate="2016-07-02T21:12:19.577" Score="3" Body="&lt;p&gt;After checking and rechecking my code over and over again. I finally made it work.&#xA;The problem was that I was creating the buffers and assigning locations to the position and the normals buffers&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Positions&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);&#xA;// Normals&#xA;glEnableVertexAttribArray(1);&#xA;glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However in the vertex shader I was not setting the locations&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410&#xA;&#xA;in vec4 vposition;&#xA;in vec3 vnormal;&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So changing the previous code to&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410&#xA;&#xA;layout(location = 0) in vec4 vposition;&#xA;layout(location = 1) in vec3 vnormal;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;fixed the application.&#xA;Now, I am not really sure why this works, but I remember reading somewhere that OpenGL assigns locations as it sees best, so maybe in my code the location for the normal was not the same as the enabled vertex attrib array. I let someone more experienced clarify this.&lt;/p&gt;&#xA;" OwnerUserId="116" LastActivityDate="2016-07-02T21:12:19.577" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3715" PostTypeId="2" ParentId="3707" CreationDate="2016-07-03T01:28:41.097" Score="7" Body="&lt;p&gt;Yes, your theory is correct. A gamma-correct blur entails converting the input pixels to linear color space, performing the blur weighting and accumulation in that space, and then converting back to gamma space at the end.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As noted in the comments, the actual transform is not literally squaring and square-rooting, that's just an approximation (and not that good of one). For the true sRGB gamma transform, see the equations in &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#Specification_of_the_transformation&quot;&gt;this Wikipedia article&lt;/a&gt; (look down the page for the equations involving $C_\text{srgb}$ and $C_\text{linear}$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, some visual comparisons of gamma-correct and gamma-incorrect blurs can be found on &lt;a href=&quot;http://ninedegreesbelow.com/photography/linear-gamma-blur-normal-blend.html#100&quot;&gt;this page by Elle Stone&lt;/a&gt;, which shows why this whole thing matters.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-07-03T01:28:41.097" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3716" PostTypeId="2" ParentId="3671" CreationDate="2016-07-03T02:55:52.373" Score="1" Body="&lt;p&gt;SceneKit, as of iOS 9/OS X El Capitan, can handle all of the suggested lighting changes from @trichoplax. The newly announced (June 2016) Physically Based Rendering (PBR), and support for Pixar's Universal Scene Description, make some stunningly beautiful images, if you can required iOS 10 (hint: you should). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;SceneKit is using Metal or OpenGL (your choice) as the renderer. What SceneKit gets you is a higher level of abstraction. I think that's a good approach for the problem you're trying to solve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I particularly recommend the videos of the SceneKit presentations at WWDC 2014, 2015, and 2016. The What's New presentation for 2014 was written in SceneKit, and is available as sample code. I haven't seen 2016's code yet but it's been promised. Also take a look at the ModelIO framework, which is designed for loading various standard 3d, texture, and lighting formats and making them available for SceneKit, Metal, and OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;David Rönnqvist's SceneKit book (&lt;a href=&quot;https://itunes.apple.com/us/book/3d-graphics-with-scene-kit/&quot; rel=&quot;nofollow&quot;&gt;on iBook Store&lt;/a&gt;) steps through the different texture, material, and lighting controls. It's a bit outdated now because of the PBR and ModelIO enhancements, but it's valuable in learning how to manipulate the scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Chris Language's book &lt;a href=&quot;https://www.raywenderlich.com/store/3d-ios-games-by-tutorials&quot; rel=&quot;nofollow&quot;&gt;3D iOS Games by Tutorials&lt;/a&gt; has two sections you should work through. Section II is, as far as I know, the only written documentation on using the Xcode Scene Editor. In the process, he covers the fundamentals of lighting and materials. Section III goes into more details on lighting and shadows. The book is pretty good at making render-related terminology and concepts accessible. I'm not a fan of its jumbling of view controllers and game logic, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think ultimately you're going to need to develop some intermediate level skill with a 3D modeling tool like Maya, Blender, or Cheetah3D, if only to understand the common challenges and paradigms for 3D rendering.&lt;/p&gt;&#xA;" OwnerUserId="4685" LastEditorUserId="4685" LastEditDate="2016-07-04T02:31:44.013" LastActivityDate="2016-07-04T02:31:44.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3717" PostTypeId="2" ParentId="2516" CreationDate="2016-07-03T12:34:20.267" Score="0" Body="&lt;p&gt;&lt;strong&gt;libCola&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;cola.js (a.k.a. WebCola) is a JavaScript based rewrite of libcola which works well with D3.js&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://marvl.infotech.monash.edu/webcola/&quot; rel=&quot;nofollow&quot;&gt;http://marvl.infotech.monash.edu/webcola/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gridified Layout example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://marvl.infotech.monash.edu/webcola/examples/dotpowergraph.html&quot; rel=&quot;nofollow&quot;&gt;http://marvl.infotech.monash.edu/webcola/examples/dotpowergraph.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;OGDF&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Open Graph Drawing Framework&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have an orthogonal layout&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Orthogonal: Ortholayout with modules for the steps of shape and&#xA;  compaction, ClusterOrthoLayout&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.ogdf.net/doku.php/ogdf:features&quot; rel=&quot;nofollow&quot;&gt;http://www.ogdf.net/doku.php/ogdf:features&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check projects that uses OGDF&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.ogdf.net/doku.php/project:external&quot; rel=&quot;nofollow&quot;&gt;http://www.ogdf.net/doku.php/project:external&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;HOLA&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Human-like Orthogonal Layout Algorithm&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://vimeo.com/150509722&quot; rel=&quot;nofollow&quot;&gt;https://vimeo.com/150509722&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Kieffer, Steve, Tim Dwyer, Kim Marriott, and Michael Wybrow. &quot;Hola: Human-like orthogonal network layout.&quot; Visualization and Computer Graphics, IEEE Transactions on 22, no. 1 (2016): 349-358.&lt;/p&gt;&#xA;" OwnerUserId="4687" LastEditorUserId="4687" LastEditDate="2016-07-04T17:26:56.427" LastActivityDate="2016-07-04T17:26:56.427" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3718" PostTypeId="2" ParentId="3706" CreationDate="2016-07-03T23:42:12.383" Score="8" Body="&lt;h2&gt;Sigma and kernel size of Gaussian filter&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Regarding how to choose the sigma and the kernel size (pixels) of the Gaussian: you set the sigma based on how wide of a blur you want (judging it visually) and then choose the kernel size based on the sigma. It's a game of finding a kernel size that captures enough of the (mathematically infinite) bell curve to look good, while not being too expensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a rule of thumb, the kernel size should be at least 6 times the sigma. Then the kernel extends out to 3 sigmas in each direction, which is enough to &lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_distribution#/media/File:Empirical_Rule.PNG&quot; rel=&quot;noreferrer&quot;&gt;cover almost all the weight&lt;/a&gt; of the mathematical bell curve. It's also nice to round up the pixel size to the next odd number so the filter will be symmetrical. So for example, with sigma = 1.5 px, you'd use a 9-pixel filter; with sigma = 2.0 px, use a 13-pixel filter, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, if you have performance limitations that control how big a kernel size you can use, then divide by 6 to get the maximum sigma you can get away with. (Note that sigma can be fractional, as it's just an input to the bell curve equation.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, a trick to get better performance on large Gaussian blurs is to downsample the image, perform a smaller blur, then upsample. For instance, to get an effective 13-pixel blur, you could downsample the image by 2x (using bilinear filtering), then perform a 7-pixel blur, and then upsample (using bilinear filtering). It will look almost as good as the 13-pixel blur, but will be considerably faster.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Creating a good-looking glow filter&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;A common trick with these is to use multiple Gaussians of different radius, added together. It makes a better glow effect than any single Gaussian by itself. For example, here's a mockup in Photoshop created with three layers additively blended together. The three Gaussians are of size 3px, 5px and 11px (corresponding to sigma = 0.5px, 0.83px, 1.83px respectively).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9QCiw.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9QCiw.jpg&quot; alt=&quot;mocked-up bloom filter&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also add even larger Gaussians to further increase the apparent radius of the glow. This is how the standard &quot;bloom&quot; effect is implemented in 3D game engines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If performance is a concern, the smallest Gaussian can be replaced by a copy of the unblurred original image; the resulting effect will look sharper, not so soft, but will still have a glow surrounding it. As mentioned previously, larger Gaussians can be done by downsampling, blurring, and upsampling; and the upsampling can be done using hardware bilinear filtering, folded into the pass that blends the layers together.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Jaggies&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;You'll notice that jaggies are still visible in some areas of the above image. Unfortunately, blurring is not very effective at hiding jaggies unless the blur radius is quite large. There's no easy way to use a post-process get rid of jaggies: the best way to avoid them is not to render them in the first place. :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hear you that you can't use MSAA for performance reasons, but may be another option.  Depending on how you render the glow trails, you might be able to slightly increase their size, and write a shader that applies a gradient to fade out the color within a couple pixels of the edge. That should help them look smoother. &lt;a href=&quot;https://www.shadertoy.com/view/MdtXWX&quot; rel=&quot;noreferrer&quot;&gt;Here's a shadertoy&lt;/a&gt; that demonstrates a 1px-wide edge falloff used for antialiasing a procedural shape.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-07-04T00:34:46.920" LastActivityDate="2016-07-04T00:34:46.920" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3721" PostTypeId="1" AcceptedAnswerId="3722" CreationDate="2016-07-04T18:23:56.550" Score="3" ViewCount="139" Body="&lt;p&gt;I try to write a simple triangle mesh renderer with OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ShaderProgram::SetUniformMatrix4(std::string name, glm::mat4 matrix)&#xA;{&#xA;  GLint location = glGetUniformLocation(program_, name.c_str());&#xA;&#xA;  if (location != -1)&#xA;  {&#xA;     glUniformMatrix4fv(location, 1, GL_FALSE, &amp;amp;matrix[0][0]);&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is my uniform related code. I made sure that &lt;em&gt;glUseProgram(program_)&lt;/em&gt; is called before this method is executed.&lt;br&gt;&#xA;Also the &lt;em&gt;glm::mat4&lt;/em&gt; does indeed contain the correct values and &lt;em&gt;program_&lt;/em&gt; has a value of 3 so it seems valid.&lt;br&gt;&#xA;The location comes out as a 0 &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here how I call that method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;shader_-&amp;gt;BindProgram();&#xA;shader_-&amp;gt;SetUniformMatrix4(&quot;matModel&quot;, transformation);&#xA;&#xA;texture_-&amp;gt;BindTexture();&#xA;mesh_-&amp;gt;Draw();&#xA;texture_-&amp;gt;FreeTexture();&#xA;&#xA;shader_-&amp;gt;FreeProgram();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now I have following simple Vertex Shader &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;layout (location = 0) in vec3 vertexPosition_modelspace;&#xA;layout (location = 1) in vec3 vertexNormal_modelspace;&#xA;layout (location = 2) in vec2 textureCoords_modelspace;&#xA;&#xA;uniform mat4 matModel;&#xA;&#xA;layout(std140) uniform Camera{&#xA;  mat4 matView;&#xA;  mat4 matProjection;&#xA;};&#xA;&#xA;out vec2 textureCoords;&#xA;&#xA;void main(){    &#xA;  textureCoords = textureCoords_modelspace;&#xA;  gl_Position =  matProjection * matView * matModel * vec4(vertexPosition_modelspace, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I see nothing on the screen which is the main error.&lt;br&gt;&#xA;When Debugging with Nvidia-NSight I find that all values except the &lt;em&gt;matModel&lt;/em&gt; are correctly set. The &lt;em&gt;matModel&lt;/em&gt; contains all zero which seems to be why the model isn't drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is the &lt;em&gt;matModel&lt;/em&gt; always zero, even when I try to set the uniform?&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="231" LastEditDate="2016-07-05T09:38:05.610" LastActivityDate="2016-07-05T09:38:05.610" Title="Uniform not set, despite valid location" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3722" PostTypeId="2" ParentId="3721" CreationDate="2016-07-04T22:32:49.957" Score="1" Body="&lt;p&gt;It seems that nothing was wrong with the code I posted.&#xA;I deleted my complete build and rebuild it, and now it seems to work.&#xA;I don't see anything on screen but i think that error is unrelated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can see the matrix in the nsight debugger.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-07-04T22:32:49.957" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3723" PostTypeId="1" CreationDate="2016-07-05T07:00:13.630" Score="4" ViewCount="396" Body="&lt;p&gt;I have a human body 'surface' mesh data.: triangular mesh (vertices, face)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I want to get from this is 'exact-down-sampled' version of the current mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which means.. the processed output mesh should have the vertices that all belong to the input mesh and the mesh data should be in the triangular mesh form..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know there are some surface mesh simplification algorithms, such as poisson surface reconstruction algorithm. But as far as I know, they don't preserve the positions of the input mesh.&#xA; What I simply want is to down-sample the points and triangulate them.&lt;/p&gt;&#xA;" OwnerUserId="4694" LastActivityDate="2018-04-18T22:33:49.680" Title="exact down sampling and re-triangulation of mesh data(non-convex)" Tags="&lt;algorithm&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3724" PostTypeId="1" AcceptedAnswerId="3735" CreationDate="2016-07-06T06:42:32.643" Score="3" ViewCount="1877" Body="&lt;p&gt;Given a set of vertices, transforming them to fit onto some spline curve.&#xA;For example 3D modelling software has extrude along curve and Unreal Engine has a spline mesh component that takes some mesh and stretches it along a defined curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some branch of mathematics or theory that looks into this?&lt;/p&gt;&#xA;" OwnerUserId="4702" LastActivityDate="2016-07-07T07:42:51.123" Title="How to deform some mesh so that it fits along a spline curve?" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;&lt;curve&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ClosedDate="2016-08-01T22:02:19.977" ContentLicense="CC BY-SA 3.0" />
  <row Id="3725" PostTypeId="1" CreationDate="2016-07-06T11:25:47.647" Score="6" ViewCount="118" Body="&lt;p&gt;For a project dealing with deep semantic labeling of images I need a format that supports arrays of arbitrary length for each pixel of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The array is an array of integers. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which image formats support this?&lt;/p&gt;&#xA;" OwnerUserId="4700" LastActivityDate="2016-07-06T22:00:21.027" Title="Is there a image-format that support an array per pixel?" Tags="&lt;raster-image&gt;&lt;image&gt;&lt;pixels&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3726" PostTypeId="2" ParentId="3725" CreationDate="2016-07-06T12:27:06.610" Score="2" Body="&lt;p&gt;Probably &lt;code&gt;.dds&lt;/code&gt;. You can store there textures array or 3d texture both can be use as array per pixel.&#xA;You can try creating this textures with &lt;code&gt;DxTex&lt;/code&gt; from &lt;code&gt;DirecX SDK&lt;/code&gt;.&#xA;Also you can look in &lt;code&gt;Legacy Texture Tools&lt;/code&gt; from Nvidia&#xA;&lt;a href=&quot;https://developer.nvidia.com/legacy-texture-tools&quot; rel=&quot;nofollow&quot;&gt;https://developer.nvidia.com/legacy-texture-tools&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2016-07-06T12:27:06.610" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3727" PostTypeId="2" ParentId="3723" CreationDate="2016-07-06T14:36:15.557" Score="4" Body="&lt;p&gt;&lt;strong&gt;1. Method: Vertex Clustering&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is more or less a low-quality method, but depending on your mesh it could work well.&lt;br&gt;&#xA;The basic idea is to partition the space into a regular grid, and then choose one representative for each cell that holds at least one vertex.&lt;br&gt;&#xA;Then calculate the connectivity based on the connectivity of the original vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/ijNC6.png&quot; alt=&quot;2D Vertex Clustering&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the image you see a basic 2D clustering. The unreduced mesh on the left, and the reduced on the right with the chosen representatives.&lt;br&gt;&#xA;As you can see, just choosing an existing vertex as representative (by closest to mean, or closest to center, or any other idea you can think of) you get a subset of vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But you also see the problem, thin parts will degenerate and parts that are close to forming a loop will probably get connected. But as already said, it depends on your mesh if this works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2. Method: Incremental Mesh Decimation with with Half-edge Collapse&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.researchgate.net/figure/221129055_fig1_Fig-1-Half-edge-collapse-decimation-operation&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vPLlx.png&quot; alt=&quot;Figure 2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One vertex gets collapsed into its neighbour. Thereby you get again a subsampling.&lt;br&gt;&#xA;This is a progressive method. You evaluate which collapse will decrease the quality (for example total distance to the original surface, but many more possible) and collapse it. Then you check if your quality has dropped too much for another collapse, and if so you stop. Otherwise you do it again. Until either the quality drops too much or the target size is reached.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Method 3: Progressive Mesh Decimation with Vertex Decimation.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same progressive idea as in method 2, but this time instead of a collapse you just delete a vertex and calculate a new triangulation for the hole that this created.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="48" LastEditDate="2018-04-18T22:33:49.680" LastActivityDate="2018-04-18T22:33:49.680" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3729" PostTypeId="1" CreationDate="2016-07-06T18:52:44.217" Score="6" ViewCount="1318" Body="&lt;p&gt;I have dealt with glsl before, but I still have problems with my understanding of how to achieve certain kinds of effects with per-pixel processing. What I am looking to do is use a fragment shader to emulate ink spreading across paper. Simply put, I want to emulate a large drop of ink being dropped on paper, with the ink spreading out from the source, perhaps with some capillary effect. Instead of one drop, this will apply to an entire image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ive done some brainstorming for the implementation. There is a random initial &quot;mass&quot; applied to each pixel, and one method I'm considering is having the texture scale outwards with the value of the initial &quot;mass&quot; decreasing until 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What might I be missing in trying to implement this? Does anyone know of a similar shader effect that I could consult while building this?&lt;/p&gt;&#xA;" OwnerUserId="4708" LastEditorUserId="4708" LastEditDate="2016-07-06T23:22:01.557" LastActivityDate="2017-03-29T19:56:36.060" Title="Creating an &quot;ink spread&quot; effect with a glsl fragment shader" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3730" PostTypeId="1" AcceptedAnswerId="3731" CreationDate="2016-07-06T19:30:02.953" Score="6" ViewCount="96" Body="&lt;p&gt;I have been trying to understand &quot;Fast Simulation of Mass-Spring Systems&quot; by Liu et al., which can be found &lt;a href=&quot;http://graphics.berkeley.edu/papers/Liu-FSM-2013-11/Liu-FSM-2013-11.pdf&quot;&gt;here&lt;/a&gt;. There is one part in the methods section that is confusing me. Just after equation 12, it states:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, &lt;strong&gt;S&lt;/strong&gt;&lt;sub&gt;&lt;em&gt;i&lt;/em&gt;&lt;/sub&gt; ∈ R&lt;sup&gt;&lt;em&gt;s&lt;/em&gt;&lt;/sup&gt; is the &lt;em&gt;i&lt;/em&gt;-th spring indicator, i.e., &lt;strong&gt;S&lt;/strong&gt;&lt;sub&gt;&lt;em&gt;i,j&lt;/em&gt;&lt;/sub&gt; = &lt;em&gt;δ&lt;/em&gt;&lt;sub&gt;&lt;em&gt;i,j&lt;/em&gt;&lt;/sub&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The subscript &lt;em&gt;i&lt;/em&gt; is for each spring in the system. But I am not sure what δ is supposed to be - it isn't mentioned anywhere else in the paper. I also don't know what the subscript &lt;em&gt;j&lt;/em&gt; is for, or what a spring indicator is. My guess was that &lt;strong&gt;S&lt;/strong&gt; is a diagonal matrix, with the deflection of each spring along the diagonal. But this doesn't work in my code. Having &lt;strong&gt;S&lt;/strong&gt; as just the identity matrix works better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know what the &lt;strong&gt;S&lt;/strong&gt; matrix is supposed to be?&lt;/p&gt;&#xA;" OwnerUserId="4705" LastEditorUserId="4705" LastEditDate="2016-07-06T19:49:16.340" LastActivityDate="2016-07-06T20:01:29.647" Title="Confusion about notation in a paper" Tags="&lt;simulation&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3731" PostTypeId="2" ParentId="3730" CreationDate="2016-07-06T19:52:08.680" Score="8" Body="&lt;p&gt;The notation $\delta_{i,j}$ is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Kronecker_delta&quot;&gt;Kronecker delta&lt;/a&gt;, a notation commonly used in physics. It's defined as:&#xA;$$\delta_{i,j} \equiv \begin{cases}1,&amp;amp;i=j\\0,&amp;amp;i\neq j\end{cases}$$&#xA;So, as you suspected, it's essentially a shorthand for the identity matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The notation $\mathbf{S}_i \in \mathrm{R}^s$ means that each $\mathbf{S}_i$ is an $s$-dimensional vector, so the index $j$ labels the components of this vector. The term &quot;indicator&quot; probably refers to the concept of an &lt;a href=&quot;https://en.wikipedia.org/wiki/Indicator_function&quot;&gt;indicator function&lt;/a&gt;, which is a function that labels some set or point with the value 1 while mapping everything else to 0. So, the &quot;$i$-th spring indicator&quot;, in this context, is a vector that has a 1 in the $i$-th component and 0 everywhere else. That's exactly the Kronecker delta, i.e. the identity matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way this &quot;indicator vector&quot; gets used in equation 12 in the paper is in the form of an outer product with another vector, $\mathbf{A}_i \in \mathrm{R}^m$. The two vectors are multiplied together in the form $\mathbf{A}_i \mathbf{S}_i^{\mathrm{T}}$, which is an outer product. The result is an $m \times s$ matrix with the contents of $\mathbf{A}_i$ in the $i$-th column, and zeroes everywhere else.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-07-06T20:01:29.647" LastActivityDate="2016-07-06T20:01:29.647" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3732" PostTypeId="1" AcceptedAnswerId="3737" CreationDate="2016-07-06T20:22:23.883" Score="4" ViewCount="515" Body="&lt;p&gt;Is it topological correct to combine triangles with quads to form a mesh. If not, why?&lt;/p&gt;&#xA;" OwnerUserId="4709" LastActivityDate="2016-07-07T14:44:39.093" Title="Combination of Triangles and Quads in a mesh" Tags="&lt;mesh&gt;&lt;triangulation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3733" PostTypeId="2" ParentId="3725" CreationDate="2016-07-06T22:00:21.027" Score="7" Body="&lt;p&gt;OpenEXR might be a good fit. You can have an arbitrary number of channels per pixel and the data types for each channel can be integers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.openexr.com/&quot;&gt;http://www.openexr.com/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4710" LastActivityDate="2016-07-06T22:00:21.027" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3734" PostTypeId="2" ParentId="3639" CreationDate="2016-07-07T03:39:29.670" Score="2" Body="&lt;p&gt;I see you use glEnable(GL_TEXTURE_GEN_S); but also use glTexCoord(...) to load coordinates. These are mutually exclusive features IIRC. If you are supplying your own texture coordinates you should not need to use glEnable(GL_TEXTURE_GEN_n).&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2016-07-07T03:39:29.670" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3735" PostTypeId="2" ParentId="3724" CreationDate="2016-07-07T07:35:05.870" Score="2" Body="&lt;p&gt;I have no knowledge of the literature on the topic, but I did something very similar to what you're asking some time ago: I wanted to generate lathe meshes and bend them according to a spline. I think the same technique could be adapted to your case quite easily.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First you would need to define what your default axis is: if the input mesh corresponds to the case when the spline curve is a straight line, where is that line in 3D? It could be defined arbitrarily as the Y axis, the PCA of the mesh, or some manually defined axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm is then:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;for each vertex v&#xA;{&#xA;    matrix4 M = ComputeTransformFromAxisToSpline(v);&#xA;    v = ApplyTransform(v, M);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The tricky part is obviously to define a transform $M$. You could do something like:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;matrix4 ComputeTransformFromAxisToSpline(vector3 v)&#xA;{&#xA;    float h = GetPositionOnAxis(v, originalAxis);&#xA;    vector3 p1 = GetPointOnSpline(h);&#xA;    vector3 p2 = GetPointOnSpline(h + dh); // dh is a small delta&#xA;    vector3 u = normalize(p2 - p1);&#xA;&#xA;    // Define an orthogonal basis&#xA;    vector3 v = v0;&#xA;    vector3 w = normalize(cross(u, v));&#xA;    vector3 v = normalize(cross(w, u));&#xA;&#xA;    return MakeTransform(u, v, w, p1) * MakeTranslation(originalAxis, -h);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;$v_0$ is going to be the problem. I have tried two approaches:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Use an absolute value, like an axis orthogonal to the default axis. This will work only if the spline never gets parallel to that axis. It may also lead to undesired shapes.&lt;/li&gt;&#xA;&lt;li&gt;Start with an absolute value for the points at $h=0$, then reuse the previous $v$ for bigger $h$ values. This means you have to treat vertices ordered by $h$. In my case this was trivial because I was generating the vertices, but in your case that would probably mean to sort them. The result is a mesh that will tend to twist in curves, which may or may not be desirable.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Another possibility would be to define the orientation by having more information in the curve, but I haven't tried that approach as I was already satisfied with the result.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-07-07T07:42:51.123" LastActivityDate="2016-07-07T07:42:51.123" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3736" PostTypeId="2" ParentId="3732" CreationDate="2016-07-07T10:32:52.690" Score="1" Body="&lt;p&gt;None of today's graphics interfaces support quads by default in the first place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that quads, when actually set up for rendering, are just pairs of triangles.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-07-07T10:32:52.690" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3737" PostTypeId="2" ParentId="3732" CreationDate="2016-07-07T12:50:17.560" Score="8" Body="&lt;p&gt;Topologically correct is a very vague.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe you think of Polygon-Meshes when you say meshes, which is to represent the surface of the object by a patch of polygons, in most cases triangles or quads. There are other options to model meshes, one idea would be to use signed distance functions as for example in constructive solid geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So back to the question. Is it correct to mix the type of polygon? Yes. There is, mathematically and theoretically nothing stopping you from doing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only real 'correctness' criteria that comes to my mind is the one of the mesh being a manifold. This is in (overly) simplficated the property that the mesh has a defined outside and inside and no strange places where you can't decide. (This happens for example if the mesh intersects with itself, but it get's freaky). And having different types of primitive does not violate the manifoldness of the mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But most algorithms can actually deal with non-manifolds. There is no problem in rasterizing or raycasting a non-manifold as these algorithms process each primitive separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The more interesting question here is: Why DONT we mix the type of primitive?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here the answer is very simple: Efficiency. You want to design an algorithm that handles your mesh as efficient as possible, and so you assume it's only one type of primitive. And at some point in time, because triangle-meshes are really handy, hardware and hardware-api began to adpot mainly to processing triangles. And now they are good at that and even other primitive types get split into triangles since splitting and rendering triangles is still faster than rendering the polygons directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in short: You can mix polygon types, but if you want to be fast, use only triangles since they are simple and widely used.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorUserId="273" LastEditDate="2016-07-07T14:44:39.093" LastActivityDate="2016-07-07T14:44:39.093" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3738" PostTypeId="1" CreationDate="2016-07-07T18:25:37.150" Score="10" ViewCount="2242" Body="&lt;p&gt;Why is the rendering equation, introduced by Kajiya in 1986, not solvable directly/analytically?&lt;/p&gt;&#xA;" OwnerUserId="4712" LastEditorUserId="7167" LastEditDate="2017-08-17T10:31:03.923" LastActivityDate="2017-08-19T09:41:00.650" Title="Rendering equation - why unsolvable directly?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;lighting&gt;&lt;brdf&gt;&lt;global-illumination&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3739" PostTypeId="1" AcceptedAnswerId="3741" CreationDate="2016-07-07T18:36:55.133" Score="6" ViewCount="244" Body="&lt;p&gt;Ok, I have a simulation I am trying to make. The entire simulation is drawn by circles (with gl_Point) and rectangles (gl_triangles with indices).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would be great to add some anti aliasing especially as there scale is usually rather small.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is I have seen some formulas that smooth step the edges of a shape, however I do not know how to properly consider scale.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each sprite will have different scale to it, each rectangle will have a different width / height ratio, not to mention I am not yet passing in texture coords because they have been so far un-necesary. And this will run on multiple screen resolutions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess I have two questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is it possible to anti-alias a rectangle in a fragment shader without knowing the UV of each fragment since I am not yet passing them in? Even if it was possible how would I account for different ratios of rectangles?&lt;/li&gt;&#xA;&lt;li&gt;What math can I use to ensure that no matter the device resolution, or shape size that the anti aliasing effects a maximum of 2 pixels (or whatever) from the edge of the shape?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-07-07T20:16:03.360" Title="How to never draw &quot;Jaggies&quot; in the first place considering resolution and scale" Tags="&lt;line-drawing&gt;&lt;antialiasing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3740" PostTypeId="2" ParentId="3738" CreationDate="2016-07-07T20:01:22.897" Score="13" Body="&lt;p&gt;The rendering equation is as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/d9L29.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d9L29.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the integral is over the sphere around the point $x$.&#xA;You integrate over some attenuated light, incoming from every direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But how much light comes in? This is the light $L(x',\omega_i)$ that some other point $x'$ reflects in the direction $\omega_i$ of point $x$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you have to calculate how much light that new point $x'$ reflects, which requires solving the rendering equation for that point. And the solution for that point depends on a huge number of other points, including $x$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, the rendering equation is infinitely recursive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You cannot solve it exactly and analytically because it has infinite integrals over infinite integration domains.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But since light gets weaker each time it is reflected, at some point a human simply cannot notice the difference any more. And so you do not actually solve the rendering equation, but you limit the number of recursions (say reflections) to something that is 'close enough'.&lt;/p&gt;&#xA;" OwnerUserId="273" LastEditorDisplayName="user106" LastEditDate="2017-08-19T09:41:00.650" LastActivityDate="2017-08-19T09:41:00.650" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3741" PostTypeId="2" ParentId="3739" CreationDate="2016-07-07T20:16:03.360" Score="3" Body="&lt;p&gt;Well you can render at higher resolution and sample down thhis is called FSAA and should just work without much change to render code. FSAA has the benefit of not having a conflation problem whereas smoothing does.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;No, something has to emit this info.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You take the derivate (the gfx card does this for you) of the surface varying to determine how far the step would take you in your pixel. if its over the edge then you antialias.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-07-07T20:16:03.360" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3742" PostTypeId="1" AcceptedAnswerId="5636" CreationDate="2016-07-08T05:14:00.333" Score="10" ViewCount="615" Body="&lt;p&gt;tl;dr: Math problem in projective geometry: &lt;strong&gt;How does one find some 4x4 camera matrix that gives a projection as illustrated below, such that points A,B,C,D are somewhere on the edges of the unit box (e.g. OpenGL normalized device coordinates), and the corners of the unit box fall somewhere reasonable along the rays EA, EB, EC, ED?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(This may be a special case possibly of a homography, a perspectivity, and/or a collineation. Not familiar with the terminology.)&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2&gt;elaboration&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Given a quadrilateral ABCD within the the viewport, I think there exists a unique(?) transformation that maps it back to a rectangle. As seen in the image below: the quadrilateral ABCD in the viewport acts as a physical 'window', and if we map it back to a rectangle it will appear distorted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/k5XLm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/k5XLm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(the box on the right represents NDC, which I talk about later)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The goal is to quickly obtain the image on the right. We could raytrace every point to obtain the image (which I've done), but I would prefer to use OpenGL or other projective techniques because I wanted to take advantage of things like blending, primitives, etc.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;first attempt&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I believe I can solve the problem of finding the 3x4 &lt;a href=&quot;https://en.wikipedia.org/wiki/Camera_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;camera matrix&lt;/a&gt; that makes the 3+1-dimensional &lt;a href=&quot;https://en.wikipedia.org/wiki/Homogeneous_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;homogeneous coordinate&lt;/a&gt; in 3-space (on the left) and projects it down to the 2+1 dimensional homogeneous coordinates in 2-space (on the right). One can solve this using the &lt;a href=&quot;https://en.wikipedia.org/wiki/Direct_linear_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;direct linear transformation&lt;/a&gt; to get a system of equations &lt;code&gt;Ba=0&lt;/code&gt; for the unknown entries &lt;code&gt;a&lt;/code&gt; of the camera matrix, and solving the system using &lt;a href=&quot;https://en.wikipedia.org/wiki/Singular_value_decomposition&quot; rel=&quot;nofollow noreferrer&quot;&gt;singular value decomposition&lt;/a&gt; (SVD). I would take the vectors EA, EB, EC, ED (where E is your physical eye or the camera in world-space) as points in the pre-image, and (0,0), (1,0), (1,1), (0,1) or something as the points in the post-image, and each pair of points would give a few linear equations to plug into the SVD. The resulting matrix would map EA-&gt;(0,0) etc. (assuming there are enough degrees of freedom i.e. if the solution is unique, which I'm not sure about, see note[a].)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But to my chagrin this is not how OpenGL works. OpenGL does not directly project 3d to 2d with a 3x4 matrix. OpenGL requires &quot;normalized device coordinates&quot; (NDC), which are three-dimensional points. After projecting into NDC, everything in the 'unit' box from (-1,-1,-1,1) to (1,1,1,1) is drawn; everything outside is clipped (since we're dealing with homogenerous coordinates: any point (x,y,z,w) will appear only on-screen only if the first three coordinates of (x/w,y/w,z/w,1) are within the unit box from -1 to 1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question becomes: does there exist some reasonable transformation that maps some weird-looking cuboid in homogeneous coordinates (specifically the cuboid drawn on the left, with ABCD (front points) and A'B'C'D' (back points, hidden behind front points)) to the unit cube, e.g. using a 4x4 matrix? How does one do it?&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;what I've tried&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I've tried something stronger: I made ABCD and A'B'C'D' look like a regular pyramidal frustrum (e.g. gl frustrum) (i.e. in this hypothetical setup, the image on the left would just have a black rectangle superposed on it, not a quadrilateral), and then used the DLT/direct linear transformation to solve for the alleged 4x4 matrix. However when I tried it, there did not seem to be enough degrees of freedom... the resulting 4x4 matrix did not map every input vector to every output vector. While using A,B,C,D,A' (5 pairs of pre-transform and post-transform vectors), I /almost/ get the result I want... the vectors are mapped correctly, but for example B',C',D' are mapping to (3,3,1,1) instead of (-1,-1,1,1) and are clipped away by OpenGL. If I try adding a sixth point (6 pairs of points for the 4x4 matrix to project), my solution seems degenerate (zeroes, infinites). How many degrees of freedom am I dealing with here, and is this possible with a 4x4 matrix mapping the usual 4vectors (3+1-dimensional homogeneous-coordinate vectors) that we know and love?&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;random minor thoughts&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I'm guessing that it's not possible to map any arbitrary cuboid to any arbitrary cuboid with a 4x4 matrix, though I'm confused because I thought it was possible to map any convex quadrilateral to any other convex quadrilateral in 2d with some matrix like in, say, Photoshop?... can/can't this not be done with a projective transform? And how does it generalize to 3d? ...... Also given the failed attempt to find a 4x4 matrix, linear algebra says we should not expect an NxN matrix to map more than N linearly independent points to N target points in the best case, but I feel that somehow homogeneous coordinates cheat this because there is some hidden colinearity going on? I guess not?&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;another solution?&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I guess one could also maybe do the following ugly thing, where you use a typical frustrum camera projection matrix, find the 2d points corresponding to the corners, then perform a 2d perspective distort homography, but if that were to happen after the pixels were rendered (e.g. photoshop) then there would be problems with resolution... maybe hypothetically one could figure out a matrix to perform this transformation on the XY-plane within NDC-space, then compose it with the normal frustrum-based matrix?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(note [a]: Degree of freedom: ABCD can be further constrained to be the post-image of a projective transformation acting on a rectangle, if that is necessary... that is the black rectangle on the left could be said to be the result of projecting a picture frame clipart model)&lt;/p&gt;&#xA;" OwnerUserId="4714" LastEditorUserId="4714" LastEditDate="2018-06-28T08:15:19.787" LastActivityDate="2018-06-28T08:15:19.787" Title="How to unproject quadrilateral into rectangle?" Tags="&lt;opengl&gt;&lt;projections&gt;&lt;matrix&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="3743" PostTypeId="2" ParentId="3704" CreationDate="2016-07-09T05:52:30.027" Score="2" Body="&lt;p&gt;The distinction is not clear mainly because the term &quot;shading&quot; is an extremely broad term. One of the first uses for programmable &quot;shaders&quot; in real-time graphics pipeline was computing illumination on vertices or pixels - close analogs to what an artist does when shading an object in a drawing for example. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Today it has come to encompass all calculations that figure into determining the final color of a fragment (&quot;fragment/pixel shader&quot;), or the final attribute values of a vertex (&quot;vertex shader&quot;) or primitive (&quot;geometry shader&quot;), etc. Generally all programmable stages in the real-time graphics pipeline have come be called &quot;shaders&quot; whether they compute colors/illumination or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Shadowing&lt;/em&gt; likely just refers to shading work that determines the portion of direct light that is occluded with respect to a location on a surface. It can also reasonably refer to &lt;em&gt;indirect&lt;/em&gt; illumination/occlusion.&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-07-09T05:52:30.027" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3744" PostTypeId="2" ParentId="3738" CreationDate="2016-07-09T21:49:04.233" Score="16" Body="&lt;p&gt;I'm sadly not able to add a comment to the answer above (not enough reputation), so I will do it like this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to point out that what Dragonseel describes is simply an integral equation (specifically a Fredholm equation of the second kind). There are many such equations which do have an analytic solution; even some forms of the rendering equation have one (e.g. the solution of a white furnace can be given using a simple convergent geometric series, even though the rendering equation is infinitely recursive).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also not necessary to bias the estimated solution by bounding the number of recursions. Russian Roulette provides an useful tool for giving us an unbiased solution for an infinitely recursive rendering equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main difficulty lies in the fact that the functions for reflectance (BRDF), emitted radiance and visibility are highly complex and often contain many discontinuities. In these cases there often is no analytic solution, or it is simply unfeasible to find such a solution. This is also true in the one dimensional case; most integrals lack analytic solutions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally I'd like to note that even though most cases of the rendering equation do not have analytic solutions, there is a lot of research in forms of the rendering equation which do have an analytic solution. Using such solutions (as approximations) when possible can significantly reduce noise and can speed up rendering times.&lt;/p&gt;&#xA;" OwnerUserId="4655" LastEditorUserId="7167" LastEditDate="2017-08-17T10:30:40.403" LastActivityDate="2017-08-17T10:30:40.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3746" PostTypeId="1" AcceptedAnswerId="3794" CreationDate="2016-07-11T14:54:35.777" Score="5" ViewCount="248" Body="&lt;p&gt;here is my vertex array I am using:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vertices = [&#xA;    -1.0,  1.0,  0.0,&#xA;     0.0,  1.0,  0.0,&#xA;    -0.5,  1.0,  0.0,&#xA;     0.5,  1.0,  0.0,&#xA;     1.0,  1.0,  0.0,&#xA;     1.0,  0.5,  0.0,&#xA;     0.0,  0.5,  0.0,&#xA;     0.5,  0.5,  0.0,&#xA;    -0.5,  0.5,  0.0,&#xA;    -1.0,  0.5,  0.0,&#xA;&#xA;    -1.0,  0.0,  0.0,&#xA;    -0.5,  0.0,  0.0,&#xA;     0.0,  0.0,  0.0,&#xA;     0.5,  0.0,  0.0,&#xA;     1.0,  0.0,  0.0,&#xA;&#xA;    -1.0, -0.5,  0.0,&#xA;     0.0, -0.5,  0.0,&#xA;    -0.5, -0.5,  0.0,&#xA;     0.5, -0.5,  0.0,&#xA;     1.0, -0.5,  0.0,&#xA;     1.0, -1.0,  0.0,&#xA;     0.0, -1.0,  0.0,&#xA;     0.5, -1.0,  0.0,&#xA;    -0.5, -1.0,  0.0,&#xA;    -1.0, -1.0,  0.0,&#xA;];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In a html-select I want to select a rendering mode and use it inmy &lt;code&gt;drawScene&lt;/code&gt;-method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var renderModeSelector = document.getElementById(&quot;renderModeDropDown&quot;);&#xA;var selectedRenderModeValue = renderModeSelector.options[renderModeSelector.selectedIndex].value;&#xA;&#xA;switch (selectedRenderModeValue) {&#xA;    case &quot;0&quot;:&#xA;        gl.drawArrays(gl.POINTS, 0, squareVertexPositionBuffer.numItems);&#xA;        break;&#xA;    case &quot;1&quot;:&#xA;        gl.drawArrays(gl.TRIANGLE_FAN, 0, squareVertexPositionBuffer.numItems);&#xA;        break;&#xA;    case &quot;2&quot;:&#xA;        gl.drawArrays(gl.LINE_LOOP, 0, squareVertexPositionBuffer.numItems);&#xA;        break;&#xA;    default:&#xA;        console.log(&quot;No rendering mode selected.&quot;);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Case '0' is supposed to draw the points which works fine&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZiyIL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZiyIL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Case '1' should draw a filled rectangle, with the shader below. Unfortunately it is messed up, see also in the picture below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;&#xA;varying vec4 vColor;&#xA;&#xA;void main(void) {&#xA;gl_FragColor = vColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vertex-shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;attribute vec3 aVertexPosition;&#xA;attribute vec4 aVertexColor;&#xA;&#xA;uniform mat4 uMVMatrix;&#xA;uniform mat4 uPMatrix;&#xA;&#xA;varying vec4 vColor;&#xA;&#xA;void main(void) {&#xA;gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);&#xA;vColor = aVertexColor;&#xA;gl_PointSize = 5.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vahR1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vahR1.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;And finally in case '2' it is supposed to draw only the outlines, which also does not work as expected, see below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/23zah.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/23zah.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So I wonder if it is possible to meet my requirements while using one vertexPositionBuffer. Should I maybe create another vertexPositionBuffer or can I just change mine &quot;on the fly&quot;, before rendering?&lt;/p&gt;&#xA;" OwnerUserId="2485" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T09:05:57.077" LastActivityDate="2018-03-06T09:05:57.077" Title="Rendering same vertex-array in different modes" Tags="&lt;rendering&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3748" PostTypeId="1" AcceptedAnswerId="3751" CreationDate="2016-07-12T19:23:13.317" Score="5" ViewCount="110" Body="&lt;p&gt;I have a pretty good glow shader going now thanks to some tips from people here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However there are a few things that bother me that could maybe be better.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;#1 Definition of the particles&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;A lot of times if the particles are moving a lot it just looks like a single sheet of color. The image below is zoomed in so you can see a bit more definition, but zoomed out and real time it just looks like a sheet of sorts&#xA;&lt;a href=&quot;https://i.stack.imgur.com/AO0kc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AO0kc.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;#2 The particles don't look like they are neon&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;I mean I don't want the effect to be huge but when they are grouped together I would hope for them to have some white highlighting in the glow.&#xA;It looks like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/UTIo5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UTIo5.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;When it should look more like this (this was just a mockup by blending in an additive copy of it with more contrast) when particles are grouped together [However singular particles shouldn't have white highlights]:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/9NWsT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9NWsT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my current rendering process:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a couple FBO's with texture attachments:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Drawing Frame: Never cleared, up-scaled for the purposes of anti-aliasing&lt;/li&gt;&#xA;&lt;li&gt;Smaller Frame: Cleared each frame, exact resolution of screen, Draws the drawing frame on it with the darkest parts cut out&lt;/li&gt;&#xA;&lt;li&gt;Horizontal Blur: Cleared each frame, does a horizontal blur (lower resolution than screen)&lt;/li&gt;&#xA;&lt;li&gt;Vertical Blur: Cleared each frame, blurs the horizontal blur vertically (lower resolution then screen)&lt;/li&gt;&#xA;&lt;li&gt;Front buffer: Draws the Smaller frame, and Vertical Buffers on top of each-other to the screen.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So A typical render might look like this (I apologize for the misalignment and cropping, the Xcode frame debugger allows you to peek at FBO's but not export the texture inside of them I had to use screenshots)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4RzP5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4RzP5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To combine the two textures I am using this &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_FragColor = vec4(clamp(texture2D(s_texture, v_texcoord).xyz, 0.,&#xA;1.) + (clamp(texture2D(s_texture2, v_texcoord).xyz, 0., 1.) * 1.5),&#xA;1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And for the two blurs I am using code like this, a lot of this is pre-computed but to make it easier to read I put how I computed it.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Gaussian(float x, float deviation)&#xA;{&#xA;    return (1.0 / sqrt(2.0 * 3.141592 * deviation)) * exp(-((x * x) / (2.0 * deviation)));&#xA;}&#xA;vec3 blurS15()&#xA;&#xA;{&#xA;    vec3 blr = vec3(0.0);&#xA;&#xA;    float scalart =  (1 / screenResolution.x) * (1.0 / 7.0) * 14.0;&#xA;    float deviationScale = 1.2;&#xA;    float finalScalar = 1.1;&#xA;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(7.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(7.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(6.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(6.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(5.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(5.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(4.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(4.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(3.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(3.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(2.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(2.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(1.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(1.0, 7.0 * deviationScale) ;&#xA;&#xA;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(0.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(0.0, 7.0 * deviationScale) ;&#xA;&#xA;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-1.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-1.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-2.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-2.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-3.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-3.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-4.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-4.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-5.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-5.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-6.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-6.0, 7.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-7.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-7.0, 7.0 * deviationScale) ;&#xA;&#xA;    return blr; //This gets put into gl_FragColor&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now while the issue could be in how I calculate the blur, and combine it I think it is more likely that the issue is in the way I render the particles. Basically each particle is rendered with a circle and a rectangle each frame. The dot marks where it is, and the rectangle connects it the the previous frame. Each new frame the previous frame is faded and then drawn over.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a diagram of the process, each new hue group represents a new frame, sorry for the childish look of the colors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tVyCW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tVyCW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I do this using two draw calls, one that draws the rectangles (GL_TRIANGLES with indices), and one that draws the circles (GL_POINTS with outsides alpha set to 0).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While this allows me to quickly simulate an accumulation buffer it comes with some drawbacks, if these can be dealt with without compromising speed then it would be nice to change them.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;No actual depth sorting, although the particles could easily have z values it is futile because opengles 2.0 will go black if you don't clear the depth buffer each frame, so it cant really work with an accumulation buffer.&lt;/li&gt;&#xA;&lt;li&gt;No additive drawing&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Because there are two separate draw calls, even with that setting on nothing seems to draw additively inside of the same draw call &lt;/li&gt;&#xA;&lt;li&gt;Even if I did the area where the circle and rectangle meet would be extra bright which is undesirable&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The additive mode I tried was&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBlendFunc(GLenum(GL_ONE), GLenum(GL_ONE))&#xA;glEnable(GLenum(GL_BLEND));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To be specific when I said it didn't work I tried disabling it before fade, and then enabling it afterwards. It caused everything to look weird almost as if there were no trails. And there didn't seem to be highlights where particles intersect. However if I had it enabled the whole time then it did look like additive blending. Only the previous frame never faded because you can't draw black in add blend mode.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you can think of any way I can get more highlighting especially when particles collide, or otherwise make the glow effect look better please let me know.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am very curious if there is a way to still do depth sorting with an accumulation buffer/a way to not have to clear the depth buffer.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorDisplayName="user246" LastEditDate="2016-10-08T20:42:22.267" LastActivityDate="2016-10-08T20:42:22.267" Title="Where are the highlight definitions inside of my shader?" Tags="&lt;lighting&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3749" PostTypeId="1" AcceptedAnswerId="3750" CreationDate="2016-07-12T20:56:38.973" Score="4" ViewCount="287" Body="&lt;p&gt;I have a 3 dimensional dataset where each value of the dataset is normalized to &lt;code&gt;[0, 1]&lt;/code&gt;. I want to visualize this dataset by using texture, and blending.&#xA;However, it seems that I can't make it work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is what I have done so far:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int main(){&#xA;    ...&#xA;    //building an image for each rectangular slice of data&#xA;    vector&amp;lt;Texture&amp;gt; myTextures;&#xA;    for (GLint rowIndex = 0; rowIndex &amp;lt; ROW_NUM; rowIndex++)&#xA;    {&#xA;        auto pathToImage = &quot;images/row&quot; + to_string(rowIndex) + FILE_EXT;&#xA;        FIBITMAP *img = FreeImage_Allocate(SLICE_DIMENSION, SLICE_NUM, 32); //32 = RGBA&#xA;&#xA;        for (GLint depthIndex = 0; depthIndex &amp;lt; DEPTH_NUM; depthIndex++)&#xA;        {&#xA;            for (GLint colIndex = 0; colIndex &amp;lt; COL_NUM; colIndex++)&#xA;            {&#xA;                auto value = my3DData[depthIndex][rowIndex][colIndex];&#xA;&#xA;                //transform tValue to a source color&#xA;                glm::vec4 source = transformValueToColor(value);&#xA;&#xA;                //note that here I am also setting the opacity. &#xA;                RGBQUAD linRgb = { source.b, source.g, source.r, source.a }; &#xA;                FreeImage_SetPixelColor(img, colIndex, depthIndex, &amp;amp;linRgb);&#xA;            }&#xA;        }&#xA;&#xA;        //Saving images. Saved images shows transparency. &#xA;        FreeImage_Save(FIF_PNG, img, pathToImage.c_str());&#xA;        myTextures.push_back(Texture(pathToImage.c_str(), GL_TEXTURE0));&#xA;    }&#xA;    //create VAO, VBO, EBO for a unit quad.&#xA;&#xA;    glEnable(GL_DEPTH_TEST);&#xA;    glEnable(GL_BLEND);&#xA;    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);&#xA;&#xA;    //game loop&#xA;    while (!glfwWindowShouldClose(window))&#xA;    {&#xA;        ...&#xA;        for (int i = 0; i &amp;lt; myTextures.size(); i++)&#xA;        {&#xA;            GLint index = myTextures.size() - i - 1;&#xA;            myTextures[index].bind(); //does glActiveTexture(...), and glBindTexture(...);&#xA;&#xA;            glm::mat4 model;&#xA;&#xA;            //translate&#xA;            model = glm::translate(model, glm::vec3(0.0f, 0.0f, -index*0.003f));&#xA;&#xA;            //scale&#xA;            model = glm::scale(model, glm::vec3(1.2f));&#xA;&#xA;            glUniformMatrix4fv(glGetUniformLocation(ourShader.Program, &quot;model&quot;), 1, GL_FALSE, glm::value_ptr(model));&#xA;&#xA;            glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;transformValueToColor&lt;/code&gt;for transforming data value in &lt;code&gt;[0,1]&lt;/code&gt; to color value:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//All inputs &amp;gt;=0.6 is transformed to highly transparent white color.&#xA;glm::vec4 transformValueToColor(GLclampf tValue)&#xA;{&#xA;    if (tValue &amp;gt;= 0.6f) {&#xA;        return glm::vec4(255, 255, 255, 10);&#xA;    }&#xA;    else {&#xA;        auto val = round(255 * tValue);&#xA;        auto valOp = round(255 * (1 - tValue));&#xA;        return glm::vec4(val, val, val, valOp);&#xA;    }    &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;layout(location = 0) in vec3 position;&#xA;layout(location = 1) in vec2 texCoord;&#xA;&#xA;out vec2 TexCoord;&#xA;&#xA;uniform mat4 model;&#xA;uniform mat4 view;&#xA;uniform mat4 projection;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position = projection * view * model * vec4(position, 1.0f);&#xA;    TexCoord = vec2(texCoord.s, 1-texCoord.t);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;in vec2 TexCoord;&#xA;&#xA;out vec4 color; &#xA;&#xA;uniform sampler2D sliceTexture;&#xA;&#xA;void main()&#xA;{&#xA;    vec4 texColor = texture(sliceTexture, TexCoord); &#xA;    color = texColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I think this is the code needed for the blending to work. The images are generated correctly, and also applied as texture on the quads correctly. However, the quads on the front appears as completely opaque, though the generated images (even the one appearing at front) shows transparent area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not sure where I am going wrong. Requesting your suggestions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Details of camera class. &lt;code&gt;Camera::getViewMatrix()&lt;/code&gt; provides &lt;code&gt;view&lt;/code&gt; matrix.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Camera::Camera(GLFWwindow* window, glm::vec3 position, glm::vec3 worldUpDirection, GLfloat yaw, GLfloat pitch)&#xA;    :mouseSensitivity(0.25f), fov(45.0f), cameraSpeed(1.0f)&#xA;{&#xA;    this-&amp;gt;position = this-&amp;gt;originalPosition = position;&#xA;    this-&amp;gt;worldUpDirection = worldUpDirection;&#xA;    this-&amp;gt;yaw = this-&amp;gt;originalYaw = yaw;&#xA;    this-&amp;gt;pitch = this-&amp;gt;originalPitch = pitch;&#xA;&#xA;    updateCameraVectors();&#xA;}&#xA;&#xA;void Camera::updateCameraVectors()&#xA;{&#xA;    glm::mat4 yawPitchRotMat;&#xA;&#xA;    yawPitchRotMat = glm::rotate(yawPitchRotMat, glm::radians(yaw), glm::vec3(0.0f, 1.0f, 0.0f));       //y-ais as yaw axis&#xA;    yawPitchRotMat = glm::rotate(yawPitchRotMat, glm::radians(pitch), glm::vec3(1.0f, 0.0f, 0.0f));     //x-axis as pitch axis&#xA;&#xA;    frontDirection = glm::normalize(-glm::vec3(yawPitchRotMat[2].x, yawPitchRotMat[2].y, yawPitchRotMat[2].z));&#xA;&#xA;    rightDirection = glm::normalize(glm::cross(frontDirection, worldUpDirection));&#xA;    upDirection = glm::normalize(glm::cross(rightDirection, frontDirection));&#xA;}&#xA;&#xA;glm::mat4 Camera::getViewMatrix()&#xA;{&#xA;    return glm::lookAt(position, position + frontDirection, upDirection);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the &lt;code&gt;projection&lt;/code&gt; matrix is given by: &lt;code&gt;glm::perspective(glm::radians(camera.fov), Width / Height, 0.1f, 100.0f);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; In short, blending was working all along. I followed the advice of user1118321, tested with only 2 textures, and found that it is working. Then I understood that a good part of images appearing on front was opaque. After that it was easy. I just manipulated with the transformation function &lt;code&gt;transformValueToColor&lt;/code&gt;, added additional threshold to make additional part of the image opaque. And that was it.&lt;/p&gt;&#xA;" OwnerUserId="3098" LastEditorUserId="3098" LastEditDate="2016-07-15T19:46:08.067" LastActivityDate="2016-07-15T19:46:08.067" Title="Can't make blending work" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;blending&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3750" PostTypeId="2" ParentId="3749" CreationDate="2016-07-13T03:59:42.333" Score="3" Body="&lt;p&gt;I notice that you've enabled blending and depth testing and are drawing with a non-opaque alpha channel. What's going to happen is that if you don't draw from back to front (relative to the camera), then any objects you draw that are farther away won't get drawn, so you won't see them through the nearer objects. If you turn off depth testing does it look correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To handle this correctly, you can also use a technique known as &lt;a href=&quot;https://en.wikipedia.org/wiki/Depth_peeling&quot; rel=&quot;nofollow&quot;&gt;depth peeling&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt; I see how you calculate your view matrix, but I don't see any code calling it, so it's hard to say whether your camera is pointing in the right direction or not for this to work as expected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One other thing I notice is that your projection matrix sets the near plane to 0.1, but you're translating your geometry in increments of -0.003. If your camera is at the origin (i.e. your view matrix has a translation of &amp;lt;0,0,0&gt;), then you won't see any layers until you get to the 34th layer. Also, with such small increments between the layers, you may end up with &lt;a href=&quot;https://en.wikipedia.org/wiki/Z-fighting&quot; rel=&quot;nofollow&quot;&gt;Z-fighting&lt;/a&gt;, as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might try hard-coding your loop to display just a single layer and make sure each layer is drawn correctly when drawn alone. Once you've verified that, you can figure out why drawing more than 1 layer doesn't work as expected.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2016-07-14T04:35:28.220" LastActivityDate="2016-07-14T04:35:28.220" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3751" PostTypeId="2" ParentId="3748" CreationDate="2016-07-13T07:54:40.517" Score="5" Body="&lt;p&gt;In order to achieve the &quot;white&quot; glow effect for amassed particles, you should probably switch to HDR rendering and have your tone mapping operator desaturate the &quot;overbright&quot; pixels. So you'll need a higher-precision, floating point render target (e.g. RGBA1010102, or RGBA16F) and a post-process step to bring  that down to the LDR system back-buffer. Then just make sure that your colliding particles add up to a sufficiently high colour value (i.e. over 1.0) and the tone mapper should do the trick.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may easily simulate an accumulation buffer by using the ping-pong pattern for your render targets:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render frame #0 to FBO A.&lt;/li&gt;&#xA;&lt;li&gt;Render frame #1 to FBO B, taking FBO A as history (i.e. hitherto accumulation) input.&lt;/li&gt;&#xA;&lt;li&gt;Render frame #2 to FBO A, taking FBO B as history input.&lt;/li&gt;&#xA;&lt;li&gt;Repeat from point 2.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In particular, you could have a moving average in order for the particles to leave nice trails like that. Check out Brian Karis's &lt;a href=&quot;https://de45xmedrsdbp.cloudfront.net/Resources/files/TemporalAA_small-59732822.pdf&quot;&gt;presentation on Unreal Engine 4's temporal supersampling&lt;/a&gt; - slides 15-17 describe the moving average-based blend weighting.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-07-13T07:54:40.517" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3752" PostTypeId="1" AcceptedAnswerId="3755" CreationDate="2016-07-13T16:50:17.123" Score="7" ViewCount="1707" Body="&lt;p&gt;I'm not really sure if this is possible but it should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I currently have a photo of a sphere, whose radius I've measures physically. Knowing the apparent size of the sphere from the photo and all internal camera parameters is it possible to estimate the distance from the camera to the sphere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is an equation, more used in lens imaging that is useful:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;object_image_size = (real_object_size * lens_focal_length)/object distance&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Problem is my object_image_size is in pixels and I need to convert it to a real world measure, preferable the size that actually showed up on the sensor. &lt;/p&gt;&#xA;" OwnerUserId="4735" LastActivityDate="2016-07-15T02:50:37.330" Title="Estimating real world object distance from photo" Tags="&lt;mathematics&gt;&lt;pixels&gt;&lt;conversion&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3753" PostTypeId="2" ParentId="3752" CreationDate="2016-07-13T17:40:43.970" Score="3" Body="&lt;p&gt;Yes, theoretically, for the sphere no for other things in image. If it is possible to augment the situation then it is possible to measure anything you can track much more reliably. First, knowing the scale of a object that you can successfully track is a requirement to getting a scale for the image as the cameras lost all scaling info. But this requirement alone is not enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice you do not know the other settings of a camera (unless calibrated with stereo geometry first), all kinds of problems arise when you do real camera tracking. Such as real cameras lens not being ideal. By tracking more than 2 features on the scene you can automatically estimate the actual focal distances and camera distortions. More importantly you can get an error estimate on your data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way is to have two photos from different angles in a scene with enough depth variation (for a stationary object this is quite easy). You can then use stereo geometry to solve the depth many such tracker apps exist as part special effects packages and making your own is not entirely out of the question (fun link, &lt;a href=&quot;https://www.youtube.com/watch?v=DgGV3l82NTk&quot; rel=&quot;nofollow&quot;&gt;fundamental matrix song&lt;/a&gt;). The second way is to have a known plane, the plane can be solved by knowing 4 points and their relative locations. In reality it is better use more points for error and lens correction estimates. A third way is to use structured light (a cloud of laser light points, or a line for example) to triangulate the point distances. Or you could use a light field camera.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-07-14T19:15:13.060" LastActivityDate="2016-07-14T19:15:13.060" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3755" PostTypeId="2" ParentId="3752" CreationDate="2016-07-14T05:02:41.603" Score="3" Body="&lt;p&gt;I may be misunderstanding what you're asking, but if you know the sensor size and the number of pixels in the object, then you can calculate the object size. For example, a &lt;a href=&quot;http://www.dpreview.com/products/canon/slrs/canon_eos7d/specifications&quot; rel=&quot;nofollow noreferrer&quot;&gt;Canon 7D&lt;/a&gt; has an APS-C sensor that's 22.3 x 14.9mm and 5184 x 3456 pixels. That works out to ~0.0043mm/pixel. So if you have an object that's 250 pixels wide, then the projection of the object onto the sensor would have been 250 pixels * 0.0043mm/pixel = 1.075mm wide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&#xA;So just for fun, I gave this a try. I took a 300mm ruler, put it at 1 meter from the camera and shot it with a 50mm lens on a Canon 7D. According to the ruler tool in Photoshop, it was 3734 pixels wide. That gives me the following equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3734 * 0.0043 = (300 * 50) / 1000&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&#xA;&lt;p&gt;16.0562 = 15.0&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, it's close, but not exact. (Over by 7%.) My guess is that the sensor site size is actually slightly smaller than 0.0043mm or the sensor size is slightly bigger than the reported size. In fact, the specs for the camera say 18MP effective size, but 19MP actual sensor size. So I'm not sure what that means, but I'm guessing it explains the difference between my actual result and the calculated result. (Either that or I'm misreading the length in Photoshop and it should actually be 3488 pixels instead of 3734.) But it was fun to try!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2nd EDIT:&lt;/strong&gt; &lt;a href=&quot;https://photo.stackexchange.com/questions/69582/why-isnt-my-computation-of-the-actual-size-of-an-object-in-a-photograph-matchin&quot;&gt;This question on the Photo Stack Exchange&lt;/a&gt; explains it. Camera lenses are often slightly longer or shorter than claimed, but rounded to the nearest nice focal length. So (assuming my calculations and measurements were correct) my lens is actually a ~53.5mm lens.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="-1" LastEditDate="2017-04-13T12:44:05.773" LastActivityDate="2016-07-15T02:50:37.330" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3756" PostTypeId="2" ParentId="3612" CreationDate="2016-07-15T05:27:57.677" Score="2" Body="&lt;p&gt;Perspective correct interpolation of normals works just as it does any color or coordinate or other linearly varying attribute. Each component of each varying vector is interpolated independently as if they were scalars, using exactly the same equation. &lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-07-15T05:27:57.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3757" PostTypeId="1" AcceptedAnswerId="3784" CreationDate="2016-07-15T09:00:02.467" Score="12" ViewCount="812" Body="&lt;p&gt;I'm Learning about BRDFs and wondering why the BRDF is defined as the ratio of outgoing radiance to a given direction and incoming irradiance from another direction. Why isn't the BRDF defined as ratio of radiances?&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2016-07-22T19:42:31.390" Title="Why isn't a BRDF a ratio of radiances?" Tags="&lt;brdf&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3758" PostTypeId="1" CreationDate="2016-07-15T10:00:11.443" Score="7" ViewCount="628" Body="&lt;p&gt;I am trying to implement &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.32.6170&amp;amp;rep=rep1&amp;amp;type=pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing with Cones (Amanatides 1984)&lt;/a&gt;. Instead of rays, cones are shot into the scene and intersected with geometry. Since multiple triangles can occupy the cone's aperture, we need to calculate (or rather quickly estimate, since cone tracing makes a lot of approximations anyway) the relative area of the circle that is covered by the triangle. Afterwards, the individual contributions are weighted and summed up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The author, unfortunately, does not give a lot of detail about his solution. Here is what he writes on cone-plane intersections:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The spread angle and the angle between the ray and plane computed&#xA;  above together indicate how the distance between the center of the&#xA;  circle and the edge of the half plane [sic]. Given this distance, the area&#xA;  of intersection is computed using a polynomial approximation. This&#xA;  completes the intersection calculation for planes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And then, after projecting a polygon to the plane perpendicular to the&#xA;direction vector of the cone:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We then must calculate the intersection between the projected polygon&#xA;  and a circle. This can be accomplished by calculating the distance&#xA;  from the center of the circle to each of the edges and then using the&#xA;  circle - half plane intersection estimation mentioned earlier.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I found &lt;a href=&quot;https://stackoverflow.com/questions/540014/compute-the-area-of-intersection-between-a-circle-and-a-triangle&quot;&gt;a solution to the problem&lt;/a&gt; over at StackExchange. I have ported the code from &lt;a href=&quot;https://stackoverflow.com/a/22420313/776142&quot;&gt;NowIGetToLearnWhatAHeadIs' answer&lt;/a&gt;, and it works fine, but seems pretty complicated to me. I am working with Compute Shaders, so branching is a bad thing, and the solutions rely heavily on it.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;What is this &lt;em&gt;polynomial approximation&lt;/em&gt; that Amanatides talks about, and how is it to be applied to polygons (espc. triangles)?&lt;/li&gt;&#xA;&lt;li&gt;Is there any approximation to the problem that will give resonably accurate results (say ±10%) at considerable performance / code simplicity gains?&lt;/li&gt;&#xA;&lt;li&gt;Working with GPUs, I am interested in an optimized solution that uses min/max over branching, for example. Maybe something like this already exists. Any luck?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="385" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-07-18T15:09:59.560" Title="Estimating the area of a triangle-circle intersection" Tags="&lt;raytracing&gt;&lt;performance&gt;&lt;computational-geometry&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3759" PostTypeId="2" ParentId="3758" CreationDate="2016-07-15T12:57:23.850" Score="4" Body="&lt;h2&gt;Working Towards an Exact solution&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;Just some quick thought before I must run!&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ok, let us turn the problem on its head. What if one does not calculate the area of the triangle cut by the circle. Instead let's calculate the inverse of this. The area of three segments cut out of the circle. The beauty of this approach is that we can make a single piece of code that we can repeat three times. Of course some of the time the answer will be 0 but that is OK.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ou8QT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ou8QT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Let's calculate this problem instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now it turns out we know how to calculate the inverse, it is the segment of a circle.  So we can just say that $A_{int}=A_{circle}-A_1-A_2-A_3$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kE7Wa.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kE7Wa.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: We know this solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula for the area of a segment is simply $A_{sector}-A_{triangle}$ and that has a well known solution in literature. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now all you need to do is find the intersections between the edges and the circle in a space centered on the circle, calculate the angle between those and then calculate each segment. And the only special case is if no intersection exists. I dont know if this is fast but at least code should be somewhat easy to implement.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-07-16T12:18:25.760" LastActivityDate="2016-07-16T12:18:25.760" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3760" PostTypeId="1" CreationDate="2016-07-15T23:49:56.603" Score="8" ViewCount="335" Body="&lt;p&gt;I'm trying to triangulate complex 3D objects, that may have holes in them. Now I tried going over the problem myself, after a few hours I didn't get anything that would work all of the time, so I've been searching around and without much luck. Does anyone know of any algorithms, or free libraries, that would suit my needs. Links to any relevant documentation would be appreciated as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also as a note, I'm a self taught programmer/cs-tist. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a set of points and I need to provide a game engine the shape in triangles. I get these points from a shape, I then add points to add area, subtract area, or split the shape. After modifying/adding points I need to give the game engine the shape in triangles as well as other information. Holes could be anywhere in any shape.&lt;/p&gt;&#xA;" OwnerUserId="4747" LastEditorUserId="4749" LastEditDate="2016-07-17T19:26:44.807" LastActivityDate="2016-07-17T19:26:44.807" Title="Computational Geometry - Triangulation" Tags="&lt;computational-geometry&gt;&lt;triangulation&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3761" PostTypeId="2" ParentId="3760" CreationDate="2016-07-16T01:18:44.440" Score="5" Body="&lt;p&gt;What it means to &quot;triangulate complex 3D objects&quot; is not unambiguous.&#xA;Just one possible interpretation: You have a 3D polygon in space, and you&#xA;want to triangulate that. This is NP-hard:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Barequet, Gill, Matthew Dickerson, and David Eppstein. &quot;On triangulating three-dimensional polygons.&quot; &lt;em&gt;Proceedings of the 12th Symposium on Computational Geometry&lt;/em&gt;. ACM, 1996. (&lt;a href=&quot;http://dl.acm.org/citation.cfm?id=237234&amp;amp;dl=ACM&amp;amp;coll=DL&amp;amp;CFID=644220912&amp;amp;CFTOKEN=23394613&quot; rel=&quot;nofollow noreferrer&quot;&gt;ACM link&lt;/a&gt;.)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;hr /&gt;&#xA;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/PeHXb.png&quot; width=&quot;400&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="4748" LastActivityDate="2016-07-16T01:18:44.440" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3764" PostTypeId="1" AcceptedAnswerId="3766" CreationDate="2016-07-18T18:39:53.650" Score="8" ViewCount="441" Body="&lt;p&gt;I am trying to simulate the image warp effect, that is used in Adobe Photoshop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rectangular image is warped according to a cubic Bézier surface (in 2D, all Z components are 0). Having any Bézier surface, &lt;strong&gt;vertical distortion&lt;/strong&gt; $d \in[0,1]$ can be applied to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Left&lt;/strong&gt;: input bézier surface, $d=0$, &lt;strong&gt;Right&lt;/strong&gt;: output surface,  $d=0.8$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VHlGk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VHlGk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.imgur.com/tSfAURr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/tSfAURr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any idea, what is done to the Bézier surface (16 points), when converting from the version on the left to the output on the right?&lt;/p&gt;&#xA;" OwnerUserId="4761" LastEditorUserId="4761" LastEditDate="2016-07-21T19:25:05.490" LastActivityDate="2016-07-21T19:25:05.490" Title="Apply distortion to Bézier surface" Tags="&lt;transformations&gt;&lt;geometry&gt;&lt;computational-geometry&gt;&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3765" PostTypeId="1" AcceptedAnswerId="3783" CreationDate="2016-07-19T12:31:24.113" Score="7" ViewCount="184" Body="&lt;h1&gt;Overview&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;My program receives some data points (0-400 per sec). &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// simplified example of point's data structure&#xA;struct Point {&#xA;    QPoint p;&#xA;    QTime t;&#xA;    quint32 value;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I need to render some filtered points (eg. that &lt;code&gt;point.time &amp;gt; currentTime-5&lt;/code&gt; and &lt;code&gt;point.value&amp;gt;5&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;li&gt;I need to store data history (up to ~50'000 points).&lt;/li&gt;&#xA;&lt;li&gt;The data can be used also on the CPU. &lt;/li&gt;&#xA;&lt;li&gt;I will use object-picking. &lt;/li&gt;&#xA;&lt;li&gt;Points are rendered in 3d.&lt;/li&gt;&#xA;&lt;li&gt;Camera position can change, but points data is constant.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;Question&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;What is the best architecture to implement this kind of problem? What are best practices with this kind of data and what are practices to avoid?&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Possible solutions&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Storing and filtering data.&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Store the data on the CPU (world coordinates), filtering data on a CPU and sending filtered data to VBO, calculating screen-space coordinates with shaders.&lt;/li&gt;&#xA;&lt;li&gt;Store the data on a CPU and a GPU (update a VBO when some new point arrives).&lt;br&gt;&#xA;Filter points on CPU and calculate offsets and use &lt;code&gt;glMultiDrawArrays&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Store the data only on a GPU (update VBO when point arrives).&lt;br&gt;&#xA;Filter it with shaders, get data from VBO to CPU when needed.&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Solution 1. is fairly easy, but I think it is a bad practice.&lt;br&gt;&#xA;Solution 2. has data duplication, but it is easy to filter the data.&lt;br&gt;&#xA;Solution 3. has data reading GPU-&gt;CPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried those solutions, and Solution 2. occurs to me as the best, but there are some issues with it:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Multiplication of data has to be handled gently.&lt;/li&gt;&#xA;&lt;li&gt;It is not the easiest-to-read-and-modify solution.&lt;/li&gt;&#xA;&lt;li&gt;When there are changes in data there is a lot of things to change.&lt;br&gt;&#xA;I used something like circular buffer on VBO and send offsets to render on it.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;Environment&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;OpenGL 3.3&lt;/li&gt;&#xA;&lt;li&gt;Qt 5+ bindings&lt;/li&gt;&#xA;&lt;li&gt;Linux&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;PS&lt;br&gt;&#xA;I am fairly new to computer graphics and openGL, so maybe this kind of problem even has its name. I changed my implementations few times, it took me a lot of time and I am not happy with it due to its complexity. Any materials, guides and thoughts are welcome. &lt;/p&gt;&#xA;" OwnerUserId="4765" LastEditorUserId="231" LastEditDate="2016-07-22T12:36:48.907" LastActivityDate="2016-07-22T17:08:40.300" Title="Proper architecture for rendering history of streamed data (points)" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3766" PostTypeId="2" ParentId="3764" CreationDate="2016-07-19T14:42:16.460" Score="5" Body="&lt;p&gt;Edit: changed the answer according to new images and clarification.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for every control point p(k, n)&#xA;   p'(k, n) = ( p(k, n) - p(k) ) * d * l(k) + p(k, n)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;k&lt;/code&gt; is the row index and &lt;code&gt;n&lt;/code&gt; is the column index of control point. &lt;code&gt;l&lt;/code&gt; is the elevation factor and is equal to {-1, -1/3, 1/3, 1}. &lt;code&gt;p(k)&lt;/code&gt; is the center of the k'th row.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Rationale:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the new images, red and blue lines are drawn from the center of the line (p(k) which is basically (k, 0)) to that point. On the first line, all control points, including the ones on the graph (red lines) are moved to the same point on that line. p(k, n) - p(k) gives the vector which moves a point from p(k) to p(k, n) which now should be applied to the other way, moving the point to the desired location. On your graphs, d = 1 so that all first line points would be moved to the center. You can easily solve the equation to verify this. &lt;code&gt;d * l(0)&lt;/code&gt; is -1, so it would be &lt;code&gt;-p(k, n) + p(k) + p(k, n)&lt;/code&gt; which would give p(k).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the second line, your blue line is again from point to the center, but this time it stopped before reaching it. I cannot tell if it really is cut from 1/3 but that would be a good starting point. So the same formula still applies. l is -1/3 d is 1, so the point would be moved in 1/3 of the way. 3rd is the same as the second but it now moves outwards, thus l is 1/3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the final line, all control points are moved out from the center point of that line. This is quite clear since your lines meet up at that center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only problem this formula can have is assumption of 1/3, other than that I do not see the reason why it should fail. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I used row, column while indexing, thus if you are using x, y you should switch their locations.&lt;/p&gt;&#xA;" OwnerUserId="4524" LastEditorUserId="4524" LastEditDate="2016-07-21T06:11:39.750" LastActivityDate="2016-07-21T06:11:39.750" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="3767" PostTypeId="1" CreationDate="2016-07-19T18:20:16.133" Score="6" ViewCount="428" Body="&lt;p&gt;I'm probably going to screw this up but.... In all the graphics libraries I've seen various matrices are often called something along the lines of&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;viewProjection&#xA;modelViewProjection&#xA;worldViewProjection&#xA;mvp&#xA;wvp&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, that seems unintuitive given that GLSL, HLSL, and most math libraries seem to multiply in the opposite direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;viewProjection = projection * view;  // correct but unintuitive&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;vs&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;viewProjection = view * projection;  // incorrect but naming matches order&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It gets worse if you add in transpose or inverse since now the order of operations vs the order of parts of the name of the matrix make zero sense whatsoever. a &lt;code&gt;worldViewProjectionInverseTranspose&lt;/code&gt; would be&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;transpose(inverse(projection * view * world))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Well you can read it backward but as far as order of operations and position in the expression its &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;5 ( 4 ( 1 * 2 * 3 ) )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there any objective reason for the names to be backward from the operations that construct them or is it just some naming convention that stuck from some example lost in obscurity?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm asking this question because being that it's unintuitive I find it's always hard to remember the order. If &lt;code&gt;worldViewProjection&lt;/code&gt; equaled &lt;code&gt;world * view * projection&lt;/code&gt; it would be easy since the name matches the order. I'm hoping there's some other objective reason that might help remember vs just remembering always multiply backward from the order of the parts of the commonly used names.&lt;/p&gt;&#xA;" OwnerUserId="4766" LastActivityDate="2016-07-21T03:41:33.600" Title="Is there a objective reason for matrix naming conventions?" Tags="&lt;transformations&gt;&lt;glsl&gt;&lt;hlsl&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3768" PostTypeId="1" CreationDate="2016-07-19T22:00:48.733" Score="0" ViewCount="350" Body="&lt;p&gt;I am trying to render Blinn Phong as a BRDF model on a surface plane. I assume that every normal in every pixel is perpendicular with the plane.&#xA;I know that to do a rendering we have to use 3d programing API such as OpenGL or WebGL and so on.&lt;br&gt;&#xA;My purpose is to render the surface plane without those APIs. The steps that I take are, I create 2 spaces:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;image space: (0,0) is at the top left of the image.&lt;/li&gt;&#xA;&lt;li&gt;camera space: (0,0) is at the middle of the image.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For vector computation, I convert every pixel position of image space to camera space then to world space.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;double[] cam=((new double[]{0,0,1}));&#xA;double[] lum=((new double[]{0,0,1}));&#xA;double[] E=new double[3];&#xA;double[] L=new double[3];&#xA;double[] H=new double[3];&#xA;double D2;&#xA;Mat image=new Mat(rows,cols,CvType.CV_8UC3);&#xA;System.out.println(&quot;Start!!&quot;);&#xA;System.out.println(&quot;ok&quot;);&#xA;for(int i=0;i&amp;lt;tileHNumber;i++)&#xA;{&#xA;    for(int j=0;j&amp;lt;tileWNumber;j++)&#xA;    {&#xA;        for(int s=0;s&amp;lt;192;s++)&#xA;        {&#xA;            for(int t=0;t&amp;lt;192;t++)&#xA;            {&#xA;                originS=s+192*i;//ligne&#xA;                originT=t+192*j;//colonne&#xA;                double[] pos=(Image2Cam(new double[]{originT,originS,0}));&#xA;                E=normalize(XY(cam,pos));&#xA;                L=normalize(XY(lum, pos);&#xA;                double[] le=addXY(L,E);&#xA;                H=normalize(le);&#xA;                D2=dot(E,E);&#xA;                double blue=color(blueColor,pos,E,L,H,D2);&#xA;                double green=color(greenColor,pos,E,L,H,D2);&#xA;                double red=color(redColor,pos,E,L,H,D2);&#xA;                image.put(originS, originT, new byte[]{(byte)(blue),(byte)(green),(byte)(red)});&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;public static double color(double col,double[] pos,double[] E,double[] L,double[] H,double D2)&#xA;{&#xA;    double value=0;&#xA;    double[] N=normalize((new double[]{pos[0],pos[1],1}));&#xA;    double diffuse=Math.max(0, dot(N,L));&#xA;    double specular=Math.pow(Math.max(0, dot(N,H)),60);&#xA;    value=d*diffuse*0.5+0.2*d+specular*255*0.3;&#xA;    return value;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The 2 images below show my results: the first one shows diffuse image only. The second one shows specular image only represented by the white color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is why the lobe specular is not surrounding the center of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7yBBh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7yBBh.jpg&quot; alt=&quot;Diffuse image&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/A1h2s.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A1h2s.jpg&quot; alt=&quot;Specular image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3328" LastEditorDisplayName="user7220" LastEditDate="2018-04-18T18:41:10.557" LastActivityDate="2018-04-18T18:41:10.557" Title="Blinn Phong rendering" Tags="&lt;rendering&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3769" PostTypeId="2" ParentId="3767" CreationDate="2016-07-19T23:21:29.547" Score="8" Body="&lt;p&gt;I think the naming order is intuitive because it is in reading order (left to right), e.g., worldViewProjection means that your point/direction is first multiplied by the world matrix, then the view matrix, and then the projection matrix. In this manner, you know the correct multiplication order by just reading the variable name and you do not have to think about mathematics at all. In your case, I think the problem is that your intuition seems to be focused on how you write the equations on paper or code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea that a point is a column vector and matrices are multiplied on the left is also just a mathematical convention that you are used. You can use a row vector and multiply on the right by the transpose matrix, and the math is exactly the same, but would imply a reverse writing order in compound transformations. Some people just prefer one notation over the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have read some old computer graphics books that use row vectors as points/directions, but it seems that most modern books have converged on using column vectors. IMHO, maybe this change during the years is one of the sources of confusion for so many new CG students.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, if you choose to represent points as row vectors you would write something like this in your code: &lt;strong&gt;new_point = point * world * view * projection&lt;/strong&gt;. On the other hand, if you use column vectors you would write this: &lt;strong&gt;new_point = projection * view * world * point&lt;/strong&gt;. The important thing is that these matrices must not be the same, that is, the world matrix in the first code is the transpose of the world matrix in the second code, and the same is true for the others. As you can see, if you choose one math convention over the other, this will probably have influence on your naming conventions while writing your code.&lt;/p&gt;&#xA;" OwnerUserId="4768" LastEditorUserId="4768" LastEditDate="2016-07-19T23:32:55.590" LastActivityDate="2016-07-19T23:32:55.590" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3771" PostTypeId="1" CreationDate="2016-07-20T06:59:43.183" Score="4" ViewCount="61" Body="&lt;p&gt;I have a 3d surface mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say the camera is located in some points and I want to get the visible points from the 3d surface mesh from the camera view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe this kind of process would be done before 3d rendering in graphics. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know how it generally works and fast, simple algorithm for the problem. It would be better, if there is some matlab function library to do this task.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that 3d rendering is not my purpose... I just want to get the visible point set from the 3d surface mesh.&lt;/p&gt;&#xA;" OwnerUserId="4696" LastActivityDate="2016-07-20T07:32:16.313" Title="get partial view points from 3d surface mesh" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3772" PostTypeId="2" ParentId="3771" CreationDate="2016-07-20T07:32:16.313" Score="1" Body="&lt;p&gt;In your case you would test every point to see if it lies inside your camera frustum, this is basically a set of point-vs-plane tests. This is not a fast way to do do things but the simplest to understand and implement. &lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2016-07-20T07:32:16.313" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3773" PostTypeId="2" ParentId="3768" CreationDate="2016-07-20T08:43:25.277" Score="1" Body="&lt;p&gt;If I'm guessing right, you are drawing a plane which is facing the camera, so your normals need to be 0,0,-1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;change&lt;/p&gt;&#xA;&#xA;&lt;p&gt;double[] N=normalize((new double[]{pos[0],pos[1],1}));&lt;/p&gt;&#xA;&#xA;&lt;p&gt;to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;double[] N=normalize((new double[]{0,0,-1}));&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2016-07-20T08:43:25.277" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="3774" PostTypeId="2" ParentId="3767" CreationDate="2016-07-20T08:44:00.260" Score="6" Body="&lt;p&gt;The order is arbitrary, but if you want to be compatible with physics textbooks then your notation is mostly set. The difference is that you seem to think that its more natural to observe the systen on the outside (and for graphics pipe devs its often so, not for modeler). For a mathematician it is more natural to think from local coordinates out. There are several reasons for this but mathematician seem to want to reduce this to functional form if you were to transform a value x through multiple functions you would get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;h(g(f(x))) &#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or sometimes&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;(h \circ g \circ f)(x)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This quite literary means transform x to f to g to h. So it is natural for a mathematician/physicist and some programmers to read the operations inside out simplybbecause this ties in better with the notation you were teached in early calculus. This way your operational order matches also other branches of mathematical notation. Since most math and physics textbooks take this approach you probably should too. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other reason is that your modeling elements lie on the outside of your data. But obviously you are free to transpose your vectors and then your order is opposite. It is up to you to define meaning to your math. This because there is  a rule that follows from how matrices are defined that states:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;(A \cdot B)^T = B^T \cdot A^T&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is easily shown that longer chains just reverse the entire chain by recursing this forumula.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is good to remeber that the order inside the vectors are arbitrary as well as calculation order. There is no reason for the vector to be defined in X, Y, Z, W order we could define the matrices and vectors in any order even a slightly cryptic X, W, Z, Y order. So rember the modeling convention is not somehow set in stone. Students would often want it to be, because that would mean not needing to understand as much, but it does not have to be. Matrices just enable you to model arbitrary vectors with unified math notation. &lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-07-20T09:15:21.853" LastActivityDate="2016-07-20T09:15:21.853" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3775" PostTypeId="1" AcceptedAnswerId="3777" CreationDate="2016-07-20T11:03:49.183" Score="8" ViewCount="251" Body="&lt;p&gt;&lt;br&gt;&#xA;In a recent version of uTorrent , if you open the &lt;strong&gt;About&lt;/strong&gt; Window, you will see an animated background , which is kind of waves that go on forever.&lt;br&gt;&#xA;How can this be achieved? Is this kind of a well-known algorithm/class of algorithms?&lt;br&gt;&#xA;Thanks.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/6us3F.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6us3F.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4770" LastEditorUserId="4770" LastEditDate="2016-07-20T11:29:55.937" LastActivityDate="2016-07-26T06:35:42.097" Title="What algorithm is used in the animation of the uTorrent 's &quot;About window&quot;?" Tags="&lt;algorithm&gt;&lt;shader&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3776" PostTypeId="2" ParentId="3775" CreationDate="2016-07-20T11:53:09.083" Score="2" Body="&lt;p&gt;After some searching, I found out it's called Plasma. &lt;br&gt;&#xA;&lt;a href=&quot;http://www.bidouille.org/prog/plasma&quot; rel=&quot;nofollow&quot;&gt;Plasma Effect&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4770" LastActivityDate="2016-07-20T11:53:09.083" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3777" PostTypeId="2" ParentId="3775" CreationDate="2016-07-20T12:24:45.157" Score="9" Body="&lt;p&gt;As you discovered and mentioned in your self-answer, the pattern in the background appears to be a sum of sinusoidal gradients.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the example linked to in your answer is more complicated than that used by µTorrent. The background of the About window appears to be a static pattern, rather than the animated sinusoidal pattern used in the plasma post.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Several sinusoidal gradients have been summed to give a single image, and the illusion of movement is given by simply cycling the colours in that one image, rather than generating a number of different images. This is most noticeable if you focus on the centre of one of the rings of colour. In the µTorrent pattern you will notice that each ring stays in one place, and has colour flowing either into it or out of it. In contrast, the rings of colour in the fully animated pattern move around, occasionally dividing or merging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simplified approach used by µTorrent is reminiscent of animations used in the past when recalculating the sinusoidal patterns each frame was not realistic.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-07-20T12:24:45.157" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3779" PostTypeId="1" AcceptedAnswerId="3785" CreationDate="2016-07-20T13:48:38.443" Score="7" ViewCount="957" Body="&lt;h1&gt;Question&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;How to manage data (GPU,CPU) for dynamic label placement in 3d for thousands of objects (OpenGL)?&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Details&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;objects:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;count:&lt;/strong&gt; 2k-10k&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;type:&lt;/strong&gt; points/quads&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;labels: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;bilboarding&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;data&lt;/strong&gt;: text and colors&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;placing:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;labels are not overlaping&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;more on this in my another &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/3765/proper-architecture-for-rendering-history-of-stramed-data-points&quot;&gt;question&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Elaboration&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To calculate label placing I need screen space coordinates. There are lots of algorithms for the purpose, but I do not even know if they are implementable (w/o some hard hacking) on shaders since Vertex Shader has access to only one vertex. But with many objects calculating matrix multiplication (MVP * vertex position) for all vertexes so as to get screen-space coordinates on CPU-side and sending them each frame seems to be fairly slow and badly designed, imo. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, should I:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;compute screen-space coordinates on CPU and send them to GPU so as to draw objects, compute label placing on CPU and send data to GPU&lt;/li&gt;&#xA;&lt;li&gt;send only vertice's word coordinates and calculate screen space coordinates on GPU, then somehow implement label placing on GPU&lt;/li&gt;&#xA;&lt;li&gt;Read the GPU-side calculated screen-side coordinates and compute on CPU&lt;/li&gt;&#xA;&lt;li&gt;something different&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I know that it depends on the load on CPU/GPU from other things, but what do you think?&lt;/p&gt;&#xA;" OwnerUserId="4765" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-07-27T20:18:15.097" Title="Label Placing for thousands of objects with OpenGL" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3780" PostTypeId="1" AcceptedAnswerId="3786" CreationDate="2016-07-20T19:10:42.160" Score="4" ViewCount="529" Body="&lt;p&gt;I am grabbing video from a web cam using Microsoft Media Foundation. The image data is in YUY2 format. The pixels are packed in a 4:2:2 ratio. The color format is YCbCr. The color data gets repeated 2x. Ex the packed pixel data is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;y0 u y1 v&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Gets unpacked to 2 pixels:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;y0 u v and y1 u v&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I want to use this data as an OpenGL texture. The question is: is there a way to pass this type of texture to &lt;code&gt;glTexImage2D&lt;/code&gt; as-is? Or do I need to unpack it first? I would like you keep the YCbCr color and convert to RGBA in a shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I know I can use OpenCV to get video - I've already done that. I am trying a more low level solution mostly as a learning experience).&lt;/p&gt;&#xA;" OwnerUserId="4497" LastEditorUserId="4497" LastEditDate="2016-07-27T14:22:20.687" LastActivityDate="2016-07-27T14:22:20.687" Title="Pixel packed texture source" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;pixels&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3783" PostTypeId="2" ParentId="3765" CreationDate="2016-07-22T16:58:36.673" Score="4" Body="&lt;p&gt;My advice would actually be to stick with solution 1 unless and until something more is needed. It's the simplest and easiest to understand, and it should be quite feasible to make it perform well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the one hand, it may seem wasteful to re-filter the points and re-upload a bunch of data to the VBO every frame. I guess that this is why you say it is a &quot;bad practice&quot;. But consider the total amount of data involved. An order-of-magnitude estimate shows that processing this amount of data every frame is not much work for a modern computer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;Point&lt;/code&gt; struct you quote looks like it's about 20 bytes (assuming that &lt;code&gt;p&lt;/code&gt; is 3 floats and &lt;code&gt;t&lt;/code&gt; is one float or int). With 50,000 points, the total size of the data is about 1 MB. Even if your actual data struct is a bit larger, still the total size of the data is only a few MB&amp;mdash;a small amount by today's standards. The time needed to process this amount of data on the CPU, and transfer it to the GPU, is on the order of ~0.1 ms. (Assuming ~20 GB/sec CPU bandwidth, and ~8 GB/sec PCIe transfer bandwidth.) So, this is an entirely reasonable amount of data to re-process each frame, and in fact you could handle many times more without stressing your system at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, just keep things simple and efficient for memory access:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Store the points in a big flat array (maybe using a ring buffer to allow new incoming points to overwrite old ones).&lt;/li&gt;&#xA;&lt;li&gt;Each frame, scan the points using a tight loop on the CPU, and copy the ones that pass the filter into the VBO.&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For best efficiency, probably you should use &lt;code&gt;GL_DYNAMIC_DRAW&lt;/code&gt; usage when you create the VBO, then use &lt;a href=&quot;http://docs.gl/gl3/glMapBufferRange&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;glMapBufferRange&lt;/code&gt;&lt;/a&gt; each frame and copy the filtered points directly into the mapped buffer.&lt;/li&gt;&#xA;&lt;li&gt;Use &lt;code&gt;GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT&lt;/code&gt; for the &lt;code&gt;access&lt;/code&gt; parameter to &lt;code&gt;glMapBufferRange&lt;/code&gt;; this will allow the GL driver to perform under-the-hood double-buffering to stream the data to the GPU efficiently. For more information on what's going on here, see &lt;a href=&quot;https://www.opengl.org/wiki/Buffer_Object_Streaming&quot; rel=&quot;nofollow&quot;&gt;Buffer Object Streaming&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Then unmap the buffer and issue the drawing commands, using a vertex shader to transform the points to screen-space as usual.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-07-22T17:08:40.300" LastActivityDate="2016-07-22T17:08:40.300" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3784" PostTypeId="2" ParentId="3757" CreationDate="2016-07-22T19:42:31.390" Score="16" Body="&lt;p&gt;There are  a couple of ways to answer this question: an algebraic way and a geometric way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Algebraically, we can identify the units that the BRDF must have by looking at its place in the rendering equation. The classic rendering equation is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_\text{outgoing}(\omega) = L_\text{emitted}(\omega) + \int_\Omega L_\text{incoming}(\omega') \, f_\text{BRDF}(\omega, \omega') \, (n \cdot \omega') \, d\omega'$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output value on the left is a radiance, so the result of the integral must also be a radiance. The integrand contains a radiance multiplied by a solid angle $d\omega'$, so something else in the integrand has to cancel out that factor of solid angle. The $n \cdot \omega'$ factor is dimensionless, and the only other thing there is the BRDF&amp;mdash;so to make the whole thing work out, the BRDF must have units of inverse solid angle. Equivalently, the BRDF can be seen as a ratio of radiance to irradiance, since they differ by a factor of solid angle in the denominator of radiance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way to see it is that the BRDF plays a role similar to a probability density. If you look at how probability densities work, they have units inverse to the volume of their domain. For instance, a 1D probability density has units of inverse length (probability per unit length, but probability itself is dimensionless), a 2D one has units of inverse area, and so on. The BRDF acts much like a probability density defined on the hemisphere, giving a likelihood for a photon coming in from a given direction to be reflected into some other direction. So, like any other probability density on a spherical domain, it has units of inverse solid angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Geometrically, we can get right down to brass tacks and take apart what's going on in the integral in the rendering equation. Recall that an integral means to subdivide the domain into tiny pieces and sum the integrand over all the pieces (in the limit as the pieces get infinitesimally small). Let's look at one such piece. The integrand should result in an infinitesimal amount of radiance $dL$, since we're going to sum over many pieces to arrive at a finite outgoing radiance. So a single infinitesimal piece of the integral looks like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$dL = L_\text{incoming} \, f_\text{BRDF} \, (n \cdot \omega') \, d\omega'$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we regroup the factors a bit, the combination $L_\text{incoming} \, (n \cdot \omega') \, d\omega'$ calculates the irradiance on the surface due to the light coming from the infinitesimal solid angle $d\omega'$. Since it's arriving from an infinitesimal amount of solid angle, it produces an infinitesimal irradiance $dE$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$dL = f_\text{BRDF} \, dE$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_\text{BRDF} = \frac{dL}{dE}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the BRDF acts as a proportionality constant between the infinitesimal irradiance arriving at the surface from an infinitesimal solid angle, and the infinitesimal outgoing radiance generated thereby. It couldn't be a ratio of radiances, because we have a &lt;em&gt;finite&lt;/em&gt; incoming radiance, and we need an &lt;em&gt;infinitesimal&lt;/em&gt; outgoing radiance if we want to sum up many pieces of the integral and get a finite result. To make that happen, the BRDF would have to be infinitesimal-valued, which...isn't a thing, in standard mathematics. :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope some of this helps. There are a variety of equivalent ways to look at this problem, as with so many things in math and physics.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-07-22T19:42:31.390" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3785" PostTypeId="2" ParentId="3779" CreationDate="2016-07-22T21:03:41.297" Score="6" Body="&lt;p&gt;Since you are new to computer graphics, you may be better off avoiding the complications of SIMD and sticking with the traditional 'create a CPU thread + collect results' approach, or even run in the main thread if the task is lightweight enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But if that approach fails to be performant and/or you are willing to dip into OpenCL / GLSL compute shaders, read on...&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This is a per-object calculation, not a per-vertex or fragment calculation, so the traditional graphics pipeline is not the best choice. That said, you could lead a vertex buffer with vertex positions at each object world position, then transform the vertices to screen space (see below) in the vertex shader, but considering you are dealing with OpenGL 3.3 you will probably be limited to writing the output label positions to textures via render to texture or transform feedback buffers which may be slow depending on the hardware. If you can use the shader image load store extension, it could help, but bending the graphics pipeline to GPGPU is all probably more work than it is worth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You have not detailed your overlap requirements (i.e., whether it must be perfect or approximate, overlap probability, whether you can guarantee sufficient screen room to achieve perfect non-overlap, whether you need all labels to be on visible screen at all times, etc.), but generally pairwise problems which can give non-convergent iterations when multiple particles are adjusted simultaneously are best done on a single thread on the CPU. It could be a dedicated CPU thread. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To understand what I mean by non-convergent iterations, imagine a grid of labels whose lower left and upper right corners touch. If they all are adjusted simultaneously in opposite directions of one neighbor, they may end up in a situation where they simply overlap their other neighbor. This cycle may repeat indefinitely since the corner overlaps are opposite. Whether this actually occurs depends on the specifics of the algorithm and the object positions / dimensions, but it is possible unless you can make some object spacing guarantees or some other assumption I am unaware of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have access to GLSL computer shaders or (even better) OpenCL, and you  do not demand perfect overlap, or predict that overlap will be relatively seldom, the following simple SIMD approach may outperform a single-threaded CPU approach.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;SIMD algorithm&lt;/strong&gt;: At the beginning of each frame (or whatever label update freq. makes sense), pass the object world positions, label dimensions, and camera projection + view transform to a per-object + label pair compute shader / kernel to calculate the screen space positions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vec4 objScreenSpacePosition = camera.projectionViewTransform * object.worldPosition;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now place the corresponding label somewhere nearby.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then place a sync fence in the shader / kernel to ensure all screen space positions have been calculated before proceeding. Finally, perform a pair-wise loop with all other labels and adjust the label position / depth to correct for overlap. You may need to repeat the loop multiple times until all labels have no overlap if you demand absolute assurance of zero overlap, or you could cutoff overlap adjustment after a certain number of iterations to ensure it doesn't take too long or run indefinitely (see above about non-convergence).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the adjustment loop is only adjusting the label its compute shader was assigned. To avoid position read/write race conditions, it is best to use a temporary position and fence every time you decide whether to continue the loop. Here is an example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 objectScreenPos = camera.projViewTrans * object[kernelIndex].worldPos;&#xA;&#xA;//...transform objectScreenPos to desired coordinate &#xA;// system if needed; either [0,1] or [-1,1] or whatever &#xA;// depending on your projViewTrans and needs of your &#xA;// overlap correction algorithm...&#xA;&#xA;label[kernelIndex].pos = objectScreenPos.xyz + someOffset;&#xA;&#xA;fence();&#xA;&#xA;bool overlap = true;&#xA;uint maxIters = 5;&#xA;vec3 tempPos = label[kernelIndex].pos;&#xA;for (uint numIters = 0; overlap &amp;amp;&amp;amp; numIters &amp;lt; maxIters; numIters++)&#xA;{&#xA;    for (each labelIndex)&#xA;    {   &#xA;        // Of course a label overlaps itself!&#xA;        if (labelIndex == kernelIndex)&#xA;            continue;&#xA;        // ...check overlap and adjust position of tempPos...  &#xA;    }&#xA;    label[kernelIndex].pos = tempPos;&#xA;    fence();&#xA;}   &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Of course avoiding fencing as much as possible and avoiding cross-kernel talk of any kind is ideal, but for this problem you can't completely avoid it. Still, I'd try turning off the fence in the loop and see what happens to perf and output. =)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are more clever overlap correction algorithms, most of which are approximate, but this one can in principle perfectly correct overlap and is simple to implement and understand.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;A GPGPU or even threaded CPU approach could actually be slower than performing a single-threaded calculation on the CPU, depending on the number of actual objects. This is why OpenCL is ideal for these sorts of problems: it gives you the option of running single or multi-threaded on CPU, or moving to the GPU. You could even switch between CPU and GPU on the fly if the number of objects radically changes over time and you can predict the change ahead of time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would probably write this in OpenCL since if all else fails, I could run it in a single thread on the CPU and come as close as possible to guaranteeing perfect non-overlap. Then I could experiment with multiple threads / GPU calculations and profile, profile, profile to my heart's content.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update - OpenGL 3.3 graphics pipeline approach&lt;/strong&gt;: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;While OpenCL or the OpenGL compute pipeline would be ideal, you should be able modify the above SIMD alg to use the OpenGL 3.3 core graphics pipeline with a bit of extra effort and likely perf loss. Example: During a point draw, pass object positions and IDs as vertex data to a vertex shader that calculates the object screen position. Set glPosition to the object ID and pass the resulting screen position to the fragment shader using the &lt;code&gt;flat&lt;/code&gt; modifier to prevent interpolation. Render the result to a 1D framebuffer with length equal to number of labels so that there is a 1:1 correspondence between 'pixel' (i.e. label) and vertex (i.e. object). You now have a 1D texture filled with label positions. You could then read this back to the CPU to perform overlap elimination (with possible guarantee of no overlap), then upload the updated label positions to OpenGL in a uniform buffer array, texture, or whatever works best in your situation. Alternatively you could launch a second vertex shader with label IDs as vertex attributes and perform a non-guaranteed overlap elimination which does not depend on the updated positions of the other labels, then follow a similar pattern from before to render the updated positions to a second 1D framebuffer, and finally use the related framebuffer texture as a label ID indexed lookup table during label rendering to determine the final positions of each of the four billboard corner vertices. The label ID could either be passed in using a uniform or vertex attribute.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hopefully you are beginning to see how much the GL 3.3 core graphics pipeline limits your options for GPGPU and how much more complicated it makes things. What was before a single compute shader or kernel gets broken into multiple shaders (and possibly multiple draws) where you must abuse the concepts of 'vertex' and 'pixel' to achieve your ends. Achieving good perf with this approach often requires a decent understanding of the graphics pipeline and hardware you are working with. Depending on the hardware, driver, and number of objects, the above graphics pipeline algorithm may not be able to beat simply calculating screen space coordinates and eliminating overlap on the CPU then uploading results to GPU. Hence the reason I suggest you either opt for OpenCL or OpenGL compute, or else stick with traditional CPU threading.&lt;/p&gt;&#xA;" OwnerUserId="58" LastEditorUserId="58" LastEditDate="2016-07-27T20:18:15.097" LastActivityDate="2016-07-27T20:18:15.097" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3786" PostTypeId="2" ParentId="3780" CreationDate="2016-07-22T21:46:50.497" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;The question is: is there a way to pass this type of texture to glTexImage2D as-is?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes; you can just pass it as-is, but (looking at &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glTexImage2D.xhtml&quot; rel=&quot;nofollow&quot;&gt;the docs&lt;/a&gt;) it is not supported directly.  You'll need a custom shader to &lt;em&gt;interpret&lt;/em&gt; it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on your needs, expanding the pixels first (or even doing the full conversion CPU-side) may be worthwhile.  At a guess, I'd say that expanding the pixels (as you copy from the camera's driver buffer into a staging buffer for upload to the GPU) is a pretty consistently good idea, unless you're extremely bandwidth-saturated.  I'd add the color-space conversion for easier debugging, or if the image doesn't update frequently.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2016-07-22T21:46:50.497" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3788" PostTypeId="1" AcceptedAnswerId="3789" CreationDate="2016-07-22T22:30:30.157" Score="7" ViewCount="203" Body="&lt;p&gt;It is pretty well known that writing depth in your fragment shader generally disables &quot;early Z&quot; test/write optimizations that modern GPUs rely on for fastness. Nonetheless, APIs still allow it and GPUs still provide support for correct visibility when shaders write arbitrary depth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is: are there any state of the art real-time effects in today's game engines that require writing Z in the fragment shader?&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-07-23T04:53:58.660" Title="What modern real-time rendering applications still use fragment shader depth writes / late-Z?" Tags="&lt;gpu&gt;&lt;rasterizer&gt;&lt;z-buffer&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3789" PostTypeId="2" ParentId="3788" CreationDate="2016-07-23T04:53:58.660" Score="10" Body="&lt;p&gt;Any techniques that involve raytracing in the fragment shader might want to write Z in order that the depth buffer contain an accurate representation of the raytraced surface. For example:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://iquilezles.org/www/articles/raymarchingdf/raymarchingdf.htm&quot;&gt;Distance-field ray marching&lt;/a&gt;, as seen in many shadertoys and demoscene productions. Here, only a full-screen quad gets rasterized, and all the geometry is generated by the fragment shader. Writing Z would be necessary if you want to use the depth buffer for deferred lighting or post-effects, or to composite distance fields with ordinary triangle geometry and get correct occlusion.&lt;/li&gt;&#xA;&lt;li&gt;Voxel ray marching, similar to the above. Even when the voxels are translucent (as in a smoke cloud or suchlike), it may be useful to write Z when the voxel density is high enough to become opaque; for instance, that can be useful for later motion blur / depth-of-field calculations.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-closer-look-at-parallax-occlusion-mapping-r3262&quot;&gt;Parallax occlusion mapping&lt;/a&gt; techniques, in which a flat surface is given the appearance of depth by ray-marching against a heightfield.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There are probably other similar cases where the shape of a surface is defined by the fragment shader rather than by the rasterized triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, newer APIs and GPUs include support for a &lt;a href=&quot;https://mynameismjp.wordpress.com/2010/11/14/d3d11-features/&quot;&gt;conservative depth output&lt;/a&gt; mode, in which the shader-written Z is only allowed to be greater-equal to the geometric Z, but not less. This allows early-Z / hierarchical-Z optimizations to still work based on the geometric Z: if the rasterized geometry gets culled for being behind something, then you know the shader-written Z would have been culled as well. This is a good fit for cases like the above, as you can rasterize some bounding geometry for the distance-field / voxel / heightfield object; then the actual depth will be greater-equal to that of the bounding geometry.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-07-23T04:53:58.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3791" PostTypeId="2" ParentId="3775" CreationDate="2016-07-26T06:09:08.703" Score="2" Body="&lt;p&gt;The effect can be roughly recreated by adding 2 (or more) radial sinusoids together and than animating the resulting phase through another sine function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Use www.shadertoy.com to verify.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;   {&#xA;       vec2 uv = fragCoord.xy / iResolution.xy;&#xA;       float d = sin(length(uv - vec2(0.5)) * 35.0) + sin(length(uv - vec2(0.2,0.3)) * 45.0);&#xA;       d = sin(d * 4.0 + iGlobalTime * 4.0)*0.5+1.0;&#xA;       fragColor = vec4(d,d,d,1.0);&#xA;   }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2016-07-26T06:35:42.097" LastActivityDate="2016-07-26T06:35:42.097" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3794" PostTypeId="2" ParentId="3746" CreationDate="2016-07-27T09:27:21.420" Score="4" Body="&lt;p&gt;Your shaders are fine, the problem is topological, that is the way the vertices are connected to create triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For cases 1 &amp;amp; 2: You cannot really draw a grid of points in this mode (&lt;code&gt;GL_TRIANGLE_FAN&lt;/code&gt;) as vertex 0 (the top left one) will be used in every triangle, as well as other issues. You should be using Triangle/Line strips, although these aren't so straightforward as some vertices are shared between each row.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, imagine you have vertices arranged like so:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;0 1 2&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;3 4 5&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;6 7 8&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You would draw strips by sending the above vertices in the following order:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;0,3,1 (outputs triangle 0,1,3)&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;4,    (outputs triangle 1,3,4)&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;2,    (outputs triangle 1,2,4)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;etc...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This you can do in code by scanning across 1 row of vertices and including the vertex on the next row for every other vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int numColumns = 5;   // As per your example..&#xA;int numRows = 5;&#xA;int vertexOffset = 0;&#xA;int vertexSize = 3;          // 3 floats per vertex&#xA;int nextRow = numColumns * vertexSize;   &#xA;&#xA;// This loop is for each row-strip, which requires 2 vertex rows..&#xA;for(int j = 0; j &amp;lt; numRows - 1; j++) {&#xA;&#xA;    // Inner loop sends vertices for each row-strip&#xA;    for(int n = 0; n &amp;lt; numColumns; n++, vertexOffset += vertexSize) {&#xA;       glVertex3fv(vertices + vertexOffset);            // Current row&#xA;       glVertex3fv(vertices + vertexOffset + nextRow);  // Row below&#xA;    }&#xA;    // This is special, we send a duplicate vertex to restart a new strip for the next row (This can be omitted if j == numRows - 1)&#xA;    glVertex3fv(vertices + vertexOffset - vertexSize + nextRow);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you are concerned about sending duplicate vertices you could use an additional index buffer, as that will allow you to use the exact same vertex buffer you used for the &lt;code&gt;GL_POINTS&lt;/code&gt; version.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="231" LastEditDate="2016-08-02T12:40:50.633" LastActivityDate="2016-08-02T12:40:50.633" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3795" PostTypeId="1" CreationDate="2016-07-28T05:39:38.747" Score="9" ViewCount="3331" Body="&lt;p&gt;So I just recently learned about the Compute Shader and it looks from what I have picked up the same idea as parallel programming you would do with CUDA or OpenCL, but in the shader pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I want to draw a million cubes in a scene should I be using one method over the other or both. If both how do you split that up so the GPU isn't trying to parallel compute both the shader and another process at the same time&lt;/p&gt;&#xA;" OwnerUserId="4820" LastActivityDate="2016-07-28T14:22:01.777" Title="Compute Shader vs CUDA/OpenCL" Tags="&lt;compute-shader&gt;&lt;opencl&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3796" PostTypeId="2" ParentId="3795" CreationDate="2016-07-28T14:22:01.777" Score="7" Body="&lt;p&gt;It's not quite correct, today, to think of compute shaders as being &quot;in the shader pipeline&quot; in the same sense that your vertex and fragment shaders are literally hooked up into a pipeline. Compute shaders are not &quot;hooked up&quot; to anything currently, cannot drive rasterization, or directly consume the outputs of rasterization. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What it allows you to do, though, is consume and produce memory resources also used by draw calls in a relatively efficient way. OpenCL makes this rather difficult (see for example &lt;a href=&quot;https://software.intel.com/en-us/articles/opencl-and-opengl-interoperability-tutorial&quot;&gt;https://software.intel.com/en-us/articles/opencl-and-opengl-interoperability-tutorial&lt;/a&gt;). This allows you to efficiently integrate compute &lt;em&gt;passes&lt;/em&gt; within your renderer, but it is not integrated into the rendering &lt;em&gt;pipeline&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-07-28T14:22:01.777" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3797" PostTypeId="1" CreationDate="2016-07-28T16:02:56.850" Score="10" ViewCount="239" Body="&lt;p&gt;AMD have recently been in the &lt;a href=&quot;http://arstechnica.com/gadgets/2016/07/amd-radeon-pro-ssg-graphics-card-specs-price-release-date/&quot;&gt;news&lt;/a&gt; with an interesting Radeon Pro board with a couple of M2 SSDs on it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As some of the more detailed stories (&lt;a href=&quot;https://semiaccurate.com/2016/07/25/amd-puts-massive-ssds-gpus-calls-ssg/&quot;&gt;here&lt;/a&gt; or &lt;a href=&quot;http://www.extremetech.com/extreme/232416-amd-announces-new-ssg-a-gpu-with-1tb-of-ssd-storage-attached&quot;&gt;here&lt;/a&gt;, for example) note, the benefits may principally accrue not from high bandwidth (the M2's are just on 4 PCIe lanes each, so the board's own 16 lane connector ought to have more) but from low latency.  &lt;a href=&quot;http://www.tomshardware.com/news/amd-radeon-ssg-1tb-gpu-memory,32325.html&quot;&gt;This story&lt;/a&gt; includes the claim &quot;this results in 10x lower memory access latency&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is basically: why should PCIe-connected SSDs on the GPU board have significantly less latency than the GPU accessing main system RAM or storage devices on the system PCIe bus?  What is it about the main system that &quot;gets in the way&quot; and means the on-board SSD's can be so much faster to access?&lt;/p&gt;&#xA;" OwnerUserId="4824" LastActivityDate="2016-08-03T05:56:53.610" Title="Why did AMD's putting an SSD on a GPU board reduce latency so much?" Tags="&lt;gpu&gt;&lt;performance&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3799" PostTypeId="1" AcceptedAnswerId="3800" CreationDate="2016-07-29T12:20:10.287" Score="1" ViewCount="80" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/j9ani.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j9ani.png&quot; alt=&quot;Equation 5.10 from Real Time Rendering book&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We will use $E_L$ for irradiance perpendicular to $l$&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Where $l$ is the light vector. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does this mean? How do I calculate $E_L$?&lt;/p&gt;&#xA;" OwnerUserId="4827" LastEditorUserId="231" LastEditDate="2016-07-29T13:06:35.380" LastActivityDate="2016-07-29T16:20:33.077" Title="What does $E_L$ mean in the context of shading equations from the book &quot;Real time rendering&quot;?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3800" PostTypeId="2" ParentId="3799" CreationDate="2016-07-29T16:20:33.077" Score="4" Body="&lt;p&gt;The line you quoted says it: $E_L$ is the incoming &lt;a href=&quot;https://en.wikipedia.org/wiki/Irradiance&quot; rel=&quot;nofollow&quot;&gt;irradiance&lt;/a&gt; at the surface due to the light source under consideration. Less technically, it's a vector representing the intensity and color of the incoming light at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The equation you mention is for a punctual light source (directional, point, or spot light), so in this case $E_L$ would simply be the user-defined RGB color of the light source, multiplied by any relevant attenuation factors—such as shadows, distance attenuation for point/spot lights, and cone angle attenuation for spot lights.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-07-29T16:20:33.077" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3801" PostTypeId="1" AcceptedAnswerId="3802" CreationDate="2016-07-29T21:46:08.980" Score="4" ViewCount="432" Body="&lt;p&gt;I have an array of color values. I have an interpolating parameter, &lt;code&gt;t&lt;/code&gt;, which varies from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't for the life of me figure out how to smoothly interpolate between these color values based on &lt;code&gt;t&lt;/code&gt;, such that I get a smooth blended color for any &lt;code&gt;t&lt;/code&gt; value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas? Its probably something simple that I am blanking out on.. &lt;/p&gt;&#xA;" OwnerUserId="4830" LastActivityDate="2016-07-29T23:18:36.603" Title="How can you interpolate over an array of say 5 colors?" Tags="&lt;color&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3802" PostTypeId="2" ParentId="3801" CreationDate="2016-07-29T23:18:36.603" Score="3" Body="&lt;p&gt;Say you have colors&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[c_1, c_2, c_3, c_4, c_5]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And $t$ values at which each color should be purely displayed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[t_1, t_2, t_3, t_4, t_5]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now your problem is given $t$ which color do I have to display?&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Find the t-values $t_i$ and $t_{(i+1)}$ between which $t$ lies.&lt;/li&gt;&#xA;&lt;li&gt;Calculate a 0 to 1 ratio where $t$ lies between them&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;$ param = (t - t_i) / (t_{(i+1)} - t_i) $&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;Interpolate the color via&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;$ c = param * c_i + (1-param) * c_{(i+1)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I haven't messed up something in my mind, this should work for any piecwise linear function, and not only if your $t_i$ values lie between 0 and 1.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-07-29T23:18:36.603" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3803" PostTypeId="1" CreationDate="2016-07-30T21:10:53.690" Score="3" ViewCount="1180" Body="&lt;p&gt;I'm learning OpenGL compute shaders and following &lt;a href=&quot;https://github.com/StanEpp/OpenGL_ParticleSystem&quot; rel=&quot;nofollow&quot;&gt;this guy's code&lt;/a&gt;, and I have stuff drawing, but not updating.  The particles are spread out in their starting positions, but they stay there.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Particle manager initialization&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ParticleManager::Init(unsigned int programId,&#xA;    unsigned int computeProgramId,&#xA;    unsigned int numParticles)&#xA;{&#xA;    ...reset all particles...&#xA;&#xA;    _unifLocDeltaTimeSec = glGetUniformLocation(_computeProgramId, &quot;uDeltaTimeSec&quot;);&#xA;&#xA;   _shaderBufferId = 0;&#xA;    glGenBuffers(1, &amp;amp;_shaderBufferId);&#xA;    glBindBuffer(GL_SHADER_STORAGE_BUFFER, _shaderBufferId);&#xA;    glBufferData(GL_SHADER_STORAGE_BUFFER, _allParticles.size() * sizeof(Particle), _allParticles.data(), GL_STATIC_DRAW);&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, _shaderBufferId);  &#xA;&#xA;    ...vertex array buffer and attribute array initialization...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Particle manager update&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ParticleManager::Update(float deltaTimeSec)&#xA;{&#xA;    glUseProgram(_computeProgramId);&#xA;    glUniform1f(_unifLocDeltaTimeSec, deltaTimeSec);&#xA;&#xA;    GLuint numWorkGroupsX = (_allParticles.size() / 128) + 1;&#xA;    GLuint numWorkGroupsY = 1;&#xA;    GLuint numWorkGroupsZ = 1;&#xA;    glDispatchCompute(numWorkGroupsX, numWorkGroupsY, numWorkGroupsZ);&#xA;&#xA;    glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);&#xA;&#xA;    glUseProgram(0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Particle manager render&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ParticleManager::Render()&#xA;{&#xA;    glUseProgram(_programId);&#xA;    glBindVertexArray(_vaoId);&#xA;    glDrawArrays(GL_POINTS, 0, _allParticles.size());&#xA;    glUseProgram(0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Compute shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440&#xA;&#xA;struct Particle&#xA;{&#xA;    vec2 _position;&#xA;    vec2 _velocity;&#xA;    int _isActive;&#xA;};&#xA;&#xA;layout (local_size_x = 128, local_size_y = 1, local_size_z = 1) in;&#xA;&#xA;layout (binding = 0) buffer ParticleBuffer {&#xA;    Particle AllParticles[];&#xA;};&#xA;&#xA;uniform float uDeltaTimeSec;     // self-explanatory&#xA;&#xA;void main()&#xA;{&#xA;    uint index = gl_GlobalInvocationID.x;&#xA;    Particle p = AllParticles[index];&#xA;&#xA;    vec2 deltaPosition = p._velocity * uDeltaTimeSec;&#xA;    p._position = p._position + deltaPosition;&#xA;&#xA;    AllParticles[index] = p;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I've looked through various forum posts (stack exchange, stack overflow, OpenGL forums) and read &lt;a href=&quot;http://antongerdelan.net/opengl/compute.html&quot; rel=&quot;nofollow&quot;&gt;at least one tutorial&lt;/a&gt; and followed another guy's github project (only allowed 2 links in a post), but I haven't been able to figure out why nothing moves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My top culprits are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Something in the compute shader's &quot;delta position&quot; is evaluating to 0.  &lt;/li&gt;&#xA;&lt;li&gt;The compute shader is not getting called.  &lt;/li&gt;&#xA;&lt;li&gt;The draw shader is not getting access to the compute shader's updated info.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Doubts:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I hard coded a change in position, so all particles should have moved some on every frame, and when that didn't work, I hard-coded a position, and that didn't work either, so the shader might not even be getting to main().&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;numWorkGroupsX&lt;/code&gt; evaluates to 79 (non-zero), so the compute shader should at least reach main().&lt;/li&gt;&#xA;&lt;li&gt;I called &lt;code&gt;glMemoryBarrier(...)&lt;/code&gt; with &lt;code&gt;GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT&lt;/code&gt;, so the vertex array buffer should have access to the updated info.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Also, no errors or warnings are reported during GLSL compilation or at runtime, so the computer is evidently happy with what I provided it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Help?  Why are my particles never moving beyond initialization?&lt;/p&gt;&#xA;" OwnerUserId="4838" LastActivityDate="2016-08-01T23:49:23.110" Title="Compute shader not updating buffer, or vertex buffer unable to read the updates" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3804" PostTypeId="1" AcceptedAnswerId="3806" CreationDate="2016-07-30T21:31:45.453" Score="7" ViewCount="1384" Body="&lt;p&gt;I'm writing my own TrueType font rasterizer as an exercise to improve my knowledge in computer graphics (along with a basic vector graphics engine). At this stage, I have implemented most of the TTF file parsing, decoding glyph outlines, scaling, and scan converting the outlines into a bitmap. &#xA;(I'm not doing any font hinting/grid fitting for the time being).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it comes to anti-aliasing the glyph bitmaps, what process or method is typically used (or best)? So far I have tried two methods. Bilinear filtering and setting the alpha value at the edges according to the pixel coverage of the outline. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bilinear sampling is too blurry to be effective in font rendering, and using pixel coverage is not continuous enough. Here are some images as reference of a lowercase Arial 'c' being rendered at 24 points: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Raw bitmap with no anti-aliasing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/w7CQD.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/w7CQD.png&quot; alt=&quot;Raw glyph with no anti-aliasing&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/T6m7H.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/T6m7H.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bilinear filtering:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1EteV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1EteV.png&quot; alt=&quot;Bilinear filtering&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7uACN.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7uACN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the same character rendered at the same size with a library (stb): &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kgEYF.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kgEYF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8tAM0.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8tAM0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally, here it is rendered as it would appear on OS X (using CoreText I presume):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UOgSC.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UOgSC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qs03k.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qs03k.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd be happy with whatever method is used by the stb library for my purposes.&lt;/p&gt;&#xA;" OwnerUserId="2507" LastActivityDate="2020-06-23T18:21:18.097" Title="What kind of anti-aliasing is used in font rasterization?" Tags="&lt;antialiasing&gt;&lt;font-rendering&gt;" AnswerCount="2" CommentCount="8" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3805" PostTypeId="1" CreationDate="2016-07-31T09:43:27.543" Score="1" ViewCount="517" Body="&lt;p&gt;Billboarding/impostors mean, roughly, representing complex 3D objects in 2D or with simple quadrilaterals, for the sake of LOD systems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the case of rendering a very numerous asteroid field where one base asteroid mesh is instanced X times. If none of the instances of the mesh are re-scaled, it is easy to replace them with a billboard/impostor: one should just generate a billboard or impostor for the base asteroid mesh and substitute each asteroid instance with an instance of the billboard/impostor when desired.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if each instance of the asteroid mesh that is present in the asteroid field is supposed to be re-scaled (e.g. to give the illusion of diversity to an asteroid field), this becomes much more complicated. Re-scaling a billboard quad of the base asteroid mesh, for instance, would not mimic the re-scaled instances of the asteroid mesh. At the same time, it is not clear whether using techniques like true-impostor would solve that any further.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, my question is: is there any impostoring technique that would allow that? I.e. pre-generating an impostor of the base asteroid mesh, then scaling each impostor's instance in a way that would mimic the re-scaling of the instances of the asteroid mesh?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been reading the recent literature on advanced billboarding/impostor techniques (true impostors, 3-view impostors, volumetric impostors, etc), but I am still confused about that.&lt;/p&gt;&#xA;" OwnerUserId="4840" LastActivityDate="2016-07-31T09:43:27.543" Title="Billboards or impostors when objects' instances are re-scaled" Tags="&lt;rendering&gt;&lt;performance&gt;&lt;optimisation&gt;" AnswerCount="0" CommentCount="2" ClosedDate="2016-08-20T12:50:53.267" ContentLicense="CC BY-SA 3.0" />
  <row Id="3806" PostTypeId="2" ParentId="3804" CreationDate="2016-07-31T21:56:45.207" Score="8" Body="&lt;p&gt;Sean Barrett, the author of the stb libraries, &lt;a href=&quot;http://nothings.org/gamedev/rasterize/&quot; rel=&quot;noreferrer&quot;&gt;wrote an article on how stb_truetype's rasterization works&lt;/a&gt;. It's quite readable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The article describes two methods of antialiasing, both based on scanline rasterization. In scanline rasterization, you iterate through the lines (rows) of pixels and keep track of which edges from the glyph outline are intersecting the scanline (considered as a mathematical zero-thickness line); then you can identify which pixel-centers are inside the outline by tracking enter/exit intersection points along that line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can do horizontal antialiasing by calculating partial pixel coverage, using the position of the intersection points relative to the pixel grid. For example, if you have an entering point at $x = 4.6$ on the current scanline, then pixel index 4 would be set to 60% empty and 40% covered. This sounds somewhat like what you tried to do. However, this doesn't help with vertical antialiasing since the scanline is still considered as a mathematical line with zero thickness. So, the article recommends to just supersample along the vertical axis: that is, process multiple &quot;scanlines&quot; spaced out vertically within each pixel row, and average the results together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second method performs both horizontal and vertical antialiasing at once, by evaluating the area of intersection of the glyph outline with each pixel square. It's still based on scanline rasterization, but now treats the scanline as a 1-pixel-tall rectangle and tracks all edges that touch the rectangle. To evaluate pixel coverage, the trapezoidal rule is used to calculate a signed area for each glyph edge—positive or negative depending on the edge's orientation—and these are summed up to give the total coverage area within the pixel square. (There are a lot more implementation details covered in the article, plus you can &lt;a href=&quot;https://github.com/nothings/stb/blob/master/stb_truetype.h&quot; rel=&quot;noreferrer&quot;&gt;read the source&lt;/a&gt;.) This is somewhat faster and more accurate than the supersampling method, though more difficult to implement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, it's important to consider whether you want gamma correction when rendering text (as with rendering anything else). Theoretically, the antialiased coverage values shouldn't be used directly as pixel values; they should be treated as an alpha, and used for linear-color-space blending between the background color and text color, followed by conversion to output gamma. However, in practice almost no one seems to do this; we're accustomed to seeing non-gamma-correct text, and screen fonts are designed to look good rendered this way. (Print fonts are another story.) On the other hand, if the text is animated, or rotated or not aligned with the pixel grid for any reason, gamma correction will help it look more consistent regardless of its placement relative to the pixel grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the choice of whether to apply gamma correction comes down to personal preference and the needs of the application. Either way, you may see artifacts such as the font appearing to get heavier or lighter depending on &lt;a href=&quot;https://twitter.com/rygorous/status/512371399542202368&quot; rel=&quot;noreferrer&quot;&gt;color&lt;/a&gt; and &lt;a href=&quot;https://www.freetype.org/freetype2/docs/text-rendering-general.html#back-to-stem-darkening&quot; rel=&quot;noreferrer&quot;&gt;font size&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-07-31T23:13:44.507" LastActivityDate="2016-07-31T23:13:44.507" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3807" PostTypeId="1" CreationDate="2016-07-31T23:18:14.897" Score="3" ViewCount="1938" Body="&lt;p&gt;My goal is to implement an edge detection algorithmus that is capable to find edges of arbitrary 3d meshes. I want to find the edges by detecting normal discontinuities. Furthermore, I want the edges to be one pixel wide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I render the color values of my scene and the corresponding normal vectors to two different render buffer targets, i.e. to two different textures (screenTexture and normalTexture).&#xA;I use the sobel edge detection algorithmus in my fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;out vec4 color;&#xA;&#xA;uniform sampler2D screenTexture;&#xA;uniform sampler2D normalTexture;&#xA;uniform sampler2D depthTexture;&#xA;&#xA;mat3 sx = mat3( &#xA;    1.0, 2.0, 1.0, &#xA;    0.0, 0.0, 0.0, &#xA;   -1.0, -2.0, -1.0 &#xA;);&#xA;mat3 sy = mat3( &#xA;   1.0, 0.0, -1.0, &#xA;   2.0, 0.0, -2.0, &#xA;   1.0, 0.0, -1.0 &#xA;);&#xA;&#xA;void main()&#xA;{&#xA;    vec4 diffuse = texelFetch(screenTexture, ivec2(gl_FragCoord), 0);&#xA;    vec3 normal = texelFetch(normalTexture, ivec2(gl_FragCoord), 0 ).xyz;&#xA;    vec3 I[3];&#xA;    for (int i=0; i&amp;lt;3; i++) {&#xA;        float sampleValLeft  = dot(normal, texelFetch(normalTexture, ivec2(gl_FragCoord) + ivec2(i-1,-1), 0 ).rgb);&#xA;        float sampleValMiddle  = dot(normal, texelFetch(normalTexture, ivec2(gl_FragCoord) + ivec2(i-1,0), 0 ).rgb);&#xA;        float sampleValRight  = dot(normal, texelFetch(normalTexture, ivec2(gl_FragCoord) + ivec2(i-1,1), 0 ).rgb);&#xA;        I[i] = vec3(sampleValLeft, sampleValMiddle, sampleValRight);&#xA;    }&#xA;&#xA;    float gx = dot(sx[0], I[0]) + dot(sx[1], I[1]) + dot(sx[2], I[2]); &#xA;    float gy = dot(sy[0], I[0]) + dot(sy[1], I[1]) + dot(sy[2], I[2]);&#xA;&#xA;    float g = sqrt(pow(gx, 2.0)+pow(gy, 2.0));&#xA;    g = smoothstep(0.4,0.8, g);&#xA;&#xA;    if(g &amp;gt; 0.2) {&#xA;        color = vec4(0., 0., 0.0, 1);&#xA;    } else {&#xA;        color = diffuse;&#xA;    }&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The shader produces the following result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XjsGs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XjsGs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the line thickness of the solids are not consistent: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Edges visible between the turquois background and the solid are 1px wide like&#xA;intended.&lt;/li&gt;&#xA;&lt;li&gt;Edges within the object are 2px wide which is too bride.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The reason why 1. works is because I initalized normalTexture with vec3(0,0,0) normal vectors which produces a dot-product of 0 as soon as the current pixel is a scene pixel and the adjacent right or left pixel is an edge pixel of the solid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But edges within the object are detected two times by sobel because of a gx or gy which is one time positive and one time negative. In other words, gx or gy is both times not 0 and therefore g is greater than 0.2 both of the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm totally stuck what I can do to produce consistent wide lines.&lt;/p&gt;&#xA;" OwnerUserId="3377" LastEditorUserId="3377" LastEditDate="2016-08-01T09:57:18.353" LastActivityDate="2016-08-01T12:14:06.147" Title="Sobel edge detection line thickness" Tags="&lt;edge-detection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3808" PostTypeId="1" AcceptedAnswerId="3811" CreationDate="2016-08-01T09:50:37.307" Score="0" ViewCount="487" Body="&lt;p&gt;VR rendering needs a lot of GPU power. VR SLI can help that. But, is it possible for us to use distributed parallel rendering technology to improve the performance dramatically? There is an open source software &quot;equalizer&quot; which could do that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, put 4 or 8 GPUs in one PC server and disable vender's SLI driver. Use equalizer to do parallel rendering. Or, run equalizer on 16 PC servers with GPU equipped. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So that we can get very high performance easily? Right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Equalizer supports sort-first and sort-last. Since sort-last needs a lot of network bandwidth, we'd better use sort-first.&lt;/p&gt;&#xA;" OwnerUserId="3058" LastActivityDate="2016-08-01T20:33:28.353" Title="Distributed parallel rendering in Gaming or VR rendering" Tags="&lt;rendering&gt;&lt;gpu&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3809" PostTypeId="1" CreationDate="2016-08-01T10:45:11.937" Score="3" ViewCount="287" Body="&lt;p&gt;I have rectangular matrix of 3d points sampled from a parametric surface. In my program this matrix provides base points for bilinear interpolation of surface (In any (u,v) point it returns 3d point interpolated from neighboring sampled values). Now I want to find closest point on surface from any other point in 3d space, considering values &quot;between&quot; sampled points of grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll attach picture with example on 2d curve. Here yellow points are sampled points, red point - point to which we want to find closest, and green - point which we need to find as closest (witness point). &lt;a href=&quot;https://i.stack.imgur.com/YKLGT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YKLGT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2644" LastEditorUserId="2644" LastEditDate="2016-08-01T18:12:38.467" LastActivityDate="2016-08-02T12:19:18.660" Title="Find closest point on surface interpolated by 2d matrix of points" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3810" PostTypeId="2" ParentId="3807" CreationDate="2016-08-01T11:58:01.420" Score="1" Body="&lt;p&gt;The edge between the sphere and the background is actually the one that is incorrect; you need to initialize your normal texture with a unit normal to get correct results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The two pixels thickness is a limitation of the Sobel based edge detection and other 3x3 convolution filters: you can only detect edges twice as big as your pixels. The &lt;a href=&quot;https://en.wikipedia.org/wiki/Roberts_cross&quot; rel=&quot;nofollow&quot;&gt;Robert operator&lt;/a&gt; uses a 2x2 convolution filter with weights making a cross, so it yields thinner edges but they are still thicker than one pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you absolutely want one pixel width, you could use filtered texture sampling and sample every half pixel when applying the Sobel operator, but the detection will probably miss some features.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-08-01T12:14:06.147" LastActivityDate="2016-08-01T12:14:06.147" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="3811" PostTypeId="2" ParentId="3808" CreationDate="2016-08-01T20:33:28.353" Score="5" Body="&lt;p&gt;You are essentially correct in assuming that it is technically feasible to distribute the rendering computation workload. It is, essentially, a computation workload like any other; possibly even better-suited for parallelization due to its very nature: many similarly structured units running the same code path (i.e. vertices, pixels).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you are forgetting, however, is latency. Having all the render power in the world is useless if the image does not arrive to the HMD fast enough not to cause discomfort to the user. Here is an article that explains the importance of motion-to-photon latency:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.chioka.in/what-is-motion-to-photon-latency/&quot;&gt;http://www.chioka.in/what-is-motion-to-photon-latency/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-08-01T20:33:28.353" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3812" PostTypeId="2" ParentId="3803" CreationDate="2016-08-01T23:49:23.110" Score="2" Body="&lt;p&gt;Got help from someone over in the &lt;a href=&quot;https://www.reddit.com/r/opengl/comments/4vdu02/need_help_with_a_compute_shader_new_to_compute/&quot; rel=&quot;nofollow&quot;&gt;OpenGL subreddit&lt;/a&gt;.  Apparently, as I trimmed the code for posting here and there, I changed the operation of the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I trimmed to this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    uint index = gl_GlobalInvocationID.x;&#xA;    Particle p = AllParticles[index];&#xA;&#xA;    vec2 deltaPosition = p._velocity * uDeltaTimeSec;&#xA;    p._position = p._position + deltaPosition;&#xA;&#xA;    AllParticles[index] = p;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Was more or less this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    uint index = gl_GlobalInvocationID.x;&#xA;    Particle p = AllParticles[index];&#xA;&#xA;    // update position&#xA;    vec2 deltaPosition = p._velocity * uDeltaTimeSec;&#xA;    deltaPosition = vec2(0.0f, 0.0f);&#xA;    //p._position = p._position + deltaPosition;&#xA;    p._position = deltaPosition;&#xA;&#xA;    AllParticles[index] = p;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which should have been this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    uint index = gl_GlobalInvocationID.x;&#xA;    Particle p = AllParticles[index];&#xA;&#xA;    // update position&#xA;    vec2 deltaPosition = p._velocity * uDeltaTimeSec;&#xA;    //deltaPosition = vec2(0.0f, 0.0f);&#xA;    p._position = p._position + deltaPosition;&#xA;    //p._position = deltaPosition;&#xA;&#xA;    AllParticles[index] = p;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So I really just did that.  The redditor who helped me downloaded my source code via github and found the error.  Standard case of one pair of eyes glossing over an error.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All is well now.&lt;/p&gt;&#xA;" OwnerUserId="4838" LastActivityDate="2016-08-01T23:49:23.110" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3813" PostTypeId="1" AcceptedAnswerId="3814" CreationDate="2016-08-02T06:06:04.130" Score="5" ViewCount="780" Body="&lt;h1&gt;Question&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Is there a way to compute something in a first shader program (eg. screen-space coordinates from word-space ones) and access those results in an another shader program? &lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Possible solutions&lt;/h1&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Give up multiple-shader-programs architecture and create one combined shader program&lt;/li&gt;&#xA;&lt;li&gt;Save somehow results to a buffer objects (I couldn't find out if this is possible except computation shaders)&lt;/li&gt;&#xA;&lt;li&gt;Render to texture and read the texture &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Is there a nicer solution?&lt;/p&gt;&#xA;" OwnerUserId="4765" LastEditorUserId="231" LastEditDate="2016-08-02T20:15:25.777" LastActivityDate="2017-10-01T21:57:57.203" Title="Sharing calculation result between shader programs in OpenGL" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;vertex-buffer-object&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3814" PostTypeId="2" ParentId="3813" CreationDate="2016-08-02T06:17:52.277" Score="3" Body="&lt;p&gt;Yes you can, this is how deferred rendering for example would work. For that you would render to a texture in one pass, in openGL this would be via an FBO, then feed that texture as the input to the next pass/shader.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2016-08-02T06:17:52.277" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3815" PostTypeId="2" ParentId="3809" CreationDate="2016-08-02T12:19:18.660" Score="2" Body="&lt;p&gt;This is only a rough idea, though I hope it may inspire better answers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The closest point on a surface is as far as I know always forms together with the red point a line that is orthogonal to the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you know which yellow vertices form the surface that the green point lies on, this is easy. You could just formulate the normal form of the surface (which is piecewise linear so it works out) formulate the orthogonal line to the surface that goes through the red point and solve for the intersection point. Though I don't have the exact math here, this step should be easy to look up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the problem is: Which linear piece of your surface is the closest one.&#xA;Either you calculate the green-point candidates for all linear pieces and also the distance and take the closest one, or you find some other possibly faster way for this.&#xA;For that I don't have a more clever idea.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-08-02T12:19:18.660" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3817" PostTypeId="2" ParentId="2271" CreationDate="2016-08-02T20:33:34.053" Score="2" Body="&lt;p&gt;I always feel gaming, particularly AAA gaming (e.g., FPS), is and will be the last application for cloud rendering, regardless being VR or not. VR simply makes the problem/requirement harder. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because of the tight loop of interactivity, latency is the the blocking factor as others have pointed out -- and we know that unlike bandwidth, latency is a much harder problem to solve practically in a commercial world. Though technically solvable (say deploying a group of game servers in every county, which is well within the Geo-boundary range of your back-of-envolop calculation above; also your matchmaking process needs to do the right player grouping), it really needs justifiable business case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said that, some non-AAA titles could well fall into cloud side rendering.&lt;/p&gt;&#xA;" OwnerUserId="4854" LastEditorUserId="4854" LastEditDate="2016-08-04T15:40:27.483" LastActivityDate="2016-08-04T15:40:27.483" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3818" PostTypeId="2" ParentId="3797" CreationDate="2016-08-03T05:56:53.610" Score="1" Body="&lt;p&gt;Answering from a somewhat layperson's perspective (I'm not a hardware expert, but I have built my own computer), I'll analogize, using the situation of getting some ingredients for cooking food.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &quot;main system&quot; RAM/storage is like you looking for an ingredient, not finding it in your cupboards, and, say, walking over to your neighbor and asking if they have any.  It turns out they do; they bring you it, you thank them and return to your house and use it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &quot;on board&quot; RAM/storage is like you looking for an ingredient, finding it in your cupboard, and using it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With on board RAM/storage, the GPU just has to do less work to obtain the information it needs.  The information is also simply closer, both physically and when considering the amount of hardware and software the information needs to go through.  With the on board RAM/storage, the GPU needs only look up where the information is, and then retrieve that information from RAM/storage, which then travels through maybe a couple inches of wire to the GPU's processing units.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With main system RAM/storage, there is a larger distance of wire for the signal to travel through which, although it may be only a minuscule fraction of a second, can still add up over thousands of calls to retrieve information.  Also, there are more potential bottlenecks, with all the different pieces that are interconnected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, with on board RAM/storage, AMD has the opportunity to optimize the system, since they're controlling precisely hardware is being used.  This is just like how Apple tailors Mac OS to its Mac computers.&lt;/p&gt;&#xA;" OwnerUserId="1870" LastActivityDate="2016-08-03T05:56:53.610" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3819" PostTypeId="1" CreationDate="2016-08-04T05:45:33.540" Score="1" ViewCount="70" Body="&lt;p&gt;There are material color and texture colors (e.g. &lt;code&gt;Kd 0.8 0.8 0.8&lt;/code&gt; vs. &lt;code&gt;map_Kd diff.png&lt;/code&gt;).  &lt;a href=&quot;http://paulbourke.net/dataformats/mtl/&quot; rel=&quot;nofollow&quot;&gt;The documentation&lt;/a&gt; says of this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;During rendering, the map_Kd value is multiplied by the Kd value.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;However, then there is a &lt;code&gt;decal&lt;/code&gt; command, which specifies a different relation:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;During rendering, the Ka, Kd, and Ks values and the map_Ka, map_Kd, and map_Ks values are blended according to the following formula:&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;result_color=tex_color(tv)*decal(tv)+mtl_color*(1.0-decal(tv))&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;where tv is the texture vertex.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;&quot;result_color&quot; is the blended Ka, Kd, and Ks values.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Essentially, this is saying that the &lt;code&gt;decal&lt;/code&gt; at a particular &lt;code&gt;(u,v)&lt;/code&gt; lerps between the texture at that &lt;code&gt;(u,v)&lt;/code&gt; and the material color.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;How does one reconcile these two different usages in the documentation?&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2016-08-04T05:45:33.540" Title="Alias|Wavefront .mtl File &quot;decal&quot; Command" Tags="&lt;texture&gt;&lt;material&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3823" PostTypeId="1" CreationDate="2016-08-05T16:25:40.423" Score="2" ViewCount="50" Body="&lt;p&gt;I'm working on a document storage project and i found a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After converting/compressing a scanned document to black &amp;amp; white sometimes, some areas of the document are unreadable because shadows are transformed to black chunks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to find out when this black chunks are present on the images?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the intuiton of this validation is to mark the file as unreadable to manual analisys.&lt;/p&gt;&#xA;" OwnerUserId="4866" LastActivityDate="2016-08-05T16:25:40.423" Title="detect blurred zones after conversion to black &amp; white" Tags="&lt;algorithm&gt;&lt;transformations&gt;&lt;optimisation&gt;&lt;blur&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3824" PostTypeId="1" AcceptedAnswerId="3832" CreationDate="2016-08-06T00:32:55.620" Score="5" ViewCount="69" Body="&lt;p&gt;I'm generalizing my texturing code, and have become confused by the frankly contradictory information about textures' pieces.  Specifically, &lt;strong&gt;I'm looking to understand what &lt;em&gt;exactly&lt;/em&gt; the terms &quot;face&quot;, &quot;layer&quot;, &quot;layer-face&quot;, and &quot;mipmap chain&quot; refer to&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I've put together an !ASCII-art diagram of what I think I understand for the example of a mipmapped cubemap array texture containing two cubemaps (&lt;a href=&quot;http://geometrian.com/programming/tutorials/gltextureterm/index.php&quot; rel=&quot;noreferrer&quot;&gt;from my site&lt;/a&gt;, reproduced poorly here):&lt;pre&gt;&#xA;                                                                                   &quot;Mipmap&quot; /&#xA;                                                         &quot;Layer-Face&quot;            &quot;Mipmap Chain&quot;&#xA;                                                         (or &quot;Image&quot;)              ┌────┴────┐&#xA;┌─ &quot;Texture&quot; (2D Cubemap Array) ──────────────────────────────┼────────────────────┼─────────┼──────────────────────────────────────────────┐&#xA;│ ┌─ &quot;Image Array&quot; / &quot;Layered Image&quot; / &quot;Mipmap Level&quot; ────────┼────────────────────┼─────────┼────────────────────────────────────────────┐ │&#xA;│ │ ┌─ &quot;Layer&quot; of Array ──────────────────────────────────────┼───────┐            │         │                                            │ │&#xA;│ │ │                                                    ┌────┴────┐  │            │         │                                            │ │&#xA;│ │ │   ╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗│╔═╦═╦═╦═╗│  │   ╔═╦═╦═╦═╗│╔═╦═╦═╦═╗│╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗ ╔═╦═╦═╦═╗     │ │&#xA;│ │ │   ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣│╠═╬═╬═╬═╣│  │   ╠═╬═╬═╬═╣│╠═╬═╬═╬═╣│╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣     │ │&#xA;│ │ │   ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣│╠═╬═╬═╬═╣│  │   ╠═╬═╬═╬═╣│╠═╬═╬═╬═╣│╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣     │ │&#xA;│ │ │   ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣│╠═╬═╬═╬═╣│  │   ╠═╬═╬═╬═╣│╠═╬═╬═╬═╣│╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣ ╠═╬═╬═╬═╣     │ │&#xA;│ │ │   ╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝│╚═╩═╩═╩═╝│  │   ╚═╩═╩═╩═╝│╚═╩═╩═╩═╝│╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝ ╚═╩═╩═╩═╝     │ │&#xA;│ │ │                                                    └─────────┘  │            │         │                                            │ │&#xA;│ │ └─────────────────────────────────────────────────────────────────┘            │         │                                            │ │&#xA;│ └────────────────────────────────────────────────────────────────────────────────┼─────────┼────────────────────────────────────────────┘ │&#xA;│         ╔═╦═╗     ╔═╦═╗     ╔═╦═╗     ╔═╦═╗     ╔═╦═╗     ╔═╦═╗           ╔═╦═╗  │  ╔═╦═╗  │  ╔═╦═╗     ╔═╦═╗     ╔═╦═╗     ╔═╦═╗         │&#xA;│         ╠═╬═╣     ╠═╬═╣     ╠═╬═╣     ╠═╬═╣     ╠═╬═╣     ╠═╬═╣           ╠═╬═╣  │  ╠═╬═╣  │  ╠═╬═╣     ╠═╬═╣     ╠═╬═╣     ╠═╬═╣         │&#xA;│         ╚═╩═╝     ╚═╩═╝     ╚═╩═╝     ╚═╩═╝     ╚═╩═╝     ╚═╩═╝           ╚═╩═╝  │  ╚═╩═╝  │  ╚═╩═╝     ╚═╩═╝     ╚═╩═╝     ╚═╩═╝         │&#xA;│                                                                                  │         │                                              │&#xA;│                                                                                  │         │                                              │&#xA;│                                                                                  │         │                                              │&#xA;│          ╔═╗       ╔═╗       ╔═╗       ╔═╗       ╔═╗       ╔═╗             ╔═╗   │   ╔═╗   │   ╔═╗       ╔═╗       ╔═╗       ╔═╗          │&#xA;│          ╚═╝       ╚═╝       ╚═╝       ╚═╝       ╚═╝       ╚═╝             ╚═╝   │   ╚═╝   │   ╚═╝       ╚═╝       ╚═╝       ╚═╝          │&#xA;│                                                                                  └─────────┘                                              │&#xA;└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘&#xA;&lt;/pre&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, I'd like corrections and additions to the above diagram, but if phrased as my key questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Where does &quot;face&quot; fit in?&lt;/li&gt;&#xA;&lt;li&gt;Is my &quot;layer-face&quot; description correct?  Or maybe it refers to all mip levels instead?&lt;/li&gt;&#xA;&lt;li&gt;Is my description of a &quot;layer&quot; correct?&lt;/li&gt;&#xA;&lt;li&gt;Similarly, does a &quot;mipmap chain&quot; refer to all mip levels of a single face, or to all mip levels of the layer?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="523" LastActivityDate="2016-08-08T04:23:40.170" Title="Texture Parts Terminology" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;terminology&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3825" PostTypeId="1" CreationDate="2016-08-06T09:09:51.730" Score="6" ViewCount="315" Body="&lt;p&gt;Given that I have implemented a function called &lt;code&gt;calc_bspline_surf()&lt;/code&gt; in C, and that function has the following declaration:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;calc_bspline_surf(ctrlnet, p, q, U, V, u, v)&#xA;/*&#xA;  ctrlnet --&amp;gt; control net of B-spline surface&#xA;  p, q --&amp;gt; degree of B-spline surface&#xA;  U, V --&amp;gt; the knots vector in two directions&#xA;  u, v --&amp;gt; parameter pair&#xA;*/&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So for a pair of parameters &lt;code&gt;{u, v}&lt;/code&gt;, corresponding B-spline surface coordinate could be generated via calling function &lt;code&gt;calc_bspline_surf(u, v)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a solution that sampling the 3D points uniformly in two direction&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for u = {0, 0.05, ..., 1}&#xA;    for v= {0, 0.05, ..., 1}&#xA;       calc_bspline_surf(u, v)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/6J4Vr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, how many 3D-points I need to sample? Is there classical sample strategy?&lt;/p&gt;&#xA;" OwnerUserId="1796" LastEditorUserId="1796" LastEditDate="2016-08-07T05:14:02.940" LastActivityDate="2016-08-08T04:15:03.340" Title="How to sample 3D points to visualize a B-spline surface?" Tags="&lt;sampling&gt;&lt;nurbs&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3826" PostTypeId="1" CreationDate="2016-08-06T19:01:49.183" Score="5" ViewCount="133" Body="&lt;p&gt;I am running this fragment shader on every pixel on screen. I am trying to make it as efficient as possible. BTW I am running open gl es 2.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code segment below is only a sample from the code, there are about 56 different calls to Gaussian() spread across different functions. I am wondering wether it would be valuable to replace the calls to Gaussian() with there appropriate resulting float value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know a lot of times stuff like this is pre-calculated on compilation of the shader, or calculated only once because the gpu realizes it is the same calculation for all fragments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So would it be worthwhile for me to manually calculate each of these and replace them with their values?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform float scalar;&#xA;varying float scalart;&#xA;float deviationScale = 1.2;&#xA;float finalScalar = 1.1;&#xA;float Gaussian(float x, float deviation)&#xA;{&#xA;    return (1.0 / sqrt(2.0 * 3.141592 * deviation)) * exp(-((x * x) / (2.0 * deviation)));&#xA;}&#xA;vec3 blurS5()&#xA;{&#xA;    vec3 blr = vec3(0.0);&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(2.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(2.0, 2.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(1.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(1.0, 2.0 * deviationScale) ;&#xA;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(0.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(0.0, 2.0 * deviationScale) ;&#xA;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-1.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-1.0, 2.0 * deviationScale) ;&#xA;    blr += texture2D(s_texture, (v_texcoord + vec2(-2.0 * scalart, 0.0))).xyz *  finalScalar * Gaussian(-2.0, 2.0 * deviationScale) ;&#xA;    return blr;&#xA;&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;        if (scalar == 2.)&#xA;        {&#xA;            gl_FragColor = vec4(blurS5(), 1.0);&#xA;        }&#xA;        else if (scalar == 3.)&#xA;        {&#xA;            gl_FragColor = vec4(blurS9(), 1.0);&#xA;        }&#xA;        //There are waaayyy more of these&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-08-09T23:14:06.840" Title="Will the gaussian kernels in this fragment shader be computed for every fragment?" Tags="&lt;shader&gt;&lt;fragment-shader&gt;&lt;gaussian-blur&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3827" PostTypeId="1" CreationDate="2016-08-06T21:36:21.350" Score="5" ViewCount="498" Body="&lt;p&gt;In order to naïvely render sprites, you can send single rectangles with their position, rotation, size, and texture. This is very easy, but given that reducing state changes, draw calls, and data uploads are good ways to improve rendering performance, it's clearly not an efficient solution.&#xA;Some techniques like passing each sprite as a single primitive and assembling a rectangle in the geometry shader are very appealing but aren't available if targeting a platform like WebGL or even just older hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On top of issues like batching and texture aliases, how do you efficiently submit geometry to render sprites?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm interested in answers that are rendering API agnostic, but using a specific API like OpenGL or Direct X is fine for illustration purposes.&lt;/p&gt;&#xA;" OwnerUserId="174" LastEditorUserId="174" LastEditDate="2016-08-07T18:13:29.600" LastActivityDate="2016-08-07T22:06:03.660" Title="Efficiently rendering sprites" Tags="&lt;rendering&gt;&lt;efficiency&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3828" PostTypeId="2" ParentId="3826" CreationDate="2016-08-07T12:03:08.463" Score="4" Body="&lt;p&gt;It depends. On a desktop, if the &lt;code&gt;Gaussian&lt;/code&gt; function is always called with the same arguments, the shader compiler will probably optimize it so it's evaluated only once. On a mobile platform though, the compiler has less time to do optimizations and might miss it. Either way, you can confirm by looking at the generated assembly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that Aras Pranckevičius of Unity wrote a GLSL optimizer to address the problem of sub-optimal compilers on mobile: &lt;a href=&quot;https://github.com/aras-p/glsl-optimizer&quot; rel=&quot;nofollow&quot;&gt;https://github.com/aras-p/glsl-optimizer&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, regarding your sample code, I would definitely at least expose &lt;code&gt;(1.0 / sqrt(2.0 * 3.141592 * deviation))&lt;/code&gt; as a uniform.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-08-07T12:03:08.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3829" PostTypeId="2" ParentId="3827" CreationDate="2016-08-07T22:06:03.660" Score="5" Body="&lt;p&gt;A good way to improve sprite rendering efficiency is &lt;a href=&quot;https://en.wikipedia.org/wiki/Geometry_instancing&quot;&gt;geometry instancing&lt;/a&gt;. This lets you define a mesh using one vertex/index buffer pair, then render many instances of that mesh in a single draw call using a second vertex buffer whose elements define the instances. This is more widely supported than geometry shaders; in particular, it's is supported in WebGL via the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/ANGLE_instanced_arrays&quot;&gt;ANGLE_instanced_arrays extension&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To apply this to sprites, one vertex buffer could define the shape of a sprite (i.e. a quad made of two triangles), then another vertex buffer could contain per-sprite information such as position, rotation, size, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there are 4 vertices per sprite and N sprites, the vertex shader will be called a total of 4N times, onces for each vertex in each sprite. You'd use the vertex shader to put the information from the two buffers together, transforming each vertex appropriately to the sprite's properties. This allows the GPU to do the work of generating all the vertices for the sprites, and saves on data uploaded from the CPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Coincidentally, I published a small &lt;a href=&quot;https://github.com/Reedbeta/gfx-workshops/&quot;&gt;OpenGL instancing demo&lt;/a&gt; recently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using instancing this way does require that all the sprites are drawn with the same state, i.e. the same shader, textures, blending mode and so on. If different states are needed for some sprites, a separate batch of instances will be needed for each state combination.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-07T22:06:03.660" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="3830" PostTypeId="1" CreationDate="2016-08-07T23:28:05.313" Score="3" ViewCount="239" Body="&lt;p&gt;I been looking for a way to do anti-aliasing with deferred rendering with WebGL as my target platform. WebGL does not support multisampled FBOs. I found FXAA implmentations such as this &lt;a href=&quot;https://github.com/mattdesl/glsl-fxaa/blob/master/fxaa.glsl&quot; rel=&quot;nofollow&quot;&gt;https://github.com/mattdesl/glsl-fxaa/blob/master/fxaa.glsl&lt;/a&gt; and it has the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifndef FXAA_REDUCE_MIN&#xA;    #define FXAA_REDUCE_MIN   (1.0/ 128.0)&#xA;#endif&#xA;#ifndef FXAA_REDUCE_MUL&#xA;    #define FXAA_REDUCE_MUL   (1.0 / 8.0)&#xA;#endif&#xA;#ifndef FXAA_SPAN_MAX&#xA;    #define FXAA_SPAN_MAX     8.0&#xA;#endif&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Im wondering what does these settings do and if I could tweak those settings to produce better results. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have implemented FXAA with the default settings and I found the image quality to be unsatisfactory. Is there other anti aliasing techniques I could try given the limitations of webgl platform? &lt;/p&gt;&#xA;" OwnerUserId="4874" LastActivityDate="2016-08-07T23:28:05.313" Title="What does these FXAA settings do?" Tags="&lt;webgl&gt;&lt;antialiasing&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3831" PostTypeId="2" ParentId="3825" CreationDate="2016-08-08T00:03:31.260" Score="3" Body="&lt;p&gt;Based on your linked question, the problem appears to be that you don't get enough samples in highly curved areas of the surface. You could increase the sample density everywhere, but then you oversample the flatter areas and it becomes too slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, you need to increase the sample density locally in areas where it's needed. A conceptually simple algorithm for this is adaptive refinement. You would start out with a uniform sample grid in UV space. Then, detect grid squares in which the curvature is too high for the grid spacing (above some threshold), and subdivide them, adding additional samples in between the existing ones. This process can be repeated recursively on the new, smaller grid squares, subdividing as finely as the surface requires. You can tune the curvature threshold to balance fidelity versus performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since B-splines (NURBS) are based on rational functions, I would guess that the maximum curvature in a region can be found (or at least bounded) analytically. This would be ideal, if possible, since it would avoid the problem of missing a small high-curvature area if none of the initial grid points happen to land in it. However, in a pinch the curvature can be estimated by looking at the sample points you've evaluated. For instance, if $p_1, p_2, p_3$ are three sample points collinear in UV space, they should be close to collinear as well, if the surface is adequately sampled. So, you could for instance evaluate&#xA;$$\frac{\|p_2 - p_1\| + \|p_3 - p_2\|}{\|p_3 - p_1\|}$$&#xA;where the double bars mean vector length. If this is greater than some threshold value such as 1.1 or 1.5 (note that 1.0 would be perfectly flat), then you would subdivide the area between these points.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-08-08T04:15:03.340" LastActivityDate="2016-08-08T04:15:03.340" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3832" PostTypeId="2" ParentId="3824" CreationDate="2016-08-08T04:23:40.170" Score="3" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;A &amp;quot;face&amp;quot; simply specifies one of the six images at a level in a cubemap (and its optional mip pyramid).&lt;/p&gt;&#xA;&lt;p&gt;It is helpful to think of level L of your mipmapped cube array texture as consisting of a 2D array of images, with exactly six columns comprising the six faces of the logical cube, and the N rows corresponding to the N layers of the array (some APIs call these &amp;quot;slices&amp;quot;). This is because non-array Cube textures are already structured like 2D arrays with exactly 6 layers.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;This is correct with the exception that it would refer to the entire mip pyramid for that layer-face. Regarding the 2D array of faces and layers i just mentioned, OpenGL uses a single index for this 2d array, &amp;quot;unrolls&amp;quot; it, and calls this 1D index a &amp;quot;layer-face&amp;quot;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Yes, but again, encompasses the mip pyramids for each layer-face image in that layer&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Depends on the context, could be either.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="3386" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-08-08T04:23:40.170" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3833" PostTypeId="1" AcceptedAnswerId="3882" CreationDate="2016-08-08T06:28:44.883" Score="3" ViewCount="729" Body="&lt;p&gt;The rough definition of &lt;em&gt;&quot;MTP&quot;&lt;/em&gt; is clear. But the exact one is not. You can refer to these links:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.chioka.in/what-is-motion-to-photon-latency&quot; rel=&quot;nofollow noreferrer&quot;&gt;What is Motion-To-Photon Latency? | chioka.in&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://xinreality.com/wiki/Motion-to-photon_latency&quot; rel=&quot;nofollow noreferrer&quot;&gt;Motion-to-photon latency | xinreality.com/wiki&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;But from different online articles, we get different definitions regarding how the value is measured:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;From &lt;a href=&quot;https://developer.oculus.com/blog/optimizing-vr-graphics-with-late-latching&quot; rel=&quot;nofollow noreferrer&quot;&gt;Atman Binstock (Oculus) blog&lt;/a&gt;, we can see:&lt;br/&gt;&#xA;&lt;code&gt;MTP = T2(time to flip) - T1(Time of PO)&lt;/code&gt;.&lt;br/&gt;&#xA;But, &lt;code&gt;T2&lt;/code&gt; is just beginning to display the image, not finish displaying.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;From &lt;a href=&quot;http://www.chioka.in/what-is-motion-to-photon-latency/&quot; rel=&quot;nofollow noreferrer&quot;&gt;John Carmack (Oculus) blog&lt;/a&gt;:&lt;br/&gt;&#xA;&lt;code&gt;MTP = T2(finish displaying) - T1(Time of PO)&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;From Alex Vlachos (Valve) slides: &lt;em&gt;Advanced VR Rendering&lt;/em&gt;, GDC 2015:&lt;br/&gt;&#xA;&lt;code&gt;MTP = T2(finish displaying) - T1(Time of PO)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;From &lt;a href=&quot;http://www.qualcomm.cn/news/blog-2016-07-20&quot; rel=&quot;nofollow noreferrer&quot;&gt;Qualcomm blog&lt;/a&gt; (sorry it is in Chinese):&lt;br/&gt;&#xA;&lt;code&gt;MTP = T2(half of finish displaying) - T1(Time of PO)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I think Qualcomm's explanation is the best. If it is correct, we can relax the rendering time budget. What is your opinion?&lt;/p&gt;&#xA;" OwnerUserId="3058" LastEditorUserId="209" LastEditDate="2018-03-23T08:48:30.360" LastActivityDate="2018-03-23T08:48:30.360" Title="What is the definition of &quot;motion to photon&quot; in VR?" Tags="&lt;rendering&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3834" PostTypeId="1" AcceptedAnswerId="3835" CreationDate="2016-08-08T17:27:27.653" Score="3" ViewCount="568" Body="&lt;p&gt;I am a newbie in computer graphics and I am trying to develop a special case of path tracing really slowly! But first: I came up studying the Mitsuba renderer and one of its uses in the so-called GDPT (Gradient Domain Path Tracer). I am trying to build a Cornell Box in this framework and my silly problem arises in realizing which kind of material is a &quot;mirror&quot;. In simpler words: I want a mirroring sphere in my scene but I don't manage to create it. According to the documentation that you can find here (&lt;a href=&quot;http://www.mitsuba-renderer.org/releases/current/documentation.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.mitsuba-renderer.org/releases/current/documentation.pdf&lt;/a&gt;) we can have all the different surfaces explained in section 8.2, which are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Smooth Diffuse material (diffuse)&lt;/li&gt;&#xA;&lt;li&gt;Rough diffuse material (roughdiffuse) &lt;/li&gt;&#xA;&lt;li&gt;Smooth dielectric material (dielectric)&lt;/li&gt;&#xA;&lt;li&gt;Thin dielectric material (thindielectric)&lt;/li&gt;&#xA;&lt;li&gt;Rough dielectric material  (roughdielectric)&lt;/li&gt;&#xA;&lt;li&gt;Smooth conductor (conductor)&lt;/li&gt;&#xA;&lt;li&gt;Rough conductor material (roughconductor)&lt;/li&gt;&#xA;&lt;li&gt;Smooth plastic material (plastic)&lt;/li&gt;&#xA;&lt;li&gt;Rough   plastic material (roughplastic)&lt;/li&gt;&#xA;&lt;li&gt;Smooth dielectric coating (coating)&lt;/li&gt;&#xA;&lt;li&gt;Rough dielectric coating (roughcoating)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Can you please help me understand what set of parameters will make a mirroring surface material?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually for each kind of material there is a reference XML code (which is what I am using to build the scene). Therefore, the main question remains understanding how to build a mirror, but please take those examples in considerations because the parameters in those are the only things I can tune. Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="3069" LastEditorUserId="182" LastEditDate="2017-05-26T05:22:25.380" LastActivityDate="2017-05-26T05:22:25.380" Title="How to create specular surface in Mitsuba Renderer" Tags="&lt;rendering&gt;&lt;specular&gt;&lt;subsurface-scattering&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3835" PostTypeId="2" ParentId="3834" CreationDate="2016-08-08T20:45:30.130" Score="6" Body="&lt;p&gt;You want to use the &quot;conductor&quot; plugin to create a smooth conductor / metal type BRDF. See section 8.2.6 in the documentation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as Mitsuba is concerned, a mirror is a special instance of a metal, where the material is specified as &quot;none&quot; (which corresponds to using complex IOR of $ \eta = 0 $ and $ k = 1 $).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example in xml:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;shape type=&quot;...&quot;&amp;gt;&#xA;    &amp;lt;bsdf type=&quot;conductor&quot;&amp;gt;&#xA;        &amp;lt;string name=&quot;material&quot; value=&quot;none&quot;/&amp;gt;&#xA;    &amp;lt;/bsdf&amp;gt;&#xA;&amp;lt;shape&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1930" LastActivityDate="2016-08-08T20:45:30.130" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="3836" PostTypeId="2" ParentId="2450" CreationDate="2016-08-08T21:12:17.303" Score="3" Body="&lt;p&gt;Just in case anyone elso also needs to detect edges: &#xA;&lt;a href=&quot;http://strattonbrazil.blogspot.de/2011/09/single-pass-wireframe-rendering_10.html&quot; rel=&quot;nofollow&quot;&gt;Here&lt;/a&gt; is a nice article how to display a wireframe and &lt;a href=&quot;http://strattonbrazil.blogspot.de/2011/09/single-pass-wireframe-rendering_11.html&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt; article explains how to show only the edges.&lt;/p&gt;&#xA;" OwnerUserId="3377" LastActivityDate="2016-08-08T21:12:17.303" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3837" PostTypeId="1" AcceptedAnswerId="3838" CreationDate="2016-08-09T17:58:59.387" Score="4" ViewCount="103" Body="&lt;p&gt;I'm doing a direct implementation of DLT algorithm but I can't figure out why, at the end the matrix H I get doesn't (even remotely) produce x2 = H*x1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm is not that complicated so I can't see what I'm missing at this stage.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;%%point matching section (manual for now)&#xA;&#xA;% point selection &#xA;&#xA;[originalpoints1, normpoints1, translation1, scaling1 ]= pointprocessing(rootimage, false);&#xA;[originalpoints2, normpoints2, translation2, scaling2 ]= pointprocessing(sideimage, true);&#xA;&#xA;if(length (originalpoints1) ~= length (originalpoints2))&#xA;    error('points must be referenced in both images');&#xA;end&#xA;&#xA;%% DLT transform application&#xA;&#xA;% getting A&#xA;i = 1;&#xA;A = zeros(2*length(originalpoints1), 9);&#xA;while(i &amp;lt;= length(normpoints1))&#xA;    x1 = normpoints1(1,i);&#xA;    y1 = normpoints1(2,i);&#xA;    w1 = normpoints1(3,i);&#xA;&#xA;    x2 = normpoints2(1,i);&#xA;    y2 = normpoints2(2,i);&#xA;    w2 = normpoints2(3,i);&#xA;&#xA;    a1 = - w2 * (normpoints1(:,i)');  &#xA;    a2 =   y2 * (normpoints1(:,i)');&#xA;    a3 =   w2 * (normpoints1(:,i)');&#xA;    a4 = - x2 * (normpoints1(:,i)');&#xA;    z = zeros(1,3);&#xA;&#xA;    a = [z a1 a2; a3 z a4];&#xA;&#xA;    A(2*i-1, :) = a(1, :);&#xA;&#xA;    A(2*i, :) = a(2, :);&#xA;&#xA;    i = i + 1;&#xA;end&#xA;&#xA;% getting H&#xA;&#xA;[U D V] = svd(A);&#xA;&#xA;h = V(:, end);&#xA;&#xA;normH = reshape(h, 3, 3)';&#xA;&#xA;% denormalization&#xA;&#xA;T1 = scaling1 * translation1;&#xA;&#xA;T2 = scaling2 * translation2;&#xA;&#xA;H = inv(T2) * normH * T1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The normalizing process works as intended - I've double checked, performs the translation and scaling (none on Z) as intended. But for clarity sake here that one also:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function [ originalpoints, normpoints, translation, scaling ] = pointprocessing( image, flag )&#xA;&#xA;% point selection &#xA;&#xA;figure(1);&#xA;imshow(image);&#xA;axis on;&#xA;if (~flag)&#xA;    title('select n &amp;gt;= 4 reference points, double click last');&#xA;else&#xA;    title('mark the same reference points (same order), double click last');&#xA;end&#xA;&#xA;[x, y] = getpts();&#xA;&#xA;close(1);&#xA;&#xA;if(length (x) &amp;lt; 4 || length (y) &amp;lt; 4)&#xA;    error('selected too few points');&#xA;end&#xA;&#xA;% coordinate conversion  - centroid calculation&#xA;&#xA;center_x = mean(x);&#xA;&#xA;center_y = mean(y);&#xA;&#xA;originalpoints  = [x'; y'; ones(1, length (x))];&#xA;&#xA;% coordinate conversion - apply the translation&#xA;&#xA;translation = [1 0 -center_x; 0 1 -center_y; 0 0 1];&#xA;&#xA;translatedpoints = translation * originalpoints;&#xA;&#xA;% coordinate conversion - apply isotropic scaling&#xA;&#xA;goal = sqrt(2);&#xA;&#xA;heuristic = meandistance(translatedpoints);&#xA;&#xA;if(heuristic &amp;lt; goal)&#xA;    error('average distance between points too (1 pixel) small? double check')&#xA;end&#xA;&#xA;scaling_factor = (length(translatedpoints) * goal) / adaptedmeandistance(translatedpoints); &#xA;&#xA;scaling = [scaling_factor 0 0; 0 scaling_factor 0; 0 0 1];&#xA;&#xA;normpoints = scaling * translatedpoints;&#xA;&#xA;&#xA;end&#xA;&#xA;function [sum] = adaptedmeandistance(point_matrix)&#xA;&#xA;%assumes &amp;gt; 3 points &#xA;i = 1;&#xA;sum = 0;&#xA;while (i &amp;lt;= length(point_matrix))&#xA;    sum = sum + abs(realsqrt( point_matrix(1,i)^2 + point_matrix(2,i)^2));&#xA;    i = i + 1;&#xA;end&#xA;end&#xA;&#xA;function [distance] = meandistance(point_matrix)&#xA;&#xA;%assumes &amp;gt; 3 points &#xA;i = 1;&#xA;sum = 0;&#xA;while (i &amp;lt;= length(point_matrix))&#xA;    sum = sum + euclidian(point_matrix(1,i), point_matrix(2,i), 0, 0);&#xA;    i = i + 1;&#xA;end&#xA;distance = sum / length(point_matrix);&#xA;&#xA;end&#xA;&#xA;function [distance] = euclidian(point1_x, point1_y, point2_x, point2_y)&#xA;&#xA;    distance = abs(realsqrt( (point1_x - point2_x)^2 + (point1_y - point2_y)^2));&#xA;&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The issue is that I get, for instance, an H of &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.4787    0.0051  186.8102&#xA;0.0702    0.4762  144.1276&#xA;0.0000    0.0000    0.4514&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Transforming originalpoints1&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   1.0e+03 *&#xA;&#xA;    0.1465    2.3465    2.3465    0.1985&#xA;    0.1545    0.1345    3.0545    3.0945&#xA;    0.0010    0.0010    0.0010    0.0010&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;into something,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   1.0e+03 *&#xA;&#xA;    0.2577    1.3108    1.3257    0.2976&#xA;    0.2280    0.3729    1.7634    1.6316&#xA;    0.0005    0.0006    0.0007    0.0006&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;that's not originalpoints2&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   1.0e+03 *&#xA;&#xA;    0.5545    2.2865    1.9265    0.5105&#xA;    0.4905    0.6505    2.5625    2.7985&#xA;    0.0010    0.0010    0.0010    0.0010&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem might be on the scale, should I manually enforce the scale of each point to 1? Doesn't that mean there's something wrong with H?&lt;/p&gt;&#xA;" OwnerUserId="4735" LastActivityDate="2016-09-08T18:27:29.033" Title="DLT algorithm (4+ points) not working, what's missing?" Tags="&lt;image-processing&gt;&lt;matlab&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3838" PostTypeId="2" ParentId="3837" CreationDate="2016-08-09T18:08:38.317" Score="3" Body="&lt;p&gt;Just realized that this is an equation involving homogeneous vectors; thus the 3-vectors should not equal, they have the same direction but may differ in magnitude by a nonzero scale factor. &lt;/p&gt;&#xA;" OwnerUserId="4735" LastActivityDate="2016-08-09T18:08:38.317" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3839" PostTypeId="2" ParentId="3826" CreationDate="2016-08-09T23:14:06.840" Score="2" Body="&lt;p&gt;The shader compiler will very likely perform common-subexpression consolidation, and compute that function once, and reuse it each time it appears in the shader. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might think that, since &lt;code&gt;deviationScale&lt;/code&gt; and all the other args are constants, it is possible it gets constant-folded entirely and never executes at runtime at all. But this is incorrect, as sqrt() and exp() are not compile-time constexpr functions.  The compiler cannot assume any specific implementation (and associated numerical properties) of these math functions, and so the entire function will not get optimized out, and it will not get re-used across threads either, as this is precluded by the shading language's programming model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your best move is to pre-calculate the entire expression and stash it in a uniform, if it is important that this be optimal.&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2016-08-09T23:14:06.840" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3840" PostTypeId="1" AcceptedAnswerId="3841" CreationDate="2016-08-10T01:56:35.487" Score="7" ViewCount="350" Body="&lt;p&gt;I'm attempting to perform an intersection test using ray casting (not sure if correct term so please forgive me if not) and am outputting the intersections as a point cloud, and the point cloud shows curvature (on the Z-axis only, the point cloud is completely flat on the Y axis, and the horizontal axis in this image is the X axis):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Wd9OX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wd9OX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I borrowed concepts from the Scratchapixel site, specifically &lt;a href=&quot;http://scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-box-intersection&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Essentially, I am generating 16 rays, all with the same origin vector.  The direction vectors start at +15 degrees on the YZ plane, and continue in increments of -2 degrees down to -15.  I have an axis aligned bounding box that I am testing intersection with.  I use a rotation transform to rotate the 16 rays CCW around the Z axis.  I am performing the intersection test for all 16 rays each 0.1 degrees, and if it returns true, I add the point to the point cloud.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my intersection code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool test_intersect(Box b, Ray r, Vec3f&amp;amp; intersect_point)&#xA;{&#xA;    float txmin = 0.0f, txmax = 0.0f, tymin = 0.0f, tymax = 0.0f, tzmin = 0.0f, tzmax = 0.0f;&#xA;    float t_min = 0.0f, t_max = 0.0f, t = 0.0f;&#xA;&#xA;    // Determine inverse direction of ray to alleviate 0 = -0 issues&#xA;    Vec3f inverse_direction(1 / r.direction.x, 1 / r.direction.y, 1 / r.direction.z);&#xA;&#xA;    // Solving box_min/box_max0 = O + Dt &#xA;    txmin = (b.box_min.x - r.origin.x) * inverse_direction.x;&#xA;    txmax = (b.box_max.x - r.origin.x) * inverse_direction.x;&#xA;    tymin = (b.box_min.y - r.origin.y) * inverse_direction.y;&#xA;    tymax = (b.box_max.y - r.origin.y) * inverse_direction.y;&#xA;    tzmin = (b.box_min.z - r.origin.z) * inverse_direction.z;&#xA;    tzmax = (b.box_max.z - r.origin.z) * inverse_direction.z;&#xA;&#xA;    // Depending on direction of ray tmin may &amp;gt; tmax, so we may need to swap&#xA;    if (txmin &amp;gt; txmax) std::swap(txmin, txmax);&#xA;    if (tymin &amp;gt; tymax) std::swap(tymin, tymax);&#xA;    if (tzmin &amp;gt; tzmax) std::swap(tzmin, tzmax);&#xA;&#xA;    t_min = txmin;&#xA;    t_max = txmax;&#xA;&#xA;    // If t-value of a min is greater than t-value of max,&#xA;    // we missed the object in that plane.&#xA;    if ((t_min &amp;gt; tymax) || (tymin &amp;gt; t_max))&#xA;        return false;&#xA;&#xA;    if (tymin &amp;gt; t_min)&#xA;        t_min = tymin;&#xA;    if (tymax &amp;lt; t_max)&#xA;        t_max = tymax;&#xA;&#xA;    if ((t_min &amp;gt; tzmax) || (tzmin &amp;gt; t_max))&#xA;        return false;&#xA;&#xA;    if (tzmin &amp;gt; t_min)&#xA;        t_min = tzmin;&#xA;    if (tzmax &amp;lt; t_max)&#xA;        t_max = tzmax;&#xA;&#xA;    if (t_min &amp;gt; 0)&#xA;        t = t_min;&#xA;    else&#xA;        if (t_max &amp;gt; 0)&#xA;            t = t_max;&#xA;        else&#xA;            return false;&#xA;&#xA;    intersect_point.x = r.origin.x + r.direction.x * t;&#xA;    intersect_point.y = r.origin.y + r.direction.y * t;&#xA;    intersect_point.z = r.origin.z + r.direction.z * t;&#xA;&#xA;    return true;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And my rotation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Rotation around z axis, for rotating array and checking beam intersections&#xA;void transform_rotate_z(Vec3f&amp;amp; in_vector, float angle)&#xA;{&#xA;    float radians = angle * (M_PI / 180);&#xA;&#xA;    float result_x = cos(radians) * in_vector.x + -sin(radians) * in_vector.y;&#xA;    float result_y = sin(radians) * in_vector.x + cos(radians) * in_vector.y;&#xA;    in_vector.x = result_x;&#xA;    in_vector.y = result_y;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have racked my brain for quite a while but I can't seem to determine how I can prevent this curvature, I'm sure I'm overlooking something simple.  I'd be grateful for any help you can provide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 9/18/16:  It turned out that I had incorrectly believed that physical LIDAR units had some algorithmic way of &quot;straightening&quot; out the curves, which is not the case!  The output is supposed to look like the picture above.&lt;/p&gt;&#xA;" OwnerUserId="4886" LastEditorUserId="4886" LastEditDate="2016-09-19T01:53:01.020" LastActivityDate="2016-09-19T01:53:01.020" Title="Ray casting in fan configuration produces point cloud with curvature, how to eliminate curvature?" Tags="&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3841" PostTypeId="2" ParentId="3840" CreationDate="2016-08-10T04:18:41.373" Score="9" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;The direction vectors start at +15 degrees on the YZ plane, and continue in increments of -2 degrees down to -15.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There's your problem—by generating the rays that way, you're doing something more like a spherical projection or fisheye projection, not a linear perspective projection. The nonlinear projection is the origin of the curvature you see.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get a perspective projection instead, conceptually the way to think about it is that there's an image rectangle floating in front of the camera, divided into grid squares (pixels), and you fire a ray from the camera position toward the center of each pixel. In code, this looks something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;p = tan(horizontalFOV / 2)&#xA;q = tan(verticalFOV / 2)&#xA;for y = 0 to imageHeight - 1&#xA;    for x = 0 to imageWidth - 1&#xA;        rayDirection = Vec3f(1.0,&#xA;                             p * ((x + 0.5) / imageWidth * 2.0 - 1.0)&#xA;                             q * ((y + 0.5) / imageHeight * 2.0 - 1.0)).normalize()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that the directions generated this way are not equally spaced in angle (they're closer together in angle toward the edges of the image than at the center), but they &lt;em&gt;are&lt;/em&gt; equally spaced in distance on the image rectangle.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-10T04:18:41.373" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3842" PostTypeId="1" CreationDate="2016-08-10T11:05:45.350" Score="9" ViewCount="2623" Body="&lt;p&gt;So I'm trying to wrap my head around this from a fairly technical point of view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you add a Bump or Normal or Displacement map in your shader they should not be gamma corrected. But diffuse textures should be. But why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you save a file in 8bit (or 16bit Integer) with a format like JPEG, PNG or TIFF they get the gamma of 0.4545 (1/2.2) burnt in. So a camera captures the light from the real world (that is linear) and when saving the photo as a JPEG a gamma value of 1/2.2 is added, as a way to compress the information into 8bit, and then when you view the image on a monitor that adds a gamma of 2.2 making the luminance linear again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when using a diffuse textures (like a photo) you need to a &quot;remove&quot; that 1/2.2 gamma to make it linear (called linearizing) so now the texture looks darker but these values are correct from a mathematical standpoint so the renderer will make the correct calculations. Side note: the software used a display gamma of 2.2 to make sure the textures looks correct it's just for the internal calculation that they are linearized. But when I create a Bump map in Photoshop and save that as a JPG or PNG then that 1/2.2 gamma is burnt into that image as well, so why doesn't this Bump map need to be linearized as well?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I load a Bump map in 3ds Max with a input gamma of 2.2 just like a would do with a Diffuse texture, the diffuse looks right but the bump looks wrong, so I have to set the input gamma to 1.0 for the bump in order to make it look right, but as I said: why, both image files have the 1/2.2 gamma burnt in, right?&lt;/p&gt;&#xA;" OwnerUserId="2736" LastActivityDate="2016-08-16T10:36:08.683" Title="Why shouldn't Bump, Normal and Displacement maps be gamma corrected?" Tags="&lt;gamma&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3844" PostTypeId="2" ParentId="3842" CreationDate="2016-08-10T14:46:23.977" Score="3" Body="&lt;p&gt;Actually, if your bump or displacement map is saved with that 0.45 gamma correction, it's wrong. These maps contain geometrical information rather than colour, and as such, should be simply encoded linearly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a related issue and a fix for Adobe Photoshop, see this slide deck: &lt;a href=&quot;https://docs.google.com/presentation/d/1vS5nAAnXbZ8Pt6-dXxy-xEXDkjfjXTmNnthNGccorl0/edit#slide=id.g14b3e28660_0_8&quot; rel=&quot;nofollow&quot;&gt;https://docs.google.com/presentation/d/1vS5nAAnXbZ8Pt6-dXxy-xEXDkjfjXTmNnthNGccorl0/edit#slide=id.g14b3e28660_0_8&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2817" LastEditorUserId="2817" LastEditDate="2016-08-16T10:36:08.683" LastActivityDate="2016-08-16T10:36:08.683" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3845" PostTypeId="2" ParentId="3842" CreationDate="2016-08-10T15:14:13.783" Score="3" Body="&lt;p&gt;JPG, PNG or any other 8 bit image formats do not intrinsically have 1/2.2 gamma associated with it. They just store values from 0-255. How that data is interpreted depends on the software that reads and writes those files. The interesting fact is that most image editing software uses gamma color space by default. All the brushes, effects, filters and even the color picker all operate in gamma space. Just look at the shades of gray on the color picker in Photoshop. They do not follow a linear distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The consequence is that Photoshop does no conversions between gamma and linear color space when opening or saving an image (by default), only when displaying it. That means that you can just as easily use it to create or edit linear data such as a heightmap as you can edit photos. The bump map does not look correctly when loaded with gamma correction, because it wasn't saved with it.&lt;/p&gt;&#xA;" OwnerUserId="3470" LastActivityDate="2016-08-10T15:14:13.783" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="3846" PostTypeId="2" ParentId="3842" CreationDate="2016-08-10T15:40:22.977" Score="5" Body="&lt;p&gt;The fact that a photo is stored in gamma space doesn't have to do with PNG or JPEG, it has to do with the fact that it's a photo.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The camera detects a 50% intensity but is going to save it as a 187 instead of 127, because that is more efficient to keep the color information that matters to the human eye when you have only 256 different possible values. And so does Photoshop if you tell it so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;For normals or displacement maps, you don't have this need so there is no reason to use gamma space for them&lt;/strong&gt; (using gamma for them would actually be a mistake, since it would affect how precision is distributed). Thus when you decode a normal texture or a displacement texture, you don't need to apply gamma.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the normal map is encoded in a different space though, &lt;a href=&quot;http://aras-p.info/texts/CompactNormalStorage.html&quot; rel=&quot;nofollow&quot;&gt;as can be the case for a G-Buffer for example&lt;/a&gt;, then you have to apply the corresponding correction.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-08-15T07:41:09.803" LastActivityDate="2016-08-15T07:41:09.803" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3848" PostTypeId="2" ParentId="3842" CreationDate="2016-08-11T20:50:28.990" Score="3" Body="&lt;h3&gt;Introduction&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;It depends on how you create the map! Consider the following and let it sink in for a while before you go forward:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The image is displayed with a gamma correction for the benefit of your eyes&lt;/li&gt;&#xA;&lt;li&gt;The data is still just data. The gamma correction is for the display part not the data part.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Now a bump map is pretty hard to draw with a paint application. Because its hard to see even if you were correctly linear. So you end up using such things as looking at values. Now here is the catch:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If you decide that 128 is halfway in your intensity then that is reality. Since that is what your encoding into the data stream. The data is what you interpret it to be since its not meant for human eyes and the monitor. Who cares what the monitor shows the values as its all on how you interpret the data editing it in.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3&gt;Making the bump/displacement map&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Ok, so now I have described that the data is up to interpretation. But why would you interpret the data as linear? Because then you can design your side profile better. See what you can do is think of 100% opacity of your brush as the target height you want to carve or layer to. You can then use the curves tool to design the shape of your stamps brush (since you think the data is linear). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Mz2yX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mz2yX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: A suction cup stamp. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you do something like this then your image is linear despite what everybody tells you. You have decided to discard the image rules that says otherwise. &lt;strong&gt;And that is why the image is linear&lt;/strong&gt;, the author chooses for it to be linear so its easier to work with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/txFW0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/txFW0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Same image displaced and interpreted linear (note I scaled the height a bit to fit to my default bb size), working as intended.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Technically linear is better.&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;A synthetic map has no benefit of compressing certain values on the expense of others. Linear is inherently better because the spread of your bump is better that way. Which is why you'd be wasting resources encoding it in a gamma corrected manner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Secondly a image does not need to specify what color space it is in. Its just that image editors will assume it is sRGB encoded. You have no reason to do same interpretation, no info means just: &quot;Nobody bothered to write down what they were thinking&quot;. So maybe the point should be made you should tag it linear. But here is the rub... your computer does not come with a easily accessible linear profile.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;What about Photoshop and blur?&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;This is where it gets tricky. Photoshop tries to do quite much work to ensure that you do not need to know anything about this stuff. And this is where you shoot yourself in the foot. Se Photoshop is not meant for texture making, its meant to edit images not random data. So since blur on a image is different linear and nonlinear it wont work its geared to wrong data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But you can do one of 2 things to fix this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Disable the gamma correction of blur&lt;/li&gt;&#xA;&lt;li&gt;set your working space to a linear profile&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h3&gt;Conclusion&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The reason you have a hard time with this is &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;You do not know what other people think, you simply do not know if they should be gamma corrected or not.&lt;/li&gt;&#xA;&lt;li&gt;that your using a application that treats images as images&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Point one is especially confusing. I just know that ALL my bump and displacement maps are in fact linear. But I can not know what your maps are. Odds are they are linear because its nearly universally understood that the data is linear. Even people who do not know about gamma tend to do it linear for bump/displacement for some reason (because its easy and that's what you think images are until somebody tells you otherwise).&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-08-12T05:49:14.120" LastActivityDate="2016-08-12T05:49:14.120" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3849" PostTypeId="1" CreationDate="2016-08-12T22:14:28.347" Score="3" ViewCount="196" Body="&lt;p&gt;I am implementing Bezier curve offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My approach is simple:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Given the handles, calculate the vectors normal to them&lt;/li&gt;&#xA;&lt;li&gt;Move the handle along the normal vector.&lt;/li&gt;&#xA;&lt;li&gt;If the new curve intersects the old one, reverse the offset direction.&lt;/li&gt;&#xA;&lt;li&gt;etc.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I would like to find an alternative to step 3. I believe the problem comes from my careless handling of vector maths (mainly calculations involving the cross product). Are there other ways to check the offset direction other than the one I just described?&lt;/p&gt;&#xA;" OwnerUserId="4843" LastActivityDate="2016-08-15T17:41:23.913" Title="Checking the correct offset direction for Bezier curve offset" Tags="&lt;bezier-curve&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3850" PostTypeId="1" AcceptedAnswerId="3851" CreationDate="2016-08-12T23:48:03.667" Score="3" ViewCount="169" Body="&lt;p&gt;I am making an engine with 2D volumetric transparent objects and need advice how to store transparency data. There are 3 requirements:&lt;br&gt;&#xA;- The transparency textures need to be easily editable with common tools (e.g paint.NET, so .png preferred)&lt;br&gt;&#xA;- Since a pixel value will determine the light transmittance 8 bits are not enough - in this case lights could travel maximum 256 pixels in non fully transparent textures.&lt;br&gt;&#xA;- It should be clear what each pixel means when looking at the texture.    &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried using the HEX values from RGB pixels. For example heres a strip with HEX values from 0 to 0xFFFFFF:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aXgNJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aXgNJ.png&quot; alt=&quot;RGB strip&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While this gives enough values (256*256*256), looking at the image its not clear what each pixel means (=if I'd pick a random pixel from this image you could not tell approximately the alpha value).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know a good method how to represent &gt;256 values in an RGB texture, where its clear what each pixel means?&lt;/p&gt;&#xA;" OwnerUserId="2437" LastEditorUserId="2437" LastEditDate="2016-08-13T00:23:30.097" LastActivityDate="2016-08-13T14:26:14.233" Title="How to store &gt; 256 transparency values in textures?" Tags="&lt;texture&gt;&lt;transparency&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3851" PostTypeId="2" ParentId="3850" CreationDate="2016-08-13T14:26:14.233" Score="1" Body="&lt;p&gt;A normal argb image has 8 bits per channel and therefor 32 bits per pixel, the size of an integer. That's why it's stored in an integer a lot of the times.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Floats are also 32 bits.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something that you can do, is to have a separate image that has only 1 channel, for the transparency. If you make that a float type (or for 16 bit, another type that uses 16 bits instead of 32 bits), then it will take about the same room as an extra normal image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After a quick google, I found out that most programs are limited to 8 bit per channel, but there should be programs that have 16 bit per channel.&#xA;This gives you at least more precision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When loading in the normal 16 bit image (your texture, if you use 16 bits per channel), you could convert the normal rgb part to 8 bits, and load that in and then create a new image that has 1 channel that is 16 or 32 bits, and then store the alpha value in there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This way it should be similar to having an extra image, and you do, but instead of 2 textures, you have the transparency in another image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What would then also be possible to do, is to store the transparency in a normal rgba image (inside your program as a texture), as you were talking about, and then in the shader, you manipulate the rgba values to restore the transparency value. This way you wouldn't need a floating point image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is just a quick idea. As far as I know, this should work. (This is my first answer here! whoop! whoop!)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope it helps and good luck!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.mbed.org/handbook/C-Data-Types&quot; rel=&quot;nofollow&quot;&gt;https://developer.mbed.org/handbook/C-Data-Types&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(^for the data sizes)&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2016-08-13T14:26:14.233" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3856" PostTypeId="2" ParentId="3849" CreationDate="2016-08-14T16:23:25.170" Score="0" Body="&lt;p&gt;Using the dot product on the offset vectors provides the answer. There are three distinct cases (when I mention handles, I am refering to Bezier handles such as the ones used in Blender):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the angle between the Bezier handles is greater than 90º. The dot product has to be positive&lt;/li&gt;&#xA;&lt;li&gt;the angle between the Bezier handles is less than 90º. The dot product has to be negative&lt;/li&gt;&#xA;&lt;li&gt;the angle is 90º.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This last case is trickier. You have to sum the offset vectors, and them sum the handle vectors (which are defined as the vector from the control point to the relevant left or right handle). The dot product of these two vectors has to be positive.&lt;/p&gt;&#xA;" OwnerUserId="4843" LastActivityDate="2016-08-14T16:23:25.170" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3857" PostTypeId="2" ParentId="3849" CreationDate="2016-08-15T17:41:23.913" Score="1" Body="&lt;p&gt;For a two dimensional spline it is possible to define a left and a right side, or let us call the directions counterclockwise and clockwise side (or maybe port and starboard would be appropriate). The side is easily identified as the cross product of the tangent in direction of point order crossed by the paper plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TtQpx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TtQpx.png&quot; alt=&quot;offset side&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Offset side in 2D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The higher dimensional cases are more problematic, I will be examining the 3D space only. A free space curve has no inherent good second direction. Mathematicians have defined, what is essentially a hack, that the second direction is in the direction of curvature which has a mathematical definition. The only problem is that curvature is subject to change and can flip direction along the curve. This is not good. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how to counter this? Well simplest is if a curve on a surface of a 2D plane or surface. In this case you can simply use the underlying primitives directions as reference and do a 2D case. This has the added benefit of not doing a somewhat random offset direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the free curve case there are several approaches you can use, they all have the downside of needing to keep some extra data with you. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One is to calculate the location where the curvature is 0 and &quot;cut&quot; the curve at that point and continue with a flipped curvature direction. In case of a straight line just continue with last good direction. A variation of this is not to use curvature but a user defined vector and use that instead. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can also be done numerically by sampling multiple points along and detect the flip by comparing nearby result and not letting it turn more than a certain degree untill you declare a flip (what your doing sound like a variation of this). One other is to propagate a vector along the curve. One way to do this is to specify a vector at each point and let the user flip them if he feels the need. Or interpolate vectors only at certain points on the curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most applications simply just use the will not do it or bug out option. This has the benefit of being rather sane, as the curvature based bi-normal is a bit erratic to say the least. This way the user has to come up with a way to make the directional control with for example a ruled surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;*  Bézier, NURBS or something other like a &lt;a href=&quot;https://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline&quot; rel=&quot;nofollow noreferrer&quot;&gt;Catmul-Rom&lt;/a&gt; spline doesn't matter&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-08-15T17:41:23.913" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3858" PostTypeId="1" AcceptedAnswerId="3859" CreationDate="2016-08-16T07:16:39.057" Score="8" ViewCount="172" Body="&lt;p&gt;I've been digging a bit into what actually happens at a hardware level on the GPU, and found NVidia's &lt;a href=&quot;https://developer.nvidia.com/content/life-triangle-nvidias-logical-pipeline&quot;&gt;Life of a triangle&lt;/a&gt; which explains the pipeline pretty well, at least for green boxes. One thing I wasn't clear on is what happens with indexed meshes, when the same vertex is used for a bunch of different triangles. Since data is generally not persisted for any longer than necessary in a stream processor, I'm guessing the vertex is simply destroyed after being rasterized, then fetched and run through the vertex shader again whenever it appears in a new triangle. Can anyone confirm this? Also, what happens in line-strip or triangle-strip modes? Does the GPU persist the transformed vertex data somewhere until the 2 or 3 relevant primitives have been rasterized in these cases?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2016-08-16T15:05:49.967" Title="Are vertices reprocessed per-poly for indexed meshes?" Tags="&lt;rendering&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3859" PostTypeId="2" ParentId="3858" CreationDate="2016-08-16T08:20:34.033" Score="5" Body="&lt;p&gt;The key expression you may be looking for is &lt;a href=&quot;https://www.opengl.org/wiki/Post_Transform_Cache&quot; rel=&quot;nofollow&quot;&gt;&quot;Post Transform Cache&quot;&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is usually effective because of the natural vertex reuse, but reordering your mesh, e.g. with &lt;a href=&quot;http://hhoppe.com/proj/tvc/&quot; rel=&quot;nofollow&quot;&gt;Hoppe's method&lt;/a&gt; (note: the page also lists some more recent work) or &lt;a href=&quot;https://tomforsyth1000.github.io/papers/fast_vert_cache_opt.html&quot; rel=&quot;nofollow&quot;&gt;Forsyth's&lt;/a&gt; can improve things further.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-08-16T15:05:49.967" LastActivityDate="2016-08-16T15:05:49.967" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3860" PostTypeId="2" ParentId="3858" CreationDate="2016-08-16T08:32:50.617" Score="4" Body="&lt;p&gt;That depends on how far apart the vertexes are reused.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example the square &lt;code&gt;0, 1, 2, 2, 1, 3&lt;/code&gt; will have a short enough interval that the &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;2&lt;/code&gt; vertices will be reused. But if there are a hundred vertices between reuses then it's more likely that there will be no reuse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But when they are much further apart then the vertex will fall out of the cache and have to be reprocessed by the vertex shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why some 3D software have a way to improve vertex locality for indexed meshes by reordering the vertices.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-08-16T08:32:50.617" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3861" PostTypeId="1" CreationDate="2016-08-16T09:30:19.817" Score="2" ViewCount="116" Body="&lt;p&gt;I am trying to write a spaceship simulator. One problem I've hit into is how to best simulate the background of space with its stars. I don't need it to be faithful to the real thing with constellations and everything, but my attempt of uniformly distributing random points on the celestial sphere produced... unnatural-looking starry backgrounds, for reasons I can't put a finger on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is there a way to &quot;realistically&quot; distribute random &quot;stars&quot; in space?&lt;/strong&gt; I'm language agnostic, so feel free to code in the language you're most comfortable with; I'll adjust. :)&lt;/p&gt;&#xA;" OwnerUserId="4924" LastActivityDate="2016-08-16T09:30:19.817" Title="How do I simulate a starfield?" Tags="&lt;simulation&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3862" PostTypeId="1" AcceptedAnswerId="3863" CreationDate="2016-08-16T14:07:04.037" Score="1" ViewCount="654" Body="&lt;p&gt;I'm trying to render a randomly generated terrain with vertex buffers and OpenGL. I want to use a shader to color the terrain, but it seemms like my shader isn't used. I have used shaders before when drawing triangles manually on the CPU and didn't have any problems there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;activate and deactivate is just glUseProgram(m_ShaderProgram) and glUseProgram(0);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my draw method: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Terrain::drawTest() {&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer);&#xA;&#xA;    glEnableClientState(GL_VERTEX_ARRAY);&#xA;    glEnableClientState(GL_NORMAL_ARRAY);&#xA;&#xA;    // setup position &amp;amp; normal pointers&#xA;    glVertexPointer(3, GL_FLOAT, sizeof(TerrainVertex), BUFFER_OFFSET(0));&#xA;    glNormalPointer(GL_FLOAT, sizeof(TerrainVertex), BUFFER_OFFSET(12));&#xA;&#xA;    m_ShaderProgram.activate();&#xA;    glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_INT, BUFFER_OFFSET(0));&#xA;    m_ShaderProgram.deactivate();&#xA;&#xA;    glDisableClientState(GL_VERTEX_ARRAY);&#xA;    glDisableClientState(GL_NORMAL_ARRAY);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And my shaders look like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;varying vec3 Normal;&#xA;varying vec3 Position;&#xA;varying vec2 Texcoord;&#xA;&#xA;void main(void) {&#xA;    Position = (gl_ModelViewMatrix * gl_Vertex).xyz;&#xA;    Normal = gl_NormalMatrix * gl_Normal;&#xA;    Texcoord = gl_MultiTexCoord0.xy;&#xA;    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;varying vec3 Normal;&#xA;varying vec3 Position;&#xA;varying vec2 Texcoord;&#xA;&#xA;void main(void) {&#xA;   gl_FragColor = vec4(1.0,1.0,0,0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Result:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/VzISb.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VzISb.jpg&quot; alt=&quot;Terrain&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the fragment shader doesn't seem to do anything and I can't figure out what the problem is.&lt;/p&gt;&#xA;" OwnerUserId="4543" LastEditorDisplayName="user7220" LastEditDate="2018-03-20T15:55:24.093" LastActivityDate="2018-03-20T15:55:24.093" Title="How to use Shaders with vertex &amp; index buffers?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3863" PostTypeId="2" ParentId="3862" CreationDate="2016-08-16T15:14:01.173" Score="-1" Body="&lt;p&gt;Apparently there was just a problem with the loading of the shader. A bug that crept into the code from an old project...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: The GLuint of the compiled shader was never saved in the class and only local to the load function. Just a stupid mistake really.&lt;/p&gt;&#xA;" OwnerUserId="4543" LastEditorUserId="4543" LastEditDate="2016-08-19T14:07:21.030" LastActivityDate="2016-08-19T14:07:21.030" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3864" PostTypeId="1" AcceptedAnswerId="3865" CreationDate="2016-08-17T04:24:02.497" Score="5" ViewCount="329" Body="&lt;p&gt;&lt;strong&gt;Intro&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Maxwell Render has a feature called &lt;em&gt;multilight&lt;/em&gt;, where one can ray-trace a scene with multiple light sources, and &lt;strong&gt;change the brightness&lt;/strong&gt; of the individual light sources &lt;em&gt;afterwards&lt;/em&gt;.&#xA;Luxrender has a similar feature called &lt;em&gt;light groups&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I image that behind the scenes, these renderers keep track of the contributions of the different light sources separately, and then composing a final image (given brightnesses of light sources) just amounts to mixing these per-light contributions with appropriate coefficients. Effectively, instead of keeping track of the color of a ray as a tuple (R,G,B), one keeps track of more numbers (R1, G1, B1, R2, G2, B2, ..., Rk, Gk, Bk) if there are k light sources (let's assume no spectral rendering, just for ease of notation -- it's conceptually identical).&lt;/p&gt;&#xA;&lt;p&gt;From a mathematical point of view, the final image is a &lt;strong&gt;linear combination&lt;/strong&gt; of the images resulting from the individual light sources.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now it seems interesting to have a similar feature that allows &lt;strong&gt;changing the colors of objects&lt;/strong&gt; in the scene &lt;em&gt;after rendering&lt;/em&gt;.&#xA;This can be done with an entirely similar technique: suppose that we have two objects whose color we want to be able to change after rendering. The final image is a &lt;strong&gt;polynomial&lt;/strong&gt; in the color of these objects, with two variables (one for each object) and of degree n, where n is the maximum number of bounces for a ray.&lt;/p&gt;&#xA;&lt;p&gt;Specifically, instead of keeping track of tuples (R,G,B), the integrator would keep track of&#xA;expressions of the form (R00,G00,B00) + (R10,G10,B10)x + (R01,G01,B01)y + (R11,G11,B11)xy + (R21,G21,B21)x²y + ..., for a total of k^n terms, where k is the number of colors you want to be able to change, and n the maximum number of bounces.&#xA;For modest k and n, this certainly seems tractable. Color calculations become more expensive, as does storing the resulting &amp;quot;polynomial-image&amp;quot;, but all the geometric calculations are identical.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Is this feature implemented in any widely available renderers?&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;If so, which ones?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If not, why not? Is this not something that's useful in practice? Is it not computationally feasible?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Remark&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I hope I've made myself clear in my explanation. I don't know much about computer graphics (mathematician by training), so my notation may be unusual. More general that just changing the colors of objects, one could change more properties of materials after rendering. For example, the transparency of objects could be changed afterwards (though assuming importance sampling is used by the integrator, this comes at the cost of noise, I guess).&lt;/p&gt;&#xA;" OwnerUserId="4933" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-08-17T09:54:42.610" Title="Changing colors after raytracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3865" PostTypeId="2" ParentId="3864" CreationDate="2016-08-17T09:54:42.610" Score="2" Body="&lt;p&gt;What you describe is essentially a deep raster. Most modern renderers implement this in fact it is implemented in several ways. There are even sopecific technical positions that rely on this technology in form of lighting, color grading and compositioning artists&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first technique is multipass rendering which is basically just this dumping of render data out of the renderer for fast defered rendering.  All rendering engines on the planet can do this, though all do not implement dumping it out of one render, most do however). What you then do is you integrate these dumped buffers in a compositioning app (Nuke, Fusion, maybe even after effects, you can even do this in photoshop) where you can do final tweaks and changes. This is a very old idea and has been used for more than 30 years. It has certain drawbacks bit overall this means you night be able to pull off even calculation changes that would be too costly to do with a re-render. So color of objects&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many systems also support interactive sessions that cache the computations, in what is essentially a deep raster. This way its possible to recalculate not only color but even the position, decay of individual lights at interactive speeds. The most modern ones of these are frankly quite sophisticated and can also issue the renderer to rerender in background. Animation studios have lots of people working on these to make them better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can even use this trick to change camera position for the second stereo camera without recomputing your scene.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-08-17T09:54:42.610" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3867" PostTypeId="1" AcceptedAnswerId="3877" CreationDate="2016-08-18T16:46:04.390" Score="8" ViewCount="858" Body="&lt;p&gt;Why is it that it's so common to use monte carlo randomized sample locations, instead of uniform sampling?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm assuming that taking randomized samples gives some benefit but I don't know what they could be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is anyone able to explain the advantage of randomized sample locations over uniform sample locations?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-08-20T06:48:31.657" Title="Why random monte carlo sampling instead of uniform sampling?" Tags="&lt;sampling&gt;&lt;monte-carlo&gt;&lt;integral&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3868" PostTypeId="1" AcceptedAnswerId="3875" CreationDate="2016-08-18T16:50:12.220" Score="16" ViewCount="2203" Body="&lt;p&gt;The 99 lines of C path tracer &lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot;&gt;Smallpt&lt;/a&gt; renders a 2x2 subpixel grid for each pixel it intends to render and then does a tent filter to combine them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is an interesting presentation explaining the code &lt;a href=&quot;https://drive.google.com/file/d/0B8g97JkuSSBwUENiWTJXeGtTOHFmSm51UC01YWtCZw/view&quot;&gt;here&lt;/a&gt;, and it mentions the tent filter but doesn't explain why it's there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain why a tent filter would be preferable in this case over a box blur (just averaging the samples)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would it be higher quality to go with something better than a tent filter, such as bicubic hermite interpolation?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-08-20T02:08:19.910" Title="Why use a tent filter in path tracing?" Tags="&lt;pathtracing&gt;&lt;filtering&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="3869" PostTypeId="2" ParentId="3868" CreationDate="2016-08-18T22:49:47.863" Score="3" Body="&lt;p&gt;I just looked at Wikipedia articles about Bilinear interpolation.&#xA;A tent filter is a kind of Bilinear interpolation.&#xA;A Bilinear interpolation interpolates on 2 dimensions.&#xA;It first linearly interpolates on one dimension and then the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8I67g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8I67g.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you look at this picture, it first does it on the column and then the row for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason why this could be better than averaging colors, is that when one of the points gets closer to the center than another one, it contributes more to the final color.&#xA;With averaging the colors, all the points contributes equally, even when one point is closer to the center than another point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all the 4 points are on fixed positions on a equal distance from the center, then you get exactly 25% contribution on all points, that's the same as averaging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that when you implement anti aliasing by just rendering at 4 times higher resolution, and then down sampling it. The output between the 2 ways should be the same, as far as I understand it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, which filter should you use? Well, it depends on what you want and your situation. If you pick random sub pixel locations for your samples, then it might be better to use a Bilinear interpolation.&#xA;If all the points are fixed and you just render out at a higher resolution, then averaging could be useful.&#xA;In the end this is all just some sub pixel things that normally you don't or barely notice, so if there is some kind if AA, then it's good enough. But that's just my opinion and probably that of the average viewer of 3D animation or something like that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A Bicubic interpolation gives you a smoother look.&#xA;Bicubic:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/iIlKX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iIlKX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bilinear:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HQDup.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HQDup.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is better? Well, it depends on what you like, and I don't think that there will be a huge difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My sources:&#xA;&lt;a href=&quot;https://en.wikipedia.org/wiki/Reconstruction_filter#Image_processing&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Reconstruction_filter#Image_processing&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Bilinear_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Bilinear_interpolation&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Bicubic_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Bicubic_interpolation&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Images are from Wikipedia and are public domain)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps, I just want to say that I am not a professional on this, I'm just somebody that just likes computer graphics stuff. It could be that I made some mistakes. If so, just say it and I change it!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2016-08-18T22:49:47.863" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3871" PostTypeId="2" ParentId="350" CreationDate="2016-08-19T04:33:52.853" Score="3" Body="&lt;p&gt;Briefly: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Low &lt;strong&gt;albedo&lt;/strong&gt; --&gt; darker object&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;High &lt;strong&gt;albedo&lt;/strong&gt; --&gt; brighter object&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Low &lt;strong&gt;diffuse&lt;/strong&gt; reflection --&gt; mirror-like reflection (aka Specular)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;high &lt;strong&gt;diffuse&lt;/strong&gt; reflection --&gt; cotton-like reflection&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4946" LastActivityDate="2016-08-19T04:33:52.853" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3872" PostTypeId="2" ParentId="3867" CreationDate="2016-08-19T11:33:54.710" Score="6" Body="&lt;p&gt;Monte Carlo methods rely on the &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Law_of_large_numbers&quot;&gt;law of large numbers&lt;/a&gt;&lt;/strong&gt;, which states that the average of a random event repeated a large number of times converges toward the expected value (if you flip a coin a gazillion times, on average you will obtain each side half the time). &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Monte_Carlo_integration&quot;&gt;Monte Carlo integration&lt;/a&gt;&lt;/strong&gt; uses that law to evaluate an integral by averaging a large number of random samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using a uniform distribution would break the algorithm because the law it is based upon wouldn't apply anymore.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-08-19T11:40:21.620" LastActivityDate="2016-08-19T11:40:21.620" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3873" PostTypeId="1" AcceptedAnswerId="3889" CreationDate="2016-08-19T17:53:15.607" Score="0" ViewCount="1379" Body="&lt;p&gt;I am working in 3DS Max with V-Ray 3.4. I have recently been encountering strange artifacts on baked textures.  Surfaces that should be flat smooth objects render with dark stripes or other unusual patterns, usually geometric.  The objects affected appear to be random.  One will bake just fine and another that is an instance of the first has these stripes.  And once an object starts baking like this there is no going back.  The only solution appears to be to remodel it from scratch (and that is not guaranteed to work either).  And this behavior only occurs when baking.  Normal rendering works just fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things I have tested for and ruled out:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Co-Planar surfaces&lt;/li&gt;&#xA;&lt;li&gt;bad UVW mapping (Tried automatic and manually unwrapping - no effect)&lt;/li&gt;&#xA;&lt;li&gt;bad material&lt;/li&gt;&#xA;&lt;li&gt;lighting problems&lt;/li&gt;&#xA;&lt;li&gt;bad normals&lt;/li&gt;&#xA;&lt;li&gt;and I've tested on multiple machines with the same results&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Below is an image of what I'm talking about.  The large square surface should be more or less smooth and evenly lit, but instead, there is a strange dark rectangle.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oSFad.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oSFad.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4948" LastEditorUserId="231" LastEditDate="2016-08-20T12:33:30.577" LastActivityDate="2018-05-07T19:37:14.313" Title="Dark stripes on surfaces in V-Ray when rendering to texture (baking)" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3874" PostTypeId="1" AcceptedAnswerId="3876" CreationDate="2016-08-19T18:22:55.483" Score="2" ViewCount="71" Body="&lt;p&gt;I would like to limit the amount draw calls to approximate performance. Is there a nominal amount to aim for when working with high performance gaming? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;From my understanding to render an object that contains exceptional amount of vertices, this would require a lot of draw calls. Though, without doing dynamic draw calls, is there another way to limit the amount of draw calls? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Per example, if the number draw calls is to be 60 for 60 frames per second; this rate is completely arbitrary, am just looking for a basic explanation on how to control this.&lt;/p&gt;&#xA;" OwnerUserId="4829" LastActivityDate="2016-08-20T04:49:46.763" Title="What is required to limit the amount of draw calls in Unity?" Tags="&lt;drawing&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3875" PostTypeId="2" ParentId="3868" CreationDate="2016-08-20T02:08:19.910" Score="15" Body="&lt;p&gt;The theoretical ideal antialiasing filter for discretely sampled data is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Sinc_filter&quot; rel=&quot;noreferrer&quot;&gt;sinc filter&lt;/a&gt;, because it perfectly removes all frequencies higher than the Nyquist frequency, while leaving alone all the lower ones. So, to some extent, we can expect antialiasing filters that more closely resemble the sinc filter to produce better-quality images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The tent filter (triangle filter) certainly resembles the central peak of the sinc filter more closely than does the box filter:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/PVdbP.png&quot; alt=&quot;sinc, triangle, and box filters&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A bicubic filter (e.g. Mitchell-Netravali) could capture the shape of the sinc even more precisely, including its first two negative lobes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reality of filter selection is a bit more subtle than &quot;approximate sinc as well as possible&quot;, since there are different kinds of artifacts that can be generated by &quot;non-ideal&quot; antialiasing filters, such as aliasing, overblurring, and ringing. Also, different filters may be more or less computationally expensive. So it's a game of trying to trade off the different artifacts against each other and against performance. Different scenes/images may favor one choice or another, and it's also partly an aesthetic judgement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for why smallpt uses a tent filter in particular, I would guess for a combination of performance (it's a quick filter to evaluate) and brevity—it can be done in a couple lines of code, while a bicubic filter would take a bunch more code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Incidentally, smallpt actually uses a 2x2 subpixel grid and places a tent filter &lt;em&gt;at each subpixel&lt;/em&gt;, then averages together the results of the four subpixels. So the overall effect is, curiously, that of the sum of four tents, which ends up looking like a pyramid with a flat top:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/sU59F.png&quot; alt=&quot;subpixel tent filters&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if this was intentional, or just happened to be the way it worked out. My guess is this results in a somewhat sharper image than if a single tent filter per pixel were used (because of the narrower support), but probably also more visible aliasing.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-20T02:08:19.910" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3876" PostTypeId="2" ParentId="3874" CreationDate="2016-08-20T04:49:46.763" Score="4" Body="&lt;p&gt;There's quite a bit of &lt;a href=&quot;http://answers.unity3d.com/questions/14578/whats-the-best-way-to-reduce-draw-calls.html&quot; rel=&quot;nofollow&quot;&gt;information&lt;/a&gt; about this:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Static/dynamic batching: basically combining objects into one super-object&lt;/li&gt;&#xA;&lt;li&gt;Atlas textures: combining textures into one large texture than only uses one material&lt;/li&gt;&#xA;&lt;li&gt;Switch to a deferred renderer if you are using many lights&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;From my understanding to render an object that contains exceptional amount of vertices, this would require a lot of draw calls.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The vertex amount doesn't directly determine the number of draw calls. There also isn't really a guide on how many draw calls is too much. The best thing to do is to profile your application and see where your performance problems come from.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2016-08-20T04:49:46.763" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3877" PostTypeId="2" ParentId="3867" CreationDate="2016-08-20T06:48:31.657" Score="7" Body="&lt;p&gt;Sample locations with a uniform pattern will create aliasing in the output, whenever there are geometric features of size comparable to or smaller than the sampling grid. That's the reason why &quot;jaggies&quot; exist: because images are made of a uniform square pixel grid, and when you render (for example) an angled line without antialiasing, it crosses rows/columns of pixels at regular intervals, creating a regular pattern of stairstep artifacts in the resulting image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Supersampling at a finer uniform grid will improve things, but the image will still have similar artifacts—just less badly. You can see this with MSAA, as in this comparison image from an NVIDIA presentation on temporal antialiasing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nYrym.png&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nYrym.png&quot; alt=&quot;comparison of no AA, uniform-grid MSAA, and temporal AA&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 8x MSAA image (which is &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218.aspx#D3D11_MSAAPatterns_8_16&quot;&gt;not quite a grid&lt;/a&gt; but still has a repeating pattern) still plainly has jaggies in it, although they're antialiased jaggies. Compare to the TXAA result, which both has a higher effective sample count (due to temporal reuse) and uses a Gaussian rather than box filter for accumulating the samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, random sampling produces noise instead of aliasing. There is no pattern to the sample locations, so no pattern to the resulting errors. Both aliasing and noise are errors due to not having enough samples to form a clean image, but arguably noise is the less visually-objectionable artifact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the &lt;em&gt;other&lt;/em&gt; other hand, perfectly random sampling (in the sense of &lt;a href=&quot;https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables&quot;&gt;i.i.d. random variables&lt;/a&gt;) tends to exhibit a certain level of clumping. Purely by chance, some areas in the domain will have denser-than-average clumps of samples, and other areas will be lacking in samples; those areas will be, respectively, over-represented and under-represented in the resulting estimate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The convergence rate of the Monte Carlo process can often by improved by using things like &lt;a href=&quot;http://cg.informatik.uni-freiburg.de/course_notes/graphics2_04_sampling.pdf#9&quot;&gt;stratified sampling&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Low-discrepancy_sequence&quot;&gt;low-discrepancy sequences&lt;/a&gt;, or &lt;a href=&quot;http://www.joesfer.com/?p=108&quot;&gt;blue noise&lt;/a&gt;. These are all strategies to generate &quot;de-clumped&quot; samples that are spaced out a bit more evenly than i.i.d. samples, but without creating any regular patterns that might lead to aliasing.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-20T06:48:31.657" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3878" PostTypeId="1" CreationDate="2016-08-20T14:02:08.247" Score="1" ViewCount="51" Body="&lt;p&gt;Alright so I'm a complete n00b at image processing so forgive me if my question sounds vague. I'll try to supplement it with what I have learnt until now and also a couple of images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See the caption in the image below?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WC1qE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WC1qE.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What I'm essentially trying to do, it to remove it and restore the original image in (Python using OpenCV).&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have a couple of approaches in mind. First one I read about is a technique called &lt;em&gt;Inpainting&lt;/em&gt;. Now I saw a tutorial on inpaiting &lt;a href=&quot;http://docs.opencv.org/trunk/df/d3d/tutorial_py_inpainting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; but this required me to create a separate mask where the non-zero pixels denote the stuff I want gone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now what I noticed is that the caption is not fully opaque. So i was wondering if there is any possible way to restore the original image by first removing the darkened part of the strip. (essentially something very the original image with only the whitened text on it) and then create a mask of the text and then use inpaiting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have a couple of questions. &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;What technique do I use to remove the darkened part (let the text be now, we can remove it in the second step using inpainting)&lt;/li&gt;&#xA;&lt;li&gt;Does this algorithm even make sense. Is there a better approach I should be looking at?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;NOTE: In no way am I looking for any sort of code or specific implementation. I'm just looking for what &lt;em&gt;techniques&lt;/em&gt; and &lt;em&gt;procedures&lt;/em&gt; I can study up on so as to get the job done. The rest is on me&lt;/p&gt;&#xA;" OwnerUserId="4954" LastEditorUserId="4954" LastEditDate="2016-08-20T17:24:09.783" LastActivityDate="2016-08-20T17:24:09.783" Title="Removing a darkened caption with text on it in an image" Tags="&lt;image-processing&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="3879" PostTypeId="1" AcceptedAnswerId="3905" CreationDate="2016-08-20T15:38:39.947" Score="4" ViewCount="897" Body="&lt;p&gt;I'm starting to learn three.js and want to create a chord diagram as possible in d3.js, but from ground up. I've created a scene and have circle segments on xz axes. But I got stuck on the chords. I looked up d3.js code (path+quadratic curve) but need some good example or explanation how to do it in three.js.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7y0zT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7y0zT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'd like to do is to have chords with stroke and fill joining my circle segments with different widths at both ends, nicely curved and thinner in the middle (same as d3.js) with a way to set z-index and opacity in the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some example could be really helpfull, thanks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to achieve something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7kxbA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7kxbA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4956" LastEditorUserId="4956" LastEditDate="2016-08-21T09:38:08.700" LastActivityDate="2016-08-27T06:38:33.557" Title="draw a chord in three.js as in d3.js" Tags="&lt;javascript&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3880" PostTypeId="1" AcceptedAnswerId="3883" CreationDate="2016-08-20T16:02:31.440" Score="5" ViewCount="481" Body="&lt;p&gt;I'm implementing volumetric fog in my OpenGL renderer. First I inject color into 3D texture using compute shader, atomic operations and shadow map visibility check. The information I use to compute cell index and position in world space are uniforms: camera pos, cellsize and texture dimensions. &#xA;Next, when volume filled with data is ready, I need to align it with view frustum to raymarch through texture and apply effect as postprocess (deffered stage) and I'm quite stuck with it. I think there are two options (red is texture volume):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3S8F1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3S8F1.jpg&quot; alt=&quot;3d texture aligned with frustum&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, while applying effect I raymarch from camera pos to frag pos (from G-Buffer texture). I dont know if it is correct, but I think I need to somewhat transform frag pos to NDC, scale it to [0,1] and then using this sample from volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Tried some magic like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 texcoords = vpMatrix * vec4(fragPos, 1.0); //to clip space&#xA;texcoords.xyz /= texcoords.w; //to NDC&#xA;texcoords.xyz = texcoords.xyz *0.5 +0.5; //[-1,1] to [0,1]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Eventually:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 texcoords;&#xA;texcoords.x = texcoord0.x; //texcoord0 - texcoords of screen quad&#xA;texcoords.y = texcoord0.y;&#xA;texcoords.z = depth; //depth from vector: worldpos-camerapos&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But its just guessing. In addition I dont know which option from picture is used in such cases (pro game engines) and how to apply only on some length of frustum because its quite big. Will be really grateful for any hint for this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To check if this works for now its implemented like this: camera aligned in center of volume so rotating it not really matters some much. So i probably will need to modify injections stage too to get correct cell indexes which are statically computed like: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 index = vec3(gl_GlobalInvocationID); //cell number of texture;&#xA;vec3 pos = camerapos+index*cellSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-08-20T17:31:49.147" LastActivityDate="2016-08-21T04:51:59.777" Title="mapping 3d texture on view frustum (or part of it)" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;glsl&gt;&lt;volumetric&gt;&lt;raymarching&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3881" PostTypeId="1" CreationDate="2016-08-20T17:35:12.873" Score="1" ViewCount="51" Body="&lt;p&gt;I really cannot get my head around on this issue - how does an analogue image is sampled and then stored in a ture-colour frame buffer (e.g. in a camera) and how do you prevent noise when you do so? Read multiple articles on it but I cannot really get it. &lt;/p&gt;&#xA;" OwnerUserId="4959" LastActivityDate="2016-08-20T17:35:12.873" Title="How do you sample an analogue image and store it in a true-colour frame buffer?" Tags="&lt;image-processing&gt;&lt;noise&gt;&lt;image&gt;&lt;buffers&gt;&lt;photometric&gt;" AnswerCount="0" CommentCount="4" ClosedDate="2016-08-30T16:52:07.133" ContentLicense="CC BY-SA 3.0" />
  <row Id="3882" PostTypeId="2" ParentId="3833" CreationDate="2016-08-20T23:23:03.777" Score="5" Body="&lt;p&gt;Ideally, motion-to-photon latency is exactly what it says. It measures time from when the user physically makes a &lt;em&gt;motion&lt;/em&gt; (say, begins to turn their head) to when the &lt;em&gt;photons&lt;/em&gt; physically coming out of the display change to reflect that motion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With a bit of apparatus, this can be measured directly—for instance by using a high-speed camera aimed at the headset. You give the headset a light bump with your finger (or use some automated device to bump it), and you can see in the high-speed video when the motion occurred and when the image visible on the screen updated to reflect the motion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The complication leading to different definitions occurs because many VR headsets have &lt;em&gt;rolling displays&lt;/em&gt;, where the physical pixels on the display light up progressively, one row at a time, as the image is scanned out from the host PC. So, when you define motion-to-photon latency, you have to say &lt;em&gt;which&lt;/em&gt; photons you're talking about. The very first ones to scan out? The very last ones? Somewhere in the middle?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can pretty much make whichever definition you want here about what point in the scanout process to use as your reference. There may be an argument for one definition or another based on psychovisual effects (i.e. how much of your visual field must be updated in order for your brain to perceive motion?) but this is beyond my knowledge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, if a headset has a global display instead of a rolling one, then the pixels are kept dark while being updated and then the whole display is flashed on and off at the end of scanout. In this case it's clear that the appropriate reference point to measure is the beginning of the flash, since all the photons come out at the same time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, it's worth noting that latency measurements incorporated into an app or API are approximations. The software can't observe the motion nor the photons directly, so instead we must use software-visible proxy events.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The app querying for the latest head pose is a proxy for user motion, but note that this discards any latency in the sensors, USB driver, sensor fusion processing, and time the data spent sitting around in a buffer waiting for the app to query it.&lt;/li&gt;&#xA;&lt;li&gt;The GPU flipping its display buffers is a proxy for photons beginning to come out, but this discards any latency added in the scanout and display process.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So, ideally an app-measured latency figure should include some corrections to at least estimate the above factors. Or accept that you're not really measuring the full motion-to-photon latency, but just the app-query-to-flip latency or some such.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-20T23:23:03.777" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3883" PostTypeId="2" ParentId="3880" CreationDate="2016-08-21T04:51:59.777" Score="2" Body="&lt;p&gt;In techniques I've seen that use a frustum-aligned voxel grid (so-called &quot;froxels&quot;), it looks like option 2 in your diagram. The voxels are cuboids in post-projective screen space, so when transformed back to world space they look like mini-frusta, automatically expanding as they get farther from the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Marching along eye rays is then very easy: you just step along the grid's Z axis. Summing optical density or in-scattered light along an eye ray is just a matter of iterating over the Z dimension of the texture. (Or you could try to apply methods like &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems3/gpugems3_ch39.html&quot; rel=&quot;nofollow&quot;&gt;parallel prefix sum&lt;/a&gt; as well, but it may not be worthwhile, depending on the texture size.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're rendering some geometry and you want to know which voxel it's in, you don't have to do any matrix transformations. Just use &lt;a href=&quot;http://docs.gl/sl4/gl_FragCoord&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;gl_FragCoord​&lt;/code&gt;&lt;/a&gt;, which represents the screen-space position (including depth) of the current fragment. It comes in window units (i.e. pixels) so you'll have to remap it to [0,1] for texture sampling, or to voxel units if you're doing an image store.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Otherwise, for mapping world-space positions into the voxel grid, use the usual sequence of transformations. It looks to me like you got it right in your code snippet, assuming &lt;code&gt;fragPos&lt;/code&gt; is in world space. For getting from the voxel grid back to world space, you'll need to invert that sequence of transformations.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-21T04:51:59.777" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3884" PostTypeId="1" AcceptedAnswerId="3894" CreationDate="2016-08-21T07:47:22.740" Score="5" ViewCount="2466" Body="&lt;p&gt;As tutors for this year’s programming languages course during our Computer Science studies we’re preparing for the students final project which is the implementation of a ray tracer. We’re implementing one on our own.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I’m having trouble understanding how the &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Phong_reflection_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;phong reflection model&lt;/a&gt; and reflection/refraction (&lt;a href=&quot;http://graphics.stanford.edu/courses/cs148-10-summer/docs/2006--degreve--reflection_refraction.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Reflections and Refractions in Ray Tracing&lt;/a&gt;, Bram de Greve, 2006) can be used in conjunction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Our materials currently have these properties:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;ka, kd, ks – ambient, diffuse and specular terms defined as RGB colors&lt;/li&gt;&#xA;&lt;li&gt;shininess – Controlling specular highlights (0 ≤ shininess)&lt;/li&gt;&#xA;&lt;li&gt;reflectivity – Controls degree of reflectivity (0 ≤ shininess ≤ 1, 0 means not reflective)&lt;/li&gt;&#xA;&lt;li&gt;refractive index – Defines the refractive index of the material (0 ≤ refractive index)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;How I understand it, ray tracing as per phong reflection model with reflection and refraction works roughly like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The material is (semi)reflective and (semi)transparent (is this a word). In this case reflectivity and transmittance can be calculated with Fresnel equations. However then the reflectivity as specified in the material is ignored. The final color is &lt;code&gt;reflectivity * trace(reflected_ray, depth + 1) + transmittance * trace(refracted_ray, depth + 1)&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;The material is (semi)reflective but not transparent. The reflective component is determined by further ray tracing. The other component is calculated via the equation from the Phong reflection model. Our ray tracer currently adds both components as in &lt;code&gt;(1 - reflectivity) * color + reflectivity * trace(reflected_ray, depth + 1)&lt;/code&gt; where &lt;code&gt;color&lt;/code&gt; is determined by the Phong equation.&lt;/li&gt;&#xA;&lt;li&gt;The material is not reflective and not transparent. The Phong equation is used solely.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;How do I know whether a material is (semi)transparent? Do I add a boolean property which I use to determine whether I’m in case 1 or 2?&lt;/p&gt;&#xA;" OwnerUserId="4962" LastEditorUserId="4962" LastEditDate="2018-07-08T10:27:45.570" LastActivityDate="2018-07-08T10:27:45.570" Title="Controlling reflection and refraction with material properties in ray tracing" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="3885" PostTypeId="1" AcceptedAnswerId="3886" CreationDate="2016-08-21T08:57:04.567" Score="2" ViewCount="216" Body="&lt;p&gt;I'm passing my vertex shader a bunch of vertices and color data. I would like to first render the triangles and then render a point at each vertex. The triangles render fine, but I can't think of a way to render the triangles and the points without making and calling a whole new method for rendering points, which I guess I could do, but I'd like to know if there is some shader magic that accomplish it for me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my vs:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 120&#xA;&#xA;uniform mat4 projection;&#xA;&#xA;void main() {&#xA;&#xA;gl_Position = projection * ftransform();&#xA;gl_PointSize = 1.0;&#xA;gl_FrontColor = gl_Color;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is my fs:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 120&#xA;&#xA;#define point_color vec3(1,1,1)&#xA;&#xA;void main() {&#xA;&#xA;vec4 color = gl_Color;&#xA;gl_FragColor = vec4(color);&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is the code behind it. I'm using lwjgl.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void render() {&#xA;&#xA;    glEnableClientState(GL_VERTEX_ARRAY);&#xA;    glEnableClientState(GL_COLOR_ARRAY);&#xA;    glEnable(GL_PROGRAM_POINT_SIZE);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO_id);&#xA;    glVertexPointer(3, GL_FLOAT, 0, 0);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, c_id);&#xA;    glColorPointer(4, GL_FLOAT, 0, 0);&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, i_id);&#xA;    glDrawElements(GL_TRIANGLES, draw_count, GL_UNSIGNED_INT, 0);&#xA;&#xA;    glDrawArrays(GL_POINTS, 0, draw_count_v);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);&#xA;&#xA;    glDisableClientState(GL_VERTEX_ARRAY);&#xA;    glDisableClientState(GL_COLOR_ARRAY);&#xA;    glDisable(GL_PROGRAM_POINT_SIZE);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4963" LastActivityDate="2016-08-28T01:11:30.527" Title="Can I use the same vertices to render multiple things?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3886" PostTypeId="2" ParentId="3885" CreationDate="2016-08-21T09:57:34.137" Score="2" Body="&lt;p&gt;If your intention is to render some textured or colored triangles and points colored diferently at the same time at vertex postions with one draw call:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawElements(GL_TRIANGLES, draw_count, GL_UNSIGNED_INT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In order to access vertex data in vertex shader, you can create vertex array object which references to vertex buffer object with data you provided (vertices) for example at index 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then in vertex shader you have:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout (location = 0) in vec3 vPosition; //positions for each vertex&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You might then do something like that (vertex shader):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;flat out vec3 fpos; //not interpolated vertices&#xA;out vec3 pos; //interpolated vertices (for default)&#xA;void main(void)&#xA;{&#xA;  pos = vPosition;&#xA;  fpos = vPosition;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then in fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(length(fpos-pos)&amp;lt;threshold) //small threshold&#xA; fragColor = pointColor;&#xA;else&#xA; fragColor = triangleColor;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2016-08-21T09:57:34.137" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3887" PostTypeId="1" AcceptedAnswerId="3892" CreationDate="2016-08-21T15:22:59.740" Score="7" ViewCount="868" Body="&lt;p&gt;I'm writing my implementation of ray tracer and I've got result which you can see at this image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/f0Pd53n.png&quot; alt=&quot;img&quot;&gt;&#xA;So you can see that some dark parts are overlapping. And I have them even in the part where it should be bright in my opinion. There are two lights one from above and the second one from right-bottom corner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I have two questions. Is it right? I really tried to google some references but failed. I'm not still sure that results in my imagination are correct ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the second one where does it come from?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use usual lambertian shading model and have something like this in my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel = (0, 0, 0)&#xA;normal = get normal of sphere in point of intersection;&#xA;normal = unit vector of normal;&#xA;for each light from light_set {&#xA;    light = unit vector of light;&#xA;    pixel = pixel + diffuseColor * max(0, scalar multiplication of light and normal);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm really struggling to find out the reason where this strange thing is coming from. But couldn't find it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPD0: added some of my real code. The part which is described here is next:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Material mat = surfaces[closestSurfase]-&amp;gt;getMaterial();&#xA;Color pixel = Color(0, 0, 0);&#xA;Vector3f normal = surfaces[closestSurfase]-&amp;gt;getNormal(point).getUnitVector();&#xA;Vector3f view = -ray.getDirection().getUnitVector();&#xA;for (size_t i = 0; i &amp;lt; lights.size(); ++i) {&#xA;    Vector3f normal_light = lights[i]-&amp;gt;getDirection().getUnitVector();&#xA;    Vector3f specVect = (normal_light + view).getUnitVector();&#xA;    float intenst = lights[i]-&amp;gt;getIntensity();&#xA;    pixel = pixel + mat.getDiffuse() * std::max(0.0f, normal_light.dotMultiply(normal)) * intenst;&#xA;}&#xA;result-&amp;gt;setPixel(x, y, pixel);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Or you can find more here: &lt;a href=&quot;https://github.com/minebv/ray_tracer/tree/lambertian_shading_fix/src&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/minebv/ray_tracer/tree/lambertian_shading_fix/src&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Described above is from Camera's method getRender.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPD1: It looks like the problem in the mixing colors in gamma space instead linear one, as answered @PaulHK .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I've still some kind of problem. Here you can see 2 renders.&#xA;&lt;img src=&quot;https://i.imgur.com/7WRCFb0.png&quot; alt=&quot;img1&quot;&gt;&#xA;At the left one I make all work after transformation all colors into linear space, I mean it's like this in my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel = pixel + mat.getDiffuse().toLinear() * std::max(0.0f, normal_light.dotMultiply(normal)) * intenst;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;At the right one I make transformation after multiplying:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel = pixel + (mat.getDiffuse() * std::max(0.0f, normal_light.dotMultiply(normal)) * intenst).toLinear();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I didn't forget to make pixel into gamma space again after all job.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for me, the right one is more correct. But then there is a question: why should I make multiplication on angle into gamma space? Or is it my incorrect way to think about what is right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPD3:it looks like the whole thing really was about mixing colors in gamma space instead of linear one. Here is result with ambient light.&#xA;&lt;img src=&quot;https://i.imgur.com/eNl8zK9.png&quot; alt=&quot;img3&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also about overlapping lights, it was my incorrect way of thinking. I finally found reference material where they have the same thing. Found it at blender &lt;a href=&quot;https://docs.blender.org/manual/en/2.79/render/blender_render/materials/properties/specular_shaders.html#cook-torrance&quot; rel=&quot;nofollow noreferrer&quot;&gt;docs&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank everyone for answers.&lt;/p&gt;&#xA;" OwnerUserId="4966" LastEditorUserId="11503" LastEditDate="2019-11-24T03:49:57.477" LastActivityDate="2019-11-25T12:11:19.520" Title="Ray tracing scene with 2 lights and sphere" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="3889" PostTypeId="2" ParentId="3873" CreationDate="2016-08-21T17:30:08.733" Score="2" Body="&lt;p&gt;Solved.  The issue was with V-Ray's global ambient occlusion on the GI tab.  Once that was shut off everything renders fine.  Interestingly, V-RayDirt maps in materials seem to be behaving just fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPDATE: It appears the real root problem is deeper.  This turned out to be caused by units being set to fractions instead of decimals.  This can cause some values that are very small to round off to zero as the system tries to make it a fraction.  In v-ray lights, the shadow bias was getting rounded to zero automatically in some cases.  A zero shadow bias can produce strange results in some cases.  SOLUTION: stop using fractional units and go through and fix lights with zero bias.&lt;/p&gt;&#xA;" OwnerUserId="4948" LastEditorUserId="4948" LastEditDate="2018-05-07T19:37:14.313" LastActivityDate="2018-05-07T19:37:14.313" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="3890" PostTypeId="1" CreationDate="2016-08-21T22:03:49.733" Score="5" ViewCount="1366" Body="&lt;p&gt;I would like to display arbitrary 3d meshes with black edges (black outline, black ridges, etc.). Thereby I have created two different textures: One color texture and one anti-aliased edge texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example of the color texture:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5sY4w.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5sY4w.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the the corresponding edge texture:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/s2d1P.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/s2d1P.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I'd like to merge both textures. The edge texture has a white background with black/grey edges. I used fxaa, therefore some pixels are grey.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question: How can I combine (blend) both textures correctly? And do I have to apply fxaa for the color texture, too?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: For completeness, here's the fxaa-shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    #version 330 core&#xA;&#xA;in vec2 texPos;&#xA;out vec4 color;&#xA;uniform sampler2D colorTexture;&#xA;uniform float rt_w;&#xA;uniform float rt_h;&#xA;&#xA;vec4 PostFX(sampler2D tex);&#xA;vec3 FxaaPixelShader(sampler2D tex, vec2 rcpFrame);  &#xA;&#xA;void main()&#xA;{&#xA;    color = PostFX(colorTexture);&#xA;    //color = texelFetch(colorTexture, ivec2(gl_FragCoord), 0 );&#xA;}&#xA;&#xA;vec4 PostFX(sampler2D tex)&#xA;{&#xA;  vec4 c = vec4(0.0);&#xA;  vec2 rcpFrame = vec2(1.0/rt_w, 1.0/rt_h);&#xA;  c.rgb = FxaaPixelShader(tex, rcpFrame);&#xA;  c.a = 1.0;&#xA;  return c;&#xA;}&#xA;&#xA;vec3 FxaaPixelShader( &#xA;  sampler2D tex, // Input texture.&#xA;  vec2 rcpFrame) // Constant {1.0/frameWidth, 1.0/frameHeight}.&#xA;{   &#xA;/*---------------------------------------------------------*/&#xA;    #define FXAA_REDUCE_MIN   (1.0/128.0)&#xA;    #define FXAA_REDUCE_MUL   (1.0/8.0)&#xA;    #define FXAA_SPAN_MAX     8.0&#xA;/*---------------------------------------------------------*/&#xA;    vec3 rgbNW = texture(tex, vec2(texPos) + (vec2(-1,-1) * rcpFrame.xy)).xyz;&#xA;    vec3 rgbNE = texture(tex, vec2(texPos) + (vec2(1,-1) * rcpFrame.xy)).xyz;&#xA;    vec3 rgbSW = texture(tex, vec2(texPos)+ (vec2(-1,1) * rcpFrame.xy)).xyz;&#xA;    vec3 rgbSE = texture(tex, vec2(texPos) + (vec2(1,1) * rcpFrame.xy)).xyz;&#xA;    vec3 rgbM  = texture(tex, vec2(texPos)).xyz;&#xA;/*---------------------------------------------------------*/&#xA;    vec3 luma = vec3(0.299, 0.587, 0.114);&#xA;    float lumaNW = dot(rgbNW, luma);&#xA;    float lumaNE = dot(rgbNE, luma);&#xA;    float lumaSW = dot(rgbSW, luma);&#xA;    float lumaSE = dot(rgbSE, luma);&#xA;    float lumaM  = dot(rgbM,  luma);&#xA;/*---------------------------------------------------------*/&#xA;    float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));&#xA;    float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));&#xA;/*---------------------------------------------------------*/&#xA;    vec2 dir; &#xA;    dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));&#xA;    dir.y =  ((lumaNW + lumaSW) - (lumaNE + lumaSE));&#xA;/*---------------------------------------------------------*/&#xA;    float dirReduce = max(&#xA;        (lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * FXAA_REDUCE_MUL),&#xA;        FXAA_REDUCE_MIN);&#xA;    float rcpDirMin = 1.0/(min(abs(dir.x), abs(dir.y)) + dirReduce);&#xA;    dir = min(vec2( FXAA_SPAN_MAX,  FXAA_SPAN_MAX), &#xA;          max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), &#xA;          dir * rcpDirMin)) * rcpFrame.xy;&#xA;/*--------------------------------------------------------*/&#xA;    vec3 rgbA = (1.0/2.0) * (&#xA;        texture(tex, texPos.xy + dir * (1.0/3.0 - 0.5)).xyz +&#xA;        texture(tex, texPos.xy + dir * (2.0/3.0 - 0.5)).xyz);&#xA;    vec3 rgbB = rgbA * (1.0/2.0) + (1.0/4.0) * (&#xA;        texture(tex, texPos.xy + dir * (0.0/3.0 - 0.5)).xyz +&#xA;        texture(tex, texPos.xy + dir * (3.0/3.0 - 0.5)).xyz);&#xA;    float lumaB = dot(rgbB, luma);&#xA;    if((lumaB &amp;lt; lumaMin) || (lumaB &amp;gt; lumaMax)) return rgbA;&#xA;    return rgbB; &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3377" LastEditorUserId="3377" LastEditDate="2016-08-21T23:24:12.990" LastActivityDate="2018-12-24T10:51:55.420" Title="GLSL - Merge two textures" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;edge-detection&gt;" AnswerCount="1" CommentCount="10" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3891" PostTypeId="1" CreationDate="2016-08-22T00:47:43.987" Score="1" ViewCount="116" Body="&lt;p&gt;Do current WebGL capabilities allow to use Clustered Lighting? If not what is it missing to allow that? Basically WebGL uses GLES 2, so is that possible with GLES 2?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to implement this one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.cse.chalmers.se/~uffe/clustered_shading_preprint.pdf&quot; rel=&quot;nofollow&quot;&gt;Clustered Shading&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And use as fallback this one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://worldoffries.wordpress.com/2015/02/19/simple-alternative-to-clustered-shading-for-thousands-of-lights/&quot; rel=&quot;nofollow&quot;&gt;Alternative to Clustered shading&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4503" LastEditorUserId="231" LastEditDate="2016-08-22T17:59:07.550" LastActivityDate="2016-08-22T17:59:07.550" Title="Can I Implement Clustered Lighting with WebGL?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;webgl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3892" PostTypeId="2" ParentId="3887" CreationDate="2016-08-22T02:30:35.690" Score="5" Body="&lt;p&gt;I think what you're describing is what happens when you mix colours in gamma space. You should be using linear colour space when mixing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When reading colours of lights and materials, convert them from gamma-&gt;linear using the inverse gamma function.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;colourLin = pow(colourLight, 2.2);&#xA;... do lambert calculation here and accumulate in 'colour' variable ..&#xA;&#xA;// On output (linear-&amp;gt;gamma conversion)&#xA;gl_FragColor = pow(colour, 1.0/2.2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There is an in depth chapter in GPU Gems on this topic: &lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch24.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Importance of Being Linear&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="11503" LastEditDate="2019-11-25T12:11:19.520" LastActivityDate="2019-11-25T12:11:19.520" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="3893" PostTypeId="1" CreationDate="2016-08-22T15:13:13.423" Score="0" ViewCount="95" Body="&lt;p&gt;I have a 3d city model that is a collada file which consist of many triangles. When I select the model in a 3d software all buildings are selected. But I want every building to be selectable separately, is it possible? Are there any methods or algorithms that define which triangles belong to a building in a 3d model that consist many buildings and triangles?&lt;/p&gt;&#xA;" OwnerUserId="4513" LastEditorUserId="67" LastEditDate="2016-08-23T02:30:07.680" LastActivityDate="2016-08-23T02:30:07.680" Title="In a polygonal mesh 3d model which consist of triangles is it possible to separate different objects?" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;polygon&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3894" PostTypeId="2" ParentId="3884" CreationDate="2016-08-23T00:39:27.270" Score="3" Body="&lt;p&gt;It sounds to me like you're slightly mixing up several concepts: how lighting due to point-light sources (Phong model) and lighting due to other objects in the scene (recursively raytraced reflection or transmission) combine with each other, as compared to how specular lighting combines with diffuse lighting and/or transmission (using the Fresnel equations).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A useful way to think about specular vs diffuse is that specular happens at the &lt;em&gt;surface&lt;/em&gt; of the material while diffuse, transmissive, and refractive properties are associated with the &lt;em&gt;bulk&lt;/em&gt; (the interior) of the material. So you can think of it as two layers composited together. Specular is on top: it reflects a portion of the incoming light, defined by the Fresnel equations, and any remaining light proceeds into the material to light the bulk.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The bulk will have some combination of scattering and absorption properties. Low scattering makes a transmissive material and high scattering makes a diffuse material (the diffuse color is due to scattering on a scale too small to see). Some materials have an intermediate degree of scattering too, but we can ignore that for simplicity and just treat it as a boolean: opaque (Lambert diffuse) or transmissive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Meanwhile, each of these potential material components (specular, diffuse, and transmissive) has to deal with light arriving both from point light sources and from the rest of the scene. Physically, all light sources are just emissive objects that are part of the scene (area lights) but again for simplicity we often approximate by using point lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, putting it all together, when lighting a surface:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For each point light&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Calculate Fresnel factor based on light vector&lt;/li&gt;&#xA;&lt;li&gt;Accumulate Phong specular weighted by Fresnel reflectance&lt;/li&gt;&#xA;&lt;li&gt;[if opaque] Accumulate Lambert diffuse weighted by Fresnel transmittance&lt;/li&gt;&#xA;&lt;li&gt;[if transparent] Nothing; light goes through and isn't scattered into the camera.&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;li&gt;For reflecting the rest of the scene&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Calculate Fresnel factor based on view vector&lt;/li&gt;&#xA;&lt;li&gt;Cast a reflection ray and accumulate it weighted by Fresnel reflectance&lt;/li&gt;&#xA;&lt;li&gt;[if opaque] Nothing. (Ideally, accumulate Lambert diffuse due to all objects visible in the normal hemisphere of the surface, i.e. indirect diffuse. However, for a basic recursive raytracer this isn't feasible; it requires path tracing, photon mapping, or suchlike.)&lt;/li&gt;&#xA;&lt;li&gt;[if transparent] Cast a transmission ray and accumulate it weighted by Fresnel transmittance&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Also, a note about your material properties: physically, not all of those properties are actually independent of each other. Ks, reflectivity, and refractive index are all the same thing. Ks is the same thing as reflectivity (literally the same value) because both control specular reflections; Ks is for point lights and reflectivity is for reflected environment rays, but it's the same physical mechanism for both. And Ks is determined in turn by the Fresnel equations based on refractive index (which can vary with wavelength).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, strictly speaking, you should pick one of those variables and let it determine the others. For opaque materials where you don't really care about refractive index, you might let users set Ks (at normal incidence) and backsolve the Fresnel equations to get the appropriate refractive index from that. For transparent materials like glass you can let users set the refractive index and then let the Fresnel equations do their thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, to get some physics background that will hopefully help clarify all this, I highly recommend Naty Hoffman's &quot;Physics and Math of Shading&quot; talk from the &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/&quot; rel=&quot;nofollow&quot;&gt;SIGGRAPH 2015 Physically-Based Shading Course&lt;/a&gt;. It gives a quick and not-too-mathematical intro to the physical basis of things like diffuse and specular lighting, BRDFs and so on.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="4962" LastEditDate="2016-09-01T21:58:19.270" LastActivityDate="2016-09-01T21:58:19.270" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3896" PostTypeId="1" AcceptedAnswerId="3917" CreationDate="2016-08-24T13:48:40.060" Score="4" ViewCount="118" Body="&lt;p&gt;At page (slide in reality) 12/20 of &lt;a href=&quot;http://documents.tips/documents/spherical-harmonics-gdce.html&quot; rel=&quot;noreferrer&quot;&gt;this tutorial&lt;/a&gt; it is shown a function used to project lights into SH coefficients, however the value of those coefficients is not given, what are their values and what they are for?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I have to clamp colors to max value of 1 (float) / 255(uint) when adding lights to SH coefficients?&lt;/p&gt;&#xA;" OwnerUserId="4503" LastActivityDate="2016-08-27T22:56:08.433" Title="What are the fConstX in Spherical Harmonics?" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3897" PostTypeId="1" AcceptedAnswerId="3903" CreationDate="2016-08-24T14:25:55.273" Score="3" ViewCount="88" Body="&lt;p&gt;Said L the incoming ray (at a point $P$).  $R$ is the reflected ray. $N$ is the normal to the surface at the point $P$.  $\alpha$ is the angle between $N$ and $L$ (and $N$ and $R$ also). It is assumed a smooth surface (like a plane). $P_{R1}$ is the projection of the vector $R$ on the plane.  $R_2$ is the vector that joins the vector $R$ and $P_{R1}$.&#xA;Now you have, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R= P_{R1} + R_2$  (sum of vectors)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$P_{R1} = -L+R_2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus:&#xA;$R=2R_2-L$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, exploiting the property of dot product (namely scalar product)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R_2 = (N\cdot L)/|N|$          (because $R_2$ is $L\cos(\alpha)$ because is the projection of $L$ on $N$)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $N\cdot L$ is the dot product and $|N|$ is the magnitude (the module) of vector $N$.&#xA; But the vector $N$ is the normal that typically has $|N|=1$&#xA;Thus:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R = 2(N\cdot L)-L$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But my book (3D Computer Graphics, Alan Watt) tells that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R_2 = (N\cdot L)N$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rather for me is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R_2=(N\cdot L)/|N| = N\cdot L$    (because $|N|=1$)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand this point.&lt;/p&gt;&#xA;" OwnerUserId="4981" LastEditorUserId="137" LastEditDate="2016-08-24T15:13:31.520" LastActivityDate="2016-08-25T08:17:44.933" Title="Expressing a reflected ray at a point as a function of the incoming ray and the normal to the surface at that point" Tags="&lt;geometry&gt;&lt;computational-geometry&gt;&lt;mathematics&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3898" PostTypeId="2" ParentId="2011" CreationDate="2016-08-24T19:10:07.183" Score="2" Body="&lt;p&gt;Your attribute locations could be wrong, because you're not querying them:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glVertexAttribPointer(0, 3, GL_FLOAT, false, 7*4, 0);&#xA;glVertexAttribPointer(3, 4, GL_FLOAT, false, 7*4, 3*4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first parameter should be queried using &lt;code&gt;glGetAttribLocation&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glVertexAttribPointer(glGetAttribLocation( program, &quot;position&quot; ), 3, GL_FLOAT, false, 7*4, 0);&#xA;glVertexAttribPointer(glGetAttribLocation( program, &quot;i_color&quot; ), 4, GL_FLOAT, false, 7*4, 3*4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If using more modern OpenGL, the locations can be set manually in the shader, eliminating the need for &lt;code&gt;glGetAttribLocation&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(location=0) in vec3 position;&#xA;layout(location=3) in vec4 i_color;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="67" LastActivityDate="2016-08-24T19:10:07.183" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3901" PostTypeId="1" CreationDate="2016-08-24T23:39:21.850" Score="1" ViewCount="101" Body="&lt;p&gt;I have code, which for the sake of argument, looks like &lt;a href=&quot;https://dl.dropboxusercontent.com/u/94180423/stereoDisparity.m&quot; rel=&quot;nofollow&quot;&gt;the code here&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bestMatchIndex = sortedIndeces(1, 1);&#xA;&#xA;% Convert the 1-based index of this block back into an offset.&#xA;% This is the final disparity value produced by basic block matching.&#xA;d = bestMatchIndex + mind - 1;&#xA;&#xA;% Calculate a sub-pixel estimate of the disparity by interpolating.&#xA;% Sub-pixel estimation requires a block to the left and right, so we &#xA;% skip it if the best matching block is at either edge of the search&#xA;% window.&#xA;if ((bestMatchIndex == 1) || (bestMatchIndex == numBlocks))&#xA;    % Skip sub-pixel estimation and store the initial disparity value.&#xA;    DbasicSubpixel(m, n) = d;&#xA;else&#xA;    % Grab the SAD values at the closest matching block (C2) and it's &#xA;    % immediate neighbors (C1 and C3).&#xA;    C1 = blockDiffs(bestMatchIndex - 1);&#xA;    C2 = blockDiffs(bestMatchIndex);&#xA;    C3 = blockDiffs(bestMatchIndex + 1);&#xA;&#xA;    % Adjust the disparity by some fraction.&#xA;    % We're estimating the subpixel location of the true best match.&#xA;    DbasicSubpixel(m, n) = d - (0.5 * (C3 - C1) / (C1 - (2*C2) + C3));&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now, I also want to calculate an &lt;em&gt;inverse disparity&lt;/em&gt;, to eliminate points at infinity, but I cannot find a suitable algorithm. Can anyone describe how it should be done?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My research has suggested that instead of comparing L(x, y) with R(x..x+n, y) it should be comparing L(x, y) with R(x-n..x, y), but am I correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(My actual situation is C++ code with a buggy inverse disparity calculation which I cannot find a reference for to discover how the code should be.)&lt;/p&gt;&#xA;" OwnerUserId="4983" LastActivityDate="2016-08-24T23:39:21.850" Title="Calculating inverse disparity of a stereo image" Tags="&lt;algorithm&gt;&lt;matlab&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3902" PostTypeId="2" ParentId="2011" CreationDate="2016-08-25T06:15:41.637" Score="1" Body="&lt;p&gt;While normally I'd agree with @Survival Machine's assessment, since you say that the geometry is correct, but the color is showing up as solid red, it sounds like your colors have their color channels backwards. Normally, I would expect RGBA to be correct. But if everything's red, that sounds like the alpha is where the red should be. (Your alpha is always 1, so if they're swapped, now your red is always 1.) You can test this by changing your fragment shader to try different color orderings. Just add a swizzle to the last line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f_color = color.yzwx;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That will switch it from RGBA to ARGB. You might also try going the other way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f_color = color.wxyz;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It could also be in ABGR format (unlikely). You'd fix that by doing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f_color = color.wzyx;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It seems strange that any of these would happen. If that does turn out to be the issue, it would be worth investigating why it's happening.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-08-25T06:15:41.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3903" PostTypeId="2" ParentId="3897" CreationDate="2016-08-25T08:17:44.933" Score="2" Body="&lt;p&gt;$N \cdot L$ is the scalar &lt;em&gt;length&lt;/em&gt; of the projection of $L$ on $N$ (assuming $|N|=1$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(N \cdot L)N$ is the actual vector with the length of $N \cdot L$ in the direction of $N$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is often a confusion when people say &quot;projection of this on that&quot; whether they mean just its length, or the actual vector resulting from the projection. In this case you want to combine it with another vector, so you need the vector version. The correct reflection formula is thus: $$R = 2(N \cdot L)N - L$$&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-25T08:17:44.933" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3904" PostTypeId="1" AcceptedAnswerId="3951" CreationDate="2016-08-25T09:22:30.033" Score="4" ViewCount="1844" Body="&lt;p&gt;To reduce noise of edge detection the norm seems like it is to apply a blur. However, is it generally better to apply the blur to the input of the edge detection. The input in my case being the depth and normal GBuffers in which I compare neighbouring pixels.&lt;br&gt;&#xA;Or is it better to blur the output of the edge detection, e.g. a greyscale image of edge strength, before I use that to apply some edge to a colour buffer?&lt;/p&gt;&#xA;" OwnerUserId="3331" LastEditorUserId="3331" LastEditDate="2016-08-26T08:07:52.887" LastActivityDate="2016-09-05T09:55:45.350" Title="Is it better to blur the input or output of an edge detection shader for noise reduction?" Tags="&lt;image-processing&gt;&lt;blur&gt;&lt;edge-detection&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3905" PostTypeId="2" ParentId="3879" CreationDate="2016-08-25T15:31:00.660" Score="1" Body="&lt;p&gt;Ok, I've found the solution myself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It goes like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// create shape&#xA;shape = new THREE.Shape();&#xA;&#xA;// move it to first point of the chord&#xA;shape.moveTo(0+(RADIUS-2)*Math.cos(-1.4639537206164), 0+(RADIUS-2)*Math.sin(-1.4639537206164));&#xA;&#xA;// create all the parts afterward&#xA;shape.absarc(0, 0, (RADIUS-2), -1.4639537206164, -1.3041396376011, true);&#xA;shape.quadraticCurveTo(0, 0, 0+(RADIUS-2)*Math.cos(4.5262534414805), 0+(RADIUS-2)*Math.sin(4.5262534414805));&#xA;shape.absarc(0, 0, (RADIUS-2), 4.5262534414805, 4.6513392175639, true);&#xA;shape.quadraticCurveTo(0, 0, 0+(RADIUS-2)*Math.cos(-1.4639537206164), 0+(RADIUS-2)*Math.sin(-1.4639537206164));&#xA;&#xA;// create geometry&#xA;geometry = new THREE.ShapeGeometry( shape );&#xA;// create mesh&#xA;mesh = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x000000, side: THREE.DoubleSide } ) ) ;&#xA;// rotate&#xA;mesh.rotation.x = 90 * Math.PI/180;&#xA;// add to scene&#xA;scene.add( mesh );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;1) create Shape object&lt;br&gt;&#xA;2) move offset to the first point on the arc&lt;br&gt;&#xA;3) create arc with the same center and smaller radius as circle (start angle of the first point, end angle second)&lt;br&gt;&#xA;4) use quadratic curve with control point (circle center) and the third point&lt;br&gt;&#xA;5) use arc the same way as before&lt;br&gt;&#xA;6) complete shape with quadratic curve and the last point&lt;br&gt;&#xA;7) set geometry, material, add it to scene&lt;/p&gt;&#xA;" OwnerUserId="4956" LastEditorUserId="-1" LastEditDate="2016-08-27T06:38:33.557" LastActivityDate="2016-08-27T06:38:33.557" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3906" PostTypeId="1" AcceptedAnswerId="3907" CreationDate="2016-08-25T21:21:30.143" Score="3" ViewCount="287" Body="&lt;p&gt;The scenery is the following:&#xA;I have a polygon in the space, defined (the polygon) from your vertices. By 3 vertices of the polygon (non-aligned) revenue equation of the plane containing the polygon.&#xA;Later I have a ray of light, represented by the parametric equation of the line in the plane (the parameter is $\textstyle t $).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I must determine the intersection between the line and the plan and see if the point of intersection (if they line and plane are not parallel) is internal or external to the polygon. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Written the equation of the plan then,&#xA;it's simple find the point of intersection: I replace the parameter values of $\textstyle x $ $\textstyle y $ and $\textstyle z $ of the line in the equation of the plane and from here I determine the value of the parameter t.&#xA;Then I replace t in the parametric equation of the line, and I have the coordinates of the intersection point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The text that I am following (3D COmputer Graphics) tells me that if I get from the calculation that $\textstyle t &amp;lt; 0 $ the point will stay in a part of plane that does not contain the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did not understand why. Than intuitive-geometric meaning has $\textstyle t $?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I point that t &amp;lt;0 is sufficient but not necessary condition to say that the point does not belong to the polygon. If it isn't  t &amp;lt;0 I'll have to explicitly test whether the point is inside the polygon or not but the book says that if t &amp;lt;0 I can avoid all this job  because the point is certainly outside the polygon (in a part of the plan that the book calls half plane ). I would like to know why, what mean the parameter t.&lt;/p&gt;&#xA;" OwnerUserId="4981" LastEditorUserId="4981" LastEditDate="2016-08-26T17:03:39.380" LastActivityDate="2016-08-26T17:03:39.380" Title="Meaning of the parameter in a line-plane intersection in the space" Tags="&lt;geometry&gt;&lt;computational-geometry&gt;&lt;mathematics&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3907" PostTypeId="2" ParentId="3906" CreationDate="2016-08-25T22:46:41.427" Score="2" Body="&lt;p&gt;The $t$ parameter represents the distance from the ray's origin point to the intersection point, as a multiple of the ray's direction vector. It is positive for intersections &quot;in front&quot; of the origin, negative for those &quot;behind&quot; the origin as judged by the direction vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In raytracing we always discard any intersections with $t &amp;lt; 0$, because we don't want to render objects behind the camera, and so forth. A ray is only half a line, and only the points $t \geq 0$ are part of the ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is not correct to say &quot;if $t&amp;lt;0$ the point will stay in a part of plane that does not contain the polygon&quot;. If the polygon is behind the ray origin, then the intersection point may well be inside the polygon. However, we can immediately discard this intersection due to its being located behind the ray origin, so we would not need to perform any further tests of whether the point on the plane is in fact inside the polygon.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-25T22:46:41.427" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3908" PostTypeId="1" AcceptedAnswerId="3909" CreationDate="2016-08-26T00:31:24.117" Score="4" ViewCount="880" Body="&lt;p&gt;I'm new to GL stuff (coming in via WebGL, with no direct OpenGL experience). Can we use PhysX with WebGL?&lt;/p&gt;&#xA;" OwnerUserId="4991" LastActivityDate="2016-08-26T08:28:27.930" Title="Can we use PhysX in WebGL?" Tags="&lt;webgl&gt;&lt;physics&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3909" PostTypeId="2" ParentId="3908" CreationDate="2016-08-26T08:28:27.930" Score="5" Body="&lt;p&gt;PhysX is a C++ API and can thus not directly be integrated with the JavaScript-based WebGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on your needs, you have the following options:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Use a JavaScript-based physics engine, mostly suitable for 2D use cases.&lt;/li&gt;&#xA;&lt;li&gt;Use a Game Engine that can export for the web (e.g. Unity 3D) and build your application in there, using full 3D physics capability. Keep in mind that this will probably require your users to install some additional Web Player and is not native WebGL.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that Game Engines may be a viable way for 2D applications too and can make your life a whole lot easier.&lt;/p&gt;&#xA;" OwnerUserId="385" LastActivityDate="2016-08-26T08:28:27.930" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3910" PostTypeId="1" AcceptedAnswerId="3938" CreationDate="2016-08-26T11:06:50.213" Score="4" ViewCount="195" Body="&lt;p&gt;I have to create a file describing a 3d surface with the following properties:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;a circular arc cross section is swept along a closed 2d curve spine defined with equations&lt;/li&gt;&#xA;&lt;li&gt;the normal direction of the arc is not always tangential to the spine, the direction is defined with an equation&lt;/li&gt;&#xA;&lt;li&gt;the surface should be analytic (defined by equations), but a tesselated surface is also acceptable (with an external script I can derive the x,y,z coords of the vertexes for a tesselated surface)&lt;/li&gt;&#xA;&lt;li&gt;the file will be modified by an external script (python), so it should be editable with text editor&lt;/li&gt;&#xA;&lt;li&gt;the file should be opened by Creo(Proe), Catia and NX&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The question:&lt;br&gt;&#xA;Which is the best file format for making this feature?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I tried:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;step: buying the ISO standard is unavoidable, as I cannot figure out on my own how the definition works&lt;/li&gt;&#xA;&lt;li&gt;vrml: only tesselated seems to be feasible&lt;/li&gt;&#xA;&lt;li&gt;x3d: same as vrml, as it has a sweep (extrusion) feature, but the normal direction is the same as the local spine direction, and Proe does not seem to open it&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The egg-shaped curve is the trajectory, the arc is the curve to be swept along it.&#xA;The plane of the arc is close to parallel to the plane &quot;Top&quot;, but this angle varies between 0-30 degrees&#xA;&lt;a href=&quot;https://i.stack.imgur.com/GJuRL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GJuRL.jpg&quot; alt=&quot;explanation for the feature&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4992" LastEditorUserId="4992" LastEditDate="2016-08-29T15:02:28.923" LastActivityDate="2017-01-03T00:14:56.387" Title="File format for swept profile with changing normal" Tags="&lt;3d&gt;&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3911" PostTypeId="1" AcceptedAnswerId="3914" CreationDate="2016-08-26T11:50:32.283" Score="5" ViewCount="294" Body="&lt;p&gt;Consider the following problem and its answer:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Given 3 points in 3D: $A=(A_x,A_y,A_z);   B=(B_x,B_y,B_z)  ;    C=(C_x,C_y,C_z)$&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Find the transformation matrix (in homogeneous coordinates) that performs a reflection around the plane spanned by the given 3 points.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Answer:&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WhjIw.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WhjIw.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Can anyone explain why this answer is correct?&lt;/li&gt;&#xA;&lt;li&gt;Shouldn't normalization be performed by dividing by $|C-A|$ and $|B-A|$ instead of $|AC|$ and $|AB|$?&lt;/li&gt;&#xA;&lt;li&gt;Wouldn't we want to reflect on $uv$ plane (and then the -1 would be one row below)?&lt;/li&gt;&#xA;&lt;li&gt;I saw a similar question where you had to rotate around a vector and not a surface, and then we created $v$ with $v=u\times(0,0,1)^T$ (the vector was $P_1-P_0$ and $u=\dfrac{P_1-P_0}{|P_1-P_0|}$. What's the difference?&lt;/li&gt;&#xA;&lt;li&gt;In general, what is the rule of thumb when finding the $u,v,z$ cartesian system of a given object (plane, line, point etc)?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="4993" LastEditorUserId="182" LastEditDate="2016-08-31T07:28:05.017" LastActivityDate="2016-08-31T07:28:05.017" Title="Transformation Matrices" Tags="&lt;3d&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3912" PostTypeId="1" AcceptedAnswerId="3935" CreationDate="2016-08-26T14:05:19.270" Score="3" ViewCount="659" Body="&lt;p&gt;In order to optimize I'm trying to set up a setup which ping pong between same framebuffer two color attachments to apply some postprocess effects. It seems to work (effects are applied) but concurently I'm getting a lot of strange artifacts like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;blinking squares&lt;/li&gt;&#xA;&lt;li&gt;borders on depth discontinuities&lt;/li&gt;&#xA;&lt;li&gt;color spilling on screen (window resize removes it)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Which change or disappear partly when I for example remove one step (one post process effect) from &quot;ping ponging&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I do this ordinary way using different framebuffers seems to remove them but I'm not 100% sure if it is not a mess in the shaders or something but they seem fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In each frame I'm doing ping pong like that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First step - render to current color attach using other fb texture&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fbDeferredLighting-&amp;gt;bindFramebuffer(); //fb which has two color attachments&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;effect1-&amp;gt;setConstPerFrameUniforms();&#xA;//get 0 attachment from fb scene prepass to apply effect and draw on fbDeferredLighting current color attach&#xA;effect1-&amp;gt;setTextureUniforms(fbScene, 0); &#xA;quad-&amp;gt;draw();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then repeating some number of times: swap step and drawing, using same fb swapped attachment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fbDeferredLighting-&amp;gt;bindFramebuffer();&#xA;//after swap - now current=1, other=0 or current=0, other=1&#xA;std::swap(colorAttachment0Current, colorAttachment0Other);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texturesDiffuse[colorAttachment0Current]-&amp;gt;getTextureID(), 0);&#xA;glClear(GL_DEPTH_BUFFER_BIT); //only clear depth&#xA;effectX-&amp;gt;setConstPerFrameUniforms();&#xA;//get other color attach and use it to apply effect on current&#xA;effectX-&amp;gt;setTextureUniforms(fbDeferredLighting , colorAttachment0Other); &#xA;quad-&amp;gt;draw();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is this correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;I wonder, maybe rewrite it to compute shaders, that would simplify things.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-08-26T22:25:16.707" LastActivityDate="2016-09-01T15:52:42.367" Title="ping pong between same framebuffer two color attachments" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;texture&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3914" PostTypeId="2" ParentId="3911" CreationDate="2016-08-27T07:40:09.907" Score="4" Body="&lt;p&gt;The answer in the screenshot is wrong on two counts. First, you're correct that in the middle matrix the −1 should be on the third row, not the second. The other error is that the $u, v$ basis vectors are normalized, but not orthogonalized, so $M$ is not in general a rotation matrix; therefore its inverse is not simply its transpose. (The reflection doesn't actually need an orthonormal basis, so you could fix the answer either way: by using the full inverse for $M$, or by fully orthonormalizing $u$ and $v$.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rule of thumb for setting up a local coordinate system (I assume orthonormal) for a given object is to set some of the axes to be lined up with the object, then choose arbitrary perpendicular vectors for any remaining axes.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For a point, there's nothing to line up with, so you can use any arbitrary axes.&lt;/li&gt;&#xA;&lt;li&gt;For a line, you line up the $u$ axis with the line, then there's nothing to constrain the $v$ axis, so you can choose any arbitrary vector perpendicular to $u$. That's what the $v=u\times(0,0,1)^T$ thing was getting at: it's a convenient formula to get &lt;em&gt;some&lt;/em&gt; vector perpendicular to $u$ if you don't otherwise care what direction it is. Except that this won't work if $u$ happens to be parallel to the z-axis (the cross product returns zero then), so you actually need to detect that and switch to a different formula, such as $v=u\times(1,0,0)^T$, in that case.&lt;/li&gt;&#xA;&lt;li&gt;For a plane, you line up the $u$ and $v$ axes with the plane. So, you can pick any arbitrary $u$ that lies in the plane, then find a $v$ that lies in the plane and is perpendicular to $u$.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3&gt;Addendum on orthonormalization&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Suppose you have a couple of 3D vectors $u, v$ that are non-parallel (linearly independent) but otherwise arbitrary, and you want to generate a 3D orthonormal basis $u', v', w'$ from them. There are two equivalent ways to do it.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Use the &lt;a href=&quot;https://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process&quot; rel=&quot;nofollow&quot;&gt;Gram–Schmidt process&lt;/a&gt;. This works as follows: first, normalize $u$. Then, for each additional vector, subtract off its projection onto the previous vectors, and normalize what's left over. For the 3D case this looks like:&#xA;$$ \begin{aligned}&#xA;u' &amp;amp;= \text{normalize}(u) = \frac{u}{|u|} \\&#xA;v' &amp;amp;= \text{normalize} \bigl( v - (u' \cdot v)u' \bigr) \\&#xA;w' &amp;amp;= u' \times v'&#xA;\end{aligned} $$&#xA;Note that the notation $(u' \cdot v)u'$ means take the dot product of $u'$ with $v$ (giving a scalar), then multiply that scalar by $u'$. This gives the vector component of $v$ that is parallel to $u'$. When this is subtracted from $v$, the remaining component is perpendicular to $u'$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, $w'$ is set to the cross product of $u'$ and $v'$ to ensure the basis is right-handed. Since $u', v'$ are already orthonormal, we don't need to normalize $w'$—it comes out already normalized. (This isn't strictly part of the Gram–Schmidt process.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, the Gram–Schmidt process works for making an orthonormal basis in any number of dimensions, not just two or three.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The other way, which only works in 3D, is to use cross products.&#xA;$$ \begin{aligned}&#xA;u' &amp;amp;= \text{normalize}(u) \\&#xA;w' &amp;amp;= \text{normalize}(u' \times v) \\&#xA;v' &amp;amp;= w' \times u'&#xA;\end{aligned} $$&#xA;Here, $w'$ has to be normalized because $u'$ and $v$ are not orthonormal. But then $u'$ and $w'$ are orthonormal, so we can calculate $v'$ from them without a normalize. This gives the same results as the previous process, so it's up to you which you prefer to use.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-08-28T01:21:12.287" LastActivityDate="2016-08-28T01:21:12.287" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="3915" PostTypeId="1" AcceptedAnswerId="3921" CreationDate="2016-08-27T16:12:21.590" Score="5" ViewCount="388" Body="&lt;p&gt;How CAD programs handle displaying B-Reps and NURBS/T-Splines in their viewports? Assuming viewport uses OpenGL API - are those programs transform every object into triangles and creating/deleting vertex/index buffers when needed?&lt;/p&gt;&#xA;" OwnerUserId="4999" LastEditorUserId="506" LastEditDate="2016-08-28T09:29:12.063" LastActivityDate="2016-08-28T11:27:09.323" Title="How do CAD programs render non-polygonal 3D objects?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;nurbs&gt;&lt;cad&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3916" PostTypeId="1" AcceptedAnswerId="3920" CreationDate="2016-08-27T17:46:17.120" Score="8" ViewCount="1105" Body="&lt;p&gt;While doing some reading on how real-time applications handle color under OpneGL, I noticed that some examples implemented Color as a collection of 4 &lt;code&gt;floats&lt;/code&gt;, while others used 4 &lt;code&gt;doubles&lt;/code&gt;. I have even seen some vertex-compression examples in the game development field that advocated saving colors as 4 &lt;code&gt;short&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All this got me eager for learning more about this: what is the limit precision that OpenGl (or hardwares) handle for colors? More importantly, though, what are the limits in precision above which color differences become impossible to notice?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have the impression that learning more carefully about that would help me better think and decide on how to implement a Color class for different applications and scenarios (e.g. making trade-off choices between memory, speed and color-variety).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for your ideas on this.&lt;/p&gt;&#xA;" OwnerUserId="3383" LastEditorUserId="3383" LastEditDate="2016-08-27T18:09:43.917" LastActivityDate="2016-08-28T02:49:41.457" Title="How much precision (half, float, double, etc) is enough for a Color class?" Tags="&lt;opengl&gt;&lt;color&gt;&lt;color-science&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3917" PostTypeId="2" ParentId="3896" CreationDate="2016-08-27T22:56:08.433" Score="0" Body="&lt;p&gt;I'm not an expert on Spherical Harmonic (SH), but I'll try to answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SH functions are basis functions. That means that they encode a function $f$ this way by a given basis function $B_i$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\int_{}^{} f(x) B_i(x) dx=fConst_i$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what we can do is to use the $fConst_i$ to reconstruct an approximation of the function $f$ this way:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\sum_{n=1}^{i} fConst_iB(i)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case they could look like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;fConst1 = 0.429043;&#xA;$$&#xA;$$&#xA;fConst2 = 0.511664;&#xA;$$&#xA;$$&#xA;fConst3 = 0.743125;&#xA;$$&#xA;$$&#xA;fConst4 = 0.886227;&#xA;$$&#xA;$$&#xA;fConst5 = 0.247708;&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These coefficients approximate diffuse lighting.&lt;/p&gt;&#xA;" OwnerUserId="5002" LastActivityDate="2016-08-27T22:56:08.433" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3918" PostTypeId="1" CreationDate="2016-08-28T01:04:45.113" Score="4" ViewCount="106" Body="&lt;p&gt;I am familiar with the basic concepts of writing vector and fragment shaders while using linear transformation matrices to describe orientations in 3D space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, what other paradigms exist (theoretical or not)?&lt;/p&gt;&#xA;" OwnerUserId="4991" LastActivityDate="2016-08-28T06:32:28.993" Title="What other paradigms exist besides vector/fragment/transform graphics programming?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3919" PostTypeId="2" ParentId="3885" CreationDate="2016-08-28T01:11:30.527" Score="0" Body="&lt;p&gt;It's totally possible to re-use vertices. That's why when making a flat rectangle plane with four corners that there can be two triangles rendered to construct the rectangle, and the triangles share two of the vertices.&lt;/p&gt;&#xA;" OwnerUserId="4991" LastActivityDate="2016-08-28T01:11:30.527" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3920" PostTypeId="2" ParentId="3916" CreationDate="2016-08-28T02:49:41.457" Score="7" Body="&lt;p&gt;Colors shown on your display or saved to standard image file formats use 8 bits per component. So to store these colors it suffices to use four bytes (&lt;code&gt;unsigned char&lt;/code&gt;). These colors are usually using &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB&quot;&gt;sRGB&lt;/a&gt; color space, which includes a non-linear &quot;gamma&quot; transformation that redistributes precision to make it somewhat more perceptually uniform, so it's actually pretty close to the limit of how finely humans can perceive color differences already. (However, the sRGB gamut is only a subset of all the colors that are physically perceivable. Wider gamuts need more bits.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you're generating or processing colors in graphics software (and not just loading/storing them), there are various reasons you might want to use more precision.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Performing operations on colors, such as adjusting brightness and contrast, alpha blending, gamma correction, etc all tend to lose precision. You might want to store colors as 16-bit or more internally to give yourself more precision headroom. Otherwise, repeated rounding off to 8 bits after each operation can cause a progressive loss of quality.&lt;/li&gt;&#xA;&lt;li&gt;Similarly, when working with linear colors (not the sRGB gamma-encoded colors) for lighting math, extra precision is needed to ensure you have sufficient precision when you eventually convert back to sRGB.&lt;/li&gt;&#xA;&lt;li&gt;It may be faster and more convenient to work with floating-point colors instead of integer ones. This is especially true on GPUs, where integer math instructions have only a fraction of the throughput of float instructions. But even on CPUs it's certainly easier and probably faster to convert colors to float, do a bunch of operations, and then convert back to integer, rather than trying to do everything with integer fixed-point math.&lt;/li&gt;&#xA;&lt;li&gt;If you do &lt;a href=&quot;https://en.wikipedia.org/wiki/High-dynamic-range_rendering&quot;&gt;HDR&lt;/a&gt; rendering at all then you'll need more than 8 bits of precision to handle the larger color gamut and intensity range. The new HDR displays just starting to come out accept images with 10 or 12 bits per component.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Using &lt;code&gt;double&lt;/code&gt; for colors is massive overkill, but using &lt;code&gt;float&lt;/code&gt; for internal representation of colors is common for all the reasons above. When working with GPUs, &lt;code&gt;half&lt;/code&gt; (16-bit float) is also common, as they support that format in hardware.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-28T02:49:41.457" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3921" PostTypeId="2" ParentId="3915" CreationDate="2016-08-28T06:19:19.717" Score="4" Body="&lt;p&gt;Depends on the CAD program. But yes basically they do just what you describe they triangulate the model into a mesh/lines on demand and then display that. How they chose to do this depends on the CAD, most modernized codebases probably use buffers. But older cads may in fact use the old immediate mode draw calls. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This said it is possible that the triangulation happens on the GPU. Though i doubt it is implemented that way in many CAD software. There are also other reasons for the CAD to triangulate the meshes, such as intersection testing, CAM path planning and export, that has nothing to do with display as such and would result in the need of implementing both a software and a gpu triangulator doubling workload or and making maintenance difficult.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most CAD systems allow you to access the triangulated representation, through their API as well as export. But if all else fails you could just attach a debug dll to see what data the CAD dumps to the display card. So for a definitive answer ask your CAD software to tell it to you.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-08-28T11:27:09.323" LastActivityDate="2016-08-28T11:27:09.323" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3922" PostTypeId="2" ParentId="3918" CreationDate="2016-08-28T06:32:28.993" Score="4" Body="&lt;p&gt;Several other rendering paradigms exist aside from conventional rasterization of triangles using vertex and fragment shaders.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Ray_tracing_(graphics)&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray tracing&lt;/a&gt; works by intersecting light rays with surfaces (triangle meshes, or more general surfaces: anything that can be tested for intersection) and then firing additional rays to gather information about lighting, shadows, reflections, etc at the intersection point. Path tracing and photon mapping are refinements of this concept.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Reyes_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;REYES rendering&lt;/a&gt; subdivides all primitives into micropolygons the size of a single pixel or smaller, calculates lighting and shading per micropolygon vertex, then uses a specialized rasterizing algorithm to render the micropolygons in screen space with motion blur and depth of field.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://iquilezles.org/www/articles/raymarchingdf/raymarchingdf.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Distance field ray-marching&lt;/a&gt; (also called &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/161/what-is-ray-marching-is-sphere-tracing-the-same-thing&quot;&gt;sphere tracing&lt;/a&gt;) represents all primitives in terms of distance fields: 3D functions and/or volumetric textures that give the distance from any given point to the nearest surface in any direction. The distance field is used to step adaptively along a ray until it hits a surface, and can also be used for lighting effects such as ambient occlusion.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;However, all rendering algorithms use linear transformation matrices. That's not part of the &quot;paradigm&quot; so much as it's the basic machinery for manipulating objects, the camera, etc in 3D space. It would be hard to do anything interesting without it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-08-28T06:32:28.993" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="3923" PostTypeId="2" ParentId="3910" CreationDate="2016-08-28T13:55:19.850" Score="3" Body="&lt;p&gt;Well realistically your choices are either IGES or STEP. IGES is slightly simpler but you will not successfully write either format without buying the standard (which in case of step is actually so many pages that by the time you have read them a year has passed, and lots of money is wasted on paper). You could also use one of the nonstandard kernel internal formats like Parasolid as its also commonly supported. Most other formats are polygon data so not suitable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would explore an alternative option to writing your own exporter, buy a commercial or take a free CAD kernel and let the kernel (open CASCADE) do the exporting for you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand this is not hard to do inside your CAD application. Which you will need anyway to verify the result. Most CAD applications have a COM API's (don't know about NX most likely, but both creo and catia do have this) so you can edit, even do the generation from a text editor via python if you so wish. This is by far the least amount of effort (and it's usually less work to set up than using just the kernel).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ufq1l.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ufq1l.png&quot; alt=&quot;sweep&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Swept with spine angle $60 \cos(4 t)+110$ and polar trajectory with $r = \cos(4 t)+3$ in Creo. All input from program injection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the approach depends on why you want to do what you do. And what your budget/time constraint is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;PS&lt;/strong&gt;: NURBS (the underlying format of CAD data) solutions are not necessarily analytic, but parametric fits to analytical solutions. Sometimes these are exact sometimes not so exact as not all functions can be fitted to rational spline (though many can). Even when they can fitting is a more general solution.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorDisplayName="user246" LastEditDate="2017-01-03T00:14:56.387" LastActivityDate="2017-01-03T00:14:56.387" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="3924" PostTypeId="1" AcceptedAnswerId="3928" CreationDate="2016-08-28T18:19:07.210" Score="5" ViewCount="5738" Body="&lt;p&gt;A 2D vector can be rotated by an angle $\theta$ using the rotation matrix:&#xA;\begin{bmatrix}&#xA;\cos(\theta) &amp;amp; -\sin(\theta) \\&#xA;\sin(\theta) &amp;amp; \cos(\theta)&#xA;\end{bmatrix}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, it can be rotated by multiplying the vector by the complex number $c$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$c = \cos(\theta) + i\sin(\theta)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any meaningful difference between these two methods? I tested both in MATLAB, and they seem to run at the same speed. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a related note, is there some spatial transformation that complex numbers can do but matrices cannot?&lt;/p&gt;&#xA;" OwnerUserId="4705" LastActivityDate="2017-07-28T14:59:01.977" Title="Computing a rotation: complex numbers vs rotation matrix" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3925" PostTypeId="2" ParentId="3924" CreationDate="2016-08-28T20:28:01.203" Score="1" Body="&lt;p&gt;In a 2D case it reduces to the same calculation. Anyway for 3D we have quaternions that are multidimensional imaginary numbers with one real and 3 imaginary components. Quaternions have a property that makes rotation composing a linear interpolation operation by summing 2 weighted quaternions. This neatly solves certain problems with space rotations. But at the cost of understandability.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-08-28T20:28:01.203" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3926" PostTypeId="1" CreationDate="2016-08-28T20:30:55.193" Score="3" ViewCount="219" Body="&lt;p&gt;I need to find the transformation matrix&#xA;(homogeneous coordinates) that flips an&#xA;object about a plane whose normal is&#xA;directed towards (-2 2 0), and intersects the&#xA;y-axis at y=2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know how to do that when I have 3 points on the plane (A,B,C): translate to origin, find the orthonormal basis of the plane (u,v,w axes) and then rotate the plane to match XYZ coordinate system (with the axes I found), perform the reflection, rotate back and translate back.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However in this case I have a normal and another data which I don't know how to use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="4993" LastActivityDate="2016-08-29T13:58:39.427" Title="Transformations about a Plane" Tags="&lt;3d&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3927" PostTypeId="2" ParentId="3926" CreationDate="2016-08-28T21:10:22.533" Score="2" Body="&lt;p&gt;This is the same problem as the rotation about an axis. What you need is a matrix (any matrix) that satisfies the following corner constraint: one axis must point toward $(-2, 2, 0)$ in the case of a rotation this matrix must be a rotation matrix, in the case of a planar mirror it just has to span the 3D space. But since we know how to make an arbitrary rotation matrix we use the same approach.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Pick any vector (u) that's not parallel to the normal (n)&lt;/li&gt;&#xA;&lt;li&gt;Take cross product of u and n for b&lt;/li&gt;&#xA;&lt;li&gt;Take cross product of n and b for a&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;You now have an arbitrary rotation matrix with one axis defined using vectors n, b and a. Otherwise same as &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/3911/transformation-matrices&quot;&gt;the last question&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-08-29T13:58:39.427" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3928" PostTypeId="2" ParentId="3924" CreationDate="2016-08-28T21:28:10.987" Score="8" Body="&lt;p&gt;Both methods end up doing the same calculations when you break it down.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rotating a vector $u$ with a matrix:&#xA;$$\begin{bmatrix}\cos\theta &amp;amp; -\sin\theta \\ \sin\theta &amp;amp; \cos\theta\end{bmatrix} \begin{bmatrix}u_x\\u_y\end{bmatrix} =&#xA;\begin{bmatrix}u_x \cos\theta - u_y\sin\theta \\ u_x \sin\theta + u_y \cos\theta \end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rotating a vector $u$ using complex numbers:&#xA;$$\begin{aligned}&#xA;(\cos\theta + i\sin\theta)(u_x + iu_y) &amp;amp;= u_x\cos\theta + iu_y\cos\theta + iu_x\sin\theta - u_y\sin\theta \\&#xA;&amp;amp;=(u_x\cos\theta - u_y\sin\theta) + i(u_x\sin\theta + u_y\cos\theta)&#xA;\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wouldn't expect either one to be appreciably faster or slower than the other, since they all end up doing the same set of basic operations, i.e. 4 multiplies and 2 adds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Conceivably, complex numbers could be faster when you have a large number of rotations stored in an array, because they have only two components instead of four and therefore more of them fit into each cache line.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;On a related note, is there some spatial transformation that complex numbers can do but matrices cannot?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No. Matrices are more general than complex numbers. Any complex number $z$ can be represented by a matrix as:&#xA;$$\begin{bmatrix}\text{Re}(z) &amp;amp; -\text{Im}(z) \\ \text{Im}(z) &amp;amp; \text{Re}(z) \end{bmatrix}$$&#xA;This corresponds to rotation by the phase of $z$ combined with scaling by the magnitude of $z$. Complex numbers can only represent rotation and uniform scaling. Matrices can represent those, but also nonuniform scaling and shearing. Another way to see it is that complex numbers have only two degrees of freedom, while 2×2 matrices have four degrees of freedom.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-08-28T21:28:10.987" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3929" PostTypeId="1" AcceptedAnswerId="3930" CreationDate="2016-08-28T22:03:42.680" Score="5" ViewCount="1570" Body="&lt;p&gt;I am trying to figure out an algorithm for handling an otherwise simple animation. I have a progress bar that &quot;ticks down&quot; from a user specified amount of time to zero. I wanted a smooth animation, so I chose to update it in a timer class at approximately 24 frames-per-second. This works just fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I am trying to figure out is how to speed up the animation at an arbitrary point in the animation cycle (the user will initiate it by pressing an &quot;Update Now&quot; type of button. So, say the timer/progress bar is running down from a 10 minute wait and they press &quot;Update Now&quot;, I want the animation to &quot;hurry up&quot; and complete. This new rate would be as if the total wait time was 1 second. To put it another way, if the user waited half way though the normal timer even and pressed &quot;Update Now&quot;, then there would only be a half-second left to animate. If they waited 75% of the time, then there would only be 250 ms left to animate, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried too many things to list and all have failed. Most notably, the progress bar &lt;em&gt;jumps&lt;/em&gt; to a later time, and then finishes the animation--I can't get it to animate fast from the point where it has left off. I'm sure this is easy, I just can't quite grasp the correct algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Givens:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;My timer is running at 24 frames-per-second for a smooth animation.&lt;/li&gt;&#xA;&lt;li&gt;My current algorithm works by taking the countdown timer's initial value (in ms) and subtracting how much time has passed, also in ms, then calculating what percentage of time has passed for the progress bar.&lt;/li&gt;&#xA;&lt;li&gt;One thing I tried of note, that does &lt;strong&gt;not&lt;/strong&gt; work for me was to have a counter of how many frames I had to consume, and subtract a frame count every time my timer even entered. I then &lt;em&gt;assumed&lt;/em&gt; I could increase the frame rate to simulate the faster time. This all failed miserably. I'm not sure why, but increasing the frame rate did not appear to do much on my computer--the speed increased, but not to the extent I wished for. Further, my timer is not reliable enough even when &lt;strong&gt;not&lt;/strong&gt; doing the faster animation. It would gain approximately 1 second for every 10 seconds of original wait time. So, that method is off the table. If the user wanted to wait 60 seconds and didn't press &quot;Update Now&quot;, then the timer would consistently run for approximately 70 seconds, a 120 seconds would become 140 seconds, etc. I'm doing this on an i7-6700 and the CPU is not strained (7-8% total), but something is causing the timer to be otherwise unreliable...&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I'm sure the answer will turn out easy, but any help would be appreciated. I'm doing this in c#, but I am sure I can figure out any algorithm presented and translate it if needed.&lt;/p&gt;&#xA;" OwnerUserId="5003" LastActivityDate="2016-08-29T10:29:04.487" Title="Algorithm for adjusting the speed of a progress bar animation" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3930" PostTypeId="2" ParentId="3929" CreationDate="2016-08-29T10:29:04.487" Score="3" Body="&lt;p&gt;You will need to persist the percent completed across frames and update it based on the time elapsed since last frame and the total time. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;percentCompleted = 0;&#xA;totalTime = 10; //in seconds&#xA;&#xA;void onUpdate(float deltaTime){&#xA;    percentCompleted += deltaTime/totalTime;&#xA;}&#xA;&#xA;void hurryUp(){&#xA;    totalTime = 1;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-08-29T10:29:04.487" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3931" PostTypeId="1" AcceptedAnswerId="3934" CreationDate="2016-08-30T07:23:10.793" Score="5" ViewCount="205" Body="&#xA;&#xA;&lt;p&gt;I am trying to translate an old (2013) bit of code from Apple from objective C to Swift with some modifications I need for my simulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code I am translating can be found &lt;a href=&quot;https://developer.apple.com/library/ios/samplecode/GLCameraRipple/Introduction/Intro.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make translation easier I have broken the simulation into parts. The part I am working on now (and am stuck on) is thus: I simply need to draw your general full screen texture coords shader however I need it to be broken up into a grid. If I have a grid scale factor 1 then each pixel on the screen will get a triangle and that will make up the mesh. However if I put in 10 then there will be a triangle every 10 pixels. Essentially this is the resolution of my simulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is these images (the numbers indicate the scale factor of the pond):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CLUwc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CLUwc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;For some reason rather then drawing a full screen texture coord drawing it draws this weirdness (Some of these honestly belong in a modern art museum). I really have no clue where to look in my code to find this issue, my guess is it is the indices.&lt;br&gt;&#xA;You would see the individual triangles on the top of the 1st and second image but I killed the resolution so it wasn't difficult to upload to SO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So first off here is how I define all of the arrays that make up this simulation:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-swift prettyprint-override&quot;&gt;&lt;code&gt;var rSimWidth:Int = 0&#xA;var rSimHeight:Int = 0&#xA;var mesh:[GLfloat] = []&#xA;var tex:[GLfloat] = []&#xA;var ind:[Indicie] = []&#xA;&#xA;var realWidth:Int = 0&#xA;var realHeight:Int = 0&#xA;&#xA;//In this case width = 568, height = 320, mpp varies look at top of picture&#xA;init(width: Int, height: Int, mpp: Int)&#xA;{&#xA;    rSimWidth = width / mpp&#xA;    rSimHeight = height / mpp&#xA;    rSimWidth += 1; rSimHeight += 1&#xA;    realWidth = width&#xA;    realHeight = height&#xA;&#xA;    mesh = [GLfloat](count: rSimWidth * rSimHeight * 2, repeatedValue: 0)&#xA;    tex = [GLfloat](count: rSimWidth * rSimHeight * 2, repeatedValue: 0)&#xA;    ind = [Indicie](count: (rSimHeight-1)*(rSimWidth*2+2), repeatedValue: 0)&#xA;&#xA;    print(&quot;Screen is (\(width) x \(height))\tPond is (\(rSimWidth) x \(rSimHeight))\tScreenSA: \(width * height)\tPond sa: \(rSimWidth * rSimHeight)\tMP: \(mpp) \((rSimWidth * rSimHeight) * mpp)&quot;)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then I fill up the indices. I had difficulties with this because of the data type. I believe for indices I am supposed to use GLushort however on my system the maximum value is 65,535 . This value was quickly overflowed by the indice generation so I had to switch it to &quot;Int&quot;. There is a typedef &quot;Indicie&quot; so I can change the type of data in the indices easily. What I find odd is when I ramped up the simulation resolution in the apple code I never had an overflow issue.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-swift prettyprint-override&quot;&gt;&lt;code&gt;    var index:Int = 0&#xA;    for i in 0..&amp;lt;rSimHeight - 1&#xA;    {&#xA;        for j in 0..&amp;lt;rSimWidth&#xA;        {&#xA;            if (i%2==0)//X is even&#xA;            {&#xA;                if (j == 0)&#xA;                {&#xA;                    //DEGENRATE TRIANGLE&#xA;                    ind[index] = Indicie(i*rSimWidth + j)&#xA;                    index += 1&#xA;                }&#xA;&#xA;                ind[index] = Indicie(i * rSimWidth + j)&#xA;                index += 1&#xA;                ind[index] = Indicie((i + 1) * rSimWidth + j)&#xA;                index += 1&#xA;                //(114 + 1) * 569 + 101&#xA;                //&#xA;&#xA;                if (j == rSimWidth - 1)&#xA;                {&#xA;                    //DEGENERATE TRIANGLE&#xA;                    ind[index] = Indicie((i+1)*rSimWidth + j)&#xA;                    index += 1&#xA;                }&#xA;            }&#xA;            else&#xA;            {&#xA;                if (j == 0)&#xA;                {&#xA;                    //DEGENRATE TRIANGLE&#xA;                    ind[index] = Indicie((i+1)*rSimWidth + j)&#xA;                    index += 1&#xA;                }&#xA;&#xA;                ind[index] = Indicie((i + 1) * rSimWidth + j)&#xA;                index += 1&#xA;                ind[index] = Indicie(i * rSimWidth + j)&#xA;                index += 1&#xA;&#xA;                if (j == rSimWidth - 1)&#xA;                {&#xA;                    //DEGENRATE TRIANGLE&#xA;                    ind[index] = Indicie(i*rSimWidth + j)&#xA;                    index += 1&#xA;                }&#xA;            }&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In case you wish to see the position and tc code&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-swift prettyprint-override&quot;&gt;&lt;code&gt;  for yy in 0..&amp;lt;rSimHeight&#xA;    {let y = GLfloat(yy);&#xA;        for xx in 0..&amp;lt;rSimWidth&#xA;        {let x = GLfloat(xx);&#xA;            let index = (yy*rSimWidth + xx) * 2&#xA;            tex[index] = x / GLfloat(rSimWidth - 1)&#xA;            tex[index + 1] = y / GLfloat(rSimHeight - 1)&#xA;&#xA;            mesh[index] = tex[index] * GLfloat(realWidth)&#xA;            mesh[index + 1] = tex[index + 1] * GLfloat(realHeight)&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the drawing code&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-swift prettyprint-override&quot;&gt;&lt;code&gt;     glUseProgram(shade.progId)&#xA;&#xA;&#xA;    let posLoc = GLuint(glGetAttribLocation(shade.progId, &quot;pos&quot;))&#xA;    let texLoc = GLuint(glGetAttribLocation(shade.progId, &quot;tc&quot;))&#xA;&#xA;&#xA;    glBindBuffer(GLenum(GL_ARRAY_BUFFER), texVBO);&#xA;    glBufferData(GLenum(GL_ARRAY_BUFFER), sim.tex.count * sizeof(GLfloat), sim.tex, GLenum(GL_DYNAMIC_DRAW));&#xA;    glVertexAttribPointer(texLoc, 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 2, BUFFER_OFFSET(0))&#xA;    glEnableVertexAttribArray(texLoc)&#xA;&#xA;    glBindBuffer(GLenum(GL_ARRAY_BUFFER), posVBO)&#xA;    glVertexAttribPointer(posLoc, 2, GLenum(GL_FLOAT), GLboolean(GL_FALSE), 2, BUFFER_OFFSET(0))&#xA;    glEnableVertexAttribArray(posLoc)&#xA;&#xA;    let uniOrtho = glGetUniformLocation(shade.progId, &quot;matrix&quot;)&#xA;    glUniformMatrix4fv(uniOrtho, 1, GLboolean(GL_FALSE), &amp;amp;orthographicMatrix)&#xA;&#xA;&#xA;    glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), indVBO)&#xA;&#xA;&#xA;    glDrawElements(GLenum(GL_TRIANGLE_STRIP), GLsizei(sim.ind.count), GLenum(GL_UNSIGNED_SHORT), nil)&#xA;&#xA;    glBindBuffer(GLenum(GL_ARRAY_BUFFER), 0)&#xA;    glBindBuffer(GLenum(GL_ELEMENT_ARRAY_BUFFER), 0)&#xA;    glDisableVertexAttribArray(posLoc)&#xA;    glDisableVertexAttribArray(texLoc)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I really have 0 clues as to why something THIS weird is drawing rather then something that makes sense. Any suggestions of what it might be or tips are appreciated!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Extra note:&#xA;I am so sorry but Swift likes to think it is special so it ditched c style for loops. Basically for all of these loops think&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-swift prettyprint-override&quot;&gt;&lt;code&gt;for (var i = &amp;lt;value before ..&amp;gt;; i &amp;lt; &amp;lt;value after dot&amp;gt;; &amp;lt;happens automatically&amp;gt;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;EDIT: Here is the matrix code&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-swift prettyprint-override&quot;&gt;&lt;code&gt;var orthographicMatrix:[GLfloat] = []&#xA;&#xA;    func buildMatrix()&#xA;    {&#xA;        orthographicMatrix = glkitmatrixtoarray(GLKMatrix4MakeOrtho(0, GLfloat(width), 0, GLfloat(height), -100, 100))&#xA;        //Storage.upScaleFactor&#xA;    }&#xA;    func glkitmatrixtoarray(mat: GLKMatrix4) -&amp;gt; [GLfloat]&#xA;    {&#xA;        var buildme:[GLfloat] = []&#xA;        buildme.append(mat.m.0)&#xA;        buildme.append(mat.m.1)&#xA;        buildme.append(mat.m.2)&#xA;        buildme.append(mat.m.3)&#xA;        buildme.append(mat.m.4)&#xA;        buildme.append(mat.m.5)&#xA;        buildme.append(mat.m.6)&#xA;        buildme.append(mat.m.7)&#xA;        buildme.append(mat.m.8)&#xA;        buildme.append(mat.m.9)&#xA;        buildme.append(mat.m.10)&#xA;        buildme.append(mat.m.11)&#xA;        buildme.append(mat.m.12)&#xA;        buildme.append(mat.m.13)&#xA;        buildme.append(mat.m.14)&#xA;        buildme.append(mat.m.15)&#xA;        return buildme&#xA;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now the issue is not the abstract art but that the rectangle only goes half way nomater the scale factor. Notice the jagged edge&#xA;&lt;a href=&quot;https://i.stack.imgur.com/jBcCz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jBcCz.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In apples frame debugger you can see the outline of all the triangles that it draws it looks like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/a5uoq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a5uoq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Could it be this line that is causing all the trouble &lt;code&gt;let index = (yy*rSimWidth + xx) * 2&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A test:&#xA;I tried the code out by passing 3, 3, and 1 into the initialize function. This should in theory make a 3x3 pixel square, however it just made a mess. Here is all the &lt;a href=&quot;http://pastebin.com/JEf48xYK&quot; rel=&quot;nofollow noreferrer&quot;&gt;data on the CPU&lt;/a&gt;, and here (according to frame capture take as grain of salt) is how the gpu understands it.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/a4lDJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a4lDJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2016-09-01T09:40:01.463" LastActivityDate="2016-09-01T10:02:15.737" Title="Weird rendering in rectangle mesh shader AKA Why has my basic shader become a modern art generator?" Tags="&lt;mesh&gt;&lt;artifacts&gt;&lt;tesselation&gt;" AnswerCount="1" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3932" PostTypeId="1" AcceptedAnswerId="3973" CreationDate="2016-08-30T21:33:23.940" Score="7" ViewCount="937" Body="&lt;p&gt;After watching &lt;a href=&quot;https://www.youtube.com/watch?v=kYB8IZa5AuE&quot;&gt;this video&lt;/a&gt; on matrices, I tried to make a simple animation of 2D linear transformations. Starting with a set of 2D points in a grid, I applied a 2x2 matrix to each point and obtained a set of transformed points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure how to animate the transition between the initial and final states. At first, I made each point move along the straight path between its initial and final position. This caused problems for rotation matrices. For example, a 180$^{\circ}$ rotation should show the points rotate about the origin in circular arcs, but my method made it look like the whole grid flipped around, without rotating. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A better rotation animation can be made by applying a very small rotation, say 1$^{\circ}$, multiple times. The matrix for a 1$^{\circ}$ rotation is close to the identity matrix:&#xA;$$\begin{bmatrix} 0.9998 &amp;amp; -0.0175 \\ 0.0175  &amp;amp;  0.9998 \end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some general formula that can generate a differential transformation matrix, given the full transformation matrix? I would like it to work for any 2x2 matrix, without needing to specify the type of transformation.&lt;/p&gt;&#xA;" OwnerUserId="4705" LastActivityDate="2016-09-10T18:18:39.683" Title="Animating a smooth linear transformation" Tags="&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3933" PostTypeId="2" ParentId="2011" CreationDate="2016-08-31T14:45:32.937" Score="1" Body="&lt;p&gt;This:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glVertexAttribPointer(0, 3, GL_FLOAT, false, 7*4, 0);&#xA;glVertexAttribPointer(3, 4, GL_FLOAT, false, 7*4, 3*4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;should be this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLint posAttrib = glGetAttribLocation(yourShader, &quot;position&quot;);&#xA;glEnableVertexAttribArray(posAttrib);&#xA;glVertexAttribPointer(posAttrib, 3, GL_FLOAT, false, sizeof(float)*7, 0);&#xA;&#xA;posAttrib = glGetAttribLocation(yourShader, &quot;i_color&quot;);&#xA;glEnableVertexAttribArray(posAttrib);&#xA;glVertexAttribPointer(posAttrib, 4, GL_FLOAT, false, sizeof(float)*7, sizeof(float)*2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;as both are byte offsets, not array indices. A GLfloat is currently defined as 32 bit = 4 Byte, but you should never hard code that.&lt;/p&gt;&#xA;" OwnerUserId="5013" LastActivityDate="2016-08-31T14:45:32.937" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3934" PostTypeId="2" ParentId="3931" CreationDate="2016-09-01T08:27:16.253" Score="4" Body="&lt;p&gt;I think you are not constructing the index buffer correctly. Firstly you only need 1 degenerate vertex to terminate each triangle-strip row. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You also should not need any special handling for odd/even rows. You can emit a single triangle-strip per loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your index loop should look something like :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var index:Int = 0&#xA;for i in 0..&amp;lt;rSimHeight - 1&#xA;{&#xA;    for j in 0..&amp;lt;rSimWidth&#xA;    {&#xA;        ind[index++] = Indicie(i*rSimWidth + j);        // current row&#xA;        ind[index++] = Indicie((i+1)*rSimWidth + j);    // row below&#xA;    }&#xA;    ind[index] = ind[index-1];      // degenerate vertex / row termination&#xA;    index++;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This also means your index count is defined like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int triStripRows = rSimHeight - 1;&#xA;int indicesPerRow = (rSimWidth * 2) + 1&#xA;int totalIndices = indicesPerRow * triStripRows;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Edit : After seeing the vertex dump you added to your question I can see there is another problem with the index buffer format. Every odd item in the vertex list is vertice 0. This looks like index buffer is created using 32bit indexes but is being interpreted by opengl as 16bits. So it will read the lower 16bits then upper 16bits of each index. This can be fixed by either changing Indicie data type to 16bit (short) or telling opengl the index buffer is really 32 bits by using GL_UNSIGNED_INT instead of GL_UNSIGNED_SHORT in glDrawElements.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2016-09-01T10:02:15.737" LastActivityDate="2016-09-01T10:02:15.737" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="3935" PostTypeId="2" ParentId="3912" CreationDate="2016-09-01T15:52:42.367" Score="1" Body="&lt;p&gt;Actually, GL_COLOR_BUFFER_BIT also need to be cleared&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After creation of the framebuffer, draw buffer need to be set to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawBuffer(GL_COLOR_ATTACHMENT0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and then after each swap:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;instead of only &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glClear(GL_DEPTH_BUFFER_BIT);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To clear current attachment 0.&#xA;I don't really understand these clearing bits extensively but this seems to fix blinking &quot;chess board&quot; artifact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Borders seems to be connected with motion blur shader.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2016-09-01T15:52:42.367" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3936" PostTypeId="1" CreationDate="2016-09-02T05:44:10.807" Score="4" ViewCount="1239" Body="&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glReadBuffer.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glReadBuffer(...)&lt;/code&gt;&lt;/a&gt;/&lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glDrawBuffer.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glDrawBuffer(...)&lt;/code&gt;&lt;/a&gt;/&lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glDrawBuffers.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glDrawBuffers(...)&lt;/code&gt;&lt;/a&gt; access part of a framebuffer's state.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For reading the default framebuffer, this is &lt;code&gt;GL_FRONT&lt;/code&gt; or &lt;code&gt;GL_BACK&lt;/code&gt;.  However, the documentation doesn't say what it is for FBOs.  The only thing I found was an offhand comment &lt;a href=&quot;http://www.lighthouse3d.com/tutorials/opengl_framebuffer_objects/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt; stating that the default is GL_COLOR_ATTACHMENT0 (which is what I would guess).  Can I rely on that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For writing, I didn't immediately find any claims what what color buffers are enabled.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2016-09-02T05:44:10.807" Title="What Are The Default Values of `glReadBuffer/glDrawBuffer(s)` for an FBO?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3937" PostTypeId="2" ParentId="3936" CreationDate="2016-09-02T05:44:10.807" Score="3" Body="&lt;p&gt;You can usually track down the answer for such questions in the OpenGL specification.  Assuming the value you care about is consistent across OpenGL versions (often the case for initial values, &lt;a href=&quot;https://github.com/imallett/parse-GL-minimum-limits&quot; rel=&quot;nofollow&quot;&gt;seldom the case for minimum values&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, in the &lt;a href=&quot;https://www.opengl.org/registry/doc/glspec45.core.pdf&quot; rel=&quot;nofollow&quot;&gt;GL 4.5 specification&lt;/a&gt;, check out the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;glReadBuffer(...)&lt;/code&gt; initial value: (default framebuffer: &lt;code&gt;GL_FRONT&lt;/code&gt; iff single-buffered, &lt;code&gt;GL_BACK&lt;/code&gt; iff double-buffered) (FBO: &lt;code&gt;GL_COLOR_ATTACHMENT0&lt;/code&gt;) (see page 506)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;glDrawBuffer(...)&lt;/code&gt; initial value: (see &lt;code&gt;glDrawBuffers(...)&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;glDrawBuffers(...)&lt;/code&gt; initial value: (default framebuffer: fragment color 0 goes to &lt;code&gt;GL_FRONT&lt;/code&gt; iff single-buffered, &lt;code&gt;GL_BACK&lt;/code&gt; iff double-buffered) (FBO: fragment color 0 goes to &lt;code&gt;GL_COLOR_ATTACHMENT0&lt;/code&gt;) (both: fragment colors other than 0 go to &lt;code&gt;GL_NONE&lt;/code&gt;) (see page 497)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="523" LastActivityDate="2016-09-02T05:44:10.807" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3938" PostTypeId="2" ParentId="3910" CreationDate="2016-09-02T06:01:15.033" Score="-1" Body="&lt;p&gt;Here is what I finally did, maybe somebody finds it useful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wrote a script with Excel VBA what does the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;gets the coordinates of n discrete points on the trajectory&lt;/li&gt;&#xA;&lt;li&gt;gets k points of the circular cross-section at each n, in a horizontal plane&lt;/li&gt;&#xA;&lt;li&gt;applies a rotation on these cross-sections (moves all points)&lt;/li&gt;&#xA;&lt;li&gt;creates (n-1)*(k-1) facets (assigns 4 corner points to each)&lt;/li&gt;&#xA;&lt;li&gt;exports the points and the facets to a vrml file&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GIwAu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GIwAu.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;The script might have been easier in python, but I chose Excel VBA&lt;br&gt;&#xA;because this way I don't have to deal with the GUI.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The format is vrml, because a) most software handles it b) the&#xA;definition is available (mostly) and simple&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;prepare the file by script instead of a CAD software: in my experience they can't build this surface reliably enough. The features will be super-sensitive to the input parameters, they will tend to crash after small changes&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There are a couple of issues remaining:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Catia can't open the result, possibly because the vertex normals are not defined in the wrl file. This feature of the vrml is not really documented. Opening and saving it with Creo solves the issue, as it adds the normals automatically. Creo and NX are ok.&lt;/li&gt;&#xA;&lt;li&gt;Can't convert the result to quilt in Creo, hence sectioning, measuring, etc is problematic&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Any suggestions with the issues above are most welcome.&lt;/p&gt;&#xA;" OwnerUserId="4992" LastActivityDate="2016-09-02T06:01:15.033" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3939" PostTypeId="1" CreationDate="2016-09-02T20:39:11.707" Score="3" ViewCount="432" Body="&lt;p&gt;There's already something called K-nearest neighbour algorithm with gives nearest neighbour to points. But what I want is unique neighbour which is not shared by any other neighbour.&#xA;I've implemented this logic but it's very slow. You can review my code &lt;a href=&quot;https://codereview.stackexchange.com/questions/140292&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: Let's assume there're 2 galaxies with 5 stars in each. GalaxyA neighbour list(let's call it closestNeighbourList) in GalaxyB starting from closest to fartherest...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 0: [4, 1, 0, 3, 2]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 1: [2, 0, 4, 3, 1]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 2: [2, 1, 3, 0, 4]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 3: [0, 3, 2, 4, 1]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 4: [0, 3, 1, 4, 2]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;from these lists default first neighbour list:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 0: [4]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 1: [2]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 2: [2]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 3: [0]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 4: [0]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I want unique neighbour in GalaxyB, but here you see a problem, star 2 in GalaxyB is closest to two GalaxyA stars 1 &amp;amp; 2 and same for star 0. So these are not unique neighbour as shared by two or more stars. So to overcome this problem what I'm doing first storing all neighbours in a list(closestNeighbourList) then looping over those to check if it's closer to(shared by) some other star then go to next neighbour and when it's find unique neighbour break out of the loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;after applying unique neighbour algorithm first neighbour list will be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 0: [4]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 1: [2]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 2: [1]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 3: [3]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;star 4: [0]&lt;/p&gt;&#xA;" OwnerUserId="5021" LastEditorUserId="-1" LastEditDate="2017-04-13T12:41:06.387" LastActivityDate="2016-09-05T03:02:35.950" Title="How to get unique nearest neighbour?" Tags="&lt;performance&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3940" PostTypeId="1" AcceptedAnswerId="3941" CreationDate="2016-09-02T20:52:10.987" Score="3" ViewCount="69" Body="&lt;p&gt;In my simulation I draw a bunch of rectangles with GL_TRIANGLE_STRIP inside of one draw call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What will happen if I turn off GL_DEPTH_SORT? If all of the rectangles were stacked on top of themselves in a 2D screenspace sense would they always be in the same order?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm assuming it's just like when you do multiple draw calls (the first one is in back, the last one is in front) how it essentially just draws over what was previously drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using OpenglES 2.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also what happens with blend modes? Let's say I am doing additive blending, and then multiply the colors by 0.5 making them transparent. Would additive blending work?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorDisplayName="user246" LastEditDate="2017-03-13T00:22:51.953" LastActivityDate="2017-03-13T00:22:51.953" Title="What happens when GL_Depth is disabled" Tags="&lt;depth-map&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3941" PostTypeId="2" ParentId="3940" CreationDate="2016-09-02T22:01:12.723" Score="5" Body="&lt;p&gt;If depth testing is disabled, the triangles get drawn in the order they're submitted, i.e. the order they appear in the index buffer or vertex buffer. Later ones will overwrite earlier ones, or blend over them if blending is enabled. This ordering is guaranteed by all GPUs and APIs as far as I know.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-02T22:01:12.723" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3942" PostTypeId="1" CreationDate="2016-09-03T01:47:23.163" Score="4" ViewCount="1495" Body="&lt;p&gt;I'm trying to condense my Deferred Rendering G-Buffer. So I have some questions about getting 2-component Screenspace Normals. I know Frostbite and Killzone (the only two AAA company's G-Buffers I could find) use them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How are screenspace normals created, and is this step before or after using normal maps or bump maps? If it's done before using normal maps, how are normal maps going to be affected by the screenspace-ness of the normals, and if after, how can you justify using a Model-View matrix on all fragments rather on vertices? Isn't that a lot more calculations?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, how are they unpacked? I realize you can get the blue component using pythagoras, but how are they returned to world space?&lt;/p&gt;&#xA;" OwnerUserId="5026" LastActivityDate="2016-09-04T13:38:32.540" Title="Screenspace Normals - Creation, Normal Maps, and Unpacking" Tags="&lt;shader&gt;&lt;transformations&gt;&lt;deferred-rendering&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3943" PostTypeId="1" CreationDate="2016-09-03T01:48:41.327" Score="4" ViewCount="230" Body="&lt;p&gt;I have been working on how the GPU does parellel processing, and branching. However I am not yet to the point where I know how to make this shader more efficent. Essentially I dont know enough about how it works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway I have the following shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;varying vec3 o_color; //Color it should be&#xA;varying vec2 texture_coord; //Interpolated value 0-1&#xA;varying float ratio_out; //This is the height / width of the capsule on screen&#xA;varying float rdistOut; //This number is used to fill in all pixels when particle is slow enough for the geometry to be a square but still has some distance from last position.&#xA;&#xA;void main()&#xA;{&#xA;&#xA;&#xA;    vec2 yCoord = vec2(0.5);&#xA;    float yScale = ratio_out;&#xA;&#xA;    vec2 my = texture_coord * vec2(1.0, yScale);&#xA;&#xA;    vec2 del = yCoord - my;&#xA;&#xA;    float len = del.x * del.x + del.y * del.y;&#xA;    if ((!(my.y &amp;gt; 1.0) &amp;amp;&amp;amp; (len &amp;lt; 0.25)) || (my.y &amp;gt; yCoord.y &amp;amp;&amp;amp; my.y &amp;lt; rdistOut))&#xA;    {&#xA;        gl_FragColor = vec4(o_color, 1.0);&#xA;    }&#xA;    else&#xA;    {&#xA;        gl_FragColor.a = 0.0;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What it does is draw capsules on the screen. Basically these capsules connect where the particle was to where it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the cpu I compute the vertices of this with some linear algebra, but in screen space terms the rectangle we will be shading has a maximum width of &lt;code&gt;W&lt;/code&gt; and a minimum height of &lt;code&gt;W&lt;/code&gt;. If the capsule is moving faster then &lt;code&gt;W/2&lt;/code&gt; then the capsules geometry will start to get longer to accommodate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some diagrams of what is going on:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is an image of a single capsule. Because the distance between the current and last position is not large enough so the screen-space geometry is a square. You can see that to compensate that lighter area is shaded in as well to connect the two points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/J6619.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/J6619.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some more examples of what could happen&#xA;&lt;a href=&quot;https://i.stack.imgur.com/TEi8a.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TEi8a.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing is these capsules are all individual, sometimes every capsule will be elongated, sometimes it will only be a small percent. This shader needs to be as steady fps as possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now here are some tips that are useful and might help make things more efficent:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The dot product is NEVER needed past the point where the circle part is done.&lt;/li&gt;&#xA;&lt;li&gt;If the scaleFactor is greater then 1 then the dot product is never needed past the center of the circle.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This is shown in this diagram.  In this case none of the grey area needs to preform the dot product.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XWikU.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XWikU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Explanation of variables:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;o_color: is the color that that particle is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;texture_coord: these are the exact same as if you were going to texture this, they go from 0-1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ratio_out: height / width. Will never be less then 1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inside the main function to get the coordinates in screen scale we simply multiply the y texture coordinate by the scale factor. That makes the center of the circle part a 0.5, 0.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;rdistOut is the tiny area that the particle sometimes has when it is a square but still moving. Things should be shaded from 0.5-rdistOut.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you please help me remove un-needed dot product computations and comparisons as well as get rid of branching?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Please include an explanation of how you got the GPU to skip dot product calculations or why you did what you did. Next time I hope to be able to do this myself.&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2018-04-23T07:46:41.127" Title="I dont understand how a GPU computes and branches, could you please help me fix this shader preformance" Tags="&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3944" PostTypeId="2" ParentId="3942" CreationDate="2016-09-03T02:56:55.973" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;How are screenspace normals created, and is this step before or after using normal maps or bump maps?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;They are created after using normal maps. In deferred rendering, you write to the various buffers (diffuse, normal, depth, etc.) in fragment shaders. By this time, the normal maps would have already been read.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If it's done before using normal maps, how are normal maps going to be affected by the screenspace-ness of the normals,...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If you are referring to normal maps on models, normal maps can stay the same. You can compress normal maps as well if you want, but this becomes irrelevant to what you do for writing to the normal buffer.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;...and if after, how can you justify using a Model-View matrix on all fragments rather on vertices? Isn't that a lot more calculations?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Your model's normals are computed per vertex and interpolated through rasterization to be per fragment. The normal maps are processed per fragment, but these are just texture lookups, and these can be applied to the camera-space normals produced from the previous pipeline steps. Therefore, a view matrix is no longer necessary.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Finally, how are they unpacked? I realize you can get the blue component using pythagoras, but how are they returned to world space?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The idea behind 2-component normals versus 3-component normals is that the vector magnitude isn't often taken into account for normals. Also, normals facing away from the camera generally aren't useful. With two components, you can use model a hemisphere facing the camera. You unpack them the same way you pack them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think about normals as positions. When converting from world space (x, y, z) to screenspace (x, y, depth), but the depth does not effect where on the screen a mesh gets displayed. Convert the 3D vector to a vector in terms of screenspace (through view matrix multiplications).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can discard the z-component (aligned with the camera) as long as you normals are unit vectors (because you can derive z from the other two vectors).&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-09-03T04:07:59.903" LastActivityDate="2016-09-03T04:07:59.903" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3946" PostTypeId="1" CreationDate="2016-09-04T12:24:58.883" Score="14" ViewCount="3645" Body="&lt;p&gt;For a while I have been doing some research on the topic of Physically Based Rendering. One reflection model that is mentioned over and over is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Specular_highlight#Cook.E2.80.93Torrance_model&quot; rel=&quot;noreferrer&quot;&gt;Cook-Torrance&lt;/a&gt; / Torrance-Sparrow model. It seems like in each mention or explanation of this model a different form of the specular term is used. The versions I have found are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;$${\frac {FDG}{\pi ({\vec N}\cdot {\vec V})({\vec N}\cdot {\vec L})}}$$&lt;/li&gt;&#xA;&lt;li&gt;$${\frac {FDG}{4 ({\vec N}\cdot {\vec V})({\vec N}\cdot {\vec L})}}$$&lt;/li&gt;&#xA;&lt;li&gt;$${\frac {FDG}{({\vec N}\cdot {\vec V})({\vec N}\cdot {\vec L})}}$$&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Which one is correct, and when? In &lt;em&gt;&lt;a href=&quot;http://www.pbrt.org/&quot; rel=&quot;noreferrer&quot;&gt;Physically Based Rendering: From Theory to Implementation&lt;/a&gt;&lt;/em&gt; by Matt Pharr and Greg Humphreys, the second one is conclusively derived, but in their original paper Cook and Torrance use the first one without any detailed explanation.&lt;/p&gt;&#xA;" OwnerUserId="5033" LastEditorUserId="5033" LastEditDate="2016-09-04T23:48:37.567" LastActivityDate="2017-10-25T11:47:19.843" Title="Correct Specular Term of the Cook-Torrance / Torrance-Sparrow Model" Tags="&lt;rendering&gt;&lt;mathematics&gt;&lt;physically-based&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="3947" PostTypeId="2" ParentId="3942" CreationDate="2016-09-04T13:38:32.540" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I'm trying to condense my Deferred Rendering G-Buffer. So I have some questions about getting 2-component Screenspace Normals. I know Frostbite and Killzone (the only two AAA company's G-Buffers I could find) use them.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm confused when you say &quot;screenspace normals&quot;, Killzone uses view-space normals, they store the X &amp;amp; Y coordinate of the normal in FP16 format, and reconstruct Z using $z = sqrt(1.0 - Normal.x^2 - Normal.y2)$ a problem with that is that we lack the sign of Z, even in view-space the normals can point away from the camera, i.e. Z is not always positive.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;How are screenspace normals created, and is this step before or after using normal maps or bump maps? If it's done before using normal maps, how are normal maps going to be affected by the screenspace-ness of the normals, and if after, how can you justify using a Model-View matrix on all fragments rather on vertices? Isn't that a lot more calculations?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;After loading your normal maps, you construct a TBN matrix to transform from tangent space to e.g. world space before writing to the G-Buffer. So in essence, your normals in the G-Buffer are stored in world-space, not screen-space. With that you can apply lighting in world space, as far as I'm aware, Crytek &amp;amp; Epic do the lighting in world-space now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure what you mean by &quot;screenspace-ness&quot;, but when writing any sort of data to the G-Buffer, you're essentially writing their current value, if the normals are in world-space, they will remain in world-space when written to the G-Buffer. When you sample the G-Buffer on the second pass, for each texel, you get an RGB color (assuming you're using RGB) that maps to your coordinate data.&lt;/p&gt;&#xA;" OwnerUserId="2351" LastActivityDate="2016-09-04T13:38:32.540" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3948" PostTypeId="2" ParentId="1759" CreationDate="2016-09-04T23:51:57.767" Score="8" Body="&lt;p&gt;Identifying your axes in both figures and adding the camera position to your first figure would help you understand what's going on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could also have a single variables for all your points, generating a 2D matrix with the rows as each point and columns as the components $x$, $y$ and $z$. That way, you could handle the projection using a simple matrix multiplication instead of handling each row separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the problem statement, would be interesting to know the direction of your rotation, and more importantly, the original camera direction and its up vector. I guess you camera is rotated by 160° counter-clockwise, the original camera direction is $[0, 0, 1]$ and its up vector is $[0, 1, 0]$. If any of those assumptions is wrong, the rest of the answer will be wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is no sign of mm to m conversion in your code. Either your focal should be $0.016$ and $S_x = S_y = 0.0001$ or your point coordinates should be multiplied by $0.00001$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's reason about where should the points end up in your image. For example, your camera center, without rotation, is pointing at the $[-1,1,x]$ line. Since the points are all on the $z=0.5$ plane, we can do the following analysis: if we focus on the $x$-axis, we can see that $tan(160°) \cdot (5 - 0.5) = 1.64...$, so the camera center will end up slightly to the left of the points (as the camera is at $x=-1$), so the center will end up at $\approx 0.64$, meaning that the points will appear on the right section of the image. Furthermore, the camera has the same $y$ coordinates as two point, and since the $y$ coordinates are not changed by the rotation, they should still end up on the same coordinates after the transform, meaning on the central row of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A good way to check your answer is by using an existing 3D modeler like Blender:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/VIypz.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VIypz.png&quot; alt=&quot;3D scene in Blender&quot;&gt;&lt;/a&gt;&#xA;Be cautious with Blender' coordinates system, for example the default camera vector is &lt;code&gt;[0, 0, -1]&lt;/code&gt;.&#xA;Here's the render:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SLLK5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SLLK5.png&quot; alt=&quot;Render in Blender&quot;&gt;&lt;/a&gt;&#xA;Focal was set to another value to make the sphere more visible. So we see that the bottom two points are on the middle row of the image and the points are slightly to the right of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I implemented your homework in Python:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;&#xA;from matplotlib import pyplot as plt&#xA;from mpl_toolkits.mplot3d import axes3d, Axes3D&#xA;&#xA;&#xA;# Parameters&#xA;f_mm = 0.016&#xA;f_px = f_mm / 0.00001&#xA;t_cam = np.array([[-1., 1., 5.]]).T&#xA;t_cam_homogeneous = np.vstack((t_cam, np.array([[0]])))&#xA;theta = 160. * np.pi / 180.&#xA;ox = 320&#xA;oy = 240&#xA;# Rotation and points are in homogeneous coordinates&#xA;rot_cam = np.array([[np.cos(theta), 0, np.sin(theta)],&#xA;                    [0, 1, 0],&#xA;                    [-np.sin(theta), 0, np.cos(theta)]])&#xA;points = np.array([[1, 1, 0.5, 1],&#xA;                   [1, 1.5, 0.5, 1],&#xA;                   [1.5, 1.5, 0.5, 1],&#xA;                   [1.5, 1, 0.5, 1]]).T&#xA;&#xA;# Compute projection matrix using intrinsics and extrinsics&#xA;intrinsics = np.array([[f_px, 0, ox],&#xA;                       [0, f_px, oy],&#xA;                       [0, 0, 1]])&#xA;extrinsics = np.hstack((rot_cam, rot_cam.dot(-t_cam)))&#xA;&#xA;rot_cam2 = np.identity(4); rot_cam2[:3,:3] = rot_cam&#xA;camera_coordinates = rot_cam2.dot(points - t_cam_homogeneous)&#xA;camera_coordinates = camera_coordinates[:3,:] / camera_coordinates[3,:]&#xA;&#xA;# Perform the projection&#xA;projected_points = intrinsics.dot(camera_coordinates)&#xA;projected_points = projected_points[:2,:] / projected_points[2,:]&#xA;projected_points[0,:] = -projected_points[0,:] # Inverted x-axis because camera is pointing toward [0, 0, 1]&#xA;&#xA;fig = plt.figure()&#xA;ax = Axes3D(fig)&#xA;ax.scatter(points[0,:], points[1,:], points[2,:], label=&quot;Points&quot;)&#xA;ax.scatter(t_cam[0], t_cam[1], t_cam[2], c=&quot;red&quot;, label=&quot;Camera&quot;)&#xA;ax.set_xlabel(&quot;X axis&quot;); ax.set_ylabel(&quot;Y axis&quot;); ax.set_zlabel(&quot;Z axis&quot;)&#xA;plt.title(&quot;World coordinates&quot;)&#xA;plt.legend()&#xA;plt.savefig('world_coordinates.png', dpi=300, bbox_inches=&quot;tight&quot;)&#xA;&#xA;fig = plt.figure()&#xA;ax = Axes3D(fig)&#xA;ax.scatter(camera_coordinates[0,:], camera_coordinates[1,:], camera_coordinates[2,:], label=&quot;Points&quot;)&#xA;ax.scatter(0, 0, 0, c=&quot;red&quot;, label=&quot;Camera&quot;)&#xA;ax.set_xlabel(&quot;X axis&quot;); ax.set_ylabel(&quot;Y axis&quot;); ax.set_zlabel(&quot;Z axis&quot;)&#xA;plt.title(&quot;Camera coordinates&quot;)&#xA;plt.legend()&#xA;plt.savefig('camera_coordinates.png', dpi=300, bbox_inches=&quot;tight&quot;)&#xA;&#xA;plt.figure()&#xA;plt.scatter(projected_points[0,:], projected_points[1,:])&#xA;plt.xlabel(&quot;X axis&quot;); plt.ylabel(&quot;Y axis&quot;)&#xA;plt.title(&quot;Image coordinates&quot;)&#xA;plt.savefig('image_coordinates.png', dpi=300, bbox_inches=&quot;tight&quot;)&#xA;&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This yield me those figures:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Ky8jK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ky8jK.png&quot; alt=&quot;World coordinates&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cjiTE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cjiTE.png&quot; alt=&quot;Camera coordinates&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/aybff.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aybff.png&quot; alt=&quot;Camera coordinates rotated&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Ca7xs.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ca7xs.png&quot; alt=&quot;Image coordinates&quot;&gt;&lt;/a&gt;&#xA;Respectively: World coordinates, Camera coordinates, Camera coordinates rotated to fit &lt;em&gt;slightly&lt;/em&gt; the camera orientation (note that here the camera vector goes toward the figure viewpoint, it does not &quot;enter&quot; the figure) and image coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So we see that the vertical coordinates for the bottom points are correctly on the middle row (240) and the points are on the right side of the image (horizontal value &gt; 320).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe one bug you had is that you found negative X values, so you negated the focals (&lt;code&gt;-f/Sxy&lt;/code&gt;) in the intrinsics matrix to compensate. The issue here is that we've assumed that the camera initially was pointing toward $[0, 0, 1]$ (otherwise the 160° rotation would not point toward the points). If you look at it that way, the $x$-axis increases when going toward the &lt;em&gt;left&lt;/em&gt;, the inverse of this axis should be taken.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both our results seems similar to me, just that you supposed a $[0, -1, 0]$ up vector for the camera (in fact both axes were mirrored because you negated both focals), and did the computation in mm instead of meters.&lt;/p&gt;&#xA;" OwnerUserId="5039" LastActivityDate="2016-09-04T23:51:57.767" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3949" PostTypeId="2" ParentId="3939" CreationDate="2016-09-05T03:02:35.950" Score="1" Body="&lt;p&gt;After asking around a bit on Twitter, I found that what you're trying to solve seems to be an instance of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Assignment_problem&quot; rel=&quot;nofollow&quot;&gt;assignment problem&lt;/a&gt;. In general, the assignment problem is to take two sets and assign elements of one to the other, in such a way that a cost function is minimized.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case the two sets would be the stars in each galaxy, and the cost function would be the distances between stars. An optimal solution to the assignment problem would then minimize the total distance between corresponding stars, summed over all the stars in the galaxies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A classic algorithm for solving the assignment problem is called the &lt;a href=&quot;https://en.wikipedia.org/wiki/Hungarian_algorithm&quot; rel=&quot;nofollow&quot;&gt;Hungarian algorithm&lt;/a&gt;. If you google around, you'll some explanations of how it works. There's even a Python module implementing this algorithm, called &lt;a href=&quot;http://software.clapper.org/munkres/&quot; rel=&quot;nofollow&quot;&gt;Munkres&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A warning: this algorithm runs in $O(n^3)$ time, so it will be rather slow for large point sets. You might want to do some further research on fast algorithms for the assignment problem. It may be that you can find a faster, approximate algorithm if you don't require a perfectly optimal solution. Or maybe there are specialized algorithms for the case of point clouds that can do better.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-05T03:02:35.950" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3950" PostTypeId="2" ParentId="3946" CreationDate="2016-09-05T08:49:28.463" Score="0" Body="&lt;p&gt;Personally I have used equation 2. Equation 3 seems incorrect to me, the Pi factor is to normalise the light response and for energy conservation. Essentially you do not want more light to be reflected from the surface than what it receives. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Equation 2 is an improvement of equation 1 and is more correct as far as I'm aware. For more information about equation 2, see &lt;strong&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/strong&gt; by Walter et al&lt;/p&gt;&#xA;" OwnerUserId="2351" LastActivityDate="2016-09-05T08:49:28.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3951" PostTypeId="2" ParentId="3904" CreationDate="2016-09-05T09:55:45.350" Score="2" Body="&lt;p&gt;Standard blur removes high frequency content from the signal, whereas edge detection usually look into high frequency to detect edges. Be careful on how much blurring to apply to ensure that you don't lose desirable edges. The goal of blurring is to perform &lt;strong&gt;noise reduction&lt;/strong&gt;, so the best would be to come up with a model of the noise present in your images and what your desired edges looks like (their frequency, orientation, what caused them: shading on a smooth object, shadows, etc.) and tailor your blur filter to remove the noise but not the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Seems like you want to implement an edge detector into a shader. Be sure to check what are the sources of noise in your image. For example, if you are displaying pure lambertian surfaces, chances are that there is virtually no noise in your data, so you don't need to apply a smoothing filter before detecting edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, instead of using a standard gaussian blur, you could look into &lt;a href=&quot;https://en.wikipedia.org/wiki/Edge-preserving_smoothing&quot; rel=&quot;nofollow&quot;&gt;edge-preserving filters&lt;/a&gt; like the bilateral filter. It is much slower, but is good to remove noise without altering too much the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are performing filtering and edge detection through convolutions (the standard way of doing it), it doesn't matter if you do one before another, as convolutions are commutative, meaning $a*b = b*a$, where $*$ is the convolution operator, $a$ being the edge detector and $b$ the smoothing kernel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On non-associative operations (like the bilateral filter), you must ask yourself the question &quot;what is the goal of this operation?&quot; Basically, blurring before the edge detection will diminish the image noise while blurring after will give you blurred edges (potentially caused by noise) instead of sharp edges. The same edges will be found, though, but the blurred one will be less precise. It depends on what you want to achieve: it could be interesting for art, but it just removes interesting information for signal analysis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not sure what &quot;applying an edge to a color buffer&quot; means; is the goal to perform &lt;a href=&quot;https://en.wikipedia.org/wiki/Edge_enhancement&quot; rel=&quot;nofollow&quot;&gt;edge enhancement&lt;/a&gt;?&lt;/p&gt;&#xA;" OwnerUserId="5039" LastActivityDate="2016-09-05T09:55:45.350" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3952" PostTypeId="1" CreationDate="2016-09-05T11:07:12.020" Score="5" ViewCount="134" Body="&lt;p&gt;I am creating a simple 3D engine as a learning project to get the hang on spherical trigonometry. I am using the following approach.&#xA;1. A model consists of a lot of triangular faces.&#xA;2. Each triangle is rendered through finding where the vectors pointing to the corners of it intersect a plane. This creates a flat projection I draw to the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eoV3E.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eoV3E.png&quot; alt=&quot;projection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have already implemented this, and it works great, except when some of the corners of a triangle are located behind me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/w8Sw8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/w8Sw8.png&quot; alt=&quot;outside the view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is quite obvious what the problem is: The vector pointing to the corner is never intersecting the plane. But I need a point to render the projection, as a part of the triangle is visible.&#xA;That causes trouble. I can not place the third corner anywhere on my projection plane, as the edges of the projected triangle are diverging when they escape the field of view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Logically, the edges of the projected triangle are thus pointing towards two &lt;strong&gt;different&lt;/strong&gt; points on the plane outside the frame (or on the frame border, depending on taste and size of data types).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QKBLG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QKBLG.png&quot; alt=&quot;frame of view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suddenly having to deal with rendering a four-sided polygon instead of a triangle is no problem, my rasterization algorithms are flexible. I can however not figure out how to calculate the locations of the new &quot;off-screen&quot; points. How can I find them?&lt;/p&gt;&#xA;" OwnerUserId="5043" LastActivityDate="2016-09-05T13:32:14.480" Title="Where should I project a polygon corner when it is behind me?" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;projections&gt;&lt;polygon&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="3953" PostTypeId="2" ParentId="3943" CreationDate="2016-09-05T12:09:40.927" Score="6" Body="&lt;p&gt;Rather than trying to speed up your shader by fiddling with the code, can I suggest you make use of the GPU's inherent ability to rapidly fill polygons? This will allow it to eliminate the vast bulk of the cases where there is no need to even make a decision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I suggest you try is &lt;em&gt;something&lt;/em&gt; like the following: Create, say, a heptagon (i.e. the blue dashed outline (&lt;em&gt;note: it shares some of the boundary with the green but I just noticed this is not particularly obvious in the diagram&lt;/em&gt;)) that starts from the original location and extends to the new position but lies inside the extremes of the new location's circle. &#xA;The shader for this is then utterly trivial.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UXeIn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UXeIn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there can be one or two cases depending on how much you want to optimise. If the tail extends outside of the end position circle, you draw the green-dashed nonagon with your decision-based shader. This contains vastly fewer pixels. &#xA;If the tail doesn't extend outside, then you'll need to mirror this polygon to get the other side of the circle. Alternatively, rather than make the decision, you could always mirror it and let the Z-test eliminate unneeded fills.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your examples also have the have the capsules shown as opaque. If this is the case, you can also make gains with, say, TBDR-systems (a blatant PowerVR plug :-) ) or those with early-Z, provided you supply all your opaque &quot;tail&quot; portions first and then follow with all parts requiring decisions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shapes of course were just examples. You may find it's better to use more segments in your outlines in order to reduce the regions requiring the complex shader.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-04-23T07:46:41.127" LastActivityDate="2018-04-23T07:46:41.127" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3954" PostTypeId="2" ParentId="3952" CreationDate="2016-09-05T13:32:14.480" Score="2" Body="&lt;p&gt;Trying to explain a problem seems to help the thought process. This is what eventually worked for me:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I realized that I can easily find the point (in 3D space) where a line between two of the corners brakes through one of the walls in my pyramid field of view, given the coordinates of the out-of-view corner and one of the visible ones. It is only a matter of finding the intersection between two lines. The position of the intersection point gives away the height on the frame wall.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fOz83.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fOz83.png&quot; alt=&quot;wall intersection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Self answer, yes, but nothing came to mind before posting at SE.&lt;/p&gt;&#xA;" OwnerUserId="5043" LastActivityDate="2016-09-05T13:32:14.480" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3955" PostTypeId="1" AcceptedAnswerId="3959" CreationDate="2016-09-05T21:20:35.890" Score="17" ViewCount="7947" Body="&lt;p&gt;I implemented a physically based path tracer after studying PBRT by M. Pharr and G. Humphreys. Now I'm trying to apply physically based rendering to real time graphics using OpenGL ES (in an iPhone application).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to start using Oren-Nayar and Cook-Torrance as diffuse and specular BRDF but I have a problem: how do I model indirect lighting?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a path tracer (like the one contained in pbrt) the indirect/ambient light is given &quot;automatically&quot; from the path tracing algorithm, as it follows the path of light rays taking into account direct and indirect lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I model the indirect lighting in a physically based render written in OpenGL ES, so using real time computer graphics?&lt;/p&gt;&#xA;" OwnerUserId="2237" LastActivityDate="2016-10-12T04:53:32.390" Title="Physically based shading - ambient/indirect lighting" Tags="&lt;real-time&gt;&lt;physically-based&gt;&lt;shading&gt;&lt;opengl-es&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="20" ContentLicense="CC BY-SA 3.0" />
  <row Id="3956" PostTypeId="2" ParentId="3946" CreationDate="2016-09-05T21:50:21.310" Score="13" Body="&lt;p&gt;I would trust Pharr and Humphreys on this. Equation 2 also agrees with the &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf#57&quot; rel=&quot;noreferrer&quot;&gt;SIGGRAPH Physically Based Rendering course notes&lt;/a&gt;, as well as with equation 20 in the &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;noreferrer&quot;&gt;Walter et al paper&lt;/a&gt; that introduced the GGX distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read somewhere that there is an error in the original Cook-Torrance paper that led them to miss the factor of 4 in the denominator, which was corrected in subsequent papers. I couldn't find a reference to this with a quick search though (if anyone knows one, please feel free to note it in the comments).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the factor of π, it might appear or not, depending on conventions. Sometimes it's factored into the normal distribution function D. For instance, if you look in the Walter et all GGX paper section 5.2 where they give the equations for several D functions, you can see they all have a π in the denominator. Note that this implies that the Lambertian BRDF should have a π in the denominator as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In real-time graphics, the π is often left out, in which case we can interpret it as &lt;a href=&quot;https://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/&quot; rel=&quot;noreferrer&quot;&gt;having been factored into the light colors&lt;/a&gt;. Either way is fine, as long as you're consistent about either putting the π in or leaving it out of &lt;em&gt;all&lt;/em&gt; the BRDFs you use.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-05T21:50:21.310" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3957" PostTypeId="2" ParentId="3955" CreationDate="2016-09-05T22:34:44.773" Score="0" Body="&lt;p&gt;Path tracing is a very computationally expensive algorithm, and not suited to real-time. PBRT's architecture is not suited to real-time either, the main goal of PBRT is to solve the rendering equation, using unbiased Monte Carlo integration. See &lt;a href=&quot;https://en.wikipedia.org/wiki/Unbiased_rendering&quot; rel=&quot;nofollow&quot;&gt;https://en.wikipedia.org/wiki/Unbiased_rendering&lt;/a&gt; for more info.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Without a lot of optimization and constraints, I doubt you'll be able to reach decent performance on a mobile device.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, path tracing can be implemented in OpenGL, I would suggest to look into &lt;strong&gt;compute shaders&lt;/strong&gt; which are very powerful. OpenGL ES 3.1 supports compute shaders with some minor limitations, in contrast to Desktop GL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have a read through this page to get more information: &lt;a href=&quot;https://github.com/LWJGL/lwjgl3-wiki/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-(Part-I)&quot; rel=&quot;nofollow&quot;&gt;https://github.com/LWJGL/lwjgl3-wiki/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-(Part-I)&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best of luck!&lt;/p&gt;&#xA;" OwnerUserId="2351" LastActivityDate="2016-09-05T22:34:44.773" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3959" PostTypeId="2" ParentId="3955" CreationDate="2016-09-06T07:34:23.493" Score="41" Body="&lt;p&gt;Real-time graphics deploys a variety of approximations to deal with the computational expense of simulating indirect lighting, trading off between runtime performance and lighting fidelity. This is an area of active research, with new techniques appearing every year.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Ambient lighting&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;At the very simplest end of the range, you can use &lt;a href=&quot;https://en.wikipedia.org/wiki/Shading#Ambient_lighting&quot; rel=&quot;noreferrer&quot;&gt;&lt;strong&gt;ambient lighting&lt;/strong&gt;&lt;/a&gt;: a global, omnidirectional light source that applies to every object in the scene, without regard to actual light sources or local visibility. This is not at all accurate, but is extremely cheap, easy for an artist to tweak, and can look okay depending on the scene and the desired visual style.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Common extensions to basic ambient lighting include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Make the ambient color vary directionally, e.g. using &lt;a href=&quot;https://dickyjim.wordpress.com/2013/09/04/spherical-harmonics-for-beginners/&quot; rel=&quot;noreferrer&quot;&gt;spherical harmonics (SH)&lt;/a&gt; or a &lt;a href=&quot;http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf#5&quot; rel=&quot;noreferrer&quot;&gt;small cubemap&lt;/a&gt;, and looking up the color in a shader based on each vertex's or pixel's normal vector. This allows some visual differentiation between surfaces of different orientations, even where no direct light reaches them.&lt;/li&gt;&#xA;&lt;li&gt;Apply &lt;a href=&quot;https://en.wikipedia.org/wiki/Ambient_occlusion&quot; rel=&quot;noreferrer&quot;&gt;ambient occlusion (AO)&lt;/a&gt; techniques including pre-computed vertex AO, AO texture maps, &lt;a href=&quot;http://www.gdcvault.com/play/1015320/Ambient-Occlusion-Fields-and-Decals&quot; rel=&quot;noreferrer&quot;&gt;AO fields&lt;/a&gt;, and &lt;a href=&quot;http://graphics.cs.williams.edu/papers/SAOHPG12/&quot; rel=&quot;noreferrer&quot;&gt;screen-space AO (SSAO)&lt;/a&gt;. These all work by attempting to detect areas such as holes and crevices where indirect light is less likely to bounce into, and darkening the ambient light there.&lt;/li&gt;&#xA;&lt;li&gt;Add an &lt;a href=&quot;http://learnopengl.com/#!Advanced-OpenGL/Cubemaps&quot; rel=&quot;noreferrer&quot;&gt;environment cubemap&lt;/a&gt; to provide ambient specular reflection. A cubemap with a decent resolution (128² or 256² per face) can be quite convincing for specular on curved, shiny surfaces.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2&gt;Baked indirect lighting&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The next &quot;level&quot;, so to speak, of techniques involve &lt;strong&gt;baking&lt;/strong&gt; (pre-computing offline) some representation of the indirect lighting in a scene. The advantage of baking is you can get pretty high-quality results for little real-time computational expense, since all the hard parts are done in the bake. The trade-offs are that the time needed for the bake process harms level designers' iteration rate; more memory and disk space are required to store the precomputed data; the ability to change the lighting in real-time is very limited; and the bake process can only use information from static level geometry, so indirect lighting effects from dynamic objects such as characters will be missed. Still, baked lighting is very widely used in AAA games today.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The bake step can use any desired rendering algorithm including path tracing, radiosity, or using the game engine itself to render out cubemaps (or &lt;a href=&quot;http://the-witness.net/news/2010/09/hemicube-rendering-and-integration/&quot; rel=&quot;noreferrer&quot;&gt;hemicubes&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The results can be stored in textures (&lt;a href=&quot;https://en.wikipedia.org/wiki/Lightmap&quot; rel=&quot;noreferrer&quot;&gt;lightmaps&lt;/a&gt;) applied to static geometry in the level, and/or they can also be converted to SH and stored in volumetric data structures, such as &lt;a href=&quot;http://simonstechblog.blogspot.com/2014_10_01_archive.html&quot; rel=&quot;noreferrer&quot;&gt;irradiance volumes&lt;/a&gt; (volume textures where each texel stores an SH probe) or &lt;a href=&quot;http://www.gdcvault.com/play/1015312/Light-Probe-Interpolation-Using-Tetrahedral&quot; rel=&quot;noreferrer&quot;&gt;tetrahedral meshes&lt;/a&gt;. You can then use shaders to look up and interpolate colors from that data structure and apply them to your rendered geometry. The volumetric approach allows baked lighting to be applied to dynamic objects as well as static geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The spatial resolution of the lightmaps etc. will be limited by memory and other practical constraints, so you might supplement the baked lighting with some AO techniques to add high-frequency detail that the baked lighting can't provide, and to respond to dynamic objects (such as darkening the indirect light under a moving character or vehicle).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's also a technique called &lt;a href=&quot;http://www0.cs.ucl.ac.uk/staff/j.kautz/PRTCourse/&quot; rel=&quot;noreferrer&quot;&gt;precomputed radiance transfer (PRT)&lt;/a&gt;, which extends baking to handle more dynamic lighting conditions. In PRT, instead of baking the indirect lighting itself, you bake the &lt;em&gt;transfer function&lt;/em&gt; from some source of light—usually the sky—to the resultant indirect lighting in the scene. The transfer function is represented as a matrix that transforms from source to destination SH coefficients at each bake sample point. This allows the lighting environment to be changed, and the indirect lighting in the scene will respond plausibly. &lt;a href=&quot;http://www.gdcvault.com/play/1015326/Deferred-Radiance-Transfer-Volumes-Global&quot; rel=&quot;noreferrer&quot;&gt;Far Cry 3 and 4 used this technique&lt;/a&gt; to allow a continuous day-night cycle, with indirect lighting varying based on the sky colors at each time of day.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One other point about baking: it may be useful to have separate baked data for diffuse and specular indirect lighting. Cubemaps work much better than SH for specular (since cubemaps can have a lot more angular detail), but they also take up a lot more memory, so you can't afford to place them as densely as SH samples. &lt;a href=&quot;https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/&quot; rel=&quot;noreferrer&quot;&gt;Parallax correction&lt;/a&gt; can be used to somewhat make up for that, by heuristically warping the cubemap to make its reflections feel more grounded to the geometry around it.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Fully real-time techniques&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Finally, it's possible to compute fully dynamic indirect lighting on the GPU. It can respond in real-time to arbitrary changes of lighting or geometry. However, again there is a tradeoff between runtime performance, lighting fidelity, and scene size. Some of these techniques need a beefy GPU to work at all, and may only be feasible for limited scene sizes. They also typically support only a single bounce of indirect light.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A dynamic environment cubemap, where the faces of the cubemap are re-rendered each frame using six cameras clustered around a chosen point, can provide decently good ambient reflections for a single object. This is often used for the player car in racing games, for instance.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://people.mpi-inf.mpg.de/~ritschel/Papers/SSDO.pdf&quot; rel=&quot;noreferrer&quot;&gt;Screen-space global illumination&lt;/a&gt;, an extension of SSAO that gathers bounce lighting from nearby pixels on the screen in a post-processing pass.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://casual-effects.blogspot.com/2014/08/screen-space-ray-tracing.html&quot; rel=&quot;noreferrer&quot;&gt;Screen-space raytraced reflection&lt;/a&gt; works by ray-marching through the depth buffer in a post-pass. It can provide quite high-quality reflections as long as the reflected objects are on-screen.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.cg.tuwien.ac.at/courses/RendEng/RendEng-2016-01-11-InstantRadiosity.pdf&quot; rel=&quot;noreferrer&quot;&gt;Instant radiosity&lt;/a&gt; works by tracing rays into the scene using the CPU, and placing a point light at each ray hit point, which approximately represents the outgoing reflected light in all directions from that ray. These many lights, known as virtual point lights (VPLs), are then rendered by the GPU in the usual way.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.klayge.org/material/3_12/GI/rsm.pdf&quot; rel=&quot;noreferrer&quot;&gt;Reflective shadow maps (RSMs)&lt;/a&gt; are similar to instant radiosity, but the VPLs are generated by rendering the scene from the light's point of view (like a shadow map) and placing a VPL at each pixel of this map.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.crytek.com/download/Light_Propagation_Volumes.pdf&quot; rel=&quot;noreferrer&quot;&gt;Light propagation volumes&lt;/a&gt; consist of 3D grids of SH probes placed throughout the scene. RSMs are rendered and used to &quot;inject&quot; bounce light into the SH probes nearest the reflecting surfaces. Then a flood-fill-like process propagates light from each SH probe to surrounding points in the grid, and the result of this is used to apply lighting to the scene. This technique &lt;a href=&quot;https://newq.net/archived/www.cse.chalmers.se/pub/scatter/index.html&quot; rel=&quot;noreferrer&quot;&gt;has been extended to volumetric light scattering&lt;/a&gt; as well.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://maverick.inria.fr/Publications/2011/CNSGE11b/&quot; rel=&quot;noreferrer&quot;&gt;Voxel cone tracing&lt;/a&gt; works by voxelizing the scene geometry (likely using varying voxel resolutions, finer near the camera and coarser far away), then injecting light from RSMs into the voxel grid. When rendering the main scene, the pixel shader performs a &quot;cone trace&quot;—a ray-march with gradually increasing radius—through the voxel grid to gather incoming light for either diffuse or specular shading.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Most of these techniques are not widely used in games today due to problems scaling up to realistic scene sizes, or other limitations. The exception is screen-space reflection, which is very popular (though it's usually used with cubemaps as a fallback, for regions where the screen-space part fails).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, real-time indirect lighting is a huge topic and even this (rather long!) answer can only provide a 10,000-foot overview and context for further reading. Which approach is best for you will depend greatly on the details of your particular application, what constraints you're willing to accept, and how much time you have to put into it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-10-12T04:53:32.390" LastActivityDate="2016-10-12T04:53:32.390" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3960" PostTypeId="1" CreationDate="2016-09-06T07:56:59.850" Score="2" ViewCount="345" Body="&lt;p&gt;I'm still working on my BRDF equations. Theoretically, all equations are correct, but the hilights are super sharp. I'm not sure if this is a result of  me not using Image-Based Lighting (I currently use just an env map with a LOD function). I'm using materials from here: &lt;a href=&quot;http://freepbr.com/c/base-materials/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://freepbr.com/c/base-materials/&lt;/a&gt; - I use Specular/Gloss but the materials use the fragment shader to convert it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pjbtv.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pjbtv.jpg&quot; alt=&quot;Bright Highlights&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Material Frag Shader (Excerpt) (Specifically, the Metalness-Roughness shader):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Roughness = baseSpecular.a;&#xA;if (uTexRoughEnabled == 1)&#xA;    Roughness = texture(texRoughness, UV).r;&#xA;&#xA;float Metalness = texture(texSpecular, UV).r;&#xA;&#xA;// 1 - Roughness becomes Glossiness&#xA;specular = vec4(mix(vec3(0.4), albedo.rgb, Metalness), 1-Roughness);&#xA;albedo = vec4(mix(albedo.rgb, vec3(0), Metalness), 1-Roughness);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Lighting Functions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 Light_F(in vec3 Specular, in float VH) {&#xA;    // Fresnel Schlick&#xA;    return Specular + (1-Specular) * pow(1-VH, 5.0f);&#xA;}&#xA;&#xA;float Light_D(in float alpha, in float NH) {&#xA;    // GGX&#xA;    float alphaSqr = alpha*alpha;&#xA;    float denom = NH * NH * (alphaSqr - 1) + 1;&#xA;&#xA;    return alphaSqr / (pi * denom * denom);&#xA;}&#xA;&#xA;float Light_V( in float NL, in float NV, in float alpha ) {&#xA;    // Frostbite's GGX&#xA;    float Lambda_GGXV = NL * sqrt (( - NV * alpha + NV ) * NV + alpha );&#xA;    float Lambda_GGXL = NV * sqrt (( - NL * alpha + NL ) * NL + alpha );&#xA;&#xA;    return 0.5f / ( Lambda_GGXV + Lambda_GGXL );&#xA;}&#xA;&#xA;vec3 Light_Diffuse(in float NV, in float NL, in vec3 Normal, in float alpha, in vec3 Albedo, in vec3 eyeDir, in vec3 lightDir) {&#xA;        // Oren-Nayar&#xA;        float gamma = dot( eyeDir - Normal * NV, lightDir - Normal * NL);&#xA;        float A = 1.0f - 0.5f * (alpha / (alpha + 0.57f));&#xA;        float B = 0.45f * (alpha / (alpha + 0.09));&#xA;    float diffAlpha = max( acos( NV ), acos( NL ) );&#xA;    float diffBeta  = min( acos( NV ), acos( NL ) );&#xA;    float C = sin(diffAlpha) * tan(diffBeta);&#xA;    return Albedo * (A + B * max( 0.0f, gamma ) * C) / pi;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Final lighting function in deferred renderer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 LightCalc(in vec3 Albedo, in vec4 WorldPos, in vec4 Specular, in vec3 Normal, in samplerCube envMap, in vec3 lightPos, in float lightAtten, in vec4 lightColor) {&#xA;    vec3 lightDir   = WorldPos.xyz - lightPos;&#xA;    vec3 eyeDir = normalize(eyePos - WorldPos.xyz);&#xA;    vec3 eyeReflect = reflect(-eyeDir, Normal);&#xA;&#xA;    float Distance  = length(lightDir);&#xA;    lightDir        = -normalize(lightDir);&#xA;&#xA;    float Attenuation = clamp(1 - pow(Distance / lightAtten, 4), 0, 1);&#xA;    Attenuation = Attenuation*Attenuation/(Distance*Distance+1);&#xA;&#xA;    vec3 AmbientColor = vec3(Albedo.xyz)*0.01;&#xA;&#xA;    float Roughness = 1-Specular.a;&#xA;    float alpha = Roughness * Roughness;&#xA;&#xA;    vec3 H = normalize(eyeDir + lightDir);&#xA;&#xA;    float NL = clamp(dot(Normal, lightDir), 0, 1);&#xA;    float NH = clamp(dot(Normal, H), 0, 1);&#xA;    float NV = clamp(dot(Normal, eyeDir), 0, 1);&#xA;    float LH = clamp(dot(lightDir, H), 0, 1);&#xA;    float VH = clamp(dot(eyeDir, H), 0, 1);&#xA;&#xA;    float lod = compute_lod(alpha, 1, NH);&#xA;    vec3 reflectDir = normalize(eyeReflect);&#xA;    vec3 reflectPix = textureLod(envMap, reflectDir, lod).rgb;&#xA;&#xA;    float D = Light_D(alpha, NH);&#xA;    vec3 F = Light_F(clamp(Specular.rgb, 0.018, 0.95), LH);&#xA;    float Vis = Light_V(NL, NV, alpha);&#xA;    vec3 Spec = (D * F * Vis) * reflectPix;&#xA;&#xA;&#xA;    vec3 Diffuse = Light_Diffuse(NV, NL, Normal, alpha, Albedo.rgb, eyeDir, lightDir);&#xA;&#xA;    vec3 lightModifier = lightColor.xyz*lightColor.w*Attenuation;&#xA;    return NL*(Spec + max(Diffuse, AmbientColor))*lightModifier;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Feel free to point out any mistakes I made, even if not related to the issue. I've tested the materials in Unreal, and they looked correct. I doubt this is solely due to the lack of Image-Based Lighting. I also doubt this is an issue with using point lighting. Additionally, if I turn down the roughness by a lot, it becomes too dark a high roughness to be the issue.&lt;/p&gt;&#xA;" OwnerUserId="5026" LastActivityDate="2018-04-09T09:41:35.750" Title="Bug: Overly Sharp Highlights in PBR" Tags="&lt;glsl&gt;&lt;brdf&gt;&lt;specular&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="3961" PostTypeId="2" ParentId="3955" CreationDate="2016-09-06T08:11:17.577" Score="6" Body="&lt;p&gt;This is the main 'hard' problem remaining in real-time CG, and there is a lot of research ongoing into solving it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The biggest hurdle is that in raster graphics, each component of the scene is rendered 'in a vacuum' - each triangle is rendered without reference to any other triangles in the scene, and the same goes for pixels, as opposed to ray-tracing approaches where each ray has access to the entire scene in memory. So real-time programmers need to use hacky tricks to do stuff like reflections and shadows, and the same applies to global illumination.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A cheap runtime method is to use baked light-maps, where you run something slow-but-awesome like radiosity or path-tracing offline first, then save the lighting information along with your regular vertex data. This is great for static geometry, but becomes problematic as soon as you add moving objects. Michal Iwanicki did a good &lt;a href=&quot;http://miciwan.com/SIGGRAPH2013/Lighting%20Technology%20of%20The%20Last%20Of%20Us.pdf&quot; rel=&quot;noreferrer&quot;&gt;presentation&lt;/a&gt; on how they solved this for 'The Last of Us'.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://Spherical%20Harmonics&quot; rel=&quot;noreferrer&quot;&gt;Spherical Harmonics&lt;/a&gt; are used a lot in game engines to represent indirect light. They're basically a Fourier transform across the surface of a sphere, by discarding high-frequency components you can get visually pleasing, mostly accurate environment lighting in only 9 coefficients per-color. Unity, for example, uses S.H. to bake 'light probes' at various points in the scene, moving objects can then interpolate between nearby probes to get an approximation of the indirect light at their position. Robin Green's &lt;a href=&quot;https://graphics.cg.uni-saarland.de/fileadmin/cguds/courses/ss15/ris/slides/RIS18Green.pdf&quot; rel=&quot;noreferrer&quot;&gt;paper&lt;/a&gt; is basically the bible on this technique, but it's pretty heavy going.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The hot technique at the moment seems to be Voxel Cone Tracing, which doesn't involve any pre-bake step. I'm not too familiar with it myself, but as I understand it, it involves voxelizing your scene into a low-res Minecraft-style world, placing the voxels into a quickly-traversable spatial structure like an octree, then casting a few wide rays (cones) from each point and checking which voxels they hit to gather bounce lighting. NVidia is pushing this pretty hard at the moment, and there are papers on it &lt;a href=&quot;https://research.nvidia.com/sites/default/files/publications/GIVoxels-pg2011-authors.pdf&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://simonstechblog.blogspot.sg/2013/01/implementing-voxel-cone-tracing.html&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope that helps :)&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2016-09-06T08:11:17.577" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3963" PostTypeId="1" CreationDate="2016-09-07T10:11:05.043" Score="3" ViewCount="337" Body="&lt;p&gt;Raw volume raymarching especially aligned with frustum seem to produce a lot of aliasing/banding on edges of shadow map. Especially when fragment pos is far because step length is then getting bigger. Making some research how to correct it I found out about temporal reprojection technique.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So basically I have an two 2D textures, current and previous where I store exponential moving average of raymarching result of previous frames like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$s(n) = w*f(n)+(1-w)*s(n-1)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$w$ - weight&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f(n)$ - current frame calculation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$s(n-1)$ - result of previous frames calculation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seem to be working when camera is moving because then bands are moving and blending with each other. But when camera stands still everything returns to normal. I tried to:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;add some noise aligned with ray direction to starting position every other frame but banding is still at the same positions&lt;/li&gt;&#xA;&lt;li&gt;add noise not aligned with ray direction but then bands are shifted ramdomly and raymarching results are wrong&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=yjoD6RCuM4c&quot; rel=&quot;nofollow&quot;&gt;Here&lt;/a&gt; (FrostBite engine) it is smooth constantly independent of camera movement.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is there a way to simulate camera movements? Or any other technique to correct the issue?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.frostbite.com/2015/08/physically-based-unified-volumetric-rendering-in-frostbite/&quot; rel=&quot;nofollow&quot;&gt;Here&lt;/a&gt; you can download some content describing subject.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2016-10-12T16:54:59.383" Title="Frustum aligned volume integration - aliasing issue - temporal reprojection" Tags="&lt;texture&gt;&lt;3d&gt;&lt;volumetric&gt;&lt;raymarching&gt;&lt;3dtexture&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3964" PostTypeId="1" AcceptedAnswerId="3965" CreationDate="2016-09-07T19:17:05.367" Score="9" ViewCount="2522" Body="&lt;p&gt;I use Phong shading as my lighting model. Nevertheless, the specular shading produces gradients in the light cone:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RknYH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RknYH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hopefully you can see the gradient starting from the lower left corner expanding along the cuboid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the shader code that produces this specular light:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 viewDir = normalize(-FragPos);&#xA;vec3 lightDir = normalize(-light.direction);&#xA;vec3 reflectDir = reflect(-lightDir, normal);&#xA;float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;By the way, I'm doing my lighting calculations in view-space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any chance to make the lighting smoother?&lt;/p&gt;&#xA;" OwnerUserId="3377" LastEditorUserId="4793" LastEditDate="2019-07-10T08:15:33.580" LastActivityDate="2019-07-10T08:15:33.580" Title="OpenGL specular shading - Gradient banding issues" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="3965" PostTypeId="2" ParentId="3964" CreationDate="2016-09-08T05:45:00.897" Score="9" Body="&lt;p&gt;This is a common problem with very subtle gradients. The problem is that the image is displayed with 8 bits per component and this is not quite enough precision to make a gradient that is smooth to the eye under these conditions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the underlying calculations being done in the shader are at higher precision (e.g. float = 24 effective bits of mantissa), so you can apply dithering to improve the appearance of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can do this by adding a slight amount of random noise to the value of each pixel in the shader. The noise can come from a texture, filled with random grayscale values in [0, 1] and mapped 1:1 to screen pixels. In the shader you remap this to the range [−0.5/255, 0.5/255] and add it to the output color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/MlV3R1&quot; rel=&quot;noreferrer&quot;&gt;Here's a Shadertoy demonstrating this.&lt;/a&gt; The left side has no dithering; the right side uses the procedure just described. As you can see, the banding vanishes on the right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/X61tI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X61tI.png&quot; alt=&quot;banding on left; dithered on right&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Dithering effectively allows you to represent intermediate values between 8-bit integer levels. For instance, an area that the shader computes as 82.3 (out of 255) would normally be uniformly rounded down to 82, but with dithering it will come out as a random mix with 70% of the pixels set to 82, and 30% set to 83. The eye averages over this very slight, high-frequency noise and it becomes practically invisible.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-08T05:45:00.897" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="3967" PostTypeId="1" CreationDate="2016-09-08T15:52:02.190" Score="0" ViewCount="49" Body="&lt;p&gt;I need a lot of real time rendered images and real images where it's recorded which one is which to prove either way whether existing gaming computers have the hardware to be photo-realistic to someone I know (which they will have if they're unable to tell the difference, statistically) at their best. Please can someone link me to what I'm looking for? Thank you.&lt;/p&gt;&#xA;" OwnerUserId="5082" LastActivityDate="2016-09-08T16:04:28.537" Title="Photo-realism blind experiment" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2016-09-09T10:13:49.367" ContentLicense="CC BY-SA 3.0" />
  <row Id="3968" PostTypeId="2" ParentId="3967" CreationDate="2016-09-08T16:04:28.537" Score="2" Body="&lt;p&gt;Path tracing is a common method for making photo realistic images.  If I were you, I'd start off doing a google image search for path tracing to find some images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may get lucky and find a site that has a lot of them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are a few examples I found doing that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LEVpW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LEVpW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Fui1d.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Fui1d.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sFkkp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sFkkp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XXF1U.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XXF1U.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-09-08T16:04:28.537" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3969" PostTypeId="1" CreationDate="2016-09-08T20:41:57.200" Score="8" ViewCount="390" Body="&lt;p&gt;I'm trying to get the correct representation of visible spectrum to render on the screen. My current progress is with using CIE 1931 standard observer color matching functions analytically approximated by the equations given in &lt;a href=&quot;http://jcgt.org/published/0002/02/01/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt;. Current image is like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/owUVn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/owUVn.png&quot; alt=&quot;current image I could generate&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here the background is not ideally black to make it possible to introduce the negative contributions from the color matching functions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NctGH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NctGH.png&quot; alt=&quot;color matching functions&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But the problem with it is that the image seems to have a dip in intensity somewhere around 490 nm. I guess that this is related to the sum of the three functions having a minimum there. See the sum plotted against wavelength:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sbazx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sbazx.png&quot; alt=&quot;sum of three color matching functions&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is now: how do I fix the intensity of the image? Is there any standard for taking spectral sensitivity into account when converting wavelength to RGB/XYZ representation?&lt;/p&gt;&#xA;" OwnerUserId="4647" LastEditorUserId="4647" LastEditDate="2018-09-12T22:10:05.627" LastActivityDate="2018-10-09T20:24:40.690" Title="How to correctly render visible spectrum with uniform intensity?" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="3970" PostTypeId="1" AcceptedAnswerId="3974" CreationDate="2016-09-09T08:03:14.227" Score="4" ViewCount="6351" Body="&lt;p&gt;Suppose you have generated an image using linear values for RGB channels. E.g. you linearly interpolated it when doing blending, etc.. When you're going to present this on the screen, should the values be transformed as $C_{\mathrm{linear}}\to C_{\mathrm{sRGB}}$ as given &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_forward_transformation_.28CIE_xyY_or_CIE_XYZ_to_sRGB.29&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; or backwards as described &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would seem that the image should be encoded in sRGB, thus the forward transformation is necessary. But I've measured response of my monitor, and it appears that to have linearly changing brightness with input RGB, the color data have to be transformed as $C_{\mathrm{sRGB}}\to C_{\mathrm{linear}}$ as if my image were already in sRGB color space (the behavior is consistent with that described in &lt;a href=&quot;https://computergraphics.stackexchange.com/q/1587/4647&quot;&gt;another question&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is it correct that to render and present an image one has to do the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Draw in linear RGB to have correct blending&lt;/li&gt;&#xA;&lt;li&gt;Treating the data &lt;em&gt;as if&lt;/em&gt; they were sRGB, convert to linear RGB&lt;/li&gt;&#xA;&lt;li&gt;Present on screen, so that monitor now converts this back&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Then the result will be linear as expected. Or am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="4647" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-09-09T14:34:07.837" Title="Confusion between usages of linear RGB and sRGB" Tags="&lt;color&gt;&lt;brightness&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3971" PostTypeId="1" CreationDate="2016-09-09T10:37:45.823" Score="3" ViewCount="84" Body="&lt;p&gt;I'd like to take an photograph, subdivide it into a tesselation, either of squares, or (ideally), hexagons, and then find the centre of gravity (or, if you prefer, centre of mass) of each cell of the tesselation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output, for any image, would be a matrix of points. For the attached diagram, something like this (in polar coordinates - $(r,\theta)$ ):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(5,5Π/4) (0,0) (1,7Π/4) (1,5Π/4)&#xA;     (5,3Π/4) (0,0) (5,Π/2) &#xA;(0.0) (0,0) (0.0) (0,0)  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I've attached an image showing what I mean.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zQng6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zQng6.png&quot; alt=&quot;Hexagonal tesselation. The black circles are the centres of gravity of each cell - in clear, or monochrome, cells it is in the centre of the cell. In those with a green splodge, the cog is pulled towards the splodge&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question, to put it simply, is the best method to use to calculate the cog, in this tessellation... For squares, it'd be easy to calculate the weighted mean for each row, but that would be too rough an approximation. What's a good way to iterate either a general tessellation (ideal), or an hexagonal one?&lt;/p&gt;&#xA;" OwnerUserId="5087" LastEditorUserId="5087" LastEditDate="2016-09-10T17:56:28.453" LastActivityDate="2016-09-10T17:56:28.453" Title="What is a good algorithm, and framework, to calculate centres of gravity or mass (cog)?" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;mathematics&gt;&lt;physics&gt;&lt;polygon&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3972" PostTypeId="1" AcceptedAnswerId="3976" CreationDate="2016-09-09T14:12:38.487" Score="7" ViewCount="1413" Body="&lt;p&gt;I have a naive diffuse/emissive material path tracer implementation (pinhole camera) and am seeing it take a very large number of samples per pixel to converge - like probably in the millions - and was wondering if that was normal for &quot;naive&quot; path tracer implementations?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is 10,000 samples per pixel:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Il8Lw.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Il8Lw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here's a 10,000spp image using cosine weighted hemisphere samples as comparison:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/bJOV7.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bJOV7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each pixel I do this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Cast a ray out into the scene for the pixel (starting at near plane, of the direction of the camera to the pixel's location on the near plane).&lt;/li&gt;&#xA;&lt;li&gt;When an object is hit, I calculate a uniform random direction in the hemisphere defined by the normal and continue.&lt;/li&gt;&#xA;&lt;li&gt;At each level, i return emissive + (2 * Dot(normal, bounceRayDir) * ColorFromBounceRay * DiffuseColor/pi)&lt;/li&gt;&#xA;&lt;li&gt;If nothing is hit by a bounced ray, i return black.&lt;/li&gt;&#xA;&lt;li&gt;I'm working with 3 floating point color channels, where the intent is that 0-1 corresponds to 0-255 in the final output uint8 per color channel.&lt;/li&gt;&#xA;&lt;li&gt;I allow 5 bounces max.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;After averaging all the samples for the pixel, I do this to convert it from HDR to LDR:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;For each color channel i do gamma correction: channel = powf(channel, 1.0f /2.2f)&lt;/li&gt;&#xA;&lt;li&gt;I then multiply the channel value by 255, clamp it from 0-255 and cast it to uint8 for the final pixel color.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The source code can be seen here in the gist below.  It includes windows.h for bitmap headers, but otherwise has no non standard headers, and no library dependencies:&#xA;&lt;a href=&quot;https://gist.github.com/anonymous/0dc9f7f5abf15f8fdb9aa84ecfcf67d5&quot; rel=&quot;noreferrer&quot;&gt;https://gist.github.com/anonymous/0dc9f7f5abf15f8fdb9aa84ecfcf67d5&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-09-09T14:24:24.757" LastActivityDate="2016-09-11T16:47:02.643" Title="Is it expected that a naive path tracer takes many, many samples to converge?" Tags="&lt;pathtracing&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3973" PostTypeId="2" ParentId="3932" CreationDate="2016-09-09T14:20:34.397" Score="6" Body="&lt;p&gt;As a general rule, you cannot interpolate transformation matrices. In stead, you decompose them into their individual values, then interpolate those and recompose. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Möbius transformation as suggested in the comments sounds interesting, but tradionally I'd just extract scale and rotation and interpolate those.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming a transformation matrix&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    | a  b |&#xA;T = | c  d |&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the &lt;em&gt;scale&lt;/em&gt; is &lt;code&gt;[sqrt(a² + c²), sqrt(b² + d²)]&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;The &lt;em&gt;rotation angle&lt;/em&gt; is &lt;code&gt;atan(c/a)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You'd now interpolate this scale and rotation angle, recomposing the matrix at each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;[Edit] Corrected the angle (as spotted by Nathan Reed) [/Edit]&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="5088" LastEditorUserId="5088" LastEditDate="2016-09-10T18:18:39.683" LastActivityDate="2016-09-10T18:18:39.683" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3974" PostTypeId="2" ParentId="3970" CreationDate="2016-09-09T14:34:07.837" Score="1" Body="&lt;p&gt;The monitor interprets its input data as encoded in sRGB color space. This means that to actually display them, i.e. to get brightness of the subpixels it does the transformation $C_{\mathrm{sRGB}}\to C_{\mathrm{linear}}$. This transformation is basically application of gamma of $\approx2.2$ to the value, so that output brightness will be superlinearly dependent on input data. Since non-extremal input values are $&amp;lt;1$, they'll all be darker than with linear response.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you have rendered an image in linear RGB color space, you need to compensate the transformation the monitor does. Thus you convert the image to sRGB, i.e. apply the $C_{\mathrm{linear}}\to C_{\mathrm{sRGB}}$ transformation. This transformation is inverse of what the monitor does: it applies a gamma of $\approx1/2.2$ to the values, so all non-extremal values will be larger than original.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the OP I was coming to the wrong conclusion because of a mistake when trying to match the output of monitor with my input. To match it correctly one needs to either apply $C_{\mathrm{sRGB}}\to C_{\mathrm{linear}}$ transformation to input data to simulate what the monitor does with them, or apply backward transformation to the measured output — to undo monitor's processing.&lt;/p&gt;&#xA;" OwnerUserId="4647" LastActivityDate="2016-09-09T14:34:07.837" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3976" PostTypeId="2" ParentId="3972" CreationDate="2016-09-09T17:23:15.240" Score="11" Body="&lt;p&gt;Without explicit light sampling, I'd expect very slow convergence.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any path that doesn't happen to hit the light source before being terminated will be useless (contributes zero). Since you have a small light source, the vast majority of paths will not hit it. It would be interesting to add some statistics to your tracer to see how many paths return zero vs nonzero. I'd guess you'll find something like 99–99.9% of them are zero, so you're only getting one useful sample out of every 100–1000 or so paths traced.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Naive path tracing is more reasonable with e.g. a sky light, which almost every path can be expected to hit.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-09T17:23:15.240" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3977" PostTypeId="1" CreationDate="2016-09-09T19:53:46.417" Score="0" ViewCount="598" Body="&lt;p&gt;I would like to make certain objects in my scene transparent, but only the parts visible to the camera when opaque. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, when I make objects transparent, I can see other transparent objects behind them, which I don't want. I only want to be able to see opaque objects behind transparent objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what happens now:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gRP4b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gRP4b.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what I want:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vIumn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vIumn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5093" LastEditorUserId="5093" LastEditDate="2016-09-09T20:42:42.007" LastActivityDate="2016-09-12T17:31:40.257" Title="Only show opaque objects behind transparent objects" Tags="&lt;rendering&gt;&lt;webgl&gt;&lt;transparency&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3978" PostTypeId="2" ParentId="3972" CreationDate="2016-09-09T20:39:49.030" Score="6" Body="&lt;p&gt;Yes, this is to be expected. The difference between your two images is the difference between using and not using importance sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first image shows noticeably more noise than the second. This is because instead of biasing the hemisphere samples towards the normal by using cosine weighting, the code instead samples uniformly over the hemisphere and then gives less reflected light to rays nearer to perpendicular to the normal. Note that since this uses the dot product, this is also cosine weighting:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$A\cdot B=\|A\|\|B\|\cos{\theta}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's just weighting the contribution of each ray, rather than weighting the number of rays in each direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second image is less noisy because it doesn't waste many samples on near-perpendicular rays which contribute very little to the image. The image will still converge to the same result given enough samples - the approach taken in the second image will just get there much sooner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The effect in both cases is the same:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Approach 1&lt;/strong&gt;: The weighting is applied to the amount of light reflected per ray, resulting in many of the rays carrying very little contribution.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Approach 2&lt;/strong&gt;: Every ray is given the same weight, but fewer of them are used in the directions associated with little contribution.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The long term sum is the same either way, but approach 1 involves many rays with negligible contribution, that still require just as much calculation as any other ray, thus wasting most of the calculation time.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Note that even with this speed up, the convergence will still be &lt;em&gt;very&lt;/em&gt; slow for scenes with small, bright lights, or if there are parts of the scene accessible only by narrow paths. Generally, any scene where there are regions for which only a narrow range of angles contribute most of the light.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-09-11T16:47:02.643" LastActivityDate="2016-09-11T16:47:02.643" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3979" PostTypeId="1" CreationDate="2016-09-10T08:40:26.277" Score="4" ViewCount="177" Body="&lt;p&gt;Just like the question says. Is it possible to selectively set the value of the stencil buffer based on a property of a vertex, like the value of its normal, during its vertex processing phase? Instead of setting for all fragments of the model. Basically I want to detect the edges of my model by using variation in vertex normals and use them to set the stencil values in the corresponding fragments for some special effects &lt;/p&gt;&#xA;" OwnerUserId="5097" LastActivityDate="2016-09-10T08:40:26.277" Title="selectively setting stencil value based on vertex property in vertex shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;stencil-buffer&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3980" PostTypeId="1" CreationDate="2016-09-10T11:42:23.603" Score="0" ViewCount="83" Body="&lt;p&gt;I'd like an automatic method to clean images. I've been looking at the GIMP, and its command line (cli) interface, in scheme / lisp. It looks very promising, but I'm a complete novice, so I'd be grateful for advice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm, essentially, wanting to remove all man-made artefacts from a large number of photos - which is why I need to automate it, it's easy enough with just the one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to remove anything with a hard-edge (square, rectangle, or part of one), or with a smooth curve (circle, ellipse, or part of one), but not remove naturally curved things, like leaves, or fronds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've attached a before and after photo. In a perfect world, I'd like a script that takes the image on the left, and leaves the image on the right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any suggestions of the best way to go?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It'd be nice if the method could be one that can use a GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mUC7H.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mUC7H.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a representative image. In this, I'd be wanting to exclude the straight-edged areas on the top right, and the straight-edged white blocks on the top left. What I'd be not wanting to exclude, but would actually be looking for (a separate problem) would be the white mass that's just to the bottom-right of the centre of the image. As you can see, it has nothing like a straight-edge or arc about it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hFsnV.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hFsnV.jpg&quot; alt=&quot;Sample photo - it&amp;#39;s a mammogram, showing a tumour&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5087" LastEditorUserId="5087" LastEditDate="2016-09-11T02:08:05.137" LastActivityDate="2016-09-11T02:08:05.137" Title="Image cleaning - removing all regular shapes ( circles, squares, text, icons etc. )" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;computational-geometry&gt;&lt;image-processing&gt;&lt;mathematics&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="3981" PostTypeId="2" ParentId="3963" CreationDate="2016-09-10T18:57:16.533" Score="0" Body="&lt;p&gt;Well actually I think I was doing it wrong. I stored raymarching effects in 2D texture. This is not correct because it suffers from issues.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Correct way is store raymarching effect in 3D texture, to get linear interpolation and no banding. And then perform sampling from it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems to improve the result because it fixes some discontinuities. However it still needs temporal blending to get it smooth during camera movement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Indeed the way to get smooth temporal blending independent of camera movement is to add some jitter which is shifted each frame, but it is hard to get it working right.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-10-12T16:54:59.383" LastActivityDate="2016-10-12T16:54:59.383" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3982" PostTypeId="1" CreationDate="2016-09-11T09:08:43.267" Score="4" ViewCount="255" Body="&lt;p&gt;I'm new to this area and have less knowledge. I want to create some graphics like  &lt;strong&gt;sparks and lightning&lt;/strong&gt; by writing some code, using my own physics. I don't want to use some engine, However I can use external libraries. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone tell me how to set started, where should I proceed?&#xA;Like should I go with &lt;code&gt;OpenGL&lt;/code&gt; for writing my own code or something else. &lt;/p&gt;&#xA;" OwnerUserId="5102" LastEditorUserId="231" LastEditDate="2016-09-11T16:36:45.070" LastActivityDate="2016-09-15T03:25:15.923" Title="Creating Sparks using Code" Tags="&lt;3d&gt;&lt;physics&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3984" PostTypeId="1" CreationDate="2016-09-11T16:24:42.170" Score="4" ViewCount="95" Body="&lt;p&gt;I am writing a texture splatting pixel shader for meshes (not terrain) whereby I find a UV position from a raycast, which I convert to a local position, and then calculate a bounding box around that position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then when cycling through the UVs (also converted to local positions) in the shader I am able to check if each UV is within the bounding box, and hence set a colour.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P28sG.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P28sG.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The bit I am struggling with is how to map each local position to the bounding box so I can then map that result to the splat texture using UVs or percentages.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the image above I have 6 splat points. As you can see the one is crossing an edge so I need to be able to transform the 3D position along all axes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was thinking I could flatten/unfold the 3D point, but I'm not sure how to do this with all axes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="5104" LastEditorUserId="5104" LastEditDate="2016-09-12T16:44:02.507" LastActivityDate="2016-09-12T16:44:02.507" Title="Unfolding a 3D point to a Cartesian plane" Tags="&lt;pixel-shader&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3985" PostTypeId="1" CreationDate="2016-09-11T18:11:19.783" Score="1" ViewCount="87" Body="&lt;p&gt;I am really new in computer graphic area.&#xA;Suppose I have 1024*1024 frame buffer, and I want to use it to control a 512*512 display. What shall I do?&#xA;In my opinion, I will only read the information in 512*512, such as from (0,0) to (0,511) then go to next line, (1,0) to (1,511)...&#xA;Is this an usual way to solve the problem?  &lt;/p&gt;&#xA;" OwnerUserId="5105" LastActivityDate="2016-09-11T18:41:04.720" Title="Use big frame buffer to control a small display" Tags="&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3986" PostTypeId="2" ParentId="3985" CreationDate="2016-09-11T18:41:04.720" Score="3" Body="&lt;p&gt;As stated, the question is a bit generic. It all depends on what part you &lt;em&gt;want&lt;/em&gt; to display in the 512x512 display. If you have a 1024x1024 frame buffer from some source and only want to display 1/4 of the information, by all means copy the first 512 elements from the first 512 lines. If you want to support &lt;em&gt;panning&lt;/em&gt;, you'll start at a different index in a different line. If you want to support &lt;em&gt;scaling&lt;/em&gt; (with or without filter), you'll use a bigger or smaller set of source pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It also depends on the type of the buffer. If it's just raw bytes, your suggested approach is basically the only way to go, but if it's a DirectX/OpenGL texture, or part of some other graphics API (Windows Bitmap, graphics engine, etc), there are usually specialized approaches to get a rectangular subset of a buffer. &lt;/p&gt;&#xA;" OwnerUserId="5088" LastActivityDate="2016-09-11T18:41:04.720" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3987" PostTypeId="1" AcceptedAnswerId="3992" CreationDate="2016-09-11T18:45:40.160" Score="3" ViewCount="746" Body="&lt;p&gt;I'm trying to understand OpenGL by using Processing OpenGL ES.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I have an example Cube to render.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read that a vertex shader will be run once for each Vertex. The fragment shader will be run (at least) once for each pixel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a vertex shader I have:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define PROCESSING_COLOR_SHADER&#xA;&#xA;&#xA;uniform mat4 transform;&#xA;&#xA;attribute vec4 vertex;&#xA;attribute vec4 color;&#xA;&#xA;varying vec4 col;&#xA;&#xA;&#xA;void main(){&#xA;&#xA;    gl_Position = vertex;&#xA;&#xA;    col = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In a fragment shader I have:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_FragColor = col;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When ran, it creates a simple painted cube of the colour defined in the Processing sketch. However, if I change the vertex shader to...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_Position = vertex&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(instead of transform*vertex) it draws a wireframe cube in exactly the same place. What exactly does the transform matrix do? &lt;/p&gt;&#xA;" OwnerUserId="5106" LastActivityDate="2016-09-12T07:59:16.487" Title="OpenGL: Purpose of transform matrix in Vertex shader where transform*vertex" Tags="&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3988" PostTypeId="2" ParentId="3987" CreationDate="2016-09-11T19:12:39.433" Score="2" Body="&lt;p&gt;The transform matrix will be a uniform which is easier to update and upload to the gpu (just a single glUniform call) than applying the transform to all vertices on the cpu and uploading the new vertices. Especially with large models.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-09-11T19:12:39.433" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3990" PostTypeId="1" AcceptedAnswerId="4003" CreationDate="2016-09-12T07:00:21.483" Score="4" ViewCount="378" Body="&lt;p&gt;I have two methods of calculating tangent and cotengent (needed for normalMap lighting calculation).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The one is doing it from CPP code (with assimp library for example)&lt;/li&gt;&#xA;&lt;li&gt;The second is doing it directly in shader (in Vertex shader/in fragment shader)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What is the best optimized method? (optimized for speed, with vsync activated)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use Opengl 3.3+&lt;/p&gt;&#xA;" OwnerUserId="5089" LastEditorUserId="5089" LastEditDate="2016-09-16T08:47:28.577" LastActivityDate="2016-09-16T08:47:28.577" Title="Where is the best place for Tangent-bitangent calculation, in shader or in C/CPP code?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3992" PostTypeId="2" ParentId="3987" CreationDate="2016-09-12T07:59:16.487" Score="2" Body="&lt;p&gt;The transform matrix allows you to translate, rotate or resize your model. From the model's point of view, its vertices always are at the same position. But if you multiply the vertices with, let us say a translation matrix, they all get moved. Seen from the model's origin, they are still at the same position. But in world space, your whole model has moved.&#xA;The reason that changing the code did nothing to how the cube was presented to you lies in your transformation matrix not applying any changes to the cube's model data.&#xA;If you choose a different transformation matrix, things will look differently.&lt;/p&gt;&#xA;" OwnerUserId="5055" LastActivityDate="2016-09-12T07:59:16.487" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3993" PostTypeId="2" ParentId="3977" CreationDate="2016-09-12T10:01:31.040" Score="1" Body="&lt;p&gt;Disclaimer: I haven't actually tested this but it seems feasible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I agree with &lt;a href=&quot;https://computergraphics.stackexchange.com/users/231/trichoplax&quot;&gt;trichoplax&lt;/a&gt; that what you want could possibly be expressed more clearly but, assuming I've understood correctly, would the following do the job?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First I assume you can supply the opaque and translucent geometry separately, and that the opaque is sent first. I'm also going to assume there &lt;em&gt;may&lt;/em&gt; be translucent geometry with exactly the same pixel Z values.(If this isn't the case, the stencil requirements could probably be dropped.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To handle the &quot;single translucent layer&quot;, clear the stencil buffer and send the translucent polygons to update the Z-buffer and set the stencil buffer on each pixel, but don't touch the frame buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Submit the translucent data a second time (to actually update the framebuffer),  but change the Z test to 'equal' and only allow drawing on the pixels that are currently set in the the stencil buffer. Also clear the stencil for any pixels that pass the tests.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This, I think, should result in only the closest translucency layer being applied.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-09-12T15:36:30.583" LastActivityDate="2016-09-12T15:36:30.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3994" PostTypeId="1" AcceptedAnswerId="3997" CreationDate="2016-09-12T11:58:46.960" Score="3" ViewCount="421" Body="&lt;p&gt;I use C# and OpenTK as my OpenGL implementation.&#xA;My Vertex layout consists of 6 Doubles and one Float:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public struct Vertex&#xA;{&#xA;    //Positions&#xA;    public double X;&#xA;    public double Y;&#xA;    public double Z;&#xA;    //ContourEdge&#xA;    public float IsContourEdge;&#xA;    //Normals&#xA;    public double NX;&#xA;    public double NY;&#xA;    public double NZ;&#xA;    public Vertex(float x, float y, float z) : this()&#xA;    {&#xA;        X = x;&#xA;        Y = y;&#xA;        Z = z;&#xA;        IsContourEdge = 0f;&#xA;    }&#xA;&#xA;    public Vertex(float x, float y, float z, float nX, float nY, float nZ) : this()&#xA;    {&#xA;        X = x;&#xA;        Y = y;&#xA;        Z = z;&#xA;        NX = nX;&#xA;        NY = nY;&#xA;        NZ = nZ;&#xA;        IsContourEdge = 0f;&#xA;    }&#xA;    public static int IsContourEdgeOffset()&#xA;    {&#xA;        return sizeof (double) * 3;&#xA;    }&#xA;    public static int NormalOffset()&#xA;    {&#xA;        return sizeof(double) * 4;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I render my vertices like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Bind vao, vbo and ebo&#xA;GL.BindVertexArray(bufferObject.Vao);&#xA;&#xA;GL.BindBuffer(BufferTarget.ArrayBuffer, bufferObject.Vbo);&#xA;GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Marshal.SizeOf(typeof(Vertex))), vertices, BufferUsage);&#xA;&#xA;// Vertex Positions&#xA;GL.EnableVertexAttribArray(0);&#xA;GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Double, false, Marshal.SizeOf(typeof(Vertex)), IntPtr.Zero);&#xA;// Is Contour Edge&#xA;GL.EnableVertexAttribArray(1);&#xA;GL.VertexAttribPointer(1, 1, VertexAttribPointerType.Float, false, Marshal.SizeOf(typeof(Vertex)), Vertex.IsContourEdgeOffset());&#xA;// Vertex Normals&#xA;if (hasNormals)&#xA;{&#xA;    GL.EnableVertexAttribArray(2);&#xA;    GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Double, false, Marshal.SizeOf(typeof(Vertex)), Vertex.NormalOffset());&#xA;}&#xA;&#xA;//Unlink buffers&#xA;GL.BindBuffer(BufferTarget.ArrayBuffer, 0);&#xA;GL.BindVertexArray(0);&#xA;GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Everything works fine here. &#xA;But the offset of the normals doesn't make sense for me. In my Vertex struct I said:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static int NormalOffset()&#xA;{&#xA;    return sizeof(double) * 4;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But shouldn't it be&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static int NormalOffset()&#xA;{&#xA;    return 3* sizeof(double) * sizeof(float);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;since IsContourEdge is a float and a I also pass it as a float (VertexAttribPointerType.Float) to my vertex shader? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, if I use this NormalOffset instead of the previous one, the normals don't work anymore.&#xA;The only explanation I have is that OpenGL expands the size of a Float to the size of a Double. Is that right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just for completeness, here is the vertex shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;layout (location = 0) in vec3 position; //Vertices and normals are in world coordinate space&#xA;layout (location = 1) in float isContourEdge;&#xA;layout (location = 2) in vec3 normal;&#xA;&#xA;out VS_OUT {&#xA;    vec3 Normal;&#xA;    vec3 FragPos;&#xA;    vec3 VertWorldNormal;&#xA;    vec3 VertWorldPos;&#xA;    float ExcludeEdge;&#xA;} vs_out;&#xA;&#xA;uniform mat4 view;&#xA;uniform mat4 proj;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position = proj * view *  vec4(position, 1.0f);&#xA;    vs_out.FragPos = vec3(view * vec4(position, 1.0f));&#xA;    vs_out.Normal = vec3(view * vec4(normal, 0));&#xA;    vs_out.ExcludeEdge = isContourEdge;&#xA;&#xA;    vs_out.VertWorldNormal = normal;&#xA;    vs_out.VertWorldPos = position;&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3377" LastActivityDate="2016-09-12T14:00:21.257" Title="OpenTK - Vertex attribute layout issue" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="3995" PostTypeId="1" AcceptedAnswerId="4041" CreationDate="2016-09-12T13:42:34.243" Score="3" ViewCount="975" Body="&lt;p&gt;So, I started writing my second raytracer - this time focusing on photometric rendering that uses IES lights and standard photometric units.  I've got the basic raytracing up and running (using pure geometry), I've read any article I could found on radio- and photometry (I think I developed an intuition for it) but the issues started when I tried to validate/play with the underlying math.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use IES lights as a function of spherical coordinates that gives me the intensity of light in that direction in candelas (lumens per unit solid angle). Also in the equation for Luminance/Radiance there are differential solid angle and differential surface area. On the paper everything looks good, however:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My question is&lt;/strong&gt;: how should I deal with those parameters in my raytracer? I assume (but I'm not sure) that my (differential) solid angle is just a (unit) vector in descrete world and the surface area is simply a point - but what values should I plug in to those equations? I saw that on some websites that people just ignored those terms and replaced the integral with sum - but no explanation was given...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And my second question is related to those IES lights - how can I simply convert intensity to radiance? The intensity already has the solid angle, but for radiance I need the surface area... Or should I somehow integrate the luminious intensity to get luminious flux and then somehow calculate the radiance from that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; I decided to try to grab a sheet of paper, try again and share with you my thought process. In order to simplify a lot of things:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;each plane has a single scalar value as material (let's name it &lt;em&gt;reflectivity&lt;/em&gt; between 0 and 1)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$p1$ has $reflectivity = 0.5$&lt;/li&gt;&#xA;&lt;li&gt;$p2$ has $reflectivity = 1$&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;all materials are lambertian (no specular reflections nor emission)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So with those in mind let's imagine that we have following scene:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/BRL0Y.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BRL0Y.png&quot; alt=&quot;Example scene with 2 planes&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 1 - Illuminance at $p1$&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The light luminious intensity at vertical angle $V=0$ is $I = 6619 [cd]$. In order to compute the illuminance at point $p1$ we can create a sphere with radius equal to the distance between the light and intersection point $p1$ which is $r = 2$ meters. That virtual sphere intersects with the first plane creating a small differential area $dA$. Knowing that $d\omega = \frac {dA}{r^2}$ we get $E_L(r) = \frac {I}{r^2} [ \frac {W}{m^2}]$ which is equal to illuminance measured at a plane perpendicular to light. We have to project it to know how many light hits the $p1$, so $E = E_L \times cos \theta$. I &lt;strong&gt;assume&lt;/strong&gt; that $L_i = E$, but that is just a guess. I hope that at this point I got it right...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 2 - Outgoing luminance&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to calculate the outgoing radiance I think that is the place for the rendering equation to kick in:&#xA;$$&#xA;L_o = L_e + \int_{\Omega} f_r(\omega_i, \omega_o) L_i(p, \omega_i) cos \theta d\omega&#xA;$$&#xA;since I ignore the emission and my BRDF is $f_r(\omega_i, \omega_o) = \frac {reflectivity}{\pi}$ which is constant across the integral giving me:&#xA;$$&#xA;L_o = \frac {reflectivity}{\pi} \int_{\Omega} L_i(p, \omega_i) cos \theta d\omega&#xA;$$&#xA;Now I have to discretize it, which I don't fully understand. Based on my notes that I've made based on many pages I've got:&#xA;$L_o = \frac {reflectivity}{\pi} \sum L_i(p, \omega_i) cos \theta \Rightarrow L_o = \frac {0.5}{\pi} L_i cos \theta$, where $L_i$ was calculated in step 1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 3 - Luminance at $p2$&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I assume that $L_{i_{p2}} = L(p_1 \rightarrow p_2) \times cos \theta = L_{o_{p1}} \times cos \theta$ ? I'm not sure if I have to apply the $cos \theta$ twice (for outgoing and incoming $dA$s).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;I also would like to apologize for making this question sooo long - but I had never taken any course that would introduce radiometry and I was forced to (try to) learn it by myself.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="5114" LastEditorUserId="6143" LastEditDate="2017-03-06T19:43:06.857" LastActivityDate="2017-03-06T19:43:06.857" Title="Solid angle and surface area values in (photometric) raytracing" Tags="&lt;raytracing&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="3996" PostTypeId="2" ParentId="3977" CreationDate="2016-09-12T13:46:16.877" Score="3" Body="&lt;p&gt;The simplest solution is to do three passes:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Render opaque meshes to a buffer (front-to-back, depth read/write on)&lt;/li&gt;&#xA;&lt;li&gt;Render translucent meshes to another buffer (front-to-back, depth read/write on)&lt;br&gt;&#xA;This makes sure that only the closest translucent mesh is rendered.&lt;/li&gt;&#xA;&lt;li&gt;Alpha blend translucent mesh on top of opaque buffer using opaque depth buffer. (depth read on)&lt;br&gt;&#xA;This will take care of opaque meshes blocking translucent meshes and preserving translucent opacity levels. Depth test for values less or equal for small early z test (potential) optimisation.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;EDIT: As mentioned below you could use the same depth buffer for the translucent pass and do the alpha blend then, the key is rendering the translucent pass front-to-back and depth write/testing.&lt;/p&gt;&#xA;" OwnerUserId="3331" LastEditorUserId="3331" LastEditDate="2016-09-12T17:31:40.257" LastActivityDate="2016-09-12T17:31:40.257" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3997" PostTypeId="2" ParentId="3994" CreationDate="2016-09-12T14:00:21.257" Score="2" Body="&lt;p&gt;welcome to the world of padding. Doubles are 8 byte aligned so when a 4 byte float gets inserted between 2 doubles some padding gets inserted to keep the next double aligned to a 8 byte boundary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can make sure the offset is always correct (even when alignment changes in future versions) by using the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.offsetof(v=vs.110).aspx&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;Marshal.OffsetOf(Type, String)&lt;/code&gt;&lt;/a&gt; method.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-09-12T14:00:21.257" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="3998" PostTypeId="1" AcceptedAnswerId="3999" CreationDate="2016-09-12T17:41:49.053" Score="6" ViewCount="4271" Body="&lt;p&gt;Reading through some code about voxelization I found the following line in the fragment shader&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;layout (binding = 0, r32f ) coherent uniform writeonly image3D volumeTexture;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have only used &lt;code&gt;samplers&lt;/code&gt; in the past and have never seen &lt;code&gt;image3D&lt;/code&gt; before. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have read the entries about &lt;a href=&quot;https://www.opengl.org/wiki/Sampler_(GLSL)&quot; rel=&quot;noreferrer&quot;&gt;Sampler Varibles&lt;/a&gt; and &lt;a href=&quot;https://www.opengl.org/wiki/Image_Load_Store#Image_variables&quot; rel=&quot;noreferrer&quot;&gt;Image Variables&lt;/a&gt; but I really don't grasp the differences, advantages/disadvantages between Sampler and Image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone help me pointing out what are the difference between these two types of variables and when should I used one over the other?&lt;/p&gt;&#xA;" OwnerUserId="116" LastEditorUserId="116" LastEditDate="2016-09-12T19:03:29.133" LastActivityDate="2016-09-14T09:05:31.750" Title="What is the difference between a Sampler and an Image variables in GLSL?" Tags="&lt;glsl&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="3999" PostTypeId="2" ParentId="3998" CreationDate="2016-09-12T17:48:52.590" Score="4" Body="&lt;p&gt;Unlike samplers imageLoad (Load in HLSL) requires a texel coordinate (integer). This will load the value at that location only. The range of the coordinate can be (0,0) to (image width, image height). Because only an integer can be supplied no sampling is applied to blend between multiple texels (e.g. bilinear in 2D). I'd therefore &lt;strong&gt;assume&lt;/strong&gt; it is a cheaper operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Image processing algorithms such as blurs often use image load so that discrete texel values can be processed.&lt;/p&gt;&#xA;" OwnerUserId="3331" LastEditorUserId="3331" LastEditDate="2016-09-12T18:22:19.587" LastActivityDate="2016-09-12T18:22:19.587" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4000" PostTypeId="2" ParentId="3998" CreationDate="2016-09-12T18:24:17.537" Score="5" Body="&lt;ul&gt;&#xA;&lt;li&gt;Images creation is the same as texture, but it must be binded as&#xA;image to image units. These are equivalent of &quot;texture units&quot;.&lt;/li&gt;&#xA;&lt;li&gt;With them you can arbitrarily perform read/write/modify operations&#xA;using &lt;code&gt;imageStore/imageLoad&lt;/code&gt; or atomic operations at some coordinates. Unlike samplers these&#xA;coordinates are in unsigned integer range.&lt;/li&gt;&#xA;&lt;li&gt;They do not need to be part of framebuffer color attachments to write&#xA;into them. This is useful and simplify some techniques like injecting&#xA;data into volume textures and is used in compute shaders. No need to use draw calls with buffer data upload.&lt;/li&gt;&#xA;&lt;li&gt;There is no mipmapping or texture filtering available when doing&#xA;operation on texture binded as image.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-09-14T09:05:31.750" LastActivityDate="2016-09-14T09:05:31.750" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4001" PostTypeId="2" ParentId="3998" CreationDate="2016-09-12T18:28:23.067" Score="6" Body="&lt;p&gt;Image and Samplers differ in many ways. Unlike Samplers, images can only be addressed with an integer coordinate that ranges from  (0,0) to (x,y), where x and y are the width and height of the image. They support random access reads like texelFetch, and support no filtering as you're accessing raw texels. The most interesting thing with images is that they support read and write access, in Open GLES there are limitations, wherein an image may only be specified as readonly or writeonly, not both, in desktop GL though you may specify an image as read/write so that you can both read and write to that image in a single pass. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using a sampler, if you wanted to write a color into it you'd have to use an FBO, then a second pass to consume that. With images, you can do this all in one pass by writing to the image and reading from it, you'd have to handle the synchronisation yourself of course.&#xA;Images are very useful for image processing etc.&lt;/p&gt;&#xA;" OwnerUserId="2351" LastActivityDate="2016-09-12T18:28:23.067" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4002" PostTypeId="1" AcceptedAnswerId="4009" CreationDate="2016-09-12T19:03:31.397" Score="8" ViewCount="416" Body="&lt;p&gt;I'm using www.scratchapixel.com among other resources to help me learn how to implement a renderer. I am looking at the following code from &lt;a href=&quot;http://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/monte-carlo-methods-in-practice/monte-carlo-simulation&quot;&gt;this page&lt;/a&gt; where a packet of photons moving through a material is being considered. For each photon packet, the weight $w$ is initialised to $1$. $dw$ is the probability of absorption.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The confusing part to me is when $dw$ is subtracted from $w$. I can see this would make sense when the packet has full-weight of $1$ because $1 - dw$ is the unabsorbed proportion of photons. E.g. if probability of absorption is $33\%$ then $w = 1 - 0.33 = 0.67$ and $67\%$ of the photons remain. I can't see how this makes sense on subsequent iterations. For example, on iteration two, $w = 0.67 - 0.33 = 0.34$ so half the photons are absorbed on this iteration, not a third.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int photons = 10000; &#xA;... &#xA;int m = 5; // there's 1 over 6 chances for the packet to be absorbed &#xA;for (int i = 0; i &amp;lt; nphotons; ++i) { &#xA;    float w = 1; // set the weight to 1 &#xA;    Vec3f P(0, 0, 0); &#xA;    Vec3f V(0, 0, 1); &#xA;    while (1) { &#xA;        ... &#xA;        float dw = sigma_a / sigma_t; &#xA;        absorption += dw; &#xA;        w -= dw; &#xA;        if (w &amp;lt; 0.001) { // perform russian roulette if weight is small &#xA;            if (drand48() &amp;lt; 1.0 / m) { &#xA;                break; // we kill the packet &#xA;            } &#xA;            else &#xA;                w *= m; // adjust weight &#xA;        } &#xA;    } &#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2941" LastEditorUserId="2941" LastEditDate="2016-09-12T19:29:11.853" LastActivityDate="2016-09-14T15:46:57.783" Title="Is this Russian roulette code correct?" Tags="&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4003" PostTypeId="2" ParentId="3990" CreationDate="2016-09-12T23:08:32.867" Score="6" Body="&lt;p&gt;Doing it in the CPU side during initialization is what I'd go for, this is assuming you are initialising that data once and passing it to the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the GPU side, doing the calculations per fragment would be too costly and should be out of the question, unless it's really needed for a special effect then you shouldn't add unneeded ALU work to the fragment shader, this will only cause your application to slow down. On the vertex shader is more acceptable but again if you have highly tessellated geometry, it'll be expensive. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whenever there is data that you can compute just once, then go for that instead of doing it every frame. Even if you were planning on doing it just once on the GPU and using transform feedback or an FBO to store the data, I think this approach would be more costly. As always though, profile your application, careful tradeoffs are specific to architectures.&lt;/p&gt;&#xA;" OwnerUserId="2351" LastActivityDate="2016-09-12T23:08:32.867" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4004" PostTypeId="1" AcceptedAnswerId="4007" CreationDate="2016-09-13T11:52:00.110" Score="1" ViewCount="2246" Body="&lt;p&gt;I have object loader, which i want to have background. I tried to put jpg image like texture to my application. I tried to make that with FreeImage library, but the image didn't show. Also i tried with Gdiplus, i opened the image but when i opened and the object the background disappeared.&#xA;I send link with the code (with FreeImage library), If someone have any ideas i will be so happy, because I haven't yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Nushiii/viewer/blob/master/ViewerPicture%20FreeImege/ViewerPicture/main.cpp&quot; rel=&quot;nofollow&quot;&gt;https://github.com/Nushiii/viewer/blob/master/ViewerPicture%20FreeImege/ViewerPicture/main.cpp&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;       int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)&#xA;    {&#xA;&#xA;    MSG msg = {0};&#xA;    WNDCLASSEX wcl = {0};&#xA;&#xA;    GLuint texture;&#xA;    float theta = 0.0f;&#xA;&#xA;    wcl.cbSize = sizeof(wcl);&#xA;    wcl.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;&#xA;    wcl.lpfnWndProc = WindowProc;&#xA;    wcl.cbClsExtra = 0;&#xA;    wcl.cbWndExtra = 0;&#xA;    wcl.hInstance = g_hInstance = hInstance;&#xA;    wcl.hIcon = static_cast&amp;lt;HICON&amp;gt;(LoadImage(hInstance,&#xA;    MAKEINTRESOURCE (IDI_ICON1),&#xA;    IMAGE_ICON,&#xA;    48, 48,    // or whatever size icon you want to load&#xA;    LR_DEFAULTCOLOR));&#xA;    wcl.hCursor = LoadCursor(0, IDC_ARROW);&#xA;    wcl.hbrBackground = 0;&#xA;    wcl.lpszMenuName = MAKEINTRESOURCE(MENU_FIXED_FUNC);&#xA;    wcl.lpszClassName = &quot;GLWindowClass&quot;;&#xA;    wcl.hIconSm = 0;&#xA;&#xA;    if (!RegisterClassEx(&amp;amp;wcl))&#xA;        return 0;&#xA;&#xA;    g_hWnd = CreateAppWindow(wcl, APP_TITLE);&#xA;&#xA;          // load our texture&#xA;      FIBITMAP  *dib1 = loadImage(&quot;angel.jpg&quot;);&#xA;      texture = LoadTexturee( dib1, TRUE );&#xA;&#xA;    if (g_hWnd)&#xA;    {&#xA;        SetProcessorAffinity();&#xA;&#xA;        if (Init())&#xA;        {&#xA;            ShowWindow(g_hWnd, nShowCmd);&#xA;            UpdateWindow(g_hWnd);&#xA;&#xA;            while (true)&#xA;            {&#xA;                if (PeekMessage(&amp;amp;msg, 0, 0, 0, PM_REMOVE))&#xA;                {&#xA;                    if (msg.message == WM_QUIT)&#xA;                        break;&#xA;&#xA;                    TranslateMessage(&amp;amp;msg);&#xA;                    DispatchMessage(&amp;amp;msg);&#xA;                } else {&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;              &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;                  UpdateFrame(GetElapsedTimeInSeconds());&#xA;                  DrawFrame(texture, g_hDC);&#xA;                  SwapBuffers(g_hDC);&#xA;&#xA;                }&#xA;&#xA;                if (msg.message == WM_QUIT)&#xA;                    break;&#xA;&#xA;            }&#xA;        }&#xA;&#xA;        Cleanup();&#xA;        UnregisterClass(wcl.lpszClassName, hInstance);&#xA;    }&#xA;    FreeTexture( texture );&#xA;    return static_cast&amp;lt;int&amp;gt;(msg.wParam);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; &lt;strong&gt;Now i load the picture, but the object doesn'n load.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;VOID DrawFrame(GLuint texture,HDC hDC)&#xA;{ &#xA;&#xA;glMatrixMode(GL_PROJECTION);&#xA;glPushMatrix();&#xA;glLoadIdentity();&#xA;&#xA;glMatrixMode(GL_MODELVIEW);&#xA;glPushMatrix();&#xA;glLoadIdentity();&#xA;&#xA;&#xA;  // setup texture mapping&#xA; glEnable( GL_TEXTURE_2D );&#xA; glBindTexture( GL_TEXTURE_2D, texture );&#xA;&#xA; glPushMatrix();&#xA; glBegin( GL_QUADS );&#xA; glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0);&#xA; glTexCoord2d(1.0,0.0); glVertex2d(+1.0,-1.0);&#xA; glTexCoord2d(1.0,1.0); glVertex2d(+1.0,+1.0);&#xA; glTexCoord2d(0.0,1.0); glVertex2d(-1.0,+1.0);&#xA; glEnd();&#xA; glPopMatrix();&#xA;&#xA;glClear(GL_DEPTH_BUFFER_BIT);&#xA;glMatrixMode(GL_PROJECTION);&#xA;glPopMatrix(); // Pops our orthographic projection matrix&#xA;glMatrixMode(GL_MODELVIEW);&#xA;glMatrixMode(GL_PROJECTION); &#xA;glLoadIdentity();&#xA;gluPerspective(CAMERA_FOVY,&#xA;   static_cast&amp;lt;float&amp;gt;(g_windowWidth) / static_cast&amp;lt;float&amp;gt; (g_windowHeight),&#xA;   CAMERA_ZNEAR, CAMERA_ZFAR);&#xA;    glMatrixMode(GL_MODELVIEW);&#xA;glLoadIdentity();&#xA;gluLookAt(g_cameraPos[0], g_cameraPos[1], g_cameraPos[2],&#xA;  g_targetPos[0], g_targetPos[1], g_targetPos[2],&#xA;  0.0f, 1.0f, 0.0f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;" OwnerUserId="5117" LastEditorUserId="38" LastEditDate="2016-09-29T08:36:14.217" LastActivityDate="2016-09-29T08:36:14.217" Title="Background behind 3D model" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;texture&gt;&lt;legacy-opengl&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4005" PostTypeId="1" AcceptedAnswerId="4006" CreationDate="2016-09-13T19:06:08.477" Score="8" ViewCount="1323" Body="&lt;p&gt;Let's say we are path tracing and that there is an object which has some amount of diffuse reflection, and some amount of specular reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the best or correct way to handle that in the path tracer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at smallpt (&lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot; rel=&quot;noreferrer&quot;&gt;http://www.kevinbeason.com/smallpt/&lt;/a&gt;), it doesn't allow for objects to have both, but instead forces materials to be either diffuse or specular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've seen other path tracing code which rolls a random number to choose which way to go, using the luminance of the diffuse and specular reflectance as weightings in the random roll.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also seen code which follows both paths and diverges when this happens and sums the results, where each recursive ray was multiplied by it's corresponding reflectance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've seen refraction dealt with similarly to all the above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a physically correct way to handle these situations?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-09-14T00:03:18.343" Title="Proper way to handle diffuse + refraction + reflection rays in path tracing?" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4006" PostTypeId="2" ParentId="4005" CreationDate="2016-09-14T00:03:18.343" Score="7" Body="&lt;p&gt;Let us take one step back.&#xA;When you do path tracing, you are doing a Monte Carlo integration.&#xA;What does this mean? You try to solve $\int f(x)\mathrm{d}x$ by sampling.&#xA;The Monte Carlo integration says for a sufficiently big $n$: $\frac{1}{n}\sum_{i=0}^n f(x_i) \rightarrow \int f(x)p(x) \mathrm{d}x$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we instead sum $\frac{f(x_i)}{p(x_i)}$ we get $\frac{1}{n}\sum_{i=0}^n \frac{f(x_i)}{p(x_i)} \rightarrow \int f(x) \mathrm{d}x$.&#xA;Now your $f(x)$ is the rendering equation and you got yourself a way to approximate the rendering equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that we are on the same page about the basics, let's consider what you do.&#xA;You generate a path of light, that will become one of the samples $\frac{f(x_i)}{p(x_i)}$. In order to do this you model the interaction of the light with the surface at each step along the path. And you always update your current path probability $p(x_i)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is now the correct way to handle a material that has multiple different ways that a ray could travel? There is no one correct way. The only important part is, that your values $n$, $f(x_i)$ and $p(x_i)$ stay correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you diverge the path and spawn two rays, you have to increase the number $n$ of total samples accordingly because now you have done two samples. Then handle both pathes as if they were separate from the beginning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to only continue one path, you can do it with the russian roulette way.&#xA;Define three intervals (one common way is to chose the intervals to be a partition of the numbers between 0 and 1). The relative sizes of these intervals have to be proportional to the material. The tricky part is how do you design this. In my class we defined a number reflectivity $\rho$.&#xA;We draw a random number between 0 and 1, if it is lower than $\rho$ the path ends. Else we reflect. The BRDF will take care to weight the specular vs diffuse part if you do enough samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course you can improve this via importance sampling, and that is probably where you have problems. For a very specular surface design a random distribution that just draws more directions from the specular reflection direction. Rest will be diffuse. I don't have enough experience with actually bulding path tracers to help you how to design one, but your sources will probably have something here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Important here is again: Design it so that you know how probable a specific direction is, and then keep your $p(x_i)$ up to it, so you can in the end divide by this and get a correct Monte Carlo estimate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TL;DR There is no correct way. It is ONLY important to keep the probabilities of samples in mind.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope I haven't missed the point of your question entirely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Addition:&#xA;Monte Carlo samling, as long as you correct weighting by probability, will always with infinite samples converge against the correct value. This means even if you use a complete stupid way to generate samples, if you do it long enough, that will work. Maybe not in your lifetime or that of your great grandchildren, but it will.&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2016-09-14T00:03:18.343" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4007" PostTypeId="2" ParentId="4004" CreationDate="2016-09-14T07:49:05.447" Score="5" Body="&lt;p&gt;Normally if you paint a background image you simply draw a textured full-screen square while depth testing and writing is disabled before drawing the actual scene (where you re-enable depth)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the code you posted you draw the quad but then clear the screen again. Don't do that. Move the drawing of the quad from main to right after the &lt;code&gt;glClear&lt;/code&gt; call.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2016-09-17T12:30:43.597" LastActivityDate="2016-09-17T12:30:43.597" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4008" PostTypeId="1" CreationDate="2016-09-14T11:53:11.273" Score="3" ViewCount="745" Body="&lt;p&gt;I am given geometry of a cylinder which lies on the XY plane with 1 unit radius. And given coordinates of 2 points in 3D I need to move the cylinder so that it connects the two points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I tried so far after searching online:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Calculated the vector between the two points p = p1 - p2;&lt;/li&gt;&#xA;&lt;li&gt;Took the normal vector to the plane(0,0,1) v&lt;/li&gt;&#xA;&lt;li&gt;Axis of rotation = v x p (cross)&lt;/li&gt;&#xA;&lt;li&gt;angle of rotation = acos(|v|.|p|) (unit vectors)&lt;/li&gt;&#xA;&lt;li&gt;I applied this rotation.&lt;/li&gt;&#xA;&lt;li&gt;Translated one of the end point of cylinder to one of the points.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;but it moves the object to a wrong location. Any help what I'm doing wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: My apologies for not being able to respond.&#xA;The main issue was with this line.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;angle of rotation = acos(|v|.|p|) (unit vectors)&#xA;I normalized the vectors then used this wrong formula. Which will always return 90 degrees.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I am still not getting exactly the correct output. Here is the screenshot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GwXFS.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GwXFS.jpg&quot; alt=&quot;Atom bond representation of ligands&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5121" LastEditorUserId="5121" LastEditDate="2016-10-05T15:46:49.993" LastActivityDate="2017-04-04T02:43:50.083" Title="Rotate a cylinder from XY plane to given points" Tags="&lt;opengl&gt;&lt;transformations&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4009" PostTypeId="2" ParentId="4002" CreationDate="2016-09-14T15:46:57.783" Score="4" Body="&lt;p&gt;I think you're right and the subtraction is a mistake. The code should rather be multiplying the fraction of photons not absorbed into the weight. Something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float fraction_absorbed = sigma_a / sigma_t;&#xA;absorption += w * fraction_absorbed;&#xA;w *= (1.0f - fraction_absorbed);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This makes &lt;code&gt;absorption&lt;/code&gt; the total fraction of photons absorbed so far, and &lt;code&gt;w&lt;/code&gt; the fraction of photons remaining.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-14T15:46:57.783" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4010" PostTypeId="2" ParentId="3982" CreationDate="2016-09-15T03:25:15.923" Score="3" Body="&lt;p&gt;For the lightning, I recommend using a midpoint displacement algorithm. You start with a line segment between any 2 points A and B (this works in either 2D or 3D). Calculate the midpoint of the segment AB. Now move that point a random amount in the direction perpendicular to the line segment AB and call it point C. Replace the original segment AB with 2 line segments AC and CB. Repeat with the new line segments until you are satisfied with how it looks. In my experience you'll need somewhere between 5 and 10 iterations depending on the resolution you're working at. You can add a glow to the resulting geometry to make it look more realistic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For sparks you need to make a particle system. These are pretty fun. You generally have a point (or other shape) that generates particles every few milliseconds. That is, particles are spontaneously formed on the point or boundary of the shape periodically. Each particle has various properties such as location, velocity, color, size, lifetime, etc. When animating, you can update the velocity and position based on various forces such as gravity, wind, or some sort of convection current or flow field. After a particle has reached its &quot;lifetime&quot; it can disappear, or fade out, and a new particle will be generated in its place at the point or on the boundary of the shape. The particles themselves can be drawn as single pixels, small shapes, or images. There's an &lt;a href=&quot;https://en.wikipedia.org/wiki/Particle_system&quot; rel=&quot;nofollow&quot;&gt;interesting wikipedia article on particle systems&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-09-15T03:25:15.923" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4011" PostTypeId="1" AcceptedAnswerId="4012" CreationDate="2016-09-15T17:02:16.237" Score="6" ViewCount="624" Body="&lt;p&gt;I've been doing some side-research on computer graphics as a hobby and came across this article on quaternions:&#xA;&lt;a href=&quot;http://www.opengl-tutorial.org/assets/faq_quaternions/index.html#Q2&quot; rel=&quot;noreferrer&quot;&gt;http://www.opengl-tutorial.org/assets/faq_quaternions/index.html#Q2&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first section on matrices, it describes 2x2, 3x3, and 4x4 matrices and their functions.  Here is the entry on 3x3 matrices:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;3x3 matrices are used to perform low-budget 3D animation. Operations&#xA;  such as rotation and multiplication can be performed using matrix&lt;br&gt;&#xA;  operations, but perspective depth projection is performed using&lt;br&gt;&#xA;  standard optimised into pure divide operations.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if this blurb means that 3x3 matrices aren't used anymore or if we are still using them for simpler calculations on certain animations.  I understand what perspective depth projection is, but what does it mean it is performed using pure divide operations?&lt;/p&gt;&#xA;" OwnerUserId="5129" LastActivityDate="2016-09-16T20:50:12.490" Title="Do we use 3x3 matrices in computer graphics?" Tags="&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4012" PostTypeId="2" ParentId="4011" CreationDate="2016-09-16T03:47:27.583" Score="4" Body="&lt;p&gt;That quote is a very strange way to phrase things. We definitely use 3x3 matrices in computer graphics. They tend to be most useful for doing affine transformations of 2D objects. It allows you to have scale, rotation, shearing, and translation (in 2D), but not perspective transformations. I believe that's what the quote is trying to say.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get a perspective projection of a 3D scene onto a 2D plane (such as your computer screen), at some point you will need to divide the x and y components of each point in your geometry by some factor that foreshortens lines in the z dimension. That's the divide that they are referring to. See &lt;a href=&quot;https://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection&quot; rel=&quot;nofollow&quot;&gt;this article&lt;/a&gt; for more details. In it, they describe:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The simplest perspective projection uses the origin as the center of projection, and z = 1 as the image plane. The functional form of this transformation is then &lt;em&gt;x' = x / z&lt;/em&gt;; &lt;em&gt;y' = y / z&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2016-09-16T20:50:12.490" LastActivityDate="2016-09-16T20:50:12.490" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4013" PostTypeId="1" AcceptedAnswerId="4018" CreationDate="2016-09-16T16:25:18.357" Score="12" ViewCount="999" Body="&lt;p&gt;In graphics, it's common to take multiple samples within the bounds of a pixel and combine them together (most commonly just doing an average) for a final sample pixel color.  This has the effect of anti aliasing an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On one hand this makes sense to me because what you are effectively doing is integrating the color of the pixel over the area that the pixel represents.  In this line of thinking, averaging &quot;random&quot; samples seems to be the ideal setup, for doing monte carlo integration.  (&quot;random&quot; could be stratified, blue noise based, low discrepency sequences etc)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, this feels wrong (or at least not as correct as it could be) from a digital signal processing point of view.  From that point of view, it feels like we are taking a lot of samples and then downsampling using a box filter (box blur) to get the final pixel value.  In that light, it seems like the ideal thing to do would be to use sinc filtering instead of averaging the samples.  I could see that the box filter is a cheaper aproximation to sinc thinking along these lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This leaves me a bit confused.  Is the core idea that we are integrating the pixel area and averaging is correct?  Or is it that we are downsampling and should be using sinc, but are using a box filter because it's fast?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or is it something else entirely?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A little bit related: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2130/anti-aliasing-filtering-in-ray-tracing&quot;&gt;Anti-aliasing / Filtering in Ray Tracing&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-09-17T04:17:53.697" Title="What is the fundamental reasoning for anti aliasing using multiple random samples within a pixel?" Tags="&lt;sampling&gt;&lt;antialiasing&gt;&lt;supersampling&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4015" PostTypeId="2" ParentId="4013" CreationDate="2016-09-16T18:32:05.067" Score="4" Body="&lt;p&gt;You are in fact doing both things. You are integrating the area and because your result is still discrete samples you are reconstructing the signal to make it continious function. Therefore the higher order filtering. (Also human eye is a discrete sampler so it also reconstructs the signal)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It took me a considerable amount of time to come into terms with this explanation. The thing that helped me was a paper by Tony Apodaca titled &lt;a href=&quot;https://renderman.pixar.com/view/the-lore-of-the-tds&quot; rel=&quot;nofollow&quot;&gt;The Lore of TDs&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-09-16T18:32:05.067" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4016" PostTypeId="1" AcceptedAnswerId="4025" CreationDate="2016-09-16T22:43:27.390" Score="5" ViewCount="194" Body="&lt;p&gt;I have recently been working on area lights for a small open source game engine called Urho3D but have run into an issues when rendering tube lights where the lights look the same as sphere lights despite the length value being changed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am working from &lt;a href=&quot;http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Epic's paper on PBR&lt;/a&gt; by Brian Karis. I have tried looking at other sources to see if I could find anything but none of the results fixed the issue I was having.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The method I am using for tube lighting is as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 TubeLight(float3 worldPos, float3 lightVec, float3 normal, float3 toCamera, float roughness, float3 specColor, out float ndl)&#xA;{&#xA;    float3 pos   = (cLightPosPS.xyz - worldPos);&#xA;    float3 reflectVec  = reflect(-toCamera, normal);&#xA;&#xA;    float3 L01 = lightVec * LightLengh;&#xA;    float3 L0 = pos - 0.5 * L01;&#xA;    float3 L1 = pos + 0.5 * L01;&#xA;    float3 ld = L1 - L0;&#xA;&#xA;    float distL0    = length( L0 );&#xA;    float distL1    = length( L1 );&#xA;&#xA;    float NoL0      = dot( L0, normal ) / ( 2.0 * distL0 );&#xA;    float NoL1      = dot( L1, normal ) / ( 2.0 * distL1 );&#xA;    ndl             = ( 2.0 * clamp( NoL0 + NoL1, 0.0, 1.0 ) ) &#xA;                    / ( distL0 * distL1 + dot( L0, L1 ) + 2.0 );&#xA;&#xA;    float RoL0      = dot( reflectVec, L0 );&#xA;    float RoLd      = dot( reflectVec, ld );&#xA;    float L0oLd     = dot( L0, ld );&#xA;    float distLd    = length( ld );&#xA;    float t         = ( RoL0 * RoLd - L0oLd ) &#xA;                / ( distLd * distLd - RoLd * RoLd );&#xA;&#xA;    float3 closestPoint   = L0 + ld * saturate( t);&#xA;    float3 centreToRay    = dot( closestPoint, reflectVec ) * reflectVec - closestPoint;&#xA;    closestPoint = closestPoint + centreToRay * saturate(LightRad / length(centreToRay));&#xA;&#xA;    float3 l = normalize(closestPoint);&#xA;    float3 h = normalize(toCamera + l);&#xA;&#xA;    ndl       = saturate(dot(normal, l));&#xA;    float hdn = saturate(dot(h, normal));&#xA;    float hdv = dot(h, toCamera);&#xA;    float ndv = saturate(dot(normal, toCamera));&#xA;&#xA;    float distL      = length(closestPoint);&#xA;    float alpha      = roughness * roughness;&#xA;    float alphaPrime = saturate(LightRad / (distL * 2.0) + alpha);&#xA;&#xA;    const float3 fresnelTerm = Fresnel(specColor, hdv) ;&#xA;    const float distTerm     = Distribution(hdn, alphaPrime);&#xA;    const float visTerm      = Visibility(ndl, ndv, roughness);&#xA;&#xA;    return distTerm * visTerm * fresnelTerm ;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the code snippet is not enough to help solve this issue you can download the &lt;a href=&quot;https://github.com/dragonCASTjosh/Urho3D&quot; rel=&quot;nofollow noreferrer&quot;&gt;full area lighting branch&lt;/a&gt; from GitHub. Build instructions can be found on the Urho3D website (cant link due to reputation), note currently area lighting is only tested in DX11. Shader source files can be found under &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[build location]/bin/CoreData/Shaders/HLSL&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.imgur.com/rUzQmHH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/rUzQmHH.jpg&quot; alt=&quot;tube light image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see that both images look identical &lt;a href=&quot;https://imgur.com/a/IxhTd&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If pos in multiplied into line 40 then it creates more of a tube effect but is still far from correct results, &lt;a href=&quot;https://imgur.com/a/zrSwV&quot; rel=&quot;nofollow noreferrer&quot;&gt;As you can see here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5136" LastEditorUserId="5136" LastEditDate="2016-09-17T21:45:10.847" LastActivityDate="2016-09-19T10:19:05.920" Title="Error with tube lighting" Tags="&lt;lighting&gt;&lt;physically-based&gt;&lt;directx11&gt;&lt;hlsl&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="4018" PostTypeId="2" ParentId="4013" CreationDate="2016-09-17T04:17:53.697" Score="9" Body="&lt;p&gt;From a signal processing point of view, you're sampling a continuous-domain signal, and you need to filter it to get rid of frequencies beyond the Nyquist limit. It's that filtering that leads to integrating over the pixel area—or more generally, integrating over the support of your antialiasing kernel (which need not be a box).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider your rendering function that takes a sample point $x, y$ in screen space and returns back the color found at that point. (Let's ignore any issues of random sampling for the moment, and assume it returns a &quot;perfect&quot; rendered color for that specific point.) This function effectively defines a 2D continuous-domain signal. Or to put it another way, it defines an &lt;em&gt;infinite-resolution&lt;/em&gt; image, since nothing prevents this function from having features at arbitrarily small scales. In terms of frequency domain: the function is not band-limited; it can include components of arbitrarily high spatial frequencies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you want to convert it down to a finite number of pixels. Much like digitizing an audio signal, when you sample it, you'll get aliasing unless you first eliminate frequencies beyond the Nyquist limit imposed by the sampling rate. In other words, you have to get rid of features smaller than the pixel grid. To do this, you apply a low-pass filter. The &lt;em&gt;ideal&lt;/em&gt; low-pass filter is the sinc function, but for various reasons of practicality we use other filters (that don't perfectly eliminate frequencies beyond the Nyquist limit, but they at least attenuate them).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Low-pass filtering is done by convolution. If $f(x, y)$ is the rendering function and $k(x, y)$ is a filter kernel, then we can define the low-pass filtered image as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_\text{filtered}(x, y) = \iint f(x', y') \, k(x' - x, y'- y) \, dx' \, dy'$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the image is safe to sample, so the final pixel values are gotten by just evaluating $f_\text{filtered}$ at the pixel coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If $k$ is a box filter, which looks like $k = 1$ within the pixel box and $k = 0$ elsewhere, then this simplifies to just integrating $f$ over the pixel box. But as noted, the box filter isn't so great and there are better choices such as tent, bicubic, and Gaussian filters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, now that we have an integral, we can use Monte Carlo for it and combine it with any other integrals we might like to do—for lighting, motion blur, and so on. We can even apply importance sampling to the $k$ factor in the integral, by generating samples for each pixel that are distributed around the pixel center according to $k$.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-17T04:17:53.697" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4019" PostTypeId="1" CreationDate="2016-09-17T16:06:39.290" Score="3" ViewCount="125" Body="&lt;p&gt;The following is the 2d complex sinusoidal function,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SPyuQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SPyuQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$u_0$ and $v_0$ represent Fundamental Frequencies in $X$ and $Y$ directions respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I represent $j$ (imaginary number)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;here is my use-case:  ...  ...  I need to implement Gabor Filter using both spatial and frequency domain equations. In the link ...  &lt;a href=&quot;http://www.cs.utah.edu/~arul/report/node13.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.cs.utah.edu/~arul/report/node13.html&lt;/a&gt;  ..., you can see that there are several equations. (14) is the equation of Gabor Filter in spatial domain. (15) is the equation of Gabor Filter in frequency domain. Hence, my question.&lt;/p&gt;&#xA;" OwnerDisplayName="user464" LastEditorDisplayName="user464" LastEditDate="2016-09-17T17:25:52.043" LastActivityDate="2016-10-17T18:02:20.260" Title="How can I implement a complex sinusoidal function?" Tags="&lt;image-processing&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4020" PostTypeId="2" ParentId="4019" CreationDate="2016-09-17T17:14:01.057" Score="3" Body="&lt;p&gt;One way to represent a complex-valued function in a bitmap is to use one color channel for the real component and one for the imaginary component. For example, rendering a complex plane wave (your equation) with R = real, G = imaginary looks like this (click for shadertoy):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/MtG3Dz&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F5gb7.png&quot; alt=&quot;complex plane wave&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-17T17:14:01.057" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4021" PostTypeId="1" AcceptedAnswerId="4022" CreationDate="2016-09-18T10:26:35.697" Score="8" ViewCount="206" Body="&lt;p&gt;We are trying to optimize Lighting in fillrate. Integrated graphics chips are very slow in memory access.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two Light Buffers: one for Diffuse and one for Specular. Both use format R11G11B10F. Is there any way to pack two buffers into one? For instance, using color model Y'CbCr:&lt;a href=&quot;https://i.stack.imgur.com/kUIZU.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kUIZU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2069" LastActivityDate="2016-09-20T16:42:47.833" Title="Encode two R11G11B10F buffers into one using Y'CbCr?" Tags="&lt;shader&gt;&lt;color&gt;&lt;optimisation&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4022" PostTypeId="2" ParentId="4021" CreationDate="2016-09-18T18:55:50.977" Score="5" Body="&lt;p&gt;You might want to look at &lt;a href=&quot;http://www.pmavridis.com/research/fbcompression/&quot;&gt;The Compact YCoCg Framebuffer&lt;/a&gt;. It uses a 2-channel buffer to store luminance for every pixel and the two chroma components in half the pixels each, forming a checkerboard. It also uses an edge-aware upsampling filter at the end of the frame to reconstruct the missing chroma components and convert back to RGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could extend this to a single 3-channel buffer to store the diffuse luminance, specular luminance, and checkerboarded chroma (assuming based on the diagram in your question that it suffices to store just one pair of chroma values).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might also consider using R10G10B10A2 format instead, unless you &lt;em&gt;really&lt;/em&gt; need the range of the floating-point format. It's the same amount of bandwidth but will give you a good deal more precision (R11G11B10F only gives you 5–6 bits of mantissa per component). Plus, you can use the 2 bits of alpha to store a couple of flags, such as your diffuse/specular flag.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-09-18T18:55:50.977" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4023" PostTypeId="1" AcceptedAnswerId="4024" CreationDate="2016-09-18T20:42:55.240" Score="6" ViewCount="497" Body="&lt;p&gt;Suppose I have to use bilinear interpolation to rescale image. I more or less understand how enlargement works in case of integer scale factor. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what to do with non-integer scale and especially when you need to downsample an image?&lt;/p&gt;&#xA;" OwnerUserId="5148" LastActivityDate="2016-09-20T05:30:08.800" Title="Image rescaling algorithm" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4024" PostTypeId="2" ParentId="4023" CreationDate="2016-09-19T02:53:45.657" Score="5" Body="&lt;h1&gt;Explanation&lt;/h1&gt;&#xA;&lt;p&gt;With a non-linear scale, you apply different weights for each pixel (or whatever unit you are using). You can use Euclidean distance towards the closest pixels in both directions to determine the weights.&lt;/p&gt;&#xA;&lt;h1&gt;Example&lt;/h1&gt;&#xA;&lt;h2&gt;Normalization&lt;/h2&gt;&#xA;&lt;p&gt;For example, in the image below, the red image is the downsampled image (3x3) and the black image is the original image (4x4). The dots represent the sample points (center of the pixels).&lt;/p&gt;&#xA;&lt;p&gt;You can align the two images by treating each pixel coordinate as a set of two values (x and y) between 0 and 1 (inclusive). Pixels should not be treated as square, so you should treat each pixel as a point rather than a square (when aligning the two images).&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dPoxG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dPoxG.png&quot; alt=&quot;Larger and downsampled image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In the above image, the four corners would all carry the weight of the original image's four corners, for example. The points in the middle would carry different weights depending on the difference between the four neighboring points.&lt;/p&gt;&#xA;&lt;h2&gt;With numbers:&lt;/h2&gt;&#xA;&lt;p&gt;This is a hypothetical area to sample in larger images (not related to the image above). The distances are between original pixels are normalized from 0 to 1 to simplify the math.&lt;/p&gt;&#xA;&lt;p&gt;The black dots represent the sample points (pixels) of the original image. The larger red dots represent the sample points of the downsampled image. The red dot in the top left is closer to the black dot in the top left than the other three surrounding dots, so that pixel will have a heavier weight for determining the color of the downsampled pixel.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/B2wip.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/B2wip.png&quot; alt=&quot;Closeup of sampling region&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Horizontal distance from:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Right 2 original (green) pixels = 0.1 pixels&lt;/li&gt;&#xA;&lt;li&gt;Left 2 original (green) pixels = 0.9 pixels&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Vertical distance from:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Top 2 original (green) pixels = 0.1 pixels&lt;/li&gt;&#xA;&lt;li&gt;Bottom 2 original (green) pixels = 0.9 pixels&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Weight for final pixel:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$weight(0, 0) = (1.0 - 0.1)(1.0 - 0.1) = 0.81$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$weight(0, 1) = (1.0 - 0.1)(1.0 - 0.9) = 0.09$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$weight(1, 0) = (1.0 - 0.9)(1.0 - 0.1) = 0.09$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$weight(1, 1) = (1.0 - 0.9)(1.0 - 0.9) = 0.01$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Subtract from 1 both the horizontal and vertical distance (because closer pixels should carry more weight). The scale factor in this example is 0.75 in each direction.&lt;/p&gt;&#xA;&lt;h1&gt;Scaling Up vs. Scaling Down&lt;/h1&gt;&#xA;&lt;p&gt;Scaling up in the same  process as scaling down. By normalizing both the original image and the new image to between (0, 0) and (1, 1), you can do either with the same process. As an exercise, in the first figure, if the red points were from the original image and the black points were from the enlarged image, you should be able to see that the process is the same.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-09-20T05:30:08.800" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4025" PostTypeId="2" ParentId="4016" CreationDate="2016-09-19T10:19:05.920" Score="4" Body="&lt;p&gt;Found the solution, it turns out the lightVec is not the vector of light from the tube but rather the direction the tube will point. Therefore i will need to pass it a light rotation value to be used there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Results:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/tpgrW.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tpgrW.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5136" LastActivityDate="2016-09-19T10:19:05.920" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4026" PostTypeId="1" CreationDate="2016-09-19T11:19:36.437" Score="2" ViewCount="1034" Body="&lt;p&gt;I'm trying to implement POM using &lt;a href=&quot;http://learnopengl.com/#!Advanced-Lighting/Parallax-Mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial&lt;/a&gt;. As stated, I need to transform fragment-to-camera to tangent space and then pass it to a function.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;tangent space is computed using &lt;a href=&quot;http://www.assimp.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;Assimp&lt;/a&gt;. Well I trusted it. For example tangent vectors look like that (Sponza model):&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OdSJs.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OdSJsm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;then in vertex I make transformation as in tutorial:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;pre&gt;&lt;code&gt;layout (location = 0) in vec3 vPosition;&#xA;layout (location = 1) in vec2 vTexCoord;&#xA;layout (location = 2) in vec3 vNormal;&#xA;layout (location = 3) in vec3 vTangent;&#xA;layout (location = 4) in vec3 vBitangent;&#xA;...&#xA;worldPos = matrices.modelMatrix * vec4(vPosition, 1.0);&#xA;//transform t, b, n from object to world (also called model) space?&#xA;vec3 t = normalize(mat3(matrices.modelMatrix) * vTangent);&#xA;vec3 b = normalize(mat3(matrices.modelMatrix) * vBitangent);&#xA;vec3 n = normalize(mat3(matrices.modelMatrix) * vNormal);&#xA;mTBN = transpose(mat3(t,b,n)); //transpose makes it from model to to tangent space?&#xA;tanViewPos = mTBN * cameraPos;&#xA;tanFragPos = mTBN * worldPos.xyz;&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;then in fragment I pass parameters to function:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;pre&gt;&lt;code&gt;vec3 viewDir = normalize(tanViewPos - tanFragPos);&#xA;    texCoord = steepParallaxMapping(vTexCoord0, viewDir, textureHeight);&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;pre&gt;&lt;code&gt;vec2 steepParallaxMapping(vec2 texCoords, vec3 viewDir, sampler2D textureHeight)&#xA;{&#xA;float height_scale = 0.09;&#xA;// number of depth layers&#xA;const float numLayers = 30.0;&#xA;// calculate the size of each layer&#xA;float layerDepth = 1.0 / numLayers;&#xA;// depth of current layer&#xA;float currentLayerDepth = 0.0;&#xA;// the amount to shift the texture coordinates per layer (from vector P)&#xA;vec2 P = viewDir.xy * height_scale;&#xA;vec2 deltaTexCoords = P / numLayers;&#xA;// get initial values&#xA;vec2  currentTexCoords     = texCoords;&#xA;float currentDepthMapValue = texture2D(textureHeight, currentTexCoords).r;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;while(currentLayerDepth &amp;lt; currentDepthMapValue)&#xA;{&#xA;    // shift texture coordinates along direction of P&#xA;    currentTexCoords -= deltaTexCoords;&#xA;    // get depthmap value at current texture coordinates&#xA;    currentDepthMapValue = texture2D(textureHeight, currentTexCoords).r;&#xA;    // get depth of next layer&#xA;    currentLayerDepth += layerDepth;&#xA;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;// get texture coordinates before collision (reverse operations)&#xA;vec2 prevTexCoords = currentTexCoords + deltaTexCoords;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;// get depth after and before collision for linear interpolation&#xA;float afterDepth  = currentDepthMapValue - currentLayerDepth;&#xA;float beforeDepth = texture2D(textureHeight, prevTexCoords).r - currentLayerDepth + layerDepth;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;// interpolation of texture coordinates&#xA;float weight = afterDepth / (afterDepth - beforeDepth);&#xA;return prevTexCoords * weight + currentTexCoords * (1.0 - weight);&#xA;}&lt;/pre&gt;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thats the result (simple displacement):&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XuvYL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XuvYLm.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or other texture (complex):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bI99O.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bI99Om.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm doing something wrong. And I wonder why we multiply by 3x3 part of the model matrix?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've found function which calculates tbn in fragment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat3 compute_tangent_frame(vec3 N, vec3 P, vec2 UV)&#xA;{&#xA;    // get edge vectors of the pixel triangle&#xA;    vec3 dp1 = dFdx( P );&#xA;    vec3 dp2 = dFdy( P );&#xA;    vec2 duv1 = dFdx( UV );&#xA;    vec2 duv2 = dFdy( UV );&#xA;&#xA;    // solve the linear system&#xA;    vec3 dp2perp = cross( dp2, N );&#xA;    vec3 dp1perp = cross( N, dp1 );&#xA;    vec3 T = dp2perp * duv1.x + dp1perp * duv2.x;&#xA;    vec3 B = dp2perp * duv1.y + dp1perp * duv2.y;&#xA;&#xA;    // construct a scale-invariant frame&#xA;    float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) );&#xA;    return mat3( T * invmax, B * invmax, N );&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;First Case:&lt;/strong&gt; So if I use that function like that:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//in vertex&#xA;vFar = cameraPos - worldPos.xyz; &#xA;//in fragment&#xA;mat3 TBN = (compute_tangent_frame(vNormal0, normalize(vFar), vTexCoord0));&#xA;vec3 viewDir = (transpose(TBN)*normalize(cameraPos - worldPos.xyz));&#xA;vec2 texCoord = steepParallaxMapping(vTexCoord0, viewDir, textureHeight);&#xA;vNormalExtr = normalize(texture2D(textureNormal, texCoord).rgb*2.0 - 1.0);&#xA;normalMapColor = vec4(normalize((TBN) * vNormalExtr), 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;parallax (all walls) and normal light seem to be ok:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1YKhy.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1YKhym.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Second Case:&lt;/strong&gt; But if I use my TBN from CPU:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//in vertex&#xA;mat4 model = ((matrices.modelMatrix));&#xA;vec3 t = normalize(mat3(model) * (vTangent));&#xA;vec3 b = normalize(mat3(model) * (vBitangent));&#xA;vec3 n = normalize(mat3(model) * (vNormal));&#xA;mTBN = ((mat3(t,b,n)));&#xA;//in fragment&#xA;mat3 TBN = mTBN;&#xA;vec3 viewDir = (transpose(TBN)*normalize(cameraPos - worldPos.xyz));&#xA;vec2 texCoord = steepParallaxMapping(vTexCoord0, viewDir, textureHeight);&#xA;vNormalExtr = normalize(texture2D(textureNormal, texCoord).rgb*2.0 - 1.0);&#xA;normalMapColor = vec4(normalize((TBN) * vNormalExtr), 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;parallax is still twisted on all walls but normal light seem to be ok:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KQFIr.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KQFIrm.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I dont transpose tbn (viewDir) (the correct way You said) in second case (mTBN)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 viewDir = ((TBN)*normalize(cameraPos - worldPos.xyz));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then some walls seem to be correct, others not...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Adventures in tangent space...&#xA;Is there a badge of longest question ever or biggest number of pictures?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2vdi7.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2vdi7.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vA5lc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vA5lc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-10-01T11:09:43.383" LastActivityDate="2020-05-30T03:58:53.173" Title="Transforming fragment-to-camera to tangent space for parallax occlusion mapping" Tags="&lt;shader&gt;&lt;texture&gt;&lt;transformations&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4028" PostTypeId="2" ParentId="4021" CreationDate="2016-09-20T16:42:47.833" Score="2" Body="&lt;p&gt;If you are ok with specular being only white, you could put diffuse and specular into RGBA.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like that is what unity does for it's deferred rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Someone discovering this issue:&#xA;&lt;a href=&quot;http://forum.unity3d.com/threads/specular-color-based-on-light-color.134412/&quot; rel=&quot;nofollow&quot;&gt;http://forum.unity3d.com/threads/specular-color-based-on-light-color.134412/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The docs mentioning it:&#xA;&lt;a href=&quot;https://docs.unity3d.com/Manual/RenderTech-DeferredLighting.html&quot; rel=&quot;nofollow&quot;&gt;https://docs.unity3d.com/Manual/RenderTech-DeferredLighting.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-09-20T16:42:47.833" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4029" PostTypeId="1" CreationDate="2016-09-20T21:55:43.057" Score="2" ViewCount="131" Body="&lt;p&gt;I know in computer graphic, we can set a world window in world coordinate system, and then mapping it to viewport which is the display window. Things that are not in the world window should not be displayed and we can do this through Clipping (like in OpenGL). I have a question that do we have alternative methods?  &lt;/p&gt;&#xA;" OwnerUserId="5105" LastActivityDate="2016-09-22T12:56:43.040" Title="Alternatives to Clipping in avoiding display problem" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4030" PostTypeId="2" ParentId="4029" CreationDate="2016-09-22T12:56:43.040" Score="4" Body="&lt;p&gt;&lt;em&gt;&amp;quot;Go not to the CG Elves for counsel for they will say both no and yes&amp;quot;.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Yes and No. As noted in another post, these issues don't exist with ray tracing but I'll assume you are interested in standard rasterisation.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;It's possible to dispose of near clipping by using homogeneous rendering but that can introduce additional cost. (e.g more expensive triangle set up, more difficulty in identifying which screen regions are covered in tile-based renderers)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You could eliminate XY clipping by using float representations for the X and Y coordinates in the rasteriser &lt;em&gt;but&lt;/em&gt; that can lead to catastrophic cancellation when computing triangle determinants which, AFAICS, is a necessary step. In my experience, hardware rasterisers* usually work in fixed-point so that everything is 'exact'.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;As a compromise to XY clipping, guard-band clipping was introduced so that clipping only needs to be done on triangles that extend a 'long'** way off screen. Culling, however, is still be done with the standard frustum planes to eliminate those that are trivially off-screen.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;*Dreamcast being a notable exception.&lt;/p&gt;&#xA;&lt;p&gt;**for certain definitions of 'long', e.g. a small integer multiple of the screen width/height.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-09-22T12:56:43.040" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4031" PostTypeId="1" AcceptedAnswerId="4032" CreationDate="2016-09-23T12:20:26.900" Score="11" ViewCount="12320" Body="&lt;p&gt;I'm working with Kinect face api, it provides an array of vertices and indices for triangles which is to be rendered to make the face image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The no of vertices and their order in array as well as the indices given by kinect is always constant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However the api gives no information on UV data and vertex normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The application requires me to keep the vertex order as given out by the kinect as their positions in 3d space change as per facial movement so generating uv and normals in a 3d editing software is out of question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I managed to generate UV by projecting the vertex positions onto a 2D plane  since there were very few vertices on same plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I don't know how to generate vertex normals for the mesh, without vertex normal the face mesh draws with no depth of its features from prespective, although silhouette is visible as vertex positions are correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that due to absence of vertex normals the lighting wont work correctly on it and hence the pale featureless mesh it looks right now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so how do I generate vertex normals when all I have is just vertex position and the index of vertices to make triangles out of it?&lt;/p&gt;&#xA;" OwnerUserId="5171" LastActivityDate="2016-09-23T18:17:51.310" Title="Programmatically generating vertex normals" Tags="&lt;mesh&gt;&lt;shading&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4032" PostTypeId="2" ParentId="4031" CreationDate="2016-09-23T17:59:18.003" Score="15" Body="&lt;p&gt;Computing the normal from vertex positions is quite simple using the vector cross product.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross_product&quot; rel=&quot;noreferrer&quot;&gt;cross product&lt;/a&gt; of two vectors $u$ and $v$ (noted $u \times v$, or sometimes $u \wedge v$) is a vector perpendicular to $u$ and $v$, of length $||u \times v|| = ||u|| \cdot ||v|| sin(\theta)$, with $\theta$ the angle between $u$ and $v$. The direction of the vector will depend on the order of the multiplication: $u \times v$ is the opposite of $v \times u$ (the two directions perpendicular to the plane).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are not familiar with the cross product, I invite you to read about it and get comfortable with it. Normals will then seem simple.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Flat shading normals&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you have a triangle $ABC$, $AB \times AC$ is a vector perpendicular to the triangle and with a length proportional to its area. Since the normal is the unit vector perpendicular to the triangle's plane, you can get the normal with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N = \dfrac{AB \times AC}{||AB \times AC||}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In code, this would look like &lt;code&gt;n = normalize(cross(b-a, c-a))&lt;/code&gt; for example. Just apply this over all your faces and you will have your normals per face.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;For each triangle ABC&#xA;    n := normalize(cross(B-A, C-A))&#xA;    A.n := n&#xA;    B.n := n&#xA;    C.n := n&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that this assumes vertices are not shared between triangles. I am not familiar with the Kinect API; it's quite possible that they are shared, in which case you would have to duplicate them, or move on to the next solution:&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Smooth shading normals&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;After lighting with normals computed as above, you will notice that triangle edges are apparent. If this in not desirable, you can compute smooth normals instead, by taking into account all the faces that share a same vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is that if a same vertex is shared by three triangles $T1$, $T2$ and $T3$ for example, the normal $N$ will be the average of $N1$, $N2$ and $N3$. Moreover, if $T1$ is a big triangle and $T2$ is a tiny one, you probably want $N$ to be more influenced by $N1$ than by $N2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember how the cross product is proportional to the area? If you add up the cross products then normalize the sum, it will do exactly the weighted sum we want. So the algorithm becomes:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;For each vertex&#xA;    vertex.n := (0, 0, 0)&#xA;&#xA;For each triangle ABC&#xA;    // compute the cross product and add it to each vertex&#xA;    p := cross(B-A, C-A)&#xA;    A.n += p&#xA;    B.n += p&#xA;    C.n += p&#xA;&#xA;For each vertex&#xA;    vertex.n := normalize(vertex.n)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This technique is explained in longer detail this article by Iñigo Quilez: &lt;a href=&quot;http://www.iquilezles.org/www/articles/normals/normals.htm&quot; rel=&quot;noreferrer&quot;&gt;clever normalization of a mesh&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;For more on normals, see also:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1562/how-to-calculate-surface-normals-for-generated-geomtery/1576#1576&quot;&gt;How to Calculate Surface Normals for Generated Geomtery&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="182" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-09-23T18:17:51.310" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4033" PostTypeId="1" AcceptedAnswerId="4034" CreationDate="2016-09-23T23:10:56.370" Score="3" ViewCount="218" Body="&lt;p&gt;Working on optimizing a fragment shader which is slowing down my OpenGL ES 2.0 shader based game. This is used with a shadow buffer to determine if the fragment/pixel is inside a shadow volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem/slowdown is the fact I need a branch if or function to determine a 1.0 (no shadow) or 0.0 (shadowed) based on comparison of the frag's shadow Z and shadow buffer Z.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    // SLOWEST&#xA;    if ( shadowValue &amp;gt; shadowTexZ ) return 1.0; else return 0.0;&#xA;&#xA;    // ALSO SLOW&#xA;    return clamp( 1.0 + (shadowValue - shadowTexZ) * 1000.0, 0.0, 1.0 );&#xA;&#xA;    // SLIGHT LESS SLOW&#xA;    return max(sign(shadowValue - shadowTexZ), 0.0);&#xA;&#xA;    // ALSO SLOW&#xA;    return sign( shadowValue - shadowTexZ ) * 0.5 + 0.5;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I disable the shadow test all together, GPU time in Xcode is 12ms and solid 60fps.  With the test on it jumps to 26ms and drops the framerate unacceptably to 40fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="5173" LastActivityDate="2016-09-24T19:55:23.803" Title="OpenGL ES Frag Shader - Branching" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;optimisation&gt;&lt;fragment-shader&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4034" PostTypeId="2" ParentId="4033" CreationDate="2016-09-24T19:55:23.803" Score="3" Body="&lt;p&gt;I think the most efficient way might be either&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;return float(shadowValue &amp;gt; shadowTexZ);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;return step(shadowTexZ, shadowValue);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2811" LastActivityDate="2016-09-24T19:55:23.803" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4035" PostTypeId="1" AcceptedAnswerId="4038" CreationDate="2016-09-25T18:03:12.037" Score="2" ViewCount="237" Body="&lt;p&gt;I was trying to understand how real-time illumination happens with image-based lighting. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understood that importance of representing the Environment Map and BRDF in spherical harmonics. Because both of them orthonormal basis function so that the illumination integral becomes a matter of dot product of coefficients.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But before that,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is environment map in the global frame and BRDF in  the local frame? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit 1: To help more this is the paper &lt;a href=&quot;http://www.msr-waypoint.net/en-us/um/people/johnsny/papers/shbrdf.pdf&quot; rel=&quot;nofollow&quot;&gt;Fast, Arbitrary BRDF Shading&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5181" LastEditorUserId="5181" LastEditDate="2016-09-26T00:15:20.853" LastActivityDate="2016-09-26T17:49:36.257" Title="Real time image based lighting for arbitrary BRDFs coordinate alignment" Tags="&lt;real-time&gt;&lt;brdf&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4036" PostTypeId="1" AcceptedAnswerId="4037" CreationDate="2016-09-25T23:23:39.913" Score="5" ViewCount="291" Body="&lt;p&gt;I have read about spherical harmonics from &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter10.html&quot;&gt;Here&lt;/a&gt; about the usage of SH for generating Irradiance Environment Maps and how it can make the process of generating EM faster than the regular operations. what they say is : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;&lt;em&gt;if we want to generate a diffuse cube map with an edge length of just 32 texels, from an input cube map with an edge length of 64 texels, the cost is 32x32x6x64x64x6 around 151 million operations. real-time generation of irradiance environment maps cannot be achieved using such a brute-force algorithm. &#xA;the runtime complexity for Spherical harmonics method in the example is just 9 x 64 x 64 x 6 around thousand operations per function&lt;/em&gt;&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;my questions are :&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;how the cost of generating cube map with the edge length of 32 texels from a 64 one has been calculated as 32x32x6x64x64x6 and why not 32x32x6+64*64*6? and why for SH, the cost of generating is 9x64x64x6 ?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;brute-force algorithm finds the shortest path from one node to another. how this algorithm used for that cubemap generation ?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5182" LastActivityDate="2016-09-26T12:58:48.857" Title="The Process of Spherical Harmonics" Tags="&lt;uv-mapping&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4037" PostTypeId="2" ParentId="4036" CreationDate="2016-09-26T04:28:05.190" Score="6" Body="&lt;h2&gt;1&lt;/h2&gt;&#xA;&lt;p&gt;For each texel of the generated diffuse cube map (which has &lt;span class=&quot;math-container&quot;&gt;$6$&lt;/span&gt; faces times &lt;span class=&quot;math-container&quot;&gt;$32 \times 32$&lt;/span&gt; texels), the diffuse equation combines all texels of the environment map (which has &lt;span class=&quot;math-container&quot;&gt;$6$&lt;/span&gt; faces times &lt;span class=&quot;math-container&quot;&gt;$64 \times 64$&lt;/span&gt; texels). Thus &lt;span class=&quot;math-container&quot;&gt;$32 \times 32 \times 6 \times 64 \times 64 \times 6$&lt;/span&gt; as stated.&lt;/p&gt;&#xA;&lt;p&gt;Since the article considers SH with &lt;span class=&quot;math-container&quot;&gt;$9$&lt;/span&gt; coefficients, and each coefficient needs to combine all texels of the environment map, that's &lt;span class=&quot;math-container&quot;&gt;$9 \times 64 \times 64 \times 6$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;h2&gt;2&lt;/h2&gt;&#xA;&lt;p&gt;&lt;em&gt;&amp;quot;Bruteforce&amp;quot;&lt;/em&gt; doesn't necessarily refer to graph theory. In this article it refers to the naive approach of going through every single texel of the diffuse map and each time combine every single texel of the environment map.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h3&gt;Appendix&lt;/h3&gt;&#xA;&lt;p&gt;Let's describe the problem at hand.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;As an input&lt;/strong&gt;, we have an environment map: it's a set of six textures forming a cube, that represents the light coming from all directions. The light is assumed to be coming from sources far enough that, at our scale, it's as if they were infinitely far. An environment map typically looks like the left figure of this illustration from the GPU Gems article:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZFIHb.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZFIHb.jpg&quot; alt=&quot;Environment map and diffuse irradiance&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;As an output&lt;/strong&gt;, for a any point of a given object that we're rendering, we want to know the diffuse irradiance affecting it. &lt;em&gt;What does that mean?&lt;/em&gt;&lt;/p&gt;&#xA;&lt;h3&gt;A parenthesis&lt;/h3&gt;&#xA;&lt;p&gt;Models describing how the perceived color of a surface varies depending the light reaching it, typically consist in &lt;a href=&quot;https://en.wikipedia.org/wiki/Rendering_equation&quot; rel=&quot;nofollow noreferrer&quot;&gt;integrating all incoming light over an hemisphere&lt;/a&gt;, with a weight that depends both on the direction of the light and of the observer.&lt;/p&gt;&#xA;&lt;p&gt;For opaque materials, it is common to consider two components contributing to that color: the diffuse and the specular. The diffuse is due to light slightly penetrating the surface, getting partly absorbed, then getting out in random directions. The specular is due to light bouncing off the surface without entering it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/85Pmg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/85Pmg.png&quot; alt=&quot;Diffuse and specular reflections&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3&gt;Back to the problem&lt;/h3&gt;&#xA;&lt;p&gt;So we want to know the color of the points of an object, we know that to compute it we need to integrate light in all directions, and we have a cube map that represents light coming from all directions. So far so good.&lt;/p&gt;&#xA;&lt;p&gt;A problem though is &lt;em&gt;integrating&lt;/em&gt; basically means we need to go over every single texel of the hemisphere (so half the environment map: &lt;span class=&quot;math-container&quot;&gt;$(64 \times 64 \times 6) / 2$&lt;/span&gt; texels), do some math, and add that to the result. That's a lot of computation for each point, which we'd like to avoid if possible.&lt;/p&gt;&#xA;&lt;p&gt;We know that the contribution of one light depends on the light direction. If we consider the environment to be static (the lighting doesn't change), then we can isolate the part of the computation that only depends on the light and surface normal (and not on the material or the observer), pre-compute it and store it to use later. For the diffuse term, that's the &lt;em&gt;diffuse irradiance&lt;/em&gt; mentioned earlier, and it typically looks like the center figure of the illustration. Each pixel represents the irradiance term for a given surface normal. The right figure is the specular environment map, computed in a similar way but with a different integral.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZFIHb.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZFIHb.jpg&quot; alt=&quot;Environment map and diffuse irradiance&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;With that texture, instead of painfully integrating, we just fetch the precomputed result, combine it with the rest of the equation (the material diffuse color, etc.) and voilà.&lt;/p&gt;&#xA;&lt;h3&gt;Finding the 32x32x6x64x64x6&lt;/h3&gt;&#xA;&lt;p&gt;Since the result looks very blurry, it probably doesn't need to be &lt;span class=&quot;math-container&quot;&gt;$64 \times 64$&lt;/span&gt; for storing, and the article assumes &lt;span class=&quot;math-container&quot;&gt;$32 \times 32$&lt;/span&gt;. But still, each of those &lt;span class=&quot;math-container&quot;&gt;$32 \times 32 \times 6$&lt;/span&gt; texels' color is computed separately, by integrating over the entire corresponding hemisphere. That part never disappeared: we just moved it from the rendering stage to a pre-computation stage.&lt;/p&gt;&#xA;&lt;p&gt;So that's still &lt;span class=&quot;math-container&quot;&gt;$(32 \times 32 \times 6) \times (64 \times 64 \times 6) / 2$&lt;/span&gt;. That's half the figure stated in the article. I suppose the author was either assuming a model that integrates of the entire sphere, or just dropped the &lt;span class=&quot;math-container&quot;&gt;$0.5$&lt;/span&gt; factor for the sake of clarity.&lt;/p&gt;&#xA;&lt;h3&gt;Finding the 9x64x64x6&lt;/h3&gt;&#xA;&lt;p&gt;We can't help but notice this irradiance diffuse environment map is really blurry: surely there must be a way to store its information using a lot less than &lt;span class=&quot;math-container&quot;&gt;$32 \times 32 \times 6$&lt;/span&gt; terms, and hopefully reduce the amount of work as well. That's what &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_harmonics&quot; rel=&quot;nofollow noreferrer&quot;&gt;spherical harmonics&lt;/a&gt; do, by compressing the irradiance in just a few coefficients.&lt;/p&gt;&#xA;&lt;p&gt;I am not familiar enough with the math to engage in an explanation, but suffice to say it is generally considered that for diffuse, order three SH are sufficient. Order three SH involve nine coefficient, and again, for each of these we need to integrate over the entire hemisphere.&lt;/p&gt;&#xA;&lt;p&gt;So that's &lt;span class=&quot;math-container&quot;&gt;$(9 \times 64 \times 64 \times 6) / 2$&lt;/span&gt; texels to fetch and process. Here too a &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt; factor is missing from the article.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-09-26T12:58:48.857" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4038" PostTypeId="2" ParentId="4035" CreationDate="2016-09-26T13:53:08.227" Score="3" Body="&lt;p&gt;The surface reflectance of a BRDF function doesn't depend on orientation or position of the surface in the world space (except for the view vector) but is defined relatively to the surface normal (or tangent space in case of anisotropic BRDF) so it should be defined in local space. Think of it as a hemispherical 2D function fixed to a point on the surface of an object that moves and rotates with the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Environment map on the other hand defines luminance from given direction in the world space so it is defined in that space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To perform the convolution of these two functions you then have to either transform BRDF to world space or environment map to local space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's common to transform surface normal/tangent space to the world space and perform lighting calculations in that space. However, if you plan to do define BRDF with spherical harmonics, you might want to consider hemispherical harmonics for better frequency response and transform lighting from world space to the local space. Overall with SH/HSH you can only reproduce fairly low-frequency lighting (i.e. rough surfaces), so they may not be able to render as versatile surfaces as you wish.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-09-26T17:49:36.257" LastActivityDate="2016-09-26T17:49:36.257" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4040" PostTypeId="1" AcceptedAnswerId="4075" CreationDate="2016-09-27T01:28:53.190" Score="4" ViewCount="169" Body="&lt;h1&gt;Context&lt;/h1&gt;&#xA;&lt;p&gt;As I was trying to learn more about Vulkan, I learned that certain fixed-function steps could be implemented with shader code from this video (at around the spot where he talks about the following problem):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://youtu.be/X8Ob_b3ANzs?t=24m&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/X8Ob_b3ANzs?t=24m&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In this video, the presenter says &amp;quot;hitching&amp;quot; can occur in OpenGL because for some GPUs the colorblend stage apparently needs to be recompiled at certain times. He gives an example of when a player takes out a torch and causes hitching due to bloom.&lt;/p&gt;&#xA;&lt;h1&gt;Questions&lt;/h1&gt;&#xA;&lt;p&gt;Why would this shader need to be recompiled in this scenario? In what scenarios would this shader need to be recompiled? Is this common practice/an issue across vendors?&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-10-04T13:25:00.963" Title="Colorblending shader recompilation scenarios" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;vulkan&gt;&lt;driver&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4041" PostTypeId="2" ParentId="3995" CreationDate="2016-09-27T02:53:24.330" Score="3" Body="&lt;p&gt;You have a lot of questions so let me take a shortcut and just try to explain how this is properly done (:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you are interested in calculating is luminance (cd/m^2) for a pixel. A simple way you can do this is by using brute-force Monte Carlo integration over the hemisphere defined by the normal of a pixel, i.e. cast few thousand randomly distributed rays over the hemisphere. For each of those sample rays you evaluate the BRDF (1/sr) and multiply it with the luminance of the area light source the ray hits, or 0 if it doesn't hit anything. Sum up all these results and multiply by 2*pi/num_samples in the end, i.e. by the solid angle of each sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This operation gives you the the luminance for the pixel, which you then multiply by camera exposure factor to map to a proper range which you can tone map, i.e. calculate EV100 from camera aperture, shutter time and ISO-settings as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float ev100=log2((aperture*aperture/shutter_time)*100.0f/iso);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then calculate exposure factor:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float exposure_factor=1.2f*pow(2.0f, ev100);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For IES light profiles you can normalize the profile and modulate light luminance with the IES factor for the given direction the ray hits the light.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-09-27T02:53:24.330" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4042" PostTypeId="1" AcceptedAnswerId="4044" CreationDate="2016-09-27T19:46:26.580" Score="3" ViewCount="741" Body="&lt;p&gt;So I've been learning opengl for some weeks now and managed to understand all the viewing pipelines. As far my understanding goes we need to bring the object to world space and then the world space to view space. After that the clipping is done by any of the two projections as we want. The clipping volume is then sent to the viewport which is mapped to the screen coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now when I write this simple basic code below I don't use any of the matrixmode&#xA;(GL_MODElVIEW or  GL_PROJECTION) but still the primitive is displayed on the screen. So what am I missing here? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;and also an extension to this question I would also like to know what exactly means to bring the object to world coordinates in theory. Does it means overlapping the axes of the object coordinates with the world coordinates.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;With lot of opengl discussions out there I don't know where to look. Would be extra nice if someone refer me to some good articles. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Di()&#xA;{&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;    glBegin(GL_QUADS) ;           &#xA;       glColor3f ( 1.0, 0.3, 0.2);     &#xA;        glVertex2f( -0.1, -0.1 );       &#xA;        glVertex2f(  0.1, -0.1 );       &#xA;        glVertex2f(  0.1,  0.1 ); &#xA;        glVertex2f( -0.1,  0.1 ); &#xA;       glEnd();&#xA;    glFlush();&#xA;}&#xA;&#xA;int main( int argc, char** argv)&#xA;{&#xA;    glutInit( &amp;amp;argc, argv);&#xA;&#xA;    glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);&#xA;&#xA;    glutInitWindowSize(500,500);&#xA;&#xA;    glutInitWindowPosition(0,0);&#xA;&#xA;    glutCreateWindow(&quot;First Program&quot;);&#xA;&#xA;    glutDisplayFunc(Di);&#xA;    glutMainLoop();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5193" LastEditorUserId="38" LastEditDate="2016-09-29T08:28:31.303" LastActivityDate="2018-04-19T07:52:09.913" Title="What if we don't mention Modelview and projection matrix?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;2d-graphics&gt;&lt;legacy-opengl&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4043" PostTypeId="1" CreationDate="2016-09-27T20:11:13.680" Score="3" ViewCount="151" Body="&lt;p&gt;I am writing an application with multiple colored surfaces. I would like to preserve luminance, i.e. a blue surface would appear as bright as a green one, are there tools to help for this?&lt;/p&gt;&#xA;" OwnerUserId="5183" LastActivityDate="2016-09-28T02:49:00.587" Title="Preserving luminance" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4044" PostTypeId="2" ParentId="4042" CreationDate="2016-09-28T01:07:49.037" Score="5" Body="&lt;p&gt;Your screen isn't 3D, so how do you display 3D objects on it? You need to map 3D coordinates into 2D space. This also explains why your OpenGL code is not behaving how you're expecting it to. Sorry if parts of this answer are things you already know (just trying to be comprehensive).&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;What do the model view and projection matrices do?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;model view&lt;/strong&gt; matrix is actually two matrices (multiplied together): the model matrix and the view matrix. This is important to understanding because these are two transformations into different spaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;model&lt;/strong&gt; matrix transforms model space into world space. This means that say you have a vertex is at an offset from the center of a model. If you want that vertex to be in world space, it must use the scale, rotation, and position of the model to determine this. The model matrix accomplishes this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;view&lt;/strong&gt; matrix transforms the world space into the camera space. Does world move or does the camera move in a 3D application? Well, actually the world moves around the camera. The camera is always at the origin, so the view matrix moves the world to this point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;projection&lt;/strong&gt; matrix might be the trickiest to visualize. Screens are 2D (technicalities aside), so how do we show 3D objects here? A projection matrix converts 3D coordinates into 2D coordinates (with depth, so still technically 3D). You end up with Normalized Device Coordinates (NDCs). Each vertex on screen is represented by three values:&#xA;* x (horizontal) ranging from [-1, 1]&#xA;* y (vertical) ranging from [-1, 1]&#xA;* z (depth) ranging from [-1, 1]&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Why don't you need model-view and projection matrices?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;It's not that you don't need them, it's just that you are using as explained in the last step above. Otherwise, you are effectively just rendering 2D graphics. Right now you are drawing a quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Look at the coordinates that you are providing. You are basically treating the vertices as 2D vertices for 2D graphics since you are directly specifying their coordinates in NDC space. Remember, the coordinates you picked are between -1 and 1 for x and y, so you are effectively treating them as NDCs. You directly send them to the rasterizer in your example.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Further Reading&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Tutorial 3 : Matrices | opengl-tutorial.org&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://learnopengl.com/#!Getting-started/Coordinate-Systems&quot; rel=&quot;nofollow noreferrer&quot;&gt;Coordinate Systems | LearnOpenGL.com&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Projection Matrix | songho.ca&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2707" LastEditorDisplayName="user7220" LastEditDate="2018-04-19T07:52:09.913" LastActivityDate="2018-04-19T07:52:09.913" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4045" PostTypeId="2" ParentId="4043" CreationDate="2016-09-28T01:23:32.313" Score="2" Body="&lt;p&gt;The usual way of doing this is to work in a color space that has luminance as one of the color components. For example the &lt;a href=&quot;https://en.wikipedia.org/wiki/YCbCr&quot; rel=&quot;nofollow&quot;&gt;Y'CbCr color space&lt;/a&gt; has a luminance channel (you can think of this as similar to brightness which is a poorly defined term) and 2 chrominance or color channels. There are other color spaces that separate colors in this way, too, such as HSV, HLS, La&lt;em&gt;b&lt;/em&gt;, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are conversions to go between RGB and these various color spaces. The article linked above shows some of the conversions for going between Y'CbCr and sRGB, for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You don't say what type of graphics library you'll be using, so it's hard to give any more detail than what I've given you here. But I've done this in OpenGL, Core Graphics, and others. It shouldn't be too difficult.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edited to add: I should point out that HSV defines value or &quot;brightness&quot; not as luminance but as the average of red, green, and blue, and as such does not track very will with our intuitive sense of brightness. HLS also suffers from some issues (discontinuities, bad but popular reference implementations) and is generally not recommended by the color scientists that I know.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2016-09-28T02:49:00.587" LastActivityDate="2016-09-28T02:49:00.587" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4047" PostTypeId="2" ParentId="1641" CreationDate="2016-09-28T22:25:13.647" Score="1" Body="&lt;p&gt;&lt;a href=&quot;http://www.cs.sandia.gov/~samitch/papers/vor_final.pdf&quot; rel=&quot;nofollow&quot;&gt;http://www.cs.sandia.gov/~samitch/papers/vor_final.pdf&lt;/a&gt; There isn't the computer algorithm in any programming languague, but u should be able to replicate it easily with some Plane Reflections and the algorithms from the above link.&lt;/p&gt;&#xA;" OwnerUserId="5096" LastActivityDate="2016-09-28T22:25:13.647" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4048" PostTypeId="1" AcceptedAnswerId="4051" CreationDate="2016-09-28T22:28:46.937" Score="3" ViewCount="415" Body="&lt;p&gt;I am trying to create a fog-like effect, similar to that found using perlin noise. I know where I can find information about that effect, but it's harder for me to tell if it's an efficient route for what I want to achieve. A similar effect can be seen here, although I'd imagine what I want is much lower in detail: &lt;a href=&quot;https://www.youtube.com/watch?v=csYzDia5Ckw&quot; rel=&quot;nofollow noreferrer&quot;&gt;Animated perlin noise | youtube.com&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am currently working in openframeworks. What I have done so far is build a grid of noise values, and have worked towards linearly interpolating in-between those. I feel like I am on the right track, but it very blocky, which makes me wonder if my approach is totally off-mark. This page on Perlin noise has been helpful: &lt;a href=&quot;http://flafla2.github.io/2014/08/09/perlinnoise.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Understanding Perlin Noise | flafla2.github.io&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for(int x = 0; x &amp;lt; grid.getWidth(); x++){&#xA;    if(x % g_size == 0){&#xA;        for(int y = 0; y &amp;lt; grid.getHeight(); y++){&#xA;            if(y % g_size == 0){&#xA;                noise = ofNoise(x,y,ofGetElapsedTimef());&#xA;                grid.setColor(x,y,ofFloatColor(noise));&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;ofVec2f g1, g2, g3, g4;&#xA;float f1, f2, f3, f4, u, v, t_1, t_2;&#xA;&#xA;for(int x = 0; x &amp;lt; grid.getWidth(); x++){&#xA;    for(int y = 0; y &amp;lt; grid.getHeight(); y++){&#xA;        //find neigboring grid points&#xA;        g1 = ofVec2f(x-(x % g_size),y-(y % g_size));&#xA;        g2 = ofVec2f(g1.x + g_size,g1.y);&#xA;        g3 = ofVec2f(g1.x,g1.y + g_size);&#xA;        g4 = g1 + g_size;&#xA;&#xA;        //get noise values from the grid neighbors&#xA;        f1 = grid.getColor(g1.x,g1.y).r;&#xA;        f2 = grid.getColor(g2.x,g2.y).r;&#xA;        f3 = grid.getColor(g3.x,g3.y).r;&#xA;        f4 = grid.getColor(g4.x,g4.y).r;&#xA;&#xA;        u = (float)(x % g_size)/g_size;&#xA;        v = (float)(y % g_size)/g_size;&#xA;&#xA;        t_1 = ofLerp(f1,f2,u);&#xA;        t_2 = ofLerp(f3,f4,u);&#xA;&#xA;        ofColor average = ofLerp(t_1,t_2,v);&#xA;&#xA;        fog.setColor(x,y,average);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4708" LastEditorDisplayName="user7220" LastEditDate="2018-04-19T07:52:21.520" LastActivityDate="2018-04-19T07:52:21.520" Title="Creating a gently moving 2D fog effect" Tags="&lt;c++&gt;&lt;interpolation&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4049" PostTypeId="1" CreationDate="2016-09-28T22:47:17.170" Score="1" ViewCount="180" Body="&lt;p&gt;I have the following object in the game&#xA;&lt;a href=&quot;https://i.stack.imgur.com/FozUp.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FozUp.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;It is a dial with the little triangle showing what part of the disk is being valued.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The dial serves as a controller that sets a variable from 0-1. If the disk has 0 degrees facing left then it is 0, if the disk has 180 degrees facing left then it is 0.5. Somehow I will eventually find a way to express that so the disk will not be uniform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway so the inner disk you see will spin meanwhile the outer disk with the triangle thing will stay in place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something that would be nice is if the area of the spinning disk that is inside of the triangle would disappear.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Nhq1p.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Nhq1p.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is I have no clue how to do this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently the rotation of the disk is done by a matrix that rotates the quad that is rendering this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have two ideas&#xA;1. Edit the quad into a mesh cutting out the triangle, however this would not work as the mesh is translated in my current model.&#xA;2. Run costly trigonometric calculations to figure out where each fragment is in real space then figure out its angle and distance from the center of the circle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know doing a little trig on each fragment might not sound like much, however just rendering the disk adds 1ms of rendering time when rendering on the lowest possible hardware this could run on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do people achieve real-time masking in opengl?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2016-09-28T22:47:17.170" Title="Mask out parts of an image in OpenGL ES" Tags="&lt;masking&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4050" PostTypeId="1" CreationDate="2016-09-29T04:29:48.253" Score="1" ViewCount="66" Body="&lt;p&gt;Look at the photo, modelling for new products. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regards&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VSL2w.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VSL2w.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5205" LastActivityDate="2016-09-29T07:05:13.690" Title="What is the name of these software on 2 screen?" Tags="&lt;3d&gt;&lt;render&gt;" AnswerCount="1" CommentCount="0" ClosedDate="2016-09-29T15:27:43.050" ContentLicense="CC BY-SA 3.0" />
  <row Id="4051" PostTypeId="2" ParentId="4048" CreationDate="2016-09-29T05:20:27.477" Score="3" Body="&lt;p&gt;Animated noise can be created by using time as an extra dimension. So instead of 2D noise, you'd use 3D noise with time as the z-axis position, like &lt;code&gt;ofNoise(x, y, time)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To control the level of detail, you'd use octaves of noise: multiple noise layers with different scales and amplitudes, mixed together. The basic Perlin routines just generate a single octave, so you can re-invoke it with scaled coordinates to add more detail, something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float noise = ofNoise(x, y, time);          // first octave&#xA;noise += 0.5 * ofNoise(2*x, 2*y, 2*time);   // second octave&#xA;noise += 0.25 * ofNoise(4*x, 4*y, 4*time);  // third octave&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and so on. The more octaves you put in, the more detailed the noise will be. The article you linked describes this in more detail if you scroll down to &lt;a href=&quot;http://flafla2.github.io/2014/08/09/perlinnoise.html#working-with-octaves&quot; rel=&quot;nofollow&quot;&gt;Working with Octaves&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-09-30T01:42:46.207" LastActivityDate="2016-09-30T01:42:46.207" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4052" PostTypeId="2" ParentId="4050" CreationDate="2016-09-29T07:05:13.690" Score="1" Body="&lt;p&gt;Judging by the interface that would be blender:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.blender.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.blender.org/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please note that here is a bender-specific stackexchange site as well:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://blender.stackexchange.com/&quot;&gt;https://blender.stackexchange.com/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3128" LastEditorUserId="-1" LastEditDate="2017-04-13T12:57:46.990" LastActivityDate="2016-09-29T07:05:13.690" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4053" PostTypeId="2" ParentId="4026" CreationDate="2016-09-29T14:21:12.513" Score="2" Body="&lt;p&gt;Without looking at the code, from the look of the pictures, my intuition would be that somewhere the code is using the inverse of the matrix it should.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at the code seems to confirm so, but there are some other problems too.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;mTBN = transpose(mat3(t,b,n)); //transpose makes it from model to to tangent space?&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;mat3(t,b,n)&lt;/code&gt; is a transform from world space to tangent space. The inverse of such a matrix is indeed its transpose, so &lt;code&gt;mTBN&lt;/code&gt; transforms from tangent space to world space, which is not what you want.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;tanViewPos = mTBN * cameraPos;&#xA;tanFragPos = mTBN * worldPos.xyz;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You cannot do something like that. &lt;code&gt;mTBN&lt;/code&gt; is a 3x3 matrix: without a 4th column and a non-zero homogeneous coordinate, you can only transform directions, not positions. You need to first get the camera direction relative to the vertex, then transform that direction.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Beware of the vector direction.&#xA;// Here viewDir points from the object toward the viewer.&#xA;vec3 worldViewDir = normalize(cameraPos - worldPos.xyz);&#xA;tanViewDir = mTBN * worldViewDir;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Let us know in comments if that helps solving your issue.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2016-09-29T14:27:04.720" LastActivityDate="2016-09-29T14:27:04.720" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4054" PostTypeId="1" CreationDate="2016-09-30T10:53:22.343" Score="2" ViewCount="176" Body="&lt;p&gt;I must convert a isosceles trapezoid to a rectangle in 2-D with a shearing transformation (or with 2 shearing transformations).  The isosceles trapezoid is centered in the origin of axes.&#xA;It is right write:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; x' = x + αy&#xA; y'=y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with α&gt;0  per y&gt;0 ,  and α&amp;lt;0  per y&amp;lt;0 (then 2 transformations)?&#xA;And if it's right how can I calculate the parameter α?&#xA;Otherwise if it is all wrong as I do?     &lt;/p&gt;&#xA;" OwnerUserId="4981" LastActivityDate="2016-09-30T10:53:22.343" Title="Transform a centered isosceles trapezoid in a rectangle in 2-D" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mathematics&gt;&lt;affine-transformations&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4055" PostTypeId="1" CreationDate="2016-09-30T20:18:21.453" Score="1" ViewCount="83" Body="&lt;p&gt;I have a skeleton (in &lt;a href=&quot;http://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/ASF-AMC.html&quot; rel=&quot;nofollow&quot;&gt;asf/amc format&lt;/a&gt;), from &lt;a href=&quot;http://mocap.cs.cmu.edu/&quot; rel=&quot;nofollow&quot;&gt;CMU's mocap database&lt;/a&gt;. &#xA;I'm using python, no libraries yet. (Blender in python mode doesn't work properly for this, as far as I know.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to mirror the movement, swapping sides, assigning the right arm movement to the left arm and so on. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The number of degrees of freedom for each joint is between 1 and 3. Angles are stored in euler format, XYZ. All angles are local, relative to the parent bone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quite obviously, just renaming the objects (rhand&amp;lt;-&gt;lhand) doesn't work. Where do I start?&lt;/p&gt;&#xA;" OwnerUserId="5211" LastEditorUserId="231" LastEditDate="2016-09-30T22:59:16.027" LastActivityDate="2016-10-03T03:16:27.113" Title="Mirroring avatar" Tags="&lt;geometry&gt;&lt;motion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4056" PostTypeId="5" CreationDate="2016-09-30T21:04:24.477" Score="0" Body="&lt;p&gt;The GL Transmission Format (&lt;a href=&quot;https://github.com/KhronosGroup/glTF&quot; rel=&quot;nofollow&quot;&gt;glTF&lt;/a&gt;) is a runtime asset delivery format for GL APIs: &lt;a href=&quot;/questions/tagged/webgl&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;webgl&amp;#39;&quot; rel=&quot;tag&quot;&gt;webgl&lt;/a&gt;, &lt;a href=&quot;/questions/tagged/opengl-es&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;opengl-es&amp;#39;&quot; rel=&quot;tag&quot;&gt;opengl-es&lt;/a&gt;, and &lt;a href=&quot;/questions/tagged/opengl&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;opengl&amp;#39;&quot; rel=&quot;tag&quot;&gt;opengl&lt;/a&gt;.  glTF bridges the gap between 3D content creation tools and modern GL applications by providing an efficient, extensible, interoperable format for the transmission and loading of 3D content.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The need for a network-enabled 3D content delivery format such as glTF has been &lt;a href=&quot;https://www.khronos.org/gltf/&quot; rel=&quot;nofollow&quot;&gt;compared to the need for JPEG for images, and MP3 for audio&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Specification&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The glTF specification is maintained by &lt;a href=&quot;https://www.khronos.org/&quot; rel=&quot;nofollow&quot;&gt;the Khronos Group&lt;/a&gt;.  This standards organization is also responsible for OpenGL, WebGL, COLLADA, and others.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF/specification/README.md&quot; rel=&quot;nofollow&quot;&gt;glTF Specification&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF/extensions/README.md&quot; rel=&quot;nofollow&quot;&gt;glTF Extension Registry&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2&gt;Sample Models&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;A collection of &lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/master/sampleModels/README.md&quot; rel=&quot;nofollow&quot;&gt;Sample models&lt;/a&gt; are available for learning glTF, and testing runtime engines and content pipeline tools.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Converters and Exporters&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;glTF files can be created by converting from other popular formats such as &lt;a href=&quot;/questions/tagged/collada&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;collada&amp;#39;&quot; rel=&quot;tag&quot;&gt;collada&lt;/a&gt;, &lt;a href=&quot;/questions/tagged/wavefront&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;wavefront&amp;#39;&quot; rel=&quot;tag&quot;&gt;wavefront&lt;/a&gt; OBJ, &lt;a href=&quot;/questions/tagged/fbx&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;fbx&amp;#39;&quot; rel=&quot;tag&quot;&gt;fbx&lt;/a&gt;, and others.  View the &lt;a href=&quot;https://github.com/KhronosGroup/glTF#converters&quot; rel=&quot;nofollow&quot;&gt;list of converters&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As support for glTF grows, 3D authoring packages may gain the ability to export to glTF directly.  For example, a &lt;a href=&quot;/questions/tagged/blender&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;blender&amp;#39;&quot; rel=&quot;tag&quot;&gt;blender&lt;/a&gt; &lt;a href=&quot;https://github.com/Kupoman/blendergltf&quot; rel=&quot;nofollow&quot;&gt;exporter&lt;/a&gt; is in early stages of development.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Loaders and Viewers&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Support for glTF is available for &lt;a href=&quot;/questions/tagged/three.js&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;three.js&amp;#39;&quot; rel=&quot;tag&quot;&gt;three.js&lt;/a&gt;, &lt;a href=&quot;/questions/tagged/babylonjs&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;babylonjs&amp;#39;&quot; rel=&quot;tag&quot;&gt;babylonjs&lt;/a&gt;, &lt;a href=&quot;/questions/tagged/cesium&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;cesium&amp;#39;&quot; rel=&quot;tag&quot;&gt;cesium&lt;/a&gt;, &lt;a href=&quot;/questions/tagged/xml3d&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;xml3d&amp;#39;&quot; rel=&quot;tag&quot;&gt;xml3d&lt;/a&gt;, and others.  Khronos maintains a &lt;a href=&quot;https://github.com/KhronosGroup/glTF#loaders-and-viewers&quot; rel=&quot;nofollow&quot;&gt;list of glTF loaders and viewers&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;File Structure&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;A &lt;a href=&quot;https://raw.githubusercontent.com/KhronosGroup/glTF/master/specification/figures/gltfOverview-0.2.0.png&quot; rel=&quot;nofollow&quot;&gt;structural overview diagram&lt;/a&gt; (by &lt;a href=&quot;https://github.com/javagl/gltfOverview&quot; rel=&quot;nofollow&quot;&gt;Marco Hutter&lt;/a&gt;) shows an at-a-glance view of the structure of a glTF file and its contents.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastEditorUserId="1908" LastEditDate="2016-10-01T00:04:17.403" LastActivityDate="2016-10-01T00:04:17.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4057" PostTypeId="4" CreationDate="2016-09-30T21:04:24.477" Score="0" Body="The GL Transmission Format (glTF) is a runtime asset delivery format for GL APIs: WebGL, OpenGL ES, and OpenGL. glTF bridges the gap between 3D content creation tools and modern GL applications by providing an efficient, extensible, interoperable format for the transmission and loading of 3D content." OwnerUserId="1908" LastEditorUserId="1908" LastEditDate="2016-10-01T00:04:27.633" LastActivityDate="2016-10-01T00:04:27.633" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4058" PostTypeId="1" AcceptedAnswerId="4077" CreationDate="2016-10-02T00:31:37.540" Score="2" ViewCount="2096" Body="&lt;p&gt;I have very recently started looking into real-time fluid simulation. Idea is to make a game that would use 3D fluid simulation as a core gameplay mechanic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking around the web, I found &lt;strong&gt;&lt;a href=&quot;http://www.it.ubi.pt/17epcg/Actas/artigos/17epcg_submission_39.pdf&quot; rel=&quot;nofollow&quot;&gt;this&lt;/a&gt;&lt;/strong&gt; article that compares the performance of fluid simulations on CPU and GPU. While the article itself is a bit dated, I assume that while CPUs and GPUs today are faster, the performance ration between the two has stayed similar enough to keep the article relevant. Actually, comparing their hardware (Core 2 Quad Q6600 and GeForce 8800 GT) to today's hardware (eg. i5 6600K and GTX 1070), CPU has &lt;a href=&quot;http://cpu.userbenchmark.com/Compare/Intel-Core2-Quad-Q6600-vs-Intel-Core-i5-6600K/1980vs3503&quot; rel=&quot;nofollow&quot;&gt;230% performance gain&lt;/a&gt;, while GPU has staggering &lt;a href=&quot;http://gpu.userbenchmark.com/Compare/Nvidia-GeForce-8800-GT-vs-Nvidia-GTX-1070/m7722vs3609&quot; rel=&quot;nofollow&quot;&gt;1670% performance gain&lt;/a&gt;. This would make the article more relevant today than it was before (more than six times).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, using the biggest grid they tested with (GS, 128^3, page 7, table 2), GPU simulation was over 3000 times faster than the CPU simulation. Even if utilizing 4 cores (they were using only a single thread), it's still over 700-fold performance gain (back in the day, today that would go up to 5000-fold). Given the results for smaller grids, that difference would only increase with bigger grids than 128^3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is, along with all the normal rendering the GPU is tasked with doing, is it viable to burden it with the task of computing the simulation too, &lt;strong&gt;in any case at all&lt;/strong&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the use of rendering the graphics at 60FPS if fluid simulation runs at 10 steps per second, effectively making the game look like it's running at 10FPS? Wouldn't it be better if I rendered graphics at 30FPS, but could do the simulation at 30 steps per second as well?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, the question is, what would take longer:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For the GPU to render a frame AND compute the simulation step&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;OR&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For the CPU to compute rest of the game logic AND compute the simulation step.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I know that this heavily depends on the GPU involved and the remainder of the GPU and CPU load, but look at the whole thing this way:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if I used just 1% of the power of GPU, the speed would still be 7(50!) times greater than using the CPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm a big novice in when it comes to computer graphics, so I may have gotten it all wrong. Does anything I wrote make any sense, or is it just gibberish?&lt;/p&gt;&#xA;" OwnerUserId="5215" LastEditorUserId="5215" LastEditDate="2016-10-02T00:54:43.130" LastActivityDate="2016-10-05T23:50:44.620" Title="Fluid sim: CPU vs. GPU" Tags="&lt;fluid-sim&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4059" PostTypeId="1" CreationDate="2016-10-02T08:41:23.423" Score="2" ViewCount="401" Body="&lt;p&gt;I have a circular shape object, which I want to rotate like a fan along it's own axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can change the rotation in any direction i.e. dx, dy, dz using my transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following it's the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; Matrix4f matrix = new Matrix4f();&#xA; matrix.setIdentity();&#xA; Matrix4f.translate(translation, matrix, matrix);&#xA; Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix);&#xA; Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix);&#xA; Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0,0,1), matrix, matrix);&#xA; Matrix4f.scale(new Vector3f(scale,scale,scale), matrix, matrix);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My vertex code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; vec4 worldPosition = transformationMatrix * vec4(position,1.0);&#xA; vec4 positionRelativeToCam = viewMatrix*worldPosition;&#xA; gl_Position = projectionMatrix *positionRelativeToCam;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Main Game Loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; Object.increaseRotation(dxf,dyf,dzf);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But, it's not rotating along it's own axis. What am I missing here? I want something like this. Please Help&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/knBlT.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/knBlT.gif&quot; alt=&quot;Like This&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5219" LastActivityDate="2016-10-02T13:29:50.337" Title="Rotating an Object Around an Axis" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4060" PostTypeId="1" CreationDate="2016-10-02T11:27:23.680" Score="4" ViewCount="193" Body="&lt;p&gt;Dithering increases percieved color depth by adding a &quot;noise&quot; to an image on transform from high color depth (e.g. 32-bit floating point) to lower color depth (e.g. 8-bit integer). A prerequisite is pixel density being high enough for the brain to &quot;blend&quot; multiple pixels together. It is also dependent on viewing distance. I´m most interested in phone or desktop workstation distance. Dithering algorithm also matters but for the sake of the question lets assume it is &quot;perfect&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;RGB8 (TrueColor, 16 million colors) requires dithering for nice smooth gradients and tend to get really nice for your average monitor. RGB5 (HighColor, ~32k colors) requires dithering for gradients to look nearly smooth, but I think pixel density start to really matter at this point. I´m not sure if RGB4 (~4k colors) or R3G3B2 (256 colors) can ever have smooth gradients but given high enough pixel density it should be possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any rule of thumb when it comes to pixel density / color channel depth ratio for a dithered image to appear having smooth gradients as percieved by the brain?&lt;/p&gt;&#xA;" OwnerUserId="3041" LastEditorUserId="3041" LastEditDate="2016-10-03T16:27:42.773" LastActivityDate="2017-02-25T17:12:01.713" Title="Pixel density / color channel depth ratio for dithered gradients" Tags="&lt;opengl-es&gt;&lt;color-science&gt;&lt;color-management&gt;&lt;human-vision&gt;&lt;theory&gt;" AnswerCount="1" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="4061" PostTypeId="2" ParentId="4059" CreationDate="2016-10-02T13:18:46.230" Score="1" Body="&lt;p&gt;Instead of &quot;stacking&quot; or overwriting these transformations on one matrix You may try doing that using matrix multiplication:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix4f translate = translate(translation,  new Matrix4F() /*identity*/);&#xA;Matrix4f rotateX = rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), new Matrix4F());&#xA;Matrix4f scale = scale(new Vector3f(scale,scale,scale), new Matrix4F());&#xA;&#xA;Matrix4f transformation = translate*rotateX*scale;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-10-02T13:29:50.337" LastActivityDate="2016-10-02T13:29:50.337" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4062" PostTypeId="1" AcceptedAnswerId="4063" CreationDate="2016-10-02T13:40:34.237" Score="14" ViewCount="2409" Body="&lt;p&gt;Despite advancements modern GPUs still have fixed rasterizers. Highly customizable, with programmable shaders but nevertheless not fully programmable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why can't GPUs be simply massively parallel devices with universal computing units where rasterizer is just a software for that device provided by the user?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is having fixed function hardware so beneficial performance-wise that such approach is unfeasible?&lt;/p&gt;&#xA;" OwnerUserId="1764" LastActivityDate="2016-10-04T12:55:04.813" Title="Why do GPUs still have rasterizers?" Tags="&lt;gpu&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4063" PostTypeId="2" ParentId="4062" CreationDate="2016-10-02T17:46:42.837" Score="15" Body="&lt;p&gt;In short, performance reasons are why they aren't programmable.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;History and Market&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;In the past, there used to be separate cores for vertex and fragment processors to avoid bloated FPU designs. There were some mathematical operations you could only do in fragment shader code for instance (because they were mostly only relevant for fragment shaders). This would produce severe hardware bottlenecks for applications that didn't max out the potential of each type of core.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As programmable shaders became more popular, universal units were introduced. More and more stages of the graphics pipeline were implemented in hardware to help with scaling. During this time, GPGPU also became more popular, so vendors had to incorporate some of this functionality. It's still important to note though that the majority of the income from GPUs were still video games, so this couldn't interfere with performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Eventually a big player, Intel, decided to invest in programmable rasterizers with their &lt;a href=&quot;https://en.wikipedia.org/wiki/Larrabee_(microarchitecture)&quot;&gt;Larrabee architecture&lt;/a&gt;. This project was supposed to be groundbreaking, but the &lt;a href=&quot;https://www.cnet.com/news/intel-initial-larrabee-graphics-chip-canceled/&quot;&gt;performance was apparently less than desired&lt;/a&gt;. It was shut down, and parts of it were salvaged for Xeon Phi processors. It's worth noting though that the other vendors haven't implemented this.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Attempts at Software Rasterizers&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;There have been some attempts at rasterization through software, but they all seem to have issues with performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One notable effort was an &lt;a href=&quot;http://highperformancegraphics.net/previous/www_2011/media/Papers/HPG2011_Papers_Laine.pdf&quot;&gt;attempt by Nvidia&lt;/a&gt; in 2011 in this &lt;a href=&quot;http://dl.acm.org/citation.cfm?id=2018337&quot;&gt;paper&lt;/a&gt;. This was released close to when Larrabee was terminated, so it's very possible that this was a response to that. Regardless, there are some performance figures in this, and most of them show performance multiple times slower than hardware rasterizers.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Technical Issues with Software Rasterization&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;There are many issues that were faced in the Nvidia paper. Here are some of the most important issues with software rasterizers though:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Major Issues&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interpolation:&lt;/strong&gt;&#xA;The hardware implementation generates interpolation equations in specialized hardware. This is slow for the software renderer since it had to be done in the fragment shader.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Anti-aliasing:&lt;/strong&gt;&#xA;There were also performance issues with anti-aliasing (specifically with memory). Information regarding the sub-pixel samples must be stored on-chip memory, which isn't enough to hold this. Julien Guertault pointed out that the texture cache/cache may be slower with software. MSAA certainly has issues here because it overflows the cache (the non-texture caches) and goes into memory off of the chip. Rasterizers compress data that is stored in that memory, which also helps with performance here.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Power Consumption:&lt;/strong&gt;&#xA;Simon F pointed out that power consumption would be lower. The paper did mention that custom ALUs are in rasterizers (which would reduce power consumption), and this would make sense since fragment and vertex processing units in the past used to have custom instruction sets (so likely custom ALUs as well). It certainly would be a bottleneck in many systems (e.g., mobile), although this has implications beyond performance.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;Summary&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;TL;DR: there are too many inefficiencies that software rendering can't past, and these things add up. There are also many larger limitations, especially when you are dealing with VRAM bandwidth, synchronization problems, and extra computations.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-10-04T12:55:04.813" LastActivityDate="2016-10-04T12:55:04.813" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4064" PostTypeId="2" ParentId="4055" CreationDate="2016-10-02T18:04:59.303" Score="3" Body="&lt;h1&gt;Mapping the Left and Right Sides&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;This step should be trivial. If I remember correctly, the CMU database animation skeletons have easily identifiable bone names. If not, then it's slightly less trivial. What you would have to do then would be to start at the root and go down each side. The bone structure should be the same for each animation though.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Create the Rotation Matrix&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;You should have three Euler angles: $X$, $Y$, and $Z$. You first need to create a &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Euler_angles_.28_z-y.E2.80.99-x.E2.80.B3_intrinsic.29_.E2.86.92_Rotation_matrix&quot; rel=&quot;nofollow&quot;&gt;rotation matrix&lt;/a&gt; for each bone. I use $\phi$ for $X$, $\theta$ for $Y$, and $\psi$ for $Z$ since this is a more common notation for matrix $R$. This is a right-handed matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;\cos(\theta)\cos(\psi) &amp;amp;&#xA;\cos(\phi)\sin(\psi) + \sin(\phi)\sin(\theta)\cos(\psi) &amp;amp;&#xA;\sin(\phi)\sin(\psi) - \cos(\phi)\sin(\theta)\cos(\psi) \\&#xA;- \cos(\theta)\sin(\psi) &amp;amp;&#xA;\cos(\phi)\cos(\psi) - \sin(\phi)\sin(\theta)\sin(\psi) &amp;amp;&#xA;\sin(\phi)\cos(\psi) + \cos(\phi)\sin(\theta)\sin(\psi) \\&#xA;\sin(\theta) &amp;amp;&#xA;- \sin(\phi)\cos(\theta) &amp;amp;&#xA;\cos(\phi)\cos(\theta)&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Flip the Sides&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To flip the rotation matrix, you will need to multiply the axis you want to flip by $-1$. This is equivalent to &lt;a href=&quot;https://en.wikipedia.org/wiki/Scaling_(geometry)#Matrix_representation&quot; rel=&quot;nofollow&quot;&gt;scaling in across that axis&lt;/a&gt;. I will assume you want to scale across the x-axis for matrix $S$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;-1 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Combine the Two Transforms&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Now just multiply these two matrices, and you get the opposite rotation:&#xA;$$T = R \times S$$&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Chain Together the Local Transforms&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Now you just need to apply forward kinematics, so you need to multiply each parent matrix by the local matrix to get an absolute transformation matrix.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-10-03T03:16:27.113" LastActivityDate="2016-10-03T03:16:27.113" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4065" PostTypeId="1" AcceptedAnswerId="4071" CreationDate="2016-10-03T00:10:43.707" Score="5" ViewCount="371" Body="&lt;p&gt;I'm working on a webgl &lt;a href=&quot;https://nickstanish.com/visual-audio-js/&quot; rel=&quot;noreferrer&quot;&gt;audio visualizer&lt;/a&gt; that uses particles, and I want to optimize rendering based on the user's hardware. I'd like to offer a &quot;low quality&quot; and &quot;high quality&quot; setting so that it works well on a wide-range of devices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to automatically detect in the browser if the user has hardware acceleration available and generically whether their graphics card is good or not?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What techniques are there for rendering low vs high quality? &#xA;My initial ideas for low quality were:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;render less geometry (less particles, and nearer &quot;far&quot; clipping distance)&lt;/li&gt;&#xA;&lt;li&gt;use a smaller framebuffer and scale it up to the size of the canvas&lt;/li&gt;&#xA;&lt;li&gt;smaller texture sizes&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;:&#xA;Additionally, any resources on performance optimization would be appreciated. It seems that searches mostly result in helping users configure their graphic card settings&lt;/p&gt;&#xA;" OwnerUserId="5220" LastActivityDate="2016-10-03T23:50:00.410" Title="Optimizing performance on hardware" Tags="&lt;performance&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4066" PostTypeId="1" CreationDate="2016-10-03T09:03:18.540" Score="8" ViewCount="2595" Body="&lt;p&gt;DX12 introduces a new feature of pipeline named 'Bundle'. It seems that can optimize the command list, and send it to final pipeline. Vulkan invent some different pipeline: The graphic pipeline and the compute pipeline. The graphic pipeline seems just the same with the original, the compute pipeline is used as an accessor of image memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My CG knowledge is pretty basic, and can not confirm that cognition is correct. Would someone kindly provide some explanations for it - The main difference of pipelines between them ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;References:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://msdn.microsoft.com/zh-cn/library/mt617309&quot;&gt;https://msdn.microsoft.com/zh-cn/library/mt617309&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#pipelines&quot;&gt;https://www.khronos.org/registry/vulkan/specs/1.0/xhtml/vkspec.html#pipelines&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5222" LastEditorUserId="16" LastEditDate="2016-10-03T13:08:03.037" LastActivityDate="2017-02-03T04:49:49.170" Title="What's the main difference of pipeline process between Vulkan and DX12?" Tags="&lt;directx12&gt;&lt;vulkan&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4067" PostTypeId="1" AcceptedAnswerId="4080" CreationDate="2016-10-03T12:31:13.210" Score="5" ViewCount="262" Body="&lt;p&gt;I am currently trying to implement a specific directional light type.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This light type has been used in the game INSIDE and is called orthogonal spotlight (aka local directional light). I assume that this is a directional light which behaves like a spot light and have a squared or rectangular attenuation but I have some difficulties to integrate it in my deferred pipeline and get the general concept of this light type.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Classical directional light : &lt;code&gt;dot(worldNormal, lightDir)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Vbbur.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Vbbur.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that you'll be able to give me some clues.&#xA;Thanks a lot !&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-10-03T14:26:30.907" LastActivityDate="2016-10-05T15:12:35.930" Title="Special directional light type" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;lighting&gt;&lt;hlsl&gt;&lt;deferred-rendering&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4068" PostTypeId="1" CreationDate="2016-10-03T14:54:41.397" Score="5" ViewCount="219" Body="&lt;p&gt;From Gortler's &lt;em&gt;Foundations of Computer Graphics&lt;/em&gt; (i.e., self-study):&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Let $\mathbf{\vec{e}}^t = \mathbf{\vec{w}}^t E$ and let $P$ be a camera matrix that is just some arbitrary $4$ by $4$ matrix with &quot;dashes&quot; in its 3rd row. Given the world coordinates of 6 points in space as well as their normalized device coordinates, how would one compute the 12 unknown entries in the matrix $PE^{-1}$? (Note: this can only be solved up to an unknown scale factor) (Hint: set up an appropriate homogeneous linear system with a right hand side of zero).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Here the &quot;dashes&quot; matrix the author refers to takes form&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;n_1 &amp;amp; 0 &amp;amp; a &amp;amp; 0 \\&#xA;0 &amp;amp; n_2 &amp;amp; b &amp;amp; 0 \\&#xA;- &amp;amp; - &amp;amp; - &amp;amp; - \\&#xA;0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where we do not care what the values with dashes are. How does one use the hint to solve this problem? I think we can infer that $a$ and $b$ (the scale factors) are undetermined, but that we can infer what the $n_1$ and $n_2$ are.&lt;/p&gt;&#xA;" OwnerUserId="5225" LastActivityDate="2018-04-15T10:08:39.497" Title="Solving a problem from *Foundations of Computer Graphics*:" Tags="&lt;projections&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4069" PostTypeId="1" AcceptedAnswerId="4074" CreationDate="2016-10-03T22:06:50.603" Score="2" ViewCount="278" Body="&lt;p&gt;I was reading &lt;a href=&quot;http://www.3dgep.com/understanding-the-view-matrix/&quot; rel=&quot;nofollow&quot;&gt;this article&lt;/a&gt; and found something that caught my attention.&#xA;They say they are using column-major for their matrices so, in the code they have under the section &lt;strong&gt;Look At Camera&lt;/strong&gt; they construct the orientation and translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;R=\begin{bmatrix}r_x &amp;amp; u_x &amp;amp; f_x &amp;amp; 0 \\&#xA;r_y &amp;amp; u_y &amp;amp; f_y &amp;amp; 0 \\&#xA;r_z &amp;amp; u_z &amp;amp; f_z &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;T=\begin{bmatrix}0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;0&amp;amp; 0&amp;amp; 0&amp;amp; 0 \\&#xA;0&amp;amp; 0&amp;amp; 0&amp;amp; 0 \\&#xA;-e_x&amp;amp; -e_y &amp;amp; -e_z &amp;amp; 1\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;RT_1 = \begin{bmatrix}r_x &amp;amp; u_x &amp;amp; f_x &amp;amp; 0 \\&#xA;r_y &amp;amp; u_y &amp;amp; f_y &amp;amp; 0 \\&#xA;r_z &amp;amp; u_z &amp;amp; f_z &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix}\begin{bmatrix}0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;0&amp;amp; 0&amp;amp; 0&amp;amp; 0 \\&#xA;0&amp;amp; 0&amp;amp; 0&amp;amp; 0 \\&#xA;-e_x&amp;amp; -e_y &amp;amp; -e_z &amp;amp; 1\end{bmatrix}=\begin{bmatrix}r_x &amp;amp; u_x &amp;amp; f_x &amp;amp; 0 \\&#xA;r_y &amp;amp; u_y &amp;amp; f_y &amp;amp; 0 \\&#xA;r_z &amp;amp; u_z &amp;amp; f_z &amp;amp; 0 \\&#xA;-e_x&amp;amp; -e_y &amp;amp; -e_z &amp;amp; 1\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They say this could be optimized if instead of doing the matrix multiplication we set the last row to be the dot product between camera position and the $\vec{r}, \vec{u} $ and $\vec{f}$ vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;RT_2 = \begin{bmatrix}r_x &amp;amp; u_x &amp;amp; f_x &amp;amp; 0 \\&#xA;r_y &amp;amp; u_y &amp;amp; f_y &amp;amp; 0 \\&#xA;r_z &amp;amp; u_z &amp;amp; f_z &amp;amp; 0 \\&#xA;-&amp;lt;\vec{r}, \vec{e}&amp;gt;&amp;amp; -&amp;lt;\vec{u}, \vec{e}&amp;gt; &amp;amp; -&amp;lt;\vec{f}, \vec{e}&amp;gt; &amp;amp; 1\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is this possible? I don't see how $RT_1 = RT_2$ could give the same matrix. What am I missing? The only way I can see this is true is inverting the order of multiplication, i.e. $TR$&lt;/p&gt;&#xA;" OwnerUserId="116" LastActivityDate="2016-10-04T11:51:27.363" Title="Building a lookat camera matrix" Tags="&lt;affine-transformations&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4071" PostTypeId="2" ParentId="4065" CreationDate="2016-10-03T23:50:00.410" Score="4" Body="&lt;p&gt;Although you may be able to detect what hardware is available as a first approximation of a computer's capability, depending on this might not be useful since the same hardware may behave differently depending on the machine it is hosted in, and any other tasks that may be competing for it.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Use the frame rate&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;It looks like you are already measuring the frame rate, so you could simply use this value to decide which features to include. If you settle on a target frame rate, then you can order your features from most essential to most optional, and gradually add in less essential features for as long as the target frame rate is exceeded.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could also remove features in reverse order if the frame rate drops (in order to avoid poor frame rate if the available resources change). If you decide to do this, I recommend setting the target frame rate to a slightly different value for adding and removing features. Otherwise some machines near the border between two feature levels may end up skipping back and for between the two levels, adding and removing that feature endlessly. So set the trigger for removing a feature at a  slightly lower frame rate than the trigger for adding it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll need to find a compromise between adding new features too quickly so that the frame rate suddenly drops further than you intended, and adding features too slowly so that there are several seconds of low quality animation before it settles on the appropriate level of features. You may be able to estimate that some features can be added 2 or 3 at a time if the frame rate is already very far above target. This will depend on the specific features involved and may take some trial and error on a variety of machines with different resources.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you prefer, you can show a blank background until the frame rate has settled, so the user does not see the feature level being adjusted. Alternatively you may be able to adjust the features sufficiently gradually that there will be no perceptible change in any given moment.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Consider the window size&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;On my laptop I get 4 frames per second consistently regardless of the window size - whether full screen or a thumbnail sized browser window. Since it appears that the particles move only away from the centre, and do not contribute later to the area they have left, it might be worth considering abandoning particles sooner when the window size is reduced. If this allows a higher frame rate when the window size is reduced, then the extra features will be automatically activated even if they were not possible at full screen.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2016-10-03T23:50:00.410" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4072" PostTypeId="2" ParentId="4068" CreationDate="2016-10-04T03:51:52.100" Score="5" Body="&lt;p&gt;Let me try to make my comment into a complete answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The general idea is to build a linear system using those 6 point pairs and solve for the desired 12 unknowns. You may find this paper&lt;sup&gt;[1]&lt;/sup&gt; useful if you want to learn the theoretical background, and you can find some more details in my blog post&lt;sup&gt;[2]&lt;/sup&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my solution using Mathematica.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first step I will build a symbolic array which contains all variables.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;v = Table[Symbol[&quot;m&quot; &amp;lt;&amp;gt; ToString[i]], {i, 0, 15}];&#xA;M = ArrayReshape[v, {4, 4}]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Next we write down the coordinates for all vertices.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;k = f/ n;&#xA;&#xA;X = {&#xA;    {l, t, -n, 1},&#xA;    {l, b, -n, 1},&#xA;    {r, b, -n, 1},&#xA;    {r, t, -n, 1},&#xA;    {k l, k t, -f, 1},&#xA;    {k l, k b, -f, 1},&#xA;    {k r, k b, -f, 1},&#xA;    {k r, k t, -f, 1}};&#xA;&#xA;U = {&#xA;    {-1, 1, -1},&#xA;    {-1, -1, -1},&#xA;    {1, -1, -1},&#xA;    {1, 1, -1},&#xA;    {-1, 1, 1},&#xA;    {-1, -1, 1},&#xA;    {1, -1, 1},&#xA;    {1, 1, 1}};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;l&lt;/code&gt;,&lt;code&gt;r&lt;/code&gt;,&lt;code&gt;b&lt;/code&gt;,&lt;code&gt;t&lt;/code&gt;,&lt;code&gt;n&lt;/code&gt;,and &lt;code&gt;f&lt;/code&gt; denote left, right, bottom, top, near, and far planes respectively,&#xA;and 'X' is the coordinates in world space, &lt;code&gt;U&lt;/code&gt; is the coordinates in NDC.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then next we implement a function &lt;code&gt;Generate&lt;/code&gt; to generate an equation for each pair of coordinates:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Generate[{i_, j_}] := M[[j]].X[[i]] - U[[i, j]] M[[4]].X[[i]] == 0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Because we do not care about the third row,&#xA;we only solve for the unknowns in &lt;code&gt;partialv&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;partialv = {m0, m1, m2, m3, m4, m5, m6, m7, m12, m13, m14, m15};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now we can build our linear system and solve it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;solve[subset_] := Solve[&#xA;    Map[Generate, Table[{i, j}, {i, subset}, {j, 1, 2}], {2}] // Flatten,&#xA;    partialv] // Simplify&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Let me explain it a little bit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because only 6 pairs of points are given, we select a &lt;code&gt;subset&lt;/code&gt; of 6 elements from the 8 pairs of points.&#xA;Then we call &lt;code&gt;Generate&lt;/code&gt; function on this &lt;code&gt;subset&lt;/code&gt;&#xA;and the first two rows of matrix(we do not care about the third row. And the fourth row is the &quot;homogeneous&quot; part, which is also ignored).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally we enumerate all subsets from these 8 pairs of points, and try to find a solution:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;solutions = Map[solve, Subsets[{1, 2, 3, 4, 5, 6, 7, 8}, {6}]];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We can view one solution by:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;MatrixForm[ArrayReshape[v /. solutions[[1]], {4, 4}]]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\left(&#xA;\begin{array}{cccc}&#xA; \text{m0} &amp;amp; 0 &amp;amp; \frac{\text{m0} (l+r)}{2 n} &amp;amp; 0 \\&#xA; 0 &amp;amp; \frac{\text{m0} (l-r)}{b-t} &amp;amp; \frac{\text{m0} (l-r) (b+t)}{2 n (b-t)} &amp;amp; 0 \\&#xA; \text{m8} &amp;amp; \text{m9} &amp;amp; \text{m10} &amp;amp; \text{m11} \\&#xA; 0 &amp;amp; 0 &amp;amp; \frac{\text{m0} (l-r)}{2 n} &amp;amp; 0 \\&#xA;\end{array}&#xA;\right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;m0&lt;/code&gt; is the &quot;unknown scalar factor&quot; which is mentioned in problem statement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact if we let &lt;code&gt;m0&lt;/code&gt; equals &lt;code&gt;2 n/(r - l)&lt;/code&gt;,&#xA;we would get the conventional projection matrix used in OpenGL:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;% /. m0 -&amp;gt; 2 n/(r - l)&#xA;% // Simplify // MatrixForm&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\left(&#xA;\begin{array}{cccc}&#xA; \frac{2 n}{r-l} &amp;amp; 0 &amp;amp; \frac{l+r}{r-l} &amp;amp; 0 \\&#xA; 0 &amp;amp; -\frac{2 n}{b-t} &amp;amp; -\frac{b+t}{b-t} &amp;amp; 0 \\&#xA; \text{m8} &amp;amp; \text{m9} &amp;amp; \text{m10} &amp;amp; \text{m11} \\&#xA; 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\&#xA;\end{array}&#xA;\right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;[1] Heckbert, Paul S. Fundamentals of texture mapping and image warping. MS thesis. University of California, Berkeley, 1989.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[2] Inferring projective mappings &lt;a href=&quot;http://blog.linearconstraints.net/2016/02/03/inferring-projective-mappings.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Inferring projective mappings | linearconstraints.net&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="120" LastEditorUserId="231" LastEditDate="2018-04-15T10:08:39.497" LastActivityDate="2018-04-15T10:08:39.497" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4074" PostTypeId="2" ParentId="4069" CreationDate="2016-10-04T11:34:32.513" Score="3" Body="&lt;p&gt;Because all matrices are column-major,&#xA;the translation matrix $\mathbf{T}$ should be&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\mathbf{T}=\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; e_x \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; e_y \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; e_z \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought you mistakenly treat the &lt;code&gt;eye&lt;/code&gt; as a row vector just because they were written as a single line in the source code&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat4 translation = {&#xA;    vec4(   1,      0,      0,   0 ),&#xA;    vec4(   0,      1,      0,   0 ), &#xA;    vec4(   0,      0,      1,   0 ),&#xA;    vec4(-eye.x, -eye.y, -eye.z, 1 )&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Another issue in that article is that the variable names are misleading:&#xA;the &lt;code&gt;orientation&lt;/code&gt; denotes $\mathbf{R}^{-1}$, and the &lt;code&gt;translation&lt;/code&gt; denotes $\mathbf{T}^{-1}$(I think it is not a good practice even they commented on these variables).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The final view matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{eqnarray*}&#xA;\mathbf{M} &amp;amp; = &amp;amp; (\mathbf{T}\mathbf{R})^{-1}\\&#xA;&amp;amp; = &amp;amp; \mathbf{R}^{-1}\mathbf{T}^{-1}\\&#xA;&amp;amp; = &amp;amp; \mathbf{R}^{T}\mathbf{T}^{-1}\\&#xA;&amp;amp; = &amp;amp;&#xA;\begin{bmatrix}&#xA;r_x &amp;amp; r_y &amp;amp; r_z &amp;amp; -&amp;lt;\vec{r}, \vec{e}&amp;gt; \\&#xA;u_x &amp;amp; u_y &amp;amp; u_z &amp;amp; -&amp;lt;\vec{u}, \vec{e}&amp;gt; \\&#xA;f_x &amp;amp; f_y &amp;amp; f_z &amp;amp; -&amp;lt;\vec{f}, \vec{e}&amp;gt; \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;\end{eqnarray*}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and the implementation in that article is correct.&lt;/p&gt;&#xA;" OwnerUserId="120" LastEditorUserId="120" LastEditDate="2016-10-04T11:51:27.363" LastActivityDate="2016-10-04T11:51:27.363" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4075" PostTypeId="2" ParentId="4040" CreationDate="2016-10-04T13:25:00.963" Score="6" Body="&lt;p&gt;In GL's model of the GPU, the colour blending step is performed by special-purpose hardware. This idea dates back to the fixed-function origins of GL, before programmable shaders were even a thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But not all GPUs today implement all colour blend options with special-purpose hardware. The hardware vendor can reduce gate count and power use by getting rid of some of the less-used blend modes (or even by getting rid of the blender hardware completely and doing everything in shaders). Instead, the GL driver has to add some code to the shader to do the blending. This code is added transparently to the driver, and isn't visible to the application, because GL doesn't have a way to make this visible or to control it from the application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the shader object (the compiled shader) doesn't just depend on the shader source code, but also on the blend mode in effect when it was compiled. If the application subsequently changes the blend mode, the driver needs to work out which shader objects are affected, retrieve the stored source of those shader objects, add the code for the new blend mode, and recompile the shader. Again, it has to do this behind the application's back, because GL doesn't have a way to control it: GL assumes the shader object is independent of the blend mode.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normally, the application would compile shaders during a loading screen, or in a thread, but because the shader compilation isn't triggered by the application, it can't control when it happens. It just happens by magic when the application changed something that should be unrelated (the blend mode), which might be in the middle of a frame, so it causes hitching. And of course because it's hidden, the app can't simply ask to go back to the old state: changing the blend mode again might trigger another shader compilation (though it might come from a cache in the shader compiler).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blend mode isn't the only parameter that causes this. Some unusual texture modes are also supported by adding code to the shader. (YUV textures commonly work this way, on implementations that support them.) Exactly which parameters cause a problem depends on the implementation: it's different for different hardware architectures. I think it's typically a bigger problem on mobile, because the GPU vendors are more sensitive to gate count and power use and more keen to replace special-purpose hardware with shader code.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The reason Vulkan makes this less of a problem is that it creates a new kind of state, which depends on the blend mode, the shaders, and other parameters. Changing any of these requires the app to perform an explicit &quot;prepare&quot; operation, which might recompile shaders. This gives the app control over when it happens, including the ability to prepare all the combinations of parameters up-front in a loading screen or in a background thread. It means that shader compilation never happens without the app asking for it explicitly. And it means the app can just go back to the old state by switching to it, instead of changing the blend mode and waiting for another shader recompilation.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-10-04T13:25:00.963" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4076" PostTypeId="2" ParentId="4066" CreationDate="2016-10-04T17:42:29.650" Score="0" Body="&lt;p&gt;The main difference with the pipelines is that DirectX12 is focus is on multi-threading or using the multiple cores most efficiently as possible according to the rendering state of an object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for Vulkan, they are separating the management of the threads into different types of pipelines, compute and graphical. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As stated in the reference from MSDN, DirectX12 is utilizing PSO (Pipeline State Object). The optimization occurs in this way by preparing the commands to the pipeline before. Seemingly, DirectX12 uses PSO to create a object of the state of rendering to better manage changes in state to the hardware more efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope that helps!&lt;/p&gt;&#xA;" OwnerUserId="4829" LastActivityDate="2016-10-04T17:42:29.650" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4077" PostTypeId="2" ParentId="4058" CreationDate="2016-10-04T17:49:05.087" Score="3" Body="&lt;p&gt;Let's go through the paper you mentioned and try to list the factors which will affect your decision on whether to use GPU or CPU for simulation.&#xA;I will also add some comments about my opinion for each factor.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Computation bound&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;A GPU program runs in a SIMT(Single instruction, multiple threads) model.&#xA;In this model, if some threads stall due to memory access or divergence,&#xA;thread scheduler will schedule another set of threads to run&#xA;to hide the memory latency.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As we can see it requires adequate computation load to make this mechanism work.&#xA;If one implementation is memory bound, we hardly benefit from the SIMT programming model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fortunately, fluid simulation is a computation bound task for most of the cases.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Locality&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;In the paper you mentioned we can observe perfect locality:&lt;br&gt;&#xA;for each grid point we only have to examine its neighbors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The actual memory access pattern depends on the finite difference scheme you use.&#xA;But for all grid based simulation methods(Eulerian or Lattice-Boltzmann method), I think the locality always presents.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Divergence&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;A warp (a group of 32 threads) in a GPU program can be executed in parallel if they follow the same code path. Otherwise the program diverges and the execution of each branch will be serialized. Divergence will hurt the performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particle based simulations (such as SPH method) we usually have to query the nearest N particles. A tree-like data structure will be used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In GPU a tree data structure may introduce divergence because particles may fall into different branches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper you mentioned uses grid based methods, where all threads execute along the same code path (Jacobi or Gauss-Seidel iteration), so divergence is not a problem here.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Interactivity&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;In the paper it uses static boundary conditions.&lt;br&gt;&#xA;For this case you just need to upload the boundary conditions to GPU memory only once.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have dynamic boundary conditions, for example, which are specified by the user at each frame, the overhead of memory transfer between GPU and CPU should be taken into consideration.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Spatial complexity&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Uniform grid based simulations cannot handle very large computation volume, because the spatial complexity is cubic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are adaptive grid methods, which use relatively higher resolution for the computation region we are most interested in. But that would also bring in divergence.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Numerical issues&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;For fluid simulation you cannot decide the number of steps solely based on the performance/frame rate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In grid based methods, the Courant–Friedrichs–Lewy (CFL) condition puts a constraint on how large simulation step you can have.&#xA;Given a fixed time step, too large or too small steps would cause instability and blow up the simulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particle based methods and some stable grid based methods (such as the semi-Lagrangian method used in the paper), we can use relatively larger simulation steps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But we still cannot increase the step size with no bound because of the accuracy.&#xA;For example in grid based methods a large step size would introduce too much numerical viscosity.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Summary&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;As a summary, if your simulation has strong convergence and locality, prefer a GPU implementation; otherwise, prefer a CPU one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice, I will always implement a CPU version because it is easier to debug and it will be useful as a baseline.&#xA;Then I will profile it to locate the bottleneck and decide whether to have a GPU version.&lt;/p&gt;&#xA;" OwnerUserId="120" LastEditorUserId="120" LastEditDate="2016-10-05T23:50:44.620" LastActivityDate="2016-10-05T23:50:44.620" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4078" PostTypeId="1" CreationDate="2016-10-04T19:55:26.123" Score="2" ViewCount="835" Body="&lt;p&gt;I have a bunch of planes each with their own texture in a grid. Currently I am rendering these as separate planes, each with their own texture, although I could use a single plane with multiple faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sgSuH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sgSuH.png&quot; alt=&quot;textures&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each color is a texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a polygon mesh with arbitrary shape that is parallel to these planes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FdGTj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FdGTj.png&quot; alt=&quot;polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This shape could be completely contained within one of the planes, or larger.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to texture the polygon with the overlapping textures of the planes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gsaSF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gsaSF.png&quot; alt=&quot;overlap&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I accomplish this clipping of the textures in three js / WebGl?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am also open to any other WebGL solutions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few ideas I had:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Subdivide the polygon into faces that correspond with the overlapping planes. Then texture these faces using UV coords. I know I can get this to work, but it seems like too complicated of a solution.&lt;/li&gt;&#xA;&lt;li&gt;Apply multiple textures to the polygon and use UV coordinates to distribute them. -- Im not sure this is possible without subdividing?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Any other ideas? Can this be accomplished with blending modes?&lt;/p&gt;&#xA;" OwnerUserId="5093" LastActivityDate="2016-10-09T10:48:16.933" Title="How to clip multiple tiled textures to polygon in Webgl / opengl" Tags="&lt;rendering&gt;&lt;webgl&gt;&lt;clipping&gt;&lt;masking&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4079" PostTypeId="1" AcceptedAnswerId="4091" CreationDate="2016-10-05T08:07:33.903" Score="8" ViewCount="3677" Body="&lt;p&gt;So I'm trying to correctly map my textures in my software renderer using the u, v coordinates but I can't seem to get it working. I got affine texture mapping working. This is what I can produce using it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EuhmH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EuhmH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see from the &quot;tilt&quot; in the texture that it's not quite right. If I add more triangles to the mesh it becomes more correct. From my understanding these are not perspective correct textures. But this perspective divide thing is confusing me. I read that I needed to divide the u, v coordinates by the w component (perspective divide). I'm guessing that this is the w component from the vertex after multiplying with the projection matrix. But I couldn't get that too work. So I looked a little bit more into the problem. First, here's what is happening to one vertex of my triangles.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 pt1 = worldViewProj * mesh-&amp;gt;vertices[mesh-&amp;gt;indices[i]];&#xA;float2 uv1 = mesh-&amp;gt;texCoords[mesh-&amp;gt;indices[i]];&#xA;triangle.p1 = float3((pt1.x / pt1.w + 0.5f) * screen-&amp;gt;GetScreenWidth(), (pt1.y / pt1.w + 0.5f) * screen-&amp;gt;GetScreenHeight(), pt1.w);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I multiply it with the wVP and then do my perspective divide with x and y. The + 0.5f is to center it in homogeneous space and then multiply with the screen dimensions to get it in screen space. I then stuff the w component of the vertex as the z value so it will be sent to the triangle drawing function and can be used for things like the depth buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To my understanding the z value from the vertex gets put into w after multiplying with the projection matrix. This makes sense since m32 = 1 in my projection matrix. So after multiplication with the projection matrix w = z. I first tried dividing the texture coordinates per vertex by w. Like so:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; float2 uv1 = mesh-&amp;gt;texCoords[mesh-&amp;gt;indices[i]] / w;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then in the triangle drawing function I used the bary centric coordinates to interpolate across these the uv coordinates. This did not work. Since w = z. When the texture is far from the camera (ie z is a large value. With my world translations applied z = ~700) then the texture coordinates shrink a lot and in every render I just get the (0, 0) value of my texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I also tried this instead in my triangle drawing function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 texCoord = (texCoord1 * u + texCoord2 * v + texCoord3 * w) / z;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(Here u, v, and w are the bary centric coordinates. Each texCoord is the texture Coordinate at that vertex) The difference here is that the interpolated z value is being divided at every pixel instead of it being divided at the vertices. Either way I can't seem to get it too work. Again the z value is too large and I end up getting (0, 0).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I'm investigating what I need to divide u and v by. Obviously I'm doing something wrong. Is it really the w component of the vertex after multiplying with the projection matrix? Is my w value wrong? Could the projection matrix be causing this? I've been googling around for awhile now... x / w and y / w are [-1, 1] (homogeneous) but z isn't [-1, 1]. Is it supposed to be? My perspective divide for x and y obviously works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's how I built my projection matrix just in case it's wrong?:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float tanHalfFov = tanf(fov * 0.5f * 3.14f / 180.0f);&#xA;float s = 1.0f / (tanHalfFov * aspectRatio);&#xA;float zRange = farZ - nearZ;&#xA;&#xA;// Set the projection matrix&#xA;proj.m00 = s;    proj.m01 = 0.0f;            proj.m02 = 0.0f;          proj.m03 = 0.0f;&#xA;&#xA;proj.m10 = 0.0f; proj.m11 = aspectRatio * s; proj.m12 = 0.0f;          proj.m13 = 0.0f;&#xA;&#xA;proj.m20 = 0.0f; proj.m21 = 0.0f;            proj.m22 = farZ / zRange; proj.m23 = farZ * nearZ / zRange;&#xA;&#xA;proj.m30 = 0.0f; proj.m31 = 0.0f;            proj.m32 = 1.0f;          proj.m33 = 0.0f;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2016-10-05T23:44:50.150" LastActivityDate="2016-10-06T13:01:13.223" Title="Perspective Correct Texture Mapping" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;perspective&gt;&lt;uv-mapping&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4080" PostTypeId="2" ParentId="4067" CreationDate="2016-10-05T11:14:03.440" Score="4" Body="&lt;p&gt;Alan Wolfe is pretty spot on, but I will sum up any way :)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;render the back-faces of your &quot;unit&quot;-sized-box, [-1;1]&lt;/li&gt;&#xA;&lt;li&gt;sample the zbuffer and transform into light-local coordinates (see &lt;a href=&quot;http://f0716f2bff707a1b9e85-36c178e006d3d30c5b9c8dd905f8236a.r70.cf2.rackcdn.com/rendering_inside.pdf&quot;&gt;our slides&lt;/a&gt; for a fast way to do that).&lt;/li&gt;&#xA;&lt;li&gt;early-out of the pixelshader if outside of the box, i.e. if any coordinate in the local-position is outside of -1;1.&lt;/li&gt;&#xA;&lt;li&gt;then do the dot-product between the normal and the lightdir, in whatever space is convenient (you can extract the worldspace-lightdir from the object-to-world matrix).&lt;/li&gt;&#xA;&lt;li&gt;projecting a texture is easy, the UV-coordinates are simply the localspace xy (moved to [0;1])&lt;/li&gt;&#xA;&lt;li&gt;using a falloff texture is eays, the coordinate is simply the localspace z (moved to [0;1])&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;In an actual game, you of course want to use some sort of acceleration to discard early; we used old-school stencil culling (and should have used depthbounds), but likely tiled culling, clustered culling or similar is better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could use zgreater testing to discard pixels where background is entirely behind the light, but iirc on most modern GPUs this will not actually be an advantage, as there will be no early-discard due to the hierarchical zbuffer being primed in the direction of zless.&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2016-10-05T11:14:03.440" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4081" PostTypeId="1" CreationDate="2016-10-05T13:32:22.793" Score="5" ViewCount="425" Body="&lt;p&gt;I have been trying to figure out why does rotation about an arbitrary axis have degree of freedom 6. I know that it takes two points, each take 3 values to determine in a 3-D space. But what about the rotation angle? Wouldn't that make the degree of freedom increase by 1 to get 7?&lt;/p&gt;&#xA;" OwnerUserId="5235" LastActivityDate="2016-10-06T11:50:11.057" Title="Why does rotation about an arbitrary axis have degree of freedom 6" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4082" PostTypeId="2" ParentId="4081" CreationDate="2016-10-05T14:25:28.713" Score="4" Body="&lt;p&gt;The length of the axis is irrelevant and so you can remove one degree of freedom.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2016-10-05T14:25:28.713" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4084" PostTypeId="2" ParentId="4067" CreationDate="2016-10-05T15:12:35.930" Score="2" Body="&lt;p&gt;I would start by looking into deferred decals (you can start &lt;a href=&quot;https://bartwronski.com/2015/03/12/fixing-screen-space-deferred-decals/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; for example, this blogpost has a lot of useful links)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you understand how the positions are calculated and compared with the volume then you should be able to apply the same logic in the lighting phase.&lt;/p&gt;&#xA;" OwnerUserId="5236" LastActivityDate="2016-10-05T15:12:35.930" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4085" PostTypeId="2" ParentId="4008" CreationDate="2016-10-05T15:33:28.897" Score="1" Body="&lt;p&gt;You also need to scale the cylinder. Take the magnitude (length) of $p_1 - p_2$, and divide it by the length of the cylinder (or don't divide, if your cylinder is already unit length). This gives you the scale factor. You can apply this as a non-uniform scale along the axis that the cylinder points in. (Since you were able to work out how to apply a rotation, I assume you can make the appropriate scaling matrix given just the scale factor and direction.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Make sure to scale it before rotating or translating the cylinder! If you translate before you scale, you'll translate the start point of the cylinder as well as its length, so the start won't be attached to $p_1$ any more. If you rotate before you scale, you won't be scaling the length of the cylinder, you'll be stretching it in the wrong direction, so it won't be a cylinder any more.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-10-05T15:33:28.897" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4086" PostTypeId="2" ParentId="4081" CreationDate="2016-10-05T16:02:44.307" Score="3" Body="&lt;p&gt;It is only 3 degrees of freedom (when talking about a rotation around the origin).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An arbitrary axis can be specified by 1 3D vector however the length doesn't matter so it only takes 2 degrees of freedom. Then you add the rotation angle to it and you have 3 degrees of freedom.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you mean a rotation around a arbitrary point other than the origin then that point takes up 3 additional degrees of freedom for a total of 6.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2016-10-06T11:50:11.057" LastActivityDate="2016-10-06T11:50:11.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4087" PostTypeId="1" AcceptedAnswerId="4088" CreationDate="2016-10-05T16:23:03.047" Score="5" ViewCount="873" Body="&lt;p&gt;I know when we use Z-buffer to eliminate the hidden faces, the polygons can be in any order. But my teacher said that this does not mean that two images generated by sending polygons in different orders will have identical values in their z-buffers and in their frame buffers. How does this happen? &#xA;And if this is the case, When or how will the z-buffers and the frame buffers have the same values even if polygons are sent in different order?&lt;/p&gt;&#xA;" OwnerUserId="5105" LastActivityDate="2018-06-04T07:42:53.117" Title="How will the z-buffers have the same values even if polygons are sent in different order?" Tags="&lt;z-buffer&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4088" PostTypeId="2" ParentId="4087" CreationDate="2016-10-05T17:03:36.627" Score="4" Body="&lt;p&gt;What your teacher means is that at the &lt;em&gt;end&lt;/em&gt; of the frame, once all polygons in the scene have been drawn, the z-buffer will have the same values. This is because the z-buffer keeps the minimum Z within each pixel, over all the polygons drawn to that pixel, and the minimum doesn't depend on the order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at the z-buffer in the &lt;em&gt;middle&lt;/em&gt; of the frame, when &lt;em&gt;some&lt;/em&gt; polygons, but not all, have been drawn, then naturally the contents of the z-buffer will depend on what's been drawn so far, which would depend on the order in general.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With regard to the color buffer, the same things are true if all the Z values within each pixel are distinct. However there's one case where the results do depend on the order: when multiple polygons have the same Z value at a given pixel. This could happen if the same polygons are rendered twice with different colors, or some such. Then, the behavior depends on the setting of the depth test (i.e. &lt;a href=&quot;http://docs.gl/gl4/glDepthFunc&quot; rel=&quot;nofollow&quot;&gt;&lt;code&gt;glDepthFunc&lt;/code&gt;&lt;/a&gt; in OpenGL). If it's strictly &quot;less&quot;, then the first polygon drawn that has the minimum Z will &quot;win&quot; and its color will end up in the color buffer at the end. But if the depth test is set to &quot;less-equal&quot;, then each polygon that has the minimum Z will overwrite the one before it, and the last one drawn will end up in the color buffer at the end. So in that case, the order of drawing polygons, and the state of the depth test, do make a difference.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-10-05T17:03:36.627" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4089" PostTypeId="2" ParentId="4087" CreationDate="2016-10-05T17:42:53.303" Score="4" Body="&lt;p&gt;If you use alpha blending, then the order of rendered polygons matter even if you use depth writes &amp;amp; tests. E.g. imagine you render two triangles A (red) and B (blue) with 50% opacity where smaller triangle B is in front of A. If you render A before B then the B will appear purple, but if you render B before A then B will appear dark blue (pixels for A are not rendered where the triangles overlap).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you use opaque rendering, then the frame buffer values will be the same regardless of the rendering order, except in the special case Nathan mentioned where the depth values are equal for the two triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Only thing where the rendering order matters for z-buffer result that comes to mind is if you use specific stencil test &amp;amp; ops. E.g. when rendering A the stencil test passes and writes a value to stencil buffer which makes B to fail which results only the triangle A to be visible. But if you render B before A, then you see B in front of A. This will naturally influence also frame buffer values.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-05T17:42:53.303" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4091" PostTypeId="2" ParentId="4079" CreationDate="2016-10-06T12:11:11.807" Score="10" Body="&lt;p&gt;You are on the right track but what you need to do is to calculate u/w and v/w, and also 1/w for each vertex, which you interpolate linearly in screen space in your rasterizer. Then for every pixel you divide the interpolated u/w and v/w coordinates with the interpolated 1/w to get perspective correct uv-coordinates for the pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same applies to all the vertex attributes, e.g. if you need to get perspective correct color or position of vertices per pixel, then you interpolate c/w and p/w and divide those values by 1/w per pixel. Even if you don't implement software rasterizer this can be quite useful for example in ray marching of screen-space reflection implementation. I have seen people doing the ray marching for SSR in world space because they don't know how to properly interpolate position in screen space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What old software rasterizers used to do is to perform this 1/(1/w) division only every X pixels and linearly interpolate values in-between because the division was relatively expensive operation to perform every pixel.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-10-06T13:01:13.223" LastActivityDate="2016-10-06T13:01:13.223" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4092" PostTypeId="1" CreationDate="2016-10-06T14:23:27.260" Score="2" ViewCount="51" Body="&lt;p&gt;When I was doing some graphic designing with JavaScript, I saw this strange behaviour.&lt;br&gt;&#xA;When I ran the following code (with proper HTML and JavaScript of course),&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;context.lineTo(100, 100);&#xA;context.lineTo(200, 200);&#xA;context.stroke();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The result was a straight line from (100, 100) to (200, 200), which I wasn't expecting. I expected that nothing would be drawn. I think this would only happen with the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;context.beginPath();&#xA;context.moveTo(100, 100);&#xA;context.lineTo(200, 200);&#xA;context.stroke();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is my thinking wrong? Why is it happening so? Can anyone explain?&lt;/p&gt;&#xA;" OwnerUserId="5246" LastEditorUserId="16" LastEditDate="2016-10-06T14:37:01.397" LastActivityDate="2016-10-06T14:53:55.370" Title="Successive lineTo(x, y) in JavaScript" Tags="&lt;javascript&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4093" PostTypeId="2" ParentId="4092" CreationDate="2016-10-06T14:35:54.007" Score="2" Body="&lt;p&gt;Straight from the &lt;a href=&quot;https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-lineto&quot; rel=&quot;nofollow&quot;&gt;specification&lt;/a&gt; of &lt;code&gt;lineTo&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If the object's path has no subpaths, then ensure there is a subpath for (x, y).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And &quot;ensure that there is a subpath&quot; links to &lt;a href=&quot;https://html.spec.whatwg.org/multipage/scripting.html#ensure-there-is-a-subpath&quot; rel=&quot;nofollow&quot;&gt;this bit&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;When the user agent is to ensure there is a subpath for a coordinate (x, y) on a path, the user agent must check to see if the path has its &lt;em&gt;need new subpath flag&lt;/em&gt; set. If it does, then the user agent must create a new subpath with the point (x, y) as its first (and only) point, as if the &lt;code&gt;moveTo()&lt;/code&gt; method had been called, and must then unset the path's &lt;em&gt;need new subpath flag&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In short, if you call &lt;code&gt;lineTo&lt;/code&gt; without an explicit &lt;code&gt;beginPath&lt;/code&gt;, then a new path is created implicitly, with the given point as its starting point.&lt;/p&gt;&#xA;" OwnerUserId="16" LastEditorUserId="16" LastEditDate="2016-10-06T14:53:55.370" LastActivityDate="2016-10-06T14:53:55.370" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4094" PostTypeId="1" CreationDate="2016-10-06T16:20:18.093" Score="8" ViewCount="2100" Body="&lt;p&gt;One of the features of ray marching is that you can use modulus to repeat shapes infinitely, like in the image below, which is from &lt;a href=&quot;https://www.shadertoy.com/view/MsBGW1&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/MsBGW1&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SKXUF.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SKXUF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was curious if there exists any technique which allows you to do the same thing with ray tracing instead of ray marching?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One method I do know of is to ray trace a plane from above, and then where you hit the plane, calculate your location on a grid on that plane, and use the relative position in that grid cell as an absolute position to raytrace a scene.  That will repeat the scene across the grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, a problem with that is if your ray doesn't hit anything in the grid cell, and it would then enter another grid cell, this technique won't catch those other shapes without walking the grid cells down the path of the ray until it exits the back side of the grid, which is very ray-marching-esque and iterative.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know of a technique that allows you to have ray marching type repetition in ray tracing?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2019-12-02T02:46:49.847" Title="Is there a method to do ray marching style modulus repeat with raytracing?" Tags="&lt;raytracing&gt;&lt;raymarching&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4095" PostTypeId="2" ParentId="245" CreationDate="2016-10-06T17:04:22.083" Score="5" Body="&lt;p&gt;Even though I didn't know about monte carlo path tracing when I wrote this, I accidentally described it.  Ironically, monte carlo path tracing is the answer I was looking for at the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Naive monte carlo path tracing works by evaluating something called the rendering equation to numerically solve the color value of a pixel.  It takes random samples by randomly jittering within a pixel (there are better sampling strategies, and filtering: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4013/what-is-the-fundamental-reasoning-for-anti-aliasing-using-multiple-random-sample&quot;&gt;What is the fundamental reasoning for anti aliasing using multiple random samples within a pixel?&lt;/a&gt;) and also by bouncing in random directions when a ray hits a surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It can take a lot of samples to give you good results, and with not enough samples, your image will look noisy.  It takes 4 times as many samples to cut the noise in half.  Render times can be on the order of an hour using 8 modern CPU cores for a simple scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are more advanced monte carlo path tracing techniques that let you get better images more quickly, such as importance sampling, or denoising the image after it's rendered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Monte carlo path tracing can make photorealistic images and gives you many advanced rendering features just because it follows physical laws so gives realistic results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can read more about it here:&#xA;&lt;a href=&quot;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example image, which took about an hour to render using all 8 of my cpu cores:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EacNQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EacNQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-10-06T17:04:22.083" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4096" PostTypeId="2" ParentId="245" CreationDate="2016-10-06T19:02:30.053" Score="11" Body="&lt;p&gt;Path tracing is the standard technique in non-realtime photorealistic rendering, and you should look specifically into &lt;a href=&quot;https://en.wikipedia.org/wiki/Path_tracing#Bidirectional_path_tracing&quot; rel=&quot;noreferrer&quot;&gt;bidirectional path tracing&lt;/a&gt; to get effects like caustics, which you can't really get with basic path tracing. Bidirectional path tracing also converges faster to the ground truth as shown in the below image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3fg6U.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3fg6U.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Also &lt;a href=&quot;https://en.wikipedia.org/wiki/Metropolis_light_transport&quot; rel=&quot;noreferrer&quot;&gt;Metropolis light transport&lt;/a&gt; (MLT) is a more advanced path tracing technique that converges even faster to the ground truth by mutating existing &quot;good&quot; paths:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/KoMaU.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KoMaU.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also use importance sampling for faster convergence by focusing more rays to the directions that matter more. I.e. by focusing rays based on BRDF (more towards the BRDF spike using probability density function) or to the light source, or get best of the two worlds and using multiple importance sampling. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/TiwGE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TiwGE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;This is all about reducing noise in unbiased manner. There are also &lt;a href=&quot;https://benedikt-bitterli.me/nfor/&quot; rel=&quot;noreferrer&quot;&gt;denoising techniques&lt;/a&gt; to further reduce noise in the rendered images.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YFQ8H.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YFQ8H.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think it's best to first implement basic brute force Monte Carlo path tracer to serve as unbiased reference before looking into the more advanced techniques. It's quite easy to do mistakes and introduce biasing that goes unnoticed, so having simple implementation is good to have around for reference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also get some really nice results by applying path tracing to participating media but that gets slow really fast :D&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3Cmp6.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3Cmp6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-10-06T19:37:04.423" LastActivityDate="2016-10-06T19:37:04.423" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4097" PostTypeId="1" CreationDate="2016-10-06T19:47:20.410" Score="4" ViewCount="121" Body="&lt;p&gt;I'm implementing bidirectional path tracing. I want to simulate perfect refraction. I read in the Veach thesis that a perfect refraction BSDF is non-symmetric. Does it mean that I need to use different computations for refraction BSDF (BTDF) for eye subpaths and light subpaths? It seems strange for me, as BPT differs from PT only in the way I generate the path and throughput computations should be the same, as in PT all BSDFs are computed in the same way. Is that non symmetry relevant only for particle based techniques like Photon Mapping?&lt;/p&gt;&#xA;" OwnerUserId="5249" LastActivityDate="2016-10-06T19:47:20.410" Title="Should I use nonsymmetric BSDF for refraction in BPT?" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;refraction&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4098" PostTypeId="1" CreationDate="2016-10-06T22:13:29.590" Score="8" ViewCount="192" Body="&lt;p&gt;Recently while searching of solving the shadow acne problem of traditional shadow mapping I implemented exponential shadow maps. It did the trick (no acne at all) but at the same time introduced other unacceptable errors.&lt;/p&gt;&#xA;&lt;p&gt;For depth map blur I use gaussian blur with smallest sigma=1.&lt;/p&gt;&#xA;&lt;p&gt;Test for shadow map:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float occluder = texture(shadowMap lightCoords.xy).r;&#xA;float c = 5000.0;&#xA;float receiver = lightCoords.z;&#xA;float shadow = exp(c*(occluder-receiver));&#xA;shadow = clamp(shadow, 0.0, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;with small c factor &lt;code&gt;c=100.0&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2EHPH.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2EHPHm.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Unacceptable light bleeding&lt;/p&gt;&#xA;&lt;p&gt;with high c factor &lt;code&gt;c=5000.0&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BBYtJ.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BBYtJm.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;No light bleeding but high frequency detail appear &amp;quot;swollen&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;Cant find optimal c - light bleeding appear even at &lt;code&gt;c=3000.0&lt;/code&gt; and high frequency shadow error is already there. Not blurring the depth map helps but then aliasing occurs.&lt;/p&gt;&#xA;&lt;p&gt;And my question is - how can I improve this technique (ESM) or should I look for another? I think good quality shadows with nice performance are definitely possible - as seen in modern games like Witcher 3 or Fallout 4.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-10-08T21:47:30.660" Title="searching for acceptable quality shadow mapping techniques" Tags="&lt;rendering&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4099" PostTypeId="1" CreationDate="2016-10-07T13:46:06.943" Score="4" ViewCount="124" Body="&lt;p&gt;I am a student of computer science and this semester is my first semester of MSc. Next semester I must choose an advisor and the subject of my dissertation. I somewhat know what geometric modeling is and I want to research in this area, but I don't know where should I start. Can anyone who is a professional researcher in geometric modeling help me with where I should start?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this field have problems to work on?&lt;/p&gt;&#xA;" OwnerUserId="5253" LastEditorUserId="231" LastEditDate="2016-10-08T07:55:02.843" LastActivityDate="2017-07-13T12:22:33.923" Title="I need advice and good reference in geometric modeling?" Tags="&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="2" ClosedDate="2017-07-14T14:03:17.607" ContentLicense="CC BY-SA 3.0" />
  <row Id="4100" PostTypeId="2" ParentId="4099" CreationDate="2016-10-07T14:15:31.037" Score="1" Body="&lt;p&gt;As a graphics professional, not a researcher, it's a bit hard to know what exactly is or is not part of geometric modeling, but looking at this page (&lt;a href=&quot;http://graphics.cs.ucdavis.edu/~joy/GeometricModelingLectures/&quot; rel=&quot;nofollow&quot;&gt;http://graphics.cs.ucdavis.edu/~joy/GeometricModelingLectures/&lt;/a&gt;) it looks like it's just all about different ways to model surfaces, whether that's with triangles, mathematical descriptions, or other things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If that is the case, yeah, there are still open problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a journal with some papers on the topic:&#xA;&lt;a href=&quot;http://jcgt.org/&quot; rel=&quot;nofollow&quot;&gt;http://jcgt.org/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would also look at the SIGGRAPH conference topics over the years, there is a lot of that sort of thing there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IMO you are going to find that the problems are broken up into two main groups:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Real Time Graphics&lt;/li&gt;&#xA;&lt;li&gt;Non Real Time Graphics&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Video games and real time simulation software has the primary need of needing representations that can be rendered in real time, and are also fairly efficient as far as size, so that they don't take up too much memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern day movies, and also &quot;offline processes&quot; (such as baking out lighting into textures to use in real time applications) use non real time rendering techniques to get high quality results.  Speed and memory still matter to them of course, but the restrictions are much more relaxed as it isn't uncommon for a single frame of a movie to take a day to render, using a cluster of machines in a rendering farm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both real time and non real time graphics also have needs beyond rigid body geometry though, and also are interested in finding good ways to model liquids, gasses like smoke, and other things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Besides the obvious representations of geometry like triangle and quad meshes, or bezier and other analytical shapes, there is also a lesser known concept of the signed distance field which can be used for both 3d modeling as well as 2d vector graphics.  In both cases, when you zoom into these shapes they have inifinite detail - such as being completely smooth, or having a perfectly sharp corner or whatever else.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a video about one way subdivision surfaces can be achieved in real time graphics, shown at SIGGRAPH 2016, regarding the call of duty game:&#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=PTGTviYwolE&quot; rel=&quot;nofollow&quot;&gt;https://www.youtube.com/watch?v=PTGTviYwolE&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I were in your shoes, part of what I would research would be what the &quot;demo scene&quot; is up to.  By demo scene I mean the people who make 64KB executables that when you run them, display photo realistic movies and have music and audio as well.  Those folks have some very creative ways of doing things that often ties into cutting edge research topics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shadertoy.com is a place where you can write webgl pixel shaders and share them with others.  There is a lot of really interesting and exotic graphics stuff there, including signed distance field rendering, ray marching, ray tracing, path tracing, and more.&#xA;&lt;a href=&quot;https://www.shadertoy.com/&quot; rel=&quot;nofollow&quot;&gt;https://www.shadertoy.com/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a demoscene website:&#xA;&lt;a href=&quot;http://www.pouet.net/&quot; rel=&quot;nofollow&quot;&gt;http://www.pouet.net/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, if I may humbly point you towards a paper I wrote, I came up with a technique for getting the GPU texture sampler to calculate Bezier curve points of arbitrary dimension for you as part of a texture lookup, using the non programmable N-dimensional texture sample linear interpolator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe it can be expanded to support Bezier surfaces as well, but haven't yet looked into the details of that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.demofox.org/2016/02/22/gpu-texture-sampler-bezier-curve-evaluation/&quot; rel=&quot;nofollow&quot;&gt;http://blog.demofox.org/2016/02/22/gpu-texture-sampler-bezier-curve-evaluation/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-07T14:15:31.037" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4101" PostTypeId="1" AcceptedAnswerId="4102" CreationDate="2016-10-07T14:25:22.823" Score="4" ViewCount="147" Body="&lt;p&gt;I need to write a photo-realistic renderer. I have been looking at ScratchAPixel site, asking a couple of questions here on CG, and going through the Advanced Global Illumination 2nd ed book. I've read about radiometry, probability, Monte Carlo, and a bit on Russian roulette. I'm aware of the rendering equation in its hemispherical and area formulations. I've written a SAH based kd-tree, so am ok for efficient ray casting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm poised to start writing some code alongside reading chapter 5 of my book which is about path tracing algorithms. However, the last half of chapter 4 is taken up with talking about the following concepts:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The Importance Function&lt;/li&gt;&#xA;&lt;li&gt;The Measurement Equation&lt;/li&gt;&#xA;&lt;li&gt;Adjoint equations and linear transport operators&lt;/li&gt;&#xA;&lt;li&gt;GRDF (Global Reflectance Distribution Function)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;These concepts I've not seen appearing elsewhere in my research (if you can call reading a few web pages about GI rendering proper research?). My question is, &lt;strong&gt;do I really need to know this stuff to progress to writing my path tracer?&lt;/strong&gt; I suspect the answer might depend on which type of path tracer I'm going to developer. To start, based upon what little I know, I think it'll be unidirectional.&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2016-10-07T18:37:58.797" Title="Can I ignore importance, adjoint equations, GRDFs for my path tracer?" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4102" PostTypeId="2" ParentId="4101" CreationDate="2016-10-07T18:25:47.573" Score="3" Body="&lt;p&gt;No, you don't need to know this stuff to implement basic path tracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basic unidirectional path tracer is quite simple to implement. Just trace bunch of paths of length X for each pixel with uniform distribution over the normal oriented hemisphere at the path's intersection points. Then weight the remaining path with the BRDF at each intersection point and multiply with luminance of light once the path hits a light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll get quite a noisy (but unbiased!) image even for large number of paths and then you can start to look into methods to reduce noise, e.g. importance sampling &amp;amp; bidirectional path tracing. Just validate the more optimized path tracers towards earlier validated path tracers to avoid introducing accidental bias.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-10-07T18:37:58.797" LastActivityDate="2016-10-07T18:37:58.797" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4103" PostTypeId="2" ParentId="4098" CreationDate="2016-10-08T12:49:53.820" Score="2" Body="&lt;p&gt;Well nevermind. I made some research and actually gonna:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;sample ESM using Poisson sampling in PCF fashion (thanks Bart Wronski for great Poisson Sample generator app) and extend this to PCSS technique (variable penumbra). Render to texture.&lt;/li&gt;&#xA;&lt;li&gt;optionally depth aware blur to soften - EDIT not so fast this option doesnt work as expected, too bad. Instead rotating PCF kernel seem to work fine. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And too bad not much of discussion here.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-10-08T21:47:30.660" LastActivityDate="2016-10-08T21:47:30.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4104" PostTypeId="1" CreationDate="2016-10-08T19:33:22.113" Score="5" ViewCount="131" Body="&lt;p&gt;So recently I have been learning how to implement Diffuse Lighting in DirectX and I have done so with the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 PS(VS_OUTPUT input) : SV_TARGET&#xA;{&#xA;    input.normal = normalize(input.normal);&#xA;&#xA;    float4 diffuse = ObjTexture.Sample(ObjSamplerState, input.TexCoord);&#xA;&#xA;    float3 finalColor;&#xA;&#xA;    finalColor = diffuse * light.ambient;&#xA;    finalColor += saturate(dot(light.dir, input.normal) * light.diffuse * diffuse);&#xA;&#xA;    return float4(finalColor, diffuse.a);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which has produced the following results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7wBHM.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7wBHM.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before I progress any further with specular lighting I wanted to clean up my code a little so I re-implemented this with a function and few changes. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 DirectDiffuseBRDF(float3 diffuseAlbedo, float nDotL)&#xA;{&#xA;    return (diffuseAlbedo * nDotL);&#xA;}&#xA;&#xA;float4 PS(VS_OUTPUT input) : SV_TARGET&#xA;{&#xA;    input.normal = normalize(input.normal);&#xA;&#xA;    float4 diffuseAlbedo = ObjTexture.Sample(ObjSamplerState, input.TexCoord);&#xA;&#xA;    float nDotL = saturate(dot(input.normal, light.dir));&#xA;&#xA;    float3 diffuseLighting = DirectDiffuseBRDF(diffuseAlbedo, nDotL);&#xA;&#xA;    return float4(diffuseLighting, diffuseAlbedo.a);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which produces:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gaRXr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gaRXr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the modified code has it's diffuse lighting a little different compared to the original. What am I missing from the original code to get it back to normal?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-10-09T10:05:42.927" Title="Problem with Basic Diffuse Lighting" Tags="&lt;texture&gt;&lt;c++&gt;&lt;brdf&gt;&lt;directx11&gt;&lt;diffuse&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4105" PostTypeId="1" CreationDate="2016-10-08T21:58:21.903" Score="1" ViewCount="179" Body="&lt;p&gt;I'm trying to do object recognition in an embedded environment, and for this I'm using Raspberry Pi (Specifically version 2).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using OpenCV Library and as of now I'm using feature detection algorithms contained in OpenCV.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've tried different approaches:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried different keypoint extraction and description algorithms: SIFT, SURF, ORB. SIFT and SURF are too heavy and ORB is not so good.&#xA;Then I tried using different algorithms for keypoint extraction and then description. The first approach was to use FAST algorithm to extract key points and then ORB or SURF for description, the results were not good and not rotation invariant, then i tried mixing the others.&#xA;I now am to the point where I get the best results time permitting using ORB for keypoint extraction and SURF for description. But it is still really slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now it is being used to match the object image (400x200) with frames captured from webcam. My definition of too slow is 2fps with 640x400 frame resolution. I wanted to take it to at least 5-6 fps per second, to obtain a more fluent video stream&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So do you have any suggestions or new ideas to obtain better results? Am I missing something?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As additional information, I'm using Python 3.5 with OpenCV 3.1&lt;/p&gt;&#xA;" OwnerUserId="5257" LastActivityDate="2017-10-15T13:23:39.430" Title="Feature detection for embedded platform OpenCV" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;hardware&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4106" PostTypeId="2" ParentId="4104" CreationDate="2016-10-08T23:18:34.233" Score="3" Body="&lt;p&gt;Your ambient lighting contribution is missing from the second one (:&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-08T23:18:34.233" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4107" PostTypeId="2" ParentId="4104" CreationDate="2016-10-09T05:50:01.477" Score="1" Body="&lt;pre&gt;&lt;code&gt;float3 DirectDiffuseBRDF(float3 diffuseAlbedo, float nDotL)&#xA;{&#xA;    return (diffuseAlbedo * nDotL);&#xA;}&#xA;&#xA;float4 PS(VS_OUTPUT input) : SV_TARGET&#xA;{&#xA;    input.normal = normalize(input.normal);&#xA;&#xA;    float4 diffuseAlbedo = ObjTexture.Sample(ObjSamplerState, input.TexCoord);&#xA;&#xA;    float nDotL = dot(input.normal, light.dir);&#xA;&#xA;    float3 diffuseLighting = diffuseAlbedo * light.ambient * light.diffuse;&#xA;&#xA;    diffuseLighting += saturate(DirectDiffuseBRDF(diffuseAlbedo, nDotL);&#xA;&#xA;    return float4(diffuseLighting, diffuseAlbedo.a);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This seemed to have fixed it. I was forgetting to multiply my Ambient light. &lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2016-10-09T10:05:42.927" LastActivityDate="2016-10-09T10:05:42.927" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4108" PostTypeId="2" ParentId="4078" CreationDate="2016-10-09T10:48:16.933" Score="1" Body="&lt;p&gt;Quick idea:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;render platforms color to screen quad&lt;/li&gt;&#xA;&lt;li&gt;render mesh and platforms to screen quad, but as a mask. For example mesh is white, rest is black. &lt;/li&gt;&#xA;&lt;li&gt;in another pass sample these textures and if mask is white, color it with sample from first texture. Render to screen.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2016-10-09T10:48:16.933" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4109" PostTypeId="1" AcceptedAnswerId="4118" CreationDate="2016-10-09T15:27:33.083" Score="3" ViewCount="520" Body="&lt;p&gt;I'm currently writing a software renderer. I managed to implement texture mapping and it works fine. Only issue is, that the edges between the pixels are sometimes jagged in x direction as you can see here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/v9Mf6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v9Mf6.png&quot; alt=&quot;example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could this be caused by a lack of precision? If so, how can I improve it?&#xA;What I'm doing is simply stepping along the edges of a triangle and interpolating the UVs for each scanline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;Here's my code for edge stepping and drawing of scanlines. The Edge class has a method step which increments the interpolants for each scanline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;edge.h&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;Edge(const Vertex&amp;amp; minY, const Vertex&amp;amp; maxY){&#xA;    float dy = maxY.position.y - minY.position.y;&#xA;&#xA;    yStart = static_cast&amp;lt;int&amp;gt;(ceil(minY.position.y));&#xA;    yEnd = static_cast&amp;lt;int&amp;gt;(ceil(maxY.position.y));&#xA;&#xA;    float prestep = yStart - minY.position.y;&#xA;&#xA;    xStep = (maxY.position.x - minY.position.x) / dy;&#xA;    x = minY.position.x + xStep * prestep;&#xA;&#xA;    wStep = (1.0f / maxY.position.w - 1.0f / minY.position.w) / dy;&#xA;    w = 1.0f / minY.position.w + wStep * prestep;&#xA;&#xA;    texCoordsStep = (maxY.textureCoordinates / maxY.position.w - minY.textureCoordinates / minY.position.w) / dy;&#xA;    texCoords = minY.textureCoordinates / minY.position.w + texCoordsStep * prestep;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;renderTarget.cpp&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;void RenderTarget::DrawScanLine(const Edge&amp;amp; left, const Edge&amp;amp; right, int y){&#xA;    int xStart = static_cast&amp;lt;int&amp;gt;(ceil(left.GetCurX()));&#xA;    int xEnd = static_cast&amp;lt;int&amp;gt;(ceil(right.GetCurX()));&#xA;    float dx = static_cast&amp;lt;float&amp;gt;(xEnd - xStart);&#xA;    float prestep = xStart - left.GetCurX();&#xA;&#xA;    float w = left.GetCurW();&#xA;    float wStep = (right.GetCurW() - w) / dx;&#xA;&#xA;    glm::vec2 texCoordsStep = (right.GetCurTexCoords() - left.GetCurTexCoords()) / dx;&#xA;    glm::vec2 texCoords = left.GetCurTexCoords() + texCoordsStep * prestep;&#xA;&#xA;    Uint32* p = pixels + xStart + y * surface-&amp;gt;w;&#xA;&#xA;    for(int x = xStart; x &amp;lt; xEnd; x++){&#xA;        float z = 1.0f / w;  //value for perspective correction&#xA;        int s = static_cast&amp;lt;int&amp;gt;(texCoords.s * z * texture-&amp;gt;surface-&amp;gt;w) &amp;amp; texture-&amp;gt;surface-&amp;gt;w - 1;&#xA;        int t = static_cast&amp;lt;int&amp;gt;(texCoords.t * z * texture-&amp;gt;surface-&amp;gt;h) &amp;amp; texture-&amp;gt;surface-&amp;gt;h - 1;&#xA;&#xA;        *p = texture-&amp;gt;pixels[s + t * texture-&amp;gt;surface-&amp;gt;w];  //copying the texture's pixel to the framebuffer&#xA;        p++;&#xA;        w += wStep;&#xA;        texCoords += texCoordsStep;&#xA;        color += colorStep;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4571" LastEditorUserId="4571" LastEditDate="2016-10-10T20:52:11.337" LastActivityDate="2017-01-09T09:41:49.727" Title="Texture Mapping jagged pixel edges" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;mapping&gt;" AnswerCount="2" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4110" PostTypeId="1" AcceptedAnswerId="4113" CreationDate="2016-10-10T09:42:13.847" Score="8" ViewCount="1546" Body="&lt;p&gt;Ideal specular reflection is like a perfect mirror. I'm looking at the code to &lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot;&gt;SmallPt&lt;/a&gt; and see that one of the spheres has an ideal specular material:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Sphere spheres[] = {//Scene: radius, position, emission, color, material &#xA;   / ...&#xA;   Sphere(16.5,Vec(27,16.5,47),       Vec(),Vec(1,1,1)*.999, SPEC),//Mirr&#xA;   / ...&#xA; };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In the radiance calculation, this happens:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  } else if (obj.refl == SPEC)            // Ideal SPECULAR reflection &#xA;     return obj.e + f.mult(radiance(Ray(x,r.d-n*2*n.dot(r.d)),depth,Xi)); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;f&lt;/code&gt; is the object colour of &lt;code&gt;Vec(.999,.999,.999)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was surprised to see colour multiplication here. Doesn't an ideal mirror have no colour? I guess as &lt;code&gt;f&lt;/code&gt; is &lt;code&gt;Vec(.999,.999,.999)&lt;/code&gt;, effectively it's passing through the colour almost unchanged? Any thoughts on why .999 was used and not 1? I'm guessing this is something to do modelling a miniscule energy loss?&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2016-10-10T14:47:30.623" Title="Should ideal specular multiply light colour with material colour?" Tags="&lt;raytracing&gt;&lt;specular&gt;" AnswerCount="4" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4111" PostTypeId="2" ParentId="4110" CreationDate="2016-10-10T13:10:59.947" Score="5" Body="&lt;p&gt;The specular of metals is a product of the light color and the albedo of the material. Only for non-metals is the color of the specular independent of the albedo, but it's also rather dim. A perfect mirror would therefore be a perfectly smooth metallic surface with an albedo of 1. So, you could say such a mirror would be white, rather than having no color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A more realistic mirror would use something like silver for coating, with an albedo of (0.972, 0.960, 0.915). This color represents the percentage of the light of each frequency that is reflected by silver, so it needs to be multiplied with the color of the reflected light.&lt;/p&gt;&#xA;" OwnerUserId="3470" LastActivityDate="2016-10-10T13:10:59.947" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4112" PostTypeId="2" ParentId="4110" CreationDate="2016-10-10T13:13:55.717" Score="3" Body="&lt;p&gt;Ideal mirrors are just that, ideal. The question if or not it has color never comes to play, its ideal it reflects everything. Like division by zero it is undefined. However, that does not mean you could not multiply your result by one its still the same result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that we have succesfully mixed the concepts of intensity and color together. We simply assume in RGB that color is 3 independent intensities. Which is not at all true, its quite an simplification of how reality works. There really is such thing as a highly intense dark orange that RGB can not account for. So as such its hard to tell since we are conflating two independent things as one. But yes probably some energy being removed for reason unknown in that code.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-10-10T13:13:55.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4113" PostTypeId="2" ParentId="4110" CreationDate="2016-10-10T14:20:03.860" Score="8" Body="&lt;p&gt;What &quot;ideal&quot; means in this context is that there is no divergence in the direction of light reflection vectors (i.e. no roughness) but that they are all considered to be perfect reflections from an &lt;a href=&quot;https://en.wikipedia.org/wiki/Optical_flat&quot; rel=&quot;noreferrer&quot;&gt;optical flat&lt;/a&gt; surface. However, even for optical flat surfaces &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;noreferrer&quot;&gt;Fresnel equation&lt;/a&gt; is still applied in BRDF evaluation that changes specular reflection and is potentially wavelength dependent, which is a common characteristic with metals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RkpTZ.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RkpTZ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in smallPt there's no Fresnel approximation (e.g. &lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick%27s_approximation&quot; rel=&quot;noreferrer&quot;&gt;Schlick's approximation&lt;/a&gt;) but the surface reflectance is simply multiplied with constant term which is wrong. Also 0.999 specular albedo is very high for any real material. Below is a table of specular reflectange of various metals &amp;amp; dielectrics at normal incidence for reference:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q73nz.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q73nz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-10T14:20:03.860" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4114" PostTypeId="2" ParentId="4110" CreationDate="2016-10-10T14:47:30.623" Score="5" Body="&lt;p&gt;In this context, &quot;perfect mirror&quot; refers to a perfectly flat surface with a 0% (pure black) diffuse color. It is still possible though to have a specular color: for example a Christmas tree ball behaves like a perfect mirror, but still tints the reflection. If you replace the 99% white color with a red tint, you will get the red Christmas ball look.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In &lt;em&gt;SmallPT&lt;/em&gt;, spheres have two colors: &lt;code&gt;e&lt;/code&gt; the emissive color and &lt;code&gt;c&lt;/code&gt;. The trick is that &lt;code&gt;c&lt;/code&gt; has two different meanings which depend on the material type &lt;code&gt;refl&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;When &lt;code&gt;refl&lt;/code&gt; is &lt;code&gt;DIFF&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt; is interpreted as the diffuse color.&lt;/li&gt;&#xA;&lt;li&gt;When &lt;code&gt;refl&lt;/code&gt; is &lt;code&gt;SPEC&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt; is interpreted as the specular color.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So in the case #2, the diffuse is left out, which is equivalent to a 0%, pure black, diffuse color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case you haven't checked it already, this presentation is an excellent code explanation of &lt;em&gt;SmallPT&lt;/em&gt;, dense but thorough: &lt;a href=&quot;https://drive.google.com/file/d/0B8g97JkuSSBwUENiWTJXeGtTOHFmSm51UC01YWtCZw/view&quot;&gt;&lt;em&gt;smallpt: Global Illumination in 99 lines of C++&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2016-10-10T14:47:30.623" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4115" PostTypeId="1" AcceptedAnswerId="4120" CreationDate="2016-10-10T19:05:58.850" Score="6" ViewCount="3434" Body="&lt;p&gt;It's common knowledge that branching in a GPU program is costly because it may have to run both the if and else logic for every pixel being evaluated in the same wave, but only applying each result to the appropriate pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was curious if branching was still a performance issue if there is only an if statement and no else statement?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, it seems like it has the ability to be faster compared to branchless logic, for the case when no pixels need to do the work inside the if statement, and can instead skip past it as a group.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this true?  Are there any other downsides? like perhaps older video cards still doing the if logic anyways, even though no pixels evaluate to true?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-12T04:32:58.580" Title="GPU branching if without else" Tags="&lt;gpgpu&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4116" PostTypeId="1" CreationDate="2016-10-10T22:36:53.850" Score="4" ViewCount="134" Body="&lt;p&gt;In general, I understand the creation of viewing transformation matrix, but I have my doubts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, let's say that a world coordinate (called $A$) has a center at $(1,1,1)$, and the view reference point (VRP) (called $B$) has a center at $(3,3,2)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each vertex of the world must be &quot;mapped&quot; to $B$. The axes of $A$ and $B$ aren't aligned so a translation isn't enough, but there are two necessary rotations (around $x$ and $y$ of two certain angles).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know if I am proceeding in a correct way. For overlapping the axes from $A$ to $B$ these are the following steps:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;translate (transformation $T$) with translation parameters $(2,2,1)$, namely $(3-1,3-1,2-1)$&lt;/li&gt;&#xA;&lt;li&gt;rotation around $x$ (transformation $R_x$)&lt;/li&gt;&#xA;&lt;li&gt;rotation around $y$ (transformation $R_y$)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Thus, the transformation is:&#xA;$R_yR_xT$ when $T$ is the first matrix which must be applied. Thus, the transformation to &quot;map&quot; a point of $A$ into the the corresponding point in $B$ coordinates is the inverse namely:&#xA;$(T^{-1})(Rx^{-1})(Ry^{-1})$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main doubt is if it's correct, for converting $A$ and $B$, to do a translation first.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, is this process correct?&lt;/p&gt;&#xA;" OwnerUserId="4981" LastEditorUserId="2707" LastEditDate="2016-10-11T06:45:15.747" LastActivityDate="2016-10-12T16:15:54.320" Title="Correctness of logical steps for create the matrix of viewing transformation" Tags="&lt;rendering&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;matrix&gt;&lt;camera-matrix&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4117" PostTypeId="2" ParentId="4115" CreationDate="2016-10-11T02:36:57.870" Score="5" Body="&lt;h1&gt;Old Hardware&lt;/h1&gt;&#xA;&lt;p&gt;Some older cards didn't used to jump instructions in warps, so this was indeed an issue. If you have a conditional with these cards, the inside logic of the conditional would still be evaluated even if the block wasn't entered by any of the pixels, vertices, etc. There's little you can do in this case because every instruction will be executed. The worst case is also the best case here.&lt;/p&gt;&#xA;&lt;h1&gt;Modern Hardware&lt;/h1&gt;&#xA;&lt;p&gt;However, if you are working with relatively modern hardware though, this isn't an issue and &amp;quot;if/else&amp;quot; blocks will be skipped when necessary. There really shouldn't be a downside to using &amp;quot;if/else&amp;quot; blocks compared to not using them. You are still branching with an &amp;quot;else&amp;quot;-less statement. In fact, some post-processing effects/deferred rendering specifically benefit from this.&lt;/p&gt;&#xA;&lt;p&gt;The worst case scenario is that some threads go through the &amp;quot;if&amp;quot; block and the rest go through the &amp;quot;else&amp;quot; block. The best case scenario is that all go through the &amp;quot;if&amp;quot; block or the &amp;quot;else&amp;quot; block. There isn't a downside to using &amp;quot;if/else&amp;quot; conditionals as they are needed (either on old hardware or newer hardware), but there's a possible upside with newer hardware.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-10-12T04:32:58.580" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4118" PostTypeId="2" ParentId="4109" CreationDate="2016-10-11T11:52:18.917" Score="2" Body="&lt;p&gt;I strongly suspect that you are simply running out of floating point precision (at least in &quot;U&quot; dimension). With this sort of mathematics, the LSBs will soon become noisy resulting in the jagged appearance when you are (effectively) doing yes/no comparisons against known constants.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;May I suggest instead that, rather than doing point sampling of your texture, try doing (at the very least) bilinear filtering which will hide the precision artefacts and also IMHO look better than having little squares.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt; It just occurred to me that one of the possible causes of inaccuracy is that you are doing increments for each pixel X step, e.g. these two&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;w  += wStep;&#xA;texCoords += texCoordsStep;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;These will soon cause errors to accumulate. Remove them and replace with multiplies by the X value and I expect things should improve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE2&lt;/strong&gt; It will also be affected by how far away from the origin of the texture you are when you sample it. If, for example, your source texture is defined over [0..1]x[0..1] and then repeats outside of that range, you might expect sampling  at uv = (1000000.125, 100000.125) to be the same as (0.125,0.125) but, because the precision of FP decreases with increasing magnitude (i.e. the steps between floats also increases), you might end up with something quite different.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2016-10-12T14:52:27.147" LastActivityDate="2016-10-12T14:52:27.147" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4119" PostTypeId="2" ParentId="4116" CreationDate="2016-10-11T13:30:40.063" Score="2" Body="&lt;p&gt;I'm assuming you mean $A$ is object$\rightarrow$world matrix and $B$ is your camera$\rightarrow$world matrix? If that's the case, to calculate object object$\rightarrow$camera matrix you calculate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$C=B^{-1}*A$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general your math is correct, i.e. the order of matrix multiplication is reversed for the inverse calculation. It's just that normally these transformations are combined to a single 4x4 transformation matrix which does rotation, scaling and translation, and then you just work with that single matrix instead of it being decomposed to separate rotation &amp;amp; translation matrices. Anyway, if you want to decompose the matrix multiplication, based on the above you would do:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$A=T_A*Ry_A*Rx_A$$&#xA;$$B=T_B*Ry_B*Rx_B$$&#xA;$$C=Rx_B^{-1}*Ry_B^{-1}*T_B^{-1}*T_A*Ry_A*Rx_A$$&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-10-11T13:35:54.813" LastActivityDate="2016-10-11T13:35:54.813" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4120" PostTypeId="2" ParentId="4115" CreationDate="2016-10-11T18:23:32.030" Score="4" Body="&lt;p&gt;If there is no divergence (i.e. all threads in a wave take the same branch) newer GPU's can skip all the work within the if-branch. If there's divergence, then code in both branches is executed, but thread execution mask basically defines which threads execute code in which branch (code in non-executed branches for threads are effectively NOPed out). This is basically the same as predicated branching but happens dynamically based on divergence.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On GCN architecture at least the branching itself is basically free or at least very cheap (handled by a separate unit running parallel to ALU for example), but something to keep in mind is that branching also tends to increase GPR pressure, which in turn lowers the occupancy. Low occupancy means there can be less threads in flight at once which influences GPU's ability to hide memory latencies. This may or may not be an issue in your shaders depending on how they access memory, i.e. you should see performance increase along with increased occupancy in shaders with heavy memory access.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it's still good to optimize out branching where reasonable, but I think it's one of the things good left to the optimization stage where you need to squeeze max performance out of your shaders.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-11T18:23:32.030" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4121" PostTypeId="1" CreationDate="2016-10-12T10:05:55.373" Score="1" ViewCount="58" Body="&lt;p&gt;How to create PNG files optimized for being compression-friendly? I.e. would it help if image is created (mostly) from 8x8 unicolor blocks?&lt;/p&gt;&#xA;" OwnerUserId="5285" LastEditorUserId="5285" LastEditDate="2016-10-12T10:55:45.823" LastActivityDate="2016-10-12T12:58:21.843" Title="Compression-friendly PNG files" Tags="&lt;image-processing&gt;&lt;image&gt;&lt;compression&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4122" PostTypeId="2" ParentId="4116" CreationDate="2016-10-12T12:13:24.057" Score="2" Body="&lt;p&gt;I would like to address an issue in your naming. This issue makes the question a bit odd, but not impossible, as I will try to show.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is an, often unspoken, implied relationship between the matrices. For a matrix to be meaningful there has to be a common ancestor of the matrix that all matrices relate to. See a transformation chain works like a disk system or the root node of a XML document. There is always a base node, in computer graphics texts we choose to call this node &lt;strong&gt;World&lt;/strong&gt;*. Calling something else world is just defining your own definition of things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lF8WK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lF8WK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: The implied hierarchy of matrices, we have agreed to name the root &lt;strong&gt;World&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now there is assumed to be nothing outside the world. Although just like zeroes before numbers there is a possibility of infinite worlds within worlds, but those extra worlds do not participate in our model so they hardly matter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The hierarchy determines how the matrices interact with each other. All matrices are identity matrices ($I$) when viewed from inside the object. Therefore we have the following property for world:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$T_{world} = I.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anything else would imply that World is not World but rather an object as &lt;a href=&quot;https://computergraphics.stackexchange.com/a/4119/38&quot;&gt;@JarkkoL's answer&lt;/a&gt; implies, so there is yet another World outside what you call World. Also because world is the identity it can be omitted from your calculations, which is why it's sometimes left unnamed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now it is obviously possible to name objects. This is smart as it makes talking about things easier. So you could call a bicycle object object &quot;bicycle&quot;, makes sense. In fact we do this by calling the camera, &quot;Camera&quot;. These names are arbitrary, so it is possible to call an object space World. But then the discussion just drops into confusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we can address the confusion as your description is ambiguous. This is also is why you have problems reasoning about this. So either what you describe is like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ysBhE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ysBhE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Since you have renamed World we do not know what your relationship is. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So by reinventing naming convention you have made the question confused. If you had not then there would be a really easy rule you would append the multiplication as normal as long as you move towards the world and inverted if you move away from the world.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* There are traditions where this is called the &lt;em&gt;Inertial frame&lt;/em&gt;, &lt;em&gt;Reference Frame&lt;/em&gt; and even sometimes rarely &lt;em&gt;Base&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-10-12T16:15:54.320" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4123" PostTypeId="2" ParentId="4121" CreationDate="2016-10-12T12:58:21.843" Score="2" Body="&lt;p&gt;PNG format is lossless format where for compression the image is first &quot;filtered&quot; and this filtered image is then passed to &lt;a href=&quot;https://en.wikipedia.org/wiki/DEFLATE&quot; rel=&quot;nofollow&quot;&gt;DEFLATE&lt;/a&gt; lossless compression algorithm. The purpose of filtering stage is to make the image more compressible by DEFLATE and current method uses delta-compression from previously decoded pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if your plan is to pre-process the image in some lossy way, then if you can reduce the deltas so that the following entropy encoding can benefit from it, then you get better compression ratio. For example &quot;blockifying&quot; the image as you suggested would only require more storage for the top-left pixel in the block while the deltas for the remaining pixels would be zero, which DEFLATE can compress very efficiently. This same would apply to any continuous constant color regions.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-12T12:58:21.843" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4124" PostTypeId="2" ParentId="3963" CreationDate="2016-10-12T13:29:42.360" Score="1" Body="&lt;p&gt;You can look into &lt;a href=&quot;https://github.com/huwb/volsample&quot; rel=&quot;nofollow&quot;&gt;alias-free volumetric sampling algorithm&lt;/a&gt; by Huw Bowles for potential solution to the ray marching aliasing issues. The basic idea is to snap your samples to planes based on the ray direction that's best explained with &lt;a href=&quot;https://www.shadertoy.com/view/ll3GWs&quot; rel=&quot;nofollow&quot;&gt;this Shadertoy demo&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-12T13:29:42.360" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4125" PostTypeId="1" AcceptedAnswerId="4126" CreationDate="2016-10-12T20:35:09.033" Score="6" ViewCount="3078" Body="&lt;p&gt;I have read through &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;noreferrer&quot;&gt;this article&lt;/a&gt; about perspective and orthographic projection matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I started playing with the perspective matrix and as expected if I either increase/decrease the field of view i have a zoom out/in effect. Similarly, if I move the camera position forward/backwards I see the object being close or further away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when I tried the orthographic matrix, since there is no field of view parameter, I tried only moving the camera forward/backwards but my model always looked the same size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anybody explain to me why this is happening?&lt;/p&gt;&#xA;" OwnerUserId="116" LastActivityDate="2016-10-12T22:39:57.350" Title="Zoom in orthographic vs perspective projection" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4126" PostTypeId="2" ParentId="4125" CreationDate="2016-10-12T22:39:57.350" Score="6" Body="&lt;p&gt;Perspective projection changes the size of an object as it's distance changes, while orthographic projection does not.  That is part of the definition of those projection types.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To simplify things a bit, a simple perspective projection of a 3d point to a 2d point can be calculated like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x_{2d} = x/z\\&#xA;y_{2d} = y/z$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the 2d version of the x and y change depending on the value of z.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Orthographic projection on the other hand can be calculated like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x_{2d} = x\\&#xA;y_{2d} = y$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In that example, you can see that the x and y values do not depend at all on z, so you can move closer to or farther away from an object in orthographic projection and it's size will not change.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a fun bit of related trivia, the sun is so far away that when the light gets here, it's all basically going in the same direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a reason why we have directional lighting, where light beams are always moving in the same way, because that is how sun light works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyways, since the light beams are parallel it means that your shadows in sun light are orthographic projections of your silhouette.  In other words, as you move your hand closer to or farther from the sun here on earth, the shadow of your hand doesn't change size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you have a more local light source - light a lamp - it casts a perspective projection type of shadow, where the closer to the light source your hand is, the larger the shadow it casts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is tied to the definition of an orthographic projection, which is that the focal length is infinitely long.  The sun is far enough away that we can consider it infinity in lighting, for as much accuracy as we care about :P&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-12T22:39:57.350" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4128" PostTypeId="1" CreationDate="2016-10-13T07:26:20.423" Score="3" ViewCount="262" Body="&lt;p&gt;I've been playing around with more advanced graphics these days (beyond the basic 2D UI and image effects that the iOS platform offers), and I'm wanting to implement a visual effect similar to how iOS's Siri uses what appears to be a &quot;color nebula&quot; in the background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/0SjS6.jpg&quot; alt=&quot;Siri&amp;#39;s color nebula&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://d3vv6lp55qjaqc.cloudfront.net/items/3K2V3b1I1p1V2d231J0r/video.mov?X-CloudApp-Visitor-Id=216938&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here's a video of it in action.&lt;/a&gt; Seeing it animated is pretty important given that it's a dynamic effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Over time, the colors and intensity change, and various areas bloom and fade colors in. It's very subtle and has this ambient feel to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, I'm working in SceneKit, Apple's 3D scene composition API, and it has access to anything from Core Image to OpenGL to Metal as far as shaders and filtering geometries. So I'm curious if there is a general purpose algorithm for this kind of a) color effect (changing hue and other properties) and b) the slow, nebulous way colors come in and out and move around.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What techniques can one employ to pull of this animated visual effect?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd also love to read any additional resources about various ways to use colors and blending in graphics to achieve interesting effects.&lt;/p&gt;&#xA;" OwnerDisplayName="user5291" LastActivityDate="2016-10-14T06:52:51.240" Title="What graphics techniques can be used to simulate a color nebula effect?" Tags="&lt;shader&gt;&lt;color&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4129" PostTypeId="2" ParentId="4128" CreationDate="2016-10-13T09:09:29.750" Score="3" Body="&lt;p&gt;I have no knowledge of SceneKit whatsoever, but the effect appears to be a simple post-process Gaussian blur of the app icon grid, with the blur radius increasing over time (i.e. increasing the blur amount) during the transition, with a touch of colour correction tacked on (which causes the darkening). It should be easy enough to implement in any graphics API that allows rendering to textures and performing image filtering on them (for instance, in OpenGL you could use framebuffer objects to achieve this).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can have a look at an example WebGL implementation &lt;a href=&quot;https://github.com/Jam3/glsl-fast-gaussian-blur/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. It's worth noting that it is a separable filter; meaning, it's a rectangle-shaped filter, but you can avoid sampling the same pixels (overlapping neighbouring samples) multiple times by splitting it into two passes – a horizontal and a vertical one – to the same effect.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastEditorUserId="2817" LastEditDate="2016-10-14T06:52:51.240" LastActivityDate="2016-10-14T06:52:51.240" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4130" PostTypeId="1" AcceptedAnswerId="4131" CreationDate="2016-10-13T18:00:21.427" Score="4" ViewCount="755" Body="&lt;p&gt;I'm brand new to OpenGL and graphics programming in general, and I'm trying to figure out what software I need to program a GPU.  I saw an &lt;a href=&quot;https://developer.nvidia.com/opengl-driver&quot; rel=&quot;noreferrer&quot;&gt;NVidia OpenGL driver&lt;/a&gt;, and I've also seen reference to the OpenGL SDK.  My understanding (sort of) is that the OpenGL driver is essentially an API that hides the differences between different GPUs and the OpenGL API works on top of that.  I really have no idea though.&lt;/p&gt;&#xA;" OwnerUserId="5293" LastActivityDate="2016-10-13T21:18:39.047" Title="What is the difference and/or relationship between the OpenGL SDK and the OpenGL GPU driver?" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;driver&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4131" PostTypeId="2" ParentId="4130" CreationDate="2016-10-13T21:18:39.047" Score="3" Body="&lt;p&gt;I wouldn't really call it OpenGL SDK but OpenGL API. There's a common OpenGL API which is basically a set of functions you can call to control the GPU. This API is hardware agnostic (barring extensions), so you can use it on NVIDIA, ATI, etc. GPU's.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What the OpenGL driver does is to turn these platform agnostic function calls to hardware specific commands that the driver then sends to the GPU. For example when you tell GPU to draw a triangle via OpenGL API, then the driver converts these calls under the hood to specific commands for the specific GPU you are using. This abstraction is important so that you don't have to write different code for every GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To explain things a bit in lower level, the graphics API implementation operates in user mode, while the graphics driver operates in kernel mode. User mode is &quot;protected&quot; mode your program runs in, in the sense that you can't mess up your entire device but only your own app and it's also relatively fast to perform the API function calls in this mode. Kernel mode on the other hand is &quot;unprotected&quot; and performing kernel mode calls requires an expensive mode switch. For OpenGL the IHV's provide both the OpenGL API and driver implementations and thus IHV's can provide optimal switching between the modes. This is in contrast to DirectX where API implementation is provided by Microsoft and the driver by IHV's.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-13T21:18:39.047" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4132" PostTypeId="1" AcceptedAnswerId="4134" CreationDate="2016-10-14T06:29:06.383" Score="2" ViewCount="875" Body="&lt;p&gt;So I have recently learned about Bezier Curves (quadratic &amp;amp; cubic) and have a thorough knowledge of how they work. In my graphics engine in DirectX I wanted to implement a Bezier Curve Tool exactly like the Pen Tool in Adobe Illustrator. I understand the basic computation of the curve but I am puzzled as to how I can get mouse interaction involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Basically I'd like to draw Bezier Curves with a Mouse.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/96HLA.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/96HLA.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-10-14T13:39:08.980" Title="Bezier Curve Tool Controlled by Mouse" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;line-drawing&gt;&lt;vector-graphics&gt;&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4133" PostTypeId="1" AcceptedAnswerId="4195" CreationDate="2016-10-14T12:03:01.897" Score="7" ViewCount="1255" Body="&lt;p&gt;I am trying to implement the Parallax Refraction effect explained by &lt;strong&gt;Jorge Jimenez&lt;/strong&gt; on this presentation:  &lt;a href=&quot;http://www.iryoku.com/downloads/Next-Generation-Character-Rendering-v6.pptx&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.iryoku.com/downloads/Next-Generation-Character-Rendering-v6.pptx&lt;/a&gt; and I am facing some difficulties. Here is a screenshot of the interesting part.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/a08kE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a08kE.png&quot; alt=&quot;screen&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this document lacks a bit of explanations especially the second part with the &lt;strong&gt;Physically based Refraction&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is what I've achieved for the moment.&lt;br&gt;&#xA;This is the simple &lt;strong&gt;Parallax Refraction&lt;/strong&gt; effect and, as you might notice in the screenshot, there is small glitch at grazing angles in the iris when the Parallax Scale value is too high.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is caused by the parallax calculation but are there some tricks to avoid or minimize such issue ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't want to go deeper with parallax mapping for the moment, so I don't want to use Steep Parallax Mapping or Parallax Occlusion Mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/y1sCY.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/y1sCY.jpg&quot; alt=&quot;eye&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the code. Nothing really special.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// height value comes from a texture&#xA;float2 offset = height * viewDir;&#xA;offset.y = -offset.y;&#xA;texcoord -= ParallaxScale * offset;&#xA;// Next there is the texture sampling with the texcoord value&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I also have another question about the &lt;strong&gt;Physically based Refraction&lt;/strong&gt; part which is not really well explained and I am missing how some values are calculated such as &lt;code&gt;refractedW&lt;/code&gt;, &lt;code&gt;frontNormalW&lt;/code&gt; or &lt;code&gt;heightW&lt;/code&gt;. If anyone could provide some explanations about those values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2016-10-28T07:59:48.507" Title="Eye Parallax Refraction" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;glsl&gt;&lt;hlsl&gt;&lt;refraction&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4134" PostTypeId="2" ParentId="4132" CreationDate="2016-10-14T13:39:08.980" Score="4" Body="&lt;p&gt;Instead of using cubic Bezier spline, you should use &lt;a href=&quot;https://en.wikipedia.org/wiki/Cubic_Hermite_spline&quot; rel=&quot;nofollow&quot;&gt;cubic Hermite spline&lt;/a&gt;. For cubic Hermite curve you specify the segment end points and tangents, which is what you then control in the tool. Hermite spline is almost the same as Bezier spline but with different $B$ matrix, so if you already understand Bezier, then understanding Hermite is a trivial step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in the Adobe Illustrator pen tool (which based on the video I take is the same as Adobe Photoshop pen tool that I have used) you keep adding more Hermite cubic spline segments to your spline. By default the Hermite start tangent matches (with opposite sign) the end tangent of the previous segment and in GUI they are linked together (changing one changes the other). So in that configuration the curve appears smooth. However, you can unlink the tangents to cause C1 discontinuity in the spline and control them separately. This is purely GUI work though and how you control the Hermite spline tangents &amp;amp; positions.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-14T13:39:08.980" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4135" PostTypeId="1" AcceptedAnswerId="4136" CreationDate="2016-10-14T17:57:46.247" Score="3" ViewCount="443" Body="&lt;p&gt;How do you migrate &lt;em&gt;Flexible Vertex Format Constants&lt;/em&gt; (or &lt;em&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/bb172559(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;FVF&lt;/a&gt; codes&lt;/em&gt;) from &lt;em&gt;DirectX 9&lt;/em&gt; to &lt;em&gt;Direct3D 11&lt;/em&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Old code&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;d3dx9.h&amp;gt;&#xA;&#xA;struct Vertex {&#xA;&#xA;public:&#xA;    Vertex() : p(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), n(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}&#xA;    Vertex(D3DXVECTOR3 p, D3DXVECTOR3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}&#xA;&#xA;    // Position of the vertex (in world space)&#xA;    D3DXVECTOR3 p;&#xA;    // Normal of this vertex&#xA;    D3DXVECTOR3 n;&#xA;    // Texture UV coordinates&#xA;    float tu, tv;&#xA;};&#xA;&#xA;// D3DFVF_XYZ: Vertex format includes the position of an untransformed vertex.&#xA;// D3DFVF_NORMAL: Vertex format includes a vertex normal vector.&#xA;// D3DFVF_TEX1: Number of texture coordinate sets for this vertex.&#xA;#define VERTEX_FVF ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )&#xA;#define VERTEX_FVF_SIZE D3DXGetFVFVertexSize( VERTEX_FVF )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;New code&lt;/strong&gt; without &lt;a href=&quot;https://blogs.msdn.microsoft.com/chuckw/2013/08/20/living-without-d3dx/&quot; rel=&quot;noreferrer&quot;&gt;D3DX&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;DirectXMath.h&amp;gt;&#xA;using namespace DirectX;&#xA;&#xA;struct Vertex {&#xA;&#xA;public:&#xA;    Vertex() : p(XMFLOAT3(0.0f, 0.0f, 0.0f)), n(XMFLOAT3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}&#xA;    Vertex(XMFLOAT3 p, XMFLOAT3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}&#xA;&#xA;    // Position of the vertex (in world space)&#xA;    XMFLOAT3 p;&#xA;    // Normal of this vertex&#xA;    XMFLOAT3 n;&#xA;    // Texture UV coordinates&#xA;    float tu, tv;&#xA;};&#xA;&#xA;// ??&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;P.S.: Can someone with enough reputation points create and add a &lt;code&gt;directx9&lt;/code&gt; tag.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2016-10-14T21:20:46.450" Title="Flexible Vertex Format Constants in Direct3D 11" Tags="&lt;c++&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4136" PostTypeId="2" ParentId="4135" CreationDate="2016-10-14T21:20:46.450" Score="2" Body="&lt;p&gt;Vertex formats are specified in D3D11 using the &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ff476512(v=vs.85).aspx&quot; rel=&quot;nofollow&quot;&gt;input layout&lt;/a&gt;. An example input layout description for your vertex might look like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_INPUT_ELEMENT_DESC aInputDescs[] =&#xA;{&#xA;    { &quot;POSITION&quot;, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, p)), D3D11_INPUT_PER_VERTEX_DATA, 0 },&#xA;    { &quot;NORMAL&quot;, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, n)), D3D11_INPUT_PER_VERTEX_DATA, 0 },&#xA;    { &quot;UV&quot;, 0, DXGI_FORMAT_R32G32_FLOAT, 0, UINT(offsetof(Vertex, tu)), D3D11_INPUT_PER_VERTEX_DATA, 0 },&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-10-14T21:20:46.450" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4137" PostTypeId="1" AcceptedAnswerId="4138" CreationDate="2016-10-15T13:13:56.173" Score="0" ViewCount="877" Body="&lt;p&gt;So recently after implementing PBR in my engine, I was wondering what are some new &amp;amp; old  Rendering Techniques that people are implementing and researching to get Real Time Graphics closer to what things look like in real life? A list of things that come to my mind were:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Physically Based Rendering/Lighting&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Dynamic Reflections&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Shadow Mapping (also PCSS)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Ambient Occlusion (SSAO, HBAO)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Bloom &amp;amp; HDR&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Depth of Field&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Lens Flares&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Motion Blur&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Particle Effects (Fog, Fire)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are some other techniques that are being used in very graphically demanding games like Battlefield 1, Star Wars: Battlefront, Assassins Creed Unity &amp;amp; other such games. The past few years PBR has been the biggest thing for the gaming industry, are there any new things like that 'on the rise'?   &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-10-15T15:22:39.140" Title="What are some new Real-Time Graphics Rendering Techniques to get closer to real life?" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;physically-based&gt;&lt;shadow&gt;&lt;ambient-occlusion&gt;" AnswerCount="1" CommentCount="0" ClosedDate="2016-11-02T02:45:50.787" ContentLicense="CC BY-SA 3.0" />
  <row Id="4138" PostTypeId="2" ParentId="4137" CreationDate="2016-10-15T15:22:39.140" Score="6" Body="&lt;p&gt;PBR isn't just a feature you &quot;add to a rendering engine&quot; but an entire philosophy how to approach solving rendering problems. This seems to be a common prevailing misconception when people talk about PBR. Quite often people assume that when they have implemented physically based BRDF (e.g. GGX) into their engines, they are &quot;done implementing PBR&quot;. They are not - they are barely getting started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's take some of the topics you list and how do you approach implementing them in the &quot;physically based&quot; way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depth of Field, Lens Flares, Motion Blur and Bloom &amp;amp; HDR for example. For years these effects have been implemented and slapped as post effect on the screen with some adhoc factors exposed to artists. However, as you know these are effects happening in the camera system and they should be exposed and implemented considering how the light interacts with this system. How camera aperture, shutter speed, ISO, camera sensor and lense system influence the effects and how they should be implemented and controlled considering these physical characteristics of the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This same principle applies to all the aspects of rendering when you go PBR. For example shadows you mention, how would you implement shadows in physically based way? First of all you would have to consider all lights as area light sources as opposed to infinitesimally small lights that people have been doing for ages. Recently there has been push to implement physically based area lights in real-time which is an important step towards more complete PBR, but they are completely omitting proper area shadowing. This is a difficult problem in real-time rendering and there has been only little research done in the area of area shadows. &quot;&lt;a href=&quot;http://www.geomerics.com/wp-content/uploads/2014/03/AltDevConf-SamMartin-RealTimeAreaLighting.pdf&quot;&gt;Real Time Area Lighting - Now and Next&lt;/a&gt;&quot; by Sam Martin is a good thing to read if you are interested in the topic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Talking about dynamic reflections or lighting in general. How should all the different lighting techniques such as SSLR, local/global environment maps, (textured) area lights, SSAO, GI, etc. be implemented and integrated together to form a cohesive lighting system? That you doesn't do double counting and that they are properly accounted in diffuse and specular lighting calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When implementing real-time PBR algorithms, you will eventually have to introduce some bias due to performance constraints and resort to some kind of approximations. But the important thing is that you know what the real result should be and are aware of the compromises you are making. PBR is a paradigm shift from the classic artistic observation-based real-time rendering algorithm development towards more scientific way of solving the rendering problems and this shift in mentality and the direction it pushes you helps you to get more realistic results in the end.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-15T15:22:39.140" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4139" PostTypeId="1" AcceptedAnswerId="4141" CreationDate="2016-10-15T16:54:38.477" Score="7" ViewCount="2605" Body="&lt;p&gt;So after reading &lt;a href=&quot;https://www.guerrilla-games.com/read/killzone-shadow-fall-creating-art-tools-for-a-new-generation&quot;&gt;https://www.guerrilla-games.com/read/killzone-shadow-fall-creating-art-tools-for-a-new-generation&lt;/a&gt; (a guerilla games presentation on PBR) I noticed the Area lights as opposed to the standard Directional, Point &amp;amp; Spot lights in DirectX can produce very realistic shadows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now a lot of the resources online talk about it and what it is but there's not much regarding implementation. Some websites online say that it is just an array of lights but I don't think that's what it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can somebody explain how I can implement this (and maybe with some code). If you could include any links to some good resources regarding implementation that would be great aswell. &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2020-12-30T06:23:59.403" Title="Physically Based Area Lights" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;physically-based&gt;&lt;directx11&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4141" PostTypeId="2" ParentId="4139" CreationDate="2016-10-16T14:34:20.807" Score="9" Body="&lt;p&gt;When I implemented real-time area lighting, there were two documents I kept referring to: &amp;quot;&lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moving Frostbite to PBR&lt;/a&gt;&amp;quot; by Sebastien Lagarde and &amp;quot;&lt;a href=&quot;https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real Shading in Unreal Engine 4&lt;/a&gt;&amp;quot; by Brian Karis. Also &amp;quot;&lt;a href=&quot;https://www.guerrilla-games.com/read/killzone-shadow-fall-creating-art-tools-for-a-new-generation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lighting of Killzone Shadow Fall&lt;/a&gt;&amp;quot; by Michal Drobot is an interesting read on the topic. None of these documents deal with area shadows though but focus on energy conserving approximation of the lighting integral. While there are some code snippets, these documents lack quite a bit of details of how to implement area lighting though, so you need to do fair amount of research on your own. For example I posted a question and an answer &lt;a href=&quot;https://math.stackexchange.com/questions/1438242/finding-ray-direction-with-smallest-angle-from-a-ray-to-a-rectangle-in-3d&quot;&gt;here&lt;/a&gt; related to implementing rectangular area lights.&lt;/p&gt;&#xA;&lt;p&gt;A very valuable tool I used was to implement a Monte Carlo reference model to easily compare different approximations to the ground truth. Some people also use &lt;a href=&quot;http://www.mitsuba-renderer.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitsuba renderer&lt;/a&gt; to validate their implementations. I think this ground truth reference is extremely important so that you know if there are mistakes in your implementation and also to see where/how these approximations fail and if you can somehow try to improve them. Implementing Monte Carlo integration is also quite a good exercise to understand the underlying problem.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="15262" LastEditDate="2020-12-16T17:52:25.930" LastActivityDate="2020-12-16T17:52:25.930" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="4142" PostTypeId="1" AcceptedAnswerId="4143" CreationDate="2016-10-16T18:58:35.857" Score="5" ViewCount="768" Body="&lt;p&gt;I'm not sure if this question is on-topic or not, based on the tour. Feel free to point me elsewhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The short version of the question is: what's the typical technique for generating the clean-plate for footage in which the camera moves?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More detail:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's easy to understand how computer graphics are superimposed over live footage to cover existing elements (like an actor in green pajamas). For example, it seems easy for the CG version of the Hulk to completely cover Mark Ruffalo without having to replace anything real that wasn't already visible in the shot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also easy to understand where this comes from for footage where the camera doesn't move. With a locked-off shot it's not hard to get a shot without any of the actors/props or whatever is being replaced (a clean-plate, as it were), and match that to the real take.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I'm baffled about non-locked-off shots. A good example might be a scene from Star Trek: First Contact when the Borg Queen is introduced. The upper half of her body is lowered onto a lower-half kind of rig. Whether the actress is actually lowered or not, there is background behind either her invisible real body, as she's lowered, or behind her invisible upper body as it's being rotoscoped down into position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either way, they had to have &lt;em&gt;something&lt;/em&gt; to show behind the parts of the actress that weren't supposed to be there in the final footage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One theory I've imagined is that they run the camera through the shot first without the actors, and then repeat the shot with the actors, but this seems prohibitively prone to imprecision. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another theory is that they get the clean plate from another frame in the same footage, but this seems like it'd only work in very specific cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also seen tutorials in which the trick is that the shot IS locked-off, and the camera shake is added in after the composite. But again, this only works for certain kinds of shots, and I have a hard time believing that this is the way it's done for everything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What is/are the typical technique(s) for generating a clean plate for footage in which the camera moves?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="4494" LastActivityDate="2019-09-18T03:46:50.880" Title="How to get clean plate from moving footage?" Tags="&lt;compositing&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4143" PostTypeId="2" ParentId="4142" CreationDate="2016-10-17T05:22:45.560" Score="5" Body="&lt;p&gt;There are a couple of techniques:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;A &lt;a href=&quot;https://en.wikipedia.org/wiki/Motion_control_photography&quot;&gt;motion controlled camera&lt;/a&gt; - The camera is on some sort of rig connected to a computer. The computer is programmed to move the camera in a particular way. The camera runs through the moves without the actors, generating a clean set of plates. Then it is run again with the actors, usually wearing green or blue costumes or parts of costumes. For example, in &quot;Forest Gump,&quot; one character loses his legs in a war. The actor had working legs, as shown early in the movie, and in some later scenes wore blue stockings that were composited out. (They also used other techniques, such as simply hiding his legs under various things in some scenes. Whatever works!)&lt;/li&gt;&#xA;&lt;li&gt;As you surmise, sometimes a larger scene is filmed with a locked-off camera to get a clean plate, then during editing, they zoom into the scene and pan around in software to create the motion you see on screen. This doesn't work well for anything that involves the camera rotating, but can work for scenes where the camera trucks.&lt;/li&gt;&#xA;&lt;li&gt;Parts of the scenery that the actors are in front of are blocked off with green screens and recreated in post. I've seen outtakes of a few pieces where they did this. If you have the DVD of &quot;The Others&quot; with Nicole Kidman, the &quot;DVD Extras&quot; show how fog was added to scenes that were filmed without it. It basically involved someone walking around behind her holding a large green board. Then, they recreated the scenery in the computer, added fog to it, and replaced the green screen with the foggy scene. I have a vague recollection of them doing something similar in the HBO mini-series &lt;a href=&quot;http://www.hbo.com/john-adams&quot;&gt;John Adams&lt;/a&gt;. This would likely involve cameras that record their motion. The motion is then imported into the computer and used to move the virtual camera around the scene they've recreated.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2016-10-17T05:34:42.553" LastActivityDate="2016-10-17T05:34:42.553" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4145" PostTypeId="2" ParentId="4133" CreationDate="2016-10-17T15:49:20.797" Score="0" Body="&lt;p&gt;Here is the way I calculate the refraction vector according to Snell's law.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float cosine = dot(viewDir, worldNormal);&#xA;float sine = sqrt(1 - cosine * cosine);&#xA;&#xA;float sine2 = (_IOR * sine);&#xA;float cosine2 = sqrt(1 - sine2 * sine2);&#xA;&#xA;float3 x = -worldNormal;&#xA;float3 y = normalize(cross(cross(viewDir, worldNormal), worldNormal));&#xA;float3 refractedW = x * cosine2 + y * sine2;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is integrated with the Physically based Refraction and it gives interesting results but I still don't know how to get rid of the high parallax scale issue which appear at grazing angles...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea how to get rig of that ?&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2016-10-17T15:49:20.797" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4146" PostTypeId="1" AcceptedAnswerId="4160" CreationDate="2016-10-17T19:28:15.607" Score="7" ViewCount="2589" Body="&lt;p&gt;Currently I have basic shadow mapping setup in my engine. I am currently trying to implement something more realistic like &lt;strong&gt;PCSS&lt;/strong&gt; (percentage closer soft shadows), to get a more physically accurate result just like the image below. (See how the shadow becomes softer &amp;amp; softer towards the end?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GtMT9.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GtMT9.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My 2 questions are:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; Is it worth implementing a shadow mapping technique like this? &lt;strong&gt;Will people actually notice the difference?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; If it is worth it, what are some resources where I can learn more about it? What are the &lt;strong&gt;major techniques like PCSS?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2020-07-14T16:46:25.173" Title="Better Shadow Mapping Techniques" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;physically-based&gt;&lt;shadow&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4147" PostTypeId="1" CreationDate="2016-10-18T00:21:11.790" Score="6" ViewCount="1021" Body="&lt;p&gt;(Apologies: I am cross-posting from SO, where there is no answer. I figured it might be more appropriate to be on this site.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to build a compute shader in OpenGL to perform a skeletonization algorithm. I've tested the algorithm in a CPU only version, and it was correct there. However, I'm having some trouble porting it to compute shader code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that no matter how many invocations of the compute shader I run, the output never changes past the first invocation. In fact, if I take out the check at the end of the while loop, the program never terminates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have two areas of memory that I use for input and output. I'm trying to do a trick with glBindBufferBase() in the main while loop where I swap the two of them (output of the last round becomes input for the current round). See lines 270 - 318 in main.cpp. This is so I don't copy the data back and forth between the CPU and GPU a bunch of times.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also reworked a version of this to memcpy IMG_1 back to data and then call glBufferData with data. It works correctly, but doing all of these CPU &amp;lt;-&gt; GPU operations seems horribly inefficient. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, my questions are:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Can I do this trick with glBindBuffers, where I swap them around so that I can operate on the data multiple times without moving it back to the CPU? In testing on a smaller problem (just adding short arrays), it worked.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) If the trick is fine, where am I going wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: this code needs a 640 x 400 size .pgm (black and white image) called &quot;test.pgm&quot;. You can make one in GIMP, but be sure to save it as a binary one instead of an ASCII one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This code is compiled with the following flags&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;g++ -g pgm.cpp main.cpp -lglut -lGLU -lGL -lm -lGLEW -o test&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also, forgive me for using C++ but doing C style tricks. I spend more time in C than I do C++.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;main.cpp&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Include standard headers&#xA;#include &amp;lt;stdio.h&amp;gt;&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xA;#include &amp;lt;stdarg.h&amp;gt;&#xA;#include &amp;lt;math.h&amp;gt;&#xA;#include &amp;lt;errno.h&amp;gt;&#xA;&#xA;//For stat&#xA;#include &amp;lt;sys/types.h&amp;gt;&#xA;#include &amp;lt;sys/stat.h&amp;gt;&#xA;#include &amp;lt;unistd.h&amp;gt;&#xA;&#xA;// Include GLEW&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;&#xA;//Glut&#xA;#include &amp;lt;GL/glut.h&amp;gt;&#xA;&#xA;//Project specific&#xA;#include &quot;skeletonize.hpp&quot;&#xA;#include &quot;PGM.hpp&quot;&#xA;&#xA;// OpenGL shader info&#xA;GLuint programID;&#xA;GLuint output_image;&#xA;&#xA;#define IMG_0               0&#xA;#define IMG_1               1&#xA;#define CMD                 2&#xA;#define NUM_BUFS            3&#xA;&#xA;#define CMD_BUF_WIDTH       0&#xA;#define CMD_BUF_HEIGHT      1&#xA;#define CMD_BUF_CMD         2&#xA;#define CMD_BUF_RESPONSE    3&#xA;#define CMD_BUF_LEN         4&#xA;&#xA;#define CMD_EXPAND          1&#xA;#define CMD_THIN_N          2&#xA;#define CMD_THIN_S          3&#xA;#define CMD_THIN_E          4&#xA;#define CMD_THIN_W          5&#xA;#define CMD_NORMALIZE       6&#xA;#define CMD_REGULARIZE      7&#xA;&#xA;#define INITIALIZED         0&#xA;#define NOT_FINISHED        1&#xA;&#xA;GLuint computeProgram;&#xA;GLuint buffers[NUM_BUFS];       //SSBO objects, one for IMG_0, one for IMG_1, and one for commands/response&#xA;static GLchar* computeSource;&#xA;GLuint shaderProgram;&#xA;&#xA;&#xA;//TODO: don't really need 2 textures yet, but will eventually when doing overlay of original image.&#xA;GLuint textures[2];&#xA;&#xA;GLchar* LoadSource(const char* pFile)&#xA;{&#xA;    struct stat buf;&#xA;    GLchar *source;&#xA;    int fd;&#xA;&#xA;    if (stat(pFile, &amp;amp;buf) == -1)&#xA;    {&#xA;        printf(&quot;Error opening file\n&quot;);&#xA;        printf(&quot;Error: %s\n&quot;, strerror(errno));&#xA;        return NULL;&#xA;    }&#xA;&#xA;    fd = open(pFile, O_RDONLY);&#xA;&#xA;    if (fd == -1)&#xA;    {&#xA;        printf(&quot;Error opening file. Error: %s\n&quot;, strerror(errno));&#xA;        return NULL;&#xA;    }&#xA;&#xA;    source = new GLchar[buf.st_size + 1];&#xA;&#xA;    if (read(fd, source, buf.st_size) == -1)&#xA;    {&#xA;        printf(&quot;Error reading file. Error: %s\n&quot;, strerror(errno));&#xA;        delete[] source;&#xA;        return NULL;&#xA;    }&#xA;&#xA;    source[buf.st_size] = '\0'; //Shader compiler needs null to know end of input&#xA;    return source;&#xA;}&#xA;&#xA;&#xA;// Shader sources&#xA;const GLchar* vertexSource =&#xA;    &quot;#version 450 core\n&quot;&#xA;    &quot;in vec2 position;&quot;&#xA;    &quot;in vec2 texcoord;&quot;&#xA;    &quot;out vec2 Texcoord;&quot;&#xA;    &quot;void main()&quot;&#xA;    &quot;{&quot;&#xA;    &quot;    Texcoord = texcoord;&quot;&#xA;    &quot;    gl_Position = vec4(position, 0.0, 1.0);&quot;&#xA;    &quot;}&quot;;&#xA;&#xA;const GLchar* fragmentSource =&#xA;    &quot;#version 450 core\n&quot;&#xA;    &quot;in vec2 Texcoord;&quot;&#xA;    &quot;out vec4 outColor;&quot;&#xA;    &quot;uniform sampler2D texData;&quot;&#xA;    &quot;void main()&quot;&#xA;    &quot;{&quot;&#xA;    &quot;   vec4 imColor = texture(texData, Texcoord);&quot;&#xA;    &quot;   outColor = vec4(0.0, imColor.r, 0.0, 1.0);&quot;&#xA;    //&quot;    outColor = texture(texData, Texcoord);&quot;&#xA;    //&quot;    outColor = vec4(1.0, 1.0, 0.0, 1.0);&quot;&#xA;    &quot;}&quot;;&#xA;&#xA;&#xA;void checkError(int line)&#xA;{&#xA;    GLint err;&#xA;&#xA;    do&#xA;    {&#xA;        err = glGetError();&#xA;        switch (err)&#xA;        {&#xA;            case GL_NO_ERROR:&#xA;                //printf(&quot;%d: No error\n&quot;, line);&#xA;                break;&#xA;            case GL_INVALID_ENUM:&#xA;                printf(&quot;%d: Invalid enum!\n&quot;, line);&#xA;                break;&#xA;            case GL_INVALID_VALUE:&#xA;                printf(&quot;%d: Invalid value\n&quot;, line);&#xA;                break;&#xA;            case GL_INVALID_OPERATION:&#xA;                printf(&quot;%d: Invalid operation\n&quot;, line);&#xA;                break;&#xA;            case GL_INVALID_FRAMEBUFFER_OPERATION:&#xA;                printf(&quot;%d: Invalid framebuffer operation\n&quot;, line);&#xA;                break;&#xA;            case GL_OUT_OF_MEMORY:&#xA;                printf(&quot;%d: Out of memory\n&quot;, line);&#xA;                break;&#xA;            default:&#xA;                printf(&quot;%d: glGetError default case. Should not happen!\n&quot;, line);&#xA;        }&#xA;    } while (err != GL_NO_ERROR);&#xA;}&#xA;&#xA;void display()&#xA;{&#xA;&#xA;    glClearColor(0.0f, 0.0f, 1.0f, 0.0f);&#xA;&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);&#xA;&#xA;    glFlush();&#xA;    glutSwapBuffers();&#xA;&#xA;}&#xA;&#xA;&#xA;void reshape(int width,int height)&#xA;{&#xA;    double w2h = (height&amp;gt;0) ? (double)width/height : 1;&#xA;    //  Set viewport as entire window&#xA;    glViewport(0,0, width,height);&#xA;&#xA;}&#xA;&#xA;&#xA;&#xA;&#xA;void runComputeProgram(uint32_t *data, uint32_t *data2)&#xA;{&#xA;    int width = 640;&#xA;    int height = 400;&#xA;&#xA;    uint32_t *ptr;&#xA;    uint32_t cmd[CMD_BUF_LEN];&#xA;&#xA;    computeSource = LoadSource(&quot;compute.shader&quot;);&#xA;    if (computeSource == NULL)&#xA;    {&#xA;        return;&#xA;    }&#xA;    GLuint computeShader = glCreateShader(GL_COMPUTE_SHADER);&#xA;    glShaderSource(computeShader, 1, &amp;amp;computeSource, NULL);&#xA;    glCompileShader(computeShader);&#xA;&#xA;    computeProgram = glCreateProgram();&#xA;    glAttachShader(computeProgram, computeShader);&#xA;    glLinkProgram(computeProgram);&#xA;    GLint status;&#xA;    glGetProgramiv(computeProgram, GL_LINK_STATUS, &amp;amp;status);&#xA;&#xA;    if (status == GL_TRUE)&#xA;    {&#xA;        printf(&quot;link good\n&quot;);&#xA;    }&#xA;    else&#xA;    {&#xA;        printf(&quot;link bad\n&quot;);&#xA;        GLchar log[4096];&#xA;        GLsizei len;&#xA;&#xA;        glGetProgramInfoLog(computeProgram, 4096, &amp;amp;len, log);&#xA;&#xA;        printf(&quot;%s\n&quot;, log);&#xA;        return;&#xA;    }&#xA;&#xA;    // First action is to transform the image into binary values (0, 1)&#xA;&#xA;    cmd[CMD_BUF_CMD] = CMD_NORMALIZE;&#xA;    cmd[CMD_BUF_WIDTH] = width;&#xA;    cmd[CMD_BUF_HEIGHT] = height;&#xA;&#xA;    glGenBuffers(NUM_BUFS, buffers);&#xA;&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffers[CMD]);&#xA;    glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(cmd), cmd, GL_DYNAMIC_DRAW);&#xA;&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffers[IMG_0]);&#xA;    glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(uint32_t) * width * height, data, GL_DYNAMIC_DRAW);&#xA;&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffers[IMG_1]);&#xA;    glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(uint32_t) * width * height, data2, GL_DYNAMIC_DRAW);&#xA;&#xA;    glUseProgram(computeProgram);&#xA;&#xA;    glDispatchCompute(width / 16, height / 16, 1);&#xA;    glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffers[IMG_1]);&#xA;    ptr = (uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);&#xA;&#xA;    glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);&#xA;&#xA;    // Rebind ptr for our while loop&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffers[CMD]);&#xA;    //glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(cmd), cmd, GL_DYNAMIC_DRAW);&#xA;    ptr = (uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);&#xA;&#xA;    int i = 0;&#xA;    do&#xA;    {   &#xA;        printf(&quot;iteration: %d&quot;, i);&#xA;        glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);&#xA;        cmd[CMD_BUF_RESPONSE] = INITIALIZED;&#xA;&#xA;        switch (i % 4)&#xA;        {&#xA;            case 0:&#xA;                cmd[CMD_BUF_CMD] = CMD_THIN_N;&#xA;                break;&#xA;            case 1:&#xA;                cmd[CMD_BUF_CMD] = CMD_THIN_S;&#xA;                break;&#xA;            case 2:&#xA;                cmd[CMD_BUF_CMD] = CMD_THIN_E;&#xA;                break;&#xA;            case 3:&#xA;                cmd[CMD_BUF_CMD] = CMD_THIN_W;&#xA;                break;&#xA;        }        &#xA;&#xA;        glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(cmd), cmd, GL_DYNAMIC_DRAW);&#xA;&#xA;        glDispatchCompute(width / 16, height / 16, 1);&#xA;        glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;&#xA;        if (i % 2 == 0)&#xA;        {&#xA;            printf(&quot;Input is now img_1. Output is img_0\n&quot;);&#xA;            glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffers[IMG_1]);&#xA;            glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffers[IMG_0]);&#xA;            checkError(__LINE__);&#xA;        }&#xA;        else&#xA;        {&#xA;            printf(&quot;Input is now img_0. Output is img_1\n&quot;);&#xA;            glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, buffers[IMG_0]);&#xA;            glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffers[IMG_1]);&#xA;            checkError(__LINE__);&#xA;        }&#xA;&#xA;        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffers[CMD]);&#xA;        ptr = (uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);&#xA;        printf(&quot;cmd issued at start: %d response: %d\n&quot;,  ptr[CMD_BUF_CMD], ptr[CMD_BUF_RESPONSE]);&#xA;        i++;&#xA;    } while(ptr[CMD_BUF_RESPONSE] != INITIALIZED &amp;amp;&amp;amp; i &amp;lt; 10); //Using i &amp;lt; 10, otherwise this never terminates&#xA;&#xA;    glUnmapBuffer(GL_SHADER_STORAGE_BUFFER); // Free ptr&#xA;&#xA;    // Transform Binary image (0, 1) to (0, 0xFFFFFFFF) values for texture display&#xA;    cmd[CMD_BUF_CMD] = CMD_REGULARIZE;        &#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffers[CMD]);&#xA;    glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(cmd), cmd, GL_DYNAMIC_DRAW);&#xA;&#xA;    glDispatchCompute(width / 16, height / 16, 1);&#xA;    glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;&#xA;    glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffers[CMD]);&#xA;    ptr = (uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);&#xA;    printf(&quot;Regularize: cmd: %d  width: %d  height: %d response: %d\n&quot;,  ptr[CMD_BUF_CMD], ptr[CMD_BUF_WIDTH], ptr[CMD_BUF_HEIGHT], ptr[CMD_BUF_RESPONSE]);&#xA;&#xA;    // Create texure&#xA;    glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);&#xA;&#xA;    glGenTextures(2, textures);&#xA;    checkError(__LINE__);&#xA;    glActiveTexture(GL_TEXTURE0);&#xA;    glBindTexture(GL_TEXTURE_2D, textures[0]);&#xA;        checkError(__LINE__);&#xA;&#xA;    if (i % 2 == 0)&#xA;    {&#xA;        printf(&quot;output image is img_1\n&quot;);&#xA;        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffers[IMG_1]);&#xA;        ptr = (uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);&#xA;    }&#xA;    else&#xA;    {        &#xA;        printf(&quot;output image is img_0\n&quot;);&#xA;        glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, buffers[IMG_0]);&#xA;        ptr = (uint32_t *)glMapBuffer(GL_SHADER_STORAGE_BUFFER, GL_READ_ONLY);&#xA;    }&#xA;&#xA;    glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);&#xA;&#xA;    glUseProgram(shaderProgram);&#xA;    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0,  GL_RED,  GL_UNSIGNED_INT, ptr);  //TODO: this is wrong. worry about later.&#xA;        checkError(__LINE__);&#xA;&#xA;    glUniform1i(glGetUniformLocation(shaderProgram, &quot;texData&quot;), 0);&#xA;    checkError(__LINE__);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;    checkError(__LINE__);&#xA;}&#xA;&#xA;void initGL()&#xA;{&#xA;    // Vertices &amp;amp; texture init&#xA;&#xA;    GLuint vao;&#xA;    glGenVertexArrays(1, &amp;amp;vao);&#xA;    glBindVertexArray(vao);&#xA;&#xA;    GLuint vbo;&#xA;    glGenBuffers(1, &amp;amp;vbo);&#xA;&#xA;    GLfloat vertices[] = {&#xA;        // X    Y      S    T&#xA;        -1.0f,  1.0f, 0.0f, 0.0f, // Top-left&#xA;         1.0f,  1.0f, 1.0f, 0.0f, // Top-right&#xA;         1.0f, -1.0f, 1.0f, 1.0f, // Bottom-right&#xA;        -1.0f, -1.0f, 0.0f, 1.0f  // Bottom-left&#xA;    };&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&#xA;    GLuint ebo;&#xA;    glGenBuffers(1, &amp;amp;ebo);&#xA;&#xA;    GLuint elements[] = {&#xA;        0, 1, 2,&#xA;        2, 3, 0&#xA;    };&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(elements), elements, GL_STATIC_DRAW);&#xA;&#xA;    // Create shaders&#xA;&#xA;    GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);&#xA;    glShaderSource(vertexShader, 1, &amp;amp;vertexSource, NULL);&#xA;    glCompileShader(vertexShader);&#xA;&#xA;    GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);&#xA;    glShaderSource(fragmentShader, 1, &amp;amp;fragmentSource, NULL);&#xA;    glCompileShader(fragmentShader);&#xA;&#xA;    shaderProgram = glCreateProgram();&#xA;    glAttachShader(shaderProgram, vertexShader);&#xA;    glAttachShader(shaderProgram, fragmentShader);&#xA;    glBindFragDataLocation(shaderProgram, 0, &quot;outColor&quot;);&#xA;    glLinkProgram(shaderProgram);&#xA;    glUseProgram(shaderProgram);&#xA;&#xA;    // Vertex data specification&#xA;    GLint posAttrib = glGetAttribLocation(shaderProgram, &quot;position&quot;);&#xA;    glEnableVertexAttribArray(posAttrib);&#xA;    glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);&#xA;&#xA;    GLint texAttrib = glGetAttribLocation(shaderProgram, &quot;texcoord&quot;);&#xA;    glEnableVertexAttribArray(texAttrib);&#xA;    glVertexAttribPointer(texAttrib, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (void *)(2 * sizeof(GLfloat)));&#xA;    checkError(__LINE__);&#xA;&#xA;&#xA;&#xA;}&#xA;&#xA;int main(int argc, char** argv)&#xA;{&#xA;    // Image setup&#xA;&#xA;    PGM pgmImage;&#xA;    pgmImage.ReadFile(&quot;test.pgm&quot;);&#xA;&#xA;    uint32_t *data = new uint32_t[pgmImage.GetHeight() * pgmImage.GetWidth()];&#xA;    uint32_t *data2 = new uint32_t[pgmImage.GetHeight() * pgmImage.GetWidth()];&#xA;    unsigned int size = pgmImage.GetHeight() * pgmImage.GetWidth();&#xA;    uint8_t *pgmData = pgmImage.GetData();&#xA;    for (int i=0; i &amp;lt; size; i++)&#xA;    {&#xA;        data[i] = pgmData[i];&#xA;    }&#xA;&#xA;    int count = 0;&#xA;    for (int i =0; i &amp;lt; pgmImage.GetHeight() * pgmImage.GetWidth(); i++)&#xA;    {&#xA;        if (data[i] == 0xFF)&#xA;        {&#xA;            count++;&#xA;        }&#xA;    }&#xA;&#xA;    printf(&quot;count: %d\n&quot;, count);&#xA;&#xA;    // Window Setup&#xA;&#xA;    glutInitWindowSize(640, 400);&#xA;    glutInitWindowPosition (140, 140);&#xA;    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);&#xA;    glutInit(&amp;amp;argc, argv);&#xA;&#xA;    glutCreateWindow( &quot;OpenGL Application&quot; );&#xA;    glutDisplayFunc(display);&#xA;    glutReshapeFunc(reshape);&#xA;&#xA;    glewExperimental = true;&#xA;    if (glewInit() != GLEW_OK) {&#xA;        fprintf(stderr, &quot;Failed to initialize GLEW\n&quot;);&#xA;        return -1;&#xA;    }&#xA;&#xA;    initGL();&#xA;    runComputeProgram(data, data2);&#xA;    checkError(__LINE__);&#xA;    glutMainLoop();&#xA;    return 0;&#xA;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;compute.shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450 core&#xA;//#extension GL_NV_shader_buffer_load : enable&#xA;&#xA;#define WIDTH           0    // Width of image&#xA;#define HEIGHT          1    // Height of image&#xA;#define CMD             2    // Command to execute&#xA;#define RESPONSE        3    // Response to command&#xA;#define BUF_LEN         4&#xA;&#xA;#define CMD_UNUSED      1    // TODO: remove this. Will have to be mirroed in C code.&#xA;#define CMD_THIN_N      2&#xA;#define CMD_THIN_S      3&#xA;#define CMD_THIN_E      4&#xA;#define CMD_THIN_W      5&#xA;#define CMD_NORMALIZE   6&#xA;#define CMD_REGULARIZE  7&#xA;&#xA;#define NOT_FINISHED 1&#xA;&#xA;layout (local_size_x = 16, local_size_y = 16) in;&#xA;//layout (local_size_x = 1) in; //TODO: remove&#xA;&#xA;layout (std430, binding = 0) buffer Cmd {&#xA;   uint cmd_buf[BUF_LEN]; //Width, height, command, response&#xA;};&#xA;&#xA;layout (std430, binding = 1) buffer Img1 {&#xA;   uint image_0[];&#xA;};&#xA;&#xA;layout (std430, binding = 2) buffer Img2 {&#xA;    uint image_1[];&#xA;};&#xA;&#xA;&#xA;int sigma(uint data[9]) {&#xA;    int i;&#xA;    int sigma = 0;&#xA;&#xA;    // Assume 9 pixels, A0 (pixel of interest) -&amp;gt; A8&#xA;    // In image, A0 is center&#xA;    // 1 2 3&#xA;    // 8 0 4&#xA;    // 7 6 5&#xA;&#xA;    for (i=1; i &amp;lt; 9; i++)&#xA;    {&#xA;        sigma += int(data[i]);&#xA;    }&#xA;&#xA;    return sigma;&#xA;}&#xA;&#xA;&#xA;int chi(uint data[9]) {&#xA;    int chi;&#xA;&#xA;    // Assume 9 pixels, A0 (pixel of interest) -&amp;gt; A8&#xA;    // 1 2 3&#xA;    // 8 0 4&#xA;    // 7 6 5&#xA;&#xA;    chi = int(data[1] != data[3]) +&#xA;          int(data[3] != data[5]) +&#xA;          int(data[5] != data[7]) +&#xA;          int(data[7] != data[1]) +&#xA;&#xA;          2 * ( int((data[2] &amp;gt; data[1]) &amp;amp;&amp;amp; (data[2] &amp;gt; data[3])) ) +&#xA;          int((data[4] &amp;gt; data[3]) &amp;amp;&amp;amp; (data[4] &amp;gt; data[5])) +&#xA;          int((data[6] &amp;gt; data[5]) &amp;amp;&amp;amp; (data[6] &amp;gt; data[7])) +&#xA;          int((data[8] &amp;gt; data[7]) &amp;amp;&amp;amp; (data[8] &amp;gt; data[1]));&#xA;&#xA;   return chi;&#xA;}&#xA;&#xA;// 1 2 3&#xA;// 8 0 4&#xA;// 7 6 5&#xA;int getPos(in int x, int y) {&#xA;   return y * int(cmd_buf[WIDTH]) + x;&#xA;}&#xA;&#xA;uint getVal(in int pos) {&#xA;   return image_0[ uint(pos) ];&#xA;}&#xA;&#xA;int removePoint(uint neighborhood[9]) {&#xA;    int x = int(gl_GlobalInvocationID.x);&#xA;    int y = int(gl_GlobalInvocationID.y);&#xA;&#xA;    if (chi(neighborhood) == 2 &amp;amp;&amp;amp; sigma(neighborhood) != 1) {&#xA;        image_1[getPos(x, y)] = 0;&#xA;        cmd_buf[RESPONSE] = NOT_FINISHED;&#xA;        return 1;&#xA;    }&#xA;    else&#xA;    {&#xA;        //TODO: needed? Swapping back and forth between input and output should account for this&#xA;        image_1[getPos(x,y)] = 1;&#xA;    }   &#xA;    return 0;&#xA;}&#xA;&#xA;&#xA;void getNeighborhood(inout uint neighborhood[9]) {&#xA;    int x = int(gl_GlobalInvocationID.x);&#xA;    int y = int(gl_GlobalInvocationID.y);&#xA;    int bottom = int(cmd_buf[WIDTH] * (cmd_buf[HEIGHT] - 1));&#xA;    int pos = getPos(x, y);&#xA;    int width = int(cmd_buf[WIDTH]);&#xA;    int height = int(cmd_buf[HEIGHT]);&#xA;    uint pixel;&#xA;    int i = 0;&#xA;&#xA;    for (i=1; i &amp;lt; 9; i++) {&#xA;       neighborhood[i] = 2;&#xA;    }&#xA;&#xA;    if (pos &amp;lt; width) {&#xA;        // Pixel on top, fill outiside image with zero&#xA;       neighborhood[1] = 0;&#xA;       neighborhood[2] = 0;&#xA;       neighborhood[3] = 0;&#xA;    }&#xA;&#xA;    if (pos % width == 0) {&#xA;        // Pixel is on left edge. Fill area outside of image with zero&#xA;        neighborhood[1] = 0;&#xA;        neighborhood[8] = 0;&#xA;        neighborhood[7] = 0;&#xA;    }&#xA;&#xA;    if ((pos % width) == (width - 1)) {&#xA;        // Pixel is on right edge.&#xA;        neighborhood[3] = 0;&#xA;        neighborhood[4] = 0;&#xA;        neighborhood[5] = 0;&#xA;    }&#xA;&#xA;    if (pos &amp;gt;= bottom) {&#xA;        // Pixel is on bottom edge.&#xA;        neighborhood[5] = 0;&#xA;        neighborhood[6] = 0;&#xA;        neighborhood[7] = 0;&#xA;    }&#xA;&#xA;    // Get remaining pixels&#xA;    for (i=1; i &amp;lt; 9; i++) {&#xA;        if (neighborhood[i] == 2) {&#xA;            switch (i) {&#xA;                case 1:&#xA;                    // Upper left pixel&#xA;                    neighborhood[i] = getVal(pos - 1 - width);&#xA;                    break;&#xA;                case 2:&#xA;                    // Upper middle pixel&#xA;                    neighborhood[i] = getVal(pos - width);&#xA;                    break;&#xA;                case 3:&#xA;                    // Upper right pixel&#xA;                    neighborhood[i] = getVal(pos + 1 - width);&#xA;                    break;&#xA;                case 4:&#xA;                    // Right pixel&#xA;                    neighborhood[i] = getVal(pos + 1);&#xA;                    break;&#xA;                case 5:&#xA;                    // Bottom right pixel&#xA;                    neighborhood[i] = getVal(pos + width + 1);&#xA;                    break;&#xA;                case 6:&#xA;                    // Bottom middle pixel&#xA;                    neighborhood[i] = getVal(pos + width);&#xA;                    break;&#xA;                case 7:&#xA;                    // Bottom left pixel&#xA;                    neighborhood[i] = getVal(pos + width - 1);&#xA;                    break;&#xA;                case 8:&#xA;                    // Left pixel&#xA;                    neighborhood[i] = getVal(pos - 1);&#xA;                    break;&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;&#xA;&#xA;&#xA;void normalize() {&#xA;    int x = int(gl_GlobalInvocationID.x);&#xA;    int y = int(gl_GlobalInvocationID.y);&#xA;    uint val = image_0[getPos(x, y)] == 0x0 ? 0 : 1;&#xA;&#xA;    image_0[getPos(x, y)] = val;&#xA;    image_1[getPos(x, y)] = val;&#xA;&#xA;}&#xA;&#xA;&#xA;void regularize() {&#xA;    int x = int(gl_GlobalInvocationID.x);&#xA;    int y = int(gl_GlobalInvocationID.y);&#xA;    uint val = image_0[getPos(x, y)] == 0x0 ? 0 : 0xFFFFFFFF;&#xA;&#xA;    if (val != 0xFFFFFFFF)&#xA;    {&#xA;        cmd_buf[RESPONSE] = 99; //Test Value -- TODO: remove&#xA;    }&#xA;&#xA;    image_1[getPos(x, y)] = val;&#xA;}&#xA;&#xA;&#xA;&#xA;// North-South-East-West skeletonization&#xA;void skeleton() {&#xA;    int x = int(gl_GlobalInvocationID.x);&#xA;    int y = int(gl_GlobalInvocationID.y);&#xA;    uint neighborhood[9];&#xA;    neighborhood[0] = getVal(getPos(x, y));&#xA;&#xA;    // Only consider cases where the center is 1&#xA;    if (neighborhood[0] != 1) {&#xA;        return;&#xA;    }&#xA;&#xA;    getNeighborhood(neighborhood);&#xA;&#xA;    switch (cmd_buf[CMD]) {&#xA;        case CMD_THIN_N:&#xA;            //north&#xA;            if (neighborhood[2] == 0 &amp;amp;&amp;amp; neighborhood[6] == 1) {&#xA;                removePoint(neighborhood);&#xA;            }&#xA;            break;&#xA;        case CMD_THIN_S:&#xA;            //south&#xA;            if (neighborhood[2] == 1 &amp;amp;&amp;amp; neighborhood[6] == 0) {&#xA;                removePoint(neighborhood);&#xA;            }&#xA;            break;&#xA;        case CMD_THIN_E:&#xA;            //east&#xA;            if (neighborhood[4] == 0 &amp;amp;&amp;amp; neighborhood[8] == 1) {&#xA;                removePoint(neighborhood);&#xA;            }&#xA;            break;&#xA;        case CMD_THIN_W:&#xA;            //west&#xA;            if (neighborhood[4] == 1 &amp;amp;&amp;amp; neighborhood[8] == 0) {&#xA;                removePoint(neighborhood);&#xA;            }&#xA;            break;&#xA;    }&#xA;}&#xA;&#xA;&#xA;&#xA;void main() {&#xA;&#xA;    switch (cmd_buf[CMD]) {&#xA;        case CMD_THIN_N:&#xA;        case CMD_THIN_S:&#xA;        case CMD_THIN_E:&#xA;        case CMD_THIN_W:&#xA;            skeleton();&#xA;            break;&#xA;        case CMD_NORMALIZE:&#xA;            normalize();&#xA;            break;&#xA;        case CMD_REGULARIZE:&#xA;            regularize();&#xA;            break;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;pgm.cpp&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &quot;PGM.hpp&quot;&#xA;&#xA;#define PGM_HEADER &quot;P5&quot;&#xA;&#xA;PGM::PGM()&#xA;{&#xA;    mpData = NULL;&#xA;    Clear();&#xA;}&#xA;&#xA;PGM::~PGM()&#xA;{&#xA;    Clear();&#xA;}&#xA;&#xA;uint8_t* PGM::GetData()&#xA;{&#xA;    return mpImgData;&#xA;}&#xA;&#xA;&#xA;uint16_t PGM::GetWidth()&#xA;{&#xA;    return mWidth;&#xA;}&#xA;&#xA;uint16_t PGM::GetHeight()&#xA;{&#xA;    return mHeight;&#xA;}&#xA;&#xA;uint8_t PGM::GetMaxWhite()&#xA;{&#xA;    return mMaxWhite;&#xA;}&#xA;&#xA;void PGM::Clear()&#xA;{&#xA;    if (mpData != NULL)&#xA;    {&#xA;        delete[] mpData;&#xA;    }&#xA;&#xA;    mpImgData = NULL;&#xA;    mWidth = 0;&#xA;    mHeight = 0;&#xA;    mMaxWhite = 255;&#xA;}&#xA;&#xA;// Finds the &#xA;int PGM::PopulateFields(size_t size)&#xA;{&#xA;    int i;&#xA;    bool EOL = false;&#xA;    bool haveWhite = false;&#xA;    bool comment = false;&#xA;&#xA;    if (mpData == NULL) { return -1; }&#xA;&#xA;    // Check header&#xA;    if ((mpData[0] != 0x50) || (mpData[1] != 0x35)) { return -2; }&#xA;&#xA;    //Ignore the comment&#xA;    //Start at 3rd position in file, after &quot;P5&quot; header    &#xA;    for (i = 2; i &amp;lt; size; i++)&#xA;    {&#xA;        if (mpData[i] == '#') &#xA;        { &#xA;            comment = true;&#xA;            continue;&#xA;        }&#xA;&#xA;        if (mpData[i] == 0x0A &amp;amp;&amp;amp; comment == true)&#xA;        {&#xA;            comment = false;&#xA;            break;&#xA;        }&#xA;&#xA;        if (comment == true) &#xA;        { &#xA;            continue; &#xA;        }&#xA;&#xA;    }&#xA;&#xA;    // Get width and height&#xA;    i++;&#xA;    sscanf((char *)&amp;amp;mpData[i], &quot;%4&quot; SCNu16 &quot; %4&quot; SCNu16, &amp;amp;mWidth, &amp;amp;mHeight);&#xA;&#xA;    for (i; i &amp;lt; size; i++)&#xA;    {&#xA;        //Move past the width and height we just found&#xA;        if (mpData[i] == 0x0A &amp;amp;&amp;amp; EOL == false)&#xA;        {&#xA;            EOL = true;&#xA;            continue;&#xA;        }&#xA;&#xA;        // If past the width and height, now at the range. Save it.&#xA;        if (EOL == true &amp;amp;&amp;amp; haveWhite == false)&#xA;        {&#xA;            sscanf((char *)&amp;amp;mpData[i], &quot;%3&quot; SCNu8, &amp;amp;mMaxWhite);&#xA;            haveWhite = true;&#xA;        }&#xA;&#xA;        if (haveWhite == true &amp;amp;&amp;amp; mpData[i] == 0x0A)&#xA;        {&#xA;            i++; //Move to next element - start of the actual data&#xA;            break;&#xA;        }&#xA;    }&#xA;&#xA;    if (i == size)&#xA;    {&#xA;        return -3; //Did not find the start of data.&#xA;    }&#xA;&#xA;    mpImgData = &amp;amp;mpData[i];&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;// Reads a PGM file. Returns 0 on success, other values on failure&#xA;int PGM::ReadFile(const char *pPath)&#xA;{&#xA;    struct stat st;&#xA;    int fd;&#xA;&#xA;    if (this-&amp;gt;mpData != NULL)&#xA;    {&#xA;        Clear();&#xA;    }&#xA;&#xA;    if (stat(pPath, &amp;amp;st) != 0)&#xA;    {&#xA;        return 1;&#xA;    }&#xA;&#xA;    fd = open(pPath, O_RDONLY);&#xA;&#xA;    if (fd == -1)&#xA;    {&#xA;        return 1;&#xA;    }&#xA;&#xA;    //this-&amp;gt;mpData = (uint8_t *) malloc(st.st_size);&#xA;    mpData = new uint8_t[st.st_size];&#xA;&#xA;    if (this-&amp;gt;mpData == NULL)&#xA;    {&#xA;        return 2;&#xA;    }&#xA;&#xA;    if (read(fd, this-&amp;gt;mpData, st.st_size) == -1)&#xA;    {&#xA;        Clear();&#xA;    }&#xA;&#xA;    close(fd);&#xA;&#xA;    PopulateFields(st.st_size);&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;pgm.hpp&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifndef __PGM_H__&#xA;#define __PGM_H__&#xA;&#xA;#include &amp;lt;stdint.h&amp;gt;&#xA;#include &amp;lt;stdio.h&amp;gt;&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xA;#include &amp;lt;string.h&amp;gt;&#xA;#include &amp;lt;sys/types.h&amp;gt;&#xA;#include &amp;lt;sys/stat.h&amp;gt;&#xA;#include &amp;lt;fcntl.h&amp;gt;&#xA;#include &amp;lt;unistd.h&amp;gt;&#xA;#include &amp;lt;errno.h&amp;gt;&#xA;#include &amp;lt;inttypes.h&amp;gt;&#xA;&#xA;class PGM&#xA;{&#xA;  public:&#xA;    int         ReadFile(const char *pPath);&#xA;    uint8_t*    GetData();&#xA;    uint16_t    GetWidth();&#xA;    uint16_t    GetHeight();&#xA;    uint8_t     GetMaxWhite();&#xA;&#xA;    PGM();&#xA;    ~PGM();&#xA;&#xA;  private:&#xA;&#xA;    void        Clear();&#xA;    int         PopulateFields(size_t size);&#xA;&#xA;    uint8_t     *mpData;&#xA;    uint8_t     *mpImgData;&#xA;    uint16_t    mWidth;&#xA;    uint16_t    mHeight;&#xA;    uint8_t     mMaxWhite;&#xA;&#xA;};&#xA;&#xA;#endif // __PGM_H__&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5316" LastActivityDate="2016-10-19T04:37:00.823" Title="Can I reuse glBindBufferBase in compute shaders to keep data on GPU?" Tags="&lt;opengl&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4148" PostTypeId="2" ParentId="4147" CreationDate="2016-10-19T04:27:20.920" Score="2" Body="&lt;p&gt;I found it! The issue stems from a problem in the swap. When we swap buffers, the output buffer becomes the input and the input buffer becomes the output. However, the buffer that is now the output was not updated to match!&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;To illustrate:&#xA;&#xA;Init:&#xA; In      Out&#xA;1 1 1   1 1 1&#xA;1 1 1   1 1 1&#xA;1 1 1   1 1 1&#xA;&#xA;First Iteration (remove north corners):&#xA; In      Out&#xA;1 1 1   0 1 0&#xA;1 1 1   1 1 1&#xA;1 1 1   1 1 1&#xA;&#xA;Swap &#xA; In      Out&#xA;0 1 0   1 1 1&#xA;1 1 1   1 1 1&#xA;1 1 1   1 1 1&#xA;&#xA;Second iteration (remove east corners):&#xA; In      Out&#xA;0 1 0   1 1 1&#xA;1 1 1   1 1 1&#xA;1 1 1   1 1 0&#xA;&#xA;... (and so on)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;By modifying skeleton() in the compute shader to copy image_0 to image_1, prior to anything else, the algorithm works correctly. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void skeleton() {&#xA;    int x = int(gl_GlobalInvocationID.x);&#xA;    int y = int(gl_GlobalInvocationID.y);&#xA;    uint neighborhood[9];&#xA;    neighborhood[0] = getVal(getPos(x, y));&#xA;&#xA;    image_1[getPos(x, y)] = image_0[getPos(x, y)];&#xA;&#xA;    // Only consider cases where the center is 1&#xA;    if (neighborhood[0] != 1) {&#xA;        image_1[0] = 0;&#xA;        return;&#xA;    }&#xA;    ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Additionally, I cleaned up the code quite a bit. For example, you can set the in and out buffers via glBindBufferBase() prior to the dispatch call.&lt;/p&gt;&#xA;" OwnerUserId="5316" LastEditorUserId="5316" LastEditDate="2016-10-19T04:37:00.823" LastActivityDate="2016-10-19T04:37:00.823" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4150" PostTypeId="1" AcceptedAnswerId="4152" CreationDate="2016-10-19T13:36:21.613" Score="5" ViewCount="123" Body="&lt;p&gt;Given a point light source, a eye position, we can find the silhouette (outline) of the given model. We can first find the silhouette edge, project the model into a 2-D plane,  then traverse all silhouette edges. But when it comes to concave model, some part of the silhouette edges should not be included in the model outline. How to find those parts? Also, can we do this without projecting the model into a 2-D plane? &lt;/p&gt;&#xA;" OwnerUserId="5105" LastActivityDate="2016-10-20T13:57:30.407" Title="How to find silhouette for concaver" Tags="&lt;silhouette&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4151" PostTypeId="1" CreationDate="2016-10-20T05:09:59.867" Score="9" ViewCount="413" Body="&lt;p&gt;I have &lt;a href=&quot;http://algorithmicassertions.com/quirk&quot; rel=&quot;nofollow noreferrer&quot;&gt;a WebGL circuit simulator&lt;/a&gt;. One of the problems it has is that, due to using quite a lot of intermediate float textures as it simulates, it doesn't work on various mobile devices. They only support byte textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My intended solution to this problem is to encode the high-precision (i.e. 32-bit) floats as bytes. Every output float is packed into a nearly-IEEE format (I put the sign bit at the other end to avoid a few shifts, I don't do denormalized values, and I don't do infinities/NaNs). Similarly, every input is unpacked before being used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have found various blog posts and answers related to this task out on the internet (&lt;a href=&quot;http://www.ozone3d.net/blogs/lab/20080604/glsl-float-to-rgba8-encoder/&quot; rel=&quot;nofollow noreferrer&quot;&gt;example 1&lt;/a&gt;, &lt;a href=&quot;https://stackoverflow.com/questions/28159591/how-to-pack4bytes-and-unpackvec4-between-c-and-glsl&quot;&gt;example 2&lt;/a&gt;, &lt;a href=&quot;https://gist.github.com/Flexi23/1713774&quot; rel=&quot;nofollow noreferrer&quot;&gt;example 3&lt;/a&gt;), but I haven't found any that work properly on all finite non-denormalized floats.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I'm running into is precision. I want to round trip the floats &lt;strong&gt;without introducing any error&lt;/strong&gt;, but I can't seem to make a shader that preserves all 23 bits of the mantissa. There always seems to be some rounding on some machine that loses the last bit, though I can perturb the cases where the rounding happens and it happens differently on the various machines I've tested on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my packing method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 packFloatIntoBytes(float val) {&#xA;    if (val == 0.0) {&#xA;        return vec4(0.0, 0.0, 0.0, 0.0);&#xA;    }&#xA;&#xA;    float mag = abs(val);&#xA;    float exponent = floor(log2(mag));&#xA;    // Correct log2 approximation errors.&#xA;    exponent += float(exp2(exponent) &amp;lt;= mag / 2.0);&#xA;    exponent -= float(exp2(exponent) &amp;gt; mag);&#xA;&#xA;    float mantissa;&#xA;    if (exponent &amp;gt; 100.0) {&#xA;        // Not sure why this needs to be done in two steps for the largest float to work.&#xA;        // Best guess is the optimizer rewriting '/ exp2(e)' into '* exp2(-e)',&#xA;        // but exp2(-128.0) is too small to represent.&#xA;        mantissa = mag / 1024.0 / exp2(exponent - 10.0) - 1.0;&#xA;    } else {&#xA;        mantissa = mag / float(exp2(exponent)) - 1.0;&#xA;    }&#xA;&#xA;    float a = exponent + 127.0;&#xA;    mantissa *= 256.0;&#xA;    float b = floor(mantissa);&#xA;    mantissa -= b;&#xA;    mantissa *= 256.0;&#xA;    float c = floor(mantissa);&#xA;    mantissa -= c;&#xA;    mantissa *= 128.0;&#xA;    float d = floor(mantissa) * 2.0 + float(val &amp;lt; 0.0);&#xA;    return vec4(a, b, c, d) / 255.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here's my unpacking method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float unpackBytesIntoFloat(vec4 v) {&#xA;    float a = floor(v.r * 255.0 + 0.5);&#xA;    float b = floor(v.g * 255.0 + 0.5);&#xA;    float c = floor(v.b * 255.0 + 0.5);&#xA;    float d = floor(v.a * 255.0 + 0.5);&#xA;&#xA;    float exponent = a - 127.0;&#xA;    float sign = 1.0 - mod(d, 2.0)*2.0;&#xA;    float mantissa = float(a &amp;gt; 0.0)&#xA;                   + b / 256.0&#xA;                   + c / 65536.0&#xA;                   + floor(d / 2.0) / 8388608.0;&#xA;    return sign * mantissa * exp2(exponent);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This method is close. It works on my laptop, as far as I can tell. But it doesn't work on my Nexus tablet. For example, the float &lt;code&gt;-0.20717763900756836&lt;/code&gt; should be encoded as &lt;code&gt;[124, 168, 76, 193]&lt;/code&gt;. When I unpack that then repack it on the Nexus tablet the output is one ulp lower: &lt;code&gt;[124, 168, 76, 191]&lt;/code&gt; (which encodes &lt;code&gt;-0.2071776[5390872955]&lt;/code&gt;). Close, but I want perfect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mostly I'm at a loss trying to figure out where the precision is being destroyed in this method. Changes almost seem to have random effects, like replacing &lt;code&gt;x * exp2(n)&lt;/code&gt; with &lt;code&gt;x / exp2(-n)&lt;/code&gt; might fix an error in one place but introduce an error in another place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is there any &lt;em&gt;exact&lt;/em&gt; way to pack floats into bytes, without losing precision?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Some example values that such a method should work on:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var testValues = new Float32Array([&#xA;    0,&#xA;    0.5,&#xA;    1,&#xA;    2,&#xA;    -1,&#xA;    1.1,&#xA;    42,&#xA;    16777215,&#xA;    16777216,&#xA;    16777218,&#xA;    0.9999999403953552, // An ulp below 1.&#xA;    1.0000001192092896, // An ulp above 1.&#xA;    Math.pow(2.0, -126), // Smallest non-denormalized 32-bit float.&#xA;    0.9999999403953552 * Math.pow(2.0, 128), // Largest finite 32-bit float.&#xA;    Math.PI,&#xA;    Math.E&#xA;]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5328" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-10-20T18:15:12.000" Title="WebGL packing/unpacking functions that can roundtrip all typical 32-bit floats" Tags="&lt;webgl&gt;" AnswerCount="0" CommentCount="12" ContentLicense="CC BY-SA 3.0" />
  <row Id="4152" PostTypeId="2" ParentId="4150" CreationDate="2016-10-20T13:57:30.407" Score="1" Body="&lt;p&gt;I'll explain the &quot;geometric way&quot; of solving the problem since that's the solution you seem to be after, instead of using rasterization that Dan suggested in the comments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get the list of potential silhouette edges without 2D projection by first iterating through all edges and taking dot product of the normal of the attached two triangles against the eye-&gt;edge vector (any point on the edge will do, e.g. one of the end-points). If the dot products for the two triangles on the edge have different signs, then it's a potential silhouette edge. If the object is convex, then you are done and got the list of silhouette edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For concave objects it gets more complicated. For concave objects it could be that an edge is only partially a silhouette edge and can be potentially split to N fragments that all belong to the silhouette. So you need to process the list of potential edges and clip them with the geometry. The way you can do the clipping is to extrude every triangle in the geometry away from eye and use this volume to clip the list of potential silhouette edges. The remaining edge fragments that are not clipped away are your silhouette.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-20T13:57:30.407" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4153" PostTypeId="1" CreationDate="2016-10-20T19:46:13.413" Score="2" ViewCount="192" Body="&lt;p&gt;In theory I can't use a lambertian shader on a cube, because there aren't surface normals on the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this correct ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is this always possible in software applications ?&lt;/p&gt;&#xA;" OwnerUserId="1636" LastActivityDate="2016-10-21T11:27:35.610" Title="Lambertian Shading of a cube" Tags="&lt;shading&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4154" PostTypeId="2" ParentId="4153" CreationDate="2016-10-20T22:31:50.500" Score="1" Body="&lt;p&gt;Each cube face is made up of a quad, or two triangles.  Let's take 3 points from either the quad, or one of the triangles, and call them $A,B,C$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get the normal to this surface by normalizing the cross product of $\overline{AB}$ and $\overline{BC}$.  You can then use that surface normal to calculate lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can do similar calculations to get the tangent and bitangent to then calculate $u,v$ values for texture mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure why the edges not having normals makes you think you can't calculate lighting for the cube faces, but you totally can.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could even use the vertices to calculate a normal for the edges if you wanted, but I'm not sure why you would want to do that :P&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-20T22:31:50.500" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4155" PostTypeId="1" CreationDate="2016-10-20T22:55:23.177" Score="0" ViewCount="281" Body="&lt;p&gt;I have got a weird bug that I cannot figure out. The Apple forums were not too helpful.&#xA;I updated my MacBookPro (Retina, early 2015) to the newest OS X Sierra. My code ran fine before, now when I call &lt;code&gt;glfwCreateWindow(mWidth, mHeight, mTitle, nullptr, nullptr);&lt;/code&gt;, I get following error:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;gt; ERROR: Setting &amp;lt;private&amp;gt; as the first responder for window&amp;lt;private&amp;gt;,but it is in a different window ((null))! This would&#xA;&amp;gt; eventually crash when the view is freed. The first responder will be&#xA;&amp;gt; set to nil.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have got no idea, why my program does not work and yes, I have set the glfw to be forward compatible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. computer info:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;MacBook Pro (Retina 13 inch, early 2015)&lt;/li&gt;&#xA;&lt;li&gt;CPU: 2.7 GHz Intel core i5&lt;/li&gt;&#xA;&lt;li&gt;GPU: Intel Iris Graphics 6100 1536 MB&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5334" LastEditorUserId="67" LastEditDate="2016-10-21T07:43:34.997" LastActivityDate="2016-10-21T07:43:34.997" Title="Error when calling glfwCreateWindow() on OS X after updating to Sierra" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4156" PostTypeId="2" ParentId="4153" CreationDate="2016-10-21T11:27:35.610" Score="1" Body="&lt;p&gt;In a polygon mesh, all the faces that meet at a point don't have to share the same vertex. They can each have their own vertex, and those vertices can all have the same position but different normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In meshes with smooth edges (such as on a sphere, where you want to hide the edges), you want all the vertices at the same point to have the same normal. Generally this will be close to the average of the normals of the faces that share the vertex. That way, Lambertian shading computes the same colour for each, and you don't get a discontinuity on the edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In meshes where you want a deliberate sharp edge (such as your cube example), you want the vertices to have their own normals. In the cube case, each face has its own four vertices, and those vertices all have the same normal (the face normal). Each corner of the cube has three (or six, depending on the triangulation) vertices, with three normals perpendicular to each other. This way, Lambertian shading gives each face the same colour (because all the normals for one face point in the same direction), and adjacent faces don't affect each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A mesh with some rounded parts and some sharp edges can have both. Some vertices can be merged (i.e. each triangle meeting at the same point has the same vertex normal) and others can be split (i.e. each triangle meeting at the same point has its own normal for that vertex). One triangle can have some smooth vertices (shared with its neighbours) and some sharp vertices (with the face normal, not an averaged normal). It's best if the vertices on one edge are all the same, otherwise the results look unphysical.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally, the 3D modelling tool you use to create the mesh will give you the choice: you can make the whole mesh smooth or sharp, or you can select some edges and make them individually smooth or sharp.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-10-21T11:27:35.610" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4157" PostTypeId="1" AcceptedAnswerId="4161" CreationDate="2016-10-21T14:40:51.237" Score="4" ViewCount="262" Body="&lt;p&gt;So after reading this Unreal Engine 4 Documentation page: &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/LayeredMaterials/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/LayeredMaterials/&lt;/a&gt; &#xA;(Which describes how to use material layering in UE4)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wanted to know how material layering is implemented. (Notice how the 'unreal engine' part of the rocket has different material and aswell as the scratches on the rocket?) Is it done by adding together the 2 final variables that contain the color's for each respective material after being processed by a BRDF?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VEjgH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VEjgH.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2016-10-21T20:04:05.633" LastActivityDate="2016-10-22T04:24:38.820" Title="Material Layering" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;physically-based&gt;&lt;material&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4158" PostTypeId="1" AcceptedAnswerId="4159" CreationDate="2016-10-21T15:48:17.663" Score="5" ViewCount="1735" Body="&lt;p&gt;Recently I wanted to improve the lighting in my game engine, naturally I looked towards Ambient Occlusion. I was considering SSAO but are there any better techniques? Maybe some that are Physically Based? Are there any other techniques that replace SSAO or HBAO+ entirely? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am aware of &lt;a href=&quot;https://developer.nvidia.com/vxao-voxel-ambient-occlusion&quot;&gt;VXAO&lt;/a&gt; but is that basically it?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-10-22T16:04:58.150" Title="Alternatives to Ambient Occlusion" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;physically-based&gt;&lt;ambient-occlusion&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4159" PostTypeId="2" ParentId="4158" CreationDate="2016-10-21T23:26:09.900" Score="7" Body="&lt;p&gt;Ambient occlusion cannot be physically based no matter what algorithm you use to calculate it. It's a simplification of global illumination that assumes all occluders only block light and are themselves completely black, which isn't true and generally makes corners darker than they should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally, you would be using some kind of global illumination method, but they generally don't have enough resolution to capture the effect ambient occlusion simulates and screen space global illumination tends to be too expensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That means ambient occlusion is still a reasonable choice, even if it's not entirely physically correct. Screen space ambient occlusion methods are the fastest, but suffer from the limited information they have access to, which can lead to artifacts like halos around objects in the foreground and the edges of the screen. Having more information about the scene to calculate the AO from, like VXAO does, eliminates those artifacts, but it again comes at a performance cost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, it depends on your perf budget. The more time you can spend calculating global illumination and ambient occlusion, the better the results are going to look. &lt;a href=&quot;http://frederikaalund.com/a-comparative-study-of-screen-space-ambient-occlusion-methods/&quot;&gt;This seems to be a solid resource&lt;/a&gt; about screen space ambient occlusion algorithms in particular. I've personally had good results with Alchemy AO accelerated for large radii with a depth mip-chain similar to the &lt;a href=&quot;https://research.nvidia.com/sites/default/files/publications/McGuire12SAO.pdf&quot;&gt;Scalable Ambient Obscurance paper&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For an alternative to traditional AO, there's &lt;a href=&quot;https://people.mpi-inf.mpg.de/~ritschel/Papers/ScreenSpaceBentCones.pdf&quot;&gt;Bent Normals and Cones in Screen-Space&lt;/a&gt; that I've heard a lot about. As far as I understand it, the key difference is that instead of just calculating &lt;em&gt;how much&lt;/em&gt; a point in space is occluded, it also captures information about what directions in particular are occluded. This information is then later used for lighting, where only light coming from the unoccluded directions is considered. It's still not what you'd call physically based, but in my opinion it comes closer than the usual ambient occlusion.&lt;/p&gt;&#xA;" OwnerUserId="3470" LastActivityDate="2016-10-21T23:26:09.900" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4160" PostTypeId="2" ParentId="4146" CreationDate="2016-10-22T03:52:07.037" Score="5" Body="&lt;p&gt;For light sources with larger solid angle and where the shadow caster is relatively closer to the light than the receiver, you get notable soft shadowing effect. So if you render larger light sources closer to the shadow receiver it's important to handle soft shadows properly for realistic lighting. Even with the Sun which has quite small solid angle, you can still see fairly large penumbras from tall buildings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PCSS is fairly simple algorithm for implementing contact hardening shadows, but it has some notable issues. PCSS fails when you have soft and hard shadows intersecting (blocker search fails), so it's not a good algorithm to use when large penumbras are needed. See in the below image where shadows from the box &amp;amp; triangle intersect. This artifact is particularly disturbing when animated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VQ4ln.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VQ4ln.png&quot; alt=&quot;PCSS artifact&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a family of &lt;a href=&quot;http://www.labri.fr/perso/guenneba/docs/SoftShadowMapping-egsr06.pdf&quot; rel=&quot;noreferrer&quot;&gt;&quot;back-projection&quot; shadow techniques&lt;/a&gt; though, which is able to handle larger penumbras. However, there's a little research done how to implement this efficiently for real-time applications that I'm aware of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bMrtV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bMrtV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In back-projection the principle idea is to project shadow map texels to the light source for every pixel to calculate light occlusion, which when implemented naively is obviously extremely slow and furthermore introduces shadow gaps &amp;amp; overlaps. However, there are some techniques to try to avoid the artifacts, such as adjusting the microquad extents as shown below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZVfaN.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZVfaN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another improvement to handle the gaps and overlaps is to use &lt;a href=&quot;http://research.michael-schwarz.com/publ/files/bmss-eg07.pdf&quot; rel=&quot;noreferrer&quot;&gt;bitmask soft shadowing&lt;/a&gt; algorithm, where occlusion bitmask determines the occluded areas of the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most recent paper I have seen on the topic is &quot;&lt;a href=&quot;http://www.geomerics.com/wp-content/uploads/2014/03/AltDevConf-SamMartin-RealTimeAreaLighting.pdf&quot; rel=&quot;noreferrer&quot;&gt;Real Time Area Lighting. Now and Next&lt;/a&gt;&quot; by Sam Martin from 2012, where the cost was several milliseconds for a single light, but it's definitely worth the read if you are interested of the topic, to get general idea about the state-of-the-art real-time shadow techniques.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-22T03:52:07.037" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4161" PostTypeId="2" ParentId="4157" CreationDate="2016-10-22T04:24:38.820" Score="2" Body="&lt;p&gt;It would be too expensive (both performance and memory wise) to evaluate BRDF first for each material layer and then blend the layers. Thus the material layer parameters &amp;amp; textures are rather first blended together and then written to the G-buffer for a single BRDF evaluation. This is feasible as long as all the layers use the same BRDF. This doesn't generate identical results to evaluating BRDF before blending, but the results are quite often acceptable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The BRDF parameter blending can be done as an offline process that generates unique textures based on blending maps. This is efficient at run-time but of course consumes more memory since for every blend map you need to generate all the source textures. You can also blend the materials at run-time with the expense of performance, but with smaller memory budget in general.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-22T04:24:38.820" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4164" PostTypeId="1" AcceptedAnswerId="4177" CreationDate="2016-10-23T08:15:51.637" Score="16" ViewCount="9481" Body="&lt;p&gt;What are &lt;strong&gt;Spherical Harmonics&lt;/strong&gt; &amp;amp; &lt;strong&gt;Light Probes&lt;/strong&gt;? How useful are they in computer graphics? What exactly do they do? I've heard the word spherical harmonics &amp;amp; Light Probes everywhere, from siggraph presentations to blog posts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recently Matt Pettineo posted a &lt;a href=&quot;https://mynameismjp.wordpress.com/2016/10/09/sg-series-part-1-a-brief-and-incomplete-history-of-baked-lighting-representations/&quot;&gt;6 part blog series&lt;/a&gt; on them but I still don't understand what they are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it another way to improve ambient lighting? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="2041" LastEditDate="2017-01-05T10:39:47.540" LastActivityDate="2017-01-05T10:39:47.540" Title="What are Spherical Harmonics &amp; Light Probes?" Tags="&lt;lighting&gt;&lt;physically-based&gt;&lt;spherical-harmonics&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="17" ContentLicense="CC BY-SA 3.0" />
  <row Id="4165" PostTypeId="2" ParentId="4164" CreationDate="2016-10-23T14:53:12.117" Score="6" Body="&lt;p&gt;&lt;strong&gt;Spherical harmonics&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say you have some data in an array but you want to represent that data with a fewer number of bytes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to do that could be to express the data as a function instead of the raw values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could represent it as a linear function:&#xA;$y=ax+b$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then instead of storing your array of values you could store just $a$ and $b$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Problem is, a linear equation is probably a poor approximation to your data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could try a quadratic instead:&#xA;$y=ax^2+bx+c$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now instead of storing $a$ and $b$, you store $a$, $b$ and $c$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We've increased the memory storage and also the computational complexity of storing and retrieving your data, compared to the linear equation, but it is a better approximation to your array of data.  We could also take it up to a cubic function or higher.  Increasing the order increases the storage, computation and accuracy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Spherical harmonics is a way of making a function that is defined on a sphere instead of an $f(x)$ like I was talking about above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just like in the examples above, you can use a lower order spherical harmonics function to make something with lower storage, and lower computation to calculate data, but also lower accuracy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, you can increase the order and get a better approximation to your original data, but at the cost of more storage space required, and more computation needed to calculate a point of data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the extreme, you can use as many spherical harmonic terms as you had samples in your array, and then you can reconstruct your original array exactly, but you spend a lot of computation doing that, and you're using just as much storage space as you started with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because of this, in practice, spherical harmonics functions don't offer much benefit if you need to represent fine details - like a sharp reflection on a sphere - but they can be cheap for data that doesn't have fine details (data that doesn't have much high frequency content). They're also useful for doing frequency-domain calculations like spectral analysis or convolution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One such data they are good at storing is &quot;irradiance&quot; which is the amount of light hitting a point from other directions. It tends to look a bit blurry, which means it has only low frequency content, and is a good candidate for being stored in a spherical harmonics function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll leave the light probes explanation to another person :p&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="231" LastEditDate="2016-10-23T16:55:54.930" LastActivityDate="2016-10-23T16:55:54.930" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4166" PostTypeId="2" ParentId="4164" CreationDate="2016-10-23T16:06:48.397" Score="17" Body="&lt;h1&gt;Spherical harmonics&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you know what a Fourier transform is, you already almost know what spherical harmonics are: they're just a Fourier transform but on a spherical instead of a linear basis. That is, while a Fourier transform is a different way of representing a function $f(x)$, spherical harmonics are the analogous thing for polar functions $f(\theta, \phi)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't know what a Fourier transform is, you kinda need to know before you can understand spherical harmonics. The Fourier transform lets you represent a signal as a series of sine and cosine waves, each with twice the frequency of the last. That is, you can represent the signal as its average, plus a sine wave whose wavelength is the same as the length of the signal, plus a sine wave twice that wavelength, and so on. Because the Fourier transform fixes you to these particular wavelengths, you only need to record the amplitude of each one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We commonly use Fourier transforms to represent images, which are just 2D digital signals. It's useful because you can throw away some of the sine waves (or reduce the precision with which you store their amplitude) without significantly changing what the image looks like to human eyes. OTOH, throwing away pixels changes the look of the image a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a sampled signal like an image, if you use the same number of sine waves as there were samples (pixels) in the original image, you can reconstruct the image exactly, so once you start throwing away any frequencies, you're making the image take less storage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Spherical harmonics are just like Fourier transforms, but instead of sine waves, they use a spherical function, so instead of linear functions (such as images), they can represent functions defined on the sphere (such as environment maps).&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Light probes&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Just like how a standard image records all the light reaching a certain point through the image plane, a light probe records all the light reaching a certain point from all directions. They first came out of movie effects. If you want to add a computer-generated object to a real-world scene, you need to be able to light the synthetic object with the real-world lighting. To do that, you need to know what light reaches the point in the scene where the synthetic object will be. (N.B. Although I say &quot;lighting&quot;, you're recording an image of &lt;em&gt;all&lt;/em&gt; the light, so it can be used for reflections as well.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because you can't have a camera with a spherical lens that records all the light reaching a single point from all directions, you record this by taking normal photographs of a spherical mirror, and then reprojecting the images onto a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Outside of movie effects, it's more common to use light probes generated from an artificial scene. Imagine you have some expensive algorithm to compute global illumination (GI) in a scene, and you also have some smaller objects moving around in this scene (such as a game level with players in it). You can't run the whole GI algorithm every time any object moves, so you run it once with the static scene, and save light probes taken at various points in the level. Then you can get a good approximation to the GI by lighting the player with whichever light probe they're closest to.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Using them together&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Generally you want to filter out sharp edges in your global illumination anyway, so you want a way to represent them that's compact and easily lets you throw away high frequencies. That's what spherical harmonics are really good at! That's why you'll hear these two terms used together a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You compute light probes with your expensive GI algorithm - typically in the level-design tool, or maybe once per second (instead of once per frame) if you want to include your dynamic objects to. You store those cheaply with spherical harmonics - 16 floats is enough for pretty high quality lighting, but not reflections. Then for each dynamic object you want to light, you pick the nearest light probe (or linearly interpolate several together) and use it as a uniform or constant input to your shader. It's also commonplace to use spherical harmonics to represent ambient occlusion data, and it's very cheap to convolve that with the light probe, though there's some complexity around rotating spherical harmonic functions.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-10-23T16:06:48.397" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4167" PostTypeId="1" CreationDate="2016-10-23T17:17:54.173" Score="1" ViewCount="625" Body="&lt;p&gt;What is the memory consumption for a true color frame buffer (with double buffering) on an XGA display? (&quot;XGA&quot; = 1024 x 768 pixels) How can I calculate this?&lt;/p&gt;&#xA;" OwnerUserId="5345" LastEditorUserId="3003" LastEditDate="2016-10-24T12:17:05.520" LastActivityDate="2016-10-24T12:17:05.520" Title="memory consumption for a true color frame buffer" Tags="&lt;memory&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4168" PostTypeId="2" ParentId="4167" CreationDate="2016-10-24T03:42:10.667" Score="4" Body="&lt;p&gt;True color is 8 bits per color channel, so 3 bytes per pixel.  1024x768 is 785,408 pixels.  At 3 bytes per pixel that is 2,356,224 bytes.  Since it's double buffered we double that number to 4,712,448 bytes which is about 4.5MB.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-10-24T03:42:10.667" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4172" PostTypeId="1" AcceptedAnswerId="8183" CreationDate="2016-10-25T08:57:13.603" Score="7" ViewCount="364" Body="&lt;p&gt;On a PenTile display, the mapping from pixels in the framebuffer to individual subpixels is not trivial. Each pixel in the framebuffer may only have RG and BG subpixels, in some interesting geometric arrangement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to do some subpixel antialiasing of content that will be displayed on a PenTile display, so to get best results I'd like to understand how I can set the values of each pixel in the framebuffer to control the subpixels individually. (N.B. I know the subpixel layout of the display I'm targeting.)&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-04-01T00:52:53.017" Title="How does a PenTile display controller interpret its RGB framebuffer?" Tags="&lt;subpixel-rendering&gt;&lt;pentile&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4173" PostTypeId="5" CreationDate="2016-10-25T09:20:47.160" Score="0" Body="&lt;p&gt;PenTile is a Samsung trademark, and refers to the technology of using an RGBG or RGBW subpixel layout in an LCD, LED, or plasma display. This layout allows the display to achieve higher luminance resolution, which works well because the human eye has much higher luminance than chrominance resolution. It also allows higher resolutions to be quoted in marketing material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information see &lt;a href=&quot;https://en.wikipedia.org/wiki/PenTile_matrix_family&quot; rel=&quot;nofollow&quot;&gt;PenTile on Wikipedia&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Related tags:-&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;/questions/tagged/subpixel-rendering&quot; class=&quot;post-tag&quot; title=&quot;show questions tagged &amp;#39;subpixel-rendering&amp;#39;&quot; rel=&quot;tag&quot;&gt;subpixel-rendering&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2016-10-25T17:12:14.717" LastActivityDate="2016-10-25T17:12:14.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4174" PostTypeId="4" CreationDate="2016-10-25T09:20:47.160" Score="0" Body="Use for questions specific to Samsung's PenTile RGBG or RGBW displays" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2016-10-25T17:11:44.810" LastActivityDate="2016-10-25T17:11:44.810" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4177" PostTypeId="2" ParentId="4164" CreationDate="2016-10-25T17:40:27.673" Score="13" Body="&lt;p&gt;&lt;strong&gt;Basics of Spherical Harmonics&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Spherical Harmonics is a way to represent a 2D function on a surface of a sphere. Instead of spatial domain (like cubemap), SH is defined in frequency domain with some interesting properties and operations relevant to lighting that can be performed efficiently. With increasing &quot;order&quot; of SH you can represent higher frequencies (details) of functions as illustrated in the image below ($l$ is the SH order). By scaling and summing the below &quot;basis functions&quot; you can represent any kind of 2D function on the sphere up to the frequency defined by the functions. The basis functions are defined with &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Associated_Legendre_polynomials&quot; rel=&quot;noreferrer&quot;&gt;associated Legendre polynomials&lt;/a&gt;&quot;, but usually you don't need to derive these yourself but can use existing derivations for &lt;a href=&quot;https://en.wikipedia.org/wiki/Table_of_spherical_harmonics#Real_spherical_harmonics&quot; rel=&quot;noreferrer&quot;&gt;real spherical harmonics&lt;/a&gt;.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/QPNGz.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QPNGz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One such operation that can be performed efficiently in SH is called &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Convolution&quot; rel=&quot;noreferrer&quot;&gt;convolution&lt;/a&gt;&quot;, which means integrating the product of two spherical 2D functions over a sphere. This is a common operation in lighting calculations, e.g. one of the function could be your incident lighting and one function the BRDF. When represented as SH, this operation is simply the dot product of two SH coefficient vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another interesting operation is the ability to do efficient low-pass filtering. Because SH is represented in frequency domain, this is simply the matter of scaling or zeroing out some of the SH coefficients. Some other operations on the other hand can be difficult to perform in SH compared to spatial domain, e.g. if you want to rotate function represented as SH, it can get quite expensive for higher order SH. So it really depends on the problem if it's suitable to be performed in SH or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SH is generally used to represent only low-frequency functions (i.e. smoothly changing functions) because higher frequencies requires increasing the amount of storage (SH coefficients) and processing. This is why you don't see SH being used for example to replace specular reflections on shiny surfaces. There are also &lt;a href=&quot;https://en.wikipedia.org/wiki/Zonal_spherical_harmonics&quot; rel=&quot;noreferrer&quot;&gt;Zonal Spherical Harmonics&lt;/a&gt;, which is can be used to reduce storage &amp;amp; computation for 2D functions that are rotationally symmetric about z-axis, by just storing diagonal elements of the SH coefficient matrix. Also &lt;a href=&quot;http://www.cs.ucf.edu/~ceh/Publications/Papers/Rendering/EGSR04GautronEtAl.pdf&quot; rel=&quot;noreferrer&quot;&gt;Hemispherical Harmonics&lt;/a&gt; can be used if you need to only deal with hemispherical functions (also common in lighting) with the advantage of being able to represent similar frequencies as SH with less coefficients.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One operation you also need to perform is &quot;SH projection&quot; to transform spatial domain data to SH. You can do this operation by performing convolution of spatial domain data with SH basis functions. An interesting property of SH is that unlike spatial domain representations SH doesn't suffer from aliasing, so you don't have aliasing artifacts even when projecting to very low-order SH.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Light Probes&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that you understand the basic operations and properties of SH, we can think how to apply them to GI. A light probe records how much light is coming from every direction to the point where the probe is located. This is a 2D function on a sphere and can be represented as SH (or 3 SH function for red, green and blue). Depending on the amount of lighting details we want to encode into the probes we can choose the SH order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For light probes that are used only for Lambertian diffuse lighting, quite low-order SH is sufficient since the convolution is performed with cosine-lobe, which can be represented with order-2 SH (9 coefficients). The SH coefficients for light probes can be generated simply by rendering a cubemap at the point of the probe and then projecting it to SH.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When rendering geometry, few nearest light probes are taken and their results are interpolated to get the incident lighting function in a point in space. This can be done for example by interpolating the SH coefficients of nearby probes directly and then performing the convolution with pixel normal oriented cosine lobe in SH domain.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-10-26T14:07:09.543" LastActivityDate="2016-10-26T14:07:09.543" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4178" PostTypeId="1" CreationDate="2016-10-25T18:00:00.047" Score="4" ViewCount="1383" Body="&lt;p&gt;How to turn a normal photo like this one : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LhZwE.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LhZwE.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;into a photo that I can use in my game development platform (Unity3D). I just wrap a 3d sphere model with the photo and then it can be all around me when I use it in a VR headset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/G3acL.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/G3acL.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know it's impossible for a car photo, but i just need to convert the space photo into the something like the car photo then retouch the stitching.&lt;/p&gt;&#xA;" OwnerUserId="5357" LastActivityDate="2016-11-25T03:44:07.283" Title="Normal 2D photo to VR-compatible spherical photo" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4179" PostTypeId="1" CreationDate="2016-10-25T21:13:37.410" Score="5" ViewCount="333" Body="&lt;p&gt;I've been introduced to local coordinates in contrast to the global ones which I was used to work on, where we have basically the camera at the origin.&lt;/p&gt;&#xA;&lt;p&gt;For example, I've the following picture of a cube:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MXVuX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MXVuX.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;According to a slides that I've:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;the object is rotated about the x-axis by &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; and then translated by &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;from the object's perspective, the world is first translated by &lt;span class=&quot;math-container&quot;&gt;$–T$&lt;/span&gt; and then rotated about the (object's local) x-axis by &lt;span class=&quot;math-container&quot;&gt;$–R$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Not just the sign but also the order of the transformations changes. Why is that?&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Note: I've some ideas, clearly, but I would like to hear a good answer with a mathematical explanation&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-10-26T09:38:04.843" Title="Why if we rotate an object by R and then translate it with T, from the object perspective, we're actually applying $-T$ and then $-R$" Tags="&lt;raytracing&gt;&lt;transformations&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4180" PostTypeId="2" ParentId="4178" CreationDate="2016-10-26T02:44:43.387" Score="1" Body="&lt;p&gt;There are a few ways you can do it. Basically, you need to get your photo into a format that's suitable for using as an environment map. There are a number of such projections available. The most common ones I've run into for 360° video are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Cube_mapping&quot; rel=&quot;nofollow&quot;&gt;Cube maps&lt;/a&gt; - 6 images that show what the camera would see if it were looking forward, backward, left, right, up and down from the same position.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Equirectangular_projection&quot; rel=&quot;nofollow&quot;&gt;Equirectangular&lt;/a&gt; - the 2nd image you show above is this type of photo. It must be exactly twice as wide as it is tall. The rows and columns of pixels then correspond to the latitude and longitude of the sphere you map it onto.&lt;/li&gt;&#xA;&lt;li&gt;Dual hemispherical - this is when you take a camera (real or virtual) and make an image with a 180° field of view. There are 2 - one for the front and one for the back.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Given the image you have, there are a few ways you could create something useful from it. You could crop it or extend it so that it has a 2x1 aspect ratio and use it as-is. You'll get a weird seam where the left and right meet, but if you are handy with photo editing tools, you can probably modify it to look reasonable. Note that this will give you the correct image for an equirect projection, but it may or may not look how you want. That purple band would never be visible all at once. It would wrap around the entire field of view, for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another option is to make a cube map out of it. You could crop what you have into 3 equal squares for, say, front, left, and right. Then you'd need to generate the other 3 yourself. Generating a star field isn't too difficult either in code or using a photo-editing/compositing tool. Or if you know any artists, perhaps they could help you.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-10-26T02:44:43.387" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4181" PostTypeId="2" ParentId="4179" CreationDate="2016-10-26T04:00:02.440" Score="2" Body="&lt;p&gt;If you have object$\rightarrow$world space transformation matrix:&#xA;$$M=T*R$$&#xA;then inverse (i.e. world$\rightarrow$object) of this transformation matrix is:&#xA;$$M^{-1}=(T*R)^{-1}=R^{-1}*T^{-1}$$&#xA;So the order of multiplication of matrix inverses is reversed per &lt;a href=&quot;http://mathworld.wolfram.com/MatrixInverse.html&quot; rel=&quot;nofollow&quot;&gt;matrix inversion rules&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-26T04:00:02.440" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4182" PostTypeId="2" ParentId="4179" CreationDate="2016-10-26T09:30:02.913" Score="1" Body="&lt;p&gt;The matrix contains a description to move form one space to another. The implied assumption is that there is some parent space which the matrix is defined in. There can be arbitrary chains of these parent child relationships. So you need to know the parent of the matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The matrix multiplications $M \cdot \vec{v}$ describes the vector $\vec{v}$ in child space $M$ as seen by the parent space. The inverse $M^{-1} \cdot \vec{v}$  does the reverse of this it describes the vector in parent space in terms of child space coordinates. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So simply if you make a tree out of your parent child relationships when you move towards the root of your tree (World) you use non-inverted matrices, and when you move in the opposite direction (towards a leaf/child node) you take the inverse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why would you need the inverse? Well because you want to move two things independently of each other but still use the results in one space. For example imagine a world with one object and a camera. Its efficient to be able to model the camera separately. But then the vectors need to move form object space  to camera space. So you take the object space move to world (moving towards root non inverted multiplication) and then you move that to camera space (move towards a child of world use inverse) so you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$T_{camera}^{-1} \cdot (T_{object} \cdot \vec{v}) = T_{camera}^{-1} \cdot T_{object} \cdot \vec{v}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;(Please note that matrix multiplication order depends on whether you define vector as row or column matrices. Both are fine mathematically as is storing the sub vectors in arbitrary order inside the matrix)&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-10-26T09:38:04.843" LastActivityDate="2016-10-26T09:38:04.843" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4183" PostTypeId="2" ParentId="4094" CreationDate="2016-10-26T15:57:53.633" Score="5" Body="&lt;p&gt;I've tried to figure this out as well, but I don't think there is a solution that is just as performant as tracing one sphere.  Basically you would want to cast one ray to hit a infinite set of repeating spheres with no marching iteration.  That would be awesome but is not possible:  Let me explain.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt; &lt;/h1&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Ray-tracing&lt;/strong&gt; is basically finding the analytical solution to this equation:&#xA;$$&#xA;f(\vec{r(t)}) = 0 \ for \ t&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $f(\vec{p})$ is the implicit surface function (which gives the distance the given point $\vec{p}$ is from the surface) and $\vec{r(t)}$ is the parametric ray equation ($\vec{r(t)} = \vec{origin} + \vec{direction}*t$).  $t$ would represent the distance along the ray the intersection happens.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to ray-trace domain manipulations (like repeating space), these domain manipulations need to be present in the implicit surface function $f(\vec{p})$ while finding an analytical solution.  Let's take a 3D repeating sphere for instance.&#xA;$$&#xA;f'(\vec{p}) = \|\vec{p}\bmod \vec{d}\| - r&#xA;$$&#xA;(where $\vec{d}$ is a constant representing the grid size and $r$ is the radius)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to solve $f'(\vec{r(t)}) = 0$ for $t$ we would need the inverse of the modulo operator which doesn't really exist : &lt;a href=&quot;http://mathforum.org/library/drmath/view/51619.html&quot; rel=&quot;noreferrer&quot;&gt;http://mathforum.org/library/drmath/view/51619.html&lt;/a&gt;.  That means there is no analytical solution to this equation, but there is a numerical one. Hence &lt;strong&gt;Ray-marching&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt; &lt;/h1&gt;&#xA;&#xA;&lt;p&gt;This is true for a lot of cool distance functions you see on shadertoy.com, the analytical solution does not exist for these surfaces so you cannot ray-trace.&lt;/p&gt;&#xA;" OwnerUserId="5362" LastActivityDate="2016-10-26T15:57:53.633" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4184" PostTypeId="1" CreationDate="2016-10-26T18:12:36.027" Score="1" ViewCount="119" Body="&lt;p&gt;This is related to &lt;a href=&quot;https://stackoverflow.com/questions/40268554/texture-coordinates-for-part-of-model&quot;&gt;question on SO&lt;/a&gt; &lt;em&gt;(but the purpose of this question is different)&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have model with &lt;em&gt;UVs&lt;/em&gt; (3DS max UVW editor screenshot)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zOJrI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zOJrI.jpg&quot; alt=&quot;3dsmax uvws editor screenshot&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have grouped some unused parts of &lt;em&gt;UVs&lt;/em&gt; on the top right corner. &lt;em&gt;Bump map&lt;/em&gt; is 512x512 (large enough), so Id like to decrease its dimensions if possible (e.g. tile a texture of smaller size). Currently I am using only &lt;em&gt;bump map&lt;/em&gt; for the top part of the object and this solution is enough for now, but I want to improve it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am asking for advice:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;How to optimize this &lt;em&gt;UVs&lt;/em&gt; mapping to be more universal and applicable for future usage (best practice/article/advice/example/other, leading to right direction)?&lt;/li&gt;&#xA;&lt;li&gt;What steps and techniques I will need to do to use multiple &lt;em&gt;UVs&lt;/em&gt; for single object (I would like make each texture obtain all avalable space)?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;P.S. For the second question:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine a cube with image of &quot;sun&quot; on left side, bump map on right side and another combinations of textures on rest sides. Then (in case of single UV) UVs would be divided into 9 parts (6 for each side and 3 unused free space) and each texture (for example image of &quot;sun&quot;) can obtain only a part of texture space and the rest space - empty. Greater dimensions of each texture is needed to get better result. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I am looking for a way to do like so (make each texture use max avalable space):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iOkhI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iOkhI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5363" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2016-10-27T07:29:28.080" Title="Model UVs optimization" Tags="&lt;texture&gt;&lt;optimisation&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4185" PostTypeId="1" AcceptedAnswerId="4186" CreationDate="2016-10-27T03:30:38.907" Score="5" ViewCount="397" Body="&lt;p&gt;I'm curious why spherical harmonics are commonly used in real time graphics instead of a spherical Fourier transform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get that spherical harmonics are in a sort of frequency space (like FT is) so you can do convolution very efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also get that SH is an approximation of a function on a sphere, using up to an infinite series to perfectly reconstruct the original data, but often using only the first few items in the series.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This sounds a lot like a spherical Fourier transform, but the math uses different functions entirely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the benefit of the SH representation over spherical FT?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="2041" LastEditDate="2017-01-05T10:39:23.930" LastActivityDate="2017-01-05T10:39:23.930" Title="Why is spherical harmonics used in low frequency graphics data instead of a spherical Fourier transform?" Tags="&lt;lighting&gt;&lt;fourier-transform&gt;&lt;spherical-harmonics&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4186" PostTypeId="2" ParentId="4185" CreationDate="2016-10-27T08:20:01.903" Score="10" Body="&lt;p&gt;Spherical harmonics really are the &quot;spherical Fourier transform&quot; you're looking for. The kind of hack you mention in comments, of doing a 2D Fourier transform on a lat-long projection, suffers from all the problems you usually have when you try to project a sphere onto a plane: not all spatial relations in the sphere are well-represented in the plane. If you take stretching at the poles as an example, that clearly results in a frequency shift. High-frequency components in the sphere get shifted down to low frequencies in the plane, and when you do the inverse transform, any inaccuracy shows up as high-frequency components at the pole.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Such a transform is useless for analysing the spectrum of the original signal, because it distorts the frequencies (and distorts them differently in different parts of the sphere). It's also poor for representation, because of the introduction of these high-frequency artefacts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Spherical harmonics use different basis functions so they can work directly on the lat-long without treating it like a plane. If you plot the response of the spherical harmonics on a plane projection of the sphere, they look kooky (like a map of the earth does), but they look much more natural on a sphere. They don't suffer from artefacts at the poles, and they don't frequency-shift signals. They're also rotation-invariant, so it doesn't even matter where you put the poles. They don't even have poles, in the sense of discontinuities, which is a property you can't achieve from a plane projection however many &lt;em&gt;ad hoc&lt;/em&gt; co-ordinate transforms you do. Rotation-invariance is useful for applications like environment maps, where you'd like to rotate the spherical-harmonic transform of the environment (light probe, or whatever) into the local co-ordinate system before feeding it to the shader. There isn't a projection onto the plane that has this property.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2016-10-27T22:49:43.190" LastActivityDate="2016-10-27T22:49:43.190" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4188" PostTypeId="1" AcceptedAnswerId="4189" CreationDate="2016-10-27T14:39:12.590" Score="3" ViewCount="89" Body="&lt;p&gt;I would like to ask about uniform (periodic) cubic B-splines (approximation, no interpolation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$B=1/6\begin{bmatrix}-1&amp;amp;3&amp;amp;-3&amp;amp;1\\3&amp;amp;-6&amp;amp;3&amp;amp;0\\-3&amp;amp;0&amp;amp;3&amp;amp;0\\1&amp;amp;4&amp;amp;1&amp;amp;0\end{bmatrix}$$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$B$ is the matrix of coefficients that allows calculating a single curve segment with the formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ Q_i(u)=[u^3 u^2 u^1 1]B \begin{bmatrix}P_{i-3}\\P_{i-2}\\P_{i-1}\\P_{i}\end{bmatrix} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When $i=3$ I calculate the first segment of the curve. My question is when $i=4$ and I want to calculate the second segment of the curve I must change the $4$ control points but does $B$ change or not? &lt;/p&gt;&#xA;" OwnerUserId="4981" LastEditorUserId="231" LastEditDate="2016-10-27T15:28:01.333" LastActivityDate="2017-07-09T10:55:46.910" Title="Does the blending matrix change between calculating various curve segments in a uniform cubic B-splines approximation?" Tags="&lt;interpolation&gt;&lt;curve&gt;&lt;mathematics&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4189" PostTypeId="2" ParentId="4188" CreationDate="2016-10-27T17:42:26.637" Score="2" Body="&lt;p&gt;No, the $B$ matrix (basis coefficient matrix) does not change from one segment to the next. It is a property of the type of spline you're using, in this case cubic B-splines. If you used Bézier splines or Hermite splines instead, you'd have a different $B$ matrix.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-10-27T17:42:26.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4190" PostTypeId="2" ParentId="4188" CreationDate="2016-10-27T17:42:52.457" Score="2" Body="&lt;p&gt;No, $B$ is constant for given type of cubic spline, e.g. B-spline, Bezier, Hermite or Catmull-Rom cubic splines have different $B$ matrix. To make B-spline continuous, you need to copy 3 control points from the previous spline segment $a$ to the control points of spline segment $b$ and add a new point as the last control point of $b$ such that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Pb_{i-3}=Pa_{i-2}$, $Pb_{i-2}=Pa_{i-1}$, $Pb_{i-1}=Pa_i$ and $Pb_i$=new control point.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-27T17:42:52.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4191" PostTypeId="1" AcceptedAnswerId="4192" CreationDate="2016-10-27T19:56:33.657" Score="6" ViewCount="1042" Body="&lt;p&gt;So in the class I've learned that Aliasing refers to the jagged edges resultant from the discrete nature of computer graphics way of representation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I know that Anti-aliasing refers to a technic (mainly of blurring) to remove (our camouiflage) aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I was presented a question about &quot;A picture flickering in a game room when the user moves&quot; and the answer was given as being an aliasing problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did not get the relation between flickering and aliasing. Can someone clarify it to me?&lt;/p&gt;&#xA;" OwnerUserId="5367" LastActivityDate="2016-10-27T20:06:16.797" Title="What is the relation between Aliasing and Flickering?" Tags="&lt;antialiasing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4192" PostTypeId="2" ParentId="4191" CreationDate="2016-10-27T20:06:16.797" Score="8" Body="&lt;p&gt;Flickering can be a form of &lt;em&gt;temporal&lt;/em&gt; aliasing. It's a similar phenomenon to spatial aliasing such as jaggies, but it occurs in time instead of space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, a common cause of image flickering in graphics is when the camera or geometry is in motion, and geometric features fluctuate in pixel size as they move. For example, imagine a railing with thin vertical bars. Depending where a bar appears relative to the pixel grid, it might get rendered as 2 pixels wide, only 1 pixel wide, or it might not appear at all. And in motion, it may rapidly fluctuate between these states, creating a visually objectionable flicker.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another common cause of image flickering is specular surfaces with a bumpy normal map and a high specular power. The specular highlights can flicker in motion, due to their alignment with pixels changing from frame to frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Antialiasing strategies that address only spatial aliasing will often produce an image that looks good in a static screenshot, but turns into a flickery mess as soon as things start moving. This is one reason why &lt;a href=&quot;https://en.wikipedia.org/wiki/Temporal_anti-aliasing&quot;&gt;temporal antialiasing&lt;/a&gt; has become popular in games in recent years.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-10-27T20:06:16.797" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4193" PostTypeId="1" AcceptedAnswerId="4194" CreationDate="2016-10-28T00:52:00.050" Score="4" ViewCount="13100" Body="&lt;p&gt;This is a rather primitive question coming from an electronic engineer. When applying rotate (about origin), scale (in which we shall translate towards origin and then back) and translate, does it matter in what order we do it? Why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically in my case I have an image in coordinate space that goes from -2 to +2 in x and -1.5 to +1.5 in y to get ration of 4:3. This range comes from how the original mandelbrot set is plotted. I need to scale and translate this to fit into an axes (of pixels) in bitmap that goes from 0 to 800 in x axis and 0 to 600 in y axis. I am trying to understand what matrix to use to scale and translate the points from my mandelbrot set into the bitmap image.&lt;/p&gt;&#xA;" OwnerUserId="5371" LastActivityDate="2016-10-28T13:25:27.570" Title="What is the correct order of transformations scale, rotate and translate and why?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4194" PostTypeId="2" ParentId="4193" CreationDate="2016-10-28T02:43:22.807" Score="10" Body="&lt;p&gt;Usually you scale first, then rotate and finally translate. The reason is because usually you want the scaling to happen along the axis of the object and rotation about the center of the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case you don't really need to worry about this generic solution though, but you only need to map range [0, 800] $\rightarrow$ [-2, 2] for x-coordinate and [0, 600] $\rightarrow$ [-1.5, 1.5] for y-coordinate, in order to map screen coordinates to real/imaginary components for Mandelbrot calculation. So this is simply done by:&#xA;$$real=4*(x+0.5)/800-2$$&#xA;$$imag=3*(y+0.5)/600-1.5$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that you need to calculate Mandelbrot coordinates from screen coordinates and not the other way around. This is to ensure that you evaluate the Manderbrot equation for each pixel exactly once and are not left with holes in the image or do double evaluation per pixel.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-10-28T13:25:27.570" LastActivityDate="2016-10-28T13:25:27.570" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4195" PostTypeId="2" ParentId="4133" CreationDate="2016-10-28T07:59:48.507" Score="0" Body="&lt;p&gt;As I am working with Unity, I found an interesting way of calculating the parallax offset inside the engine. It's not physically based but it gives better results than the classic parallax refraction.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 ParallaxOffset(half h, half height, half3 viewDir)&#xA;{&#xA;    h = h * height - height / 2.0;&#xA;    float3 v = normalize(viewDir);&#xA;    v.z += 0.42;&#xA;    return h * (v.xy / v.z);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2016-10-28T07:59:48.507" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4196" PostTypeId="1" AcceptedAnswerId="4198" CreationDate="2016-10-29T10:17:19.677" Score="7" ViewCount="2473" Body="&lt;p&gt;After reading a wikipedia article about &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Global_illumination&quot;&gt;Global Illumination&lt;/a&gt;&lt;/strong&gt; It mentions a variety of techniques like Ray Tracing, Path Tracing and Ambient Occlusion. One technique it mentions is &lt;strong&gt;Radiosity&lt;/strong&gt; which I don't know much about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After a quick google search I found this &lt;a href=&quot;https://mynameismjp.wordpress.com/2011/01/31/radiosity-dx11-style/&quot;&gt;&lt;strong&gt;blog post&lt;/strong&gt;&lt;/a&gt; which discusses what it is, a basic overview &amp;amp; implementation details. However I'm still a little confused. So from what I gather it is a way to precompute diffuse lighting on to a lightmap &lt;strong&gt;to give the illusion of light bounces?&lt;/strong&gt; Could someone explain it to me over here without all the jargon? Is this technique used alongside techniques like &lt;strong&gt;Image Based Lighting &amp;amp; Ambient Occlusion&lt;/strong&gt; or is it intended to be an entire Global Illumination technique by itself? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-08-17T20:22:34.490" Title="What is Radiosity?" Tags="&lt;lighting&gt;&lt;physically-based&gt;&lt;global-illumination&gt;&lt;ambient-occlusion&gt;&lt;radiosity&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4197" PostTypeId="1" AcceptedAnswerId="4207" CreationDate="2016-10-29T11:35:43.407" Score="3" ViewCount="1679" Body="&lt;p&gt;&lt;strong&gt;When I set up a texture as float it works (color is written -  BTW I'm doing voxelization):&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, width, height, depth, 0, GL_RGBA,GL_FLOAT,NULL);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then setting filtering...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then binding:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;writing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(rgba32f ,binding = 0) uniform image3D geometryGrid;&#xA;...&#xA;imageStore(geometryGrid, index, ivec4(1.0)); //ivec4 or vec4, it works&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;reading:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler3D geometryTexture;&#xA;...&#xA;vec4 g = texture(geometryTexture, geomCoords);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;But I want to use an integer texture (so in future I can do binary voxelization and bitwise operations - each bit = slice in z direction). I set it up like that:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then setting filtering...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then binding:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32I);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;writing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(rgba32i ,binding = 0) uniform iimage3D geometryGrid;&#xA;...&#xA;imageStore(geometryGrid, index, ivec4(1.0));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;reading (same as float):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler3D geometryTexture;&#xA;...&#xA;vec4 g = texture(geometryTexture, geomCoords);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then it's black. Whats wrong with that? There is sparse documentation about it. BTW The info that &lt;code&gt;iimage&lt;/code&gt; is for integer texture, &lt;code&gt;uimage&lt;/code&gt; is for unsigned int is actually nowhere to be found.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="231" LastEditDate="2016-10-29T23:29:51.577" LastActivityDate="2016-11-13T13:04:45.717" Title="Setting up integer texture and binding as image" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4198" PostTypeId="2" ParentId="4196" CreationDate="2016-10-29T17:43:48.003" Score="3" Body="&lt;p&gt;Radiosity is a way to calculate diffuse GI, i.e. every surface is assumed to be Lambertian surface without specular component. In the radiosity algorithm you split surfaces into small patches and calculate &quot;form factor&quot; between two patches, which defines how much energy is transferred from one patch to the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The form factor between patches is calculated using the distance between patches (patches further apart means less energy transferred between them), their respective orientation (two patches facing each other transfer more energy than when they face away from each other), the visibility (if patch is occluded, it doesn't transfer energy to the patch) and their size (larger surfaces emit more energy). The form factor obeys reciprocity which means that the factor for patches A and B can be used for energy transmission calculation from A to B and from B to A.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Yh4v5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Yh4v5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To calculate radiosity for a patch, you iterate through all patches and accumulate the energy from other patches using their respective form factors and the luminance of each patch. This is a single iteration of the radiosity algorithm, and for multiple light bounces you can run multiple iterations of this same algorithm. This can be implemented for example by rendering scene around each patch to a hemicube and accumulating the result from the cube for each patch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer your question if radiosity is a full GI solution - no it's not. Since all surfaces are Lambertian, there's no specular component to it, so you would need to use other techniques in addition for the full lighting solution. The result of radiosity is usually also cached into lightmaps with limited resolution so you may need to use AO to provide higher frequency lighting details.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="4958" LastEditDate="2017-08-17T20:22:34.490" LastActivityDate="2017-08-17T20:22:34.490" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4199" PostTypeId="2" ParentId="4197" CreationDate="2016-10-30T04:01:22.353" Score="1" Body="&lt;p&gt;Instead of sampler3D, you should use isampler3D to sample integer formats as described in the &lt;a href=&quot;https://www.opengl.org/wiki/Sampler_(GLSL)&quot; rel=&quot;nofollow&quot;&gt;GLSL documentation&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-10-30T04:01:22.353" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4200" PostTypeId="1" AcceptedAnswerId="4218" CreationDate="2016-10-30T17:37:47.637" Score="4" ViewCount="482" Body="&lt;p&gt;I have some classic texture coordinates and as a normal behaviour they follow the mesh's transformations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to use the same texture coordinates behaviour but without being affected by the mesh rotation transformation. The results would be a sort of texture coordinates projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know if my explanations are well explained but how could I achieve such effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bTlg5.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bTlg5.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-10-31T10:48:04.810" LastActivityDate="2016-11-02T15:10:39.593" Title="Texture coordinates projection" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;real-time&gt;&lt;hlsl&gt;&lt;uv-mapping&gt;" AnswerCount="3" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4201" PostTypeId="2" ParentId="4200" CreationDate="2016-10-30T20:24:28.240" Score="1" Body="&lt;p&gt;GLSL has built-in &lt;a href=&quot;https://www.opengl.org/wiki/Built-in_Variable_(GLSL)#Fragment_shader_inputs&quot; rel=&quot;nofollow&quot;&gt;fragment shader inputs&lt;/a&gt;, and one of them is gl_FragCoord. You can get the $x$ and $y$ value from this and use that as the lookup coordinate of the texture map in a sequence of two passes, but that could be a good or bad thing depending on the application (such as caching the result). This would both be rotation invariant while allowing you to scale and move the mesh.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;First Pass&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Transform the mesh without rotation. Bind a texture to the fragment shader and write the interpolated UV coordinates to it.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Second Pass&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Transform the mesh correctly this time. Bind the texture from the last pass and read from it this time. You preserved the old UV coordinates, and now you can use these to look up whatever texture you have before. Obviously, this works best with a mesh that's a sphere (such as an eye).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 texCoords = gl_FragCoord.xy; // do some sort of scaling&#xA;vec2 oldTexCoords = texture(samplerOfUVTexture, texCoords); // sample UV&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now you have both the old UV coordinates and the new UV coordinates. You can use the new UV coordinates for you diffuse map and the old UV coordinates for the occlusion map.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-11-01T03:08:38.110" LastActivityDate="2016-11-01T03:08:38.110" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4203" PostTypeId="2" ParentId="4066" CreationDate="2016-10-31T14:47:48.667" Score="15" Body="&lt;p&gt;D3D12 has 4 separate kinds of command lists: direct, bundle, compute, and copy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan has similar concepts, but they happen in a different way. Command buffers are allocated from command pools. And command pools are directly associated with a queue family. And command buffers allocated from a pool can only be submitted to the queue family for which the pool was built.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Queue families specify the kinds of operations that the queue can take: graphics, compute, or memory copying operations. D3D12's command queues have a similar concept, but D3D12's command list API has you to specify the list type. Vulkan's gets this information from the queue family the pool is meant for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The D3D12 &quot;bundle&quot; command list type seems similar on the surface to Vulkan secondary command buffers. However, they are quite different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The principle difference is this: bundles inherit &lt;em&gt;all state&lt;/em&gt; from their executing direct command list, except for the bound PSO itself. This includes resource descriptor bindings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan secondary command buffers inherit &lt;em&gt;no state&lt;/em&gt; from their primary command buffer execution environment, except for secondary CBs that execute in a subpass of a renderpass instance (and queries). And those &lt;em&gt;only&lt;/em&gt; inherit the current subpass state (and queries).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means you do different things with them, compared to D3D bundles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bundles are sometimes used to modify descriptor tables and render stuff, on the assumption that the direct command list they're executed within will have set those tables up. So bundles are kind of like light-weight OpenGL display lists, only without all of the bad things those do. So the intent with bundles is that you build them once and keep them around. They're supposed to be small things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan secondary CBs are essential for threaded building of commands intended for a single render pass instance. This is because a render pass instance can only be created within a primary CB, so for optimal use of threads, there needs to be a way to create commands meant to execute in the same subpass in different threads. That's one of the main use-cases of secondary CBs. So the intent is that you'll probably build secondary CBs each frame (though you can reuse them if you want).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in the end, bundles and secondary CBs are intended to solve separate problems. Bundles are generally dependent on the executing environment, while secondary CBs are more stand-alone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the same time, Vulkan secondary CBs can do something bundles cannot: they can execute on compute/copy-only queues. Since Vulkan makes a distinction between the primary/secondary level of the command buffer and the queues where that CB can be sent, it is possible in Vulkan to have secondary command buffers that execute on compute or copy-only queues.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Direct3D 12 can't do that with bundles. The &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn903882(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;ExecuteBundle&lt;/code&gt; function&lt;/a&gt; can only be called on a direct command list. So a copy-only command list cannot execute bundles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Granted, because Vulkan doesn't inherit anything between secondary CBs except for subpass state, and compute/copy operations don't use render passes, there isn't much to be gained from putting such commands in a secondary CB rather than a primary one.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;D3D12 has the same separation between &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn788663(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;compute pipelines&lt;/a&gt; and &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn770348(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;graphics pipelines&lt;/a&gt; that Vulkan does. However, when issuing commands, D3D12 has only one pipeline binding point, to which you can bind any kind of pipeline. By contrast, Vulkan has separate binding points for compute and graphics pipelines. Of course, Vulkan doesn't have different descriptor binding points for them, so the two pipelines can interfere with one another. But if you design their resource usage carefully, it is possible to invoke a dispatch operation without disturbing the needs of the graphics pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So overall, there's no real difference in pipeline architecture here.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-02-03T04:49:49.170" LastActivityDate="2017-02-03T04:49:49.170" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4204" PostTypeId="2" ParentId="4200" CreationDate="2016-10-31T15:32:06.603" Score="1" Body="&lt;p&gt;A static occlusion map won't generally work accurately with a dynamic mesh, as you can see. In your case you can separate the occlusion map and instead put it on a static object that wraps around the eye. You can render that object with multiplicative blending and get the effect you want.&lt;/p&gt;&#xA;" OwnerUserId="31" LastActivityDate="2016-10-31T15:32:06.603" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4205" PostTypeId="1" AcceptedAnswerId="4206" CreationDate="2016-10-31T17:36:31.287" Score="4" ViewCount="493" Body="&lt;p&gt;I'm studying Illumination subject these days and I was given a problem which asks to calculate the intensity using phong illumination model. I'm little bit confused whether I should calculate normal vector using after normalize it or as it is. Normal is given below. So if you can please tell me what type of vector I have to use there and if I have to use normalized vectors then it's value. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N=(0,0,-12)$&lt;/p&gt;&#xA;" OwnerUserId="5390" LastEditorUserId="5390" LastEditDate="2016-10-31T17:41:49.880" LastActivityDate="2016-10-31T17:50:37.073" Title="Normal vector in Phong Illumination Model should be normalized?" Tags="&lt;vectors&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4206" PostTypeId="2" ParentId="4205" CreationDate="2016-10-31T17:44:19.880" Score="4" Body="&lt;p&gt;Short answer: yes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Longer answer: yes, because the vectors you’re using are meant to represent directions, not directions-and-distances. Think of it in terms of light: it doesn’t matter how far a photon’s traveled, whether it’s from the sun or from a lamp on your desk—once it arrives at a surface, it’s going to get reflected in exactly the same way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From a mathematical standpoint, you’re making lighting calculations based on the angles between the incoming light, the view point, and the surface normal. The dot product &lt;a href=&quot;https://en.wikipedia.org/wiki/Dot_product#Geometric_definition&quot;&gt;is defined&lt;/a&gt; as the length of the two input vectors multiplied by each other and by the cosine of the angle between them. To get just the angle—which you need for the lighting model—you need to factor out the length of the two vectors, i.e. normalize them.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2016-10-31T17:50:37.073" LastActivityDate="2016-10-31T17:50:37.073" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4207" PostTypeId="2" ParentId="4197" CreationDate="2016-10-31T18:03:40.033" Score="3" Body="&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is not an &lt;a href=&quot;https://www.opengl.org/wiki/Image_Format#Color_formats&quot; rel=&quot;nofollow&quot;&gt;integer image format&lt;/a&gt;. It's an unsigned, normalized, fixed-point image format. For those, you use floating-point image/sampler variables. So for a 3D texture, you would use &lt;code&gt;image3D&lt;/code&gt;, not &lt;code&gt;iimage3D&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want a &lt;em&gt;true&lt;/em&gt; signed integer format, you would do this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32I, width, height, depth, 0, GL_RGBA_INTEGER, GL_INT, NULL);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note two changes. First, the internal format is &lt;code&gt;GL_RGBA32I&lt;/code&gt;, which specifies a 32-bit-per-channel signed integer format. The second is the use of &lt;code&gt;GL_RGBA_INTEGER&lt;/code&gt; for the &lt;a href=&quot;https://www.opengl.org/wiki/Pixel_Transfer#Pixel_format&quot; rel=&quot;nofollow&quot;&gt;pixel transfer format&lt;/a&gt;. Even though you're not actually performing a pixel transfer (since you're passing NULL), you still must use an appropriate format and type. And the &lt;code&gt;_INTEGER&lt;/code&gt; formats must be used if you're transferring to/from a texture with an integer format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you do this, you must of course use the &lt;code&gt;iimage3D&lt;/code&gt; and &lt;code&gt;isampler3D&lt;/code&gt; types in your shaders.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-10-31T18:03:40.033" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4208" PostTypeId="1" AcceptedAnswerId="4217" CreationDate="2016-11-01T10:57:16.097" Score="4" ViewCount="1440" Body="&lt;p&gt;I'm trying to switch between the rendering of two different scenes as fast as possible using OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For all my OpenGL related stuff I wrote a wrapper-class which provides a quite easy way of adding and updating data. Based on the added data it automatically creates the variable naming for the shader. In the past I always used just one instance of this OpenGL class but now I'm trying to use two of them. (Each instance has its own shader program.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I do something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;OpenGLInstance1.AssignModel(*MyModel1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;it automatically adds data and writes into the shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// per vertex attributes &#xA;layout (location = 0) in vec3   position;&#xA;layout (location = 1) in vec3   normals;&#xA;layout (location = 2) in uvec4  BoneIDs;&#xA;layout (location = 3) in vec4   Weights;&#xA;&#xA;// per instance attributes&#xA;layout (location = 4) in mat4   CameraMatrix;           //dynamic&#xA;layout (location = 8) in mat4   ProjectionMatrix;       //dynamic&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I try to do this a second time with an other OpenGL-Class instance and Model:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;OpenGLInstance2.AssignModel(*MyModel2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I get:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// per vertex attributes &#xA;layout (location = 12) in vec3  position;&#xA;layout (location = 13) in vec3  normals;&#xA;layout (location = 14) in uvec4 BoneIDs;&#xA;layout (location = 15) in vec4  Weights;&#xA;&#xA;// per instance attributes&#xA;layout (location = 16) in mat4  CameraMatrix;           //dynamic&#xA;layout (location = 20) in mat4  ProjectionMatrix;       //dynamic&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But since the GL_MAX_VERTEX_ATTRIBS gives a maximum number of attributes of 16, this is not possible.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Question 1&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Each VAO (vertex array object) has some VBO (vertex buffer object) assigned. Is the location indexing of the VBO just in the scope of each VAO (starting again from zero for each VAO) or is it independent of the VAO?&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Question 2&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Do you have a suggestion how to work around this problem while keeping the implementation as generic, reusable and scalable as possible? (Just some general hints, I don't want to bother you with details.)&lt;/p&gt;&#xA;" OwnerUserId="5399" LastEditorUserId="5399" LastEditDate="2016-11-02T09:33:33.487" LastActivityDate="2016-11-02T09:33:33.487" Title="Attribute Location in Multiple Shader Programs" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4211" PostTypeId="1" AcceptedAnswerId="4213" CreationDate="2016-11-01T19:08:07.303" Score="5" ViewCount="428" Body="&lt;p&gt;I'm trying to get a &lt;strong&gt;grey&lt;/strong&gt; linear-RGB-triple that is equally bright as another (colorful) RGB-triple.&lt;/p&gt;&#xA;&lt;p&gt;I have to admit, that there is great confusion for me with all the color stuff, even though I read a lot of wikipedia articles, but I don't really get the big picture. I'm kind of lost and need help.&lt;/p&gt;&#xA;&lt;p&gt;Wikipedia seems to mention a formula to receive the &lt;a href=&quot;https://en.wikipedia.org/wiki/Relative_luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;perceived brightness of a linear RGB color&lt;/a&gt;.&lt;br /&gt;&#xA;So I can measure the brightness of my color and do something like this I suppose:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;public Vector3d get_equally_bright_grey(Vector3d color) {&#xA;    for (double c = 0.0; c &amp;lt;= 1.0; c += 0.001) {&#xA;        Vector3d grey = new Vector3d(c, c, c);&#xA;        if (brightness(color) == brightness(grey)){&#xA;            return grey;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;But there has to be something other :)&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Some context:&lt;/p&gt;&#xA;&lt;p&gt;My input colors were spectral distributions that I converted to XYZ values (after &lt;a href=&quot;http://www.brucelindbloom.com/index.html?Eqn_Spect_to_XYZ.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bruce Lindbloom&lt;/a&gt;).&#xA;Then I have converted those XYZ values to linear RGB (again with &lt;a href=&quot;http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bruce&lt;/a&gt;). And here comes my question.&lt;/p&gt;&#xA;&lt;p&gt;I know that the &lt;code&gt;Y&lt;/code&gt; component of my &lt;code&gt;XYZ&lt;/code&gt; triples is also something like the luminance, but I don't know how I generate a grey color XYZ color from this either..&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;" OwnerUserId="5351" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-05-05T03:54:21.360" Title="Calculate an equally bright grey to a linear RGB colour" Tags="&lt;color&gt;&lt;color-science&gt;&lt;brightness&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4212" PostTypeId="1" CreationDate="2016-10-22T23:19:15.147" Score="12" ViewCount="483" Body="&lt;p&gt;I just tried using &lt;a href=&quot;https://gamedev.stackexchange.com/questions/23625/how-do-you-generate-tileable-perlin-noise/23639#23639&quot;&gt;this approach&lt;/a&gt; to create a tiling 2d simplex noise function with &lt;a href=&quot;http://staffwww.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java&quot; rel=&quot;noreferrer&quot;&gt;Gustavson's java implementation&lt;/a&gt;. The result tiled, but the texture seemed muddy / washed out. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I decided to compare the result of using the 2d, 3d &amp;amp; 4d versions to make a 2d texture by holding any 'extra' dimension parameters at zero. The 4d output looked the same as my tiled 2d output. Furthermore, I noticed a trend: as the dimensions increase, the noise starts to drift away from the min &amp;amp; max toward the average. Here are the results along with their histograms:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qOF9n.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qOF9n.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/D2JD7.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/D2JD7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/St0Ha.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/St0Ha.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I ran across &lt;a href=&quot;https://stackoverflow.com/questions/18885440/why-does-simplex-noise-seem-to-have-more-artifacts-than-classic-perlin-noise&quot;&gt;this post&lt;/a&gt; discussing some artifacts in Gustavson's implementation &amp;amp; wondered if that might be contributing to the problem, so I tried using &lt;a href=&quot;https://gist.github.com/KdotJPG/b1270127455a94ac5d19&quot; rel=&quot;noreferrer&quot;&gt;OpenSimplex noise&lt;/a&gt; instead &amp;amp; got very similar results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's going on here? I'd like to use the 4d simplex noise to make a tiling 2d texture that looks more like the &#xA;regular 2d simplex noise. If necessary I can try to massage the output, but that seems like hack &amp;amp; I'd rather &#xA;treat the problem rather than the symptoms if possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Again, just to clarify, I'm asking: why does the dimensionality seem to affect the final 2D as illustrated?&lt;/p&gt;&#xA;" OwnerUserId="5349" OwnerDisplayName="Pikalek" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2016-11-02T02:14:42.327" Title="Why does increasing simplex noise dimension wash it out?" Tags="&lt;image-processing&gt;&lt;noise&gt;&lt;procedural-generation&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4213" PostTypeId="2" ParentId="4211" CreationDate="2016-11-01T20:44:49.747" Score="5" Body="&lt;p&gt;The easiest way to get the perceived brightness of a color is to calculate the &lt;a href=&quot;https://en.wikipedia.org/wiki/Luma_(video)&quot; rel=&quot;noreferrer&quot;&gt;Luma&lt;/a&gt;. Finding the grey color with the same luma is easy - just set all of the RGB components to the desired luma value. That works because the coefficients for calculating the luma sum up to 1.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public Vector3d get_equally_bright_grey(Vector3d color) {&#xA;    double luma = color.x * 0.299 + color.y * 0.587 + color.z * 0.114;&#xA;    return new Vector3d(luma, luma, luma);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3470" LastActivityDate="2016-11-01T20:44:49.747" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4214" PostTypeId="1" CreationDate="2016-11-01T22:00:30.633" Score="1" ViewCount="70" Body="&lt;p&gt;Given an image - such as a simple JPEG of a person or a landscape - is it possible to produce an algorithm that extracts certain visual features from the input image to produce a unique fingerprints of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think of this as a hash function (such as MD5) that receives an image as input and produces a digest. However in our scenario the digest/hashing result is not from the byte content but rather form the visual representation of the image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An important feature of the visual fingerprint generation is its consistency for different variation of the image. For example the input image could be resized or saved in a different format (e.g., BMP) or with a different compression rate (in the case of JPEG), or with a reduce set of colours (in the case of GIF).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is such an algorithm possible to develop?&#xA;If so what variations can it cover? &#xA;and how accurate such algorithm can become?&lt;/p&gt;&#xA;" OwnerUserId="5401" LastActivityDate="2016-11-01T22:00:30.633" Title="Feature extractions from an image to produce a fingerprint" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="6" ClosedDate="2016-11-02T01:56:41.020" ContentLicense="CC BY-SA 3.0" />
  <row Id="4215" PostTypeId="1" AcceptedAnswerId="4216" CreationDate="2016-11-02T01:04:49.687" Score="4" ViewCount="74" Body="&lt;p&gt;I am doing renders of the inside of a room. I would like to show a &quot;bird's eye&quot; view of the room, from above the ceiling (outside the room), but still see the interior of the room.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F240t.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F240t.jpg&quot; alt=&quot;birds eye view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An easy way of doing this is to simply hide or remove the ceiling surfaces. However, this has the side effect of reducing the amount of lighting in the scene, because the ceiling no longer reflects light into the room. The top corners and edges of the walls also are no longer lit accurately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to render the scene &lt;strong&gt;as if&lt;/strong&gt; the ceiling was there, but without the ceiling actually being (directly) visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a name for this problem, a technique, or material?&lt;/p&gt;&#xA;" OwnerUserId="5403" LastActivityDate="2016-11-02T01:31:01.763" Title="Is there a material that contributes to GI, but isn't directly visible?" Tags="&lt;lighting&gt;&lt;global-illumination&gt;&lt;material&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4216" PostTypeId="2" ParentId="4215" CreationDate="2016-11-02T01:31:01.763" Score="5" Body="&lt;p&gt;You can use single sided triangles for the ceiling so that they are pointing towards the room. This way the ceiling influences the GI in the room but you can see through it when observing from outside&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-02T01:31:01.763" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4217" PostTypeId="2" ParentId="4208" CreationDate="2016-11-02T03:35:03.927" Score="2" Body="&lt;p&gt;Each VAO, and shader for that matter, has a separate space of attribute locations. It's perfectly fine to have multiple shaders use the same attribute locations. Indeed, it's a good idea to do so if those attributes conceptually mean the same thing to both shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A VAO can be used with a shader if that VAO's attribute locations match those the program expects. Well, technically they don't have to match. It's OK if the VAO provides an attribute that a shader doesn't use. &lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Specification#Non-array_attribute_values&quot; rel=&quot;nofollow noreferrer&quot;&gt;It's more complicated&lt;/a&gt; if a VAO doesn't provide an attribute for a location that the shader expects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So whatever it is that generates your shader prefix strings and VAOs should not be based on what has been generated for other shaders/VAOs. So if you're going to have attributes increase numerically starting from 0, then this should be the case for each independent shader. It should not be based on some constantly increasing global.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-11-02T03:35:03.927" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4218" PostTypeId="2" ParentId="4200" CreationDate="2016-11-02T15:10:39.593" Score="0" Body="&lt;p&gt;I think that I got a solution but I would gladly know if there are some optimizations possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My UVs and local coordinates values are corresponding. I mean that they are in the same range value. That said, I can use my XY vertices values for sampling the occlusion texture. The main problem is that the local coordinates are dependent to the rotation of my object which doesn't solve anything...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To solve that I am converting my local coordinates into world space using a objectToWorld matrix (inverse of current world matrix).&lt;br&gt;&#xA;Then I am converting it back into object space using the inverse TRS matrix but without taking into account the rotation of the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's a bit hacky and I think that I could avoid some steps but this is working.&lt;br&gt;&#xA;Any advice is welcome :)&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2016-11-02T15:10:39.593" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4219" PostTypeId="1" AcceptedAnswerId="4235" CreationDate="2016-11-03T05:38:14.550" Score="1" ViewCount="335" Body="&lt;p&gt;Recently a question that came to my mind was that &lt;strong&gt;How are Physically Based Rendering Techniques researched and developed&lt;/strong&gt;? Do people just use current equations by physicists or do they create their own? Hopefully I've explained my question correctly.&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-11-06T06:32:19.487" Title="How are Physically Based Rendering Methods Researched?" Tags="&lt;rendering&gt;&lt;physically-based&gt;&lt;pbr&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4220" PostTypeId="1" CreationDate="2016-11-03T06:58:06.073" Score="1" ViewCount="28" Body="&lt;p&gt;Suppose I take multiple 360 photos of a room from various locations but from the same height, how can I place them relative to each other?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ex.&lt;br&gt;&#xA;1 - x - 2&lt;br&gt;&#xA;x - 3 - x&lt;br&gt;&#xA;4 - 5 - x  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I shot the photos at 1, 2, 3, 4 and 5 is there any algorithm which can correctly place the images relative to each other by just analyzing them?&lt;/p&gt;&#xA;" OwnerUserId="5412" LastEditorUserId="231" LastEditDate="2016-11-04T16:25:08.310" LastActivityDate="2016-11-04T16:25:08.310" Title="Place images relative to each other based on where they were shot" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="5" ClosedDate="2016-11-04T16:26:52.713" ContentLicense="CC BY-SA 3.0" />
  <row Id="4221" PostTypeId="1" AcceptedAnswerId="4222" CreationDate="2016-11-03T08:22:40.817" Score="5" ViewCount="1781" Body="&lt;p&gt;How can I make an object give the effect that it is giving out light when it isn't? &lt;strong&gt;I basically want to make an object glow&lt;/strong&gt;, for example Neon Lights. Also Area Lights in my engine work properly but to increase how realistic it looks I wanted to give the effect of a haze or glow rather than a flat white rectangle/disk.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This photo basically shows what I want to do perfectly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/09CkX.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/09CkX.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2016-11-04T05:55:54.047" LastActivityDate="2016-11-04T05:55:54.047" Title="Bloom in DirectX" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;directx11&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4222" PostTypeId="2" ParentId="4221" CreationDate="2016-11-03T09:10:03.203" Score="7" Body="&lt;p&gt;This effect is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Bloom_(shader_effect)&quot; rel=&quot;noreferrer&quot;&gt;light bloom&lt;/a&gt;. Its algorithm is usually a variation of the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render your scene (preferably in high dynamic range) to texture.&lt;/li&gt;&#xA;&lt;li&gt;Make a thresholding pass to another texture. I.e. pixels whose brightness is below a certain (configurable) threshold are are turned down to black.&lt;/li&gt;&#xA;&lt;li&gt;Downsample and blur the thresholded pixels. Usually, this is done in several &quot;octaves&quot;, i.e. rendering a Gaussian blur with a small kernel to progressively smaller render targets: from full resolution to half resolution, from half to quarter etc.&lt;/li&gt;&#xA;&lt;li&gt;Composite the downsampled octaves back onto the scene image.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Both the number of octaves used and the Gaussian blur kernel size affect the end result in terms of visual quality and performance, so you may need to do trade-offs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, the glow effect that you seek is usually simply the original scene image, but thresholded and blurred, superimposed back onto the scene image.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-11-03T09:10:03.203" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4223" PostTypeId="2" ParentId="4219" CreationDate="2016-11-03T10:01:47.817" Score="3" Body="&lt;p&gt;The most straightforward method of researching physically based lighting is to grab a light and a camera and start taking pictures of an object from all angles when lit from all angles at varying intensities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then plot out the color values and start fitting a function to that 4+ dimensional data.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-11-03T10:01:47.817" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4224" PostTypeId="2" ParentId="4219" CreationDate="2016-11-03T10:16:39.090" Score="4" Body="&lt;p&gt;I guess physicists, and before that term was used philosophers, have always been thinking about the nature of light, color and shadow. Knowledge about those matters is not purely rooted in people trying to create the ultimate rendering technique for CGI. In &lt;a href=&quot;https://en.wikipedia.org/wiki/Category:Photometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt; there are whole &lt;a href=&quot;https://en.wikipedia.org/wiki/Category:Radiometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;categories&lt;/a&gt; that show formulas and models that were invented to describe attributes of lighting. What programmers do is to try to combine and fit those models into a probably more simple model that can be implemented in some way.&#xA;With the increase in computing power, those models align more and more with the models that were created by physicists to describe lighting in the real world.&#xA;If you look into recent (by that i mean 5 years back) papers that describe physically based rendering techniques, you will see that almost all of them base their algorithms on formulas and units of measure that are somehow used to describe real lighting.&lt;/p&gt;&#xA;" OwnerUserId="5055" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-11-03T10:16:39.090" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4226" PostTypeId="1" AcceptedAnswerId="4227" CreationDate="2016-11-03T19:04:16.233" Score="2" ViewCount="280" Body="&lt;p&gt;I´m looking into uses of high amount of samples in multisampling. If I have an RGBA8 framebuffer and render to it using multisample with many samples, say 32, dithering on per-sample level should yield a reasonably accurate 8-bit color from the 32 samples in 4-bit color when resolved. The spec (4.5) seems a bit scary though (glBlitFrameBuffer): &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If the read framebuffer is multisampled (its effective value of&#xA;  SAMPLE_BUFFERS is one) and the draw framebuffer is not (its value of SAMPLE_BUFFERS is &#xA;  zero), &lt;strong&gt;the samples corresponding to each pixel location in the source are converted&#xA;  to a single sample before being written to the destination.&lt;/strong&gt; filter is&#xA;  ignored. If the source formats are integer types or stencil values, a&#xA;  single sample’s value is selected for each pixel. If the source&#xA;  formats are ﬂoating-point or normalized types, the sample values for&#xA;  each pixel are resolved in an implementation-dependent manner. If the&#xA;  source formats are depth values, sample values are resolved in an&#xA;  implementation-dependent manner where the result will be between the&#xA;  minimum and maximum depth values in the pixel.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What does that even mean? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to do it in a cross implementation defined manner?&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2016-11-06T16:58:35.740" Title="Can I have lower color bit depth in sample buffer than target framebuffer?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;texture&gt;&lt;color&gt;&lt;subpixel-rendering&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4227" PostTypeId="2" ParentId="4226" CreationDate="2016-11-03T20:05:44.903" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;What does that even mean? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It means that multisampling is resolved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A multisample framebuffer contains multiple samples for each pixel. The combination of samples represents the color of that pixel. The process of converting from multiple samples to a single color is multisample resolving.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By blitting from a multisampled buffer to a non-multisampled buffer, you are telling OpenGL to resolve each pixel's worth of samples into a single sample. Typically, this is done by adding all the sample values up and dividing by the number of samples, but implementations can take weighted averages or something else, depending on the precise nature of each sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally speaking, it's best that you let the implementation do its job.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is there a way to do it in a cross implementation defined manner?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You can program your own resolution by rendering with a multisample texture to a non-multisampled texture. In the FS, you read each fragment's worth of pixels, doing whatever operation you would like to combine them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But that's probably not going to be as fast as letting the hardware do the multisample resolve itself.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-11-03T20:05:44.903" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4228" PostTypeId="1" AcceptedAnswerId="4234" CreationDate="2016-11-04T13:08:01.800" Score="4" ViewCount="357" Body="&lt;p&gt;So currently I want to implement radiosity in my engine. After figuring out the amount of light that bounces between elements/disks/patches &lt;em&gt;(I've been told disks are the best - correct me if I'm wrong)&lt;/em&gt; &lt;strong&gt;how do you bake it into a texture?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I set the render target as the size of my texture and modify my  shader to work with UV coordinates? This is really confusing me so &lt;strong&gt;is there another way?&lt;/strong&gt; &lt;strong&gt;Do I even need to bake the light into the textures&lt;/strong&gt;, is hardware good enough these days?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2016-11-05T10:05:42.447" LastActivityDate="2016-11-06T05:37:19.627" Title="How to implement Texture Baking?" Tags="&lt;texture&gt;&lt;radiosity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4230" PostTypeId="1" CreationDate="2016-11-05T11:59:54.150" Score="7" ViewCount="161" Body="&lt;p&gt;I have thought of a triangle sub-division for the purpose of smooth triangulation (no popping) over time on the fly. I think it is very likely the scheme is already invented and has a name but I can´t seem to find it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sub-division is made on triangle edge basis. For each edge longer than a certain threshold, say 1cm on display (i.e. projected space), the edge get two new points a threshold distance (1cm) away from each other. The edge in between the new points are then complete and need no further sub-division. Up to six new points are thus created from the sub-division, but it could be just one edge making two new points. From the points triangles are formed and the sub-division is performed recursively until all edges are shorter than the threshold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Creating two points along the edge a threshold apart is significant for the subdivision to be smooth over time. I don´t see Loop or Catmull Clark doing this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I should probably mention I use this successfully for cartesian meshes in polar projections. Strictly speaking the two points created along an edge may or may not be on the originally projected line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what is it called?&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Explanation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;So I guess I have to explain a few things about cartesian coordinate systems in polar projections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A good example of a polar coordinate system is a flat earth. Earth may look like this in a cartesian system with a huge table on top of it:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SD0qD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SD0qD.png&quot; alt=&quot;earth cartesian&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A polar coordinate system could have the x-axis defined as the angle from earth center to a cartesian coordinate given a plane used to project the earth. The y-axis is then the altitude, either from earth surface or bluntly the distance from earth center. A polar projected version of above image given my description would look like this (with the assumption the earth is spherical, which it is not...):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IZjK8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IZjK8.png&quot; alt=&quot;polar earth&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(please have patience with me not being a great artist.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the table is now bent because in the middle it is closer to the earth center than in the edges (exaggerated, I know).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Without sub-division the table would still be flat in the polar view its altitude would be misleading. A point object on top of the table in cartesian coordinates may be below it in the polar view. The triangle sub-division aim to lessens the error until it is &quot;small enough&quot;. I measure this by projected length on display because it is cheap and has good correspondence to my quality requirements but other schemes would do just as fine or better depending on the polar properties, e.g. likeliness you are interested in accurate altitude far below the earth surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you may realize the error becomes greater the bigger the object and the closer it is to the polar origin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Know to some details of the algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a triangle (in cartesian coordinates) with red and green edge being to long &lt;strong&gt;in the polar view&lt;/strong&gt;, i.e. the red is very close the polar origin, the green not so close and the black quite far away:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vshLw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vshLw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is how triangles would be formed:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XkScF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XkScF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once new points are created their cartesian coordinate is a coordinate along the original edge. The new triangles are fed to the algorithm once more and repeated until the error is small enough. In above image one might suspect the red edge should be partitioned at least one more time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The point in making two control points is to get edge matching behavior without extra edge information. Splitting two adjacent triangles (or lines for that matter) is guaranteed to have the new points on the exact same location with the exact same information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Key feature here is that new triangles does not cross the middle of the original triangle as this would otherwise cause &lt;strong&gt;too much error correction from one frame to another&lt;/strong&gt; as the greatest error is in the middle between control points. Points close to the control point will be least corrected and thus give the least amount of correction to make the error small enough. This is crucial for smooth zooming in any of the axes or even movement of the projected objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Triangulation layout is stable no matter what edges are too long.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Breadth-first recursion is the better way to go if the sub-division is limited by time or memory as edge matching is guaranteed even for interrupted/partial sub-division.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastEditorUserId="231" LastEditDate="2016-11-12T12:20:07.510" LastActivityDate="2016-11-12T12:20:07.510" Title="What is this triangle sub-division scheme called?" Tags="&lt;perspective&gt;&lt;triangulation&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4231" PostTypeId="1" AcceptedAnswerId="4232" CreationDate="2016-11-05T15:17:28.937" Score="3" ViewCount="558" Body="&lt;p&gt;Is it just so you avoid unnecessary divisions or are there other advantages as well?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've just implemented the Sutherland–Hodgman clipping algorithm and read online that you should do homogenization after clipping to avoid divisions and to &quot;avoid messy special cases&quot;. Now I wanted to ask if someone knows what they mean by &quot;messy special cases&quot;.&lt;/p&gt;&#xA;" OwnerUserId="5424" LastEditorUserId="231" LastEditDate="2016-11-05T16:38:19.297" LastActivityDate="2016-11-05T17:34:26.580" Title="Why should you do homogenization after clipping?" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4232" PostTypeId="2" ParentId="4231" CreationDate="2016-11-05T17:34:26.580" Score="3" Body="&lt;p&gt;One good reason to do clipping in homogeneous space is that the perspective division loses the distinction between regions behind the camera and in front of the camera. Points in front of the camera have $w &amp;gt; 0$, and behind the camera $w &amp;lt; 0$. After dividing by $w$, points behind the camera get mapped (with a sign flip) to the same $x, y, z$ NDC space as those in front of the camera. So it is no longer possible to tell the difference; the original sign of $w$ is lost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This implies that at least the $w$ clipping must be done in homogeneous space. For instance, triangles that have one vertex behind the camera must get clipped by the $w = 0$ plane to form a quad. Otherwise, you end up with a bizarre object called an &quot;external triangle&quot;—a triangle that appears in two pieces, both extending to infinity, originating from the in-front-of-camera and behind-camera regions of the original homogeneous triangle. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I suppose that once you have to apply &lt;em&gt;one&lt;/em&gt; of the clipping planes in homogeneous space, you might as well apply &lt;em&gt;all&lt;/em&gt; of them there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For further reading on this, here are a couple of good articles:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.gamasutra.com/view/news/168577/Indepth_Software_rasterizer_and_triangle_clipping.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;In-depth: Software rasterizer and triangle clipping&lt;/a&gt; by Simon Yeung&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://fgiesen.wordpress.com/2011/07/05/a-trip-through-the-graphics-pipeline-2011-part-5/&quot; rel=&quot;nofollow noreferrer&quot;&gt;A trip through the Graphics Pipeline 2011, part 5&lt;/a&gt; by Fabian Giesen&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-11-05T17:34:26.580" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4233" PostTypeId="2" ParentId="4230" CreationDate="2016-11-06T04:54:23.463" Score="4" Body="&lt;p&gt;Instead of subdividing until reaching certain edge length on screen, you should look into GPU Gems 2 article &quot;&lt;a href=&quot;http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter07.html&quot; rel=&quot;nofollow&quot;&gt;Adaptive Tessellation of Subdivision Surfaces with Displacement Mapping&lt;/a&gt;&quot; by Michael Bunnell. It uses edge flatness test to adaptively tessellate the geometry which results in better quality with the same number of triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With your current adaptive tessellation strategy you'll end up splitting flat surfaces, which unnecessarily increases your triangle count. This is particularly bad on GPU's as it increases quad overdraw for the resulting microtriangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About your question for the name of your subdivision scheme, I don't think there is specific name for it but it just falls under more generic &quot;adaptive tessellation&quot;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-11-07T04:38:35.347" LastActivityDate="2016-11-07T04:38:35.347" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4234" PostTypeId="2" ParentId="4228" CreationDate="2016-11-06T05:37:19.627" Score="4" Body="&lt;p&gt;Yes, you should set the lightmap texture as the render target and use UV-coordinates as vertex position coordinates in your shader to bake lighting into lightmaps. This way you'll write the baked lighting data of triangles into the correct lightmap texels that are used for rendering the triangles on the screen. The UV-map should be unique and no triangles should overlap in the UV-space. The lightmap data needs to be also expanded so that when you later use bilinear filtering to fetch the data from the texture that you don't end up having dark borders following triangle edges at UV seams.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of baking indirect illumination into surface lightmaps, you could also use volume textures. Nice thing is that the with volume textures you'll have the indirect illumination data available everywhere in the scene and you don't need unique UV-mapping, but you'll also have less resolution due to the added memory usage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need to bake indirect illumination into textures depends on the complexity of the scene, quality of the lighting and performance/mem usage you want to achieve, so there's no easy answer.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-06T05:37:19.627" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4235" PostTypeId="2" ParentId="4219" CreationDate="2016-11-06T06:32:19.487" Score="4" Body="&lt;p&gt;I think you need to split your question into real-time and offline PBR research.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For real-time PBR it's mostly about finding fast approximations for path traced equivalent. For example we know how to implement area lighting with contact hardening shadows with a simple MC integrator, but finding fast approximation for this is a complex task requiring strong background in mathematics and rendering algorithms/data structures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For offline PBR research I think it's partly about understanding optics and limitations of current PBR algorithms and where the two diverges in a significant &amp;amp; meaningful way in the worlds we try to simulate. For example we know that the microfacet model is an approximations of the more complex way light interacts with surfaces, but are there important situations where this approximation fails in a significant way that we would need a better model?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also even in offline rendering the performance is an issue, and all kinds of clever mathematical techniques needs to be developed and employed to speed up computations. For example calculating multiple scattering in participating media with brute force path tracing is extremely time consuming and clever techniques are needed to make this computation feasible for movies for example. Or techniques such as importance sampling is developed to reduce the computation in an unbiased way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For both real-time and offline PBR research you need sufficient background information in the domain of research and good mathematical/algorithmic toolbox to be able to make any meaningful contribution to the research.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-06T06:32:19.487" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4236" PostTypeId="1" CreationDate="2016-11-06T08:49:45.003" Score="5" ViewCount="213" Body="&lt;p&gt;I am in the middle of a process of implementation of Fortune's algorithm for a Voronoi diagram generating on a plane. &lt;a href=&quot;https://github.com/tomilov/sweepline/blob/develop/sweepline.hpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt; the last C++ debug version. Very rarely I catch (visually) such a bugs:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q3f2j.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q3f2j.png&quot; alt=&quot;bug&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Debugging process of a geometrical algorithms considered very complex by me. I even don't know which runtime checks (&lt;code&gt;assert&lt;/code&gt;-ions) should I add to catch this bugs on the fly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is addressed to those who have tried to implement Fortune's algorithm. I sure, if one faced similar bugs in his implementation somewhere in the middle of a way, then one may remember how to avoid it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the source of the bug? What is the main corner cases (except rectangle mesh, concentric points, etc) can I face?&lt;/p&gt;&#xA;" OwnerUserId="5430" LastEditorUserId="5349" LastEditDate="2016-11-07T06:47:17.437" LastActivityDate="2016-11-07T15:54:20.837" Title="Subtle bugs in Fortune's algorithm implementation" Tags="&lt;computational-geometry&gt;&lt;debugging&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4237" PostTypeId="2" ParentId="4226" CreationDate="2016-11-06T16:58:35.740" Score="0" Body="&lt;p&gt;GPUs compress multisample data (for bandwidth) and dithering would defeat this - so this is not supported. GPUs also have techniques to sample at higher frequencies than they store values (see QUINCUNX anti aliasing for an example that's been around a while), saving overall memory.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2016-11-06T16:58:35.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4238" PostTypeId="2" ParentId="4236" CreationDate="2016-11-07T15:44:53.687" Score="2" Body="&lt;p&gt;&lt;a href=&quot;https://github.com/tomilov/sweepline/commit/ed730b9b34a9c8dfabbb89bf33ecd554ed78aa98#diff-5fd4f98b93359557447770c52fd3d651&quot; rel=&quot;nofollow noreferrer&quot;&gt;This commit&lt;/a&gt; contains the fix of the bug.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, it is wrong to disable event for second edge, during event checking, when first edge may be truncated sooner then stated by its current associated event.&lt;/p&gt;&#xA;" OwnerUserId="5430" LastEditorUserId="5430" LastEditDate="2016-11-07T15:54:20.837" LastActivityDate="2016-11-07T15:54:20.837" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4239" PostTypeId="1" CreationDate="2016-11-08T00:32:18.173" Score="5" ViewCount="1217" Body="&lt;p&gt;I am an electronic engineer. I am trying to design (personal project) a 3D graphics hardware renderer. It shall only render wireframes at this stage, no filling and no shading, not even backface culling and whatever else we take for granted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that the most efficient method to draw a line on screen is via Bresenham's integer line drawing algorithm. Provided that I have implemented the algorithm in VHDL and am able to calculate all pixel values for the line one by one, how do I store them into the frame buffer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;E.g I have 100 lines, I can take say 10 lines and calculate their pixel values in parallel, longer lines will take longer to calculate. Every clock cycle I am able to get the next pixel value for the line, now if I just read 1 byte from memory, overwrite it with the line pixel data and write that byte back and do it for every pixel for every line, that 1 byte read-write method appears to be rather cumbersome and inefficient. So, do you know how it is worked out how to store data into the frame buffer efficiently or do people just use a very fast memory but the actual method is cumbersome and inefficient?&lt;/p&gt;&#xA;" OwnerUserId="5371" LastEditorUserId="231" LastEditDate="2016-11-08T11:25:15.453" LastActivityDate="2016-11-08T11:25:15.453" Title="How is data stored into a frame buffer?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4240" PostTypeId="2" ParentId="4239" CreationDate="2016-11-08T04:25:58.237" Score="5" Body="&lt;p&gt;Real GPUs, like CPUs, have a cache hierarchy. So the rasterizer doesn't directly store to memory, but stores into a cache that eventually gets flushed to memory. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rasterization will usually have some spatial locality (it will generate writes to nearby pixels close together in time), so if those pixels are in the same cache line it will reduce the overall number of memory transactions. This is more effective for filled polygon rasterization than for lines, but even lines have some locality (especially if multiple nearby lines are being rasterized at once).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another trick is to store the framebuffer in a tiled format instead of linearly left-to-right  and top-to-bottom. You'd pick a tile size such as 4×4 or 8×8 and store the pixels in each tile in a contiguous memory block, then make the whole framebuffer out of an array of tiles. This gives you locality in both dimensions, not just one, which improves cache performance. And tiling is easy to do in hardware, as it comes down to just swizzling the order of some X and Y address bits.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-11-08T04:25:58.237" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4241" PostTypeId="1" AcceptedAnswerId="4256" CreationDate="2016-11-09T01:04:07.590" Score="6" ViewCount="391" Body="&lt;h1&gt;Source&lt;/h1&gt;&#xA;&lt;p&gt;In this &lt;a href=&quot;https://developer.nvidia.com/engaging-voyage-vulkan&quot; rel=&quot;noreferrer&quot;&gt;webpage&lt;/a&gt; from Nvidia, the author(s) seems to imply that you could create a command buffer for each eye on separate threads. However, I don't see the benefit to this over instanced stereo rendering since you must also handle synchronization with multiple command buffers.&lt;/p&gt;&#xA;&lt;h1&gt;Possible Synchronization Issues&lt;/h1&gt;&#xA;&lt;p&gt;For synchronization (feel free to correct me if I'm wrong), I was thinking about when using a framebuffer for each eye, kind of the &amp;quot;naive&amp;quot; way of rendering for VR. I suppose though you could just render to one framebuffer like with stereo instanced rendering. Regardless, the issue with synchronization that I'm concerned about would be if one eye finishes considerably faster than the other eye. It seems that with stereo instanced rendering, this would be less likely to happen since the workload is more divisible. The other issue I see where synchronization could cause a performance hit is that you must wait for both threads to complete sending their respective command buffer before sending it again. Arguably, this might not be a huge concern, but it seems unnecessary nonetheless.&lt;/p&gt;&#xA;&lt;h1&gt;Spatial Locality Issues&lt;/h1&gt;&#xA;&lt;p&gt;It also seems that since there isn't a way to guarantee when an object is going through the pipeline that you may get additional cache misses on the GPU compared to instancing here.&lt;/p&gt;&#xA;&lt;h1&gt;Question&lt;/h1&gt;&#xA;&lt;p&gt;Is there any advantage to using multiple command buffers for stereo rendering compared to instanced stereo rendering?&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-11-12T09:33:34.987" Title="Instanced Stereo Rendering vs. Multiple Command Buffers" Tags="&lt;virtual-reality&gt;&lt;vulkan&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4242" PostTypeId="5" CreationDate="2016-11-09T01:23:02.577" Score="0" Body="&lt;p&gt;Common APIs for &lt;a href=&quot;https://en.wikipedia.org/wiki/General-purpose_computing_on_graphics_processing_units&quot; rel=&quot;nofollow noreferrer&quot;&gt;GPGPU&lt;/a&gt; include &lt;a href=&quot;https://developer.nvidia.com/cuda-zone&quot; rel=&quot;nofollow noreferrer&quot;&gt;CUDA&lt;/a&gt;, &lt;a href=&quot;https://www.khronos.org/opencl/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenCL&lt;/a&gt;, and &lt;a href=&quot;https://en.wikipedia.org/wiki/Shader#Compute_shaders&quot; rel=&quot;nofollow noreferrer&quot;&gt;compute shaders&lt;/a&gt; (e.g., via DirectX, OpenGL, and Vulkan).&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-11-09T23:18:29.457" LastActivityDate="2016-11-09T23:18:29.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4243" PostTypeId="4" CreationDate="2016-11-09T01:23:02.577" Score="0" Body="For questions related to the usage of graphics processing units for computation outside of the traditional graphics pipeline but still somewhat related to computer graphics." OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-11-09T23:18:59.153" LastActivityDate="2016-11-09T23:18:59.153" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4244" PostTypeId="5" CreationDate="2016-11-09T01:32:22.783" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Rasterisation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rasterization&lt;/a&gt; is the process of turning shapes into fragments. This is commonly done through &lt;a href=&quot;https://en.wikipedia.org/wiki/Render_output_unit&quot; rel=&quot;nofollow noreferrer&quot;&gt;ROPs&lt;/a&gt; (hardware), but it can be accomplished through software as well.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-11-09T23:19:08.257" LastActivityDate="2016-11-09T23:19:08.257" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4245" PostTypeId="4" CreationDate="2016-11-09T01:32:22.783" Score="0" Body="For questions related to the rasterization process, both in terms of GPU hardware and algorithms related to rasterization." OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2016-11-09T23:18:41.527" LastActivityDate="2016-11-09T23:18:41.527" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4247" PostTypeId="1" AcceptedAnswerId="4249" CreationDate="2016-11-10T07:33:13.057" Score="1" ViewCount="410" Body="&lt;p&gt;I have begun learning how to create a Ray Tracer and 1 thing I am confused about is &lt;strong&gt;how the pixel color from a Ray Tracer is stored into an image&lt;/strong&gt;. Do we use &lt;code&gt;SetPixel&lt;/code&gt; for a Bitmap? Do we use a third party library like &lt;a href=&quot;http://www.libpng.org/pub/png/libpng.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;libpng?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most tutorials don't really explain this well online, so if anyone can explain what the most common method for this is that would be great.&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-11-10T14:31:59.117" Title="How are the colors for each pixel from a Ray Tracer stored in an Image?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;image&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4248" PostTypeId="1" AcceptedAnswerId="4251" CreationDate="2016-11-10T07:44:03.043" Score="15" ViewCount="12759" Body="&lt;p&gt;After reading a few articles online I can confidently say I am clueless on &lt;strong&gt;how Anti-Aliasing works when using Ray Tracing&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All I understand is that &lt;strong&gt;A Single Pixel/Ray is split into 4 sub-pixels and 4 rays rather than 1&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could somebody please explain how this is done (preferably with code)? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="12035" LastEditDate="2020-03-24T22:56:51.860" LastActivityDate="2020-03-28T17:52:30.003" Title="How is Anti Aliasing Implemented in Ray Tracing?" Tags="&lt;raytracing&gt;&lt;antialiasing&gt;&lt;pixels&gt;&lt;ray&gt;" AnswerCount="4" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="4249" PostTypeId="2" ParentId="4247" CreationDate="2016-11-10T09:40:12.813" Score="3" Body="&lt;p&gt;It doesn't matter. All that matters is that you can store information per pixel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In most cases this means allocating a &lt;code&gt;x*y&lt;/code&gt; array of &lt;code&gt;int&lt;/code&gt;s (for 3 byte-sized channels of RGB) to store the pixel values and then feed it into your image compression library of choice to save it out to disk.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-11-10T09:40:12.813" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4250" PostTypeId="2" ParentId="4247" CreationDate="2016-11-10T11:28:06.017" Score="1" Body="&lt;p&gt;Do you use MFC? If so, here's a code snippet to write a red gradient image using MFC's CImage. The top of the image is redder. Because &lt;a href=&quot;https://msdn.microsoft.com/library/52861e3d-bf7e-481f-a240-90e88f76c490.aspx#cimage__create&quot; rel=&quot;nofollow noreferrer&quot;&gt;height is positive&lt;/a&gt;, it's a &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dd407212(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;bottom-up DIB&lt;/a&gt; and higher values of y (in GetPixelAddress()) point to earlier scanlines (i.e. lower in the image):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    const unsigned int imageWidth = 100;&#xA;    const unsigned int imageHeight = 255;&#xA;    CImage img;&#xA;    img.Create(imageWidth,imageHeight,24,0);&#xA;    for(unsigned int x = 0; x &amp;lt; imageWidth; ++x)&#xA;    {&#xA;        for(unsigned int y = 0; y &amp;lt; imageHeight; ++y)&#xA;        {&#xA;            // Note BGR, not RGB!&#xA;            unsigned char* pixelP = static_cast&amp;lt;unsigned char*&amp;gt;(img.GetPixelAddress(x,imageHeight - 1 - y));&#xA;            pixelP[0] = 0;&#xA;            pixelP[1] = 0;&#xA;            pixelP[2] = y;&#xA;        }&#xA;    }&#xA;&#xA;    HRESULT hr = img.Save(&quot;c:\\red.bmp&quot;,Gdiplus::ImageFormatBMP);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There's many image formats, and many different ways to do this. I'll probably migrate away from CImage at some future point...&lt;/p&gt;&#xA;" OwnerUserId="2941" LastEditorUserId="2941" LastEditDate="2016-11-10T11:39:00.527" LastActivityDate="2016-11-10T11:39:00.527" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4251" PostTypeId="2" ParentId="4248" CreationDate="2016-11-10T12:11:49.883" Score="13" Body="&lt;p&gt;I think it's safe to say that there are two different ways of doing AA in raytracing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1: if you have the final image and the depth image it is possible to apply almost all existing techniques that are used in games (FXAA, etc) Those work directly on the final image and are not related to raytracing&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2: the second method is to take into account multiple rays for each pixel and then averaging the result. For a very simple version think of it like this:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;you render first an image of size 1024x1024, one ray for each pixel (for example)&lt;/li&gt;&#xA;&lt;li&gt;after rendering, you scale the image to 512x512 (each 4 pixels are avereged into one) and you can notice that the edges are smoother. This way you have effectively used 4 rays for each pixel in the final image of 512x512 size.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There are other variations on this method. For example you can adapt the number of samples for pixels that are right at the edge of the geometry meaning that for some pixels you will have only 4 samples , and for others 16. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check the links in the comments above.&lt;/p&gt;&#xA;" OwnerUserId="5364" LastActivityDate="2016-11-10T12:11:49.883" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4252" PostTypeId="2" ParentId="4247" CreationDate="2016-11-10T14:31:59.117" Score="3" Body="&lt;p&gt;Depends if you are talking about CPU or GPU ray tracer. For CPU you generally simply allocate an array of width * height float4's (i.e. for RGB &amp;amp; alpha) and for GPU you allocate a texture (e.g. R16G16B16A16F or R32G32B32A32F format). It depends on your case if you really need the alpha though. The target on CPU is then simply accessed by image[(x+y*width)*4] (image=float array), and on GPU image[uint2(x, y)] (image=UAV).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You generally want this target to be a float format (16-bit or 32-bit) to be able to handle high dynamic range (HDR) of luminance in the scene (think of a scene illuminated by Sun = ~100,000 Lux vs Moon = ~1 Lux), that gets then &lt;a href=&quot;https://en.wikipedia.org/wiki/Exposure_value&quot; rel=&quot;nofollow noreferrer&quot;&gt;exposed&lt;/a&gt; using camera settings, &lt;a href=&quot;https://en.wikipedia.org/wiki/Tone_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;tone mapped&lt;/a&gt; and converted to &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB&quot; rel=&quot;nofollow noreferrer&quot;&gt;sRGB space&lt;/a&gt; to be viewable on regular 8bpc devices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are with a very strict with memory budget, you may allocate LDR target (e.g. R8G8B8A8_UNORM) and perform camera exposure, tone mapping &amp;amp; sRGB conversion before writing the result to the render target. This has bunch of issues though, e.g. you would need the camera exposure value prior to rendering, which can be a challenge for camera auto-exposure, so it's generally adviced to use HDR target instead.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-10T14:31:59.117" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4253" PostTypeId="2" ParentId="4248" CreationDate="2016-11-10T15:24:37.807" Score="7" Body="&lt;p&gt;Let's suppose a fairly typical raytracing main loop:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;struct Ray&#xA;{&#xA;    vec3 origin;&#xA;    vec3 direction;&#xA;};&#xA;&#xA;RGBColor* image = CreateImageBuffer(width, height);&#xA;&#xA;for (int j=0; j &amp;lt; height; ++i)&#xA;{&#xA;    for (int i=0; i &amp;lt; width; ++i)&#xA;    {&#xA;        float x = 2.0 * (float)i / (float)max(width, height) - 1.0;&#xA;        float y = 2.0 * (float)j / (float)max(width, height) - 1.0;&#xA;&#xA;        vec3 dir = normalize(vec3(x, y, -tanHalfFov));&#xA;        Ray r = { cameraPosition, dir };&#xA;&#xA;        image[width * j + i] = ComputeColor(r);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;One possible modification of it to do 4 samples SSAA would be:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;float jitterMatrix[4 * 2] = {&#xA;    -1.0/4.0,  3.0/4.0,&#xA;     3.0/4.0,  1.0/3.0,&#xA;    -3.0/4.0, -1.0/4.0,&#xA;     1.0/4.0, -3.0/4.0,&#xA;};&#xA;&#xA;for (int j=0; j &amp;lt; height; ++i)&#xA;{&#xA;    for (int i=0; i &amp;lt; width; ++i)&#xA;    {&#xA;        // Init the pixel to 100% black (no light).&#xA;        image[width * j + i] = RGBColor(0.0);&#xA;&#xA;        // Accumulate light for N samples.&#xA;        for (int sample = 0; sample &amp;lt; 4; ++sample)&#xA;        {&#xA;            float x = 2.0 * (i + jitterMatrix[2*sample]) / (float)max(width, height) - 1.0;&#xA;            float y = 2.0 * (i + jitterMatrix[2*sample+1]) / (float)max(width, height) - 1.0;&#xA;&#xA;            vec3 dir = normalize(vec3(x, y, -tanHalfFov) + jitter);&#xA;            Ray r = { cameraPosition, dir };&#xA;&#xA;            image[width * j + i] += ComputeColor(r);&#xA;        }&#xA;&#xA;        // Get the average.&#xA;        image[width * j + i] /= 4.0;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Another possibility is to do a random jitter (instead of the matrix based one above), but you then soon enter the realm of signal processing and it takes a lot of reading to know how to choose a good noise function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea remains the same though: consider the pixel to represent a tiny square area, and instead of shooting only one ray that passes through the center of the pixel, shoot many rays covering the entire pixel area. The more dense the ray distribution is, the better signal you get.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S.: I wrote the code above on the fly, so I'd expect a few errors in it. It's only meant to show the basic idea.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2020-03-28T17:52:30.003" LastActivityDate="2020-03-28T17:52:30.003" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="4254" PostTypeId="2" ParentId="4248" CreationDate="2016-11-10T17:15:01.400" Score="14" Body="&lt;p&gt;Raxvan is completely right that &quot;traditional&quot; anti aliasing techniques will work in raytracing, including those that use information such as depth to do antialiasing.  You could even do temporal anti aliasing in ray tracing for instance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Julien expanded on Raxvan's 2nd item which was an explanation of super sampling, and showed how you'd actually do that, also mentioning that you can randomize the location of the samples within the pixel but then you are entering signal processing country which is a lot deeper, and it definitely is!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Julien said, if you want to do $N$ samples per pixel, you can break the pixel up into $N$ evenly distributed sample points (on a grid basically) and average those samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do that, you can still get aliasing though.  It is better than NOT doing it, because you are increasing your sampling rate, so will be able to handle higher frequency data (aka smaller details), but it can still cause aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you instead take $N$ random samples within a pixel, you are effectively trading aliasing for noise.  Noise is easier on the eyes and looks more natural than aliasing, so is the preferred result usually.  I believe it's even provably the ideal situation with higher sample counts but don't have more info on that ):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you use just &quot;regular&quot; random numbers like you'd get from rand() or std::uniform_int_distribution, that is called &quot;white noise&quot; because it contains all frequencies, like how white light is made up of all other colors (frequencies) of light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using white noise to randomize the samples within a pixel has the problem that sometimes your samples will clump together.  For instance, if you average 100 samples in a pixel, but they ALL end up being in the upper left corner of the pixel, you aren't going to get ANY information about the other parts of the pixel, so your final resulting pixel color will be missing information about what color it should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A better approach is to use something called blue noise which only contains high frequency components (like how blue light is high frequency light).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The benefit of blue noise is that you get even coverage over the pixel, like you get with a uniform sampling grid, but, you still get some randomness, which turns aliasing into noise and gives you a better looking image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, blue noise can be very costly to compute, and the best methods all seem to be patented (what the heck?!), but one way to do this, invented by pixar (and patented too i think but not 100% sure) is to make an even grid of sample points, then randomly offset each sample point a small amount - like a random amount between plus or minus half the width and height of the sampling grid.  This way you get a sort of blue noise sampling for pretty cheap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this is a form of stratified sampling, and poisson disk sampling is a form of that too, which is also a way of generating blue noise:&#xA;&lt;a href=&quot;https://www.jasondavies.com/poisson-disc/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.jasondavies.com/poisson-disc/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are interested in going deeper you probably will also want to check out this question and answer!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4013/what-is-the-fundamental-reasoning-for-anti-aliasing-using-multiple-random-sample&quot;&gt;What is the fundamental reasoning for anti aliasing using multiple random samples within a pixel?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, this stuff is starting to stray into the realm of monte carlo path tracing which is the common method for doing photorealistic raytracing.  if you are interested in learning more about that, give this a read!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-11-10T17:46:43.577" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4255" PostTypeId="1" AcceptedAnswerId="4257" CreationDate="2016-11-10T20:08:26.250" Score="5" ViewCount="3657" Body="&lt;p&gt;I'm a software engineer and although I currently don't work on anything related to computer graphics, I understand how downscaling works, what I don't understand is why most modern games default to over 100% on my computer (GTX 1080, 1080p@144Hz monitor). For instance, Overwatch defaults to 140% render scale, which translates into a huge performance hit (stable 144 vs 60~80 fps). Why is the game doing this? I understand that downscaling makes the quality of the image a bit better, but this doesn't justify that performance hit. I read in some places that downscaling also helps to reduce some graphics artifacts, can someone please elaborate on this? I would like to know what are the benefits of downscaling and why modern games are defaulting to settings above 100%.&lt;/p&gt;&#xA;" OwnerUserId="5458" LastEditorUserId="2941" LastEditDate="2016-11-11T14:09:28.523" LastActivityDate="2016-11-11T14:09:28.523" Title="What are the benefits of downscaling on modern games?" Tags="&lt;rendering&gt;&lt;render&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4256" PostTypeId="2" ParentId="4241" CreationDate="2016-11-10T20:25:14.683" Score="4" Body="&lt;p&gt;Yes, there are advantages. You can render different command buffers to &lt;em&gt;different queues.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern NVIDIA hardware, in particular, offers a full &lt;em&gt;sixteen&lt;/em&gt; separate queues that are capable of rendering independent graphics operations. By putting each eye in a separate queue, you may be able to use the available hardware resources more efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then again, it may not. It all really depends on how things work out down in the lowest levels of hardware.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Regardless, the issue with synchronization that I'm concerned about would be if one eye finishes considerably faster than the other eye. It seems that with stereo instanced rendering, this would be less likely to happen since the workload is more divisible.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It would basically never happen with instanced rendering. But you say that like it's a &lt;em&gt;good&lt;/em&gt; thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If one eye happens to have more scene complexity than the other eye, then that means instanced stereo rendering will be wasting a lot of vertex processing on vertices for the &quot;weak&quot; eye that will never be seen. Whereas if you built the command buffers separately, you would only submit the stuff that matters for both scenes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you submit both CBs to the same queue, the total time spent processing those CBs can be less than the time spent processing the larger CB, since it isn't computing a bunch of triangles that won't be culled. If you submit the two CBs to different queues, how that balances out depends entirely on how well the hardware can adapt to the workload it is given. If it can adapt well, then you'll be fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So for this particular case, the multiple CB setup may represent a more efficient use of hardware resources. Granted, this particular case is rather rare.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Synchronization for this case is really not a problem. If one eye is so complicated relative to the other that you drop a frame, then it doesn't matter which form you're using to render. You're going to drop a frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With Vulkan, rendering entirely separate stuff to multiple queues isn't difficult. Indeed, the only real synchronization you might need would be to synchronize the presentation of the swapchain images, which is easily done with semaphores.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The other issue I see where synchronization could cause a performance hit is that you must wait for both threads to complete sending their respective command buffer before sending it again.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, you don't. If you're reusing CBs, you can always use the &lt;code&gt;VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT&lt;/code&gt;, which allows you to submit a CB that's already in use. And if you're not reusing CBs (that is, your CBs aren't static), you don't care; just double-buffer your command pools so that you aren't trying to reset a CB that's being consumed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The latter is the general standard method for rendering dynamic scenes with Vulkan.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="231" LastEditDate="2016-11-12T09:33:34.987" LastActivityDate="2016-11-12T09:33:34.987" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4257" PostTypeId="2" ParentId="4255" CreationDate="2016-11-10T21:39:05.430" Score="5" Body="&lt;p&gt;What you are describing is &lt;a href=&quot;https://en.wikipedia.org/wiki/Supersampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;supersampling&lt;/a&gt;, a technique for combating aliasing (a.k.a. jaggies), which is &lt;a href=&quot;https://en.wikipedia.org/wiki/Aliasing&quot; rel=&quot;nofollow noreferrer&quot;&gt;a term from signal theory&lt;/a&gt; that also applies to graphics. It's a spatial domain approach. Basically it means that the sampling resolution (render target pixels in this case) makes signals with different frequencies be reconstructed as the same frequency. Or, in other words, the scene is sampled too infrequently for sub-pixel detail to be properly represented.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is especially prevalent in modern games since the recent advances in GPU computing power have made that quality/performance tradeoff (that you deem unjustified, but unless we're talking VR, everything above 60 FPS is just buttery-smooth and undistinguishable) even possible, and because the (fairly) recently introduced physically-based shading models are much more susceptible to aliasing from sources other than just undersampled geometry: a group of artifacts collectively called &lt;strong&gt;shading aliasing&lt;/strong&gt;, with specular aliasing (a.k.a. fireflies) being especially visible. Epic Games' Brian Karis explains some of that in the opening of &lt;a href=&quot;https://de45xmedrsdbp.cloudfront.net/Resources/files/TemporalAA_small-59732822.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;his presentation on temporal AA in UE4&lt;/a&gt; (temporal AA is just another approach to anti-aliasing, one that distributes samples in time instead of space).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;To sum up:&lt;/strong&gt; it's the &lt;strong&gt;brute force approach to fixing aliasing&lt;/strong&gt;. An anti-aliasing technique that simply captures more samples of the scene, and thus captures more sub-pixel detail that would otherwise be lost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also worth mentioning that while it appears superficially similar to &lt;a href=&quot;https://en.wikipedia.org/wiki/Multisample_anti-aliasing&quot; rel=&quot;nofollow noreferrer&quot;&gt;Multi-Sampled Anti-Aliasing&lt;/a&gt;, it differs in the sampling pattern (SSAA simply increases the pixel grid density, whereas MSAA has a sort of sheared grid pattern) and the sampled signal resolution (SSAA is a full colour capture, MSAA cheats slightly by sampling triangle coverage more finely than colour).&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2016-11-10T21:39:05.430" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4259" PostTypeId="1" CreationDate="2016-11-11T07:44:05.897" Score="5" ViewCount="2459" Body="&lt;p&gt;Recently I have developed and interest in Ray Tracing and like most computer graphics tutorials online there is nothing regarding implementation for a beginner like myself. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I have only done real time rendering (DirectX), however I understand the basics of Ray Tracing but I want to buy a book before proceeding any further. I've taken a look at &lt;a href=&quot;http://www.pbrt.org/&quot; rel=&quot;noreferrer&quot;&gt;Physically Based Rendering: From Theory to Implementation&lt;/a&gt; (I want to learn Ray Tracing with a Physically Based Approach so I thought this would be great) but I don't think it's good for a beginner since there's not much emphasis on the code. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I was learning DirectX 11 everyone recommended Frank Luna's &lt;strong&gt;&lt;a href=&quot;http://www.d3dcoder.net/d3d11.htm&quot; rel=&quot;noreferrer&quot;&gt;Introduction to 3D Game Programming&lt;/a&gt;&lt;/strong&gt;, which was great since it covered all the basics and also a few advanced topics like SSAO with an approach a beginner could understand. Is there something like this for Ray Tracing? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2018-04-09T09:41:07.113" Title="Books to learn Ray Tracing" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;directx11&gt;" AnswerCount="2" CommentCount="6" FavoriteCount="2" ClosedDate="2016-11-11T14:10:46.957" ContentLicense="CC BY-SA 3.0" />
  <row Id="4260" PostTypeId="2" ParentId="4259" CreationDate="2016-11-11T08:28:54.327" Score="5" Body="&lt;p&gt;For an introduction, you can give a look at: &lt;a href=&quot;http://www.raytracegroundup.com/&quot; rel=&quot;noreferrer&quot;&gt;Ray Tracing from the Ground Up&lt;/a&gt; (Amazon link &lt;a href=&quot;http://rads.stackoverflow.com/amzn/click/1568812728&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://vk.com/doc-38203920_232998004&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BmIYm.jpg&quot; alt=&quot;Cover&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It starts really from the basics, and provides simple implementations for the concepts that are gradually introduced.&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2016-11-11T08:28:54.327" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4261" PostTypeId="2" ParentId="4259" CreationDate="2016-11-11T13:29:43.467" Score="3" Body="&lt;p&gt;Not a book, but here's an online write-up about the basics of Monte Carlo path tracing:&#xA;&lt;a href=&quot;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Path Tracing &amp;#8211; Getting Started With Diffuse and Emissive | The blog at the bottom of the sea&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also heard good things a out Peter Shirley's books. In particular &quot;Ray Tracing in one Weekend&quot;&#xA;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/B01B5AODD8&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing in One Weekend (Ray Tracing Minibooks Book 1) Kindle Edition | amazon.com&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T09:41:07.113" LastActivityDate="2018-04-09T09:41:07.113" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4263" PostTypeId="1" AcceptedAnswerId="4264" CreationDate="2016-11-12T19:47:45.837" Score="5" ViewCount="215" Body="&lt;p&gt;I've to rasterize a line taking into account not only the background color of the screen, which is white, but also the color of other objects in the scene. In my case, I've just another object, a sphere, which is actually visualized using a ray tracing technique. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far the code that I have seems only to consider the white background color of the screen and not also the color of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So here's the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// ray tracing of the sphere&#xA;// here we initialize the z-buffer's elements to -1.0 zBuffer that you find below&#xA;...&#xA;&#xA;//&#xA;// rasterize a line&#xA;//&#xA;&#xA;// line from p1 to p2 in LOCAL coordinates&#xA;Point3d p1 (-1.0, 0.0, 0.0);&#xA;Point3d p2 ( 1.0, 0.0, 0.0);&#xA;&#xA;// transformations...&#xA;Matrix4d S  = Matrix4d::scaling (5.0, 1.0, 1.0);&#xA;Matrix4d R1 = Matrix4d::rotation (0.5,'z');&#xA;Matrix4d R2 = Matrix4d::rotation (tau,'x');&#xA;Matrix4d T  = Matrix4d::translation (0.0, 0.0, 8.0);&#xA;&#xA;Matrix4d M  = T*R2*R1*S;&#xA;&#xA;p1 = M*p1;&#xA;p2 = M*p2;&#xA;&#xA;// screen coordinates&#xA;double x1 = ( X + p1.x()/p1.z() ) / s - 0.5;&#xA;double y1 = ( Y - p1.y()/p1.z() ) / s - 0.5;&#xA;double x2 = ( X + p2.x()/p2.z() ) / s - 0.5;&#xA;double y2 = ( Y - p2.y()/p2.z() ) / s - 0.5;&#xA;&#xA;//&#xA;// line rasterization algorithm with anti-aliasing and z-test&#xA;// (for lines with slope between -1 and 1)&#xA;//&#xA;int x  = round(x1);&#xA;int y  = round(y1);&#xA;&#xA;double I0 = 1.0;&#xA;double m = (y2-y1) / (x2-x1);&#xA;&#xA;bool up = true;&#xA;if (y2 &amp;lt; y1) {&#xA;    m = -m;&#xA;    I0 = 0.0;&#xA;    up = false;&#xA;}&#xA;&#xA;int nextY;&#xA;double z;&#xA;for ( ; x&amp;lt;=x2; x++) {&#xA;    if (up)&#xA;        nextY = y+1;&#xA;    else&#xA;        nextY = y-1;&#xA;&#xA;    // barycentric coordinates of the current point: (1-lambda, lambda),&#xA;    // i.e.: x = (1-lambda) x1 + lambda x2&#xA;    double lambda = (x-x1) / (x2-x1);&#xA;&#xA;    // perspectively correct linear interpolation of z-values&#xA;    z = p1.z()*p2.z() / ( (1.0-lambda)*p2.z() + lambda*p1.z() );&#xA;&#xA;    if ( (zBuffer[x+y*w] &amp;lt; 0) || z &amp;lt; zBuffer[x+y*w] ) {&#xA;        int I = (int) 255*I0;&#xA;        image-&amp;gt;setPixel( x, y,     qRgb( 255-I, 255, 255-I ) );&#xA;        image-&amp;gt;setPixel( x, nextY, qRgb(     I, 255,     I ) );&#xA;    }&#xA;&#xA;    if (m &amp;gt; I0) {&#xA;        y  = nextY;&#xA;        I0 += 1.0;&#xA;    }&#xA;    I0 -= m;&#xA;}&#xA;&#xA;// repaint canvas&#xA;repaint();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now the output is not as expected, because one of the pixels of the lines on the sphere is coloured white. Of course we notice this immediately! The idea is to make a smoother line that considers not only the colour of the background but also the colour of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought I need to interpolate colours, but I'm not sure which ones and how to do it. I know that the basic idea of interpolation is to find an intermediate colour between two (or more) colours ($C_1, C_2$) using a formula as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(1 - \alpha) C_1 + \alpha * C_2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the problem is that I don't know what's exactly $\alpha$ and which colours would be $C_1$ and $C_2$.  I thought $\alpha$ could be the &lt;code&gt;lambda&lt;/code&gt; variable in the code above, but this is more than a guess than a conclusion after a logical reasoning. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, I guessed that the colours $C_1$ and $C_2$ are respectively the color of the pixel before the rasterization of the line (i.e. in the ray tracing part), which can also be the color of the sphere, if that pixel is covered by the sphere, or the background color, i.e. white in my case. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To give you an idea, this is the wrong output:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q0tnC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q0tnC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and this should be the correct one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TIUz7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TIUz7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note (if you zoom in) that the line in the first picture is not that smooth over the sphere, because one of the pixels (at least) is colored for the background color white.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After trying to interpolate green and the current background color (as also Nathan Reed suggested), I obtained:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rm0BZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rm0BZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is correct in the sense that I think that the interpolation is being done correctly, but at this point I think interpolation is not what we need to do to obtain a smooth line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To obtain this I just added a few lines when setting the pixels of the line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int I = (int)255 * I0;&#xA;&#xA;Color3d c = pixels_colors[x + y * w]; &#xA;// pixels_buffer contains the color at pixel x + y * w&#xA;// this color was saved while ray tracing the sphere&#xA;&#xA;c.clamped();&#xA;&#xA;int red = c.r() * 255;&#xA;int green = c.g() * 255;&#xA;int blue = c.b() * 255;&#xA;&#xA;image-&amp;gt;setPixel(x, y, qRgb(red - I, green, blue - I));&#xA;image-&amp;gt;setPixel(x, y, qRgb(I, green, I));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 2&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After the corrections suggested by Nathan Reed, I obtained:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3NSRw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3NSRw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The colors of the pixels of the line over the sphere now really seem to be the product of the interpolation between the color green and the color of the sphere. Here's the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int I = (int)255 * I0;&#xA;&#xA;Color3d background_color = pixels_colors[x + y * w];&#xA;Color3d green(0, 1.0, 0);&#xA;&#xA;Color3d color_y = (1 - I0) * background_color + I0 * green;&#xA;Color3d color_next_y = I0 * background_color + (1 - I0) * green;&#xA;&#xA;image-&amp;gt;setPixel(x, nextY, qRgb(color_y.r() * 255, color_y.g() * 255, color_y.b() * 255));&#xA;image-&amp;gt;setPixel(x, y, qRgb(color_next_y.r() * 255, color_next_y.g() * 255, color_next_y.b() * 255));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If this is now correct, the picture still doesn't look as it should. I think we may need to color more pixels?!&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorDisplayName="user7220" LastEditDate="2018-03-05T20:18:52.287" LastActivityDate="2018-03-05T20:18:52.287" Title="How to rasterize a line when the background color is not always white?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;line-drawing&gt;&lt;interpolation&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4264" PostTypeId="2" ParentId="4263" CreationDate="2016-11-12T22:46:14.397" Score="1" Body="&lt;p&gt;You're actually already doing color interpolation in the code you posted, in these expressions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;qRgb( 255-I, 255, 255-I )&#xA;qRgb(     I, 255,     I )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first one is interpolating from white to green by &lt;code&gt;I&lt;/code&gt;, and the second one from green to white by &lt;code&gt;I&lt;/code&gt;. In both cases &lt;code&gt;I&lt;/code&gt; is acting as an integer form of the variable $\alpha$ from the equation. I note that you have already a fractional variable &lt;code&gt;I0&lt;/code&gt; there, which is exactly what's needed for interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if I rewrite your &lt;code&gt;qRgb&lt;/code&gt; expressions a little bit, I can make them look closer to the form of the interpolation equation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(1.0 - I0) * qRgb(255, 255, 255) + I0 * qRgb(0, 255, 0)&#xA;I0 * qRgb(255, 255, 255) + (1.0 - I0) * qRgb(0, 255, 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This hopefully makes it clearer that $C_1$ is the color we're interpolating from, white, and $C_2$ is the color we're interpolating to, green. In the first line $\alpha$ is &lt;code&gt;I0&lt;/code&gt; and in the second, $\alpha$ is &lt;code&gt;1.0 - I0&lt;/code&gt;. Note that interpolating from white to green by &lt;code&gt;1.0 - I0&lt;/code&gt; is equivalent to interpolating from green to white by &lt;code&gt;I0&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, to make this work against an arbitrary colored background, you just have to change white to the actual background color of the pixel you're rasterizing to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Technically, &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2264/how-are-we-supposed-to-fix-brightness-with-square-roots&quot;&gt;gamma correction&lt;/a&gt; should also be applied when interpolating, but that's a relatively minor visual change that you can safely ignore for awhile.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-11-12T22:46:14.397" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4265" PostTypeId="1" CreationDate="2016-11-13T12:04:04.140" Score="4" ViewCount="318" Body="&lt;p&gt;Given a cube defined as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Cube&#xA;{&#xA;    float min[3];&#xA;    float size;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What would be the fastest rasterization method? On the internet I only found methods that used polygons, but I think for only drawing a cube thats extremely ineffective. I don't need any depth information, I want the result to be a shadeless silhouette. &lt;/p&gt;&#xA;" OwnerUserId="5476" LastActivityDate="2016-11-13T17:03:28.437" Title="Non-Polygonal 3D cube rasterization" Tags="&lt;rasterizer&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4267" PostTypeId="2" ParentId="4265" CreationDate="2016-11-13T16:58:26.610" Score="3" Body="&lt;p&gt;Since the cube is a convex object, you could first find the silhouette edges of the cube, by using dot product between cube face normals &amp;amp; view vectors. Then you can sort the edges by the smallest screen y-coordinate for each edge and rasterize the cube a scanline at the time by filling the span between two active edges for each scanline. For each scanline you progress the two edges by adding the edge slopes (x1-x0)/(y1-y0) to the current x-coordinate of the edges.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-11-13T17:03:28.437" LastActivityDate="2016-11-13T17:03:28.437" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4268" PostTypeId="1" AcceptedAnswerId="4331" CreationDate="2016-11-13T19:50:31.847" Score="2" ViewCount="2433" Body="&lt;p&gt;I am trying to figure out how to apply the proper sequence of translate and scale commands (or a single .transform command) so that the default pixel grid (0,0,1920,1080) for instance is setup so that the coordinate system  (minx,miny,maxx,maxy) can be used where for instance &#xA;minx=100 maxx=200 miny=-5 maxy=5&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to render mathematical functions and map the results to pixels and use the mouse to select certain regions to zoom in on.. my current code is at &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://bitbucket.org/stephenc214/fastmath/src/default/src/fastmath/fx/HardyZMap.java&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://bitbucket.org/stephenc214/fastmath/src/default/src/fastmath/fx/HardyZMap.java&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would really appreciate any help... I know this is simple but I just can't seem to get it to work properly&lt;/p&gt;&#xA;" OwnerUserId="5478" LastActivityDate="2016-11-29T21:16:41.657" Title="how to map rectangular coordinate system onto JavaFX GraphicsContext canvas" Tags="&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4269" PostTypeId="1" AcceptedAnswerId="4271" CreationDate="2016-11-13T20:07:07.500" Score="3" ViewCount="189" Body="&lt;p&gt;Made a new question as suggested, follow up to that &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4197/setting-up-integer-texture-and-binding-as-image&quot;&gt;one&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was experimenting with texture declaration to find solution and thats how I done that before (&lt;code&gt;unsigned int&lt;/code&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;m_texture);&#xA;glBindTexture(GL_TEXTURE_3D, m_texture);&#xA;glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32UI, width, height, depth, 0, GL_RGBA_INTEGER, &#xA;GL_UNSIGNED_INT, NULL);&#xA;glGenerateMipap(GL_TEXTURE_3D);&#xA;&#xA;glGenSamplers(1, &amp;amp;m_sampler);&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST );&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST );&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And for that using &lt;code&gt;imagestore&lt;/code&gt; for &lt;code&gt;int&lt;/code&gt;/&lt;code&gt;unsigned int&lt;/code&gt; didnt work despite correct binding for writing as &lt;code&gt;uimage&lt;/code&gt; , &lt;code&gt;rgba32ui&lt;/code&gt;, &lt;code&gt;uvec4&lt;/code&gt; format and for reading as &lt;code&gt;usampler&lt;/code&gt;, &lt;code&gt;uvec4&lt;/code&gt; format. Of course also binding &lt;code&gt;sampler&lt;/code&gt; object for reading.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I added two lines:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;m_texture);&#xA;glBindTexture(GL_TEXTURE_3D, m_texture);&#xA;glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32UI, width, height, depth, 0, GL_RGBA_INTEGER, &#xA;GL_UNSIGNED_INT, NULL);&#xA;&#xA;glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); //&#xA;glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); //&#xA;&#xA;glGenerateMipmap(GL_TEXTURE_3D);&#xA;&#xA;glGenSamplers(1, &amp;amp;m_sampler);&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST );&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST );&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And now it seems to work. Still need to bind &lt;code&gt;sampler&lt;/code&gt; thought. But I fail to see any logic in this. I use &lt;a href=&quot;https://www.opengl.org/wiki/Sampler_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;sampler&lt;/a&gt; objects to set texture filtering not &lt;code&gt;glTexParameteri&lt;/code&gt; functions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Float&lt;/code&gt; textures work with &lt;code&gt;sampler&lt;/code&gt; objects as in first block of code. Anyone can explain?&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-11-14T18:06:49.460" Title="setting up integer texture and binding as image pt. 2" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4270" PostTypeId="2" ParentId="4268" CreationDate="2016-11-13T20:13:16.387" Score="0" Body="&lt;p&gt;You can map [x, y] pixel coordinates in an image of size [width, height] to your given range as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x'=minx+(maxx-minx)*(x+0.5)/width;&#xA;y'=miny+(maxy-miny)*(y+0.5)/height;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-13T20:13:16.387" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4271" PostTypeId="2" ParentId="4269" CreationDate="2016-11-14T16:01:54.830" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I use sampler objects to set texture filtering not &lt;code&gt;glTexParameteri&lt;/code&gt; functions. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, you do not. &lt;a href=&quot;https://www.opengl.org/wiki/Image_Load_Store&quot; rel=&quot;nofollow noreferrer&quot;&gt;Image Load/Store&lt;/a&gt; doesn't use samplers, so you cannot be using sampler objects to set the texture's filtering, when you're using the texture with Image Load/Store.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sure, Image Load/Store doesn't use the &lt;a href=&quot;https://www.opengl.org/wiki/Texture#Texture_Objects&quot; rel=&quot;nofollow noreferrer&quot;&gt;built-in sampler data stored in a texture object&lt;/a&gt; &lt;em&gt;either&lt;/em&gt;. However, those parameters &lt;em&gt;do&lt;/em&gt; have an effect. They can determine if a texture is &lt;em&gt;complete&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And &lt;em&gt;whether you're using those parameters or not&lt;/em&gt;, if a texture is not complete, you can't access the texture from the GPU. Among the texture completeness rules is that the texture's sampling parameters must be valid, with respect to the texture's image format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The default filtering parameters for textures are some form of LINEAR filtering; OpenGL does not change these defaults based on the image format. Therefore, a fresh texture with an integer image format will be incomplete &lt;em&gt;unless&lt;/em&gt; you explicitly set the mag/min filters to &lt;code&gt;GL_NEAREST&lt;/code&gt; (or &lt;code&gt;NEAREST_MIPMAP_NEAREST&lt;/code&gt; for min).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get away with what you have when using the texture with &lt;a href=&quot;https://www.opengl.org/wiki/Sampler_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;sampler objects&lt;/a&gt; because their parameters override the completeness check. But as previously mentioned, Image Load/Store doesn't care about the bound sampler objects. Therefore, the completeness check must look at the texture's sampling parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is regardless of the fact that Image Load/Store itself doesn't actually &lt;em&gt;use&lt;/em&gt; those parameters. So it's pointless, but you've gotta do it.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="231" LastEditDate="2016-11-14T18:06:49.460" LastActivityDate="2016-11-14T18:06:49.460" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4272" PostTypeId="1" AcceptedAnswerId="4353" CreationDate="2016-11-14T19:00:57.030" Score="1" ViewCount="1051" Body="&lt;p&gt;I have a cylinder that has rectangular box regions to mark leakage problems. The location of a rectangular box is determined by its initial position in the longitudinal axis and its initial position in the circumferential axis in degree. The length  and width (in degrees, from 0° to 360°) of the boxes are also available.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I convert this cylinder to a plane surface so that I can find the location of the rectangular boxes in the 2D plane?&lt;br&gt;&#xA;Here I have  three rectangles on the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qMBWR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qMBWR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5482" LastEditorUserId="231" LastEditDate="2016-11-14T22:35:06.023" LastActivityDate="2016-12-05T15:35:43.780" Title="Mapping of cylinder to 2D plane" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4274" PostTypeId="1" CreationDate="2016-11-15T07:32:44.550" Score="3" ViewCount="394" Body="&lt;p&gt;I'm trying to construct a FPS view matrix for my OpenGL renderer using yaw and pitch angles instead of the typical &lt;code&gt;LookAt&lt;/code&gt; view matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The view matrix is the inverse of the camera world transform $\mathbf{M}_{\textrm{view}} = (\mathbf{T}\mathbf{R}_p\mathbf{R}_y)^{-1}$, hence:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\small\begin{align}&#xA;(\mathbf{T}\mathbf{R}_p\mathbf{R}_y)^{-1} &amp;amp;= \mathbf{R}_y^{T}\mathbf{R}_p^{T}\mathbf{T}^{-1} \\&#xA;&amp;amp;= \begin{bmatrix}&#xA;\cos{y} &amp;amp; 0 &amp;amp; \sin{y} &amp;amp; 0 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA;-\sin{y} &amp;amp; 0 &amp;amp; \cos{y} &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}^T&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; \cos{p} &amp;amp; -\sin{p} &amp;amp; 0 \\&#xA;0 &amp;amp; \sin{p} &amp;amp; \cos{p} &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}^T&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; e_0 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; e_1 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; e_2 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}^{-1} \\&#xA;&amp;amp;=&#xA;\begin{bmatrix}&#xA;\cos{y} &amp;amp; 0 &amp;amp; -\sin{y} &amp;amp; 0\\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA;\sin{y} &amp;amp; 0 &amp;amp; \cos{y} &amp;amp; 0\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\&#xA;0 &amp;amp; \cos{p} &amp;amp; \sin{p} &amp;amp; 0\\&#xA;0 &amp;amp; -\sin{p} &amp;amp; \cos{p} &amp;amp; 0\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; -e_0\\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; -e_1\\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -e_2\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\\&#xA;\end{bmatrix} \\&#xA;&amp;amp;=&#xA;\begin{bmatrix}&#xA;\cos{y} &amp;amp; \sin{p}\sin{y} &amp;amp; -\cos{p}\sin{y} &amp;amp; -e_0\cos{y} - e_1\sin{p}\sin{y} + e_2\cos{p}\sin{y}\\&#xA;0 &amp;amp; \cos{p} &amp;amp; \sin{p} &amp;amp; -e_0 \cdot 0 - e_1 \cos{p} - e_2 \sin{p}\\&#xA;\sin{y} &amp;amp; -\cos{y}\sin{p} &amp;amp; \cos{p}\cos{y} &amp;amp; -e_0\sin{y} + e_1\cos{y}\sin{p} - e_2\cos{p}\cos{y}\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;\end{align}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Every step is double checked using WolframAlpha.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The implementation:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;inline Matrix4&#xA;FPSViewRH(const Vector3&amp;amp; eyePosition, float yaw, float pitch) noexcept&#xA;{&#xA;  yaw = Utils::Radians(yaw);&#xA;  pitch = Utils::Radians(pitch);&#xA;&#xA;  const auto sinYaw = std::sin(yaw);&#xA;  const auto cosYaw = std::cos(yaw);&#xA;&#xA;  const auto sinPitch = std::sin(pitch);&#xA;  const auto cosPitch = std::cos(pitch);&#xA;&#xA;  const Vector3 i{cosYaw, sinPitch * sinYaw, -cosPitch * sinYaw};&#xA;  const Vector3 j{0, cosPitch, sinPitch};&#xA;  const Vector3 k{sinYaw, -cosYaw * sinPitch, cosPitch * cosYaw};&#xA;&#xA;  return {&#xA;    {i[0], i[1], i[2], -i.Dot(eyePosition)},&#xA;    {j[0], j[1], j[2], -j.Dot(eyePosition)},&#xA;    {k[0], k[1], k[2], -k.Dot(eyePosition)},&#xA;    {0,    0,    0,    1},&#xA;  };&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It works fine except that &lt;em&gt;the yaw is inverted&lt;/em&gt;, i.e. increasing the angle causes the object to go right while it should go left.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can negate the yaw angle or change every $\sin{y}$ to $-\sin{y}$, but I don't really understand &lt;em&gt;why this is happening&lt;/em&gt;?&lt;/p&gt;&#xA;" OwnerUserId="5488" LastEditorUserId="5488" LastEditDate="2016-11-18T16:31:57.767" LastActivityDate="2017-01-17T18:21:12.723" Title="Inverted yaw angle in the view matrix" Tags="&lt;transformations&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4276" PostTypeId="1" CreationDate="2016-11-15T13:48:27.740" Score="2" ViewCount="128" Body="&lt;p&gt;I've the following problem:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Let the camera opening angle be &lt;span class=&quot;math-container&quot;&gt;$\frac{3}{4}\pi$&lt;/span&gt; and the window be &lt;span class=&quot;math-container&quot;&gt;$15 \times 15$&lt;/span&gt; pixels large.&lt;/p&gt;&#xA;&lt;p&gt;Which pixels does the midpoint algorithm (&lt;em&gt;without&lt;/em&gt; anti-aliasing) set for the line from &lt;span class=&quot;math-container&quot;&gt;$p_1 = (1, 1, 4)$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$p_2 = (2, 1, 1)$&lt;/span&gt;, given in &lt;strong&gt;global coordinates&lt;/strong&gt;?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;My question are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Why is the detail that the points are given in global coordinates important?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Could the points be given in local coordinates? If yes, how would they would look like? How would that affect the answer?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What would that mean local coordinates in this case?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I think I understood what are local coordinates, i.e. coordinates of an object given with respect to a local system to the object. I think that global coordinates at the end are just local coordinates with respect to the camera or the viewer. Am I right?&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Note: I'm not asking you to solve the problem, i.e. telling me which pixels are set, maybe I'm going to ask another question regarding that.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2016-11-18T03:29:04.560" Title="Points of a line given in global coordinates to calculate the pixels that are set using the midpoint algorithm without anti-aliasing" Tags="&lt;antialiasing&gt;&lt;rasterizer&gt;&lt;midpoint&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4277" PostTypeId="1" AcceptedAnswerId="4280" CreationDate="2016-11-15T21:53:23.963" Score="6" ViewCount="482" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Path_tracing#Algorithm&quot; rel=&quot;noreferrer&quot;&gt;Wikipedia's path tracing algorithm&lt;/a&gt; has the following line for the diffuse BRDF:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Color BRDF = 2 * m.reflectance * cos_theta;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm a little confused as I've been reading that Lambertian surface BRDF is $\frac{\rho}{\pi}$ where $\rho$ is the reflectivity (albedo?) of the surface. Where does the $2$ come from?&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2016-11-16T01:56:08.467" Title="Derivation of Wikipedia's path tracing diffuse BRDF" Tags="&lt;brdf&gt;&lt;pathtracing&gt;&lt;diffuse&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4278" PostTypeId="2" ParentId="4276" CreationDate="2016-11-16T00:00:33.477" Score="2" Body="&lt;p&gt;When drawing objects that exist in 3D space to a 2D plane (like your monitor or an image), there are a number of spaces that are useful to work in:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Global Coordinates - Somewhere in your 3D world there is an origin, and objects will be placed relative to that origin. The camera will also be placed somewhere relative to that origin and will point in some direction in the world.&lt;/li&gt;&#xA;&lt;li&gt;Object Coordinates - If you have 3D objects in your scene, they are generally created outside of the world and then transformed in some way to be placed in the world. You might create, say, a chair, with the origin of the chair where the front right leg touches the ground. In Object space, that's (0,0,0). But you'll transform that chair to where it needs to go in the scene and put it at some location in world (global) coordinates.&lt;/li&gt;&#xA;&lt;li&gt;View Coordinates - Your virtual camera, as mentioned above, is placed somewhere and is pointing at something. Whatever your camera is pointing at will generate a space relative to the camera. You can think of the camera as always being at the origin of camera space.&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Clip Space - eventually during rendering, you will use a projection matrix of some sort (perspective, orthographic, etc.) to render the final image. When running your geometry through this matrix, any coordinates that end up outside of [-1..1] will be clipped out. (In some cases [0..1] is used instead, but this detail doesn't change the point.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Screen Space - finally, after you've clipped everything and gotten it into normalized coordinates, you then have to flatten it to 2D and display it to the user. This is screen space, and is often the same as the pixels (or some portion of them) on the user's physical display (or in an image if your rendering to an image).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So in the original problem, you've been given the requirement of having a field of view for your camera of 135° (3/4π radians), and a window that's 15x15 pixels large. So you need to construct a projection matrix with a 135° field of view and an aspect ratio of 1:1. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The view parameters aren't specified in your problem, so I guess the camera is at the world's origin, so camera/view space and world space are the same for now. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normally, you'd take the world coordinates, (&lt;code&gt;p1&lt;/code&gt; and &lt;code&gt;p2&lt;/code&gt;) and multiply them by the view matrix (identity here, so no work to do), then multiply that result by the projection matrix to get to clip space. Once you have coordinates in the normalized range, you can multiply them by the window's size (15x15 in this case) to get them into screen space and determine which pixels to set.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2016-11-16T00:54:54.297" LastActivityDate="2016-11-16T00:54:54.297" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4279" PostTypeId="2" ParentId="1687" CreationDate="2016-11-16T00:25:28.440" Score="2" Body="&lt;p&gt;I have written a standalone java program (ObjectVolume) which reads an object file (.obj) and calculates the surface area, centroid and volume of any closed triangular mesh. The program also displays the file name, number of faces, the number of 3D coordinates and program run times. The program is in the public domain and is located at:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://sourceforge.net/projects/objectvolume/?source=navbar&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://sourceforge.net/projects/objectvolume/?source=navbar&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Included is a detail description of the process and the code.  The source code is included so you can add whatever you like.&lt;/p&gt;&#xA;" OwnerUserId="5491" LastEditorUserId="5491" LastEditDate="2016-11-17T21:17:42.587" LastActivityDate="2016-11-17T21:17:42.587" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4280" PostTypeId="2" ParentId="4277" CreationDate="2016-11-16T01:56:08.467" Score="6" Body="&lt;p&gt;When you perform regular Monte Carlo integration over a hemisphere using $N$ samples, each sample represents $\frac{2\pi}{N}$ steradians. So the Monte Carlo integration for Lambertian BRDF is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac{2\pi}{N}\sum_{i=1}^N\frac{\rho}{\pi}L_i*Cos\theta_i$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For path tracing, you only take one sample per path segment, so because $N$=1, the above sum becomes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$2\pi\frac{\rho}{\pi}L*Cos\theta = 2\rho L*Cos\theta$$&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-16T01:56:08.467" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4281" PostTypeId="1" AcceptedAnswerId="4282" CreationDate="2016-11-16T14:25:25.323" Score="11" ViewCount="1286" Body="&lt;p&gt;To be more concrete, I'm working on an iOS app, and have a &lt;code&gt;CATransform3D&lt;/code&gt; struct (basically a 4x4 transform array).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to deduce all the different &quot;operations&quot; this matrix implies? Things like how much rotation, scale, etc. it implies?&lt;/p&gt;&#xA;" OwnerUserId="5493" LastActivityDate="2016-11-16T16:30:53.197" Title="Is it possible to turn a 3d rotation matrix (4x4) into its component parts (rotation, scale, etc.)?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4282" PostTypeId="2" ParentId="4281" CreationDate="2016-11-16T16:02:41.793" Score="11" Body="&lt;p&gt;You can decompose the matrix $\mathbf{M} = \mathbf{TRS}$ into basic transformations: translation, scaling, and rotation. Given this matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathbf{M} = \begin{bmatrix}&#xA;a_{00} &amp;amp; a_{01} &amp;amp; a_{02} &amp;amp; a_{03}\\&#xA;a_{10} &amp;amp; a_{11} &amp;amp; a_{12} &amp;amp; a_{13}\\&#xA;a_{20} &amp;amp; a_{21} &amp;amp; a_{22} &amp;amp; a_{23}\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can decompose the translation by inspection using the last column $\mathbf{t} = (a_{03}, a_{13}, a_{23})$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For scaling, we know that the first three columns of the matrix corresponds to the bases (axes). We can get the scale by the length/norm of these vectors, i.e. how much the bases were scaled. So the scale is $\mathbf{s} = (s_0, s_1, s_2)$ where:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{matrix}&#xA;s_0 = \left \|(a_{00}, a_{10}, a_{20}) \right \|\\ &#xA;s_1 = \left \|(a_{01}, a_{11}, a_{21}) \right \|\\ &#xA;s_2 = \left \|(a_{02}, a_{12}, a_{22}) \right \|\\ &#xA;\end{matrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you have the scale, you can get rid of it using the $3\times 3$ sub-matrix that corresponds to $\mathbf{RS}$ by multiplying the matrix with the inverse of the scale $\mathbf{S}^{-1}$ to get $\mathbf{R}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{align}&#xA;\mathbf{(RS)S}^{-1} &amp;amp;= &#xA;\begin{bmatrix}&#xA;a_{00} &amp;amp; a_{01} &amp;amp; a_{02}\\&#xA;a_{10} &amp;amp; a_{11} &amp;amp; a_{12}\\&#xA;a_{20} &amp;amp; a_{21} &amp;amp; a_{22}\\&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;s_0 &amp;amp; 0 &amp;amp; 0\\ &#xA;0 &amp;amp; s_1 &amp;amp; 0\\ &#xA;0 &amp;amp; 0 &amp;amp; s_2&#xA;\end{bmatrix}^{-1} \\&#xA;&amp;amp;=&#xA;\begin{bmatrix}&#xA;a_{00} &amp;amp; a_{01} &amp;amp; a_{02}\\&#xA;a_{10} &amp;amp; a_{11} &amp;amp; a_{12}\\&#xA;a_{20} &amp;amp; a_{21} &amp;amp; a_{22}\\&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;1/s_0 &amp;amp; 0 &amp;amp; 0\\ &#xA;0 &amp;amp; 1/s_1 &amp;amp; 0\\ &#xA;0 &amp;amp; 0 &amp;amp; 1/s_2&#xA;\end{bmatrix}&#xA;\end{align}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus ($\mathbf{(RS)S}^{-1} = \mathbf{RI} = \mathbf{R}$):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathbf{R} =&#xA;\begin{bmatrix}&#xA;a_{00}/s_0 &amp;amp; a_{01}/s_1 &amp;amp; a_{02}/s_2\\&#xA;a_{10}/s_0 &amp;amp; a_{11}/s_1 &amp;amp; a_{12}/s_2\\&#xA;a_{20}/s_0 &amp;amp; a_{21}/s_1 &amp;amp; a_{22}/s_2\\&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the final rotation matrix. You can further decompose it using many ways. It is quit lengthy but you can search for &lt;em&gt;decomposing a rotation matrix&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This method only gives an equivalent values in the form of translation, scaling and rotation (the original matrix maybe the result of other types of transformations). It may has problems with floating point precision with the rotation angles if you further used the decomposed angles, rounding errors may accumulate in the computations. You should not use it unless you did not construct the matrix yourself. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are the one who constructed the matrix and wanted the decomposition in order to be able to edit and display the translation, scale and rotation individually and &lt;em&gt;independently&lt;/em&gt;, probabbly the cleanest why is to store the components of $\mathbf{t}$, $\mathbf{s}$ and $\mathbf{r}$ in a transform class individually as vectors (maybe quaternion for the rotation). Only when you need the transform matrix, construct a $\mathbf{TRS}$ matrix from these components (You can cache the matrix until some component is changed).&lt;/p&gt;&#xA;" OwnerUserId="5488" LastEditorUserId="5488" LastEditDate="2016-11-16T16:30:53.197" LastActivityDate="2016-11-16T16:30:53.197" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4283" PostTypeId="2" ParentId="4274" CreationDate="2016-11-16T18:55:06.673" Score="1" Body="&lt;p&gt;It's happening because they just happened to define the rotation matrix with counterclockwise rotation direction, which is the common convention for polar$\rightarrow$cartesian coordinate system transformation. If you &lt;a href=&quot;https://www.google.ca/search?q=polar%20to%20cartesian%20coordinates&amp;amp;espv=2&amp;amp;biw=1920&amp;amp;bih=911&amp;amp;source=lnms&amp;amp;tbm=isch&amp;amp;sa=X&amp;amp;ved=0ahUKEwj_6qCA-K3QAhXi7YMKHcmQCwUQ_AUIBigB&amp;amp;dpr=1#imgrc=_&quot; rel=&quot;nofollow noreferrer&quot;&gt;google for the transformation&lt;/a&gt;, you'll see that the angle is universally shown to rotate to the counterclockwise direction like below&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DU3pS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DU3pS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-16T18:55:06.673" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4284" PostTypeId="2" ParentId="4276" CreationDate="2016-11-18T03:29:04.560" Score="0" Body="&lt;p&gt;I think the mention of &quot;global coordinates&quot; is a lead to the next lecture of learning different coordinate systems (object, camera, etc.), so you are kind of jumping a head I suppose (:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The points could indeed be given in local coordinates, which would then require definition of transformation from local to global coordinate system, and understanding how this transformation is performed. This transformation is usually defined as a 4x4 matrix, and the 3D points are defined as homogeneous coordinates [x, y, z, 1], which are multiplied with the matrix to bring them into global coordinate system.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-18T03:29:04.560" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4285" PostTypeId="1" CreationDate="2016-11-18T05:43:25.880" Score="3" ViewCount="125" Body="&lt;p&gt;In my last Graphic mid-term, the exam contained a Transformation Matrices problem, its statement was:&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Question&lt;/h1&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Rotate the following ladder to form a DNA-shaped ladder using a transformation matrix.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/U2aS1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/U2aS1l.jpg&quot; alt=&quot;enter image description here&quot; title=&quot;click for full sized image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Notes&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The ladder base must be kept as it is without any rotating.&lt;/li&gt;&#xA;&lt;li&gt;The ladder lies in the  x-y plane.&lt;/li&gt;&#xA;&lt;li&gt;The total rotating angle should equal 540 degrees.&lt;/li&gt;&#xA;&lt;li&gt;The ladder step width = 2 * ladder step height (This image isn't drawn to scale).&lt;/li&gt;&#xA;&lt;li&gt;Assume that the curves are straight lines.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;First Idea&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;When I first read the problem statement, I thought of this basic trivial solution:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Translate the ladder such that the ladder's base is on the origin and the y-axis halves the ladder.&lt;/li&gt;&#xA;&lt;li&gt;Rotate all points by the required angle which depends on the current point y value.&lt;/li&gt;&#xA;&lt;li&gt;Translate the ladder back to it rotation.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Assume that $T(x,y)$ is the transformation matrix that will take care of translation to the origin and its inverse will return the ladder back to its original location, and $R_y(\theta)$ is the rotation matrix around y-axis to perform the rotation to achieve the DNA-shaped ladder.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we calculate $\theta = 540/12 = 45$ degrees, then we need to rotate as following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;1st step by $0$ degrees (to maintain the fixed-base condition).&lt;/li&gt;&#xA;&lt;li&gt;2nd step by $45$ degrees.&lt;/li&gt;&#xA;&lt;li&gt;3rd step by $90 = (2*45)$ degrees.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;The problem&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I couldn't apply this solution and put it into valid transformation matrix because referring to my previous knowledge (and the logic behind transformation matrices too), I recalled that we cannot put variables (e.g. y) inside the cos, sin functions inside the rotation matrix. Then I thought of another solution if I used power to the rotation matrix by the value of y this will give me the same effect but I also couldn't put this idea into a transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, to conclude the problem we have 2 ways for achieving this (which I think aren't valid):&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;$\begin{bmatrix}\cos(y\theta)&amp;amp;0&amp;amp;\sin(y\theta)&amp;amp;0\\0&amp;amp;1&amp;amp;0&amp;amp;0\\-\sin(y\theta)&amp;amp;0&amp;amp;\cos(y\theta)&amp;amp;0\\0&amp;amp;0&amp;amp;0&amp;amp;1\end{bmatrix}$&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;And the final answer would be: $P' =  (T(x,y))^{-1} R(45) T(x,y) P$&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;$\begin{bmatrix}\cos(\theta)&amp;amp;0&amp;amp;\sin(\theta)&amp;amp;0\\0&amp;amp;1&amp;amp;0&amp;amp;0\\-\sin(\theta)&amp;amp;0&amp;amp;\cos(\theta)&amp;amp;0\\0&amp;amp;0&amp;amp;0&amp;amp;1\end{bmatrix}$&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;And the final answer would be: $P' =  (T(x,y))^{-1} (R(45))^{y} T(x,y) P$&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Doctor's solution&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;My doctor was a big supporter of the first solution and he said this is the correct transformation matrix to solve such problems.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;The real question&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Do any of these solutions achieve the required result while maintaining the transformation matrix concepts (i.e. avoid equations and direct substitutions and instead use matrices operations)?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If both solutions are wrong, can you kindly guide me to the valid solution? &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If one of the solutions above is correct, can you please explain why?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5495" LastEditorUserId="5495" LastEditDate="2016-11-18T17:40:16.753" LastActivityDate="2016-11-18T17:40:16.753" Title="Ladder to DNA using Transformation Matrix" Tags="&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4286" PostTypeId="1" AcceptedAnswerId="4289" CreationDate="2016-11-18T13:56:53.940" Score="6" ViewCount="435" Body="&lt;p&gt;I want to experiment with some new stuff about modern rendering techniques and in that way I'm trying to implement a custom GI (somewhere between pathtracing and instant radiosity).&#xA;My scene is a bit less than 1,000,000 tris and my algorithm requires to render the same scene &lt;em&gt;a lot&lt;/em&gt; of times into different tiny textures (let's call them &quot;bounces&quot;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've began my implementation in a naive way so I rapidly ran into some performance problems:&lt;br&gt;&#xA;With my 1TFlops laptop GPU I can render my 1M poly scene I can have 200 &quot;bounces&quot; before dropping bellow 30FPS which is far from enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My &quot;naive&quot; algorithm looks like this in pseudo code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (unsigned int i = 0; i &amp;lt; res ; ++i) {&#xA;  UpdateCameraUniform(i);&#xA;  glBindFramebuffer(GL_FRAMEBUFFER, BounceFbo[i]);&#xA;  glDrawBuffers(1, renderBuffer[i]);&#xA;  for (Mesh&amp;amp; m : Scene) {&#xA;    m.render();&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Mesh::render() {&#xA;UpdateTransformUniform();&#xA;glBindVertexArray(_vao);&#xA;glBindBuffer(GL_ARRAY_BUFFER, _vbo);&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);&#xA;glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, 0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The full code is &lt;a href=&quot;https://github.com/newincpp/GLnewin/tree/master/GLnewin&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; (the depot is really messy for now...).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to find a new strategy to render my scene so I searched what I could do.&lt;br&gt;&#xA;I think I have 2 strategies:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Trying to reduce the number (or the performance) of my drawcalls. It seems that there is some magic function like glMultiDraw* (I've found it in a post on &quot;OpenGL superbible&quot; &lt;a href=&quot;http://www.openglsuperbible.com/2013/10/16/the-road-to-one-million-draws/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;). But I don't really understand what this does:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Does this render multiple times the same mesh?&lt;/li&gt;&#xA;&lt;li&gt;Different mesh but with one shader?&lt;/li&gt;&#xA;&lt;li&gt;Different mesh with different shader but just with low CPU overhead?&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Trying to reduce the render time while rendering multiple times the same mesh in &quot;Bounces&quot; using the same technique as &lt;a href=&quot;https://www.youtube.com/watch?v=nmajnglJeyE&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; but I have absolutely no idea how it works or even if it can apply to me...&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Obviously I am open to any other suggestions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I can reach 200 &quot;bounces&quot; not 35&lt;/p&gt;&#xA;" OwnerUserId="5506" LastEditorUserId="5506" LastEditDate="2016-11-22T17:52:07.010" LastActivityDate="2016-11-22T17:52:07.010" Title="How can I improve the performance of my custom Global Illumination approach?" Tags="&lt;opengl&gt;&lt;performance&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4287" PostTypeId="2" ParentId="4285" CreationDate="2016-11-18T16:52:42.817" Score="3" Body="&lt;p&gt;You can't perform this transformation by applying constant transformation matrix to the ladder model since it's not linear transformation like joojaa said in the comments. What you would have to do instead is to define the transformation as a function of height as you have done in both of your proposals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So both of your proposals are kind of correct, except for the typo in second one where you should use $R$ instead of $T$ that you raise to power of y. However, you might have difficulties raising a matrix to non-integer power (requires expansion of Taylor series, AFAIK), so your first proposal is much more practical.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-18T16:52:42.817" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4288" PostTypeId="1" CreationDate="2016-11-19T07:05:58.323" Score="8" ViewCount="1944" Body="&lt;p&gt;I originally wrote a pathtracer that just bounces by the BRDF and each sample is added to a buffer that divides by the current number of frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I'd like to do next event estimation at each bounce, directly sampling the light along the path. How do I &quot;weight&quot; the samples taken with regular pathtracing along with the direct light samples? Even if I weight the direct light by the solid angle of the light, if I have more than 1 sample taken I can no longer just divide by the frame count right?&lt;/p&gt;&#xA;" OwnerUserId="5510" LastActivityDate="2016-11-22T07:36:35.707" Title="Path weight for direct light sampling" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4289" PostTypeId="2" ParentId="4286" CreationDate="2016-11-19T07:06:00.010" Score="2" Body="&lt;p&gt;You should always profile to determine where your slowdown occurs. From your question, it's unclear whether your work is CPU bound or GPU bound.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;But I don't really understand what is does: Does this render a multiple time the same mesh ? different mesh but with one shader ? different mesh with different shader but just with low CPU overhead ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;glMultiDraw*&lt;/code&gt; draw commands are for allowing you to render multiple objects in one draw call. In terms of OpenGL 3.0 and later, this means that you could specify a VBO holding a bunch of objects and use &lt;code&gt;glMultiDraw*&lt;/code&gt; to render them. You would use this with the same shader. If you want to render the same object multiple times, then using something such as &lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Rendering#Instancing&quot; rel=&quot;nofollow noreferrer&quot;&gt;instancing&lt;/a&gt; would be a good solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This all concerns draw calls though. If you have one million triangles for only a few meshes, you won't see a massive speedup with rendering. You didn't specify your framebuffer size, but if it's small enough, you can cause severe overdraw from many small triangles. If the images are really that small, maybe you should think about adding an LOD system or use lower polygon meshes and tessellate.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;trying to reduce the render time while rendering multiple time the same mesh in &quot;Bounces&quot; using the same technique than this&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://docs.google.com/presentation/d/19x9XDjUvkW_9gsfsMQzt3hZbRNziVsoCEHOn4AercAc/edit#slide=id.p&quot; rel=&quot;nofollow noreferrer&quot;&gt;Stereo instanced rendering&lt;/a&gt; is specifically a technique for VR. It relies on the assumption that the scene is pretty much identical in each eye, and so it uses instancing to render to two sides of the screen at once. However, if your bounces render similar geometry, then you may be able to render multiple bounces onto a larger framebuffer provided that the bounces are independent. There is potential for speedup from avoiding framebuffer switching (which is a rather expensive process).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In newer OpenGL versions (4.0 and above), there is added support for &lt;a href=&quot;https://www.opengl.org/wiki/Vertex_Rendering#Indirect_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;indirect rendering&lt;/a&gt;, which allows you to determine parameters through GPU computing, but it's unclear if that will help you in this case.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2016-11-19T07:06:00.010" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4290" PostTypeId="1" CreationDate="2016-11-19T10:59:49.137" Score="10" ViewCount="5246" Body="&lt;p&gt;This is what my lecturer told me in the coursework:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We only consider 4*4 matrices. These are used to rotate, scale or translate objects (or any combination of these operations). Matrices are also used later in the implementation of the virtual camera model. If you do not know the difference between a vector transformation and point transformation, look it up. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't seem to find an answer and made an account for this website just for this question.&lt;/p&gt;&#xA;" OwnerUserId="5513" LastActivityDate="2017-01-20T09:28:34.413" Title="What is the difference between a point transformation and a vector transformation?" Tags="&lt;vectors&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4291" PostTypeId="2" ParentId="4290" CreationDate="2016-11-19T12:22:50.717" Score="2" Body="&lt;p&gt;If you would look up the definition of a vector and a point, then a vector is:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A quantity, such as velocity, completely specified by a magnitude and a direction.&#xA;  &lt;a href=&quot;http://www.thefreedictionary.com/vector&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.thefreedictionary.com/vector&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And a point is:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A dimensionless geometric object having no properties except location.&#xA;  &lt;a href=&quot;http://www.thefreedictionary.com/point&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.thefreedictionary.com/point&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So you could say that a vector is a direction with scale, and a point is a location.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if you transform a vector you just rotate and scale it. With a point you also translate it (the rotation and scaling of a point is around the origin, since it iss just a location the point itself cannot be rotated).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the times a vector and a point are put into the same container, a vector with 4 components. The only difference is the w component. If the w component is 0, then it is a direction. If it is 1 then the vector is a point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason for this can be found in the matrix itself.&#xA;It makes use of the way you multiply a vector with 4 components with a 4x4 matrix. If you do not know how that works, I would suggest a quick google.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the times you use a 4x4 matrix. A normal transformation matrix could look like this:&#xA;\begin{bmatrix}rot+scale&amp;amp;rot+scale&amp;amp;rot+scale&amp;amp;translation\\rot+scale&amp;amp;rot+scale&amp;amp;rot+scale&amp;amp;translation\\rot+scale&amp;amp;rot+scale&amp;amp;rot+scale&amp;amp;translation\\0&amp;amp;0&amp;amp;0&amp;amp;1\end{bmatrix}&#xA;(The rotation and scale are put in the 3x3 area you could say, so for just rotation and scale a 3x3 matrix could also be used, but when translation comes in, we need that 4th column.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, if the last component is 0, then you have a multiplication with 0 and therefore the result is 0 and there is no translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This makes it easy in computer graphics with polygonal objects. You have the same transformation matrix to transform the positions but also the normals. Because the normals have their w component set to 0 and the positions' w component is 1, the normals are just rotated (and also scaled which can lead to some weird stuff, so most of the times the normal is normalized after. It isn't actually recommended to use the same matrix for positions and rotations because of the weird stuff! Look at @JarkkoL 's comment.) and the positions are translated (and rotated and scaled around the origin).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope I did not make a mistake :P, and this helped you!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="4908" LastEditDate="2016-11-19T21:56:17.950" LastActivityDate="2016-11-19T21:56:17.950" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4292" PostTypeId="2" ParentId="4290" CreationDate="2016-11-19T12:26:51.290" Score="4" Body="&lt;p&gt;From what I've learnt, since I'm also a student, is that you want to work with $4 \times 4$ matrices in order to treat rotations, scaling and translations in the same way, that is, &lt;em&gt;multiplying by a matrix&lt;/em&gt; (i.e., a $4 \times 4$ matrix).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember that without these $4 \times 4$ matrices, translations would be represented by summing with a vector, whereas rotations and scaling are represented using multiplications with respectively a vector and a scalar factor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the question is: &lt;em&gt;how do we pass from a 3D coordinate systems to a 4D one&lt;/em&gt;? The answer is &quot;&lt;strong&gt;homogenous coordinates&lt;/strong&gt;&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, what does it mean? We construct $4 \times 4$ matrices to represent rotations, scaling and translation, so that we only use matrix multiplications to represent transformations (e.g., rotations, scaling, etc). How we construct them individually, it's more specific, but you can have a look it on the web. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;At this point, we have $4 \times 4$ matrices and 3D vectors, not useful yet, because you can't multiply $4 \times 4$ matrices and $3D$ vectors, since the dimensions do not match. That's why, when we work with homegeneous coordinates, we also need to convert our given 3D points into corresponding 4D ones. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;How do we do it?&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We distinguish between &lt;em&gt;direction&lt;/em&gt; and &lt;em&gt;position&lt;/em&gt; vectors. Direction vectors, as the name suggests, have a direction at which they are pointing; we also care about their length, but they are not affected by translations, since we don't care about their position. Position vectors (or simply &quot;points&quot;) can be translated or moved around; they are usually represented with respect to the origin, i.e. as a vector from the origin to the point itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We transform 3D direction vectors by adding a $0$ as the $4$th coordinate of the corresponding homogeneous vector: we add a zero because this basically eliminates the effect of translations. We do a similar thing with position vectors, but instead of a $0$ we add a $1$, for the opposite reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if we have a $3D$ direction vector $v = \begin{pmatrix} v_1 \\ v_2 \\ v_3\end{pmatrix}$, we transform it by doing $v' = \begin{pmatrix} v_1 \\ v_2 \\ v_3 \\ 0\end{pmatrix}$. Similarly, if we had a point vector $u = \begin{pmatrix} u_1 \\ u_2 \\ u_3\end{pmatrix}$ we would transform it to $u' = \begin{pmatrix} u_1 \\ u_2 \\ u_3 \\ 1\end{pmatrix}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: to convert from homogeneous coordinates back to corresponding $3D$ ones, you can't simply remove the $4th$ coordinate, unless it's &lt;strong&gt;still&lt;/strong&gt; equal to $1$ (or $0$ respectively).&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorDisplayName="user4718" LastEditDate="2017-01-18T13:09:35.250" LastActivityDate="2017-01-18T13:09:35.250" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4293" PostTypeId="1" CreationDate="2016-11-19T13:27:36.380" Score="4" ViewCount="168" Body="&lt;p&gt;I'm trying to understand part of the contents of a slide, but I'm not really understanding. So, here's the interested part.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4TwPA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4TwPA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I've a few questions.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Are the projected points $q_1$ and $q_2$ the points with respectively the screen coordinates $(x_1, y_1)$ and $(x_2, y_2)$, i.e., $q_1 = \begin{pmatrix} x_1 \\ y_1\end{pmatrix}$ and $q_2 = \begin{pmatrix} x_2 \\ y_2\end{pmatrix}$?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Regarding how to obtain the projected points. What I understand from the slide is that the projected $3D$ points are obtained by dividing all coordinates of $p_1$ (e.g.) by its $z$ coordinate, i.e., $p_1^z$, so that we obtain $q_1 = \begin{pmatrix} \frac{p_1^x}{p_1^z} \\ \frac{p_1^y}{p_1^z} \\ \frac{p_1^z}{p_1^z}  \end{pmatrix} = \begin{pmatrix} \frac{p_1^x}{p_1^z} \\ \frac{p_1^y}{p_1^z} \\ 1 \end{pmatrix}$. So, I guess, that at this point, we obtain the sccreen coordinates by ignoring the $1$ as the 3rd coordinate. Is that right?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerDisplayName="user4718" LastActivityDate="2016-11-20T05:45:23.957" Title="Projected points and screen coordinates" Tags="&lt;projections&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4294" PostTypeId="1" CreationDate="2016-11-19T14:04:43.393" Score="4" ViewCount="773" Body="&lt;p&gt;To continue with &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4293/projected-points-and-screen-coordinates&quot;&gt;this&lt;/a&gt; my other question, here's the problem. So, I've a slide, which I'm trying to understand. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UK1Ia.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UK1Ia.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are my questions.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;What are the barycentric coordinates of? From my previous question, $(x_1, y_1)$ and $(x_2, y_2)$ are also screen coordinates. So, we're interpolating between screen coordinates. Why would we do that?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Why is $\lambda = \frac{x - x_1}{x_2 - x_1}$?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Are $p_1$ and $p_2$ points given in global coordinates? That is, are they $3D$ points or screen points? &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Why is $\mu$ defined as it is?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Why do we want to know $p^z$? By the way, what is it? A vector, right?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerDisplayName="user4718" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2016-11-20T06:22:37.617" Title="Screen coordinates, barycentric coordinates and global coordinateas" Tags="&lt;interpolation&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4295" PostTypeId="2" ParentId="4290" CreationDate="2016-11-19T15:58:57.973" Score="9" Body="&lt;p&gt;Here's the simple answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 4D, to be able to multiply them by a 4x4 matrix, vectors are represented as (x,y,z,0) and points are represented as (x,y,z,1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the 4th row of a 4x4 matrix represents the translation of the matrix, the above representations make it so points are affected by translation, but vectors are not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both vectors and points are affected by the rotation, scaling, etc though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Caveat:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is deeper discussion to be had if you expect the vectors to have certain properties.  For instance, if you transform a triangle's normal by the same matrix you transform the triangle's vertices, it likely won't actually be the normal vector of that triangle anymore. This is because normal vectors have a sort of inverse relationship to the vertices that they are calculated from.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="5353" LastEditDate="2016-11-24T15:14:13.447" LastActivityDate="2016-11-24T15:14:13.447" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4296" PostTypeId="2" ParentId="4286" CreationDate="2016-11-20T02:14:01.213" Score="0" Body="&lt;p&gt;A common approach for real-time radiosity in games is to assume static geometry, which can be used to pre-calculate visible surfels (position, albedo, normal) for a point in space (light probe). This approach avoids the need for run-time rasterization of the geometry for different viewpoints. The surfels can be then dynamically re-lit in run-time and used to gather luminance for the probe, which is used to approximate the indirect illumination.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-11-20T02:19:53.937" LastActivityDate="2016-11-20T02:19:53.937" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4298" PostTypeId="2" ParentId="4293" CreationDate="2016-11-20T05:45:23.957" Score="5" Body="&lt;p&gt;It's not 100% clear what the author means here, but I'll choose to interpret &quot;screen coordinates&quot; as &quot;pixel coordinates&quot;. These would be related to the projected points by a 2D coordinate transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You're correct that projection is done by dividing each component of a point by its $z$ component. (That's not &lt;em&gt;quite&lt;/em&gt; true—actually, we usually use homogeneous coordinates, which have four components $xyzw$, and divide by the $w$ component, which has previously been set to eye-space $z$ by the projection matrix. This frees up the $z$ component of the vectors to be used for the z-buffer.) The projected points $q_i$ are then in &quot;normalized device coordinates&quot; or NDC space, which has a range of [−1, 1] on each axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To calculate the resulting pixel coordinates on the screen, we then need to perform a 2D scale-and-translate operation, to map the [−1, 1] range to the desired range of pixels. For example, if we want a 640×480 viewport, we could calculate&#xA;$$x_i = 640 \cdot \frac{q^x_i + 1}{2} \\ y_i = 480 \cdot \frac{q^y_i + 1}{2}$$&#xA;You might also need to flip the $y$ axis in this transformation, for instance if the NDC space is Y-up but the pixel coordinates are Y-down.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-11-20T05:45:23.957" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4299" PostTypeId="2" ParentId="4294" CreationDate="2016-11-20T06:22:37.617" Score="2" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;It sounds like you're rasterizing a line segment between two endpoints. The points on the line are obtained by linearly interpolating between the endpoints (whether in world space, screen space, or any other coordinate system). The barycentric coordinates identify points on the line segment.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;It's defined this way to make range of $\lambda$ be [0, 1]. (When $\lambda = 0$ you obtain $(x_1, y_1)$ and when $\lambda = 1$ you get $(x_2, y_2)$.) This is typical for barycentric coordinates for either lines or for triangles—they always range from 0 to 1, and sum to 1. These coordinates therefore also act as weights for interpolating other quantities, such as color or z-value, across the line or triangle.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Probably the $p_i$ are the original 3D points before projection.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;This is about perspective-correct interpolation. It's stating the transformation between $\lambda$ (interpolation in screen space) and $\mu$ (interpolation in world space). The two parameters are not the same, due to perspective foreshortening—in screen space, perspective will compress parts of the line that are farther away from the camera. So, for example, the midpoint of the line in world space ($\mu = \tfrac{1}{2}$) will generally project to some place that is &lt;em&gt;not&lt;/em&gt; at the midpoint in screen space ($\lambda \neq \tfrac{1}{2}$). The equation given shows how to convert between $\lambda$ and $\mu$ for a given point on the line. Note that if $p_1^z = p_2^z$, the equation reduces to $\mu = \lambda$, showing that both kinds of interpolation match if and only if the line is parallel to the screen, so the perspective effect is uniform along the whole line.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$p_z$ is going to be the depth of the interpolated point. It's the $z$-component of the vector $p$, so $p_z$ itself is a single value, not a vector. Presumably the reason you want to know this is so you can store it in the z-buffer during rasterization. In other words, while rasterizing a line, you can easily calculate $\lambda$ for each pixel based on how far you are between the endpoints in screen space; then this equation tells you the $z$ for each pixel to put into the z-buffer.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-11-20T06:22:37.617" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4302" PostTypeId="2" ParentId="4288" CreationDate="2016-11-22T07:36:35.707" Score="5" Body="&lt;p&gt;By &quot;bounces by the BRDF&quot;, I assume you mean picking random directions in the hemisphere and weighting by the BRDF, then averaging over those samples. I guess you're accumulating one sample per frame, so then you divide by the current number of frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be theoretically &quot;correct&quot;, you should also be weighting those samples by $2\pi$, as that's the solid angle of the hemisphere you're integrating over. That's not too important when you just have a single sampling method, but when you're going to combine multiple ones it's easier to be sure everything's consistent if you have these factors right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, to incorporate explicit direct light sampling, you have to convert from the light-sampling probability density to the solid angle probability density at the receiver point. If the light samples are uniform over the light source's area, then in place of the simple $2\pi$ weight, you'd use this weight factor instead:&#xA;$$\frac{A}{r^2} (N_\text{light} \cdot -L)$$&#xA;where $A$ is the area of the light source, $r$ is the distance between the receiver point (current path point) and the chosen light source point, $N_\text{light}$ is the normal of the light point, and $L$ is the unit vector from the path point, toward the light point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This factor accounts for how dense the sampled light source points will be in solid angle of the receiver point, varying both with distance and with the angle on the light source's surface (the points will bunch up in areas where the source surface slopes away from the receiver, such as around the edges of a spherical area light).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After weighting by this factor, the direct light samples are in the same solid angle domain as the BRDF samples, so you can just add them together and divide by the total number of samples—which would now be twice the number of frames, if you're doing one BRDF sample and one light sample per frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, an important thing to get right is not double-counting the light's illumination. Since you're explicitly sampling the lights now, you have to make sure &lt;em&gt;not&lt;/em&gt; to include the emissive color if you do happen to randomly hit a light while doing the BRDF samples! Otherwise you'd end up with the lights appearing twice as bright as they should.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A refinement of this is that you may wish to apply explicit light sampling only to the diffuse part of the BRDF, and not the specular part. A narrow specular highlight is better handled through importance-sampling the BRDF instead. This implies that when doing explicit light samples, you would only evaluate the diffuse component of the BRDF, and then if you hit a light source through a specular reflection ray, you &lt;em&gt;would&lt;/em&gt; include its emissive color there.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-11-22T07:36:35.707" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4305" PostTypeId="1" CreationDate="2016-11-23T02:28:56.030" Score="4" ViewCount="56" Body="&lt;p&gt;Would eye tracking allow for the alignment of a dual layered image (a google glass like device and a screen or projection) to provide a way to force the focus of the eyes into to a real life equivalent of the perceived distance in a similar, but healthier, way in which Anaglyph 3D and other stereoscopic or perspective tricks on a single 2d image confuse the brain into thinking you are?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.cs.umd.edu/sites/default/files/scholarly_papers/Kramidarev.pdf&quot; rel=&quot;noreferrer&quot;&gt;Resolving the Vergence-Accommodation Conﬂict in Head Mounted Displays&lt;/a&gt; talks about using eye tracking for &quot;Foveated rendering&quot; and &quot;gaze dependent rendered depth-of-ﬁeld&quot;. There are &quot;Deformable Mirrors in Virtual Retinal Displays&quot; and &quot;Liquid and Electroactive Lens Displays&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;EVALUATION METHODS We establish four general evaluation strategies to evaluate VAC solutions: (1) subjective user studies, (2) direct measurement of occulomotor responses (3) measurements of physiological fatigue indicators and (4) assessment of brain activity via such tools as EEG or fMRI.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are &lt;a href=&quot;https://medium.com/vrinflux-dot-com/vergence-accommodation-conflict-is-a-bitch-here-s-how-to-design-around-it-87dab1a7d9ba#.n80klmszc&quot; rel=&quot;noreferrer&quot;&gt;software approaches&lt;/a&gt; to minimise this effect;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Use long viewing distances when possible — focus cues have less influence as the distance to the display increases. Beyond 1 meter should suffice.&#xA;Match the simulated distance in the display and focal distance as well as possible.&#xA;Move objects in and out of depth at a pace that gives the user’s eyes more time to adjust.&#xA;Maximize the reliability of other depth cues. Accurate perspective, shading realism, and other visual cues that convey realistic depth...&#xA;Minimize the consequences of VAC by making existing conflicts less salient.&quot;&lt;/p&gt;&#xA;" OwnerUserId="5486" LastActivityDate="2016-11-23T02:28:56.030" Title="Is it possible to create a forced focus with a dual layer of images in order to Avoid eye strain with Virtual and Augmented Reality?" Tags="&lt;real-time&gt;&lt;virtual-reality&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4307" PostTypeId="1" CreationDate="2016-11-24T12:06:18.010" Score="4" ViewCount="854" Body="&lt;p&gt;I'm in the process of writing a Ray Tracer using DirectCompute / HLSL. First, eye rays are generated (one per pixel). Then, rays are traced, shaded and reflected in a loop. Also, shadow rays for each light source are generated and tested for occlusion. As a scene structure, I'm using a KD Tree with Ropes$^1$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have analyzed the shader with Joshua Barczak's &lt;a href=&quot;https://github.com/jbarczak/Pyramid&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pyramid&lt;/a&gt; and it seems that I have a major problem with register pressure, mainly vectors. On a Fiji GCN architecture, the shader uses 85 SGPRs and 81 VGPRs, limiting the number of simultaneous wavefronts per SIMD to 3 (VPGR).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, I have implemented a simple counter in my shader, that atomically increases a value when a thread starts, decreases it when a thread ends and keeps track of the maximum number of shaders that were concurrently running. I've managed to get rid of some data and bring it up from 8192 to 9216, resulting in a correlated speedup of ~%13. When I use an empty dummy shader, I get 16384 concurrent threads.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried to get rid of excessive variables, especially vectors, by keeping their lifetime as short as possible, and also tried storing some variables in groupshared memory and reading / writing directly from there, all without any change in register count whatsoever.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any practical tips on how to take pressure of the registers? Is this even as much of a problem as I think it is?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also thought about splitting my Ray Tracer into various kernels. This should, the way I understand it, take pressure of the registers significantly, but also takes quite some coding effort on my part. Does this sound like an idea worth trying?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;$^1$ &lt;a href=&quot;https://graphics.cg.uni-saarland.de/fileadmin/cguds/papers/2007/popov_07_GPURT/Popov_et_al._-_Stackless_KD-Tree_Traversal_for_High_Performance_GPU_Ray_Tracing.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Popov et al.: Stackless KD-Tree Traversal for High Performance GPU Ray Tracing (2007).&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2016-11-24T16:07:07.607" LastActivityDate="2016-11-24T16:07:07.607" Title="Register pressure in Compute Shader" Tags="&lt;raytracing&gt;&lt;performance&gt;&lt;compute-shader&gt;&lt;hlsl&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4308" PostTypeId="1" CreationDate="2016-11-24T14:01:42.027" Score="6" ViewCount="180" Body="&lt;p&gt;I'm trying to investigate the effect of certain image operations on how VR scenes are perceived. To do this, I'd like to run an off-the-shelf SteamVR application, capture the frames as they come out of the compositor, run a shader or compute kernel on them, and have them displayed as normal on the HMD. I'm aware of the latency penalty for doing this; I have some ways to minimise it, and in this case I can tolerate extra latency, so don't worry about that for now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can see three strategies which might let me achieve this, but I don't know enough about the display subsystem to know which will work and how to start.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Make a 'fake' display driver. My display driver would take the place of the HMD's driver, and it would act like a proxy. When the SteamVR compositor tries to swap buffers, my driver would do the processing on the backbuffer before poking the real HMD driver. It seems like the main difficulties in this would be (a) getting Windows to accept my fake driver, (b) getting SteamVR to accept my fake driver, and (c) letting my driver use the real HMD driver.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Use normal video capture software (such as OBS) in display capture mode to capture the frames before they get to the display driver, and then use an overlay technique (like the Steam overlay) to draw over the frame completely with my processed frame. This sounds simple, but I know there's a lot of work in making either of the two halves of the system.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Hook into the SteamVR compositor itself. It supports third-party HMD integrations, and I'd hoped I'd be able to trick it into using my shader as a chromatic aberration correction shader, but it turns out that it doesn't let the HMD integration run a shader directly, it just sets the parameters for the built-in shader. This seems like it should be the easiest way, if I can just find a way to make the compositor run my shader. (I'm not averse to hacking the compositor if there's a way.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I know some people on the site are also active researchers in this area, so I'm hoping someone has practical experience of what worked and what didn't. Since this is for an experiment, not production software, I'm more interested in an answer I can hack up in a few days to work on one particular PC, than in something that's reliable but takes months to get right.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-12-15T10:48:24.800" Title="How can I intercept and filter all frames coming out of SteamVR?" Tags="&lt;virtual-reality&gt;&lt;capture&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4309" PostTypeId="2" ParentId="4307" CreationDate="2016-11-24T14:39:09.100" Score="4" Body="&lt;p&gt;Lowering register pressure doesn't necessarily give you any performance boost though. I recently went through this exercise myself on GCN architectures (for a simple ray tracer) and reduced register pressure so that it increased occupancy from 2 to 4, which had no impact on performance. It's generally a good idea to reduce the pressure if you need to hide memory latencies, but it really depends on what the real bottlenecks in your shaders are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you are working on a GPU ray tracer, you might get better improvement in performance by paying attention to the divergence of threads and try to improve this instead. For example by trying to group rays based on location and direction to reduce divergence in KD-tree traversal per wave. I'm not familiar with the paper you are referring to, and you may already have considered this though.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-11-24T14:39:09.100" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4310" PostTypeId="1" AcceptedAnswerId="4313" CreationDate="2016-11-25T10:49:08.287" Score="6" ViewCount="6389" Body="&lt;p&gt;I want to rotate a 3D object. On this website &lt;a href=&quot;http://paulbourke.net/geometry/rotate/&quot; rel=&quot;noreferrer&quot;&gt;http://paulbourke.net/geometry/rotate/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the first step says:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(1) translate space so that the rotation axis passes through the origin&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is meant by &quot;space&quot;? Is it every point on my object? If so, the matrix he provides would just mean that all the points would end up being 0,0,0 when I multiply it by that matrix. That would mean the rotation matrices would have no effect.&lt;/p&gt;&#xA;" OwnerUserId="5513" LastActivityDate="2016-11-25T16:55:47.577" Title="How to translate object to origin?" Tags="&lt;matrix&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4311" PostTypeId="2" ParentId="4310" CreationDate="2016-11-25T11:11:16.303" Score="1" Body="&lt;p&gt;Normally woth rotating objects in 3d you have a pivot. With rotation matrices it is assumed that the pivot is at (0;0;0), the origin. This means that if the pivot is not at (0;0;0), you have to move all the points on that object around so it is.&#xA;This can easily be done by subtracting the location of the pivot and after the transformation adding it back in.&#xA;So with translating space they mean that you move all the points so that the pivot point is at the origin.&#xA;All the points then would not be (0;0;0), just moved.&#xA;Hope that helped you!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2016-11-25T11:11:16.303" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4312" PostTypeId="2" ParentId="1745" CreationDate="2016-11-25T15:45:42.133" Score="3" Body="&lt;p&gt;The XYZ and xyY models are extremely useful for certain operations such as manipulating RGB colour spaces to another RGB encoded colour space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, XYZ and xyY fail quite quickly in other contexts. For example, consider MacAdams ellipses that describe noticeable differences on the linear xyY scale. You could in fact apply a nonlinear, perceptually uniform transform to the xyY values and you'd likely end up closer to what you are hoping for in your circular interface element.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With that being said, there are needs for models that extend and build upon xyY / XYZ to tackle the psychophysical aspect of colour for evaluating such things as &quot;colourfulness&quot;. This enters into the domain of &lt;em&gt;Colour Appearance Models&lt;/em&gt;, which are capable of accurately modelling and predicting various issues surrounding brightness (luminance), lightness, colorfulness, chroma, saturation, and hue. To achieve what you are seeking, you would need to transform your data into a colour appearance model such as CIECAM02.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problems cited in the other solution are in fact solved by colour appearance models such as the CIECAM02 model, including psychophysical effects that manifest as optical illusions.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Color_appearance_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;Color appearance model | Wikipedia&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://rit-mcsl.org/fairchild/CAM.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Color Appearance Models | Mark Fairchild Blog&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5556" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T18:35:42.963" LastActivityDate="2018-03-04T18:35:42.963" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4313" PostTypeId="2" ParentId="4310" CreationDate="2016-11-25T16:48:31.527" Score="7" Body="&lt;p&gt;No, he's talking about subtracting the position of the cube from the vertex positions, so that your cube is positioned at the origin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you positioned the cube at (10, 30, 15), you subtract that value from every vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, you rotate the vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, you add the position to the vertices again so the box goes back to where it was, but the vertices have been rotated around the location of the box.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing rotation like this makes an object spin in place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you didn't subtract the position before rotating, the object would orbit the origin, instead of spinning in place.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-11-25T16:55:47.577" LastActivityDate="2016-11-25T16:55:47.577" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4315" PostTypeId="1" AcceptedAnswerId="4316" CreationDate="2016-11-26T21:58:19.217" Score="4" ViewCount="46" Body="&lt;p&gt;I was messing with glowing lighting when I noticed an odd artifact in my first try.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For some reason I can see three defined edges inside of the glowing pattern. I downloaded the image and marked where I see the edges.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HRuu4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HRuu4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am just curious why they appear to be there as I can see no mathematical reason why they should be there. Is it just the way I am displaying it, or is there some sort of computational precision issue? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For reference here is the ShaderToy code that created this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;    vec2 uv = fragCoord.xy / iResolution.xy;&#xA;    float disty = abs(uv.y - 0.5);&#xA;    float distx = abs(uv.x - 0.5);&#xA;    distx *= 100.0;&#xA;    disty *= 100.0;&#xA;    fragColor = vec4(0.0, 1.0 / pow(abs((1.0 - distx) + (1.0 - disty)), 0.5), 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Although I am not sure it is physically accurate to have those spikes on the edges of the diamond I sure do like the effect that creates.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2016-11-27T03:04:18.803" LastActivityDate="2016-11-27T05:26:41.540" Title="Are these edges a result of display color accuracy, computational accuracy, or something else?" Tags="&lt;lighting&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4316" PostTypeId="2" ParentId="4315" CreationDate="2016-11-26T22:34:48.407" Score="3" Body="&lt;p&gt;&lt;strong&gt;Updated answer, now that pow is getting valid arguments:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you are seeing is called &quot;banding&quot; and it comes from the fact that the color channels are quantized into 8 bits - in other words, it comes from the fact that there are only 256 different shades of green, even though the math generating the colors is capable of much larger resolution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The banding on my system isn't as bad as what you are describing but it's still present.  The reason it isn't as bad on my system is because you and I have different displays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some computer displays don't actually even have a full 256 different shades of green.  For instance, instead of having 8 bit color, they may only have 6 bit color, and they either dither it, temporally dither it, or neither and just let it look worse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to get around this problem is by dithering.  There are various algorithms for dithering, with different computation and quality trade offs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A good modern dithering algorithm is called &quot;interleaved gradient noise&quot; which is fairly close to blue noise - which is the ideal - and is pretty cheap to calculate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check out this link for more detailed information on different types of dithering, and how they compare:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://bartwronski.com/2016/10/30/dithering-part-three-real-world-2d-quantization-dithering/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://bartwronski.com/2016/10/30/dithering-part-three-real-world-2d-quantization-dithering/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;First answer, from when pow was getting a negative value parameter:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is that you are passing a negative value to pow for the first argument, which has undefined behavior.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What shows up on my screen is completely different than what shows up on yours.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/swsUt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/swsUt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You shouldn't rely on the behavior of anything in the red pixel areas in this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cVHfO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cVHfO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More info:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/sdk/docs/man4/html/pow.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.opengl.org/sdk/docs/man4/html/pow.xhtml&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-11-27T05:26:41.540" LastActivityDate="2016-11-27T05:26:41.540" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4319" PostTypeId="2" ParentId="1934" CreationDate="2016-11-27T14:16:49.077" Score="6" Body="&lt;p&gt;While creating a set of glTF models for a tutorial, I also intended to create &lt;strong&gt;THE&lt;/strong&gt; minimal glTF file. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; The following referred to glTF 1.0/1.1. See below for an update of this example to glTF 2.0.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;As already mentioned in the &lt;a href=&quot;https://computergraphics.stackexchange.com/a/3628/1649&quot;&gt;answer by 5chdn&lt;/a&gt;, one issue may be the &lt;em&gt;material&lt;/em&gt;. According to the &lt;a href=&quot;https://github.com/KhronosGroup/glTF/tree/master/specification/1.0#appendix-a&quot; rel=&quot;nofollow noreferrer&quot;&gt;Appendix A: Default Material&lt;/a&gt; of the specification, an asset that does not contain a material should be rendered with a &lt;em&gt;default&lt;/em&gt; material that simply shows the object in a uniform, 50% gray color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some viewers might not support this, and even if they do, there have been some minor subtleties in the spec regarding this point: In glTF 1.0, it was still necessary to define an &quot;empty&quot; material, because the &lt;code&gt;mesh.primitive.material&lt;/code&gt; property was not yet optional. But this should be fixed in glTF 1.1. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the following should indeed be &lt;strong&gt;THE&lt;/strong&gt; minimal possible glTF asset (version 1.1) :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;{&#xA;  &quot;scenes&quot; : {&#xA;    &quot;scene0&quot; : {&#xA;      &quot;nodes&quot; : [ &quot;node0&quot; ]&#xA;    }&#xA;  },&#xA;  &quot;nodes&quot; : {&#xA;    &quot;node0&quot; : {&#xA;      &quot;meshes&quot; : [ &quot;mesh0&quot; ]&#xA;    }&#xA;  },&#xA;&#xA;  &quot;meshes&quot; : {&#xA;    &quot;mesh0&quot; : {&#xA;      &quot;primitives&quot; : [ {&#xA;        &quot;attributes&quot; : {&#xA;          &quot;POSITION&quot; : &quot;positionsAccessor&quot;&#xA;        }&#xA;      } ]&#xA;    }&#xA;  },&#xA;&#xA;  &quot;buffers&quot; : {&#xA;    &quot;buffer0&quot; : {&#xA;      &quot;uri&quot; : &quot;data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAACAPwAAAAAAAAAAAAAAAAAAgD8AAAAA&quot;,&#xA;      &quot;byteLength&quot; : 36&#xA;    }&#xA;  },&#xA;  &quot;bufferViews&quot; : {&#xA;    &quot;positionsBufferView&quot; : {&#xA;      &quot;buffer&quot; : &quot;buffer0&quot;,&#xA;      &quot;byteOffset&quot; : 0,&#xA;      &quot;byteLength&quot; : 36,&#xA;      &quot;target&quot; : 34962&#xA;    }&#xA;  },&#xA;  &quot;accessors&quot; : {&#xA;    &quot;positionsAccessor&quot; : {&#xA;      &quot;bufferView&quot; : &quot;positionsBufferView&quot;,&#xA;      &quot;byteOffset&quot; : 0,&#xA;      &quot;componentType&quot; : 5126,&#xA;      &quot;count&quot; : 3,&#xA;      &quot;type&quot; : &quot;VEC3&quot;,&#xA;      &quot;max&quot; : [ 1.0, 1.0, 0.0 ],&#xA;      &quot;min&quot; : [ 0.0, 0.0, 0.0 ]&#xA;    }&#xA;  },&#xA;&#xA;  &quot;asset&quot; : {&#xA;    &quot;version&quot; : &quot;1.1&quot;&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It also shows a single triangle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ElVqk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ElVqk.png&quot; alt=&quot;TriangleWithoutIndices&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The version without embedded buffers is available at &lt;a href=&quot;https://github.com/javagl/gltfTutorialModels&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/javagl/gltfTutorialModels&lt;/a&gt; , as well as a triangle with indices, at &lt;a href=&quot;https://github.com/javagl/gltfTutorialModels/tree/master/Triangle&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/javagl/gltfTutorialModels/tree/master/Triangle&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update for glTF 2.0:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The concepts and top-level elements of glTF 2.0 are basically the same as for glTF 1.0. But there still have been some changes in the format. Most importantly (for this small example), the top-level dictionaries are now &lt;em&gt;arrays&lt;/em&gt;. The following is the same &quot;Triangle&quot; model as above, updated accordingly:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;{&#xA;   &quot;scenes&quot;:[&#xA;      {&#xA;         &quot;nodes&quot;:[ 0 ]&#xA;      }&#xA;   ],&#xA;   &quot;nodes&quot;:[&#xA;      {&#xA;         &quot;mesh&quot;:0&#xA;      }&#xA;   ],&#xA;   &quot;meshes&quot;:[&#xA;      {&#xA;         &quot;primitives&quot;:[&#xA;            {&#xA;               &quot;attributes&quot;:{&#xA;                  &quot;POSITION&quot;:1&#xA;               },&#xA;               &quot;indices&quot;:0&#xA;            }&#xA;         ]&#xA;      }&#xA;   ],&#xA;   &quot;buffers&quot;:[&#xA;      {&#xA;         &quot;uri&quot;:&quot;data:application/octet-stream;base64,AAABAAIAAAAAAAAAAAAAAAAAAAAAAIA/AAAAAAAAAAAAAAAAAACAPwAAAAA=&quot;,&#xA;         &quot;byteLength&quot;:44&#xA;      }&#xA;   ],&#xA;   &quot;bufferViews&quot;:[&#xA;      {&#xA;         &quot;buffer&quot;:0,&#xA;         &quot;byteOffset&quot;:0,&#xA;         &quot;byteLength&quot;:6,&#xA;         &quot;target&quot;:34963&#xA;      },&#xA;      {&#xA;         &quot;buffer&quot;:0,&#xA;         &quot;byteOffset&quot;:8,&#xA;         &quot;byteLength&quot;:36,&#xA;         &quot;target&quot;:34962&#xA;      }&#xA;   ],&#xA;   &quot;accessors&quot;:[&#xA;      {&#xA;         &quot;bufferView&quot;:0,&#xA;         &quot;byteOffset&quot;:0,&#xA;         &quot;componentType&quot;:5123,&#xA;         &quot;count&quot;:3,&#xA;         &quot;type&quot;:&quot;SCALAR&quot;,&#xA;         &quot;max&quot;:[&#xA;            2&#xA;         ],&#xA;         &quot;min&quot;:[&#xA;            0&#xA;         ]&#xA;      },&#xA;      {&#xA;         &quot;bufferView&quot;:1,&#xA;         &quot;byteOffset&quot;:0,&#xA;         &quot;componentType&quot;:5126,&#xA;         &quot;count&quot;:3,&#xA;         &quot;type&quot;:&quot;VEC3&quot;,&#xA;         &quot;max&quot;:[&#xA;            1.0,&#xA;            1.0,&#xA;            0.0&#xA;         ],&#xA;         &quot;min&quot;:[&#xA;            0.0,&#xA;            0.0,&#xA;            0.0&#xA;         ]&#xA;      }&#xA;   ],&#xA;   &quot;asset&quot;:{&#xA;      &quot;version&quot;:&quot;2.0&quot;&#xA;   }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This and other glTF sample models can be found in the &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0&quot; rel=&quot;nofollow noreferrer&quot;&gt;glTF sample models repository&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1649" LastEditorUserId="1649" LastEditDate="2017-11-29T22:03:23.673" LastActivityDate="2017-11-29T22:03:23.673" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4320" PostTypeId="1" CreationDate="2016-11-27T15:42:29.077" Score="4" ViewCount="156" Body="&lt;p&gt;How is &lt;strong&gt;glint rendering&lt;/strong&gt; done with ray tracing in the photo below? &lt;strong&gt;Is it just a simple normal map?&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dybNF.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dybNF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found a paper online that describes the exact same method used in the photo above but I have no idea what's going on, especially with all the jargon being thrown around. Here's the link:&#xA;&lt;strong&gt;&lt;a href=&quot;https://people.eecs.berkeley.edu/~lingqi/publications/paper_glints.pdf&quot; rel=&quot;noreferrer&quot;&gt;https://people.eecs.berkeley.edu/~lingqi/publications/paper_glints.pdf&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-11-27T15:42:29.077" Title="How is glint rendering done in Ray Tracing?" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;physically-based&gt;&lt;normal-mapping&gt;&lt;ray&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4321" PostTypeId="1" AcceptedAnswerId="4557" CreationDate="2016-11-27T23:59:40.663" Score="8" ViewCount="2279" Body="&lt;p&gt;I have some colors in RGB in [0,1] and want to find a way to rate their similarity, as perceived by a human.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have two ideas in mind, but I am sure there are other options as well, but am unsure which is best, or if perhaps there is no best, but only trade offs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first idea is to treat the RGB colors as XYZ points and calculate their distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another idea I have is to treat the RGB values as a histogram and use dot product to get a similarity value between them, where a larger value is better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know however, that not all of the color channels have the same perceived brightness so maybe I ought to weight the color channels differently for both cases?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm also thinking I perhaps would need to do sRGB correction on the color values (such as, sqrt each color channel).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also know other color spaces exist, so maybe one of those would be better at giving a similarity value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another challenge to this may be that different displays will display the same color values differently.  Not sure if that's relevant in this case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone able to provide some help/direction?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorDisplayName="user246" LastEditDate="2017-03-13T00:24:42.417" LastActivityDate="2017-03-13T00:24:42.417" Title="What is a good color similarity metric?" Tags="&lt;color&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4322" PostTypeId="1" AcceptedAnswerId="4323" CreationDate="2016-11-28T04:43:33.893" Score="9" ViewCount="1385" Body="&lt;p&gt;Why is a Lambertian BRDF normalised by dividing by $\pi$? Since the area of a unit sphere is $4 \pi$, and the area of the half sphere above the surface is $2 \pi$, shouldn't it rather be $1/(2\pi)$?&lt;/p&gt;&#xA;" OwnerUserId="4650" LastEditorUserId="4650" LastEditDate="2016-11-28T06:13:52.323" LastActivityDate="2016-11-28T06:13:52.323" Title="Why normalise Lambertian BRDF by 1/pi?" Tags="&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4323" PostTypeId="2" ParentId="4322" CreationDate="2016-11-28T06:13:26.820" Score="7" Body="&lt;p&gt;I think I got it! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because $cos(\theta)$ integrates to $\pi$ over the hemisphere (and not $2\pi$). And the incoming light is multiplied by $cos(\theta)$ (and the BRDF).&lt;/p&gt;&#xA;" OwnerUserId="4650" LastActivityDate="2016-11-28T06:13:26.820" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4324" PostTypeId="1" CreationDate="2016-11-28T07:20:35.980" Score="5" ViewCount="62" Body="&lt;p&gt;I'm working on an SSAO implementation. I've had an idea to speed it up by having AO fragment shader finish faster for fragments that are not occluded (depending on the scene, this can be a significant portion of the screen in my case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried a naive approach first: if, after the initial four samples the occlusion is still zero, we exit. This results in a significant speedup, but the quality deteriorates badly: the occluded portions become very noisy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering if anyone else has attempted a similar optimization. Is there a better way to approach it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="5502" LastActivityDate="2016-11-28T07:20:35.980" Title="Early exit strategy for SSAO" Tags="&lt;ambient-occlusion&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4325" PostTypeId="1" AcceptedAnswerId="4327" CreationDate="2016-11-28T08:59:44.537" Score="5" ViewCount="142" Body="&lt;p&gt;If I have a point in world space: (wx, wy, wz)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and I have a centre of projection: (cx, cy, cz)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and I wanted to project that point using perspective projection&lt;/p&gt;&#xA;&#xA;&lt;p&gt;would my point on the screen be calculated by: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;x = (cz * wx) / wz&#xA;y = (cz * wy) / wz&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I got this from this lecturer &lt;a href=&quot;https://www.youtube.com/watch?v=VpNJbvZhNCQ&quot; rel=&quot;noreferrer&quot;&gt;https://www.youtube.com/watch?v=VpNJbvZhNCQ&lt;/a&gt;&#xA;I don't understand what he means by the variable 'd'. What would the variable 'd' be?&lt;/p&gt;&#xA;" OwnerUserId="5513" LastActivityDate="2016-11-28T23:06:04.277" Title="Am I calculating perspective projection correctly?" Tags="&lt;projections&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4326" PostTypeId="2" ParentId="4321" CreationDate="2016-11-28T12:52:08.143" Score="4" Body="&lt;p&gt;If complex metric is acceptable I would suggest to look at perceptual based approach described &lt;a href=&quot;http://pdiff.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. The metric is designed to pick perceptual difference of two images. There are two main tests for that : luminance based and color based. First one allows to answer the question how important luminance change is by estimating a non uniform threshold factor based on sensitivity to contrast changes depending on spatial frequencies of the image. The second one is based on euclidean distance in CIE LAB color space, but slightly modified to make color difference less important when luminance is in mesopic and scotopic ranges. A list of papers related to that metric can be found &lt;a href=&quot;https://gist.github.com/reinsteam/9e6b3c05109b8bf121ec0f47252a2e1a&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5567" LastEditorUserId="5567" LastEditDate="2016-11-28T16:00:25.253" LastActivityDate="2016-11-28T16:00:25.253" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4327" PostTypeId="2" ParentId="4325" CreationDate="2016-11-28T23:06:04.277" Score="2" Body="&lt;p&gt;In the video you linked to, $d$ is just the distance from the eye to the image plane.  To simplify things though, you can just set $d$ to 1, which is the usual case and causes it to disappear from the formulas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your formula for projection is a bit wrong but don't worry, projection is actually pretty simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x_{Screen} = x_{World} / z_{World}\\&#xA;y_{Screen} = y_{World} / z_{World}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to move the center of projection, you can do so with a screen space coordinate, by modifying the formula to be this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x_{Screen} = x_{World} / z_{World} - x_{ScreenCenter}\\&#xA;y_{Screen} = y_{World} / z_{World} - y_{ScreenCenter}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to re-introduce the $d$ value to control the distance from the eye to the projection plane, you can use the formula below.  Adjusting $d$ will make the camera look like it is zooming in or out.  Again, you can just set $d$ to 1 though and not deal with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x_{Screen} = d*x_{World} / z_{World} - x_{ScreenCenter}\\&#xA;y_{Screen} = d*y_{World} / z_{World} - y_{ScreenCenter}$&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-11-28T23:06:04.277" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4329" PostTypeId="1" CreationDate="2016-11-29T11:50:16.860" Score="6" ViewCount="104" Body="&lt;p&gt;I feel a bit confused about the use of $F_{ij}$ and $F_{ji}$ in Radiosity papers. $F_{ij}$ should be the fraction of energy leaving patch $i$ that arrives at patch $j$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you take the original radiosity paper &lt;em&gt;(&quot;Modeling the Interaction of Light Between Diffuse Surfaces&quot;, by Goral, Torrance, Greenberg, and Battaile, at SIGGRAPH 84)&lt;/em&gt;, the radiosity equation is expressed as:&#xA;$$&#xA;B_{j} = E_{j} + \rho_{j} \sum\limits_{i=1}^n B_{i} F_{ij}&#xA;$$&#xA;and they explicitly mention that all radiosities are measured in $W/m^2$ and that $F_{ij}$ is the &lt;em&gt;&quot;form factor and represents the fraction of radiant energy leaving surface i and impinging on surface j&quot;&lt;/em&gt; (sic).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you take another famous paper &lt;em&gt;(&quot;The Hemi-Cube. A Radiosity solution for complex environments&quot;, by Cohen and Greenberg, at SIGGRAPH 85)&lt;/em&gt; you see that their equation 1 is:&#xA;$$&#xA;B_{i} = E_{i} + \rho_{i} \sum\limits_{j=1}^n B_{j} F_{ij}&#xA;$$&#xA;and they also explicitly say that radiosities are expressed in $W/m^2$ and that $F_{ij}$ is the &lt;em&gt;&quot;the fraction of the energy leaving one surface which lands on another surface&quot;&lt;/em&gt; (sic).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, I didn't make a mistake, both papers use $F_{ij}$ even if they switched the $i$ and $j$ indices and even if they're formulating the classical gathering radiosity (the shooting-based progressive refinement approach came later, in SIGGRAPH 88).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, to add more into the confusion, some books follow the SIGGRAPH 84 paper equation (&lt;em&gt;Foley, van Dam, Feiner, Hugues&lt;/em&gt;, for example), while others use the SIGGRAPH 85 paper equation (&lt;em&gt;Sillion &amp;amp; Puech&lt;/em&gt;, for example).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know $F_{ij}$ and $F_{ji}$ get reversed if you express the equation in radiant energy $(W)$ instead of radiosities $(W/m^2)$ because of the reciprocity relationship $F_{ij}A_{i}=F_{ji}A_{j}$, but however, both equations above are explicitly radiosity-based, in $W/m^2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any mistake in radiosity papers? In that case, what equation is right? Or maybe I'm missing some piece in this puzzle?&lt;/p&gt;&#xA;" OwnerUserId="5571" LastActivityDate="2016-11-29T11:50:16.860" Title="Form Factors confusion in Radiosity papers" Tags="&lt;radiosity&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4331" PostTypeId="2" ParentId="4268" CreationDate="2016-11-29T21:16:41.657" Score="0" Body="&lt;pre&gt;&lt;code&gt;import javafx.scene.canvas.GraphicsContext;&#xA;import javafx.scene.transform.Affine;&#xA;import javafx.scene.transform.NonInvertibleTransformException;&#xA;double xrange = maxx - minx;&#xA;double yrange = maxy - miny;&#xA;// width and height are in units of pixels&#xA;// gc is the GraphicsContext object from javafx&#xA;Affine t = new Affine();&#xA;double xratio = xrange / width;&#xA;double yratio = yrange / height;&#xA;t.appendTranslation( minx, miny );&#xA;t.appendScale( xratio, yratio );&#xA;try&#xA;{&#xA;  t.invert();&#xA;}&#xA;catch( NonInvertibleTransformException e )&#xA;{&#xA;  throw new RuntimeException( e.getMessage(), e );&#xA;}&#xA;gc.setTransform( t );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5478" LastActivityDate="2016-11-29T21:16:41.657" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4333" PostTypeId="1" AcceptedAnswerId="4335" CreationDate="2016-11-30T17:22:36.337" Score="4" ViewCount="173" Body="&lt;p&gt;So, I go to install GMIC for Gimp via the package manager and landed myself upon the demo program. I have discovered things such as Hough transform and  color quantization. So, I get the number of colors on the bottom bar, I understand what it is doing, but I do not get the cube in the middle, mainly why it's 3D or that it has other shapes inside of it (other than the dots for the colors chosen). Basically, I want to know the purpose of this cube, such as why is it a cube, or why is it 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/O6REm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/O6REm.jpg&quot; alt=&quot;Original RGB Quantization Picture!&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: &lt;a href=&quot;https://i.stack.imgur.com/GUzy0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GUzy0.png&quot; alt=&quot;I hope this is a better picture. Turns out the image is different too!&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this is a better picture. Turns out the image is different too!&lt;/p&gt;&#xA;" OwnerUserId="5583" LastEditorUserId="5583" LastEditDate="2016-12-01T02:49:53.607" LastActivityDate="2016-12-01T02:49:53.607" Title="What is the purpose of this cube in color quantization?" Tags="&lt;color&gt;&lt;color-science&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4334" PostTypeId="1" AcceptedAnswerId="4339" CreationDate="2016-11-30T17:55:14.373" Score="3" ViewCount="374" Body="&lt;p&gt;I have NURBS surface data. I have a list of control points, knot vectors in U and V params and the degree. The U knot vector lies in range -3.14 to 3.14 and the knot V vector lies in range -100 to 100. How can I normalize this data so that both knot U and V lies in range 0 to 1?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for your help!&lt;/p&gt;&#xA;" OwnerUserId="5584" LastActivityDate="2016-12-01T09:00:20.597" Title="Normalize NURBS knot vector" Tags="&lt;nurbs&gt;&lt;cad&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4335" PostTypeId="2" ParentId="4333" CreationDate="2016-11-30T19:59:39.063" Score="1" Body="&lt;p&gt;The cube looks like just an RGB cube, i.e. X,Y,Z map to R,G,B. Since there are 3 color channels, the 3D cube is a convenient way to visualize the space of all possible RGB colors. However, I don't know what the pie-wedge-looking shape outlined inside the cube is.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-11-30T19:59:39.063" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4336" PostTypeId="1" AcceptedAnswerId="4338" CreationDate="2016-11-30T21:48:51.070" Score="5" ViewCount="203" Body="&lt;p&gt;After looking at a lot of existing implementations, I am currently implementing a path tracer in OpenCL. However there seems to be divergence to what parts of the pipeline can actually benefit from OpenCL acceleration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is it possible to construct a complete path tracer in OpenCL? What parts of the pipeline will benefit the most? Which will benefit the least? Are there any parts that is recommended to keep out of OpenCL?&lt;/p&gt;&#xA;" OwnerUserId="5586" LastActivityDate="2016-11-30T23:14:44.050" Title="What parts of unbiased path tracing pipeline can benefit from OpenCL?" Tags="&lt;pathtracing&gt;&lt;opencl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4337" PostTypeId="1" CreationDate="2016-11-30T22:40:36.490" Score="6" ViewCount="1559" Body="&lt;p&gt;I am trying to get the screen space position of each pixel in a texture on a mesh and write it into a texture. I was hoping to use a compute shader to do this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#pragma kernel CSMain&#xA;&#xA;struct VertexData&#xA;{&#xA;    float4 v_point;&#xA;    float2 uv;&#xA;    float4x4 MVP; &#xA;};&#xA;&#xA;RWTexture2D&amp;lt;float4&amp;gt; Result;&#xA;RWStructuredBuffer&amp;lt;VertexData&amp;gt; vBuf;&#xA;&#xA;[numthreads(16,1,1)]&#xA;void CSMain (uint3 id : SV_DispatchThreadID)&#xA;{&#xA;    // one thread per pixel in texture&#xA;&#xA;    //Get pixels position in relation to vertices in UV space, using models UV layout&#xA;&#xA;    //multiply pixels object space position against MVP matrix to bring it into clip space and do some stuff to it&#xA;&#xA;    //finally, output this pixels colour back into the texture, storing screen space related data.&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In the above code (lump of comments) I can tell that I am going to run into some problems. The VertexData struct contains mesh data per vertex, but I want to run a thread for each pixel in a texture and then figure out what my pixels position is on a triangle. In a regular shader, this would be interpolated from the vertex shader when using data in the fragment shader, but from my little knowledge of compute shaders, this would require something extra. In the back of my mind I feel like its going to end up being something to do with Barycentric coords, but I just can't put my finger on it!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A picture is worth a thousand words:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Rv4UL.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Rv4UL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The desired end result is a texture mapped to the UV coords of a mesh, storing the screen space positions of each pixel on the mesh. If there is a better way of tackling this, please let me know!&lt;/p&gt;&#xA;" OwnerUserId="5587" LastActivityDate="2017-10-01T17:51:19.740" Title="UV Coordinate Interpolation in Compute Shader" Tags="&lt;shader&gt;&lt;compute-shader&gt;&lt;hlsl&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4338" PostTypeId="2" ParentId="4336" CreationDate="2016-11-30T23:14:44.050" Score="2" Body="&lt;p&gt;In short: All of it can benefit from OpenCL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Path tracing is done by taking many individual ray samples from a scene and combining them into a final image.  As the number of samples increase, so does the quality of the resulting image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are doing regular path tracing (not photon mapping or bidirectional path tracing or anything like that), each sample needs just READ ONLY access to the scene so can work completely independently of the other samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That fact makes path tracing astonishing parallelizable.  If you had an output image resolution of 1000x1000, for a total of 1,000,000 pixels, and took 10,000 samples that would mean you needed to take 10,000,000,000 (10 billion) samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each one of those samples is parallelizable, so if you had 10 billion cores, you could make use of all of them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are pragmatic concerns when doing this including cache coherency, but the costs of getting that wrong with the naive implementation are much smaller than the benefits of going massively threaded in the first place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is some more information about the details of naive path tracing if you are interested:&#xA;&lt;a href=&quot;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2016-11-30T23:14:44.050" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4339" PostTypeId="2" ParentId="4334" CreationDate="2016-12-01T09:00:20.597" Score="1" Body="&lt;p&gt;The relative size of the spacing of knots is irrelevant for the NURBS curve. The only thing that matters is that they keep the relation. Note this may not be wise as parametrization may have other uses behind the scenes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cZzWl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cZzWl.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: 3 differently parametrized knots result in same curve if knot values are relatively the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you can scale and offset knot points as you wish. However you can not make the relative distances between entries different or your curve will change.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ICsHG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ICsHG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: On the other hand if you change the relative spacing your in trouble. So beware of floating point errors if you need to be really accurate.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2016-12-01T09:00:20.597" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4340" PostTypeId="1" CreationDate="2016-12-02T08:26:54.907" Score="1" ViewCount="135" Body="&lt;p&gt;my code :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;A.layout('neato', args='-Gsep=+250 -Gsplines=ortho -Goverlap=false')&#xA;A.draw('1.svg')&#xA;&#xA;#do something, add new nodes with pos to A,&#xA;add_some_nodes_to_A()&#xA;&#xA;for node in A.nodes():&#xA;    node.attr['pos'] += '!'&#xA;    node.attr['pin'] = 'true'&#xA;A.layout('neato', args='-Gsep=+250 -Gsplines=ortho -Goverlap=false - Gnotranslate=true')&#xA;A.draw('2.svg')&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;1.svg :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UfzR0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UfzR0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.svg : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/isZkZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/isZkZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;before the second layout, all A's nodes have pined, why the nodes move in 2.svg? &lt;/p&gt;&#xA;" OwnerUserId="5597" LastActivityDate="2016-12-02T08:26:54.907" Title="why pygraphviz layout() move the nodes which has 'pin = true'?" Tags="&lt;vector-graphics&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2017-05-02T08:31:31.287" ContentLicense="CC BY-SA 3.0" />
  <row Id="4341" PostTypeId="1" AcceptedAnswerId="4342" CreationDate="2016-12-02T12:22:41.513" Score="8" ViewCount="3691" Body="&lt;p&gt;I have been following the &lt;a href=&quot;https://www.scratchapixel.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;scratchapixel&lt;/strong&gt;&lt;/a&gt; ray tracing tutorials online which have been great at explaining the theory behind everything &amp;amp; how to implement it. However, I reached the point where I want to implement Area Lights but I am clueless on how to do it. The tutorial on the website hasn't been uploaded yet (all though there is a placeholder link with a bunch of others).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's not much online regarding implementation so this has lead me here. &lt;strong&gt;Could someone please explain how I can implement Area Lights with Ray Tracing&lt;/strong&gt; as opposed to Point Lights?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KKjbF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KKjbF.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2016-12-03T16:05:50.283" LastActivityDate="2016-12-03T16:05:50.283" Title="Area Lights in Path Tracing" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;physically-based&gt;&lt;area&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4342" PostTypeId="2" ParentId="4341" CreationDate="2016-12-02T18:33:39.380" Score="7" Body="&lt;p&gt;I'm going to provide the simple/naive/brute force answer to this question, which does work, and gives accurate results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are better answers however, which make the rendering converge faster with fewer samples, but uses more advanced math.  I'm hoping someone else will provide an answer along those lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simple answer is this:&#xA;Area lights are just geometry which have an emissive value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To add support for emissive values to path tracing is pretty easy luckily.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you know, the amount of light heading towards a pixel is the amount of light leaving the surface that a ray down that pixel would intersect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is calculated recursively by seeing how much light is hitting that point, integrating the BRDF, multiplying by the cosine and all that jazz.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Emissive lighting is just added to that result.  So, whatever you have now as &quot;outgoing light&quot; from a surface, just add to it the emissive color of that surface.  (You could also optionally do something similar to texture mapping and have emissive values vary over the object, possibly based on a texture).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's all there is to it, it's very simple and easy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the rendering equation below, $L_e(\omega_o)$ represents the emissive term (that's what the e stands for, emissive), and the rest of the equation is the light integrated over the hemisphere.  You can see that you just add the emissive to the result you return as your outgoing light from a point ($L_o( \omega_o)$) to apply that emissive lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_o( \omega_o)= L_e(\omega_o)+\int_{\Omega}{f(\omega_i, \omega_o)L_i(\omega_i)(\omega_i \cdot n)\mathrm{d}\omega_i}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can read more about a simple path tracer with area lights at this link, which also has commented C++ source code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.demofox.org/2016/09/21/path-tracing-getting-started-with-diffuse-and-emissive/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8miKf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8miKf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-12-02T18:41:30.103" LastActivityDate="2016-12-02T18:41:30.103" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4344" PostTypeId="1" AcceptedAnswerId="4346" CreationDate="2016-12-03T06:51:09.220" Score="6" ViewCount="2522" Body="&lt;p&gt;&lt;strong&gt;How can I implement Depth of Field in my Path Tracer?&lt;/strong&gt; I have read this &lt;a href=&quot;https://courses.cs.washington.edu/courses/csep557/99au/projects/trace/depthoffield.doc&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;article&lt;/strong&gt;&lt;/a&gt; which explains the theory behind everything &amp;amp; I already have a good understanding of what this effect needs to achieve based on previous experience with a DSLR but &lt;strong&gt;I am a little confused on how to code everything although I understand a most of the calculations involved&lt;/strong&gt; &lt;em&gt;(after reading the article linked above)&lt;/em&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand how to calculate the focal point, focal distance and the secondary ray. But I'm confused on how to put this all together to create the 'blur' that is needed. I haven't found much online so I was hoping that someone here could explain that with some code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone show me their implementation? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nVWIf.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nVWIf.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="231" LastEditDate="2016-12-04T00:57:35.017" LastActivityDate="2016-12-04T00:57:35.017" Title="Depth of Field in Path Tracing: What do I do with the secondary ray?" Tags="&lt;rendering&gt;&lt;physically-based&gt;&lt;image&gt;&lt;depth-of-field&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4345" PostTypeId="1" CreationDate="2016-12-03T11:57:00.930" Score="1" ViewCount="46" Body="&lt;p&gt;When I have a plaster cast of a &lt;a href=&quot;https://en.wikipedia.org/wiki/Mandible&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Lower jaw bone&quot;&gt;mandibula&lt;/a&gt; and rest it upside down on a table, in most cases it will be in a stable position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In real life, I do not have a plaster cast, but a 3D scan, i.e. a surface mesh. I want to transform the meshes to the position they would be in if they were resting on a table.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why: we have 3D scans of mandibulae, but some of them are slightly misaligned against the axis because the patient did not sit straight. For easier comparison, we would like to make them look more similar. And in case someone suggests &quot;registration&quot;: we do that anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone point me to an algorithm? Any keyword I can use to google?&lt;/p&gt;&#xA;" OwnerUserId="5603" LastEditorUserId="231" LastEditDate="2016-12-04T00:01:33.897" LastActivityDate="2016-12-04T00:02:46.437" Title="Aligning similar surface meshes consistently" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4346" PostTypeId="2" ParentId="4344" CreationDate="2016-12-03T15:23:44.857" Score="5" Body="&lt;h1&gt;The missing step&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you already understand how to generate a secondary ray, then you have already grasped the difficult part. All you need to do now is find the colour that this secondary ray results in. This is exactly the same process as using the primary ray to find a colour, in basic ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After repeating this for a large number of secondary rays, the average of all those colours is the colour you assign to the pixel in question (you don't use the primary ray - its only purpose is generating the secondary rays). This is the only difference from basic ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Why it works&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;My personal difficulty when trying to understand this was that I was trying to understand how the light gets from the different points on the lens back to the eye/camera. The thing to understand is that this is only an approximation of a lens, and the rays don't need to consider the eye/camera at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The lens is being approximated by a disc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All these different secondary rays show you what you would see from different points on that disc, if you looked directly towards a certain point (the focal point).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For an object at the focal point, all these different viewpoints will see the same point on the object, and the object will look sharply defined.&lt;/li&gt;&#xA;&lt;li&gt;For an object behind the focal point, all these different viewpoints will see slightly different positions on the object, and some of them will miss the object and see what is to the side of it. The edges of the object will be blended with the colour of whatever is to the side of it.&lt;/li&gt;&#xA;&lt;li&gt;For an object in front of the focal point, again the different viewpoints will see slightly different positions on the object, giving blurred edges.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If a primary ray hits an object at the focal distance, but there is a closer object which is not quite in the way, but almost, then some of the secondary rays will hit the closer object before they reach the focal point. This will give a blurred edge to the closer object, partially obscuring the object at the focal point, even though that object itself is in sharp focus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of this is as desired. To this level of explanation, this mimics the effect of a real lens, without having to consider refraction at all.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2016-12-03T15:36:38.837" LastActivityDate="2016-12-03T15:36:38.837" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4347" PostTypeId="1" AcceptedAnswerId="4352" CreationDate="2016-12-03T21:09:53.060" Score="8" ViewCount="296" Body="&lt;p&gt;I am looking for theoretical and implemented models to represent color in software that strives for physical accuracy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that &quot;color only exists in the mind&quot; and that it sort of does not make sense to look for &quot;physical accuracy&quot;, but still, how much better is spectrum sampling or other more elaborate representations of color to simple RGB, and what benefits will it bring? What drawback beside performance will it incur (or is performance a drawback)?&lt;/p&gt;&#xA;" OwnerUserId="5586" LastActivityDate="2016-12-08T05:02:32.973" Title="What is the most physically accurate representation of color possible in computer graphics?" Tags="&lt;color&gt;&lt;color-science&gt;&lt;implementation&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4349" PostTypeId="1" CreationDate="2016-12-04T00:26:34.960" Score="7" ViewCount="470" Body="&lt;p&gt;I  am looking for theoretical and implemented models to represent surface materials in software that strives for physical accuracy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is BRDF really the best model? What alternatives are better? Why? What drawbacks beside performance do these models have?&lt;/p&gt;&#xA;" OwnerUserId="5586" LastActivityDate="2017-01-09T19:51:20.567" Title="What is the most physically accurate model of surface materials possible in computer graphics?" Tags="&lt;physically-based&gt;&lt;brdf&gt;&lt;material&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4350" PostTypeId="1" AcceptedAnswerId="4356" CreationDate="2016-12-04T11:34:43.663" Score="6" ViewCount="713" Body="&lt;p&gt;I am looking for a method of rendering a heightmap from a 3D scene. The scene may consist of a terrain which is in turn generated from another heightmap, but will also have regular 3D objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The generated heightmap should, so to speak, indicate the highest point in the &quot;column&quot; of the 3D scene represented by each pixel in the heightmap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This does not need to be a fast/realtime operation, and it does not really matter what language or library is used, although I'd prefer using Python (perhaps with Panda3D?). Also, I would prefer being able to run it headlessly, from a command-line tool without the need for an actual on-screen rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this a common operation for which there are established/canonical methods, either through a library such as Panda3D or through more direct/low-level use of data structures representing the 3D scene?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I should add that I am quite new to the computer graphics field of programming.&lt;/p&gt;&#xA;" OwnerUserId="5605" LastActivityDate="2016-12-06T09:20:26.703" Title="Method for rendering heightmap from a 3D scene" Tags="&lt;scene-graph&gt;&lt;height-field&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4352" PostTypeId="2" ParentId="4347" CreationDate="2016-12-05T10:13:18.270" Score="7" Body="&lt;p&gt;The most physically accurate way would be to have a $l(\theta)$ which for each possible color frequency has a certain value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Converting to RGB would then need a frequency responce function for each channel and the result is then $\int_{infrared}^{ultraviolet} l(\theta)F_{red}(\theta)d\theta$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Reflected light then has a 2 dimensional response function: $L_{reflected}(\theta) = \int l_{incoming}(\phi)R(\phi,\theta)d\phi$. (ignoring the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;BRDF&lt;/a&gt; here for simplicity)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Drawbacks are that instead of just 3 color channels you now have &lt;strong&gt;infinite&lt;/strong&gt; channels to worry about.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2016-12-05T10:13:18.270" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4353" PostTypeId="2" ParentId="4272" CreationDate="2016-12-05T15:35:43.780" Score="3" Body="&lt;p&gt;You already have a 2D parametrisation, don't you? One of the dimensions is the longitudal axis (in mm?) and the other is the circumferential axis (in degrees). The only problem I see is when you have rectangles wrapping around the 0/360-degree boundary. One workaround for that would be to duplicate each rectangle (or just the ones on the boundary) so that you get one copy on each side of the boundary. Does that help? And if you need to have a distance, and not an angle, for the circular dimension, that is readily available as $l = r a \pi/180$, where $r$ is the radius and $a$ is the angle in degrees.&lt;/p&gt;&#xA;" OwnerUserId="4650" LastActivityDate="2016-12-05T15:35:43.780" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4354" PostTypeId="1" AcceptedAnswerId="4357" CreationDate="2016-12-05T19:59:12.123" Score="4" ViewCount="635" Body="&lt;p&gt;I am trying to make use of free hardware PCF sampling with &lt;code&gt;sampler2DShadow&lt;/code&gt; and extend it to more samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I am sampling shadow map (&lt;code&gt;sampler2D&lt;/code&gt;) in ESM way and extending this to PCF and it works.&#xA;So I have no acne (thanks to ESM) and soft result, but I need a lot of PCF samples:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float shadowMapSize = 512.0;&#xA;float c = 5000.0;&#xA;float receiver = lightCoords.z;&#xA;float shadow = 0.0;&#xA;for(int i = 0; i &amp;lt; SAMPLE_NUM; ++i)&#xA;{&#xA;    vec2 off = (POISSON_SAMPLES[i])/shadowMapSize;&#xA;    float occluder = texture(shadowmap, lightCoords.xy+off).r;&#xA;    shadow += exp(c*(occluder-receiver));&#xA;}&#xA;shadow /= SAMPLE_NUM;&#xA;&#xA;shadow = clamp(shadow, 0.0, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But I wanted to use &lt;code&gt;sampler2DShadow&lt;/code&gt; and get 4 PCF tabs for free and extend this to 16 taps for almost free with only 4 poisson samples like that:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float shadowMapSize = 512.0;&#xA;float c = 5000.0;&#xA;float receiver = lightCoords.z;&#xA;float shadow = 0.0;&#xA;for(int i = 0; i &amp;lt; SAMPLE_NUM; ++i)&#xA;{&#xA;    vec2 off = (POISSON_SAMPLES[i])/shadowMapSize;&#xA;    float occluder = texture(shadowmap, vec3(lightCoords.xy+off, receiver)).r;&#xA;    shadow += exp(c*(occluder-receiver));&#xA;}&#xA;shadow /= SAMPLE_NUM;&#xA;shadow = clamp(shadow, 0.0, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But unfortunately it doesnt work as expected:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qjV7F.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qjV7F.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to make it work (in ESM way, not traditional due to acne) or due to &lt;code&gt;sampler2DShadow&lt;/code&gt; specification it is rather impossible? In traditional way it is possible.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-12-05T20:58:40.107" LastActivityDate="2016-12-06T22:51:40.787" Title="Exponential shadow maps sampling with PCF for sampler2DShadow instead of sampler2D" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;glsl&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4355" PostTypeId="2" ParentId="4350" CreationDate="2016-12-05T22:04:07.790" Score="4" Body="&lt;p&gt;Using OpenGL, or any such library, you could transform your scene with an orthogonal matrix and move your camera view point to be looking above (and parallel to) the scene (in a vertex shader) and then use an empty fragment shader which is going to write to the depth buffer of the current attached framebuffer. Finally retrieving this depth buffer gives you the heightmap of the current view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your scene is too big, you could move the camera higher and also move it around taking &quot;chunks&quot; of the map at a time and assembling your heightmap manually by &quot;stitching&quot; these &quot;chunk&quot; heightmaps together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps.&lt;/p&gt;&#xA;" OwnerUserId="5002" LastActivityDate="2016-12-05T22:04:07.790" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4356" PostTypeId="2" ParentId="4350" CreationDate="2016-12-06T09:20:26.703" Score="4" Body="&lt;p&gt;The easiest way to do this is by rendering the 3D scene the way you usually would through OpenGL, using whatever 3D Python library you already have loading the scene. Instead of the perspective camera you would usually use, render through an orthographic camera looking down on the scene from above (making sure the camera plane is above any part of the scene). Make sure the renderer uses a z (depth) buffer, and if you don't want anything on screen, render it to an off-screen buffer (you don't actually need the colour buffer at all, only the z buffer). Just &lt;code&gt;glReadPixels&lt;/code&gt; the z buffer (i.e. read back the pixels from the buffer) after rendering, and save it to a file. Your 3D library will probably have a way to save the buffer to a file directly.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-12-06T09:20:26.703" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4357" PostTypeId="2" ParentId="4354" CreationDate="2016-12-06T17:04:28.847" Score="3" Body="&lt;p&gt;PCF does N shadow tests, where each test returns 1 (in light) or 0 (in shadow), and returns the average of the results. &lt;code&gt;sampler2DShadow&lt;/code&gt; is a special sampler where PCF is applied to the nearest texels to a sample, based on the depth coordinate provided. So you can't use it with ESM.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="231" LastEditDate="2016-12-06T22:51:40.787" LastActivityDate="2016-12-06T22:51:40.787" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4358" PostTypeId="1" AcceptedAnswerId="4425" CreationDate="2016-12-06T17:49:11.040" Score="3" ViewCount="288" Body="&lt;p&gt;You can perform color conversion as a post process step to convert a rendered frame's colors to a different set of colors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might make darker colors more blue for instance, to give it a night time feel, or just modify colors to give it a different mood.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way of doing this is using a volume texture.  You use the RGB value of a source pixel as texture coordinates into a volume texture, where you read out the RGB value that you should replace that pixel with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/registry/specs/SGIS/texture4D.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;This&lt;/a&gt; page on the 4d texture GL extension says this though:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Four-dimensional textures are used primarily as color lookup tables&#xA;  for color conversion.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain why you would use a 4d texture lookup for color grading?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alpha (transparency) lookup doesn't seem like a plausible explanation, but perhaps something like normalizing an HDR color and using the intensity as the fourth component could be?  Or perhaps time, to be able to interpolate between two different color gradings, when moving from inside to outside and exposure is changing or something?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2016-12-06T17:54:58.873" LastActivityDate="2016-12-27T17:54:32.507" Title="Why would a 4d texture be used for color conversion?" Tags="&lt;color&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4359" PostTypeId="2" ParentId="4358" CreationDate="2016-12-06T19:46:50.763" Score="6" Body="&lt;p&gt;I think your quote refers to conversion between color spaces, rather than color grading. 4d textures could be used as lookup tables to convert color spaces like CMYK to some other space. Since CMYK has 4 components, a 3d texture wouldn't be enough.&lt;/p&gt;&#xA;" OwnerUserId="5632" LastActivityDate="2016-12-06T19:46:50.763" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4360" PostTypeId="1" AcceptedAnswerId="4365" CreationDate="2016-12-06T21:59:51.237" Score="4" ViewCount="2508" Body="&lt;p&gt;I have a point $P = (0, y, z)$. I need to determine the $x$ coordinate of its projection $P'$ onto a plane $T$ along the $x$ axis unit vector $\vec{X} = (1, 0, 0)$. The plane $T$ is defined by a point $V$ that lies on $T$ and its normal $\vec{N}$ (see the attached picture).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NIbgq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NIbgq.png&quot; alt=&quot;Projection onto plane along a vector.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3233" LastEditorUserId="3233" LastEditDate="2017-11-15T19:05:23.837" LastActivityDate="2017-11-15T19:05:23.837" Title="How to project a 3D point onto a plane along another (axis) vector?" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4361" PostTypeId="1" CreationDate="2016-12-06T22:35:52.973" Score="4" ViewCount="1029" Body="&lt;p&gt;I am struggling trying to implement vertex selection by mouse clicking. I load in some set of vertices and display them onto the screen. Then I do the following to try and retrieve a line that passes through the selected point in world coordinates and through the eye position.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  setFocus();&#xA;  float xRatio, yRatio, xScene, yScene;&#xA;  xRatio = (float)event-&amp;gt;x() / width();&#xA;  yRatio = (float)event-&amp;gt;y() / height();&#xA;&#xA;  xScene = (1-xRatio)*-1 + xRatio*1;&#xA;  yScene = yRatio*-1 + (1-yRatio)*1;&#xA;  // mouse click now transformed to [-1,1]^2&#xA;&#xA;  // Import the viewPort&#xA;      GLint *params = new GLint(4);&#xA;      glGetIntegerv(GL_VIEWPORT, params);&#xA;      QRect vp = QRect(*params, *(params + 1), *(params + 2), *(params + 3));     &#xA;&#xA;&#xA;      QVector3D dir = QVector3D(xScene, yScene, 0.2); // distance to near pane = 0.2&#xA;      QVector3D origin = QVector3D(0.0, 0.0, 0.0);&#xA;&#xA;  // Now I have the origin and point in near clipping pane of the line (I think)&#xA;  // Unproject them to world coordinates.&#xA;      dir = dir.unproject(modelViewMatrix, projectionMatrix, vp);&#xA;      origin = origin.unproject(modelViewMatrix, projectionMatrix, vp);&#xA;&#xA;  float minDist = 1000.0;&#xA;  int minIndex = 0;&#xA;  float dist;&#xA;&#xA;  for (int i = 0; i &amp;lt; vertexCoords.size(); ++i){&#xA;      dist = vertexCoords[i].distanceToLine(origin, dir);&#xA;      if (dist &amp;lt; minDist){&#xA;          minDist = dist;&#xA;          minIndex = i;&#xA;      }&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I keep getting wrong result with this method. It will almost always select the same point and report a large distance of about 20 to that point. So something is going terribly wrong. Can anyone spot what is going wrong or what I am missing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, here is how the view and projection matrices look:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  modelViewMatrix.setToIdentity();&#xA;  modelViewMatrix.translate(QVector3D(0.0, 0.0, -3.0));&#xA;  modelViewMatrix.scale(QVector3D(1.0, 1.0, 1.0));&#xA;  modelViewMatrix.rotate(rotX, 0.0, 1.0, 0.0);&#xA;  modelViewMatrix.rotate(rotY, 1.0, 0.0, 0.0);&#xA;&#xA;  projectionMatrix.setToIdentity();&#xA;  projectionMatrix.perspective(FoV, dispRatio, 0.2, 8.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Sorry for the long question, I have found quite some resources online but none of them help me figure out what is going wrong. Also, if there is a better method I would gladly hear it! Thanks&lt;/p&gt;&#xA;" OwnerUserId="5633" LastActivityDate="2018-03-01T12:13:17.790" Title="How to perform vertex selection using unproject (Qt/openGL)" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4363" PostTypeId="1" AcceptedAnswerId="4382" CreationDate="2016-12-07T10:13:04.487" Score="5" ViewCount="1699" Body="&lt;p&gt;I am trying to implement &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems/gpugems_ch07.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blades of Waving Grass&lt;/a&gt; and I am still stuck at the point where I need to achieve texture arrangements like in the figure below (the first one).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QVbKy.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QVbKy.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my plan is to draw the first texture, then draw the second and rotate it by 30°, then another and rotate it by 60° etc. Drawing the first texture is not a problem but I have some issues rotating the second one. I would expect it to look something like this (view from above):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7xhvk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7xhvk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead the actual result looks something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7qQrc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7qQrc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect that this deviation occurs due to the object being rotated around the world-space axes and not around its own.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex and position data:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat vertices[] = {&#xA;    -0.5f, -0.5f, -0.5f,  0.0f,  0.0f,&#xA;     0.5f, -0.5f, -0.5f,  1.0f,  0.0f,&#xA;     0.5f,  0.5f, -0.5f,  1.0f,  1.0f,&#xA;     0.5f,  0.5f, -0.5f,  1.0f,  1.0f,&#xA;    -0.5f,  0.5f, -0.5f,  0.0f,  1.0f,&#xA;    -0.5f, -0.5f, -0.5f,  0.0f,  0.0f,&#xA;};&#xA;&#xA;glm::vec3 texturePositions[] = {&#xA;    glm::vec3(0.0f, 0.0f, 0.0f),&#xA;    glm::vec3(0.0f, 0.0f, 0.0f)&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Camera/View transformations:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Camera/View transformation&#xA;glm::mat4 view;&#xA;view = camera.GetViewMatrix();&#xA;// Projection&#xA;glm::mat4 projection;&#xA;projection = glm::perspective(glm::radians(camera.Zoom), (GLfloat)WIDTH / (GLfloat)HEIGHT, 0.1f, 1000.0f);&#xA;// Get the uniform locations&#xA;GLint modelLoc = glGetUniformLocation(ourShader.Program, &quot;model&quot;);&#xA;GLint viewLoc = glGetUniformLocation(ourShader.Program, &quot;view&quot;);&#xA;GLint projectionLoc = glGetUniformLocation(ourShader.Program, &quot;projection&quot;);&#xA;// Pass the matrices to the shader&#xA;glUniformMatrix4fv(viewLoc, 1, GL_FALSE, glm::value_ptr(view));&#xA;glUniformMatrix4fv(projectionLoc, 1, GL_FALSE, glm::value_ptr(projection));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Drawing the first two textures:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Texture 1&#xA;glm::mat4 model;&#xA;model = glm::translate(model, texturePositions[0]);&#xA;glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));&#xA;glDrawArrays(GL_TRIANGLES, 0, 6);&#xA;&#xA;//Texture 2&#xA;GLfloat angle = glm::radians(30.0f);&#xA;model = glm::translate(model, texturePositions[1]);&#xA;model = glm::rotate(model, angle, glm::vec3(0.0f, 1.0f, 0.0f));&#xA;glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));&#xA;glDrawArrays(GL_TRIANGLES, 0, 6);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Online search showed that this might have several reasons:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Order of the applied transformations are crucial&lt;/li&gt;&#xA;&lt;li&gt;One solution might be to first move the &quot;object&quot; until its center&#xA;matches the world-space origin, apply the rotation and then move it&#xA;to the desired position.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;As I am still in the very early learning process so I am kind of clueless here.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I think that the order of transformations for the second texture is fine in my code, isn't it?&lt;/li&gt;&#xA;&lt;li&gt;Also how would I determine the right position for the object where&#xA;the rotation would be applied correctly? (see above point 2)&lt;/li&gt;&#xA;&lt;li&gt;Might it be more efficient to apply the rotation in the objects&#xA;local space? Is that possible in my case?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I do not expect anybody to write code for me (though some snippet would be nice) but I would appreciate some hints or somebody pointing me in the right direction. I think that I have a basic fallacy here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If I change the rotation axis from &lt;code&gt;y&lt;/code&gt; to &lt;code&gt;z&lt;/code&gt; the object rotates&#xA;around its own center just like expected.&lt;/li&gt;&#xA;&lt;li&gt;I also tried to apply the following solutions (taken from &lt;a href=&quot;https://gamedev.stackexchange.com/questions/18854/rotating-an-object-in-opengl-about-its-centre&quot;&gt;here&lt;/a&gt;&#xA;and &lt;a href=&quot;https://www.opengl.org/discussion_boards/showthread.php/169200-Rotating-an-Object-around-its-center&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;) where I moved the object to &lt;code&gt;glm::vec3(-x,-y,-z)&lt;/code&gt;&#xA;rotate it and then moving it back to &lt;code&gt;glm::vec3(x,y,z)&lt;/code&gt;,&#xA;unfortunately with no success. Which makes sence as the position&#xA;vector is set to (0,0,0) anyway. I also tried to change thisposition&#xA;to something else than the origin also with no success.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2485" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T09:06:20.863" LastActivityDate="2018-03-06T09:06:20.863" Title="Rotating object around its own center" Tags="&lt;opengl&gt;&lt;transformations&gt;" AnswerCount="2" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4364" PostTypeId="2" ParentId="4363" CreationDate="2016-12-07T14:03:26.197" Score="1" Body="&lt;p&gt;I see you are rendering one quad of grass at the time. Many draw calls each for small number of vertices aren't very efficient and would make massive CPU bottlenecks especially if you want to render thousand of grass blades. This isn't an answer to your question about order of transformation but you might consider how I implemented this grass technique.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I stored each grass instance (3 quads with 60° degrees between each as in picture) in single VAO which contains buffers for vertices, texcoords, indices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//first quad&#xA;vertices.push_back(glm::vec3(-0.25, 0.5, 0.0));&#xA;vertices.push_back(glm::vec3(0.25, 0.5, 0.0));&#xA;vertices.push_back(glm::vec3(-0.25, 0.0, 0.0));&#xA;vertices.push_back(glm::vec3(0.25, 0.0, 0.0));&#xA;&#xA;//second quad&#xA;vertices.push_back(glm::vec3(-0.25 * glm::cos(60.0f), 0.5, -0.25 * glm::sin(60.0f)));&#xA;vertices.push_back(glm::vec3(0.25 * glm::cos(60.0f), 0.5, 0.25 * glm::sin(60.0f)));&#xA;vertices.push_back(glm::vec3(-0.25 * glm::cos(60.0f), 0.0, -0.25 * glm::sin(60.0f)));&#xA;vertices.push_back(glm::vec3(0.25 * glm::cos(60.0f), 0.0, 0.25 * glm::sin(60.0f)));&#xA;&#xA;//third quad&#xA;vertices.push_back(glm::vec3(0.25 * glm::cos(60.0f), 0.5, -0.25 * glm::sin(60.0f)));&#xA;vertices.push_back(glm::vec3(-0.25 * glm::cos(60.0f), 0.5, 0.25 * glm::sin(60.0f)));&#xA;vertices.push_back(glm::vec3(0.25 * glm::cos(60.0f), 0.0, -0.25 * glm::sin(60.0f)));&#xA;vertices.push_back(glm::vec3(-0.25 * glm::cos(60.0f), 0.0, 0.25 * glm::sin(60.0f)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;sin&lt;/em&gt; and &lt;em&gt;cos&lt;/em&gt; are from &lt;a href=&quot;http://www.mathopenref.com/coordparamcircle.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;circle equation&lt;/a&gt;. You might need to change these angles to radians if you use glm.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//texcoords&#xA;for (int i = 0; i &amp;lt; 3; ++i)&#xA;{&#xA;    texCoords.push_back(glm::vec2(1.0, 0.0)); &#xA;    texCoords.push_back(glm::vec2(0.0, 0.0));&#xA;    texCoords.push_back(glm::vec2(1.0, 1.0)); &#xA;    texCoords.push_back(glm::vec2(0.0, 1.0));&#xA;}&#xA;&#xA;//indices&#xA;    for(int i = 0; i &amp;lt; 3; ++i)&#xA;    {&#xA;        for(int j = 0; j &amp;lt; 4; ++j)&#xA;        {&#xA;            indices.push_back(4*i + j);&#xA;            if(j == 3 &amp;amp;&amp;amp; i != 2)&#xA;            {&#xA;                indices.push_back(4*i+j);&#xA;                indices.push_back(4*i+j+1);&#xA;            }&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then draw call for single instance with triangle strip:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawElements(GL_TRIANGLE_STRIP, indices.size(), GL_UNSIGNED_INT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But the power lies in drawing many instances with single draw call as you can do it easily with so filled buffer. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawElementsInstanced(GL_TRIANGLE_STRIP, indices.size(), GL_UNSIGNED_INT, 0, totalGrassInstances);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Each instance will have its position somewhere on the terrain which is &lt;code&gt;glm::vec3&lt;/code&gt; type. This is the additional buffer you need to bind with VAO to do instancing. Then you only need &lt;code&gt;model&lt;/code&gt; matrix you use for terrain, for example which scales your terrain multiplied by &lt;code&gt;viewProjection&lt;/code&gt;, or just &lt;code&gt;viewProjection&lt;/code&gt; matrix if your positions generated by CPU are in world space, which you multiply by the position of each instance in vertex shader. thats all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case you need some random scale or rotation matrix for each instance to look more realistic you can generate on the fly based on some random values in vertex shader.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2016-12-07T14:40:03.687" LastActivityDate="2016-12-07T14:40:03.687" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4365" PostTypeId="2" ParentId="4360" CreationDate="2016-12-07T16:38:40.270" Score="6" Body="&lt;p&gt;You can determine &lt;code&gt;x&lt;/code&gt; by calculating line-plane intersection. Your line starts at &lt;code&gt;P&lt;/code&gt; and has direction &lt;code&gt;D=[1, 0, 0]&lt;/code&gt;, and plane &lt;code&gt;T=[V, N]&lt;/code&gt;. This can be done as follows:&#xA;$$x=\frac{(V-P)\cdot N}{N\cdot D}$$&#xA;&lt;code&gt;x&lt;/code&gt; is the distance from &lt;code&gt;P&lt;/code&gt; along &lt;code&gt;D&lt;/code&gt; to the intersection point with &lt;code&gt;T&lt;/code&gt; (assuming both &lt;code&gt;D&lt;/code&gt; and &lt;code&gt;N&lt;/code&gt; are unit vectors)&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-12-07T16:38:40.270" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4366" PostTypeId="1" AcceptedAnswerId="4367" CreationDate="2016-12-07T19:08:26.103" Score="5" ViewCount="180" Body="&lt;p&gt;I tried passing a variable from the vertex shader to tell the fragment shader whether or not I wanted part of an object textured. That way I could write another shader for the other parts of the object. Unfortunately, what I have creates the undesirable effect seen here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rQKtO.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rQKtO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex shader for house&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;script id=&quot;long_house-vs&quot; type=&quot;x-shader/x-vertex&quot;&amp;gt;&#xA;    precision highp float;&#xA;&#xA;    attribute vec3 vpos;&#xA;    attribute vec3 vnormal;&#xA;    attribute vec2 vtexCoords;&#xA;&#xA;    varying vec3 outNormal;&#xA;    varying vec3 outPos;&#xA;    varying vec2 outTexCoords;&#xA;    // 1 if part of roof&#xA;    varying float roof;&#xA;&#xA;&#xA;    uniform mat4 view;&#xA;    uniform mat4 proj;&#xA;    uniform mat4 model;&#xA;    uniform vec3 lightdir;&#xA;    uniform vec3 long_housecolor;&#xA;&#xA;    void main(void) {&#xA;        if(vpos.y &amp;gt; 1.2) {&#xA;            roof = 1.0;&#xA;        } else {&#xA;            roof = 0.0;&#xA;        }&#xA;        gl_Position = proj * view * model * vec4(vpos, 1.0);&#xA;        outTexCoords = vtexCoords;&#xA;        outPos =  (view * model * vec4(vpos, 1.0)).xyz;&#xA;        outNormal = normalize(view * model * vec4(vnormal,0.0)).xyz;&#xA;    }&#xA;&amp;lt;/script&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;fragment shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;script id=&quot;long_house-fs&quot; type=&quot;x-shader/x-fragment&quot;&amp;gt;&#xA;    precision highp float;&#xA;    varying vec3 outNormal;&#xA;    varying vec3 outPos;&#xA;    varying vec2 outTexCoords;&#xA;    varying float roof;&#xA;&#xA;    uniform vec3 lightdir;&#xA;    uniform vec3 long_housecolor;&#xA;    uniform sampler2D usampler;&#xA;    uniform sampler2D urooftext;&#xA;&#xA;    void main(void) {&#xA;        float diffuse = .5 + .5*abs(dot(outNormal, lightdir));&#xA;        vec3 outColor = long_housecolor * diffuse;&#xA;        vec4 textureColor;&#xA;        if(roof == 1.0) {&#xA;            textureColor = texture2D(urooftext, outTexCoords);&#xA;        } else {&#xA;            discard;&#xA;        }&#xA;        gl_FragColor = vec4(textureColor.rgb * diffuse, textureColor.a);&#xA;    }&#xA;&amp;lt;/script&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I rearrange the code a bit so that the bottom half of the house is textured instead of the top I get this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Vkq46.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Vkq46.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what would be the correct way to write a shader that only affects part of an object?&lt;/p&gt;&#xA;" OwnerUserId="5640" LastActivityDate="2016-12-09T03:15:10.777" Title="What is the correct way to put different textures on different parts of an object?" Tags="&lt;shader&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4367" PostTypeId="2" ParentId="4366" CreationDate="2016-12-07T19:59:31.397" Score="4" Body="&lt;p&gt;In vertex, put  &lt;code&gt;vPos&lt;/code&gt; as &lt;code&gt;varying&lt;/code&gt;. Then instead of doing the height check in vertex, do it in fragment.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(outVPos.y &amp;gt; 1.2) &#xA;{&#xA;   textureColor = texture2D(urooftext, outTexCoords);&#xA;} &#xA;else &#xA;{&#xA;   discard;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;By the way, &lt;code&gt;varying&lt;/code&gt; qualifier is deprecated and replaced with &lt;code&gt;out&lt;/code&gt; in vertex and &lt;code&gt;in&lt;/code&gt; in fragment.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2016-12-07T19:59:31.397" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4368" PostTypeId="2" ParentId="4347" CreationDate="2016-12-08T04:41:03.083" Score="7" Body="&lt;p&gt;There is &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Spectral_rendering&quot; rel=&quot;noreferrer&quot;&gt;spectral rendering&lt;/a&gt;, where you can quantize the visible wavelengths from ~390nm to ~700nm to N discrete wavelengths instead of the standard 3 for RGB. Then if you had to model say a prism, you would get more realistic distribution of the spectrum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Light has also property of polarization that you would need to model for increased realism. I don't know if this is being modeled in any existing publicly available rendering engines and how would you represent it exactly. Light is electromagnetic wave with two orthogonal electric and magnetic components, which may have different amplitudes and be also out of phase potentially resulting in elliptical polarization. The polarization would be a relevant propery for example to model multiple specular reflections from dielectric surfaces, or modeling polarizing filters used by photographers on cameras.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both spectral rendering and accounting light polarization would come with the cost of performance and higher memory usage.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-12-08T05:02:32.973" LastActivityDate="2016-12-08T05:02:32.973" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4369" PostTypeId="1" CreationDate="2016-12-08T12:25:51.290" Score="11" ViewCount="587" Body="&lt;p&gt;&lt;strong&gt;How could I generate the waves for a water body with whitecaps &amp;amp; foam and variable intensity of the waves?&lt;/strong&gt; Is the surface a mesh with a normal map? Is there a formula for generating that? Is there something similar to determine where and how the whitecaps are rendered?  I came across this &lt;a href=&quot;http://www.cs.utah.edu/~michael/water/waterPGColor.pdf&quot; rel=&quot;noreferrer&quot;&gt;&lt;strong&gt;paper&lt;/strong&gt;&lt;/a&gt; but it's not very clear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the paper, I understand the part where it talks about wave generation. There is a section dedicated to whitecaps and foam and it does present a formula to generate them but how do you only apply it to the parts of the water that need it? Based on what I observed it just represents F as the area that will need whitecaps, could someone clarify how that works aswell?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2016-12-08T13:04:06.707" LastActivityDate="2018-09-05T07:35:56.257" Title="Ocean Wave Rendering" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4370" PostTypeId="1" CreationDate="2016-12-08T18:49:30.387" Score="7" ViewCount="4118" Body="&lt;p&gt;&lt;em&gt;I'd like to create a mesh from a point cloud generated by video tracking, ideally using python for some kind of prototype at least.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Initially I thought this is a fairly easy task, connecting the vertices, creating the faces, done ;) Then I've read that &lt;a href=&quot;http://www.cs.jhu.edu/~misha/Code/PoissonRecon/Version9.01/&quot; rel=&quot;noreferrer&quot;&gt;Screened Poisson Surface Reconstruction&lt;/a&gt; is currently the best approach. Although there is a nice &lt;a href=&quot;https://github.com/mkazhdan/PoissonRecon&quot; rel=&quot;noreferrer&quot;&gt;github repository&lt;/a&gt; and code to play with, it's hard to understand the papers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; Is there another clever implementation/approach you would recommend or is &lt;em&gt;Screened Poisson Surface Reconstruction&lt;/em&gt; the way to go? Any suggestion how to implement that as simple as possible will be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="18" LastActivityDate="2017-11-28T11:08:43.790" Title="Creating a mesh from a point cloud?" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4371" PostTypeId="2" ParentId="4366" CreationDate="2016-12-09T03:15:10.777" Score="4" Body="&lt;p&gt;There are couple of ways this is usually done:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) put the textures for the house to a single texture are just UV-map the object accordingly. If you would need to use different BRDF etc. for different parts of the object, you can use uber shader and switch in shader and use another texture to control which BRDF to use in which parts. The benefit is that you can render the entire object with a single draw call reducing CPU overhead with the expense of some GPU overhead due to the uber shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) split the object to different sub-objects (at triangle level) based on the material and issue separate draw call for each. This keeps the shader simpler, but has higher CPU overhead due to more draw calls.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-12-09T03:15:10.777" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4374" PostTypeId="1" CreationDate="2016-12-10T17:52:17.820" Score="7" ViewCount="507" Body="&lt;p&gt;I am writing a basic raytracer and have implemented normal maps. However, when using normal maps, sometimes the rays generated are opposite to the surface's geometry normal, so that the rays are reaching light sources behind the object. If I kill the ray, the shading results looked faceted and the surface normals are apparent. If I don't kill the ray, the ray reaches light sources on the opposite side of the geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is this handled normally?&lt;/p&gt;&#xA;" OwnerUserId="5653" LastActivityDate="2017-01-09T19:35:15.503" Title="Sampling against geometry normals" Tags="&lt;raytracing&gt;&lt;geometry&gt;&lt;shading&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4375" PostTypeId="2" ParentId="4374" CreationDate="2016-12-10T18:01:57.447" Score="0" Body="&lt;p&gt;One thing that I see being done, is that when the ray is generated, the location is shifted on the normal. Basically the normal multiplied by a small amount is added to it.&#xA;If you are shading the backside of the face, then the normal needs to be inverted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason why, is, for example, when a light is behind a face, and you cast the light ray. Without the offset the origin is exactly on the face, so t is 0. Algorithms see this as not a hit, so the offset along the normal, makes it so that t isn't 0 anymore.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this answers it.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2016-12-10T18:01:57.447" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4377" PostTypeId="1" CreationDate="2016-12-12T14:51:30.703" Score="5" ViewCount="868" Body="&lt;p&gt;I am trying to implement the &lt;a href=&quot;http://developer.download.nvidia.com/shaderlibrary/docs/shadow_PCSS.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Percentage-closer Soft Shadows&lt;/a&gt; (PCSS) from NVidia inside Unity but I am facing some issue and I don't know where they come from and then, I do not know how to solve them...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my current setup.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using an orthographic camera to calculate my shadowmap. Here are the different steps and some pseudo-code.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Setup camera&#xA;_shadowCamera.clearFlags = CameraClearFlags.Depth;&#xA;_shadowCamera.orthographic= true;&#xA;&#xA;// Setup a render texture to output the shadowmap from the camera&#xA;RenderTexture _shadowTexture = new RenderTexture((int)_shadowMapSize, _shadowMapSize, 16, RenderTextureFormat.Shadowmap, RenderTextureReadWrite.Linear);&#xA;&#xA;// Render scene using a replacement shader. This is only used to output &#xA;_shadowCamera.SetReplacementShader(_shadowMapShader, &quot;RenderType&quot;);&#xA;_shadowCamera.Render();&#xA;&#xA;// Set the camera positions and matrix&#xA;_radius = _bounds;&#xA;Vector3 targetPos = _target.transform.position;&#xA;Vector3 lightDir = _light.transform.forward;&#xA;Quaternion lightRot = _light.transform.rotation;&#xA;&#xA;_shadowCamera.transform.position = targetPos - lightDir * _radius;&#xA;_shadowCamera.transform.rotation = lightRot;&#xA;_shadowCamera.orthographicSize = _radius;&#xA;&#xA;_shadowCamera.farClipPlane = _radius * 2.0f;&#xA;&#xA;Matrix4x4 shadowViewMatrix = _shadowCamera.worldToCameraMatrix;&#xA;Matrix4x4 shadowProjectionMatrix = GL.GetGPUProjectionMatrix(_shadowCamera.projectionMatrix, false);&#xA;&#xA;Matrix4x4 shadowBiasMatrix = Matrix4x4.identity;&#xA;shadowBiasMatrix.SetRow(0, new Vector4(0.5f, 0.0f, 0.0f, 0.5f));&#xA;shadowBiasMatrix.SetRow(1, new Vector4(0.0f, 0.5f, 0.0f, 0.5f));&#xA;shadowBiasMatrix.SetRow(2, new Vector4(0.0f, 0.0f, 1.0f, 0.0f));&#xA;shadowBiasMatrix.SetRow(3, new Vector4(0.0f, 0.0f, 0.0f, 1.0f));&#xA;&#xA;_shadowMatrix = shadowBiasMatrix * shadowProjectionMatrix * shadowViewMatrix;&#xA;&#xA;// Transfering data to shader&#xA;_material.SetMatrix(&quot;_ShadowMatrix&quot;, _shadowMatrix);&#xA;_material.SetTexture(&quot;_ShadowTexture&quot;, _shadowTexture);&#xA;_material.SetTexture(&quot;u_PointSampler&quot;, _pointSampler);&#xA;_material.SetFloat(&quot;u_NearPlane&quot;, _shadowCamera.nearClipPlane);&#xA;_material.SetFloat(&quot;u_LightWorldSize&quot;, _lightWorldSize);&#xA;_material.SetFloat(&quot;u_LightFrustrumWidth&quot;, _lightFrustrumWidth);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In my shader, I am simply doing the blocker search part and here is also some pseudo-code.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define BLOCKER_SEARCH_NUM_SAMPLES 16&#xA;#define NEAR_PLANE u_NearPlane&#xA;#define LIGHT_WORLD_SIZE u_LightWorldSize&#xA;#define LIGHT_FRUSTUM_WIDTH u_LightFrustrumWidth&#xA;#define LIGHT_SIZE_UV (LIGHT_WORLD_SIZE / LIGHT_FRUSTUM_WIDTH) &#xA;&#xA;uniform Texture2D               _ShadowTexture;&#xA;uniform SamplerComparisonState  sampler_ShadowTexture;&#xA;uniform Texture2D               u_PointSampler;&#xA;uniform SamplerState            sampleru_PointSampler;&#xA;&#xA;half4 coords = mul(_ShadowMatrix, float4(worldPos.xyz, 1.f));&#xA;float2 uv = coords.xy;&#xA;float zReceiver = coords.z;&#xA;float searchWidth = LIGHT_SIZE_UV * (zReceiver - NEAR_PLANE) / zReceiver;&#xA;float blockerSum = u_PointSampler.Sample(sampleru_PointSampler, float2(0, 0)).a;&#xA;float numBlockers = 0;&#xA;&#xA;for (int i = 0; i &amp;lt; BLOCKER_SEARCH_NUM_SAMPLES; ++i)&#xA;{&#xA;    float shadowMapDepth = _ShadowTexture.Sample(sampleru_PointSampler, uv.xy + poissonDisk[i] * searchWidth).r;&#xA;    if (shadowMapDepth &amp;lt; zReceiver)&#xA;    {&#xA;        blockerSum += shadowMapDepth;&#xA;        numBlockers++;&#xA;    }&#xA;}&#xA;float avgBlockerDepth = blockerSum / numBlockers;&#xA;return avgBlockerDepth;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is an example of my issue. As you can see on the right the shadowing seems correct but if you move the cylinder, you can see on the left, the penumbra is not computed correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uBosM.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uBosM.jpg&quot; alt=&quot;pcss&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I said I don't know what I am doing wrong, I suppose that this comes from the matrix or maybe the depth but there might be some other problems.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Additional information&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I've rebuilt my system and I better understand the whole thing and I also think that I know where the issue comes from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's focus on the near plane value, the shadow map and the zReceiver which is the z projection coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shadow map and the zReceiver are calculated within the light view space as you can see in the following screenshot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8KSCZ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8KSCZ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let's see how the searchWidth is calculated and some screenshots with different NEAR_PLANE values.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float searchWidth = LIGHT_SIZE_UV * (zReceiver - NEAR_PLANE) / zReceiver;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In those examples only the NEAR_PLANE value is changed and the camera near plane remains to 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pC0lH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pC0lH.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see with a NEAR_PLANE value of zero the searchWidth doesn't vary compared to other values. But I think that other values are wrong and don't behave right as I am using a directional light. Indeed, the penumbra should not be affected by the distance from the object to the light. To try fixing this, I only used the zReceiver without taking in account the NEAR_PLANE value and the results are not good.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float searchWidth = LIGHT_SIZE_UV * zReceiver;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can see in the following screenshots, in the red circles as you move the object far according to the shadow map, the width gets bigger and it shouldn't.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HniVt.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HniVt.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct behaviour is that the searchWidth shouldn't be affected by the object position in the shadow map but more by its height. I think that this should makes sense.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like know how could I calculate the searchWidth as it seems that my problem comes from its calculation. Maybe the issue also comes from the shadowmap or the zReceiver but I have some doubts about it.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="231" LastEditDate="2016-12-14T15:21:51.963" LastActivityDate="2016-12-14T15:21:51.963" Title="Percentage-closer Soft Shadows implementation" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;lighting&gt;&lt;shadow&gt;&lt;shadow-mapping&gt;" AnswerCount="0" CommentCount="9" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4378" PostTypeId="1" AcceptedAnswerId="4383" CreationDate="2016-12-13T01:16:36.967" Score="6" ViewCount="1137" Body="&lt;p&gt;I attempted to implement font rendering using signed distance fields.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My program first generates a mono bitmap at font size 64 (using FreeType), then generates an SDF from the bitmap. This is then uploaded into a texture atlas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The results are not very nice and look nothing like the various papers show:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WGKeI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WGKeI.png&quot; alt=&quot;Generated letter capital X&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My guess is that the bitmap does not have a high enough resolution, but&#xA;I do not necessarily want to generate SDF's larger than 64px (they have to fit in the atlas). Besides, at 256px, the generated sdf still has artifacts, albeit less noticable unless blown up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how can I get better results / how am I applying the algorithm wrong?&lt;/p&gt;&#xA;" OwnerUserId="5661" LastActivityDate="2016-12-13T18:10:32.850" Title="Signed distance field font looks odd" Tags="&lt;opengl&gt;&lt;signed-distance-field&gt;&lt;font-rendering&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4379" PostTypeId="1" AcceptedAnswerId="4380" CreationDate="2016-12-13T04:35:14.420" Score="5" ViewCount="630" Body="&lt;p&gt;I would just like to know why are there so many things defined as macros that point to memory addresses in OpenGL? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I see them all over the place. For example when I go to choose parameters for a function such as glDrawArrays(), I have to choose a mode like GL_TRIANGLES as the first parameter which is a macro like all the others. &lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2016-12-13T08:28:47.280" Title="Why is there so many macros in OpenGL?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4380" PostTypeId="2" ParentId="4379" CreationDate="2016-12-13T08:28:47.280" Score="8" Body="&lt;p&gt;These aren't macros pointing to memory addresses. They're just integer preprocessor constants. Back in the days when OpenGL originated, using preprocessor constants for your numeric constants was common practice in C.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nowadays it's considered better practice to define new types (single-element structs) for your constants, but it's too late to change OpenGL.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-12-13T08:28:47.280" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4381" PostTypeId="1" CreationDate="2016-12-13T14:55:05.223" Score="6" ViewCount="385" Body="&lt;p&gt;I have a polygonal mesh with ngons in it. I want to make a tessellation shader to which I send only the regular quads in such a way that it can construct a B-Spline surfaces across it. I came across the useful &lt;a href=&quot;http://prideout.net/blog/?tag=tessellation-shaders&quot; rel=&quot;noreferrer&quot;&gt;tutorial&lt;/a&gt;, but I do not completely understand it, and my problem is slightly more general in that it contains irregular polygons and vertices. In the mesh I am looking for regular quads, i.e., quads for which all vertices have valency 4. They look like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;     |    |&#xA;  ___|____|___&#xA;     |    |&#xA;  ___|____|___&#xA;     |    |&#xA;     |    |&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It is the inner face that I want the tessellation shader to divide up and then smooth using B-spline method. However, for the B-spline method I need  16 points, So I must subdivide the inner face like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; ______         .  .  .  .&#xA;|      |        .  .  .  .&#xA;|      |   --&amp;gt;  .  .  .  .&#xA;|______|        .  .  .  .&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am lost on how to find these points, I can of course just use averaging to get these points but then there will be no smoothing happening. The subdivision rules I normally use are all binary, that is, they split edges into two edges, but this can not produce such a set of control points. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I proceed from here? Should I just resort to using quadratic B-splines, and use the top diagram to find approximations of the half way points and send those to the shader? Another issue is that adjacent faces of regular quads may very well be triangles or pentagons etc. So it is difficult to find the points I need for the tessellation shader to perform B-spline smoothing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for any tips,&#xA;if anyone would like some more clarification about the problem please ask, I realize that the question might be vague.&lt;/p&gt;&#xA;" OwnerUserId="5633" LastActivityDate="2016-12-14T04:28:37.033" Title="B-Spline patches on the tessellation shader. How to get the control points" Tags="&lt;shader&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4382" PostTypeId="2" ParentId="4363" CreationDate="2016-12-13T15:37:01.320" Score="2" Body="&lt;p&gt;Am I right if I understand&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat vertices[] = {&#xA;    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,&#xA;    0.5f, -0.5f, -0.5f, 1.0f, 0.0f,&#xA;    0.5f, 0.5f, -0.5f, 1.0f, 1.0f,&#xA;    0.5f, 0.5f, -0.5f, 1.0f, 1.0f,&#xA;    -0.5f, 0.5f, -0.5f, 0.0f, 1.0f,&#xA;    -0.5f, -0.5f, -0.5f, 0.0f, 0.0f,&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;as being: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;x, y, z, texX, texY&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;for 6 vertices in total?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so, then it seems like you do not use indexing yet (vertices 3 and 4 are the same), but nevermind.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not being sure what order your coordinate system is in, the plane you are constructing here is perpendicular to an axis, but does not go through your origin. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An object that gets rotated by a rotation matrix rotates around its origin. The origin of your model matrix is (0, 0, 0), but this is &lt;strong&gt;not&lt;/strong&gt; the center of your object. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a right handed coordinate system, the following vertices give you a plane that is standing on the x-z-plane (perpendicular to it) and goes through your origin. Rotating that around y should rotate it like you wish to do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; GLfloat vertices[] = {&#xA;     -0.5f, 0.0f, 0.0f, 0.0f, 0.0f,&#xA;     0.5f, 0.0f, 0.0f, 1.0f, 0.0f,&#xA;     0.5f, 1.0f, 0.0f, 1.0f, 1.0f,&#xA;     0.5f, 1.0f, 0.0f, 1.0f, 1.0f,&#xA;     -0.5f, 1.0f, 0.0f, 0.0f, 1.0f,&#xA;     -0.5f, 0.0f, 0.0f, 0.0f, 0.0f,&#xA; };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Notice the third value for each vertex.&lt;/p&gt;&#xA;" OwnerUserId="5055" LastEditorUserId="231" LastEditDate="2016-12-13T17:26:43.167" LastActivityDate="2016-12-13T17:26:43.167" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4383" PostTypeId="2" ParentId="4378" CreationDate="2016-12-13T18:10:32.850" Score="8" Body="&lt;p&gt;Hmm, that SDF doesn't look right. It should be much smoother, like this image for instance:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://farm3.staticflickr.com/2899/14414646376_03162c9141_o.png&quot; alt=&quot;SDF example&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(image from &lt;a href=&quot;https://www.mapbox.com/blog/text-signed-distance-fields/&quot; rel=&quot;noreferrer&quot;&gt;this blog&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One possible issue I noticed in your description:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;My program first generates a mono bitmap at font size 64 (using FreeType), then generates an SDF from the bitmap.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The initial text needs to be rendered at a &lt;em&gt;much higher&lt;/em&gt; resolution than the resulting SDF, so you can get subpixel precision in the distances stored in the SDF. For example, in the &lt;a href=&quot;http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&quot; rel=&quot;noreferrer&quot;&gt;original Valve paper&lt;/a&gt;, they render the initial mono bitmap at 4096×4096 in order to generate a 64×64 SDF from it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-12-13T18:10:32.850" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4384" PostTypeId="2" ParentId="4381" CreationDate="2016-12-13T18:29:07.240" Score="2" Body="&lt;p&gt;For regular quad faces, what you want to do is send the vertices for the quad you're evaluating &lt;em&gt;and&lt;/em&gt; the eight neighboring quads around it: a total of 4x4 vertices. The B-spline needs to know where the neighboring vertices are in order to generate a surface patch that connects smoothly to the neighboring patches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case that the adjacent faces aren't quads, I don't think you can use the straightforward B-spline evaluation. In Catmull-Clark subdivision, everything is quads after the first level of subdivision, though you'll still have extraordinary vertices to deal with.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="1952" LastEditDate="2016-12-14T04:28:37.033" LastActivityDate="2016-12-14T04:28:37.033" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4385" PostTypeId="1" CreationDate="2016-12-13T22:03:06.060" Score="3" ViewCount="245" Body="&lt;p&gt;I have a question regarding Laplacian Smoothing of meshes and in particular the paper &quot;Improved Laplacian smoothing of noisy surface meshes&quot; by J. Vollmer in the early 2000's.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the reason for &lt;em&gt;shrinkage&lt;/em&gt; after Laplacian Smoothing on noisy surface meshes?&lt;/p&gt;&#xA;" OwnerUserId="5670" LastEditorUserId="231" LastEditDate="2016-12-14T21:43:12.663" LastActivityDate="2016-12-22T13:44:08.963" Title="Improved Laplacian smoothing of noisy surface meshes" Tags="&lt;3d&gt;&lt;algorithm&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4388" PostTypeId="1" AcceptedAnswerId="4392" CreationDate="2016-12-14T23:58:54.283" Score="5" ViewCount="451" Body="&lt;p&gt;This problem has been haunting me for some time but I was busy with other things. I can't finish my GI technique (specifically occlusion step) without solving it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I made a binary scene voxelization in a single pass. The result is stored in a &lt;code&gt;RGBA32UI&lt;/code&gt; 3D texture. It is three way so I set three ortho matrices each for X, Y, Z direction. These matrices are centered in camera position and form frustum in cube shape. And in geometry shader choose axis based on triangle normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;First, what works - without binary voxelization&lt;/strong&gt; (but it's a waste of VRAM).&#xA;Here is fragment shader code of voxelization pass:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//gridDim - gridDimensions in voxels&#xA;ivec3 temp = ivec3( gl_FragCoord.xy, gridDim.z * gl_FragCoord.z) ;&#xA;ivec3 texcoord[3];&#xA;&#xA;//correction of texture coord based on chosen axis and ortho matrix &#xA;//(f_axis - 0, 1 or 2 from geometry shader)&#xA;texcoord[0] = temp;&#xA;&#xA;texcoord[1].x = int(gridDim.z) - temp.x;&#xA;texcoord[1].y = temp.z;&#xA;texcoord[1].z = temp.y;&#xA;&#xA;texcoord[2].x = temp.z;&#xA;texcoord[2].y = temp.y;&#xA;texcoord[2].z = int(gridDim.z) - temp.x;&#xA;&#xA;imageStore(geometryGrid, texcoord[f_axis], uvec4(1u));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Drawing pass is done using instancing with cubes. The voxels are quite big because more of them results in a big framerate drop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//vpVoxels is ortho matrix, worldPosCenter - center of each cube from vertex shader&#xA;vec4 geomCoords = vpVoxels * vec4(worldPosCenter, 1.0);&#xA;geomCoords.xyz /= geomCoords.w;&#xA;geomCoords.xyz = geomCoords.xyz * 0.5 + 0.5;&#xA;&#xA;ivec3 index = ivec3(geomCoords.xyz * gridDim);&#xA;&#xA;uvec4 voxel2 = texelFetch(geometryTexture, index, 0);&#xA;if(voxel2.r == 0u)&#xA;    discard;&#xA;&#xA;normalColor = vec4(normal0, 1.0);&#xA;fragColor = vec4(1.0, 0.0, 0.0, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And it works:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bQmhv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bQmhvm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;But if I change it to the binary version:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//input - position 1-128, output: coded binary position as 1 in uvec4 format&#xA;    uvec4 encodeBinaryVoxel(int position)&#xA;    {&#xA;        // check for positioning to R channel&#xA;        position = max(position, 0);&#xA;        uint voxelId1 = (position &amp;gt; 32 || position == 0)? 0u : 1u &amp;lt;&amp;lt; uint(position - 1);&#xA;&#xA;        // check for positioning to G channel&#xA;        position = max(position - 32, 0);&#xA;        uint voxelId2 = (position &amp;gt; 32 || position == 0)? 0u : 1u &amp;lt;&amp;lt; uint(position - 1);&#xA;&#xA;        // check for positioning to B channel&#xA;        position = max(position - 32, 0);&#xA;        uint voxelId3 = (position &amp;gt; 32 || position == 0)? 0u : 1u &amp;lt;&amp;lt; uint(position - 1);&#xA;&#xA;        // check for positioning to A channel&#xA;        position = max(position - 32, 0);&#xA;        uint voxelId4 = (position &amp;gt; 32 || position == 0)? 0u : 1u &amp;lt;&amp;lt; uint(position - 1);&#xA;&#xA;        return uvec4(voxelId1, voxelId2, voxelId3, voxelId4);&#xA;    }&#xA;&#xA;void main()&#xA;{&#xA;    ivec3 temp = ivec3( gl_FragCoord.xy, gridDim.z * gl_FragCoord.z) ;&#xA;    ivec3 texcoord[3];&#xA;&#xA;    texcoord[0] = temp;&#xA;&#xA;    texcoord[1].x = int(gridDim.z) - temp.x;&#xA;    texcoord[1].y = temp.z;&#xA;    texcoord[1].z = temp.y;&#xA;&#xA;    texcoord[2].x = temp.z;&#xA;    texcoord[2].y = temp.y;&#xA;    texcoord[2].z = int(gridDim.z) - temp.x;&#xA;&#xA;    //get z index of texture, each z slice has room for 128 bits (32*4)&#xA;    int indexZ = texcoord[f_axis].z / 128; &#xA;    //get position in slice&#xA;    int bitZ = texcoord[f_axis].z % 128 + 1; &#xA;    ivec3 index = ivec3(texcoord[f_axis].xy, indexZ);&#xA;    uvec4 current = imageLoad(geometryGrid, index);&#xA;    //encode position as binary uvec4&#xA;    uvec4 bit = encodeBinaryVoxel(bitZ); &#xA;    //or operation with stored value&#xA;    imageStore(geometryGrid, index, bit | current); &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And read:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 geomCoords = vpVoxels * vec4(worldPosCenter, 1.0);&#xA;geomCoords.xyz /= geomCoords.w;&#xA;geomCoords.xyz = geomCoords.xyz * 0.5 + 0.5;&#xA;&#xA;ivec3 index = ivec3(geomCoords.xyz * gridDim);&#xA;int indexZ = index.z / 128;&#xA;int bitZ = index.z % 128 + 1;&#xA;uvec4 binZ = encodeBinaryVoxel(bitZ);&#xA;&#xA;uvec4 voxel = texelFetch(geometryTexture, ivec3(index.xy, indexZ), 0);&#xA;uvec4 occupy = binZ &amp;amp; voxel;&#xA;if((occupy.r | occupy.g | occupy.b | occupy.a) == 0u)&#xA;    discard;&#xA;&#xA;normalColor = vec4(normal0, 1.0);&#xA;fragColor = vec4(1.0, 0.0, 0.0, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://web.archive.org/web/20190825194522/http://oi65.tinypic.com/2e6g12b.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://web.archive.org/web/20190825194522/http://oi65.tinypic.com/2e6g12b.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you see in the binary version it flickers and I have failed to find out the logic behind this (yet). However, voxel positions seem to be fine. I can render these voxels also by raymarching through the texture and this flickers too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've made a simplest voxelization using only vertex + fragment and one ortho matrix in X direction (then it is incorrect but whatever), and store value only in first slice (my &lt;code&gt;gridDim&lt;/code&gt; is less than 128 so it fits) and it still flickers:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ivec3 index = ivec3( gl_FragCoord.xy, gridDim.z * gl_FragCoord.z) ;&#xA;&#xA;uvec4 bit = encodeBinaryVoxel(index.z + 1);&#xA;&#xA;uvec4 current = imageLoad(geometryGrid, ivec3(index.xy, 0));&#xA;&#xA;imageStore(geometryGrid, ivec3(index.xy, 0), bit | current);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2019-08-26T15:28:57.160" LastActivityDate="2019-08-26T15:28:57.160" Title="Binary scene voxelization using imageStore - problem" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;glsl&gt;&lt;3dtexture&gt;&lt;voxelization&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="4389" PostTypeId="1" CreationDate="2016-12-15T09:16:53.853" Score="5" ViewCount="76" Body="&lt;p&gt;After calling &lt;code&gt;glVertexAttribPointer&lt;/code&gt; to associate data of the currently bound vertex array with data from the currently bound &lt;code&gt;GL_ARRAY_BUFFER&lt;/code&gt;, I mentioned that I can simply delete the used buffer without it affecting the rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What actually happens with the data within the buffer when calling &lt;code&gt;glVertexAttribPointer&lt;/code&gt;? It seems like the data from the buffer actually get's copied into another memory location that the vertex array uses.&lt;/p&gt;&#xA;" OwnerUserId="2623" LastActivityDate="2016-12-16T16:23:32.423" Title="OpenGL VertexArray Data &quot;Retention&quot;?" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4390" PostTypeId="2" ParentId="4308" CreationDate="2016-12-15T10:48:24.800" Score="4" Body="&lt;p&gt;So far, I've been able to attach to &lt;code&gt;vrcompositor.exe&lt;/code&gt; with RenderDoc and intercept the D3D calls that do the composition. According to Baldur Karlsson (the author of RenderDoc), it's not that hard to hack RenderDoc to use its hooks to run arbitrary code on each &lt;code&gt;Present&lt;/code&gt; call of the chain I'm interested in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've not had a chance to try that out yet, so this isn't a final answer! I'll update this post with any further progress.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2016-12-15T10:48:24.800" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4392" PostTypeId="2" ParentId="4388" CreationDate="2016-12-15T23:07:07.783" Score="5" Body="&lt;p&gt;In the binary version you're doing an &lt;code&gt;imageLoad&lt;/code&gt; and an &lt;code&gt;imageStore&lt;/code&gt; on the same texture to modify it. This is a classic race condition: the GPU executes multiple threads of the shader in parallel, and there's no guarantee for those load-modify-store sequences to happen atomically. The operations from different threads can be interleaved, resulting in wrong data stored.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix it, you should use &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/imageAtomicOr.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;imageAtomicOr&lt;/code&gt;&lt;/a&gt; to combine the bits you want to write with the bits already in the buffer without a race condition. For more information, see &lt;a href=&quot;https://www.opengl.org/wiki/Image_Load_Store#Atomic_operations&quot; rel=&quot;noreferrer&quot;&gt;this OpenGL wiki page&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-12-15T23:07:07.783" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4393" PostTypeId="1" AcceptedAnswerId="4401" CreationDate="2016-12-16T00:09:40.350" Score="14" ViewCount="1069" Body="&lt;p&gt;I'm fiddling with simple procedural 3D modeling to make teeny buildings for 3D printing. An Example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/CrYde.png&quot; alt=&quot;The Building&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To make the models more readable onscreen, I've implemented basic shadow mapping for a single directional light. Since my scene isn't changing, I just render the shadow map once using an axis aligned box of the scene to figure out what the bounds of the shadow map should be. The shadows and bounds look like I've got all the matrices right, but coming in a bit closer looks terrible:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/QdBmM.png&quot; alt=&quot;Closeup of Tower&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the reading I've done, I understand the peter panning and what I might do about it, but the ragged edges, which I believe is a form of projective aliasing, look so bad that I think something is wrong in my basic implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hacked the pixel shader to show the shadow texel boundaries:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/KPygS.png&quot; alt=&quot;Showing Texel Boundaries&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've got bilinear filtering on in the texture (without it, I get serious shadow acne). Sadly, my attempt at PCF failed too - it looks just as ragged:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/V4vqA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the single sample case with bilinear filtering disabled:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Tkef4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this look like &quot;typical&quot; projective aliasing? Could dynamic rendering of the shadow map, using the view frustum clipped to the scene, possibly with cascading, address the issue?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: Adding a closeup of bilinear filtering, post shadow comparison, just to show what I get. Bad shadow acne shows up because of interior edges; I'm modeling with stacked virtual blocks and not doing a proper union operation. From my reading, implementing boolean operations on polyhedra is not trivial, but will also allow me to implement static shadow volumes as well as clean up for some 3D printing software.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/t28ZW.png&quot; alt=&quot;Bilinear Filtering&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-12-20T12:01:53.907" LastActivityDate="2018-11-21T10:47:15.080" Title="Handling Projective Aliasing In Shadow Mapping" Tags="&lt;shadow-mapping&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4394" PostTypeId="1" AcceptedAnswerId="4395" CreationDate="2016-12-16T03:00:25.953" Score="29" ViewCount="5290" Body="&lt;p&gt;-- Sorry for the long post, but I prefer to do that way because &quot;&lt;em&gt;Devil is in the details.&lt;/em&gt;&quot; :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am writing a path tracer from the scratch and it is working nicely for perfectly diffuse (Lambertian) surfaces (&lt;em&gt;i.e.&lt;/em&gt; the furnace test indicates - at least visually - that it is energy conserving, and rendered images match those generated with Mitsuba renderer for the same parameters). Now I am implementing the support for the specular term of the original Cook-Torrance microfacet model, in order to render some metallic surfaces. However, it seems that this BRDF is reflecting more energy than that received. See the example images below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3T0K5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3T0K5.png&quot; alt=&quot;Mitsuba reference image.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Above image: &lt;em&gt;Mitsuba reference (assumed to be correct) image: Path tracing with direct light sampling, importance hemisphere sampling, max path lenght = 5, 32 stratified spp, box filter, surface roughness = 0.2, RGB.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BU0s0.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BU0s0.png&quot; alt=&quot;Rendered image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Above image: &lt;em&gt;Actual rendered image: Brute force naïve path tracing, uniform hemisphere sampling, max path lenght = 5, 4096 stratified spp, box filter, surface roughness = 0.2, RGB. Despite some differences with respect to the rendering settings, it is clear that the rendered image will not converge to the reference shown before.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tend to think that it is not an implementation problem, but an issue regarding the proper use of the Cook-Torrance model within the rendering equation framework. Below I explain how I am evaluating the specular BRDF and I would like to know if I am doing it properly and, if not, why. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before going into the nitty-gritty details, notice that the renderer is quite simple: 1) implements only the brute force naïve path tracing algorithm - no direct light sampling, no bi-directional path tracing, no MLT; 2) all sampling is uniform on the hemisphere above the intersection point - no importance sampling at all, neither for diffuse surfaces; 3) the ray path has a fixed maximum length of 5 - no russian roulette; 4) radiance/reflectance is informed through RGB tuples - no spectral rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Cook Torrance microfacet model&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I will try to construct the path I've followed to implement the specular BRDF evaluation expression. Everything starts with the rendering equation&#xA;$$&#xA;L_o(\textbf{p}, \mathbf{w_o}) = L_e + \int_{\Omega} L_i(\textbf{p}, \mathbf{w_i}) fr(\mathbf{w_o}, \mathbf{w_i}) \cos \theta d\omega&#xA;$$&#xA;where $\textbf{p}$ is the intersection point at the surface, $\mathbf{w_o}$ is the viewing vector, $\mathbf{w_i}$ is the light vector, $L_o$ is the outgoing radiance along $\mathbf{w_o}$, $L_i$ is the radiance incident upon $\textbf{p}$ along $\mathbf{w_i}$ and $\cos \theta = \mathbf{n} \cdot \mathbf{w_i}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above integral (&lt;em&gt;i.e.&lt;/em&gt; the reflection term of the rendering equation) can be approximated with the following Monte Carlo estimator&#xA;$$&#xA;\frac{1}{N} \sum_{k=1}^{N} \frac{ L_i(\textbf{p}, \mathbf{w_k}) fr(\mathbf{w_k}, w_o) \cos \theta }{p(\mathbf{w_k})}&#xA;$$&#xA;where $p$ is the probability density function (PDF) that describes the distribution of the sampling vectors $\mathbf{w_k}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For actual rendering, the BRDF and PDF must be specified. In the case of the specular term of the Cook-Torrance model, I am using the following BRDF&#xA;$$&#xA;fr(\mathbf{w_i}, \mathbf{w_o}) = \frac{DFG}{\pi (\mathbf{n} \cdot \mathbf{w_i})(\mathbf{n} \cdot \mathbf{w_o})}&#xA;$$&#xA;where &#xA;$$&#xA;D = \frac{1}{m^2 (\mathbf{n} \cdot \mathbf{h})^4} \exp \left( {\frac{(\mathbf{n} \cdot \mathbf{h})^2 - 1}{m^2 (\mathbf{n} \cdot \mathbf{h})^2}} \right)&#xA;$$&#xA;$$&#xA;F = c_{spec} + (1 - c_{spec}) (1 - \mathbf{w_i} \cdot \mathbf{h})^5&#xA;$$&#xA;$$&#xA;G = \min \left( 1, \frac{2(\mathbf{n} \cdot \mathbf{h})(\mathbf{n} \cdot \mathbf{w_o})}{\mathbf{w_o} \cdot \mathbf{h}}, \frac{2(\mathbf{n} \cdot \mathbf{h})(\mathbf{n} \cdot \mathbf{w_i})}{\mathbf{w_o} \cdot \mathbf{h}} \right)&#xA;$$&#xA;In the above equations, $\mathbf{h} = \frac{\mathbf{w_o} + \mathbf{w_i}}{|\mathbf{w_o} + \mathbf{w_i}|}$ and $c_{spec}$ is the specular color. All equations, with the exception of $F$, were extracted from the original paper. $F$, also known as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick&amp;#39;s_approximation&quot; rel=&quot;noreferrer&quot;&gt;Schlick's approximation&lt;/a&gt;, is an efficient and less accurate approximation to the actual Fresnel term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would be mandatory to use importance sampling in the case of rendering smooth specular surfaces. However, I am modeling only reasonably rough surfaces ($m \approx 0.2$), thus, I've decided to keep with uniform sampling for a while (at the cost of longer rendering times). In this case, the PDF is&#xA;$$&#xA;p(\mathbf{w_k}) = \frac{1}{2 \pi}&#xA;$$&#xA;By substituting the uniform PDF and Cook-Torrance BRDF into the Monte Carlo estimator (notice that $\mathbf{w_i}$ is substituted by $\mathbf{w_k}$, the random variable), I get&#xA;$$&#xA;\frac{1}{N} \sum_{k=1}^{N} \frac{ L_i(\textbf{p}, \mathbf{w_k})\left( \frac{DFG}{\pi (\mathbf{n} \cdot \mathbf{w_k})(\mathbf{n} \cdot \mathbf{w_o})} \right) \cos \theta }{\left( \frac{1}{2\pi} \right)}&#xA;$$&#xA;Now we can cancel the $\pi$'s and remove the summation because we shoot only one random ray from the intersection point. We end up with&#xA;$$&#xA;2 L_i(\textbf{p}, \mathbf{w_k})\left( \frac{DFG}{(\mathbf{n} \cdot \mathbf{w_k})(\mathbf{n} \cdot \mathbf{w_o})} \right) \cos \theta&#xA;$$&#xA;Since $\cos \theta = \mathbf{n} \cdot \mathbf{w_k}$, we can further simplify it&#xA;$$&#xA;2 L_i(\textbf{p}, \mathbf{w_k})\left( \frac{DFG}{\mathbf{n} \cdot \mathbf{w_o}} \right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, that's the expression I am evaluating when a ray hits an specular surface whose reflectance is described by the Cook-Torrance BRDF. That is the expression that seems to be reflecting more energy than that received.&#xA;I am almost sure that there is something wrong with it (or in the derivation process), but I just can't spot it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Interestingly enough, if I multiply the above expression by $\frac{1}{\pi}$, I get results that look correct. However, I've refused to do that because I can't mathematicaly justify it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is very welcome! Thank you!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As @wolle pointed out below, &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;noreferrer&quot;&gt;this paper&lt;/a&gt; presents a new formulation better suited for path tracing, where the normal distribution function (NDF) $D$ includes the $\frac{1}{\pi}$ factor and the BRDF $fr$ includes the $\frac{1}{4}$ factor. Thus&#xA;$$&#xA;D_{new} = \frac{1}{\pi m^2 (\mathbf{n} \cdot \mathbf{h})^4} \exp \left( {\frac{(\mathbf{n} \cdot \mathbf{h})^2 - 1}{m^2 (\mathbf{n} \cdot \mathbf{h})^2}} \right)&#xA;$$&#xA;and&#xA;$$&#xA;fr_{new}(\mathbf{w_i}, \mathbf{w_o}) = \frac{DFG}{4 (\mathbf{n} \cdot \mathbf{w_i})(\mathbf{n} \cdot \mathbf{w_o})}&#xA;$$&#xA;Afer the inclusion of the above equations into the rendering equation, I ended up with&#xA;$$&#xA;\frac{\pi}{2} L_i(\textbf{p}, \mathbf{w_k})\left( \frac{D_{new}FG}{\mathbf{n} \cdot \mathbf{w_o}} \right)&#xA;$$&#xA;which worked nicely!&#xA;PS: The issue now is to better understand how the new formulation for $D$ and $fr$ help in maintaining the energy conservation... but this is another topic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE 2&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As pointed out by &lt;a href=&quot;https://computergraphics.stackexchange.com/q/4771/5681&quot;&gt;PeteUK&lt;/a&gt;, the authorship of the Fresnel formulation presented in the original text of my question was wrongly attributed to Cook and Torrance. The Fresnel formulation used above is actually known as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick&amp;#39;s_approximation&quot; rel=&quot;noreferrer&quot;&gt;Schlick's approximation&lt;/a&gt; and is named after Christophe Schlick. The original text of the question was modified accordingly.&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-03-21T15:05:52.740" Title="Path tracing the Cook-Torrance BRDF" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;pathtracing&gt;&lt;specular&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="17" ContentLicense="CC BY-SA 3.0" />
  <row Id="4395" PostTypeId="2" ParentId="4394" CreationDate="2016-12-16T10:44:48.997" Score="12" Body="&lt;p&gt;According to &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;noreferrer&quot;&gt;this paper&lt;/a&gt;, the $\frac{1}{\pi}$ in your $f_r$ should be $\frac{1}{4}$:&#xA;$$&#xA;f_r = \frac{DFG}{4(n\cdot w_i)(n \cdot w_o)},&#xA;$$&#xA;so you would end up with&#xA;$$&#xA;\frac{\pi}{2}L_i(p,w_k)\left(\frac{DFG}{n\cdot w_o}\right).&#xA;$$&lt;/p&gt;&#xA;" OwnerUserId="5632" LastActivityDate="2016-12-16T10:44:48.997" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4396" PostTypeId="1" AcceptedAnswerId="4400" CreationDate="2016-12-16T14:33:27.163" Score="6" ViewCount="1582" Body="&lt;p&gt;I am mainly using Unity but I think that it's not related to this engine, and I am wondering what's the difference between using &lt;a href=&quot;http://http.developer.nvidia.com/Cg/tex2D.html&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;tex2D&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/bb509695(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;Sample&lt;/code&gt;&lt;/a&gt; for sampling a texture.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2016-12-16T16:19:13.510" LastActivityDate="2016-12-16T18:34:32.290" Title="What's the difference between Sample and tex2D" Tags="&lt;shader&gt;&lt;texture&gt;&lt;directx11&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4397" PostTypeId="2" ParentId="2013" CreationDate="2016-12-16T16:20:27.710" Score="3" Body="&lt;p&gt;You must fully create a renderbuffer &lt;em&gt;before&lt;/em&gt; you can attach it to an FBO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://www.opengl.org/wiki/OpenGL_Object#Object_Creation_and_Destruction&quot; rel=&quot;nofollow noreferrer&quot;&gt;pre-DSA OpenGL Object creation functions&lt;/a&gt; do not create objects; they create object &lt;em&gt;names&lt;/em&gt;. It's like creating an uninitialized pointer variable; it doesn't point to anything yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The actual creation of the object happens the first time the name is bound to the context. At that moment, the name is given a real object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Under normal circumstances, it was pretty much impossible to use an object &lt;em&gt;without&lt;/em&gt; binding it to the context, so this distinction couldn't be noticed. However, once the ability to attach objects to one another came to be, this distinction became noticeable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pre-DSA, the only way to fully create a renderbuffer object was to bind it to the context.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, with &lt;a href=&quot;https://www.opengl.org/wiki/Direct_State_Access&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_DSA/GL 4.5&lt;/a&gt;, the &lt;code&gt;glCreate*&lt;/code&gt; functions actually &lt;em&gt;create objects&lt;/em&gt; (imagine that!). So if you use &lt;code&gt;glCreateRenderbuffers&lt;/code&gt;, you can attach the renderbuffer to an FBO without binding it first.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-12-16T16:20:27.710" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4398" PostTypeId="2" ParentId="4389" CreationDate="2016-12-16T16:23:32.423" Score="5" Body="&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/wiki/OpenGL_Object#Object_Creation_and_Destruction&quot; rel=&quot;nofollow noreferrer&quot;&gt;Deleting an OpenGL object&lt;/a&gt; is merely a suggestion. Deleting an object will unbind the object from any binding point it is currently bound to. However, buffer objects are not &quot;bound&quot; to VAOs. They are &lt;em&gt;attached&lt;/em&gt; to VAOs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you call &lt;code&gt;glVertexAttrib*Pointer&lt;/code&gt;, you attach a buffer object to the VAO. The buffer object to be attached is the one bound to &lt;code&gt;GL_ARRAY_BUFFER&lt;/code&gt;. Unbinding that buffer, or even flat-out deleting it, will &lt;em&gt;not&lt;/em&gt; undo the attachment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And an OpenGL object &lt;a href=&quot;https://www.opengl.org/wiki/OpenGL_Object#Deletion_orphaning&quot; rel=&quot;nofollow noreferrer&quot;&gt;will continue to exist so long as it is &lt;em&gt;attached&lt;/em&gt; to a container object&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-12-16T16:23:32.423" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4399" PostTypeId="2" ParentId="4393" CreationDate="2016-12-16T17:26:17.327" Score="1" Body="&lt;p&gt;You've said that &quot;... bilinear filtering on in the texture ...&quot;. It seems that you are interpolating the depth values of the shadow map. The correct way of using interpolation with the shadow map is to apply it over the outcomes of the shadow tests (as far as I remember, OpenGL supports that). You might even combine the interpolation of the outcomes of the shadow tests with PCF, which will deliver much better results. However, as you might have noticed, aliasing is a plague that always pursue the shadow mapping :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although I understand that you are looking for solutions regarding shadow mapping (even because it is quite simple to implement), have you ever considered the use of shadow volumes? It is much more intricate to implement, but does not suffer from aliasing at all, and I think would fit nicely your purposes.&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorDisplayName="user5681" LastEditDate="2016-12-16T17:44:27.493" LastActivityDate="2016-12-16T17:44:27.493" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4400" PostTypeId="2" ParentId="4396" CreationDate="2016-12-16T18:34:32.290" Score="6" Body="&lt;p&gt;They represent the same operation, but &lt;code&gt;Sample&lt;/code&gt; is what it's called in D3D10 and newer versions of HLSL, while &lt;code&gt;tex2D&lt;/code&gt; is what it's called in D3D9 HLSL, and NVIDIA's (defunct) Cg language. By the way, the operation is also called &lt;a href=&quot;http://docs.gl/sl4/texture&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;texture&lt;/code&gt;&lt;/a&gt; in GLSL.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2016-12-16T18:34:32.290" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4401" PostTypeId="2" ParentId="4393" CreationDate="2016-12-16T18:50:35.457" Score="9" Body="&lt;p&gt;Shadow mapping with acceptable quality is quite a journey. So you implemented first step - basic shadow map that encompass whole scene statically. This means that shadow map texel size in light view space to texel size of rendered scene in camera view space ratio is quite big, resulting in aliasing. To reduce this ratio closer to 1:1 there are techniques you mentioned like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the easiest way is increasing size of your shadow map, to find the value with still optimal performance,&lt;/li&gt;&#xA;&lt;li&gt;align shadow map with camera view frustum. Then shadow map encompass smaller part of the scene, so it reduces aliasing,&lt;/li&gt;&#xA;&lt;li&gt;this can be improved to CSM, which does the same but you need to render scene for each of cascade with different center position of light view matrix based on center point of each slice of frustum.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Some of the basic techniques of smoothing the edge of shadow:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;obviously PCF, but is it recommended to combine your PCF implementiation with built in hardware PCF (in Opengl - using &lt;code&gt;sampler2DShadow&lt;/code&gt;). This would result in less loop iterations from your side and cheaper PCF,&lt;/li&gt;&#xA;&lt;li&gt;blockiness of edges can be exchanged for noise using rotated Poisson Disk. Samples used to sample from shadow map are rotated randomly with each iteration of PCF loop.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can also research the edge smoothing techniques like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;rendering shadow map to MSAA applied framebuffer,&lt;/li&gt;&#xA;&lt;li&gt;further enhancing PCF by &lt;a href=&quot;http://codeflow.org/entries/2013/feb/15/soft-shadow-mapping/#pcf-and-interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;interpolation&lt;/a&gt;,&lt;/li&gt;&#xA;&lt;li&gt;increasing number of samples with &lt;a href=&quot;https://pdfs.semanticscholar.org/3d73/8241631af1aece833e0944faff308be8ccb8.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;temporal blend&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;PCF basic technique suffers from shadow acne which can be fixed by applying some offset in shadow test. Calculating the size of this offset is also area of &lt;a href=&quot;http://jcgt.org/published/0003/04/08/&quot; rel=&quot;nofollow noreferrer&quot;&gt;research&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other more advanced shadow map methods include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://jankautz.com/publications/esm_gi08.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Exponential Shadow Maps&lt;/a&gt; and &lt;a href=&quot;http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/VarianceShadowMapping/Doc/VarianceShadowMapping.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Variance Shadow Maps&lt;/a&gt; - in most cases do not suffer from shadow acne and offer smooth edges without blockiness, but in cost of some light leaking situations,&lt;/li&gt;&#xA;&lt;li&gt;Exponential Variance Shadow Maps - probably most advanced technique of 2D depth map shadow mapping, combines great smoothness of VSM and resolves light leaks, in a cost of memory usage doubling,&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://developer.download.nvidia.com/shaderlibrary/docs/shadow_PCSS.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Percentage Closer Soft Shadows&lt;/a&gt; - basic technique of enhancing traditional shadow maps with varying penumbra size,&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/MultiViewSoftShadows.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Multiview Shadow Maps&lt;/a&gt; - multiple shadow maps of some technique, arranged on area light, for computing realistic soft shadows with varying penumbra size,&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://graphics.stanford.edu/papers/deepshadows/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Deep Shadow Maps&lt;/a&gt; - for enhancing volumetric scattering with shadows,&lt;/li&gt;&#xA;&lt;li&gt;Real time ray traced shadows - probably the future.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You didn't fail with PCF, it looks like that:)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wish there was a way to apply gaussian blur on shadow map in camera view space, but it doesn't work as expected.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2018-11-21T10:47:15.080" LastActivityDate="2018-11-21T10:47:15.080" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="4407" PostTypeId="1" CreationDate="2016-12-21T21:37:50.127" Score="5" ViewCount="1486" Body="&lt;p&gt;This might be an odd question, but I was wondering if you could improve GPU performance with games, comparatively, when using doubles/halves of the native resolution, instead of an odd ratio of that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lets compare the situation with a metaphor first. If I'd give you a standard A4 sheet of paper, I bet you can more easily fold it in half than 1/3rd. Same goes when I'd give you two sheets of A4 and ask you to create a A3-size rectangle, instead of a not-A3-but-larger-than-A4-shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To go back to the actual situation: My Macbook has a native resolution of 2880x1800. But the game offers a variety of resolutions, such as 1440x900, 1680x1050, 2048x1280, 2560x1600 and for some reason also 3360x2100, which is above the native resolution..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we'd include the sheet of paper thought in resolution scaling with games, compared to the native resolution, I'd say 1440x900 could run even better than 1280x800, because the GPU could simply say: reduce all pixels by 50%. Not only is that an easier calculation, but it's also much easier to interpolate, &lt;em&gt;if that's the correct word for it&lt;/em&gt; to calculate how the pixel should look like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sudden thought: This does assume the game environment is rendered at the native resolution and thereafter downscaled to the set resolution, which is probably wrong. That said, I do think it'd be easier to render at half the resolution than something like 40%.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This idea &lt;strong&gt;does&lt;/strong&gt; apply to Photoshop with increasing and decreasing the resolution: Always increase with halves and doubles. So why not games?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I'm not only very interested in the actual answer, but perhaps makes it easier to set a resolution for a battery vs performance question :)&lt;/p&gt;&#xA;" OwnerUserId="5708" LastActivityDate="2016-12-27T16:30:53.710" Title="Do GPU performance improve when rendering at native or half resolution, compared to fixed scaling?" Tags="&lt;rendering&gt;&lt;gpu&gt;&lt;pixel-graphics&gt;&lt;subpixel-rendering&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4408" PostTypeId="2" ParentId="4407" CreationDate="2016-12-21T23:49:17.320" Score="5" Body="&lt;p&gt;GPUs can efficiently scale an image by an arbitrary amount (within limits - display options fall within those limits by design) either using a 3D rendering operation or as the signal is sent from GPU to the display. Both of these paths have fully dedicated hardware for the arbitrary resizing and are not likely to be optimized for doubling or halving. Both support a technique called &quot;bilinear filtering&quot; though advances in display hardware may provide higher quality.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If a game is run at non native resolution on a laptop (TVs and desktop displays have their own scalers, but laptop displays generally rely on the GPU), one of these two methods will be used. Display scaling is essentially &quot;free&quot;, so it is preferred and the lower the resolution the game is originally rendered the faster the frame rate (or the lower power consumption) - with no special performance benefit for, say, doubling. If a 3D operation is required (say, due to a limitation or issue in the display scaler), the scale operation is not free, but is going to go up with the source and destination sizes smoothly, with no special casing at doubling/halving.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The game may look far better at certain scaling factors, but that's up to the user to decide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: The intuition behind the question is correct: if GPUs didn't have dedicated scaling hardware, doubling/halving could implemented more efficiently than arbitrary scaling, either in shader code or via a slightly simpler hardware design - though the 3D rendering operation is a requirement of graphics APIs and display scaling is a requirement from systems vendors.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2016-12-27T16:30:53.710" LastActivityDate="2016-12-27T16:30:53.710" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4409" PostTypeId="1" CreationDate="2016-12-22T00:15:05.157" Score="3" ViewCount="144" Body="&lt;p&gt;I have been following a tutorial, shadow mapping works more or less as expected except sometimes the shadow projects completely weirdly on nearby walls. This isn't sampling outside the lightmap because I use CLAMP_TO_EDGE and if(min(ShadowCoord.x, ShadowCoord.y) &gt; 0.0 &amp;amp;&amp;amp; max(ShadowCoord.x, ShadowCoord.y) &amp;lt; 1.0) in the fragment shader. Does anyone know what the official term for this problem is so I can go research it some more? Thanks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/ZbqDfVe.png&quot; alt=&quot;Shadowmapping error&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="5709" LastActivityDate="2016-12-22T06:11:47.190" Title="What is this shadow mapping error called?" Tags="&lt;shadow&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4410" PostTypeId="2" ParentId="4409" CreationDate="2016-12-22T06:11:47.190" Score="1" Body="&lt;p&gt;It's not entirely clear what the scene in your picture is supposed to look like, so I'm not sure I'm interpreting it correctly. But if I am, it seems like the problem is that you're projecting the shadow properly, but onto the wrong face of the gray wall. If you want to research it, you might have luck looking up &lt;a href=&quot;https://en.wikipedia.org/wiki/Winding_number&quot; rel=&quot;nofollow noreferrer&quot;&gt;winding order&lt;/a&gt; (sometimes called winding number), or &lt;a href=&quot;https://en.wikipedia.org/wiki/Back-face_culling&quot; rel=&quot;nofollow noreferrer&quot;&gt;back-face culling&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I'm correct in what's shown above, I think you could solve it in your shader by only applying the shadows to the current fragment if the vector from the light source to the surface points away from the surface normal. In other words, take the dot product of those 2 vectors, and if it's negative apply shadows, otherwise, don't.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-12-22T06:11:47.190" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4411" PostTypeId="2" ParentId="4385" CreationDate="2016-12-22T12:20:10.197" Score="5" Body="&lt;p&gt;This is a quite common property of smoothing in 3D. When you have some data and you smooth it out you get some kind of average of the local variation. And this works fine, and stably, in one dimensional graphs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But when your entire data set is being smoothed over its coordinates the neighboring coordinates drag your data with them. Those again are dragged by their neighbors. The net effect is that the local variation of the surface as a whole is dragging itself towards an average that is stable in the smoothing operation itself. This will cause shrinkage because a closed object as a whole has a local average that is towards the common center of all the points in operation. Even in cases where you go locally outwards you are eventually caught up with the edges that drag you inwards. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words there is no structure to keep the surface locked to its place. The tendency to drag towards the center eventually wins because there is nothing to counteract this. There just simply are more opportunities to go inward than outward.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-12-22T13:44:08.963" LastActivityDate="2016-12-22T13:44:08.963" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4412" PostTypeId="1" AcceptedAnswerId="4414" CreationDate="2016-12-25T11:37:25.197" Score="4" ViewCount="1239" Body="&lt;p&gt;I have a few doubts and questions regarding &lt;strong&gt;volume rendering&lt;/strong&gt;, I was hoping someone here could help me understand.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I commonly hear the terms &lt;strong&gt;'Ray-Marching'&lt;/strong&gt; &amp;amp; &lt;strong&gt;'Volume Rendering'&lt;/strong&gt; being used together when it comes to &lt;strong&gt;rendering fog or any other volumetric object.&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is Ray Marching the method used to render these volumes such as Fog, Smoke &amp;amp; Fire&lt;/strong&gt; &lt;em&gt;(this is regarding path tracing)&lt;/em&gt;? Since we can use signed distance fields to &lt;strong&gt;easily manipulate the shape of the volume?&lt;/strong&gt; At the &lt;strong&gt;approximated intersection point is a BSDF evaluated&lt;/strong&gt; (BRDF + BTDF) or is it &lt;strong&gt;just a BRDF?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;At the approximated intersection point for the volume &lt;strong&gt;what BRDF/BSDF do we use (if we do use one, I might have a wrong understanding of the topic)? Are there measured BRDFs &amp;amp; BTDFs that is the common standard?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;hr&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2016-12-25T20:09:34.663" Title="Volume Rendering (Path Tracing &amp; Real-Time)" Tags="&lt;brdf&gt;&lt;pathtracing&gt;&lt;volumetric&gt;&lt;raymarching&gt;&lt;volumetric-scattering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4413" PostTypeId="1" AcceptedAnswerId="4415" CreationDate="2016-12-25T17:37:20.547" Score="4" ViewCount="334" Body="&lt;p&gt;I want to draw a string of text with a single draw call (Instancing). I am reading a bitmap for each character texture. I want to pass the texture coordinates for each vertex of a quad (a single character). Now these texture coordinates are supposed to be updated for each vertex processed by the vertex shader because I set the &lt;code&gt;glVertexAttribDivisor()&lt;/code&gt; to 0 which means it should be. But it's not happening.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the source code where I am sending the data to the GPU...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//TEXTURE COORDS&#xA;glBindBuffer(GL_ARRAY_BUFFER, mVBOTexCoords);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2)*mTexCoords.size(), mTexCoords.data(), GL_STATIC_DRAW);&#xA;&#xA;glEnableVertexAttribArray(3);&#xA;glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 0, 0);&#xA;&#xA;glVertexAttribDivisor(3,0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and the vertex shader...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400 &#xA;&#xA;out vec2 tex_coords;&#xA;&#xA;layout(location = 0) in vec2 pos;&#xA;layout(location = 1) in vec2 offset;&#xA;layout(location = 2) in vec2 scale;&#xA;layout(location = 3) in vec2 tex;&#xA;&#xA;uniform mat4 projection;&#xA;&#xA;void main()&#xA;{&#xA;    tex_coords = tex;&#xA;&#xA; vec4 position = vec4(pos,0.0f,1.0f);&#xA;     position.xy*=scale;&#xA;     position.xy+=offset;&#xA;&#xA;     gl_Position = projection*position;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Sorry for the mess. I hope you get it. I am not getting why its not updating the texture coordninates for each vertex.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="6" LastEditDate="2016-12-28T18:17:37.793" LastActivityDate="2016-12-28T18:17:37.793" Title="Texture coordinates are not updating according to the vertex divisor specified" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4414" PostTypeId="2" ParentId="4412" CreationDate="2016-12-25T20:09:34.663" Score="4" Body="&lt;p&gt;Ray marching is a ray tracing method where you take multiple steps along a ray to find intersection with geometry or to perform integration of in-scattered light from participating media (fog, clouds, water, etc.) along the ray. Signed distance fields doesn't really help you with participating media rendering since it's a method of finding the ray intersection instead of helping with volume integration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when you perform ray marching along the ray for volume integration, for each step you need to calculate incoming light to that point and evaluate the &quot;phase function&quot; to calculate how much of that light scatters towards the eye. This phase function can be simple isotropic function (i.e. constant $\frac{\rho}{4\pi}$) or more complex anisotropic function such as Mie phase function shown below, depending on the modeled participating media.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WR0ZN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WR0ZN.png&quot; alt=&quot;Mie Phase Function&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally you need to take the extinction coefficient of the media into account, which is spatially varying for heterogeneous media, for calculating transmittance and to properly &quot;attenuate&quot; the in-scattered light as it's being blocked by media between eye and the point (&lt;a href=&quot;https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law&quot; rel=&quot;nofollow noreferrer&quot;&gt;Beer-Lambert law&lt;/a&gt;). This approach assumes homogeneous media between steps and for proper physically based integration you could take a look at SIGGRAPH 2015 presentation &quot;&lt;a href=&quot;http://www.frostbite.com/2015/08/physically-based-unified-volumetric-rendering-in-frostbite/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically-based &amp;amp; Unified Volumetric Rendering in Frostbite&lt;/a&gt;&quot; by Sebastien Hillaire.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To know how much light reaches a point in space for each of those ray steps, you can use path tracing. This can get quite expensive though since light can take random paths in the media until it reaches the point. This is known as &quot;multiple scattering&quot;, which is analogous to indirect illumination. When performing the integration over the sphere for each step along the ray, you can use &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Woodcock tracking&lt;/a&gt; to get unbiased results for heterogeneous media. Also if you use Mie phase function you should use importance sampling as the phase function has very strong forward peak.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2016-12-25T20:09:34.663" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4415" PostTypeId="2" ParentId="4413" CreationDate="2016-12-25T20:37:04.397" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Now this texture coordinates supposed to be updated for each vertex processed by vertex shader because i set the glVertexAttribDivisor() to 0 which means it should be.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, it doesn't.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A divisor of 0 means that the texture coordinate work &lt;em&gt;exactly&lt;/em&gt; as if you hadn't called &lt;code&gt;glVertexAttribDivisor&lt;/code&gt; for that attribute at all. 0 is not a special case; it's the &lt;em&gt;default&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That means that the texture coordinate will be updated at the same rate as the position. So it will get the same value &lt;em&gt;for each instance&lt;/em&gt;, exactly like it does for the positions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is no way to use instancing to get an attribute to always increase. It either is a per-instance attribute (changing more-or-less based on &lt;code&gt;gl_InstanceID&lt;/code&gt;) or it is a per-vertex attribute (changing based on &lt;code&gt;gl_VertexID&lt;/code&gt;). To get the per-instance behavior, you use a divisor 1 or greater. To get the per-vertex behavior, you use a divisor of 0.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2016-12-25T20:37:04.397" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4417" PostTypeId="1" CreationDate="2016-12-26T03:43:09.017" Score="3" ViewCount="314" Body="&lt;p&gt;Is there any tool available for debugging GLSL shaders? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have nvidia geForce 940m GPU which doesn't support Nvidia NSight and RenderDoc is great but it doesn't support GLSL shader debugging. I am using windows 10.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="2096" LastEditDate="2016-12-26T07:52:07.330" LastActivityDate="2016-12-26T07:52:07.330" Title="GLSL shader debugging" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;debugging&gt;" AnswerCount="0" CommentCount="5" ClosedDate="2016-12-26T11:36:55.020" ContentLicense="CC BY-SA 3.0" />
  <row Id="4418" PostTypeId="1" CreationDate="2016-12-26T17:42:10.087" Score="5" ViewCount="1280" Body="&lt;p&gt;Right now, all current monitors use three (or &lt;a href=&quot;https://en.wikipedia.org/wiki/Quattron&quot; rel=&quot;nofollow noreferrer&quot;&gt;four&lt;/a&gt;) primary colors to create their color, which could never allow them to produce all colors that can be seen by the human eye; &lt;a href=&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/1/1e/CIE1931xy_gamut_comparison.svg/512px-CIE1931xy_gamut_comparison.svg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;in fact, their colors will always be inside a triangle on the xyY diagram of all possible colors&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But we could decide to replace these color filters with something such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Lyot_filter&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lyot filters&lt;/a&gt;, which can be tuned, similarly to LCDs, to allow only light whose wavelength is higher/lower than a certain value to pass through. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This would mean that we could basically create color filters that can be adjusted to produce any color, by replacing each pixel with two stacked filters, which allow a range $[a, b]$ to pass, and a third filter next to it which allows the range $[c,\infty)$ to pass through.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using Mathematica, I &lt;a href=&quot;http://pastebin.com/eQkpqHZV&quot; rel=&quot;nofollow noreferrer&quot;&gt;have tested&lt;/a&gt; that a mapping between these three values is enough to create any possible $x$, $y$ and $Y$ in the CIE xyY color space:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/66aT9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/66aT9.png&quot; alt=&quot;Plot of mapping&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, in other words, the range of &#xA;$$\text{XYZ}(a,b,c)=\int_{[a,b]\cup[c,\infty)}\text{I}(\lambda)\cdot(\overline{x}(\lambda),\overline{y}(\lambda),\overline{z}(\lambda))$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;, where $\text{I}$ is the illuminant, is enough to produce the color of any object that can be illuminated by that illuminant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, my questions are: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Are there already any such displays that can produce any visible color, and if not, then why not?&lt;/li&gt;&#xA;&lt;li&gt;Could this actually be done in practice?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5724" LastEditorUserId="5724" LastEditDate="2016-12-26T18:03:56.657" LastActivityDate="2016-12-28T00:26:17.833" Title="Display that supports full CIE xyY color space" Tags="&lt;color-science&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4420" PostTypeId="2" ParentId="4418" CreationDate="2016-12-27T07:02:41.813" Score="1" Body="&lt;p&gt;No, most likely these kinds of displays do not exist, at the time of writing this post. Although the negative is hard to prove. And in this case i don't have deep enough understanding of the lore.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Reason for me saying this is that usable displays need some serious miniaturization. The miniaturization process is quite expensive and requires some serious investment. There should be quite massive patent trail if this was indeed true. So we should look in patent databases for this trail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, having such tech probably will not yield full color space, at least initially. Because the filter can only filter out colors that the back light can generate. Most probably therefore this is some kind of projector technology at first. Also filters probably have a practical limit to how much they can be tuned.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Third, if/when such tech is available it must recuperate the development cost by selling enough units to overcome the capital investment. There is a likelihood that this is one of those things that can not be produced without the miniaturization step like digital cameras. So keep a lookout for a killer application for this tech.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some major downsides of this kind of tech is the fact that you filter out light. This means it eats up part of the energy input. This leads to a heat dissipation problem, which for perfect narrow band filters is actually pretty huge part of the emitted light. Lot of energy goes wasted, and needs to be engineered around.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2016-12-27T16:30:16.040" LastActivityDate="2016-12-27T16:30:16.040" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4422" PostTypeId="1" AcceptedAnswerId="4432" CreationDate="2016-12-27T08:51:10.870" Score="33" ViewCount="14041" Body="&lt;p&gt;Often a similar hardware feature is exposed via DirectX and OpenGL using different terminology. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example:&lt;br&gt;&#xA;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ff476898(v=vs.85).aspx#Shader_Constant_Buffer&quot; rel=&quot;noreferrer&quot;&gt;Constant Buffer&lt;/a&gt; / &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object&quot; rel=&quot;noreferrer&quot;&gt;Uniform Buffer Object&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ff471472(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;RWBuffer&lt;/a&gt; / &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object&quot; rel=&quot;noreferrer&quot;&gt;SSBO&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am looking for an exhaustive chart that describes which DirectX terminology is used to refer to which OpenGL concept, and vice-versa.&lt;br&gt;&#xA;Where can I find such a resource?  &lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="110" LastEditDate="2016-12-28T06:08:53.740" LastActivityDate="2019-03-16T20:09:59.560" Title="DirectX / OpenGL(Vulkan) concepts mapping chart" Tags="&lt;api&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="43" ContentLicense="CC BY-SA 3.0" />
  <row Id="4423" PostTypeId="2" ParentId="4418" CreationDate="2016-12-27T16:08:51.790" Score="0" Body="&lt;p&gt;The answer should be a theoretical no for any tri-light system, or even four light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason is, if you examine the original CIE RGB primaries, you will see that the positions of the three CIE 1931 lights correspond to the tips of the triangle in the spectral locus image here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0aRqO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0aRqO.png&quot; alt=&quot;CIE versus Imaginary Colours&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look closely, you will see that along the edges of the green red axis, and the red blue, that there is some &quot;escape&quot; of the values where the primaries mixed cannot replicate the range of visible lights that the experimental observers were attempting to replicate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What we learn from this is that any combination of tristimulus physical lamps &lt;em&gt;can never&lt;/em&gt; encompass the entire spectral locus shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to fully enclose the unique shape of the spectral locus, it would require using primaries that consist of imaginary visual lamps that would form a triangle well beyond the spectral locus tips. Examples include the imaginary XYZ lamps, or the ACES lamps. Those lamps of course do not exist in the physical sense.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So with all of that said, is it plausible that such a display could exist in the future? Absolutely. If we switch to a 40 lamp display, or something close to that, we could replicate the various wavelengths that enclose the entire shape of the spectral locus and fully encapsulate the CIE standard observer response.&lt;/p&gt;&#xA;" OwnerUserId="5556" LastEditorUserId="5556" LastEditDate="2016-12-27T19:08:28.790" LastActivityDate="2016-12-27T19:08:28.790" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4424" PostTypeId="2" ParentId="4060" CreationDate="2016-12-27T16:29:44.280" Score="2" Body="&lt;p&gt;There has been quite some research into this using Barten contrast sensitivity function. It is the current formula behind the Dolby Perceptual Quantizer as featured in SMPTE 2084 and HDR10.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This, coupled with a colour appearance model such as the work behind Dr. Mark Fairchild's CIECAM02, can result in very accurate predictions of quantization depth.&lt;/p&gt;&#xA;" OwnerUserId="5556" LastActivityDate="2016-12-27T16:29:44.280" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4425" PostTypeId="2" ParentId="4358" CreationDate="2016-12-27T17:04:22.813" Score="3" Body="&lt;p&gt;Offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While any transform between two RGB colour spaces can be accomplished with a pure 3x3 matrix, some alternate transforms, such as to YCbCr with given weights, requires an offset.&lt;/p&gt;&#xA;" OwnerUserId="5556" LastEditorUserId="5556" LastEditDate="2016-12-27T17:54:32.507" LastActivityDate="2016-12-27T17:54:32.507" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4426" PostTypeId="2" ParentId="4418" CreationDate="2016-12-28T00:26:17.833" Score="1" Body="&lt;p&gt;In addition to what the others have said, there are some practical issues with making such a display. It was mentioned in the comments that all current content is made for current display technologies, so having extra display capabilities wouldn't get you anything useful. Of course, if such displays were common, content would eventually come, right? Well, not necessarily. Where would it come from? Photos and video are produced either with film cameras or digital cameras. These have wider gamuts and higher dynamic range than current monitors, but I don't believe any of them cover the entire color space you're describing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if you did have ways of capturing the whole range or generating it you'd run into the problem that you'd need more bits per channel, and you'd need data structures and applications to interpret that data appropriately. Photoshop, for example, has supported working in 32-bit per channel float for a while, but many of its functions are unavailable in that mode. Next would be the playback apps. Then all the services that stream stuff to our devices would need to be updated, too. That would mean new codecs, too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fact is, this &lt;em&gt;is&lt;/em&gt; happening. Apple and other manufacturers are starting to use wider gamut displays on their consumer devices (the iMac and iPhone, for example). UHD content is being made for both televisions and consoles, and the display hardware is now available for them. As display gamuts get wider color gamuts (currently most wide displays are DCI-P3 or a variation thereof) and higher dynamic range the software will get written to display properly on them, then codecs will get written store and stream such data. I predict that after P3 displays are the norm, we'll make the next step to something wider like Rec. 2020, and then onto something even wider like ACES-CG. Will it ever cover the whole gamut, and the dynamic range of the eye? Probably someday. Someday soon? Probably not. But in 20-50 years, I could see it being the norm. In the meantime there's a lot of infrastructure that needs to be updated to support it, and it's going to be slow to get it all working properly.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2016-12-28T00:26:17.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4427" PostTypeId="2" ParentId="4394" CreationDate="2016-12-28T03:56:07.543" Score="12" Body="&lt;p&gt;I am posting this for anyone wondering about the confusion between the terms $\frac{1}{\pi}$ and $\frac{1}{4}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The term $\frac{1}{\pi}$ is an error from the original Cook-Torrance reference. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact, the whole term $\frac{1}{4(n \cdot \omega_i)}$ comes from the Jacobian of the transformation from reflected solid angle to normal solid angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to most papers, the $\frac{1}{4}$ term first appeared in &lt;a href=&quot;http://www.graphics.cornell.edu/~westin/pubs/TorranceSparrowJOSA1967.pdf&quot; rel=&quot;noreferrer&quot;&gt;[Torrance, 67]&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a nice explanation of the term, you should check &lt;a href=&quot;http://www1.cs.columbia.edu/CAVE/publications/pdfs/Nayar_PAMI91.pdf&quot; rel=&quot;noreferrer&quot;&gt;[Nayar, 91]&lt;/a&gt;, appendix D. Here is an image from the same paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.gyazo.com/07d01de3a8ad87c74b1c506a36df1460.png&quot; alt=&quot;&quot;&gt;&#xA;$$&#xA;   d\omega' = \frac{d\omega_r}{4\cos{\theta_i'}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, Joe Stam agrees with Nayar's $\frac{1}{4}$ term in [Stam 01, An Illumination Model for a Skin Layer Bounded by Rough Surfaces] , appendix B.&lt;/p&gt;&#xA;" OwnerUserId="5519" LastActivityDate="2016-12-28T03:56:07.543" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4429" PostTypeId="1" CreationDate="2016-12-28T17:08:35.083" Score="3" ViewCount="2250" Body="&lt;p&gt;I searched for Z Buffer on Google and I discovered that's a 2 dimensional array used by the graphical card and whose aim is to enable the handling of two pixels' depth in order to display one of these pixels in front of the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;To illustrate my words&lt;/strong&gt;, let an image which has only 1 pixel.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;What is a Z-Buffer? What is its utility?&lt;/h1&gt;&#xA;&#xA;&lt;h2&gt;Introduction&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Let $P_1$ be the pixel we want to draw in front of $P_2$ (thus, $P_1$ will hide $P_2$ at drawing). So $P_1$ and $P_2$ have the same $X$ and $Y$ coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We decide that the $Z$ coordinate of $P_1$ (ie. its depth) is less than $P_2$'s one (it means $P_1$ is closer to the computer's user than $P_2$): $Z(P_1) = 1$, and $Z(P_2) = 2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Our Z-Buffer has, by definition, the same size as our image: 1 case. Each case of the Z-Buffer contains one pixel's depth and each case is associated with one image's pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, we initialize the (only one) case of our Z Buffer at the maximum value we can store in its cases (depending on the Z Buffer's type, on the OS, etc.: double/float/integer).&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;$P_1$&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Now, we want to first draw $P_1$. The Z Buffer is used: the depth of the $(X(P_1); Y(P_1))$ case's value is compared to the $P_1$'s depth. Of course, $Z(P_1)$ is lesser than $Z( (X(P_1) ; Y(P_1)) )$. The results of this comparison are: first, we replace the old case value with the new $Z$ value (which is: $Z(P_1)$ ); then, $P_1$ is drawn.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;$P_2$&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Finally, we want to draw $P_2$. Again the Z Buffer is used. $(X(P_2); Y(P_2))$ case's value is compared to $Z(P_2)$ (note that: $X(P_2) = X(P_1)$ and $Y(P_2) = Y(P_1)$ - cf. &quot;So $P_1$ and $P_2$ have the same $X$ and $Y$ coordinates.&quot;).&#xA;The results of this comparison are: $(Z(P_2) = 2)$ is superior to $( Z( (X(P_2); Y(P_2)) ) = 1)$; first, we don't replace any case; then, $P_2$ is not drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's how a Z Buffer is used to display a pixel in front of another.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Example of application&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://raphaello.univ-fcomte.fr/IG/ZBuffer/Images/ZBuffer-03.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://raphaello.univ-fcomte.fr/IG/ZBuffer/Images/ZBuffer-03.gif&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Z-Fighting&lt;/h1&gt;&#xA;&#xA;&lt;h2&gt;What is Z-Fighting?&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;If two polygons are very closed AND (note the &quot;AND&quot;) if the camera is moving, Z-Fighting phenomenon appears: &lt;a href=&quot;https://icculus.org/neverball/mapping/zfighting.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://icculus.org/neverball/mapping/zfighting.png&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;How to reproduce Z-Fighting (ie. how does it work? why does it appear?)&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I know Z Fighting is caused by the resolution in depth of the Z Buffer, due to some conversion/casts mathematical and precision errors. But I don't understand it...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particular, I don't understand why the camera must move.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: could you explain this please?&lt;/p&gt;&#xA;" OwnerUserId="5740" LastEditorUserId="231" LastEditDate="2016-12-29T13:12:33.833" LastActivityDate="2016-12-31T19:56:52.237" Title="How to understand Z-Fighting?" Tags="&lt;polygon&gt;&lt;z-buffer&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4430" PostTypeId="2" ParentId="4429" CreationDate="2016-12-28T18:21:08.453" Score="3" Body="&lt;p&gt;The camera does not need to move for this problem to exist. You can see the mixed polygons as in your linked image even with a static camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things are worse with a moving camera because it makes the position of the polygons change, which can lead to different rounding. This means it may not be the same polygon which comes up in front at a given location for every frame. Even a very small change in the camera could swap which polygon is visible. So you get flickering which is visually a lot worse because it draws attention.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One possible solution is to progressively blend surfaces together when their Z values become too similar. However, I'm not certain how easily that can be implemented in traditional Z-buffer rendering.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2016-12-28T18:21:08.453" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4431" PostTypeId="2" ParentId="4429" CreationDate="2016-12-28T18:53:04.913" Score="1" Body="&lt;p&gt;Z-fighting is not related with camera movement. But this issue can be avoided by moving the near plane of the view frustum a little further away from the viewer. As you know, depth testing is the stage in the graphics pipeline which is used to determine whether one pixel is in front or back of the other pixel. It is done by having a buffer known as the z-buffer which stores z values (distance from the viewer) for each fragment. Z-fighting happens when the depth buffer doesn't have enough enough floating point precision to compare two very close z values. Sometimes two z values are so close to each other that they need higher precision to be compared. &lt;a href=&quot;https://learnopengl.com/#!Advanced-OpenGL/Depth-testing&quot; rel=&quot;nofollow noreferrer&quot;&gt;This tutorial&lt;/a&gt; explains everything in a simple way about Depth testing and Z-fighting and also discusses about the solutions to avoid them.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="231" LastEditDate="2016-12-29T12:52:53.623" LastActivityDate="2016-12-29T12:52:53.623" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4432" PostTypeId="2" ParentId="4422" CreationDate="2016-12-28T20:29:30.783" Score="57" Body="&lt;p&gt;I haven't been able to find such a chart on the web, so I made one here. (Everyone, feel free to add, elaborate, or correct any mistakes. Some of these are just best guesses based on a partial understanding of the API and hardware internals.)&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;API Basics&lt;/h2&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11                          OpenGL 4.x&#xA;-----                          ----------&#xA;device                         context&#xA;immediate context              (implicit; no specific name)&#xA;deferred context               (no cross-vendor equivalent, but see&#xA;                                GL_NV_command_list)&#xA;swap chain                     (implicit; no specific name)&#xA;(no cross-vendor equivalent)   extensions&#xA;debug layer; info queue        GL_KHR_debug extension&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Shaders&lt;/h2&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11              OpenGL 4.x&#xA;-----              ----------&#xA;pixel shader       fragment shader&#xA;hull shader        tessellation control shader&#xA;domain shader      tessellation evaluation shader&#xA;(vertex shader, geometry shader, and compute shader&#xA; are called the same in both)&#xA;&#xA;registers          binding points&#xA;semantics          interface layouts&#xA;SV_Foo semantics   gl_Foo builtin variables&#xA;&#xA;class linkage      subroutines&#xA;&#xA;(no equivalent)    program objects; program linking&#xA;&#xA;(D3D11's normal&#xA; behavior; no      separate shader objects&#xA; specific name)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Geometry and Drawing&lt;/h2&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11              OpenGL 4.x&#xA;-----              ----------&#xA;vertex buffer      vertex attribute array buffer; vertex buffer object&#xA;index buffer       element array buffer&#xA;input layout       vertex array object (sort of)&#xA;&#xA;Draw               glDrawArrays&#xA;DrawIndexed        glDrawElements&#xA;(instancing and indirect draw are called similarly in both)&#xA;(no equivalent)    multi-draw, e.g. glMultiDrawElements​&#xA;&#xA;stream-out         transform feedback&#xA;DrawAuto           glDrawTransformFeedback​&#xA;&#xA;predication        conditional rendering&#xA;(no equivalent)    sync objects&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Buffers and Textures&lt;/h2&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11                    OpenGL 4.x&#xA;-----                    ----------&#xA;constant buffer          uniform buffer object&#xA;typed buffer             texture buffer&#xA;structured buffer        (no specific name; subset of SSBO features)&#xA;UAV buffer; RWBuffer     SSBO (shader storage buffer object)&#xA;UAV texture; RWTexture   image load/store&#xA;&#xA;shader resource view     texture view&#xA;sampler state            sampler object&#xA;&#xA;interlocked operations   atomic operations&#xA;append/consume buffer    SSBO + atomic counter&#xA;&#xA;discard buffer/texture   invalidate buffer/texture&#xA;(no equivalent)          persistent mapping&#xA;(D3D11's normal&#xA; behavior; no            immutable storage&#xA; specific name)&#xA;(implicitly inserted     glMemoryBarrier; glTextureBarrier&#xA; by the API)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Render Targets&lt;/h2&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11                     OpenGL 4.x&#xA;-----                     ----------&#xA;(no equivalent)           framebuffer object&#xA;render target view        framebuffer color attachment&#xA;depth-stencil view        framebuffer depth-stencil attachment&#xA;multisample resolve       blit multisampled buffer to non-multisampled one&#xA;&#xA;multiple render targets   multiple color attachments&#xA;render target array       layered image&#xA;&#xA;(no equivalent)           renderbuffer&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Queries&lt;/h2&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11                       OpenGL 4.x&#xA;-----                       ----------&#xA;timestamp query             timer query&#xA;timestamp-disjoint query    (no equivalent)&#xA;(no equivalent)             time-elapsed query&#xA;occlusion query             samples-passed query&#xA;occlusion predicate query   any-samples-passed query&#xA;pipeline statistics query   (no equivalent in core, but see&#xA;                             GL_ARB_pipeline_statistics_query)&#xA;SO statistics query         primitives-generated/-written queries &#xA;(no equivalent)             query buffer object&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Compute Shaders&lt;/h2&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;D3D11                     OpenGL 4.x&#xA;-----                     ----------&#xA;thread                    invocation&#xA;thread group              work group&#xA;thread group size         local size&#xA;threadgroup variable      shared variable&#xA;&#xA;group sync                &quot;plain&quot; barrier&#xA;group memory barrier      shared memory barrier&#xA;device memory barrier     atomic+buffer+image memory barriers&#xA;all memory barrier        group memory barrier&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Other Resources&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://anteru.net/blog/2013/10/13/2188/&quot; rel=&quot;noreferrer&quot;&gt;Porting from DirectX11 to OpenGL 4.2&lt;/a&gt; – not exhaustive, but a quick discussion of common porting issues&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/windows/uwp/gaming/glsl-to-hlsl-reference&quot; rel=&quot;noreferrer&quot;&gt;MSDN: GLSL-to-HLSL porting guide&lt;/a&gt; – lists correspondences and differences between GLSL and HLSL shading languages&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2016-12-29T04:11:37.157" LastActivityDate="2016-12-29T04:11:37.157" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4433" PostTypeId="1" CreationDate="2016-12-29T07:36:18.203" Score="4" ViewCount="316" Body="&lt;p&gt;I'm implementing my path tracer using C++ and OpenMP partially based on the design of &lt;a href=&quot;https://users.cg.tuwien.ac.at/zsolnai/gfx/smallpaint/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Small Paint&lt;/a&gt; (using a globally available RND function to generate random floats) and &lt;a href=&quot;https://github.com/mmp/pbrt-v2&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBRTv2&lt;/a&gt; (uses a single RNG across all threads). I notice that due to the fact there can can be multiple threads accessing the same RNG. Race condition and CPU cache invalidation will occur caused by the RNG writing to memory to store/update it's current state. Thus dragging the performance down and mess up the RNG(makes it unpredictable).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How come this is in one of the top grade educational renderer? Or it's just a minor issue that isn't important?&lt;br&gt;&#xA;If it's important, is there a known good way to fix this without breaking PBRT's rendering/threading architecture?&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="231" LastEditDate="2016-12-30T12:15:06.260" LastActivityDate="2016-12-30T12:15:06.260" Title="Avoiding CPU race condition/cache invalidation of RNG on multi thread path tracing" Tags="&lt;multithreading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4434" PostTypeId="2" ParentId="4422" CreationDate="2016-12-29T10:12:42.363" Score="33" Body="&lt;p&gt;Here's a non-exhaustive list of Vulkan and DirectX 12. This is cobbled together using criteria similar to that of Nathan's.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Overall both APIs are surprisingly similar. Things like shader stages remain unchanged from DX11 and OpenGL. And obviously, DirectX uses views to make things visible to shaders. Vulkan also uses views, but they are less frequent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shader visibility behavior differs a bit between the two. Vulkan uses a mask to determine if a descriptor is visible to the various shader stages. DX12 handles this a little differently, resource visibility is either done on single stage or all stages.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I broke the descriptor set / root parameter stuff down best I could. Descriptor handling is one of the areas that vary greatly between the two APIs. However, the end result is fairly similar.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;API Basics&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vulkan                              DirectX 12&#xA;---------------                     ---------------&#xA;n/a                                 IDXGIFactory4&#xA;VkInstance                          n/a&#xA;VkPhysicalDevice                    IDXGIAdapter1&#xA;VkDevice                            ID3D12Device&#xA;VkQueue                             ID3D12CommandQueue&#xA;VkSwapchain                         IDXGISwapChain3&#xA;VkFormat                            DXGI_FORMAT&#xA;SPIR-V                              D3D12_SHADER_BYTECODE&#xA;VkFence                             fences&#xA;VkSemaphore                         n/a&#xA;VkEvent                             n/a&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vulkan's WSI layer supplies images for the swapchain. DX12 requires creation resources to represent the image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;General queue behavior is pretty similar between both. There's a bit of idiosyncrasy when submitting from multiple threads. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will try to update as I remember more stuff...&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Command Buffer and Pool&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vulkan                              DirectX 12&#xA;---------------                     ---------------&#xA;VkCommandPool                       ID3D12CommandAllocator&#xA;VkCommandBuffer                     ID3D12CommandList/ID3D12GraphicsCommandList&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Verbiage about command pool/allocator from Vulkan/DX12 docs state the behavior in very different words - but the actual behavior is pretty similar. Users are free to allocate many command buffers/lists from the pool. However, only one command buffer/list from the pool can be recording. Pools cannot be shared between threads. So multiple threads require multiple pools. You can also begin recording immediately after submitting the command buffer/list on both.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;DX12 command list are created in an open state. I find this a bit annoying since I'm used to Vulkan. DX12 also requires and explicit reset of the command allocator and command list. This is an optional behavior in Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Descriptors&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vulkan                              DirectX 12&#xA;---------------                     ---------------&#xA;VkDescriptorPool                    n/a&#xA;VkDescriptorSet                     n/a&#xA;VkDescriptorSetLayout               n/a&#xA;VkDescriptorSetLayoutBinding        RootParameter**&#xA;n/a                                 ID3D12DescriptorHeap&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;** &lt;strong&gt;RootParameter&lt;/strong&gt; - not an exact equivalent to &lt;strong&gt;VkDescriptorSetLayoutBinding&lt;/strong&gt; but similar thinking in the bigger picture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VkDescriptorPool and ID3D12DescriptorHeaps are sort of similar (thanks Nicolas) in that they both manage allocation of the descriptors themselves. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It should be noted that DX12 only supports at most two descriptor heaps bound to a command list at any given time. One CBVSRVUAV and one sampler. You can have as many descriptor tables as you want referencing these heaps. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the Vulkan side, there is a hard limit to the max number of descriptor sets that you tell the descriptor pool. On both you have to do a bit of manual accounting on the number of descriptors per type the pool/heap can have. Vulkan is also more explicit with the type of descriptors. Whereas on DX12 descriptors are either CBVSRVUAV or sampler. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;DX12 also has a feature where you can sort of bind a CBV on the fly using SetGraphicsRootConstantBufferView. However, the SRV version of this, SetGraphicsRootShaderResourceView, does not work on textures. It's in the docs - but may also take you a couple of hours to figure this out if you're not a careful reader.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Pipeline&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vulkan                              DirectX 12&#xA;---------------                     ---------------&#xA;VkPipelineLayout                    RootSignature***&#xA;VkPipeline                          ID3D12PipelineState&#xA;VkVertexInputAttributeDescription   D3D12_INPUT_ELEMENT_DESC&#xA;VkVertexInputBindingDescription     &quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;* **RootSignature&lt;/strong&gt; - not an exact equivalent to &lt;strong&gt;VkPipelineLayout&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;DX12 combines the vertex attribute and binding into a single description. &lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Images and Buffers&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vulkan                              DirectX 12&#xA;---------------                     ---------------&#xA;VkImage                             ID3D12Resource&#xA;VkBuffer                            ID3D12Resource&#xA;uniform buffer                      constant buffer&#xA;index buffer                        index buffer&#xA;vertex buffer                       vertex buffer&#xA;VkSampler                           sampler&#xA;barriers/transitions                barriers/transitions&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Barriers on both APIs break down a bit different, but have similar net result.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;RenderPasses / RenderTargets&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vulkan                              DirectX 12&#xA;---------------                     ---------------&#xA;VkRenderPass                        render pass&#xA;VkFramebuffer                       collection of ID3D12Resource&#xA;subpass                             n/a&#xA;n/a                                 render target&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vulkan render passes have a nice auto-resolve feature. DX12 doesn't have this AFIAK. Both APIs provide functions for manual resolve. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's not a direct equivalence between VkFramebuffer and any objects in DX12. A collection of ID3D12Resource that map to RTVs is a loose similarity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VkFramebuffer acts more or less like an attachment pool that VkRenderPass references using an index. Subpasses within a VkRenderPass can reference any of the attachments in a VkFramebuffer assuming the same attachment isn't referenced more than once per subpass. Max number of color attachments used at once is limited to VkPhysicalDeviceLimits.maxColorAttachments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;DX12's render targets are just RTVs that are backed by an ID3D12Resource objects. Max number of color attachments used at once is limited to D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT (8).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both APIs require you to specify the render targets/passes at the creation of the pipeline objects. However, Vulkan allows you to use compatible render passes, so you're not locked into the ones you specify during the pipline creation. I haven't tested it on DX12, but I would guess since it's just an RTV, this is also true on DX12.&lt;/p&gt;&#xA;" OwnerUserId="5745" LastEditorUserId="-1" LastEditDate="2019-03-16T20:09:59.560" LastActivityDate="2019-03-16T20:09:59.560" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="4435" PostTypeId="2" ParentId="4433" CreationDate="2016-12-29T14:46:19.280" Score="3" Body="&lt;p&gt;You need to implement your own RNG class and not use the clib RNG implementation that shares the state across threads. What I'm using is a simple &amp;amp; efficient &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Multiply-with-carry&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;multiply-with-carry&quot;&gt;multiply-with-carry&lt;/a&gt; RNG by George Marsaglia, that I initialize with a seed based on pixel coordinates (e.g. simple x+y*width) that I'm calculating (state per pixel instead of global state)&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2016-12-29T15:54:11.297" LastActivityDate="2016-12-29T15:54:11.297" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4436" PostTypeId="1" AcceptedAnswerId="4437" CreationDate="2016-12-29T18:35:58.620" Score="7" ViewCount="8051" Body="&lt;p&gt;I was studying about Euler angles and I came across the problem gimbal lock which can occur by using Euler angles. In gimbal lock we lose one axis of rotation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But how? And when does it happen? On what conditions? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;All I know about Euler angles is that rotation always occurs about the object axes not upright axes (axes whose orientation is always the same as the world axes). And the object axes will remain perpendicular to each other in each rotation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone use Euler angles and show me how to get to that point of gimbal lock?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can it affect animations?&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="231" LastEditDate="2016-12-31T21:08:19.070" LastActivityDate="2016-12-31T21:08:19.070" Title="How to achieve gimbal lock with Euler angles?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;animation&gt;&lt;mathematics&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4437" PostTypeId="2" ParentId="4436" CreationDate="2016-12-30T10:46:21.203" Score="9" Body="&lt;p&gt;Rotations in 3D are normally done with matrices. The xyz Euler angles can be converted to matrices so that it can be used in the rotation.&#xA;That is where something called rotation order comes in.&#xA;Basically it says in what order you rotate the object.&#xA;First you rotate the object around the x axis, then the y axis and lastly the z axis for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that when you rotate the object around the x axis first, you change the way the y axis and z axis rotate.&#xA;Of course this changes depending on the rotation order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This GIF shows how changing one axis value can change the others, but it doesn't work that way for everything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.giphy.com/3oz8xXJ5NB2owg5V16.gif&quot; alt=&quot;gimbal lock&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here you can also see at the end that I add in that gimbal lock.&#xA;This is where I lose one axis of rotation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This could be fixed by changing the rotation order to an order, where it doesn't break the way it should work.&#xA;It could also be fixed by not using Euler angles but Euler angles are handy and simple in 3D animation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 3D animation it could lead to weird rotations since the values of the rotations have to be changed a lot to get a certain rotation that you want.&#xA;If you would look at the xyz Euler angle values in a graph, you would see spikes because of that.&#xA;This could lead to weird interpolation of the keyframes and a weird end result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you would like to read more about the math behind it, I would recommend reading about rotation matrices in 3D.&#xA;&lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A little extra explanation for the animation:&#xA;Rotation in this case is around axis (shown as circles) and by rotating on one axis, you rotate the other axis. The consequence is that with a normal rotation sphere (the sphere in the animation, but then without the axis being rotated) in the animation, you don't see these axis being rotated. If you get a gimbal lock, one axis is the same as another one, but with a normal rotation sphere it still tries to rotate as if that axis wasn't the same as another one, this means that it uses weird values to get to that rotation and this can make an animation look weird.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="-1" LastEditDate="2017-03-10T09:42:35.423" LastActivityDate="2016-12-30T16:06:55.983" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4438" PostTypeId="2" ParentId="4436" CreationDate="2016-12-30T22:12:50.373" Score="9" Body="&lt;p&gt;A &lt;code&gt;gimbal&lt;/code&gt; is a pivoted support that allows you to rotate around one axis. Now it so happens that Euler rotations* work like a set of 3 gimbals attached to each other, one rotation builds upon the next (or previous/whole stack if your inclined to model it that way). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9Bkct.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9Bkct.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Rotation is like a gimbal. &lt;a href=&quot;http://tf3dm.com/3d-model/fa-22-raptor-86148.html&quot; rel=&quot;noreferrer&quot;&gt;Model&lt;/a&gt; using &lt;em&gt;yxz&lt;/em&gt; rotation (z=blue, x= red and y=green) in a physical 3 axis gimbal structure. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A &lt;code&gt;gimbal lock&lt;/code&gt; happens when you turn 2 or 3 of the successive gimbals and they align onto a plane. You succeed in erasing one direction since the angles both operate same same direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1pCtJ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1pCtJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Rotation direction lost because 2 of the rotations overlap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only way out is to unwind the stricture. Although this is the lock, problems due to diminishing possibilities to turn start earlier than the lock itself.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;A more in depth look at things&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Now this is where most people stop thinking about the issue and move on with their life. They just conclude that Euler angles are somehow broken. This is also where a lot of misunderstandings happen so it's worth investigating the matter slightly further than what causes gimbal lock.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is important to understand that this is &lt;em&gt;only&lt;/em&gt; problematic if you &lt;code&gt;interpolate&lt;/code&gt; in Euler angles**! In a real physical gimbal this is given - you have no other choice. In computer graphics you have many other choices, from normalized matrix, axis angle or quaternion interpolation. Gimbal lock has a much more dramatic implication to designing control systems than it has to 3d graphics. Which is why a mechanical engineer for example will have a very different take on gimbal locking. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You don't have to give up using Euler angles to get rid of gimbal locking, just stop interpolating values in Euler angles. Of course, this means that you can now no longer drive a rotation by doing direct manipulation of one of the channels. But as long as you key the 3 angles simultaneously you have no problems and you can internally convert your interpolation target to something that has less problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using Euler angles is just simply more intuitive to think in most cases. And indeed Euler never claimed it was good for interpolating but just that it can model all possible space orientations. So Euler angles are just fine for setting orientations like they were meant to do. Also incidentally Euler angles have the benefit of being able to model multi turn rotations which will not happen sanely for the other representations.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Problems and how to circumvent them&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;The fact of the matter is that interpolating in Euler angle space is a bad idea, in general and affects you way before you come close to a true gimbal lock. For this reason NASA lunar orbiter would warn of gimbal lock when you come close to a 70-80 degree angle on a single gimbal's turn. So be aware that people do not necessarily talk of just the actual locking condition when they talk of a gimbal lock. Even worse some people blame all their rotation problems on gimbal locking.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Euler rotation is only safe if you rotate primarily one angle and shallow amounts on the other 2 rotations, which is quite common admittedly. This works fine for describing movement of a commercial airliner, a car etc. But not so well for a jet fighter or an acrobatics plane doing complex air maneuvers. What happens is the rotations start to interfere with each other and you get a weird wobble instead of moving straight from one position to the next.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix the wobble problem in shallow cases just swap the rotation order so that the big rotation gets applied on the other rotations. If you need to use more complex rotations then either switch over to other interpolation methods or add even more rotation links to your gimbal (which is a good stopgap measure for cases where you cannot do the switch in a timely manner).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;* To be exact most of the time people do not actually use Euler angles but Tait–Bryan angles. Which are nearly the same thing only Euler insisted on repeating the same axis, not very important distinction but good to know if you ever speak to an academic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;** Oh well, if you use Euler–Lagrange equation it won't matter.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2016-12-31T20:55:39.923" LastActivityDate="2016-12-31T20:55:39.923" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4439" PostTypeId="1" CreationDate="2016-12-31T15:19:00.490" Score="2" ViewCount="219" Body="&lt;p&gt;I have a rendering system that I use for drawing height maps. The system uses triangle strips of indexed verts in a vao. The system has worked fine on the 3 Nvidia cards I have tried it on across several versions of windows and OSX. I don't own any Systems with an ATI card but I sent the application to a colleague to look at for me, and on his machine no output is produced in the 3d viewport. He has a Radeon HD 7800 and is using windows 10 which is one of the operating systems I have tried it on with an Nvidia card. Running OpenGL extensions viewer indicates that his card supports a modern range of capabilities up to GL 4.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I attached an opengl debug callback. The shader program compiles fine and the vao is created without errors. There are no errors on draw either. The shaders use #version 330 core but I tried dropping down to #version 130 and simplifying the shaders to basically output the vertex position and a flat color, and it still works fine on nvidia but outputs nothing on ATI, so I doubt the shaders are the issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect it has something to do with the way the vao is set up or possibly some feature that is missing in ATI drivers or hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following two blocks of code are in Kotlin using LWJGL3. The relevant GL calls are all the same as from Java though. They are a very tiny wrapper to the &lt;code&gt;C&lt;/code&gt; calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vao gets set up like this: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vao = glGenVertexArrays()&#xA;&#xA;if (vao &amp;gt; 0) {&#xA;&#xA;    val stride = floatsPerVertex * 4&#xA;    glBindVertexArray(vao)&#xA;&#xA;    val vbo = glGenBuffers()&#xA;    val ibo = glGenBuffers()&#xA;&#xA;    if (vbo &amp;gt; 0 &amp;amp;&amp;amp; ibo &amp;gt; 0) {&#xA;        glBindBuffer(GL_ARRAY_BUFFER, vbo)&#xA;&#xA;        glBufferData(GL_ARRAY_BUFFER, heightMapVertexData, GL_STATIC_DRAW)&#xA;&#xA;&#xA;        if (positionAttribute.location &amp;gt;= 0) {&#xA;            glEnableVertexAttribArray(positionAttribute.location)&#xA;            glVertexAttribPointer(positionAttribute.location, 2, GL_FLOAT, false, stride, 0)&#xA;        }&#xA;&#xA;        if (uvAttribute.location &amp;gt;= 0) {&#xA;            glEnableVertexAttribArray(uvAttribute.location)&#xA;            glVertexAttribPointer(uvAttribute.location, 2, GL_FLOAT, false, stride, 8)&#xA;        }&#xA;&#xA;        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)&#xA;&#xA;        glBufferData(GL_ELEMENT_ARRAY_BUFFER, heightMapIndexData, GL_STATIC_DRAW)&#xA;&#xA;    } else {&#xA;        throw RuntimeException(&quot;error setting up buffers&quot;)&#xA;    }&#xA;&#xA;    glBindVertexArray(0)&#xA;} else {&#xA;    throw RuntimeException(&quot;error generating vao&quot;)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A draw call does this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDisable(GL_BLEND)&#xA;glDisable(GL_CULL_FACE)&#xA;glEnable(GL_DEPTH_TEST)&#xA;glEnable(GL_SCISSOR_TEST)&#xA;glEnable(GL_MULTISAMPLE)&#xA;glClearColor(background.r, background.g, background.b, background.a)&#xA;glScissor(xPosition, flippedY, width, height)&#xA;glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)&#xA;glViewport(xPosition, flippedY, width, height)&#xA;glUseProgram(heightMapProgram)&#xA;glUniformMatrix4fv(mvMatrixUniform.location, false, mvMatrix.get(0, floatBuffer))&#xA;glUniformMatrix3fv(nMatrixUniform.location, false, normalMatrix.get(0, floatBuffer))&#xA;glUniformMatrix4fv(mvpMatrixUniform.location, false, mvpMatrix.get(0, floatBuffer))&#xA;glUniform3f(lightDirectionUniform.location, lightDirection.x, lightDirection.y, lightDirection.z)&#xA;glUniform4f(color1Uniform.location, 0.157f, 0.165f, 0.424f, 1.0f)&#xA;glUniform4f(color2Uniform.location, 0.459f, 0.761f, 0.859f, 1.0f)&#xA;glUniform4f(color3Uniform.location, 0.353f, 0.706f, 0.275f, 1.0f)&#xA;glUniform4f(color4Uniform.location, 0.922f, 0.922f, 0.157f, 1.0f)&#xA;glUniform4f(color5Uniform.location, 0.835f, 0.176f, 0.165f, 1.0f)&#xA;glUniform4f(color6Uniform.location, 0.955f, 0.955f, 0.955f, 1.0f)&#xA;glUniform4f(ambientUniform.location, 0.1f, 0.1f, 0.1f, 1.0f)&#xA;glUniform4f(diffuseUniform.location, 0.6f, 0.6f, 0.6f, 1.0f)&#xA;glUniform4f(specularUniform.location, 0.85f, 0.85f, 0.85f, 1.0f)&#xA;glUniform1f(shininessUniform.location, 1.7f)&#xA;glUniform1f(heightScaleUniform.location, heightMapScaleFactor.value)&#xA;glUniform1f(uvScaleUniform.location, heightMap.width / textureResolution)&#xA;glUniform1i(heightMapTextureUniform.location, 0)&#xA;glActiveTexture(GL_TEXTURE0)&#xA;glBindTexture(GL_TEXTURE_2D, textureId)&#xA;glBindVertexArray(vao)&#xA;glDrawElements(GL_TRIANGLE_STRIP, indexCount, GL_UNSIGNED_INT, 0)&#xA;glBindVertexArray(0)&#xA;glDisable(GL_SCISSOR_TEST)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here are the shaders for what they're worth even though reducing these to #version 130 doesn't help and it doesn't work with or without the commented code on ATI. Nvidia runs all variations. The shaders themselves don't appear to have any impact on the issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330&#xA;&#xA;uniform mat4 modelViewProjectionMatrix;&#xA;uniform float heightScale;&#xA;uniform sampler2D heightMapTexture;&#xA;&#xA;in vec2 position;&#xA;in vec2 uv;&#xA;&#xA;out VertexData {&#xA;    vec2 position;&#xA;    vec2 uv;&#xA;} VertexOut;&#xA;&#xA;void main () {&#xA;    VertexOut.uv = uv;&#xA;    VertexOut.position = position;&#xA;    float height = texture(heightMapTexture, uv).r * heightScale;&#xA;    gl_Position = modelViewProjectionMatrix * vec4(position, height, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;fragment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330&#xA;&#xA;uniform mat4 modelViewProjectionMatrix;&#xA;uniform mat4 modelViewMatrix;&#xA;uniform mat3 normalMatrix;&#xA;uniform vec3 lightDirection;&#xA;uniform vec4 color1;&#xA;uniform vec4 color2;&#xA;uniform vec4 color3;&#xA;uniform vec4 color4;&#xA;uniform vec4 color5;&#xA;uniform vec4 color6;&#xA;uniform vec4 ambientColor;&#xA;uniform vec4 diffuseColor;&#xA;uniform vec4 specularColor;&#xA;uniform float shininess;&#xA;uniform float heightScale;&#xA;uniform float uvScale;&#xA;uniform sampler2D heightMapTexture;&#xA;&#xA;&#xA;in VertexData {&#xA;    vec2 position;&#xA;    vec2 uv;&#xA;} VertexIn;&#xA;&#xA;out vec4 colorOut;&#xA;&#xA;//const ivec3 off = ivec3(-1, 0, 1);&#xA;//&#xA;//const float gamma = 2.2;&#xA;&#xA;//vec3 toLinear(vec3 v) {&#xA;//  return pow(v, vec3(gamma));&#xA;//}&#xA;//&#xA;//vec4 toLinear(vec4 v) {&#xA;//  return vec4(toLinear(v.rgb), v.a);&#xA;//}&#xA;//&#xA;//vec3 toGamma(vec3 v) {&#xA;//  return pow(v, vec3(1.0 / gamma));&#xA;//}&#xA;//&#xA;//vec4 toGamma(vec4 v) {&#xA;//  return vec4(toGamma(v.rgb), v.a);&#xA;//}&#xA;&#xA;void main() {&#xA;//    if (!gl_FrontFacing) {&#xA;//        colorOut = vec4(0.076f, 0.082f, 0.212f, 1.0f);&#xA;//        return;&#xA;//    }&#xA;    colorOut = color1;&#xA;//    vec2 size = vec2(uvScale * 2, 0.0);&#xA;//    float unscaledHeight = texture(heightMapTexture, VertexIn.uv).r;&#xA;//    float height = unscaledHeight * heightScale;&#xA;//    float westPixel = textureOffset(heightMapTexture, VertexIn.uv, off.xy).r * heightScale;&#xA;//    float eastPixel = textureOffset(heightMapTexture, VertexIn.uv, off.zy).r * heightScale;&#xA;//    float northPixel = textureOffset(heightMapTexture, VertexIn.uv, off.yx).r * heightScale;&#xA;//    float southPixel = textureOffset(heightMapTexture, VertexIn.uv, off.yz).r * heightScale;&#xA;//    float northWestPixel = textureOffset(heightMapTexture, VertexIn.uv, off.xx).r * heightScale;&#xA;//    float southEastPixel = textureOffset(heightMapTexture, VertexIn.uv, off.zz).r * heightScale;&#xA;//    float northEastPixel = textureOffset(heightMapTexture, VertexIn.uv, off.zx).r * heightScale;&#xA;//    float southWestPixel = textureOffset(heightMapTexture, VertexIn.uv, off.xz).r * heightScale;&#xA;//    vec3 va = normalize(vec3(size.xy, eastPixel - westPixel));&#xA;//    vec3 vb = normalize(vec3(size.yx, southPixel - northPixel));&#xA;//    vec3 vc = normalize(vec3(size.xx, southEastPixel - northWestPixel));&#xA;//    vec3 vd = normalize(vec3(size.x, -size.x, southWestPixel - northEastPixel));&#xA;//    vec3 crossNormal = cross(va, vb);&#xA;//    crossNormal = normalize(vec3(crossNormal.x, -crossNormal.y, crossNormal.z));&#xA;//    vec3 xNormal = cross(vd, vc);&#xA;//    xNormal = normalize(vec3(xNormal.y, -xNormal.x, xNormal.z));&#xA;//    vec3 modelNormal = normalize(xNormal + crossNormal);&#xA;//    vec3 normal = normalize(normalMatrix * modelNormal);&#xA;//    float diffuse = max(dot(normal, lightDirection), 0.0) + 0.06;&#xA;//    vec4 lowColor;&#xA;//    vec4 highColor;&#xA;//    float interpolation;&#xA;//    if (unscaledHeight &amp;lt;= 0.05) {&#xA;//        lowColor = color1;&#xA;//        highColor = color1;&#xA;//        interpolation = 0.5;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.19) {&#xA;//        lowColor = color1;&#xA;//        highColor = color2;&#xA;//        interpolation = (unscaledHeight - 0.05) * 7.1426;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.24) {&#xA;//        lowColor = color2;&#xA;//        highColor = color2;&#xA;//        interpolation = 0.5;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.38) {&#xA;//        lowColor = color2;&#xA;//        highColor = color3;&#xA;//        interpolation = (unscaledHeight - 0.24) * 7.1426;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.43) {&#xA;//        lowColor = color3;&#xA;//        highColor = color3;&#xA;//        interpolation = 0.5;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.57) {&#xA;//        lowColor = color3;&#xA;//        highColor = color4;&#xA;//        interpolation = (unscaledHeight - 0.43) * 7.1426;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.62) {&#xA;//        lowColor = color4;&#xA;//        highColor = color4;&#xA;//        interpolation = 0.5;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.76) {&#xA;//        lowColor = color4;&#xA;//        highColor = color5;&#xA;//        interpolation = (unscaledHeight - 0.62) * 7.1426;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.81) {&#xA;//        lowColor = color5;&#xA;//        highColor = color5;&#xA;//        interpolation = 0.5;&#xA;//    } else if (unscaledHeight &amp;lt;= 0.95) {&#xA;//        lowColor = color5;&#xA;//        highColor = color6;&#xA;//        interpolation = (unscaledHeight - 0.81) * 7.1426;&#xA;//    } else {&#xA;//        lowColor = color6;&#xA;//        highColor = color6;&#xA;//        interpolation = 0.5;&#xA;//    }&#xA;//    vec4 baseColor = mix(toLinear(lowColor), toLinear(highColor), interpolation);&#xA;//    vec4 lightColor = toLinear(vec4(1.0));&#xA;//    vec4 diffuseColor = vec4(baseColor.rgb * lightColor.rgb * diffuse, 1.0);&#xA;//    vec4 spec = vec4(0.0);&#xA;//    vec3 eye = -normalize(vec3(modelViewMatrix * vec4(VertexIn.position.xy, height, 1.0)));&#xA;//    float intensity = max(dot(normal, lightDirection), 0.0);&#xA;//    if (intensity &amp;gt; 0.0) {&#xA;//        vec3 halfVector = normalize(lightDirection + eye);&#xA;//        spec = toLinear(specularColor) * pow(max(dot(halfVector, normal), 0.0), shininess);&#xA;//    }&#xA;//    colorOut = toGamma(diffuseColor * max(intensity * toLinear(diffuseColor) + spec, toLinear(ambientColor)));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The geometry itself is correctly formed in &lt;code&gt;heightMapTexture&lt;/code&gt; to the best of my knowledge because I've inspected it piece by piece in a debugger and because the strips come out correctly on Nvidia cards. I am assuming there are no fundamental differences in how &lt;code&gt;GL_TRIANGLE_STRIP&lt;/code&gt; works between Nvidia and ATI. If there is a difference then that's exactly the type of thing this question is trying to figure out. The description of triangle strips in the OpenGL spec doesn't seem to leave much room for differences here if any, so it seems likely that if the strips themselves are formed correctly according to the spec they should work everywhere or nowhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The geometry is a basic hexagonally arranged triangle grid with degenerates in between the strips. I'd like to figure out what features are causing this to output nothing except the &lt;code&gt;glClear()&lt;/code&gt; on ATI cards so I can get people with different machines looking at the application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example of what it outputs on all the Nvidia machines across various windows and OSX flavors, in case that helps&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NTg6O.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NTg6O.jpg&quot; alt=&quot;sample output&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On ATI it displays the gray scissor clear rectangle that is drawn by the snippet:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glEnable(GL_SCISSOR_TEST)&#xA;glClearColor(background.r, background.g, background.b, background.a)&#xA;glScissor(xPosition, flippedY, width, height)&#xA;glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Nothing else besides the gray rectangle is displayed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In summary, for someone who has something like this working on an ATI card, are these the OpenGL calls that you would use to get it drawing on an ATI card or is there some obvious feature I'm using that's not supported by ATI that's causing the whole thing to not draw. I'm looking for possible differences between how ATI and Nvidia would handle this geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. I added this note to answer some of the comments that suggest I should go back to a single triangle and debug from scratch on my own. The reason I'm asking this question is that I don't currently have access to ATI hardware. I'm in South America until May and hardware availability is basically nil where I am. I have several workstations that I brought with me for work, but they all have Nvidia hardware. I have to do a full build and then ship the product to someone in a different time zone each time I attempt to correct the issue. I need to be more purposeful in my fixes than going back to drawing a triangle and working up from scratch. I would love to debug it myself on the affected hardware step by step. I just can't right now. I need to get the code closer to a likely solution before sending another build, so I'm looking for some educated guesses from people with direct experience with this type of geometry on ATI hardware. I would greatly appreciate more understanding than &quot;That's what debug is for. Go back to a triangle.&quot;, because those comments really don't help me or anyone else reading this later. This problem seems like something that someone must have encountered before because it seems like a pretty standard way to draw a heightmap. I think that this question will help anyone else who has this problem in the future. I've lost several days to this, and there is no published answer to anything similar that I could find. If this remains unanswered until May, when I return home, I will write the answer myself and remove this note, but I hope it doesn't come to that.&lt;/p&gt;&#xA;" OwnerUserId="5763" LastEditorUserId="5763" LastEditDate="2017-01-01T12:43:39.040" LastActivityDate="2017-01-01T12:43:39.040" Title="Is there a difference in how ATI cards draw triangle strips vs Nvidia cards that would cause ATI cards to output nothing?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="16" ContentLicense="CC BY-SA 3.0" />
  <row Id="4440" PostTypeId="2" ParentId="4429" CreationDate="2016-12-31T19:56:52.237" Score="1" Body="&lt;p&gt;As others mentioned, &lt;a href=&quot;https://en.wikipedia.org/wiki/Z-fighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;z-fighting/stiching&lt;/a&gt; occurs even if the camera is not moving.  However, when the camera is moving and you're getting z-fighting, it will appear as though the polygons are flickering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://reedbeta.com/blog/depth-precision-visualized/&quot; rel=&quot;nofollow noreferrer&quot;&gt;This link&lt;/a&gt; helped me to understand the depth buffer much better.  Here he generates depth values and simulates the different kinds of precision errors you would get depending on your depth buffer format (graphics APIs usually let you request a depth buffer format).  &quot;indist&quot; and &quot;swaps&quot; are both precision errors, and can cause the z-fighting to appear.&lt;/p&gt;&#xA;" OwnerUserId="2318" LastActivityDate="2016-12-31T19:56:52.237" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4441" PostTypeId="1" AcceptedAnswerId="4445" CreationDate="2017-01-01T04:46:15.877" Score="3" ViewCount="564" Body="&lt;p&gt;I've just finished writing a path tracer that takes OBJ files and renders it. This is convenient for still images, but my end goal was to export a sequence from a 3D application (Blender was what I had in mind), and then render an image sequence from that. Originally I figured an OBJ sequence would do, but that would take a massive amount of space for complex scenes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I began looking into parsing .fbx, .3ds and other popular file formats, but there's so little out there that I could find. I still don't really understand how those files store animations. I can imagine the mesh is stored and then keyframes indicate which vertices translate...? Maybe? Or whole objects? What happens when you have complex deformation like an ocean wave, fluid, or character where many, many vertices are translating? At that point would it be easier to do some sort of OBJ like sequence? I want to stay away from that if I can since it takes lots of memory/time to export.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hopefully someone can point me in the right direction or explain how other standalone renderers keep their animation data. Thank you!&lt;/p&gt;&#xA;" OwnerUserId="5764" LastActivityDate="2017-01-02T10:43:30.797" Title="Storing 3D animations for ray tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;animation&gt;&lt;scene-description&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4442" PostTypeId="1" AcceptedAnswerId="4444" CreationDate="2017-01-01T06:52:09.213" Score="3" ViewCount="1432" Body="&lt;p&gt;I have implemented a sky rendering model in my ray tracer which saves the color of the sky to an image. I was wondering how I can render the sky dome and texture map the image on to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I render the sphere at the center of the environment and add the image to the inside of the sphere? How would I add a texture to the inside of a sphere as opposed to the outside in code? Do I just reverse the normals?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2017-01-01T13:32:25.380" LastActivityDate="2017-01-01T17:14:19.177" Title="Skybox in a Ray Tracer" Tags="&lt;raytracing&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4443" PostTypeId="2" ParentId="4441" CreationDate="2017-01-01T10:37:24.880" Score="2" Body="&lt;p&gt;Pixar spent quite much time, money and other capital to archive all their renders. What they did was just to store the raw render description files their render engine used. The reason for this is that it's the only way to ensure that the features stay intact. Of course they had a very well documented standardized format to work with. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The benefit of this method is that it stores things relevantly. In other words static objects can be stored static and only animation objects need to be stored frame by frame which is the only way to ensure compatibility for animation without relying on host apps to do this for you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alembic works on a similar principle. The downside is big formats. But note that formats such as FBX and Collada (*.dae) are not much better. While it's true that they can contain some of the animation data they cannot always do everything that you want them to do. Which means that in the end it might not do what you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The animation exchange formats (FBX, Collada etc...) do not usually store vertex positions, if they did then they would just have same problem as your obj storage. Instead they store the modification history so that they can redo the animation. So for example the bones are stored as transforms and the vertex weights are used to compute their position. The downside is that your reader needs to implement substantial amounts of the animation core. And anything the format does not know how to do is stored either as point caches, or not at all. Realistically speaking for FBX you would use the API to do this. Implementing it yourself is a quite big undertaking, it may be cheaper to just buy more storage space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Personally I would implement something like the RI spec for my own renderer. If not RI spec itself which would allow you to swap renderer if need be (also the other way around a user could swap to your renderer without many changes).&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2017-01-02T10:43:30.797" LastActivityDate="2017-01-02T10:43:30.797" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4444" PostTypeId="2" ParentId="4442" CreationDate="2017-01-01T17:14:19.177" Score="4" Body="&lt;p&gt;I'm not entirely sure if I understood the question, but it seems like you want to implement environment map illumination in your ray tracer (you seem to be thinking in real-time, though). I will approach the general solution for offline renderers without assuming anything about the scene except the environment sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is generally done by considering your environment as a light source. Let's say that you use a sphere with a radius big enough to contain your scene. Then, you sample it as you would sample an area light source. You can think of this sphere as a &lt;strong&gt;textured light source&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The contribution of the direct lighting on the radiance leaving a point $x$ on the direction $\Theta$ would be:&#xA;$$&#xA;L_{\text{direct}}(x \rightarrow \Theta) = L_{\text{lights}}(x \rightarrow \Theta) + L_{\text{env}}(x \rightarrow \Theta)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where the environment map contribution is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;L_{\text{env}}(x \rightarrow \Theta) = {\int_{\Omega_x} L_{\text{tex}}}(x \leftarrow \Psi)f_r(x, \Theta \leftrightarrow \Psi)V(x, \Psi) \cos(\Psi, N_x)\, d\omega_{\Psi} \qquad (1)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that, here, $\Psi$ are directions to the sphere, $V(x, \Psi) = 1$ if and only if the sphere is visible from that direction and $V(x, \Psi) = 0$ otherwise, $f_r$ is the BRDF and $L_{\text{tex}}$ is the color on the texture. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Directions $\Psi$ can be generated with a parameterization of the sphere. If you want something simple, then this is enough, &lt;strong&gt;just treat it as a textured area light and emit whatever color is on the texture on the sampled point&lt;/strong&gt;. If you want something more elaborate, consider the rest of the text.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With this said, environment mapping can be inefficient if not implemented with care. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I am assuming you only implemented area lights that emit uniformly, so it was okay to sample its area uniformly. However, it is clear that the sphere is a light source where some parts contribute more than others since the colors vary on the texture. This, combined with the fact that the sphere occupies the entire solid angle around a point (instead of the hemisphere that you usually sample), skyrockets the variance of the estimator of $(1)$. The visibility term $V(x, \Psi)$ further complicates things regarding variance, depending on your scene (if it very exposed or not).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to sample and estimate $(1)$, you have to consider:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Parameterization of the sphere&lt;/strong&gt;: You need to decide how to parameterize your sphere. You need to have a space where you can generate random points and map to a point on the sphere to get a direction $\Psi$ and the color from the texture. You can just use typical the latitude-longitude parameterization. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more elaborate, better distributed parameterizations: &lt;a href=&quot;http://gamedevs.org/uploads/realistic-hardware-accelerated-shading-and-lighting.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paraboloid parameterization&lt;/a&gt; [page 4]; &lt;a href=&quot;https://pdfs.semanticscholar.org/4322/6a3916a85025acbb3a58c17f6dc0756b35ac.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;concentric-map parameterization&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;PDF $p(\Psi)$ used for sampling the sphere&lt;/strong&gt;: It is possible to reduce the variance that I mentioned earlier. You can importance sample only using the term $\cos(\Psi, N_x)$ (i.e. cosine lobe sampling), but even so it is possible to do better than that. If the BRDF $f_r$ is simple, you can sample the product of the BRDF with $\cos(\Psi, N_x)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are other methods. In &lt;a href=&quot;https://www.uni-kl.de/AG-Heinrich/EIbHDRI.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;[Kollig, Keller; 03]&lt;/a&gt; a PDF is built from the 2D array of the texture itself. This way, it is possible to get more samples from directions from where the map contributes more. A PDF from the product of this with the BRDF would yield the best results considering a compromise between the sampling cost and actual variance reduction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a more elaborate and adaptive solution, check &lt;a href=&quot;http://graphics.ucsd.edu/~sagarwal/structured.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;[Agarwal et. al, 03]&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5519" LastActivityDate="2017-01-01T17:14:19.177" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4445" PostTypeId="2" ParentId="4441" CreationDate="2017-01-01T17:37:32.553" Score="4" Body="&lt;p&gt;I think that it is important to &lt;em&gt;classify&lt;/em&gt; between different types of animations here. One rough classification could be&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Rigid body animations&lt;/li&gt;&#xA;&lt;li&gt;Vertex skinning animations&lt;/li&gt;&#xA;&lt;li&gt;Others...&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h1&gt;Rigid body animations&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;This refers to animations where the actual geometry data does not change. For example, you could have a geometric object, like a unit cube, and apply (usually affine) transformations to it: You can rotate, translate or scale this object. This is usually accomplished by some sort of scene graph: Each &lt;em&gt;node&lt;/em&gt; of this scene graph can have information about the rotation, translation and scaling that should be applied to the objects. In general, this is something that can be expressed with a 4x4 transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The key point is that you don't have to store &quot;animated geometry data&quot;. You only have to store the geometry data &lt;em&gt;once&lt;/em&gt;, in its original state. In addition to that, you store the key frames of the transformation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case, if you wanted to do a rigid body animation, you could store the geometry in an OBJ file, and additionally store the key frame information in an arbitrary form, for example&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;TIME  TRANSLATION&#xA;0.0   ( 0, 0, 0)&#xA;0.1   (10, 0, 0)&#xA;0.2   (10,10, 0)&#xA;0.3   ( 0,10, 0)&#xA;0.4   ( 0, 0, 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This could describe a movement of the object along a rectangular path, taking 0.4 seconds. Fortunately, you don't have to create your own file format for that. There already are solutions for storing this sort of animation data. For example, the COLLADA format already supports animations like this. A more compact representation of such an animation can be stored in a &lt;a href=&quot;https://github.com/KhronosGroup/glTF/&quot; rel=&quot;nofollow noreferrer&quot;&gt;glTF asset&lt;/a&gt;. For example, it can represent animations like this one, from the glTF sample models repository:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mm5ek.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mm5ek.gif&quot; alt=&quot;animation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Vertex skinning animations&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;This technique refers, roughly speaking, to cases where you have an &quot;initial&quot; geometry, and you can define &quot;rules&quot; of how this geometry should be deformed based on the pose of a skeleton. As the name suggests, this is mainly intended for character animations, where you define a skeleton consisting of the &quot;bones&quot; of the character, and the geometry defines the &quot;skin&quot; of the character. Vertex skinning is also supported by different file formats like COLLADA or glTF. The effect is shown in this image, again, from the glTF sample models:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/C85k5.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/C85k5.gif&quot; alt=&quot;skinning&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As already mentioned by &lt;a href=&quot;https://computergraphics.stackexchange.com/a/4443/1649&quot;&gt;joojaa in his answer&lt;/a&gt;, implementing vertex skinning according to the specifications of these file formats may be a bit tricky. Additionally, a considerable amount of the skinning computations is usually done by the &lt;em&gt;vertex shader&lt;/em&gt;. So for a ray-tracer, you would have to move these computations into your application code. &lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Others...&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;This refers to what you already alluded to in the question: There may be cases where the animation is &lt;em&gt;not&lt;/em&gt; a simple transformation of rigid objects, and where you cannot define any &quot;rules&quot; of how the vertices should be transformed. For example, when the vertex positions are computed by a simulator, like a fluid simulator or a &lt;em&gt;soft&lt;/em&gt; body simulator. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In doubt, it may simply be necessary to actually store the positions of all vertices, frame for frame. You could achieve this as a sequence of OBJ files. But note that OBJ files contain ASCII data, and thus, are usually &lt;em&gt;large&lt;/em&gt; and the geometry data has to be parsed before it can be used. Storing the data in a binary form that can be used by the application directly may be beneficial here. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are some possible approaches for reducing the amount of data that has to be stored. For example, one could extend the concept of &quot;key frames&quot; here. For example, one could store the initial configuration of al vertices, and then only store the &lt;em&gt;movement&lt;/em&gt; of vertices that acutally have &lt;em&gt;changed&lt;/em&gt; between two frames. But of course, if (nearly) &lt;em&gt;all&lt;/em&gt; vertices changed, the savings may be diminishing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not aware of any universally applicable, &quot;standardized&quot; solutions for this. Maybe some of the solutions that &lt;a href=&quot;https://computergraphics.stackexchange.com/a/4443/1649&quot;&gt;joojaa referred to in his answer&lt;/a&gt; could be helpful here. &lt;/p&gt;&#xA;" OwnerUserId="1649" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-01-01T17:37:32.553" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4447" PostTypeId="1" AcceptedAnswerId="4448" CreationDate="2017-01-02T08:32:05.583" Score="5" ViewCount="2236" Body="&lt;p&gt;In older versions of OpenGL there were things like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;glLight(...)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;gl_LightSourceParameters&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The modern way of doing lighting is passing light source parameters manually to the shader in vao-s? Or uniforms?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why are these things decrepated? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if I have 100 light sources in the scene, I obviously can't compute lighting with all of them. So somehow in a specific object's shading I have to only care about the light sources which are important for it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that I should move for example only 8 light sources to the shaders, based on their &quot;strength&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But isn't this too complicated to call every frame? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I handle lots of light sources (in the scene)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;/I read about deferred lighting, but is that the only way?/&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="5609" LastActivityDate="2017-01-02T09:48:30.780" Title="Modern way of light sources in OpenGL?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;lighting&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4448" PostTypeId="2" ParentId="4447" CreationDate="2017-01-02T09:48:30.780" Score="9" Body="&lt;p&gt;&lt;strong&gt;Why are they deprecated?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Those functions are deprecated because the OpenGL API moved in favor of a programmable pipeline in contrast with the old fixed pipeline. The programmable pipeline allows the flexibility necessary to enable a wide variety of effects and solutions that before were difficult or not possible at all to implement. You can &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Legacy_OpenGL&quot;&gt;still access those functions&lt;/a&gt;, as they are necessary to support older systems, but besides that I don't see any reason not to use the programmable pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How to pass parameters&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we are talking about parameters of lights (such as their position or intensity), you can pass those using uniforms. Particularly, you should look at &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object&quot;&gt;Uniform Buffer Objects&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would look like this in a shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Light {&#xA;   int type;&#xA;   vec3 diffuse;&#xA;   vec3 position;&#xA;   bool on;&#xA;   ...&#xA;};&#xA;&#xA;#define MAX_NUM_LIGHTS 8&#xA;&#xA;uniform lightBlock {&#xA;    Light lights[MAX_NUM_LIGHTS];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that this already gives you a way of passing the lights that you want. Make your shaders expect an uniform buffer with 8 lights, copy those into an array in your client code and send them using the API. For more info on how to do this using the API functions, check the link above about UBOs and &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Interface_Block_(GLSL)&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is it too complicated to call every frame?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depends on your scene and the criteria for how to choose the lights that you want to pass to the shader. If you are worried about sending the data of 8 lights through uniforms each frame, then don't, that is the least of your worries. The problem lies in the selection process of the lights and the complexity of your scene/shading model, as the cost increases with the number of lights.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Forward Renderer&lt;/strong&gt;: If your scene and shading models are simple, maybe 8 lights are okay. If you implement modern shading models, 8 lights might be a bit too much. The point is that you will have to test it with the scene and shading models and find a compromise between all of that. Maybe pass 4 instead of 8 lights, maybe you should simplify shading models, etc.&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deferred Renderer&lt;/strong&gt;: A deferred renderer does help with multiple light rendering due to the way it is designed. However, deferred rendering may introduce other difficulties as it is, in my opinion, a more complex system. Also, transparency and other aspects may be a pain to deal with. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Other considerations&lt;/strong&gt;: Keep in mind that there are possible optimizations. It may be possible to optimize specific lights. Maybe not all of them need to be dynamic: think of &lt;a href=&quot;http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-15-lightmaps/&quot;&gt;light maps&lt;/a&gt; and other &lt;a href=&quot;https://en.wikipedia.org/wiki/Image-based_lighting&quot;&gt;image based lighting&lt;/a&gt;. You should consider if your scene can apply any of this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In summary&lt;/strong&gt;, choosing between deferred or forward is a big decision. Carefully think about your scene requirements first and devise a strategy for light selection. Take into account the complexity of your shading models. For optimization, you can combine several techniques, such as simplifying some lights that are far away from the camera and only pass the relevant ones. When you have a framework for testing, find a compromise between all of this.&lt;/p&gt;&#xA;" OwnerUserId="5519" LastActivityDate="2017-01-02T09:48:30.780" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4450" PostTypeId="1" AcceptedAnswerId="4451" CreationDate="2017-01-02T16:33:10.507" Score="7" ViewCount="1883" Body="&lt;p&gt;Can I pass the data to the GPU through multiple cores with OpenGL?&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="231" LastEditDate="2017-01-03T00:01:10.000" LastActivityDate="2017-01-03T00:01:10.000" Title="Why can't I utilize multiple CPU cores with OpenGL like Vulkan?" Tags="&lt;opengl&gt;&lt;opengl-es&gt;&lt;vulkan&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4451" PostTypeId="2" ParentId="4450" CreationDate="2017-01-02T18:47:54.863" Score="12" Body="&lt;p&gt;Because the fundamental foundation of OpenGL makes multi-CPU-core submission impossible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Memory_Model&quot;&gt;OpenGL, at its core, is a &lt;em&gt;synchronous API&lt;/em&gt;&lt;/a&gt;. Every OpenGL command behaves &quot;as if&quot; it were executed and completed immediately. Sure, &lt;code&gt;glFlush&lt;/code&gt; and &lt;code&gt;glFinish&lt;/code&gt; are provided, so that implementations can have some asynchronous execution of commands. But these are essentially fig leaves over the definition of OpenGL as synchronous.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can attach a texture to an FBO, bind that FBO, render to it, unbind that FBO, bind the texture as a source, and read from it. You can do all of this without &lt;em&gt;any thought&lt;/em&gt; as to the fact that you've issued two sets of commands where there can be zero overlap between them. This is because OpenGL implementations are required to issue whatever synchronization mechanisms are needed to make this work. You as the user can be completely oblivious to this.&lt;sup&gt;1&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because of that, consider what would happen if you could issue that render-to-texture in one thread and the read-from-texture in another. How exactly would that even work? You would need some way to say &quot;don't execute the read until the write is done&quot;. But since the two sets of commands are on different threads, how do you say that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL has no mechanism for doing so; the closest it gets would be some form of fence sync. And even that would require that the render-to-texture thread has already finished sending those commands, since &lt;code&gt;glFenceSync&lt;/code&gt; issues the fence actual fence (you cannot create a fence that has not yet been submitted). Which means that the render-to-texture thread may as well send the read-from-texture commands too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make OpenGL work asynchronously means making lots of adjustments to its memory model. You'll have to add lots of commands for making things visible to other threads. For allowing thread A to not have its commands execute until thread B is finished. You'd need to make command buffers and queues first-class constructs of the API. And so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And you have to do it in a way that's backwards compatible with the existing memory model. Unless you want to go through another core/compatibility split &lt;em&gt;again&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NV_command_list shows the challenges of trying to build this sort of thing into OpenGL. They force you to use ARB_bindless_texture. They had to invent bindless buffers, so that you can provide vertex arrays, UBOs, and SSBOs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And even then, it's not something that AMD could even implement. Why? Because of image layouts. NVIDIA's hardware has fewer layouts and handles transitions automatically. AMD's hardware requires explicit control of layouts. Once you break the synchronous memory model, that implementation detail of what layout a texture is in becomes really important. You &lt;em&gt;have to&lt;/em&gt; have control over it. You have to explicitly state it in various API, and you have to know to change it when you use a texture in a different way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is also almost certainly why AMD doesn't implement D3D11 deferred contexts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or you can do what Khronos did: make an API that naturally handles all of this stuff. A clean break is ultimately best for everyone. It allows us to jettison other garbage that OpenGL had, so that we can have a nice, clean, lower-level API.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;: While you can be oblivious, obviously you &lt;em&gt;shouldn't&lt;/em&gt; be oblivious if you care about things like performance. You should put some work between the render-to-texture and the read from that texture, if at all possible. That's one of the biggest problems with OpenGL's synchronous-by-default API: it makes it easy to do things the slow way, since the API itself doesn't force you to issue that synchronization. In Vulkan, you &lt;em&gt;cannot&lt;/em&gt; be ignorant of that synchronization. Or at least, not without your code invoking UB.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-01-02T21:57:19.360" LastActivityDate="2017-01-02T21:57:19.360" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4452" PostTypeId="1" AcceptedAnswerId="4453" CreationDate="2017-01-02T18:59:49.803" Score="3" ViewCount="184" Body="&lt;p&gt;Using my raytracing engine, I'd like to generate a 360 degree video which could then be uploaded on Youtube.&#xA;By looking on the internet, I couldn't find any specific details about how to do so. I am using FFMPEG to generate short movies.&#xA;I saw something about stitching but that didn't really help me that much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you provide me some hints, please ?&lt;/p&gt;&#xA;" OwnerUserId="5770" LastActivityDate="2017-01-02T21:06:23.077" Title="How to generate a 360 degre video" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4453" PostTypeId="2" ParentId="4452" CreationDate="2017-01-02T21:06:23.077" Score="6" Body="&lt;p&gt;&lt;a href=&quot;https://support.google.com/youtube/answer/6178631?hl=en&quot; rel=&quot;nofollow noreferrer&quot;&gt;YouTube Help: Upload 360-degree videos&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We recommend uploading  360 videos (equirectangular format with a 2:1 aspect ratio) at a resolution of 7168x3584 or higher, up to 8192x4096.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That means the format uses &lt;a href=&quot;https://en.wikipedia.org/wiki/Equirectangular_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Equirectangular projection&lt;/a&gt; for capturing the view from all directions to a normal video format with a 2:1 aspect ratio. The projection should translate nicely to a raytracing engine with a simple mapping from pixel coordinates to the ray direction using the formula in the wiki article.&lt;/p&gt;&#xA;" OwnerUserId="3470" LastActivityDate="2017-01-02T21:06:23.077" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4454" PostTypeId="1" AcceptedAnswerId="4456" CreationDate="2017-01-02T22:12:26.490" Score="0" ViewCount="4248" Body="&lt;p&gt;I'm trying to load an array of float to a fragment shader using a uniform buffer object, but it doesn't work.&#xA;In the fragment shader I declared the following uniform block:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/// Spectrum samples.&#xA;const int samples = 31;&#xA;&#xA;layout(std140) uniform SpectralDataBlock {&#xA;&#xA;    float illuminant[samples];&#xA;    float object[samples];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then on client side in my C++ code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float illuminant[31] = {&#xA;    82.754900,91.486000,93.431800,86.682300,104.865000,117.008000,117.812000,114.861000,115.923000,108.811000,109.354000,&#xA;    107.802000,104.790000,107.689000,104.405000,104.046000,100.000000,96.334200,95.788000,88.685600,90.006200,89.599100,&#xA;    87.698700,83.288600,83.699200,80.026800,80.214600,82.277800,78.284200,69.721300,71.609100&#xA;};&#xA;&#xA;float object[31] = {&#xA;    0.051, 0.05, 0.049, 0.049, 0.049, 0.049, 0.048, 0.047, 0.045, 0.044,&#xA;    0.044, 0.044, 0.044, 0.044, 0.045, 0.047, 0.05, 0.057, 0.072, 0.109,&#xA;    0.192, 0.332, 0.486, 0.598, 0.654, 0.686, 0.7, 0.707, 0.718, 0.724,&#xA;    0.729&#xA;};&#xA;&#xA;std::copy(illuminant, illuminant + 31, spectralData);&#xA;std::copy(object, object + 31, spectralData + 31);&#xA;&#xA;blockId = glGetUniformBlockIndex(program, &quot;SpectralDataBlock&quot;);&#xA;glUniformBlockBinding(program, blockId, bindingPoint);&#xA;glGetActiveUniformBlockiv(program, blockId, GL_UNIFORM_BLOCK_DATA_SIZE, &amp;amp;blockSize);&#xA;&#xA;glGenBuffers(1, &amp;amp;bufferId);&#xA;glBindBuffer(GL_UNIFORM_BUFFER, bufferId);&#xA;glBufferData(GL_UNIFORM_BUFFER, blockSize, spectralData, GL_DYNAMIC_DRAW);&#xA;glBindBufferBase(GL_UNIFORM_BUFFER, bindingPoint, bufferId);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the data doesn't get correctly loaded. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any limitation in OpenGL ES the prevent to use float[] in an uniform buffer object? Are there any error in my code above?&lt;/p&gt;&#xA;" OwnerUserId="2237" LastActivityDate="2017-01-02T23:59:41.573" Title="OpenGL ES 3 - Uniform buffer object with float array" Tags="&lt;opengl-es&gt;&lt;uniform-buffer-object&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4455" PostTypeId="1" AcceptedAnswerId="4476" CreationDate="2017-01-02T22:23:54.210" Score="6" ViewCount="1507" Body="&lt;p&gt;It seems that in all existing graphics libraries, 3D objects are always described in terms of triangles. Drawing triangles can be implemented very efficiently on video hardware and since any 3D object can be approximated with triangles, triangles are the only basic element needed. Triangles can be represented by 3-tuples and are simple to work with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have always wondered whether other approaches have been tried. There are certain complications when approximating spherical objects with triangles. Have there been any alternative approaches to drawing spherical objects (for example, without using polygons for approximations)? What are the problems with such approaches that make using triangles the best option?&lt;/p&gt;&#xA;" OwnerUserId="5772" LastEditorUserId="231" LastEditDate="2017-01-02T23:28:55.927" LastActivityDate="2017-01-04T19:18:24.873" Title="Is there a way to draw spherical objects without triangles?" Tags="&lt;shader&gt;&lt;3d&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4456" PostTypeId="2" ParentId="4454" CreationDate="2017-01-02T23:50:23.747" Score="2" Body="&lt;p&gt;Let's review what the specification says about &lt;code&gt;std140&lt;/code&gt; layout of arrays:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If the member is an array of scalars or vectors, the base alignment and array stride are set to match the base alignment of a single array element, according to rules (1), (2), and (3), and &lt;strong&gt;rounded up to the base alignment of a &lt;code&gt;vec4&lt;/code&gt;&lt;/strong&gt;. The array may have padding at the end; the base offset of the member following the array is &lt;strong&gt;rounded up to the next multiple of the base alignment&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Emphasis added.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if you have an array of &lt;code&gt;float&lt;/code&gt;, the array stride shall be the same as the base alignment of a &lt;code&gt;vec4&lt;/code&gt;. Also, each array will be padded at the end to the base alignment of a &lt;code&gt;vec4&lt;/code&gt;. Yes, a &lt;code&gt;float[]&lt;/code&gt; takes up the same room as a &lt;code&gt;vec4[]&lt;/code&gt; of the same size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Welcome to the wonderful world of &lt;code&gt;std140&lt;/code&gt; layout.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to have a real array of floats in a UBO... well, it's best to &lt;em&gt;avoid&lt;/em&gt; wanting that. But if you have absolutely no other choice, then I suggest making it an array of &lt;code&gt;vec4&lt;/code&gt;. Obviously, the size of this array will be the size you actually want, divided by 4 and rounded up:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const int samples = 31;&#xA;const int arraySize = ((samples + 3) / 4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To fetch a single float from this array, use math:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;arrayOfVec4[index / 4][index % 4]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that OpenGL ES 3.0 does allow non-constant array indexing of &lt;code&gt;vec&lt;/code&gt; and &lt;code&gt;mat&lt;/code&gt; types. It also allows the integer operations needed to pull this off.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-01-02T23:59:41.573" LastActivityDate="2017-01-02T23:59:41.573" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4457" PostTypeId="2" ParentId="4455" CreationDate="2017-01-03T01:12:39.917" Score="6" Body="&lt;p&gt;A standard technique is to use a ray/sphere intersection test inside a pixel shader. One draws a billboard large enough cover the area the sphere could appear on the screen (or drawing a bounding cube) to reduce the number of wasted intersection tests (other geometric shapes could be used). The fragment is killed if the intersection test fails; if an intersection occurs, the appropriate depth value is calculated in the pixel shader and output for further visibility tests.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2017-01-03T01:12:39.917" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4458" PostTypeId="1" CreationDate="2017-01-03T01:38:46.377" Score="3" ViewCount="504" Body="&lt;p&gt;How can I benchmark a fragment shader? &#xA;What my shader does is basically lots of floating point operations, since it's doing some procedural stuff.&lt;/p&gt;&#xA;" OwnerUserId="5774" LastEditorUserId="231" LastEditDate="2017-01-03T21:09:41.580" LastActivityDate="2017-01-03T23:35:58.547" Title="Benchmark GLSL fragment shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4459" PostTypeId="1" CreationDate="2017-01-03T08:04:00.200" Score="1" ViewCount="40" Body="&lt;p&gt;I have an &lt;a href=&quot;https://i.stack.imgur.com/oJxCJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;image&lt;/a&gt; that I'm trying to recreate programatically using Pyx in Python. It seems that there's an overlaid circle covering the color wheel. I'm trying to see if there's a way to, given the starting and composited RGB values for each of the 8 colors shown in the image, as well as the assumption that the overlaid shape has uniform RGB color and opacity, to find said shape's color and opacity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, seeing that I'm not familiar with alpha blending formulae, I'm at a loss as to how to find this out. How could I go about this? I've done some research using the info &lt;a href=&quot;https://en.wikipedia.org/wiki/Alpha_compositing&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, but I can't seem to find a converging answer using the system of equations.&lt;/p&gt;&#xA;" OwnerUserId="5776" LastActivityDate="2017-01-04T23:11:45.333" Title="Given a composited image, is it possible to find the color and opacity of an overlaid shape?" Tags="&lt;2d&gt;&lt;blending&gt;&lt;compositing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4460" PostTypeId="1" AcceptedAnswerId="4461" CreationDate="2017-01-03T08:05:59.750" Score="1" ViewCount="266" Body="&lt;p&gt;Is it possible to directly bypass the CPU while transferring data to the GPU? could there be hardware which gives the GPU direct memory access to a data stream for real-time GPU processing and rendering?&lt;/p&gt;&#xA;" OwnerUserId="5777" LastActivityDate="2017-01-03T12:36:13.830" Title="Is it Possible to send data directly to the GPU via a custom hardware interface?" Tags="&lt;gpu&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4461" PostTypeId="2" ParentId="4460" CreationDate="2017-01-03T12:36:13.830" Score="3" Body="&lt;p&gt;On a desktop (or laptop) the GPU is connected to the PCIe bus. This gives it direct access to the physical RAM. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you map the buffer you want to fill and then read a file into that mapped memory. The OS will tell the disk drive to dump the file into the physical ram (the disk also has direct memory access), then when you go to use the mapped buffer the driver will tell the gpu to copy it into the vram. All the while the CPU never touched that bit of ram.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-01-03T12:36:13.830" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4462" PostTypeId="1" AcceptedAnswerId="4466" CreationDate="2017-01-03T14:00:44.447" Score="3" ViewCount="91" Body="&lt;p&gt;I have two high-resolution 3D objects(femur and patella) with arbitrary smooth surface and I want to find the contact point/area between those two objects. Accuracy is more important than computation time in this case, though it would be great if the algorithm has relatively low computation time. Also, it would be great if the contact between two objects can be represented with surface/point penetration distance, e.g. if distance between two points/triangles/areas &amp;lt;= &lt;code&gt;x&lt;/code&gt; distance, then there is collision, while &lt;code&gt;x&lt;/code&gt; can be non-zero. Is there any collision algorithm that satisfy above requirement?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Mbgwe.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mbgwe.jpg&quot; alt=&quot;objects&amp;#39; shape&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2687" LastEditorUserId="2687" LastEditDate="2017-01-05T01:51:50.260" LastActivityDate="2017-01-05T01:51:50.260" Title="Given two arbitrary surfaces, what is the accurate and quite fast algo to find collision within X distance?" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4463" PostTypeId="1" CreationDate="2017-01-03T14:27:45.830" Score="5" ViewCount="94" Body="&lt;p&gt;I'm a programmer working in Java and I'm not sure if this is the right place to ask this kind of question, here it goes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my program, I need to show an image (.jpeg .png etc.) based on the screen size, this image is used to compare to real size (physical) of an actual label which is later printed on a specific machine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is, for example on my machine I have the laptop screen and a '27 monitor they are both using the same resolution 1920x1080 but as you imagine if you resize any window/program/image it looks smaller on the laptop as the physical screen size is different although it has the same resolution (I imagine is because the physical size of the pixel is smaller than the ones on my monitor)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now what I would need to do is somehow always show the image on it's corect physical size (as it were printed), on any type of screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding to programming I could easily get the screens size and resize the image but, this is because the OS gives the size (it's set up size) back to the program, yet even if I have the correct size the physical screen could display the image smaller for example, as the screen's pixels are smaller.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas where to start with this?&#xA;How can I know the real physical screen size?&#xA;This seems to be more a hardware issue than graphics..&lt;/p&gt;&#xA;" OwnerUserId="5780" LastActivityDate="2018-04-20T15:57:51.577" Title="Get screen size and then resize image accordingly" Tags="&lt;pixel-graphics&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4464" PostTypeId="1" AcceptedAnswerId="4465" CreationDate="2017-01-03T14:40:39.543" Score="2" ViewCount="472" Body="&lt;p&gt;I know I can use &lt;code&gt;QueryPerformanceCounter&lt;/code&gt; for measure time for whole single frame. But can I when it comes to OpenGL draw or compute call?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I always assumed that, as on the diagram, CPU waits for GPU to finish so timer would measure approximate time or am I wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2nb3d.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2nb3d.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As seen in code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(vertexArrayObject);&#xA;timer-&amp;gt;startCounter();      &#xA;glDrawElements(GL_TRIANGLE_STRIP, indices.size(), GL_UNSIGNED_INT, 0);&#xA;glBindVertexArray(0);&#xA;estimatedRenderTime = timer-&amp;gt;getCounter();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;timer-&amp;gt;startCounter();&#xA;glDispatchCompute(width, height, 1);&#xA;estimatedRenderTime = timer-&amp;gt;getCounter();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-01-03T14:50:59.330" LastActivityDate="2017-01-03T15:04:56.997" Title="Can I use QueryPerformanceCounter to measure single draw or compute call performance?" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4465" PostTypeId="2" ParentId="4464" CreationDate="2017-01-03T15:04:56.997" Score="6" Body="&lt;p&gt;That diagram includes a CPU block titled &quot;wait for GPU&quot;. I do not see the part of your code that includes an equivalent command.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, even if it did include &lt;code&gt;glFinish&lt;/code&gt;/&lt;code&gt;glClientWaitSync&lt;/code&gt;/etc, there is no guarantee that the CPU time in any way relates to how much time the GPU spent processing it. &lt;code&gt;glFinish&lt;/code&gt; might block on a mutex, thus ending the thread's timeslice. Which means that the thread will start up sometime after that mutex is released. How long after? Who knows, but your &lt;code&gt;QueryPerformanceCounter&lt;/code&gt; call will include that time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to measure GPU time, you should use tools that actually &lt;em&gt;measure GPU time&lt;/em&gt;. For example, &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Query_Object#Timer_queries&quot;&gt;timer queries&lt;/a&gt;. You bracket some commands with &lt;code&gt;glBeginQuery(GL_TIME_ELAPSED, queryObject)&lt;/code&gt; and &lt;code&gt;glEndQuery(GL_TIME_ELAPSED)&lt;/code&gt;. Then you can &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Query_Object#Query_retrieval&quot;&gt;read the result after some time has elapsed&lt;/a&gt;. Like maybe next frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And unlike &lt;code&gt;glFinish&lt;/code&gt;, this will not absolutely murder your performance ;)&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-01-03T15:04:56.997" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4466" PostTypeId="2" ParentId="4462" CreationDate="2017-01-03T15:40:21.740" Score="2" Body="&lt;p&gt;A key search phrase is &quot;collision detection.&quot; You may find some references at this MO posting, &quot;&lt;a href=&quot;https://mathoverflow.net/a/141730/6094&quot;&gt;Intersection of Polyhedra&lt;/a&gt;.&quot;&#xA;And here is a more recent reference:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Jiménez, Juan J., and Rafael J. Segura. &quot;Collision detection between complex polyhedra.&quot; &lt;em&gt;Computers &amp;amp; Graphics&lt;/em&gt; 32.4 (2008): 402-411. (&lt;a href=&quot;http://www.sciencedirect.com/science/article/pii/S0097849308000526&quot; rel=&quot;nofollow noreferrer&quot;&gt;Journal link&lt;/a&gt;.)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Google Scholar shows this has been cited by 33 papers since.&lt;/p&gt;&#xA;" OwnerUserId="4748" LastEditorUserId="-1" LastEditDate="2017-04-13T12:58:47.570" LastActivityDate="2017-01-03T15:40:21.740" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4467" PostTypeId="2" ParentId="4459" CreationDate="2017-01-03T23:09:53.143" Score="2" Body="&lt;p&gt;You can solve the colors by solving a system of linear equations if you make few assumptions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The alpha of the color wheel is constant (i.e. same for all colors in the wheel)&lt;/li&gt;&#xA;&lt;li&gt;The beige background extends half way through the color wheel, and is constant for top and bottom halves of the image&lt;/li&gt;&#xA;&lt;li&gt;The background in the center is constant for all colors&lt;/li&gt;&#xA;&lt;li&gt;The alpha blending equation is the standard $f=c*\alpha+b*(1-\alpha)$, where $f$ = final color, $c$ = color on the wheel, $b$ = background color, $\alpha$ = alpha of the color wheel&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;If you now pick two colors with the same beige background (e.g. green and yellow), and feed them into the above alpha blending equation you get 4 equations with 4 unknowns, which you can then solve. I.e.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_1=c_1*\alpha+b_1*(1-\alpha)$$&#xA;$$f_2=c_1*\alpha+b_2*(1-\alpha)$$&#xA;$$f_3=c_2*\alpha+b_1*(1-\alpha)$$&#xA;$$f_4=c_2*\alpha+b_2*(1-\alpha)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $f_1$ &amp;amp; $f_2$ = brighter &amp;amp; darker green colors respectively, $f_3$ &amp;amp; $f_4$ = brighter &amp;amp; darker yellow colors respectively, $c_1$ &amp;amp; $c_2$ = the unknown green &amp;amp; yellow colors respectively you try to solve, $\alpha$ = alpha you try to solve, $b_1$ = beige background color, $b_2$ = unknown background color in the center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can repeat this process for all the colors, or because you solved $\alpha$ you can use this information to solve the rest of the colors simply by:&#xA;$$c=\frac{f-(b_1*(1-\alpha))}{\alpha}$$&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-01-04T23:11:45.333" LastActivityDate="2017-01-04T23:11:45.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4468" PostTypeId="2" ParentId="4458" CreationDate="2017-01-03T23:35:58.547" Score="3" Body="&lt;p&gt;A lot goes in to benching performance. I think most would agree that measuring the frame time of your application is the best metric you can gather about how well you're doing at run-time. An easy way to &quot;bench&quot; your shaders in your engine/environment is to simply record frame times for a fixed duration with a fixed view and fixed scene. Then save those frame times out to a CSV and plot them in something like Excel. This should give you a good idea of how much your frame time is fluctuating and if you're actually hitting your frame time targets most of the time. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However if you want to see if your shaders are properly utilizing the GPU you may want to dig into your application with something like &lt;a href=&quot;http://developer.amd.com/tools-and-sdks/graphics-development/gpu-perfstudio/&quot; rel=&quot;nofollow noreferrer&quot;&gt;AMD's GPU Perf Studio&lt;/a&gt; or &lt;a href=&quot;https://developer.nvidia.com/nvidia-nsight-visual-studio-edition&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nvidia's NSight&lt;/a&gt; tool. I'm more familiar with Perf Studio but it can give you a static shader analysis to see if you're actually taking full advantage of the GPU or if you're overloading certain registers. &lt;/p&gt;&#xA;" OwnerUserId="5715" LastActivityDate="2017-01-03T23:35:58.547" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4469" PostTypeId="1" AcceptedAnswerId="4471" CreationDate="2017-01-04T06:55:00.287" Score="2" ViewCount="817" Body="&lt;p&gt;Does any of their rendering techniques involve rendering an area at a higher resolution just to scale it down in order to mitigate artifacts? I know they use ray methods rather than rasterization however ray methods still have artifacts even when done with a ton of rays.. right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I noticed a few moments in the film Moana that seemed to be poorly rendered because small details seemed fuzzy and sorta pixelated. Especially around the edges of a figure that was in focus with a slightly blurred background. Could they have used supersampling on those scenes to decrease the issue?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2041" LastEditDate="2017-01-05T10:38:53.840" LastActivityDate="2017-01-05T10:38:53.840" Title="Do animation studios like Pixar, Dreamworks, and Disney use super-sampling?" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;supersampling&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4470" PostTypeId="1" AcceptedAnswerId="4474" CreationDate="2017-01-04T09:17:56.527" Score="13" ViewCount="1289" Body="&lt;p&gt;From my understanding, the specular color usually refers to the amount of light that is reflected when the surface is lit at normal incidence, and is noted $F_0$ or $R_0$. Moreover, for non metal materials, this value is calculated from the index of refraction of the material $n$ with the formula &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;noreferrer&quot;&gt;deduced from the Fresnel equations&lt;/a&gt; (in which 1 is the index of refraction of air or void):&#xA;$$F_0 = \frac{(n - 1)^2}{(n + 1)^2} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to this &lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_refractive_indices#List&quot; rel=&quot;noreferrer&quot;&gt;list of refractive indices on Wikipedia&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Solid materials typically have $n$ between 1.46 (&lt;a href=&quot;https://en.wikipedia.org/wiki/Fused_quartz&quot; rel=&quot;noreferrer&quot;&gt;fused quartz&lt;/a&gt;) and 2.69 (&lt;a href=&quot;https://en.wikipedia.org/wiki/Moissanite&quot; rel=&quot;noreferrer&quot;&gt;Moissanite&lt;/a&gt;). That would mean an $F_0$ between 0.03 and 0.21.&lt;/li&gt;&#xA;&lt;li&gt;Liquids typically have $n$ between 1.33 (water) and 1.63 (&lt;a href=&quot;https://en.wikipedia.org/wiki/Carbon_disulfide&quot; rel=&quot;noreferrer&quot;&gt;carbon disulfide&lt;/a&gt;). That would mean an $F_0$ between 0.02 and 0.057, if I am not mistaken.&lt;/li&gt;&#xA;&lt;li&gt;Gases typically have $n \approx 1$, so I guess we can safely assume an $F_0$ of 0.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;All these values are very low; even crystals with high refractive indices like diamond ($F_0=0.17$) and moissanite ($F_0=0.21$) hardly exceed 20%. Yet most metals have $F_0$ values above 50%. Moreover, I have read multiple times that the formula mentioned above doesn't apply for metals (which can be easily confirmed by trying to use it and see completely wrong results), but I haven't found any further explanation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What phenomenon explains this difference? How can I calculate $F_0$ for a metal (in particular if the medium it is in contact with has an IoR different than 1, like water)?&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2017-01-04T15:25:51.027" Title="What explains the high specularity of metals?" Tags="&lt;physics&gt;&lt;refraction&gt;&lt;fresnel&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4471" PostTypeId="2" ParentId="4469" CreationDate="2017-01-04T09:43:03.930" Score="7" Body="&lt;p&gt;Super-sampling for ray-tracing doesn't just mean rendering an area at higher resolution and then downscaling the finished image: in fact, this simplest super-sampling technique is really not effective enough for high-quality production rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a production ray-tracer, super-sampling means sending more than one primary ray per pixel (16 primary rays per pixel is a good average) and then using signal reconstruction techniques (i.e. not just averaging) to compute a colour for each pixel of the image. Using lots of primary rays doesn't just help to avoid aliasing (jaggies) from when polygons partially cover pixels; it also helps to smooth over noise added in shading, such as when sampling global illumination or fuzzy reflections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition, super-sampling by sending more rays lets you jitter the sample positions to avoid the artefacts you get from regular sampling. It also lets you use the results of previously traced primary rays to decide where to put more samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, the simplest &lt;em&gt;adaptive sampling&lt;/em&gt; algorithm is contrast based: within each pixel, you measure the contrast among all of the primary rays. Pick the pixel(s) with the highest contrast, and shoot more primary rays in those pixels. You can also use the contrast between samples to choose where in the pixel to shoot new primary rays, but then you have to use a more complex reconstruction algorithm to avoid bias in your result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you can find a frame-grab of the particular details you noticed, it would be possible to go discuss those in more detail. It's entirely possible that some artefacts are caused by a particular technique, and aren't related to super-sampling at all.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2017-01-05T10:25:39.180" LastActivityDate="2017-01-05T10:25:39.180" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4472" PostTypeId="2" ParentId="4470" CreationDate="2017-01-04T13:56:51.150" Score="2" Body="&lt;p&gt;The refractive index is related to the speed at which light travels through the medium, and only applies to materials which are at least partially transparent. Metals are electrically conductive, so they are opaque, so light can't travel through them at any speed, so they don't have a refractive index. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why Fresnel's law doesn't apply: it's for predicting what fraction of the incoming light is reflected &lt;em&gt;vs.&lt;/em&gt; transmitted. No light is transmitted through the material: everything that isn't absorbed is reflected, either as a specular reflection (if the surface is smooth) or as diffuse scatter (if the surface is rough).&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-01-04T13:56:51.150" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4473" PostTypeId="2" ParentId="4463" CreationDate="2017-01-04T14:12:05.507" Score="4" Body="&lt;p&gt;The OS does not, in many or most cases, know the physical screen size! Often the only thing you can glean is the make and model, sometimes not even that. So if you do not want to have a database then the best you can do is ask your user.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also some interesting corner cases. What do you do if the monitor is in fact a projector? What do you do in multi monitor setups? What if the image is halfway between 2 monitors? What do you do if the operator is using pixel zoom for accessibility reasons? What do you do if the image is shown on 2 monitors at the same time? What do you do if the monitor is huge, like one used in a conference room and your image turns out to be very small in comparison (like 4 by 4 pixels)? ...&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-01-04T16:32:36.503" LastActivityDate="2017-01-04T16:32:36.503" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4474" PostTypeId="2" ParentId="4470" CreationDate="2017-01-04T15:15:11.770" Score="12" Body="&lt;p&gt;&lt;strong&gt;Warning&lt;/strong&gt;: I am not a physicist.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Dan Hulme already explained, light can't travel through metals, so dealing with IOR is a lot more... &lt;em&gt;complex&lt;/em&gt;. I will answer why that happens and how to calculate the reflection coefficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: Metals are filled with free electrons. Those electrons react to external fields and reposition until electrostatic equilibrium is met (the electric field is zero inside a conductor in electrostatic equilibrium). When electromagnetic waves hit a metallic surface, the free electrons move until the field that they create cancels the field of the incoming wave. Those electrons grouped together radiate a wave going out nearly the same as the one that hit the surface (i.e. with very low attenuation). How much is attenuated depends on the material properties. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;From this explanation it is clear that conductivity is a key part of the high reflection coefficient on metals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Math-wise, what you are missing is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Refractive_index#Complex_refractive_index&quot; rel=&quot;noreferrer&quot;&gt;complex index of refraction&lt;/a&gt;. On good conductors, such as metals, the complex term of the IOR is relevant and key for explaining this phenomena.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Practically&lt;/strong&gt;, in rendering, achieving good metal parameters is more visual based. Artists adjust to their preference until it looks believable. Often you see a &lt;em&gt;metalness&lt;/em&gt; parameter with specific handling for materials marked as metal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Involved answer&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The complex index of refraction can be seen if we use Ohm's Law $J = \sigma \vec{E}$, which holds for conductors, on the &lt;a href=&quot;https://en.wikipedia.org/wiki/Maxwell&amp;#39;s_equations#Formulation_in_SI_units_convention&quot; rel=&quot;noreferrer&quot;&gt;Ampère-Maxwell&lt;/a&gt; equation using sinusoidal waves $\vec{E} = e^{i\omega t}$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\vec{\nabla} \times \vec{H} = \sigma\vec{E} + \frac{\partial \vec{D}}{\partial t} = \sigma \vec{E} + i\omega \epsilon \vec{E}&#xA;$$&#xA;$$&#xA; = i\omega \left( \epsilon - i \frac{\sigma}{\omega} \right)\vec{E} = i \omega \epsilon_m\vec{E} &#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note how we can interpret that whole term as a complex permittitivity $\epsilon_m$ and that $\sigma$ is the conductivity of the material. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This affects the IOR, as its definition is given by:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;  n' = \sqrt{\frac{\epsilon_m}{\epsilon_0}} = \sqrt{\frac{\left(\epsilon - i \sigma / \omega\right)}{\epsilon_0}} = n_{\text{real}} + in_{\text{img}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This shows how $n'$ can be complex. Also, note how very good conductors have a relevant complex term, as $\sigma \gg \epsilon_0 \omega$. Since it would take a lot, I will skip some steps with a &lt;a href=&quot;http://www.patarnott.com/atms749/pdf/FresnelEquations.pdf&quot; rel=&quot;noreferrer&quot;&gt;reference&lt;/a&gt;, page 27: it can be shown that, since $\sigma \gg \epsilon_0\omega$, (we are dealing with $\omega$ of the visible spectrum):&#xA;$$&#xA;  n_{\text{real}} \approx n_{\text{img}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and reflection from metals with normal incidence, from a medium with IOR $n$, given that $n' \gg n$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;  R = \frac{(n_{\text{real}} - n)^2 + n_{\text{img}}^2}{(n_{\text{real}} + n)^2 + n_{\text{img}}^2} \approx 1&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Agreeing that a good conductor is, in general, a good reflector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The famous &lt;em&gt;Introduction to Electrodynamics&lt;/em&gt; from Griffiths, pages 392-398, explains this and a lot more in a similar fashion.&lt;/p&gt;&#xA;" OwnerUserId="5519" LastActivityDate="2017-01-04T15:15:11.770" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4475" PostTypeId="2" ParentId="4470" CreationDate="2017-01-04T15:25:51.027" Score="6" Body="&lt;p&gt;Look at the &lt;a href=&quot;http://refractiveindex.info/&quot; rel=&quot;noreferrer&quot;&gt;refractive index&lt;/a&gt; of several metals. They are all complex numbers and the math does work out when you put this into the fresnel equation: you get the expected high reflectivity at all angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also subtle color shifts because the index depends on wavelength. This is actually used in rendering but it is not common. The function is sometimes named &quot;conductor fresnel&quot; but it's really the same fresnel equation with complex numbers.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-01-04T15:25:51.027" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4476" PostTypeId="2" ParentId="4455" CreationDate="2017-01-04T17:44:25.723" Score="2" Body="&lt;p&gt;Raytracing is a great way to render spheres as Daniel mentioned.  Below is a screenshot of a raytraced scene I made but lost the source code to unfortunately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ee8T2.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ee8T2.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are looking to render smooth / non polygonal objects in general, it's not always easy, desired or even possible to do an analytical solve for ray vs object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For these cases, a useful technique is something called &quot;ray marching&quot; (also called sphere tracing).  In ray marching, you take steps down a ray and at each point ask if you are inside or outside of the object (alternately, above or below).  When the answer changes, you know that the intersection of the ray occurred between the current and last point you tested on the ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you know the intersection occured between those two points, you can do various things to try and find the actual intersection, depending on quality needs vs computation costs.  Some common techniques:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Just accept either the current or last point tested as the intersection point (fastest)&lt;/li&gt;&#xA;&lt;li&gt;Binary search the range to get a better answer&lt;/li&gt;&#xA;&lt;li&gt;If you have a function which gives you an (estimated) signed distance from a point to the surface, instead of just an &quot;inside vs outside&quot; test, you can do a linear interpolation between the last point and the current point to find where the &quot;0&quot; is, and take that as your intersection point.  This is what I've had most success with personally.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Note that you can get an estimated signed distance numerically using finite differences and using the gradient. Check this link for more info on that: &lt;a href=&quot;http://www.iquilezles.org/www/articles/distance/distance.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.iquilezles.org/www/articles/distance/distance.htm&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find more info about finite difference methods here:&#xA;&lt;a href=&quot;http://blog.demofox.org/2015/08/02/finite-differences/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.demofox.org/2015/08/02/finite-differences/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With a signed distance estimating function, you can also use the gradient to get the normal, which is required for shading.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is a ray marched surface that is defined as a function $z=f(x,y)$, and is a screenshot of this webgl2 interactive demo: &lt;a href=&quot;http://demofox.org/LeastSquaresSurfaceFit.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://demofox.org/LeastSquaresSurfaceFit.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bK8KL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bK8KL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternately, here's a shadertoy which ray marches a cubic bezier rectangle - it's cubic on each axis, so is degree(3,3): &lt;a href=&quot;https://www.shadertoy.com/view/4tfXz2&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/4tfXz2&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/O7ORO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/O7ORO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Back to talking about rendering spheres, you can also just rasterize a sphere as a 2d circle (possibly distorted by a view / projection matrix type setup in &quot;2d&quot;), and then shade it as if it was a 3d object.  It can also work for non spheres, and you see this a lot with renderings of metaballs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is a screenshot of this shadertoy which renders metaballs: &lt;a href=&quot;https://www.shadertoy.com/view/4sXXWM&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/4sXXWM&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CJoC4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CJoC4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, I wanted to mention that all of these techniques are compatible with traditional renderers as well.  Like Daniel said, you can draw a screen space billboard that is larger than the shape (or draw a world space scaled and oriented unit cube that contains it) and then you do your raytracing, raymarching, or rasterization / fake 3d lighting within the pixel shader, to mix these techniques with standard rasterization rendering methods.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-01-04T19:18:24.873" LastActivityDate="2017-01-04T19:18:24.873" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4477" PostTypeId="1" AcceptedAnswerId="4478" CreationDate="2017-01-04T22:39:42.020" Score="4" ViewCount="273" Body="&lt;p&gt;Is there currently anyone working on a link between these two fields? I have a hunch that, due to the repetitive nature of sampling, there could be a good bit to gain in the area of ray tracing using Machine Learning techniques, but I'm interested in finding out more and getting involved if there's a group out there doing this.&lt;/p&gt;&#xA;" OwnerUserId="5787" LastActivityDate="2017-01-05T03:41:43.930" Title="Machine Learning and Computer Graphics" Tags="&lt;optimisation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4478" PostTypeId="2" ParentId="4477" CreationDate="2017-01-05T03:36:09.997" Score="5" Body="&lt;p&gt;A group from UC Santa Barbara published the Siggraph 2015 paper &lt;a href=&quot;http://cvc.ucsb.edu/graphics/Papers/SIGGRAPH2015_LBF/&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Machine Learning Approach for Filtering Monte Carlo Noise&lt;/a&gt; describing a technique which trains a neural network to select filtering parameters for path tracing. The paper details the structure of the neural network, the filter parameters used and how several secondary features are pre-computed to feed the neural network.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2500" LastEditDate="2017-01-05T03:41:43.930" LastActivityDate="2017-01-05T03:41:43.930" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4479" PostTypeId="1" AcceptedAnswerId="4482" CreationDate="2017-01-05T17:06:19.973" Score="8" ViewCount="3956" Body="&lt;p&gt;How do you use textures with direct state access in OpenGL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have the following in my code, which seems to work:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint textureHandle;&#xA;glGenTextures(1, &amp;amp;textureHandle);&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D, textureHandle);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, when I replace it with the following everything just becomes black:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint textureHandle;&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glCreateTextures(GL_TEXTURE_2D, 1, &amp;amp;textureHandle);&#xA;glTextureImage2DEXT(textureHandle, GL_TEXTURE_2D, 0, GL_RGBA8, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, image_data);&#xA;glTextureParameteri(textureHandle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5802" LastEditorUserId="2654" LastEditDate="2017-01-07T16:03:11.527" LastActivityDate="2017-01-07T16:03:11.527" Title="How to do texturing with OpenGL direct state access?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4480" PostTypeId="1" AcceptedAnswerId="4481" CreationDate="2017-01-05T19:49:27.193" Score="4" ViewCount="133" Body="&lt;p&gt;What black magic is behind &lt;a href=&quot;https://blender.stackexchange.com/a/46319/13953&quot;&gt;this&lt;/a&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1frCY.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1frCY.gif&quot; alt=&quot;rigged finger&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Starting from a pile of polygons, a skeleton, and an initial conformation, how is a new conformation turned into a new pile of polygons?&lt;/p&gt;&#xA;" OwnerUserId="5750" LastEditorUserId="-1" LastEditDate="2017-04-13T12:57:46.990" LastActivityDate="2017-01-05T22:03:06.623" Title="How does a rigged model work?" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;animation&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4481" PostTypeId="2" ParentId="4480" CreationDate="2017-01-05T22:03:06.623" Score="5" Body="&lt;p&gt;The magic is that the mesh is attached to the skeleton.  In it's simplest form, this is done by assigning each vertex to a bone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When a vertex is assigned to a bone, that means that it will always keep the same position relative to that bone's position, and orientation (normal, tangent, bitangent aka the bone's local X,Y,Z axis) as the bone moves as directed by the animation data, physics impulses, or whatever else driving it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you might expect, some triangles will have vertices that belong to different bones.  When this happens, since the triangle is made up of those vertices, the triangle will stretch or squish as the bones move.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The link you mention explains a way to set up the vertices for this specific type of movement such that the vertices stretch and squish in realistic and well behaved ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In modern games, vertices are usually attached to multiple bones with a weight per bone so that each vertex is actually affected by the movement of multiple bones.  This gives a more natural and organic look to the mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This answer only scratches the surface though, and this is a very deep topic which has many sub topics that are active areas of research!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to read more about skeletal animation, this link is a good starting point:&#xA;&lt;a href=&quot;http://blog.demofox.org/2012/09/21/anatomy-of-a-skeletal-animation-system-part-1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.demofox.org/2012/09/21/anatomy-of-a-skeletal-animation-system-part-1/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-01-05T22:03:06.623" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4482" PostTypeId="2" ParentId="4479" CreationDate="2017-01-05T22:42:40.700" Score="11" Body="&lt;p&gt;You still have to bind the desired texture to the texture unit to use it for rendering. In your current code, you're not specifying which texture to use for rendering, so the GL driver doesn't know which one you want to use and is defaulting to &quot;no texture&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a few ways to bind a texture. You can keep using &lt;code&gt;glActiveTexture&lt;/code&gt;+&lt;code&gt;glBindTexture&lt;/code&gt; as in your non-DSA code, or you can use either &lt;a href=&quot;http://docs.gl/gl4/glBindTextures&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glBindTextures&lt;/code&gt;&lt;/a&gt; or &lt;a href=&quot;http://docs.gl/gl4/glBindTextureUnit&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glBindTextureUnit&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, with &lt;code&gt;glBindTextureUnit&lt;/code&gt;, do this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindTextureUnit(0, textureHandle);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first parameter is the texture unit to bind to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, instead of using &lt;code&gt;glTextureImage2DEXT&lt;/code&gt; (which is from the old and deprecated EXT_direct_state_access extension), it's probably better to stick with core OpenGL calls. You can initialize the texture by using &lt;a href=&quot;http://docs.gl/gl4/glTexStorage2D&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glTextureStorage2D&lt;/code&gt;&lt;/a&gt; to allocate the memory and set the format, then &lt;a href=&quot;http://docs.gl/gl4/glTexSubImage2D&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glTextureSubImage2D&lt;/code&gt;&lt;/a&gt; to upload the data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Direct_State_Access#Changes_from_EXT&quot; rel=&quot;noreferrer&quot;&gt;Here's an article with more on the differences&lt;/a&gt; between EXT_direct_state_access and the newer core version of the functionality, if you're interested.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2017-01-06T03:12:18.397" LastActivityDate="2017-01-06T03:12:18.397" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4483" PostTypeId="1" CreationDate="2017-01-06T04:23:02.390" Score="6" ViewCount="277" Body="&lt;p&gt;I apologize if my methods seem way off because this is my first time trying to build a path tracer and I'm struggling quite a bit. Currently, I am trying to mimic the &quot;mix shader&quot; node in Blender 3D that combines two different shaders. I would like to add this functionality to my path tracer because it would allow me to make a plastic-like material. Reading through a few explanations, it seems it takes a probabilistic approach to picking one or the other when a ray hits the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a rendering of an object with a 50/50 mix of ideal reflection and ideal diffuse at 80 samples per pixel:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/yAi7i.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yAi7i.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something is just off about it. Especially those weird underside highlights on the leg extending farthest to the left. I have a strong feeling I'm implementing it wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a pseudo implementation of the path tracing part. It uses explicit light sampling. Based off of smallpt path tracer.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;rayColor(ray r, depth, int E=1)&#xA;{&#xA;    if(r doesn't hit triangle)&#xA;        return 0&#xA;    if(r hit is a light)&#xA;    {&#xA;       if(E)&#xA;         return light_emission&#xA;       else&#xA;         return 0&#xA;    }&#xA;&#xA;    vector x = r.origin + r.direction*t // x is point where r hit tri&#xA;    vector n = normal where ray hit triangle&#xA;    n.normalize()&#xA;    vector nl = n.dot(r.d) &amp;lt; 0 ? n : n*(-1) // properly orient normal&#xA;&#xA;    if(++depth &amp;gt; 5) return 0 // max bounces&#xA;&#xA;    float triangle_area   = area of emitting triangle&#xA;    vector x_light_random = random point on emitting triangle&#xA;    vector light_normal   = normal of emitting triangle&#xA;&#xA;    vector d = x_light_random = x_converted;&#xA;&#xA;&#xA;    if(light_normal.dot(d) &amp;gt; 0) light_normal *= -1; // make it emit&#xA;                                                    // both sides&#xA;&#xA;    object_normal.normalize();&#xA;    light_normal.normalize();&#xA;&#xA;    BRDF = 1/PI // perfect diffuse&#xA;    light_emitted = 1 // emission of 1&#xA;    vector light_out = 0&#xA;    if(ray starting at x towards d hits light (i.e. not in shadow))&#xA;    {&#xA;         light_out = BRDF*light_emitted*(object_normal.dot(d))*&#xA;                            (-1*light_normal.dot(d)*triangle_area)/&#xA;                            (d.length*d.length*d.length*d.length)&#xA;    }&#xA;    vector direct_light = color_of_object_triangle*light_out;&#xA;&#xA;&#xA;&#xA;  //----SPECULAR-----&#xA;  vector d2 = r.dir-n*2*n.dot(r.dir); // ideal reflection&#xA;  vector light_color = 1 // white since dialectics don't change spec&#xA;  vector specular = light_color*rayColor(createRay(x, d2),depth)&#xA;&#xA;  float P = 0.5; // 50/50 chance of mirror/diffuse&#xA;  if(erand(Xi) &amp;lt; P)&#xA;      return direct_light/P&#xA;  else&#xA;      return spec/(1-P)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Thank you to anyone who can offer me some direction! Again, sorry if this is really convoluted. I've made it so far and I'm about to give up, but I feel like I'm reaaaally close. &lt;/p&gt;&#xA;" OwnerUserId="5764" LastEditorUserId="231" LastEditDate="2017-01-07T12:17:46.577" LastActivityDate="2017-01-07T12:17:46.577" Title="Mix shader looks wrong on my path tracer" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;shader&gt;&lt;3d&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4484" PostTypeId="1" CreationDate="2017-01-06T13:33:35.830" Score="6" ViewCount="802" Body="&lt;h1&gt;THE SHORT VERSION&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;In my fragment shader I'm reading (using texelFetch) multiple times the same texel from a texture (created by another fragment shader) and write it to the output render buffer. After a few read operations on the texel a fault occurs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The texture and my rendered image have a size of (n*256) x (m*192) pixel/texel. In the first instance (texel [0,...,255]x[0,...,191]) the texture contains a human.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the minimal code of the fragment shader which should copy the human:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;// output render buffer&#xA;layout(location = 5) out float depth;&#xA;&#xA;in      vec4    gl_FragCoord;&#xA;&#xA;uniform sampler2DRect GradientsTexture;&#xA;&#xA;&#xA;void main(){&#xA;&#xA;    ivec2 pos       = ivec2(mod(gl_FragCoord.x,256),  mod(gl_FragCoord.y,192));&#xA;    vec4  gradient  = texelFetch(GradientsTexture, pos);&#xA;    depth           = gradient.x;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After execution the output looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iqYUW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iqYUW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, there is an Problem after the third instance. Additionally I noticed, that the position of the black boxe/stripes varies randomly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any idea how this problem could be fixed?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;THE LONG VERSION&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Basically my problem deals with texture access in OpenGL's Fragment Shader. First I'll describe the background of the problem and what I want to accomplish. Afterwards I'll explain the point at which my problem arises. And finally I'll present a few lines of code followed by my actual question. If you're not interested in the details you can skip directly to the problem. But maybe the detailed explanation is useful for others.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;The Background&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Basically I want to compute the partial derivatives of a rendered depth image according to equation (15) in this paper &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.297.3923&amp;amp;rep=rep1&amp;amp;type=pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Wei, Xiaolin, Peizhao Zhang, and Jinxiang Chai. &quot;Accurate realtime full-body motion capture using a single depth camera.&quot; ACM Transactions on Graphics (TOG) 31.6 (2012): 188.&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Derivatives&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this paper there are two important derivatives which has to be computed: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1. The Parameter Gradient&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The change of depth value $D$ with respect to a parameter $q_k$ which moves the skeleton:&#xA;$$ \frac{\partial D_c}{\partial \vec{q}} = \left[\frac{\partial D_c}{\partial q_1},\; ...,\; \frac{\partial D_c}{\partial q_k},\;...\right] $$&#xA;But since I'm using multiple cameras, I've different depth images of the same model. In the example here two cameras are used ($c=1,2$) and therefore we have $D_1$ and $D_2$.&#xA;This gradients can be seen in the image below. I'll refer to this image as &lt;em&gt;Gradient-Texture&lt;/em&gt; $G$. Here we see multiple instances of the same model. The first instance (0) in the upper left corner is in contrast to the other instances not a derivative but the raw depth value $D_1$. The second instance is the depth change with respect to a rotation of the whole model around the x-axis (which is  parameter $q_1$)($q_7$ is the angle of the upper leg). After all $\frac{\partial D_1}{\partial q_k}$ are computed we proceed with $c=2$ and see $D_2$ and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UJEzd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UJEzd.png&quot; alt=&quot;Absolute value of the depth gradient&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Figure 1: The raw depth images and depth gradients with respect to parameters. (referred to as Gradient-Texture $G$ )&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2. The Image Gradient&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image gradient is well known and has to be computed by applying the convolution operator $\left[-1/2, 0, +1/2 \right]$ to $D_1$ and $D_2$. By doing this in x and y direction we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \nabla D_c = \left[ \frac{\partial D_c}{\partial x}, \frac{\partial D_c}{\partial y} \right]&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Summation&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end I have to sum up the two derivatives:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \nabla D_c \frac{\partial \vec{x}}{\partial \vec{q}} + \frac{\partial D_c}{\partial \vec{q}} \;. \;\; (1)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $\frac{\partial \vec{x}}{\partial \vec{q}}$ is the change of the image coordinates of a projected point on the model with respect to a parameter. This becomes a constant for a orthographic projection as it is applied here.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;The Problem&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To compute the sum in equation (1) i need to add the gradient to each $\frac{\partial D_c}{\partial q_k}$. Therefore I need to access $D_c$ in each instance, compute the derivative and add it to the instance $\frac{\partial D_c}{\partial q_k}$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is done in a Fragment Shader which has as input the figure 1 (as GL_TEXTURE_RECTANGLE). Since each instance $i$ does not know where to find the raw depth image ($D_c$) in the texture, an additional input with the x- and y-offset from the current pixel/texel position to the according pixel/texel position of the raw depth image is provided: Let's call it $O_x$ and $O_y$. So to get the coordinates of the raw depth image $D_c$ in the Gradient-Texture $G$, we do:&#xA;$$&#xA;x_D  =  x + O_x(x,y)\;\, \;\;\;\;\;\;\;\;  \\&#xA;y_D  =  y + O_y(x,y)\;, \;\;\; (2)$$&#xA;where $x$, $y$ are the current pixel coordinates (gl_fragCoord) in the Fragment Shader and $x_D$ is the x-coordinate of the raw depth image $D_c$ assigned to the Gradient-Texture at $(x,y)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Offset-Texture $O_x$ is shown in the image below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zFcmq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zFcmq.png&quot; alt=&quot;Offset-Texture&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Figure 2: The Offset-Texture which transforms the coordinates from a point of each instance in the Gradient-Texture to the coordinates of the raw depth image in the Gradient-Texture.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I do the computation stated in equation (2) I obtain the Base-Coordinates $x_D$, as I called them. They are shown in the image below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dLMrk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dLMrk.png&quot; alt=&quot;Position Offset&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Figure 3: The Base-Position $x_D$ of the raw depth image for each instance.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And now when I access the values of the Gradient-Texture with the computed Base-Coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$D_c = G(x_D,y_D)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get a fault. The result is shown in Figure 4 below. I would expect each instance to show it's assigned raw depth $D_c$. But as you see there are black artefacts. Afterwards I would have to compute the gradient image $\nabla D_c$ but I stopped here since there is obviously a fault.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zSJEu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zSJEu.png&quot; alt=&quot;Raw Depth accessed using Base-Coordinates&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Figure 4: Raw depth $D_c$ extracted from the Gradient-Texture $G$ using the computed Base-Coordinates&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;The Code&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To provide useful feedback I assume you'll need the Code. In the following you'll find the Fragment Shader code. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The variable&#xA;    GradientsTexture&#xA;contains $G$ and&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GradientsOffset&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;contains $O_x$ and $O_y$.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;// locations of the output data&#xA;layout(location = 5) out float  depth2;&#xA;&#xA;in      vec4    gl_FragCoord;&#xA;&#xA;uniform sampler2DRect GradientsTexture;&#xA;uniform sampler2DRect GradientsOffset;&#xA;&#xA;void main(){&#xA;&#xA;    ivec2 pos       = ivec2(gl_FragCoord.x-0.5,  gl_FragCoord.y-0.5);&#xA;    ivec2 offset    = ivec2(texelFetch(GradientsOffset, pos).xy);&#xA;    ivec2 basePos   = pos+offset;&#xA;&#xA;&#xA;    vec4  gradient  = texelFetch(GradientsTexture, basePos);&#xA;&#xA;    depth2 = gradient.x;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;The Question&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;And finally my question: Does anyone knows where these artefacts come from? As you saw in the figures above, the steps before give corret results. Only the access to the Gradient-Texture with &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4  gradient  = texelFetch(GradientsTexture, basePos);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;causes unexpected results as shown in figure 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance and sorry for the long explanation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cheers,&#xA;Christian Bloch.&lt;/p&gt;&#xA;" OwnerUserId="5399" LastEditorUserId="5399" LastEditDate="2017-01-09T12:56:58.447" LastActivityDate="2017-04-19T19:19:22.147" Title="OpenGL texelFetch causes black stripes" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;fragment-shader&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4485" PostTypeId="2" ParentId="4483" CreationDate="2017-01-06T16:10:43.373" Score="4" Body="&lt;p&gt;As suggested in the comments, I created an exact scene in Blender using the same .obj. After adding a mix shader node and setting one side to diffuse and the other to a perfect mirror, you can see that the results are almost identical. This would indicate that my implementation is correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a side by side comparison. Mine is on the left, Blender's is on the right:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qWziH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qWziH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5764" LastActivityDate="2017-01-06T16:10:43.373" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4486" PostTypeId="1" AcceptedAnswerId="4494" CreationDate="2017-01-06T16:37:47.590" Score="6" ViewCount="1240" Body="&lt;p&gt;Recently I asked a question regarding how to mix a glossy and diffuse shader in my path tracer: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4483/mix-shader-looks-wrong-on-my-path-tracer&quot;&gt;Mix shader looks wrong on my path tracer&lt;/a&gt;. &#xA;I thought it was incorrect, but a comparison between mine and Blender's seems correct. However, now I am lost in how I would approach making the surface of a mirror look rough as this example shows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lBTPz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lBTPz.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have done some research, and discovered that there are different types of reflectance models such as Beckmann and GGX. I've found some explanations of how to find the BRDF such as this site: &lt;a href=&quot;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Specular BRDF&lt;/a&gt;, but I can't find any explanation on how to do the reflection ray with explicit lighting. As shown in the pseudo code of my path tracer (below), for every object I shoot a ray towards a light and use the surface transport rendering equation to incorporate the BRDF. I am assuming this is where the GGX/Beckmann BRDF would be plugged in. (I'm guessing it's not quite that simple though and some probability must be involved). What really gets me though is that reflection ray. For diffuse it's easy because I just send off a random ray anywhere in the hemisphere of the surface normal. However, for specular, there's a more sharp bump in the BRDF. How would I translate that into a reflected ray? If I just jittered the ideal reflection ray a little, that wouldn't relate to how the microfacets are modeled in the GGX/Beckmann reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Explicit lighting equation from Peter Shirley's Realistic Ray Tracing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\large L_S(\mathbf x,\mathbf k_o)\approx\frac{\rho(\mathbf k_i,\mathbf k_o)L_e(\mathbf x',\mathbf x-\mathbf x')v(\mathbf x,\mathbf x')\cos\theta_i\cos\theta'}{p(\mathbf x')\left\lVert \mathbf x-\mathbf x'\right\rVert^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $p(\mathbf x)$ is the density function of the light triangle $1/\text{Area}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\mathbf x'$ is a random point on the light triangle&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\mathbf x$  is the hit point on the object&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cosines are the angles between the light's normal and the light ray, and the object's normal and the light ray&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\rho$ is the BRDF ($1/\pi$ for ideal diffuse)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And $v$ is either $1$ or $0$ depending on if it's in shadow&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pseudo code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;rayColor(ray r, depth, int E=1)&#xA;{&#xA;    if(r doesn't hit triangle)&#xA;        return 0&#xA;    if(r hit is a light)&#xA;    {&#xA;       if(E)&#xA;         return light_emission&#xA;       else&#xA;         return 0&#xA;    }&#xA;&#xA;    vector x = r.origin + r.direction*t // x is point where r hit tri&#xA;    vector n = normal where ray hit triangle&#xA;    n.normalize()&#xA;    vector nl = n.dot(r.d) &amp;lt; 0 ? n : n*(-1) // properly orient normal&#xA;&#xA;    if(++depth &amp;gt; 5) return 0 // max bounces&#xA;&#xA;    float triangle_area   = area of emitting triangle&#xA;    vector x_light_random = random point on emitting triangle&#xA;    vector light_normal   = normal of emitting triangle&#xA;&#xA;    vector d = x_light_random = x_converted;&#xA;&#xA;&#xA;    if(light_normal.dot(d) &amp;gt; 0) light_normal *= -1; // make it emit&#xA;                                                    // both sides&#xA;&#xA;    object_normal.normalize();&#xA;    light_normal.normalize();&#xA;&#xA;    BRDF = 1/PI // perfect diffuse&#xA;    light_emitted = 1 // emission of 1&#xA;    vector light_out = 0&#xA;    if(ray starting at x towards d hits light (i.e. not in shadow))&#xA;    {&#xA;         light_out = BRDF*light_emitted*(object_normal.dot(d))*&#xA;                            (-1*light_normal.dot(d)*triangle_area)/&#xA;                            (d.length*d.length*d.length*d.length)&#xA;    }&#xA;    vector direct_light = color_of_object_triangle*light_out;&#xA;&#xA;&#xA;&#xA;  //----SPECULAR-----&#xA;  vector d2 = r.dir-n*2*n.dot(r.dir); // ideal reflection&#xA;  vector light_color = 1 // white since dialectics don't change spec&#xA;  vector specular = light_color*rayColor(createRay(x, d2),depth)&#xA;&#xA;  float P = 0.5; // 50/50 chance of mirror/diffuse&#xA;  if(erand(Xi) &amp;lt; P)&#xA;      return direct_light/P&#xA;  else&#xA;      return spec/(1-P)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5764" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-01-08T20:07:08.267" Title="Mimicking Blender's &quot;roughness&quot; in my path tracer" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;material&gt;&lt;render&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4487" PostTypeId="1" AcceptedAnswerId="4495" CreationDate="2017-01-06T21:48:05.473" Score="3" ViewCount="135" Body="&lt;p&gt;I would like to compute volumetric obscurance with line integrals like described in &lt;a href=&quot;http://advances.realtimerendering.com/s2010/Ownby,Hall%20and%20Hall%20-%20Toystory3%20(SIGGRAPH%202010%20Advanced%20RealTime%20Rendering%20Course).pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a 2D sample, it is possible to know the &quot;depth in sphere&quot;. But I don't understand how they compute the occluded (in red on the following image) part and the unnoccluded (in yellow) part of the line in the sphere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that they say that given the depth read through the sample and the &quot;depth in sphere&quot;, we should be able to deduce each part of the lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eOLwt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eOLwt.png&quot; alt=&quot;line sampling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5807" LastEditorUserId="231" LastEditDate="2017-01-07T12:12:11.423" LastActivityDate="2017-01-08T20:27:29.750" Title="Volumetric Obscurance : line integrals" Tags="&lt;rendering&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4489" PostTypeId="2" ParentId="4479" CreationDate="2017-01-07T16:03:04.000" Score="6" Body="&lt;p&gt;I have now replaced it with the following, which works:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint textureHandle;&#xA;glCreateTextures(GL_TEXTURE_2D, 1, &amp;amp;textureHandle);&#xA;glTextureStorage2D(textureHandle, 1, GL_RGBA8, imageW, imageH);&#xA;glTextureSubImage2D(textureHandle, 0, 0, 0, imageW, imageH, GL_RGBA, GL_UNSIGNED_BYTE, image_data);&#xA;glTextureParameteri(textureHandle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glBindTextureUnit(0, textureHandle);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5802" LastActivityDate="2017-01-07T16:03:04.000" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4490" PostTypeId="1" AcceptedAnswerId="4498" CreationDate="2017-01-07T21:00:10.837" Score="4" ViewCount="1113" Body="&lt;p&gt;Let's say that I have a raytracer that is rendering a scene that includes a refractive object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When a ray hits the refractive object, I know that I can use the fresnel equation (Schlick's approximation in my case) as well as the object's base reflectivity amount to figure out how much light is reflected or transmitted at that point on the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At this point, I can get the reflected color using a reflection ray (possibly recursively), an environment map, and also calculate a specular highlight for the light source(s) I have.  I sum whatever reflection colors I have, multiplied by the amount of reflection from the fresnel equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, I calculate what amount of light comes in due to refraction by following the refracted ray (recursively) and multiplying that value by 1.0-reflectionAmount.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That makes sense to me so far, but where I get a little confused is for the refraction rays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I follow the refracted ray into the object and hit the back side of the surface the first time, i once again use the fresnel equations to calculate the reflected (internally) and refracted multipliers for the light, taking into account the possibility of total internal refraction (assuming here that the inside of the object has a higher IOR than outside of the object, an ok assumption for my case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, at this point, do i apply a specular highlight to the surface that i hit from the inside?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On one hand it's a surface so i feel like i should, but which ray should i use for the lighting - the refracted ray or the reflected ray, or both?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If using the refracted ray, it feels wrong to use the direction to the light source for the specular light, and feels like i should shoot the refracted ray to the surface of the object and see what the specular highlight would look like from there and use that - but do so recursively, using the fresnel equation again at each step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain a decent way to handle a specular highlight in a ray tracer that supports refraction and total internal reflection?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since this is a ray tracer, not a path tracer, instead of being limited to physically accurate solutions, I'm looking for any plausible solutions, but of course, physically inspired solutions are likely to be better!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-01-09T15:25:04.057" Title="How to handle specular highlights with reflection / total internal reflection in a ray tracer?" Tags="&lt;raytracing&gt;&lt;specular&gt;&lt;reflection&gt;&lt;refraction&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4491" PostTypeId="1" AcceptedAnswerId="4493" CreationDate="2017-01-07T21:35:26.213" Score="3" ViewCount="254" Body="&lt;p&gt;I am writing a plugin to export data from 3DS Max. 3DS Max's geometry pipeline is... interesting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As part of my plugin I decompose a transform matrix into a translation, (quaternion) rotation &amp;amp; scale using an inbuilt function.&#xA;This of course does not always work, such as when a shear is present.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Max does have an affine decomposition function, but I don't want to use that because the resulting components do not all have an analogue in the destination application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'd like to do, is detect when the decomposition is lossy, so I can bake the geometry for the object which uses it, before transmitting it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How can I determine, either before or after, whether a matrix TRS decomposition is exact?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="4509" LastActivityDate="2017-01-08T19:36:44.920" Title="Detect a lossy matrix decomposition?" Tags="&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4492" PostTypeId="2" ParentId="350" CreationDate="2017-01-07T23:34:33.220" Score="-1" Body="&lt;p&gt;Think of diffuse as the amount of light scattered by the roughness of the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Surfaces such as wood has a high diffuse coefficient due to it's material texture, but if it was sanded, varnished and polished, the surface would be far smoother, thus decreasing the diffuse coefficient, but increasing the &quot;mirror shine&quot;, or specularity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Albedo would be the amount of light, on average, that a surface reflects. The moon, despite being cratered and pitted, reflect a lot of light due to the distance between the observer and the moon, and so, the diffuse of the individual surface regions can be ignored, in favour of an average value. Going back to the lunar example, we know that the moon has many regions, with varying amounts of diffuse and specular values, but at a far enough distance, those values become less important, as we are too far away to make out such detail with the naked eye.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At far distances, you could theoretically, in computer graphics terms, use albedo to compute the average colour of a surface (using sampling), and use the specular coefficient to compute the brightness of that colour. But in practice, LOD texture sampling does the job just fine.&lt;/p&gt;&#xA;" OwnerUserId="5816" LastActivityDate="2017-01-07T23:34:33.220" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4493" PostTypeId="2" ParentId="4491" CreationDate="2017-01-08T19:36:44.920" Score="3" Body="&lt;p&gt;You can detect a matrix that can't be decomposed in TRS form by taking its 3×3 upper-left submatrix, interpreting its columns as vectors, and dotting them together in all combinations (1 with 2, 2 with 3, and 1 with 3). For a TRS matrix, the three dot products should all be zero, i.e. the column vectors should be orthogonal to each other. If any of the dot products are nonzero (beyond some epsilon to account for roundoff error) then the matrix is not decomposable as TRS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This derives from the property that a rotation matrix is an &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthogonal_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;orthogonal matrix&lt;/a&gt;, i.e. its column vectors form an orthonormal basis. When you multiply the rotation by a scaling matrix, the column vectors may no longer be unit vectors, but they should still be orthogonal. And the translation part doesn't affect the rotation-scaling part.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-08T19:36:44.920" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4494" PostTypeId="2" ParentId="4486" CreationDate="2017-01-08T20:07:08.267" Score="4" Body="&lt;p&gt;For explicit light sampling: yep, you just evaluate the BRDF for that incoming direction and the output direction back toward the camera. There's probability involved in the case of an area light: you have to randomly choose a point on the light source, and include a factor to convert from probability density over light source area to a density over solid angle at the receiver point. It looks like you've got that already (that's the $\cos \theta' / (p(\mathbf{x}')\|\mathbf{x}-\mathbf{x}'\|^2)$ in the formula you mentioned).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For sampling the reflection ray, you &lt;em&gt;could&lt;/em&gt; just pick a random ray from the hemisphere and weight it by the BRDF, the same as you'd do for diffuse. But that won't be very efficient; it'll take a huge number of samples to converge to a low-noise result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you really want to do is &lt;em&gt;importance-sample&lt;/em&gt; the BRDF. This means choosing a random ray not uniformly over the hemisphere, but using a probability distribution that matches the shape of the BRDF (as much as possible). Then you'll automatically get rays that are clustered around the sharp reflection peak in the BRDF when the roughness is low, and spread out more over the hemisphere when the roughness is high.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how do you do it? The paper &lt;a href=&quot;http://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt; by Walter et al (which popularized the GGX distribution in graphics) handily gives importance-sampling formulas for several common BRDFs in section 5.2. Their approach is to importance-sample the normal distribution of the BRDF, then leave the Fresnel and geometry factors to be factored into the path weight.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, their GGX importance-sampling formula is (equations 35–36):&#xA;$$\begin{aligned}\theta_m &amp;amp;= \arctan \left( \frac{\alpha_g\sqrt{\xi_1}}{\sqrt{1-\xi_1}} \right) \\ \phi_m &amp;amp;= 2\pi\xi_2\end{aligned}$$&#xA;where $\alpha_g$ is the GGX roughness parameter, and $\xi_1, \xi_2$ are a pair of uniform random numbers in [0, 1]. The outputs $\theta_m, \phi_m$ are the polar coordinates (relative to the surface normal) of the sampled microfacet normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to use this, you'd choose random inputs $\xi_1, \xi_2$, then evaluate the above equations, and use the resulting normal to compute the reflection ray, as well as the Fresnel and geometry factors from the BRDF.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-08T20:07:08.267" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4495" PostTypeId="2" ParentId="4487" CreationDate="2017-01-08T20:27:29.750" Score="1" Body="&lt;p&gt;This is based on the formula for a sphere that expresses its surface $z$ as a function of $x, y$:&#xA;$$z(x, y) = \pm\sqrt{r^2 - x^2 - y^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if $x, y$ is the vector from the sphere's center to your sample point, the total length of the line segment (both occluded and unoccluded parts) is the distance between the top and bottom surfaces, which is $L = 2\sqrt{r^2 - x^2 - y^2}$. (This formula appears on slide 51 of that paper, BTW, although they've apparently scaled so that the radius is 1.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, if you know the depth of the sample point relative to the sphere's center (call it $\Delta z$), you can calculate the fraction of the line that's occluded as&#xA;$$\frac{\tfrac{1}{2}L - \Delta z}{L}$$&#xA;or equivalently&#xA;$$\frac{1}{2} - \frac{\Delta z}{L}$$&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-08T20:27:29.750" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4496" PostTypeId="2" ParentId="4109" CreationDate="2017-01-09T09:41:49.727" Score="1" Body="&lt;p&gt;In my case, i fixed the problem adding Dx' for interpolation of x-direction.&#xA;In edge scan line of x-direction, I use integer-type for speed-up but ingnored dx' as below. I changed variable type from interger to float and adding dx'.&#xA;(picture 1)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/sqqTx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sqqTx.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5823" LastActivityDate="2017-01-09T09:41:49.727" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4498" PostTypeId="2" ParentId="4490" CreationDate="2017-01-09T15:25:04.057" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;But, at this point, do i apply a specular highlight to the surface that i hit from the inside?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Unless you have a light source inside your object, there's no point in doing lighting on the inside surface as you'll hit the object again before you reach the light or environment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to support a light in the object, then by all means do your lighting but make sure to trace rays to check that you actually reach the lights without exiting the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Otherwise, that lighting should come from your (internal) reflected ray which will eventually hit the surface again, be refracted and get light from the outside.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;which ray should i use for the lighting - the refracted ray or the reflected ray, or both?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I think the confusion here is that when you write of &quot;calculate a specular highlight&quot; there is an assumed BRDF which may not make much sense for refraction. At least probably not without a few tweaks. What you really need is a BTDF (bidirectional transmittance distribution function).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to keep it simple, I think you could adapt a Blinn-Phong model for refraction by using the half vector of equation (16) in &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-01-09T15:25:04.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4499" PostTypeId="1" AcceptedAnswerId="4502" CreationDate="2017-01-09T18:57:31.660" Score="4" ViewCount="1512" Body="&lt;p&gt;I have problems implementing a Vulkan renderer alongside my OpenGL one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL one can change sampler parameters easily at runtime (like anisotropy settings through glTexParameter) or blend/depth states.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wonder if this is also possible in Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I usually create lets say a sampler object with all information needed and throw the creation info away after construction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did not find any information on this on the net.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is there any way to change those settings at runtime or do I have to create a complete new sampler object down the road?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same question applies to depth/blend states in pipeline objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the second case would not actually be particularly fast performance wise.&lt;/p&gt;&#xA;" OwnerUserId="5825" LastEditorUserId="231" LastEditDate="2017-01-10T12:10:24.840" LastActivityDate="2017-01-10T12:10:24.840" Title="How to change sampler/pipeline states at runtime in Vulkan?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4500" PostTypeId="2" ParentId="4374" CreationDate="2017-01-09T19:35:15.503" Score="4" Body="&lt;p&gt;That is, to my knowledge, a problem without a proper solution. You're seeing the discrepancy between shading normal and geometry normal and it becomes obvious, that the shading normal is just a trick. &lt;a href=&quot;http://pbrt.org&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;PBRT&quot;&gt;PBRT&lt;/a&gt; has a paragraph on this, their solution is to look at the geometric normal to determine whether to call the BRDF (reflection) or the BTDF (transmission), then to pass the shading normal to the BxDF. Still, this doesn't work robustly in all situations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This problem is also known and described for production proven render engines:&#xA;&lt;a href=&quot;http://blog.irayrender.com/post/29042276644/shadow-acne-and-the-shadow-terminator&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.irayrender.com/post/29042276644/shadow-acne-and-the-shadow-terminator&lt;/a&gt;&#xA;The solution suggested for iRay is to use displacement mapping instead of normal maps. This way, shading and geometry normal are in agreement again.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-01-09T19:35:15.503" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4501" PostTypeId="2" ParentId="4349" CreationDate="2017-01-09T19:51:20.567" Score="4" Body="&lt;p&gt;BRDFs are not accurate for any dielectric surface, as all of them have some degree of subsurface scattering. A BSSRDF is also just an approximation based on the assumption of a semi-infinite slab. Ideally, you'd run a volumetric path trace for all surfaces, which would be much more accurate than BRDFs or BSSRDFs, but significantly more expensive. Although, Disney has already used brute force path tracing over BSSRDFs in production, see &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf&quot; rel=&quot;noreferrer&quot;&gt;the SIGGRAPH 2015 course notes, section 2.5&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-01-09T19:51:20.567" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4502" PostTypeId="2" ParentId="4499" CreationDate="2017-01-09T20:11:42.203" Score="3" Body="&lt;p&gt;You're sort of asking two different questions here but that's okay.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Changing Sampler states is pretty straightforward. When you create a descriptor set, you write your &lt;code&gt;VkSampler&lt;/code&gt; object that you've created into a descriptor set. If you want to update a sampler in a descriptor set, create a &lt;code&gt;VkSampler&lt;/code&gt; with the sampler settings you want and then call &lt;code&gt;vkUpdateDescriptorSets&lt;/code&gt; with the new &lt;code&gt;VkSampler&lt;/code&gt; writes that you want to perform. When you bind that descriptor set again it should contain your new sampler. This is a bit roundabout but you have to architect for it. You probably don't want to update samplers every frame so only do this when you need to. This is not an extremely expensive operation if you do it right. Vulkan expects descriptor set data to change; so long as that data lines up with the descriptor set layout it's going to go pretty fast. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Changing Pipelines is EXTREMELY expensive. Vulkan doesn't like to perform context switches like this so you can't just &lt;em&gt;update&lt;/em&gt; an existing pipeline that's in use. You do have to completely rebuild your rendering path to use the new PSO. If you want to change between a few different Pipelines it's best to build them all upfront, build all the different command buffers that use the different pipelines and then execute the command buffer that has the pipeline you want to run. If you want to change your pipeline, execute the other command buffer that uses the pipeline you want. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan wants you to create, cache and reuse data as much as possible. That's how you get a lot of savings. You don't need to update descriptor sets, command buffers etc. unless they actually change. &lt;/p&gt;&#xA;" OwnerUserId="5715" LastActivityDate="2017-01-09T20:11:42.203" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4503" PostTypeId="1" CreationDate="2017-01-09T22:38:06.093" Score="3" ViewCount="3868" Body="&lt;p&gt;I'm having some trouble trying to figure out how to go from a coordinate on the screen, to 3D world coordinates on a plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My case is as seen on the picture further down. World origin is in the center with the grid representing the X-Y plane.&lt;br&gt;&#xA;I want to be able to click/touch on the screen, and transform the screen coordinates to the correct 3D world coordinates on the X-Y plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I first tried to figure out the maths myself by simple geometry, but got stuck...&lt;br&gt;&#xA;I then tried the function &lt;code&gt;glm::unProject()&lt;/code&gt; after checking out &lt;a href=&quot;https://stackoverflow.com/questions/9901453/using-glms-unproject&quot;&gt;this post&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The screen has dimensions &lt;code&gt;mWindowWidth&lt;/code&gt; and &lt;code&gt;mWindowHeight&lt;/code&gt;.&lt;br&gt;&#xA;&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt; are the screen coordinates where origin is in the top left corner. Positive x to the right, positive y down.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;projM&lt;/code&gt; is the projection matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Third parameter is the model matrix, which I believe in my case only needs to be an identity matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get the world coordinates X and Y (Z is already known as it is on the plane) by using these parameters in &lt;code&gt;glm::unProject&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 posVec = glm::unProject(&#xA;   glm::vec3(x, float(mWindowHeight) - y, 1.0f), &#xA;   glm::mat4(1.0f), &#xA;   projM, &#xA;   glm::vec4(0.0f, 0.0f, float(mWindowWidth), float(mWindowHeight))&#xA;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What happens is that if I have screen coordinates near world origin, the world coordinates seems correct. But If I use screen coordinates near the edges and corners of the screen, I get a certain offset (see image below).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where is this offset coming from, and what am I misunderstanding?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Gc5Mu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Gc5Mu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As mentioned in the comments, the second parameter should be the &quot;model-view&quot; matrix. I tried to switch &lt;code&gt;glm::mat4(1.0f)&lt;/code&gt; with &lt;code&gt;viewM&lt;/code&gt; (view matrix). The effect is still the same, if not with even more offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also tried to get the &lt;code&gt;z&lt;/code&gt; buffer depth value by using:&#xA;(Got it from this &lt;a href=&quot;http://nehe.gamedev.net/article/using_gluunproject/16013/&quot; rel=&quot;nofollow noreferrer&quot;&gt;tutorial&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float z;&#xA;glReadPixels(int(x), int(mWindowHeight) - int(y), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &amp;amp;z);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This results in very small values of X and Y world coordinates, and essentially where ever I touch, the resulting coordinates are near the origin.&lt;/p&gt;&#xA;" OwnerUserId="3434" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-02-10T15:43:34.500" Title="Screen to World coordinates glm::unProject" Tags="&lt;raytracing&gt;&lt;projections&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4504" PostTypeId="1" AcceptedAnswerId="4506" CreationDate="2017-01-10T01:45:02.033" Score="2" ViewCount="673" Body="&lt;p&gt;I have been trying to implement the GGX shader in my path tracer based on this paper: &lt;a href=&quot;http://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt;&#xA;It's pretty clear how the importance sampling works, but I would also like to do next event estimation (direct lighting) for when the object is more rough and acts close to a diffuse shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The part that is really confusing to me is equation [19] and [20]:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/58HCg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/58HCg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand why in [19] they use the microsurface normal, but in [20] they use the macrosurface normal. The transmission term I don't need because I'm just working on the reflectance, but I still don't get why it's &lt;strong&gt;m&lt;/strong&gt; on [19] and &lt;strong&gt;n&lt;/strong&gt; on [20]. Is it possible to use any incident direction and outgoing direction and get back a proper BRDF? Or does the scatter direction &quot;&lt;strong&gt;o&lt;/strong&gt;&quot; have to match where the microsurface normal makes it bounce to? In direct lighting the directions would need to be independent of each other for it to work since you're grabbing a from the hit point to the light, and from the hit point to the camera. &lt;/p&gt;&#xA;" OwnerUserId="5764" LastEditorUserId="231" LastEditDate="2017-01-10T11:58:09.770" LastActivityDate="2017-01-10T11:58:09.770" Title="How to properly direct light sample GGX in path tracing" Tags="&lt;raytracing&gt;&lt;shader&gt;&lt;3d&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4505" PostTypeId="2" ParentId="2271" CreationDate="2017-01-10T01:49:10.983" Score="0" Body="&lt;p&gt;Network latency will not be low enough VR in near future. Mobile VR is a key driver for Cloud Rendering. However, the mobile network latency is much higher. Split rendering with future micro-cloud based Gamelets architecture (&lt;a href=&quot;http://ieeexplore.ieee.org/document/6799051/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://ieeexplore.ieee.org/document/6799051/&lt;/a&gt;) is one possible solution for Cloud Rendering for VR. &lt;/p&gt;&#xA;" OwnerUserId="5826" LastActivityDate="2017-01-10T01:49:10.983" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4506" PostTypeId="2" ParentId="4504" CreationDate="2017-01-10T02:01:08.383" Score="3" Body="&lt;p&gt;This may simply be a typo or oversight. Note that in the previous section they've been discussing the &lt;em&gt;microsurface&lt;/em&gt; BxDFs $f^m_r(\mathbf{i},\mathbf{o},\mathbf{m})$ and $f^m_t(\mathbf{i},\mathbf{o},\mathbf{m})$, which are naturally evaluated at a microsurface normal, but in this section they've moved on to talking about &lt;em&gt;macrosurface&lt;/em&gt; BxDFs, which have the microsurface integrated out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;AFAICT, the intent of equation 19 is just to say that the total BSDF is a sum of reflection and transmission parts, so it doesn't really matter ($\mathbf{m}$ is a free variable there and could be named anything), but to be less confusing it should probably have been $\mathbf{n}$. Maybe they just forgot to update it during a round of edits, or something.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, you can evaluate a BRDF/BSDF with any combination of input and output directions and it should give the correct answer.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-10T02:01:08.383" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4507" PostTypeId="1" AcceptedAnswerId="4508" CreationDate="2017-01-10T04:40:10.430" Score="3" ViewCount="984" Body="&lt;p&gt;I have a set of non-convex polygons and I want to merge them. I am able to find the connection between two polygons. If there are more than two polygons, one connection can intersect another polygon within the set. I do not want to check for a possible intersection. So I have to find the nearest neighbor of a single polygon. Is there an existing algorithm? I can't find anything in my literature.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0wGVT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0wGVT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/b1bca.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/b1bca.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5828" LastEditorUserId="5828" LastEditDate="2017-01-13T02:59:20.857" LastActivityDate="2017-01-19T10:59:57.347" Title="Finding the nearest neighbor of polygons" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;2d&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4508" PostTypeId="2" ParentId="4507" CreationDate="2017-01-10T08:35:47.950" Score="1" Body="&lt;p&gt;You're looking for a nearest neighbor search: &lt;a href=&quot;https://en.wikipedia.org/wiki/Nearest_neighbor_search&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Nearest_neighbor_search&lt;/a&gt;&#xA;We've solved similar problems in 3D space using spatial subdivision (kd tree). Depending on polygon count and uniformity, a linear search or hash grid would be options too. A linear search, while O(N^2) can still be faster than setting up extra data structures for small a small number of polygons/vertices. A hash grid should be faster to update than a kd tree if your scene is dynamic, and I would expect it to be more efficient when the scene is uniform in vertex density.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-01-10T08:35:47.950" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4510" PostTypeId="1" CreationDate="2017-01-10T18:18:07.440" Score="1" ViewCount="313" Body="&lt;p&gt;I have trouble understanding the following Javascript code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It calculates, given a mesh described by its vertices &lt;code&gt;vs&lt;/code&gt; and indices &lt;code&gt;ind&lt;/code&gt;, the normals for each vertex. The mesh faces are a triangle list, and are oriented counterclockwise.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;utilsObject.prototype.calculateNormals = function(vs, ind) {&#xA;    var x = 0;&#xA;    var y = 1;&#xA;    var z = 2;&#xA;    var ns = [];&#xA;    // for each vertex, initialize normal x, normal y, normal z&#xA;    for (var i = 0; i &amp;lt; vs.length; i++) {&#xA;        ns[i] = 0.0;&#xA;    }&#xA;    // we work on triads of vertices to calculate normals so&#xA;    // i = i+3 (i = indices index)&#xA;    for (var i = 0; i &amp;lt; ind.length; i = i + 3) {&#xA;        var v1 = [];&#xA;        var v2 = [];&#xA;        var normal = [];&#xA;        // p1 - p0&#xA;        v1[x] = vs[3 * ind[i + 1] + x] - vs[3 * ind[i] + x];&#xA;        v1[y] = vs[3 * ind[i + 1] + y] - vs[3 * ind[i] + y];&#xA;        v1[z] = vs[3 * ind[i + 1] + z] - vs[3 * ind[i] + z];&#xA;        // p0 - p1&#xA;        v2[x] = vs[3 * ind[i + 2] + x] - vs[3 * ind[i + 1] + x];&#xA;        v2[y] = vs[3 * ind[i + 2] + y] - vs[3 * ind[i + 1] + y];&#xA;        v2[z] = vs[3 * ind[i + 2] + z] - vs[3 * ind[i + 1] + z];&#xA;        // cross product by Sarrus Rule&#xA;        normal[x] = v1[y] * v2[z] - v1[z] * v2[y];&#xA;        normal[y] = v1[z] * v2[x] - v1[x] * v2[z];&#xA;        normal[z] = v1[x] * v2[y] - v1[y] * v2[x];&#xA;        // update the normals of that triangle: sum of vectors&#xA;        for (j = 0; j &amp;lt; 3; j++) {&#xA;            ns[3 * ind[i + j] + x] = ns[3 * ind[i + j] + x] + normal[x];&#xA;            ns[3 * ind[i + j] + y] = ns[3 * ind[i + j] + y] + normal[y];&#xA;            ns[3 * ind[i + j] + z] = ns[3 * ind[i + j] + z] + normal[z];&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How does this function work? For example, could you explain the use of indices in the instruction:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;v1[x] = vs[3*ind[i+1]+x] - vs[3*ind[i]+x];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Rather than a high-level explanation, I am interested in the logic of the implementation details.&lt;/p&gt;&#xA;" OwnerUserId="4981" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:38:19.650" LastActivityDate="2018-03-04T00:38:19.650" Title="How does this function calculate normals of a mesh?" Tags="&lt;shader&gt;&lt;computational-geometry&gt;&lt;webgl&gt;" AnswerCount="0" CommentCount="5" ClosedDate="2017-01-10T22:43:20.437" ContentLicense="CC BY-SA 3.0" />
  <row Id="4511" PostTypeId="1" AcceptedAnswerId="4533" CreationDate="2017-01-10T21:27:37.973" Score="3" ViewCount="163" Body="&lt;p&gt;I'm about to implement downscaling on a microcontroller. Source resolution is e.g. 720x576 (the 576i PAL resolution, other one possible: 480i, NTSC resolution), destination is 32x16. The goal is to have RGB LED matrix (of size 32x16) flowing with various colors, shapes, shadows, etc. – a half-abstract vs. half-meaningful effect, driven by a prepared PAL or NTSC video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will only be able to select every 22th pixel (720 / 36) and every 36th line (576 / 16) – the microcontroller will not be able to compute averages of groups of pixels etc. This way I will obtain 32x16 downscaled image to output to the LED matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I cannot find any examples of how such downscaling will behave. Tried searching for &quot;decimation&quot; but no luck. Which program can I use to test this downscaling? Can I quickly code this somehow – if I would to code this, I would use libSDL1, generate set of files, but this is difficult (e.g. image loading). Maybe some snippet-solution is possible? Should I care about Nyquist frequency?&lt;/p&gt;&#xA;" OwnerUserId="5832" LastEditorUserId="5832" LastEditDate="2017-01-13T17:47:26.793" LastActivityDate="2017-01-13T17:47:26.793" Title="Downscaling by skipping rows and columns – any example images?" Tags="&lt;image-processing&gt;&lt;noise&gt;&lt;sampling&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4512" PostTypeId="1" CreationDate="2017-01-11T10:14:08.090" Score="8" ViewCount="845" Body="&lt;p&gt;I'm considering topic of my thesis connected with computer graphics - I would compare some GI techniques which work &lt;strong&gt;completely in real time&lt;/strong&gt; (no precomputation to lightmaps etc. and each frame everything is calculated anew) to narrow my topic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I plan to compare two kind of techniques:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;based on RSM sampling heuristics (Radiance Hints) &lt;/li&gt;&#xA;&lt;li&gt;based on cone tracing of scene voxelization calculated in every frame (Voxel Cone Tracing) &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Each technique is based on grid moving with camera in voxel size increments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The key I think is to describe pros and cons of kind of technique in more general way. For example some other techniques are based on RSM sampling. I think two kinds should suffice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any other important or popular kind of technique which I should include or I am not aware of?&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-01-11T21:04:00.550" LastActivityDate="2017-01-11T21:04:00.550" Title="Selection of GI techniques working in real time" Tags="&lt;real-time&gt;&lt;global-illumination&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4513" PostTypeId="1" AcceptedAnswerId="4515" CreationDate="2017-01-11T11:24:26.260" Score="9" ViewCount="9595" Body="&lt;p&gt;I use &lt;strong&gt;SDL2&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently my only shader has a &lt;strong&gt;MVP matrix&lt;/strong&gt;, and transforms the points with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;I calculate my View and Projection matrix for a camera with GLM:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::lookAt(pos, pos + forward, up);&#xA;glm::perspective(fov, aspectRatio, zNear, zFar);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I searched it, but I can only find legacy implementation of multiple viewports.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I create for example &lt;strong&gt;4 cameras&lt;/strong&gt; and let's say that they &lt;strong&gt;all the same&lt;/strong&gt;, except every camera has a &lt;strong&gt;different quarter of the screen&lt;/strong&gt; to render. (So I want 4 viewports with the same content)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I do this? Sorry if I didn't give enough informations, feel free to ask.&lt;/p&gt;&#xA;" OwnerUserId="5609" LastEditorUserId="5609" LastEditDate="2017-01-11T15:24:54.707" LastActivityDate="2019-08-24T18:54:50.743" Title="Multiple viewports with modern OpenGL?" Tags="&lt;opengl&gt;&lt;glm&gt;" AnswerCount="4" CommentCount="5" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4514" PostTypeId="2" ParentId="4503" CreationDate="2017-01-11T14:45:57.720" Score="1" Body="&lt;p&gt;You can calculate the world position of the pixel on near plane quite easily by first defining Normalized Device Coordinates (NDC) for the point and then transforming the NDC back to the world space. You can calculate NDC for your point as follows:&#xA;$$v=[2*(x+0.5)/width-1, 1-2*(y+0.5)/height, 0, 1]$$&#xA;I'm using 0 here for the z-component assuming near-plane in NDC is 0, but it could be something else as well, so check with your projection matrix what values comes out at the near-plane. This vector must be then transformed to clip-space by multiplying by near-plane distance:&#xA;$$v'=np*v$$&#xA;Now that you have clip-space coordinates, you just need to transform this back to world space with the standard clip$\rightarrow$world transformation matrix:&#xA;$$v''=M*v'$$&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-01-11T14:45:57.720" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4515" PostTypeId="2" ParentId="4513" CreationDate="2017-01-11T14:51:02.887" Score="8" Body="&lt;p&gt;Rendering to different viewports (parts) of the same screen can be done as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example splitting screen into four parts and rendering the same scene four times to each corner with different uniforms and different viewports:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bindFramebuffer();&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;scene-&amp;gt;setConstPerFrameUniforms();&#xA;&#xA;//left bottom&#xA;glViewport(0, 0, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;setVarPerFrameUniforms(1);&#xA;scene-&amp;gt;draw();&#xA;&#xA;//right bottom&#xA;glViewport(WindowWidth*0.5, 0, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;setVarPerFrameUniforms(2);&#xA;scene-&amp;gt;draw();&#xA;&#xA;//left top&#xA;glViewport(0, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;setVarPerFrameUniforms(3);&#xA;scene-&amp;gt;draw();&#xA;&#xA;//right top&#xA;glViewport(WindowWidth*0.5, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;setVarPerFrameUniforms(4);&#xA;scene-&amp;gt;draw();&#xA;&#xA;glViewport(0, 0, WindowWidth, WindowHeight); //restore default&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-01-12T15:50:49.653" LastActivityDate="2017-01-12T15:50:49.653" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="4516" PostTypeId="2" ParentId="4512" CreationDate="2017-01-11T15:09:28.307" Score="1" Body="&lt;p&gt;Many of the real-time GI solutions have some precomputation involved, which enable real-time lighting changes but limit the geometry changes to be non-real time. E.g. in cone tracing you mentioned there's the non-real time scene voxelization process. Here are few such real-time solutions that come to mind in addition to the ones you listed.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Light probes&lt;/li&gt;&#xA;&lt;li&gt;Screen-Space GI&lt;/li&gt;&#xA;&lt;li&gt;Virtual Point Lights&lt;/li&gt;&#xA;&lt;li&gt;Precomputed Radiance Transfer&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;It's also the question how you define real-time: What's FPS, on what kind of hardware and for what kind of scene complexity.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-01-11T15:09:28.307" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4518" PostTypeId="1" CreationDate="2017-01-11T18:19:27.617" Score="1" ViewCount="358" Body="&lt;p&gt;I have just started learning OpenGL and I am trying to map a texture on a Quad Strip. Basically, I am trying to create a parametric surface and I don't know how to map the coordinates. What can I do? This is what I tried so far and, unfortunately, it doesn't work.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void draw(GL2 gl, GLU glu, GLUT glut) {&#xA;&#xA;    Textures.track.enable(gl);&#xA;    Textures.track.bind(gl);&#xA;&#xA;    gl.glEnable(GL_TEXTURE_2D);&#xA;&#xA;    gl.glBegin(GL_QUAD_STRIP);&#xA;&#xA;    double t = 0.0;&#xA;    gl.glColor3f(1f, 1f, 1f);&#xA;&#xA;    for(int i = 0; i &amp;lt;= 100; i++){&#xA;        t = t + 0.01;&#xA;        Vector tangent = getTangent(t);&#xA;        Vector normal = tangent.cross(Vector.Z);&#xA;        Vector centerPoint = getPoint(t);&#xA;&#xA;        Vector point1 = centerPoint.subtract(normal.scale(w/30));&#xA;        Vector point2 = centerPoint.add(normal.scale(w/30));&#xA;&#xA;        gl.glTexCoord2f((float)t, 0f);&#xA;        gl.glVertex3d(point1.x, point1.y, point1.z);&#xA;        gl.glTexCoord2f(0f, (float)t);&#xA;        gl.glVertex3d(point2.x, point2.y, point2.z);&#xA;    }&#xA;    gl.glEnd();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5835" LastEditorUserId="2041" LastEditDate="2017-01-11T18:48:33.300" LastActivityDate="2017-01-11T18:48:33.300" Title="Texture mapping on a quad strip" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2017-01-12T12:58:14.103" ContentLicense="CC BY-SA 3.0" />
  <row Id="4519" PostTypeId="2" ParentId="4512" CreationDate="2017-01-11T20:33:24.870" Score="3" Body="&lt;p&gt;In this vein a bit, Killzone renders one bounce reflections, but uses temporal anti aliasing to combine the last frame with the current frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice, this means you get MANY bounce reflections, since in effect each frame rendered catches the previous number of reflections as the new reflection - adding one each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not quite GI, but i wouldn't be surprised if people pursue that direction more in the future, if they aren't already working on it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The temporal anti aliasing used normally lets you get more samples with subsequent frames, but used in this way, it also gives you higher bounce counts with subsequent frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could totally see doing path tracing type path following, choosing reflection or BSDF rays based on fresnel equations for instance, and having the temporal AA combine it over time.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-01-11T20:51:31.777" LastActivityDate="2017-01-11T20:51:31.777" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4521" PostTypeId="1" AcceptedAnswerId="4536" CreationDate="2017-01-12T09:19:21.363" Score="0" ViewCount="513" Body="&lt;p&gt;&lt;strong&gt;What are some of the challenges of Offline Rendering?&lt;/strong&gt; I know one problem that is faced is performance and rendering times, are there any more issues? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Path Traced photos seem to have reached the point where it is hard to distinguish a CGI image in comparison to a real photo so being able to render a photo-realistic image doesn't really seem like a challenge anymore.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is offline rendering just about refining current techniques to find an improvement in render times now and not so much about photo realism?&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ko8BI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ko8BI.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;(Grand Moff Tarkin in Star Wars: Rogue One was entirely created through CGI since the actual actor had died)&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-01-15T07:44:37.087" Title="Challenges of Offline Rendering" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;performance&gt;&lt;pathtracing&gt;&lt;offline&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4523" PostTypeId="1" CreationDate="2017-01-12T12:05:10.333" Score="6" ViewCount="1353" Body="&lt;p&gt;I've been reading around that matrices (for example, rotation matrices, but not only) can be thought somehow as coordinate systems. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: how is that possible? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've seen for example that if we're using row-major conventions, the rows of the matrices involved in the transformations (specifically I've seen about &lt;em&gt;rotations&lt;/em&gt;) can be thought as the vectors representing some coordinate system (specifically it should be a &lt;em&gt;local&lt;/em&gt; coordinate system).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is this the case? And why specifically a &lt;em&gt;local coordinate system&lt;/em&gt;? What does it even mean &lt;em&gt;local coordinate system&lt;/em&gt; in this context? Are there any other type of matrices, apart from the rotation matrices, which can be thought as coordinate systems? If yes, which ones, and why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Matrices usually represent a transformation (linear or not, maybe also affine in computer graphics), but it's new to me to think about matrices as coordinate systems. &lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastActivityDate="2017-01-12T19:30:49.027" Title="How is that possible that matrices can be thought as coordinate systems?" Tags="&lt;transformations&gt;&lt;matrix&gt;&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4524" PostTypeId="2" ParentId="4523" CreationDate="2017-01-12T14:23:41.867" Score="3" Body="&lt;p&gt;A matrix can be used to transform a coordinate system into a new one. More specifically, it can be used to transform the basis vectors of a coordinate system. That's how it defines a new coordinate system. It is of course always in relation to another coordinate system but that is often implicit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;local coordinate system&lt;/em&gt; usually means a coordinate system which is specific to only part of your scene. For example, the coordinate system where an object's vertices are defined. Those vertices are then transformed, with a matrix, to some global coordinate system with the rest of the scene. That's why it is said that the matrix defines the local coordinate system, in relation to the global one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With that said, there can be a number of other meanings. Texture coordinates are also a form of local coordinate system: a 2D one defined on a surface. It is specific to that surface and it is usually not defined by a transformation matrix.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-01-12T14:23:41.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4525" PostTypeId="2" ParentId="4513" CreationDate="2017-01-12T15:14:50.807" Score="5" Body="&lt;p&gt;This is a copy of @narthex's answer, except with only the viewports since that is all you need.  I'm not sure why the frame buffer / blend stuff is included in his answer.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//left bottom&#xA;glViewport(0, 0, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;draw();&#xA;&#xA;//right bottom&#xA;glViewport(WindowWidth*0.5, 0, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;draw();&#xA;&#xA;//left top&#xA;glViewport(0, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;draw();&#xA;&#xA;//right top&#xA;glViewport(WindowWidth*0.5, WindowHeight*0.5, WindowWidth*0.5, WindowHeight*0.5);&#xA;scene-&amp;gt;draw();&#xA;&#xA;glViewport(0, 0, WindowWidth, WindowHeight); //restore default&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3332" LastActivityDate="2017-01-12T15:14:50.807" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4527" PostTypeId="2" ParentId="4523" CreationDate="2017-01-12T18:34:20.407" Score="5" Body="&lt;p&gt;If you have a 3x3 matrix representing some transformation, you will actually have the X,Y,Z vectors of that transformation in the rows or columns (depending on if it's a row major or column major matrix).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, if you have a 3x3, you can look at it and immediately get the up, right(*), forward vectors (asterisk due to handedness, it could be the left vector).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3x3 Details:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;let's say you have a 3x3 matrix $M$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;M_{ij} =&#xA;\begin{bmatrix}&#xA;M_{1,1} &amp;amp; M_{1,2} &amp;amp; M_{1,3} \\&#xA;M_{2,1} &amp;amp; M_{2,2} &amp;amp; M_{2,3} \\&#xA;M_{3,1} &amp;amp; M_{3,2} &amp;amp; M_{3,3} \\&#xA;\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's see what happens when you multiply that by a vector $\begin{bmatrix}1,0,0 \end{bmatrix}$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;\begin{bmatrix}&#xA;M_{1,1} &amp;amp; M_{1,2} &amp;amp; M_{1,3} \\&#xA;M_{2,1} &amp;amp; M_{2,2} &amp;amp; M_{2,3} \\&#xA;M_{3,1} &amp;amp; M_{3,2} &amp;amp; M_{3,3} \\&#xA;\end{bmatrix}&#xA;*&#xA;\begin{bmatrix}&#xA;1 \\&#xA;0 \\&#xA;0 \\&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;M_{1,1} \\&#xA;M_{2,1} \\&#xA;M_{3,1} \\&#xA;\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let's try vector $\begin{bmatrix}0,1,0\end{bmatrix}$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;\begin{bmatrix}&#xA;M_{1,1} &amp;amp; M_{1,2} &amp;amp; M_{1,3} \\&#xA;M_{2,1} &amp;amp; M_{2,2} &amp;amp; M_{2,3} \\&#xA;M_{3,1} &amp;amp; M_{3,2} &amp;amp; M_{3,3} \\&#xA;\end{bmatrix}&#xA;*&#xA;\begin{bmatrix}&#xA;0 \\&#xA;1 \\&#xA;0 \\&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;M_{1,2} \\&#xA;M_{2,2} \\&#xA;M_{3,2} \\&#xA;\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And lastly, vector $\begin{bmatrix}0,0,1\end{bmatrix}$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;\begin{bmatrix}&#xA;M_{1,1} &amp;amp; M_{1,2} &amp;amp; M_{1,3} \\&#xA;M_{2,1} &amp;amp; M_{2,2} &amp;amp; M_{2,3} \\&#xA;M_{3,1} &amp;amp; M_{3,2} &amp;amp; M_{3,3} \\&#xA;\end{bmatrix}&#xA;*&#xA;\begin{bmatrix}&#xA;0 \\&#xA;0 \\&#xA;1 \\&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;M_{1,3} \\&#xA;M_{2,3} \\&#xA;M_{3,3} \\&#xA;\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This shows that whatever matrix $M$ is, the first column is the X axis vector of the coordinate space defined by the matrix.  The second column is the Y axis vector, and the third column is the Z axis vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These vectors are in global space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;M =&#xA;\begin{bmatrix}&#xA;X_x &amp;amp; Y_x &amp;amp; Z_x \\&#xA;X_y &amp;amp; Y_y &amp;amp; Z_y \\&#xA;X_z &amp;amp; Y_z &amp;amp; Z_z \\&#xA;\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can even see that this is true in an identity matrix, where the X,Y and Z vectors are just what you'd expect them to be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;M =&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{bmatrix}&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;A 3x3 matrix is much like a vector in that it describes directions but has no position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have a 4x4 matrix that represents a 3d transform and uses homogeneous coordinates for a translation, you can then use that to get the X,Y,Z orientation vectors, but also can get the translation from the origin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hopefully this is helpful, and not misleading for less common matrix types.  I saw an answer deleted which said similar, so fingers crossed :P&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-01-12T19:30:49.027" LastActivityDate="2017-01-12T19:30:49.027" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4528" PostTypeId="1" AcceptedAnswerId="4529" CreationDate="2017-01-12T19:51:33.987" Score="4" ViewCount="776" Body="&lt;p&gt;I have a &lt;a href=&quot;https://www.shadertoy.com/view/4tyXDR&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Shadertoy&quot;&gt;Shadertoy&lt;/a&gt; which renders the image below using ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to add caustics, but am aware that in general they are a hard solution, especially without bidirectional ray tracing or photon mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know if there is a way to analytically calculate caustics, or at least some of the caustics (or plausible caustic effects) in a situation like this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is refraction going on here, not just transparency, in case that makes a difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YtQBB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YtQBB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-01-12T20:30:57.713" Title="Is there a way to do sphere caustics analytically?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4529" PostTypeId="2" ParentId="4528" CreationDate="2017-01-12T20:30:57.713" Score="5" Body="&lt;p&gt;You might find &lt;a href=&quot;http://graphics.cs.williams.edu/papers/TransparencyI3D16/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; useful—its authors describe a way to make reasonably plausible caustic effects just by modulating their shadows with the surface normal and refractive index. It won’t get you the more complex/interesting hot-spot shapes that you’d get with photon mapping, but it could work well depending on your scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/91pVo.jpg&quot; alt=&quot;sample fake caustics&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;To extend stochastic shadow maps to mimic caustics, we decrease shadowing where light strikes a transmissive surface at normal incidence. We increase shadowing where the refractor is at a glancing angle and thus has a low Fresnel transmission factor.&#xA;  Specifically, during shadow map rendering, we increase ρ(λ) where the magnitude of the dot product of the surface normal nˆ and the vector to the light ωˆi is close to 1, and decrease ρ(λ) where the dot product is close to zero. We also increase this effect with the relative refractive index η.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="506" LastActivityDate="2017-01-12T20:30:57.713" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4530" PostTypeId="2" ParentId="4511" CreationDate="2017-01-13T06:18:55.530" Score="1" Body="&lt;p&gt;A basic nearest neighbour scale function would work like so. Here I also use 24:8 fixed point arithmetic to make it more micro friendly. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const int originalWidth = 320, originalHeight = 240;&#xA;int targetWidth = 50, targetHeight = 50;&#xA;&#xA;char *pSource = sourceBuffer; &#xA;char *pDest = destBuffer;    // you can use RGB instead of char&#xA;&#xA;int yStep = (originalWidth &amp;lt;&amp;lt; 8) / targetWidth;&#xA;int xStep = (originalHeight &amp;lt;&amp;lt; 8) / targetHeight;&#xA;&#xA;for(int y = 0, sampleY = 0; y &amp;lt; targetHeight; y++, sampleY += yStep) {&#xA;    // Point to start of scaled Y source line&#xA;    char *pSourceLine = pSource + ((sampleY &amp;gt;&amp;gt; 8) * originalWidth);&#xA;&#xA;    // Output the line, scaling only in X (we already know scaled-Y)&#xA;    for(int x = 0, sampleX = 0; x &amp;lt; targetWidth; x++, sampleX += xStep)&#xA;        *pDest++ = pSourceLine[sampleX &amp;gt;&amp;gt; 8];&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This will also work to scale image up as well as down, it should work on any input vs output size.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-01-13T06:18:55.530" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4531" PostTypeId="2" ParentId="4513" CreationDate="2017-01-13T12:37:08.923" Score="11" Body="&lt;p&gt;If you are writing your own Vertex/Fragment Shader there is another additional possibility to do this. It is much more complicated but might be useful for you and/or others. Additionally it speeds up the whole drawing process since it uses only one call to a draw command. The maximum number of Viewports is defined by GL_MAX_VIEWPORTS and is usually 16. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since OpenGL 4.1 the method &lt;a href=&quot;https://www.opengl.org/sdk/docs/man4/html/glViewportArray.xhtml&quot; rel=&quot;noreferrer&quot;&gt;glViewportArrayv&lt;/a&gt; exists. It can define an array of Viewports. The Viewports which are created by this method have an index assigned. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This index can be used in the Vertex Shader to set the Viewport to which the scene is rendered. (You have to include the &quot;&lt;em&gt;ARB_shader_viewport_layer_array&lt;/em&gt;&quot; extension in the shader code)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case I would suggest to do the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Store the 4 camera matrices in a Shader Storage Buffer (Array of mat4) to have them in the Vertex Shader&lt;/li&gt;&#xA;&lt;li&gt;Use &lt;a href=&quot;https://learnopengl.com/#!Advanced-OpenGL/Instancing&quot; rel=&quot;noreferrer&quot;&gt;indexed drawing&lt;/a&gt;, for example :&lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/glDrawElementsInstanced.xhtml&quot; rel=&quot;noreferrer&quot;&gt;glDrawElementsInstanced&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;use the build in &lt;a href=&quot;https://www.opengl.org/sdk/docs/man/html/gl_InstanceID.xhtml&quot; rel=&quot;noreferrer&quot;&gt;gl_InstanceID&lt;/a&gt; of the Vertex Shader to access the camera matrix array&lt;/li&gt;&#xA;&lt;li&gt;set the build in variable output variable gl_ViewportIndex in the Fragment Shader to the gl_InstanceID. (for details see &lt;a href=&quot;https://www.opengl.org/registry/specs/ARB/fragment_layer_viewport.txt&quot; rel=&quot;noreferrer&quot;&gt;ARB_fragment_layer_viewport&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5399" LastEditorUserId="5399" LastEditDate="2017-01-19T14:17:18.273" LastActivityDate="2017-01-19T14:17:18.273" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4532" PostTypeId="1" CreationDate="2017-01-13T12:41:15.877" Score="2" ViewCount="834" Body="&lt;p&gt;After asking &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4523/how-is-that-possible-that-matrices-can-be-thought-as-coordinate-systems&quot;&gt;this&lt;/a&gt; question, a few new terms that I had never heard of came up. Note, I'm quite familiar with linear algebra, but I've never heard these terms in the context of linear algebra. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Comments like &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In my example, you can use the columns to get the basis vectors of the coordinate system it describes. &lt;em&gt;The columns are in the coordinate system of whatever the &lt;strong&gt;parent coordinate system&lt;/strong&gt; is. If there is no parent coordinate system, they are in global space. Else, they are in the coordinate system of the parent.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What's a parent coordinate system? When is this term used? Why is it called a parent coordinate system?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the author of the comment tries to explain me the meaning as follows:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Matrices can be parented off of each other, but that is probably too confusing to visualize as you are just trying to learn things. Just imagine that if there was a matrix hierarchy, that all the matrices are multiplied together into one matrix M then you can ignore hierarchies.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This hasn't really cleared things up. What is it mean that &lt;em&gt;matrices can be parented off of each other&lt;/em&gt;? What is it meant by &lt;em&gt;matrix hierarchy&lt;/em&gt;? &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I know that if you have $m$ $A_1, A_2, \cdots, A_m \in \mathbb{R}^{n \times n}$ matrices which represent transformations, any combination of products of these matrices represents clearly a new transformation. For example, say that $A_1 * A_2 = B_{12}$. Suppose now that we have a vector $v \in \mathbb{R}^{n \times 1}$. Then the following two statements should clearly be equivalent&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$A_1 * A_2 * v$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$B_{12} * v$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but the transformations used are different, i.e., in one case we use two single transformations (i.e., $A_1$ and $A_2$) and in the other case we use only one transformation, namely $B_{12}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I don't know if this has something to do with &quot;parent coordinate systems&quot;, but I just wanted to show you a few things that I'm suspecting could be related to this terminology and concepts of computer graphics.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Final question would be: does it make sense to talk just about &quot;parent &lt;em&gt;coodinate systems&lt;/em&gt;&quot; or does it also make sense to talk about &quot;parent vector spaces&quot;? Why?&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-04-24T10:18:52.637" Title="What's a parent vector space or coordinate system?" Tags="&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4533" PostTypeId="2" ParentId="4511" CreationDate="2017-01-13T14:48:55.407" Score="1" Body="&lt;p&gt;&lt;strong&gt;&lt;em&gt;&quot;Downscaling by skipping rows and columns – any example images?&quot;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You asked for example images: The following is a sequence of 50 frames from a well known (and hopefully freely available) sequence, subsampled as you suggested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think you might find simply subsampling/decimating to be a bit too noisy. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are you sure you can't at least do some box filtering?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AZjl1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AZjl1.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-01-13T15:40:26.613" LastActivityDate="2017-01-13T15:40:26.613" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4534" PostTypeId="2" ParentId="4532" CreationDate="2017-01-13T15:47:09.850" Score="4" Body="&lt;p&gt;You have to step outside the world of mathematics for a while and look at what we are trying to achieve. Mathematics in its purest form only tells us what kinds of properties certain constructs have, it does not tell us why and how that would be useful.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;The modeler's perspective on things&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;So we have to look at the problem from modeling perspective. In this perspective it is mostly irrelevant how the mathematics work. As long as it provides the modeler with a system that yields with a understandable toolset to do his work everything is as it should be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is frequently beneficial to describe things such as physical objects (creatures, mechanisms etc.), forces or any number of other things independent of each other. Either because it's easier to think in one orientation or just simply because you want to move/rotate/scale objects out of convenience.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice you want at minimum that the camera is separated from the rest of the objects. While in more complex cases you want to have a more rich system. For example a bug is walking straight ahead on a straw. For practical reasons it would be neat if the bug only move forward in relation to the straw while the straw sways in the wind in relation to the world and the camera is independent of the straw. Similar modeling cases happen a lot, in human hands, robotics, car simulations, Finite object modeling etc.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Computational perspective&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The rendering and other functions need to be able to transform elements from these modeling hierarchies to each other. For example you need to know the point location in camera space to render. Preferably all this space transform happens automatically. For this purpose the modeler tells your application how the modeling elements are structured in relation to each other, a hierarchy, for modeler's benefit. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although this could be done in any number of ways it is commonly done with a tree structure, much like a filesystem with much the same effect. Each level stores in addition to tree information a affine matrix that describes the transform to its predecessor in the hierarchy. Mainly because this takes care of two core issues. The tree structure is easy to traverse and find the path to any other part. The matrices solve the problem of needing to do a lot of work transforming form a transform from one hierarchy space to another.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the user provides a tree where each object describes the transform required to transform the object to the coordinates of the object it is described in relation to, the parent. This parent in turn in turn describes the transform to its parent all the way to the world. Since all objects share one common ancestor, world, we can easily traverse the tree to find a transform path from any one coordinate system to another coordinate system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since linear transforms are invertible, we do not need to store a description separately for moving in the opposite direction, away from world towards the children/leaves of the tree structure. All we need to do is to invert the matrix. This is almost always needed as it's practical to describe camera as a separate object under the world, there is no reason to describe the cameras transform from world to camera just treat it like any other object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To compute a point from one space to another you do as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Use the tree to find a relationship between spaces.&lt;/li&gt;&#xA;&lt;li&gt;For each step on the way pre multiply your matrix/ or its inverse if you're traversing away from world. **&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Example:  You have the following hierarchy because it makes sense (this way you do not need to model each petal separately)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;World&#xA;  |&#xA;  +---- Flower&#xA;  |      |&#xA;  |      +--- Petal 1&#xA;  |      |&#xA;  |      +--- Petal 2&#xA;  |      |&#xA;  |      +--- Petal 3&#xA;  |&#xA;  +---- Track&#xA;         |&#xA;         +--- Boom&#xA;               |&#xA;               +--- Camera&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To render Petal 1 you need to transform the vertices of petal one into the camera object space and from there to perspective space etc. Your calculation would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;T_{\text{Perspective}} \cdot T_{\text{Camera}}^{-1} \cdot T_{\text{Boom}}^{-1} \cdot T_{\text{Track}}^{-1} \cdot T_{\text{Flower}} \cdot T_{\text{Petal 1}} \cdot \vec{v}_{\text{PetalPoint}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This way you can model a flower in a flowerpot totally independently from  from the robot shaking the camera about. At the same time freeing the modeler of the need to do complex trigonometric calculations, and in fact a big load of mathematics. Pretty neat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that you understand why, you should understand also that we do not have any limit to complexity of the hierarchy to &#xA;facilitate a broad range of things you could do. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This kind of hierarchy is called a scene graph and such things can be found in web pages, vector and CAD applications, many scientific modeling applications, most games.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This should answer why as well as the less exciting how.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Do we absolutely need these?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;No, we do not. We can dispense all the matrices and describe all of our data directly in the camera's final coordinates. It's just that this is horribly complicated in 98% of the cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice we need this hierarchy if we try to do even something more complex than a stationary box. Most of this deign is to make scene modelers' life easier. So that simple operations make more sense.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;* why do we call it a parent child relationship? Because it's a tree, and earliest tree graphs are genealogical studies, aka family trees. Where the previous level is simply the parents and the next one is their children. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;** or the other way around if you want to transpose your calculations.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorDisplayName="user246" LastEditDate="2017-04-24T10:18:52.637" LastActivityDate="2017-04-24T10:18:52.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4535" PostTypeId="1" AcceptedAnswerId="4566" CreationDate="2017-01-13T18:44:07.243" Score="7" ViewCount="1026" Body="&lt;p&gt;I need to implement translation, scaling and rotation gizmos and I'm having trouble with the rotation gizmo. Basically I don't know how to translate the mouse movement to determine in which direction to rotate the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By rotation gizmo (widget) I mean something like the below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LVQ2Y.jpg&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LVQ2Y.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the translation and scaling gizmos, which are represented as 3 axes, I do the following: I make a vector of the difference between the previous and current mouse position in screen space. Then multiply this vector by the inverse of the view and projection matrices, which gives me a vector of the mouse movement in world space. Then I take the dot product of the vector in world space with the  selected axis. This allows me determine if the mouse movement is in line with the axis or away from the axis. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I can't do the same thing for the rotation gizmo. The rotation gizmo is represented as 3 circles, each representing a rotation around an axis. Once a circle is clicked, I need to find some way to translate the mouse movement to determine which direction to rotate the object around the selected axis. I don't know how to do this. Please help.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is important to note that I am using color picking and not raycasting to determine where the gizmo was clicked. This means that I don't have the point at which the ray hits the gizmo in world space to start from. I mention this because I've looked at examples that use raycasting like libgizmo and I don't think I can do the same thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance for any help.&lt;/p&gt;&#xA;" OwnerUserId="5841" LastEditorUserId="56" LastEditDate="2017-01-13T18:55:57.740" LastActivityDate="2017-01-18T14:39:24.213" Title="How to translate mouse movement to a rotation gizmo?" Tags="&lt;3d&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4536" PostTypeId="2" ParentId="4521" CreationDate="2017-01-13T18:59:18.583" Score="3" Body="&lt;p&gt;From the presentations on non real time rendering I've seen at SIGGRAPH, the answer is basically yes, a lot of time is spent making render times faster.  For instance, even with huge amounts of ram, the amount of data needed to render a scene is larger than can fit in memory all at once, so strategies are developed to minimized disk access during the render process since it is so slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I have also seen a lot of effort and research put into simulations - such as realistic foamy ocean tidal wave simulations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess once the rendering is realistic, the next things to work on is the simulation that is being rendered.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-01-13T18:59:18.583" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4537" PostTypeId="1" AcceptedAnswerId="4539" CreationDate="2017-01-13T19:16:40.717" Score="22" ViewCount="6687" Body="&lt;p&gt;I've seen the term &lt;code&gt;st&lt;/code&gt; come up a few times when looking at other OpenGL fragment shaders. However, I don't know what it stands for or what it's used for. Here's an example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform vec2 u_resolution;&#xA;&#xA;vec2 st = gl_FragCoord.xy/u_resolution;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I can understand that this is converting the pixel coordinates into normalized coordinates of 0.0 - 1.0 instead of 640 x 480 (for example).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also seen things like &lt;code&gt;position.st&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does it mean?&lt;/p&gt;&#xA;" OwnerUserId="5843" LastActivityDate="2017-01-14T00:12:14.447" Title="What does &quot;st&quot; mean in the context of OpenGL?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4538" PostTypeId="1" CreationDate="2017-01-13T19:19:47.913" Score="2" ViewCount="587" Body="&lt;p&gt;I've been reading some code which setups a ray tracer and I've realized I've a doubt regarding what's a screen and what's a window in this context. Here's the relevant code using Qt:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;...&#xA;&#xA;void CCanvas::paint()&#xA;{&#xA;  // check if we have something to draw on&#xA;  if (!image) return;&#xA;&#xA;  // camera position&#xA;  Point3d camera (0.0, 0.0, 0.0);&#xA;&#xA;  // screen resolution&#xA;  int w = image-&amp;gt;width();&#xA;  int h = image-&amp;gt;height();&#xA;&#xA;&#xA;&#xA;  // horizontal opening angle&#xA;  double alpha = PI/2.0;&#xA;&#xA;  // horizontal window dimension [-X,X]&#xA;  double X = tan(alpha/2.0);&#xA;&#xA;  // pixel size&#xA;  double s = 2.0 * X / (double)w;&#xA;&#xA;  // vertical window dimension [-Y,Y]&#xA;  double Y = s * h / 2.0;&#xA;  ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I think I know what's the screen resolution: if we think of the screen as a matrix, &lt;code&gt;w&lt;/code&gt; and &lt;code&gt;h&lt;/code&gt; would be respectively the number of columns and rows in this &quot;matrix&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After obtaining the resolution of the image, we define an opening angle $\alpha$. I interpreted this opening angle as the opening angle of the camera, i.e., it defines basically what's visible from the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we compute &lt;code&gt;X&lt;/code&gt;, which is half of the horizontal window (according to the comments in the code). (&lt;strong&gt;&lt;em&gt;Note this &lt;code&gt;X&lt;/code&gt; is not the same X representing the x axis in the picture below.&lt;/strong&gt; Yes, whoever wrote this code had no common sense!&lt;/em&gt;) &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Now, mathematically I understood these calculations, &lt;em&gt;what I don't understand is the difference between $2X$ and $w$&lt;/em&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the &quot;window&quot; here the same thing as &quot;screen&quot;? &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I've this picture here&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H9Ye3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H9Ye3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've added the $X=\tan \left( \frac{\alpha}{2}\right)$ to the picture according to what I think $X$ is from the code above.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If the window is the same thing as the screen, I wonder why do we need $w$. I mean, couldn't we just decide how many rows and columns we have in the visible area?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Again, it's not clear if the visible area of the camera is the same thing as the screen or window...&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorDisplayName="user4718" LastEditDate="2017-01-13T22:09:35.867" LastActivityDate="2017-02-12T14:05:38.507" Title="Is there a difference between window and screen in computer graphics?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;ray&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4539" PostTypeId="2" ParentId="4537" CreationDate="2017-01-13T19:41:42.197" Score="30" Body="&lt;p&gt;The common names for the components of texture coordinates are U and V. However, because the next letter used (for 3D textures) is W, that causes a conflict with the names for the components of a &lt;em&gt;position&lt;/em&gt;: X, Y, Z, and &lt;strong&gt;W&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To avoid such conflicts, OpenGL's convention is that the components of texture coordinates are named S, T, and R. Thus, you have function calls like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameter(..., GL_TEXTURE_WRAP_S, GL_REPEAT);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;GL_TEXTURE_WRAP_S&lt;/code&gt; refers to wrapping in the S component of the texture coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, OpenGL picked S, T, and R long before GLSL and &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Data_Type_(GLSL)#Swizzling&quot;&gt;swizzle masks&lt;/a&gt; came around. R, of course, conflicts with &lt;strong&gt;R&lt;/strong&gt;, G, B, and A. To avoid such conflicts, in GLSL, the texture coordinate swizzle mask uses S, T, &lt;strong&gt;P&lt;/strong&gt;, and Q.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In GLSL, you can swizzle with XYZW, STPQ, or RGBA. They all mean exactly the same thing. So &lt;code&gt;position.st&lt;/code&gt; is exactly the same as &lt;code&gt;position.xy&lt;/code&gt;. However, you're not allowed to combine swizzle masks from different sets. So &lt;code&gt;position.xt&lt;/code&gt; is not allowed.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-01-14T00:12:14.447" LastActivityDate="2017-01-14T00:12:14.447" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4540" PostTypeId="1" AcceptedAnswerId="4543" CreationDate="2017-01-14T01:14:23.337" Score="1" ViewCount="43" Body="&lt;p&gt;In the paper &lt;a href=&quot;http://www3.cs.stonybrook.edu/~mueller/papers/EG06_geomfield.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real-time Reflection using Ray Tracing with Geometry Field&#xA;&lt;/a&gt;, it mentions this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A ray is represented&#xA;  by its two intersection points (in,out) with the bounding box&#xA;  of the surface. Hence, the geometry field is a 4 dimensional&#xA;  function.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Having two $3D$ points gives 6 values: $A=(A_x,A_y,A_z), B = (B_x, B_y, B_z)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is it that those 6 values, which are on the surface of a unit cube, can be represented with only 4 numbers?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: the best I can think of is to convert each point to spherical coordinates and throw away the length, effectively converting these points to points on a unit sphere.  That way involves some trig operations though. Is there a better way that uses less computation?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-01-14T02:14:35.530" LastActivityDate="2017-01-14T16:10:34.077" Title="Enter/Exit of unit cube representable as 4 numbers?" Tags="&lt;mathematics&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4541" PostTypeId="1" CreationDate="2017-01-14T07:44:08.223" Score="1" ViewCount="1028" Body="&lt;p&gt;Simply put, what does the transparency data of an EXR file represent? &lt;/p&gt;&#xA;" OwnerUserId="5847" LastActivityDate="2017-01-15T05:15:45.130" Title="Explanation of a the transparency of an .EXR file" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4542" PostTypeId="2" ParentId="4538" CreationDate="2017-01-14T13:04:20.307" Score="1" Body="&lt;p&gt;In this code, the &quot;screen resolution&quot; means the number of pixels in the output image (which happens to be a window in the windowing system), while the &quot;window dimension&quot; means the corresponding size in the 3D scene. Computing &lt;code&gt;s&lt;/code&gt; tells you the ratio between one unit of 3D space in your scene and one pixel of output image. You need to do this in order to know how far apart in world-space to cast your primary rays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These uses of &quot;screen&quot; and &quot;window&quot; aren't standard; they're specific to this code. No wonder you're confused.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-01-14T13:04:20.307" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4543" PostTypeId="2" ParentId="4540" CreationDate="2017-01-14T16:10:34.077" Score="4" Body="&lt;p&gt;3D object surface is 2D domain and can thus be parametrized with a 2D function. In case of a unit cube you could parametrize the surface for example by mapping each 6 faces to a 2D image strip. So if you know two points of the ray that intersects the cube, you can define it with 4D function using the parametrization&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-01-14T16:10:34.077" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4544" PostTypeId="1" CreationDate="2017-01-14T16:11:42.713" Score="1" ViewCount="85" Body="&lt;p&gt;I was looking at this Wikipedia article about the &lt;em&gt;image plane&lt;/em&gt; or the &lt;em&gt;screen space&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Image_plane&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Image_plane&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;and at a certain point there's&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A rectangular region of this plane, called the viewing window or viewport, maps to the monitor.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Here, by &quot;plane&quot; they are (I think) referring to the &lt;em&gt;image plane&lt;/em&gt; (or screen space); but I'm wondering now what do they mean here by monitor. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the monitor the same thing as the screen? Is the screen the plane in the monitor, but people in computer graphics usually say only &lt;em&gt;monitor&lt;/em&gt; to refer to the &lt;em&gt;screen&lt;/em&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, maybe first of all, what is intended by screen and monitor in computer graphics?&lt;/p&gt;&#xA;" OwnerDisplayName="user4718" LastEditorDisplayName="user4718" LastEditDate="2017-01-14T16:17:08.770" LastActivityDate="2017-01-14T17:42:46.897" Title="Are the terms screen and the monitor in computer graphics used interchangeably?" Tags="&lt;space&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4545" PostTypeId="2" ParentId="4544" CreationDate="2017-01-14T17:42:46.897" Score="1" Body="&lt;p&gt;The terms &lt;em&gt;screen&lt;/em&gt;, &lt;em&gt;monitor&lt;/em&gt;, and &lt;em&gt;display&lt;/em&gt; are used more or less interchangeably to refer to the real-world physical device that shows the image you're looking at. (They're not 100% interchangeable: &lt;em&gt;monitor&lt;/em&gt; means a discrete display device such as you'd use with a desktop PC. However, a built-in display such as the one in a laptop, tablet, or phone is never called a monitor.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;em&gt;image plane&lt;/em&gt; means the abstract geometric plane that identifies the surface of the display, but extends infinitely in all directions, i.e. isn't bounded by the edges of the display. The &lt;em&gt;viewport&lt;/em&gt; or &lt;em&gt;viewing window&lt;/em&gt; is the rectangle within this plane that identifies the edges of the display (or more generally, the edges of the image you're rendering, in case your app is running in a window and not fullscreen).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The term &lt;em&gt;screen&lt;/em&gt; might also be used more colloquially to mean various other things, such as: various coordinate systems on the image plane (&quot;screen space&quot;), the viewport or view frustum (&quot;the object is off-screen&quot;), the back buffer (&quot;render it to the screen&quot;), and probably more.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-14T17:42:46.897" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4546" PostTypeId="1" AcceptedAnswerId="4547" CreationDate="2017-01-15T00:37:15.240" Score="4" ViewCount="802" Body="&lt;p&gt;As stated in &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Image_formats&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation&lt;/a&gt; possible values for layout qualifiers of image formats are (for example floating point):&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Floating-point layout image formats:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;rgba32f&lt;/li&gt;&#xA;&lt;li&gt;rgba16f&lt;/li&gt;&#xA;&lt;li&gt;rg32f&lt;/li&gt;&#xA;&lt;li&gt;rg16f&lt;/li&gt;&#xA;&lt;li&gt;r11f_g11f_b10f&lt;/li&gt;&#xA;&lt;li&gt;r32f&lt;/li&gt;&#xA;&lt;li&gt;r16f&lt;/li&gt;&#xA;&lt;li&gt;rgba16&lt;/li&gt;&#xA;&lt;li&gt;rgb10_a2&lt;/li&gt;&#xA;&lt;li&gt;rgba8&lt;/li&gt;&#xA;&lt;li&gt;rg16&lt;/li&gt;&#xA;&lt;li&gt;rg8&lt;/li&gt;&#xA;&lt;li&gt;r16&lt;/li&gt;&#xA;&lt;li&gt;r8&lt;/li&gt;&#xA;&lt;li&gt;rgba16_snorm&lt;/li&gt;&#xA;&lt;li&gt;rgba8_snorm&lt;/li&gt;&#xA;&lt;li&gt;rg16_snorm&lt;/li&gt;&#xA;&lt;li&gt;rg8_snorm&lt;/li&gt;&#xA;&lt;li&gt;r16_snorm&lt;/li&gt;&#xA;&lt;li&gt;r8_snorm&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So we can use &lt;code&gt;R&lt;/code&gt;, &lt;code&gt;RG&lt;/code&gt; and &lt;code&gt;RGBA&lt;/code&gt; formats. But why &lt;code&gt;RGB&lt;/code&gt; (except r11f_g11f_b10f) is not allowed?&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-01-15T10:17:31.000" Title="Using RGB texture format for image load/store" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4547" PostTypeId="2" ParentId="4546" CreationDate="2017-01-15T01:27:00.053" Score="9" Body="&lt;p&gt;RGB8 format and similar are often not supported by GPUs (or only supported for a subset of GPU operations) because they don't have a power-of-two number of bytes per pixel. RGB8 would be 24 bits or 3 bytes per pixel. All the formats in that list have 1, 2, 4, 8, or 16 bytes per pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using a power of two simplifies addressing calculations in the hardware, because it can be implemented using a shift instead of a full multiply. (A shift by a fixed value such as 2 bits can even be implemented in hardware without any actual &quot;calculations&quot; at all, just by routing wires.) It also means that pixels are always nicely aligned with respect to boundaries of memory pages, cache lines, etc., which no doubt simplifies many things in the hardware.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2017-01-15T02:19:05.003" LastActivityDate="2017-01-15T02:19:05.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4548" PostTypeId="2" ParentId="4541" CreationDate="2017-01-15T03:12:52.950" Score="0" Body="&lt;p&gt;Generally, the &quot;a&quot; channel is referred to as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Glossary_of_computer_graphics#Alpha_channel&quot; rel=&quot;nofollow noreferrer&quot;&gt;alpha channel&lt;/a&gt;. It represents the amount of a pixel that an object covers. For computer-generated imagery this is pretty straightforward. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I generate a circle, parts of the circle on the interior will cover a full pixel, but parts on the edges of the circle may only cover a portion of the pixel. Internal pixels would have an alpha channel of 100%, whereas those edge pixels that only cover a portion of the pixel would have a value less than 100%. Outside the circle all pixels would have an alpha value of 0%.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For captured imagery, generally all pixels have an alpha value of 100%. However, if you use keying or matting tools to remove a green screen or blue screen, for example, there will be some pixels that are partially green (or blue), and they may end up with an alpha value between 0% and 100%. pixels that are solid green (or blue) will have an alpha value of 0%, and pixels that contain no green (or blue) will have an alpha value of 100%.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is used when you want to composite one image over another. For normal compositing, you will mix the top and bottom pixels by multiplying the color value of the top pixel by its coverage or alpha, multiplying the color value of the bottom pixel by the inverse of the alpha (1.0 - alpha), and adding the two together. So it would look something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;composite = top * alpha + bottom * (1.0 - alpha)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2017-01-15T03:20:40.020" LastActivityDate="2017-01-15T03:20:40.020" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4550" PostTypeId="1" AcceptedAnswerId="4558" CreationDate="2017-01-15T03:25:32.707" Score="4" ViewCount="2756" Body="&lt;p&gt;As I understand, the back-buffer is used for rendering the image while the front-buffer is drawn on the screen. So if you have only one image to be drawn on the screen, then you only need to swap the buffers one time because in the second swap the image is already drawn and there is no point to draw the same image again. However, when I tried to swap buffers no more than 2 times the graphics slow down a lot and move the window from one position to another takes 10-20 seconds. My question is... Why?&#xA;How double-buffers works then?&lt;/p&gt;&#xA;" OwnerUserId="5852" LastActivityDate="2017-01-16T10:50:19.880" Title="How double-buffers works in opengl?" Tags="&lt;opengl&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4551" PostTypeId="1" AcceptedAnswerId="4555" CreationDate="2017-01-15T05:10:55.160" Score="5" ViewCount="125" Body="&lt;p&gt;I am trying to implement a physically based renderer, in OpenGL. I was planning to implement the Cook-Torrance BRDF. I read about radiance cubemaps (for reflections), like the one discussed &lt;a href=&quot;http://www.codinglabs.net/article_physically_based_rendering.aspx&quot;&gt;here&lt;/a&gt;, for example. I a bit confused however. My test environment is Sponza with some other models thrown in, where you can move the camera around freely. How would an environmental cubemap work with a scene like that, where there are arcades or similar architectural pieces, and other things in the way? Would there need be multiple cubemaps? &lt;/p&gt;&#xA;" OwnerUserId="5854" LastActivityDate="2017-01-15T13:27:00.043" Title="Trying to understand environmental cubemaps" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;brdf&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4552" PostTypeId="2" ParentId="4541" CreationDate="2017-01-15T05:15:45.130" Score="5" Body="&lt;p&gt;In an EXR, the convention is to store &lt;em&gt;associated alpha&lt;/em&gt;, also known as &lt;em&gt;premultiplied&lt;/em&gt;. The latter term however doesn't do justice to the nuances of the alpha format as compared to its evil distant cousin known as &lt;em&gt;unassociated alpha&lt;/em&gt;, aka &lt;em&gt;straight&lt;/em&gt; or &lt;em&gt;key&lt;/em&gt; alpha.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In an associated alpha image, two facets are represented via the RGB triplet and its associated alpha channel:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Occlusion.&lt;/li&gt;&#xA;&lt;li&gt;Emission.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In an associated alpha image, the alpha channel could be considered to represent a distillation of the geometry of occlusion covering a given pixel coordinate. 0.5 would represent a baked down 50% occlusion, while the RGB values would represent the degree of emission.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This also means that an RGBA triplet such as 0.0,12.4,10282.9,0.0 is entirely valid, and represents a pixel that is emitting and unoccluding. Naturally occuring things such as candles represent such a combination. Consider the following image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/aINLh.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aINLh.jpg&quot; alt=&quot;Candle flame with no shadow&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above image could not be created using unassociated alpha, and is symptomatic as to why ray tracing renderers cannot generate any alpha model other than associated alpha.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fundamental difference between the two alpha formats is defined by the two different over operations, as described by &lt;a href=&quot;http://ssp.impulsetrain.com/porterduff.html&quot; rel=&quot;noreferrer&quot;&gt;Porter Duff&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Associated alpha over:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;FG.RGB + ((1.0-FG.Alpha) * BG.RGB&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Unassociated alpha over:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(FG.Alpha * FG.RGB) + ((1.0-FG.Alpha) * BG.RGB&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The nuances of the difference mean that care should be taken when dealing with alpha and the RGB channels.&lt;/p&gt;&#xA;" OwnerUserId="5556" LastActivityDate="2017-01-15T05:15:45.130" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4553" PostTypeId="2" ParentId="4521" CreationDate="2017-01-15T07:44:37.087" Score="4" Body="&lt;p&gt;Since you've used the &quot;path tracing&quot; tag, I'm assuming you're thinking mainly about light transport. At SIGGRAPH 2015, there was a course on the topic of path tracing in movie production that may be interesting:&#xA;&lt;a href=&quot;https://sites.google.com/site/pathtracingrevolution/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://sites.google.com/site/pathtracingrevolution/&lt;/a&gt;&#xA;Some of the presenters point out unsolved challenges towards the end of their presentation, for example see the second to last slides in the presentations from Alexander Keller and Johannes Hanika.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there are challenges in rendering that are not necessarily tied to path tracing but also present in game engines. Triangle meshes as an approximation of smooth solid surfaces are one, the use of shading normals or even worse, bumped normals have been pointed out as a source of artifacts a long time ago: &lt;a href=&quot;https://pdfs.semanticscholar.org/7986/ebd7b5427bbe54edb7c0c9cf674fee817933.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;It's not really a rendering bug, you see...&quot;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-01-15T07:44:37.087" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4554" PostTypeId="1" CreationDate="2017-01-15T11:59:14.617" Score="5" ViewCount="601" Body="&lt;p&gt;I am converting some Unity3D scenes to a proprietary json format to be used by my OpenGL renderer that uses a different coordinate system from Unity's.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have multiple sets of {translation, rotation(quat), scale} pairs that describe some node transformations. The engine that uses them (Unity) uses the positive x-axis looking to the right, the positive y-axis looking up and the positive z-axis looking front.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to convert each pair into a {new_translation, new_rotation(quat), new_scale} in order to use them in my engine using the same coordinate convention with the z-axis inverted (positive z-axis looking back, the most common OpenGL convention).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should the new pairs be constructed?&lt;/p&gt;&#xA;" OwnerUserId="5855" LastActivityDate="2017-01-24T13:10:29.947" Title="How to convert decomposed transformations between different coordinate systems?" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4555" PostTypeId="2" ParentId="4551" CreationDate="2017-01-15T12:23:22.520" Score="5" Body="&lt;p&gt;Your confusion comes from fact that in some basic tutorials like one you point cubemap which is used for applying lighting is global and static - it does not come from actual geometry but from infite sky box which moves with camera position so it is valid everywhere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And there is nothing mentioned about second type - local cubemaps which are actually computed using local geometry and are valid only in point of their placement. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be approached using multiple local cubemaps and connecting them with local objects situated around them but what is problematic is that it generates seams between them especially for high frequency reflections, which you probably would like to test. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For now you can generate few local cubemaps - each one centered at one of your small objects and used on it. They would move with objects if you plan to change their position. They would take into account your local geometry and, if you render it, your global skybox or skydome. You can precompute these cubemaps each time you change the position of your objects or do it every frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to make your whole sponza reflective with high frequency, that's harder problem but one idea is to voxelize whole sponza with different mipmap voxel levels and then ray trace it as in voxel cone tracing technique. Voxelization could be done as precomputation but it is generally memory intensive.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-01-15T13:27:00.043" LastActivityDate="2017-01-15T13:27:00.043" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4556" PostTypeId="1" CreationDate="2017-01-15T14:22:32.480" Score="2" ViewCount="76" Body="&lt;p&gt;I need to generate an easy animation video in Python (I use PIL to create every frame, then combine them using &lt;code&gt;avconv&lt;/code&gt;). The animation is just an image being zoomed out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for i in xrange(zoom_length):&#xA;&#xA;    # zoom level on this step&#xA;    zoom = 1.0 - 1.0 * i * (max_zoom / zoom_length)&#xA;&#xA;    # &quot;size&quot; is the resulting video frame size&#xA;    # &quot;img.size&quot; is the source image size (around 2.5x bigger than the frame)&#xA;    anti_zoomed_frame_size = int(size[0] / zoom), int(size[1] / zoom)&#xA;    anti_zoomed_frame_margins = (img.size[0] - anti_zoomed_frame_size[0]) / 2, (img.size[1] - anti_zoomed_frame_size[1]) / 2&#xA;&#xA;    anti_zoomed_frame = img.crop(anti_zoomed_frame_margins +&#xA;                                 (anti_zoomed_frame_size[0] + anti_zoomed_frame_margins[0],&#xA;                                  anti_zoomed_frame_size[1] + anti_zoomed_frame_margins[1]))&#xA;&#xA;    frame = anti_zoomed_frame.resize(size, resample=Image.BILINEAR)&#xA;&#xA;    print i, img.size, anti_zoomed_frame_size, anti_zoomed_frame_margins&#xA;&#xA;    # frame No for debugging&#xA;    draw = ImageDraw.Draw(frame)&#xA;    draw.text((size[0] - 200, size[1] - 100), str(i), (0,0,0), font=font)&#xA;&#xA;    yield frame&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So what happens is I crop out of the source image a rectangle of size &lt;code&gt;frame_size / zoom&lt;/code&gt; , then I resize it &lt;code&gt;zoom&lt;/code&gt; times to get the needed frame size. &lt;code&gt;zoom &amp;lt;= 1.0&lt;/code&gt; so doing it in this order seems to be a good idea, though I also tried doing it the other way (resize, then crop).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway in both cases the resulting video is kind of shaking at times. It seems that the problem is in rounding the numbers. The math I'm doing inevitably leads to non-integers, yet PIL requires integers everywhere (also the resulting frame size is obviously a pair of integer constants). This rounding operation seems to affect the smoothness of the animation badly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How smooth zooming is implemented in real life? &lt;/p&gt;&#xA;" OwnerUserId="5856" LastActivityDate="2017-01-15T14:22:32.480" Title="smooth zoom animation formulas (and rounding numbers)" Tags="&lt;animation&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4557" PostTypeId="2" ParentId="4321" CreationDate="2017-01-15T16:50:15.950" Score="3" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;I have some colors in RGB in [0,1] and want to find a way to rate&#xA;their similarity, as percieved by a human.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This is a huge subject, and loosely is found under the banner of &lt;em&gt;colour appearance models&lt;/em&gt;. Why is it not strictly a more simple formation is due to the psychophysical nature of colour in that colour does not exist beyond the human organism.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;My first idea is to treat the RGB colors as XYZ points and calculate&#xA;their distance.&lt;/p&gt;&#xA;&lt;p&gt;Another idea I have is to treat the RGB values as a histogram and use&#xA;dot product to get a similarity value between them, where a larger&#xA;value is better.&lt;/p&gt;&#xA;&lt;p&gt;I know however, that not all of the color channels have the same&#xA;percieved brightness so maybe i ought to weight the color channels&#xA;differently for both cases?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Best advice is, much like cryptography, do not roll your own; you are likely to arrive at a sub-optimal system that will, in the best of cases, hit walls already hit by other researchers in the field. If you base your work on existing models and research, you might find it to be more accurate for your needs[1].&lt;/p&gt;&#xA;&lt;p&gt;One could point at the historical developments around CAMs, but it is easier here to suggest that you research the IPT colour encoding model and its cylindrical equivalent that models colourfulness and hue as an angle. The evolutions in the IPT model overcome most of the issues of the earlier Lab model, and simplifies some of the work involved in CIECAM02.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Another challenge to this may be that different displays will display&#xA;the same color values differently. Not sure if that's relevant in this&#xA;case.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;IPT, and every RGB colour space for that matter, are anchored in the 1931 CIE research. As such, these sorts of issues are solved at a lower level.&lt;/p&gt;&#xA;&lt;p&gt;[1] This expanded answer is due to Mr. Wolfe's comment below in an attempt to explain why rolling your own solution might be a sub-optimal approach.&lt;/p&gt;&#xA;" OwnerUserId="5556" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-01-15T20:55:49.967" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="4558" PostTypeId="2" ParentId="4550" CreationDate="2017-01-16T10:50:19.880" Score="5" Body="&lt;p&gt;Yes, the back buffer is for the GPU to write the frame that's in-progress, while the display controller sends the front buffer to the attached display. &lt;em&gt;Swapping&lt;/em&gt; buffers doesn't really copy anything these days. The display controller has a register which tells it the address of the frame buffer to display. Swapping buffers simply puts the address of the old back buffer in this register, making it the front buffer. You should only swap buffers when the frame is complete (i.e. you've finished drawing all the objects) and you want it to be displayed. This frame will continue to be displayed until you swap buffers again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In some configurations (e.g. in EGL it depends on what swap interval you set) swapping buffers will make the CPU wait (block) until the GPU has finished rendering that frame. In others, the CPU can continue to queue up draw calls for further frames.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-01-16T10:50:19.880" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4559" PostTypeId="2" ParentId="4535" CreationDate="2017-01-16T11:53:27.893" Score="2" Body="&lt;p&gt;Map the mouse position to the circle by drawing an imaginary line between the mouse and the center of the gizmo on the plane of the current circle. Do this for the start and current positions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can easily get the quaternion rotation around the center from the start to the end by doing &lt;code&gt;normalize(quat(1+dot(v_1, v_2), cross(v_1, v_2)))&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This works because the dot product is the cos of the angle between the vectors and the cross is the vector perpendicular to the 2 vectors (aka the rotation angle) and has length of the sin of the angle between the vectors. This means that you can create the double quaternion out of them. Then you can nlerp that double quaternion with the unit quaternion to get the rotation you need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However with that information you can do an arcball by projecting the mouse onto the ball that is the gizmo and using the start and end vectors that way.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-01-16T11:53:27.893" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4562" PostTypeId="1" AcceptedAnswerId="4563" CreationDate="2017-01-16T23:51:58.473" Score="14" ViewCount="3612" Body="&lt;p&gt;I am pretty confused about that function. &lt;a href=&quot;http://www.glfw.org/docs/latest/group__context.html#ga1c04dc242268f827290fe40aa1c91157&quot; rel=&quot;noreferrer&quot;&gt;GLFW Context reference&lt;/a&gt; says as follow:&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;This function makes the OpenGL or OpenGL ES context of the specified&#xA;  window current on the calling thread. A context can only be made&#xA;  current on a single thread at a time and each thread can have only a&#xA;  single current context at a time.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But it does not help me much.&lt;br /&gt;&#xA;Can it work like &lt;a href=&quot;https://stackoverflow.com/q/9758884/5744858&quot;&gt;&lt;code&gt;glBind-&lt;/code&gt;&lt;/a&gt; methods? (glBindBuffer, glBindVertexArray and so on)&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-01-17T00:31:17.157" Title="What does &quot;makeContextCurrent&quot; do exactly?" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4563" PostTypeId="2" ParentId="4562" CreationDate="2017-01-17T00:05:26.303" Score="24" Body="&lt;p&gt;OpenGL is a state machine. An OpenGL context holds that state. The state contains information such as which textures are bound to which texture units, which attachments the current FBO has, and things like that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you set the current context, you are switching all the state from the old context to the new context. Here's an example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glfwMakeContextCurrent(window1);&#xA;glEnable(GL_TEXTURE_2D);&#xA;glBindTexture(GL_TEXTURE_2D, texture1);&#xA;&#xA;glfwMakeContextCurrent(window2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What this does is makes the context of &lt;code&gt;window1&lt;/code&gt; current. It then enables the 2D texture unit and binds &lt;code&gt;texture1&lt;/code&gt; to it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next it makes the context of &lt;code&gt;window2&lt;/code&gt; current. If you were to check the enabled state of &lt;code&gt;GL_TEXTURE_2D&lt;/code&gt; it would be false (unless you had previously enabled it on the &lt;code&gt;window2&lt;/code&gt; context). Likewise, if you check which texture is bound to the 2D texture unit, you would likely find no texture was bound, or some texture other than &lt;code&gt;texture1&lt;/code&gt; was bound.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically all drawing happens in the current context. If you make a different context current, then all drawing will now happen in that context.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is common to have a single context per thread in a multi-threaded OpenGL application. That way each thread is drawing into its own context and doesn't mess up the state of contexts on other threads.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-01-17T00:05:26.303" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4564" PostTypeId="1" CreationDate="2017-01-17T09:20:48.213" Score="1" ViewCount="63" Body="&lt;p&gt;In shaders, when using &lt;code&gt;SampleLevel&lt;/code&gt; intrinsic, if we pass &lt;code&gt;0.5&lt;/code&gt; in the mip level parameter, and the sampler is a &lt;code&gt;point sampler&lt;/code&gt;, what mip level is selected ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to this blog: &lt;a href=&quot;https://blogs.msdn.microsoft.com/shawnhar/2009/09/14/texture-filtering-mipmaps/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blogs.msdn.microsoft.com/shawnhar/2009/09/14/texture-filtering-mipmaps/&lt;/a&gt;&lt;br&gt;&#xA;It seems as if the coarser level of &lt;code&gt;1&lt;/code&gt; is selected, so that would be a &lt;code&gt;ceil&lt;/code&gt; operation going on internally.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I still ask because the wording in the blog:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;rounds up to the next larger mip level&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Is open to interpretation, that could mean the larger in dimensions, therefore finer.&lt;br&gt;&#xA;And honestly it feels that using &lt;code&gt;ceil&lt;/code&gt; is a very unfair convention for the &lt;code&gt;mip 0&lt;/code&gt;, which can only be selected with exactly &lt;code&gt;0.0&lt;/code&gt;, poor thing.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2017-01-17T09:20:48.213" Title="Rounding rules for mip level with point sampling" Tags="&lt;shader&gt;&lt;directx&gt;&lt;mipmap&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4565" PostTypeId="1" AcceptedAnswerId="4577" CreationDate="2017-01-17T15:58:03.663" Score="2" ViewCount="108" Body="&lt;p&gt;I need to write a function (in Javascript) that accepts the endpoints of a line segment and an additional point and returns coordinates for the point relative to the start point. So, based on this picture:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TESQW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TESQW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function perpendicular_coords(x1,y1, x2,y2, xp,yp)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;returns &lt;code&gt;[xp',yp']&lt;/code&gt; where xp' is the distance from (xp,yp) along a line perpendicular to the line segment, and yp' is the distance from (x1,y1) to the point where that perpendicular line intersects the line segment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I've tried so far:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function rotateRad(cx, cy, x, y, radians) {&#xA;    var cos = Math.cos(radians),&#xA;        sin = Math.sin(radians),&#xA;        nx = (cos * (x - cx)) + (sin * (y - cy)) + cx,&#xA;        ny = (cos * (y - cy)) - (sin * (x - cx)) + cy;&#xA;    return [nx, ny];&#xA;}&#xA;&#xA;[xp', yp'] = rotateRad(x1,y1, xp, yp, Math.atan2(y2-y1,x2-x1));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't really understand the function; got it from &lt;a href=&quot;https://stackoverflow.com/a/17411276/1368860&quot;&gt;https://stackoverflow.com/a/17411276/1368860&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5871" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-01-19T12:50:29.113" Title="translate coordinates relative to line segment" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4566" PostTypeId="2" ParentId="4535" CreationDate="2017-01-17T17:54:11.663" Score="2" Body="&lt;p&gt;Ratchet Freak's answer might work. I'm not sure, I didn't spend much time on it because I didn't know how to create the quaternion from the dot and cross product as described.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What we ended up doing was:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Project the center of the gizmo to screen space.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Get the angle between the vectors GizmoToLastMouse and GizmoToCurrentMouse using the dot product formula: acos(Dot(GizmoToLastMouse, GizmoToCurrentMouse) / (GizmoToLastMouse.Length() * GizmoToCurrentMouse.Length()))&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Get the sign of the angle by taking the cross of the GizmoToLastMouse and GizmoToCurrentMouse and dotting it with the screen normal.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Get another sign (times 1.0f or -1.0f) based on the orientation of the gizmo, by taking the dot product between the rotated axis and a vector from the center of the gizmo to the camera&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Apply the rotation based on the angle and the two signs to the appropriate axis&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There might be a better way to do it, but this works pretty well for our needs.&lt;/p&gt;&#xA;" OwnerUserId="5841" LastEditorUserId="5841" LastEditDate="2017-01-18T14:39:24.213" LastActivityDate="2017-01-18T14:39:24.213" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4568" PostTypeId="1" AcceptedAnswerId="4570" CreationDate="2017-01-17T20:27:31.020" Score="3" ViewCount="718" Body="&lt;p&gt;I know that when you call glVertexAttribPointer, you are specifying how the buffer currently binded should take its own data. But if you can have binded one buffer per type (Let's say GL_ARRAY_BUFFER and GL_ELEMENT_ARRAY_BUFFER) then, Are you specifying two buffers simultaneously? In &lt;a href=&quot;http://alfonse.bitbucket.org/oldtut/Basics/Tut01%20Following%20the%20Data.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; tutorial says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;glVertexAttribPointer always refers to whatever buffer is bound to&#xA;  GL_ARRAY_BUFFER at the time that this function is called. Therefore it&#xA;  does not take a buffer object handle; it simply uses the handle we&#xA;  bound previously.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If glVertexAttribPointer refers to the GL_ARRAY_BUFFER buffer currently binded, How I call glVertexAttribPointer for the GL_ELEMENT_ARRAY_BUFFER buffer?&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="5852" LastEditDate="2017-01-17T20:37:53.040" LastActivityDate="2017-01-18T14:54:25.577" Title="How glVertexAttribPointer works?" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4569" PostTypeId="1" CreationDate="2017-01-17T21:31:44.923" Score="3" ViewCount="66" Body="&lt;p&gt;I'm running a Python program whose GUI uses OpenGL. I'm getting all sorts of graphics error messages. I want to check the OpenGL version to make sure it's all good, but the OpenGL Extensions Viewer doesn't work. Even as admin, the extensions viewer just fails when I try to open it (and the install fails when I'm not admin).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, how do I access info about OpenGL's current status on my machine without using that program? I looked all over and didn't see any real alternatives. I'm using Windows 7, Intel Xeon CPU, X5680 3.33GHz (x2), 24 GB RAM, NVIDIA Quadro 4000.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that I'm not an OpenGL programmer -- I work in Python and I use PyQt etc. So, I'd like to find a solution to this without needing a Visual tutorial...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks, and sorry if this question is too basic/in the wrong place!&lt;/p&gt;&#xA;" OwnerUserId="5874" LastActivityDate="2017-01-17T21:31:44.923" Title="Super basic question: OpenGL version/install issue" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4570" PostTypeId="2" ParentId="4568" CreationDate="2017-01-17T21:52:15.573" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;How I call glVertexAttribPointer for the GL_ELEMENT_ARRAY_BUFFER buffer?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You don't. The element array buffer is used to store vertex indices, not vertex attribute data and therefore it doesn't have attribute pointers. The count, size, and offset for index data is specified in the draw call, e.g. &lt;code&gt;glDrawElements&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-17T21:52:15.573" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4571" PostTypeId="2" ParentId="4568" CreationDate="2017-01-18T14:54:25.577" Score="4" Body="&lt;p&gt;A VAO holds the attribute information. This means that for each attribute it has a buffer, offset, size, type, stride and whether it's normalized. Separately from those is the element buffer binding that is set by binding the &lt;code&gt;GL_ELEMENT_ARRAY_BUFFER&lt;/code&gt; while the VAO is bound.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes that odd but the reason this is the case is because VAO's were added after VBO and EBO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 4.5 (or with the Direct_state_access extension) you can instead use &lt;code&gt;glVertexArrayElementBuffer&lt;/code&gt; to directly set the element buffer of a vao.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-01-18T14:54:25.577" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4572" PostTypeId="1" CreationDate="2017-01-19T06:21:57.630" Score="4" ViewCount="952" Body="&lt;p&gt;After reading about the new &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;noreferrer&quot;&gt;Disney Diffuse BRDF&lt;/a&gt;, I have been wondering if this is currently the best Diffuse BRDF at the moment? How much more of a difference would this make compared to using a Lambertian BRDF? I have heard of other BRDFs such as Hanrahan-Krueger and Oren-Nayar, are these also better? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MyOOc.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MyOOc.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-01-19T06:21:57.630" Title="Better alternatives to the Lambert BRDF" Tags="&lt;brdf&gt;&lt;physically-based&gt;&lt;diffuse&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4573" PostTypeId="1" AcceptedAnswerId="4579" CreationDate="2017-01-19T06:45:09.883" Score="5" ViewCount="3251" Body="&lt;p&gt;I am currently following a tutorial at Scratchapixel.com on &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/reflection-refraction-fresnel&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;refraction&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the &lt;strong&gt;refract function&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3f refract(const Vec3f &amp;amp;I, const Vec3f &amp;amp;N, const float &amp;amp;ior) &#xA;{ &#xA;    float cosi = clamp(-1, 1, dotProduct(I, N)); &#xA;    float etai = 1, etat = ior; &#xA;    Vec3f n = N; &#xA;    if (cosi &amp;lt; 0) { cosi = -cosi; } else { std::swap(etai, etat); n= -N; } &#xA;    float eta = etai / etat; &#xA;    float k = 1 - eta * eta * (1 - cosi * cosi); &#xA;    return k &amp;lt; 0 ? 0 : eta * I + (eta * cosi - sqrtf(k)) * n; &#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; I understand that if there is no total internal reflection, &lt;strong&gt;first we must find the refraction direction&lt;/strong&gt; (&lt;code&gt;ior&lt;/code&gt; is the object's index of refraction):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3f refractionDirection = refract(dir, hitNormal, isect.hitObject-&amp;gt;ior).normalize(); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; We then compute the &lt;strong&gt;refraction ray origin&lt;/strong&gt; (which is the point where the ray will leave the object?) &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3f refractionRayOrig = outside ? hitPoint - bias : hitPoint + bias; &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; Finally to get the refracted ray color we cast a ray using the &lt;code&gt;refractionDirection&lt;/code&gt; &amp;amp; &lt;code&gt;refractionRayOrig&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;refractionColor = castRay(refractionRayOrig, refractionDirection, objects, lights, options, depth + 1); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So far I understand how a glass block (or any other transparent object which undergoes refraction) bends the light towards the normal when entering the object and then away from the normal when exiting but &lt;strong&gt;I am confused as to how refraction works or is computed when there is another object in the medium as shown in the image below.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/c6p4j.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c6p4j.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when the ray hits the object from the inside do we use a BRDF to calculate the surface properties and then that ray leaves the glass block with the refraction origin and direction?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2017-01-21T13:29:10.300" LastActivityDate="2017-01-21T13:29:10.300" Title="Refraction in a Ray Tracer: What do with an intersection within the medium?" Tags="&lt;lighting&gt;&lt;brdf&gt;&lt;reflection&gt;&lt;refraction&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4574" PostTypeId="2" ParentId="4573" CreationDate="2017-01-19T07:52:29.097" Score="5" Body="&lt;p&gt;You need to spawn a new ray at each IOR interface. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So let's say your ray hits the surface of the glass object. You spawn a new ray from the intersection point along the new IOR direction for air-&gt;glass interfaces, this new ray is inside the glass. This ray will then either hit a solid object or the interior surface of the glass. If we hit a solid object we can light it as normal. If the ray exits the glass, you spawn a new ray again at the exit point but now using the Glass-&gt;air IOR. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also have cases for total-internal reflection where the exiting ray is reflected back inside instead of leaving the glass, same principle applies, generate a new ray from the intersect position using the reflected direction.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-01-19T07:52:29.097" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4576" PostTypeId="2" ParentId="4507" CreationDate="2017-01-19T10:59:57.347" Score="0" Body="&lt;p&gt;I have successful developed an algorithm with the help of a Kd-tree and a simple test for overlapping lines. Here is a result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/X8Igv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X8Igv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5828" LastActivityDate="2017-01-19T10:59:57.347" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4577" PostTypeId="2" ParentId="4565" CreationDate="2017-01-19T12:50:29.113" Score="0" Body="&lt;p&gt;I got a good answer on StackOverflow: &lt;a href=&quot;https://stackoverflow.com/questions/41701713/translate-coordinates-relative-to-line-segment/41702475#41702475&quot;&gt;https://stackoverflow.com/questions/41701713/translate-coordinates-relative-to-line-segment/41702475#41702475&lt;/a&gt; from &lt;a href=&quot;https://stackoverflow.com/users/1579780/giladd&quot;&gt;https://stackoverflow.com/users/1579780/giladd&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function perpendicular_coords(x1, y1, x2, y2, xp, yp) {&#xA;  var dx = x2 - x1,&#xA;      dy = y2 - y1;&#xA;&#xA;  //find intersection point    &#xA;  var k = (dy * (xp-x1) - dx * (yp-y1)) / (dy*dy + dx*dx);&#xA;  var x4 = xp - k * dy;&#xA;  var y4 = yp + k * dx;&#xA;&#xA;  var ypt = Math.sqrt((y4-y1)*(y4-y1)+(x4-x1)*(x4-x1));&#xA;  var xpt = distance(x1, y1, x2, y2, xp, yp);&#xA;  return [xpt, ypt];&#xA;}&#xA;&#xA;// Distance of point from line&#xA;function distance(x1, y1, x2, y2, xp, yp) {&#xA;  var dx = x2 - x1;&#xA;  var dy = y2 - y1;&#xA;&#xA;  return Math.abs(dy*xp - dx*yp + x2*y1 - y2*x1) / Math.sqrt(dy*dy + dx*dx);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5871" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-01-19T12:50:29.113" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4578" PostTypeId="1" CreationDate="2017-01-19T21:44:33.960" Score="2" ViewCount="411" Body="&lt;p&gt;I am trying to get a normal of a triangle on a sphere, however the normal equations (straight line) give the wrong answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the points:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(-986.786743, -93.348259, -132.439041)\\&#xA;(210.731644, -534.785583, -818.290039)\\&#xA;(637.734985, -449.826904, -553.501648)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;on a radius $1000$ sphere, the average point (straight line) is $(-0.074536, -0.580873, -0.810574) * 1000$, which is visibly incorrect on a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The triangle's normal normalized to distance $1000$ gives: $(0.086455, 0.899604, -0.428062) * 1000$ which is different from the average value above (which would have also given a normal) and also far off from the spherical triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I was trying to unwrap a mesh into a globe to map it to a texture. I needed to know if triangles were upside down using normals.&lt;/p&gt;&#xA;" OwnerUserId="5882" LastEditorUserId="5884" LastEditDate="2017-01-25T01:46:54.440" LastActivityDate="2018-04-24T07:44:40.820" Title="Average point on sphere between 3 other points (spherical triangle)" Tags="&lt;computational-geometry&gt;&lt;mathematics&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4579" PostTypeId="2" ParentId="4573" CreationDate="2017-01-19T22:21:26.007" Score="7" Body="&lt;p&gt;this is an interesting question (and I am actually an author on Scratchapixel so I can maybe help on that one)). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things go as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;you cast the primary ray into the scene&lt;/li&gt;&#xA;&lt;li&gt;the ray hits the glass which is a refractive-reflective/transparent material&lt;/li&gt;&#xA;&lt;li&gt;you compute and cast two rays from the point of intersection: a reflective ray and a refractive ray&lt;/li&gt;&#xA;&lt;li&gt;if the refractive ray hits an object contained in the transparent object (the glass) then you need to shade that object too. So if it's a plastic material, compute the result of that shader (including the lighting, so loop over all lights and add their contribution, etc.)&lt;/li&gt;&#xA;&lt;li&gt;the color at the intersection point can finally be computed as a mix between the reflection and the refraction color (where as the mix is driven by the fresnel effect).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Now that works but this is essentially &lt;strong&gt;wrong&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why? Because in fact light rays too are bent by say glass and water. So in fact when you cast a shadow ray from a point on the pen in the direction of the light, this ray direction is in fact wrong, since you should account for refraction and reflection (the ray should be bent when it goes from one medium to another in this case from water to air) but this is impossible to do with this algorithm/approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though in general this gives acceptable results so no one cares much but if your goal is really a physically plausible image then this approach is wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A solution to this maybe is to use photon mapping, where photons of light are cast from the light into the scene in a pre-pass. Thus when a light-photon hits the glass/water surface it will bent due to the law of refraction and eventually it will be &quot;deposited&quot; onto the pen. This is a bit hard to explain here but hopefully there will be a lesson on Scratchapixel about this in the future. Hope it helps.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;EDIT&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;&gt; Thanks for clarifying, I had one other issue though. In the source code provided on the website for that lesson there doesn't seem to be code present to spawn a ray when the light ray leaves the glass cylinder. Is this unnescessary or is it actually already present? If it is could you point out where in the code?&lt;/em&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hum it seems like my explanation wasn't clear if you ask this question. When the refractive ray hits the surface of the pen you need to compute the color of the pen at that intersection point (where the refractive ray intersected the pen's geometry). Now the pen is made out of wood for example which for the sake of simplicity is a diffuse material only (no specular). So in order to compute the color of the pen at the intersection point, you simply execute the traditional illumination loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3f computePenColor(const Vec3f&amp;amp; objectColor, const Vec3f&amp;amp; intersectionPoint, normalAtIntersection) {&#xA;    Vec3f shadedPointColor = 0;&#xA;    // loop over all lights in the scene to cadd their contribution&#xA;    for (i = 0; i &amp;lt; scene.lights.size(); ++i) {&#xA;        Light currentLight = scene.lights[i];&#xA;        // let's say this light source is a point light source&#xA;        Vec3f lightDirection = currentLight.position - intersectionPoint;&#xA;        // this cast a shadow ray from the shaded point to the light position&#xA;        // if this ray intersects an object along the way then this point is in the shadow of this light and the function returns true&#xA;        bool shadow = castShadowRay(lightDirection.length(), lightDirection.normalize());&#xA;        // this point is not in the shadow of the light so add its contribution&#xA;        if (!shadow) {&#xA;            // the object is diffuse so apply cosine law only&#xA;            shadedPointColor += max(0, normalAtIntersection.dot(lightDirection)) * currentLight-&amp;gt;intensity * currentLight-&amp;gt;color; &#xA;        }&#xA;    }&#xA;    return shadedPointColor * objectColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So maybe as you can see more clearly from this example, is that when I say &quot;cast a ray from the point of intersection to the light&quot; I mean cast a shadow ray. This shadow ray helps to determine if the shaded point is in the shadow of that light. If not, then you can add the contribution of that light to the shaded point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can also see that the direction of this shadow ray is computed as the position of the point on the pen (the intersection point or shaded point) to the light position (we assume a point light source here for simplicity). So this is a &lt;strong&gt;straight line&lt;/strong&gt; between the point on the pen and the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this where things are wrong. This &lt;strong&gt;shoudn't&lt;/strong&gt; be a straight line, since when the &quot;shadow ray&quot; (which is also a light ray but we go from the point on the pen to the light rather than from the light to the pen, but in essence they are the same thing) exits the water volume it should be bent due to refraction (and part of it should be reflected to). You can compute this new direction if you wish, but then if the shadow ray is bent when it leaves the volume of water then it won't travel in the direction of the light anymore (as showed in the pic below), so you can't use it as a shadow or light ray any longer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So this algorithm that consists of looping over the lights and casting shadow ray can't be used if you &lt;strong&gt;really&lt;/strong&gt; want to account for light ray bending due to reflection and refraction. Though as I said few people care about that because in reality, ignoring this fact, doesn't make much of a visual difference in 99% of cases. And as I pointed out, the solution to &lt;strong&gt;get it right&lt;/strong&gt; if really needed is something like photon mapping where photon of lights are cast from the light into the scene into a pre-pass, which allows to follow the paths of light rays into the scene as they are being bent by refractive/reflective surfaces. But photon mapping is a rather complex algorithm to implement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ADgso.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ADgso.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="1608" LastEditDate="2017-01-20T09:23:19.177" LastActivityDate="2017-01-20T09:23:19.177" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4580" PostTypeId="2" ParentId="4578" CreationDate="2017-01-19T22:32:22.790" Score="2" Body="&lt;p&gt;If i read you right, you have a triangular patch which is on the surface of a sphere - so the triangle isn't really a true triangle in that it isn't flat, but instead is just made up of 3 points on a sphere connected by lines across the spheres surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also if I understand you correctly, you have a point on this triangle that you want to get the normal at.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all that is right, the way to get the normal is to subject subtract the origin from your point on the triangle (since it is also a point on the sphere) and normalize it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The normal at any point on a sphere is parallel to the point from the center of the sphere to that point on the surface. &lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-01-19T22:32:22.790" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4581" PostTypeId="2" ParentId="4578" CreationDate="2017-01-20T00:51:17.867" Score="1" Body="&lt;p&gt;The triangle spans from one side of the sphere to the other so using straight line equations is very inaccurate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think I can figure it out like so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The centroid of a triangle is where its medians intersect:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.mathopenref.com/trianglemedians.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Median of a triangle - math word definition | Math Open Reference&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So use the equations given elsewhere to find the shortest path between two points on a sphere for all the vertices, and get the intersection between two midpoints on those with the opposing vertices to get two curves along the sphere and their point intersection.&lt;/p&gt;&#xA;" OwnerUserId="5884" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:44:40.820" LastActivityDate="2018-04-24T07:44:40.820" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4583" PostTypeId="2" ParentId="4532" CreationDate="2017-01-20T11:42:58.187" Score="2" Body="&lt;p&gt;First start to be sure you understand what matrices are (4x4 which are the most common in CG).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) about your first question. You are taking about a hierarchy of transforms. I don't know if you use Maya at all, but if you do, you know you can for example create a sphere and group this sphere. So you have:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Group1&#xA;   |&#xA;   --Sphere1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That's the a hierarchy where &lt;code&gt;Group1&lt;/code&gt; is the parent of &lt;code&gt;Sphere1&lt;/code&gt;. What does that mean is that if you move &lt;code&gt;Group1&lt;/code&gt; then &lt;code&gt;Sphere1&lt;/code&gt; will move with it. If you move &lt;code&gt;Sphere1&lt;/code&gt; instead, then of course &lt;code&gt;Sphere1&lt;/code&gt; will move but &lt;code&gt;Group1&lt;/code&gt; will stay where it is. That's what parenting is used for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I as mentioned you can apply a transform to &lt;code&gt;Group1&lt;/code&gt; as well as a transform to &lt;code&gt;Sphere1&lt;/code&gt; and transforms as you know can be expressed as 4x4 matrices. So &lt;code&gt;Group1&lt;/code&gt; has a 4x4 matrix to represent its transformation (scale, rotation, translation) and &lt;code&gt;sphere1&lt;/code&gt; has one too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) so the sphere is affected by the matrix applied to &lt;code&gt;Group1&lt;/code&gt; (since it is parented to &lt;code&gt;Group1&lt;/code&gt;) and the matrix applied to the sphere itself do you agree? If you want to transform the sphere then you need to apply both transformation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Sphere_Final_Rot_Scale_Trans = Sphere_Default_Scale_Rot_Trans * Mgroup1 * Msphere1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;Mgroup1&lt;/code&gt; is the 4x4 matrix of &lt;code&gt;Group1&lt;/code&gt; and &lt;code&gt;MSphere1&lt;/code&gt; is the 4x4 matrix of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However rather than multiplying the sphere by the 2 matrices, you can combine their effect into a single matrix. Just do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix44f Mcombined = Mgroup1 * Msphere1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is also called a matrix concatenation. Then you can do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Sphere_Final_Rot_Scale_Trans = Sphere_Default_Scale_Rot_Trans * Mcombined &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Simple! So all you need to know here is about matrix multiplication. Do you know that if you multiply 2 matrices together you get a third matrix that combines the effect of the first 2?&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="1608" LastEditDate="2017-01-20T15:47:25.677" LastActivityDate="2017-01-20T15:47:25.677" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4584" PostTypeId="1" CreationDate="2017-01-20T13:40:02.377" Score="1" ViewCount="45" Body="&lt;p&gt;The title says it all, given two convex patches, how to find points/faces that have distance &amp;lt; x?  Can I use GJK for this case?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Convex patches are obtained from convex decomposition, see &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.9.3141&amp;amp;rep=rep1&amp;amp;type=pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. If I read it correctly, I don't think methods used in that paper can give points/faces that satisfy above condition.&lt;/p&gt;&#xA;" OwnerUserId="2687" LastActivityDate="2017-01-21T11:18:33.813" Title="Given two convex patches, how to find points/faces that have distance &lt; x?" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4585" PostTypeId="1" AcceptedAnswerId="4589" CreationDate="2017-01-20T15:44:53.310" Score="4" ViewCount="4708" Body="&lt;p&gt;Are mirror-like reflections in computer graphics purely handled with ray-tracing/ray-casting techniques or are there some situations where they are achieved through rasterisation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/IYlur.jpg&quot; alt=&quot;example of raytraced reflection on a sphere&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="5887" LastEditorUserId="48" LastEditDate="2017-01-21T15:29:01.360" LastActivityDate="2017-01-21T15:29:01.360" Title="Mirror Reflections: Ray Tracing or Rasterisation?" Tags="&lt;raytracing&gt;&lt;rasterizer&gt;&lt;reflection&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4586" PostTypeId="2" ParentId="4585" CreationDate="2017-01-20T15:57:10.400" Score="3" Body="&lt;p&gt;This is one of the most common &quot;misconceptions&quot; on rendering, rasterisation and ray-tracing. Don't get me wrong. This is a good question, but one that should be answered once and for all. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to answer your question:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) it is much easier to simulate reflection and refraction with ray-tracing than with rasterisation, which is often why when you see an image produced with a ray-tracer you see spheres reflecting each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) the misconception (even among people working in the CG business) is that you can NOT produce reflection or refraction with rasterisation. In fact, you can.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally, ray-tracing/rasterisation have nothing to do with reflection or refraction or whatever else. These are two ways of solving a single problem which is to find out (in short) if two points in space are visible to each other (the visibility problem). Ray-tracing solves this problem in one way, rasterisation in an other. Rasterisation is very efficient at solving this problem from primary rays (or camera rays) and less efficient to solve this problem for secondary rays (reflection, refraction, shadows, etc.) than ray-tracing. Ray-tracing is slower than rasterisation for primary rays but offers a simpler solution for secondary rays compared to rasterisation. Yet ray-tracing is not good for solving problems like caustics, so this is far from being a solution to every problem in computer graphics. Yet rasterisation can be used (different techniques exist) to simulate reflections and refractions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am sorry to repeat myself &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4573/refraction-in-a-ray-tracer&quot;&gt;here&lt;/a&gt; but there are resources on the web that explain this well. I am tired of promoting the same ones all the time but Google &lt;code&gt;ray-tracing vs rasterisation&lt;/code&gt; (I have just done it) and you will stumble upon a couple of good ones. You now just need to make the effort to read.&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-01-21T10:53:32.483" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4587" PostTypeId="2" ParentId="4585" CreationDate="2017-01-20T16:46:45.810" Score="3" Body="&lt;p&gt;You can mimic a mirror by masking out the visible reflective surface when you first render and then mirror the world around the reflective plane and render again while only drawing where the reflective surface was.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are some other details to worry about like not drawing stuff on the far side of the mirror when drawing the mirrored world which can be done with a second depth test (only draw stuff farther away from the camera than the mirror). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This works very well for flat mirrors, when you add curves things get a lot more complicated.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-01-20T16:46:45.810" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4588" PostTypeId="2" ParentId="4584" CreationDate="2017-01-20T17:00:29.737" Score="2" Body="&lt;p&gt;Yes GJK is appropriate for this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The overall algorithm of GJK goes something like &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;simplex = empty&#xA;direction n = arbitrary&#xA;&#xA;while(not finished){&#xA;&#xA;    find furthest point p1 in mesh 1 in direction n&#xA;    find furthest point p2 in mesh 2 in direction -n&#xA;&#xA;    supplement simplex with point p1-p2&#xA;&#xA;    if(simplex is tetrahedron) simplify simplex&#xA;&#xA;    direction n = pick direction perpendicular to simplex pointing to origin&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;you can then use the simplex at the end of the loop to calculate the distance from it to the origin and set finished to true and you will get a collection of points on each mesh which make up a pair of faces that are closer than x.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="231" LastEditDate="2017-01-21T11:18:33.813" LastActivityDate="2017-01-21T11:18:33.813" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4589" PostTypeId="2" ParentId="4585" CreationDate="2017-01-20T20:36:32.873" Score="10" Body="&lt;p&gt;There are a couple of special cases where mirror-like reflections can be rendered efficiently using rasterization techniques, and these are commonly used in games, although they don't work for the general case.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Planar reflections&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If the reflecting surface is flat or reasonably close to flat, the reflected image can be rasterized in an separate rendering pass, by applying a reflection transform and clip plane to the scene. The reflection is then composited into the final image using a shader (or, in older games, stencil buffer masking). Also, a small amount of distortion or blurring might be applied to the image if the reflecting surface isn't intended to appear perfectly flat and smooth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is very commonly used in games for water reflection in lakes or the ocean, as long as any waves aren't too large. &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/PlanarReflections/&quot;&gt;This page from the UE4 docs&lt;/a&gt; shows a number of examples of planar reflections used for water. The same technique is also often used for mirror reflections in glossy floors, or for &lt;a href=&quot;https://i.imgur.com/IrCKR.png&quot;&gt;actual mirrors&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main strength of planar reflection is that it automatically gives you correct perspective and occlusion in the reflected image. The main limitation, aside from being limited to planar surfaces, is the performance cost of rendering an extra copy of the scene (with full lighting, etc) for each reflection plane. For instance, having multiple water surfaces at different elevations (e.g. in a boat lock) would require another rendering pass for each elevation. For this reason, usually when planar reflections are used, they're set up in such a way that only one reflection plane is visible at a time.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Cubemap reflections&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Another special case is when the reflecting object is reasonably small and, ideally, not too close to other objects around it. In that case, you can approximate reflections by rasterizing a cubemap around the object. Then it can be used as an environment map during shading, by sampling the cubemap along the reflection vector calculated in the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many games use pre-rendered cubemaps to render static environment reflections on characters and dynamic objects; somewhat less commonly, you can also dynamically re-render a cubemap every frame to get dynamic reflections of other objects. This might be used on the cars in a racing game, for instance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The advantage of cubemap reflections is that they can be applied to any shape of object, not just planar ones. However, since the cubemap is rendered from a single point, the reflections have increasingly incorrect perspective and occlusion the farther you get from that point. This can be partly addressed by &lt;a href=&quot;https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/&quot;&gt;parallax correction&lt;/a&gt;, and by blending between multiple cubemaps based on location, but ultimately cubemaps just don't give you the accuracy of either planar reflections or raytracing. Moreover, re-rendering a dynamic cubemap every frame is quite expensive, as it requires 6 extra rendering passes (one for each face of the cube).&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Hybrid techniques&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;There are also cases where rasterization is used to build an initial data structure for ray tracing / casting to traverse into.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Screen-space reflection can be understood this way, as it involves first rendering the screen using ordinary rasterization techniques, then treating the Z-buffer as a heightfield and marching rays through it. &lt;/li&gt;&#xA;&lt;li&gt;Voxel cone tracing is a similar case, where the scene is voxelized using rasterization, and then rays can be marched through the voxel grid. This perhaps doesn't qualify as &quot;mirror-like&quot; reflections since in practice the voxel grid isn't high-resolution enough for that, but it could be done in principle.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So yes, depending on what degree of approximation you can accept and what constraints you can work within, there are quite a few cases where mirror-like reflections can be achieved using rasterization, or hybrid rasterization/raytracing techniques.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-20T20:36:32.873" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4590" PostTypeId="1" AcceptedAnswerId="4591" CreationDate="2017-01-20T23:19:45.310" Score="3" ViewCount="1956" Body="&lt;p&gt;I am fairly new to graphics programming and I am trying to pass a custom Matrix4 (non-glm) to my vertex shader by using a uniform.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    Matrix44 transform;  //creates a 4x4 identity matrix&#xA;    transform.SetTranslation(Vector3(0.5f, 0.3f, 0.0f));&#xA;    GLint transformLocation = glGetUniformLocation(ourShader.Program, &quot;transformation&quot;);&#xA;    glUniformMatrix4fv(transformLocation, sizeof(transform), GL_FALSE, &amp;amp;transform.m[0][0]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Above is the code which I am using to send the matrix to the shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(the .m allows me to access the matrix as a 2D array of 4x4 floats);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how my vertex shader looks like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (location = 0) in vec3 position;&#xA;&#xA;uniform mat4 transform;&#xA;&#xA;void main()&#xA;{                   &#xA;   gl_Position = transform*vec4(position,1.0f);     &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I run it, I don't get anything drawn on my screen, except the background color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the matrix which I send to the shader. I am using column major, so as far as I've read this should be the translation part of the 4x4. I've also tried transposing the matrix with no luck whatsoever.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ay01I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ay01I.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last clue I have is that the values which I am sending are 0s. I came to this conclusion because I tried playing with the fragment shader and I set the color to be equal to the last column from the uniform mat4:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;out vec4 color;&#xA;&#xA;uniform mat4 transform;&#xA;&#xA;void main()&#xA;{&#xA; color = vec4(transform[0][3],transform[1][3], transform[2][3], transform[3][3]);   &#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which gives me a black triangle i.e. the color vec4 is filled with 0s.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Fi9c5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Fi9c5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I apologize in advance if the question is too noob-ish but I've been struggling with this for several days and I could not find a way to run it :(&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any advise would be appreciated!&lt;/p&gt;&#xA;" OwnerUserId="5890" LastActivityDate="2017-01-21T00:27:46.957" Title="Unable to pass custom Matrix4 to GLSL as a uniform" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4591" PostTypeId="2" ParentId="4590" CreationDate="2017-01-21T00:27:46.957" Score="3" Body="&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;glUniformMatrix4fv(transformLocation, sizeof(transform), GL_FALSE, &amp;amp;transform.m[0][0]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;http://docs.gl/gl4/glUniform&quot; rel=&quot;nofollow noreferrer&quot;&gt;second parameter to &lt;code&gt;glUniformMatrix&lt;/code&gt;&lt;/a&gt; is not the number of bytes in the data. OpenGL can figure that out from the &lt;code&gt;4fv&lt;/code&gt; part of the command (a 4x4 matrix of &lt;code&gt;GLfloat&lt;/code&gt;s). The second parameter is the number of &lt;em&gt;matrices&lt;/em&gt; you're sending to that uniform, in case it is an array of &lt;code&gt;mat4&lt;/code&gt;s.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So that value ought to be 1. You almost certainly got a &lt;code&gt;GL_INVALID_OPERATION&lt;/code&gt; error from calling it with &lt;code&gt;sizeof(transform)&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-01-21T00:27:46.957" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4593" PostTypeId="1" AcceptedAnswerId="4594" CreationDate="2017-01-21T16:33:28.520" Score="3" ViewCount="1786" Body="&lt;p&gt;This code snippet:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLint versionMajor;&#xA;glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);&#xA;glGetIntegerv(GLFW_CONTEXT_VERSION_MAJOR, &amp;amp;versionMajor);&#xA;std::cout &amp;lt;&amp;lt; &quot;Version major:&quot; &amp;lt;&amp;lt; version &amp;lt;&amp;lt; std::endl;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;prints &quot;3&quot; in my screen, but in the first line I set the the GLFW_CONTEXT_VERSION_MAJOR to &quot;2&quot;. How I can get back that value?&lt;/p&gt;&#xA;" OwnerUserId="5852" LastActivityDate="2017-01-21T16:39:47.863" Title="How to get the GLFW_CONTEXT_VERSION_MAJOR value?" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4594" PostTypeId="2" ParentId="4593" CreationDate="2017-01-21T16:39:47.863" Score="4" Body="&lt;p&gt;According to &lt;a href=&quot;http://www.glfw.org/docs/latest/window_guide.html#window_hints_ctx&quot; rel=&quot;nofollow noreferrer&quot;&gt;the GLFW docs&lt;/a&gt;, the context version hint acts as a &lt;em&gt;minimum&lt;/em&gt; version, i.e. the context you actually get may be a higher version than what you request. However, the context should be backward-compatible, so even if you get a GL 3.x context you're OK to use GL 2.x code.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-21T16:39:47.863" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4596" PostTypeId="1" AcceptedAnswerId="4598" CreationDate="2017-01-22T00:39:37.217" Score="5" ViewCount="3611" Body="&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; This is a duplicate of a question from stack overflow:&#xA;&lt;a href=&quot;https://stackoverflow.com/questions/9222217/how-does-the-fragment-shader-know-what-variable-to-use-for-the-color-of-a-pixel&quot;&gt;https://stackoverflow.com/questions/9222217/how-does-the-fragment-shader-know-what-variable-to-use-for-the-color-of-a-pixel&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to send a value from vertex shader to fragment shader, the vertex shader should declare one variable as &lt;code&gt;out&lt;/code&gt;, the fragment shader should declare other variable as &lt;code&gt;in&lt;/code&gt; and both variables must have their names and types equal. But this doesn't happen when you want to send the color value from the fragment shader. In fact, you can call the output variable as you want. Why? In older version there was one variable called &lt;code&gt;gl_FragColor&lt;/code&gt;&lt;br /&gt;&#xA;How the program links your output fragment variable with gl_FragColor?&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-01-25T01:44:51.697" Title="Fragment shader's output variables" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4597" PostTypeId="1" AcceptedAnswerId="8051" CreationDate="2017-01-22T02:00:59.087" Score="6" ViewCount="359" Body="&lt;p&gt;I am currently a beginner when it comes to anti-aliasing. I have read some notes online that how anti-aliasing works is that you first draw the line using an algorithm such as Bresenham's algorithm. Then you modify it to include anti-aliasing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I understand that one method of anti-aliasing is to simply imagine there being a rectangle that encompasses the line and any pixel that touches that will be turned on or filled with an RGB value. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if I know that area of the segment of the pixel that is cut off by the rectangle (let's assume the pixel is a circle) how would I use that area of the segment to compute the density of the colour which is from 0-1 (where 0 is very light and 1 is the darkest)?&lt;/p&gt;&#xA;" OwnerUserId="5900" LastEditorUserId="231" LastEditDate="2017-01-22T03:11:47.250" LastActivityDate="2018-09-11T22:34:39.573" Title="Anti-aliasing - Controlling colour density of pixel that comes within the &quot;rectangle&quot; surrounding my line" Tags="&lt;line-drawing&gt;&lt;antialiasing&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4598" PostTypeId="2" ParentId="4596" CreationDate="2017-01-22T03:05:38.667" Score="6" Body="&lt;p&gt;It works almost exactly the same way as vertex shader inputs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In vertex shaders, you have inputs. And these inputs represent vertex attribute indices, the numbers you pass to &lt;code&gt;glVertexAttribPointer&lt;/code&gt; and &lt;code&gt;glEnableVertexAttribArray&lt;/code&gt; and so forth. You set up which input pulls from which attribute. In GLSL 3.30, you use this syntax:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(location = 2) in color;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This sets the &lt;code&gt;color&lt;/code&gt; vertex shader input to come from attribute location 2. Before 3.30 (or without ARB_explicit_attrib_location), you would have to either set this up explicitly with &lt;a href=&quot;http://www.opengl.org/wiki/GLAPI/glBindAttribLocation&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glBindAttrbLocation&lt;/code&gt;&lt;/a&gt; before linking or query the program for the attribute index with &lt;a href=&quot;http://www.opengl.org/wiki/GLAPI/glGetAttribLocation&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glGetAttribLocation&lt;/code&gt;&lt;/a&gt;. If you don't explicitly provide an attribute location, GLSL will assign a location &lt;em&gt;arbitrarily&lt;/em&gt; (ie: in an implementation-defined manner).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Setting it in the shader is almost always the better option.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, fragment shader outputs work almost exactly the same way. Fragment shaders can write to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Fragment#Fragment_shader_outputs&quot; rel=&quot;nofollow noreferrer&quot;&gt;multiple output colors&lt;/a&gt;, which themselves get mapped to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Framebuffer_Draw_Buffer&quot; rel=&quot;nofollow noreferrer&quot;&gt;multiple buffers in the framebuffer&lt;/a&gt;. Therefore, you need to indicate which output goes to which fragment output color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This process begins with the fragment output location value. It's set very similarly to vertex shader input locations:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(location = 1) out secColor;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There are also the API functions &lt;a href=&quot;http://www.opengl.org/wiki/GLAPI/glBindFragDataLocation&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glBindFragDataLocation&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;http://www.opengl.org/wiki/GLAPI/glGetFragDataLocation&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glGetFragDataLocation&lt;/code&gt;&lt;/a&gt;, which are analogous to &lt;code&gt;glBindAttribLocation&lt;/code&gt; and &lt;code&gt;glGetAttribLocation&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't do any explicit assignments, implementations usually will assign one of your output variables to location 0. However, the OpenGL standard does not &lt;em&gt;require&lt;/em&gt; this behavior, so you should not depend on it either.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-01-22T03:12:36.043" LastActivityDate="2017-01-22T03:12:36.043" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4599" PostTypeId="1" CreationDate="2017-01-22T07:30:09.780" Score="0" ViewCount="329" Body="&lt;p&gt;Where can I learn about particle and fluid simulation? Is there a good book available?  I want to couple volume rendering with fluid/particle simulation to be able to finally render smoke and ocean with foam etc. Is there a chapter in PBRT on it?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-01-22T07:47:39.300" Title="Particle &amp; Fluid Simulation: Where to learn?" Tags="&lt;raytracing&gt;&lt;rasterizer&gt;&lt;fluid-sim&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2017-01-22T14:34:13.780" ContentLicense="CC BY-SA 3.0" />
  <row Id="4600" PostTypeId="2" ParentId="4599" CreationDate="2017-01-22T07:47:39.300" Score="1" Body="&lt;p&gt;PBRT handles only the rendering part, not the simulation part. There are several books out on game physics that handle fluid simulation, the one on my bookshelf is &lt;a href=&quot;https://www.crcpress.com/Game-Physics/Eberly/p/book/9780123749031&quot; rel=&quot;nofollow noreferrer&quot;&gt;David Eberly's &quot;Game Physics&quot;.&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-01-22T07:47:39.300" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4601" PostTypeId="2" ParentId="4554" CreationDate="2017-01-23T14:49:30.837" Score="2" Body="&lt;p&gt;Maybe not the best solution but one that should work would be to multiply them by matrix like&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{bmatrix}-1&amp;amp;0&amp;amp;0\\0&amp;amp;1&amp;amp;0\\0&amp;amp;0&amp;amp;-1\end{bmatrix}&lt;/span&gt;&#xA;And multiply by this your &lt;code&gt;mvp&lt;/code&gt; matrix to convert meshes vertices (this could be done offline).&lt;/p&gt;&#xA;&lt;p&gt;Quaternion can be change to matrix form, multiply and save as quaternion.&lt;/p&gt;&#xA;&lt;p&gt;You also need to change culling in &lt;code&gt;OpenGL&lt;/code&gt; because triangle order will be inverted.&lt;/p&gt;&#xA;&lt;p&gt;I did this in one project and it works fine. If I will find this project I will write something more about it.&lt;/p&gt;&#xA;&lt;p&gt;//EDIT&lt;/p&gt;&#xA;&lt;p&gt;This matrix will invert your Z-axis and X-axis&lt;/p&gt;&#xA;&lt;p&gt;//EDIT2&lt;/p&gt;&#xA;&lt;p&gt;To apply this solution to each to component you need to:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Change translation &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;z&lt;/code&gt; component to &lt;code&gt;-x&lt;/code&gt; and &lt;code&gt;-z&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Rotation in matrix form multiply by matrix above and change it to quaternion.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Scale leave how it is.&lt;/p&gt;&#xA;&lt;p&gt;&lt;s&gt;4. Iterate through all meshes and multiply each of their vertices by this matrix.&lt;/s&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;//EDIT3&lt;/p&gt;&#xA;&lt;p&gt;Instead of matrix you can just multiply rotation by quaternion &lt;code&gt;(0, 0, 1, 0)&lt;/code&gt; (in order &lt;code&gt;(w, x, y, z)&lt;/code&gt;) and new quaternion will look like this: &lt;code&gt;(-y,z,w,-x)&lt;/code&gt;. This operation (and matrix too) just rotate object by 180 degree in y-axis.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-01-24T13:10:29.947" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4602" PostTypeId="1" AcceptedAnswerId="4605" CreationDate="2017-01-23T16:54:27.387" Score="3" ViewCount="848" Body="&lt;p&gt;I had some magical tasks to do on my lessons. I had to write an app which performs some operations: basic (adding, subtracting, multiplying a constant and a second image), geometric, filtering, histograms etc. There were ~50 tasks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've made them all, even with Prewitt filters and other down/upbandwith and gradient things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, my teacher sent me an info, that I did my normalization wrong in basic operations, for example in adding a constant. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As he wrote in his document there are 3 ways of handling the pixel overflow &gt;255 or &amp;lt;0:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;cutting the overflow - which means a simple clamp&lt;/li&gt;&#xA;&lt;li&gt;scaling images before processing&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;&lt;em&gt;normalization&lt;/em&gt;&lt;/strong&gt; of the final image - scaling and moving the image function with a specified range that the final image fills the given range.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I've left first two and got the third one, because he said it's the correct way. I've read somewhere that I still need to combine it with a clamp (0,255).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I got his formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\large f_{norm}=Z_{rep}[(f-f_{min})\div(f_{max}-f_{min})]$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And  I thought it's easy to understand, but I have some problems with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I understand:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$f_{norm}$ - final pixel (normalized)&lt;/li&gt;&#xA;&lt;li&gt;$f$ - given pixel&lt;/li&gt;&#xA;&lt;li&gt;$f_{min}$ - minimum&lt;/li&gt;&#xA;&lt;li&gt;$f_{max}$ - extremum&lt;/li&gt;&#xA;&lt;li&gt;$Z_{rep}$ - clamp 0-255?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;I have the following questions:&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Are $f_{min}$ and $f_{max}$ taken from the given image, or from the image after the operation (for ex. adding a constant)? I know what extremes are, but I can't figure it out which two should I use in this formula.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Is $Z_{rep}$ really a clamp method as I thought which just cuts to 0-255? I've read somewhere that even with normalization there can be an overflow.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Does normalization work like: no matter what value you'll add or subtract from the image, I'll make for you a beautiful 0-255 values? Or am I wrong?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I've even made some calculations, made some images in photoshop with extremes 30,200 and even 0,255, put them into the formula and got some results, but I still don't know if it's done well. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm sitting here for 3 weeks, really and can't get which extremes should I use and if I should clamp or not. &lt;/p&gt;&#xA;" OwnerUserId="5910" LastEditorUserId="231" LastEditDate="2017-01-23T23:07:27.067" LastActivityDate="2017-01-24T04:10:30.857" Title="How to perform an image normalization after for example adding a constant to it?" Tags="&lt;image-processing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4603" PostTypeId="2" ParentId="4602" CreationDate="2017-01-23T18:01:22.457" Score="2" Body="&lt;p&gt;Coming from an audio perspective dealing with dynamics processing (which is also digital signal processing of course!), here's the answers I would believe to be true.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;fmin and fmax are the global min and max values of the image before it's normalized (but after the adding a constant or whatever other processing has happened).  Since in an RGB image you have three channels of data, the max would be the maximum value seen in any channel, and min would be the minimum value seen in any channel.&lt;/li&gt;&#xA;&lt;li&gt;I have no idea what Zrep is unfortunately.  If you are truly normalizing the data, the only cause of overflow I can think of is due to rounding issues which can definitely happen.  Yes, I would clamp, but also I would do my operations in a larger non integer intermediary data format (such as floating point, or maybe fixed point) before clamping and then converting to the final data format (eg. from float to uint8).&lt;/li&gt;&#xA;&lt;li&gt;Normalization will modify the signal such that it will span the entire range possible (0-255) however the result may not be &quot;beautiful&quot;.  Basically, you might find banding in the results where instead of a smooth gradient from one color to the next you might have very distinct bands of color steps.  You will see this being especially true if you don't use a larger non integer intermediary format like i mentioned in the last point, but can come up even if you do.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;By the way, there are other ways to deal with this situation of going out of range.  In the audio world there is such thing as limiters and compressors which deal with adjusting dynamics in a non linear way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simplistic look at how they would apply to graphics would be that maybe you leave the color values that are between 32 and 223 alone so that most colors are unaffected, but then, colors less than 32 and colors greater than 223 get a non linear transformation to &quot;squish&quot; them into the valid range of values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are dealing with a high dynamic range image (HDR), you may have very large values in the thousands or ten thousands or higher.  As you can imagine, trying to squish all of that into the 223-255 range with a non linear transformation might be a little rediculous, so you may just squish in a certain amount (maybe make it so 512 input = 255 output in your remapping function), and then clamp the result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case you are interested, games sometimes deal with this situation as you move from an indoors darker area to an outdoors brighter area.  Some games will make it so that the brighter outside is far too bright at first, and then over time, their colors will scale more towards being &quot;normal&quot;.  This is to mimic how it takes time for your eyes to adjust to bright light after being in the dark.  The reverse effect is also valid of course, of going from a bright area to a dark one, and having things be too dark until your eyes adjust.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, in case you are interested, there is a lot of work being done in games and graphics on mapping HDR color values to LDR values, and applying color grading and tone mapping.  The work is focused not only on quality, but on speed, so there are different trade offs for real time processing vs off line processing.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-01-23T18:51:26.450" LastActivityDate="2017-01-23T18:51:26.450" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4605" PostTypeId="2" ParentId="4602" CreationDate="2017-01-24T04:10:30.857" Score="6" Body="&lt;p&gt;I believe that &lt;code&gt;Zrep&lt;/code&gt; is the output range. In 8-bit it would be 255. Let's say &lt;code&gt;fmin&lt;/code&gt; was 25, &lt;code&gt;fmax&lt;/code&gt; was 132. You want to scale that range to 0-255. The part of the equation in brackets: &lt;code&gt;[(f-fmin) / (fmax-fmin)]&lt;/code&gt; will give you a percentage - a value between 0 and 1. If &lt;code&gt;f&lt;/code&gt; is 25, you'd get 0%. If &lt;code&gt;f&lt;/code&gt; is 89, you'd get ~60%. If it's 132, you'd get 100%&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So once you have the percentage, you then need to multiply that by the output range, &lt;code&gt;Zrep&lt;/code&gt;. That converts from a percentage to whatever range you need it in, and ensures that the largest value in the input is mapped to the largest output value, and the smallest input is mapped to the smallest output value.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-01-24T04:10:30.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4606" PostTypeId="1" CreationDate="2017-01-25T09:02:25.943" Score="2" ViewCount="148" Body="&lt;p&gt;I've heard a lot that in shader development, you absolutely need to avoid branching and so if statements.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But why? Does this have a real impact on performances on old and modern hardware or is it more a case by case choice depending on your scenario?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When possible, it's better to use preprocessor macros but when it's not, what can we do?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the purpose of using &lt;code&gt;flatten&lt;/code&gt; or &lt;code&gt;branch&lt;/code&gt; attributes? Are there other solutions available?&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="231" LastEditDate="2017-01-25T12:40:45.030" LastActivityDate="2017-01-25T12:40:45.030" Title="If statements in shaders - implications and consequences" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;hlsl&gt;&lt;directx&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2017-01-25T18:12:42.110" ContentLicense="CC BY-SA 3.0" />
  <row Id="4607" PostTypeId="2" ParentId="2060" CreationDate="2017-01-25T09:12:49.897" Score="0" Body="&lt;p&gt;Here's a very speedy 10 line maths fix for converting mesh to voxels... forget rays, dot products, square roots etc, edges, intersections do this:&#xA;&lt;a href=&quot;https://gamedev.stackexchange.com/questions/136243/how-can-i-randomly-pick-points-on-a-triangle/136250#136250&quot;&gt;https://gamedev.stackexchange.com/questions/136243/how-can-i-randomly-pick-points-on-a-triangle/136250#136250&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5811" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2017-01-25T09:12:49.897" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4609" PostTypeId="1" CreationDate="2017-01-26T18:34:21.427" Score="2" ViewCount="530" Body="&lt;h3&gt;Short introduction&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;I created a function that interpolates the IES luminious intensities (candelas) using Hermite interpolation, so in my code all light sources have $I(\theta, \phi)$ function - but for simplicity lets assume we are dealing with a hemispherical light source with constant intensity $I = 100cd$ and we are dealing with monochromatic light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I managed to compute the direct illumination part from an IES point light source by calculating illuminance at each shading point using $E = \frac{I \cos(\theta_i)}{r^2}$ which I can easily convert to luminance $L_o$ by multiplying it by BRDF (since all my materials are diffuse, so $f_r = \frac{\rho}{\pi}$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This time I decided to implement &lt;em&gt;Instant Radiosity&lt;/em&gt; to approximate the global illumination using &lt;em&gt;Virtual Point Lights&lt;/em&gt;. I did some research, and I found a &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/slides/Boyadzhiev-Matzen-InstantRadiosity.pdf#10&quot; rel=&quot;nofollow noreferrer&quot;&gt;presentation with equations at slide 10 and 11&lt;/a&gt;. So I spent my last month experimenting with it, but the results I've got are too dark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My current implementation is split into 2 applications. The first one is tracing random rays from light source. The second one is an OpenGL application for shading.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;VPL generation (for single light path)&lt;/h3&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create a new ray in random direction&lt;/li&gt;&#xA;&lt;li&gt;Since I'm dealing with a point light, I believe that we can't calculate $L_i$, but I know that $L_o = f_r \times E$ and $E = \frac{I \cos{\theta_i}}{r^2}$ so now I know the outgoing luminance. Since I'm using a Lambertian BRDF, I know that $L_o$ is constant - that's why I store it as light intensity (I know that this is not &quot;luminious intensity&quot; per se, but at this point I don't know the outgoing direction).&lt;/li&gt;&#xA;&lt;li&gt;Randomize a new outgoing reflection direction.&lt;/li&gt;&#xA;&lt;li&gt;This time I know $L_i$ (it is equal to $L_o$ from previous iteration - no participating medium). I use &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/slides/Boyadzhiev-Matzen-InstantRadiosity.pdf#10&quot; rel=&quot;nofollow noreferrer&quot;&gt;the equation from slide 10&lt;/a&gt;, so $L_o = \frac{\rho}{\pi} L_i$. Again I store $L_o$ as VPL's intensity.&lt;/li&gt;&#xA;&lt;li&gt;Randomize a new outgoing (reflected) direction.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;if (depth++ &amp;lt; max_depth) goto step_4;&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h3&gt;Shading with VPLs&lt;/h3&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Set the illumination accumulator to $E = 0$&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;code&gt;foreach (vpl in vpls)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;a. Check light visibility $V$ (from shadow map), if in shadow then &lt;code&gt;continue&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;b. Compute the distance $r$ to light and a normalized vector $\hat{l}$ &quot;to the light&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;c. $E_{vpl} = I_{vpl} \frac{\cos{\theta_i} \cos{\theta_e}}{r^2}$, where $\cos \theta_e = \hat{l} \circ \hat{n}_{vpl}$ based on &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/slides/Boyadzhiev-Matzen-InstantRadiosity.pdf#11&quot; rel=&quot;nofollow noreferrer&quot;&gt;equation from slide 11&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;d. &lt;code&gt;E +=&lt;/code&gt; $\frac{E_{vpl}}{N}$, where $N$ is the number of traced light paths&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$L_o = f_r \times E$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h2&gt;Problem&lt;/h2&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The problem is that the resulting $L_o$ values are always below $1$, while an identical scene rendered in Radiance (and limited to 1 bounce) has values above $20$.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;(If my method is wrong) How to compute VPLs intensity?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;In the mentioned presentation at page 13 is an algorithm (which I don't fully understand). Can somebody enlighten me how to calculate &quot;average_reflectivity&quot;? As you can see my implementation is derived from The Rendering Equation and the equations look similar.  &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5114" LastActivityDate="2017-01-26T18:34:21.427" Title="Calculating intensities of Virtual Point Lights in Instant Radiosity from IES lights" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;reflection&gt;&lt;radiosity&gt;&lt;photometric&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4610" PostTypeId="1" CreationDate="2017-01-27T00:23:32.123" Score="2" ViewCount="210" Body="&lt;p&gt;I am in awe at &lt;a href=&quot;https://play.google.com/store/apps/details?id=com.volutopia.forgeofneon3d&amp;amp;hl=en&quot; rel=&quot;nofollow noreferrer&quot;&gt;this app&lt;/a&gt; I just found. It was actually one of the first things I installed when I first bought my iPad 2 but now they have updated it to add an HDR effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have never seen a real-time glow effect that looked quite this amazing. I have no clue how the developer pulled off such a large radius in realtime graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fTjVa.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fTjVa.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a game with similar unprocessed graphics to his. I have been trying to get a glow effect like this working but it has been near impossible. I am currently using separable convolution gaussian blur methods in addition to downscaling my blur mask. Still, it barely runs in real-time. It is nowhere near as big as a radius as this app pulls off and it certainly isn't as good of quality.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some method I am not thinking of?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am open to the possibility (but doubtful) that they are using really large textures with a falloff distance or that lighting is computed from the distance from a fragment to light sources. If you play with it and notice when the FPS drops it it just doesn't seem to have the right FPS to particle amount and HDR on/off quality to it to be that.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2017-01-27T06:38:04.500" Title="How does this app pull off fast, high radius HDR" Tags="&lt;lighting&gt;&lt;gaussian-blur&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4611" PostTypeId="1" AcceptedAnswerId="4619" CreationDate="2017-01-27T01:32:22.360" Score="11" ViewCount="959" Body="&lt;p&gt;I'm currently trying to implement a Monte Carlo path tracer. I've done some research and it seems that a common approach to materials is to use a layered model. Something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2ABBQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2ABBQ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When light hits the surface, Fresnel tells us how much of that light is reflected by the first layer and how much goes to the second, and so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I did something similar, but simpler: only one layer of specular and one layer of diffuse. No transmittance yet. So far so good, I use a simple cosine-weighted &lt;a href=&quot;https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;brdf&lt;/a&gt; for my diffuse and the Cook-Torrance microfaceted model for my specular. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now comes the hard part: what should I do once a ray hits the surface?&#xA;Normally, I'd pick the brdf corresponding to the surface material, sample an incident light direction, evaluate the brdf, and divide by the right probability distribution function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But here, a surface hit effectively corresponds to multiple materials. The naive way to handle this would be to sample once for each layer hit. But this clearly is source of a huge performance hit, causing my path to effectively become a tree.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a better solution? &lt;/p&gt;&#xA;" OwnerUserId="2330" LastEditorUserId="171" LastEditDate="2017-05-19T01:24:13.250" LastActivityDate="2017-05-19T01:24:13.250" Title="Path tracer - multi layered materials and importance sampling" Tags="&lt;pathtracing&gt;&lt;material&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4612" PostTypeId="2" ParentId="4610" CreationDate="2017-01-27T03:06:37.117" Score="4" Body="&lt;p&gt;At CEDEC and GDC in the early 2000s, Masaki Kawase has presented a series of fast post-processing based lens effects, including large bloom.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This presentation from GDC 2003, &lt;a href=&quot;http://www.daionet.gr.jp/~masa/archives/GDC2003_DSTEAL.ppt&quot;&gt;Frame Buffer Postprocessing Effects in DOUBLE-S.T.E.A.L (Wreckless)&lt;/a&gt; (see slides 15 and upwards: &lt;em&gt;&quot;Bloom&quot;&lt;/em&gt;), gives a first version of the bloom. It consists in doing a Gaussian blur by sampling at exponentially increasing distances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this presentation from GDC 2004, &lt;a href=&quot;http://www.daionet.gr.jp/~masa/archives/GDC2004/GDC2004_PIoHDRR_EN.ppt&quot;&gt;Practical Implementation of High Dynamic Range Rendering&lt;/a&gt; (see slides 44 and upward: &lt;em&gt;&quot;Glare generation&quot;&lt;/em&gt;), he updates the technique. Instead of varying the sampling distance, he uses downsized versions of the original image, using a carefully crafted equation to achieve a large yet spiky Gaussian blur.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2017-01-27T03:12:40.317" LastActivityDate="2017-01-27T03:12:40.317" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4613" PostTypeId="2" ParentId="4610" CreationDate="2017-01-27T06:38:04.500" Score="2" Body="&lt;p&gt;One way to speed things up if you're doing this on a mobile GPU is to avoid indirect texture look-ups. This is where you calculate the texture coordinates then use the results of that calculation in the call to sample the texture. So it might be natural to write a 3-tap blur fragment shader doing something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;sample1 = texture2D(inputTexture, gl_TexCoord [ 0 ] - vec2(1.0, 0.0));&#xA;sample2 = texture2D(inputTexture, gl_TexCoord [ 0 ]);&#xA;sample3 = texture2D(inputTexture, gl_TexCoord [ 0 ] + vec2(1.0, 0.0));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can get around this by doing the calculation in the vertex shader or on the CPU. You can use multi texturing to get around this when you have very straightforward situations like above. You can set texture coordinates for textures 1 and 2 to be offset by 1 pixel in either direction from those in texture 0. Your fragment shader then becomes:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;sample1 = texture2D(inputTexture, gl_TexCoord [ 0 ]);&#xA;sample2 = texture2D(inputTexture, gl_TexCoord [ 1 ]);&#xA;sample3 = texture2D(inputTexture, gl_TexCoord [ 2 ]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now you're not doing any calculations to figure out texture coordinates.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-01-27T06:38:04.500" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4614" PostTypeId="1" AcceptedAnswerId="4617" CreationDate="2017-01-27T10:58:22.070" Score="3" ViewCount="2308" Body="&lt;p&gt;I've heard a lot about &lt;strong&gt;jittering&lt;/strong&gt; and &lt;strong&gt;dithering&lt;/strong&gt; but I would like to know more about those techniques, especially when used to avoid visible sampling in a fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What are the differences between both?&lt;/li&gt;&#xA;&lt;li&gt;When are they used the most?&lt;/li&gt;&#xA;&lt;li&gt;What's the best way to implement them?&lt;/li&gt;&#xA;&lt;li&gt;Can we combine them?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="231" LastEditDate="2017-01-28T14:15:19.090" LastActivityDate="2017-01-28T14:15:19.090" Title="What are Jittering and Dithering" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;hlsl&gt;&lt;directx11&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4615" PostTypeId="1" AcceptedAnswerId="4618" CreationDate="2017-01-27T11:48:34.043" Score="2" ViewCount="1076" Body="&lt;p&gt;In my ray tracer, I render my images out to a .PPM file and then view it in photoshop. To make things easier and faster I want my ray tracer to open up another window and show the image being rendered each ray at a time like how modern renderers like Mental Ray or V-Ray do it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is this done? What is the most common method? I tried writing a viewer in C# that uses a &lt;code&gt;picturebox&lt;/code&gt; to load the image which is then constantly refreshed but that doesn't work since the image cannot be shared. After asking on reddit most people suggested writing the image to an OpenGL quad as a texture but I don't want to do this as it complicates things. I've taken a look at at the &lt;code&gt;setpixel&lt;/code&gt; function which will set the pixel's color at a specified coordinate and color, is this the way to do it? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is really great to watch your image be rendered, it is also helpful because if your image is rendering wrong you can stop rather than waiting for the entire image to rendered and then noticing there is a problem. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;(the image below is 3DS Max with Mental Ray which shows image being rendered each Ray at a time, I want to achieve this)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UyUk5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UyUk5.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2017-01-28T07:20:30.227" LastActivityDate="2017-01-28T14:51:49.923" Title="How to watch image being ray traced?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;ui&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4616" PostTypeId="1" CreationDate="2017-01-27T14:42:29.203" Score="2" ViewCount="246" Body="&lt;p&gt;I would like to downsample my depth buffer and my normals.&lt;br&gt;&#xA;For that, I take in input of my shader, the corresponding textures (depth, normal), and I write my new values in a multi render target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I downsample the normals by doing a simple average of four texels and for the depth buffer, I can choose the max or min of four texels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My color attachment's format for the downsampled buffer is R32F.&lt;br&gt;&#xA;How could I write my new depth floating point value in it?&lt;br&gt;&#xA;I tried: &lt;code&gt;gl_FragData[1].r = newDepth;&lt;/code&gt; &#xA;But it doesn't seem to store correctly a float with 32 bits precision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get a pixel's depth, I know that I can do:&lt;br&gt;&#xA;&lt;code&gt;float depth = texture2D(depth, tc).x;&lt;/code&gt;&lt;br&gt;&#xA;But what about to output a single float with 32 bits precision?&lt;/p&gt;&#xA;" OwnerUserId="5807" LastEditorUserId="231" LastEditDate="2017-01-28T14:23:17.460" LastActivityDate="2017-01-28T14:23:17.460" Title="How to output a 32 floating value in a render buffer with fragment shader" Tags="&lt;shader&gt;&lt;3d&gt;&lt;glsl&gt;&lt;depth-map&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4617" PostTypeId="2" ParentId="4614" CreationDate="2017-01-27T15:00:28.523" Score="8" Body="&lt;p&gt;Jittering and dithering are both techniques of adding noise to reduce visible artefacts (such as banding) in an image. They solve different kinds of artefacts so they are used in different situations. Jittering moves sample positions in space to reduce artefacts caused by regular sampling. Dithering changes the way colours are rounded (when reducing precision), replacing banding with noise.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;When is jittering used?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;A use case for jittering is when generating eye rays in a ray-tracer. Without jittering, you might generate one ray in the centre of each pixel. But then if you trace those at a regular pattern, such as a grille of bars each one pixel wide, you might find that every ray hits a bar, making the grille solid; or that every ray hits a gap, and the grille isn't seen at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, you can add a small stochastic displacement to each ray direction, so that each ray goes through a different part of its pixel. That way, some rays will hit the bars of the grille and some will hit the gaps, making a noisy image instead of a completely wrong image.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;When is dithering used?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The normal use of dithering is when rounding colours (intensity values) from a high-precision format (such as floating-point numbers) to a low-precision format (such as 8-bit integers). Say you have a smooth gradient you want to represent in an 8-bit image. If you round each number separately, then starting from the black end of the gradient, you get a lot of black pixels until they get light enough to round to 1/256; then these all have the same value until you get to 2/256; and so on. You end up with regular bands where all the pixels have the same value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, when you round the first number down, you can let it &quot;donate&quot; the lost intensity to another nearby pixel. That way, then at the black end of the gradient, maybe every tenth pixel is 1/256 and the other nine are 0. The ratio of black to nearly-black pixels increases gradually, until eventually all the pixels are 1/256, and then every tenth is 2/256, and so on. Instead of visible bands, the overall intensity increases smoothly along the gradient - but the price of this is that pixels which should be the same are slightly different, adding noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Dithering is used a lot in printing, where the colour resolution is quite poor (i.e. the steps between colours are big) but the spatial resolution (how small you can make each dot of colour) is very fine. It used to be used in the days of 256-colour displays for making colours which couldn't otherwise be represented, and it's still used to avoid banding when displaying (for example) a 16-bit-per-channel image on an 8-bit display.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Is dithering the only way?&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Because traditional dithering algorithms involve giving information from each pixel to its neighbours, they don't parallelise well, so they're not suited to modern hardware. Another popular technique is to deliberately add noise to the source image. The range of the noise is less than one step of the destination format (e.g. the noise ranges from -1/512 to 1/512), so it can't be seen directly, but it means that each pixel will be rounded differently. Like true dithering, it replaces any banding with subtle noise in the output image.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Can we combine them?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;There's no reason you can't use both in the same image, but as they solve different problems, that's not really &quot;combining&quot; them. It's like asking if we can combine hoses and axes. A fire truck has both, and the firefighters might use both at the same incident, but one is for extinguishing fires and the other is for freeing trapped people.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example of when you might use both is if you ray-trace an image into a floating-point framebuffer, using jittered ray positions to avoid sampling artefacts, and then reduce that to an 8-bit image using dithering to better preserve the colours.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-01-27T15:00:28.523" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="4618" PostTypeId="2" ParentId="4615" CreationDate="2017-01-28T12:24:24.843" Score="4" Body="&lt;p&gt;This is a very common question that most people in your situation (interested or fascinated shall I say in Computer Graphics) have and a problem they want to figure out. The solution is pretty simple, though not necessarily that straightforward to implement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't make a specific answer because it depends on the OS you are using, and as I said this is not something you can do in 2 lines of code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The answer is to use some sort of library that:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;allows you to create a window on your system&lt;/li&gt;&#xA;&lt;li&gt;allows you to display some content (an image) in the window you created and displayed to the screen&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The first task is generally quite complex regardless of the OS you use (MacOS, Windows, Linux). For the second step, you need to generally go through some sort of graphics API (like OpenGL).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So there is hope for you. One thing you can do is use some other library that works as a wrapper around 1) and 2) In other words they help you especially with the creation of the window, and then if you know OpenGL you can do the rest of the work. You will need to create some texture that you will fill with the content of your image as it gets rendered and display this texture to the screen (that's pretty basic in OpenGL though you need to know this API in order to do so).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.glfw.org/docs/latest/quick.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLFW&lt;/a&gt; is a great library that will allow you to do that. It's simple to use and compile and install, etc. You can alternatively use Qt but I don't recommend it unless you want to become a professional programmer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had some documentation about the whole process but it's offline right now. I might put it back in a few weeks but you will need to wait I am afraid.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;EDIT&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I am editing the answer to respond to your comment. The algorithm would look like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Color *buffer = Color  char [w * h];&#xA;// create a texture that you can map onto the quad stretched over the area&#xA;// of the window. You will need to create a quad rendered in the space of the&#xA;// window, aka you in 2D not 3D.&#xA;...&#xA;// now render your image using you ray-tracer&#xA;for (j = 0; j &amp;lt; h; ++h) {&#xA;    for (i =0; i &amp;lt; w; ++i) {&#xA;        buffer[j * w + i] =  trace(orig, dir, ...);&#xA;    }&#xA;    // it is not very efficient to update your window each time you have &#xA;    // a new pixel so do this every row or every 10 rows ... you get the idea&#xA;    // copy content of your buffer into the GL texture&#xA;    // I am not using the right calls here, too lazy to find the right ones&#xA;    glCopyTexture(myGLTextureId, buffer, (sizeof(char) * 3 * w * h); &#xA;    // do the texture binding, etc... all GL or DX stuff&#xA;    ...&#xA;    // this will update your window with the content of the buffer&#xA;    glSwapBuffer(); &#xA;}&#xA;// now save content of buffer to image file&#xA;saveToDisk(buffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Windows? Arg(. You will have to use DirectX calls indeed but they 2 APIs are very close.&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="1608" LastEditDate="2017-01-28T14:22:48.743" LastActivityDate="2017-01-28T14:22:48.743" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4619" PostTypeId="2" ParentId="4611" CreationDate="2017-01-28T13:22:55.387" Score="7" Body="&lt;p&gt;Wenzel Jakob et al presented a &lt;a href=&quot;http://www.cs.cornell.edu/projects/layered-sg14/layered.pdf&quot;&gt;framework for layered Materials&lt;/a&gt; at SIGGRAPH 2014. Section 6.2 explains importance sampling. If you prefer code over equations, the method is implemented in the &lt;a href=&quot;http://www.mitsuba-renderer.org&quot;&gt;Mitsuba renderer&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-01-28T13:22:55.387" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4620" PostTypeId="2" ParentId="4615" CreationDate="2017-01-28T14:44:13.377" Score="1" Body="&lt;p&gt;In QtCreator IDE (C++) any kind of image buffer - result of CPU raytracing or (what I did) frames captured from the camera can be easily rendered or painted on Widget - which is simplest part of the UI available in QtDesigner - UI designer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could send your ray tracing engine class to another thread and use timer which every once in a while would emit signal to send your image through signal/slot mechanism to GUI main thread and paint it on the widget. It's quite simple actually. No need of OpenGL or DirectX API. &lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-01-28T14:51:49.923" LastActivityDate="2017-01-28T14:51:49.923" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4621" PostTypeId="1" CreationDate="2017-01-28T23:33:50.787" Score="1" ViewCount="867" Body="&lt;p&gt;Given a point and a line segment, how do you calculate the barycentric coordinates of the point to the line?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;bool BarycentricCoordinates(const Vector3&amp;amp; point, const Vector3&amp;amp; a, const Vector3&amp;amp; b, float&amp;amp; u, float&amp;amp; v, float epsilon)&lt;/p&gt;&#xA;" OwnerUserId="5943" LastEditorUserId="56" LastEditDate="2017-01-30T20:03:22.677" LastActivityDate="2017-01-30T20:03:22.677" Title="Barycentric Coordinates of a Point on a Line" Tags="&lt;texture&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4623" PostTypeId="1" AcceptedAnswerId="4625" CreationDate="2017-01-29T10:31:39.703" Score="2" ViewCount="3207" Body="&lt;p&gt;Let's say I have a have 10 different terrains. Each terrain have the same x and z coordinates, but they have different y coordinate, normals and colors. The indices used for element rendering is also the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The data looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;std::vector&amp;lt;GLfloat&amp;gt; xzCoords;&#xA;std::vector&amp;lt;GLuint&amp;gt; indices;&#xA;&#xA;std::vector&amp;lt;GLfloat&amp;gt; yCoords[10];&#xA;std::vector&amp;lt;GLfloat&amp;gt; normals[10];&#xA;std::vector&amp;lt;GLfloat&amp;gt; colors[10];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the VBO and VAO IDs:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint VAO_IDs[10];&#xA;GLuint VBO_xzCoord_IDs[10];&#xA;GLuint VBO_yCoord_IDs[10];&#xA;GLuint VBO_indices_IDs[10];&#xA;GLuint VBO_normals_IDs[10];&#xA;GLuint VBO_colors_IDs[10];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I want one VAO for each of the terrain deffinitions, how would that look if the VBO for xz coordinates and indices are the same for each?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I am doing now looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Setting up the buffers:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (size_t i = 0; i &amp;lt; 10; i++){&#xA;        //VAO&#xA;        glGenVertexArrays(1, &amp;amp;VAO_IDs[i]);&#xA;        glBindVertexArray(VAO_IDs[i]);&#xA;&#xA;        //VBO&#xA;        glGenBuffers(1, &amp;amp;VBO_xzCoord_IDs[i]);&#xA;        glGenBuffers(1, &amp;amp;VBO_yCoord_IDs[i]);&#xA;        glGenBuffers(1, &amp;amp;VBO_indices_IDs[i]);&#xA;        glGenBuffers(1, &amp;amp;VBO_normals_IDs[i]);&#xA;        glGenBuffers(1, &amp;amp;VBO_colors_IDs[i]);&#xA;&#xA;        //xz coords&#xA;        glBindBuffer(GL_ARRAY_BUFFER, VBO_xzCoord_IDs[i]);&#xA;        glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*xzCoords.size(), &amp;amp;xzCoords[0], GL_STATIC_DRAW);&#xA;        glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;        glEnableVertexAttribArray(0);&#xA;        //y coords&#xA;        glBindBuffer(GL_ARRAY_BUFFER, VBO_yCoord_IDs[i]);&#xA;        glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*yCoords[i].size(), &amp;amp;yCoords[i][0], GL_STREAM_DRAW);&#xA;        glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;        glEnableVertexAttribArray(1);&#xA;        //normals&#xA;        glBindBuffer(GL_ARRAY_BUFFER, VBO_normals_IDs[i]);&#xA;        glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*VBO_normals_IDs[i].size(), &amp;amp;VBO_normals_IDs[i][0], GL_STREAM_DRAW);&#xA;        glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;        glEnableVertexAttribArray(2);&#xA;        //colors&#xA;        glBindBuffer(GL_ARRAY_BUFFER, VBO_colors_IDs[i]);&#xA;        glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*VBO_colors_IDs[i].size(), &amp;amp;VBO_colors_IDs[i][0], GL_STREAM_DRAW);&#xA;        glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;        glEnableVertexAttribArray(3);&#xA;&#xA;//indices&#xA;        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO_indices_IDs[i]);&#xA;        glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*indices.size(), &amp;amp;indices[0], GL_STATIC_DRAW);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Rendering function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (size_t i = 0; i &amp;lt; 10; i++)&#xA;    {&#xA;        glBindVertexArray(VAO_IDs[i]);&#xA;        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO_indices_IDs[i]);&#xA;        glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, (void*)0);&#xA;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So as you can see, I create a new xz-coordinates and indices buffer for each VAO. I doubt this is the most effective way to do it. How should I do this?&lt;/p&gt;&#xA;" OwnerUserId="3434" LastActivityDate="2017-01-29T15:52:14.177" Title="Multiple VAO share a VBO" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4625" PostTypeId="2" ParentId="4623" CreationDate="2017-01-29T15:52:14.177" Score="4" Body="&lt;p&gt;VAO can share VBO's because they do not store vertex data itself but references to Vertex Buffer Objects. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you can first generate your buffers and upload your buffer data (vertex data and index data) to currently bound buffers.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenBuffers(1, &amp;amp;VBO_xzCoord_IDs[i]);&#xA;glGenBuffers(1, &amp;amp;VBO_yCoord_IDs[i]);&#xA;glGenBuffers(1, &amp;amp;VBO_indices_IDs[i]);&#xA;glGenBuffers(1, &amp;amp;VBO_normals_IDs[i]);&#xA;glGenBuffers(1, &amp;amp;VBO_colors_IDs[i]);&#xA;&#xA;//xz coords&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO_xzCoord_IDs[i]);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*xzCoords.size(), &amp;amp;xzCoords[0], GL_STATIC_DRAW);&#xA;&#xA;...&#xA;&#xA;//indices&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO_indices_IDs[i]);&#xA;glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint)*indices.size(), &amp;amp;indices[0], GL_STATIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then generate your VAO's and connect vertex array object data index you provide in &lt;code&gt;glVertexAttribPointer&lt;/code&gt; call with currently bound &lt;code&gt;GL_ARRAY_BUFFER&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;GL_ELEMENT_ARRAY_BUFFER&lt;/code&gt; can be a little confusing because it doesn't require &lt;code&gt;glVertexAttribPointer&lt;/code&gt; call. So how it is connected with VAO? It seems that binding the buffer ties it to the currently bound VAO.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//VAO&#xA;glGenVertexArrays(1, &amp;amp;VAO_IDs[i]);&#xA;glBindVertexArray(VAO_IDs[i]);&#xA;&#xA;//xz coords&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO_xzCoord_IDs[i]);&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;&#xA;...&#xA;&#xA;//indices&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBO_indices_IDs[i]);&#xA;&#xA;glBindVertexArray(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And in your rendering call you don't need to bind &lt;code&gt;GL_ELEMENT_ARRAY_BUFFER&lt;/code&gt; because it was already connected with VAO.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2017-01-29T15:52:14.177" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4626" PostTypeId="1" AcceptedAnswerId="4636" CreationDate="2017-01-29T16:24:12.903" Score="2" ViewCount="602" Body="&lt;p&gt;In my project, for convenience I would like to use many buffers. &#xA;Many buffers in my case means 50-100 terrain patches represented by buffers with vertex coordinates, normals, indices and maybe color. The magnitude of data would be, let's say &lt;strong&gt;10^4 floats&lt;/strong&gt; per buffer. Some of this data can be shared between each terrain patch, f.ex. xz-coordinates and indices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;During the rendering loop, some terrain patches will be updated. Which means that for certain buffers I call &lt;code&gt;glBufferSubData()&lt;/code&gt; for the whole buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is; are there any pros/cons, performance wise between these two methods:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; Controlling my data in many buffers (50-100), thus letting me call &lt;code&gt;glBufferSubData&lt;/code&gt; on a complete buffer when needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; Controlling my data in fewer (5-20) buffers, with more data in each. But then having to set up a system where I need to call &lt;em&gt;glBufferSubData&lt;/em&gt; on smaller portion of a buffer. (Which leads to a more complex design in my case). &lt;/p&gt;&#xA;" OwnerUserId="3434" LastEditorUserId="3434" LastEditDate="2017-01-29T16:29:22.060" LastActivityDate="2017-01-30T21:22:18.990" Title="Multiple buffers and calling glBufferSubData" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4627" PostTypeId="1" CreationDate="2017-01-29T17:05:14.790" Score="1" ViewCount="948" Body="&lt;p&gt;I want to know about some technique with which i can generate nice reflections on the surface. I know one conventional technique where we invert an object and render it and blend it with the floor but in this technique each object has to be rendered twice which is not good. Is there any other technique to achieve the same result?&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="2096" LastEditDate="2017-01-30T14:50:15.433" LastActivityDate="2017-01-30T14:50:15.433" Title="Which technique is fast to generate real-time reflections?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;real-time&gt;&lt;reflection&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4628" PostTypeId="2" ParentId="4627" CreationDate="2017-01-29T19:58:21.713" Score="2" Body="&lt;p&gt;Usually modern game engines use &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Rendering/PostProcessEffects/ScreenSpaceReflection/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Screen Space Reflections&lt;/a&gt; which is some kind of screen space raymarching.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, a simple way to achieve this is to shoot rays from the G-buffer. This means you use your depth buffer as a height field by raymarching any ray you cast. Then sample the normal at this position and take the final composed lighting from you previous frame and project it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although it has the usual drawbacks associated with any screen space method. This means you only have what is visible in front of you (screen space) to compute your reflections, so anything outside the screen would require tricks to have them get reflected on your current frame (e.g. you can combine this with environment mapping reflections and such).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find a few &lt;a href=&quot;http://casual-effects.blogspot.fr/2014/08/screen-space-ray-tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;articles&lt;/a&gt; about that and &lt;a href=&quot;http://www.frostbite.com/2015/08/stochastic-screen-space-reflections/&quot; rel=&quot;nofollow noreferrer&quot;&gt;presentations&lt;/a&gt; on the Internet.&lt;/p&gt;&#xA;" OwnerUserId="5002" LastEditorUserId="5002" LastEditDate="2017-01-29T22:14:55.970" LastActivityDate="2017-01-29T22:14:55.970" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4630" PostTypeId="1" CreationDate="2017-01-30T17:29:42.183" Score="1" ViewCount="124" Body="&lt;p&gt;This is PNG was exported from Inkscape.  I created it manually and used the&#xA;connector tool to link tables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I find the plain SVG for this diagram more complicated than I was expecting so would like to know if there are simpler graphic languages or specifications for this task?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to write something using Python.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the pastebin: &lt;a href=&quot;http://pastebin.com/PDEupPFr&quot; rel=&quot;nofollow noreferrer&quot;&gt;SVG for database diagram&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ixSgo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ixSgo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5958" LastEditorUserId="48" LastEditDate="2017-01-30T17:54:30.523" LastActivityDate="2017-01-30T17:54:30.523" Title="What graphic languages are simpler than SVG for database diagrams?" Tags="&lt;2d&gt;&lt;vector-graphics&gt;&lt;diagram&gt;" AnswerCount="1" CommentCount="2" ClosedDate="2017-02-04T02:02:40.960" ContentLicense="CC BY-SA 3.0" />
  <row Id="4631" PostTypeId="2" ParentId="4630" CreationDate="2017-01-30T17:50:53.680" Score="1" Body="&lt;p&gt;&lt;a href=&quot;http://www.graphviz.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Graphviz&lt;/a&gt; is a popular tool for making network diagrams. It takes a text format (&quot;DOT language&quot;) describing the nodes and edges as input, and can render the resulting diagram to SVG or other image formats.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-30T17:50:53.680" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4632" PostTypeId="1" CreationDate="2017-01-30T19:16:44.263" Score="8" ViewCount="1159" Body="&lt;p&gt;I'm creating a renderer using modern OpenGL (3.1 and up) and now I'm trying to create an efficient but flexible way of handling uniforms. I've been reading up on uniform buffer objects and on what a 'common' approach is to using these (the latter unfortunately didn't give me as many results as I had hoped).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to reduce OpenGL API calls and storing data in contiguous memory, I'm considering creating multiple large buffers for each data structure that should be uploaded to the GPU. Each buffer has a maximum size of 16kb (as from what I understand this much is guaranteed to be available for an UBO). When an object wants to be able to upload uniforms to the GPU it fetches the first buffer of the to-be-uploaded-type that isn't full yet and gets the next available index in that buffer. When the object is drawn it binds the UBO (if not bound yet) and uploads the element index of the UBO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This results in something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(std140) uniform ModelData { &#xA;    mat4 model_matrix[kNumInstancesPerModelUbo]; &#xA;}&#xA;uniform int u_ModelDataIndex;&#xA;&#xA;layout(std140) uniform SkeletonData { &#xA;    mat4 bone_transforms[kNumInstancesPerSkeletonUbo][kMaxBones]; &#xA;}&#xA;uniform int u_SkeletonDataIndex;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However I'm also considering the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(std140) uniform MeshData {&#xA;    mat4 model_matrix[kNumInstancesPerMeshUbo];&#xA;    mat4 bone_transforms[kNumInstancesPerMeshUbo][kMaxBones];&#xA;}&#xA;uniform int u_MeshDataIndex;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In some ways this feels a lot cleaner in that it takes a single index to access all data related to the mesh to be uploaded. On the other hand this could get out of hand (buffer size larger than 16kb, handles to irrelevant data (e.g. a mesh with no skeleton) or even synchronization issues as you're not allowed access to say the bones while uploading the model matrices) and I'm not sure how this would affect the memory layout on the GPU either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Frankly it feels like I'm stuck here and I can't find a good concrete example of how you'd go about handling UBO's fast and flexible. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any advice or resources for me that could help me out here?&lt;/p&gt;&#xA;" OwnerUserId="5960" LastEditorUserId="2287" LastEditDate="2018-09-15T12:48:25.543" LastActivityDate="2018-11-14T17:58:25.930" Title="What is a good approach for handling uniforms in modern OpenGL?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;glsl&gt;&lt;c++&gt;&lt;uniform-buffer-object&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="4634" PostTypeId="2" ParentId="4621" CreationDate="2017-01-30T19:56:54.660" Score="2" Body="&lt;p&gt;If you have a point $C$ on a line defined by a point $A$ and a point $B$, here is how you calculate the barycentric coordinates $(t_0,t_1)$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$t_0 = \frac{sqrt((C_x-A_x)^2+(C_y-A_y)^2)}{sqrt((B_x-A_x)^2+(B_y-A_y)^2)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$t_1 = 1.0 - t_0$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, you calculate the length of the vector from $A$ to $C$, and divide that by the length of the vector from $A$ to $B$.  This gives you $t_0$, and you can subtract that from 1.0 to get $t_1$ since barycentric coordinates always add up to 1.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A more mathish style version of the above is this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$t_0 = \frac{\left\| C-A\right\|}{\left\| B-A\right\|}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$t_1 = 1.0 - t_0$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it's important to note that $C$ must be on the line defined by $A$ and $B$.  If that isn't the case, let us know and let us know what it is you are trying to do specifically.  For instance, maybe you want to project some other point $D$ onto the line $\overline{AB}$ and then find the barycentric coordinates of that projected point?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-01-30T19:56:54.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4635" PostTypeId="1" CreationDate="2017-01-30T20:10:13.587" Score="0" ViewCount="205" Body="&lt;p&gt;How do I test to see if a polygon edge is facing another polygon? For the edge being tested to return true, the edge needs to be facing a polygon which has a different attribute than itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://drive.google.com/uc?export=download&amp;amp;id=0B5gF5vQzfd2SMDFERkhxUE1heEk&quot; alt=&quot;polygon example&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this example, I am iterating through the edges on Polygon A. Segment 0 and segment 1 would return true for facing the polygon, where segment 2 would return false, because, while it is still facing a polygon, the polygon has the same 'green' attribute.&lt;/p&gt;&#xA;" OwnerUserId="5961" LastEditorUserId="5961" LastEditDate="2017-01-30T20:30:24.947" LastActivityDate="2017-05-31T07:26:53.907" Title="Test if polygon edge is facing another polygon" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4636" PostTypeId="2" ParentId="4626" CreationDate="2017-01-30T21:22:18.990" Score="3" Body="&lt;p&gt;It depends. There are a few competing factors at work here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, consolidating terrain data into fewer buffers (or one) may allow you to combine multiple terrain patches together in a single draw call—assuming there aren't other state changes between patches that would prevent this. So, you may be able to reduce draw-call overhead this way, or at least reduce the state-change overhead between draws. That being said, 50–100 draw calls is not that many, so this may not be a real performance concern.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition, do you anticipate needing to use the terrain data for other shader effects? For example, maybe a shader procedurally generates grass growing on the terrain, or you use height above the terrain to influence lighting or AO or some such. In that case having all the terrain data in one big buffer that you can pass to those shaders may simplify things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, if you're having the terrain deformed/edited in real-time (which it sounds like you are), then it may be faster to update the entirety of a small buffer than to update a small portion of a large buffer. The problem is when the CPU and GPU are working asynchronously, and you update a buffer from the CPU, the GPU may still be using the previous version of that buffer. To fix this, the driver internally keeps 2–3 instances of the buffer (much like double/triple buffering the screen). If you always update the entire buffer at once, the driver can just put the updated data into the &quot;next&quot; instance of that buffer. But if you update only part of the buffer, the driver must copy all the &lt;em&gt;rest&lt;/em&gt; of the data from the current instance to the next instance. This extra copy will consume some performance either on the CPU or on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if the terrain data was entirely static I'd say it's better to put it all in one big buffer. However, if you're going to be updating portions of the data in real-time, it may be better to keep it in smaller buffers so that you can update exactly the ones that have changed while leaving others alone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, you'll have to do some profiling to see which approach is better.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-01-30T21:22:18.990" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4637" PostTypeId="1" AcceptedAnswerId="4638" CreationDate="2017-01-30T23:55:32.017" Score="2" ViewCount="4073" Body="&lt;p&gt;If no, Should I create a new VAO for every VBO that has its own vertex attribute configurations?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you please give me a snippet code example that shows how to use one VAO for multiple VBOs? All examples I find on the internet call to glVertexAttribPointer before drawing a buffer, but if you have to call that method everytime you want to draw a buffer, then VAOs doesn't make sense.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: The tutorial I'm following uses Opengl 3.3&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="5852" LastEditDate="2017-01-31T19:36:51.077" LastActivityDate="2017-02-01T16:50:10.010" Title="Can one VAO store multiple calls to glVertexAttribPointer?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;vertex-buffer-object&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4638" PostTypeId="2" ParentId="4637" CreationDate="2017-01-31T01:48:48.497" Score="2" Body="&lt;p&gt;Yes, VAO state includes vertex attribute specification for multiple attributes. Each attribute has its own format information and can come from a distinct buffer object. That's part of why you can only bind one VAO at a time.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// two VBOs but one VAO&#xA;GLuint points_vbo = 0;&#xA;glGenBuffers(1, &amp;amp;points_vbo);&#xA;glBindBuffer(GL_ARRAY_BUFFER, points_vbo);&#xA;glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), points, GL_STATIC_DRAW);&#xA;&#xA;GLuint colours_vbo = 0;&#xA;glGenBuffers(1, &amp;amp;colours_vbo);&#xA;glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);&#xA;glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), colours, GL_STATIC_DRAW);&#xA;&#xA;GLuint vao = 0;&#xA;glGenVertexArrays(1, &amp;amp;vao);&#xA;glBindVertexArray(vao);&#xA;glEnableVertexAttribArray(0);&#xA;glEnableVertexAttribArray(1);&#xA;&#xA;&#xA;rendering-loop&#xA;{&#xA;    glBindVertexArray(vao);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, points_vbo);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, colours_vbo);&#xA;    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);&#xA;&#xA;    glDrawArrays(GL_TRIANGLES, 0, 3);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;PS: you will need to be careful about the location of the vertex attribute. Those used in the rendering loop need to match those in the vertex shader.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-01-31T16:56:54.283" LastActivityDate="2017-01-31T16:56:54.283" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4639" PostTypeId="2" ParentId="4635" CreationDate="2017-01-31T05:00:08.793" Score="1" Body="&lt;p&gt;You can take the normal of the line segment you're testing and find the dot product of that normal and the normal of each segment of the polygon you're testing against. If it is positive, then they are facing the same way. If the dot product is negative, then the line segments are facing in opposite directions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If they are facing in opposite directions, then they're either pointing at each other, or away from each other. You can figure out which by calculating a vector from a point on the first segment to a point on the other segment and seeing if it's facing the same direction as its normal (by again using the dot product). If so, they are facing each other, otherwise they're facing away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can skip all the tests above by first testing if the polygons are the same color and only doing the tests if they're not.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-01-31T05:00:08.793" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4640" PostTypeId="1" CreationDate="2017-01-31T05:43:42.517" Score="1" ViewCount="888" Body="&lt;p&gt;How do I classify a point with respect to a plane, returning whether the point is inside, outside, or coplanar?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that if a point is on the plane the Dot product + the plane distance would equal to 0, but what does inside, outside, and coplanar mean. Also how it is computed.&lt;/p&gt;&#xA;" OwnerUserId="5943" LastActivityDate="2019-08-05T05:45:12.480" Title="Point respect to plane" Tags="&lt;c++&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4641" PostTypeId="2" ParentId="4637" CreationDate="2017-01-31T09:46:08.293" Score="3" Body="&lt;p&gt;In version 4.3+ the vao layout can be set independently from the VBO buffer which allows you to rebind the vbo without having to call vertexAttribPointer every time:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//in init&#xA;glBindVertexArray(vao);&#xA;&#xA;glVertexAttribFormat(posAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, pos));&#xA;// set the details of a single attribute&#xA;glVertexAttribBinding(posAttrLoc, 0);&#xA;// which buffer binding point it is attached to&#xA;glEnableVertexAttribArray(posAttrLoc);&#xA;&#xA;glVertexAttribFormat(normalAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, normal));&#xA;glVertexAttribBinding(normalAttrLoc, 0);&#xA;glEnableVertexAttribArray(normalAttrLoc);&#xA;&#xA;glVertexAttribFormat(texAttrLoc, 2, GL_FLOAT, false, offsetof(Texture, tex));&#xA;glVertexAttribBinding(texAttrLoc, 1);&#xA;glEnableVertexAttribArray(texAttrLoc);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that there is no mention of any VBO during init, just the binding points. That binding point is then used during draw to specify which vbo to pull the vertex data from:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//draw&#xA;&#xA;glBindVertexArray(vao);&#xA;foreach(mesh in meshes){&#xA;    glBindVertexBuffer(0, mesh.vbo, mesh.vboOffset, sizeof(Vertex));&#xA;    glBindVertexBuffer(1, mesh.texVbo, mesh.texVboOffset, sizeof(Texture));&#xA;    // bind the buffer to the binding point&#xA;    glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);&#xA;    //draw&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In pre 4.3 you would create a VAO per mesh and per mesh call glVertexAttribPointer for each attribute:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(mesh.vao);&#xA;glBindBuffer(GL_ARRAY_BUFFER, mesh.vbo);&#xA;&#xA;glVertexAttribPointer (posAttrLoc, 3, GL_FLOAT, false, sizeof(Vertex), mesh.vboOffset + offsetof(Vertex, pos));&#xA;glEnableVertexAttribArray(posAttrLoc);&#xA;//...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then during draw bind the per mesh vao before drawing it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;foreach(mesh in meshes){        &#xA;    glBindVertexArray(mesh.vao);&#xA;    glDrawArrays(GL_TRIANGLES, 0, mesh.vertexCount);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2017-02-01T16:50:10.010" LastActivityDate="2017-02-01T16:50:10.010" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4642" PostTypeId="2" ParentId="4640" CreationDate="2017-01-31T10:34:49.637" Score="2" Body="&lt;pre&gt;&lt;code&gt;Vec3 v = myPoint - pointOnPlane;&#xA;float vDotPlaneNormal = dot(v, planeNormal)&#xA;if (vDotPlaneNormal == 0) &#xA;    printf(&amp;quot;point on plane&amp;quot;);&#xA;else if (vDotPlaneNormal &amp;gt; 0)&#xA;    printf(&amp;quot;point above somehow...&amp;quot;);&#xA;else&#xA;    printf(&amp;quot;point under sadly...&amp;quot;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If you wonder what is &lt;code&gt;pointOnPlane&lt;/code&gt;. In fact it can be any point that lies on the plane. Imagine this as a sheet of paper; draw two lines on this sheet to define the center of the piece of paper, imagine that this point is aligned with the world coordinate system origin and that sheet is in xz plane of that coordinate system (in which y defines the up vector). So the paper is horizontal in a way. Now move the sheet around. The &lt;code&gt;pointOnPlane&lt;/code&gt; can be the coordinates of the point you drew in the center of the sheet of paper with respect to the world origin.&lt;/p&gt;&#xA;&lt;p&gt;All you have to do is rotate that sheet of paper. That rotation is given to you by the plane's normal.&lt;/p&gt;&#xA;&lt;p&gt;The rest is basic trig. If the point P is one the plane, the dot product between the vector defined by (P - PointOnPlane) and the plane's normal will be equal to 0. The dot product tells you whether two vectors are orthogonal, on the same side of the plane or point in opposite directions.&lt;/p&gt;&#xA;&lt;h1&gt;FASTER SOLUTION - EDIT&lt;/h1&gt;&#xA;&lt;p&gt;As mentioned by SimonF in a comment, you don't really need the &lt;code&gt;pointOnPlane&lt;/code&gt; parameter and save the subtraction between this point and the tested point:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;As you imply, a plane can be represented by its normal, &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt;, and a scalar, &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;A point X is on the plane if &lt;span class=&quot;math-container&quot;&gt;$N \cdot X+d = 0$&lt;/span&gt;. As for inside and&#xA;outside typically you define a rule, e.g., that the normal points&#xA;&amp;quot;out&amp;quot; from the plane which just means that if &lt;span class=&quot;math-container&quot;&gt;$N \cdot X + d &amp;gt; 0$&lt;/span&gt;, then&#xA;&lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; is above the plane, while &lt;span class=&quot;math-container&quot;&gt;$N \cdot X + d &amp;lt; 0$&lt;/span&gt;, implies it's below.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;You can test/use both techniques.&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-08-05T05:45:12.480" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="4645" PostTypeId="1" CreationDate="2017-01-31T21:11:24.653" Score="0" ViewCount="230" Body="&lt;p&gt;I have an obj file together with an associated mtl file and texture jpg file. I have managed to find some code that sets a specific camera view and raytraces the image to output a depth map plus a point cloud. The code is using assimp and CGAL to do this. I have access to the specific face the ray intersects but I don't know how to find the pixel color value at the intersection point. Can this be done? Or is there are better way to do this using some software or library? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My final goal is to create depth and color images of different viewpoints from a set of viewpoints for given camera parameters.&lt;/p&gt;&#xA;" OwnerUserId="5972" LastActivityDate="2017-02-01T09:54:22.953" Title="Getting texture value of cartesian coordinate from a Obj file" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4646" PostTypeId="2" ParentId="4645" CreationDate="2017-02-01T07:10:39.080" Score="1" Body="&lt;p&gt;Your question is very broad because it is close again to &quot;how to I render 3D objects&quot;. So some people might give you a more precise answer than mine but at least I will try to give you some pointers.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;First look on the web. There are plenty of tutorials that explain to you exactly what you to do (which is to raytrace texture mapped objects). While it's great to ask questions, there is really no excuse for posting such a generic question here, considering the amount of information that is available on the topic on the Web.&lt;/li&gt;&#xA;&lt;li&gt;Though I will try to give you some pointers nonetheless (because we are kind and not here to judge each other;0)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;What you want to do is called texture mapping. The way it's done is simple. Each triangle of your geometry holds what we call vertex coordinates, basically it explains how a triangle is actually mapped onto an image (or texture). Imagine your triangle laying flat on the image. The part that it lays on is that part of the texture that should appear on the triangle once rendered. Note that texture coordinates are 2D coordinates and that the shape of the triangle in the texture space (when it lays flat on the texture) doesn't have to match the shape of the triangle in 3D space (in which case the texture will be stretched).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So your 3D object when you render it should have a set of 3D points (the vertex position) 3D normals (the normals of the object at the vertex position) and 2D coordinates (read from the OBJ file).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the ray hits a triangle your compute the texture coordinates at the intersection point using the &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage&quot; rel=&quot;nofollow noreferrer&quot;&gt;barycentric coordinates&lt;/a&gt; of the intersection point and the texture coordinates set at the 3 vertices of the hit triangle. This is very common technique you will find many tutorials about that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then once you have your interpolated texture coordinates you use it to do a lookup into the texture. The texture coordinates are in the range [0:1] (in general), where (0,0) might be the top-left corner if your texture and (1,1) the bottom right. You need to remap that texture coordinate to pixel space (multiply it by image width and height and cast to integers eventually).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now just read the pixel value at that position (remapped to pixel coordinates), and that's the color of the mapped intersection point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Easy, breezy!&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="1608" LastEditDate="2017-02-01T09:54:22.953" LastActivityDate="2017-02-01T09:54:22.953" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4648" PostTypeId="1" CreationDate="2017-02-02T05:56:18.780" Score="1" ViewCount="919" Body="&lt;p&gt;I was trying to make a CPU-based ray tracer but I know after all the calculation I will end up with an array of pixels. I don't know how to paint it on the screen. What are the various ways to do that? I am using C++ and I am working on Windows 10. I know OpenGL(useless since I am not gonna use my GPU), Allegro 5 game library and I am also familiar with win32 C++ API. &lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="6546" LastEditDate="2017-05-05T16:40:51.833" LastActivityDate="2017-05-05T16:40:51.833" Title="How can I send custom bitmap to frame buffer?" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;c++&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4649" PostTypeId="1" AcceptedAnswerId="4652" CreationDate="2017-02-02T13:52:12.987" Score="0" ViewCount="105" Body="&lt;p&gt;I was always interested how programs like: Unity, AE, godot engine and other render their custom guis. So my question is, do they use graphics library to render custom guis or something else. If they don't use graphics library, should I use it? Thanks :).&lt;/p&gt;&#xA;" OwnerUserId="5985" LastActivityDate="2017-02-02T17:40:41.843" Title="Does programs like After effects and Unity engine use graphics library to render custom guis?" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4650" PostTypeId="1" CreationDate="2017-02-02T15:11:42.530" Score="3" ViewCount="1237" Body="&lt;p&gt;I can't find any paper about a bevel/chamfer algorithm for 3D mesh. Bevel has a lot of special cases (corners, different bevel profile, bevel larger than a face). I am looking for robustness.&#xA;Do you know any algorithm for this ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="5986" LastActivityDate="2017-02-07T06:55:00.263" Title="Bevel/Chamfer algorithm for arbitrary 3D mesh" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4651" PostTypeId="1" CreationDate="2017-02-02T16:03:42.733" Score="7" ViewCount="1388" Body="&lt;p&gt;I am trying to retrofit &lt;a href=&quot;http://jcgt.org/published/0002/02/09/&quot; rel=&quot;noreferrer&quot;&gt;weighted blended OIT&lt;/a&gt; to my rendering pipeline and while it works well, producing convincing results, for normal alpha blending (based on the OVER) operator, I am struggling to make it support additive blending (for example Colour1 + Colour2 + Background Colour) correctly using the blending formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \frac{C_1 w_1 + C_2 w_2}{\alpha_1 w_1 + \alpha_2 w_2} \cdot \bigl(1 - (1 - \alpha_1)(1 - \alpha_2)\bigr) + \text{Bg} \cdot (1 - \alpha_1)(1 - \alpha_2) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could hack it outputting weight values of 1 and very low alphas (eg 0.01), which would make it to sort of converge to additive blending, trouble is, this does not weight the colours at all and does not blend nicely with normal alpha blending.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering how people have tackled this problem.&lt;/p&gt;&#xA;" OwnerUserId="270" LastEditorUserId="48" LastEditDate="2017-02-02T18:20:26.063" LastActivityDate="2017-12-30T17:10:40.843" Title="Additive blending with weighted-blended order independent transparency" Tags="&lt;transparency&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4652" PostTypeId="2" ParentId="4649" CreationDate="2017-02-02T17:40:41.843" Score="1" Body="&lt;p&gt;So:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;All GUI are somehow graphics. They don't have to be accelerated by the GPU but these days most are. In the old times, they could be rendered on the CPU (X11 times).&lt;/li&gt;&#xA;&lt;li&gt;You need to be careful between making a distinction between the frameworks/libraries that are potentially being used for building up UIs and what these libraries use to render the graphics making up these UIs.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;A lot of applications like Maya for instance use libraries for creating their UIs (Maya uses Qt so as most products developed by the Foundry: Nuke, Marri, etc.) which is why a lot of these applications look the same ... (sadly).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Qt and most UI library/framework use a graphics API to accelerate the rendering of widgets. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some applications like Unity do not use &quot;commercial&quot; libraries like Qt. They develop their own, but in the end they also use the GPU to render their GUIs.&lt;/p&gt;&#xA;" OwnerUserId="1608" LastActivityDate="2017-02-02T17:40:41.843" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4653" PostTypeId="2" ParentId="4648" CreationDate="2017-02-02T21:26:21.273" Score="2" Body="&lt;p&gt;This answer uses GDI and a little bit of MFC. The MFC bits aren't necessary and just there for my convenience. You can hit the Windows API directly if you need to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your window class have some data members for the bitmap. I currently use MFC's CBitmap for convenience:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;CBitmap             bitmap_;&#xA;unsigned char*      bitmapBits_;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;bitmapBits_&lt;/code&gt; is a pointer to the bitmap data that you can write directly into.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before rendering, you'll need to create the bitmap using &lt;code&gt;CreateDIBSection()&lt;/code&gt; and get the pointer to the bits of the bitmap:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;BITMAPINFO bmi;&#xA;memset(&amp;amp;bmi.bmiHeader,0,sizeof(bmi.bmiHeader));&#xA;bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);&#xA;bmi.bmiHeader.biWidth = widthOfTheImage;&#xA;bmi.bmiHeader.biHeight = heightOfTheImage;&#xA;bmi.bmiHeader.biPlanes = 1;&#xA;bmi.bmiHeader.biBitCount = 24;&#xA;bmi.bmiHeader.biCompression = BI_RGB;&#xA;&#xA;void* bitmapBits;&#xA;bitmap_.Attach(CreateDIBSection(0,&amp;amp;bmi,DIB_RGB_COLORS,&amp;amp;bitmapBits,0,0));&#xA;if(bitmap_.m_hObject == NULL)&#xA;    AfxMessageBox(&quot;CreateDIBSection() FAILED!\n&quot;);&#xA;bitmapBits_ = reinterpret_cast&amp;lt;unsigned char*&amp;gt;(bitmapBits);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When writing to the bitmap bits, you first need to determine the row size (see &lt;a href=&quot;https://en.wikipedia.org/wiki/BMP_file_format#Pixel_storage&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Compute the row size of a DIB.&#xA;// (See https://en.wikipedia.org/wiki/BMP_file_format#Pixel_storage and ComputePitch() from atlimage.h)&#xA;const unsigned int rowSize = ((24 * imageWidth + 31) / 32) * 4;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then you can write the colour information into the bitmap's data. Note this is a bottom-up DIB; memory earlier in the buffer represents scanlines lower in the image. Another way of putting it is that the the first element of the bitdata relates to the bottom-left. Colour components are in BGR order. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned char* dibPtr = &amp;amp;bitmapBits_[pixelY * rowSize + pixelX * 3];&#xA;dibPtr[0] = ???; // blue between 0 and 255&#xA;dibPtr[1] = ???; // green between 0 and 255&#xA;dibPtr[2] = ???; // red between 0 and 255&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Sorry if the previous part is already known to you, as you asked simply how to get it painted to the screen. Here's my simplified paint routine from my MFC application:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RendererWnd::OnPaint()&#xA;{&#xA;    CPaintDC dc(this);&#xA;&#xA;    CDC dcMemory;&#xA;    dcMemory.CreateCompatibleDC(&amp;amp;dc);&#xA;    CBitmap* oldBmp = dcMemory.SelectObject(&amp;amp;bitmap_);&#xA;    dc.BitBlt(0,0,imageWidth,imageHeight,&amp;amp;dcMemory,0,0,SRCCOPY);&#xA;    dcMemory.SelectObject(oldBmp);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There are going to be many other ways of doing this. If you're doing a long render and want to update the window periodically then you'll probably want to have a timer in your window. When this timer fires you want to request a repaint of your window using &lt;code&gt;InvalidateRect()&lt;/code&gt;. You'll need to synchronise access to the bitmap data between your rendering thread(s) and the thread that's doing the painting. This will ensure the painter can access the bitmap when it's not being written to. I use a &lt;code&gt;CRITICAL_SECTION&lt;/code&gt; for this.&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2017-02-02T21:26:21.273" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4654" PostTypeId="1" CreationDate="2017-02-03T01:17:58.430" Score="1" ViewCount="587" Body="&lt;p&gt;I recently ran across the paper &lt;a href=&quot;https://arxiv.org/abs/1606.01299&quot; rel=&quot;nofollow noreferrer&quot;&gt;RAISR: Rapid and Accurate Image Super Resolution&lt;/a&gt; and thought it seemed like an interesting technique for scaling up images. However, I haven't seen any implementation of it, and I would like to see what it would be like to use it for scaling up a video in realtime, if that is possible. So I'm thinking of implementing my own version of it, but I will need to use GPU acceleration in some way if I want to at least give it a chance to run in realtime. Ultimately, I would like to see if I could successfully implemented this in an open source media player.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;So&lt;/strong&gt;, what library should I use to implement this algorithm? DirectX and CUDA are out of the question, since I want to make it run under any (major) OS and on any graphics card (well, on most of the popular ones, at least), so I'm thinking that my only options are&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;OpenGL (ES) + GLSL (ES), and&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;OpenCL.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;(Vulkan also exists but I don't know whether this API is mature enough yet.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I choose OpenGL + GLSL, is this approach flexible enough to allow this algorithm to be implemented? Are there algorithms that cannot be implemented this way and have to be implemented in OpenCL, and if so, how do I know if my algorithm is one of them?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I on the other hand choose OpenCL, will it be possible for other people to use my implementation without installing OpenCL on their computer? &lt;/p&gt;&#xA;" OwnerUserId="5989" LastActivityDate="2017-02-03T03:29:57.760" Title="What framework shoud I use to implement the RAISR upscaling algorithm on the GPU?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;real-time&gt;&lt;gpgpu&gt;&lt;opencl&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4655" PostTypeId="2" ParentId="4654" CreationDate="2017-02-03T03:29:57.760" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Are there algorithms that cannot be implemented this way and have to be implemented in OpenCL, and if so, how do I know if my algorithm is one of them?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes. Generally &lt;a href=&quot;https://en.wikipedia.org/wiki/Gather-scatter_(vector_addressing)&quot; rel=&quot;nofollow noreferrer&quot;&gt;scatter-gather algorithms&lt;/a&gt; work poorly in OpenGL as the data locality is poor. When you have to grab bits from all over the input image for each output pixel, it's going to be slow or nearly impossible to implement in a typical GL shader. Likewise, when a calculation on an input pixel results in data that needs to be spread out to several output pixels, it's a poor fit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's hard to tell just from the abstract, but it looks to me like this wouldn't be a great fit for a typical OpenGL shader. I think you'll end up needing to sample an area of the input, classify it, then sample from one or more of a large set of small exemplars.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I mainly work on iOS and macOS which both come with OpenGL and OpenCL. Not sure how Windows and Linux handle that.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-02-03T03:29:57.760" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4656" PostTypeId="1" AcceptedAnswerId="4673" CreationDate="2017-02-03T04:00:09.103" Score="4" ViewCount="598" Body="&lt;p&gt;I'm implementing mesh skinning in a project of mine. I can calculate vertex positions based on bone transformations, but I've run into a problem with calculating their normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the resources I've read, it appears that a given vertex's skinned normal is the weighted sum of each influencing bone's transform applied to the vertex's normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I don't understand, is how this would produce equivalent normals to what you &lt;em&gt;would&lt;/em&gt; get if you calculated each vertex's normal directly. (I.E. from the sum of the normals of its adjacent faces)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, consider the case of three connected vertices with the normals shown below. Note the bone in the center, which has the same position as the center vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/stboN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/stboN.png&quot; alt=&quot;A simple rigged mesh&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, suppose this bone is turned 45 degrees CCW. If this bone only influenced the vertex to its right, my understanding is that it would produce the following result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mQfeC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mQfeC.png&quot; alt=&quot;Single influenced vertex&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is because there is only one influencing bone, and the normal is rotated by the same rotation as the bone, 45 degrees CCW.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, consider that the bone influenced the middle &lt;em&gt;and&lt;/em&gt; right vertices. Each vertex's normal would be rotated exactly as in the previous image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MG97U.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MG97U.png&quot; alt=&quot;Two influenced vertices&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, neither of these would produce the &quot;correct&quot; normal for the middle vertex, shown here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dKPYh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dKPYh.png&quot; alt=&quot;Presumably the correct middle normal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, my question is, is this the intended behavior for this algorithm? Is it only meant to be an approximation, or have I missed something critical? How are these normals meant to be calculated?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For what it's worth, the resources I've been following are presented &lt;a href=&quot;http://web.archive.org/web/20161027175806/http://ruh.li/AnimationVertexSkinning.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://www.3dgep.com/loading-and-animating-md5-models-with-opengl/#The_MD5Model::PrepareMesh_Method&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5991" LastEditorUserId="-1" LastEditDate="2019-10-28T00:51:51.253" LastActivityDate="2019-10-28T00:51:51.253" Title="Calculating Skeleton-Deformed Mesh Normals" Tags="&lt;algorithm&gt;&lt;mesh&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="4657" PostTypeId="2" ParentId="4651" CreationDate="2017-02-03T07:07:19.220" Score="0" Body="&lt;p&gt;Use the following equation for blending&#xA;$$&#xA;\frac{\alpha_1 w_1 C_1 + \alpha_2 w_2 C_2}{\alpha_1 w_1 + \alpha_2 w_2}.(1-(1-\alpha_1)(1-\alpha_2)) + Bg.(1-\alpha_1)(1-\alpha_2)&#xA;$$&#xA;Also note that $\alpha$ value must always be between $0$ and $1$&lt;/p&gt;&#xA;" OwnerUserId="5881" LastActivityDate="2017-02-03T07:07:19.220" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4659" PostTypeId="1" AcceptedAnswerId="4667" CreationDate="2017-02-03T18:22:16.563" Score="2" ViewCount="110" Body="&lt;p&gt;Currently I got interested in implementation of Precomputed Radiance Transfer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I decided that occlusion representation (which is not trivial to compute) would be precomputed as CPU raytracing and stored as vertex buffer in addition to usual vertices. This representation would be stored as SH coefficients because I need to have information about occluded and unoccluded directions (probably 4 so additional &lt;code&gt;vec4&lt;/code&gt; buffer). So these would store only unoccluded directions. I don't know yet how that would behave but using this foreach vertex should make it quite accurate despite being low frequency.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And as for color representation, computing it is quite trivial (transforming image representing skymap scattering and normals into SH set) and I want it to be dynamic so it would be done every frame. These would be 9 coefficients because why not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in reconstruction step I would have two sets of coefficients: precomputed occlusion (4 coefficients) and real time color (9 coefficients for RGB so in sum 27 coefficients). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I (and how) multiply them (as in the picture below from &lt;a href=&quot;http://www.inf.ufrgs.br/~oliveira/pubs_files/Slomp_Oliveira_Patricio-Tutorial-PRT.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt;) so in the result I would get representation with occluded color filtered out?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oJomp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oJomp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-02-03T22:21:25.040" LastActivityDate="2017-03-07T11:59:01.533" Title="Multiplication of SH coefficient sets representing occlusion and color" Tags="&lt;lighting&gt;&lt;global-illumination&gt;&lt;spherical-harmonics&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4660" PostTypeId="1" CreationDate="2017-02-04T09:30:13.033" Score="0" ViewCount="611" Body="&lt;p&gt;I am working on a ray tracer. But i want to put more than 10 objects in the scene. How can i make the intersection fast so that it can give me reasonable FPS.&#xA;Its a cpu-based ray tracer.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastActivityDate="2017-02-04T17:37:22.263" Title="How can i make my ray tracing algorithm fast in terms of intersection testing?" Tags="&lt;raytracing&gt;&lt;shading&gt;&lt;ray&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4661" PostTypeId="2" ParentId="4660" CreationDate="2017-02-04T17:37:22.263" Score="4" Body="&lt;p&gt;You have several techniques.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Use acceleration structures. The idea is that you store your geometry (triangles) into generally some kind of volumes. The general idea behind acceleration structure is to discard quickly large parts of the scene, which we know (using these structure) don't have any object that your ray will intersect. An introduction to the topic can be found &lt;a href=&quot;https://www.scratchapixel.com/lessons/advanced-rendering/introduction-acceleration-structure&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;You can also take advantage of multi-threading and parallelism (threads and SSE instructions or similar - this is harder than 1. and the benefits are not always as high but you optimise for your hardware).&lt;/li&gt;&#xA;&lt;li&gt;You can ray-trace in the GPU but ray-tracing is a memory-bound problem so you will have memory problems quicker with the GPU than with CPU.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;These are just some ideas. &lt;/p&gt;&#xA;" OwnerUserId="1608" LastActivityDate="2017-02-04T17:37:22.263" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4662" PostTypeId="1" AcceptedAnswerId="4670" CreationDate="2017-02-04T20:45:00.333" Score="3" ViewCount="1759" Body="&lt;p&gt;So I've been messing with perspective projection matrices recently. I used numpy and GTK/Cairo to make a very small Python renderer. I'm very confused with the results I'm getting though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I took this Homogeneous Coordinates technique from an online lecture. If I understood correctly, the objective is to transform every point inside a &quot;Viewing Pyramid&quot; that's frustum shaped so they fit in a cube. (Image from of songho.ca)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;https://i.stack.imgur.com/AoWoV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AoWoV.png&quot; alt=&quot;Image courtesy of songho.ca&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You need a Field of View angle ($\alpha$), the Near and Far plane distances ($n$ and $f$ respectively), and the aspect ratio ($r$). Firstly you turn every 3D Point into a Homogeneous Point by adding  a 1 like so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{align*}&#xA;\begin{pmatrix}&#xA;  x &amp;amp; y &amp;amp; z&#xA;\end{pmatrix}&#xA;\xrightarrow{\text{4D}}&#xA;\begin{bmatrix}&#xA;  x &amp;amp; y &amp;amp; z &amp;amp; 1&#xA;\end{bmatrix}&#xA;\end{align*}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you multiply your point matrix by a perspective projection matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{align*}&#xA;\begin{bmatrix}x &amp;amp; y &amp;amp;z &amp;amp; 1 \end{bmatrix}&#xA;\begin{bmatrix}&#xA;  1\over\tan(\alpha/2) &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\ &#xA;  0 &amp;amp; r\over\tan(\alpha/2) &amp;amp; 0 &amp;amp; 0\\&#xA;  0 &amp;amp; 0 &amp;amp; (f+n)\over(f-n) &amp;amp; -1 \\&#xA;  0 &amp;amp; 0 &amp;amp; (2nf)\over(f-n) &amp;amp; 0&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;x' &amp;amp; y' &amp;amp; z' &amp;amp; w&#xA;\end{bmatrix}&#xA;\end{align*}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And to go back to a 3D point in space you divide by the fourth dimension:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{align*}&#xA;\begin{bmatrix}&#xA;  x' &amp;amp; y' &amp;amp; z' &amp;amp; w&#xA;\end{bmatrix}&#xA;\xrightarrow{\text{3D}}&#xA;\begin{pmatrix}&#xA;  x' \over w &amp;amp; y' \over w &amp;amp; z' \over w&#xA;\end{pmatrix}&#xA;\end{align*}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;br/&gt;&#xA;This is exactly what I've done with numpy:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def projection_matrix(fov, aspect, near, far):&#xA;    t = 1/math.tan(math.radians(fov)/2)&#xA;    a = (far + near)/(far - near)&#xA;    b = (2*near*far)/(far-near)&#xA;    r = aspect&#xA;&#xA;    return numpy.matrix([[t,   0,   0,   0],&#xA;                         [0, r*t,   0,   0],&#xA;                         [0,   0,   a,  -1],&#xA;                         [0,   0,   b,   0]])&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But for some reason the renderer is totally messed up. This is supposed to be a spinning cube... What am I missing here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href=&quot;https://i.stack.imgur.com/YSERI.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YSERI.gif&quot; alt=&quot;Messed up cube&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5998" LastActivityDate="2017-02-08T00:16:12.833" Title="My perspective projection is messed up?" Tags="&lt;rendering&gt;&lt;projections&gt;&lt;camera-matrix&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4663" PostTypeId="1" CreationDate="2017-02-04T21:59:09.617" Score="2" ViewCount="321" Body="&lt;p&gt;I have an idea of how to render opaque rasterized geometry alongside raycast volumes:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Render rasterized geometry to a depth map and also a render target&lt;/li&gt;&#xA;&lt;li&gt;When raycasting, check position against the depth map. When the ray penetrates the opaque geometry, alpha blend its color (from the render target) with the current color &quot;rolling sum&quot; of the ray, and stop raycasting&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This might even work for a single piece of transparent geometry (say a piece of glass in front of the raycast volume), but it will break down with multiple pieces of transparent geometry. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, imagine a red transparent quad in front of a raycast volume, and a green transparent quad behind the same volume. On the rasterized geometry pass, the render target will receive a yellow color (blend of the red and green of the quads). This yellow color will be alpha blended with every sample of the raycast volume, making it look as if the green quad was also in front of it. Ideally we would want to see a reddish volume with effectively no green. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How could I go about solving this?&lt;/p&gt;&#xA;" OwnerUserId="5999" LastActivityDate="2017-05-06T11:21:32.850" Title="Volumetric raycasting with transparent rasterized geometry" Tags="&lt;raytracing&gt;&lt;transparency&gt;&lt;volumetric&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4664" PostTypeId="1" AcceptedAnswerId="4665" CreationDate="2017-02-05T07:36:17.750" Score="12" ViewCount="4783" Body="&lt;p&gt;When converting from uniform hemisphere sampling to cosine weighted hemisphere sampling I am confused by a statement in an article.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My current indirect contribution is calculated as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3 RayDir = UniformGenerator.Next()&#xA;Color3 indirectDiffuse = Normal.dot(RayDir) * castRay(Origin, RayDir)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where the dot product is cos(θ)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in this article on better sampling (&lt;a href=&quot;http://www.rorydriscoll.com/2009/01/07/better-sampling/&quot;&gt;http://www.rorydriscoll.com/2009/01/07/better-sampling/&lt;/a&gt;) the author suggests the PDF is (cos(θ) / pi), and there is no evidence of the N dot L calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is - does that mean that I no longer need to perform the normal dot rayDirection because it is included in the PDF, or is it in addition to the pdf?&lt;/p&gt;&#xA;" OwnerUserId="6001" LastEditorUserId="2479" LastEditDate="2017-02-10T13:21:11.203" LastActivityDate="2017-02-10T13:21:11.203" Title="Does cosine weighted hemisphere sampling still require NdotL when calculating contribution for indirect light?" Tags="&lt;raytracing&gt;&lt;sampling&gt;&lt;monte-carlo&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4665" PostTypeId="2" ParentId="4664" CreationDate="2017-02-05T10:24:41.067" Score="12" Body="&lt;p&gt;You always need to multiply by the cosine term indeed (that's part of the rendering equation). Though when you do indirect diffuse using ray-tracing and thus monte-carol integration (which is the most common technique in this case), you have to &lt;strong&gt;divide&lt;/strong&gt; the contribution of each sample by your &lt;strong&gt;PDF&lt;/strong&gt;. This is well exampled &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing/global-illumination-path-tracing-practical-implementation&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note also that in the mentioned reference, if the PDF has terms that you also find in the rendering equations then you can optimise the code if you wish by cancelling out these terms.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Don't forget that the BRDF of a diffuse surface is ρ/π where ρ stands for the surface albedo. So we need to divide the result by π. Though in the case of the indirect diffuse component, don't forget that we should have divided the result of castRay by the PDF of the random variable, which as we showed earlier in this chapter is 1/(2π). Dividing indirectDiffuseby 1/(2π) mis the same as multiplying this value by 2π. And since the albedo is also divided by π we can simplify the code...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You have a similar situation. If you look at the PDF for the cosine sampling, then you will realise that terms can be cancelled out. Which doesn't mean they are 'not' strictly necessary. They are, they just cancel each other out which allows to optimize the code slightly (and avoid a few division, multiplication, etc.). You are more in the micro-optimisation here... which can be confusing if you try to learn the theory by just looking at optimised code (which is often not properly commented).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ \dfrac{(cos(\theta) ... )}{PDF} = \dfrac{(cos(\theta) ... )}{\dfrac{cos(\theta)}{\pi}} = ... $&lt;/p&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="1608" LastEditDate="2017-02-05T10:57:39.233" LastActivityDate="2017-02-05T10:57:39.233" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4666" PostTypeId="2" ParentId="4663" CreationDate="2017-02-05T10:27:08.100" Score="1" Body="&lt;p&gt;This is called &quot;&lt;a href=&quot;https://graphics.stanford.edu/papers/deepshadows/deepshad.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;deep shadow mapping&lt;/a&gt;&quot; and deep compositing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sadly invented long before you had this ideas yourself);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you are talking about implementing this idea specifically on a given architecture (GPU). It's up to you to make it work for this given architecture, and if you have technical difficulties with that maybe you can ask a question on this forum again.&lt;/p&gt;&#xA;" OwnerUserId="1608" LastActivityDate="2017-02-05T10:27:08.100" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4667" PostTypeId="2" ParentId="4659" CreationDate="2017-02-05T10:34:22.213" Score="0" Body="&lt;p&gt;I was overthinking it. The usual reconstruction for given direction and then multiplication will work fine probably.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2017-02-05T10:34:22.213" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4668" PostTypeId="1" CreationDate="2017-02-05T11:48:42.317" Score="3" ViewCount="5094" Body="&lt;p&gt;I'm familiar with the &quot;look-at&quot; matrix and the goal of being able to rotate a &lt;code&gt;Camera&lt;/code&gt; at a specific location towards a specified target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I tell the &lt;code&gt;Camera&lt;/code&gt; to look at some target, there're no issues. However, when some other non-&lt;code&gt;Camera&lt;/code&gt; object needs to &quot;look-at&quot; another object, such as a hypothetical &lt;code&gt;Dog&lt;/code&gt; looking at some &lt;code&gt;Food&lt;/code&gt;, so that the &lt;code&gt;Dog&lt;/code&gt; &quot;points&quot; in its direction, it doesn't work as expected. In this case, when the look-at matrix used for the &lt;code&gt;Camera&lt;/code&gt; is used (without modification) for the &lt;code&gt;Dog&lt;/code&gt;, the &lt;code&gt;Dog&lt;/code&gt; ends up looking in the &lt;em&gt;opposite&lt;/em&gt; direction I intended it to face.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What follows is the code I've been using to build my look-at matrix:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static Matrix4 createLookAtMatrix(&#xA;    Vector4 eyePosition,&#xA;    Vector4 targetPosition,&#xA;    Vector4 upDirection)&#xA;{&#xA;    // forward, side, up&#xA;    // &#xA;    // f = normalize(targetPosition - eyePosition);&#xA;    // s = normalize(f × normalize(upDirection));&#xA;    // u = s × f;&#xA;    Vector4 f = targetPosition.sub(eyePosition).normalize();&#xA;    Vector4 s = f.cross(upDirection.normalize()).normalize();&#xA;    Vector4 u = s.cross(f);&#xA;&#xA;    float[][] values = new float[][] {&#xA;        { s.x(),  s.y(),  s.z(), -s.dot(eyePosition) }, // row 0&#xA;        { u.x(),  u.y(),  u.z(), -u.dot(eyePosition) }, // row 1&#xA;        {-f.x(), -f.y(), -f.z(), -f.dot(eyePosition) }, // row 2&#xA;        { 0f   ,  0f   ,  0f   ,  1f                 }  // row 3&#xA;    };&#xA;&#xA;    return createFrom(values);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What am I missing? Is there a way to build such a &quot;look-at&quot; matrix so that it works for both regardless of who/what the viewer is (i.e. &lt;code&gt;Camera&lt;/code&gt; or &lt;code&gt;Dog&lt;/code&gt;)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to avoid depending on &quot;special corner cases&quot; to detect what kind of object is trying to &quot;look-at&quot; something else, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My system can have multiple &lt;code&gt;SceneObject&lt;/code&gt;s at any given moment connected to the same &lt;code&gt;SceneNode&lt;/code&gt; (&lt;code&gt;SceneNode&lt;/code&gt;s are the objects that actually contain the transforms) and I &lt;em&gt;really&lt;/em&gt; need a way to build a &quot;look-at&quot; matrix that will work regardless of which kind of object happens to get attached to the &lt;code&gt;SceneNode&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This is a screenshot of the reference book I was reading/using when writing my code above:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LV0gi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LV0gi.png&quot; alt=&quot;The Look-At Matrix&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6003" LastEditorUserId="6003" LastEditDate="2017-02-12T03:00:55.387" LastActivityDate="2018-05-04T23:48:44.257" Title="Correcting my &quot;look-at&quot; matrix so that it works on non-camera objects?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;transformations&gt;&lt;matrix&gt;&lt;camera-matrix&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4669" PostTypeId="2" ParentId="4668" CreationDate="2017-02-05T12:16:33.900" Score="1" Body="&lt;p&gt;You don't seem to get the concept right:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A &lt;a href=&quot;https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function&quot; rel=&quot;nofollow noreferrer&quot;&gt;look-at camera matrix&lt;/a&gt; is created by defining two points, the &quot;from&quot; point (the dog eyes for example assuming you take the position of the eyes of the dog and average them to get the point in between) and a &quot;to&quot; point which is where the dog looks at. So if your dog is at (3,3,3) and that you want it to look at the some food which is at (-10, 100, 20), then you need to call the lookAt() method with these 2 points and it will create a matrix that will actually orient and position the camera properly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you are getting confused (probably) because most cameras in most 3D packages are positioned at the origin (by default) and looking down the z-axis (by default). You can create such camera with a lookAt() function btw that would look like that:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;lookAt(Vec3f(0), Vec3f(0,0,-1));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For example. Now check what the matrix this call will produce with the matrix of the default camera in Maya. You will notice they are &lt;strong&gt;different&lt;/strong&gt;. The second is an identity matrix, the first one is not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now for example if you create a default camera in Maya it will be position at (0,0,0) and looking down the negative z-axis. If you look at the 4x4 matrix of this camera you will get identity. And maybe what you are trying to do is to create a 4x4matrix using the &lt;code&gt;lookAt&lt;/code&gt; function and multiply this matrix by the Maya's default camera matrix in which case, your camera will point in the wrong direction (it will be flipped along the camera's local coordinate z-axis). That's because the matrix returns by &lt;code&gt;lookAt&lt;/code&gt; properly orient the camera (as suggested in the first paragraph) but since the &lt;code&gt;default&lt;/code&gt; camera in Maya is already oriented along the negative-z axis, your Maya camera will look the wrong way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in summary:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If you use the &lt;code&gt;lookAt&lt;/code&gt; method in a renderer, it will work as you expect. There's no z problem.&lt;/li&gt;&#xA;&lt;li&gt;if you try to use it on a camera that is already oriented along the negative z-axis &lt;em&gt;and yet has identity matrix&lt;/em&gt; yes indeed you will be looking the wrong way. This can be fixed easily by flipping the camera back one more time along the z-axis. Simply create another matrix that scales the object/camera by (1,1,-1).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h1&gt;EDIT&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The OP says (see comment):&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I did spot what looks like a typo: it says &quot;(mind the direction of this vector: it is To − From not From − To)&quot;, but then you go on to write the line of code Vec3f forward = Normalize(from - to);, which contradicts what you were trying to clarify.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But a note in the reference says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The camera is aligned along the negative z-axis. Does it mean I need to rotate the camera by 180 degrees along the y-axis or scale it up by -1 along the z-axis? Not at all. Transforming a camera is no different from transforming any other object in a scene. Keep in mind that in ray-tracing, we build the primary rays as if the camera was located in its default position. This is explained in the lesson Ray Tracing: Generating Camera Rays. This is when we actually reverse the direction of the rays. In other words, the z-coordinates of the rays' directions at this point are always negative: the camera in its default position, looks down along the negative z-axis. Those primary rays are then transformed by the camera-to-world matrix. Therefore, there is no need to account for the default orientation of the camera when the 4x4 camera-to-world matrix is built.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So if you look at the reference they use by default a right-hand coordinate system, which means x-axis points to the right, y is up and z goes out of the screen (outward, going your direction when x-axis points to the right). So they build a matrix that &quot;follows this convention&quot; which makes sense. Then they say in the note &quot;yes but wait, normally the camera points down the negative z-axis, so you should be doing &lt;code&gt;to - from&lt;/code&gt; and not &lt;code&gt;from - to&lt;/code&gt;, and they explain that in the case of ray-tracing the fact that the camera looks down the z-axis is performed when the rays are cast (by inverting their z-coordinate).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3f rayDirectionInCamSpace{ x, y, -1 }; // invert here&#xA;normalize(rayDirectionInCamSpace);&#xA;Vec3f rayDirInWorldSpace = transform(rayDirectionInCamSpace, camToWorldMat);&#xA;pixelColor = trace(rayOrigWorldSpace, rayDirInWorldSpace);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So no it's not a typo. Now the reference you are pointing out maybe assume this matrix needs to be used in some OpenGL render in which there is no possibility to invert they ray direction when they cast. So they indeed use &lt;code&gt;to - from&lt;/code&gt; instead which is the same as multiplying the cam-to-world matrix you would get from the reference by a matrix that flips the coordinates z-axis (multiply by (1,1,1-)).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So no typo, things are quite logical in both cases. The result you get is always constrained to a lot of small details, such as the handiness of the coordinate system and how is the matrix later used down your graphics pipeline (OpenGL pipeline, ray-tracer, renderer, animation package, etc. which may follow its own conventions, etc.).&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;EDIT 2&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Note that in the reference your provide (screenshot of book) they do &lt;code&gt;target - eye&lt;/code&gt; but then they use the negative of that in the matrix construction. Not sure why. Then also no idea why the multiply the eye by the vectors for the translation part of the matrix. It seems to be using row-order matrices for the axis of the coordinate system but then the translation part should be at &lt;code&gt;mat[3][0]&lt;/code&gt;, &lt;code&gt;mat[3][1]&lt;/code&gt; and &lt;code&gt;mat[3][2]&lt;/code&gt; and not &lt;code&gt;mat[0][3]&lt;/code&gt;, &lt;code&gt;mat[1][3]&lt;/code&gt; and &lt;code&gt;mat[2][3]&lt;/code&gt;. Not sure what book this is but seems to be terribly wrong and confusing.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;EDIT 3&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Code (that seems to be the only solution):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void lookAt(const Vec3f&amp;amp; from, const Vec3f&amp;amp; to, Matrix44f &amp;amp;V)&#xA;{&#xA;    static const Vec3f tmp(0, 1, 0);&#xA;    Vec3f forward = normalize(from - to);&#xA;    Vec3f right = crossProduct(normalize(tmp), forward); &#xA;    Vec3f up = crossProduct(forward, right); &#xA;&#xA;    V[0][0] = right.x;&#xA;    V[0][1] = right.y;&#xA;    V[0][2] = right.z;&#xA;    V[1][0] = up.x;&#xA;    V[1][1] = up.y;&#xA;    V[1][2] = up.z;&#xA;    V[2][0] = forward.x;&#xA;    V[2][1] = forward.y;&#xA;    V[2][2] = forward.z;&#xA;&#xA;    V[3][0] = from.x;&#xA;    V[3][1] = from.y;&#xA;    V[3][2] = from.z;&#xA;}&#xA;&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    ...&#xA;    lookAt(from, to, camToWorldMatrix);&#xA;    worldToCamMatrix = camera.camToWorldMatrix.inverse();&#xA;&#xA;    Matrix44f projectionMatrix;&#xA;&#xA;    Matrix44f openGLWorldToCamMatrix = worldToCamMatrix;&#xA;    Matrix44f openGLProjectionMatrix = projectionMatrix;&#xA;&#xA;    while (!glfwWindowShouldClose(window)) {        &#xA;        glViewport(0, 0, width, height);&#xA;&#xA;        glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, (const GLfloat *)&amp;amp;openGLProjectionMatrix[0][0]);&#xA;        glUniformMatrix4fv(viewLocation, 1, GL_FALSE, (const GLfloat *)&amp;amp;openGLWorldToCamMatrix[0][0]);&#xA;&#xA;        ...            &#xA;        wwapBuffers(window);&#xA;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="1608" LastEditDate="2017-02-06T12:39:26.050" LastActivityDate="2017-02-06T12:39:26.050" CommentCount="18" ContentLicense="CC BY-SA 3.0" />
  <row Id="4670" PostTypeId="2" ParentId="4662" CreationDate="2017-02-05T12:26:53.187" Score="2" Body="&lt;p&gt;The math for the projection matrix is (with &lt;code&gt;fov&lt;/code&gt; as $\alpha$):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$q \leftarrow \frac{1}{tan(\frac{\alpha}{2})}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$a \leftarrow \frac{q}{aspect}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$b \leftarrow \frac{(far + near)}{(near - far)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$c \leftarrow \frac{(2 * far * near)}{(near - far)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Notice that there're some things you're doing that are differently, such as the order of your subtractions between &lt;code&gt;near&lt;/code&gt; and &lt;code&gt;far&lt;/code&gt;, how you organize the matrix values, and your multiplication between your &lt;code&gt;r * t&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the variables above, the column-major matrix below would be the resulting perspective projection matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{bmatrix}&#xA;  a &amp;amp; 0 &amp;amp;  0 &amp;amp; 0 \\&#xA;  0 &amp;amp; q &amp;amp;  0 &amp;amp; 0 \\&#xA;  0 &amp;amp; 0 &amp;amp;  b &amp;amp; c \\&#xA;  0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0&#xA;\end{bmatrix}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the above, we get:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def perspective_projection_matrix(fov, aspect, near, far):&#xA;    q = 1 / tan(radians(fov * 0.5))&#xA;    a = q / aspect&#xA;    b = (far + near) / (near - far)&#xA;    c = (2*near*far) / (near - far)&#xA;&#xA;    # construct column-major matrix here...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; I left the last part out because I'm not familiar enough with &lt;code&gt;numpy&lt;/code&gt; to know whether it expects row-major or column-major order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, you should validate all your arguments (e.g. both &lt;code&gt;near &amp;gt; 0&lt;/code&gt; and &lt;code&gt;far &amp;gt; 0&lt;/code&gt;, &lt;code&gt;far &amp;gt; near&lt;/code&gt;, etc.) if you want to avoid future headaches.&lt;/p&gt;&#xA;" OwnerUserId="6003" LastEditorUserId="6003" LastEditDate="2017-02-08T00:16:12.833" LastActivityDate="2017-02-08T00:16:12.833" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="4671" PostTypeId="2" ParentId="4662" CreationDate="2017-02-05T12:51:12.860" Score="2" Body="&lt;p&gt;Please read the &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;references&lt;/a&gt; that are given to you:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$S = \dfrac{1}{\tan(\dfrac{fov}{2}*\dfrac{\pi}{180})}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\left[\begin{array}{cccc}&#xA;S &amp;amp;&amp;amp; 0 &amp;amp;&amp;amp; 0 &amp;amp;&amp;amp; 0 \\&#xA;0 &amp;amp;&amp;amp; S &amp;amp;&amp;amp; 0 &amp;amp;&amp;amp; 0 \\&#xA;0 &amp;amp;&amp;amp; 0 &amp;amp;&amp;amp; -\dfrac{f}{(f-n)} &amp;amp;&amp;amp; -1\\&#xA;0 &amp;amp;&amp;amp; 0 &amp;amp;&amp;amp; -\dfrac{f*n}{(f-n)} &amp;amp;&amp;amp; 0\\&#xA;\end{array}\right]&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this reference they use row-major order matrices so your assumption that your matrix is column-major is wrong (to start with). Then you will need to check the code you use to multiply this matrix with points. All source code is provided on the reference, so you just need to &lt;strong&gt;read&lt;/strong&gt; and reproduce.&lt;/p&gt;&#xA;" OwnerUserId="1608" LastActivityDate="2017-02-05T12:51:12.860" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4673" PostTypeId="2" ParentId="4656" CreationDate="2017-02-06T16:41:25.357" Score="3" Body="&lt;p&gt;You're right, standard skinning pipelines don't produce correct normals. You get similar problems when using translation on joints, which is very common in facial animation. The only way to get a correct result is to take the average of the surrounding face normals - this is not information you will be able to get in the vertex shader, so you'll have to use a geometry shader or run your skinning on CPU or a compute shader. &lt;/p&gt;&#xA;" OwnerUserId="6011" LastActivityDate="2017-02-06T16:41:25.357" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4675" PostTypeId="1" AcceptedAnswerId="4678" CreationDate="2017-02-06T21:02:46.383" Score="1" ViewCount="1395" Body="&lt;p&gt;In order to reduce the amount of draw calls per frame I've decided to use a vertex array object to store vertex data from several different meshes. More precisely, I use the vao to the define the vertex format (attributes) and the buffers which contain the vertex and index data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I could call glDrawElements on the batch's vao once and draw all the stored vertex data directly. But I also see a lot of discussions about sorting your draw data front-to-back for opaque objects (in order to reduce overdraw) and back-to-front for translucent objects (in order to blend 'correctly'). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering how you would go about sorting the contents of several vertex batches (vaos) even though a batch most likely contains data for objects at different distances from the camera. &#xA;Say batch &lt;strong&gt;A&lt;/strong&gt; contains objects with depth { 1, 3, 5 } and batch &lt;strong&gt;B&lt;/strong&gt; contains objects with depth { 2, 4 }, how could this be sorted properly so that it can be drawn in the order { 1, 2, 3, 4, 5 } without specifying 5 separate draw calls (with each a different buffer offset).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Were it just the overdraw &lt;em&gt;optimization&lt;/em&gt; I would probably just say &lt;em&gt;screw it&lt;/em&gt; as it would allow me to draw an entire buffer's contents in one go (instead of having a draw call with a different offset for each object), but then there's still the sorting of translucent objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="5960" LastActivityDate="2017-02-07T03:12:49.807" Title="Can you batch vertex data and still sort by depth?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;c++&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4676" PostTypeId="1" CreationDate="2017-02-07T02:55:16.393" Score="2" ViewCount="531" Body="&lt;p&gt;I am making an iOS game using Unity. I am testing some shaders that I have made for the game, and in some cases the device will run at under 30 FPS but not have 100% device utilization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sometimes a test will start at a higher device utilization %, and then over time go lower, even though the test is simply rendering a plane with a material on it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, a shader test I just ran on an iPad 4: Device utilization 85% Renderer utilization 85% Tiler utilization 1% Core Animation Frames Per Second 12&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This test is using barely any CPU, and is only rendering 4 triangles (2 big planes covering the screen).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone have any ideas why this could be happening? Usually the renderer utilization goes up to 100%... pretty stumped, being a graphics rookie.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;IOS has mandatory v-sync. I am curious why the &quot;Core Animation Frames Per Second&quot; in the Instruments profiler would say 12 FPS if v-sync is enabled, and how that would correspond to the 85% device utilization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perhaps the device is rendering 12 frames, and 2 are dropped to get it down to the v-synced frame rate of 10? That would result in ~83-84% effective device utilization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or perhaps it is that given the above stats (85% utilization and 12 FPS), the GPU could render 14 FPS if at 100% usage. However v-sync requires either 10, or 15 FPS, nothing in between. This may result in the GPU slowing down, to not waste power and CPU, but still remain safely above the next step down on v-sync.&lt;/p&gt;&#xA;" OwnerUserId="6015" LastEditorUserId="231" LastEditDate="2017-02-19T21:28:53.673" LastActivityDate="2017-02-19T21:28:53.673" Title="GPU not reaching 100% usage when frame rate is dropping" Tags="&lt;shader&gt;&lt;performance&gt;&lt;unity&gt;&lt;mobile&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4677" PostTypeId="2" ParentId="4675" CreationDate="2017-02-07T03:01:01.057" Score="0" Body="&lt;p&gt;Drawing back-to-front is &lt;em&gt;not optional&lt;/em&gt; with blending (unless you use an order-independent blending technique), so getting the visual effect you actually want has to trump performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But drawing front-to-back is purely a performance thing. Specifically, it makes it possible for early-Z to save you fragment processing time, as earlier objects are in front of later ones. So it's a GPU performance improvement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Batching is a performance improvement for the &lt;em&gt;CPU&lt;/em&gt;, in that you're spending less CPU time doing state change stuff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you need to decide which is more important: CPU performance or GPU performance. With deferred rendering, saving FS computation time also means saving memory bandwidth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But the general construction of your scene, what you're actually drawing, can help inform which is more important.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Oftentimes what happens is that you render static terrain first, perhaps using your visibility system to order what you render coarsely front-to-back. Then you render your dynamic objects. Because dynamic objects usually require a lot of state changes, you won't necessarily draw all of them in a single batch (though there are techniques you can use to hide even texture changes).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, the point is that there is a tradeoff. And the one you pick depends on exactly what you're rendering. A top-down game like StarCraft or DotA would never bother with front-to-back sorting; you just render the terrain after the characters. A tight-quarters FPS by contrast would probably really need to employ such techniques, particularly for terrain.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-02-07T03:01:01.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4678" PostTypeId="2" ParentId="4675" CreationDate="2017-02-07T03:12:49.807" Score="0" Body="&lt;p&gt;Yes, but with tradeoffs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that there are two optimizations going on here at different potential bottlenecks, the CPU and the GPU.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Reducing Overdraw&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The goal of reducing overdraw primarily is to reduce the number of times the fragment shader runs via early-z discard. This is usually desirable when you have expensive fragment shaders. However, maintaining a strict depth ordering here may not be necessary. A few common techniques are to either use deferred rendering or to use a depth pre-pass (particularly if you have a forward renderer variant) to minimize the time it takes to run the fragment shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The depth pre-pass technique will require double the draw calls and double the execution of the rest of the shader types (vertex, tessellation control, tessellation evaluation, and geometry) twice, but it may be worth it depending on the scene. The fragment shader is executed twice as well, but usually you would use a very simple one for the pre-pass.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Preserving Transparency&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Transparency of course is a different story. Many applications avoided transparency because of two problems:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Objects blending in order&lt;/li&gt;&#xA;&lt;li&gt;Fragments blending in order&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Even if you are able to sort each object by depth at the VBO or VAO level, it's still not guaranteed to be accurate. For example, two objects could overlap each other. Even within the same object, two triangles can overlap each other, so unless you perform clipping, the transparency order may not be correct. You can sort by the fragment level. There are various order-independent transparency techniques, ranging from screen-door transparency to more accurate variants such as depth-peeling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you are concerned about draw calls and want accurate transparency, then there are techniques that are single-pass order-independent transparency that are becoming more popular. These rely on saving fragment shader output values in additional buffers (generally called A-buffers) and sorting through them later, performing blending manually. These single-pass techniques requires shader atomics though, so OpenGL 4.2 is required.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2017-02-07T03:12:49.807" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4680" PostTypeId="2" ParentId="4650" CreationDate="2017-02-07T06:55:00.263" Score="2" Body="&lt;p&gt;You should look into &lt;a href=&quot;https://en.wikipedia.org/wiki/Medial_axis&quot; rel=&quot;nofollow noreferrer&quot;&gt;Medial Axis Transform&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Straight_skeleton&quot; rel=&quot;nofollow noreferrer&quot;&gt;Straight Skeletons&lt;/a&gt;. They are often used to generate the information you need to bevel things properly. They give you a distance from the bounds of your object at any point in space, which allows you to generate bevels correctly. They are difficult to calculate, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may also want to look into &lt;a href=&quot;http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; from Valve Software for an alternative way to generate the distance field.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-02-07T06:55:00.263" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4682" PostTypeId="1" CreationDate="2017-02-08T03:07:14.083" Score="4" ViewCount="553" Body="&lt;p&gt;I wrote a small python script with recursion to create a &quot;lattice&quot; of non-overlapping pentagons. Below one can see the first stages of recursion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WIGNE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WIGNE.png&quot; alt=&quot;first recursion&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1uVtg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1uVtg.png&quot; alt=&quot;second recursion&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QQscK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QQscK.png&quot; alt=&quot;third recursion&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One can see that 5 small pentagons are missing in the second stage of recursion. The code in python to generate these figures is this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;# fill the plane with pentagons as tightly as possible in a regular way&#xA;#!/usr/bin/python&#xA;import numpy as np&#xA;import matplotlib.pyplot as plt&#xA;N = 5&#xA;phi = (1.0+np.sqrt(5.0))/2&#xA;def pentagon (X, Y, n):&#xA;    if n == 0:&#xA;        rx = np.append(X, X[0])&#xA;        ry = np.append(Y, Y[0])&#xA;        plt.plot(rx, ry, 'r-')&#xA;        return&#xA;    for i in range(N):&#xA;        Xn = np.array([X[i], X[i], X[i], X[i], X[i]])&#xA;        Yn = np.array([Y[i], Y[i], Y[i], Y[i], Y[i]])&#xA;    U = Xn/phi+X*(1-1.0/phi)&#xA;    V = Yn/phi+Y*(1-1.0/phi)&#xA;    pentagon (U, V, n-1)&#xA;Xn = X/phi +np.roll(X, 2)*(1-1.0/phi)&#xA;Yn = Y/phi +np.roll(Y, 2)*(1-1.0/phi)&#xA;# center pentagon&#xA;pentagon (Xn, Yn, n-1)&#xA;Ind = np.arange(N)&#xA;theta =np.pi/10&#xA;X = np.cos(Ind*2*np.pi/N+theta)&#xA;Y = np.sin(Ind*2*np.pi/N+theta)&#xA;plt.figure()&#xA;plt.axes().set_aspect('equal')&#xA;n_iter = 2 # number of iterations&#xA;pentagon (X, Y, n_iter)&#xA;figure = &quot;pentagons%d.png&quot; % n_iter&#xA;plt.axis('off')&#xA;plt.savefig(figure)&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any suggestions on how to fill in the missing pentagons in a simple way (e.g. keeping the recursive nature of the algorithm)? &lt;/p&gt;&#xA;" OwnerUserId="6023" LastEditorUserId="6023" LastEditDate="2017-04-11T20:37:08.920" LastActivityDate="2017-04-11T20:37:08.920" Title="Fill the plane with pentagons as tightly as possible in a regular way" Tags="&lt;computational-geometry&gt;" AnswerCount="3" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4683" PostTypeId="2" ParentId="4682" CreationDate="2017-02-08T04:53:45.517" Score="1" Body="&lt;p&gt;If you're trying to tile the plane with regular pentagons with no spacing, &lt;a href=&quot;https://en.wikipedia.org/wiki/Pentagonal_tiling&quot; rel=&quot;nofollow noreferrer&quot;&gt;that's not possible.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A regular pentagonal tiling on the Euclidean plane is impossible because the internal angle of a regular pentagon, 108°, is not a divisor of 360°, the angle measure of a whole turn.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;From the same link, though, there are several non-regular pentagons you can use to tile it as shown in the above link. Additionally, you can do a &lt;a href=&quot;https://en.wikipedia.org/wiki/Pentagonal_tiling#Pentagonal.2Fhexagonal_tessellation&quot; rel=&quot;nofollow noreferrer&quot;&gt;pentagonal/hexagonal tiling&lt;/a&gt; of the plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I've misunderstood what you're trying to do, please clarify.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-02-08T04:53:45.517" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4684" PostTypeId="1" CreationDate="2017-02-08T13:33:28.823" Score="4" ViewCount="6049" Body="&lt;p&gt;I'm new to computer graphics.  I played around with OpenGL and now am trying out Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically what I want to do, in 2D is have an 800x800 window, and I want that to represent 800 meters by 800 meters.  Then I want a circle with a radius of 1 meter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am going off of the Vulkan tutorial.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My data structure is this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex {&#xA;    glm::vec2 pos;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I create my circle:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const int NUM_POINTS = 20;&#xA;uint32_t angle = 360/NUM_POINTS;&#xA;Vertex vertex;&#xA;std::vector&amp;lt;Vertex&amp;gt; vertices;&#xA;&#xA;for(uint32_t i=0; i &amp;lt;= 360; i+=angle){&#xA;  vertex.pos.x = cos(glm::radians(float(i)));&#xA;  vertex.pos.y = sin(glm::radians(float(i)));&#xA;  vertices.push_back(vertex);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Something to do with the viewport:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;VkViewport viewport = {};&#xA;viewport.x = 0.0f;&#xA;viewport.y = 0.0f;&#xA;viewport.width = (float) swapChainExtent.width;&#xA;viewport.height = (float) swapChainExtent.height;&#xA;viewport.minDepth = 0.0f;&#xA;viewport.maxDepth = 1.0f;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;viewport.width and viewport.height both equal 800.0f.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Projection matrices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct UniformBufferObject{&#xA;  glm::mat4 model;&#xA;  glm::mat4 view;&#xA;  glm::mat4 proj;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;projections:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ubo.view = glm::lookAt(glm::vec3(2.0f, 2.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));&#xA;ubo.proj = glm::perspective(glm::radians(45.0f), swapChainExtent.width / (float) swapChainExtent.height, 0.1f, 10.0f);&#xA;ubo.proj[1][1] *= -1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This shows the circle, but it's almost as big as the window and it's tilted 45° away from me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all, I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing.  I mean the circle is in the x-y plane.  If I move in the z-direction, shouldn't I see it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I tried glu::ortho&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ubo.proj = glm::ortho(0.0f, 800.0f, 800.0f, 0.0f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But I still see nothing.&lt;/p&gt;&#xA;" OwnerUserId="6025" LastActivityDate="2017-03-10T17:15:11.177" Title="understanding glm::perspective vs glm::ortho" Tags="&lt;projections&gt;&lt;vulkan&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4685" PostTypeId="2" ParentId="4684" CreationDate="2017-02-08T16:47:44.643" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I don't understand why, if I make the first argument to glm::lookAt be glm::vec3(0.0f, 0.0f, 2.0f), I see nothing.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's because of the &lt;em&gt;up&lt;/em&gt; vector. If you think about the look-at operation, you specify where the camera is and what point it's looking towards. These two things alone leave one degree of freedom: the rotation around that axis. Which way is up on your screen? The third argument is for specifying that: it's a direction in world space which will correspond to &lt;em&gt;up&lt;/em&gt; on the screen. If your first argument is that and the rest of the code is as your example, you're calling &lt;code&gt;lookAt((0,0,2), (0,0,0), (0,0,1))&lt;/code&gt;. Your up vector points along the $z$-axis, which is the same direction the camera is looking (well, the opposite direction. This can't define which way is &lt;em&gt;up&lt;/em&gt; on the screen. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You probably want to pass a vector &lt;code&gt;(0,1,0)&lt;/code&gt; as the third argument, which will make $y$ point up on your screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're making a plan view of a 3D scene, then perspective projection is probably the right answer, but if all your content is going to be in the $z=0$ plane, then you probably want to use an orthographic rather than a perspective projection. Look at &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2383/whats-the-difference-between-orthographic-and-perspective-projection&quot;&gt;What&amp;#39;s the difference between orthographic and perspective projection?&lt;/a&gt; to learn more about that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Last of all, remember that if you're projecting an $800m \times 800m$ scene onto $800 \times 800$ pixels, then a $1m$ radius circle will only be one pixel large. You probably need to scale up the size of your circle.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-02-08T16:47:44.643" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4686" PostTypeId="1" AcceptedAnswerId="4687" CreationDate="2017-02-08T20:36:37.163" Score="6" ViewCount="4978" Body="&lt;p&gt;I want to recreate this smoke/cloud effect which is used in the Arrival (2016) movie end credits.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I uploaded a sped up version of the credits to see the smoke dynamics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://streamable.com/n3309&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9eaAH.jpg&quot; alt=&quot;thumbnail&quot;&gt;&#xA;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;&lt;a href=&quot;http://streamable.com/n3309&quot; rel=&quot;noreferrer&quot;&gt;http://streamable.com/n3309&lt;/a&gt; 49s x6 sped up video of the credits&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know how shaders work and can comfortably implement simple GLSL fragment shaders, but looking at this I can't seem to find a way to get started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Starting points I considered:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Using a noise function:&lt;/em&gt; Every noise function I could find looks unnatural and unsmooth. Not what I need.&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Creating 2D/3D particle simulation:&lt;/em&gt; This seems a bit overkill and even then I need functions that do not look calculated.&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Just use some sprites and transform them randomly around:&lt;/em&gt; That's lame and still looks 'fake'.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If you could guide me to a starting point on how to accomplish a somewhat similar looking GLSL shader implementation that would be great!&lt;/p&gt;&#xA;" OwnerUserId="6028" LastActivityDate="2017-05-02T15:40:07.213" Title="Advice on how to create GLSL 2D soft smoke/cloud shader" Tags="&lt;shader&gt;&lt;pixel-shader&gt;&lt;fragment-shader&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4687" PostTypeId="2" ParentId="4686" CreationDate="2017-02-08T23:45:46.797" Score="5" Body="&lt;p&gt;Noise functions are definitely your friend here—&lt;a href=&quot;https://code.google.com/archive/p/fractalterraingeneration/wikis/Fractional_Brownian_Motion.wiki&quot; rel=&quot;nofollow noreferrer&quot;&gt;FBM&lt;/a&gt; would be one good candidate. You’re right that it can look too uniform on its own, but if you blend multiple layers of it together, using different speeds / directions for each and maybe distorting their domains a bit, you should be able to get very close to the look of that footage. There’s lots of clever uses of noise functions on &lt;a href=&quot;https://www.shadertoy.com/results?query=tag=noise&amp;amp;sort=popular&quot; rel=&quot;nofollow noreferrer&quot;&gt;Shadertoy&lt;/a&gt;; for an example of something like the approach described above, check out &lt;a href=&quot;https://www.shadertoy.com/view/Mtd3W7&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2017-05-02T15:40:07.213" LastActivityDate="2017-05-02T15:40:07.213" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4688" PostTypeId="1" AcceptedAnswerId="4693" CreationDate="2017-02-09T05:26:50.003" Score="3" ViewCount="975" Body="&lt;p&gt;I have had luck with cosine weighted hemisphere samples, and I know how to generate stratified uniform samples, but I wanted to experiment with combining the two. However, how do I correctly stratify the hemisphere when performing the cosine weighted sampling? Do I cosine-weight the stratification? How many rays do I cast in each stratum? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My application is the collection of indirect samples in a lightmapper.&lt;/p&gt;&#xA;" OwnerUserId="6001" LastEditorUserId="6001" LastEditDate="2017-02-09T05:53:24.547" LastActivityDate="2017-02-09T23:03:16.517" Title="Generation of stratified cosine weighted samples on hemisphere" Tags="&lt;raytracing&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;&lt;importance-sampling&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4689" PostTypeId="1" CreationDate="2017-02-09T09:39:17.250" Score="1" ViewCount="96" Body="&lt;p&gt;So I have a matrix:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Matrix4f Mbsp = Matrix4f(Vector4f(1.0, 4.0, 1.0, 0.0)&#xA;            , Vector4f(-3.0, 0.0, 3.0, 0.0)&#xA;            , Vector4f(3.0, -6.0, 3.0, 0.0)&#xA;            , Vector4f(-1.0, 3.0, -3.0, 1.0), true);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and I'm doing a scalar multiplication to it, e.g.:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Mbsp = (1.0/6.0)*Mbsp;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;One would now expect Mbsp to be&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{array} &amp;amp;1/6&amp;amp;-1/2&amp;amp;1/2&amp;amp;-1/6\\2/3&amp;amp;0&amp;amp;-1&amp;amp;1/2\\1/6&amp;amp;1/2&amp;amp;1/2&amp;amp;-1/2\\ 0&amp;amp;0&amp;amp;0&amp;amp;1/6 \end{array}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However Mbsp now is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{array} &amp;amp;1.0&amp;amp;1.4901161e-008&amp;amp;1.4901161e-008&amp;amp;0\\1.0&amp;amp;1.4901161e-008&amp;amp;1.4901161e-008&amp;amp;0\\1.0&amp;amp;1.4901161e-008&amp;amp;1.4901161e-008&amp;amp;0&amp;amp;\\ 1.0&amp;amp;1.4901161e-008&amp;amp;1.4901161e-008&amp;amp;0 \end{array}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, doing (using the original Mbsp): &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Mbsp = 2.0*Mbsp;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Gives&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{array} &amp;amp;12&amp;amp;0&amp;amp;0&amp;amp;0\\12&amp;amp;0&amp;amp;0&amp;amp;0\\12&amp;amp;0&amp;amp;0&amp;amp;0\\ 12&amp;amp;0&amp;amp;0&amp;amp;0 \end{array}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's wrong?&lt;/p&gt;&#xA;" OwnerUserId="6029" LastEditorUserId="6029" LastEditDate="2017-02-09T11:06:13.280" LastActivityDate="2017-02-09T11:06:13.280" Title="Scalar multiplication in vecmath on Matrix4f results in strange values" Tags="&lt;opengl&gt;&lt;bezier-curve&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4690" PostTypeId="1" AcceptedAnswerId="4694" CreationDate="2017-02-09T11:14:46.130" Score="1" ViewCount="237" Body="&lt;p&gt;I read the &lt;a href=&quot;http://paulbourke.net/dataformats/mtl/&quot; rel=&quot;nofollow noreferrer&quot;&gt;MTL&lt;/a&gt; specification for materials and noticed that the specular exponent &lt;strong&gt;Ns&lt;/strong&gt; must be a scalar value instead of a spectrum. Would a specular exponent with three color channels (i.e. RGB, XYZ, ...) make sense (i.e. could &lt;em&gt;represent&lt;/em&gt; (the specular exponent is of course not physically based at all) something &lt;em&gt;physically plausible&lt;/em&gt;)?&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-02-09T11:22:39.530" LastActivityDate="2017-02-09T15:35:00.203" Title="Specular exponent spectrum" Tags="&lt;shading&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4691" PostTypeId="2" ParentId="4688" CreationDate="2017-02-09T12:50:50.153" Score="4" Body="&lt;p&gt;The classic method is to uniformly sample the disc at the base of your hemisphere and to project your samples upwards on the hemisphere (eg. compute z from x and y). This yields a cosine weighted distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the projection preserves stratification, you need only use stratified sampling of the disc to get a stratified cosine distribution.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2017-02-09T13:55:36.607" LastActivityDate="2017-02-09T13:55:36.607" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4692" PostTypeId="1" CreationDate="2017-02-09T13:05:42.390" Score="1" ViewCount="175" Body="&lt;p&gt;in OpenCV there is functions to warp any 2D image using a homography matrix (3x3), e.g. &lt;code&gt;cv2.warpPerspective&lt;/code&gt;. These matrices are generally constructed using point correspondences 2D-&gt;2D and solving for the matrix that maps the first set of points to the second, e.g. using &lt;code&gt;cv2.findHomography&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I'm wondering what the rotations and translations of the camera are, that lead to a homography. So if I rotate and translate the (virtual) camera (6 degrees of freedom) by given values - what does the matrix look like to project a 2D image to the version seen by the rotated and translated camera. I somehow feel that this can't be solved in 2D but I can't really tell why.&lt;/p&gt;&#xA;" OwnerUserId="6030" LastActivityDate="2017-02-09T13:05:42.390" Title="image warping, given the rotations/translations" Tags="&lt;image-processing&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4693" PostTypeId="2" ParentId="4688" CreationDate="2017-02-09T15:15:01.967" Score="2" Body="&lt;p&gt;If you have a deterministic mapping function which transforms uniformly distributed samples into the desired PDF (cosine shaped in your case), just feed it directly with stratified uniformly distributed samples. The mapping will keep the strata separated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually one sample per stratum is used and the number of strata is set according to the total amount of needed samples per one Monte Carlo estimation. More samples per stratum will somehow work too, you just need to make sure that each stratum gets the same amount of samples not to break uniformity of the (input) distribution. Keep in mind, however, that using more samples per stratum will degrade the per-sample performance of the Monte Carlo estimator due to sample clustering which usually happen for simple non-stratified random sampling.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2017-02-09T23:03:16.517" LastActivityDate="2017-02-09T23:03:16.517" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4694" PostTypeId="2" ParentId="4690" CreationDate="2017-02-09T15:35:00.203" Score="2" Body="&lt;p&gt;Using independent settings for each colour channel is like using settings dependent on wavelength when doing spectral rendering. So the question could be re-formulated as:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is a material which changes its roughness with wavelengths physically plausible?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;With some kind of nano-fabrication process you could build a material surface using some microfacets reflecting certain parts of spectrum and distributing each type of microfacets in a different way. So not only it is physically plausible, but it is also physically realisable. On the other hand, you normally don't encounter such behaviour in &quot;common&quot; materials.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastActivityDate="2017-02-09T15:35:00.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4696" PostTypeId="2" ParentId="4686" CreationDate="2017-02-09T16:31:17.233" Score="4" Body="&lt;p&gt;There is good glsl source of noise (simplex noise) &lt;a href=&quot;https://github.com/ashima/webgl-noise/tree/master/src&quot; rel=&quot;nofollow noreferrer&quot;&gt;online&lt;/a&gt; to make real time noise. In addition to this, to make effect of moving fog/smoke like in this video you can make 3D FBM function. This is my function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float default3DFbm(vec3 P, float frequency, float lacunarity, int octaves, float addition)&#xA;{&#xA;    float t = 0.0f;&#xA;    float amplitude = 1.0;&#xA;    float amplitudeSum = 0.0;&#xA;    for(int k = 0; k &amp;lt; octaves; ++k)&#xA;    {&#xA;        t += min(snoise(P * frequency)+addition, 1.0) * amplitude;&#xA;        amplitudeSum += amplitude;&#xA;        amplitude *= 0.5;&#xA;        frequency *= lacunarity;&#xA;    }&#xA;    return t/amplitudeSum;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;snoise&lt;/code&gt; is 3D noise function from link and &lt;code&gt;P&lt;/code&gt; is used to seed noise, for example&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;P = vec3(texcoord, uniform_speed)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;uniform_speed&lt;/code&gt; is uniform variable incremented each frame with some value.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2017-02-09T16:31:17.233" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4698" PostTypeId="1" CreationDate="2017-02-09T23:49:34.187" Score="7" ViewCount="1410" Body="&lt;p&gt;I'm attempting to apply a height map to a ray-traced sphere. The height map is stored as a texture. I have the intersection point on the sphere $p$, and I compute the normal vector at that point $N = normalize(p - c)$, where $c$ is the center of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I then use the components of the normalized $N$ with a sqrt and a couple of atan2's to get texture coordinates $u$ and $v$ (which correspond to sphere longitude and latitude, respectively.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, I can't quite see how to get a perturbed normal from the height map. Here's what I have so far:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p^{'} = p + h(u,v) N$ is the sphere perturbed by the height map $h$ in the direction of the normalized normal $N$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The perturbed normal is then, by definition, $N^{'} = p^{'}_u \times p^{'}_v$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first question I have is, how do I know that normal points to the outside of the sphere? (To light the sphere properly, I do need outward-pointing normals.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that, at worst, I can just run the shader and change the sign if it looks wrong, but I'd like to understand from first principles how I should order the cross product. I've looked around, and could not find any discussion of this point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we can define the sphere as $p = c + N r$ with $c$ the center and $r$ the scalar radius. Substituting this into the perturbed height map equation, we get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p^{'} = c + N(r + h)$, which makes perfect sense: the radius is being perturbed by the height.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Differentiating that, we get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p^{'}_u = N_u(r+h) + h_uN$ and $p^{'}_v = N_v(r+h) + h_vN$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Computing the cross product directly, we get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N^{'} = (N_u(r+h) + h_uN) \times (N_v(r+h) + h_vN)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N^{'} = (r+h)^2(N_u \times N_v) + (r+h)(h_u(N \times N_v) + h_v(N_u \times N))$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N^{'} = (r+h)(N_u \times N_v) + h_u(N \times N_v) + h_v(N_u \times N)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N^{'} = (r+h)N + h_u(N \times N_v) + h_v(N_u \times N)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(because $N \times N = 0$, the common factor $(r+h)$ will drop out from the normalized vector, and $N = N_u \times N_v$.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next question I have is that the sphere longitude is discontinuous ($u$ jumps from 1 to 0 as you cross the meridian); won't that cause the cross product to be computed incorrectly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The final problem is, I'm not seeing how to compute $N(u,v)$. I'm just hitting a blank here. ($h_u$ and $h_v$ are easy enough to compute; they're just the derivative of the texture.)&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Boy do I feel stupid. I just use spherical to cartesian to get a point on the sphere as a function of $u$ and $v$. And that is precisely the function $N(u,v)$. D'oh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I still have my first question pending, and I'll see if there are any problems with singularities after I compute the derivative of $N$ (I suspect there will be no issues.)&lt;/p&gt;&#xA;" OwnerUserId="6033" LastEditorUserId="2479" LastEditDate="2017-03-16T13:22:15.900" LastActivityDate="2017-03-16T13:22:15.900" Title="Bump mapping a ray-traced sphere" Tags="&lt;raytracing&gt;&lt;computational-geometry&gt;&lt;normal-mapping&gt;&lt;height-field&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4699" PostTypeId="1" AcceptedAnswerId="4732" CreationDate="2017-02-10T01:46:04.253" Score="3" ViewCount="324" Body="&lt;p&gt;I have a working light mapper that captures global illumination. I evaluate a hemisphere when collecting the data and store the result in the texel. However, I want to support directional lightmaps so that I can more realistically light normal maps at runtime. What strategies are there to adapt my light mapper's final gather operation to capture this data? Is it as simple as performing three hemisphere samples per texel in orthogonal directions? Or should I uniformly sample the hemisphere once, and project the results onto the basis vectors? Or do I sample the hemisphere and project each sample on to the basis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've done some tests with the latter - projecting the each sample on the hemisphere onto the three basis vectors - and this works mostly, but I'm not sure about whether the projected samples should be clamped when their dot product is facing away from the basis or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When reading all of Valve's HL2 Radiosity Normal Mapping articles, the need to generate three lightmaps for the bases vectors is clear, as are the coordinates for the bases vectors, as is the reconstruction in a shader of the data - this is straight forward enough. See &lt;a href=&quot;http://www.valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Valve SIGGRAPH06&lt;/a&gt;, &lt;a href=&quot;http://www.valvesoftware.com/publications/2004/GDC2004_Half-Life2_Shading.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Valve Tutorial&lt;/a&gt; and &lt;a href=&quot;http://www.decew.net/OSS/References/sem_ss06_07-Independant%20Explanation.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Peter Houska on Directional Lightmaps&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The complication comes from &lt;em&gt;how&lt;/em&gt; to generate those three samples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example - from a Valve GDC talk:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;• Traditionally, when computing light map values using a radiosity&#xA;  preprocessor, a single color value is calculated&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;• In Radiosity Normal&#xA;  Mapping, we transform our basis into tangent space and compute light&#xA;  values for each vector&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Given that I am currently sampling on a hemisphere, do I simply project each sample onto the bases and store those accumulations? If I do that, how do I handle the fact that data within my original hemisphere, when projected onto the bases, could create a projection that actually &lt;em&gt;subtracts&lt;/em&gt; energy, given that a sample ray pointing away from the bases gives a negative dot product.&lt;/p&gt;&#xA;" OwnerUserId="6001" LastEditorUserId="6001" LastEditDate="2017-02-15T17:28:53.027" LastActivityDate="2017-02-16T21:03:22.210" Title="How to adapt diffuse/GI light mapper to directional light maps?" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;radiosity&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4700" PostTypeId="2" ParentId="1681" CreationDate="2017-02-10T15:40:13.627" Score="2" Body="&lt;p&gt;The technic what Benedikt mentioned&#xA;is explained in Section 2.4.1 of this thesis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://fileadmin.cs.lth.se/graphics/theses/projects/projgrid/projgrid-lq.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://fileadmin.cs.lth.se/graphics/theses/projects/projgrid/projgrid-lq.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Implementing this should solve your problem.&lt;/p&gt;&#xA;" OwnerUserId="6040" LastEditorUserId="6040" LastEditDate="2017-02-25T13:49:26.930" LastActivityDate="2017-02-25T13:49:26.930" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4701" PostTypeId="1" AcceptedAnswerId="4704" CreationDate="2017-02-10T16:15:16.373" Score="3" ViewCount="529" Body="&lt;p&gt;How is sun modelled for ray tracing rendering? Is it part of the scene, like a&#xA;sphere with a centre in some far location or it is just considered as a point?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also regarding sending shadow rays to the sun, is it, again, sampling a sphere&#xA;or just sending shadow rays to one point?&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="231" LastEditDate="2017-02-11T20:34:29.563" LastActivityDate="2017-02-11T23:30:45.983" Title="Sending shadow rays to the sun" Tags="&lt;raytracing&gt;&lt;shadow&gt;&lt;ray&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4702" PostTypeId="2" ParentId="4701" CreationDate="2017-02-10T17:16:32.643" Score="3" Body="&lt;p&gt;Sunlight is typically modeled as a directional light. All rays point the same direction off into infinity. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-02-10T17:16:32.643" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4703" PostTypeId="1" CreationDate="2017-02-11T08:20:36.757" Score="2" ViewCount="326" Body="&lt;p&gt;I have a 3D triangular mesh representing cortical surface of a brain. I also have one vertex of interest. I would like to unfold a neighborhood of this vertex in such a way that both the angles (their ratios) and distances of paths from this vertex are preserved as much as possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read some reviews on mesh parameterization techniques (eg. &lt;a href=&quot;http://people.eecs.berkeley.edu/~jrs/meshpapers/ShefferPraunRose.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; one by Scheffer et al.). My understanding is that all the algorithms try to preserve a certain property (angle, distance, area) or a combination of those properties for all of the vertices or faces. In my case I need to preserve angles and distance of paths going from only one point. My intuition tells me that what I need should be quite simple because I demand much less from the output than all those parameterization algorithms. Yet I cannot come up with the solution. Any help is greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="6044" LastEditorUserId="6044" LastEditDate="2017-02-13T17:14:58.693" LastActivityDate="2017-02-13T17:30:24.073" Title="Algorithm to map a triangular mesh onto plane preserving angles and distances from one vertex" Tags="&lt;mesh&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4704" PostTypeId="2" ParentId="4701" CreationDate="2017-02-11T15:17:23.673" Score="4" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Sun light can be represented as a distant light. Light sources are radial like a bulb, though in the case of the sun, it is so far away from the Earth, that a reasonable approximation is to consider that all rays coming out of the sun are parallel at the Earth's surface. Using a distant light is an approximation. Because it's far away it is also assumed that there is no variation of light intensity as you go up or down (change height).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you do physically based rendering, the sun is an area light. From the Earth it looks like a small disk so you can approximate this with a large disk that is far far away. Area light like all light sources obeys a light intensity square fall off. So you will need to put your area light far away so that the intensity on the ground or as you change height doesn't vary much. Representing the sun as an area light avoids having to do strange things to the surface shader such as specifying a specular size.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="231" LastEditDate="2017-02-11T23:30:45.983" LastActivityDate="2017-02-11T23:30:45.983" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4706" PostTypeId="2" ParentId="1990" CreationDate="2017-02-11T17:21:45.813" Score="1" Body="&lt;p&gt;I too could not see my GPU through clinfo.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fix for me was disabling Secure Boot in the BIOS which did not let the Ubuntu kernel load DKMS code. There was even a ncurses warning after installing the driver, in my case AMDGPU PRO 16.60 on Ubuntu 16.10.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps!&lt;/p&gt;&#xA;" OwnerUserId="6047" LastActivityDate="2017-02-11T17:21:45.813" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4707" PostTypeId="2" ParentId="4701" CreationDate="2017-02-11T17:43:46.127" Score="0" Body="&lt;p&gt;What others said. Sun is modelled as a directional light, i.e. the direction of light is independent of the intersection point as it's very far away. So you just define a point in space and that itself is the &quot;direction towards the light source&quot;. If you want the direction of light rays towards the objects you gotta negate that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Coming to your second part. For shadow rays, you need to send a ray from the point of intersection towards the light source, since it's the sun in your case, the direction is just the location of the sun. Do note that the origin of the ray is not &lt;code&gt;intersection point&lt;/code&gt; rather it's &lt;code&gt;intersection point + epsilon&lt;/code&gt; where epsilon is a very small value (say 0.001) in order to avoid intersection of the ray with the object it generated from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After that you check for intersection of objects with this shadow ray. You don't need to compute the intersection points, you just need to know whether the ray intersected with an object or not. If it did you set the pixel color to just the ambient color.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-02-11T17:43:46.127" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4708" PostTypeId="2" ParentId="4538" CreationDate="2017-02-11T18:18:43.907" Score="0" Body="&lt;p&gt;Just leaving my opinion here in case someone else comes searching for the answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Different rendering systems have different definitions for screen space i guess. According to Renderman Screen Space means coordinates in the range [-1,1] where as other systems such as OpenGL thinks of it as Pixel coordinates ranging from 0 or 1 to the width/height of the actual screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In CG, before converting all the points to the actual pixel coordinates i.e where they are projected on the screen, we usually normalize all the points in the range [0,1] or [-1,1]. This is known as the Normalized device coordinates. It's done because it's easier to scale it back to screen size that may vary and it's usually easier to perform other calculation in this range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the coder there was just trying to do that.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  // horizontal window dimension [-X,X]&#xA;  double X = tan(alpha/2.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;according to him the horizontal window ranges from -X to X. Since alpha was PI/2 or 90 degrees. tan(alpha/2) comes out 1. So X is in the range -1,1. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; // pixel size&#xA;  double s = 2.0 * X / (double)w;&#xA;&#xA;  // vertical window dimension [-Y,Y]&#xA;  double Y = s * h / 2.0;&#xA;  ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Dunno about the fancy stuff but here the Y range has been mapped to &lt;code&gt;[-a,a]&lt;/code&gt; where &lt;code&gt;a&lt;/code&gt; is the aspect ratio. which is &lt;code&gt;width/height&lt;/code&gt; or &lt;code&gt;height/width&lt;/code&gt;. You can see that clearly if you substitue the value of &quot;s&quot; in the final equation. You'll get&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double Y = 2 * X * h / (2 * w)&#xA;Y = h/w    // X = 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The mapping to [-a,a] is done because our screen is not always a square. Its usually a rectangle. You can fix the Y values in [-1,1] and let X be in the range [-a, a] as well.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2017-02-11T18:24:33.900" LastActivityDate="2017-02-11T18:24:33.900" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4709" PostTypeId="1" CreationDate="2017-02-11T18:43:13.620" Score="0" ViewCount="730" Body="&lt;p&gt;I am currently making a Ray-tracer as a personal project. My lighting equation looks like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Pixel_color[i] = 255 * (Ma*Ig*Ca + Md*I*Cd * diffuse  + Ms*I*Cs * glossy)&#xA;// M = material color (ambient, diffuse and specular)&#xA;// I = intensity of light (Ig is the global ambient intensity)&#xA;// C = color of the light (ambient , diffuse and specular)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here &lt;code&gt;diffuse&lt;/code&gt; and &lt;code&gt;glossy&lt;/code&gt; contains all the necessary dot products and the normalization factors ( PI for diffuse and n+8/8*PI for Blinn Phong). Also everything is in range 0-1. I've read from some books and it says to make sure that &lt;code&gt;&quot;Ks + Kd&quot; &amp;lt;= 1&lt;/code&gt; And now I am confused. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) What exactly is Ks and Kd? Is it just my surface diffuse color and specular color divided by 255 to make it in the range 0-1? Or is it the reflectance ratio that I have to multiply with my color? If it's something else then what should I set them to? For example if I have a color &lt;code&gt;rgb(66, 170, 244)&lt;/code&gt; which is somewhat light blue. What should the Ks and Kd be for the above color?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) These books don't include the ambient component when talking about this conservation so should it be  Ka+Kd+Ks &amp;lt;= 1? Again if that's the case what will Ka be?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) If I consider Ks = Ms and Kd = Md. It doesn't fit out. for example if I want a surface with the above color &lt;code&gt;rgb(66, 170, 244)&lt;/code&gt; to be shiny and the specular highlight should be white. Then my Ms would be (255-66, 255-170, 255-244) which won't be white. Another way I could do is subtract the maximum from every component Ms(255-244, 255-244, 255-244). But this means the specular color would be very low. What if I wanted a very shiny surface?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPDATE:-&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So according to the book Computer Graphics Principles and Practice, Chapter 6 &quot;Fixed Function and Hierarchial Modeling in WPF&quot; &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Cd Innate color of “diffuse layer” (Cd,R,Cd,G,Cd,B)&#xA;Cs Innate color of “specular layer” (Cs,R,Cs,G,Cs,B)&#xA;ka Efficiency of diffuse layer at reflecting ambient light (ka,R, ka,G, ka,B)&#xA;kd Efficiency of diffuse layer at reflecting light (kd,R, kd,G, kd,B)&#xA;ks Efficiency of specular layer at reflecting light (ks,R, ks,G, ks,B)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After that it writes, &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Note that for solid-color materials, the distinction between the two terms Cd&#xA;  and kd is unnecessary, as far as the math is concerned; you can think of them as&#xA;  a single term. That is, you can fix kd,R at 1. 0 and use Cd,R to achieve any effect,&#xA;  and conversely you could fix Cd,R and specify only kd,R. However, the distinction&#xA;  between the two terms is meaningful when the innate color Cd is being provided&#xA;  via texture mapping; in that case, there is a need for a kd,R factor affecting the&#xA;  reflection of the varying color Cd specified by the texture.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;After that in Chapter 14.9 it removes Kd/Ks and Cd/Cs and replaces both with K_L and K_G&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;These k parameters are no longer potentially ambiguous RGB triples (each 0 . . . 1), but constants representing the net probability over all directions of&#xA;  that term contributing to scattering.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Which led me to think they are just a single constant like &quot;0.5&quot; However in the next example they are telling the same thing to ensure that K_L + K_G &amp;lt;= 1 across all channel which implies that k_L and k_G are infact RGB triples.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6546" LastEditDate="2017-05-02T00:26:52.560" LastActivityDate="2021-02-21T12:19:39.613" Title="Energy Conservation in Lighting Equation" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;shading&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4710" PostTypeId="2" ParentId="4709" CreationDate="2017-02-12T08:42:13.213" Score="3" Body="&lt;p&gt;Comment: if you make references to book, then it would be good if you could provide references.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer your questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;First, it is quite unusual these days to see people representing colors using a computer byte that is integer values within the range [0:255]. Most people these days use floats, and you will understand why in a moment. When you look at a material in general you can see a shiny part and a diffuse part. Shininess and diffuse appearance are computed using two different types of equation. Let's call the functions that compute the diffuse part &lt;code&gt;diffuse()&lt;/code&gt; and the function that compute the specular component &lt;code&gt;specular()&lt;/code&gt;. So now you can write:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ObjectColor = Ks * specular() + Kd * diffuse();&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Ks&lt;/code&gt; and &lt;code&gt;Kd&lt;/code&gt; control how shiny or/and diffuse your object is. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;About conservation of energy. In short an object can not reflect more light that it receives. So that means that technically if the specular() and diffuse() function do the right thing &lt;code&gt;Ks + Kd&lt;/code&gt; ought to be &lt;code&gt;1&lt;/code&gt;. If that wasn't true you would violate the principle of conservation of energy. In practice, it is generally good to follow this rule though most of the basic shading models are based on simple diffuse and specular models (for example the Phong model) and are not themselves energy conserving, so trying to be purely energy conserving at this level, is like trying to say you can paint a miniature with a paint roller. Forget about it, just try to be more or less in the right range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;ks&lt;/code&gt; and &lt;code&gt;kd&lt;/code&gt; generally stand for the specular and diffuse coefficients.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;if you don't do path tracing (aka don't simulate global illumination) the object won't reflect light from other objects in the scene, just light from direct light sources. So in the old time, in order to compensate for that, they would add an ambient term. In these days in age, this is considered as 'heresy'. Though if you account for the ambient term still then Ka + Kd + Ks should be again equal to 1 (same principle).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Not sure to understand what you say here but all these components are additive. You compute the diffuse multiplied by Kd and then you multiply the specular multiplied by Ks and then you add the two resulting numbers together. And that's your object color at the intersection point.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For an introduction to these topics I recommend you read:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-ray-tracing&quot; rel=&quot;nofollow noreferrer&quot;&gt;Introduction Ray-Tracing&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading&quot; rel=&quot;nofollow noreferrer&quot;&gt;Introduction to Shading&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/phong-shader-BRDF&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Phong Model&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order for you to progress, I personally recommend you proceed by step and don't try to understand everything at once. The problem of rendering and shading is very complex. You need to first understand the principle of light-matter interactions, what is diffuse what is specular and how are objects illuminated (direct and indirect lighting). Once you have these notions you can jump onto shading and understand or learn about the concept of shading model, and what the flaws and strengths of existing shading models (many of them exist).&lt;/p&gt;&#xA;" OwnerUserId="1608" LastActivityDate="2017-02-12T08:42:13.213" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4711" PostTypeId="2" ParentId="4538" CreationDate="2017-02-12T09:08:25.593" Score="1" Body="&lt;p&gt;You have two issues at stake here:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;What conventions are used in the particular program you use (or use as a template). The meaning that people gave to certain words within the context of your program.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The meaning of the terms 'screen coordinates' and 'window coordinates' in the Computer Graphics world. In the CG world, these terms have very precise meaning which do not necessarily correspond to the meaning they have in the context of your program. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So does your question relate to &quot;what do these terms mean in the context of my program&quot; or &quot;what do they mean in CG&quot;? It seems like you're more interested in the former.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's try to reconcile the two questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;When you render a CG image you use a virtual camera. The image plane of that camera exists in the virtual world (think of it as a rectangle if the image resolution width != the image resolution height what we call the image aspect ratio), and has the same coordinates as all the objects that are in your scene. Think of this camera as a pyramid whose apex is the eye position and the base of the pyramid the image plane. &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LFJxf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LFJxf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine that the image plane (the base of the pyramid) is 1 unit away from the apex. By changing the size of this image plane which you do by changing the field-of-view angle as shown in the image above, you can control how much of the scene you see (this is equivalent in photography to zooming in or out).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Points that lie on these planes, are said to be in &lt;code&gt;screen coordinates&lt;/code&gt;. Though at some point you need to transform these coordinates to pixel coordinates that we call &lt;code&gt;raster coordinates&lt;/code&gt; (which I believe in OpenGL are also called somehow &lt;code&gt;window coordinates&lt;/code&gt;). There are &lt;strong&gt;&lt;em&gt;no&lt;/em&gt;&lt;/strong&gt; conventions for what range the screen coordinates should lie in because it depends entirely on the way you actually build your camera model, but they go from -something to +something in height and -something * imageAspectRatio and +something * imageAspectRatio in width. Your raster coordinates always go from [0:height] for the y-coordinate and [0:width] for the x-coordinate. Screen coordinates are &lt;code&gt;floats&lt;/code&gt;, raster/window coordinates are &lt;code&gt;integers&lt;/code&gt; (they correspond to pixel position in the digital image representation, the stuff you save to disk or display to the screen).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Understand that all these concepts might take time and can't be properly explained in just a few lines. I would recommend additional sources for you to look at and really understand and learn about the different coordinate systems that are used and involved in the process of simulating physical cameras in computer graphics.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point&quot; rel=&quot;nofollow noreferrer&quot;&gt;Start from the start by understanding the geometry behind projecting points on screens&lt;/a&gt;.  &lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/3d-viewing-pinhole-camera&quot; rel=&quot;nofollow noreferrer&quot;&gt;Continue with learning about the pinhole camera model&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="1608" LastEditorUserId="231" LastEditDate="2017-02-12T14:05:38.507" LastActivityDate="2017-02-12T14:05:38.507" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4712" PostTypeId="1" AcceptedAnswerId="4713" CreationDate="2017-02-12T18:24:12.840" Score="5" ViewCount="346" Body="&lt;p&gt;Doing post-process gamma correction is showing texture artifacts, here is a small example on a skybox:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HAqRT.jpg&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HAqRT.jpg&quot; alt=&quot;Correction on Skybox vs Post Process&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first image is gamma correcting on the skybox shader and seems correct, the lower is doing it in post-process and has terrible artifacts near the edges of the clouds, however both versions do it the same usual way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Color.rgb = pow(Color.rgb, vec3(1.0/2.2));&#xA;Color.a = 1.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So that makes me believe there's something wrong with the way I'm creating and using frame buffers, here's sort of how I'm doing it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Generate FirstFBO, specify this as the color attachment&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, FramebufferSize.x, FramebufferSize.y, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); &#xA;&#xA;// ...&#xA;&#xA;while (true) {&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, FirstFBO.ID);&#xA;    DrawStuff();&#xA;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;    glBindTexture(GL_TEXTURE_2D, FirstFBO.ColorTexture);&#xA;    DrawFullscreenQuad();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6049" LastActivityDate="2017-02-12T19:46:23.880" Title="Artifacts when gamma correcting" Tags="&lt;c++&gt;&lt;gamma&gt;&lt;artifacts&gt;&lt;post-processing&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4713" PostTypeId="2" ParentId="4712" CreationDate="2017-02-12T19:46:23.880" Score="6" Body="&lt;p&gt;Short answer, set the precision of the image to a higher value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Long answer,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When looking at a gamma correction curve, you can see that the lower values get changed much more, this means that the difference between lower values will get greater and that causes this effect. You have a limited amount of values for a color channel and this means that when it rounds the number down to the 8 bit value, it makes some neighboring pixels the same color. You don't notice this in a normal image, but after gamma correcting it this effect comes out, because you lose that bit of change in the color that later on can become a much bigger difference in color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this, you just give the gamma correction more precision to also get that small color change it would've else rounded away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the actual shader, it has floating point color information and that means that it has more precision and thus not the weird artifact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when making the frame buffer, you can use for example GL_RGBA16F or GL_RGBA32F. This would increase the precision and remove the artifact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that this can help you fix the problem, good luck and have a great day!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2017-02-12T19:46:23.880" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4715" PostTypeId="1" AcceptedAnswerId="4716" CreationDate="2017-02-13T02:33:56.647" Score="4" ViewCount="276" Body="&lt;p&gt;I'm learning about subdivision surface algorithms. The &quot;Catmull-Clark&quot; algorithm seems to be one of the most widely-used classical algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The introduction of new face points and edges is straightforward, but I'm confused by the following formula for modifying the locations of original points&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \frac{F + 2R + (n-3)P}{n} $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$P$ is the original point&lt;/li&gt;&#xA;&lt;li&gt;$R$ is the average of all $n$ edges midpoints touching $P$&lt;/li&gt;&#xA;&lt;li&gt;$F$ is the average of all $n$ face points touching $P$&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I understand the result is a weighted average of three points $F$, $R$ and $P$, but where do the coefficients $1$, $2$, and $(n-3)$ come from? Why $2R$? Why not $2.01R$? Or $1R$ and $2F$?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All the introductions I've seen just present the formula without presenting a justification.&lt;/p&gt;&#xA;" OwnerUserId="5905" LastEditorUserId="5905" LastEditDate="2017-02-13T20:02:57.813" LastActivityDate="2017-02-15T08:21:24.800" Title="Where do the coefficients in the Catmull-Clark subdivision algorithm come from?" Tags="&lt;subdivision&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4716" PostTypeId="2" ParentId="4715" CreationDate="2017-02-13T09:16:21.083" Score="3" Body="&lt;p&gt;The derivation is presented in the original paper that introduced CC subdivisions as a generalisation of B-Spline patches: &lt;a href=&quot;https://people.eecs.berkeley.edu/~sequin/CS284/PAPERS/CatmullClark_SDSurf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://people.eecs.berkeley.edu/~sequin/CS284/PAPERS/CatmullClark_SDSurf.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-02-13T09:16:21.083" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4718" PostTypeId="1" CreationDate="2017-02-13T20:52:12.473" Score="1" ViewCount="272" Body="&lt;p&gt;I'm using GLSL 4.0 to write a subdivision routine that divides the triangles on an object through a geometry shader. I'm not using barycentric co-ordinates but vector arithmetic to output the triangle vertices. I managed to get the subdivision working but I don't understand how to interpolate the vertex normals to produce the correct shading:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400 &#xA;&#xA;layout(triangles) in;&#xA;layout(triangle_strip, max_vertices = 93) out; //MAX 128&#xA;&#xA;uniform mat4 mvMatrix;&#xA;uniform mat4 pMatrix;&#xA;uniform mat3 normalMatrix; //mv matrix without translation&#xA;uniform int subdivision_level;&#xA;uniform vec4 lightPosition_camSpace; //light Position in camera space&#xA;&#xA;uniform int time;&#xA;&#xA;in data&#xA;{&#xA;  vec4 position_camSpace;&#xA;  vec3 normal_camSpace;&#xA;  vec2 textureCoordinate;&#xA;  vec4 color;&#xA;}vertexIn[3];&#xA;&#xA;out fragmentData&#xA;{&#xA;  vec4 position_camSpace;&#xA;  vec3 normal_camSpace;&#xA;  vec2 textureCoordinate;&#xA;  vec4 color;&#xA;} frag;&#xA;&#xA;&#xA;void emit_triangle(vec4 position, vec4 width, vec4 hyp, float s) {&#xA;&#xA;    /* NORMALS NOT FIXED */&#xA;&#xA;    //A&#xA;    gl_Position = position;&#xA;    frag.color = vertexIn[0].color;&#xA;    frag.position_camSpace = vertexIn[0].position_camSpace;&#xA;    frag.normal_camSpace = vertexIn[0].normal_camSpace;&#xA;    frag.textureCoordinate = vertexIn[0].textureCoordinate;&#xA;    EmitVertex();&#xA;&#xA;    //B&#xA;    gl_Position = position + width;&#xA;    frag.color = vertexIn[1].color;&#xA;    frag.position_camSpace = vertexIn[1].position_camSpace;&#xA;    frag.normal_camSpace = vertexIn[1].normal_camSpace;&#xA;    frag.textureCoordinate = vertexIn[1].textureCoordinate;&#xA;&#xA;    EmitVertex();&#xA;&#xA;    //C&#xA;    gl_Position = position + hyp;&#xA;    frag.color = vertexIn[2].color;&#xA;    frag.position_camSpace = vertexIn[2].position_camSpace;&#xA;    frag.normal_camSpace = vertexIn[2].normal_camSpace;&#xA;    frag.textureCoordinate = vertexIn[2].textureCoordinate;&#xA;&#xA;    EmitVertex();&#xA;&#xA;    EndPrimitive();&#xA;}&#xA;&#xA;void main() {&#xA;&#xA;  // A gl_In[0].gl_Position;&#xA;  // B gl_In[1].gl_Position;&#xA;  // C gl_In[2].gl_Position;&#xA;&#xA;  float s = 1/pow(2,subdivision_level);&#xA;  int triangles_render = int(1/s);&#xA;&#xA;&#xA;  vec4 hyp_off = vec4(0.0,0.0,0.0,0.0);&#xA;  vec4 width_off = vec4(0.0,0.0,0.0,0.0);&#xA;&#xA;  vec4 position = gl_in[0].gl_Position;&#xA;  vec4 width = s*(gl_in[1].gl_Position - gl_in[0].gl_Position);&#xA;  vec4 hyp = s*(gl_in[2].gl_Position - gl_in[0].gl_Position);&#xA;&#xA;  vec4 hyp_off_f = vec4(0.0,0.0,0.0,0.0);&#xA;  vec4 width_off_f = width;&#xA;&#xA;&#xA;  for (int i=0; i&amp;lt;=subdivision_level+1; i++) {&#xA;    for (int j=0; j&amp;lt;triangles_render-i; j++) {&#xA;&#xA;      // Normal triangle&#xA;      emit_triangle(position + hyp_off + width_off, width, hyp,s);&#xA;      width_off += width;  &#xA;&#xA;      // Flipped triangle&#xA;      if (j &amp;lt;triangles_render-i-1)&#xA;      {&#xA;        emit_triangle(position + width_off_f + hyp_off_f, hyp, hyp - width,s);&#xA;        width_off_f += width;&#xA;      }&#xA;&#xA;    }&#xA;    hyp_off += hyp;&#xA;    width_off = vec4(0.0,0.0,0.0,0.0);&#xA;&#xA;    hyp_off_f += hyp;&#xA;    width_off_f = width;&#xA;&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Currently the result looks like flat shading because I just use the normals of the vertices from the vertex shader. How do I compute the correct normals so that the shading looks correct? Also do I need to modify the vertex position too? I'm unsure about this part. I've read &#xA;&lt;a href=&quot;https://stackoverflow.com/questions/4703432/why-does-my-opengl-phong-shader-behave-like-a-flat-shader&quot;&gt;https://stackoverflow.com/questions/4703432/why-does-my-opengl-phong-shader-behave-like-a-flat-shader&lt;/a&gt; But they use barycentric co-ordinates for the solution.&lt;/p&gt;&#xA;" OwnerUserId="6061" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-02-13T20:52:12.473" Title="Subdivision vertex normal interpolation" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4720" PostTypeId="2" ParentId="4676" CreationDate="2017-02-14T17:29:39.060" Score="1" Body="&lt;p&gt;Generally, with VSYNC, your CPU is effectively doing nothing 99% of the time, as it merely sent the simple vertex buffer batch (few triangles, as you said) to the driver. If the shader is bandwidth-heavy, it takes multiple frames to render. In your case, you said it's 12 fps, e.g. 60/12 = 5 frames. So, the CPU (or the core that runs your thread), is literally doing nothing for 5 frames (other than waiting for vsync). That's an egregious waste of performance for a 3d engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is the 'utilization' statistics important, anyway ? What matters is your framerate, that's how you know how well you're doing, not some arbitrary 'utilization' number in the OS, that god-knows-how it got assembled in the first place.&lt;/p&gt;&#xA;" OwnerUserId="6063" LastActivityDate="2017-02-14T17:29:39.060" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4721" PostTypeId="2" ParentId="4699" CreationDate="2017-02-14T17:41:44.410" Score="1" Body="&lt;p&gt;Take a look at &lt;a href=&quot;http://valvesoftware.com/publications/2006/SIGGRAPH06_Course_ShadingInValvesSourceEngine.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Valve's paper&lt;/a&gt; on combining Radiosity and Normal Mapping. It had a lot of useful insights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I'm not mistaken, it looks to me like you're trying to compute normal mapping using the energy value at the texel that is a result of Radiosity - e.g. it came from all directions through almost-endless bumping around the room across thousands of surfaces. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But your point light, for the normal mapping, has a very specific position, direction, distance and intensity. Meaning, you're combining apples and goats.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I believe you should do is:&#xA;- compute the normal mapping separately for those surfaces&#xA;- blend the GI solution with normal mapping&#xA;- experiment with the blending factor till it looks 'good enough' for you&lt;/p&gt;&#xA;" OwnerUserId="6063" LastEditorUserId="506" LastEditDate="2017-02-16T08:46:57.793" LastActivityDate="2017-02-16T08:46:57.793" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4722" PostTypeId="1" AcceptedAnswerId="4724" CreationDate="2017-02-14T19:05:10.187" Score="4" ViewCount="373" Body="&lt;p&gt;After Z-Buffer Testing does the fragment shader run on the discarded fragments?&#xA;Does the Z-Test happen after the fragment shader runs?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please, tell me the step by step events that occur in the Z-Test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also what is early Z-Test and how to achieve it?&lt;/p&gt;&#xA;" OwnerUserId="6064" LastEditorUserId="6546" LastEditDate="2017-05-02T00:26:31.770" LastActivityDate="2017-05-02T00:26:31.770" Title="Z buffer working in OpenGL" Tags="&lt;opengl&gt;&lt;rasterizer&gt;&lt;fragment-shader&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4723" PostTypeId="1" CreationDate="2017-02-14T22:48:50.527" Score="2" ViewCount="159" Body="&lt;p&gt;According to Peter Shirely &lt;a href=&quot;http://www.cs.virginia.edu/~jdl/bib/globillum/mis/shirley96.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt;, one pdf(probability density function) can be defined for the union of the light sources and pick only one using a random number from this density:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$p(x) = \alpha_1 P_1(x) + (1-\alpha_1) P_2(x)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This has been referred to as mixture densities. where $\alpha_1 \in [0,1]$ and $P_1$ is a pdf for selecting a point on the $L_1$ geometry (usually $1/A$). If the random number is less than $\alpha_1$ then the total estimate is $(\text{estimated }L_1)/\alpha_1$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This has been extended for N:&#xA;$$p(x) = \alpha_1 P_1(x) + \alpha_2 P_2(x) + \cdots + \alpha_n P_n(x)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is how one pick two or multiple light sources, instead of just one, from the above density and what the estimate would be in that case.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="2479" LastEditDate="2017-02-16T08:46:42.547" LastActivityDate="2017-02-16T08:46:42.547" Title="Picking multiple light sources from a mixture densities" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;global-illumination&gt;&lt;sampling&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4724" PostTypeId="2" ParentId="4722" CreationDate="2017-02-15T02:55:06.983" Score="4" Body="&lt;p&gt;When depth testing is enabled, the testing occurs after the fragment shader executes. The procedure is relatively simple (and spelled out pretty well &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Depth_Test&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Get depth of fragment&lt;/li&gt;&#xA;&lt;li&gt;Test against depth buffer&lt;/li&gt;&#xA;&lt;li&gt;Discard if it fails&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Early-z discard is when a rasterizer discards a fragment before a fragment shader runs because it's clear early on that it won't pass the depth test. However, the rasterizer can't safely do this if certain things happen (such as calling &lt;code&gt;discard()&lt;/code&gt; or modifying the fragment depth in a fragment shader). This is a hardware optimization and isn't required to occur unless you force it with OpenGL 4.2 or with an extension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are things that can &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Early_Fragment_Test#Limitations&quot; rel=&quot;nofollow noreferrer&quot;&gt;prevent early-z discard from occurring&lt;/a&gt;. To achieve it:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Don't use &lt;code&gt;discard()&lt;/code&gt; in a fragment shader&lt;/li&gt;&#xA;&lt;li&gt;Don't modify the depth of a fragment in a fragment shader&lt;/li&gt;&#xA;&lt;li&gt;Don't use alpha testing (deprecated)&lt;/li&gt;&#xA;&lt;li&gt;Make sure you have depth testing turned on&lt;/li&gt;&#xA;&lt;li&gt;Make sure you have a depth buffer&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2017-02-15T03:01:45.460" LastActivityDate="2017-02-15T03:01:45.460" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4725" PostTypeId="2" ParentId="4715" CreationDate="2017-02-15T08:21:24.800" Score="3" Body="&lt;p&gt;I'm just going to add a few more details to &lt;a href=&quot;https://people.eecs.berkeley.edu/~sequin/CS284/PAPERS/CatmullClark_SDSurf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;the paper&lt;/a&gt; that Stefan linked to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all, the matrix $H_1$ displayed in the paper is incorrect; every element should be multiplied by a factor of $\frac{1}{8}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ H_1 = \frac{1}{8} \begin{bmatrix}&#xA;    4 &amp;amp; 4 &amp;amp; 0 &amp;amp; 0 \\&#xA;    1 &amp;amp; 6 &amp;amp; 1 &amp;amp; 0 \\&#xA;    0 &amp;amp; 4 &amp;amp; 4 &amp;amp; 0 \\&#xA;    0 &amp;amp; 1 &amp;amp; 6 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, the derivation of the new face point formula for quads in the first half of the paper is confusing, so I will fill in some of the details. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The matrix $G_1 = HGH^T$ contains the 16 control points for one sub-quad of the original quad with control points $G$. The entries of $G_1$ are referred to with $q_{i,j}$. Of most interest are the elements $q_{1,1}$, $q_{1,2}$ and $q_{2,2}$, which represent control points for a corner, edge, and interior of the $4\times 4$ control point grid for the sub-quad. All the other elements have similar formulas due to the symmetry of the subdivision process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By carrying out the matrix multiplication, we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$q_{2,2} = \frac{P_{1,1} +P_{3,1} +P_{3,1} +P_{3,3}}{64} + \frac{6(P_{1,2} +P_{2,1} +P_{3,2} +P_{2,3})}{64} + \frac{36P_{2,2}}{64}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can see from this formula that, when relocating a control point, its new location is determined by the $3\times 3$ grid of points surrounding it. Here we see that in this grid, corner points have $\frac{1}{64}$ influence, edge points have $\frac{6}{64} = \frac{3}{32}$ influence, and the center (&quot;old&quot;) point has $\frac{36}{64} = \frac{9}{16}$ influence. These weights are consistent with the ones given at the bottom of &lt;a href=&quot;http://www.rorydriscoll.com/2008/08/01/catmull-clark-subdivision-the-basics/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this blog post&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With a bit of rearranging, we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$q_{2,2} = \frac{1}{4} \big[ \frac{1}{4}(\frac{P_{1,1} + P_{1,2} + P_{2,1} + P_{2,2}}{4} + \frac{P_{1,2} + P_{2,2} + P_{1,3} + P_{2,3}}{4} + \frac{P_{2,1} + P_{2,2} + P_{3,2} + P_{3,1}}{4} + \frac{P_{2,2} + P_{2,3} + P_{3,2} + P_{3,3}}{4}) + 2\frac{1}{4}(\frac{P_{1,2} + P_{2,2}}{2} + \frac{P_{2,1} + P_{2,2}}{2} + \frac{P_{2,3} + P_{2,2}}{2} + \frac{P_{3,2} + P_{2,2}}{2}) + P_{2,2}\big]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first term is merely the average of the four surrounding face points; in other words, it is $F$. The second term is the average of the four surrounding edge midpoints multiplied by $2$; in other words, it is $2R$. Finally, $P_{2,2}$ is simply the original control point $P$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And so we see this is the same as the original formula for quads: $\frac{1}{4}(F + 2R + P)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper does not provide a derivation of the general case for an $n$-sided polygon, but it seems like a reasonable extension based on intuition.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;As an aside, here is an explanation for the other points, and &lt;a href=&quot;https://en.wikipedia.org/wiki/Catmull%E2%80%93Clark_subdivision_surface&quot; rel=&quot;nofollow noreferrer&quot;&gt;their meanings as seen on wikipedia&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$q_{1,1} = \frac{P_{1,1} +P_{1,2} +P_{2,1} +P_{2,2}}{4}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is simply the formula for adding a new control point at the center of an existing quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$q_{1,2} = \frac{P_{1,1} +P_{1,2} +P_{2,1} +P_{2,3}}{16} + \frac{6(P_{1,2} +P_{2,1})}{16}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rearranging this, we see it is just the average of the two neighbouring face points and the edge endpoints:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$q_{1,2} = \frac{1}{4}(\frac{P_{1,1} +P_{2,1} +P_{1,2} +P_{2,2}}{4} + \frac{P_{1,2} +P_{2,2} +P_{1,3} +P_{2,3}}{4} + P_{1,2} + P_{2,1})$&lt;/p&gt;&#xA;" OwnerUserId="5905" LastActivityDate="2017-02-15T08:21:24.800" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4726" PostTypeId="1" CreationDate="2017-02-16T04:26:53.823" Score="0" ViewCount="642" Body="&lt;p&gt;I'm writing a function that reads the number of red pixels on the left and right halves of the screen, it makes adjustments while the difference between the number of red pixels falls outside of a threshold. I'm having trouble with the buffers (back and front) because when I finally swap to the front buffer, it dynamically draws all changes I made in the loop meant for the back buffer but I only want the final one drawn to screen. In pseudocode, &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;do {&#xA;    draw scene to back buffer&#xA;    read number of left, right red pixels&#xA;    if (abs(left-right)&amp;gt;threshold) {&#xA;        //some function to jitter objects in the scene&#xA;    }&#xA;    else done=true,&#xA;}while(!done);&#xA;&#xA;//draw to front buffer&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is some C++/OpenGL code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;do {&#xA;    glDrawBuffer(GL_BACK_LEFT);&#xA;    display(0);&#xA;&#xA;    glDrawBuffer(GL_BACK_RIGHT);&#xA;    display(1);&#xA;&#xA;    redsleft = 0;&#xA;    redsright = 0;&#xA;&#xA;    glReadBuffer(GL_BACK_LEFT);&#xA;    glReadPixels(0, 0, resolution.first, resolution.second, GL_RGBA, GL_UNSIGNED_BYTE, frameBuffer);&#xA;    for (int j = 0; j &amp;lt; resolution.first*resolution.second * 4; j += 4)&#xA;    {&#xA;        if (frameBuffer[j]&amp;gt;0 &amp;amp;&amp;amp; frameBuffer[j + 1] == 0 &amp;amp;&amp;amp; frameBuffer[j + 2] == 0 &amp;amp;&amp;amp; frameBuffer[j + 3] &amp;gt; 0)&#xA;        {&#xA;            if (j % 4 == 0 &amp;amp;&amp;amp; i == 0)&#xA;            {&#xA;                int redX = (j / 4) % resolution.first;&#xA;                int redY = j / 4 / resolution.first;&#xA;&#xA;                if (redX &amp;lt; resolution.first / 2)&#xA;                    redsleft++;&#xA;                else&#xA;                    redsright++;&#xA;            }&#xA;        }&#xA;    }&#xA;    //if above threshold, call function to adjust &#xA;    //else done&#xA;} while (!done);&#xA;&#xA;glDrawBuffer(GL_BACK_LEFT);&#xA;display(0);&#xA;&#xA;glDrawBuffer(GL_BACK_RIGHT);&#xA;display(1);&#xA;&#xA;glutSwapBuffers();&#xA;glutPostRedisplay();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="5183" LastEditorDisplayName="user7220" LastEditDate="2018-03-03T17:40:16.723" LastActivityDate="2018-03-03T17:40:16.723" Title="OpenGL back and front buffer - counting and adjusting the number of red pixels before displaying to screen" Tags="&lt;opengl&gt;&lt;buffers&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4727" PostTypeId="1" CreationDate="2017-02-16T05:44:46.617" Score="2" ViewCount="148" Body="&lt;p&gt;If I want to use my own Ray Tracer in a program like 3DS Max to render geometry, how could I do this? Can someone explain to me what I need to do and where I can learn to use an SDK to make this happen? Is this worth it to render test scenes to compare and test my ray tracer?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-02-16T16:47:12.630" Title="How to use my Ray Tracer in 3DS Max" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4728" PostTypeId="1" AcceptedAnswerId="4729" CreationDate="2017-02-16T10:06:05.250" Score="4" ViewCount="220" Body="&lt;p&gt;I've difficulties in looking for an answer by myself because I don't know the jargon. I need somebody who'll points me in the right direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume I have 100000 points with coordinates in the unit square, so points like (0.55313, 0.236831).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to create a B/W picture with a given side in pixels (say 1000 x 1000) which shows these points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The naive approach is to multiply by the side the coordinates and round, so point (0.55313, 0.236831) becomes pixel (553, 237) and to turn pixel (553,237) on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is rather unsatisfactory. If the points are many, say millions, I could easily fill all the area with a black blob that gives me 0 information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, what I thought was to have an array 1000x1000 of floating point numbers that I can update somehow when I add a point, and at the end I can normalize the values and obtain a grayscale image, which will be &quot;blacker&quot; where more points are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Now the question&lt;/strong&gt;: which algorithms are used to add a &quot;blurred&quot; point? I.e., I would like to take into account the real coordinates, so that, if a point is near the border of a &quot;pixel&quot; I would like its addition to my array to &quot;smudge&quot; a little the nearby pixels. Like when you draw a point in a drawing program and it actually adds a little disk with decreasing (linear? Gaussian?) intensity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Surely it is a problem that has been already been studied and solved, just I don't know how it is called...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;thanks&lt;/p&gt;&#xA;" OwnerUserId="6072" LastActivityDate="2017-02-16T11:10:17.193" Title="Main techniques to draw a point at non integer coordinates?" Tags="&lt;algorithm&gt;&lt;antialiasing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4729" PostTypeId="2" ParentId="4728" CreationDate="2017-02-16T11:10:17.193" Score="4" Body="&lt;p&gt;Instead of having a binary on/off per pixel you can instead make a heat map. The more points fall within the pixel the brighter the pixel is. Essentially create a 2D histogram which you then renormalize to get the grayscale for the output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to blur the points then you can move a portion of the brightness to the next pixel based on the remaining fraction after multiplying to the resolution. If it the coordinate is &lt;code&gt;(0.55313, 0.236831)&lt;/code&gt; and your resolution is 1000x1000 then &lt;code&gt;0.87*0.17&lt;/code&gt; goes to &lt;code&gt;553, 236&lt;/code&gt;, &lt;code&gt;0.87*0.83&lt;/code&gt; goes to &lt;code&gt;553, 237&lt;/code&gt;, &lt;code&gt;0.13*0.17&lt;/code&gt; goes to &lt;code&gt;554, 236&lt;/code&gt; and &lt;code&gt;0.13*0.83&lt;/code&gt; goes to &lt;code&gt;554, 237&lt;/code&gt;. This is distributed linearly but there are other options.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-02-16T11:10:17.193" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4730" PostTypeId="2" ParentId="4727" CreationDate="2017-02-16T16:47:12.630" Score="4" Body="&lt;p&gt;You can do this by writing a renderer plugin for 3ds Max. This gives you the same kind of access as the built-in renderers, including a settings dialog, a preview window, and an interface where you can write the final frame of a full render (and 3ds Max will write it to the output file). The renderer plugin gets full access to the scene graph when the user hits &quot;Render&quot; (or when the preview window is in use). Any complex geometry (such as subdivision surfaces) will already have been converted to a triangle mesh for you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PaulHK already linked the official &lt;a href=&quot;http://docs.autodesk.com/3DSMAX/16/ENU/3ds-Max-SDK-Programmer-Guide/index.html?url=files/GUID-40ED5D02-BBCF-4EE3-9EE7-E59425B49CBB.htm,topicNumber=d30e2631&quot; rel=&quot;noreferrer&quot;&gt;&lt;em&gt;Programmers' Guide&lt;/em&gt;&lt;/a&gt; online. You'll also find it in the help files that are installed with 3ds Max, along with sample source code for a trivial renderer plugin. Because your plugin needs to link against the 3ds Max SDK, you'll need to compile it with the same version of Microsoft Visual Studio that was used to compile the particular version of 3ds Max you're targeting. (This means that if you want to target multiple versions of 3ds Max, you might need multiple builds.) Again, how to do this is described in the Programmers' Guide.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-02-16T16:47:12.630" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4731" PostTypeId="1" CreationDate="2017-02-16T18:33:37.293" Score="0" ViewCount="1621" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FL0Xn.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FL0Xn.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Download this picture and see it as a thumbnail, like in whatsapp or your phone gallery and you'll find that it shows another picture in the thumbnail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;If you can't see the thumbnail:&lt;/em&gt;&#xA;You can simply do some changes in color, or do some filters on it using PicsArt and you'll notice the difference.  I've searched the whole internet, but haven't got the answer yet.&#xA;Please explain how is this happening. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I know about the trick with PNG files, but this is a JPEG file and the trick works with this too.&#xA;I added &lt;a href=&quot;https://youtu.be/j6gFEULzAdE&quot; rel=&quot;nofollow noreferrer&quot;&gt;video&lt;/a&gt; a to elaborate.&lt;/p&gt;&#xA;" OwnerUserId="6074" LastEditorUserId="6074" LastEditDate="2017-02-18T14:57:02.013" LastActivityDate="2017-02-18T14:57:02.013" Title="Why thumbnail shows just another pic?" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4732" PostTypeId="2" ParentId="4699" CreationDate="2017-02-16T21:03:22.210" Score="1" Body="&lt;p&gt;In the end, what I gleaned from the Valve paper, and what I found in an existing light mapper implementation, led me to the following conclusion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When performing my final global illumination integration, instead of using a cosine-weighted hemisphere of samples, use a uniform hemisphere of samples. For each sample, project the sample's direction on each of the three basis vectors, scaling the sample colour by the resulting projection. The three sums are accumulated, and then divided by the number of samples. At runtime, the normal map is projected onto the basis and the contributing lightmap colour for each basis is scaled by the projection prior to accumulating.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Color3 basisSum[3] = { 0, 0, 0 };&#xA;&#xA;for ( each sample in hemisphere... )&#xA;{&#xA;  Color3 colour = trace_sample(sample);&#xA;&#xA;  for ( int b = 0; b &amp;lt; 3; b++ )&#xA;  {&#xA;    float dot = Dot( sample.directionTS, basisTS[b] ); // both in tangent space&#xA;    basisSum[b] += colour * dot;&#xA;  }&#xA;}&#xA;for ( int b = 0; b &amp;lt; 3; b++ )&#xA;{&#xA;  basisSum[b] /= numSamples;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I made no special case handling for clamping the back-side of the basis in the tool - my experiments and research lead me to conclude that the entire hemisphere should be represented for each basis, even if intuitively the backwards-facing samples seem like they would 'subtract' colour because of a negative dot product.&lt;/p&gt;&#xA;" OwnerUserId="6001" LastActivityDate="2017-02-16T21:03:22.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4733" PostTypeId="2" ParentId="4731" CreationDate="2017-02-17T11:01:58.830" Score="2" Body="&lt;p&gt;You can't see it in the image you uploaded because it's a JPEG, but PNG files which have a full alpha channel can do the trick you mentioned. It works with websites or apps where the &quot;thumbnail&quot; image is displayed on a white background and the &quot;full&quot; image is displayed on a black background. In the thumbnail display, white pixels and completely transparent pixels look the same, because of the white background; in the full image, black pixels and completely transparent pixels look the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, you can have a white-on-black picture and a black-on-white picture in the same image, and the background hides one of the two images. You can easily see what's going on if you look at the image against a background of some other colour.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-02-17T11:01:58.830" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4735" PostTypeId="1" CreationDate="2017-02-18T22:57:13.080" Score="1" ViewCount="43" Body="&lt;p&gt;So i'm currently trying to draw a 3D cube, and from what I understand everything should be working right, but It's coming out weird and I believe it's because the ordering of my indexes is wrong. Is there any way to view what vertex is associated with an index? for instance something along the lines of&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;print(index[5]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;that would output something along the lines of:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;index[5]: (0.5, 0.5, 0.5)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is this possible at all? or at least to view it in a debugger?&lt;/p&gt;&#xA;" OwnerUserId="6085" LastActivityDate="2017-02-18T22:57:13.080" Title="View / print index values?" Tags="&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4736" PostTypeId="1" CreationDate="2017-02-19T04:11:31.440" Score="2" ViewCount="59" Body="&lt;p&gt;Vectorizing continuous tone images is often met with color palette reduction and visual artifacts. Half-tone images, on the hand, have constant patterns in their tones, which would intuitively lead to the conclusion that these images can be vectorized with greater success, if without any visual artifacts at all.&#xA;   Failing to find any sufficient comparisons against vectorizing continuous tone images and half-tone images on separate research, I now pose this: &lt;strong&gt;What behaviors occur during vectorization of &quot;raster&quot; half-tone images?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="6089" LastActivityDate="2017-02-19T04:11:31.440" Title="Vectorizing half tone images" Tags="&lt;vector-graphics&gt;&lt;artifacts&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4737" PostTypeId="1" AcceptedAnswerId="4789" CreationDate="2017-02-19T16:39:03.550" Score="1" ViewCount="1285" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;For a 3D scene in the world coordinates, its &lt;em&gt;View Reference Point&lt;/em&gt; $\mathrm{VRP}$ is at $(5,-2,1)$, and a viewer is looking towards point $A=(1,1,1)$. Construct a transform matrix which will map world coordinate points to a right-handed $(UVN)$ viewing space, so that $\mathrm{VRP}$ is the origin, the line joining $\mathrm{VRP}$ to $A$ is the positive $N$ axis, and the view-up Vector is $(0,0,1)$.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;To my knowledge, the final answer should be a single transform matrix.&#xA;To calculate the final matrix, I first find the matrix which translates the coordinate system to the to the origin in homogeneous matrix form:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Translation matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;T=&#xA;        \begin{bmatrix}&#xA;        1 &amp;amp;0 &amp;amp;0 &amp;amp;-5 \\&#xA;        0 &amp;amp;1 &amp;amp;0&amp;amp; 2 \\&#xA;        0 &amp;amp;0 &amp;amp;1 &amp;amp;-1 \\&#xA;        0 &amp;amp;0 &amp;amp;0 &amp;amp;1 \\&#xA;        \end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the unit vectors of the coordinate axes, the resulting rotation matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;R=&#xA;        \begin{bmatrix}&#xA;        -0.6 &amp;amp;-0.8 &amp;amp;0 &amp;amp;0 \\&#xA;        0 &amp;amp;0 &amp;amp;0 &amp;amp;1 \\&#xA;        -0.8 &amp;amp;0.6 &amp;amp;0 &amp;amp;0 \\&#xA;        0 &amp;amp;0 &amp;amp;0 &amp;amp;1 \\&#xA;        \end{bmatrix}&#xA;$$&#xA;Then the final matrix (the final answer for full marks) would be the rotation matrix multiplied by the translation matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;M=&#xA;        \begin{bmatrix}&#xA;        -0.6 &amp;amp;-0.8 &amp;amp;0 &amp;amp;1.4 \\&#xA;        0 &amp;amp;0 &amp;amp;0 &amp;amp;1 \\&#xA;        -0.8 &amp;amp;0.6 &amp;amp;0 &amp;amp;5.2 \\&#xA;        0 &amp;amp;0 &amp;amp;0 &amp;amp;1 \\&#xA;        \end{bmatrix}&#xA;$$&#xA;Is my method and final answer correct?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Following the answer to this question, I have calculated the translation matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;T=&#xA;\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; -5 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 2 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -1 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have calculated the rotation matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;R=&#xA;\begin{pmatrix}&#xA;-0.6 &amp;amp; -0.8 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;-0.8 &amp;amp; 0.6 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what would the final transformation matrix $M$ be? My lecture slides tell me it would be rotation matrix multiplied by translation matrix, with the last column multiplied by $-1$ except for the $1$. This would equal:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;M = R \times T = &#xA;\begin{pmatrix}&#xA;-0.6 &amp;amp; -0.8 &amp;amp; 0 &amp;amp; -1.4 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 1 \\&#xA;-0.8 &amp;amp; 0.6 &amp;amp; 0 &amp;amp; -5.2 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But the answer here just adds them together somehow. Which one is correct?&lt;/p&gt;&#xA;" OwnerUserId="5513" LastEditorUserId="231" LastEditDate="2017-08-05T21:32:15.277" LastActivityDate="2017-08-05T21:32:15.277" Title="Building view transform matrices" Tags="&lt;3d&gt;&lt;matrix&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4740" PostTypeId="1" CreationDate="2017-02-21T00:32:20.080" Score="2" ViewCount="457" Body="&lt;p&gt;I am working on a &quot;CAD&quot; like program in HTML5 that requires drawing many thousands (700,000+) of images on the screen. I think, &quot;fortunately&quot; the many images are replicated uses of a unique set of images. The unique set is many orders of magnitude less than the instances of them. One example I am working with has 700,000+ instances from a set of 360 unique images. The images are actually generated on the fly when the program first loads and they are rectangles with the &quot;name&quot; of the image centered about the middle of the rectangle (no color within the rectangle, etc... just a rectangle outline with the text in the middle, text and rectangle outline is black). The program should be able to display the images at many magnification levels, and of course, be fast enough for it to be useful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A first implementation worked well with SVG images loaded. Due to the vector aspect of the images, it worked nicely at all magnifications. But after about 70,000 or so instances the program started to run out of memory. I assume because the DOM is not able to keep up with so many instances...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After a lot of studying and experimentation, I was able to implement a working version of the program using WebGL. It works pretty well, and it is fast. I know I will have to implement all the fun things I got from SVG for free, like CSS colors, listeners, individual elements in the DOM, etc, but I was not using a lot of that anyhow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've been able to implement a system that can render a lot of different instances of a subset of rectangles using a shape atlas with 1 texture and then using the standard technique of passing the texture coordinates to the pixel shader for rendering. This worked OK, except that the strings in the center of the atlas shape did not look too good at all magnifications. For the program to be most useful, I need to be able to display the strings clearly. Generating the rectangle atlases from a canvas 2d, even at high resolutions, with the strings as part of the atlas rectangles, while quite straight forward to do, did not seem to render well at all magnifications. I looked into generating string atlases by themselves, which is fine, but it seems to me that I should be able to create an image atlas that can display pretty well at a reasonable number of magnifications including the text, and perhaps save a bunch of unique draw calls for simply generating the text using Signed Distance Fields.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is where I have hit a wall... I found a few places that reference the paper &quot;Improved Alpha-Tested Magnification for Vector Textures and Special Effects&quot;. It seems exactly what I am looking for. I think of my unique set of rectangle, text pairs as &quot;decals&quot; as outlined in the paper above. In my case, I would have all my unique instances generate a lower resolution SDF version (64x64) of a high resolution version (2048x2048) of the instances and then change my fragment shader to be able to render at any resolution as outlined here -&gt; Drawing Text with Signed Distance Fields in Mapbox GL. However, I have not found anywhere that shows how to generate a lower resolution version SDF from a high resolution image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My questions are the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;How do I generate a lower resolution SDF version (64x64) of a hi-res image (2048x2048) generated on the fly using canvas and JavaScript so I can create a texture to use in my fragment shader? Ideally, this would only have to be generated once at the start of the program.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Am I thinking about his correctly? Is the text doomed to have to be drawn by itself separately using an SDF font atlas?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6099" LastEditorUserId="231" LastEditDate="2017-02-21T17:06:23.563" LastActivityDate="2017-02-21T17:06:23.563" Title="Creating Signed Distance Fields Images On The Fly For WebGL Application" Tags="&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4741" PostTypeId="1" AcceptedAnswerId="4742" CreationDate="2017-02-21T00:47:10.527" Score="6" ViewCount="707" Body="&lt;p&gt;I have a (2d) region defined as a list of vertices that I'm currently drawing as a line loop in opengl. I want to draw this region solidly. I started by using triangle fan, but that doesn't work if the region has vertices positioned at the same angle (relative to the center) but different radii, because then that whole region is draw solid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I think I just need some general method to convert an enclosed spline/list of points into a triangle mesh. Maybe there's a better way?&lt;/p&gt;&#xA;" OwnerUserId="6100" LastActivityDate="2018-03-06T10:52:19.053" Title="Turn an enclosed region into a triangle mesh" Tags="&lt;opengl&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4742" PostTypeId="2" ParentId="4741" CreationDate="2017-02-21T01:25:21.483" Score="5" Body="&lt;p&gt;If the number of vertices is not too large, I would suggest looking into &quot;ear clipping&quot;. It's a straightforward method to triangulate possibly-concave polygons, as long as they don't have holes. However, it's $O(n^2)$ in the number of vertices, so may not a great choice if you need to handle a large number of verts. Dave Eberly has &lt;a href=&quot;https://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf&quot; rel=&quot;noreferrer&quot;&gt;a paper on ear clipping&lt;/a&gt; and also &lt;a href=&quot;https://www.geometrictools.com/Source/ComputationalGeometry.html&quot; rel=&quot;noreferrer&quot;&gt;an open-source implementation in C++&lt;/a&gt;. There are many other links available on the web, too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basic idea is to find an &quot;ear&quot; of the polygon, which is defined as a triangular subset of the polygon, formed by three consecutive vertices of the polygon. Once you find an ear, you add it to the output triangle list, and remove it from the original polygon (which reduces the number of vertices by one). Repeat this until the polygon is gone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason it's $O(n^2)$ is that you have to repeatedly search the list of vertices to find another ear to remove. There are more efficient triangulation algorithms as well, but they're more difficult to implement.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-02-21T01:25:21.483" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4743" PostTypeId="2" ParentId="4741" CreationDate="2017-02-21T12:16:05.027" Score="5" Body="&lt;p&gt;If your aim is just to fill the region and since you say you're using opengl, an alternative to Nathan's suggestion of using a triangulation algorithm&lt;sup&gt;++&lt;/sup&gt;, is to use the stencil buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming you want odd/even fill, clear the stencil buffer, dice up your polygon as before but have your triangles just (IIRC) invert the stencil. When all are sent, draw again but only where the stencil is non-zero. (It's been a while but I think you can clear the stencil buffer at the same time as this second pass to save time on the next complex polygon.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stencil buffer approach should also work with self-intersecting polygons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One final thing, I think it is more fill-efficient if you use a triangle strip rather than a fan when you chop up your polygon. You just need to access your vertices in something like  0, 1, N-1, 2, N-2 etc. order&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More information on the stencil buffer can be found in &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Stencil_Test&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Stencil Tests&lt;/a&gt; and in &lt;a href=&quot;http://www.glprogramming.com/red/chapter14.html#name13&quot; rel=&quot;nofollow noreferrer&quot;&gt;Drawing Filled, Concave Polygons Using the Stencil Buffer&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;++&lt;/sup&gt; Though, if you do want to use a triangulation algorithm but have a very large number of vertices, you could try Seidel's method as it's 'relatively' easy to implement but has &lt;em&gt;nearly&lt;/em&gt; O(n) time complexity. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However if you do a search for Seidel, note that the code in &lt;a href=&quot;http://www.cs.unc.edu/%7Edm/CODE/GEM/chapter.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Narkhede &amp;amp;&#xA;Manocha&lt;/a&gt; is &lt;em&gt;not&lt;/em&gt; actually Seidel's method as theirs is only O(n log n) not the faster O(n log* n) you should expect, where, if you're not familiar with it, &#xA;$$log^*n =\begin{cases}&#xA;1+ log^*(log(n))  &amp;amp; \text{if $n$ &amp;gt; 1} \\&#xA;0 &amp;amp; \text{otherwise}&#xA;\end{cases}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In &lt;em&gt;practical&lt;/em&gt; terms, you can consider it to be constant as it grows so slowly.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-03-06T10:52:19.053" LastActivityDate="2018-03-06T10:52:19.053" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4744" PostTypeId="1" AcceptedAnswerId="4746" CreationDate="2017-02-21T21:13:30.893" Score="4" ViewCount="431" Body="&lt;p&gt;I am starting to learn WebGL. Can a scene graph be stored in the GPU? Or is that type of thing more for the main thread (or webworker)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I want to calculate some layout, and apply it as a transform matrix. Can I keep track of a scene graph node in the GPU over time, and modify it's properties over time?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm just wondering because I know the GPU architecture is different. Do people normally do scene graph stuff outside the GPU? Can it be done in the GPU?&lt;/p&gt;&#xA;" OwnerUserId="4991" LastActivityDate="2017-02-22T08:13:08.287" Title="Can a scene graph be stored in the GPU?" Tags="&lt;transformations&gt;&lt;gpu&gt;&lt;webgl&gt;&lt;javascript&gt;&lt;scene-graph&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4746" PostTypeId="2" ParentId="4744" CreationDate="2017-02-22T00:06:54.373" Score="1" Body="&lt;p&gt;A gpu only cares about the full transform used for a particular object. It's much better that the CPU (webworker) collates the transformation hierarchy into a single matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you can do is use UBO and create a block where the final transform is stored and as you traverse the scenegraph update the data on the gpu. In the vertex shader you then index into it to get the data that applies to the vertexes. But you shouldn't store graph data in there only the final data needed for rendering.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-02-22T00:06:54.373" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4747" PostTypeId="2" ParentId="4741" CreationDate="2017-02-22T00:10:33.493" Score="4" Body="&lt;p&gt;Have you access to the OpenGL utility library? If so, you could use the tesselation functions from that. See this guide : &lt;a href=&quot;http://www.glprogramming.com/red/chapter11.html#name1&quot; rel=&quot;nofollow noreferrer&quot;&gt;Polygon Tessellation | OpenGL Programming Guide&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2941" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:56:52.873" LastActivityDate="2018-03-04T19:56:52.873" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4748" PostTypeId="1" AcceptedAnswerId="4750" CreationDate="2017-02-22T01:56:03.817" Score="14" ViewCount="1965" Body="&lt;p&gt;We know that in PNG,BMP,etc... the pixel value stored is not in the linear RGB space. But I found no document saying anything about the alpha channel. Is the alpha channel stored in image files in linear space or not?&lt;/p&gt;&#xA;" OwnerUserId="2448" LastActivityDate="2020-09-26T13:38:28.473" Title="Should the alpha channel be gamma corrected" Tags="&lt;gamma&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4749" PostTypeId="2" ParentId="4744" CreationDate="2017-02-22T02:08:18.270" Score="7" Body="&lt;p&gt;Short answer: Yes, It can be done. But no one does so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Long answer: &#xA;Scene graphs can be stored and processed on a GPU using OpenCL/WebCL. But it is not practical to do so. Updating scene graphs (a tree not in flat memory) on a GPU is slow, and processing it on a GPU is also slow (again, the tree is not in flat memory), while computing transformation matrices is cheap on a CPU. Thus no one is doing this.&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="48" LastEditDate="2017-02-22T08:13:08.287" LastActivityDate="2017-02-22T08:13:08.287" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4750" PostTypeId="2" ParentId="4748" CreationDate="2017-02-22T02:42:03.827" Score="13" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;We know that in PNG,BMP,etc... the pixel value stored is not in the linear RGB space.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is not necessarily true. You can store whatever color space you want into an image, it doesn't even need to be colors (such as normal maps).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The alpha channel is generally linear. The alpha channel doesn't get displayed, but it is generally a non-color term used for transparency (or whatever else). Because they don't need to display on a monitor, there's no reason to store in in gamma space. If you did, you would unnecessarily lose precision at the lower end of the alpha values. &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/3842/why-shouldnt-bump-normal-and-displacement-maps-be-gamma-corrected?rq=1&quot;&gt;Normals maps follow a similar line of reasoning, as explained very well by Julien Guertault&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-02-22T02:49:27.110" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4751" PostTypeId="5" CreationDate="2017-02-22T03:30:47.747" Score="0" Body="&lt;p&gt;The &lt;a href=&quot;https://www.khronos.org/vulkan/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Vulkan&lt;/a&gt; is a low-level, cross-platform graphics and compute API developed by the Khronos Group.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2017-02-22T13:39:57.570" LastActivityDate="2017-02-22T13:39:57.570" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4752" PostTypeId="4" CreationDate="2017-02-22T03:30:47.747" Score="0" Body="For questions about the Vulkan graphics/compute API." OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2017-02-22T13:39:49.013" LastActivityDate="2017-02-22T13:39:49.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4753" PostTypeId="1" AcceptedAnswerId="4756" CreationDate="2017-02-22T10:36:54.167" Score="5" ViewCount="251" Body="&lt;p&gt;As far as I understand, radiance is a measure of the &quot;intensity&quot; of light in a direction defined as a differential cone . It's measure is Flux per solid angle per projected area.  &lt;span class=&quot;math-container&quot;&gt;$L = \frac{d\Phi}{d\omega dA^\perp} = \frac{d\Phi}{d\omega dAcos(\theta)} $&lt;/span&gt;. Using this definition, it seems like as the &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; angle increases, radiance increases, thus light is somehow more &quot;intense&quot; in a direction nearly perpendicular to the normal at point p. This contradicts my intuition.&lt;br&gt;&#xA;Where am I interpreting this wrong?&lt;/p&gt;&#xA;" OwnerUserId="1831" LastEditorUserId="1831" LastEditDate="2018-12-08T18:12:51.800" LastActivityDate="2018-12-08T18:12:51.800" Title="Radiance at a nearly perpendicular angle is almost infinite?" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;radiosity&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="4755" PostTypeId="2" ParentId="4748" CreationDate="2017-02-22T15:26:51.890" Score="3" Body="&lt;p&gt;Image file formats themselves do not regard the gamma but store pixel values unmodified as the authoring program (e.g. Photoshop) decides to store the values, so RGB and alpha channels have no distinction from image file format point of view (barring potential lossy compression strategies, but that's another topic).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when you author images in Photoshop, they are displayed on the screen in sRGB space including the alpha channel, so if you author alpha channel relying that the perceived brightness of pixels represents transparency, then you can say that alpha is also stored in the gamma space. BUT, if you author alpha by using layer transparency in Photoshop, then the alpha is stored linearly (e.g. 50% transparent layer is stored as alpha=128).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in the end it depends how you author the data that in which space the data is stored and how you should interpret it. Also a thing to consider is if non-linear distribution of values gives you any precision benefits. Color values are stored in sRGB because human visual system responds logarithmically to light brightness, so it makes sense to have more details in darks than in brights to reduce perceived banding, but you could ask if such distribution would benefit say normal maps or roughness values stored in textures.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-02-22T15:36:13.627" LastActivityDate="2017-02-22T15:36:13.627" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4756" PostTypeId="2" ParentId="4753" CreationDate="2017-02-22T17:46:46.373" Score="4" Body="&lt;p&gt;It's only more intense if $d\phi$ remains constant. However, for light source with constant luminance the flux is a function of $cos(\theta)$, i.e. depends on the light's angle of incidence with the surface and cancels out the term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I feel the need to clarify this a bit because you say that:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;thus light is somehow more &quot;intense&quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's not that the &quot;light is somehow more intense&quot;, but rather that the light &lt;strong&gt;has to be&lt;/strong&gt; more intense to have same flux in grazing angles as when it's parallel to the surface. If you think of flux as particles hitting to this differential surface, the number of particles hitting the surface is smaller more perpendicular the light gets to the surface. So you have to throw more particles at the surface (i.e. increase the radiance) for the same flux until when the surface is completely perpendicular to the light, none of the particles hit the surface, thus the radiance goes to infinity.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-02-22T21:18:16.620" LastActivityDate="2017-02-22T21:18:16.620" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4757" PostTypeId="2" ParentId="4753" CreationDate="2017-02-22T18:45:00.967" Score="1" Body="&lt;p&gt;Remember radiance corresponds to a particular direction. When the equation is considering directions quasi parallel to the surface normal, the differential flux (the numerator) will typically be a much greater quantity than for grazing angles. The numerator is not remaining constant.&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2017-02-22T18:45:00.967" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4758" PostTypeId="1" CreationDate="2017-02-22T20:22:30.670" Score="1" ViewCount="120" Body="&lt;p&gt;My light mapper can generate soft shadows just fine - for each texel I cast a ray to the light, offset by some distribution of the 'area' of the light on disc. The problem is that I am casting many rays and that slows down production. I note that even for texels completely in shadow, I still cast 128 rays towards the light, but none of them hit it. This seems like a waste of effort. I imagine I could try to intersect a cone with the scene to reject cases when the texel is so deeply in shadow that multiple rays would be ineffective, but I currently only have a ray-tracer at my disposal, so before I go on I wanted to know if anyone has any good ideas. How can I accelerate the calculation of soft-shadows on the CPU?&lt;/p&gt;&#xA;" OwnerUserId="6001" LastActivityDate="2017-02-23T13:32:29.873" Title="Acceleration techniques for CPU soft-shadow calculation in light mapper" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4760" PostTypeId="1" CreationDate="2017-02-23T03:30:33.140" Score="3" ViewCount="954" Body="&lt;p&gt;I have drawn a cylinder and an icosahedron using OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I need to use the icosahedron and the open cylinder to build a structure motivated by crystal lattices, where I use an icosahedron for each atom and a cylinder to connect each 2 icosahedrons. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would have to use 12 icosahedrons for atoms and about 20 cylinders for the lines connecting the atoms, as I need to place them all to form the shape of an icosahedron itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there anybody that could give me any ideas regarding how to go about this? I can arrange 12 icosahedrons to simulate the 12 vertices of an icosahedron, but I'm not sure how to place all of the cylinders around properly.&lt;/p&gt;&#xA;" OwnerUserId="6097" LastEditorUserId="231" LastEditDate="2017-04-30T11:27:56.647" LastActivityDate="2017-11-28T12:20:27.940" Title="OpenGL - drawing icosahedrons and cylinders and combining them" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4761" PostTypeId="1" CreationDate="2017-02-23T04:39:04.937" Score="5" ViewCount="140" Body="&lt;p&gt;I often use a 2D Perlin noise texture to displace a grid in the vertex shader (e.g. terrain, ocean).  However, every time I google the method to calculate post-displacement normals there is a slight difference.  For example, the value to place in the Y-component varies depending on the source.  In this example, they place a '1' in the Y-component prior to normalization:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://software.intel.com/en-us/articles/real-time-parametric-shallow-wave-simulation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real-Time Parametric Shallow Wave Simulation | Intel® Software&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whereas in these codes, the value '2' is chosen:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.dian-xiang.com/blog/2&quot; rel=&quot;nofollow noreferrer&quot;&gt;Terrains, Normals, and a Heightmap | dian-xiang.com/blog&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What gives?  Is there a definitive source for calculating normals from a height map?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Might this be related to unprojecting mouse clicks?  It always bothered me that you could throw a '0.5' in the Z-component, as mrdoob mentioned here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/11036106/three-js-projector-and-ray-objects&quot;&gt;Three.js Projector and Ray objects | Stack Overflow&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or use a '1' in the Z-component as Anton does here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://antongerdelan.net/opengl/raycasting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mouse Picking with Ray Casting | Anton's OpenGL 4 Notes&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a connection between calculating normals from height maps and unprojecting mouse clicks?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second part of my question concerns choosing an epsilon to sample the height map.  Before I learned about height maps, I read about getting the normal from an implicit surface as in this link:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.iquilezles.org/www/articles/terrainmarching/terrainmarching.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fractals, computer graphics, mathematics, demoscene and more | Inigo Quilez Blog&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like the epsilon number is just made up though.  In my projects, I typically just fudge the value until it looks good.  Is there a definitive source, or at least a good rule of thumb?&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastEditorDisplayName="user7220" LastEditDate="2018-03-23T17:29:15.663" LastActivityDate="2018-03-23T17:29:15.663" Title="Correct post-displacement normal calculation (Y-component and epsilon)" Tags="&lt;mathematics&gt;&lt;real-time&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4762" PostTypeId="2" ParentId="4758" CreationDate="2017-02-23T13:32:29.873" Score="2" Body="&lt;p&gt;You could try to optimize the calculation by first casting a smaller number of &quot;feeler rays&quot; (say 32) to check for penumbra, and cast the remaining rays if the result is in penumbra according to the rays. Of course this can give you false negatives, but you could then try to improve the heuristics by checking the results of nearby feeler rays.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-02-23T13:32:29.873" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4763" PostTypeId="2" ParentId="81" CreationDate="2017-02-23T18:43:31.500" Score="3" Body="&lt;p&gt;To easily understand the 'dipole theory' we have first to understand from where it comes from the 'diffusion theory'.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And it comes from simulating light transport in participating media by solving the radiance transport equation (RTE).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The classical diffusion approximation solves the RTE by considering only a first-order spherical harmonic expansion of the radiance. If we further assume that the source function is a unit power isotropic point source in an infinite homogeneous medium we get to the classical diffusion Green's function (monopole).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When rendering translucent materials, it is convenient to re-formulate this problem in analogy to the local surface reflection integral. This results in an integral equation which computes the outgoing radiance, Lo, at position and direction as a convolution of the incident illumination, Li, and the BSSRDF, S, over all incident positions and directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now with Green's diffusion function we don't account for boundary conditions imposed by the material surfaces. These conditions can be simply handled by placing a mirrored negative source outside the medium for every positive source inside the medium such that the fluence is zeroed at an extrapolated distance above the surface. This is the dipole approximation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So without boundary conditions our fluence is expressed volumetrically within the medium. To render subsurface scattering we have to compute light leaving various points on the surface. For this to happen we have to compute diffusion profiles due to a dipole so to evaluate the directional derivative of the fluence in the direction of the surface normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Latest advancements on BSSRDF comes from shifting the initial volumetric and participating media approach with ad-hoc stuff that better takes into account surface boundary conditions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the ..&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;BSSRDF model still requires integrating over a radius of nearby points&#xA;  on the surface to gather incoming light .. ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, we integrate incident light togheter with the BSSRDF over all incident positions and directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we can adopt here a brute force method or a dart-throwing approach with russian rouletting. But they are both naive approaches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SSS came to production (Pixar Renderman) when an approximation method has been developed to use hierarchical light gathering using an octree data structure where to bake diffuse lighting to be available in clusters for SSS computation. With Renderman this was a natural approach because of REYES so that every micropoligon generated from REYES could be easily 'splatted' into a point and inserted into an octree.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A second wave of improvements relies on disk based importance sampling (Arnold) that is now the de-facto approach for many SSS implementations outthere. Generally we define a search volume (sphere), distribute samples on disk above the surface and probe along normal directions and orthogonal directions to find all hits inside the volume.&lt;/p&gt;&#xA;" OwnerUserId="6114" LastActivityDate="2017-02-23T18:43:31.500" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4764" PostTypeId="1" CreationDate="2017-02-24T00:14:57.873" Score="2" ViewCount="449" Body="&lt;p&gt;I'm building a 2D inverse kinematics system and can't figure out how to find all the joint positions. I have the math to make a typical IK set up with a single bend (e.g. arm, leg), but I get stuck when adding another bend.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How do I find the position of all joints for an inverse kinematic chain that is longer than 2 segments?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an example of the planar solution I'm looking for: &lt;a href=&quot;https://youtu.be/3sqd_CZNq7s?t=6s&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/3sqd_CZNq7s?t=6s&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm building this in Adobe After Effects so using an existing IK solver isn't going to work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my visual setup for reference:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/VoZwLCT.png&quot; alt=&quot;ik reference&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'm aiming for is that when the blue box is moved (target) joints 2 and 3 bend appropriately to maintain their length. Joint 1 is static and doesn't move.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make this work, I need x,y coordinates to be calculated in real time. No need to render anything on screen—just the position values for each joint.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my javascript so far:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var angle1, angle2, angle3, theta1, theta2, theta3, targetSqrDist;&#xA;&#xA;// joints&#xA;var joint1 = thisComp.layer(&quot;joint 1&quot;);&#xA;var joint2 = thisComp.layer(&quot;joint 2&quot;);&#xA;var joint3 = thisComp.layer(&quot;joint 3&quot;);&#xA;var joint4 = thisComp.layer(&quot;joint 4&quot;);&#xA;&#xA;// segment lengths&#xA;var segment1Len = length(joint2.transform.position, joint1.transform.position);&#xA;var segment2Len = length(joint3.transform.position, joint2.transform.position);&#xA;var segment3Len = length(joint4.transform.position, joint3.transform.position);&#xA;&#xA;// target position&#xA;var target = thisComp.layer(&quot;target&quot;);&#xA;var ix = target.transform.position[0] - joint1.transform.position[0];&#xA;var iy = target.transform.position[1] - joint1.transform.position[1];&#xA;&#xA;// target square distance&#xA;targetSqrDist = ix * ix + iy * iy;&#xA;&#xA;&#xA;// Segment 1&#xA;angle1 = Math.max(-1, Math.min( 1, &#xA;    (targetSqrDist + (segment1Len*segment1Len) - (segment2Len*segment2Len)) / (2 * segment1Len * Math.sqrt(targetSqrDist))&#xA;));&#xA;&#xA;theta1 = Math.atan2(iy, ix) - Math.acos(angle1);&#xA;&#xA;var s1X = joint1.transform.position[0] + segment1Len * Math.cos(theta1);&#xA;var s1Y = joint1.transform.position[1] + segment1Len * Math.sin(theta1);&#xA;&#xA;&#xA;// Segment 2&#xA;angle2 = Math.max(-1, Math.min( 1, &#xA;    (targetSqrDist - (segment1Len*segment1Len) - (segment2Len*segment2Len)) / (2 * segment1Len * segment2Len)&#xA;));&#xA;&#xA;theta2 = Math.acos(angle2);&#xA;&#xA;var s2X = s1X + segment2Len * Math.cos(theta2 + theta1);&#xA;var s2Y = s1Y + segment2Len * Math.sin(theta2 + theta1);&#xA;&#xA;&#xA;// Segment 3&#xA;angle3 = Math.max(-1, Math.min( 1, &#xA;    (targetSqrDist - (segment2Len*segment2Len) - (segment3Len*segment3Len)) / (2 * segment2Len * segment3Len)&#xA;));&#xA;&#xA;theta3 = Math.acos(angle3);&#xA;&#xA;var s3X = s2X + segment3Len * Math.cos(theta3 + theta2);&#xA;var s3Y = s2Y + segment3Len * Math.sin(theta3 + theta2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code would be applied to each joint with a unique position value assigned to it, depending on the joint's location.&lt;/p&gt;&#xA;" OwnerUserId="2076" LastEditorUserId="2076" LastEditDate="2017-03-01T18:57:24.860" LastActivityDate="2017-03-01T19:47:55.513" Title="Inverse Kinematics with more than 2 segments" Tags="&lt;animation&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4765" PostTypeId="2" ParentId="1736" CreationDate="2017-02-24T03:58:44.900" Score="5" Body="&lt;p&gt;I've generalized Everitt's results if that's needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VyA1o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VyA1o.png&quot; alt=&quot;generalized common frustum&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a bonus, a way to extract left0/right0 from the eyes perspective matrices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;left0   = n0 * (Mle13 - 1) / Mle11;&#xA;right1  = n1 * (Mre13 + 1) / Mre11;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you have row major. transpose for column major. c.f. &lt;a href=&quot;https://stackoverflow.com/a/12926655/893406&quot;&gt;this answer&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1614" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-02-27T03:52:47.363" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4766" PostTypeId="2" ParentId="4760" CreationDate="2017-02-24T04:13:10.053" Score="1" Body="&lt;p&gt;When drawing in OpenGL and related APIs you usually have one or more models. In your case, this would be the cylinder and the icosahedron. The models are generally generated at some default size which may or may not suit your needs for a particular task. You move them, scale them, and rotate them by setting up a model matrix which describes how you want to transform them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how would this work in your case? I recommend having 2 functions. One which draws a unit cylinder and another which draws a unit icosahedron. Say you have a data structure for your coordinates like this (I'm assuming a C-like language):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef struct Position3D {&#xA;    float x;&#xA;    float y;&#xA;    float z;&#xA;} Position3D;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can then construct a triangle by making a structure for one:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef struct Triangle3D {&#xA;    Position3D p0;&#xA;    Position3D p1;&#xA;    Position3D p2;&#xA;} Triangle3D;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then you'd have functions for generating the vertices you need. Something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void generateCylinder (Triangle3D* triangles) // &amp;lt;-assumes you allocated triangles before calling and that you have enough space for all of them!&#xA;{&#xA;    int i = 0;&#xA;    const float kRadius = 1.0;&#xA;    const float kDeltaH = 0.1; // &amp;lt;- change this to make the mesh more or less dense&#xA;    const float kDeltaAngle = M_PI / 10.0; // &amp;lt;- change this to make the mesh more or less curved&#xA;    for (float h = -1.0; h &amp;lt; 1.0; h += kDeltah)&#xA;    {&#xA;        for (float angle = 0; angle &amp;lt; 2.0 * M_PI; angle += kDeltaAngle)&#xA;        {&#xA;            float x = kRadius * cos(angle);&#xA;            float y = h;&#xA;            float z = kRadius * sin(angle);&#xA;            //... add points to triangles array here...&#xA;            // p0 = &amp;lt;x,y,z&amp;gt;&#xA;            // p1 = &amp;lt;x, y + kDeltaH, z&amp;gt;&#xA;            // p1 = &amp;lt;x + radius * cos(angle + kDeltaAngle), y, z  + radius * sin(angle + kDeltaAngle)&amp;gt;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And a similar function for the icosahedron. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, you'll create a matrix for every object you draw and send that to your shader before drawing it. So you'll have the translations for the vertices of the (big) icosahedron, and you want to draw a (small) icosahedron at each one. You'd do the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float translationMatrix [ 16 ] = {&#xA;    1, 0, 0, 0,&#xA;    0, 1, 0, 0,&#xA;    0, 0, 1, 0,&#xA;    0, 0, 0, 1&#xA;};&#xA;translationMatrix [ 12 ] = xPos;&#xA;translationMatrix [ 13 ] = yPos;&#xA;translationMatrix [ 14 ] = zPos;&#xA;GLuint modelMatrixLoc = glGetUniformLocation(program, &quot;modelMatrix&quot;);&#xA;glUniformMatrix4fv(modelMatrixLoc, 1, GL_FALSE, translationMatrix);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then you'd draw your icosahedron. For the cylinders you would need to scale vertically, rotate to the appropriate angle and translate it to the position between 2 icosahedrons.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-02-24T04:13:10.053" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4767" PostTypeId="1" AcceptedAnswerId="4769" CreationDate="2017-02-24T12:42:00.360" Score="4" ViewCount="986" Body="&lt;p&gt;I know the BRDF of specular reflection is nonzero only in the reflection direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But why it is infinite?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A paragraph on page 36 of &lt;a href=&quot;http://www.advancedglobalillumination.com/&quot; rel=&quot;noreferrer&quot;&gt;Advanced Global Illumination&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GQgcj.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GQgcj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="5944" LastEditDate="2017-02-24T13:36:15.887" LastActivityDate="2017-02-24T14:02:14.297" Title="Why the BRDF of specular reflection is infinite in the reflection direction?" Tags="&lt;rendering&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4768" PostTypeId="1" AcceptedAnswerId="4775" CreationDate="2017-02-24T13:31:18.200" Score="4" ViewCount="823" Body="&lt;p&gt;I'm reading &lt;a href=&quot;http://www.advancedglobalillumination.com/&quot; rel=&quot;noreferrer&quot;&gt;Advanced Global Illumination&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the part confusing me:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CDfwS.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CDfwS.png&quot; alt=&quot;Advanced Global Illumination 2nd Edition, page 34&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;What do the second equation and $\delta$-function mean?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Why the third equation is a sufficient condition even though a reason is given?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="5944" LastEditDate="2017-02-24T13:36:51.043" LastActivityDate="2017-02-25T19:49:27.607" Title="Energy conservation of BRDF" Tags="&lt;rendering&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4769" PostTypeId="2" ParentId="4767" CreationDate="2017-02-24T14:02:14.297" Score="6" Body="&lt;p&gt;In the BRDF curve, the total area under the curve is the albedo: what fraction of incident light is reflected in total (as opposed to being absorbed or transmitted). For a perfect reflector, the area under the curve sums to 1, because it reflects all of the incident light. This area limits how high the curve can be. For example, a &lt;em&gt;perfect&lt;/em&gt; diffuse reflector has a BRDF that's a flat line at $\frac{1}{2\pi}$, because it reflects the light evenly across the whole hemisphere, the solid angle of a hemisphere is $2\pi$, and the area has to be 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a &lt;em&gt;perfect&lt;/em&gt; specular reflector, the area under the curve is still 1: it still reflects all of the incident light. But this time, it's reflecting all of that light in one direction. The BRDF curve is a single spike. If you draw a graph with an infinitely thin spike, and the area under the graph has to be 1, then the spike must also be infinitely high. It's the only way to make the area correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously a real material can't be a &lt;em&gt;perfect&lt;/em&gt; specular reflector, so it will have two differences. First, the area under the curve will be less than 1,  because some light is absorbed. This doesn't matter much to us. More importantly, the reflection peak can't be infinitely thin: the reflection will be blurred ever so slightly. This means the peak won't be infinitely high: the wider the peak, the less high it has to be to still have an area of 1.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The remark about &quot;$\delta$-functions&quot; is because of a function (properly speaking, it's not a function but a &lt;em&gt;distribution&lt;/em&gt;) called the Dirac $\delta$ (delta). This distribution is an infinitely thin, infinitely tall spike at $x = 0$, whose area is 1, just like our perfect specular BRDF.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-02-24T14:02:14.297" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4771" PostTypeId="1" AcceptedAnswerId="4772" CreationDate="2017-02-24T21:25:29.627" Score="5" ViewCount="769" Body="&lt;p&gt;I'm trying to implement Cook-Torrance BRDF and had previously bookmarked &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4394/path-tracing-the-cook-torrance-brdf&quot;&gt;this question&lt;/a&gt; as it looked very well thought out. Going through it, I'm confused about the Fresnel equation. The author has the equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;F = c_{spec} + (1 - c_{spec}) (1 - \mathbf{w_i} \cdot \mathbf{h})^5 \tag{1}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and says &quot;&lt;em&gt;$c_{spec}$ is the specular color&lt;/em&gt;&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking elsewhere, I can see this equation is &lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick%27s_approximation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Schlick's approximation&lt;/a&gt;, but in other references, $c_{spec}$ is called $R_0$ and is $\left(\frac{n_1-n_2}{n_1+n_2}\right)^2$ which is clearly a number based upon refractive indices and &lt;strong&gt;not&lt;/strong&gt; a colour.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does equation $(1)$ make sense with colour?&lt;/p&gt;&#xA;" OwnerUserId="2941" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-02-24T23:52:37.747" Title="Fresnel and specular colour" Tags="&lt;brdf&gt;&lt;specular&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4772" PostTypeId="2" ParentId="4771" CreationDate="2017-02-24T23:52:37.747" Score="6" Body="&lt;p&gt;Yes, because refractive index can vary with wavelength. This is the origin of colored specular reflection in metals such as gold and copper; most other materials have essentially uncolored specular. At each wavelength, the specular reflectance at normal incidence is related to the refractive index at that wavelength according to the formula you mentioned.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case you're interested, the site &lt;a href=&quot;https://refractiveindex.info/&quot; rel=&quot;noreferrer&quot;&gt;refractiveindex.info&lt;/a&gt; has data tables and graphs of refractive index versus wavelength for various materials. For example, &lt;a href=&quot;https://refractiveindex.info/?shelf=main&amp;amp;book=Au&amp;amp;page=Johnson&quot; rel=&quot;noreferrer&quot;&gt;here's gold&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/XX9FC.png&quot; alt=&quot;refractive index of gold vs wavelength&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-02-24T23:52:37.747" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4774" PostTypeId="2" ParentId="4761" CreationDate="2017-02-25T14:37:15.800" Score="3" Body="&lt;p&gt;The Epsilon is chosen to hit the appropriated Nyquist-Frequency avoiding aliasing. It refers to the highest frequency in your heightfield function. You'll need well knowledge of the definition of your function to find it. For example, the figure shows an iterated Brownian motion (IBM) which approximate Perlin noise. The frequency of each added noise function is given by &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=2%5E%7Bi%7D&quot; alt=&quot;&quot;&gt;. So the Epsilon would be the last added frequency: &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Cfrac%7B1%7D%7B2%5E%7BN-1%7D%7D&quot; alt=&quot;\frac{1}{2^{N-1}}&quot;&gt;. That means the Epsilon is predefined for each Noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vhVN4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vhVN4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IBM by Hugo Elias approximating Perlin Noise.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Might this be related to unprojecting mouse clicks? It always bothered me that you could throw a '0.5' in the Z-component, as mrdoob mentioned here:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Your first question has nothing to do with mouse picking in my opinion. Your mouse is defined in normalized-device-coordinates (NDC) meaning a click in a window is ranging from -1 to 1 in each direction. The Z component is not given since our screen is just 2-dimensional, meaning we have to select a value from -1 to 1. -1 refers to the near plane and 1 to the far plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For further information on that topic: &#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=DLKN0jExRIM&amp;amp;t=371s&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=DLKN0jExRIM&amp;amp;t=371s&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6040" LastEditorUserId="6040" LastEditDate="2017-02-25T16:10:53.883" LastActivityDate="2017-02-25T16:10:53.883" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4775" PostTypeId="2" ParentId="4768" CreationDate="2017-02-25T17:31:52.827" Score="4" Body="&lt;p&gt;You are right to be confused. What I think they should have written:&#xA;$$&#xA;L( x \leftarrow \Psi ) = L_{in} \delta(\Psi - \alpha)&#xA;$$&#xA;using $ \alpha $ instead of $ \Theta $, which is already used as a dummy variable in the integral.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You should look up the Dirac delta function to learn its meaning and properties. In this context, you can imagine the $ L$ above as representing a very concentrated beam (a laser) coming from the angle $ \alpha $. Practically, to do the integral over $ \Psi $ with $ \delta (\Psi - \alpha) $ present in the integrand, remove the integration and replace all occurrences of $ \Psi $ with $ \alpha $. Then it should be clear how they arrive at the next line, which should read, for all $ \alpha $: $$ \int f_r(x, \alpha \rightarrow \Theta) \; \cos(N_x, \Theta)\; d \omega_\Theta \leq 1 $$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fact that this condition is sufficient follows from two facts: 1. that any function (e.g. $ L $) can be approximated by a sum of many $ \delta $ functions, and 2. that everything is linear. In other words, if I write $ N(L) $ and $ D(L) $ for the numerator and denominator of the left hand side of (2.21), then you can see that if $ L = L_1 + L_2 $, then $ N(L_1+L_2) = N(L_1) + N(L_2) $ and $ D(L_1+L_2) = D(L_1) + D(L_2) $. So if I know $ N(L_1) \leq D(L_1) $ and $ N(L_2) \leq D(L_2) $, then I know $ N(L) \leq D(L) $ since $$ N(L) = N(L_1) + N(L_2) \leq D(L_1) + D(L_2) = D(L) $$. &lt;/p&gt;&#xA;" OwnerUserId="6125" LastEditorUserId="6125" LastEditDate="2017-02-25T19:49:27.607" LastActivityDate="2017-02-25T19:49:27.607" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4777" PostTypeId="1" CreationDate="2017-02-25T20:29:55.600" Score="5" ViewCount="150" Body="&lt;p&gt;I understand that Fresnel tells us what percentage of light reflects vs refracts, but what law tells me the  percentage of refracted light that is transmitted versus the percentage of refracted light that is scattered back out as diffuse?&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastEditorUserId="2041" LastEditDate="2017-02-27T09:33:46.980" LastActivityDate="2017-02-27T09:33:46.980" Title="Equivalent of Fresnel law for determining transmitted/diffuse split" Tags="&lt;transparency&gt;&lt;diffuse&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4778" PostTypeId="1" AcceptedAnswerId="4779" CreationDate="2017-02-26T06:48:21.620" Score="1" ViewCount="716" Body="&lt;p&gt;Right now I am reading Peter Shirley's &lt;a href=&quot;http://rads.stackoverflow.com/amzn/click/B01B5AODD8&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing in One Weekend&lt;/a&gt; book, I want to be able to use the provided &lt;a href=&quot;https://github.com/petershirley/raytracinginoneweekend&quot; rel=&quot;nofollow noreferrer&quot;&gt;source code&lt;/a&gt; but I am not sure what platform or IDE it was written on, because of this it does not compile in Visual Studio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can somebody help me? Whenever I try compiling the code it asks me to 'attach to process'.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I get this working? In a few reviews I have read online it says that I'll need to do some tweaking to get it working but I honestly don't know how.&#xA;Would it mean rewriting the entire ray tracer as a Win32 Project? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-02-26T11:19:21.013" Title="How to get Ray Tracer working in Visual Studio" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4779" PostTypeId="2" ParentId="4778" CreationDate="2017-02-26T11:19:21.013" Score="3" Body="&lt;p&gt;No MakeFile or Visual Studio Solution file is provided. So you will need to do the setup yourself in the Visual Studio IDE. Note that you could just drag and drop the files (.h and .cc are known extensions to Visual Studio) in a new console application if you are not/less familiar with Visual Studio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code itself is just plain C++ code. No special stuff. So it does not matter which platform or IDE was used during development. In fact the code is pretty self containing except for&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;math.h&amp;gt;&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;#include &quot;float.h&quot; -&amp;gt; &amp;lt;float.h&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But if your Visual Studio is installed and configured correctly, every &lt;strong&gt;console&lt;/strong&gt; application can just include these headers without any problems. (Just try a basic &lt;code&gt;hello world&lt;/code&gt; &lt;strong&gt;console&lt;/strong&gt; application, since the problem has in my opinion nothing to do with the code you want to use.) Note that you need a &lt;strong&gt;Win32 Console application&lt;/strong&gt; and NOT a &lt;strong&gt;Win32 Project&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It could be possible that the pre-compiled header file is enabled (&lt;code&gt;StdAfx.h&lt;/code&gt; or &lt;code&gt;pch.h&lt;/code&gt;) in which case you could disable this or include the header as the first included header in every &lt;code&gt;.cpp&lt;/code&gt; file.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2017-02-26T11:19:21.013" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4780" PostTypeId="2" ParentId="4777" CreationDate="2017-02-26T19:38:06.853" Score="2" Body="&lt;p&gt;Physically, the origin of diffuse light is subsurface scattering, which happens continuously as light travels through a material. So, the proportion of transmitted light depends on the thickness of the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's no precise equivalent to the Fresnel law, but maybe the closest thing is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law&quot; rel=&quot;nofollow noreferrer&quot;&gt;Beer–Lambert law&lt;/a&gt;. It states that the transmitted light falls off exponentially with distance, proportional to $e^{-\sigma x}$, where $x$ is the distance the light has traveled through the material and $\sigma$ is the extinction coefficient (with units of inverse length). The non-transmitted portion of the light may be partly absorbed, and partly scattered through the material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You get the appearance of &quot;diffuse&quot; when typical length scale of scattering is smaller than you can see ($1/\sigma \ll  1\text{ pixel}$). Then the light gets scattered so many times in such a short distance that by the time it comes back out, its distribution looks isotropic (Lambertian). The apparent diffuse color is controlled by the wavelength-dependence of the scattering and attenuation coefficients.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the scattering length scale is larger, you get a soft appearance to the material (as in wax, marble, human skin, etc), or partial translucency.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-02-26T19:38:06.853" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4781" PostTypeId="1" AcceptedAnswerId="4795" CreationDate="2017-02-27T18:35:17.340" Score="3" ViewCount="185" Body="&lt;p&gt;I am interested in building a program to accomodate the following workflow:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A user begins with an arbitrary vector/CAD shape, which they wish to transfer onto paper without using a printer (there are both realistic and novelty reasons why this problem is interesting to me). The program will accept this file and create a list of instructions to draft the shape using ruler, square, compass, and standard curve forms. I am not currently concerned with the details of this program (file formats, types of vector curve [spline, bezier, etc], output formatting, etc) but with the core geometric description problem. I think it is fairly straightforward to accomplish this with straight lines, angles, and offsets.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I am not sure how to approach the problem of curve fitting. Ideally, the user would be able to have curves in the cad file fit (probably approximated) so that they may draft them using standard French curve forms, including:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P2YSE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P2YSE.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&#xA;Hip Curve&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DSB3q.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DSB3q.jpg&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&#xA;Vary form curve&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume that these curves are made to standard shapes and sizes and are modeled with dimensional accuracy. Furthermore, they are ruled at specific points and a user can place them on the paper diagram at specific positions and angles (relative to the other elements in the diagram that have already been drafted).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What would be the first steps towards solving this problem? Are there existant computational geometry methods for approximating curves with (segments and combinations of) standard forms? What literature would I want to read? I apologize for the somewhat open-ended nature of this question, but it's difficult for me to determine where to begin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it's helpful, the CAD patterns are probably such that the curves can, in fact, be very closely approximated with just one or two of these shapes - the primary use would be for fashion pattern drafting, and these French curves are specifically designed for creating the geometry of flat patterns that fit a human body.&lt;/p&gt;&#xA;" OwnerUserId="6136" LastActivityDate="2017-07-09T10:31:40.207" Title="First steps towards CAD standard curve fitting" Tags="&lt;computational-geometry&gt;&lt;line-drawing&gt;&lt;vector-graphics&gt;&lt;bezier-curve&gt;&lt;cad&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4785" PostTypeId="1" AcceptedAnswerId="4786" CreationDate="2017-02-28T13:50:00.070" Score="1" ViewCount="103" Body="&lt;p&gt;It's been a long time since I last used OpenGL and I can't figure out VAOs anymore... I want to make a simple voxel engine using geometry shaders. This is what I want to do: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;vbo1: array of GLfloat for the positions (3 floats per vertex)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vbo2: array of GLfloat for the size of the cube (1 float per vertex)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vbo3: array of GLbyte for the type of voxel (1 byte per vertex)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;-&gt; vao: GLfloat x, GLfloat y, GLfloat z, GLfloat size, GLbyte type&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    float *positions = new GLfloat[size * 3];&#xA;&#xA;    positions[0] = 0.5;&#xA;    positions[1] = 0.5;&#xA;    positions[2] = 0;&#xA;&#xA;    glGenBuffers(1, &amp;amp;positionsId);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, positionsId);&#xA;    glBufferData(GL_ARRAY_BUFFER, size * 3 * sizeof(GLfloat), positions, GL_STATIC_DRAW);&#xA;&#xA;    byte * voxelValues = new GLubyte[size];&#xA;&#xA;&#xA;    voxelValues[0] = 0;&#xA;&#xA;    glGenBuffers(1, &amp;amp;voxelValuesId);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, voxelValuesId);&#xA;    glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLubyte), voxelValues, GL_STATIC_DRAW);&#xA;&#xA;    float * sizes = new GLfloat[size];&#xA;&#xA;&#xA;    sizes[0] = 1;&#xA;&#xA;    glGenBuffers(1, &amp;amp;sizesId);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, sizesId);&#xA;    glBufferData(GL_ARRAY_BUFFER, size * sizeof(GLfloat), sizes, GL_STATIC_DRAW);&#xA;&#xA;    glGenVertexArrays(1, &amp;amp;vao);&#xA;&#xA;    glBindVertexArray(vao);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, positionsId);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, sizesId);&#xA;    glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, NULL);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, voxelValuesId);&#xA;    glVertexAttribPointer(2, 1, GL_UNSIGNED_BYTE, GL_FALSE, 0, NULL);&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glEnableVertexAttribArray(1);&#xA;    glEnableVertexAttribArray(2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is the code even doing what I want it to do? And is it even possible to use different datatypes in the vao? &lt;/p&gt;&#xA;" OwnerUserId="5476" LastActivityDate="2017-02-28T13:55:13.977" Title="Need help with VBO/VAO" Tags="&lt;opengl&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4786" PostTypeId="2" ParentId="4785" CreationDate="2017-02-28T13:55:13.977" Score="2" Body="&lt;p&gt;Look good to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And yes you can use different datatypes for different attributes in a vao, that's the entire point of having the type parameter there in the first place.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-02-28T13:55:13.977" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4787" PostTypeId="2" ParentId="4764" CreationDate="2017-03-01T09:30:44.637" Score="2" Body="&lt;p&gt;What you have here is an underconstrained problem*. To solve this problem you do what you do to any other underconstrained system. This is also why you mostly only see the 2 joint version as it is not underconstrained in the planar solution, and in any case the preregistration is trivial.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically you have 2 options:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Add more constraints&lt;/li&gt;&#xA;&lt;li&gt;Deal with the freedom&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Adding more constraints to the system reduces the degrees of freedom. For example if you only permit one of the joints to rotate about its z axis and the another around its x axis then y then you have reduced the problem to the same 2 member problem. Another way to constrain it is to force the orientation of the last link. This also reduces it to the same case as 2 links. But there are other meaningful ways to reduce complexity that depend on your application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OoFDT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OoFDT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Constraining one member reduces the problem to a 2 member problem. In the planar case that means 2 solutions (other in blue).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Dealing with the freedom just means that your answer is going to be a family of answers. Then you develop a way to choose the solution from that family. Letting the user adjust the parameter is equivalent to adding one more constraint. But there are other methods such as least squares, or energy methods that yield different results. Sky is the limit here. For example I have worked with robot controllers that decided the parameter based on what was the least amount of rotation on joints. The problem was that this wasn't entirely deterministic so over time the robot ended up doing things differently...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;* This is more suited to Engineering.SE but since IK is a common graphics problem lets deal with it here.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2017-03-01T19:47:55.513" LastActivityDate="2017-03-01T19:47:55.513" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4788" PostTypeId="1" CreationDate="2017-03-01T14:50:43.980" Score="2" ViewCount="96" Body="&lt;p&gt;I have 3 objects in my scene, each one is being passed to the buffer and drawn as part of a different Vertex Array Object, so for the 3 objects i have:&#xA;&lt;code&gt;vao1&lt;/code&gt;, &lt;code&gt;vao2&lt;/code&gt;, &lt;code&gt;vao3&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Object1&lt;/code&gt; is drawn using &lt;code&gt;glDrawElementsInstanced&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Object2&lt;/code&gt; is drawn using &lt;code&gt;glDrawElementsInstanced&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Object3&lt;/code&gt; is drawn using &lt;code&gt;glDrawArraysInstanced&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of those instances of all of those objects create one big object. So how can i take that big object (meaning - treat all 3 object as one) and draw it 5 times using instancing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="6097" LastActivityDate="2017-03-01T14:50:43.980" Title="OpenGL - how to draw instances of several objects?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4789" PostTypeId="2" ParentId="4737" CreationDate="2017-03-02T02:12:58.190" Score="1" Body="&lt;p&gt;To solve the problem, we will flow three steps, first, calculate translation matrix, second, calculate rotation matrix, third, get transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because translation is a &lt;em&gt;affine transformation&lt;/em&gt;, we need to use a 4x4 matrix to represent translation. I find you use column vector post-multiply matrix. the result of the translation matrix is same as yours.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Translation matrix = &lt;a href=&quot;https://i.stack.imgur.com/lk5Xn.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lk5Xn.gif&quot; alt=&quot;translation matrix&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, same as your idea, we use basis vectors(same as unit vectors of the coordinate axes) to calculate rotation matrix.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;basis &lt;strong&gt;z&lt;/strong&gt; vector: we can get rotated basis &lt;strong&gt;z&lt;/strong&gt; vector by using a vector from VRP to point A, and normalize it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;z&lt;/strong&gt; = &lt;strong&gt;b&lt;/strong&gt;(VRP) - &lt;strong&gt;a&lt;/strong&gt; = [5,-2,1] - [1,1,1] = [4,-3,0] ,then, normalize to [0.8,-0.6,0]&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;basis &lt;strong&gt;x&lt;/strong&gt; vector: we know basis vector is a vector perpendicular to &lt;strong&gt;z-up&lt;/strong&gt; plane, we get the &lt;strong&gt;x&lt;/strong&gt; vector by cross product &lt;strong&gt;up&lt;/strong&gt; and &lt;strong&gt;z&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;x&lt;/strong&gt; = &lt;strong&gt;up&lt;/strong&gt; x &lt;strong&gt;z&lt;/strong&gt; = [1,1,1] x [0.8 ,-0.6 ,0] = [0.6, 0.8, 0]&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;basis &lt;strong&gt;y&lt;/strong&gt; vector, &lt;strong&gt;y&lt;/strong&gt; is prependicular to &lt;strong&gt;z-x&lt;/strong&gt; plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;y&lt;/strong&gt; = &lt;strong&gt;z&lt;/strong&gt; x &lt;strong&gt;x&lt;/strong&gt; = [0.8 ,-0.6, 0] x [0.6, 0.8, 0] = [0, 0, 1]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;finally, the rotation matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rotation Matrix = &#xA;   &lt;a href=&quot;https://i.stack.imgur.com/gmygD.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gmygD.gif&quot; alt=&quot;rotation matrix&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 4x4 matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Transformation matrix = &lt;a href=&quot;https://i.stack.imgur.com/8ue8L.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8ue8L.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The transformation matrix is a matrix from &lt;em&gt;Object Space&lt;/em&gt; to &lt;em&gt;World Space&lt;/em&gt;, we should invert this matrix to get &lt;em&gt;World Space&lt;/em&gt; to &lt;em&gt;Camera Space&lt;/em&gt; matrix.(Thanks for @JarkkoL correcting me).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Refer to &lt;a href=&quot;https://tfetimes.com/wp-content/uploads/2015/04/F.Dunn-I.Parberry-3D-Math-Primer-for-Graphics-and-Game-Development.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;3D Math Primer for Graphics and Game Developmen&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Following your request for clarification: I just combine the translation matrix and the rotation matrix, actually, It's the result translation matrix(T) multiply rotation matrix(R). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rotation is a 3x3 matrix, we can extend the matrix to a 4x4 matrix with adding a dimension, the 4x4 rotation matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QOZur.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QOZur.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the translation matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/l3FFz.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/l3FFz.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, now we can calculate the transform matrix by translation matrix multiply(T) rotation matrix(R):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cause the matrix multiply formula is too big for the 4x4 matrix, we just look at the 1st row, In the transform matrix(M), the M11 element equals to T11*R11+T12*R21+T13*R31+T14*R41, cause T12, T13, R41 is 0, so, the M11 equals to R11 right? And in the same way, M14 equals to T11*R14+T12*R24+T13*R34+T14*R44, only R44 equals to 1, so, the M14 equals to T14. so, I just simply put them together in my last answer. For the reason why we put the translation matrix on the left, you can check on the book that I gave you in my previous answer on page 91(translating first and then rotating).&lt;/p&gt;&#xA;" OwnerUserId="6140" LastEditorUserId="231" LastEditDate="2017-08-05T21:28:41.683" LastActivityDate="2017-08-05T21:28:41.683" CommentCount="11" ContentLicense="CC BY-SA 3.0" />
  <row Id="4791" PostTypeId="1" CreationDate="2017-03-02T14:21:09.160" Score="2" ViewCount="155" Body="&lt;p&gt;Having taken a basic CG course, I remember that transformations are relative, so rotating the camera is identical to rotating the view in the opposite direction. Right now I want to implement camera rotation using the mouse. In OpenGL, I can see the family of functions called &lt;code&gt;lookAt()&lt;/code&gt; as implemented by the various libraries. However, those take vectors for camera positions. I feel it is incorrect to calculate the vector for camera position when we can rotate the world with a matrix transformation, e.g. using quaternions (as implemented handily by Qt5 or GLM). Thus, is it a correct and adopted solution to apply a transformation to the &lt;code&gt;model&lt;/code&gt; matrix as opposed to the &lt;code&gt;view&lt;/code&gt; matrix in the following line of code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_Position = proj * view * model * vec4(position, 0.0, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;ref. &lt;a href=&quot;https://open.gl/transformations&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://open.gl/transformations&lt;/a&gt;, subsection &quot;&lt;em&gt;Going 3D&lt;/em&gt;&quot;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, should I rather apply a rotation transformation as defined by a matrix received using quaternion algebra analogous to the solution above, but, this time around, to the matrix position vector? Will those be identical? (My common sense tells me they will only be identical if the camera is pointing to 0 and the object is located at point 0 - but I lack the required knowledge about transformations yet.)&lt;/p&gt;&#xA;" OwnerUserId="6157" LastActivityDate="2017-03-02T14:21:09.160" Title="With OpenGL, is it correct to apply model transformation to rotate the camera?" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;glm&gt;&lt;camera-matrix&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4792" PostTypeId="1" AcceptedAnswerId="4811" CreationDate="2017-03-02T16:13:49.933" Score="7" ViewCount="858" Body="&lt;p&gt;I've got my path tracer working great for a single light, but I'm having trouble coming up with a solution for scenes with multiple lights. My first thought was to just send a ray to each light and sum up all the contributions. That worked fine, but it was very slow, especially for many lights. I tried researching techniques for working around this, but I found very little. I did find that some renderers weight each light and then pick one based on how much light they might contribute, but I couldn't find any detailed process of how that's actually done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is, could someone give me an overview of how this might be accomplished, or point me to a resource that goes over multiple lights? &lt;/p&gt;&#xA;" OwnerUserId="5764" LastEditorUserId="231" LastEditDate="2017-03-13T00:56:06.863" LastActivityDate="2021-03-15T20:20:27.937" Title="Path Tracing With Multiple Lights" Tags="&lt;lighting&gt;&lt;pathtracing&gt;&lt;sampling&gt;&lt;monte-carlo&gt;&lt;render&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4793" PostTypeId="1" CreationDate="2017-03-02T19:02:11.807" Score="7" ViewCount="3224" Body="&lt;p&gt;This question has an answer here:&lt;br /&gt;&#xA;&lt;a href=&quot;https://stackoverflow.com/questions/42596516/generating-mipmaps-manually&quot;&gt;https://stackoverflow.com/questions/42596516/generating-mipmaps-manually&lt;/a&gt;&lt;br /&gt;&#xA;It was a silly mistake. Sorry for the inconvenience.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL is fairly difficult to learn.&lt;br /&gt;&#xA;According to my understanding of mipmaps, I can set each mipmap level manually, so I could change the image to use when my texture looks greater or smaller.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried the following code but doesn't matter the size of the triangle, it always take the first mipmap level.&#xA;Why?&#xA;if the triangle is closer to any other mipmap level, why does not take it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I really hate putting a bunch of code in my questions because I force others to waste time analyzing the code instead of putting the most revelant snippet code, but I don't know where is the problem and I have not alternative. Sorry :(&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&#xA;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;#define GLEW_STATIC&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;&#xA;#include &amp;lt;GLFW/glfw3.h&amp;gt;&#xA;&#xA;const GLchar* VERTEX_SHADER_SOURCE =&#xA;        &quot;#version 330 core                           \n&quot;&#xA;        &quot;layout (location = 0) in vec2 position;     \n&quot;&#xA;        &quot;layout (location = 1) in vec2 myTexCoord;   \n&quot;&#xA;        &quot;                                            \n&quot;&#xA;        &quot;out vec2 TexCoord;                          \n&quot;&#xA;        &quot;                                            \n&quot;&#xA;        &quot;void main()                                 \n&quot;&#xA;        &quot;{                                           \n&quot;&#xA;        &quot;    gl_Position = vec4(position,0.0f, 1.0f);\n&quot;&#xA;        &quot;    TexCoord = myTexCoord;                  \n&quot;&#xA;        &quot;}                                           \n&quot;;&#xA;&#xA;const GLchar* FRAGMENT_SHADER_SOURCE =&#xA;        &quot;#version 330 core                         \n&quot;&#xA;        &quot;in vec2 TexCoord;                         \n&quot;&#xA;        &quot;                                          \n&quot;&#xA;        &quot;out vec4 color;                           \n&quot;&#xA;        &quot;                                          \n&quot;&#xA;        &quot;uniform sampler2D ourTexture;             \n&quot;&#xA;        &quot;                                          \n&quot;&#xA;        &quot;void main()                               \n&quot;&#xA;        &quot;{                                         \n&quot;&#xA;        &quot;    color = texture(ourTexture, TexCoord);\n&quot;&#xA;        &quot;}                                         \n&quot;;&#xA;&#xA;int main()&#xA;{&#xA;    //INIT STUFFS&#xA;    glfwInit();&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);&#xA;    GLFWwindow* window = glfwCreateWindow(800, 600, &quot;&quot;, nullptr, nullptr);&#xA;    glfwMakeContextCurrent(window);&#xA;    glewExperimental = GL_TRUE;&#xA;    glewInit();&#xA;    glViewport(0, 0, 800, 600);&#xA;&#xA;&#xA;&#xA;    //THE MOST INTERESTING PART&#xA;    GLuint texture;&#xA;    glGenTextures(1, &amp;texture);&#xA;    glBindTexture(GL_TEXTURE_2D, texture);&#xA;&#xA;    //Our image for the mipmap with level 0 and white color&#xA;    //The dimensions are 200 x 200 and is multiplied by 3 because I defined R,G and B colors&#xA;    unsigned char imageArray[200*200*3];&#xA;    for(int i = 0; i &amp;lt; 200*200*3; i++){&#xA;        imageArray[i] = 255;&#xA;    }&#xA;&#xA;    //Our image for the mipmap with level 1-8 and blue color&#xA;    unsigned char imageArray2[100*100*3];&#xA;    for(int i = 0; i &amp;lt; 100*100*3; i++){&#xA;        if((i+1)%3 == 0)&#xA;            imageArray2[i] = 255;&#xA;        else&#xA;            imageArray2[i] = 0;&#xA;    }&#xA;&#xA;    //All mipmap levels&#xA;    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 200, 200, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);&#xA;    glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 100, 100, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, 50,  50,  0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, 25,  25,  0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB, 13,  13,  0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB, 7,   7,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 4,   4,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 7, GL_RGB, 2,   2,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 8, GL_RGB, 1,   1,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;    //If I comment the line above and uncomment the following, the program will show a black triangle. Why?&#xA;    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;&#xA;    GLfloat vertices[] =&#xA;    //(un)comment the first and second lines of vertex coords to swap between a bigger or smaller triangle&#xA;    //It doesn't matter, this program always take the first mipmap level&#xA;    //But... Why? the triangle should be closer to any other mipmap level :( why does not take it?&#xA;    {&#xA;//          -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 1.0f,      //Bigger triangle&#xA;            -0.05f, -0.05f, 0.05f, -0.05f, 0.0f, 0.05f, //Smaller triangle&#xA;            -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 1.0f       //Triangle's texture coordinates&#xA;    };&#xA;&#xA;&#xA;&#xA;    //VAOs AND VBOs&#xA;    GLuint VAO, VBO;&#xA;    glGenVertexArrays(1, &amp;VAO);&#xA;    glGenBuffers(1, &amp;VBO);&#xA;    glBindVertexArray(VAO);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&#xA;    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0);&#xA;    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat)*3*2));&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glEnableVertexAttribArray(1);&#xA;&#xA;&#xA;&#xA;    //SHADERS&#xA;    GLuint program;&#xA;    GLuint vertex, fragment;&#xA;&#xA;    vertex = glCreateShader(GL_VERTEX_SHADER);&#xA;    glShaderSource(vertex, 1, &amp;VERTEX_SHADER_SOURCE, NULL);&#xA;    glCompileShader(vertex);&#xA;&#xA;    fragment = glCreateShader(GL_FRAGMENT_SHADER);&#xA;    glShaderSource(fragment, 1, &amp;FRAGMENT_SHADER_SOURCE, NULL);&#xA;    glCompileShader(fragment);&#xA;&#xA;    program = glCreateProgram();&#xA;    glAttachShader(program, vertex);&#xA;    glAttachShader(program, fragment);&#xA;    glLinkProgram(program);&#xA;&#xA;    glDeleteShader(vertex);&#xA;    glDeleteShader(fragment);&#xA;    glUseProgram(program);&#xA;&#xA;&#xA;&#xA;    //DRAWING OUR TRIANGLE&#xA;    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    glDrawArrays(GL_TRIANGLES, 0,3);&#xA;    glfwSwapBuffers(window);&#xA;    while (!glfwWindowShouldClose(window))&#xA;        glfwPollEvents();&#xA;&#xA;&#xA;&#xA;    glDeleteVertexArrays(1, &amp;VAO);&#xA;    glDeleteBuffers(1, &amp;VBO);&#xA;    glfwTerminate();&#xA;    return 0;&#xA;}&#xA;&#xA;&lt;/code&gt;&#xA;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For any reason, these two lines doesn't work together&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;h1&gt;EDIT:&lt;/h1&gt;&lt;/strong&gt; I think that the two lines above doesn't work because mipmaps only works with GL_TEXTURE_MIN_FILTER. However, when I replace&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;//If I comment the line above and uncomment the following, the program will show a black triangle. Why?&#xA;//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;it shows a black triangle :(&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used glGetError as Dan Hulme stated in the comments but with the last change I made to my code I have not errors returned by glGetError but still showing a black triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;h1&gt;EDIT 2:&lt;/h1&gt;&lt;/strong&gt; I solved the problem setting the sizes by powers of 2. However, it now takes only the first mipmap level. Here is the new source code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&#xA;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;#define GLEW_STATIC&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;&#xA;#include &amp;lt;GLFW/glfw3.h&amp;gt;&#xA;&#xA;const GLchar* VERTEX_SHADER_SOURCE =&#xA;        &quot;#version 330 core                           \n&quot;&#xA;        &quot;layout (location = 0) in vec2 position;     \n&quot;&#xA;        &quot;layout (location = 1) in vec2 myTexCoord;   \n&quot;&#xA;        &quot;                                            \n&quot;&#xA;        &quot;out vec2 TexCoord;                          \n&quot;&#xA;        &quot;                                            \n&quot;&#xA;        &quot;void main()                                 \n&quot;&#xA;        &quot;{                                           \n&quot;&#xA;        &quot;    gl_Position = vec4(position,0.0f, 1.0f);\n&quot;&#xA;        &quot;    TexCoord = myTexCoord;                  \n&quot;&#xA;        &quot;}                                           \n&quot;;&#xA;&#xA;const GLchar* FRAGMENT_SHADER_SOURCE =&#xA;        &quot;#version 330 core                         \n&quot;&#xA;        &quot;in vec2 TexCoord;                         \n&quot;&#xA;        &quot;                                          \n&quot;&#xA;        &quot;out vec4 color;                           \n&quot;&#xA;        &quot;                                          \n&quot;&#xA;        &quot;uniform sampler2D ourTexture;             \n&quot;&#xA;        &quot;                                          \n&quot;&#xA;        &quot;void main()                               \n&quot;&#xA;        &quot;{                                         \n&quot;&#xA;        &quot;    color = texture(ourTexture, TexCoord);\n&quot;&#xA;        &quot;}                                         \n&quot;;&#xA;&#xA;int main()&#xA;{&#xA;    //Change the value of size by 1,2,4,8,16,32,64,128 or 256 and see how the color of the triangle doesn't change. Why does it happen?&#xA;    GLint size = 128;&#xA;&#xA;    //INIT STUFFS&#xA;    glfwInit();&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);&#xA;    GLFWwindow* window = glfwCreateWindow(size,size, &quot;&quot;, nullptr, nullptr);&#xA;    glfwMakeContextCurrent(window);&#xA;    glewExperimental = GL_TRUE;&#xA;    glewInit();&#xA;    glViewport(0, 0,size,size);&#xA;&#xA;&#xA;&#xA;    GLuint texture;&#xA;    glGenTextures(1, &amp;texture);&#xA;    glBindTexture(GL_TEXTURE_2D, texture);&#xA;&#xA;    //Our image for the mipmap with odd level and green color&#xA;    //The dimensions are 256 x 256 and is multiplied by 3 because I defined R,G and B colors&#xA;    unsigned char imageArray[256*256*3];&#xA;    for(int i = 0; i &amp;lt; 256*256*3; i++){&#xA;        if((i+2)%3 == 0)&#xA;            imageArray[i] = 255;&#xA;        else&#xA;            imageArray[i] = 0;&#xA;    }&#xA;&#xA;    //Our image for the mipmap with pair level and red color&#xA;    unsigned char imageArray2[256*256*3];&#xA;    for(int i = 0; i &amp;lt; 256*256*3; i++){&#xA;        if(i%3 == 0)&#xA;            imageArray2[i] = 255;&#xA;        else&#xA;            imageArray2[i] = 0;&#xA;    }&#xA;&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 8);&#xA;&#xA;    //All mipmap levels defined by hand&#xA;    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);&#xA;    glTexImage2D(GL_TEXTURE_2D, 1, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 2, GL_RGB, 64,  64,  0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);&#xA;    glTexImage2D(GL_TEXTURE_2D, 3, GL_RGB, 32,  32,  0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 4, GL_RGB, 16,  16,  0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);&#xA;    glTexImage2D(GL_TEXTURE_2D, 5, GL_RGB, 8,   8,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 6, GL_RGB, 4,   4,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);&#xA;    glTexImage2D(GL_TEXTURE_2D, 7, GL_RGB, 2,   2,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray2);&#xA;    glTexImage2D(GL_TEXTURE_2D, 8, GL_RGB, 1,   1,   0, GL_RGB, GL_UNSIGNED_BYTE, imageArray);&#xA;&#xA;    GLfloat vertices[] = {&#xA;            -1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 1.0f,  //vertex coordinates&#xA;            0.0f, 0.0f                              //Triangle's texture coordinates&#xA;    };&#xA;&#xA;&#xA;&#xA;    //VAOs AND VBOs&#xA;    GLuint VAO, VBO;&#xA;    glGenVertexArrays(1, &amp;VAO);&#xA;    glGenBuffers(1, &amp;VBO);&#xA;    glBindVertexArray(VAO);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&#xA;    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)0);&#xA;    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(GLfloat), (GLvoid*)(sizeof(GLfloat)*3*2));&#xA;&#xA;    glEnableVertexAttribArray(0);&#xA;    glEnableVertexAttribArray(1);&#xA;&#xA;&#xA;&#xA;    //SHADERS&#xA;    GLuint program;&#xA;    GLuint vertex, fragment;&#xA;&#xA;    vertex = glCreateShader(GL_VERTEX_SHADER);&#xA;    glShaderSource(vertex, 1, &amp;VERTEX_SHADER_SOURCE, NULL);&#xA;    glCompileShader(vertex);&#xA;&#xA;    fragment = glCreateShader(GL_FRAGMENT_SHADER);&#xA;    glShaderSource(fragment, 1, &amp;FRAGMENT_SHADER_SOURCE, NULL);&#xA;    glCompileShader(fragment);&#xA;&#xA;    program = glCreateProgram();&#xA;    glAttachShader(program, vertex);&#xA;    glAttachShader(program, fragment);&#xA;    glLinkProgram(program);&#xA;&#xA;    glDeleteShader(vertex);&#xA;    glDeleteShader(fragment);&#xA;    glUseProgram(program);&#xA;&#xA;&#xA;&#xA;    //DRAWING OUR TRIANGLE&#xA;    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    glDrawArrays(GL_TRIANGLES, 0,3);&#xA;    glfwSwapBuffers(window);&#xA;    while (!glfwWindowShouldClose(window))&#xA;        glfwPollEvents();&#xA;&#xA;&#xA;&#xA;    glDeleteVertexArrays(1, &amp;VAO);&#xA;    glDeleteBuffers(1, &amp;VBO);&#xA;    glfwTerminate();&#xA;    return 0;&#xA;}&#xA;&#xA;&lt;/code&gt;&#xA;&lt;/pre&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="5852" LastEditDate="2017-07-08T19:19:46.010" LastActivityDate="2020-07-02T12:09:04.983" Title="How can I generate mipmaps manually?" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4794" PostTypeId="1" AcceptedAnswerId="4797" CreationDate="2017-03-02T20:13:40.953" Score="2" ViewCount="1168" Body="&lt;p&gt;Nearest interpolation between 2 texels means to take the texel whose center is nearest to a given coordinate to draw or, in other words, the texel the coordinate is matching.&lt;/p&gt;&#xA;&lt;p&gt;Linear interpolation between 2 texels means to mix the colors of them using more of the nearest texel and less of the others according to the distance to a certain coordinate.&lt;/p&gt;&#xA;&lt;p&gt;Nearest interpolation between 2 mipmap levels consist in taking the mipmap whose size fits better the size of the image to draw&lt;/p&gt;&#xA;&lt;p&gt;But I cannot understand how linear interpolation works with mipmap levels.&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="5852" LastEditDate="2021-01-12T11:53:56.443" LastActivityDate="2021-01-12T11:53:56.443" Title="How linear interpolation works between mipmaps?" Tags="&lt;opengl&gt;&lt;image-processing&gt;&lt;image&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="4795" PostTypeId="2" ParentId="4781" CreationDate="2017-03-02T22:42:02.590" Score="2" Body="&lt;p&gt;Since you have a limited set of tools you are not actually doing a classical fitting. What you have is a discrete problem. And since you are looking for a somewhat easily drawn fit, no more than twice segmented for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to approach this is to find all the points that match your curvature requirements. Then find the point x units away from point on both ends for all of these and see how well it matches. If the curvature match at the endpoint is too much off then this isn't a good candidate. If you don't find a good candidate split the problem into two. Once you have found a goodish candidate slide the result to see if relaxing the thing makes the error more symmetric.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some things to note. Since your french curve is accelerating from one end to another you need to split beziers and b-splines at each span where the curve changes direction. Also once you've found good endpoints be sure to check that the halfway isn't too much off.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you want to do a classical fitting like approach then you need to parametrize the sliding and scale of your curve. This is not likely useful since you in fact can not scale your rules at whim.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or then you could just get a spline, you know one of those things that were used before computers and stuff, and write instructions on how to set up the spline.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2017-04-30T11:21:30.250" LastActivityDate="2017-04-30T11:21:30.250" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4796" PostTypeId="2" ParentId="4682" CreationDate="2017-03-02T23:21:24.430" Score="3" Body="&lt;p&gt;If I understand the general idea correctly, you are going to close the gaps which are appearing after further structure growth. I cannot do it algorithmically but geometrically it is quite easy to do. I use Illustrator here and manually cover the gaps with two additional shapes.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in addition to the pentagon and flat rhombus, I will need a 5-fold star and another rhombus:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5J0CX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5J0CX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So after first steps we get such a structure and the filling will be:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xjcoj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xjcoj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Initial center is marked red)  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't fill all holes and I leave out the obvious ones just to make arrangements more visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then next step will give this:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/d75He.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d75He.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here I do only halves of crack fillings, those are symmetrical. As seen those cracks indeed can be covered using same shapes without gaps and have self-similar patterns. How this can be achieved algorithmically, I don't know unfortunatelly. But this is interesting question, probably there are solutions somewhere, IDK.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Theoretically if one analyse several crack fillings for each step, one can guess a relatively&#xA;simple algorithm.&lt;/p&gt;&#xA;" OwnerUserId="6160" LastActivityDate="2017-03-02T23:21:24.430" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4797" PostTypeId="2" ParentId="4794" CreationDate="2017-03-02T23:52:29.450" Score="4" Body="&lt;p&gt;It's called &lt;a href=&quot;https://en.wikipedia.org/wiki/Trilinear_interpolation&quot; rel=&quot;noreferrer&quot;&gt;trilinear interpolation&lt;/a&gt;. You first do a bilinear interpolation of the higher-res texture, then do a bilinear interpolation on the lower-res texture, then interpolate between the 2 results. The weight of the final interpolation is based on where between the 2 textures your Z-coordinate falls. If 0 is fully the low-res texture and 1 is fully the high-res texture, then you can use the standard glsl &lt;code&gt;mix()&lt;/code&gt; function to combine the two:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;result = (highres texture color * weight) + (lowres texture color * (1.0 - weight));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-03-02T23:52:29.450" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4798" PostTypeId="1" CreationDate="2017-03-03T05:44:19.293" Score="3" ViewCount="396" Body="&lt;p&gt;Recently, I am writing a simple software rasterizer for self-studying and fun. But the texture mapping has problems. The texture I want to map is below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8xj8w.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8xj8w.png&quot; alt=&quot;Texture&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But the final image of two triangles is problematic, it shows below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lqNhi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lqNhi.png&quot; alt=&quot;final image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The triangle rasterizing algorithm I use is the Triangle barycentric coordinates interpolation. It seems the mapping of second triangle is not correct. My code is below, As the code shows, the three vertices of the triangle is, p1, p2, p3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope someone can help me to fix the problem. Thanks very much!&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (mRenderState &amp;amp; (RENDERING_TEXTURE | RENDERING_COLOR))&#xA;{&#xA;    int x0 = p1.x();&#xA;    int x1 = p2.x();&#xA;    int x2 = p3.x();&#xA;    int y0 = p1.y();&#xA;    int y1 = p2.y();&#xA;    int y2 = p3.y();&#xA;&#xA;    //Firstly build the bounding box&#xA;    int xMin = std::min(x0, std::min(x1, x2));&#xA;    int xMax = std::max(x0, std::max(x1, x2));&#xA;    int yMin = std::min(y0, std::min(y1, y2));&#xA;    int yMax = std::max(y0, std::max(y1, y2));&#xA;&#xA;    // Triangle setup.&#xA;    // Compute the edge equation coefficients.&#xA;    float edge_a_0 = -(y1 - y0);&#xA;    float edge_a_1 = -(y2 - y1);&#xA;    float edge_a_2 = -(y0 - y2);&#xA;&#xA;    float edge_b_0 =   x1 - x0;&#xA;    float edge_b_1 =   x2 - x1;&#xA;    float edge_b_2 =   x0 - x2;&#xA;&#xA;    float edge_c_0 = edge_a_0 * -x0 + edge_b_0 * -y0;&#xA;    float edge_c_1 = edge_a_1 * -x1 + edge_b_1 * -y1;&#xA;    float edge_c_2 = edge_a_2 * -x2 + edge_b_2 * -y2;&#xA;&#xA;    // Triangle area and inverse area&#xA;    float area = 0.5f * ((x1 - x0) * (y2 - y0) - (y1 - y0) * (x2 - x0));&#xA;    float inv2Area = 1.f / (2.f * area);&#xA;&#xA;    // Check the triangle is backfacing.&#xA;    if (area &amp;lt;= 0.)&#xA;        return;&#xA;&#xA;    // Loop over the bounding box of the pixels that the triangle possibly&#xA;    // covers.&#xA;    int py;&#xA;    int px;&#xA;    for (int py = yMin; py &amp;lt; yMax; ++py)&#xA;    for (int px = xMin; px &amp;lt; xMax; ++px)&#xA;    {&#xA;        float e0 = edge_a_0 * px + edge_b_0 * py + edge_c_0;&#xA;        float e1 = edge_a_1 * px + edge_b_1 * py + edge_c_1;&#xA;        float e2 = edge_a_2 * px + edge_b_2 * py + edge_c_2;&#xA;&#xA;        //Check the sample is outside the triangle&#xA;        if (e0 &amp;lt;= 0.f || e1 &amp;lt;= 0.f || e2 &amp;lt;= 0.f)&#xA;            continue;&#xA;&#xA;        float wt0 = e1 * inv2Area;&#xA;        float wt1 = e2 * inv2Area;&#xA;        float wt2 = e0 * inv2Area;&#xA;&#xA;        // Interpolate z&#xA;        float z = (wt0 * p1.z() + wt1 * p2.z() + wt2 * p3.z());&#xA;        float zrhw = 1.0f / z;&#xA;&#xA;        if (z &amp;lt; mZBuffer[py*mWidth + px])&#xA;        {&#xA;            mZBuffer[py*mWidth + px] = z;&#xA;&#xA;            if (mRenderState &amp;amp; RENDERING_COLOR)&#xA;            {&#xA;                float r = wt0 * v1-&amp;gt;r + wt1 * v2-&amp;gt;r + wt2 * v3-&amp;gt;r;&#xA;                float g = wt0 * v1-&amp;gt;g + wt1 * v2-&amp;gt;g + wt2 * v3-&amp;gt;g;&#xA;                float b = wt0 * v1-&amp;gt;b + wt1 * v2-&amp;gt;b + wt2 * v3-&amp;gt;b;&#xA;                DrawPixel(px, py, Color(r, g, b));&#xA;            }&#xA;&#xA;            if (mRenderState &amp;amp; RENDERING_TEXTURE)&#xA;            {&#xA;                float u = wt0 * v1-&amp;gt;u + wt1 * v2-&amp;gt;u + wt2 * v3-&amp;gt;u;&#xA;                float v = wt0 * v1-&amp;gt;v + wt1 * v2-&amp;gt;v + wt2 * v3-&amp;gt;v;&#xA;                unsigned int cc = TextureRead(u, v);&#xA;                unsigned char r = (cc &amp;amp; (0xff &amp;lt;&amp;lt; 16)) &amp;gt;&amp;gt; 16;&#xA;                unsigned char g = (cc &amp;amp; (0xff &amp;lt;&amp;lt; 8 )) &amp;gt;&amp;gt; 8;&#xA;                unsigned char b = cc &amp;amp; (0xff);&#xA;                Color color;&#xA;                color.setColor(r, g, b);&#xA;                DrawPixel(px, py, color);&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4848" LastEditorUserId="209" LastEditDate="2017-03-03T14:42:02.160" LastActivityDate="2017-03-03T14:42:02.160" Title="What happened to my texture mapping?" Tags="&lt;texture&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4799" PostTypeId="2" ParentId="4798" CreationDate="2017-03-03T12:25:02.800" Score="4" Body="&lt;p&gt;You aren't doing perspective correct texturing. At each pixel, $(X,Y)$, you need to be computing U and V with the equivalent of:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$U=\frac{aX+bY+c}{pX+qY+r}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$V=\frac{dX+eY+f}{pX+qY+r}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The denominator of both is linearly interpolating 1/W, while the numerators are, respectively, interpolating U/W and V/W.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I.E. for each triangle vertex you need to compute 1/W, U/W and V/W and then interpolate these. You can do it via barycentrics if you wish but you must do the division per pixel.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-03-03T14:08:30.720" LastActivityDate="2017-03-03T14:08:30.720" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4800" PostTypeId="2" ParentId="4794" CreationDate="2017-03-03T12:44:18.320" Score="2" Body="&lt;p&gt;You might find the 1983 paper that introduced this**, i.e. &lt;a href=&quot;https://classes.soe.ucsc.edu/cmps160/Fall05/papers/p1-williams.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lance Williams' &quot;Pyramidal Parametrics&quot;&lt;/a&gt; informative.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can ignore the scheme, in Figure 1, he used for the layout of the MIP maps as I doubt any hardware, at least in the last 20+ years, used that approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;** &lt;em&gt;(Actually, Williams *may* have described the technique at an earlier SIGGRAPH (1981) as part of tutorial/course but I've never been able to get hold of a copy)&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-03-03T14:43:59.700" LastActivityDate="2017-03-03T14:43:59.700" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4801" PostTypeId="1" CreationDate="2017-03-03T14:44:50.877" Score="4" ViewCount="5077" Body="&lt;p&gt;I am working on a 2D lighting system for my game. My approach has been to:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create a transparency quad representing 'darkness'.&lt;/li&gt;&#xA;&lt;li&gt;Create a stencil shader for light sources to clip from the darkness quad.&lt;/li&gt;&#xA;&lt;li&gt;Create a shader that blends alpha from 0 -&gt; {darkness alpha} to soften the edges of the light source.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This looks like the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vZ77t.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vZ77t.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see the problem - the two light source shaders that soften the shadow edges are being blended like normal transparency layers should and causing the colour to intensify. Here is another image without the darkness quad, which might make things a bit clearer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bpC3M.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bpC3M.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question: Is there any sort of alpha blending I can do to make this intersection appear 'normal' i.e. it doesn't intensify the color? If not, is there another approach which could help with this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the shader code that generates the fade on the light source - note that the _Radius is set for each light source. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Properties&#xA;{&#xA;    _Color(&quot;Bottom Color&quot;, Color) = (1,1,1,1)&#xA;    _Radius(&quot;Radius&quot;, Float) = 1&#xA;}&#xA;&#xA;SubShader&#xA;{&#xA;    Tags&#xA;    { &#xA;        &quot;RenderType&quot; = &quot;Transparent&quot; &#xA;        &quot;IgnoreProjector&quot; = &quot;True&quot;&#xA;        &quot;Queue&quot; = &quot;Transparent&quot; &#xA;    }&#xA;&#xA;    Cull Back&#xA;    Blend One OneMinusSrcAlpha&#xA;&#xA;    Pass&#xA;    {&#xA;        CGPROGRAM&#xA;        #pragma vertex vert&#xA;        #pragma fragment frag&#xA;&#xA;        #include &quot;UnityCG.cginc&quot;&#xA;&#xA;        struct appdata&#xA;        {&#xA;            float4 vertex : POSITION;&#xA;        };&#xA;&#xA;        struct v2f&#xA;        {&#xA;            float4 vertex : SV_POSITION;&#xA;            float distance : float2;&#xA;        };&#xA;&#xA;        fixed4 _Color;&#xA;        float _Radius;&#xA;&#xA;        v2f vert(appdata v)&#xA;        {&#xA;            v2f o;&#xA;            o.vertex = UnityObjectToClipPos(v.vertex);&#xA;            o.distance = distance(float3(0, 0, 0), v.vertex);&#xA;            return o;&#xA;        }&#xA;&#xA;        fixed4 frag(v2f i) : SV_Target&#xA;        {               &#xA;            float distance = (i.distance / _Radius); // 0 -&amp;gt; 1 as progressing to outside&#xA;            float normalizedDistance = 1 - distance; // 1 -&amp;gt; 0 as progressing to outside &#xA;&#xA;            // 0 -&amp;gt; 0.43&#xA;            fixed colorOffset = lerp(0, _Color.a, distance);&#xA;&#xA;            // return alpha &#xA;            return fixed4(0, 0, 0, colorOffset);&#xA;        }&#xA;&#xA;        ENDCG&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6164" LastEditorUserId="6164" LastEditDate="2017-03-06T11:54:31.817" LastActivityDate="2018-05-02T13:23:09.923" Title="Alpha blending between two overlapping semi-transparent shapes" Tags="&lt;shader&gt;&lt;transparency&gt;&lt;unity&gt;&lt;blending&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4803" PostTypeId="1" AcceptedAnswerId="4806" CreationDate="2017-03-03T16:18:43.253" Score="1" ViewCount="374" Body="&lt;p&gt;This summer I will be working with a professor on a research topic of my choice, in the field of graphics &amp;amp; simulation. While my professor is knowledgeable in the area he is being very hands off as he does not want to make the student research his research. The intent is to use OpenGL to work on the topic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We previously had a talk about the idea of taking a scene, specifying a water level, flow direction, and then generating a heat map at that height level of water disturbance to then allow us to render a scene at low cost with &quot;semi-realistic&quot; water flow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While this idea interests me, I was looking to try to look into more ideas regarding fluid's or possible other area's of the field to attempt to find other possible projects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, what would be a good place to look for entry level research projects regarding computer graphics? Or just idea's in general to help steer a beginner.&lt;/p&gt;&#xA;" OwnerUserId="6167" LastActivityDate="2017-03-04T18:40:41.257" Title="Beginner CG Research Project" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;3d&gt;&lt;mathematics&gt;&lt;physics&gt;" AnswerCount="1" CommentCount="2" ClosedDate="2017-03-29T22:20:07.590" ContentLicense="CC BY-SA 3.0" />
  <row Id="4804" PostTypeId="1" AcceptedAnswerId="4814" CreationDate="2017-03-03T17:40:26.487" Score="3" ViewCount="2523" Body="&lt;p&gt;&lt;strong&gt;This &lt;a href=&quot;https://www.google.de/amp/s/0fps.net/2012/07/12/smooth-voxel-terrain-part-2/amp/&quot; rel=&quot;nofollow noreferrer&quot;&gt;question&lt;/a&gt; is comming from ComputerScience after suggestion&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to understand the Naive Surface Nets algorithm which is related to surface generation out of Voxels. I've learned of it &lt;a href=&quot;https://www.google.de/amp/s/0fps.net/2012/07/12/smooth-voxel-terrain-part-2/amp/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I understood that the naive surface nets algorithm calculates the &quot;optimal&quot; edge crossings for a given input. Problem is that I don't understand how it's supposed to calculate the edge crossings compared to the marching cubes algorithm. If the input data is represented in binary values (only one and zero) like for marching cubes algorithm shouldn't the computation of the edge crossings have the same results?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suppose a step by step showcase of what the algorithm does for aquiring the surface of 2D sample voxels data would help me a lot understanding it. Sample code is fine too but is not a must have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example for this data the marching cubes algorithm gives as result the image show below (the lines). Would the naive surface nets algorithm return the same result?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5Fi9E.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5Fi9E.png&quot; alt=&quot;Marching squares algorithm result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where red stands for binary 1 and blue for binary 0 asuming each voxel has the same space between each other (as always I think).&lt;/p&gt;&#xA;" OwnerUserId="6165" LastEditorUserId="6165" LastEditDate="2017-03-03T23:33:14.600" LastActivityDate="2018-01-06T17:19:23.753" Title="Workflow of the Naive Surface Nets algorithm" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4805" PostTypeId="1" AcceptedAnswerId="4867" CreationDate="2017-03-03T21:48:16.963" Score="3" ViewCount="162" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pp9Ug.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pp9Ug.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a visibility algorithm I want to remove verts of polygon that are guaranteed not visible from a vert S. The idea is to remove pockets that points are on the backside of a plane formed by the vector n, the perpendicular vector between S and 0, and a point S.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The prerequisites are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the points of a polygon are in ccw order&lt;/li&gt;&#xA;&lt;li&gt;the labeled points are the cutting-points between g(t) and the edges of the polygon&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;sorted by occurrence with respect to S&lt;/li&gt;&#xA;&lt;li&gt;only the points with a positive t are retained&lt;/li&gt;&#xA;&lt;li&gt;the points are part of a new created polygon, we are working with&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The difficult task is to identify a pocket respectively the pair of indices a pocket starts and ends.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are my approaches:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Use the natural order of cutting-points and remove items with a smaller t to their previous ones (works on I, III and IV).&lt;/li&gt;&#xA;&lt;li&gt;Sort the cutting-points by t. If the second point has the highest index in the original order, then all other cutting-points are part of the pocket and can be ignored (works on II).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Now the questions are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;When should I use the first and when the second approach (I can't see it)?&lt;/li&gt;&#xA;&lt;li&gt;Is there an easier way?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5828" LastActivityDate="2017-03-16T15:09:31.147" Title="Remove clearly not visible vertices from a polygon" Tags="&lt;2d&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4806" PostTypeId="2" ParentId="4803" CreationDate="2017-03-04T18:34:18.343" Score="1" Body="&lt;p&gt;If you are going for physics. You can do physically based rendering. Physically Based Rendering(PBR for short) is a filed of computer graphics where we take consider of physics(energy conservation, spectrum, etc) in to account and try to not do approximations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The are two main sub fields of PBR. &lt;br&gt;&#xA;(quick intro, layman's term below)&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Production Rendering.&#xA;This is where accuracy is the focus. We do as little or no approximations as possible. There are algorithms in this field where if the wave-like property of light is ignored. Then the result generated by the algorithm is physically accurate. But each frame might take more than a few minutes or even hours to render. There are a lot of different topics actively being researched in this field(fast ray-scene intersection, better Monticello integration, fast/robust acceleration struct building)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Realtime Rendering.&#xA;In this field, speed is the key concern. Where accuracy is achieved by doing good approximations. But will never be physically accurate. Most research on this field is focusing on doing good and fast approximations.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;These are my random ideas for fluids.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Fast Ray-Liquid intersection testing&lt;/li&gt;&#xA;&lt;li&gt;Fast triangle mesh generation from particles.&lt;/li&gt;&#xA;&lt;li&gt;Fast acceleration structure building from particles.&lt;/li&gt;&#xA;&lt;li&gt;Simplification of liquid surface to generate simpler mesh&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;And some random ideas for general GC.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Improve sampling efficiency for sky maps in ray based rendering algorithm&lt;/li&gt;&#xA;&lt;li&gt;Robust method of dealing with floating point accuracy problem in shadow maps&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I don't know if the above topics are possible or not. Those are just ideas.&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="2448" LastEditDate="2017-03-04T18:40:41.257" LastActivityDate="2017-03-04T18:40:41.257" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4807" PostTypeId="1" CreationDate="2017-03-04T21:07:10.787" Score="1" ViewCount="160" Body="&lt;p&gt;I would like to generate a bitmap for use with a webgl texture generated from a 2d canvas, but I don't think I am doing it correctly. I know how to display the contents of one canvas into another by using &quot;drawImage&quot;. As has been posted many times, the trick is to make sure the width and height values of the canvas are multiplied by the &quot;display&quot; ratio (1.25 in my case). So if I create some graphics in canvas &quot;a&quot;, by using ctx.rect, ctx.fillText, etc. and display the graphics of canvas a into canvas b I have to make sure that both canvases are multiplied by the ratio above and css displayed accordingly.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the proper way to generate the bitmap for a WebGL texture using a the  canvas? I thought the webgl canvas should have also had the multiplier as above, but that does not seem to work for me. Assuming the image is displayed 1:1 I was thinking I could create the image 1:1 zoom, generate a texture vertext that exactly (0,0) to (1,1) and a &quot;point&quot; vertext that was also 1:1 the size of the image (translated to -1,1 space, of course). Is this correct or am I thinking about it wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks,&#xA;Jose&lt;/p&gt;&#xA;" OwnerUserId="6099" LastActivityDate="2017-03-04T21:07:10.787" Title="How To Generate High Quality Bitmap From Canvas For WebGL Texture" Tags="&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4808" PostTypeId="1" CreationDate="2017-03-05T15:49:05.427" Score="4" ViewCount="177" Body="&lt;p&gt;How can I calculate the rigid transformation [R|t] between two 3d triangles, but restricted to a given N degrees of freedom (for N = 1..6) ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know for N=6 I can get a least-squares solution via SVD of a certain matrix, but how can I integrate further constraints (fewer DOF) into the system?&lt;/p&gt;&#xA;" OwnerUserId="6175" LastEditorUserId="231" LastEditDate="2017-03-06T20:41:41.757" LastActivityDate="2017-06-06T16:30:18.970" Title="Calculate Transformation between two point sets - but with constrained Degrees of Freedom" Tags="&lt;transformations&gt;&lt;geometry&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4809" PostTypeId="1" AcceptedAnswerId="4822" CreationDate="2017-03-05T17:25:47.820" Score="6" ViewCount="525" Body="&lt;p&gt;How is distant directional light source(like sun) added in BDPT?&#xA;If this is an indoor scene that gets sunlight through windows, how is this handled in BDPT(other than to consider Sun as a big disc far away and to sample a position on it's area, as this probably wouldn't be efficient for points within the room)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would it be valid instead to consider window polylines as area sources that emits light in one direction(directional source)? The light samplePosition would be same as sampling a point on the window area (with pdf 1/A ?) and sampleDirection with pdf=1? How about connecting s=1 and t and MIS weights? are they need to be modified or same codes can be used?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help/hint is appreciated, Thanks.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2017-03-08T01:35:32.813" Title="How Sunlight is added in Bidirectional Path tracing?" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;pathtracing&gt;&lt;physically-based&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4810" PostTypeId="1" CreationDate="2017-03-05T22:05:05.670" Score="4" ViewCount="1650" Body="&lt;p&gt;I have a simple &lt;strong&gt;cube&lt;/strong&gt; mesh, which I &lt;strong&gt;scale&lt;/strong&gt; with modifying the &lt;strong&gt;model&lt;/strong&gt; matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Texture settings:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;m_texture);&#xA;glBindTexture(GL_TEXTURE_2D, m_texture);&#xA;&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);&#xA;&#xA;glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I set &lt;code&gt;GL_REPEAT&lt;/code&gt; as wrap mode, but in my case it doesn't help, because the texture coordinates don't exceed &lt;code&gt;[0...1]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;For example&lt;/strong&gt; from the unit cube I want to make a column whose dimensions are (1,10,1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just scaling this doesn't work because it textures the cube and then applies the scaling, which means that the texture will be stretched, instead of repeated along the y axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How can I implement this so I could set the length, width and depth of a cube dynamically and the texture will be repeated on it instead of stretched?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="5609" LastEditorUserId="5609" LastEditDate="2017-03-05T22:41:43.983" LastActivityDate="2017-03-07T17:19:56.697" Title="Stretch the cube mesh but repeat the texture?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4811" PostTypeId="2" ParentId="4792" CreationDate="2017-03-05T22:31:17.853" Score="5" Body="&lt;p&gt;It's not that hard. If you have just planar or angular light sources, you can think of them as one light source split into multiple chunks and the only thing to deal with is how to sample this multi-light and how to compute the PDF of the resulting samples.&lt;/p&gt;&#xA;&lt;h2&gt;Picking probability&lt;/h2&gt;&#xA;&lt;p&gt;First, you need to setup the picking probability &lt;span class=&quot;math-container&quot;&gt;$P(l)$&lt;/span&gt; for each light source &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt;. The picking probabilities can be any non-negative numbers, you just have to make sure that are always non-zero if the contributions of the respective lights are non-zero. However, the closer the probabilities are to the actual (relative) light contribution, the better the overall performance of your Monte Carlo estimator will be.&lt;/p&gt;&#xA;&lt;p&gt;Contribution estimates may be:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt;: naive, uniform probability; good to start with; used by PBRT&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$power$&lt;/span&gt;: better&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$power / distance^2$&lt;/span&gt;: even better; closer light sources have greater contributions&lt;/li&gt;&#xA;&lt;li&gt;…and other improvements: make zero if not visible at all, multiply by the cosine of the inclination angle, etc.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Note that to get the light-picking probabilities, you need to normalise the contribution estimates to the sum of all of them:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;P(l)=&#xA;  \frac&#xA;    {ContribEst_l}&#xA;    {\sum_{a\in\mathrm{Lights}}&#xA;      {ContribEst_a}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;You could even use more different picking strategies if you find they work just for certain type of scenes and combine them using multiple importance sampling technique…&lt;/p&gt;&#xA;&lt;h2&gt;Sampling&lt;/h2&gt;&#xA;&lt;p&gt;When sampling the lights, you just select one light &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; with the appropriate probability &lt;span class=&quot;math-container&quot;&gt;$P(l)$&lt;/span&gt; and then sample the light surface/angle with its own sampling strategy (with PDF &lt;span class=&quot;math-container&quot;&gt;$p_l$&lt;/span&gt;). The resulting PDF &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; will be:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;p(x)=P(l) * p_l(x)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;h2&gt;Evaluating PDF&lt;/h2&gt;&#xA;&lt;p&gt;When computing the light sampling PDF for given direction (as needed for multiple importance sampling), you just find the light source at the direction, evaluate the PDF of the lights own strategy and, again, multiply it by the probability of picking this particular light.&lt;/p&gt;&#xA;&lt;h2&gt;Conclusion&lt;/h2&gt;&#xA;&lt;p&gt;Now you have a sampling strategy which gives you PDF which can be used in the Monte Carlo estimators (e.g. &lt;span class=&quot;math-container&quot;&gt;$f(x)/p(x)$&lt;/span&gt;) and the resulting estimator will be unbiased.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2021-03-15T20:20:27.937" LastActivityDate="2021-03-15T20:20:27.937" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="4812" PostTypeId="2" ParentId="4810" CreationDate="2017-03-06T04:28:53.877" Score="4" Body="&lt;p&gt;You need to set your texture coordinates appropriately. Let's look at one side of your cube. Let's say it's 100 x 100. If the user stretches the cube to be 100 x 150, you need to set the texture coordinates of the corner vertices to be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;lower left = &amp;lt;0.0, 0.0&amp;gt;&#xA;lower right = &amp;lt;1.5, 0.0&amp;gt;&#xA;upper right = &amp;lt;1.5, 1.0&amp;gt;&#xA;upper left = &amp;lt;0.0, 1.0&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That's the easiest way to handle it. Another way to handle it would be to pass either as scale factor or scale matrix into your fragment shader and apply that to your texture coordinates before doing any sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To elaborate on the texture matrix idea, it's fairly simple. In your fragment shader, you'd have a uniform, say &lt;code&gt;textureMatrix&lt;/code&gt; that's a &lt;code&gt;mat4&lt;/code&gt;. It can contain any sort of transform you need - scale, rotation, translation, shear, etc. Before you sample any texture, you run the uv coordinates through the texture matrix, and then use the resulting values for your lookup. Something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 uv = gl_TexCoord[ 0 ]; // or whatever you called it coming from your vert. shader&#xA;vec4 newUV = textureMatrix * uv;&#xA;vec4 pixel = texture2D(texture, newUV.xy);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To do your non-uniform scaling, your matrix would be a scale matrix. For example if you wanted to scale the Y coordinate, you could use a matrix like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;| 1 0 0 0 |&#xA;| 0 2 0 0 |&#xA;| 0 0 0 0 |&#xA;| 0 0 0 1 |&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2017-03-07T17:19:56.697" LastActivityDate="2017-03-07T17:19:56.697" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4813" PostTypeId="1" AcceptedAnswerId="4816" CreationDate="2017-03-06T14:21:46.133" Score="1" ViewCount="195" Body="&lt;p&gt;a) I have used an online service where you can upload an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;b) Afterwards, you can select a print size and it gives you information on what is actual DPI based on that print size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;c) When it gives you information if that particular DPI (dots per inch) for that print size is enough quality to print, so basically it outputs &quot;bad&quot;, &quot;average&quot; or &quot;good&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to built this functionality on my own site, but I lack logic's behind how they count DPI.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my two tests where I upload slightly different photos. As site outputs DPI it is easy to try to get how it counts it, but as for different photos it does differently. I just can not grasp the pattern on why it does so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my two different photos uploaded:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Product: Poster&#xA;Size: 1000x1200&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will just explain the first value - 8x10 -&gt; 1200 / 10  -  you get DPI by subtracting photo height with print size height.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;8x10 -&amp;gt; 1200 / 10   -&amp;gt;&amp;gt;&amp;gt; why this DPI is counted differently from other image?     &#xA;10x10 -&amp;gt; 1000 / 10                &#xA;12x12 -&amp;gt; 1000 / 12               &#xA;12x16 -&amp;gt; 1200 / 16  -&amp;gt;&amp;gt;&amp;gt; why this DPI is counted differently from other image?     &#xA;14x14 -&amp;gt; 1000 / 14                &#xA;16x16 -&amp;gt; 1000 / 16                &#xA;12x18 -&amp;gt; 1200 / 18                &#xA;18x18 -&amp;gt; 1000 / 18                &#xA;16x20 -&amp;gt; 1200 / 20  -&amp;gt;&amp;gt;&amp;gt; why this DPI is counted differently from other image?     &#xA;18x24 -&amp;gt; 1200 / 24  -&amp;gt;&amp;gt;&amp;gt; why this DPI is counted differently from other image?     &#xA;24x36 -&amp;gt; 1200 / 36   &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Product: Poster&#xA;Size: 1000x1333&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;8x10 -&amp;gt; 1000 / 8    -&amp;gt;&amp;gt;&amp;gt; comparing to this value &#xA;10x10 -&amp;gt; 1000 / 10&#xA;12x12 -&amp;gt; 1000 / 12&#xA;12x16 -&amp;gt; 1000 / 12  -&amp;gt;&amp;gt;&amp;gt; comparing to this value   &#xA;14x14 -&amp;gt; 1000 / 14&#xA;16x16 -&amp;gt; 1000 / 16&#xA;12x18 -&amp;gt; 1333 / 18                   &#xA;18x18 -&amp;gt; 1000 / 18&#xA;16x20 -&amp;gt; 1000 / 20  -&amp;gt;&amp;gt;&amp;gt; comparing to this value &#xA;18x24 -&amp;gt; 1000 / 18  -&amp;gt;&amp;gt;&amp;gt; comparing to this value &#xA;24x36 -&amp;gt; 1333 / 36    &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Just do not get it why for a very similar image, counting of the same print sizes are different for particular values?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="6179" LastActivityDate="2017-03-07T06:10:11.150" Title="How to count DPI of an image (challenge)?" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4814" PostTypeId="2" ParentId="4804" CreationDate="2017-03-06T18:01:39.370" Score="4" Body="&lt;p&gt;I think the basic idea, as explained in the article to which you linked, is to associate a vertex (shown in light blue) to each square that intersects the surface, with the vertex positioned at the average of the adjacent edge crossings (shown in gray). Then connect up with dual edges (shown also in light blue).&lt;a href=&quot;https://i.stack.imgur.com/v6qSj.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v6qSj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6125" LastActivityDate="2017-03-06T18:01:39.370" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4815" PostTypeId="2" ParentId="4682" CreationDate="2017-03-07T01:33:20.277" Score="1" Body="&lt;p&gt;Although this is not the solution I was looking for initially, the figure below is the tightest filling without overlaps of the plane with pentagons that I could come up with so far. I haven't found a recursive algorithm yet. I think it's not possible or it is too complicated to code. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TLnKi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TLnKi.png&quot; alt=&quot;pentagon-rhombus lattice&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the python script:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#!/usr/bin/python&#xA;import numpy as np&#xA;import matplotlib.pyplot as plt&#xA;N = 5&#xA;def pentagon (Xorig, Yorig, theta):&#xA;    Ind = np.arange(N+1)&#xA;    X = np.cos(Ind*2*np.pi/N+theta)+Xorig&#xA;    Y = np.sin(Ind*2*np.pi/N+theta)+Yorig&#xA;    plt.fill(X, Y, 'r-')&#xA;&#xA;plt.axes().set_aspect ('equal')&#xA;r = 2*np.cos(np.pi/5)&#xA;plt.xlim(-2, 30)&#xA;plt.ylim(-2, 30)&#xA;Lx = np.cos(np.pi/10)&#xA;for j in np.arange(0, 10):&#xA;    Xorig = (j%2)*Lx*np.ones(N+1)&#xA;    Yorig = j*(1+2*np.cos(np.pi/5)+np.cos(2*np.pi/5))*np.ones(N+1)&#xA;    theta = np.pi/(2*N)&#xA;    sign = 1&#xA;    for i in np.arange(1, 32):&#xA;        pentagon(Xorig, Yorig, theta)&#xA;        Xorig += r*np.cos(3*theta)*np.ones(N+1)&#xA;        Yorig += r*np.sin(3*theta)*np.ones(N+1)&#xA;        sign *= -1&#xA;        theta = sign*np.pi/(2*N)&#xA;plt.axis('off')&#xA;plt.savefig(&quot;pentagonLattice.png&quot;, bbox_inches='tight')&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also I haven't found yet a simple way to make a quasi-periodic tiling of the plane with only pentagons and rhombi yet. I did find out though how to fill the plane with pentagons and rhombi with a center with 5-fold symmetry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/djejd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/djejd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a python script with a recursive algorithm (though not optimized):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#!/usr/bin/python&#xA;import numpy as np&#xA;import matplotlib.pyplot as plt&#xA;N = 5&#xA;# The golden ratio&#xA;phi = (1.0+np.sqrt(5.0))/2&#xA;# angle increment&#xA;theta0 = np.pi/5&#xA;LEFT = 0&#xA;RIGHT = 1&#xA;# fill plot a pentagon with center at (Xorig, Yorig) and orientation theta&#xA;def pentagon (Xorig, Yorig, theta):&#xA;    Ind = np.arange(N+1)&#xA;    X = np.cos(Ind*2*np.pi/N+theta)+Xorig&#xA;    Y = np.sin(Ind*2*np.pi/N+theta)+Yorig&#xA;    plt.fill(X, Y, 'r-')&#xA;# At each step three edges are generated&#xA;# and two recursive calls are made&#xA;def stepSplit (previousPoint, previousTurn, theta, nIter):&#xA;    if nIter == 0:&#xA;        return&#xA;    if previousTurn == RIGHT:&#xA;        # Turn left &#xA;        theta = theta+theta0&#xA;    elif previousTurn == LEFT:&#xA;        # turn right &#xA;        theta = theta-theta0&#xA;    nextPoint = previousPoint + phi*np.array([np.cos(theta), np.sin(theta)])&#xA;    X, Y = zip(previousPoint, nextPoint)&#xA;    pentagon (nextPoint[0], nextPoint[1], theta)&#xA;    # Update&#xA;    previousPoint[:] = nextPoint[:]&#xA;    # Bifurcation&#xA;    # Turn left &#xA;    theta1 = theta+theta0&#xA;&#xA;    nextPoint = previousPoint + phi*np.array([np.cos(theta1), np.sin(theta1)])&#xA;    X, Y = zip(previousPoint, nextPoint)&#xA;    pentagon (nextPoint[0], nextPoint[1], theta1)&#xA;    stepSplit(nextPoint, LEFT, theta1, nIter-1)&#xA;&#xA;    # Turn right &#xA;    theta1 = theta-theta0&#xA;    nextPoint = previousPoint + phi*np.array([np.cos(theta1), np.sin(theta1)])&#xA;    X, Y = zip(previousPoint, nextPoint)&#xA;    pentagon (nextPoint[0], nextPoint[1], theta1)&#xA;    stepSplit(nextPoint, RIGHT, theta1, nIter-1)&#xA;&#xA;# fill plot pentagons&#xA;# Central pentagon&#xA;pentagon (0.0, 0.0, 0.0)&#xA;for i in [1, 3, 5, 7, 9]:&#xA;    stepSplit (np.array([0.0, 0.0]), -1, i*theta0, 5)&#xA;&#xA;for i in [0, 2, 4, 6, 8]:&#xA;    theta = i*np.pi/5&#xA;    x0 = phi*(1.0+2*np.cos(np.pi/5))*np.cos(theta)&#xA;    y0 = phi*(1.0+2*np.cos(np.pi/5))*np.sin(theta)&#xA;    pentagon (x0, y0, theta0)&#xA;    stepSplit (np.array([x0, y0]), -1, theta, 4)&#xA;&#xA;plt.axes().set_aspect ('equal')&#xA;plt.axis('off')&#xA;plt.savefig(&quot;pentagonLattice4.png&quot;, bbox_inches='tight')&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6023" LastEditorUserId="6023" LastEditDate="2017-03-21T12:13:46.197" LastActivityDate="2017-03-21T12:13:46.197" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4816" PostTypeId="2" ParentId="4813" CreationDate="2017-03-07T06:10:11.150" Score="3" Body="&lt;p&gt;They are not &quot;very similar images&quot;. They have quite different aspect ratios. The first one has a 5:6 aspect ratio, while the other has a 3:4 ratio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you try to print a 5:6 image at 8x10, what you find is that if the width is 8, then a 5:6 image would have a height of 9.6, which is less than 10. So that means the 5:6 image can fit into the 8x10 region with its full width; some of the height will go unused.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, a 3:4 aspect ratio image at 8x10 doesn't do that. If the width is 8, then the 3:4 aspect ratio would require a height of 10.6. That would exceed the maximum available height, so the width cannot be full width. Instead, it uses the full height of 10, and the width used will only be 7.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You will find that this is the case for all of the ones where you noted such a difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &quot;DPI&quot; its computing is essentially the number of pixels in the dimension that &lt;em&gt;isn't&lt;/em&gt; the maximum. For the 3:4 image at 8x10, it takes the image width (1000) and divides by the area width (8). For the 5:6 image at 8x10, it takes the image height (1200) and divided by the area height (10).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This number only makes sense if we assume that the image is being scaled independently in width and height to fit the page. That is, the aspect ratio of the image is not being preserved when printed. So a 5:6 image is being transformed into a 4:5 aspect ratio image when printed at 8x10.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since each dimension is being scaled differently, each dimension has its own DPI. The lowest DPI will be for the dimension being stretched the most. And that's what this formula seems to be computing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course... &lt;em&gt;who cares?&lt;/em&gt; Stretching images creates obvious visual distortion, and should pretty much never be done when printing something you actually want to have a paper copy of. So I would declare this computation algorithm to be bogus and move to something that actually makes sense with a reasonable printing methodology.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-03-07T06:10:11.150" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4817" PostTypeId="1" AcceptedAnswerId="4818" CreationDate="2017-03-07T10:24:44.110" Score="3" ViewCount="271" Body="&lt;p&gt;Suppose I have two 3D triangles before &amp;amp; after a single rotation around an unknown axis.&#xA;How would I go about finding this axis?&lt;/p&gt;&#xA;" OwnerUserId="6175" LastActivityDate="2017-03-07T13:19:40.897" Title="Calculate a rotation around an arbitrary axis" Tags="&lt;transformations&gt;&lt;geometry&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4818" PostTypeId="2" ParentId="4817" CreationDate="2017-03-07T11:08:32.130" Score="4" Body="&lt;p&gt;Take a point $P$ and it's rotated point $P'$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Find the plan that runs through the middle between them $C = \frac{P+P'}{2}$ and is perpendicular to the line connecting them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do this for all 3 of them and find the line of the planes' intersection. That will be the rotation axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all mid-planes are coplanar then you can use the planes of the triangles themselves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get the angle you can take a $P$ and $P'$ again and project them onto the axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Take a point $A$ on the axis and the direction $v$ of the axis. The projected point is $P_p=A+\frac{v \cdot (P-A)}{v\cdot v} v$. And then the angle is $acos(\frac{dot(P-P_p, P'-P_p)}{|P-P_p|* |P'-P_p|})$&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2017-03-07T13:19:40.897" LastActivityDate="2017-03-07T13:19:40.897" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4819" PostTypeId="1" CreationDate="2017-03-07T13:03:03.557" Score="2" ViewCount="122" Body="&lt;p&gt;I was suprised to learn that RGB tertiary colors are much more similar to RGB primary then secondary colors.&#xA;I was expecting they will be halfway between them and look more like this: &lt;br/&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M20cO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M20cO.png&quot; alt=&quot;tertiary&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rather then this: &lt;br/&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nigie.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nigie.png&quot; alt=&quot;tertiary RGB&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a reason/purpose for this disproportion? &lt;br/&gt;&#xA;(I know how to calculate values- this is not my question. I'd like to know why correctly calculated tertiary RGB colors seems to be much closer to primary then secondary RGB colors)&lt;/p&gt;&#xA;" OwnerUserId="6187" LastActivityDate="2017-03-08T05:27:29.110" Title="Why are RGB tertiary colors so similar to RGB primary colors?" Tags="&lt;color-science&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4820" PostTypeId="1" AcceptedAnswerId="4821" CreationDate="2017-03-07T14:47:37.547" Score="1" ViewCount="1122" Body="&lt;p&gt;I have trouble understanding the way a camera is set in &lt;a href=&quot;https://processing.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Processing&lt;/a&gt; (according to the reference this shoudn't be very different from OpenGl). For starters, when I set the eye position of the camera I have to set three coordinates. I'm assuming that the X coordinate is the horizontal border of the display and the Y coordinate would be the vertical border. I think the Z coordinate to be behind or in front my computer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when I do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;camera(width/2, height/2, depth, 250, 250, 0, 0, 1, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm setting the camera in the middle of the display and putting it some depth in the axis that comes into my eyes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think this part is clear enough. However, the two other parameters are not as clear. In particular in don't see the difference between the center of the scene and the last parameter which is the axis that is facing upward. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the center of the scene I'm assuming that it gives me the direction the camera is looking to but what is the axis that is facing upward? &lt;/p&gt;&#xA;" OwnerUserId="6183" LastEditorUserId="506" LastEditDate="2017-03-08T10:21:41.930" LastActivityDate="2017-03-08T10:21:41.930" Title="Understanding camera() settings in Processing" Tags="&lt;camera&gt;&lt;processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4821" PostTypeId="2" ParentId="4820" CreationDate="2017-03-07T23:35:07.460" Score="1" Body="&lt;p&gt;As the &lt;a href=&quot;https://processing.org/reference/camera_.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation&lt;/a&gt; describes it, it looks like each group of three parameters is a vector in 3D space. The first three are the position of the “eye”, the next three are the position it’s looking at, and the last three are the “up vector”, i.e. the direction of an arrow pointing out of the top (…sort of—more detail below) of the eye. The positions aren’t related to the size of your display window—the view of your 3D geometry from the camera at that point will fill the display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, if you have a &lt;a href=&quot;https://processing.org/reference/box_.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;box&lt;/a&gt; centered at (0, 0, 0) that’s 1×1×1 units in size, then your camera should be positioned a few units away—say (2, 3, 4)—and looking roughly at the center of the box, i.e. (0, 0, 0). If the box is 100×100×100 instead, then the eye position should be on the same order of magnitude in distance, e.g. (200, 300, 400). The behavior of the up vector is a little more complicated to explain, but leaving it at (0,1,0) is fine for most purposes—it’s mostly there to help you avoid &lt;a href=&quot;https://en.wikipedia.org/wiki/Gimbal_lock&quot; rel=&quot;nofollow noreferrer&quot;&gt;gimbal lock&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2017-03-07T23:35:07.460" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4822" PostTypeId="2" ParentId="4809" CreationDate="2017-03-08T01:35:32.813" Score="3" Body="&lt;p&gt;This can be done in two ways - either use a sky with a sun in it as an cubemap-type light source outside your building, or use the windows as light sources. With BDPT, you could sort of do both, and consider the windows area light sources where the light differs depending upon the angle, using a sun and sky image/model, and then you could implement importance sampling so that you usually get light rays going from the sun instead of the darker sky. This way you get all the accuracy of a full sun and sky model, and it'll still look good at low sample rates.&lt;/p&gt;&#xA;" OwnerUserId="1578" LastActivityDate="2017-03-08T01:35:32.813" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4823" PostTypeId="2" ParentId="4819" CreationDate="2017-03-08T05:27:29.110" Score="2" Body="&lt;p&gt;Likely a gamma correction issue. Tertiary colours are some permutation of (1, 0.5, 0) in RGB, right? So the issue arises because without applying gamma, 0.5 appears less than half as bright as 1, so the blended colour skews towards the primary (1,0,0) rather than the secondary (1,1,0). The image below has linear colour on top, gamma corrected on the bottom, you can see the gamma corrected colours appear much closer to a halfway tone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7wZsK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7wZsK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-03-08T05:27:29.110" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4824" PostTypeId="1" AcceptedAnswerId="4825" CreationDate="2017-03-08T09:18:14.720" Score="4" ViewCount="1020" Body="&lt;p&gt;When I download this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zjaAF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zjaAF.jpg&quot; alt=&quot;https://www.ucn.edu.ni/media/2016/03/graduados-ucn-nicaragua.jpg&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;&lt;sub&gt;(source: &lt;a href=&quot;https://www.ucn.edu.ni/media/2016/03/graduados-ucn-nicaragua.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;ucn.edu.ni&lt;/a&gt;)&lt;/sub&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;then its total size is 341,0 kB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image has a width of 2880 pixels and height of 1100 pixel and 1 X/Y resolution pixel/in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I opened the image with gimp and pressed &lt;strong&gt;scale image&lt;/strong&gt; and reduced the width to 1920px and auto adjusted height of 733px, and keeped the resolution as it is and used the interpolation cubic. If I now export this as a jpg with 90% quality, then the image size is 546 kB! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is that possible and how can I avoid that?&lt;/p&gt;&#xA;" OwnerUserId="6194" LastEditorUserId="5778" LastEditDate="2019-07-15T07:53:53.047" LastActivityDate="2019-07-15T07:53:53.047" Title="reducing image size increases file size?" Tags="&lt;image-processing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="4825" PostTypeId="2" ParentId="4824" CreationDate="2017-03-08T09:28:19.447" Score="6" Body="&lt;p&gt;JPEG is a lossy format and depends on both the 2d frequency components of the image and the user specified quality level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is possible that down-scaling an image can increase the higher frequency components and potentially result in an increase in file size, typically higher frequency components a encoded using a higher number of bits compared to lower frequency components. An example would be to imagine shrinking a checkerboard texture, the smaller it gets the more it shifts into higher frequency.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It may also be possible that your original image was encoded with a low quality factor and your new image has a high quality factor so it can also gain extra bytes from that. On a more technical level this may be because of a mismatch in quantization bands leading to higher number of DCT coefficients being needed compared to the original JPEG. The quality parameter is not standardized and different applications have different ideas of what '90% quality' means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another problem is that because you are using JPEG as a source image it will introduce ringing artifacts into the image, which then need more bits to encode when trying to encode it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately there is no easy fix for this apart from reducing quality.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="137" LastEditDate="2017-03-08T09:50:06.233" LastActivityDate="2017-03-08T09:50:06.233" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4826" PostTypeId="2" ParentId="4808" CreationDate="2017-03-08T15:24:17.080" Score="1" Body="&lt;p&gt;Every 3D rotation has an associated space that can be generated by 3 basis vectors, which can be seen as the axis of the coordenate system of this space. These vectors are also the 3 columns of the transformation matrix. In order to decrease the dof of the rotation, you should provide one or more of these basis vectors and solve for the rest of the matrix. The same principle applies to the translation vector, you should provide constants for one or more distances of the translation. Of course, if you restrict the transformation too much you will end with an unsolvable exact system or a transformation that take the first triangle too far away from the second one, if you are using a non-linear solver.&lt;/p&gt;&#xA;" OwnerUserId="303" LastActivityDate="2017-03-08T15:24:17.080" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4827" PostTypeId="2" ParentId="4824" CreationDate="2017-03-09T02:24:19.703" Score="1" Body="&lt;p&gt;Your original image is very low in quality and talking with experance image with such dimension should have 3MB size but your file  is already compressed using lossy data DCT algorithm, deflated upto 0.1 rate and had lost a lot of data before you download it!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to reduce the dimensions and preserving the filesize ratio, image editor program needs to extract the image and omit the lines vertically and horiznotally to reach to the desired dimensions and compress it again using a lossy data algorithm upto 10 percent but unfortunately  this time the image will loose too much data and you will unable to recognize the faces in it. So you must select a higher quality cause the file just can not tolerate to loose any data again!&#xA;This means you can not compress the extracted file as well as it was at first place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Comparing JPEG encoding (after resizing the image ) with PNG which uses ZLIb algorithm(non lossy data) I believe you may recieve a better result if you save your altered dimension file in to PNG, the image has a lot of same color pixel that will let ZLIB to compress it very well. This is only true in case you have a file which is once compressed using JPEG.&lt;/p&gt;&#xA;" OwnerUserId="537" LastEditorUserId="537" LastEditDate="2017-03-09T13:04:37.927" LastActivityDate="2017-03-09T13:04:37.927" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4828" PostTypeId="1" CreationDate="2017-03-09T10:35:36.013" Score="0" ViewCount="76" Body="&lt;p&gt;What are ways to render high resolution screenshot from application?&#xA;Problem is I have to capture screenshot in higher resolution that it is present on screen. Resolution can be higher than 4K so making one big render target isn't option also rendering parts of scene and merging them will have artifacts in effects like &lt;code&gt;SSR&lt;/code&gt; or &lt;code&gt;vignette&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any other options to do this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rendering is done with classic triangle rasterisation and it have to stay this way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;//EDIT&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Screenshots are from game and saved in &lt;code&gt;PNG&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can't render to higher resolution because no everyone have enough &lt;code&gt;VRAM&lt;/code&gt; (it can be higer than 7680x4320)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use standard &lt;code&gt;Tiled Deferred Rendering&lt;/code&gt; with &lt;code&gt;DX11&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorUserId="3123" LastEditDate="2017-03-10T11:47:45.860" LastActivityDate="2017-03-10T11:47:45.860" Title="High resolution screenshot" Tags="&lt;capture&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4830" PostTypeId="1" AcceptedAnswerId="4835" CreationDate="2017-03-09T12:30:16.693" Score="7" ViewCount="3004" Body="&lt;p&gt;I'm having trouble understanding the &lt;a href=&quot;http://www.comp.nus.edu.sg/~tants/jfa/i3d06.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;JFA&lt;/a&gt;. As far as I understood the algorithm, it walks &lt;em&gt;log(n)&lt;/em&gt; times through every pixel (no matter if it is a seed or not) and looks at that pixel's neighbors in $(x+i, y+j)$ where $i,j \in \{-step\ length, 0, step\ length\}$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When finding a seed (i.e., a colored pixel) among those neighbors, it checks whether the distance between the found neighbor seed and the current pixel is less than the distance the current pixel has already stored (after a previous round). If it is, the current pixel will be overwritten with the color of the found seed and the new distance and therefore serves as input seed for the next round. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I tried to comprehend an example in some slides by the author himself but failed at step length 2, especially with the three bottommost red seeds:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dGXJd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dGXJd.png&quot; alt=&quot;complex example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, why does the blue circled seed keep its red color even though at step length 2 it finds two green seeds with a smaller distance (in my understanding the circled red pixel has stored a 4 and the distance to its top and bottom green neighbors is 2)? Or why does the other blue circled pixel become red, though its &lt;em&gt;(x+2, y)&lt;/em&gt; neighbor is a green one with a smaller distance than its &lt;em&gt;(x+2, y+2)&lt;/em&gt; red neighbor? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also sketched another example on paper but when it comes to step length 1 the algorithm finds more than one neighbor seed with equal distances, so how will it decide? We could also think of a more simple example like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mWkzJs.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mWkzJs.jpg&quot; alt=&quot;simple example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the diagonal pixels supposed to be according to the algorithm in that case? What am I getting wrong?&lt;/p&gt;&#xA;" OwnerUserId="5406" LastEditorUserId="361" LastEditDate="2017-03-10T19:56:16.560" LastActivityDate="2017-03-10T20:38:28.327" Title="Understanding Jump Flooding Algorithm (JFA) for Voronoi Diagrams" Tags="&lt;algorithm&gt;&lt;color&gt;&lt;mathematics&gt;&lt;2d&gt;&lt;distribution&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4832" PostTypeId="1" CreationDate="2017-03-09T16:24:25.097" Score="3" ViewCount="195" Body="&lt;p&gt;I'm trying to calculate camera paramters and a hand eye calibration (Transformation from camera to eye (display) coordinates) for rendering on a see-through HMD.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have already calculated a Projection matrix P (using SPAAM) which transforms points in the camera coordinate system to the screen (Tested by custom rendering).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cause of the used framework (metaio) I can't set the projection matrix directly  but have to separately set the camera parameters and Hand Eye calibration for rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore I have extracted the extrinsic (E) and intrinsic (I) camera parameters from the Projection matrix P.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WKalf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WKalf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But those are not working correctly when set. The result seems to be not completely off, cause the rendered scale seems to be correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess I'm missing some additional step I'm not aware of or the extrinsics are not the hand-eye-calibration I'm looking for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I appreciate any ideas and help.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additional information:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;right handed coordinate system with camera looking in negative z axsis, x to the right and y up&lt;/li&gt;&#xA;&lt;li&gt;Since The translation part of HEC on the x- axis has to be positive (known from working configs) (camera is on the right side of the HMD) I assume it's transformation is specified from eye to camera?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;PS: Before I realized this stackexchange exist, I have already asked the question &lt;a href=&quot;https://stackoverflow.com/questions/42623966/calculate-camera-parameters-and-handeyecalibration&quot;&gt;here&lt;/a&gt;. I got unfortunately no feedback so far.&lt;/p&gt;&#xA;" OwnerUserId="6204" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-03-09T16:24:25.097" Title="Calculate Camera parameters and HandEyeCalibration" Tags="&lt;transformations&gt;&lt;projections&gt;&lt;perspective&gt;&lt;camera-matrix&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4835" PostTypeId="2" ParentId="4830" CreationDate="2017-03-10T20:33:09.150" Score="6" Body="&lt;p&gt;I think that there is a bit of confusion in terminology. My understanding is that only the initially colored points, before step 1, are called seeds. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe this helps clarify the algorithm as well. When the a point $ p $ with color $ s $ finds a neighbor $ q $ with color $ s' $, he compares the distance $ d(p,s) $ with $ d(p,s') $ (not $ d(p,q) $) to decide his new color. This is why each pixel crucially holds the $ (x,y) $ coordinates of his seed color (in the paper they used the r,g channels for this) and not just the distance. In each step this data is also passed to the neighbor. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in that example, in moving from step length 4 to step length 2, that red square (the circled one that remains red) sees the green square who tells red square that the green seed is at $ (8,6) $. Red square then computes his distance to green square to be $ \sqrt{2^2 + 4^2} $, which is bigger than the distance to red ($ 4 $), and so remains red.&lt;/p&gt;&#xA;" OwnerUserId="6125" LastEditorUserId="6125" LastEditDate="2017-03-10T20:38:28.327" LastActivityDate="2017-03-10T20:38:28.327" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4836" PostTypeId="1" CreationDate="2017-03-11T05:57:37.130" Score="0" ViewCount="121" Body="&lt;p&gt;I am going to have the following texture drawn hundreds of times all over the screen using a 4 point GL Triangle Strip. I would use GL's dots except I need to be able to orient the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/35Hk6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/35Hk6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The color does not really matter as that will change every so often.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Technically this is not the only image. Occasionally the thing will switch to being just a dot texture. I am not sure how I will be implementing that quite yet however. Worst case scenario I will pass two textures into the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need the drawing of this texture to be done as efficiently as humanly possible so I need to know if there is anything I can do to make sure that this does not cause OpenGL any hiccups. If there is any good way to initialize the texture that will hold this, pass it in, or sample it please let me know.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am also not sure what resolution I want this shape to be drawn at. I don't know what the relationship between texture sampling cost and resolution is. Any suggestions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I considered drawing the shape inside of a fragment shader but my hunch is that it will be more expensive. But I shall see.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="231" LastEditDate="2017-03-13T00:36:32.227" LastActivityDate="2017-03-13T00:36:32.227" Title="How to quickly draw multiple instances of a texture?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4837" PostTypeId="1" CreationDate="2017-03-11T06:01:57.790" Score="2" ViewCount="336" Body="&lt;p&gt;I am trying to make it so that objects leave trails behind them and if an object is in the back and tries to draw over a previous trail it is transparent because of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is whenever I do not GL_CLEAR the depth buffer after each frame the screen goes blank. Is there a way around this in Open GL ES 2.0?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Diagram:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/LPxF6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LPxF6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2017-03-11T07:01:36.757" LastActivityDate="2017-03-11T07:01:36.757" Title="Do you have to clear the depth buffer each frame in OpenGL" Tags="&lt;depth-map&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4838" PostTypeId="1" AcceptedAnswerId="4845" CreationDate="2017-03-11T17:39:01.493" Score="0" ViewCount="300" Body="&lt;p&gt;What formula is for counting aspect ratio of the image as in this site:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.ninjaunits.com/calculators/aspect-ratio/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Aspect ratio calculator (ARC) | NinjaUnits&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 1000x1200 its aspect ratio 5:6 &#xA; 1000x1333 its aspect ratio 3:4&#xA; 2592x3888 its aspect ratio 2:3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I want to determine this by handling an uploaded image so it should be a formula for counting this, but did not figure out this yet.&lt;/p&gt;&#xA;" OwnerUserId="6179" LastEditorDisplayName="user7220" LastEditDate="2018-04-15T09:57:19.180" LastActivityDate="2018-04-15T09:57:19.180" Title="How to count aspect ratio of an image when you have dimensions?" Tags="&lt;image-processing&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4839" PostTypeId="1" AcceptedAnswerId="4840" CreationDate="2017-03-11T18:46:56.427" Score="2" ViewCount="392" Body="&lt;p&gt;Consider a triangular face of three vertices $A=(0,2,1)$, $B=(3,0,1)$ and the origin $O$, with normal vectors $(0,0,1)$, $(1,1,0)$, and $(-1,-1,1)$, respectively. The incident light is white and directional in the direction of $L = (0,3,4)$ and the intensity is $1$, the background ambient light intensity is $0.1$, and the diffuse reflection coefficients for $(red, green, blue)$ are $(0.6,0.7,0.8)$. No specular light contribution need be considered. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To find the $(red, green, blue)$ intensity values at the centre of the face using flat shading, I follow this procedure:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I try to calculate ambient light intensity&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ambient\ light\ intensity = (ambient\ reflection\ coefficient) \cdot (incident\ ambient\ light\ intensity)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$red = 0.6 \cdot 0.1 = 0.06$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$green = 0.7 \cdot 0.1 = 0.07$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$blue = 0.8 \cdot 0.1 = 0.08$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, I try to calculate diffuse light:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$diffuse\ light = (incident\ light\ intensity) \cdot (diffusive\ reflection\ light) \cdot \cos{\theta}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$incident\ light\ intensity = 1$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$diffusive\ reflection\ light$ is given as $(0.6, 0.7, 0.8)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not sure how to calculate $\cos{\theta}$. I believe it to be the angle between the normal vector of a vertex and the incident light. But I am having difficulties because there are three different normal vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After that, I think I should sum the ambient light intensity with the diffuse light to get the final RGB values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would really appreciate it if you could help me fill the gaps to my calculations. Thanks.&lt;/p&gt;&#xA;" OwnerUserId="5513" LastEditorUserId="2707" LastEditDate="2017-03-12T09:26:37.177" LastActivityDate="2017-03-14T20:27:39.237" Title="How do you calculate cos(theta) for diffuse in flat shading?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4840" PostTypeId="2" ParentId="4839" CreationDate="2017-03-12T03:48:04.913" Score="2" Body="&lt;p&gt;With flat shading, the normal is the same across the whole triangle (or quad or whatever). There are some assumptions that were made here and two approaches. The latter approach will probably be best for most basic problems (although more work). We don't have the winding order, so we need to calculate the normal based on the vertices.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Average normal approach&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The assumption is that each vertex contributes the same amount of weight towards the triangle normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We first calculate the average of each:&#xA;$$normal = normalize(0,0,1) + normalize(1,1,0) + normalize(-1,-1,1) \approx \frac{(0,0,1)+(0.7,0.7,0)+(-0.58,-0.58,0.58)}{3} \approx (0.04,0.04,0.53)$$&#xA;$$normalize(0.04,0.04,0.53) \approx (0.076,0.076,0.994)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For Lambert shading:&#xA;$$cos(\theta) = normalize(0,3,4) \cdot (0.76,0.76, 0.994) \approx 0.84 $$&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Geometric approach (recommended for this problem)&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Another assumption Nathan Reed suggested was that each vertex normal holds equal weight, which would make sense in more common use cases. For this, we will want to find the face normals in both winding directions to compare this value to:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Winding order 1&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;$$normal1 = normalize((B-A) \times (O-A)) \approx (0.29,0.43,-0.85)$$&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Winding order 2&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;$$normal2 = normalize((O-A) \times (B-A)) \approx (-0.29,-0.43,0.85)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we can take the dot product between these two vectors and the one we computed above. Whichever one is greater or equal to 0:&#xA;$$geometric\ normal1 = normal \cdot normal1 \approx -0.79$$&#xA;$$geometric\ normal2 = normal \cdot normal2 \approx 0.79$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So then,&#xA;$$normal = geometric\ normal2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For Lambert shading:&#xA;$$cos(\theta) = normalize(0,3,4) \cdot (-0.29,-0.43,0.85) \approx 0.42 $$&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2017-03-14T20:27:39.237" LastActivityDate="2017-03-14T20:27:39.237" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4841" PostTypeId="2" ParentId="4838" CreationDate="2017-03-12T09:04:58.073" Score="1" Body="&lt;p&gt;One way you could do it is by writing the dimensions as a fraction, and simplifying that fraction (dividing each of the numbers by their greatest common denominator). From that you can then create a string and format it as [simplified numerator]:[simplified denominator].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/4652468/is-there-a-javascript-function-that-reduces-a-fraction&quot;&gt;This SO question&lt;/a&gt; talks about this too, and it shows some code to implementing it in JavaScript and also suggests some libraries... although I don't know what language you're using, I think this will still help.&lt;/p&gt;&#xA;" OwnerUserId="3083" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-03-12T09:04:58.073" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4842" PostTypeId="1" CreationDate="2017-03-12T09:42:45.390" Score="1" ViewCount="1242" Body="&lt;p&gt;Consider a triangular face of three vertices A(0,2,1), B(3,0,1) and the origin, and the normal vectors at the vertices are nA=(0,0,1), nB=(1,1,0) and nO=(-1,-1,1), respectively. The incident light is white and directional in the direction of L=(0,3,4) and the intensity is 1, the background ambient light intensity is 0.1, and the diffuse reflection coefficients for (red, green, blue) are (0.6,0.7,0.8). No specular light contribution need be considered. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I find the (red, green, blue) intensity values at the centre of the face using flat shading?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Flat Shading:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = Ia x Ka + Fatt x Il x (Kd x (N x L))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Final intensity = ambient reflection x ambient reflection coefficient + (attenuation x incident light intensity x (diffusive reflection coefficient x (surface normal x Light intensity))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My lecturer told me that because ambient reflection coefficient and attenuation are not given, I can forget about it. Also specular light contribution need not be considered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The surface normal is: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A = (0, 2, 1) B = (3, 0, 1) O = (0, 0, 0)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;U = A - O = (0, 2, 1) V = B - O = (3, 0, 1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Surface normal = U x V (cross-product) = (2, 3, -6)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = 0.1 + (1, 1, 1) x ((0.6, 0.7, 0.8) x ((2, 3, -6) x (0, 3, 4)))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = 0.1 + (1, 1, 1) x ((0.6, 0.7, 0.8) x (0, 9, -2.4))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = 0.1 + (1, 1, 1) x (0, 6.3, -1.92)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = (0.1, 6.4, -1.82) = RGB intensity values&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this correct?&lt;/p&gt;&#xA;" OwnerUserId="5513" LastEditorUserId="5513" LastEditDate="2017-03-16T19:31:26.957" LastActivityDate="2017-03-16T19:31:26.957" Title="How to calculate the RGB intensity values at center of face using flat shading?" Tags="&lt;rendering&gt;" AnswerCount="2" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4843" PostTypeId="1" CreationDate="2017-03-12T12:57:28.707" Score="2" ViewCount="151" Body="&lt;p&gt;In Ray-Sphere intersection is $b=2*(O-C) \cdot dirv$?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $dirv$ is the Ray direction vector. $O$ is origin and $C$ is center of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also seen this without the $2$, i.e. $b=(O-C)\cdot dirv$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Particularly &lt;a href=&quot;https://bobobobo.wordpress.com/2013/03/03/ray-sphere-intersection/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; it's calculated like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Compute:&#xA;//    d = L - E ; // Direction vector of ray, from start to end&#xA;//    f = E - C ; // Vector from center sphere to ray start&#xA;const Vector &amp;amp;d = ray.direction ;&#xA;Vector f = ray.startPos - this-&amp;gt;pos ;&#xA;real a = d • d ;  // a is non-negative, this is actually always 1.0&#xA;real b = 2*(f • d) ;&#xA;real c = f • f - radius*radius ;&#xA;&#xA;real discriminant = b*b-4*a*c;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6029" LastActivityDate="2017-03-12T20:48:54.123" Title="In Ray-Sphere intersection is $b=2*(O-C) \cdot dirv$?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4844" PostTypeId="2" ParentId="4843" CreationDate="2017-03-12T20:48:54.123" Score="1" Body="&lt;p&gt;TL;DR $b = 2(f \cdot d)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll try to derive it and then we can see what $b$ should be. If the sphere is centered at point $a$ with radius $r$, its equation is $|p - a| = r$, where $p$ is a point on the sphere. $|p - a|$ is the distance from a point $p$ to the centre of the sphere, and if that is equal to the radius, then it's a point on the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We'll assume the centre of the sphere is at the origin, so $a = 0$ and we have $|\vec{p}| = r$. Squaring both sides gives $|\vec{p}|^2 = r^2$ which I'm going to write as $$\vec{p}^2 = r^2 \tag{1}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ray has equation $$x + td\tag{2}$$ where $x$ is the endpoint, $d$ is the direction, and $t$ is the parameter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the ray doesn't intersect the sphere, we will not be able to find a $t$ satisfying the ray equation. In the quadratic equation the discriminant (the bit under the square root) will be $&amp;lt; 0$. If it grazes the sphere (i.e. tangent) then we'll have a single point of intersection and a single $t$ and the discriminant will be $0$. If it goes through the sphere, we'll get a $t$ for the sphere entry, and a distinct $t$ for the sphere exit and the discriminant will be $&amp;gt; 0$. We need to plug $(2)$ into $(1)$ and solve for $t$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{alignat}{2}&#xA;  &amp;amp;&amp;amp;(x + td)^2  &amp;amp;= r^2\\&#xA;  &amp;amp;\Rightarrow\quad&#xA;  &amp;amp;(x + td)(x + td)  &amp;amp;= r^2\\&#xA;  &amp;amp;\Rightarrow\quad&#xA;  &amp;amp;x \cdot x + 2t(x \cdot d) + t^2(d \cdot d)  &amp;amp;= r^2\\&#xA;  &amp;amp;\Rightarrow\quad&#xA;  &amp;amp;(d \cdot d)t^2 + 2(x \cdot d)t + (x \cdot x - r^2) &amp;amp;= 0 \tag{3}\\&#xA;\end{alignat}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Equation $3$ is a quadratic expression in $t$ (i.e. $at^2 + bt + c = 0$) where $$a = (d \cdot d)$$ $$b = 2(x \cdot d)$$ $$c = (x \cdot x - r^2)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This matches the code you posted, but the code is allowing spheres to be centered at an arbitrary point &lt;code&gt;C&lt;/code&gt;. The code then has this line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// f = E - C ; // Vector from center sphere to ray start&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which effectively translates the endpoint of the ray &lt;code&gt;E&lt;/code&gt; to a new endpoint &lt;code&gt;f&lt;/code&gt; so that we can now consider the sphere to be centered at the origin. The ray direction is unchanged.&lt;/p&gt;&#xA;" OwnerUserId="2941" LastActivityDate="2017-03-12T20:48:54.123" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4845" PostTypeId="2" ParentId="4838" CreationDate="2017-03-12T22:33:13.340" Score="2" Body="&lt;p&gt;You need to take your width and height and make them into a fraction, then &lt;a href=&quot;https://en.wikipedia.org/wiki/Irreducible_fraction&quot; rel=&quot;nofollow noreferrer&quot;&gt;reduce it&lt;/a&gt;. To do that, you'll need to find the &lt;a href=&quot;https://en.wikipedia.org/wiki/Greatest_common_divisor&quot; rel=&quot;nofollow noreferrer&quot;&gt;greatest common divisor&lt;/a&gt; of the numerator and denominator, and divide them both by that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now take the new fraction you got by dividing both the numerator and denominator by the greatest common divisor and do it again. Repeat this process until the greatest common divisor is 1. At that point you have your irreducible fraction and you can print it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way to do it is to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Euclidean_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Euclid's Algorithm&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's look at your top example, 1,000 x 1,200&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1,000 / 1,200 = ?&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We can see by examination that they both end in &quot;00&quot; so they're both divisible by 100. So start there:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1,000 ÷ 100 = 10&#xA;1,200 ÷ 100 = 12&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Next, we see that 10 and 12 are both even, so they're both divisible by 2:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;10 ÷ 2 = 5&#xA;12 ÷ 2 = 6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Finally, we see that 5 and 6 share no common factors besides 1. (This is because 5 is prime, so its only factors are 5 and 1. 6 has the factor 2 and 3, as well as 1 and 6.) So we have reached the end. The reduced fraction is 5 / 6.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;One More Thing&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might also want to be able to detect cases of irrational ratios, such as &lt;a href=&quot;https://en.wikipedia.org/wiki/Golden_ratio&quot; rel=&quot;nofollow noreferrer&quot;&gt;the golden ratio&lt;/a&gt;, which is quite popular in visual arts. Such a ratio will not be possible to divide into small integers, so checking whether &lt;code&gt;width / height&lt;/code&gt; is within some small distance of the golden ratio may be sufficient.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="231" LastEditDate="2017-03-13T00:44:50.290" LastActivityDate="2017-03-13T00:44:50.290" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4846" PostTypeId="2" ParentId="336" CreationDate="2017-03-13T02:41:03.990" Score="4" Body="&lt;p&gt;Yes, it is possible.  Remember that a shift in space is equivalent to a linear-phase multiplication in frequency.  A rotation can be accomplished by a shearing operation in one direction followed by a shearing operation in the perpendicular direction followed by a final shear in the original direction (Alan Paeth, ``A Fast Algorithm for General Raster Rotation,'' Proceedings of Graphics Interface 1986.  Larkin et al. have shown how to take this concept and turn it into 1D FFTs multiplied by linear-phase terms, another set of perpendicular 1D FFTs followed by linear-phase multiplication, followed by a final set of 1D FFTs, etc., in the original direction (&quot;Fast Fourier method for the accurate rotation of sampled images&quot;, Optic Communications, 1997).  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternately, you can definitely rotate the Fourier matrix to accomplish rotation.  But you have to keep in mind that the rotation must be around the origin in DFT space.  Since the DFT is periodic, you have to circularly shift the array to the center, rotate around that, and then shift back.  Even then it induces a rotation of the image around the origin (upper left corner), accounting for the fact that the image itself is now treated by the DFT as if it is periodic.&lt;/p&gt;&#xA;" OwnerUserId="6227" LastActivityDate="2017-03-13T02:41:03.990" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4847" PostTypeId="1" AcceptedAnswerId="4855" CreationDate="2017-03-13T10:39:27.830" Score="3" ViewCount="306" Body="&lt;p&gt;For rendering an indoor scene where light source is skylight coming in through&#xA;the window opening, one can consider the window polyline as the light &#xA;source, with the sky distribution, in direct lighting calculation. And sample&#xA;the window area(or solid angle).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It works as long as it's just an opening. Once a glazing is introduced I cannot figure out how to do direct lighting(in a path tracer) correctly. Shadow rays either are transmitted or reflected. I guess the transmitted ray needs to be traced again but this is not easy I suppose(as the the Brdf.SampleDirection method returns only direction), considering also that it might be a double &#xA;glazing which inter-reflection can happen too. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does any one have any suggestion or experience on this?&#xA;Thanks,&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="209" LastEditDate="2017-03-13T10:51:55.543" LastActivityDate="2017-03-14T15:17:08.503" Title="How to send shadow rays to window light source with glazing" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;pathtracing&gt;&lt;shadow&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4848" PostTypeId="1" CreationDate="2017-03-14T06:01:41.660" Score="7" ViewCount="659" Body="&lt;p&gt;After taking a look at the &lt;a href=&quot;https://www.wikiwand.com/en/M%C3%B6bius_strip#/Geometry_and_topology&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mobius strip&lt;/a&gt;, I noticed its equation is really simple and tried to add it into my Raytracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried a &quot;naive&quot; way by simply generating &lt;code&gt;N&lt;/code&gt; triangles attached to each other to obtain the desired shape. While this approach works, the result it not really pretty:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1w5Kx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1w5Kx.png&quot; alt=&quot;IMG&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(By the way I probably have an issue with my normals but I don't know where it comes from.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried it with PovRay and the result was astonishing. Perfectly smooth strip made in a far far FAR smaller time than mine. I'm pretty sure Povray is &lt;strong&gt;well&lt;/strong&gt; optimized but I also think it won't generate triangles like I did.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DN5p4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DN5p4.png&quot; alt=&quot;povray&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case that might help, here is the actual code used (C++) :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float step = .1f;&#xA;float halW = 0.5f;&#xA;&#xA;_facets.clear();&#xA;&#xA;auto lambda = [this] (float v, float t) {&#xA;  Vec_t p;&#xA;&#xA;  float cdv = Tools::Cos(2 * v);&#xA;  float sdv = Tools::Sin(2 * v);&#xA;  float ctv = Tools::Cos(v);&#xA;  float stv = Tools::Sin(v);&#xA;&#xA;  float c = 2 + t * ctv;&#xA;&#xA;  p.x = c * cdv;&#xA;  p.z = c * sdv;&#xA;  p.y = t * stv;&#xA;&#xA;  return p;&#xA;};&#xA;&#xA;for (float v = 0.f; v &amp;lt; Globals::PI; v += step)&#xA;{&#xA;  if (v &amp;gt; Globals::PI)&#xA;    v = Globals::PI;&#xA;&#xA;  for (float t = -halW; t &amp;lt; halW; t += step)&#xA;  {&#xA;    if (t &amp;gt; halW)&#xA;      t = halW;&#xA;&#xA;    Vec3 p1 = lambda(v, t);&#xA;    Vec3 p2 = lambda(v + step, t);&#xA;    Vec3 p3 = lambda(v, t + step);&#xA;    Vec3 p4 = lambda(v + step, t + step);&#xA;    _facets.emplace_back(p1, p2, p3);&#xA;    _facets.emplace_back(p3, p2, p4);&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I handle parametric surfaces like &lt;a href=&quot;https://www.wikiwand.com/en/M%C3%B6bius_strip#/Geometry_and_topology&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt; in raytracing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;&#xA;After letting the above algorithm run for about 20 hours, I got a way prettier result (with 3 torsions instead of 1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://cdn.discordapp.com/attachments/148687431728627713/291972504245895178/unknown.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://cdn.discordapp.com/attachments/148687431728627713/291972504245895178/unknown.png&quot; alt=&quot;Better result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5770" LastEditorUserId="5770" LastEditDate="2017-03-16T16:59:54.710" LastActivityDate="2017-03-16T16:59:54.710" Title="How to handle a parametric equation in raytracing?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;c++&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4849" PostTypeId="2" ParentId="4848" CreationDate="2017-03-14T09:44:21.260" Score="6" Body="&lt;p&gt;&lt;em&gt;Many&lt;/em&gt; years ago I worked on a ray tracer that handled parametric surfaces, so this is unlikely to be state of the art, but, IIRC, I used a combination of interval arithmetic with (binary?) subdivision and Newton-Rhapson.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The interval arithmetic + subdivision constructed (conservative) bounding boxes which could be used for intersection rejection. I think I &lt;em&gt;may&lt;/em&gt; also have used interval arithmetic on the 1st derivative to help determine when it was safe to launch into Newton-Rhapson. Typically the Newton steps converged very rapidly. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also pre-dice your parametric surfaces and put them into an acceleration structure (Voxel grid/BVH) to speed up the process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This work was based on/inspired by Daniel Toth's 1985 paper &lt;a href=&quot;https://www.cs.drexel.edu/~david/Classes/CS586/Papers/p171-toth.pdf&quot; rel=&quot;noreferrer&quot;&gt;&quot;On Ray Tracing Parametric Surfaces&quot;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-03-14T09:44:21.260" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4850" PostTypeId="2" ParentId="4848" CreationDate="2017-03-14T09:47:48.797" Score="2" Body="&lt;p&gt;In general when doing parametric in a ray tracer you need a solution for &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\begin{cases}  P = v * t + C \\&#xA; P = f(u,v)&#xA;\end{cases}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for the lowest $t$ where $f(u,v)$ is your parametric function $C$ is the camera position and $v$ is the ray direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a few general ways, for example if you can tell whether 2 points are on the same side or not you can take 2 points on the ray on opposite sides and binary search until you have the depth. You can find the first pair by marching along the ray.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-03-14T09:47:48.797" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4851" PostTypeId="1" AcceptedAnswerId="4852" CreationDate="2017-03-14T09:52:59.677" Score="2" ViewCount="38" Body="&lt;p&gt;I don't completely understand the last part of the MVP matrix (projection).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In orthographic projection we simply scale the view volume into the default view volume (+-1 on all axis).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In perspective projection we scale and skew the view frustrum into the default view volume (+-1 on all axis) which causes non-uniform foreshortening giving the appearance of perspective that we're used to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now, regardless of which type of projection we have used, we have the default viewing volume (+-1 on all axis). So how do we get from this cube to an image on the screen?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that we need this volume for the z-buffer. But how are points (anywhere in this volume) finally transformed from 3d to 2d and is it the same procedure for orthographic projection as it is for perspective projection?&lt;/p&gt;&#xA;" OwnerUserId="6230" LastActivityDate="2017-03-14T10:01:29.640" Title="Getting from the default view volume to an image on the screen" Tags="&lt;transformations&gt;&lt;projections&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4852" PostTypeId="2" ParentId="4851" CreationDate="2017-03-14T10:01:29.640" Score="2" Body="&lt;p&gt;The mapping from NDC space to screen space is orthographic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The x is mapped linearly from [-1, 1] to [0,viewport width], same with y and viewport height.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This mapping happens after the projection matrix has been applied and the divide by w happened. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-03-14T10:01:29.640" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4853" PostTypeId="1" CreationDate="2017-03-14T14:23:55.450" Score="4" ViewCount="326" Body="&lt;p&gt;I'm learning Ray Tracing using &lt;a href=&quot;https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-837-computer-graphics-fall-2012/assignments/MIT6_837F12_assn4.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this MIT tutorial&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've heard Ray Tracing only in the context of lighting. I.e. I understand that ray casting is used to light an object that has been already drawn. However, I've also seen ray casting in the context of just drawing the picture (not lighting). So which one are rays about?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the concept of &quot;ray&quot; really?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;E.g. in that tutorial one draws the picture like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;image.SetPixel( x, y, pixelColor );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;pixelColor&lt;/code&gt; has been acquired from the Ray Caster. But I read this to mean that &lt;code&gt;pixelColor&lt;/code&gt; already has lighting information.&lt;/p&gt;&#xA;" OwnerUserId="6029" LastEditorUserId="231" LastEditDate="2017-03-19T00:49:34.497" LastActivityDate="2017-04-24T10:17:59.363" Title="What's the concept of &quot;Ray&quot; really?" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;ray&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4854" PostTypeId="2" ParentId="4853" CreationDate="2017-03-14T15:08:38.553" Score="6" Body="&lt;p&gt;A &lt;em&gt;ray&lt;/em&gt; is just a semi-infinite line, and &lt;em&gt;casting&lt;/em&gt; the ray finds intersections between the ray and an object in the scene. It doesn't just tell you the position in space that the ray intersected the object: it also tells you the texture co-ordinates of that point on the object, the surface normal and tangent, and (depending on the algorithm you use) filter widths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in a ray-tracer, there are different kinds of rays. &lt;em&gt;Primary rays&lt;/em&gt; and reflection and refraction rays use their intersection to run a shader and compute a fragment colour. They also fire &lt;em&gt;shadow rays&lt;/em&gt; at lights, which don't compute a colour but just tell you whether any object is shadowing the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So rays are about finding the objects which are in the scene, and shading those objects to make an image. They're also about finding the reflections and refractions on shiny objects. They are used to draw shadows. They're also used for more advanced effects like ambient occlusion and photon tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is one of the main conceptual advantages of ray-tracing over scanline rasterisation: instead of having to use different techniques for computing reflections, shadows, and all those other effects, the same core ray-cast algorithm can be used recursively to compute the whole image.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-03-14T15:08:38.553" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4855" PostTypeId="2" ParentId="4847" CreationDate="2017-03-14T15:17:08.503" Score="5" Body="&lt;p&gt;Most renderers allow you to set a flag on an object to make shadow rays ignore it (so it won't cast shadows). You could set this flag on your glazing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, it's not unusual to make it so that refraction is disabled on shadow rays: that is, if they would be transmitted by an object, a child ray is traced in the same direction, ignoring any refraction that would be caused by the ior of the material. Although this gives wrong results for objects such as crystal balls, you need photon mapping or similar to get good results for that situation anyway. Just tracing a child ray is an easy way of making objects like stained-glass windows give simple coloured shadows.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-03-14T15:17:08.503" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4856" PostTypeId="2" ParentId="4842" CreationDate="2017-03-14T15:21:24.343" Score="1" Body="&lt;p&gt;You shouldn't solve for $\cos^{-1}(\theta)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ambient component is as follows (we are assuming the ambient light is white):&#xA;$$ambient\ color = (ambient\ light\ color)(ambient\ intensity)(diffuse\ color) = (1,1,1)(0.1)(0.6,0.7,0.8) = (0.06,0.07,0.08)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The diffuse component is as follows:&#xA;$$diffuse\ color = (light\ color)(light\ intensity)(diffuse\ color)(\cos(\theta)) = (1,1,1)(1)(0.6,0.7,0.8)(0.8) = (0.48,0.56,0.64)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we just need to add them up:&#xA;$$final\ intensity = (diffuse\ color) + (ambient\ color) = (0.06,0.07,0.08) + (0.48,0.56,0.64) = (0.54,0.63,0.72)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information, here's a pretty decent &lt;a href=&quot;https://learnopengl.com/#!Lighting/Basic-Lighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;summary&lt;/a&gt; of various lighting calculations.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2017-03-14T15:21:24.343" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4857" PostTypeId="1" CreationDate="2017-03-15T10:33:48.220" Score="0" ViewCount="88" Body="&lt;p&gt;Which 3D object properties should be affected by distance in VR and other 3D applications and how important is it that they are changed?&#xA;For example the level of detail, colour (?)... &lt;/p&gt;&#xA;" OwnerUserId="4646" LastEditorUserId="4646" LastEditDate="2017-03-20T12:00:01.647" LastActivityDate="2017-03-24T06:01:32.157" Title="Which 3D object properties should be affected by distance?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4858" PostTypeId="1" CreationDate="2017-03-15T11:14:17.397" Score="3" ViewCount="58" Body="&lt;p&gt;I'm wondering what metrics I could use to decide upon the visibility of a 3D object in VR or other 3D applications and what advantages each has.&lt;/p&gt;&#xA;" OwnerUserId="4646" LastActivityDate="2017-03-15T11:33:40.107" Title="What metrics are used for deciding if a 3D object is visible?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4859" PostTypeId="2" ParentId="4858" CreationDate="2017-03-15T11:33:40.107" Score="4" Body="&lt;p&gt;Visibility for culling (or passing to the render pipeline) is very sensitive to false negatives. False positives are not a big deal because when rendering the Z buffer will take care of that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that one very simple metric is simply assuming that it's always visible. If any other metric gives too much overhead than simply processing the object requires then this is a good fallback. For example in a redering api with command buffers rebuilding the command buffer would be too expensive compared to the processing required to render a single object to warrant it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next option is to see if the object is in front or behind the camera, This can be done with a dot product with the view vector and the forward most point of the bounding volume of the object. If it's negative then the object is behind the camera and you can skip it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next is using the view pyramid. From the camera you extrude the frustum and do a collision check between it and the object. If it collides then the object is visible. Instead of 1 plane you now check against 4 and the object must pass All 4 to be considered visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next you can take into account when the object is fully occluded by another object. This can be done by various methods. With static geometry you can partition the world and say for each section which other sections you can see from it. You can also ask the GPU to do occlusion queries which basically means &quot;did any fragments of these render commands pass the depth test&quot;. But getting the information back from the GPU typically has a decently long latency, by which time the camera may have moved.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-03-15T11:33:40.107" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4862" PostTypeId="1" CreationDate="2017-03-15T17:07:46.003" Score="2" ViewCount="285" Body="&lt;p&gt;So I'm reading some Ray-Sphere interaction codes and in one there was &quot;texCoord&quot;, which I think means &quot;texel coordinate&quot;. However, what does this refer to &quot;visually&quot;?&lt;/p&gt;&#xA;" OwnerUserId="6029" LastActivityDate="2017-03-15T17:10:12.380" Title="What's a &quot;texel coordinate&quot;?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4863" PostTypeId="2" ParentId="4862" CreationDate="2017-03-15T17:10:12.380" Score="4" Body="&lt;p&gt;It stands for texture coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's a 2D value between 0 and 1 to indicate where in the texture to sample from for the color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For sphere that means creating a map projection to map the curved surface to the flat plane, a simple option is to use the lat/long remapped to 0-1 though that gives awful distortion at the poles.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-03-15T17:10:12.380" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4866" PostTypeId="2" ParentId="4842" CreationDate="2017-03-16T09:44:48.307" Score="0" Body="&lt;p&gt;Flat Shading:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = Ia x Ka + Fatt x Il x (Kd x (N x L))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Final intensity = ambient reflection x ambient reflection coefficient + (attenuation x incident light intensity x (diffusive reflection coefficient x (surface normal x Light intensity))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;He told me that because ambient reflection coefficient and attenuation are not given, I can forget about it. Also specular light contribution need not be considered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The surface normal is:&#xA;A = (0, 2, 1) B = (3, 0, 1) O = (0, 0, 0)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;U = A - O = (0, 2, 1) &#xA;V = B - O = (3, 0, 1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Surface normal = U x V (cross-product) = (2, 3, -6)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = 0.1 + (1, 1, 1) x ((0.6, 0.7, 0.8) x ((2, 3, -6) x (0, 3, 4)))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = 0.1 + (1, 1, 1) x ((0.6, 0.7, 0.8) x (0, 9, -2.4))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = 0.1 + (1, 1, 1) x (0, 6.3, -1.92)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I = (0.1, 6.4, -1.82) = RGB intensity values&lt;/p&gt;&#xA;" OwnerUserId="5513" LastActivityDate="2017-03-16T09:44:48.307" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4867" PostTypeId="2" ParentId="4805" CreationDate="2017-03-16T15:09:31.147" Score="0" Body="&lt;p&gt;I solved it myself. Here is a result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/18HYq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/18HYq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The example is out of this post: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4507/finding-the-nearest-neighbor-of-polygons&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5828" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2017-03-16T15:09:31.147" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4868" PostTypeId="1" CreationDate="2017-03-16T20:31:41.430" Score="3" ViewCount="826" Body="&lt;p&gt;Apologies for posting two questions in one post, but as they are relevant I kept them in one.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Question 1&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;In the definition of multi sample estimator that Veach has defined, the integrand is the same for all the n sampling strategies. If this is so, then is it not the case that, in direct lighting, those shadow rays that miss the light geometry are to be considered, as the integrand is not zero (and the PDF is also not zero) but has some value, not from the light of course, but due to the surfaces that have occluded the light? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would missing those contributions not be the same as partitioning the integral in sampling the lights and BRDF, whereas MIS claims to give &#xA;a solution without partitioning the integral?&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Question 2&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;My main problem is to sample adequately part of the scene where light comes from the external obstructions (marked as P2 in the image). The only source of light is skylight coming in through the window opening. P1 is PDF for sampling window area (or solid angle) to get direct light; P2 is same PDF but to account for external surfaces contributions; and P3 is BRDF sampling for indirect light from indoor surfaces. I could rely just on BRDF sampling to account for external surfaces but as their contribution is large (illuminance from infinite source) I want to explicitly account for them.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't intend to partition the integral into three regions as it ends up to have recursive calls to get the contribution of external hits; it also slows down and makes the code too complex. I therefore guess I need to use MIS to account for indirect contribution of externals surfaces but am not clear how it is to be done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/N92zY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N92zY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to take one sample from BRDF P3 with $W3 = p_3/(p_3+p_2)$, and one from P2 PDF with $W2 = p_2/(p_2+p_3)$. I am not clear how to evaluate the integrand for samples taken from P2 distributions. This is the pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for each measurement point x {&#xA;    while(1){&#xA;        //P1&#xA;        //DirectLight routine uses P1 if x is indoor hit or &#xA;        //sampling hemisphere if x is outdoor, to get direct light from sky &#xA;        totalEstimate += DirectLight(x) * throughput&#xA;&#xA;        //P2&#xA;        y = Trace one sample from P2&#xA;        if y is external surface {&#xA;           weight = p2(y) / (p2(y)+p3(y))&#xA;           totalestimate += DirectRadiance(y) * weight * brdf(x) * dot(x, Nx) / P2  &#xA;        }&#xA;&#xA;        //P3&#xA;        z = Trace one sample form P3&#xA;        if z is a hit{&#xA;            weight = p3(z) / (p3(z)+p2(z))&#xA;            throughput *= weight * brdf(x) * dot(x, Nx) / P3  &#xA;        }&#xA;        else &#xA;            break;&#xA;&#xA;        //using russian roulette to terminate the path.. &#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I tried this but had increase in variance. The measurement points are few points in room floor area and a contour line is drawn based on a the values. The above gives higher variance than using only P1 and P3 with no MIS weights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This excersise in PBRT seems to be relevant to this question. So I post it here&#xA;in case it helps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ABK7X.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ABK7X.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="2479" LastEditDate="2017-03-20T07:55:17.530" LastActivityDate="2017-03-20T07:55:17.530" Title="Efficiently sampling specific surfaces using MIS in path tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4869" PostTypeId="1" AcceptedAnswerId="4870" CreationDate="2017-03-17T07:35:31.833" Score="2" ViewCount="1080" Body="&lt;p&gt;Is there an equation for flat shading?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To my understanding, it is this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$I = I_a \times K_a + F_{att} \times  I_l \times  (K_d \times  (N \times  L))$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Final intensity = ambient reflection x ambient reflection coefficient + (attenuation x incident light intensity x (diffusive reflection coefficient x (surface normal x Light intensity))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I have only found one source for this equation (my lecture slides).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any other sources to confirm this is the equation for flat shading? I can't find one.&lt;/p&gt;&#xA;" OwnerUserId="5513" LastEditorUserId="231" LastEditDate="2017-03-19T01:00:58.800" LastActivityDate="2017-03-19T01:00:58.800" Title="What is the equation for flat shading?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4870" PostTypeId="2" ParentId="4869" CreationDate="2017-03-17T09:19:17.510" Score="3" Body="&lt;p&gt;I don't think having a equation for flat shading is meaningful as such. Mainly because the formula for flat shading is same as the formula for the model the flat shading is emulating. The difference is that flat shading is operating per primitive rather than per point or per vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So there can in fact exist multiple formulas that work differently but are still all flat shading.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-03-17T09:19:17.510" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4871" PostTypeId="2" ParentId="4853" CreationDate="2017-03-17T14:06:30.177" Score="2" Body="&lt;p&gt;I'd like to leave a longish comment with pictures on the drawing aspect. Raytracing is not limited to computer graphics you can and often do see see artists manually raytrace to figure out intersections of shapes on paper with a ruler or even freehand by elbow twisting*.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also useful for many physical sciences like mechanical engineering and surveying. Or anywhere where you can use geometry to solve your problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While @DanHulme correctly surmises that the mathematical definition of a ray is just a line with a starting point and no ending point (goes to infinity). This is not really what people do, instead it's defined that way to be rigorous. In general it's just a line that goes far enough for the job, and we aren't really interested in the other end but rather how the line interacts with something. Infinity is just a safe way of saying it will in fact interact if possible. Mathematicians are very particular about stuff like that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WwdR3.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WwdR3.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: An example of manually tracing shadows of objects with ruler and pen for an as of yet unfinished answer on the subject &lt;a href=&quot;https://graphicdesign.stackexchange.com/a/86754/18306&quot;&gt;here&lt;/a&gt;. Mainly here because I had spent yesterday evening doing the rays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you see you would use rays whenever you try to find a geometric intersection between two geometric primitives. It's not only useful for shadows, it's for anything where you can intersect two things, with a starting point somewhere. So tracing can be used to find the shape of 2 intersecting surfaces, manually drawing perspective images, volumetric problems, rendering implicit surfaces like metaballs solving mathematical functions numerically etc etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;* The definition of what now is called a ray was first described by Euclid's Elements about 300 bc. Which predates computers by a safe(ish) margin.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorDisplayName="user246" LastEditDate="2017-04-24T10:17:59.363" LastActivityDate="2017-04-24T10:17:59.363" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4872" PostTypeId="2" ParentId="4853" CreationDate="2017-03-17T15:28:38.707" Score="0" Body="&lt;p&gt;Keeping in mind the definition of wave-front:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Upuwr.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Upuwr.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now quoting from &lt;a href=&quot;http://www.springer.com/gp/book/9789401065207&quot; rel=&quot;nofollow noreferrer&quot;&gt;Image Acquisition&lt;/a&gt; book:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;A &lt;strong&gt;ray&lt;/strong&gt; of light is a straight line connecting the wavefront normals in a series of radiative wavefronts. Connecting together the like-angle normals of the wavefronts emanating from a source defines a ray of light from that source. A collection of rays emanating from a &lt;em&gt;point&lt;/em&gt; is referred to as a &lt;strong&gt;pencil&lt;/strong&gt; of light, while a group of pencils emanating from a &lt;em&gt;finite-area patch&lt;/em&gt; is called a &lt;strong&gt;beam&lt;/strong&gt; of light.&quot;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2017-03-17T15:28:38.707" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4873" PostTypeId="2" ParentId="4868" CreationDate="2017-03-18T00:22:37.870" Score="2" Body="&lt;p&gt;I will not answer your questions directly, but will try to change your mindset a bit. I hope got your intentions reasonably well... &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The usual way the path tracing is implemented is that the reflection integral is split into direct and indirect illumination and they are estimated separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The direct illumination&lt;/strong&gt; can be estimated using more sampling strategies which are combined together using the multi-sample multiple importance sampling method by Veach. Typically, there is just BSDF sampling and light sampling used, but you can also add things like light portals sampling and other more sophisticated stuff. I guess this is where you are headed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The indirect illumination&lt;/strong&gt; is usually estimated by just one sampling strategy (typically BSDF sampling) because you want to avoid exponential growth of recursive paths count. That's the reason why path tracing has poor performance for indirect illumination reflected/refracted through glossy/specular materials.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A nice thing about the split integral is that you can share samples between the direct and indirect integral. If you have two integrals over the same domain and have a sampling strategy that can be used for both, then you can generate a sample to estimate the first integral and then use the same sample for the second integral as well. There is no problem with correlated samples here because we have two separate computations. In practice you generate a BSDF sample with some PDF, shoot a ray in that direction and use the intersection point to estimate both direct and indirect integral separately.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;PS: I guess that for indirect illumination estimator you could possibly use the one-sample multiple importance sampling method by Veach to incorporate the light portals and other sampling strategies, but I have some doubts about the efficiency of the resulting estimator, especially when reusing the samples for the direct illumination integral.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2017-03-18T14:42:15.503" LastActivityDate="2017-03-18T14:42:15.503" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4874" PostTypeId="1" CreationDate="2017-03-18T07:55:13.137" Score="-1" ViewCount="648" Body="&lt;p&gt;I'm using Urho3D on Raspberry Pi, but the following questions apply to all platforms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What should I do in order to reduce the load of online real-time rendering of the game? Does building/compiling/rendering the game (before running it) makes it easier and lighter to be run afterwards?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When making animations with 3dsmax, we use high-end computers to design the animation and render it. After that, any low-end and simple computer can play the animation. Now can we use a similar approach? Can I build/compile/render the game in a high-end machine and run the game in a low-end machine?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is exactly the difference between building/compiling/rendering when designing a game, and running/real-time-rendering when playing the game?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does a game needs rendering after designing? Or all the renderings are left to the playing time!?&lt;/p&gt;&#xA;" OwnerUserId="6253" LastActivityDate="2017-03-21T11:10:39.660" Title="Fundamental Questions: Building vs Compiling vs Rendering vs Coding vs Running?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4875" PostTypeId="1" AcceptedAnswerId="4876" CreationDate="2017-03-19T18:31:12.817" Score="2" ViewCount="345" Body="&lt;p&gt;If you clear the color buffer and draw a triangle, you have nothing in the buffer that is shown in the screen and a triangle in the other buffer, so you have to swap buffers to show the triangle. If you swap buffers, you have a triangle in your screen and a empty color buffer in the other side. If you swap buffers again you should see and empty screen because you changed the buffer with the triangle by the other empty buffer. Instead of this, the triangle is shown again. Why?&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="5852" LastEditDate="2021-01-18T08:37:03.180" LastActivityDate="2021-01-18T08:37:03.180" Title="Swap buffers twice does not show the first scene" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="4876" PostTypeId="2" ParentId="4875" CreationDate="2017-03-19T20:32:25.210" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;If you swap buffers, you have a triangle in your screen and a empty color buffer in the other side.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, you do not. Buffer swapping does not necessarily mean that the current contents of the front buffer are preserved. When you do a swap, the contents of the back buffer become the front buffer, but the state of the back buffer is &lt;em&gt;undefined&lt;/em&gt; after the swap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some implementations use a true swap, where the two buffers really are switched. Other implementations copy the data from the back buffer on a swap, leaving the back buffer as whatever was there before. Still others could do something else.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-03-19T20:32:25.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4877" PostTypeId="1" CreationDate="2017-03-19T20:59:46.397" Score="9" ViewCount="999" Body="&lt;p&gt;I'm writing a path tracer and, for the moment, spectra related data (spectral power distributions and spectral reflectance curves) are stored as RGB tuples. In the Cook-Torrance specular BRDF I am using the Schlick's approximation for the Fresnel term:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$F(\theta) = R_0 + (1-R_0)(1-\cos \theta)^5$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$R_0 = \left( \frac{\eta_1 - \eta_2}{\eta_1 + \eta_2} \right)^2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Schlick's approximation is fast and very convenient in the current context (&lt;em&gt;e.g.&lt;/em&gt; for conductors, $R_0$ is simply the RGB tuple of the normal incidence reflectance of the metallic material).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, despite being fast, Schlick's approximation is very simple (it does not take into account, for instance, the extinction coefficients of conductors). Some path tracers use much more accurate Fresnel formulations. &lt;a href=&quot;http://www.pbrt.org&quot; rel=&quot;noreferrer&quot;&gt;PBRT&lt;/a&gt;, for instance, uses the following equations for the Fresnel terms:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Fresnel term for conductors&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$r^2_{||} = \frac{(\eta^2 + k^2) \cos \theta_i^2 - 2 \eta \cos \theta_i + 1}{(\eta^2 + k^2) \cos \theta_i^2 + 2 \eta \cos \theta_i + 1}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$r^2_{\perp} = \frac{(\eta^2 + k^2) - 2 \eta \cos \theta_i + \cos \theta_i^2}{(\eta^2 + k^2) + 2 \eta \cos \theta_i + \cos \theta_i^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Fresnel term for dielectrics&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$r_{||} = \frac{\eta_t \cos \theta_i - \eta_i \cos \theta_t}{\eta_t \cos \theta_i + \eta_i \cos \theta_t}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$r_{\perp} = \frac{\eta_i \cos \theta_i - \eta_t \cos \theta_t}{\eta_i \cos \theta_i + \eta_t \cos \theta_t}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For both equations, the resulting Fresnel reflectance is obtained with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ F=\frac{r^2_{||} + r^2_{\perp}}{2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of spectral path tracers, I believe that the use of the above Fresnel formulations would be straightforward (just a matter of feeding the formulas with already tabulated IORs and $\kappa$ data - such as those available at &lt;a href=&quot;https://refractiveindex.info&quot; rel=&quot;noreferrer&quot;&gt;https://refractiveindex.info&lt;/a&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, how could these formulations be used in a RGB-based path tracer? Is this even possible (I believe so, because these are the only Fresnel formulations used by PBRT and it works both with spectral and RGB-based spectral data - at least, to the best of my knowledge)? So, if yes, how to generate the IOR and $\kappa$ triplets to be used in the above formulations? If not, what would be the alternatives (with the exception of going fully spectral)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've found a potential answer to the question and, despite missing technical soundness (that's why I've just added it as an update and not as the actual answer), I am posting it here in the case someone may be interested or may have comments to add. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to this &lt;a href=&quot;https://docs.chaosgroup.com/display/OSLShaders/Complex+Fresnel+shader&quot; rel=&quot;noreferrer&quot;&gt;OSL Shader&lt;/a&gt;, at least the complex Fresnel term (for conductors), in the context of an RGB-based path tracer, can be evaluated by simply substituting $\eta$ and $\kappa$ by those values corresponding to the R, G and B &quot;representative&quot; wavelengths. Since R, G and B are not narrow spikes on the electromagnetic spectrum, the &quot;representative&quot; wavelength may be a little different from one implementation to another. I've seen that the most common values for these representative wavelengths are 0.65$\mu$m for Red, 0.55$\mu$m for Green and 0.45$\mu$m for Blue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, suppose that we want to render the gold material. The $\eta$ and $\kappa$ values of gold, for our representative wavelengths (0.65$\mu$m, 0.55$\mu$m and 0.45$\mu$m), can be obtained from &lt;a href=&quot;https://refractiveindex.info&quot; rel=&quot;noreferrer&quot;&gt;https://refractiveindex.info&lt;/a&gt;, and will be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\eta_{gold} = ( 0.15557, 0.42415, 1.3831 )$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\kappa_{gold} = ( 3.6024, 2.4721, 1.9155 )$$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, it is just a matter of evaluating the Fresnel reflectance for each color channel:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$Fresnel_{Red} = F(\eta[0],\kappa[0], \theta)$$&#xA;$$Fresnel_{Green} = F(\eta[1],\kappa[1], \theta)$$&#xA;$$Fresnel_{Blue} = F(\eta[2],\kappa[2], \theta)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have used this complex Fresnel equation within my Cook-Torrance BRDF, whose formulation can be seen &lt;a href=&quot;https://computergraphics.stackexchange.com/q/4394/5681&quot;&gt;here&lt;/a&gt;, and I've obtained the following results (I've compared them to reference images rendered with &lt;a href=&quot;http://www.mitsuba-renderer.org/&quot; rel=&quot;noreferrer&quot;&gt;Mitsuba&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mSf98.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mSf98.png&quot; alt=&quot;Gold. Left: Mitsuba. Right: My renderer.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Above image: Gold material rendered with (left) Mitsuba and (right) my renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EfU5C.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EfU5C.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Above image: Copper material rendered with (left) Mitsuba and (right) my renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The images generated by my path tracer are noisier because it uses only BRDF importance sampling. With respect to copper, the images are, at least visually, almost identical. With respect to gold, colors are slightly different. I have made some experiments, and observed that very small changes on the values of the &quot;representative wavelengths&quot; might have significant impact on the final color. Thus, the color difference regarding the rendering of the gold material could be eventually attributed to differences regarding the &quot;representative&quot; wavelengths used by each renderer for R,G and B.&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorUserId="-1" LastEditDate="2017-04-13T13:00:43.660" LastActivityDate="2021-01-11T12:22:59.623" Title="More accurate Fresnel approximation for a RGB-based Path Tracer" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4878" PostTypeId="1" CreationDate="2017-03-20T02:39:18.593" Score="6" ViewCount="3427" Body="&lt;p&gt;I'm working on my own engine and I'm struggling to find any techniques that give okay-ish reflections in realtime on dynamic scene.&#xA;So far the only technique I found that work in real time on dynamic scene is SSR but it's really heavy and have a lot of bias.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea of having multiple cubemaps and updating them in real time crossed my mind but because that mean re-rasterising the scene that also mean that every cubemap updated in realtime is a shadow casting that I can't do.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is: is there another technique other than reflection probe (cubemap) or Screen Space Reflections ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The artstyle of the game where the engine will be used is based on a lot of &quot;almost mirror&quot; reflections and it's not PBR.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[Edit]&#xA;To be a bit more precise with what I'm searching:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I do not need more than one bounce.&lt;/li&gt;&#xA;&lt;li&gt;I do not want any baking that cannot be done at &quot;loading time&quot;.&lt;/li&gt;&#xA;&lt;li&gt;I prefer if the technique work with a per-pixel normal but if you&#xA;know a technique that work with a per-vertex normal I am also open.&lt;/li&gt;&#xA;&lt;li&gt;I am open to techniques that only work in specific cases (like tiny&#xA;scene, deferred rendering only etc...) as long as it meet other&#xA;requirements.&lt;/li&gt;&#xA;&lt;li&gt;If your technique is a feature of a global illumination technique I am&#xA;also open but I would prefer if it work stand alone.&lt;/li&gt;&#xA;&lt;li&gt;If it can easily support GGX it's better but not required.&lt;/li&gt;&#xA;&lt;li&gt;Inaccuracy is not a problem as long as it is predictable by the&#xA;artist&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5506" LastEditorUserId="5506" LastEditDate="2017-03-20T22:12:24.587" LastActivityDate="2018-03-04T19:55:29.637" Title="realtime dynamic reflections, which way to go?" Tags="&lt;opengl&gt;&lt;reflection&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4879" PostTypeId="1" CreationDate="2017-03-20T07:23:33.077" Score="3" ViewCount="120" Body="&lt;p&gt;The &lt;a href=&quot;http://pbrt.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;book&lt;/a&gt; omitted the explanation of &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/master/src/shapes/hyperboloid.cpp#L43&quot; rel=&quot;nofollow noreferrer&quot;&gt;the constructor of hyperboloid&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone give some explanations about:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Why the arguments are two points?&lt;/li&gt;&#xA;&lt;li&gt;What are the meanings of &lt;strong&gt;&lt;em&gt;ah&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;ch&lt;/em&gt;&lt;/strong&gt;?&lt;/li&gt;&#xA;&lt;li&gt;Why is there a while loop?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="48" LastEditDate="2017-05-23T15:13:59.847" LastActivityDate="2017-05-23T15:13:59.847" Title="The constructor of hyperboloid in pbrt-v3" Tags="&lt;rendering&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4880" PostTypeId="1" AcceptedAnswerId="4888" CreationDate="2017-03-20T07:54:09.673" Score="1" ViewCount="410" Body="&lt;p&gt;On page 89 of &lt;a href=&quot;http://people.inf.elte.hu/plisaai/pdf/David%20Wolff%20-%20OpenGL%204.0%20Shading%20Language%20Cookbook%20(2).pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;David Wolff - OpenGL 4.0 Shading Language Cookbook&lt;/a&gt; book, it suggests a way to set up up a Phong shader in the fragment stage. It lists some different matrices to pass via uniform, and I suspect I might be passing slightly incorrect matrices, as my results are a bit off. This could be from somewhere else in the code of course, but I'd rather know for sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These are the matrices used that I'm curious about:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform mat4 ModelViewMatrix;&#xA;uniform mat3 NormalMatrix;&#xA;uniform mat4 MVP;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What exactly are these? At the moment I'm sending these matrices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;view*model //ModelViewMatrix;&#xA;transpose(inverse(model))) //top 3x3 row of modelview&#xA;projection*view*model //MVP;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The shader &quot;works&quot;, but I can't get the lighting direction right.&lt;/p&gt;&#xA;" OwnerUserId="6255" LastEditorUserId="231" LastEditDate="2017-03-30T07:05:55.557" LastActivityDate="2017-03-30T07:05:55.557" Title="Am I passing the correct matrices for my shader? openGL/C++" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;glsl&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4881" PostTypeId="2" ParentId="4878" CreationDate="2017-03-20T09:12:07.217" Score="2" Body="&lt;p&gt;If there is only a single flat mirrored surface the solution is to render the scene twices, once normally. Afterwards you use stencil to mark the area where the mirror is visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then only drawing into that area you render the scene again but mirror it around the mirror's plane and cull any geometry on the other side of the mirror.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-03-20T09:12:07.217" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4882" PostTypeId="1" CreationDate="2017-03-20T18:30:25.327" Score="3" ViewCount="1103" Body="&lt;p&gt;&lt;strong&gt;Problem.&lt;/strong&gt; I have inherited a large C++ 3D graphics codebase (with some shader code). The program runs for about 1-5 minutes before crashing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Problem Data.&lt;/strong&gt; Using system tools, one can see a sharp rise in VRAM memory usage after the program launches, which eclipses into a crash. The same is true for GTT memory usage also (although the spike isn't quite as dramatic as with the VRAM).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Questions.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Does this (probably) mean that there is a memory leak in OpenGL shader code somewhere (as opposed to a leak in regular C++ code)?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Are there well-known tools for tracking down vram/gtt memory leaks (similar to the way that valgrind can be used to track down system memory usage)?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5225" LastEditorUserId="231" LastEditDate="2017-03-20T20:31:51.247" LastActivityDate="2017-03-23T17:11:24.093" Title="How can I chase down VRAM &amp; GTT memory leaks?" Tags="&lt;memory&gt;&lt;debugging&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4883" PostTypeId="2" ParentId="4882" CreationDate="2017-03-20T20:10:09.437" Score="3" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Probably not. Most OpenGL resources (framebuffers, vertex buffer objects, textures &amp;amp;c.) are controlled by host code (i.e. your C++ code), but take up GPU memory. OpenGL doesn't make it very easy to manage these resources, so it's most likely that they're being created but not deleted from your C++ code. For example, it might create a new VBO per frame but never delete the old VBOs.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I've never used it for this purpose, but if you're on Windows I'd suggest RenderDoc as your first stop. It's not specifically designed for debugging source - it intercepts GL and DX calls so you can see how the application is using the library even if you don't have the source - so it won't point you to the offending line of code, but it does show you what resources are being created and when, so it should at least tell you &lt;em&gt;what&lt;/em&gt; is being leaked and how often. It might even be that this is enough information is enough for you to guess the rest, or that the easiest way to continue after this is to do something by hand (e.g. printing &lt;code&gt;__FILE__&lt;/code&gt; and &lt;code&gt;__LINE__&lt;/code&gt; every time such a resource is created).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Sorry this is a bit of a half-answer but it's too big for a comment. I hope it gives you a good starting point at least.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-03-20T20:10:09.437" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4884" PostTypeId="1" AcceptedAnswerId="4885" CreationDate="2017-03-21T01:22:30.937" Score="1" ViewCount="216" Body="&lt;p&gt;This is what I'm doing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400&#xA;layout ( location = 0 ) in vec3 vertex_position;&#xA;layout ( location = 1 ) in vec3 vertex_normal;&#xA;&#xA;uniform mat4 ModelViewMatrix; //view*model&#xA;uniform mat3 NormalMatrix; //transpose(inverse(modelviewmatrix))) //top 3x3 row of model*view&#xA;uniform mat4 priv_mat; //projection*view*model&#xA;&#xA;out vec3 normal;&#xA;out vec3 position;&#xA;&#xA;void main()&#xA;{&#xA;  normal=normalize(NormalMatrix*vertex_normal);&#xA;  position=vec3(ModelViewMatrix*vec4(vertex_position,1.0));&#xA;  gl_Position=priv_mat*vec4(vertex_position,1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400&#xA;in vec3 normal;&#xA;in vec3 position;&#xA;&#xA;uniform vec4 LightPosition; // *needs to be in view-space* (view*lightpos)&#xA;uniform vec3 LightIntensity;&#xA;&#xA;uniform vec3 Kd;            // Diffuse reflectivity&#xA;uniform vec3 Ka;            // Ambient reflectivity&#xA;uniform vec3 Ks;            // Specular reflectivity&#xA;uniform float Shininess;    // Shininess&#xA;&#xA;vec3 ads( ){&#xA;    vec3 n = normal;&#xA;    vec3 s = normalize( vec3(LightPosition) - position ); &#xA;    vec3 v = normalize( vec3(-position)); &#xA;    vec3 r = reflect( -s, n );&#xA;return &#xA;    LightIntensity * &#xA;    ( Ka + &#xA;    Kd * max( dot(s, n), 0.0 ) +  &#xA;    Ks * pow( max( dot(r,v), 0.0 ), Shininess ) );&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;     gl_FragColor = vec4(ads(), 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But when I run it, I get this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Wuyui.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wuyui.png&quot; alt=&quot;shouldn&amp;#39;t the light be correct?&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where the light doesn't just come from the wrong spot, but it also doesn't change when I move the planet around, like so&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Fb7DY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Fb7DY.png&quot; alt=&quot;I can spin the asteroid, but the light doesn&amp;#39;t come from where it should&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where the diffuse value somehow gets the wrong direction? The math is beyond me however.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the diffuse value is calculated by getting the dot(s,n), where s is (lightposition - position), and position is (view * model * vertex_position). But like you can see, the results are not as expected&lt;/p&gt;&#xA;" OwnerUserId="6255" LastEditorUserId="6546" LastEditDate="2018-05-10T14:16:45.280" LastActivityDate="2018-05-10T14:16:45.280" Title="My (ADS) shader doesn't render the light direction correctly" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;c++&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="4885" PostTypeId="2" ParentId="4884" CreationDate="2017-03-21T07:35:21.053" Score="4" Body="&lt;p&gt;It seems to me, to be that your different positions and normals are not in the same space. Having them in the same space is important because else it might think the normal is pointing left while it should point to the right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't know what I mean with space in this context it's basically a coordinate system. Think about a grid, grid A. On grid A you have a point. Then you have another grid, grid B. You place grid A on grid B. If you move grid A around, the point on grid A does not move relative to grid A. It does however move relative to grid B, so they are different spaces. Hope that clarifies it for you, if not I am so sorry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You have a few coordinate spaces:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Local&lt;/strong&gt;: This is the vertex locations relative to the model position.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;World&lt;/strong&gt;: This is the location relative to the actual world origin.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;View&lt;/strong&gt;: This is the location relative to the camera.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You have the light position, vertex position and normal:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Light position is in world space.&lt;/li&gt;&#xA;&lt;li&gt;Normal is in world space, since you multiplied it with a model matrix making it go from local to world.&lt;/li&gt;&#xA;&lt;li&gt;Vertex position is in view space, since you put it to world space with the model matrix and then to view space with the view matrix.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Do you see that you have one of the three variables in a different space?&#xA;I have a strong feeling this is the problem and if you do not multiply the vertex position with the view matrix, in the vertex shader, this should be fixed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that this helps you and good luck!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="231" LastEditDate="2017-03-21T08:05:40.443" LastActivityDate="2017-03-21T08:05:40.443" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4887" PostTypeId="2" ParentId="4874" CreationDate="2017-03-21T11:10:39.660" Score="2" Body="&lt;p&gt;When you offline-render an animation, you take all the 3D information and turn it into a video file: a sequence of 2D images. The video file doesn't have any of the 3D information. A 3D game doesn't work this way because when you run the game, the 3D information needs to be present.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's quite common to use 3D models for making 2D games. Donkey Kong was a very early example of this: all the characters and backgrounds were modelled and animated in 3D, then rendered to 2D animations. These 2D animations were then used as sprites in the game. It allowed the sprites to look a lot more impressive than could be achieved with hand-made 2D sprites, using 3D ray-tracing techniques that weren't usable in real-time on the available hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More recently than that, it was common for cutscenes in 3D games to be pre-rendered videos. Cutscenes don't need to be interactive like the rest of the game. Using a pre-rendered video means that the artists can use expensive, non-real-time techniques to make the cutscenes look better than the interactive parts of the game can look. This isn't so popular nowadays: video files are big, and real-time rendering is a lot better than it used to be, so doing the cutscenes in real-time gives you lighting and shading that's almost as good, without having a fixed-resolution video file with compression artefacts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, there are some graphics techniques that use an offline pre-processing step to allow you to use techniques that wouldn't be possible in real-time (on the target hardware). The simplest example is texture compression: the compression is typically quite expensive, but it makes the textures use less memory, so you can have higher-quality textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your scene has static lighting, it's common to &lt;em&gt;bake&lt;/em&gt; lighting including global illumination and shadows into a texture, or into static light probes. This replaces the expensive lighting calculations with a simple texture look-up at run-time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, at the stage you're at, you shouldn't start worrying about any of these techniques yet. All of the rendering you'll be doing will be at run-time, so you need to optimize it to run at the target frame-rate on your target hardware.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-03-21T11:10:39.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4888" PostTypeId="2" ParentId="4880" CreationDate="2017-03-21T12:08:01.220" Score="3" Body="&lt;p&gt;I wasn't placing the lightposition into view space before passing it in. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 LightPosition_view=view*LightPosition; //put lp into view space with the rest&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When it comes to these things, you have to think in terms of spaces, and I was multiplying the view matrix and the model matrix, into view space, but not the lightposition itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that helps anyone else facing the same/similar problem.&lt;/p&gt;&#xA;" OwnerUserId="6255" LastEditorUserId="6255" LastEditDate="2017-03-29T20:33:10.220" LastActivityDate="2017-03-29T20:33:10.220" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4890" PostTypeId="1" AcceptedAnswerId="4898" CreationDate="2017-03-21T20:14:58.007" Score="5" ViewCount="194" Body="&lt;p&gt;I am building my own graphic engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My depth texture is significantly smaller than that of the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The low resolution depth map results in rigid shadow like this...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kniJw.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kniJw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am sure this is a common issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to learn &quot;go to&quot; technique to resolve this issue.&lt;/p&gt;&#xA;" OwnerUserId="6282" LastActivityDate="2017-03-23T17:30:51.187" Title="In forward rendering what's the go to technique to smooth out rigid shadow due to low resolution shadowmap texture?" Tags="&lt;shadow&gt;&lt;shadow-mapping&gt;" AnswerCount="3" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4891" PostTypeId="1" AcceptedAnswerId="4892" CreationDate="2017-03-22T10:01:56.727" Score="3" ViewCount="817" Body="&lt;p&gt;Using a shader that works like Phong, what would be the difference between painted Metal and plastic?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I seem to remember reading in books years ago, that I no longer have access to, the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Specular color for painted metal is same color as the paint.&lt;/li&gt;&#xA;&lt;li&gt;Specular color for plastic is always white.&lt;/li&gt;&#xA;&lt;li&gt;Ambient for metal should be darker than for plastic.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This also seems to correlate with what I see when I observe objects (in real world)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I tried to verify this also by checking the Internet, and found conflicting versions, some said the complete opposite.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what is true?&lt;/p&gt;&#xA;" OwnerUserId="6291" LastEditorUserId="6291" LastEditDate="2017-03-22T10:38:21.567" LastActivityDate="2020-05-25T11:01:59.143" Title="Phong: Real-time rendering of Metal and Plastic Materials" Tags="&lt;lighting&gt;&lt;real-time&gt;&lt;shading&gt;&lt;specular&gt;&lt;material&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4892" PostTypeId="2" ParentId="4891" CreationDate="2017-03-22T10:59:43.597" Score="5" Body="&lt;p&gt;Diffuse colours on materials typically come from within the material, while the specular colour is from the very surface. Coloured plastic materials are made by embedding particles of dye inside a colourless medium, so the diffuse colour is the colour of the dye, while the specular colour is white from the colourless surface. With metals, all of the reflection is at the surface, so the diffuse and specular colours are the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many different kinds of paint, but most commonly they're made like plastics: putting dye particles inside a white or colourless medium. Emulsion, acrylic, and enamel paints are all made this way. For this reason, painted or varnished metal surfaces have white specular as if they were plastic. There are some kinds of paint (metallic paints being the most obvious example) that aren't made this way, so it's not always true.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambient doesn't correspond to a physical property of the material: it's a cheap substitute for global illumination. It represents all of the indirect light that falls on the shading point and is reflected in the viewing direction. There's no physically correct way to set it: you should just do what looks best in your scene. That said, I'd offer a rule of thumb that shinier objects probably want less ambient, because less of the indirect light is going to be reflected diffusely to where you can see it. However, you might consider not using ambient at all, and pointing dim &lt;em&gt;fill lights&lt;/em&gt; at places that will come out too dark without indirect light.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-03-22T10:59:43.597" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4893" PostTypeId="1" CreationDate="2017-03-22T12:18:41.047" Score="2" ViewCount="32" Body="&lt;p&gt;I want to run audio FFT transformations on a GPU using, possibly, OpenCL.&#xA;What are the best optimization strategies for:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;converting audio signals to FFT;&lt;/li&gt;&#xA;&lt;li&gt;transfer them to the graphics card;&lt;/li&gt;&#xA;&lt;li&gt;compute those&lt;/li&gt;&#xA;&lt;li&gt;return the FFT into audio signal domain&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;if possible, i would like to do such a thing:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;with minimum latency possible;&lt;/li&gt;&#xA;&lt;li&gt;in real time;&lt;/li&gt;&#xA;&lt;li&gt;using really big fft window sizes;&lt;/li&gt;&#xA;&lt;li&gt;using really high sample rates and bit depth&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6098" LastEditorUserId="6098" LastEditDate="2017-03-22T12:54:23.400" LastActivityDate="2017-03-22T12:54:23.400" Title="Optimization Strategies for FFT sound transformations using GPGPU" Tags="&lt;gpgpu&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4894" PostTypeId="2" ParentId="4890" CreationDate="2017-03-23T02:51:41.967" Score="2" Body="&lt;p&gt;One technique is &lt;a href=&quot;http://www.graphics.cornell.edu/pubs/2001/FFBG01.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;adaptive shadow maps&lt;/a&gt; where you use a low resolution map for shadows that are rendered far away from the camera, a mid-resolution map for stuff that's in the mid range, and a high resolution map for stuff that's close.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-03-23T02:51:41.967" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4895" PostTypeId="1" CreationDate="2017-03-23T13:16:51.900" Score="-1" ViewCount="398" Body="&lt;p&gt;I'm playing around with OpenGL.  I wrote a small program to simulate a falling object.  My code looks like the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static GLfloat last = glfwGetTime();&#xA;GLfloat now = glfwGetTime();&#xA;GLfloat delta = now - last;&#xA;const GLfloat g = -9.8;&#xA;&#xA;velocity += g * delta;&#xA;distance += velocity * delta;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;now for some reason the object falls really slowly.  However, if I remove the &lt;code&gt;* delta&lt;/code&gt; from the last line&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;distance += velocity;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the simulation appears correct.  But if g = acceleration = $m/s^2$ then g * delta = $m/s$ = velocity.  Then velocity * delta = $m$, right? Where did I go wrong?&lt;/p&gt;&#xA;" OwnerUserId="6025" LastActivityDate="2021-01-16T05:04:30.513" Title="animating falling object" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4897" PostTypeId="2" ParentId="4878" CreationDate="2017-03-23T16:56:42.633" Score="2" Body="&lt;p&gt;If you want a real-time solution (no baking), and only need one reflection bounce, you can try to generate (or update) a cubemap of the scene every frame, as described in this &lt;a href=&quot;http://www.adriancourreges.com/blog/2015/11/02/gta-v-graphics-study/&quot; rel=&quot;nofollow noreferrer&quot;&gt;graphics study of GTA5&lt;/a&gt;  .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This solution should work in general cases (be sure to handle cases when the cubemap probe would be in an object of the scene).  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If rendering the six faces of the cube every frame seems too heavy, you can try for example to update only one face at a time. You can then use some kind of average function when updating the faces so that the change between each frame looks smoother.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is only an idea, there are many other solutions that one can think of.&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:55:29.637" LastActivityDate="2018-03-04T19:55:29.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4898" PostTypeId="2" ParentId="4890" CreationDate="2017-03-23T17:04:31.433" Score="3" Body="&lt;p&gt;Percentage Closer Filtering with some amount of blur (ie. a minimum filter size in texture space) is the most basic method I know of. For example, see &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems/gpugems_ch11.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;GPU Gems&lt;/a&gt;. My experience is that it is also quite robust.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-03-23T17:04:31.433" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4899" PostTypeId="2" ParentId="4882" CreationDate="2017-03-23T17:11:24.093" Score="3" Body="&lt;p&gt;Assuming your code has several locations that can allocate/release GPU memory, but you don't know which one leaks.&#xA;Maybe you can try to add a GPU memory monitor to that code. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When GPU memory is allocated in code, insert the buffer handle that was returned, the buffer size, the function/file name (or even better, stack trace) in a globally defined array.&#xA;When GPU memory is released, remove the handle of the buffer that was released from that array.&#xA;Run the application a while and exit before it crashes. Output the contents of the array before leaving. It shows information about the GPU memory that was not released. You might see some patterns leading you to understand how to fix the &quot;leak&quot;.&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2017-03-23T17:11:24.093" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4900" PostTypeId="2" ParentId="4879" CreationDate="2017-03-23T17:18:39.640" Score="1" Body="&lt;ol&gt;&#xA;&lt;li&gt;They must define it as a surface of revolution of a line segment.&lt;/li&gt;&#xA;&lt;li&gt;From the comments, they are probably the &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;c&lt;/em&gt; coefficients of the canonical hyperboloid equation. With a surface of revolution, &lt;em&gt;a&lt;/em&gt; == &lt;em&gt;b&lt;/em&gt; so no need to store &lt;em&gt;b&lt;/em&gt; separately.&lt;/li&gt;&#xA;&lt;li&gt;It's clearly related to figuring out &lt;em&gt;ah&lt;/em&gt; and &lt;em&gt;ch&lt;/em&gt; from the line segment. I can't say more precisely without working out the math involved. I'll leave that to someone with more free time.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-03-23T17:18:39.640" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4901" PostTypeId="2" ParentId="4890" CreationDate="2017-03-23T17:30:51.187" Score="3" Body="&lt;p&gt;Ah, shadows. They still are bothering after so many people spent years trying to improve them.&lt;br&gt;&#xA;Whether your engine is deferred or forward, the shadow pass should be quite the same, and suffer the same issues.&lt;br&gt;&#xA;You are correct, this is a famous problem. Some methods can improve these artifacts in some cases, see the methods mentioned already, or for example &quot;light-perspective-cascades&quot;, &quot;variance shadow maps&quot;, &quot;shadow atlas&quot; (compute optimal resolution for shadows of each light given available memory, and arrange them accordingly in a big buffer), &quot;moment shadow mapping&quot;.&lt;br&gt;&#xA;Some other workarounds are &quot;baking&quot; the shadow maps if light and object do not move.&#xA;I am missing a lot, but don't recall seeing a solution that works well when resolution / number of filtering passes / samples is restricted...  &lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2017-03-23T17:30:51.187" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4902" PostTypeId="1" AcceptedAnswerId="4905" CreationDate="2017-03-23T21:10:35.083" Score="6" ViewCount="135" Body="&lt;p&gt;Consider hypothetical camera with pinhole (in mathematical sense) lens and is sensor, like in below image. Is it the case that the central region of the sensor will receive more light (pixels will be brighter) than the pixels closer to the border?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will the darkening be proportional to the cosine of the sensor normal and the direction which the light comes from?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this phenomenon occurring in digital cameras, is it corrected digitally?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ALd2E.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ALd2E.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I mostly interested in case of idealized film. Digital cameras exhibit this effect due to light attenuation caused be some participating media.&#xA;I'm asking about pure geometrical effect like in Lambertian law.&lt;/p&gt;&#xA;" OwnerUserId="5249" LastEditorUserId="5249" LastEditDate="2017-03-24T20:45:17.373" LastActivityDate="2017-03-24T20:45:17.373" Title="Amount of light reaching the sensor of pinhole camera model" Tags="&lt;raytracing&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4903" PostTypeId="2" ParentId="4857" CreationDate="2017-03-24T06:01:32.157" Score="1" Body="&lt;p&gt;There is only one major thing that I can think of in nonstereographic view that is affected by size and that is:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Atmospheric haze and subsurface scattering, even this is similar at most or all macroscopic ranges.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;That said you can easily do this by fudging one constant in a shader. Or slightly more tediously by adding aerosols in the air if you are in fact doing this in real photography, altough getting it exactly right is hard.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This changes in stereoscopy as humans have some sense of their own scale. So the disparity between cameras sets a scale. But if you change the distance between the cameras then you change scale so even they do not have to be in absolute scale just relative scale.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in fact most things are self similar at all practical scales. And only when you start to see effects that are fixed light wavelength do you get into this problem.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-03-24T06:01:32.157" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4905" PostTypeId="2" ParentId="4902" CreationDate="2017-03-24T13:50:31.327" Score="5" Body="&lt;p&gt;This effect is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Vignetting&quot; rel=&quot;noreferrer&quot;&gt;vignetting&lt;/a&gt;. The cases you talk about are specifically natural and pixel vignetting as explained on the wiki page. Digital cameras compensate these effects, but optical vignetting has to be done in image software for DSLR's with interchangeable lenses. For example if you import an image to Lightroom, there's &quot;lens correction&quot; option, which removes vignetting, distortion and chromatic aberration caused by the lens based on the lens profile.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-03-24T13:50:31.327" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4906" PostTypeId="1" CreationDate="2017-03-24T23:29:06.743" Score="0" ViewCount="359" Body="&lt;p&gt;I have a scene kit app I'm working on and at a certain point I move the camera under a list of objects and tilt it up to give a star wars type view of them. I then need to pull the objects up one at a time and face them at the camera. All of this is working however the last step is making them rotate so while facing the camera it looks like it's spinning on its y axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm setting my camera's eularAngle.x to 0.75. I then do the same to the object I'm bringing to the foreground so it faces the camera. I cannot for the life of me figure out the matrix math to make it spin correctly.&lt;/p&gt;&#xA;" OwnerUserId="6318" LastEditorUserId="231" LastEditDate="2017-03-25T13:08:00.823" LastActivityDate="2017-03-25T13:08:00.823" Title="Tilting a 3d object to face a camera and have it look like it's spinning on the y axis" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4907" PostTypeId="1" CreationDate="2017-03-25T14:42:29.927" Score="1" ViewCount="540" Body="&lt;p&gt;I am trying to make 3D drawing software. I wanted to have the drag feature so I am using object picking using the OBB algorithm. I am facing problems in understanding the algorithm, and my implementation thus is having bugs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I implement object picking, using OBB in OpenGL? As I am new to OpenGL (free-glut library), a step by step explanation would be helpful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not able to understand what t1 and t2 mean and how the algorithm is working. If you explain the algorithm that would be enough.&lt;/p&gt;&#xA;" OwnerUserId="6320" LastEditorUserId="231" LastEditDate="2017-03-29T08:19:57.697" LastActivityDate="2017-03-29T08:19:57.697" Title="How do I implement object picking, using OBB in OpenGL?" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;3d&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4908" PostTypeId="2" ParentId="4907" CreationDate="2017-03-25T16:59:26.117" Score="3" Body="&lt;p&gt;Ray vs OBB intersection works by shooting a ray towards the OBB's planes. This results in 2 intersections referred to as &lt;code&gt;t1&lt;/code&gt; and &lt;code&gt;t2&lt;/code&gt; (per axis), also referred to as &lt;code&gt;tNear&lt;/code&gt; and &lt;code&gt;tFar&lt;/code&gt; or &lt;code&gt;tMin&lt;/code&gt; and &lt;code&gt;tMax&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/saY7S.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/saY7S.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Checking whether the ray intersects with the box, can then be done by comparing the largest &lt;code&gt;tNear&lt;/code&gt; against the smallest &lt;code&gt;tFar&lt;/code&gt;. If the largest &lt;code&gt;tNear&lt;/code&gt; is less than the smallest &lt;code&gt;tFar&lt;/code&gt; then there is a intersection.&lt;/p&gt;&#xA;" OwnerUserId="4776" LastActivityDate="2017-03-25T16:59:26.117" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4909" PostTypeId="2" ParentId="4895" CreationDate="2017-03-26T11:00:55.810" Score="0" Body="&lt;p&gt;As Dan Hulme points out in a comment, the variable &lt;code&gt;last&lt;/code&gt; is not updated each frame. Assuming this code is within a function, it is initialised to the current time once, the first time this function is called. Every time the function is called after that, the &lt;code&gt;static&lt;/code&gt; keyword prevents the &lt;code&gt;last&lt;/code&gt; variable from being updated. This variable therefore remains unchanged throughout the animation, always set to the initial time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this suspected problem is indeed the case, you can correct it by either not using static variables, or by initialising the static variables and then separately updating them in lines that do not contain the &lt;code&gt;static&lt;/code&gt; keyword.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the current code, I can't think of a way that &lt;code&gt;last&lt;/code&gt; could already be set to the current time each frame unless there is more code that has not been posted, in which case we will not be able to help you without seeing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are more subtle problems with simply multiplying by delta, which will give a different trajectory for different delta sizes, but they may not be relevant depending on the accuracy that you require. I have focused on what appears to be the most significant problem, as nothing else can be tested until that is either addressed or proved to be not a problem.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2017-03-26T11:00:55.810" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4912" PostTypeId="1" CreationDate="2017-03-27T03:21:25.450" Score="2" ViewCount="63" Body="&lt;p&gt;I briefly read the paper and I think I got the basic idea of it. The paper doesn't really go into implementation details though so my question is mostly on that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the paper, needed tiles are identified by going through the vertex stage and the vertices that make it to the fragment stage have paging data written into another texture at the vert's texcoord. Tiles are then assigned a tile from some form of pager. Cpu reads paging and assignment data and streams image data from disk to said tiles. At least that's from what I understand. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm unclear on the TLM implementation. I assume it's using image load stores (glsl. Don't know what the hlsl equivalent is). Is this a correct assumption to make or is there a better way to do this? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, is this better than just streaming in data based on the object distance from the camera? Their implementation may be more efficient that it streams in only when needed, but it sounds like it might introduce more pop in since it doesn't guarantee that objects nearby will have the appropriate mip level in memory. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: link to the paper &lt;a href=&quot;https://hal.inria.fr/inria-00070783&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://hal.inria.fr/inria-00070783&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Did a proper read through again. It outputs the texcoord as a color frame buffer attachment at the vertex stage. Now the only confusion is how they output the texcoord coordinates but still use the mvp transform for the actual clipping. My solution is probably to abs the x and y mvp coords, take the max of those and output that to the z coord. The vertex will be clipped if the z value is more than one.  That's my solution for this. They vaguely mentioned using the clipping registers in Nvidia hw. I'm guessing that means is a better way to do this? &lt;/p&gt;&#xA;" OwnerUserId="6331" LastEditorUserId="6331" LastEditDate="2017-03-29T00:13:19.403" LastActivityDate="2017-03-29T00:13:19.403" Title="Implementation of the paper &quot;unified texture management of arbitrary meshes&quot;" Tags="&lt;texture&gt;&lt;glsl&gt;&lt;hlsl&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4913" PostTypeId="2" ParentId="4895" CreationDate="2017-03-27T04:51:13.653" Score="0" Body="&lt;pre&gt;&lt;code&gt;GLfloat now = glfwGetTime();&#xA;delta = last - now;&#xA;last = now;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;delta&lt;/code&gt; and &lt;code&gt;last&lt;/code&gt; should be initialized as 0.0f outside the gameloop.&lt;/p&gt;&#xA;" OwnerUserId="6290" LastActivityDate="2017-03-27T04:51:13.653" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4914" PostTypeId="1" CreationDate="2017-03-27T05:32:04.817" Score="3" ViewCount="110" Body="&lt;p&gt;I was in my elevator when i saw this... &lt;a href=&quot;https://i.stack.imgur.com/7JbXE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7JbXE.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see here that reflections are kind of stretched. What causes this? And how can we achieve something like this in computer graphics?&lt;/p&gt;&#xA;" OwnerUserId="2096" LastActivityDate="2017-03-27T05:32:04.817" Title="How can i achieve reflections like this?" Tags="&lt;opengl&gt;&lt;algorithm&gt;&lt;reflection&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4915" PostTypeId="1" CreationDate="2017-03-27T09:56:55.150" Score="1" ViewCount="340" Body="&lt;p&gt;I'm interested in how to organize in code (I prefer C++) lighting.&lt;br&gt;&#xA;Problem is: I have &lt;code&gt;Scene&lt;/code&gt; which contains &lt;code&gt;Model&lt;/code&gt; where model contains &lt;code&gt;Shader&lt;/code&gt;, some&lt;code&gt;Texture&lt;/code&gt;s and geometry &lt;code&gt;Mesh&lt;/code&gt;. Now I want to add &lt;code&gt;Light&lt;/code&gt; with the following fields:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Light&#xA;{&#xA;    Vector3f Color;&#xA;    float AmbientIntensity;&#xA;    Vector3f Direction;&#xA;    float DiffuseIntensity;&#xA;    float SpecularIntensity;&#xA;    Vector3f Position;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To apply light I need to know the values of this field and the position of the fragment pixel of geometry. This means I need to make a function like &lt;code&gt;Light::lightModel(Model mdl)&lt;/code&gt; to get data from &lt;code&gt;Model&lt;/code&gt; which I want to light. But also I want to make &lt;code&gt;Light&lt;/code&gt; &lt;strong&gt;debuggable&lt;/strong&gt; - show it in the scene like a &lt;code&gt;Model&lt;/code&gt; (cube). How can I light all &lt;code&gt;Model&lt;/code&gt;s and do not light the light itself?  Make two &lt;code&gt;Scene&lt;/code&gt;s? &lt;code&gt;Scene&amp;lt;Model&amp;gt; models&lt;/code&gt; and &lt;code&gt;Scene&amp;lt;Light&amp;gt; lights&lt;/code&gt; and for loop for each like this?   &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (const auto&amp;amp; light : lights-&amp;gt;data()) {&#xA;    for (const auto&amp;amp; model : models-&amp;gt;data())&#xA;    {&#xA;        light-&amp;gt;lightModel(model);&#xA;        model-&amp;gt;draw(camera);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6337" LastEditorUserId="231" LastEditDate="2017-03-27T22:29:26.117" LastActivityDate="2017-03-28T11:08:29.177" Title="How to organize Lights and Models?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4916" PostTypeId="1" CreationDate="2017-03-27T13:00:17.613" Score="2" ViewCount="87" Body="&lt;p&gt;This might be not laser precision question but this issue appeared a long time ago when first trying to render some scene with 3D models in rasterisation renderer and apply some lighting, posprocessing etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Random squares:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XgquJ.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XgquJ.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sometimes it look like flooding model area:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4WWaw.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4WWaw.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it appears only on models loaded from file, sponza or any other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what could be the cause? Numerical errors in shaders? &lt;code&gt;NaN&lt;/code&gt; or negative values? Anyone experiences this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's hard to explain because its quite random.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-03-27T16:32:04.960" LastActivityDate="2017-03-27T16:32:04.960" Title="Artifacts (numerical errors?) in rasterisation renderer" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;glsl&gt;&lt;rasterizer&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="4917" PostTypeId="1" CreationDate="2017-03-27T14:14:59.757" Score="1" ViewCount="353" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;For a 3D scene in the world coordinates, its &lt;em&gt;View Reference Point&lt;/em&gt; $\mathrm{VRP}$ is at $(5,2,1)$, and a viewer is looking towards point $A=(1,1,1)$. Construct a transform matrix which will map  world  coordinate  points  to  a  right-handed  $(UVN)$  viewing  space,  so  that  VRP  is &#xA;  the  origin,  the  line  joining  $\mathrm{VRP}$ to  $A$  is  the  positive  $N$  axis,  and  the  view-up  Vector  is $(0,0,1)$.  &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I have calculated the translation matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;T=&#xA;\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; -5 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 2 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -1 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have calculated the rotation matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;R=&#xA;\begin{pmatrix}&#xA;-0.6 &amp;amp; -0.8 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;-0.8 &amp;amp; 0.6 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what would the final transformation matrix $M$ be? My lecture slides tell me it would be rotation matrix multiplied by translation matrix, with the last column multiplied by $-1$ except for the $1$. This would equal:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;M = R \times T = &#xA;\begin{pmatrix}&#xA;-0.6 &amp;amp; -0.8 &amp;amp; 0 &amp;amp; -1.4 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 1 \\&#xA;-0.8 &amp;amp; 0.6 &amp;amp; 0 &amp;amp; -5.2 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{pmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this answer here: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4737/building-view-transform-matrices&quot;&gt;Building view transform matrices&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;just adds them together somehow. Which one is correct?&lt;/p&gt;&#xA;" OwnerUserId="5513" LastEditorUserId="182" LastEditDate="2017-07-28T08:43:05.080" LastActivityDate="2017-07-28T08:43:05.080" Title="Final transformation matrix to transform world coordinate into vrc" Tags="&lt;3d&gt;&lt;matrix&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2017-08-05T21:34:55.190" ContentLicense="CC BY-SA 3.0" />
  <row Id="4918" PostTypeId="1" CreationDate="2017-03-27T15:01:24.157" Score="1" ViewCount="94" Body="&lt;p&gt;I'm developing a deep learning algorithm to find and classify (post consumption) plastic bottles on a conveyor belt. A way to train my model is to get tons of labeled images of each bottle, which for now is not feasible. Another possible option is to make a 3D scan of the bottle and render it in different angles thus creating synthetic training data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I want to obtain the mesh is by using for example ReMake or CapturingReality and 2D images. The problem is that most of the bottles are transparent and are causing problems in those programs. I just ordered Chalk spray to paint them and with a marker add dots allover. Then hopefully I'd be able to render it with the specific material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, is there a way to add the visual details like the labels and the color of the bottle cap back to the mesh? I'll be using a RGB-D camera so the priorities are getting both the visual cues as well as the depth information as accurate as possible to what the camera will be classifying in a further stage. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any advise and feedback will be highly appreciated, thanks in advanced!! &lt;/p&gt;&#xA;" OwnerUserId="6340" LastActivityDate="2017-03-27T15:01:24.157" Title="Advice on synthetic data generation using 3D mesh" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;texture&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4919" PostTypeId="1" CreationDate="2017-03-28T03:30:19.457" Score="4" ViewCount="1955" Body="&lt;p&gt;I have a series of MRI images. I want to build a 3D model out of it, which not only presents the surface, but also contains the inside structures. What kind of photogrammetry based method can realize that? &lt;/p&gt;&#xA;" OwnerUserId="6290" LastActivityDate="2019-04-26T05:05:03.950" Title="How to build a 3d model from 2d pictures" Tags="&lt;3d&gt;&lt;algorithm&gt;&lt;computational-geometry&gt;" AnswerCount="4" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4920" PostTypeId="1" CreationDate="2017-03-28T03:42:22.670" Score="2" ViewCount="308" Body="&lt;p&gt;I was thinking that I could pass a timestamp in (from requestAnimationFrame) to the vert shader, and just have my easing curves in the GPU instead of using (for example) Tween.js from the outside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this a good idea? Why or why not?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: After learning more GL and thinking about it, it doesn't seem like I want &lt;em&gt;every&lt;/em&gt; shader instance to run a tween that I may only use for a handful of vertices. Can we have only certain shaders run tween calculations if the vertex being animated is the one of the current shader?&lt;/p&gt;&#xA;" OwnerUserId="4991" LastEditorUserId="4991" LastEditDate="2017-03-28T17:56:36.370" LastActivityDate="2017-03-30T06:53:44.660" Title="Easing curves on the GPU?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4921" PostTypeId="2" ParentId="4915" CreationDate="2017-03-28T11:08:29.177" Score="1" Body="&lt;p&gt;If I understand you correctly then you are probably looking for a way in which lights in the scene interact with models in the scene. Also, you want each light to be visually debuggable in scene, maybe by drawing a cube. Here's one of the simplest way to do it. There could be more better &amp;amp; optimized ways of doing this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can have a class for Each light type eg&gt; PointLight, DirectionalLight etc each with their own properties. You need to have a class which then keeps track of all the lights in the scene. This class will have list of light types in the scene. This class will also have functions for adding active lights from the scene to it's list of lights. Usual get-set functions for accessing individual lights will be required too. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class LightsManager&#xA;{&#xA;// maybe create singleton object here..&#xA;public:&#xA;   void GatherPointLights(PointLight* light);&#xA;   PointLight GetPointLight(int id);&#xA;&#xA;private:&#xA;   int numPointLights;&#xA;   std::vector&amp;lt;PointLight*&amp;gt; vecPointLights; &#xA;}&#xA;&#xA;void LightsManager::GatherPointLights(PointLight* light)&#xA;{&#xA;    vecPointLights.push_back(light);&#xA;    numPointLights = vecPointLights.size();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In your class where you create objects in the scene, you can then add light objects from the scene to this LightManager using the function you created earlier. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming scene class where all the objects including Lights are created...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Scene::Init()&#xA;{&#xA;    // load mesh&#xA;    ...&#xA;    ...&#xA;    // add lights&#xA;    PointLight light1;&#xA;    light1.color = Color::Red;&#xA;    light1.position = vec3(0,0,0);&#xA;    LightManager::getInstance()-&amp;gt;GatherPointLights(&amp;amp;light1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If LightManager creates singleton object then you can then access all the lights in the scene by their type during actual rendering to extract their properties in a class where you render actual scene geometry by passing light color, position etc to a shader which draws scene geometry. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now drawing the actual debug geometry for any light object, say cube for point light, I would make sure my PointLight type object has a way of rendering cube at a Point light position, using it's color property to draw cube of that same color with a flat color shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As per making sure lights are not lighting actual light debug geometry, if your cube drawing shader is a flat color shader representing color of a light, then it will not be affected by any light in the scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this is what you asked for. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2017-03-28T11:08:29.177" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4922" PostTypeId="1" CreationDate="2017-03-28T17:03:49.197" Score="0" ViewCount="100" Body="&lt;p&gt;Consider a triangular face of three vertices A(0,2,-1), B(1,0,1) and the origin O, and the normal vectors at the vertices are nA=(0,1,0), nB=(1,0,0) and nO=(0,0,1), respectively. The incident light is white and directional in direction of L=(1,2,2) and the intensity is 1, the background ambient light intensity is 0.1, and the diffuse reflection coefficients for (red, green, blue) are (0.6,0.7,0.8). No specular light contribution needs to be considered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Find the (red, green, blue) intensity values at the centre of the face using Gouraud shading.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I do not know how to answer this question and have looked at my lecture slides, youtube videos, computer graphics textbook by Foley and Van Damm and obviously used google. Any help would be much appreciated. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I want to find the intensity values using Gouraud shading, not flat shading. From my understanding, the intensity at a point is interpolated along polygon edges and scan lines? But with the information I am given in the question, I don't have a clue how to answer this question. This video helped a bit: &lt;a href=&quot;https://www.youtube.com/watch?v=_SuyLrU2Xr0&amp;amp;t=142s&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=_SuyLrU2Xr0&amp;amp;t=142s&lt;/a&gt; but it doesn't set me up for answering this question.&lt;/p&gt;&#xA;" OwnerUserId="5513" LastEditorUserId="5513" LastEditDate="2017-03-29T08:08:04.450" LastActivityDate="2017-03-29T08:08:04.450" Title="Find RGB intensity values at center of face using Gouraud shading" Tags="&lt;rendering&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ClosedDate="2017-03-29T15:59:02.933" ContentLicense="CC BY-SA 3.0" />
  <row Id="4923" PostTypeId="1" CreationDate="2017-03-28T19:42:12.480" Score="3" ViewCount="47" Body="&lt;p&gt;I am trying to implement &lt;a href=&quot;http://jcgt.org/published/0002/01/02/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rauwendall and Bailey's&lt;/a&gt; Conservative Voxelization algorithm in a compute shader (Section 7)(page 20/34).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This algorithm is similar to Schwarz &amp;amp; Seidel's, in that it orthogonally projects a triangle into a plane (aligned with an axis - the &lt;em&gt;depth axis&lt;/em&gt;), then iterates over all the points in the plane, using edge functions to determine if they are within the triangle's projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rather than then perform a box-plane intersection for each voxel however as in Schwarz and Seidel, this algorithm computes the range of points along the depth axis to check, then just checks the projection in the remaining two planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What I do not understand is how that algorithm identifies the range in the depth axis.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper does not go into much more detail than I just did, and I can't work out from the pseudo-code how it functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(PS. I have tried to implement the pseudo-code as written, and I needed to make a couple of corrections to get it working. The minimal range check is the last bit that is not functioning. I need to understand how it works so I can fix it.)&lt;/p&gt;&#xA;" OwnerUserId="4509" LastActivityDate="2017-03-28T19:42:12.480" Title="How does the depth range test in Rauwendaal &amp; Bailey's voxelisation algorithm work?" Tags="&lt;voxelization&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4924" PostTypeId="1" CreationDate="2017-03-29T00:51:45.537" Score="1" ViewCount="328" Body="&lt;p&gt;I am new to the DX12 world and I am currently trying to tweak the nbody_gravity DX12 sample, but appending or calling another Compute Shader which is to add 2 buffers to produce an output in a different buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now, I have made a call to my ComputeBufferAddition shader and was wondering if I need a separate Compute PSO to do this, or can I reuse the one already present to call the NbodyGravity.hlsl&lt;/p&gt;&#xA;" OwnerUserId="6349" LastEditorUserId="6546" LastEditDate="2017-05-02T00:25:31.073" LastActivityDate="2017-05-02T00:25:31.073" Title="Compute Shader PSO Dx12" Tags="&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4926" PostTypeId="2" ParentId="4917" CreationDate="2017-03-29T09:02:43.823" Score="0" Body="&lt;p&gt;Thanks for notification me, In my previous answer, I just combine the translation matrix and the rotation matrix, actually, It's the result translation matrix(T) multiply rotation matrix(R). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rotation is a 3x3 matrix, we can extend the matrix to a 4x4 matrix with adding a dimension, the 4x4 rotation matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QOZur.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QOZur.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the translation matrix is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/l3FFz.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/l3FFz.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, now we can calculate the transform matrix by translation matrix multiply(T) rotation matrix(R):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cause the matrix multiply formula is too big for the 4x4 matrix, we just look at the 1st row, In the transform matrix(M), the M11 element equals to T11*R11+T12*R21+T13*R31+T14*R41, cause T12, T13, R41 is 0, so, the M11 equals to R11 right? And in the same way, M14 equals to T11*R14+T12*R24+T13*R34+T14*R44, only R44 equals to 1, so, the M14 equals to T14. so, I just simply put them together in my last answer. For the reason why we put the translation matrix on the left, you can check on the book that I gave you in my previous answer on page 91(translating first and then rotating).&lt;/p&gt;&#xA;" OwnerUserId="6140" LastActivityDate="2017-03-29T09:02:43.823" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4928" PostTypeId="2" ParentId="4924" CreationDate="2017-03-29T15:08:09.497" Score="2" Body="&lt;p&gt;If I understand you correctly, you've added a new compute shader. In DX12, you'll need at least one separate PSO for each shader, since the shader code is part of the PSO.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-03-29T15:08:09.497" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4930" PostTypeId="1" CreationDate="2017-03-29T17:45:38.100" Score="1" ViewCount="413" Body="&lt;p&gt;I'm building an application where I stream video camera feed from one mobile device to another in Unity. I tried searching for answers, but most of the topics deal with how to display a video stream, rather than how to send it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried looking for plugins and only found two that do something similar &lt;a href=&quot;https://www.assetstore.unity3d.com/en/#!/content/68030&quot; rel=&quot;nofollow noreferrer&quot;&gt;1&lt;/a&gt;, &lt;a href=&quot;https://www.assetstore.unity3d.com/en/#!/content/7447&quot; rel=&quot;nofollow noreferrer&quot;&gt;2&lt;/a&gt;, but they don't provide much information in regards to mobile support and the plugin price is way too steep for my student budget and a non-commercial application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another approach I am looking into right now is to try streaming the texture itself, but I haven't figured it out yet. Is there an easier way to stream WebCamTexture content on mobile platforms?&lt;/p&gt;&#xA;" OwnerUserId="6356" LastActivityDate="2017-03-29T17:45:38.100" Title="Streaming video camera input from WebCamTexture on mobile? (Possibly via WebRTC or websocket?)" Tags="&lt;unity&gt;&lt;video&gt;&lt;mobile&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4931" PostTypeId="2" ParentId="3729" CreationDate="2017-03-29T19:56:36.060" Score="6" Body="&lt;p&gt;If you want to implement this with GLSL, the general concept that could be applied is multi-pass rendering. In a first render pass, draw some ink on the screen and write the result in a frame buffer object (FBO). Then in the second render pass, draw a screen-size quad and attach the texture of the FBO. In this second render pass you could use a GLSL shader that distributes the ink. In the example below I used a simple Erode and a Gauss filter but more complicated effects are possible here. The result is then used as the background for the first render pass that draws more ink, which is passed on to the second render pass, and so on...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AFA6C.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AFA6C.gif&quot; alt=&quot;ink flow animated gif&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have generated the example above with an online tool called &quot;GSN Composer&quot;, which uses GLSL shaders and WebGL. You find the corresponding node graph here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.gsn-lib.org/index.html#projectName=foruminkspread&amp;amp;graphName=erode&quot; rel=&quot;noreferrer&quot;&gt;https://www.gsn-lib.org/index.html#projectName=foruminkspread&amp;amp;graphName=erode&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, in this very simple implementation, the spreading of ink will never stop. To achieve this you would need to remember a per-pixel state (e.g. a &quot;mass&quot; or &quot;reservoir&quot;, as you have mentioned in your question) and use this per-pixel state in the shader that performs the spreading. This state could be encoded in the texture output (e.g. in the alpha channel) or could be written into a second texture that is passed along the shader pipeline.&lt;/p&gt;&#xA;" OwnerUserId="4652" LastActivityDate="2017-03-29T19:56:36.060" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4932" PostTypeId="2" ParentId="4920" CreationDate="2017-03-29T22:07:39.817" Score="2" Body="&lt;p&gt;This is a pure optimisation problem. It depends on many factors like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What you need to do with the tween&lt;/li&gt;&#xA;&lt;li&gt;How many different tweens you need to calculate&lt;/li&gt;&#xA;&lt;li&gt;How much signaling between systems you need&lt;/li&gt;&#xA;&lt;li&gt;Whether you need to use that data in your CPU bound process or not.&lt;/li&gt;&#xA;&lt;li&gt;How much time you have to write the code&lt;/li&gt;&#xA;&lt;li&gt;What your tool set supports easiest&lt;/li&gt;&#xA;&lt;li&gt;...&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;See if you only need one value to interpolate then your CPU is more than likely faster (unless you're running some weird embedded system). Even if you move a bunch of points you can still calculate the tween of that one position and do the needed cluster transformation in the GPU, like bone animation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The GPU only starts to win against your processor if you need to calculate many truly separate animation curves in parallel. Or you're in an otherwise performance bound system like running JavaScript in a WebGL application. If you do use the GPU then it's most likely best to tween all vertices, at least unless your object is somehow massive. Since initiating a new draw call is costly and maintaining many states is more complex. Its just that those vertices that don't move would just move from starting point to starting point.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2017-03-30T06:53:44.660" LastActivityDate="2017-03-30T06:53:44.660" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4935" PostTypeId="1" CreationDate="2017-03-30T14:25:30.000" Score="3" ViewCount="121" Body="&lt;p&gt;I've been trying to figure this out for a few days now, but I just can't get it right. I've read multiple &lt;a href=&quot;http://ogldev.atspace.co.uk/www/tutorial26/tutorial26.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;tutorials&lt;/a&gt; and &lt;a href=&quot;http://renderdan.blogspot.no/2006/05/rotation-matrix-from-axis-vectors.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;possible&lt;/a&gt; explanations, I even watched a &lt;a href=&quot;https://www.youtube.com/watch?v=4DUfwAEx4Ts&quot; rel=&quot;nofollow noreferrer&quot;&gt;java tutorial&lt;/a&gt; without finding the solution. This is what I do:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First I build the tangent values to pass as attributes:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//this parsing has not been updated, unlike the shaders, correct parsing in the answer below&#xA;float f;&#xA;vec3 edge1, edge2, tangentbuf;&#xA;vec2 deltaUV1, deltaUV2;&#xA;//for each face, x=vert,y=uv, z=normal&#xA;for (size_t i = 0; i &amp;lt; totalrefs.size(); i += 9)&#xA;{&#xA;    edge1 = verticeref[totalrefs[i + 3] - 1] - verticeref[totalrefs[i] - 1];&#xA;    edge2 = verticeref[totalrefs[i + 6] - 1] - verticeref[totalrefs[i] - 1];&#xA;    deltaUV1 = texkoordref[totalrefs[i + 4] - 1] - texkoordref[totalrefs[i + 1] - 1];&#xA;    deltaUV2 = texkoordref[totalrefs[i + 7] - 1] - texkoordref[totalrefs[i + 1] - 1];&#xA;    f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);&#xA;&#xA;    tangentbuf = f*vec3(&#xA;        (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x),&#xA;        (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y),&#xA;        (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z));&#xA;&#xA;    normalize(tangentref[tangentcount++]);&#xA;    tangentref[totalrefs[i] - 1] += vec4(normalize(tangentbuf), 1);&#xA;    tangentref[totalrefs[i + 3] - 1] += vec4(normalize(tangentbuf), 1);&#xA;    tangentref[totalrefs[i + 6] - 1] += vec4(normalize(tangentbuf), 1);&#xA;}&#xA;&#xA;//for (auto &amp;amp;x : tangentref)x = normalize(x / x.w); //find average&#xA;for (auto &amp;amp;x : tangentref)x = normalize(x); //just normalize is enough?&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Normalizing or dividing seems to give the same result, and I think this is correct this far. With these shaders:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vert&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400&#xA;layout ( location = 0 ) in vec3 vertex_position;&#xA;layout ( location = 1 ) in vec2 tex_cord;&#xA;layout ( location = 2 ) in vec3 vertex_normal;&#xA;layout ( location = 3 ) in vec3 vertex_tangent;&#xA;&#xA;uniform mat4 model; //model matrix, aka model 2 world&#xA;&#xA;uniform mat4 modelviewmatrix; //view*model matrix&#xA;uniform mat3 normalmatrix; // transpose/invert(view*model)&#xA;uniform mat4 priv_mat; //projection-view-model pre multiplied&#xA;&#xA;uniform vec4 LightPosition; //after view*lightpos, ie viewspace&#xA;&#xA;out vec3 lightdir;&#xA;out vec3 viewdir;&#xA;out vec2 fUV;&#xA;out vec3 position;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position=priv_mat*vec4(vertex_position,1.0);&#xA;    fUV=tex_cord;&#xA;    position=(model*vec4(vertex_position,1.0)).xyz;&#xA;    len=length(vertex_position);&#xA;&#xA;    // Transform normal and tangent to eye space&#xA;    vec3 n = normalize(normalmatrix * vertex_normal);&#xA;    vec3 t = normalize(normalmatrix * vec3(vertex_tangent));&#xA;         t = normalize(t-dot(t,n)*n);  //Gramm-Schmidt process&#xA;    vec3 bitangent = normalize( cross( n, t ) );&#xA;    mat3 tbn = transpose(mat3(t,bitangent,n)); //why transpose??&#xA;&#xA;    vec3 pos=vec3(modelviewmatrix*vec4(vertex_position,1.0));&#xA;&#xA;    // Transform light dir. and view dir. to tangent space&#xA;    lightdir = normalize( tbn *  (LightPosition.xyz - pos) );&#xA;    viewdir = tbn * normalize(-pos);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And frag&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400&#xA;&#xA;in float len;&#xA;in vec3 lightdir; //tang light&#xA;in vec3 viewdir; //tang view&#xA;in vec2 fUV;&#xA;in vec3 position;&#xA;&#xA;uniform sampler2D png_tex;&#xA;uniform sampler2D bump_map;&#xA;&#xA;uniform vec4 LightPosition;&#xA;uniform vec3 LightIntensity;&#xA;&#xA;uniform vec3 Kd;            // Diffuse reflectivity&#xA;uniform vec3 Ka;            // Ambient reflectivity&#xA;uniform vec3 Ks;            // Specular reflectivity&#xA;uniform float Shininess;    // Specular shininess factor&#xA;&#xA;out vec4 Color;&#xA;vec3 phongModel( vec3 norm, vec3 diffr );&#xA;&#xA;void main()&#xA;{&#xA;    vec4 b_normal = (255.0/128.0) * texture( bump_map, fUV )-1.0; // Lookup the normal from the normal map&#xA;    vec4 texColor = texture( png_tex, fUV ); // The color texture is used as the diffuse reflectivity&#xA;    Color = vec4( phongModel(b_normal.xyz, texColor.rgb), 1.0 );&#xA;}&#xA;&#xA;vec3 phongModel( vec3 norm, vec3 diffr )&#xA;{&#xA;    vec3 r = reflect( -lightdir, norm );&#xA;    vec3 ambient = LightIntensity * Ka;&#xA;    float sDotN = max( dot(lightdir, norm), 0.0 );&#xA;    vec3 diffuse = Kd*LightIntensity * diffr * sDotN;&#xA;    vec3 spec = vec3(0.0);&#xA;    if( sDotN &amp;gt; 0.0 )&#xA;        spec = LightIntensity * Ks * pow( max( dot(r,viewdir), 0.0 ), Shininess );&#xA;    return ambient + diffuse + spec;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I only got this result: &lt;em&gt;the shaders are updated as I went along, so the ones posted above work (for me anyway)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BBvQS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BBvQS.png&quot; alt=&quot;when rotated it turns dark&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which has 2 obvious errors: When I rotate the object, the shading doesn't follow the lightsource and goes from dark to full bright, and, it seems to have dents at seams where the cube-sphere wraps. The normalmapping seems to work though, but again I struggle with the shading. Is there an obvious error here?&lt;/p&gt;&#xA;" OwnerUserId="6255" LastEditorUserId="231" LastEditDate="2017-04-03T12:38:34.560" LastActivityDate="2018-04-23T14:06:15.633" Title="NormalMap problems: bumps work, but shade does not" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;glsl&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4936" PostTypeId="1" AcceptedAnswerId="4938" CreationDate="2017-03-30T14:46:56.553" Score="5" ViewCount="1569" Body="&lt;p&gt;I have got a texture ID and would like to retrieve its data. The data should be stored in a &lt;code&gt;BufferedImage&lt;/code&gt; for future use. I am using the LWJGL library in Java, so if there are some library-specific shortcuts I'd like to use them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My naive approach is to first fill a buffer with the image data and then pass it to the image.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int id = ...;&#xA;IntBuffer buff = BufferUtils.createIntBuffer(1024*512*4);&#xA;GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);&#xA;System.out.println(buff.remaining());&#xA;GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, buff);&#xA;System.out.println(buff.remaining());&#xA;buff.flip();&#xA;buff.rewind();&#xA;System.out.println(buff.remaining());&#xA;// Somehow create a BufferedImage from buff here&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't know why, but the first and to &lt;code&gt;buff.remaining()&lt;/code&gt; return the same value, indicating that nothing has been written which should not be the case.&lt;/p&gt;&#xA;" OwnerUserId="6092" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:39:13.117" LastActivityDate="2018-03-04T00:39:13.117" Title="LWJGL/OpenGL get BufferedImage from texture ID" Tags="&lt;opengl&gt;&lt;image&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4937" PostTypeId="1" AcceptedAnswerId="4967" CreationDate="2017-03-30T21:34:25.473" Score="12" ViewCount="2441" Body="&lt;p&gt;I discovered that some engines use &lt;strong&gt;derivative maps&lt;/strong&gt; instead of &lt;strong&gt;tangent space normal maps&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some reading, it seems to be a really awesome way to replace tangent space normals but are there some disadvantage using them ? Why still continue using tangent space normals ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to compare both with advantage and disadvantage ?&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2018-04-09T09:41:30.730" Title="Derivative maps vs. Tangent Space Normal maps" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;normal-mapping&gt;&lt;directx&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4938" PostTypeId="2" ParentId="4936" CreationDate="2017-03-31T01:56:23.087" Score="5" Body="&lt;p&gt;To make it a more complete example, let's also consider loading a texture from a &lt;code&gt;BufferedImage&lt;/code&gt; as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First let's assume:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int texture = glGenTextures();&#xA;glBindTexture(GL_TEXTURE_2D, texture);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;First we need to load an image. For this we can use &lt;code&gt;ImageIO.read()&lt;/code&gt;. Then we put all the pixels from the &lt;code&gt;BufferedImage&lt;/code&gt; into a &lt;code&gt;ByteBuffer&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;BufferedImage image = ImageIO.read(new File(&quot;image.png&quot;));&#xA;int width = image.getWidth(), height = image.getHeight();&#xA;&#xA;int[] pixels = new int[width * height];&#xA;image.getRGB(0, 0, width, height, pixels, 0, width);&#xA;&#xA;ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4); // 4 because RGBA&#xA;&#xA;for(int y = 0; y &amp;lt; height; ++y) {&#xA;    for(int x = 0; x &amp;lt; width; ++x) {&#xA;        int pixel = pixels[x + y * width];&#xA;        buffer.put((byte) ((pixel &amp;gt;&amp;gt; 16) &amp;amp; 0xFF));&#xA;        buffer.put((byte) ((pixel &amp;gt;&amp;gt; 8) &amp;amp; 0xFF));&#xA;        buffer.put((byte) (pixel &amp;amp; 0xFF));&#xA;        buffer.put((byte) ((pixel &amp;gt;&amp;gt; 24) &amp;amp; 0xFF));&#xA;    }&#xA;}&#xA;&#xA;buffer.flip();&#xA;&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Before we go ahead and call &lt;code&gt;glGetTexImage()&lt;/code&gt; lets assume that the only thing we have is the texture name (&lt;code&gt;texture&lt;/code&gt;). Thus we consider that we don't know the size or format of the texture. We can get all this by doing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int format = glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_INTERNAL_FORMAT);&#xA;int width = glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH);&#xA;int height = glGetTexLevelParameteri(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Using that information we again create a &lt;code&gt;ByteBuffer&lt;/code&gt; as well as a &lt;code&gt;BufferedImage&lt;/code&gt;. Reading the pixels from the &lt;code&gt;ByteBuffer&lt;/code&gt; and placing them on the &lt;code&gt;BufferedImage&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int channels = 4;&#xA;if (format == GL_RGB)&#xA;    channels = 3;&#xA;&#xA;ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * channels);&#xA;BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);&#xA;&#xA;glGetTexImage(GL_TEXTURE_2D, 0, format, GL_UNSIGNED_BYTE, buffer);&#xA;&#xA;for (int x = 0; x &amp;lt; width; ++x) {&#xA;    for (int y = 0; y &amp;lt; height; ++y) {&#xA;        int i = (x + y * width) * channels;&#xA;&#xA;        int r = buffer.get(i) &amp;amp; 0xFF;&#xA;        int g = buffer.get(i + 1) &amp;amp; 0xFF;&#xA;        int b = buffer.get(i + 2) &amp;amp; 0xFF;&#xA;        int a = 255;&#xA;        if (channels == 4)&#xA;            a = buffer.get(i + 3) &amp;amp; 0xFF;&#xA;&#xA;        image.setRGB(x, y, (a &amp;lt;&amp;lt; 24) | (r &amp;lt;&amp;lt; 16) | (g &amp;lt;&amp;lt; 8) | b);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now go ahead and save that &lt;code&gt;BufferedImage&lt;/code&gt; to a file.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ImageIO.write(image, &quot;PNG&quot;, new File(&quot;out.png&quot;));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Last but not least, you can get rid of all those &lt;code&gt;GL11.&lt;/code&gt; prefixes, by statically importing &lt;code&gt;GL11&lt;/code&gt;. You do that by doing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import static org.lwjgl.opengl.GL11.*;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4776" LastEditorUserId="4776" LastEditDate="2017-03-31T03:09:59.420" LastActivityDate="2017-03-31T03:09:59.420" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4939" PostTypeId="2" ParentId="4935" CreationDate="2017-03-31T17:08:41.877" Score="2" Body="&lt;p&gt;Silly me, posting all of this hoping to get someone to solve it for me, I managed to find the solution tho, but perhaps more as a result of trial and error, than of actual understanding. Either way, this is the object I'm looking at now:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cN0vN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cN0vN.png&quot; alt=&quot;UV ordering, transpose and crossing in the wrong order&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at my current tangent calculation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vector&amp;lt;vec4&amp;gt;tangentref(texkoordref.size()); //math UV size, w=amount for divide&#xA;vec3 tangentbuf;&#xA;&#xA;float f;&#xA;vec3 edge1, edge2;&#xA;vec2 deltaUV1, deltaUV2;&#xA;for (size_t i = 0; i &amp;lt; totalrefs.size(); i += 9)&#xA;{&#xA;    //i=vert, i+1=uv, i+2 vn//i+3=vert2,i+4=uv2,i+5=vn2;//i+6=vert3, i+7=uv3, i+8=vn3;&#xA;    //get the tangent for each face&#xA;    edge1 = verticeref[totalrefs[i + 3] - 1] - verticeref[totalrefs[i] - 1];&#xA;    edge2 = verticeref[totalrefs[i + 6] - 1] - verticeref[totalrefs[i] - 1];&#xA;    deltaUV1 = texkoordref[totalrefs[i + 4] - 1] - texkoordref[totalrefs[i + 1] - 1];&#xA;    deltaUV2 = texkoordref[totalrefs[i + 7] - 1] - texkoordref[totalrefs[i + 1] - 1];&#xA;    f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);&#xA;&#xA;    tangentbuf = f*vec3(&#xA;        (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x),&#xA;        (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y),&#xA;        (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z));&#xA;&#xA;    //one tangent per uv coordinate&#xA;    tangentref[totalrefs[i+1] - 1] += vec4(normalize(tangentbuf), 1);&#xA;    tangentref[totalrefs[i + 4] - 1] += vec4(normalize(tangentbuf), 1);&#xA;    tangentref[totalrefs[i + 7] - 1] += vec4(normalize(tangentbuf), 1);&#xA;}&#xA;&#xA;for (auto &amp;amp;x : tangentref)x = normalize(x / x.w); //find average&#xA;//some tutorials say to just normalize these&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I cycle through every face, and totalref[i], is here 9 integers per cycle, that each refer to +0=vert, +1=uv, and +2=vert normal. By populating the tangentref according to each of the UVs, I get a list of tangents that go along with the UV values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think its worth mentioning specifically, the tangents describe not the normal, or the vertex, but the direction of the uv, together with the bitangent, they make out an xy coordinate that describes the UV direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It only makes sense to make tangents according to UVs, and the results are not disagreeing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Secondly, I was building the tbn matrix incorrectly.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//in the vert shader&#xA;vec3 bitangent = normalize( cross( n, t ) );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The bitangent was in the wrong order, and&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat3 tbn = transpose(mat3(t,bitangent,n)); //why transpose??&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The tbn was supposed to be transpose. Transpose is cheap (apparently) so thats not a problem, but why exactly this is correct? I'm not sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It works (better) however, so maybe It will make sense later.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FVeYM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FVeYM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6255" LastEditorUserId="6255" LastEditDate="2018-04-23T14:06:15.633" LastActivityDate="2018-04-23T14:06:15.633" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4941" PostTypeId="1" CreationDate="2017-03-31T23:42:12.983" Score="0" ViewCount="1091" Body="&lt;p&gt;I am just trying to make a simple Skia program. A very simple program, but as I run this code, the output image file never writes anything. I am running this code on VS 2015 and included the skia.lib and OpenGL32.lib static libraries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone tell me why this simple example does not work?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &quot;skiaIncludes.h&quot;&#xA;&#xA;void draw(SkCanvas* canvas) {&#xA;SkPaint paint;&#xA;paint.setColor(SK_ColorWHITE);&#xA;canvas-&amp;gt;drawPaint(paint);&#xA;}&#xA;&#xA;int main ()&#xA;{&#xA;try {&#xA;    FILE * pFile;&#xA;    char buffer[100];&#xA;&#xA;    pFile = fopen(&quot;myfile.png&quot;, &quot;wb&quot;);&#xA;&#xA;sk_sp&amp;lt;SkSurface&amp;gt; rasterSurface(&#xA;        SkSurface::MakeRasterN32Premul(300, 300));&#xA;    SkCanvas* rasterCanvas = rasterSurface-&amp;gt;getCanvas();&#xA;&#xA;    //rasterCanvas-&amp;gt;save();&#xA;    rasterCanvas-&amp;gt;translate(SkIntToScalar(128), SkIntToScalar(128));&#xA;    rasterCanvas-&amp;gt;rotate(SkIntToScalar(45));&#xA;    SkRect rect = SkRect::MakeXYWH(-90.5f, -90.5f, 181.0f, 181.0f);&#xA;    SkPaint paint;&#xA;    paint.setColor(SK_ColorBLUE);&#xA;    rasterCanvas-&amp;gt;drawRect(rect, paint);&#xA;    //rasterCanvas-&amp;gt;restore();&#xA;&#xA;    sk_sp&amp;lt;SkImage&amp;gt; img = rasterSurface-&amp;gt;makeImageSnapshot();&#xA;    sk_sp&amp;lt;SkData&amp;gt; png(img-&amp;gt;encode(SkEncodedImageFormat::kPNG, 100));&#xA;    rasterCanvas-&amp;gt;drawImage(img, 0, 0);&#xA;    png-&amp;gt;MakeFromFILE(pFile);&#xA;&#xA;    //sk_sp&amp;lt;SkImage&amp;gt; bmap = SkImage::MakeFromBitmap(bitmap);&#xA;    //SkData * encBmap = bmap-&amp;gt;encode(SkEncodedImageFormat::kJPEG, 100);&#xA;    //encBmap-&amp;gt;MakeFromFILE(pFile);&#xA;&#xA;    fclose(pFile);&#xA;}&#xA;catch (std::exception ex){&#xA;    printf(ex.what());&#xA;}&#xA;&#xA;return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Header file :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#pragma once&#xA;&#xA;&#xA;#include &quot;core/SkData.h&quot;&#xA;#include &quot;core/SkImage.h&quot;&#xA;#include &quot;core/SkStream.h&quot;&#xA;#include &quot;core/SkSurface.h&quot;&#xA;#include &quot;core/SkCanvas.h&quot;&#xA;#include &quot;core/SkGraphics.h&quot;&#xA;#include &quot;core/SkImageEncoder.h&quot;&#xA;#include &quot;gpu/gl/GrGLInterface.h&quot;&#xA;#include &quot;gpu/gl/GrGLExtensions.h&quot;&#xA;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;sys/stat.h&amp;gt;&#xA;#include &amp;lt;sys/types.h&amp;gt;&#xA;#include &amp;lt;fcntl.h&amp;gt;&#xA;#include &amp;lt;exception&amp;gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;//#include &quot;gpu/gl/GrGLUtil.h&quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6371" LastActivityDate="2017-04-04T12:42:12.333" Title="Skia example code not writing an image" Tags="&lt;c++&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4942" PostTypeId="1" CreationDate="2017-04-01T00:44:50.680" Score="1" ViewCount="100" Body="&lt;p&gt;I'm researching highlighting accessible color contrast via filter operations. I have a test screenshot of SRGB hex values compared with &lt;a href=&quot;https://www.w3.org/TR/WCAG20/relative-luminance.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;WCAG's official contrast algorithm&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iiLxk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iiLxk.png&quot; alt=&quot;Text on various bands of color, with the contrast ratios listed next to them. They descend from maximum contrast to minimum contrast.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I converted it to its luminosity:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xBHPX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xBHPX.png&quot; alt=&quot;The previous image, with the colors changed to grayscale using a luminosity algorithm, not brightness.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then an edge detect:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jM5nb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jM5nb.png&quot; alt=&quot;The edge detection results no longer smoothly progress from maximum contrast to minimum contrast, instead having asymmetrical progression and discontinuities.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This no longer looks like a smooth progression; there's a noticeable reversal between, say, &lt;code&gt;#f00&lt;/code&gt; and &lt;code&gt;#777&lt;/code&gt;. And after applying a threshold to remove insufficient contrast, it seems like one side is favored out of proportion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a few leads, but not enough understanding of color theory to know which to attack:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is it a byproduct of how browsers antialias text?&lt;/li&gt;&#xA;&lt;li&gt;Am I in the wrong color space?&lt;/li&gt;&#xA;&lt;li&gt;I tried inverting the input and averaging its results together with the original's results, but I'm not seeing a difference other than which way the ringing travels.&lt;/li&gt;&#xA;&lt;li&gt;Similarly, switching the kernel matrix's signs doesn't change the progression.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;These images are from The GIMP's filter operations, but ultimately I aim to create an SVG &lt;code&gt;&amp;lt;filter&amp;gt;&lt;/code&gt; to dynamically highlight insufficient color contrast in web pages. I'm sure I'm not articulating with the right terminology, so please ask for more context if I'm unclear.&lt;/p&gt;&#xA;" OwnerUserId="6373" LastEditorUserId="6373" LastEditDate="2017-04-02T02:59:53.277" LastActivityDate="2017-04-02T02:59:53.277" Title="Why does this edge detect show different results for the same color combinations?" Tags="&lt;color&gt;&lt;edge-detection&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="4943" PostTypeId="1" CreationDate="2017-04-01T20:48:27.873" Score="3" ViewCount="537" Body="&lt;p&gt;RGB has the advantage over schemes like YP&lt;sub&gt;B&lt;/sub&gt;P&lt;sub&gt;R&lt;/sub&gt; in that it's more intuitive to understand, so why use the latter?  The only advantage I can think of right now is that it allows you to encode greyscale images more easily.  Is this the reason, or are there other reasons?&lt;/p&gt;&#xA;" OwnerUserId="6379" LastActivityDate="2017-04-01T21:41:58.253" Title="What are the advantages of having two chroma channels and a luma channel vs. three chroma channels?" Tags="&lt;color&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4944" PostTypeId="2" ParentId="4943" CreationDate="2017-04-01T21:22:09.983" Score="2" Body="&lt;p&gt;Human eye is less sensitive to chrominance than luminance, which means you have a nifty way to compress the data by not measuring chrominance for each pixel, while you do measure luminance of all pixels. Although the black and white thing is part of the reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the subject RGB might be more intuitive, but its not actually a very good intuition when you start going deeper into how the human senses actually work. As it turns out RGB is a gross simplification. RGB is not good for measuring how far away different colors are from each other visually for example.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-04-01T21:22:09.983" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4945" PostTypeId="2" ParentId="4943" CreationDate="2017-04-01T21:41:58.253" Score="4" Body="&lt;p&gt;From a historical context, the YUV color encoding was originally designed to support the existing black-and-white infrastructure. In addition, as jooja mentioned, humans are generally less perceptive to changes in chroma and more perceptive to changes in luma. Both NTSC and PAL use less bandwidth for the chroma channel than the luma channel. In a digital context, we can use &lt;a href=&quot;https://en.wikipedia.org/wiki/Chroma_subsampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;chroma subsampling&lt;/a&gt; to achieve the same effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;YUV/YIQ/YDbDr is used for color PAL/NTSC/SECAM television broadcasts.&lt;br&gt;&#xA;YPbPr is used for component video cables.&lt;br&gt;&#xA;YCbCr is used for everything else.&lt;br&gt;&#xA;YCgCo is like YCbCr but is easier to compute.&lt;/p&gt;&#xA;" OwnerUserId="6380" LastActivityDate="2017-04-01T21:41:58.253" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4946" PostTypeId="2" ParentId="4937" CreationDate="2017-04-01T23:09:33.567" Score="1" Body="&lt;p&gt;I assume that you're using precomputed height map derivatives rather than calculating them on the fly (for details see &lt;a href=&quot;http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this post&lt;/a&gt; on Mikkelsen's blog). If we need to supply pre-computed height derivatives, then we have to supply two channels, just like a normal map. One could argue that derivative mapping doesn't require the presence of a tangent vertex attribute like normal mapping does, but the extra differentiation operations on the height map somewhat nullify that performance gain. Derivative maps are a cool concept, but at the end of the day I don't think they are significantly better than normal mapping performance-wise (although conceptually I agree that derivative maps are easier to work with because we don't have to deal with tangent space).&lt;/p&gt;&#xA;" OwnerUserId="6380" LastEditorUserId="6380" LastEditDate="2017-04-02T00:01:57.743" LastActivityDate="2017-04-02T00:01:57.743" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4947" PostTypeId="1" AcceptedAnswerId="4949" CreationDate="2017-04-02T01:18:05.610" Score="2" ViewCount="147" Body="&lt;p&gt;I'm gonna start this off with an... &quot;indexed image&quot;? If that's the proper term for it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cao4b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cao4b.png&quot; alt=&quot;All 12 possible cross-sections of both possible sorted RGB-6 cubes; each color represented in 12x12 pixel tiles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this 384x144 image were actually only the top-left 192x48 pixels (I'll refer to that portion as &quot;0,0&quot;), I feel like the other five sections could most likely be generated by using a single automatic operation that applies the following RGB value (swaps/rotations) to all pixels in section 0,0 simultaneously:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;0,1: Red -&gt; Green -&gt; Blue -&gt; Red (#FFAA55 -&gt; #55FFAA for one example)&lt;/li&gt;&#xA;&lt;li&gt;0,2: Red -&gt; Blue -&gt; Green -&gt; Red (#FFAA55 -&gt; #AA55FF)&lt;/li&gt;&#xA;&lt;li&gt;1,0: Green &amp;lt;-&gt; Blue (#FFAA55 -&gt; #FF55AA)&lt;/li&gt;&#xA;&lt;li&gt;1,1: Red &amp;lt;-&gt; Green (#FFAA55 -&gt; #AAFF55)&lt;/li&gt;&#xA;&lt;li&gt;1,2: Red &amp;lt;-&gt; Blue (#FFAA55 -&gt; #55AAFF)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What is the name of the operation I'm looking for + what image editing programs can perform that operation? I tried Googling a bunch of things along the lines of &quot;rgb rotate&quot;, &quot;rgb exchange&quot;, &quot;rgb swap&quot;, &quot;rgb trade&quot;, etc. etc. etc. and I couldn't quickly + intuitively find anything that did what I wanted it to do in a single swing. The amount of stuff completely unrelated to what I had in mind that came up honestly quickly got &lt;em&gt;really&lt;/em&gt; frustrating. I even tried Googling &quot;triadic rotation&quot; and nothing related to what I had in mind showed up on the 1st page.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason for the sorted colors instead of an actual image is basically the same reason I have to ask this question in the first place; I can't do it automatically with the free tools that I'm currently aware of the existence of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had to sort those 64 colors manually 6 times over with paint.net; which thankfully has functions that made it slightly easier to do, though there's definitely no way that I could quickly apply the effect I'm talking about to any actual image of any kind using paint.net (unless it has some feature I'm not yet aware of). I'm pretty sure there should be a way to apply that effect automatically; I just don't know the name of that effect + therefore can't even search for it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One thing that came up a few times during my failed attempts at searching was &quot;hue rotation&quot;; however as far as I know + could observe that not only applies to only one hue range at a time, but also pays more attention to hue angle than actual RGB values (if that makes any sense). So I really don't think hue rotation is what I'm looking for; though if it's suggested to me anyway I will try it again as long as I'm given specific instructions on how to use it to achieve the effect that I desire.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I'm not using a tag that I should be using, or even outright posting on the wrong Stack Exchange site for the question; please let me know.&lt;/p&gt;&#xA;" OwnerUserId="6376" LastActivityDate="2017-04-02T02:30:28.350" Title="What is the name of the RGB thing I want to be able to do, and what free program(s) can do it automatically?" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4948" PostTypeId="2" ParentId="4919" CreationDate="2017-04-02T01:54:13.180" Score="0" Body="&lt;p&gt;The field you want to study is called &lt;strong&gt;&lt;em&gt;Photogrammetry&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One place to begin is &lt;a href=&quot;https://en.wikipedia.org/wiki/Photogrammetry&quot; rel=&quot;nofollow noreferrer&quot;&gt;the Wikipedia article on the topic&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Actually the field is broader than what you are asking about but there is a more specific Wikipedia article on just this subfield too: &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/3D_reconstruction_from_multiple_images&quot; rel=&quot;nofollow noreferrer&quot;&gt;3D reconstruction from multiple images&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="1647" LastActivityDate="2017-04-02T01:54:13.180" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4949" PostTypeId="2" ParentId="4947" CreationDate="2017-04-02T02:30:28.350" Score="2" Body="&lt;p&gt;Swapping color channels is called channel swap or swizzling. (Searching for &quot;RGB channel swap&quot; brings up lots of relevant results.) Looking at your image, the squares in the right half appear to be flipped across the diagonal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most editing apps have a channel mixer tool that allows you to calculate each output color channel as some combination of the input color channels. In Photoshop it's called &quot;Channel Mixer&quot;. I've also seen it referred to as &quot;Color Operations&quot; or just &quot;Color Ops&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The flipping can usually be done with a horizontal flip followed by a vertical flip.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-04-02T02:30:28.350" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4950" PostTypeId="1" CreationDate="2017-04-02T14:37:49.790" Score="3" ViewCount="190" Body="&lt;p&gt;I am an aspiring CG programmer and would like to know what some of the more nuanced aspects of computer architecture are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have already taken several introductory arch courses where we've covered things like cache levels, basic multi-staged piplined datapaths, and memory structures (NUMA, Von Neumann), etc. I have also spent time understanding the basics of CUDA programming and SIMT work distribution models.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any special aspect of architecture that you only learned outside of the classroom/in the real world that comes in handy when writing graphics applications?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;: some people think my phrasing is too broad. When I say CG programmer, I mean someone who writes their own Vulkan/D3D application from scratch. I do not mean someone who writes games in Unity and wants to improve their performance based on platform architecture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be &lt;strong&gt;even more&lt;/strong&gt; specific, I should mention that I'm asking because of a presentation on architecture that I'm supposed to give that's coming up. I'm supposed to present on a topic &lt;em&gt;related&lt;/em&gt; to architecture, but I'm kinda sick of going over the same old things. This is my third course on the subject and am a little sick of learning how caches work. A good example of something that I'm looking for is hyperthreading. I'd never heard about this until someone presented on it earlier in the semester.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 2&lt;/strong&gt; I think I've found my own answer. &lt;a href=&quot;http://15418.courses.cs.cmu.edu/spring2017/&quot; rel=&quot;nofollow noreferrer&quot;&gt;This CMU lecture series&lt;/a&gt; has a bunch of slides talking about modern parallel architecture and algorithms. &lt;a href=&quot;http://15418.courses.cs.cmu.edu/spring2013content/lectures/22_heterogeneity/heterogeneity_slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;These&lt;/a&gt; slides on heterogeneous systems is particularly interesting to me.&lt;/p&gt;&#xA;" OwnerUserId="6384" LastEditorUserId="6384" LastEditDate="2017-04-03T16:31:57.080" LastActivityDate="2017-04-03T16:31:57.080" Title="What aspects of GPU architecture are computer graphics programmers expected to be intimately familiar with?" Tags="&lt;gpu&gt;&lt;gpgpu&gt;&lt;terminology&gt;" AnswerCount="0" CommentCount="4" ClosedDate="2017-04-03T12:49:44.383" ContentLicense="CC BY-SA 3.0" />
  <row Id="4951" PostTypeId="1" CreationDate="2017-04-03T00:24:11.490" Score="1" ViewCount="182" Body="&lt;p&gt;In path-tracing, is a specular reflection model like Blinn-Phong useful? Is it more accurate to render a complete reflection dependent on the objects roughness?&lt;/p&gt;&#xA;" OwnerUserId="6387" LastActivityDate="2017-04-03T00:24:11.490" Title="Pathtracing specular reflections vs. specular highlights" Tags="&lt;pathtracing&gt;&lt;specular&gt;&lt;reflection&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4952" PostTypeId="1" CreationDate="2017-04-03T23:11:37.860" Score="7" ViewCount="598" Body="&lt;p&gt;I am working on a planet visualizer, which at this point is little more than the NASA blue marble image applied as a diffuse texture.  For the atmospheric rim, I am simply blending in a constant color depending on Fresnel.  It looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qClko.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qClko.png&quot; alt=&quot;earth from space&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Besides the obvious problems (no clouds) I am struggling to understand what techniques are applicable at this scale.  As I understand it, normal mapping is simply a modeling of surface features below the threshold of polygon resolution.  Likewise, roughness-based BRDFs are simply a modeling of surface features below the threshold of normal maps.  In my case, I am using the 8k texture map at 500m resolution.  Does it make sense to normal map the Earth from this distance?  How would I even do that?  Is there a height map for the planet?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there other techniques that are more applicable to rendering (real) planets like this?  My next step is to make a specular mask based on water cover, but I feel like I am missing something else.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;P.S.  I noticed that the NASA blue marble image didn't render well when I enabled gamma correction, nor when I divided its texel values by $\pi$ before computing the light value.  I'm not sure why that is.&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastEditorUserId="231" LastEditDate="2017-04-04T20:57:33.890" LastActivityDate="2018-02-02T21:27:29.960" Title="Does normal mapping make sense for a view of earth from space?" Tags="&lt;texture&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4953" PostTypeId="2" ParentId="4008" CreationDate="2017-04-04T02:43:50.083" Score="2" Body="&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;When you say $acos(\|v\|\|p\|)$ are you saying $acos(\|\hat{v} \cdot \hat{p}\|)$? If not the second, your angle will be some bizarre thing (In fact, you'll always get 90deg).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How are you applying the rotation? &lt;code&gt;glRotate&lt;/code&gt;? Have you tried glRotate with the negative of your estimated angle?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Are you doing rotation/scaling/translation in the right order? Could you post the actual code that is executing if it is short? (If not, then a small runnable excerpt?)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Also: I'd be quite careful, as the cross-product-as-axis approach will produce goofy results when $v \parallel u$.&lt;/p&gt;&#xA;" OwnerUserId="1988" LastActivityDate="2017-04-04T02:43:50.083" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4954" PostTypeId="2" ParentId="4919" CreationDate="2017-04-04T02:51:53.187" Score="6" Body="&lt;p&gt;This is a bit different from a conventional photogrammetry problem. You're not trying to estimate a 3D world from 2D projections. You have actual 3D information - you have the imaging slices - and you want to assemble them into a 3D model. That's a much easier problem, the kind you can solve from the comfort of your couch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do know the cutting planes that each image belongs to? If so, you can easily assemble them. Just plop down the images at each plane. If not, it will be hard to determine how the images stack. (Is image N on top of or below image K?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the images are not all taken from parallel cutting planes, then your problem is a bit easier. You can compute point correspondences between the slices and solve the alignment as an iterative registration problem. (i.e. every point in every image that &quot;corresponds&quot; should be at the same point in 3D space)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, making this into a 3D point cloud is easy - I would drop points based on the density at each point in each image, so that empty spaces are empty and dense objects have many points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Building a mesh is way more difficult. If that's what you intend to do, and you're okay with hokey results, you might consider a triangulation approach to mesh building.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want good results, I would forego trying to fit a mesh to the cloud, and instead try to find density level sets in each 2D image, and see if you can build volumetric objects by following those level sets as isosurfaces in the 3D assembled scan.&lt;/p&gt;&#xA;" OwnerUserId="1988" LastActivityDate="2017-04-04T02:51:53.187" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4955" PostTypeId="1" CreationDate="2017-04-04T12:00:32.950" Score="1" ViewCount="208" Body="&lt;p&gt;I am trying to measure width of an object in image. The object size is 2D object 15cm X 15cm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I capture a frame with resolution 1280 X 720 (16:9) I am getting that the object width is 50px.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But when I capture a frame resolution 640 X 480 (4:3) I am getting that the object width is 30px.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The distance between the object and the camera did not changed during the test.&#xA;I didn't find a transformation that can convert the width in pixels from 1280 X 720 to 640 X 480. I think that the aspect ratio is the issue here but I didn't succeed to solve it out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I know that the width in pixels is both resolutions is actually the same object size?&lt;/p&gt;&#xA;" OwnerUserId="3305" LastActivityDate="2017-04-04T16:30:24.900" Title="Transformation between aspect ratio" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4956" PostTypeId="2" ParentId="4941" CreationDate="2017-04-04T12:42:12.333" Score="3" Body="&lt;p&gt;This never writes anything to the output file because you haven't included any code to write to the output file. The only time you touch the file after opening it is in the line&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;png-&amp;gt;MakeFromFILE(pFile);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which &lt;strong&gt;reads&lt;/strong&gt; from the file &lt;strong&gt;into&lt;/strong&gt; the &lt;code&gt;SkData&lt;/code&gt; instance. It won't even do that in this case, because the file handle has to be open for reading only.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm no expert on Skia, but you probably want to use &lt;a href=&quot;https://skia-doc.commondatastorage.googleapis.com/doxygen/doxygen/html/classSkFILEWStream.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;SkFILEWStream&lt;/code&gt;&lt;/a&gt; to write the file. Or just call &lt;code&gt;png.bytes()&lt;/code&gt; and write the bytes to the file using the standard library.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-04-04T12:42:12.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4957" PostTypeId="2" ParentId="4955" CreationDate="2017-04-04T16:30:24.900" Score="1" Body="&lt;p&gt;It looks to me like the vertical dimension is the one to use for scaling:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac{50\text{ px}}{720\text{ px}} \approx \frac{30\text{ px}}{480\text{ px}}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a slight error there, but it's only a few pixels. I'm not sure if the object sizes you mentioned were intended to be precise to the nearest pixel (30 and 50 are roundish numbers).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Typically when switching between aspect ratios, the vertical FOV would remain constant while the horizontal FOV widens or narrows to match the aspect ratio.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-04-04T16:30:24.900" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4958" PostTypeId="2" ParentId="4952" CreationDate="2017-04-05T02:34:16.480" Score="4" Body="&lt;p&gt;In my opinion, yes, it does. I've heard it claimed that in reality, the ratio of the tallest mountain on Earth to the Earth's diameter is smaller than the variations in height of an apple's skin to its diameter. So I can't say that it would be realistic, but it certainly looks better than not doing it. At the least it gives you some shading between high and low spots, even with a simple directional light.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-04-05T02:34:16.480" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4959" PostTypeId="1" AcceptedAnswerId="4960" CreationDate="2017-04-05T06:50:29.980" Score="5" ViewCount="422" Body="&lt;p&gt;Problem X: I need to provide &quot;compensation&quot; streams for attributes that are not plugged by the mesh data, but the shader requires them.&#xA;(In d3d not matching the input layout is a hard error)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solution Y: In D3D I've created a 16 bytes buffer initialized with some default color (when the missing semantic is color, let's take this as my typical use case) and specified a stride of zero so that one element is repeated whatever the index in the index buffer, and this way I don't need to clog VRAM with the biggest buffer that's necessary to cover all objects. This works in D3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But looking at &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glVertexAttribPointer.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;glVertexAttribPointer&lt;/a&gt; I see that the API is eating away my stride and makes it automatic when I specify zero.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any workaround ?&lt;/p&gt;&#xA;" OwnerUserId="1614" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:54:31.750" LastActivityDate="2018-03-04T19:54:31.750" Title="OpenGL set a vertex element stride of zero" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4960" PostTypeId="2" ParentId="4959" CreationDate="2017-04-05T07:59:44.857" Score="5" Body="&lt;p&gt;Disable the vertex attrib array and use &lt;code&gt;glVertexAttrib&lt;/code&gt; to set the data that should be used.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-04-05T07:59:44.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4961" PostTypeId="2" ParentId="4959" CreationDate="2017-04-05T13:54:10.807" Score="5" Body="&lt;p&gt;You can set a stride of zero with OpenGL 4.3's &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Specification#Separate_attribute_format&quot; rel=&quot;noreferrer&quot;&gt;separate attribute format&lt;/a&gt; API, or the ARB_vertex_attrib_binding extension:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexBuffer(index, buffer, offset, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The stride of zero will be a real stride of zero.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This also has the benefit of looking a lot more familiar to D3D users than the &lt;code&gt;glVertexAttribPointer&lt;/code&gt; API.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-04-05T13:54:10.807" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4962" PostTypeId="1" AcceptedAnswerId="4965" CreationDate="2017-04-05T18:15:09.107" Score="3" ViewCount="946" Body="&lt;p&gt;For the fun of it, I've taken up a task of writing a level editor for a voxel game.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is to have window that contains two main components. First component is openGL viewport placed in lower left or right corner of the window (or anywhere, really). The rest would be occupied with the second component, you guessed it, the GUI. It would consist of the menu bar, status bar and various options to select tools to use. It could also contain dialog boxes to manage metadata contained in the map. The GUI stuff. It would have this general look:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Z4w4f.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z4w4f.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question here is whether those two would get along. I've been googling for a while and have failed to find any specific info on openGL to GUI interaction and vice versa.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I free to just use any GUI library with openGL, limiting the latter to a part of the window, or are there some things I'd have to look out after. I know it's a bit of a general question, but I really didn't manage to find any specific information on this. &lt;/p&gt;&#xA;" OwnerUserId="5215" LastActivityDate="2018-03-04T00:39:07.157" Title="Clashes when combining openGL and GUI" Tags="&lt;opengl&gt;&lt;ui&gt;" AnswerCount="4" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4964" PostTypeId="1" AcceptedAnswerId="4968" CreationDate="2017-04-06T10:01:24.110" Score="5" ViewCount="1523" Body="&lt;p&gt;gl.drawArrays()/gl.drawElements() initiates a drawing and returns immediately.&#xA;There is also (non-recommended) gl.finish() that (theoretically) blocks execution until rendering is complete.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to receive event when rendering is complete, or other ways to track status of rendering, without blocking execution of the main thread? If there are, how well they work with Offscreen rendering (to a buffer)?&lt;/p&gt;&#xA;" OwnerUserId="6404" LastEditorUserId="6404" LastEditDate="2017-04-06T12:41:15.740" LastActivityDate="2017-04-06T23:45:22.017" Title="How to know when rendering is complete in WebGL?" Tags="&lt;rendering&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4965" PostTypeId="2" ParentId="4962" CreationDate="2017-04-06T10:01:55.410" Score="3" Body="&lt;p&gt;General answer is that creating a window as a GUI element with some GUI designer library involves subclassing some basic GUI element (like widget in QtCreator for example) with class providing handling GL context in more or less user friendly way (like &lt;code&gt;QOpenGLWidget&lt;/code&gt; in QtCreator which provide some user friendly wrapper or on the other hand basic Win32 API handle) and override methods for handling its framebuffer drawing or resizing, swapping buffers etc. with usual gl extensions provided by some lib you use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will work perfectly fine with other GUI elements.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know which GUI lib or IDE with GUI designer or language you prefer but most good libs can handle this. You can even do it in Assembler with WinApi GUI elements.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-04-06T10:13:27.050" LastActivityDate="2017-04-06T10:13:27.050" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4967" PostTypeId="2" ParentId="4937" CreationDate="2017-04-06T17:19:42.487" Score="5" Body="&lt;p&gt;After some researches and some answers from professionals here is my conclusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Don’t require tangents or binormals. Less interpolators.&lt;/li&gt;&#xA;&lt;li&gt;Only need two channels. less texture memory.&lt;/li&gt;&#xA;&lt;li&gt;Don’t suffer from tangent seams.&lt;/li&gt;&#xA;&lt;li&gt;Can be blended using alpha blending, without renormalization.&lt;/li&gt;&#xA;&lt;li&gt;Less mesh memory: We don’t need to store a tangent vector.&lt;/li&gt;&#xA;&lt;li&gt;Fast implementation.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;More ALU&lt;/li&gt;&#xA;&lt;li&gt;Less flexible. A normal map can represent any derivative map, but the reverse is not true. As an example, sharp edges can be difficult to represent.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So, that's a lot of pros compared to cons. But the major problem is that it's not an industry standard.&lt;br&gt;&#xA;There are almost no content authoring tools nor artist know-how.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's is a quote from &lt;a href=&quot;https://twitter.com/BartWronsk&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bart Wronski&lt;/a&gt; that illustrates well the current status of derivative maps :&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Sadly in life / technology not always best solution wins / not even&#xA;  gets deserved attention... It's more about standards and inertia.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If you are interested in knowing more about derivative maps here are some interesting articles.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://mmikkelsen3d.blogspot.fr/2011/07/derivative-maps.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mikkelsen and 3D Graphics: Derivative Maps | Morten Mikkelsen Blog&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.rorydriscoll.com/2012/01/11/derivative-maps/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Derivative Maps | CodeItNow&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.rorydriscoll.com/2012/01/15/derivative-maps-vs-normal-maps/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Derivative Maps vs Normal Maps | CodeItNow&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://therobotseven.com/devlog/triplanar-texturing-derivative-maps/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Triplanar Texturing with Derivative Maps | The Robot Seven&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://polycount.com/discussion/91605/derivative-normal-maps-what-are-they&quot; rel=&quot;nofollow noreferrer&quot;&gt;Derivative Normal Maps - What are they? | polycount.com&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://docs.knaldtech.com/doku.php?id=derivative_maps_knald&quot; rel=&quot;nofollow noreferrer&quot;&gt;Derivative Maps | Knald Technologies Documentation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If I forgot something or if your don't agree feel free to tell in the comments, I would be glad to improve this answer.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T09:41:30.730" LastActivityDate="2018-04-09T09:41:30.730" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4968" PostTypeId="2" ParentId="4964" CreationDate="2017-04-06T18:09:07.647" Score="3" Body="&lt;p&gt;You can utilize &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_sync.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_sync&lt;/a&gt; or in other words &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Sync_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;sync objects&lt;/a&gt; which have been core since 3.2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the point-of-view of OpenGL then right after issuing a specific command (you want to know whether has finished), you'd insert a fence.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Say you want to check if a &lt;code&gt;glDrawArrays()&lt;/code&gt; call has been executed.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawArrays(...);&#xA;GLsync sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Note that if &lt;code&gt;glFenceSync()&lt;/code&gt; fails it will return &lt;code&gt;0&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can now check whether it has finished by doing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLint signaled = 0;&#xA;glGetSynciv(sync, GL_SYNC_STATUS, 1, NULL, &amp;amp;signaled);&#xA;&#xA;if (signaled == GL_SIGNALED)&#xA;    // Done&#xA;else&#xA;    // Not done&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can then of course repeatably call &lt;code&gt;glGetSynciv()&lt;/code&gt; and check when you receive &lt;code&gt;GL_SIGNALED&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to completely block until it's done then you can do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLenum status = glClientWaitSync(sync, 0, 0);&#xA;&#xA;if (status == GL_CONDITION_SATISFIED)&#xA;    // Done&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It blocks and waits for up to &lt;code&gt;timeout&lt;/code&gt; nanoseconds (the last parameter).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember to delete the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Sync_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;sync object&lt;/a&gt; again:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDeleteSync(sync);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When it comes to WebGL. Then note that sync objects are not supported in WebGL 1.0. They are however in WebGL 2.0 in the form of &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/WebGLSync&quot; rel=&quot;nofollow noreferrer&quot;&gt;WebGLSync&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;The equivalent to the above code in WebGL 2.0 would be the following:&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0);&#xA;&#xA;var signaled = gl.getSyncParameter(sync, gl.SYNC_STATUS);&#xA;&#xA;if (signaled == gl.SIGNALED)&#xA;    // Done&#xA;else&#xA;    // Not done&#xA;&#xA;var status = gl.clientWaitSync(sync, 0, 0);&#xA;&#xA;if (status == gl.CONDITION_SATISFIED)&#xA;    // Done&#xA;&#xA;gl.deleteSync(sync);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4776" LastEditorUserId="4776" LastEditDate="2017-04-06T23:45:22.017" LastActivityDate="2017-04-06T23:45:22.017" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="4969" PostTypeId="1" AcceptedAnswerId="4971" CreationDate="2017-04-06T21:59:09.380" Score="5" ViewCount="1286" Body="&lt;p&gt;I'm in the process of working out how to pack all the information I need for a Physically Based Deferred Renderer into a G-Buffer without using an obscene amount of render targets. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I have so far is 4 3-part vectors: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Albedo/Diffuse&lt;/li&gt;&#xA;&lt;li&gt;Normal&lt;/li&gt;&#xA;&lt;li&gt;Tangent&lt;/li&gt;&#xA;&lt;li&gt;Position&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And 4 single components&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Metallic&lt;/li&gt;&#xA;&lt;li&gt;Roughness&lt;/li&gt;&#xA;&lt;li&gt;Height&lt;/li&gt;&#xA;&lt;li&gt;Ambient Occlusion&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;A naive approach is to bundle one of the single components into the alpha (fourth) channel with one of the 3-part vectors, which is my current line of investigation. However, given that four 4-channel full precision floating point render targets isn't small I understand it's common to use half precision and even smaller representations to be more memory conscious. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'm asking is: which components can I safely cut precision down on without losing quality, and by how much?&lt;/p&gt;&#xA;" OwnerUserId="6406" LastActivityDate="2017-04-06T23:22:46.880" Title="How much precision do I need in my G-Buffer?" Tags="&lt;optimisation&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4970" PostTypeId="1" AcceptedAnswerId="4992" CreationDate="2017-04-06T22:57:54.143" Score="4" ViewCount="368" Body="&lt;p&gt;Link to paper : &lt;a href=&quot;http://www2.lawrence.edu/fast/GREGGJ/CMSC420/chapter21/Irradiance.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Irradiance and Incoming Radiance | lawrence.edu&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Using a shader to compute En&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FeT3I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FeT3I.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Computing En as described above is a very compute intensive operation,&#xA;  because we have to compute the integral over the cube map for each new&#xA;  direction vector n that we want to work with. At the same time, the&#xA;  details for different values of n are highly repetitive. This suggests&#xA;  that we should enlist the aid of shaders to compute this mapping for&#xA;  us. Here is the outline of a strategy that makes it possible to do&#xA;  this.&lt;/p&gt;&#xA;  &#xA;  &lt;ol&gt;&#xA;  &lt;li&gt;Use OpenGL to render a two dimensional square centered at the origin&#xA;  with sides of length 2. This square represents one of the sides of our&#xA;  cubical irradiance map. Given the mapping above we can map any point&#xA;  (x , y) on the square to a direction vector n. &lt;/li&gt;&#xA;  &lt;li&gt;We render the square to&#xA;  a framebuffer with dimensions size by size pixels, where size is the&#xA;  desired size of our irradiance cube map texture. &lt;/li&gt;&#xA;  &lt;li&gt;In the fragment&#xA;  shader, we translate the interpolated fragment positions we are given&#xA;  into direction vectors n and construct loops that sum over the six&#xA;  faces of the environment map:&lt;/li&gt;&#xA;  &lt;/ol&gt;&#xA;  &#xA;  &lt;p&gt;When rendering is done, we convert the image in the frame buffer to a&#xA;  texture for use by our irradiance cube map.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I understand that Li is color at i. ωi is the direction of incoming light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I do not understand what dωi is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Paper describes it as...&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Computing the solid angle dωi subtended by a particular texel is a&#xA;  little more involved. Texels near the center of the texture subtend a&#xA;  somewhat larger angle, while texels near the corner take up a smaller&#xA;  solid angle when we map the cube texture onto a sphere. Here is a&#xA;  reference that explains how to compute the solid angle correctly from&#xA;  the positions xi and yi.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;However I am not following words to understand what it means.&lt;/p&gt;&#xA;" OwnerUserId="6282" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:56:57.423" LastActivityDate="2018-03-04T19:56:57.423" Title="Irradiance Map Equation What is &quot;dω&quot;?" Tags="&lt;lighting&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4971" PostTypeId="2" ParentId="4969" CreationDate="2017-04-06T23:22:46.880" Score="4" Body="&lt;p&gt;First of all, you don't need position in the G-buffer at all. The position of a pixel can be &lt;a href=&quot;https://mynameismjp.wordpress.com/2010/09/05/position-from-depth-3/&quot; rel=&quot;noreferrer&quot;&gt;reconstructed from the depth buffer&lt;/a&gt;, knowing the camera setup and the pixel's screen-space xy position. So you can get rid of that whole buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, you don't ordinarily need tangent vectors in the G-buffer either. They're only needed for converting normal maps from tangent space, and for parallax mapping; these would be done during the G-buffer fill pass (when you have tangents from the mesh you're rendering), and the G-buffer would only store normals in world or view space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Material properties like colors, roughness, and metallic are usually just 8-bit values in the G-buffer, since they're sourced from 8-bit textures. Same for AO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Height is also not needed in the G-buffer unless you're going to be doing some kind of multi-pass blending that depends on it, but if you do need it, 8 bits is probably enough for that too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normals can be benefit from being stored as 16-bit values rather than 8-bit. Half-float is okay, but 16-bit fixed-point is even better, as it gives you more uniform precision across all orientations (half-float is more precise near the axes and loses some precision away from them). Moreover, you can cut them from 3 components down to 2 using &lt;a href=&quot;http://jcgt.org/published/0003/02/01/&quot; rel=&quot;noreferrer&quot;&gt;octahedral mapping&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, at the end of the day, a minimal G-buffer might look like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Material color + metallic: RGBA8&lt;/li&gt;&#xA;&lt;li&gt;Octahedral world-space normal + roughness + AO: RGBA16&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;and that's all! Only 12 bytes per pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, you could use an RG16 buffer for the normals, and move roughness + AO into a separate 8-bit buffer. That would give you some room to grow should you eventually need more G-buffer components of either 8-bit or 16-bit sizes.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-04-06T23:22:46.880" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4972" PostTypeId="1" AcceptedAnswerId="4988" CreationDate="2017-04-07T07:54:11.457" Score="3" ViewCount="163" Body="&lt;p&gt;I'm confused by the &lt;code&gt;Waves&lt;/code&gt; class &lt;a href=&quot;https://github.com/utilForever/DirectX/blob/master/DirectX%2011/Frank%20D.%20Luna/Common/Waves.cpp#L55&quot; rel=&quot;nofollow noreferrer&quot;&gt;implementation&lt;/a&gt; in the source code of the book &lt;em&gt;Introduction to 3D Game Programming with DirecX11&lt;/em&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float d = damping*dt+2.0f;&#xA;float e = (speed*speed)*(dt*dt)/(dx*dx);&#xA;mK1     = (damping*dt-2.0f)/ d;&#xA;mK2     = (4.0f-8.0f*e) / d;&#xA;mK3     = (2.0f*e) / d;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What do the parameters mean? How are the waves generated? I've tried searching waves implementation and found &lt;a href=&quot;https://stackoverflow.com/questions/6716887/how-to-render-ocean-wave-using-opengl-in-3d&quot;&gt;https://stackoverflow.com/questions/6716887/how-to-render-ocean-wave-using-opengl-in-3d&lt;/a&gt; , I looked up the links mentioned by the answer but I couldn't understand the complicated equations and it seems that the equations have no relation with the code above. I also tried searching &quot;spatially damped wave&quot;, and then I found &lt;a href=&quot;https://physics.stackexchange.com/questions/223366/wave-equation-with-spatial-damping&quot;&gt;https://physics.stackexchange.com/questions/223366/wave-equation-with-spatial-damping&lt;/a&gt;, that didn't help me, neither...&lt;/p&gt;&#xA;" OwnerUserId="6407" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-08-10T13:29:45.910" Title="How does the Waves class in the book Introduction to 3D Game Programming with DirecX11 work?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4973" PostTypeId="2" ParentId="4962" CreationDate="2017-04-08T06:18:54.387" Score="2" Body="&lt;p&gt;Some of the easy to use GUI libraries for OpenGL I have come across are (in no specific order):&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/ocornut/imgui&quot; rel=&quot;nofollow noreferrer&quot;&gt;imGUI&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/wjakob/nanogui&quot; rel=&quot;nofollow noreferrer&quot;&gt;NanoGUI&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://anttweakbar.sourceforge.net/doc/&quot; rel=&quot;nofollow noreferrer&quot;&gt;AntTweakBar&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Although AntTweakBar is bit outdated, it's still pretty easy to use. imGUI is definitely the one you should have a look at once. I personally haven't used NanoGUI but have heard good things about it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2017-04-08T06:18:54.387" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4974" PostTypeId="2" ParentId="4962" CreationDate="2017-04-08T10:46:11.840" Score="2" Body="&lt;p&gt;At one point I had a similiar issue, however, I was using DirectX as opposed to OpenGL so this may not be very helpful but you might be able to gain some knowledge out of this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main objective was to create a level editor with basic functionality such as importing models and postioning. I wanted to use C# and WinForms rather than having to learn another entire framework like Qt. I made my engine available as a DLL and exposed a C-style function that intialized my engine with a provided HWND (a C# panel). This enabled me to render to the panel, so I then expanded upon this 'link' and proceeded to add on additional functionality like importing objects.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// in C++:&#xA;extern &quot;C&quot; &#xA;{&#xA;  void InitializeMyEngine(HWND window);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can then then use P/Invoke in C# to access that function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class Engine&#xA;{&#xA;  [DllImport(&quot;engine.dll&quot;)]&#xA;  public static extern void Initialize(IntPtr window);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I then called &lt;code&gt;Engine.Initialize(someWindowHandle)&lt;/code&gt; in my C# code to initialize the engine. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a link to where asked how I could do this on the gamedev stack exchange: &lt;a href=&quot;https://gamedev.stackexchange.com/questions/124249/how-do-i-render-my-directx-c-engine-to-a-c-panel&quot;&gt;https://gamedev.stackexchange.com/questions/124249/how-do-i-render-my-directx-c-engine-to-a-c-panel&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I got a few answers and I managed to do what I needed to do (which I've of course detailed there). There is much more detail and code available regarding the implementation aswell. I would suggest asking on the &lt;a href=&quot;http://gamedev.stackexchange.com&quot;&gt;GameDev Stack Exchange&lt;/a&gt; if you don't find a sufficient answer here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jcvYM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jcvYM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(photo of the engine rendering a cyan screen when the button is pressed using the method I described)&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="-1" LastEditDate="2017-04-13T12:18:54.697" LastActivityDate="2017-04-08T10:46:11.840" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4977" PostTypeId="1" AcceptedAnswerId="4978" CreationDate="2017-04-10T10:10:59.200" Score="2" ViewCount="597" Body="&lt;p&gt;I am currently reading through Peter Shirley's &lt;a href=&quot;https://www.amazon.in/Ray-Tracing-Weekend-Minibooks-Book-ebook/dp/B01B5AODD8&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing in One Weekend&lt;/a&gt;. In the beginning chapters where the author introduces diffuse surfaces we a presented with this function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 color(const ray&amp;amp; r, hitable *world)&#xA;{&#xA;hit_record rec;&#xA;if(world-&amp;gt;hit(r, 0.0, MAXFLOAT,rec))&#xA;  {&#xA;   vec3 target = rec.p + rec.normal + random_in_unit_sphere();&#xA;   return 0.5*color(ray(rec.p, target-rec.p), world);&#xA;  }&#xA;else&#xA;  {&#xA;   vec3 unit_direction = unit_vector(r.direction());&#xA;   float t = 0.5*(unit_direction.y() + 1.0);&#xA;   return (1.0-t)*vec3(1.0, 1.0, 1.0) + t*vec3(0.5, 0.7, 1.0);&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Can somebody where the actual definition for the function is? Because in the first part of the &lt;code&gt;if&lt;/code&gt;the return &lt;code&gt;value&lt;/code&gt; is &lt;code&gt;0.5*color(ray(rec.p, target-rec.p), world);&lt;/code&gt;. Will it execute the function again except go through the &lt;code&gt;else&lt;/code&gt;? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding what the function actually does here is what I have gathered from the book based on my current understanding:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Pick a random point s from the unit radius sphere that is tangent to the hitpoint, and send a&#xA;ray from the hitpoint p to the random point s. That sphere has center (p+N)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BmPFx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BmPFx.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Which then gives us:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/edqsj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/edqsj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-04-10T18:29:00.203" Title="Can somebody explain this Ray Tracing Function?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;vectors&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4978" PostTypeId="2" ParentId="4977" CreationDate="2017-04-10T10:36:13.927" Score="2" Body="&lt;pre&gt;&lt;code&gt;vec3 target = rec.p + rec.normal + random_in_unit_sphere();&#xA;return 0.5*color(ray(rec.p, target-rec.p), world);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;this is the exact same as &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 targetDir = rec.normal + random_in_unit_sphere();&#xA;return 0.5*color(ray(rec.p, targetDir), world);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In other words the sphere is a way to pick a random direction which is biased towards the normal direction without doing a lot of fancy maths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And yeah if that hits again it will repeat the process again and again until it hits the sky box. this can be avoided by adding a parameter to avoid unlimited recursion. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However that function is bad in general for a few reasons:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The color on hit should depend on the object's material (the color) and the relation between the normal vector the incoming eye ray and the outgoing light ray.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The light sky box is hardcoded to be a gradiant.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;only a single recursive sample on each hit. This gives very grainy images and requires a lot of samples per pixel to converge to a proper image.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-04-10T10:36:13.927" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4979" PostTypeId="1" AcceptedAnswerId="4994" CreationDate="2017-04-10T17:52:03.400" Score="35" ViewCount="8591" Body="&lt;p&gt;What is importance sampling? Every article I read about it mentions 'PDF' what is that as well?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I gather, importance sampling is a technique to only sample areas on a hemisphere that matter more than others. So, ideally, I should sample rays towards light sources to reduce noise and increase speed. Also, some BRDF's at grazing angles have little no difference in the calculation so using importance sampling to avoid that is good? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I were to implement importance sampling for a Cook-Torrance BRDF how could I do this? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="310" LastEditDate="2017-10-25T00:49:46.943" LastActivityDate="2019-11-13T20:00:45.940" Title="What is Importance Sampling?" Tags="&lt;brdf&gt;&lt;importance-sampling&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="21" ContentLicense="CC BY-SA 3.0" />
  <row Id="4980" PostTypeId="2" ParentId="4977" CreationDate="2017-04-10T18:29:00.203" Score="3" Body="&lt;p&gt;Good answer above.    (I like that the book adds in p then subtracts it.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a hard-coded grey world as a &quot;hello world&quot; kind of ray tracer.   The 0.5 is the hard-coded reflectance.   Keep working through book and the object reflectance and max-recursion will be addressed.   Ray branching I avoid like the plague.   In cost benefit I am always a skeptic on ray trees versus ray paths.&lt;/p&gt;&#xA;" OwnerUserId="6422" LastActivityDate="2017-04-10T18:29:00.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4981" PostTypeId="2" ParentId="4962" CreationDate="2017-04-10T20:33:01.677" Score="0" Body="&lt;p&gt;Take a look at Qt.  Qt is built on opengl and therefore integrates with it pretty easily.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://doc.qt.io/qt-5/qtopengl-hellogl2-example.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hello GL2 Example | Qt Documentation&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3332" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:39:07.157" LastActivityDate="2018-03-04T00:39:07.157" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4982" PostTypeId="1" CreationDate="2017-04-10T21:35:15.237" Score="5" ViewCount="522" Body="&lt;p&gt;Recently I have been having a rather confusing performance drop with loading in layers of a 2D texture array, but only in one case from what I can tell, leaving me to speculate on why it is happening as I have never seen anything like this before.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Firstly to explain some context for this problem, I implemented a simple version of a virtual texture atlas based on some papers I read by NVIDIA and idTech which in short loads textures (which have been split into fixed size tiles) into various levels of the 2D texture array based on which layers are considered &quot;free&quot; in a CPU-side list of free indices. Sampling in the fragment shader is then preformed by accessing a page table stored as a persistently coherently mapped SSBO (for CPU-side updating) which associates offsets in the UVs with layers of the texture array.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Due to the fact that the texture when created is uninitialized, every layer is considered free, so texture tiles to be loaded will slowly fill up the uninitialized layers (preferring them over previously freed layers). Once all of the uninitialized layers have been used, additional tiles will then begin overwriting previously freed layers, if any exist when needed. Also note that I am using &lt;code&gt;glCompressedTexSubImage3D&lt;/code&gt; to load in each layer and that I load in mipmap levels as well manually per layer with this call as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This system works fine and was tested rather extensively until I began to notice the problem which this question is about. In short, after all of the uninitialized layers of the texture array were used up, the next 5-15 (I don't know exactly how many, but it's just a few) texture tiles which are loaded suffer massive performance drops. After that, everything returns to normal and the problem never returns (from what I can tell). Also note that this is while some currently drawn textures were also in use at the lower end of the texture array which is right before where the first free tiles begin (due to the first in first out nature of the free list).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Upon examining the problem further, I noticed through using the NVIDIA Nsight graphics profiling tool that the call after &lt;code&gt;glCompressedTexSubImage3D&lt;/code&gt; in the cases where performance was impacted blocks on the CPU for very long periods of time, usually 10-40ms per mipmap level (in this case it was &lt;code&gt;glGetError&lt;/code&gt;, but any other call following it had the same effect after disabling error checking to ensure that was not the problem).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the API was blocking, I assumed that it was some sort of synchronization issue with the GPU perhaps due to the locality of the newly loaded tiles with respect to tiles currently being drawn as it may have considered them &quot;in use&quot;. That hypothesis did not add up in my mind due to how long the calls were blocking for as each one was the length of multiple frames at 16ms as well as how this problem never appears to return even after multiple times through this same process, though I'm not ignoring that possibility.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another odd thing I found was that during the time the next call was blocking, many tiny GPU commands were being executed according to NVIDIA Nsight, which I usually only see under any sort of drawing activity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At this point I'm pretty much stumped and don't know what could possibly be causing this, so any help would be greatly appreciated. Additional details are provided below (and more can be requested if needed):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Texture Array&lt;/strong&gt; (there are 3 of them):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Format: &lt;code&gt;COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT&lt;/code&gt;, &lt;code&gt;COMPRESSED_RED_RGTC1&lt;/code&gt;,&#xA;&lt;code&gt;COMPRESSED_RG_RGTC2&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Extents: 256x256x512, 9 mipmap levels&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;GPU&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GeForce GTX 960M&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;NVIDIA Nsight Results&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wide view of 3 long frames where the slow texture loading happens (the line down the screen is centered on the first texture loading call):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nwjN4.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nwjN4.png&quot; alt=&quot;Overall view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Zoomed in view near the very start of the first slow call to &lt;code&gt;glCompressedTexSubImage3D&lt;/code&gt; (which cannot be seen as it only blocks for a few microseconds), note the many tiny green lines below the blocking &lt;code&gt;glGetError&lt;/code&gt; calls representing GPU commands (as again the line down the screen is centered on the first texture loading call):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SfLfV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SfLfV.png&quot; alt=&quot;Zoomed view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4837" LastEditorUserId="4837" LastEditDate="2017-04-10T21:40:19.603" LastActivityDate="2017-04-11T00:13:55.873" Title="Performance impact during texture layer loading" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4983" PostTypeId="1" CreationDate="2017-04-10T21:44:37.270" Score="1" ViewCount="182" Body="&lt;p&gt;Can i have a root signature with 3 root parameters all being of the UAV type? Because what I am trying to do is, add two buffers and put the output of that in a output buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the following snippet I am trying to do the afroementioned. However, I get an error at the line calling D3DX12SerializeVersionedRootSignature()&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it because I am not allowed to have 3 uav ranges?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;CD3DX12_DESCRIPTOR_RANGE1 ranges_madhu[3];&#xA;ranges_madhu[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE);&#xA;ranges_madhu[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE);&#xA;ranges_madhu[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE);&#xA;&#xA;CD3DX12_ROOT_PARAMETER1 rootParameters_madhu[ComputeRootParametersCount_madhu]; // this is 3   (thus all 3 ranges have been initialized as UAVs)&#xA;rootParameters_madhu[ComputeRootUAVTable_in1].InitAsDescriptorTable(1, &amp;amp;ranges_madhu[0], D3D12_SHADER_VISIBILITY_ALL);&#xA;rootParameters_madhu[ComputeRootUAVTable_in2].InitAsDescriptorTable(1, &amp;amp;ranges_madhu[1], D3D12_SHADER_VISIBILITY_ALL);&#xA;rootParameters_madhu[ComputeRootUAVTable_outp1].InitAsDescriptorTable(1, &amp;amp;ranges_madhu[2], D3D12_SHADER_VISIBILITY_ALL);&#xA;&#xA;CD3DX12_VERSIONED_ROOT_SIGNATURE_DESC computeRootSignatureDesc_madhu;&#xA;computeRootSignatureDesc_madhu.Init_1_1(_countof(rootParameters_madhu), rootParameters_madhu, 0, nullptr);&#xA;&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; signature1;&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; error1;&#xA;&#xA;ThrowIfFailed(D3DX12SerializeVersionedRootSignature(&amp;amp;computeRootSignatureDesc_madhu, featureData_madhu.HighestVersion, &amp;amp;signature1, &amp;amp;error1));&#xA;ThrowIfFailed(m_device-&amp;gt;CreateRootSignature(0, signature1-&amp;gt;GetBufferPointer(), signature1-&amp;gt;GetBufferSize(), IID_PPV_ARGS(&amp;amp;m_computeRootSignature1)));&#xA;NAME_D3D12_OBJECT(m_computeRootSignature1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6349" LastEditorUserId="48" LastEditDate="2017-04-10T21:59:48.300" LastActivityDate="2017-04-10T23:24:46.677" Title="DX12 compute signature" Tags="&lt;directx12&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4984" PostTypeId="2" ParentId="4983" CreationDate="2017-04-10T23:24:46.677" Score="2" Body="&lt;p&gt;You're trying to map all three UAVs to the same descriptor slot (slot 0).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ranges_madhu[0].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE);&#xA;ranges_madhu[1].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE);&#xA;ranges_madhu[2].Init(D3D12_DESCRIPTOR_RANGE_TYPE_UAV, 1, 0, 0, D3D12_DESCRIPTOR_RANGE_FLAG_DATA_VOLATILE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;baseShaderRegister&lt;/code&gt; value (the third parameter to these calls) indicates which descriptor slot to use. You have all of them set to 0, which won't work. They need to be distinct. For example, they could be 0, 1, and 2.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-04-10T23:24:46.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4985" PostTypeId="2" ParentId="4982" CreationDate="2017-04-11T00:13:55.873" Score="5" Body="&lt;p&gt;From the way the problem only manifests when you start overwriting previously used texture tiles, I suspect you're running afoul of some driver heuristic that's attempting to manage the lifetime of the texture data on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, when you update buffer or texture data from the CPU, the driver has to make sure it doesn't overwrite anything that might still be in use by the GPU (considering that the CPU and GPU run asynchronously to each other). There are various ways the driver can do this, such as internally double-buffering the texture, inserting sync points (for the CPU to wait on the GPU), or initially copying data to a temporary staging buffer and then later re-copying it to its final destination. All this stuff is under-the-hood and the driver makes its own decisions about what strategy to employ in any given situation, using some heuristics based on texture size, usage patterns, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can only guess at the details, but I suspect what's happening is that the driver is getting into a state where it thinks those previously-used texture tiles are still in use on the GPU somehow. Then when you start to overwrite them, it decides that it needs to make a second instance of the whole texture, and laboriously copies everything over before finally doing the updates you wanted—or something like that. That could be the many tiny draws you see in Nsight.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's still a mystery why it's taking tens of milliseconds to do that, though. Maybe the textures are large enough that a second copy of them causes you to run out of VRAM? In that case, you'd get a lot of thrashing as things are spilled to main RAM. That's just a guess, though. As for why the bad behavior only happens for a few tiles and then goes back to normal, it could be that the driver heuristics are deciding to switch to a different strategy at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, as for how to fix it, you might try using &lt;a href=&quot;http://docs.gl/gl4/glInvalidateTexSubImage&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glInvalidateTexSubImage&lt;/code&gt;&lt;/a&gt; whenever you free a texture tile. This lets the driver know that you don't care what was in that texture tile before, which &lt;em&gt;hopefully&lt;/em&gt; will convince it to just update the texture in-place rather than doing anything crazy with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another thing to try is to make sure you don't try to re-use a texture tile in the very next frame after you free it, but give it a frame or two of &quot;downtime&quot; before re-using it. But it sounds like that's probably the case already, given that you prefer unused tiles before you start re-using them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If that doesn't help, I'd recommend sending an email to devsupport@nvidia.com. The OpenGL driver team there can likely take your Nsight captures and help diagnose the issue, and fix it if it's due to a driver bug.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-04-11T00:13:55.873" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="4986" PostTypeId="1" AcceptedAnswerId="4987" CreationDate="2017-04-11T08:21:18.333" Score="6" ViewCount="1780" Body="&lt;p&gt;By using smooth shading (i.e. interpolation of normals), an object can have a smooth look despite low polygon count. A nasty artifact that can happen when casting shadow rays is the &lt;a href=&quot;http://wiki.povray.org/content/Knowledgebase:The_Shadow_Line_Artifact&quot; rel=&quot;noreferrer&quot;&gt;Shadow Line Artifact&lt;/a&gt;. Since shadow rays originate from a certain position and don't usually take the normal into account, a complete face on a smooth object will either be shadowed or not, revealing the hard edges again:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VH8eM.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VH8eM.png&quot; alt=&quot;Flat and smooth shading, right one with artifacts.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shadow is, so to speak, 'correct' and the weird appearance results from the normal map interpolation 'cheat'. Nevertheless, it is visually distracting. The linked article above, written in 2009, suggests removing shadows or self-shadows on objects that show this kind of artifact, which (especially for non-convex objects) is not a satisfying solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a very common problem inherent to ray tracing algorithms. I wonder if there is any better solution to it than subdividing the mesh into flat-shaded high-poly or getting rid of the shadows altogether.&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2017-04-11T08:28:47.623" LastActivityDate="2017-04-11T16:07:27.453" Title="Ray Tracing Shadows: The Shadow Line Artifact" Tags="&lt;raytracing&gt;&lt;shadow&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4987" PostTypeId="2" ParentId="4986" CreationDate="2017-04-11T16:07:27.453" Score="8" Body="&lt;p&gt;The shadow terminator problem (as it's also known) is still something of an open problem in ray-tracing. As you say, disabling self-shadowing is not a very good workaround, because non-convex meshes often &lt;em&gt;need&lt;/em&gt; to self-shadow. There's a possible refinement to this method. Instead of throwing away all shadow ray intersections with the same object, you can only throw away the intersection if it's with the same object and it's through the reverse face of the triangle (i.e. discard the intersection if $d\dot\ N &amp;gt; 0$, where $N$ is the geometric normal of the intersected polygon and $d$ is the shadow ray direction).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One alternative that I've used successfully is to offset the origin of the shadow ray a short distance along the surface normal. This way, the shadow ray originates not at the geometric surface of the mesh (which is only an approximation) but at the hypothetical surface of the real object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In theory, you should choose the distance along the normal according to the point's distance from that polygon's vertices, so that the origin is on the approximated surface, but in practice, a small fixed offset works for almost all situations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You should also be sure to use the normal rather than the geometric surface to decide whether the light is &quot;behind&quot; the surface. That is, if $N\dot\ L &amp;lt; 0$, the shading point is in shadow (without needing to cast a ray), where $N$ is the interpolated and shaded normal.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-04-11T16:07:27.453" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="4988" PostTypeId="2" ParentId="4972" CreationDate="2017-04-11T20:07:54.760" Score="2" Body="&lt;p&gt;This implementation represents the water as a regular height field grid. The function parameters &lt;code&gt;m&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt; are the dimensions of the grid, &lt;code&gt;dx&lt;/code&gt; is the regular distance between the water vertices, &lt;code&gt;dt&lt;/code&gt; is the time step, &lt;code&gt;speed&lt;/code&gt; is the speed of the movement and &lt;code&gt;damping&lt;/code&gt; is a constant to ease disturbance as the water flows from the disturbance center.&lt;/p&gt;&#xA;" OwnerUserId="303" LastEditorUserId="231" LastEditDate="2017-04-12T11:28:55.877" LastActivityDate="2017-04-12T11:28:55.877" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4989" PostTypeId="1" CreationDate="2017-04-11T21:18:18.350" Score="0" ViewCount="46" Body="&lt;p&gt;I am pretty new to graphics programming using DX12. I was testing out my skills by building a shader to add 2 buffers and put the result in an output buffer. I have written this code in &quot;ComputeShader.hlsl&quot; however when i tried to invoke it using the following, i get an error sayin &quot;file not found&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L&quot;ComputeShader.hlsl&quot;).c_str(), nullptr, nullptr, &quot;main&quot;, &quot;cs_5_0&quot;, compileFlags, 0, &amp;amp;computeShader_madhu, nullptr));&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there something that I am doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="6349" LastActivityDate="2017-04-11T21:18:18.350" Title="DX12- hlsl code invoking" Tags="&lt;directx&gt;" AnswerCount="0" CommentCount="7" ClosedDate="2017-04-12T08:55:03.440" ContentLicense="CC BY-SA 3.0" />
  <row Id="4991" PostTypeId="1" CreationDate="2017-04-11T22:12:51.680" Score="0" ViewCount="117" Body="&lt;p&gt;So I am new to the DX12 world. I am currently trying to tweek the nbody_gravity DX12 sample, but appending or calling another Compute Shader which is to add 2 buffers to produce an output in a different buffer.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I have written this code in &quot;ComputeShader.hlsl&quot; however when i tried to invoke it using the following, i get an error sayin &quot;file not found&quot;&lt;/li&gt;&#xA;&lt;li&gt;When i printed the debug error it says the following: D3D12GetDebugInterface: This method requires the D3D12 SDK Layers for Windows 10, but they are not present on the system.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I am invoking my shader after the default invocation to the nBodyGravity.hlsl is done:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ComPtr&amp;lt;ID3DBlob&amp;gt; computeShader;&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; computeShader_m;&#xA;&#xA;#if defined(_DEBUG)&#xA;        // Enable better shader debugging with the graphics debugging tools.&#xA;        UINT compileFlags = D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;&#xA;#else&#xA;        UINT compileFlags = 0;&#xA;#endif&#xA;&#xA;&#xA;        ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L&quot;NBodyGravityCS.hlsl&quot;).c_str(), nullptr, nullptr, &quot;CSMain&quot;, &quot;cs_5_0&quot;, compileFlags, 0, &amp;amp;computeShader, nullptr));&#xA;&#xA;//extra call for my shader&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; error_ptr;&#xA;        ThrowIfFailed(D3DCompileFromFile(GetAssetFullPath(L&quot;ComputeShader.hlsl&quot;).c_str(), nullptr, nullptr, &quot;main&quot;, &quot;cs_5_0&quot;, compileFlags, 0, &amp;amp;computeShader_m, &amp;amp;error_ptr));&#xA;&#xA;if (error_ptr)&#xA;{&#xA;    OutputDebugStringA((char *)error_ptr-&amp;gt;GetBufferPointer());&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there somthing amiss?&lt;/p&gt;&#xA;" OwnerUserId="6349" LastEditorUserId="231" LastEditDate="2017-04-12T07:06:51.280" LastActivityDate="2017-04-12T07:06:51.280" Title="Invoking shader in DX" Tags="&lt;directx&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="4992" PostTypeId="2" ParentId="4970" CreationDate="2017-04-12T14:33:20.173" Score="6" Body="&lt;p&gt;$E_n$ is illuminance (or irradiance), $L_i$ is luminance (or radiance) in direction $\omega_i$ and $d\omega$ is differential solid angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: $d\omega_i$ is the area of a pixel in the cubemap projected onto the unit sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then a longer explanation (:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solid angle is essentially the projected area of an object on a unit sphere and has unit of steradians (sr). Entire unit sphere has surface area of $4\pi$ and hemisphere has the area of $2\pi$, which comes up a lot in lighting calculations due to integrals over spheres and hemispheres respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you would want to calculate solid angle for an object and point $p$, you would project the object on the unit sphere at $p$ and calculate the area of the projection. Further the object is from $p$ smaller the solid angle gets. As an example, we can calculate solid angle for Sun as seen from the Earth. We know that Sun has about 0.52 degrees &lt;a href=&quot;https://er.jsc.nasa.gov/seh/math30.html&quot; rel=&quot;noreferrer&quot;&gt;subtended angle&lt;/a&gt; from Earth, so we can calculate that the solid angle is:&#xA;$$2\pi*(1-Cos(0.52/2))\simeq0.00006469sr$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the differential solid angle is just an infinitesimally small solid angle. If you would numerically integrate over a sphere ($4\pi$ steradians) by taking $N$ uniform samples on the sphere, your $d\omega$ would be $4\pi/N$. With integrals $N$ goes to infinity, while with numerical approximation of the integral $N$ is some &quot;sufficiently large&quot; number.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in this paper you refer to they perform integration by rendering to a cubemap at $p$ and then iterating through all the rendered pixels. But because these pixels are rendered onto planes (cubemap faces), their projection on the unit sphere isn't constant, so $d\omega$ needs to be weighted by the position in the rendered image, which they explain in your second quote:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Computing the solid angle dωi subtended by a particular texel is a&#xA;  little more involved. Texels near the center of the texture subtend a&#xA;  somewhat larger angle, while texels near the corner take up a smaller&#xA;  solid angle when we map the cube texture onto a sphere.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-04-12T14:33:20.173" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4993" PostTypeId="2" ParentId="4979" CreationDate="2017-04-12T17:08:08.050" Score="11" Body="&lt;p&gt;If you have a 1D function $f(x)$ and you want to integrate this function from say 0 to 1, one way to perform this integration is by taking N random samples in range [0, 1], evaluate $f(x)$ for each sample and calculate the average of the samples. However, this &quot;naive&quot; Monte Carlo integration is said to &quot;converge slowly&quot;, i.e. you need a large number of samples to get close to the ground truth, particularly if the function has high frequencies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With importance sampling, instead of taking N random samples in [0, 1] range, you take more samples in the &quot;important&quot; regions of $f(x)$ that contribute most to the final result. However, because you bias sampling towards the important regions of the function, these samples must be weighted less to counter the bias, which is where the PDF (probability density function) comes along. PDF tells the probability of a sample at given position and is used to calculate weighted average of the samples by dividing the each sample with the PDF value at each sample position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With Cook-Torrance importance sampling the common practice is to distribute samples based on the normal distribution function NDF. If NDF is already normalized, it can serve directly as PDF, which is convenient since it cancels the term out from the BRDF evaluation. Only thing you need to do then is to distribute sample positions based on PDF and evaluate BRDF without the NDF term, i.e.&#xA;$$f=\frac{FG}{\pi(n\cdot\omega_i)(n\cdot\omega_o)}$$&#xA;And calculate average of the sample results multiplied by the solid angle of the domain you integrate over (e.g. $2\pi$ for hemisphere).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For NDF you need to calculate &lt;a href=&quot;https://en.wikipedia.org/wiki/Cumulative_distribution_function&quot; rel=&quot;noreferrer&quot;&gt;Cumulative Distribution Function&lt;/a&gt; of the PDF to convert uniformly distributed sample position to PDF weighted sample position. For isotropic NDF this simplifies to 1D function because of the symmetry of the function. For more details about the CDF derivation you can check &lt;a href=&quot;http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html&quot; rel=&quot;noreferrer&quot;&gt;this old GPU Gems article&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-04-12T17:08:08.050" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="4994" PostTypeId="2" ParentId="4979" CreationDate="2017-04-12T22:48:41.963" Score="54" Body="&lt;h1&gt;Short answer:&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Importance sampling&lt;/strong&gt; is a method to reduce variance in Monte Carlo Integration by choosing an estimator close to the shape of the actual function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;PDF&lt;/strong&gt; is an abbreviation for &lt;a href=&quot;https://en.wikipedia.org/wiki/Probability_density_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;Probability Density Function&lt;/a&gt;. A &lt;span class=&quot;math-container&quot;&gt;$pdf(x)$&lt;/span&gt; gives the probability of a random sample generated being &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Long Answer:&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To start, let's review what Monte Carlo Integration is, and what it looks like mathematically. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Monte Carlo Integration is an technique to estimate the value of an integral. It's typically used when there isn't a closed form solution to the integral. It looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int f(x) \, dx \approx \frac{1}{N} \sum_{i=1}^N \frac{f(x_i)}{pdf(x_{i})}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In english, this says that you can approximate an integral by averaging successive random samples from the function. As &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; gets large, the approximation gets closer and closer to the solution. &lt;span class=&quot;math-container&quot;&gt;$pdf(x_{i})$&lt;/span&gt; represents the probability density function of each random sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's do an example: Calculate the value of the integral &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I = \int_{0}^{2\pi} e^{-x} \sin(x) dx$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's use Monte Carlo Integration:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I \approx \frac{1}{N} \sum_{i=1}^N \frac{e^{-x} \sin(x_i)}{pdf(x_{i})}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple python program to calculate this is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import random&#xA;import math&#xA;&#xA;N = 200000&#xA;TwoPi = 2.0 * math.pi&#xA;&#xA;sum = 0.0&#xA;&#xA;for i in range(N):&#xA;    x = random.uniform(0, TwoPi)&#xA;&#xA;    fx = math.exp(-x) * math.sin(x)&#xA;    pdf = 1 / (TwoPi - 0.0)&#xA;&#xA;    sum += fx / pdf&#xA;&#xA;I = (1 / N) * sum&#xA;print(I)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If we run the program we get &lt;span class=&quot;math-container&quot;&gt;$I = 0.4986941$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using separation by parts, we can get the exact solution:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I = \frac{1}{2} (1 − e−2π) = 0.4990663$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll notice that the Monte Carlo Solution is not quite correct. This is because it is an estimate. That said, as &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; goes to infinity, the estimate should get closer and closer to the correct answer. Already at &lt;span class=&quot;math-container&quot;&gt;$N = 2000$&lt;/span&gt; some runs are almost identical to the correct answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A note about the PDF: In this simple example, we always take a uniform random sample. A uniform random sample means every sample has the exact same probability of being chosen. We sample in the range &lt;span class=&quot;math-container&quot;&gt;$[0, 2\pi]$&lt;/span&gt; so, &lt;span class=&quot;math-container&quot;&gt;$pdf(x) = 1 / (2\pi - 0)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Importance sampling works by &lt;em&gt;not&lt;/em&gt; uniformly sampling. Instead we try to choose more samples that contribute a lot to the result (important), and less samples that only contribute a little to the result (less important). Hence the name, importance sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you choose a sampling function whose pdf very closely matches the shape of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;, you can greatly reduce the variance, which means you can take less samples. However, if you choose a sampling function whose value is very different from &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;, you can &lt;strong&gt;&lt;em&gt;increase&lt;/em&gt;&lt;/strong&gt; the variance. See the picture below:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XGyXh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XGyXh.png&quot; alt=&quot;Comparison of good sampling vs bad sampling&quot;&gt;&lt;/a&gt;&#xA;Image from Wojciech Jarosz's &lt;a href=&quot;https://www.cs.dartmouth.edu/~wjarosz/publications/dissertation/appendixA.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dissertation Appendix A&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One example of importance sampling in Path Tracing is how to choose the direction of a ray after it hits a surface. If the surface is not perfectly specular (ie. a mirror or glass), the outgoing ray can be anywhere in the hemisphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6crnH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6crnH.png&quot; alt=&quot;Outgoing rays can go anywhere in the hemisphere&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We &lt;strong&gt;&lt;em&gt;could&lt;/em&gt;&lt;/strong&gt; uniformly sample the hemisphere to generate the new ray. However, we can exploit the fact that the rendering equation has a cosine factor in it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L_{\text{o}}(p, \omega_{\text{o}}) =  L_{e}(p, \omega_{\text{o}}) + \int_{\Omega} f(p, \omega_{\text{i}}, \omega_{\text{o}}) L_{\text{i}}(p, \omega_{\text{i}}) \left | \cos \theta_{\text{i}} \right | d\omega_{\text{i}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically, we know that any rays at the horizon will be heavily attenuated (specifically, &lt;span class=&quot;math-container&quot;&gt;$\cos(x)$&lt;/span&gt; ). So, rays generated near the horizon will not contribute very much to the final value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To combat this, we use importance sampling. If we generate rays according to a cosine weighted hemisphere, we ensure that more rays are generated well above the horizon, and less near the horizon. This will lower variance and reduce noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case, you specified that you will be using a Cook-Torrance, microfacet-based BRDF. The common form being:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$f(p, \omega_{\text{i}}, \omega_{\text{o}}) = \frac{F(\omega_{\text{i}}, h) G(\omega_{\text{i}}, \omega_{\text{o}}, h) D(h)}{4 \cos(\theta_{i}) \cos(\theta_{o})}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$F(\omega_{\text{i}}, h) = \text{Fresnel function} \\&#xA;G(\omega_{\text{i}}, \omega_{\text{o}}, h) = \text{Geometry Masking and Shadowing function} \\&#xA;D(h) = \text{Normal Distribution Function}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The blog &quot;A Graphic's Guy's Note&quot; has an excellent write up on how to sample Cook-Torrance BRDFs. I will refer you to &lt;a href=&quot;https://agraphicsguy.wordpress.com/2015/11/01/sampling-microfacet-brdf/&quot; rel=&quot;nofollow noreferrer&quot;&gt;his blog post&lt;/a&gt;. That said, I will try to create a brief overview below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The NDF is generally the dominant portion of the Cook-Torrance BRDF, so if we are going to importance sample, the we should sample based on the NDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cook-Torrance doesn't specify a specific NDF to use; we are free to choose whichever one suits our fancy. That said, there are a few popular NDFs:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;GGX&lt;/li&gt;&#xA;&lt;li&gt;Beckmann&lt;/li&gt;&#xA;&lt;li&gt;Blinn&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Each NDF has it's own formula, thus each must be sampled differently. I am only going to show the final sampling function for each. If you would like to see how the formula is derived, see the blog post.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;GGX&lt;/strong&gt; is defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$D_{GGX}(m) = \frac{\alpha^2}{\pi((\alpha^2-1) \cos^2(\theta) + 1)^2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To sample the spherical coordinates angle &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt;, we can use the formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\theta = \arccos \left( \sqrt{\frac{\alpha^2}{\xi_1 (\alpha^2 - 1) + 1}} \right)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$\xi$&lt;/span&gt; is a uniform random variable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We assume that the NDF is isotropic, so we can sample &lt;span class=&quot;math-container&quot;&gt;$\phi$&lt;/span&gt; uniformly:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\phi = \xi_{2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Beckmann&lt;/strong&gt; is defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$D_{Beckmann}(m) = \frac{1}{\pi \alpha^2\cos^4(\theta)} e^{-\frac{\tan^2(\theta)}{\alpha^2}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which can be sampled with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\theta = \arccos \left(\sqrt{\frac{1}{1 = \alpha^2 \ln(1 - \xi_1)}} \right) \\&#xA;\phi = \xi_2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, &lt;strong&gt;Blinn&lt;/strong&gt; is defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$D_{Blinn}(m) = \frac{\alpha + 2}{2 \pi} (\cos(\theta))^{\alpha}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which can be sampled with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\theta = \arccos \left(\frac{1}{\xi_{1}^{\alpha + 1}} \right) \\&#xA;\phi = \xi_2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Putting it in Practice&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Let's look at a basic backwards path tracer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) {&#xA;    Ray ray = m_scene-&amp;gt;Camera.CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;&#xA;    // Bounce the ray around the scene&#xA;    for (uint bounces = 0; bounces &amp;lt; 10; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.geomID == RTC_INVALID_GEOMETRY_ID) {&#xA;            color += throughput * float3(0.846f, 0.933f, 0.949f);&#xA;            break;&#xA;        }&#xA;&#xA;        // We hit an object&#xA;&#xA;        // Fetch the material&#xA;        Material *material = m_scene-&amp;gt;GetMaterial(ray.geomID);&#xA;        // The object might be emissive. If so, it will have a corresponding light&#xA;        // Otherwise, GetLight will return nullptr&#xA;        Light *light = m_scene-&amp;gt;GetLight(ray.geomID);&#xA;&#xA;        // If we hit a light, add the emmisive light&#xA;        if (light != nullptr) {&#xA;            color += throughput * light-&amp;gt;Le();&#xA;        }&#xA;&#xA;        float3 normal = normalize(ray.Ng);&#xA;        float3 wo = normalize(-ray.dir);&#xA;        float3 surfacePos = ray.org + ray.dir * ray.tfar;&#xA;&#xA;        // Get the new ray direction&#xA;        // Choose the direction based on the material&#xA;        float3 wi = material-&amp;gt;Sample(wo, normal, sampler);&#xA;        float pdf = material-&amp;gt;Pdf(wi, normal);&#xA;&#xA;        // Accumulate the brdf attenuation&#xA;        throughput = throughput * material-&amp;gt;Eval(wi, wo, normal) / pdf;&#xA;&#xA;&#xA;        // Shoot a new ray&#xA;&#xA;        // Set the origin at the intersection point&#xA;        ray.org = surfacePos;&#xA;&#xA;        // Reset the other ray properties&#xA;        ray.dir = wi;&#xA;        ray.tnear = 0.001f;&#xA;        ray.tfar = embree::inf;&#xA;        ray.geomID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.primID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.instID = RTC_INVALID_GEOMETRY_ID;&#xA;        ray.mask = 0xFFFFFFFF;&#xA;        ray.time = 0.0f;&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera.FrameBuffer.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;IE. we bounce around the scene, accumulating color and light attenuation as we go. At each bounce, we have to choose a new direction for the ray. As mentioned above, we &lt;strong&gt;&lt;em&gt;could&lt;/em&gt;&lt;/strong&gt; uniformly sample the hemisphere to generate the new ray. However, the code is smarter; it importance samples the new direction based on the BRDF. (Note: This is the input direction, because we are a backwards path tracer)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Get the new ray direction&#xA;// Choose the direction based on the material&#xA;float3 wi = material-&amp;gt;Sample(wo, normal, sampler);&#xA;float pdf = material-&amp;gt;Pdf(wi, normal);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which could be implemented as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void LambertBRDF::Sample(float3 outputDirection, float3 normal, UniformSampler *sampler) {&#xA;    float rand = sampler-&amp;gt;NextFloat();&#xA;    float r = std::sqrtf(rand);&#xA;    float theta = sampler-&amp;gt;NextFloat() * 2.0f * M_PI;&#xA;&#xA;    float x = r * std::cosf(theta);&#xA;    float y = r * std::sinf(theta);&#xA;&#xA;    // Project z up to the unit hemisphere&#xA;    float z = std::sqrtf(1.0f - x * x - y * y);&#xA;&#xA;    return normalize(TransformToWorld(x, y, z, normal));&#xA;}&#xA;&#xA;float3a TransformToWorld(float x, float y, float z, float3a &amp;amp;normal) {&#xA;    // Find an axis that is not parallel to normal&#xA;    float3a majorAxis;&#xA;    if (abs(normal.x) &amp;lt; 0.57735026919f /* 1 / sqrt(3) */) {&#xA;        majorAxis = float3a(1, 0, 0);&#xA;    } else if (abs(normal.y) &amp;lt; 0.57735026919f /* 1 / sqrt(3) */) {&#xA;        majorAxis = float3a(0, 1, 0);&#xA;    } else {&#xA;        majorAxis = float3a(0, 0, 1);&#xA;    }&#xA;&#xA;    // Use majorAxis to create a coordinate system relative to world space&#xA;    float3a u = normalize(cross(normal, majorAxis));&#xA;    float3a v = cross(normal, u);&#xA;    float3a w = normal;&#xA;&#xA;&#xA;    // Transform from local coordinates to world coordinates&#xA;    return u * x +&#xA;           v * y +&#xA;           w * z;&#xA;}&#xA;&#xA;float LambertBRDF::Pdf(float3 inputDirection, float3 normal) {&#xA;    return dot(inputDirection, normal) * M_1_PI;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After we sample the inputDirection ('wi' in the code), we use that to calculate the value of the BRDF. And then we divide by the pdf as per the Monte Carlo formula:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Accumulate the brdf attenuation&#xA;throughput = throughput * material-&amp;gt;Eval(wi, wo, normal) / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;em&gt;Eval()&lt;/em&gt; is just the BRDF function itself (Lambert, Blinn-Phong, Cook-Torrance, etc.):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 LambertBRDF::Eval(float3 inputDirection, float3 outputDirection, float3 normal) const override {&#xA;    return m_albedo * M_1_PI * dot(inputDirection, normal);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2019-11-13T20:00:45.940" LastActivityDate="2019-11-13T20:00:45.940" CommentCount="13" ContentLicense="CC BY-SA 4.0" />
  <row Id="4995" PostTypeId="1" CreationDate="2017-04-13T03:43:49.593" Score="1" ViewCount="548" Body="&lt;p&gt;I am trying to implement a shape matching algorithm for vector images discussed in a paper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The input to the algorithm is a model of 2D shapes deﬁned by contour segments. According to the paper, such segments can be deﬁned as polylines, obtained for example by vectorizing the output of an edge detector like Canny.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to vectorize a tiff image using Inkscape's bitmap tracing feature. The svg image I got from it has a path node with many attribute values, but that is not what the algorithm wants:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SVWx7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SVWx7.png&quot; alt=&quot;output of canny edge detector&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/7f7RQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7f7RQ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I vectorize to polylines instead of paths?&lt;/p&gt;&#xA;" OwnerUserId="6435" LastEditorUserId="231" LastEditDate="2017-04-14T09:37:07.473" LastActivityDate="2017-04-17T06:12:54.330" Title="Vectorizing to polylines instead of paths" Tags="&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="4997" PostTypeId="1" AcceptedAnswerId="5001" CreationDate="2017-04-14T11:36:59.443" Score="6" ViewCount="3295" Body="&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://graphics.stanford.edu/papers/envmap/envmap.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;envmap.pdf | An Efficient Representation for Irradiance Environment Maps&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://xlgames-inc.github.io/posts/sphericalharmonics0/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Spherical Harmonics and applications in real time graphics&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I am using Spherical Harmonics to turn reflective(mirror like) cube map to diffuse light cube map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I understand for an image, I calculate 9 coefficient(for red green blue) that describes the color of the cube map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The nine coefficients are this...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kmjyY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kmjyY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And when you visualize them they become...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oRvEP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oRvEP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I do something with these coefficients to get color of the cube map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The part that I am not understanding is using an image to get that 9 coefficients. All the papers kinda assume that you somehow got that coefficient calculated because it is &quot;easy&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know how to do that calculation.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Update&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So while I were looking at &lt;a href=&quot;http://simonstechblog.blogspot.com/2011/12/spherical-harmonic-lighting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Spherical Harmonic Lighting | Simon's Tech Blog&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found this equation...&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ViYx1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ViYx1.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now I know that the mysterious yellow part of the equation was &quot;solid angle related&quot;. I do know how to do solid angle but I still don't understand how to do it.&lt;/p&gt;&#xA;" OwnerUserId="6282" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:55:52.017" LastActivityDate="2018-03-04T19:55:52.017" Title="Spherical Harmonics Diffuse CubeMap. How to get coefficients?" Tags="&lt;spherical-harmonics&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4998" PostTypeId="2" ParentId="4997" CreationDate="2017-04-14T12:47:58.287" Score="1" Body="&lt;p&gt;To start I'll assume you have a list of (x,y,z) points each with a r, g, b color that are the samples you want to approximate with the spherical harmonics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get the coefficients you make a matrix n x 9 $A$ where each row is the sequence $y_0(x,y,z), y_1^{-1}(x,y,z), y_1^{0}(x,y,z), y_1^{1}(x,y,z), y_2^{-2}(x,y,z), y_2^{-1}(x,y,z), y_2^{0}(x,y,z), y_2^{1}(x,y,z), y_2^{2}(x,y,z)$ of a point and also a n x 3 matrix $b$ with each corresponding row the color at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you take a 9x3 matrix $x$ of the unknown coefficients (9 for each color). Then $Ax=b$ is the equation to solve. This equation will be overdetermined so you'll need to approximate the solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means doing a &lt;a href=&quot;https://en.wikipedia.org/wiki/Linear_regression&quot; rel=&quot;nofollow noreferrer&quot;&gt;linear regression&lt;/a&gt; to find the coefficients that give the smallest error. This is well described in linear algebra.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2017-04-15T09:40:58.400" LastActivityDate="2017-04-15T09:40:58.400" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="4999" PostTypeId="1" CreationDate="2017-04-14T16:03:10.307" Score="3" ViewCount="90" Body="&lt;p&gt;In &lt;a href=&quot;https://stackoverflow.com/questions/43163337/parallelize-chain-of-gaussian-blurs&quot;&gt;this&lt;/a&gt; question I asked how to implement a chain of blurs in one single step. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I found out from the &lt;a href=&quot;https://en.wikipedia.org/wiki/Gaussian_blur&quot; rel=&quot;nofollow noreferrer&quot;&gt;gaussian blur&lt;/a&gt; page of Wikipedia that:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Applying multiple, successive gaussian blurs to an image has the same&#xA;  effect as applying a single, larger gaussian blur, whose radius is the&#xA;  square root of the sum of the squares of the blur radii that were&#xA;  actually applied. For example, applying successive gaussian blurs with&#xA;  radii of 6 and 8 gives the same results as applying a single gaussian&#xA;  blur of radius 10, since sqrt {6^{2}+8^{2}}=10.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So I thought that &lt;code&gt;blur&lt;/code&gt; and &lt;code&gt;singleBlur&lt;/code&gt; were the same in the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;cv::Mat firstLevel;&#xA;float sigma1, sigma2;&#xA;//intialize firstLevel, sigma1 and sigma2&#xA;cv::Mat blur = gaussianBlur(firstLevel, sigma1);&#xA;        blur = gaussianBlur(blur, sigma2);&#xA;float singleSigma = std::sqrt(std::pow(sigma1,2)+std::pow(sigma2,2));&#xA;cv::Mat singleBlur = gaussianBlur(firstLevel, singleSigma);&#xA;cv::Mat diff = blur != singleBLur;&#xA;// Equal if no elements disagree&#xA;assert( cv::countNonZero(diff) == 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this &lt;code&gt;assert&lt;/code&gt; fails (and actually, for example, the first row of &lt;code&gt;blur&lt;/code&gt; is different from the first one of &lt;code&gt;singleBlur&lt;/code&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After different comments asking for more information, I'll update the answer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'm trying to do is to parallelize &lt;a href=&quot;https://github.com/perdoch/hesaff&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; code. In particular, I'm focusing now on computing all the blurs at all levels in advance. The serial code (&lt;strong&gt;which works correctly&lt;/strong&gt;) is the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   vector&amp;lt;Mat&amp;gt; blurs ((par.numberOfScales+3)*levels, Mat());&#xA;   cv::Mat octaveLayer = firstLevel;&#xA;   int scaleCycles = par.numberOfScales+2;&#xA;&#xA;   //compute blurs at all layers (not parallelizable)&#xA;   for(int i=0; i&amp;lt;levels; i++){&#xA;       blurs[i*scaleCycles+1] = octaveLayer.clone();&#xA;       for (int j = 1; j &amp;lt; scaleCycles; j++){&#xA;           float sigma = par.sigmas[j]* sqrt(sigmaStep * sigmaStep - 1.0f);&#xA;           blurs[j+1+i*scaleCycles] = gaussianBlur(blurs[j+i*scaleCycles], sigma);&#xA;           if(j == par.numberOfScales)&#xA;               octaveLayer = halfImage(blurs[j+1+i*scaleCycles]);&#xA;       }&#xA;   }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm sorry for the horrible indexes above, but I tried to respect the original code system (which is horrible, like starting counting from &lt;code&gt;1&lt;/code&gt; instead of &lt;code&gt;0&lt;/code&gt;). The code above has &lt;code&gt;scaleCycles=5&lt;/code&gt; and &lt;code&gt;levels=6&lt;/code&gt;, so 30 blurs are generated in total.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the &quot;single blur&quot; version, where first I compute the sigmas for each blur that has to be computed (following Wikipedia's formula) and then I apply the blur (notice that this is still serial and not parallelizable):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   vector&amp;lt;Mat&amp;gt; singleBlurs ((par.numberOfScales+3)*levels, Mat());&#xA;   vector&amp;lt;float&amp;gt; singleSigmas(scaleCycles);&#xA;   float acc = 0;&#xA;   for (int j = 1; j &amp;lt; scaleCycles; j++){&#xA;       float sigma = par.sigmas[j]* sqrt(sigmaStep * sigmaStep - 1.0f);&#xA;       acc += pow(sigma, 2);&#xA;       singleSigmas[j] = sqrt(acc);&#xA;   }&#xA;&#xA;   octaveLayer = firstLevel;&#xA;   for(int i=0; i&amp;lt;levels; i++){&#xA;       singleBlurs[i*scaleCycles+1] = octaveLayer.clone();&#xA;       for (int j = 1; j &amp;lt; scaleCycles; j++){&#xA;           float sigma = singleSigmas[j];&#xA;           std::cout&amp;lt;&amp;lt;&quot;j=&quot;&amp;lt;&amp;lt;j&amp;lt;&amp;lt;&quot; sigma=&quot;&amp;lt;&amp;lt;sigma&amp;lt;&amp;lt;std::endl;&#xA;           singleBlurs[j+1+i*scaleCycles] = gaussianBlur(singleBlurs[j+i*scaleCycles], sigma);&#xA;           if(j == par.numberOfScales)&#xA;               octaveLayer = halfImage(singleBlurs[j+1+i*scaleCycles]);&#xA;       }&#xA;   }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Of course the code above generates 30 blurs also with the same parameters of the previous version.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then this is the code to see the difference between each &lt;code&gt;signgleBlurs&lt;/code&gt; and &lt;code&gt;blurs&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   assert(blurs.size() == singleBlurs.size());&#xA;   vector&amp;lt;Mat&amp;gt; blurDiffs(blurs.size());&#xA;   for(int i=1; i&amp;lt;levels*scaleCycles; i++){&#xA;        cv::Mat diff;&#xA;        absdiff(blurs[i], singleBlurs[i], diff);&#xA;        std::cout&amp;lt;&amp;lt;&quot;i=&quot;&amp;lt;&amp;lt;i&amp;lt;&amp;lt;&quot;diff rows=&quot;&amp;lt;&amp;lt;diff.rows&amp;lt;&amp;lt;&quot; cols=&quot;&amp;lt;&amp;lt;diff.cols&amp;lt;&amp;lt;std::endl;&#xA;        blurDiffs[i] = diff;&#xA;        std::cout&amp;lt;&amp;lt;&quot;blurs rows=&quot;&amp;lt;&amp;lt;blurs[i].rows&amp;lt;&amp;lt;&quot; cols=&quot;&amp;lt;&amp;lt;blurs[i].cols&amp;lt;&amp;lt;std::endl;&#xA;        std::cout&amp;lt;&amp;lt;&quot;singleBlurs rows=&quot;&amp;lt;&amp;lt;singleBlurs[i].rows&amp;lt;&amp;lt;&quot; cols=&quot;&amp;lt;&amp;lt;singleBlurs[i].cols&amp;lt;&amp;lt;std::endl;&#xA;        std::cout&amp;lt;&amp;lt;&quot;blurDiffs rows=&quot;&amp;lt;&amp;lt;blurDiffs[i].rows&amp;lt;&amp;lt;&quot; cols=&quot;&amp;lt;&amp;lt;blurDiffs[i].cols&amp;lt;&amp;lt;std::endl;&#xA;        namedWindow( &quot;blueDiffs[&quot;+std::to_string(i)+&quot;]&quot;, WINDOW_AUTOSIZE );// Create a window for display.&#xA;        //imshow( &quot;blueDiffs[&quot;+std::to_string(i)+&quot;]&quot;, blurDiffs[i] );                   // Show our image inside it.&#xA;        //waitKey(0);                                          // Wait for a keystroke in the window&#xA;        Mat imageF_8UC3;&#xA;        std::cout&amp;lt;&amp;lt;&quot;converting...&quot;&amp;lt;&amp;lt;std::endl;&#xA;        blurDiffs[i].convertTo(imageF_8UC3, CV_8U, 255);&#xA;        std::cout&amp;lt;&amp;lt;&quot;converted&quot;&amp;lt;&amp;lt;std::endl;&#xA;        imwrite( &quot;blurDiffs_&quot;+std::to_string(i)+&quot;.jpg&quot;, imageF_8UC3);&#xA;   }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now, what I've seen is that &lt;code&gt;blurDiffs_1.jpg&lt;/code&gt; and &lt;code&gt;blurDiffs_2.jpg&lt;/code&gt; are black, but suddendly from &lt;code&gt;blurDiffs_3.jpg&lt;/code&gt; until the &lt;code&gt;blurDiffs_29.jpg&lt;/code&gt; becomes whiter and whiter. For some reason, &lt;code&gt;blurDiffs_30.jpg&lt;/code&gt; is almost completely black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The first (correct) version generates 1761 descriptors. The second  (uncorrect) version generates &gt;2.3k descriptors.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't post the &lt;code&gt;blurDiffs&lt;/code&gt; matrices because (especially the first ones) are very big and post's space is limited. I'll post some samples. I'll not post &lt;code&gt;blurDiffs_1.jpg&lt;/code&gt; and &lt;code&gt;blurDiffs_2.jpg&lt;/code&gt; because they're totally blacks. Notice that because of &lt;code&gt;halfImage&lt;/code&gt; the images become smaller and smaller (as expected).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;blurDiffs_3.jpg:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/e0xLz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e0xLz.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;blurDiffs_6.jpg:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/58ciq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/58ciq.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;blurDiffs_15.jpg:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yv8kd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yv8kd.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;blurDiffs_29.jpg:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EeoDd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EeoDd.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;If you need any more details, please let me know&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6454" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-04-15T11:04:39.243" Title="Replace a chain of image blurs with one blur" Tags="&lt;gaussian-blur&gt;&lt;blur&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5001" PostTypeId="2" ParentId="4997" CreationDate="2017-04-15T11:40:06.890" Score="3" Body="&lt;p&gt;So at start you have samples from your cube map. Each sample has color and normal (dir) at which you sampled that color.&#xA;This is how I do it. I use coeffs from this &lt;a href=&quot;https://graphics.stanford.edu/papers/envmap/envmap.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; (the same you linked), there are values for the first 9 of them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;So for constructing for each sample you:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Compute your SH basis using normal from sample&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Y00     = 0.282095;&#xA;float Y11     = 0.488603 * normal.x;&#xA;float Y10     = 0.488603 * normal.z;&#xA;float Y1_1    = 0.488603 * normal.y;&#xA;float Y21     = 1.092548 * normal.x*normal.z;&#xA;float Y2_1    = 1.092548 * normal.y*normal.z;&#xA;float Y2_2    = 1.092548 * normal.y*normal.x;&#xA;float Y20     = 0.946176 * normal.z * normal.z - 0.315392;&#xA;float Y22     = 0.546274 * (normal.x*normal.x - normal.y*normal.y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Then multiply these coeffs by your color (L)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 L00   = L * Y00;&#xA;vec3 L11   = L * Y11;&#xA;vec3 L10   = L * Y10;&#xA;vec3 L1_1  = L * Y1_1;&#xA;vec3 L21   = L * Y21;&#xA;vec3 L2_1  = L * Y2_1;&#xA;vec3 L2_2  = L * Y2_2;&#xA;vec3 L20   = L * Y20;&#xA;vec3 L22   = L * Y22;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And thats it, you have your coeffs. Now, you can store them in some data structure. You accumulate each of them like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;someArray[0] += L00;&#xA;someArray[1] += L11;&#xA;etc...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And you divide these accumulated coeffs by a number of samples;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Then when reconstructing :&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;compute your SH basis one more time for normal at point of the scene.&lt;/li&gt;&#xA;&lt;li&gt;for approximating diffuse irradiance at given point of scene,&#xA;convolution with cosine lobe is performed using normal from that point.&#xA;Convolution means, for each SH order, multiplication by $&#xA;   \hat{A}=[\pi, \frac{2}{3}\pi, \frac{\pi}{4}]$&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;$\hat{A_0} = 3.141593$, &#xA;$\hat{A_1} = 2.094395$, &#xA;$\hat{A_2} = 0.785398$&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;L coeffs are sampled from data structure.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 color = A0*Y00*L00  &#xA;             + A1*Y1_1*L1_1 + A1*Y10*L10 + A1*Y11*L11 &#xA;             + A2*Y2_2*L2_2 + A2*Y2_1*L2_1 + A2*Y20*L20 + A2*Y21*L21 + A2*Y22*L22;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Disclaimer:&lt;/strong&gt; This basically works (for me) but I am not an expert and something might be missing or not perfect because this &lt;strong&gt;IS&lt;/strong&gt; confusing topic...&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-04-18T09:48:56.267" LastActivityDate="2017-04-18T09:48:56.267" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5002" PostTypeId="1" CreationDate="2017-04-15T13:22:49.767" Score="2" ViewCount="188" Body="&lt;p&gt;Would it be possible to make text significantly more legible in VR? I know there are hardware limitations, but are there hanging fruit techniques that aren't being employed in 3D that are in 2D (vector based rendering, signed distance field rendering, and so forth)?&lt;/p&gt;&#xA;" OwnerUserId="5225" LastActivityDate="2017-04-15T13:22:49.767" Title="Rendering Crystal Clear 3D Text in VR" Tags="&lt;virtual-reality&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5003" PostTypeId="1" CreationDate="2017-04-16T07:15:25.497" Score="3" ViewCount="786" Body="&lt;p&gt;I made this flowchart with draw.io:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DQSOf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DQSOf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It was the first chart I made so it took me a while to make it. I need to be able to dynamically generate variations of this diagram programmatically. I wold need to do things like change the colours of the human shapes, change the text and colours of the boxes. And the trickiest part I think would be adding more children or less children. I want to make it possible to generate diagrams that can have up to 10 children.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only image programming I have ever done was with PHP GD library, I have don't even know what modern graphics experts use for programmatically generating images. I have read about vector images that are programmed, and I read a little bit about HTML5 canvas. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The javascript flowchar and diagram creation frameworks seem very complicated. If I found one with this particular type of flowchart as a template I could use it, but it would still be difficult. The most ideal scenario would be if I use a visual builder program like draw.io to build a template, and it would output the raw code that I could then convert function for generating these charts dynamically. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know how this can be done? There are actually lots of diagrams I need to be able to make programatically, like metabolic pathways:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Iv8r4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Iv8r4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What would be the best way of going about generating these kinds of diagrams programatically? The first one would become a great tool for learning about genetics if I can do this. Any insight would be much appreciated. &lt;/p&gt;&#xA;" OwnerUserId="6462" LastEditorUserId="2041" LastEditDate="2017-04-18T09:11:11.950" LastActivityDate="2017-04-18T09:11:11.950" Title="Can draw.io type flowcharts be programmed?" Tags="&lt;2d-graphics&gt;&lt;diagram&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5005" PostTypeId="2" ParentId="4995" CreationDate="2017-04-17T06:12:54.330" Score="1" Body="&lt;p&gt;If you look at &lt;a href=&quot;https://www.w3.org/TR/SVG/paths.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;chapter 8&lt;/a&gt; of the &lt;a href=&quot;https://www.w3.org/TR/SVG/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SVG Specification&lt;/a&gt;, it describes how to parse a &lt;code&gt;path&lt;/code&gt; element. The short version is that you'll want to find the &lt;code&gt;d&lt;/code&gt; attribute of the element. That element should be a string describing the curve. It will contain the following commands:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;m&lt;/code&gt; - Moveto command&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;l&lt;/code&gt; - Lineto command&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;c&lt;/code&gt;, &lt;code&gt;s&lt;/code&gt;, &lt;code&gt;q&lt;/code&gt;, &amp;amp; &lt;code&gt;a&lt;/code&gt; - Curve commands&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;z&lt;/code&gt; - close path&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Simple lines will just be combinations of &lt;code&gt;m&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt; sequences. The curves will be either circular arcs, quadratic bezier or cubic beziers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To convert a Bezier curve into line segments, you can do the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const float kNumPolyLines = 10; // &amp;lt;- change this to make more lines per bezier segment&#xA;const float kDeltaT = 1.0 / kNumPolyLines;&#xA;Point c0;&#xA;Point c1;&#xA;Point c2;&#xA;Point c3;&#xA;GetBezierControlPoints(&amp;amp;c0, &amp;amp;c1, &amp;amp;c2, &amp;amp;c3); // &amp;lt;- get the 3 or 4 control points for the next bezier segment&#xA;Point prevPoint = c0;&#xA;Point currentPoint;&#xA;for (float t = kDeltaT; t &amp;lt;= 1.0; t += kDeltaT)&#xA;{&#xA;    currentPoint = CalculateBezier(c0, c1, c2, c3, t);&#xA;&#xA;    // Now you have the next line segment in your poly line. &#xA;    // It goes from prevPoint to currentPoint. Store it or draw it, &#xA;    //or whatever you need&#xA;&#xA;    // Get ready for the next iteration&#xA;    prevPoint = currentPoint;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can find the formula for both quadratic and cubic bezier curves &lt;a href=&quot;https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Specific_cases&quot; rel=&quot;nofollow noreferrer&quot;&gt;on Wikipedia&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-04-17T06:12:54.330" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="5006" PostTypeId="1" AcceptedAnswerId="5009" CreationDate="2017-04-18T05:51:03.983" Score="5" ViewCount="4444" Body="&lt;p&gt;Given a triangle and a point inside the triangle in Cartesian coordinate system, I compute the Barycentric coordinate of the point like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double v2_1[3], v2_3[3], v2_t[3];&#xA;&#xA;double bary[3];&#xA;vtkMath::Subtract(p1, p2, v2_1);&#xA;vtkMath::Subtract(p3, p2, v2_3);&#xA;vtkMath::Subtract(t, p2, v2_t);&#xA;&#xA;float d00 = vtkMath::Dot(v2_1, v2_1);&#xA;float d01 = vtkMath::Dot(v2_1, v2_3);&#xA;float d11 = vtkMath::Dot(v2_3, v2_3);&#xA;float denom = d00 * d11 - d01 * d01;&#xA;&#xA;float d20 = vtkMath::Dot(v2_t, v2_1);&#xA;float d21 = vtkMath::Dot(v2_t, v2_3);&#xA;bary[0] = (d11 * d20 - d01 * d21) / denom;&#xA;bary[1] = (d00 * d21 - d01 * d20) / denom;&#xA;bary[2] = 1.0f - bary[0] - bary[1];&#xA;&#xA;return bary;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now, how can I use the values in &lt;code&gt;bary&lt;/code&gt; to interpolate the vertex normal at &lt;code&gt;p1&lt;/code&gt;, &lt;code&gt;p2&lt;/code&gt; and &lt;code&gt;p3&lt;/code&gt;? Specifically, I'm confused which coefficient belongs to which vertex.&lt;/p&gt;&#xA;" OwnerUserId="2687" LastEditorUserId="2687" LastEditDate="2017-04-20T06:31:26.373" LastActivityDate="2017-04-20T06:31:26.373" Title="How do I use barycentric coordinates to interpolate vertex normal?" Tags="&lt;interpolation&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5007" PostTypeId="2" ParentId="5006" CreationDate="2017-04-19T02:08:11.633" Score="2" Body="&lt;p&gt;You can find which coefficient belongs to which vertex empirically by changing &lt;code&gt;t&lt;/code&gt; to be one of the points on the triangle (&lt;code&gt;p1, p2, p3&lt;/code&gt;). Then one of the coefficients will be &lt;code&gt;1&lt;/code&gt; and others are &lt;code&gt;0&lt;/code&gt;. Based on that you know which coefficient belongs to which vertex. Then, interpolating the normal is trivial:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;interpolatedNormal = bary[0] * p1_normal + bary[2] * p2_normal + bary[1] * p3_normal;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But I'm still curious the mathematical explanation behind this.&lt;/p&gt;&#xA;" OwnerUserId="2687" LastActivityDate="2017-04-19T02:08:11.633" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5009" PostTypeId="2" ParentId="5006" CreationDate="2017-04-19T14:56:08.043" Score="5" Body="&lt;p&gt;Thats the way your defining the vectors. See your defining vectors $V_1$ and $V_2$ as pointing outwards from the point $P_2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DhmzX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DhmzX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now then $denom$ is the square of the area of the parallelogram of formed by completing the triangle with a duplicate of itself. Another way to look at this is that its the 2 tines the square of the are of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/C7Rsq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/C7Rsq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now then the calculation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(d11 * d20 - d01 * d21)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is the square area of the parallelogram of $P_2$-$T$-$P_3$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ErNBM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ErNBM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you divide this with denom, then you have calculated the total area relative area of triangle $P_2$-$T$-$P_3$. So the formula &lt;code&gt;(d11 * d20 - d01 * d21) / denom&lt;/code&gt; is the triangle size in relation to whole triangle size of: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/napil.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/napil.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the weight that the opposing corner exerts on the point. which in other words it is the barycenter weight related to point $P_1$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next line is simply the relative area of triangle $P_2$-$T$-$P_1$ or:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YYu3U.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YYu3U.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is opposite to $P_3$ being the barycentric coordinate of $P_3$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly you calculate the rest which is the remaining triangle which is opposite of $P_2$ using &lt;code&gt;1 - bary[0] - bary[1]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You could have chosen the first vectors differently for a different order.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="2687" LastEditDate="2017-04-20T05:27:32.077" LastActivityDate="2017-04-20T05:27:32.077" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5010" PostTypeId="1" CreationDate="2017-04-19T17:52:59.037" Score="1" ViewCount="155" Body="&lt;p&gt;I have huge point cloud data I want to render them at interactive frame frate. Process I know is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1.point cloud data &lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.triangulate it using delnauy or other triangulation algo&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3.surface voxelization for mesh&lt;/p&gt;&#xA;&#xA;&lt;p&gt;4.volume tracing ti render&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But triangulation process is very very slow. Can I somehow voxelize my point cloud directly?&#xA;I am newbie to voxelization.&lt;/p&gt;&#xA;" OwnerUserId="6475" LastEditorUserId="6546" LastEditDate="2017-05-02T08:28:09.843" LastActivityDate="2017-05-02T09:38:24.710" Title="Can I voxelize 3D set of points without reconstructing surface first?" Tags="&lt;rendering&gt;&lt;performance&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5012" PostTypeId="1" AcceptedAnswerId="5025" CreationDate="2017-04-20T04:53:53.727" Score="1" ViewCount="1401" Body="&lt;p&gt;I am pretty new to the dx12 world. As a sample project I am trying to add 2 buffers and store the output in yet another output buffer. As apart of this debugging I am trying to see if the buffers that I am loading actually have the right values. &#xA;Thus, once the buffer is loaded, I want to put in a fence and &quot;read back the data uploaded&quot; into the CPU and print out the contents of the buffer. &#xA;After a lot of googling I thought i should use the map function in DXD12. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I am not entirely sure how I should go about doing this. Any thoughts?&lt;/p&gt;&#xA;" OwnerUserId="6349" LastEditorUserId="6349" LastEditDate="2017-04-20T05:17:42.067" LastActivityDate="2017-04-25T22:42:55.887" Title="Readback Data through Buffers" Tags="&lt;directx12&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="5013" PostTypeId="2" ParentId="4370" CreationDate="2017-04-20T05:46:49.803" Score="2" Body="&lt;p&gt;There is algorithm called as delaunay triangulation which does triangulation or points it's comparably simple to understand . But it is very slow. If you don't want to implement your own algorithm from scratch please have look at pcl &#xA;&lt;a href=&quot;http://pointclouds.org/documentation/tutorials/greedy_projection.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://pointclouds.org/documentation/tutorials/greedy_projection.php&lt;/a&gt;&#xA;Also have look at CGAL&#xA;&lt;a href=&quot;http://www.cgal.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.cgal.org&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6475" LastActivityDate="2017-04-20T05:46:49.803" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5014" PostTypeId="1" AcceptedAnswerId="5015" CreationDate="2017-04-20T05:56:56.747" Score="4" ViewCount="1864" Body="&lt;p&gt;What are the recommended ways to render caustics? I am aware bidirectional path tracing and photon mapping can do this. Could someone give a brief overview of photon mapping and a good resource of where to learn about implementation? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-04-20T16:46:43.533" Title="Caustics: methods to render?" Tags="&lt;pathtracing&gt;&lt;photon-mapping&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5015" PostTypeId="2" ParentId="5014" CreationDate="2017-04-20T08:49:32.683" Score="7" Body="&lt;p&gt;First of all, you can get caustics just by Path Tracing. Caustics isn't a difficult phenomenon in computer graphics. Almost any global illumination algorithm can render it. It's just a matter of the converging speed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While (naive) Path Tracing can render caustics, it takes a long time to clean the rendered image due to how the algorithm works. Photon Mapping makes the converging speed faster by doing some tricks on how light paths are interpolated. Bi-Directional Path Tracing on the other hand tries to make some difficult-to-sample light paths easier.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Besides the two algorithms, Metropolis Light Transport can render caustics efficiently by finding the most significant light path in the scene and exploring other possibilities around it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some good lectures on:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=pjc1QAI6zS0&amp;amp;list=PLujxSBD-JXgnGmsn7gEyN28P1DnRZG7qi&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray based rendering algorithms&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=cDi-uti2oLQ&amp;amp;list=PLujxSBD-JXgnGmsn7gEyN28P1DnRZG7qi&amp;amp;index=29&quot; rel=&quot;nofollow noreferrer&quot;&gt;Path Tracing&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=-1C2kL5pTbs&amp;amp;list=PLujxSBD-JXgnGmsn7gEyN28P1DnRZG7qi&amp;amp;index=34&quot; rel=&quot;nofollow noreferrer&quot;&gt;Photon Mapping&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There is the &lt;a href=&quot;https://graphics.stanford.edu/courses/cs348b-03/papers/veach-chapter10.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;original paper of BDPT&lt;/a&gt;. It's not too difficult if you can implement explicit light sampling and multiple importance sampling by your self.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I recommend the book Physically Based Rendering: From Theory to Implementation. It talks about all the algorithms above and more. It is basically a must have if you want to dive deep into computer graphics.&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="231" LastEditDate="2017-04-20T16:46:43.533" LastActivityDate="2017-04-20T16:46:43.533" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5016" PostTypeId="1" CreationDate="2017-04-20T10:54:02.307" Score="1" ViewCount="559" Body="&lt;p&gt;I have to add a spotlight to my rotating cube so this is my code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;HTML&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        &amp;lt;!DOCTYPE html&amp;gt;&#xA;&amp;lt;html&amp;gt;&#xA;&#xA;&amp;lt;button id = &quot;ButtonX&quot;&amp;gt;Rotate X&amp;lt;/button&amp;gt;&#xA;&amp;lt;button id = &quot;ButtonY&quot;&amp;gt;Rotate Y&amp;lt;/button&amp;gt;&#xA;&amp;lt;button id = &quot;ButtonZ&quot;&amp;gt;Rotate Z&amp;lt;/button&amp;gt;&#xA;&amp;lt;button id = &quot;ButtonT&quot;&amp;gt;Toggle Rotation&amp;lt;/button&amp;gt;&#xA;&#xA;&#xA;&amp;lt;script id=&quot;vertex-shader&quot; type=&quot;x-shader/x-vertex&quot;&amp;gt;&#xA;&#xA;attribute  vec4 vPosition;&#xA;attribute  vec4 vColor;&#xA;attribute  vec2 vTexCoord;&#xA;attribute  vec3 vNormal;&#xA;&#xA;uniform float shininess;&#xA;&#xA;uniform vec4 posLightPosition;&#xA;uniform vec4 posAmbientProduct, posDiffuseProduct,      posSpecularProduct;&#xA;&#xA;uniform vec4 dirLightPosition;&#xA;uniform vec4 dirAmbientProduct, dirDiffuseProduct,      dirSpecularProduct;&#xA;&#xA;uniform vec4 spotLightPosition;&#xA;uniform vec4 spotAmbientProduct, spotDiffuseProduct,spotSpecularProduct;&#xA;uniform vec4 spotLightDirection;&#xA;uniform float lCutOff;&#xA;&#xA;&#xA;&#xA;varying vec4 fColor;&#xA;varying vec2 fTexCoord;&#xA;&#xA;uniform vec3 theta;&#xA;&#xA;void main()&#xA;{&#xA;    // Compute the sines and cosines of theta for each of&#xA;    //   the three axes in one computation.&#xA;    vec3 angles = radians( theta );&#xA;    vec3 c = cos( angles );&#xA;    vec3 s = sin( angles );&#xA;&#xA;    // Remeber: thse matrices are column-major&#xA;    mat4 rx = mat4( 1.0,  0.0,  0.0, 0.0,&#xA;            0.0,  c.x,  s.x, 0.0,&#xA;            0.0, -s.x,  c.x, 0.0,&#xA;            0.0,  0.0,  0.0, 1.0 );&#xA;&#xA;    mat4 ry = mat4( c.y, 0.0, -s.y, 0.0,&#xA;            0.0, 1.0,  0.0, 0.0,&#xA;            s.y, 0.0,  c.y, 0.0,&#xA;            0.0, 0.0,  0.0, 1.0 );&#xA;&#xA;&#xA;    mat4 rz = mat4( c.z, s.z, 0.0, 0.0,&#xA;            -s.z,  c.z, 0.0, 0.0,&#xA;            0.0,  0.0, 1.0, 0.0,&#xA;            0.0,  0.0, 0.0, 1.0 );&#xA;&#xA;    vec3 N=normalize((rz*ry*rx*vNormal).xyz);&#xA;&#xA;    // positional light&#xA;    vec3 pos=-(rz*ry*rx*vPosition).xyz;&#xA;    vec3 posLight=posLightPosition.xyz;&#xA;    vec3 posL=normalize(posLight-pos);&#xA;    vec3 posE=normalize(-pos);&#xA;    vec3 posH=normalize(posL+posE);&#xA;    vec4 posAmbient=posAmbientProduct;&#xA;    float posKd=max(dot(posL,N),0.0);&#xA;    vec4 posDiffuse=posKd*posDiffuseProduct;&#xA;    float posKs=pow(max(dot(N,posH),0.0), shininess);&#xA;    vec4 posSpecular=posKs*posSpecularProduct;&#xA;    if(dot(posL,N)&amp;lt;0.0){&#xA;    posSpecular=vec4(0.0,0.0,0.0,1.0);&#xA;    }&#xA;&#xA;    // directional light&#xA;    vec3 dirLight=dirLightPosition.xyz;&#xA;    vec3 dirL=normalize(dirLight);&#xA;    vec3 dirE=normalize(-pos);&#xA;    vec3 dirH=normalize(dirL+dirE);&#xA;    vec4 dirAmbient=dirAmbientProduct;&#xA;    float dirKd=max(dot(dirL,N),0.0);&#xA;    vec4 dirDiffuse=dirKd*dirDiffuseProduct;&#xA;    float dirKs=pow(max(dot(N,dirH),0.0), shininess);&#xA;    vec4 dirSpecular=dirKs*dirSpecularProduct;&#xA;    if(dot(dirL,N)&amp;lt;0.0){&#xA;    dirSpecular=vec4(0.0,0.0,0.0,1.0);&#xA;    }&#xA;&#xA;&#xA;    //spotlight&#xA;    vec3 spotLight=spotLightPosition.xyz;&#xA;    vec3 spotL=normalize(spotLight);&#xA;    vec3 spotE=normalize(-pos);&#xA;    vec3 spotH=normalize(spotL+spotE);&#xA;    vec3 spotD=spotLightDirection.xyz;&#xA;    vec4 spotAmbient=spotAmbientProduct;&#xA;    float spotKd=max(dot(spotL,N),0.0);&#xA;    vec4 spotDiffuse=spotKd*spotDiffuseProduct;&#xA;    float spotKs=pow(max(dot(N,spotH),0.0), shininess);&#xA;    vec4 spotSpecular=spotKs*spotSpecularProduct;&#xA;    if(dot(spotL,N)&amp;lt;0.0){&#xA;    spotSpecular=vec4(0.0,0.0,0.0,1.0);&#xA;    }&#xA;    float lEffect= dot(normalize(spotD), -spotH);&#xA;    if(lEffect&amp;gt;lCutOff)&#xA;    {&#xA;    vec4 ambient=posAmbient+dirAmbient+spotAmbient;&#xA;    vec4 diffuse=posDiffuse+dirDiffuse+spotDiffuse;&#xA;    vec4 specular=posSpecular+dirSpecular+spotSpecular;&#xA;&#xA;&#xA;    fColor = ambient+vColor*(diffuse+specular);&#xA;    fColor.a = 1.0;&#xA;    }&#xA;    else{&#xA;    vec4 ambient=posAmbient+dirAmbient;&#xA;    vec4 diffuse=posDiffuse+dirDiffuse;&#xA;    vec4 specular=posSpecular+dirSpecular;&#xA;&#xA;&#xA;    fColor = ambient+vColor*(diffuse+specular);&#xA;    fColor.a = 1.0;&#xA;&#xA;        }&#xA;&#xA;        fTexCoord = vTexCoord;&#xA;    gl_Position = rz * ry * rx * vPosition;&#xA;    gl_Position.z = -gl_Position.z;&#xA;}&#xA;&amp;lt;/script&amp;gt;&#xA;&#xA;&amp;lt;script id=&quot;fragment-shader&quot; type=&quot;x-shader/x-fragment&quot;&amp;gt;&#xA;&#xA;precision mediump float;&#xA;&#xA;varying vec4 fColor;&#xA;varying  vec2 fTexCoord;&#xA;&#xA;uniform sampler2D Tex0;&#xA;uniform sampler2D Tex1;&#xA;&#xA;void&#xA;main()&#xA;{&#xA;    gl_FragColor = fColor*(texture2D(Tex0, fTexCoord)*texture2D(Tex1, fTexCoord));&#xA;&#xA;}&#xA;&amp;lt;/script&amp;gt;&#xA;&#xA;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;../Common/webgl-utils.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;../Common/initShaders.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;../Common/MV.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;Homework1.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;&#xA;&amp;lt;body&amp;gt;&#xA;&amp;lt;canvas id=&quot;gl-canvas&quot; width=&quot;1024&quot; height=&quot;1024&quot;&amp;gt;&#xA;Oops ... your browser doesn't support the HTML5 canvas element&#xA;&amp;lt;/canvas&amp;gt;&#xA;&amp;lt;/body&amp;gt;&#xA;&amp;lt;/html&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;JAVASCRIPT&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;use strict&quot;;&#xA;&#xA;var canvas;&#xA;var gl;&#xA;&#xA;var numVertices  = 36;&#xA;&#xA;var texSize = 256;&#xA;var numChecks = 8;&#xA;&#xA;var program;&#xA;&#xA;var texture1, texture2;&#xA;var t1, t2;&#xA;var normalsArray = [];&#xA;&#xA;var dirLightPosition = vec4(1.0, 1.0, 1.0, 0.0 );&#xA;var dirLightAmbient = vec4(0.2, 0.2, 0.2, 1.0 );&#xA;var dirLightDiffuse = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;var dirLightSpecular = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;&#xA;var posLightPosition = vec4(1.0, 1.0, 1.0, 1.0 );&#xA;var posLightAmbient = vec4(0.2, 0.2, 0.2, 1.0 );&#xA;var posLightDiffuse = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;var posLightSpecular = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;&#xA;var materialAmbient = vec4( 1.0, 0.0, 1.0, 1.0 );&#xA;var materialDiffuse = vec4( 1.0, 0.8, 0.0, 1.0 );&#xA;var materialSpecular = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;var materialShininess = 20.0;&#xA;&#xA;var spotLightPosition = vec4(1.0, 2.0, 3.0, 1.0 );&#xA;var spotLightAmbient = vec4(0.2, 0.2, 0.2, 1.0 );&#xA;var spotLightDiffuse = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;var spotLightSpecular = vec4( 1.0, 1.0, 1.0, 1.0 );&#xA;var spotLightDirection = vec4(-0.5,1.0,2.0,1.0);&#xA;var lCutOff=0.867;&#xA;&#xA;&#xA;var c;&#xA;&#xA;var flag = true;&#xA;&#xA;var image1 = new Uint8Array(4*texSize*texSize);&#xA;&#xA;    for ( var i = 0; i &amp;lt; texSize; i++ ) {&#xA;        for ( var j = 0; j &amp;lt;texSize; j++ ) {&#xA;            var patchx = Math.floor(i/(texSize/numChecks));&#xA;            var patchy = Math.floor(j/(texSize/numChecks));&#xA;            if(patchx%2 ^ patchy%2) c = 255;&#xA;            else c = 0;&#xA;            //c = 255*(((i &amp;amp; 0x8) == 0) ^ ((j &amp;amp; 0x8)  == 0))&#xA;            image1[4*i*texSize+4*j] = c;&#xA;            image1[4*i*texSize+4*j+1] = c;&#xA;            image1[4*i*texSize+4*j+2] = c;&#xA;            image1[4*i*texSize+4*j+3] = 255;&#xA;        }&#xA;    }&#xA;&#xA;var image2 = new Uint8Array(4*texSize*texSize);&#xA;&#xA;    // Create a checkerboard pattern&#xA;    for ( var i = 0; i &amp;lt; texSize; i++ ) {&#xA;        for ( var j = 0; j &amp;lt;texSize; j++ ) {&#xA;            image2[4*i*texSize+4*j] = 127+127*Math.sin(0.1*i*j);&#xA;            image2[4*i*texSize+4*j+1] = 127+127*Math.sin(0.1*i*j);&#xA;            image2[4*i*texSize+4*j+2] = 127+127*Math.sin(0.1*i*j);&#xA;            image2[4*i*texSize+4*j+3] = 255;&#xA;           }&#xA;    }&#xA;&#xA;var pointsArray = [];&#xA;var colorsArray = [];&#xA;var texCoordsArray = [];&#xA;&#xA;var texCoord = [&#xA;    vec2(0, 0),&#xA;    vec2(0, 1),&#xA;    vec2(1, 1),&#xA;    vec2(1, 0)&#xA;];&#xA;&#xA;var vertices = [&#xA;    vec4( -0.5, -0.5,  0.5, 1.0 ),&#xA;    vec4( -0.5,  0.5,  0.5, 1.0 ),&#xA;    vec4( 0.5,  0.5,  0.5, 1.0 ),&#xA;    vec4( 0.5, -0.5,  0.5, 1.0 ),&#xA;    vec4( -0.5, -0.5, -0.5, 1.0 ),&#xA;    vec4( -0.5,  0.5, -0.5, 1.0 ),&#xA;    vec4( 0.5,  0.5, -0.5, 1.0 ),&#xA;    vec4( 0.5, -0.5, -0.5, 1.0 )&#xA;];&#xA;&#xA;var vertexColors = [&#xA;    vec4( 0.0, 0.0, 0.0, 1.0 ),  // black&#xA;    vec4( 1.0, 0.0, 0.0, 1.0 ),  // red&#xA;    vec4( 1.0, 1.0, 0.0, 1.0 ),  // yellow&#xA;    vec4( 0.0, 1.0, 0.0, 1.0 ),  // green&#xA;    vec4( 0.0, 0.0, 1.0, 1.0 ),  // blue&#xA;    vec4( 1.0, 0.0, 1.0, 1.0 ),  // magenta&#xA;    vec4( 0.0, 1.0, 1.0, 1.0 ),  // white&#xA;    vec4( 0.0, 1.0, 1.0, 1.0 )   // cyan&#xA;];&#xA;&#xA;var xAxis = 0;&#xA;var yAxis = 1;&#xA;var zAxis = 2;&#xA;var axis = xAxis;&#xA;&#xA;var theta = [45.0, 45.0, 45.0];&#xA;&#xA;var thetaLoc;&#xA;&#xA;function configureTexture() {&#xA;    texture1 = gl.createTexture();&#xA;    gl.bindTexture( gl.TEXTURE_2D, texture1 );&#xA;    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);&#xA;    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, texSize, texSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, image1);&#xA;    gl.generateMipmap( gl.TEXTURE_2D );&#xA;    gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,&#xA;                      gl.NEAREST_MIPMAP_LINEAR );&#xA;    gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);&#xA;&#xA;    texture2 = gl.createTexture();&#xA;    gl.bindTexture( gl.TEXTURE_2D, texture2 );&#xA;    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);&#xA;    gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, texSize, texSize, 0, gl.RGBA, gl.UNSIGNED_BYTE, image2);&#xA;    gl.generateMipmap( gl.TEXTURE_2D );&#xA;    gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER,&#xA;                      gl.NEAREST_MIPMAP_LINEAR );&#xA;    gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);&#xA;}&#xA;&#xA;function quad(a, b, c, d) {&#xA;&#xA;     var t1 = subtract(vertices[b], vertices[a]);&#xA;     var t2 = subtract(vertices[c], vertices[b]);&#xA;     var normal = cross(t1, t2);&#xA;     var normal = vec3(normal);&#xA;&#xA;     pointsArray.push(vertices[a]);&#xA;     colorsArray.push(vertexColors[a]);&#xA;     texCoordsArray.push(texCoord[0]);&#xA;     normalsArray.push(normal);&#xA;&#xA;     pointsArray.push(vertices[b]);&#xA;     colorsArray.push(vertexColors[a]);&#xA;     texCoordsArray.push(texCoord[1]);&#xA;     normalsArray.push(normal);&#xA;&#xA;     pointsArray.push(vertices[c]);&#xA;     colorsArray.push(vertexColors[a]);&#xA;     texCoordsArray.push(texCoord[2]);&#xA;     normalsArray.push(normal);&#xA;&#xA;     pointsArray.push(vertices[a]);&#xA;     colorsArray.push(vertexColors[a]);&#xA;     texCoordsArray.push(texCoord[0]);&#xA;     normalsArray.push(normal);&#xA;&#xA;     pointsArray.push(vertices[c]);&#xA;     colorsArray.push(vertexColors[a]);&#xA;     texCoordsArray.push(texCoord[2]);&#xA;     normalsArray.push(normal);&#xA;&#xA;     pointsArray.push(vertices[d]);&#xA;     colorsArray.push(vertexColors[a]);&#xA;     texCoordsArray.push(texCoord[3]);&#xA;     normalsArray.push(normal);&#xA;}&#xA;&#xA;function colorCube()&#xA;{&#xA;    quad( 1, 0, 3, 2 );&#xA;    quad( 2, 3, 7, 6 );&#xA;    quad( 3, 0, 4, 7 );&#xA;    quad( 6, 5, 1, 2 );&#xA;    quad( 4, 5, 6, 7 );&#xA;    quad( 5, 4, 0, 1 );&#xA;}&#xA;&#xA;&#xA;window.onload = function init() {&#xA;&#xA;    canvas = document.getElementById( &quot;gl-canvas&quot; );&#xA;&#xA;    gl = WebGLUtils.setupWebGL( canvas );&#xA;    if ( !gl ) { alert( &quot;WebGL isn't available&quot; ); }&#xA;&#xA;    gl.viewport( 0, 0, canvas.width, canvas.height );&#xA;    gl.clearColor( 1.0, 1.0, 1.0, 1.0 );&#xA;&#xA;    gl.enable(gl.DEPTH_TEST);&#xA;&#xA;    //&#xA;    //  Load shaders and initialize attribute buffers&#xA;    //&#xA;    program = initShaders( gl, &quot;vertex-shader&quot;, &quot;fragment-shader&quot; );&#xA;    gl.useProgram( program );&#xA;&#xA;    colorCube();&#xA;&#xA;    var nBuffer = gl.createBuffer();&#xA;    gl.bindBuffer( gl.ARRAY_BUFFER, nBuffer );&#xA;    gl.bufferData( gl.ARRAY_BUFFER, flatten(normalsArray), gl.STATIC_DRAW );&#xA;&#xA;    var vNormal = gl.getAttribLocation( program, &quot;vNormal&quot; );&#xA;    gl.vertexAttribPointer( vNormal, 3, gl.FLOAT, false, 0, 0 );&#xA;    gl.enableVertexAttribArray( vNormal );&#xA;&#xA;&#xA;    var cBuffer = gl.createBuffer();&#xA;    gl.bindBuffer( gl.ARRAY_BUFFER, cBuffer );&#xA;    gl.bufferData( gl.ARRAY_BUFFER, flatten(colorsArray), gl.STATIC_DRAW );&#xA;&#xA;    var vColor = gl.getAttribLocation( program, &quot;vColor&quot; );&#xA;    gl.vertexAttribPointer( vColor, 4, gl.FLOAT, false, 0, 0 );&#xA;    gl.enableVertexAttribArray( vColor );&#xA;&#xA;    var vBuffer = gl.createBuffer();&#xA;    gl.bindBuffer( gl.ARRAY_BUFFER, vBuffer);&#xA;    gl.bufferData( gl.ARRAY_BUFFER, flatten(pointsArray), gl.STATIC_DRAW );&#xA;&#xA;    var vPosition = gl.getAttribLocation( program, &quot;vPosition&quot; );&#xA;    gl.vertexAttribPointer( vPosition, 4, gl.FLOAT, false, 0, 0 );&#xA;    gl.enableVertexAttribArray( vPosition );&#xA;&#xA;    var tBuffer = gl.createBuffer();&#xA;    gl.bindBuffer( gl.ARRAY_BUFFER, tBuffer);&#xA;    gl.bufferData( gl.ARRAY_BUFFER, flatten(texCoordsArray), gl.STATIC_DRAW );&#xA;&#xA;    var vTexCoord = gl.getAttribLocation( program, &quot;vTexCoord&quot; );&#xA;    gl.vertexAttribPointer( vTexCoord, 2, gl.FLOAT, false, 0, 0 );&#xA;    gl.enableVertexAttribArray( vTexCoord );&#xA;&#xA;    var dirAmbientProduct = mult(dirLightAmbient, materialAmbient);&#xA;    var dirDiffuseProduct = mult(dirLightDiffuse, materialDiffuse);&#xA;    var dirSpecularProduct = mult(dirLightSpecular, materialSpecular);&#xA;&#xA;    var posAmbientProduct = mult(posLightAmbient, materialAmbient);&#xA;    var posDiffuseProduct = mult(posLightDiffuse, materialDiffuse);&#xA;    var posSpecularProduct = mult(posLightSpecular, materialSpecular);&#xA;&#xA;&#xA;    var spotAmbientProduct = mult(spotLightAmbient, materialAmbient);&#xA;    var spotDiffuseProduct = mult(spotLightDiffuse, materialDiffuse);&#xA;    var spotSpecularProduct = mult(spotLightSpecular, materialSpecular);&#xA;&#xA;&#xA;&#xA;&#xA;    configureTexture();&#xA;&#xA;    gl.activeTexture( gl.TEXTURE0 );&#xA;    gl.bindTexture( gl.TEXTURE_2D, texture1 );&#xA;    gl.uniform1i(gl.getUniformLocation( program, &quot;Tex0&quot;), 0);&#xA;&#xA;    gl.activeTexture( gl.TEXTURE1 );&#xA;    gl.bindTexture( gl.TEXTURE_2D, texture2 );&#xA;    gl.uniform1i(gl.getUniformLocation( program, &quot;Tex1&quot;), 1);&#xA;&#xA;    thetaLoc = gl.getUniformLocation(program, &quot;theta&quot;);&#xA;&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;dirAmbientProduct&quot;),flatten(dirAmbientProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;posAmbientProduct&quot;),flatten(posAmbientProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;spotAmbientProduct&quot;),flatten(spotAmbientProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;dirDiffuseProduct&quot;),flatten(dirDiffuseProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;posDiffuseProduct&quot;),flatten(posDiffuseProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;spotDiffuseProduct&quot;),flatten(spotDiffuseProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;dirSpecularProduct&quot;),flatten(dirSpecularProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;posSpecularProduct&quot;),flatten(posSpecularProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;spotSpecularProduct&quot;),flatten(spotSpecularProduct) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;posLightPosition&quot;),flatten(posLightPosition) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;dirLightPosition&quot;),flatten(dirLightPosition) );&#xA;    gl.uniform4fv( gl.getUniformLocation(program,&#xA;       &quot;spotLightPosition&quot;),flatten(spotLightPosition) );&#xA;    gl.uniform1f( gl.getUniformLocation(program,&#xA;       &quot;shininess&quot;),materialShininess );&#xA;    gl.uniform1f( gl.getUniformLocation(program,&#xA;       &quot;lCutOff&quot;),lCutOff );&#xA;    gl.uniform1f( gl.getUniformLocation(program,&#xA;       &quot;spotLightDirection&quot;),spotLightDirection );&#xA;&#xA;&#xA;&#xA;&#xA; document.getElementById(&quot;ButtonX&quot;).onclick = function(){axis = xAxis;};&#xA; document.getElementById(&quot;ButtonY&quot;).onclick = function(){axis = yAxis;};&#xA; document.getElementById(&quot;ButtonZ&quot;).onclick = function(){axis = zAxis;};&#xA; document.getElementById(&quot;ButtonT&quot;).onclick = function(){flag = !flag;};&#xA;&#xA;    render();&#xA;}&#xA;&#xA;var render = function() {&#xA;    gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);&#xA;    if(flag) theta[axis] += 2.0;&#xA;    gl.uniform3fv(thetaLoc, theta);&#xA;    gl.drawArrays( gl.TRIANGLES, 0, numVertices );&#xA;    requestAnimFrame(render);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So I computed tha angle between the spotlight direction and the vector to light source from vertex and if this angle is greater than the cutoff angle defined by the spotlight I compute the three products for the Phong lighting model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where am I wrong?&lt;/p&gt;&#xA;" OwnerUserId="6401" LastEditorUserId="6401" LastEditDate="2017-04-20T17:54:07.303" LastActivityDate="2017-04-20T17:54:07.303" Title="WebGL Spotlight" Tags="&lt;lighting&gt;&lt;webgl&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5017" PostTypeId="1" AcceptedAnswerId="5019" CreationDate="2017-04-21T01:41:52.290" Score="7" ViewCount="886" Body="&lt;p&gt;Some games claim to use subsurface scattering but my current understanding of sss is only achieved with ray tracing. How would you sub surface scatter without ray tracing? Do some claim to use sss but really use some approximation trick that doesn't use rays. I can't even imagine doing the below real time.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/U6i0v.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/U6i0v.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="2479" LastEditDate="2017-04-24T09:02:38.007" LastActivityDate="2017-04-24T09:02:38.007" Title="Subsurface Scattering Without Rays?" Tags="&lt;raytracing&gt;&lt;real-time&gt;&lt;rasterizer&gt;&lt;subsurface-scattering&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5018" PostTypeId="1" AcceptedAnswerId="5208" CreationDate="2017-04-21T14:23:35.873" Score="4" ViewCount="351" Body="&lt;p&gt;I am trying to achieve a special texture stretching effect in my shader.&#xA;Here is how I define my uv before sampling my texture, nothing really special.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// uv_ST contains the tiling and offset values&#xA;uv.xy = uv.xy * uv_ST.xy + uv_ST.zw&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This gives the standard tiling/stretching and offset behaviour when you tile/stretche a clamped texture as you can see in the image below. First is normal, second is offset and last is stretching.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Zwj4l.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Zwj4l.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I want to avoid the deformation behaviour when stretching, I want to keep margins when stretching my texture or simply cut it in the middle and stretching it. Here is an illustration below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HdUgs.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HdUgs.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How could I do that inside my shader when defining my uvs before sampling the texture ?&lt;/p&gt;&#xA;" OwnerUserId="2372" LastEditorUserId="2372" LastEditDate="2017-04-21T15:40:27.670" LastActivityDate="2017-06-06T09:12:49.437" Title="Special Texture Stretching without deformation" Tags="&lt;shader&gt;&lt;texture&gt;&lt;glsl&gt;&lt;hlsl&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5019" PostTypeId="2" ParentId="5017" CreationDate="2017-04-21T17:53:45.463" Score="8" Body="&lt;p&gt;There are lots of ways to fake SSS with greater or lesser fidelity. A few recent-ish methods:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Screen-space blurring of object lighting (described in detail &lt;a href=&quot;http://www.iryoku.com/sssss/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/WyOYZ.png&quot; alt=&quot;screen-space light blurring&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Using “interior” ambient-occlusion maps generated from a normal-flipped version of the geometry to approximate local thickness, providing an easy way to fake light transmission (more information &lt;a href=&quot;https://colinbarrebrisebois.com/2011/03/07/gdc-2011-approximating-translucency-for-a-fast-cheap-and-convincing-subsurface-scattering-look/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;, with an addendum &lt;a href=&quot;https://colinbarrebrisebois.com/2011/04/04/approximating-translucency-part-ii-addendum-to-gdc-2011-talk-gpu-pro-2-article/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/NFG3W.png&quot; alt=&quot;local thickness map&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There’s also the assortment of techniques in the GPU Gems article PaulHK linked to. One thing I’d add is about the light-falloff-texture approach mentioned at the beginning of it, which Valve used for a couple of interesting effects in Source games in addition to fake SSS—see their &lt;a href=&quot;https://developer.valvesoftware.com/wiki/$lightwarptexture&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;$lightwarptexture&lt;/code&gt;&lt;/a&gt; documentation for some information about that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/0AXjk.png&quot; alt=&quot;Team Fortress 2 illustrative rendering&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2017-04-21T17:53:45.463" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5021" PostTypeId="1" AcceptedAnswerId="5082" CreationDate="2017-04-23T16:08:02.317" Score="0" ViewCount="2976" Body="&lt;p&gt;I have to build a texture of a cube that models the emission of light by the object. Any tips? I really don't know where to start.&lt;/p&gt;&#xA;" OwnerUserId="6401" LastActivityDate="2017-05-09T10:01:10.883" Title="Emission of light from texture on WebGL" Tags="&lt;texture&gt;&lt;lighting&gt;&lt;webgl&gt;" AnswerCount="2" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5022" PostTypeId="1" CreationDate="2017-04-24T09:49:29.407" Score="0" ViewCount="141" Body="&lt;p&gt;I'm playing around with volume rendering and looking into multi dimensional transfer functions. I keep seeing images like this for 2d transfer functions:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZUJqV.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZUJqV.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read numerous papers and articles but haven't gotten very far because I can't seem to understand how the image on the right is generated from the volume data set. Also what would you call this image? From my understanding the two axis are data values (intensities) on the x and gradient magnitude on the y. But where is the gradient magnitude coming from? I have a basic understanding of gradient magnitude and don't see how it can be used to make that picture.&#xA;How is it calculated? How can I generate a picture like the one on the right?&lt;/p&gt;&#xA;" OwnerUserId="113" LastActivityDate="2018-01-17T00:51:52.407" Title="How to generate a 2d histogram?" Tags="&lt;rendering&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5023" PostTypeId="1" CreationDate="2017-04-24T11:30:14.640" Score="2" ViewCount="325" Body="&lt;p&gt;I wanted to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Monotone_cubic_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Monotone cubic interpolation&lt;/a&gt;, but the site only provide explanation for 2D case. How can I extend it to 3D?&lt;/p&gt;&#xA;" OwnerUserId="2687" LastActivityDate="2017-04-26T07:32:22.853" Title="How to use Monotone cubic interpolation in 3D?" Tags="&lt;interpolation&gt;&lt;curve&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5024" PostTypeId="1" CreationDate="2017-04-24T15:17:09.370" Score="0" ViewCount="266" Body="&lt;p&gt;I am working on a project which plots points over a checkerboard (representing seats for people).  I would like each pixel in the image to represent each integer matrix entry.  After updating my Octave from $3.8$ to $4.2$, any image takes up $\frac 14$ of the actual plot window using the default OpenGL/ FLTK, as seen below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sample code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;clear&#xA;&#xA;A = [1,2;3,4];&#xA;&#xA;image(A)&#xA;&#xA;axis xy %orients to bottom left&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I need the purple to take up the entire plot window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can plot overtop the image using the line() function and I get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iweRz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iweRz.png&quot; alt=&quot;OpenGL with Line plotted overtop&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if I enter graphics_toolkit(&quot;gnuplot&quot;) into the octave command window prior to running the code then I get the correct purple image taking up the entire plot window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if I then use the line() function under gnuplot and plot the same line as before with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x=[0.5,2.5];&#xA;y=[1,1];&#xA;line(x,y,'color','red','linewidth',2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the following bug appears:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;multiplot&gt; lot &quot;-&quot; binary format='%float64' record=2 using ($1):($2) axes x1y1 title &quot;&quot; with lines linestyle 10 ;&#xA;           ^&#xA;           line 0: invalid command&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and I get the following image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6LR2U.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6LR2U.png&quot; alt=&quot;Gnuplot with Line() function overtop&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know the issue?  Thank you.&lt;/p&gt;&#xA;" OwnerUserId="6501" LastEditorUserId="6501" LastEditDate="2017-05-19T18:50:47.850" LastActivityDate="2017-05-19T18:50:47.850" Title="Octave matrix to image pixels too small (do not have 1 pixel per integer)" Tags="&lt;image-processing&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5025" PostTypeId="2" ParentId="5012" CreationDate="2017-04-25T22:42:55.887" Score="1" Body="&lt;p&gt;Ok, so I made little example of how to do this.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Short version&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;You need to allocate additional buffer with heap type &lt;code&gt;D3D12_HEAP_TYPE_READBACK&lt;/code&gt; and resource state set to &lt;code&gt;D3D12_RESOURCE_STATE_COPY_DEST&lt;/code&gt;. Then create command list with type &lt;code&gt;D3D12_COMMAND_LIST_TYPE_COPY&lt;/code&gt;. After dispatch compute shader use fence to check if buffer is ready, then copy from this buffer to buffer on &lt;code&gt;D3D12_HEAP_TYPE_READBACK&lt;/code&gt; heap. Check again with fence if copying is finished and call &lt;code&gt;Map&lt;/code&gt; on this buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would suggest that you stop reading here and try implement it from description above and check longer version if its still doesn't work. Copy/Past isn't the best way to learn :)&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;strong&gt;Longer version&lt;/strong&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;First lets create new command list.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ID3D12CommandQueue* copyQueue;&#xA;ID3D12CommandAllocator* copyAllocator;&#xA;ID3D12GraphicsCommandList* copyList;&#xA;&#xA;D3D12_COMMAND_QUEUE_DESC descCopyQueue = {};&#xA;descCopyQueue.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;&#xA;descCopyQueue.Type = D3D12_COMMAND_LIST_TYPE_COPY;&#xA;device-&amp;gt;CreateCommandQueue(&amp;amp;descCopyQueue, IID_PPV_ARGS(&amp;amp;copyQueue));&#xA;device-&amp;gt;CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_COPY, IID_PPV_ARGS(&amp;amp;copyAllocator));&#xA;device-&amp;gt;CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_COPY, copyAllocator, nullptr, IID_PPV_ARGS(&amp;amp;copyList));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Notice type &lt;code&gt;D3D12_COMMAND_LIST_TYPE_COPY&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next thing is new buffer.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D12_HEAP_PROPERTIES const heapPropertiesReadback =&#xA;{&#xA;    /*Type*/                    D3D12_HEAP_TYPE_READBACK&#xA;    /*CPUPageProperty*/         ,D3D12_CPU_PAGE_PROPERTY_UNKNOWN&#xA;    /*MemoryPoolPreference*/    ,D3D12_MEMORY_POOL_UNKNOWN&#xA;    /*CreationNodeMask*/        ,0&#xA;    /*VisibleNodeMask*/         ,0&#xA;};&#xA;&#xA;D3D12_RESOURCE_DESC buffersDesc = {};&#xA;buffersDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;&#xA;buffersDesc.Alignment = 0;&#xA;buffersDesc.Width = sizeof( unsigned int ) * 5;&#xA;buffersDesc.Height = 1;&#xA;buffersDesc.DepthOrArraySize = 1;&#xA;buffersDesc.MipLevels = 1;&#xA;buffersDesc.Format = DXGI_FORMAT_UNKNOWN;&#xA;buffersDesc.SampleDesc.Count = 1;&#xA;buffersDesc.SampleDesc.Quality = 0;&#xA;buffersDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;&#xA;buffersDesc.Flags = D3D12_RESOURCE_FLAG_NONE;&#xA;&#xA;ID3D12Resource* bufferReadback;&#xA;&#xA;device-&amp;gt;CreateCommittedResource(&amp;amp;heapPropertiesReadback, D3D12_HEAP_FLAG_NONE, &amp;amp;buffersDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&amp;amp;bufferReadback));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Remember to set &lt;code&gt;D3D12_RESOURCE_DESC ::Width&lt;/code&gt; to size of your buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then after you &lt;code&gt;Dispatch&lt;/code&gt; compute list and call &lt;code&gt;ExecuteCommandLists&lt;/code&gt; on compute queue you need to use fence, copy buffer and use fence again.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;computeQueue-&amp;gt;Signal(fence, fenceValue);&#xA;fence-&amp;gt;SetEventOnCompletion(fenceValue, fenceEvent);&#xA;++fenceValue;&#xA;WaitForSingleObject(fenceEvent, INFINITE);&#xA;&#xA;copyList-&amp;gt;CopyResource(bufferReadback, bufferB);&#xA;copyList-&amp;gt;Close();&#xA;copyQueue-&amp;gt;ExecuteCommandLists(1, (ID3D12CommandList**)(&amp;amp;copyList));&#xA;&#xA;copyQueue-&amp;gt;Signal(fence, fenceValue);&#xA;fence-&amp;gt;SetEventOnCompletion(fenceValue, fenceEvent);&#xA;++fenceValue;&#xA;WaitForSingleObject(fenceEvent, INFINITE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After this you can call &lt;code&gt;Map&lt;/code&gt; on resource.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned int* data;&#xA;bufferReadback-&amp;gt;Map(0, nullptr, reinterpret_cast&amp;lt;void**&amp;gt;(&amp;amp;data));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I hope this will help, let me know if you have any questions.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2017-04-25T22:42:55.887" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5026" PostTypeId="2" ParentId="5023" CreationDate="2017-04-26T07:32:22.853" Score="4" Body="&lt;p&gt;Ok, monotonic interpolation depends on what you are monotonic about. For a simple 1D function interpolation monotonicity is easy to define. But for a 2D and 3D dataset its not so self evident what the situation would be.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;First you could interpolate along a independent variable t in which case your monotonicity is most probably in relation to t. This is the same as interpolating each direction separately.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Second you could interpolate along one of the axes, so that your interpolant becomes a function of position on that axis. Reducing a 2D case into a 1D case and a 3D case to two separate 2D cases.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Third you could interpolate on some other spatial variable.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So you see the question is a bit open ended and is hard to say for sure.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-04-26T07:32:22.853" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5027" PostTypeId="1" AcceptedAnswerId="5031" CreationDate="2017-04-26T17:31:25.210" Score="7" ViewCount="893" Body="&lt;p&gt;I'm working my way through this paper about GGX-filtering environment maps:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.ppsloan.org/publications/ggx_filtering.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.ppsloan.org/publications/ggx_filtering.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I find myself stuck on the basics.  In particular, I am confused by two statements in section 1.1, &lt;em&gt;Related Work&lt;/em&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Most recent reflection models assume&#xA;  dielectric materials, and in the case of a metal would simply multiply&#xA;  the specular color by an auxiliary specular color map.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This sentence immediately follows an overview of old-school mirrored torus environment mapping, which it refers to as &quot;metal&quot;.  However, I'm not sure what the author means by specular color here -- incident light or material color.  Likewise, what is this secondary map that is referenced.  Is that the metalness map from the currently popular PBR texturing workflow?  Or is &quot;auxillary specular color map&quot; a cubemap?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Importance&#xA;  sampling is inefficient for texture filtering because raster images&#xA;  are band-limited, which results in the peak of the function being&#xA;  oversampled&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I don't understand this at all.  I am still learning importance sampling via Peter Shirley's weekend book, so I kind of get the difference between sampling a function with infinite resolution and sampling a down sampled raster grid... but I don't know what the author means by band-limited and how that produces the peak oversampling effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry if these questions are overly naive!  I'm going to try to read (Kautz 03) now to hopefully fill in some gaps.  My ultimate goal is to write the simplest possible dynamic environment mapping demo to show an after school class the connection between offline global illumination and high-end realtime rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A side goal is to synthesize for myself a history of these techniques from the end of this article until today:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.pauldebevec.com/ReflectionMapping/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pauldebevec.com/ReflectionMapping/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastEditorDisplayName="user3412" LastEditDate="2017-04-27T15:30:18.527" LastActivityDate="2017-04-29T01:37:46.317" Title="Confused about prefiltering environment maps (Manson 16)" Tags="&lt;lighting&gt;&lt;real-time&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5028" PostTypeId="1" AcceptedAnswerId="5043" CreationDate="2017-04-26T20:55:08.593" Score="3" ViewCount="387" Body="&lt;p&gt;I am trying to write my own path tracer in JavaScript, but I have a problem with the implementation of russian roulette. First, let me describe how my path tracer works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a function called &lt;em&gt;traceRay&lt;/em&gt; where I am looking for ray-objects intersections and doing some shading. Shading is divided into direct and indirect illumination. I have a separate function that does Importance Sampling only and it is being called inside &lt;em&gt;traceRay&lt;/em&gt;. This function gets Monte Carlo samples count and max recursion depth as parameters, generates sample rays and calls &lt;em&gt;traceRay&lt;/em&gt; again (if max recursion depth is not exceeded).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RayTracer.indirectLighting = function(scene, camera, intersectionPoint, normal, options)&#xA;{&#xA;  var prob = 0.5;&#xA;  var oneOverProb = 1/prob;&#xA;  if(Math.random() &amp;lt; prob) return new Vector(0,0,0);&#xA;&#xA;  var diffuse = new Vector(0, 0, 0);&#xA;  var specular = new Vector(0, 0, 0);&#xA;&#xA;  if(options.MC_SAMPLES &amp;gt; 0)// &amp;amp;&amp;amp; options.MC_DEPTH &amp;gt; 0)&#xA;  {&#xA;    var basis = createCoordinationSystem(normal);&#xA;    var sampleVector, sampleTransformed, mcRay;&#xA;    for(var i = 0; i &amp;lt; options.MC_SAMPLES; ++i)&#xA;    {&#xA;      sampleVector = getCosineWeightedSample(Math.random(), Math.random());&#xA;      sampleTransformed = new Vector(sampleVector.x * basis.tangent.x + sampleVector.y * normal.x + sampleVector.z * basis.bitangent.x,&#xA;                                 sampleVector.x * basis.tangent.y + sampleVector.y * normal.y + sampleVector.z * basis.bitangent.y,&#xA;                                 sampleVector.x * basis.tangent.z + sampleVector.y * normal.z + sampleVector.z * basis.bitangent.z);&#xA;      mcRay = new Ray(intersectionPoint.clone().add(sampleTransformed.clone().mul(0.000001)), sampleTransformed);&#xA;&#xA;      diffuse.add(RayTracer.traceRay(mcRay, scene, camera, {&#xA;        MC_DEPTH: options.MC_DEPTH - 1,&#xA;        MC_SAMPLES: options.MC_SAMPLES,&#xA;        AREA_LIGHT_SAMPLES: options.AREA_LIGHT_SAMPLES&#xA;      }));&#xA;    }&#xA;    diffuse.mul(1 / options.MC_SAMPLES);&#xA;  }&#xA;  return Vector.add(diffuse, specular).mul(oneOverProb);&#xA;}&#xA;&#xA;&#xA;RayTracer.traceRay = function(ray, scene, camera, options)&#xA;{&#xA;  var color = new Vector(0, 0, 0);&#xA;  //Depth test - finding closest object&#xA;  var minT = 1e12, currentT;&#xA;  var object = null;&#xA;  var objectI;&#xA;  for(var i = 0; i &amp;lt; scene.objects.length; ++i)&#xA;  {&#xA;    currentT = scene.objects[i].intersects(ray);&#xA;    if(currentT &amp;gt; 0 &amp;amp;&amp;amp; currentT &amp;lt; minT)&#xA;    {&#xA;      objectI = i;&#xA;      minT = currentT;&#xA;      object = scene.objects[i];&#xA;    }&#xA;  }&#xA;&#xA;  var emissiveObjects = [];&#xA;  for(var i = 0; i &amp;lt; scene.objects.length; ++i)&#xA;  {&#xA;    if(i == objectI) continue;&#xA;    else if(scene.objects[i].isFinite &amp;amp;&amp;amp; scene.objects[i].material.emittance.lengthSq() &amp;gt; 0.3)&#xA;      emissiveObjects.push(scene.objects[i]);&#xA;  }&#xA;&#xA;  if(object == null) return new Vector(0, 0, 0);&#xA;&#xA;  var indirectLighting = new Vector(0, 0, 0);&#xA;  var directLighting = new Vector(0, 0, 0);&#xA;&#xA;  var intersectionPoint = ray.getPoint(minT);&#xA;  var normal = object.getNormalAt(intersectionPoint);&#xA;  var toEye = camera.position.clone().sub(intersectionPoint).normalize();&#xA;  var albedo = object.material.color.clone().mul(object.material.diffuseFactor);&#xA;&#xA;  //Direct illumination&#xA;  for(var n = 0; n &amp;lt; scene.lights.length; ++n)&#xA;  {&#xA;    //Searching for objects occluding light&#xA;    var shadowRay = scene.lights[n].getShadowRay(intersectionPoint);&#xA;    var inShadow = RayTracer.visabilityTest(shadowRay, scene.objects,&#xA;  scene.lights[n].occlusionTestLimit(shadowRay)).occlusion;&#xA;&#xA;    if(!inShadow)&#xA;    {&#xA;      var lighting = scene.lights[n].getLightingInfo(intersectionPoint, normal, toEye);&#xA;&#xA;      directLighting.add(scene.lights[n].color.clone().mul(&#xA;    lighting.diffuse * lighting.attenuation * scene.lights[n].intensity / Math.PI))&#xA;    }&#xA;  }&#xA;&#xA;  color.add(Vector.componetesMul(object.material.color, scene.ambient));&#xA;&#xA;  directLighting.add(RayTracer.sampleAreaLights(scene, emissiveObjects, intersectionPoint, normal, options.AREA_LIGHT_SAMPLES));&#xA;  indirectLighting = RayTracer.indirectLighting(scene, camera, intersectionPoint, normal, options);&#xA;&#xA;  color.add(object.material.emittance.clone().clamp(0, 1));&#xA;  color.add(Vector.componetesMul(directLighting.add(indirectLighting), albedo));&#xA;&#xA;  return color&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem is that when I remove recursion depth test and add russian roulette to my indirect illumination function I get &quot;Maximum call stack size exceeded&quot; error. Same problem is when I implement roulette in &lt;em&gt;traceRay&lt;/em&gt; function. But when I use only one Monte Carlo sample, everything works fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My russian roulette algorithm works as follows: at the beginning of a function, I am checking if a pseudo-random number is less then some constant threshold. If so, I am returning black color. In other case, function does what it would do without roulette, but the returned value is divided by the threshold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the question is: how do I implement Russian Roulette properly?&lt;/p&gt;&#xA;" OwnerUserId="6515" LastEditorUserId="231" LastEditDate="2017-05-04T19:41:17.070" LastActivityDate="2017-05-04T19:41:17.070" Title="Russian Roulette - Maximum call stack size exceeded" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5029" PostTypeId="1" AcceptedAnswerId="5037" CreationDate="2017-04-27T19:45:51.180" Score="4" ViewCount="204" Body="&lt;p&gt;This is the vertex shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;layout (location = 0) in vec3 position;&#xA;layout (location = 1) in vec3 myColor;&#xA;&#xA;out vec3 MyColor;&#xA;&#xA;void main()&#xA;{&#xA;    MyColor = myColor;&#xA;    vec3 v = position;&#xA;    v.x = v.x/v.z;&#xA;    v.y = v.y/v.z;&#xA;    gl_Position = vec4(v, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This shader is fairly simple, but when I draw a square at the bottom instead of leaving the screen empty draws this shapes and I was wondering why does it happen:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uXmRW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uXmRW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following is an example code showing this behaviour so you only have to uncomment certain code snippets for checking it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;#define GLEW_STATIC&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;&#xA;#include &amp;lt;GLFW/glfw3.h&amp;gt;&#xA;&#xA;int main()&#xA;{&#xA;    //INIT LIBRARIES&#xA;    glfwInit();&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);&#xA;    GLFWwindow* window = glfwCreateWindow(200 ,200 , &quot;&quot;, nullptr, nullptr);&#xA;    glfwMakeContextCurrent(window);&#xA;    glewExperimental = GL_TRUE;&#xA;    glewInit();&#xA;    glViewport(0, 0, 200, 200);&#xA;&#xA;&#xA;&#xA;    //SHADERS&#xA;    const GLchar* VERTEX_SHADER_SOURCE =&#xA;        &quot;#version 330 core                      \n&quot;&#xA;        &quot;                                       \n&quot;&#xA;        &quot;layout (location = 0) in vec3 position;\n&quot;&#xA;        &quot;layout (location = 1) in vec3 myColor; \n&quot;&#xA;        &quot;                                       \n&quot;&#xA;        &quot;out vec3 MyColor;                      \n&quot;&#xA;        &quot;                                       \n&quot;&#xA;        &quot;void main()                            \n&quot;&#xA;        &quot;{                                      \n&quot;&#xA;        &quot;   MyColor = myColor;                  \n&quot;&#xA;        &quot;   vec3 v = position;                  \n&quot;&#xA;        &quot;   v.x = v.x/v.z;                      \n&quot;&#xA;        &quot;   v.y = v.y/v.z;                      \n&quot;&#xA;        &quot;   gl_Position = vec4(v, 1.0f);        \n&quot;&#xA;        &quot;}                                      \n&quot;;&#xA;&#xA;    const GLchar* FRAGMENT_SHADER_SOURCE =&#xA;        &quot;#version 330 core              \n&quot;&#xA;        &quot;                               \n&quot;&#xA;        &quot;in vec3 MyColor;               \n&quot;&#xA;        &quot;                               \n&quot;&#xA;        &quot;out vec4 color;                \n&quot;&#xA;        &quot;                               \n&quot;&#xA;        &quot;void main()                    \n&quot;&#xA;        &quot;{                              \n&quot;&#xA;        &quot;   color = vec4(MyColor,1.0f); \n&quot;&#xA;        &quot;}                              \n&quot;;&#xA;&#xA;    GLuint program;&#xA;    GLuint vertex, fragment;&#xA;&#xA;    vertex = glCreateShader(GL_VERTEX_SHADER);&#xA;    glShaderSource(vertex, 1, &amp;VERTEX_SHADER_SOURCE, NULL);&#xA;    glCompileShader(vertex);&#xA;&#xA;    fragment = glCreateShader(GL_FRAGMENT_SHADER);&#xA;    glShaderSource(fragment, 1, &amp;FRAGMENT_SHADER_SOURCE, NULL);&#xA;    glCompileShader(fragment);&#xA;&#xA;    program = glCreateProgram();&#xA;    glAttachShader(program, vertex);&#xA;    glAttachShader(program, fragment);&#xA;    glLinkProgram(program);&#xA;&#xA;    glDeleteShader(vertex);&#xA;    glDeleteShader(fragment);&#xA;    glUseProgram(program);&#xA;&#xA;    //VAOs &amp; VBOs&#xA;    GLfloat vertices[] =&#xA;//Uncomment one of the following set of vertices to see the program in action&#xA;//The last one produces the strange behaviour&#xA;    /*{&#xA;            //This set will show you a square occuping the full window&#xA;            -0.5f, -0.5f,  0.5f,        1.0f, 0.0f, 0.0f,&#xA;            -0.5f,  0.5f,  0.5f,        0.0f, 1.0f, 0.0f,&#xA;             0.5f, -0.5f,  0.5f,        0.0f, 0.0f, 1.0f,&#xA;             0.5f,  0.5f,  0.5f,        1.0f, 1.0f, 0.0f&#xA;    };/**/&#xA;    /*{&#xA;            //This set draw a square at the bottom&#xA;             0.5f, -0.5f,  0.5f,        1.0f, 0.0f, 0.0f,&#xA;            -0.5f, -0.5f,  0.5f,        0.0f, 1.0f, 0.0f,&#xA;             0.5f, -0.5f,  1.0f,        0.0f, 0.0f, 1.0f,&#xA;            -0.5f, -0.5f,  1.0f,        1.0f, 1.0f, 0.0f&#xA;    };/**/&#xA;    /*{&#xA;            //This set draw the square to the left (Z is negative therefore z/x is also negative and the x value is inversed)&#xA;            -0.5f, -0.5f, -0.5f,        1.0f, 0.0f, 0.0f,&#xA;            -0.5f,  0.5f, -0.5f,        0.0f, 1.0f, 0.0f,&#xA;            -0.5f, -0.5f, -1.0f,        0.0f, 0.0f, 1.0f,&#xA;            -0.5f,  0.5f, -1.0f,        1.0f, 1.0f, 0.0f&#xA;    };/**/&#xA;    {&#xA;            //This set should not draw anything because y = y/z -&gt; y = -0.5/[-0.25,+0.25] -&gt; y = (-inf,-4] U [4,inf)&#xA;            //[-0.25,+0.25] means any value between -0.25 and 0.25&#xA;            //(-inf,-4] U [4,inf) means any value that is not between -4 and 4&#xA;            //Whathever value 'y' gets is out of the range [-1,1] so it should not be visible, but instead a figure is drawn causing the strange behaviour&#xA;             0.5f, -0.5f, -0.25f,       1.0f, 0.0f, 0.0f,&#xA;            -0.5f, -0.5f, -0.25f,       0.0f, 1.0f, 0.0f,&#xA;             0.5f, -0.5f,  0.25f,       0.0f, 0.0f, 1.0f,&#xA;            -0.5f, -0.5f,  0.25f,       1.0f, 1.0f, 0.0f&#xA;    };/**/&#xA;&#xA;    GLuint VAO, VBO;&#xA;    glGenVertexArrays(1, &amp;VAO);&#xA;    glBindVertexArray(VAO);&#xA;    glGenBuffers(1, &amp;VBO);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3*sizeof(GLfloat)));&#xA;    glEnableVertexAttribArray(1);&#xA;&#xA;&#xA;    //DRAW&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    glDrawArrays(GL_TRIANGLE_STRIP, 0,4);&#xA;    glfwSwapBuffers(window);&#xA;    while (!glfwWindowShouldClose(window))&#xA;        glfwPollEvents();&#xA;&#xA;&#xA;&#xA;    //END&#xA;    glDeleteVertexArrays(1, &amp;VAO);&#xA;    glDeleteBuffers(1, &amp;VBO);&#xA;    glfwTerminate();&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt; The following link is a youtube video that will show you how the square gets transformed with different Z values:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://youtu.be/S4TsfZjCIbM&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/S4TsfZjCIbM&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is the code that I used for the video:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;#define GLEW_STATIC&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;&#xA;#include &amp;lt;GLFW/glfw3.h&amp;gt;&#xA;&#xA;int main()&#xA;{&#xA;    //INIT LIBRARIES&#xA;    glfwInit();&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);&#xA;    GLFWwindow* window = glfwCreateWindow(400 ,400 , &quot;&quot;, nullptr, nullptr);&#xA;    glfwMakeContextCurrent(window);&#xA;    glewExperimental = GL_TRUE;&#xA;    glewInit();&#xA;    glViewport(0, 0, 400, 400);&#xA;&#xA;&#xA;&#xA;    //SHADERS&#xA;    const GLchar* VERTEX_SHADER_SOURCE =&#xA;        &quot;#version 330 core                      \n&quot;&#xA;        &quot;                                       \n&quot;&#xA;        &quot;layout (location = 0) in vec3 position;\n&quot;&#xA;        &quot;layout (location = 1) in vec3 myColor; \n&quot;&#xA;        &quot;&quot;&#xA;        &quot;uniform float movement;&quot;&#xA;        &quot;                                       \n&quot;&#xA;        &quot;out vec3 MyColor;                      \n&quot;&#xA;        &quot;                                       \n&quot;&#xA;        &quot;void main()                            \n&quot;&#xA;        &quot;{                                      \n&quot;&#xA;        &quot;   MyColor = myColor;                  \n&quot;&#xA;        &quot;   vec3 v = position;                  \n&quot;&#xA;        &quot;   v.z = v.z - movement;               \n&quot;&#xA;        &quot;   v.x = v.x/v.z;                      \n&quot;&#xA;        &quot;   v.y = v.y/v.z;                      \n&quot;&#xA;        &quot;   gl_Position = vec4(v, 1.0f);        \n&quot;&#xA;        &quot;}                                      \n&quot;;&#xA;&#xA;    const GLchar* FRAGMENT_SHADER_SOURCE =&#xA;        &quot;#version 330 core              \n&quot;&#xA;        &quot;                               \n&quot;&#xA;        &quot;in vec3 MyColor;               \n&quot;&#xA;        &quot;                               \n&quot;&#xA;        &quot;out vec4 color;                \n&quot;&#xA;        &quot;                               \n&quot;&#xA;        &quot;void main()                    \n&quot;&#xA;        &quot;{                              \n&quot;&#xA;        &quot;   color = vec4(MyColor,1.0f); \n&quot;&#xA;        &quot;}                              \n&quot;;&#xA;&#xA;    GLuint program;&#xA;    GLuint vertex, fragment;&#xA;&#xA;    vertex = glCreateShader(GL_VERTEX_SHADER);&#xA;    glShaderSource(vertex, 1, &amp;amp;VERTEX_SHADER_SOURCE, NULL);&#xA;    glCompileShader(vertex);&#xA;&#xA;    fragment = glCreateShader(GL_FRAGMENT_SHADER);&#xA;    glShaderSource(fragment, 1, &amp;amp;FRAGMENT_SHADER_SOURCE, NULL);&#xA;    glCompileShader(fragment);&#xA;&#xA;    program = glCreateProgram();&#xA;    glAttachShader(program, vertex);&#xA;    glAttachShader(program, fragment);&#xA;    glLinkProgram(program);&#xA;&#xA;    glDeleteShader(vertex);&#xA;    glDeleteShader(fragment);&#xA;&#xA;    GLfloat uniform = glGetUniformLocation(program, &quot;movement&quot;);&#xA;    glUseProgram(program);&#xA;&#xA;&#xA;&#xA;    //VAOs &amp;amp; VBOs&#xA;    GLfloat vertices[] =&#xA;    {&#xA;             0.25f, -0.25f,  1.0f,      1.0f, 0.0f, 0.0f,&#xA;            -0.25f, -0.25f,  1.0f,      0.0f, 1.0f, 0.0f,&#xA;             0.25f, -0.25f,  1.5f,      0.0f, 0.0f, 1.0f,&#xA;            -0.25f, -0.25f,  1.5f,      1.0f, 1.0f, 0.0f&#xA;    };&#xA;&#xA;    GLuint VAO, VBO;&#xA;    glGenVertexArrays(1, &amp;amp;VAO);&#xA;    glBindVertexArray(VAO);&#xA;    glGenBuffers(1, &amp;amp;VBO);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)0);&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(GLfloat), (GLvoid*)(3*sizeof(GLfloat)));&#xA;    glEnableVertexAttribArray(1);&#xA;&#xA;&#xA;&#xA;    //DRAW&#xA;    GLfloat movement = 0.0f;&#xA;    glfwSetTime(0.0);&#xA;&#xA;    while (!glfwWindowShouldClose(window))&#xA;    {&#xA;        if(movement &amp;gt;= 2.5f)&#xA;            glfwSetTime(0.0);&#xA;        glClear(GL_COLOR_BUFFER_BIT);&#xA;        movement = glfwGetTime()/4;&#xA;        glUniform1f(uniform, movement);&#xA;        glDrawArrays(GL_TRIANGLE_STRIP, 0,4);&#xA;        glfwSwapBuffers(window);&#xA;        glfwPollEvents();&#xA;    }&#xA;&#xA;&#xA;&#xA;    //END&#xA;    glDeleteVertexArrays(1, &amp;amp;VAO);&#xA;    glDeleteBuffers(1, &amp;amp;VBO);&#xA;    glfwTerminate();&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT 2&lt;/strong&gt; The problem was that I believed the vertex shader runs for every point in the square, but instead it only run for the 4 vertex specified. Now the problem is... How can I fix it?&lt;/p&gt;&#xA;" OwnerUserId="5852" LastEditorUserId="5852" LastEditDate="2017-04-28T16:55:31.200" LastActivityDate="2017-05-04T17:47:19.993" Title="Strange behaviour in vertex shader with divisions" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5030" PostTypeId="2" ParentId="5029" CreationDate="2017-04-27T22:19:58.360" Score="4" Body="&lt;p&gt;Going by the code in your vertex shader, the last set of vertices produces the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;( 0.5, -0.5, -0.25) → (-2,  2)&#xA;(-0.5, -0.5, -0.25) → ( 2,  2)&#xA;( 0.5, -0.5,  0.25) → ( 2, -2)&#xA;(-0.5, -0.5,  0.25) → (-2, -2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;…which is a 4×4 square, centered on (0,0), with the points specified in clockwise order (which won’t draw correctly with a triangle strip, as you’re seeing in the above screenshot).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like you’re expecting &lt;code&gt;y&lt;/code&gt; values outside of the [-1, 1] range to not be drawn at all, but all that’s doing is drawing triangles that are larger than the viewport.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2017-04-27T23:14:32.577" LastActivityDate="2017-04-27T23:14:32.577" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5031" PostTypeId="2" ParentId="5027" CreationDate="2017-04-28T01:29:40.230" Score="7" Body="&lt;p&gt;Your first quote is referring to &quot;Split-sum approximation&quot; presented in &quot;&lt;a href=&quot;https://de45xmedrsdbp.cloudfront.net/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real Shading in Unreal Engine 4&lt;/a&gt;&quot; by Brian Karis, and also referred in the paper [Kar13]:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac{1}{N}\sum_{k=1}^N \frac{L_i(l_k)f(l_k,v)cos\theta_{l_k}}{p(l_k,v)}\approx \bigg(\frac{1}{N}\sum_{k=1}^N L_i(l_k)\bigg)\bigg(\frac{1}{N}\sum_{k=1}^N \frac{f(l_k,v)cos\theta_{l_k}}{p(l_k,v)}\bigg)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In split-sum approximation the incident radiance (cubemap) is pre-convolved with GGX kernel using for example importance sampling, and normal-incident specular reflectance ($F_0$ or &quot;specular color&quot; you refer to) is multiplied with another pre-convolved 2D look-up-texture (referred as &quot;an auxiliary specular color map&quot;) shown below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OlGdF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OlGdF.jpg&quot; alt=&quot;Split-Sum 2D LUT&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next about your second question of importance sampling being inefficient due to band-limited signal - It simply means that the incident radiance is sampled with finite resolution (cubemap resolution) and thus higher frequencies have been filtered out. But because importance sampling biases samples to important regions of the function (peak of the GGX BRDF) this region may be sampled in unnecessarily high frequency thus wasting samples.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-04-29T01:37:46.317" LastActivityDate="2017-04-29T01:37:46.317" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5033" PostTypeId="1" CreationDate="2017-04-28T06:54:53.087" Score="3" ViewCount="143" Body="&lt;p&gt;What is the name of effect, that we see on far objects in outdoors ? These objects are low-contrast, foggy ? Is it only fog or some scattering ? &lt;a href=&quot;https://i.stack.imgur.com/1EEw5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1EEw5.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6524" LastActivityDate="2017-04-28T14:00:57.553" Title="What is name for far lowcontrast blueish landspace?" Tags="&lt;rendering&gt;&lt;fog&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5034" PostTypeId="2" ParentId="5033" CreationDate="2017-04-28T08:15:41.523" Score="1" Body="&lt;p&gt;Do you mean &lt;a href=&quot;http://www.thefreedictionary.com/haze&quot; rel=&quot;nofollow noreferrer&quot;&gt;haze&lt;/a&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;FWIW, in Australia the Blue Mountains get their name from the &lt;a href=&quot;http://www.australia.gov.au/about-australia/australian-story/eucalypts&quot; rel=&quot;nofollow noreferrer&quot;&gt;release of oil into the atmosphere from the eucalypts&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-04-28T08:15:41.523" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5035" PostTypeId="2" ParentId="5033" CreationDate="2017-04-28T08:34:48.740" Score="1" Body="&lt;p&gt;As Simon F says, the meterological phenomenon that causes this is &lt;em&gt;haze&lt;/em&gt;. A physicist would call it an example of &lt;em&gt;scattering&lt;/em&gt;, but the visual effect is known as &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Aerial_perspective&quot; rel=&quot;nofollow noreferrer&quot;&gt;aerial perspective&lt;/a&gt;&lt;/em&gt;. Reproducing this in paintings has been a technique since the 15th Century, with Leonardo da Vinci one of the early proponents.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since your question included a nice real-world example, here's a computer graphics example, courtesy of Dave Pape (CC-by) from a &lt;a href=&quot;http://resumbrae.com/ub/dms423_f07/09/&quot; rel=&quot;nofollow noreferrer&quot;&gt;slide deck of techniques for showing depth&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/rT2lh.jpg&quot; alt=&quot;Aerial perspective in GTA&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-04-28T08:34:48.740" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5036" PostTypeId="2" ParentId="5033" CreationDate="2017-04-28T13:53:00.643" Score="5" Body="&lt;p&gt;In computer graphics the effect is called &quot;&lt;a href=&quot;http://www.severewx.com/Radiation/scattering.html&quot; rel=&quot;noreferrer&quot;&gt;atmospheric scattering&lt;/a&gt;&quot;, that's sun light scattering from atoms and other particles in the atmosphere. In modern computer games atmospheric scattering is commonly modelled with &lt;a href=&quot;http://www-evasion.imag.fr/people/Eric.Bruneton/&quot; rel=&quot;noreferrer&quot;&gt;Bruneton sky model&lt;/a&gt; by Eric Bruneton and is most prevalent in the clear sky due to long view distances, but also visible for distant objects on ground as you have observed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/I681a.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/I681a.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Atmospheric scattering in Bruneton model is composed of &lt;a href=&quot;https://en.wikipedia.org/wiki/Mie_scattering&quot; rel=&quot;noreferrer&quot;&gt;Mie scattering&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Rayleigh_scattering&quot; rel=&quot;noreferrer&quot;&gt;Rayleigh scattering&lt;/a&gt;. Mie scattering is mostly wavelength independent strongly anisotropic scattering from particles that are quite a bit larger than the wavelength of light (water droplets &amp;amp; pollution in the atmosphere). Mie scattering results in effects like halo around the sun.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rayleigh scattering on the other hand is wavelength dependent scattering from atoms in the atmosphere whose size is close to the visible light wavelength range. Rayleigh scattering is responsible of effects such as the blueish sky at noon and blueish tint of objects in the distance.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-04-28T14:00:57.553" LastActivityDate="2017-04-28T14:00:57.553" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5037" PostTypeId="2" ParentId="5029" CreationDate="2017-04-28T17:18:44.537" Score="5" Body="&lt;p&gt;The vertex shader only runs per vertex, not for every point in the square. So the four vertices are mapped to (±2, ±2), and then the GPU draws a polygon between those vertices, which does cross the viewport.&lt;/p&gt;&#xA;&lt;p&gt;The points interior to the polygon do not go through the &lt;code&gt;v.y = v.y/v.z&lt;/code&gt; transform, so the resulting point set is not &lt;span class=&quot;math-container&quot;&gt;$(-\infty,-2] \cup [2,\infty)$&lt;/span&gt; after all.&lt;/p&gt;&#xA;&lt;p&gt;For this reason, one can't generally do non-linear geometry transformations in the vertex shader alone—except for perspective projection, which has special hardware support. (You run into this problem as well if you try to do any non-linear camera projection, such as a fisheye projection.) There are two ways to solve it:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Subdivide the geometry into small pieces so that the vertices are closely spaced. Then, applying the nonlinear transform per vertex may be a good-enough approximation.&lt;/p&gt;&#xA;&lt;p&gt;Also, since in your case the transform has a discontinuity at &lt;span class=&quot;math-container&quot;&gt;$z = 0$&lt;/span&gt;, you would need to split the original polygon into two pieces (each with its own set of vertices) where it crosses the &lt;span class=&quot;math-container&quot;&gt;$z = 0$&lt;/span&gt; plane, and push the split vertices away from that plane, so you'd have &lt;span class=&quot;math-container&quot;&gt;$z = \pm \epsilon$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt; is some small number. [It might even work to use IEEE floating point &amp;quot;negative zero&amp;quot; values here; not sure.] Otherwise the pieces that cross &lt;span class=&quot;math-container&quot;&gt;$z = 0$&lt;/span&gt; will cause the same problem all over again.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Do the transform as an image-space process, i.e. in the pixel shader rather than the vertex shader. This is used for example for lens distortion correction in VR: the image is rendered first using an ordinary perspective projection, then resampled to the distorted projection. This requires being able to invert the transform, i.e. map from the destination pixel position back to the corresponding source position, then sampling the source pixel from a texture.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-04-28T17:18:44.537" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5039" PostTypeId="1" AcceptedAnswerId="5045" CreationDate="2017-04-29T16:37:22.760" Score="2" ViewCount="170" Body="&lt;p&gt;I am learning ray tracing and the mathematics behind it.  I have a working monte-carlo raytracer I am experimenting on.  I have gotten past pure diffuse BRDFS, area lights, acceleration structures, etc, and now I'm working on properly sampling the next ray direction from an anisotropic distribution.  I believe I have interpreted the D,G,F factors correctly, and have working tests that verify those function's outputs.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am having trouble with drawing a &quot;wi&quot; sample from the half vector distribution function.   The purpose of the function is to give you a randomized half vector in shading space based on the &quot;incoming&quot; wo ray, which is the eye ray, and a roughness parameter.  As I graph out the function outputs, it seems like the &#xA;half-vector sampling function begins to rotate the spherical coordinates about the wrong axis (I know this makes no sense, but I'm just observing the graphed results).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Knowing that situation, I was hoping some people could post some pointers to good academic articles, open source code examples, or other educational material that could help me investigate and educate myself on the behavior of functions that generate half-vectors from distributions.  I have found plenty of the original source papers from Cook-Torrence, etc that explain their algorithms, but I cannot find any that explain in plain language HOW to generate the half vector for the eye ray to reflect about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: I have also extensively explored PBRT and its source code, all of which has been incredibly enlightening, and I have seen their sample_wi function, i even went so far as to directly copy and translate it to webgl for troubleshooting my functions.  I know i must be doing or interpreting something wrong - I just can't find enough material out there to help me figure out what.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a visualization of only the half vector normals.  They have been put into a range of [0,1] for viewing in the RGB spectrum.  I have also boosted the contrast of the image to make the error more easily visible.  You can clearly see that instead of randomly orienting themselves about the surface normal, they are instead correlating themselves radially about the camera eye-vector.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M6975.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M6975.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPDATE:&lt;br&gt;&#xA;here is a webgl &quot;proof&quot; i put together to isolate and illustrate my problem.  What should happen is the color should be fairly blended together, interpolated rather nicely.  Instead I get this obvious hard shift in the distribution throughout the 4 quadrants: &lt;a href=&quot;http://rdtests.ml3ds-test.com/microfacettesting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://rdtests.ml3ds-test.com/microfacettesting.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The functions referenced by main function here can all be viewed directly in the source code of the page I linked to: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        vec3 finalColor = vec3(0.);&#xA;&#xA;        // create a changing &quot;wo&quot; vector across screen space (simulates perspective ray change)&#xA;        vec2 screenUv = gl_FragCoord.xy / u_resolution;&#xA;        // fire rays into positive z (forward) space from &quot;camera&quot;s&#xA;        float z = 1.;&#xA;&#xA;        vec3 rd = normalize(vec3(screenUv, z));&#xA;&#xA;        // remap 0,1 to -1,1&#xA;        vec3 wo = (rd * 2.) - 1.;&#xA;        // wo is outward facing&#xA;        wo *= -wo;&#xA;&#xA;        // convert wo to spherical coordinates&#xA;        vec3 Nt, Nb;&#xA;        // simulate hitting an infinite plane, facing us like a wall&#xA;        vec3 normal = vec3(0., 0.,-1.);&#xA;        CoordinateSystem(normal, Nt, Nb);&#xA;&#xA;        // put wo into the shading space coordinate system of the &quot;wall&quot; normal&#xA;        vec3 shadingWo = WorldToShading(wo, Nt, Nb, normal);&#xA;&#xA;        // sample half vector distribution from trowbridge-reitz&#xA;        // make random input a constant to allow error to be more clearly seen&#xA;        vec3 wh = Dist_TR_Sample_wh(shadingWo, vec2(.2,.1), .5, .5);&#xA;&#xA;        // Reflect wo about the half vector normal&#xA;        vec3 wi = Reflect(shadingWo, wh);&#xA;&#xA;        // put wi back into cartesian coordinate system&#xA;        vec3 wiWorld = ShadingToWorld(wi, Nt, Nb, normal);&#xA;&#xA;        // now remap wi to a viewable color: 0,1&#xA;        finalColor = normalize((wiWorld + 1.) / 2.);&#xA;&#xA;        gl_FragColor = vec4(finalColor, 1.);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6534" LastEditorUserId="6534" LastEditDate="2017-05-01T22:15:03.717" LastActivityDate="2017-05-02T00:12:46.617" Title="Troubleshoot half vector sampling from a distribution (cook-torrence, trowbridge-reitz, etc)" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;sampling&gt;&lt;monte-carlo&gt;&lt;distribution&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5040" PostTypeId="1" AcceptedAnswerId="5042" CreationDate="2017-04-29T21:26:31.417" Score="8" ViewCount="735" Body="&lt;p&gt;Lately I've been reading about texture filtering, namely Nearest-neighbor filtering, Bilinear filtering, Trilinear filtering, Anisotropic filtering, MIP maps, RIP Maps and so on. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;From a high-level perspective I think I can understand these techniques, how the work and why they exist, with the exception of Anisotropic filtering. Anisotropic filtering is driving me nuts. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can see the problem of having to texturize a surface that is at an angle relative to the camera, but I don't get how sampling trapezoidal footprints could solve this (although I can see the result). This is probably because I DO NOT understand how the trapezoidal footprint is calculated and how the enclosed telexes are weighted to sample the texture. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This article by &lt;a href=&quot;http://www.geforce.com/whats-new/guides/aa-af-guide#1&quot; rel=&quot;noreferrer&quot;&gt;Nvidia&lt;/a&gt; confuses me even more by using sentences as &quot;&lt;em&gt;when a texel is trapezoidal&lt;/em&gt;&quot; or &quot;&lt;em&gt;anisotropic filtering scales either the height or width of a mipmap by a ratio relative to the perspective distortion of the texture&lt;/em&gt;&quot;. Trapezoidal texel? Scaling a MIPmap? What does this even mean?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you help me grasp how AF and AF levels work? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please note that my goal is NOT to have an OpenGL or DirectX AF implementation, but rather to grasp how AF works from a high-level perspective.&lt;/p&gt;&#xA;" OwnerUserId="6535" LastEditorUserId="6535" LastEditDate="2017-04-29T23:47:16.007" LastActivityDate="2017-04-30T03:14:36.227" Title="Help me grasp Anisotropic Filtering (AF)" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;filtering&gt;&lt;directx&gt;&lt;mipmap&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5041" PostTypeId="2" ParentId="5040" CreationDate="2017-04-29T23:28:28.417" Score="3" Body="&lt;p&gt;A few points that you probably already know, but that I just want to put out there for others reading this. Filtering in this case refers to low-pass filtering like you might get from a Gaussian Blur or a box blur. We need to do this because we are taking some media that has high frequencies in it, and rendering it into a smaller space. If we didn't filter it, we would get aliasing artifacts, which would look bad. So we filter out the frequencies that are too high to be accurately reproduced in the scaled version. (And we pass the low frequencies, so we use a &quot;low pass&quot; filter like a blur.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So let's think about this first from the point of view of a blur. A blur is a type of convolution. We take the convolution kernel and multiply it by all the pixels in an area and then add them together and divide by the weight. That gives us the output of one pixel. Then we move it over and do it again for the next pixel over, and again, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's really expensive to do it that way, so there's a way to cheat. Some convolution kernels (particularly a Gaussian blur kernel and a box blur kernel) can be separated into a horizontal and vertical pass. You can filter everything with just a horizontal kernel first, then take the result of that and filter it with just a vertical kernel, and the result will be identical to doing the more expensive calculation at every point. Here's an example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Original:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NFK7C.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NFK7C.jpg&quot; alt=&quot;Hawaii&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Horizontal Blur:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5BbgB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5BbgB.jpg&quot; alt=&quot;Hawaii blurred horizontally&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Horizontal followed by Vertical Blur:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AGa3e.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AGa3e.jpg&quot; alt=&quot;Hawaii blurred horizontally and then vertically&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So we can separate the filtering into a vertical and horizontal pass. So what? Well, it turns out that we can do the same thing for spatial transforms. If you think about a perspective rotation, like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OzqBz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OzqBz.jpg&quot; alt=&quot;Hawaii Rotated around Y-axis&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It can be broken down into an X scale:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/u6orj.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u6orj.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;followed by a scale of each column by a slightly different amount:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FDSRm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FDSRm.jpg&quot; alt=&quot;Hawaii scaled in X and then proportionally in Y&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now you have 2 different scaling operations. To get the filtering correct for this, you're going to want to filter more heavily in X than in Y, and you're going to want to filter by a different amount for each column. The first column gets no filtering because it's the same size as the original. The second column gets just a little because it's just slightly smaller than the first, etc. The last column gets the most filtering of any column.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The word &quot;anisotropy&quot; comes from the greek &quot;an&quot; meaning &quot;not&quot;, &quot;isos&quot; meaning equal, and &quot;tropos&quot; meaning &quot;direction&quot;. So it means &quot;not equal in all directions.&quot; And that's exactly what we see - the scaling and the filtering are done in different amounts in each direction.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-04-29T23:28:28.417" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5042" PostTypeId="2" ParentId="5040" CreationDate="2017-04-30T03:04:03.403" Score="10" Body="&lt;p&gt;To understand the nature of anisotropic filtering, you need to have a firm understanding of what texture mapping really means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The term &quot;texture mapping&quot; means to assign positions on an object to locations in a texture. This permits the rasterizer/shader to, for each position on the object, fetch the corresponding data from the texture. The traditional method for doing this is to assign each vertex on an object a texture coordinate, which directly maps that position to a location in the texture. The rasterizer will interpolate this texture coordinate across the faces of the various triangles to produce the texture coordinate used to fetch the color from the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, let's think about the process of rasterization. How does that work? It takes a triangle and breaks it up into pixel-sized blocks which we will call &quot;fragments&quot;. Now, these pixel-sized blocks are pixel-sized relative to the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But these fragments are not pixel-sized relative to the &lt;em&gt;texture.&lt;/em&gt; Imagine if our rasterizer generated a texture coordinate for each corner of the fragment. Now imagine drawing those 4 corners, not in screen space, but in &lt;em&gt;texture space&lt;/em&gt;. What shape would this be?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, that depends on the texture coordinates. That is, it depends on how the texture is mapped to the polygon. For any particular fragment, it might be an axis-aligned square. It might be a non-axis-aligned square. It might be a rectangle. It might be a trapezoid. It might be pretty much &lt;em&gt;any four-sided figure&lt;/em&gt; (or at least, convex ones).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you were doing texture accessing correctly, the way to get the texture color for a fragment would be to figure out what this rectangle is. Then fetch every texel from the texture within that rectangle (using coverage to scale colors that are on the border). Then average them all together. That would be perfect texture mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would also be &lt;em&gt;exceedingly slow&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the interest of performance, we instead try to approximate the real answer. We base things on one texture coordinate, rather than the 4 that cover the entire fragment's area in texel space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mipmap-based filtering uses lower-resolution images. These images are basically a shortcut for the perfect method, by pre-computing what large blocks of colors would look like when blended together. So when it selects a lower mipmap, it is using pre-computed values where each texel represents an area of the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anisotropic filtering works by approximating the perfect method (which can, and should, be coupled with mipmapping) through taking up to a fixed number of additional samples. But how does it figure out the area in texel space to fetch from, since it's still only given one texture coordinate?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, it cheats. Because fragment shaders are executed in 2x2 neighboring blocks, it is possible to compute the derivative of any value in the fragment shader in screen-space X and Y. It then uses these derivatives, coupled with the actual texture coordinate, to compute an approximation of what the true fragment's texture footprint would be. And then it performs a number of samples within this area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a diagram to help explain it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H9G6E.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H9G6E.png&quot; alt=&quot;Fragment footprint and anisotropic samples. FYI: if you&amp;#39;ve seen it before, it&amp;#39;s mine.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The black-and-white squares represent our texture. It's just a checkerboard of 2x2 white and black texels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The orange dot is the texture coordinate for the fragment in question. The red outline is the fragment's footprint, which is centered on the texture coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The green boxes represent the texels that an anisotropic filtering implementation &lt;em&gt;might&lt;/em&gt; access (the details of anisotropic filtering algorithms are platform specific, so I can only explain the general idea). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This particular diagram suggests that an implementation might access 4 texels. Oh yes, the green boxes cover 7 of them, but the green box in the center could fetch from a smaller mipmap, thus fetching the equivalent of 4 texels in one fetch. The implementation would of course weight the average for that fetch by 4 relative to the single texel ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the anisotropic filtering limit was 2 rather than 4 (or higher), then the implementation would pick 2 of those samples to represent the fragment's footprint.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-04-30T03:14:36.227" LastActivityDate="2017-04-30T03:14:36.227" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5043" PostTypeId="2" ParentId="5028" CreationDate="2017-04-30T11:09:43.513" Score="5" Body="&lt;h1&gt;Forking defeats Russian Roulette&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;A key difference between path tracing and ray tracing is that unlike ray tracing, which can have a branching tree of rays splitting at each intersection, path tracing follows a single path with no recursive branching. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Russian Roulette requires that only one recursive function call be made each time through the function. However, the code currently branches at each function call, so each call triggers several more calls. This prevents the roulette process from killing the recursion. New recursive function calls are being introduced faster than they can be killed off. The problem is similar to a &lt;a href=&quot;https://en.wikipedia.org/wiki/Fork_bomb&quot; rel=&quot;noreferrer&quot;&gt;fork bomb&lt;/a&gt;, growing exponentially, so that the killing cannot keep up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The clue that led me to look for this problem was that you said that it works fine when the number of Monte Carlo samples is set to 1. In this case the function is only called once each time, so the recursion can only maintain the same number of rays, not introduce new ones. So there is no forking and when the recursion is killed that is the end of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want more than one Monte Carlo sample per pixel, you will need to move that loop out of the recursive function so that the number of samples does not grow.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Pseudocode examples&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;Approach 1&lt;/h3&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function RECURSIVE_FUNCTION()&#xA;{&#xA;    RECURSIVE_FUNCTION()&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;This sends 1 ray that bounces around the scene but does not fork.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h3&gt;Approach 2&lt;/h3&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function RECURSIVE_FUNCTION()&#xA;{&#xA;    for(var i = 0; i &amp;lt; 10; ++i)&#xA;    {&#xA;        RECURSIVE_FUNCTION()&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;This sends 10 rays that each spawn 10 new rays, giving 100 rays, then 1000, then 10000...&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If you want 10 samples per pixel, use the function from approach 1, and call it 10 times. Currently the code uses approach 2, which causes far more than 10 samples per pixel, exploding to arbitrarily large numbers of rays until the stack overflows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Note that I've simplified the recursive calls in the pseudocode for the sake of explanation, but the same problem presents itself in the real code:&lt;/em&gt; &lt;code&gt;traceRay&lt;/code&gt; &lt;em&gt;calls&lt;/em&gt; &lt;code&gt;indirectLighting&lt;/code&gt; &lt;em&gt;once, then&lt;/em&gt; &lt;code&gt;indirectLighting&lt;/code&gt; &lt;em&gt;calls&lt;/em&gt; &lt;code&gt;traceRay&lt;/code&gt; &lt;em&gt;multiple times depending on&lt;/em&gt; &lt;code&gt;MC_SAMPLES&lt;/code&gt;&lt;em&gt;, then each of those calls to&lt;/em&gt; &lt;code&gt;traceRay&lt;/code&gt; &lt;em&gt;calls&lt;/em&gt; &lt;code&gt;indirectLighting&lt;/code&gt; &lt;em&gt;again. Each time through this cycle there are&lt;/em&gt; &lt;code&gt;MC_SAMPLES&lt;/code&gt; &lt;em&gt;times as many calls as the previous time, and Russian Roulette cannot cull enough of these calls to prevent runaway growth.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2017-04-30T21:35:32.853" LastActivityDate="2017-04-30T21:35:32.853" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5045" PostTypeId="2" ParentId="5039" CreationDate="2017-05-01T19:19:37.580" Score="3" Body="&lt;p&gt;The general idea for sampling half vector based distributions is that you generate $H$ and then compute $w_i$ by reflecting $w_o$ about $H$. This is so $H$ will be the half vector of your $w_i$ and $w_o$ pair. It is standard reflection:&#xA;$$w_i = -w_o + 2(w_o\cdot H)H $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How you generate $H$ depends on the specific distribution. Generally, it is done in polar coordinates, with the angle from your distribution's center being picked using some specific function. Then the azimuth will be a uniform distribution, unless your distribution is anisotropic, in which case it gets more complicated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, with Cook-Torrance, it goes something like:&#xA;$$\tan \theta = m \sqrt{ - \log \xi_1 }$$&#xA;$$\phi = \xi_2 2\pi$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, given an orthonormal basis made of vectors $N$, $a$, $b$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$H = a\sin\theta\cos\phi + b\sin\theta\sin\phi + N\cos\theta$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for problems in your code, replacing this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 rd = normalize(vec3(screenUv, z));&#xA;&#xA;// remap 0,1 to -1,1&#xA;vec3 wo = (rd * 2.) - 1.;&#xA;// wo is outward facing&#xA;wo *= -wo;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 wo = normalize(vec3(screenUv*2.0-1.0, -z));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Gives me a much nicer plot. Your remapping was incorrect as it was done on a vector which includes z and is no longer in 0,1 for x and y because of the normalization. This explains why the center was not in the center of the frame and the whole thing was leaning. Removing &lt;code&gt;wo *= -wo;&lt;/code&gt; (a transformation which makes no sense) and using &lt;code&gt;-z&lt;/code&gt; instead fixes what I think you were calling the hard transition in the 4 quadrants. That was caused by squaring the components of the vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The remaining glitch in the center appears to be numerical issues. Fixing that will require reworking the code to better handle some cases (likely where you have the &lt;code&gt;0.0008&lt;/code&gt; constant for a sin and the &lt;code&gt;0.9999&lt;/code&gt; for a cos).&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2017-05-02T00:12:46.617" LastActivityDate="2017-05-02T00:12:46.617" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5046" PostTypeId="1" AcceptedAnswerId="5048" CreationDate="2017-05-01T21:07:20.933" Score="6" ViewCount="2998" Body="&lt;p&gt;I've been doing OpenGL tutorials using &lt;a href=&quot;http://learnopengl.com&quot; rel=&quot;noreferrer&quot;&gt;LearnOpenGL&lt;/a&gt;. Currently I'm reading about Stencil Buffers and in his example he uses a Stencil Buffer to draw an outline around an object. I've also read that it can be used to create shadows and reflections. My question is, what are other practical uses for a Stencil Buffer and why were they invented in the first place?&lt;/p&gt;&#xA;" OwnerUserId="6546" LastEditorUserId="48" LastEditDate="2017-05-01T22:25:36.097" LastActivityDate="2017-05-03T08:50:54.200" Title="Uses for Stencil Buffer" Tags="&lt;opengl&gt;&lt;stencil-buffer&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5048" PostTypeId="2" ParentId="5046" CreationDate="2017-05-02T13:17:49.447" Score="11" Body="&lt;p&gt;The original use for the stencil buffer was for non-3D content. Say you're making a 3D game. Most of the screen is the 3D content, but you also have some GUI around the outside which is not drawn through OpenGL but through a 2D canvas API. You can mask off the shape of the 2D GUI using the stencil buffer, and then make sure that your 3D/OpenGL content won't affect it and won't cause overdraw (which wastes fragment shading time).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you've seen, it's also used for techniques like shadow volumes and some reflection techniques. In general, it can be used for techniques where you draw an object and then want to run another fragment shader (or some more draw calls) to alter that object's appearance, by adding reflections, lighting, or screen-space effects. In that case, when you draw the object the first time, it's very cheap to fill the stencil buffer at the same time. Then, your later pass (to add the reflections or whatever) can use the stencil test to only run on those fragments that eventually did get drawn on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another common use is when rendering a scene in multiple parts. For example, in a flight simulator, it's common for the cockpit (and aircraft exterior) and the terrain (and other aircraft) to be done in completely separate passes. This lets you use a lower-precision depth buffer without causing z fighting, because you can use different depth ranges for the near content and the far content. But if you do this, you can't reuse the same depth values for both passes. In this case, you can fill the stencil buffer when you're drawing the cockpit, and use the stencil test to avoid overdrawing the cockpit when you draw the terrain. (You need to do more to handle glass effects on the cockpit windows: this description is an oversimplification.) You can use similar techniques for drawing the player's weapon and/or hands in first-person shooters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stencil buffer is used in many techniques: too many to list them all individually. But in general, if you want to have some render passes only affect some fragments, and the fragments you want to affect are those corresponding to particular objects or shaders, then the stencil buffer is a cheap way to enable that.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-05-02T13:17:49.447" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5049" PostTypeId="1" AcceptedAnswerId="5051" CreationDate="2017-05-02T14:36:12.060" Score="4" ViewCount="253" Body="&lt;p&gt;I'm trying to figure out why the probability density function for picking a direction uniformly on the hemisphere is $\frac{1}{2\pi}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something tells me this is related to the number of steradians in a hemisphere being $2\pi$, but I can't see how this is connected. We could come up with another measure for solid angle (&quot;blibs&quot; for example) where the number of blibs in the hemisphere would be $8000\pi$, but I'd expect the probability for picking a direction uniformly to be unchanged.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: I understand this now. My confusion arose because I wasn't thinking clearly about the &lt;strong&gt;units&lt;/strong&gt; of the probability density function, i.e. $\frac{1}{sr}$. I got thrown off by thinking of area, and confusingly thought the pdf units were inverse area (or something)!&lt;/p&gt;&#xA;" OwnerUserId="2941" LastEditorUserId="2941" LastEditDate="2017-05-17T14:24:36.460" LastActivityDate="2017-05-17T14:24:36.460" Title="Why is $pdf(\Psi) = \frac{1}{2\pi}$ when picking from hemisphere uniformly?" Tags="&lt;mathematics&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5050" PostTypeId="2" ParentId="5049" CreationDate="2017-05-02T15:52:36.140" Score="5" Body="&lt;p&gt;It's like this because the surface area of a unit sphere is $4\pi$. As ratchet freak points out, the integral of a probability distribution over its domain has to be 1. Put another way, the probability of choosing some direction is 1. The surface area of the hemisphere is $2\pi$. The constant that you integrate over a $2\pi$ domain to get 1 is $\frac{1}{2\pi}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The connection to steradians is that 1 steradian is defined as the solid angle that subtends a surface of area 1 on a unit sphere. That is, a unit sphere has $4\pi$ steradians and a surface area of $4\pi$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's just the same in two dimensions. A radian is chosen so that a 1 radian arc of a unit circle has length 1, so there are $2\pi$ radians in a circle, and $\pi$ radians in a semicircle. If you choose 2D directions uniformly on a semicircle, the probability distribution is $\frac{1}{\pi}$.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-05-02T15:52:36.140" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5051" PostTypeId="2" ParentId="5049" CreationDate="2017-05-02T16:38:40.207" Score="5" Body="&lt;p&gt;Actually, it would change if you changed units in the $\textit{pdf}$ definition. The fundamental reason is that the $\textit{pdf}$ is defined as the probability per steradian. That's what the density part means. You could very well redefine it as the probability per hemisphere and end up with a $\textit{pdf}$ of $1$ for your example.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2017-05-02T17:49:07.707" LastActivityDate="2017-05-02T17:49:07.707" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5052" PostTypeId="2" ParentId="5046" CreationDate="2017-05-03T08:25:02.333" Score="5" Body="&lt;p&gt;Another use, that I think Dan didn't mention, is for filling non-convex polygons, e.g,&#xA;&lt;a href=&quot;https://i.stack.imgur.com/i3eZb.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/i3eZb.jpg&quot; alt=&quot;Concavities&quot;&gt;&lt;/a&gt; and &lt;a href=&quot;https://i.stack.imgur.com/fEApM.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fEApM.jpg&quot; alt=&quot;Self intersections&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stencil can be used to implement the fill rule which is typically either &lt;em&gt;odd/even&lt;/em&gt; (as used in these examples) or &lt;em&gt;non-zero&lt;/em&gt;, simply by, say, treating the list of vertices as a triangle fan or, with reordering, a triangle strip, and setting the stencil appropriately. Finally an enclosing object is drawn but restricted to just those pixels that match the appropriate rule. One catch, if you use the non-zero rule, is that you don't want to &quot;overflow&quot; the max stencil value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If, however, you are going to draw the same polygon repeatedly (with or without transformations), it might be more efficient to first apply a triangulation algorithm, which would eliminate the wasted overdraw. (FWIW the supplied images come from a triangulation algorithm I worked on about a decade ago for SVG/OpenVG.)&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-05-03T08:50:54.200" LastActivityDate="2017-05-03T08:50:54.200" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5053" PostTypeId="1" CreationDate="2017-05-03T15:27:52.273" Score="3" ViewCount="311" Body="&lt;p&gt;I am attempting to visualize the raw output from PBRT's half-vector sampling function, based on the trowbridge-reitz distribution.  I'm isolating only the distribution and the associated functions necessary to sample it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The function is based on the standard GGX half vector sampling formula: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\theta_s = arctan(\frac{\alpha_g\sqrt{\xi_1}}{\sqrt{1-\xi_1}})$$&#xA;$$\phi_s = 2\pi\xi_2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(from Walter GGX: &lt;a href=&quot;http://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but the PBRT version has a lot more black magic related to importance sampling only directions that make significant contributions based on the incoming &quot;wo&quot; angle.  That one detail is making it hard for me to find published papers which specify how to add this directional importance sampling to the standard GGX sampling function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, these angles come back from the sampling function as a vector 3 and spherical coordinates with $$Normalize([\theta_s,\phi_s, 1.0])$$ which should perturb the surface normal, creating the half vector to reflect around.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At this point I am only trying to make sense of the output from the &quot;sample wh&quot; function.  To visualize the results (raw &quot;wh&quot; output) I made a little graphics utility to output the results to a &quot;normal map&quot;.  Here is the output:&lt;a href=&quot;https://i.stack.imgur.com/0G3ei.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0G3ei.jpg&quot; alt=&quot;GGX half vector samples&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And a live webgl example here that continually runs new random numbers through the output (as if monte carlo sampling were running): &lt;a href=&quot;http://rdtests.ml3ds-test.com/microfacettesting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://rdtests.ml3ds-test.com/microfacettesting.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My expectation of the output would be a somewhat smooth gradient blend of the wh orientations as the x and y slopes cross into each other.  But what i'm seeing is an area between the 2 axes that doesn't want to blend well.  The random noise is good/expected, but you can see that inside the x/y blend areas, even the noise becomes fairly non-random.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone give me some tips on what the half vector sampling &lt;em&gt;should&lt;/em&gt; graph like, or some pointers to papers/published work that I can use to locate test data, graphs, or other educational material that could help me figure this out?  &lt;/p&gt;&#xA;" OwnerUserId="6534" LastEditorUserId="6534" LastEditDate="2017-05-03T16:07:52.830" LastActivityDate="2017-05-03T18:05:42.833" Title="Visualize the output of a Trowbridge-Reitz Half Vector Sampling Function" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;sampling&gt;&lt;distribution&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5054" PostTypeId="1" AcceptedAnswerId="5058" CreationDate="2017-05-03T16:54:57.977" Score="4" ViewCount="1443" Body="&lt;p&gt;So ordinarily we have this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W7GLv.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W7GLv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I'm after this!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3bVXX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3bVXX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to do this? Ideally by changing the projection matrix?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reasoning is kinda interesting - I am developing for mobile VR, and I have found that putting my phone (and surely many others) in headsets that are too wide for them makes its so that your horizontal perspective convergence point is in the wrong place.&lt;/p&gt;&#xA;" OwnerUserId="6560" LastActivityDate="2017-05-03T21:12:54.930" Title="Render with camera perspective off-center" Tags="&lt;projections&gt;&lt;perspective&gt;&lt;matrix&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5056" PostTypeId="2" ParentId="5053" CreationDate="2017-05-03T18:05:42.833" Score="2" Body="&lt;p&gt;So for anyone who was interested - after studying the source material by Walter, I became convinced the error had to be in the rotation of the slopes back into &quot;normal shading space&quot;.  PBRT does this in a one-liner: &quot;CosPhi(wiStretched) * slope_x - SinPhi(wiStretched) * slope_y;&quot; etc etc.  I had split it out into separate sinTheta, sinPhi, sinPhiX steps.  One of those steps wasn't correct so the rotation wasn't unstreching correctly.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the correct visualization for a GGX normal distribution of half vectors is this: &#xA;&lt;a href=&quot;https://i.stack.imgur.com/rcyw8.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rcyw8.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6534" LastActivityDate="2017-05-03T18:05:42.833" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5057" PostTypeId="1" AcceptedAnswerId="5060" CreationDate="2017-05-03T19:43:39.773" Score="3" ViewCount="499" Body="&lt;p&gt;In &lt;a href=&quot;https://www.youtube.com/watch?v=cWSdORU-Gnk&quot; rel=&quot;nofollow noreferrer&quot;&gt;my real time ray tracer&lt;/a&gt;, I shoot primary rays from the eye, and at hit points, I trace to a single light source to determine if the object is shadowed or lit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pretty straightforward stuff so far.&#xA;However I have recently added perfect mirrors to my scene.&#xA;The reflections work just fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the shadow calculation breaks down!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A shadowed point could still be lit by the light source via a mirror.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an easy way to handle shadow rays towards bounced light?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NOTE: I am not talking about the projection visible in the mirror surface: this shows shadowed and lit objects. But the directly visible scene itself, there are more shadowed objects than there should be, as some of the scene is lit via a mirror.&lt;/p&gt;&#xA;" OwnerUserId="6562" LastActivityDate="2017-05-04T00:36:54.467" Title="Tracing shadow rays in a scene with mirrors" Tags="&lt;raytracing&gt;&lt;shadow&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5058" PostTypeId="2" ParentId="5054" CreationDate="2017-05-03T21:12:54.930" Score="6" Body="&lt;p&gt;Yes, you can use an off-axis projection matrix.&#xA;This is what I use in my code (note: I shift the centre upwards, not left as you do in your example.)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void camera_setAspectRatio(float aspect, float zNear, float zFar, bool offaxis)&#xA;{&#xA;        // create a projection matrix&#xA;        const float f = 1.0f / tanf(fovy_radians/2.0f);&#xA;        fovx_radians = 2.0f * atanf( aspect * tanf(fovy_radians/2.0f) );&#xA;        float* mout = proj.data;&#xA;&#xA;        mout[0] = f / aspect;&#xA;        mout[1] = 0.0f;&#xA;        mout[2] = 0.0f;&#xA;        mout[3] = 0.0f;&#xA;&#xA;        mout[4] = 0.0f;&#xA;        mout[5] = f;&#xA;        mout[6] = 0.0f;&#xA;        mout[7] = 0.0f;&#xA;&#xA;        mout[8] = 0.0f;&#xA;        mout[9] = offaxis ? -0.25f : 0.0f; // off axis projection!&#xA;        mout[10] = (zFar+zNear) / (zNear-zFar);&#xA;        mout[11] = -1.0f;&#xA;&#xA;        mout[12] = 0.0f;&#xA;        mout[13] = 0.0f;&#xA;        mout[14] = 2 * zFar * zNear /  (zNear-zFar);&#xA;        mout[15] = 0.0f;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Stereo Projection screens (not head-mounted) tend to use Off-Axis projection matrices as well. &lt;a href=&quot;http://paulbourke.net/stereographics/stereorender/&quot; rel=&quot;noreferrer&quot;&gt;Paul Bourke&lt;/a&gt; has a great write up on these projections.&lt;/p&gt;&#xA;" OwnerUserId="6562" LastActivityDate="2017-05-03T21:12:54.930" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5059" PostTypeId="1" AcceptedAnswerId="8985" CreationDate="2017-05-03T23:35:40.103" Score="10" ViewCount="3039" Body="&lt;p&gt;More out of curiosity than for any practical purpose, I'm wondering what is lacking from older GPUs that causes them to be unable to support Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that some argue that some hardware, such as nVidia's Fermi series of GPUs, could support Vulkan in hardware but the vendors simply won't implement it for business reasons, but even disregarding that, there is obviously some most recent hardware that really doesn't support Vulkan, and I'm curious what they lack. Like, say, the nVidia Tesla GPUs, AMD's TeraScale (VLIW) GPUs, or Intel's Gen8 hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm mostly curious in knowing if the features in Vulkan that precludes support for these GPUs are somewhat &quot;peripheral&quot; in the API (like, say, required support for some particular texture format that the API &lt;em&gt;could&lt;/em&gt; have just as well not required but did anyway to create a baseline that was considered reasonable), or if it's truly central to the Vulkan model.&lt;/p&gt;&#xA;" OwnerUserId="6567" LastActivityDate="2020-06-20T13:10:56.007" Title="What prevents older GPUs from supporting Vulkan?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="14" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5060" PostTypeId="2" ParentId="5057" CreationDate="2017-05-04T00:36:54.467" Score="5" Body="&lt;p&gt;It depends how you define easy and what kind of constraints you have. The general case of this is rendering caustics but that's probably not what you're looking for if real time is your target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your mirrors are always flat as in your demo and you only want to support a single bounce, the easiest I can see would be to reflect your light sources on the other side of the mirror's plane, before you start a frame. Let's call each reflection a virtual light source. Then for each of these, test if the ray between whatever you're shading and the virtual light source hits inside the mirror (simple plane/ray test). If it does hit then you trace the actual shadow ray to the mirror and the rest of the shadow ray from the mirror to the actual light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This obviously won't scale well to many mirrors. I think it could be adapted to 2-3 bounces if the mirror and light count is low. The number of virtual lights could quickly grow out of hand though.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-05-04T00:36:54.467" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5062" PostTypeId="1" CreationDate="2017-05-04T11:53:38.683" Score="2" ViewCount="49" Body="&lt;p&gt;I have been looking for an algorithm that evaluates a shared complex edge between two objects to determine which of the two is 'facing inwards', which can then be simplified by converting the edge in a straight line. In my situation the adjusted object will be painted beneath the unmodified object, and thus will have no visual effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image below illustrates what I want to achieve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/rOWdGOUl.png&quot; alt=&quot;example&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is anyone aware of an algorithm that does this?&lt;/p&gt;&#xA;" OwnerUserId="6572" LastActivityDate="2017-05-04T11:53:38.683" Title="Algorithm for shared complex edge simplification" Tags="&lt;compression&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5063" PostTypeId="1" AcceptedAnswerId="5069" CreationDate="2017-05-05T06:48:27.043" Score="1" ViewCount="8780" Body="&lt;p&gt;I've been following the &lt;a href=&quot;https://learnopengl.com/code_viewer.php?code=advanced-lighting/normal_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;LearnOpenGL&lt;/a&gt; tutorials and I've come across a piece of code I don't understand.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glUniform1i(glGetUniformLocation(ShaderID, &quot;textureVar&quot;), 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In the above code &lt;em&gt;ShaderID&lt;/em&gt; is a &lt;em&gt;GLuint&lt;/em&gt; which references a shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;textureVar&lt;/em&gt; is a &lt;em&gt;sampler2D&lt;/em&gt; in the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand the last parameter in that line of code. Does the &lt;em&gt;0&lt;/em&gt; represent &lt;strong&gt;GL_TEXTURE0&lt;/strong&gt; or what exactly does the last parameter mean?&lt;/p&gt;&#xA;" OwnerUserId="6546" LastActivityDate="2017-05-07T07:51:13.510" Title="Send Texture to Shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5064" PostTypeId="1" CreationDate="2017-05-05T09:51:46.833" Score="0" ViewCount="61" Body="&lt;p&gt;What would cause this grayscaled backside?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mkpo3.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mkpo3.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When my camera is behind my model I see a grayscale specular highlight. However, in front of it is perfectly fine. Here's my shading code. (Software rendering)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  // diffuse cosines&#xA;  float diffVal1 = MathHelper::Dot(n1, dirLight);&#xA;  float diffVal2 = MathHelper::Dot(n2, dirLight);&#xA;  float diffVal3 = MathHelper::Dot(n3, dirLight);&#xA;&#xA;  // Get the specular shade&#xA;  // Reflectance vectors&#xA;  float3 r1 = dirLight - n1 * 2 * diffVal1;&#xA;  float3 r2 = dirLight - n2 * 2 * diffVal2;&#xA;  float3 r3 = dirLight - n3 * 2 * diffVal3;&#xA;&#xA;  float spec1 = pow(MathHelper::Dot(r1, cam-&amp;gt;GetViewDir()), mesh-&amp;gt;mat-&amp;gt;specularShine);    &#xA;  float spec2 = pow(MathHelper::Dot(r2, cam-&amp;gt;GetViewDir()), mesh-&amp;gt;mat-&amp;gt;specularShine);&#xA;  float spec3 = pow(MathHelper::Dot(r3, cam-&amp;gt;GetViewDir()), mesh-&amp;gt;mat-&amp;gt;specularShine);&#xA;&#xA;  Color col1 = mesh-&amp;gt;mat-&amp;gt;diffuse * Utility::Saturate(diff1) + mesh-&amp;gt;mat-&amp;gt;specular * Utility::Saturate(spec1) + mesh-&amp;gt;mat-&amp;gt;ambient;&#xA;  Color col2 = mesh-&amp;gt;mat-&amp;gt;diffuse * Utility::Saturate(diff2) + mesh-&amp;gt;mat-&amp;gt;specular * Utility::Saturate(spec2) + mesh-&amp;gt;mat-&amp;gt;ambient;&#xA;  Color col3 = mesh-&amp;gt;mat-&amp;gt;diffuse * Utility::Saturate(diff3) + mesh-&amp;gt;mat-&amp;gt;specular * Utility::Saturate(spec3) + mesh-&amp;gt;mat-&amp;gt;ambient);&#xA;&#xA;  DrawBaryTriangle(screen, triangle, col1, col2, col3);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It's simply &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Diffuse Color * Sat(diffuseVal) + Specular Color * Sat(specularVal) + Ambient Color&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where Sat clamps any color values to [0, 255] and any scalars [0, 1].&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2017-05-05T10:22:55.370" LastActivityDate="2017-05-05T10:22:55.370" Title="Specular Highlight Gray When Behind Model" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;lighting&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5065" PostTypeId="2" ParentId="5063" CreationDate="2017-05-05T15:35:38.160" Score="0" Body="&lt;p&gt;As was stated by @PaulHK, the last parameter represents the Texture Unit the texture is bound to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint unit = 0;&#xA;&#xA;glActiveTexture(GL_TEXTURE0 + unit);&#xA;glBindTexture(GL_TEXTURE_2D, texture);&#xA;glUniform1i(glGetUniformLocation(shaderRef, &quot;texture1&quot;), unit);&#xA;&#xA;unit = 1;&#xA;&#xA;glActiveTexture(GL_TEXTURE0 + unit);&#xA;glBindTexture(GL_TEXTURE_2D, texture2);&#xA;glUniform1i(glGetUniformLocation(shaderRef, &quot;texture2&quot;), unit);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The above code binds Texture Unit 0 to the fragment shader and then sends it texture1. Then it binds Texture Unit 1 to the shader and sends it texture2. The &lt;code&gt;unit&lt;/code&gt; var represents the Texture Unit we are binding to the &lt;code&gt;sampler&lt;/code&gt; in the shader to.&lt;/p&gt;&#xA;" OwnerUserId="6546" LastEditorUserId="6546" LastEditDate="2017-05-06T16:53:38.740" LastActivityDate="2017-05-06T16:53:38.740" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5067" PostTypeId="1" AcceptedAnswerId="5081" CreationDate="2017-05-05T19:43:44.567" Score="3" ViewCount="1126" Body="&lt;p&gt;I implemented a Phong shader in GLSL, but there is a bug.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What you are (supposed) to see down below:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;A point light source rotating around the center of the world,&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;with a &lt;strong&gt;radiance of (0, 100, 0)&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A textured quad with &lt;strong&gt;kd of (1, 0, 0)&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The problem is:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Why is there a a &lt;strong&gt;green line to the center of the world&lt;/strong&gt; instead of a &lt;strong&gt;green spot light where the quad is lit&lt;/strong&gt;? (where the center of the point light source is)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;(Btw in this case there would be only a yellow spot of light, because red + green = yellow)&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oPH5d.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oPH5d.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Vertex Shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330&#xA;&#xA;uniform mat4 ModelMatrix, ViewMatrix, ProjectionMatrix;   &#xA;&#xA;uniform vec4 wLiPos[5];       // pos of light source &#xA;uniform vec3 wEye;         // pos of eye&#xA;uniform int lightSize;      //number of lights&#xA;&#xA;layout(location = 0) in vec3 vtxPos;&#xA;layout(location = 1) in vec3 vtxNorm;&#xA;layout(location = 2) in vec2 vtxUV;&#xA;&#xA;out vec2 texCoord;&#xA;out vec3 wNormal;           // normal in world space&#xA;out vec3 wView[5];             // view in world space&#xA;out vec3 wLight[5];            // light dir in world space&#xA;&#xA;void main() {&#xA;    gl_Position = ProjectionMatrix * ViewMatrix * ModelMatrix * vec4(vtxPos, 1);&#xA;    texCoord = vtxUV;&#xA;    vec4 wPos = ModelMatrix * vec4(vtxPos, 1);&#xA;    wNormal = (vec4(vtxNorm, 0) * inverse(ModelMatrix)).xyz;&#xA;    for(int i = 0; i &amp;lt; lightSize; i++) {&#xA;        wView[i] = wEye * wPos.w - wPos.xyz;&#xA;        wLight[i] = wLiPos[i].xyz * wPos.w - wPos.xyz * wLiPos[i].w;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Fragment shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330&#xA;&#xA;uniform sampler2D samplerUnit;&#xA;&#xA;uniform vec3 kd, ks, ka;   // diffuse, specular, ambient ref&#xA;uniform vec3 La, Le[5];    // ambient and point source rad&#xA;uniform float shininess;    // shininess for specular ref&#xA;uniform int lightSize;&#xA;&#xA;in vec2 texCoord;    &#xA;in vec3 wNormal;       // interpolated world sp normal&#xA;in vec3 wView[5];         // interpolated world sp view&#xA;in vec3 wLight[5];        // interpolated world sp illum dir&#xA;&#xA;&#xA;layout(location = 0) out vec4 fragmentColor;&#xA;&#xA;void main() {     &#xA;    vec3 color = vec3(0, 0, 0);&#xA;    for(int i = 0; i &amp;lt; lightSize; i++) {&#xA;        vec3 N = normalize(wNormal);&#xA;        vec3 V = normalize(wView[i]);&#xA;        vec3 L = normalize(wLight[i]);&#xA;        vec3 H = normalize(L + V);&#xA;        float cost = max(dot(N,L), 0);&#xA;        float cosd = max(dot(N,H), 0);&#xA;        color += ka * La + (kd * cost + (ks * pow(cosd, shininess)) * Le[i]) / pow(length(wLight[i]), 2);&#xA;    }&#xA;    vec3 gamma = vec3(1.0/2.2);&#xA;    fragmentColor = vec4(pow(color * vec3(texture2D(samplerUnit, texCoord)), gamma), 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5609" LastEditorUserId="5609" LastEditDate="2017-05-07T14:16:56.003" LastActivityDate="2017-05-09T09:48:45.650" Title="Phong shading in OpenGL: line of light from the center of the world" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="12" ContentLicense="CC BY-SA 3.0" />
  <row Id="5068" PostTypeId="1" AcceptedAnswerId="5077" CreationDate="2017-05-06T09:57:20.703" Score="5" ViewCount="631" Body="&lt;p&gt;I have multiple reflection cube map that's prebaked before a scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I am being confused as to which one to choose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am told I need to choose &quot;closest cube map&quot; then use it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However it is unclear to me that whether I should do that based off of per pixel or per object(object's position).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I looked at Unity to get some ideas as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unity chooses a reflection probe based off of distance and area probe affects the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However there is no clear &quot;do this&quot;. So I am tentative and left unsure.&lt;/p&gt;&#xA;" OwnerUserId="6282" LastActivityDate="2017-05-08T18:43:25.410" Title="How to choose which reflection probe to use?" Tags="&lt;reflection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5069" PostTypeId="2" ParentId="5063" CreationDate="2017-05-06T19:04:47.600" Score="2" Body="&lt;p&gt;Yes, the &lt;code&gt;0&lt;/code&gt; in there represents the &lt;strong&gt;texture unit that the sampler references&lt;/strong&gt;. So in order for a texture to be referenced by &lt;code&gt;textureVar&lt;/code&gt; in the shader, it should be bound to texture unit 0 (e.g. by &lt;code&gt;glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ...)&lt;/code&gt; or any other means you can bind a texture to a texture unit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, note that it &lt;strong&gt;doesn't actually matter which texture unit is active when setting that uniform, nor what texture is bound to that unit&lt;/strong&gt;. Effectively to the outside world the sampler uniform is just an integer value specifying the texture unit to take its texture and sampler information from. It can be set to that texture unit whenever you want and the texture can be bound to that unit whenever you want (in fact in GLSL 4.20+ you can actually initialize the uniform right in the shader with e.g. &lt;code&gt;layout(binding=0) uniform sampler2D textureVar&lt;/code&gt;). All that matters is that at the point the shader gets invoked (i.e. when actually &lt;code&gt;glDraw...&lt;/code&gt;ing something) the sampler is set to the proper unit and the texture is bound to that unit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information on the matter, take a look at the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Sampler_(GLSL)#Binding_textures_to_samplers&quot; rel=&quot;nofollow noreferrer&quot;&gt;corresponding section in the OpenGL Wiki&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="231" LastEditDate="2017-05-07T07:51:13.510" LastActivityDate="2017-05-07T07:51:13.510" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5070" PostTypeId="1" AcceptedAnswerId="5075" CreationDate="2017-05-07T03:44:31.897" Score="1" ViewCount="666" Body="&lt;p&gt;I'm on OpenGL ES 3.0 using Mesa 17.0.3. When calling &#xA;&lt;code&gt;glDrawArrays(GL_TRIANGLE_FAN, 0, 4)&lt;/code&gt;, &#xA;&lt;code&gt;glGetError()&lt;/code&gt; returns &lt;code&gt;GL_INVALID_ENUM&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have no idea what's causing it and &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glDrawArrays.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glDrawArrays.xhtml&lt;/a&gt; is claiming that GL_TRIANGLE_FAN is an accepted value for &lt;code&gt;mode&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm checking for GL errors immediately before the call, and everything's fine then.&lt;/p&gt;&#xA;" OwnerUserId="6579" LastActivityDate="2018-04-24T07:45:34.880" Title="glDrawArrays is failing with GL_INVALID_ENUM" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5071" PostTypeId="1" CreationDate="2017-05-07T12:46:08.733" Score="2" ViewCount="1023" Body="&lt;p&gt;I have a task to join two bezier curves, so that the resulting curve is two-times continuously differentiable.&lt;br&gt;&#xA;I have the cubic bezier Curve C with control points:&lt;br&gt;&#xA;c0 = (1,1)&lt;br&gt;&#xA;c1 = (3,4)&lt;br&gt;&#xA;c2 = (7,5)&lt;br&gt;&#xA;c3 = (8,2)&lt;br&gt;&#xA;I shall continue this curve C with Curve D from control point c3 to a control point d3 = (12,1) so that this curve is two-times continuously differentiable.&lt;br&gt;&#xA;First Task: Determine control points d0, d1, d1 for the new curve.&#xA;Second Task: Specify a pecewise defined formula for the new curve G(v) with v out of [0,1] that passes through c0,c3 and d3. Thus connect curves C and D in v = 1/2.&#xA;Third Task: Prove by calculation that the transition between C and D is two-times continuously differentiable.&lt;br&gt;&lt;br&gt;&#xA;Regarding first task: I don't know how to determine the points. Can someone help to do this? The rest of the tasks is then maybe something easier to do for me.&lt;/p&gt;&#xA;" OwnerUserId="6583" LastEditorUserId="231" LastEditDate="2017-05-08T06:49:00.107" LastActivityDate="2017-05-08T06:49:00.107" Title="Join two bezier curves so that the result is two-times continuously differentiable" Tags="&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5072" PostTypeId="1" CreationDate="2017-05-07T22:46:57.750" Score="4" ViewCount="1334" Body="&lt;p&gt;I'm currently enrolled in an entry level Computer Graphics class, and as I'm studying for my final, I realize I have a question regarding the Cohen-Sutherland line clipping algorithm. I understand the basics of the algorithm, such as how to compute the 4-bit outcodes associated with each region and the test conditions for the endpoints of a line segment, but where I'm struggling is how to determine what the worst case scenario is for the algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;I've had the following question on both my midterm and a homework assignment: &quot;Draw two line segments (one with a positive slope and one with a negative slope) that reflect the worst case scenarios for the corresponding checking order.&quot;&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following image file shows what the checking order was for each question, along with my original answers to the questions followed by the correct answers. If anyone could point me in the right direction, it would be greatly appreciated. The only &quot;answer&quot; from my professor I received when asking for an explanation was &quot;the worst case has to do with the checking order&quot;, and that answers absolutely nothing for me.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/212kU.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/212kU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6589" LastActivityDate="2017-05-10T13:45:00.500" Title="Worst Case Scenario for Cohen-Sutherland Line Clipping Algorithm" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5074" PostTypeId="2" ParentId="5071" CreationDate="2017-05-08T05:10:40.827" Score="3" Body="&lt;p&gt;For 2 bezier curves to connect and be continuous at all, the last control point of the first curve (C in your case) must be the same as the first control point of the next curve (D). So c3 has to equal d0. That gives you &lt;a href=&quot;https://en.wikipedia.org/wiki/Smoothness&quot; rel=&quot;nofollow noreferrer&quot;&gt;C0 continuity&lt;/a&gt; or positional continuity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next step is to make sure that the tangents where the 2 curves meet are the same. That will ensure c1 continuity. (That is continuity of the first derivatives of the 2 curves.) To do this, the slope must be equal at both points. In order to do that, you need to ensure that the line from c2 to c3/d0 is continuous with the line from c3/d0 to d1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know of a good way to describe C2 continuity, but this &lt;a href=&quot;https://stackoverflow.com/questions/12295773/joining-two-b%C3%A9zier-curves-smoothly-c2-continuous&quot;&gt;Stack Overflow answer&lt;/a&gt; describes it better than I could. That answer should also explain the calculation you need for your proof.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="-1" LastEditDate="2017-05-23T12:39:19.850" LastActivityDate="2017-05-08T05:10:40.827" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5075" PostTypeId="2" ParentId="5070" CreationDate="2017-05-08T05:21:21.710" Score="1" Body="&lt;p&gt;I used &lt;code&gt;MESA_DEBUG=1&lt;/code&gt; (&lt;a href=&quot;https://www.mesa3d.org/debugging.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Debugging Tips | mesa3d.org&lt;/a&gt;, &lt;a href=&quot;https://www.mesa3d.org/envvars.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Environment Variables | mesa3d.org&lt;/a&gt;) and found out that &lt;code&gt;glEnable(TEXTURE_2D)&lt;/code&gt; was causing the error.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know why it only got triggered on the &lt;code&gt;glDrawArrays&lt;/code&gt; (maybe weird bindings) but when I removed that call it no longer failed with &lt;code&gt;GL_INVALID_ENUM&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6579" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:45:34.880" LastActivityDate="2018-04-24T07:45:34.880" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5077" PostTypeId="2" ParentId="5068" CreationDate="2017-05-08T18:43:25.410" Score="4" Body="&lt;p&gt;Are you trying to make your own rendering engine?   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a solution that prioritizes visual quality ; it is slightly more complex than the object-based solution you are referring to.&lt;br&gt;&#xA;For better visual quality your shading should be on a per-pixel basis.&lt;br&gt;&#xA;(If you highly prioritize performance, or do not require detailed reflections, you should probably stick to the object-based solution though).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are doing deferred rendering, instead of selecting only a single cubemap for each pixel, you can use a formula that combines all the cubemaps that are close enough to a pixel.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A trick sometimes used to achieve this is to add a pass that computes the number of cubemaps that affect a single pixel (so you can do averages in the final shading pass).&lt;br&gt;&#xA;If you are doing forward rendering for transparent objects for example, I think it might be a bit trickier to compute the average of cubemaps.&lt;br&gt;&#xA;That's because you need to have pixel positions already available before shading ; you might think it could be possible to do it if you had a kind of depth pre-pass buffer for that purpose, however for transparent objects you usually do not want to write their depth in that buffer, because this leads to artifacts when transparent objects are overlapping.&lt;br&gt;&#xA;You would therefore need to have a rather complex logic to handle those cases...  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However even with forward rendering you can still select the closest cubemap on a per-pixel basis, although without the &quot;averaging&quot; formula the transitions between the boundaries of two cubemap influence zones will be very visible and reflections will not look realistic.&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2017-05-08T18:43:25.410" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5078" PostTypeId="1" AcceptedAnswerId="5079" CreationDate="2017-05-09T02:54:07.127" Score="2" ViewCount="84" Body="&lt;p&gt;I am trying to recreate a filter that Facebook released back in 2015 when gay marriage was legalized in the US.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, that filter no longer works/exists so people are left with only knockoff ones that dont do quite as good as a job. None of them manage to do quite what the actual one did espeically in the red, yellow, and purple stripes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to figure out what kind of filter they used to achieve this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried a bunch of colors with each of the blend modes available in my photo editing software with no luck. Perhaps it is more complicated than just one math equation? Perhaps they processed the background image before putting on the overlay?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did find in the blog that the algorithm to achieve this was a O(n^2) algorithm but that is about all I know.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas of what could have caused this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below are some reference photos I used to attempt to find a pattern.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example 1: Mark Zuckerburg (note this isn't exact. I couldn't perfectly recreate the crop they used)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LNbOZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LNbOZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example 2: Facebook logo with colors pulled out on the right&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nYlfQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nYlfQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2017-05-09T06:19:47.080" Title="What kind of image processing was used in the Facebook &quot;Celebrate Pride&quot; filter?" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5079" PostTypeId="2" ParentId="5078" CreationDate="2017-05-09T06:19:47.080" Score="5" Body="&lt;p&gt;The top Zuckerberg image looks like you first convert your background Zuckerberg image to grayscale. Then you can add a second layer with the rainbow texture but use the 'Screen' blending mode, this will cause it to colourise the layers beneath it, but in such a way the whites are preserved. You could also try 'Multiply' mode too if the results are too bright.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second one with the facebook logo looks like alpha blending. This can be done using a default layer in photoshop but setting the layer opacity to some midway value, i'd guess around 75% opacity. In this version the rainbow texture is the background, and the layer contains the 'F' logo.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-05-09T06:19:47.080" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5080" PostTypeId="2" ParentId="5021" CreationDate="2017-05-09T07:01:58.150" Score="2" Body="&lt;p&gt;A self-illuminating texture is rather easy. You can use the fragmentshader to increase the color value of those pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want a &quot;halo&quot;-like effect it gets more complicated. As Charlie said, you'd have to render in multiple passes. Render your texture only in a first pass, blur it and adjust color / brightness and put that information on top of your main render pass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you even want your texture to illuminate surrounding objects it gets even more complicated. &#xA;You could go for a texture projection for static purposes. Or you could average the texture information into one color and place an omni light in front of the emitting cube face.&#xA;There are better solutions though, I am sure.&lt;/p&gt;&#xA;" OwnerUserId="5055" LastActivityDate="2017-05-09T07:01:58.150" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5081" PostTypeId="2" ParentId="5067" CreationDate="2017-05-09T09:48:45.650" Score="2" Body="&lt;p&gt;I forgot to set the &lt;strong&gt;wEye uniform&lt;/strong&gt;, so it was always &lt;strong&gt;(0, 0, 0)&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5609" LastActivityDate="2017-05-09T09:48:45.650" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5082" PostTypeId="2" ParentId="5021" CreationDate="2017-05-09T09:53:38.163" Score="3" Body="&lt;p&gt;Presumably you are using a lighting system already, let's say Lambert shading for simplicity..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So we have a texture which is going to be illuminated by some light source. The following psuedo/shader code will do lambert shading as normal..&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;diffuseIllum = lightColour * dot(normal, lightDir);&#xA;outputColour = textureColour.rgb * diffuseIllum;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But we want certain parts of our texture to emit colours instead of being illuminated by only our light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One method would be to use an extra channel in the input texture, say the Alpha channel, to control which pixels are emissive&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;diffuseIllum = lightColour * dot(normal, lightDir);&#xA;outputColor = mix(textureColour.rgb * diffuseIllum, textureColour.rgb, texture.a);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Unfortunately this won't work so well if you want say a dark red glow because the output pixel will either be the emissive colour (dark red) or the lit texture colour, which could be much brighter. In effect our emissive areas could end up darker than the surrounding illuminated areas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We could add the emissive colour to the illuminated texture but that limits how much control over final colour we have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;outputColour = textureColour.rgb * diffuseIllum + textureColour.rgb * textureColour.a;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A more correct method would involve using 2 textures, one for diffuse illumination and another for purely emissive. These would be added together in the pixel shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; outputColour = textureColour.rgb * diffuseIllum + emissiveTextureColour.rgb;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2017-05-09T10:01:10.883" LastActivityDate="2017-05-09T10:01:10.883" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5085" PostTypeId="1" AcceptedAnswerId="5114" CreationDate="2017-05-09T14:44:27.940" Score="11" ViewCount="20339" Body="&lt;p&gt;&lt;em&gt;EDIT: I'm not fully clear on terminology here, what I previously understood to be called &quot;brightness&quot; seems poorly defined. I think I am asking about &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiant_intensity&quot; rel=&quot;noreferrer&quot;&gt;radiant intensity&lt;/a&gt;, that is, the measurable intensity of energy emitted, not weighted for subjective perception.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can calculate subjective brightness of an RGB value by weighting the three channels according to their perceived brightness, e.g. with something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(0.21 × R) + (0.72 × G) + (0.07 × B)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But, ignoring human biology and perception, is there an accepted way to calculate the objective, theoretical &quot;light intensity&quot; of an RGB value? (Theoretical because the real value will vary between displays)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first thought, given that the RGB values correspond to the intensity of the pixel's three lights, is to take the average: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(R + G + B) ÷ 3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So, for instance, that makes yellow (&lt;code&gt;#ffff00&lt;/code&gt;) twice as intense as red (&lt;code&gt;#ff0000&lt;/code&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That makes sense, thinking about two lights being on rather than one, but looking at the colours I would have guessed they were of somewhat equal intensity. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unlike dark yellow (&lt;code&gt;#808000&lt;/code&gt;) which actually is equal to the red in intensity! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect there isn't a linear relationship which is confusing the issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Can objective light intensity be calculated from an RGB value?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="6603" LastEditorUserId="6603" LastEditDate="2017-05-09T15:34:32.883" LastActivityDate="2017-05-16T04:52:10.800" Title="&quot;Light intensity&quot; of an RGB value" Tags="&lt;color-science&gt;&lt;brightness&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5086" PostTypeId="1" AcceptedAnswerId="5100" CreationDate="2017-05-09T20:27:31.777" Score="8" ViewCount="1284" Body="&lt;p&gt;I need to offset all (blue) triangles, each independently of the others, using the vertex-shader. In order to manipulate the triangle as a whole, I've created custom (vec3) attributes for each vertex (red) representing the leftward (purple) and rightward (green) neighboring vertices. From this, I need to derive the orange point, equidistant (in &lt;strong&gt;&lt;em&gt;screen space&lt;/em&gt;&lt;/strong&gt;) from both adjoining edges. With three such orange points derived from each triangle, the processed (orange) triangle is passed on to the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hN8dz.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hN8dz.png&quot; alt=&quot;per vertex operation&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/tmoMe.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tmoMe.png&quot; alt=&quot;offset triangles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally, the triangle will be culled (as in backfacing/ not rendered) if the offsets negate any available space within the triangle, such as in the second triangle in the second picture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using &lt;a href=&quot;http://threejs.org/docs/#api/core/BufferGeometry&quot; rel=&quot;noreferrer&quot;&gt;THREE.BufferGeometry()&lt;/a&gt; as my data structure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a screen shot of the effect I'm aiming for:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W9AzA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W9AzA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6596" LastEditorUserId="6596" LastEditDate="2017-05-13T13:09:17.780" LastActivityDate="2019-05-20T12:46:58.460" Title="How can I offset/shrink a triangular polygon in GLSL?" Tags="&lt;shader&gt;&lt;three.js&gt;" AnswerCount="2" CommentCount="7" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5087" PostTypeId="1" CreationDate="2017-05-10T03:09:24.577" Score="3" ViewCount="1907" Body="&lt;p&gt;I am trying to write a simple WebGL script to display a pyramid with a brick texture and Phong lighting. The lighting works fine but when I incorporate the texture, the pyramid turns black. I've checked and set my parameters to use with power-of-two textures since my texture is 512x512. This scene should be straight out of the the Mozilla WebGL examples but some reason it is not working. I am now desperate and cannot figure out why adding textures objects black. Below is my code.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    &amp;lt;html&amp;gt;&#xA;    &amp;lt;head&amp;gt;&#xA;    &amp;lt;title&amp;gt;WebGL Simple Pyramid&amp;lt;/&#xA;&#xA;    CanvasMatrix class&#xA;    (c) Apple Inc&#xA;    --&amp;gt;&#xA;    &amp;lt;script src=&quot;CanvasMatrix.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;&#xA;&#xA;    &amp;lt;!--&#xA;      Vertex shader&#xA;    --&amp;gt;&#xA;    &amp;lt;script id=&quot;shader-vs&quot; type=&quot;x-shader/x-vertex&quot;&amp;gt; &#xA;       precision highp float;&#xA;       attribute vec3 XYZ;&#xA;       attribute vec3 RGB;&#xA;       attribute vec3 NOR;&#xA;       attribute vec2 TEX;&#xA;       uniform mat4 ProjectionMatrix;&#xA;       uniform mat4 ModelviewMatrix;&#xA;       varying vec3 col;&#xA;       varying vec2 tex;&#xA;       vec3 ambient = vec3(0.3, 0.3, 0.3);&#xA;       vec3 diffuse = vec3(1.0, 1.0, 1.0);&#xA;       vec3 specular = vec3(1.0, 1.0, 1.0);&#xA;       vec4 position = vec4(-2.0, 1.0, -2.0, 1.0);&#xA;       void main(void)&#xA;       {&#xA;           //  P is the vertex coordinate on body&#xA;           vec3 P = vec3(ModelviewMatrix * vec4(XYZ, 1));&#xA;           //  N is the object normal at P&#xA;           vec4 norm = normalize(ModelviewMatrix * vec4(NOR, 1));&#xA;           vec3 N = vec3(norm.xyz);&#xA;           //  L is the light vector&#xA;           vec3 L = normalize(vec3(ModelviewMatrix*position) - P);&#xA;           //  Emission and ambient color&#xA;           vec3 color = ambient;&#xA;           //  Diffuse light intensity is cosine of light and normal vectors&#xA;           float Id = dot(L,N);&#xA;           if (Id&amp;gt;0.0)&#xA;           {&#xA;              //  Add diffuse&#xA;              color += Id*diffuse;&#xA;              //  R is the reflected light vector R = 2(L.N)N - L&#xA;              vec3 R = reflect(-L, N);&#xA;              //  V is the view vector (eye at the origin)&#xA;              vec3 V = normalize(-P);&#xA;              //  Specular is cosine of reflected and view vectors&#xA;              float Is = dot(R,V);&#xA;              if (Is&amp;gt;0.0) color += pow(Is,32.0)*specular;&#xA;           }&#xA;           //  Pass color to fragment shader&#xA;           col = color*RGB;&#xA;           //  Pass texture coordinates to fragment shader (will be interpolated)&#xA;           tex = TEX;&#xA;           //  Set transformed vertex location&#xA;           gl_Position = ProjectionMatrix * ModelviewMatrix *            vec4(XYZ,1);&#xA;       }&#xA;    &amp;lt;/script&amp;gt; &#xA;&#xA;    &amp;lt;!--&#xA;      Fragment shader&#xA;      --&amp;gt;&#xA;    &amp;lt;script id=&quot;shader-fs&quot; type=&quot;x-shader/x-fragment&quot;&amp;gt; &#xA;       precision highp float;&#xA;       varying vec3 col;&#xA;       varying vec2 tex;&#xA;       uniform sampler2D uSampler;&#xA;       void main(void)&#xA;       {&#xA;          gl_FragColor = vec4(col,1) * texture2D(uSampler, tex);&#xA;       }&#xA;    &amp;lt;/script&amp;gt; &#xA;&#xA;    &amp;lt;!--&#xA;      WebGL program&#xA;      --&amp;gt;&#xA;    &amp;lt;script type=&quot;text/javascript&quot;&amp;gt; &#xA;&#xA;    //&#xA;    //  Compile a shader&#xA;    //&#xA;    function CompileShader(gl,id)&#xA;    {&#xA;       //  Get shader by id&#xA;       var src = document.getElementById(id);&#xA;       //  Create shader based on type setting&#xA;       var shader;&#xA;       if (src.type == &quot;x-shader/x-fragment&quot;)&#xA;          shader = gl.createShader(gl.FRAGMENT_SHADER);&#xA;       else if (src.type == &quot;x-shader/x-vertex&quot;)&#xA;          shader = gl.createShader(gl.VERTEX_SHADER);&#xA;       else&#xA;          return null;&#xA;       //  Read source into str&#xA;       var str = &quot;&quot;;&#xA;       var k = src.firstChild;&#xA;       while (k)&#xA;       {&#xA;          if (k.nodeType == 3) str += k.textContent;&#xA;          k = k.nextSibling;&#xA;       }&#xA;       gl.shaderSource(shader, str);&#xA;       //  Compile the shader&#xA;       gl.compileShader(shader);&#xA;       //  Check for errors&#xA;       if (gl.getShaderParameter(shader, gl.COMPILE_STATUS) == 0)&#xA;          alert(gl.getShaderInfoLog(shader));&#xA;       //  Return shader&#xA;       return shader;&#xA;    }&#xA;&#xA;    //&#xA;    //  Compile shader program&#xA;    //&#xA;    function CompileShaderProg(gl,vert,frag)&#xA;    {&#xA;       //  Compile the program&#xA;       var prog  = gl.createProgram();&#xA;       gl.attachShader(prog , CompileShader(gl,vert));&#xA;       gl.attachShader(prog , CompileShader(gl,frag));&#xA;       gl.linkProgram(prog);&#xA;       //  Check for errors&#xA;       if (gl.getProgramParameter(prog, gl.LINK_STATUS) == 0)&#xA;          alert(gl.getProgramInfoLog(prog));&#xA;       //  Return program&#xA;       return prog;&#xA;    }&#xA;&#xA;    var text;&#xA;    var image;&#xA;    function initTexture() &#xA;    {&#xA;       text = gl.createTexture();&#xA;       image = new Image();&#xA;       image.onload = function() {handleTextureLoaded(text, image)}&#xA;       image.src = &quot;wall.png&quot;;&#xA;    }&#xA;&#xA;    function handleTextureLoaded(txt, img) &#xA;    {&#xA;       gl.bindTexture(gl.TEXTURE_2D, txt);&#xA;       gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);&#xA;       gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);&#xA;       gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_NEAREST);&#xA;       gl.generateMipmap(gl.TEXTURE_2D);&#xA;       gl.bindTexture(gl.TEXTURE_2D, null);&#xA;    }&#xA;&#xA;    var gl,canvas;&#xA;    function webGLStart()&#xA;    {&#xA;       //  Set canvas&#xA;       canvas = document.getElementById(&quot;canvas&quot;);&#xA;       //  Select canvas size&#xA;       var size = Math.min(window.innerWidth,window.innerHeight)-10;&#xA;       canvas.width  = size;&#xA;       canvas.height = size;&#xA;       //  Start WebGL&#xA;       if (!window.WebGLRenderingContext)&#xA;       {&#xA;          alert(&quot;Your browser does not support WebGL. See http://get.webgl.org&quot;);&#xA;          return;&#xA;       }&#xA;       try&#xA;       {&#xA;          gl = canvas.getContext(&quot;experimental-webgl&quot;);&#xA;       }&#xA;       catch(e)&#xA;       {}&#xA;       if (!gl)&#xA;       {&#xA;          alert(&quot;Can't get WebGL&quot;);&#xA;          return;&#xA;       }&#xA;&#xA;       //  Set viewport to entire canvas&#xA;       gl.viewport(0,0,size,size);&#xA;&#xA;       //  Initialize textures&#xA;       initTexture();&#xA;&#xA;       //  Load Shader&#xA;       var prog = CompileShaderProg(gl,&quot;shader-vs&quot;,&quot;shader-fs&quot;);&#xA;&#xA;       //  Set program&#xA;       gl.useProgram(prog);&#xA;&#xA;       //  Set projection&#xA;       var ProjectionMatrix = new CanvasMatrix4();&#xA;       ProjectionMatrix.ortho(-2.5,+2.5,-2.5,+2.5,-2.5,+2.5);&#xA;&#xA;       //  Vertex array count&#xA;       var n = 18;&#xA;       //  Pyramid vertex coordinates&#xA;       var xyz = &#xA;       [&#xA;        -1,-1,-1,   1,-1,-1,    -1,-1,1,&#xA;        1,-1,-1,    -1,-1,1,    1,-1,1,&#xA;        0,1,0,      -1,-1,1,    1,-1,1,&#xA;        0,1,0,      1,-1,-1,    -1,-1,-1,&#xA;        0,1,0,      1,-1,1,     1,-1,-1,&#xA;        0,1,0,      -1,-1,-1,   -1,-1,1,&#xA;       ];&#xA;       var verts = gl.createBuffer();&#xA;       gl.bindBuffer(gl.ARRAY_BUFFER,verts);&#xA;       gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(xyz),gl.STATIC_DRAW);&#xA;&#xA;       //  Pyramid colors&#xA;       var rgb = &#xA;       [&#xA;        0.84,0.62,0.32, 0.84,0.62,0.32, 0.84,0.62,0.32,&#xA;        0.84,0.62,0.32, 0.84,0.62,0.32, 0.84,0.62,0.32,    &#xA;        0.84,0.62,0.32, 0.84,0.62,0.32, 0.84,0.62,0.32,&#xA;        0.84,0.62,0.32, 0.84,0.62,0.32, 0.84,0.62,0.32,&#xA;        0.84,0.62,0.32, 0.84,0.62,0.32, 0.84,0.62,0.32,&#xA;        0.84,0.62,0.32, 0.84,0.62,0.32, 0.84,0.62,0.32,&#xA;       ];&#xA;       var color = gl.createBuffer();&#xA;       gl.bindBuffer(gl.ARRAY_BUFFER,color);&#xA;       gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(rgb),gl.STATIC_DRAW);&#xA;&#xA;       //  Pyramid texture coordinates&#xA;       var tex =&#xA;       [&#xA;        0,0,    4,0,    0,4,&#xA;        4,0,    0,4,    4,4,&#xA;        2,4,    0,0,    4,0,&#xA;        2,4,    0,0,    4,0,&#xA;        2,4,    0,0,    4,0,&#xA;        2,4,    0,0,    4,0,&#xA;       ];&#xA;       var texture = gl.createBuffer();&#xA;       gl.bindBuffer(gl.ARRAY_BUFFER,texture);&#xA;       gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(tex),gl.STATIC_DRAW); &#xA;&#xA;       //  Cube normals&#xA;       var nor =&#xA;       [&#xA;        0,-1, 0,                    0,-1, 0,                    0,-1, 0,&#xA;        0,-1, 0,                    0,-1, 0,                    0,-1, 0,&#xA;        0,0.4472136,0.89442719,     0,0.4472136,0.89442719,     0,0.4472136,0.89442719,&#xA;        0,0.4472136,-0.89442719,    0,0.4472136,-0.89442719,    0,0.4472136,-0.89442719,&#xA;        0.89442719,0.4472136,0,     0.89442719,0.4472136,0,     0.89442719,0.4472136,0,&#xA;        -0.89442719,0.4472136,0,    -0.89442719,0.4472136,0,    -0.89442719,0.4472136,0,&#xA;       ];&#xA;       var normals = gl.createBuffer();&#xA;       gl.bindBuffer(gl.ARRAY_BUFFER,normals);&#xA;       gl.bufferData(gl.ARRAY_BUFFER,new Float32Array(nor),gl.STATIC_DRAW);&#xA;&#xA;       //  Set state to draw scene&#xA;       gl.enable(gl.DEPTH_TEST);&#xA;       gl.clearColor(0.8,0.8,0.8,1);&#xA;       //  Mouse control variables&#xA;       var x0 = y0 = move  = 0;&#xA;       //  Rotation angles&#xA;       var th = ph = 15;&#xA;       //  Draw scene the first time&#xA;       Display();&#xA;&#xA;       //&#xA;       //  Display the scene&#xA;       //&#xA;       function Display()&#xA;       {&#xA;          //  Clear the screen and Z buffer&#xA;          gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);&#xA;&#xA;          // Compute modelview matrix&#xA;          var ModelviewMatrix = new CanvasMatrix4();&#xA;          ModelviewMatrix.makeIdentity();&#xA;          ModelviewMatrix.rotate(ph,0,1,0);&#xA;          ModelviewMatrix.rotate(th,1,0,0);&#xA;&#xA;          // Set shader&#xA;          gl.useProgram(prog);&#xA;&#xA;          //  Set projection and modelview matrixes&#xA;                 gl.uniformMatrix4fv(gl.getUniformLocation(prog,&quot;ProjectionMatrix&quot;) , false , new Float32Array(ProjectionMatrix.getAsArray()));&#xA;  gl.uniformMatrix4fv(gl.getUniformLocation(prog,&quot;ModelviewMatrix&quot;)  , false , new Float32Array(ModelviewMatrix.getAsArray()));&#xA;&#xA;  //  Set up 3D vertex array&#xA;  gl.bindBuffer(gl.ARRAY_BUFFER,verts);&#xA;  var XYZ = gl.getAttribLocation(prog,&quot;XYZ&quot;);&#xA;  gl.enableVertexAttribArray(XYZ);&#xA;  gl.vertexAttribPointer(XYZ,3,gl.FLOAT,false,0,0);&#xA;&#xA;  //  Set up 3D color array&#xA;  gl.bindBuffer(gl.ARRAY_BUFFER,color);&#xA;  var RGB = gl.getAttribLocation(prog,&quot;RGB&quot;);&#xA;  gl.enableVertexAttribArray(RGB);&#xA;  gl.vertexAttribPointer(RGB,3,gl.FLOAT,false,0,0);&#xA;&#xA;  //  Set up 3D normal array&#xA;  gl.bindBuffer(gl.ARRAY_BUFFER,normals);&#xA;  var NOR = gl.getAttribLocation(prog,&quot;NOR&quot;);&#xA;  gl.enableVertexAttribArray(NOR);&#xA;  gl.vertexAttribPointer(NOR,3,gl.FLOAT,false,0,0);&#xA;&#xA;  //  Set up 2D texture array&#xA;  gl.bindBuffer(gl.ARRAY_BUFFER,texture);&#xA;  var TEX = gl.getAttribLocation(prog,&quot;TEX&quot;);&#xA;  gl.enableVertexAttribArray(TEX);&#xA;  gl.vertexAttribPointer(TEX,2,gl.FLOAT,false,0,0);&#xA;&#xA;  gl.activeTexture(gl.TEXTURE0);&#xA;  gl.bindTexture(gl.TEXTURE_2D, text);&#xA;  gl.uniform1i(gl.getUniformLocation(prog, &quot;uSampler&quot;), 0);&#xA;&#xA;  //  Draw all vertexes&#xA;  gl.drawArrays(gl.TRIANGLES,0,n);&#xA;&#xA;  //  Disable vertex arrays&#xA;  gl.disableVertexAttribArray(XYZ);&#xA;  gl.disableVertexAttribArray(RGB);&#xA;  gl.disableVertexAttribArray(NOR);&#xA;  gl.disableVertexAttribArray(TEX);&#xA;&#xA;  //  Flush&#xA;  gl.flush();&#xA;       }&#xA;&#xA;       //&#xA;       //  Resize canvas&#xA;       //&#xA;       canvas.resize = function ()&#xA;       {&#xA;          var size = Math.min(window.innerWidth, window.innerHeight)-10;&#xA;          canvas.width  = size;&#xA;          canvas.height = size;&#xA;          gl.viewport(0,0,size,size);&#xA;          Display();&#xA;       }&#xA;&#xA;       //&#xA;       //  Mouse button pressed&#xA;       //&#xA;       canvas.onmousedown = function (ev)&#xA;       {&#xA;          move  = 1;&#xA;          x0 = ev.clientX;&#xA;          y0 = ev.clientY;&#xA;       }&#xA;&#xA;       //&#xA;       //  Mouse button released&#xA;       //&#xA;       canvas.onmouseup = function (ev)&#xA;       {&#xA;          move  = 0;&#xA;       }&#xA;&#xA;       //&#xA;       //  Mouse movement&#xA;       //&#xA;       canvas.onmousemove = function (ev)&#xA;       {&#xA;          if (move==0) return;&#xA;          //  Update angles&#xA;          ph -= ev.clientX-x0;&#xA;          th += ev.clientY-y0;&#xA;          //  Store location&#xA;          x0 = ev.clientX;&#xA;          y0 = ev.clientY;&#xA;          //  Redisplay&#xA;          Display();&#xA;       }&#xA;    }&#xA;    &amp;lt;/script&amp;gt; &#xA;&#xA;    &amp;lt;!--&#xA;      Web page&#xA;      --&amp;gt;&#xA;    &amp;lt;/head&amp;gt;&#xA;    &amp;lt;body onload=&quot;webGLStart();&quot; onresize=&quot;canvas.resize();&quot;&amp;gt; &#xA;    &amp;lt;H1&amp;gt;WebGL Simple Pyramid&amp;lt;/H1&amp;gt;&#xA;    &amp;lt;canvas id=&quot;canvas&quot; width=&quot;500&quot; height=&quot;500&quot;&amp;gt;&amp;lt;/canvas&amp;gt; &#xA;    &amp;lt;/body&amp;gt;&#xA;    &amp;lt;/html&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5521" LastActivityDate="2017-05-10T16:48:57.933" Title="WebGL: Why are my textures black?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5088" PostTypeId="1" CreationDate="2017-05-10T07:50:43.090" Score="3" ViewCount="491" Body="&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/D2uft.png&quot; width=&quot;300&quot; height=&quot;250&quot;&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/AtyZf.jpg&quot; width=&quot;300&quot; height=&quot;250&quot;&gt;&lt;br/&gt;&#xA;Above on the left is my attempt and on the right is what I'm aiming for.As you can see my sphere with the specular brdf has a weird dark ring&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my radiance function I am recursing through the intersected objects with the next intersection from the ray that's being traced. I'm using russian roulette with a depth of 5 to avoid infinite recursion. After this I find a point of intersection &lt;code&gt;Vec y&lt;/code&gt; and calculate the normal there. After this I sample the brdf, which in this case is specular, to get the incoming direction vector, stored in i. Finally I call the function using a new ray with the point of intersection and -i.&lt;br/&gt;&lt;br/&gt;&#xA;I have a feeling the my error is with my normal vector n being sent to brdf.eval or brdf.sample. I am not sure if the normal is supposed to be the normal at the origin of the ray, r.o, or at the intersection point y. When I try changing it the specular sphere ends up completely black, or my diffuse brdf for the rest of the scene becomes incorrect.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec receivedRadiance(const Ray &amp;amp;r, int depth, bool flag) {&#xA;double t, p;                                   // Distance to intersection/pdf&#xA;int id = 0;                                 // id of intersected sphere&#xA;&#xA;if (!intersect(r, t, id)) return Vec();   // if miss, return black&#xA;const Sphere &amp;amp;obj = spheres[id];            // the hit object&#xA;const BRDF &amp;amp;brdf = obj.brdf;                // Surface BRDF at x&#xA;Vec rad = obj.e;                            // Emitted radiance&#xA;&#xA;Vec o = (Vec() - r.d).normalize();          // The outgoing direction (= -r.d)&#xA;Vec x = r.o + r.d*t;                        // The intersection point&#xA;&#xA;Vec n = (x - obj.p).normalize();            // The normal direction&#xA;if (n.dot(r.d) &amp;lt; 0) n = n*-1.0;&#xA;&#xA;if (depth &amp;lt;= 5)&#xA;    p = 1.0;&#xA;else&#xA;    p = .9;&#xA;&#xA;if (rng() &amp;lt; p)&#xA;{&#xA;    Vec i, b;&#xA;    brdf.sample(n, o, i, p);&#xA;    b = brdf.eval(n, o, i);&#xA;    Ray y = Ray(x, i * -1);&#xA;    rad = rad + (receivedRadiance(y, depth + 1, true) * (PI)).mult(b) * (1 / p);&#xA;}&#xA;return rad;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is my specular BRDF struct:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct SpecularBRDF : public BRDF {&#xA;SpecularBRDF(Vec ks_) : ks(ks_) {}&#xA;&#xA;Vec eval(const Vec &amp;amp;n, const Vec &amp;amp;o, const Vec &amp;amp;i) const {&#xA;    Vec m;&#xA;    mirroredDir(n, o, m);&#xA;    if (abs(i.x - m.x) &amp;lt; 1e-5 &amp;amp;&amp;amp; abs(i.y - m.y) &amp;lt; 1e-5 &amp;amp;&amp;amp; abs(i.z - m.z) &amp;lt; 1e-5) //i == m&#xA;        return ks * (1 / n.dot(i));&#xA;    else&#xA;        return Vec(0.0, 0.0, 0.0);&#xA;}&#xA;&#xA;void sample(const Vec &amp;amp;n, const Vec &amp;amp;o, Vec &amp;amp;i, double &amp;amp;pdf) const {&#xA;    mirroredDir(n, o, i);&#xA;    pdf = 1.0;&#xA;}&#xA;&#xA;Vec ks;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And my mirrorDir function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;inline void mirroredDir(const Vec &amp;amp;n, const Vec &amp;amp;o, Vec &amp;amp;m){&#xA;m = n * 2.0 * (n.dot(o)) - o;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6606" LastEditorUserId="6606" LastEditDate="2017-05-11T03:28:41.967" LastActivityDate="2017-05-11T03:28:41.967" Title="Problem with specular BRDF (Monte Carlo &amp; Path Tracing)" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;pathtracing&gt;&lt;specular&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5090" PostTypeId="1" AcceptedAnswerId="5095" CreationDate="2017-05-10T13:33:27.430" Score="4" ViewCount="516" Body="&lt;p&gt;I'm working on a Software Rasterizer on a sub-30 MHz RISC CPU My current focus is on zooming-in on a slowly rotating planet. For maximum quality, no 3D polygons are involved with the planet - the planet texturing is purely image-based. This is what I have:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the planet rotates only around Y axis and is always viewed straight&#xA;on with camera at the equator (so you can't see poles, hence the&#xA;default pole distortion artifact is not an issue here at all)&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;midpoint Bresenham circle algorithm to compute 8 endpoints at each iteration, effectively giving me 4 horizontal scanlines&lt;/li&gt;&#xA;&lt;li&gt;simple linear remapping between texture row and planet's scanline - e.g. if the planet is 64 pixels tall on screen and texture is 128&#xA;pixels tall, I simply skip every other row&lt;/li&gt;&#xA;&lt;li&gt;same linear remapping within each scanline - e.g. if the current scanline is 64 pixels wide, and texture is 128 pixels wide, I simply&#xA;skip every other texel in current texture row&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The above works and is great as a first working and reasonably fast  prototype. However, when the planet rotates, despite the low screen resolution, due to the simple linear remapping (within each scanline), it does not &lt;em&gt;feel and look&lt;/em&gt; like planet rotation, as the perspective/distortion/stretching at the sphere edges (left and right edge of the circle) is obviously missing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the equation that can give me the exact texture coordinate, for a current texture row, of each on-screen pixel of that circle's scanline ? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please note that I can't afford to compute sin/cos (or use precomputed tables). Division is expensive, but I could perhaps hide its latency via interleaving with other instructions (while division is being computed). So, ideally, I could compute it just via add/sub/mul/bitshift. &#xA;Obviously, due to symmetry, that computed coordinate will be reused for 3 other points, so we're in reality computing that for only 25% points of the circle.&lt;/p&gt;&#xA;" OwnerUserId="6063" LastEditorUserId="1952" LastEditDate="2017-05-11T14:45:17.697" LastActivityDate="2017-05-11T14:45:17.697" Title="Fast approximation of spherical texture coordinates" Tags="&lt;texture&gt;&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5091" PostTypeId="2" ParentId="5072" CreationDate="2017-05-10T13:45:00.500" Score="3" Body="&lt;p&gt;Maybe it helps to draw out the steps of the algorithm. Here is an example for TBLR &#xA;&lt;a href=&quot;https://i.stack.imgur.com/bNJzf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bNJzf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The red is the worst case: clip top, clip bottom, clip left, clip right. Four steps!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The green is the best case: clip top, clip bottom, done. Two steps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The blue is a middle case: clip top, clip bottom, clip left, done. Three steps.&lt;/p&gt;&#xA;" OwnerUserId="6608" LastActivityDate="2017-05-10T13:45:00.500" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5092" PostTypeId="2" ParentId="5090" CreationDate="2017-05-10T13:49:43.373" Score="0" Body="&lt;p&gt;With the correct mapping used for the texture you can avoid a lot of complex math for the sample point. For example the &lt;a href=&quot;https://en.wikipedia.org/wiki/Lambert_cylindrical_equal-area_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lambert cylindrical equal-area projection&lt;/a&gt; will let you keep the y coordinate unmodified and the x coordinate only depends on which meridian you are on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you could use bresenham's ellipse algorithm to draw every visible meridian on the planet.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-05-10T13:49:43.373" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5093" PostTypeId="2" ParentId="5087" CreationDate="2017-05-10T16:48:57.933" Score="4" Body="&lt;p&gt;Okay, I figured it out. It has to do with the texture not loading before the first display function is called. The texture displays after a mouse or keyboard event. To remedy this, I added a timer to refresh the scene. This only works on Firefox however. I'm not sure why the image does not display on Chrome.&lt;/p&gt;&#xA;" OwnerUserId="5521" LastActivityDate="2017-05-10T16:48:57.933" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5095" PostTypeId="2" ParentId="5090" CreationDate="2017-05-10T23:20:26.937" Score="3" Body="&lt;p&gt;Incidentally I &lt;a href=&quot;https://youtu.be/AZTqTrCrNlw&quot; rel=&quot;nofollow noreferrer&quot;&gt;implemented something similar&lt;/a&gt; for similar hardware some 20 years ago (:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IIRC, I calculated 1D look-up-table using acos for parallel projection of a cylinder and just scaled it for each scanline to reduce computation cost. The LUT just gives you x-coordinate offset to the texture and you add constant offset for each scanline for the rotation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For y-axis the input texture can be preprocessed to have proper spherical distortion applied and you can just linearly scale the texture vertically. Though it's not that much extra computation to do it run-time either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This doesn't give you proper perspective projection but might be enough for your purposes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: Didn't notice you said you can't afford LUT. You could do the table look-up every N pixels and linearly interpolate inbetween. This was a common method in the past to do affordable perspective correct texture mapping for software rasterizers to avoid div/pixel&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-05-11T00:33:42.320" LastActivityDate="2017-05-11T00:33:42.320" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5096" PostTypeId="1" CreationDate="2017-05-11T07:50:08.453" Score="5" ViewCount="126" Body="&lt;p&gt;Is there any open-source implementation of n*log(n) visibility graph construction algorithm?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to understand &lt;a href=&quot;http://www-lb.cs.umd.edu/~mount/Papers/sicomp91-visib.pdf&quot; rel=&quot;noreferrer&quot;&gt;S. K. GHOSH and D. M. MOUNT&lt;/a&gt; sweep line algorithm, but it's known for having very hard implementation. It would be great if I saw at least some implementation, in any programming language. Or in pseudo-code.&lt;/p&gt;&#xA;" OwnerUserId="2644" LastEditorUserId="2644" LastEditDate="2017-05-11T12:54:49.767" LastActivityDate="2017-05-11T12:54:49.767" Title="Is there any open-source implementation of n*log(n) visibility graph construction algorithm?" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;2d&gt;&lt;scene-graph&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5097" PostTypeId="1" AcceptedAnswerId="5098" CreationDate="2017-05-11T12:26:45.180" Score="5" ViewCount="2434" Body="&lt;p&gt;As the title says I have been trying to understand the normal interpolation for the Phong shading/lighting model. I am unsure of the equation to calculate the normal but I have come across this equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;N=Na*α+Nb(1−α)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where N is the interpolated vector, Na and Nb are unit vectors to interpolate between and I'm assuming α is the percentage between the two. However in using this model as shown here: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static Vector3 lerp(Vector3 a, Vector3 b, double alpha){&#xA;     return (a.multiply(alpha)).add(b.multiply(1-alpha)).normalize();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am not obtaining the correct results, so any advice on the topic, such as what I may be doing wrong etc, would be appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: I found my mistake in the interpolation, here is the updated method for those who are interested:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static Vector3 lerp(Vector3 a, Vector3 b, double gradient){&#xA;    return a.add((b.minus(a)).multiply(gradient));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5887" LastEditorUserId="6546" LastEditDate="2017-05-15T03:05:39.467" LastActivityDate="2017-05-15T03:05:39.467" Title="Normal Interpolation for Phong shading" Tags="&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5098" PostTypeId="2" ParentId="5097" CreationDate="2017-05-11T13:52:09.930" Score="3" Body="&lt;p&gt;Your first version was correct, except that &lt;code&gt;alpha&lt;/code&gt; and &lt;code&gt;1-alpha&lt;/code&gt; should be swapped (the result should be &lt;code&gt;a&lt;/code&gt; when &lt;code&gt;alpha == 0&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; when &lt;code&gt;alpha == 1&lt;/code&gt;). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For Phong shading, you &lt;em&gt;do&lt;/em&gt; want to keep the normalize on the end; that's the key thing that makes Phong different from Gouraud shading. But also, normalize isn't part of the usual definition of &quot;lerp&quot; (linear interpolation), so I would keep it out of the &lt;code&gt;lerp&lt;/code&gt; function, and move the normalize to the Phong shading function where you call &lt;code&gt;lerp&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-05-11T13:52:09.930" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5099" PostTypeId="1" CreationDate="2017-05-12T11:24:41.030" Score="3" ViewCount="139" Body="&lt;p&gt;So what I would like to achieve is this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;User submits &lt;em&gt;Image 1&lt;/em&gt; - this image is then broken down into X by X sized blocks&lt;/li&gt;&#xA;&lt;li&gt;User submits &lt;em&gt;Image 2&lt;/em&gt; - then the program/algorithm takes all the blocks generated in the above step, and reconstructs &lt;em&gt;Image 2&lt;/em&gt; using them&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Example &lt;em&gt;Image 2&lt;/em&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lbKpH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lbKpH.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example &lt;em&gt;Output&lt;/em&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4w5qk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4w5qk.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I would like to know is, are there any libraries, or some easy way of doing this (ideally in Javascript, as I don't know any other languages) - or even some standalone software tool to accomplish this?&lt;/p&gt;&#xA;" OwnerUserId="6618" LastEditorUserId="6618" LastEditDate="2017-05-12T15:15:36.030" LastActivityDate="2017-05-26T03:15:06.213" Title="Image regeneration with nearest neighbor search" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;javascript&gt;&lt;image-comparison&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5100" PostTypeId="2" ParentId="5086" CreationDate="2017-05-12T17:50:49.733" Score="9" Body="&lt;p&gt;Given triangle ▲ABC, we bisect angle ∠BAC with line AD, derived with &lt;a href=&quot;https://en.wikipedia.org/wiki/Angle_bisector_theorem&quot; rel=&quot;noreferrer&quot;&gt;Angle Bisector Theorem&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BA / BD = CA / CD&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kKiYW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kKiYW.png&quot; alt=&quot;Triangle Inset Diagram&quot;&gt;&lt;/a&gt;&#xA;Point E represents our objective refined position on the desired resulting inset triangle. As it lies upon angle bisector AD, it is equidistant from sides BA &amp;amp; CA, forming identical right triangles ▲AFE &amp;amp; ▲AGE. We can now use &lt;a href=&quot;https://en.wikibooks.org/wiki/Geometry/Right_Triangles_and_Pythagorean_Theorem&quot; rel=&quot;noreferrer&quot;&gt;Sine for Right Triangles&lt;/a&gt; to find the length of AE:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;AE = EG / Sin(∠EAG)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's all the math we need, so let's cook up some GLSL!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We start off with all the typical attributes: position, normal, and transformation matrices, but since the vertex shader only works on a single vertex, we need to add the neighboring vertices as additional attributes. This way, each vertex will find its own &quot;point E&quot;, creating the resulting inset triangle. (Note: I don't call them &quot;B&quot; &amp;amp; &quot;C&quot; here, because they are not yet in &lt;em&gt;screen space&lt;/em&gt;.)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    attribute vec3 left; //vertex to the left of this vertex&#xA;    attribute vec3 right; //vertex to the right of this vertex&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Speaking of screen space, I'm also including the aspect ratio of the display, (and making it a uniform, in case the window is resized.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After preparing varying normals for the fragment shader, and transforming the face into clipping-space, we can get down to the business of applying the above math:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        attribute vec3 left; //vertex to the left of this vertex&#xA;        attribute vec3 right; //vertex to the right of this vertex&#xA;        uniform float aspect;&#xA;        varying vec3 vNormal;&#xA;        varying vec2 vUv;&#xA;&#xA;        void main() {&#xA;            vNormal = normal;&#xA;            vUv = uv;&#xA;&#xA;            mat4 xform= projectionMatrix * modelViewMatrix;&#xA;            vec4 A = xform * vec4( position, 1.0 );&#xA;            vec4 B = xform * vec4( left, 1.0 );&#xA;            vec4 C = xform * vec4( right, 1.0 );&#xA;&#xA;            vec3 CB = C.xyz - B.xyz;&#xA;            vec2 BA = B.xy - A.xy;&#xA;            vec2 CA = C.xy - A.xy;&#xA;            float lengthBA = length(BA);&#xA;            float lengthCA = length(CA);&#xA;            float ratio = lengthBA / ( lengthBA + lengthCA );&#xA;            vec3 D = B.xyz + ratio * CB.xyz;&#xA;            vec3 AD = D - A.xyz;&#xA;            vec3 bisect = normalize(AD);&#xA;&#xA;            float theta = acos( dot(BA, CA) / (lengthBA * lengthCA) ) / 2.0;&#xA;            float AE = 1.0/(sin(theta)*aspect);&#xA;            newPos.z += AE/length(AD) * (D.z - A.z);&#xA;            newPos.x += bisect.x*AE;&#xA;            newPos.y += bisect.y*AE;&#xA;&#xA;            gl_Position = newPos;&#xA;        }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code gives us the results below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0Gu9i.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0Gu9i.png&quot; alt=&quot;Screen Shot&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note, there are a few edge-cases having to do with &lt;em&gt;almost&lt;/em&gt; backface-culled triangles being flipped by this process, and I began to address this in code, yet decided to simply avoid these cases for now. Perhaps I'll revisit it when I get this project done.&lt;/p&gt;&#xA;" OwnerUserId="6596" LastEditorUserId="6596" LastEditDate="2017-05-13T13:07:48.043" LastActivityDate="2017-05-13T13:07:48.043" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5101" PostTypeId="1" AcceptedAnswerId="5113" CreationDate="2017-05-12T19:48:09.700" Score="5" ViewCount="1393" Body="&lt;p&gt;I understand that ambient light is light that occurs a result of light from a given source refecting off an infinite number of points in a scene, thereby illuminating all objects in the scene uniformly and explains why areas not directly illuminated by a light source in a scene aren't pitch black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I guess ambient light gives everything in the scene the same basic &quot;brightness&quot;. But how does one determine this value? I presume the ambient light is proportional to the primary light source intensity (a floodlight in a bedroom will surely produce more ambient light than a lit match in the same room) and inversely proportional to the scene size (a lamp in a closet surely produces more ambient light than a lamp in a hall). Is there a formula that gives ambient light &quot;brightness&quot; as a function of scene volume, light source intensity, and any other variables please?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please excuse my naivety, as I'm a noob to computer graphics, and only a hobbyist at that.&lt;/p&gt;&#xA;" OwnerUserId="6622" LastEditorUserId="6622" LastEditDate="2017-05-13T06:42:38.020" LastActivityDate="2017-05-15T22:41:07.660" Title="Formula for the ambient light intensity of a scene?" Tags="&lt;rendering&gt;&lt;lighting&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5102" PostTypeId="1" CreationDate="2017-05-12T21:23:44.517" Score="0" ViewCount="99" Body="&lt;p&gt;I have developed a C++ core application, which needs a relatively simple GUI, like a mind map. Now I wish to find a multipurpose solution for the visualization. So far my effort:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;three.js (webgl) in browser&lt;/li&gt;&#xA;&lt;li&gt;QT (qml) rendering three.js in a container , also win/lin/osx solution&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Everything works and I am enthusiastic to see the same code run on so many platforms. But the problem is, that I'm using some newly released features of three.js and qt uses an older version. More specific: there is no way to render a css3drenderer object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I almost gave up and tried to find an OpenGL solution (imgui?) or some funky solution like electron (node.js).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it seems to be, that there is no way and I have to develop native apps, may be based on OpenGL ES.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will appreciate any concept for my GUI solution&lt;/p&gt;&#xA;" OwnerUserId="6623" LastEditorUserId="6546" LastEditDate="2017-05-13T04:07:55.407" LastActivityDate="2017-05-13T04:07:55.407" Title="Is there a concept for a cross platform GUI?" Tags="&lt;opengl&gt;&lt;webgl&gt;&lt;opengl-es&gt;&lt;three.js&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5103" PostTypeId="2" ParentId="5101" CreationDate="2017-05-13T12:52:32.560" Score="10" Body="&lt;p&gt;Using an 'ambient light' term in your lighting calculations is an approximation of the indirect light reflected around the scene. Usually it's up to the artist to choose an appropriate value. There isn't really a formula, because the indirect light is dependent on many factors:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Light intensity&lt;/li&gt;&#xA;&lt;li&gt;Light shape&lt;/li&gt;&#xA;&lt;li&gt;The BRDFs of the surfaces the light will bounce off of&lt;/li&gt;&#xA;&lt;li&gt;Visibility to the light source (Think the back of a deep cave)&lt;/li&gt;&#xA;&lt;li&gt;etc.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You &lt;em&gt;could&lt;/em&gt; use some kind of formula to get an approximate value, based on these factors, but, in my opinion, it's simpler just to do it manually per scene. Or, you can remove it entirely, and use more sophisticated methods to calculate indirect lighting.&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2017-05-13T12:52:32.560" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5104" PostTypeId="1" AcceptedAnswerId="5124" CreationDate="2017-05-14T14:16:19.003" Score="5" ViewCount="1663" Body="&lt;p&gt;&lt;a href=&quot;https://youtu.be/7oSH-aZKyU8?t=72&quot; rel=&quot;nofollow noreferrer&quot;&gt;This YouTube video&lt;/a&gt; of a flip-dot display (physical b/w pixels) shows the reverse of an effect that might be called dissolve or dispersion, i.e. a text emerges from noise by pixels moving in to form letters. Here's a short cropped clip showing just the &quot;crystallization&quot; (wouldn't that be an appropriate name?):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/ikUqQ3k.gif&quot; alt=&quot;animated gif extract from youtu.be/7oSH-aZKyU8 copyright BREAKFAST NY&quot;&gt;(source: &lt;a href=&quot;https://youtu.be/7oSH-aZKyU8&quot; rel=&quot;nofollow noreferrer&quot;&gt;BREAKFAST NY&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking for more info on this or similar effects I found &lt;a href=&quot;https://www.macprovideo.com/hub/after-effects/after-effects-text-that-blows-away-like-sand&quot; rel=&quot;nofollow noreferrer&quot;&gt;After Effects: Text That Blows Away Like Sand&lt;/a&gt; which has a &lt;em&gt;Shatter&lt;/em&gt; effect, apparently a 3D &lt;a href=&quot;https://en.wikipedia.org/wiki/Particle_system&quot; rel=&quot;nofollow noreferrer&quot;&gt;particle system&lt;/a&gt; with physics simulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a particle system, I can imagine that &quot;dissolving&quot; every pixel (of a character) randomly wouldn't be too hard. Reversing the effect as shown in the video could be done using a precalculated sequence or even just animated sprites for each letter. Or, each pixel in the noise gets chosen to gravitate towards a letter (seems more complicated, may require clustering).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I found an implementation and live demo:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;Particles text effects&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uses particles with a seek behavior to make up a word.&#xA;The word is loaded into memory so that each particle can figure out their own position they need to seek.&#xA;Inspired by Daniel Shiffman's arrival explantion from The Nature of Code. (natureofcode.com)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.openprocessing.org/sketch/377231&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.openprocessing.org/sketch/377231&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reference resolves to&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://natureofcode.com/book/chapter-4-particle-systems&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://natureofcode.com/book/chapter-4-particle-systems&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://natureofcode.com/book/chapter-6-autonomous-agents/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://natureofcode.com/book/chapter-6-autonomous-agents/&lt;/a&gt; (6.4 Arriving Behavior)&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I think the effect is very similar, so I think they used a particle system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Q: Is there an approach that does not require particles (i.e. less memory-expensive)?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr/&gt;&#xA;&#xA;&lt;p&gt;Just for comparison, here's an attempt at creating a &quot;normal&quot; animated noise dissolve (&lt;a href=&quot;https://math.stackexchange.com/questions/2280900/pseudorandom-binary-mask-for-animated-dissolve-effect&quot;&gt;random dither&lt;/a&gt;), &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5104/pixel-dispersion-dissolving-algorithms#comment7504_5104&quot;&gt;as suggested in a comment&lt;/a&gt;, but I think it's obvious that the pixels in the original &lt;em&gt;do&lt;/em&gt; move and it's not just a binary blending effect:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/6eXW0B7.gif&quot; alt=&quot;Imgur&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It requires at least one random value for each pixel: on which frame of the animation to become active.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;hr/&gt;&#xA;This is what &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5124/&quot;&gt;trichoplax's solution&lt;/a&gt; looks like (pseudorandomly swapping 10,000 neighboring pixels in each of 100 frames, and then reversing it using the same pseudorandom number sequence, just reversed):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/J4gjKED.gif&quot; alt=&quot;Imgur&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="6628" LastEditorUserId="6628" LastEditDate="2017-05-21T10:50:42.607" LastActivityDate="2018-04-05T19:34:05.323" Title="Pixel dispersion (dissolving) algorithms" Tags="&lt;image-processing&gt;&lt;animation&gt;&lt;filtering&gt;&lt;particles&gt;" AnswerCount="2" CommentCount="9" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5105" PostTypeId="1" AcceptedAnswerId="5106" CreationDate="2017-05-14T19:05:59.660" Score="1" ViewCount="513" Body="&lt;p&gt;I'm developing a general Mesh class with the help of &lt;a href=&quot;https://learnopengl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;LearnOpenGL&lt;/a&gt;. In the example he creates a class which assumes that you want to generate a VAO, VBO, and an EBO but I don't usually use EBOs so I only want to generate an EBO under certain circumstances. So if I decide not to generate an EBO then I want to set my EBO to a number which cannot be generated by &lt;code&gt;glGenBuffers&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Draw Mesh&#xA;glBindVertexArray(this-&amp;gt;VAO);&#xA;&#xA;if(EBO not in range generated by glGenBuffers)&#xA;    glDrawArrays(GL_TRIANGLES, 0, numVertices);&#xA;} else {&#xA;    glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0);&#xA;}&#xA;&#xA;glBindVertexArray(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My question is what is the range that a buffer object's name can be in?&lt;/p&gt;&#xA;" OwnerUserId="6546" LastActivityDate="2017-05-14T20:10:00.883" Title="Range of integers returned by glGenBuffers?" Tags="&lt;opengl&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5106" PostTypeId="2" ParentId="5105" CreationDate="2017-05-14T20:10:00.883" Score="2" Body="&lt;p&gt;According to the OpenGL spec, any integer other than zero can be a potential name. Zero is the only value that's guaranteed not to be an object name.&lt;/p&gt;&#xA;&lt;p&gt;Relevant quote from &lt;a href=&quot;https://khronos.org/registry/OpenGL/specs/gl/glspec45.core.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;the spec&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;2.6.1.1    Name Spaces, Name Generation, and Object Creation&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Each object type has a corresponding &lt;em&gt;name space&lt;/em&gt;.  Names of objects are represented by unsigned integers of type &lt;code&gt;uint&lt;/code&gt;.  The name zero is reserved by the GL; for some object types, zero names a &lt;em&gt;default object&lt;/em&gt; of that type, and in others zero will never correspond to an actual instance of that object type.&lt;/p&gt;&#xA;&lt;p&gt;Names of most types of objects are created by &lt;em&gt;generating&lt;/em&gt; unused names using commands starting with &lt;strong&gt;Gen&lt;/strong&gt; followed by the object type.  For example, the command &lt;strong&gt;GenBuffers&lt;/strong&gt; returns one or more previously unused buffer object names.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="48" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-05-14T20:10:00.883" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5108" PostTypeId="1" CreationDate="2017-05-15T10:35:13.343" Score="5" ViewCount="90" Body="&lt;p&gt;If I have some 3d points, how can I discover parallel planes within them (not just arbitrary planes).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know how many &quot;levels&quot; or &quot;floors&quot; something can travel within, after it has done so, so I want to cluster the positions into planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some of them might not be in a plane, most of them are noisy (not perfectly planar), and I have no knowledge of the world orientation, so the planes aren't necessarily orthogonal to some known axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know one way is a 3d-hough transform, but is there something better?&lt;/p&gt;&#xA;" OwnerUserId="6175" LastActivityDate="2017-06-05T03:40:45.830" Title="Best way to group 3d points into planes, if any" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5109" PostTypeId="2" ParentId="5101" CreationDate="2017-05-15T12:00:36.697" Score="1" Body="&lt;p&gt;The &quot;Ambient&quot; term more accurately is described as the light emitted by the object itself. While it's not wrong to see it as a constant which approximates indirect lighting, it's still more accurate to call it the former, especially for the thinking process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As such, the answer depends on your scene. Considering that all objects emit their own &quot;light&quot;, there is no way to manually set a global ambient term without sacrificing image quality, as no object will be equally shaded compared to the next one. That causes the brain to perceive it as &quot;wrong looking&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, there is no formula for ambient, because ambient in the way it has been introduced a few decades ago has no basis in reality. The values are set based on the scenes, to make sure they look &quot;good enough&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Indirect light though, as found in modern graphics engines, can be calculated on the fly and removes the need for a manually set ambient term completely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short: For &quot;ambient&quot; they guess, for &quot;indirect light&quot; they calculate.&lt;/p&gt;&#xA;" OwnerUserId="6633" LastActivityDate="2017-05-15T12:00:36.697" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5112" PostTypeId="2" ParentId="5104" CreationDate="2017-05-15T19:07:39.017" Score="2" Body="&lt;p&gt;You could do this entirely within an OpenGL/WebGL fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Attach the image you wish to emerge as a texture/sampler2D.&#xA;Attach uniforms for the current time, as well as the time you want the effect to finish.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler2D myTexture;&#xA;uniform float currentTime;&#xA;uniform float finishTime;&#xA;&#xA;#define TWO_PI 6.283185307179586476925286766559&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Next, apply a deterministic pseudo-random noise algorithm for displacing pixels a given distance and compass direction. Something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float rand(vec2 co){&#xA;return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);&#xA;}&#xA;float R = rand(thisPixel.xy);&#xA;&#xA;var float timeLeft = clamp((finishTime - currentTime) * R, 0.0, 10000.0);&#xA;&#xA;float direction = classic1dPerlinNoise( R + currentTime ) * TWO_PI;&#xA;float offsetX = thisPixel.x + sin(direction) * timeLeft / 500.0;&#xA;float offsetY = thisPixel.Y + cos(direction) * timeLeft / 500.0;&#xA;vec2 texCoord = vec2( offsetX, offsetY );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note, the above &lt;em&gt;clamp&lt;/em&gt; stops the effect at the appropriate time, as well as sets a maximum (10 sec, in this example) duration of the effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, look up your texture sample:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_FragColor = gl_Color * texture2D(myTexture, texCoord);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Voila! While the pixels may not navigate around each other, they'll at least wander into place, each arriving at it's own distinct time within the timeframe allotted to the effect, and using very little memory and CPU time.&lt;/p&gt;&#xA;" OwnerUserId="6596" LastEditorUserId="6596" LastEditDate="2017-05-15T20:07:57.437" LastActivityDate="2017-05-15T20:07:57.437" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5113" PostTypeId="2" ParentId="5101" CreationDate="2017-05-15T22:41:07.660" Score="2" Body="&lt;p&gt;The formula you are seeking (and implying with the examples of a match and a lamp) is really a Radiosity formula - at which point we have to stop using the term &quot;ambient light&quot;, as with Radiosity, everything (light source and surfaces of all scene objects including) is just energy, only converted to the monitor's RGB values at the last [rendering] stage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a 10,000 ft overview, during radiosity, you break up all polygons into patches, and it's the FormFactor portion of the formula that takes care of how much energy of the current patch ends up at the target patch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Going back to your examples - a match will have different amount of starting energy than a lamp. Also, the distance from the light source to the closet walls vs hall walls will ensure a drastically different amount of energy arriving at those patches (due to the distance falloff).&lt;/p&gt;&#xA;" OwnerUserId="6063" LastActivityDate="2017-05-15T22:41:07.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5114" PostTypeId="2" ParentId="5085" CreationDate="2017-05-16T03:57:10.810" Score="14" Body="&lt;p&gt;The short answer: no, but if you are interested in details, please keep reading (:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;About lighting units&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Light “brightness” is indeed quite poor/ambiguous layman’s definition for brightness of a light source. Below is a list of different lighting properties/units commonly used in lighting calculations that define the light “brightness”. I listed both &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiometry&quot; rel=&quot;noreferrer&quot;&gt;radiometric&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Photometry_(optics)&quot; rel=&quot;noreferrer&quot;&gt;photometric&lt;/a&gt; [in brackets] properties/units. Radiometric units are Human Visual System (HVS) neutral &quot;physical&quot; units defined based on &lt;strong&gt;Watts (W)&lt;/strong&gt;, while photometric units are HVS weighted units defined based on &lt;strong&gt;Lumens (lm)&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Photometric units are commonly used in rendering because practically all consumer image input and output devices operate in these units as they are designed &amp;amp; optimized for image acquisition &amp;amp; consumption by normal &lt;a href=&quot;https://en.wikipedia.org/wiki/CIE_1931_color_space#Tristimulus_values&quot; rel=&quot;noreferrer&quot;&gt;tristimulus&lt;/a&gt; (&lt;a href=&quot;https://en.wikipedia.org/wiki/LMS_color_space&quot; rel=&quot;noreferrer&quot;&gt;LMS&lt;/a&gt;) HVS. Proper conversion between photometric &amp;amp; radiometric units isn’t simply a matter of multiplication by some factor (like between kilometers &amp;amp; miles or kilograms &amp;amp; pounds), but different projection from &lt;a href=&quot;https://en.wikipedia.org/wiki/Spectral_power_distribution&quot; rel=&quot;noreferrer&quot;&gt;Spectral Power Distribution (SPD)&lt;/a&gt; of visible light spectrum (explained later). Some people use constant &lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_efficacy&quot; rel=&quot;noreferrer&quot;&gt;luminous efficacy&lt;/a&gt; of 683 &lt;strong&gt;lm/W&lt;/strong&gt; to convert between the units, but this has very little touch with reality and results in unrealistic values.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Radiant_flux&quot; rel=&quot;noreferrer&quot;&gt;Radiant Flux&lt;/a&gt; in &lt;strong&gt;Watts (W)&lt;/strong&gt; [&lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_flux&quot; rel=&quot;noreferrer&quot;&gt;Luminous Flux&lt;/a&gt; in &lt;strong&gt;Lumen (lm)&lt;/strong&gt;] - Total power emitted by a light (regardless&#xA;of shape or size)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Radiant_exitance&quot; rel=&quot;noreferrer&quot;&gt;Radiant Exitance&lt;/a&gt; in &lt;strong&gt;W/m^2&lt;/strong&gt; [&lt;a href=&quot;https://en.wikipedia.org/wiki/Illuminance&quot; rel=&quot;noreferrer&quot;&gt;Luminous Exitance&lt;/a&gt; in &lt;strong&gt;lm/m^2&lt;/strong&gt; or &lt;strong&gt;Lux&lt;/strong&gt;] - Power emitted by a light per unit area to all directions (think different size light sources with equivalent Radiant Flux)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Radiant_intensity&quot; rel=&quot;noreferrer&quot;&gt;Radiant Intensity&lt;/a&gt; in &lt;strong&gt;W/sr&lt;/strong&gt; (sr=steradian) [&lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_intensity&quot; rel=&quot;noreferrer&quot;&gt;Luminous Intensity&lt;/a&gt; in &lt;strong&gt;lm/sr&lt;/strong&gt; or &lt;strong&gt;Candela&lt;/strong&gt;] - Power emitted by a light to certain direction (think of a spot vs omni light with equivalent Radiant Flux)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Radiance&quot; rel=&quot;noreferrer&quot;&gt;Radiance&lt;/a&gt; in &lt;strong&gt;W/sr/m^2&lt;/strong&gt; [&lt;a href=&quot;https://en.wikipedia.org/wiki/Luminance&quot; rel=&quot;noreferrer&quot;&gt;Luminance&lt;/a&gt; in &lt;strong&gt;lm/sr/m^2&lt;/strong&gt; or &lt;strong&gt;Nits&lt;/strong&gt;] - Power that falls on a patch of surface from some direction (e.g. pixel on screen or patch of surface from certain direction)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Irradiance&quot; rel=&quot;noreferrer&quot;&gt;Irradiance&lt;/a&gt; in &lt;strong&gt;W/m^2&lt;/strong&gt; [&lt;a href=&quot;https://en.wikipedia.org/wiki/Illuminance&quot; rel=&quot;noreferrer&quot;&gt;Illuminance&lt;/a&gt; in &lt;strong&gt;lm/m^2&lt;/strong&gt; or &lt;strong&gt;Lux&lt;/strong&gt;] - Power that falls on a patch of surface regardless of direction (e.g. hemispherical sky illuminating a patch of ground).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;It’s important to understand the difference between these properties when performing lighting calculations, just like it is important not to confuse properties of length and speed when doing physics calculations. There are various other light properties but having good grasp of the above gets you pretty far already.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Visible light spectrum and RGB projection&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Visible light spectrum contains “infinite” number of electromagnetic wavelengths from ~390nm to ~730nm.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/makY5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/makY5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The power spectrum emitted by light is defined with SPD (in &lt;strong&gt;W/m^2/nm&lt;/strong&gt;) and you can calculate the “HVS neutral” physical light intensity, i.e. Radiant Exitance $M_e$ (in &lt;strong&gt;W/m^2&lt;/strong&gt;) by integrating the spectrum over the visible light range:&#xA;$$M_e=\int_{390}^{730} S(\lambda)d\lambda$$&#xA;However, RGB color space is defined in photometric units by projecting SPD using HVS weighted color matching functions. This projection is done because storing SPD would consume immense amount of memory for little gain for image visualization purposes. The projection of SPD to RGB is defined with integrals over the visible light range as follows:&#xA;$$R=\int_{390}^{730} S(\lambda)\bar{r}(\lambda)d\lambda$$&#xA;$$G=\int_{390}^{730} S(\lambda)\bar{g}(\lambda)d\lambda$$&#xA;$$B=\int_{390}^{730} S(\lambda)\bar{b}(\lambda)d\lambda$$&#xA;CIE 1931 defines standard observer RGB color matching functions as shown below, based on measurement of 10 human observers&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yDQwT.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yDQwT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the functions are not discrete wavelengths for RGB, but rather weighted averages of (overlapping) wavelengths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It’s not possible to unambiguously calculate Radiant Exitance from RGB values because many different SPD's may resulting different Radiant Exitance but project to the same RGB. This is called &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Metamerism_(color)&quot; rel=&quot;noreferrer&quot; title=&quot;metamerism&quot;&gt;metamerism&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-05-16T04:52:10.800" LastActivityDate="2017-05-16T04:52:10.800" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5116" PostTypeId="1" AcceptedAnswerId="5119" CreationDate="2017-05-16T14:23:29.357" Score="7" ViewCount="1650" Body="&lt;p&gt;I'm learning about 3D computer graphics, but I'm having a hard time understanding why the &lt;a href=&quot;https://en.wikipedia.org/wiki/Viewing_frustum&quot; rel=&quot;noreferrer&quot;&gt;near plane of a viewing frustum&lt;/a&gt; can not be placed at z position $0$ (right at the camera).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can understand conceptually that the near plane is essentially the retinal canvas -- so by definition it must exist to some extent -- but I have trouble understanding why the near plane isn't simply an abstract concept where it's actual position is infinitesimally close to the camera position, as opposed to a definite z position away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In several explanations, the following formula is given to explain why $0$ cannot be used as the near plan position (where $A$ is the camera position, $B$ is an object vertex, and $D$ is the perspective projection of point $B$ onto the near plane):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gO1nR.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gO1nR.png&quot; alt=&quot;similar right triangles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$${ BC \over AC } = { DE \over AE }$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, the geometry of similar triangles $ABC$ and $ADE$ is used to determine the height of $D$ via the solution of $DE$. It is obvious that if the near plane is at $0$ ($AE = 0$), then a division by $0$ occurs -- hence, why the near plane cannot be located at position $0$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;However, why is this method used to determine the position of $D$ on the canvas?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've written a simple raycasting visualizer before and didn't have an explicitly defined near plane. In my engine, I simply defined a $60^\circ$ field of view and divided the number pixels on my screen among that field of view. For example, for a $300$x$300$ screen:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$1\text{ pixel} = 300/60^\circ = 5^\circ$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, I found the angle between my camera and the object vertex ($\angle BAC$) and divided it by $5^\circ$ to acquire the pixel coordinate on my screen. In this method, no explicit near plane was necessary and I used my actual camera position to determine the angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;So how was I able to perform a perspective projection without a near plane in my raycasting method?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="6646" LastEditorUserId="6646" LastEditDate="2017-05-16T19:42:45.977" LastActivityDate="2020-01-04T03:51:34.203" Title="How am I able to perform perspective projection without a near plane?" Tags="&lt;raytracing&gt;&lt;projections&gt;&lt;perspective&gt;&lt;mathematics&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5118" PostTypeId="2" ParentId="5116" CreationDate="2017-05-16T16:08:20.913" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;In this case, the geometry of similar triangles ABC and ADE is used to determine the height of D via the solution of DE. It is obvious that if the near plane is at 0 (AE=0), then a division by 0 occurs -- hence, why the near plane cannot be located at position 0.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is &lt;em&gt;not&lt;/em&gt; why the nearZ plane cannot be zero. The goal of perspective math is not to project the E onto the near plane. If you look at the actual perspective matrices, you'll find that the nearZ &lt;em&gt;only&lt;/em&gt; applies to the computed clip-space Z coordinate, not the X and Y.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember: projection is essentially transforming a position such that you lose one or more dimensions. You're projecting from 3D space to 2D space. So projection is removing the Z component, projecting a scene into a 2D region of space. Orthographic projection just discards the Z; perspective projection does something more complex, rescaling the X and Y based on the Z.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, we're not &lt;em&gt;really&lt;/em&gt; doing that; Z still exists. Otherwise, the depth buffer wouldn't work. But the basic perspective projection math does not define how the Z is computed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, we can compute the Z however we want. The traditional depth equation (for OpenGL's standard NDC space) is where near/farZ come from:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$Z_{ndc} = \frac{\frac{Z_{camera}(F + N)}{N - F} + \frac{2NF}{N - F}}{-Z_{camera}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;N&lt;/code&gt; and &lt;code&gt;F&lt;/code&gt; are near/farZ, respectively. If &lt;code&gt;N&lt;/code&gt; is zero, then the equation degenerates:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$Z_{ndc} = \frac{\frac{Z_{camera}(F)}{-F} + 0}{-Z_{camera}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$Z_{ndc} = \frac{-Z_{camera}}{-Z_{camera}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$Z_{ndc} = 1$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Oops.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So your question really is why we use depth computations (which again, don't really have anything to do with perspective projection) that require near/farZ values like this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This equation, and those like it, has some very nice properties. It plays well with the clip-space W component needed for perspective projection (the division by &lt;span class=&quot;math-container&quot;&gt;$-Z_{camera}$&lt;/span&gt;). But it also has the effect of being a non-linear Z projection. It puts more precision at the front of the scene than in the distance. And that's generally where you &lt;em&gt;need&lt;/em&gt; depth precision the most.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are alternative ways to compute the clip-space Z. You can use a linear method, which doesn't forbid near Z from being 0. You can also use a method that allows for an infinitely distant far Z (but still relies on near Z); this requires a floating-point Z buffer, though. And so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You haven't really shown your code, so I can't say if it truly &quot;works&quot;. The clip-space W in particular is important, as it is used for &lt;a href=&quot;https://nicolbolas.github.io/oldtut/Texturing/Tut14%20Interpolation%20Redux.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;perspective-correct interpolation of vertex data&lt;/a&gt;. If you set it to one, then you won't get proper perspective-correct interpolation. &lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-01-04T03:51:34.203" LastActivityDate="2020-01-04T03:51:34.203" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="5119" PostTypeId="2" ParentId="5116" CreationDate="2017-05-17T02:19:48.653" Score="10" Body="&lt;p&gt;The near and far planes of a viewing frustum aren't needed for simple 3D→2D projection. What the near and far planes actually do, in a typical rasterizer setup, is define the range of values for the depth buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depths in the [near, far] range will be mapped into [0, 1] to be stored in the depth buffer. However, the depths aren't simply linearly rescaled. Instead, we use a hyperbolic mapping for depth: the value stored in the depth buffer is the &lt;em&gt;reciprocal&lt;/em&gt; of the actual depth distance, with a scale and offset applied.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2Ovvk.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2Ovvk.png&quot; alt=&quot;Graph of standard hyperbolic depth mapping&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at this curve and imagine moving the near plane value toward $z = 0$, the corresponding point on the $1/z$ curve would shoot up toward infinity. The math blows up and the depth buffer becomes useless (it suffers a catastrophic loss of precision).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason why we use the reciprocal instead of some other function of depth is basically convenience: the reciprocal depth interpolates nicely in screen space, and it fits naturally into the mathematical framework of perspective projections: there's already a divide by $z$ being applied to the $x, y$ coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you'd like to know more, I have a short article on the topic: &lt;a href=&quot;http://reedbeta.com/blog/depth-precision-visualized/&quot; rel=&quot;noreferrer&quot;&gt;Depth Precision Visualized&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-05-17T02:19:48.653" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5120" PostTypeId="1" CreationDate="2017-05-17T04:12:25.817" Score="2" ViewCount="114" Body="&lt;p&gt;When drawing billboards to a cubemap, the billboard texture was incorrectly aligned on the boundaries of the cubemap between different sides. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My guess is that the false projection of the billboard texture shape using the perspective cameras when drawing the cubemap caused this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is that without using a geometry with dimensions (such as using a plane geometry for the billboard texture to attach) to achieve the correct projection, is there any other methods to reduce the artifacts? e.g. process on the pointCoord?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DnSD1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DnSD1.jpg&quot; alt=&quot;cubemap problem&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=a-cMGQFCOYs&amp;amp;feature=youtu.be&quot; rel=&quot;nofollow noreferrer&quot;&gt;a screen record showing the matter&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user4613" LastEditorDisplayName="user4613" LastEditDate="2017-05-20T06:28:19.797" LastActivityDate="2017-05-20T06:28:19.797" Title="Possible methods to deal with artifacts when drawing billboards to a cubemap" Tags="&lt;texture&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5121" PostTypeId="2" ParentId="5120" CreationDate="2017-05-17T08:09:02.443" Score="3" Body="&lt;p&gt;Change the projection to always be the same no matter which face is being rendered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simplest way is you use the direction from billboard to the camera instead of the direction the camera is facing to rotate the billboard.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-05-17T08:09:02.443" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5122" PostTypeId="1" CreationDate="2017-05-17T16:35:08.200" Score="1" ViewCount="814" Body="&lt;p&gt;I have been working on a ray tracer and I was trying to use multiple threads to maximize the performance. I tried couple of approaches but there's no difference in performance. Here's my shot...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ray_tracer::render()&#xA;{&#xA;    #define USE_THREADS&#xA;    #ifdef USE_THREADS&#xA;        for (int threadIndex = 0; threadIndex &amp;lt; mMaxThreads; ++threadIndex) {&#xA;            mThreads[threadIndex] = std::thread(&amp;amp;ray_tracer::put_pixel_with_thread, this, threadIndex);&#xA;        }&#xA;        for (int threadIndex = 0; threadIndex &amp;lt; mMaxThreads; ++threadIndex) {&#xA;            if (mThreads[threadIndex].joinable())&#xA;                mThreads[threadIndex].join();&#xA;        }&#xA;    #else&#xA;        put_pixel(); //uses single thread&#xA;    #endif&#xA;&#xA;    stbi_write_bmp(&quot;result.bmp&quot;,mImageWidth,mImageHeight,3,mFrameBuffer);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and here's the put_pixel_with_thread(int)...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ray_tracer::put_pixel_with_thread(int threadIndex)&#xA;{&#xA;    for (int row = 0; row &amp;lt;mImageHeight; ++row)&#xA;    {&#xA;        for (int col = int((threadIndex / mMaxThreads)*mImageWidth);&#xA;            col &amp;lt; int(((threadIndex + 1) / mMaxThreads)*mImageWidth);&#xA;            ++col)&#xA;        {&#xA;            int index = ((row * mImageWidth) + col) * 3;&#xA;&#xA;            mFrameBuffer[index] = 0;&#xA;            mFrameBuffer[index + 1] = 0;&#xA;            mFrameBuffer[index + 2] = 244;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can see in put_pixel_with_threads(int) that I tried to split the row for each thread. I don't know what am i doing wrong. I am working on intel i5 6th gen which has 2 hyper-threaded cores. Please help. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:55:18.663" LastActivityDate="2018-03-04T19:55:18.663" Title="How can I utilize all cores of CPU In my ray tracer with std::thread?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5123" PostTypeId="2" ParentId="5122" CreationDate="2017-05-17T17:51:15.463" Score="7" Body="&lt;p&gt;This is not really a CG issue but you appear to have an integer division problem. Assuming &lt;code&gt;mMaxThreads&lt;/code&gt; is an integer,  &lt;code&gt;(threadIndex / mMaxThreads)&lt;/code&gt; is always 0 and &lt;code&gt;((threadIndex + 1) / mMaxThreads)&lt;/code&gt; is 0 for all threads but the last one, where it is 1. So one thread is doing all the work.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-05-17T17:51:15.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5124" PostTypeId="2" ParentId="5104" CreationDate="2017-05-18T00:24:27.203" Score="4" Body="&lt;h1&gt;A very simple low memory approach&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you really want to use as little memory as possible, it can be done with not much more memory than that required to store a single image (the first frame) provided it is acceptable to do some preprocessing in advance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you copy the following jumbled image, &lt;a href=&quot;https://jsfiddle.net/rxaacpp1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this jsfiddle&lt;/a&gt; will take it as input:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Qx7Ao.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Qx7Ao.png&quot; alt=&quot;Blurred image showing a jumble of pixels&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It will then move the pixels around one step at a time so they drift into place to give the original image again:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NnZON.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NnZON.png&quot; alt=&quot;Original image of clear text&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This does not require any memory for tracking particles. The algorithm is very simple:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Pick a pixel at random&lt;/li&gt;&#xA;&lt;li&gt;Swap it with one of its 4 neighbours&lt;/li&gt;&#xA;&lt;li&gt;Repeat a million times&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;No additional memory is required as no particles are being used. We're simply swapping pixels at random, with no destination locations in mind. The key is in choosing that apparently jumbled initial image to have the pixels in exactly the right places such that applying a million random swaps will happen to leave all the pixels in exactly the right places to give the desired text.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Setting up the initial jumbled image&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To do that, &lt;a href=&quot;https://jsfiddle.net/2f9a3jcm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this preparatory jsfiddle&lt;/a&gt; takes an image as input and outputs a jumbled image that is precisely arranged to work as input for the main jsfiddle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This one takes more memory, but is still a very simple algorithm:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Generate a large number of random numbers and store them&lt;/li&gt;&#xA;&lt;li&gt;Using these numbers in reverse order* (using the last first):&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Pick a pixel at random&lt;/li&gt;&#xA;&lt;li&gt;Swap it with one of its 4 neighbours&lt;/li&gt;&#xA;&lt;li&gt;Repeat a million times&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This is exactly the opposite of what the main jsfiddle will do, so the jumbling will be completely reversed, restoring the original image. You can paste in a colour image, or if you want just text with only black and white pixels that will work too. The example image shown above is between these two extremes, as it has greyscale pixels for the antialiasing, which wander around alongside the black and white pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A million pixel swaps works for fairly small images. For larger sizes this won't jumble them enough to completely obscure the original image, so you would need to adjust the number of swaps.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Languages without reseeding&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Note that this only works because the pseudorandom number generator is reseeded at the start of both algorithms, to ensure that they are both working with exactly the same list of &quot;random&quot; numbers. Most languages will allow you to reseed the random number generator, making this an easy approach. JavaScript does not, so the jsfiddles include an implementation of &lt;a href=&quot;https://en.wikipedia.org/wiki/Xorshift&quot; rel=&quot;nofollow noreferrer&quot;&gt;xorshift&lt;/a&gt; to allow reseeding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even with a language that does allow reseeding, if the hardware is particularly limited then you may want to consider xorshift as it is very fast and uses only 4 bytes of memory for its state. It's also only a few lines of code.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;*Note that the order isn't quite the same as just reversed. In this example code, three random numbers are used for each pair of pixels to be swapped. So the order of each triple must be kept the same to avoid choosing different pairs of pixels. For example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[1, 2, 3], [4, 5, 6], [7, 8, 9]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;must be reversed to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[7, 8, 9], [4, 5, 6], [1, 2, 3]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;in order that the same x value, y value and direction be chosen for each pixel pair when running in reverse.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2017-05-21T11:16:04.630" LastActivityDate="2017-05-21T11:16:04.630" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5125" PostTypeId="1" AcceptedAnswerId="5127" CreationDate="2017-05-18T12:48:09.397" Score="5" ViewCount="657" Body="&lt;p&gt;I have a 2D space of dimensions (X,Y) with toroidal properties :&#xA;In this space, when a point A(x,y) change it's position such as x is getting &gt; X or &amp;lt; 0, then x becomes (x % X).&#xA;So when the point reach the bottom of the space, it get back to the top.&#xA;And the same for y coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the name of such a space ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I supposed it was toroidal space, but I can't find any resources with such terms.&lt;/p&gt;&#xA;" OwnerUserId="6655" LastActivityDate="2017-05-19T09:01:19.537" Title="What is the name of toroidal 2D space" Tags="&lt;geometry&gt;&lt;terminology&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5126" PostTypeId="1" CreationDate="2017-05-19T05:03:34.127" Score="1" ViewCount="41" Body="&lt;p&gt;(I initially posted this in a section that is less suited for the particular issue, oops)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm having this issue on some of my client's computers (this is for a Unity asset) that I cannot reproduce on my machine, so finding a fix is incredibly difficult. I'm using camera.rect to render to only part of a screenspace rendertexture to save on render time. For those of you unfamiliar with Unity, as far as I can tell it's analogous to glviewport.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is, on some older mac computers, realtime lighting is totally shot. The lighting appears to render only within a rectangle that is of the same SIZE as the correct one, but that is docked at 0,0. Additionally, it's not like the lighting data is just slid over, since even though the lighting is only rendering for part of the screen it's not computing it incorrectly in that portion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This happens in both forward and deferred rendering, and does not happen with baked lights. It is only reproducible on older mac machines, which I do not have access to. What on earth could cause this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oNN0b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oNN0b.png&quot; alt=&quot;Issue visualization&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, that's not good. It looks like this issue is present in Unity version 5.6 as well, even on my windows 10 machine with a GTX 1080. I cannot for the life of me figure out what could cause this, but I'll be inspecting it with renderdoc to see what I can find.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/vXx2W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vXx2W.png&quot; alt=&quot;5.6 bug&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6658" LastEditorUserId="6658" LastEditDate="2017-05-20T02:09:09.060" LastActivityDate="2017-05-20T02:09:09.060" Title="What could cause realtime lighting within a viewport to be calculated on the wrong part of the screen?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;shadow&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5127" PostTypeId="2" ParentId="5125" CreationDate="2017-05-19T08:56:12.097" Score="4" Body="&lt;p&gt;As I said in the comments, this is indeed called &lt;em&gt;torus&lt;/em&gt; or &lt;em&gt;toroidal space&lt;/em&gt; when it comes to the topology. Even if the images suggest something 3 dimensional, this is just a visualization of the embedding of such a space in $\mathbb R^3$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding the distance between two points, I think you mean following: &#xA;Just consider the coordinates $p=(x_1,y_1)$ and $q=(x_2,y_2)$ in the $[0,X)\times [0,Y) \simeq (\mathbb R / X\mathbb Z)\times (\mathbb R / Y\mathbb Z)$ square. Then define all the translations $q_i$ of $q$ :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{align*}&#xA;q_0 &amp;amp;= (x_2\hphantom{+X\,\,\,},y_2\hphantom{+X\,\,\,})\\&#xA;q_1 &amp;amp;= (x_2+X,y_2+Y)\\&#xA;q_2 &amp;amp;= (x_2\hphantom{+X\,\,\,},y_2+Y)\\&#xA;q_3 &amp;amp;= (x_2-X,y_2+Y)\\&#xA;q_4 &amp;amp;= (x_2-X,y_2\hphantom{+X\,\,\,})\\&#xA;q_5 &amp;amp;= (x_2-X,y_2-Y)\\&#xA;q_6 &amp;amp;= (x_2\hphantom{+X\,\,\,},y_2-Y)\\&#xA;q_7 &amp;amp;= (x_2+X,y_2-Y)\\&#xA;q_8 &amp;amp;= (x_2+X,y_2\hphantom{+X\,\,\,})&#xA;\end{align*}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I think the distance you're looking for is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$d(p,q) = \min_{i=0}^8 \Vert p-q_i \Vert$$&lt;/p&gt;&#xA;" OwnerUserId="1981" LastEditorUserId="1981" LastEditDate="2017-05-19T09:01:19.537" LastActivityDate="2017-05-19T09:01:19.537" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5129" PostTypeId="1" CreationDate="2017-05-19T14:16:45.537" Score="-3" ViewCount="371" Body="&lt;p&gt;o7&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am unable to find an answer to my question, because apparently it's not well enough defined to separate itself from a similar one. So I have to ask here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is quite simple. I have multiple shaderpasses and want to render each output into the same texture, which apparently isn't possible even using discard to, ahem, discard empty pixels each shaderpass isn't rendering to anyway. Each pass is supposed to only draw its own part to the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can use other methods of rendering only the necessary parts. I picked &quot;discard&quot;, because it was the quickest to implement... and it's probably a bad idea compared to stencil.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyhow: The output-texture only contains one pass, which means it works, but not how I hoped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it even possible to render multiple shaderpasses to the same texture without having each pass overwrite the output of the preceding pass?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if it is... how?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="6633" LastEditorUserId="209" LastEditDate="2017-05-19T15:13:08.543" LastActivityDate="2017-05-19T15:13:08.543" Title="Multiple shader passes to the same texture?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5130" PostTypeId="2" ParentId="5129" CreationDate="2017-05-19T15:01:14.780" Score="0" Body="&lt;p&gt;You want to use blending, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This takes the previous color and the output color of your fragment shader and mixes them together based on the blend parameters and the alpha values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This only works for simple math but when doing more complex things you will need to &quot;ping-pong&quot; between 2 textures making sure to draw to every pixel (or copy it over). &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-05-19T15:01:14.780" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5131" PostTypeId="1" CreationDate="2017-05-20T00:15:48.683" Score="2" ViewCount="157" Body="&lt;p&gt;I defined my Model-View Matrix defining a function lookAt that represents the eye of the camera, the position of the object that I'm representing and the &quot;up&quot; vector of the camera. How can I move the object in the line of sight of the camera? Any tips? If I define the vector that points to the position of the object and starts at the eye of the camera (so if I define the line of sight) how can I use this to make the object move along this direction?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my lookAt function&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  function lookAt( eye, at, up )&#xA;{&#xA;    if ( !Array.isArray(eye) || eye.length != 3) {&#xA;        throw &quot;lookAt(): first parameter [eye] must be an a vec3&quot;;&#xA;    }&#xA;&#xA;    if ( !Array.isArray(at) || at.length != 3) {&#xA;        throw &quot;lookAt(): first parameter [at] must be an a vec3&quot;;&#xA;    }&#xA;&#xA;    if ( !Array.isArray(up) || up.length != 3) {&#xA;        throw &quot;lookAt(): first parameter [up] must be an a vec3&quot;;&#xA;    }&#xA;&#xA;    if ( equal(eye, at) ) {&#xA;        return mat4();&#xA;    }&#xA;&#xA;    var v = normalize( subtract(at, eye) );  // view direction vector&#xA;    var n = normalize( cross(v, up) );       // perpendicular vector&#xA;    var u = normalize( cross(n, v) );        // &quot;new&quot; up vector&#xA;&#xA;    v = negate( v );&#xA;&#xA;    var result = mat4(&#xA;        vec4( n, -dot(n, eye) ),&#xA;        vec4( u, -dot(u, eye) ),&#xA;        vec4( v, -dot(v, eye) ),&#xA;        vec4()&#xA;    );&#xA;&#xA;    return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6401" LastActivityDate="2017-05-20T00:15:48.683" Title="WebGL- moving an object in the line of sight" Tags="&lt;webgl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5132" PostTypeId="1" AcceptedAnswerId="5135" CreationDate="2017-05-21T13:53:36.040" Score="6" ViewCount="590" Body="&lt;p&gt;So Bidirectional essentially means &quot;two directions&quot;, right? But &lt;strong&gt;what are these two direction&lt;/strong&gt; (left-right? up-down? north-south?) we are talking about in regards to bidirectional reflectance distribution function (BRDF), bidirectional scattering distribution function (BSDF), or bidirectional transmittance distribution function (BTDF) in computer graphics?&lt;/p&gt;&#xA;" OwnerUserId="2736" LastActivityDate="2017-05-22T01:01:42.507" Title="What does &quot;Bidirectional&quot; in BRDF mean?" Tags="&lt;brdf&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5133" PostTypeId="2" ParentId="5132" CreationDate="2017-05-21T18:13:48.967" Score="6" Body="&lt;p&gt;BRDFs are functions the define the distribution of the way light reflects off of a surface. They effectively answer the question, &quot;given a light source here, how much light is reflected to me?&quot; Well, that question has the two directions right there: the direction from the surface point to the light source, and the direction from the surface point to &quot;me&quot;: the viewer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BSDFs and BTDFs work in the same way, just asking slightly different questions. But the givens to those questions are the same: a light source and a viewer. And thus, they use the same directions.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-05-21T18:13:48.967" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5134" PostTypeId="1" AcceptedAnswerId="5151" CreationDate="2017-05-21T20:36:09.770" Score="5" ViewCount="5261" Body="&lt;p&gt;It makes use of tables, buckets, and sorting, which all seem unnecessary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand why I can't just fill between pairs of scan line intersections, ignoring vertices and edges with gradient 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My lecturer didn't provide the best notes on this algorithm, and all I can find online are even more complicated versions of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An ideal answer would be an explanation of the algorithm, and a reason why simply filling between pairs of intersections won't work.&lt;/p&gt;&#xA;" OwnerUserId="6677" LastEditorUserId="231" LastEditDate="2017-05-22T00:18:17.037" LastActivityDate="2017-05-24T23:06:11.927" Title="Why is the scan line filling algorithm so seemingly over complicated?" Tags="&lt;rasterizer&gt;&lt;scanline&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5135" PostTypeId="2" ParentId="5132" CreationDate="2017-05-22T01:01:42.507" Score="9" Body="&lt;p&gt;In general the two directions in BxDF are incoming $\omega_i$ and outgoing $\omega_o$ radiance directions, often defined in &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_coordinate_system&quot; rel=&quot;noreferrer&quot;&gt;spherical coordinates&lt;/a&gt; $[\theta, \phi]$ or as a 3D unit vector in &lt;a href=&quot;https://en.wikipedia.org/wiki/Cartesian_coordinate_system&quot; rel=&quot;noreferrer&quot;&gt;Cartesian coordinates&lt;/a&gt; $[x, y, z]$. The BxDF $f(\omega_i, \omega_o)$ defines how much of the incident radiance $L_i$ from direction $\omega_i$ hitting the surface is scattered towards direction $\omega_o$. What $\omega_i$ and $\omega_o$ exactly represent depends on the context.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Often $\omega_i$ represents the direction of a light source, but it could also be the direction of a surfel reflecting light or some other light emitting/scattering element in space. $\omega_o$ often represent the direction of the viewpoint (camera/eye), but it could as well be the direction of a surfel or other point in space whose incident radiance we are interested in calculating.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While $\omega_o$ is valid for normal oriented hemisphere above the surface, there are differences in valid $\omega_i$ domain between BxDF's. Because BRDF defines the amount of reflected light $\omega_i$ is valid for the normal oriented hemisphere &lt;strong&gt;above&lt;/strong&gt; the surface. On the other hand, BTDF defines the amount of light transmitted through the surface so $\omega_i$ is valid for the normal oriented hemisphere &lt;strong&gt;below&lt;/strong&gt; the surface. BSDF is the sum of the two so $\omega_i$ is valid for the entire sphere.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-05-22T01:01:42.507" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5136" PostTypeId="1" CreationDate="2017-05-22T05:43:33.280" Score="3" ViewCount="89" Body="&lt;p&gt;I want to make a basic video oscillator for the web. What I want to do is basically illustrated in a tutorial for &lt;a href=&quot;http://lumen-app.com/guide/oscillators/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lumen&lt;/a&gt;: essentially, I want to define an oscillator to turn on and off a color signal at a given frequency. This is simple to do for a frequency below 60hz, but anything higher does not seem to get the effect that the program is showing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems likely to me that the tutorial is far more simplified than what is going on behind the scenes, and since I don't have background in graphics programming I don't really have the tools to even know what I need to know. I'd like to understand what is going on and if it is possible to produce such things for the web&lt;/p&gt;&#xA;" OwnerUserId="6674" LastActivityDate="2017-05-22T07:47:58.723" Title="Need help reasoning about video oscillation &gt;60hz" Tags="&lt;rendering&gt;&lt;webgl&gt;&lt;javascript&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5137" PostTypeId="2" ParentId="5136" CreationDate="2017-05-22T06:50:07.923" Score="3" Body="&lt;p&gt;Yeah, that makes sense. Most flat panel monitors on the market have a 60Hz refresh rate! So you are not going to be able to flicker faster than 60Hz due to technical limitation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Were you to do this with a electron sweeping oscilloscope, or a LED lamp connected to a PWM source fast enough then no problem (you can find this in arduino samples). It would work. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also emulate the effect by rendering multiple frames and then blending them. But you should take careto do correct kind of blending as the monitor output is not nesseserily linear!&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-05-22T07:10:26.917" LastActivityDate="2017-05-22T07:10:26.917" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5139" PostTypeId="1" CreationDate="2017-05-22T17:19:49.283" Score="5" ViewCount="224" Body="&lt;p&gt;I implemented &lt;a href=&quot;http://advancedgraphics.marries.nl/presentationslides/10_dual-paraboloid_shadow_mapping.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;dual paraboloid&lt;/a&gt; shadows for point lights. The goal was to reduce the number of shadow passes. Also the target is GLES3.0 so no layered rendering is available. The shadows work, and actually the quality is not bad at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is one issue though. I store both hemisphere shadow maps into a single atlas during the shadow pass. During the lighting pass I sample from that atlas,from the relevant part based on the direction (forward or backward). When the shadow crosses both maps there is a white seam in the middle. I tried to change the filter mode of the FBO texture, also changed wrapping mode, but nothing helps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the screenshot:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KPiIN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KPiIN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The point source is the small white sphere at the top and currently it is located so that the shader samples half from each map in the atlas.It results in the white line in the middle of the shadow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the code in the light pass:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Shadow(vec3 viewPos,vec3 lightViewPos,vec3 viewNormal,float bias)&#xA;{&#xA;    vec3 vPosDP = vec3(u_lightViewMatrix * v_worldPosition);&#xA;    float fLength = length(vPosDP);&#xA;    vPosDP /= fLength;&#xA;    lightViewPos = (u_viewMatrix * vec4(lightViewPos,1.0)).xyz;&#xA;    vec3 L = normalize(lightViewPos - viewPos);&#xA;    float NdotL = saturate(dot(L, viewNormal));&#xA;    bias =  max(0.01 *(1.0 - NdotL), bias);&#xA;    float fDPDepth;&#xA;    float fSceneDepth;&#xA;&#xA;    if(vPosDP.z &amp;gt;=  0.0)&#xA;    {&#xA;        vec2 vTexFront;&#xA;        vTexFront.x =  ((vPosDP.x /  (1.0 + vPosDP.z))  * 0.25  + 0.25 );&#xA;        vTexFront.y =  ((vPosDP.y /  (1.0 + vPosDP.z))  * 0.5  + 0.5  );&#xA;        fSceneDepth = (fLength - u_nearFarPlanes.x) / (u_nearFarPlanes.y - u_nearFarPlanes.x);&#xA;        fDPDepth =   texture(u_shadowMap, vec3(vTexFront,fSceneDepth - bias));&#xA;    }&#xA;    else&#xA;    {&#xA;        // for the back the z has to be inverted        &#xA;        vec2 vTexBack;&#xA;        vTexBack.x =  ((vPosDP.x /  (1.0 - vPosDP.z)) * 0.25  + 0.75);&#xA;        vTexBack.y =  ((vPosDP.y /  (1.0 - vPosDP.z)) * 0.5  + 0.5);&#xA;&#xA;        fSceneDepth = (fLength - u_nearFarPlanes.x) / (u_nearFarPlanes.y - u_nearFarPlanes.x);&#xA;        fDPDepth =   texture(u_shadowMap, vec3(vTexBack,fSceneDepth - bias));&#xA;    }&#xA;    return  fDPDepth;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I read that this shadow technique has negative effect when low res geometry is involved. Is my issue related to that effect?&lt;/p&gt;&#xA;" OwnerUserId="213" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:34:55.497" LastActivityDate="2018-03-04T00:34:55.497" Title="Dual paraboloid shadow texture edge seams" Tags="&lt;shader&gt;&lt;lighting&gt;&lt;shadow&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5140" PostTypeId="1" AcceptedAnswerId="5157" CreationDate="2017-05-22T17:25:59.793" Score="2" ViewCount="379" Body="&lt;p&gt;I'm currently working on a project where a 3D model gets computed through&#xA;an isosurface algorithm. This algorithm outputs single triangles&#xA;with vertices and normals, but without indices. So therefore I have&#xA;a lot of duplicates which can't be avoided, because of a software&#xA;restriction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was asked to write smooth lighting for this model, by sending the proper normals to the visualisation software, which uses OpenGL and runs under Windows. What I tried was to set the normals for duplicated vertices to the same direction but this also results in unsmoothed lighting &lt;/p&gt;&#xA;&#xA;&lt;p&gt;as visible here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://imgur.com/a/JjLxp&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LMQdI.png&quot; alt=&quot;http://imgur.com/a/JjLxp&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to have smooth Gouraud shading on a 3D Model&#xA;which consists of many single unconnected triangles?&lt;/p&gt;&#xA;" OwnerUserId="6682" LastEditorDisplayName="user7220" LastEditDate="2018-04-22T21:30:20.847" LastActivityDate="2018-04-22T21:30:20.847" Title="Does smooth lighting work with Gouraud shading on single triangles?" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5144" PostTypeId="1" AcceptedAnswerId="5147" CreationDate="2017-05-23T13:47:02.440" Score="3" ViewCount="431" Body="&lt;p&gt;In the paper &lt;a href=&quot;http://www.dgp.toronto.edu/people/stam/reality/Research/pdf/ns.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Stable Fluids&lt;/a&gt; by Jos Stam, I am confused about the boundaries in the set_bnd function in the code. I don't know what kind of boundaries is this. Is it Neumann boundary condition or Dirichlet boundaries? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the &lt;code&gt;set_bnd&lt;/code&gt; function; the full code can be found &lt;a href=&quot;https://www.autodeskresearch.com/sites/default/files/TheArtOfFluidAnimationCode.zip&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void set_bnd ( int N, int b, float * x )&#xA;{&#xA;    int i;&#xA;&#xA;    for ( i=1 ; i&amp;lt;=N ; i++ ) {&#xA;        x[IX(0  ,i)] = b==1 ? -x[IX(1,i)] : x[IX(1,i)];&#xA;        x[IX(N+1,i)] = b==1 ? -x[IX(N,i)] : x[IX(N,i)];&#xA;        x[IX(i,0  )] = b==2 ? -x[IX(i,1)] : x[IX(i,1)];&#xA;        x[IX(i,N+1)] = b==2 ? -x[IX(i,N)] : x[IX(i,N)];&#xA;    }&#xA;    x[IX(0  ,0  )] = 0.5f*(x[IX(1,0  )]+x[IX(0  ,1)]);&#xA;    x[IX(0  ,N+1)] = 0.5f*(x[IX(1,N+1)]+x[IX(0  ,N)]);&#xA;    x[IX(N+1,0  )] = 0.5f*(x[IX(N,0  )]+x[IX(N+1,1)]);&#xA;    x[IX(N+1,N+1)] = 0.5f*(x[IX(N,N+1)]+x[IX(N+1,N)]);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4978" LastEditorUserId="48" LastEditDate="2017-05-23T15:08:37.217" LastActivityDate="2017-05-27T23:57:41.090" Title="Jos Stam's &quot;Stable Fluids&quot; boundary conditions" Tags="&lt;c++&gt;&lt;fluid-sim&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5146" PostTypeId="1" CreationDate="2017-05-23T16:24:39.233" Score="5" ViewCount="713" Body="&lt;p&gt;I implemented cascaded shadow maps, where shadow maps for each cascade is rendered to one canvas:&lt;a href=&quot;https://i.stack.imgur.com/3kRtI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3kRtI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The light projections for each cascade are calculated from the bounding spheres of camera sub-frustums:&lt;a href=&quot;https://i.stack.imgur.com/XcPSK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XcPSK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code for calculation visibility value:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; 3; i++) {&#xA;    v_shadowCoord[i] = u_lightVPshifted[i] * vec4(a_WolrdPosition, 1);&#xA;}&#xA;&#xA;highp float zTocompare = v_shadowCoord[iCascade].z - bias;&#xA;return texture(u_shadowMap, vec3(v_shadowCoord[iCascade].xy, zTocompare));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;v_shadowCoord&lt;/code&gt; for first cascade are in &lt;code&gt;(0, 1), (0, 0.33)&lt;/code&gt; ranges, for second &lt;code&gt;(0, 1), (0.33, 0.66)&lt;/code&gt;, third &lt;code&gt;(0, 1), (0.66, 1)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The problem&lt;/strong&gt; is that I get seams between cascades when anisotropic filtering is enabled. Here is the explanation of problem and suggested fix at the bottom of the page: &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ee416307(v=vs.85).aspx&quot; rel=&quot;noreferrer&quot;&gt;link&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I understand, for cascade borders the wrong mipmap is selected - the smallest. Because the texels for two neighboring vertices on scene come from different cascades and therefore screen-space derivatives are large. I tried the suggested fix from the site, still have same seam:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;highp vec2 uv = v_shadowCoord[iCascade].xy;&#xA;highp vec2 dx = dFdx (uv) / u_cascadeScales[iCascade];&#xA;highp vec2 dy = dFdy (uv) / u_cascadeScales[iCascade];&#xA;highp float zTocompare = (v_shadowCoord[iCascade].z) - bias;&#xA;return textureGradOffset(u_shadowMap, vec3(uv,  zTocompare), dx, dy, ivec2(0, 0));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I suppose I don't use the right input there. &lt;code&gt;v_shadowCoord&lt;/code&gt; I described above, &lt;code&gt;u_cascadeScales&lt;/code&gt; are scales of projection sizes in light view space relative to first one: I have &lt;code&gt;(1.0, 14.0, 300.0)&lt;/code&gt;. Could you please explain how just scaling the derivatives will help selecting right mipmap and suggest what is wrong in the code? I expect that even with that scaling, values on the border will still be mapped to distant texels and wrong mipmap will be used.&lt;/p&gt;&#xA;" OwnerUserId="6688" LastEditorUserId="213" LastEditDate="2017-05-23T16:39:21.827" LastActivityDate="2017-05-23T16:39:21.827" Title="Cascaded shadow maps. Seams between cascades" Tags="&lt;opengl&gt;&lt;shadow&gt;&lt;shadow-mapping&gt;&lt;mipmap&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5147" PostTypeId="2" ParentId="5144" CreationDate="2017-05-24T09:08:53.453" Score="3" Body="&lt;p&gt;It's Dirichlet boundary condition. The quantities at domain boundaries will take either the same value as its inner neighbor or the negated value, depending on the condition $\mathbf{b}$. Take velocity field for instance, velocity of fluid will either gets reflected or not change at domain boundary. The condition $\mathbf{b}$ is a user option, $\mathbf{b}==1$ is used to set reflected values at the horizonal boundaries, and $\mathbf{b}==2$ is to set reflected values at vertical boundaries. To be more clear:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$\mathbf{b}==1$: field values at horizonal boundaries get reflected, field values at vertical boundaries do not change.&lt;/li&gt;&#xA;&lt;li&gt;$\mathbf{b}==2$: field values at vertical boundaries get reflected, field values at horizonal boundaries do not change.&lt;/li&gt;&#xA;&lt;li&gt;$\mathbf{b}== other\ value$: field values at neither vertical nor horizonal boundaries do not change. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;set_bnd could be called multiple times to set desired boundary values.&lt;/p&gt;&#xA;" OwnerUserId="6691" LastEditorUserId="6691" LastEditDate="2017-05-25T02:16:26.863" LastActivityDate="2017-05-25T02:16:26.863" CommentCount="12" ContentLicense="CC BY-SA 3.0" />
  <row Id="5148" PostTypeId="1" AcceptedAnswerId="5150" CreationDate="2017-05-24T15:12:21.807" Score="3" ViewCount="362" Body="&lt;p&gt;To start, this is my VBO Data Struct:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//-----------------------------------------------------------------&#xA;struct Vertex&#xA;//-----------------------------------------------------------------&#xA;{&#xA;    //-----------------------------------------------------------------&#xA;    Vertex()&#xA;    : x(0), y(0), z(0), &#xA;      s(0), t(0)&#xA;    //-----------------------------------------------------------------&#xA;    {}&#xA;&#xA;    //-----------------------------------------------------------------&#xA;    Vertex(Vertex&amp;amp; rhs)        &#xA;    : x(rhs.x), y(rhs.y), z(rhs.z),&#xA;      s(rhs.s), t(rhs.t)&#xA;    //-----------------------------------------------------------------&#xA;    {}&#xA;&#xA;    // Position&#xA;    float x;&#xA;    float y;&#xA;    float z;&#xA;&#xA;    // Texture Coords&#xA;    float s;&#xA;    float t;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am reading a lot of tutorials and all seem to submit the color of their polygons with the VBO to the GPU. However, if you ever change the color, you need resubmit the data to the GPU. Why is that so common, when you can bind the color via an uniform? Isn't that heaps and bounds faster? One could argue that you need to bind the color then for each Polygon or at least Sprite or Model, depending on what you are doing, if you use the same shader for each of them, which is common practice. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I am confused how to design my (learning) 2D Game from the ground up. Should I put the 4 floats (r,g,b,a) into the VBO and add it to the layout or simply keep changing it via glUniform4fv? Is there a best practice for this?&lt;/p&gt;&#xA;" OwnerUserId="6679" LastActivityDate="2017-05-24T20:47:01.250" Title="What is the best practice for data in a VBO?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5149" PostTypeId="2" ParentId="5148" CreationDate="2017-05-24T15:43:09.403" Score="1" Body="&lt;p&gt;To have a attribute have a certain values for a subset of vertices in the draw call you need to duplicate the data. You can only change uniforms between draw calls and you will want to minimize the number of draw calls if possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That duplicated bit of data is likely not going to be significant overhead. Most textures will be much larger than that.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-05-24T15:43:09.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5150" PostTypeId="2" ParentId="5148" CreationDate="2017-05-24T20:47:01.250" Score="2" Body="&lt;p&gt;If the color needs to vary per vertex, it will need to be an attribute in the vertex buffer. If it's acceptable to have the color be constant per draw call, then by all means make it a uniform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, editing a vertex buffer and resubmitting data to the GPU, while certainly slower than updating a uniform, doesn't have to be a huge inefficiency. By using &lt;code&gt;GL_DYNAMIC_DRAW&lt;/code&gt; when you set up the buffer, combined with using &lt;a href=&quot;http://docs.gl/gl4/glMapBufferRange&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glMapBufferRange&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;GL_MAP_INVALIDATE_BUFFER_BIT&lt;/code&gt; to update it, the driver can manage the buffer memory and transfers efficiently. That's how you would typically do a particle system, for instance, with the particles' positions, colors, etc. changing every frame. Furthermore, if only one or two vertex attributes need to change, you can split those off into their own buffer to decrease the total data updated.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-05-24T20:47:01.250" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5151" PostTypeId="2" ParentId="5134" CreationDate="2017-05-24T21:45:10.007" Score="7" Body="&lt;p&gt;The scan-line algorithm (as described on &lt;a href=&quot;https://en.wikipedia.org/wiki/Scanline_rendering&quot; rel=&quot;noreferrer&quot;&gt;Wikipedia&lt;/a&gt; for instance) is concerned with generating the pixels in order, left-to-right and top-to-bottom, with each pixel needing to be touched only once. It was developed in the late 1960s, for devices with no framebuffer memory—so it has to generate each pixel just-in-time as it scans out to the display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The constraint to generate the pixels exactly in order is a strong one. Now, it's possible to imagine a very simple and naive algorithm that doesn't need tables, buckets, or sorting to accomplish this. For example, for each pixel, you might just iterate over all the triangles, test whether the current pixel falls inside it, and keep track of the closest triangle that passes that test. (That's effectively ray tracing without any acceleration structure.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's pretty clear that this is inefficient as soon as you have more than a handful of triangles. The complicated data structures and stuff that show up in the classic scan-line algorithm are there to optimize this process. For instance, pre-bucketing the edges by Y-coordinate and maintaining an &quot;active edge table&quot; lets you quickly and incrementally identify the edges that affect each scanline as you move down the image. Keeping the edge intersections sorted by X-coordinate allows you to quickly generate the pixels left-to-right within each scanline, and keeping a Z-sorted list of active triangles as you scan left-to-right enables you to do hidden surface removal at the same time.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Incidentally, this algorithm is of mainly historical interest. It is very far from how modern GPU rasterizers or even software rasterizers work. Nowadays we pretty much always have a framebuffer and use double buffering, so we don't need to generate the pixels precisely in order anymore; consequently, we usually iterate over the triangles first, then find which pixels each triangle covers, rather than the other way around.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, the scanline algorithm is pretty inherently serial and doesn't make good use of today's highly parallel hardware. Modern approaches rely on multicore processing and SIMD to test many pixels against many triangles at once, rather than incrementally updating sorted lists of edges and suchlike.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more on modernized software rasterization, see Fabian Giesen's articles &lt;a href=&quot;https://fgiesen.wordpress.com/2013/02/08/triangle-rasterization-in-practice/&quot; rel=&quot;noreferrer&quot;&gt;Triangle rasterization in practice&lt;/a&gt; and &lt;a href=&quot;https://fgiesen.wordpress.com/2013/02/10/optimizing-the-basic-rasterizer/&quot; rel=&quot;noreferrer&quot;&gt;Optimizing the basic rasterizer&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2017-05-24T23:06:11.927" LastActivityDate="2017-05-24T23:06:11.927" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5152" PostTypeId="1" AcceptedAnswerId="5153" CreationDate="2017-05-24T22:08:38.813" Score="15" ViewCount="6342" Body="&lt;p&gt;I understood the logic behind the importance sampling for the BRDF part. However, when it comes to sampling light sources explicitly, all becomes confusing. For example, if I have one point light source in my scene and if I directly sample it at each frame constantly, should I count it as one more sample for the monte carlo integration? That is, I take one sample from cosine-weighted distribution and other from the point light. Is it two samples in total or just one? Also, should I divide the radiance coming from the direct sample to any term?&lt;/p&gt;&#xA;" OwnerUserId="6698" LastActivityDate="2017-05-25T18:56:47.003" Title="Progressive Path Tracing with Explicit Light Sampling" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="13" ContentLicense="CC BY-SA 3.0" />
  <row Id="5153" PostTypeId="2" ParentId="5152" CreationDate="2017-05-25T04:09:07.557" Score="23" Body="&lt;p&gt;There are multiple areas in path tracing that can be importance sampled. In addition, each of those areas can also use Multiple Importance Sampling, first proposed in Veach and Guibas's &lt;a href=&quot;https://sites.fas.harvard.edu/~cs278/papers/veach.pdf&quot; rel=&quot;noreferrer&quot;&gt;1995 paper&lt;/a&gt;. To better explain, let's look at a backwards path tracer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) {&#xA;    Ray ray = m_scene-&amp;gt;Camera-&amp;gt;CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;    SurfaceInteraction interaction;&#xA;&#xA;    // Bounce the ray around the scene&#xA;    const uint maxBounces = 15;&#xA;    for (uint bounces = 0; bounces &amp;lt; maxBounces; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.GeomID == INVALID_GEOMETRY_ID) {&#xA;            color += throughput * m_scene-&amp;gt;BackgroundColor;&#xA;            break;&#xA;        }&#xA;&#xA;        // Fetch the material&#xA;        Material *material = m_scene-&amp;gt;GetMaterial(ray.GeomID);&#xA;        // The object might be emissive. If so, it will have a corresponding light&#xA;        // Otherwise, GetLight will return nullptr&#xA;        Light *light = m_scene-&amp;gt;GetLight(ray.GeomID);&#xA;&#xA;        // If we hit a light, add the emission&#xA;        if (light != nullptr) {&#xA;            color += throughput * light-&amp;gt;Le();&#xA;        }&#xA;&#xA;        interaction.Position = ray.Origin + ray.Direction * ray.TFar;&#xA;        interaction.Normal = normalize(m_scene-&amp;gt;InterpolateNormal(ray.GeomID, ray.PrimID, ray.U, ray.V));&#xA;        interaction.OutputDirection = normalize(-ray.Direction);&#xA;&#xA;&#xA;        // Get the new ray direction&#xA;        // Choose the direction based on the bsdf        &#xA;        material-&amp;gt;bsdf-&amp;gt;Sample(interaction, sampler);&#xA;        float pdf = material-&amp;gt;bsdf-&amp;gt;Pdf(interaction);&#xA;&#xA;        // Accumulate the weight&#xA;        throughput = throughput * material-&amp;gt;bsdf-&amp;gt;Eval(interaction) / pdf;&#xA;&#xA;        // Shoot a new ray&#xA;&#xA;        // Set the origin at the intersection point&#xA;        ray.Origin = interaction.Position;&#xA;&#xA;        // Reset the other ray properties&#xA;        ray.Direction = interaction.InputDirection;&#xA;        ray.TNear = 0.001f;&#xA;        ray.TFar = infinity;&#xA;&#xA;&#xA;        // Russian Roulette&#xA;        if (bounces &amp;gt; 3) {&#xA;            float p = std::max(throughput.x, std::max(throughput.y, throughput.z));&#xA;            if (sampler-&amp;gt;NextFloat() &amp;gt; p) {&#xA;                break;&#xA;            }&#xA;&#xA;            throughput *= 1 / p;&#xA;        }&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera-&amp;gt;FrameBufferData.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In English:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Shoot a ray through the scene&lt;/li&gt;&#xA;&lt;li&gt;Check if we hit anything. If not we return the skybox color and break.&lt;/li&gt;&#xA;&lt;li&gt;Check if we hit a light. If so, we add the light emission to our color accumulation&lt;/li&gt;&#xA;&lt;li&gt;Choose a new direction for the next ray. We can do this uniformly, or importance sample based on the BRDF&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the BRDF and accumulate it. Here we have to divide by the pdf of our chosen direction, in order to follow the Monte Carlo Algorithm.&lt;/li&gt;&#xA;&lt;li&gt;Create a new ray based on our chosen direction and where we just came from&lt;/li&gt;&#xA;&lt;li&gt;[Optional] Use Russian Roulette to choose if we should terminate the ray&lt;/li&gt;&#xA;&lt;li&gt;Goto 1&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;With this code, we only get color if the ray eventually hits a light. In addition, it doesn't support punctual light sources, since they have no area. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this, we sample the lights directly at every bounce. We have to do a few small changes:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) {&#xA;    Ray ray = m_scene-&amp;gt;Camera-&amp;gt;CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;    SurfaceInteraction interaction;&#xA;&#xA;    // Bounce the ray around the scene&#xA;    const uint maxBounces = 15;&#xA;    for (uint bounces = 0; bounces &amp;lt; maxBounces; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.GeomID == INVALID_GEOMETRY_ID) {&#xA;            color += throughput * m_scene-&amp;gt;BackgroundColor;&#xA;            break;&#xA;        }&#xA;&#xA;        // Fetch the material&#xA;        Material *material = m_scene-&amp;gt;GetMaterial(ray.GeomID);&#xA;        // The object might be emissive. If so, it will have a corresponding light&#xA;        // Otherwise, GetLight will return nullptr&#xA;        Light *light = m_scene-&amp;gt;GetLight(ray.GeomID);&#xA;&#xA;        // If this is the first bounce or if we just had a specular bounce,&#xA;        // we need to add the emmisive light&#xA;        if ((bounces == 0 || (interaction.SampledLobe &amp;amp; BSDFLobe::Specular) != 0) &amp;amp;&amp;amp; light != nullptr) {&#xA;            color += throughput * light-&amp;gt;Le();&#xA;        }&#xA;&#xA;        interaction.Position = ray.Origin + ray.Direction * ray.TFar;&#xA;        interaction.Normal = normalize(m_scene-&amp;gt;InterpolateNormal(ray.GeomID, ray.PrimID, ray.U, ray.V));&#xA;        interaction.OutputDirection = normalize(-ray.Direction);&#xA;&#xA;&#xA;        // Calculate the direct lighting&#xA;        color += throughput * SampleLights(sampler, interaction, material-&amp;gt;bsdf, light);&#xA;&#xA;&#xA;        // Get the new ray direction&#xA;        // Choose the direction based on the bsdf        &#xA;        material-&amp;gt;bsdf-&amp;gt;Sample(interaction, sampler);&#xA;        float pdf = material-&amp;gt;bsdf-&amp;gt;Pdf(interaction);&#xA;&#xA;        // Accumulate the weight&#xA;        throughput = throughput * material-&amp;gt;bsdf-&amp;gt;Eval(interaction) / pdf;&#xA;&#xA;        // Shoot a new ray&#xA;&#xA;        // Set the origin at the intersection point&#xA;        ray.Origin = interaction.Position;&#xA;&#xA;        // Reset the other ray properties&#xA;        ray.Direction = interaction.InputDirection;&#xA;        ray.TNear = 0.001f;&#xA;        ray.TFar = infinity;&#xA;&#xA;&#xA;        // Russian Roulette&#xA;        if (bounces &amp;gt; 3) {&#xA;            float p = std::max(throughput.x, std::max(throughput.y, throughput.z));&#xA;            if (sampler-&amp;gt;NextFloat() &amp;gt; p) {&#xA;                break;&#xA;            }&#xA;&#xA;            throughput *= 1 / p;&#xA;        }&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera-&amp;gt;FrameBufferData.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;First, we add &quot;color += throughput * SampleLights(...)&quot;. I'll go into detail about SampleLights() in a bit. But, essentially, it loops through all the lights, and returns their contribution to the color, attenuated by the BSDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is great, but we need to make one more change in order to make it correct; specifically, what happens when we hit a light. In the old code, we added the light's emission to the color accumulation. But now we directly sample the light every bounce, so if we added the light's emission, we would &quot;double dip&quot;. Therefore, the correct thing to do is... nothing; we skip accumulating the light's emission.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there are two corner cases: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The first ray&lt;/li&gt;&#xA;&lt;li&gt;Perfectly specular bounces (aka mirrors)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;If the first ray hits the light, you should see the light's emission directly. So if we skip it, all the lights will show up as black, even though the surfaces around them are lit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you hit a perfectly specular surfaces you can't directly sample a light, because an input ray has only one output. Well, technically, we &lt;em&gt;could&lt;/em&gt; check if the input ray is going to hit a light, but there's no point; the main Path Tracing loop is going to do that anyway. Therefore, if we hit a light just after we hit a specular surface, we need to accumulate the color. If we don't, lights will be black in mirrors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, let's delve into SampleLights(): &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 SampleLights(UniformSampler *sampler, SurfaceInteraction interaction, BSDF *bsdf, Light *hitLight) const {&#xA;    std::size_t numLights = m_scene-&amp;gt;NumLights();&#xA;&#xA;    float3 L(0.0f);&#xA;    for (uint i = 0; i &amp;lt; numLights; ++i) {&#xA;        Light *light = &amp;amp;m_scene-&amp;gt;Lights[i];&#xA;&#xA;        // Don't let a light contribute light to itself&#xA;        if (light == hitLight) {&#xA;            continue;&#xA;        }&#xA;&#xA;        L = L + EstimateDirect(light, sampler, interaction, bsdf);&#xA;    }&#xA;&#xA;    return L;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In English:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Loop through all the lights&lt;/li&gt;&#xA;&lt;li&gt;Skip the light if we hit it&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Don't double dip&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Accumulate the direct lighting from all the lights&lt;/li&gt;&#xA;&lt;li&gt;Return the direct lighting&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Finally, EstimateDirect() is just evaluating $BSDF(p, \omega_{\text{i}}, \omega_{\text{o}}) L_{\text{i}}(p, \omega_{\text{i}})$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For punctual light sources, this is simple as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 EstimateDirect(Light *light, UniformSampler *sampler, SurfaceInteraction &amp;amp;interaction, BSDF *bsdf) const {&#xA;    // Only sample if the BRDF is non-specular &#xA;    if ((bsdf-&amp;gt;SupportedLobes &amp;amp; ~BSDFLobe::Specular) != 0) {&#xA;        return float3(0.0f);&#xA;    }&#xA;&#xA;    interaction.InputDirection = normalize(light-&amp;gt;Origin - interaction.Position);&#xA;    return bsdf-&amp;gt;Eval(interaction) * light-&amp;gt;Li;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, if we want lights to have area, we first need to sample a point on the light. Therefore, the full definition is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 EstimateDirect(Light *light, UniformSampler *sampler, SurfaceInteraction &amp;amp;interaction, BSDF *bsdf) const {&#xA;    float3 directLighting = float3(0.0f);&#xA;&#xA;    // Only sample if the BRDF is non-specular &#xA;    if ((bsdf-&amp;gt;SupportedLobes &amp;amp; ~BSDFLobe::Specular) != 0) {&#xA;        float pdf;&#xA;        float3 Li = light-&amp;gt;SampleLi(sampler, m_scene, interaction, &amp;amp;pdf);&#xA;&#xA;        // Make sure the pdf isn't zero and the radiance isn't black&#xA;        if (pdf != 0.0f &amp;amp;&amp;amp; !all(Li)) {&#xA;            directLighting += bsdf-&amp;gt;Eval(interaction) * Li / pdf;&#xA;        }&#xA;    }&#xA;&#xA;    return directLighting;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We can implement light-&gt;SampleLi however we want; we can choose the point uniformly, or importance sample. In either case, we divide the radiosity by the pdf of choosing the point. Again, to satisfy the requirements of Monte Carlo.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the BRDF is highly view dependent, it may be better to choose a point based on the BRDF, instead of a random point on the light. But how do we choose? Sample based on the light, or based on the BRDF?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why not both? Enter Multiple Importance Sampling. In short, we evaluate $BSDF(p, \omega_{\text{i}}, \omega_{\text{o}}) L_{\text{i}}(p, \omega_{\text{i}})$ multiple times, using different sampling techniques, then average them together using weights based on their pdfs. In code this is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 EstimateDirect(Light *light, UniformSampler *sampler, SurfaceInteraction &amp;amp;interaction, BSDF *bsdf) const {&#xA;    float3 directLighting = float3(0.0f);&#xA;    float3 f;&#xA;    float lightPdf, scatteringPdf;&#xA;&#xA;&#xA;    // Sample lighting with multiple importance sampling&#xA;    // Only sample if the BRDF is non-specular &#xA;    if ((bsdf-&amp;gt;SupportedLobes &amp;amp; ~BSDFLobe::Specular) != 0) {&#xA;        float3 Li = light-&amp;gt;SampleLi(sampler, m_scene, interaction, &amp;amp;lightPdf);&#xA;&#xA;        // Make sure the pdf isn't zero and the radiance isn't black&#xA;        if (lightPdf != 0.0f &amp;amp;&amp;amp; !all(Li)) {&#xA;            // Calculate the brdf value&#xA;            f = bsdf-&amp;gt;Eval(interaction);&#xA;            scatteringPdf = bsdf-&amp;gt;Pdf(interaction);&#xA;&#xA;            if (scatteringPdf != 0.0f &amp;amp;&amp;amp; !all(f)) {&#xA;                float weight = PowerHeuristic(1, lightPdf, 1, scatteringPdf);&#xA;                directLighting += f * Li * weight / lightPdf;&#xA;            }&#xA;        }&#xA;    }&#xA;&#xA;&#xA;    // Sample brdf with multiple importance sampling&#xA;    bsdf-&amp;gt;Sample(interaction, sampler);&#xA;    f = bsdf-&amp;gt;Eval(interaction);&#xA;    scatteringPdf = bsdf-&amp;gt;Pdf(interaction);&#xA;    if (scatteringPdf != 0.0f &amp;amp;&amp;amp; !all(f)) {&#xA;        lightPdf = light-&amp;gt;PdfLi(m_scene, interaction);&#xA;        if (lightPdf == 0.0f) {&#xA;            // We didn't hit anything, so ignore the brdf sample&#xA;            return directLighting;&#xA;        }&#xA;&#xA;        float weight = PowerHeuristic(1, scatteringPdf, 1, lightPdf);&#xA;        float3 Li = light-&amp;gt;Le();&#xA;        directLighting += f * Li * weight / scatteringPdf;&#xA;    }&#xA;&#xA;    return directLighting;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In English:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;First, we sample the light&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;This updates interaction.InputDirection&lt;/li&gt;&#xA;&lt;li&gt;Gives us the Li for the light&lt;/li&gt;&#xA;&lt;li&gt;And the pdf of choosing that point on the light&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Check that the pdf is valid and the radiance is non-zero&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the BSDF using the sampled InputDirection&lt;/li&gt;&#xA;&lt;li&gt;Calculate the pdf for the BSDF given the sampled InputDirection&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Essentially, how likely is this sample, if we were to sample using the BSDF, instead of the light&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Calculate the weight, using the light pdf and the BSDF pdf&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Veach and Guibas define a couple different ways to calculate the weight. Experimentally, they found the power heuristic with a power of 2 to work the best for most cases. I refer you to the paper for more details. The implementation is below&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Multiply the weight with the direct lighting calculation and divide by the light pdf. (For Monte Carlo) And add to the direct light accumulation.&lt;/li&gt;&#xA;&lt;li&gt;Then, we sample the BRDF&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;This updates interaction.InputDirection&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the BRDF&lt;/li&gt;&#xA;&lt;li&gt;Get the pdf for choosing this direction based on the BRDF&lt;/li&gt;&#xA;&lt;li&gt;Calculate the light pdf, given the sampled InputDirection&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;This is the mirror of before. How likely is this direction, if we were to sample the light&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;If lightPdf == 0.0f, then the ray missed the light, so just return the direct lighting from the light sample.&lt;/li&gt;&#xA;&lt;li&gt;Otherwise, calculate the weight, and add the BSDF direct lighting to the accumulation&lt;/li&gt;&#xA;&lt;li&gt;Finally, return the accumulated direct lighting&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;inline float PowerHeuristic(uint numf, float fPdf, uint numg, float gPdf) {&#xA;    float f = numf * fPdf;&#xA;    float g = numg * gPdf;&#xA;&#xA;    return (f * f) / (f * f + g * g);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There are a number of optimizations / improvements you can do in these functions, but I've pared them down to try to make them easier to comprehend. If you would like, I can share some of these improvements.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Only Sampling One Light&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;In SampleLights() we loop through all the lights, and get their contribution. For a small number of lights, this is fine, but for hundreds or thousands of lights, this gets expensive. Fortunately, we can exploit the fact that Monte Carlo Integration is a giant average. Example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's define &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$h(x) = f(x) + g(x)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, we're estimating $h(x)$ by:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$h(x) = \frac{1}{N} \sum_{i=1}^N f(x_i) + g(x_i)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, calculating both $f(x)$ and $g(x)$ is expensive, so instead we do:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$h(x) = \frac{1}{N} \sum_{i=1}^N \frac{r(\zeta, x)}{pdf}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $\zeta$ is a uniform random variable, and $r(\zeta, x)$ is defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$r(\zeta, x) = &#xA;\begin{cases}&#xA;  f(x), &amp;amp; 0.0 \leq \zeta \lt 0.5 \\&#xA;  g(x), &amp;amp; 0.5 \leq \zeta \lt 1.0&#xA;\end{cases}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case $pdf = \frac{1}{2}$ because the pdf must integrate to 1, and there are 2 functions to choose from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In English:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Randomly choose either $f(x)$ or $g(x)$ to evaluate. &lt;/li&gt;&#xA;&lt;li&gt;Divide the result by $\frac{1}{2}$ (since there are two items)&lt;/li&gt;&#xA;&lt;li&gt;Average&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;As N gets large, the estimate will converge to the correct solution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can apply this same principle to light sampling. Instead of sampling every light, we randomly pick one, and multiply the result by the number of lights (This is the same as dividing by the fractional pdf):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 SampleOneLight(UniformSampler *sampler, SurfaceInteraction interaction, BSDF *bsdf, Light *hitLight) const {&#xA;    std::size_t numLights = m_scene-&amp;gt;NumLights();&#xA;&#xA;    // Return black if there are no lights&#xA;    // And don't let a light contribute light to itself&#xA;    // Aka, if we hit a light&#xA;    // This is the special case where there is only 1 light&#xA;    if (numLights == 0 || numLights == 1 &amp;amp;&amp;amp; hitLight != nullptr) {&#xA;        return float3(0.0f);&#xA;    }&#xA;&#xA;    // Don't let a light contribute light to itself&#xA;    // Choose another one&#xA;    Light *light;&#xA;    do {&#xA;        light = m_scene-&amp;gt;RandomOneLight(sampler);&#xA;    } while (light == hitLight);&#xA;&#xA;    return numLights * EstimateDirect(light, sampler, interaction, bsdf);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In this code, all the lights have an equal chance of being picked. However, we can importance sample, if we like. For example, we can give larger lights a higher chance of being picked, or lights closer to the hit surface. You just have to divide the result by the pdf, which would no longer be $\frac{1}{\text{numLights}}$.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Multiple Importance Sampling the &quot;New Ray&quot; Direction&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The current code only importance samples the &quot;New Ray&quot; direction based on the BSDF. What if we want to also importance sample based on the location of lights?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Taking from what we learned above, one method would be to shoot &lt;strong&gt;two&lt;/strong&gt; &quot;new&quot; rays and weight each based on their pdfs. However, this is both computationally expensive, and hard to implement without recursion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To overcome this, we can apply the same principles we learned by sampling only one light. That is, randomly choose one to sample, and divide by the pdf of choosing it.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Get the new ray direction&#xA;&#xA;// Randomly (uniform) choose whether to sample based on the BSDF or the Lights&#xA;float p = sampler-&amp;gt;NextFloat();&#xA;&#xA;Light *light = m_scene-&amp;gt;RandomLight();&#xA;&#xA;if (p &amp;lt; 0.5f) {&#xA;    // Choose the direction based on the bsdf &#xA;    material-&amp;gt;bsdf-&amp;gt;Sample(interaction, sampler);&#xA;    float bsdfPdf = material-&amp;gt;bsdf-&amp;gt;Pdf(interaction);&#xA;&#xA;    float lightPdf = light-&amp;gt;PdfLi(m_scene, interaction);&#xA;    float weight = PowerHeuristic(1, bsdfPdf, 1, lightPdf);&#xA;&#xA;    // Accumulate the throughput&#xA;    throughput = throughput * weight * material-&amp;gt;bsdf-&amp;gt;Eval(interaction) / bsdfPdf;&#xA;&#xA;} else {&#xA;    // Choose the direction based on a light&#xA;    float lightPdf;&#xA;    light-&amp;gt;SampleLi(sampler, m_scene, interaction, &amp;amp;lightPdf);&#xA;&#xA;    float bsdfPdf = material-&amp;gt;bsdf-&amp;gt;Pdf(interaction);&#xA;    float weight = PowerHeuristic(1, lightPdf, 1, bsdfPdf);&#xA;&#xA;    // Accumulate the throughput&#xA;    throughput = throughput * weight * material-&amp;gt;bsdf-&amp;gt;Eval(interaction) / lightPdf;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That all said, do we really &lt;strong&gt;&lt;em&gt;want&lt;/em&gt;&lt;/strong&gt; to importance sample the &quot;New Ray&quot; direction based on the light? For &lt;em&gt;direct&lt;/em&gt; lighting, the radiosity is affected by both the BSDF of the surface, and the direction of the light. But for &lt;em&gt;indirect&lt;/em&gt; lighting, the radiosity is almost exclusively defined by the BSDF of the surface hit before. So, adding light importance sampling doesn't give us anything. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, it is common to only importance sample the &quot;New Direction&quot; with the BSDF, but apply Multiple Importance Sampling to the direct lighting.&lt;/p&gt;&#xA;" OwnerUserId="310" LastEditorUserId="310" LastEditDate="2017-05-25T18:56:47.003" LastActivityDate="2017-05-25T18:56:47.003" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="5155" PostTypeId="2" ParentId="5099" CreationDate="2017-05-26T02:10:08.607" Score="1" Body="&lt;p&gt;I would have done it with a script and &lt;a href=&quot;https://en.wikipedia.org/wiki/Netpbm&quot; rel=&quot;nofollow noreferrer&quot;&gt;NETPBM&lt;/a&gt; like so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) reducing Image1 (the tiles) to size X by X -&gt; Image1R &lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) recording the mapping from pixel values of Image1R to coordinates (no need to worry about duplicates as an exact RGB match of two or more averaged pixels is unlikely)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) remapping Image2 using Image1R as the color map -&gt; Image2M&lt;/p&gt;&#xA;&#xA;&lt;p&gt;4) reading pixels of Image2M, consulting the map, and picking the tile corresponding to the coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;5) concatenating the selected tiles across and down&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a separate tool for all the above image manipulations in NETPBM.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any scripting language that allows spawning other processes and supports associative arrays, would do.&lt;/p&gt;&#xA;" OwnerUserId="6705" LastEditorUserId="6705" LastEditDate="2017-05-26T03:15:06.213" LastActivityDate="2017-05-26T03:15:06.213" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5156" PostTypeId="1" CreationDate="2017-05-26T02:46:35.170" Score="3" ViewCount="89" Body="&lt;p&gt;I have a JPEG file with a &lt;a href=&quot;https://www.dropbox.com/s/01ygrkzlhylu612/ACPU-128.jpg?dl=0&quot; rel=&quot;nofollow noreferrer&quot;&gt;200 dpi scan of a sample printout&lt;/a&gt; from a &lt;strong&gt;badly maintained&lt;/strong&gt; old drum printer. I was able to segment it and to collect &lt;a href=&quot;https://www.dropbox.com/s/doc2bzh155mey26/tiles.zip?dl=0&quot; rel=&quot;nofollow noreferrer&quot;&gt;all instances of each letter together&lt;/a&gt;, for example&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZJqH0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZJqH0.png&quot; alt=&quot;Letters A&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/rFNd6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rFNd6.png&quot; alt=&quot;Letters G&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/x3BwS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/x3BwS.png&quot; alt=&quot;Letters Q&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dEohV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dEohV.png&quot; alt=&quot;Letters W&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I would like to recreate its font; as the first step I've written a utility that estimates the shift amount (in pixels) between two images using MSE, then weighted-averages them according to that shift amount, and continues until all instances of a character have been processed.&lt;/p&gt;&#xA;&lt;p&gt;My results look like&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nuumF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nuumF.png&quot; alt=&quot;Sample result&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Is this the best I can hope for, or are there smarter algorithms that are able to deal with low-quality samples?&lt;/p&gt;&#xA;&lt;p&gt;Specifically, I would like to get rid of the ink smear at the top of the characters due to the rotational momentum of the drum with respect to the hammers.&lt;/p&gt;&#xA;&lt;p&gt;(As far as I understand, &lt;a href=&quot;https://en.wikipedia.org/wiki/Super-resolution_imaging&quot; rel=&quot;nofollow noreferrer&quot;&gt;super-resolution&lt;/a&gt; is not a good match for this task, and I couldn't find a good open source implementation of it.)&lt;/p&gt;&#xA;&lt;p&gt;The second step is to use &lt;a href=&quot;https://en.wikipedia.org/wiki/Potrace&quot; rel=&quot;nofollow noreferrer&quot;&gt;Potrace&lt;/a&gt;, of course.&lt;/p&gt;&#xA;" OwnerUserId="6705" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-05-27T17:35:20.040" Title="Recreating a font from a low-quality printout" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5157" PostTypeId="2" ParentId="5140" CreationDate="2017-05-27T12:47:12.710" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TTgLw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TTgLw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After thinking about it for some days I came up with a proof sketch (which is hopefully correct) that it is possible to use Gouraud shading on disconnected triangles, if they share an edge with the same normals as in the picture. The simple idea of this proof is to check that there is no discontinuity between the intensity of the triangles by approaching from each side to the edge. So given two triangles $T_1: (P_1,P_2,P_3)$ and $T_2: (P_1', P_2', P_3')$ which share an edge and let's assume w.l.o.g. that this edges are constructed by $(P_2,P_3)$ and $(P_2', P_3')$. Because Gouraud shading only computes the light intensity at the vertex positions and interpolate in between them, it's save to assume that the intensity at $P_2$ is the same as on $P_2'$, same goes for $P_3$ and $P_3'$. Because it's also save to assume that the values inside the triangles are getting computed correctly so it's only necessary to show that there is no discontinuity between the triangles. To interpolate inside the triangle it's rational to use Barycentric coordinates so that the intensity at any point inside the triangle is given by&#xA;\begin{align*}&#xA;	I  &amp;amp;= aI_2   + bI_3   + (1 - (a+b)) I_1\\&#xA;	I' &amp;amp;= a'I_2' + b'I_3' + (1 - (a'+b')) I_1'&#xA;\end{align*}&#xA;By now going from $I_1$ respectively $I_1'$ to the edge, a sequence can be constructed to archive this, by setting $a_n = \frac{c}{n+1}, b_n=\frac{d}{n+1}, c + d = 1$ and analogously for $a_n', b_n'$. Then the intensity is&#xA;\begin{align*}&#xA;	I_n  &amp;amp;= \frac{c}{n+1} I_2  + \frac{d}{n+1} I_3  + (1 - \frac{c+d}{n+1}) I_1\\&#xA;	I_n' &amp;amp;= \frac{c'}{n+1}I_2' + \frac{d'}{n+1}I_3' + (1 - \frac{c'+d'}{n+1}) I_1'&#xA;\end{align*}&#xA;If one now approaches the edge with:&#xA;\begin{align*}&#xA;	&amp;amp;\lim\limits_{n\rightarrow 0^+} I_n = cI_2 + dI_3\\&#xA;	&amp;amp;\lim\limits_{n\rightarrow 0^+} I_n' = c'I_2 + d'I_3'&#xA;\end{align*}&#xA;and using the requirement that $I_n$ and $I_n'$ share the same position $P_n$ if they are on an edge, which can be constructed by&#xA;\begin{align*}&#xA;	P_n &amp;amp;= \frac{c}{n+1} P_2  + \frac{d}{n+1} P_3  + (1 - \frac{c+d}{n+1}) P_1\\&#xA;	P_n &amp;amp;= \frac{c'}{n+1}P_2' + \frac{d'}{n+1}P_3' + (1 - \frac{c'+d'}{n+1}) P_1'&#xA;\end{align*}&#xA;with the fact that $P_2 =P_2'$ and $P_3 = P_3'$ it follows:&#xA;\begin{align*}&#xA;	&amp;amp;\lim\limits_{n\rightarrow 0^+} P_n = cP_2 + dP_3\\&#xA;	&amp;amp;\lim\limits_{n\rightarrow 0^+} P_n' = c'P_2 + d'P_3&#xA;\end{align*}&#xA;and $d = 1 - c$&#xA;\begin{align*}&#xA;	&amp;amp;\lim\limits_{n\rightarrow 0^+} P_n = cP_2 + (1-c)P_3\\&#xA;	&amp;amp;\lim\limits_{n\rightarrow 0^+} P_n' = c'P_2 + (1-c')P_3&#xA;\end{align*}&#xA;this results in $c = c'$ and therefore this gives the final result:&#xA;\begin{align*}&#xA;	\lim\limits_{n\rightarrow 0^+} I_n = cI_2 + (1-c)I_3 = c'I_2' + (1-c')I_3' = \lim\limits_{n\rightarrow 0^+}I_n'&#xA;\end{align*}&#xA;Thereby is possible to use Gouraud shading over disconnected triangles as in my case, because the intensity on the edge is the same on both triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What actually happened in my case was that the normals differs slightly (thank you @Rahul for the tip) which therefore results in this strange look. I fixed them by averaging the normals over a small radius to ensure&#xA;the proper set up of the normals.&lt;/p&gt;&#xA;" OwnerUserId="6682" LastEditorUserId="6682" LastEditDate="2017-05-27T17:46:29.623" LastActivityDate="2017-05-27T17:46:29.623" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5160" PostTypeId="1" CreationDate="2017-05-27T16:37:52.760" Score="2" ViewCount="395" Body="&lt;p&gt;Is there a material table that lists all the specific values to obtain a certain type of material (e.g: copper or asphalt) available? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found this table in the paper: &lt;a href=&quot;http://inst.cs.berkeley.edu/~cs294-13/fa09/lectures/cookpaper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Reflectance Model for Computer Graphics&lt;/a&gt;. However, it doesn't really seem to have all the materials I would like to use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eX6TB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eX6TB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I am looking for a material table for use in a Path Tracer.&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-05-27T16:37:52.760" Title="Is there a material table for the Cook Torrance BRDF?" Tags="&lt;brdf&gt;&lt;physically-based&gt;&lt;pbr&gt;&lt;material&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5161" PostTypeId="1" CreationDate="2017-05-27T17:06:03.013" Score="1" ViewCount="122" Body="&lt;p&gt;I'm adding photon mapping to my current raytracer to add indirect lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone explain how the radiance estimate works in simple terms and with some simple math? I have read a lot of documents about it online, but the math is beyond my understanding so far. I have used Lambertian and Phong shading in my raytracer, so I'm thinking of using that. Next, how do you add up the power of nearby photons at a point? I see a lot of papers that say you have to divide by the number of photons shot, but doesn't that reduce the power of a photon by way too much? (say divide it by a million photons...)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TLDR: Explain how radiance estimate works in detail but with simple math.&lt;/p&gt;&#xA;" OwnerUserId="6715" LastActivityDate="2017-05-27T17:06:03.013" Title="Explain Radiance Estimate for photon mapping" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;photon-mapping&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5166" PostTypeId="1" AcceptedAnswerId="5177" CreationDate="2017-05-28T12:14:54.733" Score="2" ViewCount="843" Body="&lt;p&gt;How can I a find the Light Direction/Ray from a Point on a surface to an Area Light? Is there a universal technique to do this for all types of lights (circle, rectangle, sphere &amp;amp; tube)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although this is for area lighting in a ray tracer, is there another way to implement area lighting through an emissive value that I can apply to any object or surface (I have seen this mentioned online)? As opposed to doing it like this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example for a point light I know it can be done like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class PointLight : public Light &#xA;{ &#xA;    Vec3f pos; &#xA;public: &#xA;    PointLight(const Matrix44f &amp;amp;l2w, const Vec3f &amp;amp;c = 1, const float &amp;amp;i = 1) : Light(l2w, c, i) &#xA;    { l2w.multVecMatrix(Vec3f(0), pos); } &#xA;    // P: is the shaded point&#xA;    void getDirectionAndIntensity(const Vec3f &amp;amp;P, Vec3f &amp;amp;lightDir, Vec3f &amp;amp;lightIntensity) const &#xA;    { &#xA;        lightDir = pos - P; // compute light direction &#xA;        float r2 = lightDir.norm(); &#xA;        lightDir.normalize(); &#xA;        lightIntensity = intensity * color / (4 * M_PI * r2); &#xA;    } &#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2017-05-28T12:29:28.813" LastActivityDate="2017-05-30T13:36:02.933" Title="How to find Light Direction from a Point on a surface to an Area Light" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;pathtracing&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5167" PostTypeId="2" ParentId="5166" CreationDate="2017-05-28T13:33:44.313" Score="0" Body="&lt;p&gt;One way to achieve this, is using the same approach as POV-Ray wich uses multiple point lights to create an area light (as mentioned &lt;a href=&quot;http://www.povray.org/documentation/view/3.6.2/38/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;) by aligning them into an array. This should also work for arbitrary surfaces if you approximate them through point lights. This has also the benefit that you don't need to change much of your code.&lt;/p&gt;&#xA;" OwnerUserId="6682" LastActivityDate="2017-05-28T13:33:44.313" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5168" PostTypeId="1" CreationDate="2017-05-28T17:17:58.473" Score="5" ViewCount="220" Body="&lt;p&gt;Look at this image:&lt;a href=&quot;https://i.stack.imgur.com/jVP0a.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jVP0a.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is CG, Saya, a project meant to make as real CG as possible to the point of becoming indistinguishable from reality. I would say that it is pretty believable. But, it still doesn't seem real enough, something's missing. And I don't know what it is. And it drives me nuts. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not saying that CG has to do reality, I am personaly fond of stylization, but I really want to know why we can't get a 3d image just right yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it the light? The clothing? The lines above the lip, too defined?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any insights would be appreciated.&lt;/p&gt;&#xA;" OwnerUserId="6722" LastEditorUserId="231" LastEditDate="2017-05-29T12:45:46.750" LastActivityDate="2017-05-29T21:42:20.827" Title="What is missing in this image that stops it from looking like a photograph?" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;3d&gt;&lt;lighting&gt;" AnswerCount="2" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5169" PostTypeId="1" AcceptedAnswerId="5173" CreationDate="2017-05-29T10:53:30.840" Score="5" ViewCount="634" Body="&lt;p&gt;I'm following &lt;a href=&quot;https://learnopengl.com/#!Getting-started/Coordinate-Systems&quot; rel=&quot;noreferrer&quot;&gt;this tutorial&lt;/a&gt; on the perspective projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; If the point of a perspective projection is to create the perspective effect (where objects faraway appear to be smaller):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W1LpU.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W1LpU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then why does it generate a frustrum in which the &lt;strong&gt;back&lt;/strong&gt; is larger than the &lt;strong&gt;front&lt;/strong&gt;? Should it be the other way around?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jBNlH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jBNlH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5225" LastActivityDate="2017-05-29T13:22:58.040" Title="Why is the back of a perspective frustrum larger than the front?" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5170" PostTypeId="2" ParentId="5169" CreationDate="2017-05-29T11:05:43.390" Score="3" Body="&lt;p&gt;It is bigger because it fills the same view and it ts further away. It would be smaller if it wouldn't fill the same view but then it wouldn't fill the camera view and it wouldnt work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the inverse relation applies. If you want something to stay constant in size in the view then it needs to grow as it gets further. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your just comparing apples with oranges. &lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-05-29T11:10:49.933" LastActivityDate="2017-05-29T11:10:49.933" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5172" PostTypeId="2" ParentId="5169" CreationDate="2017-05-29T12:32:11.353" Score="1" Body="&lt;p&gt;if you place your hand by your ear, you can't see it ... now then if you move it forward, suddenly you'll start seeing it ... this is what the frustrum represents, as in your second picture... &lt;/p&gt;&#xA;" OwnerUserId="6727" LastActivityDate="2017-05-29T12:32:11.353" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5173" PostTypeId="2" ParentId="5169" CreationDate="2017-05-29T13:22:58.040" Score="5" Body="&lt;p&gt;It might help to think of it this way:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both the near plane and the far plane are the size that will fit onto the screen you are viewing on. The further away something is, the bigger it can be and still fit on the screen. Close up, a playing card can fill the whole screen, but in the distance, an entire building can fit on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the example image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jBNlH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jBNlH.png&quot; alt=&quot;image of near and far plane&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If a playing card exactly fills the near plane, then you will be able to fit 4 playing cards on the far plane. This reflects the fact that when a playing card is twice as far from the camera, it appears to have half the height and width.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think of the near plane and the far plane as simply the area that will fit on your screen. The further away you point your camera, the more will fit on the screen. This matches up with the fact that things look smaller in the distance - this means you can fit bigger things on the screen if they are further away.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2017-05-29T13:22:58.040" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5174" PostTypeId="2" ParentId="5168" CreationDate="2017-05-29T13:34:06.867" Score="6" Body="&lt;ul&gt;&#xA;&lt;li&gt;The hair seems to have sampling noise or aliasing in it. This &lt;em&gt;might&lt;/em&gt; be poor jpeg compression but it does not look like it.&lt;/li&gt;&#xA;&lt;li&gt;I've never seen hair part that way (could just be me).&lt;/li&gt;&#xA;&lt;li&gt;The neck looks a little too regular (I'm no modeler though).&lt;/li&gt;&#xA;&lt;li&gt;The skin's subsurface scattering falls a bit short. Perhaps it's not that but there is something slightly off about the skin.&lt;/li&gt;&#xA;&lt;li&gt;The shirt has a slight plastic feel to it.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Most of this is entirely subjective of course. I think it's fairly good but falls short of the state of the art in many areas.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-05-29T13:34:06.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5175" PostTypeId="2" ParentId="5168" CreationDate="2017-05-29T21:22:31.583" Score="2" Body="&lt;p&gt;I suppose you'd like to hear the first impression, so to say.&#xA;So here are most notable features that uncover the 'synthetic' nature of the image (for my eye).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Too smooth textures on the shirt. In real world &#xA;every textile is imperfect, regardless how smooth it is and how good the lights are set up.&#xA;There is always visible 'grain' and imperfection of textures, but i suppose it is next to impossible&#xA;to model due to complexity of real shadow plays. &#xA;So on this image the shirt has most noticable &quot;plastic&quot; look.&#xA;Face is a bit too smooth textured, but this could be percieved as, say too much cosmetics. So&#xA;in general the head looks quite real.&lt;/li&gt;&#xA;&lt;li&gt;Shadows, contrast. Every detail of real objects has very different contrast zones of shadows. &#xA;Here again on the shirt around the neck and especially near the stud:  there is simply too little&#xA;contrast diversity or too simple shadows, as if the objects are flat. &lt;/li&gt;&#xA;&lt;li&gt;Focus of the camera. It is rarely seen on real fotos that all parts of the portrait have equally sharp focus&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And something is wrong with her ear, no? but it is hard to say what is it exactly. &lt;/p&gt;&#xA;" OwnerUserId="6160" LastEditorUserId="6160" LastEditDate="2017-05-29T21:42:20.827" LastActivityDate="2017-05-29T21:42:20.827" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5177" PostTypeId="2" ParentId="5166" CreationDate="2017-05-30T13:36:02.933" Score="3" Body="&lt;p&gt;If you want to use only one sample to approximate analytical area lighting (e.g. for real-time applications), you can use Most Representative Point (MRP) approximation as described in &quot;&lt;a href=&quot;https://www.guerrilla-games.com/read/killzone-shadow-fall-creating-art-tools-for-a-new-generation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lighting in Killzone Shadow Fall&lt;/a&gt;&quot;, &quot;&lt;a href=&quot;https://de45xmedrsdbp.cloudfront.net/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real Shading in Unreal Engine 4&lt;/a&gt;&quot; and &quot;&lt;a href=&quot;http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moving Frostbite to PBR&lt;/a&gt;&quot;. This works reasonably well for specular approximation, though the energy conservation is a challenge. What I have found working best is to find a point on a light source with smallest angle from the view reflection vector, and the solution depends on the shape of the light (for example &lt;a href=&quot;https://math.stackexchange.com/questions/1438242/finding-ray-direction-with-smallest-angle-from-a-ray-to-a-rectangle-in-3d&quot;&gt;here's my solution for rectangular lights&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For diffuse evaluation there are numerical and analytical approximations depending on light shape presented in the papers, which also properly handle the horizon case. You can also try to use MRP for diffuse lighting, but I haven't found good approximations for it. Depending your application though diffuse MRP might result in feasible quality.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's also some more recent work for evaluating area lighting integrals not using MRP. &quot;&lt;a href=&quot;http://jmarvie.free.fr/Publis/2016_I3D/i3d_2016_AccurateAnalyticApproximationsForReal-TimeSpecularAreaLighting.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Accurate Analytic Approximations For Real-Time Specular Area Lighting&lt;/a&gt;&quot; deals with the specular evaluation via edge integrals, though I recall this method is patented. &quot;&lt;a href=&quot;https://eheitzresearch.wordpress.com/415-2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real-Time Polygonal-Light Shading with Linearly Transformed Cosines&lt;/a&gt;&quot; looks quite promising, but I haven't checked the paper in more details.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For non-real time applications and ray tracing area lighting is fundamentally and mathematically much simpler problem. For your integrator you just check the incident radiance at each sample (ray intersection with the scene) and accumulate results for total radiance towards the output direction. The challenge is how to reduce variance of your integrator, but getting basic area lighting to work in a ray tracer is relatively simple.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-05-30T13:36:02.933" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5178" PostTypeId="1" CreationDate="2017-05-30T15:05:58.273" Score="4" ViewCount="87" Body="&lt;p&gt;How is measured BRDF data recorded? Like the &lt;a href=&quot;https://www.merl.com/brdf/&quot; rel=&quot;noreferrer&quot;&gt;MERL BRDF Database&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What kind of equipment is used and what are the key values that need to be recorded?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know one place this data was used was in the &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;noreferrer&quot;&gt;Disney PBR paper&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-05-30T15:52:40.287" Title="How is measured BRDF data recorded?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5179" PostTypeId="2" ParentId="5178" CreationDate="2017-05-30T15:52:40.287" Score="2" Body="&lt;p&gt;Section 6 of &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt; has a good description of how they did it to validate their own model. That may not be everything needed to build a full database (eg. more automation) but it's an interesting read.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-05-30T15:52:40.287" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5181" PostTypeId="1" CreationDate="2017-05-30T19:47:21.487" Score="2" ViewCount="101" Body="&lt;p&gt;How are fluid simulations handled in Computer Graphics? For a novice, there are hardly any novice friendly tutorials explaining how particles or fluids can be simulated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things like smoke, crown splashes and fog are they animated by artists as opposed to physically based simulations? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there are any worthwhile resources that you could recommend please do! :)&lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-05-30T19:47:21.487" Title="How are fluid simulations handled in Computer Graphics?" Tags="&lt;animation&gt;&lt;pbr&gt;&lt;simulation&gt;&lt;fluid-sim&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5182" PostTypeId="1" AcceptedAnswerId="5227" CreationDate="2017-05-30T20:47:55.340" Score="7" ViewCount="1364" Body="&lt;p&gt;I've seen a Fresnel equation for calculating the reflection amount at &lt;em&gt;incidence angle&lt;/em&gt; with &lt;em&gt;n&lt;/em&gt; and &lt;em&gt;k&lt;/em&gt; values defined. This formula usually comes up in relation to computer graphics, but I can't find this equation anywhere in a science context. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example written in Python, taken from the website&#xA;&lt;a href=&quot;http://therenderblog.com/custom-fresnel-curves-in-maya-part-2/&quot; rel=&quot;noreferrer&quot;&gt;Fresnel Formula in python&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def IOR(n,k):&#xA;theta_deg = 0&#xA;&#xA;n = n&#xA;k = k&#xA;fresnel = []&#xA;  &#xA;while theta_deg &amp;lt;= 90:&#xA;theta = math.radians(theta_deg)&#xA;&#xA;a = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 + ((4 * n**2) * k**2)) + (n**2 - k**2 - (math.sin(theta))**2))/2)&#xA;&#xA;b = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 + ((4 * n**2) * k**2)) - (n**2 - k**2 - (math.sin(theta))**2))/2)&#xA;  &#xA;Fs = (a**2+b**2-(2 * a * math.cos(theta))+(math.cos(theta))**2)/(a**2+b**2+(2 * a * math.cos(theta))+(math.cos(theta))**2)&#xA;Fp = Fs * ((a**2+b**2-(2 * a * math.sin(theta) * math.tan(theta))+(math.sin(theta))**2*(math.tan(theta))**2)/(a**2+b**2+(2 * a * math.sin(theta) * math.tan(theta))+(math.sin(theta))**2*(math.tan(theta))**2))&#xA;R = (Fs + Fp)/2&#xA;fresnel.append(R)&#xA;&#xA;theta_deg += 1&#xA;return fresnel&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I can't find any references online for this formula, the Wikipedia article on &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;noreferrer&quot;&gt;Fresnel equations&lt;/a&gt; contains completely different formulas, and I can't see the connection between them. I've searched high and low, but can't find any reference to this particular formula, why is that? Can you help me find it, or explain to me why I can't find it online? Or could you show me how to derive it from the Fresnel formulas from the Wikipedia article?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, I realize that I already have the formula right there in the code sample. But I'm baffled over why I can't find this formula anywhere, I would like to have more sources to cite then just this code example.&lt;/p&gt;&#xA;" OwnerUserId="2736" LastEditorUserId="231" LastEditDate="2017-05-31T09:20:12.810" LastActivityDate="2018-03-07T02:57:52.767" Title="Fresnel equation with incident angle, n and k as input" Tags="&lt;reflection&gt;&lt;fresnel&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5183" PostTypeId="1" AcceptedAnswerId="5202" CreationDate="2017-05-31T03:54:49.040" Score="5" ViewCount="134" Body="&lt;p&gt;I read &lt;a href=&quot;https://www.autodeskresearch.com/pdf/ns.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Stable Fluids&lt;/a&gt; and &lt;a href=&quot;https://www.autodeskresearch.com/sites/default/files/TheArtOfFluidAnimationCode.zip&quot; rel=&quot;nofollow noreferrer&quot;&gt;the code&lt;/a&gt; by Jos Stam and &lt;a href=&quot;http://www.cs.uu.nl/docs/vakken/mgp/2013-2014/literature/Fluid%20Simulation.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;FLUID SIMULATION SIGGRAPH 2007 Course Notes&lt;/a&gt; by Robert Bridson. The boundary conditions in the two papers are different in my sight. I don't understand them. How are these two ways related to solving a linear system of PDEs with boundary conditions? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Stam's paper, he uses a function called &lt;code&gt;set_bnd&lt;/code&gt; to set boundaries, so is this function just setting the boundaries that I need in my matrix of linear systems of Pressure Poisson and Diffuse Equation? In Numerical Analysis, we don't modify the matrix with the boundary values, but we put the boundary condition either it's a Neumann or Dirichlet. I don't really understand what kind of boundaries is this &lt;code&gt;set_bnd&lt;/code&gt; function. My thinking now is that it sets the boundary values which will be used to solve linear systems but what kind of boundaries?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Bridson's paper, I don't find any implementation about boundaries except for speaking about the normal components of velocity. Actually, I can't find any relation between this and Stam's way. In the section on making fluid incompressible, he says something about boundaries but I don't understand. He just satisfies boundary conditions on the boundary cells then he solves the system or he put the boundaries in the matrix?&#xA;Actually I don't know how to satisfy &lt;code&gt;u*n = u_solid * n&lt;/code&gt; which I think is the no stick boundaries for interacting between a fluid and solid boundaries.&lt;/p&gt;&#xA;" OwnerUserId="4978" LastEditorUserId="4978" LastEditDate="2017-06-05T02:17:54.003" LastActivityDate="2017-06-05T20:29:23.180" Title="Rigorous and simple explanation for satisfying boundary conditions in Stam and Bridson papers" Tags="&lt;fluid-sim&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5184" PostTypeId="1" CreationDate="2017-05-31T13:18:02.727" Score="3" ViewCount="369" Body="&lt;p&gt;Can somebody help explain the mathematics of Sub Surface Scattering in a Path Tracer based on the Diffuse Approximation in &lt;strong&gt;&lt;a href=&quot;http://www.graphics.stanford.edu/papers/bssrdf/&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Practical Model for Subsurface Light Transport&lt;/a&gt;&lt;/strong&gt; ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like someone to explain the mathematics a little more clearly (why we need both the Fresnel terms, the diffusion profile, why we multiply everything by 1/π) and show me what I need to put together finally in Pseudocode. The symbols in all of the equations are also confusing (I'm still doing high school math), so any definition for each symbol would be great. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Along with that, I had a few simpler questions.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Why do we approximate the BSSRDF as a BRDF? Is it because the outgoing rays are usually isotropic? What are the main differences in mathematics between the original and approximation? &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Can this BSSRDF approximation be importance sampled?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Currently I have an understanding of how everything works based on this &lt;strong&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/81/what-is-the-dipole-approximation-for-subsurface-scattering&quot;&gt;post&lt;/a&gt;&lt;/strong&gt; from a while back which is a good explanation. However, when it comes to implementation and all the overwhelming mathematics I get very confused. Can someone help me? I haven't been able to find a beginner friendly resource online so I hoped someone here could share their knowledge. &lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2017-06-01T16:59:20.137" LastActivityDate="2017-06-01T16:59:20.137" Title="Mathematics of Sub Surface Scattering" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;pbr&gt;&lt;subsurface-scattering&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5185" PostTypeId="1" CreationDate="2017-05-31T16:21:37.193" Score="14" ViewCount="884" Body="&lt;p&gt;I'm discovering the wonderful world of math and I'm hitting a huge wall with PBR and naming so I have a few questions:&#xA;As far as I understand BRDF describe how a material react to light (incoming direct light and reflections). But in &quot;Cook-Torrance&quot; I don't see anything about reflections I don't understand how I integrate it so I only get diffuse light and reflections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read a lot about different &quot;diffuse term&quot; like &quot;Oren-Nayar&quot; is it a part of Cook-Torrance like a different &quot;D&quot; in the DFG nominator ? does it replace it without specular calculations ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read a lot about &quot;GGX&quot; from my blender artist background I thought it was something that make a blurry reflection but It seems I was wrong and now I find this GGX term in a lot of different situations like in micro-facet normal distribution in this &lt;a href=&quot;http://learnopengl.com/#!PBR/Lighting&quot; rel=&quot;noreferrer&quot;&gt;tutorial&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in short the question is: how &quot;Oren-Nayar&quot; and &quot;GGX&quot; and &quot;Cook-Torrance&quot; are related to each other (if they are) and how do I integrate &quot;vec3 reflection&quot; in those algorithm ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I said before I'm a newbie in math so If your answer is &quot;math heavy&quot; please write a glsl/hlsl version of your equations it's much easier to understand for me so an equivalence will help me a lot&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I understand my question is blurry but it is also as blurry as my understanding of the subject.&lt;/p&gt;&#xA;" OwnerUserId="5506" LastEditorUserId="110" LastEditDate="2017-06-06T09:40:14.763" LastActivityDate="2017-06-06T09:40:14.763" Title="Confused with PBR implementations" Tags="&lt;glsl&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5186" PostTypeId="1" AcceptedAnswerId="5364" CreationDate="2017-05-31T16:44:02.317" Score="4" ViewCount="651" Body="&lt;p&gt;I was reading the Wikipedia entry on Marching Squares, and was confused by the explanation of the saddle point disambiguation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambiguous Case:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yMvup.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yMvup.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, given the saddle points, the ambiguity is resolved by using the average data value for the center of the cell. I don't understand why this would help resolve the ambiguity. It seems to just select the longer pair of lines over the shorter pair. Is there any reason for this approach?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Marching_squares#Disambiguation_of_saddle_points&quot; rel=&quot;noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Marching_squares#Disambiguation_of_saddle_points&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerDisplayName="user6750" LastActivityDate="2017-07-15T09:23:39.413" Title="Explanation of the Marching Squares saddle points resolution" Tags="&lt;algorithm&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5187" PostTypeId="1" AcceptedAnswerId="5188" CreationDate="2017-06-01T01:55:28.263" Score="3" ViewCount="321" Body="&lt;p&gt;In &lt;a href=&quot;https://www.khronos.org/opengl/wiki/GLSL_:_common_mistakes#Functions_inputs_and_outputs&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLSL: Common Mistakes&lt;/a&gt; it states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Functions parameters must be declared with the &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;out&lt;/code&gt;, or &lt;code&gt;inout&lt;/code&gt; qualifiers.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;but I have never declared function parameters with &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;out&lt;/code&gt;, or &lt;code&gt;inout&lt;/code&gt; qualifiers and I have never run into any problems. Could this be because of my specific graphics card? What are the side effects of not using the &lt;code&gt;in&lt;/code&gt;, &lt;code&gt;out&lt;/code&gt;, or &lt;code&gt;inout&lt;/code&gt; qualifiers?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Info: I am using GLSL 3.3 and I have an Intel graphics card&lt;/p&gt;&#xA;" OwnerUserId="6546" LastActivityDate="2017-06-01T09:08:45.190" Title="GLSL function parameters" Tags="&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5188" PostTypeId="2" ParentId="5187" CreationDate="2017-06-01T04:29:24.750" Score="5" Body="&lt;p&gt;&lt;a href=&quot;https://khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.40.pdf&quot; rel=&quot;noreferrer&quot;&gt;The GLSL Specification&lt;/a&gt; in section 6.1.1 &amp;quot;Function Calling Conventions&amp;quot; states:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;The keyword &lt;strong&gt;in&lt;/strong&gt; is used as a qualifier to denote a parameter is to be copied in, but not copied out.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The keyword &lt;strong&gt;out&lt;/strong&gt; is used as a qualifier to denote a parameter is to be copied out, but not copied in. This should be used whenever possible to avoid unnecessarily copying parameters in.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The keyword &lt;strong&gt;inout&lt;/strong&gt; is used as a qualifier to denote the parameter is to be both copied in and copied out. It means the same thing as specifying both in and out.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A function parameter declared with no such qualifier means the same thing as specifying &lt;strong&gt;in&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-06-01T09:08:45.190" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5189" PostTypeId="2" ParentId="5182" CreationDate="2017-06-01T09:50:21.427" Score="4" Body="&lt;p&gt;This is the complex number version of refraction, were K is the extinction coefficient. This is commonly used for metals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can check the Wikipedia on refraction:  &lt;a href=&quot;https://en.wikipedia.org/wiki/Refractive_index#Complex_refractive_index&quot; rel=&quot;nofollow noreferrer&quot;&gt;Complex refractive index | Wikipedia&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorDisplayName="user7220" LastEditDate="2018-03-07T02:57:52.767" LastActivityDate="2018-03-07T02:57:52.767" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5191" PostTypeId="1" AcceptedAnswerId="5193" CreationDate="2017-06-01T11:31:58.113" Score="7" ViewCount="1264" Body="&lt;p&gt;Ambient Occlusion is a physical approximation to occlude ambient light. If ambient light is not considered post-processing, why is AO? Ambient occlusion has the same inputs as regular deferred lighting, plus kernels and a noise map, but essentially, it can be handled the same way. Is there a reason why it's considered post-processing and deferred lighting/shading isn't?&lt;/p&gt;&#xA;" OwnerUserId="5026" LastActivityDate="2017-06-05T01:48:38.677" Title="Why is AO considered Post-Processing?" Tags="&lt;ambient-occlusion&gt;&lt;post-processing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5192" PostTypeId="1" AcceptedAnswerId="5723" CreationDate="2017-06-01T13:41:12.970" Score="9" ViewCount="892" Body="&lt;p&gt;You can have blue noise sampling like these poisson disc samples:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/DrzFt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DrzFt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And you can have a blue noise texture like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CgvI3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CgvI3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get that in the first image, there is one input (the index of the sample) and two outputs (the x,y coordinate of the point) and that the second image is basically the reverse where there are two inputs (the x,y coordinate of the sample) and one output (the value of the point).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm curious though, how are these related?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you take the DFT of the second image, you can see that it has more high frequency components than low, but I'm not sure how you'd take the DFT of the first set of data points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm wondering if it's possible to take other low discrepancy sequences (say, halton, or jittered grid) and make a texture out of the idea, like the second image?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-06-03T17:09:04.203" LastActivityDate="2017-10-14T00:25:21.527" Title="Link between blue noise sampling and blue noise textures?" Tags="&lt;sampling&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5193" PostTypeId="2" ParentId="5191" CreationDate="2017-06-01T15:43:53.170" Score="10" Body="&lt;p&gt;This is a potentially confusing re-use of terminology. &lt;a href=&quot;https://en.wikipedia.org/wiki/Ambient_occlusion&quot; rel=&quot;noreferrer&quot;&gt;Ambient Occlusion&lt;/a&gt; is not in itself a post processing effect. &lt;a href=&quot;https://en.wikipedia.org/wiki/Screen_space_ambient_occlusion&quot; rel=&quot;noreferrer&quot;&gt;Screen Space Ambient Occlusion&lt;/a&gt; is a post processing effect using the depth buffer to approximate the effects produced by Ambient Occlusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ambient Occlusion is a relatively expensive global method, while Screen Space Ambient Occlusion is the cheaper alternative for real time animation. Only the latter is considered post processing.&lt;/p&gt;&#xA;" OwnerUserId="231" LastActivityDate="2017-06-01T15:43:53.170" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5194" PostTypeId="1" AcceptedAnswerId="5198" CreationDate="2017-06-01T19:27:16.947" Score="3" ViewCount="447" Body="&lt;p&gt;I'm having problems with Ambient Occlusion. I've tried to follow both &lt;a href=&quot;http://john-chapman-graphics.blogspot.com.eg/2013/01/ssao-tutorial.html&quot; rel=&quot;noreferrer&quot;&gt;John Chapman's improvements over the Crytek AO&lt;/a&gt; and &lt;a href=&quot;https://learnopengl.com/#!Advanced-Lighting/SSAO&quot; rel=&quot;noreferrer&quot;&gt;LearnOpenGL's tutorial of it&lt;/a&gt; when I failed to properly obtain the correct result. &lt;a href=&quot;https://i.imgur.com/FbNsq9X.png?1&quot; rel=&quot;noreferrer&quot;&gt;http://i.imgur.com/FbNsq9X.png?1&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the camera turns or moves, the screen flashes consistently though it seems arbitrary. Can anyone tell me what I'm doing wrong?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 140&#xA;&#xA;in vec2 UV;&#xA;in vec4 vRay;&#xA;out vec3 SSAOout;&#xA;&#xA;const int kernelSize = 64;&#xA;&#xA;uniform mat4 projection;&#xA;uniform sampler2D gbuffer0;&#xA;uniform sampler2D gbuffer1;&#xA;uniform sampler2D gbuffer2;&#xA;uniform sampler2D gbuffer3;&#xA;uniform sampler2D noiseTex;&#xA;uniform vec3 kernels[kernelSize];&#xA;&#xA;vec4 ViewPosFromDepth(float depth, vec2 TexCoord) {&#xA;    float z = depth * 2.0 - 1.0;&#xA;&#xA;    vec4 clipSpacePosition = vec4(TexCoord * 2.0 - 1.0, z, 1.0);&#xA;    vec4 viewSpacePosition = invProjMat * clipSpacePosition;&#xA;    viewSpacePosition /= viewSpacePosition.w;&#xA;&#xA;    return viewSpacePosition;&#xA;}&#xA;&#xA;const vec2 noiseScale = vec2(1366.0/4.0, 768.0/4.0);&#xA;&#xA;const float near = 0.1;&#xA;const float far = 100.0;&#xA;&#xA;float LinearizeDepth(float depth)&#xA;{&#xA;    float z = depth * 2.0 - 1.0; // back to NDC &#xA;    return (2.0 * near * far) / (far + near - z * (far - near));    &#xA;}&#xA;&#xA;void main() {&#xA;    vec4 gbuffer0Val = texture(gbuffer0, UV);&#xA;    vec4 gbuffer1Val = texture(gbuffer1, UV);&#xA;    vec4 gbuffer2Val = texture(gbuffer2, UV);&#xA;    vec4 gbuffer3Val = texture(gbuffer3, UV);&#xA;&#xA;    vec3 fragPos    = ViewPosFromDepth(gbuffer0Val.r, UV).rgb;&#xA;    float dist      = LinearizeDepth(gbuffer0Val.r);&#xA;    vec3 normal     = gbuffer1Val.rgb;&#xA;    normal          = decodeNormal(normal);&#xA;    vec3 randomVec  = vec3(2 * texture(noiseTex, UV * noiseScale).rg - 1, 0); &#xA;&#xA;    vec3 tangent   = normalize(randomVec - normal * dot(randomVec, normal));&#xA;    vec3 bitangent = cross(normal, tangent);&#xA;    mat3 TBN       = mat3(tangent, bitangent, normal);&#xA;&#xA;    float bias = 0.025;&#xA;    float radius = 3.0;&#xA;    float occlusion = 0.0;&#xA;&#xA;    for(int i = 0; i &amp;lt; kernelSize; i++) {&#xA;        vec3 sampleKernel = TBN * kernels[i];&#xA;        sampleKernel = fragPos + sampleKernel * radius;&#xA;&#xA;        vec4 offset = vec4(sampleKernel, 1.0);&#xA;        offset      = projection * offset;    // from view to clip-space&#xA;        offset.xyz /= offset.w;               // perspective divide&#xA;        offset.xyz  = offset.xyz * 0.5 + 0.5; // transform to range 0.0 - 1.0&#xA;&#xA;        float sampleDepth = texture(gbuffer0, 1-offset.xy).r;&#xA;        sampleDepth = LinearizeDepth(sampleDepth);&#xA;        float rangeCheck = smoothstep(0.0, 1.0, radius / abs(fragPos.z - sampleDepth));&#xA;        occlusion += (sampleDepth &amp;gt;= sampleKernel.z + bias ? 1.0 : 0.0) * rangeCheck;&#xA;    }&#xA;&#xA;    occlusion = 1.0 - (occlusion / kernelSize);&#xA;    SSAOout = vec3(occlusion);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5026" LastActivityDate="2017-06-02T15:11:04.193" Title="Screen Space Ambient Occlusion Issues" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;ambient-occlusion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5195" PostTypeId="2" ParentId="5185" CreationDate="2017-06-01T19:51:53.180" Score="12" Body="&lt;p&gt;DFG pops up in the family of microfacet based BRDFs. It is simply the product of three terms:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;D : The microfacet distribution.&lt;/li&gt;&#xA;&lt;li&gt;F : The fresnel coefficient.&lt;/li&gt;&#xA;&lt;li&gt;G : The geometric attenuation between microfacets.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;When someone says Cook-Torrance, they usually mean a microfacet BRDF where the distribution (D) is Beckmann, which I think is what the original Cook-Torrance paper was about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GGX is really just a different distribution (D term). GTR is another one. The names are often used as a shortcut to mean a BRDF using that distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now all of these assume specular reflection (or refraction) on the microfacets, hence the fresnel term. If you take a similar idea but use diffuse (lambertian) microfacets, you get the Oren-Nayar BRDF. I think that one is based on a gaussian distribution of the microfacets but I'm not familiar with the details.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2017-06-01T19:51:53.180" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5197" PostTypeId="1" CreationDate="2017-06-02T13:43:56.020" Score="3" ViewCount="326" Body="&lt;p&gt;Suppose I have a set of points in 3D which are all co-planar, and which describe the vertices of a convex polygon. I know the coordinates of all of these vertices, I know the unit normal to the plane of the polygon, and I know the order (in a right-hand sense with respect to the normal) in which the vertices go around the polygon. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also have a polyhedron, which is in general non-convex, and the surface of which is made of triangles. It is a triangle mesh like the one shown &lt;a href=&quot;https://en.wikipedia.org/wiki/Triangle_mesh#/media/File:Dolphin_triangle_mesh.png&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;. It describes a completely enclosed volume (no holes in the surface). I know the coordinates of all the vertices of all the triangles that make up the polyhedron. For a given vertex, I know the list of which triangles it is a vertex of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One other thing I know, which may or may not be useful, is that the polygon lies &quot;in the vicinity of&quot; a particular pair of vertices of the polyhedron, say the ones with indices $i$ and $j$. So if there were to some kind of a search of the surface of the polyhedron, that would be the place to start.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My task is to find the area of the intersection between the polygon and the polyhedron. I believe this is a well-defined quantity. I need an algorithm to calculate this, hopefully efficiently but at this point I'll take anything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My thoughts:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can classify each polygon vertex as either inside or outside the polyhedron. I've written a ray-casting algorithm that computes this fairly accurately and efficiently. That means that each edge of the polygon can be classified as either &quot;both vertices inside&quot;, &quot;both vertices outside&quot;, or &quot;one in, one out.&quot; I can calculate the point of intersection between a given polygon edge and the polyhedron by checking a bunch of nearby triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But that's not enough. For instance, just because both vertices of an edge are inside doesn't mean the whole edge is inside. A &quot;finger&quot; of the polyhedron might intersect an edge without touching either of its endpoints. Furthermore, the polyhedron might intersect the polygon in such a way that it doesn't touch any of the edges at all. Clearly, one must also calculate the intersections between the triangles' edges and the polygon as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It gets a bit too complicated for me at that point, and I'm wondering if there is some established algorithm for this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perhaps something like: Project the polyhedron onto the plane containing the polygon and then... I don't know.&lt;/p&gt;&#xA;" OwnerUserId="6762" LastActivityDate="2017-06-03T22:13:34.263" Title="An algorithm to find the area of intersection between a convex polygon and a 3D polyhedron?" Tags="&lt;computational-geometry&gt;&lt;polygon&gt;" AnswerCount="2" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5198" PostTypeId="2" ParentId="5194" CreationDate="2017-06-02T13:56:28.060" Score="2" Body="&lt;p&gt;You need to be careful about spaces - position and normal need to be in view space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To transform depth into view space position I used &lt;a href=&quot;https://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; method.&#xA;So:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 viewPositionFromDepth(vec2 vTexCoord)&#xA;{&#xA;    float z = texture2D(depthTexture, vTexCoord).r;&#xA;    // Get x/w and y/w from the viewport position&#xA;    float x = vTexCoord.x * 2.0 - 1.0;&#xA;    float y = vTexCoord.y * 2.0 - 1.0;&#xA;    vec4 vProjectedPos = vec4(x, y, z, 1.0f);&#xA;    // Transform by the inverse projection matrix&#xA;    vec4 vPositionVS = invProjection*vProjectedPos;&#xA;    // Divide by w to get the view-space position&#xA;    return vPositionVS.xyz / vPositionVS.w;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To transform normal into view space you need to multiply it by transpose of inverse of view matrix (should be done on CPU):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 n = transpose(inverse(ViewMatrix)) * normalize(texture2D(normalTexture, texCoord)*2.0 - 1.0 );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And in loop while sampling depth with offset to compare with kernel position, this depth should be in same space as position so I did it the same way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sampleDepth = viewPositionFromDepth(offset.xy).z;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is not the most optimal way though, but it worked for me.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-06-02T15:11:04.193" LastActivityDate="2017-06-02T15:11:04.193" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5199" PostTypeId="2" ParentId="5197" CreationDate="2017-06-02T14:50:00.947" Score="2" Body="&lt;p&gt;If you have GL (or equivalent) available, the easiest way is probably to set up your projection matrix so that the plane of the polygon is the near clipping plane, draw the polygon into the stencil buffer, and then draw the polyhedron such that inside faces output a 1 fragment. (You could do this by flipping the winding of the polyhedron and turning on back-face culling, or you could check the normal in the fragment shader.) Then the sum of the white pixels in your framebuffer is the intersection area.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-06-02T14:50:00.947" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5200" PostTypeId="1" CreationDate="2017-06-03T09:54:23.520" Score="0" ViewCount="401" Body="&lt;p&gt;I am trying to find a way to go from some proportion of cyan, magenta and yellow where: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;cyan: 33 % + magenta : 33% + yellow : 33% = 100% black&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so each is represented as a percentage of the sum total. mixing 50% magenta and 50 % yellow should result in red. Mixing some colour with its complement would in effect mix some proportion of all three primaries and result in some amount of black and pulling it further towards one of the primaries, so mixing red and blue would mix cmy in some proportion which would result in some amount of black and a balance of the other two primaries so it would just change chroma.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated. I know that the gamuts of devices and colour models vary so it doesn't need to be perfect, it just needs to be intuitive for someone familiar with the cmy colour wheel to be able to use. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The desired output is an rgb colour code or a cmyk that could then be converted to rgb. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is no white so you're limited to the hues and shades that can be formed from the three primaries. I'm okay with that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hey guys, I'm still trying to find a solution to this. If anyone could help it would be great. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This is for a game, the input is derived from some time value that represents a proportion of primary paints. Sort of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I realize that in cmyk k stands for key and is a black dye that is purer than the black that can be obtained from mixing the primaries. In my game cmyk is unimportant, only that I can mix three primary colours cyan, magenta and yellow to mix the colour wheel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is unlikely that black will even be required, but the chroma effect of mixing some proportion of all three primaries together is required as I would want more than just the hues.  I appreciate that lightness of the hues is not possible without white but that is also fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want it so that given some floating point value for representing some proportion of each primary, I can calculate that as percentages and then resolve that to an rgb colour code. It need not be a perfect conversion as only the rgb colour will be displayed, the cmy will just be for the calculation. A close approximation will suffice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't need an especially wide gamut. I just need to be able to mix some proportion of the paints to mix a colour palette. If the player mixes equal parts of each primary then it would be black, if they keep mixing in magenta then it will become more and more magenta again as the volume of magenta dwarfs the volume of black. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you mix red and blue you're mixing magenta and yellow with magenta and cyan. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that clarifies some of the questions. The goal is to take the intuitive representation expressed to the player, three primary colours, and resolve that to a colour code that can be used to actually render to the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The player will be able to clear the colour so they can then return to a pure primary colour. But to mix any particular colour they will do so by mixing the primary colours. Hue, chroma and brightness should be possible though lightness isn't possible without white as this is subtractive. &lt;/p&gt;&#xA;" OwnerUserId="6770" LastEditorUserId="6770" LastEditDate="2017-06-05T17:03:07.777" LastActivityDate="2017-07-05T17:54:03.280" Title="correct rgb or cmyk code from some proportion of cyan, magenta and yellow" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5201" PostTypeId="2" ParentId="5197" CreationDate="2017-06-03T15:33:35.077" Score="3" Body="&lt;p&gt;There are different numerical approximations you could use:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple solution is to use brute-force Monte Carlo integration. Distribute $N$ random points on the polygon and calculate the number of points inside the 3D polyhedron $N_i$ using ray tracing. The area inside the polyhedron is $A_i=A\frac{N_i}{N}$, where $A$ is the area of the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To improve convergence of the above algorithm, you can distribute the points on grid on the polygon and jitter the sample positions within each grid cell. This is called stratified sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further improvement would be to perform the MC integration in 1D instead of 2D. Pick a sample line $L$ that's on the polygon plane and a sample direction $D$ that's on the plane perpendicular to $L$. Select sample line segment $L_s$ that bounds the polygon within $D$-directed lines (min &amp;amp; max of the polygon projection on $L$ for tight fit). For each sample on $L_s$ first calculate the line segment $S$ that intersects the polygon in direction $D$. Next calculate the length of $S$ that's inside the polyhedron $S_i$. You can calculate $S_i$ using ray tracing, by starting from one end of $S$ and marching along $S$ to intersection points of the segment with the polyhedron, summing up the segments of $S$ inside the polyhedron. More specifically, you need to first check if the start point on $S$ is within polyhedron and set the &quot;inside&quot; state accordingly. Then for each intersection flip the state and add the length from previous intersection to $S_i$ if the state changes from inside to outside. The approximation of the polygon area inside the 3D polyhedron is:&#xA;$$A_i=\frac{|L_s|}{N}\sum_{i=1}^N S_i$$&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-06-03T22:13:34.263" LastActivityDate="2017-06-03T22:13:34.263" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5202" PostTypeId="2" ParentId="5183" CreationDate="2017-06-04T20:32:50.323" Score="3" Body="&lt;p&gt;First of all, I would like to state that handling the boundary conditions correctly is challenging, both from mathematical perspective and from an implementation perspective. Additionally, I think most of the papers don't explain the handling of boundary conditions sufficiently. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, it is worth noticing that you have to apply boundary conditions to both the velocity field and the pressure field (and they are linked to each other). Additionally, you have to distinguish between is the pressure solve (or projection step) and the diffusion step, which must be treated separately. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the very beginning you need to decide what kind of physical behavior you want to have at the boundaries. The standard example is a square surrounded by solid walls where no fluid can enter or leave. In this case you constrain the normal component of the velocity field to be zero ( a dirichlet boundary condition for the diffusion step). As we don't want changes for the normal component of the velocity in the projection step,  we also need to constrain the pressure. If you check the pressure update routine (which makes the velocity field divergency free) you can see that the derivative of the pressure field in direction of the normal must be zero, I.e. a Neumann boundary condition for the pressure field. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume you are talking about the boundary conditions in the pressure solve/ projection step. Stam states that for pressure there is a Neumann boundary condition. As written above this condition implies that the velocity won't be modified at the last stage of the projection step (the pressure update). In order to achieve the dirichlet boundaries for the velocity as bridson states it, you require to have homogenous Neumann conditions. So for pressure, both authors have equivalent boundary conditions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;With these considerations you need to set up your system of linear equations. For this it is worth to note the equations for some cells (I.e. one row of the system of linear equations) and check how the matrix and the right hand side must be modified to account for the boundary conditions. In a 2d scenario we have a 5 point Laplace stencil that results in a 4 on the diagonal and -1 for each of the adjacent cells (times some constants). In cells that are adjacent to the boundary there is at least one value that is outside of the simulation domain and care has to be taken what we do with this value. For homogenous dirichlet conditions this value is simply zero and no changes are required for the matrix and the right hand side. For Neumann boundaries the constraint is that there is no change across the boundary,  I.e. the value should be identical to the one of the cell. This reduces the value on the diagonal of the matrix by -1, I.e. 3 for a cell with one Neumann boundary. These considerations result in the linear system that you have to solve. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The set bnd method (that doesn't appear in the paper by the way) is a trick to make the computations without the necessity to modify the matrix. This trick only works with gauss seidel or Jacobi iterations (As commented on your other question). The set bnd method is part of the code that stam published. Personally I find it difficult to read and understand because of the variable names and the &quot;b&quot; that changes the behavior significantly and that seems to confuse you as well (see your other question).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&#xA;At first glance it looks like stam and bridson apply different boundary conditions, but they are actually the same. If we assume a solid body that is not moving and the velocity is zero before the pressure correction then the difference between them is zero. The term in parentheses in (4.23) will then be evaluated to -p_{i,j} which is exactly a  homogeneous Neumann boundary condition for the pressure. I've got the second edition of bridsons book,  where  this is explained in equation 5.3 and at the bottom of the page in more detail. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit2: up to know we discussed the Neumann boundary conditions for the pressure. No slip/slip boundary conditions are applied to the velocity and for both (with non-moving walls) you need homogenized Neumann boundary conditions for the pressure. With stam's approach of discretization, I.e. storing all velocity components at the cell center it is easier to realize no slip boundary conditions as the boundary for all velocity components are at cell faces. So to realize no slip boundary conditions in the diffusion step (mathematically you can't realize no slip conditions with the Euler equations ( no diffusion)) you need to use homogeneous dirichlet boundary conditions for all velocity components.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit3: It is not straight forward to use the set_bnd method on a staggered grid for no slip boundary conditions. The storage for the tangential (to the boundary) components is not ideal. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit 4: A Neumann boundary condition for the pressure implies that there are no changes for the (normal) velocity at this boundary. If you subtract the pressure gradient at such a boundary, the pressure gradient is simply zero due to the boundary condition. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit 5: Slip / no slip boundary conditions (for the velocity) are not(!) realized in the pressure correction step. For non-moving solid walls there is always a homogeneous Neumann boundary condition for the pressure no matter if you impose a slip or no-slip boundary condition. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit 6: I don't &quot;have&quot; facebook ;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are more subtleties like singular systems for Neumann- only boundary conditions, central differences in staggered or standard grids, distance to the boundary (at cell border or at cell center outside three domain) etc., that I could address if you detail your question. &lt;/p&gt;&#xA;" OwnerUserId="2695" LastEditorUserId="2695" LastEditDate="2017-06-05T20:29:23.180" LastActivityDate="2017-06-05T20:29:23.180" CommentCount="18" ContentLicense="CC BY-SA 3.0" />
  <row Id="5203" PostTypeId="1" CreationDate="2017-06-04T23:31:33.737" Score="2" ViewCount="54" Body="&lt;p&gt;I'm trying to understand the &lt;a href=&quot;http://www.iryoku.com/separable-sss/&quot; rel=&quot;nofollow noreferrer&quot;&gt;separable subsurface scattering&lt;/a&gt; algorithm, but I'm a little confused on what the parameters mean from a notation and implementation standpoint, particularly for the artistic model (the paper includes two models). I'm also confused as to how the kernel should be placed in the equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The equation used is:&#xA;$$M_e(x,y) = \int \int E(x',y')\frac{1}{||a_p||_1}a_p(x-x')a_p(y-y')dx'dy'$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Later on the artistic model has a kernel equal to:&#xA;$$a_m=wG(x,\sigma_{near})+(1-w)G(x,\sigma_{far})$$&#xA;$$A_m=a_m(x)a_m(y)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the supplementary materials, there is an implementation clarification based on depth:&#xA;$$a_m(\sqrt{d_{xy}^2+d_{z}^2}) \approx e^{\frac{-d_{z}^2}{2\sigma_{max}}}a_m(d_{xy})$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would this be the correct final form?&#xA;$$M_e(x,y)=\int \int E(x',y')e^{\frac{-d_{z}^2}{2\sigma_{max}}}a_m(d_{xy})e^{\frac{-d_{z}^2}{2\sigma_{max}}}a_m(d_{xy})dx'dy'$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where (some of these might not be correct interpretations):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$M_e$: output color&lt;/li&gt;&#xA;&lt;li&gt;$E(x',y')$: color at sampling point (from color attachment)&lt;/li&gt;&#xA;&lt;li&gt;$a_p$: kernel in one direction (not sure if this is somehow different than $a_m$)&lt;/li&gt;&#xA;&lt;li&gt;$d_z$: linearized depth from depth buffer&lt;/li&gt;&#xA;&lt;li&gt;$d_{xy}$: sampling points in the x and y direction (distance in x and y direction from the sampling point), not sure if this is in screen or world space&lt;/li&gt;&#xA;&lt;li&gt;$w$: arbitrarily chosen weight between 0 and 1&lt;/li&gt;&#xA;&lt;li&gt;$\sigma_{near}/\sigma_{far}$: diffuse profile for near/far Gaussian (3 color channels each), arbitrarily chosen&lt;/li&gt;&#xA;&lt;li&gt;$\sigma_{max}$: $max(\sigma_{near}, \sigma_{far})$, this is keep the sampling from undersampling the larger Gaussian form my understanding&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2017-06-04T23:31:33.737" Title="Is this the correct interpretation of the separable SSS artistic model?" Tags="&lt;real-time&gt;&lt;post-processing&gt;&lt;subsurface-scattering&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5204" PostTypeId="2" ParentId="5191" CreationDate="2017-06-05T01:48:38.677" Score="4" Body="&lt;p&gt;&lt;strong&gt;Ambient occlusion&lt;/strong&gt; isn't a technique, but rather a concept. It can be implemented (and approximated) as a post-processing effect such as SSAO, SSDO, HBAO+, etc. @trichoplax gave a good answer, I just wanted to elaborate on the comments.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is there a reason why it's considered post-processing and deferred lighting/shading isn't?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I personally would consider deferred rendering to be a post-processing effect, but it depends on your definition of a post-processing effect. For this answer, I will assume it's anything that doesn't require geometry other than a screen-space quad or (&lt;a href=&quot;https://www.saschawillems.de/?p=2148&quot; rel=&quot;noreferrer&quot;&gt;triangle&lt;/a&gt;) to be rendered.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Post-Process Techniques&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Screen space AO techniques involve reading the depth and/or normal buffers to determine if light should be occluded. There are expansions on these techniques that deal with temporal aliasing as well as &lt;a href=&quot;http://graphics.cs.williams.edu/papers/DeepGBuffer14/&quot; rel=&quot;noreferrer&quot;&gt;occlusions by objects in the scene&lt;/a&gt;. Some people also apply AO to separate parts of the scene (dynamic and static objects for instance). This is where the definition of post-processing might become ambiguous.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some renderers do post-process AO before the lighting pass however. Usually these renderers either do a Z-prepass or are light-prepass renderers. This can be used on devices with lower VRAM or eDRAM to preserve memory since you can also do tonemapping during your lighting pass.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;World-Space Static Techniques&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Lightmaps can be used particularly for static environments AO can be easily computed offline. Similarly, art assets can have AO textures.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;World-Space Partially Dynamic Techniques&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Some objects just need rough AO and are largely rigid. For instance, &lt;a href=&quot;http://reedbeta.com/talks/ao-fields/&quot; rel=&quot;noreferrer&quot;&gt;AO fields and decals&lt;/a&gt; can be used with or without SSAO to improve AO for some objects (by Nathan Reed). Another example includes placing a circle around a character's feet.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;World-Space Dynamic Techniques&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;NVidia came up with &lt;a href=&quot;https://developer.nvidia.com/vxao-voxel-ambient-occlusion&quot; rel=&quot;noreferrer&quot;&gt;VXAO&lt;/a&gt;, which is a voxel-based ambient occlusion effect that helps simulate AO in places that aren't visible of screen. This has been one of the downsides to SSAO. Another issue with SSAO is that it must be computed each frame and is subject to temporal aliasing (bad for VR, although some people have developed improvements for this). VXAO can also reduce the memory/production costs of having many AO textures. Also, VXAO can have considerable latency with updates (if the application wants this). However, VXAO has a high performance cost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other applications, such as voxel-based games, can approximate AO very easily by using algorithms based on neighborhood information. This is kind of similar to VXAO, but without the rasterization (voxelization) steps, and they may have much rougher approximations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, there are many implementations of AO, many of which aren't post-processing effects.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2017-06-05T01:48:38.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5205" PostTypeId="2" ParentId="5108" CreationDate="2017-06-05T03:40:45.830" Score="3" Body="&lt;p&gt;A reasonable approach is a continuous sample consensus method. The hough transform can be though of as a discrete sample consensus method, and so becomes intractable for some problems. Sample consensus is nice, because we can impose arbitrary constraints, and handle even the most horrific noise.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Getting Planes: Sample Consensus&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The idea is determine the minimum number of observations needed to form a hypothesis, and then check how many observations agree with that hypothesis. We'll call those observations &quot;inliers&quot;.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Three point determine a plane. Select three points (deterministically, at random, whatever) from your dataset, fit a plane to them.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Check how many points in your point cloud &quot;support&quot; the plane. Meaning that the plane existing in the world could explain what the sensor saw; the observations &quot;support&quot; the conclusion that the plane exists. For your case, a reasonable metric for &quot;support&quot; would be perpendicular distance to the plane.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;In postprocessing, you might cull planes that don't have sufficient width.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h1&gt;Extracting Parallel Planes: Normal Binning&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If you don't have a prior on the structure of your data other than &quot;has parallel planes&quot;, then you're likely trapped trying to discover as many planes as possible and then filtering for parallel ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One might consider a &quot;binning&quot; approach&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Start with the first plane, and say its normal belongs to $bin_0$&lt;/li&gt;&#xA;&lt;li&gt;For each discovered plane, check the angle it makes with every existing bin&lt;/li&gt;&#xA;&lt;li&gt;If the angle is less than $\epsilon$, add that plane to $bin_n$&lt;/li&gt;&#xA;&lt;li&gt;If the angle is greater than (or equal, for completeness) to $\epsilon$, create a new bin, $bin_{n+1}$&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Presumably the largest bin is the thing you want if you have culled small planes.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Other Notes&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Sample consensus will generally perform better if, after fitting to data and finding points that agree, you run a quick optimization to fit a plane to &lt;em&gt;all&lt;/em&gt; of the inlier points. Then recompute inliers, and re-run the optimization. After all, it's quite unlikely that the three points you happened to choose were exactly the true plane. Much more likely is that varying plane parameters to minimize point-to-plane error over all of the inlier observations will yield a nice plane, with the noise averaged out.&lt;/p&gt;&#xA;" OwnerUserId="1988" LastActivityDate="2017-06-05T03:40:45.830" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5206" PostTypeId="2" ParentId="5183" CreationDate="2017-06-05T14:00:28.983" Score="0" Body="&lt;p&gt;The answers of my questions is that Stam uses set_bnd to implement both the pressure boundary condition and the velocity. Bridson uses slip boundaries and he derives an equation for the pressure at boundaries. When you subtract the pressure gradient in the chorin's projection method he uses, the boundary condition of the pressure is forced. &lt;/p&gt;&#xA;" OwnerUserId="4978" LastActivityDate="2017-06-05T14:00:28.983" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5207" PostTypeId="2" ParentId="5200" CreationDate="2017-06-05T16:32:23.167" Score="3" Body="&lt;p&gt;First off, the CMYK model includes black as its own channel, so you typically don't mix a combo of cyan, magenta &amp;amp; yellow to get black, you add black directly as its own independent element. There are a number of reasons for using black directly &amp;amp; without knowing your context, it's difficult to advise you on how to get by without it. &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/2984/what-kind-of-black-should-i-use-when-designing-for-cmyk-print&quot;&gt;What kind of black should I use when designing for CMYK print?&lt;/a&gt; on the graphic design SE has some in depth answers regarding use of black by itself &amp;amp; as a mixture (sometimes called composite black).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, CMYK is a subtractive model for mixing inks based on the notion of reducing brightness. RGB is an additive model based on mixing lights. Because they use different models &amp;amp; are both context dependent, there isn't a generalized conversion formula. The &lt;a href=&quot;https://stackoverflow.com/questions/4858131/rgb-to-cmyk-and-back-algorithm&quot;&gt;RGB to CMYK and back algorithm&lt;/a&gt; question on SO has a number of in depth answers regarding possible conversion algorithms. Again, it's hard to know what to suggest when you haven't clarified what you're using the colors for.&lt;/p&gt;&#xA;" OwnerUserId="5349" LastActivityDate="2017-06-05T16:32:23.167" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5208" PostTypeId="2" ParentId="5018" CreationDate="2017-06-06T09:12:49.437" Score="2" Body="&lt;p&gt;The &lt;strong&gt;Nine Patches&lt;/strong&gt; algorithm is a really nice and powerful solution if you are using textures but I ended up by using a fully procedural solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am just drawing a round box like this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float udRoundBox( vec3 p, vec3 b, float r )&#xA;{&#xA;  return length(max(abs(p)-b,0.0))-r;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can simply avoid the 3rd dimension if you don't need it.&#xA;This method comes from the &lt;a href=&quot;http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Distance function article&lt;/a&gt; from &lt;strong&gt;Inigo Quilez&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2017-06-06T09:12:49.437" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5210" PostTypeId="1" CreationDate="2017-06-06T12:02:46.587" Score="2" ViewCount="2110" Body="&lt;p&gt;I have a lot of data that I generate from an Excel spreadsheet and would like to render them graphically using OpenGL by launching it from within a VBA module.&#xA; Here, I mean Visual Basic for &lt;strong&gt;APPLICATIONS&lt;/strong&gt;, (not .NET). Could somebody give me a pointer on how to get started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've written lots of C++ code with OpenGL, but I'd like to know how to get that first foot in the door with regards to including OpenGL in a VBA environment. I'm running Windows 7. Thanks&lt;/p&gt;&#xA;" OwnerUserId="6785" LastActivityDate="2018-04-24T07:44:27.470" Title="OpenGL with VBA" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5211" PostTypeId="1" CreationDate="2017-06-06T22:33:18.020" Score="4" ViewCount="419" Body="&lt;p&gt;I'm trying to figure out the surface area of a mesh that is the result of various CSG union operations between an arbitrary number of other meshes by summing up the same property of each one of  it's faces (triangles, in this case) but the result is far greater than expected. I believe that this is happening because the mesh that results from the CSG union operations have internal faces, but I'm trying to find only the surface area of it's exterior.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any technique to remove the inner faces of a triangulated mesh, or maybe some way to just ignore these ones while calculating it's surface area?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I'm using &lt;a href=&quot;https://github.com/Arakis/Net3dBool&quot; rel=&quot;nofollow noreferrer&quot;&gt;Net3dBool&lt;/a&gt; to perform the CSG operations. The code that performs the intersection is on the file &lt;a href=&quot;https://github.com/Arakis/Net3dBool/blob/master/src/Net3dBool/BooleanModeller.cs&quot; rel=&quot;nofollow noreferrer&quot;&gt;BooleanModeller.cs&lt;/a&gt;, on the &lt;code&gt;getIntersection&lt;/code&gt; method, wich calls the &lt;code&gt;composeSolid&lt;/code&gt; method.&lt;/p&gt;&#xA;" OwnerUserId="6788" LastEditorUserId="231" LastEditDate="2017-06-15T18:09:12.703" LastActivityDate="2017-06-15T18:09:12.703" Title="Algorithm to remove inner faces of a triangulated mesh" Tags="&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5212" PostTypeId="1" CreationDate="2017-06-07T13:25:13.953" Score="2" ViewCount="167" Body="&lt;p&gt;I have a problem of linear interpolation of &lt;a href=&quot;https://books.google.fr/books?id=94HtCAAAQBAJ&amp;amp;pg=PA9&amp;amp;dq=Rigid+and+Flexible+Mechanisms+A+Finite+Element+Approach+Based+on+the+Conformal+Rotation+Vector&amp;amp;hl=en&amp;amp;sa=X&amp;amp;redir_esc=y#v=onepage&amp;amp;q=Rigid%20and%20Flexible%20Mechanisms%20A%20Finite%20Element%20Approach%20Based%20on%20the%20Conformal%20Rotation%20Vector&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;CRV (Conformal Rotation Vector)&lt;/a&gt; in which CRVs are used to parameterize the orientations. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my knowledge, in order to derive a linear interpolation of orientations, we could apply a conversion from CRV into the corresponding unit quaternion, and then a SLERP (&lt;a href=&quot;https://en.wikipedia.org/wiki/Slerp&quot; rel=&quot;nofollow noreferrer&quot;&gt;Spherical Linear Interpolation&lt;/a&gt;) could be performed to interpolate linearly the orientation parametrized by CRVs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: Could we derive an interpolation of quality directly using CRVs (in linear scope)? &lt;/p&gt;&#xA;" OwnerUserId="6791" LastActivityDate="2017-06-07T13:25:13.953" Title="Interpolation of orientations" Tags="&lt;3d&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5213" PostTypeId="1" CreationDate="2017-06-07T16:25:00.687" Score="1" ViewCount="73" Body="&lt;p&gt;If I have two applications that I've written running on a machine, is it possible to have one application inject triangles into the scene of the other application? So effectively, the data for meshes is coming from two different applications?&lt;/p&gt;&#xA;" OwnerUserId="6792" LastActivityDate="2017-06-07T16:25:00.687" Title="Can one application inject triangles into the graphics pipeline of another application?" Tags="&lt;rendering&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5214" PostTypeId="1" AcceptedAnswerId="5229" CreationDate="2017-06-08T10:06:10.043" Score="7" ViewCount="3263" Body="&lt;p&gt;I read &quot;A Practical Model for Subsurface Light Transport&quot; and &quot;A Rapid Hierarchical Rendering Technique for Translucent Materials&quot;. If I understand correctly, the former does not consider the case when an object is lit behind and we can see the light is going through it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The latter can achieve this but there is a preprocessing stage which is not suitable for my CUDA path tracer and I want it to be as natural as possible. So, do you have any paper in mind which is not obsolete or would you suggest me to solve the full radiative transfer equation?&lt;/p&gt;&#xA;" OwnerUserId="6698" LastEditorUserId="6698" LastEditDate="2017-06-08T16:23:29.667" LastActivityDate="2017-06-13T19:01:26.207" Title="A recent approach for subsurface scattering" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;subsurface-scattering&gt;&lt;cuda&gt;" AnswerCount="2" CommentCount="8" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5215" PostTypeId="1" AcceptedAnswerId="5219" CreationDate="2017-06-08T10:35:32.740" Score="2" ViewCount="129" Body="&lt;p&gt;Since I am using batch rendering, so I should pack every render units can be batched into one big VBO. But, what if I am in a case where render units are dynamically changed, some new units are added in, and some units are subtracted out. So &lt;strong&gt;I should reconstruct my VBO again and again in very frame.&lt;/strong&gt; So here is the question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I allocate a big enough storage in the first time and update the data in it, and only reallocate when run out of the storage, or allocate storage according to the size on demand in each frame?&lt;/p&gt;&#xA;" OwnerUserId="6660" LastEditorUserId="6660" LastEditDate="2017-06-09T02:53:48.173" LastActivityDate="2017-06-09T04:22:51.870" Title="How can deal with batch rendering when the elements in the batch changed every frame?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5216" PostTypeId="1" AcceptedAnswerId="5218" CreationDate="2017-06-08T12:56:39.470" Score="1" ViewCount="367" Body="&lt;p&gt;So this should be easy and simple, but I still can't get it to work. All I need is a small example program that:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Takes in a BufferedImage (TYPE_INT_ARGB)&lt;/li&gt;&#xA;&lt;li&gt;Renders that BufferedImage on a textured quad&lt;/li&gt;&#xA;&lt;li&gt;Using a VBO&lt;/li&gt;&#xA;&lt;li&gt;Without additional shader declaration&lt;/li&gt;&#xA;&lt;li&gt;Using LWJGL3&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Here's what I have got so far:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;package togos.minecraft.maprend.guistandalone;&#xA;&#xA;import static org.lwjgl.glfw.GLFW.*;&#xA;import static org.lwjgl.opengl.GL11.*;&#xA;import static org.lwjgl.opengl.GL15.*;&#xA;import static org.lwjgl.system.MemoryUtil.NULL;&#xA;import java.io.IOException;&#xA;import java.nio.ByteBuffer;&#xA;import java.nio.FloatBuffer;&#xA;import org.lwjgl.BufferUtils;&#xA;import org.lwjgl.glfw.GLFWErrorCallback;&#xA;import org.lwjgl.glfw.GLFWKeyCallback;&#xA;import org.lwjgl.glfw.GLFWVidMode;&#xA;import org.lwjgl.glfw.GLFWWindowSizeCallback;&#xA;import org.lwjgl.opengl.GL;&#xA;import org.lwjgl.opengl.GLUtil;&#xA;import org.lwjgl.system.Callback;&#xA;&#xA;public class GuiMain2 {&#xA;&#xA;    // We need to strongly reference callback instances.&#xA;    private GLFWErrorCallback       errorCallback;&#xA;    private GLFWKeyCallback         keyCallback;&#xA;    private GLFWWindowSizeCallback  wsCallback;&#xA;    private Callback                debugProc;&#xA;&#xA;    // The window handle&#xA;    private long                    window;&#xA;    private int                     width, height;&#xA;&#xA;    public void run() {&#xA;        try {&#xA;            init();&#xA;            loop();&#xA;&#xA;            // Release window and window callbacks&#xA;            glfwDestroyWindow(window);&#xA;            keyCallback.free();&#xA;            wsCallback.free();&#xA;            if (debugProc != null)&#xA;                debugProc.free();&#xA;        } catch (IOException e) {&#xA;            e.printStackTrace();&#xA;        } finally {&#xA;            glfwTerminate();&#xA;            errorCallback.free();&#xA;        }&#xA;    }&#xA;&#xA;    private void init() {&#xA;        glfwSetErrorCallback(errorCallback = GLFWErrorCallback.createPrint(System.err));&#xA;        if (!glfwInit())&#xA;            throw new IllegalStateException(&quot;Unable to initialize GLFW&quot;);&#xA;&#xA;        glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);&#xA;        glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);&#xA;&#xA;        // Create the window&#xA;        window = glfwCreateWindow(300, 300, &quot;Hello World!&quot;, NULL, NULL);&#xA;        if (window == NULL)&#xA;            throw new RuntimeException(&quot;Failed to create the GLFW window&quot;);&#xA;&#xA;        // Setup a key callback. It will be called every time a key is pressed, repeated or released.&#xA;        glfwSetKeyCallback(window, keyCallback = new GLFWKeyCallback() {&#xA;&#xA;            @Override&#xA;            public void invoke(long window, int key, int scancode, int action, int mods) {&#xA;                if (key == GLFW_KEY_ESCAPE &amp;amp;&amp;amp; action == GLFW_RELEASE)&#xA;                    glfwSetWindowShouldClose(window, true); // We will detect this in our rendering loop&#xA;            }&#xA;        });&#xA;        glfwSetWindowSizeCallback(window, wsCallback = new GLFWWindowSizeCallback() {&#xA;&#xA;            @Override&#xA;            public void invoke(long window, int w, int h) {&#xA;                if (w &amp;gt; 0 &amp;amp;&amp;amp; h &amp;gt; 0) {&#xA;                    width = w;&#xA;                    height = h;&#xA;                }&#xA;            }&#xA;        });&#xA;&#xA;        GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());&#xA;        glfwSetWindowPos(window, (vidmode.width() - width) / 2, (vidmode.height() - height) / 2);&#xA;        glfwMakeContextCurrent(window);&#xA;        glfwShowWindow(window);&#xA;    }&#xA;&#xA;    private void loop() throws IOException {&#xA;        GL.createCapabilities();&#xA;        debugProc = GLUtil.setupDebugMessageCallback();&#xA;&#xA;        glEnable(GL_TEXTURE_2D);&#xA;        glEnable(GL_COLOR_MATERIAL);&#xA;        glEnableClientState(GL_VERTEX_ARRAY);&#xA;        glEnableClientState(GL_TEXTURE_COORD_ARRAY);&#xA;&#xA;        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);&#xA;&#xA;        float[] vertices = {&#xA;                -0.5f, -0.5f, 0, 0,&#xA;                0.5f, -0.5f, 1, 0,&#xA;                0.5f, 0.5f, 1, 1,&#xA;                -0.5f, 0.5f, 0, 1 };&#xA;        int vbo = glGenBuffers();&#xA;        glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;        glBufferData(GL_ARRAY_BUFFER, (FloatBuffer) BufferUtils.createFloatBuffer(vertices.length).put(vertices).flip(), GL_STATIC_DRAW);&#xA;&#xA;        int id = genTexture();&#xA;        while (!glfwWindowShouldClose(window)) {&#xA;            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;            glViewport(0, 0, width, height);&#xA;            glMatrixMode(GL_PROJECTION);&#xA;            float aspect = (float) width / height;&#xA;            glLoadIdentity();&#xA;            glOrtho(-aspect, aspect, -1, 1, -1, 1);&#xA;&#xA;            {// Rendering&#xA;                glBindTexture(GL_TEXTURE_2D, id);&#xA;                glVertexPointer(2, GL_FLOAT, 4 * 4, 0L);&#xA;                glTexCoordPointer(2, GL_FLOAT, 4 * 4, 4 * 2);&#xA;                glDrawArrays(GL_QUADS, 0, 4);&#xA;            }&#xA;&#xA;            glfwSwapBuffers(window);&#xA;            glfwPollEvents();&#xA;        }&#xA;    }&#xA;&#xA;    public int genTexture() {&#xA;        int id = glGenTextures();&#xA;        glBindTexture(GL_TEXTURE_2D, id);&#xA;        ByteBuffer pixels = BufferUtils.createByteBuffer(512 * 512 * 4);&#xA;&#xA;        for (int y = 0; y &amp;lt; 512; y++) {&#xA;            for (int x = 0; x &amp;lt; 512; x++) {&#xA;                pixels.put((byte) 255);&#xA;                pixels.put((byte) 0);&#xA;                pixels.put((byte) 0);&#xA;                pixels.put((byte) 255);&#xA;            }&#xA;        }&#xA;        pixels.flip();&#xA;&#xA;        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);&#xA;        return id;&#xA;    }&#xA;&#xA;    public static void main(String[] args) {&#xA;        new GuiMain2().run();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When starting, it displays a white quad in the center of the screen. If textures were working, that quad would be red. And I can't get textures to work.&lt;/p&gt;&#xA;" OwnerUserId="6092" LastEditorUserId="6092" LastEditDate="2017-06-08T13:46:55.850" LastActivityDate="2017-06-08T15:26:10.153" Title="LWJGL/OpenGL render textured quad" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;&lt;image&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5217" PostTypeId="1" CreationDate="2017-06-08T13:03:49.863" Score="2" ViewCount="131" Body="&lt;p&gt;I am reading and trying to implement a research paper.&#xA;It uses openGL to define which part of an image to use in order to reconstitute a big image composited of several images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to do so, I have to generate several masks and multiply them together for each image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One mask is the &quot;focus mask&quot;, and they say:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We evaluate the per-pixel &quot;focusness&quot; of the source image using a sharpness operator that is the energy of the image Laplacian applied on a window of 20x20 pixels centered on each evaluated points.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;My incomprehension is that: isn't Laplacian filter the convolution matrix:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 0  -1   0   or    -1  -1  -1&#xA;-1   4  -1         -1   8  -1&#xA; 0  -1   0         -1  -1  -1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But it's of size 3 x 3 and not 20 x 20.&#xA;The fact that I'm not a native english speaker maybe fools me on the words and there is something I don't understand in this sentence...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT : &#xA;The PDF with the article is downloadable &lt;a href=&quot;https://www.researchgate.net/publication/220252497_Masked_photo_blending_Mapping_dense_photographic_data_set_on_high-resolution_sampled_3D_models&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; for free.&#xA;=&gt; §4.1 : Focus Mask&lt;/p&gt;&#xA;" OwnerUserId="6662" LastEditorUserId="6662" LastEditDate="2017-06-09T09:54:44.387" LastActivityDate="2017-06-09T09:54:44.387" Title="Image Laplacian incomprehension" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;pixel-graphics&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5218" PostTypeId="2" ParentId="5216" CreationDate="2017-06-08T15:26:10.153" Score="1" Body="&lt;p&gt;I figured it out myself, again: just add&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;behind the glTexImage2D command and it works as intended.&lt;/p&gt;&#xA;" OwnerUserId="6092" LastActivityDate="2017-06-08T15:26:10.153" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5219" PostTypeId="2" ParentId="5215" CreationDate="2017-06-09T04:22:51.870" Score="2" Body="&lt;p&gt;Allocate a VBO with a reasonable amount of storage during startup, and update the data in it each frame. This will help the driver manage the memory efficiently. Don't destroy and recreate the buffer unless absolutely necessary; too much resource creation/destruction churn will put more pressure on the driver and can potentially lead to stalls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be more specific: for data that will be updated every frame, you probably want to initialize it using &lt;a href=&quot;http://docs.gl/gl4/glBufferStorage&quot; rel=&quot;nofollow noreferrer&quot;&gt;glBufferStorage&lt;/a&gt; with &lt;code&gt;GL_DYNAMIC_STORAGE_BIT&lt;/code&gt; (or, if you're on an older OpenGL version, &lt;a href=&quot;http://docs.gl/gl4/glBufferData&quot; rel=&quot;nofollow noreferrer&quot;&gt;glBufferData&lt;/a&gt; with &lt;code&gt;GL_DYNAMIC_DRAW&lt;/code&gt;). Then, to update it each frame, use &lt;a href=&quot;http://docs.gl/gl4/glMapBufferRange&quot; rel=&quot;nofollow noreferrer&quot;&gt;glMapBufferRange&lt;/a&gt; with &lt;code&gt;GL_MAP_INVALIDATE_BUFFER_BIT&lt;/code&gt;. This should be an efficient, fast path in the graphics driver.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-06-09T04:22:51.870" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5220" PostTypeId="1" CreationDate="2017-06-09T14:22:04.883" Score="1" ViewCount="439" Body="&lt;p&gt;Can somebody explain how to implement volume rendering and scattering? I've been told that this is the easiest and most effective method to render things like smoke, milk and fog. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Scratchapixel has a great article about it &lt;a href=&quot;https://www.scratchapixel.com/lessons/advanced-rendering/volume-rendering-for-artists&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; but the lesson on implementation is unavailable. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand what Ray Marching is because of this &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4412/volume-rendering-path-tracing-real-time&quot;&gt;answer&lt;/a&gt; from a while back but similiar to my previous problem I have no idea how to implement it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make it clear and narrow this question down so it is easier to answer here are my main problems:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Can someone provide some pseudo code or code of a basic Volume&#xA;Rendering and Ray Marching loop with Absorption &amp;amp; Scattering&#xA;coefficients, Phase Function and a Density function?&lt;/li&gt;&#xA;&lt;li&gt;How is Ray Marching used alongside Path Tracing?&lt;/li&gt;&#xA;&lt;li&gt;Is this the best way to render sub surface scattering?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-06-09T14:22:04.883" Title="Volume Rendering: Implementation" Tags="&lt;pathtracing&gt;&lt;subsurface-scattering&gt;&lt;raymarching&gt;&lt;volumetric-scattering&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5221" PostTypeId="1" AcceptedAnswerId="5225" CreationDate="2017-06-09T14:44:20.620" Score="5" ViewCount="93" Body="&lt;p&gt;I was wondering about the variance for Monte Carlo.&#xA;The book (Advanced Global Illumination 2ed, p.60) writes the equation as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\sigma^2 = \frac{1}{N} \int(\frac{f(x)}{p(x)} - I)^2p(x)dx$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\color{red}{\frac{1}{N} \int(\frac{f(x)}{p(x)})^2p(x)dx  -I^2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\frac{1}{N} \int\frac{f(x)^2}{p(x)}dx  -I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the equation appears incorrect. I think the red area is wrong and the equation should be changed as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\sigma^2 = \frac{1}{N} \int(\frac{f(x)}{p(x)} - I)^2p(x)dx$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\color{red}{\frac{1}{N} \int((\frac{f(x)}{p(x)})^2 -2\frac{f(x)}{p(x)}I + I^2)p(x)dx}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\frac{1}{N} \int\frac{f(x)^2}{p(x)} - 2f(x)I + I^2p(x)dx$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\frac{1}{N} \int\frac{f(x)^2}{p(x)} - 2f(x)I dx \space + \frac{1}{N}I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\frac{1}{N} \int\frac{f(x)^2}{p(x)} dx - \frac{2}{N}I^2 \space + \frac{1}{N}I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\space\space\space\space=\frac{1}{N} \int\frac{f(x)^2}{p(x)} dx - \frac{1}{N}I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it right?&lt;/p&gt;&#xA;" OwnerUserId="6806" LastEditorUserId="1952" LastEditDate="2017-06-12T17:05:24.697" LastActivityDate="2017-06-12T17:05:24.697" Title="The variance for the Monte Carlo estimator" Tags="&lt;global-illumination&gt;&lt;monte-carlo&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5222" PostTypeId="1" AcceptedAnswerId="5224" CreationDate="2017-06-09T19:18:56.963" Score="4" ViewCount="716" Body="&lt;p&gt;Let's assume we have a 3D object (in 3D space). We get a single representation vertex from this whole 3D object. Given the fact that the object can be moved and rotated in the space in any direction, what are the minimum set of other information to add to uniquely identify the object's direction and translation in space?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance lets consider this 3D object. If we have one single point as a reference, we can construct the whole object (the spatial dependency of other points/vertices are known). The single point can infer the movement. But the object can also rotate in any axis. I was initially thinking with a single normal vector added we can infer the object in space. But looks like we need at least two vectors (am I right?) because the object can also rotate around the normal vector. If we have another vector (maybe orthogonal to the first one), we can infer the whole 3D location. With that we can infer the degree of rotation around the normal axis. Is this right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another alternative can be to store 3 reference points. Right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/73jq5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/73jq5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4678" LastActivityDate="2017-07-13T00:20:52.597" Title="Minimum requirements to uniquely represent a 3D object in space" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;computational-geometry&gt;&lt;normal-mapping&gt;&lt;mapping&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5223" PostTypeId="1" CreationDate="2017-06-10T01:38:28.147" Score="9" ViewCount="229" Body="&lt;p&gt;I'm trying to implement metropolis light transport based on &lt;a href=&quot;https://pdfs.semanticscholar.org/a386/55316ee7f438ba115b38e8d0b1410c691a26.pdf&quot; rel=&quot;noreferrer&quot;&gt;this paper&lt;/a&gt;, and I have the basic thing working. I run the algorithm multiple times with different starting points, add the results for each starting point together and multiply them by a scaling factor to approximate the real image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The scaling factor is the one described in the paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$average\_brightess / average\_samples\_per\_pixel$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the resulting image, the starting points are noticeably brighter (they are aligned in a grid below).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YT0qH.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YT0qH.png&quot; alt=&quot;resulting image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper I was reading doesn't have any advice on avoiding this start up bias. I found this &lt;a href=&quot;https://graphics.stanford.edu/papers/metro/metro.pdf&quot; rel=&quot;noreferrer&quot;&gt;other paper&lt;/a&gt; that has advice on this, but I find the paper a little hard to understand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It says each initial path should be assigned a weight $f(x_0) / p_0(x_0)$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f(x_0)$ should be the luminance of the sample at the starting point $x_0$, but is it raw luminance or normalized? $p_0$ is supposed to be a path distribution (possibly sampled by path tracing). How do I get the value of a path distribution at a specified point? Is it the ratio of the point's luminance over the average luminance of the distribution (i.e. average brightness of the image)?&lt;/p&gt;&#xA;" OwnerUserId="6811" LastEditorUserId="6811" LastEditDate="2017-06-10T08:52:00.293" LastActivityDate="2017-06-10T08:52:00.293" Title="Help with start up bias in Metropolis Light Transport" Tags="&lt;rendering&gt;&lt;pathtracing&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5224" PostTypeId="2" ParentId="5222" CreationDate="2017-06-10T10:28:12.517" Score="6" Body="&lt;p&gt;A rigid body has 6 degrees of freedom, in 3D- space. So that means you need 6 values to represent the object. The common way to do this is to store a position vector for position and 3 rotations. But for obvious reasons any 6 variables that are independent of each other would do this.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with vectors is that they aren't the most efficient way to store the data. If you have a vector for origin and a normal you still need one value for the rotation around the normal resulting in seven variables (this is called an axis angle rotation). Two reference points on object has same problem since you dont know the rotation around the axis of point 1 and point 2 leading to 7 variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UkkSi.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UkkSi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Storing vectors of 2 points has a freedom to rotate along the axis of those the vectors &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now storing extra values can be beneficial for other purposes than position and orientation. So it is quite common to store 7 values for solid bodies. This way it is easier to interpolate so that you dont need to convert between representations all the time.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-06-10T11:39:07.803" LastActivityDate="2017-06-10T11:39:07.803" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5225" PostTypeId="2" ParentId="5221" CreationDate="2017-06-10T21:43:46.077" Score="4" Body="&lt;p&gt;I don't have that book to check the context of this, but from the equations you posted, yes, it looks like you're right. The $1/N$ factor should be applied to both terms. That agrees with the formula for variance from statistics, which is $E[X^2] - E[X]^2$.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-06-10T21:43:46.077" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5226" PostTypeId="1" AcceptedAnswerId="5231" CreationDate="2017-06-11T02:46:46.023" Score="2" ViewCount="1077" Body="&lt;p&gt;I have a Display P3 color (1, 0, 0), on a scale of 0.0 to 1.0. I want to find out what the closest color to this is in the sRGB gamut. I chose (1, 0, 0) on the right side ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Kp8O2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Kp8O2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;... but the left side still shows (1, 0, 0).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This makes no sense since (1, 0, 0) in sRGB is not the same color as (1, 0, 0) in P3 — the former is less saturated. As you can see in the screenshot above if you're reading this on a P3 monitor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, how do I convert this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Conversely, given an sRGB color (1, 0, 0), how do I find out what the most saturated version of this color is in P3?&lt;/p&gt;&#xA;" OwnerUserId="6814" LastEditorUserId="231" LastEditDate="2017-06-12T19:48:16.633" LastActivityDate="2017-06-12T20:05:19.057" Title="How do I use ColorSync Utility to convert between Display P3 and sRGB?" Tags="&lt;color-management&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5227" PostTypeId="2" ParentId="5182" CreationDate="2017-06-11T13:43:43.707" Score="6" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fQjfe.png&quot; rel=&quot;noreferrer&quot;&gt;@PaulHK's answer&lt;/a&gt; is correct I'm sure, here's a bit of a check to show that the &lt;code&gt;IOR()&lt;/code&gt; function is calculating the reflection coefficients for $s$ and $p$ polarizations then averaging the two assuming unpolarized incident light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reflection is for a single interface, and at least at normal incidence the results reduce to the simpler $(n_2-n_1)^2/(n_2+n_1)^2$. With this script you can check against other on-line calculators using non-zero incident angle and nonzero values for $k$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I cleaned up the python a bit (indents) and added the plot. You can see when exiting from glass to air, the reflectivity goes to 100% at the critical angle for total internal reflection:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fQjfe.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fQjfe.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/174bS.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/174bS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def IOR(n,k):&#xA;    theta_deg = 0&#xA;&#xA;    fresnel = []&#xA;&#xA;    while theta_deg &amp;lt;= 90:&#xA;        theta = math.radians(theta_deg)&#xA;&#xA;        a = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 +&#xA;                                 ((4 * n**2) * k**2)) + (n**2 - k**2 -&#xA;                                            (math.sin(theta))**2))/2)&#xA;&#xA;        b = math.sqrt((math.sqrt((n**2-k**2-(math.sin(theta))**2)**2 +&#xA;                                 ((4 * n**2) * k**2)) - (n**2 - k**2 -&#xA;                                            (math.sin(theta))**2))/2)&#xA;&#xA;        Fs = (a**2+b**2-(2 * a * math.cos(theta))+&#xA;              (math.cos(theta))**2)/(a**2+b**2 +&#xA;                            (2 * a * math.cos(theta))+(math.cos(theta))**2)&#xA;&#xA;        Fp = Fs * ((a**2+b**2 -&#xA;                    (2 * a * math.sin(theta) * math.tan(theta)) +&#xA;                    (math.sin(theta))**2*(math.tan(theta))**2)/(a**2+b**2 +&#xA;                    (2 * a * math.sin(theta) * math.tan(theta)) +&#xA;                    (math.sin(theta))**2*(math.tan(theta))**2))&#xA;&#xA;        R = (Fs + Fp)/2&#xA;&#xA;        fresnel.append((R, Fs, Fp))&#xA;&#xA;        theta_deg += 1&#xA;    return fresnel&#xA;&#xA;import math&#xA;import matplotlib.pyplot as plt&#xA;&#xA;n1, n2  = 1.00, 1.45  # into glass, one side only&#xA;n2ovrn1 = n2/n1&#xA;&#xA;Rin, Fsin, Fpin = zip(*IOR(n2ovrn1, 0))&#xA;&#xA;print Rin[0]&#xA;print (n2ovrn1-1.0)**2 / (n2ovrn1+1.0)**2  # check&#xA;&#xA;n1, n2  = 1.45, 1.00  # outof glass, one side only&#xA;n2ovrn1 = n2/n1&#xA;&#xA;Rout, Fsout, Fpout = zip(*IOR(n2ovrn1, 0))&#xA;&#xA;print Rout[0]&#xA;print (n2ovrn1-1.0)**2 / (n2ovrn1+1.0)**2  # check&#xA;&#xA;plt.figure()&#xA;plt.plot(range(91), Rin, '-k', linewidth=2)&#xA;plt.plot(range(91), Rout, '-k', linewidth=2)&#xA;plt.plot(range(91), Fsin, '-k')&#xA;plt.plot(range(91), Fsout, '-k')&#xA;plt.plot(range(91), Fpin, '--k')&#xA;plt.plot(range(91), Fpout, '--k')&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5846" LastActivityDate="2017-06-11T13:43:43.707" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5228" PostTypeId="2" ParentId="5210" CreationDate="2017-06-11T15:51:28.620" Score="3" Body="&lt;p&gt;As promised but with apologies for the tardiness, here's a GREAT repository of detailed information for using OpenGL with VBA:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://arkham46.developpez.com/articles/office/vbaopengl/?page=page_1&quot; rel=&quot;nofollow noreferrer&quot;&gt;Découvrez la 3D OpenGL 1.1 en VB6/VBA | arkham46.developpez.com&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's in French, but translates beautifully. I wa able to get OpenGL up and running in less than 15 mins using this SUPERB tutorial.&lt;/p&gt;&#xA;" OwnerUserId="6785" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:44:27.470" LastActivityDate="2018-04-24T07:44:27.470" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5229" PostTypeId="2" ParentId="5214" CreationDate="2017-06-11T18:53:07.640" Score="9" Body="&lt;p&gt;As mentioned in the comments, I would highly suggest starting with Full Volumetric Scattering. This is two fold:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Since you are doing path tracing, adding volumetrics isn't super difficult.&lt;/li&gt;&#xA;&lt;li&gt;Fully understanding how full volumetric scattering works will be a great basis for understanding the estimations. In addition, it can provide great &quot;references&quot; to see if your estimations are performing well / correctly.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;With that in mind, below is a basic introduction to how to implement Full Volumetric Scattering in a backwards path tracer.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To start, let's look at the code for a backwards path tracer with only reflection, no transmission / refraction:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) {&#xA;    Ray ray = m_scene-&amp;gt;Camera-&amp;gt;CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;    SurfaceInteraction interaction;&#xA;&#xA;    // Bounce the ray around the scene&#xA;    const uint maxBounces = 15;&#xA;    for (uint bounces = 0; bounces &amp;lt; maxBounces; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.GeomID == INVALID_GEOMETRY_ID) {&#xA;            color += throughput * m_scene-&amp;gt;BackgroundColor;&#xA;            break;&#xA;        }&#xA;&#xA;        // Fetch the material&#xA;        Material *material = m_scene-&amp;gt;GetMaterial(ray.GeomID);&#xA;        // The object might be emissive. If so, it will have a corresponding light&#xA;        // Otherwise, GetLight will return nullptr&#xA;        Light *light = m_scene-&amp;gt;GetLight(ray.GeomID);&#xA;&#xA;        // If this is the first bounce or if we just had a specular bounce,&#xA;        // we need to add the emmisive light&#xA;        if ((bounces == 0 || (interaction.SampledLobe &amp;amp; BSDFLobe::Specular) != 0) &amp;amp;&amp;amp; light != nullptr) {&#xA;            color += throughput * light-&amp;gt;Le();&#xA;        }&#xA;&#xA;        interaction.Position = ray.Origin + ray.Direction * ray.TFar;&#xA;        interaction.Normal = normalize(m_scene-&amp;gt;InterpolateNormal(ray.GeomID, ray.PrimID, ray.U, ray.V));&#xA;        interaction.OutputDirection = normalize(-ray.Direction);&#xA;&#xA;&#xA;        // Calculate the direct lighting&#xA;        color += throughput * SampleLights(sampler, interaction, material-&amp;gt;bsdf, light);&#xA;&#xA;&#xA;        // Get the new ray direction&#xA;        // Choose the direction based on the bsdf        &#xA;        material-&amp;gt;bsdf-&amp;gt;Sample(interaction, sampler);&#xA;        float pdf = material-&amp;gt;bsdf-&amp;gt;Pdf(interaction);&#xA;&#xA;        // Accumulate the weight&#xA;        throughput = throughput * material-&amp;gt;bsdf-&amp;gt;Eval(interaction) / pdf;&#xA;&#xA;        // Shoot a new ray&#xA;&#xA;        // Set the origin at the intersection point&#xA;        ray.Origin = interaction.Position;&#xA;&#xA;        // Reset the other ray properties&#xA;        ray.Direction = interaction.InputDirection;&#xA;        ray.TNear = 0.001f;&#xA;        ray.TFar = infinity;&#xA;&#xA;&#xA;        // Russian Roulette&#xA;        if (bounces &amp;gt; 3) {&#xA;            float p = std::max(throughput.x, std::max(throughput.y, throughput.z));&#xA;            if (sampler-&amp;gt;NextFloat() &amp;gt; p) {&#xA;                break;&#xA;            }&#xA;&#xA;            throughput *= 1 / p;&#xA;        }&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera-&amp;gt;FrameBufferData.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;In English:&lt;/h2&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Shoot a ray through the scene.&lt;/li&gt;&#xA;&lt;li&gt;Check if we hit anything. If not we return the skybox color and break.&lt;/li&gt;&#xA;&lt;li&gt;If this is the first ray, or we just bounced off a specular surface, check if we hit a light. If so, we add the light emission to our color accumulation.&lt;/li&gt;&#xA;&lt;li&gt;Sample the direct lighting.&lt;/li&gt;&#xA;&lt;li&gt;Choose a new direction for the next ray. We can do this uniformly, or importance sample based on the BRDF.&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the BRDF and accumulate it. &lt;/li&gt;&#xA;&lt;li&gt;Create a new ray based on our chosen direction and where we just came from.&lt;/li&gt;&#xA;&lt;li&gt;[Optional] Use Russian Roulette to choose if we should terminate the ray.&lt;/li&gt;&#xA;&lt;li&gt;Goto 1.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For more details on Direct Light Sampling, see &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5152/progressive-path-tracing-with-explicit-light-sampling/5153#5153&quot;&gt;this answer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;BSDFs&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;To add transmission, we first need to upgrade some of our BRDF materials to full BSDFs, with a BTDF function.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2oBo9.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2oBo9.png&quot; alt=&quot;BSDF Explanation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, a BSDF for an ideal specular dielectric (ie. glass) is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class IdealSpecularDielectric : public BSDF {&#xA;public:&#xA;    IdealSpecularDielectric(float3 albedo, float ior)&#xA;        : BSDF(BSDFLobe::Specular, albedo), &#xA;          m_ior(ior) {&#xA;    }&#xA;&#xA;private:&#xA;    float m_ior;&#xA;&#xA;public:&#xA;    float3 Eval(SurfaceInteraction &amp;amp;interaction) const override {&#xA;        return m_albedo;&#xA;    }&#xA;&#xA;    void Sample(SurfaceInteraction &amp;amp;interaction, UniformSampler *sampler) const override {&#xA;        float VdotN = dot(interaction.OutputDirection, interaction.Normal);&#xA;        float IORo = m_ior;&#xA;        if (VdotN &amp;lt; 0.0f) {&#xA;            IORo = 1.0f;&#xA;            interaction.Normal = -interaction.Normal;&#xA;            VdotN = -VdotN;&#xA;        }&#xA;&#xA;        float eta = interaction.IORi / IORo;&#xA;        float sinSquaredThetaT = SinSquaredThetaT(VdotN, eta);&#xA;        float fresnel = Fresnel(interaction.IORi, IORo, VdotN, sinSquaredThetaT);&#xA;&#xA;        float rand = sampler-&amp;gt;NextFloat();&#xA;        if (rand &amp;lt;= fresnel) {&#xA;            // Reflect&#xA;            interaction.InputDirection = reflect(interaction.OutputDirection, interaction.Normal);&#xA;            interaction.SampledLobe = BSDFLobe::SpecularReflection;&#xA;            interaction.IORo = interaction.IORi;&#xA;        } else {&#xA;            // Refract&#xA;            interaction.InputDirection = refract(interaction.OutputDirection, interaction.Normal, VdotN, eta, sinSquaredThetaT);&#xA;            interaction.SampledLobe = BSDFLobe::SpecularTransmission;&#xA;            interaction.IORo = IORo;&#xA;        }&#xA;&#xA;        if (AnyNan(interaction.InputDirection)) {&#xA;            printf(&quot;nan&quot;);&#xA;        }&#xA;    }&#xA;&#xA;    float Pdf(SurfaceInteraction &amp;amp;interaction) const override {&#xA;        return 1.0f;&#xA;    }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The interesting part of the code is &lt;code&gt;Sample()&lt;/code&gt;. This is where a ray will choose whether to reflect or refract. How we do this is really up to us, as shown in &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2482/choosing-reflection-or-refraction-in-path-tracing&quot;&gt;this answer&lt;/a&gt;. However, an obvious choice would be to sample based on the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;noreferrer&quot;&gt;Fresnel equations&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of an ideal Specular Dielectric, there are only two potential output directions: perfect refraction or perfect reflection. So we evaluate the Fresnel and randomly choose to refract / reflect with proportion equal to the Fresnel. &lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Media&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Next, we need to talk about media, and how they affect light bouncing around. As explained by Nathan Reed in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/3570/310&quot;&gt;this answer&lt;/a&gt;: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The way I like to think about volume scattering is that a photon traveling through a medium has a certain probability per unit length of interacting (getting scattered or absorbed). As long as it doesn't interact, it just goes in a straight line unimpeded and without losing energy. The greater the distance, the greater the probability that it interacts somewhere in that distance. The interaction probability per unit length is the coefficient $\sigma$ that you see in the equations. We usually have separate coefficients for scattering and absorption probabilities, so $\sigma = \sigma_s + \sigma_a$&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;This probability per unit length is exactly the origin of the Beer-Lambert law. Slice a ray segment into infinitesimal intervals, treat each interval as an independent possible place to interact, then integrate along the ray; you get an exponential distribution (with rate parameter σσ) for the probability of interaction as a function of distance.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;You &lt;em&gt;can&lt;/em&gt; technically choose the distance between events however you want, as long as you correctly weight the path for the probability that a photon can make it between two adjacent events without interacting with the medium. In other words, each path segment within the medium contributes a weight factor of $e^{-\sigma x}$, where $x$ is the length of the segment.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Given this, a usually good choice for the distance is to importance-sample it from the exponential distribution. In other words, you set $x = -(\ln \xi)/\sigma$&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In summary:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;A ray travelling through a medium has some probability to:&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Be absorbed&lt;/li&gt;&#xA;&lt;li&gt;Be scattered&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Since this is Monte Carlo Integration, we are free to choose the interaction distance however we want. However, a good choice is to importance sample from an exponential distribution similar to Beer-Lambert.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I chose to implement this with a scattering coefficient, and letting Beer-Lambert take care of the absorption coefficient.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class Medium {&#xA;public:&#xA;    Medium(float3 absorptionColor, float absorptionAtDistance) &#xA;        : m_absorptionCoefficient(-log(absorptionColor) / absorptionAtDistance) {&#xA;        // This method for calculating the absorption coefficient is borrowed from Burley's 2015 Siggraph Course Notes &quot;Extending the Disney BRDF to a BSDF with Integrated Subsurface Scattering&quot;&#xA;        // It's much more intutive to specify a color and a distance, then back-calculate the coefficient&#xA;    }&#xA;    virtual ~Medium() {&#xA;    }&#xA;&#xA;protected:&#xA;    const float3a m_absorptionCoefficient;&#xA;&#xA;public:&#xA;    virtual float SampleDistance(UniformSampler *sampler, float tFar, float *weight, float *pdf) const = 0;&#xA;&#xA;    virtual float3a SampleScatterDirection(UniformSampler *sampler, float3a &amp;amp;wo, float *pdf) const = 0;&#xA;    virtual float ScatterDirectionPdf(float3a &amp;amp;wi, float3a &amp;amp;wo) const = 0;&#xA;&#xA;    virtual float3 Transmission(float distance) const = 0;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A Non-scattering medium is one where a photon travels straight through, but it is attenuated along the way according to Beer-Lambert:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class NonScatteringMedium : public Medium {&#xA;public:&#xA;    NonScatteringMedium(float3 color, float atDistance)&#xA;        : Medium(color, atDistance) {&#xA;    }&#xA;&#xA;public:&#xA;    float SampleDistance(UniformSampler *sampler, float tFar, float *weight, float *pdf) const override {&#xA;        *pdf = 1.0f;&#xA;        return tFar;&#xA;    }&#xA;&#xA;    float3a SampleScatterDirection(UniformSampler *sampler, float3a &amp;amp;wo, float *pdf) const override {&#xA;        return wo;&#xA;    }&#xA;    float ScatterDirectionPdf(float3a &amp;amp;wi, float3a &amp;amp;wo) const override {&#xA;        return 1.0f;&#xA;    }&#xA;&#xA;    float3 Transmission(float distance) const override {&#xA;        return exp(-m_absorptionCoefficient * distance);&#xA;    }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aERCt.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aERCt.png&quot; alt=&quot;Non-scattering example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An Isotropic Scattering Medium allows the ray to have scattering (reflection) events while the ray is traveling through it. The ray can be reflected in any direction in the sphere around the interaction point (hence Isotropic). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tOp55.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tOp55.jpg&quot; alt=&quot;Explanation of Isotropic scattering&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The distance between reflections is random, based on an exponential &quot;scatter&quot; probability.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class IsotropicScatteringMedium : public Medium {&#xA;public:&#xA;    IsotropicScatteringMedium(float3 absorptionColor, float absorptionAtDistance, float scatteringDistance)&#xA;        : Medium(absorptionColor, absorptionAtDistance),&#xA;          m_scatteringCoefficient(1 / scatteringDistance) {&#xA;    }&#xA;&#xA;private:&#xA;    float m_scatteringCoefficient;&#xA;&#xA;public:&#xA;    float SampleDistance(UniformSampler *sampler, float tFar, float *weight, float *pdf) const override {&#xA;        float distance = -logf(sampler-&amp;gt;NextFloat()) / m_scatteringCoefficient;&#xA;        // If we sample a distance farther than the next intersecting surface, clamp to the surface distance&#xA;        if (distance &amp;gt;= tFar) {&#xA;            *pdf = 1.0f;&#xA;            return tFar;&#xA;        }&#xA;&#xA;        *pdf = std::exp(-m_scatteringCoefficient * distance);&#xA;        return distance;&#xA;    }&#xA;    float3a SampleScatterDirection(UniformSampler *sampler, float3a &amp;amp;wo, float *pdf) const override {&#xA;        *pdf = 0.25f * M_1_PI; // 1 / (4 * PI)&#xA;        return UniformSampleSphere(sampler);&#xA;    }&#xA;&#xA;    float ScatterDirectionPdf(float3a &amp;amp;wi, float3a &amp;amp;wo) const override {&#xA;        return 0.25f * M_1_PI; // 1 / (4 * PI)&#xA;    }&#xA;    float3 Transmission(float distance) const override {&#xA;        return exp(-m_absorptionCoefficient * distance);&#xA;    }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;At high scattering distances, the material behaves almost like a NonScatteringMedium, because it has a very small probability of scattering before it travels through the medium.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H7OX2.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H7OX2.png&quot; alt=&quot;High Scattering Distance&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At low scattering distances, the material behaves like wax or jade. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JgjlE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JgjlE.png&quot; alt=&quot;Low Scattering Distance&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the scattering distance gets lower and lower, we have a higher and higher chance to scatter while traveling through the medium. This presents a few issues:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The number of bounces per ray is going to explode. &lt;/li&gt;&#xA;&lt;li&gt;If Russian Roulette kills the ray, or if you go over &quot;maxBounces&quot;, you will &quot;lose&quot; any color contribution from inside the medium. &lt;a href=&quot;https://i.stack.imgur.com/tZ6QO.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tZ6QO.png&quot; alt=&quot;Over Max bounces example&quot;&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Thus, you need to set maxBounces to some high number, and rely on Russian Roulette to terminate rays in the general case. In addition, IsotropicScatteringMedium is extremely inefficient for representing mostly opaque materials. To get better performance, we should use a non Isotropic phase function, &lt;a href=&quot;https://www.cs.dartmouth.edu/~wjarosz/publications/dissertation/chapter4.pdf&quot; rel=&quot;noreferrer&quot;&gt;like Henyey-Greenstein or Schlick&lt;/a&gt;. These bias the scattering in a certain direction. So we could set them to have high back-scattering, thereby lessening the issue of &quot;lost&quot; rays.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Putting it all together&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;So, with this new information, how do we modify the integrator to understand BSDFs and media? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, we need to start tracking what medium we are currently in, and its Index of Refraction (IOR). &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;SurfaceInteraction interaction;&#xA;interaction.IORi = 1.0f; // Vacuum &#xA;Medium *medium = nullptr; // nullptr == vacuum&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then, we break the integrator up into two parts: transmission and material interaction.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderPixel(uint x, uint y, UniformSampler *sampler) const {&#xA;    Ray ray = m_scene-&amp;gt;Camera-&amp;gt;CalculateRayFromPixel(x, y, sampler);&#xA;&#xA;    float3 color(0.0f);&#xA;    float3 throughput(1.0f);&#xA;    SurfaceInteraction interaction;&#xA;    interaction.IORi = 1.0f; // Air&#xA;    Medium *medium = nullptr;&#xA;    bool hitSurface = false;&#xA;&#xA;    // Bounce the ray around the scene&#xA;    uint bounces = 0;&#xA;    const uint maxBounces = 1500;&#xA;    for (; bounces &amp;lt; maxBounces; ++bounces) {&#xA;        m_scene-&amp;gt;Intersect(ray);&#xA;&#xA;        // The ray missed. Return the background color&#xA;        if (ray.GeomID == INVALID_GEOMETRY_ID) {&#xA;            color += throughput * m_scene-&amp;gt;BackgroundColor;&#xA;            break;&#xA;        }&#xA;&#xA;        // We hit an object&#xA;        hitSurface = true;&#xA;&#xA;        // Calculate any transmission&#xA;        if (medium != nullptr) {&#xA;            float weight = 1.0f;&#xA;            float pdf = 1.0f;&#xA;            float distance = medium-&amp;gt;SampleDistance(sampler, ray.TFar, &amp;amp;weight, &amp;amp;pdf);&#xA;            float3 transmission = medium-&amp;gt;Transmission(distance);&#xA;            throughput = throughput * weight * transmission;&#xA;&#xA;            if (distance &amp;lt; ray.TFar) {&#xA;                // Create a scatter event&#xA;                hitSurface = false;&#xA;&#xA;                ray.Origin = ray.Origin + ray.Direction * distance;&#xA;&#xA;                // Reset the other ray properties&#xA;                float directionPdf;&#xA;                float3a wo = normalize(ray.Direction);&#xA;                ray.Direction = medium-&amp;gt;SampleScatterDirection(sampler, wo, &amp;amp;directionPdf);&#xA;                ray.TNear = 0.001f;&#xA;                ray.TFar = infinity;&#xA;                ray.GeomID = INVALID_GEOMETRY_ID;&#xA;                ray.PrimID = INVALID_PRIMATIVE_ID;&#xA;                ray.InstID = INVALID_INSTANCE_ID;&#xA;                ray.Mask = 0xFFFFFFFF;&#xA;                ray.Time = 0.0f;&#xA;            }&#xA;        }&#xA;&#xA;        if (hitSurface) {&#xA;            // Fetch the material&#xA;            Material *material = m_scene-&amp;gt;GetMaterial(ray.GeomID);&#xA;            // The object might be emissive. If so, it will have a corresponding light&#xA;            // Otherwise, GetLight will return nullptr&#xA;            Light *light = m_scene-&amp;gt;GetLight(ray.GeomID);&#xA;&#xA;            // If this is the first bounce or if we just had a specular bounce,&#xA;            // we need to add the emmisive light&#xA;            if ((bounces == 0 || (interaction.SampledLobe &amp;amp; BSDFLobe::Specular) != 0) &amp;amp;&amp;amp; light != nullptr) {&#xA;                color += throughput * light-&amp;gt;Le();&#xA;            }&#xA;&#xA;            interaction.Position = ray.Origin + ray.Direction * ray.TFar;&#xA;            interaction.Normal = normalize(m_scene-&amp;gt;InterpolateNormal(ray.GeomID, ray.PrimID, ray.U, ray.V));&#xA;            interaction.OutputDirection = normalize(-ray.Direction);&#xA;            interaction.IORo = 0.0f;&#xA;&#xA;&#xA;            // Calculate the direct lighting&#xA;            color += throughput * SampleOneLight(sampler, interaction, material-&amp;gt;bsdf, light);&#xA;&#xA;&#xA;            // Get the new ray direction&#xA;            // Choose the direction based on the bsdf        &#xA;            material-&amp;gt;bsdf-&amp;gt;Sample(interaction, sampler);&#xA;            float pdf = material-&amp;gt;bsdf-&amp;gt;Pdf(interaction);&#xA;&#xA;            // Accumulate the weight&#xA;            throughput = throughput * material-&amp;gt;bsdf-&amp;gt;Eval(interaction) / pdf;&#xA;&#xA;            // Update the current IOR and medium if we refracted&#xA;            if (interaction.SampledLobe == BSDFLobe::SpecularTransmission) {&#xA;                interaction.IORi = interaction.IORo;&#xA;                medium = material-&amp;gt;medium;&#xA;            }&#xA;&#xA;            // Shoot a new ray&#xA;&#xA;            // Set the origin at the intersection point&#xA;            ray.Origin = interaction.Position;&#xA;&#xA;            // Reset the other ray properties&#xA;            ray.Direction = interaction.InputDirection;&#xA;            if (AnyNan(ray.Direction))&#xA;                printf(&quot;bad&quot;);&#xA;            ray.TNear = 0.001f;&#xA;            ray.TFar = infinity;&#xA;            ray.GeomID = INVALID_GEOMETRY_ID;&#xA;            ray.PrimID = INVALID_PRIMATIVE_ID;&#xA;            ray.InstID = INVALID_INSTANCE_ID;&#xA;            ray.Mask = 0xFFFFFFFF;&#xA;            ray.Time = 0.0f;&#xA;        }&#xA;&#xA;        // Russian Roulette&#xA;        if (bounces &amp;gt; 3) {&#xA;            float p = std::max(throughput.x, std::max(throughput.y, throughput.z));&#xA;            if (sampler-&amp;gt;NextFloat() &amp;gt; p) {&#xA;                break;&#xA;            }&#xA;&#xA;            throughput *= 1 / p;&#xA;        }&#xA;    }&#xA;&#xA;    if (bounces == maxBounces) {&#xA;        printf(&quot;Over max bounces&quot;);&#xA;    }&#xA;&#xA;    m_scene-&amp;gt;Camera-&amp;gt;FrameBufferData.SplatPixel(x, y, color);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;In English:&lt;/h2&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Shoot a ray through the scene.&lt;/li&gt;&#xA;&lt;li&gt;Check if we hit anything. If not we return the skybox color and break.&lt;/li&gt;&#xA;&lt;li&gt;Check if we are currently in a medium (not in a vacuum).&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Sample the medium for a distance.&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the medium's transmission and accumulate the throughput.&lt;/li&gt;&#xA;&lt;li&gt;If the scatter distance is less than the distance from the ray origin to the next surface, make a scatter event.&lt;/li&gt;&#xA;&lt;li&gt;Sample the medium for a scatter direction.&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;li&gt;Check if we hit a surface (ie, we didn't have a scatter event).&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If this is the first ray, or we just bounced off a specular surface, check if we hit a light. If so, we add the light emission to our color accumulation.&lt;/li&gt;&#xA;&lt;li&gt;Sample the direct lighting.&lt;/li&gt;&#xA;&lt;li&gt;Choose a new direction for the next ray. We can do this uniformly, or importance sample based on the BRDF.&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the BRDF and accumulate it. &lt;/li&gt;&#xA;&lt;li&gt;If we refracted into the material, update the IOR and medium for the next bounce.&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;li&gt;Create a new ray based on our chosen direction and where we just came from.&lt;/li&gt;&#xA;&lt;li&gt;[Optional] Use Russian Roulette to choose if we should terminate the ray.&lt;/li&gt;&#xA;&lt;li&gt;Goto 1.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="310" LastEditorUserId="231" LastEditDate="2017-06-12T17:56:21.303" LastActivityDate="2017-06-12T17:56:21.303" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5230" PostTypeId="1" AcceptedAnswerId="5247" CreationDate="2017-06-12T19:00:12.177" Score="3" ViewCount="946" Body="&lt;p&gt;This is the follow-up question from here: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5222/&quot;&gt;Minimum requirements to uniquely represent a 3D object in space&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume I have 3 original points in a 3D object (in 3D space) as &lt;code&gt;A1=&amp;lt;xa,ya,za&amp;gt;&lt;/code&gt;, &lt;code&gt;A2=&amp;lt;xa,ya,za&amp;gt;&lt;/code&gt;, and &lt;code&gt;A3=&amp;lt;xa,ya,za&amp;gt;&lt;/code&gt; (assume we have all the requirements mentioned in our previous question). The 3D object is moved and rotated in the 3D space, and the new destination points become &lt;code&gt;B1=&amp;lt;xb,yb,zb&amp;gt;&lt;/code&gt;, &lt;code&gt;B2=&amp;lt;xb,yb,zb&amp;gt;&lt;/code&gt;, and &lt;code&gt;B3=&amp;lt;xb,yb,zb&amp;gt;&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the formula for the transformation matrix? Basically, I need a matrix that if applied to all points of the origin object, I get the displaced object.&lt;/p&gt;&#xA;" OwnerUserId="4678" LastEditorUserId="4678" LastEditDate="2017-06-12T20:27:23.653" LastActivityDate="2017-06-16T12:05:35.587" Title="Rotation matrix for a 3D object in space" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;matrix&gt;&lt;normal-mapping&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5231" PostTypeId="2" ParentId="5226" CreationDate="2017-06-12T19:42:27.477" Score="0" Body="&lt;p&gt;Assuming that &quot;Display P3&quot; refers to the &lt;a href=&quot;https://en.wikipedia.org/wiki/DCI-P3&quot; rel=&quot;nofollow noreferrer&quot;&gt;DCI-P3&lt;/a&gt; colour space, this covers a wider gamut of colours than sRGB, so that an exact match is not possible for P3 colours that fall outside the gamut of sRGB. The example colour in the question is the reddest red that DCI-P3 can produce. This is considerably redder than the reddest red that sRGB can produce, so the nearest available red is shown instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You are right that (1, 0, 0) in sRGB is not the same as (1, 0, 0) in P3, but it is the closest it is possible to get. If you enter (1, 0, 0) in sRGB, you should see that converting it to P3 gives a red that is not the extreme (1, 0, 0). Any colour in sRGB can be converted to P3, which covers all of sRGB and more. However, only some of the colours in P3 can be converted to sRGB, since sRGB doesn't cover all of those colours. For colours that sRGB doesn't cover, the conversion utility used appears to be giving the nearest approximation available within sRGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is analogous to converting RGB to greyscale. Any shade of grey in RGB can be converted to greyscale and still look the same, but outside of the set of greys, any other colour will be changed when you convert to greyscale. So red will be converted to a grey that best approximates it.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In answer to your final sentence, if you want to take an sRGB colour and find the most saturated form of that colour that P3 can represent, then it is going to be less straightforward when you are dealing with a colour other than one of the primaries red, green, and blue. You need to consider whether you want the nearest hue amongst the maximum saturation colours in P3, or the most saturated of the exact hue match colours in P3. These are subtly different, because for a given hue its maximum saturation available within P3 is less than the maximum saturation available for the primaries, since the colour space is a triangle. You can compromise by deviating only slightly from the desired hue to achieve slightly more saturation, but the degree of compromise will depend on your purpose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even for the primaries, you need to ask whether you want to convert the greenest green sRGB can represent to the greenest green P3 can represent, or whether you want to take into account that those two colours are not quite the same hue. since sRGB and P3 don't use quite the same primaries (only the blue primary is identical). If you want the hue to remain constant, it might help to convert to an intermediary colour space that includes hue as a parameter.&lt;/p&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2017-06-12T20:05:19.057" LastActivityDate="2017-06-12T20:05:19.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5232" PostTypeId="1" AcceptedAnswerId="5252" CreationDate="2017-06-12T21:37:12.610" Score="4" ViewCount="1347" Body="&lt;p&gt;For column-major rotation matrices (right up forward in columns) do you right-multiply (post-multiply?) a row vector or left-multiply (pre-multiply) a column vector to result in a correct/valid transformation? Or are both &quot;valid&quot; but just transform different spaces?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case I'm getting my terminology wrong, suppose we have 3x3 column-major matrix R. Is it R * V for column-major matrix, where V is 3x1? Or is it V * R for column-major matrix, where V is 1x3? What about for row-major?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks so much for the help!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I believe my question needs further clarification. I am more confused about whether a vector, regardless if it's a row or column, is multiplied to the left or right of a &lt;strong&gt;row specific majored matrix&lt;/strong&gt;. And vice versa for column-majored matrix, but it would be implied by answering either which one. I do understand the concept that transposing a matrix will just mean you have to transpose the vector and flip the order of multiplication, which will result in the same thing because you're multiplying the same elements the other way around. That is not the concern of my question (though thanks for those who answered that part). When I say row specific (or column), I'm talking about the way the &lt;strong&gt;right up forward vectors&lt;/strong&gt; are positioned in the matrix. Though at this point, I think I already have figured out my answer just by typing this, but will leave it open for answers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is simply this:&#xA;(sorry, I don't know how to format things here)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have the following matrix composed of Right Up and Forward vectors:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rx Ry Rz&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ux Uy Uz&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fx Fy Fz&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a row-majored, orthonormal rotation matrix. Now I have a vector V as {V1 V2 V3} as either a 3x1 or 1x3 (right side or left side respectively, else the multiplication doesn't even work out). Is it R * V or V * R in this case of a row-major matrix? Again, not asking about 1x3 on left or 3x1 on right, but rather for a row-specific matrix, which way would produce a valid or meaningful transformation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;{V1*Rx + V2*Ry + V3*Rz, V1*Ux + V2*Uy + V3*Uz, V1*Fx + V2*Fy + V3*Fz} ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OR&lt;/p&gt;&#xA;&#xA;&lt;p&gt;{V1*Rx + V2*Ux + V3*Fx, V1*Ry + V2*Uy + V3*Fy, V1*Rz + V2*Uz + V3*Fz} ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm guessing the second, but would like clarification/confirmation. Thank you again!&lt;/p&gt;&#xA;" OwnerUserId="6824" LastEditorUserId="6824" LastEditDate="2017-06-14T20:38:15.630" LastActivityDate="2017-06-20T15:53:08.717" Title="row and column majored rotation matrix pre- or post- multiplied" Tags="&lt;matrix&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5233" PostTypeId="1" CreationDate="2017-06-13T03:10:34.970" Score="2" ViewCount="629" Body="&lt;p&gt;I'm working with a object tracking project.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Steps:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Preprocessing the image and achieve some candidates regions of interest.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;For each region, test if it is the target by ORB/BF.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;After the target region determined, acquire coordinates of some points on the target and their corresponding coordinates in the world coordinate system.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Use solvePnP(in opencv) to get rotation vector and translation vector.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Translation vector is used in VR for localization and view control.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Tracking jitter means, although the object is stationary, because of some tracking errors, such as noise, the position of the target is slightly changing. Then, &lt;strong&gt;look at step 4 and step 5&lt;/strong&gt;, due to the change, translation vector is slightly changed and with the Head Mounted Device, I feel the jitter all the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Seems to me that tracking jitter is unavoidable because of change in environment or some noise. But one pixel value change can lead to about a few centimeters change in z value in translation vector. So any proper way to deal with it? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have googled but there didn't seem much information. &lt;a href=&quot;http://www.yorku.ca/mack/3dui2009.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Effects of Tracking Technology, Latency, and Spatial Jitter on Object Movement&lt;/a&gt; mentions the phemomenon, but did not provide a solution. So can anyone offer some useful information?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It occurs to me that filtering is needed to do some post processing to the tracking data. But the idea is not very idea. Kalman filter can be used for tracking and can be used to attenuate noise. I don't know whether it can compensate for this kind of jitter (I mean, very small fluctuation in values) very well. And investigate how to incorporate Kalman filter into this project is another topic and need extra time.&lt;/p&gt;&#xA;" OwnerUserId="2131" LastEditorUserId="2041" LastEditDate="2017-06-13T07:50:25.173" LastActivityDate="2017-10-15T13:19:39.503" Title="how to overcome tracking jitter" Tags="&lt;image-processing&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5234" PostTypeId="2" ParentId="5232" CreationDate="2017-06-13T09:03:37.640" Score="2" Body="&lt;p&gt;Okay let us start by pointing out that a colmun major matrix is the same as a transposed row major matrix. So:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;{M_{cm}}^{T} = M_{rm} \tag{1}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then notice that matrixes have following properties. Matrix multiplication is associative (2a) and that the distribution of transpose reverses computation order (2b).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;A(BC)  =  (AB)C \tag{2a}&#xA;$$&#xA;$$&#xA;(AB)^T  =  B^TA^T \tag{2b}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From these follow that the chain of multiplication events can be as long as one likes and all transpose does is inverse the computation. So given that we can conclude &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;{T_1}\ {T_2}\ \ldots\ {T_n}\ \vec{v} = \vec v\,^T\ {T_n}^T\ \ldots\ {T_2}^T\ {T_1}^T, \tag{3}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so calculating in column major order &lt;strong&gt;is the same calculation&lt;/strong&gt; as calculating in row major orientation. The difference is that the order of computation is reversed. An interpretation of this is that the difference is the same as looking at the object from the outside or looking at the situation from the object out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Formula 3 should provide you the insight. Just one more thing a column vector is the same as a transpose of a row vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: You are allowed to mix and match the computations as much as you like. All you have do is remember is that the other approach is just transposed.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-06-13T10:22:32.700" LastActivityDate="2017-06-13T10:22:32.700" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5236" PostTypeId="1" AcceptedAnswerId="5237" CreationDate="2017-06-13T17:00:00.227" Score="6" ViewCount="284" Body="&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; Is there a name for a type of (non-physical) projection that causes objects to become larger the farther they are from a camera?&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;With a &lt;strong&gt;fisheye&lt;/strong&gt; projection, an object twice as far from the camera is less than half the size on screen. &lt;em&gt;(I think; my understanding of fisheye math is fuzzy. I gather there are various projections/mapping functions.)&lt;/em&gt; There is massive foreshortening, objects shrink very quickly as they move away.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;With a &lt;strong&gt;rectilinear&lt;/strong&gt; projection, an object twice as far from the camera is always half the size on screen, regardless of FoV. This is how trigonometry works. Infinitely-far objects have zero size.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/LmYtx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LmYtx.png&quot; alt=&quot;Triangles showing two different field of view, showing that twice the distance yields an image plane that is twice the size&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;With an &lt;strong&gt;orthographic&lt;/strong&gt; projection, an object twice as far from the camera is always the same size on screen. There is no foreshortening. Infinitely-far objects have the same size.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Now, go one step farther. I want negative foreshortening. I want to see an object get bigger the farther away it gets. Infinitely-far objects have infinite size.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6832" LastEditorUserId="231" LastEditDate="2017-06-15T17:44:27.200" LastActivityDate="2017-06-15T17:44:27.200" Title="3D projection that increases objects' size as they become more distant" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5237" PostTypeId="2" ParentId="5236" CreationDate="2017-06-13T18:30:10.880" Score="4" Body="&lt;p&gt;After a quick google of 'Inverted perspective' I found out that you have five different names for it; Reverse perspective, inverse perspective, inverted perspective, divergent perspective and Byzantine perspective. &lt;a href=&quot;https://en.wikipedia.org/wiki/Reverse_perspective&quot; rel=&quot;noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Reverse_perspective&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that if you want to use it in a render engine using a projection matrix, in the perspective divide, you use multiply by w instead of divide. This is because in a perspective projection, the divide by w is what actually gives the perspective. In a orthographic projection w is always 1, meaning that there is no actual perspective.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a ray tracer you probably just need to scale the image plane up of course, but probably instead of having the origin of the ray to be the center of the camera, you have some kind of second image plane that is larger than the actual image plane. If both are the same size, the rays are straight and you have an orthographic projection, if the actual image plane is smaller then you have your Reverse perspective.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quick extra note: If you have proper lenses, you might be able to get this effect in real life. Yes, you would need to have a lens that is a few meters in diameter, but I do not think it is impossible! :P&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this will help you and that I have not made any mistakes. Good luck with whatever you are doing!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2017-06-13T18:30:10.880" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5238" PostTypeId="2" ParentId="5214" CreationDate="2017-06-13T19:01:26.207" Score="4" Body="&lt;p&gt;For cases where the diffusion approximation is preferred over full volumetric path tracing, the method published by Solid Angle is fairly efficient:&#xA;&lt;a href=&quot;https://www.solidangle.com/research/s2013_bssrdf_slides.pdf&quot; rel=&quot;noreferrer&quot;&gt;https://www.solidangle.com/research/s2013_bssrdf_slides.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is implemented in the Arnold render engine, Blender's Cycles, and pbrt, the latter being open source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The file which implements it in PBRT is here:&#xA;&lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/7095acfd8331cdefb03fe0bcae32c2fc9bd95980/src/core/bssrdf.cpp&quot; rel=&quot;noreferrer&quot;&gt;https://github.com/mmp/pbrt-v3/blob/7095acfd8331cdefb03fe0bcae32c2fc9bd95980/src/core/bssrdf.cpp&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-06-13T19:01:26.207" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5239" PostTypeId="1" AcceptedAnswerId="5240" CreationDate="2017-06-14T01:28:19.090" Score="3" ViewCount="116" Body="&lt;p&gt;How can i store the X,Y,Z vertex points of a mesh into a 2d image, such that reading the image pixel values will correspond to the 3d coordinates? is it possible to just store x, y, values on a grid and use the Z value as an intensity value?&lt;/p&gt;&#xA;" OwnerUserId="6834" LastActivityDate="2017-06-14T01:56:42.377" Title="Store 3d coordinates in a 2d image?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5240" PostTypeId="2" ParentId="5239" CreationDate="2017-06-14T01:56:42.377" Score="2" Body="&lt;p&gt;The most straightforward way would be to put x into the red channel, y into the green channel, and z into the blue channel of each pixel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could also make a 1 channel image where intensity is used to describe height. This is called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Heightmap&quot; rel=&quot;nofollow noreferrer&quot;&gt;height map&lt;/a&gt;. Usually the x and y of the mesh are the same as the x and y of the image, so no need to store them in any way.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-06-14T01:56:42.377" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5242" PostTypeId="1" CreationDate="2017-06-14T15:22:22.347" Score="1" ViewCount="71" Body="&lt;p&gt;I'm confused by the Mitsuba bidirectional framework for quite a while now, especially by the different &lt;code&gt;eval&lt;/code&gt; and &lt;code&gt;connect&lt;/code&gt; functions, as well as the &lt;code&gt;weight&lt;/code&gt; and &lt;code&gt;pdf&lt;/code&gt; variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, what is the difference between &lt;code&gt;PathVertex::eval&lt;/code&gt; and &lt;code&gt;PathVertex::weight[]&lt;/code&gt;, and &lt;code&gt;PathVertex::evalPdf&lt;/code&gt; and &lt;code&gt;PathVertex::pdf[]&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the differences between &lt;code&gt;PathEdge::evalCached&lt;/code&gt;, &lt;code&gt;PathEdge::eval*&lt;/code&gt;, &lt;code&gt;PathEdge::weight[]&lt;/code&gt;, &lt;code&gt;PathEdge::pdf[]&lt;/code&gt;, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, how do the &lt;code&gt;PathVertex::connect&lt;/code&gt; and &lt;code&gt;PathEdge::pathConnectAndCollapse&lt;/code&gt; differ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make the problem more concrete, let's say I have two vertices, one at the end of an emitter subpath, call it $y_{s-1}$ and one at the end of a sensor subpath, $x_{t-1}$, both surface interactions. &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What is the correct way of connecting these two?&lt;/li&gt;&#xA;&lt;li&gt;If I want to calculate $f(y_{s-2} \rightarrow y_{s-1} \rightarrow z_{t-1}) G(y_{s-1} \leftrightarrow x_{t-1}) f(y_{s-1} \rightarrow z_{t-1} \rightarrow z_{t-2})$, what is the correct way of going about this?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot in advance!&lt;/p&gt;&#xA;" OwnerUserId="6367" LastActivityDate="2017-06-14T15:22:22.347" Title="Mitsuba Bidirectional Framework" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;physically-based&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5243" PostTypeId="1" AcceptedAnswerId="5249" CreationDate="2017-06-14T20:47:35.490" Score="4" ViewCount="416" Body="&lt;p&gt;How does one go about taking a single photograph, like a picture of a rock wall, and getting a decent normal map out of it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you can, I'd like to learn about the mechanics behind it, and not a piece of software like CrazyBump that does it for me.&lt;/p&gt;&#xA;" OwnerUserId="6838" LastEditorUserId="6838" LastEditDate="2017-06-15T17:59:37.277" LastActivityDate="2017-06-17T08:11:39.670" Title="How are Normal Maps created?" Tags="&lt;texture&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="17" ContentLicense="CC BY-SA 3.0" />
  <row Id="5245" PostTypeId="1" AcceptedAnswerId="5248" CreationDate="2017-06-15T16:50:43.420" Score="2" ViewCount="543" Body="&lt;p&gt;At the moment, I render everything in my OpenGL application to a single framebuffer (color only, no depth buffer). I then go from the texture ID and read out some data to use it. My problem is, in the init, I first init the GLFW window, make it visible calling &lt;code&gt;glfwShowWindow(window);&lt;/code&gt; and then create the frame buffer. This means I have an empty window showing up where nothing is rendered. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But when I comment this line to keep the window hidden, the frame buffer status after creation is &lt;code&gt;GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT&lt;/code&gt;. How do I go about rendering offscreen without window, and is there a possibility to not use GLFW at all?&lt;/p&gt;&#xA;" OwnerUserId="6092" LastActivityDate="2020-07-27T14:47:59.770" Title="LWJGL 3 render to texture offscreen without display" Tags="&lt;opengl&gt;&lt;frame-buffer&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5246" PostTypeId="1" AcceptedAnswerId="5264" CreationDate="2017-06-16T09:02:40.483" Score="4" ViewCount="342" Body="&lt;p&gt;I want to write plugin (library) for Unity3d (it doesn't matter which framework I will choose for this, question is ), for cutting arbitrary mesh with plane (for simplicity it will be plane for beginning). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qvcgX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qvcgX.png&quot; alt=&quot;Cutting simple (convex to be more precise) figures with plane&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are following steps:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) check every triangle whether it lies above, under plane or intersected by plane, assign all vertices to &lt;code&gt;VER_ABOVE&lt;/code&gt; or &lt;code&gt;VER_UNDER&lt;/code&gt; lists, recalculate triangles, put them in &lt;code&gt;TRI_ABOVE&lt;/code&gt; or &lt;code&gt;TRI_UNDER&lt;/code&gt; lists&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Split intersected triangles into triangle and quadrilateral, triangulate last one and put them in corresponding lists (&lt;code&gt;TRI_ABOVE&lt;/code&gt; or &lt;code&gt;TRI_UNDER&lt;/code&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) Triangulate slice surface, assign it to &lt;code&gt;TRI_ABOVE&lt;/code&gt; and &lt;code&gt;TRI_UNDER&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;And now the question:&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where it is better to calculate intersections, triangulation (for example I will use Constrained Delaunay Triangulation or Sweep Line Non-Convex Polygonal Triangulation cutting into monotone polygonals) and other stuff: on CPU or on GPU (using Shaders), if someone could explain me general pipeline from loading cashing mesh to memory and so on on GPU and on CPU, so I can better understand the most time consuming actions and can optimize some stuff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will also be thankful for sharing link on code examples calculating similar stuff.&lt;/p&gt;&#xA;" OwnerUserId="6841" LastActivityDate="2017-06-20T12:12:02.687" Title="What is better to use for real-time computing Mesh - Plane intersection points, GPU or CPU?" Tags="&lt;shader&gt;&lt;real-time&gt;&lt;mesh&gt;&lt;triangulation&gt;&lt;tesselation&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5247" PostTypeId="2" ParentId="5230" CreationDate="2017-06-16T12:05:35.587" Score="2" Body="&lt;p&gt;Skimming the math.  Starting with a quaternion $Q=w+\left(x,y,z\right)$ then we can rotate $\mathbf{v}$ by:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathbf{v}' = Q\mathbf{v}Q^{-1}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and if $Q$ is unit magnitude this reduces to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathbf{v}' = Q\mathbf{v}Q^*$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To create a matrix we need to apply the rotation to the basis set to form our three equations:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\mathbf{x} = \left(1,0,0\right) \\&#xA;\mathbf{y} = \left(0,1,0\right) \\&#xA;\mathbf{z} = \left(0,0,1\right) \\&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which expanded and reduced gives:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\mathbf{x}' = Q\mathbf{x}Q^{-1} = \left(1 - 2 \left(y^2+z^2\right), 2\left(xy+wz\right), 2\left(xz-wy\right) \right) \\&#xA;\mathbf{y}' = Q\mathbf{y}Q^{-1} = \left(2 \left(xy-wz\right), 1 - 2\left(x^2+z^2\right), 2\left(wx+yz\right) \right)  \\&#xA;\mathbf{z}' = Q\mathbf{z}Q^{-1} = \left(2 \left(wy+xz\right), 2\left(yz-wx\right), 1 - 2\left(x^2+y^2\right) \right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sticking to the math convention of column vectors, then we shove the three equations into the first three columns and to add a translation by $\left(t_x,t_y,t_z\right)$ we shove that into the last column giving:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;{&#xA;\left( \begin{array}{ccc}&#xA;1 - 2 \left(y^2+z^2\right) &amp;amp; 2\left(xy-wz\right)       &amp;amp;  2\left(xz+wy\right)  &amp;amp; t_x\\&#xA;2 \left(xy+wz\right)       &amp;amp; 1 - 2\left(x^2+z^2\right) &amp;amp;  2\left(wx-yz\right)  &amp;amp; t_y \\&#xA;2 \left(wy-xz\right)       &amp;amp; 2\left(yz+wx\right)       &amp;amp; 1 - 2\left(x^2+y^2\right) &amp;amp; t_z \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{array} \right)&#xA;}&#xA;$$&lt;/p&gt;&#xA;" OwnerUserId="2831" LastActivityDate="2017-06-16T12:05:35.587" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5248" PostTypeId="2" ParentId="5245" CreationDate="2017-06-16T18:01:59.833" Score="1" Body="&lt;p&gt;So the way I went by not showing the window seems the way to go, and the error about &lt;code&gt;GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT&lt;/code&gt;apparently wasn't related to this at all and is gone.&lt;/p&gt;&#xA;" OwnerUserId="6092" LastActivityDate="2017-06-16T18:01:59.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5249" PostTypeId="2" ParentId="5243" CreationDate="2017-06-17T08:11:39.670" Score="5" Body="&lt;p&gt;&quot;decent&quot; is quite subjective and if you are restricting the capture to certain types of surfaces and controlled lighting conditions. For example normals and other &lt;a href=&quot;https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function&quot; rel=&quot;noreferrer&quot;&gt;SVBRDF&lt;/a&gt; parameters for shiny metallic surfaces are very difficult to capture compared to non-metallic, matte and bright surfaces without texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are tools proposed in comments (&lt;a href=&quot;http://www.crazybump.com/&quot; rel=&quot;noreferrer&quot;&gt;CrazyBump&lt;/a&gt;, &lt;a href=&quot;https://github.com/kmkolasinski/AwesomeBump&quot; rel=&quot;noreferrer&quot;&gt;AwesomeBump&lt;/a&gt;) that try to do what you ask for and may generate normal maps sufficient to your requirements, but you could argue how &quot;decent&quot; the results are and how robust these tools are in capturing different types of surfaces. I don't know about the algorithms these tools use, but I believe they use more of an &quot;artistic&quot; than robust/accurate methods in generating the results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is some recent work to estimate normal map and other SVBRDF parameters using &lt;a href=&quot;https://mediatech.aalto.fi/publications/graphics/TwoShotSVBRDF/&quot; rel=&quot;noreferrer&quot;&gt;two images&lt;/a&gt; or from a &lt;a href=&quot;https://mediatech.aalto.fi/publications/graphics/NeuralSVBRDF/&quot; rel=&quot;noreferrer&quot;&gt;single image&lt;/a&gt; (using neural networks), which is probably your best bet. However these algorithms assume a level of repeating pattern in the input images, but this might be ok for you since you mention rock wall as an example. There are likely other constraints as well such as requiring the captured surface to be dielectric hard surface material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more robust SVBRDF capturing you can check paper on &lt;a href=&quot;https://mediatech.aalto.fi/publications/graphics/FourierSVBRDF/&quot; rel=&quot;noreferrer&quot;&gt;frequency domain capture&lt;/a&gt;, but this is more complex capturing setup and far from a single image capture.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Z80R5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z80R5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To my knowledge there's no known generic algorithm to accurately extract SVBRDF parameters from a single image of a non-repeating surface because of the fundamental issue that a single image can't unambiguously represent SVBRDF parameters. E.g. two different normal &amp;amp; albedo combinations of a &lt;a href=&quot;https://en.wikipedia.org/wiki/Lambertian_reflectance&quot; rel=&quot;noreferrer&quot;&gt;Lambertian surface&lt;/a&gt; may result in same pixel color in a single image.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-06-17T08:11:39.670" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5251" PostTypeId="1" CreationDate="2017-06-17T13:40:25.280" Score="5" ViewCount="138" Body="&lt;p&gt;I'am studying PBR and the book introduce the potential equation.&#xA;They said the potential equation can describe shooting algorithms better, and&#xA;$W(x, \theta)$ describes the fraction of the radiance $L(x, \theta)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I could not understand the concept. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is just $W(x, \theta)$ a fraction such as $\frac{1}{3}$(I know the original equation is quite complicate, integral) to reduce the radiance $L$ which is derived from a light source? (because the L would be diminished if it collides with objects).&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2017-06-17T13:40:25.280" Title="What is the potential equation in PBR?" Tags="&lt;physically-based&gt;&lt;pbr&gt;&lt;photo-realistic&gt;&lt;realistic&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5252" PostTypeId="2" ParentId="5232" CreationDate="2017-06-18T11:55:14.240" Score="0" Body="&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let $M=\Biggl[\begin{matrix} Rx &amp;amp; Ux &amp;amp; Fx\\ Ry &amp;amp; Uy &amp;amp; Fy\\ Rz &amp;amp; Uz &amp;amp; Fz\\ \end{matrix}\Biggl], V = \Biggl(\begin{matrix}Vx\\ Vy\\ Vz \end{matrix}\Biggl)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct multiplication is:&#xA;$V' = M V$ or $V'^T = V^TM^T$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now to the proper explanation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whenever we define a coordinate in $R^{3}$ space that coordinate must be in respect to a basis. When one state that an arbitrary point in $R^{3}$ is $(x, y, z)$ it is implicit that this is in respect to the standard basis. Let's call $\vec{r}, \vec{u}, \vec{f}$ the axes that define an arbitrary basic $B$ in $R^{3}$. An arbitrary point $P$ can be defined as &#xA;$$P = x * \vec{r} + y * \vec{u} + z * \vec{f}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Expanding we have:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$P_x = x * \vec{r_x} + y * \vec{u_x} + z * \vec{f_x}$$&#xA;$$P_y = x * \vec{r_y} + y * \vec{u_y} + z * \vec{f_y}$$&#xA;$$P_z = x * \vec{r_z} + y * \vec{u_z} + z * \vec{f_z}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In matrix form we can write that as:&#xA;$$\Biggl(\begin{matrix}P_x\\ &#xA;  P_y\\ &#xA;  P_z\\ &#xA;\end{matrix}\Biggl)=\Biggl[\begin{matrix} &#xA;  \vec{r_x} &amp;amp; \vec{u_x} &amp;amp; \vec{f_x}\\ &#xA;  \vec{r_y} &amp;amp; \vec{u_y} &amp;amp; \vec{f_y}\\ &#xA;  \vec{r_z} &amp;amp; \vec{u_z} &amp;amp; \vec{f_z}\\ &#xA;\end{matrix}\Biggl]\Biggl(\begin{matrix} &#xA;  x\\ &#xA;  y\\ &#xA;  z\\ &#xA;\end{matrix}\Biggl)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another easy way to check this is to think about what is a rotation matrix. The matrix &#xA;$$R_z = \Biggl[\begin{matrix} cos(\theta) &amp;amp; -sin(\theta) &amp;amp; 0\\ sin(\theta) &amp;amp; cos(\theta) &amp;amp; 0\\ 0 &amp;amp; 0 &amp;amp; 1\\ \end{matrix}\Biggl]$$ rotates a vector $\vec{v}$ by $\theta^{\circ}$ around $z$ axis or, to think in another way, represents $\vec{v}$ in a basis that is rotated $\theta^{\circ}$ from the standard basis. If you compute the axes of this new rotated basis you'll see that the new $\vec{r}, \vec{u}, \vec{f}$ of this rotated matrix are the columns of $R_z$ matrix.&lt;/p&gt;&#xA;" OwnerUserId="250" LastEditorUserId="250" LastEditDate="2017-06-20T15:53:08.717" LastActivityDate="2017-06-20T15:53:08.717" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5253" PostTypeId="1" CreationDate="2017-06-18T15:19:31.403" Score="0" ViewCount="678" Body="&lt;p&gt;I am trying to run the following program on ubuntu 15.04. However on typing &quot;g++ pgm1.cpp -lglut&quot;&#xA;I am getting following errors&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;/usr/bin/ld: /tmp/cc9aXqhZ.o: undefined reference to symbol 'glClear'&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: error adding symbols: DSO missing from command line&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though I am familiar with C programming in Codeblocks and DevC++, this is the first time I am working on Ubuntu and OpenGL. I installed ubuntu and files related to OpenGL based on information available on the net. The sample program too is from the internet. I would request help in getting the program run. Thanks.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;# include &quot;GL/freeglut.h&quot;&#xA;# include &quot;GL/gl.h&quot;&#xA;# include &amp;lt;GL/glut.h&amp;gt;&#xA;&#xA;void init(void)&#xA;{&#xA;glClearColor(0.0f,0.0f,1.0f,1.0f);&#xA;}&#xA;void display (void) &#xA;{&#xA;glClear(GL_COLOR_BUFFER_BIT);&#xA;glFlush();&#xA;}&#xA;int main (int argc, char** argv)&#xA;{&#xA;glutInit(&amp;amp;argc,argv);&#xA;glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);&#xA;glutCreateWindow(&quot;A Blank Window&quot;);&#xA;init();&#xA;glutDisplayFunc(display);&#xA;glutMainLoop();&#xA;return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5099" LastActivityDate="2018-04-11T01:59:02.523" Title="Errors on Compiling my first program on OpenGL on Ubuntu" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5254" PostTypeId="1" AcceptedAnswerId="5257" CreationDate="2017-06-19T02:01:58.190" Score="3" ViewCount="252" Body="&lt;p&gt;The following four SVG paths render the same (using the default &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill-rule&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;fill-rule=&quot;nonzero&quot;&lt;/code&gt;&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;path id=&quot;cwOccwI&quot; d=&quot;M0,0 10,0 10,10zM5,2 8,5 8,2z&quot; transform=&quot;translate( 0,0)&quot;/&amp;gt;&#xA;&amp;lt;path id=&quot;ccwOcwI&quot; d=&quot;M0,0 10,10 10,0zM5,2 8,2 8,5z&quot; transform=&quot;translate(15,0)&quot;/&amp;gt;&#xA;&amp;lt;path id=&quot;ccwIcwO&quot; d=&quot;M5,2 8,5 8,2zM0,0 10,0 10,10z&quot; transform=&quot;translate(30,0)&quot;/&amp;gt;&#xA;&amp;lt;path id=&quot;cwIccwO&quot; d=&quot;M5,2 8,2 8,5zM0,0 10,10 10,0z&quot; transform=&quot;translate(45,0)&quot;/&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4yENe.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4yENe.png&quot; alt=&quot;Four triangles with triangular holes inside&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As hinted at by the IDs, these are combinations of clockwise (&lt;code&gt;cw&lt;/code&gt;) and counter-clockwise (&lt;code&gt;ccw&lt;/code&gt;) orientations for the outer (&lt;code&gt;O&lt;/code&gt;) and inner (&lt;code&gt;I&lt;/code&gt;) subpaths, varying the order the subpaths are added.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm converting SVG paths to &lt;a href=&quot;http://geojson.org/&quot; rel=&quot;noreferrer&quot;&gt;GeoJSON&lt;/a&gt;. It requires a single 'positive' subpath that is oriented counter-clockwise, and any/all &lt;a href=&quot;https://tools.ietf.org/html/rfc7946#section-3.1.6&quot; rel=&quot;noreferrer&quot;&gt;'hole' subpaths to be oriented clockwise&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given an SVG path with subpaths (which I can assume/guarantee will not overlap), how can I determine which subpath(s) are 'positive' paths, and which are 'holes'? As shown above, I cannot rely on the orientation of the points within the path, and I cannot rely on the ordering of sub-paths.&lt;/p&gt;&#xA;" OwnerUserId="6832" LastActivityDate="2017-06-19T14:01:50.707" Title="Determining the 'outer' subpath in a compound SVG path" Tags="&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5255" PostTypeId="2" ParentId="5253" CreationDate="2017-06-19T06:49:26.527" Score="4" Body="&lt;p&gt;You need to link with the OpenGL library. Try adding &lt;code&gt;-lgl&lt;/code&gt; to the compilation command.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2017-06-19T06:49:26.527" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5256" PostTypeId="1" CreationDate="2017-06-19T12:58:32.157" Score="3" ViewCount="272" Body="&lt;p&gt;Only a few games have resizable windows when running in full screen mode. All others have a finite fixed set of allowed resolutions. But why? I see some reasons, but none of them seems to be that important to me that would justify such a user-unfriendly feature.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's use Dark Souls II, because it's the first I can think of. The allowed resolutions are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;800x450&#xA;1024x576&#xA;1152x648&#xA;1280x720&#xA;1440x810&#xA;1600x900&#xA;1680x945&#xA;1920x1080&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What is the reason to not allow the resolutions &lt;code&gt;800x451, 800x452, ..., 801x450, 801x451, ...&lt;/code&gt;? What it I think can't be:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;The UI.&lt;/strong&gt; If we keep minimum and maximum window sizes as limitations, the only issue I can see here is with settings with a weird aspect ratio (1920x450, 800x1080). Otherwise, there shouldn't be any problems with free scaling between the resolutions.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Camera, Viewport.&lt;/strong&gt; Same as above.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6092" LastEditorUserId="6092" LastEditDate="2017-06-19T13:47:25.987" LastActivityDate="2017-06-19T22:24:19.707" Title="Why do games only allow certain resolutions?" Tags="&lt;rendering&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5257" PostTypeId="2" ParentId="5254" CreationDate="2017-06-19T14:01:50.707" Score="2" Body="&lt;p&gt;If you can assume the subpaths are non-intersecting (and non-self-intersecting), and that the fill rule is always the nonzero rule, the easiest way is probably to pick the first point on the first subpath, and do &lt;a href=&quot;https://en.wikipedia.org/wiki/Point_in_polygon&quot; rel=&quot;nofollow noreferrer&quot;&gt;a standard point-in-polygon test&lt;/a&gt; with the polygons defined by each other subpath. If the point is not inside any other subpath, then this subpath is the outermost one. If the point is inside one other subpath, that one must be the outermost one. If the point is inside more than one other subpath, take the set of subpaths it is inside and repeat the test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously doing it this way requires that there is only one outermost subpath. It's entirely possible in SVG to have multiple disjoint subpaths in one path, and you didn't say whether this is possible in your source data. If it is possible, then you'll have to test every subpath to find out which other subpath(s) it is inside. Each time you run the point-in-polygon test, you find the subpath you're considering is either an outermost one, or you'll find out which subpath it is inside. If it's inside another path, you don't need to consider it in any further tests. At the end, you have a list of outermost subpaths, each of which has a list of all the subpaths it encloses. You can turn each outermost subpath into a separate GeoJSON polygon.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-06-19T14:01:50.707" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5258" PostTypeId="1" CreationDate="2017-06-19T15:43:21.463" Score="0" ViewCount="70" Body="&lt;p&gt;I need a 3D triangular sphere mesh with uniformly sampled vertices, say $V$, with a predefined adjacency. Is there a specific way to achieve that?&lt;/p&gt;&#xA;" OwnerUserId="6854" LastActivityDate="2017-06-19T15:43:21.463" Title="3D sphere mesh with a predefined number of vertices and a given adjacency matrix of vertices" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5260" PostTypeId="2" ParentId="3960" CreationDate="2017-06-19T15:58:53.210" Score="3" Body="&lt;p&gt;Just to comment on the 0.16*Specular^2 term that was mentioned in the comments by Karim:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Frostbite only &lt;strong&gt;remaps&lt;/strong&gt; the specularity for their internal purpose so that they can pack gemstones specularity into the 8bit channel. They just lose some precision in favor of more variation. The specularity value is the original one when rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check the Disney BRDF viewer which is a awesome start for PBR, since it contains the whole BRDF from Disney.&#xA;&lt;a href=&quot;https://www.disneyanimation.com/technology/brdf.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;BRDF Explorer | Walt Disney Animation Studios&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, if you are looking at a better Fresnel function than&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 Light_F(in vec3 Specular, in float VH) {&#xA;    // Fresnel Schlick&#xA;    return Specular + (1-Specular) * pow(1-VH, 5.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Use this instead since it takes roughness/gloss into account:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 Light_F(in vec3 Specular, in float VH, in float gloss) &#xA;{&#xA;    return Specular + (max(vec3(gloss), Specular) - Specular) * pow(1-VH, 5.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6855" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T09:41:35.750" LastActivityDate="2018-04-09T09:41:35.750" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5261" PostTypeId="2" ParentId="5256" CreationDate="2017-06-19T22:14:25.480" Score="6" Body="&lt;p&gt;Note that in your Dark Souls example, all the resolutions listed are the exact same aspect ratio.  So the question is, why doesn't it support arbitrary aspect ratios?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The answer is that it costs time and effort to support arbitrary aspect ratios, and if that money spent doesn't translate to increased profit, then it doesn't make sense to do.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;This &lt;a href=&quot;http://gamedev.stackexchange.com/a/125316/26734&quot;&gt;answer&lt;/a&gt; covers the 2d layout issues, which includes extra time and effort to create a versatile layout that can be resized so that elements do not overlap, stretch, or pixelate in an undesired manner, and that the overal UI maintains the best user experience.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The developer would have to ensure that the window doesn't get too large or too small.  Does it make the game any better if the user can drag the window size to be smaller than 800 x 450?  probably not.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;you have to define the behavior of the camera when the aspect ratio changes. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;For example, take the following scene:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5YUYg.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5YUYg.png&quot; alt=&quot;Original Aspect Ratio&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we allow the user to change the horizontal size, we can decide to &quot;zoom out&quot; horizontally so that the same area still shows up horzontally but now we can see more vertically.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/998Of.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/998Of.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, instead, we can keep the same zoom level but just clip the viewing area more:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cHGce.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cHGce.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note, that if you don't specifically handle the changing aspect ratio, the default graphics pipeline behavior will be to stretch the image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jJbqG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jJbqG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These decisions take time and effort to design, code and test, but management has to decide if it actually makes the user experience better enough to be worth the time.  Apparently, most games have decided its not worth the effort.  I'd even go further and suggest that allowing users to screw up the best layout of the game is a bad feature.&lt;/p&gt;&#xA;" OwnerUserId="3332" LastEditorUserId="3332" LastEditDate="2017-06-19T22:24:19.707" LastActivityDate="2017-06-19T22:24:19.707" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5263" PostTypeId="1" CreationDate="2017-06-20T07:27:43.027" Score="1" ViewCount="133" Body="&lt;p&gt;Below there are two identical meshes, however the first one has edges moving in random directions, the second one has edges moving in a orderly, uniform fashion (edge flow). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F99iV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F99iV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;i want to be able to make a mesh with uniform edges (good edge flow) from a mesh with bad edge flow.&lt;/p&gt;&#xA;" OwnerUserId="6834" LastEditorUserId="6834" LastEditDate="2017-06-24T01:09:37.547" LastActivityDate="2017-06-29T22:07:12.803" Title="How do you get edge flow information from mesh" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="5264" PostTypeId="2" ParentId="5246" CreationDate="2017-06-20T12:12:02.687" Score="3" Body="&lt;p&gt;doing the calculation to decide whether a point is on one side of a plane or the other is very simple (a single dot product). Doing that 3 times and having a special case when they don't match to split the triangle is pretty fast. It's also a parallel problem. The hardest part is reserving the space for the output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Preparing the data to start computing this on the gpu is already enough overhead that it's not worth doing it on the gpu unless the mesh is very big or you are splitting it multiple times (due to the plane moving for example). Or the data is already in good enough condition to be sent over to the gpu directly through DMA without the cpu needing to touch it at all.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-06-20T12:12:02.687" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5265" PostTypeId="1" AcceptedAnswerId="5266" CreationDate="2017-06-20T13:56:18.387" Score="1" ViewCount="361" Body="&lt;p&gt;I'm currently researching how to compute geometric properties of architectural shapes based on their 3D meshes, and am stuck for some time on the &lt;strong&gt;area&lt;/strong&gt; and &lt;strong&gt;perimeter&lt;/strong&gt; calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, the &lt;strong&gt;area&lt;/strong&gt;: assuming that I have the proportions set right, if, for example, I have a wall with 3 meters of height, 7.8 meters of width and 0.290 meters of thickness I'm interested in the result of height * width &lt;code&gt;(3 * 7.8)&lt;/code&gt;, which would give me 23.4 meters in this case. My idea is to obtain a 2D projection of this 3D mesh onto a plane parallel to it, calculate the surface area of each triangle and sum them up, what I believe would give me the mesh area independent of it's shape, assuming that it is planar. The problem is, how exactly can I obtain this triangulated projection? I believe that if the mesh is aligned to the world axis it would simply be a matter of ignoring one of them, but unfortunatelly this is an assumption that can't be made, as there will be meshes rotated in relation to one or more axis, and just ignoring an axis would distort the projection. Aditionaly, is there any method that would work even in the case of a non-planar mesh?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, for the &lt;strong&gt;perimeter&lt;/strong&gt;: having the area problem solved, is there any robust algorithm that would give me the contours of this 2D triangulated projection, and that would work with both convex and concave meshes? I believe that with this it would be a matter of simply adding up all the edges of the contour.&lt;/p&gt;&#xA;" OwnerUserId="6788" LastActivityDate="2017-06-20T14:53:09.700" Title="Compute area (not surface area) and perimeter of a mesh" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;&lt;projections&gt;&lt;area&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5266" PostTypeId="2" ParentId="5265" CreationDate="2017-06-20T14:53:09.700" Score="2" Body="&lt;p&gt;There's a small problem with your method. When the mesh self shadows then part of the model will be counted twice. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get the projection of a mesh onto an arbitrary plane by finding the rotation from the normal of the plane to the Z axis and rotating the mesh with it. After that you discard the Z component.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However it's more straightfoward to simply draw the mesh with appropriate projection and counting how many pixels it takes up.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;An edge can be part of the perimeter only when both the triangles that make it are projected onto the same side of the projected line. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can use that to walk around the perimeter. Start with the negative x most point after the rotation and follow the lines. When another potential perimeter line crosses the current line you start following that one instead.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-06-20T14:53:09.700" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="5267" PostTypeId="1" AcceptedAnswerId="5290" CreationDate="2017-06-21T10:14:47.927" Score="8" ViewCount="154" Body="&lt;p&gt;I'm currently learning mathemetical concepts of distribution and the way to use them in a ray tracer with the book &quot;Physically Based Rendering&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's start by uniformly sampling an hemisphere:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you probably know, a way to generate the uniformly distributed direction is to use the inversion method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us denote by $p$ our uniform probability density function:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p(\omega) = \cfrac{1}{2\pi}$ and so $p(\theta, \phi) = \sin(\theta)p(\omega)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you compute $p(\theta)$, $p(\phi | \theta)$, you integrate your cumulative distribution function and you invert the function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My questions are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;What does $p(\theta, \phi)$ really mean?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;What is the transformation between $p(\omega)$ and $p(\theta, \phi)$?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;In the book, to find $p(\theta,\phi)$ they state that $p(\theta, \phi) d\theta d\phi = p(\omega)d\omega$, but why?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I know that for $p(\omega)$, our random variable is a given $\omega$ (a direction), so the function represents a relative probability for this direction (so a solid angle, because the relative term implies a direction and a delta area around this direction).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But for $p(\theta,\phi)$, our random variable is now the couple $(\theta,\phi)$. To what extent is it different from a direction?&lt;/p&gt;&#xA;" OwnerUserId="6862" LastEditorUserId="231" LastEditDate="2017-06-21T23:47:23.690" LastActivityDate="2017-06-30T12:20:17.527" Title="2D sampling with multidimensional transformations" Tags="&lt;raytracing&gt;&lt;mathematics&gt;&lt;sampling&gt;&lt;distribution&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5269" PostTypeId="1" CreationDate="2017-06-21T19:17:54.407" Score="2" ViewCount="49" Body="&lt;p&gt;My goal is to create a noise model so that the &lt;a href=&quot;https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Peak Signal to Noise Ratio&quot;&gt;PSNR&lt;/a&gt; of the noisy image compared to the original is some pre-defined constant $\alpha$. This means the mean squared-error will also be a constant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My model is as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The additive noise is a random normally distributed variable with $\mu = 0$ and unknown $\sigma$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$K(i,j) = I(i,j) + f(x; 0, \sigma)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ MSE = \frac{1}{mn}\sum_{i = 0}^{m - 1}\sum_{j = 0}^{n - 1}\ [K(i,\ j) - I(i,\ j)]^2 = \frac{1}{mn}\sum_{i = 0}^{m - 1}\sum_{j = 0}^{n - 1}\ [\ f(x;\ 0,\  \sigma)]^2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $$f(x;\ 0,\ \sigma) = \frac{1}{\sqrt{2\pi}\sigma}e^{\frac{-x^2}{2\sigma^2}}$$&#xA;i.e. the Gaussian pdf with unknown variance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'm confused about is how to solve for sigma when the values of the pdf are supposed to be independent samples from the distribution. If I'm understanding correctly, this means that the MSE itself becomes a random variable and cannot be a constant. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we were to make it a constant, wouldn't the values of $f(x)$ for each pixel have to already be known for the equation to be solvable? In which case the distribution would need to be already known to randomly sample the distribution to produce the values of $f(x)$...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyhow, if anyone has advice on how to construct noisy images with a pre-defined PSNR, that would be appreciated.&lt;/p&gt;&#xA;" OwnerUserId="6865" LastEditorUserId="231" LastEditDate="2017-06-21T23:38:22.057" LastActivityDate="2017-06-21T23:38:22.057" Title="How to create a noise model with a constant PSNR?" Tags="&lt;noise&gt;&lt;model&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5270" PostTypeId="1" CreationDate="2017-06-22T05:02:09.163" Score="8" ViewCount="991" Body="&lt;p&gt;I have been working on my own renderer for a while, and I'm wondering if there's any way to remove the Monte Carlo noise from the rendered image, besides waiting for a long time for it to converge?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I found is to blur the image, which is not really helpful, since it reduces the quality/sharpness of the image a lot. And I can achieve the same thing by rendering a small image with more samples, then scaling it up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any algorithm designed to deal with noise in the image in path tracing?&lt;/p&gt;&#xA;" OwnerUserId="2448" LastEditorUserId="48" LastEditDate="2017-06-23T06:36:05.500" LastActivityDate="2017-06-23T06:36:05.500" Title="Algorithms to Remove High Frequency Noise from Path Tracing" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;pathtracing&gt;&lt;denoise&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5271" PostTypeId="1" AcceptedAnswerId="5272" CreationDate="2017-06-22T06:48:51.800" Score="6" ViewCount="2781" Body="&lt;p&gt;I have been trying to understand display and graphics. I feel that it's hard to make a logical image of the terms. I understand this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Frame buffer is a dedicated memory that has the image/video/3dimage or video to be shown, in pixel format.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Overlay is some kind of hardware that is used with the frame buffer.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Surfaceflinger is a composition manager. It takes rendered data from the GPU, and composites them in one surface. That means, it uses the underlying hardware and driver to do all this composition.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Composition means blending, mixing of all the surfaces.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Overlay, plane, framebuffer and sprite? What does all this do, or how to combine them and understand?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Any book, links will be appreciated. A lot of books go to graphics way, instead of taking one particular SoC and explain display first then graphics in detail.&lt;/p&gt;&#xA;" OwnerUserId="6868" LastEditorUserId="231" LastEditDate="2017-06-22T23:34:38.627" LastActivityDate="2017-06-23T08:16:48.473" Title="What is the difference in overlay and framebuffer?" Tags="&lt;rendering&gt;&lt;gpu&gt;&lt;frame-buffer&gt;&lt;compositing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5272" PostTypeId="2" ParentId="5271" CreationDate="2017-06-22T08:58:07.610" Score="9" Body="&lt;p&gt;As you've understood, the &lt;em&gt;framebuffer&lt;/em&gt; is an array in memory that holds all the pixels to display on the screen. On a desktop PC, it's probably special memory on the graphics card, but in a SoC with one memory shared by GPU and CPU, it's probably a normal memory allocation that the display controller uses DMA to read from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;em&gt;display controller&lt;/em&gt; is a piece of hardware that reads pixels from the frame buffer and displays them on the physical screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many display controllers support the use of an overlay, which is like a very simple window. Sometimes they're fixed-size, but sometimes they're &lt;em&gt;masked&lt;/em&gt; off. In this case, then there might be a secondary framebuffer that covers the whole screen. When the display controller reads a pixel of a particular colour from the primary framebuffer, then instead of displaying that pixel, it substitutes the corresponding pixel from the secondary framebuffer. It's like the &lt;em&gt;chroma key&lt;/em&gt; or green screen technique used in movie effects and weather forecasts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's one particular configuration: sometimes the secondary framebuffer is much smaller than the primary framebuffer, and a particular &lt;em&gt;register&lt;/em&gt; in the display controller controls the dimensions and offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The overlay technique is commonly used for displaying video streams. The frames of video might be coming from camera hardware or from video decoder hardware. Using an overlay means that this hardware and the GPU that's producing the rest of the screen (such as camera or playback GUI) aren't trying to access the same memory at once. The overlay might also be in a different pixel format to the primary framebuffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The overlay technique only lets you do this simple substitution, though (and maybe some scaling), not anything complicated. You can't make the frame of video spin around and shrink to an icon when you're transitioning between different applications. You can't alpha-blend the video with the primary framebuffer. Also, the number of overlays is limited by the hardware: usually one, but some controllers support two.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Composition&lt;/em&gt; in this context refers to something the window manager does. It takes the frames from each application on the screen (the system GUI is also an application), and produces the final frame. On a smartphone, this usually means just taking the current foreground app and the system GUI (notification bar and navigation bar) and drawing them next to each other. But when there are transitions between apps, or if you use the &quot;recent tasks&quot; button, the situation is more complicated. The compositor also has to handle choreographing applications so the screen gets updated at 60 Hz even if applications are drawing at different rates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Surface Flinger&lt;/em&gt; is Android's compositor. It uses OpenGL ES to do the things described in the previous paragraph. It's also in charge of creating a framebuffer for each application to render into. (These framebuffers show up as textures inside Surface Flinger, using &lt;code&gt;EGLImage&lt;/code&gt;.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Android also detects when there are simple cases that the display controller on the phone can handle as an overlay, so that it can switch to the faster, more energy-efficient path of using the overlay instead of using Surface Flinger's full GLES-based composition.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2017-06-23T08:16:48.473" LastActivityDate="2017-06-23T08:16:48.473" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5274" PostTypeId="1" AcceptedAnswerId="5295" CreationDate="2017-06-22T15:44:42.960" Score="2" ViewCount="1178" Body="&lt;p&gt;Let's assume we have a 3D model consisted of &lt;code&gt;XYZ&lt;/code&gt;-formatted vertices (such as point cloud model). My problem is given the position and normal of camera or camera projection (i.e. where I am looking at the points- usually given by my API), how can I extract the visible points and remove the non-visible points?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance here points corresponding to the black point cloud box and the back surface of the red box are removed. In point clouds, points have a size. So let's assume they have a size, say 5 pixel radius just for modeling purpose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. It doesn't have to be perfect. Just any approach to somehow remove the non-visible points so to decrease the total points with not much impact on the visible points will work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a test point cloud model to work with: &lt;a href=&quot;https://www.dropbox.com/s/dfhyy9xa5i9o2fz/testPLY.ply?dl=0&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.dropbox.com/s/dfhyy9xa5i9o2fz/testPLY.ply?dl=0&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eoovAm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eoovAm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4678" LastEditorUserId="4678" LastEditDate="2017-06-23T23:23:17.363" LastActivityDate="2017-07-04T14:42:26.767" Title="Extract visible vertices from a 3D geometry model" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="18" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5275" PostTypeId="2" ParentId="5270" CreationDate="2017-06-22T18:51:45.090" Score="7" Body="&lt;p&gt;There are, and I am looking forward to seeing the specifics of other answers, but one way to deal with this is to not have the noise (or as much noise) in the source data to begin with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The noise is coming from the fact that there is high variance in the rendering - the number of samples you've taken haven't converged enough to the actual right answer of the integral, and so some pixels are too high/bright and some are too low/dim (in each color channel).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is this: If you use white noise random numbers to do your sampling, you may get samples clumping together like the image below.  Given enough samples, it will converge, but it will take a while before it gives good coverage over the sampling space.  Find a region of empty space in the image below (like in the lower right) and imagine that there was a small, bright light there and that the scene was dark everywhere else.  You can see how not having any samples there is going to make a problem for rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4cQjK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4cQjK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternately, you could sample at even intervals like the below, but that will give you aliasing artifacts instead of noise, which is worse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rHjVE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rHjVE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One idea is to use low discrepancy sequences and do quasi monte carlo integration (&lt;a href=&quot;https://en.wikipedia.org/wiki/Quasi-Monte_Carlo_method&quot; rel=&quot;noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Quasi-Monte_Carlo_method&lt;/a&gt;).  Low discrepancy sequences are related to blue noise, which has only high frequency components.  Going these routes, you get faster convergence of $O(1/N)$ instead of $O(\sqrt{N})$.  These give better coverage of the sample space, but since there is some randomness (or random like qualities) to them, they don't have the aliasing issues that regularly spaced sampling does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a &quot;jittered grid&quot; where you sample on a grid, but use small random offsets within a cell size.  This was invented by pixar and was under patent for a while but is no longer:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kSYFd.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kSYFd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a common low discrepancy sequence called the Halton sequence (basically a 2d version of Van Der Corpus)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ayirs.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ayirs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is a poisson disc sampling, using Mitchel's best candidate algorithm:&lt;a href=&quot;https://i.stack.imgur.com/DgPeP.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DgPeP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More information, including the source code that generated these images can be found here: &lt;a href=&quot;https://blog.demofox.org/2017/05/29/when-random-numbers-are-too-random-low-discrepancy-sequences/&quot; rel=&quot;noreferrer&quot;&gt;https://blog.demofox.org/2017/05/29/when-random-numbers-are-too-random-low-discrepancy-sequences/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-06-22T18:57:31.190" LastActivityDate="2017-06-22T18:57:31.190" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5276" PostTypeId="1" CreationDate="2017-06-22T19:02:53.857" Score="1" ViewCount="58" Body="&lt;p&gt;How can I identify that an object is patterned (or symmetrical at least?). For example, I give to the algorithm a wall of red bricks. I want it to recognize that if it takes 1,2 or 4 bricks, it's possible to recreate the whole wall with translation. I didn't find anything in literature, I probably have not tried the right keywords. Any suggestion is welcome.&lt;/p&gt;&#xA;" OwnerUserId="6873" LastActivityDate="2017-06-22T19:02:53.857" Title="Pattern recognition on 3d geometry" Tags="&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5277" PostTypeId="1" AcceptedAnswerId="5278" CreationDate="2017-06-23T00:28:04.167" Score="2" ViewCount="802" Body="&lt;p&gt;New to opengl! I am having issues with passing colours from the program to vertex shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am creating a grid where I want to control the color of each cell.Thus I am generating each cell and having two vbo's, one for the vertices, and another for the colour. I want my grid to look like this: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LIN0W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LIN0W.png&quot; alt=&quot;Ideal&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I end up with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Pxew3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Pxew3.png&quot; alt=&quot;Reality&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have confirmed if I generate the colour data in the vertex shader and then pass it to the fragment, I get the first case. It is only when I grab the colour data from the program that I get the second case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Code for creating each vbo(written in go):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;var vbo [2]uint32&#xA;gl.GenBuffers(2, &amp;amp;vbo[0])&#xA;gl.BindBuffer(gl.ARRAY_BUFFER, vbo[0])&#xA;gl.BufferData(gl.ARRAY_BUFFER, 4*len(points), gl.Ptr(points), gl.STATIC_DRAW)&#xA;gl.BindBuffer(gl.ARRAY_BUFFER, vbo[1])&#xA;gl.BufferData(gl.ARRAY_BUFFER, 4*3, gl.Ptr([]float32{0.5,0.5,0.0}), gl.STATIC_DRAW)&#xA;var vao uint32&#xA;gl.GenVertexArrays(1, &amp;amp;vao)&#xA;gl.BindVertexArray(vao)&#xA;gl.EnableVertexAttribArray(0)&#xA;gl.BindBuffer(gl.ARRAY_BUFFER, vbo[0])&#xA;gl.VertexAttribPointer(0, 3, gl.FLOAT, false, 0, nil)&#xA;&#xA;gl.EnableVertexAttribArray(1)&#xA;gl.BindBuffer(gl.ARRAY_BUFFER, vbo[1])&#xA;gl.VertexAttribPointer(1, 3, gl.FLOAT, false, 0, nil)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vertex Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410&#xA;/*layout (location=0) */in vec3 vp;&#xA;/*layout (location=1)*/ in vec3 colour;&#xA;/*layout (location=2)*/  out vec3 outcolour;&#xA;void main(){&#xA;    gl_Position = vec4(vp,1.0);&#xA;    //outcolour = vec3(0.5,0.5,0.0);&#xA;    outcolour = vec3(colour);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment Shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410&#xA;in vec3 outcolour;&#xA;out vec4 frag_colour;&#xA;void main(){&#xA;    frag_colour = vec4(outcolour,1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6874" LastActivityDate="2017-06-23T01:37:30.183" Title="Passing Colour from program to vertex shader" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5278" PostTypeId="2" ParentId="5277" CreationDate="2017-06-23T01:37:30.183" Score="2" Body="&lt;p&gt;I don't know what language that is, but I'm going to hazard a guess that the arrays &lt;code&gt;points&lt;/code&gt; and &lt;code&gt;gl.Ptr([]float32{0.5,0.5,0.0})&lt;/code&gt; are &lt;em&gt;not&lt;/em&gt; the same size. If you intend to provide per-vertex colors, then you must provide one color for &lt;em&gt;every vertex&lt;/em&gt;. If you want to provide a single color that all vertices share, then that would be a &lt;code&gt;uniform&lt;/code&gt;, not a vertex shader &lt;code&gt;in&lt;/code&gt;put.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, commenting out your &lt;code&gt;layout&lt;/code&gt; declarations isn't helping. Though if you are going to declare a &lt;code&gt;location&lt;/code&gt; for the VS output variable, then the matching FS input needs to have the same &lt;code&gt;location&lt;/code&gt; declared.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-06-23T01:37:30.183" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5279" PostTypeId="2" ParentId="5270" CreationDate="2017-06-23T02:20:29.577" Score="4" Body="&lt;p&gt;One technique you could use is break the image into blocks and measure each blocks variance - this way you can apply more samples to blocks with higher variance. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The variance can be estimated by using 2 accumulation buffers instead of 1. You render each pass into an alternate buffer. The absolute difference between these buffers (with respect to each block) is proportional to variance. Upon presentation to screen you can add the two buffers together to get your full accumulation buffer back.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2017-06-23T02:47:17.973" LastActivityDate="2017-06-23T02:47:17.973" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5280" PostTypeId="1" CreationDate="2017-06-23T05:57:20.637" Score="3" ViewCount="401" Body="&lt;p&gt;I am trying to vectorize the contours (skewed rectangle) of the TV in the following original image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pndvM.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pndvM.jpg&quot; alt=&quot;oroginal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first step is applying threshold. Tried selection of threshold values based on what skimage has to offer, but non of them managed (for example) to separate correctly the little fawn to the left, or the TV stand from the TV border. For example this is the result using yen's method:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aEytA.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aEytA.jpg&quot; alt=&quot;bw&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you suggest any preprocessing that may help before applying a threshold ?  &lt;/p&gt;&#xA;" OwnerUserId="6875" LastActivityDate="2017-07-31T07:57:01.183" Title="Suggested image preprocessing before applying threshold" Tags="&lt;transformations&gt;&lt;color&gt;&lt;filtering&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5281" PostTypeId="2" ParentId="5280" CreationDate="2017-06-23T09:35:41.487" Score="0" Body="&lt;p&gt;I think the result you've already shown is about as good as you're going to get. What you need isn't preprocessing of the input image, but to give your edge detector a good idea of what contour it's looking for. If you write your contour extractor to look specifically for quadrilaterals, it'll easily be able to filter where the fawn sticks out at the bottom left, and the stand at the bottom. Then it's just a question of finding the one that corresponds to the TV (probably the largest, but it depends on what other images you're running it on).&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-06-23T09:35:41.487" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5282" PostTypeId="5" CreationDate="2017-06-23T10:35:14.413" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2017-06-23T10:35:14.413" LastActivityDate="2017-06-23T10:35:14.413" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5283" PostTypeId="4" CreationDate="2017-06-23T10:35:14.413" Score="0" Body="Compositing is the combining of visual elements from separate sources into single images, often to create the illusion that all those elements are parts of the same scene." OwnerUserId="6749" LastEditorUserId="6749" LastEditDate="2017-06-24T19:02:47.330" LastActivityDate="2017-06-24T19:02:47.330" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5284" PostTypeId="1" CreationDate="2017-06-23T14:31:48.053" Score="2" ViewCount="227" Body="&lt;p&gt;The OpenGL Programming Guide states the formula for diffuse hemisphere lighting on a surface with normal vector $\vec{n}$ as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_o(\vec{n}) = L_i(\uparrow) (1-\frac{1}{2}\sin(\theta)) + L_i(\downarrow) \frac{1}{2}\sin(\theta)$ if $0 &amp;lt;= \theta &amp;lt; \frac{1}{2}\pi$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_o(\vec{n}) = L_i(\uparrow) \frac{1}{2}\sin(\theta) + L_i(\downarrow) (1 - \frac{1}{2}\sin(\theta))$ if $\frac{1}{2}\pi &amp;lt;= \theta &amp;lt;= \pi$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;with $\theta$ as the polar angle of $\vec{n}$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\theta = \cos^{-1}(n_z)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found various other sources (e.g. &lt;a href=&quot;http://www2.lawrence.edu/fast/GREGGJ/CMSC420/chapter21/Irradiance.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this text&lt;/a&gt;) for this formula, however I was unable to find the derivation of this formula.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;On the other hand, I found this &lt;a href=&quot;https://en.wikibooks.org/wiki/GLSL_Programming/Unity/Diffuse_Reflection_of_Skylight#Hemisphere_Lighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikibook article&lt;/a&gt;, suggesting:&#xA;$L_o(\vec{n}) = L_{i}(\uparrow) (\frac{1}{2} + \frac{1}{2} \cos(\theta)) + L_{i}(\downarrow) (\frac{1}{2} - \frac{1}{2} \cos(\theta))$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is explicitly described as an approximation/cheating in the OpenGL Programming Guide. The derivation of this formula is done without a clear source of error.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Trying to reproduce either formula, I solved&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_o(\vec{n}) = \frac{1}{\pi}\int_{H} L_i(\vec{w}) \langle{}\vec{w}, \vec{n}\rangle{} \mathrm{d}\vec{w}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;both analytically and numerically, and both times I ended up with the latter formula.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While it may not matter much in practice, I am apparently making some mistake here. So my question is: &lt;strong&gt;How can I derive the former formula from this integral and why is the latter formula only an approximation?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="6876" LastEditorUserId="6876" LastEditDate="2017-06-23T17:43:46.240" LastActivityDate="2017-06-23T17:43:46.240" Title="Exact Formula for Diffuse Hemisphere Lighting" Tags="&lt;lighting&gt;&lt;diffuse&gt;&lt;hemisphere&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5285" PostTypeId="1" AcceptedAnswerId="5289" CreationDate="2017-06-24T13:24:24.573" Score="3" ViewCount="266" Body="&lt;p&gt;Existence question: Can there exist a &lt;strong&gt;convex&lt;/strong&gt; polygon witch is not a &lt;strong&gt;simple&lt;/strong&gt; polygon?&lt;/p&gt;&#xA;" OwnerUserId="6882" LastEditorUserId="38" LastEditDate="2017-06-25T08:57:09.550" LastActivityDate="2017-06-25T09:16:35.453" Title="Convex non simple polygon?" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5286" PostTypeId="1" AcceptedAnswerId="5288" CreationDate="2017-06-24T20:20:53.910" Score="6" ViewCount="443" Body="&lt;p&gt;Many books describe that a BRDF has the following property (reciprocity):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_r(x, \Theta \to \Psi ) =  f_r(x, \Psi \to \Theta)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is the above equation correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the above equation should be changed as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(because the two symbols $\Theta$ and $\Psi$ are &lt;strong&gt;direction vectors&lt;/strong&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_r(x, \Theta\to \Psi ) =  f_r(x,  -\Psi \to -\Theta)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is my mistake?&lt;br&gt;&#xA;(I am very confused about the concept.)&lt;/p&gt;&#xA;" OwnerUserId="6806" LastEditorUserId="231" LastEditDate="2017-06-24T21:39:25.960" LastActivityDate="2017-06-24T21:39:25.960" Title="The reciprocity of BRDF" Tags="&lt;physically-based&gt;&lt;pbr&gt;&lt;photo-realistic&gt;&lt;realistic&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5287" PostTypeId="1" CreationDate="2017-06-24T21:08:57.180" Score="3" ViewCount="255" Body="&lt;p&gt;I have little knowledge of this topic but from what I gather in a Ray Tracer each ray is given its own wavelength as opposed to an RGB value. This automatically simulates Dispersion and Fluorescence. Is this called Spectral Rendering?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the approaches usually taken to render Iridescence? Could someone give a brief overview of the method and a reference to a resource I can use to learn more in-depth knowledge I can use for implementation? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="231" LastEditDate="2017-06-24T21:14:10.720" LastActivityDate="2018-08-20T06:43:40.957" Title="How is Iridescence handled in a Path Tracer?" Tags="&lt;pathtracing&gt;&lt;physically-based&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5288" PostTypeId="2" ParentId="5286" CreationDate="2017-06-24T21:35:58.823" Score="6" Body="&lt;p&gt;You probably know that the BRDF is to calculate the reflected light, from a light source to a camera (In examples a light source and a camera is used, but it does not need to be just that). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The property that you are talking about, basically says that when you swap the light source with the camera, it still gives the same result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lets look at an example I quickly made.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/zTOsg.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zTOsg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ok, so here you see the basic setup. You have a light source, a camera and a point on a surface. Wi is the direction towards the light, the incoming direction. Wo is the direction towards the camera, the outgoing direction. N is the normal of the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The property says that if we switch Wi and Wo with each other the result is the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The example would then look like this.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/TjC5p.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TjC5p.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This looks normal and logical. You said that you should invert the direction vectors. If we do that, this is then our result.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/VxHWn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VxHWn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;You can see that it now looks like the surface is illuminated from the other side, and since the normal is not inverted, it will end up looking black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So that is where you made your mistakes. The property says that you can swap the incoming and outgoing vectors and the result will still be the same. This is called the Helmholtz reciprocity. And where you might got confused was this part &quot;how a ray of light and its reverse ray encounter matched optical adventures&quot; (from the wikipedia). But it is not talking about the inverse (multipled by -1) but about the outgoing ray of the event in something like a reflection or refraction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I recommend reading up on the Helmholtz reciprocity. For example on the wikipedia: &lt;a href=&quot;https://en.wikipedia.org/wiki/Helmholtz_reciprocity&quot; rel=&quot;noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Helmholtz_reciprocity&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope I explained this properly, and if I made any mistakes, I am happy to learn and fix this answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Good luck with your adventures through the computer graphics universe!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2017-06-24T21:35:58.823" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5289" PostTypeId="2" ParentId="5285" CreationDate="2017-06-25T09:16:35.453" Score="5" Body="&lt;p&gt;For a polygon to be convex the outside angle of the polygon has to be more than or equal to 180 degrees. Now at intersection of 2 lines the outermost angle has to be less than 180 degrees for the lines to intersect between the endpoints.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the answer to this question depends on how you define what is inside of the polygon. If you consider some a even odd filling rule then the answer is &lt;strong&gt;No&lt;/strong&gt; such shape exists. But if you consider only the outermost curve to do filling then yes, its possible if you intersect at the endpoint of a line. But to me this sounds more like splitting hairs as that shape reduces to a simple polygon.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-06-25T09:16:35.453" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5290" PostTypeId="2" ParentId="5267" CreationDate="2017-06-25T10:53:36.243" Score="5" Body="&lt;p&gt;I'm not sure I've correctly understood the question, but here goes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You're trying to sample directions uniformly, so you've got $p(\omega)$, which is the probability of getting a particular direction. But what is a direction? You actually need your probability distribution to produce numbers in some representation, and the easiest representation to deal with is lat-long (i.e. two angles). So the thing you actually need to sample from is the probability distribution of pairs of angles. This is what $p(\theta, \phi)$ is: the joint probability of two variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p(\omega)$ and $p(\theta, \phi)$ mean the same thing geometrically, but the former gives you an abstract &lt;em&gt;direction&lt;/em&gt; you can't sample from directly, while the latter more usefully gives you two numbers that &lt;em&gt;represent&lt;/em&gt; a direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason for your third bullet point is to do with the point you've made about how it isn't just a single direction. These aren't really functions: they're &lt;em&gt;distributions&lt;/em&gt;. A direction is infinitesimal, so you can't have a probability of just one direction. What you actually need to do is integrate it over the directions you're interested in.&#xA;$$&#xA;\int p(\omega)d\omega = \int_0^{2\pi}\int_0^\pi p(\theta, \phi)d\theta d\phi = 1&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whichever representation you use, the integral over the hemisphere has to be 1, because it's a probability distribution.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if I need to explain this or if you already understood, but here's the origin of the $sin(\theta)$. When you do the double-integral on the right, you're splitting the problem up into a series of rings, or slices of the unit sphere. Each ring has constant $\theta$ while $\phi$ goes from $0$ to $2\pi$. Also, the area of each individual ring decreases as $\theta$ increases: the ring at the equator is huge, while the last &quot;ring&quot; at the pole is tiny. The area decreases as $sin(\theta)$. Because we want each unit of area of the sphere to have the same probability, we need the smaller rings to get a smaller share of the probability.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Florian R. explains, you can do that by including the $sin(\theta)$ factor in the integral, or you can put it inside the definition of $p(\theta, \phi)$ like the book does.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2017-06-30T12:20:17.527" LastActivityDate="2017-06-30T12:20:17.527" CommentCount="14" ContentLicense="CC BY-SA 3.0" />
  <row Id="5291" PostTypeId="1" AcceptedAnswerId="10865" CreationDate="2017-06-25T16:31:35.673" Score="6" ViewCount="195" Body="&lt;p&gt;I've recently been using &lt;strong&gt;CrazyBump&lt;/strong&gt;, and I think I'm starting to understand how it works. But I'm confused about what it calls &lt;strong&gt;Shape Recognition&lt;/strong&gt;. According to &lt;a href=&quot;https://iamsparky.wordpress.com/crazybump/&quot; rel=&quot;noreferrer&quot;&gt;this&lt;/a&gt; website, that feature attempts to add directional lighting information, but what exactly does that mean?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pyg06.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pyg06.png&quot; alt=&quot;Test Texture&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Here's my test texture. It's simple, just so I can understand what's going on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MwYMx.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MwYMx.png&quot; alt=&quot;Shape Recognition Off&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Here's the generated normal map, before Shape Recognition.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YPgMf.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YPgMf.png&quot; alt=&quot;Shape  Recognition On&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Here's the generated normal map, after Shape Recognition.&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2021-05-03T18:04:30.033" Title="CrazyBump Shape Recognition" Tags="&lt;texture&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5293" PostTypeId="1" CreationDate="2017-06-25T16:54:18.873" Score="9" ViewCount="2458" Body="&lt;p&gt;I'm using OpenGL to learn computer graphics.  I'm trying to understand projection matrices.  The following are shown in the OpenGL 'Red Book':&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Qi0UI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Qi0UI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FBZZ5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FBZZ5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand why the width and height are divided by 2?&lt;/p&gt;&#xA;" OwnerUserId="6025" LastEditorUserId="2041" LastEditDate="2017-06-25T17:11:19.750" LastActivityDate="2017-06-26T19:20:52.603" Title="Why are width and height divided by 2 in the perspective projection matrix?" Tags="&lt;projections&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5294" PostTypeId="2" ParentId="5293" CreationDate="2017-06-25T17:35:05.283" Score="11" Body="&lt;p&gt;Because $x_{proj}$ doesn't vary from $0 \to width$, it varies from $-\tfrac{width}{2} \to \tfrac{width}{2}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's important is not the width, but the minimum and maximum values of $x_{proj}$. Because $(0, 0)$ is in the centre of the viewport, not the corner, the min and max values are plus and minus half of the width.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;BTW, the Red Book is not a great introduction to graphics in general. It's a technical standard, not a tutorial, so the explanation of concepts is just enough to be unambiguous - it's not trying to &lt;em&gt;teach&lt;/em&gt; the material. It's also about a scanline rendering library in particular, so there's a lot of important concepts it doesn't describe at all, such as what BRDFs are important, how they relate to real-world surface properties, what an image really is, and many higher-level techniques.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally, even in the area it's about - how to use a GPU to accelerate rendering - it's hideously out of date. The GL architecture is based on GPUs from 20 years ago. Although lots of features have been added to keep up with changes to hardware, the fundamental abstractions are not a good way to understand current GPU architectures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to learn about the theory of computer graphics, start with a proper textbook such as Physically Based Rendering or Computer Graphics: Principles and Practice, or an online course. If you want to learn how to make a 3D application, start with a tutorial about the kind of application you're interested in (e.g. if it's a game, try a Unity tutorial).&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2017-06-26T19:20:52.603" LastActivityDate="2017-06-26T19:20:52.603" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5295" PostTypeId="2" ParentId="5274" CreationDate="2017-06-27T02:46:40.427" Score="4" Body="&lt;h3&gt;Idea A:&lt;/h3&gt;&#xA;&lt;p&gt;Draw an invisible mesh that will occlude the points we don't want.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create a mesh from the point cloud.&lt;/li&gt;&#xA;&lt;li&gt;Render that mesh to a depth buffer but not to the color buffer.&lt;/li&gt;&#xA;&lt;li&gt;Render the point cloud using a depth test &amp;quot;closer or equal&amp;quot;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This approach should give the expected result, but the problem with it is the first part, which is not trivial at all.&lt;/p&gt;&#xA;&lt;h3&gt;Idea B:&lt;/h3&gt;&#xA;&lt;p&gt;Approximate the mesh with fat particles, that are big enough to hide points in the background.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Pick a size that is roughly the typical distance between two points.&lt;/li&gt;&#xA;&lt;li&gt;Use that size as a particle diameter.&lt;/li&gt;&#xA;&lt;li&gt;Render the point clouds using such large particles, to a depth buffer but not to the color buffer. Maybe offset that point cloud a little, so it's a bit farther from the camera.&lt;/li&gt;&#xA;&lt;li&gt;Render the point cloud using points this time, and using a depth test &amp;quot;closer or equal&amp;quot;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This method should be a lot simpler to implement than A, because there is no need to triangulate anymore. The result will not be perfect though: some points that should be visible might disappear, and some that shouldn't be visible will remain visible. Tweaking the particle diameter and offset will yield different results.&lt;/p&gt;&#xA;&lt;h3&gt;Idea C:&lt;/h3&gt;&#xA;&lt;p&gt;As a very cheap trick, just render the point cloud with a fog function. The farther points are from the camera, the less visible they are. This method won't hide any point, but still help reading the volume.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-06-27T02:46:40.427" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5296" PostTypeId="1" CreationDate="2017-06-27T12:22:45.397" Score="3" ViewCount="79" Body="&lt;p&gt;I have a simple test scene setup in a toy software rasterizer.  I have a plane facing the +Z axis at the origin and the camera is facing -Z at Z=2.  Everything works fine and looks good at that orientation but if I turn the camera to face -X it  renders a distorted triangle long after the plane has left the view of the camera.  I have been trying to debug this for weeks and can't find the problem.  I assume I am missing somthing silly, maths are not my strong suit.  I have check my matrix/vector math and it seems good to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the realevent code: NOTE it's emited from the &quot;ReadableC backend&quot; of a toy language so the formating is a little strange.  Also I am fully aware there are important parts of software rasterization that are missing i the implementation.  It has been simplified to isolate the bug.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/Twiebs/3278d2e58d0a51b2d86a101172b2904e&quot; rel=&quot;nofollow noreferrer&quot;&gt;Relevant Source Code&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6900" LastActivityDate="2017-06-27T12:22:45.397" Title="Strange behaviour in simple software rasterizer" Tags="&lt;rendering&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5297" PostTypeId="1" CreationDate="2017-06-27T13:25:50.940" Score="0" ViewCount="1518" Body="&lt;p&gt;I have a question regarding 3D PDF files. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a 3D vector graphics image which is saved as a Product Representation Compact (PRC) file. The PRC file is embedded in a PDF file. I can view and rotate the 3D image in Adobe Acrobat Reader, and it looks beautiful. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I need to save this image in a 2D file format. In other words, I need to export the view of the 3D image as it appears in Acrobat Reader (from a given point of view) to a 2D file format. The file format could be either bitmap or vector graphics, it is not too important. For instance, I would like to save the image in a PNG- or SVG-file. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have to do this because I need the image to be displayed in a graphical user interface (GUI) of a software I am working on. I work in a software company, an the GUI programmers would like me to hand over the image in a 2D file format like PNG or SVG.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried several approaches to export the view from Acrobat Reader to a 2D file format, but I haven't found a satisfactory solution. I have tried to export the 3D PDF-file to JPEG and PNG using Adobe Acrobat Pro DC. However, the pictures obtained with this method were extremely blurred. I have also tried to print the 3D graphics using the Adobe PDF printer, but this also yields poor results.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only work around I have come up with so far is to make a screen shot when the graphics is shown in Acrobat Reader. This actually works, and I can get a PNG-file, but only at a relatively low solution. In any case, this is hardly a satisfactory solution.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: Is there some way that I can obtain a high quality 2D file format from the 3D PDF (PRC-file) format?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any input would be highly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="6902" LastActivityDate="2017-06-27T13:25:50.940" Title="Convert prc-file (3D PDF) to 2D file format" Tags="&lt;3d&gt;&lt;conversion&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5299" PostTypeId="1" CreationDate="2017-06-28T11:19:37.747" Score="1" ViewCount="48" Body="&lt;p&gt;This might sound confusing, but this is what I'm trying to achieve:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/KOqaS.png&quot; alt=&quot;Cartesian bounds of isometric object&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;project to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/CdpU1.png&quot; alt=&quot;Isometric bounds of isometric object&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already have an algorithm in my mind, where we simply detect the corners touching the Cartesian rectangle and calculate the bounds from there, but I just wanted to see if there were more clever ways of solving this problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;It's not a homework&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I don't want a full answer, just a pointer, wondering if there are more clever ways of solving it.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The isometric object can be a rectangle, it's width and height might differ.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6908" LastEditorUserId="6908" LastEditDate="2017-06-28T15:14:37.527" LastActivityDate="2017-06-28T15:14:37.527" Title="Rectangle bounds of isometric object to isometric bounds" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;2d&gt;&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5300" PostTypeId="1" CreationDate="2017-06-28T12:32:45.580" Score="6" ViewCount="740" Body="&lt;p&gt;To change particular colors in an image, generally you multiply the RGB by a transformation matrix. Image manipulation programs such as gimp &amp;amp; photoshop have a selective color change function that allows a user to convert pixels within a certain &quot;distance&quot; to the original color in some color space to a new color. Eg, changing &lt;code&gt;#00f&lt;/code&gt; blue into &lt;code&gt;#ffd&lt;/code&gt; pale yellow. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to implement such a function in a &lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;. What color space and distance definition do these algorithms typically use, and then how do they compute the transformation matrix?&lt;/p&gt;&#xA;" OwnerUserId="2040" LastEditorUserId="2040" LastEditDate="2017-06-29T11:21:19.377" LastActivityDate="2017-11-12T23:36:14.577" Title="Color transform algorithm (that also works on saturation and value/lightness)?" Tags="&lt;transformations&gt;&lt;algorithm&gt;&lt;color&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5301" PostTypeId="1" CreationDate="2017-06-28T19:50:22.727" Score="5" ViewCount="462" Body="&lt;p&gt;I'm using OpenGL's stencil test to carve out a semicircular hole in a transition frustum with a cylinder oriented perpendicularly. However as one can see below, while this objective is achieved, the cylinder is still visible through the frustum which shouldn't be the case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pmWBD.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pmWBD.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;p&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using the following code fragment that I found at&#xA;&lt;a href=&quot;https://en.wikibooks.org/wiki/OpenGL_Programming/Mini-Portal&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikibooks.org/wiki/OpenGL_Programming/Mini-Portal&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glClear(GL_DEPTH_BUFFER_BIT);&#xA;glEnable(GL_STENCIL_TEST);&#xA;glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);&#xA;glDepthMask(GL_FALSE);&#xA;glStencilFunc(GL_NEVER, 1, 0xFF);&#xA;glStencilOp(GL_REPLACE, GL_KEEP, GL_KEEP);  // draw 1s on test fail (always)&#xA;&#xA;// draw stencil pattern&#xA;glStencilMask(0xFF);&#xA;glClear(GL_STENCIL_BUFFER_BIT);  // needs mask=0xFF&#xA;DRAW_CYLINDER ();&#xA;&#xA;glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);&#xA;glDepthMask(GL_TRUE);&#xA;glStencilMask(0x00);&#xA;// draw where stencil's value is 0&#xA;glStencilFunc(GL_EQUAL, 0, 0xFF);&#xA;/* (nothing to draw) */&#xA;// draw only where stencil's value is 1&#xA;glStencilFunc(GL_EQUAL, 1, 0xFF);&#xA;&#xA;DRAW_FRUSTUM();&#xA;&#xA;glDisable(GL_STENCIL_TEST);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Moreover I've found that the results are insensitive to the parameters of the &lt;strong&gt;glStencilOp&lt;/strong&gt;  and &lt;strong&gt;DepthMask&lt;/strong&gt; commands. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I seem to vaguely remember from several years ag that a multi-pass rendering may be required. If so, could someone point me to how to accomplish this with the proper set of command parameters?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;thanks in advance.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This is an example of what I'm expecting - The cylinder should cut a hole through the frustum. I've rendered it here by trimming the black cylinder within the frustum so that it just just out past the frustum surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vcxON.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vcxON.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6785" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:38:57.383" LastActivityDate="2018-03-04T00:38:57.383" Title="Honouring Depth Test with Stencil Test" Tags="&lt;opengl&gt;&lt;stencil-test&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5302" PostTypeId="1" AcceptedAnswerId="5312" CreationDate="2017-06-29T03:28:58.073" Score="5" ViewCount="684" Body="&lt;p&gt;I'm creating an SVG editor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a simple selection tool that appears when I click and move my mouse from a blank area in my SVG.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My SVG is populated with rectangles that can have a rotation applied to.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I have the X and Y position applied to a translate function.&lt;/li&gt;&#xA;&lt;li&gt;Width and height are easy to calculate based on a scale factor and original dimensions of my rectangle(s).&lt;/li&gt;&#xA;&lt;li&gt;My rotation angle is applied in a rotate function&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I know about the &lt;a href=&quot;https://en.wikipedia.org/wiki/Point_in_polygon&quot; rel=&quot;nofollow noreferrer&quot;&gt;point in polygon&lt;/a&gt; algorithm but I don't know how to calculate the points of my (rotated) rectangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is how can I verify if my selection area is over one or more of these rectangles and if the PIP algorithm is the best, how can I calculate the points of my rectangle(s)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the kind of render I'm trying to have:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/jtAGY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jtAGY.png&quot; alt=&quot;selection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6844" LastEditorUserId="231" LastEditDate="2017-07-02T07:56:46.723" LastActivityDate="2017-07-02T12:16:40.190" Title="How can I verify if a selection area is over a shape in SVG?" Tags="&lt;algorithm&gt;&lt;vector-graphics&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5303" PostTypeId="1" CreationDate="2017-06-29T11:37:48.937" Score="5" ViewCount="239" Body="&lt;p&gt;I'm currently trying to implement a fast algorithm for KD-Tree construction using &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_interval_hierarchy&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Surface Area Heuristic&quot;&gt;SAH&lt;/a&gt;, as described in this paper: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://dcgi.felk.cvut.cz/publications/2006/wald-rt-fkd&quot; rel=&quot;nofollow noreferrer&quot;&gt;On building fast KD-trees for ray tracing, and on doing that in O(N log N)&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found one already working implementation by Miguel Granados and Richard Socher from the University of Saarland (even though this code does not implement the final O(N log N) algorithm, but a slightly slower O(N log^2 N), which is also described in the paper). The implementation can be found &lt;a href=&quot;http://www.socher.org/uploads/Main/RenderingCompetitionSocherGranados/src/SAHKdtree.h&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I'm not entirely certain their implementation is correct. What makes me particularly unsure is this part:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// get primitives's clipped bounding box&#xA;Box clipTriangleToBox(Primitive* t, const Box&amp;amp; V) const {&#xA;    Box b = t-&amp;gt;CalcBounds(); // calculates the triangle's AABB&#xA;    for(int k=0; k&amp;lt;3; k++) {&#xA;        if(V.min[k] &amp;gt; b.min[k])&#xA;            b.min[k] = V.min[k];&#xA;        if(V.max[k] &amp;lt; b.max[k])&#xA;            b.max[k] = V.max[k];&#xA;    }&#xA;    assert(V.contains(b));&#xA;    return b;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code should return a conservative Axis-Aligned Bounding Box of the given triangle, which is clipped by the given box/voxel, but I'm certain this code will not compute these AABBs correctly, since this case, which is correctly evaluated:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OB1iB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OB1iB.png&quot; alt=&quot;correctly clipped AABB&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;( Source of the image &lt;a href=&quot;https://stackoverflow.com/questions/34653134/conservative-aabb-for-voxel-triangle-intersection&quot;&gt;here&lt;/a&gt; )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;will be incorrectly evaluated as this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LdCcn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LdCcn.png&quot; alt=&quot;wrong case&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output seems to be only a conjunction of AABBs, rather than a real conservative AABB. This, of course, makes the algorithm either crash at deeper levels of KD-Tree construction (with small voxels compared to sizes of the scene triangles) or, in most cases, halt prematurely. I've been trying to find an algorithm that evaluates these cases correctly, but I do not seem to be successful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are my assumptions correct? And if yes, would anyone happen to know of an algorithm which would correctly evaluate the conservative AABB, given the triangle and the voxel?&lt;/p&gt;&#xA;" OwnerUserId="2138" LastEditorUserId="231" LastEditDate="2017-06-30T13:09:12.537" LastActivityDate="2017-06-30T13:09:12.537" Title="Computation of conservative AABB for clipped triangle" Tags="&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5304" PostTypeId="1" AcceptedAnswerId="5308" CreationDate="2017-06-29T13:28:24.047" Score="6" ViewCount="127" Body="&lt;p&gt;Let $I$ = the value of integration and $p$ = probability distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The estimator is denoted as $\left\langle I \right &amp;gt;$ and is&#xA;$$\left\langle I \right &amp;gt;=\frac{1}{N}\sum_{i=1}^{N}\frac{f(x_i)}{p(x_i)}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The expected value of this estimator is computed as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$E[\left\langle I \right &amp;gt;] = E[\frac{1}{N}\sum_{i=1}^{N}\frac{f(x_i)}{p(x_i)}]$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\qquad \qquad  \space \space \space \space = \frac{1}{N}E[\sum_{i=1}^{N}\frac{f(x_i)}{p(x_i)}]\cdots(1)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \qquad \qquad\qquad\quad= \frac{1}{N}N\int\frac{f(x)}{p(x)}p(x)dx\cdots(2)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ = \int f(x)dx \space \space$$&#xA;$$ = I\qquad\qquad \space$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wonder why the two equation, $(1)$ and $(2)$, are equal??&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2017-06-29T23:35:56.760" Title="Monte Carlo Integration" Tags="&lt;mathematics&gt;&lt;physically-based&gt;&lt;pbr&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5305" PostTypeId="2" ParentId="350" CreationDate="2017-06-29T13:48:38.200" Score="4" Body="&lt;p&gt;The Diffuse, specular and Reflection terms have lead to a lot of confusion because they have been commonly used to describe different lighting processes along the CG history and sometimes diverge from their scientific usage. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;to clarify this I is use my own vocabulary made up of different terms i picked up here and there:&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1- Surface Reflectance&lt;/strong&gt;: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;could correspond to specular map in the old system&lt;/li&gt;&#xA;&lt;li&gt;Correspond to the fresnel reflection part of the BRDF model for the dielectric materials and to the global reflection for the metallic ones.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The Surface-Relfectance process description&lt;/strong&gt;: the light is &quot;bouncing&quot; off the surface without any transmission inside the material or micro subsurface scattering involved in the process (no refraction, no absorbtion).&#xA;&lt;strong&gt;Light color information remain inchanged during surface reflection process except for some precise cases (colored metallic reflection, shimmering)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1.1 - Rough surface reflectance&lt;/strong&gt;: is light &quot;bouncing&quot; off a rough material (micro facets) in a more or less evenly distributed direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1.2 - smooth surface reflectance&lt;/strong&gt;: is light &quot;bouncing&quot; off a glossy or smooth material in an more or less oriented direction.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2 - Body reflectance&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;correspond to the diffuse in the old system&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;correspond to the basecolor or albedo map in the new system.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The Body-Reflectance process description&lt;/strong&gt;: The light hitting the surface that is &lt;em&gt;not&lt;/em&gt; surface-reflected is first being transmitted in the interior of the object and then may be absorbed, further scattered and reflected, and in some cases exit the material again. It involve micro sub-subsurface scattering from internal irregularities.&#xA;&lt;strong&gt;Light color information is changed during the absorbtion steps of the body relfectance process.&lt;/strong&gt; And if the light manage to get out of the material again, it will transmit its color information.&#xA;The body reflectance process is not applyable to metallic material as they only totally absorb or surface-reflect light depending on its wave lenghts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Body-reflectance will not be influenced by material surface smoothness as there is scattering involved inside the material no matter the surface, except maybe for transparent materials where there is mostly absorbtion process involved (no light deviation) and very few scattering. Then when going out again, the surface roughness could really influence if these light rays are going out parallels or scattered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Micro subsurface scattering is different than global subsurface scattering as,  for a matter of simplification through approximation, the light is considered as going out of the material at the same exact point it went in. This is a just what makes that regular dielectric objects have color; there must be transmission, then absorbtion and micro scattering, then re-transmission outside of the material in order to get dielectric's color&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Ok now, what i've understand from this naming confusion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1 - concerning the diffuse reflection&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What we call usually call &lt;strong&gt;diffuse reflection&lt;/strong&gt; is the mechanism that include &lt;strong&gt;rough surface-reflectance&lt;/strong&gt; and &lt;strong&gt;body-reflectance&lt;/strong&gt; for a rough dielectric surface.&#xA;But in some case the term &lt;strong&gt;diffuse reflection&lt;/strong&gt; can be used to describe only the &lt;strong&gt;surface reflectance&lt;/strong&gt; part when opposed to the transmission process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Concerning Metallic materials, diffuse reflection concern, as a matter of fact, only rough surface reflectance. In case of smooth metallic material, the term diffuse reflection is replaced by specular reflection or direct reflection (which add to the confusion as specular is used here to mean &quot;sharp&quot;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When talking about smooth dielectric material, there are still diffusing processes, in the sense that the light transmitted into the material is still scattered when goign out of it (body-reflectance), but the surface-reflectance part of it could be called specular or direct reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2 - Concerning the albedo&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the physicist field, &lt;strong&gt;Albedo&lt;/strong&gt; seems to be the &lt;strong&gt;ratio between reflected light intensity (surface-reflectance + body-reflectance) and incident light&lt;/strong&gt;. So it is a &lt;strong&gt;one dimentionnal&lt;/strong&gt; value.&#xA;In CG, in the other hand, we view &lt;strong&gt;albedo&lt;/strong&gt; as a &lt;strong&gt;three dimentional value&lt;/strong&gt; in RGB which correspond to the traditionnal &quot;diffuse&quot; of the old system and to the &quot;baseColor&quot; of the metall/roughness workflow. In this case albedo would be, for a metal/roughness workflow the body reflectance for dielectrics and and the Surface-reflectance for metals  &lt;strong&gt;but without the fresnel composant of the fresnel surface reflectance&lt;/strong&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in the physicist way of the term, albedo also cover the surface-reflectance part of the light re-emmission (fresnel reflection).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the metall/roughness workflow though, BaseColor doesn't have any incidence onto the fresnel reflection wich is directly embedded into the shaders. So BaseColor is basically the body-reflectance RGB value for the Dielectric material and the surface relfectance RGB value being surface-reflected by the metallic material (being &quot;Surface-reflected&quot;, but in a colored way because of the conductive property of the metals and their cristalline organisation combined).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is all really confusing indeed... and i'm not even sure that i entirely get it&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of the doc I'm refering to along with substance PBR guidelines:&#xA;&lt;a href=&quot;http://creativecoding.evl.uic.edu/courses/cs488/reportsA/brdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://creativecoding.evl.uic.edu/courses/cs488/reportsA/brdf.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6915" LastEditorUserId="6915" LastEditDate="2017-06-29T14:51:23.273" LastActivityDate="2017-06-29T14:51:23.273" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5307" PostTypeId="1" AcceptedAnswerId="5316" CreationDate="2017-06-29T23:19:42.447" Score="6" ViewCount="1073" Body="&lt;p&gt;How can a diffused(frosted) glass be modelled in path tracing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I am able to define a window poly line as a clear glass material where it transmits or reflects the ray. I am not clear though how it should work if the sheet of glass is frosted(diffuse transmission?).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/gr3jB.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="209" LastEditDate="2017-07-05T08:03:07.047" LastActivityDate="2017-07-05T08:03:07.047" Title="How can a diffused(frosted) glass be modelled in path tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;material&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5308" PostTypeId="2" ParentId="5304" CreationDate="2017-06-29T23:35:56.760" Score="3" Body="&lt;p&gt;In Monte Carlo integration, the samples $x_1, x_2, \ldots x_N$ are &lt;a href=&quot;https://en.wikipedia.org/wiki/Independent_and_identically_distributed_random_variables&quot; rel=&quot;nofollow noreferrer&quot;&gt;independent, identically-distributed&lt;/a&gt; random variables. This implies they all have the same expectation value. The derived quantities $f(x_i)/p(x_i)$ also all have the same expectation value. So the expectation of a sum of $N$ of these is the same as $N$ times the expectation of any one of them:&#xA;$$E\left[ \sum_{i=1}^N \frac{f(x_i)}{p(x_i)} \right] = N \cdot E\left[\frac{f(x_1)}{p(x_1)}\right]$$&#xA;(I picked $x_1$ arbitrarily.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, the expectation value of a continuous random variable is found by integrating over its probability measure:&#xA;$$E\left[\frac{f(x_1)}{p(x_1)}\right] = \int_{\text{domain of }p(x)} \frac{f(x)}{p(x)} \, p(x) \, dx$$&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-06-29T23:35:56.760" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5309" PostTypeId="1" CreationDate="2017-06-30T08:55:13.373" Score="2" ViewCount="68" Body="&lt;p&gt;In a fragment shader, I need to draw a line at a given value of &lt;em&gt;u&lt;/em&gt;. The shader is applied to a planar polygon mesh that's being drawn in the scene with a perspective camera. (It isn't a full-screen textured quad; that would be easy!)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is, the thickness of the line is given in screen pixels, not in world units. How can I draw this line in my shader?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shader is Cg, but a pseudocode answer outlining the technique is fine.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-06-30T08:55:13.373" Title="How can I draw a line whose position is given in UV space and its width in screen space?" Tags="&lt;fragment-shader&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5310" PostTypeId="1" CreationDate="2017-06-30T11:51:03.603" Score="4" ViewCount="1102" Body="&lt;p&gt;I'm writing a raytracer and I'm using the assimp library to load objects. I have an object's material specified in a .mtl file:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;newmtl rightSphere&#xA;Ka 0.01 0.01 0.01&#xA;Kd 0.01 0.01 0.01&#xA;Ks 0.30 0.30 0.30&#xA;Tf 0.10 0.10 0.10&#xA;Ns 200&#xA;Ni 2.5&#xA;illum 7&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and I'm trying to load this material. I've been mostly successful so far, for example I know that to extract the diffuse component (Kd), I can use&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;aiMesh *mesh = scene-&amp;gt;mMeshes[i];&#xA;aiMaterial *mat = scene-&amp;gt;mMaterials[mesh-&amp;gt;mMaterialIndex];&#xA;aiColor3D color;&#xA;mat-&amp;gt;Get(AI_MATKEY_COLOR_DIFFUSE, color);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;using the identifiers specified in &lt;a href=&quot;http://assimp.sourceforge.net/lib_html/materials.html&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;. However, I've been unable to extract the Tf component. I understand that this component defines the coefficient of refracted light per color channel, and I need this value along with the index of refraction (Ni) to get it to work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: how can I get the Tf value?&lt;/p&gt;&#xA;" OwnerUserId="2138" LastActivityDate="2017-07-02T06:49:13.320" Title="Loading a material via assimp" Tags="&lt;raytracing&gt;&lt;material&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5311" PostTypeId="1" CreationDate="2017-06-30T13:18:54.557" Score="2" ViewCount="136" Body="&lt;p&gt;I have a grayscale image and want to &quot;resize&quot; it in terms of &quot;pixel concentration&quot;.&lt;br&gt;&#xA;That means I divide the source image &lt;code&gt;x_old * y_old&lt;/code&gt; into &lt;code&gt;x_new * y_new&lt;/code&gt; sections, and all (sub)pixel grayscale values in each section shall be accumulated to make the new grayscale value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Writing two loops also considering the sub pixel parts in each section is easy, but doesn't seem very sophisticated.&lt;br&gt;&#xA;Are there some smart and yet efficient algorithms doing the task?&lt;/p&gt;&#xA;" OwnerUserId="6346" LastEditorUserId="231" LastEditDate="2017-07-02T08:00:01.340" LastActivityDate="2018-01-18T17:29:56.807" Title="Image resize with pixel accumulation?" Tags="&lt;transformations&gt;&lt;algorithm&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="5312" PostTypeId="2" ParentId="5302" CreationDate="2017-06-30T14:07:29.473" Score="1" Body="&lt;h1&gt;In pseudocode&lt;/h1&gt;&#xA;&#xA;&lt;pre class=&quot;lang-none prettyprint-override&quot;&gt;&lt;code&gt;For each rectangle:&#xA;    If the rectangle overlaps the selection area, highlight the rectangle&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is all that is required for a correctly working approach, but there are a number of other things you might need to take into account if this approach performs too slowly. I recommend implementing the simple approach, and once it works correctly you can make gradual improvements if it is not sufficiently smooth and responsive (this may not be necessary unless you have a large number of rectangles or restrictive hardware/software).&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Determining whether a rectangle overlaps the selection rectangle&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;As you point out, using the point in polygon algorithm is impractical for this purpose - each rectangle is made up of an infinite number of points. So we need a completely different approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to check if a candidate rectangle overlaps the selection rectangle is to check for the following two cases:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Check if any edge of the candidate rectangle intersects an edge of the selection rectangle.&lt;/li&gt;&#xA;&lt;li&gt;Check if either the candidate rectangle or the selection rectangle is completely contained within the other.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If either of these are true, there is some overlap. If neither of these are true, there is no overlap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The complete containment check is simplified by the fact that the selection rectangle is never rotated - always remaining aligned to the x and y axes:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;To check if a candidate rectangle is completely contained within the selection rectangle, check that all 4 of its corners are between the x boundaries of the selection rectangle, and between the y boundaries of the selection rectangle.&lt;/li&gt;&#xA;&lt;li&gt;To check if a candidate rectangle completely contains the selection rectangle, check that it has one corner outside the bounds of the selection rectangle in each of the 4 orthogonal directions (left, right, up, and down). If so, it either contains the selection rectangle completely, or one or more of the edges intersect (but edge intersection was checked for in the previous stage, so we're only checking for complete containment if we already know there is no edge intersection).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;Line segment intersection&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To check whether any of the edges of a candidate rectangle intersects with any of the edges of the selection rectangle, you can either use a general line segment intersection algorithm and apply it to each pair of candidate edge and selection edge, or you can take advantage of the fact that the selection rectangle is never rotated,as follows:&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Parallel case&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;If the candidate rectangle has edges parallel to the x and y axes (that is, it is rotated by 0, 90, 180 or 270 degrees), check each of its edges:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the edge is vertical, check if its x position is between the x coordinates of the selection rectangle, and if one of the following holds then there is an intersection:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The y coordinate of one of its end points is between the y coordinates of the selection rectangle AND the y coordinate of the other end point is not.&lt;/li&gt;&#xA;&lt;li&gt;The end points are both outside the y coordinates of the selection rectangle but in opposite directions.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Similarly, if the edge is horizontal, check if its y position is between the y coordinates of the selection rectangle, and if one of the following holds then there is an intersection:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The x coordinate of one of its end points is between the x coordinates of the selection rectangle AND the x coordinate of the other end point is not.&lt;/li&gt;&#xA;&lt;li&gt;The end points are both outside the x coordinates of the selection rectangle but in opposite directions.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3&gt;Non-parallel case&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Check each of the edges of the candidate rectangle as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First find the points of intersection of the infinite line on which the candidate edge lies, with the infinite lines forming the boundaries of the selection rectangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If either of the intersections with the y boundaries of the selection rectangle has an x coordinate between the x boundaries of the selection rectangle, then there is an intersection of one of the horizontal line segment edges of the selection rectangle with the candidate infinite line (so potentially with the candidate line segment too).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, if either of the intersections with the x boundaries of the selection rectangle has a y coordinate between the y boundaries of the selection rectangle, then there is an intersection of one of the vertical line segment edges of the selection rectangle with the candidate infinite line (so potentially with the candidate line segment too).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To then check if there is an intersection with the candidate line segment, check if one of the following is true:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;An intersection with the y boundary of the selection rectangle is between the x boundaries of the selection rectangle AND between the y coordinates of the candidate line segment.&lt;/li&gt;&#xA;&lt;li&gt;An intersection with the x boundary of the selection rectangle is between the y boundaries of the selection rectangle AND between the x coordinates of the candidate line segment.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;Examples of refinements if speed is unsatisfactory&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Space_partitioning#In_computer_graphics&quot; rel=&quot;nofollow noreferrer&quot;&gt;Acceleration data structures&lt;/a&gt; such as a grid or space partitioning hierarchy so that not every rectangle needs to be checked. &lt;/li&gt;&#xA;&lt;li&gt;Only checking the changed parts of the selection (usually one corner of the selection stays fixed while the opposite corner moves).&lt;/li&gt;&#xA;&lt;li&gt;Tracking which rectangles are already selected to reduce the checking required each time the selection changes:&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;No need to check unselected rectangles if the selection has purely shrunk.&lt;/li&gt;&#xA;&lt;li&gt;No need to check already selected rectangles if the selection has purely grown.&lt;/li&gt;&#xA;&lt;li&gt;It will only be necessary to check both selected and unselected rectangles if the selection has grown in one direction and shrunk in the other.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="231" LastEditorUserId="231" LastEditDate="2017-07-02T12:16:40.190" LastActivityDate="2017-07-02T12:16:40.190" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5313" PostTypeId="1" AcceptedAnswerId="5318" CreationDate="2017-06-30T23:36:00.927" Score="1" ViewCount="87" Body="&lt;p&gt;I want to find out how the art brush in adobe illustrator works.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like it's taking some vector art and applying it to a smooth line. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rN7IF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rN7IF.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I go about implementing this?&lt;/p&gt;&#xA;" OwnerUserId="6834" LastEditorUserId="6546" LastEditDate="2017-07-02T07:42:53.087" LastActivityDate="2017-07-03T08:00:02.250" Title="adobe illustrator art brush, how does it work?" Tags="&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5315" PostTypeId="2" ParentId="5310" CreationDate="2017-07-02T06:49:13.320" Score="2" Body="&lt;p&gt;AI_MATKEY_COLOR_TRANSPARENT is used to define the transparent colour and AI_MATKEY_REFRACTI is the refractive index.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-07-02T06:49:13.320" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5316" PostTypeId="2" ParentId="5307" CreationDate="2017-07-02T15:25:27.840" Score="7" Body="&lt;p&gt;Assuming that you are familiar with the concept of BSDFs, the usual way of modelling rough dielectric surfaces (i.e. glass, water, plastics) is to use microfacet-based models like &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make it work efficiently in a path tracer you will need a good sampling strategy, like &lt;a href=&quot;http://www.eugenedeon.com/project/importance-sampling-microfacet-based-bsdfs-using-the-distribution-of-visible-normals/&quot; rel=&quot;noreferrer&quot;&gt;Importance Sampling Microfacet-Based BSDFs using the Distribution of Visible Normals&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also keep in mind, that the mentioned BSDF model tends to get darker as you increase roughness because it neglects the light which gets inter-reflected among micro-facets. This can be compensated, but it's not a trivial thing to do.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastActivityDate="2017-07-02T15:25:27.840" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5317" PostTypeId="1" AcceptedAnswerId="5348" CreationDate="2017-07-03T01:41:02.667" Score="6" ViewCount="1432" Body="&lt;p&gt;I understand how an artist would make seamless textures by hand, but how can a computer program automate that process? Software like &lt;a href=&quot;https://www.pixplant.com/&quot; rel=&quot;noreferrer&quot;&gt;PixPlant&lt;/a&gt; is capable of doing this, but I don't understand &lt;strong&gt;how&lt;/strong&gt; it does this.&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-07-13T10:43:15.777" Title="Seamless Textures" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5318" PostTypeId="2" ParentId="5313" CreationDate="2017-07-03T07:54:01.700" Score="3" Body="&lt;p&gt;These rely on a transformation from global coordinates to path local coordinates, where the local axes are along and out (or more often u and v). In essence this all works on a principle similar to how offset works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GRsF9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GRsF9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Depiction of local axes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the first one ($A$) is a sweep of an oval. Which is technically the most challenging of the four. In essence You offset edges directionally and cap them with a fixed directional oval. Although this has all kinds of interesting edge cases. A lot of mathematical lore is known about sweeping shapes as this is somewhat hard to do in 3D and doing so with an arbitrary shape is useful for the cad crowd. At it simplest its just sampling many times, which allows for change in shape along line, but quite sophisticated approaches are available.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rGI67.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rGI67.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Oval sweep.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second is simply (bombing) a shape in random places in the new coordinate system. Mathematically this is pretty simple. Generate a number in along direction then find that point. Then generate a second number and multiply that by the normal direction vector of your path then add this to the point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The third and fourth just do this for a lot of points read in form a Cartesian template object. Again you should familiarize yourself with how offset and graduated offset is done. You can find a lot of references but one of my favorite online resource for Béziers is in the &lt;a href=&quot;https://pomax.github.io/bezierinfo/#graduatedoffset&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pomax Bézier primer&lt;/a&gt;. Its just lot of small offset lines to transform from. &lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-07-03T08:00:02.250" LastActivityDate="2017-07-03T08:00:02.250" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5319" PostTypeId="1" CreationDate="2017-07-04T11:38:13.837" Score="2" ViewCount="38" Body="&lt;p&gt;I'm rendering clouds by applying a texture map on the inside of an ellipsoid. From a distance (at the center of the cloud ellipsoid) the texture looks quite nice and reasonably realistic. See image below:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7eEYB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7eEYB.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that as I fly close to the boundary of the ellipsoid (into the cloud) I see the boundaries of each of the quads that make up the ellipsoid. See image below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OBo1n.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OBo1n.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Any suggestions on how to get around this artifact would be appreciated. I'm using 50 grid segments in both the azimuthal and polar directions of the ellipsoid which is actually truncated 10 degrees below the poles. The texture map uses GL_MODULATE with GL_LINEAR and GL_LINEAR_MIPMAP_LINEAR for the Min and Mag filters. The ellipsoid base colour is white, so that there are no shading issues involved. I have also verified that the texture coordinates are correctly applied and the normals are oriented correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could cheat and use a lot of fog which would mimic actually flying into a cloud, but I'd really like to implement an elegant robust solution.&lt;/p&gt;&#xA;" OwnerUserId="6785" LastActivityDate="2017-07-04T16:44:40.883" Title="Hiding Boundaries with the Eye close to a set of adjacent textured quads" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5320" PostTypeId="2" ParentId="5319" CreationDate="2017-07-04T14:04:28.497" Score="3" Body="&lt;p&gt;I figured out the mistake that I was making and confirmed the hypothesis in my comment above. I was rendering each quad with its distinct set of vertex normals calculated from the local parametrisation. With lighting enabled, the vertices were therefore shaded differently for adjacent quads owing to the different dot products between the local normal and the light direction vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I did was average out the normals to create a unique normal at each vertex. Now when I fly into the clouds, I do not see the quad boundaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Dan suggested, I could avoid the problem altogether by disabling lighting, but it would eliminate the ability to simulate different times of the day and in any case, the fix above worked and only involved about 30 lines of code!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Problem solved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case anyone else finds this useful, here's the code (I wrote it in VBA) to calculate averaged vertex normals given a set of vertices on a surface that is topologically rectangular.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Sub Calculate_Averaged_Vertex_Normals(Vertx#(), M%, N%, VnormX#())&#xA;' INPUT:&#xA;'L,M: Array Dimensions&#xA;' Vertx - 3D array of vertex coordinates&#xA;' OUTPUT: VnormX: 3D array of Averaged Vertex Normals &#xA;&#xA; Dim i%, j%, k%, p%, q%, w%, NormX#(3), Ncount%(), Vx#(), Fn#(3),Gn#(3),Hn#(3),A#&#xA; ReDim Ncount%(0 To L, NF + 1), Vx(0 To L, NF + 1, 4, 3)&#xA; For k = 0 To M - 1&#xA;  For i = 0 To N - 1&#xA;   Call Quad_Normal_Vector_Parametrisation(Vertx,k, i,Fn,Gn,Hn) ' Local Normals at each Vertex&#xA;&#xA;     p = k: q = i: Ncount(p, q) = Ncount(p, q) + 1: j = Ncount(p, q)&#xA;     Call Quad_Vertex_Normal(0, 0, NormX,Fn,Gn,Hn)&#xA;     For w = 1 To 3: Vx(p, q, j, w) = NormX(w): Next w&#xA;&#xA;     p = k: q = i + 1: Ncount(p, q) = Ncount(p, q) + 1: j = Ncount(p, q)&#xA;     Call Quad_Vertex_Normal(1, 0, NormX,Fn,Gn,Hn)&#xA;     For w = 1 To 3: Vx(p, q, j, w) = NormX(w): Next w&#xA;&#xA;     p = k + 1: q = i + 1: Ncount(p, q) = Ncount(p, q) + 1: j = Ncount(p, q)&#xA;     Call Quad_Vertex_Normal(1, 1, NormX,Fn,Gn,Hn)&#xA;     For w = 1 To 3: Vx(p, q, j, w) = NormX(w): Next w&#xA;&#xA;     p = k + 1: q = i: Ncount(p, q) = Ncount(p, q) + 1: j = Ncount(p, q)&#xA;     Call Quad_Vertex_Normal(0, 1, NormX,Fn,Gn,Hn)&#xA;     For w = 1 To 3: Vx(p, q, j, w) = NormX(w): Next w&#xA;  Next i&#xA; Next k&#xA;&#xA; For k = 0 To M&#xA;  For i = 0 To N&#xA;   For w = 1 To 3&#xA;    A = 0#&#xA;    For j = 1 To Ncount(k, i)&#xA;     A = A + Vx(k, i, j, w)&#xA;    Next j&#xA;    VnormX(k, i, w) = A / Ncount(k, i)          ' Averaged Vertex Normal&#xA;   Next w&#xA;  Next i&#xA; Next k&#xA;End Sub&#xA;&#xA;Sub Quad_Normal_Vector_Parametrisation(Vertx#(),k%, i%,Fn#(),Gn#(),Hn#())&#xA; Dim j%, Bv#(3), CV#(3), Dv#(3)&#xA; For j = 1 To 3&#xA;  Bv(j) = Vertx(k, i + 1, j) - Vertx(k, i, j)           ' Tangent Vectors from Bilinear Parametrisation&#xA;  CV(j) = Vertx(k + 1, i, j) - Vertx(k, i, j)&#xA;  Dv(j) = Vertx(k + 1, i + 1, j) - Vertx(k, i + 1, j) - Vertx(k + 1, i, j) + Vertx(k, i, j)&#xA; Next j&#xA; Call CrossProd(Bv, CV, Fn)             ' Normal Vector from Cross Product of Tangent Vectors.&#xA; Call CrossProd(Bv, Dv, Gn)&#xA; Call CrossProd(Dv, CV, Hn)&#xA;End Sub&#xA;&#xA;Sub Quad_Vertex_Normal(x#, y#, NormX#(),Fn#(),Gn#(),Hn#())&#xA; Dim j%, Norm#&#xA; Norm = 0#&#xA; For j = 1 To 3&#xA;  NormX(j) = Fn(j) + Gn(j) * x + Hn(j) * y&#xA;  Norm = Norm + NormX(j) * NormX(j)&#xA; Next j&#xA; Norm = Sqr(Norm)&#xA; For j = 1 To 3&#xA;  NormX(j) = NormX(j) / Norm&#xA; Next j&#xA;End Sub&#xA;&#xA;Sub CrossProd(x#(), y#(), Z#())&#xA; Z(1) = x(2) * y(3) - y(2) * x(3)&#xA; Z(2) = y(1) * x(3) - x(1) * y(3)&#xA; Z(3) = x(1) * y(2) - y(1) * x(2)&#xA;End Sub&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6785" LastEditorUserId="6785" LastEditDate="2017-07-04T16:44:40.883" LastActivityDate="2017-07-04T16:44:40.883" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5321" PostTypeId="2" ParentId="5274" CreationDate="2017-07-04T14:42:26.767" Score="3" Body="&lt;p&gt;Conceptually simplest would be to treat it as a ray-casting problem, representing each point as a small sphere. It should work like the shadow rays in a conventional raytracer: iterate over all of your points, and for each one, trace a ray to the camera. If the ray intersects the sphere representing another point, then remove it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the number of points is small enough, you can do this directly, but if that's not fast enough, you should put the points into an acceleration structure such as a kd-tree. (If you need this kind of optimization, it might be best to start from an existing ray-tracer such as PBRT instead of writing it from scratch.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the points represent surface detections (from something like a laser scanner), you might also have the surface normal at each point, depending on the scanner technology. In this case, you might get better results by using small discs instead of spheres. That'll be more robust on faces seen at a glancing angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, if you also need to remove points that are outside the camera's view (e.g. behind the camera), you can do this at the same time by comparing the direction of each ray with the camera's view bounds.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-07-04T14:42:26.767" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5322" PostTypeId="1" CreationDate="2017-07-04T16:26:02.303" Score="1" ViewCount="121" Body="&lt;pre&gt;&lt;code&gt;void display(void) {&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    glColor3f(1.0, 1.0, 1.0);&#xA;    glBegin(GL_LINES);&#xA;    glVertex3d(0.75, 0.25, 0.0);&#xA;    glVertex3d(0.75, 0.25, -0.75);&#xA;    glEnd();&#xA;    glFlush();&#xA;}&#xA;&#xA;void init(void) {&#xA;    glClearColor(0.0, 0.0, 0.0, 0.0);&#xA;    glMatrixMode(GL_PROJECTION);&#xA;    glLoadIdentity();&#xA;    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I should be able to see line from &lt;code&gt;(0.75, 0.25, 0.0)&lt;/code&gt;  to &lt;code&gt;(0.75, 0.25, -0.75)&lt;/code&gt;, but I can't see anything on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I'm able to see the line using snippet below&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glVertex3d(0.35, 0.25, 0.0);&#xA;glVertex3d(0.75, 0.25, -0.75);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain this behavior?&lt;/p&gt;&#xA;" OwnerDisplayName="user6935" LastActivityDate="2017-07-05T08:05:30.967" Title="glOrtho() in fixed function pipeline - Unable to see change in z-axis" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5323" PostTypeId="1" AcceptedAnswerId="5326" CreationDate="2017-07-05T02:09:35.390" Score="7" ViewCount="6915" Body="&lt;p&gt;Is it possible to have a dynamic array in a GLSL shader? For instance, what if I have something like this in my GLSL Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform int size;&#xA;uniform SceneLights lights[size];&#xA;&#xA;void main()&#xA;{&#xA;    for(int i = 0; i &amp;lt; size; i++) {&#xA;        /* Do Some Calculation */&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this would be my C++ file:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (GLuint i = 0; i &amp;lt; pointLights.size(); i++) {&#xA;    glUniform3f(glGetUniformLocation(shader, (&quot;pointLights[&quot; + std::to_string(i) + &quot;].position&quot;).c_str()), lights[i].someValue);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I would like to do this because I have a file with the positions of all the light sources in my scene (this may vary for each scene) so I would like to have a dynamic array which will allow me to send different numbers of lights to my shader.&lt;/p&gt;&#xA;" OwnerUserId="6546" LastEditorUserId="6546" LastEditDate="2017-07-05T02:15:14.993" LastActivityDate="2021-01-10T13:05:58.397" Title="Dynamic Array in GLSL" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5324" PostTypeId="1" CreationDate="2017-07-05T03:58:48.610" Score="1" ViewCount="63" Body="&lt;p&gt;So I have implemented motion blur via depth re-construction using the depth texture and a previous view projection matrix. The shader basically finds the texel coordinate in by using the previous (frame) view projection matrix and subtract the current UV (what's given to fragment) to find a blurring vector. Then I simply blur along this vector by sampling along it and then normalize it with the number of samples, a constant I set at the beginning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I'm having is that even a tiny movement will cause the motion blur to ... well blur the scene. I find this too invasive and would like to ... &quot;soften&quot; this effect. I have tried to cap it by saying if the dot product of this blur vector is greater than 0.01, then blur. This sadly creates an oval like artifact in the middle the screen ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone have good suggestions on how to handle this? &lt;/p&gt;&#xA;" OwnerUserId="6938" LastEditorUserId="231" LastEditDate="2017-07-05T04:42:53.790" LastActivityDate="2017-07-05T04:42:53.790" Title="Motion Blur via depth re-construction too sensitive" Tags="&lt;post-processing&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5325" PostTypeId="2" ParentId="5322" CreationDate="2017-07-05T08:05:30.967" Score="4" Body="&lt;p&gt;This projection is a 2d projection, with the Z axis pointing into your screen. When both vertices with the same X&amp;amp;Y are projected to screen space they will occupy the same screen coordinate so your line will either be 1 pixel or invisible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are expecting a difference in screen position from those 2 coordinates then you need a perspective projection.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-07-05T08:05:30.967" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5326" PostTypeId="2" ParentId="5323" CreationDate="2017-07-05T08:11:40.990" Score="14" Body="&lt;p&gt;I don't think uniform arrays can be dynamically sized. In your case you should define the array as the maximum number of lights you will process and then use a uniform to control the number of iterations you do on this array. On the CPU side you can set a subset of the lights[] array according to the 'size' variable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define MAX_LIGHTS 128&#xA;&#xA;uniform int size;&#xA;uniform SceneLights lights[MAX_LIGHTS];&#xA;&#xA;void main()&#xA;{&#xA;    for(int i = 0; i &amp;lt; size; i++) {&#xA;        /* Do Some Calculation */&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I think (speculate) the likely reason for this is that it would be impossible to determine the location of a uniform if there are variable sized arrays in your uniform list which depend on the value of another uniform.. e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform int arraySize;               // offset 0&#xA;uniform int myArray[arraySize];      // offset 4&#xA;uniform int anotherVar;              // offset ???? &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;GLSL would not know were to place anotherVar, because it would need arraySize to be set with a value before it can compute the offset of 'anotherVar'. I suppose the compiler could be clever and re-arrange the order of uniforms to get around this, but this will fail again if you have 2 or more variable sized arrays..&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2017-07-11T02:49:43.297" LastActivityDate="2017-07-11T02:49:43.297" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5327" PostTypeId="1" CreationDate="2017-07-05T09:25:43.813" Score="4" ViewCount="289" Body="&lt;p&gt;Is it possible to describe a position of a point $A$ (in 3D) w.r.t. the position and orientation of 3 other points? If so, how?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;FYI, the 3 other points lie on a plane, whereas the point $A$ is not on the plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just to elaborate, initially I have the info for all four points. My goal is to find where point $A$ is when the other three points changing position and orientation.&lt;/p&gt;&#xA;" OwnerUserId="2687" LastEditorUserId="2687" LastEditDate="2017-07-05T11:23:53.203" LastActivityDate="2017-07-05T11:32:44.437" Title="How to describe a position of a point w.r.t the position and orientation of 3 other points" Tags="&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5328" PostTypeId="2" ParentId="5327" CreationDate="2017-07-05T10:33:21.623" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;FYI, the 3 other points lie on a plane&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Of course they do. Any set of three points defines a plane (except in the degenerate case joojaa mentions, where they lie on many planes). If the points are $p$, $q$, and $r$, then $(q - p) \wedge (r - p)$ is the normal to the plane; call it $n$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This plane defines a co-ordinate system. If you make it the XY plane, then $z = a \dot\ n$. You can also project $a$ onto the plane to get the other two co-ordinates: $x = (a - p) \dot\ (q - p)$ and $y = (a - p) \dot\ (r - p)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the co-ordinate system I've described here is pretty rubbish: it isn't even orthogonal. It's good enough to uniquely identify a point, as long as you're careful about all the signs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But if you want an orthonormal basis, you can construct it from this one. First, instead of $q - p$ and $r - p$, normalize those vectors. Then $n$ will also have length 1, and the $x$ axis will also be normal. The last problem is the $y$ axis, which is not orthogonal to the $x$ axis. You can get a better $y$ axis by crossing the other two and normalizing, and while you're doing that you might as well also choose the order to ensure the basis is right-handed. Your three basis vectors are as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{eqnarray}&#xA;\hat{z} &amp;amp; = &amp;amp; \frac{n}{|n|} \\&#xA;\hat{x} &amp;amp; = &amp;amp; \frac{q - p}{|q - p|} \\&#xA;\hat{y} &amp;amp; = &amp;amp; \hat{z} \wedge \hat{x}&#xA;\end{eqnarray}&#xA;$$&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2017-07-05T10:42:50.280" LastActivityDate="2017-07-05T10:42:50.280" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5329" PostTypeId="2" ParentId="5327" CreationDate="2017-07-05T10:56:23.460" Score="3" Body="&lt;p&gt;What you're looking for is closest point on a plane for the 3rd direction but since @DanHulme described this I would not repeat it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can pretty easily use &lt;a href=&quot;https://en.wikipedia.org/wiki/Affine_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;affine transformation matrices&lt;/em&gt;&lt;/a&gt; for this. Making a fully defined affine transform from 3 points is a pretty normal operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The standard way is to just use a cross product to produce a third axis (possibly normalized, but whether or not you want to do that depends on application) this way you have 2 axes on the plane and one perpendicular to the plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To form the matrix say you have the vectors $\vec a$, $\vec b$ and $\vec c$ then you formulate the matrix. Then you calculate the vector from a to b $\vec v_{b-a}$ by subtracting $\vec a$ from $\vec b$, and a second vector $\vec v_{c-a}$ by subtracting $\vec a$ from $\vec c$. So basically 2 spanning vectors pointing out from $\vec a$. Then you formulate this as a matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{bmatrix}&#xA;\vec v_{b-a} \\&#xA;\vec v_{c-a} \\&#xA;\left|\vec v_{b-a} \times \vec v_{c-a}\right|\\&#xA;\vec a&#xA;\end{bmatrix}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thats about it. Some more maths to orthogonalize the thing.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2017-07-05T11:32:44.437" LastActivityDate="2017-07-05T11:32:44.437" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5330" PostTypeId="1" AcceptedAnswerId="5331" CreationDate="2017-07-05T14:55:43.540" Score="8" ViewCount="544" Body="&lt;p&gt;On the Wikipedia page for the &lt;a href=&quot;https://en.wikipedia.org/wiki/Phong_reflection_model&quot; rel=&quot;noreferrer&quot; title=&quot;Phong reflection model&quot;&gt;Phong model&lt;/a&gt;, it says that the ambient term is a constant, and just gets added on to the other terms. But on other pages like &lt;a href=&quot;https://learnopengl.com/#!Lighting/Basic-Lighting&quot; rel=&quot;noreferrer&quot; title=&quot;Learn OpenGL&quot;&gt;LearnOpenGL&lt;/a&gt; it says you should take the ambient term and multiply it by the color of the object. Which one is correct?&lt;/p&gt;&#xA;" OwnerUserId="6838" LastEditorUserId="6546" LastEditDate="2017-07-06T01:00:45.077" LastActivityDate="2020-02-17T05:11:32.777" Title="Ambient Lighting" Tags="&lt;rendering&gt;&lt;lighting&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5331" PostTypeId="2" ParentId="5330" CreationDate="2017-07-05T15:17:50.497" Score="7" Body="&lt;p&gt;Correct is the OpenGL way. If you had a white light ( let's say vec3(255,255,255) )&#xA;and just simply added it to a blue object ( vec3(0,0,255) ), the object would seem to be white, which is wrong. But if you were to multiply these colors, the object would be fully illuminated and correctly blue (which is the desired product).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing with ambient light is that it is only influenced by the ambient light intensity and by the color of the object, which means it is not influenced by the lights position, direction or anything of the sort. That is why you can think of it as &quot;simply adding it as a constant&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We use ambient light mostly to simulate reflected light in the scene, which is very hard to simulate otherwise (without raytracing). It's a fairly good and cheap alternative.&lt;/p&gt;&#xA;" OwnerUserId="2138" LastActivityDate="2017-07-05T15:17:50.497" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5332" PostTypeId="2" ParentId="5330" CreationDate="2017-07-05T15:26:14.490" Score="5" Body="&lt;p&gt;The relevant equation on the Wikipedia page follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;I_\text{p} = k_\text{a} i_\text{a} + \sum_{m\;\in\;\text{lights}} (k_\text{d} (\hat{L}_m \cdot \hat{N}) i_{m,\text{d}} + k_\text{s} (\hat{R}_m \cdot \hat{V})^{\alpha}i_{m,\text{s}})&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this equation, all the $k$ and $i$ terms are not numbers but colours (RGB intensities). This includes $k_a$ and $i_a$: the ambient colour of the object, and the ambient illumination colour, respectively. The ambient term isn't a constant: it's a product of an intensity and albedo, just like the specular and diffuse terms. The only difference is that the lighting and view directions aren't a factor in this term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's very unusual to have $k_a$ different from the diffuse colour, so you can think of it as multiplying by &quot;the colour of the object&quot;. That said, it's quite common for $i_a$ to be a distinct colour: for example, if you're using a yellowish directional light for direct sunlight, you might want the ambient light to be blueish to stand in for skylight.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-07-05T15:26:14.490" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5333" PostTypeId="1" CreationDate="2017-07-05T22:24:12.907" Score="2" ViewCount="154" Body="&lt;pre&gt;&lt;code&gt;module initial(letter, size) {&#xA;  linear_extrude(height=size*4, center=true) {&#xA;    text(letter, size=size, halign=&quot;center&quot;, valign=&quot;center&quot;, font=font);&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm using this module to generate very tall letters that I then cut out of other shapes using &quot;difference&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This works well for some letters (like M), but leaves detached pieces floating in the middle for letters like &quot;O&quot; or &quot;A&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to know how to get just the outline of the letter without changing the shape of that outline the way the &quot;hull&quot; function would.&lt;/p&gt;&#xA;" OwnerUserId="6946" LastActivityDate="2017-07-05T22:24:12.907" Title="OpenSCAD: Using outline of 2D shape" Tags="&lt;2d&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5334" PostTypeId="1" CreationDate="2017-07-05T23:48:02.617" Score="0" ViewCount="122" Body="&lt;p&gt;I'm trying to break a continuous line segment into multiple, straight segments. &lt;a href=&quot;https://i.stack.imgur.com/ToT9w.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ToT9w.png&quot; alt=&quot;Group of line segments as connected&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried using the Hough transform but have found it unreliable for getting the line segments I'm looking for and because it demands too much fine tuning to fit the automated medium I'm working in. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Analyzing points (comparing slopes/averages) as they change has shown some success, but the lines found are often too segmented or too unsegmented (just the whole line), proving unreliable so far. These are also prone to give too much of the subsequent line before cutting off when they have worked.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Contextual restrictions include:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Only one 'Y' value per X point (this image doesn't show this, but the property holds).&lt;/li&gt;&#xA;&lt;li&gt;There are no gaps between points in the line.&lt;/li&gt;&#xA;&lt;li&gt;Noise is possible, but not that bad usually (within a few pixels of being correct).&lt;/li&gt;&#xA;&lt;li&gt;The lines being detected are straight, not curved.&lt;/li&gt;&#xA;&lt;li&gt;This is being developed in C++ using the SDL2 framework.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I feel like I'm overcomplicating this question. How can I find the points that separate the segments? I suspect something comparing averages or averages of averages might be the way to go.&lt;/p&gt;&#xA;" OwnerUserId="2108" LastEditorUserId="231" LastEditDate="2017-07-06T09:16:02.783" LastActivityDate="2017-07-06T09:16:02.783" Title="Finding Segments in Continuous line" Tags="&lt;c++&gt;&lt;image-processing&gt;&lt;line-drawing&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5335" PostTypeId="1" AcceptedAnswerId="5452" CreationDate="2017-07-06T07:35:15.887" Score="3" ViewCount="313" Body="&lt;p&gt;I'm looking for a way to procedurally create a realistically looking texture overlay simulating the object being shrink wrapped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is only used to be added to single images, so it does not need to behave correctly in an animation with changes of position or angle of the object, camera or light source(s).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already tried by implementing a grayscale &lt;a href=&quot;https://en.wikipedia.org/wiki/Plasma_effect&quot; rel=&quot;nofollow noreferrer&quot;&gt;plasma effect&lt;/a&gt;. It looks nice but not real:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/J6Kzf.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/J6Kzf.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below you can find some examples of what I am hoping to achieve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any suggestions on how something like this could be generated? I'm looking to produce thousands of unique textures, so there should be some variation/randomness involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7Omsl.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7Omsl.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/go88a.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/go88a.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/0pslh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0pslh.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/OlfMd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OlfMd.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XYHIx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XYHIx.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6951" LastEditorUserId="6951" LastEditDate="2017-07-06T08:51:25.780" LastActivityDate="2017-08-03T07:51:12.020" Title="procedurally generating a texture overlay simulating shrink wrap" Tags="&lt;texture&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5336" PostTypeId="1" CreationDate="2017-07-07T08:46:44.143" Score="6" ViewCount="314" Body="&lt;p&gt;I'm in search for an algorithm that takes the left side of the following graphic as an input and outputs a minimal amount of convex polygons as seen on the right side of the graphic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GMer4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GMer4.png&quot; alt=&quot;input and output of the wanted algorithm&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The input mesh can be very complex and could contain several holes. The position of the vertices are not constrained to a grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The use case for this is the creation of multiple polygon shapes for the Box2D physics engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additional information:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The result does not need to be deterministic.&lt;/li&gt;&#xA;&lt;li&gt;The result does not need to be vertically striped. &lt;/li&gt;&#xA;&lt;li&gt;As trichoplax noted, the right part of the picture does not resemble the minimal polygon count that can be achieved. It's just an example.&lt;/li&gt;&#xA;&lt;li&gt;It's not necessary that it will find the absolute minimum of convex polygons. A fast algorithm is preferred over a &quot;best solution&quot; one.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4558" LastEditorUserId="4558" LastEditDate="2017-07-07T11:40:03.150" LastActivityDate="2017-08-06T15:18:28.000" Title="List of triangles to minimum amount of convex polygons" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5337" PostTypeId="1" AcceptedAnswerId="5340" CreationDate="2017-07-07T14:17:12.117" Score="3" ViewCount="238" Body="&lt;p&gt;In my program, I use a additional frame buffer to render something into a texture(only a glClear), which I will reference it's handle in next draw command. And draw the texture back to the default frame buffer.&#xA;My program almost run like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;frame buffer create and attached by a GL_TEXTURE_2D texture and other setup&#xA;glGetTextureHandle&#xA;glMakeHandleResident&#xA;&#xA;bind this frame buffer&#xA;glclear(1.0f, 0.0f, 0.0f, 1.0f)&#xA;&#xA;glBindFramebuffer to 0(back to default frame buffer)&#xA;ShaderUse//nothing but return texture's color&#xA;glUniformHandleui64(location, textureHandle)//witch is the texture above&#xA;//if I use normal bind texture, the result will be correct&#xA;glDraw*//just draw a quad&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here I got a strange issue, The 2nd glDraw cmd gives an empty result(Back Buffer is an black image). And I also checked the first frame buffer's render texture witch is a pure red image, and it's a correct result. And my GPU is AMD R7 200.&#xA;But when I change bindless texture to normal bind texture style, and everything is ok finally.Also I checked in NV GPU-GTX650 with same program, and the result is also ok.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am sure there is no opengl error occurred in my program, and I also checked GL_ARB_bindless_texture extension is supported by my devices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I wonder, am I missing some memory sync or coherent?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also looked up to the document and I found this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;(4) Can texture or sampler objects be modified while they are used by&#xA;  a&#xA;          texture or image handle?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  RESOLVED:  No.  If such changes were permitted, each modification to the&#xA;  texture object would require potential synchronization with one or more&#xA;  texture/image handles extracted from the texture.  This seems like a lot&#xA;  of bookkeeping with little benefit.  One exception to this rule is that&#xA;  individual texels of such texture objects may still be updated with APIs&#xA;  such as TexSubImage* and by rendering to a framebuffer object to which&#xA;  the texture is attached.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;One exception to this rule is that&#xA;      individual texels of such texture objects may still be updated with APIs&#xA;      such as TexSubImage* and by rendering to a framebuffer object to which     the texture is attached.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does glClear belong to this exception?&lt;/p&gt;&#xA;" OwnerUserId="6660" LastEditorUserId="6660" LastEditDate="2017-07-07T14:26:55.497" LastActivityDate="2017-07-07T19:58:38.320" Title="glClear's result can't be seen when using bindless texture" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5338" PostTypeId="2" ParentId="5336" CreationDate="2017-07-07T14:32:30.150" Score="1" Body="&lt;p&gt;If a edge corner is concave then it needs to border 2 of the output polygons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So one algorithm would be to find all concave corners (including the ones in the holes) and making cuts starting from them to other concave corners. This will split the polygon in two or join 2 holes into 1 or connect a hole to the outside. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cut from a concave corner should be constrained by the angle or it will create a new concave corner that then needs to be cut again.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2017-07-07T15:12:41.807" LastActivityDate="2017-07-07T15:12:41.807" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5340" PostTypeId="2" ParentId="5337" CreationDate="2017-07-07T19:11:47.757" Score="1" Body="&lt;p&gt;This is clearly a bug in AMD's driver, though it's a very understandable one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is probably happening is that the driver does not correctly detect that there is a dependency between the framebuffer operation and the use of the texture. It's easy for an API to tell that you've bound a texture that was the subject of an outstanding render target command, since the API sees exactly what texture you're going to use. It can simply keep track of the texture objects recently used in an FBO, and if it sees you render with one of them bound, it issues whatever dependencies are needed to ensure that the operation is complete before the rendering operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's much harder when you're not &lt;em&gt;binding&lt;/em&gt; the texture; you're just passing an arbitrary number to the shader. The API has no idea if that number represents a render target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To verify that this is the problem, insert a &lt;code&gt;glFinish()&lt;/code&gt; between the clear command and the draw command that uses the texture. Odds are good that it will go away (or at least be partially mitigated). A &lt;code&gt;glTextureBarrier()&lt;/code&gt; call might also fix it. If you're getting the texture handle after attaching the texture to the FBO, you might also want to get the handle first. Just in case that shakes something loose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that you shouldn't &lt;em&gt;have&lt;/em&gt; to do any of these; the specification requires that things work exactly as you expect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What AMDs driver needs to do is to realize that you're using bindless texturing and emit the appropriate dependency operations when you change framebuffer render targets. That is, it has to assume that any &lt;code&gt;glBindFramebuffer&lt;/code&gt; or any calls that modify the FBO that's currently bound will result in any subsequent rendering command reading from previously written textures. Therefore, it &lt;em&gt;must&lt;/em&gt; issue a synchronization at the first rendering command that involves a bindless texture operation (if the texture used by the FBO is made resident).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either that, or it somehow has to figure out which arbitrary integers represent which textures. This is very difficult, since you can pass those handles in a variety of ways. UBOs, for example; you don't want implementations combing through images.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-07-07T19:58:38.320" LastActivityDate="2017-07-07T19:58:38.320" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5342" PostTypeId="2" ParentId="4793" CreationDate="2017-07-08T18:26:23.773" Score="3" Body="&lt;p&gt;You need to round down the mipmap sizes.&#xA;In your case the correct sequence is 200, 100, 50, 25, 12, 6, 3, 1.&lt;/p&gt;&#xA;" OwnerUserId="6966" LastActivityDate="2017-07-08T18:26:23.773" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5343" PostTypeId="2" ParentId="1984" CreationDate="2017-07-09T10:11:17.017" Score="2" Body="&lt;p&gt;The silhouette curve of a quadric surface is a conic (ellipse, parabola, hyperbola, etc.). Suppose you have the quadric $\mathbf{X}^T \mathbf{M} \mathbf{X} = 0$ and your eye is at the point $\mathbf{Y}$. Then the silhouette curve is the intersection of the quadric and the so-called polar plane of $\mathbf{Y}$, which is $\mathbf{Y}^T \mathbf{M} \mathbf{X} = 0$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For anything more complex than quadrics, things get nasty in a hurry, and you won't find any analytic solutions; you'll need numerical methods to trace the curve. Even the silhouette of a torus is pretty complex. So, in essence, the best you can do is compute discrete points along the curve, and use these to construct either a polyline or a spline of some sort. But, of course, you can always get a polyline just by tesselating the surface and finding the silhouette of the tesselation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One approach would be to approximate your surface of revolution by quadrics, but that may not be any better than tesselating. You'd get a piecewise conic curve, instead of a polyline, which might be an improvement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that if your surface is not G2, then it's silhouette will not be G1 (i.e. it may have sharp corners). Tracing a curve with corners is tricky.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are silhouette generation functions in geometry kernels like Parasolid and ACIS. Maybe in OpenCascade, too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To illustrate the difficulty, suppose we have a surface with parametric equations $(u,v) \mapsto \mathbf{S}(u,v)$, and we are viewing it from an eye- point $\mathbf{E}$. Let $\mathbf{N}(u,v)$ be the surface normal at parameter values $(u,v)$, which we can calculate as the cross product of partial derivatives: $\mathbf{N}(u,v) = \mathbf{S}^u(u,v) \times \mathbf{S}^v(u,v)$.&#xA;If a point $\mathbf{P}$ is on the silhouette curve, then the surface normal at this point is perpendicular to the vector $\mathbf{P} - \mathbf{E}$. So, the silhouette curve is the locus of points where&#xA;$$&#xA;(\mathbf{S}(u,v) - \mathbf{E}) \cdot \mathbf{N}(u,v) = 0&#xA;$$&#xA;Substituting for $\mathbf{N}(u,v)$, this becomes&#xA;$$&#xA;(\mathbf{S}(u,v) - \mathbf{E}) \cdot (\mathbf{S}^u(u,v) \times \mathbf{S}^v(u,v) ) = 0&#xA;$$&#xA;If $\mathbf{S}(u,v)$ is even a very simple surface, like a torus or a biquadratic or bicubic patch, the silhouette equation will not have any analytic solution.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-07-11T00:20:45.700" LastActivityDate="2017-07-11T00:20:45.700" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5344" PostTypeId="2" ParentId="3697" CreationDate="2017-07-09T10:22:58.737" Score="1" Body="&lt;p&gt;Since we're not told what defintion of &quot;center&quot; to use, we may as well use the easiest. This would be &#xA;$$&#xA;\text{Center} = \frac14( \mathbf{P}_0 + \mathbf{P}_1 + \mathbf{P}_2 + \mathbf{P}_3)&#xA;$$&#xA;where $\mathbf{P}_0$, $\mathbf{P}_1$,  $\mathbf{P}_2$,  $\mathbf{P}_3$ are the control points of the curve. &lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-12-22T01:38:11.077" LastActivityDate="2017-12-22T01:38:11.077" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5345" PostTypeId="2" ParentId="4781" CreationDate="2017-07-09T10:31:40.207" Score="1" Body="&lt;p&gt;As far as I know, there are no standard shapes for (physical) French curves. The folks who manufacture them are free to choose any shapes they like. Of course, they choose shapes that look &quot;nice&quot;, which typically means curvature that's either monotonely increasing or has a single peak value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, you can't solve this problem unless you make some assumptions about the specific shapes of French curves available to your user(s).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have done this, you can model the shape of the French curve as a Bezier curve (for example). Then the problem is to position/orient this Bezier curve so that it fits the data, which is a simple least-squares fitting problem. I'll provide more details if you confirm that this approach is promising.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastActivityDate="2017-07-09T10:31:40.207" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5346" PostTypeId="2" ParentId="4188" CreationDate="2017-07-09T10:55:46.910" Score="0" Body="&lt;p&gt;If you use the same $\mathbf{B}$ matrix on each segment, then you are constructing a so-called &quot;uniform&quot; b-spline. This means that the parameter increment over each segment is a constant (typically $=1$). Uniform b-splines often have undesirable shapes if the control points are unevenly distributed. But, if the distances between control points don't vary too wildly, then you can use uniform b-splines and get some nice computational simplifications.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastActivityDate="2017-07-09T10:55:46.910" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5348" PostTypeId="2" ParentId="5317" CreationDate="2017-07-10T02:47:41.113" Score="10" Body="&lt;p&gt;For these types of algorithms, you usually have to rely on multiple forms of texture synthesis. That doesn't mean you have to generate the whole texture from scratch. For example, you could regenerate the sides of the texture to achieve a seamless effect. This answer may not be complete because it's a large field, and different approaches will have various effectiveness depending on the input image.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Naive blur along edges&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;As an artist, one way to make seamless textures is to offset the image in two directions. Then, you can blur the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Nf1L4.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Nf1L4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This example isn't the best, but you can get decent results with results with certain texture types.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, you could do a minimum cut on the edge here by overlapping the image with itself, and then taking the difference between the two images.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Min-cut algorithms&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;One of the most popular algorithms is &lt;a href=&quot;http://dl.acm.org/citation.cfm?id=383296&quot; rel=&quot;noreferrer&quot;&gt;image quilting&lt;/a&gt;. The idea behind this is separate the texture into a bunch of patches. You fill in the texture by first randomly picking a subset of patches from your total set of patches and picking the one with the least amount of error when you overlap the patch with it's neighboring patch(es). You then perform minimum cuts along the overlapping regions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My experience with this algorithm is that it works well for many textures that have round details. If the texture is grass for instance, then it can perform poorly. The amount you overlap each patch also has a large impact on quality. The larger the overlap, the better the match, but the more likely there will be repetition. Also, if the subset of candidate patches is too large, then you'll get repetition. Otherwise, you might not find good matches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are extensions of this algorithm including PatchMatch (which was used in Photoshop).&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Gradient correction&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Another way to handle seamless textures is to remove the gradient. &lt;a href=&quot;http://dl.acm.org/citation.cfm?id=882269&quot; rel=&quot;noreferrer&quot;&gt;Poisson image editing&lt;/a&gt; can help with this if you break up your image and use the various pieces are foreground and background objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simpler approach is to create a low-frequency (e.g., mipmap) of your texture and then remove the gradient of your image. Of course, high frequency data won't be seamless, but you can remove that with other algorithms.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Computer vision approaches&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;You could use various computer vision approaches as well. The idea here would be that you keep important features intact as you attempt to tile your textures. For instance, if there's a texture of dirt with a rock on the edge of the picture, using various feature detectors such as difference of Gaussians could help you identify this rock and remove it before you do the tiling. You might need to fill in the rest of the texture where the rock was removed, but this could help with making the image more seamless.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Additional References&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.connellybarnes.com/work/class/2014/comp_photo/proj1/&quot; rel=&quot;noreferrer&quot;&gt;Image quilting and PatchMatch high-level explanation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.connellybarnes.com/work/class/2014/comp_photo/proj2/&quot; rel=&quot;noreferrer&quot;&gt;Gradient domain compositing&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="209" LastEditDate="2017-07-13T10:43:15.777" LastActivityDate="2017-07-13T10:43:15.777" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5349" PostTypeId="1" AcceptedAnswerId="5352" CreationDate="2017-07-10T09:24:34.713" Score="3" ViewCount="1945" Body="&lt;p&gt;I am trying to reduce aliasing in an image using some filters. I tried the Gaussian variant of filters to remove the said high frequency patterns in the image, but I feel it's a bit too much of a blur. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need a filter that can help me do some kind of anti-aliasing without doing too much blur. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have searched a lot and unfortunately the results are not fruitful.&lt;/p&gt;&#xA;" OwnerUserId="6974" LastEditorUserId="231" LastEditDate="2017-07-12T12:57:27.430" LastActivityDate="2017-07-12T12:57:27.430" Title="How can I remove aliasing in an image without introducing blur?" Tags="&lt;image-processing&gt;&lt;image&gt;&lt;antialiasing&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5351" PostTypeId="2" ParentId="1983" CreationDate="2017-07-11T13:24:03.003" Score="3" Body="&lt;p&gt;The curve you are seeking is just the intersection of a plane (the back of the camera) and a right circular cone. This is not really a question about the earth, or views of planets from space; it's just plain simple 3D coordinate geometry. To find a reference, I'd recommend searching for &quot;intersection of a plane and a cone&quot; or &quot;plane section of a cone&quot;, or &quot;plane section of quadric&quot;, something like that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd expect that you can find the relevant formulae (and derivations) in any standard text on 3D coordinate geometry. Some likely places are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Salmon -- A Treatise on the Analytic Geometry of Three Dimensions&lt;/li&gt;&#xA;&lt;li&gt;Somerville -- Analytical Geometry of Three Dimensions&lt;/li&gt;&#xA;&lt;li&gt;Snyder and Sisam -- Analytic Geometry of Space&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;These are all pretty old books, and you may have trouble finding them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might also try asking on Math.StackExchange.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Calling the derivation &quot;original research&quot; seems absurd, to me. It's a high-school homework problem in analytic geometry.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-07-11T14:30:23.097" LastActivityDate="2017-07-11T14:30:23.097" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5352" PostTypeId="2" ParentId="5349" CreationDate="2017-07-11T13:34:38.400" Score="0" Body="&lt;p&gt;Depending on the specific content of your input images, you could either use the Gaussian filter with kernel size varying with distance from the camera ( &lt;a href=&quot;https://en.wikipedia.org/wiki/Spatial_anti-aliasing&quot; rel=&quot;nofollow noreferrer&quot;&gt;Link&lt;/a&gt; ) or use a slightly more complex &lt;a href=&quot;http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;bilateral filter&lt;/a&gt;, which is widely used to eliminate noise while keeping edges mostly intact.&lt;/p&gt;&#xA;" OwnerUserId="2138" LastActivityDate="2017-07-11T13:34:38.400" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5353" PostTypeId="2" ParentId="4099" CreationDate="2017-07-12T12:37:42.457" Score="1" Body="&lt;p&gt;&lt;strong&gt;Books&lt;/strong&gt;&lt;br&gt;&#xA;Farin - Curves and Surfaces for CAGD&lt;br&gt;&#xA;Hoffman -- Geometric &amp;amp; Solid Modeling: An Introduction&lt;br&gt;&#xA;Hoschek &amp;amp; Lasser -- Fundamentals of Computer Aided Geometric Design&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Journals&lt;/strong&gt;:&lt;br&gt;&#xA;Computer Aided Design&lt;br&gt;&#xA;Computer Aided Geometric Design&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Conferences&lt;/strong&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://s3pm.icsi.berkeley.edu/s3pm/spm.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://s3pm.icsi.berkeley.edu/s3pm/spm.html&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;http://graphics.xmu.edu.cn/gmp2017/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphics.xmu.edu.cn/gmp2017/&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;http://www.siam.org/meetings/gd17/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.siam.org/meetings/gd17/&lt;/a&gt;   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Organizations&lt;/strong&gt;:&lt;br&gt;&#xA;&lt;a href=&quot;http://solidmodeling.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://solidmodeling.org/&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;http://www.siam.org/activity/gd/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.siam.org/activity/gd/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are &lt;strong&gt;plenty&lt;/strong&gt; of open problems.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-07-13T12:22:33.923" LastActivityDate="2017-07-13T12:22:33.923" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5354" PostTypeId="2" ParentId="5222" CreationDate="2017-07-12T13:01:46.553" Score="0" Body="&lt;p&gt;You need a position, and an orientation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Positions are easy, obviously -- just 3 coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are &lt;strong&gt;many&lt;/strong&gt; different ways to represent an orientation: start reading &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, or &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. The common ones are rotation matrices, quaternions, and Euler angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In theory, an orientation has only 3 degrees of freedom, so you ought to be able to represent it with three numbers. But representations that use 3 numbers inevitably have discontinuities or singularities (like &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Gimbal_lock&quot; rel=&quot;nofollow noreferrer&quot;&gt;gimbal lock&lt;/a&gt;&quot;), so using 4 numbers (e.g. a quaternion) is more practical.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-07-13T00:20:52.597" LastActivityDate="2017-07-13T00:20:52.597" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5355" PostTypeId="1" CreationDate="2017-07-13T01:58:54.427" Score="7" ViewCount="1340" Body="&lt;p&gt;As of lately I've been studying a bit of shaders (in Unity), and am trying to recreate the &quot;light-based inline&quot; that can be observed in the latest Legend of Zelda. But maybe the task is a bit above my knowledge, for now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8z0Ex.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8z0Ex.png&quot; alt=&quot;Annotated reference image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As from what I can analyze, it seems to behave (when moving) similar to what a &quot;rim shading&quot; does, except it has a sharp cutoff (simple to do), and — the part I'm struggling with — it seems to have a constant width independent from the local curvature of the mesh and distance from camera, essentially having a constant &quot;width&quot; in relation to the screen. (well it actually varies a bit with camera distance, but mostly it doesn't so let's assume it doesn't)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's a bit hard to show in a still, but you can find plenty videos on the game, and the effect is visible everywhere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've managed to do the simpler part, the cut-off rim shading. But this gives the awkward effect that depending on camera orientation and the geometry curvature, the &quot;inline&quot; occupies more or less screen area. Below is an image of the current results I get on various camera angles, with green arrows showing good/acceptable areas and red arrows demonstrating deviation from the intended effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dnPyb.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dnPyb.png&quot; alt=&quot;Current output with annotated good/bads&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my current implementation for reference, as a Unity Surface Light Model:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;half4 LightingToonPoster(SurfaceOutputStandard surf, float3 viewDir, UnityGI gi) {&#xA;    // Material properties&#xA;    half3 specular;&#xA;    half oneMinusReflectivity;&#xA;    DiffuseAndSpecularFromMetallic(surf.Albedo, surf.Metallic, /*out*/ specular, /*out*/ oneMinusReflectivity);&#xA;    float3 reflected = normalize(-reflect(gi.light.dir, surf.Normal));&#xA;    float specularity = dot(viewDir, reflected) * _Specularity;&#xA;&#xA;    // Light setup&#xA;    float ndotl = dot(surf.Normal, gi.light.dir) * 0.5 + 0.5;&#xA;    float lightIncidence = gi.light.color * ndotl;&#xA;    float3 ramp = tex2D(_Ramp, lightIncidence.xx).rgb;&#xA;    float3 specularRamp = tex2D(_Ramp, specularity.xx).rgb;&#xA;    gi.light.color = ramp * _LightColor0.rgb;&#xA;&#xA;    // Rim and camera-light convergence&#xA;    float rim = 1 - saturate(dot(surf.Normal, viewDir));&#xA;    float facing = -dot(viewDir, gi.light.dir) * 0.5 + 0.25;&#xA;&#xA;    // sigmoid of rim for smooth falloff centered at _EdgeBias&#xA;    float outline = 1 / (1 + exp(-100 * (rim - _EdgeBias)));&#xA;    float highlight = _HighlightStrength * outline * facing * outline;&#xA;&#xA;    float4 std = LightingStandard(surf, viewDir, gi);&#xA;&#xA;    float3 toonDiffuse = surf.Albedo * (gi.light.color / 2 + ShadeSH9(float4(viewDir, 1)));&#xA;    float3 toonSpecular = specular * gi.indirect.specular * specularRamp;&#xA;    float4 toon = half4(toonDiffuse + toonSpecular, surf.Alpha);&#xA;    return lerp(std, toon, _UnshadeFactor) * half4(1 + highlight.xxx, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/kroltan/8eb8ba213dfeea14fde694c967630ae2&quot; rel=&quot;noreferrer&quot;&gt;Or check this Gist for the full shader file&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question now being, what can I use instead of rim-shading to obtain a similar effect, where the curvature is not taken into account and I get a constant &quot;inset&quot;?&lt;/p&gt;&#xA;" OwnerUserId="6986" LastActivityDate="2017-07-13T08:11:16.030" Title="Constant screen-space-width rim shading" Tags="&lt;shader&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5356" PostTypeId="2" ParentId="5355" CreationDate="2017-07-13T08:11:16.030" Score="3" Body="&lt;p&gt;Nice question! I hadn't seen the game myself but this question got me interested so I watched some footage on Youtube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This one for example gives a good view of it: &lt;a href=&quot;https://youtu.be/Ktjdg3zgRzk?t=15m46s&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/Ktjdg3zgRzk?t=15m46s&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/hEUiR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hEUiR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few things I notice:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Hair and right leg: note how only the diffuse lit part has rim lighting.&lt;/li&gt;&#xA;&lt;li&gt;Left wrist: note how the width becomes thinner at the angle with the hand.&lt;/li&gt;&#xA;&lt;li&gt;On some other part you can also see the rim lighting is affected by cast shadows too. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;From these observations, I think there are two effects used:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;A diffuse shading with a sharp transition between lit a unlit, that happens somewhere below 0 so the light leaks behind a little.&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The rim lighting that, as you mention, has an almost constant screenspace width.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the look of it and some of the artifacts, my best guess is that it's actually some edge detection filter based on depth, which is then used in combination with the diffuse lighting so the rim lighting doesn't affect the unlit parts.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;It's a pretty cool effect, thank you for point it out!&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2017-07-13T08:11:16.030" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5357" PostTypeId="1" CreationDate="2017-07-13T08:38:24.073" Score="2" ViewCount="410" Body="&lt;p&gt;I've implemented a ping pong rendering that does something according to constraints on the current fragment :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(1) The value of the fragment depth is equal to the median of neighbors depth values&#xA;(2) the value of the fragment depth is equal to a weighted sum of neighbors depth values&#xA;(3) The point is black&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll say that the easier part is the (3), but for the 2 others (1) and (2), I have optimization problems (my FPS drop to 1.2 when I use it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I do, is if we're in case (1) or (2) I fill an array with all neighbors values that are valid (not the background).&#xA;for (1), I use Niklaus_wirth algorithm to sort the array and take the median value.&#xA;For (2), I calculate the weigth for each neighbors and then do a Sum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since i'm not very used to work with GPUs, the ways to optimize my program are not known by me. I checked several tuto to improve a shader code, but couldn't find something that fit with me :/ (I saw that I have to remove the most if statement possible, but don't find any ways to do it...)&#xA;Here's the code :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 PingPongDepth() {&#xA;    return texture(fillingTexDepth, TexCoords).xyz;&#xA;}&#xA;&#xA;//I do the pingpong around &quot;fillingTexDepth&quot;. The next function give me the 3-neighbourhood of the current fragment.&#xA;vec3 PingPongDepth(int i) {                                                     &#xA;    int x = i % 3;&#xA;    int y = i / 3;&#xA;&#xA;    int rx = x - 1;&#xA;    int ry = 1 - y;&#xA;&#xA;    return texture(fillingTexDepth, TexCoords + vec2(rx*dx, ry*dy)).xyz;&#xA;}&#xA;//I Put values in my array if they are valid neighbors&#xA;void PutInArray() {&#xA;for (int i = 0; i &amp;lt; 9; ++i) {&#xA;    //We don't want to take the current fragment in the calculus&#xA;    if (i != 4) {&#xA;        vec3 pIDepth = PingPongDepth(i);&#xA;        if (isValid(pIDepth)) {&#xA;            xArray[xSize] = pIDepth.x;&#xA;            xSize++;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and then, for (1):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void xSwap(int a, int b) {&#xA;     float tmp = xArray[a];&#xA;    xArray[a] = xArray[b];&#xA;    xArray[b] = tmp;&#xA;}&#xA;&#xA;&#xA;void kth_smallest(int k) {&#xA;    int i, j, l, m;&#xA;    float x;&#xA;&#xA;    l = 0;&#xA;    m = xSize - 1;&#xA;    while (l &amp;lt; m) {&#xA;        x = xArray[k];&#xA;        i = l;&#xA;        j = m;&#xA;        do {&#xA;            while (xArray[i] &amp;lt; x) i++;&#xA;            while (x &amp;lt; xArray[j]) j--;&#xA;            if (i &amp;lt;= j) {&#xA;                xSwap(i, j);&#xA;                i++; j--;&#xA;            }&#xA;        } while (i &amp;lt;= j);&#xA;        if (j &amp;lt; k) l = i;&#xA;        if (k &amp;lt; i) m = j;&#xA;    }&#xA;//retDepth is the vec4 that is returned by my shader&#xA;retDepth = vec4(vec3(xArray[k], 0.0f, 0.0f), 1.0f);&#xA;}&#xA;&#xA;void Median_NW(vec3 vDepth, vec3 vCol) {&#xA;    if (xSize == 0) {&#xA;        retDepth = vec4(vDepth, 1.0f);&#xA;        retColor = vec4(vCol, 1.0f);&#xA;        return;&#xA;    }&#xA;    else if (xSize == 1) {&#xA;        retDepth = vec4(vec3(xArray[0], 0.0f, 0.0f), 1.0f);&#xA;        return;&#xA;    }&#xA;    else&#xA;       kth_smallest(xSize / 2);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and for (2)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float xWeight_(vec3 v, int i, float sigma) {&#xA;    float rI = (i % 2 == 0) ? 1.4142 : 1.0;&#xA;&#xA;    return (1.0f - 0.5*rI )*(1 - min(1, abs(xArray[i] - v.x) / sigma));&#xA;}&#xA;&#xA;void WeightedSum(vec3 vDepth, vec3 vCol) {&#xA;    if (xSize == 0) {&#xA;        retDepth = vec4(vDepth, 1.0f);&#xA;        return;&#xA;    }&#xA;    float weightedDepth = 0.0f;&#xA;    float xSum = 0.0f;&#xA;&#xA;    for (int i = 0; i &amp;lt; xSize; ++i) {&#xA;        float w_ = xWeight_(vDepth, i, 2.0f);&#xA;        weightedDepth += xArray[i] * w_;&#xA;        xSum += w_;&#xA;    }&#xA;    retDepth = vec4(vec3(weightedDepth, 0.0f, 0.0f) / xSum, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If someone have an idea... (sorry for the long post)&lt;/p&gt;&#xA;" OwnerUserId="6662" LastActivityDate="2017-07-13T08:38:24.073" Title="fragment shader median/weigthed sum of neighbors depth values (optimization)" Tags="&lt;opengl&gt;&lt;optimisation&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5358" PostTypeId="1" CreationDate="2017-07-14T10:46:23.170" Score="2" ViewCount="47" Body="&lt;p&gt;CNT is a promising new material, which &lt;a href=&quot;https://en.wikipedia.org/wiki/Carbon_nanotube#Electrical&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt; describes as such:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Carbon nanotubes (CNTs) are allotropes of carbon with a cylindrical nanostructure. These cylindrical carbon molecules have unusual properties, which are valuable for nanotechnology, electronics, optics and other fields of materials science and technology. Owing to the material's exceptional strength and stiffness, nanotubes have been constructed with length-to-diameter ratio of up to 132,000,000:1, significantly larger than for any other material.&lt;/p&gt;&#xA;&lt;p&gt;In addition, owing to their extraordinary thermal conductivity, mechanical, and electrical properties, carbon nanotubes find applications as additives to various structural materials.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;For this reason, the name carbon nanotubes appear from time to time in various works of science fiction, and I too want to use CNT in a science fiction game, set in the near future which I am making, since I am trying to achieve some degree of photorealistic graphic, I will, however, need to know what CNT will look like.&lt;/p&gt;&#xA;&lt;p&gt;specifically, I want to know which of the two main categories of solid, non-transparent material surfaces commonly used in physically based rendering CNT would fall under.&lt;/p&gt;&#xA;&lt;p&gt;as &lt;a href=&quot;https://www.marmoset.co/posts/basic-theory-of-physically-based-rendering/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; article on PBR computer graphics explains,&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;»Electrically conductive materials, most notably metals« look quite different from other materials.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Which is why it often is sufficient to assume that the most common materials in the world are either &lt;em&gt;metallic&lt;/em&gt; or &lt;em&gt;dielectric&lt;/em&gt;/&lt;em&gt;insulating&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Given that CNT by Wikipedia is described as:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Unlike graphene, which is a two-dimensional semimetal, carbon&#xA;nanotubes are either metallic or semiconducting&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I first assumed was that I should treat CNT as a metal, but I am not certain if CNT has other properties which would make it look significantly different from metal.&lt;/p&gt;&#xA;&lt;p&gt;My question is, therefore, is it a fair approximation to render carbon nanotubes using a metallic shader? or would it be better to render it as an insulator? Edit 1: and would CNT look anisotropic.&lt;/p&gt;&#xA;&lt;p&gt;Edit 0: So it looks like we actually already have some macroscopic CNT structures, but I really can't tell whether or not this looks metallic or not:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aSvgK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aSvgK.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6991" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-07-14T10:51:40.790" Title="Would the surface of a large carbon-nanotupe structure look metalic?" Tags="&lt;physically-based&gt;&lt;material&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5359" PostTypeId="1" CreationDate="2017-07-14T11:10:24.710" Score="1" ViewCount="305" Body="&lt;p&gt;I have the 8 vertices of a cuboid (red points)(XYZvox) with known distance in millimetres (vox to mm) between each vertex which I transform in 3d space using the 4d transformation matrix (M). I am really struggling to work out the new voxel to millimetre conversion for the transformed vertices. How can I work this out? I feel it should be relatively straightforward:&lt;a href=&quot;https://i.stack.imgur.com/o3jR7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o3jR7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;XYZvox =[ 1     1     1     1   409   409   409   409&#xA;     1     1   389   389     1     1   389   389&#xA;     1   162     1   162     1   162     1   162]&#xA;&#xA;M =[0.0337    0.0958   -0.9616   -2.5360&#xA;    0.3706    0.0107    0.1012 -150.2009&#xA;    0.0201   -0.3571   -0.2550 -231.0513&#xA;         0         0         0    1.0000]&#xA;&#xA;for i=1:8&#xA;&#xA;poi1=XYZvox(:,i);&#xA;poi2=[XYZvox(:,i)];&#xA;poi2(4,1)=1;&#xA;&#xA;poi_trans=M*poi2;&#xA;&#xA;poi_trans=poi_trans(1:3);&#xA;&#xA;scatter3(poi1(1),poi1(2),poi1(3),'red','filled'); xlabel('x'); hold all;&#xA;scatter3(poi_trans(1),poi_trans(2),poi_trans(3),'green','filled'); xlabel('x'); ylabel('y'); zlabel('z'); &#xA;&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6990" LastActivityDate="2017-07-14T11:10:24.710" Title="Applying 3d transformation to cuboid" Tags="&lt;3d&gt;&lt;affine-transformations&gt;&lt;matlab&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5360" PostTypeId="1" CreationDate="2017-07-14T14:37:00.287" Score="3" ViewCount="183" Body="&lt;p&gt;I was looking into measuring the amount of aliasing in an image. After reading through many papers and sites, I came to the conclusion that the best method to measure the amount of aliasing in an image is by utilizing the frequency domain. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a relationship between spatial frequency of an image and aliasing? &#xA;Also, is there any other metric that one can use to measure the amount of aliasing that is present in an image?&lt;/p&gt;&#xA;" OwnerUserId="6974" LastEditorUserId="231" LastEditDate="2017-07-15T12:40:44.607" LastActivityDate="2017-07-15T12:40:44.607" Title="Relationship between spatial frequency of an image and Aliasing" Tags="&lt;image-processing&gt;&lt;antialiasing&gt;&lt;image-comparison&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5361" PostTypeId="2" ParentId="5360" CreationDate="2017-07-14T15:32:26.470" Score="7" Body="&lt;p&gt;Like in any other kind of signal processing, the relationship is Nyquist's theorem. An image is a discrete sequence of samples of a continuous signal. If the original signal has frequency components higher than half the sampling rate, then there will be aliasing. To put that another way, if you look at the real-world size of a pixel, any details smaller than two pixels wide will be aliased. This applies to synthetic images as well as to photographs. If you define a procedural texture via a mathematical function, the function is continuous but you only evaluate it at certain points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is, of course, if you only have the sampled image and not the original signal, the high-frequency components have &lt;em&gt;already&lt;/em&gt; been aliased, so you can't measure them directly. You have to use statistical techniques to guess which details in your aliased image were originally higher-frequency signals.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-07-14T15:32:26.470" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5362" PostTypeId="1" CreationDate="2017-07-14T19:00:06.583" Score="3" ViewCount="90" Body="&lt;p&gt;On the &lt;a href=&quot;https://www.allegorithmic.com/products/bitmap2material/&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Bitmap2Material&quot;&gt;main page&lt;/a&gt; for Allegorithmic's Bitmap2Material, it mentions that the software uses a &lt;strong&gt;Slope Based&lt;/strong&gt; approach over a &lt;strong&gt;Luminance Based&lt;/strong&gt; approach. What exactly does this mean?&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-07-14T19:00:06.583" Title="Slope Based Texturing" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;image-processing&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5363" PostTypeId="1" CreationDate="2017-07-15T07:09:41.110" Score="-2" ViewCount="58" Body="&lt;p&gt;I have a bounding box of 1000m x 1000m. I randomly generate 10000 points (sites) inside it. Now, how can I create 'n' polygons (geometries) within the bounding box based on a given constrain. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The constrain could be anything. For example:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;number of sites inside each polygon are same for all polygons&lt;/li&gt;&#xA;&lt;li&gt;sum of distances from points inside the geometry to the centroid of geometry are same for all polygons&lt;/li&gt;&#xA;&lt;li&gt;let's say, I assign a weight to each site then constrain i sum of weights inside each polygon are same for all polygons &lt;/li&gt;&#xA;&lt;li&gt;area of each polygon is same&lt;/li&gt;&#xA;&lt;li&gt;etc.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Is there a way to generate such a geometry?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. -- would be great if someone can also point me in the right direction and then give down vote.  &lt;/p&gt;&#xA;" OwnerUserId="6994" LastEditorUserId="6994" LastEditDate="2017-07-15T12:49:28.720" LastActivityDate="2017-07-17T19:57:09.087" Title="constrain based dynamic geometry generation" Tags="&lt;geometry&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2017-07-24T02:02:37.330" ContentLicense="CC BY-SA 3.0" />
  <row Id="5364" PostTypeId="2" ParentId="5186" CreationDate="2017-07-15T09:23:39.413" Score="4" Body="&lt;p&gt;Imagine that a black dot represents a value of -1 whereas a white dot represents a value of +1. You are looking for the iso-line(s) where each point upon the line is 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this example you could either place the iso-lines like on the left or the right:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IMlTY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IMlTY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; or &lt;a href=&quot;https://i.stack.imgur.com/mALSW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mALSW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference between the solutions is the value in the center. In the left case we assume 1s whereas in the right solution we assume -1s. So we check the center value and based on that value decide which solution fits best. If the center value is 1, we pick the left solution. If the center value is -1, we choose the right solution.&lt;/p&gt;&#xA;" OwnerUserId="6124" LastActivityDate="2017-07-15T09:23:39.413" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5365" PostTypeId="2" ParentId="5300" CreationDate="2017-07-15T09:51:23.973" Score="1" Body="&lt;p&gt;Very often, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Lab_color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lab&lt;/a&gt; color space is used, since it is close to how humans perceive color. As to which distance to apply: This &lt;a href=&quot;https://en.wikipedia.org/wiki/Color_difference#LAB_Delta_E&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia article&lt;/a&gt; mentions a Delta E distance of 1.0 for a just noticeable difference. There are a lot of different formulas resulting in different thresholds.&lt;/p&gt;&#xA;" OwnerUserId="6124" LastActivityDate="2017-07-15T09:51:23.973" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5366" PostTypeId="2" ParentId="5300" CreationDate="2017-07-15T21:12:39.003" Score="1" Body="&lt;p&gt;I find the hue/saturation or luminance/chrominance spaces to be fairly easy to work in. They follow our intuitive sense of how color works, even if they're not as scientifically accurate as Lab is. The &lt;a href=&quot;https://en.wikipedia.org/wiki/YCbCr#YCbCr&quot; rel=&quot;nofollow noreferrer&quot;&gt;conversion from RGB to YCbCr&lt;/a&gt; is a simple matrix multiply. Working in YCbCr would allow you to do things like keep luminance constant while changing hue and/or saturation. You can think of saturation as the distance of the color from the luminance axis (so just the magnitude of CbCr = sqrt(Cb x Cb + Cr x Cr)). The hue is the angle the color point makes with the x-axis when projected onto the CbCr plane. (So you can use atan2(Cr, Cb).) Once you've modified your values, converting back to RGB is another matrix multiply.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-07-15T21:12:39.003" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5367" PostTypeId="1" AcceptedAnswerId="5369" CreationDate="2017-07-16T03:44:51.177" Score="2" ViewCount="154" Body="&lt;p&gt;This is something that pops up on my mind once a while when I browse around the web for art and desktop wallpaper, since I tend to see JPG and PNG as the common formats. I just had to ask to get it off my mind, hopefully I've posted in the correct stackexchange domain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm sure many computer users who are aware that PNG is a lossless computer image format (doesn't lose quality) while JPG is a lossy format (losses quality).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After researching. I've found that PNG has been out since 1995 and the size of computer storage has drastically increased since then. Even if image resolution and file size increases, I'm sure anyone can store over 100,000+ PNG images on a single hard drive today.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Personally when I look for art. I make sure I get the highest resolution available as a PNG. I'm aware converting from JPG to PNG will still have the lossy image detail from being a JPG.&lt;/p&gt;&#xA;" OwnerUserId="6998" LastActivityDate="2017-07-16T16:08:29.740" Title="Why isn't PNG preferred over JPG for being lossless art quality yet?" Tags="&lt;image-comparison&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5368" PostTypeId="1" AcceptedAnswerId="5371" CreationDate="2017-07-16T04:14:11.153" Score="2" ViewCount="405" Body="&lt;p&gt;I am trying to draw a triangle.  Here is my code:&#xA;    const char* vertexShaderSource = &quot;#version 330 core\n&quot;&#xA;        &quot;layout (location = 0) in vec3 aPos;\n&quot;&#xA;        &quot;void main()\n&quot;&#xA;        &quot;{\n&quot;&#xA;        &quot;   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n&quot;&#xA;        &quot;}\0&quot;;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const char* fragmentShaderSource = &quot;#version 330 core\n&quot;&#xA;    &quot;out vec4 FragColor;\n&quot;&#xA;    &quot;void main()\n&quot;&#xA;    &quot;{\n&quot;&#xA;    &quot;   FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n&quot;&#xA;    &quot;}\n\0&quot;;&#xA;&#xA;GLfloat vertices[] = {&#xA;    -0.5f, -0.5f, 0.0f,&#xA;    0.5f, -0.5f, 0.0f,&#xA;    0.0f,  0.5f, 0.0f&#xA;};&#xA;&#xA;// Create the VAO&#xA;GLuint vao;&#xA;GLuint buffer;&#xA;&#xA;glGenBuffers(1, &amp;amp;buffer);&#xA;glBindBuffer(GL_ARRAY_BUFFER, buffer);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&#xA;glGenVertexArrays(1, &amp;amp;vao);&#xA;glBindVertexArray(vao);&#xA;glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);&#xA;glEnableVertexAttribArray(0);&#xA;glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;glBindVertexArray(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This results in the following image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7uGSN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7uGSN.png&quot; alt=&quot;triangle&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, trying to use newer, DSA type methods does not draw the correct triangle.  If I switch my code to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glCreateBuffers(1, &amp;amp;buffer);&#xA;glNamedBufferStorage(buffer, sizeof(vertices), vertices, 0);&#xA;&#xA;glCreateVertexArrays(1, &amp;amp;vao);&#xA;glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(GLfloat) * 3);&#xA;glVertexArrayAttribBinding(vao, 0, 0);&#xA;glEnableVertexArrayAttrib(vao, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I get this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1hBov.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1hBov.png&quot; alt=&quot;squished triangle&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The triangle is squished.  In fact, changing any of the coordinates of the last row of vertices (the point that is squished) do not change the image result.  Why is this happening?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-04-30T18:42:01.773" LastActivityDate="2018-04-30T18:42:01.773" Title="Different result with DSA (vertexArrayVertexBuffer, vertexArrayAttribBinding) than with glBufferData" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5369" PostTypeId="2" ParentId="5367" CreationDate="2017-07-16T12:07:48.543" Score="5" Body="&lt;p&gt;I don't know if this is the real reason, but here's one possibility: because it's unnecessary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's easy to say &quot;JPEG = lossy = bad&quot;, but JPEG doesn't just destroy image quality willy-nilly. What the format gives you is a slider with &quot;small, low-quality&quot; at one end and &quot;big, high-quality&quot; at the other. You can easily reduce the byte size of a PNG image by encoding it as JPEG, and if you use the high-quality end of the slider, you needn't lose any &lt;strong&gt;visual&lt;/strong&gt; appeal. Although normal JPEG is &lt;em&gt;lossy&lt;/em&gt; in the information-theoretic sense, a high-quality JPEG appears identical by the naked eye.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many image hosting sites will replace images by lower-quality JPEG files not because of the storage cost but because of the &lt;strong&gt;bandwidth&lt;/strong&gt; cost. If you're serving millions of views of these files every day, the cost of sending those extra bytes is pretty big, even though the cost of storing them is tiny. And those bytes don't just cost money: they also cost load time for your users on mobile networks. These sites will have targets for how long their pages take to load on slow connections, and reducing the quality slider ever so slightly makes a big total difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In summary, JPEG encoding can be lossless or lossy, and it can be as high- or low-quality as you want. Using PNG everywhere instead of JPEG would be costly for image sites and would make you wait longer for your art files to download. Choosing a high-quality JPEG file can give you something that looks just the same as the PNG without being as &quot;heavy&quot;.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-07-16T12:07:48.543" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5370" PostTypeId="2" ParentId="5367" CreationDate="2017-07-16T13:12:33.443" Score="4" Body="&lt;p&gt;Lossy does not necessarily imply any major quality loss. It is mostly dropping out meaningless information of the image in favor a much smaller image file. The amount of quality drop can be adjusted, and in best case scenario this is done so that the quality drop is just invisible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In exchange for this quality drop you get quite big file size savings. And for most part the quality drop just makes reusing the image for future edits harder. While this may sound bad, its actually a good thing for the author. The original author will store a master file that has not been compressed, thus making it harder for others to reclaim your work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also quite many times the image starts its life as a JPEG, as quite many cameras only allow output of JPEG files, because the other  option is HUGE files.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now it should be mentioned that JPEG only works well for photographic content. For synthetic images like logos PNG fares much better than jpeg in because the image has less variation. Also PNG does not guarantee lossless compression as you can preprocess the image for some compression gain, and often do so.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-07-16T16:08:29.740" LastActivityDate="2017-07-16T16:08:29.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5371" PostTypeId="2" ParentId="5368" CreationDate="2017-07-16T16:16:17.923" Score="3" Body="&lt;p&gt;You forgot to call &lt;code&gt;glVertexArrayAttribFormat&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glCreateBuffers(1, &amp;amp;buffer);&#xA;glNamedBufferStorage(buffer, sizeof(vertices), vertices, 0);&#xA;&#xA;glCreateVertexArrays(1, &amp;amp;vao);&#xA;glEnableVertexArrayAttrib(vao, 0);&#xA;glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0);&#xA;&#xA;glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(GLfloat) * 3);&#xA;glVertexArrayAttribBinding(vao, 0, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-07-16T16:16:17.923" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5372" PostTypeId="2" ParentId="5363" CreationDate="2017-07-16T22:52:41.590" Score="3" Body="&lt;p&gt;It is possible to generate geometry from constraints. However, some of your constraints are hard to formulate as continuous functions that can be minimized or maximized. Also the ones that can be  formulated this way have a staggering number of dimensions making gradient descents quite costly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means, you can not use a gradient descent method to find the solution. In turn this makes the problem computationally harder to do as the only way to do so is by trying a number of solutions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you would need to take some points by initial condition then solve for the constraints that can be made continuous. And then reevaluate if no solution is found. So some genetic algorithm should work fine, although it would be very inefficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But more likely your looking for some sort of clustering solutions. But if i were to do this with this vague instructions (which would surely fail) i would start by building a voronoi diagram, as it would help me find the connectivity. &lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-07-17T19:57:09.087" LastActivityDate="2017-07-17T19:57:09.087" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5373" PostTypeId="1" AcceptedAnswerId="5395" CreationDate="2017-07-17T14:30:50.300" Score="8" ViewCount="1146" Body="&lt;p&gt;I am currently working with Earl Hammon Jr's Presentation &lt;a href=&quot;http://twvideo01.ubm-us.net/o1/vault/gdc2017/Presentations/Hammon_Earl_PBR_Diffuse_Lighting.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBR Diffuse Lighting for GGX+Smith Microsurfaces&lt;/a&gt; (now mentioned as [PBR, p.XYZ] and have read through (among others) Brent Burley's &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically-Based Shading at Disney&lt;/a&gt; (now mentioned as [DIS, p. XYZ] to get a good diffuse BRDF component. I am stuck at combining the two with the Fresnel Term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Short introduction for vectors and angles as I use them:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$\omega_i$ is the light vector&lt;/li&gt;&#xA;&lt;li&gt;$\omega_o$ is the view vector&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$\omega_n$ is the macro geometry normal&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;$\theta_i$ is the angle between $\omega_i$ and $\omega_n$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;$\theta_o$ is the angle between $\omega_o$ and $\omega_n$&lt;/li&gt;&#xA;&lt;li&gt;$\theta_h$ is the angle between $\omega_n$ and $\omega_h$&lt;/li&gt;&#xA;&lt;li&gt;$\alpha_{hi}$ is the angle between $\omega_i$ and $\omega_h$ &lt;/li&gt;&#xA;&lt;li&gt;$\alpha_{ho}$ is the angle between $\omega_o$ and $\omega_h$ (this distinction is for clarification)&lt;/li&gt;&#xA;&lt;li&gt;$\alpha_h$ is any of the angles $\alpha_{hi}$, $\alpha_{ho}$, since they are equal&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;now given that $r_s$ is the BRDF term of the specular component without the fresnel factor and $r_d$ accordingly the term of the diffuse component without the fresnel stuff, the fresnel factor is written as $F(angle)$. &#xA;[PBR, p.105] mentions that the diffuse light is transmitted two times, once in and once out. Thus, the Fresnel component has to be multiplied two times. &#xA;[PBR, p. 106] goes on to say Fresnel's laws are symmetrix, meaning entering and leaving is direction independent (i.e. it does not matter that once we go into the material from air and once we leave into air). Now I would assume (for $F_1$ is Fresnel for entering and $F_2$ is for Fresnel leaving the material) to use &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(1-F_1(\alpha_{hi}))*(1-F_2(\alpha_{ho}))$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$F_1$ and $F_2$ are the same function, and $\alpha_{hi}$ and $\alpha_{ho}$ are the same angle, therefore&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(1-F(\alpha_h))^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This would lead to a brdf $f$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f = F(\alpha_h) * r_s + (1-F(\alpha_h))^2 * r_d$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But both [PBR, p.113] and [DIS, p.14] use &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f = F(\alpha_h) * r_s + (1-F(\theta_i))*(1-F(\theta_o)) * r_d$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as does the original paper to use this kind of calculation by Shirely et al. 1997.&#xA;I just don't get this, why do they change from the microfacet angles to the macro angles? The microfacet angles lead to energy conversation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$F \in [0, 1]$ &#xA;$\Rightarrow(1-F) \in [0, 1] $&#xA;$\Rightarrow(1-F)^2 \in [0, 1]$ and $(1-F(\alpha_h)) &amp;gt;= (1-F(\alpha_h))^2)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;it should be reciprocal&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f(\theta_i, \theta_o) &#xA;= F(\alpha_{hi}) * r_s + (1-F(\alpha_{hi}))*(1-F(\alpha_{ho}) * r_d&#xA;= F(\alpha_h) * r_s + (1-F(\alpha_h))^2 * r_d&#xA;= F(\alpha_{ho}) * r_s + (1-F(\alpha_{ho}))*(1-F(\alpha_{hi})) * r_d&#xA;= f(\theta_o, \theta_i)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and thus fulfill BRDF requirements. The microfacet angle is used for the specular term, therefore it is the more sensible thing to interpolate between specular and diffuse component (ignoring the fact of two transmissions for this argument).&#xA;Instead, [PBR, p.113] and [DIS, p. 14] put the $\theta_h$ into a roughness calculation and leave that rather unexplained.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally to my confusion about this, in the explanation slides [PBR, p.187] uses the dot product $\omega_h * \omega_o$ (and therefore the $\alpha_{ho}$ angle) and later on [PBR, p. 191] also the dot product $\omega_h *  \omega_i$ ($\Rightarrow\alpha_{hi}$).&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2018-07-23T08:11:37.200" LastActivityDate="2021-01-25T11:45:22.043" Title="Why is the half vector not used in diffuse BRDF Fresnel calculations?" Tags="&lt;brdf&gt;&lt;pbr&gt;&lt;diffuse&gt;&lt;fresnel&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="5374" PostTypeId="1" AcceptedAnswerId="5376" CreationDate="2017-07-18T01:30:10.600" Score="2" ViewCount="1497" Body="&lt;p&gt;I have been learning OpenGL 3.3 and I saw this expression:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_Position = projection * view * model * vertex&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am confused because I read in some book that if the vector (vertex) is placed on the right side of the matrix then it would be a column vector and to transform this vector you should have a column major matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But glm library follows GLSL right. So I printed the &lt;code&gt;glm::mat4&lt;/code&gt; and it was a row-major matrix.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastEditorUserId="231" LastEditDate="2017-07-18T12:08:30.813" LastActivityDate="2017-07-18T12:08:30.813" Title="Why do we multiply vertex from left side in vertex shader with matrices?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;matrix&gt;&lt;legacy-opengl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5375" PostTypeId="2" ParentId="5374" CreationDate="2017-07-18T03:17:51.180" Score="5" Body="&lt;p&gt;OpenGL uses column-major matrices. For example, the translation values will be in the last row rather than the last column of the matrix. For example when loading matrices into uniforms in glsl, the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glUniform.xml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glUniformMatrix4fv()&lt;/code&gt; function&lt;/a&gt; takes its matrix parameters in column-major order:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Each matrix is assumed to be supplied in column major order.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In glm, the matrices are also in column-major order. From the &lt;code&gt;matrix_transform.hpp&lt;/code&gt; header, the comment for the &lt;code&gt;translate()&lt;/code&gt; method says this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/// #include &amp;lt;glm/glm.hpp&amp;gt;&#xA;/// #include &amp;lt;glm/gtc/matrix_transform.hpp&amp;gt;&#xA;/// ...&#xA;/// glm::mat4 m = glm::translate(glm::mat4(1.0f), glm::vec3(1.0f));&#xA;/// // m[0][0] == 1.0f, m[0][1] == 0.0f, m[0][2] == 0.0f, m[0][3] == 0.0f&#xA;/// // m[1][0] == 0.0f, m[1][1] == 1.0f, m[1][2] == 0.0f, m[1][3] == 0.0f&#xA;/// // m[2][0] == 0.0f, m[2][1] == 0.0f, m[2][2] == 1.0f, m[2][3] == 0.0f&#xA;/// // m[3][0] == 1.0f, m[3][1] == 1.0f, m[3][2] == 1.0f, m[3][3] == 1.0f&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that the translation amount (1,1,1) is in the last row rather than the last column.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-07-18T03:17:51.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5376" PostTypeId="2" ParentId="5374" CreationDate="2017-07-18T07:58:37.583" Score="6" Body="&lt;p&gt;There is no 100% consensus on what order matrix multiplication should model things, worse the industry is split along this. Some sources use row major and some sources use column major matrices. Great care should be taken to verify which is being used in your source and what is being used by your API!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some API's go as far as allowing one to multiply vectors on both sides of the matrix. The wisdom is thus in reading your API reference and verifying how it works. Old, fixed pipeline OpenGL and glm, does in fact use column major matrices. While (&lt;strong&gt;warning&lt;/strong&gt;) DirectX had chosen to use row major matrices [&lt;a href=&quot;http://www.mindcontrol.org/~hplus/graphics/matrix-layout.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;source&lt;/a&gt;]. Obviously with programmable shaders any application can have any order, even mixed one&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Due to fundamental properties of matrices this duality is the same as transposing the matrix. If you transpose the matrix you reverse the order of calculation, as you are now thinking outside in instead of inside out or vice versa.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The moral of the story is that you should always check your assumptions. And just printing out values does not always help as the printing function can screw things up, and memory not aligned the same way. Also simple testing may make you blind to having mixed conventions inside your program. &lt;strong&gt;Read what convention is in use&lt;/strong&gt;! Because, as confusing as having two sources with different  conventions is, it pales in comparasion to a piece of software that mixes the two in the codebase.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-07-18T08:34:18.817" LastActivityDate="2017-07-18T08:34:18.817" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5377" PostTypeId="1" AcceptedAnswerId="5380" CreationDate="2017-07-18T09:18:07.740" Score="11" ViewCount="732" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/49rn8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/49rn8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;I have 3 vertices &lt;code&gt;(V1, V2, V3)&lt;/code&gt; randomly selected on a regular triangle mesh. For these 3 vertices, I have computed the geodesic distance and the path (by using Dijkstra) among them and formed a triangle-like surface as in the above figure. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I have the vertices that lie in each path and can compute geodesic distances from a given vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I want to do is to get the vertices or triangles that lies in triangle-like area. How can I do this?&lt;/p&gt;&#xA;" OwnerUserId="7013" LastEditorUserId="7013" LastEditDate="2017-07-18T12:57:17.630" LastActivityDate="2017-07-21T10:38:37.857" Title="How can I perform a triangle inside test in polygon meshes?" Tags="&lt;mesh&gt;&lt;triangulation&gt;" AnswerCount="3" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5378" PostTypeId="2" ParentId="5377" CreationDate="2017-07-18T12:22:01.350" Score="2" Body="&lt;p&gt;I think you can calculate some surface-bound barycentric coordinates for each point on the surface, and then use them to check for inside or outside of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't have an exact algorithm at hand but I found this following paper which does seem to handle exactly this kind of coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.cct.lsu.edu/~swan2/Reference/DifferentialGeom/papers/BaryCoordonSurf_Rustamov2010SGP.pdf&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Barycentric Coordinates On Surfaces&quot;&gt;Barycentric Coordinates On Surfaces&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="273" LastActivityDate="2017-07-18T12:22:01.350" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5379" PostTypeId="1" AcceptedAnswerId="5388" CreationDate="2017-07-18T18:32:50.670" Score="4" ViewCount="860" Body="&lt;p&gt;When using the &lt;a href=&quot;http://glad.dav1d.de/&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLAD&lt;/a&gt; web service, I am allowed to pick any version of OpenGL and any extensions I want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I pick the latest version of OpenGL and &quot;all extensions&quot;, will the header file returned by the Web Service &lt;code&gt;#define&lt;/code&gt; extensions on my machine that I do not actually have or does it just define those that exist?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, if I include the &lt;code&gt;GL_ARB_SHADER_CLOCK&lt;/code&gt; extension, on GLAD, does it get defined even if not available on the machine I use?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't see how it could be selectively defining extensions because the script is generated on a server ahead of time but I want to make sure that I am not trying to use unsupported extensions.&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2017-11-09T09:01:49.107" LastActivityDate="2018-11-07T04:30:57.190" Title="How do I include all extensions my system supports using GLAD?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5380" PostTypeId="2" ParentId="5377" CreationDate="2017-07-18T21:37:16.053" Score="4" Body="&lt;p&gt;There is an alternative method that relies on flood filling. First arrange your edge data into a loop where the edges are forming a counterclockwise loop. Then start at an arbitrary point on the loop and pick edges joining that point. Use the outbound boundary edge and cross it with the other outbound edge, if it points in the direction of the face normal then it's an edge to be included, if not discard it. From this edge continue until you hit a boundary edge, at which point you terminate the fill. Continue at a yet to be visited boundary edge vertex.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="231" LastEditDate="2017-07-19T22:05:00.340" LastActivityDate="2017-07-19T22:05:00.340" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5381" PostTypeId="1" AcceptedAnswerId="5382" CreationDate="2017-07-18T23:28:05.997" Score="1" ViewCount="656" Body="&lt;p&gt;My question is very similar to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4479/how-to-do-texturing-with-opengl-direct-state-access&quot;&gt;this one&lt;/a&gt; but the answers there did not help me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to use the DSA approach to bind textures and it is not working.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my attempt at the DSA code, which leads too all black in as my output:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint samplerName;&#xA;glCreateSamplers(1, &amp;amp;samplerName);&#xA;glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_S, GL_REPEAT);&#xA;glSamplerParameteri(samplerName, GL_TEXTURE_WRAP_T, GL_REPEAT);&#xA;glSamplerParameteri(samplerName, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glSamplerParameteri(samplerName, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;glBindSampler(0, samplerName);&#xA;&#xA;// Create texture&#xA;GLuint texture;&#xA;glCreateTextures(GL_TEXTURE_2D, 1, &amp;amp;texture);&#xA;glTextureStorage2D(texture, 1, GL_RGB, width, height);&#xA;glTextureSubImage2D(texture, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);&#xA;glTextureParameteri(texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glBindTextureUnit(0, texture);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I add these two lines from the older approach:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindTexture(GL_TEXTURE_2D, texture);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;it works so I do not think it is an issue with my sampler or my data. Does anybody have any advice here? &lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-04-30T18:41:31.870" LastActivityDate="2018-04-30T18:41:31.870" Title="How to use textures with DSA?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5382" PostTypeId="2" ParentId="5381" CreationDate="2017-07-19T00:25:35.180" Score="3" Body="&lt;p&gt;My issue was in the call to &lt;code&gt;glTextureStorage2D(texture, 1, GL_RGB, width, height);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexStorage2D.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;the man page&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;internalformat must be one of the sized internal formats given in Table 1 below, one of the sized depth-component formats GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT24, or GL_DEPTH_COMPONENT16, one of the combined depth-stencil formats, GL_DEPTH32F_STENCIL8, or GL_DEPTH24_STENCIL8, or the stencil-only format, GL_STENCIL_INDEX8&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Changing &lt;code&gt;GL_RGB&lt;/code&gt; to &lt;code&gt;GL_RGB8&lt;/code&gt; fixed my issue. &lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2017-07-19T00:25:35.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5383" PostTypeId="2" ParentId="5377" CreationDate="2017-07-19T07:25:04.967" Score="3" Body="&lt;p&gt;I've already commented on the use of flood fill and how it would be better as it's more flexible but another possible solution is scanline. (I say possible because it makes a lot of assumptions about your geometry but for the particular set shown and many similar ones it would work.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your example with 3 points: Find the intersection vertex from the segment v1,v2 and the line that v3 lies on. (The vertex to the upper left of v2) We'll call this vertex v4. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;For every vertex pair a,b down v1,v4 and v1,v3 &#xA;    For every vertex from a to b&#xA;        Mark as in the set&#xA;For every vertex pair a,b down v3,v2 and v4,v3&#xA;    For every vertex from a to b&#xA;        Mark as in the set&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XsUCe.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XsUCe.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's called scanline because (in the image above) you go down the red and green lines simultaneously and then red and blue lines simultaneously scanning the lines in as you go.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This solution would be very fast if there is an index pattern, which is often the case. Otherwise a calculation would be needed to determine which neighboring vertex lies on the line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Funny thing is scanline, barycentric testing (in triangle bounding box), and flood fill are all ways of drawing triangles in 3d rendering.&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="231" LastEditDate="2017-07-19T22:10:48.463" LastActivityDate="2017-07-19T22:10:48.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5386" PostTypeId="2" ParentId="5379" CreationDate="2017-07-19T14:58:01.647" Score="1" Body="&lt;p&gt;The &quot;all&quot; extensions option means exactly what it says: all extensions. If it exists, then its in the generated header. But this doesn't mean that the code will fail to execute on an implementation that doesn't provide every extension. The extensions you select are merely what the generated files make available to you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But of course, the whole point of selecting specific extensions is that you don't have stuff you don't use cluttering up your header. If you're going to select everything, you may as well be using GLEW.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-07-19T14:58:01.647" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5388" PostTypeId="2" ParentId="5379" CreationDate="2017-07-19T18:35:45.040" Score="6" Body="&lt;p&gt;In this &lt;a href=&quot;https://github.com/Dav1dde/glad/issues/97&quot; rel=&quot;nofollow noreferrer&quot;&gt;github issue&lt;/a&gt; the GLAD author offers the following way to correctly check if there is an extension is available at runtime:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The defines just allow you to check at compile time which extensions&#xA;  (and opengl versions) are potentially available. After&#xA;  loading/initilaizing glad you can check with GLAD_&#xA;  if the extension is available at runtime (= supported by the driver&#xA;  and loaded).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// [initialize glad] // ...&#xA;if (!GLAD_GL_EXT_memory_object) {&#xA;    die(&quot;GL_EXT_memory_object not supported!&quot;); &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-11-07T04:30:57.190" LastActivityDate="2018-11-07T04:30:57.190" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="5389" PostTypeId="1" CreationDate="2017-07-19T19:52:02.130" Score="1" ViewCount="575" Body="&lt;p&gt;The biggest bottleneck of my code is fetching texture RGB values from memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code looks something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;game loop{&#xA;    for every mesh{&#xA;        perform clipping;&#xA;        for every 3 verticies in mesh {&#xA;            draw triangle {&#xA;                interpolate texture coordinates;&#xA;                fetch texture RGB and place value in backbuffer;&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fetching the texture RGB value from memory takes up so much time!!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not familiar with multithreading but I'm assuming there is some way to apply it here. Let me know what suggestions you have and how I should go about doing this!&lt;/p&gt;&#xA;" OwnerUserId="7016" LastActivityDate="2017-07-21T08:45:34.500" Title="How to use multithreading in 3D software renderer to speed up fetching texture values" Tags="&lt;texture&gt;&lt;3d&gt;&lt;c++&gt;&lt;rasterizer&gt;&lt;multithreading&gt;" AnswerCount="2" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5390" PostTypeId="1" AcceptedAnswerId="5394" CreationDate="2017-07-20T07:14:03.170" Score="3" ViewCount="529" Body="&lt;p&gt;I am using Unreal Engine to export custom render passes for the scene depth in world units. Every pixel in the render pass has a value which is the distance from the camera to that pixel in standard UE4 units. For example, a pixel with a value of 500 (more precisely 500,500,500) would be 500cm away from the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am then taking these render passes and trying to project them into point clouds inside Houdini. I have this all working, but I'm having trouble figuring out how to correct for the distortion that arises in the point cloud.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my attempt to understand this, I have created a box which is the same aspect ratio as my output (1920 x 1080) and positioned the camera in such a way that it fills the frame more or less exactly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the point cloud, with a wireframe showing where the box was in Unreal Engine. After distortion correction, all those points should align with the face of box nearest the camera on the left. The centre pixels are in the correct place, but as you can see the further away from the centre the more offset they become from their true spatial location.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/N6QeI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N6QeI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand that this distortion is arising because the render pass is essentially drawing a line from each pixel to the camera, so the further away from centre, the longer the line, giving the false impression of increased depth across what should be a flat plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been doing a lot of experimenting with varying distances, sizes of boxes, focal lengths, and so on, trying to figure out what the formula is to correct this distortion, but I'm completely stuck.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I feel like the formula must involve a combination of the distance of camera to pixel, as well as the angle formed between the camera-to-pixel line and the line pointing straight out of the camera. But I might be totally off-base, because I'm not a mathematician by any means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone help me out or point me in the right direction?&lt;/p&gt;&#xA;" OwnerUserId="7023" LastEditorUserId="231" LastEditDate="2017-07-20T15:41:01.323" LastActivityDate="2017-07-20T18:10:29.333" Title="How to correct point cloud distortion" Tags="&lt;3d&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5391" PostTypeId="2" ParentId="5389" CreationDate="2017-07-20T08:34:24.757" Score="2" Body="&lt;p&gt;This is rather general programming question but parallelizing for loop (most common usage) in c++ is easy with openMP library. Basic example for parallelizing outer loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#pragma omp parallel for schedule(static, 1) num_threads(omp_get_num_procs())&#xA;for (int i = 0; i &amp;lt; size1; ++i)&#xA;{&#xA;    for (int j = 0; j &amp;lt; size2; ++j)&#xA;    {&#xA;        buffer[i*size1 + j] = ...&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But because of thread race situation below (incrementing array index) which would work in single thread wouldn't work in parallel:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int it = 0;&#xA;#pragma omp parallel for schedule(static, 1) num_threads(omp_get_num_procs())&#xA;for (int i = 0; i &amp;lt; size1; ++i)&#xA;{&#xA;    for (int j = 0; j &amp;lt; size2; ++j)&#xA;    {&#xA;        buffer[it++] = ...&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also thing to consider is using SIMD instructions (Single Instruction Multiple Data) which optimize multiple operations to single CPU instruction:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#pragma omp parallel for simd schedule(static,10) &#xA;for (i=0; i&amp;lt;N; i++) &#xA;{ &#xA;    a[i] = b[i] * c[i]; &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Some further info:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://bisqwit.iki.fi/story/howto/openmp/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://bisqwit.iki.fi/story/howto/openmp/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=Pc8DfEyAxzg&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=Pc8DfEyAxzg&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2017-07-20T08:34:24.757" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5392" PostTypeId="2" ParentId="5389" CreationDate="2017-07-20T08:49:58.067" Score="4" Body="&lt;p&gt;It could be that you have to overcome a different bottleneck first.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have you ever read Jim Blinn's &quot;The Truth About Texture Mapping&quot;? (I had a quick search to see if I could find a non-paywalled version but you may have better luck than me. Alternatively you might find a dead tree version of &quot;Jim Blinn's Corner&quot; in a library). Though this article is old and describes paging of texture data, it is still very relevant today.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Essentially, if your textures are large (i.e. too large to fit in the cache), in scan order, and they have been rotated when displayed on the polygons, you are very likely to be thrashing your cache and, as memory is an order or two of magnitude slower than the CPU, this will hurt performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To avoid the cache thrashing, textures are often stored in twiddled-order (that's what we called it in the early 90s but, more correctly, it'll be some variant of Morton order) or in a block order, which is what Blinn describes. This then makes texel/memory accesses far more coherent and the cache more effective.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-07-21T08:45:34.500" LastActivityDate="2017-07-21T08:45:34.500" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5394" PostTypeId="2" ParentId="5390" CreationDate="2017-07-20T18:10:29.333" Score="1" Body="&lt;p&gt;I've figured a difference approach to projecting the point cloud inside Houdini.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had assumed that the 'Scene Depth World Units' would provide the depth of each pixel along a vector parallel with the camera vector, rather than angled to point at the camera as a single point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So rather than projecting the point cloud as if the depth was correct, and then trying to adjust for the distortion this creates, it makes more sense to just project the points in the same way they were created.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, knowing the position and rotation of the camera, I can then use the depth pass to project the points outwards from this location.&lt;/p&gt;&#xA;" OwnerUserId="7023" LastActivityDate="2017-07-20T18:10:29.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5395" PostTypeId="2" ParentId="5373" CreationDate="2017-07-21T09:29:20.313" Score="6" Body="&lt;p&gt;I finally figured out a flaw in my argumentation to use the half vector for the diffuse part.&lt;/p&gt;&#xA;&lt;h1&gt;&lt;strong&gt;tl;dr version:&lt;/strong&gt;&lt;/h1&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\alpha_{hi}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\alpha_{ho}$&lt;/span&gt; are not equal, this assumption only works for the specular part. Therefore the energyconservation is not given.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;More correct: Per definition &lt;span class=&quot;math-container&quot;&gt;$\alpha_{hi} = \alpha_{ho}$&lt;/span&gt;, but you are not allowed to use them in the equation, you need to use the microfacet normals instead of the half vectors. The microfacet normal and the half vector are however not generally equal.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;h1&gt;long version:&lt;/h1&gt;&#xA;&lt;p&gt;The diffuse BRDF (like the specular one) is an integration over all possible microfacet normals. The generalized BRDF form is:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(1)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f = \int_{\Omega} \frac{\rho_m * D * G * \cos(\alpha_{hi}) * \cos(\alpha_{ho})}{ \cos(\theta_i) * \cos(\theta_o)}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$\rho_m$&lt;/span&gt; is the behaviour of light when it reaches a microfacet, &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; is the normal distribution function, &lt;span class=&quot;math-container&quot;&gt;$G$&lt;/span&gt; is the geometry function and the rest is normalization [PBR, p.16-25][HEI, p.61f.]&lt;/p&gt;&#xA;&lt;p&gt;Now for the specular BRDF, the behaviour is perfect reflection. This means, only microfacets where the microfacet normal &lt;span class=&quot;math-container&quot;&gt;$\omega_m$&lt;/span&gt; equals the half vector &lt;span class=&quot;math-container&quot;&gt;$\omega_h$&lt;/span&gt; between light (&lt;span class=&quot;math-container&quot;&gt;$\omega_i$&lt;/span&gt;) and view (&lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;) direction reflect light from the light direction to the view direction. Mathematically, this translates to a Dirac Delta function &lt;span class=&quot;math-container&quot;&gt;$\delta(\omega_h)$&lt;/span&gt;. The amount of light reflected is determined by Fresnel &lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt;. With accounting for integration domain changes[PBR, p.31-41], this leads to (&lt;span class=&quot;math-container&quot;&gt;$\rho_{m,s}$&lt;/span&gt; being the specular specific reaction of microfacets for the specular part):&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(2)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\rho_{m,s} = \frac{\delta(\omega_h) * F }{4*\alpha_{hi}*\alpha_{ho}}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Plug this into &lt;strong&gt;(1)&lt;/strong&gt; and you integrate over any &lt;span class=&quot;math-container&quot;&gt;$\omega_m$&lt;/span&gt;, but the dirac delta function makes you ignore anything where &lt;span class=&quot;math-container&quot;&gt;$\omega_m \neq \omega_h$&lt;/span&gt;. This is the nice thing about those dirac delta functions, the &amp;quot;cancel&amp;quot; the integral. Therefore, you come to the well known BRDF [PBR, p.43]&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(3)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f_s = \frac{F * D * G}{4 * \cos(\theta_i) * \cos(\theta_o)}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;and here you can savely assume &lt;span class=&quot;math-container&quot;&gt;$\alpha_{hi} = \alpha_{ho}$&lt;/span&gt;. The Fresnel part makes this one side of a linear interpolation (seeing as this is the ratio of light being specularly reflected).&lt;/p&gt;&#xA;&lt;p&gt;On the other side though, you still have an integral and you can't &amp;quot;cancel&amp;quot; it with anything. Let &lt;span class=&quot;math-container&quot;&gt;$\theta_{mi}$&lt;/span&gt; be the angle between the microfacet normal and the light dir, &lt;span class=&quot;math-container&quot;&gt;$\theta_{mo}$&lt;/span&gt; between the microfacet normal and the view dir (as opposed to &lt;span class=&quot;math-container&quot;&gt;$\alpha_{hi}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\alpha_{ho}$&lt;/span&gt;, which specifically are defined for the half angle!).That means 2 important things:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(4)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\theta_{mi} \neq \alpha_{hi} = \alpha_h = \alpha_{ho} \neq \theta_{mo} \forall \omega_m \neq \omega_h$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;and &lt;span class=&quot;math-container&quot;&gt;$\rho_{m,d}$&lt;/span&gt; (as the diffuse reaction of light when reaching microfacets) is depended upon Fresnel, it can only use non reflected parts, but you cannot just assume EVERY microfacet normal diffusley reflects all the light that was not specularly reflected (i.e. &lt;span class=&quot;math-container&quot;&gt;$(1-F(\alpha_h))$&lt;/span&gt;).&lt;/p&gt;&#xA;&lt;p&gt;So the problem now is, you have one side of that linear interpolation being the analytically solvable specular BRDF without an integral. On the other side, you have the interpolation factor within the integral, and thus you would use it for any microfacet normal. This is not energy conserving anymore, if you model &lt;span class=&quot;math-container&quot;&gt;$\rho_{m,d}$&lt;/span&gt; with a lambertian term.&lt;/p&gt;&#xA;&lt;p&gt;If you manage to pull the &lt;span class=&quot;math-container&quot;&gt;$1-F$&lt;/span&gt; part out of the integral, then and only then can you use the half vector for both specular and diffuse BRDFs, otherwise you need to handle it differently.&lt;/p&gt;&#xA;&lt;p&gt;If you still want to use the half vector for the &amp;quot;Fresnelinterpolation&amp;quot;, then you need to normalize.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f = F(\alpha_h) * r_s + (1-F(\alpha_h)) * r_d * k$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;With &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; being chosen, such that&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$r_d * k = 1$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Note that &lt;span class=&quot;math-container&quot;&gt;$r_d$&lt;/span&gt; still includes an integral over all possible microfacet normals.&lt;/p&gt;&#xA;&lt;h2&gt;Using &lt;span class=&quot;math-container&quot;&gt;$\theta_i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\theta_o$&lt;/span&gt;&lt;/h2&gt;&#xA;&lt;p&gt;I guess I should add a sentence about the actually used angles, because the question I originally posed was not just &amp;quot;why not &lt;span class=&quot;math-container&quot;&gt;$\alpha_h$&lt;/span&gt;&amp;quot; but also &amp;quot;why &lt;span class=&quot;math-container&quot;&gt;$\theta_i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\theta_o$&lt;/span&gt;&amp;quot;. So for the poeple wondering if this is correct: No. It is just an approximation.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Instead, we can modify the matte term to be a simple approximation that captures the important qualitative angular behavior[...].&lt;/p&gt;&#xA;&lt;p&gt;[SHI, p.46]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h2&gt;Discussion on why this is so hard to figure out&lt;/h2&gt;&#xA;&lt;p&gt;Now [DIS, p.14] and [PBR, p.100,184] quoted [SHI] and [ASH] on this, where [ASH] uses [SHI], so it boils down to the model of the latter. And seeing as [DIS] and [PBR] are non-scientific (though pretty well thought through) publications, I can't fault them too much, but really, a better way of quoting papers or an extra explanation might have helped and saved me about 2 weeks of thinking, reading and almost starting a paper on why everybody is (supposedly) wrong.&lt;/p&gt;&#xA;&lt;p&gt;Furthermore, neither of them really explains their diffuse approximations, [PBR, p.193] just mentions trying different functions until he saw one he liked.&lt;/p&gt;&#xA;&lt;p&gt;Additionally, [SHI, p.46] actually quoted [SCH, p.10f.] who used the linear interpolation between &lt;span class=&quot;math-container&quot;&gt;$F(\alpha_h)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$1-F(\alpha_h)$&lt;/span&gt;. However, [SHI, p.46] quoted him incorrectly, they said he used &lt;span class=&quot;math-container&quot;&gt;$F(\theta_i)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$1-F(\alpha_h)$&lt;/span&gt;. Assuming this, they are of course right in thinking [SCH] is not energy conserving, but this lead me to believe that &lt;span class=&quot;math-container&quot;&gt;$F(\alpha_h)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$1-F(\alpha_h)$&lt;/span&gt; would be. Their mistake might've come from them using &lt;span class=&quot;math-container&quot;&gt;$F(\theta_i)$&lt;/span&gt; themselves, I can't say.&lt;/p&gt;&#xA;&lt;h2&gt;Literature&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;[ASH] An anisotropic phong BRDF model, in Journal of Graphics Tools Vol. 5, No. 2, Michael Ashikhmin and Peter Shirley, 2000&lt;/li&gt;&#xA;&lt;li&gt;[SCH] An Inexpsensive BRDF Model for Physically-based Rendering, in Computer Graphics Forum Vol. 13, No. 3, Christophe Schlick, 1994&lt;/li&gt;&#xA;&lt;li&gt;[SHI] A Practitioners' Assessment of Light Reflection Models, in The Fifth Pacific Conference on Computer Graphics and Applications, 1997. Proceedings, Peter Shirley,  Helen Hu, Brian Smits and Eric Lafortune, 1997&lt;/li&gt;&#xA;&lt;li&gt;[DIS] Physically-Based Shading at Disney, at SIGGRAPH 2012 Course: Physically Based Shading in Film and Game Production, Brent Burley, 2012&lt;/li&gt;&#xA;&lt;li&gt;[HEI] Understanding the Masking-Shadowing Function in Microfacet-Based BRDFs, in Journal of Computer Graphics Techniques Vol. 3, No. 2, Eric Heitz, 2014&lt;/li&gt;&#xA;&lt;li&gt;[PBR] PBR Diffuse Lighting for GGX+Smith Microsurfaces, at GDC2017, Earl Hammon Jr., 2017&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2021-01-25T11:45:22.043" LastActivityDate="2021-01-25T11:45:22.043" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="5396" PostTypeId="1" CreationDate="2017-07-21T10:21:28.957" Score="6" ViewCount="509" Body="&lt;p&gt;I've been writing some custom shaders based around Unity's Standard BRDF, which is uses GGX distribution term and Smith visibility term. It looks great at either end of the smoothness scale (1 and 2 in the pic below). However, with the smoothness set to about 50%, things start to get a little ugly (3). Increasing the metalness makes it worse (4), and strongly coloured specular gets worse still, as different colour channels blow out at different rates(5).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/meanS.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/meanS.png&quot; alt=&quot;BRDFs&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems to be caused by specular term returning &gt;1 around the highlights, probably caused by Unity's hack of multiplying specular by pi (instead of dividing diffuse) as shown in the code snippet below.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Specular term&#xA;// HACK: theoretically we should divide diffuseTerm by Pi and not multiply specularTerm!&#xA;// BUT 1) that will make shader look significantly darker than Legacy ones&#xA;// and 2) on engine side &quot;Non-important&quot; lights have to be divided by Pi too in cases when they are injected into ambient SH&#xA;half roughness = PerceptualRoughnessToRoughness(perceptualRoughness);&#xA;half V = SmithJointGGXVisibilityTerm (nl, nv, roughness);&#xA;half D = GGXTerm (nh, roughness);&#xA;half specularTerm = V*D * UNITY_PI; // Torrance-Sparrow model, Fresnel is applied later&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;HDR rendering helps a lot, but unfortunately our project is on mobile and using LDR. I'm making a car paint shader with a clear coat, so the base coat will likely be semi-rough and semi-metallic in a lot of cases which seems to be a worst-case-scenario for this BRDF. Can anyone suggest a way to get saner specular highlights? Either some kind of rolloff for out-of-range specular values, or a different BRDF altogether?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-07-21T21:36:59.797" Title="Dealing with blown-out highlights in PBR" Tags="&lt;brdf&gt;&lt;pbr&gt;&lt;unity&gt;&lt;ggx&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5397" PostTypeId="1" CreationDate="2017-07-21T13:26:47.583" Score="2" ViewCount="102" Body="&lt;p&gt;I've been following a guide to learn OpenGL, and I'm now learning how to do post-processing.&#xA;In particular, I'm trying to apply a blur to my rendering through the following kernel:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{\begin{bmatrix}1&amp;amp;2&amp;amp;1\\2&amp;amp;4&amp;amp;2\\1&amp;amp;2&amp;amp;1\end{bmatrix}}{16}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I'm encountering is that whenever I try to access a float array's member through the &lt;code&gt;[]&lt;/code&gt; operator giving it an int variable as parameter, it returns &lt;code&gt;0.0&lt;/code&gt;.&#xA;Here's my fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410 core&#xA;in vec2 txcoords;  // Texture coordinates&#xA;out vec4 color;&#xA;uniform sampler2D tx;&#xA;&#xA;const float offset = 1.0 / 300.0;&#xA;&#xA;void main() {&#xA;    vec2 offsets[9] = vec2[](&#xA;        vec2(-offset,    offset),&#xA;        vec2( 0.0,       offset),&#xA;        vec2( offset,    offset),&#xA;        vec2(-offset,    0.0),&#xA;        vec2( 0.0,       0.0),&#xA;        vec2( offset,    0.0),&#xA;        vec2(-offset,   -offset),&#xA;        vec2( 0.0,      -offset),&#xA;        vec2( offset,   -offset)&#xA;    );&#xA;&#xA;    const float kernel[9] = float[9](&#xA;        1.0 / 16, 2.0 / 16, 1.0 / 16,&#xA;        2.0 / 16, 4.0 / 16, 2.0 / 16,&#xA;        1.0 / 16, 2.0 / 16, 1.0 / 16&#xA;    );&#xA;&#xA;    vec3 sampleTex[9];&#xA;    vec3 final = vec3(0.0);&#xA;    for (int i = 0; i &amp;lt; 9; i++) {&#xA;        sampleTex[i] = vec3(texture(tx, txcoords.st + offsets[i]));&#xA;    }&#xA;&#xA;    for (int i = 0; i &amp;lt; 9; i++) {&#xA;        final += sampleTex[i] * kernel[i];&#xA;    }&#xA;    color = vec4(final, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code doesn't work(whole screen renders black), but if I change it to&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;final += sampleTex[i] * kernel[0];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then my scene is rendered correctly, but, of course, without any blur, just a bit darker than normal.&#xA;It also doesn't just work with &lt;code&gt;kernel[0]&lt;/code&gt;, but with any number (&lt;code&gt;[1]&lt;/code&gt;, &lt;code&gt;[2]&lt;/code&gt;, etc.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If instead I change it to &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;final += sampleTex[i] * (kernel[i] + 0.05);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then it renders exactly the same as with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;final += sampleTex[i] * 0.05;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And that's why I ended up suspecting that it's the &lt;code&gt;[i]&lt;/code&gt; part that just won't work, for whatever reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone have any idea as to why this is happening? I also tried with different shader versions (330, 400, etc.) but they all give the same result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for your time!&lt;/p&gt;&#xA;" OwnerUserId="7029" LastActivityDate="2017-07-21T13:26:47.583" Title="GLSL broken access operator" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5398" PostTypeId="1" AcceptedAnswerId="5400" CreationDate="2017-07-21T16:32:09.867" Score="5" ViewCount="732" Body="&lt;p&gt;I have been learning about projection matrix in OpenGL and I am finding it really hard to understand. All I know is that there are other configurations in the projection matrix besides placing z in w for perspective projection. What are those other numbers and why are they there? &#xA;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="2096" LastActivityDate="2017-07-24T09:47:46.310" Title="Is placing z value of vertex in w enough to achieve perspective projection in OpenGL?" Tags="&lt;opengl&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5399" PostTypeId="2" ParentId="5396" CreationDate="2017-07-21T21:36:59.797" Score="7" Body="&lt;p&gt;Using physically based BRDFs only makes sense if your entire pipeline is built for physical units - the extreme range of values can't be displayed properly without some form of tone mapping. You didn't include that part of the code but from the looks of it I'd say you're doing a simple clamp() followed by linear-&gt;sRGB conversion, which causes the bad highlights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you're not ready to run your entire frame in HDR, you could apply something simple like a sigmoid operator to just the specular component. This may look a bit off next to other BRDFs but should make those highlights much more pleasant.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-07-21T21:36:59.797" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5400" PostTypeId="2" ParentId="5398" CreationDate="2017-07-22T06:28:00.507" Score="3" Body="&lt;p&gt;The projection matrix distorts the view frustum (the volume the camera can see) into a unit cube. So everything with all coordinates in the range -1 to 1 after projection is potentially visible, and everything else can be clipped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make things further away look smaller, we need to divide by their Z distance. We can't put this value directly into the matrix since it is different for each point we want to project, so instead we place each point's Z into its projected W, giving (X, Y ,Z ,1) -&gt; (X', Y', Z', Z), known as clip coordinates. This is then divided by the new W to give (X'/Z, Y'/Z, Z'/Z, 1),  known as normalized device coordinates. On the GPU this division happens automatically after the vertex shader and before clipping and rasterization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The general form of a projection matrix is&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;A 0 0 0&#xA;0 B 0 0&#xA;0 0 C D&#xA;0 0 1 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The A and B terms relate to the field of view, higher values give a narrower view. Specifically, B is the cotangent of half the vertical view angle, and A is B/aspect ratio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The C and D terms are bias and scale terms which map the near plane to -1 (0 in DirectX), and the far plane to 1. These are used for writes to the depth buffer to determine which objects occlude others. The depth mapping is actually a function of 1/Z, rather than Z, since this gives better precision close to the near plane, and allows perspective-correct interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note that in OpenGL, W' is -Z rather than Z, since we are using a right-handed coordinate system, with negative Z pointing into the screen.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-07-22T06:28:00.507" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5402" PostTypeId="1" AcceptedAnswerId="5403" CreationDate="2017-07-23T01:44:58.527" Score="3" ViewCount="1313" Body="&lt;p&gt;I have a very simple OpenGL program where the positions are embedded in the GLSL code. The vertex shader looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core&#xA;&#xA;uniform float offsetX;&#xA;uniform float offsetY;&#xA;&#xA;out VS_OUT&#xA;{&#xA;  vec2 tc;&#xA;} vs_out;&#xA;&#xA;void main()&#xA;{&#xA;  const vec2[4] position = vec2[4](vec2(-0.5, -0.5),&#xA;                                   vec2(0.5, -0.5),&#xA;                                   vec2(-0.5, 0.5),&#xA;                                   vec2(0.5, 0.5));&#xA;&#xA;  vs_out.tc = position[gl_VertexID].xy + vec2(0.5);&#xA;  vec2 pos = position[gl_VertexID].xy + vec2(offsetX, offsetY);&#xA;  gl_Position = vec4(pos, 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To run this, to me it seems like I should basically be able to just be able to call &lt;code&gt;glDrawArrays&lt;/code&gt; from my application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this is not the case. I my application I have the following code (reused from an earlier example):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Create buffer&#xA;glCreateBuffers(1, &amp;amp;buffer);&#xA;glNamedBufferStorage(buffer, sizeof(vertices), vertices, bufferFlags);&#xA;&#xA;// Create vao&#xA;glCreateVertexArrays(1, &amp;amp;vao);&#xA;&#xA;// Enable attributes&#xA;glEnableVertexArrayAttrib(vao, positionIndex);&#xA;glEnableVertexArrayAttrib(vao, texCoordIndex);&#xA;&#xA;// Set up formats for attributes&#xA;glVertexArrayAttribFormat(vao, positionIndex, positionSize, GL_FLOAT, GL_FALSE, firstElementOffset);&#xA;glVertexArrayAttribFormat(vao, texCoordIndex, texCoordSize, GL_FLOAT, GL_FALSE, positionSize * sizeof(GLfloat));&#xA;&#xA;// Make attributes use binding 0&#xA;glVertexArrayAttribBinding(vao, positionIndex, bufferBindingIndex);&#xA;glVertexArrayAttribBinding(vao, texCoordIndex, bufferBindingIndex);&#xA;&#xA;// Bind &quot;buffer&quot; to vertex buffer binding point 0&#xA;glVertexArrayVertexBuffer(vao, bufferBindingIndex, buffer, firstElementOffset, elementStride);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;None of that actually seems necessary because my shaders are now responsible for generating the position and texture coordinates.  However, if I comment out the call to &lt;code&gt;glVertexArrayVertexBuffer&lt;/code&gt; my program crashes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I required to have a buffer bound to binding point 0 (even if I do not use any of that buffer's data) before calling &lt;code&gt;glDraw*&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2017-07-23T14:24:18.913" Title="Do I have to have a buffer bound before making a draw call?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5403" PostTypeId="2" ParentId="5402" CreationDate="2017-07-23T14:24:18.913" Score="3" Body="&lt;p&gt;There is nothing in the OpenGL specification that requires you to have enabled attribute arrays in the bound VAO when you render. All of the user-defined vertex attributes will have undefined values, but since you're not reading any of them, that won't be a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What &lt;em&gt;may&lt;/em&gt; be a problem is driver bugs. Rendering with an empty VAO is not exactly the most common thing in the world, so it's possible that some drivers won't do the right thing. But the implementation &lt;em&gt;should&lt;/em&gt; allow this.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;However, if I comment out the call to &lt;code&gt;glVertexArrayVertexBuffer&lt;/code&gt; my program crashes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Of course it does. You have to not &lt;em&gt;enable&lt;/em&gt; the attribute array as well. If you have a vertex attribute enabled, it has to come from somewhere. So there must be a buffer behind it. If you don't want to put a buffer there, then you can't have an attribute array source its data from that buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So while you are not required to have enabled attribute arrays, if you have enabled an array, you are required to provide a buffer for it. If you don't want to use vertex attributes, you have to not use vertex attributes.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-07-23T14:24:18.913" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5404" PostTypeId="1" CreationDate="2017-07-23T19:15:23.890" Score="0" ViewCount="581" Body="&lt;p&gt;I would like to return the XY coordinates of vertex C using math formula. &#xA;I have 5 input data what I always know and can be used for solution (green in the image): I know X; Y; coordinates of point A and point B (Ax, Ay, Bx, By), and I know the length of all three sides of triangle (AB, AC, AD). Please help how to get the values of X Y coordinate of point C, what is 70/30 in the example, but I have no formula to get back them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/q6WGF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/q6WGF.jpg&quot; alt=&quot;Example situation to get coordinates with input values&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that more than one solution of this formula, but:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Coordinates cannot be in negative areas. All coordinates must be positive.&lt;/li&gt;&#xA;&lt;li&gt;I always use 1 direction for vertex labelling, but because I always know the length of AC and BC, I think to change the label from A to B will not change the position of C.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7039" LastActivityDate="2017-07-28T07:33:30.007" Title="Return x; y; coordinates of vertex C of triangle" Tags="&lt;triangulation&gt;&lt;mathematics&gt;" AnswerCount="3" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5406" PostTypeId="2" ParentId="5404" CreationDate="2017-07-24T09:23:50.647" Score="1" Body="&lt;p&gt;You can get the coordinates of C by using circle equations for one circle C_A with point A as center and AC as its radius and one circle C_B with point B as its center and BC as its radius.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can calculate their intersection points, which leaves you with 2 points (iff C is not on a line between A and B).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not entirely sure how you want to determine which of the two candidates C_1 and C_2 is the correct one. If I understand correctly, you always label the triangle counterclockwise. There is a &lt;a href=&quot;https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order&quot;&gt;neat way&lt;/a&gt; to check this, so you should have everything to find your point.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2017-07-24T09:23:50.647" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5408" PostTypeId="1" CreationDate="2017-07-24T13:19:43.587" Score="1" ViewCount="89" Body="&lt;p&gt;I'm launching OpenGL from a VBA module linked to an Excel spreadsheet which goes quasi-dormant (the quasi will become clear in a moment) once I enter glutMainLoop. I would like to be able to edit the Excel spreadsheet and observe corresponding changes in the OpenGL simulation. In this context,  I have two issues:&lt;/p&gt;&#xA;&lt;p&gt;Issue 1 (as John McLaughlin used to bark on his PBS show!): Currently, &lt;strong&gt;once within glutMainLoop&lt;/strong&gt;, I can only make changes to Excel cells that have pulldown menus, but not cells that require keyboard input. I believe that this issue may be related to the lack of a multi-threading ability either withing glut or VBA (this is WAY above my Mech E pay grade). I'd like to know however, if there's a workaround.&lt;/p&gt;&#xA;&lt;p&gt;Issue 2: When I make changes to the Excel cells with pulldown menus, the OpenGL window gets minimised, unless I move it to a second screen or outside the Excel window which is not convenient. I understand that this is typical Windows behaviour, but at the very least, is there an openGL command to maximise it again after the changes to the Excel spreadsheet, &lt;strong&gt;from within glutMainLoop&lt;/strong&gt;?&lt;/p&gt;&#xA;&lt;p&gt;I'd like to emphasise that Issue 1 above - the lack of ability to edit Excel cells requiring keyboard input once within glutMainLoop - is far more important.&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance. I've added an image below that (hopefully!) describes what I'm trying to accomplish.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IpzMc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IpzMc.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6785" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-01-14T22:30:32.987" Title="Manipulating simulation within glutMainLoop from an Excel spreadsheet" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5409" PostTypeId="1" CreationDate="2017-07-24T15:58:52.647" Score="3" ViewCount="246" Body="&lt;p&gt;I am trying to implement Beer's law according to &lt;a href=&quot;http://www.eng.utah.edu/~cs6620/beers.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; page in dielectric material but I am not sure have done it correctly as the image does not suggest so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula is: I(s) = I(0) * pow(e, ln(A)*s)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;'A' is said to be transmission coefficient which I am not clear what this is&#xA;and what value I should use for it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the code and the image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone shed some light if I have gone wrong. Thanks.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public override LightVector SampleBrdf(ISect isect, Random rand,&#xA;        out LightVector woW, out double pdfDir, out double cosWo)&#xA;{&#xA;    woW = LightVector.ZERO;&#xA;    cosWo = 0;&#xA;    LightVector n = isect.Thing.Normal;&#xA;    LightVector tan = isect.Thing.Edge1;&#xA;    tan.Normalize();&#xA;    LightVector ts = n.Cross(tan);&#xA;&#xA;    //set wo to be incoming dir&#xA;    LightVector wo = MaterialHelper.WorldToLocal(-isect.Ray.Dir, tan, ts, n);dir&#xA;    LightVector refracted = LightVector.ZERO;&#xA;    LightVector reflected = new LightVector(-wo.X, -wo.Y, wo.Z);&#xA;&#xA;    double F = Fresnel.Evaluate(rindex1, rindex2, MaterialHelper.CosTheta(wo));&#xA;    pdfDir = F;&#xA;&#xA;    //Figure out which eta is incident and which is transmitted&#xA;    double extCoeff = 1;&#xA;    double etaI = rindex1;&#xA;    double etaT = rindex2;&#xA;    LightVector z = new LightVector(0, 0, 1);&#xA;    if (MaterialHelper.CosTheta(wo) &amp;lt; 0)//existing&#xA;    {&#xA;        etaI = rindex2;&#xA;        etaT = rindex1;&#xA;        z = -z;&#xA;        extCoeff = Math.Exp(-Math.Log(A, Math.E) * isect.Dist);&#xA;    }&#xA;&#xA;    //Compute ray direction for specular transmission&#xA;    if (!MaterialHelper.Refract(wo, z, etaI / etaT, out refracted))&#xA;        pdfDir = 1;&#xA;&#xA;    if (rand.NextDouble() &amp;lt; pdfDir)&#xA;    {&#xA;        woW = MaterialHelper.LocalToWorld(reflected, tan, ts, n);&#xA;        cosWo = MaterialHelper.AbsCosTheta(reflected);&#xA;&#xA;        return R * (F / cosWo);&#xA;    }&#xA;    else //refracted&#xA;    {&#xA;        woW = MaterialHelper.LocalToWorld(refracted, tan, ts, n);&#xA;        cosWo = MaterialHelper.AbsCosTheta(refracted);&#xA;        pdfDir = 1d - F;&#xA;&#xA;        return T * (extCoeff * (1d - F) / cosWo);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4jgjp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4jgjp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was expecting to see the reflection of the light source at the ceiling on the glass. But it was my mistake in the caller method where the specular bounce contribution was dismissed. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorDisplayName="user7220" LastEditDate="2018-04-22T12:56:38.213" LastActivityDate="2018-04-22T12:56:38.213" Title="Beer's law in dielectric material" Tags="&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;material&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5411" PostTypeId="1" AcceptedAnswerId="5412" CreationDate="2017-07-26T08:03:52.067" Score="3" ViewCount="1601" Body="&lt;p&gt;I am working on a normal mapping. I need to have the ability to scale normal vectors to adjust the normal strength of the surface. Currently the way I am doing it basically shows plausible results. But I am still not sure that it's 100% correct and to my surprise I found no info on the web regarding this subject.&#xA;So here is how I do that (my lightning is in camera space):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;vertex shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 N = normalize(normalMatrix * a_normal); &#xA;vec3 T = normalize(normalMatrix * a_tangent.xyz) * nStrength;          &#xA;vec3 B = normalize(normalMatrix * (cross(a_normal, a_tangent.xyz) * a_tangent.w) ) * nStrength; &#xA;&#xA;v_TBN =  mat3(T,B,N);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;normalMatrix - inverse-transpose of model-view matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shading itself happens in the fragment shader.&#xA;The only relevant part which is happening there is transforming normal from&#xA;the texture with v_TBN varying:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Fragment shader:&lt;/strong&gt;   &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; vec3 GetNormal(){&#xA;    vec3 n = texture(normalMap,uv).xyz;&#xA;    n = normalize(n * 2.0 - 1.0);&#xA;    return  normalize (v_TBN * n);&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So, as you can see, I scale tangent and bi-tangent vectors with nStrength scalar.That's the most optimal setup I figured out that gives most correct looking effect.Is this the right way to strengthen the normals?                 &lt;/p&gt;&#xA;" OwnerUserId="213" LastEditorUserId="6" LastEditDate="2017-09-30T20:52:18.293" LastActivityDate="2017-09-30T20:52:18.293" Title="Correct way to set normal strength" Tags="&lt;opengl&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5412" PostTypeId="2" ParentId="5411" CreationDate="2017-07-26T19:36:53.900" Score="7" Body="&lt;p&gt;Assuming that the normal was created by differentiating some height field &lt;code&gt;f(u,v)&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;N = normalize(df_du, df_dv, 1)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What you probably want to achieve is to &quot;strengthen&quot; your normals as-if by scaling that height field by a factor C:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;g(u,v) = C*f(u,v)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then your new normal would be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;M = normalize(dg_du, dg_dv, 1) = normalize(C*N0, C*N1, N2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Translating that to GLSL in your shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 GetNormal(){&#xA;    vec3 n = texture(normalMap,uv).xyz;&#xA;    n = n * 2.0 - 1.0;&#xA;    n.xy *= C;&#xA;    n = normalize(n);&#xA;    return  normalize (v_TBN * n);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;By constructing a normal map texture that stores only the height-field gradient &lt;code&gt;(df_du, df_dv)&lt;/code&gt; without normalization, using the internal format &lt;code&gt;GL_RG8_SNORM&lt;/code&gt; for the texture, and making sure that &lt;code&gt;v_TBN&lt;/code&gt; is orthonormal, you can simplify it further to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 GetNormal() {&#xA;    vec3 n = normalize(vec3(texture(normalMap,uv).xy, C));&#xA;    return v_TBN*n;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7057" LastEditorUserId="7057" LastEditDate="2017-07-28T10:30:17.600" LastActivityDate="2017-07-28T10:30:17.600" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5413" PostTypeId="1" AcceptedAnswerId="5428" CreationDate="2017-07-26T20:07:34.660" Score="2" ViewCount="195" Body="&lt;p&gt;I am trying to do simple PCF with Unity but I am facing some issues and I don't know where they come from. If anybody has an idea...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are two examples&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// C#&#xA;GetTemporaryRT(_shadowMapProperty, _shadowSettings.shadowAtlasWidth, _shadowSettings.shadowAtlasHeight, _depthBufferBits, FilterMode.Bilinear, RenderTextureFormat.Depth, RenderTextureReadWrite.Linear);&#xA;&#xA;// CG&#xA;sampler2D_float _ShadowMap;&#xA;float4 _ShadowMap_TexelSize;&#xA;&#xA;half ShadowAttenuation(float3 shadowCoord)&#xA;{&#xA;    float depth = tex2D(_ShadowMap, shadowCoord).r;&#xA;#if defined(UNITY_REVERSED_Z)&#xA;    return step(depth - _ShadowData.y, shadowCoord.z);&#xA;#else&#xA;    return step(shadowCoord.z, depth + _ShadowData.y);&#xA;#endif&#xA;}&#xA;&#xA;/////// EXAMPLE 1 /////// &#xA;&#xA;float shadow = ShadowAttenuation(half3(shadowCoord.xy, shadowCoord.z));&#xA;return shadow;&#xA;&#xA;/////// EXAMPLE 2 ///////&#xA;&#xA;float3 UnityCombineShadowcoordComponents(float2 baseUV, float2 deltaUV, float depth)&#xA;{&#xA;    float3 uv = float3(baseUV + deltaUV, depth);&#xA;    uv.z += dot(deltaUV, receiverPlaneDepthBias.xy);&#xA;    return uv;&#xA;} &#xA;&#xA;half shadow = 1;&#xA;const float2 offset = float2(0.5, 0.5);&#xA;float2 uv = (shadowCoord.xy * _ShadowMap_TexelSize.zw) + offset;&#xA;float2 base_uv = (floor(uv) - offset) * _ShadowMap_TexelSize.xy;&#xA;float2 st = frac(uv);&#xA;&#xA;float2 uw = float2(3 - 2 * st.x, 1 + 2 * st.x);&#xA;float2 u = float2((2 - st.x) / uw.x - 1, (st.x) / uw.y + 1);&#xA;u *= _ShadowMap_TexelSize.x;&#xA;&#xA;float2 vw = float2(3 - 2 * st.y, 1 + 2 * st.y);&#xA;float2 v = float2((2 - st.y) / vw.x - 1, (st.y) / vw.y + 1);&#xA;v *= _ShadowMap_TexelSize.y;&#xA;&#xA;half sum = 0;&#xA;&#xA;sum += uw[0] * vw[0] * ShadowAttenuation(UnityCombineShadowcoordComponents(base_uv, float2(u[0], v[0]), shadowCoord.z));&#xA;sum += uw[1] * vw[0] * ShadowAttenuation(UnityCombineShadowcoordComponents(base_uv, float2(u[1], v[0]), shadowCoord.z));&#xA;sum += uw[0] * vw[1] * ShadowAttenuation(UnityCombineShadowcoordComponents(base_uv, float2(u[0], v[1]), shadowCoord.z));&#xA;sum += uw[1] * vw[1] * ShadowAttenuation(UnityCombineShadowcoordComponents(base_uv, float2(u[1], v[1]), shadowCoord.z));&#xA;&#xA;shadow = sum / 16.0f;&#xA;return shadow;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here are the results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4NJ9e.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4NJ9e.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2017-07-28T10:46:14.160" Title="DX9 Shadow map PCF issue" Tags="&lt;shader&gt;&lt;shadow&gt;&lt;shadow-mapping&gt;&lt;unity&gt;&lt;directx&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5414" PostTypeId="1" AcceptedAnswerId="5422" CreationDate="2017-07-27T00:24:23.270" Score="4" ViewCount="625" Body="&lt;p&gt;I was taking a look at Smallpt (&lt;a href=&quot;http://www.kevinbeason.com/smallpt&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.kevinbeason.com/smallpt&lt;/a&gt;), more specifically at the Russian Roulette part. Actually, RR is used in two places along the code: first, to determine ray termination; and second, for the rendering of dielectrics. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is the code for the ray termination case (expanded code version):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// p = maximum reflectance&#xA;// fr = BRDF&#xA;double p = fr.x &amp;gt; fr.y &amp;amp;&amp;amp; fr.x &amp;gt; fr.z ? fr.x : fr.y &amp;gt; fr.z ? fr.y : fr.z; &#xA;&#xA;if ( ++depth &amp;gt; 5 ) &#xA;    if ( erand48(Xi) &amp;lt; p )&#xA;        fr = fr * ( 1 / p ); &#xA;    else &#xA;        return obj.emission;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After five bounces, RR is used to determine if the ray path continues or not. If it continues, the BRDF is scaled to compensate for it. This is Ok for me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;RR is also used in a second code segment to select between refraction or transmission during the rendering of dielectrics (expanded code version): &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double Re = R0 + ( 1 - R0 ) * cost * cost * cost * cost * cost;&#xA;double Tr = 1 - Re;&#xA;double P = .25 + .5 * Re;&#xA;double RP = Re / P;&#xA;double TP = Tr / ( 1 - P );&#xA;Vec Lo; // output radiance&#xA;&#xA;if ( depth &amp;gt; 2 )&#xA;    if ( erand48(Xi) &amp;lt; P )&#xA;        Lo = radiance(reflRay,depth,Xi) * RP;&#xA;    else&#xA;        Lo = radiance(Ray(x,tdir),depth,Xi) * TP;&#xA;else    &#xA;    Lo = radiance(reflRay,depth,Xi) * Re + radiance(Ray(x,tdir),depth,Xi) * Tr;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;According to the code above, the path branches recursively if the ray has bounced up to two times. After two bounces, however, RR is used to select the path to be followed. This is also Ok for me. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is a bit confusing is the fact that the radiance returned by both possible non-branching paths (refraction and transmission) is scaled. I understand that there are different probabilities regarding reflection and transmission. However, if for instance Re = 0.3 and Tr = 0.7, and 100 rays strike the surface, about 30% of the rays will be reflected and 70% of will be transmitted due RR. In this case, I understand that there is no path termination neither energy loss, so there wouldn't be anything to compensate for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, my first two questions are: why are these radiances scaled? Should they be scaled, or would it work without scaling at all?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My third question is related to the scaling factors: Why the author has used P, RP and TP instead of Re and Tr?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any indication of a good reading about this topic is also very welcome!! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorDisplayName="user5681" LastEditDate="2017-07-28T00:10:33.437" LastActivityDate="2017-07-28T00:10:33.437" Title="About the use of Russian Roulette in Smallpt" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5415" PostTypeId="1" AcceptedAnswerId="5426" CreationDate="2017-07-27T00:27:57.897" Score="1" ViewCount="226" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KGI2H.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KGI2H.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;(example of effect i am trying to render)&lt;/p&gt;&#xA;&lt;p&gt;Rendering Transparent Object in forward rendering is far easier. However I am having an issue when it comes to transparent glass like object that applies post processing like effect when seen through it.&lt;/p&gt;&#xA;&lt;p&gt;I do know how to render &amp;quot;glass&amp;quot; that reflects &amp;quot;skybox&amp;quot; however I do not know how to render a glass like object that applies its distortion effect around its dynamic surroundings.&lt;/p&gt;&#xA;&lt;p&gt;I need help figuring out how to render this effect.&lt;/p&gt;&#xA;" OwnerUserId="6282" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-07-28T02:18:00.760" Title="Forward Rendering Distortion Effect" Tags="&lt;distortion&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5416" PostTypeId="1" AcceptedAnswerId="5423" CreationDate="2017-07-27T06:34:32.850" Score="3" ViewCount="2159" Body="&lt;p&gt;&lt;a href=&quot;https://github.com/Erkaman/image-load-store-demo&quot; rel=&quot;nofollow noreferrer&quot;&gt;One example&lt;/a&gt; of Image Load / Stores that I have seen could be done using framebuffers instead of Image Load / Stores.  Framebuffers have been available longer in OpenGL and so my question is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why would you use Images instead of Framebuffers?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What advantages do they offer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The referenced example says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Note that this demo can also easily be imlemented using Framebuffer Objects. But with Framebuffer Objects you cannot write to arbitrary locations in a texture, though.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I am not exactly sure what is meant here. My understanding is that you &lt;em&gt;can&lt;/em&gt; write to whatever pixel coordinates you want in an FBO.  Am I mistaken here?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2018-04-09T09:41:50.900" Title="Why use image load / stores instead of FBOs" Tags="&lt;opengl&gt;&lt;frame-buffer&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5417" PostTypeId="2" ParentId="5404" CreationDate="2017-07-27T10:37:21.597" Score="-1" Body="&lt;p&gt;As mentioned by previous answers, the best way to solve your issue is to compute the intersections of the two circles centered at A and B. Since you will have two candidates, you will need to choose a specific order for your edges to only select one candidate.&lt;/p&gt;&#xA;" OwnerUserId="7059" LastActivityDate="2017-07-27T10:37:21.597" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5418" PostTypeId="2" ParentId="5416" CreationDate="2017-07-27T11:03:05.473" Score="0" Body="&lt;p&gt;The documentation quickly sum up the idea with: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The idea with image load/store is that the user can bind one of the&#xA;  images in a Texture to a number of image binding points (which are&#xA;  separate from texture image units). Shaders can read information from&#xA;  these images and write information to them, in ways that they cannot&#xA;  with textures.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Aside for the simplicity of usage, from &lt;a href=&quot;http://rastergrid.com/blog/2011/08/an-introduction-to-opengl-4-2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;An introduction to OpenGL 4.2 | Daniel Rákos Blog&lt;/a&gt; at the section &lt;strong&gt;ARB_shader_image_load_store&lt;/strong&gt; you can perform more complex operations and algorithms in GLSL to a single level of a texture (which is called an image) and from any shader stage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am also curious about the implementation of the example with FBO since I don't understand why you cannot write to a specific pixel coordinate too.&lt;/p&gt;&#xA;" OwnerUserId="7059" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T09:41:50.900" LastActivityDate="2018-04-09T09:41:50.900" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5419" PostTypeId="2" ParentId="5416" CreationDate="2017-07-27T11:28:31.237" Score="1" Body="&lt;p&gt;To write to an arbitrary location in a FBO you need to do rasterization of point primitive at that location. This is significantly more costly than a single &lt;code&gt;imageStore&lt;/code&gt; because it involves invoking the vertex shader, the ROP units, and possibly rasterizing a whole 2x2 quad or more for just a single pixel.&lt;sup&gt;†&lt;/sup&gt; With &lt;code&gt;imageLoad&lt;/code&gt;/&lt;code&gt;imageStore&lt;/code&gt; you have greater flexibility and finer control of where you read and write, including atomics, barriers, etc... Since you skip the ROP and give up the API-order guarantee, such direct writes might be faster even for filling triangles.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;† I'm not sure about this last point, but since the screen-space derivatives are still available in the fragment shader, and point primitives are typically used for larger sprites, it means that the implementations are more likely to just go the typical rasterization route used for lines and triangles.&lt;/p&gt;&#xA;" OwnerUserId="7057" LastActivityDate="2017-07-27T11:28:31.237" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5420" PostTypeId="2" ParentId="411" CreationDate="2017-07-27T11:29:57.653" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is there any software which would let me import the existing models,&#xA;  define the bone hierarchy and the model which corresponds to each&#xA;  bone, and export a single articulated model in T-pose?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I found that it is relatively easy to create articulations using Blender.&#xA;This tutorial might be helpful: &lt;a href=&quot;https://en.wikibooks.org/wiki/Blender_3D:_Noob_to_Pro/Bones&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender 3D: Noob to Pro/Bones | Wikibooks&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7059" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T08:58:15.113" LastActivityDate="2018-04-09T08:58:15.113" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5421" PostTypeId="1" CreationDate="2017-07-27T12:33:12.903" Score="0" ViewCount="73" Body="&lt;p&gt;I have a number of (opaque) objects created using the glGenLists() glNewList() utilities. As generated, the Alpha values are all set to 1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to make these objects when summoned blend into the scene (sort of as if they were being teleported using the Star Trek transporter). Likewise, I'd also like them to dissolve away when dismissed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could of course use time-varying alpha blending in a subroutine if they weren't list objects, but I'm wondering if there's a performance penalty associated with that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I'm really trying to do is replace larger coarser ground texture quads  with finer smaller quads as I descend in altitude from a satellite while looking down.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="6785" LastEditorUserId="6785" LastEditDate="2017-07-27T12:42:39.643" LastActivityDate="2017-08-01T18:40:09.653" Title="Make Object created in a list blend in/dissolve out of a scene" Tags="&lt;opengl&gt;&lt;blending&gt;&lt;alpha&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5422" PostTypeId="2" ParentId="5414" CreationDate="2017-07-27T14:09:19.767" Score="1" Body="&lt;p&gt;The reflected and transmitted values need to be scaled because they are not sampled proportionally to their contribution. You'll notice how the decision whether to reflect or transmit is made based on P, not Re.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About why that scaling has been done in the first place, only the author can give you the definitive answer. My guess is that this is done to prevent extreme values that would come from tiny probabilities. Imagine that Re is 0.001 and is used without scaling. Then only one in 1000 rays would reflect, and the contribution of that ray would be multiplied by 1000. At a render with, say, 64 rays per pixel, this would leave very visible artefacts, as not every pixel would get a reflected ray. The scaling from this code snipped on the other hand makes sure that the ray budget is more evenly distributed between reflection and transmission and that each potential path taken is guaranteed at least 25% or the rays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For further reading about path tracing, there is no better and comprehensive resource than www.pbrt.org - both the book and the source code are worth reading.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-07-27T14:09:19.767" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5423" PostTypeId="2" ParentId="5416" CreationDate="2017-07-27T16:21:35.037" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Why would you use Images instead of Framebuffers?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Load_Store&quot; rel=&quot;noreferrer&quot;&gt;Image Load/Store&lt;/a&gt; is not intended to replace framebuffers. It's a feature that allows (relatively) arbitrary reading and writing to memory. So you would use images when you need to arbitrarily read and write to memory. You would use framebuffers when you're rasterizing primitives for rendering purposes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fact that you can build scenarios where you would use the latter in place of the former does not mean that this is the purpose of the feature.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;What advantages do they offer?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Again, it's not meant to replace framebuffers. But the comparison is pretty simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A particular FS invocation cannot:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Choose what framebuffer texel(s) to write to. An FS invocation will only ever write outputs to the framebuffer texel(s) that map to its current fragment location. &lt;code&gt;gl_FragCoord&lt;/code&gt; is an input value; it is non-modifiable. An FS's outputs will either be &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Fragment#Fragment_discard&quot; rel=&quot;noreferrer&quot;&gt;discard&lt;/a&gt; or written to the framebuffer texel(s) corresponding to &lt;code&gt;gl_FragCoord.xy&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, through point rasterization, you can select which fragment is being generated. But it isn't the fragment shader &lt;em&gt;itself&lt;/em&gt; that's deciding this; it's whatever process wrote the vertex to the buffer that it's being read from. That is not under the direct control of the FS invocation itself.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Choose to write to multiple distinct framebuffer texel(s) locations. A fragment cannot cover multiple texels.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;Choose which output attachments in the framebuffer to write to. The decision of which &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Fragment#Fragment_shader_outputs&quot; rel=&quot;noreferrer&quot;&gt;fragment shader outputs&lt;/a&gt; will be written is made by the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Write_Mask&quot; rel=&quot;noreferrer&quot;&gt;write mask state&lt;/a&gt;, which the FS has zero control over. An FS can choose to be &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Fragment#Fragment_discard&quot; rel=&quot;noreferrer&quot;&gt;discarded&lt;/a&gt;, but that discards &lt;em&gt;all&lt;/em&gt; of its outputs.&lt;/li&gt;&#xA;&lt;li&gt;Choose to read from the current framebuffer texel(s) it is writing to. &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Blending&quot; rel=&quot;noreferrer&quot;&gt;Blending&lt;/a&gt; is done by a fixed-function stage; the FS has zero control over this. The closest you can get is to employ some &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Texture_Barrier&quot; rel=&quot;noreferrer&quot;&gt;texture barrier gymnastics&lt;/a&gt;, but that's not something the FS can directly control.&lt;/li&gt;&#xA;&lt;li&gt;Choose to read from framebuffer texel(s) other than the one it's writing to. Even with texture barrier gymnastics, you cannot read from other people's texels.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Now granted, image load/store doesn't exactly make read/modify/write passes easy, due to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Memory_Model#Incoherent_memory_access&quot; rel=&quot;noreferrer&quot;&gt;incoherent memory access rules&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, image load/store cannot handle (easily):&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Depth testing. Or at least, not in any way that is &lt;em&gt;nearly&lt;/em&gt; as efficient as the rasterizer. The read/modify/write nature of the depth test makes this exceedingly tricky with image load/store. With a regular depth buffer however, this is trivial.&lt;/li&gt;&#xA;&lt;li&gt;Simple blending. Again, you can do it, but it's really hard, and far less efficient than the normal rendering process.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-07-27T16:21:35.037" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5426" PostTypeId="2" ParentId="5415" CreationDate="2017-07-28T02:18:00.760" Score="2" Body="&lt;p&gt;An effect like that is most likely done as a second pass, after storing a copy of the color buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When looking carefully, you can see some of the vertices from the shape of the effect above the character. So this scene in particular probably does something like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;First render the scene into a color buffer, without the distortion effect.&lt;/li&gt;&#xA;&lt;li&gt;Because it's not possible to both read from and write to a same frame buffer at the same time, copy it as is (blit) into another frame buffer. From now on, new draws will go into that new frame buffer.&lt;/li&gt;&#xA;&lt;li&gt;In the new frame buffer, draw a mesh with the shape of the effect, using a shader that will fetch the texture of the first color buffer, with an offset depending on the normal. Also note that:&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The mesh is opaque (no blending): it's the texture that makes it look transparent.&lt;/li&gt;&#xA;&lt;li&gt;Although we don't see this in the screenshot, it's also perfectly possible to use the depth buffer as usual and have the effect intersect with the scene.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Finally a simpler effect, like rain drops on the screen, could be done this way:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;First render the scene into a frame buffer, without the distortion effect.&lt;/li&gt;&#xA;&lt;li&gt;Copy the entire frame buffer into another frame buffer using a custom shader. The shader will apply some offset to the texture coordinates (either directly or maybe using a distortion texture), thus distorting the image.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="182" LastActivityDate="2017-07-28T02:18:00.760" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5427" PostTypeId="2" ParentId="5404" CreationDate="2017-07-28T07:33:30.007" Score="0" Body="&lt;p&gt;There are several ways of doing this, the circle intersection way is by no metrics the easiest way. If you have any standard vector maths library available then the simpest way in my mind is as follows:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Calculate the direction vector a-b, by subtracting vector a from vector b. Then normalize this vector then multiply it by length of b-c&lt;/li&gt;&#xA;&lt;li&gt;calculate the angle at corner b&lt;/li&gt;&#xA;&lt;li&gt;rotate the vector calculated by 180 +- the angle. (There are 2 solutions).&lt;/li&gt;&#xA;&lt;li&gt;add b to that vector. And you are done.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-07-28T07:33:30.007" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5428" PostTypeId="2" ParentId="5413" CreationDate="2017-07-28T10:46:14.160" Score="1" Body="&lt;p&gt;It seems that &lt;code&gt;sampler2D_float&lt;/code&gt; doesn't allow to interpolate shadow lookup  linearly. So I had to do it by hand. Here's an example of &lt;a href=&quot;http://codeflow.org/entries/2013/feb/15/soft-shadow-mapping/#interpolated-shadowing&quot; rel=&quot;nofollow noreferrer&quot;&gt;interpolated shadowing&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float texture2DCompare(sampler2D depths, vec2 uv, float compare){&#xA;    float depth = texture2D(depths, uv).r;&#xA;    return step(compare, depth);&#xA;}&#xA;&#xA;float texture2DShadowLerp(sampler2D depths, vec2 size, vec2 uv, float compare){&#xA;    vec2 texelSize = vec2(1.0)/size;&#xA;    vec2 f = fract(uv*size+0.5);&#xA;    vec2 centroidUV = floor(uv*size+0.5)/size;&#xA;&#xA;    float lb = texture2DCompare(depths, centroidUV+texelSize*vec2(0.0, 0.0), compare);&#xA;    float lt = texture2DCompare(depths, centroidUV+texelSize*vec2(0.0, 1.0), compare);&#xA;    float rb = texture2DCompare(depths, centroidUV+texelSize*vec2(1.0, 0.0), compare);&#xA;    float rt = texture2DCompare(depths, centroidUV+texelSize*vec2(1.0, 1.0), compare);&#xA;    float a = mix(lb, lt, f.y);&#xA;    float b = mix(rb, rt, f.y);&#xA;    float c = mix(a, b, f.x);&#xA;    return c;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2017-07-28T10:46:14.160" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5429" PostTypeId="1" CreationDate="2017-07-28T13:39:36.447" Score="2" ViewCount="114" Body="&lt;p&gt;What is the best way to save video from faces of a cube? The render can produce 6 squares (90°x90°) of 1024x1024 resolution. Faces oriented along axies and only position is changed continuously. I want to save them into the video stream and then play back them into 360° panorama viewver by means of projection on the cube or using cubemap (OpenGL ES).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the best codec suitable and what is the best way to save video for above purposes? Is it better to use six separate synchronized video streams or, instead, to enclose all six faces into the one?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If cube is unfolded into six square bitmaps and composed into a 3x2 (or 2x3) rectangle, then it is possible to get artifacts on glued inner edges and on the outer edge of the resulting rectangle. I sure it may depend on codec used to compress/decompress resulting video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case of 6 separate video streams it is possible to render only 5 of 6 (or 3 of 6 in case of only pitch and yaw (but not roll) rotations are possible) faces of cube, i.e. only visible ones. But on the other hand it may be waste of resources to support six separate streams due to necessity of attendant metainformation handling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are expected performance issues inherent to different approaches?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The relevant platform is average home desktop PC.&lt;/p&gt;&#xA;" OwnerUserId="5430" LastEditorUserId="5430" LastEditDate="2017-07-28T17:13:19.933" LastActivityDate="2017-07-28T17:13:19.933" Title="A way to save 360° panorama video" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;projections&gt;&lt;video&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5430" PostTypeId="2" ParentId="5429" CreationDate="2017-07-28T14:21:24.263" Score="1" Body="&lt;p&gt;I would be tempted to use a solution which involves decoding a single rectangular video stream so you don't need any special video decoder. As you have said there will be performance penalties for decoding multiple seperate streams. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something like octohedran cube maps might be a good offline way to convert 6 video streams into a single video stream while minimizing distortion. A relatively cheap pixel shader can be used to project the 'cube' map back to camera space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further reading here &gt; &lt;a href=&quot;http://www.vis.uni-stuttgart.de/~engelhts/paper/vmvOctaMaps.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.vis.uni-stuttgart.de/~engelhts/paper/vmvOctaMaps.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2017-07-28T14:27:02.617" LastActivityDate="2017-07-28T14:27:02.617" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5431" PostTypeId="2" ParentId="3924" CreationDate="2017-07-28T14:44:29.253" Score="0" Body="&lt;p&gt;In the rotation matrix, you actually use trigonometric functions (i.e. sine and cosine with an independent variable known as the angle) which internally implemented by Taylor series (i.e. has some costs). With complex numbers you could avoid that by multiplying the vector (i.e. after represents it as a complex number) by a complex number that represents the rotation. For example, if you need to rotate a vector (1,0) and make it points upward (i.e. no need for an angle), you basically multiple it by a complex number $z=i$, the rotated vector is then (0,1). As you can see no trigonometric functions are being used. See the following Matlab code to perform some rotations&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;clear all&#xA;clc&#xA;&#xA;v =  1 + 0i; % vector&#xA;&#xA;z1 =  1 + 1i; % 45  rotation&#xA;z2 =  0 + 1i; % 90  rotation&#xA;z3 = -1 + 1i; % 135 rotation&#xA;z4 = -1 + 0i; % 180 rotation&#xA;z5 = -1 - 1i; % 225 rotation&#xA;z6 =  1 - 1i; % 270 rotation&#xA;&#xA;%rotate v1 by z deg&#xA;v1 = v*z6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But remember with 2D, the rotation matrix does fairly a good job however, with 3D the importance of complex numbers represented via quaternion is significant. &lt;/p&gt;&#xA;" OwnerUserId="7066" LastEditorUserId="7066" LastEditDate="2017-07-28T14:59:01.977" LastActivityDate="2017-07-28T14:59:01.977" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5432" PostTypeId="1" CreationDate="2017-07-28T15:02:37.380" Score="1" ViewCount="664" Body="&lt;p&gt;I trying to highlight vertices which are on &quot;borders&quot;, imagine half of sphere for example. Also for example I added image geomtry with triangles and highlighted necessary vertices. Any ideas? Thanks&#xA;&lt;img src=&quot;https://i.imgur.com/5CaiStV.jpg&quot; alt=&quot;Graph&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="6337" LastActivityDate="2018-04-09T08:58:03.337" Title="How to find vertices on borders of geometry" Tags="&lt;mathematics&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5433" PostTypeId="1" AcceptedAnswerId="5434" CreationDate="2017-07-28T15:04:02.200" Score="5" ViewCount="1239" Body="&lt;p&gt;This is more a theoretical question. I'm wondering what happens when I write float values into an empty RGBA texture of type &lt;code&gt;gl.UNSIGNED_BYTE&lt;/code&gt; in WebGL 1.0. Obviously, every channel then has 8 bits. But that wouldn't be enough to represent floating point values, would it? Nevertheless it somehow works, more or less. See part of a fragment shader code here:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;&#xA;uniform vec2 u_Resolution;&#xA;&#xA;void main(void){&#xA;   gl_FragColor = vec4(gl_FragCoord.xy / u_Resolution, 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I specify the texture to be of type &lt;code&gt;gl.FLOAT&lt;/code&gt; (using the OES_texture_float extension), the results of course look better. But I want to know exactly why they do.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition: does the specified precision have an effect on the texture (to be written)?&lt;/p&gt;&#xA;" OwnerUserId="5406" LastActivityDate="2017-07-28T17:50:44.740" Title="What happens to float values written to UNSIGNED_BYTE texture?" Tags="&lt;texture&gt;&lt;glsl&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5434" PostTypeId="2" ParentId="5433" CreationDate="2017-07-28T17:50:44.740" Score="3" Body="&lt;p&gt;Unsigned byte textures in a graphics API are usually &quot;normalized&quot;—the byte values are interpreted as ranging from 0.0 to 1.0, with a byte of 255 mapping to 1.0. So no, they aren't truly floating-point values, but the hardware will automatically convert them to/from float when you read/write the texture. If you try to write a value outside the [0, 1] range, it will be clamped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the &lt;code&gt;precision highp&lt;/code&gt; part, it doesn't directly affect the texture, but it can certainly affect any calculations of values you write to the texture. For example, to calculate an 8-bit texture you certainly want a &lt;em&gt;minimum&lt;/em&gt; of 8 bits of mantissa precision (i.e. &lt;code&gt;lowp&lt;/code&gt;)—and you &lt;em&gt;probably&lt;/em&gt; want more than that, depending on what calculations you're doing. I'd advise you to check what the actual precision levels are on your device, since they vary widely depending on what GPU you have. See &lt;a href=&quot;https://stackoverflow.com/questions/4414041/what-is-the-precision-of-highp-floats-in-glsl-es-2-0-for-iphone-ipod-touch-ipad&quot;&gt;this question&lt;/a&gt; for more.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-07-28T17:50:44.740" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5435" PostTypeId="2" ParentId="5432" CreationDate="2017-07-28T18:04:53.583" Score="1" Body="&lt;p&gt;I'm assuming you are rendering this object as a set of triangles. To do what you are trying to do, you will need to store all your triangles (and vertices) in some sort of buffer or list. Then, for each triangle, test if all three of its sides are matched with another triangle side. If so, it is enclosed and inside the object. Otherwise, it is outside the object. Some basic pseudo-code (I apologize for all the foreach loops :) )&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;foreach t in triangles:&#xA;    all_sides_touched = True&#xA;    foreach side_t in t:&#xA;        this_side_touched = False&#xA;        foreach u in triangles.exclude(t):    // run through all other triangles to test&#xA;            foreach side_u in u:&#xA;                if side_t.equals(side_u):  this_side_touched = True&#xA;        all_sides_touched = all_sides_touched and this_side_touched&#xA;    if not all_sides_touched:&#xA;        foreach side in t:&#xA;            foreach point in side:&#xA;                // do whatever you want to do with outside vertices&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6883" LastActivityDate="2017-07-28T18:04:53.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5436" PostTypeId="1" CreationDate="2017-07-29T06:43:44.320" Score="1" ViewCount="145" Body="&lt;p&gt;I'm dealing with hardware that uses quads as its polygonal primitive. Not triangles. A triangle can be expressed by setting 2 of the 4 vertices equal to each other for a degenerate quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the 3D engine, I'm in need of clipping for polygons outside of clip space volume in order to avoid vertex inversion and division by zero errors when performing the perspective divide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My logic is that I first identify the primitives that intersect with the 6 planes. From there I add edges to cut the primitive. What I don't understand at this point is how to cut/add quads. Do I need to &quot;triangulate&quot;, but for quads? Is it possible? Are there constraints other than the quad needing to be convex?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I might be over complicating this. I can't come up with a case where I get less than 4 or more than 4 vertices when clipping. The only case is when all points are outside the clipping area, all except one edge. That edge would produce a triangle.&lt;/p&gt;&#xA;" OwnerUserId="7068" LastEditorUserId="7068" LastEditDate="2017-07-29T07:48:18.853" LastActivityDate="2017-07-29T07:48:18.853" Title="Algorithm for clipping convex quadrilaterals" Tags="&lt;3d&gt;&lt;algorithm&gt;&lt;geometry&gt;&lt;mathematics&gt;&lt;clipping&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5437" PostTypeId="1" AcceptedAnswerId="5438" CreationDate="2017-07-29T17:08:59.967" Score="0" ViewCount="779" Body="&lt;p&gt;Does anyone know who to interpolate UVs in a quad tessellation evaluation shader? I can interpolate the position easily like so :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 p1 = mix(gl_in[0].gl_Position,&#xA;        gl_in[1].gl_Position,&#xA;        gl_TessCoord.x);&#xA;vec4 p2 = mix(gl_in[2].gl_Position,&#xA;        gl_in[3].gl_Position,&#xA;        gl_TessCoord.x);&#xA;gl_Position = mix(p2, p1, gl_TessCoord.y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But I can't figure out how to interpolate the incoming UV coordinates. I need to do so to pass them on to the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With perfect quad UVs from 0 to 1, I can use &lt;code&gt;gl_TessCoord.xy&lt;/code&gt;. Unfortunately that doesn't work when the UVs aren't mapped 1:1 to a texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="5978" LastEditorUserId="5978" LastEditDate="2017-07-29T17:27:43.380" LastActivityDate="2017-07-29T17:27:43.380" Title="How do you interpolate UV mapping coords in a quad tessellation evaluation shader?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;glsl&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5438" PostTypeId="2" ParentId="5437" CreationDate="2017-07-29T17:27:29.600" Score="1" Body="&lt;p&gt;The problem was else-where, the same interpolation works for UV coords.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv1 = mix(teUv[0], teUv[1], gl_TessCoord.x);&#xA;vec2 uv2 = mix(teUv[2], teUv[3], gl_TessCoord.x);&#xA;fUv = mix(uv2, uv1, gl_TessCoord.y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5978" LastActivityDate="2017-07-29T17:27:29.600" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5439" PostTypeId="2" ParentId="5421" CreationDate="2017-07-29T19:42:06.340" Score="1" Body="&lt;p&gt;It looks like there are a few steps to make this work:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Linearly interpolate the alpha of the mesh from transparent to fully opaque, or vice versa. &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;Note 1: It seems as if the alpha starts to fade a few seconds after the effect has started.&lt;/em&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;Note 2: The alpha of the &quot;effect meshes&quot; (covered in #2 and #3) should be changed independently of the original mesh. This will help produce the desired effect.&lt;/em&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Generate (just the color buffer for) a mesh with identical vertices, but make the color blue or green. The brightness of each vertice's/triangle's color should be calculated using either &lt;strong&gt;random noise&lt;/strong&gt; (i.e. using a random number generator), or &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Perlin_noise&quot; rel=&quot;nofollow noreferrer&quot;&gt;Perlin Noise&lt;/a&gt;&lt;/strong&gt;; or a combination of the two. For the flashing effect, it would be best to regenerate the mesh each frame (with a different noise seed, if using Perlin Noise). Next, calculate a weighted average between the colors of this &quot;effect mesh&quot; and the those of the original mesh, according to how much time has passed. For instance, assuming &lt;code&gt;t&lt;/code&gt; is the percentage of the way through the effect that has passed; at &lt;code&gt;t=0&lt;/code&gt;, make the color buffer &lt;code&gt;0*effect_mesh + 1*original_mesh&lt;/code&gt;; and at &lt;code&gt;t=0.3&lt;/code&gt;, make the color buffer &lt;code&gt;0.3*effect_mesh + 0.7*original_mesh&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;For the vertical line effect, think about ray-tracing all the vertices (using multiple vertical rays). If a vertex is hit by (or near) a ray, make that vertex's color lighter/darker. This effect would be best done with a weighted average also, according to the time (since the lines are stronger towards the beginning).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;*** Although this &quot;Star Trek&quot; effect varies from scene to scene, you should order these effects; don't do them all at the same time.&lt;/p&gt;&#xA;" OwnerUserId="6883" LastEditorUserId="6883" LastEditDate="2017-08-01T18:40:09.653" LastActivityDate="2017-08-01T18:40:09.653" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5440" PostTypeId="1" CreationDate="2017-07-30T03:42:25.000" Score="2" ViewCount="582" Body="&lt;p&gt;Monte Carlo rendering is just a process of sampling and reconstruction to evaluate the rendering equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is it called noise rather than error?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2017-08-01T12:10:04.270" Title="What's the nature of Monte Carlo noise?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;monte-carlo&gt;&lt;noise&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5442" PostTypeId="1" CreationDate="2017-07-30T16:49:21.710" Score="1" ViewCount="46" Body="&lt;p&gt;I am trying to create an effect where a bumpy billboarded texture is illuminated by a emission map that is also billboarded but is logically closer to the camera in 3D space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this way a blue light would be represented by a blue circle drawn on the emission map with transparency representing the brightness of the light. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The light would then illuminate the bumpy texture in the back. Because the texture is bumpy (due to a bump map) the lights might cast slight shadows and unequally light the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have no clue how to go about achieving this as I am unsure of the math involved in getting a bump map to play well with an emission map. Furthermore i am having difficulty finding a good tutorial or piece of code that represents emission maps that actually cast light onto other objects as if they were comprised of point lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any pointers that might help me get started? &lt;/p&gt;&#xA;" OwnerUserId="7072" LastActivityDate="2017-08-01T04:02:06.747" Title="Emission maps that interact with a bump map" Tags="&lt;texture&gt;&lt;lighting&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5443" PostTypeId="1" CreationDate="2017-07-31T05:14:07.903" Score="0" ViewCount="49" Body="&lt;p&gt;This link says &lt;a href=&quot;https://code.google.com/archive/p/iphone-glu/&quot; rel=&quot;nofollow noreferrer&quot;&gt;iPhoneGLU&lt;/a&gt; says, this libraray supports below futures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Matrix manipulation&#xA;Polygon tessellation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to know whether I can use this library to draw primitives(lines,points,triangles,simple polygon).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="7076" LastActivityDate="2017-08-05T06:26:59.333" Title="iPhone GLU(OpenGL Utility Library)" Tags="&lt;opengl-es&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5445" PostTypeId="2" ParentId="5280" CreationDate="2017-07-31T07:57:01.183" Score="1" Body="&lt;p&gt;In your case, I don't think a pre-processing is necessary. You may find the &lt;a href=&quot;https://en.wikipedia.org/wiki/Hough_transform&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hough transform useful&lt;/a&gt; in your case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since your image is big, it can be difficult to have a straight line due to the noise and blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what I got using a sobel contour detection with a smaller version of your image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is maybe a good start to use a line detection algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eAVQh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eAVQh.jpg&quot; alt=&quot;Input image after resizing and sobel contour detection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A second solution would be to use color segmentation. If you assume that your screen would always have black border you can work something in the &lt;a href=&quot;https://en.wikipedia.org/wiki/Lab_color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;L&lt;em&gt;A&lt;/em&gt;b&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/HSL_and_HSV&quot; rel=&quot;nofollow noreferrer&quot;&gt;HSV&lt;/a&gt; color space.&lt;/p&gt;&#xA;" OwnerUserId="7059" LastActivityDate="2017-07-31T07:57:01.183" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5447" PostTypeId="1" CreationDate="2017-08-01T06:15:26.000" Score="2" ViewCount="81" Body="&lt;p&gt;I am writing an OpenSceneGraph based program that uses two cameras, one to render the preview for the user and one that uses a callback to make screenshots with MRT. The exporter camera is using an orthographic projection and always from the same position with the same view and up vector, whereas the preview camera can be moved by the user (which is why I use two cameras rather than one for both tasks).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Upon starting the program, I create the preview camera, add the shaders to it, then set up the viewer and add the preview camera to the viewer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Afterwards I create the export camera, add its shaders, textures and callback and then I add the export camera as a child to the preview camera. Up to this point, nothing has been rendered (i.e. no &lt;code&gt;frame&lt;/code&gt; call has been made).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;addChild&lt;/code&gt; call is issued (i.e. the break point is reached in Visual Studio, and stepping further I can see that the exporter camera is now a child of the preview camera). However, once I issue a command to actually make a screenshot, the exporter camera is not the child of the preview camera anymore (by now, a few render calls have been made). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is this, and how can I fix it apart from adding the exporter camera again?&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2020-05-28T12:31:41.153" LastActivityDate="2020-05-28T12:31:41.153" Title="Why does the camera not remain child of the other camera after adding it in osg?" Tags="&lt;camera&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5449" PostTypeId="1" AcceptedAnswerId="5451" CreationDate="2017-08-01T13:39:13.580" Score="5" ViewCount="1478" Body="&lt;p&gt;I've been looking up this question on the internet for a while, and I haven't been very successful, so I decided I'll ask it here. Should I apply tone mapping before gamma correction, gamma correction before tone mapping, or should I just use one or the other?&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-08-01T14:37:22.093" Title="Tone Mapping &amp; Gamma Correction" Tags="&lt;rendering&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5450" PostTypeId="2" ParentId="5432" CreationDate="2017-08-01T14:29:07.837" Score="0" Body="&lt;p&gt;A close solution would be like &lt;a href=&quot;https://stackoverflow.com/questions/11779797/how-to-detect-border-vertices-of-an-open-mesh-3d-model&quot;&gt;How to detect border vertices of an open mesh 3d model? | Stack Overflow&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For edge, you test in the edge is connected to at least 2 triangles. If it is not the case, the edge is a border under the assumption that the mesh is a manifold.&lt;/p&gt;&#xA;" OwnerUserId="7059" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T08:58:03.337" LastActivityDate="2018-04-09T08:58:03.337" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5451" PostTypeId="2" ParentId="5449" CreationDate="2017-08-01T14:37:22.093" Score="4" Body="&lt;p&gt;This depends on your calculations really, since you can do it either way. However, probably when you reach tone mapping you will be in linear space (i.e. no gamma correction has been done yet and you don't assume non-linear space for your calculations).&#xA;Assuming this, gamma correction should be applied after tone mapping, otherwise you have &quot;linear&quot; tone mapping on non-linear color values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To quote from Real-Time Rendering 3rd by Möller, Haines and Hoffman, p. 145:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;It is important to apply the conversion at the final stage of rendering (when the values are written to the display buffer for the last time), and not before. If post-processing is applied after gamma correction, post-processing effects will be computed in nonlinear space, which is incorrect and will often cause visible artifacts. So operations such as tone mapping [...] can be applied to images to adjust luminance balance, but gamma corection should always be done last.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2017-08-01T14:37:22.093" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5452" PostTypeId="2" ParentId="5335" CreationDate="2017-08-02T08:13:34.223" Score="1" Body="&lt;p&gt;I finally arrived at a solution that is not perfect, but seems to be good enough for my application right now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The pipeline is as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;-&amp;gt; grayscale perlin noise with affine transformed (stretched and rotated) coordinate system&#xA;-&amp;gt; gaussian blur (sigma 3.0)&#xA;-&amp;gt; normalize (range 0.0 to 1.0)&#xA;-&amp;gt; pixels = pixels - 0.5&#xA;-&amp;gt; pixels = pixels * 2&#xA;-&amp;gt; threshold (change everything below 0 to 0)&#xA;-&amp;gt; add pixels to original image with an alpha value of 0.7&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here are some of the results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Sygqn.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Sygqn.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7BQSL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7BQSL.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/oFSyv.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oFSyv.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Bime8.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Bime8.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/yY1Ds.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yY1Ds.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6951" LastEditorUserId="6951" LastEditDate="2017-08-03T07:51:12.020" LastActivityDate="2017-08-03T07:51:12.020" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5453" PostTypeId="1" CreationDate="2017-08-02T14:14:18.357" Score="5" ViewCount="2513" Body="&lt;p&gt;I would like implement physically based rendering, following &lt;a href=&quot;https://learnopengl.com/#!PBR/Lighting&quot; rel=&quot;noreferrer&quot;&gt;this tutorial&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was able to find a &lt;a href=&quot;https://en.wikipedia.org/wiki/Orders_of_magnitude_(luminous_flux)&quot; rel=&quot;noreferrer&quot;&gt;list of light sources ordered by lumens&lt;/a&gt;, but I have no idea how to use it in the calculations.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float attenuation = 1.0 / (distance * distance);&#xA;vec3 radiance = lightColor * attenuation;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What should the &lt;code&gt;lightColor&lt;/code&gt; be, if the light source is a 60W lightbulb (780 lm) and in my scene one unit is one cm?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I define the &lt;code&gt;radiance&lt;/code&gt;, if I have a directional light, for example the sun?&lt;/p&gt;&#xA;" OwnerUserId="7028" LastActivityDate="2017-08-27T04:42:51.887" Title="How to calculate attenuation and radiance in PBR? (point and directional lights)" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;physically-based&gt;&lt;pbr&gt;&lt;radiosity&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5454" PostTypeId="1" AcceptedAnswerId="5455" CreationDate="2017-08-02T14:32:12.343" Score="4" ViewCount="198" Body="&lt;p&gt;Most 3D video games since the nineties have used hardware rendering based on polygons. Why polygons? They work well for some things, but not so well for others, e.g. a human figure rendered in polygons looks bad unless the polygon count is very large. I'm guessing it's because they work better for hardware rendering, which is best at doing very simple operations very many times. (Modern graphics cards may be more flexible, but the industry pretty much settled on polygons a long time ago.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose you want to write a software rendering game engine (let's say because your target hardware has a fast CPU but a very weak graphics chip). Would polygons still be the way to go?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Conjecture: if you are going to render in software, it's better to play to strengths and use more complex primitives, in particular curved shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this correct? If so, are there any known results regarding what kind of curve primitives should be used?&lt;/p&gt;&#xA;" OwnerUserId="7096" LastEditorUserId="7096" LastEditDate="2017-08-02T14:56:37.857" LastActivityDate="2017-08-02T15:49:42.180" Title="Polygons versus curve primitives in software rendering" Tags="&lt;rendering&gt;&lt;polygon&gt;&lt;rasterizer&gt;&lt;curve&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5455" PostTypeId="2" ParentId="5454" CreationDate="2017-08-02T15:41:39.987" Score="3" Body="&lt;p&gt;Most software rendering engines dice the parametric primitives to micropolygons, usually on the fly as needed. In essence this reduces the needed complexity to determine intersections. The surface will still look smooth, since each polygon is smaller than a pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This allows for &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Data caching.&lt;/li&gt;&#xA;&lt;li&gt;Discrete geometric derivates.&lt;/li&gt;&#xA;&lt;li&gt;Displacement is easy to implement.&lt;/li&gt;&#xA;&lt;li&gt;Same rendering code to be used on most primitive types.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XTfti.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XTfti.jpg&quot; alt=&quot;micropolygon render of trimmed NURBS&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Micropolygon render of trimmed NURBS surfaces using Renderman from 2003. No polygon is visible as each sample gets more or less a separate polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But yes it is possible to use iteration method to solve surfaces from implicit formulations. It is typically used in raymarching contexts. The entire render engine could work by doing this its essentially a tradeof between memory and computation.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-08-02T15:49:42.180" LastActivityDate="2017-08-02T15:49:42.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5456" PostTypeId="2" ParentId="5453" CreationDate="2017-08-03T09:46:45.640" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;How should I define the &lt;code&gt;radiance&lt;/code&gt;, if I have a directional light, for example the sun?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The radiance in physics has different definitions in different books. I will use the definition with irradiance and radiant flux here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine photons having some energy $Q$. Your &lt;strong&gt;radiant flux&lt;/strong&gt; $\Phi$ is the amount of energy $Q$ (and therefore the amount of photons) per unit time $t$. To get the energy for an instant (an infinitesimally short time), you use the change ($\Delta$) of energy over the change of time for $\lim_{t\rightarrow0}$ i.e.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\Phi = \lim_{t\rightarrow0} \frac{\Delta Q}{ \Delta t} = \frac{dQ}{dt}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Energy is measured in Joules and time in seconds, therefore radiant flux is measured in $\frac{J}{s}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This however doesn't say anything about the surface you're measuring the energy at, but if you want to light an object, that needs to be taken into account.&#xA;Therefore, you define &lt;strong&gt;irradiance&lt;/strong&gt; $E$ as your radiant flux per area $A$ (note that irradiance usually means energy arriving at an area, whereas &lt;em&gt;radiosity&lt;/em&gt; is energy leaving the area, but is otherwise defined exactly the same way). Since some integrations later on are easier to do with infinitesimally small area patches, we go that route again, but I will not rewrite the limes stuff all the time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$E = \frac{d\Phi}{dA}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that it is assumed, that the photons' traveling direction is assumed to be perpendicular to the surface.&#xA;Irradiance is thus measured in $\frac{J}{sm^2}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To understand radiance, you need to understand solid angles. I will just assume that you do, otherwise read up on it, this is really an important concept for physically based lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with irradiance is, that you cannot take into consideration any directionality of the light. The directionality can be expressed through solid angles $\omega$, where an infinitesimally small solid angle $d\omega$ can be seen as a vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine that you have a sheet of paper parallel to another sheet of paper, one emitting and one receiving light, both equal in size. You can express all you need with irradiance. Now let the emitting sheet of paper transform into your light bulb centered at where the emitting sheet of paper was before. All of a sudden, it makes a difference, if you measure the light at the corners of the receiving sheet of paper or at its center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, to take directionality into account, you define &lt;strong&gt;radiance&lt;/strong&gt; $L$ as the irradiance per solid angle of the light. $\omega$ is the solid angle and we want to use the infinitessimally small one again, thus $d\omega$.&#xA;$$L = \frac{dE}{d\omega}$$&#xA;Thus your radiance is measured in $\frac{J}{sm^2sr}$ where sr is the solid angle unit steradians and really is dimensionles. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at the definitions of Watts it's $W = \frac{J}{s}$ , therefore radiance measurement can be seen as $\frac{W}{m^2sr}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 04th of August 2017:&lt;/strong&gt;&#xA;The radiance in the end is exactly what you calculate as a pixel's color, it is what you see. In the real world, it is wave length dependend, but of course in computer graphics it is an RGB color vector. Therefore, &lt;strong&gt;you don't define radiance, you calculate it.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;What should the &lt;code&gt;lightColor&lt;/code&gt; be, if the light source is a 60W lightbulb (780 lm) and in my scene one unit is one cm?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Light usually uses different wave lengths lambda which determine the color of the light. For example, imagine a photon of red light, i.e. $\lambda=700nm$ , then it has the energy of $\frac{hc}{\lambda}$ where $h$ is Planck's constant and $c$ is the speed of light, leading to about $2.838\times10^{-19}J$ for this red photon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your light bulb &quot;uses&quot; just one single wave length and is a $60W=60\frac{J}{s}$ light bulb, then you can calculate the energy, radiant flux, irradiance and finally radiance... If you know the exact spectral emission, you can also calculate this.&#xA;However, that is probably not really what you are looking for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edited 04th of August 2017:&lt;/strong&gt;&#xA;Therefore, your (or rather the tutorials code) to calculate radiance is an oversimplified way of modeling the lightsource.  It does not take into account the power of the light source directly, it is just modelled by a color vector.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;What the tutorial is asking you to do is to think of the color you want your light to be, and write down the RGB value for it. If your light is just white, use an RGB value of (1,1,1), try it in your scene and if you then think it's too bright, lower the values until you're satisfied (or increase them, if it's not bright enough).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edited 04th of August 2017:&lt;/strong&gt;&#xA;If you want to use the physically based light bulb, then you will need to take more into account and I'd really advice you to read up on this.&#xA;A good book for this is Physically Based Rendering (by Matt Pharr et al.). &#xA;As that is expensive and takes a long time to read, you can also try to get along with some of the Physically Based Shading course materials of previous years, to be found &lt;a href=&quot;http://blog.selfshadow.com/archives/&quot; rel=&quot;nofollow noreferrer&quot;&gt;on the Selfshadow Blog&lt;/a&gt;. Especially, there is some explanation on Sebastien Lagarde's &lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moving Frostbite to Physically Based Rendering&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a side note, the sun is usually modeled as being so distant to the receiver of the light, that you don't take attenuation into account. Thus you would just multiply by the light color (or set the attenuation to 1).&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="5703" LastEditDate="2017-08-17T14:06:14.830" LastActivityDate="2017-08-17T14:06:14.830" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5458" PostTypeId="1" AcceptedAnswerId="5459" CreationDate="2017-08-03T15:49:16.160" Score="3" ViewCount="836" Body="&lt;p&gt;I am writing a large 3D game in Java with OpenGL.&lt;/p&gt;&#xA;&lt;h3&gt;Question #1&lt;/h3&gt;&#xA;&lt;p&gt;As of now, I am rendering my 3D objects using a &lt;code&gt;Model&lt;/code&gt; class that I defined. This class contains vertex, color, model matrix, code (a custom attribute I defined), and index arrays. I defined a method &lt;code&gt;addModels&lt;/code&gt; that can concatenate an array of &lt;code&gt;Model&lt;/code&gt; instances into a new, larger &lt;code&gt;Model&lt;/code&gt; (it concatenates all the attribute arrays using &lt;code&gt;System.arraycopy&lt;/code&gt;). For instance, to draw a forest; for every tree, I create a &lt;code&gt;Model&lt;/code&gt;; and at the end I combine them all into one forest &lt;code&gt;Model&lt;/code&gt;, which I render. This procedure is a very &lt;em&gt;object-oriented&lt;/em&gt; way of doing it, and consists of fitting together many bundles of attribute arrays into larger ones.&#xA;Simple example code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Model[] models = new Model[trees.length];&#xA;for (int i=0; i&amp;lt;trees.length; i++) {&#xA;    models[i] = getTreeModel(trees[i]);&#xA;}&#xA;Model result = addModels(models);&#xA;return result;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However, this procedure may be bad practice memory-wise, since I create &lt;em&gt;many&lt;/em&gt; &lt;code&gt;Model&lt;/code&gt; instances per frame. (Nonetheless, I read in &lt;a href=&quot;https://softwareengineering.stackexchange.com/a/149569/279723&quot;&gt;this answer&lt;/a&gt; that objects do not take much memory.) &lt;strong&gt;Would it be better practice to lean towards a more &lt;em&gt;data-oriented&lt;/em&gt; approach; like first declaring large attribute arrays (vertex, color, etc.), and creating them individually?&lt;/strong&gt; Simple example code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float[] vertices, colors;&#xA;for (int i=0; i&amp;lt;trees.length; i++) {&#xA;    float[] treeVertices = getTreeVertices(trees[i]),&#xA;            treeColors = getTreeColors(trees[i]);&#xA;    // copy treeVertices into vertices, and treeColors into colors at appropriate positions&#xA;}&#xA;return new Model(vertices, colors);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;em&gt;Please note that either option results in&lt;/em&gt; one &lt;em&gt;model that is going to be rendered finally.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Are there any better ways of doing this?&lt;/p&gt;&#xA;&lt;h3&gt;Question #2&lt;/h3&gt;&#xA;&lt;p&gt;When I render a &lt;code&gt;Model&lt;/code&gt;, I convert each attribute array into an attribute buffer (e.g. &lt;code&gt;float[]&lt;/code&gt; into &lt;code&gt;FloatBuffer&lt;/code&gt;). Would it make my game run faster to, first, load data into a buffer without using the array at all? (I'm using arrays because they're easier for me to manipulate.)&lt;/p&gt;&#xA;&lt;h3&gt;Question #3&lt;/h3&gt;&#xA;&lt;p&gt;Would it be more efficient to call &lt;code&gt;glBufferSubData&lt;/code&gt; then to concatenate all the attribute arrays into longer ones and then call &lt;code&gt;glBufferData&lt;/code&gt; (or a similar method)?&lt;/p&gt;&#xA;&lt;h3&gt;Question #4&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://learnopengl.com/#!Model-Loading/Model&quot; rel=&quot;nofollow noreferrer&quot;&gt;One tutorial&lt;/a&gt; I read defined a &lt;code&gt;Model&lt;/code&gt; class as containing multiple &lt;code&gt;Mesh&lt;/code&gt;s. &lt;em&gt;Then, they drew each mesh separately to the screen.&lt;/em&gt; Is this good practice if I have a lot of meshes (trees) per model (forest)? I heard it isn't good to make a lot of &lt;code&gt;glDraw*&lt;/code&gt; calls.&lt;/p&gt;&#xA;" OwnerUserId="6883" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-08-03T16:07:23.753" Title="Most efficient way to render many OO meshes in OpenGL" Tags="&lt;opengl&gt;&lt;mesh&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5459" PostTypeId="2" ParentId="5458" CreationDate="2017-08-03T16:07:23.753" Score="2" Body="&lt;p&gt;Don't copy around huge chunks of data if you don't have to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would delay collecting and building the final forest mesh for as long as possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However when you have multiple of the same mesh that just needs to be translated and rotated a bit you can use instancing. Which lets you draw thousands of copies of a tree with a single draw call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most efficient way of getting data to the gpu is to map the buffer and fill that. In java that means using a Buffer.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-08-03T16:07:23.753" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5460" PostTypeId="1" AcceptedAnswerId="5461" CreationDate="2017-08-03T20:22:18.907" Score="3" ViewCount="115" Body="&lt;p&gt;I was told that human's visual sharpness is 60 pixels per degree. As such, pixel per inch is approximately given by:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PPI = 1/ (Distance * tg((1/60*pi/180) )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is this formula fully correct? (I saw similar, but slightly different versions). How is this formula derived? Maybe some step by step description?&lt;/p&gt;&#xA;" OwnerUserId="4678" LastEditorUserId="38" LastEditDate="2017-08-05T17:27:39.783" LastActivityDate="2017-08-05T17:27:39.783" Title="human visual: relation of Distance and DPI" Tags="&lt;computational-geometry&gt;&lt;2d&gt;&lt;pixel-graphics&gt;&lt;pixels&gt;&lt;human-vision&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5461" PostTypeId="2" ParentId="5460" CreationDate="2017-08-04T15:43:36.317" Score="3" Body="&lt;p&gt;According to a review by Legge &amp;amp; Bigelow the arc or degrees of visual angle ($\alpha$) is,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\alpha = 57.3 \times S/D,&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where S is height of object and D is distance to object. [1] $S/D$ is the small angles approximation of $2 \times arctan(S/2D)$ which follows form geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/168C3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/168C3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: the equation comes straight from trigonometric definitions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since humans continuously scan the page with the fovea, small angles assumption is a good approximation for entire pages. The factor $57.3$ is simply $180/\pi$ or conversion form radians to angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So given that we do not know the nature of $tg$, then its hard to say. Looks a bit fishy, but if tg is some sort of inversion of S then its plausible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[1] G. Legge &amp;amp; C Bigelow. 2011. Jornal of vision. &lt;a href=&quot;http://jov.arvojournals.org/article.aspx?articleid=2191906&quot; rel=&quot;nofollow noreferrer&quot;&gt;Does print size matter for reading? A review of findings from vision science and typography&lt;/a&gt;. &lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-08-04T15:48:47.340" LastActivityDate="2017-08-04T15:48:47.340" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5462" PostTypeId="1" CreationDate="2017-08-04T17:10:52.993" Score="2" ViewCount="296" Body="&lt;p&gt;I am in the process of creating some software in Java for generating 3D gear geometry and saving it as an STL file. I am looking at a means of drawing the geometry so that the user can view the geometry before saving as an STL file. The intended result should appear along the lines of the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V9Szm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V9Szm.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;(MeshLab)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far, rendering using &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Ray_casting&quot; rel=&quot;nofollow noreferrer&quot;&gt;ray casting&lt;/a&gt; appears to be the best way to approach this. For each pixel, a ray is extended out from the camera in the appropriate direction and its intersection with the triangles that make up the geometry is tested, keeping the closest intersection: simple in concept, doesn't mess around with unnecessary effects, and seems like it should run fast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main concern is: will it render fast enough? In my program, it should be possible to rotate and pan the visualisation, and have it render on the fly. My concern stems from this: the largest screen I want to draw the visualisation on will be 1280px by 800px (although in general use it may be somewhat less than this), which means up to 1024,000 pixels need to be processed, and so an equal number of rays will be projected. In each 3D geometric part, there could easily be upward of thousands of triangular facets. That already means have to perform at least $10^9$ operations, a number similar to the order of magnitude of operations per second. Surely it appears ray-casting won't run fast enough, especially if you want to refresh the visualisation at a rate of 10Hz.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is done to ensure that the rendering is done quickly enough? Is it a matter of using a single ray for every 2x2, 3x3 or larger sub-array of pixels? Is an alternative algorithm to ray casting used? There certainly appears to be a solution to this, as STL visualisation software is not a new thing, with the app MeshLab and the site &lt;a href=&quot;http://viewstl.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;viewstl.com&lt;/a&gt; being perfectly adequate.&lt;/p&gt;&#xA;" OwnerUserId="7108" LastActivityDate="2017-08-04T17:10:52.993" Title="Rendering of large STL files" Tags="&lt;rendering&gt;&lt;3d&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5463" PostTypeId="1" CreationDate="2017-08-04T17:55:03.860" Score="3" ViewCount="675" Body="&lt;p&gt;Two questions which cross over maths/3D imaging/computer science. I'm trying to describe a point of view of an item in a 3d space and subsequently its rotation in a paper I'm writing. Versions I've had read have confused readers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The scene is as illustrated in the attached image - we are looking on as it were from the left-hand side of the scene.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How should I describe the view of the object from the eye symbol? I've termed it a &quot;thirty degree elevated front view&quot; - it's the 'front' that I think is most problematic.&lt;/li&gt;&#xA;&lt;li&gt;Then if the object is rotated backwards along the x axis how do I describe that? I've said &quot;transformation, specifically a rotation seventy degrees backwards along the x axis&quot;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Are these the correct way of describing this point of view and rotation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lPICy.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lPICy.jpg&quot; alt=&quot;point of view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7109" LastActivityDate="2017-09-04T14:29:40.150" Title="Point of view and rotation" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;perspective&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5464" PostTypeId="1" CreationDate="2017-08-04T19:49:20.240" Score="1" ViewCount="56" Body="&lt;p&gt;Say I have two squares, both 10x10, with some small, unknown overlap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to draw the intersection of these two squares using the width, height and x,y coordinates of each square, while also not using an if statement?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="7111" LastActivityDate="2017-08-05T12:20:52.950" Title="Is it possible to draw the intersection of two squares of known dimension using only x,y coordinates and without an if statement?" Tags="&lt;geometry&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5465" PostTypeId="1" AcceptedAnswerId="5466" CreationDate="2017-08-04T20:06:04.727" Score="18" ViewCount="19047" Body="&lt;p&gt;In film school, in the classes of 3D modeling, I was told that when we model something for films we maintain topology of 4 edged polygons. Any polygon which has more or less than 4 edge/vertex is considered bad and should be avoided. Whereas if the same model is used in games, it is triangulated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although I'm not majoring in 3D modeling, the question is still in my mind. Why is 3 edged polygon used in gaming? Does it render faster? Then why not is it used in film renderings?&lt;/p&gt;&#xA;" OwnerUserId="6749" LastActivityDate="2020-09-02T21:23:02.840" Title="Why are quads used in filmmaking and triangle in gaming?" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;triangulation&gt;" AnswerCount="5" CommentCount="2" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5466" PostTypeId="2" ParentId="5465" CreationDate="2017-08-04T23:44:51.457" Score="21" Body="&lt;p&gt;For 3D modeling, the usual reason to prefer quads is that &lt;a href=&quot;https://en.wikipedia.org/wiki/Subdivision_surface&quot; rel=&quot;noreferrer&quot;&gt;subdivision surface&lt;/a&gt; algorithms work better with them—if your mesh is getting subdivided, triangles can cause problems in the curvature of the resulting surface. For an example, take a look at these two boxes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/xvA7K.png&quot; alt=&quot;original boxes&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The left one is all quads; the right one has the same overall shape, but one corner is made of triangles instead of quads.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now see what happens when the boxes get subdivided:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/jVesy.png&quot; alt=&quot;subdivided boxes, wireframe&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Different, yeah? Note the way the edge loops have changed from being roughly equidistant on the left box to a more complicated, pinched-and-stretched arrangement on the right. Now let’s turn off the wireframe and see how it’s getting lit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/tHNoz.png&quot; alt=&quot;subdivided boxes, smooth&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See the weird pinching in the highlight on the right box? That’s caused by the messy subdivision. This particular one is a pretty benign case, but you can get way more messed-up-looking results with more complex meshes with higher subdivision levels (like the ones you’d usually use in film).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;All of this still applies when making game assets, if you’re planning to subdivide them, but the key difference is that the subdivision happens &lt;strong&gt;ahead of time&lt;/strong&gt;—while you’re still in quad-land—and then the final subdivided result gets turned into triangles because that’s what the graphics hardware speaks (because, as mentioned in the comments above, it makes the math easier).&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2017-08-04T23:44:51.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5467" PostTypeId="2" ParentId="5464" CreationDate="2017-08-05T03:32:17.380" Score="1" Body="&lt;h2&gt;Basic calculations&lt;/h2&gt;&#xA;&lt;p&gt;I'm assuming you want to calculate the bounds of the rectangle of intersection, so you can draw it later. As AlanWolfe mentioned, you will want to use the max and min functions. This is so you can retrieve the left-most, right-most, top and bottom squares. We'll call these placeholders &lt;code&gt;right&lt;/code&gt;, &lt;code&gt;bottom&lt;/code&gt;, &lt;code&gt;left&lt;/code&gt;, and &lt;code&gt;top&lt;/code&gt; (each of these will point to one of the two squares).&lt;/p&gt;&#xA;&lt;p&gt;Now that you know these, you can start mathing. The top-left position of the intersection will be at &lt;code&gt;(right.x_left, bottom.y_top)&lt;/code&gt;. The bottom-right position of the intersection will be at &lt;code&gt;(left.x_left + left.width, bottom.y_top + bottom.height)&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;h2&gt;Rendering the intersection&lt;/h2&gt;&#xA;&lt;p&gt;To draw this rectangle (unconditionally), first you will need a location and a dimension, because most draw functions require these.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Intersection.width = Intersection.x_right - Intersection.x_left&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and the same for the height. Now suppose the squares don't overlap. This would mean at least one dimension is negative. We don't want anything to draw in this case, so we will set any negative dimensions to zero.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Intersection.width = max(Intersection.width, 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and the same for the height. And to wrap up, we render our rectangle:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;fillRect(Intersection.x_left, Intersection.y_top, Intersection.width, Intersection.height)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6883" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-08-05T12:20:52.950" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5468" PostTypeId="2" ParentId="5463" CreationDate="2017-08-05T04:11:27.000" Score="1" Body="&lt;p&gt;You could phrase it in terms of elevation away from various planes. So 30° above the x-z plane, and 0° from the y-z plane (or whatever it actually is). It's sort of like &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_coordinate_system&quot; rel=&quot;nofollow noreferrer&quot;&gt;spherical coordinates&lt;/a&gt; where you'd have theta and phi.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-08-05T04:11:27.000" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5469" PostTypeId="1" AcceptedAnswerId="5471" CreationDate="2017-08-05T06:08:50.727" Score="4" ViewCount="293" Body="&lt;p&gt;I am experimenting on a simple wave tessellation shader. I ported it from a working vertex shader. When my frequency is higher than 1, I get strange &quot;saw-tooth&quot; artifacting at peaks of the wave. Here are some images with a frequency of 3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/evCYZ.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/evCYZ.jpg&quot; alt=&quot;Wireframe artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gGZdw.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gGZdw.png&quot; alt=&quot;Artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I keep the frequency lower, it is smooth as butter. Any ideas what the problem could be?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 410 core&#xA;layout(quads, equal_spacing, ccw) in;&#xA;in vec2 teUv[];&#xA;out vec2 fUv;&#xA;out vec4 fWorld_pos;&#xA;uniform mat4 VP;&#xA;uniform mat4 M;&#xA;uniform sampler2D water_disp;&#xA;uniform float time;&#xA;const float M_PI = 3.1415926535;&#xA;&#xA;float water_displacement(vec2 pos) {&#xA;    const float freq = 3.0; // &amp;lt;-- This is the problematic value.&#xA;    float d = length(pos);&#xA;    return (0.5 + 0.5 * sin(-M_PI * d * freq + time));&#xA;}&#xA;&#xA;void main() {&#xA;    vec4 p1 = mix(gl_in[0].gl_Position,&#xA;            gl_in[1].gl_Position,&#xA;            gl_TessCoord.x);&#xA;    vec4 p2 = mix(gl_in[2].gl_Position,&#xA;            gl_in[3].gl_Position,&#xA;            gl_TessCoord.x);&#xA;    vec4 local_pos = mix(p1, p2, gl_TessCoord.y);&#xA;    fWorld_pos = M * local_pos;&#xA;    fWorld_pos.y += water_displacement(fWorld_pos.xz);&#xA;&#xA;    gl_Position = VP * fWorld_pos;&#xA;&#xA;    vec2 uv1 = mix(teUv[0], teUv[1], gl_TessCoord.x);&#xA;    vec2 uv2 = mix(teUv[2], teUv[3], gl_TessCoord.x);&#xA;    fUv = mix(uv2, uv1, gl_TessCoord.y);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And more examples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QE8Xq.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QE8Xq.png&quot; alt=&quot;Smooooth (freq = 0.5)&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dM5X5.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dM5X5.jpg&quot; alt=&quot;Not so smooth (freq = 8)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5978" LastEditorUserId="5978" LastEditDate="2017-08-05T06:39:35.653" LastActivityDate="2017-08-05T17:26:16.053" Title="Tesselation sine distortion?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;artifacts&gt;&lt;tesselation&gt;&lt;distortion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5470" PostTypeId="2" ParentId="5443" CreationDate="2017-08-05T06:26:59.333" Score="-1" Body="&lt;p&gt;I personally like glad. The have an online generator as well &lt;a href=&quot;http://glad.dav1d.de&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://glad.dav1d.de&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It will generate exactly what you need for your platform.&lt;/p&gt;&#xA;" OwnerUserId="5978" LastActivityDate="2017-08-05T06:26:59.333" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5471" PostTypeId="2" ParentId="5469" CreationDate="2017-08-05T06:50:10.237" Score="5" Body="&lt;p&gt;Not enough triangles. The situation is analogous to the sampling theorem that states that you can not reconstruct a signal if your sample frequency is below a certain threshold. Although in this, case you're not attempting to rebuild the signal with a higher order filter so the result is even more dramatic. And it results in interpolation errors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can alleviate the problem with less points if your point wavefront follows your waves. So you may want to shift points towards the gradient maximum in other directions than UP.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-08-05T17:26:16.053" LastActivityDate="2017-08-05T17:26:16.053" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5472" PostTypeId="1" AcceptedAnswerId="5473" CreationDate="2017-08-05T19:53:42.923" Score="3" ViewCount="46" Body="&lt;p&gt;Lets say i have a picture. I send it to a server. While sending it to the server half way  the upload gets canceled. Now the server has half or some of the picture. Now is there a way in which this can be  processed and viewed. Are there any formats which support this? And are there any other factors which account as to why the picture can or cannot be processed?&lt;/p&gt;&#xA;" OwnerUserId="7115" LastActivityDate="2017-08-05T20:51:59.693" Title="can half of a picture be processed and viewed?" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5473" PostTypeId="2" ParentId="5472" CreationDate="2017-08-05T20:44:20.333" Score="1" Body="&lt;p&gt;Yes, most formats work this way! For example JPEG can be decoded up to the point where the chunks are available:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Gmc2f.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Gmc2f.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt; Scaled version of original JPEG picture at (1 048 198 bytes) and corrupted one (610 922 bytes) side by side. Original image by &lt;em&gt;Maruf Mostafa&lt;/em&gt; image available &lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Colored_Duck.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is easy for you to test take an image and just simply delete some bytes out of it (like with a text editor). Some files are easy just open them, like the JPEG in question that just opens up in many editors without a hitch. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PNG required some slight special handling to uncompress. It did't open in Photoshop or windows image preview. But was still relatively straightforward to open as the web browser happily opened even partial PNG files to the point it was defined to.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-08-05T20:51:59.693" LastActivityDate="2017-08-05T20:51:59.693" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5474" PostTypeId="1" CreationDate="2017-08-05T22:25:31.997" Score="2" ViewCount="33" Body="&lt;p&gt;In the early 3D Studio days before it got Max in its name it was possible to make a 3d object by defining its projections in xy, xz and yz plane. 3ds would then interpolate a 3d object from the projections. I cannot remember what was the name of this method and how it was exactly done, so I don't know which words to google. Essentially I want to use this method in Max if it is possible anymore. Can somebody give me a hint for keywords or even better explain the procedure in 3ds max?&lt;/p&gt;&#xA;" OwnerUserId="7116" LastActivityDate="2017-08-05T22:25:31.997" Title="Make 3d objects from 3 projections in 3D Studio Max" Tags="&lt;projections&gt;&lt;interpolation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5475" PostTypeId="2" ParentId="5465" CreationDate="2017-08-06T12:40:31.687" Score="2" Body="&lt;p&gt;One thing i see most people forget is in film making it's mostly about quality not speed. That's cause film making is concerned more with Offline rendering where as in Video games it's all real time so performance/speed is much more crucial than quality.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence when it comes to video games people try to find the best way to &quot;approximate&quot; or &quot;fake&quot; the look of a real thing. When it comes to different calculations and speed triangles are much more easier than polygons. Like @ratchet freak mentioned as all the 3 points are coplanar and it simplifies intersections and other calculations. That's one of the main reasons triangles are used in video-games.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However in film making rendering one frame can take hours or even days, hence speed isn't that much of an issue. What Noah said is correct, i just wanted to share this point of view as well.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-08-06T12:40:31.687" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5477" PostTypeId="2" ParentId="5465" CreationDate="2017-08-06T13:48:19.513" Score="8" Body="&lt;p&gt;As @Noah Witherspoon correctly, says triangle subdivision does not work as well as quad subdivision. Although, in the beginning triangles could not be subdivided at all. However, he does not really explain why that is the case. Which is useful information and explains why quads are preferred and how to use them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, observe that a triangle does gets subdivided into 3 quads in many schemes. Since you now have a all quad mesh, clearly keeping the subdivision all quad is not in itself the requirement. There has to be a more profound reason than just being four sided.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/d9TRb.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d9TRb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: You can subdivide a triangle into 3 quadrangles&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason lies in what has become called edge loops. The person doing the modeling have to anticipate how the subdivision happens as the subdivision is going to be the final shape. Unfortunately humans are only really good at deciphering the shape of the object along the edges of your primitives edges. By formulating the shape into continuous multi edge long loops helps us predict the shape after subdivision and importantly after deformation by bones etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A triangle has a nasty way of terminating the loop so we do not understand what happens with the shape within and out of that shape. The subdivided mesh thus has a tendency to behave uncontrollably, causing undesired bumps. &lt;strong&gt;Note&lt;/strong&gt;: It is possible to subdivide triangles in a way that this does not happen, they are just harder to work with and working with quads were well known by then.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now this is not actually the original reason, only it happened in roundabout way. The original reason what that the geometrical patches that they did use a as parametric primitives are square in shape. As extending a line into a surface naturally takes a square shape if you just extrude out. Having a triangle causes one edge to be degenerate and have a singularity. But this is very much related to the subdividing reason as it can be shown that a subdivision surface is just a  general case of a spline patch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GRFa8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GRFa8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Image 2&lt;/strong&gt;: Original parametric surfaces were extensions of curves, not arbitrary meshes and these shapes naturally tend to be square.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-08-06T13:59:43.243" LastActivityDate="2017-08-06T13:59:43.243" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5478" PostTypeId="2" ParentId="306" CreationDate="2017-08-06T16:26:37.153" Score="1" Body="&lt;p&gt;I am by no means an expert on the subject, but you might be able to, at least in theory, preserve sharp corners in a monochromatic pseudo-SDF if you used either a Bilateral filter a Directional Bicubic filter instead of a standard Bilinear filter. Besides the obvious benefit of saving memory, you could also have multiple channels for multi-colored SDF decals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, if you don't mind using a second channel, then you could also try having one channel for Horizontal Distance and another for Vertical Distance, and use a Difference of Laplacean (DoL) energy pyramid to compress the texture so that redundant information wouldn't be recorded.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A third and final theoretical solution would be to experiment with a Hexagonally Sampled Texture via Array Set Addressing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, I don't have any means of testing my ideas currently, and have been unable to find any documents describing or testing anything similar to my ideas. I will link all of the relevant articles where I got my information/ideas shortly.&lt;/p&gt;&#xA;" OwnerUserId="7119" LastEditorUserId="7119" LastEditDate="2017-08-06T16:40:20.090" LastActivityDate="2017-08-06T16:40:20.090" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5479" PostTypeId="1" CreationDate="2017-08-07T19:40:47.790" Score="1" ViewCount="68" Body="&lt;p&gt;I'm mainly trying to understand what it means for Monte Carlo samples to be correlated. Can somebody fit this into the theory of what I know about random variables, covariance and correlation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then specifically, when it comes to Monte Carlo path tracing (within the path integral formulation), what would the paths be analogous to? Let's say I have two variables producing paths of length $l$. The way I understand it right now is that they produce samples from a $3l$-dimensional space -- 3 cartesian coordinates, one for each point on the path. Is this correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I had two random variables generating paths of some length $l$, how would I measure the correlation?&lt;/p&gt;&#xA;" OwnerUserId="6367" LastActivityDate="2017-08-07T19:40:47.790" Title="Sample Correlation and Random Variables -- An Intuitive Explanation?" Tags="&lt;pathtracing&gt;&lt;sampling&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5480" PostTypeId="1" CreationDate="2017-08-08T10:28:34.570" Score="1" ViewCount="123" Body="&lt;p&gt;Being confused about the example of Combining Stratified Sampling and Importance Sampling in &lt;em&gt;Advanced Global Illumination&lt;/em&gt; (P72,P73).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bskvn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bskvn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/huQTU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/huQTU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know how to do importance sampling and stratified sampling. But I can't understand this example and the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this example to calculate $S$ stochastically or to get a random number $u$?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the $u$ for?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the meaning of &quot;Sample the $i$th term of the sum $N_i$ times&quot;?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="5944" LastEditDate="2017-08-09T13:46:06.740" LastActivityDate="2017-08-09T13:46:06.740" Title="An example of Combining Stratified Sampling and Importance Sampling in AGI" Tags="&lt;sampling&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5482" PostTypeId="1" CreationDate="2017-08-09T14:04:42.447" Score="7" ViewCount="18185" Body="&lt;p&gt;What is the difference between glossy and specular reflection?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is their relations with BRDF?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mqALR.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mqALR.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ic1g1.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ic1g1.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/gIaQ5.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gIaQ5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="5944" LastEditDate="2017-08-10T03:58:21.990" LastActivityDate="2017-08-16T15:27:36.590" Title="What is the difference between glossy and specular reflection?" Tags="&lt;brdf&gt;&lt;reflection&gt;&lt;specular&gt;&lt;material&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5483" PostTypeId="1" CreationDate="2017-08-09T14:05:49.567" Score="1" ViewCount="302" Body="&lt;p&gt;Nvidia in &lt;a href=&quot;http://developer.download.nvidia.com/assets/gamedev/files/sdk/11/OpacityMappingSDKWhitePaper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; presented a way to upsample low res buffer to full res buffer called Nearest Depth Upsampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This works by comparing four depth values from downsampled low res depth buffer with current value of full res depth buffer and selecting texcoords where difference is minimal to sample the low res buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the article they stated the four places to sample as &quot;bilinear footprint of the current full res pixel&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the picture, the circle marks the texcoord of one of the fragments of full res buffer. So if full res is 4x4 then low res is 2x2. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JFfPw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JFfPw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunaltely it is not clear to me how to sample the low res buffer correctly. My question are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;What are locations of the four samples used to sample low res buffer in relation to current texcoords of full res buffer?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Is downsampling depth using just hardware interpolation is enough?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Can I upsample not only half res buffer but also quarter res buffer to full res?&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2017-08-09T14:05:49.567" Title="Nearest depth upsampling" Tags="&lt;texture&gt;&lt;glsl&gt;&lt;sampling&gt;&lt;supersampling&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5484" PostTypeId="2" ParentId="5482" CreationDate="2017-08-09T14:22:33.817" Score="6" Body="&lt;p&gt;The charts you show aren't showing two different phenomena - &quot;glossy reflection&quot; and &quot;specular reflection&quot; - they're showing two parameters of specular reflection. One is the &lt;em&gt;specularity&lt;/em&gt; or &lt;em&gt;specular colour&lt;/em&gt; and gives the amount or brightness of the specular reflection. The other is the &lt;em&gt;glossiness&lt;/em&gt; or &lt;em&gt;roughness&lt;/em&gt; and shows how sharp the specular reflection is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Put another way, if you picture the curve of the specular reflection over changing angle, the specularity (the vertical axis on your charts) gives the height of the peak - the maximum brightness - and the glossiness gives the width of the peak - the size of the highlight. The highlight gets narrower with increasing glossiness, whereas roughness is the inverse of this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;BRDF&lt;/em&gt; is more general: it's a function that tells you how much light is reflected in a given direction (view direction) from a given direction (light direction). Usually (for most materials) we approximate a BRDF using a &lt;em&gt;diffuse term&lt;/em&gt; and a &lt;em&gt;specular term&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-08-09T14:22:33.817" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5485" PostTypeId="2" ParentId="5482" CreationDate="2017-08-09T15:55:00.263" Score="0" Body="&lt;p&gt;In the book Computer Graphics Principles and Practice, they use the term specular reflection when they want to imagine things resembling a mirror and glossy reflection when things like a polished door knob or an orange skin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The charts shows you exactly that. When a material has more specular color, it should have less diffuse color due to the conservation of energy. That is, the sum of the light reflected specularly and light absorbed and emitted in random directions must be less than equal to 100% (the amount of light incident on the surface). Hence when you increase the specular color the material tends to go white or have a slight tint of the color like in metals. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where as glossy surfaces can have more diffuse color but show a specular highlight like the surface of an orange skin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So assuming the CGPP's point of view, we can say in pure specular reflection, the diffuse part is much less than the glossy part. Where as in glossy reflection the diffuse part is usually greater.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2017-08-09T16:02:45.520" LastActivityDate="2017-08-09T16:02:45.520" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5486" PostTypeId="1" AcceptedAnswerId="5488" CreationDate="2017-08-10T02:57:16.860" Score="6" ViewCount="1580" Body="&lt;p&gt;In my opinion, geometric surface normal is the cross product of triangle edge vectors, and shading surface normal is the interpolation of the predefined normals at the three vertexes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used Mitsuba to render the geometric normal channel and the shading normal channel:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;geometric normal:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Slwfb.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Slwfb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;shading normal:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/TOW4d.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TOW4d.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="5944" LastEditDate="2017-08-10T03:30:17.840" LastActivityDate="2017-08-10T08:54:46.260" Title="What's the difference between geometric surface normal and shading surface normal?" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5487" PostTypeId="1" CreationDate="2017-08-10T06:15:27.740" Score="2" ViewCount="151" Body="&lt;p&gt;Are there some tools or softwares to merge multiple exr into a single multilayer exr?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I only find a tool to split a multilayer exr into multiple exr.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And it seems that Blender, Mitsuba, Darktable all can't do this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I write a tool myself using OpenEXR?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2017-08-10T06:15:27.740" Title="How to merge multiple exr into a single multilayer exr?" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5488" PostTypeId="2" ParentId="5486" CreationDate="2017-08-10T08:54:46.260" Score="3" Body="&lt;p&gt;Your existing opinion is correct, though there's one extra detail. The geometric normal is the normal of the actual triangle, based on the vertices' positions (the cross-product of edge vectors, as you said). The shading normal is altered from this, and is used when shading a fragment or ray hit. In the simple case, it's the interpolation of the three normals set at the vertices. This is used for curved objects to hide the polygon boundaries. It might also be modified by a bump map or normal map, to add finer detail to the appearance than the polygon mesh has.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-08-10T08:54:46.260" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5489" PostTypeId="1" CreationDate="2017-08-10T09:26:23.707" Score="3" ViewCount="971" Body="&lt;p&gt;Today I found something really interesting (I've never seen something like that). While debugging the buffers used in lightning, I see that the depth information is stored in what looks like cascades of depth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/brV9I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/brV9I.png&quot; alt=&quot;UE4 Depth Buffer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's going on there? Is that a technique to improve depth precision?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7107" LastActivityDate="2017-09-14T14:39:43.210" Title="How does UnrealEngine handle depth?" Tags="&lt;lighting&gt;&lt;depth-map&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5490" PostTypeId="1" CreationDate="2017-08-10T12:25:57.527" Score="1" ViewCount="62" Body="&lt;p&gt;Let's say I have a lighting lobe represented as a ndotl ramp texture, how do I compress it into a zonal harmonic?&lt;/p&gt;&#xA;" OwnerUserId="7138" LastActivityDate="2019-08-09T16:07:37.400" Title="Lighting ramps compressed to zonal harmonics" Tags="&lt;lighting&gt;&lt;spherical-harmonics&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5491" PostTypeId="1" CreationDate="2017-08-11T02:47:36.090" Score="2" ViewCount="548" Body="&lt;p&gt;Get the title problem when implementing a walkthrough camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use normlize(cross(WorldUp, Front)) to get Right vector. And when they are collinear, I get a zero vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any more robust fake version? Or do I need to store the &quot;previous&quot; Right vector as a backup?&lt;/p&gt;&#xA;" OwnerUserId="5646" LastActivityDate="2017-09-11T21:11:12.360" Title="How to get camera Right vector when Front vector and WorldUp vector are collinear" Tags="&lt;transformations&gt;&lt;camera&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5492" PostTypeId="2" ParentId="5491" CreationDate="2017-08-11T16:05:54.240" Score="1" Body="&lt;p&gt;You can't have a camera with collinear look/front and up vectors. It doesn't make geometric sense. The whole point of the up vector is to disambiguate roll.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As russ says, for a &quot;first-person&quot; camera it's reasonable to always use world-up for the up vector and simply lock the pitch angle to within (say) 85 degrees of horizontal, to avoid degenerate cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a CAD viewer where the user would expect to pitch the camera arbitrarily, you should rotate &lt;strong&gt;both&lt;/strong&gt; the up and front vectors about the right vector when the user pitches the camera, to ensure they are always perpendicular. Beware that when you do this kind of arbitrary rotation, it's easy for the user to get stuck in unfortunate roll angles. You need to do at least one of the following to let them get themselves out:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Have a &quot;reset up&quot; button that applies the pitch angle limits and resets the up vector to world up.&lt;/li&gt;&#xA;&lt;li&gt;Give the user arbitrary control over camera roll. (This can be confusing, so it's best to offer the first option as well if you do this.)&lt;/li&gt;&#xA;&lt;li&gt;Constrain the up vector so that its dot product with the world up is non-negative. That is, if the user pitches so far up or down that they are upside-down, roll the camera 180 degrees.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-08-11T16:05:54.240" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5494" PostTypeId="1" AcceptedAnswerId="5496" CreationDate="2017-08-12T20:24:14.457" Score="4" ViewCount="264" Body="&lt;p&gt;Currently I'm 16 and in high school and I love graphics programming and I'm seriously considering it as a career path. I was wondering what a day as a graphics programmer looks like for offline Rendering (path tracing).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since were close to hitting photorealism now it seems like the only main challenge for the next decade is performance. I've been digging through the recent SIGGRAPH papers for the Future directions for rendering but haven't found much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what kinda tasks can graphics programmers do these days? Working on performance can't be the only thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, is a lot of the work research based as opposed to traditional programming? &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-08-13T02:06:13.890" Title="Tasks of a professional graphics programmer?" Tags="&lt;pathtracing&gt;&lt;performance&gt;&lt;pbr&gt;&lt;photo-realistic&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5495" PostTypeId="2" ParentId="5491" CreationDate="2017-08-12T20:34:06.070" Score="1" Body="&lt;p&gt;First of all instead of taking &lt;code&gt;Cross(WorldUp, Front/LookAt)&lt;/code&gt; you can use Gram-Schmidt orthogonalization to produce an orthogonal vector that's close to the WorldUp vector. Then you take the cross of this orthogonal vector and the look at to get the side vector. However as you mentioned this'd fail if the vectors are parallel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence the usual solution is to pick another vector that's not parallel to the look at one and again use Gram-Schmidt orthogonalization to produce the orthogonal vector ( camera up) and then take the cross.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The maths is like this. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;CameraUp = c&#xA;WorldUp = w&#xA;LookAt = l&#xA;&#xA;c = w - ( (w.l) / ||l||^2 ) * l &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What it does is this. We know that world up isn't pure orthogonal to the look at vector. So we take the projection of world up onto the direction of the look at vector. Subtract the parallel part of this projection from the world up vector to obtain the remaining i.e. the orthogonal part. This vector is closer to the world up but is purely orthogonal to the look at vector.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-08-12T20:34:06.070" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5496" PostTypeId="2" ParentId="5494" CreationDate="2017-08-13T02:06:13.890" Score="6" Body="&lt;p&gt;I don't know if this is exactly what you're looking for. I work tangentially in the film and TV industry. I don't work for a studio, but I work on the software that studios use for their productions. It's software that any user could buy if they wanted to, but it has been used in feature films, television shows, commercials, music videos, and more.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About half of my time is spent programming and debugging. This is the fun stuff. It involves implementing rendering and filters of various types, sometimes based on papers I've read from SIGGRAPH or cool web sites or book. I don't do very much user interface work, though there is some. I work with OpenGL and Metal mostly. I need to know image processing algorithms in addition to general computer science algorithms, like graph processing and traversing, for example. This includes dealing with source control, continuous integration, stepping through code to find and fix bugs, talking to QA about problems, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other half of my time is spent doing non-programming things. This is a variety of things like attending conferences to learn (things like the Game Developers Conference or SIGGRAPH), conventions to promote the company and/or product (things like NAB, IBC, etc.), answering tech support emails and writing sample code (we have an API so 3rd parties can extend our product), attending meetings (scrum, management updates, company-wide meetings, etc.), talking with marketing about how our new features work, meeting with customers to understand how they use the product, explaining to our documentation people how the product works so they can document it, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems like a pretty similar breakdown to other programming jobs in other industries from talking to my friends who work in other areas.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-08-13T02:06:13.890" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5497" PostTypeId="1" CreationDate="2017-08-14T10:00:35.807" Score="0" ViewCount="144" Body="&lt;p&gt;I'm doing some parallel computing using my GPU. When I used glDispatchCompute first the program crashed after a few seconds which I found out was due to TDR. I deactivated TDR using the registry key TdrLevel and setting it to 0. Now it works for up to a few minutes but if the computation takes too long (about 3+ minutes) the function seems to return but then the program instantly crashes. Any ideas what the problem could be? The function always seems to fully execute, even if it takes 30 minutes to do so but right after that the program crashes which makes me think that it is not just another layer of TDR because it would probably kill the program after a certain amount of time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&#xA;There is an error message: &quot;Unable to communicate with display driver&quot; and &quot;Error code 2&quot;.&#xA;I'm using a Nvidia Quadro M2000M, newest drivers are installed. TDR is disabled and Nvidia energy options are set to maximum (from adaptive).&lt;/p&gt;&#xA;" OwnerUserId="7151" LastEditorUserId="7151" LastEditDate="2017-08-14T11:28:05.703" LastActivityDate="2017-08-14T11:28:05.703" Title="C++/OpenGL program crashes after return of glDispatchCompute function (TDR related?)" Tags="&lt;opengl&gt;&lt;gpgpu&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5498" PostTypeId="1" AcceptedAnswerId="5499" CreationDate="2017-08-14T17:43:49.423" Score="4" ViewCount="2954" Body="&lt;p&gt;I'm implementing normal mapping on my toy pathtracer. I need to compute the tangent (and bitangent) of any sphere point in order to create the matrix that will transform tangent space to world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More specifically, I want the tangent that runs along the u texture coordinate, and the bitangent that runs along the v coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's how I implemented it:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;At the intersection point P, compute the spherical coordinates&#xA;(theta, phi) of P.&lt;/li&gt;&#xA;&lt;li&gt;Add a tiny delta to the angle that relates to the u texture&#xA;coordinate (phi), finding another point Q on the sphere.&lt;/li&gt;&#xA;&lt;li&gt;Compute Q - P and normalize it to have the tangent.&lt;/li&gt;&#xA;&lt;li&gt;The bitangent is then computed by doing the cross product of the&#xA;tangent and the normal at the point P.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Relevant code on the sphere collision function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    hitRecord.point = ray.pointAtParameter(t);&#xA;&#xA;    Vec3 localCoord = hitRecord.point - center;&#xA;    float theta = asin(localCoord.y / radius); //[-pi/2,pi/2]&#xA;    float phi = atan2(localCoord.z, localCoord.x); //[-pi,+pi]&#xA;&#xA;    float deltaPhi = phi + FLOAT_BIAS;&#xA;    Vec3 deltaPoint(radius * cos(theta) * cos(deltaPhi),&#xA;        radius * sin(theta),&#xA;        radius * cos(theta) * sin(deltaPhi));&#xA;&#xA;    //Assume local space to be aligned with world space&#xA;    //So this is also the tangent in world space&#xA;    hitRecord.tangent = deltaPoint - localCoord;&#xA;    hitRecord.tangent.normalize();&#xA;&#xA;    hitRecord.normal = localCoord / radius;&#xA;    hitRecord.bitangent = hitRecord.tangent.cross(hitRecord.normal);&#xA;    hitRecord.bitangent.normalize();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This seems to work, but all this trigonometry is not light and makes me wonder if there is a better way of doing it. Does anyone has any ideias/pointers?&lt;/p&gt;&#xA;" OwnerUserId="2064" LastActivityDate="2017-08-14T22:22:22.820" Title="Compute sphere tangent for normal mapping" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5499" PostTypeId="2" ParentId="5498" CreationDate="2017-08-14T22:22:22.820" Score="5" Body="&lt;p&gt;You can do this a little bit more efficiently and accurately by calculating derivatives of $P$ with respect to $u, v$—or the derivatives with respect to $\phi, \theta$, equivalently (up to a scalar multiple).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Start by expressing $P$ in terms of the spherical coordinates:&#xA;$$\begin{aligned}&#xA;P_x &amp;amp;= r \cos \theta \cos \phi \\&#xA;P_y &amp;amp;= r \sin \theta \\&#xA;P_z &amp;amp;= r \cos \theta \sin \phi&#xA;\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can get the tangent as $T = \partial P / \partial \phi$, which works out as:&#xA;$$\begin{aligned}&#xA;T_x &amp;amp;= -r \cos \theta \sin \phi \\&#xA;T_y &amp;amp;= 0 \\&#xA;T_z &amp;amp;= r \cos \theta \cos \phi&#xA;\end{aligned}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you normalize it, the $r \cos \theta$ factors drop out and you're left with just $T = (-\sin \phi, 0, \cos \phi)$. Pretty simple!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can similarly get the bitangent as $B = \partial P / \partial \theta$, or you can just calculate it as the cross product $N \times T$, which is probably faster. (Note it should be $N \times T$, not $T \times N$, assuming you want $T, B, N$ to form a right-handed basis in that order.)&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The above approach will work for pretty much any kind of surface that can be parameterized, not just spheres. However, in the case of spheres with the usual $\phi, \theta$ coordinates, there's an even quicker shortcut that you can do with just vector math, no trig at all. Let $C$ be the center of the sphere, and $A$ be a vector representing the axis of the spherical coordinates—i.e. pointing from the center toward the north pole. Then you can just calculate $T = \text{normalize}\bigl(A \times (P - C) \bigr)$, then $B = N \times T$ as before.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-08-14T22:22:22.820" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5500" PostTypeId="1" AcceptedAnswerId="5501" CreationDate="2017-08-15T00:50:32.770" Score="2" ViewCount="210" Body="&lt;p&gt;Suppose I can run some graphics in 1366x768 equally well as 1280x720, and I have a 1920x1080 monitor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are more pixels in 1366x768 than in 1280x720.  However, in 1280x720, a 2x2 grid of pixels fits exactly within a 3x3 grid of physical pixels in my monitor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So which should look better, and is there any theoretical basis for which one looks better?  Does the 3:2 ratio mean anything at all?&lt;/p&gt;&#xA;" OwnerUserId="7154" LastActivityDate="2017-08-15T15:28:16.820" Title="Upscaling 720p to 1080p vs upscaling 768p to 1080p" Tags="&lt;sampling&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5501" PostTypeId="2" ParentId="5500" CreationDate="2017-08-15T15:28:16.820" Score="3" Body="&lt;p&gt;With a good-quality upscaling filter (&lt;a href=&quot;https://en.wikipedia.org/wiki/Bicubic_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;bicubic&lt;/a&gt;, for example), there's no particular importance to the 3:2 ratio. Starting from a higher-resolution source will produce a better-looking final image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's true that if you're programming the upscaler from scratch, making one for a fixed ratio like 3:2 is much simpler than making one that handles arbitrary ratios. But image-processing software, monitors, etc probably have arbitrary-ratio upscaling built in anyway.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-08-15T15:28:16.820" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5502" PostTypeId="1" AcceptedAnswerId="5503" CreationDate="2017-08-16T08:52:47.000" Score="3" ViewCount="315" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SSqzx.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SSqzx.png&quot; alt=&quot;reflection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the book AGI (Advanced Global Illumination), the Phong BRDF is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f_r(x,\Psi\leftrightarrow\Theta)=k_s\cfrac{(R\cdot\Theta)^n}{N\cdot\Psi}+k_d$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$k_d=\cfrac{albedo}\pi$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In Mitsuba and Tungsten, the Phong BRDF is &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f_r(x,\Psi\leftrightarrow\Theta)=[\cfrac{ratio_{diffuse}}\pi+\cfrac{(R\cdot\Theta)^n(n+2)(1-ratio_{diffuse})}{2\pi}]\cdot albedo$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Why there is a $\cfrac{n+2}{2\pi}$ in the specular part?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the relation between the two BRDFs?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastEditorUserId="5944" LastEditDate="2017-08-16T09:18:52.977" LastActivityDate="2018-03-06T08:54:54.820" Title="Phong BRDF in Mitsuba, Tungsten and AGI" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5503" PostTypeId="2" ParentId="5502" CreationDate="2017-08-16T09:16:36.053" Score="3" Body="&lt;p&gt;It's the normalization factor to make sure the BRDF always reflects the same amount of energy regardless of the value of the specular exponent n. Without that factor, changing the specular exponent changes the overall reflectance of the material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further reading: &lt;a href=&quot;http://www.thetenthplanet.de/archives/255&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Blinn-Phong Normalization Zoo | The Tenth Planet Blog&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4546" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T08:54:54.820" LastActivityDate="2018-03-06T08:54:54.820" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5504" PostTypeId="2" ParentId="5482" CreationDate="2017-08-16T15:27:36.590" Score="1" Body="&lt;p&gt;Gloss and Specularity are features of the surface. In modern PBR terms we usually refer to the smoothness and metalness of a surface instead (unless you use a specular workflow, then metalness is still linked to specular).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, dielectric surfaces reflect around 4% of light in a specular way, and the rest is diffuse. Metallic surfaces reflect no light diffused, and all specular. Specular light bounces directly back to the eye and shows clear reflections of the environment more. Diffuse bounces around a lot more and therefore gives a more matte result. Gloss is another term for smoothness of a surface. When a surface is rougher its specular light is bounced all over, and so the reflection appears more blurry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TL;DR: Specular is how shiny it is and usually is higher with metals. Gloss is how clear the reflections are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that there are some surfaces that don't fall into the metalness workflow, especially when they have a coat on top. There are also materials in between metal and dielectric (semiconductors / metalloids).&lt;/p&gt;&#xA;" OwnerUserId="5026" LastActivityDate="2017-08-16T15:27:36.590" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5506" PostTypeId="1" CreationDate="2017-08-18T04:30:20.457" Score="4" ViewCount="141" Body="&lt;p&gt;I have a very basic grasp of computer graphics however I threw it all away when I wrote this simple application that I am using for scientific purposes. I didn't have a lot of time to write it correctly because my &quot;bosses&quot; didn't see the promise of it but now that it is done they have found it quite useful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is I built it stupidly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically it takes a TON of points stored in a big array and draws them to the screen. The screen can be moved and zoomed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of using a matrix to accomplish this I am simply passing in the width, height and center of the screen making my average vertex shader look like so&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;layout (location = 0) in float ex;&#xA;layout (location = 1) in float ey;&#xA;&#xA;uniform float sizeX;&#xA;uniform float sizeY;&#xA;uniform float centerX;&#xA;uniform float centerY;&#xA;uniform float size;&#xA;&#xA;out vec4 color;&#xA;out float passsize;&#xA;void main()&#xA;{&#xA;    gl_PointSize = size;&#xA;    passsize = size;&#xA;    float x = (ex - centerX) / (sizeX / 2.0);&#xA;    float y = (ey - centerY) / (sizeY / 2.0);&#xA;    gl_Position = vec4(x, y, 0.0, 1.0);&#xA;&#xA;    color = vec4(1.0f, 0.5f, 0.2f, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and an average draw call look about like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glUseProgram(program);&#xA;glGenVertexArrays(1, &amp;amp;VAO1);&#xA;glBindVertexArray(VAO1);&#xA;&#xA;glGenBuffers(1, &amp;amp;VBO1);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO1);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(data1), data1, GL_STATIC_DRAW);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO1);&#xA;glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);&#xA;glEnableVertexAttribArray(0);&#xA;&#xA;glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;&#xA;glGenBuffers(1, &amp;amp;VBO2);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO2);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(data2), data2, GL_STATIC_DRAW);&#xA;glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);&#xA;glEnableVertexAttribArray(1);&#xA;&#xA;glUniform1f(glGetUniformLocation(program, &quot;centerX&quot;), centerX);&#xA;glUniform1f(glGetUniformLocation(program, &quot;centerY&quot;), centerY);&#xA;glUniform1f(glGetUniformLocation(program, &quot;sizeX&quot;), scrwidth);&#xA;glUniform1f(glGetUniformLocation(program, &quot;sizeY&quot;), scrheight);&#xA;glUniform1f(glGetUniformLocation(program, &quot;size&quot;), dotSize);&#xA;&#xA;glDrawArrays(GL_POINTS, 0, dot count);&#xA;glfwSwapBuffers(window);&#xA;glfwPollEvents();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This works very well but I would love to get rid of the low frame rate this causes when I am drawing a ton of points (generally over 10,000 on my small laptop that doesn't actually have a GPU).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way I can get the GPU to more intelligently clip points that are going to be off screen?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't have a lot of time to change things around so it would be great if it were something simple to achieve.&lt;/p&gt;&#xA;" OwnerUserId="7072" LastActivityDate="2017-08-20T16:24:38.197" Title="Is there a way I can make this easier for openGL to draw?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5507" PostTypeId="2" ParentId="5506" CreationDate="2017-08-18T08:29:59.387" Score="8" Body="&lt;p&gt;You only need to create the VBOs and VAO once and then you can reuse them every frame.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void init(){&#xA;&#xA;    glGenVertexArrays(1, &amp;amp;VAO1);&#xA;    glBindVertexArray(VAO1);&#xA;&#xA;    glGenBuffers(1, &amp;amp;VBO1);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO1);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(data1), data1, GL_STATIC_DRAW);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO1);&#xA;    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);&#xA;    glEnableVertexAttribArray(0);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;&#xA;    glGenBuffers(1, &amp;amp;VBO2);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO2);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(data2), data2, GL_STATIC_DRAW);&#xA;    glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, 0);&#xA;    glEnableVertexAttribArray(1);&#xA;&#xA;    uniformLoc_centerX = glGetUniformLocation(program, &quot;centerX&quot;);&#xA;    uniformLoc_centerY = glGetUniformLocation(program, &quot;centerY&quot;);&#xA;    uniformLoc_sizeX = glGetUniformLocation(program, &quot;sizeX&quot;);&#xA;    uniformLoc_sizeY = glGetUniformLocation(program, &quot;sizeY&quot;);&#xA;    uniformLoc_size= glGetUniformLocation(program, &quot;size&quot;);&#xA;}&#xA;&#xA;void draw(){&#xA;    glUseProgram(program);&#xA;    glBindVertexArray(VAO1);&#xA;&#xA;    glUniform1f(uniformLoc_centerX, centerX);&#xA;    glUniform1f(uniformLoc_centerY, centerY);&#xA;    glUniform1f(uniformLoc_sizeX, scrwidth);&#xA;    glUniform1f(uniformLoc_sizeY, scrheight);&#xA;    glUniform1f(uniformLoc_size, dotSize);&#xA;&#xA;    glDrawArrays(GL_POINTS, 0, dot count);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the data ever changes then all you need to do is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenBuffers(1, &amp;amp;VBO1);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(data1), data1, GL_STATIC_DRAW);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO2);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(data2), data2, GL_STATIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-08-18T08:29:59.387" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5509" PostTypeId="1" AcceptedAnswerId="5511" CreationDate="2017-08-19T09:31:27.877" Score="6" ViewCount="2708" Body="&lt;p&gt;I made a convolution testing program for experimenting with stuff. I've created a 5x5 Gaussian kernel for blurring. Everything looked fine, then I tried to blur a transparent png with a white circle in the middle. On the blurred image, the edge looks like a gradient from white to black.&#xA;This is mathematically correct, because the transparent points are treated as black, transparent pixels, so the convolution should gradually give darker colors near the edge.&#xA;But if I do a gaussian blur on the same image e.g. in GIMP, the circle will be fully white, with gradually more transparency toward the edges. I'd like to get this effect. What am I missing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I set the transparent pixels to transparent white, it'll work, but only if the blurred color is white.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the original image:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/v6Tdw.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v6Tdw.png&quot; alt=&quot;The original image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the result I get if I left the transparent pixels on default:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/u00CV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u00CV.png&quot; alt=&quot;Blur on the original&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if I set the transparent pixels to #00FFFFFF, I'll get this (this is the intended IF the blurred color is white)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BfVw8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BfVw8.png&quot; alt=&quot;Intended result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7177" LastEditorUserId="7177" LastEditDate="2017-08-19T11:45:26.557" LastActivityDate="2020-08-03T08:44:17.107" Title="Gaussian blur with transparency" Tags="&lt;texture&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5510" PostTypeId="2" ParentId="5509" CreationDate="2017-08-19T11:27:04.580" Score="1" Body="&lt;p&gt;How do you load your image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe your image is loaded as RGB instead of RGB-A, which means you are totally ignoring Alpha channel (the transparency value). In this case the transparent pixels are converted into black ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are using OpenCV library, &lt;a href=&quot;https://stackoverflow.com/questions/3803888/opencv-how-to-load-png-images-with-4-channels&quot;&gt;this article&lt;/a&gt; might help you load the image with 4-channels (into a 4-dimensional array); then you are able to apply Gaussian-blur function on every 4 channels and get the desired result.&lt;/p&gt;&#xA;" OwnerUserId="7178" LastActivityDate="2017-08-19T11:27:04.580" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5511" PostTypeId="2" ParentId="5509" CreationDate="2017-08-19T11:55:10.607" Score="3" Body="&lt;p&gt;As it turned out, I forgot to weight the color channel by the transparency, so I got the same issue as written here:&#xA;&lt;a href=&quot;http://www.imagemagick.org/Usage/bugs/blur_trans/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blur Transparency Bug&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7177" LastActivityDate="2017-08-19T11:55:10.607" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5512" PostTypeId="1" CreationDate="2017-08-20T07:22:06.270" Score="2" ViewCount="2678" Body="&lt;p&gt;For the past month, I have been learning on my own and writing a little graphics library and am currently working on the transformation of vertex normals to soon support lighting/shading. I understand how if I transform the vertices by a matrix &lt;strong&gt;M&lt;/strong&gt; that I need to apply the inverse-transpose of M (i.e., (&lt;strong&gt;M&lt;/strong&gt;^-1 )^T ) to the surface normals. However, I am struggling to understand how this &quot;rule&quot; can be applied to all of the basic transformations (translate, scale, rotate) ... particularly, translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using a homogeneous (w) coordinate in a 4D vector class, a Translate(x, y, z) would have no effect on a normal since its w-coordinate is 0, indicating that it is a vector, not a point. However, when we transpose the inverse of the Translate then it would have an effect on the normal (which feels incorrect). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, let's say that we have created a 3D triangle and want to apply a basic Translate(1, 2, 3) to the three vertices' positions. Based upon the &quot;rule&quot; for transforming vertex normals (i.e., inverse-transpose), we should be multiplying the three vertices' normals by Transpose(Translate(-1, -2, -3)). However, this feels incorrect since a vertex normal should remain unaffected by Translation and only be affected by Rotation and Scaling. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help in understanding how the inverse-transpose can be applied to vertex normals would be greatly appreciated!&lt;/p&gt;&#xA;" OwnerUserId="7180" LastActivityDate="2018-03-03T20:07:34.817" Title="Inverse-Transpose of Vertex Normals" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;matrix&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5513" PostTypeId="1" CreationDate="2017-08-20T09:35:52.587" Score="2" ViewCount="679" Body="&lt;p&gt;I am trying to figure out the correct order between edges on edge table on scan line polygon fill.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One example here on &lt;code&gt;Y=1&lt;/code&gt; takes first &lt;code&gt;AB&lt;/code&gt; line&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XYs28.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XYs28.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And another example takes on &lt;code&gt;Y=0&lt;/code&gt; &lt;code&gt;v1v0&lt;/code&gt;.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2cLWP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2cLWP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I cannot understand why not &lt;code&gt;AB&lt;/code&gt; instead of &lt;code&gt;BA&lt;/code&gt; and why &lt;code&gt;v1v0&lt;/code&gt; instead of &lt;code&gt;v0v1&lt;/code&gt; respectively&lt;/p&gt;&#xA;" OwnerUserId="7181" LastActivityDate="2017-08-20T09:35:52.587" Title="Scan Line Polygon Fill Edge Table Entry Order" Tags="&lt;polygon&gt;&lt;scanline&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5515" PostTypeId="2" ParentId="5506" CreationDate="2017-08-20T16:24:38.197" Score="2" Body="&lt;p&gt;To start with, you should (almost) never have a glGen*() call in your render loop. Do that during initialization only. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like your vertex data isn't changing. Don't re-set the buffer data, just send it once during initialization. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the application you've described, about the only thing that should be in your render loop is bindBuffer, setting your uniforms, clear, draw and present. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fixing those issues will likely have a significant perf impact. If that still isn't enough, look at spatial partitioning and frustum culling - in 2D, your frustum is just going to be a box - to more intelligently clip your data CPU-side. Google &quot;quad trees&quot; to get started. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, depending on the use case, you MIGHT be better off just doing this in Unity or another off-the-shelf engine. They already provide much of this functionality.  (However, I'm all for roll-your-own  for the fun factor, and a full engine may be overkill for this.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And never forget: the profiler is your friend. Without it, everything else is just professional guessing. &lt;/p&gt;&#xA;" OwnerUserId="5240" LastActivityDate="2017-08-20T16:24:38.197" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5516" PostTypeId="2" ParentId="5512" CreationDate="2017-08-21T09:40:09.877" Score="1" Body="&lt;p&gt;You are correct, when they are talking about taking the inverse-transpose they are talking about the 3x3 part of the affine transformation leaving the translation since it doesn't affect the normal vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check : &lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_(geometry)#Transforming_normals&quot; rel=&quot;nofollow noreferrer&quot;&gt;Normal / Transforming Normals | Wikipedia&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About how or why is it the inverse transpose, a simple explanation, that is also given in the book &quot;Essential Mathematics for Games&quot; is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose we have a Point $P$ and a normal vector $n$ both represented by column matrix. Then we know that&#xA;$$&#xA;n^T P = 0&#xA;$$&#xA;This is the same as the dot product.&#xA;Now if we apply a transformation matrix $M$ to point $P$, we'll have to apply some sort of transformation matrix $Q$ to $n$ also.&#xA;$$&#xA;\begin{eqnarray}&#xA;(Q n)^T M P &amp;amp; = &amp;amp; 0 \\&#xA;n^T Q^T M P &amp;amp; = &amp;amp; 0&#xA;\end{eqnarray}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One solution is&#xA;$$&#xA;\begin{eqnarray}&#xA;Q^T M &amp;amp; = &amp;amp; I \\&#xA;Q &amp;amp; = &amp;amp; {M^{-1}}^T&#xA;\end{eqnarray}&#xA;$$&#xA;Hence the inverse transpose. This stands for any sort of transformation matrix $M$ be it scaling, rotation etc. Also for pure rotation matrix, since they are orthogonal, the matrix transforming the normals is the same as that of the vertices. as ${M^T}^T = M$&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorDisplayName="user7220" LastEditDate="2018-03-03T20:07:34.817" LastActivityDate="2018-03-03T20:07:34.817" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5517" PostTypeId="2" ParentId="5509" CreationDate="2017-08-21T16:27:25.710" Score="7" Body="&lt;p&gt;I apologise for only skimming through your question/answer and the links you gave but I thought it would be a good idea to post what needs to be done to &lt;em&gt;correctly&lt;/em&gt; do any blending and/or filtering on images with an alpha channel.&lt;/p&gt;&#xA;&lt;p&gt;The first thing to note is that all calculations should be done in a linear colour space, but the image data in PNGs and JPEGs is most likely to be in &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB&quot; rel=&quot;nofollow noreferrer&quot;&gt;sRGB&lt;/a&gt; which is non-linear. You should convert this data to a linear form before doing any calculations. For example, the average of black (0,0,0) and white (255,255,255) in sRGB is not (127,127,127) but (off the top of my head) something like (186,186,186). The filtering of images, especially those with neighbouring, complementary, saturated colours (e.g. Yellow&amp;amp;Blue), can look quite odd if you don't take gamma into account.&lt;/p&gt;&#xA;&lt;p&gt;The second part of this theory dates back to Porter and Duff's seminal 1984 paper, &amp;quot;&lt;a href=&quot;https://keithp.com/%7Ekeithp/porterduff/p253-porter.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Compositing Digital Images&lt;/a&gt;&amp;quot;, which introduces the concept of pre-multiplied alpha. Pre-multiplied alpha basically means that you multiply the RGBs by the alpha value before doing calculations.&lt;/p&gt;&#xA;&lt;p&gt;The Porter-Duff paper states...&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;There are a few reasons to dismiss this proposal,&#xA;the most severe being that all compositing operations&#xA;will involve multiplying the 1 in the red channel by&#xA;the .5 in the alpha channel to compute the red contribution&#xA;of this object at this pixel. The desire to avoid this&#xA;multiplication points up a better solution, storing the&#xA;pre-multiplied value in the color component, so that&#xA;(.5,0,0,.5) will indicate a full red object half covering a&#xA;pixel.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;... which suggests this was initially done just to reduce computation costs, but in Jim Blinn's article &lt;a href=&quot;https://graphics.stanford.edu/courses/cs248-02/blinn_theory.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&amp;quot;Compositing-Theory&amp;quot;&lt;/a&gt;, he demonstrates that the correct way to do any filtering or compositing operations is to first convert everything to premultipled.&lt;/p&gt;&#xA;&lt;p&gt;Once you have linearised and then pre-multiplied your pixel data, do the filtering/blending and, finally, undo the pre-multiply and reapply the gamma function to map back to sRGB.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-08-03T08:44:17.107" LastActivityDate="2020-08-03T08:44:17.107" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="5518" PostTypeId="1" AcceptedAnswerId="5519" CreationDate="2017-08-22T01:21:03.783" Score="1" ViewCount="71" Body="&lt;p&gt;I have a series of images obtained from a microscope as follows&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qCMPx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qCMPx.jpg&quot; alt=&quot;Time step 3&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to create a series of filters that would isolate the centre section    on the yellow droplet.(This is highlighted by the bright yellow circle area), and remove all the noise and other pictures.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/epfyH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/epfyH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;I tried using just RGB  channel threshold but its not working. Also ambient light may also change so I am not getting a consistent output. Can anyone provide a MWE for the workflow of the filter required in MATLAB to achieve this?&lt;/p&gt;&#xA;" OwnerUserId="7185" LastEditorUserId="506" LastEditDate="2017-08-24T15:16:14.057" LastActivityDate="2017-08-24T15:16:14.057" Title="Appropriate filter steps for resolving a droplet pixel" Tags="&lt;image-processing&gt;&lt;matlab&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5519" PostTypeId="2" ParentId="5518" CreationDate="2017-08-22T05:39:09.370" Score="1" Body="&lt;p&gt;First simple thresholding is usually not a good idea. However, if you want to do that, I suggest to also consider other &lt;a href=&quot;https://en.wikipedia.org/wiki/Color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;color spaces&lt;/a&gt;. In your case, &lt;a href=&quot;https://en.wikipedia.org/wiki/HSL_and_HSV&quot; rel=&quot;nofollow noreferrer&quot;&gt;HSV&lt;/a&gt; might be a better choice; You can convert your image into HSV-image then you can define a range on Hue channel to select yellow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, take a look at &lt;a href=&quot;http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt;; it is about implementing &lt;strong&gt;Adaptive Thresholding&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7178" LastActivityDate="2017-08-22T05:39:09.370" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5520" PostTypeId="1" CreationDate="2017-08-22T07:31:11.597" Score="9" ViewCount="586" Body="&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am editing and posting this question in a different way; this time from the point of view of &lt;a href=&quot;http://nishitalab.org/user/nis/cdrom/sig93_nis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nishita paper&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JCbNW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JCbNW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sunlight gets scattered at P and attenuated before reaching Pv. Therefore intensity reaching Pv coming from P can be obtained by multiplying the attenuation by intensity at P:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zEuOL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zEuOL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The intensity reaching Pv therefore can be obtained by integrating light due to air molecules along the ray segment PaPb:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bPZsR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bPZsR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WHUw0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WHUw0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I am to solve this integral by Monte Carlo method and without ray marching approach, What would be the estimator and what are the good choices for pdf and sampling method?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I am trying to implement the concept of distributed ray tracing on Rayleigh scatterting to render sky a bit more realistic. The code I use is borrowed from&#xA;&lt;a href=&quot;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky&quot; rel=&quot;nofollow noreferrer&quot;&gt;this website&lt;/a&gt;. It takes 16 samples along the ray and 8 samples for sunlight.&#xA;This works fine and I was able to generate this image using only 1 sample per pixel(not sure why the sun is so small, any idea?):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YTuXG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YTuXG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I then tried to use Monte Carlo to do this. 1 sample uniformly selected along the ray and 1 sample for sunlight. The only changes I did are on four lines:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;line 7:  uint32_t numSamples = 1; //16&#xA;line 8:  uint32_t numSamplesLight = 1; //8 &#xA;&#xA;//used drand48() instead of 0.5&#xA;line 18: Vec3f samplePosition = orig + (tCurrent+&#xA;                                segmentLength * drand48()) * dir; &#xA;line 32: Vec3f samplePositionLight = samplePosition + (tCurrentLight + &#xA;                                segmentLengthLight * drand48) * sunDirection; &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The pdf is 1/segmentLength and the sample is taken uniformly in this distance.&#xA;Here is my implementation in c# code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public override void Render(int pxlX, int pxlY, Random rand)&#xA;{&#xA;    Vector estimatedColor = new Vector();&#xA;&#xA;    Ray ray = Scene.Camera.GenerateRay(pxlX + rand.NextDouble(), pxlY + rand.NextDouble(), rand.NextDouble(), rand.NextDouble());&#xA;&#xA;    ISect isect = Scene.Trace(ray);&#xA;    if (ISect.IsNull(isect))&#xA;        estimatedColor = Atmosph.ComputeIncidentLight(ray, rand);&#xA;    else&#xA;        estimatedColor = isect.Thing.Material.Emission +&#xA;                ComputeRadiance(isect, rand, 0);&#xA;&#xA;    ImageFilm.AddToPixel(pxlX, pxlY, estimatedColor/numPixelSamples);&#xA;}&#xA;&#xA;public Vector ComputeIncidentLight(Ray r, Random rand)&#xA;{&#xA;    r.Start.Z += earthRadius;&#xA;&#xA;    ISect isect = earth.Intersect(r);&#xA;    if (ISect.IsNull(isect)) return Vector.ZERO;&#xA;&#xA;    int numSamples = 1;&#xA;    int numSamplesLight = 1;&#xA;    double segmentLength = isect.Dist / numSamples;&#xA;    double tCurrent = 0;&#xA;    Vector sumR = Vector.ZERO;&#xA;    Vector sumM = Vector.ZERO;// mie and rayleigh contribution &#xA;    double opticalDepthR = 0, opticalDepthM = 0;&#xA;    double mu = r.Dir.Dot(sunDirection); // mu in the paper which is the cosine of the angle between the sun direction and the ray direction &#xA;    double phaseR = 3d / (16d * Math.PI) * (1 + mu * mu);&#xA;    double g = 0.76f;&#xA;    double phaseM = 3d / (8d * Math.PI) * ((1d - g * g) * (1d + mu * mu)) / ((2d + g * g) * Math.Pow(1d + g * g - 2d * g * mu, 1.5d));&#xA;    for (int i = 0; i &amp;lt; numSamples; ++i)&#xA;    {&#xA;        Vector samplePosition = r.Start + r.Dir * (tCurrent + segmentLength * rand.NextDouble());&#xA;        double height = samplePosition.Length() - earthRadius;&#xA;        // compute optical depth for light&#xA;        double hr = Math.Exp(-height / Hr) * segmentLength;&#xA;        double hm = Math.Exp(-height / Hm) * segmentLength;&#xA;        opticalDepthR += hr;&#xA;        opticalDepthM += hm;&#xA;        // light optical depth&#xA;        ISect isectSun = earth.Intersect(new Ray(samplePosition, sunDirection));&#xA;        double segmentLengthLight = isectSun.Dist/ numSamplesLight, tCurrentLight = 0;&#xA;        double opticalDepthLightR = 0, opticalDepthLightM = 0;&#xA;        int j;&#xA;        for (j = 0; j &amp;lt; numSamplesLight; ++j)&#xA;        {&#xA;            Vector samplePositionLight = samplePosition + sunDirection * (tCurrentLight + segmentLengthLight * rand.NextDouble());&#xA;            double heightLight = samplePositionLight.Length() - earthRadius;&#xA;            if (heightLight &amp;lt; 0) break;&#xA;            opticalDepthLightR += Math.Exp(-heightLight / Hr) * segmentLengthLight;&#xA;            opticalDepthLightM += Math.Exp(-heightLight / Hm) * segmentLengthLight;&#xA;            tCurrentLight += segmentLengthLight;&#xA;        }&#xA;        if (j == numSamplesLight)&#xA;        {&#xA;            Vector tau = betaR * (opticalDepthR + opticalDepthLightR) + betaM * 1.1f * (opticalDepthM + opticalDepthLightM);&#xA;            Vector attenuation = new Vector(Math.Exp(-tau.X), Math.Exp(-tau.Y), Math.Exp(-tau.Z));&#xA;            sumR += attenuation * hr;&#xA;            sumM += attenuation * hm;&#xA;        }&#xA;        tCurrent += segmentLength;&#xA;    }&#xA;&#xA;    // We use a magic number here for the intensity of the sun (20). We will make it more&#xA;    // scientific in a future revision of this lesson/code&#xA;    return (sumR * betaR * phaseR + sumM * betaM * phaseM) * sunIrradiance;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The below image rendered with 400 samples per pixel, however is different from the above:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9aw6n.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9aw6n.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone shed some light where I've got it wrong?&#xA;Thanks,&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:56:07.270" LastActivityDate="2021-03-16T20:01:20.150" Title="Using Monte carlo on Rayleigh scattering" Tags="&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;distribution&gt;&lt;volumetric-scattering&gt;" AnswerCount="1" CommentCount="8" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5521" PostTypeId="1" CreationDate="2017-08-23T05:38:04.923" Score="1" ViewCount="71" Body="&lt;p&gt;As a pet project, I'm trying to build a small app that visualizes 4D polytopes. I want to use the &lt;a href=&quot;https://en.wikipedia.org/wiki/Wythoff_construction&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wythoff Construction&lt;/a&gt; method, where the shape is generated kaleidoscopically by the interaction of 4 mirrors using a single movable generator vertex. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know how to create a reflection matrix from a hypersurface normal, what I am looking for is an simple way to generate all possible matrices generated by the interreflections of the set of mirrors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The brute force method would be something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1: Create the initial set of mirrors and their matrices&#xA;2: Reflect each matrix in each of the other mirrors, add to temp list&#xA;3: Remove duplicates from temp list&#xA;4: Add temp list to master list and remove duplicates&#xA;5: Reflect each matrix in temp list through each mirror except its generating mirror &#xA;   and add to new temp list&#xA;6: Repeat from step 3 with new temp list, continue until no non-duplicates found&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This method will work but will involve a huge amount of redundant computation generating, checking, and discarding duplicates, especially in symmetry groups like the 120-cell / 600-cell which contain thousands of permutations. Does anybody know of a more elegant method of creating the full set?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-08-30T08:54:57.873" Title="Finding all possible reflection matrices for a given Wythoff construction" Tags="&lt;algorithm&gt;&lt;matrix&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5523" PostTypeId="2" ParentId="374" CreationDate="2017-08-24T15:50:24.077" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/results?query=bezier&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/results?query=bezier&lt;/a&gt;&#xA;sort by age, in case of compatibility issues:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;,...shows many solutions of many spline-subsets, either returning the distance to a 2d spline, or tracing a 3d patch. Splines and patches come in many forms. heavensine beind simplest, bezier being simple, nurbs being overly complex. The more constrains yo add to your spline, the simpler it gets. NURBS is extension overkill; &#xA;- its Non-Uniform-ness of weights (the &quot;NU&quot;) diminishes efficiency in comparison to to more symmetric splines &#xA;- its Ration-al-ness (the R) also adds some complexity, for segmenting (rationing) and mixing with nearby segments (recursively solved).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;bezier-patch-tracing is root-solving and with that comes contextual prioritization on precision; in what order to solve the quadratic equation.&#xA;this becomes impractical on higher exponents than cubic, due to exponential complexity and precision loss.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ray-marching==sphere-tracking is the simpler heuristic approach to root-solving, which seems to be the simple and most efficient solution to rendering most splines patches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lagrange-representation simplifies tracing/marching (as the L-points are ON the spline while the ControlVector-points (of the exact same spline) are rarely on the spline)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The special case of a heavensine-spline, where first derivatives of stat and end are ==0. simplifies continuity and involves less differentials (less subtraction).&#xA;A heavensine-patch can be traced efficiently in a single pass:&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/4djfW3&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/4djfW3&lt;/a&gt;&#xA;while other cubic (or higher) splines make the heuristic sphere-tracking/ray-marching approach more efficient (and &quot;precise enough&quot;) than daring to analytically calculate all the roots to keep the smallest positive root (with exponentially accumulating precision errors for each root).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In computer graphics, splines and patches have been nearly completely replaced by z-brushing by 2006. z-brushing uses displacement maps with homogeneous coordinates, or even using a &quot;type&quot; that us a union of sphere and linesegments (linesegments have a radius of 0, spheres have a length of 0, a union is simple and useful). For a minor loss in precision for a big gain in performance at relatively low memory cost for a look-up-table, that is easily made dynamic on a gpu.&lt;/p&gt;&#xA;" OwnerUserId="7199" LastActivityDate="2017-08-24T15:50:24.077" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5524" PostTypeId="1" CreationDate="2017-08-24T22:29:53.457" Score="2" ViewCount="178" Body="&lt;p&gt;I have a screen-aligned texture resulting from multiple rendering passes. It looks  about this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/Adod4.png&quot; width=&quot;250&quot; alt=&quot;textureToBeSmoothed&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want the edges to appear smoother than they do now (but still keep their characteristic shape). When zooming in, the blocky appearance becomes very obvious. Is there a common approach in computer graphics (or in OpenGL in particular) to resolve this? Since the texture results from the application of the &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4830/understanding-jump-flooding-algorithm-jfa-for-voronoi-diagrams&quot;&gt;jump flooding algorithm&lt;/a&gt; the what-ever approach has to be performed in a post-processing step. I'm so far just interested in the approach(es) itself, not in the implementation.&lt;/p&gt;&#xA;" OwnerUserId="5406" LastEditorUserId="5406" LastEditDate="2018-08-07T07:48:14.287" LastActivityDate="2018-08-07T07:48:14.287" Title="What is a common approach to smooth structures in textures?" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;interpolation&gt;&lt;filtering&gt;&lt;post-processing&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="5526" PostTypeId="1" AcceptedAnswerId="5527" CreationDate="2017-08-25T12:27:08.357" Score="2" ViewCount="1366" Body="&lt;p&gt;How is this 'w&lt;sub&gt;y&lt;/sub&gt;' equation for thick line segment derived?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EmgKN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EmgKN.png&quot; alt=&quot;Thick line segment&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/73syB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/73syB.png&quot; alt=&quot;equation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7205" LastActivityDate="2017-08-25T13:59:42.973" Title="Thick Line segment" Tags="&lt;vector-graphics&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5527" PostTypeId="2" ParentId="5526" CreationDate="2017-08-25T13:59:42.973" Score="3" Body="&lt;p&gt;The main part of it is simply Pythagoras's Theorem. The square root gives the length of the central line segment (which is the hypotenuse of a triangle formed by the change in x and change in y). The ratio between the hypotenuse and the change in x is the same as the ratio between the line width and the line width in y (they are similar triangles). Dividing by two is because $w_y$ is the half-width, not the full width. The -1 doesn't appear to make sense in a continuous context, so I assume it's to make sure the number of pixels is rounded down as part of the division. This prevents the line from jumping in thickness when it crosses a pixel boundary.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-08-25T13:59:42.973" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5528" PostTypeId="1" AcceptedAnswerId="5551" CreationDate="2017-08-25T14:21:50.707" Score="4" ViewCount="54" Body="&lt;p&gt;When warping the contents of an arbitrary quadrilateral to another by extrapolating equal points along both the &quot;lengths&quot; and &quot;widths&quot;, thus ignoring all perspective effects / foreshortening, we are not using a &quot;homography&quot; or &quot;affine&quot; mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a correct name to describe the type of mapping we are doing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Z2ix7.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z2ix7.gif&quot; alt=&quot;(Looking for example image ...)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1647" LastEditorUserId="1647" LastEditDate="2017-08-25T14:37:33.280" LastActivityDate="2017-09-01T05:00:49.610" Title="Is there a term for mapping between two arbitrary quadrilaterals without using homography / perspective projection?" Tags="&lt;mapping&gt;&lt;terminology&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5529" PostTypeId="2" ParentId="5524" CreationDate="2017-08-25T16:33:49.097" Score="1" Body="&lt;p&gt;I don't have enough rep to add a comment so...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could use a post process based anti-aliasing technique like FXAA or SMAA. Also, if performance is not a priority, you could go for &lt;a href=&quot;https://en.wikipedia.org/wiki/Supersampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;SSAA&lt;/a&gt;. Another option could be to write to a multi sampled texture (I'm not 100% sure if that is possible in your case).&lt;/p&gt;&#xA;" OwnerUserId="7107" LastActivityDate="2017-08-25T16:33:49.097" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5530" PostTypeId="2" ParentId="5512" CreationDate="2017-08-26T08:00:22.163" Score="0" Body="&lt;p&gt;You're right, translation is not relevant in this context: it wouldn't affect the normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider a non-uniformly scaled object:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MET67.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MET67.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We want to get the normal matrix to transform the normals in the vertex buffer into vectors representing world space normals from the world matrix M, which encodes the translation, rotation and scaling (and shearing) of the model object.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If you were to interpret the 3x3 of the M in the vertex shader, you would read rotation data with scaling applied. If the world matrix contains non-uniform scaling, your normal vectors will be scaled incorrectly, and you'll get the wrong results. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason we take the transpose of the transform is because the rotation matrix, used to create &lt;code&gt;M = TranslationMatrix x RotationMatrix x ScaleMatrix&lt;/code&gt;, is an &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthogonal_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;Orthagonal Matrix&lt;/a&gt;, which means that the row vectors are &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthogonality&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;orthogonal&lt;/strong&gt;&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Unit_vector&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;unit&lt;/strong&gt;&lt;/a&gt; vectors, i.e. they are linearly-independent and their length is one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This type of matrices hold a property like the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Q^T * Q = Q * Q^T = I&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you remember the inverse rule:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Q^-1 * Q = Q * Q^-1 = I&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This also means the following for the orthogonal matrices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Q^T = Q^-1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This allows us to apply the inverse of the rotations by transposing the matrix. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In summary, taking inverse-transpose of the world matrix does 2 important things:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Undo transformation (Inverse)&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;undo the scaling (and shearing)&lt;/li&gt;&#xA;&lt;li&gt;invert rotations&lt;/li&gt;&#xA;&lt;li&gt;translate the object to the world center (irrelevant)&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aeMoe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aeMoe.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Un-undo rotations (Transpose)&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Now, if we take the transpose of our matrix, we will get our rotations back to their original state because of the orthogonal property of the rotation matrix.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nmGHd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nmGHd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We now have our normal matrix ready to transform model-space normals defined in the vertex buffer into world-space normals in the vertex shader.&lt;/p&gt;&#xA;" OwnerUserId="5353" LastActivityDate="2017-08-26T08:00:22.163" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5533" PostTypeId="2" ParentId="5453" CreationDate="2017-08-27T04:32:43.977" Score="2" Body="&lt;p&gt;You need to convert luminous flux (lumens, $lm$) to luminance ($\frac{lm}{m^2sr}$) for the &lt;a href=&quot;https://en.wikipedia.org/wiki/Rendering_equation&quot; rel=&quot;nofollow noreferrer&quot;&gt;rendering equation&lt;/a&gt;. For that you need to know the physical properties of the light source. For example luminance $L$ of spherical light source of radius $r$ radiating over $4\pi$ solid angle and luminous flux $\phi$ has luminance:&#xA;$$L = \frac{\phi}{4\pi^2r^2}$$&#xA;I think it's better to define lights straight using luminance instead of luminous flux though since you can simply measure luminance with spot meter instead of using &lt;a href=&quot;https://en.wikipedia.org/wiki/Luminous_flux#/media/File:Luminance_Chamber.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;cumbersome special equipment&lt;/a&gt; or be limited by values provided by manufacturers in illuminant packaging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding distance attenuation, all lights in PBR should be area lights and there's no explicit attenuation formula for lights because the distance attenuation emerges naturally from the rendering equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also better use &lt;a href=&quot;https://en.wikipedia.org/wiki/Category:Units_of_photometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;photometric units&lt;/a&gt; instead of &lt;a href=&quot;https://en.wikipedia.org/wiki/Template:SI_radiometry_units&quot; rel=&quot;nofollow noreferrer&quot;&gt;radiometric units&lt;/a&gt; for RGB-rendering (not spectral/monochromatic rendering). In photometric units the extraterrestrial sun luminance is ~1.9B cd/m^2 (don't try to measure sun with spot meter though!). If you want to use radiometric units, you need to take the &lt;a href=&quot;https://en.wikipedia.org/wiki/Spectral_power_distribution&quot; rel=&quot;nofollow noreferrer&quot;&gt;spectral power distribution&lt;/a&gt; of the sun and integrate that with &lt;a href=&quot;https://en.wikipedia.org/wiki/CIE_1931_color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;CIE color matching functions&lt;/a&gt; to get any reasonable values rendering.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-08-27T04:42:51.887" LastActivityDate="2017-08-27T04:42:51.887" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5534" PostTypeId="1" CreationDate="2017-08-28T07:57:55.330" Score="3" ViewCount="1873" Body="&lt;p&gt;I'm trying to build a raytracer and I use &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-generating-camera-rays/generating-camera-rays&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; on how to build camera system. The problem is that when, after calculating ray direction in camera space, I multiply it by camera-to-world transformation matrix and my camera seems to rotate in opposite directions and works correctly if I inverse transformation matrix before multiplication.&lt;br&gt;&#xA;Here is the code (I use glm library and right-handed coordinate system). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some data&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 origin_ = glm::vec3(0.f);// camera origin&#xA;cont glm::vec3 kDirection = glm::vec3(0.f, 0.f, -1.f);&#xA;cont glm::vec3 kUp = glm::vec3(0.f, 1.f, 0.f);&#xA;float aspect_ratio_ = (float)raster_height_ / raster_width_;&#xA;&#xA;// bug !!! rotates in opposite direction  (camera is actually tilted down)&#xA;glm::mat4 camera_to_world_ = glm::lookAtRH(origin_, glm::vec3(0.f, 0.2f, -1.f), kUp);&#xA;// works !!! (camera is tilted up)&#xA;glm::mat4 camera_to_world_ = glm::inverse(glm::lookAtRH(origin_, glm::vec3(0.f, 0.2f, -1.f), kUp));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And function that generates camera rays &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Calculate ray as if camera is located at 0,0,0 and pointing into negative z direction&#xA;// Then transform ray direction to desired plase&#xA;// x,y - pixel coordinates of raster image&#xA;// calculate as if raster image (screen) is 1.0 unit away from origin (eye)&#xA;Ray Camera::GenRay(const uint32_t x, const uint32_t y) {&#xA;  glm::vec3 ray_direction = kDirection;&#xA;  // from raster space to NDC space&#xA;  glm::vec2 pixel_ndc((x + 0.5f) / raster_width_, (y + 0.5f) / raster_height_);&#xA;  // from NDC space to camera space&#xA;  float scale = tan(fov_ / 2.0f);&#xA;  ray_direction.x = (2.0f * pixel_ndc.x - 1.0f) * scale; // *aspect_ratio_;&#xA;  ray_direction.y = (1.0f - 2.0f * pixel_ndc.y) * scale * aspect_ratio_;&#xA;  // apply camera-to-world rotation matrix to direction&#xA;  ray_direction = camera_to_world_ * glm::vec4(ray_direction, 0.0f);&#xA;&#xA;  return  Ray(origin_, ray_direction, Ray::Type::kPrimary);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I really can't understand the root of a problem so any help us appreciated.&lt;/p&gt;&#xA;" OwnerUserId="7214" LastActivityDate="2018-03-06T08:54:14.090" Title="Please, help me to understand why my raytracing camera rotates in wrong directions?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5535" PostTypeId="2" ParentId="5534" CreationDate="2017-08-28T10:26:17.637" Score="2" Body="&lt;p&gt;The problem is that instead of a camera-to-world matrix, a world-to-camera matrix is being made by glm::lookAtRH. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is because GLM is a math library made for OpenGL. In OpenGL, you do not move the 'camera' as there is no camera in OpenGL. You move the whole world the other way around, so that it lines up in the frustum. The lookAtRH method returns a matrix that moves the whole world in a way that it seems like you have the camera there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inversing the matrix is a fine way to get the proper camera-to-world matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Scrathapixel does have an article regarding making your own lookAt function. One thing to note about this article is that they use a row-major notation. It might be that you need to switch it up and use a column-major notation (just swap the x index with the y index).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/lookat-function/framing-lookat-function&quot; rel=&quot;nofollow noreferrer&quot;&gt;Placing a Camera: the LookAt Function | Scratchapixel&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T08:54:14.090" LastActivityDate="2018-03-06T08:54:14.090" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5536" PostTypeId="1" AcceptedAnswerId="5537" CreationDate="2017-08-28T10:44:26.777" Score="7" ViewCount="6953" Body="&lt;p&gt;I'm sort of struggling to understand the conceptual difference between uniform buffers and push constants. From what I can gather by reading the spec, the main differences are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Uniform buffers can be &lt;em&gt;much&lt;/em&gt; larger than push constants.&lt;/li&gt;&#xA;&lt;li&gt;UBOs use std140, PCs use std430.&lt;/li&gt;&#xA;&lt;li&gt;UBOs can be updated at any time with vkCmdUpdateBuffer (or host mapping) and persist their values otherwise, PCs have to be re-pushed for each render pass. (Which surprised me - based on the name. I thought I would literally be updating constants in the pipeline in-place, and have those changes persist)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In my scenario, I have about ~200 bytes worth of data that I expect to be &lt;strong&gt;mostly constant&lt;/strong&gt;. That is, I will change them very infrequently. Would it be better to (assuming the size permits) use push constants even though I have to re-send them in every command buffer? Or would it be better to use a 200-byte UBO and only update it infrequently with vkCmdUpdatebuffer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also. what if I have e.g. a &lt;code&gt;float random_seed&lt;/code&gt; that I will update every time the shader is run? Assuming I already have a UBO, would it be better to lump that in with the UBO, even though the rest of the UBO is constant, or would I gain a benefit from using push constants for specifically this variable, so I can avoid having to vkCmdUpdateBuffer before every render pass?&lt;/p&gt;&#xA;" OwnerUserId="7215" LastActivityDate="2017-10-06T16:44:43.843" Title="Vulkan: Uniform Buffers versus Push Constants for static data" Tags="&lt;vulkan&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5537" PostTypeId="2" ParentId="5536" CreationDate="2017-08-28T14:33:07.843" Score="9" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;UBOs can be updated at any time with vkCmdUpdateBuffer &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;From the specification: &quot;vkCmdUpdateBuffer is only allowed outside of a render pass.&quot; So &quot;at any time&quot; is not the case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if it were allowed inside of a render pass, it's still a transfer operation. Which means you need to synchronize the memory transfer with the commands that use it. Which slows down performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the general Push Constant vs. Uniform thing, use your judgment. By &quot;judgment&quot;, I mean just look at how they work. Push Constants allow you to change their data at any time without doing heavy-weight processes like memory operations, synchronization, or altering the descriptor state. Clearly, they are for frequently changing data. How frequently is &quot;frequently&quot;? Well, that's a judgment call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Failing that, profile the performance difference.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-09-19T21:28:12.283" LastActivityDate="2017-09-19T21:28:12.283" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5538" PostTypeId="1" AcceptedAnswerId="5626" CreationDate="2017-08-29T12:43:00.323" Score="0" ViewCount="259" Body="&lt;p&gt;I have asked this question on &lt;a href=&quot;https://ru.stackoverflow.com/questions/705286/%D0%A3%D0%B4%D0%B0%D0%BB%D0%B5%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D1%8C-%D1%81%D1%82%D0%BE%D1%80%D0%BE%D0%BD-%D0%BA%D1%83%D0%B1%D0%B0-%D0%BE%D1%82-%D0%BF%D0%BB%D0%BE%D1%81%D0%BA%D0%BE%D1%81%D1%82%D0%B8-%D0%BF%D1%80%D0%BE%D0%B5%D0%BA%D1%86%D0%B8%D0%B8&quot;&gt;ru.stackoverflow.com&lt;/a&gt; and have no valid answers.&lt;/p&gt;&#xA;&lt;p&gt;Specification:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://i.stack.imgur.com/bKXyI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Coordinate system&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Cube spins around its center on all three axes.&lt;/li&gt;&#xA;&lt;li&gt;Turn angle is not known previously.&lt;/li&gt;&#xA;&lt;li&gt;Parallel projection calculated by:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;x`` = x;&lt;/p&gt;&#xA;&lt;p&gt;y`` = y + z / 4;&#xA;5. Per unit of time only 3 sides, closest to the projection plane, are visible.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Question:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;How to determine which are the closest sides?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm going this way: take pairs of sides left and right, front and back, top and bottom, then determine closest and farthest points in (Z) axis, determine the equation of a line, take the second farthest point in (Z) axis, and substitute into this equation - so determine the inclination of the side. Based on this choose which side is closer. I want to draw only the visible faces.&lt;/p&gt;&#xA;&lt;p&gt;This code don't work:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;// Получаем параллельную проекцию кубика на плоскость экрана&#xA;function getParallelProjection(arr) {&#xA;&#xA;var i, j, k;&#xA;&#xA;var arr_new = [];&#xA;&#xA;// Попарно работаем с гранями&#xA;// Левая и правая&#xA;arr_new[0] = getSideParallelProjection(arr[0], arr[1], arr[6]);&#xA;// Задняя и передняя&#xA;arr_new[1] = getSideParallelProjection(arr[2], arr[3], arr[6]);&#xA;// Верхняя и нижняя&#xA;arr_new[2] = getSideParallelProjection(arr[4], arr[5], arr[6]);&#xA;&#xA;return arr_new;&#xA;}&#xA;&#xA;// Параллельная проекция грани&#xA;function getSideParallelProjection(side1, side2, cubeCenter) {&#xA;&#xA;    // Сначала выясним какая пара нам попалась&#xA;    var centralProjection1 = getPointParallelProjection(side1[4]);&#xA;    var centralProjection2 = getPointParallelProjection(side2[4]);&#xA;&#xA;    var coordinate = {&#xA;        x:Math.abs(side1[4].x - side2[4].x),&#xA;        y:Math.abs(side1[4].y - side2[4].y),&#xA;        z:Math.abs(side1[4].z - side2[4].z)};&#xA;&#xA;    var i;&#xA;&#xA;    // Найдем дальнюю (1) и ближнюю (2) от экрана точки&#xA;    // по оси (Z) и посчитаем их проекции&#xA;    var point1 = {z:10000},&#xA;    point2 = {z:-10000},&#xA;    point3 = {z:10000};&#xA;&#xA;    for (i = 0; i &amp;lt; 4; i++) {&#xA;        if (point1.z &amp;gt; side1[i].z) {&#xA;            point1 = side1[i];&#xA;        }&#xA;        if (point1.z == side1[i].z&#xA;            &amp;amp;&amp;amp; point1.x &amp;gt; side1[i].x) {&#xA;            point1 = side1[i];&#xA;        }&#xA;        if (point1.z == side1[i].z&#xA;            &amp;amp;&amp;amp; point1.x == side1[i].x&#xA;            &amp;amp;&amp;amp; point1.y &amp;lt; side1[i].y) {&#xA;            point1 = side1[i];&#xA;        }&#xA;        if (point2.z &amp;lt; side1[i].z) {&#xA;            point2 = side1[i];&#xA;        }&#xA;        if (point2.z == side1[i].z&#xA;            &amp;amp;&amp;amp; point2.x &amp;lt; side1[i].x) {&#xA;            point2 = side1[i];&#xA;        }&#xA;        if (point2.z == side1[i].z&#xA;            &amp;amp;&amp;amp; point2.x == side1[i].x&#xA;            &amp;amp;&amp;amp; point2.y &amp;gt; side1[i].y) {&#xA;            point2 = side1[i];&#xA;        }&#xA;    }&#xA;&#xA;    for (i = 0; i &amp;lt; 4; i++) {&#xA;        if (point3.z &amp;gt; side1[i].z&#xA;            &amp;amp;&amp;amp; point1 != side1[i]) {&#xA;            point3 = side1[i];&#xA;        }&#xA;        if (point3.z == side1[i].z&#xA;            &amp;amp;&amp;amp; point3.x &amp;gt; side1[i].x&#xA;            &amp;amp;&amp;amp; point1 != side1[i]) {&#xA;            point3 = side1[i];&#xA;        }&#xA;        if (point3.z == side1[i].z&#xA;            &amp;amp;&amp;amp; point3.x == side1[i].x&#xA;            &amp;amp;&amp;amp; point3.y &amp;lt; side1[i].y&#xA;            &amp;amp;&amp;amp; point1 != side1[i]) {&#xA;            point3 = side1[i];&#xA;        }&#xA;    }&#xA;&#xA;    var direction = (point3.x - point1.x) / (point2.x - point1.x)&#xA;                  - (point3.y - point1.y) / (point2.y - point1.y);&#xA;    var projection = [];&#xA;&#xA;    // (X) Правая и левая грани&#xA;    if (coordinate.x &amp;gt; coordinate.y &amp;amp;&amp;amp; coordinate.x &amp;gt; coordinate.z) {&#xA;&#xA;        point1 = getPointParallelProjection(point1);&#xA;        point2 = getPointParallelProjection(point2);&#xA;        point3 = getPointParallelProjection(point3);&#xA;&#xA;        var direction = (point3.x - point1.x) / (point2.x - point1.x)&#xA;                      - (point3.y - point1.y) / (point2.y - point1.y);&#xA;&#xA;        var selected;&#xA;&#xA;        if (point1.x &amp;gt;= point2.x) {&#xA;            if (centralProjection1.x &amp;gt;= centralProjection2.x) {&#xA;                selected = side1;&#xA;            } else {&#xA;                selected = side2;&#xA;            }&#xA;        } else {&#xA;            if (centralProjection1.x &amp;lt;= centralProjection2.x) {&#xA;                selected = side1;&#xA;            } else {&#xA;                selected = side2;&#xA;            }&#xA;        }&#xA;&#xA;        if (selected.length &amp;lt; 6) {&#xA;            for (i = 0; i &amp;lt; 4; i++) {&#xA;                projection[i] = getPointParallelProjection(selected[i]);&#xA;            }&#xA;            projection[4] = 'rgb(200,200,0)';&#xA;        }&#xA;    }&#xA;&#xA;    // (Z) Передняя и задняя грани&#xA;    else if (coordinate.z &amp;gt; coordinate.x &amp;amp;&amp;amp; coordinate.z &amp;gt; coordinate.y) {&#xA;&#xA;        var selected;&#xA;&#xA;        if (point1.x &amp;gt;= point2.x &amp;amp;&amp;amp; direction &amp;lt; 0) {&#xA;            if (centralProjection1.x &amp;gt;= centralProjection2.x) {&#xA;                selected = side1;&#xA;            } else {&#xA;                selected = side2;&#xA;            }&#xA;        } else {&#xA;            if (centralProjection1.x &amp;lt;= centralProjection2.x) {&#xA;                selected = side1;&#xA;            } else {&#xA;                selected = side2;&#xA;            }&#xA;        }&#xA;&#xA;        if (selected.length &amp;lt; 6) {&#xA;            for (i = 0; i &amp;lt; 4; i++) {&#xA;                projection[i] = getPointParallelProjection(selected[i]);&#xA;            }&#xA;            projection[4] = 'rgb(200,0,0)';&#xA;        }&#xA;    }&#xA;&#xA;    // (Y) Верхняя и нижняя грани&#xA;    else {&#xA;&#xA;        var selected;&#xA;&#xA;        if (point1.y &amp;lt;= point2.y) {&#xA;            if (centralProjection1.y &amp;lt;= centralProjection2.y) {&#xA;                selected = side1;&#xA;            } else {&#xA;                selected = side2;&#xA;            }&#xA;        } else {&#xA;            if (centralProjection1.y &amp;gt;= centralProjection2.y) {&#xA;                selected = side1;&#xA;            } else {&#xA;                selected = side2;&#xA;            }&#xA;        }&#xA;&#xA;        if (selected.length &amp;lt; 6) {&#xA;            for (i = 0; i &amp;lt; 4; i++) {&#xA;                projection[i] = getPointParallelProjection(selected[i]);&#xA;            }&#xA;            projection[4] = 'rgb(0,0,0)';&#xA;        }&#xA;    }&#xA;&#xA;    return projection;&#xA;}&#xA;&#xA;// Параллельная проекция точки&#xA;function getPointParallelProjection(point) {&#xA;return {&#xA;    x:point.x,&#xA;    y:point.y + point.z / 4};&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;pre class=&quot;lang-html prettyprint-override&quot;&gt;&lt;code&gt;&amp;lt;canvas id=&amp;quot;animation&amp;quot; width=&amp;quot;300&amp;quot; height=&amp;quot;300&amp;quot;&amp;gt;&#xA;    &amp;lt;p&amp;gt;Your browser does not support Canvas&amp;lt;/p&amp;gt;&#xA;&amp;lt;/canvas&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;" OwnerDisplayName="user7220" LastEditorUserId="13095" LastEditDate="2020-11-06T08:55:36.630" LastActivityDate="2020-11-06T08:55:36.630" Title="The distance from the cube sides to the parallel projection plane" Tags="&lt;3d&gt;&lt;projections&gt;&lt;javascript&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="5539" PostTypeId="1" CreationDate="2017-08-29T22:25:54.133" Score="2" ViewCount="105" Body="&lt;p&gt;There is a &lt;a href=&quot;https://www.ted.com/talks/michael_hansmeyer_building_unimaginable_shapes&quot; rel=&quot;nofollow noreferrer&quot;&gt;TED presentation&lt;/a&gt;, where we see really good looking geometries, which are generated using space folding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get the general idea, that we start from a basic geometry like a cube, and then apply linear transformations and conditional foldings (reflecting a point on a plane). I tried it, but my results were not really good looking.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am looking for the algorithm, to generate geometries like that. But by guessing I can not progress further. Unfortunately I was not able to find articles, explaining it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is an example from the video:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0Khps.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0Khps.png&quot; alt=&quot;before folding&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/toj2t.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/toj2t.jpg&quot; alt=&quot;after folding&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7028" LastActivityDate="2017-09-01T06:41:58.023" Title="How is it possible to generate geometries using space folding?" Tags="&lt;transformations&gt;&lt;geometry&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5540" PostTypeId="1" AcceptedAnswerId="5542" CreationDate="2017-08-30T01:59:26.593" Score="1" ViewCount="1167" Body="&lt;p&gt;I've been working on a 2d shadow system for a school project, using &lt;a href=&quot;http://ncase.me/sight-and-light/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this method&lt;/a&gt; to generate visibility polygons. However, I'm having issues figuring out how to draw those visibility polygons in a way that reveals everything drawn within them, rather than drawing over them like a normal sprite would.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I've been able to figure out, it seems like what I want to do is to draw the visibility polygons to some texture first, and then use that texture somehow when drawing the rest of the objects on the screen to get the shadow/light effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately all the tutorials I've been able to find aren't very helpful. So, my questions are:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) How do I tell OpenGL to render to a texture instead of the screen?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) How do I use that texture to create the effect I want?&lt;/p&gt;&#xA;" OwnerUserId="7202" LastActivityDate="2017-08-30T07:18:24.450" Title="OpenGL: Rendering 2D shadows" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;texture&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5542" PostTypeId="2" ParentId="5540" CreationDate="2017-08-30T07:12:36.397" Score="3" Body="&lt;p&gt;You don't need to render to texture to achieve an effect like this. Use &lt;a href=&quot;https://open.gl/depthstencils&quot; rel=&quot;nofollow noreferrer&quot;&gt;stencil buffer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The visibility polygon can be drawn using &lt;code&gt;GL_TRIANGLE_FAN&lt;/code&gt;, if you start from the middle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/R6FZS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/R6FZS.png&quot; alt=&quot;mask&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the beginning of each frame:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Clear the stencil buffer (and enable stencil test)&lt;/li&gt;&#xA;&lt;li&gt;Set the stencil function to always pass, and to replace the current value in the buffer to a greater than zero number (for example one)&lt;/li&gt;&#xA;&lt;li&gt;Draw the visible part as a &lt;code&gt;GL_TRIANGLE_FAN&lt;/code&gt;. If you have multiple characters/lights, draw the visibility polygon for each.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Now the stencil buffer contains 1 at visible locations and 0 where the character can't see.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have a stencil buffer like this, you can control which objects you want to draw using glStencilFunc. Do not write to the stencil buffer, just use the stencil test to discard fragments which are visible/invisible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to draw a background which is visible everywhere, use &lt;code&gt;GL_ALWAYS&lt;/code&gt;. For objects which are only displayed in the visible area use &lt;code&gt;GL_EQUAL&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt;. Similarly you can draw something (for example a dark quad) just in the invisible parts of the scene with &lt;code&gt;GL_EQUAL&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it is not clear, how to use stencil buffers, check out &lt;a href=&quot;https://open.gl/depthstencils&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7028" LastEditorUserId="7028" LastEditDate="2017-08-30T07:18:24.450" LastActivityDate="2017-08-30T07:18:24.450" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5543" PostTypeId="2" ParentId="5521" CreationDate="2017-08-30T08:54:57.873" Score="2" Body="&lt;p&gt;I found an answer in the form of the &lt;a href=&quot;https://en.wikipedia.org/wiki/Todd%E2%80%93Coxeter_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Todd-Coxeter Algorithm&lt;/a&gt; from group theory. This still involves iterating over permutations of the group, and removing duplicates. However, the group can be defined using symbols to represent different sequences of operations, and duplicate-matching performed on these symbols rather than elements of the group itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if a pair of mirrors A and B have an angle of (PI/3) then they form a cycle of order 3 (since a reflection through a pair of mirrors equals a rotation through twice the angle between them). So the sequence ABABAB maps any element back onto itself. By constructing a path like this for each pair of mirrors, it's possible to define new elements for each step along a path, then eliminate duplicates either through string-matching operations or by constructing a graph and eliminating equivalent nodes. For large sets, this should be much more efficient than multiplying and comparing matrices directly at each step.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-08-30T08:54:57.873" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5544" PostTypeId="2" ParentId="5538" CreationDate="2017-08-30T11:25:59.247" Score="0" Body="&lt;p&gt;According to your comment, your goal is to avoid drawing the invisible faces.&#xA;There is no reason to find the closest 3 sides of the cube and draw them, because it is possible that only one or tho sides are visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finding the exact distance from a polygon in 3D space is computationally expensive. Instead of doing it, I would like to suggest a better method:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Use &lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_(geometry)&quot; rel=&quot;nofollow noreferrer&quot;&gt;face normals&lt;/a&gt;. A normal is a vector, which is perpendicular to a given surface at a given point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you calculate the normal vector (and the points of the polygon) in world space, you can decide using a simple dot product, if the polygon is facing towards the camera:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool is_visisble = 0 &amp;lt; dot(&#xA;    transformMat4(face.normal, world_mat_it), // normal in world space&#xA;    // vec from face midpoint to the camera position&#xA;    sub(&#xA;        eye, // camera position&#xA;        transformMat4(face.midpoint, world_mat) // Face midpoint in world space&#xA;    )&#xA;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here you can find a renderer written is javascript, which uses this method: &lt;a href=&quot;https://jsfiddle.net/deadmanswitch/sw22s4fs/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://jsfiddle.net/deadmanswitch/sw22s4fs/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there are more complex objects in the scene, then you should order the faces by the distance between the midpoint and the camera, and draw the farthest ones first, to avoid rendering farther objects over closer ones.&lt;/p&gt;&#xA;" OwnerUserId="7028" LastEditorUserId="7028" LastEditDate="2017-08-30T11:34:32.957" LastActivityDate="2017-08-30T11:34:32.957" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5547" PostTypeId="1" CreationDate="2017-08-31T08:04:29.587" Score="3" ViewCount="174" Body="&lt;p&gt;I'm currently fighting with the spectrum-&gt;RGB color conversions, my algorithm seems to make an error somewhere, e.g. I get values &gt;1 for some spectral responses.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now there is a way to calculate an rgb value for normal incidence from index of refraction:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;F(0°) = $(\frac{n-1}{n+1})^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where n is the index of refraction (Real-Time Rendering 3rd, p.234 f.)&#xA;And if $n$ is constant, you can use it for all RGB channels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if I calculate the spectral value with my spectrum-&gt;RGB conversion and just use a constant $n$, I get different values for R, G and B.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically, $n = 1.52$ would lead to $RGB_{single} = (0.04257999496;0.04257999496;0.04257999496)$ whereas my program calculates $RGB_{spectrum} = 0.054223;0.042692;0.041095$ (evaluated at $390nm - 780nm$ with $\Delta\lambda = 10nm$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question now is: would a constant index of refraction really lead to a grayscale (i.e. all channels the same) value? Because the conversion functions depend on the CIE functions, taking the integral of those and clearly the integrals are different for $x, y, z$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also: since I seem to have a problem with my program in the first place: is there a step by step tutorial for creating the conversion function somewhere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 01.09.2017 10:25&lt;/strong&gt;&#xA;After being asked to share my code, here goes (in a somewhat top-down approach):&#xA;First I read the CIE functions from file and store them in a std::vector&gt; with wavelength as key and function value as value. the vector just encapsulates x, y and z independently.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;std::vector&amp;lt;std::map&amp;lt;float, float&amp;gt;&amp;gt; cieFunctions = readCieFunctions(ciePath);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now cieFunctions.at(0) is the x function and so forth.&#xA;I read in the spectral values basically the same way, into a map with key being the wavelength and value being the reflectivity. Here I take care to match the units, wavelength as $nm$ and reflectivity in values $\in [0, 1]$ (rather than $\in [0, 100]$%).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having reached this, I call my &lt;code&gt;calculateRgbValue(std::map&amp;lt;float, float&amp;gt;spectralValue)&lt;/code&gt; function, where I use the matrix for a D65 white point monitor. I calculate the coordinate, divide it by the integral of Y over the visible wavelength spectrum (constant taken from Physically Based Rendering book) and use that in a multiplcation with said matrix to get the RGB value:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;QString SpectralToRGBConverter::calculateRgbValue(std::map&amp;lt;float, float&amp;gt; spectralValues)&#xA;{&#xA;QString result;&#xA;Vec3 rgb;&#xA;&#xA;Mat3 conversionMatrix(&#xA;    3.240479, -1.537150, -0.498535,&#xA;    -0.969256, 1.875992, 0.041556,&#xA;    0.055648, -0.204043, 1.057311);&#xA;&#xA;float X = calcCieCoordinate(spectralValues, cieFunctions.at(0));&#xA;float Y = calcCieCoordinate(spectralValues, cieFunctions.at(1));&#xA;float Z = calcCieCoordinate(spectralValues, cieFunctions.at(2));&#xA;&#xA;float yIntegral = 106.856895;   //from Phyiscally Based Rendering 3rd, p. 325&#xA;&#xA;Vec3 XYZ(X, Y, Z);&#xA;XYZ /= yIntegral;&#xA;&#xA;rgb = conversionMatrix*XYZ;&#xA;&#xA;result = (std::to_string(rgb.x) + &quot;;&quot; + std::to_string(rgb.y) + &quot;;&quot; + std::to_string(rgb.z)).c_str();&#xA;return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;The idea of calculating the cie coordinate is best described with the mathematical formula:&#xA;$coord = \sum_{i=0}^{n-1}x_i c_i \Delta\lambda$ where $n$ is the number of samples in the spectrum, $x_i$ is the $i-th$ cie function value for the wavelength of the $i-th$ sample and $c_i$ is the $i-th$ function value of the spectrum and $\Delta\lambda$ is the stride between two samples $\Delta\lambda = \lambda_{i+1} - \lambda_i$&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float SpectralToRGBConverter::calcCieCoordinate(std::map&amp;lt;float, float&amp;gt; spectralValues, std::map&amp;lt;float, float&amp;gt; function)&#xA;{&#xA;//http://www.brucelindbloom.com/index.html?Eqn_Spect_to_XYZ.html&#xA;//Coordinate = Int_lambda function(lambda) * spectralValue(lambda) dlambda&#xA;//for discrete values:&#xA;//Coordinate = Sum_i function(i) * spectalValue(i) * Delta lambda&#xA;//where Delta lambda is the spacing between two measurements&#xA;float deltaLambda;// in nm&#xA;auto first = spectralValues.begin();&#xA;auto second = std::next(first, 1);&#xA;&#xA;if (ui.radioButtonMicroMeter-&amp;gt;isChecked())&#xA;{&#xA;    deltaLambda = (second-&amp;gt;first - first-&amp;gt;first) * 1000;&#xA;}&#xA;else&#xA;{&#xA;    deltaLambda = second-&amp;gt;first - first-&amp;gt;first;&#xA;}&#xA;&#xA;float coordinate = 0;&#xA;for (auto pairWavelengthReflectance : spectralValues)&#xA;{&#xA;    coordinate += getFunctionValue(function, pairWavelengthReflectance.first) * pairWavelengthReflectance.second * deltaLambda;&#xA;}&#xA;&#xA;return coordinate;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;getFunctionValue&lt;/code&gt; is basically a nearest neighbor sampling:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float SpectralToRGBConverter::getFunctionValue(std::map&amp;lt;float, float&amp;gt; function, float x)&#xA;{&#xA;float conversionFactorWaveLength;&#xA;if (ui.radioButtonMicroMeter-&amp;gt;isChecked())&#xA;{&#xA;    //if x is not in nm like function.first&#xA;    conversionFactorWaveLength = 1000;&#xA;}&#xA;else&#xA;{&#xA;    conversionFactorWaveLength = 1;&#xA;}&#xA;&#xA;float conversionFactorReflectivityScale;&#xA;if (ui.radioButtonPercentage-&amp;gt;isChecked())&#xA;{&#xA;    //if the reflectivity is given in percentages [0, 100] rather than proportions [0, 1]&#xA;    conversionFactorReflectivityScale = 0.01;   &#xA;}&#xA;else&#xA;{&#xA;    conversionFactorReflectivityScale = 1;&#xA;}&#xA;&#xA;float xLookUp = x * conversionFactorWaveLength;&#xA;float previous = 0;&#xA;for (auto pairXY : function)&#xA;{   //maps are sorted&#xA;    float current = pairXY.first;&#xA;    if (current == xLookUp)&#xA;    {&#xA;        return function[current] * conversionFactorReflectivityScale;&#xA;    }&#xA;    else&#xA;    if (current &amp;gt; xLookUp)&#xA;    {&#xA;        //get the closest value to x&#xA;        float min;&#xA;        if (xLookUp - previous &amp;lt; current - xLookUp)&#xA;        {&#xA;            min = previous;&#xA;        }&#xA;        else&#xA;        {&#xA;            min = current;&#xA;        }&#xA;        return function[min] * conversionFactorReflectivityScale;&#xA;    }&#xA;    previous = current;&#xA;}&#xA;return -1;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2017-09-01T08:24:58.267" LastActivityDate="2021-02-06T08:01:15.117" Title="Does a constant reflection over the light spectrum lead to grayscale value?" Tags="&lt;color-science&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5548" PostTypeId="1" AcceptedAnswerId="5549" CreationDate="2017-08-31T23:36:44.823" Score="1" ViewCount="708" Body="&lt;p&gt;I tried implementing &lt;code&gt;Perlin Noise&lt;/code&gt; using the &lt;code&gt;Wikipedia&lt;/code&gt; as my main resource. From what I can tell my implementation of the algorithm is spot on but for some reason I'm getting a lot of values equating to 1 or to 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my Perlin function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat perlin(GLfloat x, GLfloat y)&#xA;{&#xA;    // Turn param into vector&#xA;    glm::vec2 xy = glm::vec2(x, y);&#xA;&#xA;    // Grid Cell Coordinates&#xA;    glm::vec2 bottomLeft = glm::vec2(std::floor(x), std::floor(y));&#xA;    glm::vec2 topRight = glm::vec2(bottomLeft.x + 1, bottomLeft.y + 1);&#xA;&#xA;    GLfloat sx = x - bottomLeft.x;&#xA;    GLfloat sy = y - bottomLeft.y;&#xA;&#xA;    GLfloat bottomLeftDot = glm::dot(gradients[(GLint)bottomLeft.x][(GLint)bottomLeft.y], xy - bottomLeft);&#xA;    GLfloat bottomRightDot = glm::dot(gradients[(GLint)topRight.x][(GLint)bottomLeft.y], xy - glm::vec2(topRight.x, bottomLeft.y));&#xA;&#xA;    GLfloat smooth1 = glm::smoothstep(bottomLeftDot, bottomRightDot, sx);&#xA;&#xA;    GLfloat topLeftDot = glm::dot(gradients[(GLint)bottomLeft.x][(GLint)topRight.y], xy - glm::vec2(bottomLeft.x, topRight.y));&#xA;    GLfloat topRightDot = glm::dot(gradients[(GLint)topRight.x][(GLint)topRight.y], xy - topRight);&#xA;&#xA;    GLfloat smooth2 = glm::smoothstep(topLeftDot, topRightDot, sx);&#xA;&#xA;    GLfloat value = glm::smoothstep(smooth1, smooth2, sy);&#xA;    return value;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/p5zn0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/p5zn0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, I am using the generated values as a height map. In the image above you can see that there's a straight wall and I'm wondering if maybe I'm not interpolating correctly. Can someone point out my mistake?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm generating a 100 by 100 grid and my input values are from 0.00 to 0.99 on each axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another question I have is Wikipedia says to use a smoothstep function but I'm not sure for what values?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;:&#xA;I changed the &lt;code&gt;smoothstep&lt;/code&gt; and function to the &lt;code&gt;lerp&lt;/code&gt; function and now everything seems to be working well but can someone please explain why the outcome is so drastically different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;New outcome below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qE0qp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qE0qp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6546" LastEditorUserId="6546" LastEditDate="2017-09-01T02:15:51.063" LastActivityDate="2017-09-01T04:27:54.810" Title="Perlin Noise with Smooth function vs Lerp" Tags="&lt;interpolation&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5549" PostTypeId="2" ParentId="5548" CreationDate="2017-09-01T04:27:54.810" Score="3" Body="&lt;p&gt;It looks like the way you're using smoothstep isn't quite right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With lerp, the first two parameters are the endpoints of the output range, and the third is a 0–1 value specifying how far to interpolate. It looks like you're trying to use smoothstep the same way, but it doesn't work like that: the first two parameters to smoothstep are endpoints of the &lt;em&gt;input&lt;/em&gt; range, and the third is a value in the input range; the output of smoothstep is always in 0–1. It's almost the inverse of lerp in that regard. (See also &lt;a href=&quot;https://glm.g-truc.net/0.9.4/api/a00129.html#gabdfe71a62ef69b5ec834601e87588667&quot; rel=&quot;nofollow noreferrer&quot;&gt;the GLM docs for smoothstep&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To use smoothstep here, you'd want to do something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::lerp(bottomLeftDot, bottomRightDot, glm::smoothstep(0, 1, sx));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This applies smoothstep to the &lt;code&gt;sx&lt;/code&gt; value (which is between 0 and 1). The result, which is another 0–1 value, is then used to lerp between the two &quot;dot&quot; values.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-09-01T04:27:54.810" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5550" PostTypeId="1" AcceptedAnswerId="5554" CreationDate="2017-09-01T04:55:33.183" Score="1" ViewCount="421" Body="&lt;p&gt;In &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferStorage.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;the documentation&lt;/a&gt; I see that the final parameter for &lt;code&gt;glNamedBufferStorage&lt;/code&gt; is &lt;code&gt;flags&lt;/code&gt; and that &lt;code&gt;flags&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Specifies the intended usage of the buffer's data store. Must be a bitwise combination of the following flags. GL_DYNAMIC_STORAGE_BIT, GL_MAP_READ_BIT GL_MAP_WRITE_BIT, GL_MAP_PERSISTENT_BIT, GL_MAP_COHERENT_BIT, and GL_CLIENT_STORAGE_BIT.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;However, in the older &lt;code&gt;glBufferData&lt;/code&gt; we use to specify a &lt;code&gt;usage&lt;/code&gt; flag which would include things such as &lt;code&gt;GL_STATIC_DRAW&lt;/code&gt; to specify expected usage patterns.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where do we include that with the newer OpenGL?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-04-30T18:40:07.433" LastActivityDate="2018-04-30T18:40:07.433" Title="How to set flags and usage glnamedBufferStorage in new OpenGL 4.4+ (GL_STATIC_DRAW)?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5551" PostTypeId="2" ParentId="5528" CreationDate="2017-09-01T05:00:49.610" Score="2" Body="&lt;p&gt;Yes, this is called bilinear interpolation or a bilinear mapping. The term &quot;bilinear&quot; crops up more commonly in the context of image resizing or resampling, but it's the same basic idea for transforming quadrilaterals—it's just that the interpolation is applied to the vertex positions of the quad, instead of the colors of pixels in an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One paper that briefly discusses bilinear mappings of quadrilaterals is &lt;a href=&quot;https://www.cs.cmu.edu/~ph/texfund/texfund.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fundamentals of Texture Mapping and Image Warping&lt;/a&gt; by Paul Heckbert; see section 2.2.2.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-09-01T05:00:49.610" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5552" PostTypeId="1" AcceptedAnswerId="5553" CreationDate="2017-09-01T06:25:39.153" Score="0" ViewCount="117" Body="&lt;p&gt;The typical way I see transform feedback being used is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    glGenBuffers(1, &amp;amp;tbo);&#xA;    glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tbo);&#xA;    glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(data), nullptr, GL_DYNAMIC_COPY);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, new, DSA OpenGL eschews the binding points.  Is there a DSA way to bind a buffer to the transform feedback binding point?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="127" LastEditDate="2017-09-01T16:07:51.327" LastActivityDate="2017-09-30T15:57:05.677" Title="Is there a DSA technique for transform feedback?" Tags="&lt;opengl&gt;&lt;transform-feedback&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5553" PostTypeId="2" ParentId="5552" CreationDate="2017-09-01T08:10:14.527" Score="1" Body="&lt;p&gt;Binding points (and other state) are still important when doing actual draw calls (stuff like VAOs, UBOs, SSBOs and programs are still bound). It's only bind-to-edit that was eschewed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case the most DSA way to do that would be: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glCreateBuffers(1, &amp;amp;tbo);&#xA;glNamedBufferData(tbo,sizeof(data), nullptr, GL_DYNAMIC_COPY);&#xA;&#xA;glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tbo);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastEditorUserId="2654" LastEditDate="2017-09-30T15:57:05.677" LastActivityDate="2017-09-30T15:57:05.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5554" PostTypeId="2" ParentId="5550" CreationDate="2017-09-01T08:15:20.380" Score="2" Body="&lt;p&gt;The usage flag in BufferData was basically useless. There is no functional difference between each value and drivers used other ways to decide how to handle its data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;flags&lt;/code&gt; parameter on the other hand actually changes what you can do with the buffer.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-09-01T08:15:20.380" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5555" PostTypeId="2" ParentId="5552" CreationDate="2017-09-01T14:35:03.900" Score="5" Body="&lt;p&gt;There isn't a DSA way to bind buffers to the feedback buffer bindings. But that's because &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Transform_Feedback#Feedback_objects&quot; rel=&quot;noreferrer&quot;&gt;transform feedbacks are &lt;em&gt;objects&lt;/em&gt;&lt;/a&gt;, and there &lt;em&gt;is&lt;/em&gt; a DSA way to attach buffers to transform feedback objects:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLuint buffer;&#xA;glCreateBuffers(1, &amp;amp;buffer);&#xA;//Fill in buffer's data.&#xA;&#xA;GLuint feedback;&#xA;glCreateTransformFeedbacks(1, &amp;amp;feedback);&#xA;glTransformFeedbackBufferRange(feedback, 0, buffer, offset, size);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can then bind &lt;code&gt;feedback&lt;/code&gt; when you're ready to actually do your feedback operations into those buffers.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-09-01T14:35:03.900" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5556" PostTypeId="1" AcceptedAnswerId="5560" CreationDate="2017-09-01T17:42:45.150" Score="16" ViewCount="3551" Body="&lt;p&gt;My question is specifically in regards to Metal, since I don't know if the answer would change for another API.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I believe I understand so far is this:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;A mipmapped texture has precomputed &quot;levels of detail&quot;, where lower levels of detail are created by downsampling the original texture in some meaningful way.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Mipmap levels are referred to in descending level of detail, where level &lt;code&gt;0&lt;/code&gt; is the original texture, and higher-levels are power-of-two reductions of it.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Most GPUs implement trilinear filtering, which picks two neighboring mipmap levels for each sample, samples from each level using bilinear filtering, and then linearly blends those samples.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What I don't quite understand is how these mipmap levels are selected. In the &lt;a href=&quot;https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf&quot; rel=&quot;noreferrer&quot;&gt;documentation&lt;/a&gt; for the Metal standard library, I see that samples can be taken, with or without specifying an instance of a &lt;code&gt;lod_options&lt;/code&gt; type. I would assume that this argument changes how the mipmap levels are selected, and there are apparently three kinds of &lt;code&gt;lod_options&lt;/code&gt; for 2D textures:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;bias(float value)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;level(float lod)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;gradient2d(float2 dPdx, float2 dPdy)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the documentation doesn't bother explaining what any of these options do. I can guess that &lt;code&gt;bias()&lt;/code&gt; biases some automatically chosen level of detail, but then what does the bias &lt;code&gt;value&lt;/code&gt; mean? What scale does it operate on? Similarly, how is the &lt;code&gt;lod&lt;/code&gt; of &lt;code&gt;level()&lt;/code&gt; translated into discrete mipmap levels? And, operating under the assumption that &lt;code&gt;gradient2d()&lt;/code&gt; uses the gradient of the texture coordinate, how does it use that gradient to select the mipmap level?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More importantly, if I omit the &lt;code&gt;lod_options&lt;/code&gt;, how are the mipmap levels selected then? Does this differ depending on the type of function being executed?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And, if the default no-lod-options-specified operation of the &lt;code&gt;sample()&lt;/code&gt; function is to do something like &lt;code&gt;gradient2D()&lt;/code&gt; (at least in a fragment shader), does it utilize simple screen-space derivatives, or does it work directly with rasterizer and interpolated texture coordinates to calculate a precise gradient?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally, how consistent is any of this behavior from device to device? An old article (old as in DirectX 9) I read referred to complex device-specific mipmap selection, but I don't know if mipmap selection is better-defined on newer architectures.&lt;/p&gt;&#xA;" OwnerUserId="7238" LastActivityDate="2018-10-23T16:20:20.933" Title="How are mipmap levels computed in Metal?" Tags="&lt;texture&gt;&lt;interpolation&gt;&lt;rasterizer&gt;&lt;filtering&gt;&lt;mipmap&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5557" PostTypeId="1" CreationDate="2017-09-01T20:03:25.607" Score="1" ViewCount="90" Body="&lt;p&gt;Below are the original image and a JPEG encoded/decoded image. To my untrained eyes, cyan becomes yellow, yellow becomes magenta, and magenta becomes cyan. Obviously there's a problem with the encoding and/or decoding, but I'd appreciate a more specific answer, along the lines of: &quot;The image was encoded in X [color space], but was decoded in Y.&quot; Thank you. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xJK6x.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xJK6x.png&quot; alt=&quot;original&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4Fu3g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Fu3g.png&quot; alt=&quot;JPEG&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7239" LastActivityDate="2017-09-01T20:03:25.607" Title="What causes this color shift?" Tags="&lt;color&gt;&lt;compression&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5558" PostTypeId="1" AcceptedAnswerId="5559" CreationDate="2017-09-02T22:01:33.643" Score="3" ViewCount="1472" Body="&lt;p&gt;I am reading the OpenGL SuperBible 7th edition which covers &lt;em&gt;atomic operations&lt;/em&gt; on memory specifically within shader storage blocks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It says (about atomic operations):&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If two invocations access the same memory locations... then they will be &lt;em&gt;serialized&lt;/em&gt; and only one will get to go at one time.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Great. However, it then goes on to cover &lt;strong&gt;Synchronizing Access to Memory&lt;/strong&gt; specifically and the use of &lt;code&gt;glMemoryBarrier&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I understand it, you need to use &lt;code&gt;glMemoryBarrier&lt;/code&gt; once you start writing to buffers from shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the distinction is not made clear to me about &lt;em&gt;why&lt;/em&gt; I need to use a barrier if the operations I am doing within my shader are atomic operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's possible I am conflating atomic operations and general memory access, but, in the book the line is not clearly drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When is it that a &lt;code&gt;glMemoryBarrier&lt;/code&gt; is required? Is it &lt;strong&gt;everytime&lt;/strong&gt; a shader writes to memory (whether the operations are atomic or not)?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-04-30T18:38:54.110" LastActivityDate="2018-04-30T18:38:54.110" Title="Why do I need memory barrier when doing atomic operations?" Tags="&lt;opengl&gt;&lt;memory&gt;&lt;synchronization&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5559" PostTypeId="2" ParentId="5558" CreationDate="2017-09-02T22:31:26.180" Score="4" Body="&lt;p&gt;&lt;code&gt;glMemoryBarrier&lt;/code&gt; is for when you want to make &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Memory_Model#Incoherent_memory_access&quot; rel=&quot;nofollow noreferrer&quot;&gt;writes from one rendering command visible to reads from a subsequent rendering command&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is, you can do all the atomics you like during a rendering command. But without the barrier, there's no guarantee that any of those atomic actions will be visible to later commands. Yes, they will still be &lt;em&gt;atomic&lt;/em&gt;, but this only ensures that they will each execute in some order and each operation will fully execute before the next. What they won't ensure is that operations which OpenGL defines has happening &quot;later&quot; will execute before earlier operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sometimes, you actually don't care about the order of the operations; being atomic may be enough. And sometimes, you &lt;em&gt;do care&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the case of a &quot;linked-list&quot; style blending buffer. Each pixel in the image is an integer that represents one of the items in the list. Each FS invocation will use an atomic increment to get a unique identifier, then swap that identifier with the current value in the image. It writes its pixel data to the entry in an SSBO, along with the identifier it swapped out of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When doing that atomic increment on the unique identifier, you don't care if FS invocations from two different rendering commands execute out of order. You simply need the operation to be atomic. Similarly, the swap doesn't have to be in order; it just needs to be atomic. As long as they all execute, and the atomic operations do their jobs, then they will be fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, when it comes time to do blending based on this data, &lt;em&gt;that&lt;/em&gt; is when you need to be able to read all of the data that was previously written. And that rendering operation requires &lt;code&gt;glMemoryBarrier&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, you're not necessarily using atomic operations to &lt;em&gt;read&lt;/em&gt; these values.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-11-12T02:31:07.540" LastActivityDate="2017-11-12T02:31:07.540" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5560" PostTypeId="2" ParentId="5556" CreationDate="2017-09-02T23:29:48.480" Score="21" Body="&lt;p&gt;Mip selection is pretty well standardized across devices today—with the exception of some of the nitty-gritty details of anisotropic filtering, which is still up to the individual GPU manufacturers to define (and its precise details are generally not publicly documented).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A good place to read about mip selection  in detail is in &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf#page=273&quot; rel=&quot;noreferrer&quot;&gt;the OpenGL spec, section 8.14, &quot;Texture Minification&quot;&lt;/a&gt;. I'd assume it works the same way in Metal. (Apple &lt;em&gt;could&lt;/em&gt; have changed something, considering they make both the hardware and the API...but I doubt they have.) I'll summarize it here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The default mip selection (not using any of the &lt;code&gt;lod_options&lt;/code&gt; modifiers) uses the screen-space gradients of the texture coordinates to pick the mip levels. Essentially, it tries to pick the mip levels that produce as close as possible to a 1:1 mapping of texels to pixels. For example, if the gradients have a length of 4 texels per pixel, it would pick mip level 2 (which is 1/4th the size of level 0 and therefore gives you 1 mipped texel per pixel).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With trilinear filtering, since you usually don't land on an &lt;em&gt;exact&lt;/em&gt; 1:1 mapping, it picks the two nearest levels and linearly interpolates between them, so that you have a smooth transition between mip levels as the camera or objects in your scene move around.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be mathematically precise: you take the screen-space gradients of the texture coordinates, scale them by the texture size (to get them in units of &quot;texels per pixel&quot;), take their lengths, take the longer of the two (X and Y) gradients, and calculate its logarithm base 2. This quantity is called $\lambda$ in the OpenGL spec; it's also commonly known as the texture LOD (level of detail). It's simply a continuous version of the integer mip level index. So, the mip levels used are the two integers nearest to $\lambda$, and the fractional part of $\lambda$ is used to blend between them. For example if $\lambda = 2.8$, the GPU will sample mip levels 2 and 3 of the texture, then blend to 80% level 3 and 20% level 2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anisotropic filtering is turned on, then instead of simply using the longer of the two gradients, you use the ratio of them to set the number of aniso samples. For example, if the X gradient is 4 times longer than the Y gradient, you'd use 4 aniso samples, with their positions spaced out along the X gradient. Each one would be a trilinear sample, using a $\lambda$ corresponding to 1/4th the length of the X gradient (i.e. two mip levels lower, since $\log_2(1/4) = -2$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, as for the modifier options:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;bias&lt;/code&gt; applies an offset to $\lambda$ before using it to select mip levels. So, for example, a bias of +1 will make it do trilinear filtering using mips one level higher than it would normally. A bias of −1 will use mips one level lower, and so on.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;level&lt;/code&gt; completely overrides the automatic calculation of $\lambda$ from screen-space gradients, and lets you put in your own value of $\lambda$ (aka &lt;code&gt;lod&lt;/code&gt;) directly.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;gradient2d&lt;/code&gt; lets you put in your own gradient vectors, which substitute for the implicit screen-space gradients of the texture coordinates. The rest of the mip selection and sampling process proceeds as normal, but with the altered gradients. This lets you customize anisotropic filtering.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;In other types of shaders besides fragment shaders, there's no notion of &quot;screen-space gradients&quot;, so the latter two operations are typically the only ones allowed—any operation that tries to use implicit gradients would give a compile error. I'm not positive that's how Metal does it, but that's what I'd expect from working with other APIs.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-09-02T23:29:48.480" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5562" PostTypeId="1" AcceptedAnswerId="5564" CreationDate="2017-09-04T03:06:21.977" Score="3" ViewCount="738" Body="&lt;p&gt;The OpenGL SuperBible 7th Edition points out that &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the glMemoryBarrier() function supports a bit specifically for synchronizing access to atomic counters with other parts of the OpenGL pipeline&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;and describes its usage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Atomic_Counter&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Wiki&lt;/a&gt; says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Atomic counter memory access is not incoherent. So it follows the same rules as for texture reads, framebuffer writes, and so forth, not the Image Load/Store rules. You do not need to use a glMemoryBarrier to synchronize counter accesses.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So now I am confused:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I (and if so when do I) need to use &lt;code&gt;glMemoryBarrier&lt;/code&gt; when using an atomic counter?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2017-09-05T03:52:23.157" LastActivityDate="2020-04-12T16:25:21.887" Title="Do I need to use glMemoryBarrier with atomic counters?" Tags="&lt;opengl&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5563" PostTypeId="1" AcceptedAnswerId="5568" CreationDate="2017-09-04T03:27:43.530" Score="1" ViewCount="255" Body="&lt;p&gt;Scaling up or down a texture is quite simple, modify the UVs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my particular scenario though, I have multiple &quot;quads&quot; (it is a patch tessellation shader) each with a tiling texture. Does anyone know of a way to change the texture scale, while retaining the tiling in the shader?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is precomputing/scaling the uvs on the CPU the only option?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example of (traditional) tiling problem:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zHYzP.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zHYzP.jpg&quot; alt=&quot;tiling issue&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5978" LastActivityDate="2017-09-05T02:31:28.663" Title="How do you scale an image across planes while retaining perfect tiling?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;glsl&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5564" PostTypeId="2" ParentId="5562" CreationDate="2017-09-04T04:21:54.893" Score="4" Body="&lt;p&gt;The post October 22, 2019 version of the OpenGL 4.6 standard gives atomic counters the same incoherency restrictions as image load/store and SSBO operations. You have to use explicit barriers to synchronize access to them and so forth. This is a textual change from older versions of the standard, but it isn't a behavioral change from implementations. The older wording &lt;a href=&quot;https://github.com/KhronosGroup/OpenGL-API/issues/14&quot; rel=&quot;nofollow noreferrer&quot;&gt;is considered a bug&lt;/a&gt; and thus it should be assumed that atomic counters have always worked incoherently.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Note: the following predates the October 22, 2019 update to OpenGL 4.6.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the OpenGL 4.6 specification, section 7.12: Shader Memory Access:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;As described in the OpenGL Shading Language Specification, shaders may perform random-access reads and writes to buffer object memory by reading from, assigning to, or performing atomic memory operation on shader buffer variables, or to texture or buffer object memory by using built-in image load, store, and atomic functions operating on shader image variables. The ability to perform such random-access reads and writes in systems that may be highly pipelined results in ordering and synchronization issues discussed in the sections below.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Notice something missing from that list? It mentions &quot;shader buffer variables&quot;, and &quot;shader image variables&quot;. But atomic counter variables are not mentioned. And atomic counter variables are a different kind of thing from either of those.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, that entire section (which is what explains the behavior of &lt;code&gt;glMemoryBarrier&lt;/code&gt;) does not apply to atomic counters. Well, except where it specifically says otherwise, but that's only where it defines that helper FS invocations don't have side-effects. Note that even this &lt;em&gt;explicitly&lt;/em&gt; calls out atomic counters as being something different from regular buffer or image operations: &quot;stores, atomics, and atomic counter updates&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To lend greater credence to this view, the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shader_atomic_counters.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_atomic_counter_buffer_object&lt;/a&gt; extension does not mention barriers at all. It doesn't require &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_shader_image_load_store.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_shader_image_load_store&lt;/a&gt; as a companion extension either, which is what defines &lt;code&gt;glMemoryBarrier&lt;/code&gt;. Indeed, it has no interactions whatsoever with image load/store, while image load/store does have specified interactions with atomic counters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given the weight of the evidence in the specifications, I would have to say that the Wiki is right. In the interest of full disclosure, I did write that Wiki article. Though I also did all this research &lt;em&gt;before&lt;/em&gt; I wrote it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, what the API seems to be saying is that buffer updates from atomic counters are treated like buffer updates from feedback operations. The implementation is required to track when you attempt to use that buffer for a read operation, then issue any synchronization needed to make sure that you can read the value. Or if you write to the value in the buffer (like clearing it to a value), then the implementation must automatically synchronize this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The likely reason the specification permits this for atomic counters but not for image load/store is that the range of data for atomic counters is &lt;em&gt;fixed&lt;/em&gt;. SSBOs and image load/store through buffer textures can write to arbitrary parts of the bound range of buffer data. By contrast, atomic counters write to 4 bytes times the number of atomic counter variables used by the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note however that atomic counters are affected by the in-shader &lt;code&gt;memoryBarrier&lt;/code&gt; function. That is, atomic counters are subject to the requirements of, as the Wiki calls it, &quot;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Memory_Model#Internal_visibility&quot; rel=&quot;nofollow noreferrer&quot;&gt;Internal Visibility&lt;/a&gt;&quot;. Granted, that's not very useful most of the time, as the primary use of atomic counters is for when multiple invocations are all updating the same one.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;On the other hand:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the glMemoryBarrier() function supports a bit specifically for synchronizing access to atomic counters with other parts of the OpenGL pipeline&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The specification describes this particular barrier as:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Memory accesses using shader atomic counter built-in functions issued after the barrier will reflect data written by shaders prior to the barrier. Additionally, atomic counter function invocations after the barrier will not execute until all memory accesses (e.g., loads, stores, texture fetches, vertex fetches) initiated prior to the barrier complete.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What's curious about this is the &quot;all memory accesses&quot; part. This specific wording is only used in two other bits: shader storage and shader image. Other barriers for coherent operations like query buffers and transform feedbacks tend to use the term &quot;all shader writes&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So... I would say that there is confusion at the specification level.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-04-12T16:25:21.887" LastActivityDate="2020-04-12T16:25:21.887" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="5566" PostTypeId="2" ParentId="5463" CreationDate="2017-09-04T09:07:43.543" Score="1" Body="&lt;p&gt;Just say, that the angle between the surface and the vector pointing from the object to the camera is 30 degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To describe rotations, I suggest using the &quot;yaw, pitch, roll&quot;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iU6GY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iU6GY.png&quot; alt=&quot;yaw pitch roll&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7028" LastActivityDate="2017-09-04T09:07:43.543" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5567" PostTypeId="2" ParentId="5463" CreationDate="2017-09-04T14:29:40.150" Score="0" Body="&lt;p&gt;If you are writing a paper, you should just explain what you mean by your terms in the beginning of the paper, and include your illustrations (preferrably rendered in 3D)&lt;/p&gt;&#xA;" OwnerUserId="7250" LastActivityDate="2017-09-04T14:29:40.150" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5568" PostTypeId="2" ParentId="5563" CreationDate="2017-09-05T02:31:28.663" Score="1" Body="&lt;p&gt;One solution would be to use repeating texture wrapping, and then use a texture transformation matrix. So let's say you normally set the texture coordinates of your &lt;code&gt;GL_TEXTURE_2D&lt;/code&gt; to be 0-1 in &lt;code&gt;u&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt;. Instead, ensure that your &lt;code&gt;GL_TEXTURE_WRAP_S&lt;/code&gt; and &lt;code&gt;GL_TEXTURE_WRAP_T&lt;/code&gt; are set to &lt;code&gt;GL_REPEAT&lt;/code&gt; or &lt;code&gt;GL_MIRRORED_REPEAT&lt;/code&gt; and set the texture coordinates to be the tile number to tile number + 1. So the first one would still be 0 to 1. The second one would be 1 to 2, the third would be 2 to 3, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, your vertex shader would have a &lt;code&gt;mat4&lt;/code&gt; uniform called &lt;code&gt;textureMatrix&lt;/code&gt; or something like that. The texture matrix you pass in could have scaling in it (and probably other transformations, too). You just multiply the texture coordinates for the polygons by the texture matrix in the vertex shader, and it should apply appropriately.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-09-05T02:31:28.663" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5570" PostTypeId="1" AcceptedAnswerId="5572" CreationDate="2017-09-05T15:26:52.040" Score="2" ViewCount="139" Body="&lt;p&gt;While making a GPU Marching Cubes implementation a while back, I ran into the issue of OpenGL holding on to memory I had asked it to release. There are a lot of threads on this over at Stack Overflow, and the gist seems to be that you simply can't rely on the API to release VRAM  in a timely manner. In my app, I was trying to be smart, releasing all temp buffers used in mesh creation once I was done with them, and allocating an exact-sized vertex buffer each time the mesh changed. This was counterproductive, and rapidly led to out-of-memory crashes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my case, since it was just a toy app for a uni project, I solved it by allocating worst-case sized buffers and leaving them allocated, recycling buffer space wherever possible for different passes during the mesh extraction process. This was also a bit of an edge-case, since buffers were pretty huge (sometimes hundreds of MB) so out of memory errors appeared quickly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is fine for a strictly limited use case like mine, but my question is, how is VRAM handled in environments like games, where large numbers of meshes and textures need to be loaded and unloaded dynamically? I'm thinking particularly of open-world games like GTA where the world is constantly being streamed-in as the player moves around, but even in more linear games, loading a new level would need a lot of unloading and reloading assets.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are assets generally loaded to sections of large fixed buffers and space usage tracked somehow? Or if using a large number of smallish buffers, can the APIs keep up with a few of them being created and destroyed regularly?&#xA;Can anyone with experience in engine design shed some light on how this is done in real world usage?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-09-05T21:29:55.367" Title="Best practices for VRAM management in dynamic environments (e.g. games)" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5571" PostTypeId="1" AcceptedAnswerId="5575" CreationDate="2017-09-05T16:29:56.203" Score="7" ViewCount="6335" Body="&lt;p&gt;I've been going over some OpenGL learning resources and one of them is this article: &lt;a href=&quot;https://www.tomdalling.com/blog/modern-opengl/04-cameras-vectors-and-input/&quot; rel=&quot;noreferrer&quot;&gt;Modern OpenGL 04 - Cameras, Vectors &amp;amp; Input&lt;/a&gt; in which the author presents an approach to building a &lt;code&gt;Camera&lt;/code&gt; class that can be used to derive the view and projection matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the accompanying source code there is a function that returns the orientation of the camera as a transform matrix (&lt;a href=&quot;https://github.com/tomdalling/opengl-series/blob/2f1cb93a531f4f9bd5cbad5b2ac1ebe0cfcff7c7/source/04_camera/source/tdogl/Camera.cpp#L74-L79&quot; rel=&quot;noreferrer&quot;&gt;permalink to source code&lt;/a&gt;) which is implemented like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::mat4 Camera::orientation() const {&#xA;    glm::mat4 orientation;&#xA;    orientation = glm::rotate(orientation, glm::radians(_verticalAngle), glm::vec3(1,0,0));&#xA;    orientation = glm::rotate(orientation, glm::radians(_horizontalAngle), glm::vec3(0,1,0));&#xA;    return orientation;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I'd like to translate the camera relative to the direction it is facing then I would assume that I could multiply the orientation matrix by the translation vector to get a new vector that does the translation in the direction the camera is facing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this does not yield the result I was expecting. After looking at how the forward, up and right axis are derived (&lt;a href=&quot;https://github.com/tomdalling/opengl-series/blob/2f1cb93a531f4f9bd5cbad5b2ac1ebe0cfcff7c7/source/04_camera/source/tdogl/Camera.cpp#L104-L117&quot; rel=&quot;noreferrer&quot;&gt;permalink to source code&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 Camera::forward() const {&#xA;    glm::vec4 forward = glm::inverse(orientation()) * glm::vec4(0,0,-1,1);&#xA;    return glm::vec3(forward);&#xA;}&#xA;&#xA;glm::vec3 Camera::right() const {&#xA;    glm::vec4 right = glm::inverse(orientation()) * glm::vec4(1,0,0,1);&#xA;    return glm::vec3(right);&#xA;}&#xA;&#xA;glm::vec3 Camera::up() const {&#xA;    glm::vec4 up = glm::inverse(orientation()) * glm::vec4(0,1,0,1);&#xA;    return glm::vec3(up);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I can see that I need to multiply the translation vector with the inverse of the orientation matrix to get the expected result but I don't understand why. Isn't the orientation (as used in this article) a rotation matrix? If that's the case then why do I need to inverse it?&lt;/p&gt;&#xA;" OwnerUserId="7255" LastActivityDate="2020-01-28T18:07:51.260" Title="Why do I need to inverse the orientation matrix of a camera to be able to translate it in the direction it is facing?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;transformations&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5572" PostTypeId="2" ParentId="5570" CreationDate="2017-09-05T21:29:55.367" Score="2" Body="&lt;p&gt;For consoles (and D3D12/Metal/Vulkan), you know everything you need to know to develop an allocation strategy. You know:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;How much memory, of each kind, is available.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How big each kind of resource will be. Textures of a particular format and size take up X bytes, require Y alignment, etc.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Given such information, you can devise an allocation strategy for data uploading. Open-world games use streaming of fixed-sized blocks of data. Each sector of the game contains resources that take up X number of bytes, and therefore, artists have X number of bytes of storage to work with. It's their job to fit all of the stuff needed for that region of the game into that much space. There will also be stream blocks for larger collections of regions, or other data that gets shared between all game regions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For other games, some of them load everything at level-load time. Some do hard-loads in the middle of &quot;levels&quot; (see many Source-engine games). Others stream things more dynamically, but even there, artists are restricted to using resources that total up to X number of bytes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On consoles, such sizes can be known a priori, but with Vulkan/Metal/D3D12, these have to be queried for a particular piece of hardware. So in the latter case, you have to be more reactive to what's available, but all of the information is &lt;em&gt;available&lt;/em&gt; to the user.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For other APIs/platforms (OpenGL/D3D pre-12), things are rather more complicated. Consoles and the lower-level APIs give you direct access to memory allocations, which gives you more flexibility. You can use a piece of memory for vertex data at one point, then put an image into it later on. Memory is divorced from its current use, so it's much easier for an application to choose &lt;em&gt;how&lt;/em&gt; to recycle memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For GL/D3D-pre-12, things are difficult. A buffer object is a buffer object, and the memory currently associated with it cannot later be used as a texture. Well, it can, but you cannot explicitly ask that to be done. The most you can do is deallocate the buffer, allocate the image, and hope that the buffer's memory was recycled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For cases where you're doing dynamic loading in fixed-sized blocks, you basically have to give your artists more limitations. Instead of limiting the artists by memory, you have to spell out the limitations by &lt;em&gt;object&lt;/em&gt; So you'd say that a stream block can have &quot;X numbers of textures of Y formats and Z size, and W bytes of vertex data&quot;. Artists can't sacrifice 4 textures to allow one texture to be 4 times the size, or sacrifice a texture to get more vertex data, or sacrifice some vertex data to get more texture space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is what you have to do if you don't trust the implementation's memory allocator to effectively recycle resources. For hard-load cases, it's generally OK to just delete all of the objects and expect the implementation to recycle effectively. But even here, it's a good idea to make sure that you don't try to allocate &lt;em&gt;all&lt;/em&gt; of the available storage; leave the implementation a healthy percentage for fragmentation and so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, these kinds of things are a big part of the reason why IHVs have application-specific optimizations: they know up-front which resources were allocated for which purpose, and the driver makers can design allocation schemes that work with these assumptions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is why Vulkan et. al exist: so that application developers don't have to rely on IHVs to work around problems in the API.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-09-05T21:29:55.367" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5575" PostTypeId="2" ParentId="5571" CreationDate="2017-09-06T09:55:25.500" Score="6" Body="&lt;p&gt;People always forget that there is no &quot;camera&quot; in OpenGL. In order to simulate a camera you have to move the whole world inversely. So if you want ur camera looking 30 degrees downward, you move the whole world 30 degrees upwards. If you want your camera moved to the left, you move the whole world right. That's why you will notice the &lt;code&gt;&quot;-&quot;&lt;/code&gt; sign in the translation vector where he used the variable &lt;code&gt;position&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence the reason there is no separate &quot;view&quot; matrix in openGL, it's modelview matrix combined. That's the reason for taking the inverse. Since a view matrix represent's the camera's forward, up and side, you have to take the inverse since the orientation is defined for the world not the camera.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-09-06T09:55:25.500" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5576" PostTypeId="1" AcceptedAnswerId="5577" CreationDate="2017-09-06T12:17:30.847" Score="1" ViewCount="380" Body="&lt;p&gt;What's the algorithm for doing so?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have flat shading working and I have perspective correct texture mapping working.  Is the way your raster Gouraud shading much different from the perspective correct texture mapping?  (Is gouraud shading even supposed to be perspective correct?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is my understanding that you interpolate the lighting color/value down the edges, then interpolate across each scanline.  However,  I think I'm stuck on how to properly divide by Z for each pixel to get the correct light/color value for each pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any algorithm/article/tutorial would be of great help as I've searched everywhere but can only find high level, abstract descriptions of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="7261" LastActivityDate="2017-09-12T07:38:11.637" Title="How do you implement perspective correct Gouraud shading across a triangle?" Tags="&lt;lighting&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5577" PostTypeId="2" ParentId="5576" CreationDate="2017-09-06T13:21:14.370" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;(Is gouraud shading even supposed to be perspective correct?)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Originally, it wouldn't have been perspective correct, but on (hardware) systems these days it will be. FWIW Dreamcast had perspective correct Gouraud shading because, once you are doing perspective correct texturing, it is relatively little additional cost to do Gouraud &quot;correctly&quot;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I have flat shading working and I have perspective correct texture mapping working. Is the way your raster Gouraud shading much different from the perspective correct texture mapping?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm assuming that you've started with homogeneous 'world space' vertices, i.e. something like, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[x,y,z, 1, u,v, R,G,B]$,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;applied a projection matrix to get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[X_p, Y_p, Z_p, 1, u, v, R, G, B, w]$,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and then, after clipping, divided through by w to obtain screen coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[X_p/w, Y_p/w, Z_p/w, 1/w, u/w, v/w, R/w,... ]$.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For convenience, let's rename $u/w$ and $v/w$ as $u'$ &amp;amp; $v'$, $1/w$ as $w'$, $R/w$ as $R'$ etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do perspective correct texturing I &lt;em&gt;assume&lt;/em&gt; you are linearly interpolating, per pixel, the $u'$, $v'$, and $w'$ values, computing the reciprocal of the interpolated  $w'$ and multiplying that by $u'$ and $v'$ to obtain the per-pixel U &amp;amp; V coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do perspective correct Gouraud, simply use the same approach with the interpolated $R'$ , $G'$ and $B'$ values. The most expensive part is typically the division (i.e. reciprocal) but that can be shared with the texturing.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2017-09-12T07:38:11.637" LastActivityDate="2017-09-12T07:38:11.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5578" PostTypeId="1" AcceptedAnswerId="5579" CreationDate="2017-09-06T22:33:47.717" Score="1" ViewCount="257" Body="&lt;p&gt;I am very new to computer graphics, so I am sorry if this results in a stupid question. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For educational purposes I am looking through the pbrt code and I have noticed that before computing the direction for the next path for the subsequent bounce, they flip the direction of the incoming ray. Specifically:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    Vector3f wo = -ray.d, wi;&#xA;    Float pdf;&#xA;    BxDFType flags;&#xA;    Spectrum f = isect.bsdf-&amp;gt;Sample_f(wo, &amp;amp;wi, sampler.Get2D(), &amp;amp;pdf,&#xA;                                      BSDF_ALL, &amp;amp;flags);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now my rationale to justify that (also hinted by the name of the variable), is that we are tracing the rays from the camera, but really the phenomenon we are simulating is light coming from light into the camera, so even if the algorithm does:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;a) Eye --&gt; Object --&gt; Light &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What we are simulating is more like &lt;/p&gt;&#xA;&#xA;&lt;p&gt;b) Eye &amp;lt;-- Object &amp;lt;-- Light &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my assumption here is that the direction is flipped because of this reason. But if this is the case, should the resulting wi be flipped again before giving it to the next ray as direction? In the next bounce we'll find ourselves in the same process as in the option a) , but if we don't flip wi, don't we have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PrevObject &amp;lt;-- Object --&gt; Light  instead of &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PrevObject --&gt; Object --&gt; Light &lt;/p&gt;&#xA;&#xA;&lt;p&gt;? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is Sample_f returning an already flipped wi (i.e. ready for the next step)? Is my reasoning all wrong? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that I don't have the book yet, I am just trying to guess from code what's happening.&lt;/p&gt;&#xA;" OwnerUserId="7228" LastActivityDate="2017-09-07T13:10:37.660" Title="PBRT path tracing: negation of ray direction before next event estimation" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5579" PostTypeId="2" ParentId="5578" CreationDate="2017-09-07T09:52:40.797" Score="1" Body="&lt;p&gt;The incoming direction $\omega_o$ (coming from eye) is flipped in pbrt:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Another convention we will follow is that the incident light direction $\omega_i$ and the outgoing viewing direction $\omega_o$ will both be normalized and outward facing after being transformed into the local coordinate system at the surface. By convention, the surface normal always points to the &quot;outside&quot; of the object...&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aFn0D.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aFn0D.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="2941" LastEditDate="2017-09-07T13:10:37.660" LastActivityDate="2017-09-07T13:10:37.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5583" PostTypeId="1" CreationDate="2017-09-08T02:27:20.823" Score="5" ViewCount="346" Body="&lt;p&gt;Metal seems to provide two very different ways to access vertex data in your vertex shader. You can:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create an &lt;code&gt;MTLVertexDescriptor&lt;/code&gt; object, which describes vertex shader inputs, including per-vertex, per-instance, and constant data of basically any Metal-supported primitive type, and compile it into an &lt;code&gt;MTLRenderPipelineState&lt;/code&gt;. The inputs you describe map to indexed attributes in a single &lt;code&gt;struct&lt;/code&gt;, which you declare as the &lt;code&gt;[[stage_in]]&lt;/code&gt; argument of a vertex function.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;OR&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Use the &lt;code&gt;[[vertex_id]]&lt;/code&gt; and &lt;code&gt;[[instance_id]]&lt;/code&gt; inputs to a vertex function as indices into user-defined buffers of arbitrary data.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The first option is very reminiscent of a classical VBO-centric rendering pipeline, while the second option is a very compute-shader-like approach. Personally, I prefer the second approach, but I'm concerned as to whether it offers the same performance as the first.&lt;/p&gt;&#xA;" OwnerUserId="7238" LastActivityDate="2017-09-08T02:27:20.823" Title="In Metal, what performance advantages are there, if any, to using vertex descriptors and the [[stage_in]] qualifier?" Tags="&lt;shader&gt;&lt;performance&gt;&lt;vertex-buffer-object&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5584" PostTypeId="1" AcceptedAnswerId="5592" CreationDate="2017-09-08T05:19:44.253" Score="2" ViewCount="125" Body="&lt;p&gt;I am a little bit confused about the various flavors of material layering in both online and offline rendering.  I had naively assumed (after using the Mix Shader in Cycles and a few minutes in Substance Painter) that material layering was just a simple mask channel that blended between the final colors, sort of like texture splatting for terrain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But reading this question I see that the actual shader inputs are interpolated, rather than the final colors:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4157/material-layering&quot;&gt;Material Layering&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this the same process for offline renderers?  Reading the man page for RenderMan it seems like it is, as they specify only similar Bxdfs can be mixed:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://rmanwiki.pixar.com/display/REN/PxrLayerSurface&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://rmanwiki.pixar.com/display/REN/PxrLayerSurface&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any papers that describe the basics?  I found this from SIGGRAPH last month, but it confused the hell out of me:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://blog.selfshadow.com/publications/s2017-shading-course/drobot/s2017_pbs_multilayered.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.selfshadow.com/publications/s2017-shading-course/drobot/s2017_pbs_multilayered.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, are there any contexts in which material layering is simulation of multiple physical interfaces?  Or is that referred to something else, like nested dielectrics?&lt;/p&gt;&#xA;" OwnerDisplayName="user3412" LastActivityDate="2017-09-11T12:12:41.450" Title="Confused about material layering" Tags="&lt;material&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5585" PostTypeId="1" CreationDate="2017-09-08T21:11:22.137" Score="2" ViewCount="366" Body="&lt;p&gt;I am implementing light tracing from &lt;a href=&quot;http://rendering-memo.blogspot.co.uk/2016/03/bidirectional-path-tracing-6-implement.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this website&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The right wall on the below image is perfect mirror(specular reflection). Its BRDF returns zero that's why it's been rendered black. But how is it to correctly simulate this type of light path in light tracing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mKZLF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mKZLF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2017-09-08T21:11:22.137" Title="How to simulate specular reflection in Light Tracing?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;global-illumination&gt;&lt;specular&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5586" PostTypeId="1" AcceptedAnswerId="5587" CreationDate="2017-09-09T00:17:01.073" Score="6" ViewCount="1089" Body="&lt;p&gt;My graphics text explains rotating along the cardinal axes, then generalizes the math to show how to make a rotation matrix for rotating around an arbitrary vector. That all makes sense and I can both follow the math and picture the operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the text discusses scaling uniformly and in cardinal directions. Again I can follow everything. But then it goes through the math for &quot;scaling in an arbitrary direction&quot;, and although I can follow the vector operations I don't understand what scaling in a non cardinal direction even &lt;em&gt;means&lt;/em&gt;. I can start with an object rotated &quot;right side up&quot;, and then imagine it getting wider/taller/deeper, but I don't understand what it would mean to scale it in an arbitrary direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first thought was they must just mean scaling each cardinal direction by a different amount, but that can't be right because they don't end up with a diagonal matrix (take the identity matrix, change the first row 1 to 5 and the second row 1 to 3, and now you have a matrix that scales x by 5 and y by 3). Their 2D general scaling matrix is below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/U75St.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/U75St.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7272" LastActivityDate="2017-09-09T12:42:07.350" Title="What does it *mean* to scale in an arbitrary direction?" Tags="&lt;mathematics&gt;&lt;matrix&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5587" PostTypeId="2" ParentId="5586" CreationDate="2017-09-09T12:42:07.350" Score="7" Body="&lt;p&gt;When you scale along the X-axis, the X-coordinate (parallel to the axis) gets stretched, while the Y-coordinate (perpendicular to the axis) remains the same. You can think of scaling along an arbitrary axis as stretching along some diagonal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a pic of a square being scaled along the main diagonal (the axis pointing to &amp;lt;1, 1&gt; ) by factors of 2 and 0.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kUmir.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kUmir.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see that the distance along the axis (green line) gets scaled while the perpendicular distance (red line) stays the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematically, this is the same as rotating until your chosen axis lies along the X-axis, scaling by X, then rotating back again. &lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-09-09T12:42:07.350" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5588" PostTypeId="1" AcceptedAnswerId="5590" CreationDate="2017-09-11T07:31:00.197" Score="1" ViewCount="115" Body="&lt;p&gt;For an art project, I need to make an OpenGL visualization run for at least 4 weeks. Is this possible? I can pretty much choose the rest of the hardware and software.&lt;/p&gt;&#xA;" OwnerUserId="7250" LastActivityDate="2017-09-15T16:31:06.277" Title="How can an OpenGL visualization run for weeks?" Tags="&lt;opengl&gt;&lt;performance&gt;&lt;memory&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5589" PostTypeId="2" ParentId="5588" CreationDate="2017-09-11T07:53:16.377" Score="3" Body="&lt;p&gt;Yes, of course. The duration it has to run for doesn't make much difference. Your Android smartphone's main GUI is OpenGL, and phones typically have an uptime longer than four weeks. Air Traffic Control centres might use OpenGL SC (the subset of GL for safety-critical applications) continuously for months or years.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do have free choice of software, OpenGL is probably not the thing you're concerned about. Artists often use Processing for art projects, because it's simple and lets you get to drawing stuff on the screen with minimal 'boilerplate' code. It's very nice for drawing maths-as-art: particle systems, L-systems, strange attractors, &amp;amp;c. For a 3D scene that's supposed to look like the real world, Unity 3D might be a good choice: it's a game engine that handles all the use of OpenGL or DirectX for you, so you can create the scene you want to draw without much programming.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have more recommendation- or opinion-based questions about what might be useful to look at, maybe drop into our chat room and be ready to tell us what kind of art project you're making.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-09-11T07:53:16.377" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5590" PostTypeId="2" ParentId="5588" CreationDate="2017-09-11T09:15:59.833" Score="5" Body="&lt;p&gt;Opengl doesn't care how long it has been running. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However there are a few other challenges with long running applications in general:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;memory leaks, both normal ones and opengl resources. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;lack of precision after incrementing a float to a big number. After 4 weeks your millisecond counter will be at 2.4 billion which is well beyond the point where integers cannot be expressed exactly in a single precision floating point number. Make sure that those numbers are wrapped down to a smaller value explicitly.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-09-11T09:15:59.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5592" PostTypeId="2" ParentId="5584" CreationDate="2017-09-11T12:12:41.450" Score="1" Body="&lt;p&gt;There is no single method of layering materials. Some implementations, as you have observed, simply interpolate shader input parameters. This helps especially in contexts where code divergence comes with performance penalties (GPUs for example), since all material layers use the same code path and only have different data. Other blend between the output of the individual shader layers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More complex approaches take the interface between material layers into account, as well as layer thickness. A recent publication describing such a method is &lt;a href=&quot;http://www.cs.cornell.edu/projects/layered-sg14/&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;A Comprehensive Framework for Rendering Layered Materials&quot;&gt;&quot;A Comprehensive Framework for Rendering Layered Materials&quot;&lt;/a&gt; by Jakob et al.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-09-11T12:12:41.450" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5594" PostTypeId="1" CreationDate="2017-09-11T14:40:32.310" Score="2" ViewCount="84" Body="&lt;p&gt;I'm doing linear tweening of a cyllinder to a cone of equal radius and height in OpenGL. I know parametric equations of both of them, so I derived vertex normals accordingly. Now, I know, that proper interpolation of normals here should be quadratic, but, for some reason, linear looks better. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's call cyllinder $C(u,v) := (r\cos(u),\ v,\ r\sin(u))$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and the cone $K(u,v) := (\frac{r\cos(u)(h-v)}{h},\ v,\ \frac{r\sin(u)(h-v)}{h})$ where $u \in [0, 2\pi]$ and $v \in [0,h]$. $r, h$ are radius and height, respectively. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the moment $t \in [0,1]$, body has equation $T(u,v) := (1-t)C(u,v)+tK(u,v)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given that the normals are computed using partial derivative cross product formula, we get that normal to $T$ at $(u,v)$ is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(1-t)^2(C'_u\times C'_v)+t^2(K'_u \times K'_v)+t(1-t)M(u,v),$$ where $M(u,v) := C'_u \times K'_v+K'_u \times C'_v$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, apart from $M$, vertex normals to $T$ can be expressed as a quadratic inerpolation of corresponding normals for $C$ and $K$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Linear interpolation of normals does not work perfectly, but performs way better in general, because whenever I try and implement the correct interpolation formula, somewhere halfway through, all those polygons in the mesh become very apparent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the reference GL_NORMALIZE is on, but I store parametrically generated normals (so I can apply my formula for intermediary bodies).&lt;/p&gt;&#xA;" OwnerUserId="7282" LastActivityDate="2017-09-11T14:40:32.310" Title="Interpolating normals during animation" Tags="&lt;interpolation&gt;&lt;shading&gt;&lt;animation&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5595" PostTypeId="1" CreationDate="2017-09-11T16:09:09.940" Score="1" ViewCount="66" Body="&lt;p&gt;Say my animation scenario contains one mesh interpolating into another (possibly approximating over other meshes), using Bezier curves. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that for smooth surfaces, where normals can be expressed via cross product of partial derivatives, linear interpolation of vertices would induce quadratic interpolation of normals, involving some expressions with several cross product, not tied to the normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it acceptable in practice to do the same interpolation for corresponding vertex normals (linear-linear, quadratic-quadratic and so on)?&lt;/p&gt;&#xA;" OwnerUserId="7282" LastActivityDate="2017-09-11T16:09:09.940" Title="General interpolation practices" Tags="&lt;interpolation&gt;&lt;shading&gt;&lt;animation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5596" PostTypeId="1" CreationDate="2017-09-11T20:05:51.987" Score="1" ViewCount="48" Body="&lt;p&gt;I have just two local axis to rotate a 3D object: X (horizontal) and Y (vertical). How to make from this 2 local axises for example a global Y rotation or a Local Z rotation? What math magic do the trick? &lt;/p&gt;&#xA;" OwnerUserId="7285" LastActivityDate="2017-09-11T22:48:32.167" Title="How to rotate an object around any axis if i have just local x and y?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5598" PostTypeId="2" ParentId="5596" CreationDate="2017-09-11T21:24:46.673" Score="1" Body="&lt;p&gt;If you know how to make a rotation matrix from X,Y,Z basis vectors (just make them the rows or columns, depending on whether you are using a row or column major matrix), you can do that, using the cross product of X and Y to get the Z vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The order of X and Y in the cross product depend on whether you are using a left or right handed coordinate system, but if you are unsure about this, you can check if doing Z=cross(X,Y) looks right and if not, switch to Z=cross(Y,X).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, it'll be something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// May be Y,X instead, depending on your handedness&#xA;Z = Cross(X,Y);&#xA;&#xA;// May need to be transposed based on you using row or column major matrices&#xA;RotationMatrix = MatrixFromRows(X,Y,Z); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-09-11T22:48:32.167" LastActivityDate="2017-09-11T22:48:32.167" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5599" PostTypeId="1" AcceptedAnswerId="5659" CreationDate="2017-09-12T12:15:23.683" Score="0" ViewCount="703" Body="&lt;p&gt;I've been trying to build a simple DirectX renderer from the ground up (was an OpenGL guy before but i figure it's good to know different APIs). I've been following the guide at rastertek.com to learn how to get the basics up and running.&lt;/p&gt;&#xA;&lt;p&gt;I got as far as &lt;a href=&quot;http://www.rastertek.com/dx11s2tut03.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this lesson&lt;/a&gt;, following the guide verbatim except for variable names, and ran into a really weird bug. The renderer class contains 3 XMMatrix instances, world, perspective and orthographic, but trying to initialize them would crash my application - it ran fine once i commented out these lines :&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;m_projMat = XMMatrixPerspectiveFovLH(fov, aspect, nearplane, farplane);&#xA;m_orthoMat = XMMatrixOrthographicLH(width, height, nearplane, farplane);&#xA;m_worldMat = XMMatrixIdentity();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;At first i thought it was the dreaded SIMD alignment issue, but I'm compiling 64-bit so that should be taken care of. After a bit more tinkering i found out the ortho and world matrices were fine, it was just the projection matrix that was causing problems. Assigning to this matrix with the other XMMatrix... functions also works ok.&#xA;So:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;m_projMat = XMMatrixPerspectiveFovLH(fov, aspect, nearplane, farplane); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;fails, but:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;m_projMat = XMMatrixPerspectiveLH(fov*aspect*nearplane, fov*nearplane, nearplane, farplane); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;works! The right-handed version also fails. Also, the failure only happens in release mode, not in debug. I'm using Visual Studio 2015 community and the SDKs that installed with it.&lt;/p&gt;&#xA;&lt;p&gt;Has anyone else encountered this bug, or have any idea what's going on here?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-10-01T18:33:39.773" Title="XMMatrixPerspectiveFovLH is broken?" Tags="&lt;directx11&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5600" PostTypeId="1" CreationDate="2017-09-12T20:13:54.217" Score="1" ViewCount="118" Body="&lt;p&gt;I'm trying to understand basis vectors and the plane equation and I am confused. From what I saw, if we take a basis vector i, j, k, each variable point to the axe (x, y, z). Are i,j,k scalars or vectors? It seems that any vector can be seen as i&lt;em&gt;x, j&lt;/em&gt;y, k*z. Does that mean that changing the values of i,j,k can &quot;rotate&quot; the whole plane (the world)? Does this has any connection with the plane equation? Maybe that I am mixing things up.&lt;/p&gt;&#xA;" OwnerUserId="7291" LastActivityDate="2017-09-12T20:13:54.217" Title="Basis vectors and plane equation" Tags="&lt;vectors&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5602" PostTypeId="1" AcceptedAnswerId="5628" CreationDate="2017-09-13T09:41:48.410" Score="2" ViewCount="1773" Body="&lt;p&gt;I Recently posted this question on SO but didn't got any response so i thought to post it here since it's somewhat related to Raytracing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am making a real time ray tracer in OpenGL using Compute Shaders for my project and was following this &lt;a href=&quot;https://github.com/LWJGL/lwjgl3-wiki/wiki/2.6.1.-Ray-tracing-with-OpenGL-Compute-Shaders-(Part-I)&quot; rel=&quot;nofollow noreferrer&quot;&gt;link&lt;/a&gt; as a reference. The link tells to first draw a full screen quad, then store all the individual pixel colors gotten through intersections in a texture and render the texture to the quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However i was thinking can't we use Frame Buffer Objects to display the texture image instead of rendering the quad and save the over head?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Like I save all the colors using &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/imageStore.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;ImageStore&lt;/a&gt; and &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindImageTexture.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;GlBindImageTexture&lt;/a&gt; in a texture, then attach it to a FBO to display it. And since I won't be using any rendering commands I won't be causing a Feedback loop as in writing and reading the same texture?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the snippet&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  void initialization() {&#xA;  int tex = create new texture object&#xA;&#xA;  setup min/mag NEAR filtering for that texture&#xA;  initialize texture as 2D rgba32f FLOAT and some width/height&#xA;&#xA;  int vao = create VertexArrayObject of full-screen-quad&#xA;  // This quad is used to render our&#xA;  // &quot;framebuffer&quot; texture onto the screen.&#xA;&#xA;  int computeProgram = create-and-link program with single compute shader object&#xA;&#xA;  int quadProgram = create-and-link simple full-screen quad vertex and fragment shader&#xA;  // The fragment shader would fetch&#xA;  // texels from our &quot;tex&quot; texture.&#xA;&#xA;  Setup constant uniforms in quad program, such as &quot;tex&quot; texture unit = 0&#xA;}&#xA;&#xA;&#xA;&#xA; The rendering process to produce one frame will be as follows:&#xA;&#xA;Bind the Compute Shader&#xA;Setup camera properties in compute shader uniforms&#xA;Bind level 0 of framebuffer texture to image binding point 0&#xA;Start/dispatch the compute shader to generate a frame in the framebuffer image&#xA;Unbind image binding point&#xA;Bind the written framebuffer texture in OpenGL to texture unit 0&#xA;Bind the full-screen shader program&#xA;Bind the full-screen-quad VAO&#xA;Draw the VAO&#xA;Release all bindings&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-09-17T09:12:04.343" Title="Raytracing in OpenGL using Compute Shaders" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;compute-shader&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5604" PostTypeId="1" CreationDate="2017-09-13T12:50:23.057" Score="0" ViewCount="268" Body="&lt;p&gt;I'm using VBO to upload vertex array, colors and then texture coordinates! I did implement mouse pick with color coding technique. It works fine but when I render texture after ReadPixels, it returns wrong color!&#xA;I don't know why this happens! Here is my render code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);&#xA;        GL.ShadeModel(ShadingModel.Flat);&#xA;        Debug.Assert(_vbo.VertexBufferId != 0);&#xA;        Debug.Assert(_vbo.ElementBufferId != 0);&#xA;&#xA;        // vertex colors&#xA;        if (_vbo.ColorBufferId != 0)&#xA;        {&#xA;            GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.ColorBufferId);&#xA;            GL.ColorPointer(4, ColorPointerType.UnsignedByte, sizeof(int), IntPtr.Zero);&#xA;            GL.EnableClientState(ArrayCap.ColorArray);&#xA;        }&#xA;&#xA;        // vertex position&#xA;        GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.VertexBufferId);&#xA;        GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);&#xA;        GL.EnableClientState(ArrayCap.VertexArray);&#xA;&#xA;        // primitives&#xA;        GL.BindBuffer(BufferTarget.ElementArrayBuffer, _vbo.ElementBufferId);&#xA;        GL.DrawElements(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, _vbo.NumIndices * 3, _vbo.Is32BitIndices ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort, IntPtr.Zero);&#xA;&#xA;        // Read pixel under mouse cursor&#xA;        _selectedPolyIndex = uint.MaxValue;&#xA;        Byte4 Pixel = new Byte4();&#xA;        GL.ReadPixels(mouse_x, height - mouse_y, 1, 1, PixelFormat.Rgba, PixelType.UnsignedByte, ref Pixel);&#xA;        _selectedPolyIndex = Pixel.ToUInt();&#xA;&#xA;        // Restore the state&#xA;        GL.PopClientAttrib();&#xA;&#xA;        GL.PushClientAttrib(ClientAttribMask.ClientVertexArrayBit);&#xA;&#xA;        // normals&#xA;        if (flags.HasFlag(RenderFlags.Shaded))&#xA;        {&#xA;            if (_vbo.NormalBufferId != 0)&#xA;            {&#xA;                GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.NormalBufferId);&#xA;                GL.NormalPointer(NormalPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);&#xA;                GL.EnableClientState(ArrayCap.NormalArray);&#xA;            }&#xA;        }&#xA;&#xA;        // UV coordinates&#xA;        if (flags.HasFlag(RenderFlags.Textured))&#xA;        {&#xA;            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); // this line must move out to line 160&#xA;            if (_vbo.TexCoordBufferId != 0)&#xA;            {&#xA;                GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.TexCoordBufferId);&#xA;                GL.TexCoordPointer(2, TexCoordPointerType.Float, 8, IntPtr.Zero);&#xA;                GL.EnableClientState(ArrayCap.TextureCoordArray);&#xA;            }&#xA;        }&#xA;&#xA;&#xA;        // vertex position&#xA;        GL.BindBuffer(BufferTarget.ArrayBuffer, _vbo.VertexBufferId);&#xA;        GL.VertexPointer(3, VertexPointerType.Float, Vector3.SizeInBytes, IntPtr.Zero);&#xA;        GL.EnableClientState(ArrayCap.VertexArray);&#xA;&#xA;&#xA;        // primitives&#xA;        GL.BindBuffer(BufferTarget.ElementArrayBuffer, _vbo.ElementBufferId);&#xA;        GL.DrawElements(OpenTK.Graphics.OpenGL.PrimitiveType.Triangles, _vbo.NumIndices * 3, _vbo.Is32BitIndices ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort, IntPtr.Zero);&#xA;&#xA;        // Restore the state&#xA;        GL.PopClientAttrib();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When texture rendering is enabled OpenGL reads wrong pixel color under mouse cursor (I want vertex color but it reads texture color), even I call readpixels before texture rendering!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I fix this problem?&lt;/p&gt;&#xA;" OwnerUserId="7298" LastEditorUserId="67" LastEditDate="2017-09-14T07:08:00.400" LastActivityDate="2017-09-17T09:46:18.060" Title="How to read vertex color before rendering texture?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5605" PostTypeId="1" CreationDate="2017-09-13T17:04:05.110" Score="2" ViewCount="105" Body="&lt;p&gt;I'm trying to implement a segmentation model which will divide a 3d mesh model into charts. But I'm having really hard time to find resources in the web. The papers and some other places these approaches discussed either in very brief or with very complicated math. Really need some step by step guide with example for the algorithm. I'm particularly interested on the approach given in this &lt;a href=&quot;http://www.cs.jhu.edu/~misha/Fall09/Levy02.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;LSCM&lt;/a&gt; paper. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is another algorithm discussed in &lt;a href=&quot;http://the-witness.net/news/2010/03/graphics-tech-texture-parameterization/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; and the code for this can be found in this &lt;a href=&quot;https://github.com/Thekla/thekla_atlas&quot; rel=&quot;nofollow noreferrer&quot;&gt;repo&lt;/a&gt;. This also looks very promising.&lt;/p&gt;&#xA;" OwnerUserId="7299" LastEditorUserId="7299" LastEditDate="2017-09-14T13:37:59.393" LastActivityDate="2017-09-14T13:37:59.393" Title="Algorithm for 3D mesh model segmentation to chart" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5606" PostTypeId="1" CreationDate="2017-09-13T17:17:43.010" Score="3" ViewCount="2162" Body="&lt;p&gt;Does anyone know how to do run an OpenGL animation and then convert it into a mp4 movie?  I've been trying with apitrace and ffmpeg but I get horrible quality output...&lt;/p&gt;&#xA;" OwnerUserId="6025" LastActivityDate="2017-09-16T16:24:07.580" Title="OpenGL animation - turn into mp4 movie" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5607" PostTypeId="2" ParentId="5489" CreationDate="2017-09-13T17:56:57.697" Score="-1" Body="&lt;p&gt;While I have no idea how UnrealEngine handle depth I have thought of a technique which would result in that kind of depth output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is to better manage Z-fighting by rendering multiple (stacked) frustums with shorter distance between ner and far planes. Each step in the cascade would represent one of those frustums. Using near/far plane clipping, stencil masking and optional vf-culling you can easily render the cascade front-to-back, or each frustum to each own framebuffer and consolidate afterwards, with only minor hit in performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This should scale better than increasing depth buffer bit depth which has diminishing returns. Besides not all platforms support high bit depth. OpenGL ES require only 16 bits!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is just a theory though :-)&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2017-09-13T17:56:57.697" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5608" PostTypeId="2" ParentId="5301" CreationDate="2017-09-13T18:55:24.660" Score="1" Body="&lt;p&gt;When cylinder and frustum intersect the hole will be a view into the internals of the cylinder. &lt;strong&gt;The hole is where external of the cylinder occlude frustum and internal of the cylinder does not occlude the frustum.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Knowing this you should simply do the following to find the surface (or rather volume) made from the hole.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Render frustum without color and set depth accordingly. Set a stencil bit where the cylinder (external) occludes the frustum, without setting new depth. Clear the previously set bit where the internal of the cylinder occludes the frustum, without setting new depth. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternate between internal and external using CullFace.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stencil mask you now have is the surface where the frustum hole is. Render the frustum (in color) masking it with the stencil. Make sure to use LEQUALS depth test to allow the frustum to render on top of itself. Voila. Note that the depth buffer holds the value of the unmasked frustum so If you need to render something within the hole you would have to render the whole scene again and mask it to only render in the hole unless depth test passes against the frustum. Left as student exercise.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2017-09-13T18:55:24.660" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5609" PostTypeId="2" ParentId="4632" CreationDate="2017-09-13T19:09:44.583" Score="0" Body="&lt;p&gt;Include a benchmarking phase for of both solutions in your application and then select the winning solution at runtime. This is simple, portable, and future proof. I mean, you do have test for this, right? ;-)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know this is a pretty generic answer to &quot;best practice&quot; for high performance but if you think of it there are thousands of possible target configurations and many vendors to consider. If you need that little extra, go pay your vendor for a driver optimized for your application.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2017-09-13T19:09:44.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5610" PostTypeId="2" ParentId="95" CreationDate="2017-09-13T19:23:35.453" Score="0" Body="&lt;p&gt;Depending on your renderer you could make the surfaces more &quot;fuzzy&quot; applying a miniscule offset in multisampling depth using a noise like algorithm. This should result in a sort of blending effect for surfaces in close depth proximity. For what I know setting per-sample depth in fragment shader is quite recent in OpenGL and then only as an extension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL has the PolygonOffset but requires knowing in advance you are about to render something coplanar. While not feasible for surfaces within a single model it could work nicely for example when rendering a road overlaid on a piece of land.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2017-09-13T19:23:35.453" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5611" PostTypeId="1" AcceptedAnswerId="5612" CreationDate="2017-09-13T23:28:33.280" Score="8" ViewCount="1644" Body="&lt;p&gt;I've heard that pre-multiplied alpha gives you order independent transparency but when I sit down and do the math, it doesn't seem to be working.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is that untrue, or am I doing something incorrectly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula I'm using is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$out_{rgba} = in_{rgba} + out_{rgba} * (1 - in_a)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $in$ is premultiplied alpha. In other words, taking a &quot;normal&quot; color in RGBA, i multiply RGB by a.  30% opaque white would start out as (1, 1, 1, 0.3) but would become (0.3, 0.3, 0.3, 0.3) as premultiplied alpha.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After getting the wrong answers when working it out by hand, I wrote the C++ program below and am still getting the wrong results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After execution:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$out1 = (0.738, 0.913, 0.3, 1.0)\\&#xA;out2 = (0.738, 0.875, 0.113, 1.0)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain why?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;array&amp;gt;&#xA;&#xA;typedef std::array&amp;lt;float, 4&amp;gt; RGBA;&#xA;&#xA;void PremultiplyAlpha (RGBA&amp;amp; rgba)&#xA;{&#xA;    rgba[0] *= rgba[3];&#xA;    rgba[1] *= rgba[3];&#xA;    rgba[2] *= rgba[3];&#xA;}&#xA;&#xA;RGBA BlendPremultipliedAlpha (const RGBA&amp;amp; dest, const RGBA&amp;amp; src)&#xA;{&#xA;    RGBA ret;&#xA;    ret[0] = src[0] + dest[0] * (1.0f - src[3]);&#xA;    ret[1] = src[1] + dest[1] * (1.0f - src[3]);&#xA;    ret[2] = src[2] + dest[2] * (1.0f - src[3]);&#xA;    ret[3] = src[3] + dest[3] * (1.0f - src[3]);&#xA;    return ret;&#xA;}&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    RGBA greenGround = { 0.0f, 1.0f, 0.0f, 1.0f };&#xA;    PremultiplyAlpha(greenGround);&#xA;&#xA;    RGBA red25PercentOpaque = { 1.0f, 0.0f, 0.0f, 0.25f };&#xA;    PremultiplyAlpha(red25PercentOpaque);&#xA;&#xA;    RGBA white30PercentOpaque = { 1.0f, 1.0f, 1.0f, 0.3f };&#xA;    PremultiplyAlpha(white30PercentOpaque);&#xA;&#xA;    RGBA yellow50PercentOpaque = { 1.0f, 1.0f, 0.0f, 0.5f };&#xA;    PremultiplyAlpha(yellow50PercentOpaque);&#xA;&#xA;    // one way&#xA;    RGBA out1;&#xA;    {&#xA;        // start with the green ground and blend in 25% opaque red&#xA;        out1 = greenGround;&#xA;        out1 = BlendPremultipliedAlpha(out1, red25PercentOpaque);&#xA;&#xA;        // then blend in 50% yellow&#xA;        out1 = BlendPremultipliedAlpha(out1, yellow50PercentOpaque);&#xA;&#xA;        // then blend in 30% opaque white&#xA;        out1 = BlendPremultipliedAlpha(out1, white30PercentOpaque);&#xA;    }&#xA;&#xA;    // other way&#xA;    RGBA out2;&#xA;    {&#xA;        // start with the green ground and blend in 30% opaque white&#xA;        out2 = greenGround;&#xA;        out2 = BlendPremultipliedAlpha(out2, white30PercentOpaque);&#xA;&#xA;        // then blend in 25% red&#xA;        out2 = BlendPremultipliedAlpha(out2, red25PercentOpaque);&#xA;&#xA;        // then blend in 50% yellow&#xA;        out2 = BlendPremultipliedAlpha(out2, yellow50PercentOpaque);&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="56" LastActivityDate="2018-07-18T11:04:21.220" Title="Does premultiplied alpha give order independent transparency?" Tags="&lt;mathematics&gt;&lt;transparency&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5612" PostTypeId="2" ParentId="5611" CreationDate="2017-09-14T04:14:54.510" Score="9" Body="&lt;p&gt;Premultiplied alpha itself does not give you order independent transparency, no.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This page talks about how it can be used as part of an order independent transparency solution however: &lt;a href=&quot;http://casual-effects.blogspot.com/2015/03/implemented-weighted-blended-order.html&quot; rel=&quot;noreferrer&quot;&gt;http://casual-effects.blogspot.com/2015/03/implemented-weighted-blended-order.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other benefits of premultiplied alpha include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;better mipmaps for textures that contain alpha: &lt;a href=&quot;https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre&quot; rel=&quot;noreferrer&quot;&gt;https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Being able to do both transparency and additive blending within a single texture without needing to change render states or issue multiple draw calls: &lt;a href=&quot;http://amindforeverprogramming.blogspot.com/2013/07/why-alpha-premultiplied-colour-blending.html&quot; rel=&quot;noreferrer&quot;&gt;http://amindforeverprogramming.blogspot.com/2013/07/why-alpha-premultiplied-colour-blending.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Being able to represent more realistic lighting situations, such as the fact that being non opaque doesn't always mean transparency: &lt;a href=&quot;http://distantsoulsdev.blogspot.com.ar/2013/02/premultiplied-alpha-online-interactive.html&quot; rel=&quot;noreferrer&quot;&gt;http://distantsoulsdev.blogspot.com.ar/2013/02/premultiplied-alpha-online-interactive.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Being able to more naturally / correctly / effortlessly composite images that have alpha channels.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Being able to get better results from image processing (blurs / convolution). No black halo: &lt;a href=&quot;https://stackoverflow.com/questions/4854839/how-to-use-pre-multiplied-during-image-convolution-to-solve-alpha-bleed-problem&quot;&gt;https://stackoverflow.com/questions/4854839/how-to-use-pre-multiplied-during-image-convolution-to-solve-alpha-bleed-problem&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Premultiplied alpha also allows transparent objects to be drawn front to back instead of back to front, possibly saving pixel writes.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-09-14T04:30:18.637" LastActivityDate="2017-09-14T04:30:18.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5613" PostTypeId="2" ParentId="5611" CreationDate="2017-09-14T08:06:29.790" Score="4" Body="&lt;p&gt;Alan, &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.163.5748&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jim Blinn's compositing article&lt;/a&gt; also explains why premultiplied is the correct way to do any filtering of transparent images.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-09-14T08:06:29.790" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5615" PostTypeId="2" ParentId="5489" CreationDate="2017-09-14T14:39:43.210" Score="1" Body="&lt;p&gt;This is just a visualisation. Type the command vis scenedepthz uv0 to see the actual depth buffer used. UE4 uses a &quot;reversed&quot; depth buffer for the scene.&lt;/p&gt;&#xA;" OwnerUserId="3331" LastActivityDate="2017-09-14T14:39:43.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5618" PostTypeId="1" AcceptedAnswerId="5619" CreationDate="2017-09-15T01:49:17.137" Score="5" ViewCount="345" Body="&lt;p&gt;If you have a bunch of particles to render, using different shaders and/or render states, that have some level of transparency, the naive solution of sorting all particles by depth can be extremely inefficient since it is likely to turn a few large batch draw calls into a multitude of smaller batch calls which have expensive render state switches between those draw calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know of a few ways to help fake things such as sorting particle batches by their emitter location, or using something like additive blending, which gives the same result regardless of draw order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also know there are some techniques out there to attempt order independent transparency, often being an approximation, requiring a (sometimes unbounded) amount of memory, or some combination thereof.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know any pragmatic solutions (fast/low extra memory requirements/absolute correctness not required) for dealing with this situation?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-09-15T16:15:02.437" Title="Are there tricks for getting proper sort ordering on particle systems?" Tags="&lt;transparency&gt;&lt;particles&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5619" PostTypeId="2" ParentId="5618" CreationDate="2017-09-15T08:44:17.403" Score="4" Body="&lt;p&gt;First option should be to make all particles able to go through the same pipeline. Perhaps with an uber shader. That way you can batch them all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Positive ieee floating point numbers can be sorted like unsigned integer. And there are O(n) algorithms to sort those for example radix sort. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-09-15T08:44:17.403" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5621" PostTypeId="2" ParentId="5618" CreationDate="2017-09-15T16:15:02.437" Score="1" Body="&lt;p&gt;Sort the particles by Z each rendering cycle using an algorithm such as bubble sort which is good when element changes position in small steps. If the perspective does not change much the errors would be few enough over time to be unnoticable. The technique is easy to configure between quality and performance dependning on the target platform by adjusting how much sorting is performed each cycle.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2017-09-15T16:15:02.437" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5622" PostTypeId="2" ParentId="5588" CreationDate="2017-09-15T16:31:06.277" Score="2" Body="&lt;p&gt;To make an application, OpenGL or not, run for extended time safety-critical applications are mostly built to restart on error, be it a driver bug, your application is broken, or hardware failure. If function during the downtime is required you need redundnacy. In your case maybe start multiple sessions of the same program, or even having dual computers running the same program outputing to the same display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL is no different from other applications, BUT vendors optimize and test for certain kinds of customers. Your scenario is not common so be suspicious.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2017-09-15T16:31:06.277" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5623" PostTypeId="2" ParentId="5606" CreationDate="2017-09-16T08:01:01.007" Score="0" Body="&lt;p&gt;That is not an easy question to answer. First of all you will have to understand the MP4 format. And secondly you will have to keep track of every frame being displayed by OpenGL. So my suggestion to maximize performance is to keep all of the frame data after every frame in a file on the hard drive and after the animation read all of the files and write to an MP4 file.&lt;/p&gt;&#xA;" OwnerUserId="7318" LastActivityDate="2017-09-16T08:01:01.007" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5625" PostTypeId="1" CreationDate="2017-09-16T13:20:47.860" Score="7" ViewCount="246" Body="&lt;p&gt;In my CS class in high school I'm doing a presentation on Computer Graphics and I wanted to talk about Ray Tracing. I was wondering what would be the easiest way to do this without confusing my audience?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are some of your personal favorite analogies and explanations that have worked effectively to people who have never touched the field?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please don't mistake this as a 'do my homework' type question. I'm just curious to see what has worked and what hasn't. &lt;/p&gt;&#xA;" OwnerUserId="5256" LastActivityDate="2017-11-14T18:39:12.280" Title="An Effective way to explain Ray Tracing?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5626" PostTypeId="2" ParentId="5538" CreationDate="2017-09-16T14:50:51.570" Score="0" Body="&lt;p&gt;OK. This is the &lt;a href=&quot;https://ru.stackoverflow.com/a/717999/236980&quot;&gt;answer&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function getParallelProjection(arr) {&#xA;    var i, j, k;&#xA;&#xA;    var projected = [];&#xA;    var projection;&#xA;&#xA;    for (i = 0; i &amp;lt; 6; i++) {&#xA;        projection = [];&#xA;        if (arr[i].length &amp;lt; 6) {&#xA;            for (j = 0; j &amp;lt; 4; j++) {&#xA;                projection[j] = getPointParallelProjection(arr[i][j]);&#xA;            }&#xA;        }&#xA;        projected[i] = projection;&#xA;    }&#xA;&#xA;    return projected.filter(isClockwise);&#xA;}&#xA;&#xA;function isClockwise(point_array) {&#xA;    if (point_array.length &amp;lt; 3) return false;&#xA;    var p0 = point_array[0];&#xA;    var p1 = point_array[1];&#xA;    var p2 = point_array[2];&#xA;    return (p1.x-p0.x)*(p2.y-p0.y) - (p2.x-p0.x)*(p1.y-p0.y) &amp;gt; 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;All the magic that we check how the faces are drawn. After the vector product we check the order in wich projected vertices goes. If it is counterclockwise - so this set of vertices is discarded.&lt;/p&gt;&#xA;" OwnerDisplayName="user7220" LastActivityDate="2017-09-16T14:50:51.570" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5627" PostTypeId="2" ParentId="5606" CreationDate="2017-09-16T16:24:07.580" Score="3" Body="&lt;p&gt;It's not too difficult to set up your app to stream frames directly to ffmpeg. &lt;a href=&quot;http://blog.mmacklin.com/2013/06/11/real-time-video-capture-with-ffmpeg/&quot; rel=&quot;nofollow noreferrer&quot;&gt;This blog post by Miles Macklin shows how&lt;/a&gt;, and I've used this method in my own apps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You spawn ffmpeg as a child process from your app, and at the end of each frame you just read back the GL framebuffer and write its contents to ffmpeg's stdin. The relevant code bits are excerpted here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Initializing ffmpeg:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// start ffmpeg telling it to expect raw rgba 720p-60hz frames&#xA;// -i - tells it to read frames from stdin&#xA;const char* cmd = &quot;ffmpeg -r 60 -f rawvideo -pix_fmt rgba -s 1280x720 -i - &quot;&#xA;                  &quot;-threads 0 -preset fast -y -pix_fmt yuv420p -crf 21 -vf vflip output.mp4&quot;;&#xA;&#xA;// open pipe to ffmpeg's stdin in binary write mode&#xA;FILE* ffmpeg = _popen(cmd, &quot;wb&quot;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Writing a frame:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);&#xA;fwrite(buffer, sizeof(int)*width*height, 1, ffmpeg);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can adjust the quality by altering the &lt;code&gt;-crf&lt;/code&gt; option in the command line (lower numbers are better quality). Don't forget to change the resolution (&lt;code&gt;-s&lt;/code&gt;) and framerate (&lt;code&gt;-r&lt;/code&gt;) to match what you want, as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on the quality, how fast your PC is, etc, it might not quite work in real-time. It's a good idea to set up your app to use a fixed per-frame timestep when you're in video capture mode, so the resulting animation doesn't depend on how much slowdown there was in the capture process.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-09-16T16:24:07.580" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5628" PostTypeId="2" ParentId="5602" CreationDate="2017-09-16T16:32:48.923" Score="2" Body="&lt;p&gt;So i searched a lot after this and I think it was my confusion on FrameBuffer Objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought you could use FBO's just like a default FrameBuffer and display the texture image attached to it but you can't. It's only used for offscreen rendering. So while you can use rendering commands to draw something to a &quot;texture image&quot; attached to it, you can't &quot;display the image&quot; by making it default framebuffer or something like that.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-09-16T16:32:48.923" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5629" PostTypeId="2" ParentId="5602" CreationDate="2017-09-17T09:12:04.343" Score="1" Body="&lt;p&gt;The overhead on this is pretty miniscule anyway. Modern GPU raster and texture rates are on the order of tens of gigapixels per second. Compared to the cost of running a ray tracer, it's a rounding error.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-09-17T09:12:04.343" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5630" PostTypeId="2" ParentId="5604" CreationDate="2017-09-17T09:46:18.060" Score="1" Body="&lt;p&gt;For this kind of functionality, you shouldn't try to use the same framebuffer for the vertex colours and for the final image. Don't forget that GL is &lt;em&gt;asynchronous&lt;/em&gt;, so alternating CPU reads and GPU writes to the same framebuffer seriously limit your achievable performance and make it much harder for you to get the concurrency right. (The &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Synchronization&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL wiki&lt;/a&gt; has more about synchronization.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, you should create an FBO that you only use for your vertex colours render. Draw the vertex colours into that and use it for mouse picking. Only use the 'real' framebuffer (the one that gets drawn) for the final image.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-09-17T09:46:18.060" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5632" PostTypeId="1" CreationDate="2017-09-19T08:14:25.393" Score="0" ViewCount="95" Body="&lt;p&gt;Thanks! A very simple but great way to estimate mean curvatures@NathanReed answer.&#xA;For my case, I also need an estimate of triangular mesh curvature, and I support this is what i was looking for.&#xA;However, could you please show me (or any recommended literature) how is the following equation derived?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac{(n_1 - n_0).(p_1 - p_0)}{||p_1 - p_0||^2}$$&lt;/p&gt;&#xA;" OwnerUserId="7335" LastEditorUserId="182" LastEditDate="2017-09-19T08:37:04.470" LastActivityDate="2017-09-19T08:37:04.470" Title="How to derive the formula@NathanReed answer" Tags="&lt;mathematics&gt;" AnswerCount="0" CommentCount="3" ClosedDate="2017-09-21T23:47:06.113" ContentLicense="CC BY-SA 3.0" />
  <row Id="5633" PostTypeId="2" ParentId="2076" CreationDate="2017-09-19T10:06:04.793" Score="6" Body="&lt;p&gt;For an nVidia only solution you can use floating point atomic add intrinsics (like NvInterlockedAddFp32) &lt;a href=&quot;https://developer.nvidia.com/unlocking-gpu-intrinsics-hlsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unlocking GPU Intrinsics in HLSL | NVIDIA Developer&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried this on 80.000 vertex mesh and it's quite fast (something like 1 or 2 ms on a GTX980M, if I remember correctly)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just beware of compiling your shaders in release for the intrinsics to work (due to nvidia bug/limitation)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also beware of vertex splits (due to UV discontinuities for example), you'll have to handle them or else you'll have unwanted hard edges at UV seams.&lt;/p&gt;&#xA;" OwnerUserId="7337" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T08:54:24.783" LastActivityDate="2018-03-06T08:54:24.783" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5634" PostTypeId="2" ParentId="3742" CreationDate="2017-09-19T10:59:45.120" Score="1" Body="&lt;p&gt;I think the solution is looking for the projective transform that correctly transforms the four points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;i.e. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$y' = P \times x'$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $x' = [x_0, x_1, 1]$ and $y = [\frac{y'_0}{y'_2}, \frac{y'_1}{y'_2}]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$P$ is a 3x3 matrix with 9 entries. Due to the final normalization it is unique up to scaling, leaving 8 degrees of freedom, which are uniquely determined by the 8 equations given by the correspondence (2 per point pair).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can use algebra to do this, or just use OpenCV's &lt;code&gt;getPerspectiveTransform&lt;/code&gt; :).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also check out &lt;a href=&quot;https://en.wikipedia.org/wiki/Homogeneous_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;homnogenous coordinates&lt;/a&gt; on wikipedia to get familiar with the concept.&lt;/p&gt;&#xA;" OwnerUserId="7338" LastEditorUserId="182" LastEditDate="2017-09-20T12:18:11.700" LastActivityDate="2017-09-20T12:18:11.700" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5636" PostTypeId="2" ParentId="3742" CreationDate="2017-09-20T11:40:12.210" Score="0" Body="&lt;p&gt;I solved my own question by implementing the &lt;a href=&quot;https://en.wikipedia.org/wiki/Direct_linear_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Direct Linear Transformation&lt;/a&gt;. The examples section on Wikipedia was my use case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get the equations, plug in the matrices (e.g. &lt;code&gt;[x1 x2 x3 x4; x5 x6 x7 x8; x9 x10 x11 x12]&lt;/code&gt;) into your favorite computer algebra system like SageMath, then Solve the required matrix equation as illustrated, copy-paste the solutions in terms of variables into your code, and adjust formatting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One could then adapt the solution to one's use case by scaling or ignoring particular dimensions as appropriate (e.g. ignore the depth/z coordinate in the Normalized Device Coordinates matrix as appropriate to the use case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You will need an SVD decomposition function or library in your language.&lt;/p&gt;&#xA;" OwnerUserId="4714" LastActivityDate="2017-09-20T11:40:12.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5637" PostTypeId="1" CreationDate="2017-09-20T17:20:17.527" Score="1" ViewCount="146" Body="&lt;p&gt;I'm currently working on a renderer that tries to minimize the amount of state changes when drawing objects.&#xA;During each frame the client submits draw instances (the client provides a render state (shader program, vao, vbo) and the vertex offset and count).&#xA;At the end of each frame the renderer sorts these draw instances by depth and state and generates a list of draw commands (e.g. BindVertexBuffer, UseProgram, DrawArrays).&#xA;Now my question is, how would I go about handling uniforms in a renderer like this which holds on to all actual gpu communication until the end of the frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have an idea on how to do this using callbacks which would be passed to the renderer when submitting a draw instance.&#xA;Something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Called several times by systems during the game loop&#xA;renderer.add(program, vbo, VertexPositionColor::getFormat(), 0, 3, [](){&#xA;    const GLfloat[4] color = { 1, 0, 0, 1 };&#xA;    glUniform4fv(0, color);&#xA;});&#xA;// Called once at the end of the game loop&#xA;renderer.draw(); // sort, generate commands, execute commands&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this seems like a less than optimal approach as it'll most likely trash the icache if there is significant amount of draw instances.&#xA;Would this be a valid approach? And what are some of the alternatives?&lt;/p&gt;&#xA;" OwnerUserId="5960" LastActivityDate="2017-09-20T22:44:51.663" Title="How do I handle uniforms in a deferred renderer?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5638" PostTypeId="1" CreationDate="2017-09-20T19:12:34.760" Score="2" ViewCount="141" Body="&lt;p&gt;I've been working on implementing the technique from the paper &quot;Designing look-and-feel using generalized crosshatching&quot; which can be found at: &#xA; &lt;a href=&quot;http://dl.acm.org/citation.cfm?id=3085054&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://dl.acm.org/citation.cfm?id=3085054&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper uses triplanar texture mapping to put tilable &quot;line shading&quot; style textures onto 3d rendered models.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It uses the brightness of the pixel to select which texture to use, where it has source textures of varying brightness levels like in the image below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qdL0X.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qdL0X.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The key part of our approach is a texture synthesis algorithm that&#xA;  can construct on average constant color crosshatching textures&#xA;  from a single crosshatching image that can be hand-drawn by&#xA;  artists&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It then explains that it takes that constant color texture and applies dilation and erosion filters to obtain the darker and lighter versions of the (greyscale) texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is this:  Let's say that you have a greyscale image of an artist drawing some cross hatching on a white piece of paper using a pencil.  How would you convert that image to be constant average color or brightness?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only other relevant info from the paper seems to be this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Our texture synthesis algorithm is an extremely simple nonstationary&#xA;  convolution filter that consists of two stages as follows:&#xA;  (1) For every pixel, compute the average color in a region around&#xA;  the pixel where the shape of the region and weights are controlled&#xA;  by a user-defined kernel. (2) If the color of the region is darker than&#xA;  the goal color, make the color of the pixel lighter; or otherwise&#xA;  darker&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That information is a bit sparse, and doesn't explain how much lighter or darker you should make a pixel. It's also a bit ambiguous to me whether they are talking about the process that makes the image constant color, or if they are talking about the process that makes lighter or darker versions of the constant color source texture.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-09-20T19:12:34.760" Title="Making an approximately constant color or brightness image" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5639" PostTypeId="2" ParentId="5637" CreationDate="2017-09-20T22:44:51.663" Score="2" Body="&lt;p&gt;I'd say that the fundamental problem here is your approach. You basically want the outside renderer to throw a bunch of random stuff at the wall, then let the internal rendering system sort it out without having any idea what any of that stuff actually &lt;em&gt;means&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's what I mean. Consider the case of skinned meshes vs. unskinned meshes. The internal rendering system has no idea which ones are skinned or not; all it knows is that some draw commands use a particular program and a large UBO/SSBO, while others use a different program and much smaller UBOs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And that kinda works... to a point. And that point is when you're dealing with state values that are no longer encapsulated in objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniform values are program state. And you might reasonably have two different objects that use the same program have the same value for that uniform. They might have different values for other uniforms, but there would be different variance in which objects use which values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But here's the thing: in pretty much every case where this happens, someone knows that it happened. And the code that knows that is the higher level code. After all, if two objects have common programs and common uniform values, they probably have a bunch of other stuff in common too. So odds are good that the higher level code knows when such things would happen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By using this &quot;throw stuff against the wall&quot; approach, by separating the business end of your renderer from the source of that rendering data, you destroy the semantic information you could have used to detect such things. That is, it is the higher level system that should handle the &quot;sort by state change&quot; part, since it can do a much better job.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;However, given that you've effectively designed yourself into a corner, I'd say that the simplest approach is to develop a way to encode uniform values, rather than relying on callbacks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniforms can be scalars, vectors, or matrices (arrays and structs use multiple uniform locations). So you need the equivalent of a &quot;variant&quot; type that can store all of such data, of the types supported by GLSL. And then, for each object, you walk through each uniform location in that object's data block and set that value. Sure, &quot;visitation&quot; is not the most instruction-cache friendly approach, but it's a lot better performing than calling a &lt;code&gt;std::function&lt;/code&gt;. At least with visitation, you're executing the same block of code each time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what you'd have is a (possibly dynamic) array of uniform data, where each uniform datum is a location, a type, and the variant data. I'll leave the storage optimization of the &quot;variant&quot; as an exercise for the reader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally speaking however, non-block uniform usage should be fairly minimal, dealing only with values that change frequently while rendering with a program. So even in that case, things shouldn't be too bad.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-09-20T22:44:51.663" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5640" PostTypeId="1" CreationDate="2017-09-23T10:14:06.407" Score="4" ViewCount="113" Body="&lt;p&gt;In my n-body simulation I would like to color the particles in way which corresponds to the magnitude of the net force acting on them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is so that I can confirm visually that the particles closer to the center of a galaxy have higher accelerations (so for example particles near the rim of a galaxy are lighter colored, and the core is red).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let P be a particle. If F is the magntitude of the net force acting on P, the idea is to calculate s=F/F_max where F_max is the maximum possible force between two particles (which exists since my simulation uses gravitational softening). Since s is a number between 0 and 1, I can associate to P an HSV color by fixing saturation and value, and setting hue=s.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue: because the gravitational force scales as 1/r^2 the mapping of F to s is not linear. The result is that, when their are few particles (N&amp;lt;50), the color of a particle seem to change only if it becomes locked in a binary (in a bound system of two particles which are very close to eachother). The binaries are easy to identify because they blink (default color when they are at maximal distance, another color when they are at minimal distance).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For N=10,000 the result is pretty at least, but I'm not sure how realistic it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rsQtH.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rsQtH.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how should I map the force to a color in a realistic way? My goal would be to get something more like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tqwVR.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tqwVR.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7363" LastActivityDate="2017-09-23T10:14:06.407" Title="How to properly color particles in N body sim?" Tags="&lt;color&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5641" PostTypeId="1" CreationDate="2017-09-24T21:20:31.143" Score="1" ViewCount="58" Body="&lt;p&gt;I want to create an application to visualize image pairs in stereoscopic 3D. I want it to have a cursor that can move left and right, but also in and out. I think the way to achieve this is to draw a cursor on top of each image and then draw the images on screen (which would be a 3D capable screen).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I create such an application?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The experience I have is console programming in C, C++, Python. And I once used GTK+ to create a windowed app.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've searched around and my problem is that I don't know where to start learning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More details:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This app is meant to run on windows (although it would be nice if I could made multi-platform)&lt;/p&gt;&#xA;" OwnerUserId="7368" LastActivityDate="2017-09-25T03:10:06.253" Title="Stereoscopic 3D app development" Tags="&lt;3d&gt;&lt;stereo-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5642" PostTypeId="2" ParentId="5641" CreationDate="2017-09-25T03:10:06.253" Score="1" Body="&lt;p&gt;This is a &lt;em&gt;very&lt;/em&gt; broad question. The basic way to do this is to generate 2 frames - one for each eye. You can do this using any modern 3D API from &lt;a href=&quot;https://www.opengl.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL&lt;/a&gt; to &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ee663274(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;DirectX&lt;/a&gt; to &lt;a href=&quot;https://www.khronos.org/vulkan/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Vulkan&lt;/a&gt;, &lt;a href=&quot;https://developer.apple.com/metal/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metal&lt;/a&gt;, or DX12. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll need to understand things like interocular distance, &lt;a href=&quot;http://www.eruptingmind.com/depth-perception-cues-other-forms-of-perception/&quot; rel=&quot;nofollow noreferrer&quot;&gt;depth cues&lt;/a&gt;, and &lt;a href=&quot;http://www.wisegeek.com/what-is-3d-compositing.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;3D compositing&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll also need some way to allow the user to move the curser in and out, so you'll want to read up on various user interface, visual interface, and user experience (UI, VI, and UX, respectively) techniques.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-09-25T03:10:06.253" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5643" PostTypeId="1" AcceptedAnswerId="5646" CreationDate="2017-09-25T12:03:24.207" Score="2" ViewCount="1559" Body="&lt;p&gt;I am working my way through my first path tracer and I am currently designing how to deal with area lights. I have two questions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each object in my scene can have a Light attached to it, this is how I represent Area Lights. Given this I have two questions: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) &lt;strong&gt;Shadow ray:&lt;/strong&gt; When doing shadows, if I use a blind &lt;code&gt;IsOccluded&lt;/code&gt; function that I use successfully for point lights, I will obviously have always an &quot;occluded&quot; result, as the light vector by construction ends up at the light source itself which is an object in my scene and therefore will be hit by the shadow ray. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To rephrase, how do I deal nicely with the light being an object in my scene when casting the shadow ray for that light? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to keep my &lt;code&gt;IsOccluded&lt;/code&gt; function simple, returning only a boolean and not a position/interaction record. At first glance PBRT manages to do so, but I don't understand how they get around the problem. Am I forced to use a different scene intersection function? If so, what is the most graceful way to solve the problem? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) &lt;strong&gt;Secondary rays&lt;/strong&gt;: If I have more than one bounce, I often see this black dots appearing (even if I disable shadows). I know this is hard without more context, but I wonder if someone has encountered something like this or can guess: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;With multiple bounces&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oxwtz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oxwtz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;With only first hit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VALHH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VALHH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought it could be related to the way I sample the sphere, but if that was the case, shouldn't I get black dots even with only one event? I think these are NaNs, will double check, but if you know common scenarios when this happens it'd be appreciated. I am guessing I am trying to lit the light with the light itself, causing a NaN that gets then propagated. Does it make sense? I am more interested to understand the cause than how to fix this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) &lt;strong&gt;Bright pixels&lt;/strong&gt;: Somewhat unrelated? (I can open separate question), but I get lots of unnaturally bright pixels all over the place if I have more than 2 bounces. What is the cause of this? How do I fix this? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, do you have any suggestion on how to handle area light sources that I am clearly missing here? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you and sorry for the probably confused question, I am happy to edit it if you have suggestions. &lt;/p&gt;&#xA;" OwnerUserId="7228" LastEditorUserId="7228" LastEditDate="2017-09-25T12:41:23.657" LastActivityDate="2017-09-26T19:21:24.273" Title="Path tracing with Next event estimation and area lights auto occlusion" Tags="&lt;lighting&gt;&lt;pathtracing&gt;&lt;shadow&gt;&lt;area&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5644" PostTypeId="1" CreationDate="2017-09-26T15:06:39.450" Score="2" ViewCount="678" Body="&lt;p&gt;I am trying out different anti-aliasing algorithms on my image to improve the image quality. I want to compare the differences between these generated images via some metric. I was checking online for good metrics and found none.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone please help me by pointing me to a valid metric that one can use to measure aliasing effects in an image ? &lt;/p&gt;&#xA;" OwnerUserId="6974" LastActivityDate="2017-09-26T17:54:25.353" Title="How to compare anti-aliasing effects on images ?" Tags="&lt;antialiasing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5645" PostTypeId="2" ParentId="5644" CreationDate="2017-09-26T17:54:25.353" Score="1" Body="&lt;p&gt;What you want to do is compare your anti aliased results against a &quot;ground truth&quot; image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ground truth image is the same image but without aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many ways to make an alias-free image, but a straight forward way would be by doing super sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Super Sampling&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When we render, we usually take a single sample at the center of the pixel (rasterize / shader / etc it to make the color).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Super sampling works by taking $N$ samples for that pixel, in random parts of the pixel and averaging the result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The more samples you take, the closer you get to the ideal &quot;alias free&quot; image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One simple way to do super sampling is to render the image at a higher resolution and then shrink it down to a smaller image.  For instance, if you render at double the height and width and then shrink the image down, that's the same as taking 4 samples per pixel.  However, going this route, the samples are evenly spaced on a grid, not randomly placed within each pixel.  Making the samples random instead of evenly spaced is really important to this monte carlo integration working, but evenly spacing them on a grid is a cheaper method that is better than nothing (aka useful in realtime situations sometimes).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way to do super sampling would be to render the image at normal resolution $N$ times, but in each render, you randomly offset the camera by a sub-pixel amount.  You then average your $N$ images together.  That will give you the random sample points, but of course each pixel has the same random sample points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why you will often see sub-pixel jittering of the camera when doing temporal anti aliasing: it allows for better anti aliased results (a better integration) over time when combining multiple frames.  If they were all in the same position every frame, you wouldn't get any more information about the pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing these methods will give you your ground truth alias free image, if using enough samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Comparing vs Ground Truth&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next step would be to compare the other anti aliased techniques against the super sampled ground truth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are lots and lots of ways that you might want to analyze this data, but I'll give a few ideas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way could be to make a texture where each pixel is the absolute value of the difference between the images for that pixel.  This would let you see the entire image as a whole and get an idea of how different it was from the ground truth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way could be to calculate the mean and standard deviation of the difference of the images. This would give you an idea of how much on average pixels differed in the images, while also giving you an idea of how much variance there was in the difference. A high variance means some places are much worse than other places, so isn't very consistent.  Ideally, the best AA method will have the lowest mean, and the lowest variance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, since aliasing is ultimately a &quot;frequency&quot; thing, you might find interesting data in doing a discrete Fourier transform on your images and comparing the frequencies in the AA method images vs the frequencies in the super sampled image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More info on taking DFT of images here: &lt;a href=&quot;https://blog.demofox.org/2016/07/28/fourier-transform-and-inverse-of-images/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.demofox.org/2016/07/28/fourier-transform-and-inverse-of-images/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-09-26T17:54:25.353" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5646" PostTypeId="2" ParentId="5643" CreationDate="2017-09-26T19:21:24.273" Score="3" Body="&lt;p&gt;I am no expert in offline renderers, but I'll give it a go until someone else comes with a better answer :)&lt;/p&gt;&#xA;&lt;h2&gt;Shadow rays intersecting area light&lt;/h2&gt;&#xA;&lt;p&gt;It is &lt;em&gt;very&lt;/em&gt; common to assign an extent to your rays. How to do so? Think about the parametric formula of a ray:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$R(t) = O + t\vec{D}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;it should immediately jumps out that how far &lt;span class=&quot;math-container&quot;&gt;$R(t)$&lt;/span&gt; can be from the origin &lt;span class=&quot;math-container&quot;&gt;$O$&lt;/span&gt; depends on how much we can travel in the direction &lt;span class=&quot;math-container&quot;&gt;$\vec{D}$&lt;/span&gt;, and this travelling is clearly governed by the parameter &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Your problem here is that you don't want to let the ray travel indefinitely, but you want to stop just before it hits the source of the light, because otherwise, as you correctly noticed, everything will result occluded.&lt;/p&gt;&#xA;&lt;p&gt;So how do you limit how much your ray can travel? You just have to limit the maximum value that &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; can take. You have two option:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Probably the most intuitive one is to compute at what &lt;span class=&quot;math-container&quot;&gt;$t_{light}$&lt;/span&gt; your light source lies. By using the same parametric formulation of the ray, if &lt;span class=&quot;math-container&quot;&gt;$L_p$&lt;/span&gt; is the point you've chosen on the area light, then &lt;span class=&quot;math-container&quot;&gt;$t_{light}$&lt;/span&gt; will be:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$t_{light} = \frac{L_{p}[i] - O[i]}{\vec{D}[i]}$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$[i]$&lt;/span&gt; represents the coordinate of your choice.  Given this, you want to stop your shadow ray to travel just before &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; reaches &lt;span class=&quot;math-container&quot;&gt;$t_{light}$&lt;/span&gt;. If it goes over this value, report an unoccluded result.&lt;/p&gt;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Now while the option above is probably the first thing that comes to mind, it is wasteful as you'd need to both have &lt;span class=&quot;math-container&quot;&gt;$L_p$&lt;/span&gt; around and perform some unneeded arithmetic operations if you have your light vector &lt;span class=&quot;math-container&quot;&gt;$\vec{D}$&lt;/span&gt; as unnormalized around. In fact, this is none other than &lt;span class=&quot;math-container&quot;&gt;$L_p - O$&lt;/span&gt; and in a case like this, the Light lies at exactly &lt;span class=&quot;math-container&quot;&gt;$t == 1$&lt;/span&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ O + 1 \times (L_p - O ) = L_p $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So if you trace your shadow ray with an unnormalized direction &lt;span class=&quot;math-container&quot;&gt;$\vec{D}$&lt;/span&gt;, you can just set your maximum &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; to be &lt;em&gt;just under&lt;/em&gt; &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt;. This is in fact what PBRT does, and as far as I am aware many other renderers.&lt;/p&gt;&#xA;&lt;h2&gt;Black dots (or NaNs)&lt;/h2&gt;&#xA;&lt;p&gt;Nothing to add over @Dan Hulme comment, so I'll just add it here for completeness of the answer:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&amp;quot;I think these are NaNs, will double check, but if you know common scenarios when this happens it'd be appreciated.&amp;quot; The common scenario is that you're using floating-point and you have a bug in your code :-) You have to expect that you'll get NaNs during development, so you should either (a) make sure they get filtered out instead of propagated by the filter, or (b) show all NaNs as bright pink so it's immediately obvious when they're there. – Dan Hulme♦&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;and if I may add, you should expect some &lt;code&gt;inf&lt;/code&gt; as well from time to time, so it's always good to account for these two special cases.&lt;/p&gt;&#xA;&lt;h2&gt;&amp;quot;Bright pixels&amp;quot;&lt;/h2&gt;&#xA;&lt;p&gt;With that, I assume you are talking about what is commonly referred to as fireflies. Fireflies avoidance is indeed quite a big topic and probably warrant its own question. However, just briefly.&lt;/p&gt;&#xA;&lt;p&gt;Fireflies typically occur when you lots of your paths end in areas with low light and very few paths end up in very bright light.&#xA;There is lots of material on how to fight fireflies, a short google search will lead to a lot of techniques depending on your case.&#xA;Just to name drop a few:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Radiance clamping&lt;/li&gt;&#xA;&lt;li&gt;Multiple Importance Sampling (especially if in presence of glossy/shiny surfaces)&lt;/li&gt;&#xA;&lt;li&gt;Denoising techniques&lt;/li&gt;&#xA;&lt;li&gt;Increment your sample count :-)&lt;/li&gt;&#xA;&lt;li&gt;etc.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Also, generally increasing the size of the light source tends to help as well. Remember, the goal is always to hit those bright spot with higher probability!&lt;/p&gt;&#xA;&lt;p&gt;A better solution to the problem is probably to use something like &lt;a href=&quot;https://graphics.stanford.edu/courses/cs348b-03/papers/veach-chapter10.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bidirectional Path Tracing&lt;/a&gt; as this will have sub-paths starting from the light source as well, increasing the likelihood of sampling the bright areas.&lt;/p&gt;&#xA;&lt;p&gt;Another cause of fireflies are caustics, but I don't want to make this answer longer, so if you are interested this is well worth an additional question.&lt;/p&gt;&#xA;" OwnerUserId="100" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-09-26T19:21:24.273" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5647" PostTypeId="1" CreationDate="2017-09-26T19:41:53.557" Score="2" ViewCount="70" Body="&lt;p&gt;I have implemented an N-body simulation using the Barnes-Hut optimisation in Python which runs at a not-unacceptable speed for N=10,000 bodies, but it's still too slow to watch real time. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A new frame is generated each time-step, and to display the frame we must first calculate the new positions of the bodies, and then draw them all. For N=10,000, it takes about 5 seconds to generate one frame (this is waaay too high as Barnes-Hut should be giving better results). The display is done through the pygame module.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would thus like to record my simulation and replay it once after it's done at a higher speed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How can I accomplish this without slowing down the program or exceeding memory limitations?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One potential solution is simply to save the pygame screen each timestep, but this is apparently very slow. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought also about storing the list of positions of the bodies generated each time step, and then redrawing all the frames once the situation finishes. Drawing a frame still takes some time, but not as much time as it takes to calculate the new positions.&lt;/p&gt;&#xA;" OwnerUserId="7363" LastActivityDate="2018-04-24T07:46:19.220" Title="How to record N-body simulation as a video?" Tags="&lt;simulation&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5648" PostTypeId="2" ParentId="5647" CreationDate="2017-09-27T02:12:08.333" Score="1" Body="&lt;p&gt;You could always write each frame out as an image and then use another tool to compress it into a movie that you playback. You don't say what type of system you're running on, but I believe that &lt;a href=&quot;http://ffmpeg.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;ffmpeg&lt;/a&gt; could do it for you, as it's a cross-platform tool. It's hard to estimate how long the compression will take since it will depend on the content you're compressing. I'm not sure whether you can continuously feed it frames, or if you need to generate them all at once.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-09-27T02:12:08.333" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5650" PostTypeId="2" ParentId="5647" CreationDate="2017-09-27T20:14:29.643" Score="3" Body="&lt;p&gt;user1118321's suggestion is the correct one but i'll elaborate a bit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You run your simulation giving it a fixed time step between frames.  This time step would be 1/30th of a second (33.3333 ms) for instance if you wanted a 30 fps movie.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You let your simulation calculations and your rendering run, taking as long as they need to, and then write the rendered frame out to disk, with the frame number in the name (like frame0.bmp, frame1.bmp, etc).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After you have all these frames, you can use ffmpeg to combine them into a video of the desired frame rate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want audio in your video (like sounds when things collide), you can actually keep an audio timeline (what audio events happened on which frames, or at what points in time) while doing your simulation, and then after your rendering is finished, you can generate the audio stream that goes along with your video, which ffmpeg will gladly combine with your video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've used this on a few projects in times past and it's worked great.  I also wrote up some more details about this process a while back:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://blog.demofox.org/2012/09/09/recording-perfectly-lagless-audio-synchronized-video-of-your-game/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Recording lagless demo videos of a laggy game | The blog at the bottom of the sea&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:46:19.220" LastActivityDate="2018-04-24T07:46:19.220" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5651" PostTypeId="1" CreationDate="2017-09-27T22:13:31.273" Score="3" ViewCount="304" Body="&lt;ul&gt;&#xA;&lt;li&gt;I have done my due hour of research before asking this question, it's a simple question, but I have found no hint at an answer online.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I want the ability to extend an object infinitely in one direction, such as a tower that appears infinitely high, or a road infinitely long. I have tried my hardest to think up an approach to this that doesn't cheat, but nothing has come to mind.&lt;/p&gt;&#xA;&lt;p&gt;An example, take a textured cube, and have it appear infinitely tiled in one direction, to its vanishing point:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZEwMC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZEwMC.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Is there a way of doing this while retaining lighting and bumpmaps so it seamlessly blends with level geometry? Is there any way to do this efficiently?&lt;/p&gt;&#xA;&lt;p&gt;Hopefully this isn't a stupid or misplaced question, thanks for your time.&lt;/p&gt;&#xA;" OwnerUserId="7378" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-09-28T15:38:46.670" Title="Creating a vanishing point perspective shader" Tags="&lt;shader&gt;&lt;computational-geometry&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5652" PostTypeId="1" AcceptedAnswerId="5653" CreationDate="2017-09-28T05:38:31.193" Score="3" ViewCount="170" Body="&lt;p&gt;I've been getting interested in SIMD programming on CPU using SSE recently, but I'm a complete noob on the subject. I found &lt;a href=&quot;http://www.codersnotes.com/notes/maths-lib-2016/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; describing how to make an efficient float3 type using the recent __vectorcall convention, and it made me wonder how best to deal with the wasted space inherent in using a 128-bit type to represent vectors smaller than 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a typical use case, you might want to transform a bunch of positions and normals on the CPU in order to do a batched draw call. When transmitting the data over to the GPU, though, ideally you'd want this as tightly packed arrays of float3, either interleaved or in separate buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like there are two options here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A - store the data tightly packed, and unpack and repack to and from SSE-friendly format when you need to manipulate it, taking the CPU performance hit, or&lt;/p&gt;&#xA;&#xA;&lt;p&gt;B - store the data loosely packed on 16-byte boundaries, SSE it directly, and take the bandwidth and VRAM hit when sending to GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which of these options would be preferred in a real-world 3D engine, or under what circumstances would you prefer one to the other?   &lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="6" LastEditDate="2018-06-25T12:39:11.763" LastActivityDate="2018-07-01T23:10:45.130" Title="Dealing with wasted space when using SIMD on CPU for vector maths" Tags="&lt;performance&gt;&lt;memory&gt;&lt;data-structure&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5653" PostTypeId="2" ParentId="5652" CreationDate="2017-09-28T07:24:17.870" Score="6" Body="&lt;p&gt;There's a third option you've neglected. Because of how graphics APIs work, typically you have to copy the data between the CPU and GPU anyway - even if you're on a mobile SoC where they share the same physical memory. This copy is the ideal time to take the hit of changing format, since you have to touch all of the memory anyway. So the copy in user memory, owned by the CPU, can be stored padded for SIMD alignment. Then, when you need to send that data to GPU memory, instead of doing a memcpy, just read in the 4-vectors and write out 3-vectors. It's less memory bandwidth than a normal copy (you're reading just as much, but writing less) and negligible CPU work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you've got that fourth float doing nothing, you might as well use it and make your co-ordinates homogeneous instead of just xyz. Depending on what compute you're doing on the CPU, that might make some things easier (transforms are the obvious example, but also reducing divisions if you were renormalising your normals a lot before).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is similar but not identical to a trick I used when implementing OpenGL texture upload. On ARM, most Neon instructions operate at memory bandwidth rate, so if you're already doing a memcpy, it's free to do a pipeline-worth of instructions at the same time. You can use those free instructions to do pixel format conversion &lt;em&gt;and&lt;/em&gt; reordering to Z-order or U-order.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-09-28T07:24:17.870" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5655" PostTypeId="2" ParentId="5651" CreationDate="2017-09-28T15:16:13.127" Score="2" Body="&lt;p&gt;It should be possible to do this properly by using a modified projection matrix for your entire scene that has its far plane at infinity, as detailed &lt;a href=&quot;http://www.terathon.com/gdc07_lengyel.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. That should allow you to properly render points infinitely far away from the camera. The presentation says that such a point is represented by a direction (a vector with .w = 0), so it should be as simple as replacing the position of your vertex with the direction vector pointing towards the desired vanishing point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One caveat is that any interpolation between the vanishing point and any other vertex would be incorrect, because the perspective correct hardware interpolator can't properly handle infinite values. This shouldn't affect lighting assuming normals are the same, but it will make texturing considerably harder. Probably the easiest way here would be to do an inverse projection of the point back to object space in the fragment shader and define the texture coordinates to be based on the object space position of the fragment.&lt;/p&gt;&#xA;" OwnerUserId="3470" LastEditorUserId="3470" LastEditDate="2017-09-28T15:38:46.670" LastActivityDate="2017-09-28T15:38:46.670" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5656" PostTypeId="2" ParentId="3946" CreationDate="2017-09-29T10:47:41.160" Score="1" Body="&lt;p&gt;A more recent paper (2005 at least ;) ), has a more concise notation while comparing multiple BRDFs including the &lt;strong&gt;Cook-Torrance BRDF&lt;/strong&gt;. Their formula does not include the division by 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://people.csail.mit.edu/addy/research/ngan05_brdf_eval.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Addy Ngan, Frédo Durand, Wojciech Matusik: Experimental Analysis of BRDF Models, &#xA;Proceedings of the Eurographics Symposium on Rendering 2005.&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://people.csail.mit.edu/addy/research/brdf/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Project Page&lt;/a&gt;, &lt;a href=&quot;http://people.csail.mit.edu/addy/research/ngan05_brdf_supplemental_doc.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Supplemental&lt;/a&gt; (Take a look at the supplemental!)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note, however that the &lt;strong&gt;Cook-Torrance BRDF&lt;/strong&gt; is not equal and thus not a synonym for the &lt;strong&gt;Torrance-Sparrow BRDF&lt;/strong&gt;. The latter includes your division by 4. An interesting reference overview can be found in:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://digibug.ugr.es/bitstream/10481/19751/1/rmontes_LSI-2012-001TR.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Rosana Montes, Carlos Ureña: An Overview of BRDF Models, Technical Report, 2012.&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same &lt;strong&gt;Cook-Torrance BRDF&lt;/strong&gt; formula is also present in:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Philip Dutré, Kavita Bala, Philippe Bekaert: Advanced Global Illumination, 2nd Edition, 2006.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;: I looked at some (isotropic) implementations of the &lt;strong&gt;F&lt;/strong&gt;, &lt;strong&gt;G&lt;/strong&gt; (or &lt;strong&gt;V&lt;/strong&gt; depending if you factor the foreshortening in the denominator into &lt;strong&gt;G&lt;/strong&gt;) and &lt;strong&gt;D&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;D&lt;/strong&gt;: Beckmann, Ward-Duer, Blinn-Phong, Trowbridge-Reitz a.k.a. GGX a.k.a. GTR2, Berry a.k.a. GTR1;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;G&lt;/strong&gt;|&lt;strong&gt;V&lt;/strong&gt;: Implicit, Ward, Neumann, Ashikhmin-Premoze, Kelemann, Cook-Torrance, Smith GGX, Smith Schlick-GGX, Smith Beckmann, Smith Schlick-Beckmann;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;F&lt;/strong&gt;: Schlick, Cook-Torrance.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;They all seem to be used (in the literature, in the animation industry and in the gaming industry) in the format corresponding to your &lt;strong&gt;second&lt;/strong&gt; option. All the &lt;strong&gt;D&lt;/strong&gt; factors in my enumeration contain an explicit $\frac{1}{\pi \alpha^2} $ with $\alpha \equiv \text{roughness}^2$ (See &lt;a href=&quot;http://graphicrants.blogspot.be/2013/08/specular-brdf-reference.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Equations&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 2:&lt;/strong&gt; A recent presentation deriving and explaining the division by $4$ instead of $\pi$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://twvideo01.ubm-us.net/o1/vault/gdc2017/Presentations/Hammon_Earl_PBR_Diffuse_Lighting.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Earl Hammon: PBR Diffuse Lighting for GGX+Smith Microsurfaces&lt;/em&gt;, GDC 2017.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make a long story shorter, &lt;strong&gt;option 2 is the only correct specular term&lt;/strong&gt; (of the three options provided).&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-10-25T11:47:19.843" LastActivityDate="2017-10-25T11:47:19.843" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5657" PostTypeId="1" CreationDate="2017-09-29T11:26:31.540" Score="1" ViewCount="848" Body="&lt;p&gt;I am trying to implement bilinear interpolation as described in the paper &lt;strong&gt;Spatial Tranformer Networks&lt;/strong&gt; by &lt;em&gt;Jaderberg et. al&lt;/em&gt; (see &lt;a href=&quot;https://arxiv.org/pdf/1506.02025.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;link to paper&lt;/a&gt;). They describe bilinear interpolation in Equation 5 as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;V_i^c = \sum_{n}^{H}\sum_{m}^{W} U_{nm}^c \max(0,1-|x_i^s - m|)\cdot\max(0,1-|y_i^s - n|),&#xA;$$&#xA;where:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$V_i^c$ is the resulting pixel value in the new image&lt;/li&gt;&#xA;&lt;li&gt;$H$ and $W$ are the height and width of the original image (or feature map) in pixels&lt;/li&gt;&#xA;&lt;li&gt;$c$ refers to the channel (e.g. RGB)&lt;/li&gt;&#xA;&lt;li&gt;$(x_i^s, y_i^s)$ are the coordinates where the original image is sampled (where the image is normalized such that $-1 \le x_i^s, y_i^s\le 1$)&lt;/li&gt;&#xA;&lt;li&gt;$U_{nm}^c$ is defined as the pixel value at location $(n,m)$ in channel $c$.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I am having trouble interpreting the variables $n$ and $m$. Are these&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;coordinates in the normalized image (i.e. $-1 \le n, m\le 1$, where you would sum $n$ from $n=-1$ to $H=1$ in steps of the normalized resolution, e.g. steps of $1/100$ for an image that is 100 px in height)&lt;/li&gt;&#xA;&lt;li&gt;or are these row and column values (e.g. you sum $n$ from $n=0$ to $n=100$ for an image that is 100px in height)?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I have tried out both to do downsampling of an image, but don't get consistent results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If someone can help me out interpreting this, I would appreciate it very much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below I have included what I understand of bilinear interpolation. Maybe that someone can help me out based on this.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;In the below figure, a single channel feature map (or image) with one channel is displayed that consists of four pixels with values $ U_{nm} $, where $ n $ and $ m $ are the coordinates of the center of the pixels, i.e. $ m,n \in \{-0.5, 0.5\} $. If we index $ m $ and $ n $ as $ m_k, n_k $, with $ k \in [1,4] $, we can also index the pixel values as $ U_{n_km_k} $. The values of all four pixels can be reduced to a single value $ V $ at position $ (x_i^s, y_i^s) $ by applying bilinear interpolation.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/m5tiS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/m5tiS.png&quot; alt=&quot;Bilinear Interpolation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The procedure can be divided into three linear interpolations. First the value $ U_1' $ at position $ (x_{U_1'}, y_{U_1'}) $ can be computed by interpolating the values $ U_{n_1m_1} $ and $ U_{n_2m_2} $:&#xA;\begin{equation}&#xA;U_1' = \Delta x_2\ U_{n_1m_1} + \Delta x_1\ U_{n_2m_2}.&#xA;\end{equation}&#xA;As the sum of $ \Delta x_1 $ and $ \Delta x_2 $ is equal to one, due to normalization of the axes, the above equation can be rewritten as:&#xA;\begin{equation}&#xA;U_1' = (1-\Delta x_1) U_{n_1m_1} + (1-\Delta x_2) U_{n_2m_2}.&#xA;\end{equation}&#xA;The terms $ \Delta x_1 $ and $ \Delta x_2 $ can be expressed as:&#xA;\begin{align}&#xA;\Delta x_1 = |x_i^s - {m_1}|\\&#xA;\Delta x_2 = |x_i^s - {m_2}|,&#xA;\end{align}&#xA;which, substituted into the equation for $U_1'$ yields:&#xA;\begin{equation}&#xA;U_1' = U_{n_1m_1}(1-|x_i^s - {m_1}|)  +  U_{n_2m_2}(1-|x_i^s - {m_2}|).&#xA;\end{equation}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly the value for $ U_2' $ can be computed:&#xA;\begin{equation}&#xA;U_2' = U_{n_3m_3}(1-|x_i^s - {m_3}|)  +  U_{n_4m_4}(1-|x_i^s - {m_4}|).&#xA;\end{equation}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once $ U_1' $ and $ U_2' $ have been computed, $ V $ can be determined by linearly interpolating $ U_1' $ and $ U_2' $:&#xA;\begin{equation}&#xA;V =  U_1'(1-\Delta y_1) + U_2'(1-\Delta y_2) .&#xA;\end{equation}&#xA;The values for $ \Delta y_1 $ and $ \Delta y_2 $ can be expressed as follows:&#xA;\begin{align}&#xA;	\Delta y_1 = |y_i^s - y_{U_1'}| = |y_i^s - {n_1}| = |y_i^s - {n_2}|\\&#xA;	\Delta y_2 = |y_i^s - y_{U_2'}| = |y_i^s - {n_3}| = |y_i^s - {n_4}| .&#xA;\end{align}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Substituting the above equations and those of $\Delta x_1$ and $\Delta x_2$ into the equation for $V$ yields:&#xA;\begin{equation}&#xA;\begin{split}&#xA;V &amp;amp;= U_{n_1m_1}\cdot (1-|x_i^s - {m_1}|) \cdot (1-|y_i^s - {n_1}|) \\&#xA;&amp;amp;+ U_{n_2m_2}\cdot (1-|x_i^s - {m_2}|) \cdot (1-|y_i^s - {n_2}|) \\&#xA;&amp;amp;+ U_{n_3m_3}\cdot (1-|x_i^s - {m_3}|) \cdot (1-|y_i^s - {n_3}|) \\&#xA;&amp;amp;+ U_{n_4m_4}\cdot (1-|x_i^s - {m_4}|) \cdot (1-|y_i^s - {n_4}|),&#xA;\end{split}&#xA;\end{equation}&#xA;which can be written more compactly as:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;\begin{equation}&#xA;\begin{split}&#xA;V &amp;amp;= \sum_{k=1}^{4} U_{n_km_k} \cdot (1-|x_i^s - {m_k}|) \cdot (1-|y_i^s - {n_k}|)\\&#xA;&amp;amp;=\sum_{n}^{H}\sum_{m}^{W} U_{nm} \cdot (1-|x_i^s - {m}|) \cdot (1-|y_i^s - {n}|).&#xA;\end{split}&#xA;\end{equation}&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit to clarify my comment to @Dan Hulme&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Initially I also thought that $n$ and $m$ are row and column indices as you normally do a summation over integer values. Also the summation is up to $H$ and $W$, respectively, which are the # of rows and # of columns. So it seems logical to think that $\sum_{n=0}^{H = \#rows-1}\sum_{m=0}^{W = \#columns-1}$, with $n=0,1,2,...,H-1$ and $m=0,1,2,...,W-1$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when you try to apply this to an image which is larger than 2x2 pixels, it doesn't hold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify this, imagine the original image is an 8x8 image and we wish to downsample the image to a 6x6 image (I cannot add a new image to expose this due to reputation constraints, I am new here). If we want to compute the value of the upper left pixel of the downsampled image with coordinates $(x_1^s, y_1^s) = (-0.833, 0.833)$, we would have:&#xA;\begin{equation}&#xA;\begin{split}&#xA;V_{1} &amp;amp;= \sum_{n}^{H}\sum_{m}^{W} U_{nm}\cdot \max(0, 1-|x_1^s-m|)\cdot \max(0, 1-|y_1^s-n|) \\&#xA;&amp;amp;= U_{00}\cdot \max(0, 1-|-0.833-0|)\cdot \max(0, 1-|0.833-0|)\\&#xA;&amp;amp;+ U_{01}\cdot \max(0, 1-|-0.833-1|)\cdot \max(0, 1-|0.833-0|)\\&#xA;&amp;amp;+ U_{02}\cdot \max(0, 1-|-0.833-2|)\cdot \max(0, 1-|0.833-0|)\\&#xA;&amp;amp;+ ...\\&#xA;&amp;amp;+ U_{10}\cdot \max(0, 1-|-0.833-0|)\cdot \max(0, 1-|0.833-1|)\\&#xA;&amp;amp;+ U_{11}\cdot \max(0, 1-|-0.833-1|)\cdot \max(0, 1-|0.833-1|)\\&#xA;&amp;amp;+ ...\\&#xA;&amp;amp;+ U_{77}\cdot \max(0, 1-|-0.833-7|)\cdot \max(0, 1-|0.833-7|)\\&#xA;&amp;amp;= U_{00}\cdot 0.167^2 + U_{10}\cdot 0.167\cdot 0.833,&#xA;\end{split}&#xA;\end{equation}&#xA;which is only a function of $U_{00}$ and $U_{10}$ and not of $U_{00}$, $U_{01}$, $U_{10}$ and $U_{11}$ as one would reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we reason abouth the lower right pixel of the downsampled image with coordinates $(x_{49}^s, y_{49}^s) = (0.833, -0.833)$ and apply the same equation, we have:&#xA;\begin{equation}&#xA;\begin{split}&#xA;V_{49} &amp;amp;= \sum_{n}^{H}\sum_{m}^{W} U_{nm}\cdot \max(0, 1-|x_{49}^s-m|)\cdot \max(0, 1-|y_{49}^s-n|) \\&#xA;&amp;amp;= U_{00}\cdot \max(0, 1-|0.833-0|)\cdot \max(0, 1-|-0.833-0|)\\&#xA;&amp;amp;+ U_{01}\cdot \max(0, 1-|0.833-1|)\cdot \max(0, 1-|-0.833-0|)\\&#xA;&amp;amp;+ U_{02}\cdot \max(0, 1-|0.833-2|)\cdot \max(0, 1-|-0.833-0|)\\&#xA;&amp;amp;+ ...\\&#xA;&amp;amp;+ U_{10}\cdot \max(0, 1-|0.833-0|)\cdot \max(0, 1-|-0.833-1|)\\&#xA;&amp;amp;+ U_{11}\cdot \max(0, 1-|0.833-1|)\cdot \max(0, 1-|-0.833-1|)\\&#xA;&amp;amp;+ ...\\&#xA;&amp;amp;+ U_{77}\cdot \max(0, 1-|0.833-7|)\cdot \max(0, 1-|-0.833-7|)\\&#xA;&amp;amp;= U_{00}\cdot 0.167^2 + U_{01}\cdot 0.833\cdot 0.167,&#xA;\end{split}&#xA;\end{equation}&#xA;which again is only function of $U_{00}$ and $U_{01}$ and not of $U_{66}$, $U_{67}$, $U_{76}$ and $U_{77}$ as one would expect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also tried normalizing $n$ and $m$, such that $n =-1, -1+ 2/8, -1 +4/8, ..., 1$ (and similarly for $m$, but I end up with similar problems. &lt;/p&gt;&#xA;" OwnerUserId="7390" LastEditorUserId="7390" LastEditDate="2017-09-30T11:44:22.803" LastActivityDate="2017-09-30T11:44:22.803" Title="Bilinear Interpolation" Tags="&lt;image-processing&gt;&lt;sampling&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5658" PostTypeId="2" ParentId="5657" CreationDate="2017-09-29T14:38:00.140" Score="2" Body="&lt;p&gt;I think the formula at the top only makes sense if $n$ and $m$ are pixel indices, i.e. row and column numbers from 0 to $H - 1$ and 0 to $W - 1$. This way, for the four surrounding pixels, the weight varies from 0 to 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a representation of the algorithm it's unnecessarily opaque, because you don't actually want to look at every pixel of the image and multiply most of them by zero.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To implement it, you want to do something closer to your diagram, where you only look at the four surrounding pixel values, and sum just those four, multiplying each by $(1 - |x - m|)(1 - |y - n|)$. This is exactly how your four-line equation for $V$ (near the bottom of your question) expresses it, and the code should look most like this.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-09-29T14:38:00.140" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5659" PostTypeId="2" ParentId="5599" CreationDate="2017-09-29T17:18:24.943" Score="1" Body="&lt;p&gt;&lt;strong&gt;Problem&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;XMMATRIX&lt;/code&gt; and &lt;code&gt;XMVECTOR&lt;/code&gt; (which use &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/ayeb3ayc.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;__m128&lt;/code&gt;&lt;/a&gt; under the hood) require 16 byte alignment. The C++ compiler can automatically ensure this for &lt;code&gt;XMMATRIX&lt;/code&gt; and &lt;code&gt;XMVECTOR&lt;/code&gt; data allocated on the stack, but can't ensure this for &lt;code&gt;XMMATRIX&lt;/code&gt; and &lt;code&gt;XMVECTOR&lt;/code&gt; data allocated on the heap. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your specific situation (referring to the RasterTek tutorial), three member variables of your &lt;code&gt;D3DClass&lt;/code&gt; class are declared to be of type &lt;code&gt;XMMATRIX&lt;/code&gt; and you construct one instance of this &lt;code&gt;D3DClass&lt;/code&gt; class on the heap by using the default &lt;code&gt;operator new&lt;/code&gt; (due to the absence of a custom one). Using the default &lt;code&gt;operator new&lt;/code&gt; does not guarantee this 16 byte alignment. Even if your code would have run fine using the default &lt;code&gt;operator new&lt;/code&gt;, you could still face this issue after adding some extra member variables in the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Solution 1&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most easy fix in this specific case, is to allocate your &lt;code&gt;D3DClass&lt;/code&gt; class instances on the stack instead of on the heap. This, however, does not prevent you or future users of your code to allocate an instance on the stack instead. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Solution2&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The programmers of the DirectXMath library advise the general programmer audience to use &lt;code&gt;XMMATRIX&lt;/code&gt; and &lt;code&gt;XMVECTOR&lt;/code&gt; for calculations only, and to not use them as containers for storing persistent data (i.e. class member variables). For the latter, they advise to use &lt;code&gt;XMFLOAT4&lt;/code&gt;, &lt;code&gt;XMFLOAT4x4&lt;/code&gt;, etc. The latter structs do not impose the 16 byte alignment restriction and their instances can simply be loaded in SIMD registers by using &lt;code&gt;XMLoadFloat4&lt;/code&gt; for &lt;code&gt;XMVECTOR&lt;/code&gt;, &lt;code&gt;XMLoadFloat4x4&lt;/code&gt; for &lt;code&gt;XMMATRIX&lt;/code&gt;, etc.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;However, often it is easier and more compact to avoid using &lt;code&gt;XMVECTOR&lt;/code&gt;&#xA;  or &lt;code&gt;XMMATRIX&lt;/code&gt; directly in a class or structure. Instead, make use of the&#xA;  &lt;code&gt;XMFLOAT3&lt;/code&gt;, &lt;code&gt;XMFLOAT4&lt;/code&gt;, &lt;code&gt;XMFLOAT4X3&lt;/code&gt;, &lt;code&gt;XMFLOAT4X4&lt;/code&gt;, and so on, as members of&#xA;  your structure. Further, you can use the Vector Loading and Vector&#xA;  Storage functions to move the data efficiently into &lt;code&gt;XMVECTOR&lt;/code&gt; or&#xA;  &lt;code&gt;XMMATRIX&lt;/code&gt; local variables, perform computations, and store the results.&#xA;  There are also streaming functions (&lt;code&gt;XMVector3TransformStream&lt;/code&gt;,&#xA;  &lt;code&gt;XMVector4TransformStream&lt;/code&gt;, and so on) that efficiently operate directly&#xA;  on arrays of these data types.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Solution 3&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ensure the 16 byte alignment by overwriting &lt;code&gt;operator new&lt;/code&gt;/&lt;code&gt;operator delete&lt;/code&gt;, &lt;code&gt;operator new[]&lt;/code&gt;/&lt;code&gt;operator delete[]&lt;/code&gt;. We declare a template class which does allow heap allocation with arbitrary alignment restrictions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;malloc.h&amp;gt;&#xA;&#xA;inline void *AllocAligned(size_t size, size_t alignment = 16) noexcept {&#xA;    return _aligned_malloc(size, alignment);&#xA;}&#xA;&#xA;inline void FreeAligned(void *ptr) noexcept {&#xA;    if (!ptr) {&#xA;        return;&#xA;    }&#xA;&#xA;    _aligned_free(ptr);&#xA;}&#xA;&#xA;template&amp;lt; typename DataT &amp;gt;&#xA;struct AlignedData {&#xA;&#xA;public:&#xA;&#xA;    static void *operator new(size_t size) {&#xA;        const size_t alignment = __alignof(DataT);&#xA;&#xA;        // __declspec(align) on DataT is required&#xA;        static_assert(alignment &amp;gt; 8, &#xA;            &quot;AlignedData is only useful for types with &amp;gt; 8 byte alignment.&quot;);&#xA;&#xA;        void * const ptr = AllocAligned(size, alignment);&#xA;        if (!ptr) {&#xA;            throw std::bad_alloc();&#xA;        }&#xA;&#xA;        return ptr;&#xA;    }&#xA;&#xA;    static void operator delete(void *ptr) noexcept {&#xA;        FreeAligned(ptr);&#xA;    }&#xA;&#xA;    static void *operator new[](size_t size) {&#xA;        return operator new(size);&#xA;    }&#xA;&#xA;    static void operator delete[](void *ptr) noexcept {&#xA;        operator delete(ptr);&#xA;    }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code snippet is based on the &lt;a href=&quot;https://github.com/Microsoft/DirectXTK&quot; rel=&quot;nofollow noreferrer&quot;&gt;DirectXTK&lt;/a&gt; and is also included in my own &lt;a href=&quot;https://github.com/matt77hias/MAGE/blob/master/MAGE/MAGE/src/memory/allocation.hpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;codebase&lt;/a&gt; (including documentation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This data structure can now be used as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;__declspec(align(16)) struct Transform final : public AlignedData&amp;lt; Transform &amp;gt; {&#xA;    XMMATRIX m_transform;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A Transform structure can now be allocated on the heap with 16 byte alignment, since our custom &lt;code&gt;operator new&lt;/code&gt; will now be invoked:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Transform *transform = new Transform();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you use instances of the &lt;code&gt;Transform&lt;/code&gt; struct as member variables in other structs of classes, the alignment restrictions remain of course. So instead of having only alignment restrictions for &lt;code&gt;XMVECTOR&lt;/code&gt; and &lt;code&gt;XMMATRIX&lt;/code&gt;, you will have now alignment restrictions for &lt;code&gt;XMVECTOR&lt;/code&gt;, &lt;code&gt;XMMATRIX&lt;/code&gt; and &lt;code&gt;Transform&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Smart Pointer Pitfalls&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Be careful if you use &lt;code&gt;std::shared_ptr&lt;/code&gt; and especially &lt;code&gt;std::make_shared&lt;/code&gt;. The latter allocates the data block together with the control block without using customly defined allocators such as our custom &lt;code&gt;operator new&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that this method will not work:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;template&amp;lt; typename T, typename... ConstructorArgsT &amp;gt;&#xA;inline std::shared_ptr&amp;lt; T &amp;gt; MakeShared(ConstructorArgsT&amp;amp;&amp;amp;... args) {&#xA;    return std::make_shared&amp;lt; T &amp;gt;(std::forward&amp;lt; ConstructorArgsT &amp;gt;(args)...);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;but you should rather use an explicit invocation of &lt;code&gt;operator new&lt;/code&gt; (which is also the case for &lt;code&gt;std::make_unique&lt;/code&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;template&amp;lt; typename T, typename... ConstructorArgsT &amp;gt;&#xA;inline std::shared_ptr&amp;lt; T &amp;gt; MakeAllocatedShared(ConstructorArgsT&amp;amp;&amp;amp;... args) {&#xA;    return std::shared_ptr&amp;lt; T &amp;gt;(new T(std::forward&amp;lt; ConstructorArgsT &amp;gt;(args)...));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;std::unique_ptr&lt;/code&gt; and especially &lt;code&gt;std::make_unique&lt;/code&gt; will work as intended since the latter explicitly calls &lt;code&gt;operator new&lt;/code&gt; (due to the absence of a control block).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;RasterTek&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.rastertek.com/tutdx11s2.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;RasterTek's second series of D3D11 tutorials&lt;/a&gt; is a subset of &lt;a href=&quot;http://www.rastertek.com/tutdx11.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;RasterTek's first series of D3D11 tutorials&lt;/a&gt; with the minor difference that the latter uses the obsolete &lt;code&gt;D3DXMath&lt;/code&gt;. The &lt;a href=&quot;https://blogs.msdn.microsoft.com/chuckw/2013/08/20/living-without-d3dx/&quot; rel=&quot;nofollow noreferrer&quot;&gt;transition&lt;/a&gt; is from D3DXMath to DirectXMath is actually pretty straightforward. Therefore, it can be interesting to take a look at the first series as well (which I ported to &lt;code&gt;Visual Studio 2017&lt;/code&gt;, run fine in both &lt;code&gt;Debug&lt;/code&gt; and &lt;code&gt;Release&lt;/code&gt; configurations, and can be founded as well in this &lt;a href=&quot;https://github.com/matt77hias/RasterTek&quot; rel=&quot;nofollow noreferrer&quot;&gt;repository&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to stick to &lt;code&gt;DirectXMath&lt;/code&gt;, you can also take a look at the D3D11 tutorials of Microsoft itself (&lt;a href=&quot;https://code.msdn.microsoft.com/windowsdesktop/Direct3D-Tutorial-Win32-829979ef&quot; rel=&quot;nofollow noreferrer&quot;&gt;explanation&lt;/a&gt; + &lt;a href=&quot;https://github.com/walbourn/directx-sdk-samples/tree/master/Direct3D11Tutorials&quot; rel=&quot;nofollow noreferrer&quot;&gt;code&lt;/a&gt;). (I also created a &lt;a href=&quot;https://github.com/matt77hias/Direct3D-11-Projects&quot; rel=&quot;nofollow noreferrer&quot;&gt;repository&lt;/a&gt; with some code refactors of these tutorials).&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-10-01T18:33:39.773" LastActivityDate="2017-10-01T18:33:39.773" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5661" PostTypeId="2" ParentId="4726" CreationDate="2017-09-30T16:09:36.020" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I have tried doing glCear(GL_BACK_LEFT) between each iteration but it is not clearing, I'm wondering if I'm missing a line of code before the glClear, or if I'm calling it right. I think the problem is that the back buffer isn't clearing&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This comment of yours sheds some light on the matter. This function call doesn't do what you think it does and is actually wrong usage. The &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glClear.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glClear&lt;/code&gt;&lt;/a&gt; function doesn't actually take the buffer identificator (that you give to &lt;code&gt;glDraw/ReadBuffer&lt;/code&gt;) to clear rather than a mask of the general parts of the framebuffer to clear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The framebuffer usually consists of one or more color buffers, a possible depth buffer and a possible stencil buffer. Therefore you give &lt;code&gt;glClear&lt;/code&gt; an ORed combination of the respective flags &lt;code&gt;GL_COLOR_BUFFER_BIT&lt;/code&gt;, &lt;code&gt;GL_DEPTH_BUFFER_BIT&lt;/code&gt; and &lt;code&gt;GL_STENCIL_BUFFER_BIT&lt;/code&gt; and those buffers (of the currently specified draw buffer for the color buffer) are then cleared.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So &lt;em&gt;after&lt;/em&gt; setting the draw buffer with &lt;code&gt;glDrawBuffer&lt;/code&gt; you call &lt;code&gt;glClear&lt;/code&gt; to clear that. As said, the flags depend on what you want cleared (usually at least &lt;code&gt;GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT&lt;/code&gt;, special algorithms notwithstanding).&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2017-09-30T16:09:36.020" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5662" PostTypeId="2" ParentId="3813" CreationDate="2017-09-30T17:06:32.490" Score="1" Body="&lt;p&gt;While the other answers are giving possible techniques to achieve what you're looking for, rendering your stuff into a texture is not always the best way if you need it as VBOs (i.e. vertex attributes) in the next render step (requiring either a read into a PBO and some index/coordinate/sizing magic or a vertex texture fetch).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An approach that would more accurately represent your 2nd point and be better when you need a transformation &lt;em&gt;from&lt;/em&gt; a buffer &lt;em&gt;into&lt;/em&gt; a buffer would be what's called &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Transform_Feedback&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;Transform Feedback&lt;/strong&gt;&lt;/a&gt; (or Stream Output in the DirectX world). However, this requires OpenGL 3/DirectX 10 hardware (however, not necessarily the GL4/DX11 needed for compute shaders). It's also a little less of a synchronization mess than compute shaders with arbitrary shader storage buffers when your use case is really just to transform a bunch of vertices/primitives into a nother bunch of vertices/primitives.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It basically lets you &lt;strong&gt;hook into the render pipeline after the vertex (or rather primitive) processing step and before the rasterization&lt;/strong&gt; and write out whatever per-vertex values you computed &lt;strong&gt;directly into a buffer object&lt;/strong&gt; (that you can then use as vertex attributes in the next step). It therefore doesn't draw anything into the framebuffer either. You just specify a bunch of &lt;code&gt;varying/out&lt;/code&gt; variables and how to format them into the buffer and bind a buffer to the corresponding binding point. You can also use a query to gather information of how many primtives were written (since a geometry shader could change that dynamically) or, in later versions, just render the results directly without any need for synchronization. For more details, see the above Wiki article.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Together with the geometry shader (which TF hardware should have, too) and its abilities for changing the primtive type or removing/adding vertices, this makes a useful tool for transforming your geometry however you deem fit in preparation of further rendering stages. Of course, it &lt;strong&gt;has to be evaluated if that really buys you anything&lt;/strong&gt; in the particular use-case, especially if you're really just doing a simple vertex transformation.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-10-01T21:57:57.203" LastActivityDate="2017-10-01T21:57:57.203" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5663" PostTypeId="2" ParentId="2542" CreationDate="2017-09-30T18:09:39.607" Score="0" Body="&lt;p&gt;As you analyzed correctly, GPUs aren't particularly good at dynamically sized data structures. A common approach to situations like this is speparating the problem into multiple passes, first &lt;strong&gt;computing the data in a rigid fashion and then compacting it&lt;/strong&gt; for further processing. Off the top of my head, one way to approach this would be:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;First disregard the sparseness and tiling and basically &lt;strong&gt;just store a &lt;em&gt;full&lt;/em&gt; boolean grid&lt;/strong&gt; where each pixel just stores if it is green or not, could basically just be a 0/1 uchar &lt;em&gt;per pixel&lt;/em&gt;. Fortunately, since it's a post-processing step and you're not e.g. working on rendered geometry directly, you know that you don't need more storage for possible &lt;code&gt;true&lt;/code&gt; fragments than the image resolution.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Then perform a so-called &lt;strong&gt;stream compaction&lt;/strong&gt; step, which is a common step in GPU computing where you basically compact the full array of flags into a tight array of indices (i.e. coordinates) of the actually set pixels. This is usually done by two sub-steps:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;A &lt;strong&gt;&lt;em&gt;scan&lt;/em&gt;, basically a partial sum (specifically a &lt;em&gt;prefix sum&lt;/em&gt;)&lt;/strong&gt;, that for each element computes the number of all the &lt;code&gt;true&lt;/code&gt; values preceding it. This is actually the index of that value in the final compacted array.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The actual compaction step, which &lt;strong&gt;writes each &lt;code&gt;true&lt;/code&gt; value to the position it belongs at&lt;/strong&gt;, of course now storing its index in the original array rather than just its flag value.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;While still inherently dependent on the preceding/surrounding elements, these steps are rather easy and efficient to implement in a block-based manner in the usual GPU computing frameworks like CUDA/OpenCL or OpenGL/Direct3D Compute Shaders and there's many resources on optimized algorithms for doing that. If using CUDA, there might even be ready-made computing primitives available for that. For a good introduction, see &lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch39.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this GPU Gems article&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The only problem left here is the tiling issue. Of course together with the compaction step you might also want to compute the &lt;strong&gt;boundaries (i.e. start and end indices) of your individual tiles inside the big coordinate array&lt;/strong&gt;. But that should be integratable into the general stream compaction/prefix sum algorithm since that is already inherently block-based and maybe just using the tile size as actual block size in the stream compaction would be the easiest approach there, since the per-block sums of the &lt;code&gt;true&lt;/code&gt; elements are already a by-product of the straight-forward approaches for block-based stream compaction (of course 32x32 tiles would be much cooler in this case ;-)).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It might be further simplified by actually storing your tiles not in a 2D-grid rather than one tile after the other in a linear array already when doing the first analysis step of the pixels. On the other hand, it might also be evaluated how far the first step, which afterall just looks at a pixel and creates a boolean flag value could already be intergrated into the stream compaction step. But you can do all that once the general framework is up and running.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;But of course all this also depends on how you actually want to proceed with processing your found per-tile generated green pixels. This way you still end up with a varying number of pixels in each tile, but at least they're laid out linearly in memory and you alleviated the impact of that &quot;dynamicality&quot; on the generation of those per-tile lists, however you go about processing them now. But maybe all you want is just the sum of all green pixels or some avergae weight of their coordinates?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An option you &lt;em&gt;might&lt;/em&gt; also consider is simply ignoring all that and just restructuring the next processing step in a way that works on a sparse boolean array. This gives you a fixed number of pixels but a scattered layout of the relevant data. As said, heavily depends on how you proceed with the data.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-10-01T11:46:53.130" LastActivityDate="2017-10-01T11:46:53.130" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5664" PostTypeId="1" AcceptedAnswerId="5671" CreationDate="2017-10-01T02:15:06.717" Score="2" ViewCount="121" Body="&lt;p&gt;I am studying inverse kinematics.&#xA;But I wonder the suggested equations.&#xA;(The following equations are taken from 'Computer Animation Algorithms and Techniques Third Edition Page, 181')&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To better control the kinematic model such as encouraging joint angle constraints, a control expression can be added to the pesudoinverse Jacobian solution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;($J$ is Jacobian, $J^+ = J^T(JJ^T)^{-1} = (J^TJ)^{-1}J^T$, and I will explain $z$ later)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The form for &lt;strong&gt;the control expression&lt;/strong&gt; is the below eqution 5.25&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ \theta = (J^+J - I)z\cdot\cdot\cdot\cdot(5.25) $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, the $\theta$ is always zero vector because $J^+J = I$, so $\theta = \mathbf 0z$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The book said that a change to pose parameters in the form of Equation 5.25 does not add anything to the velocities, so the control expression can be added to the pseudoinverse Jacobian solution without chaining the given velocities to be satisfied. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ V = J\theta \\&#xA;V = J(J^+J - I)z \\&#xA;V = \mathbf0z \\&#xA;V = \mathbf0 \cdot\cdot\cdot\cdot(5.26)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And the book defined $z$ (Equation (5.27)) to bias the solution toward specific joint angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$z = \alpha_i(\theta_i - \theta_{ci})^2\cdot\cdot\cdot\cdot(5.27)$ where $\theta_i$ is the current joint angles, $\theta_{ci}$ are the desired joint angles, and $\alpha_i$ is joint gains.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, &lt;strong&gt;The form of the conventional pseudoinverse&lt;/strong&gt; of the Jocobian added by &lt;strong&gt;the contorol expression&lt;/strong&gt; is Equation 5.28.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\theta = J^+V + (J^+J - I)z \cdot\cdot\cdot\cdot(5.28)\\&#xA;\theta = J^+(V + Jz) -z \\&#xA;\theta = J^T[(JJ^T)^{-1}(V+Jz)] -z&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I could not understand why the book derived the above equation. Because the equation 5.25 is  zero vector, the equation 5.28 of red part($\theta = J^+V + \color{red}{(J^+J - I)z}$) is zero vector and $z$ doesn't have any effect on the result. We just have $\theta = J^+V$, no difference from the real original conventional pseudoinverse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is wrong with me?&lt;/p&gt;&#xA;" OwnerUserId="6806" LastEditorUserId="6" LastEditDate="2017-10-01T15:48:51.317" LastActivityDate="2017-10-02T23:10:49.363" Title="pseudoinverse Jacobian and adding more control in computer animation" Tags="&lt;animation&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5665" PostTypeId="2" ParentId="3713" CreationDate="2017-10-01T15:16:56.470" Score="9" Body="&lt;p&gt;It has been suggested in comments repeatedly, but noone felt the need to give a proper answer, so for the sake of completeness, a straight-forward and common solution to this problem might be to use a &lt;strong&gt;texture as lookup table, specifically a 1D texture that contains all the values of your function for the possible input range&lt;/strong&gt; (i.e. $[0,360)$ / $[0,2\pi)$). This has various advantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It uses normalized coordinates, i.e. you access the texture by mapping your angles from $[0,360]$ to $[0,1]$. This means your &lt;strong&gt;shader doesn't actually have to care about the specific amount of values&lt;/strong&gt;. You can adjust its size according to whatever memory/speed vs. quality tradeoff you want (and especially on older/embedded hardware you might want a power of two as texture size anyway).&lt;/li&gt;&#xA;&lt;li&gt;You get the additional benefit of not having to do your loop-like interval adjustment (although, you wouldn't need loops anyway and could just use a modulus operation). Just use &lt;strong&gt;&lt;code&gt;GL_REPEAT&lt;/code&gt; as wrapping mode for the texture and it will automatically start at the beginning again&lt;/strong&gt; when accessing with arguments &gt; 1 (and similarly for negative arguments).&lt;/li&gt;&#xA;&lt;li&gt;And you also get the benefit of &lt;strong&gt;linearly interpolating between two values in the array&lt;/strong&gt; basically for free (or let's say almost free) by using &lt;code&gt;GL_LINEAR&lt;/code&gt; as texture filter, this way getting values you didn't even store. Of course linear interpolation isn't 100% accurate for trigonometric functions, but it's certainly better than &lt;em&gt;no&lt;/em&gt; interpolation.&lt;/li&gt;&#xA;&lt;li&gt;You can store &lt;strong&gt;more than one value in the texture&lt;/strong&gt; by using an RGBA texture (or however many components you need). This way you can get e.g. sin and cos with a single texture lookup.&lt;/li&gt;&#xA;&lt;li&gt;For sin and cos you only need to store values in $[-1,1]$ anyway, which you can naturally upscale from the normalized $[0,1]$ range of a common 8-bit fixed-point format. However, that might not be enough precision for your needs. Some people suggested using 16-bit floating point values, as they're more precise than the usual 8-bit normalized fixed point values but less memory intensive than real 32-bit floats. But then again, I also don't know if your implementation supports floating point textures to begin with. If not, then maybe you can use 2 8-bit fixed point components and combine them into a single value with something like &lt;code&gt;float sin = 2.0 * (texValue.r + texValue.g / 256.0) - 1.0;&lt;/code&gt; (or even more components for finer grain). This lets you profit from multi-component textures yet again.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Of course it still has to be evaluated if this is a better solution, since texture access isn't &lt;em&gt;entirely&lt;/em&gt; free either, as well as what the best combination of texture size and format would be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to filling the texture with data and adressing one of your comments, you have to consider that texture filtering returns the exact value at the &lt;em&gt;texel center&lt;/em&gt;, i.e. a texture coordinate off by half the texel size. So yes, you should &lt;strong&gt;generate values at &lt;code&gt;.5&lt;/code&gt; texels&lt;/strong&gt;, i.e. something like this in application code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float texels[256];&#xA;for(unsigned int i = 0; i &amp;lt; 256; ++i)&#xA;    texels[i] = sin((i + .5f) / 256.f) * TWO_PI);&#xA;glTexImage1D(GL_TEXTURE_1D, 0, ..., 256, 0, GL_RED, GL_FLOAT, texels);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;You might, however, still want to compare this approach's performance against an approach using a small uniform array (i.e. &lt;code&gt;uniform float sinTable[361]&lt;/code&gt;, or maybe less in practice, keep an eye on your implementation's limit on uniform array size) which you just load with the respective values using &lt;code&gt;glUniform1fv&lt;/code&gt; and access by adjustig your angle to $[0,360)$ using the &lt;code&gt;mod&lt;/code&gt; function and rounding it to the nearest value:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;angle = mod(angle, 360.0);&#xA;float value = sinTable[int(((angle &amp;lt; 0.0) ? (angle + 360.0) : angle) + 0.5)];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2018-03-13T10:54:25.730" LastActivityDate="2018-03-13T10:54:25.730" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5666" PostTypeId="2" ParentId="2029" CreationDate="2017-10-01T16:14:37.520" Score="2" Body="&lt;p&gt;It basically &lt;strong&gt;gives &lt;em&gt;you&lt;/em&gt; control of the semantics of the individual attribute indices&lt;/strong&gt;. This mostly pays off in bigger projects, where you have many different shaders which, however, often use rather common attributes, like e.g. positions or texture coordinates. With explicit attribute locations you can establish a semantic for those attributes and enforce that on &lt;em&gt;all your shaders&lt;/em&gt;, e.g. positions are always in attribute 0, texture coordinates always in attribute 1, ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, this has the advantage of not having to query the attribute index for &lt;em&gt;every shader&lt;/em&gt;. Of course you could query it once and sotre it in e.g. a map from attribute names/semantics to indices, but establishing this beforehand is even better. And it brings us to a much bigger advantage, without explicit attribute binding you &lt;strong&gt;would have to bind vertex arrays of a model to the individual attribute channels not only for each model, but also &lt;em&gt;for each shader&lt;/em&gt;&lt;/strong&gt;, since your position array might go to attribute 0 in one shader and attribute 1 in another one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is not only a huge hassle, but also basically &lt;strong&gt;destroys the advantage of &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Specification#Vertex_Array_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;Vertey Array Objects (VAO)&lt;/a&gt;&lt;/strong&gt;, which are specfically there to capture all the vertex attribute state, including the enabled attribute indices and their buffer sources so that you can draw your object by just binding the VAO and calling a draw function. Without explicit attribute binding you would &lt;em&gt;still&lt;/em&gt; have to reenable/bind the individual arrays at least for each different shader you use. &lt;strong&gt;With explicit attribute binding you know that your model's positions &lt;em&gt;always&lt;/em&gt; go into attribute index 0&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2018-08-08T08:35:00.123" LastActivityDate="2018-08-08T08:35:00.123" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="5667" PostTypeId="2" ParentId="4361" CreationDate="2017-10-01T17:24:39.123" Score="2" Body="&lt;p&gt;You're basically mixing up your spaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at the &lt;a href=&quot;http://doc.qt.io/qt-5/qvector3d.html#unproject&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation for &lt;code&gt;QVector3D::unproject&lt;/code&gt;&lt;/a&gt;, you see that it actually &lt;strong&gt;expects coordinates in &lt;em&gt;window space&lt;/em&gt;&lt;/strong&gt;. And this makes sense, since you explicitly query the viewport (i.e. basically the window's &lt;em&gt;pixel&lt;/em&gt; dimensions) and give that to the function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But with your ratio computation above you already transformed your coordinates from that space into normalized device space, i.e. the $[-1,1]$ square. So this whole computation isn't necessary at all and is already done for you by &lt;code&gt;unproject&lt;/code&gt;. Likewise are the near and far distances from world/eye space not the same in window space, which uses the normalized $[0,1]$ depth range. If we assume that your viewport is your whole window, then all you need to do is put those pixel coordinates you clicked on into &lt;code&gt;unproject&lt;/code&gt; (still accounting for the different Y-convention, though):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;dir = QVector3D(event.x, height()-event.y, 0.);    //in window space 0 = near, 1 = far&#xA;dir = dir.unproject(modelViewMatrix, projectionMatrix, vp);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;A problem is that you &lt;strong&gt;don't easily know the window space coordinates of the camera position&lt;/strong&gt;, since it is in front of the near plane, but the transformation from $[0,1]$ to $[near,far]$ is non-linear. One way to overcome this would be to just unproject a point on the near plane (depth = 0) as origin and the difference to the unproject of that same point on the far plane (depth = 1) as the direction.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;QVector3D near(QVector3D(event.x, height()-event.y, 0.);&#xA;QVector3D far( QVector3D(event.x, height()-event.y, 1.);&#xA;origin = near.unproject(modelViewMatrix, projectionMatrix, vp);&#xA;dir = far.unproject(modelViewMatrix, projectionMatrix, vp) - origin;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Or you compute &lt;code&gt;dir&lt;/code&gt; just the same and don't unproject the origin at all, rather than just transforming the eye-space origin (which is conveniently $\mathbf{0}$) back into model space (assuming your modelview matrix isn't projective, which it really shouldn't be, otherwise don't forget the W-division):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;origin = QVector3D(modelViewMatrix.inverted() * QVector4D(0., 0., 0., 1.));&#xA;//origin = QVector3D(modelViewMatrix.inverted().column(3));    //would work the same&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If your viewport is &lt;em&gt;not&lt;/em&gt; the same as your window dimensions however, you need to fiddle with the mouse coordinates a little more and transform them from the entire window into your viewport rect before unprojecting them. But the point is that &lt;/p&gt;&#xA;&#xA;&lt;h1&gt;&lt;code&gt;unproject&lt;/code&gt; expects window space (i.e. pixel) coordinates.&lt;/h1&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-10-02T10:24:15.617" LastActivityDate="2017-10-02T10:24:15.617" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5668" PostTypeId="2" ParentId="4337" CreationDate="2017-10-01T17:51:19.740" Score="2" Body="&lt;p&gt;You seem to do things more complicatedly than you need to, as adressed in the comments. What you actually want to do is simple the opposite of the normal render flow. Rather than drawing your mesh in world space and mapping the texture into it, &lt;strong&gt;you draw it in texture space and map its vertices onto it&lt;/strong&gt; and let your graphics hardware worry about interpolation. I'll give the general outline here, as I honestly don't know the actual DirectX terms for the stuff here, but it should be easy to map onto real HLSL if you know your way around DirectX (which I'm sure you do when messing with Compute Shaders).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You basically render into your output texture using an offscreen render target. You then render your mesh using its texture coordinates as positions rather than its model space vertices, which you just pass through to the pixel shader, where you finally transform them into screen space and write out as the pixel's colour:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[Vertex Shader]&#xA;&#xA;PER VERTEX float2 uv;&#xA;PER VERTEX float4 v_point;&#xA;&#xA;TO PS float4 modelPos;&#xA;&#xA;void VSMain() {&#xA;    CLIP_POSITION = uv;&#xA;    modelPos = v_point;&#xA;}&#xA;&#xA;[Pixel Shader]&#xA;&#xA;CONSTANT float4x4 MVP;&#xA;CONSTANT float2 viewportSize;&#xA;&#xA;FROM VS float4 modelPos;&#xA;&#xA;void PSMain() {&#xA;    float4 clipPos = MVP * modelPos;&#xA;    float3 ndcPos = clipPos.xyz / clipPos.w;&#xA;    float3 screenPos = float3(viewportSize * (screePos.xy * 0.5 + float2(0.5)), ndcPos.z);&#xA;    OUT_COLOR = screenPos;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Feel free to adjust this to the realities of proper DirectX screen-space transformations and matrix multiplication orders, but the general idea should be clear.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2017-10-01T17:51:19.740" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5669" PostTypeId="2" ParentId="1835" CreationDate="2017-10-01T19:18:10.423" Score="2" Body="&lt;p&gt;As suggested in the comments, there's a few ways you might be able to reduce the geometry before merging it into the big mesh and sending it out for drawing.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;First of all, you might &lt;strong&gt;not want to draw cubes that are hidden behind other cubes&lt;/strong&gt;. While this is not a trivial thing to check, it becomes easier when we at least try to limit it to &lt;strong&gt;cubes that are on the outer surface of the terrain&lt;/strong&gt; and the cubes are laid out in a &lt;strong&gt;regular grid&lt;/strong&gt;. In this case you first of all make a regular grid storing a boolean flag for each coordinate where there's a cube. Then all you need to do is walk over that array and for each active cell check its neighbours' flags and only add it to the geometry when it doesn't have all 6 face-neighbours active too. You can even optimize this by checking only the 3 neighbours in the direction of the camera.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Another thing you can do is &lt;strong&gt;frustum culling&lt;/strong&gt;, basically ignoring all cubes that are not inside the actual view volume, which amounts to just checking the cubes against the 6 planes of the viewing frustum.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What you also could do is perform basic &lt;strong&gt;backface culling&lt;/strong&gt; yourself, and only adding the geometry of the 3 cube faces that actually face the camera (or better yet, combining it with the first point, the ones facing the camera and not having an active neighbour).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;But all this only reduces the amount of geometry that you are generating and sending over for drawing. It does &lt;em&gt;not&lt;/em&gt; do anything for reducing the actual computation you do to generate that geometry (rather on the contrary actually). It is not clear what exactly it is that's causing your script to take too long or acquire too many resources but I also don't know anything about Javascript or Ajax or whatever specific web-stuff you're doing.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Maybe it's possible to delegate all this to some kind of &lt;strong&gt;background task that doesn't block&lt;/strong&gt; the main process. This way you might also be able to &lt;strong&gt;process the whole file in smaller batches&lt;/strong&gt;, generating parts of the whole geometry and updating the display whenever you generated another batch.&lt;/li&gt;&#xA;&lt;li&gt;The above method &lt;em&gt;might&lt;/em&gt; help to reduce overall memory consumption &lt;em&gt;if&lt;/em&gt; the amount of actually generated geometry is much less than those 11M cubes from the file and if the regular grid isn't too large either. But you actually only need 1 bit for every grid cell, making just 2MB for 256^3 grid and 128 MB for a 1024^3 grid. You might further reduce this by &lt;strong&gt;tiling the grid space into smaller sub grids and processing these each&lt;/strong&gt;. However, this might require you to traverse the terrain file multiple times if that isn't already sorted appropriately.&lt;/li&gt;&#xA;&lt;li&gt;Which brings us to the possibility of simply &lt;strong&gt;restructuring your input file format&lt;/strong&gt; to better facilitate any of the above methods, like already sorting your cubes into spatial subgrids, or even storing a full boolean grid rather than a compact list of coordinates.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This all really depends on &lt;em&gt;what&lt;/em&gt; the bottleneck is here. But it should give you some general ideas of how you could approach this for optimization.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-10-01T20:39:57.980" LastActivityDate="2017-10-01T20:39:57.980" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5671" PostTypeId="2" ParentId="5664" CreationDate="2017-10-02T11:57:02.027" Score="1" Body="&lt;p&gt;I think I found your misunderstanding, but it's IMHO based on a little inconsistency (or at least lack of clarity) in the book.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;But, the θ is always zero vector because J+J=I, so θ=0z.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is not true, $J^+J$ is not necessarily $I$. $JJ^+=I$ but the &lt;strong&gt;multiplication by the pseudoinverse is &lt;em&gt;not&lt;/em&gt; commutative&lt;/strong&gt;. Let's look at this in more detail:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$JJ^+ = JJ^T(JJ^T)^{-1}= (JJ^T)(JJ^T)^{-1} = I$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$J^+J = J^T(JJ^T)^{-1}J = ?$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The underlying misunderstanding comes from the assumption that the matrices $J^T(JJ^T)^{-1}$ and $(J^TJ)^{-1}J^T$ are equal (since the latter &lt;em&gt;would&lt;/em&gt; produce $I$ if right-multiplied by $J$), which is &lt;em&gt;not&lt;/em&gt; true. They are &lt;strong&gt;both pseudoinverses of $J$ but they are not necessarily the same matrices&lt;/strong&gt;, in fact they don't necessarily both &lt;em&gt;exist&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the book says, the $(JJ^T)^{-1}$ only exists if the &lt;em&gt;rows&lt;/em&gt; of $J$ are linearly independent, and in turn &lt;a href=&quot;https://en.wikipedia.org/wiki/Moore%E2%80%93Penrose_pseudoinverse#Definition&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt; says that $(J^TJ)^{-1}$ exists if the &lt;em&gt;columns&lt;/em&gt; of $J$ are linearly independent. However, they can't both exist if the matrix is not square, since one of the dimensions would necessarily have more vectors than the dimension, which can't all be linearly independent. Specifically, for a normal redundant joint system you probably have &lt;strong&gt;more columns than rows, making only the pseudoinverse $J(JJ^T)^{-1}$ exist&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can, however, see that for a square matrix they are indeed the same and actually the real inverse:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$J^T(JJ^T)^{-1} = J^TJ^{-T}J^{-1} = (J^{-1}J)^TJ^{-1} = I^TJ^{-1} = J^{-1}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(J^TJ)^{-1}J^T = J^{-1}J^{-T}J^T = J^{-1}(JJ^{-1})^T = J^{-1}I^T = J^{-1}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(But in that case the system would have a unique solution and there's no point to angle control anyway.) But you cannot resolve the brackets with a non-square matrix, since the &lt;strong&gt;individual matrices aren't square and don't have an actual inverse&lt;/strong&gt;. The only situation when &lt;strong&gt;both matrices &lt;em&gt;exist&lt;/em&gt; are square $J$s&lt;/strong&gt; and then they are indeed &lt;strong&gt;equal, but then there's also no point to angle control&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I understand why you are confused and I am a little, too, since Parent actually seems to use the &lt;em&gt;alleged&lt;/em&gt; identity $J^T(JJ^T)^{-1}=(J^TJ)^{-1}J^T$ in equation 5.20, where he derives the pseudoinverse's relevance for solving the inverse kinematics problem. He computes everything with the &lt;em&gt;left inverse&lt;/em&gt; but than concludes with using the &lt;em&gt;right inverse&lt;/em&gt;. I guess that works conceptually because they're both pseudoinverses, even if it doesn't make complete mathematical sense (to me and you at least). He seemed to have used the assumption of a square matrix as a trick for transforming the problem and then used the conclusion for a non-square matrix, which &lt;em&gt;might&lt;/em&gt; be conceptually correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess it simply &lt;strong&gt;doesn't matter &lt;em&gt;which&lt;/em&gt; of the two pseudoinverses we use, since only &lt;em&gt;one&lt;/em&gt; of them ever exists&lt;/strong&gt; (for a non-square Jacobian) anyway and if the left inverse &lt;em&gt;would&lt;/em&gt; exist (making your above assumption true), that means you have more constraints than DoF and thus your system is overconstrained and there's no point in angle control.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-10-02T22:24:58.050" LastActivityDate="2017-10-02T22:24:58.050" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5672" PostTypeId="1" AcceptedAnswerId="5673" CreationDate="2017-10-02T14:17:47.420" Score="6" ViewCount="211" Body="&lt;p&gt;In a project where I want to select visible objects using using a screen-aligned polygon and various conditions for what &quot;selected&quot; means with regards to that polygon, I'm basically drawing the polygon into the stencil buffer and then drawing the individual objects with &lt;strong&gt;stencil testing and using occlusion queries&lt;/strong&gt; for measuring how much the object and selection polygon overlap in screen space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This works pretty well. But imagine my surprise when stumbling over the statement that, &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Query_Object#Occlusion_queries&quot; rel=&quot;nofollow noreferrer&quot;&gt;according to the OpenGL Wiki&lt;/a&gt;, occlusion queries supposedly don't actually care about the stencil test:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;They detect whether the scoped drawing commands pass the depth test and if so, how many samples in those triangles passed the Depth Test. Note that the sample count and pass/fail are &lt;strong&gt;based only on the depth test. The Stencil Test, or fragment shader discard is irrelevant&lt;/strong&gt; with queries, even though they technically happen after the fragment shader...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This clearly contradicts my practical experience and made me a little worried/confused. I took a look at the specification (both the newest 4.6 core as well as good old 2.0, which we're actually targetting in our project for compatibility) and it also says that occlusion queries count the number of &lt;strong&gt;samples passing the depth test&lt;/strong&gt;. It does however not make such a definite statement as the wiki pertaining to the stencil test. And since the &lt;strong&gt;depth test technically comes &lt;em&gt;after&lt;/em&gt; the stencil test&lt;/strong&gt;, I'm not entirely sure if that maybe already includes the stencil test anyway and the wording of the specification is simply using the last stage for convenience.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, my question is, &lt;em&gt;do&lt;/em&gt; occlusion queries respect the stencil test (or any other earlier per-fragment tests, I'm actually using scissor testing with occlusion queries in another unrelated algorithm)? I see a few possiblities here:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;They &lt;em&gt;do definitely&lt;/em&gt; respect all tests and the wording in the spec is just using the last test for convenience reasons. This would mean that &lt;strong&gt;fragments failing earlier tests and thus not even &lt;em&gt;reaching&lt;/em&gt; the depth test would technically count as &lt;em&gt;failing&lt;/em&gt; that&lt;/strong&gt;. I'm not sure this comes too clearly out of the specification's wording, though, but maybe I'm missing something and people better-versed in the intricacies of specification laywering can shed more light on this. This would also mean the above Wiki article is slightly misleading (or I just misread it).&lt;/li&gt;&#xA;&lt;li&gt;They &lt;em&gt;definitely don't&lt;/em&gt; respect the stencil test and really only care about the depth test. This would mean that a &lt;strong&gt;fragment failing the stencil test would have to still go through depth testing&lt;/strong&gt;. It would also mean that what I experience on my specific hardware (it's an nVidia GeForce GTX 1xxx) is clearly a bug.&lt;/li&gt;&#xA;&lt;li&gt;Or this might simply not be a well-specified part of the API and it leaves room for interpretation. This might be rather odd, though, as this isn't a particularly rarely used feature I'd suppose.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;(In practice, I could definitely restrucure my algorithm to use depth testing instead, but it is a problem that makes me curious about the theoretic implications and underpinnings nevertheless.)&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-10-02T19:09:00.113" LastActivityDate="2019-04-03T17:21:41.760" Title="Do occlusion queries respect the stencil test at all?" Tags="&lt;opengl&gt;&lt;stencil-test&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5673" PostTypeId="2" ParentId="5672" CreationDate="2017-10-02T15:34:51.003" Score="4" Body="&lt;p&gt;The specification &lt;a href=&quot;https://github.com/KhronosGroup/OpenGL-API/issues/19&quot; rel=&quot;nofollow noreferrer&quot;&gt;has been clarified on this point&lt;/a&gt;, as has the Wiki article. So let's explain that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The new wording in the spec says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the samples-passed count is incremented for each fragment still being processed after the depth test&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is better wording, as it makes clear that the order in which things are processed matters. OpenGL &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Per-Sample_Processing&quot; rel=&quot;nofollow noreferrer&quot;&gt;defines the depth test as happening after the stencil test, scissor test, etc&lt;/a&gt;. So this wording clearly states that the depth test, and everything before it, matter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it does respect the stencil test. And fragment shader &lt;code&gt;discard&lt;/code&gt;, since the FS is specified to come before all of these tests.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well, unless you &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Early_Fragment_Test#Explicit_specification&quot; rel=&quot;nofollow noreferrer&quot;&gt;force these tests to happen before the fragment shader&lt;/a&gt;. If you do that, then &lt;code&gt;discard&lt;/code&gt;ing the fragment in the FS will not prevent that fragment from being counted by the occlusion query. So if you enforce early tests, you lose the right to use &lt;code&gt;discard&lt;/code&gt; to affect the occlusion query count.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2019-04-03T17:21:41.760" LastActivityDate="2019-04-03T17:21:41.760" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="5676" PostTypeId="1" CreationDate="2017-10-03T22:55:59.197" Score="1" ViewCount="251" Body="&lt;p&gt;I am creating a 2D CAD drawing generator in C# using .netDXF library. Given a area I want to fill it with rectangles/circles (convex). For example, the regions marked with numbers in below image. This is just an example, the pattern may change.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'am not an expert in the area of graphics. What should be my approach to this problem? Is there any algorithm that I can follow? What would be a generalized (not specific to .netDXF) way to fill an irregular region with 2D shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gSzNA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gSzNA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7413" LastActivityDate="2017-12-03T15:03:01.487" Title="Fill an irregular region with 2D shapes" Tags="&lt;vector-graphics&gt;&lt;polygon&gt;&lt;2d-graphics&gt;&lt;cad&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5677" PostTypeId="2" ParentId="5676" CreationDate="2017-10-04T13:31:46.130" Score="1" Body="&lt;p&gt;There is no general algorithm for packing problems. Only some of the special cases have known, and optimal, solutions. If you are packing one shape then finding a reasonable solution is possible. Like the known cases of hexagonal packing etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you have multiple diffenently sized objects then easy just flew out of the door. Some heurestics have been developed, since there is a very big demand for such algorithms in manufacturing. But they are not usually very fast (performant?) or simple to implement. Many of them use a genetic algorithm. A free one that you may test can be found at&lt;a href=&quot;http://svgnest.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;svgnest.com&lt;/a&gt; but faster ones and ones working on shaking and collision also exist.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway your question is sufficiently vague, so i dont actually know if&#xA; you want to do packing. I mean it is perfectly possible you mean tiling, which is pretty trivial.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-10-04T13:31:46.130" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5678" PostTypeId="1" CreationDate="2017-10-04T14:10:51.743" Score="2" ViewCount="119" Body="&lt;p&gt;I recently finished the base implementation of a DX12 rederer and I started to think in ways of improving the performance. I think that one problem that my implementation has, is memory fragmentation, as I mostly perform &quot;single&quot; allocations for my resources. During run-time some resources are deleted and recreated which I guess will cause even more memory frag. There are quite a few articles online about writing system memory managers but I've never encountered something like that for video memory and GPU resources. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone explain the basics of a system like this? &#xA;Thanks!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;I had this link laying around: &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/mt613239(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;Memory Management in Direct3D 12 | Windows Dev Center&lt;/a&gt;. That gives some good general information about the topic.&lt;/p&gt;&#xA;" OwnerUserId="7107" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:34:05.677" LastActivityDate="2018-03-04T00:34:05.677" Title="Handling GPU resource management" Tags="&lt;gpu&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5679" PostTypeId="1" AcceptedAnswerId="5715" CreationDate="2017-10-04T17:58:25.343" Score="2" ViewCount="295" Body="&lt;p&gt;&lt;strong&gt;Spotlight&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My spotlight's intensity is cut off at a distance of 3 and at an angle of $\pi/4$ radians (umbra angle). The corresponding light camera has a near plane at a distance of 0.1, a far plane at a distance of 3, an aspect ratio of 1 and a vertical/horizontal FOV of $\pi/2$. The spotlight is positioned somewhere above the tree and faces downward to the floor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shadow map of my spotlight has a resolution of 512x512. I use the following DXGI formats:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;DXGI_FORMAT_R16_TYPELESS&lt;/code&gt;: texture resource;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;DXGI_FORMAT_D16_UNORM&lt;/code&gt;: DSV (one for each spotlight);&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;DXGI_FORMAT_R16_UNORM&lt;/code&gt;: SRV (one &lt;code&gt;Texture2DArray&lt;/code&gt; for all, spotlights).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My shadow factor is calculated in HLSL as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/**&#xA; Calculates the shadow factor.&#xA;&#xA; @pre           @a shadow_maps must contain a shadow map at index @a index.&#xA; @param[in]     pcf_sampler&#xA;                The PCF sampler comparison state.&#xA; @param[in]     shadow_maps&#xA;                The array of shadow maps.&#xA; @param[in]     index&#xA;                The index into the array of shadow maps.&#xA; @param[in]     p_proj&#xA;                The hit position in light projection space coordinates.&#xA; */&#xA;float ShadowFactor(SamplerComparisonState pcf_sampler,&#xA;    Texture2DArray&amp;lt; float &amp;gt; shadow_maps, uint index,&#xA;    float4 p_proj) {&#xA;&#xA;    const float  inv_w  = 1.0f / p_proj.w;&#xA;    const float3 p_ndc  = p_proj.xyz * inv_w;&#xA;    const float3 loc    = float3(NDCtoUV(p_ndc.xy), index);&#xA;&#xA;    return shadow_maps.SampleCmpLevelZero(pcf_sampler, loc, p_ndc.z);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here, the hit position in light projection space coordinates is calculated as follows from the hit position in camera view space coordinates (shading space):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const float4 p_proj = mul(float4(p, 1.0f), light.cview_to_lprojection);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I obtain the following images after visualizing the shadow factor (&lt;em&gt;this is not the light contribution of the spotlight&lt;/em&gt;) (and some linear fog as well):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8Al0D.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8Al0D.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/DW86m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DW86m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems to result in the correct behavior (see the shadows of the leaves, pillars and curtains). &lt;em&gt;The bright border on the first image starts at the position of the spotlight and is due to the near plane distance of 0.1. This border will completely vanish after multiplying the shadow factor with the spotlight's contribution.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Omni light&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My omni light's intensity is cut off at a distance of 3. The corresponding light camera has a near plane at a distance of 0.1, a far plane at a distance of 3, an aspect ratio of 1 and a vertical/horizontal FOV of $\pi/2$. This means that one of the six light cameras (after applying some rotations), is completely identical to the spotlight camera above. I double checked this in the code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Frame 1: &#xA;&lt;code&gt;world_to_lprojection&lt;/code&gt; (spotlight):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1.16532457,  0.000000000, 0.000000000, 0.000000000&#xA;0.000000000, -2.18211127e-07, -1.03448260, -0.999999881&#xA;0.000000000, 1.83048737, -1.23319950e-07, -1.19209290e-07&#xA;0.000000000, 4.36422255e-07, 1.96551692, 1.99999976&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;world_to_lprojection&lt;/code&gt; (fourth omni light camera):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1.16532457, 0.000000000, 0.000000000, 0.000000000&#xA;0.000000000, -2.18211127e-07, -1.03448260, -0.999999881&#xA;0.000000000, 1.83048737, -1.23319950e-07, -1.19209290e-07&#xA;0.000000000, 4.36422255e-07, 1.96551692, 1.99999976&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;world_to_lprojection&lt;/code&gt; represents the world-to-light-projection transformation matrix (&lt;em&gt;world-to-camera-view-to-world-to-light-view-to-light-projection&lt;/em&gt;). &lt;em&gt;I go to camera view first to mimic the same multiplications between my depth passes and shading passes to reduce z-fighting (although, this does not result in visual differences so far).&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So apart from the fact that a spotlight corresponds to one DSV (and is part of one SRV to a &lt;code&gt;Texture2DArray&lt;/code&gt; for all spotlight shadow maps) and an omni light corresponds to six DSVs (and is part of one SRV to a &lt;code&gt;Texture2DCubeArray&lt;/code&gt; for all omni light shadow cube maps), the shadow map generation is pretty much the same for both types of lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shadow map of my omni light has a resolution of 512x512. I use the following DXGI formats:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;DXGI_FORMAT_R16_TYPELESS&lt;/code&gt;: texture resource;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;DXGI_FORMAT_D16_UNORM&lt;/code&gt;: DSV (one for each omni light);&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;DXGI_FORMAT_R16_UNORM&lt;/code&gt;: SRV (one &lt;code&gt;Texture2DCubeArray&lt;/code&gt; for all, omni lights).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My shadow factor is calculated in HLSL as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/**&#xA; Calculates the shadow factor.&#xA;&#xA; @pre           @a shadow_maps must contain a shadow cube map at index @a index.&#xA; @param[in]     pcf_sampler&#xA;                The PCF sampler comparison state.&#xA; @param[in]     shadow_maps&#xA;                The array of shadow cube maps.&#xA; @param[in]     index&#xA;                The index into the array of shadow cube maps.&#xA; @param[in]     p_view&#xA;                The hit position in light view space coordinates.&#xA; @param[in]     projection_values&#xA;                The projection values [view_projection22, view_projection32].&#xA; */&#xA;float ShadowFactor(SamplerComparisonState pcf_sampler, &#xA;    TextureCubeArray&amp;lt; float &amp;gt; shadow_maps, uint index,&#xA;    float3 p_view, float2 projection_values) {&#xA;&#xA;    const float p_view_z = Max(abs(p_view));&#xA;    const float p_ndc_z  = ViewZtoNDCZ(p_view_z, projection_values);&#xA;    const float4 loc     = float4(p_view, index);&#xA;&#xA;    return shadow_maps.SampleCmpLevelZero(pcf_sampler, loc, p_ndc_z);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here, the hit position in light view space coordinates is calculated as follows from the hit position in camera view space coordinates (shading space):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const float3 p_view = mul(float4(p, 1.0f), light.cview_to_lview).xyz;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The conversion of the z coordinate to NDC space is done as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/**&#xA; Converts the given (linear) view z-coordinate to the (non-linear) NDC &#xA; z-coordinate.&#xA;&#xA; @param[in]     p_view_z&#xA;                The (linear) view z-coordinate.&#xA; @param[in]     projection_values&#xA;                The projection values [view_projection22, view_projection32].&#xA; @return        The (non-linear) NDC z-coordinate.&#xA; */&#xA;float ViewZtoNDCZ(float p_view_z, float2 projection_values) {&#xA;    return projection_values.x + projection_values.y / p_view_z;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with the following dual C++ method:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/**&#xA; Returns the projection values from the given projection matrix to construct &#xA; the NDC position z-coordinate from the view position z-coordinate.&#xA;&#xA; @return        The projection values from the given projection matrix to &#xA;                construct the NDC position z-coordinate from the view position &#xA;                z-coordinate.&#xA; */&#xA;inline const XMVECTOR XM_CALLCONV GetNDCZConstructionValues(&#xA;    FXMMATRIX projection_matrix) noexcept {&#xA;&#xA;    //        [ _  0  0  0 ]&#xA;    // p_view [ 0  _  0  0 ] = [_, _, p_view.z * X + Y, p_view.z] = p_proj&#xA;    //        [ 0  0  X  1 ]&#xA;    //        [ 0  0  Y  0 ]&#xA;    //&#xA;    // p_proj / p_proj.w     = [_, _, X + Y/p_view.z, 1] = p_ndc&#xA;    //&#xA;    // Construction of p_ndc.z from p_view and projection values&#xA;    // p_ndc.z = X + Y/p_view.z&#xA;&#xA;    const F32 x = XMVectorGetZ(projection_matrix.r[2]);&#xA;    const F32 y = XMVectorGetZ(projection_matrix.r[3]);&#xA;&#xA;    return XMVectorSet(x, y, 0.0f, 0.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I obtain the following images after visualizing the shadow factor (this is not the light contribution of the omni light) (and some linear fog as well):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hQ0sB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hQ0sB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/zedO9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zedO9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is clearly wrong. All six shadow maps seem kind of &lt;strong&gt;stretched&lt;/strong&gt;. Without the stretching, the curtain's shadow would still be in the close vicinity of the curtain itself and the leaves' shadow would be much smaller (equal to the leaves' shadow for the spotlight). Furthermore, the circular shadow at the end of the pillar's shadow is associated to the buckets in front of the curtains.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas what goes or could go wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For clarity, the following two images show the shadow factor of the cube map face corresponding to the spotlight, for the omni light by adding:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (p_view_z != -p_view.y) {&#xA;    return 0.0f;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4B8dZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4B8dZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/T4oQV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/T4oQV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The lit area seems a bit (how much?) larger than for the spotlight.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;SampleCmpLevelZero&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An other strange observation is that using a depth value of 1.1 for my spotlight's PCF filtering (&lt;code&gt;SampleCmpLevelZero&lt;/code&gt;) always results in a 0 value as expected:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/49GZW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/49GZW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;whereas for my omni light this is not the case:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9vBBr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9vBBr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if I use a value equal to 100000.0, I'll notice lit areas?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Depth Biasing&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use &lt;code&gt;DepthBias = 100;&lt;/code&gt; (to prevent shadow acne; note that I use 16bit depth maps) &lt;code&gt;SlopeScaledDepthBias = 0.0f; DepthBiasClamp = 0.0f;&lt;/code&gt; for all my Rasterizer states.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;PCF filtering&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use the following sampler comparison state for PCF filtering (&lt;em&gt;my shadow maps have no mipmaps&lt;/em&gt;) for both spotlights and omni lights. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_SAMPLER_DESC desc = {};&#xA;desc.Filter         = D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT;&#xA;desc.AddressU       = D3D11_TEXTURE_ADDRESS_BORDER;&#xA;desc.AddressV       = D3D11_TEXTURE_ADDRESS_BORDER;&#xA;desc.AddressW       = D3D11_TEXTURE_ADDRESS_BORDER;&#xA;desc.MaxAnisotropy  = (device-&amp;gt;GetFeatureLevel() &amp;gt; D3D_FEATURE_LEVEL_9_1) &#xA;                                ? D3D11_MAX_MAXANISOTROPY : 2;&#xA;desc.MaxLOD         = D3D11_FLOAT32_MAX;&#xA;desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-10-08T14:47:52.287" LastActivityDate="2017-10-11T17:02:41.413" Title="Artifacts in omni light shadow mapping" Tags="&lt;hlsl&gt;&lt;shadow-mapping&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5680" PostTypeId="1" CreationDate="2017-10-04T18:25:19.453" Score="6" ViewCount="1686" Body="&lt;p&gt;In the SIGGRAPH course: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;BURLEY B.: Physically Based Shading at Disney, SIGGRAPH 2012 Course: Practical Physically Based Shading in Film and Game Production, 2012.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;it is mentioned that some BRDF models include a diffuse Fresnel factor such as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(1-F(\theta_l)) (1-F(\theta_d)).$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Disney BRDF itself uses the following diffuse BRDF component (using Sclick's Fresnel approximation):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_d = \frac{\textrm{c_base}}{\pi} (1 + (F_{\textrm{D90}} - 1)(1-\cos\theta_l)^5) (1 + (F_{\textrm{D90}} - 1)(1-\cos\theta_v)^5),$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$F_{\textrm{D90}} = 0.5 + 2 \text{roughness} \cos^2\theta_d. $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where does this come from? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My attempt...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I evaluate $(1-F(\theta_l)) (1-F(\theta_v))$ (instead of $(1-F(\theta_l)) (1-F(\theta_d))$?) with Schlick's approximation, we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\left(1-(F_0 + (1-F_0)(1-\cos\theta_l)^5)\right) \left(1-(F_0 + (1-F_0)(1-\cos\theta_v)^5)\right)$$&#xA;$$\left(1-F_0 + (F_0-1)(1-\cos\theta_l)^5\right) \left(1-F_0 + (F_0-1)(1-\cos\theta_v)^5\right)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we substitute $F_{\textrm{D90}} = F_0$, we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\left(1-F_{\textrm{D90}} + (F_{\textrm{D90}}-1)(1-\cos\theta_l)^5\right) \left(1-F_{\textrm{D90}} + (F_{\textrm{D90}}-1)(1-\cos\theta_v)^5\right)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This looks similar except for the 2x $-F_{\textrm{D90}}$? Is my reasoning completely wrong or where do I make mistakes? Or am I not aware of some further (common) approximations?&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-10-22T09:05:12.230" LastActivityDate="2017-10-22T09:05:12.230" Title="Diffuse BRDF component of the Disney BRDF" Tags="&lt;brdf&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5681" PostTypeId="2" ParentId="5678" CreationDate="2017-10-04T19:59:18.963" Score="3" Body="&lt;p&gt;Whenever there's too much churn of things being created and destroyed, regardless of the specifics of the situation, a common way to dealing with this is to make free object pools.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How these work is when you are done using something, instead of actually freeing or destroying it, you put it back into a list or array of &quot;free objects&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you need a new object of a specific type, you check the object pool to see if there's a free one lying around.  If there isn't one there, you create a new one the &quot;expensive&quot; way and use it.  When you are done with it, you put it in the free pool for use in the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A possible issue with free object pools is that you may have a spike in objects for some reason and then you are left with a ton of unused objects sitting in a free pool that will never be needed again.  In situations like this, you can keep track of how long (in number of frames for instance) since an object was last used, and if they get over a certain unused age, free them from the object pool.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS - make sure and profile your code to find what the ACTUAL performance bottlenecks are before attempting to solve problems.  Optimizing without profiling before (to find the problem) and after (to verify you improved things, and knowing by how much) won't get you very far (:&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-10-04T19:59:18.963" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5682" PostTypeId="1" AcceptedAnswerId="5687" CreationDate="2017-10-05T04:00:54.277" Score="6" ViewCount="2218" Body="&lt;p&gt;I'm trying to generate an image where black dots are arranged in a blue noise distribution on a white background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that there are other ways to do this, one of the best being &quot;Fast Capacity Constrained Voronoi Tessellation.&quot; [&lt;a href=&quot;https://www.microsoft.com/en-us/research/publication/fast-capacity-constrained-voronoi-tessellation/&quot; rel=&quot;noreferrer&quot;&gt;Hongwei 09&lt;/a&gt;], but I'm using Mitchell's best candidate algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This algorithm works by generating $N$ random pixel locations as candidates for where the next black pixel should go and chooses the candidate which has the farthest distance to the nearest black pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've implemented this and have used it to put 455 black pixels on a 64x64 image, using various candidate counts.  Looking at the DFT (frequency magnitude, not phase) of the results, I'm seeing some unexpected frequency data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zCTZO.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zCTZO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Strangely, I never get that &quot;nice concentric rings&quot; DFT frequency amplitude that i'd expect and see in papers regarding blue noise sample patterns.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are these results expected?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Manually hunting between 100 and 1000 samples, it seems like 400 is pretty near optimal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NytDe.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NytDe.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/mtrOr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mtrOr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some &quot;sweet spot&quot; for the number of candidates to use based on image size and desired sample (black pixel) count to get the best result?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2020-07-29T17:30:36.030" Title="Mitchell's Best Candidate Algorithm" Tags="&lt;sampling&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5683" PostTypeId="2" ParentId="5682" CreationDate="2017-10-05T07:19:55.487" Score="3" Body="&lt;p&gt;Another very simple, easy to implement, algorithm to generate a Poisson-disk/blue noise point distribution is the following one [ 1 ]: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Decide a radius &lt;strong&gt;&lt;em&gt;r&lt;/em&gt;&lt;/strong&gt;, and therefore the expected number &lt;em&gt;N&lt;/em&gt; of samples per area (use the formula for maximum packing density of &lt;em&gt;k&lt;/em&gt; disks distributed on a toroidal domain see [ 2 ]) &lt;/li&gt;&#xA;&lt;li&gt;Generate 10~20 x &lt;em&gt;N&lt;/em&gt; samples in your area using a plain unbiased montecarlo sampling&lt;/li&gt;&#xA;&lt;li&gt;Until all samples respect poisson disk condition:&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;randomly choose a sample &lt;strong&gt;&lt;em&gt;p&lt;/em&gt;&lt;/strong&gt; &lt;/li&gt;&#xA;&lt;li&gt;remove all the samples at distance lower than &lt;strong&gt;&lt;em&gt;r&lt;/em&gt;&lt;/strong&gt; from &lt;strong&gt;&lt;em&gt;p&lt;/em&gt;&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Eventually step 3 can be furtherly iterated a small number of times choosing the sample with minimal number of surviving samples within distance r.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find an implementation of this algorithm in MeshLab.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[ 1 ] &lt;a href=&quot;http://vcg.isti.cnr.it/Publications/2012/CCS12/&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;Efficient and Flexible Sampling with Blue Noise Properties of Triangular Meshes&lt;/strong&gt;&lt;br&gt;&#xA;&lt;em&gt;Massimiliano Corsini, Paolo Cignoni, Roberto Scopigno&lt;/em&gt;&lt;br&gt;&#xA;IEEE Transaction on Visualization and Computer Graphics, Volume 18, Number 6, page 914--924 - 2012&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[ 2 ] &lt;a href=&quot;https://lirias.kuleuven.be/handle/123456789/176251&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;A comparison of methods for generating Poisson disk distributions&lt;/strong&gt;&lt;br&gt;&#xA; &lt;em&gt;Ares Lagae, Philip Dutré,&lt;/em&gt;&lt;br&gt;&#xA;Computer Graphics Forum vol:27 issue:1 , 2008&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7425" LastActivityDate="2017-10-05T07:19:55.487" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5684" PostTypeId="1" AcceptedAnswerId="5705" CreationDate="2017-10-05T09:51:05.740" Score="3" ViewCount="146" Body="&lt;p&gt;I need to highlight(colour) sun reflections(through the year) off a mirror surface. It was easy having one Sun like in the below image but how about if it is to determine if a ray hits the entire surface that represents sun positions throughout the year.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;:&lt;/p&gt;&#xA;&lt;p&gt;Suppose the house surfaces are all mirror, so that from specific angles the viewer might see the reflection of the sun off the house surfaces. this is easy to render an image that simulate this but how about rendering an image that shows the reflection of not just one Sun, in a specific day time, but all the Suns, one for every second throughout the year. It's not efficient to dump in all these Suns into model and intersect them for each surface point. So I need to check if a ray intersects the entire surface that represents the path of the sun throughout the year.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/S7EU4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S7EU4.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-03-04T19:55:58.710" Title="Ray intersection with Sun positions throughout the year" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5685" PostTypeId="1" AcceptedAnswerId="5689" CreationDate="2017-10-05T13:22:25.087" Score="1" ViewCount="128" Body="&lt;p&gt;&lt;a href=&quot;https://soulsphere.org/apocrypha/bsp/&quot; rel=&quot;nofollow noreferrer&quot;&gt;This&lt;/a&gt; article says that binary space partitioning divides the map into convex polygons.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;[...]&lt;br&gt;&#xA;  Before the map can be rendered we must perform a number of&#xA;  calculations on it. However, once these calculations are performed&#xA;  their results can be used many times. This is one of the advantages of&#xA;  BSP — once the calculations are performed they do not need to be done&#xA;  again, unless the map is changed. BSP only allows ”static” maps, or&#xA;  ones that do not move. If a map has any moving parts then they must be&#xA;  rendered separately.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;What must be done is to partition, or divide up, &lt;strong&gt;the map into convex&#xA;  polygons&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Why should non-convex polygons be partitioned into convex polygons? Is there a mathematical basis behind this?&lt;/p&gt;&#xA;" OwnerUserId="6207" LastActivityDate="2017-10-06T05:25:48.573" Title="Why do we have to partition non-convex polygons into convex polygons in a map in Binary Space Partitioning?" Tags="&lt;rendering&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5686" PostTypeId="2" ParentId="5685" CreationDate="2017-10-05T15:18:08.323" Score="3" Body="&lt;p&gt;Because with 2 non-overlapping convex polygons you can always say that 1 polygon is closer to a point than another.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If they are not convex then for example with a U surrounding a circle. You cannot say easily which should be drawn first.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-10-05T15:18:08.323" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5687" PostTypeId="2" ParentId="5682" CreationDate="2017-10-05T19:28:30.110" Score="3" Body="&lt;p&gt;The problem turned out to be that you don't do the same number of candidates per point, but that if you have &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; points already, you should generate &lt;span class=&quot;math-container&quot;&gt;$m*n$&lt;/span&gt; candidates for the next point.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; is a tuneable parameter where in general higher values of &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; will take longer to calculate, but will result in higher quality sampling.&lt;/p&gt;&#xA;&lt;p&gt;The reason that the candidate count should scale with the existing sample count is that it keeps statistics about the points constant, so lets you reason about how higher sample counts will look / behave by looking at lower sample counts.&lt;/p&gt;&#xA;&lt;p&gt;Values of &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; that are too high will end up looking like the lower images of the question though, where the randomness is almost completely gone.&lt;/p&gt;&#xA;&lt;p&gt;The problem with the high sample counts is that they more fully cover all possible pixel locations, and since the best candidate is chosen, much randomness will go away leaving you with something a lot more deterministic.&lt;/p&gt;&#xA;&lt;p&gt;I personally choose to do &lt;span class=&quot;math-container&quot;&gt;$m*n+1$&lt;/span&gt; samples to slightly simplify the logic and let it handle the first sample when &lt;span class=&quot;math-container&quot;&gt;$n=0$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This technique was described in this paper:&lt;/p&gt;&#xA;&lt;p&gt;&amp;quot;Spectrally optimal sampling for distribution ray tracing&amp;quot; Mitchell 1991.&#xA;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=122718.122736&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://dl.acm.org/citation.cfm?id=122718.122736&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Below is the same setup as in the question where 455 black pixels are placed in a 64x64 image, showing the result for some values of &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt;.  The quality is surprisingly good even for low values of &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; and the execution time is much, much lower than the process described in the question.  I'm also limiting the candidate count to be at maximum 1/2 the number of pixels (an arbitrary limit I came up with) in the image to keep the candidate count from going too high for denser samplings in an effort to keep the quality and computation time decent.&lt;/p&gt;&#xA;&lt;p&gt;I've heard that storing points in grids can help in accelerating the calculation time of &amp;quot;how far is this candidate from the closest point&amp;quot; and I believe it should, but I haven't tried it yet.&lt;/p&gt;&#xA;&lt;p&gt;When &lt;span class=&quot;math-container&quot;&gt;$m=0$&lt;/span&gt;, it's equivelant to white noise and just randomly placing the dots.&lt;/p&gt;&#xA;&lt;p&gt;Note that when calculating the distance between two points I am treating the image as if it wraps around, so that dots on opposite edges are treated close  together.  If interested in details of how to calculate distance in wrap around (toroidal) space, check out this blog post:&#xA;&lt;a href=&quot;https://blog.demofox.org/2017/10/01/calculating-the-distance-between-points-in-wrap-around-toroidal-space/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.demofox.org/2017/10/01/calculating-the-distance-between-points-in-wrap-around-toroidal-space/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here is a blog post on Mitchell's best candidate algorithm too I wrote up:&#xA;&lt;a href=&quot;https://blog.demofox.org/2017/10/20/generating-blue-noise-sample-points-with-mitchells-best-candidate-algorithm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.demofox.org/2017/10/20/generating-blue-noise-sample-points-with-mitchells-best-candidate-algorithm/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/blUaK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/blUaK.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2020-07-29T17:30:36.030" LastActivityDate="2020-07-29T17:30:36.030" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="5688" PostTypeId="2" ParentId="5685" CreationDate="2017-10-05T22:07:55.657" Score="1" Body="&lt;p&gt;Well, BSP is an application of a Binary Search Tree (BST)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BSTs need a criterium to propagate the search through itself. Put simply, the criterium used in BSP is in which side of a partition a point is. Each partition just divides space in two parts. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is absolutely imposible to create a concave polygon (or polyhedron) by dividing space in halves. I dare you to try, you will see that it cannot be done&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2017-10-05T22:07:55.657" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5689" PostTypeId="2" ParentId="5685" CreationDate="2017-10-06T05:25:48.573" Score="1" Body="&lt;p&gt;Before GPUs were popular we rendered without using Z-Buffers and instead used polygon sorting to make sure things were drawn back-to-front correctly. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;By having a BSP with only convex geometry we guarantee that each leaf node will not have any ordering issues with the polygons contained in them, the BSP traversal algorithm itself can then produce a depth-sorted node list for you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These days we have z-buffers so the need for convex leaf nodes isn't really that important, in some ways its better to render front-to-back also to take advantage of early-z optimisations on hardware.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-10-06T05:25:48.573" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5691" PostTypeId="2" ParentId="5536" CreationDate="2017-10-06T16:44:43.843" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I have about ~200 bytes worth of data that I expect to be mostly constant. That is, I will change them very infrequently.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If the data changes infrequently, you can use &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.0/html/vkspec.html#pipelines-specialization-constants&quot; rel=&quot;nofollow noreferrer&quot;&gt;Specialization Constants&lt;/a&gt;. They are set when the pipeline is created, and a new pipeline must be created if you need to change the values. For an infrequent event, like a window resize, this may be an acceptable cost.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;what if I have e.g. a float random_seed that I will update every time the shader is run? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That's a perfect use case for Push Constants. You can keep all the other data in the UBO (or in the Specialization Constants) and change this value with &lt;code&gt;VkCmdPushConstants&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7433" LastActivityDate="2017-10-06T16:44:43.843" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5692" PostTypeId="1" CreationDate="2017-10-07T12:47:13.060" Score="2" ViewCount="197" Body="&lt;p&gt;I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP &quot;Colors &gt; Colorize&quot; function works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gDWgl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gDWgl.png&quot; alt=&quot;GIMP&amp;#39;s Colorize&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my program, I can easily convert between RGB and HSV. I can therefore get:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pix_h, pix_s, pix_v&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I also define the inputs of the colorize function as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;col_h, col_s, col_v&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What calculations can I perform to determine the output pixel hsv?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think I can get:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;out_h = col_h&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But I'm a little lost on how to calculate output saturation and value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&#xA;Where lum is the luminance of the input pixel:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;out_s = clamp( (1 - pix_v) * 2, 0, 1)&#xA;&#xA;out_v = clamp( pix_v * 2, 0, 1)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;seems to produce good results when colorize inputs S=1 ([0, 1]) and V=.5 ([0, 1]). I'm still struggling to generalize these formulas for when S!=1 and V!=.5.&lt;/p&gt;&#xA;" OwnerUserId="7434" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:45:23.727" LastActivityDate="2018-04-24T07:45:23.727" Title="How can I implement GIMP's &quot;Colorize&quot; function?" Tags="&lt;transformations&gt;&lt;glsl&gt;&lt;color&gt;&lt;2d&gt;&lt;pixel-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5693" PostTypeId="1" AcceptedAnswerId="5694" CreationDate="2017-10-07T14:40:17.987" Score="5" ViewCount="481" Body="&lt;p&gt;A few days ago I found a video on Twitter showing the Evans &amp;amp; Sutherland CT5 Flight Simulator system. It was labeled as 1981 footage and looked really amazing. The first time I saw similar 3D grahics in computer games was in the late 90s and in ealy 2000s. I wasn't suspisous because it was described as a product made for the military and I thought it's normal the technology to be more advanced.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yesterday I showed the video to my colleagues, all of them experienced developers and computer gurus, and they said it's impossible such graphics to be achieved in the 80's. I tried to search for a proof but I found none except a short documentary on YouTube and some forum topics where people were discussing how it was achieved without mentioning anything about the exact year. I found no definitive proof that the year of creation of CT5 system was 1981. No product specifications, no publications in wellknown newspapers and not even a Wikipedia article. I'm amazed how little information is out there about something so astonishing. And this is one of the things that fuel the doubt of my colleagues.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Was Evans &amp;amp; Sutherland CT5 really created in 1981 or at least from the same decade?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My colleagues are with a high self esteem and it's hard to change their opinion on something. I'll appreciate any resource that proves or disproves the existance of such advanced graphics in the early 80s as well as some details how it was made.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the link below you can see the two parts of the documentary I mentioned earlier and a short forum discussion about the CT5 and similar technologies. My colleagues don't consider it a sufficient proof.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://forum.beyond3d.com/threads/ct5-evans-sutherland-simulator-how-did-it-work.57664/&quot; rel=&quot;noreferrer&quot;&gt;CT5 Evans Sutherland Simulator - How did it work?&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7435" LastActivityDate="2019-07-10T20:23:22.760" Title="Was Evans &amp; Sutherland CT5 really created in 1981?" Tags="&lt;3d&gt;&lt;image-processing&gt;&lt;animation&gt;&lt;video&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5694" PostTypeId="2" ParentId="5693" CreationDate="2017-10-07T17:21:21.503" Score="3" Body="&lt;p&gt;After some searching on the internet, I am fairly certain that it was made in 1981 or at least the same decade. I have found multiple sources that indicate the CT5 was made in or around the year 1981.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first bit is in one of the promotional videos they made. At the very end there is a copyright statement. &quot;(C) November, 1981&quot;. I would already believe this as it looks to be integrated into the video, meaning it would be quite impressive if somebody would have edited it. To me, there seems no reason to put in a false date for the copyright as, I would imagine, it invalidates the copyright statement. It can be found at 3:22 in this video: &lt;a href=&quot;https://www.youtube.com/watch?v=7e7_GiCc-HA&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=7e7_GiCc-HA&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found a pdf scan from an article, written 24th of April 1982, about the CT5. It can be found here, &lt;a href=&quot;https://www.flightglobal.com/FlightPDFArchive/1982/1982%20-%201104.PDF&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.flightglobal.com/FlightPDFArchive/1982/1982%20-%201104.PDF&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also found a book called &quot;Modeling and Simulation:: Linking Entertainment and Defense&quot;, which has a brief bit about the CT5. It states, &quot;Nevertheless, the E&amp;amp;S CT5 (circa 1983) and the GE Compuscene 4 Computer Image generators were benchmarks by which all interactive computer graphics systems were measured for years.&quot;. This book says that it was around 1983 which does seem to support the claim of 1981, but it might have been a few years later. It can be found here, &lt;a href=&quot;https://books.google.nl/books?id=HTkrAAAAYAAJ&amp;amp;pg=PA36&amp;amp;lpg=PA36&amp;amp;dq=e%26s%20ct5&amp;amp;source=bl&amp;amp;ots=xka2n-9Uxx&amp;amp;sig=wfscYmgDGXB7AOlq00R9QtxDD60&amp;amp;hl=nl&amp;amp;sa=X&amp;amp;ved=0ahUKEwjustWX8t7WAhWJL1AKHT4wDhQQ6AEIQTAD#v=onepage&amp;amp;q=e%26s%20ct5&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://books.google.nl/books?id=HTkrAAAAYAAJ&amp;amp;pg=PA36&amp;amp;lpg=PA36&amp;amp;dq=e%26s+ct5&amp;amp;source=bl&amp;amp;ots=xka2n-9Uxx&amp;amp;sig=wfscYmgDGXB7AOlq00R9QtxDD60&amp;amp;hl=nl&amp;amp;sa=X&amp;amp;ved=0ahUKEwjustWX8t7WAhWJL1AKHT4wDhQQ6AEIQTAD#v=onepage&amp;amp;q=e%26s%20ct5&amp;amp;f=false&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I also found a patent filed by E&amp;amp;S for &quot;Computer graphics system of general surface rendering by exhaustive sampling&quot; in 1985. It has talked about doing rendering surfaces with a z buffer. It can be found here, &lt;a href=&quot;https://patents.justia.com/patent/4625289&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://patents.justia.com/patent/4625289&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there is another patent filled in 1982 for &quot;Graphics display system using logic-enhanced pixel memory cells&quot;, which claims it is capable real time. It can be found here, &lt;a href=&quot;https://www.google.com/patents/US4590465?dq=EVANS%20%26amp;%20SUTHERLAND&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0ahUKEwie5K-x-97WAhXKnRoKHduFAWo4ChDoAQgnMAA&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.google.com/patents/US4590465?dq=EVANS+%26amp;+SUTHERLAND&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0ahUKEwie5K-x-97WAhXKnRoKHduFAWo4ChDoAQgnMAA&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These two patents show that in the 80's they already have the technology for real time graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The forum discussion had a quote from a Wikipedia article which is from the following article, &lt;a href=&quot;https://en.wikipedia.org/wiki/Framebuffer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Framebuffer&lt;/a&gt;. This is more in case someone wants to know where it came from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It does seem like the technology was there and with a big enough budget, you just needed to gather it and make it into something like the CT5. You have 3 different sources that all show that the CT5 was created around 1981, and 2 sources that show the technology was there. Yes, you can still argue about the sources, but honestly then you can argue any fact in a history textbook.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that this answers your question or at least has informed you about something you might not have known.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="3003" LastEditDate="2017-10-08T01:58:12.557" LastActivityDate="2017-10-08T01:58:12.557" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5695" PostTypeId="2" ParentId="5692" CreationDate="2017-10-08T02:07:17.910" Score="1" Body="&lt;p&gt;It appears to me that in the image, the saturation of the original image is 0 since it is grayscale. (Unless I've misunderstood the question.) When the saturation is 0, the hue is undefined, but it appears that the GIMP is setting the hue to 0. It is then using the sliders from the dialog to modify the HSL. It adds 180° to the hue (so from 0 to 180 which gets you from red to cyan). The saturation is increased by 75 units, and the lightness is kept the same. It may have special protections for black and white, given that the white part of the letter &quot;A&quot; remains white in the final image (although even there, it appears to have an RGB value of (0.99, 1.0, 1.0), whereas on the right, it's fully white (1.0, 1.0, 1.0)).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can always look at the &lt;a href=&quot;https://www.gimp.org/source/#gimp-source-code&quot; rel=&quot;nofollow noreferrer&quot;&gt;source code&lt;/a&gt; since it's an open source package.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-10-08T02:07:17.910" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5696" PostTypeId="1" AcceptedAnswerId="5703" CreationDate="2017-10-09T00:32:56.993" Score="2" ViewCount="1116" Body="&lt;p&gt;I performed a quick search on programs that translate natural language to sign language (through a 3D animation character). Here are examples:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=RarMKnjqzZU&quot; rel=&quot;nofollow noreferrer&quot;&gt;IBM SISI&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=fEvvrLpTb0E&quot; rel=&quot;nofollow noreferrer&quot;&gt;ProDeaf&lt;/a&gt; (which is an android app)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My question is:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;how can I make my own character that uses sign language?&lt;/li&gt;&#xA;&lt;li&gt;Which platforms are preferred for 3D-modeling and animation(e.g. blender, maya, unity, ... etc.)?&lt;/li&gt;&#xA;&lt;li&gt;Is there specific algorithm(s) to make the character learn the sign language, or it is just a dictionary?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7438" LastActivityDate="2018-11-12T10:15:11.350" Title="How can I use 3d animation to create a character that uses sign language?" Tags="&lt;3d&gt;&lt;animation&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5697" PostTypeId="1" CreationDate="2017-10-09T07:15:04.703" Score="3" ViewCount="310" Body="&lt;p&gt;I have a triangle that is extended in space and each edge is refracted differently, creating a 5 sided polytope. The initial and final triangles are the view radii segments of a frustum. We need to get the u and v along the triangle and the w depth in between the triangles of a point inside the polytope. &lt;/p&gt;&#xA;" OwnerUserId="5884" LastActivityDate="2021-04-22T06:02:30.270" Title="Barycentric coordinates for 5-sided polytope of two triangles and three trapezoids" Tags="&lt;mathematics&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5698" PostTypeId="1" AcceptedAnswerId="5721" CreationDate="2017-10-09T19:48:20.873" Score="3" ViewCount="514" Body="&lt;p&gt;When making sampling locations, there is a lot of information out there on how to do white noise sampling, uniform sampling, uniform+jittered sampling, low discrepancy sequence sampling (eg halton) and blue noise sampling (eg mitchell's best candidate algorithm &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5682/mitchells-best-candidate-algorithm&quot;&gt;Mitchell&amp;#39;s Best Candidate Algorithm&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance these, where each point is a sample location in a 2d quad. (source: &lt;a href=&quot;https://blog.demofox.org/2017/05/29/when-random-numbers-are-too-random-low-discrepancy-sequences/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.demofox.org/2017/05/29/when-random-numbers-are-too-random-low-discrepancy-sequences/&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;White Noise:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WLFzs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WLFzs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniform:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dHAQQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dHAQQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniform + Jitter:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4LQlu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4LQlu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Halton (2,3):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JskHx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JskHx.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blue Noise:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/t71xm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t71xm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While those are good for sampling (a 2d quad in this case), here is a blue noise texture which is useful for dithering or stippling (src: &lt;a href=&quot;http://momentsingraphics.de/?p=127&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://momentsingraphics.de/?p=127&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YvAjF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YvAjF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, here is a white noise (random) one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WkZUp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WkZUp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been trying to figure out in this case (a dither / stippling noise texture), if there is an equivalent to uniform sampling, uniform + jitter, or low discrepancy, and if so, what those textures might look like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One obvious difference between the first set of the textures and the second is that the first textures take a single scalar value as input (an index) and give a 2d vector as output (a location on the 2d quad).  The second set of textures takes an (x,y) 2d vector location as input, and gives out a scalar value as output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It almost looks though like in the blue noise case that maybe you could start with the blue noise sample points, and then color every other pixel based on it's distance from the closest sample point, and that you might come up with the same image.  If that's correct, could you do the same for the other flavors of sample distributions to make the other noise textures?  It seems like white noise (random) wouldn't work for this though, so that doesn't seem correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, Jorge Jiminez has some &quot;Interleaved Gradient Noise&quot; that looks sort of blue noise-ish but kind of not... so seems a bit low discrepancy sequence. (&lt;a href=&quot;http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.iryoku.com/next-generation-post-processing-in-call-of-duty-advanced-warfare&lt;/a&gt;  and also an image and the math mentioned here &lt;a href=&quot;https://bartwronski.com/2016/10/30/dithering-part-three-real-world-2d-quantization-dithering/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://bartwronski.com/2016/10/30/dithering-part-three-real-world-2d-quantization-dithering/&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/34XJw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/34XJw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It makes me wonder if something about that noise shows the secret on how to generalize (low discrepancy) sample points to 2d?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know whether there is a way to translate these sample concepts to noise textures for dithering and stippling?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-10-13T18:24:47.113" Title="Making low discrepancy sequence noise textures, not LDS sample positions" Tags="&lt;texture&gt;&lt;image-processing&gt;&lt;sampling&gt;&lt;post-processing&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5699" PostTypeId="2" ParentId="5697" CreationDate="2017-10-09T20:15:46.180" Score="0" Body="&lt;p&gt;I think I can do this using trilinear interpolation and treating two vertices on each side as merged and using my own volume calculations. I just need to interpolate some values given by the three points and a z. &lt;a href=&quot;http://bmia.bmt.tue.nl/People/BRomeny/Courses/8C080/Interpolation.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://bmia.bmt.tue.nl/People/BRomeny/Courses/8C080/Interpolation.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5884" LastActivityDate="2017-10-09T20:15:46.180" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5701" PostTypeId="2" ParentId="5698" CreationDate="2017-10-09T21:15:15.793" Score="6" Body="&lt;p&gt;In theory, it is possible to stuff every sample distribution into a texture to &quot;pre-bake&quot; it for fast access. The question is whether any of the results might be useful. For blue noise, this makes a lot of sense, as blue noise distributions have global influence and are hard to evaluate at runtime. Uniform random sampling, on the other hand, is so simple precisely because it is not global, but has no influence whatsoever from neighboring samples. So the best you can achieve, as you noticed yourself, is writing uncorrelated white noise to the texture, which gains you very little.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the key property of the blue noise textures that you failed to mention is that they are progressive. If you take, for example, Blue Noise Masks, Forced Random Dithering, or Relaxation Dart Throwing to generate a matrix/texture, you will not get grayscale values, but unique, ascending integer values corresponding to the order of insertion of the samples/texels. This means that you can also re-arrange such textures to a 1D list of width * height elements, where each element is a 2D position within the matrix. I.e., the first element of this list will be the (x, y) of the first sample inserted into the texture upon creation. The second element will be the (x2, y2) of the second sample, which will be quite far away from the first one, because the blue noise texture algorithms try to maximize distances between similar values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The list representation is nothing but a sequence accomplishing what 2D low-discrepancy sequences do: giving you a 2D sample position (albeit discrete and in a grid) for a scalar index. You do not lose any information while converting. So applying the reverse conversion to low-discrepancy sequences, it should be possible to write their element indices into a texture for fast lookup. What I don't know is how fast this will degenerate, because sooner or later higher values will end up at the same discretized locations as previously written ones. Low-discrepancy sequences guarantee spatial uniformity on average, but if you want to fill an n² texture and create exactly n² samples, I bet that you will get some of these overlaps while also having some holes. These conflicts can, by design, not occur in blue noise textures, but here you would have to find a strategy. Just discarding the higher values? I don't know how this influences the distribution properties. I assume that results vary between different low-discrepancy sequences. I have only ever worked with Halton and Hammersley, which don't seem like the best fit in this case. Maybe something based on a grid/lattice would help you to reduce/eliminate the overlaps. Not my field of expertise, unfortunately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the key problem, that low-discrepancy sequences (at least the ones I know) and in general sampling distributions used in computer graphics output nD values in the continuous domain rather than in a discrete grid. The reason blue noise textures work so well is because the discretization is already part of the generation. What you want is a permutation of n² integer values such that the result has special properties. Maximizing distances between similar values would be blue noise. Having no correlation between values would be white noise. And some other magic property could be pink noise, green noise, or a perfect interleaved gradient noise as in your provided picture. Would this be a reasonable approach, to understand your problem as the problem of permuting given values? Instead of continuous sampling? Maybe it simplifies the solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another point to consider for dithering and related effects is that blue noise textures can usually be tiled seemlessly because the sample domain is taken to be toroidal. You will lose this feature unless you find a way to make your low-discrepancy sequence toroidal, which I think is pretty tough, but would be a great scientific contribution!&lt;/p&gt;&#xA;" OwnerUserId="7442" LastEditorUserId="7443" LastEditDate="2017-10-10T03:33:14.523" LastActivityDate="2017-10-10T03:33:14.523" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5703" PostTypeId="2" ParentId="5696" CreationDate="2017-10-10T12:04:28.857" Score="2" Body="&lt;p&gt;This is quite a broad topic, so I can only give a general overview. If you've never done any interactive animation before, this might be too big a challenge to start with, and maybe you should think of something smaller to do first.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You first need to model and rig your character, or try to find an existing model online that's rigged with enough control over the fingers. You then need to define a &quot;dictionary&quot; of animations or poses for each item of vocabulary in the language. To create the poses, it is probably easiest to use motion-capture technology to record a proficient sign-language speaker.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of the above needs to be done in a 3D modelling and animation tool. Maya is very popular for character animation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get natural sign-language, you'll also need to write an algorithm to understand the way places in space are used as pronouns, and a fall-back that spells things out using letters when you don't have a vocab item for them. Based on next to no knowledge of sign language, I'd guess the algorithm will end up a little more complicated than a normal text-to-speech algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You've already mentioned Unity 3D in your question, and that might be a good choice for the real-time part of the system (assuming you want to render the character in real-time). If you use that, you can write the algorithm in C#. You would import the animation/pose dictionary into your system in Unity, and have your algorithm compute the transitions from one pose or animation to the next. In Unity itself, you can define the camera and lighting layout for your model and the backdrop to draw it in front of.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-10-10T12:04:28.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5704" PostTypeId="1" CreationDate="2017-10-10T15:13:11.773" Score="2" ViewCount="921" Body="&lt;p&gt;Is it possible to create a single kernel which can help us to perform an 2 step image processing? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I want to first perform a median filter on my image to remove salt and pepper noise and then perform a sharpen operation on it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this purpose, I have to perform the following operation &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(image * Median_Kernel) *  sharpening kernel = final_image&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;I want to have a kernel which combines the effect of Median_kernel and sharpening it such that&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;image * combined_kernel = final_image&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is this mathematically possible? If so, could someone please explain to me how to do this mathematically?&lt;/p&gt;&#xA;" OwnerUserId="6974" LastEditorUserId="6" LastEditDate="2017-10-12T15:43:27.700" LastActivityDate="2018-07-06T10:21:53.127" Title="How can I combine two filter kernels for image processing to create a single kernel?" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5705" PostTypeId="2" ParentId="5684" CreationDate="2017-10-10T16:47:15.093" Score="2" Body="&lt;p&gt;The function that calculates sun position in the sky takes as input&#xA;local latitude, longitude and local date time. The output is a vector &#xA;which is sun position:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OzwCQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OzwCQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inversing the above means using the ray direction(sun position in the sky) and retrieving back the local date time. If the date time is valid then the ray must hit the sun path throughout the year. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the inverse function of the above:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public DateTime GetLocalDatetime(double haSolar, double vaSolar)&#xA;{&#xA;    double latitude = Helper.ToRadian(Latitude);&#xA;    double longitude = Helper.ToRadian(Longitude);&#xA;&#xA;    double zenithTheta = Helper.PiOver2 - vaSolar;&#xA;&#xA;    double sinSolarDeclination = (Math.Cos(Math.PI - haSolar) * Math.Cos(latitude) * Math.Sin(zenithTheta)) + Math.Sin(latitude) * Math.Cos(zenithTheta);&#xA;    double solarDeclination = Math.Asin(sinSolarDeclination);&#xA;&#xA;    double cosH = (Math.Sin(vaSolar) - Math.Sin(latitude) * sinSolarDeclination) / (Math.Cos(latitude) * Math.Cos(solarDeclination));&#xA;    if (Math.Abs(cosH) &amp;gt; 1) return DateTime.MinValue;&#xA;&#xA;    double H = Math.Acos(cosH);&#xA;    if (haSolar &amp;lt; 0) H *= -1;&#xA;&#xA;    double declratio = solarDeclination / Helper.ToRadian(23.45);&#xA;    if (Math.Abs(declratio) &amp;gt; 1) return DateTime.MinValue;&#xA;&#xA;    double beta = Math.Asin(declratio);&#xA;    int n = (int)Math.Round(beta / Helper.ToRadian(360d / 365d) + 81d, 1);&#xA;&#xA;    DateTime localtime = new DateTime(DateTime.Now.Year, 1, 1).AddDays(n - 1);&#xA;    DateTime solartime = new DateTime(localtime.Year, localtime.Month, localtime.Day, 12, 0, 0);&#xA;    solartime = solartime.AddMinutes(4 * Helper.ToDegree(H));&#xA;&#xA;    double eot = 9.87 * Math.Sin(2d * beta) - 7.53 * Math.Cos(beta) - 1.5 * Math.Sin(beta);&#xA;    double deltatimezone = 4d * (longitude - (Timezone * 15d));&#xA;    return solartime.AddMinutes(-(eot + deltatimezone));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the image where each band represent each month in the year:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XvI8R.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XvI8R.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:55:58.710" LastActivityDate="2018-03-04T19:55:58.710" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5707" PostTypeId="2" ParentId="5704" CreationDate="2017-10-10T17:28:07.050" Score="2" Body="&lt;p&gt;Why not just do them one after the other?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Img = (Img * median) * sharpen;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think you should look into how these filter operations actually work before attempting to use them. It's pretty simple, use wikipedia or even any image processing textbook. Even the Matlab docs have good explanations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Median filtering is a &lt;strong&gt;non linear filtering operation&lt;/strong&gt; which means that there is no fixed &lt;strong&gt;kernel&lt;/strong&gt; function for it. You may define a neighborhood size but other than that, nope, no kernel. Have you looked into how it works? I dont know how you could generate a &quot;kernel&quot; for a non-linear filtering operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe a basic refresher in Image Processing is in order? Perhaps even going over basics of Signal Processing / DSP? I would suggest looking over 2D filtering if you can.&lt;/p&gt;&#xA;" OwnerDisplayName="user7450" LastEditorUserId="-1" LastEditDate="2017-10-27T03:31:07.743" LastActivityDate="2017-10-27T03:31:07.743" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5712" PostTypeId="1" AcceptedAnswerId="5714" CreationDate="2017-10-11T08:31:58.690" Score="13" ViewCount="11520" Body="&lt;p&gt;In OpenGL the buffer object functions (&lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferData.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glBufferData&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferSubData.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glBufferSubData&lt;/code&gt;&lt;/a&gt;, and probably a few others) have a parameter &lt;code&gt;usage&lt;/code&gt;, described by the documentation as a hint of the intended usage, likely meant to help the implementation yield better performance.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;em&gt;usage&lt;/em&gt;&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Specifies the expected usage pattern of the data store. The symbolic constant must be &lt;code&gt;GL_STREAM_DRAW&lt;/code&gt;, &lt;code&gt;GL_STREAM_READ&lt;/code&gt;, &lt;code&gt;GL_STREAM_COPY&lt;/code&gt;, &lt;code&gt;GL_STATIC_DRAW&lt;/code&gt;, &lt;code&gt;GL_STATIC_READ&lt;/code&gt;, &lt;code&gt;GL_STATIC_COPY&lt;/code&gt;, &lt;code&gt;GL_DYNAMIC_DRAW&lt;/code&gt;, &lt;code&gt;GL_DYNAMIC_READ&lt;/code&gt;, or &lt;code&gt;GL_DYNAMIC_COPY&lt;/code&gt;.&lt;br/&gt;&#xA;  &lt;em&gt;[...]&lt;/em&gt;&lt;br/&gt;&#xA;  usage is a hint to the GL implementation as to how a buffer object's data store will be accessed. This enables the GL implementation to make more intelligent decisions that may significantly impact buffer object performance. It does not, however, constrain the actual usage of the data store.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object#Buffer_Object_Usage&quot; rel=&quot;noreferrer&quot;&gt;The wiki&lt;/a&gt; is similarly vague:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;These are only hints, after all. It is perfectly legal OpenGL code to modify a STATIC buffer after it has been created, or to never modify a STREAM buffer.&lt;br/&gt;&#xA;  &lt;em&gt;[...]&lt;/em&gt;&lt;br/&gt;&#xA;   These are questions that can only be answered with careful profiling. And even then, the answer will only be accurate for that particular driver version from that particular hardware vendor.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In fine, how relevant is this parameter, if at all? Do drivers actually take it into account, and if they do, in your experience how much does it impact performance in practice? Do you have data to share?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have written a thin graphics API abstraction layer meant to be implemented as either of the existing APIs, and it is tempting to just ignore this parameter altogether and hide it from the exposed abstraction.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2017-10-11T10:00:24.917" Title="GL_STATIC_DRAW vs GL_DYNAMIC_DRAW vs GL_STREAM_DRAW: does it matter?" Tags="&lt;opengl&gt;&lt;optimisation&gt;&lt;vertex-buffer-object&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5713" PostTypeId="2" ParentId="5712" CreationDate="2017-10-11T08:54:45.903" Score="5" Body="&lt;p&gt;Functionally they are the same. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The driver could use them to differentiate how to handle the buffer behind the scenes. Where for example static_draw would be copied to vram as soon as possible and left there but stream_read would have a op to date copy in RAM at all times.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This vagueness is the reason that &lt;a href=&quot;http://docs.gl/gl4/glBufferStorage&quot; rel=&quot;noreferrer&quot;&gt;glBufferStorage&lt;/a&gt; became a thing. That way you specify what you want to be able to do with the buffer (whether you'll update it through BufferSubData, whether you'll read or write through a map, how coherent the mapping is, whether the mapping can persist across uses) and going outside those boundaries is an error.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-10-11T08:54:45.903" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5714" PostTypeId="2" ParentId="5712" CreationDate="2017-10-11T10:00:24.917" Score="9" Body="&lt;p&gt;This will vary between implementations, but the driver I worked on did use these, mainly to decide memory layout. The optimizations enabled by these hints are much smaller than you would like, mainly because of the restriction that you &lt;em&gt;can&lt;/em&gt; do any use whatever hints you give. e.g. it would make cache invalidation a lot cheaper if buffers hinted for read access only could not be written at all, but this optimization is impossible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some notable games which are widely used for benchmark comparisons between GPUs do not use these hints correctly, so GPU vendors have an incentive to make all uses fast even if they doesn't match the hints.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-10-11T10:00:24.917" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5715" PostTypeId="2" ParentId="5679" CreationDate="2017-10-11T10:19:24.863" Score="3" Body="&lt;p&gt;I finally found the cause of the problem. There appears to be a problem with the shadow map of both the omni light and spotlight. While debugging, I noticed by accident that the light-view-to-light-projection (&lt;code&gt;lview_to_lprojection&lt;/code&gt;) &lt;code&gt;00&lt;/code&gt; and &lt;code&gt;11&lt;/code&gt; matrix entries were not equal. Due to the aspect ratio of 1, both matrix entries must be equal. Furthermore, due to the FOV of $\pi/2$, these matrix entries must be equal to 1 (assuming no floating-point precision issues).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The constructor of my &lt;code&gt;PerspectiveCamera&lt;/code&gt; class expects a &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt;, &lt;code&gt;FOVy&lt;/code&gt;, &lt;code&gt;near&lt;/code&gt;, &lt;code&gt;far&lt;/code&gt; order or &lt;code&gt;aspect ratio&lt;/code&gt;, &lt;code&gt;FOVy&lt;/code&gt;, &lt;code&gt;near&lt;/code&gt;, &lt;code&gt;far&lt;/code&gt; order and correctly handles the creation of the view-to-projection transformation matrix via redirecting to &lt;code&gt;XMMatrixPerspectiveFovLH&lt;/code&gt; expecting a &lt;code&gt;FOVy&lt;/code&gt;, &lt;code&gt;aspect ratio&lt;/code&gt;, &lt;code&gt;near&lt;/code&gt;, &lt;code&gt;far&lt;/code&gt; order. Since, I did not want to create a corresponding &lt;code&gt;PerspectiveCamera&lt;/code&gt; for each light per frame, I bypassed that class by directly providing a member method in my &lt;code&gt;OmniLight&lt;/code&gt; and &lt;code&gt;SpotLight&lt;/code&gt; classes redirecting to &lt;code&gt;XMMatrixPerspectiveFovLH&lt;/code&gt; using the wrong order of arguments. &lt;strong&gt;This explains why the above images are wrong.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The generated shadow map of the spotlight is still equal to one of the six shadow maps of the omni light, although both use the same but wrong &lt;code&gt;world_to_lprojection&lt;/code&gt; transformation matrix (which contains the wrong &lt;code&gt;lview_to_lprojection&lt;/code&gt; transformation matrix). The HLSL code for the spotlight uses the &lt;code&gt;cview_to_lprojection&lt;/code&gt; transformation matrix, which includes &lt;code&gt;lview_to_lprojection&lt;/code&gt;, and thus will perform the &quot;right&quot; mapping. The HLSL code for the omni light uses the &lt;code&gt;cview_to_lview&lt;/code&gt; transformation matrix, which does not include &lt;code&gt;lview_to_lprojection&lt;/code&gt;, and thus will not take the non-uniform scaling of the 00 and 11 entries into account, resulting in some non-linear stretching and thus the wrong mapping. &lt;strong&gt;This explains why the above images differ for the omni light and spotlight.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;After fixing the bug:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Omni Light&lt;/strong&gt; (6 faces) shadow factor:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7t8ku.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7t8ku.png&quot; alt=&quot;Omni Light (6 faces)&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7Hl37.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7Hl37.png&quot; alt=&quot;Omni Light (6 faces)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Omni Light&lt;/strong&gt; (1 face) shadow factor:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pV2DZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pV2DZ.png&quot; alt=&quot;Omni Light (1 face)&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/iXX5r.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iXX5r.png&quot; alt=&quot;Omni Light (1 face)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Spotlight&lt;/strong&gt; shadow factor:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kLBIl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kLBIl.png&quot; alt=&quot;Spotlight&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dNEB6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dNEB6.png&quot; alt=&quot;Spotlight&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;SampleCmpLevelZero&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using this method on a signed-normalized or unsigned-normalized format (which is the case), the comparison value is automatically clamped between 0.0 and 1.0. The two perspective cameras looking along the positive or negative x-axis (along the middle hallway) associated with the omni light, will have &quot;rays&quot; which are not occluded by the scene's geometry due to the far plane at distance 3. Therefore, these pixels (displaying the shadow factor) will always be lit for comparison values larger than or equal to &lt;code&gt;1.0f&lt;/code&gt; (since all such values are clamped to &lt;code&gt;1.0f&lt;/code&gt;).&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-10-11T17:02:41.413" LastActivityDate="2017-10-11T17:02:41.413" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5716" PostTypeId="1" AcceptedAnswerId="5801" CreationDate="2017-10-12T04:05:28.420" Score="1" ViewCount="125" Body="&lt;p&gt;I understand de Casteljau's algorithm and I am familiar although not fully experienced with B-Splines. I am trying to understand the geometric interpretation of B-splines through the algorithm (just like how de Casteljau's algorithm shows the geometric interpretation of Bézier curves). Thank you in advance.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="6968" LastEditDate="2021-04-16T15:42:02.770" LastActivityDate="2021-04-16T15:42:02.770" Title="How does the Lane Riesenfeld algorithm work?" Tags="&lt;bezier-curve&gt;&lt;curve&gt;&lt;nurbs&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="5718" PostTypeId="1" AcceptedAnswerId="5719" CreationDate="2017-10-13T07:19:16.473" Score="1" ViewCount="805" Body="&lt;p&gt;I'm studying spring model. There is a suggested equation (Hooke's Law vector form) But, I couldn't understand how to derive that equation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm reading 'Computer Animation Algorithms and Techniques Third Edition.&#xA;In the page 241, (7.88)&#xA;The equation is as follows: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;($|v_{1}^* - v_{2}^*|$: the rest length)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;($|v_{1} - v_{2}|$: the current length)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$F_s = (\frac{k_s|v_1 -v_2| - |v_{1}^* - v_{2}^*|}{{|v_{1}^* - v_{2}^*|}})\frac{(v_1 -v_2)}{|v_1 -v_2|}$ // I think the $k_s$ is typo. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I referred to &lt;a href=&quot;http://www2.cs.uregina.ca/~anima/408/Notes/Cloth/Cloth.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www2.cs.uregina.ca/~anima/408/Notes/Cloth/Cloth.htm&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, maybe $F_s = k_s(\frac{|v_1 -v_2| - |v_{1}^* - v_{2}^*|}{\color{red}{|v_{1}^* - v_{2}^*|}})\frac{(v_1 -v_2)}{|v_1 -v_2|}\cdot\cdot$(1) is correct. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I wonder why the red part divides the equation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I know correctly about Hooke's Law, $F=-k_s(current_{lenght} - rest_{length})\cdot\cdot$(2).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It means that the red part should be removed like that $F_s = k_s(|v_1 -v_2| - |v_{1}^* - v_{2}^*|)\frac{(v_1 -v_2)}{|v_1 -v_2|}\cdot\cdot$(3).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, in 3D space, there is a spring that has the spring term as $k_s$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rest length is '3', so let's assume the left rest point, $v_2^*$, is fixed at (0,0,0) and the right rest point, $v_1^*$, is (3,0,0).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then we moved $v_1^*$ to $v_1 $=(5, 0, 0) with some force.&#xA;We can calculate the force with (2), and the force is $-2k_s = -k_s(|(5,0,0) - (0,0,0)| - |(3,0,0) - (0,0,0)|)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But if we use equation (1), the result is different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$F_s = -k_s(\frac{|v_1 -v_2| - |v_{1}^* - v_{2}^*|}{{|v_{1}^* - v_{2}^*|}})\frac{(v_1 -v_2)}{|v_1 -v_2|} \\\quad= -k_s(\frac{|(5,0,0) -(0,0,0)| - |(3,0,0) - (0,0,0)|}{{|(3,0,0) - (0,0,0)|}})\frac{((5,0,0) -(0,0,0))}{|(5,0,0) -(0,0,0)|} \\\quad= -\frac{2}{3}k_s(1,0,0)$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The force amount of $-\frac{2}{3}k_s(1,0,0)$ is totally different from $-2k_s$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you explain what I'm wrong?&lt;/p&gt;&#xA;" OwnerUserId="6806" LastEditorUserId="6806" LastEditDate="2017-10-13T16:59:12.087" LastActivityDate="2017-10-13T16:59:12.087" Title="Hooke's Law vector form" Tags="&lt;mathematics&gt;&lt;physically-based&gt;&lt;vector-graphics&gt;&lt;physics&gt;&lt;model&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5719" PostTypeId="2" ParentId="5718" CreationDate="2017-10-13T12:34:37.820" Score="1" Body="&lt;p&gt;If we sidestep your typo (the last term has one absolute too much), both formulations are correct. They just express different things. The $k$ in Hooke's law is for a particular spring. $k_s$ is the siffness for a paricular material. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now in the linear portion there is a direct relationship betwen these the material stffness is directly propotional to the spring factor and length of member. So for example when the rest length of a different spring with same material is 2 times as long its 1/2 as stiff.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-10-13T12:34:37.820" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5720" PostTypeId="1" CreationDate="2017-10-13T13:04:06.417" Score="2" ViewCount="121" Body="&lt;p&gt;I am working on a graphics engine designed to be used in flight simulators.&#xA;It therefore has to feature an advanced weather rendering system with clouds you can fly through.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this, I implemented a particle system that renders a few hundred thousand billboards scattered in layers and in a 120km radius area.&#xA;Until now, these clouds were my only transparent objects and I was relying on sorted alpha blending to get the desired result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My engine is making some progress and I now need to be able to render different types of transparent objects. Of course, I cannot rely on sorted alpha blending anymore since these objects are too different to be handled with a uber shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In search for alternatives, I tried to implement a few order independent transparency techniques with inconclusive results :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Weighted Blended OIT : not working well with very contrasting objects and almost opaque objects. Hard to find a visibility function that can handle all kind of objects.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Linked List OIT / Adaptive transparency : result quality is very good but efficiency depends too much on scene complexity and a cloud rendering system involves way too much layers/overdraw.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Most OIT techniques are illustrated with simple to moderate complexity scenes.&#xA;I feel like I am in a dead-end and I'm looking for new ideas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a different OIT technique that I am not aware of and that can be appropriate for such a case ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there cloud rendering techniques or rendering pipeline designs that can help to solve this problem ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you for your time and help.&lt;/p&gt;&#xA;" OwnerUserId="7473" LastEditorUserId="7473" LastEditDate="2017-10-13T13:14:01.350" LastActivityDate="2017-10-16T02:21:24.383" Title="Cloud rendering and transparency order" Tags="&lt;transparency&gt;&lt;particles&gt;" AnswerCount="0" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="5721" PostTypeId="2" ParentId="5698" CreationDate="2017-10-13T18:24:47.113" Score="0" Body="&lt;p&gt;The missing link between sample locations and the greyscale noise textures is &quot;ordered dithering&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ordered dithering is a list of pixel locations with a &quot;rank&quot; (order) for each pixel.  If you have a white background and want to add two black dots, you add them at the locations for the two pixels rank 0 and rank 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Choosing how to rank the order of the pixels to turn on can vary dramatically with different results.  For instance, a bayer matrix is a specific ordering of the points, and blue noise sample points are as well.  White noise is just shuffling the points so that they have a random ordering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How we get from this &quot;ordered dithering&quot; (stippling) to the greyscale color noise images is that we divide each point's rank by the number of points to get a value from 0 to 1, and use that as the points greyscale color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That gives you the greyscale noise textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with converting the concept of &quot;uniform sampling&quot; to this is coming up with a definition of what uniform samples in 2d would look like.  Would it just be in scanline order of the pixels?  Would vertical stripes be any more or less uniform sampled?  Maybe uniform sampling would consist of a course grid followed by a finer grid, and a finer grid, and a finer grid, until all pixels were filled in?  It seems open to debate and interpretation.  That question would need to be solved before you could assign ranks to the pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with converting the concept of &quot;low discrepancy sequences&quot; to this is figuring out how to do a low discrepancy sequence in 2d on a discretized grid where samples are only chosen for places that do not yet already have a sample.  I'm betting there are some LDS's that fit this or could be made to fit this but many don't.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-10-13T18:24:47.113" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5722" PostTypeId="1" CreationDate="2017-10-13T23:55:40.713" Score="1" ViewCount="706" Body="&lt;p&gt;How do we rotate the camera around &lt;code&gt;x axis&lt;/code&gt; 360 degrees, without having to flip the axis, meaning without having the strange flip after we go over +-90 degrees on &lt;code&gt;x axis&lt;/code&gt;.&#xA;Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;References&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;C++ code: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://pastebin.com/BBGdmKGb&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pastebin.com/BBGdmKGb&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Video:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://drive.google.com/open?id=0Bz3F9j1LiPNTS29XSUJoU2taRXc&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://drive.google.com/open?id=0Bz3F9j1LiPNTS29XSUJoU2taRXc&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6908" LastEditorUserId="6908" LastEditDate="2017-10-14T16:18:17.957" LastActivityDate="2017-10-14T16:18:17.957" Title="360 degrees rotation around x axis" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;glm&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5723" PostTypeId="2" ParentId="5192" CreationDate="2017-10-14T00:25:21.527" Score="4" Body="&lt;p&gt;The missing link between sample locations and the greyscale noise texture is &quot;ordered dithering&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ordered dithering is a list of pixel locations with a &quot;rank&quot; (order) for each pixel. If you have a white background and want to add two black dots, you add them at the locations for the two pixels rank 0 and rank 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Choosing how to rank the order of the pixels to turn on can vary dramatically with different results though. For instance, a bayer matrix is a specific ordering of the points, and blue noise sample points are as well. White noise is just shuffling the points so that they have a random ordering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How we get from this &quot;ordered dithering&quot; (stippling) to the greyscale color noise images is that we divide each point's rank by the number of points to get a value from 0 to 1, and use that as the points greyscale color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That gives you the greyscale noise textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The greyscale blue noise texture was created with the &quot;void and cluster&quot; algorithm which makes it so that each new dot placed goes in the middle of the largest void.  This has the nice property that you can threshold the blue noise texture at any value, and the result will be blue noise samples of the desired density.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This paper is a great read that talks about these things more deeply:&#xA;&lt;a href=&quot;http://cv.ulichney.com/papers/1993-void-cluster.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://cv.ulichney.com/papers/1993-void-cluster.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-10-14T00:25:21.527" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5724" PostTypeId="1" AcceptedAnswerId="5725" CreationDate="2017-10-14T11:30:50.603" Score="20" ViewCount="22659" Body="&lt;p&gt;I'm new to shaders and know that you can color pixels with gl_FragColor but sometimes there is this thing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = gl_FragCoord.xy / screenSize; // or resolution or smthn depends on the implementation&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If gl_FragCoord is like pixel coordinates, what does &lt;strong&gt;uv&lt;/strong&gt; get?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is it often done in GLSL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If someone could even draw an example of which part of the screen will be UV it will be very helpful!&lt;/p&gt;&#xA;" OwnerUserId="7464" LastEditorUserId="10159" LastEditDate="2019-02-12T19:19:11.300" LastActivityDate="2019-12-08T08:20:21.087" Title="GLSL. Can someone explain why gl_FragCoord.xy / screenSize is performed and for what reason?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="5725" PostTypeId="2" ParentId="5724" CreationDate="2017-10-14T12:42:15.177" Score="29" Body="&lt;p&gt;First, &lt;code&gt;gl_FragCoord.xy&lt;/code&gt; are screen space coordinates of current pixel based on viewport size. So if viewport size is &lt;code&gt;width=5&lt;/code&gt;, &lt;code&gt;height=4&lt;/code&gt; then each fragment contains:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Oa1zn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Oa1zn.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Why are uvs needed? For example I rendered geometry to screen quad and then I need to apply some postprocessing on this quad in another rendering pass. To sample from that quad I need texture coordinates in range [0, 1]. So to calculate them I perform division &lt;code&gt;gl_FragCoord.xy / viewPortSize&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-10-14T12:42:15.177" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5727" PostTypeId="1" CreationDate="2017-10-14T20:14:40.320" Score="1" ViewCount="304" Body="&lt;p&gt;I've been thinking about making my own 3D rendering engine in C++, but I don't know much about math that's required to do it. I'm not even sure if it's possible or if it even exists or how it's called.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It goes like this. Let's imagine a 3D body that has 6 vertices and 8 faces. It's like a pyramid on top of an upside-down pyramid. Each face is a triangle, but let's imagine that every line between the triangle points is a three-dimensional bezier curve. That would make each face look like a tent. If we do that, then we get a sphere. Now, imagine if instead of rendering that sphere by subdividing the tents into triangles we render the tents exactly how they are and imagine if we don't render raster graphics, but rather vector graphics in PostScript/Flash/ActionScript/GhostScript format in ASCII that can be opened by Notepad and rendered as a semi-transparent PNG image at any resolution without losing quality.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When rendering 3D triangles, matrix operations are used if I'm not mistaken. There's a matrix with some values and then a determinant is calculated. But these values are constants. What if the values depend on a formula of the bezier curve that's in 3D space? How can we stuff the formula into the matrix? And a better question; how can we stuff that into an algorithm or into OpenGL or into a language that a graphics card can process instead of the CPU? Does such a formula, matrix or an algorithm exist?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I'm not thinking about rendering simple spheres, but rendering something like this: &lt;a href=&quot;https://www.blendswap.com/blends/view/24878&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.blendswap.com/blends/view/24878&lt;/a&gt;&#xA;&lt;br&gt;I'm thinking about making a lightweight renderer in assembly for an ESP32 SoC or some other Arduino microcontroller/processor/SoC which would render all that onto an LCD or a PAL/NTSC TV via a composite AV jack, but that's another topic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is whether or not such a rendering method exists, how it's named, is it free to use, is it patented and is there any permissive-licensed C++ code for it (MIT, zlib/png, Apache, BSD). Please let me know.&lt;/p&gt;&#xA;" OwnerUserId="7477" LastActivityDate="2017-10-16T13:30:35.757" Title="Does this 3D rendering method exist? How is it called? Is there any C++ algorithm for it?" Tags="&lt;3d&gt;&lt;bezier-curve&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5728" PostTypeId="2" ParentId="5727" CreationDate="2017-10-14T21:02:18.483" Score="4" Body="&lt;p&gt;Yes, such rendering exists. It is called a parametric surface and there are several methods you can render such entities. In this case you are talking of bezier patches.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Turn the object into enough triangles. The triangilation is called tesselation or meshing depending on what literature you read.&lt;/p&gt;&#xA;&lt;p&gt;There are lots of applications that do this allready. Most cad applications work this way and many graphics apps like blender can work&#xA;this way.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;raytrace or raymarch the surface in a shader.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Microdice the surface&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;etc.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The reason this is not often done is that the on line tesselation is for most intent and purposes just a hindrance to asset developpers. You get the same with subdivision schemes and its just easier. The primary reason to drag the bezier (or nurbs, or t-splines...) is that unless you need to find better intersection of underlying primitives then it is often just a waste of resources. Although subdividing your mesh  via a subdivision surface is allready more useful&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-10-14T21:02:18.483" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5730" PostTypeId="1" CreationDate="2017-10-15T13:42:35.720" Score="2" ViewCount="4570" Body="&lt;p&gt;I'm working with OpenGL to try to rotate / translate my 3d object : a cow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The requirement is simple : &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;If I toggle key 'r'. The cow spinning around and random axis.&lt;/li&gt;&#xA;&lt;li&gt;If I drag the cow with mouse, it translate along its own x axis which means +x directions is for cow's head&lt;/li&gt;&#xA;&lt;li&gt;Rotation and translation need not execute at the same time.&lt;/li&gt;&#xA;&lt;li&gt;Rotation and translation is done is modeling space.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;To implement first requirement, I used timer function like this :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void rotateCow(int value) {&#xA;    //rotation ended&#xA;    if (!rotate_flag)&#xA;        return;&#xA;&#xA;    printf(&quot;rotateCow\n&quot;);&#xA;&#xA;    angle = (angle + 5) % 360;&#xA;    glutPostRedisplay();&#xA;    glutTimerFunc(30, rotateCow, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and for rotation and translation : &#xA;(some of codes are skipped)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void dragCow() {&#xA;    glPushMatrix();&#xA;    //some codes are skipped..&#xA;&#xA;    //rotation start&#xA;    if (rotate_flag == 1) {&#xA;        rotate_flag = 2;&#xA;        glutTimerFunc(30, rotateCow, 1);&#xA;    }&#xA;&#xA;    glTranslatef(trans_x, trans_y, trans_z);&#xA;    glRotatef(angle, rotate_x, rotate_y, rotate_z);&#xA;&#xA;    glCallList( cowID ); // Draw cow.&#xA;    glPopMatrix();&#xA;}&#xA;&#xA;void onMouseDrag( int x, int y ) {&#xA;    y = height - y - 1;&#xA;    if (trans_flag == DIR_X) {&#xA;        trans_x = ((x - oldX) / DRAG) + old_trans_x;&#xA;    }&#xA;&#xA;    glutPostRedisplay();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I run as above(rotate and then translate) rotation is as expected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the translation is done in global x-axis not towards head direction of cow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I change the order like this : &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glRotatef(angle, rotate_x, rotate_y, rotate_z);&#xA;glTranslatef(trans_x, trans_y, trans_z);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It shows that translation is as expected(towards head direction of cow).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the rotations not works - the rotation-axis made on global x-axis and the cow revolve around that line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how can I solve this problem??&lt;/p&gt;&#xA;" OwnerUserId="7482" LastEditorDisplayName="user7220" LastEditDate="2018-04-24T07:44:16.063" LastActivityDate="2018-04-24T07:44:16.063" Title="OpenGL : How to translate an object with it's own axis" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5731" PostTypeId="1" CreationDate="2017-10-15T14:43:51.530" Score="3" ViewCount="429" Body="&lt;p&gt;I am experienced with C++ and know more embedded device related stuff but have absolutely no knowledge of computer graphics and its algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to get a road mesh (based off of a spline) blended seamlessly into a terrain mesh, which is based on a regular grid, like in the picture below. How is this achieved?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just looked at the CGAL documentation and I cannot even see which problem I am facing and which package to study. Delauney refinement maybe? But I only see a CGAL package for 2D. I'd like to generate a 3D mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The road mesh should be unmodified, the terrain mesh can be altered to form a seamloss mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you guide me to the kind of algorithms needed for this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Kind regards&#xA;Max&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/v0EMM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v0EMM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7483" LastActivityDate="2018-06-27T07:43:02.357" Title="Fuse detailed road mesh with regular grid terrain mesh" Tags="&lt;mesh&gt;&lt;grid&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5732" PostTypeId="2" ParentId="5730" CreationDate="2017-10-15T18:01:19.500" Score="1" Body="&lt;p&gt;You can put the translation first, and then the rotation, but have the translation happen in the direction of the cow's head. To do that, you need a vector from the center of the cow to its head. Then you need the length of the translation. You can then do the translation in that direction. Like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float direction_x;&#xA;float direction_y;&#xA;float direction_z;&#xA;direction_x = cow_head_x - cow_center_x;&#xA;direction_y = cow_head_y - cow_center_y;&#xA;direction_z = cow_head_z - cow_center_z;&#xA;&#xA;// find the length of the direction vector&#xA;float dir_length = sqrt(direction_x * direction_x + direction_y * direction_y + direction_z * direction_z);&#xA;&#xA;// normalize the direction vector by dividing by the length&#xA;direction_x /= dir_length;&#xA;direction_y /= dir_length;&#xA;direction_z /= dir_length;&#xA;&#xA;// Create a new vector pointing in the correct direction with the same&#xA;// length as the drag&#xA;float cow_translate_x = direction_x * drag_length;&#xA;float cow_translate_y = direction_y * drag_length;&#xA;float cow_translate_z = direction_z * drag_length;&#xA;&#xA;// Do the transformation&#xA;glTranslatef(cow_translate_x, cow_translate_y, cow_translate_z);&#xA;glRotate(angle, rotate_x, rotate_y, rotate_z);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You could also get the direction vector by converting the angles to a direction. For example, if the rotation is only around the Y-axis, you could calculate it by doing the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float direction_x;&#xA;float direction_y;&#xA;float direction_z;&#xA;direction_x = cos(angle);&#xA;direction_y = 0.0; // since we're rotating around the Y axis&#xA;direction_z = sin(angle);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In this case, the direction vector is already normalized.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do have rotations around all 3 axes, you can calculate the direction vector using &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_coordinate_system&quot; rel=&quot;nofollow noreferrer&quot;&gt;spherical coordinates&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;direction_x = sin(angle) * cos(phi);&#xA;direction_y = sin(angle) * sin(phi);&#xA;direction_z = cos(angle);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;angle&lt;/code&gt; is the rotation around the y axis and &lt;code&gt;phi&lt;/code&gt; is the angle above/below the x/z plane. The direction should already be normalized in this case, too.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-10-15T18:01:19.500" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5734" PostTypeId="2" ParentId="5727" CreationDate="2017-10-16T13:30:35.757" Score="3" Body="&lt;p&gt;The 1994 game &lt;a href=&quot;http://ecstatica.wikia.com/wiki/Ecstatica&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ecstatica&lt;/a&gt; and its 1997 sequel rendered ellipsoid segments instead of triangles, but I don't think anyone else has ever used this exact technique. Direct raytracing of Bézier patches was a popular research topic in production graphics a few years ago, but the industry has moved onto polygon mesh subdivision. Subdivision gives much more predictable results for artists, and polygon meshes are much easier to deal with inside the renderer.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I've been thinking about making my own 3D rendering engine in C++, but I don't know much about math that's required to do it.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I hope you're up for learning lots of linear algebra, then. This is a great idea for a hobby project to learn from, but don't go into it thinking you can get by without learning any maths.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-10-16T13:30:35.757" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5735" PostTypeId="1" AcceptedAnswerId="5737" CreationDate="2017-10-16T18:07:00.383" Score="6" ViewCount="335" Body="&lt;p&gt;I need to draw a logarithmic spiral (or close approximation) whose vertices are equally spaced, such that the lines between any two consecutive vertices are of equal length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Actually, that spiral is just the basis for something a little more complex, but equally spaced incrementation is what matters right now.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The basis for the spiral is&#xA;$$r=e^{0.25 \theta}$$&#xA;where $r$ is the radius and $\theta$ is the angle from the $x$ axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it's easy to step around the spiral by a given angle, but obviously the actual length of any line between two vertices (defined by change in angle $\Delta\theta$) will vary with the radius.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I step along the arc of the spiral by a set length (say $0.1$ arbitrary units) and get the right coordinates (polar or Cartesian)?&lt;/p&gt;&#xA;" OwnerUserId="7490" LastActivityDate="2017-10-18T00:09:29.823" Title="Logarithmic spiral with equal vertex spacing, what equations?" Tags="&lt;mathematics&gt;&lt;geometry&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5736" PostTypeId="2" ParentId="5731" CreationDate="2017-10-17T00:35:59.907" Score="2" Body="&lt;p&gt;I think the best way to tackle this problem would be to make an algorithm that works on a single triangle at a time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'd look at each terrain triangle individually that the road intersected and process it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at one triangle individually, you would have to chop that triangle into one or more meshes to make it contour to the road.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some of the cases to consider in the image below.  I'm betting there is some triangle slicing algorithm that would be suited to this, and I'm not sure of a name off hand, but the main contribution I'm proposing here is that you deal with triangles individually.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qZVx4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qZVx4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When cutting the triangle on the x/y plane to make a hole for for the road, you would also want the terrain to take on the z value (height) of the road, for those vertices that touch the road.  This will make the terrain rise up to meet the road.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At this point, you'd have a terrain mesh which did conform to the road but it would be ugly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of having a nice even looking hill that went up to the road at reasonable slopes, you'd have some triangles that went very sharply up to the road, and others that had a very flat slope.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you would need to do now is do some kind of &quot;relaxation&quot; algorithm to address this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, if something is too steep, because there wasn't enough triangle to make the height adjustment, you need to make your whole triangle closer in height to the road and bleed off some of the height adjustment to neighboring triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If something was not steep enough for your liking, because there was a lot of triangle to make a small height adjustment, you may want to break the triangle up into more polygons where it gets closer to the road and have that smaller area handle the change in elevation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;During this second step, when you added a vertex to an edge between two triangles you would also need to adjust the triangle that shares the edge to prevent cracks from showing up in the terrain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The details are a bit vague, but hopefully the two step approach will help you tackle the problem.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Make the terrain mesh adapt to the road, without caring about how it looks.&lt;/li&gt;&#xA;&lt;li&gt;Refine the terrain mesh to make it appear to meet the road in a more organic man made way.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-10-18T16:36:39.667" LastActivityDate="2017-10-18T16:36:39.667" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5737" PostTypeId="2" ParentId="5735" CreationDate="2017-10-17T00:57:31.683" Score="9" Body="&lt;p&gt;Since a logarithmic spiral is defined by &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$r=e^{a\cdot\theta}$, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;the inverse of the equation is this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\theta=\frac{\ln{r}}{a}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we want to be able to control our step value, we can multiply it by a scalar ($a\cdot k$) before taking the logarithm, like so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\theta=\frac{\ln (ak\cdot r)}{a}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, if we take the natural log of theta multiplied by the scalar and $a$, then divide the whole thing by $a$ before plugging it in to the equation, we will get equally stepped vertices on the logarithmic spiral. Image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7r77U.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7r77U.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I generated this with some JavaScript code, which you can find in this &lt;a href=&quot;https://jsfiddle.net/anonymousey22/3rxhya8g/6/&quot; rel=&quot;nofollow noreferrer&quot;&gt;JSFiddle&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also try it out interactively on &lt;a href=&quot;https://www.desmos.com/calculator/qaoovzi6pk&quot; rel=&quot;nofollow noreferrer&quot;&gt;Desmos&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This looks good initially, but let's analyze what's going on here a little deeper. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a list of the distance between each consecutive pair of points, starting at the origin and spiraling outward:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;20.6834877876017&#xA;25.8265879847751&#xA;27.3020264943519&#xA;27.9155365639631&#xA;28.2274404549991&#xA;28.4072329605331&#xA;28.5201842104742&#xA;28.5957343926866&#xA;28.6487385499231&#xA;28.6873487186944&#xA;28.7163404861061&#xA;28.7386617798632&#xA;28.7562121095165&#xA;28.7702600892245&#xA;28.7816791255158&#xA;28.7910864406300&#xA;28.7989282185451&#xA;28.8055334775293&#xA;28.8111491387549&#xA;28.8159634339811&#xA;28.8201218817722&#xA;28.8237384111142&#xA;28.8269032465565&#xA;28.8296885891879&#xA;28.8321527704665&#xA;28.8343433306399&#xA;28.8362993285731&#xA;28.8380530946981&#xA;28.8396315754034&#xA;28.8410573741728&#xA;28.8423495651939&#xA;28.8435243345428&#xA;28.8445954894748&#xA;28.8455748659368&#xA;28.8464726569062&#xA;28.8472976786488&#xA;28.8480575879711&#xA;28.8487590604974&#xA;28.8494079377702&#xA;28.8500093492502&#xA;28.8505678139929&#xA;28.8510873257846&#xA;28.8515714247378&#xA;28.8520232577561&#xA;28.8524456298024&#xA;28.8528410475339&#xA;28.8532117565801&#xA;28.8535597734869&#xA;28.8538869132081&#xA;28.8541948128041&#xA;28.8544849519687&#xA;28.8547586708355&#xA;28.8550171854833&#xA;28.8552616014621&#xA;28.8554929256347&#xA;28.8557120765606&#xA;28.8559198936319&#xA;28.8561171451194&#xA;28.8563045352784&#xA;28.8564827106597&#xA;28.8566522656712&#xA;28.8568137475608&#xA;28.8569676608282&#xA;28.8571144711722&#xA;28.8572546090145&#xA;28.8573884726640&#xA;28.8575164311457&#xA;28.8576388267439&#xA;28.8577559773038&#xA;28.8578681782850&#xA;28.8579757046362&#xA;28.8580788124715&#xA;28.8581777406078&#xA;28.8582727119331&#xA;28.8583639346897&#xA;28.8584516035825&#xA;28.8585359008445&#xA;28.8586169971792&#xA;28.8586950526148&#xA;28.8587702173116&#xA;28.8588426322609&#xA;28.8589124299770&#xA;28.8589797350751&#xA;28.8590446648521&#xA;28.8591073297703&#xA;28.8591678339633&#xA;28.8592262756316&#xA;28.8592827474659&#xA;28.8593373370150&#xA;28.8593901270040&#xA;28.8594411956751&#xA;28.8594906170532&#xA;28.8595384612331&#xA;28.8595847946223&#xA;28.8596296801627&#xA;28.8596731775581&#xA;28.8597153434631&#xA;28.8597562316691&#xA;28.8597958932898&#xA;28.8598343768895&#xA;28.8598717286685&#xA;28.8599079925824&#xA;28.8599432104601&#xA;28.8599774221564&#xA;28.8600106656362&#xA;28.8600429770912&#xA;28.8600743910437&#xA;28.8601049404189&#xA;28.8601346566671&#xA;28.8601635697958&#xA;28.8601917084984&#xA;28.8602191001836&#xA;28.8602457710551&#xA;28.8602717461905&#xA;28.8602970495771&#xA;28.8603217041829&#xA;28.8603457319945&#xA;28.8603691540817&#xA;28.8603919906349&#xA;28.8604142610140&#xA;28.8604359837728&#xA;28.8604571767236&#xA;28.8604778569632&#xA;28.8604980408853&#xA;28.8605177442508&#xA;28.860536982199 &#xA;28.8605557692684&#xA;28.8605741194424&#xA;28.8605920461606&#xA;28.8606095623542&#xA;28.8606266804642&#xA;28.8606434124606&#xA;28.8606597698673&#xA;28.8606757637894&#xA;28.8606914049092&#xA;28.8607067035307&#xA;28.8607216695845&#xA;28.8607363126319&#xA;28.8607506419126&#xA;28.8607646663229&#xA;28.8607783944441&#xA;28.8607918345695&#xA;28.8608049947040&#xA;28.8608178825589&#xA;28.8608305056052&#xA;28.8608428710407&#xA;28.8608549858324&#xA;28.8608668567086&#xA;28.8608784901671&#xA;28.8608898925065&#xA;28.8609010698021&#xA;28.8609120279379&#xA;28.8609227726126&#xA;28.8609333093227&#xA;28.8609436434116&#xA;28.8609537800355&#xA;28.8609637242006&#xA;28.8609734807368&#xA;28.8609830543426&#xA;28.8609924495660&#xA;28.8610016707985&#xA;28.8610107223272&#xA;28.8610196082769&#xA;28.8610283326623&#xA;28.8610368993920&#xA;28.8610453122201&#xA;28.8610535748236&#xA;28.8610616907611&#xA;28.8610696634759&#xA;28.8610774963191&#xA;28.8610851925415&#xA;28.8610927553168&#xA;28.8611001876897&#xA;28.8611074926601&#xA;28.8611146731067&#xA;28.8611217318631&#xA;28.8611286716494&#xA;28.8611354951266&#xA;28.8611422048820&#xA;28.8611488034280&#xA;28.8611552932030&#xA;28.8611616766001&#xA;28.8611679559112&#xA;28.8611741333984&#xA;28.8611802112609&#xA;28.8611861916049&#xA;28.8611920765250&#xA;28.8611978680366&#xA;28.8612035681006&#xA;28.8612091786388&#xA;28.8612147015119&#xA;28.8612201385397&#xA;28.8612254914896&#xA;28.8612307620868&#xA;28.8612359520116&#xA;28.8612410629093&#xA;28.8612460963629&#xA;28.8612510539384&#xA;28.8612559371502&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first data point is an outlier caused by the spiral almost &quot;lapping&quot; itself. As the spiral progresses, we can see the the distances get closer and closer to the same distance. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is because we are sampling the curve in increments that cause equal lengths along the curve, not equal lengths between consecutive points. As the spiral gets bigger and bigger, the curve will get shallower and shallower, so the distances will get closer and closer to each other. &lt;/p&gt;&#xA;" OwnerUserId="7431" LastEditorUserId="7431" LastEditDate="2017-10-18T00:09:29.823" LastActivityDate="2017-10-18T00:09:29.823" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5738" PostTypeId="1" AcceptedAnswerId="5739" CreationDate="2017-10-17T09:02:32.130" Score="1" ViewCount="2077" Body="&lt;p&gt;Can you explain me what a nonrigid motion is?&#xA;In German it would be a &quot;unbewegliche Bewegung&quot; but I think it has to be translated in a different way.&#xA;I could imagine that it means something like the scene window is moving but the elements in the scene are staying in the same position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read it in the context of a paper about quantitative optic flow comparison. &lt;/p&gt;&#xA;" OwnerUserId="3274" LastEditorUserId="3274" LastEditDate="2017-10-17T11:38:47.797" LastActivityDate="2019-10-17T22:38:02.253" Title="What is a nonrigid motion?" Tags="&lt;motion&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5739" PostTypeId="2" ParentId="5738" CreationDate="2017-10-17T16:34:12.210" Score="3" Body="&lt;p&gt;Generally a non-rigid transformation is motion that doesn't preserve the shape of objects. If you look at a typical transformation matrix, rigid transformations would include translation, rotation, and reflection. Things like shear, uniform or non-uniform scale, and perspective would be non-rigid. Shear and scale would fall into the category of affine transformations, and perspective is of course perspective transformation. So there's a hierarchy of types of transformations:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Rigid_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rigid transforms&lt;/a&gt; - translation, reflection, and rotation. These perserve the distances between every pair of points on objects.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Affine_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Affine transforms&lt;/a&gt; - rigid + shear and (possibly non-uniform) scale&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/3D_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Perspective transforms&lt;/a&gt; - Affine plus perspective transforms (think of a rectangle rotated around the upward pointing axis - the part closer to the camera/viewer may be larger than the pre-transformed object, and the part farther away may be smaller)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I haven't done a lot with optical flow, but I would guess that as you figure out the path of motion of various points on an object, you would be able to classify them into one of the above categories. If all the points in an object move in tandem, then you probably have rotation and/or translation only (rigid transforms), but if they don't then you may have an affine or perspective transform between the points.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-10-17T16:34:12.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5740" PostTypeId="1" AcceptedAnswerId="5741" CreationDate="2017-10-17T18:32:27.180" Score="3" ViewCount="1132" Body="&lt;p&gt;I'm trying to follow along with a tutorial that uses an OpenGL compute shader, but I'm using D3D11. What they do is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout (std430, binding = 0) buffer indices {&#xA;    int j[];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have no experience with this and very little with directX, but that looks like a buffer of integer arrays. I've looked around and read that the equivalent to this OpenGL buffer in D3D11 is an RWBuffer. Using a compute shader, this is what I've tried. Note, I didn't redefine them in my code as they appear here, I just listed them together here.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RWBuffer indices&#xA;{&#xA;    int j[];&#xA;}&#xA;&#xA;RWBuffer&amp;lt;{int j[];}&amp;gt; indices;&#xA;&#xA;struct index&#xA;{&#xA;    //requires explicit length, which is why this doesn't work&#xA;    int j[];&#xA;}&#xA;RWStructuredBuffer&amp;lt;index&amp;gt; indices;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But, none of those worked. The end goal is to access them like so:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//id is SV_DispatchThreadID&#xA;indices.j[int(id.y)]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This seems like an inappropriately simple question to post, but I wasn't able to find documentation, even on MSDN, on defining buffers and what's allowed and not, etc.&lt;/p&gt;&#xA;" OwnerUserId="7492" LastActivityDate="2017-10-17T19:01:59.660" Title="Buffer of arrays in HLSL compute shader" Tags="&lt;directx11&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5741" PostTypeId="2" ParentId="5740" CreationDate="2017-10-17T19:01:59.660" Score="3" Body="&lt;p&gt;It looks to me like you want a buffer containing a single array of integers (not a buffer containing multiple arrays, whatever that would mean). So, you should be able to just do this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RWBuffer&amp;lt;int&amp;gt; indices;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then access it like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;indices[int(id.y)]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-10-17T19:01:59.660" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5742" PostTypeId="1" CreationDate="2017-10-18T00:27:37.427" Score="2" ViewCount="1511" Body="&lt;p&gt;I have discovered that there are two ways to update the viewport (might be more, but not sure). Currently I am rebuilding the Pipeline when I resize my screen but there is a noticeable stutter as it rebuilds, but I have also found out that you can use &lt;code&gt;vkCmdSetViewport&lt;/code&gt; when building/rebuilding your command buffers. But is this the right way to do it? And if I used &lt;code&gt;vkCmdSetViewport&lt;/code&gt;, what should be put into the &lt;code&gt;VkGraphicsPipelineCreateInfo pViewportState&lt;/code&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there is an even better way of handling screen resizing please let me know.&lt;/p&gt;&#xA;" OwnerUserId="7497" LastEditorUserId="2287" LastEditDate="2017-10-20T16:31:02.093" LastActivityDate="2017-10-20T16:31:02.093" Title="Vulkan best way of updating pipeline viewport" Tags="&lt;c++&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5743" PostTypeId="2" ParentId="5742" CreationDate="2017-10-18T03:43:39.957" Score="3" Body="&lt;p&gt;Both suggested methods are fine, but they should be preferred in certain situations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Dynamic state should be preferred in situations where you have many, perhaps thousands of, pipeline objects or you need to change the resolution often (such as in some sort of windowed tool. The downside to this is that it may reduce runtime performance since the driver may not be able apply optimizations for this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having the viewport only defined when building the pipeline objects might be more appropriate for games or simulators where you don't change the resolution often. Of course, when the viewport does change, it hits performance hard during resizing. This also has the drawback of needing to generate new pipeline objects, which could be especially problematic if you cache pipelines in a hash table of something similar.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastActivityDate="2017-10-18T03:43:39.957" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5745" PostTypeId="2" ParentId="4919" CreationDate="2017-10-18T17:17:33.690" Score="0" Body="&lt;p&gt;Typically you would search for voxels with specific features, e.g. using thresholding and create your model as an isosurface made of the particles corresponding to those voxels..MRI images are dense 3 dimensional matrices, and without prior anatomical perprocessing or voxel selection you will endup with a dense cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;you can check ITK Snap, it is a free tool reading NII and DCM images and using different techniques it would build basic 3D models  &lt;/p&gt;&#xA;" OwnerUserId="7504" LastActivityDate="2017-10-18T17:17:33.690" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5746" PostTypeId="1" AcceptedAnswerId="5748" CreationDate="2017-10-18T17:42:55.073" Score="3" ViewCount="97" Body="&lt;p&gt;&lt;strong&gt;Perspective Camera&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A (row-major) perspective transformation matrix has the following format:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{align} \mathrm{T} &#xA;&amp;amp;= \begin{bmatrix} &#xA;\mathrm{T}_{00} &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;\mathrm{T}_{11} &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{22} &amp;amp;1 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{32} &amp;amp;0 \end{bmatrix}=\begin{bmatrix} 1/x &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ 0 &amp;amp;1/y &amp;amp;0 &amp;amp;0 \\ 0 &amp;amp;0 &amp;amp;-w &amp;amp;1 \\ 0 &amp;amp;0 &amp;amp;z &amp;amp;0\end{bmatrix}. &#xA;\end{align}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This transformation matrix is used to transform (&lt;em&gt;homogeneous&lt;/em&gt;) points from view to projection space, after which the homogeneous divide is applied to transform to NDC (Normalized Device Coordinate) space. (&lt;em&gt;NDC space is technically a 3D space, but for ease of notation, I use 4D points with a $w=1$&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a deferred renderer, we need to go the other way around while resolving the GBuffer and could use four components ($x$, $y$, $z$, $w$, see above) to transform a point from NDC to view space:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/**&#xA; Returns the projection values from the given projection matrix to construct&#xA; the view position coordinates from the NDC position coordinates.&#xA;&#xA; @return    The projection values from the given projection matrix to&#xA;            construct the view position coordinates from the NDC position&#xA;            coordinates.&#xA; */&#xA;inline const XMVECTOR XM_CALLCONV GetViewPositionConstructionValues(&#xA;    FXMMATRIX projection_matrix) noexcept {&#xA;    //        [ 1/X  0   0  0 ]&#xA;    // p_view [  0  1/Y  0  0 ] = [p_view.x 1/X, p_view.y 1/Y, p_view.z (-W) + Z, p_view.z] = p_proj&#xA;    //        [  0   0  -W  1 ]&#xA;    //        [  0   0   Z  0 ]&#xA;    //&#xA;    // p_proj / p_proj.w        = [p_view.x/p_view.z 1/X, p_view.y/p_view.z 1/Y, -W + Z/p_view.z, 1] = p_ndc&#xA;    //&#xA;    // Construction of p_view from p_ndc and projection values&#xA;    // 1) p_ndc.z = -W + Z/p_view.z       &amp;lt;=&amp;gt; p_view.z = Z / (p_ndc.z + W)&#xA;    // 2) p_ndc.x = p_view.x/p_view.z 1/X &amp;lt;=&amp;gt; p_view.x = X * p_ndc.x * p_view.z&#xA;    // 3) p_ndc.y = p_view.y/p_view.z 1/Y &amp;lt;=&amp;gt; p_view.y = Y * p_ndc.y * p_view.z&#xA;&#xA;    const F32 x = 1.0f / XMVectorGetX(projection_matrix.r[0]);&#xA;    const F32 y = 1.0f / XMVectorGetY(projection_matrix.r[1]);&#xA;    const F32 z = XMVectorGetZ(projection_matrix.r[3]);&#xA;    const F32 w = -XMVectorGetZ(projection_matrix.r[2]);&#xA;&#xA;    return XMVectorSet(x, y, z, w);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Orthographic Camera&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An (row-major) orthographic transformation matrix has the following format:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{align} \mathrm{T} &#xA;&amp;amp;= \begin{bmatrix} &#xA;\mathrm{T}_{00} &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;\mathrm{T}_{11} &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{22} &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{32} &amp;amp;1 \end{bmatrix}=\begin{bmatrix} 1/x &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ 0 &amp;amp;1/y &amp;amp;0 &amp;amp;0 \\ 0 &amp;amp;0 &amp;amp;1/z &amp;amp;0 \\ 0 &amp;amp;0 &amp;amp;-w &amp;amp;1\end{bmatrix}. &#xA;\end{align}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This transformation matrix is used to transform (&lt;em&gt;homogeneous&lt;/em&gt;) points from view to projection space, after which the homogeneous divide (no-op) is applied to transform to NDC (= projection) space. (&lt;em&gt;So basically a non-uniform scaling followed by a translation of the z component&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We could similarly use four components ($x$, $y$, $z$, $w$, see above) to transform a point from NDC (= projection) to view space:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/**&#xA; Returns the projection values from the given projection matrix to construct &#xA; the view position coordinates from the NDC position coordinates.&#xA;&#xA; @return        The projection values from the given projection matrix to &#xA;                construct the view position coordinates from the NDC position &#xA;                coordinates.&#xA; */&#xA;inline const XMVECTOR XM_CALLCONV GetViewPositionConstructionValues(&#xA;    FXMMATRIX projection_matrix) noexcept {&#xA;&#xA;    //        [ 1/X  0   0  0 ]&#xA;    // p_view [  0  1/Y  0  0 ] = [p_view.x 1/X, p_view.y 1/Y, p_view.z 1/Z -W, 1] = p_proj = p_ndc&#xA;    //        [  0   0  1/Z 0 ]&#xA;    //        [  0   0  -W  1 ]&#xA;    //&#xA;    // Construction of p_view from p_ndc and projection values&#xA;    // 1) p_ndc.z = p_view.z/Z -W &amp;lt;=&amp;gt; p_view.z = Z * (p_ndc.z + W)&#xA;    // 2) p_ndc.x = p_view.x/X    &amp;lt;=&amp;gt; p_view.x = X * p_ndc.x&#xA;    // 3) p_ndc.y = p_view.y/Y    &amp;lt;=&amp;gt; p_view.y = Y * p_ndc.y&#xA;&#xA;    const F32 x = 1.0f / XMVectorGetX(projection_matrix.r[0]);&#xA;    const F32 y = 1.0f / XMVectorGetY(projection_matrix.r[1]);&#xA;    const F32 z = 1.0f / XMVectorGetZ(projection_matrix.r[2]);&#xA;    const F32 w = -XMVectorGetZ(projection_matrix.r[3]);&#xA;&#xA;    return XMVectorSet(x, y, z, w);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can a deferred renderer support multiple camera types (minimally: perspective and orthographic cameras, ideally: all cameras that a forward renderer could support) without specializing the shaders or specializing in the shaders?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A straightforward solution is to specify some pre-processor directive in the shader, but this unfortunately results in a multiple of all the shader perturbations used so far for lighting in a deferred pipeline. Another solution is to pass a flag in some constant buffer to specify the used camera type, though I am not a fan of the dynamic branching introduced by this flag. Furthermore, both solutions are not as flexible as is the case for forward rendering which can handle arbitrary view-to-projection matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally, a (hypothetical) NDC-to-view transformation matrix should handle the transformation. Such a matrix does, however, not generally exist for perspective cameras since the view to NDC transformation reduces a 4D space to a 3D subspace.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorDisplayName="user7220" LastEditDate="2018-04-22T12:10:12.527" LastActivityDate="2018-04-22T12:10:12.527" Title="Supporting multiple camera types in a deferred renderer without specializing the shaders or in the shaders" Tags="&lt;transformations&gt;&lt;perspective&gt;&lt;rasterizer&gt;&lt;deferred-rendering&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5747" PostTypeId="1" AcceptedAnswerId="5749" CreationDate="2017-10-18T18:15:43.177" Score="4" ViewCount="252" Body="&lt;p&gt;Transparency can be achieved (or actually approximated) by using alpha-to-coverage (in case of MSAA) or basic alpha/transparency blending using the following approach:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Bind a rasterizer state with a Less-Equal comparison function.&lt;/li&gt;&#xA;&lt;li&gt;Bind no blend state.&lt;/li&gt;&#xA;&lt;li&gt;Render opaque geometry.&lt;/li&gt;&#xA;&lt;li&gt;Bind alpha-to-coverage or alpha/transparency blend state.&lt;/li&gt;&#xA;&lt;li&gt;Render transparent geometry.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Here, the sets of opaque and transparent geometry are mutually exclusive. The benefit of this approach is that geometry is only drawn once and the rasterization state does not need to change. Unfortunately, it could be possible to observe, through the semi-transparent holes of some double-sided object, that object itself. In this case there is no guarantee that fragments of this object would be blended with other fragments of this object, since the order in which the fragments are resolved is and should not be known.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another approach:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Bind a rasterizer state with a Less-Equal comparison function.&lt;/li&gt;&#xA;&lt;li&gt;Bind no blend state.&lt;/li&gt;&#xA;&lt;li&gt;Render all geometry and clip transparent fragments&lt;/li&gt;&#xA;&lt;li&gt;Bind a rasterizer state with a Less comparison function.&lt;/li&gt;&#xA;&lt;li&gt;Bind alpha-to-coverage or alpha/transparency blend state.&lt;/li&gt;&#xA;&lt;li&gt;Render transparent geometry.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Here, all transparent geometry is drawn twice. First, opaque fragments are processed by the pixel shader whereas transparent fragments are clipped inside the pixel shader. Second, opaque fragments will be discarded by the early-z-test of the rasterizer whereas transparent fragments are processed by the pixel shader (and blended afterwards). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both approaches have some differences, but the difference that concerns me the most is the latter approach having two variants of the pixel shader: one that clips transparent fragments and one that does not clip transparent fragments. In case of multiple pixel shaders, this approach will always result in a doubling of the number of pixel shaders. Is it possible to have the benefits of the second approach while having only one variant of the pixel shader?&lt;/p&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2017-10-18T20:04:57.427" Title="Avoid having an opaque and transparent variant of each pixel shader" Tags="&lt;rendering&gt;&lt;rasterizer&gt;&lt;transparency&gt;&lt;alpha&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5748" PostTypeId="2" ParentId="5746" CreationDate="2017-10-18T19:58:55.687" Score="4" Body="&lt;p&gt;Projective transformations (represented by 4×4 projection matrices) are invertible. You can go from NDC coordinates back to view space using the inverse of the projection matrix, in the same way that you go from view space to NDC. That is: take your NDC $x, y, z$ coordinates, append $w = 1$ to make a 4D vector, transform by the inverse projection matrix, then divide out $w$ to get back to 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;View space and NDC space are both fundamentally 3D spaces, though with a 4D homogeneous representation, so the transformation between them doesn't throw away a dimension, despite the divide by $w$. (Some information &lt;em&gt;is&lt;/em&gt; lost, though: the sign of $w$, which corresponds to whether a point was behind or in front of the camera. However, this isn't usually a concern, since we cull or clip everything behind the camera during rasterization anyway.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the shader code, it can presumably be simplified according to which components may be nonzero in the inverse projection matrix. You may only need the $x, y$ diagonal elements and the lower-right 2×2 submatrix, as long as you don't need to support off-axis projections (which have additional nonzero components in their matrix).&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-10-18T19:58:55.687" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5749" PostTypeId="2" ParentId="5747" CreationDate="2017-10-18T20:04:57.427" Score="3" Body="&lt;p&gt;You can use a threshold set through a constant buffer to clip pixels (ie an alpha test):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float threshold; // in constant buffer&#xA;&#xA;float4 color = myTexture.Sample(...);&#xA;if (color.a &amp;lt; threshold)&#xA;    discard;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Set &lt;code&gt;threshold&lt;/code&gt; to 1.0 to discard all transparent fragments; set it to 0.0 to discard nothing. There will be some minor inefficency in the latter case compared to having a separate pixel shader with the alpha test removed entirely, but it shouldn't be a big deal on most GPUs nowadays.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-10-18T20:04:57.427" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5751" PostTypeId="1" CreationDate="2017-10-19T01:03:48.723" Score="1" ViewCount="37" Body="&lt;p&gt;I am trying to solve a problem in computer graphics but to do it I need to be able to see a comparison of geodesic lines and straigth line projections on the ellipsoid. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have not been able to figure out how to fing the mathematical definition of geodesics (linear projections are easy).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering if anybody has coded somehting like this already or is aware ofa  tool I could use?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2017-10-19T01:03:48.723" Title="Program to visualize geodesics and linear projection of an ellipsoid simultaneously" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;projections&gt;&lt;curve&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5752" PostTypeId="2" ParentId="5746" CreationDate="2017-10-19T11:44:45.513" Score="1" Body="&lt;p&gt;For completeness (and in addition to Nathan Reed's &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5748/2287&quot;&gt;answer&lt;/a&gt;), I explicitly add the inverse projection matrices for perspective and orthographic cameras.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Perspective Camera&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{align} &#xA;\mathrm{T}_{\mathrm{view \rightarrow projection}} &amp;amp;= \begin{bmatrix} &#xA;\mathrm{T}_{00} &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;\mathrm{T}_{11} &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{22} &amp;amp;1 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{32} &amp;amp;0 \end{bmatrix} \! , \\&#xA;\mathrm{T}_{\mathrm{projection \rightarrow view}} &amp;amp;=\begin{bmatrix} &#xA;1/\mathrm{T}_{00} &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;1/\mathrm{T}_{11} &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;0 &amp;amp;1/\mathrm{T}_{32} \\ &#xA;0 &amp;amp;0 &amp;amp;1 &amp;amp;-\mathrm{T}_{22}/\mathrm{T}_{32}\end{bmatrix} \! . &#xA;\end{align}$$&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        /**&#xA;         Returns the projection-to-view matrix of this perspective camera.&#xA;&#xA;         @return        The projection-to-view matrix of this perspective &#xA;                        camera.&#xA;         */&#xA;        virtual const XMMATRIX GetProjectionToViewMatrix() const noexcept override {&#xA;            const XMMATRIX view_to_projection = GetViewToProjectionMatrix();&#xA;&#xA;            const F32 m00 = 1.0f / XMVectorGetX(view_to_projection.r[0]);&#xA;            const F32 m11 = 1.0f / XMVectorGetY(view_to_projection.r[1]);&#xA;            const F32 m23 = 1.0f / XMVectorGetZ(view_to_projection.r[3]);&#xA;            const F32 m33 = -XMVectorGetZ(view_to_projection.r[2]) * m23;&#xA;&#xA;            return XMMATRIX {&#xA;                 m00, 0.0f, 0.0f, 0.0f,&#xA;                0.0f,  m11, 0.0f, 0.0f,&#xA;                0.0f, 0.0f, 0.0f,  m23,&#xA;                0.0f, 0.0f, 1.0f,  m33&#xA;            };&#xA;        }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Orthographic Camera&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{align} &#xA;\mathrm{T}_{\mathrm{view \rightarrow projection}} &amp;amp;= \begin{bmatrix} &#xA;\mathrm{T}_{00} &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;\mathrm{T}_{11} &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{22} &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;\mathrm{T}_{32} &amp;amp;1 \end{bmatrix} \! , \\&#xA;\mathrm{T}_{\mathrm{projection \rightarrow view}} &amp;amp;=\begin{bmatrix} &#xA;1/\mathrm{T}_{00} &amp;amp;0 &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;1/\mathrm{T}_{11} &amp;amp;0 &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;1/\mathrm{T}_{22} &amp;amp;0 \\ &#xA;0 &amp;amp;0 &amp;amp;-\mathrm{T}_{32}/\mathrm{T}_{22} &amp;amp;1\end{bmatrix} \! . &#xA;\end{align}$$&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        /**&#xA;         Returns the projection-to-view matrix of this orthographic camera.&#xA;&#xA;         @return        The projection-to-view matrix of this orthographic &#xA;                        camera.&#xA;         */&#xA;        virtual const XMMATRIX GetProjectionToViewMatrix() const noexcept override {&#xA;            const XMMATRIX view_to_projection = GetViewToProjectionMatrix();&#xA;&#xA;            const F32 m00 = 1.0f / XMVectorGetX(view_to_projection.r[0]);&#xA;            const F32 m11 = 1.0f / XMVectorGetY(view_to_projection.r[1]);&#xA;            const F32 m22 = 1.0f / XMVectorGetZ(view_to_projection.r[2]);&#xA;            const F32 m32 = -XMVectorGetZ(view_to_projection.r[3]) * m22;&#xA;&#xA;            return XMMATRIX {&#xA;                 m00, 0.0f, 0.0f, 0.0f,&#xA;                0.0f,  m11, 0.0f, 0.0f,&#xA;                0.0f, 0.0f,  m22, 0.0f,&#xA;                0.0f, 0.0f,  m32, 1.0f&#xA;            };&#xA;        }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2017-10-19T11:44:45.513" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5754" PostTypeId="1" CreationDate="2017-10-20T02:33:12.553" Score="6" ViewCount="490" Body="&lt;p&gt;I'm trying to render a particle simulation. I want each particle to leave a trace. To achieve this I'm using a framebuffer and two textures. On each frame the algorithm goes like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render to a framebuffer previously rendered screen texture with &lt;code&gt;opacity * 0.9&lt;/code&gt;;&lt;/li&gt;&#xA;&lt;li&gt;Render current particles at updated positions;&lt;/li&gt;&#xA;&lt;li&gt;Switch to main display and render current content of the framebuffer; &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This works fine, and I get nice looking particle trails:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2WLuA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2WLuA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Problem&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I want to allow users to pan and zoom canvas with these particles, similar to a map interface. This is achieved by applying a transformation matrix to each particle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to keep particle's state, but I don't want the pan/zoom to leave a particle trace:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Bad&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Here I'm dragging canvas up and down with mouse cursor. See how particles leave a trace?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1O5ZL.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1O5ZL.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Good&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Here I'm also dragging the canvas up and down, but particles remain on their trajectory, without leaving a pan trace:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Wp0hK.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wp0hK.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm wondering what is a proper way of achieving this? I got a basic solution working by applying a transformation to a previous frame's texture, so that it approximately matches what will be rendered in the current frame, but I there still a few artifacts:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;When zooming in, the updated texture &quot;explodes&quot;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CPHte.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CPHte.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume this is because I'm using fixed point size for a particle (regardless of the zoom level), but when we scale texture, we scale rasterized image, and thus all particles rendered on it also get bigger.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;When a particle enters the scene (crosses the border of visible area), it is also very likely to leave a trail:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fQPVB.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fQPVB.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure why this one happens. My screen/back textures are the same size, I'm just translating back texture. I thought it might be related to clamp_to_edge setting, but I don't know how to prove or validate this. I've got a workaround by extending canvas beyond visible area (say by 2%) and in the fragment shader I check that if particle is closer than 2% to the border - I give it transparent color. This kind of &quot;fixes&quot; the problem, but I feel uncomfortable not knowing why it's happening.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;Finally, if transformation is very-very small (think kinetic movement), I also observe artifacts:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/h1mpm.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/h1mpm.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd appreciate if you could explain some of these artifacts, suggest possible solutions, or general practices used to solve this problem.&lt;/p&gt;&#xA;" OwnerUserId="7512" LastEditorUserId="7512" LastEditDate="2017-10-20T04:47:37.027" LastActivityDate="2017-10-20T08:20:04.227" Title="Fading particles and transition" Tags="&lt;opengl&gt;&lt;webgl&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5757" PostTypeId="2" ParentId="5754" CreationDate="2017-10-20T08:20:04.227" Score="7" Body="&lt;p&gt;I made a visualization a little like yours years ago, and used a similar technique, because it's the natural approach to the problem. After I spent a few years writing drivers for modern GPUs, I wouldn't use this approach at all, because it creates a dependency from one frame to the next, which introduces pipeline stalls and/or false sharing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Today, I'd keep the path of the particle as part of its state, and render the whole trail each frame, instead of reusing the old FBO. It's conceptually a little more difficult, and you have to be careful that the way you draw the past path is exactly the same each frame. For example, if you represent the path with some kind of cubic spline, you can't just move the final control point forward, because it'll change the whole curve slightly. A circular buffer of (x, y) positions would be much easier to get right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you get in exchange for this extra complexity is (a) reduced frame time, memory use, and power consumption (which might be important if you're on mobile), and (b) you won't have your current problem at all. Maybe the frame time advantage won't be as big in WebGL, because you'll end up doing extra work in Javascript, which is slow, but memory bandwidth is more of a bottleneck on most systems. Just make sure that the co-ordinates you store are in the space of your simulation, and transform them into screen co-ordinates when you draw them, just like you would with a 3D scene.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-10-20T08:20:04.227" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5758" PostTypeId="1" AcceptedAnswerId="5761" CreationDate="2017-10-20T12:34:04.483" Score="8" ViewCount="1220" Body="&lt;p&gt;I'm wondering about the technique used when sampling a layered material for the next event in a path tracer. I have a material with three layers: a base diffuse, specular and sheen lobes. How does one go about choosing a discrete layer to sample for the next ray direction? Is this just a random selection? If so, are equal weights assigned to the layers or are weights used based on final contribution of a lobe? Thanks for any insight into this stage of sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;~M&lt;/p&gt;&#xA;" OwnerUserId="7516" LastActivityDate="2019-08-10T15:45:30.680" Title="Path Tracing &amp; Materials" Tags="&lt;pathtracing&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5759" PostTypeId="2" ParentId="5758" CreationDate="2017-10-20T16:46:53.423" Score="3" Body="&lt;p&gt;Thinking about it from a physical standpoint, it seems that it would work like a generalized version of diffuse / specular calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'd start with the top most layer and use fresnel etc to calculate a percentage of light that reflects vs transmits.  You then use a random number to determine which of these to do for your sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of reflection, you'd do the specular lobe of your top most layer, reflect off the surface and move on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of transmission, you'd move to the 2nd layer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At this layer, you'd once again calculate the percentage chance to reflect vs transmit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of reflection, you'd use the specular lobe of this second layer, do the reflection and move on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of transmission, you'd move to the inner layer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this inner most layer you'd once again figure out if you needed to reflect or transmit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For reflection you'd use this inner layer's specular lobe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For transmission, you'd do your diffuse calculation, or whatever else your inner most surface wants to do for transmitted light (sub surface scattering? refraction? etc).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm uncertain if each layer should do it's own refraction and if technically you should move the ray a tiny bit between layers to get more realistic effects.  For your case it may not make a difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But basically, if you had a sphere with 3 layers on it, it SHOULD behave as if you had 3 different spheres nested in one another that each had a single layer that handled transmission vs reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having a layered material is just a more compact way of saying that this is what you want, compared to having the three separate objects.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-10-20T16:46:53.423" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5760" PostTypeId="1" AcceptedAnswerId="5767" CreationDate="2017-10-20T22:57:26.113" Score="4" ViewCount="108" Body="&lt;p&gt;I'm re-learning WebGL, and I stumbled upon &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer&quot; rel=&quot;noreferrer&quot; title=&quot;gl.vertexAttribPointer&quot;&gt;gl.vertexAttribPointer&lt;/a&gt; and &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttrib&quot; rel=&quot;noreferrer&quot; title=&quot;gl.vertexAttrib&quot;&gt;gl.vertexAttrib&lt;/a&gt;. To my knowledge, gl.vertexAttribPointer tells the GPU how the data in the currently binded buffer relates to the vertex attributes. But, I'm confused on what gl.vertexAttrib does. It seems like it also sends data to the GPU, but without the use of a buffer. Can anybody explain it's role to me?&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-10-22T20:22:43.393" Title="Role of gl.vertexAttrib" Tags="&lt;shader&gt;&lt;webgl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5761" PostTypeId="2" ParentId="5758" CreationDate="2017-10-21T03:56:19.317" Score="13" Body="&lt;p&gt;This question is somewhat related to &lt;a href=&quot;https://computergraphics.stackexchange.com/q/4611/5681&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Alan has already said, following the actual light path through each layer leads to more physically accurate results. I will base my answer on a paper by Andrea Weidlich and Alexander Wilkie (&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1321292&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;Arbitrarily Layered Micro-Facet Surfaces&quot;&lt;/a&gt;) that I have read and partially implemented. In the paper the authors assume that the distance between two layers is smaller than the radius of a differential area element. This assumption simplifies the implementation because we do not have to calculate intersection points separately for each layer, actually we assume that all intersection points over the layers are just the same point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to the paper, two problems must be solved in order to render multilayered material. The first one is to properly sample the layers and the second is to find the resulting BSDF generated by the combination of the multiple BSDFs that are found along the sampling path. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; Actually I have adopted a different method to implement the evaluation of this layered model. While I have kept with the idea of considering the intersection points to be just the same point along the layers, I have computed the sampling and the final BRDF differently: for sampling, I have used ordinary ray tracing, but through the layers (using Russian Roulette to select between reflection/refraction when that's the case); for the final BRDF evaluation, I just multiply each BRDF traversed by the ray path (weighting the incident radiances according to the cosine of the incident ray).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Sampling&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this first stage we will determine the actual light path through the layers. When a light ray is moving from a less dense medium, e.g. air, to a denser medium, e.g. glass, part of its energy is reflected and the remaining part is transmitted. You can find the amount of energy that is reflected through the &lt;a href=&quot;https://en.wikipedia.org/wiki/Fresnel_equations&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fresnel reflectance equations&lt;/a&gt;. So, for instance, if the Fresnel reflectance of a given dielectric is 0.3, we know that 30% of the energy is reflected and 70% will be transmitted:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/S4zHY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S4zHY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the light ray is moving from a denser to a less dense medium, the same principle described by the Fresnel reflectance applies. However, in this specific case, &lt;a href=&quot;https://en.wikipedia.org/wiki/Total_internal_reflection&quot; rel=&quot;nofollow noreferrer&quot;&gt;total internal reflection&lt;/a&gt; (a.k.a TIR) might also happen if the angle of the incident ray is above the critical angle. In the case of TIR, 100% of the energy is reflected back into the material:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Li0lu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Li0lu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When light hits a conductor or a diffuse surface, it will always be reflected (being the direction of reflection related to the type of the BRDF). In a multilayer material, the resulting light path will be the aggregate result of all those possibilities. Thus, in the case of a 3-layer material, assuming that the first and second layers are dielectrics and the third layer is diffuse, we might end up, for instance, with the following light path (a tree actually):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WBz0l.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WBz0l.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can simulate this type of interaction using recursion and weighting each light path according to the actual reflectance/transmitance at the corresponding incident points. A problem regarding the use of recursion in this case is that the number of rays increases with the deepness of the recursion, concentrating computational effort on rays that individually might contribute almost nothing to the final result. On the other hand, the aggregate result of those individual rays at deep recursion levels can be significant and should not be discarded. In this case, we can use Russian Roulette (RR) in order to avoid branching and to probabilistic end light paths without losing energy, but at the cost of a higher variance (noisier result). In this case, the result of the Fresnel reflectance, or the TIR, will be used to randomly select which path to follow. For instance:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/t5ewd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t5ewd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As can be seen, TIR or Fresnel reflectance might keep some rays bouncing indefinitely among layers. As far as I know, &lt;a href=&quot;https://www.mitsuba-renderer.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitsuba&lt;/a&gt; implements plastic as a two layer material, and it uses a closed form solution for this specific case that accounts for an infinity number of light bounces among layers. However, Mitsuba also allows for the creation of multilayer materials with an arbitrary number of layers, in which case it imposes a maximum number of internal bounces since no closed form solution seems to exist for the general case. As a side effect, some energy can be lost in the rendering process, making the material look darker than it should eventually be. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my current multilayer material implementation I allow for an arbitrary number of internal bounces at the cost of longer rendering times (well... actually, I've implemented only two layers.. one dielectric and one diffuse :).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An additional option is to mix branching and RR. For instance, the initial rays (lower deep levels) might present substantial contribution to the final image. Thus, one might choose to branch only at the first one or two intersections, using only RR afterwards. This is, for example, the approached used by &lt;a href=&quot;http://www.kevinbeason.com/smallpt&quot; rel=&quot;nofollow noreferrer&quot;&gt;smallpt&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An interesting point regarding multilayered materials is that individual reflected/transmitted rays can be importance sampled according to the corresponding BRDFs/BTDFs of each layer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Evaluating the Final BSDF&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Considering the following light path computed using RR:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GWv6b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GWv6b.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can evaluate the total amount of radiance &lt;span class=&quot;math-container&quot;&gt;$L_r$&lt;/span&gt; reflected by a multilayer BSDF considering each layer as a individual object and applying the same approach used in ordinary path tracing (i.e. the radiance leaving a layer will be the incident radiance for the next layer). The final estimator can thus be represented by the product of each individual Monte Carlo estimator:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ L_r =  \left( \frac{fr_1 \cos \theta_1}{pdf_1}  \left( \frac{fr_2 \cos \theta_2}{pdf_2} \left( \frac{fr_3 \cos \theta_3}{pdf_3} \left( \frac{fr_2 \cos \theta_4}{pdf_2} \left( \frac{L_i fr_1 \cos \theta_5}{pdf_1} \right)\right)\right)\right)\right)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since all terms of the estimator are multiplied, we can simplify the implementation by computing the final BSDF and &lt;span class=&quot;math-container&quot;&gt;$pdf$&lt;/span&gt; and factoring out the &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; term:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$fr = fr_1 \cdot fr_2 \cdot fr_3 \cdot fr_2 \cdot fr_1$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$pdf = pdf_1 \cdot pdf_2 \cdot pdf_3 \cdot pdf_2 \cdot pdf_1$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\cos \theta= \cos \theta_1 \cdot \cos \theta_2 \cdot \cos \theta_3 \cdot \cos \theta_2 \cdot \cos \theta_1$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ L_r =  \left( \frac{fr \cos \theta}{pdf} \right) L_i$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1321292&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; by Andrea Weidlich and Alexander Wilkie also takes absorption into consideration, i.e. each light ray might be attenuated according to the absorption factor of each transmissive layer and its thickness. I've not included absorption into my renderer yet, but it is represented by just one scalar value, which will be evaluated according to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law&quot; rel=&quot;nofollow noreferrer&quot;&gt;Beer's Law&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Alternate approaches&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Mitsuba renderer uses an alternate representation for multilayered material based on the &quot;tabulation of reflectance functions in a Fourier basis&quot;. I have not yet dig into it, but might be of interest: &quot;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2601139&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Comprehensive Framework for Rendering Layered Materials&lt;/a&gt;&quot; by Wenzel Jacob &lt;em&gt;et al&lt;/em&gt;. There is also an expanded version of this paper.&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorDisplayName="user5681" LastEditDate="2019-08-10T15:45:30.680" LastActivityDate="2019-08-10T15:45:30.680" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="5762" PostTypeId="1" AcceptedAnswerId="5763" CreationDate="2017-10-21T11:00:02.030" Score="5" ViewCount="360" Body="&lt;p&gt;In their &lt;a href=&quot;https://www.slideshare.net/DICEStudio/physically-based-and-unified-volumetric-rendering-in-frostbite&quot; rel=&quot;noreferrer&quot;&gt;presentation&lt;/a&gt; at SIGGRAPH 2015 Electronic Arts presented method of volumetric rendering using 3D texture aligned with view frustum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This technique needs two steps:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Injection of color and density into 3D texture,&lt;/li&gt;&#xA;&lt;li&gt;Integration along Z axis of texture.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Integration code example is on slide 27. However, it is stated as being wrong. Do anyone can explain what is wrong with that (pretty standard raymarching integration) code?&lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2017-10-22T22:10:35.020" Title="Volumetric integration in Frostbite" Tags="&lt;raymarching&gt;&lt;3dtexture&gt;&lt;volumetric-scattering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5763" PostTypeId="2" ParentId="5762" CreationDate="2017-10-21T16:19:08.130" Score="6" Body="&lt;p&gt;What is wrong with it seems to be explained on the next two slides: it leads to non-energy-conserving results, where the apparent brightness of the volume changes depending on the scattering coefficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My read of it is that the &quot;wrong&quot; integration code implicitly assumes a constant transmittance over the extent of each voxel. But the trouble is, when the scattering coefficient is high, the transmittance will fall off significantly within a single voxel. For instance, if you have voxels of size 10 cm, but the scattering coefficient is 1 / (5 cm), then the transmittance falls off by exp(10 cm / 5 cm), or about a factor of 7.4 over the length of the voxel!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, according to slide 28, a better approach is to explicitly account for the transmittance falloff over the voxel length, while still assuming constant inscattered light. Fortunately the integral has a simple closed-form solution. So, they're saying to evaluate &lt;em&gt;that&lt;/em&gt; formula per voxel in the integration loop, in place of the former &quot;wrong&quot; one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For completeness: in the code from slide 27, replace this line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;accumScatteringTransmittance.rgb += scatteringExtinction.rgb *&#xA;    accumScatteringTransmittance.a;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;with this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;accumScatteringTransmittance.rgb += scatteringExtinction.rgb *&#xA;    accumScatteringTransmittance.a *&#xA;    ((1.0 - transmittance) / scatteringExtinction.a);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here, &lt;code&gt;accumScatteringTransmittance.a&lt;/code&gt; is the transmittance at the point the ray &lt;em&gt;enters&lt;/em&gt; the voxel (i.e. the resultant transmittance of all the voxels in front of it), and then the &lt;code&gt;((1.0 - transmittance) / scatteringExtinction.a)&lt;/code&gt; factor accounts for the varying transmittance within the voxel.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2017-10-22T22:10:35.020" LastActivityDate="2017-10-22T22:10:35.020" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5764" PostTypeId="1" AcceptedAnswerId="5765" CreationDate="2017-10-22T07:58:25.637" Score="2" ViewCount="645" Body="&lt;p&gt;Both &lt;a href=&quot;https://github.com/mitsuba-renderer/mitsuba&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitsuba&lt;/a&gt; and &lt;a href=&quot;https://github.com/tunabrain/tungsten&quot; rel=&quot;nofollow noreferrer&quot;&gt;Tungsten&lt;/a&gt; use the &lt;strong&gt;power heuristic&lt;/strong&gt; to do multiple importance sampling (MIS).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mitsuba:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;inline Float miWeight(Float pdfA, Float pdfB) const {&#xA;    pdfA *= pdfA;&#xA;    pdfB *= pdfB;&#xA;    return pdfA / (pdfA + pdfB);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Tungsten:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static inline float powerHeuristic(float pdf0, float pdf1)&#xA;{&#xA;    return (pdf0*pdf0)/(pdf0*pdf0 + pdf1*pdf1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Advanced Global Illumination&lt;/em&gt; gives the &lt;strong&gt;balance heuristic&lt;/strong&gt;:&#xA;$$F=\cfrac1N\sum_{i=1}^n\sum_{j=1}^{n_i}\cfrac{f(X_{i,j})}{{\sum\limits_{k=1}^n}\frac{c_k}Np_k(X_{i,j})}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;power heuristic&lt;/strong&gt; may be like this:&#xA;$$F=\cfrac1N\sum_{i=1}^n\sum_{j=1}^{n_i}\cfrac{f(X_{i,j})p_i(X_{i,j})}{{\sum\limits_{k=1}^n}\frac{n_k}Np_k^2(X_{i,j})}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know they are all valid estimators.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the motivation to use the &lt;strong&gt;power heuristic&lt;/strong&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What about the &lt;strong&gt;cube heuristic&lt;/strong&gt;?&#xA;$$F=\cfrac1N\sum_{i=1}^n\sum_{j=1}^{n_i}\cfrac{f(X_{i,j})p_i^2(X_{i,j})}{{\sum\limits_{k=1}^n}\frac{n_k}Np_k^3(X_{i,j})}$$&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2017-10-22T10:37:26.660" Title="Power heuristic in multiple importance sampling" Tags="&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5765" PostTypeId="2" ParentId="5764" CreationDate="2017-10-22T10:37:26.660" Score="4" Body="&lt;p&gt;&lt;em&gt;PBRT v3&lt;/em&gt; Page 799:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xwuxh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xwuxh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Veach determined it empirically.&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2017-10-22T10:37:26.660" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5767" PostTypeId="2" ParentId="5760" CreationDate="2017-10-22T20:22:43.393" Score="2" Body="&lt;p&gt;gl.vertexAttribPointer is used when different vertices should have different values, and gl.vertexAttrib is used when all vertices should have the same values, and you don't want to use a special shader with a uniform.&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-10-22T20:22:43.393" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5772" PostTypeId="1" AcceptedAnswerId="5773" CreationDate="2017-10-24T06:27:41.470" Score="3" ViewCount="1494" Body="&lt;p&gt;I modified my code, and tried to pass a set of integers specifying the face of a cube (top, bottom left...) to the vertex shader in order to draw multiple instances of a cube face.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did this by trying to pass them as vertex attributes, but it isn't working as I expected, the value of the int should be between 0 and 5, but it's never a number between 0 and 5, in fact it seems to be much much larger than that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my current shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;#define PI 3.1415926535897932384626433832795&#xA;&#xA;layout(location = 0) in vec3 position; //(x,y,z) coordinates of a vertex&#xA;layout(location = 1) in vec3 norm; //a 3D vertex representing the normal to teh vertex &#xA;layout(location = 2) in vec2 texture_coordinate;&#xA;layout(location = 3) in int face_type;&#xA;&#xA;out vec3 normal; &#xA;out vec3 vertexPos; //projected vertex&#xA;out vec2 texture_coord;&#xA;&#xA;uniform mat4 model = mat4(1); //Position and orientation of the current object&#xA;uniform mat4 view = mat4(1); //Camera orientation and position&#xA;uniform mat4 proj = mat4(1); //the projection parameters (FOV, viewport dimensions)&#xA;&#xA;//Taken from: https://gist.github.com/neilmendoza/4512992&#xA;mat4 rotationMatrix(vec3 axis, float angle)&#xA;{&#xA;    axis = normalize(axis);&#xA;    float s = sin(angle);&#xA;    float c = cos(angle);&#xA;    float oc = 1.0 - c;&#xA;&#xA;    return mat4(oc * axis.x * axis.x + c,           oc * axis.x * axis.y - axis.z * s,  oc * axis.z * axis.x + axis.y * s,  0.0,&#xA;                oc * axis.x * axis.y + axis.z * s,  oc * axis.y * axis.y + c,           oc * axis.y * axis.z - axis.x * s,  0.0,&#xA;                oc * axis.z * axis.x - axis.y * s,  oc * axis.y * axis.z + axis.x * s,  oc * axis.z * axis.z + c,           0.0,&#xA;                0.0,                                0.0,                                0.0,                                1.0);&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;    mat4 rotation = mat4(1);&#xA;    switch(face_type)&#xA;    {&#xA;        case 0:&#xA;            rotation = mat4(1);&#xA;            break;&#xA;        case 1:&#xA;            rotation = rotationMatrix(vec3(0,0,1), -PI/2.f);&#xA;            break;&#xA;        case 2:&#xA;            rotation = rotationMatrix(vec3(0,0,1), PI/2.f);&#xA;            break;&#xA;        case 3:&#xA;            rotation = rotationMatrix(vec3(0,0,1), PI);&#xA;            break;&#xA;        case 4:&#xA;            rotation = rotationMatrix(vec3(1,0,0), PI/2.f);&#xA;            break;&#xA;        case 5:&#xA;            rotation = rotationMatrix(vec3(1,0,0), -PI/2.f);&#xA;            break;&#xA;&#xA;        default:&#xA;            rotation = mat4(vec4(face_type,0,0,0),&#xA;                            vec4(0,1,0,0),&#xA;                            vec4(0,0,1,0),&#xA;                            vec4(0,0,0,1));&#xA;            break;&#xA;    }&#xA;&#xA;    /*rotation = mat4(vec4(5,0,0,0),&#xA;                    vec4(0,5,0,0),&#xA;                    vec4(0,0,5,0),&#xA;                    vec4(0,0,0,1));*/&#xA;&#xA;    vec4 projection = proj*view*model*rotation*vec4(position, 1.0);&#xA;    gl_Position = projection;&#xA;&#xA;    normal = vec3(model*vec4(norm,1.0));&#xA;    vertexPos = vec3(model*vec4(position, 1.0)); //calculate the transformed pos&#xA;    texture_coord = texture_coordinate + vec2(face_type*(1/6.f),0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this is how I am passing the face information to the shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vector&amp;lt;Face&amp;gt; face_types = {Top, Bottom, Left,};&#xA;glEnableVertexAttribArray(3);&#xA;glBindBuffer(GL_ARRAY_BUFFER, experiment);&#xA;glVertexAttribPointer(3, 1, GL_INT, GL_FALSE, sizeof(Face), (void*)0);&#xA;glBufferData(GL_ARRAY_BUFFER, face_types.size()*sizeof(Face),&#xA;    face_types.data(), GL_DYNAMIC_DRAW);&#xA;glVertexAttribDivisor(3, 1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="2041" LastEditDate="2018-03-03T17:39:54.783" LastActivityDate="2018-03-03T17:39:54.783" Title="How to dynamically calculate texture coordinates in a vertex shader with OpenGL?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;glsl&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5773" PostTypeId="2" ParentId="5772" CreationDate="2017-10-24T07:00:35.770" Score="2" Body="&lt;p&gt;To be able to give a good answer, we need to know what is the compiler error you are referring to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At first sight your shader looks ok, although:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It always sets &lt;code&gt;texture_coord.y&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt;, which might not be what you want.&lt;/li&gt;&#xA;&lt;li&gt;The &lt;code&gt;.f&lt;/code&gt; notation (in &lt;code&gt;orientation*(1/6.f)&lt;/code&gt;) doesn't exist in GLSL. It should be &lt;code&gt;1./6.&lt;/code&gt;. Moreover, I am not entirely sure if strict GLSL allows to multiply a uint with a float; a cast might be necessary.&lt;/li&gt;&#xA;&lt;li&gt;You also need to make sure that on the receiving end, the fragment shader is declaring the texture coordinate as needed: &lt;code&gt;in vec2 texture_coord;&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;It is fairly common to set texture coordinates dynamically in the vertex shader, so you should be able to do so too.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update to your additional questions and details:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;OpenGL throws an INVALID_OPERATION error&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;OpenGL error handling is quite tricky, since you have to poll for errors yourself, and it uses the same few error codes for wildly different functions. You have to identify exactly which function yielded the error, then refer to the documentation for the list of reasons this error can happen for that function. To make that task easier, the best way I have found so far is to &lt;em&gt;always&lt;/em&gt; surround OpenGL calls with a macro doing an error check. You can find an &lt;a href=&quot;https://github.com/bkaradzic/bgfx/blob/8d471959eb3cbc16c0e7fdac25efcf842abd2ad1/src/renderer_gl.h#L994&quot; rel=&quot;nofollow noreferrer&quot;&gt;implementation of a macro like that in the source code of bgfx&lt;/a&gt; for example.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The error comes from my face type array being too big, but now I don't know how to pass the face type information into the shader, since I know I need 2048 elements at most&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The layout declared in the shader must match the one declared through the OpenGL calls. The number of vertices is irrelevant on the shader side, but it must be consistent on the OpenGL declaration side. Unless you are using different indexes for the vertex attributes, you should have as many positions, normals, texture coordinates and face types.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following snippet from your question seems to be declaring face types for only three vertices though:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindBuffer(GL_ARRAY_BUFFER, experiment);&#xA;glVertexAttribPointer(3, 1, GL_INT, GL_FALSE, sizeof(Face), (void*)0);&#xA;glBufferData(GL_ARRAY_BUFFER, face_types.size()*sizeof(Face), face_types.data(), GL_DYNAMIC_DRAW);&#xA;glVertexAttribDivisor(3, 1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am not familiar with &lt;code&gt;glVertexAttribDivisor&lt;/code&gt;, but from what I read, it seems to be limited to instanced rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find a simple &lt;a href=&quot;https://github.com/ocornut/imgui/blob/50f5be9266ce21391597695dc80b15a4724447cc/examples/opengl3_example/imgui_impl_glfw_gl3.cpp#L270&quot; rel=&quot;nofollow noreferrer&quot;&gt;example of binding in the examples of Dear ImGui&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2017-10-25T08:57:05.470" LastActivityDate="2017-10-25T08:57:05.470" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5778" PostTypeId="1" CreationDate="2017-10-25T20:33:13.310" Score="4" ViewCount="329" Body="&lt;p&gt;I am writing a 2D light casting algorithm with OpenGL compute shaders. The algorithm is simple:&#xA;For each light source shoot out light rays from it, the ray begins at the light coordinates, it ends at a pixel in a circle around the light source (the light distance). When calculating the ray sample the pixel underneath it to model light colour/alpha changes. The algorithm works well, but a few pixels are missed, so they stay black causing Moire-like artifacts. The lightrays are calculated in a compute shader parallelly, one thread for each pixel in the light border circle. This means for example for a light with 256 radius, there are 2*256*Pi=1608 threads on the GPU, each calculating a single ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Heres the relevant compute shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define LOCAL_WG_SIZE 128u&#xA;const float PI = 3.1415926535897932384626433832795;&#xA;const float RAY_LENGTH = 256.0f;&#xA;&#xA;// get the number of the current thread (0...1608)&#xA;uint renderNodeNum = local_coords;&#xA;// get the endpoint of the ray, it will be on a circle&#xA;endPoint.x = int(RAY_LENGTH * sin(float(renderNodeNum) * PI / 1024.0f)) + lightPos.x;&#xA;endPoint.y = int(RAY_LENGTH * cos(float(renderNodeNum) * PI / 1024.0f)) + lightPos.y;&#xA;&#xA;// vector approximation. Works, but has moire artifacts.&#xA;// I've also tried Bresenham's line algorithm, but it leaves a cross shape as the light fades which looks ugly.&#xA;vec2 dt = normalize(vec2(endPoint - lightPos));&#xA;vec2 t = vec2(lightPos);&#xA;for (int k = 0; k &amp;lt; RAY_LENGTH; k++) {&#xA;    coords.x = int(t.x);&#xA;    coords.y = int(t.y);&#xA;&#xA;    // calculate transparency&#xA;    transpPixel = imageLoad(transpTex, coords);   &#xA;    currentAlpha = (transpPixel.b + transpPixel.g * 10.0f + transpPixel.r * 100.0f) / 111.0f;&#xA;    // calculate color&#xA;    colorPixel = imageLoad(colorTex, coords);&#xA;    lightRay.rgb = min(colorPixel.rgb, lightRay.rgb) - (1.0f - currentAlpha) - transmit; &#xA;    currentOutPixel = imageLoad(img_output, coords);&#xA;    currentOutPixel.rgb = max(currentOutPixel.rgb, lightRay.rgb);&#xA;    currentOutPixel.a = lightRay.a;&#xA;    // write color&#xA;    imageStore(img_output, coords, currentOutPixel);&#xA;&#xA;    t += dt;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Heres is how it looks:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/h7aHK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/h7aHK.png&quot; alt=&quot;Moire artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another example with coloured background that shows light propagation, with the same artifacts:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/on4OX.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/on4OX.png&quot; alt=&quot;same Moire artifacts here too&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I need a better algorithm to draw these light rays (or any other method that is highly parallellizable on a compute shader) that does not leave out some pixels (the black spots in the pic). I could oversample the lightray (for example shoot twice as many rays), but this would be very expensive, there must be a cheaper solution.&lt;/p&gt;&#xA;" OwnerUserId="2437" LastActivityDate="2017-10-26T05:17:38.033" Title="How to prevent moire artifacts in this light casting algorithm?" Tags="&lt;raytracing&gt;&lt;glsl&gt;&lt;2d&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5779" PostTypeId="1" AcceptedAnswerId="5780" CreationDate="2017-10-25T21:11:16.110" Score="1" ViewCount="90" Body="&lt;p&gt;I am trying to pass vertex attributes from my vertex shader -&gt; geometry shader and then to the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pretty simple program, here is my vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core&#xA;&#xA;uniform mat4 uModelViewMatrix;&#xA;uniform mat4 uProjMatrix;&#xA;&#xA;in vec4 aPosition;&#xA;&#xA;out vec3 modelPosition;&#xA;&#xA;void main()&#xA;{&#xA;    modelPosition = aPosition.xyz;&#xA;    gl_Position = uProjMatrix * uModelViewMatrix * aPosition;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is my geometry shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core&#xA;&#xA;layout (triangles) in;&#xA;layout (triangle_strip, max_vertices = 3) out;&#xA;&#xA;in vec3 modelPosition[];&#xA;&#xA;out vec3 gModelPosition[];&#xA;&#xA;void main()&#xA;{&#xA;    for (int i = 0; i &amp;lt; gl_in.length(); i++)&#xA;    {&#xA;        gl_Position = gl_in[i].gl_Position;&#xA;        EmitVertex();&#xA;    }&#xA;    gModelPosition[0] = modelPosition[0];&#xA;    gModelPosition[1] = modelPosition[1];&#xA;    gModelPosition[2] = modelPosition[2];&#xA;    EndPrimitive();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is my fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core&#xA;&#xA;in vec3 gModelPosition;&#xA;&#xA;out vec4 fragColor;&#xA;&#xA;void main()&#xA;{&#xA;    fragColor = vec4(gModelPosition, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I get the following error:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PROGRAM_LINKING_ERROR: error: &quot;gModelPosition&quot; not declared as input from previous stage&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I just comment out the last line in the fragment shader, and say &lt;code&gt;fragColor = vec4(1.0);&lt;/code&gt; it works fine. And I clearly &lt;strong&gt;am&lt;/strong&gt; declaring gModelPosition as an input from the previous stage. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I doing something wrong here?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2017-10-25T22:17:27.853" Title="Issue with declaring inputs to geometry shader?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;geometry-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5780" PostTypeId="2" ParentId="5779" CreationDate="2017-10-25T22:17:27.853" Score="1" Body="&lt;p&gt;The issue was that I declared &lt;code&gt;out vec3 gModelPosition[]&lt;/code&gt; as an array in my geometry shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It should have only been declared as a &lt;code&gt;vec3&lt;/code&gt; (i.e. &lt;code&gt;out vec3 gModelPosition&lt;/code&gt;)&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2017-10-25T22:17:27.853" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5781" PostTypeId="1" CreationDate="2017-10-25T22:26:19.193" Score="2" ViewCount="102" Body="&lt;p&gt;Suppose I took a picture of a whiteboard at an angle. If I could detect where the corners of the whiteboard are, what algorithms and linear projections could I use to convert this slanted view into a &quot;head on&quot; view?&lt;/p&gt;&#xA;" OwnerUserId="7541" LastEditorUserId="6" LastEditDate="2017-10-26T10:32:18.233" LastActivityDate="2017-11-08T05:12:05.033" Title="How would I convert a picture of a slanted surface into a straight one?" Tags="&lt;image-processing&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ClosedDate="2017-11-10T21:55:24.527" ContentLicense="CC BY-SA 3.0" />
  <row Id="5782" PostTypeId="2" ParentId="5778" CreationDate="2017-10-26T05:17:38.033" Score="2" Body="&lt;p&gt;In principle you avoid using scatter (casting) behavior with GPU. They have offered random output coordinate write out since only shader model 5 as a need for extreme situations. But you should as general rule write your GPU code in a &quot;gather&quot; fashion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference: the hardware threads are logically soft-locked to one output position in the render target. The scheduler decides to what rectangle (or cube) in the target buffers, the kicked thread group will output results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you should work around the designated destination, and figure out the start; instead of working from some start and computing a dynamic destination.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This way not only will you please the hardware by avoiding contention, and race conditions completely; but also you'll avoid holes.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2017-10-26T05:17:38.033" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5784" PostTypeId="1" AcceptedAnswerId="5786" CreationDate="2017-10-27T14:17:11.860" Score="17" ViewCount="6287" Body="&lt;p&gt;Why do red, green, and blue combinations can make up all the visible colors?&lt;/p&gt;&#xA;" OwnerUserId="7550" LastEditorUserId="7550" LastEditDate="2017-10-27T14:38:54.810" LastActivityDate="2017-10-28T21:08:59.327" Title="Why do red, green, and blue make up all the colors?" Tags="&lt;color&gt;&lt;color-science&gt;&lt;color-separation&gt;" AnswerCount="5" CommentCount="14" FavoriteCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5785" PostTypeId="2" ParentId="5784" CreationDate="2017-10-27T14:55:16.743" Score="17" Body="&lt;p&gt;Humans are trichromatic, which means we have 3 different kinds of color receptors (better known as &lt;a href=&quot;https://en.wikipedia.org/wiki/Cone_cell&quot; rel=&quot;noreferrer&quot;&gt;cone cells&lt;/a&gt;), each sensitive to a different set of wavelengths: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LucVA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LucVA.png&quot; alt=&quot;frequency responses of different cone cells&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Image source: &lt;a href=&quot;https://en.wikipedia.org/wiki/File:Cone-fundamentals-with-srgb-spectrum.svg&quot; rel=&quot;noreferrer&quot;&gt;wikipedia&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it only takes 3 different monochromatic stimuli to fool our eye into thinking it sees a color that is the same as another. Red, green, and blue are good fits to the peaks of the frequency response curves of each type of color receptor.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="48" LastEditDate="2017-10-27T21:56:56.383" LastActivityDate="2017-10-27T21:56:56.383" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5786" PostTypeId="2" ParentId="5784" CreationDate="2017-10-27T15:07:10.777" Score="23" Body="&lt;p&gt;Let's reminds ourselves what light is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Radio waves, micro waves, X rays and gamma rays are all &lt;a href=&quot;https://en.wikipedia.org/wiki/Electromagnetic_radiation&quot; rel=&quot;noreferrer&quot;&gt;electromagnetic radiation&lt;/a&gt; and they only differ by their frequency. It just so happens that the human eye is able to detect electromagnetic radiation between ~400nm and ~800nm, which we perceive as light. The 400nm end is perceived as violet and the 800nm end is perceived as red, with the colors of the rainbow in between.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A ray of light can be a mix of any of those frequencies, and when light interacts with matter, some frequencies are absorbed while other might not: this is what we perceive as the colors of objects around us. Unlike the ear though, which is able to distinguish between a lot of sound frequencies (we can identify individual notes, voices and instruments when listening to a song), the eye is not able to distinguish every single frequency. It can generally only detect &lt;em&gt;four ranges&lt;/em&gt; of frequencies (there are exceptions like daltonism or mutations).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This happens in the retina, where there are several kinds of &lt;a href=&quot;https://en.wikipedia.org/wiki/Photoreceptor_cell&quot; rel=&quot;noreferrer&quot;&gt;photo-receptors&lt;/a&gt;. A first kind, called &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Rod_cell&quot; rel=&quot;noreferrer&quot;&gt;rods&lt;/a&gt;&quot;, detects most frequencies of the visible light, without being able to tell them apart. They are responsible for our perception of brightness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A second kind of photo-receptors, called &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Cone_cell&quot; rel=&quot;noreferrer&quot;&gt;cones&lt;/a&gt;&quot;, exists in three specializations. They detect a narrower range of frequencies, and some of them are more sensitive to the frequencies around red, some to the frequencies around green, and the last ones to the frequencies around blue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because they detect a &lt;em&gt;range of frequencies&lt;/em&gt;, they cannot tell the difference between two frequencies within that range, and they cannot tell the difference between a monochromatic light and a mix of frequencies within that range either. The visual system only has the inputs from those three detectors and reconstruct a perception of color with them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this reason, the eye cannot tell the difference between a white light made of all the frequencies of the visible light, and the simple mix of only red green and blue lights. Thus, with only three colors, we can reconstruct &lt;em&gt;most&lt;/em&gt; colors we can see.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, rods are a lot more sensitive than cones, and that's why we don't perceive colors in the night.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2017-10-28T07:37:20.117" LastActivityDate="2017-10-28T07:37:20.117" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5787" PostTypeId="1" CreationDate="2017-10-27T15:19:35.053" Score="4" ViewCount="1086" Body="&lt;p&gt;In appendix &lt;strong&gt;A&lt;/strong&gt; of the paper &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt; there is a derivation provided for $\Lambda(w)$ but the mathematics is very confusing. Could somebody help me by explaining it?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Smith's shadow masking function $G1$ gives the fraction of microfacets with normal $w_h$ that are visible from direction $w$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$G(w_o, w_i)$ $=$ $G_1(w_o)G_1(w_i)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the literature, the Smith masking function is often&#xA;expressed as a fraction involving a function $\Lambda(w_o)$. This function is expressed&#xA;as an integral over the slopes of the microsurface and its form is derived with a raytracing&#xA;formulation of the masking probability.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$G_1(w_o,w_m)$ $=$ $1\over1+\Lambda(w_o)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the Trowbridge-Reitz distribution it is quite simple:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\Lambda(w)$ $=$ $-1+ \sqrt{1+\alpha^2tan^2\theta}\over 2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is this $\Lambda(w)$ function derived?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="5256" LastEditDate="2017-11-03T09:31:24.537" LastActivityDate="2017-11-03T09:31:24.537" Title="Explanation of math of the Smith G1 term" Tags="&lt;pbr&gt;&lt;ggx&gt;&lt;ndf&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5789" PostTypeId="2" ParentId="5784" CreationDate="2017-10-28T11:47:04.403" Score="20" Body="&lt;p&gt;&lt;strong&gt;They don't.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with the diagrams representing the visible and RGB gamuts is that they're presented on RGB displays. They obviously cannot show you what they cannot show you : the area inside the parabola but outside of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QIpkW.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QIpkW.png&quot; alt=&quot;RGB gamut&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The region outside of the triangle cannot be shown on your screen in a faithful way. For example, RGB cannot display a true, deep cyan. All you see is an approximation using green and blue. Some diagrams don't even try and only show a gray area :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DGyOe.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DGyOe.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To see what cyan can look like, you could stare at the white dot on this drawing for at least 30 seconds (2 minutes are recommended) and then slowly move your head towards a white wall:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/upswE.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/upswE.jpg&quot; alt=&quot;cyan illusion&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, RGB displays cannot show deep, saturated oranges or browns.&lt;/p&gt;&#xA;" OwnerUserId="7560" LastEditorUserId="7560" LastEditDate="2017-10-28T12:27:13.477" LastActivityDate="2017-10-28T12:27:13.477" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="5790" PostTypeId="2" ParentId="5784" CreationDate="2017-10-28T14:30:44.827" Score="4" Body="&lt;p&gt;One more thing: &quot;violet&quot; and &quot;purple&quot; &lt;em&gt;are not the same color.&lt;/em&gt;  Violet is a pure color around 400 nm; but purple is a combination of red and blue.  To our not-quite-perfect human eyes they look the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you pass a beam of pure violet through a triangular prism, the light will be bent but not broken up into components.  If you then shine a beam of purple through the same prism, it will be separated into a blue and a red beam, with different amounts of &quot;bend&quot; to them.&lt;/p&gt;&#xA;" OwnerUserId="7564" LastActivityDate="2017-10-28T14:30:44.827" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5791" PostTypeId="2" ParentId="5784" CreationDate="2017-10-28T21:08:59.327" Score="4" Body="&lt;p&gt;They don't. Aside from what others have said about the physical reasons not, from a practical computer graphics standpoint, representing either surface pigments or light sources with RGB color is insufficient to model colored lighting of a scene. For example there is no way to represent a material which is translucent or reflective only in a narrow band; you can only represent translucency or reflectivity of wide bands corresponding roughly to what the red, green, and blue cones in the human eye pick up. This actually matters for a lot of real-world colors in the pink/purple/violet family, which look radically different under different types of light, even different &quot;white&quot; light that looks identical when viewed on a white surface.&lt;/p&gt;&#xA;" OwnerUserId="3411" LastActivityDate="2017-10-28T21:08:59.327" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5792" PostTypeId="1" AcceptedAnswerId="5795" CreationDate="2017-10-29T01:47:28.557" Score="2" ViewCount="535" Body="&lt;p&gt;So i am working through the book &quot;Raytracing in one weekend&quot;.&#xA;At the point where i am at we want to check if a ray hits a sphere.&#xA;For that we have the equation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;dot((A + t*B - C),(A + t*B - C)) = R*R&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where A + t*B is a point on the ray, with A the start, B the direction and t how far along we went on the ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To solve this the author transformed the equation to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;t*t*dot(B,B) + 2*t*dot(A-C,A-C) + dot(C,C) - R*R = 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now i just can not understand how this transformation comes about. &#xA;Simply multiplying this out seems to give a way different result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some kind of vector math i'm missing here?&lt;/p&gt;&#xA;" OwnerUserId="7577" LastActivityDate="2017-11-14T18:31:31.283" Title="Vector Math for Raytracer" Tags="&lt;raytracing&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5793" PostTypeId="1" CreationDate="2017-10-29T03:11:43.770" Score="2" ViewCount="777" Body="&lt;p&gt;When trying to find the vanishing point of an image, why is it that the vector from the center of the camera to the vanishing point is parallel to the parallel lines of the image? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the mathematical reasoning behind this? &#xA;&lt;a href=&quot;https://i.stack.imgur.com/aiY3p.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aiY3p.png&quot; alt=&quot;Diagram of vanishing point&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7578" LastEditorUserId="7578" LastEditDate="2017-10-29T04:35:16.803" LastActivityDate="2017-11-29T10:51:24.277" Title="Why is the line from the camera to vanishing point parallel to the other parallel lines?" Tags="&lt;image-processing&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5795" PostTypeId="2" ParentId="5792" CreationDate="2017-10-29T07:03:29.237" Score="3" Body="&lt;p&gt;I think there might be a misprinting in the book. I am getting this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$((A-C) + tB)\cdot((A-C) + tB) = R\cdot R$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Let  A-C = Y&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(Y + tB)\cdot(Y + tB) = R\cdot R$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Y\cdot Y + Y\cdot tB + tB\cdot Y + t^2B\cdot B = R\cdot R$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Substituting back &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(A-C)\cdot(A-C) + 2t * B\cdot(A-C) + t^2B\cdot B = R\cdot R$&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="7431" LastEditDate="2017-10-31T19:51:54.827" LastActivityDate="2017-10-31T19:51:54.827" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5797" PostTypeId="1" AcceptedAnswerId="5809" CreationDate="2017-10-30T03:48:17.477" Score="5" ViewCount="381" Body="&lt;p&gt;I want to do volume rendering using path tracing with a &lt;strong&gt;absorption only&lt;/strong&gt; model. And my data is in a 3D grid, which is turned into a voxel medium in my renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I can't seem to be correct implementing the algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this note&lt;/a&gt; (however absorption-only heterogeneous case is not mentioned here), the radiance at point $x$, direction $\omega$, with &lt;strong&gt;emission-absorption&lt;/strong&gt; model in a &lt;strong&gt;homogeneous&lt;/strong&gt; medium is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L(x,\omega) = \int_{x}^{y} \tau(x,x') \epsilon(x')dx + \tau(x,y)L_e(x,\omega)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $\tau$ is the attenuation, y is a point on surface, and $\epsilon$ is emission at point $x'$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I come up with the &lt;strong&gt;heterogenous&lt;/strong&gt;, &lt;strong&gt;absorption-only&lt;/strong&gt; equation as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L(x, \omega) = \tau(x,y)L_e(x,\omega)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;since I think the emission term should be omitted. However this equation seems not correct intuitively and do not give correct image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to this equation, the radiance at every point $x'$ along the ray within the volume is not counted, which is where I think the problem lies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So &lt;strong&gt;what is the correct heterogeneous volume path tracing equation?&lt;/strong&gt;&#xA;&lt;strong&gt;How to derive the correct equation?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I give more details of my implementation here. The scene is simply a &lt;strong&gt;cornell box&lt;/strong&gt; where only a voxel medium is inside the box. I trace a ray from the eye(camera), and the ray go through the medium and intersect a surface(the wall). To simplify the procedure, I set &lt;code&gt;max_bounce&lt;/code&gt; to &lt;strong&gt;1&lt;/strong&gt; which means the path is &#xA;&lt;code&gt;eye -&amp;gt; medium -&amp;gt; surface -&amp;gt; light&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the value of this sample is simply the &lt;em&gt;throughput of the medium&lt;/em&gt; times &lt;em&gt;the throughput of the surface&lt;/em&gt; times &lt;em&gt;direct light at surface intersection&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hoK2f.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hoK2f.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I got the result image&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8Omkw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8Omkw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7334" LastEditorUserId="7334" LastEditDate="2017-10-30T06:01:15.363" LastActivityDate="2017-11-02T02:49:39.857" Title="How to do heterogeneous volume absorption using path tracing?" Tags="&lt;pathtracing&gt;&lt;volumetric&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5798" PostTypeId="2" ParentId="5793" CreationDate="2017-10-30T10:35:14.210" Score="2" Body="&lt;p&gt;FYI every set of parallel lines will have their own vanishing point. The reason why there is usually only a single vanishing point (the most obvious one) talked about in an image is due to aesthetic choice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A perspective projection can be seen as a point projection of a 3D scene onto a 2D plane. The way to determine where a point in the 3D scene ends up on the 2D plane is to draw a line between the point and the camera (the sight line) and see where it intersects the projection target plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To find the vanishing point of a set of parallel lines you can take a the limit of traveling on that line infinitely far. At the limit the sight line will be parallel to the line. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-10-30T10:35:14.210" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5799" PostTypeId="2" ParentId="374" CreationDate="2017-10-30T12:45:56.897" Score="9" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;is it a total pipe dream to hope to solve the Ray/Bezier-surface intersection algebraically&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, it's a pipe dream. A bicubic Bezier patch is an algebraic surface of degree 18. To intersect a ray with this surface, you have to find the roots of a polynomial of degree 18. There is no formula for these roots -- you have to find them by numerical methods. In fact, there are mathematical results (&lt;a href=&quot;https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem&quot; rel=&quot;nofollow noreferrer&quot;&gt;the Abel-Ruffini theorem&lt;/a&gt;) telling us that there can never be formulae for roots of equations beyond degree 4. The math doesn't just say that the formulae have not yet been found; it says that they never will be found, because they can't exist.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you really want to do analytical (algebraic) ray-tracing of curvaceous shapes, you might try using &lt;a href=&quot;https://www.researchgate.net/publication/234780280_Ray_tracing_of_Steiner_patches&quot; rel=&quot;nofollow noreferrer&quot;&gt;Steiner patches&lt;/a&gt;. These have degree 4, so the ray-patch intersection can be computed by finding the &lt;a href=&quot;https://en.wikipedia.org/wiki/Quartic_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;roots of a quartic&lt;/a&gt; (i.e. a polynomial of degree 4). There are formulae for finding roots of quartics, but they're pretty nasty, and it's surprisingly hard to write code that implements the formulae reliably.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-11-01T12:09:22.133" LastActivityDate="2017-11-01T12:09:22.133" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5801" PostTypeId="2" ParentId="5716" CreationDate="2017-10-31T12:09:57.443" Score="1" Body="&lt;p&gt;What you're looking for is called de Boor's algorithm. It lets you compute a point on a b-spline curve by doing a series of linear interpolation (LERP) calculations. So, it works very much like the de Casteljau algorithm for Bezier curves. In fact, the de Casteljau algorithm is a special case of de Boor's algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/De_Boor%27s_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;A link&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/de-Boor.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Another one&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;http://web.mit.edu/hyperbook/Patrikalakis-Maekawa-Cho/node18.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;And another&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-10-31T12:15:26.530" LastActivityDate="2017-10-31T12:15:26.530" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5802" PostTypeId="2" ParentId="405" CreationDate="2017-10-31T12:52:50.163" Score="1" Body="&lt;p&gt;I use Powerpoint and various (expensive) CAD packages. I wrote Powerpoint macros (VBA code) to do some special things like draw the control polygons of Bezier curves. Then I use the standard Windows Snipping Tool to grab screen shots. Here are some examples:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BdBcH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BdBcH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wQaEx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wQaEx.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bpywg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bpywg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EUeLW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EUeLW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And some further examples from Math.SE&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://math.stackexchange.com/questions/2230316/ellipse-tangent-to-two-circles&quot;&gt;One&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://math.stackexchange.com/questions/2200952/intersection-of-cones-tangent-to-a-common-sphere&quot;&gt;Two&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://math.stackexchange.com/questions/482063/parabolas-through-three-points&quot;&gt;Three&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://math.stackexchange.com/questions/1601158/how-can-we-find-geodesics-on-a-one-sheet-hyperboloid/1606820#1606820&quot;&gt;Four&lt;/a&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://math.stackexchange.com/questions/465782/control-points-of-offset-bezier-curve/467038#467038&quot;&gt;Five&lt;/a&gt;     &lt;/p&gt;&#xA;" OwnerUserId="6968" LastEditorUserId="6968" LastEditDate="2017-10-31T13:21:42.220" LastActivityDate="2017-10-31T13:21:42.220" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5803" PostTypeId="1" CreationDate="2017-11-01T06:04:55.013" Score="5" ViewCount="1326" Body="&lt;p&gt;As some of you may know drawing line segments between sets of points is really difficult especially when you want wide lines or variable widths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because I am looking to draw a few hundred of these line segments each frame I am having to go with the cheapest option to achieve a connected segment. So far this has meant that I am using a miter to join the two rectangles like so (&lt;a href=&quot;https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader&quot; rel=&quot;nofollow noreferrer&quot;&gt;described here&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TBAumm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TBAumm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/lHZmRm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lHZmRm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with this approach is that the extra length added by the miter is sometimes quite large especially in the case of acute angles and I would like to have rounded corners where possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe it is a job for the fragment shader as I don't have enough processing resources to calculate more geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a diagram showing what might end up happening after the fragment function:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xiMsV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xiMsV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Purple represents the area between the two lines that ought to be kept; the rest should be removed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know a way to achieve this rounded rectangle in the fragment shader even though texture co-ords are pretty useless in a scenario where the shape is not a polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wish I was allowed to just draw the rounded circle over the disjointed &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember, whatever it is it needs to be fast.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2041" LastEditDate="2017-11-01T14:32:39.647" LastActivityDate="2017-11-01T14:32:39.647" Title="Rounding the edges in a mitered line segment inside of a fragment shader" Tags="&lt;geometry&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5804" PostTypeId="2" ParentId="5803" CreationDate="2017-11-01T11:27:12.617" Score="4" Body="&lt;p&gt;First, adressing the concerns of speed and performance, you will always have to make some trade-offs between quality and performance, as you already do. If the first version looks &lt;em&gt;fine enough&lt;/em&gt; for your use-case and all other versions are much slower, you have to make the decision yourself. You will, however, not get around actually &lt;strong&gt;&lt;em&gt;measuring&lt;/em&gt; any time difference&lt;/strong&gt;. But since various ways to do this are not too hard to integrate into an existing wide lines renderer, just testing the various approaches in action and getting some time measurements shouldn't be too difficult, especially with OpenGL timer queries (or whatever the Direct3D equivalent).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So let's get to some &lt;em&gt;possible&lt;/em&gt; improvements to your situation. It seems from your link and your explanations that you're using a classic geometry shader based approach for wide line rendereing, converting each line into a screen-aligned quad (or two triangles), computing the vertex positions based on the line width you want to achieve. I recently built something similar, too and there's a few ways you can improve the quality.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;As you said yourself, since you're working on rather arbitrary rounded shapes it's probably best to let the fragment shader figure out the exact pixel-shape rather than trying to &lt;strong&gt;approximate the circular middle region in the geometry shader&lt;/strong&gt;. Though, that idea is not completely off-the table and might give for a nice adjustable quality-speed trade-off by adjusting the number of vertices of that circle-part. But it also, together with your current approach, has the problem that it actually &lt;strong&gt;needs to know the line's neighbouring lines&lt;/strong&gt; in order to compute the middle section, which makes it difficult to just put into an existing shader-agnostic rendering system that just draws all the lines as vertex pairs (not to speak of line strips/loops), since you need to add the adjacency information for each line.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you just want to let the fragmet shader do the job using simple alpha testing, you generate a &lt;strong&gt;screen-aligned rectangle that's a little larger than the line, i.e. it spans half the width across the endpoints&lt;/strong&gt; and thus covers the circular end caps, too. In the fragment shader you just check each &lt;strong&gt;fragment's screen-space distance to the nearest point on the actual line&lt;/strong&gt; (which you transfer from the geometry shader to the fragment shader as a varying). And whenever that distance is larger than the line width (or half the line width, to be precise), you &lt;strong&gt;&lt;code&gt;discard&lt;/code&gt; the fragment&lt;/strong&gt;. This way you will basically render a rounded box for each line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be precise you render your line as three quad-sections (i.e. 6 triangles in a single strip). The middle section between the ednpoints as one rectangle and the two end-caps as rectangles spanning from the endpoint half the width in the direction of the line. You do this separation to give the rightmost 4 vertices their respective endpoint as varying value and the leftmost one their respective endpoint. This way you get smooth interpolation of the line point across the middle section and clamping in the cap sections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This distance computation might also be used to &lt;strong&gt;antialias&lt;/strong&gt; the lines, i.e. by using alpha blending (or multisampling with alpha to coverage) and &lt;strong&gt;letting alpha go from 1 to 0 along the outermost ~1-pixel thick border&lt;/strong&gt; of the line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this approach has the disadvantage of &lt;strong&gt;drawing the uneccessary grey area from your above picture, &lt;em&gt;twice&lt;/em&gt; even&lt;/strong&gt;. This not only causes possibly slowing overdraw (and the explicit discarding inhibits early z-testing), it will also interfere with any possible alpha-based antialiasing as described above.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A solution to mitigate this could be to actually just draw the completely uncapped lines as rectangles from one endpoint to the other (i.e. like your very first picture). And then &lt;strong&gt;drawing the connection points (i.e. the line's vertices) as additional circular large points&lt;/strong&gt; (i.e. using a similar technique of transforming points into screen-aligned quads with the geometry shader and testing for the distance to the actual point center in the fragment shader to get pixel-perfect circles).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This has the advantage that you can actually use &lt;strong&gt;stencil testing to only draw the connective sections in the regions where you haven't drawn other parts of the line set before&lt;/strong&gt; and thus only the violet area, which will tremendously reduce overdraw (at the cost of more complicated rendering and per-fragment operations). This gives very nice results with an alpha-based antialiasing approach as described above (there are however still some minor areas where there's some tiny artefacts).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This stencil testing approach might as well be used on the earlier approach where you draw the line section together with its end-caps when you don't perform any kind of antialiasing or blending, but I think to remember that it caused more artefacts than the separate rendering if you do. I haven't spend too many thoughts on this right now, though, and it might be worth some more investigation. However the seperate solution also has the advantage of &lt;strong&gt;requiring the expensive fragment test and possible discard only in the actual connective regions&lt;/strong&gt;, the line middle sections can be rendered with a straight-forward fragment shader.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Those are just a few thoughts that I happened to ponder on just recently and deemed worth sharing. As said, &lt;em&gt;if&lt;/em&gt; they are appropriate for your use-case has to be evaluated, possibly with some timing and quality measurements.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-11-01T12:30:50.333" LastActivityDate="2017-11-01T12:30:50.333" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5805" PostTypeId="1" CreationDate="2017-11-01T16:13:44.947" Score="5" ViewCount="1471" Body="&lt;p&gt;I am trying to wrap my head around how exactly the GPU interpolates texture coords on a quad. I realize to the GPU a quad is two triangles but I find thinking in terms of the whole quad to be easiest.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we define texture space as the texture coordinates from X:Y{0-1} and world space as the actual coordinates of the quad how can I given a point p1 that is on the quad figure out what its texture coordinate would be? Given a texture coordinate point p2 how would I figure out its real world coordinates?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that the quad can be any quadrilateral not necessarily always a parallelogram. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an extra note lets define the texture coordinates on the quad so that they are as such&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2wkpm.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2wkpm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2017-11-14T18:33:51.950" Title="The mathematics of two dimensional interpolation on a quad" Tags="&lt;texture&gt;&lt;gpu&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5806" PostTypeId="2" ParentId="5805" CreationDate="2017-11-01T18:08:40.643" Score="8" Body="&lt;p&gt;(It actually &lt;em&gt;is&lt;/em&gt; easier to think (and compute) about this with triangles, but for the sake of the answer, let's first stick to your quad example.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this you just have to define the point you're interested in in terms of the quad's (or whatever primitive's) vertices. This is called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Barycentric_coordinate_system&quot; rel=&quot;noreferrer&quot;&gt;&lt;strong&gt;barycentric coordinate system&lt;/strong&gt;&lt;/a&gt;. More practically-speaking, you basically give the point $n$ weights, each describing &lt;strong&gt;the influence the $i$th vertex of the quad has on the point&lt;/strong&gt;. Those are the point's barycentric coordinates with respect to that quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So for example the center point of the quad (or &quot;center of mass&quot;) would have the weights $\frac{1}{4}$, $\frac{1}{4}$, $\frac{1}{4}$, and $\frac{1}{4}$. A point in the middle of the left edge would have a weight of $\frac{1}{2}$ for the left two vertices each and a weight of $0$ for the right two vertices. (Notice how they always sum to $1$?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These barycentric coordinates can then be used to &lt;strong&gt;interpolate whatever kind of per-vertex values&lt;/strong&gt; you want, be that positions or texture coordinates. It all reduces to a simple &lt;strong&gt;weighted sum&lt;/strong&gt;. And even more than that, they can also be quite easily computed by simple vector algebra from any &lt;strong&gt;existing per-vertex values if you have the point's values&lt;/strong&gt; given (comes down to just a few little 2x2 determinants for a triangle, or similarly easy computation). This means if you know a pixel's screen space position and those of the vertices, you can compute its barycentric coordinates. These you can then use to interpolate the pixel's texture coordinates (or normal, or whatever) from the per-vertex values, or vice versa.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So much to the theory, there's a few practical considerations to keep in mind, especially when using them for interpolation in a rasterizer, like GPUs do.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For anything but triangles the barycentric coordinates don't necessarily have to be uniquely defined for any arbitrary point. That's why &lt;strong&gt;thinking about triangles is much easier&lt;/strong&gt;, especially for the computer.&lt;/li&gt;&#xA;&lt;li&gt;Due to the fact that they are negative if and only if the point doesn't actually lie inside the triangle they can also be used for &lt;strong&gt;checking &lt;em&gt;if&lt;/em&gt; the point belongs to the triangle at all&lt;/strong&gt; and thus are more or less a by-product of the pixel-in-triangle test that the rasterizer already performs to, well, rasterize the triangle.&lt;/li&gt;&#xA;&lt;li&gt;When it comes to interpolation in projected space, i.e. when &lt;strong&gt;projecting a 3D world onto the plane using perspective distortion&lt;/strong&gt;, it becomes a little more involved since you have to account for the fact that a line's length in screen space is not the same as its length in world space, or more precisely its screen space length doesn't increase linearly when going along a triangle edge in world space. The keyword here is &lt;a href=&quot;https://en.wikipedia.org/wiki/Texture_mapping#Perspective_correctness&quot; rel=&quot;noreferrer&quot;&gt;&lt;strong&gt;perspective correct interpolation&lt;/strong&gt;&lt;/a&gt;. But this still uses the point's barycentric coordinates.&lt;/li&gt;&#xA;&lt;li&gt;Of course in an actual rasterizer you also have to take account for shared triangle edges and only rasterize a shared edge once, which requires special rules as to which triangle a shared edge belongs and might make the computation of barycentric coordinates a little more complicated, together with using fixed-point coordinates or whatever optimized computations.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;(This is a more general overview of the matter and how it generally works. For specific mathematical as well as technical details, I'd advise for further reading, maybe starting with the above Wikipedia articles.)&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2017-11-01T18:29:48.963" LastActivityDate="2017-11-01T18:29:48.963" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5807" PostTypeId="2" ParentId="2093" CreationDate="2017-11-01T18:50:48.140" Score="0" Body="&lt;p&gt;I've found &lt;a href=&quot;https://www.vtk.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;VTK&lt;/a&gt; library and used bindings to Python  3 available from different Anaconda organizations: &lt;a href=&quot;https://anaconda.org/anaconda/vtk&quot; rel=&quot;nofollow noreferrer&quot;&gt;anaconda&lt;/a&gt; itself, &lt;a href=&quot;https://anaconda.org/conda-forge/vtk&quot; rel=&quot;nofollow noreferrer&quot;&gt;conda-forge&lt;/a&gt;, &lt;a href=&quot;https://anaconda.org/clinicalgraphics/vtk&quot; rel=&quot;nofollow noreferrer&quot;&gt;clinicalgraphics&lt;/a&gt; and &lt;a href=&quot;https://anaconda.org/menpo/vtk&quot; rel=&quot;nofollow noreferrer&quot;&gt;menpo&lt;/a&gt;.&#xA;Also it can be compiled from sources.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Works fast (I've rendered a mesh with half a million vertices without any problems) and easier in use than low-level OpenGL shaders with GLUT.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.menpo.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;menpo&lt;/a&gt; has its own wrapper for VTK and &lt;a href=&quot;http://code.enthought.com/projects/mayavi/&quot; rel=&quot;nofollow noreferrer&quot;&gt;mayavi&lt;/a&gt; called &lt;a href=&quot;http://www.menpo.org/menpo3d/&quot; rel=&quot;nofollow noreferrer&quot;&gt;menpo3d&lt;/a&gt;.&#xA;I have not tried it yet, but examples look very simple.&lt;/p&gt;&#xA;" OwnerUserId="2750" LastActivityDate="2017-11-01T18:50:48.140" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5808" PostTypeId="2" ParentId="2316" CreationDate="2017-11-02T00:35:37.813" Score="11" Body="&lt;p&gt;Just to expand on some of the other answers, the proof that Russian Roulette does not give a biassed result is very simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose that you have some random variable $F$ which is the sum of several terms:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$F = F_1 + \cdots + F_N$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Replace each term with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$F'_i = \left\{&#xA;\begin{array}{ll}&#xA;      \frac{1}{p_i} F_i &amp;amp; \hbox{with probability } p_i \\&#xA;      0 &amp;amp; \hbox{otherwise}&#xA;\end{array} &#xA;\right.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$E[F'_i] = p_i \times \frac{1}{p_i}E[F_i] + (1-p_i) \times 0 = E[F_i]$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that it &lt;em&gt;doesn't matter&lt;/em&gt; what probabilities you pick for $p_i$. The expected value of the terms, and hence the expected value of $F$, is the same.&lt;/p&gt;&#xA;" OwnerUserId="159" LastActivityDate="2017-11-02T00:35:37.813" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5809" PostTypeId="2" ParentId="5797" CreationDate="2017-11-02T02:49:39.857" Score="2" Body="&lt;p&gt;Your equation for the absorption-only model is correct: You multiply the luminance $L_x$ at the surface by the transmittance of the participating media between eye and the surface. For homogeneous media you can calculate this analytically using &lt;a href=&quot;https://en.wikipedia.org/wiki/Beer%E2%80%93Lambert_law&quot; rel=&quot;nofollow noreferrer&quot;&gt;Beer-Lambert law&lt;/a&gt;:&#xA;$$L_y=L_xe^{-\mu|x-y|}$$&#xA;For heterogeneous medium you can calculate the transmittance by ray march through the medium using for example Woodcock tracking explained in &lt;a href=&quot;http://www.cs.cornell.edu/courses/cs6630/2012sp/notes/09volpath.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;the paper you referred&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-11-02T02:49:39.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5810" PostTypeId="1" AcceptedAnswerId="5813" CreationDate="2017-11-02T04:32:00.937" Score="3" ViewCount="853" Body="&lt;p&gt;I am trying to send rendering information for an instancing rendering using shader buffer objects. My current problem is that I have 2 shader buffer objects, one which works just fine, and another that is not quite working.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is to render squared faces at different positions in the screen. For this, I create a vector of glm::vec3 that represent the position of each face, put all of them in an std::vector and use them as the data for the Shader buffer object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words I am creating the data as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;face_positions.push_back(vec3(0,0,0));&#xA;visible_faces.push_back(Left);&#xA;&#xA;face_positions.push_back(vec3(0,-10,0));&#xA;visible_faces.push_back(Front);&#xA;&#xA;face_positions.push_back(vec3(0,0,0));&#xA;visible_faces.push_back(Back);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then updating the buffers as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindBuffer(GL_SHADER_STORAGE_BUFFER, cube_rendering_VBOs[3]);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, visible_faces.size()*sizeof(Face), visible_faces.data(), GL_DYNAMIC_COPY);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, cube_rendering_VBOs[3]);&#xA;&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, cube_rendering_VBOs[4]);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, face_positions.size()*sizeof(vec3), face_positions.data(), GL_DYNAMIC_COPY);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, cube_rendering_VBOs[4]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And finally rendering by doing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDrawElementsInstanced(GL_TRIANGLES, MESH-&amp;gt;indices-&amp;gt;size(), GL_UNSIGNED_INT, (void*)0, visible_faces.size());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Obviously there is more code associated with passing the actual mesh geometry used for the instanced rendering and enabling the correct layouts in the vertex shader, but I cannot put my enire code base here and I have more throuroughly tested those, so I beleive the mistake is in how I am passing or reading the shader buffer objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The behaviour is, if you look at the lines:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;face_positions.push_back(vec3(0,0,0));&#xA;visible_faces.push_back(Left);&#xA;&#xA;face_positions.push_back(vec3(0,-10,0));&#xA;visible_faces.push_back(Front);&#xA;&#xA;face_positions.push_back(vec3(0,0,0));&#xA;visible_faces.push_back(Back);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The face_positions() should be the poisitions of the faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However what I have noticed is, the first 3 floats (i.e face_positions[0]) work just as expected. Then one value is skipped (i.e face_positions[1].x) and the next values read are the next 3 (i.e face_positions[1].y face_positions[1].z face_positions[2].x) then once again one value is skipped, and it starts reading the next value (i.e face_positions[2].z).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it seems somewhere something is padding the array with 0's to make everything 4 bytes aligned.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone have any idea of where to start looking?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2017-11-03T01:11:31.053" LastActivityDate="2017-11-03T01:11:31.053" Title="Shader storage buffer indexing by 4 bytes instead of 3?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;uniform-buffer-object&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5811" PostTypeId="1" CreationDate="2017-11-02T05:29:24.290" Score="1" ViewCount="90" Body="&lt;p&gt;I have a big cube made of smaller cubes, but sometimes, due to the fact that each side of the cube has different colors, I get some ugly colored lines that I would like to get rid off. Any advice is appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6T6R9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6T6R9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qGpZs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qGpZs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;The BLACK lines and arrows are part of a texture, they are not relevant to my question, the focus is the RED line in the first picture and the red dots in the second picture. The lines appear mostly because this cube is made of smaller cubes put together side by side, so, depending on camera orientation, the side of a cube gets drawn on top of the front of the neighbouring cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;The solution, at least for now, was to &quot;delete&quot; all faces that are not visible, this, for obvious reasons, eliminated the problem, but I am going to leave this question open in case someone comes up with a solution that does not involve hiding faces.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2017-11-04T00:14:12.827" LastActivityDate="2017-11-04T00:14:12.827" Title="How to eliminate line aliasing in an object made of cubes?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;antialiasing&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5813" PostTypeId="2" ParentId="5810" CreationDate="2017-11-02T06:59:02.537" Score="6" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Does anyone ahve[sic] any idea of where to start looking&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You fell victim to one of the classic blunders. &lt;a href=&quot;https://stackoverflow.com/questions/38172696/should-i-ever-use-a-vec3-inside-of-a-uniform-buffer-or-shader-storage-buffer-o&quot;&gt;Never use a &lt;code&gt;vec3&lt;/code&gt; in a UBO or SSBO.&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While &lt;code&gt;vec3&lt;/code&gt;s take up 12 bytes, they always have the alignment requirements of a &lt;code&gt;vec4&lt;/code&gt;. Yes, even under &lt;code&gt;std430&lt;/code&gt; layout, they always have &lt;code&gt;vec4&lt;/code&gt; alignment. So if you have an array of &lt;code&gt;vec3&lt;/code&gt;s in a U/SSBO, what you really have is an array of &lt;code&gt;vec4&lt;/code&gt;s where one of the elements doesn't get used.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-11-02T06:59:02.537" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5814" PostTypeId="1" AcceptedAnswerId="5835" CreationDate="2017-11-03T02:18:07.130" Score="7" ViewCount="393" Body="&lt;p&gt;Ok so, I keep reading papers about this and non of them have pictures. The lane Riesenfeld algorithm provides a way to subdivide set of points with B-spline conversion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The quesiton is simple HOW? If you can give me a set of pictures with the explanation that's be the best explanation, more than the math. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first step (i.e duplication of the original vertices) seems clear enough, but I do not fully understand how the mid point averaging works. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently my very, very poor understanding is producing this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Starting with the following 4 points&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pOMeL.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pOMeL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We duplicate each point (denoted by the grey area)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7Yn07.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7Yn07.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We take all odd points in our new set, and move them to the middle of the line connecting 2 consecutive points:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FR93Q.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FR93Q.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do I do now? From here on I am just completely lost&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2017-11-09T12:36:49.520" Title="Visualizing the Lane-Riesenfeld Algorithm" Tags="&lt;algorithm&gt;&lt;geometry&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5815" PostTypeId="1" AcceptedAnswerId="5818" CreationDate="2017-11-03T06:14:28.530" Score="2" ViewCount="150" Body="&lt;p&gt;What's the meaning of the &quot;dynamic&quot; in &quot;high dynamic range&quot;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why use this word?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2017-11-07T07:43:09.977" Title="What's the meaning of the &quot;dynamic&quot; in &quot;high dynamic range&quot;?" Tags="&lt;rendering&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5816" PostTypeId="1" CreationDate="2017-11-03T08:56:40.433" Score="0" ViewCount="141" Body="&lt;p&gt;I have a .obj file with accompanying .mtl file and texture files. I want to extract the coordinates of the seams on my mesh. I then want to plot these seams in a 3D matrix in Python. Is there a fast way to do that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further clarification: I have found a way recreate my mesh in my Python IDE using a library called Pymesh. I now want to plot the seams of my mesh (the ones that will give me the unwrap that I have in my texture files) in a 3D matrix as well. One way I could do this is to write a script that takes the edge points of all my UV islands, and then searches the .obj file for the 3D coordinates that they map to (and translate that into coordinates appropriate for my 3D matrix in Python). &#xA;That will take a long time though - is there a faster way?&#xA;I also asked this in the Blender StackExchange as I wasn't sure which was more appropriate. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="7622" LastActivityDate="2018-01-02T10:59:01.680" Title="Extract 3D seam coordinates from" Tags="&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5817" PostTypeId="2" ParentId="5816" CreationDate="2017-11-03T09:58:13.187" Score="2" Body="&lt;p&gt;A seam can be defined as a line along the mesh where the vertices are doubled each with different texture coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So that's what you should look for. The set of vertices where there is a twin in the same position with different texture coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on how the obj file was built that will be simple if they didn't duplicate the position when a vertex became part of a seam. Or it's not as simple because you need to deduplicate positions again.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-11-03T09:58:13.187" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5818" PostTypeId="2" ParentId="5815" CreationDate="2017-11-03T13:59:27.610" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;a href=&quot;http://www.dictionary.com/browse/dynamic&quot; rel=&quot;noreferrer&quot;&gt;Dynamic, adjective:&lt;/a&gt;&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;1: pertaining to or characterized by energy or effective action; vigorously active or forceful; energetic:&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;...&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;4: of or relating to the range of volume of musical sound.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;HDR allows you to deal with high light energies. And such high energies could be characterized as being &quot;vigorously active or forceful; energetic&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I think the fourth definition is more suitable. Graphics and rendering are forms of signal processing, much like sound. So they share a lot in common. For example, the term &quot;aliasing&quot; originated in digital conversion of sound.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;High light energies&quot; are the visual equivalent of &quot;volume&quot; in sound. So the &quot;dynamic range&quot; that you can record, the &quot;range of volume&quot; is high, as opposed to low.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-11-03T13:59:27.610" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5819" PostTypeId="1" AcceptedAnswerId="5820" CreationDate="2017-11-03T19:11:48.717" Score="7" ViewCount="140" Body="&lt;p&gt;How can I check if a polygon (can also be irregular) can completely contain a circle of a certain radius? I do not want to actually draw a circle inside the polygon but just a boolean outcome whether or not it can be fit. I need this for an application that I'm developing in Java. Note that I'm not looking for the inscribed circle, but the largest circle that a polygon can contain. I suppose there can be multiple circles with the same area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone share an algorithm or code snippet (any language is fine) or guide me to any relevant resource?&lt;/p&gt;&#xA;" OwnerUserId="7413" LastEditorUserId="231" LastEditDate="2017-11-05T01:50:42.413" LastActivityDate="2017-11-05T01:50:42.413" Title="How can I check if a polygon can completely contain a circle of a certain radius?" Tags="&lt;computational-geometry&gt;&lt;polygon&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5820" PostTypeId="2" ParentId="5819" CreationDate="2017-11-04T13:14:09.480" Score="8" Body="&lt;p&gt;This is likely more complicated than you would prefer, but: Compute the medial axis, which immediately yields the largest disks that fit inside the polygon:&#xA;their centers are vertices (degree $\ge 3$) of the axis (see the&#xA;figure below).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Chin, Francis, Jack Snoeyink, and Cao An Wang. &quot;Finding the medial axis of a simple polygon in linear time.&quot; &lt;em&gt;Discrete &amp;amp; Computational Geometry&lt;/em&gt; 21.3 (1999): 405-420.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;hr /&gt;&#xA;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#xA;&lt;a href=&quot;https://i.stack.imgur.com/R2ZKK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/R2ZKK.png&quot; alt=&quot;medialax&quot;&gt;&lt;/a&gt;&#xA;&lt;br /&gt;&#xA;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#xA;&lt;sup&gt;&#xA;(Image from &lt;a href=&quot;http://endl.ch/content/centerline&quot; rel=&quot;noreferrer&quot;&gt;Alexander Tsvyashchenko&lt;/a&gt;.)&#xA;&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr /&gt;&#xA;&#xA;&lt;p&gt;See also, &lt;a href=&quot;https://stackoverflow.com/a/4279633/387778&quot;&gt;Largest circle inside a non-convex polygon&lt;/a&gt; for an &lt;em&gt;ad hoc&lt;/em&gt; approach&#xA;(whose correctness I did not attempt to verify).&lt;/p&gt;&#xA;" OwnerUserId="4748" LastEditorUserId="4748" LastEditDate="2017-11-04T23:05:19.717" LastActivityDate="2017-11-04T23:05:19.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5821" PostTypeId="1" CreationDate="2017-11-06T00:53:57.970" Score="2" ViewCount="70" Body="&lt;p&gt;I'd like to develop a system for web animation similar to animated gifs, like &lt;a href=&quot;https://www.sublimetext.com/~jps/animated_gifs_the_hard_way.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt;. I capture a series of screenshots at fixed time intervals, and then I'd like to animate them. I can trivially calculate the pixels which have changed from one frame to another, but I'd then like to calculate a set of rectangles such that blitting those rectangles over the previous frame results in the new one. There's a tradeoff between the number of rectangles and the number of &quot;wasted&quot; pixels, i.e. the number of pixels stored and copied which have not changed between the two frames. Is there a good algorithm for this which would give me control over the tradeoff parameter in some form?&lt;/p&gt;&#xA;" OwnerUserId="7635" LastActivityDate="2017-12-14T17:59:46.260" Title="Calculate set of rectangles covering pixel diffs?" Tags="&lt;algorithm&gt;&lt;2d&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5822" PostTypeId="1" AcceptedAnswerId="5840" CreationDate="2017-11-06T08:05:31.383" Score="3" ViewCount="1648" Body="&lt;p&gt;The &lt;a href=&quot;https://en.wikibooks.org/wiki/OpenGL_Programming/Installation/Linux&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt; says the following about using OpenGL on Linux:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Most Linux distributions rely on the Mesa3D project to provide their OpenGL implementation&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But it also says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;OpenGL is included in drivers, so you'll have to make sure drivers are properly installed if you want to enjoy programs using OpenGL. Open source drivers actually make use of Mesa's OpenGL implementation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So I am a little confused:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I have an nVidia graphics card and install the nVidia drivers, do I need to install Mesa?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What if I have the card but do not install nVidia's drivers?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What, exactly, is meant by &quot;implementation&quot; in this context?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2017-11-08T13:41:36.453" Title="If I have an nVidia graphics card on Linux, do I need Mesa or FreeGLUT or anything like that?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5823" PostTypeId="1" AcceptedAnswerId="7937" CreationDate="2017-11-06T08:11:29.510" Score="6" ViewCount="2913" Body="&lt;p&gt;Assume that we have voxelized a 3D scene into a regular 3D grid of cubes, storing the average (diffuse) radiance and some flag indicating whether or not a voxel is empty. Next, the finer levels of the 3D texture (voxels) are downsampled to get coarser levels (&quot;pre-integrated&quot;) which will be stored as MIP levels for that texture. (&lt;em&gt;I know that some sparser structures can be used instead, but a regular grid is conceptually the most easiest to master first.&lt;/em&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, given that we have our surface position (and thus also the voxel we are in), how does voxel cone tracing work and how is it applied?&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2018-08-19T16:55:54.117" LastActivityDate="2018-08-19T16:55:54.117" Title="How does voxel cone tracing work?" Tags="&lt;global-illumination&gt;&lt;voxelization&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="5824" PostTypeId="2" ParentId="5815" CreationDate="2017-11-06T12:15:56.443" Score="-3" Body="&lt;p&gt;High Dynamic range, somtimes use as a feature in still image or in higher level in rolling image.&#xA;It means that your shot has been captured by camera that can hold all information about exposure (at least in 3 modes: Overexpos, Normal and Underexpos).&#xA;It is happening in high-end camera and high-end project.&#xA;With this feature, you have alot of control in CC step like a pro.&lt;/p&gt;&#xA;" OwnerUserId="7640" LastActivityDate="2017-11-06T12:15:56.443" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5825" PostTypeId="1" CreationDate="2017-11-06T12:36:34.677" Score="1" ViewCount="68" Body="&lt;p&gt;Given a png image with an unknown number of green colored &lt;em&gt;(rgba=0, 65535, 0, 65535)&lt;/em&gt; regions &lt;a href=&quot;https://i.stack.imgur.com/0nynM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0nynM.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1- How can I find and put the border points of only the separate green boxes to an array like:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[0] = []point{...} // the first box's points&#xA;[1] = []point{...} // the second box's points&#xA;[...] = []point{...} // &#xA;[7] = []point{...} // the last box's points&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2- Which algorithm(s) should I use?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;I tried canny edge detector and my own custom ones (like flood-fill) but the canny algorithm finds all the regions not only the green ones&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7641" LastEditorUserId="7641" LastEditDate="2017-11-07T08:54:40.160" LastActivityDate="2017-11-07T08:54:40.160" Title="Extracting the green-screen region borders" Tags="&lt;image-processing&gt;&lt;color&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5826" PostTypeId="1" AcceptedAnswerId="5827" CreationDate="2017-11-06T14:04:06.523" Score="0" ViewCount="89" Body="&lt;p&gt;I want to implement a LOD algorithm that reduces the number of objects rather than the number of vertices of the objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine a forest, then close up I want to see all the trees but moving away from it there is no need to display every single tree, so I want to remove random trees (up to a threshold).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I wasn't able to find current algorithms for this, but that may just be due to a lack of terminology: I have been looking for LOD algorithms. Maybe this technique exists under a different name, so I wanted to ask if there are such algorithms out there already?&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2017-11-06T14:58:53.097" Title="Are there LOD Algorithms that work through removing objects?" Tags="&lt;algorithm&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5827" PostTypeId="2" ParentId="5826" CreationDate="2017-11-06T14:58:53.097" Score="2" Body="&lt;p&gt;Here's how I'd do it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assign an sequential id to each tree. This can be an implicit id like an index in an array if you have this structure. The important part is that you can create N stable groups of trees that will be removed based on distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then decide at which distance you want to start removing each group of trees. Each tree group will have a specific distance at which it gets removed from the rendering. You must choose the appropriate granularity based on your use-case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, for each tree, compute its distance from the viewpoint and compare that with its removal distance to decide if it should be rendered or not. To get a nicer effect, use a fade-out distance over which the trees progressively disappear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Essentially the process is to tag trees with some LOD parameters (removal distance, fade distance, etc.) and remove them based on distance from the viewpoint.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2017-11-06T14:58:53.097" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5828" PostTypeId="2" ParentId="5825" CreationDate="2017-11-06T15:07:57.027" Score="1" Body="&lt;p&gt;Here is a brute force algorithm. This requires some temporary storage (another image, an array, etc.) to record the visited pixels.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Start at the first pixel and continue iterating over the image until you find a green pixel. Mark each read pixel as &quot;visited&quot;.&lt;/li&gt;&#xA;&lt;li&gt;Extract the set of green neighbor pixels and record them. Also tag them as &quot;visited&quot;. The idea is to find all the green pixels connected to the one found in [1].&lt;/li&gt;&#xA;&lt;li&gt;If any pixels in the source image are left, go back to [1].&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This will give you a set of contiguous green pixel regions where each pixel appears 1 or 0 times.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2017-11-06T15:07:57.027" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5829" PostTypeId="5" CreationDate="2017-11-06T15:13:02.983" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2017-11-06T15:13:02.983" LastActivityDate="2017-11-06T15:13:02.983" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5830" PostTypeId="4" CreationDate="2017-11-06T15:13:02.983" Score="0" Body="This is a special tag that is designed to be used only by the system for questions that have had all of their other tags removed. Do not add this tag to existing questions, it is reserved for use by the system to identify posts with no valid tags." OwnerUserId="5778" LastEditorUserId="5778" LastEditDate="2017-11-06T22:39:42.120" LastActivityDate="2017-11-06T22:39:42.120" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5831" PostTypeId="1" CreationDate="2017-11-06T15:24:59.837" Score="3" ViewCount="104" Body="&lt;p&gt;How can I find the vertices of a polygon (specifically hexagon) given the radius of the incircle? I want to calculate the vertices of a polygon given the face-to-face distance (inscribed circle diameter?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've below code to calculate the vertices from the Circum-circle of a polygon&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;(x,y)&lt;/code&gt; - Center of the circumcircle&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;r&lt;/code&gt; - Radius of the circumcircle&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (var i = 1; i &amp;lt;= sides; i++)&#xA;{&#xA;    var X = x + r * Math.Cos(2 * Math.PI * i / sides);&#xA;    var Y = y + r * Math.Sin(2 * Math.PI * i / sides);&#xA;&#xA;    vertices.Add(new Tuple(X,Y));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Alternatively, what is the relation between radius of the in-circle and circum-circle of a polygon? Could you please share a relevant resource or a code snippet (any language is fine).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7413" LastEditorDisplayName="user7220" LastEditDate="2018-04-22T21:30:31.597" LastActivityDate="2018-04-22T21:30:31.597" Title="Vertices of a regular polygon given the incircle radius" Tags="&lt;computational-geometry&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5833" PostTypeId="2" ParentId="5831" CreationDate="2017-11-06T15:56:48.057" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;what is the relation between radius of the in-circle and circum-circle of a polygon?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That is $cos ( \frac{2\pi}{n}*\frac{1}{2} ) = cos ( \frac{\pi}{n})$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The triangle with edges from the center to the middle of a side, from the center to an adjacent corner and half the side connecting them is a right angle triangle. The angle of the point at the center $ =\frac\pi 2$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then it's simply the cosine to get the ratio between adjacent and hypotenuse.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-11-06T15:56:48.057" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5834" PostTypeId="2" ParentId="5815" CreationDate="2017-11-07T07:43:09.977" Score="3" Body="&lt;p&gt;From &lt;a href=&quot;https://en.wikipedia.org/wiki/Dynamic_range&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Dynamic_range&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Dynamic range, abbreviated DR, DNR, or DYR is the ratio between the&#xA;  largest and smallest values that a certain quantity can assume.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In the case of HDR, this refers to the ratio of the highest/lowest luminance values that can be perceived or represented.&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2017-11-07T07:43:09.977" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5835" PostTypeId="2" ParentId="5814" CreationDate="2017-11-07T10:08:34.453" Score="16" Body="&lt;p&gt;The Lane-Riesenfeld algorithm subdivides the control polygon of a B-spline to create a new control polygon with the same limit spline.  It's made up of two steps: first, duplicating all of the control points $P_i$ into $P^\prime_{2i}$ and $P^\prime_{2i+1}$; then, moving each point to the midpoint between it and the next point, so $P^\prime_i \rightarrow \frac{1}{2} P^\prime_i + \frac{1}{2}P^\prime_{i+1}$.  These steps are illustrated in the figure:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/d7Dfn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d7Dfn.png&quot; alt=&quot;One duplication and one movement step&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the left is an initial control polygon.  In the middle, I've duplicated the vertices.  On the right, the vertices have moved halfway to the next vertex.  Notice that only half of the vertices move in the first movement step: this is because $P^\prime_{2i} = P^\prime_{2i+1},$ but $P^\prime_{2i+1} \neq P^\prime_{2i+2}.$  These eight vertices are a refined control polygon for the linear B-spline defined by the initial four vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we can do a second movement step (without another duplication):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gjIca.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gjIca.png&quot; alt=&quot;Second movement step and new polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the left, we've moved each vertex to the midpoint between it and its neighbour; note that all of the vertices move this time (since none are in the same position).  On the right, we have drawn the polygon with these eight vertices.  This is a refined control polygon for the &lt;em&gt;quadratic&lt;/em&gt; B-spline defined by the initial four vertices.  You may also recognize this as the same polygon you get by Chaikin corner-cutting, which also gets you the quadratic B-spline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we can perform more duplicate-move-move steps to further refine the polygon, and thus more closely approximate the quadratic B-spline curve:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AXVhV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AXVhV.png&quot; alt=&quot;Further refinements of the quadratic B-spline control polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an animation of this process:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q29mn.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q29mn.gif&quot; alt=&quot;Animation of LR algorithm creating quadratic B-spline&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If, instead, we do a third movement step without a duplication step (that is, one duplication followed by three successive movements) we get a refined control polygon for the &lt;em&gt;cubic&lt;/em&gt; B-spline defined by the initial four vertices:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HaIxE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HaIxE.png&quot; alt=&quot;Cubic B-spline refinement by dup-move-move-move steps&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An animation of this process:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/94Um1.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/94Um1.gif&quot; alt=&quot;Animation of LR algorithm creating cubic B-spline&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, doing $k$ movement steps after each duplicate gives us the refined polygon for the $C^k$ B-spline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: Added animations.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastEditorUserId="7647" LastEditDate="2017-11-09T12:36:49.520" LastActivityDate="2017-11-09T12:36:49.520" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5837" PostTypeId="1" AcceptedAnswerId="5838" CreationDate="2017-11-07T19:45:52.777" Score="4" ViewCount="261" Body="&lt;p&gt;I am trying to use a linear transformation to straighten out the camera angle on this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/03ys6.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/03ys6.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, I want to transform the image into a head-on view of the whiteboard.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I applied an affine transformation to that image, identifying the top left, top right, and bottom left corners, thinking that it would turn the image into a 1080x720 rectangle. However, here's what I ended up with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/k5UFZ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/k5UFZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, it is NOT a rectangle, but some sort of misshapen quadrilateral. It's close, but not exactly a head-on view of the whiteboard!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What exactly happened here? I really thought an affine transformation would work.&lt;/p&gt;&#xA;" OwnerUserId="7541" LastActivityDate="2017-11-07T20:54:25.020" Title="Why does an affine transform work only on three of the corners?" Tags="&lt;image-processing&gt;&lt;affine-transformations&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5838" PostTypeId="2" ParentId="5837" CreationDate="2017-11-07T20:54:25.020" Score="6" Body="&lt;p&gt;An affine transformation doesn't have enough freedom to do what you want. Affine transforms can be constructed to map any triangle to any other triangle, but they can't map any quadrilateral to any other quadrilateral.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to see this is that the matrix for a 2D affine transform has only 6 free coefficients. That's enough to specify what it does to 3 points, but not 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this task you likely want a projective transformation. A 2D projective transformation has enough freedom to &lt;a href=&quot;http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/&quot; rel=&quot;noreferrer&quot;&gt;map any convex quadrilateral to any other&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-11-07T20:54:25.020" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5839" PostTypeId="2" ParentId="5781" CreationDate="2017-11-08T05:12:05.033" Score="0" Body="&lt;p&gt;As @user1118321 mentioned, as well as @NathanReed in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5838/7541&quot;&gt;this answer&lt;/a&gt; to another question, you can do a perspective transform to transform &lt;a href=&quot;http://www.reedbeta.com/blog/quadrilateral-interpolation-part-1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;any convex quadrilateral to any other&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html#getperspectivetransform&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenCV&lt;/a&gt; has a good library for doing perspective transformations if you don't want to roll your own.&lt;/p&gt;&#xA;" OwnerUserId="7541" LastActivityDate="2017-11-08T05:12:05.033" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5840" PostTypeId="2" ParentId="5822" CreationDate="2017-11-08T13:41:36.453" Score="3" Body="&lt;p&gt;The Mesa3D project is a software implementation of OpenGL; that is, an implementation that does all the rendering on the CPU with no GPU involvement at all. It's designed in two layers: a backend which renders each frame from some internal state, and a frontend which implements the OpenGL API and sets up the state for the backend to use. Most OpenGL implementations have a similar two-layer architecture, so that the same backend can be used by an OpenGL frontend, an OpenCL frontend, a Direct3D frontend, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The open-source NVidia drivers (and most open-source drivers) use Mesa's frontend to provide the OpenGL API and a backend specific to that GPU. The OpenGL API is quite complicated to implement, so it makes sense for vendors to share an existing front-end in this way. However, closed-source drivers do not use Mesa's frontend and have their own closed-source frontend.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you install and use a closed-source GPU driver, it will include its own libgl, which doesn't use Mesa at all. You don't need to install anything else to run OpenGL applications. (You might need an extra &quot;-dev&quot; package to get the header files needed to &lt;em&gt;compile&lt;/em&gt; OpenGL applications.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you install and use an open-source GPU driver, it will use Mesa, but the packages in your distribution should have the dependencies set up correctly, so that if an external Mesa package is needed, it will be installed automatically.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either way, you shouldn't have to worry about whether the OpenGL implementation you're using is based on Mesa or not.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-11-08T13:41:36.453" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5841" PostTypeId="1" CreationDate="2017-11-08T17:41:25.870" Score="6" ViewCount="228" Body="&lt;p&gt;The paper (&lt;a href=&quot;http://resources.mpi-inf.mpg.de/DeepScreenSpace/&quot; rel=&quot;noreferrer&quot;&gt;http://resources.mpi-inf.mpg.de/DeepScreenSpace/&lt;/a&gt;) just says that &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&quot;The ambient occlusion contribution of a surfel to a pixel [..] as&#xA;  well as the influence radius [..] are computed using the point-to-disk&#xA;  form factor [Wallace et al. 1989]&quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Wallace et al. 1989, A ray tracing algorithm for progressive radiosity&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does that mean that, in order to test for occlusion, rays are shot from a surfel to other surfels within its influence radius? That's just a speculation. Unfortunately the paper does not really explain how they implemented AO.&lt;/p&gt;&#xA;" OwnerUserId="5424" LastEditorUserId="5424" LastEditDate="2017-11-10T18:23:25.283" LastActivityDate="2017-11-10T18:23:25.283" Title="How is Ambient Occlusion calculated in &quot;Deep Screen Space&quot;?" Tags="&lt;rendering&gt;&lt;real-time&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5842" PostTypeId="1" CreationDate="2017-11-09T21:35:32.930" Score="2" ViewCount="51" Body="&lt;p&gt;I wan't create some LED-rope text, using some script font, like the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SRt9c.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SRt9c.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this I need somewhat estimate the needed length of the LED-rope for the given letter (or combinations of letters).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some more info:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The font will be TTF or FT2.&lt;/li&gt;&#xA;&lt;li&gt;I could manage some programs in perl using the FreeType library, eg. read some properties of the character in the font-file - if this helps.&lt;/li&gt;&#xA;&lt;li&gt;Also could install Inkscape (Illustrator  open-source alternative) or even could use Illustrator at my friend - if any of this tools could help.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Looking for some suggestions how to measure the length of paths in the given font for the particular character (or whole text).&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't need exact precision, (see the purpose above) and looking for the solution &lt;em&gt;as simple as possible&lt;/em&gt;, but I haven't any idea how even approach this problem. :(&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, I always could print the text and buy some inexpensive &lt;a href=&quot;https://en.wikipedia.org/wiki/Opisometer&quot; rel=&quot;nofollow noreferrer&quot;&gt;curve runner&lt;/a&gt;, but would be better to have some computer-based solution. :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ps: I'm not fully sure that this is the right place to ask such question, if not - I will delete it, but please suggest some better place.&lt;/p&gt;&#xA;" OwnerUserId="7661" LastEditorUserId="7661" LastEditDate="2017-11-09T21:57:36.003" LastActivityDate="2017-11-10T09:11:31.297" Title="How to get the length of paths in an given font/character" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;&lt;pathtracing&gt;&lt;vector-graphics&gt;&lt;font-rendering&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5843" PostTypeId="1" AcceptedAnswerId="5844" CreationDate="2017-11-09T23:23:17.673" Score="2" ViewCount="369" Body="&lt;p&gt;I am following this tutorial: &lt;a href=&quot;http://flafla2.github.io/2014/08/09/perlinnoise.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Understanding Perlin Noise | Blog&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To understand Perlin Noise. In particular, right now I am focusing on the following code section:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int xi = (int)x &amp;amp; 255; // Calculate the &quot;unit cube&quot; that the point asked will be located in&#xA;int yi = (int)y &amp;amp; 255; // The left bound is ( |_x_|,|_y_|,|_z_| ) and the right bound is that&#xA;int zi = (int)z &amp;amp; 255; // plus 1.  Next we calculate the location (from 0.0 to 1.0) in that cube.&#xA;double xf = x-(int)x;&#xA;double yf = y-(int)y;&#xA;double zf = z-(int)z;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I am correct, the first 3 lines of code are calculating a set of 3 coordinates (xi,yi,zi) that range from 0 to 255 inclusive, as integers. This is, in other words, a 255x255x255 3D grid of unit cubes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next 3 lines are calculating the relative 0-1 coordinates inside of the cube in the grid the point (x,y,z) is mapped to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any reason for this number to be 255? Or is this simply a number that was chosen because it made the algorithm faster (smaller grid, less numbers, faster hash lookup, caching...) and could easily be extended to any other integer (theoretically).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In either case, won't this generate a repetitive pattern?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I mean by the second question is: If I have a set of (x,y,z) values that extend to &quot;infinity&quot; at regular intervals (let's say they all change at intervals of 1), won't I start seeing a clearly predictable/repetitive pattern emerge after around 255 steps in a given direction? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, if a repetitive pattern emerges, how can you create more variation while keeping pseudo randomness?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorDisplayName="user7220" LastEditDate="2018-03-03T17:40:08.140" LastActivityDate="2018-03-03T17:40:08.140" Title="Help understanding Perlin Noise" Tags="&lt;algorithm&gt;&lt;noise&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5844" PostTypeId="2" ParentId="5843" CreationDate="2017-11-10T03:11:42.277" Score="3" Body="&lt;p&gt;Yep, you've got that right. In Perlin's reference implementation of &quot;improved noise&quot;, the noise will be periodic, repeating after 256 units along each axis. It's usually not very noticeable even if you have a large extent of noise visible, since there's no large-scale features for the eye to track.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But there's no particular reason it needs to tile after 256 units; that's pretty much just an arbitrary choice made by Perlin. He uses a permutation table as a hash function to map grid coordinates to gradient vectors, and the hard-coded table is of size 256, so has to be tiled after that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, any other hash function you like could be used as well. It just has to pseudorandomly map the integer parts of the x, y, z coordinates to a gradient vector.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-11-10T03:11:42.277" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5845" PostTypeId="2" ParentId="5842" CreationDate="2017-11-10T04:37:10.783" Score="2" Body="&lt;p&gt;The way I would approach this is to get the outline curves of the font and then break each one down into some fixed number of steps (like, say, 100), and make a series of very small straight lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if you've got some bezier curve, you loop &lt;code&gt;t&lt;/code&gt; from 0 to 1 in 100 steps and plug it into the equation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double x = calculateBezier(0.0, c0.x, c1.x, c2.x, c3.x);&#xA;double y = calculateBezier(0.0, c0.y, c1.y, c2.y, c3.y);&#xA;double dist = 0.0;&#xA;for (double t = 0.01; t &amp;lt;= 1.0; t+= 0.01)&#xA;{&#xA;    double nextX = calculateBezier(t, c0.x, c1.x, c2.x, c3.x);&#xA;    double nextY = calculateBezier(t, c0.y, c1.y, c2.y, c3.y);&#xA;    double nextDist = sqrt((nextX - x) * (nextX - x) + (nextY - y) * (nextY - y));&#xA;    dist += nextDist;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;calculateBezier()&lt;/code&gt; is a function that calculates a point on a bezier curve given the parameter &lt;code&gt;t&lt;/code&gt; and control points &lt;code&gt;c0&lt;/code&gt; through &lt;code&gt;c3&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double calculateBezier(double t, double c0, double c1, double c2, double c3)&#xA;{&#xA;    double t1 = 1.0 - t;&#xA;&#xA;    return (t1 * t1 * t1) * c0 + 3.0 * (t1 * t1) * c1 + &#xA;            3.0 * t1 * (t * t) * c2 + (t * t * t) * c3;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And just add the distances of each part of the curve until you're out of curves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this assumes cubic bezier curves. For quadratic, the &lt;code&gt;calculateBezier&lt;/code&gt; function would calculate a quadratic one (like described &lt;a href=&quot;https://en.wikipedia.org/wiki/B%C3%A9zier_curve#Quadratic_B.C3.A9zier_curves&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-11-10T04:37:10.783" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5846" PostTypeId="1" AcceptedAnswerId="5847" CreationDate="2017-11-10T06:20:24.977" Score="4" ViewCount="4515" Body="&lt;p&gt;I have been playing around for a day with Perlin noise, and I am currently stuck. Most of the modifications I have made to the algorithm produce more or less the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LNK39.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LNK39.png&quot; alt=&quot;Perlin noice&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, this is a very good start, but the idea is to generate terrain similar to real life (as close as I can get at least). Rivers and lakes would be nice to have, but that's way ahead in the schedule, right now I would like some help understanding 2 things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say that in my image, black is water and grey is land this is quite unlike the earth's shores. On earth continents are large masses of land and if they are cut by watter, it's usually on large areas (Imagine the Mexican gulf or the Mediterranean sea). However my image has a lot of narrow elongated &quot;peninsulas&quot; with patches of water around it. Due to the nature of Perlin noise (the square grid with the underlying random vector field) I am not sure how to create those large clusters of land and water. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other problem is vertical, if we see the grey scale as a height map, these islands are too odd. In real life one would have large sections of flat land with elongated mountain ranges cutting through.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some options that I have considered are, changing the smoothing/fade function in the improved Perlin noise algorithm for one that extends over multiple squares in the grid, but this adds too much computational complexity. I have also considered changing the vector field generation from pseudo random to one that follows a pattern, but this doesn't seem like it would actually solve the problem given that Perlin noise, as is, doesn't seem able to generate large consistent clusters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know about octaves, but they have their limitations, re-sampling perlin noise at different frequencies and amplitudes does change the terrain generation and ca give you some good results:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Wd6Da.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wd6Da.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But even this has issues.&#xA;For example if I want smooth hills I loose jaggy shores, same as if I try to create more valleys. And doing this also reduces the likelihood of generating islands in the middle of the bodies of water, moreover in terms of topography, the mountains look chaotic, they don't really from mountain ranges, they rather spread semi-chaoticly, which is not exactly what I need. &lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2017-11-10T07:44:56.277" LastActivityDate="2019-05-30T04:34:39.833" Title="How to modify Perlin (not simplex) noise to create continental like terrain generation" Tags="&lt;algorithm&gt;&lt;noise&gt;&lt;procedural-generation&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5847" PostTypeId="2" ParentId="5846" CreationDate="2017-11-10T08:24:07.170" Score="9" Body="&lt;p&gt;Perlin noise is just a base block, not very interesting by itself. You don't need to modify it, but to combine and filter it in interesting ways. Look at how to make &lt;a href=&quot;https://en.wikipedia.org/wiki/Fractional_Brownian_motion&quot; rel=&quot;noreferrer&quot;&gt;fractal Brownian motion (fBm)&lt;/a&gt; with it for example, which combines octaves based on few parameters to get a richer texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question of terrain rendering is a difficult one and a topic of active research. Many generated terrains have this artificial and uninteresting look. This is exactly what the paper &lt;a href=&quot;http://jcgt.org/published/0004/02/01/&quot; rel=&quot;noreferrer&quot;&gt;&quot;Modeling Real-World Terrain with Exponentially Distributed Noise&quot;&lt;/a&gt; tries to address, by proposing a formula based on statistics measured from actual terrain, which yields more convincing shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another source of valuable information is &lt;a href=&quot;http://www.iquilezles.org/www/&quot; rel=&quot;noreferrer&quot;&gt;Iñigo Quilez's website&lt;/a&gt;, where he mentions procedural generation a lot, &lt;a href=&quot;http://www.iquilezles.org/www/articles/morenoise/morenoise.htm&quot; rel=&quot;noreferrer&quot;&gt;including tricks to fake erosion&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2017-11-10T08:32:04.707" LastActivityDate="2017-11-10T08:32:04.707" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5848" PostTypeId="2" ParentId="5842" CreationDate="2017-11-10T09:11:31.297" Score="0" Body="&lt;p&gt;I decided to solve the LED-rope problem using Inkscape as:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;enter the wanted text into the Inkscape&lt;/li&gt;&#xA;&lt;li&gt;set the color of the text to yellow&lt;/li&gt;&#xA;&lt;li&gt;add new layer above the text and lock the text layer&lt;/li&gt;&#xA;&lt;li&gt;in the new layer, manually draw over the letters my own wanted bezier path(s)&lt;/li&gt;&#xA;&lt;li&gt;and finally use the tool in &lt;code&gt;Extensions -&amp;gt; Visualise Path -&amp;gt; Measure Path...&lt;/code&gt; - this adds the length of the given bezier path into the drawing as text.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The reason why:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I studied a bit the ttf-font structure (the whole new world for me). &lt;a href=&quot;http://stevehanov.ca/blog/index.php?id=143&quot; rel=&quot;nofollow noreferrer&quot;&gt;This blog entry&lt;/a&gt; and this &lt;a href=&quot;https://developer.apple.com/fonts/TrueType-Reference-Manual/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Reference manual&lt;/a&gt; helped a lot understanding the following (rough) basics.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the given glyph (character) is composed from many &lt;em&gt;closed paths&lt;/em&gt;, e.g. the letter &lt;code&gt;O&lt;/code&gt; is composed from two paths (outer circle and the inner circle).&lt;/li&gt;&#xA;&lt;li&gt;the paths are stored in the font file as pairs of x-y coordinates&lt;/li&gt;&#xA;&lt;li&gt;so it isn't so hard to calculate the length of &lt;em&gt;each&lt;/em&gt; path from the given coordinates.&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;but&lt;/em&gt; - in such way I will get the lengths of the all &lt;em&gt;outlines&lt;/em&gt;. Creating the outlines using the LED-rope it could be even interesting and also it is used at many examples, (like bellow), but this isn't what I want - I want a simple path(s) - as in the image in the question.&lt;/li&gt;&#xA;&lt;li&gt;getting such &lt;em&gt;simple path&lt;/em&gt; from the font's many outlines would need some tracing and approximation and other complicated math, which is definitely outside of my area of interest.&lt;/li&gt;&#xA;&lt;li&gt;therefore (for me) would be much easier just manually create the simple path's and measure their length in the Inkscape.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Also,&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;if someone want the length of the font's outlines, it is easily doable&lt;/li&gt;&#xA;&lt;li&gt;just need break apart the text into characters&lt;/li&gt;&#xA;&lt;li&gt;transform the (font) objects into the strokes&lt;/li&gt;&#xA;&lt;li&gt;and use the &lt;code&gt;Measure path...&lt;/code&gt; tool&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gk26Z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gk26Z.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7661" LastActivityDate="2017-11-10T09:11:31.297" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5850" PostTypeId="1" CreationDate="2017-11-10T16:33:17.410" Score="1" ViewCount="42" Body="&lt;p&gt;I have 2 images, called left and right images. I have some matched points $[c_l,r_l]$ and $[c_r,r_r]$ in both of them (these points are in pixel coordinates). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a 3D point in the real world, they are related by:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\lambda_l*[c_l , r_l,1]^t = W_l*[X,Y,Z]^t$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\lambda_r*[c_r ,r_r,1]^t = W_r*[R|T]*[X,Y,Z,1]^t$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here $W_l$ and $W_r$ are the intrinsic parameters of the left and right cameras and $T and R$ are the relative / overall translation and rotation between the cameras.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I attempted to solve this as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Q*[M,1]^T = 0$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where Q is &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;        \begin{matrix}&#xA;        (k_1 +k_2-k_3*c_r-k_3*r_r) &amp;amp; (tw_x + tw_y -r_r*tw_z - c_r*tw_z) \\&#xA;        (w_1 + w_2 - w_3*c_l -w_3*r_l) &amp;amp; 0 \\&#xA;        \end{matrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and M is $[X,Y,Z]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$k1,k2, k3$ are the rows of the matrix K given by $K = R_r*R$&lt;/li&gt;&#xA;&lt;li&gt;$tw$ is the vector formed by $tw = W_r*T$, its elements are&#xA;$[tw_x,tw_y,tw_z]$&lt;/li&gt;&#xA;&lt;li&gt;$w1, w2, w3$ are the rows of the matrix $W_l$&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I'm solving this as: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Q*[M,1]^t = 0$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I look for a solution in the null space of $Q$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[M,1]^t$ would be hence be the null vector of Q.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$svd(Q) = [U,S,V]$ and $[M,1]^t$ would be the last column of &lt;em&gt;V&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result I get would be of form $[mx,my,mz,mk]$ so I simply divide all elements by $mk$ to get something of the form&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$[mx/mk,my/mk,mz/mk,1]$. I consider this to be the value of &lt;em&gt;X,Y,Z&lt;/em&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a better way to solve this? Correct me if I'm wrong here but I'm feel this could have been done in a simpler (more accurate) fashion.&lt;/p&gt;&#xA;" OwnerUserId="7663" LastActivityDate="2017-11-10T16:33:17.410" Title="3D reconstruction using 2D matched points" Tags="&lt;image-processing&gt;&lt;geometry&gt;&lt;projections&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5852" PostTypeId="1" AcceptedAnswerId="6076" CreationDate="2017-11-11T16:15:30.437" Score="2" ViewCount="928" Body="&lt;p&gt;I have an object(cow).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This cow was translated and rotated(with arbitrary axis) in the modeling space for several times.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I can't know how much cow is translated or rotated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Only I can obtain is this cow's current matrix and it's inverse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this circumstance, how can I rotate the cow around the x-axis in the viewing space?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(center of rotation is at the center of modeling space)&lt;/p&gt;&#xA;" OwnerUserId="7482" LastActivityDate="2018-03-07T11:54:23.580" Title="OpenGL : How to rotate an object around viewing space x-axis" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5853" PostTypeId="2" ParentId="5846" CreationDate="2017-11-11T20:41:18.200" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://youtu.be/dZG60_c29EI&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here’s&lt;/a&gt; a video that talks about a couple different techniques.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One idea mentioned in the video is to take the values from 0.0 to 1.0 you get from the noise and only care about ones within a certain range, (mapping the rest to 0.0). Further, you can map the values in that range to different values, following a curve. For instance if you take the values between 0.25 and 0.75 you can map 0.5 to 1.0 and fill in the values in between with a straight line. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another technique mentioned is to compose your noise function. Say you have a noise function that takes a 2d vector, you can call &lt;code&gt;Vec2(Noise(pos), Noise(pos + offset))&lt;/code&gt; to get a vector you can put into the noise function again. This gives an interesting skewed/streaky look. &lt;/p&gt;&#xA;" OwnerUserId="7669" LastActivityDate="2017-11-11T20:41:18.200" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5854" PostTypeId="1" AcceptedAnswerId="5855" CreationDate="2017-11-12T00:23:49.170" Score="5" ViewCount="1462" Body="&lt;p&gt;If I am writing my own function to check shader compile errors, or do anything that interacts with the OpenGL API but ultimately returns as a result of my application code, should I use the C++ &lt;code&gt;void&lt;/code&gt; or &lt;code&gt;GLvoid&lt;/code&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I.E.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLvoid Shader::check_compile_errors(GLuint ComputeShader, std::string type)&#xA;{&#xA;    const GLint log_length{ 1024 };&#xA;    GLchar info_log[log_length];&#xA;    GLint success;&#xA;&#xA;    if (type == &quot;PROGRAM&quot;)&#xA;    {&#xA;        glGetProgramiv(ComputeShader, GL_LINK_STATUS, &amp;amp;success);&#xA;        if (!success)&#xA;        {&#xA;            glGetProgramInfoLog(ComputeShader, log_length, nullptr, info_log);&#xA;            std::cout &amp;lt;&amp;lt; &quot;ERROR::PROGRAM_LINKING_ERROR of type: &quot; &amp;lt;&amp;lt; type &amp;lt;&amp;lt; &quot;\n&quot; &amp;lt;&amp;lt; info_log &amp;lt;&amp;lt; &quot;\n ---- &quot; &amp;lt;&amp;lt; std::endl;&#xA;        }&#xA;    }&#xA; // Here the return is implicitly void, but from C++ not OpenGL!&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I realize here that &lt;code&gt;GLvoid&lt;/code&gt; is typedef'd to void but I am wondering if there is any case where using the GL types could cause issues when it it is not explictly clear that the values are coming from OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another example would be writing an image to a file (from &lt;code&gt;glReadPixels&lt;/code&gt;). If I am setting fields in the header which normally takes things in the form &lt;code&gt;unsigned char&lt;/code&gt; should I change that to a &lt;code&gt;GLuchar&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2017-11-12T01:53:53.330" LastActivityDate="2017-11-15T04:40:24.777" Title="Is there ever a time when I should *not* use the GL* types?" Tags="&lt;opengl&gt;&lt;types&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5855" PostTypeId="2" ParentId="5854" CreationDate="2017-11-12T02:27:15.337" Score="4" Body="&lt;p&gt;Yes, there's a time not to use GL types when interacting with OpenGL: &lt;code&gt;GLvoid&lt;/code&gt;. There is absolutely no reason to use this type.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With everything else (assuming you're using a &quot;standard&quot; OpenGL loader), you should use OpenGL's types when &lt;em&gt;talking to OpenGL&lt;/em&gt;. That is, the values you pass to OpenGL functions should be in OpenGL's types. This may mean that a function that talks to OpenGL may need an OpenGL data type in its function parameter list. This should be avoided where possible, to prevent you from creating dependencies between OpenGL code and non-OpenGL code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you don't mind having large portions of your application have dependencies on OpenGL, you may use OpenGL's data types throughout your code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/OpenGL_Type&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL's data types&lt;/a&gt; are specified to have a particular bitdepth. As such, they are (conceptually, if not strictly C++-legally) pointer-interconvertible to certain types defined in &lt;code&gt;&amp;lt;stdint.h&amp;gt;/&amp;lt;cstdint&amp;gt;&lt;/code&gt;. Indeed, many OpenGL headers will check for the existence of this header and use it wherever it is available to define OpenGL's data types. As such, if you want a fixed bitdepth integer, you have a choice besides using OpenGL's data types.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I am wondering if there is any case where using the GL types could cause issues when it it is not explictly clear that the values are coming from OpenGL.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;OpenGL is C, not &lt;em&gt;magic&lt;/em&gt;. A function in C cannot have any control over the return value of the function that calls it. Even a C++ function cannot; at best, it can throw an exception, but this still doesn't have anything to do with its caller's return value.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-11-15T04:40:24.777" LastActivityDate="2017-11-15T04:40:24.777" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5858" PostTypeId="1" AcceptedAnswerId="5868" CreationDate="2017-11-12T18:20:38.473" Score="0" ViewCount="333" Body="&lt;p&gt;My current laptop has a fairly old Intel integrated GPU which was good enough for following simple tutorials.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am now keen on getting to grips with advanced techniques and newer APIs, and so I am looking for a new discrete GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to ignore the usual price/performance metric for GPUs, as I assume that's going to be irrelevant for a hobbyist programmer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a pragmatic reason to prefer AMD over Nvidia or vice versa?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A cursory search shows that some tools are exclusive to one vendor (e.g. Nvidia Nsight), but is one significantly better than the other or are the differences minor?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will drivers make a difference here also? And finally will I run into a lot of example code specific to one vendor?&lt;/p&gt;&#xA;" OwnerUserId="7674" LastEditorUserId="7674" LastEditDate="2017-11-12T20:09:29.047" LastActivityDate="2017-11-13T21:16:13.317" Title="Should I prefer an AMD or Nvidia GPU for studying graphics programming, especially with respect to vendor specific debugging tools and ecosystem?" Tags="&lt;gpu&gt;&lt;debugging&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5859" PostTypeId="1" AcceptedAnswerId="5869" CreationDate="2017-11-12T20:43:52.890" Score="4" ViewCount="354" Body="&lt;p&gt;I have been recently exploring physically-based rendering (PBR), but there is one part that still confuses me. I don't quite get roughness remapping, as described in the &lt;a href=&quot;https://learnopengl.com/#!PBR/Theory/&quot; rel=&quot;noreferrer&quot; title=&quot;PBR Theory&quot;&gt;PBR section&lt;/a&gt; on Learn OpenGL. Specifically, scroll down until you find &lt;em&gt;Geometry function&lt;/em&gt;. This remapping is described in several other papers / courses as well, such as &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf/&quot; rel=&quot;noreferrer&quot; title=&quot;Disney PBR&quot;&gt;Disney&lt;/a&gt; and &lt;a href=&quot;https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf/&quot; rel=&quot;noreferrer&quot; title=&quot;Real Shading in Unreal Engine 4&quot;&gt;Epic Game's PBR Course&lt;/a&gt;. Is this remapping solely artistic, or is there some physical reasoning in it? A quick answer and explanation would be quite appreciated :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TL;DR What in the world is roughness remapping for?&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-11-14T09:00:32.263" Title="Roughness Remapping" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5860" PostTypeId="1" AcceptedAnswerId="5871" CreationDate="2017-11-13T01:31:53.133" Score="0" ViewCount="225" Body="&lt;p&gt;I have two columns of data, x(angle) and y(distance), they are my experiment results(figure 1). How can I use these results to make a ‘hotmap diagram’ by matlab? The z axis is the density value of xy dots in the 2D coordinate department, like below figure2. Thank you!&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CVbH8.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CVbH8.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/swpBg.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/swpBg.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7675" LastActivityDate="2017-11-14T16:58:08.963" Title="Matlab scatter hotmap" Tags="&lt;image-processing&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ClosedDate="2017-11-16T21:50:17.697" ContentLicense="CC BY-SA 3.0" />
  <row Id="5861" PostTypeId="1" AcceptedAnswerId="5863" CreationDate="2017-11-13T07:51:43.630" Score="3" ViewCount="310" Body="&lt;p&gt;I'm wondering what happens with the framebuffer between the time that the fragment shader is done, and the time when it appears on my screen. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is my understanding correct if I assume that the framebuffer is in memory on the GPU, which is then copied back to the CPU side after glDrawX is completed, and then fit to a window somewhere on the screen, and then sent through my HDMI cable (via the GPU again!) to my monitor?&lt;/p&gt;&#xA;" OwnerUserId="4650" LastActivityDate="2017-11-13T09:42:58.247" Title="What happens with the framebuffer after the fragment shader is done?" Tags="&lt;frame-buffer&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5862" PostTypeId="1" AcceptedAnswerId="5864" CreationDate="2017-11-13T08:08:18.760" Score="0" ViewCount="159" Body="&lt;p&gt;Given an input signal(ex. sine) how can one go about plotting an image like below ones(the stripped black and white image)? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The images are from &lt;a href=&quot;http://www.robots.ox.ac.uk/~az/lectures/ia/lect2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;these slides&lt;/a&gt; on image processing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4ZhOo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4ZhOo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or this one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LjYJ8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LjYJ8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2017-11-13T10:32:58.587" LastActivityDate="2017-11-13T10:32:58.587" Title="How to plot an input signal in image?" Tags="&lt;image-processing&gt;&lt;antialiasing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5863" PostTypeId="2" ParentId="5861" CreationDate="2017-11-13T09:42:58.247" Score="4" Body="&lt;p&gt;It entirely depends what hardware and OS you're on. It's up to the integration between the windowing system and GL. In the simple case where one application is rendering full-screen directly, the framebuffer is in memory that's accessible by both the GPU and the display controller. After the GPU is finished, and when the display controller gets to a vsync (the time to start drawing a new frame to the screen), the display controller just reads out the framebuffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a compositing system like modern MS Windows or Android, your app's framebuffer is not used by the display controller directly. After you finish drawing your frame, the compositor runs. On the GPU, it reads in your framebuffer, puts it in the right place on the desktop, and writes the composited desktop into the real framebuffer. The display controller then reads out the desktop framebuffer. There's also an optimization possible using &lt;a href=&quot;https://computergraphics.stackexchange.com/q/5271/20410&quot;&gt;overlays&lt;/a&gt;, which we have another question about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Copying completed frames into CPU memory is to be avoided. If you had to do this every frame, your application probably couldn't run at a reasonable frame-rate. Even reading back a single pixel (with &lt;code&gt;glReadPixels&lt;/code&gt;) is a big slow-down, because the CPU has to wait for the GPU to finish, and they have to invalidate the cache of any shared memory. Reading back a million pixels is extra slow on desktop because the CPU and GPU have separate memory and the path between them is relatively slow. It's very rare that it should be necessary: mainly it's needed for screenshots, or for debugging.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-11-13T09:42:58.247" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5864" PostTypeId="2" ParentId="5862" CreationDate="2017-11-13T09:49:43.823" Score="1" Body="&lt;p&gt;If you're using Python, you can use a library such as matplotlib for this. It can take a numpy array and plot it as a standard chart using the function &lt;code&gt;plot&lt;/code&gt; or as an image using &lt;code&gt;imshow&lt;/code&gt;. The resulting image/plot can be displayed in an interactive window, or saved to a file, or it shows inline in your Jupyter notebook if you're using that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are other (better?) Python chart plotting libraries but the functionality is basic and IMO matplotlib is easier to get started with (perhaps just because it's older and more established).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also do this using OpenCV, if your input is an OpenCV image. Its plotting functions are named similarly to the matplotlib ones. OpenCV is available in Python, C++, and a handful of other languages.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-11-13T09:49:43.823" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5865" PostTypeId="2" ParentId="5854" CreationDate="2017-11-13T10:38:51.130" Score="2" Body="&lt;p&gt;GL's types aren't true types but &lt;code&gt;typedef&lt;/code&gt;s for platform types. So when you think about &lt;code&gt;GLuint&lt;/code&gt; &lt;em&gt;vs.&lt;/em&gt; &lt;code&gt;unsigned int&lt;/code&gt;, you should consider that in the same way you consider &lt;code&gt;unsigned int&lt;/code&gt; &lt;em&gt;vs.&lt;/em&gt; &lt;code&gt;uint32_t&lt;/code&gt;. If you are only writing for a single platform, you should read your system's &lt;code&gt;GL/gl.h&lt;/code&gt; and pay attention to the section that looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef unsigned int    GLenum;&#xA;typedef unsigned char   GLboolean;&#xA;typedef unsigned int    GLbitfield;&#xA;typedef void        GLvoid;&#xA;typedef signed char GLbyte;     /* 1-byte signed */&#xA;typedef short       GLshort;    /* 2-byte signed */&#xA;typedef int     GLint;      /* 4-byte signed */&#xA;typedef unsigned char   GLubyte;    /* 1-byte unsigned */&#xA;typedef unsigned short  GLushort;   /* 2-byte unsigned */&#xA;typedef unsigned int    GLuint;     /* 4-byte unsigned */&#xA;typedef int     GLsizei;    /* 4-byte signed */&#xA;typedef float       GLfloat;    /* single precision float */&#xA;typedef float       GLclampf;   /* single precision float in [0,1] */&#xA;typedef double      GLdouble;   /* double precision float */&#xA;typedef double      GLclampd;   /* double precision float in [0,1] */&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If your coding standard says you should always use the old C types instead of the guaranteed-width types like &lt;code&gt;uint32_t&lt;/code&gt;, and you should avoid unnecessary casts, maybe it makes sense to just use the appropriate native type instead of the GL names. As Nicol Bolas says, it avoids having to include &lt;code&gt;GL/gl.h&lt;/code&gt;. If your coding standard prefers using the guaranteed-width types, maybe it makes sense to keep using those in your non-GL code, and to think more carefully about when you pass those to functions taking GL type names.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you avoid explicit casts wherever possible and you compile with warnings enabled, it'll be much easier to switch to a new platform where the &lt;code&gt;typedef&lt;/code&gt;s are different, because the compiler will warn you about numeric conversions that might lose information. If you explicitly cast from (say) &lt;code&gt;GLint&lt;/code&gt; to &lt;code&gt;int&lt;/code&gt;, but then move to a platform where &lt;code&gt;int&lt;/code&gt; is 16-bit and &lt;code&gt;GLint&lt;/code&gt; is a &lt;code&gt;typedef&lt;/code&gt; for &lt;code&gt;uint32_t&lt;/code&gt;, then the explicit cast will stop the compiler warning you about the narrowing conversion.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-11-13T10:38:51.130" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5867" PostTypeId="1" CreationDate="2017-11-13T17:35:59.287" Score="4" ViewCount="148" Body="&lt;p&gt;What is the color of the sky depending on the time?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking for a set of colors (HTML-Code), the sky has during sunrise, morning, forenoon, noon, afternoon, evening and sunset. A formula to calculate the color would be awesome.&lt;/p&gt;&#xA;" OwnerUserId="7678" LastEditorUserId="231" LastEditDate="2017-12-12T20:00:16.087" LastActivityDate="2017-12-12T20:00:16.087" Title="Color of the Sky" Tags="&lt;color&gt;&lt;atmospherics&gt;" AnswerCount="0" CommentCount="9" ClosedDate="2017-12-12T20:05:08.377" ContentLicense="CC BY-SA 3.0" />
  <row Id="5868" PostTypeId="2" ParentId="5858" CreationDate="2017-11-13T21:16:13.317" Score="3" Body="&lt;p&gt;If you want to learn OpenGL X.Y or DirectX A.B then shop for hardware that supports that specification. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're using other software (Blender, Maya, 3DSMax, etc) you'll want to make sure it's supported.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your OS has a history of issues with a particular vendor, adjust accordingly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Beyond that, it's not going to matter much, especially at the hobbyist level.&#xA;Price / performance metrics are still relevant, it's just that the definition of performance is different.&lt;/p&gt;&#xA;" OwnerUserId="5349" LastActivityDate="2017-11-13T21:16:13.317" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5869" PostTypeId="2" ParentId="5859" CreationDate="2017-11-14T08:54:25.413" Score="2" Body="&lt;p&gt;In general, artists like working with a linear roughness value between 0 and 1 (similarly for all other material parameters), since this is easier to work with and to understand compared to directly using the parameters of certain BRDF components as presented in the literature. Disney for instance always uses linear material parameters for their Disney BRDF in the range [0,1] from the perspective of the artists (see their &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;course notes&lt;/a&gt; on page 18). Working with linear values in the range [0,1] also simplifies storing and loading these values in RGB or sRGB textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The actual roughness used in the BRDF equations is non-linear. So one needs to map linear to non-linear roughness in some computationally cheap way that pleases the artists. The most important thing is to be consistent across your renderer and to explicitly specify when a roughness parameter is linear or non-linear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is worth reading &lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moving Frostbite to Physically Based Rendering 3.0&lt;/a&gt;. These course notes explicitly use the terminology linear roughness and (non-linear) roughness, both in the text and code samples. Furthermore, it is also worth reading &lt;a href=&quot;http://graphicrants.blogspot.be/2013/08/specular-brdf-reference.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Specular BRDF Reference&lt;/a&gt; which defines various BRDF components for the Cook-Torrance BRDF using the same non-linear roughness parameter $\alpha$ (defined as the square of the linear roughness $roughness$).&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2017-11-14T09:00:32.263" LastActivityDate="2017-11-14T09:00:32.263" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5871" PostTypeId="2" ParentId="5860" CreationDate="2017-11-14T16:58:08.963" Score="1" Body="&lt;p&gt;You basically need to plot the scatter map with varying colors for each point&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;scatter(x, y, [], c);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The main difficulty is to calculate&lt;code&gt;c&lt;/code&gt; so that it’s proportional to the density. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do so you can divide the map into a grid of a certain resolution, say &lt;code&gt;[res_x, res_y]&lt;/code&gt;. Then count for each grid cell how many points are there. This count is an approximation of the density at that grid cell. Finally you can assign to all points within this grid cell the &lt;code&gt;c&lt;/code&gt; value equal this count. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Probably you also need to normalize &lt;code&gt;c&lt;/code&gt; to &lt;code&gt;[0, 1]&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="7680" LastActivityDate="2017-11-14T16:58:08.963" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5872" PostTypeId="2" ParentId="5821" CreationDate="2017-11-14T17:19:54.190" Score="2" Body="&lt;p&gt;I would say it’s a &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Set_cover_problem&quot; rel=&quot;nofollow noreferrer&quot;&gt;weighted set covering&lt;/a&gt; problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In specific, the cost for a set of points is the number of extra pixels in the bounding rectangle of this set.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the number of diff points is small, you can solve this by linear programming. Otherwise, try some approximated algorithms e.g. greedy.&lt;/p&gt;&#xA;" OwnerUserId="7680" LastActivityDate="2017-11-14T17:19:54.190" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5874" PostTypeId="1" AcceptedAnswerId="5877" CreationDate="2017-11-14T18:31:59.083" Score="6" ViewCount="174" Body="&lt;p&gt;I’m not sure if I’m posting this question in the right area but, I’m wondering what determines the color gamut of a display?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is or hardware down to the RGB filter built into a display like a monitor etc or is it software like a different color profile?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Question stems from the curiosity of if one display’s color gamut can be changed or not&lt;/p&gt;&#xA;" OwnerUserId="7693" LastActivityDate="2017-11-14T22:55:00.863" Title="What determines the color gamut of a display?" Tags="&lt;color&gt;&lt;color-science&gt;&lt;color-management&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5876" PostTypeId="2" ParentId="5625" CreationDate="2017-11-14T18:39:12.280" Score="3" Body="&lt;p&gt;Here's my introduction: &lt;a href=&quot;http://www.gabrielgambetta.com/computer-graphics-from-scratch/raytracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.gabrielgambetta.com/computer-graphics-from-scratch/raytracing.html&lt;/a&gt; It uses the somewhat contrived analogy of making a painting by putting a grid in front of a real landscape, and painting a square of the colour you see through each hole in the grid. A raytracer is essentially that, but with some linear algebra :)&lt;/p&gt;&#xA;" OwnerUserId="7692" LastActivityDate="2017-11-14T18:39:12.280" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5877" PostTypeId="2" ParentId="5874" CreationDate="2017-11-14T22:55:00.863" Score="4" Body="&lt;p&gt;The physical imaging elements of your monitor define your gamut. So things like how bright the elements can be as well as the color spectra of the color elements define the gamut. But, thats quite the simplification, its also affected by such things as the screen surface material and background lighting conditions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can the gamut be changed? Sure, if you want a smaller gamut then you can restrict your colors to a subrange of your gamut.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-11-14T22:55:00.863" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5878" PostTypeId="1" AcceptedAnswerId="5880" CreationDate="2017-11-15T06:52:11.777" Score="2" ViewCount="327" Body="&lt;p&gt;First of all, I'm using OpenGL and GLM. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I have a square perpendicular to the z-axis and centered around it. Let's say that it has Z-value (offset along the Z-axis) X. Now, I want to set up a projective camera, its position is &lt;code&gt;(0, 0, Y)&lt;/code&gt; looking at &lt;code&gt;(0, 0, 0)&lt;/code&gt;. The perspective is: viewing &lt;code&gt;angle=45&lt;/code&gt; degrees, &lt;code&gt;far=100&lt;/code&gt;, &lt;code&gt;near = 0.1&lt;/code&gt;, &lt;code&gt;aspect=1&lt;/code&gt;) I'm using &lt;code&gt;glm::lookat()&lt;/code&gt; and &lt;code&gt;glm::perspective()&lt;/code&gt;. &#xA;How can I calculate the value for Y from X (given the parameters I've described)? &lt;/p&gt;&#xA;" OwnerUserId="7695" LastEditorUserId="7457" LastEditDate="2017-11-15T12:27:04.337" LastActivityDate="2017-11-15T12:27:04.337" Title="How to calculate camera distance so that after projective transformation a quad is filling the whole screen" Tags="&lt;transformations&gt;&lt;perspective&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5880" PostTypeId="2" ParentId="5878" CreationDate="2017-11-15T10:43:13.663" Score="1" Body="&lt;p&gt;Fortunately your scenario is rather simple, your camera is on a line directly perpendicular above and centered on the quad you're concerned about. So what you want is for the quad to fill the whole screen, I assume (more or less) exactly the whole screen, i.e. the size of your projected quad in window space is your entire viewport.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The mathematics of this are rather easy if you understand how the perspective matrix is actually constructed and what it does and if you know some basic trigonometry. The matrix constructed with &lt;code&gt;glm::perspective&lt;/code&gt; takes as viewing angle the field of view along the y-axis and is based on goold old &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;gluPerspective&lt;/code&gt;&lt;/a&gt;. And if we take a look at the actual matrix, we can see that it transforms a $1$ high object sitting on the view axis at distance $1$ from the camera to a height of $\cot \frac{\alpha}{2}$ ($\alpha$ being your view angle). If you move it further away it obviously gets smaller and if you increase its height, it gets larger, so it's $\frac{h}{d}\cot\frac{\alpha}{2}$ for camera distance $d$ and object height $h$. We want that height to be equal to $1$ (the height, from the center, of the view plane in NDC space).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So all you need to know in addition to that is the size of your square in the y-direction. We take half that height (because the square is centered) and multiply that by $\cot\frac{\alpha}{2}$ to get the distance it has to be from the camera. So if your square vertices have the y-coordinate +/-H and given your other values:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$Y-X = H\cot22.5°$$&#xA;$$Y = X+H\cot22.5°$$&#xA;$$Y \approx X+2.41421H$$&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2017-11-15T10:43:13.663" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5881" PostTypeId="1" CreationDate="2017-11-15T22:21:02.393" Score="1" ViewCount="67" Body="&lt;p&gt;We are trying to check some hardware and our 100Hz video card is running at 99.97Hz.  Maybe this is just the natural speed of the chip and it is called 100Hz.  I would have thought, however, that 100Hz is very slow for a computer and that control would closer to the megahertz.  Any insight would be appreciated.  Thanks&lt;/p&gt;&#xA;" OwnerUserId="7702" LastActivityDate="2017-11-15T22:21:02.393" Title="Is 100 Hz really 100 Hz, or is it 99.97Hz" Tags="&lt;video&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5882" PostTypeId="1" CreationDate="2017-11-16T09:03:40.417" Score="-1" ViewCount="58" Body="&lt;p&gt;I've basically 0-knowledge about augmented reality. For academic purposes I've to study this paper &lt;a href=&quot;http://ieeexplore.ieee.org/document/8007317/?reload=true&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://ieeexplore.ieee.org/document/8007317/?reload=true&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm struggling trying to understand some unclear concepts to me:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;what's environment mapping in this context?&lt;/li&gt;&#xA;&lt;li&gt;what's basically &quot;distance impostor tracing&quot;?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I've several doubts about the rest of the paper too, maybe someone may have some simple references to make me understand what's the pipeline they present does.&lt;/p&gt;&#xA;" OwnerUserId="7686" LastActivityDate="2017-11-16T15:38:58.350" Title="Natural Environment Illumination in Augmented Reality" Tags="&lt;global-illumination&gt;&lt;mobile&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5883" PostTypeId="1" AcceptedAnswerId="5899" CreationDate="2017-11-16T10:47:36.510" Score="1" ViewCount="2244" Body="&lt;p&gt;I am trying to read an input texture, modify it and then write to an output texture from a very simple compute shader.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For some reason I am not able to write to the output image from the compute shader.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The screen is black (even though I have a red clear color).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my application code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    // Compute shader&#xA;    (...Code to setup images)&#xA;    glTextureStorage2D(m_color_texture, 1, GL_RGB32F, m_src_fbo_size, m_src_fbo_size); // &amp;lt;- Yikes, wrong format!&#xA;    glTextureStorage2D(m_temp_texture, 1, GL_RGB32F, m_src_fbo_size, m_src_fbo_size); // &amp;lt;- Yikes, wrong format!&#xA;    m_compute_shader.use();&#xA;    glBindImageTexture(0, m_color_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);&#xA;    glBindImageTexture(1, m_temp_texture, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);&#xA;&#xA;    glDispatchCompute(m_info.window_width / 32, m_info.window_height / 32, 1);&#xA;&#xA;    // Full screen quad&#xA;    glBindImageTexture(0, m_temp_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);&#xA;    glDisable(GL_DEPTH_TEST);&#xA;    m_full_screen_quad_shader.use();&#xA;    glViewport(0, 0, m_info.window_width, m_info.window_height);&#xA;    glBindVertexArray(m_full_screen_quad_vao);&#xA;    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is the compute shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core&#xA;&#xA;layout (local_size_x = 32, local_size_y = 32) in;&#xA;&#xA;layout (binding = 0, rgba32f) readonly uniform image2D input_image;&#xA;layout (binding = 1, rgba32f) writeonly uniform image2D output_image;&#xA;&#xA;void main()&#xA;{&#xA;    vec4 texel;&#xA;    ivec2 p = ivec2(gl_GlobalInvocationID.xy);&#xA;&#xA;    texel = imageLoad(input_image, p);&#xA;    texel = vec4(1.0) - texel;&#xA;    imageStore(output_image, p, texel);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I just swap &lt;code&gt;m_temp_texture&lt;/code&gt; with &lt;code&gt;m_color_texture&lt;/code&gt; (which is the &lt;em&gt;input&lt;/em&gt; image )    in the call to &lt;code&gt;glBindImageTexture(0, m_temp_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA32F);&lt;/code&gt; then I see the image, so I know it is not a problem with the frag shader. (Here is is though anyway):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core&#xA;&#xA;layout (binding = 0) uniform sampler2D input_image;&#xA;&#xA;layout (location = 0) out vec4 fragColor;&#xA;&#xA;//uniform float focal_distance = 50.0;&#xA;//uniform float focal_depth = 30.0;&#xA;&#xA;void main()&#xA;{&#xA;    vec4 color = texelFetch(input_image, ivec2(gl_FragCoord.xy), 0).rgba;&#xA;    fragColor = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there some reason why my compute shader is not being called? Even if I just write &lt;code&gt;imageStore(output_image, p, vec4(1.0));&lt;/code&gt; in the compute shader, the screen is all black.  I do not know what I am missing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;glGetError&lt;/code&gt; does not return anything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I originally failed to include the code for the texture creation (the first two lines).  This affects the qustion. Please see the answer below. &lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2017-11-20T09:20:11.090" LastActivityDate="2017-11-20T09:21:22.790" Title="Issue with image load stores and compute shaders" Tags="&lt;opengl&gt;&lt;compute-shader&gt;&lt;image-load-store&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5884" PostTypeId="1" CreationDate="2017-11-16T13:52:47.747" Score="3" ViewCount="131" Body="&lt;p&gt;I don't know the name of this technique, but the idea is to adjust the density and location of identical dots or small objects in order to produce a gray tone image or even a suggestion of three dimensionality. It's better to use these two images below as examples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to do something like this on my own, but by writing relatively simple algorithm rather than a program or package. I'll be starting with a 3D representation of an object's surface inside a python script running in  Blender. &lt;em&gt;My question isn't how to implement, but how to understand what's happening&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could someone explain what this is called and share some amount of insight into how this works? I don't need a full-blown derivation, just some idea to get started on something simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In the screenshot&lt;/strong&gt;, the objects (in software) follow the face contour in 3D, but their position (and brightness) is fluid and their separation varies continuously. While they appear to be approximately on a grid, I'm not sure if they are a fixed projected grid (I think I've read somewhere it was done using a Kinect) and move because of the movement of the model, or if they move algorithmically as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;edit:&lt;/strong&gt; More info on the Kinect in the Below the Line article &lt;a href=&quot;http://www.btlnews.com/crafts/visual-fx/level-256-vfx-produces-the-final-moments-of-karl-brant-for-nerdist-com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Level 256 VFX Produces The Final Moments of Karl Brant for Nerdist.com&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;“Leveraging the power of open source applications like Processing, Python, and bash scripting, we were able to take the point cloud data from the Kinect, manipulate it, and get it into Nuke for integration with the live-action plates for texture re-projection,” Kleinberg explained. “The process evolved and grew over time, and when we finally saw the fruits of our labor on the screen, we were excited to see Karl Brant fully realized, taking on an expressive life of his own.”&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm familliar with something simple like using a random number to decide if the pixel should be on or off depending on the gray value; if it's 0.3, then if a random number (chosen for each pixel, but not necessarily randomized every frame) is below 0.3, the pixel should be ON (seems to be called 1-bit &lt;a href=&quot;https://en.wikipedia.org/wiki/Dither&quot; rel=&quot;nofollow noreferrer&quot;&gt;dithering&lt;/a&gt;). But I think there is a lot more going on here than that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;below:&lt;/strong&gt; Cropped screen shot at &lt;code&gt;11:23&lt;/code&gt; in the short film &lt;a href=&quot;https://www.youtube.com/watch?v=jFotiDbj-D4&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;The Final Moments of Karl Brandt&lt;/em&gt;&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FBas6.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FBas6.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5846" LastEditorUserId="5846" LastEditDate="2017-11-16T14:45:30.840" LastActivityDate="2017-11-17T00:24:38.170" Title="What is this technique called and how can I reproduce it algorithmically?" Tags="&lt;rendering&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5885" PostTypeId="2" ParentId="5882" CreationDate="2017-11-16T15:38:58.350" Score="0" Body="&lt;p&gt;This probably should go as a comment; however I don't have enough reputations to do so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't have access to the paper, and probably most of the people here don't either. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Did you check about the standard concepts in Computer Graphics of &lt;a href=&quot;https://en.wikipedia.org/wiki/Reflection_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;environment mapping&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Sprite_(computer_graphics)&quot; rel=&quot;nofollow noreferrer&quot;&gt;impostor&lt;/a&gt;? Do they make sense in this context or did the authors invent something new for their framework?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would say those are common techniques to reduce the scene complexity (which improves the performance of AR/VR systems), while trying to provide some level of reality. &lt;/p&gt;&#xA;" OwnerUserId="7680" LastActivityDate="2017-11-16T15:38:58.350" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5886" PostTypeId="2" ParentId="5884" CreationDate="2017-11-17T00:24:38.170" Score="2" Body="&lt;p&gt;I've done something similar. The way I did it was by using a height map image to change the positions of vertices in a grid in a vertex shader. I generated a 2D grid of vertices that were evenly spaced on the CPU. I uploaded the vertices and a texture and in the vertex shader, I sampled the texture and used the resulting brightness as the height. So I'd keep the x and y positions of each vertex and change the z based on the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now there are other ways you could utilize this to get something more like in the video. You could either have a 2D grid of single vertices, or even a grid of small 3D models. Change the z position based on the color of a height map. But additionally, you could upload a small noise texture and vary the x and y positions by a small amount based on the noise, which might vary per frame. I would see if you could vary the x and y by a large enough amount to see, but small enough that no point ever crossed over a neighbor point. That would get you some more movement and randomness.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-11-17T00:24:38.170" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5887" PostTypeId="1" AcceptedAnswerId="5888" CreationDate="2017-11-17T10:42:29.130" Score="4" ViewCount="3142" Body="&lt;p&gt;The maximum allowed number of threads per compute shader group is 1024 for Shader Model 5.0. Is it advisable with regard to performance to stay close to this maximum number?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to resolve SSAA and MSAA (down-scaling with appropriate tone mapping), I wrote some compute shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One general compute shader works in all cases and performs one task without synchronization for each output texel and uses [numthreads(16, 16, 1)] (= 256 threads/group which is a multiple of NVidia's warp size of 32 and AMD's wavefront size of 64). Algorithmically, this does not result in the best performance, since for MSAA $T$x, each task performs $T$ texture loads from the radiance, normal and depth textures, and for SSAA $T$x, each task performs $T \times T$ texture loads from the radiance, normal and depth textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So instead of dispatching jobs in terms of output texels, I have some specialized compute shaders performing tasks with synchronization for each input texel (for SSAA) or for each subsample of an input texel (for MSAA). Here, each task performs $1$ texture load from the radiance, normal and depth textures and stores the results in group shared memory. Next, a &lt;code&gt;GroupMemoryBarrierWithGroupSync&lt;/code&gt; takes place and only one job per output texel continues to finish the work. This is not ideal in case of many SSAA and MSAA samples, but for few samples such as MSAA 2x, one expects to see some gains. In practice, however, the general compute shader outperforms all the specialized compute shaders for both small and large numbers of samples/ouput texel?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SSAA 2x [numthreads(4, 16, 16)] = 1024 (multiple of 64): ~655 FPS vs ~577 FPS&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SSAA 3x [numthreads(9, 8, 8)]   =  576 (multiple of 64): ~265 FPS vs ~200 FPS&lt;/p&gt;&#xA;&#xA;&lt;p&gt;SSAA 4x [numthreads(16, 8, 8)]  = 1024 (multiple of 64): ~127 FPS vs  ~75 FPS&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can this be solely due to dispatching more threads/group? Can this be due to the synchronization of all threads per group (close to the maximum allowed number of threads)? Or is there some performance one needs to sacrifice in case of using a 3D instead of 2D block of threads per group? &lt;/p&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2017-11-17T15:45:29.037" Title="Threads per compute shader group" Tags="&lt;hlsl&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5888" PostTypeId="2" ParentId="5887" CreationDate="2017-11-17T15:45:29.037" Score="4" Body="&lt;p&gt;There shouldn't be any performance penalty inherent in using a 3D group over a 2D one, the dimensions are just an aid for programmers to map invocations on to memory locations (since you can read or write wherever you like). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The group size affects which invocations can access the same block of groupshared memory, so it forces all warps from the same group to run on the same SMP. If you have a shader that needs to move stuff around a lot in its local memory block (e.g. a bitonic sorter), a large group size is preferable, but in your case it shouldn't make much difference. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect your problem is with the idle threads within your warps. If I understand your question properly, you're using a thread per input texel or sample to do the texture reads, but then only a subset of these threads to do the processing? If so, you're sacrificing a lot of compute power within each warp. Remember, texture reads are done in minimum 2x2 blocks, and the results get cached in a way optimized for locality for the dimension of the texture (see &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/355/how-does-texture-cache-work-considering-multiple-shader-units&quot;&gt;this question&lt;/a&gt;). So although your general purpose shader might seem slow with all the texture reads, a lot of them will be effectively almost free. Also, the GPU does latency-hiding on slow memory reads, swapping in other warps until the result of the read is available. So your general purpose shader actually seems like the smart option here, as it maximizes compute power.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-11-17T15:45:29.037" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5889" PostTypeId="1" AcceptedAnswerId="5891" CreationDate="2017-11-17T18:18:19.923" Score="3" ViewCount="322" Body="&lt;p&gt;Due to perspective foreshortening, the projections of parallel lines (1D geometric objects) meet in their vanishing point (a 0D geometric object). Higher dimensional geometric objects also has higher dimensional vanishing objects. I am interested in vanishing points of the edges of the triangle &lt;/p&gt;&#xA;&#xA;&lt;p&gt;∆(p0, p1, p2) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;if p0T,p1T and p2T are given ? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea ?&lt;/p&gt;&#xA;" OwnerUserId="7710" LastActivityDate="2017-11-18T00:14:04.307" Title="Determining Vanishing Points of edges of Triangle using given Point" Tags="&lt;2d&gt;&lt;perspective&gt;&lt;vector-graphics&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5891" PostTypeId="2" ParentId="5889" CreationDate="2017-11-18T00:14:04.307" Score="1" Body="&lt;p&gt;Vanishing points are &quot;points at infinity&quot; in projective geometry, which are represented by $w = 0$ in homogeneous coordinates. You can construct the vanishing point of a ray or line by taking its $xyz$ direction vector and adjoining $w = 0$. (For a line, use the direction vector and its negation to get vanishing points in both directions.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can transform this homogeneous vector by your view/projection matrices as usual, and divide out $w$ from the result to find where the point lies in screen space. (If the result has $w \leq 0$ then it's behind the camera or off to the side.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-11-18T00:14:04.307" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5892" PostTypeId="1" CreationDate="2017-11-18T18:42:46.277" Score="4" ViewCount="337" Body="&lt;p&gt;I've got a discrete grayscale image (a.k.a. 2D rectangular array of floats). Its continuous representation (whether received via reconstruction with sinc, with a cubic kernel, with a triangle kernel...) is a continous 2D function, so it has isolines. I'm interested in calculating the magnitude of the derivative of the isoline at a given point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pic:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QErl7.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QErl7.png&quot; alt=&quot;diagram&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Red line is part of an isoline, and green arrows are example derivatives of that isoline at 2 points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my approximate solution:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float getCurvature(vec2 p) {&#xA;    vec2 grad = getBilinear(gradients, p);&#xA;    if(grad = vec2(0, 0)) return 0;&#xA;    else grad = normalize(grad);&#xA;&#xA;    vec2 gradP = perpendicularLeft(grad);&#xA;&#xA;    float val = getBilinear(img, p);&#xA;    float valLeft = getBilinear(img, p+gradP);&#xA;    float valRight = getBilinear(img, p-gradP);&#xA;    return (val - (valLeft + valRight) * .5f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It basically computes the second directional derivative in a direction perpendicular to the gradient. It works fine for my purposes, except that it's somewhat slow in the CPU implementation (and I have reasons not to port it to GPU).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any faster (and/or more accurate) method?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; I found a twice-faster method, still calculating the second derivative, but in a simpler way. It's equation (5) &lt;a href=&quot;http://mathonline.wikidot.com/higher-order-directional-derivatives&quot; rel=&quot;noreferrer&quot;&gt;on this page&lt;/a&gt;. It works, but the result is more crude. I think I should switch to a higher-quality differentiation kernel than [+1, 0, -1].&lt;/p&gt;&#xA;" OwnerUserId="3085" LastEditorUserId="3085" LastEditDate="2017-11-18T19:41:34.780" LastActivityDate="2018-03-20T05:41:07.777" Title="How to calculate curvature of isoline of image" Tags="&lt;algorithm&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5894" PostTypeId="2" ParentId="5311" CreationDate="2017-11-19T17:08:37.160" Score="2" Body="&lt;p&gt;Long story short: downscale using a standard downscaling algorithm. Then multiply the value in each element by &lt;code&gt;originalArea/scaledArea&lt;/code&gt;. This is what Rahul meant in the comments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why that works:&lt;br&gt;&#xA;You can think of every output pixel as a (weighted or not) average of a neighbourhood of the source pixel. And as we know:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;average = sum / count&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now, for the caveats.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Broadly, there are 3 types of downscaling algorithms:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Ones that simply do resampling with some kernel&lt;br&gt;&#xA;1.1. Ones that lowpass first&lt;br&gt;&#xA;1.2. Ones that don't&lt;/li&gt;&#xA;&lt;li&gt;Pyramid downscaling&lt;/li&gt;&#xA;&lt;li&gt;Algorithms like the one in &quot;Genuine Fractals&quot; which are intended for detail-preserving &lt;strong&gt;up&lt;/strong&gt;scaling, but could conceivably be abused for downscaling&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Since &quot;3.&quot; is not intended for downscaling, it's not useful for your case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with &quot;1.2.&quot; is that, normally a small (e.g. 5x5) resampling kernel is used, which means that only a few of the source pixels are taken into account. In image resizing applications, this can manifest as aliasing. In your application, it can manifest as inaccuracy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This problem with &quot;1.2.&quot; can be fixed by using a big resampling kernel. I believe that's what the ImageMagick library used to do. E.g. taking a good-quality kernel like Lanczos and stretching it by x and y. Or you could go ahead and use a big box kernel like you describe in the question. Which one is appropriate depends on your exact application, but if you're dead set on using a box kernel, use that. The algorithm you described in the question would work fine, and I believe that on a CPU there is no better one (except splitting this one into threads), for the reason that any algorithm would need at least N (number of pixels) operations to take into account all the pixels, and your algorithm does a tiny amount of work for each of these N pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But on the GPU there is a better algorithm that takes full advantage of the GPU's strong parallelism. It's called &quot;parallel reduction&quot;, you can find info on it based on that. Since it's widely documented, I'll just sketch the algorithm:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Iteratively downscale the image by a factor of 2 by x and y until you get to your desired size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;1.1.&quot; would probably also suit your needs, but I won't comment on it for now, as it's not much better than the other options.&lt;/p&gt;&#xA;" OwnerUserId="3085" LastActivityDate="2017-11-19T17:08:37.160" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5895" PostTypeId="1" AcceptedAnswerId="5900" CreationDate="2017-11-19T22:00:55.527" Score="3" ViewCount="2094" Body="&lt;p&gt;Before I get downvoted. I am not asking how to use them, I know how to use them. I am trying to understand what they are. For example, an array is actually a contiguous section of memory, a linked list is actually just a clever way of using memory addresses, a 3D array is actually just a 1D array being used in a clever fashion...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Under that logic, VBO's are sections of GPU RAM that contain rendering data. They are thus &quot;arrays&quot;. But then what is a VAO? My current understanding is that they are magical &quot;boxes&quot; that somehow store machine state information for a set of VBO's, but what are they actually?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because for example, as far as I know, you MUST bind the VBO's under a VAO to get rendering output, if you just bind the VAO you won't get outpt, so what is their purpouse?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2017-11-20T16:19:54.260" Title="What is an OpenGL VAO in a nutshell?" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;&lt;buffers&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5896" PostTypeId="2" ParentId="5892" CreationDate="2017-11-20T03:16:23.037" Score="2" Body="&lt;p&gt;Gradient magnitude and angle can be found using a &lt;a href=&quot;https://en.wikipedia.org/wiki/Sobel_operator&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sobel operator&lt;/a&gt;. It's more sophisticated than the [1, 0, -1]. This is commonly used either directly for &lt;a href=&quot;https://en.wikipedia.org/wiki/Edge_detection&quot; rel=&quot;nofollow noreferrer&quot;&gt;edge detection&lt;/a&gt;, or as part of a &lt;a href=&quot;https://en.wikipedia.org/wiki/Canny_edge_detector&quot; rel=&quot;nofollow noreferrer&quot;&gt;more complex algorithm&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or, if I've misunderstood, and you want only the curvature of the 2D isoline, &lt;a href=&quot;https://math.stackexchange.com/questions/1122819/numerical-approximation-for-2d-curvature&quot;&gt;this answer on Math Overflow&lt;/a&gt; might be of use.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-11-20T03:16:23.037" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5897" PostTypeId="2" ParentId="5895" CreationDate="2017-11-20T07:08:19.690" Score="2" Body="&lt;p&gt;VAOs are essentially 'plumbing' objects that help get data from your buffers into your vertex shader ready for drawing. On the GPU this is handled by the vertex fetch stage, so a VAO is basically just a bundle of vertex fetch state corresponding to a particular model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can think of it as a bundle of pointers, but with somewhat more complexity than CPU-side pointers. Since OpenGL buffers are just a blob of untyped bytes by default (that's why you get a void* when you map them), the VAO handles type-casting (to vec3 or whatever) when fetching the data. It also deals with the size of the data not necessarily matching the stride between consecutive elements, and makes sure that each data item (position, normal, uv, etc.) is transmitted to the correct 'channel' in the vertex shader input.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can render without a VAO in legacy OpenGL, but this is generally more of a PITA, since you need to bind each vertex attribute separately each time you draw the object. Encapsulating all these bindings in a VAO lets you set them up once, then you have a 'plug and play' object that simply needs to be bound before a draw call, and all your vertex data will be ready to go.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-11-20T07:08:19.690" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5899" PostTypeId="2" ParentId="5883" CreationDate="2017-11-20T09:21:22.790" Score="0" Body="&lt;p&gt;Originally mistmatching image formats (&lt;code&gt;GL_RGB32F&lt;/code&gt; instead of &lt;code&gt;GL_RGBA32F&lt;/code&gt;) were used in the creation of textures and the call to &lt;code&gt;glBindImageTexture&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This error was hard to track down because the format (without alpha) only mattered (in this case) in the compute shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &lt;code&gt;GL_RGBA32F&lt;/code&gt;everywhere fixed the issue.&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2017-11-20T09:21:22.790" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5900" PostTypeId="2" ParentId="5895" CreationDate="2017-11-20T10:33:14.170" Score="2" Body="&lt;p&gt;tl;dr The vao caches the calls to &lt;code&gt;glVertexAttribPointer&lt;/code&gt; et. al.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Every call to &lt;code&gt;glVertexAttribPointer&lt;/code&gt;, &lt;code&gt;glEnableVertexAttribArray&lt;/code&gt; and the binding of &lt;code&gt;gl_Element_Array&lt;/code&gt; will store the parameters into the currently bound vao. In the case of &lt;code&gt;glVertexAttribPointer&lt;/code&gt; it will also store the current binding to &lt;code&gt;GL_VERTEX_ARRAY&lt;/code&gt; in the vao.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a major help when drawing a lot of meshes because then the render loop turns from&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void drawMesh(Mesh[] meshes){&#xA;    foreach(mesh in meshes){        &#xA;        glBindBuffer(GL_ARRAY_BUFFER, mesh.vbo);&#xA;        glVertexAttribPointer(posAttrLoc, 3, GL_FLOAT, false, sizeof(Vertex), mesh.vboOffset + offsetof(Vertex, pos));&#xA;        glVertexAttribPointer (normalAttrLoc, 3, GL_FLOAT, false, sizeof(Vertex), mesh.vboOffset + offsetof(Vertex, normal));&#xA;        //...&#xA;        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.ebo);&#xA;&#xA;        glDrawElements(GL_TRIANGLES, mesh.vertexCount, GL_UNSIGNED_INT, mesh.indexOffset);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;into &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//done once per mesh on load&#xA;void prepareMeshForRender(Mesh mesh){&#xA;    glBindVertexArray(mesh.vao);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, mesh.vbo);&#xA;&#xA;    glVertexAttribPointer (posAttrLoc, 3, GL_FLOAT, false, sizeof(Vertex), mesh.vboOffset + offsetof(Vertex, pos));//will associate mesh.vbo with the posAttrLoc&#xA;    glEnableVertexAttribArray(posAttrLoc);&#xA;&#xA;    glVertexAttribPointer (normalAttrLoc, 3, GL_FLOAT, false, sizeof(Vertex), mesh.vboOffset + offsetof(Vertex, normal));&#xA;    glEnableVertexAttribArray(normalAttrLoc);&#xA;&#xA;    //...&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.ebo); //this binding is also saved.&#xA;    glBindVertexArray(0);&#xA;}&#xA;&#xA;void drawMesh(Mesh[] meshes){&#xA;    foreach(mesh in meshes){        &#xA;        glBindVertexArray(mesh.vao);&#xA;        glDrawElements(GL_TRIANGLES, mesh.vertexCount, GL_UNSIGNED_INT, mesh.indexOffset);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This means a lot less calls and the driver can do some optimizations because it knows which vertex formats will be used. (some hardware has to do software vertex pulling so suddenly having a new format will require a patch of the vertex shader).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In version 4.3 (or with extension ARB_separate_attrib_format) there is a new way to bind the vertex attributes where the vao holds the format separately from the buffer binding to help exactly the above mentioned hardware: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//accessible constant declarations&#xA;constexpr int vertexBindingPoint = 0;&#xA;constexpr int texBindingPoint = 1;// free to choose, must be less than the GL_MAX_VERTEX_ATTRIB_BINDINGS limit&#xA;&#xA;//during initialization&#xA;glBindVertexArray(vao);&#xA;&#xA;glVertexAttribFormat(posAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, pos));&#xA;// set the details of a single attribute&#xA;glVertexAttribBinding(posAttrLoc, vertexBindingPoint);&#xA;// which buffer binding point it is attached to&#xA;glEnableVertexAttribArray(posAttrLoc);&#xA;&#xA;glVertexAttribFormat(normalAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, normal));&#xA;glVertexAttribBinding(normalAttrLoc, vertexBindingPoint);&#xA;glEnableVertexAttribArray(normalAttrLoc);&#xA;&#xA;glVertexAttribFormat(texAttrLoc, 2, GL_FLOAT, false, offsetof(Texture, tex));&#xA;glVertexAttribBinding(texAttrLoc, texBindingPoint);&#xA;glEnableVertexAttribArray(texAttrLoc);&#xA;&#xA;//...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then during draw you keep the vao bound and only change the buffer bindings.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void drawMesh(Mesh[] mesh){&#xA;    glBindVertexArray(vao);&#xA;&#xA;    foreach(mesh in meshes){&#xA;        glBindVertexBuffer(vertexBindingPoint, mesh.vbo, mesh.vboOffset, sizeof(Vertex));&#xA;        glBindVertexBuffer(texBindingPoint, mesh.texVbo, mesh.texVboOffset, sizeof(Texture));&#xA;        // bind the buffers to the binding point&#xA;&#xA;        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mesh.ebo);&#xA;&#xA;        glDrawElements(GL_TRIANGLES, mesh.vertexCount, GL_UNSIGNED_INT, mesh.indexOffset);&#xA;        //draw&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;note: code sourced from now defunct docs.SO article on it &lt;a href=&quot;https://gist.github.com/ratchetfreak/be5d870396c6e43af3372344001e5339&quot; rel=&quot;nofollow noreferrer&quot;&gt;cached copy available here&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-11-20T10:33:14.170" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5901" PostTypeId="2" ParentId="54" CreationDate="2017-11-20T16:16:00.740" Score="4" Body="&lt;p&gt;I stumbled on this blog:&#xA;&lt;a href=&quot;http://diaryofagraphicsprogrammer.blogspot.com/2014/03/compute-shader-optimizations-for-amd.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Compute Shader Optimizations for AMD&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given what tricks can be done in compute shader (that are specific only to compute shaders) I was curious if parallel reduction on compute shader was faster than on pixel shader. I e-mail'ed the author, Wolf Engel, to ask if he had tried pixel shader. He replied that yes and back when he wrote the blog post the compute shader version was substantially faster than the pixel shader version. He also added that today the differences are even bigger. So apparently there are cases where using compute shader can be of great advantage.&lt;/p&gt;&#xA;" OwnerUserId="7725" LastEditorUserId="231" LastEditDate="2018-03-04T00:36:31.087" LastActivityDate="2018-03-04T00:36:31.087" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5902" PostTypeId="2" ParentId="5895" CreationDate="2017-11-20T16:19:54.260" Score="0" Body="&lt;p&gt;Buffer objects contain your vertex data. Vertex array objects tell OpenGL how to &lt;em&gt;interpret&lt;/em&gt; that data. Without the VAO, OpenGL just knows that you suck some bytes into some buffers. The VAO says that &quot;in this buffer, at byte offset X, is an array of 4-vector floats, and that data will be fed to attribute index Y.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They're state objects. VAOs are no more &quot;magical&quot; than this C++ data structure:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct VertexFormat&#xA;{&#xA;  bool enabled = false;&#xA;  int attribute_index;&#xA;  VertexFormatType data_type; //Is f32, f64, or int32.&#xA;  int num_components = 4;&#xA;  bool normalized = false;&#xA;  GLenum type;&#xA;  int binding;    //The `bindings` index this attribute gets its data from.&#xA;  intptr_t offset;&#xA;};&#xA;&#xA;struct VertexBufferBinding&#xA;{&#xA;  BufferObject buffer;&#xA;  intptr_t offset;&#xA;  intptr_t stride;&#xA;  int instancing;&#xA;};&#xA;&#xA;struct VertexArrayObject&#xA;{&#xA;  VertexFormat formats[16];&#xA;  VertexBufferBinding bindings[16];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The fields of &lt;code&gt;VertexFormat&lt;/code&gt; are specified by the &lt;code&gt;glVertexAttrib*Format&lt;/code&gt; or &lt;code&gt;glVertexAttrib*Pointer&lt;/code&gt; functions. In the case of the latter, it also specifies the corresponding &lt;code&gt;VertexBufferBinding&lt;/code&gt; data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that &lt;code&gt;VertexBufferBinding&lt;/code&gt; stores a buffer object. That's where that binding point reads its data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This structure is not magical; it simply explains how to read vertex data from its associated buffers.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-11-20T16:19:54.260" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5903" PostTypeId="2" ParentId="54" CreationDate="2017-11-20T21:00:26.293" Score="15" Body="&lt;p&gt;John has already written &lt;a href=&quot;https://computergraphics.stackexchange.com/a/60/7644&quot;&gt;a great answer&lt;/a&gt; so consider this answer an extension of his.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently working a lot with compute shaders for different algorithms. In general, I've found that compute shaders can be much faster than their equivalent pixel shader or transform feedback based alternatives.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you wrap your head around how compute shaders work, they also make a lot more sense in many cases. Using pixels shaders to filter an image requires setting up a framebuffer, sending vertices, using multiple shader stages, etc. Why should this be required to filter an image? Being used to rendering full-screen quads for image processing is certainly the only &quot;valid&quot; reason to continue using them in my opinion. I'm convinced that a newcomer to the compute graphics field would find compute shaders a much more natural fit for image processing than rendering to textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your question refers to image filtering in particular so I won't elaborate too much on other topics. In some of our tests, just setting up a transform feedback or switching framebuffer objects to render to a texture could incur performance costs around 0.2ms. Keep in mind that this excludes any rendering! In one case, we kept the exact same algorithm ported to compute shaders and saw a noticeable performance increase.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using compute shaders, more of the silicon on the GPU can be used to do the actual work. All these additional steps are required when using the pixel shader route:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Vertex assembly (reading the vertex attributes, vertex divisors, type conversion, expanding them to vec4, etc.)&lt;/li&gt;&#xA;&lt;li&gt;The vertex shader needs to be scheduled no matter how minimal it is&lt;/li&gt;&#xA;&lt;li&gt;The rasterizer has to compute a list of pixels to shade and interpolate the vertex outputs (probably only texture coords for image processing)&lt;/li&gt;&#xA;&lt;li&gt;All the different states (depth test, alpha test, scissor, blending) have to be set and managed&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You could argue that all the previously mentioned performance advantages could be negated by a smart driver. You would be right. Such a driver could identify that you're rendering a full-screen quad without depth testing, etc. and configure a &quot;fast path&quot; that skips all the useless work done to support pixel shaders. I wouldn't be surprised if some drivers do this to accelerate the post-processing passes in some AAA games for their specific GPUs. You can of course forget about any such treatment if you're not working on a AAA game.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What the driver can't do however is find better parallelism opportunities offered by the compute shader pipeline. Take the classic example of a gaussian filter. Using compute shaders, you can do something like this (separating the filter or not):&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;For each work group, divide the sampling of the source image across the work group size and store the results to group shared memory.&lt;/li&gt;&#xA;&lt;li&gt;Compute the filter output using the sample results stored in shared memory.&lt;/li&gt;&#xA;&lt;li&gt;Write to the output texture&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Step 1 is the key here. In the pixel shader version, the source image is sampled multiple times per pixel. In the compute shader version, each source texel is read only once inside a work group. Texture reads usually use a tile-based cache, but this cache is still much slower than shared memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The gaussian filter is one of the simpler examples. Other filtering algorithms offer other opportunities to share intermediary results inside work groups using shared memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is however a catch. Compute shaders require explicit memory barriers to synchronize their output. There are also fewer safeguards to protect against errant memory accesses. For programmers with good parallel programming knowledge, compute shaders offer much more flexibility. This flexibility however means that it is also easier to treat compute shaders like ordinary C++ code and write slow or incorrect code.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;References&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Compute_Shader&quot; rel=&quot;noreferrer&quot;&gt;OpenGL Compute Shaders wiki page&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;DirectCompute: Optimizations and Best Practices, Eric Young, NVIDIA Corporation, 2010 &lt;a href=&quot;http://on-demand.gputechconf.com/gtc/2010/presentations/S12312-DirectCompute-Pre-Conference-Tutorial.pdf&quot; rel=&quot;noreferrer&quot;&gt;[pdf]&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Efficient Compute Shader Proramming, Bill Bilodeau, AMD, 2011? &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Efficient%20Compute%20Shader%20Programming.pps&quot; rel=&quot;noreferrer&quot;&gt;[pps]&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;DirectCompute for Gaming - Supercharge your Engine with Compute Shaders, Layla Mah &amp;amp; Stephan Hodes, AMD, 2013, &lt;a href=&quot;http://developer.amd.com/wordpress/media/2013/04/DirectComputeForGaming_SuperchargeYourEngineWithComputeShaders.ppsx&quot; rel=&quot;noreferrer&quot;&gt;[pps]&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://diaryofagraphicsprogrammer.blogspot.ca/2014/03/compute-shader-optimizations-for-amd.html&quot; rel=&quot;noreferrer&quot;&gt;Compute Shader Optimizations for AMD GPUs: Parallel Reduction, Wolfgang Engel, 2014&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7644" LastEditorUserId="7644" LastEditDate="2017-11-21T13:33:56.480" LastActivityDate="2017-11-21T13:33:56.480" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5904" PostTypeId="1" AcceptedAnswerId="5952" CreationDate="2017-11-21T05:27:08.683" Score="9" ViewCount="1326" Body="&lt;p&gt;When reducing color depth and dithering with a 2 bit noise (with n=]0.5,1.5[ and output=floor(input*(2^bits-1) + n)), the ends of the value range (inputs 0.0 and 1.0) are noisy. It would be desirable to have them to be solid color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example: &lt;a href=&quot;https://www.shadertoy.com/view/llsfz4&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/llsfz4&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xFMrJ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xFMrJ.png&quot; alt=&quot;Noise gradient&quot;&gt;&lt;/a&gt;&#xA;(above is screenshot of the shadertoy, picturing a gradient and both ends which &lt;em&gt;should&lt;/em&gt; be solid white and black respectively, but are noisy instead)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem can be of course solved by just compressing the value range so that the ends get always rounded to single values. This feels bit of a hack though, and I'm wondering if there's a way to implement this &quot;properly&quot;?&lt;/p&gt;&#xA;" OwnerUserId="2306" LastEditorUserId="2306" LastEditDate="2017-12-01T16:01:07.417" LastActivityDate="2020-04-13T03:05:41.383" Title="What's a proper way to clamp dither noise?" Tags="&lt;image-processing&gt;&lt;noise&gt;" AnswerCount="3" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5905" PostTypeId="1" CreationDate="2017-11-21T06:01:41.567" Score="8" ViewCount="440" Body="&lt;p&gt;I know that texture caching on GPU works to optimize locality in 2D (or 3D if using 3D textures). I believe this is done using space-filling curves like Morton or Hilbert curves. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When passing an array of texture data to the GPU, though, for example using glTextureSubImage2D, the data is specified in scan-line order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how and when does the conversion take place? I can think of a couple of possibilites:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The texture is laid out linearly in VRAM, and the texture unit&#xA;merges transactions on different areas when loading to cache.&lt;/li&gt;&#xA;&lt;li&gt;The texture gets swizzled when passed to the GPU, and is stored in VRAM in Morton-coded order (or another space-filling curve).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So which is it, or is there another possibility I've missed? If it's option 2, is there an option to pass textures 'verbatim' if you already have a Morton-coded version on CPU-side? Or would you have to de-swizzle it before loading to GPU?&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-11-21T10:30:46.710" Title="Are textures automatically Morton-coded when loaded to VRAM?" Tags="&lt;texture&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5906" PostTypeId="2" ParentId="5905" CreationDate="2017-11-21T09:31:59.037" Score="3" Body="&lt;p&gt;Possibly &quot;all of the above&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've worked with different generations of the same vendor's hardware which have, variously, required software (either the API/driver or the texture tool) to preorder the texture data into a Morton/tiled layout, and others which, I think, had more &quot;built-in&quot; processing.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-11-21T09:31:59.037" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5907" PostTypeId="2" ParentId="5905" CreationDate="2017-11-21T10:30:46.710" Score="6" Body="&lt;p&gt;In vulkan, like a lot of other implicit operations, this transition is made explicit. Images can be in one of 2 tiling layouts: optimal and linear. Linear images have a fixed layout while optimal is with implementation-defined space-filling curve. (There is no way currently to figure out which exact curve is used).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fill a optimally tiled image you need to copy from another image or from a vkBuffer (which has the data in linear format). The swizzle is done as part of the copy. But with the requirement that the data source must not be changed during the operation. Because other operations are allowed be read from the copy operation's source.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2017-11-21T10:30:46.710" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5910" PostTypeId="1" AcceptedAnswerId="5911" CreationDate="2017-11-21T22:12:59.227" Score="5" ViewCount="1382" Body="&lt;p&gt;Given a polygon (regular or irregular, convex or concave), I want to round its corner, with a given radius; let's say 'x'. I have the code to draw an arc given 2 points, but how can I find the start and end points of the arc?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All I have is a list of points representing each corner of the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a simple example: I have a list of vertices of corners of the figure (1). &#xA;The figure (2) is what I need so I could draw the arcs to round the corners.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I'm developing a CAD drawing generator using .netdxf API (&lt;a href=&quot;https://github.com/haplokuon/netDxf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/haplokuon/netDxf&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jeu7d.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jeu7d.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7412" LastEditorUserId="209" LastEditDate="2017-11-23T16:05:27.430" LastActivityDate="2017-11-24T12:42:05.647" Title="Rounding corners of polygon given vertices of its corners" Tags="&lt;polygon&gt;&lt;2d-graphics&gt;&lt;cad&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5911" PostTypeId="2" ParentId="5910" CreationDate="2017-11-21T23:54:37.403" Score="1" Body="&lt;p&gt;Since you're working on CAD software, you probably want some precise results. Here an algorithm that could work:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each side:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Compute the segment's equation.&lt;/li&gt;&#xA;&lt;li&gt;Compute each round corner's circle equation.&lt;/li&gt;&#xA;&lt;li&gt;Compute the intersections between the segment and each circle.&lt;/li&gt;&#xA;&lt;li&gt;The 2 intersection points are the new endpoints for the line segment.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This doesn't handle the case where a side is smaller than the rounded corner radius. You could reduce the rounded corner's radius in this case based on the segment's length.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2017-11-21T23:54:37.403" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5912" PostTypeId="1" AcceptedAnswerId="5913" CreationDate="2017-11-22T12:38:05.463" Score="2" ViewCount="2131" Body="&lt;p&gt;I want to decompose projection matrices into &lt;strong&gt;near&lt;/strong&gt;, &lt;strong&gt;far&lt;/strong&gt;, &lt;strong&gt;top&lt;/strong&gt;, &lt;strong&gt;bottom&lt;/strong&gt;, &lt;strong&gt;left&lt;/strong&gt; and &lt;strong&gt;right&lt;/strong&gt; values to create a bounding box for view frustum. I used the formula described in  this site &lt;a href=&quot;http://lektiondestages.blogspot.com.tr/2013/11/decompose-opengl-projection-matrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Decompose the OpenGL projection matrix&lt;/a&gt;. This formula works for perspective which is created with frustum function (&lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;glFrustum&lt;/a&gt;). But it does not work for perspective which is created via perspective func (&lt;a href=&quot;http://lektiondestages.blogspot.com.tr/2013/11/decompose-opengl-projection-matrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;gluPerspective&lt;/a&gt;) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Frustum and perspective may create same perspective effect but generated matrices seems different. So it seems I can't use single formula to extract perspective parameters. &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there any proof of that decomposition formula, or does it always work? &lt;/li&gt;&#xA;&lt;li&gt;How do I decompose the matrix generated by perspective function into &lt;strong&gt;near&lt;/strong&gt;, &lt;strong&gt;far&lt;/strong&gt;, &lt;strong&gt;top&lt;/strong&gt;, &lt;strong&gt;bottom&lt;/strong&gt;, &lt;strong&gt;left&lt;/strong&gt; and &lt;strong&gt;right&lt;/strong&gt; values? Is there any formula which is already used in industry?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;My implementations of ortho, frustum and perspetive is here: &lt;a href=&quot;https://github.com/recp/cglm/blob/master/include/cglm/cam.h&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/recp/cglm/blob/master/include/cglm/cam.h&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6929" LastActivityDate="2017-11-22T13:36:12.673" Title="How to decompose projection matrix?" Tags="&lt;matrix&gt;&lt;projections&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5913" PostTypeId="2" ParentId="5912" CreationDate="2017-11-22T12:50:26.863" Score="0" Body="&lt;p&gt;Do you have any &quot;input data&quot; from which you constructed the matrix (like fov, near plane distance, etc.)? Or is the matrix itself &lt;em&gt;the only&lt;/em&gt; data you have?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;Ok, so if you want to know the size of the near plane while you have viewProj matrix available do this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;a)&lt;/strong&gt; compute viewProj^-1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;b)&lt;/strong&gt; vertices of the near plane in clip-space have coordinates (in OpenGL):&#xA;(-1, -1, -1, 1)&#xA;(-1,  1, -1, 1)&#xA;( 1, -1, -1, 1)&#xA;( 1,  1, -1, 1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and on the far plane:&#xA;(-1, -1, 1, 1)&#xA;(-1,  1, 1, 1)&#xA;( 1, -1, 1, 1)&#xA;( 1,  1, 1, 1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's a unit cube spanning (-1, -1, -1) and (1, 1, 1) coordinates with w=1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;c)&lt;/strong&gt; take each of those vertices, mutiply by viewProj^-1 and finally divide all resulting components by the w-component. That gives you the frustum's vertices in world space. From this you can easily find world space planes constraining the view frustum or the bounding box or whatever you like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think it's not possible to extract left/right/bottom/top/near/far from the matrix directly. But since you can compute the world space coordinates of frustum's corners (as shown above) you can easily find left/right/bottom/top/near/far.&lt;/p&gt;&#xA;" OwnerUserId="7725" LastEditorUserId="7725" LastEditDate="2017-11-22T13:36:12.673" LastActivityDate="2017-11-22T13:36:12.673" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5915" PostTypeId="1" CreationDate="2017-11-23T01:17:21.210" Score="1" ViewCount="104" Body="&lt;p&gt;I am interested in simulating water movement like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1:45 to 3:05 of &lt;a href=&quot;https://www.youtube.com/watch?v=sbrFIp73tbw&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=sbrFIp73tbw&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have learnt a lot of computer graphics so far, for example:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Interactive Computer Graphics: A Top-Down Approach with Shader-Based&#xA;OpenGL, 6th Edition, by Edward Angel and Dave Shreiner&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Fluid Simulation for Computer Graphics, 2nd Edition, by Robert&#xA;Bridson&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;, as well as other math books on e.g. linear algebra and numerical PDE solvers. They are all good books and I learnt lots of foundations of computer graphics from them, but it seems that they are too basic to be useful. So far, I still have no idea how to implement the video clip mentioned above. I know I still have a lot to learn and need to continue to invest vast time and efforts, but I hope my time and efforts devoted are not deviating from what I am aiming at. So, in order for me to implement the above water simulation, what is the shortest but sufficient study path, that is, what books and/or papers I need to read? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A side note: the video implemented bubbles, but after splashing onto the wall, some water blobs should stick on the wall and flow down slowly, assuming the wall is plastic. This was not implemented. I want to make that effects myself too. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you for pointing me a correct direction.&lt;/p&gt;&#xA;" OwnerUserId="4839" LastActivityDate="2017-11-23T01:17:21.210" Title="Ask for a study path to simulate water like this" Tags="&lt;simulation&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5916" PostTypeId="2" ParentId="5910" CreationDate="2017-11-23T02:31:47.267" Score="1" Body="&lt;p&gt;The cut length from the vertex is x*ctan(t/2), where t is the angle at this vertex.&lt;/p&gt;&#xA;" OwnerUserId="5748" LastActivityDate="2017-11-23T02:31:47.267" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5917" PostTypeId="2" ParentId="2343" CreationDate="2017-11-23T09:12:09.580" Score="2" Body="&lt;p&gt;You could try &lt;a href=&quot;https://en.wikipedia.org/wiki/Natural_neighbor_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;natural neighbour interpolation&lt;/a&gt; or Sibson coordinates for this. These coordinates are based on a Voronoi tessellation of the points.&#xA;The coordinates have been extended to an approach where the points lie on some surface in &lt;a href=&quot;https://ac.els-cdn.com/S0925772101000189/1-s2.0-S0925772101000189-main.pdf?_tid=160000a8-d02d-11e7-99c0-00000aab0f27&amp;amp;acdnat=1511427960_98dcfd5f9afa172805cda3bdc267f6ab&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; publication.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2017-11-24T15:09:23.990" LastActivityDate="2017-11-24T15:09:23.990" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5918" PostTypeId="2" ParentId="5910" CreationDate="2017-11-23T09:27:54.870" Score="6" Body="&lt;p&gt;Ok, Xenapior and Reynolds together have the right idea. But the explanation is a bit lacking so here is a image to explain it all and some further musings. First let us  start by drawing an image (yes i know that is what they say in school for you to do but nobody does it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/g55pU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g55pU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the image we can see that there are 2 equal right triangles $V_2, A, C$ and $V_1, B, C$. In this triangle we have one unknown that we can define namely rounding radius $r$, also we know right angle is 90&amp;deg;. The angle between the line $V_1-V_2 = \vec a$ and line $V_2-V_3 = \vec b$ is easy to compute with  the formulation fo angle between vectors&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\cos(\beta) = \frac{\vec a·\vec b}{ |\vec a|·|\vec b|}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That in turn can be simplified if the vectors already are normal. Thus three things of the triangle is known, which means all is known. So if you know the rounding radius to use the calculating the points $A$, $B$ and $C$. So finally:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;a = normalize(V2-V1);&#xA;b = normalize(V2-V3);&#xA;halfang = acos(dot(a, b))/2.;&#xA;// skip center if you iuse splines&#xA;C = V2 - r / sin(halfang) * normalize((a+b)/2);&#xA;A = V2 - r/tan(halfang)*a;&#xA;B = V2 - r/tan(halfang)*b;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can simplify this a bit with trigonometric identities. Or if you use rational B-splines you can skip the calculation of C&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: that this is only one possible formulation&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2017-11-24T12:42:05.647" LastActivityDate="2017-11-24T12:42:05.647" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5919" PostTypeId="1" AcceptedAnswerId="5921" CreationDate="2017-11-25T01:54:49.893" Score="0" ViewCount="63" Body="&lt;p&gt;I am trying to study the texture deformations caused when mapping a rectangle to a sphere, if I had a software that took an image as an input and displayed how it looks like when texture mapped to a sphere, it would allow me to observe and study this deformations better.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2017-11-25T10:25:25.337" Title="Is there any free software to visualize a texture mapped to a sphere?" Tags="&lt;texture&gt;&lt;mathematics&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="2" ClosedDate="2017-12-01T19:58:01.790" ContentLicense="CC BY-SA 3.0" />
  <row Id="5921" PostTypeId="2" ParentId="5919" CreationDate="2017-11-25T10:25:25.337" Score="1" Body="&lt;p&gt;Although this is borderline &quot;off-topic&quot; for the site, there is perhaps a simple answer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why not use a webgl approach such as this one?&#xA;&lt;a href=&quot;http://learningwebgl.com/lessons/lesson11/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://learningwebgl.com/lessons/lesson11/index.html&lt;/a&gt;&#xA;(parent page here: &lt;a href=&quot;http://learningwebgl.com/blog/?p=1253&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://learningwebgl.com/blog/?p=1253&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just rotate the image of the moon around until you have one of the poles visible and you'll see the typical artefacts you get with mapping a rectangle to a sphere.&#xA;Though I've not tried, you could &lt;em&gt;probably&lt;/em&gt; modify the code (use, say, &quot;view page source&quot; to read it, or save a local copy and edit) to load whatever texture your heart desired.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-11-25T10:25:25.337" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5922" PostTypeId="1" AcceptedAnswerId="5924" CreationDate="2017-11-25T11:47:14.857" Score="5" ViewCount="1282" Body="&lt;p&gt;Is there any reason why OpenGL performs primitives' clipping in clip coordinates? Can it be at least theoretically done in normalized device coordinates?&lt;/p&gt;&#xA;" OwnerUserId="7737" LastActivityDate="2017-11-26T16:30:41.583" Title="Why does opengl perform clipping in clip coordinates?" Tags="&lt;opengl&gt;&lt;clipping&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5923" PostTypeId="2" ParentId="5922" CreationDate="2017-11-25T18:09:36.357" Score="1" Body="&lt;p&gt;Clipping could be done in normalised device coordinates as all primitives with z-coordinates outside -1 to 1 are outside the clipping planes. However, there is no reason not to do it in clip coordinates by considering z-coordinates from -w to w.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Theoretically it possible. However it seems there is performance increase when doing the clipping in clip coordinates. By first comparing z-coordinates before perspective division it saves time by not computing perspective division for the clipped primitives. This means less division operations. This favourable as floating point division can take a few processing cycles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Refer also to the answer in &lt;a href=&quot;https://gamedev.stackexchange.com/questions/65789/why-is-clip-space-always-referred-to-as-homogeneous-clip-space&quot;&gt;this&lt;/a&gt; related question&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2017-11-26T11:33:36.287" LastActivityDate="2017-11-26T11:33:36.287" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5924" PostTypeId="2" ParentId="5922" CreationDate="2017-11-25T20:17:32.463" Score="8" Body="&lt;p&gt;The space after clip space is normalized device coordinate space, which is obtained by dividing &lt;code&gt;clip.xyz&lt;/code&gt; by &lt;code&gt;clip.w&lt;/code&gt;. If W is zero... oops.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Oh sure, you could put a conditional test to see if W is zero or very close to zero. Or you can just do the clipping math in clip space and never have to worry about it. No post-clipping vertex can have a W of zero, because the clip box for each vertex is based on being in the &lt;em&gt;closed&lt;/em&gt; range (-W, W). And if W is 0, then the closed range is an empty set, and thus the vertex is not on that range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, negative values of W are outside of the clipping space. The closed range (-W, W) is inverted where W is negative, but the meaning of the range itself is not. Consider a W of -1; the range becomes (1, -1). There are no numbers that are simultaneously greater than 1 and less than -1. Therefore that space is &lt;em&gt;empty&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And yet, division by a negative W can still land NDC points in the [-1, 1] NDC-space range, where they will not be clipped if you didn't clip them beforehand.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2017-11-26T16:30:41.583" LastActivityDate="2017-11-26T16:30:41.583" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="5925" PostTypeId="1" CreationDate="2017-11-26T04:26:42.733" Score="2" ViewCount="191" Body="&lt;p&gt;A scene can be pre-rendered from a single camera position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can a scene be efficiently rendered for a fixed set of positions and lines that the camera can move through?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider games like escape room games where the camera only assumes fixed locations. Can the transition between those positions also be rendered more efficiently than frame-by-frame?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose I wanted the player to move freely along a fixed linear (or curved) track, how can I show the maximum render quality?&lt;/p&gt;&#xA;" OwnerUserId="7743" LastActivityDate="2018-06-26T15:07:15.247" Title="Can a scene be efficiently pre-rendered and displayed along a fixed camera line?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5926" PostTypeId="1" CreationDate="2017-11-26T07:26:38.583" Score="6" ViewCount="430" Body="&lt;p&gt;I'm trying to render water using path tracing. However, since in path tracing, the light sampling is skipped while the intersection point is perfect specular and thus no direct light would be taken into account.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So does that mean &lt;strong&gt;all contributions(radiance) are indirect lighting on specular surfaces&lt;/strong&gt;(i.e. dirac BSDFs), no direct light should be computed for specular sufaces?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say, I have a scene with environment map(infinite sphere) and a water object, represented by a triangle mesh. If the max bounce parameter is set to &lt;strong&gt;1&lt;/strong&gt;, then the water surface would not be lit at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if the max bounce parameter is set to 2, all contributions are from rays reflected and &quot;hit the environment map&quot;. For those reflected rays still hit the water surface, there would be no radiance on that ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The consequence would be for some region on the water appears to be very dark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wonder if my understanding is right, and if not, how do I fix it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my demo for one bounce, two bounces and 20 bounces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1 bounce&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WooiS.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WooiS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2 bounces&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qLU3b.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qLU3b.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;20 bounces&lt;/strong&gt;&#xA;I think the color in the red box is incorrect, it should be brighter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uUIcG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uUIcG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7334" LastActivityDate="2018-01-17T21:59:33.597" Title="How does path tracing handle specular surfaces(Dirac BSDFs) such as water?" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5929" PostTypeId="2" ParentId="4760" CreationDate="2017-11-28T10:42:09.517" Score="1" Body="&lt;p&gt;You could calculate the midpoints of the segments between the vertices (atoms) of the icosahedron. These are the positions of the cylinders. You would then need to determine the orientation and scale of the cylinders. This information should then be encoded into a transformation matrix. Doing this for every cylinder would mean multiple transformation matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An effective way to draw many copies of the same object is to use instanced drawing. Instead of defining the position of the vertices of each cylinder separately, you only define the geometry for one cylinder and send this to a buffer. You can then draw a number of copies of this cylinder and transforming each copy of this cylinder with its respective transformation matrix. The matrices should be put into a buffer on the GPU to make it efficient. Alternatively, it is possible to do it with uniforms but this would mean multiple draw calls and no instancing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A couple of things you would need to look up documentation for is &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glDrawElementsInstanced.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;instanced drawing&lt;/a&gt;. Next, would be to investigate &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribDivisor.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;attribute divisors&lt;/a&gt;. Attribute divisors regulate the rate for which vertex attributes are read from the buffer. If you upload the transformation matrices for each cylinder with 40 vertices to the buffer. You would want to have one transformation matrix for each batch of 40 vertices. Therefore, the attribute divisor for the transformation matrix should be set to 1, such that it advances once per batch of vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using this approach it is best to define you cylinder as an axis aligned unit length and width cylinder centered at the origin. This will simplify the transformations a whole lot.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2017-11-28T12:20:27.940" LastActivityDate="2017-11-28T12:20:27.940" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5930" PostTypeId="2" ParentId="5925" CreationDate="2017-11-28T11:08:29.487" Score="1" Body="&lt;p&gt;Would Diego Nehab et al's &quot;Accelerating Real-Time Shading with Reverse Reprojection Caching&quot; be the sort of thing you are looking for? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://gfx.cs.princeton.edu/pubs/Nehab_2007_ARS/NehEtAl07.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Paper Link&lt;/a&gt; and/or &lt;a href=&quot;http://www.graphicshardware.org/previous/www_2007/presentations/nehab-reprojection-gh07.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Slide presentation from Graphics Hardware 2007&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IIRC, the idea is to reuse a previous frame's rendered image results in the current frame rather than running a, potentially expensive, shader for every pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the conference, I did ask Diego if he'd considered doing 'bidirectional' reuse (i.e. rendering frames out of order somewhat akin to h.264) but I can't recall his answer. I think in your proposed use case it might be of value.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-11-28T11:08:29.487" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5931" PostTypeId="1" AcceptedAnswerId="5932" CreationDate="2017-11-28T15:59:05.893" Score="5" ViewCount="76" Body="&lt;p&gt;Stencil bits are often used for optimizations, for instance having full screen lighting passes only affect certain pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does the stencil test mechanism use any acceleration structures of any kind (like maybe dividing the screen into a coarser grid?) or do the perf benefits come solely from having a pre-pixel shader test that can early out waves of shaders?&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2017-11-28T19:06:32.767" Title="Do stencil tests use any acceleration techniques?" Tags="&lt;optimisation&gt;&lt;stencil-test&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5932" PostTypeId="2" ParentId="5931" CreationDate="2017-11-28T19:06:32.767" Score="4" Body="&lt;p&gt;I don't have a definite authoritive answer for you but I'm very confident that the answer is &amp;quot;yes&amp;quot;. Here's why:&lt;/p&gt;&#xA;&lt;p&gt;When using framebuffer objects, &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Format#Depth_stencil_formats&quot; rel=&quot;nofollow noreferrer&quot;&gt;stencil attachments are usually combined&lt;/a&gt; with the depth attachment in a single texture (&lt;code&gt;GL_DEPTH24_STENCIL8&lt;/code&gt; or &lt;code&gt;GL_DEPTH32F_STENCIL8&lt;/code&gt;). In fact, until recently, a combined depth and stencil was the only way to get a stencil buffer. It is now possible to create a stencil only attachment for an FBO.&lt;/p&gt;&#xA;&lt;p&gt;This &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Framebuffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL wiki article on FBOs&lt;/a&gt; states (emphasis mine):&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;These color formats can be combined with a depth attachment with any of the required depth formats. Stencil attachments can also be used, again with the required stencil formats, as well as the combined depth/stencil formats. However, &lt;strong&gt;implementations are only required to support both a depth and stencil attachment simultaneously if both attachments refer to the same image&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This means that if you want stencil with no depth, you can use one of the required stencil formats. If you want depth with no stencil, you can use one of the required depth formats. &lt;strong&gt;But if you want depth and stencil, you must use a depth/stencil format and the same image in that texture must be attached to both the depth and stencil attachments&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;All this strongly hints towards an accelerated storage format for stencils similar to the one used by depth buffers.&lt;/p&gt;&#xA;&lt;p&gt;Also, empirically, over the years many rendering algorithms (e.g. stencil shadows) using the stencil buffer would have been prohibitively slow if stencil buffers did not use some form of accelerated structure.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/NV/NV_packed_depth_stencil.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;NV_packed_depth_stencil extension&lt;/a&gt; (2001) spec also provides interesting insight:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Many OpenGL implementations have chosen to interleave the depth and stencil buffers into one buffer, often with 24 bits of depth precision and 8 bits of stencil data.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;and (emphasis mine)&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Should the depth/stencil format support other standard types, like GL_FLOAT or GL_UNSIGNED_INT?&lt;/p&gt;&#xA;&lt;p&gt;RESOLVED: No, this extension is designed to be minimalist. Supporting more types gains little because the new types will just require data format conversions.  &lt;strong&gt;Our goal is to match the native format of the buffer&lt;/strong&gt;, not add broad new classes of functionality.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="7644" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2017-11-28T19:06:32.767" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5933" PostTypeId="1" AcceptedAnswerId="6279" CreationDate="2017-11-30T00:58:48.183" Score="6" ViewCount="156" Body="&lt;p&gt;I am having my first encounter with the rendering of indirect reflections in the form of screen space reflections in a game engine, but i am struggling to get correct looking results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/E9xzy.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/E9xzy.png&quot; alt=&quot;taken at low resolution and ray count&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(patterns arise from a bad way of generating noise for montecarlo integration)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(image taken at low ray count. otherwise the color values end up going to NaN)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what i've gathered, a common formulation of the rendering equation is as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o(p,\omega_o)=L_e(p,\omega_o)+\int_{\Omega}L_i(p,\omega_i)fr(\omega_i,\omega_o)(n\cdot\omega_i)d\omega_i$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which, dropping the $L_e(p,\omega_o)$ term, can be approximated using the following monte carlo estimator:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N}\frac{L_i(p,\omega_i)fr(\omega_i,\omega_o)(n\cdot\omega_i)}{p(\omega_i)}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $n$ is a unit vector perpendicular to the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for actual computation of values, all of these terms must be specified.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_i(p,\omega_i)$ is found through raymarching in screen space&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$fr(\omega_i,\omega_o)$ is the Cook-Torrance BRDF:$\frac{FGD}{4(n\cdot\omega_i)(n\cdot\omega_o)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;if we name the angle between $n$ and $m$ $\theta$, we get that the GGX NDF is:$D=\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $m$ is the microfacet normal $m=\frac{\omega_i+\omega_o}{|\omega_i+\omega_o|}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$p(\omega_i)$ Is the PDF that can be derived from the GGX NDF $\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When put all together we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N} \frac{L_i(p,\omega_i)\frac{FG}{4(n\cdot\omega_i)(n\cdot\omega_o)}\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}(n\cdot\omega_i)}{\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After simplifying, we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N} \frac{L_i(p,\omega_i)FG}{4(n\cdot\omega_o)\cos(\theta)\sin(\theta)}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This procedure seems correct to me but the images produced by my implementation have over exposed reflections at sharp incidence angles or at low roughness values. However, when i remove the $\sin(\theta)$ factor from the denominator it looks plausible (not sure about correctness though).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eZnaa.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eZnaa.png&quot; alt=&quot;taken at low resolution with no denoise solution&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-15T04:44:21.353" Title="fix over exposure in importance sampling in screen space reflections" Tags="&lt;rendering&gt;&lt;brdf&gt;&lt;real-time&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5934" PostTypeId="1" AcceptedAnswerId="5940" CreationDate="2017-11-30T06:06:47.610" Score="6" ViewCount="1546" Body="&lt;p&gt;These days anti-aliasing uses gray scale pixel values on displays with high pixel counts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to take a step back in time and learn what is available for anti-aliasting or at least improving the quality of curved lines and fonts drawn on bindary (on/off) 1-bit displays, such as these low cost OLED displays shown below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know if the procedure would be called anti-aliasing, or something else. Ideally an explanation or a link/reference to a mathematical procedure or algorithm would be most helpful, or if something exists in Python, that would be great as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PIL, the Python Image Library is wonderful but I have a hunch it is mostly useful for gray scale or RGB continuous tone images rather than binary 1-bit images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See for example the question &lt;a href=&quot;https://stackoverflow.com/q/47545359/3904031&quot;&gt;Drawing multilingual text using PIL and saving as 1-bit and 8-bit bitmaps&lt;/a&gt;, where PIL turned this gray scale image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/otMYr.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/otMYr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;into this 1-bit binary image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ov0i3.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ov0i3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and similar things would happen if I drew circles in PIL and then converted to 1-bit. The antialiasing is designed for continuous tone display, and so the subsequent thresholding just makes a mess.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Example of a 1-bit binary OLED display (128x64 pixels) cropped from &lt;a href=&quot;https://cdn-shop.adafruit.com/1200x900/326-18.jpg&quot; rel=&quot;noreferrer&quot;&gt;this image&lt;/a&gt; from the AdaFruit Page &lt;a href=&quot;https://www.adafruit.com/product/326&quot; rel=&quot;noreferrer&quot;&gt;Monochrome 0.96&quot; 128x64 OLED graphic display, Product ID: 326&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/THcMR.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/THcMR.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5846" LastEditorUserId="5846" LastEditDate="2017-11-30T06:14:45.877" LastActivityDate="2017-12-01T04:28:05.280" Title="Algorithms to &quot;anti-alias&quot; (or somehow improve) binary 1-bit drawings and fonts" Tags="&lt;antialiasing&gt;&lt;bitmap-graphics&gt;" AnswerCount="4" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5935" PostTypeId="2" ParentId="5934" CreationDate="2017-11-30T06:34:02.233" Score="2" Body="&lt;p&gt;In the olden days, for things like fonts, they didn't do antialiasing. They generally hand made bitmap fonts because it generated the clearest, easiest-to-read results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, you could look into &lt;a href=&quot;https://en.wikipedia.org/wiki/Error_diffusion&quot; rel=&quot;nofollow noreferrer&quot;&gt;error diffusion&lt;/a&gt;, &lt;a href=&quot;https://en.wikipedia.org/wiki/Halftone&quot; rel=&quot;nofollow noreferrer&quot;&gt;halftoning&lt;/a&gt; or other &lt;a href=&quot;https://en.wikipedia.org/wiki/Dither&quot; rel=&quot;nofollow noreferrer&quot;&gt;dithering&lt;/a&gt; techniques for changing continuous-tone images into 1-bit images. These are techniques for reducing the bit depth of images.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-11-30T06:34:02.233" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5936" PostTypeId="1" CreationDate="2017-11-30T16:08:24.900" Score="0" ViewCount="831" Body="&lt;p&gt;This one I am not getting even one bit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I started learning directx11 and using the basic dx initialization i tried a experiment by allowing an option to destroy the window and creating it again initializing direct x again(any key press triggers it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but i observe during debugging(also by opening task manager) that memory occupied by dx com objects are not getting released,memory keeps adding up as a new window is created.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include&quot;windowcreation.h&quot;&#xA;&#xA;#pragma comment(lib, &quot;d3d11.lib&quot;)&#xA;#pragma comment(lib, &quot;d3d10.lib&quot;)&#xA;#pragma comment(lib,&quot;D3dcompiler.lib&quot;)&#xA;&#xA;#include&amp;lt;d3d11_1.h&amp;gt;&#xA;#include&amp;lt;d3d10.h&amp;gt;&#xA;#include &amp;lt;D3Dcompiler.h&amp;gt; &#xA;#include&amp;lt;DirectXMath.h&amp;gt;&#xA;#include&amp;lt;DirectXColors.h&amp;gt;&#xA;&#xA;&#xA;#include&amp;lt;stdio.h&amp;gt;&#xA;#include &amp;lt;io.h&amp;gt;&#xA;#include &amp;lt;fcntl.h&amp;gt;&#xA;#include&amp;lt;iostream&amp;gt;&#xA;#include&amp;lt;fstream&amp;gt;&#xA;&#xA;&#xA;&#xA;bool openglinuse = false;&#xA;bool switchRenderDrivers = false;&#xA;bool switchrendercomsumequitmessage = false;&#xA;bool running = true;&#xA;&#xA;//--------------------------------------------DX Globals--------------------------------------------&#xA;DXWindow window(1920, 1080, &quot;dxandgl&quot;);&#xA;&#xA;//dx data&#xA;struct dxData&#xA;{&#xA;    IDXGISwapChain* SwapChain;&#xA;    ID3D11Device* d3d11Device;&#xA;    ID3D11DeviceContext* d3d11DevCon;&#xA;    ID3D11RenderTargetView* renderTargetView;&#xA;};&#xA;&#xA;dxData* dxessentials;&#xA;&#xA;&#xA;std::ofstream fileone(&quot;logs.txt&quot;);&#xA;&#xA;&#xA;&#xA;//---------------------------------------------functions------------------------------------------------&#xA;bool initdirectx(HINSTANCE hinst);&#xA;bool init();&#xA;void render();&#xA;void update(double);&#xA;void destroy();&#xA;int messageloop(HINSTANCE);&#xA;&#xA;bool initdirectx(HINSTANCE hinst)&#xA;{&#xA;    HRESULT hr;&#xA;&#xA;    dxessentials = new dxData();&#xA;&#xA;    //Describe our Buffer&#xA;    DXGI_MODE_DESC bufferDesc;&#xA;&#xA;    ZeroMemory(&amp;amp;bufferDesc, sizeof(DXGI_MODE_DESC));&#xA;&#xA;    bufferDesc.Width = window.getWidth();&#xA;    bufferDesc.Height = window.getHeight();&#xA;    bufferDesc.RefreshRate.Numerator = 60;&#xA;    bufferDesc.RefreshRate.Denominator = 1;&#xA;    bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;    bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;&#xA;    bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;&#xA;&#xA;    //Describe our SwapChain&#xA;    DXGI_SWAP_CHAIN_DESC swapChainDesc;&#xA;&#xA;    ZeroMemory(&amp;amp;swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));&#xA;&#xA;    swapChainDesc.BufferDesc = bufferDesc;&#xA;    swapChainDesc.SampleDesc.Count = 1;&#xA;    swapChainDesc.SampleDesc.Quality = 0;&#xA;    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;&#xA;    swapChainDesc.BufferCount = 2;&#xA;    swapChainDesc.OutputWindow = window.getWindowHandle();&#xA;    swapChainDesc.Windowed = TRUE;&#xA;    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;&#xA;&#xA;&#xA;    //Create our SwapChain&#xA;    hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &amp;amp;swapChainDesc, &amp;amp;(dxessentials-&amp;gt;SwapChain), &amp;amp;(dxessentials-&amp;gt;d3d11Device), NULL, &amp;amp;(dxessentials-&amp;gt;d3d11DevCon));&#xA;&#xA;    //Create our BackBuffer&#xA;    ID3D11Texture2D* BackBuffer;&#xA;    hr = dxessentials-&amp;gt;SwapChain-&amp;gt;GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&amp;amp;BackBuffer);&#xA;&#xA;    //Create our Render Target&#xA;    hr = dxessentials-&amp;gt;d3d11Device-&amp;gt;CreateRenderTargetView(BackBuffer, NULL, &amp;amp;(dxessentials-&amp;gt;renderTargetView));&#xA;    BackBuffer-&amp;gt;Release();&#xA;&#xA;    //Set our Render Target&#xA;    dxessentials-&amp;gt;d3d11DevCon-&amp;gt;OMSetRenderTargets(1, &amp;amp;(dxessentials-&amp;gt;renderTargetView), NULL);&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;int messageloop(HINSTANCE hinst)&#xA;{&#xA;    MSG message;&#xA;    ZeroMemory(&amp;amp;message, sizeof(MSG));&#xA;&#xA;    while (true)&#xA;    {&#xA;        if (PeekMessage(&amp;amp;message, NULL, 0, 0, PM_REMOVE))&#xA;        {&#xA;            if (message.message == WM_QUIT)&#xA;                break;&#xA;            TranslateMessage(&amp;amp;message);&#xA;            DispatchMessage(&amp;amp;message);&#xA;        }&#xA;        else&#xA;        {&#xA;            update(0.0);&#xA;            render();&#xA;        }&#xA;    }&#xA;&#xA;    return (int)message.wParam;&#xA;}&#xA;&#xA;&#xA;bool init()&#xA;{&#xA;&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;&#xA;void update(double delta)&#xA;{&#xA;&#xA;&#xA;}&#xA;&#xA;void render()&#xA;{&#xA;    //Clear our backbuffer to the updated color&#xA;    const float bgColor[] = { 0.0,0.0,0.0, 1.0f };&#xA;&#xA;    dxessentials-&amp;gt;d3d11DevCon-&amp;gt;ClearRenderTargetView(dxessentials-&amp;gt;renderTargetView, bgColor);&#xA;&#xA;    dxessentials-&amp;gt;SwapChain-&amp;gt;Present(0, 0);&#xA;}&#xA;&#xA;void destroy()&#xA;{&#xA;    dxessentials-&amp;gt;d3d11DevCon-&amp;gt;OMSetRenderTargets(0,NULL, NULL);&#xA;    dxessentials-&amp;gt;d3d11DevCon-&amp;gt;Flush();&#xA;    fileone &amp;lt;&amp;lt; '\n' &amp;lt;&amp;lt; dxessentials-&amp;gt;renderTargetView-&amp;gt;Release();&#xA;    fileone &amp;lt;&amp;lt; '\n' &amp;lt;&amp;lt; dxessentials-&amp;gt;d3d11DevCon-&amp;gt;Release();&#xA;    fileone &amp;lt;&amp;lt; '\n' &amp;lt;&amp;lt; dxessentials-&amp;gt;SwapChain-&amp;gt;Release();&#xA;    fileone &amp;lt;&amp;lt; '\n' &amp;lt;&amp;lt; dxessentials-&amp;gt;d3d11Device-&amp;gt;Release();&#xA;&#xA;    delete dxessentials;&#xA;    dxessentials = nullptr;&#xA;}&#xA;&#xA;&#xA;int WINAPI WinMain(HINSTANCE hinst, HINSTANCE previnst, LPSTR cmdparams, int showcmd)&#xA;{&#xA;    window.registerWindow(hinst);&#xA;&#xA;    while(running)&#xA;    {&#xA;        //DX code&#xA;&#xA;            fileone &amp;lt;&amp;lt; &quot;DX \n&quot;;&#xA;            fileone.flush();&#xA;            if (!window.initializeWindow(hinst, showcmd, true, &quot;DX101&quot;))&#xA;            {&#xA;                MessageBox(0, &quot;Window Initialization - Failed&quot;, &quot;Error&quot;, MB_OK);&#xA;                return 0;&#xA;            }&#xA;&#xA;            if (!initdirectx(hinst))&#xA;            {&#xA;                MessageBox(0, &quot;direct x Initialization - Failed&quot;, &quot;Error&quot;, MB_OK);&#xA;                return 0;&#xA;            }&#xA;&#xA;&#xA;            if (!init())&#xA;            {&#xA;                MessageBox(0, &quot;Scene Initialization - Failed&quot;, &quot;Error&quot;, MB_OK);&#xA;                return 0;&#xA;            }&#xA;&#xA;&#xA;        messageloop(hinst);&#xA;        destroy();&#xA;&#xA;    }&#xA;&#xA;&#xA;    fileone &amp;lt;&amp;lt; &quot;\nGoing out\n&quot;;&#xA;    fileone.flush();&#xA;    fileone.close();&#xA;&#xA;    return 0;&#xA;&#xA;&#xA;}&#xA;&#xA;&#xA;&#xA;LRESULT CALLBACK windowprocedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)&#xA;{&#xA;    switch (msg)    //Check message&#xA;    {&#xA;&#xA;    case WM_KEYDOWN:    //For a key down&#xA;                        //if escape key was pressed, display popup box&#xA;        if (wParam == VK_ESCAPE) {&#xA;            if (MessageBox(0, &quot;Are you sure you want to exit?&quot;,&#xA;                &quot;Really?&quot;, MB_YESNO | MB_ICONQUESTION) == IDYES)&#xA;&#xA;                //Release the windows allocated memory  &#xA;                DestroyWindow(hwnd);&#xA;        }&#xA;        else&#xA;        {&#xA;            switchrendercomsumequitmessage = true;&#xA;            DestroyWindow(hwnd);&#xA;        }&#xA;        return 0;&#xA;&#xA;    case WM_SIZE:&#xA;        return 0;&#xA;&#xA;    case WM_NCDESTROY:    //if x button in top right was pressed&#xA;        if (switchrendercomsumequitmessage)&#xA;            switchrendercomsumequitmessage = false;&#xA;        else&#xA;            running = false;&#xA;&#xA;        PostQuitMessage(0);&#xA;        return 0;&#xA;    }&#xA;    //return the message for windows to handle it&#xA;    return DefWindowProc(hwnd,&#xA;        msg,&#xA;        wParam,&#xA;        lParam);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I tried the following-&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;tried doing the same with out dx initialization and it was fine no memory leak.So I guess problem is with dx coms.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I am sure i am releasing the coms as the output log shows zero references for each object i release.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So could any one explain me what is going wrong and how the memory is leaking.&#xA;Also a possible fix if any.&lt;/p&gt;&#xA;" OwnerUserId="6064" LastActivityDate="2017-11-30T16:08:24.900" Title="How to properly release directx com objects" Tags="&lt;c++&gt;&lt;directx11&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="5937" PostTypeId="2" ParentId="4651" CreationDate="2017-11-30T16:19:44.550" Score="3" Body="&lt;p&gt;I have worked with this specific formula for the OVER operator but not with additive blending. I'll use the paper's nomenclature in the following discussion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ C_f = \frac{\sum_{i=1}^{n}C_i \cdot w(z_i, \alpha_i)}{\sum_{i=1}^{n}\alpha_i \cdot w(z_i, \alpha_i)}(1 - \prod_{i=1}^{n}(1 - \alpha_i)) +  C_0\prod_{i=1}^{n}(1 - \alpha_i) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is not explicitly stated in the paper, but the term $$C_i$$ is the premultiplied-alpha color (i.e. &lt;code&gt;color.rgb * color.a&lt;/code&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As described in the paper, the term&#xA;$$ C_0\prod_{i=1}^{n}(1 - \alpha_i) $$&#xA;provides the &quot;revealage&quot; of the background color. If all the transparent surfaces are transparent, the product will be 1 and the background will be fully visible. The rest of the equation provides an approximation of the result of sorting the transparent surfaces by distance and using the OVER operator with pre-multiplied alpha colors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the equation for additive blending (using &lt;code&gt;glBlendFunc(GL_SRC_ALPHA, GL_ONE)&lt;/code&gt; and &lt;code&gt;glBlendEquation(GL_FUNC_ADD)&lt;/code&gt;) without weights is:&#xA;$$ C_f = \sum_{i=1}^{n}\alpha_iRGB_i + C_0 $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This equation is already order independent! In order to add weights to the transparent surfaces with a normalization step in the end, the equation can then be simplified to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ C_f = \frac{\sum_{i=1}^{n}C_i \cdot w(z_i, \alpha_i)}{\sum_{i=1}^{n}w(z_i, \alpha_i)} +  C_0 $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you'd rather keep the same equation as before, you can achieve the same result by changing the shader outputs in listing 3 to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_FragData[0] = vec4(Ci, 1) * w(zi, ai);&#xA;gl_FragData[1] = vec4(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2017-11-30T16:19:44.550" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5938" PostTypeId="2" ParentId="5934" CreationDate="2017-11-30T16:27:08.630" Score="3" Body="&lt;p&gt;Have a look at &lt;em&gt;Improved Alpha-Tested Magnification for Vector Textures and Special Effects&lt;/em&gt; [Gre07] (&lt;a href=&quot;http://www.valvesoftware.com/publications/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;pdf&lt;/a&gt;). The gist of their method is to store distance field information in the font texture instead of bitmap glyphs. This information is then used to build much higher quality up-scaled versions of the glyphs. They even describe a rendering path without programmable shading that gives ok results.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2017-11-30T16:27:08.630" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5939" PostTypeId="1" AcceptedAnswerId="5982" CreationDate="2017-11-30T19:45:13.610" Score="7" ViewCount="1139" Body="&lt;p&gt;I'm doing some ray tracing on GPU using a fragment shader...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I calculate texture coordinates partial derivatives with respect to screen coordinates so I could perform filtered texture lookup with &lt;code&gt;textureGrad&lt;/code&gt; GLSL function?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I need to use ray differentials?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If yes, then how?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example explaining derivatives calculation for ray-plane intersection (ray described using origin and direction normal vector, plane using one point laying on a plane and normal vector) would be nice, although pointers for general case would also be appreciated...&lt;/p&gt;&#xA;" OwnerUserId="1764" LastActivityDate="2017-12-13T09:31:40.473" Title="Ray tracing - partial derivatives for texture lookup" Tags="&lt;raytracing&gt;&lt;texture&gt;&lt;glsl&gt;&lt;fragment-shader&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5940" PostTypeId="2" ParentId="5934" CreationDate="2017-11-30T21:01:13.407" Score="5" Body="&lt;p&gt;PIL's &lt;a href=&quot;http://pillow.readthedocs.io/en/4.0.x/reference/Image.html#PIL.Image.Image.convert&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;Image.convert&lt;/code&gt;&lt;/a&gt; function performs dithering by default when you convert the image to 1-bit—not simply thresholding. That's what creates the noise along the edges of the shapes; the antialiasing isn't the problem. Unfortunately, at such a low resolution, the dithering does more harm than good.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I grabbed your original image from your other question and did a straight threshold at 128, and it comes out looking a lot better:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/WAlDF.png&quot; alt=&quot;threshold, no dithering&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's probably about as good as you'll be able to do on a low-resolution 1-bit display, absent a bitmap font that's specifically designed for those circumstances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In PIL this operation can be implemented using &lt;a href=&quot;http://pillow.readthedocs.io/en/4.0.x/reference/Image.html#PIL.Image.Image.point&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;Image.point&lt;/code&gt;&lt;/a&gt;, as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;image1Bit = image8Bit.point(lambda x: 0 if x &amp;lt; 128 else 1, mode='1')&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-11-30T21:01:13.407" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5941" PostTypeId="2" ParentId="5934" CreationDate="2017-12-01T04:28:05.280" Score="3" Body="&lt;p&gt;This is just a supplementary answer based on the &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5940/5846&quot;&gt;accepted answer&lt;/a&gt;, using the original 64x128 pixel images instead of the zoomed-in interpolated screen shot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;imtype = &quot;RGB&quot;:&lt;/code&gt; &lt;a href=&quot;https://i.stack.imgur.com/x5BOT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/x5BOT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (true RGB)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;imtype  =  &quot;L&quot;:&lt;/code&gt; &lt;a href=&quot;https://i.stack.imgur.com/IT7Fd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IT7Fd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (grayscale 8-bit)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;imtype  =  &quot;1&quot;:&lt;/code&gt; &lt;a href=&quot;https://i.stack.imgur.com/BYTgZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BYTgZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (binary 1-bit, threshold = 128)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;imtype  =  &quot;1&quot;:&lt;/code&gt; &lt;a href=&quot;https://i.stack.imgur.com/IBTd7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IBTd7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (binary 1-bit, threshold = 80)&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Here are screenshots zoomed-in for those without their glasses:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gdNwt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gdNwt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (screenshot of 1-bit, threshold = 128)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ki3eh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ki3eh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (screenshot of 1-bit, threshold = 80)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;from PIL import Image, ImageDraw, ImageFont&#xA;w_disp   = 128&#xA;h_disp   =  64&#xA;fontsize =  32&#xA;text     =  u&quot;你好!&quot;&#xA;&#xA;imageRGB  = Image.new(&quot;RGB&quot;, (w_disp, h_disp))&#xA;draw      = ImageDraw.Draw(imageRGB)&#xA;font      = ImageFont.truetype(&quot;/Library/Fonts/Arial Unicode.ttf&quot;, fontsize)&#xA;w, h      = draw.textsize(text, font=font)&#xA;&#xA;draw.text(((w_disp - w)/2, (h_disp - h)/2), text, font=font)&#xA;&#xA;imageRGB.save(&quot;NiHao! &quot; + &quot;RGB&quot; + &quot;.bmp&quot;)&#xA;&#xA;image8bit = imageRGB.convert(&quot;L&quot;)&#xA;&#xA;image8bit.save(&quot;NiHao! &quot; + &quot;L&quot; + &quot;.bmp&quot;)&#xA;&#xA;threshold = 80&#xA;image1bit = image8bit.point(lambda x: 0 if x &amp;lt; threshold else 1, mode='1')&#xA;image1bit.save(&quot;NiHao! &quot; + &quot;1&quot; + &quot; threshold = &quot; + str(threshold) + &quot;.bmp&quot;)&#xA;&#xA;threshold = 128&#xA;image1bit = image8bit.point(lambda x: 0 if x &amp;lt; threshold else 1, mode='1')&#xA;image1bit.save(&quot;NiHao! &quot; + &quot;1&quot; + &quot; threshold = &quot; + str(threshold) + &quot;.bmp&quot;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5846" LastActivityDate="2017-12-01T04:28:05.280" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5942" PostTypeId="1" AcceptedAnswerId="5944" CreationDate="2017-12-01T13:44:33.067" Score="6" ViewCount="160" Body="&lt;p&gt;Say I'm generating some texture using perlin noise (or simplex noise, or any similar noise). Then I generate mipmaps to obtain minified versions of that texture...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is if it is possible to directly (and quickly) calculate lower LOD version of said noise at given position, without going through steps of generating high frequency noise first, and then generating mipmaps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What about sums of noises at different frequencies and amplitudes that are often used?&lt;/p&gt;&#xA;" OwnerUserId="1764" LastActivityDate="2017-12-02T01:12:12.893" Title="Is it possible to directly generate mipmap levels of perlin noise?" Tags="&lt;noise&gt;&lt;mipmap&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5943" PostTypeId="2" ParentId="5904" CreationDate="2017-12-01T21:05:27.180" Score="3" Body="&lt;p&gt;I am not sure I can fully answer your question, but I will add some thoughts and maybe we can arrive at an answer together :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, the foundation of the question is a bit unclear to me: Why do you consider it desirable to have clean black/white when every other color has noise? The ideal result after dithering is your original signal with entirely uniform noise. If black and white are different, your noise becomes signal-dependant (which might be fine though, since it happens where colors are clamped anyway).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, there are situations, where having noise in either whites or blacks does pose an issue (I am not aware of usecases that require both black and white to simultaneously be &quot;clean&quot;): When rendering an additively blended particle as a quad with a texture, you do not want noise added in the entire quad, as that would show outside the texture as well. One solution is to offset the noise, so rather than adding [-0.5;1.5[ you add [-2.0;0.0[ (ie subtract 2bits of noise). This is quite an empirical solution, but I am not aware of a more correct approach. Thinking about it, you likely also want to boost your signal to compensate for the lost intensity...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Somewhat related, Timothy Lottes did a GDC talk on shaping noise to the parts of the spectrum where it is most needed, reducing noise in the bright end of the spectrum: &lt;a href=&quot;http://32ipi028l5q82yhj72224m8j-wpengine.netdna-ssl.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://32ipi028l5q82yhj72224m8j-wpengine.netdna-ssl.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2463" LastActivityDate="2017-12-01T21:05:27.180" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5944" PostTypeId="2" ParentId="5942" CreationDate="2017-12-02T00:24:30.547" Score="8" Body="&lt;p&gt;I would say yes with a small asterisk.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When generating a perlin noise texture, using multiple of octaves of noise like you are talking about, the point of adding higher octaves (higher frequency lower amplitude) is to add high frequency details to the noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When making mipmaps of a texture, the point is to remove high frequency content that would cause aliasing at the resolution of that mip map level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, when making a specific mip level of a multiple octave perlin noise texture, you could find out which frequency would cause aliasing, and just use all the octaves up to (but not including) that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result would be that you would have reasonable mips.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, there are some reasons for that small asterisk:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The result you get would not be the same as if you mipped the image that has the highest frequency content.  This might not necessarily be a bad thing, because the usual way to make mips causes some bluring (a blur is a low pass filter) so you wouldn't have the bluring that comes with mips.  However, it's possible that a higher octave happens to add some lower frequency content than you'd expect.  Your lower mips, which could handle this frequency, would have that data missing unfortunately.&lt;/li&gt;&#xA;&lt;li&gt;It might be that your octaves don't perfectly line up with the frequencies that your various mip levels can handle.  For instance, if an octave is just barely higher than nyquist frequency, you are going to miss out on some of the frequency components that the octave gave you.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Because of these two points, it might be more correct to process all octaves for each mip level, but to low pass filter the data for the octaves that are above nyquist.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That would be a lot more expensive than just omiting octaves at a cutoff point though (:&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-12-02T01:12:12.893" LastActivityDate="2017-12-02T01:12:12.893" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5945" PostTypeId="1" AcceptedAnswerId="5946" CreationDate="2017-12-02T20:13:24.450" Score="6" ViewCount="8848" Body="&lt;p&gt;Whenever I make semantic or syntax errors in OpenGL, either I get a black screen or the program crashes. I looked up on internet on how to do error handling in OpenGL and in the documentations I found &lt;code&gt;glGetError()&lt;/code&gt;. To my understanding, &lt;code&gt;glGetError()&lt;/code&gt; will return one or more error code(s) if I call it after calling a &quot;normal&quot; OpenGL function, provided I have made some error. Also I have to call it in while loop to get all the errors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have multiple problems with this. One I can't find the line number on which the error has occurred, second it doesn't tell me properly why the error occurred (not a big problem though) and lastly I have to include a while loop after each OpenGL function call. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an example, &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned int buffer = 0;&#xA;glGenBuffers(1, &amp;amp;buffer);&#xA;glBindBuffer(GL_ARRAY_BUFFER, buffer);&#xA;glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), vertices, GL_STATIC_DRAW); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now if I write it with &lt;code&gt;glGetError()&lt;/code&gt;, it would look something like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned int err = 0;&#xA;glGenBuffers(1, &amp;amp;buffer);&#xA;while( !(err = glGetError()) ){&#xA;    std::cout &amp;lt;&amp;lt; err;&#xA;}  &#xA;glBindBuffer(GL_ARRAY_BUFFER, buffer);&#xA;while( !(err = glGetError()) ){&#xA;    std::cout &amp;lt;&amp;lt; err;&#xA;}  &#xA;glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), vertices, GL_STATIC_DRAW); &#xA;while( !(err = glGetError()) ){&#xA;    std::cout &amp;lt;&amp;lt; err;&#xA;}  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Surely this isn't the way to go, right ? The source code looks so ugly.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I do proper error handling with OpenGL ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My graphics card supports OpenGL 4.4 and I am using C++ . &lt;/p&gt;&#xA;" OwnerUserId="7814" LastEditorUserId="2654" LastEditDate="2017-12-03T15:33:45.430" LastActivityDate="2020-03-07T21:06:14.593" Title="How to do error handling with OpenGL?" Tags="&lt;opengl&gt;&lt;debugging&gt;" AnswerCount="3" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5946" PostTypeId="2" ParentId="5945" CreationDate="2017-12-02T23:17:43.107" Score="12" Body="&lt;p&gt;Yes, there is a better way!  OpenGL 4.3 and later support the &lt;a href=&quot;http://docs.gl/gl4/glDebugMessageCallback&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glDebugMessageCallback&lt;/code&gt;&lt;/a&gt; API, which allows you to specify a function in your app that GL will call to issue a warning or error. In this function you can do whatever you like, such as setting a breakpoint in the debugger, or printing the error to a log file. This way you only need to setup the callback during initialization—much nicer than putting &lt;code&gt;glGetError&lt;/code&gt; calls everywhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To turn on this functionality your GL context also needs to be a &quot;debug context&quot;, which is specified by setting a flag when you create the context. The details will depend on which OS / windowing system / framework you're using. A debug context might be slower (on the CPU) than a regular context, but that's the price you pay for more detailed debugging info, kinda like turning optimizations off in the compiler.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See also &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Debug_Output&quot; rel=&quot;noreferrer&quot;&gt;this wiki page&lt;/a&gt; for more information. There's a bunch of other debugging-related functionality. For instance you can give human-readable names to textures, buffers, framebuffers, etc using &lt;a href=&quot;http://docs.gl/gl4/glObjectLabel&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glObjectLabel&lt;/code&gt;&lt;/a&gt;, which will then (I assume) be used in error messages. There are also APIs for turning off certain messages or categories of messages, in case you get spammed by warnings that you don't care about or some such.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-12-02T23:17:43.107" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5947" PostTypeId="1" AcceptedAnswerId="5948" CreationDate="2017-12-03T05:02:15.720" Score="2" ViewCount="1633" Body="&lt;p&gt;What does it mean and why is it not well suited for describing colors by human? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is CMYK nonlinear also?&lt;/p&gt;&#xA;" OwnerUserId="7817" LastEditorUserId="67" LastEditDate="2017-12-07T00:41:04.437" LastActivityDate="2019-10-07T08:02:21.960" Title="RGB nonlinear, what does it mean?" Tags="&lt;color&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5948" PostTypeId="2" ParentId="5947" CreationDate="2017-12-03T07:30:51.530" Score="4" Body="&lt;p&gt;In general, non-linear function would mean that an increase in an input does not produce a proportional increase or decrease in output. Mathematically, any function that relates one value to another that doesn't follow a straight line is non-linear. So x raised to the power y is a non-linear function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This matters for colors because our brains don't perceive light in a linear fashion. If you double the number of photons reaching the retina, the brain doesn't interpret it as twice as bright. Further, we can better distinguish two dark shades that are separated by a certain difference in intensity than two bright shades that are separated by the same fixed intensity difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When encoding light values in a computer, we need to choose how precisely to record them without losing too much quality. If we use too many bits, then our hardware becomes more expensive. If we use too few then the image looks bad. Until the last ~10-15 years or so, it was generally considered too expensive to store more than 8 bits per red, green, and blue channel. The problem is that if you encode the light values linearly (where 2x causes your monitor to produce twice as many photons as 1x does), then images stored with only 8 bits per channel will have very obvious banding in bright areas of continuous color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But remember above that humans can perceive smaller increments in darker shades than lighter? That means that we can use 8 bits per channel, but not use them linearly. If we instead take each 8-bit color channel value and treat it as a value between 0 and 1, if we raise that value to a power then we have smaller steps in the darker areas than in the lighter. This is called gamma-correction or gamma-encoding. We just have to remember to do the reverse (raise the value to the 1 / x power) when we want to output the values on a display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if you're dealing with non-linear RGB, it is probably gamma encoded. sRGB is a popular encoding that uses a power of ~2.2. (In truth, it's &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_.28.22gamma.22.29&quot; rel=&quot;nofollow noreferrer&quot;&gt;a little more complicated than just raising it to a power&lt;/a&gt;.) So when someone tells you that RGB is non-linear, that's usually what they are referring to. It is entirely possible to store images in linear RGB, so long as you use more than 8 bits per color channel. There are also formats that use a logarithmic encodings, though they are less common outside of film production.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;CMYK is more complicated than RGB. Rather than having only a single thing that is outputting the color (the monitor), with CMYK, you have to deal with the medium you're printing on as well as the inks you are printing with. In a typical scenario, you print onto a white surface (such as a piece of paper). Ideally all visible frequencies of light should be reflected off of the paper and into your eyes or camera. When you add ink, the ink absorbs some frequencies of light and reflects others. (And I believe some passes through the ink, hits the paper and is reflected back as well.) The manner in which an ink reflects light is non-linear. Doubling the amount of ink may not cut in half the number of photons reflected back. So CMYK is also non-linear.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="209" LastEditDate="2019-10-07T08:02:21.960" LastActivityDate="2019-10-07T08:02:21.960" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="5949" PostTypeId="2" ParentId="5945" CreationDate="2017-12-03T07:43:27.347" Score="1" Body="&lt;p&gt;If you can't go to OpenGL 4.3 (or your implementation doesn't support &lt;code&gt;glDebugMessageCallback&lt;/code&gt;s), you can simplify your code in a number of ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first is to move the calls to &lt;code&gt;glGetError()&lt;/code&gt; into a function like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void checkGLError()&#xA;{&#xA;    GLenum err;&#xA;    while((err = glGetError()) != GL_NO_ERROR){&#xA;        std::cout &amp;lt;&amp;lt; err;&#xA;    }  &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That reduces your code to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned int buffer = 0;&#xA;glGenBuffers(1, &amp;amp;buffer);&#xA;checkGLError();&#xA;glBindBuffer(GL_ARRAY_BUFFER, buffer);&#xA;checkGLError();&#xA;glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(float), vertices, GL_STATIC_DRAW); &#xA;checkGLError();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, calling &lt;code&gt;glGetError()&lt;/code&gt; frequently can hurt performance, so it's best to conditionalize it so it only gets called in debug builds by doing something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#if DEBUG&#xA;#define checkGLError() debugCheckGLError()&#xA;#else&#xA;#define checkGLError()&#xA;#endif&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then name the actual function &lt;code&gt;debugCheckGLError()&lt;/code&gt;. It will get called in debug builds but not release builds.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2020-03-07T21:06:14.593" LastActivityDate="2020-03-07T21:06:14.593" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="5950" PostTypeId="2" ParentId="5945" CreationDate="2017-12-03T15:39:50.970" Score="8" Body="&lt;p&gt;While &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Debug_Output&quot; rel=&quot;noreferrer&quot;&gt;Debug Output&lt;/a&gt; is good, and manual &lt;code&gt;glGetError&lt;/code&gt; usage is adequate, it's often better to employ a more &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Debugging_Tools&quot; rel=&quot;noreferrer&quot;&gt;dedicated tool for finding exactly where OpenGL errors came from&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://renderdoc.org/&quot; rel=&quot;noreferrer&quot;&gt;RenderDoc&lt;/a&gt; is probably the most up-to-date tool for this process, but there are quite a few in various states of functionality. These tools can also give you a detailed log of every OpenGL call you've made.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-12-03T15:39:50.970" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5951" PostTypeId="1" CreationDate="2017-12-03T21:31:56.190" Score="3" ViewCount="709" Body="&lt;p&gt;I'm trying to get an algorithm for intersecting a &quot;tube&quot; (a 3D cubic Bézier curve extruded by a possibly-changing radius) with the following required properties:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Computes intersections of ray and a 3D cubic Bézier curve.  Must not become confused, as some numerical algorithms do, by secondary rays, which start from the surface of the curve (i.e. at a zero).&lt;/li&gt;&#xA;&lt;li&gt;Must support a varying radius along the curve (a linear function is fine).  The radius may be zero in at-most one point.&lt;/li&gt;&#xA;&lt;li&gt;Hit point accuracy should be a function of floating-point precision or solver iterations.  I.e., the geometry must be correct, fully volumetric.&lt;/li&gt;&#xA;&lt;li&gt;Some reasonable way of handling endpoints.  I'd prefer spherical caps, but flat ones would be okay too.  A choice would be nice.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I don't need the fastest-possible algorithm.  The easiest reasonable algorithm is what I'm looking for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Can someone help me find an ray + 3D-cubic-Bézier intersection algorithm satisfying the above?  A paper link, a description, help pinning down references, etc.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;I've had great difficulty with a literature search on this.  Here are some of the (few) papers I found:&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;sup&gt;&quot;&lt;a href=&quot;http://wscg.zcu.cz/wscg2002/Papers_2002/A83.pdf&quot; rel=&quot;noreferrer&quot;&gt;Ray Tracing for Curves Primitive&lt;/a&gt;&quot;.  I implemented this, but the hit depth seems to be incorrect.  I suspect this is because it assumes (erroneously) that the cross section of the curve will be circular, even if at an angle.&lt;/sup&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;sup&gt;&quot;&lt;a href=&quot;http://research.nvidia.com/sites/default/files/pubs/2017-07_Exploiting-Budan-Fourier-and//HPG2017-Budan-Fourier.pdf&quot; rel=&quot;noreferrer&quot;&gt;Exploiting Budan-Fourier and Vincent's Theorems for Ray Tracing 3D Bézier Curves&lt;/a&gt;&quot;.  Seems over-complex, and doesn't seem to support varying radius.  Looks like it has the same bad assumption, and code isn't available.&lt;/sup&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;sup&gt;&quot;&lt;a href=&quot;http://fileadmin.cs.lth.se/graphics/research/papers/2012/hairy/&quot; rel=&quot;noreferrer&quot;&gt;High-Quality Curve Rendering using Line Sampled Visibility&lt;/a&gt;&quot;.  Quadratic curves only, rasterizer-based, unclear if meets other criteria.&lt;/sup&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="523" LastActivityDate="2017-12-03T22:35:21.037" Title="Simple Intersection Algorithm for Ray and 3D Bézier Curves of Varying Thickness" Tags="&lt;raytracing&gt;&lt;algorithm&gt;&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5952" PostTypeId="2" ParentId="5904" CreationDate="2017-12-03T21:47:03.927" Score="8" Body="&lt;p&gt;TL;DR: 2*1LSB triangular-pdf dithering breaks in edgecases at 0 and 1 due to clamping. A solution is to lerp to a 1bit uniform dither in those edgecases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am adding a second answer, seeing as this turned out a bit more complicated than I originally thought. It appears this issue has been a &quot;TODO: needs clamping?&quot; in my code since I switched from normalized to triangular dithering... in 2012. Feels good to finally look at it :) Full code for solution / images used throughout the post: &lt;a href=&quot;https://www.shadertoy.com/view/llXfzS&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/llXfzS&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all, here is the problem we are looking at, when quantizing a signal to 3bits with 2*1LSB triangular-pdf dithering:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nNHuJ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nNHuJ.png&quot; alt=&quot;outputs&quot;&gt;&lt;/a&gt;&#xA; - essentially what hotmultimedia showed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Increasing contrast, the effect described in the question becomes apparent: The output does not average to black/white in the edgecases (and actually extends well beyond 0/1 before doing so).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Cdgag.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Cdgag.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at a graph provides a bit more insight:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Z1Q15.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z1Q15.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;(grey lines mark 0/1, also in grey is the signal we are trying to output, yellow-line is average of dithered/quantized output, red is the error (signal-average)).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Interestingly, not only is the average output not 0/1 at the limits, it is also not linear (likely due to the triangular pdf of the noise). Looking at the lower end, it makes intuitive sense why the output diverges: As the dithered signal starts to include negative values, the clamping-on-output changes the value of the lower dithered parts of the output (ie the negative values), thereby increasing the value of the average. An illustration appears to be in order (uniform, symmetric 2LSB dither, average still in yellow):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IntiM.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IntiM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if we just use a 1LSB normalized dither, there are no issues at the edges-cases at all, but then of course we lose the nice properties of triangular dithering (see e.g. &lt;a href=&quot;http://loopit.dk/rendering_inside.pdf&quot; rel=&quot;noreferrer&quot;&gt;this presentation&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tHGbs.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tHGbs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A (pragmatic, empirical) solution (hack) then, is to revert to [-0.5;0.5[ uniform dithering for the edgecase:&lt;/p&gt;&#xA;&#xA;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;float dithertri = (rnd.x + rnd.y - 1.0); //note: symmetric, triangular dither, [-1;1[&#xA;float dithernorm = rnd.x - 0.5; //note: symmetric, uniform dither [-0.5;0.5[&#xA;&#xA;float sizt_lo = clamp( v/(0.5/7.0), 0.0, 1.0 );&#xA;float sizt_hi = 1.0 - clamp( (v-6.5/7.0)/(1.0-6.5/7.0), 0.0, 1.0 );&#xA;&#xA;dither = lerp( dithernorm, dithertri, min(sizt_lo, sizt_hi) );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which fixes the edgecases while keeping the triangular dithering intact for the remaining range:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MYr1f.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MYr1f.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to not answer your question: I do not know if there is a more mathematically solid solution, and am equally keen to know what Masters of Past have done :) Until then, at least we have this horrific hack to keep our code functioning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT&lt;br&gt;&#xA;I should probably cover the workaround-suggestion given in The Question, on simply compressing the signal. Because the average is not linear in the edgecases, simply compressing the input-signal does not produce a perfect result - though it does fix the endpoints:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/DEVJo.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DEVJo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;References&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.shadertoy.com/view/llXfzS&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/llXfzS&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://loopit.dk/rendering_inside.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://loopit.dk/rendering_inside.pdf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://loopit.dk/banding_in_games.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://loopit.dk/banding_in_games.pdf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://32ipi028l5q82yhj72224m8j-wpengine.netdna-ssl.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://32ipi028l5q82yhj72224m8j-wpengine.netdna-ssl.com/wp-content/uploads/2016/03/GdcVdrLottes.pdf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2463" LastEditorUserId="2463" LastEditDate="2017-12-04T08:16:35.227" LastActivityDate="2017-12-04T08:16:35.227" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="5953" PostTypeId="2" ParentId="5951" CreationDate="2017-12-03T22:06:38.167" Score="1" Body="&lt;p&gt;You say that you don't need the fastest possible algorithm, so instead of solving it analytically, you might try considering the numeric alternatives, which in this case could mean ray marching.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How you could do this is take steps down the ray and test if the point is inside or outside of this bezier tube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You would iterate down the ray until you either find an intersection or leave the bounding box of this shape (or maybe when you take a maximum number of steps, or some other fail case).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The challenge then only becomes &quot;how can I tell if a point is inside or outside of the shape?&quot; which is a lot simpler.  If you had constant thickness you would just find the closest point on the bezier to your point and do a distance comparison.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some details you might be interested in:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;taking smaller steps, and more of them, will give you more accurate results, but will be more expensive computationally. That makes this algorithm tuneable for quality vs speed.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;if the step size is too large or the tube is too thin, you may completely miss the tube when there is really a hit.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;when/if you do find a hit, you are finding the first point inside the shape. The real answer is somewhere between the last sample and the current sample.  You could refine the hit location with a binary search or some other method if you wanted to.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;you can likely increase the step size as you move farther from the camera. Smaller details are harder to see at greater distances.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;you might be able to calculate or approximate the gradient of your point vs bezier tube function as you ray march. If so, this gradient can be used to give you a lower bound on the distance from your point to the bezier tube, which would let you take larger steps through empty space.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Regarding the &quot;secondary ray&quot; issue you mention like for shadow rays or reflection rays that comes up with both analytical and numerical solutions.  Getting a (probably) less precise answer than a numerical solution does make the problem worse, but there should be ways to get around it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, after you detect a hit, you could find a point on the surface near the hit even if it isn't where the hit was (like, push the hit point to the surface, in whatever direction is easiest to compute), add an epsilon (needed for analytical solutions anyways) and spawn secondary rays from there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way could be to have every object have an ID and when ray marching / tracing, don't count intersections with the same ID as what you just hit.  This only really works for opaque convex objects though.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2017-12-03T22:35:21.037" LastActivityDate="2017-12-03T22:35:21.037" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5955" PostTypeId="1" AcceptedAnswerId="5958" CreationDate="2017-12-05T00:41:56.357" Score="6" ViewCount="504" Body="&lt;p&gt;The GGX NDF, as it appears on the paper where it is presented is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$D(m)=\frac{\alpha_g^2\space\chi^+(m\cdot n)}{\pi\cos^4(\theta_m)(\alpha_g^2+\tan^2(\theta_m))^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is equivalent, in the range $[0,\frac{\pi}{2}]$, to the following formulation (notation simplified by me):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$D(m)=\frac{\alpha^2}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;by finding the derivative of the inverse of the expresions used for importance sampling ($\theta_m=\arctan(\frac{\alpha\sqrt{\xi_1}}{\sqrt{1-\xi_1}})$ and $\phi_m=2\pi\xi_2$) presented in the same paper we can derive the following PDF:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$p(m)=\frac{\alpha^2\cos(\theta)\sin(\theta)}{\pi(\cos^2(\theta)(\alpha^2-1)+1)^2}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When finding the corresponding PDF for, for instance, the Blinn NDF the only difference is a $\sin(\theta)$ in the numerator that comes from the fact that the NDF is a distribution over a hemisphere. So where does the $\cos(\theta)$ factor in the GGX PDF come from? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think it is explained after formula (37) in the paper but i don't understand the reasoning behind it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PD:here are the Blinn NDF and PDF as i understand them for reference&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NDF: $\frac{n+1}{2\pi}\cos^n(\theta)$  --- PDF: $\frac{n+1}{2\pi}\cos^n(\theta)\sin(\theta)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: here is a &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;link to the paper&lt;/a&gt; in case it makes the question easier to answer&lt;/p&gt;&#xA;" OwnerUserId="5703" LastEditorUserId="5703" LastEditDate="2017-12-05T16:52:22.627" LastActivityDate="2017-12-05T21:50:09.517" Title="Where does the cosine factor comes from in the GGX PDF?" Tags="&lt;rendering&gt;&lt;mathematics&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5957" PostTypeId="1" CreationDate="2017-12-05T08:05:30.770" Score="3" ViewCount="200" Body="&lt;p&gt;I am trying to apply sinc interpolation on &lt;a href=&quot;https://drive.google.com/file/d/0BwxvtmE7yeVKSUlnbWxUbC1VdGM/view?usp=sharing&quot; rel=&quot;nofollow noreferrer&quot;&gt;this data set&lt;/a&gt;. The patches in the left image is a snapshot of AutoCAD 3d faces. Lux values are calculated for centre of each patch that are in 0.3m x 0.3m dimension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rwfs3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rwfs3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/uJ7Zv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uJ7Zv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SuYWb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SuYWb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The middle is a bitmap image of the above data set. Applying below sinc interpolation method results in the right side image. I was expecting to get smooth gradient in the colours but am not sure if the sinc function is applied correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the sinc interpolation method&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public ImageFilm ConvolveWithSinc(ImageFilm fs, float Ts)&#xA;{&#xA;    float Ws = 1 / Ts;&#xA;    int N = fs.Width;&#xA;    int M = fs.Height;&#xA;    ImageFilm fy = new ImageFilm(N, M);&#xA;    Vector zero = Vector.ZERO;&#xA;    for (int x = 0; x &amp;lt; N; x++)&#xA;    {&#xA;        for (int y = 0; y &amp;lt; M; y++)&#xA;        {&#xA;            LightVector sum = LightVector.ZERO;&#xA;            double sincSum = 0;&#xA;            for (int n = 0; n &amp;lt; fs.Width; n++)//= (int)Ts&#xA;            {&#xA;                for (int m = 0; m &amp;lt; fs.Height; m++)//= (int)Ts&#xA;                {&#xA;                    double sinc = (Helper.Sinc(Ws * (x - n)) *&#xA;                        Helper.Sinc(Ws * (y - m)));&#xA;&#xA;                    sincSum += sinc;&#xA;&#xA;                    LightVector v = fs.GetPixel(n, m);&#xA;                    if (v == zero) continue;&#xA;&#xA;                    sum += v * sinc;&#xA;                }&#xA;            }&#xA;            LightVector c = sum / sincSum;&#xA;            if (c.X &amp;gt; 255 || c.Y &amp;gt; 255 || c.Z &amp;gt; 255)&#xA;                c = c.Clamp(0, 255);&#xA;            fy.SetPixel(x, y, c);&#xA;        }&#xA;    }&#xA;    return fy;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I understand that the sampling frequency on the above middle image might be below the Nyquist frequency but I wanted to know if this is the case or &#xA;I am doing something wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried the above method on a simpler function sin(16*x*x) and the interpolated image looks similar to the original:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LiFLH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LiFLH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for the comments. I have modified the code to divide the pixel value by the sum of the two sinc functions. Is this the correct way of normilizing it? The image looks better but it is very blurry. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aZrhE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aZrhE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T19:55:01.770" LastActivityDate="2018-03-04T19:55:01.770" Title="Sinc interpolation and Ideal reconstruction example" Tags="&lt;image-processing&gt;&lt;interpolation&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="5958" PostTypeId="2" ParentId="5955" CreationDate="2017-12-05T21:43:20.207" Score="6" Body="&lt;p&gt;Normal distribution functions are defined a bit differently than you might expect. They're not &lt;em&gt;strictly&lt;/em&gt; a probability distribution over solid angle; they have to do with the density of microfacets with respect to macro-surface area. The upshot is that they're normalized with an extra cosine factor:&#xA;$$ \int_\Omega D(m) \cos(\theta_m)\, d\omega_m = 1 $$&#xA;This cosine factor accounts for the projected area of microfacets onto the macrosurface. When importance-sampling the NDF this cosine factor must be accounted for as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is actually hinted at in the text of the paper, as it says&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The equations for sampling $D(m) | m \cdot n |$ are:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;(just above equations 35–36). The $|m \cdot n|$ factor there is equal to $|cos(\theta_m)|$. So the quantity being sampled is not just the NDF itself, but includes this extra factor. Then, as you note, the sine shows up as part of the area element for spherical coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wrote &lt;a href=&quot;http://reedbeta.com/blog/hows-the-ndf-really-defined/&quot; rel=&quot;noreferrer&quot;&gt;a blog post&lt;/a&gt; a few years ago that goes into more detail about this.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2017-12-05T21:50:09.517" LastActivityDate="2017-12-05T21:50:09.517" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5959" PostTypeId="1" AcceptedAnswerId="5962" CreationDate="2017-12-07T05:44:01.390" Score="0" ViewCount="144" Body="&lt;p&gt;I have a bunch of intersecting convex polygons, I want to find vertices of the outer contour of all those polygons. An individual polygon is not self-intersecting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you please tell What could be a generic way of achieving this? Is there an API to do this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I'm developing a CAD drawing generator using .netdxf and C#.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is a simple example&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UT9G4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UT9G4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7412" LastActivityDate="2017-12-07T19:51:33.557" Title="Finding vertices of the outer contour of intersecting polygons" Tags="&lt;polygon&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5962" PostTypeId="2" ParentId="5959" CreationDate="2017-12-07T19:51:33.557" Score="1" Body="&lt;p&gt;Sounds like you’re looking for a way to do a &lt;a href=&quot;https://en.wikipedia.org/wiki/Boolean_operations_on_polygons&quot; rel=&quot;nofollow noreferrer&quot;&gt;Boolean union operation&lt;/a&gt;. There’s a couple of algorithms linked from that article that should do the trick.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2017-12-07T19:51:33.557" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5963" PostTypeId="1" CreationDate="2017-12-07T20:31:34.333" Score="1" ViewCount="147" Body="&lt;p&gt;Using an iPhone X, I can get a mesh of the face (using &lt;code&gt;ARFaceGeometry&lt;/code&gt;), which I can output as an &lt;code&gt;.obj&lt;/code&gt; file using &lt;code&gt;Model I/O&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not included in the output file is an image for the face, but I can get the camera image for that frame, as a jpeg.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I look at the resulting &lt;code&gt;.mtl&lt;/code&gt; file in a text editor, I see 5 different materials (&quot;material_1&quot;, &quot;material_2&quot;, etc.), When I look at the &lt;code&gt;.obj&lt;/code&gt; file in a text editor, there are 5 &quot;groups&quot; of info (each with vertices, normals, texture coordinates, and face elements).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know about 2 assumptions I am making:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;If I erase the last 4 materials in the &lt;code&gt;.mtl&lt;/code&gt; file, along with the last 4 groups of info in the &lt;code&gt;.obj&lt;/code&gt; file, the mesh seems to look the same. Is it okay to assume only the first set is sufficient?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Can I replace the texture coordinates in this first group (of the &lt;code&gt;.obj&lt;/code&gt; file, the set of &lt;code&gt;vt&lt;/code&gt;s), to reflect the new jpeg image? My goal is to get the image of the face to texture onto the face mesh.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I'm creating these new texture coordinates by: for each vertex in the mesh, transform to world space, then camera space, then divide by image dimensions to get a value between 0 and 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you might guess, I'm getting some pretty funky textures on the mesh (though I'm pleased I'm getting some texture!). Does any part of my workflow sound incorrect?&lt;/p&gt;&#xA;" OwnerUserId="7864" LastActivityDate="2017-12-07T20:31:34.333" Title="Composition of an .obj file" Tags="&lt;texture&gt;&lt;3d&gt;&lt;transformations&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5964" PostTypeId="1" AcceptedAnswerId="5967" CreationDate="2017-12-08T09:01:41.160" Score="2" ViewCount="616" Body="&lt;p&gt;I'm confused how does the GL_SRC_ALPHA_SATURATE function effect a 32 bit floating point texture attachment in FBO while blending colors. In the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;reference&lt;/a&gt; the equation is:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/EDVYW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EDVYW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here what is the value of kA for a 32-bit(GL_RGBA32F) texture?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Blending#Source.2C_Destination.2C_and_the_buffer&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt;, when blending a floating point texture, the color value does not get normalized. If so then does min(As, ka - Ad) get divided by the kA?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And lastly, what happens if Ad is negative floating value?&lt;/p&gt;&#xA;" OwnerUserId="3024" LastEditorUserId="3024" LastEditDate="2017-12-08T09:09:01.710" LastActivityDate="2017-12-08T21:13:57.917" Title="Blending for Floating Point Texture" Tags="&lt;opengl&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5965" PostTypeId="1" AcceptedAnswerId="5966" CreationDate="2017-12-08T12:05:51.657" Score="3" ViewCount="144" Body="&lt;p&gt;Do primary rays conform to the frustum? If they're randomly directed, is the randomness fitted to some distribution (as it would be for a diffuse BRDF? I'm building my existing raymarcher into a monte carlo path tracer and I'm really unsure about how to orient my rays before tracing actually starts.&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2017-12-09T10:24:59.560" Title="Primary ray directions (MC Path tracer)" Tags="&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5966" PostTypeId="2" ParentId="5965" CreationDate="2017-12-08T12:13:33.037" Score="1" Body="&lt;p&gt;Yes, in the simple case, primary rays conform to the frustum. If you're doing depth-of-field optically, then the rays don't quite conform to the frustum, because you need to vary the ray origins slightly as well as the directions. How exactly the variation works depends on how closely you're simulating the lens system and aperture. You can picture it as sampling from several frustums, one for each pinhole camera you're averaging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've never done full Monte Carlo for ray sampling: generating the rays according to a uniform distribution is bad at distributing them usefully around the image. Popular options include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You can generate the ray directions according to a space-filling curve on the image plane, and then adaptively supersample once you have enough samples to estimate contrast.&lt;/li&gt;&#xA;&lt;li&gt;Start with a regular grid that goes through the centre of each pixel, but randomly jitter the directions within each pixel. This was popular for many years but (done naively) it's still slightly biased because you're too likely to sample the corners of pixels.&lt;/li&gt;&#xA;&lt;li&gt;Start with a uniform random sampling but use Poisson discs to avoid putting rays too close together. This is closer to a pure random sampling, and it has the advantage you can keep using the technique as you refine/supersample the image by decreasing the disc radius over time.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2017-12-09T10:24:59.560" LastActivityDate="2017-12-09T10:24:59.560" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="5967" PostTypeId="2" ParentId="5964" CreationDate="2017-12-08T21:13:57.917" Score="2" Body="&lt;p&gt;Section &quot;17.3.8 Blending&quot; of the OpenGL spec states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If the color buffer is fixed-point, the components of the source and destination values and blend factors are each clamped to [0, 1] or [-1, 1] respectively for an unsigned normalized or signed normalized color buffer prior to evaluating the blend equation. &lt;strong&gt;If the color buffer is floating-point, no clamping occurs&lt;/strong&gt;. The resulting four values are sent to the next operation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So we know that no clamping occurs there. The next section is &quot;17.3.8.1 Blend Equation&quot; and states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Signed or unsigned normalized fixed-point destination (framebuffer) components are represented as described in section 2.3.4. &lt;strong&gt;Constant color components, floating-point destination components, and source (fragment) components are taken to be floating-point values&lt;/strong&gt;. If source components are represented internally by the GL as fixed-point values, they are also interpreted according to section 2.3.4.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Finally, section &quot;17.3.8.2 Blend Functions&quot; refers to table 17.2 which explains that for &lt;code&gt;GL_SRC_ALPHA_SATURATE&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RGB Blend Factors = (f, f, f)&#xA;Alpha Blend Factor = 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ f = min(A_{s0}, 1 - A_d) $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it seems that the reference documentation is misleading for this particular case. However the specification is clear: there is no clamping or conversion for floating-point color buffers.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;What if Ad is negative floating value?&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;My reading of the spec is that nothing special happens if Ad is negative. The &lt;code&gt;min()&lt;/code&gt; operation will still produce results, but I don't see how they would be useful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've never used &lt;code&gt;GL_SRC_ALPHA_SATURATE&lt;/code&gt; myself, but the way I understand it, with &lt;code&gt;GL_FUNC_ADD&lt;/code&gt;, it is meant to accumulate color values in the color buffer until the accumulated alpha value equals 1. When the alpha value of the color buffer is 1, no further color contribution from new pixels is allowed. This assumes that you use alpha values between 0 and 1 and use an initial alpha value of 0. Otherwise everything falls apart.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact, I think majority of the blending factor mechanisms were designed with alpha values between 0 and 1 in mind and make little sense outside of that range.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2017-12-08T21:13:57.917" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5968" PostTypeId="1" AcceptedAnswerId="6023" CreationDate="2017-12-09T01:07:53.423" Score="2" ViewCount="1360" Body="&lt;p&gt;I'm following &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing/global-illumination-path-tracing-practical-implementation&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial&lt;/a&gt; where at somepoint the derived PDF for spherical coordinates for a Lambertian surface is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{array}{l}&#xA;p(\theta, \phi) = \dfrac{\sin \theta}{2 \pi}.&#xA;\end{array}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But as soon as they compute a sample, the result is instead divided by $ \dfrac{1}{2\pi} $, which as they say is the &quot;pdf of the integral&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why isn't it divided by $ \frac{\sin \theta}{2 \pi} $ instead?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we were using differential steradians over the unit hemisphere, the only possible probability density function integrating to 1 is infact $ \frac{1}{2\pi} $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But if we separate the integral over the hemisphere traced by spherical coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ &#xA;\int_{\phi = 0}^{2\pi} \int_{\theta = 0}^{\frac{\pi}{2}}  \,  \frac{\sin{\theta}}{2\pi}d\theta d\phi= 1. &#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The PDF now becomes $ \frac{\sin \theta}{2 \pi} $ yet they still divide by $ \frac{1}{2\pi} $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: after carefully reviewing the concept of PDFs and integration over the hemisphere I'm starting to think the article I've linked is making a substantial error, mixing the idea of importance sampling with the pdf of choosing a direction of reflectance from a lambertian surface&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Radiance is defined as&#xA;$$ L_{(x,\omega)} = \frac{\mathrm{d}^2\Phi}{\mathrm{d}\omega\ cos\theta\ \mathrm{d}x}  $$&#xA;Since it's defined over differential solid angles, we can interpret the result of one sample as if it was the flux density &quot;over a unit steradian&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we use monte carlo estimation and find &quot;the average flux density over a single steradian&quot; and multiply the result by $2\pi$, we get irradiance:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ (2\pi) \frac{1}{n}\sum^n L_{(x,\omega)} $$. &#xA;But in this particular case, $2\pi$ has nothing to do with pdfs! since it's the integral domain used for the monte carlo estimation!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, the real pdf is computed for $\theta$ and $\phi$ because that is the probability density function of choosing &lt;strong&gt;one direction over the other, according to the particular properties of a lambertian surface&lt;/strong&gt;. A mirror-like surface has a different probability of choosing one direction over the other, but this has nothing to do us with dividing the sample with $\frac{1}{2\pi}$. It would be different if we were using importance sampling, but in this case it seems like we're not&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is my reasoning correct? If not, what am I missing?&lt;/p&gt;&#xA;" OwnerUserId="7871" LastEditorUserId="7871" LastEditDate="2017-12-11T01:25:09.150" LastActivityDate="2017-12-22T04:51:00.597" Title="Probability density function while using spherical coordinates" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5971" PostTypeId="1" CreationDate="2017-12-11T22:13:51.483" Score="3" ViewCount="82" Body="&lt;p&gt;This is more just for curiosity rather than actually wanting to get one, but is there a place where I could buy a printed version of the CIE xy colour space diagram which accurately recreates all of the visible colours outside of the regular printing gamuts?&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-12T17:59:57.457" Title="Accurately printed CIE diagram" Tags="&lt;color-science&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5972" PostTypeId="1" AcceptedAnswerId="5973" CreationDate="2017-12-12T00:22:25.070" Score="7" ViewCount="2811" Body="&lt;p&gt;I ran into half-edges as part of the result of a Delaunay Triangulation library, but can't find an actual definition of what one is. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand vertices, edges and faces, but can't find a concrete definition of a half-edge.&lt;/p&gt;&#xA;" OwnerUserId="6406" LastActivityDate="2017-12-12T04:09:35.353" Title="What is the definition of a Half Edge?" Tags="&lt;triangulation&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5973" PostTypeId="2" ParentId="5972" CreationDate="2017-12-12T04:09:35.353" Score="12" Body="&lt;p&gt;A half-edge is an edge split along its length, and having a directional component, that is, a beginning vertex and an end vertex. Where two polygons share an edge, each polygon gets a single half-edge between the same two vertices, which will have opposite directions if the winding order is consistent. These half-edges will have references to one another as two halves of a pair.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The full half edge data structure stores for each half-edge:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The polygon it belongs to&lt;/li&gt;&#xA;&lt;li&gt;Previous and next half edges within the polygon&lt;/li&gt;&#xA;&lt;li&gt;Its pair half-edge in a neighbouring polygon&lt;/li&gt;&#xA;&lt;li&gt;Its origin vertex&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This structure allows you to extract all sorts of connectivity information from a mesh, such as which edges or polygons lie around a particular vertex, simply by traversing the half-edges. There's a good article explaining it &lt;a href=&quot;http://kaba.hilvi.org/homepage/blog/halfedge/halfedge.htm&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-12-12T04:09:35.353" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5974" PostTypeId="2" ParentId="5971" CreationDate="2017-12-12T10:12:11.697" Score="-2" Body="&lt;p&gt;I think there is no point pursuing &quot;objective accuracy&quot; for colors, because individual perception of colors is different. The current standard is merely a statistical result for human eye perception.&#xA;That is to say, it is possible for someone else to perceive the colors you regard identical as different.&lt;/p&gt;&#xA;" OwnerUserId="5748" LastActivityDate="2017-12-12T10:12:11.697" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5976" PostTypeId="1" AcceptedAnswerId="5977" CreationDate="2017-12-12T14:51:35.527" Score="2" ViewCount="87" Body="&lt;p&gt;I am told that in computer graphics, the screen refreshes in number of times(in this scenario let say that it &lt;strong&gt;renders&lt;/strong&gt; &lt;strong&gt;60&lt;/strong&gt; times per second). The screen is cleared and drawn to 60 times per second.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is how can I see the &lt;strong&gt;Image&lt;/strong&gt; being shown 60 times per second yet I cannot see the &lt;strong&gt;Clear Color&lt;/strong&gt; which is also being displayed 60 times per second too?&#xA;Or does this have to do with how our eyes see or how our brain interprets things we see?&lt;/p&gt;&#xA;" OwnerUserId="7884" LastEditorUserId="2041" LastEditDate="2017-12-13T10:18:32.047" LastActivityDate="2017-12-13T10:18:32.047" Title="Why isn't the clear color visible on the screen between frames?" Tags="&lt;rendering&gt;&lt;image&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5977" PostTypeId="2" ParentId="5976" CreationDate="2017-12-12T15:07:37.507" Score="7" Body="&lt;p&gt;You're confusing the &lt;em&gt;screen&lt;/em&gt; (the physical display) with the &lt;em&gt;framebuffer&lt;/em&gt; (the memory which gets read out by the &lt;em&gt;display controller&lt;/em&gt;). The framebuffer might get cleared at the start of each frame period, but that doesn't change the display. The order of events is as follows:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;At the start of a new frame, &lt;code&gt;glClear&lt;/code&gt; or equivalent sets the framebuffer to the clear colour.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;glDraw&lt;/code&gt; or equivalent calls draw more stuff on top of the clear colour.&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;eglSwapBuffers&lt;/code&gt; or equivalent queues the finished frame to be drawn on the display.&lt;/li&gt;&#xA;&lt;li&gt;When the display is ready, &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5863/2041&quot;&gt;this process&lt;/a&gt; is followed. It reads out the contents of the framebuffer and shows them on the physical screen.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The framebuffer that's being drawn into is never shown on the screen; only when it's finished can it be shown. Double- or triple-buffering gives you multiple copies of the framebuffer, so the application can be using one while the display is using the other. It's nothing to do with your eyes or brain.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;It's actually a lot more complicated than this, because most GL implementations today are not immediate-mode, so none of the real work happens when you call the functions named above. In fact, clearing the buffer might not even happen at all: if every pixel is drawn to anyway, there's no need to. Back when clearing the framebuffer took significant time, games would go faster by not calling &lt;code&gt;glClear&lt;/code&gt;. Today it's more important to call &lt;code&gt;glClear&lt;/code&gt; because it lets the implementation know when the start of the new frame is, but it will probably do something smarter than just writing to every pixel.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2017-12-12T15:07:37.507" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5978" PostTypeId="2" ParentId="5971" CreationDate="2017-12-12T17:59:57.457" Score="1" Body="&lt;p&gt;Its not actually possible to do. Because that paper you print on needs to have properties not avalialbe. The color on the edge are very pure and can not be mixed. I dont also see any way they could be reflected either. Also the xy diagram is not the full color space just a slice of it.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2017-12-12T17:59:57.457" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5979" PostTypeId="1" CreationDate="2017-12-12T20:54:53.310" Score="0" ViewCount="71" Body="&lt;p&gt;I have OSM world data (essentially I processed the XML data into JSON containing arrays of objects (streets, buildings etc.) that each are represented by an array of lat/lon coordinates). Some of these are lines (roads etc.), others are areas that have to be filled (1st and last point close the area). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyhow, I would like to achieve an image similiar to google maps or mapbox but much simpler as I do not require city name labels or anything of the sort. For now all I really need is roads.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need this for a game I am making so the method itself must not be the most elegant one as I probably wont be doing this on the fly but rather prerendering the world to then send the images prerendered to the players. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is merely, where the heck do I start? I have no idea how the rendering of bitmaps is done (or whatever other format is best.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know C# and NodeJS and am not afraid of learning new frameworks or technologies.&lt;/p&gt;&#xA;" OwnerUserId="7888" LastActivityDate="2017-12-13T09:27:14.377" Title="I need to build my own map renderer" Tags="&lt;rendering&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5981" PostTypeId="2" ParentId="5979" CreationDate="2017-12-13T09:27:14.377" Score="1" Body="&lt;p&gt;If you have the prerendered images, you can &quot;simply&quot; render them onto a grid of quads. This is done with texturing, i.e. you upload the image to your GPU as a texture and apply texturecoordinates to quads, such that when you render the quads, the textures are applied correctly to their surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You will however need to learn OpenGL (preferrably with GLSL), Direct3D with HLSL or even Vulkan, all of which will take some time. Depneding on where your goals lie, you may be better of going with a preexisting rendering engine and just learning like Unity or Unreal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do want to learn one of the mentioned Graphics APIs, there are numerous tutorials on the web. For OpenGL I can recommend the &lt;a href=&quot;https://www.youtube.com/watch?v=VS8wlS9hF8E&amp;amp;list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&quot; rel=&quot;nofollow noreferrer&quot;&gt;youtube tutorials by ThinMatrix&lt;/a&gt;, for the other two APIs you'd need to ask someone else. Furthermore, there are splendid books online as well as offline. If you have some money to burn, the basics of rendering are covered in &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/1568814240&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real-Time Rendering&lt;/a&gt; and &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/1435458869&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mathematics for 3d Game Programming and Computer Graphics&lt;/a&gt;. In regards to OpenGL, there are the &lt;a href=&quot;https://learnopengl.com/#!Introduction&quot; rel=&quot;nofollow noreferrer&quot;&gt;Online Tutorials of Learn OpenGL&lt;/a&gt;, as well as offline books in &lt;a href=&quot;https://learnopengl.com/book/learnopengl_book.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;pdf&lt;/a&gt; and &lt;a href=&quot;https://learnopengl.com/book/learnopengl_book.epub&quot; rel=&quot;nofollow noreferrer&quot;&gt;epub&lt;/a&gt; version.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2017-12-13T09:27:14.377" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5982" PostTypeId="2" ParentId="5939" CreationDate="2017-12-13T09:31:40.473" Score="4" Body="&lt;p&gt;Yes, ray differentials are the way to go. The &lt;a href=&quot;https://graphics.stanford.edu/papers/trd/trd_jpg.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Paper by Igehy&lt;/a&gt; introduces them for the use case of filtered texture lookups. When generating the primary rays, you initialise the differentials to reflect the pixel footprint. As the ray progresses through the scene, you update the differentials at every bounce. When it comes to a texture lookup, you need to project the differentials to your s,t texture space (aka UV), typically by going to surface parameter space as an intermediate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The case that you mention, the calculation of derivatives for a ray surface intersection, is implemented in &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/eafd87d4ea3d6beb42f5e31a400a2158c4bee0f8/src/core/interaction.cpp#L103&quot; rel=&quot;nofollow noreferrer&quot;&gt;pbrt&lt;/a&gt;:&#xA;Here the surface is described by a point p, normal n and two tangent vectors dPdu and dPdv. The resulting dudx, dudy, dvdx and dvdy are the differentials of the u, v parameters of the surface with respect to screen space x and y. Conversion from surface parameters to texture space happens &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/7095acfd8331cdefb03fe0bcae32c2fc9bd95980/src/core/texture.cpp#L93&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2017-12-13T09:31:40.473" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5985" PostTypeId="1" AcceptedAnswerId="5986" CreationDate="2017-12-14T01:11:05.310" Score="0" ViewCount="189" Body="&lt;p&gt;I've been exploring the &lt;a href=&quot;https://en.wikipedia.org/wiki/Midpoint_circle_algorithm&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Midpoint circle algorithm&quot;&gt;Midpoint algorithm&lt;/a&gt; for drawing lines and curves, and I have a quick question: How should you determine the &lt;strong&gt;fast direction&lt;/strong&gt; for a curve? I've seen that if the shape is simple, you can draw one section and repeat the rest, but what if the shape does not have this property?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now I'm just using the derivative(slope), so I wonder if this is correct or cheaty? :P&lt;/p&gt;&#xA;" OwnerUserId="6838" LastActivityDate="2017-12-14T15:05:30.660" Title="Midpoint Algorithm Fast Direction" Tags="&lt;curve&gt;&lt;2d-graphics&gt;&lt;midpoint&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5986" PostTypeId="2" ParentId="5985" CreationDate="2017-12-14T03:32:46.393" Score="0" Body="&lt;p&gt;I have never done this so this is just my best guess. I think you are on the track with the slope but I'm going to expand it little with some calculus. If you parameterize your curve by some variable t:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;x(t) = ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;y(t) = ...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you can compute dx/dt and dy/dt which is how much x or y changes as you change t. This runs into some problems on a general purpose curve though. For example dx/dt might be a function of t. This means that the rate of change of x itself is changing as you move along the curve. But then you can also find dx/dt^2 (rate of change of the rate of change) and so on. This method is known as forward differencing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then what you can do is have an x, y starting point and draw a pixel there. Then you add the first order difference (dx/dt, dy/dt) to x and y. Then you add the second order difference to the first order difference and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a link I found on forward differencing:&#xA;&lt;a href=&quot;http://www.nptel.ac.in/courses/122104018/node103.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.nptel.ac.in/courses/122104018/node103.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't read it but it looks promising.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;--edit--&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an example that was derived in my computer graphics class:&#xA;Some of the algebra can be tricky so it may or may not be correct.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Q(t) = a*t^3 + b*t^2 + c*t + k&#xA;0 &amp;lt; t &amp;lt; 1&#xA;segment size d&#xA;num segments: 1/d&#xA;&#xA;Q1(t) = Q(t + d) - Q(t)&#xA;= 3*a*d*t^2 + 3*a*t*d^2 + a*d^3 + 2*b + d + b*d^2 + c*d&#xA;&#xA;Q2(t) = Q1(t + d) - Q1(t)&#xA;= b*a*t*d^2 + 6*a*d^3 + 2*b*d^2&#xA;&#xA;Q3(t) = Q2(t + d) - Q2(t)&#xA;= b*a*d^3      &amp;lt;==== no longer depends on t!&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Iterate:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;init variables:&#xA;Q  = Q(0)  = k&#xA;Q1 = Q1(0) = a*d^3 + b*d^2 + c*d&#xA;Q2 = Q2(0) = b*a*d^3 + 2*b*d&#xA;Q3 = Q3(0) = b*a*d^3&#xA;&#xA;repeat 1/d times:&#xA;    drawLine(Q, Q + Q1)&#xA;    Q  += Q1&#xA;    Q1 += Q2&#xA;    Q2 += Q3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Q is just for one of the x or y variables. You could have a QX, QX1, ... and QY, QY1, ... and forward difference them both in the same loop. Then draw using (QX, QY) and (QX + QX1, QY + QY1). You could also extend this into as many dimensions as you like.&lt;/p&gt;&#xA;" OwnerUserId="7740" LastEditorUserId="7740" LastEditDate="2017-12-14T15:05:30.660" LastActivityDate="2017-12-14T15:05:30.660" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5988" PostTypeId="1" AcceptedAnswerId="5989" CreationDate="2017-12-15T11:18:29.250" Score="1" ViewCount="134" Body="&lt;p&gt;I'm doing a project with assimp.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I got confused with the weird situation for me.&#xA;I think the both code are exactly same, but the result is different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why the codes act differently?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(vertex shader)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;layout (location = 0) in vec3 aPos;&#xA;layout (location = 1) in vec3 aNormal;&#xA;layout (location = 2) in vec2 aTexCoords;&#xA;&#xA;// declare an interface block; see 'Advanced GLSL' for what these are.&#xA;out VS_OUT {&#xA;    vec2 TexCoords;&#xA;} vs_out;&#xA;&#xA;out vec2 TexCoords;&#xA;&#xA;uniform mat4 model;&#xA;uniform mat4 projection;&#xA;uniform mat4 view;&#xA;&#xA;&#xA;void main()&#xA;{&#xA;    TexCoords = aTexCoords; ----(1)&#xA;    //vs_out.TexCoords = aTexCoords; ----(2) &#xA;    gl_Position = projection * view * model * vec4(aPos, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(fragment shader)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;out vec4 FragColor;&#xA;&#xA;in VS_OUT {&#xA;    vec2 TexCoords;&#xA;} fs_in;&#xA;&#xA;in vec2 TexCoords;&#xA;&#xA;uniform sampler2D texture_diffuse1;&#xA;uniform vec3 lightPos;&#xA;uniform vec3 viewPos;&#xA;&#xA;void main()&#xA;{&#xA;    FragColor = vec4(texture(texture_diffuse1, TexCoords).rgb, 1.0); ----(1)&#xA;    //FragColor = vec4(texture(texture_diffuse1, fs_in.TexCoords).rgb, 1.0); ----(2)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I use the code above, the result is as follows&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/A70UG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A70UG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but, instead of (1) pair, if I use the pair (2), then the result is strange.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OjMQb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OjMQb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why it happened?&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2017-12-15T11:30:10.510" Title="What's the difference between two code in shader?" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="5989" PostTypeId="2" ParentId="5988" CreationDate="2017-12-15T11:30:10.510" Score="1" Body="&lt;p&gt;&lt;em&gt;I don't have enough rep to comment :(&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hi,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like with (2), fs_in.TexCoords is == vec2(0.0,0.0). Do you keep both &lt;strong&gt;&lt;em&gt;in VS_OUT {}/ out VS_OUT {}&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;out vec2/in vec2&lt;/em&gt;&lt;/strong&gt; ? If so, it's possible that as both have the same name (TexCoords) the compiler is confused. Try using only one of the two options.&lt;/p&gt;&#xA;" OwnerUserId="7107" LastActivityDate="2017-12-15T11:30:10.510" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="5991" PostTypeId="1" CreationDate="2017-12-15T21:54:40.427" Score="1" ViewCount="84" Body="&lt;p&gt;I am trying to take either a HDR panoramic or HDR cubeMap and from that create a Lambert Irradiance environment map and a Cook-Torrence Specular environment map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am stuck at the proper implementation to get the samples using Hammersley and importance sampling and then placing them on my target image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is essentially a pre-filtering environment maps question in C#&lt;/p&gt;&#xA;" OwnerUserId="7906" LastActivityDate="2017-12-15T21:54:40.427" Title="How to make Convolved Diffuse and Specular image in C#" Tags="&lt;image-processing&gt;&lt;pbr&gt;&lt;image&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5992" PostTypeId="1" AcceptedAnswerId="6001" CreationDate="2017-12-16T00:40:01.720" Score="0" ViewCount="47" Body="&lt;p&gt;So I have this racing game I'm trying to modify that uses lightmaps that fade to transparency for light sources. An example from the game:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9SLZM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9SLZM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been trying to produce a similar effect but with no luck. I've tried blender but that doesn't support transparency off of light sources, if anyone has any program ideas I'd greatly appreciate it! &lt;/p&gt;&#xA;" OwnerUserId="7907" LastActivityDate="2017-12-17T22:08:49.800" Title="What program can bake transparent light maps?" Tags="&lt;lighting&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5994" PostTypeId="1" AcceptedAnswerId="5999" CreationDate="2017-12-16T07:28:26.923" Score="3" ViewCount="1471" Body="&lt;p&gt;I am a bit confused in terms of directional light calculation in OpenGL. Generally we care about the direction of the directional light and we use it with the normal and view (toCamera) vector to calculate lighting. Let's say I do my calculation in view-space ... would I need to multiply the direction of the directional light with ViewMatrix (and then normalize) ? I tried both and they don't seem to make a difference ... I'm leaning towards &quot;yes I need to do that&quot;. Is this correct? Here's part of my fragment shader that does lighting for directional light:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 calculateDirectionalLightIntensities(in vec3 N, in vec3 V)&#xA;{&#xA;    vec4 result = vec4(0.0, 0.0, 0.0, 1.0);&#xA;    for(int i=0; i&amp;lt;DirectionalLightCount; ++i)&#xA;    {&#xA;        //vec3 L = normalize( (ViewMatrix * -vec4(DirectionalLightDirections[i], 0.0)).xyz );&#xA;        vec3 L = normalize(-DirectionalLightDirections[i].xyz);&#xA;        vec4 currentResult = calculateDiffuse(N, L);&#xA;        currentResult += calculateSpecular(N, L, V);&#xA;        currentResult *= DirectionalLightIntensities[i];&#xA;        result += currentResult;&#xA;    }&#xA;    return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Basically N would be the normal vector and V is vector pointing towards camera in view-space and it is calculated as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    normal = normalize(NormalMatrix * vec4(NORMAL, 0.0)).xyz;       //We use 0 because normals are directional vectors&#xA;    uv0 = TEXCOORD0;&#xA;&#xA;    vec4 viewSpacePosition = ModelViewMatrix * vec4(POSITION, 1.0);&#xA;&#xA;#if defined(BLINN_PHONG_LIGHTING)&#xA;&#xA;    toCamera = -viewSpacePosition.xyz; //CALCULATED HERE&#xA;&#xA;#endif&#xA;&#xA;    gl_Position = ProjectionMatrix * viewSpacePosition;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Should I be multiplying my dir of directional light in the vertex shader? If so, is there a performance hit to having multiple lights that results in having array of varying variables being set to the fragment shader?&lt;/p&gt;&#xA;" OwnerUserId="6938" LastActivityDate="2017-12-17T01:25:32.843" Title="Directional Light ViewSpace Calculation" Tags="&lt;opengl&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="5995" PostTypeId="1" AcceptedAnswerId="5998" CreationDate="2017-12-16T17:24:03.753" Score="2" ViewCount="477" Body="&lt;p&gt;This is general question.&#xA;In the multitude of video-games that are not specialized in scoped warfare (like Sniper Elite), I've noticed that when you zoom in with a scope, the textures and normal maps won't &amp;quot;update&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;You're standing on coordinate &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; and the textures will load in full quality to some other &lt;span class=&quot;math-container&quot;&gt;$R^3$&lt;/span&gt; coordinate, let's say &lt;span class=&quot;math-container&quot;&gt;$(10,10,10)$&lt;/span&gt;.&lt;br /&gt;&#xA;If you look through a scope from &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; past the &amp;quot;Max quality&amp;quot; distance, let's say &lt;span class=&quot;math-container&quot;&gt;$(10+n1,10+n2,10+n3)$&lt;/span&gt; (where &lt;span class=&quot;math-container&quot;&gt;$n_i$&lt;/span&gt; is the zoom in factor), the zoomed in textures will not updated as if you were standing on the coordinate &lt;span class=&quot;math-container&quot;&gt;$(n,n,n)$&lt;/span&gt;.&lt;br /&gt;&#xA;The best example is the Fallout 4 scope zoom-in.&lt;br /&gt;&#xA;If you zoom in anywhere, the distant textures to which you zoom in will look washed out.&lt;br /&gt;&#xA;What are the solutions to such problems? Are they engine related? I've just started to dabble in OpenGL and noticed that problem on the multitude of games which share the same game engine.&lt;/p&gt;&#xA;" OwnerUserId="6202" LastEditorUserId="6202" LastEditDate="2021-01-22T20:55:28.677" LastActivityDate="2021-01-22T20:55:28.677" Title="Video-games; Rendering textures on scope zoom-in. Texture compression problem?" Tags="&lt;texture&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="5996" PostTypeId="1" CreationDate="2017-12-16T18:54:29.433" Score="2" ViewCount="456" Body="&lt;p&gt;I'm developing a CAD drawing generator using C# and netdxf library (&lt;a href=&quot;https://github.com/haplokuon/netDxf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/haplokuon/netDxf&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The app first performs boolean operations (specifically - union &amp;amp; subtraction) on polygons and draws the resultant path on .dxf file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using Angus johnson's Clipper library (&lt;a href=&quot;http://www.angusj.com/delphi/clipper.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;Clipper - an open source freeware polygon clipping library | angusj.com&lt;/a&gt;) for clipping &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Everything works fine for polygons, The problem is when I need to clip circles and polygons, the result is a large list of points (representing the path of the figure to be drawn on dxf)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the curved portion of the path is composed of tiny segments, which is a big problem for the CAM software that'd be used later. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is such an image (the result of clipping circle and polygon). The grey portion is full of tiny line segments&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NioSC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NioSC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Questions - &lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) How can I convert those tiny line segments to circles/arcs using the list of points?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Can I take a completely different approach to avoid this problem?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7412" LastEditorDisplayName="user7220" LastEditDate="2018-04-18T18:41:42.127" LastActivityDate="2021-04-03T14:04:25.483" Title="Clipping circle and polygon and generate a CAD drawing" Tags="&lt;polygon&gt;&lt;clipping&gt;&lt;cad&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="5998" PostTypeId="2" ParentId="5995" CreationDate="2017-12-17T00:59:28.990" Score="4" Body="&lt;p&gt;Well there's no way to know for sure unless you look at the source code but my guess is that they do zooming by lowering the FOV (field of view) of the camera. This is easy to implement and actually sort of represents how a real scope works (in the way that light rays are bent through an optical lens). A zoom effect where you change the actual position of the camera might be more trouble than its worth. What if there is an object between the player and the desired camera position? So as you can see, the camera position has not changed at all and so there is no reason the textures would update when zooming.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you would think that hey maybe they could just scale the distance required to trigger the higher detail textures as the player zooms in but this may or may not be easy depending on how that is implemented in the engine. The game developers may not even be able to change LOD (level of detail) distances dynamically. Like you said, games like sniper elite which are based all around sniping have dealt with this but general purpose game engines might not have this functionality.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also you have to consider possible popping effects. If you zoom in to an area and suddenly the textures and meshes update dramatically, this would look very bad. This gets even worse if the zoom effect is gradual or the sight is adjustable. I would even go as far as to say that it might be preferable to have lower quality textures than to have really bad popping.&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-17T00:59:28.990" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="5999" PostTypeId="2" ParentId="5994" CreationDate="2017-12-17T01:25:32.843" Score="3" Body="&lt;p&gt;It just depends on which space your light directions are actually specified in. You compute both your normal and view vector correctly in view space in order to perform your lighting computations in view space. So &lt;strong&gt;you need your normalized light direction in view space&lt;/strong&gt;, too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it depends on how you actually transfer your light direction into the shader. Usually it's best to &lt;strong&gt;transform the light direction into view space before uploading it to the shader&lt;/strong&gt; (from whatever space it's originally in in the scene, likely some kind of object space local to a certain light source, but in case of a directional light maybe already in world/view space). This has a few advantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;As you realized yourself already, you won't have to perform a tedious matrix transformation for each and every vertex when the light is actiually constant for all vertices of a draw call (it's probably a &lt;code&gt;uniform&lt;/code&gt; variable). While a matrix multiplication per-vertex doesn't really kill anyone, there's really no need to do that extra work, in contrast to simply transforming the light direction on the CPU once a frame.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;But there's another problem to transforming it in every shader call. Usually your light direction isn't easily specified in object space at all (or not the local object space of whatever object your currently drawing). If anything, it comes from a local light source that has its &lt;em&gt;own&lt;/em&gt; model transformation, but that is &lt;em&gt;not&lt;/em&gt; the one encapsulated in the current modelview matrix, which usually depends on the model you're drawing. So using the modelview matrix you transform your vertices with is most likely the wrong way. You could use the view matrix (as you do) if it is specified in world space already, but as said above, that's usually not necessary.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So what you do &lt;strong&gt;depends on the space in which your light direction is stored&lt;/strong&gt; in the scene. If it is stored in world space (e.g. the sun as the directional light example par-excellence), you just have to transform it into view space (e.g. by multiplying it with the camera/view matrix) right before uploading it into the shader (i.e. likely each frame, since it's view dependent). If it is actually view &lt;em&gt;independent&lt;/em&gt; (e.g. a kind of &quot;flashlight&quot; always shining straight into the camera direction), you don't really have to transform it at all. And if it's local to some specific scene object (more appropriate for point light sources, though), you transform it by &lt;em&gt;that object&lt;/em&gt;'s modelview matrix.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2017-12-17T01:25:32.843" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6000" PostTypeId="2" ParentId="5996" CreationDate="2017-12-17T21:59:40.770" Score="0" Body="&lt;p&gt;I don't know how the clipping library you are using returns the clipped objects, but if I understand your question, you want a way to represent your circles that does not use much memory? If you are only using perfect circles (and not ellipses) you could represent each arc segment as simply an origin point, a radius, and a start/stop angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the part where it would be helpful to know what the clipping library returns. If it returns a chain of points as a separate object for each clipped arc segment, and you already know the radius and center of the circle (from before clipping), you could take the first and last point in the returned chain and compute the angle for each.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;atan2(x - origin.x, y - origin.y)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then when you would like to draw the thing, you can write and algorithm to trace the arc going from the start to stop angle. If you want to do further clipping, you could recreate the arc as a chain of points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Be careful about whether the returned segment was clockwise or counterclockwise.&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-17T21:59:40.770" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6001" PostTypeId="2" ParentId="5992" CreationDate="2017-12-17T22:08:49.800" Score="0" Body="&lt;p&gt;Not sure what sort of lightmaps are produced by blender. Perhaps if you can get it to render a non-transparent lightmap (for example one that has all the colours you want but on a black background), you could then use a program to remove all of the black. I believe GIMP and Photoshop both have a colour to alpha tool. Be sure to pick a background colour that will not be the same colour as any of the lights.&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-17T22:08:49.800" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6002" PostTypeId="1" AcceptedAnswerId="6004" CreationDate="2017-12-18T01:52:36.257" Score="2" ViewCount="352" Body="&lt;p&gt;I'm writing an OpenGL application that runs on a Raspberry Pi, i.e., a quite resource-limited system. Essentially, a few quads with RGBA textures are overlayed/alpha blended on top of each other with individual translation/rotation applied. They are clipped against an unrotated rectangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this purpose, I currently use the stencil buffer. I.e., when drawing a texture which requires clipping, I clear the stencil buffer, render the clipping quad to the stencil buffer and enable the stencil testing before rendering the translated/rotated object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a Pi, clearing the stencil buffer is a painfully slow process in the order of 20ms, completely ruining performace. I thought about pre-rending the clipping rects to different bits of the stencil buffer, but that would lead to a maximum of 8 clipping regions (I need more).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, is there a different way of achieving clipping against a simple rectangle that does not require an expensive operation such as flushing the stencil buffer?&lt;/p&gt;&#xA;" OwnerUserId="7915" LastActivityDate="2017-12-18T09:54:06.533" Title="Fast clipping without clearing stencil buffer" Tags="&lt;opengl&gt;&lt;clipping&gt;&lt;legacy-opengl&gt;&lt;stencil-test&gt;&lt;stencil-buffer&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6003" PostTypeId="1" CreationDate="2017-12-18T03:18:07.663" Score="1" ViewCount="60" Body="&lt;p&gt;I want to extend the following to work on a solid angle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose we have a volume filled with small surfaces.  If we cast a ray from a given point, the probability that the ray will not hit a surface (i.e. is visible to the sky) is given as &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$P(ray\ does\ not\ hit) = {e}^{-\alpha d/\cos\theta}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $\alpha$ is some decay factor, $d/cos\theta$ is the path length of the ray within the volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My question:&lt;/strong&gt;&lt;br&gt;&#xA; How can we compute the expected visibility of a ray if we consider the directions $(\theta, \phi)$, where $0&amp;lt;\theta&amp;lt;\pi/2$ and $0&amp;lt;\phi&amp;lt;2\pi$?&lt;/p&gt;&#xA;" OwnerUserId="5183" LastEditorUserId="5183" LastEditDate="2017-12-19T19:31:27.390" LastActivityDate="2017-12-21T04:15:02.363" Title="Expected visibility" Tags="&lt;ambient-occlusion&gt;&lt;ray&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6004" PostTypeId="2" ParentId="6002" CreationDate="2017-12-18T05:02:41.307" Score="1" Body="&lt;p&gt;It sounds like what you need is a &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Scissor_Test&quot; rel=&quot;nofollow noreferrer&quot;&gt;scissor test&lt;/a&gt;. It's specifically designed for clipping against an unrotated rectangle, and should be faster than messing about with the stencil buffer.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2017-12-18T05:02:41.307" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6005" PostTypeId="2" ParentId="6002" CreationDate="2017-12-18T05:35:40.620" Score="0" Body="&lt;p&gt;You could try clipping the polygons in code before you send them off to the renderer. Then you could avoid the stencil buffer entirely. To do this you could clip against all sides of the rectangle one at a time. I can't say for sure if this is faster than what you were doing before but here goes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this algorithm you need to represent a polygon as a list of points&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to clip against one side:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;# careful of array out of bounds access&#xA;k = -1&#xA;# find first instance where a vertex is outside followed by one that is inside&#xA;for(i = 0; i &amp;lt; verts.length; ++i)&#xA;    if(isOutside(verts[i]) &amp;amp;&amp;amp; !isOutside(verts[i + 1]))&#xA;        k = i&#xA;# if no such instance found&#xA;if(k == -1)&#xA;    if(isOutside(verts[0])) # entire thing outside&#xA;        return empty array&#xA;    else # entire thing inside&#xA;        return verts # return unchanged&#xA;# if instance was found&#xA;else&#xA;    newVerts = empty array&#xA;    # add first vertex in new shape&#xA;    newVerts.add(intersect(verts[k], verts[k + 1]))&#xA;    # walk the part of the polygon that is inside&#xA;    while(!isOutside(verts[++k]))&#xA;        newVerts.add(verts[k])&#xA;    # add last vertex in new shape&#xA;    newVerts.add(intersect(verts[k - 1], verts[k]))&#xA;    return newVerts&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then you could do something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;poly = clipLeftEdge(poly)&#xA;poly = clipRightEdge(poly)&#xA;poly = clipTopEdge(poly)&#xA;poly = clipBottomEdge(poly)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the the original polygon was convex then the new one should be as well which means you could triangulate it or whatever you need before you draw.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A line which forms an edge of the clipping rectangle (if you extend it to be infinitely long) splits the entire space into 2 half spaces. You will need to provide a function to check whether a vertex is in the &quot;inside&quot; half space or the &quot;outside&quot; half space. Ex: left edge of rectangle is at x = -15. To check if the point is outside, do (point.x &amp;lt; -15).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You will also need to provide a function to intersect 2 vertices. You have one vertex on the outside and one on the inside and somewhere in between there is a line that you want to clip against. For example if the left edge of the rectangle is at x = -15:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;factor = (-15 - p1.x)/(p2.x - p1.x)&#xA;newVertex.x = -15&#xA;newVertex.y = (p2.y - p1.y)*factor + p1.y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You will also need to linearly interpolate all other attributes you care about (like texture coordinates).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to be really slick, you can write the clipping algorithm once and provide an appropriate isOutside and intersect function for each run.&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-18T05:35:40.620" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6006" PostTypeId="1" AcceptedAnswerId="6014" CreationDate="2017-12-18T08:00:32.367" Score="1" ViewCount="258" Body="&lt;p&gt;Here's an example of the &lt;a href=&quot;https://wikipedia.org/wiki/File:Phong-shading-sample.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;flat shaded&lt;/a&gt; squares I want. But my squares are made of two triangles, and I'm getting flat shading of those &lt;em&gt;triangles&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7UNuF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7UNuF.jpg&quot; alt=&quot;from wiki article on phong shading&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In openGLES 3.1 (android), I'm turning off interpolation in the fragment shader, and using the provoking vertex (or using the centroid/average), to get the same &quot;low-poly&quot; lighting throughout a tri. The specular calculation is done in the vertex shader, so it's only done once.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a flat sea, a mesh of squares (two triangles per quad), with a specular reflection of the sun. But instead of each square being lit the same, the two triangles forming a square get different specular values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I worked out it's because the tris are at different locations. Although the sun's rays are parallel (with the same angle of incidence at all locations), the angle between each tri and the &lt;em&gt;viewer&lt;/em&gt; is slightly different, depending on where the tri is relative to the viewer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/X9oGg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X9oGg.png&quot; alt=&quot;[Introduction to Computer Graphics, *David J. Eck*](http://math.hws.edu/graphicsbook/c4/s1.html)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;This diagram (&lt;a href=&quot;http://math.hws.edu/graphicsbook/c4/s1.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Intro to Computer Graphics&lt;/em&gt;, David J. Eck&lt;/a&gt;) only shows the light from one point, for observers at different locations, but you can see that light from different points would produce a shifted cone, having a similar effect on an observer at one place.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;A brute force solution would be to store a special &quot;location&quot; for each vertex of each tri, and set &quot;location&quot; to the same value for each of the 4 verices of the two tris forming the square.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But that's inefficient, and I'm using a STRIP for the mesh. I don't think this brute force solution work, because any &lt;em&gt;per vertex&lt;/em&gt; data would be used by the 4 squares sharing that vertex, wouldn't they? Or can you have &lt;em&gt;per tri&lt;/em&gt; data?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt; I currently have &lt;em&gt;per vertex&lt;/em&gt; normals - used in the specular calc - and only the normal of the provoking vertex is used for a tri. This works out as &lt;em&gt;per tri&lt;/em&gt;, since only one tri is provoked by each vertex. I could give the same &quot;location&quot; to both tris in a quad this way. But it's still brute force - is there a better way?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Or, can you tell which tri of a quad you're in, so you can decide what it's &quot;location&quot; should be?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems so simple, but doesn't fit with openGL ES's approach... is there a way to do it? Note it's openGL ES 3.1 (mobile).&lt;/p&gt;&#xA;" OwnerUserId="5545" LastEditorUserId="5545" LastEditDate="2017-12-19T04:44:56.920" LastActivityDate="2017-12-19T04:44:56.920" Title="Same specular lighting on both tris in a quad (for &quot;low-poly&quot; &quot;flat shading&quot; look)?" Tags="&lt;shader&gt;&lt;mesh&gt;&lt;specular&gt;&lt;opengl-es&gt;&lt;android&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6007" PostTypeId="2" ParentId="6002" CreationDate="2017-12-18T09:54:06.533" Score="0" Body="&lt;p&gt;As per &lt;a href=&quot;https://computergraphics.stackexchange.com/a/6004/209&quot;&gt;Russ's answer&lt;/a&gt;, I'd also suggest using scissor rectangles but, on the off-chance that is also slow, is it possible to use the Z buffer to set the Z to &quot;near&quot; in the regions you don't want drawn? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, it would be useful to have an example image.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2017-12-18T09:54:06.533" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6008" PostTypeId="1" AcceptedAnswerId="6018" CreationDate="2017-12-18T10:47:13.770" Score="2" ViewCount="111" Body="&lt;p&gt;I'm rendering fonts using Cairo to surfaces, convert those surfaces to RGBA textures and then display them on GL_QUADS using orthotogonal projection and alpha blending. When I use Cairo to render directly to the window (i.e., without hardware acceleration), fonts look perfect. When I show them through OpenGL, they look &quot;thinned&quot;. Example: &lt;a href=&quot;https://imgur.com/a/J7IvG&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://imgur.com/a/J7IvG&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My texture sizes are powers of two and I do not currently use any scaling (i.e., use the texture coordinates to only show the portion of the texture that actually contains data). I've also tried using the full texture and scaling in the Cairo drawing matrix (i.e., upscaling by Cairo, downloading by OpenGL) which looks even worse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe this has something to do with GL's interpolation, but cannot seem to figure out why it is. When I disable the bilinear GL_LINEAR texture interpolation to GL_NEAREST, they look even worse (and blocky, as if it'd ignore the alpha channel). What can I do to make my font textures look more true to their original?&lt;/p&gt;&#xA;" OwnerUserId="7915" LastEditorUserId="7915" LastEditDate="2017-12-18T11:27:28.713" LastActivityDate="2017-12-20T04:19:18.693" Title="Fonts rendered through textures look thinned" Tags="&lt;opengl&gt;&lt;legacy-opengl&gt;&lt;font-rendering&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="6009" PostTypeId="1" CreationDate="2017-12-18T18:22:59.053" Score="0" ViewCount="1034" Body="&lt;p&gt;I convert RGB input to YUV 420 semi-planar output using compute shader.Luma plane is straightforward as it maps 1:1 with RGB dimensions. As we know, &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;NV12 packs Cb&lt;/a&gt; and Cr into one plane, which means the CbCr values must be calculating from downsampled (x4) source.And this is the part I am not completely sure I am doing right. I currently try subsampling with simple bileanar filtering.And it 'almost' looks right.I uses t&lt;a href=&quot;https://blog.demofox.org/2015/08/15/resizing-images-with-bicubic-interpolation/&quot; rel=&quot;nofollow noreferrer&quot;&gt;his article&lt;/a&gt; as reference.It is possible that my code is 100% correct and the aliasing stems from compression losness. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my part of shader code that samples from RGB texture and writes U and V values:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ivec2 itexSize =textureSize(rbga_tex,0);&#xA;vec2 texSize =  vec2(itexSize);&#xA;vec2 texelSize = 1.0 / (texSize / 2.0);&#xA;vec2 pixel = uv * texSize + 0.5;&#xA;pixel = (floor(pixel) / texSize) - vec2(texelSize/2.0);&#xA;&#xA;//bilinear filtering:&#xA;float sc = 4.0;&#xA;vec3 ts = texture(rbga_tex,pixel).rgb * 0.25; // center&#xA;vec3 tr = texture(rbga_tex,pixel + vec2(texelSize.x * sc, 0.0)).rgb  * 0.25;&#xA;vec3 bl = texture(rbga_tex,pixel + vec2(0.0, texelSize.y * sc)).rgb * 0.25;&#xA;vec3 br = texture(rbga_tex,pixel + vec2(texelSize.x,texelSize.y) * sc).rgb * 0.25;&#xA;&#xA;vec3 tex1 = (ts + tr + bl + br) ;&#xA;&#xA;// calculate and write U...&#xA;&#xA;// calculate and write V...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the original rgb image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lQ7Og.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lQ7Og.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is the snapshot of the video frame after the conversion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8lm8a.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8lm8a.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So here are my questions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;a)I would like to understand if there is something I am doing wrong, and if possible to get a concise explanation on how subsampling should be done when converting from rbg to yuv420 color space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;b)If this result is correct, are there ways to get smoother effect while keeping overall sharpness?I understand that using bicubic filter we can get smoother visuals but at cost of image sharpness.&lt;/p&gt;&#xA;" OwnerUserId="213" LastEditorDisplayName="user7220" LastEditDate="2018-03-04T00:38:38.313" LastActivityDate="2018-03-04T00:38:38.313" Title="YUV (NV12) Chroma subsampling while converting from RGB image" Tags="&lt;texture&gt;&lt;gpu&gt;&lt;sampling&gt;&lt;filtering&gt;&lt;video&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="6010" PostTypeId="2" ParentId="6006" CreationDate="2017-12-18T18:30:18.777" Score="0" Body="&lt;p&gt;The easiest fix would be to do your light calculations in the fragment shader rather than per-vertex—you’ll avoid the discontinuity you’re currently seeing and your lighting will appear more natural (while still fitting the “low-poly” aesthetic). If that’s not an option, then you’re probably stuck with passing in each quad’s center along with the normals you’re already supplying.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2017-12-18T18:30:18.777" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6011" PostTypeId="2" ParentId="6006" CreationDate="2017-12-18T20:22:35.983" Score="0" Body="&lt;p&gt;You are probably mixing thing up. As I understood from you explanation, you are trying to do Phong shading and you want flat shading. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your problem might be happening because you are calculating a specular component that depends on the view/camera direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would help if you could add pictures explaining what is happening and what you want to happen.&lt;/p&gt;&#xA;" OwnerUserId="7289" LastActivityDate="2017-12-18T20:22:35.983" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6012" PostTypeId="1" CreationDate="2017-12-18T21:08:13.860" Score="2" ViewCount="895" Body="&lt;p&gt;I'm trying to get a 2D screen position so I unproject a point from 3D into 2D screen coordinates by that following function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Ogre::Vector2 SpaceTransformHelper::convertWorldToScreenPosition( const Ogre::Vector3&amp;amp; worldPosition )&#xA;{&#xA;    Stages::AStage* currStage = Stages::StageManager::getSingleton()-&amp;gt;getActiveStage();&#xA;    Core::Resolution screenRes = Core::EnvironmentInformation::getSingleton()-&amp;gt;getScreenResolution();&#xA;&#xA;    // Get worldviewprojection from camera.&#xA;    Ogre::Matrix4 worldViewProjection = currStage-&amp;gt;getActiveCamera()-&amp;gt;getCameraViewProjectionMatrix();&#xA;&#xA;    // Transform world coordinates.&#xA;    Ogre::Vector3 transformedWorldPosition = worldViewProjection * worldPosition;&#xA;&#xA;    // Calculate screen coordinates from world coordinates.&#xA;    Ogre::Vector2 screenPosition;&#xA;    screenPosition.x = (int) ( ( ( transformedWorldPosition.x + 1 ) / 2.0 ) * screenRes.width + 0.5 );&#xA;    screenPosition.y = (int) ( ( ( 1 - transformedWorldPosition.y ) / 2.0 ) * screenRes.height + 0.5 );&#xA;&#xA;    return screenPosition;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now I want to convert that screenPosition into Image space to crop an image:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Core::Resolution screenRes = Core::EnvironmentInformation::getSingleton()-&amp;gt;getScreenResolution();&#xA;float screenPositionX = (screenPosition.x / screenRes.width) * (pixelBuffer-&amp;gt;getWidth());&#xA;float screenPositionY =  (screenPosition.y / screenRes.height) * (pixelBuffer-&amp;gt;getHeight());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/p4c3n.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/p4c3n.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I click on the mobile screen on the Green LED I get that cropped image.. but what I want is to only crop that green led.. Is there a problem with the transformation ?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  const Core::Resolution cameraRes = Core::EnvironmentInformation::getSingleton()-&amp;gt;getCameraResolutionUpLoad( plane );&#xA;    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture[plane]-&amp;gt;getBuffer( 0, 0 );&#xA;&#xA;    viewarassert( screenPosition.x &amp;lt; cameraRes.width || screenPosition.x &amp;gt;= 0 || screenPosition.y &amp;lt; cameraRes.height || screenPosition.y &amp;gt;= 0 );&#xA;&#xA;   Core::Resolution screenRes = Core::EnvironmentInformation::getSingleton()-&amp;gt;getScreenResolution();&#xA;   std::pair&amp;lt; Ogre::Vector2, Ogre::Vector2 &amp;gt; uvBounds = calculateSingleViewTextureCoordinates();&#xA;&#xA;    float screenPositionX = cameraRes.height - (screenPosition.x / screenRes.width) * ((int)pixelBuffer-&amp;gt;getHeight());&#xA;    float screenPositionY=  cameraRes.width -  (screenPosition.y / screenRes.height) * ((int)pixelBuffer-&amp;gt;getWidth());&#xA;&#xA;    int  min_x = std::max( 0,(int)screenPositionX - radius);&#xA;    int  min_y = std::max( 0,(int)screenPositionY - radius);&#xA;    int  max_x = std::min( (int)cameraRes.width, (int) screenPositionX + radius );&#xA;    int  max_y = std::min( (int)cameraRes.height, (int) screenPositionY+ radius );&#xA;&#xA;    // Get the pixelbox within the radius.&#xA;    pixelBuffer-&amp;gt;lock(Ogre::HardwareBuffer::HBL_READ_ONLY);&#xA;    const Ogre::PixelBox &amp;amp;readrefpb = pixelBuffer-&amp;gt;getCurrentLock();&#xA;&#xA;    unsigned char *readrefdata = static_cast&amp;lt;unsigned char*&amp;gt;(readrefpb.data);&#xA;&#xA;    Ogre::Image img;&#xA;    img = img.loadDynamicImage (readrefdata, pixelBuffer-&amp;gt;getWidth(),&#xA;                                pixelBuffer-&amp;gt;getHeight(), pixelBuffer-&amp;gt;getFormat());&#xA;    img = img.flipAroundY();&#xA;&#xA;    Ogre::Image *out = cropImage(img,  min_x, min_y,  max_x,  max_y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7918" LastEditorUserId="7918" LastEditDate="2017-12-19T11:59:20.873" LastActivityDate="2018-10-15T19:00:31.637" Title="I'm trying to get a 2D screen position so I unproject a point from 3D into 2D screen coordinates by that following function:" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6013" PostTypeId="2" ParentId="6012" CreationDate="2017-12-18T22:39:35.610" Score="0" Body="&lt;p&gt;From what I can see, it looks like screenPosition.x is in some sort of screen space and screenPositionX is in terms of the actual pixel buffer in units of pixels. My guess is that cropImage wants its inputs in units of pixels but when you calculate min_x, min_y, ... you are using screenPosition.x when you should really be using screenPositionX. Also, where does radius come from? Is it in world space, screen space, or pixel buffer space?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regardless of whether or not that fixes your problem, try to be more explicit in the future about your variables names to keep track of which space/units you are in. Having a screenPosition.x and a screenPositionX which refer to different things is generally a bad idea.&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-18T22:39:35.610" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6014" PostTypeId="2" ParentId="6006" CreationDate="2017-12-19T03:46:27.520" Score="1" Body="&lt;p&gt;If I understand you correctly, the problem is that the provoking vertex isn't the same vertex between the two triangles in a quad, due to using triangle strips. You could switch to using an indexed triangle list, and set up indices in such a way that the provoking vertex is the same in each quad. For instance, if one quad is vertices {0, 1, 2, 3} (CCW) then you might write {0, 1, 2, 3, 0, 2} in your index buffer so that 2 is the provoking vertex for both triangles. This should still be pretty efficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another possibility (more involved, but more flexible) is to use the built-in &lt;a href=&quot;http://docs.gl/el3/gl_VertexID&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;gl_VertexID&lt;/code&gt;&lt;/a&gt; variable in your vertex shader to figure out which quad you're in (eg &lt;code&gt;int quadID = gl_VertexID / 4&lt;/code&gt;), and use an appropriate shading location for that quad—the centroid of its vertices, for instance. However, for this to work, I think you would have to &quot;un-share&quot; the vertices so that each quad has its own 4 unique vertices (the two triangles in a quad can still share). So you would have to use primitive restarting, or again switch to indexed non-strip draws. You could also have per-quad data in an SSBO that you manually fetch using your computed quad index.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2017-12-19T03:46:27.520" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="6015" PostTypeId="1" AcceptedAnswerId="6016" CreationDate="2017-12-19T10:22:52.117" Score="0" ViewCount="137" Body="&lt;p&gt;I am working on a specific blur effect that implies several behaviours. But before I would like to know what you think about those blurring algorithms according to performances and quality :&#xA;&lt;strong&gt;Kawase blur&lt;/strong&gt;, &lt;strong&gt;Box blur&lt;/strong&gt; and &lt;strong&gt;two pass Gaussian blur&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next are the effects I am currently working on and I would be glad to have your thoughts on those on the proper way to achieve this. Here is a schematic view followed by my questions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eCwIX.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eCwIX.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I would like to blur the content of those 4 spheres using the same offset no mater their position. If I apply the same blur on all objects, far object's content will appear more blurry than ones on the foreground and I want to avoid that. I think that the depth make could help but any precision would help me.&lt;/li&gt;&#xA;&lt;li&gt;If I blur the whole image and apply the result on the sphere, the white background will bleed onto the sphere shape and I want to avoid that. I also don't want that the blue (3) and yellow (4) sphere merges with the red (1) and green (2) ones. But I would like that the green and red ones merges. Again This could be done using the depth but if you have more precision about how to do it it would be interesting.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Any ideas about those questions would be helpful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2017-12-19T10:45:50.210" Title="Questions about Blur effect" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;gaussian-blur&gt;&lt;blur&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6016" PostTypeId="2" ParentId="6015" CreationDate="2017-12-19T10:45:50.210" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;If I blur the whole image and apply the result on the sphere, the white background will bleed onto the sphere shape and I want to avoid that. I also don't want that the blue (3) and yellow (4) sphere merges with the red (1) and green (2) ones. But I would like that the green and red ones merges. Again This could be done using the depth but if you have more precision about how to do it it would be interesting.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You will need to blurr in multiple passes to achieve this:&#xA;once for the blue and once for the yellow, as well as once for the red and green (together). That is: you need to render to texture, you need three textures in this instance to render to, you need to blur the individual textures and then combine them in another render pass.&#xA;If you know beforehand that the green and red spheres may blur together, you can just hardcode it, otherwise you need to come up with a way of determining, which spheres may blur together, and group your spheres to render into the same texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do this, keep in mind that for combining the three individual blurred textures, you need z-values for correct visibility determination.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I would like to blur the content of those 4 spheres using the same offset no mater their position. If I apply the same blur on all objects, far object's content will appear more blurry than ones on the foreground and I want to avoid that. I think that the depth make could help but any precision would help me.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, you can scale your blur filter with a depth value (where you should &quot;invert&quot; the value to make the blurriness scale to larger effects on closer proximities, i.e. smaller depths). For a box filter, you take ratios of the pixels neighbourhoods, but you need to make sure that those ratios add up to one. For this, you'd ideally increase the ratio for the center pixel based on the proximity and reduce the ratio for the neighbouring pixels accordingly.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;performances and quality : Kawase blur, Box blur and two pass Gaussian blur.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As to performance, I can't say anything about the three. As to quality, the Box Filter is rather simple, but that doesn't mean it doesn't suffice for your specific need. Just test them against each other.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2017-12-19T10:45:50.210" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6018" PostTypeId="2" ParentId="6008" CreationDate="2017-12-20T04:19:18.693" Score="3" Body="&lt;p&gt;From looking at your example images this looks like a case of Alpha blending being applied to the RGB channel of the font-atlas texture and then again applied via the A channel when rendering. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The tell-tale sign of this is usually a feint dark halo surrounding your glyphs which is caused by the unwanted mid-greys present in the texture being multiplied by alpha.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For font rendering it is typical to have anti-aliasing in the A channel and have your RGB channels a constant colour. &lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2017-12-20T04:19:18.693" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6019" PostTypeId="1" CreationDate="2017-12-20T12:23:04.700" Score="6" ViewCount="388" Body="&lt;p&gt;I wrote a simple Phong shader with two directional lights for a project, and noticed an unpleasant artifact in the lighting. Where both lights are illuminating the same region, dark bands appear at the light terminators where N.L reaches zero. At first I thought it must be a bug in my code, but a quick test revealed the Unity standard shader has the exact same problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RKu8H.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RKu8H.png&quot; alt=&quot;my shader&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YJesJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YJesJ.png&quot; alt=&quot;unity shader&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My best guess is that this is some form of the Mach effect, and our retinas are overshooting where the brightness plateaus. Does anyone know any tricks to mitigate this effect?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT FOR CLARITY:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are two more images to illustrate the effect better - one with my shader, and one with Unity's diffuse shader, with the lights at 90 degrees and all specular and ambient contributions removed. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Dyaw5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Dyaw5.png&quot; alt=&quot;mine&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/T5PCZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/T5PCZ.png&quot; alt=&quot;unity&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can clearly see the dark bands around the top right quadrant where one light's terminator intersects the other's area of effect (well, I can anyway, YMMV). I've run an eyedropper over it and confirmed it's a perceptual effect, the pixels do not in fact get darker.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="5778" LastEditDate="2018-12-05T21:41:28.770" LastActivityDate="2018-12-05T21:41:28.770" Title="Avoiding Mach band effect when using multiple lights" Tags="&lt;shader&gt;&lt;artifacts&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6020" PostTypeId="1" CreationDate="2017-12-20T14:12:10.737" Score="1" ViewCount="405" Body="&lt;p&gt;I'm trying to outline a 3D model in WebGL. I've tried using a stencil buffer techique with glLineWidth and glPolygonMode. However, Mozilla's WebGL reference says that the minimum and maximum widths of lines are 1 (therefore can't be modified). I've tried it using it without glLineWidth and just use wireframe mode.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (let i = 0; i &amp;lt; node_to_display.leaves.length; i++) {&#xA;&#xA;    if (node_to_display.pickable) {&#xA;        this.scene.gl.enable(this.scene.gl.STENCIL_TEST);&#xA;        this.scene.gl.clearStencil(0);&#xA;        this.scene.gl.clear(this.scene.gl.STENCIL_BUFFER_BIT);&#xA;        this.scene.gl.stencilFunc(this.scene.gl.ALWAYS, 1, -1);&#xA;        this.scene.gl.stencilOp(this.scene.gl.KEEP, this.scene.gl.KEEP, this.scene.gl.REPLACE);&#xA;        node_to_display.leaves[i].primitive.primitiveType = this.scene.gl.TRIANGLES;&#xA;    }&#xA;&#xA;    node_to_display.leaves[i].display(); //Display leaves&#xA;&#xA;    if (node_to_display.pickable) {&#xA;        this.scene.activeShader.setUniformsValues({ outline_color: [1, 0, 0, 1] });&#xA;&#xA;        this.scene.gl.stencilFunc(this.scene.gl.NOTEQUAL, 1, -1);&#xA;        this.scene.gl.stencilOp(this.scene.gl.KEEP, this.scene.gl.KEEP, this.scene.gl.REPLACE);&#xA;        node_to_display.leaves[i].primitive.primitiveType = this.scene.gl.LINES;&#xA;        node_to_display.leaves[i].display();  //Display leaves in wireframe&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However this is the result I'm getting:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ggcAK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ggcAK.png&quot; alt=&quot;Model Outline&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with this result is that the wireframe still shows where there is a triangle mesh &quot;behind it&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[EDIT] The result I'm looking for is something like this: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WApve.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WApve.png&quot; alt=&quot;Example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7925" LastEditorUserId="7925" LastEditDate="2017-12-20T14:48:31.660" LastActivityDate="2017-12-20T14:48:31.660" Title="3D model outline using stencil buffer" Tags="&lt;webgl&gt;&lt;javascript&gt;&lt;model&gt;&lt;stencil-buffer&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6021" PostTypeId="1" AcceptedAnswerId="6032" CreationDate="2017-12-20T17:00:32.510" Score="2" ViewCount="1530" Body="&lt;p&gt;By default, the eye an the projection reference point PRP are in (0,0,0). I can change the eye position with gluLookAt(), but how can I change the PRP (i.e., the  convergence position for a set of parallel lines) for a perspective projection in OpenGL?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/9QdUj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9QdUj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VrYBF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VrYBF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7929" LastEditorUserId="7929" LastEditDate="2018-01-05T11:20:05.580" LastActivityDate="2018-03-07T11:54:31.937" Title="Changing the projection reference point in Open GL" Tags="&lt;opengl&gt;&lt;perspective&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6022" PostTypeId="1" AcceptedAnswerId="6026" CreationDate="2017-12-21T01:01:33.720" Score="0" ViewCount="186" Body="&lt;p&gt;I'am curious about compute shader in OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume the number of points (vec4) is 900&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and  the work group size(= the number of work items) is 256&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, We would have four work groups because 900/256 = 3.xx, so need to plus 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code is as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDispatchCompute(4, 1, 1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and shader is as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;&#xA;layout(std430, binding = 0) buffer Particles {&#xA;    vec4 partices[];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In this case, I wonder how to work fourth work group.&#xA;In my thought, the fourth work group have overflow problem because the total number of points is 900.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do we need to deal exceptional case(overflow)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if idex &gt; total num, then 'pass'&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Opengl deals this problem automatically? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(ex, There is no problem situation.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to check by myself. Even though I make overflow situation, there was no warning.&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2017-12-21T15:28:16.737" Title="Process of compute shader in OpenGL" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;gpu&gt;&lt;compute-shader&gt;&lt;gpgpu&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6023" PostTypeId="2" ParentId="5968" CreationDate="2017-12-21T03:37:31.990" Score="0" Body="&lt;p&gt;Normally $sin(\theta)$ isn't written as part of the pdf, because it's an artifact from using double integral for spherical integration. The double integral does the integration over a rectangular domain (in you case of size $2\pi$ x $\pi/2$), while you want integration over a sphere/hemisphere, so $sin(\theta)$ is added there as a weight function to transform rectangular to spherical integration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A common notation is to use integration over solid angle with single integral and differential solid angle $d\omega$ denoting 2D integration over sphere, and you won't see the $sin(\theta)$ term in there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify, the notation with single integral has constant infinitesimally small solid angle $d\omega$ over the sphere. However, for the double integral over $\theta$ and $\phi$ the solid angle isn't constant (think of &lt;a href=&quot;https://en.wikipedia.org/wiki/Sphere#/media/File:Sphere_wireframe_10deg_6r.svg&quot; rel=&quot;nofollow noreferrer&quot;&gt;sphere tessellation&lt;/a&gt;) but a function of $sin(\theta)$. In case of Monte Carlo integration and even distribution of samples over the hemisphere, each sample represents solid angle of $2\pi/N$ steradians and there's no $sin(\theta)$ solid angle weighting required.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastEditorUserId="1952" LastEditDate="2017-12-22T04:51:00.597" LastActivityDate="2017-12-22T04:51:00.597" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6024" PostTypeId="2" ParentId="6003" CreationDate="2017-12-21T04:15:02.363" Score="1" Body="&lt;p&gt;You need to perform integration of $P$ over the hemisphere to &lt;a href=&quot;https://www.wolframalpha.com/input/?i=Integrate%5BExp%5B-alpha%2FCos%5Btheta%5D%5D*sin%5Btheta%5D,%20%7Btheta,%200,%20pi%2F2%7D,%20%7Bphi,%200,%202pi%7D%5D&quot; rel=&quot;nofollow noreferrer&quot;&gt;calculate the solution&lt;/a&gt;. There doesn't seem to be closed-form solution as the solution requires &lt;a href=&quot;https://en.wikipedia.org/wiki/Incomplete_gamma_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;incomplete gamma function&lt;/a&gt;:&#xA;$$2\pi(e^{-\alpha d}-\alpha d\Gamma(0,\alpha d))$$&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2017-12-21T04:15:02.363" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6026" PostTypeId="2" ParentId="6022" CreationDate="2017-12-21T15:28:16.737" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;The Opengl deals this problem automatically? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;How could it? At no point do you inform OpenGL that you only want 900 invocations. You have exactly 2 mechanisms to control the number of invocations: the work group size in the shader, and the work group count in the dispatch call. That determines how many invocations there are.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want a variable number of invocations with a fixed work group size, then your shader has to be given the actual maximum number of operations, and you have to explicitly not do anything for invocations beyond that size.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2017-12-21T15:28:16.737" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6028" PostTypeId="1" CreationDate="2017-12-22T09:34:44.743" Score="3" ViewCount="362" Body="&lt;p&gt;Given shapes like these, which contain just Arcs and lines, I want to round all its corners with certain radius. I know the vertices of the lines &amp;amp; arcs these shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F1Hlh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F1Hlh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can round the corners of a polygon (when two lines meet to form a corner), but can't figure out how to round a corner formed by an Arc and a Line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used this post to round the corners of polygon:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/24771828/algorithm-for-creating-rounded-corners-in-a-polygon&quot;&gt;Algorithm for creating rounded corners in a polygon | Stack Overflow&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you please share a code snippet, or just explain/list the math/algorithm behind achieving this? Thanks!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I'm developing a CAD drawing generator using C# &amp;amp; .netDxf library&lt;/p&gt;&#xA;" OwnerUserId="7412" LastEditorDisplayName="user7220" LastEditDate="2018-03-07T02:58:04.523" LastActivityDate="2018-03-07T02:58:04.523" Title="Rounding a corner formed by Arc and Line" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;polygon&gt;&lt;edge-detection&gt;&lt;cad&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6029" PostTypeId="1" AcceptedAnswerId="6030" CreationDate="2017-12-22T10:01:57.720" Score="3" ViewCount="2212" Body="&lt;p&gt;I have this GLSL function that I am trying to optimize because it is going to be ran on many pixels of an older devices GPU. There is no room for branching inefficiency. Essentially this function returns a 0 or a 1 based on the variables &lt;code&gt;actualY&lt;/code&gt; &lt;code&gt;shouldY&lt;/code&gt; and &lt;code&gt;state&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float val = 0.0;&#xA;if (actualY &amp;lt; shouldY) {&#xA;    val = 1.0;&#xA;}&#xA;&#xA;if (state &amp;gt;= 20.0 &amp;amp;&amp;amp; state &amp;lt; 40.0) { //The equal/not equals is VERY important&#xA;  return 1.0 - val;&#xA;}&#xA;return val;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Usually I am fairly good at removing branching from GLSL code but I really don't know what to do with the range check for the state variable.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2019-07-18T11:34:56.477" Title="Getting rid of branching to check if a variable is within a range in GLSL" Tags="&lt;glsl&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6030" PostTypeId="2" ParentId="6029" CreationDate="2017-12-22T11:17:55.480" Score="10" Body="&lt;p&gt;This could be done that way:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First condition is &lt;code&gt;float val = 1.0-step(shouldY, ActualY);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, the condition: &lt;code&gt;state &amp;gt;= 20.0 &amp;amp;&amp;amp; state &amp;lt; 40.0&lt;/code&gt; can be changed to &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;step(20.0, state) - step(40.0, state)&lt;/code&gt;. This equals 0.0 if outside of range and 1.0 if inside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let &lt;code&gt;a = step(20.0, state) - step(40.0, state)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we know that mix function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;genType mix(genType x,&#xA;    genType y,&#xA;    genType a);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is $$x * (1 - a) + y * a  = val * (1 - a) + (1 - val) * a  = val - 2*a*val + a$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So final code is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float val = 1.0-step(shouldY, ActualY);&#xA;float a = step(20.0, state) - step(40.0, state);&#xA;return val - 2.0*a*val + a;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2017-12-22T12:31:26.967" LastActivityDate="2017-12-22T12:31:26.967" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6031" PostTypeId="1" AcceptedAnswerId="6036" CreationDate="2017-12-22T14:09:57.817" Score="2" ViewCount="82" Body="&lt;p&gt;I have a textured 3D mesh. I want to deduce a 3D mesh without texture, but with an RGB vector color on each node of this 3D mesh. The colors have to be picked from the initial texture. Is there a way to do this ? My question isn't related to art work. It's related to 3D mesh processing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="7936" LastEditorUserId="2041" LastEditDate="2017-12-23T09:41:39.407" LastActivityDate="2017-12-23T22:17:43.320" Title="How do I replace a mesh's texture with vertex colours?" Tags="&lt;texture&gt;&lt;3d&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6032" PostTypeId="2" ParentId="6021" CreationDate="2017-12-22T14:17:50.210" Score="1" Body="&lt;p&gt;Eye position, projection reference point PRP, camera center, or projection center are all just different words for the same thing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;gluLookAt() applied to the GL_MODELVIEW matrix works for both, parallel and perspective projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can choose between parallel and perspective projection by setting up the GL_PROJECTION matrix. For perspective projection this can be done using the gluPerspective() function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.mathematik.uni-marburg.de/~thormae/lectures/graphics1/graphics_6_1_eng_web.html#19&quot; rel=&quot;nofollow noreferrer&quot;&gt;Creating a perspective projection matrix in OpenGL&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit: (after revised question)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the PRP is not at the eye position, you can not use gluPerspective(). Instead you have to create your own GL_PROJECTION matrix. Following the formula that you have now provided, this results in the 4 x 4 matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathtt{A} =\begin{bmatrix} z_c-z_{pp} &amp;amp; 0 &amp;amp; -x_c &amp;amp;  x_c \cdot z_{pp}\\ 0  &amp;amp; z_c-z_{pp}  &amp;amp; -y_c &amp;amp; y_c \cdot z_{pp} \\ 0 &amp;amp; 0 &amp;amp; \frac{\mathrm{far}+\mathrm{near}}{\mathrm{near}-\mathrm{far}} &amp;amp; \frac{2 \cdot \mathrm{far} \cdot \mathrm{near}}{\mathrm{near}-\mathrm{far}} \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; z_c \end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have done a quick OpenGL/WebGL rendering test with the GSN Composer. Follow the link and move the mouse over the render output to change $x_c$ and $y_c$ of the projection reference point $(x_c, y_c, z_c)$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.gsn-lib.org/docs/gallery.php?projectName=ProjRefPoint&amp;amp;graphName=ProjectionReferencePoint&quot; rel=&quot;nofollow noreferrer&quot;&gt;Example: ProjectionReferencePoint | GSN Composer&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4652" LastEditorDisplayName="user7220" LastEditDate="2018-03-07T11:54:31.937" LastActivityDate="2018-03-07T11:54:31.937" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6033" PostTypeId="2" ParentId="1536" CreationDate="2017-12-22T17:02:39.707" Score="-1" Body="&lt;ul&gt;&#xA;&lt;li&gt;simpler formulas&lt;/li&gt;&#xA;&lt;li&gt;Fewer special cases&lt;/li&gt;&#xA;&lt;li&gt;Unification and &lt;/li&gt;&#xA;&lt;li&gt;Duality&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7937" LastActivityDate="2017-12-22T17:02:39.707" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6034" PostTypeId="2" ParentId="1536" CreationDate="2017-12-22T20:59:56.793" Score="4" Body="&lt;p&gt;Imagine you want to represent transformations using matrices. Points could be stored as $$\begin{bmatrix}x\\y\end{bmatrix}$$ and you could represent a rotation as $$\begin{bmatrix}u\\v\end{bmatrix}=\begin{bmatrix}cos(\theta)&amp;amp;-sin(\theta)\\sin(\theta)&amp;amp;cos(\theta)\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}$$ and scaling as $$\begin{bmatrix}u\\v\end{bmatrix}=\begin{bmatrix}k1&amp;amp;0\\0&amp;amp;k2\end{bmatrix}\begin{bmatrix}x\\y\end{bmatrix}$$ These are known as linear transformations and they allow us to do transformations as matrix multiplications. But notice that you cannot do translations as a matrix multiplication. Instead you have to do $$\begin{bmatrix}u\\v\end{bmatrix}=\begin{bmatrix}x\\y\end{bmatrix}+\begin{bmatrix}s\\t\end{bmatrix}$$ This is known as an affine transformation. However this is undesirable (computationally).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let R and S be rotation and scaling matrices and T be a translation vector. In computer graphics, you may need to do a series of translations to a point. You could imagine how tricky this could get.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Scale, translate, then rotate and scale, then translate again: $$p'=SR(Sp+T)+T$$&#xA;Not too bad but imagine you had do this computation on a million points. What we would like is to represent rotation, scaling, and translation all as matrix multiplications. Then those matrices can be pre multiplied together for a single transformation matrix which is easy to do computations with. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Scale, translate, then rotate and scale, then translate again:&#xA;$$M=TSRTS$$ $$p'=Mp$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can achieve this by adding another coordinate to our points. I'm going to show all this for 2D graphics (3D points) but you could extend all this to 3D graphics (4D points).&#xA;$$p=\begin{bmatrix}x\\y\\1\end{bmatrix}$$&#xA;Rotation matrix:&#xA;$$R=\begin{bmatrix}cos(\theta)&amp;amp;-sin(\theta)&amp;amp;0\\sin(\theta)&amp;amp;cos(\theta)&amp;amp;0\\0&amp;amp;0&amp;amp;1\end{bmatrix}$$&#xA;Scale matrix:&#xA;$$S=\begin{bmatrix}k1&amp;amp;0&amp;amp;0\\0&amp;amp;k2&amp;amp;0\\0&amp;amp;0&amp;amp;1\end{bmatrix}$$&#xA;Translation matrix:&#xA;$$T=\begin{bmatrix}1&amp;amp;0&amp;amp;t1\\0&amp;amp;1&amp;amp;t2\\0&amp;amp;0&amp;amp;1\end{bmatrix}$$&#xA;You should work out some examples to convince yourself that these do in fact give you the desired transformation and that you can compose a series of transformations by multiplying multiple matrices together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could go further and allow the extra coordinate to take on any value. $$p=\begin{bmatrix}x\\y\\w\end{bmatrix}$$ and say this this homogeneous (x, y, w) coordinate represents the euclidean (x, y) coordinate at (x/w, y/w). Normally you cannot do division using matrix transformations, however by allowing w to be a divisor, you can set w to some value (through a matrix multiplication) and allow it to represent division. This is useful for doing projection because (in 3D) you will need to divide the x and y coordinates by -z (in a right handed coordinate system). You can achieve this by simply setting w to -z using the following projection matrix:&#xA;$$Q=\begin{bmatrix}1&amp;amp;0&amp;amp;0&amp;amp;0\\0&amp;amp;1&amp;amp;0&amp;amp;0\\0&amp;amp;0&amp;amp;1&amp;amp;0\\0&amp;amp;0&amp;amp;-1&amp;amp;0\end{bmatrix}$$&lt;/p&gt;&#xA;" OwnerUserId="7740" LastActivityDate="2017-12-22T20:59:56.793" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6035" PostTypeId="1" CreationDate="2017-12-23T07:40:48.327" Score="4" ViewCount="599" Body="&lt;p&gt;In the following two graphs,&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the red lines are borders of the perspective-projection frustum,&lt;/li&gt;&#xA;&lt;li&gt;the blue lines are to be rasterized,&lt;/li&gt;&#xA;&lt;li&gt;the green lines are perspective-projection lines, which are wrong.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;How do modern GPU pipelines do such clipping given only a perspective-projection matrix?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/A39Hi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A39Hi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/936y3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/936y3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2018-03-06T08:42:25.230" Title="Clipping for perspective projection" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;rasterizer&gt;&lt;clipping&gt;&lt;directx&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6036" PostTypeId="2" ParentId="6031" CreationDate="2017-12-23T22:17:43.320" Score="1" Body="&lt;p&gt;You can sample the texture in your vertex shader and set the color appropriately. You don't say what system you're using, but for something like an OpenGL vertex shader, it would look something like this (this is a little old school, so it may need updating for modern GL) :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler2DRect texture;&#xA;varying vec4 color;&#xA;void main ()&#xA;{&#xA;    color  = texture2DRect(texture, gl_MultiTexCoord0.xy);&#xA;&#xA;    vec4    newVertex   = vec4(gl_Vertex.xyz, 1.0);&#xA;&#xA;    gl_Position = gl_ModelViewProjectionMatrix * newVertex;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Your fragment shader would then just set the color of the fragment to the interpolated color coming from the vertex shader. Something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;varying vec4 color;&#xA;void main()&#xA;{&#xA;    gl_FragColor = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-12-23T22:17:43.320" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6039" PostTypeId="1" CreationDate="2017-12-25T00:32:25.993" Score="2" ViewCount="121" Body="&lt;p&gt;I hope this is the right group to be able to expose my doubts about the implementation of the algorithm shown in this &lt;a href=&quot;https://pdfs.semanticscholar.org/6a7e/8a731dc35fb6c9d740a9f43eb2e84672cad6.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt;. The question I have is how to do the feature curves, what I do not understand is how to use piecewise Bézier cubic spline to build them. I hope someone can help me with an example please to be able to advance with that algorithm. Any help is welcome, thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="7943" LastActivityDate="2018-03-26T05:28:34.977" Title="how to build the feature curves of this algorithm?" Tags="&lt;algorithm&gt;&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6040" PostTypeId="1" CreationDate="2017-12-25T01:20:41.573" Score="1" ViewCount="75" Body="&lt;p&gt;This question is a little different to your typical questions but I think this is the best community to ask this in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been interested in lego technic for most my life and have been trying to come up with a way to quickly and easily represent axles, pins, axle holes and pin holes on computers universally. I decided to  use plain ASCII since it is quicker and works on mobile devices and on desktops.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I made a good representation of the pins, axles and holes in one axis but the problem is: ASCII is 2D but lego technic is 3D, so rotated or flipped lego parts are very hard to represent and if the entire building axis changes then so do the part orientations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some way I can do this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my syntax:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;facing the front:&#xA;&#xA;+ axle hole&#xA;× axle&#xA;o pin hole&#xA;. pin&#xA;&#xA;facing the side:&#xA;&#xA;&amp;lt; axle hole&#xA;= axle&#xA;Z pin hole&#xA;- pin&#xA;&#xA;facing the side rotated 90 degrees:&#xA;&#xA;V axle hole&#xA;! axle&#xA;N pin hole&#xA;| pin&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;if a symbol is underlined it means it is half thickness, if not it is worth 1L&lt;/p&gt;&#xA;" OwnerUserId="7945" LastEditorUserId="7945" LastEditDate="2017-12-25T01:54:29.090" LastActivityDate="2018-01-05T21:57:29.987" Title="Creating 3d model building notation using ASCII" Tags="&lt;diagram&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6042" PostTypeId="1" CreationDate="2017-12-25T20:51:09.160" Score="0" ViewCount="83" Body="&lt;p&gt;I am working on a raytracing Java program for fun. Here's one rendering: &lt;a href=&quot;https://i.stack.imgur.com/CSWU3.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CSWU3.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see I still have to implement anti-aliasing (and there are huge geometry problems I won't get in to). How would one go about this in a raytracing program, where the renderer doesn't really render lines, but individual pixels? Is it even possible? For example, in a scanline rendering, you could apply anti-aliasing after filling a triangle. But in a raytraced rendering, the program works pixel-by-pixel, and doesn't know where object's edges are, or where to smooth things out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="7950" OwnerDisplayName="MCMastery" LastEditorUserId="7950" LastEditDate="2017-12-25T21:18:46.993" LastActivityDate="2017-12-25T21:18:46.993" Title="How does anti-aliasing work, in general, for raytracing?" Tags="&lt;3d&gt;&lt;antialiasing&gt;&lt;raytracing&gt;" AnswerCount="0" CommentCount="2" ClosedDate="2017-12-25T22:16:46.443" ContentLicense="CC BY-SA 3.0" />
  <row Id="6043" PostTypeId="2" ParentId="6039" CreationDate="2017-12-26T04:35:56.950" Score="1" Body="&lt;p&gt;The way I read it, you have a 2D cubic Bézier that defines the projections of the ridge line (or river bed, or whatever) onto the X/Y plane. In Figure 4, these are the dark purple lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So that gives you the direction that the ridge line moves. Now you have to define the height of the ridge line. This is done by picking some points along the 2D Bézier and setting the following values at each of the chosen points:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;h = height&#xA;r = radius (this appears more like a width at the ridge line than a curved radius)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can then also set the angle of the terrain as it comes off the radius. These are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;`phi` and `theta`&#xA;`a` and `b` are the lengths of the slopes&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that you don't have to set every value for every control point you pick. I assume any you don't set are defaulted to 0, or some reasonable default.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So for a hill, you would set &lt;code&gt;h&lt;/code&gt; to the height of the hill at a few point. You would then set &lt;code&gt;phi&lt;/code&gt; and &lt;code&gt;theta&lt;/code&gt; to be horizontal, so yes, &lt;code&gt;pi / 4&lt;/code&gt;. The length of &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; will decide how quickly the hill falls off as you move away from the ridge line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like the above 6 values are turned into another cubic Bézier curve that is perpendicular to the first one for the rasterization step in section 4 of the paper. &lt;code&gt;h&lt;/code&gt; doesn't factor into the shape of the perpendicular Bézier because it's also perpendicular to it. So &lt;code&gt;r&lt;/code&gt;, &lt;code&gt;theta&lt;/code&gt;, &lt;code&gt;phi&lt;/code&gt;, &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are used to make a cubic Bézier. I believe that you can think about like this: the point on the ridge line where you define one of these control points is the link between 2 cubic Bézier segments - one to the left of the point and the other to the right. The images they show only show a single point between 2 Bézier curves, but the way I'm reading it there are actually 2 curves that look something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/L6TPF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/L6TPF.png&quot; alt=&quot;Beziers&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I think normally, you'd have 2 Béziers. One on each side of the control point they show in the paper. (Pardon my bad drawing.)  &lt;code&gt;a&lt;/code&gt; would be the distance between control points 2 and 3 of the left curve. &lt;code&gt;Theta&lt;/code&gt; would be the angle formed between the vertical and &lt;code&gt;a&lt;/code&gt; of the left curve. &lt;code&gt;r&lt;/code&gt; would be the distance between points 3 and 4 of the left curve. I'm unclear on how one would pick control point 1 in this scenario, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Ai&lt;/code&gt; and &lt;code&gt;Ri&lt;/code&gt; have to do with the noise parameters and don't appear to me to be related to the Bézier curves at all.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2017-12-26T04:35:56.950" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6044" PostTypeId="2" ParentId="6021" CreationDate="2017-12-26T11:40:51.503" Score="0" Body="&lt;p&gt;If you are talking about an oblique perspective projection in which the line joining the eye and center of the projection plane is not perpendicular to the plane like here (upper left),&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dJInW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dJInW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be generated by the &lt;code&gt;glFrustum()&lt;/code&gt; call. Normally when you describe perspective projection they set &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;left = -right&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;bottom = -top&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so that these are centered around the Z-axis. In order to generate an oblique projection you can use the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;above&lt;/a&gt; mentioned method which takes input the coordinates for left, right, top, bottom, near and far planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other way around is to build your own custom projection matrix, and load it directly. The matrix should be stored as an array&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;GLfloat mat[16] = {...}&#xA; GlLoadMatrix(mat)&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-12-26T11:40:51.503" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6045" PostTypeId="1" AcceptedAnswerId="6049" CreationDate="2017-12-26T11:50:35.493" Score="2" ViewCount="2022" Body="&lt;p&gt;I'm working with OpenGL and facing some difficulties because I'm not familiar with OpenGL. I tried to search related example in Google, but I could not find some useful code.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are five arrays.&#xA;I bound and changed the data in compute shahder as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;computeShader.use();&#xA;int bufferSize = sizeof(vertices) * vertices.size();&#xA;glGenBuffers(1, &amp;amp;vbo_Previous);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Previous);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vbo_Previous);&#xA;&#xA;&#xA;glGenBuffers(1, &amp;amp;vbo_Current);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Current);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo_Current);&#xA;&#xA;glGenBuffers(1, &amp;amp;vbo_Next);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Next);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, vbo_Next);&#xA;&#xA;glGenBuffers(1, &amp;amp;vbo_Normal);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Normal);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;normals[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, vbo_Normal);&#xA;&#xA;glGenBuffers(1, &amp;amp;vbo_Tangent);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Tangent);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;tangents[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, vbo_Tangent);&#xA;&#xA;glGenBuffers(1, &amp;amp;vbo_Binormal);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Binormal);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;binormals[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, vbo_Binormal);&#xA;computeShader.unUse();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I want to use the data in vertex shader.&#xA;I tried like that, but I doesn't work. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenVertexArrays(1, &amp;amp;vao);&#xA;glGenBuffers(1, &amp;amp;ebo);&#xA;glBindVertexArray(vao);&#xA;&#xA;&#xA;int bufferOffset = 0;&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Next);&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));&#xA;&#xA;bufferOffset += sizeof(glm::vec4) * vertices.size();&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Normal);&#xA;glEnableVertexAttribArray(1);&#xA;glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));&#xA;&#xA;bufferOffset += sizeof(glm::vec4) * normals.size();&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Tangent);&#xA;glEnableVertexAttribArray(2);&#xA;glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));&#xA;&#xA;bufferOffset += sizeof(glm::vec4) * tangents.size();&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Binormal);&#xA;glEnableVertexAttribArray(3);&#xA;glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));&#xA;&#xA;//Because the texture coordinate are not changed in compute shader I generated the vbo for texture coordinate data&#xA;bufferOffset += sizeof(glm::vec4) * binormals.size();&#xA;glGenBuffers(1, &amp;amp;vbo);&#xA;glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2)*texCoords.size(), &amp;amp;texCoords[0], GL_STATIC_DRAW);&#xA;glEnableVertexAttribArray(4);&#xA;glVertexAttribPointer(4, 2, GL_FLOAT, GL_FALSE, 0, (void*)(bufferOffset));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I hope to use the data in vertex shader as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;layout(location = 0) in vec4 aPos;&#xA;layout(location = 1) in vec4 aNormal;&#xA;layout(location = 2) in vec4 aTangent;&#xA;layout(location = 3) in vec4 aBinormal;&#xA;layout(location = 4) in vec2 aTexCoord;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How to set vertex object array to use the data?&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2018-02-06T07:57:14.563" Title="How to use the data manipulated in OpenGL Compute Shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;compute-shader&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6046" PostTypeId="2" ParentId="6045" CreationDate="2017-12-26T14:48:51.100" Score="1" Body="&lt;p&gt;I think you are confusing all the binding targets thingy. From what I see your vertex data is coming from compute shader after some processing and now you want to pass it to the vertex shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can create a buffer object once, use it as an SSBO for use in a compute shader then use it as a VBO for use in rendering. i.e&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Setup SSBO for use in Compute shader&#xA;glGenBuffers(1, &amp;amp;vbo_Current);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, vbo_Current);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo_Current);&#xA;&#xA;// Setup the same Buffer object as VBO for use in rendering&#xA;glBindBuffer(GL_ARRAY_BUFFER, vbo_Current);   &amp;lt;- Note the change in binding target&#xA;GlVertexAttribPointer().......                &amp;lt;- set your vertex data&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Hence there is no need to generate 1 more buffer object for the texture, just pass the same buffer but change the binding points to &lt;code&gt;GL_ARRAY_BUFFER&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However do note that you need to use appropriate Memory barrier calls as SSBO reads and writes are incoherent memory accesses. Don't know much about these but you can find more information &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Memory_Model&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2017-12-26T14:48:51.100" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6047" PostTypeId="2" ParentId="6028" CreationDate="2017-12-26T17:42:23.180" Score="2" Body="&lt;p&gt;I suppose you want an arc of C0 and C1 continuity between the line and an arc.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/VC5L4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VC5L4.png&quot; alt=&quot;Rounding corner illustration&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As illustrated above, you already have a vertex A which is the intersection of an edge and an arc of which the center positioned at O and radius equal to R. The question is thus pure mathematical: given A,O,R, edge direction BA, and a corner radius r, find C,B, and T.&#xA;For simplicity, here let's assume that the black dotted line has the form of $C_y=kC_x+b$, where k is the same as edge BA while b is easily derived by combining k and rounding radius r. Therefore, three constraint equations can be listed to solve $C_x$:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The distance TC is r: $(T_x-C_x)^2+(T_y-C_y)^2=r^2$&lt;/li&gt;&#xA;&lt;li&gt;The big arc equation: $(T_x-O_x)^2+(T_y-O_y)^2=R^2$&lt;/li&gt;&#xA;&lt;li&gt;Point C is on OT: $\frac{T_y-C_y}{T_x-C_x}=\frac{T_y-O_y}{T_x-O_x}$&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Solve for Cx and you'll obtain four solutions (I used Mathematica):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$C_x=\frac{-bk+O_x+kO_y\pm\sqrt{-(O_y-kO_x-b)^2+(1+k^2)(R-r)^2}}{1+k^2}$&#xA;$C_x=\frac{-bk+O_x+kO_y\pm\sqrt{-(O_y-kO_x-b)^2+(1+k^2)(R+r)^2}}{1+k^2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second expression is out of the arc, so you should use the first solutions. Given the two Cx values, they can be used to derive Cy values to make a candidate list for point C. Pick the correct C using manual check.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you have the center C of the round corner arc as well as its radius r. It should be relatively easy to determine point B and point T, and draw an arc through the two points.&lt;/p&gt;&#xA;" OwnerUserId="5748" LastEditorUserId="5748" LastEditDate="2017-12-26T17:58:31.897" LastActivityDate="2017-12-26T17:58:31.897" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6049" PostTypeId="2" ParentId="6045" CreationDate="2017-12-27T06:43:25.317" Score="2" Body="&lt;p&gt;I can see a few things wrong here. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, you're setting your GL buffer size to &lt;code&gt;sizeof(vertices) * vertices.size()&lt;/code&gt;&#xA;This looks wrong. What is vertices? A std::array of vec4? Then you want &lt;code&gt;vertices.size() * sizeof(glm::vec4)&lt;/code&gt;, or just &lt;code&gt;sizeof(vertices)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, as wandering-warrior said, you want to be binding to &lt;code&gt;GL_ARRAY_BUFFER&lt;/code&gt; before calling &lt;code&gt;glVertexAttribPointer&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Third, I don't know what you're doing with &lt;code&gt;bufferOffset&lt;/code&gt; in the second part of the code. This is a valid approach if the data is laid out sequentially in one large buffer (vertices then normals then tangents etc. etc.). But in your case you're using a separate buffer for each data set - so each attribute should start reading from the beginning of its own buffer, i.e. &lt;code&gt;bufferOffset&lt;/code&gt; should always be 0. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fourth, you don't seem to be actually &lt;em&gt;using&lt;/em&gt; your compute shader anywhere. It's not enough to just call &lt;code&gt;glUseProgram&lt;/code&gt;, you need to call &lt;code&gt;glDispatchCompute&lt;/code&gt; after you bind your buffers to actually run it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, it's not common practice to store binormals in an array, since they can be reconstructed in the fragment shader from the tangent and normal using a cross product.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would do it something like this (using OpenGL 4.5 with the new Direct State Access functions to save all those buffer bindings).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int bufferSize = sizeof(vertices);&#xA;&#xA;glCreateBuffers(1, &amp;amp;vbo_Previous);&#xA;glNamedBufferData(vbo_Previous, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, vbo_Previous);&#xA;&#xA;glCreateBuffers(1, &amp;amp;vbo_Current);&#xA;glNamedBufferData(vbo_Current, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo_Current);&#xA;&#xA;glCreateBuffers(1, &amp;amp;vbo_Next);&#xA;glNamedBufferData(vbo_Next, bufferSize, &amp;amp;vertices[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, vbo_Next);&#xA;&#xA;glCreateBuffers(1, &amp;amp;vbo_Normal);&#xA;glNamedBufferData(vbo_Normal, bufferSize, &amp;amp;normals[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, vbo_Normal);&#xA;&#xA;glCreateBuffers(1, &amp;amp;vbo_Tangent);&#xA;glNamedBufferData(vbo_Tangent, bufferSize, &amp;amp;tangents[0], GL_STATIC_DRAW);&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, vbo_Tangent);&#xA;&#xA;glCreateBuffers(1, &amp;amp;vbo_Texcoords);&#xA;glNamedBufferData(vbo_Texcoords, sizeof(texCoords), &amp;amp;texCoords[0], &#xA;GL_STATIC_DRAW);&#xA;&#xA;glCreateBuffers(1, &amp;amp;ebo);&#xA;glNamedBufferData(ebo, sizeof(elements), &amp;amp;elements[0], GL_STATIC_DRAW);&#xA;//you have element data in an array, right?&#xA;&#xA;glCreateVertexArrays(1, &amp;amp;vao);&#xA;glBindVertexArray(vao);&#xA;&#xA;glBindVertexBuffer(0, vbo_Next, 0, 0);&#xA;glVertexAttribBinding(0,0);&#xA;glVertexAttribFormat(0, 4, GL_FLOAT, GL_FALSE, 0);&#xA;glBindVertexBuffer(1, vbo_Normal, 0, 0);&#xA;glVertexAttribBinding(1,1);&#xA;glVertexAttribFormat(1, 4, GL_FLOAT, GL_FALSE, 0);&#xA;glBindVertexBuffer(2, vbo_Tangent, 0, 0);&#xA;glVertexAttribBinding(2,2);&#xA;glVertexAttribFormat(2, 4, GL_FLOAT, GL_FALSE, 0);&#xA;glBindVertexBuffer(3, vbo_Texcoords, 0, 0);&#xA;glVertexAttribBinding(3,3);&#xA;glVertexAttribFormat(3, 2, GL_FLOAT, GL_FALSE, 0);&#xA;glVertexArrayElementBuffer(vao, ebo);&#xA;&#xA;glEnableVertexAttribArray(0);&#xA;glEnableVertexAttribArray(1);&#xA;glEnableVertexAttribArray(2);&#xA;glEnableVertexAttribArray(3);&#xA;&#xA;computeShader.use();&#xA;glDispatchCompute (/*number of groups*/)&#xA;computeShader.unUse();&#xA;&#xA;glMemoryBarrier(GL_VERTEX_ATTRIB_ARRAY_BARRIER_BIT);&#xA;&#xA;renderShader.use();&#xA;glDrawElements(GL_TRIANGLES, elements.size(), GL_UNSIGNED_INT, 0);&#xA;renderShader.unUse();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="1937" LastEditDate="2018-02-06T07:57:14.563" LastActivityDate="2018-02-06T07:57:14.563" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6052" PostTypeId="2" ParentId="6035" CreationDate="2017-12-28T04:07:40.420" Score="2" Body="&lt;p&gt;3D clipping is usually done in clipspace coordinates, that means the perspective matrix is used for sending the primitives to clipspace before doing the actual perspective projection. You can visualize the clipspace as a view frustum but with the shape of a box. So it is very fast to clip primitives against a AABB. The math is a little involved, but is all explained in this blog post: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://unspecified.wordpress.com/2012/06/21/calculating-the-gluperspective-matrix-and-other-opengl-matrix-maths/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Calculating the gluPerspective matrix and other OpenGL matrix maths | Unspecified Behaviour Blog&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7957" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T08:42:25.230" LastActivityDate="2018-03-06T08:42:25.230" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6053" PostTypeId="2" ParentId="4801" CreationDate="2017-12-28T04:17:42.153" Score="1" Body="&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/16706911/34399964-ae3c684a-eba1-11e7-95f1-2696a37b650c.JPG&quot; alt=&quot;image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used &lt;a href=&quot;https://docs.unity3d.com/Manual/SL-Stencil.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Stencil Buffer&lt;/a&gt; to fixing your problem , you need a way for checking &lt;a href=&quot;https://stackoverflow.com/questions/35574227/unity-shader-highlighting-overlaps&quot;&gt;overlapping two or more shapes&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; Shader &quot;Custom/SemiTransparent&quot;&#xA;{&#xA;    Properties&#xA;    {&#xA;        _Color(&quot;Color&quot;,Color) = (0,0,1,0.1)&#xA;    }&#xA;    SubShader&#xA;    {&#xA;Tags {&quot;Queue&quot;=&quot;Transparent&quot; &quot;IgnoreProjector&quot;=&quot;true&quot; &quot;RenderType&quot;=&quot;Transparent&quot;}&#xA;ZWrite Off Blend SrcAlpha OneMinusSrcAlpha Cull Off&#xA;&#xA;        LOD 100&#xA;&#xA;        Pass&#xA;        {&#xA;            Stencil {&#xA;                Ref 0&#xA;                Comp Equal&#xA;                Pass IncrSat &#xA;                Fail IncrSat &#xA;            }&#xA;&#xA;            CGPROGRAM&#xA;            #pragma vertex vert&#xA;            #pragma fragment frag&#xA;&#xA;            #include &quot;UnityCG.cginc&quot;&#xA;&#xA;            fixed4 _Color;&#xA;&#xA;            struct appdata&#xA;            {&#xA;                float4 vertex : POSITION;&#xA;            };&#xA;&#xA;            struct v2f&#xA;            {&#xA;                float4 vertex : SV_POSITION;&#xA;            };&#xA;&#xA;            v2f vert (appdata v)&#xA;            {&#xA;                v2f o;&#xA;                o.vertex = UnityObjectToClipPos(v.vertex);&#xA;                return o;&#xA;            }&#xA;&#xA;            fixed4 frag (v2f i) : SV_Target&#xA;            {&#xA;                fixed4 col = _Color;&#xA;                return col;&#xA;            }&#xA;            ENDCG&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6541" LastEditorUserId="6541" LastEditDate="2018-05-02T13:23:09.923" LastActivityDate="2018-05-02T13:23:09.923" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="6057" PostTypeId="2" ParentId="1741" CreationDate="2017-12-28T20:37:57.843" Score="2" Body="&lt;p&gt;If you have an oriented triangle mesh (a non oriented surface would be the &lt;a href=&quot;https://en.wikipedia.org/wiki/M%C3%B6bius_strip&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moebius Strip&lt;/a&gt; for instance), you can check the triangle inversion by looking at the &lt;a href=&quot;http://mathworld.wolfram.com/TriangleArea.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;signed area of triangles&lt;/a&gt;. The signed area is positive when the vertices are in CCW order and negative if they are in CW order. If your triangle vertices are all sorted in CCW then all triangles with negative area are inverted. Fixing that depends on the deformation technique, I don't know your case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Checking self-intersection is more involved. You should actually do Collision Detection of the mesh with itself. Collision detection is fast but need to implement proper data structures such as &lt;a href=&quot;https://www.azurefromthetrenches.com/introductory-guide-to-aabb-tree-collision-detection/&quot; rel=&quot;nofollow noreferrer&quot;&gt;AABB Tree&lt;/a&gt; for narrow the amount of triangle-triangle intersection tests. Collision Detection is usually performed using very low-poly version of the meshes. In some computer games, the bounding volume hierarchy (spheres, AABBs, etc) that approximate the mesh is the only thing considered for collision, no the mesh itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once a collision is detected, there are several ways to response, applying a  bouncing force for instance, is common.&lt;/p&gt;&#xA;" OwnerUserId="7957" LastEditorUserId="7957" LastEditDate="2017-12-28T20:47:20.027" LastActivityDate="2017-12-28T20:47:20.027" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6058" PostTypeId="1" CreationDate="2017-12-29T17:18:03.710" Score="0" ViewCount="83" Body="&lt;p&gt;I want to write a program that allows me to simulate the effect of wind on a decorated 3d tree standing outdoors (rocking ornaments and decorations, falling balls, etc.). The program should allow to determine the parameters of the tree, the selection and placement of ornaments and the specification of wind parameters (wind way, average force, gusts, etc.) Does anyone know what libraries or tools I could use I have heard about unity, does anyone have any suggestions?&lt;/p&gt;&#xA;" OwnerUserId="7966" LastActivityDate="2017-12-31T08:07:22.110" Title="Technology for specific project 3d in c#?" Tags="&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6059" PostTypeId="1" CreationDate="2017-12-31T03:39:09.060" Score="4" ViewCount="197" Body="&lt;p&gt;In my naïve raytracer experiment I work internally with RGB values, and after all the tracing has been done, I end up with raw RGB triplets that I need to write down to some image format with a limited gamut, typically sRGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since bright spots in my image can have values far beyond (1,1,1), I need to clip them. Right now I just limit each channel individually, but that will obviously introduce a shift in hue when one channel clips before another. Here is a typical (enlarged) example from my code where the yellow-green object turns into yellow around the highlight:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V1hMC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V1hMC.png&quot; alt=&quot;Example of hue shift&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm now looking for a way to solve this problem, but all the solutions I come up with seems to have the same drawback: eventually you &lt;em&gt;have&lt;/em&gt; to discard information. For example, I've thought about working with another colorspace like Lab internally, but even then I would first have to transform it to sRGB for rendering the final image file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before I dig myself into this any further, I would like to see if there is either:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;An objectively &quot;best&quot; way to solve this problem, or..&lt;/li&gt;&#xA;&lt;li&gt;An industry standard way that is used in practice&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7969" LastActivityDate="2017-12-31T11:11:02.877" Title="How do you deal with clipping when rendering to a limited colorspace?" Tags="&lt;raytracing&gt;&lt;color&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6060" PostTypeId="2" ParentId="6058" CreationDate="2017-12-31T04:15:09.303" Score="1" Body="&lt;p&gt;I have done 3D graphics in c# with Managed DirectX. Nowadays people uses SharpDX and SlimDX instead. I have heard about XNA is easier for doing simple 3D games. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also use OpenGl since there are several bindings for C#. Some people find OpenGl simpler to understand than DirectX, and is cross platform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unity uses C# as scripting language, the Unity Engine is running the actual simulations. You are mostly configuring and scripting Unity for running your simulation. This is not just a technology to use in your C# project, this is the oposite, a platform for games that uses C# as one technology.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can do 2D graphics with all the above technologies. For the simulation, in case you do not use Unity or other game engine capable of doing physics simulations, you would need to find or write a rigid body simulation for animating all your moving objects. For animating the tree you would probably need a spring system which is also simple to simulate along rigid bodies.&lt;/p&gt;&#xA;" OwnerUserId="7957" LastEditorUserId="7957" LastEditDate="2017-12-31T08:07:22.110" LastActivityDate="2017-12-31T08:07:22.110" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6062" PostTypeId="2" ParentId="6059" CreationDate="2017-12-31T11:11:02.877" Score="6" Body="&lt;p&gt;Effectively, before you start to think about clipping/clamping, you'll need a general approach to map the much wider color range you are working in onto the [0,1] triplets you want to output. There are various way to do this, look up &lt;strong&gt;HDR tone mapping&lt;/strong&gt; to get a good first impression of what is possible. Simply clipping things to [0,1] will leave you with a very cramped color space to work in, throwing away much of the advantages of raytracying in &quot;high dynamic range&quot; (floats).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On to the actual problem at hand, to prevent clamped colours from shifting hue, a naive but functional approach is:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Take the max component &lt;em&gt;m&lt;/em&gt; from (R, G, B)&lt;/li&gt;&#xA;&lt;li&gt;If &lt;em&gt;m&lt;/em&gt; &gt; 1, scale all three components by 1 / &lt;em&gt;m&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This does not take the relative luminance of the color components into account, but if you eventually end up doing something like tone-mapping anyway that would be a better time to tackle that problem.&lt;/p&gt;&#xA;" OwnerUserId="5088" LastActivityDate="2017-12-31T11:11:02.877" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6064" PostTypeId="1" AcceptedAnswerId="6066" CreationDate="2017-12-31T20:35:30.410" Score="1" ViewCount="370" Body="&lt;p&gt;Here's a constructor to construct a axis-aligned bounding box given two opposite vertices on the bounding box, from &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/0128006455&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pharr's &lt;em&gt;Physically Based Rendering&lt;/em&gt;, Third Edition&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;BBox(const Point &amp;amp;p1, const Point &amp;amp;p2) {&#xA;    pMin = Point(min(p1.x, p2.x), min(p1.y, p2.y), min(p1.z, p2.z));&#xA;    pMax = Point(max(p1.x, p2.x), max(p1.y, p2.y), max(p1.z, p2.z));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't understand why this works; for example if I take $P_1 = (1,2,3)$ and $P_2 = (2,1,4)$, I'll get $\text{pMin} = (1,1,3)$ and $\text{pMax} = (2,2,4)$. The bounding box between $P_1$ and $P_2$ is doesn't look same as bounding box between &lt;code&gt;pMin&lt;/code&gt; and &lt;code&gt;pMax&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The explanation for this constructor given in the book :&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If the caller passes two corner points (&lt;code&gt;p1&lt;/code&gt; and &lt;code&gt;p2&lt;/code&gt;) to define the box, since &lt;code&gt;p1&lt;/code&gt; and &lt;code&gt;p2&lt;/code&gt; are not necessarily chosen so that &lt;code&gt;p1.x&lt;/code&gt; &amp;lt;= &lt;code&gt;p2.x&lt;/code&gt;, and so on, the constructor needs to find their component-wise minimum and maximum values.      &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As far as I understand, if &lt;code&gt;p1.x&lt;/code&gt; is less than &lt;code&gt;p2.x&lt;/code&gt; then &lt;code&gt;pMin = p1&lt;/code&gt;. So we should only be checking against &lt;code&gt;p1.x&lt;/code&gt; and &lt;code&gt;p2.x&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I missing something ? The above constructor doesn't feel correct for axis-aligned bounding boxes.&lt;/p&gt;&#xA;" OwnerUserId="7814" LastEditorUserId="2041" LastEditDate="2018-01-01T00:44:36.920" LastActivityDate="2018-01-01T01:00:20.183" Title="AABB bounding boxes" Tags="&lt;raytracing&gt;&lt;mathematics&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6065" PostTypeId="2" ParentId="6064" CreationDate="2018-01-01T00:55:35.140" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;As far as I understand, if &lt;code&gt;p1.x&lt;/code&gt; is less than &lt;code&gt;p2.x&lt;/code&gt; then &lt;code&gt;pMin = p1&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Nope. That would be true if you wanted the caller to only pass the lower-left and upper-right points, but they can be any pair of opposite points. Let's truncate to two dimensions to make it simpler. If $p_1 = (1,2)$ and $p_2 = (2,1)$, they're not the bottom-left and top-right of a rectangle, they're the &lt;em&gt;other&lt;/em&gt; two corners. The bottom-left corner is $(1,1)$ and the top-right corner is $(2,2)$. It's no different in three dimensions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To put it another way, an axis-aligned bounding box is the Cartesian product of three intervals or ranges, one along each axis. It's the set of all points $(x,y,z)$ where $x_{min} &amp;lt; x &amp;lt; x_{max}\ \wedge y_{min} &amp;lt; y &amp;lt; y_{max}\ \wedge z_{min} &amp;lt; z &amp;lt; z_{max}$. You're trying to find the smallest box that contains all of the points you're passed. (In fact, you're only passed two, but it would be the same if you had a whole set of points.) To do that, you find the interval on each axis separately. Just because one of the points you're passed in has the smallest $x$ co-ordinate, that doesn't mean it'll have the smallest $y$ or $z$ co-ordinate, so you take the min and max separately for each axis.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-01-01T00:55:35.140" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6066" PostTypeId="2" ParentId="6064" CreationDate="2018-01-01T01:00:20.183" Score="6" Body="&lt;p&gt;In short; The constructor is correct.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;As far as I understand, if p1.x is less than p2.x then pMin = p1. So we should only be checking against p1.x and p2.x.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I get where the confusion comes from, but the explanation meant something else. It meant that when $p1$ and $p2$ are given, they are not always ordered so that $p1$ is always $pMin$ and $p2$ is always $pMax$. So we need to find out. However, it could be that when solely looking at the x-axis, $p1$ is $pMin$, but when looking at the y-axis, $p2$ is $pMin$. So, we need to find $pMin$ and $pMax$ for each of their components, seperately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we look at a two dimensional example, we can see more easily how it works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have $p1=(7, 4)$ and $p2=(2, 6)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZkEGn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZkEGn.png&quot; alt=&quot;Graph of p1 and p2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We want to get $pMin$ and $pMax$. $pMin$ should be the lowest value for all the components. $pMax$ should be the highest value for all the components. That would make calculations a lot easier of course.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When looking at the graph we can easily find $pMin$ and $pMax$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CHVe3.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CHVe3.png&quot; alt=&quot;pMin and pMax plotted on a graph&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$pMin=(2, 4)$ and $pMax=(7, 6)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can see that for $pMin$, we took the lowest value from $p2$ for the x component and the lowest value from $p1$ for the y component.&#xA;For $pMax$, we took the highest value from $p1$ for the x component and the highest value from $p2$ for the y component.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we would only look at the x component and determined $pMin$ and $pMax$ from that, we would get $pMin=(2, 6)$ and $pMax=(7, 4)$. This works for the x component, but it makes no sense on the y component, as $pMin$ has the highest y value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The bounding boxes are still the same. We still store the same rectangle, we just used different points to store it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When going to the third dimension, it is still exactly the same. You just do the same for the z component as you would do for the x and y components.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-01-01T01:00:20.183" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6067" PostTypeId="1" AcceptedAnswerId="6068" CreationDate="2018-01-01T08:56:20.587" Score="6" ViewCount="159" Body="&lt;p&gt;I am starting to think about how I can make my app (currently written in Metal) available on older device that dont have Metal as well as Android. This is a predicament because while I could write two separate rendering classes that use the different frameworks it doesn’t teach me anything about how to code for multiple graphics libraries. I can only get away with this because my rendering code is fairly short and has few states and draw calls. I want to learn for the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Writing a renderer that supports multiple frameworks especially becomes difficult when thinking of the two libraries I hope to support — OpenGL and Metal — which are quite different in how they expose the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am curious how exactly one usually does design their code for apps that can target multiple graphics languages. Here are my theories of what could be done:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Write two different rendering classes keep the data and simulation stuff in its own area and just vary the renderer.&lt;/li&gt;&#xA;&lt;li&gt;Take high level functions like createTexture or copyTextureOnto and have an if statement checking which language the device supports and have a custom implementation for it.&lt;/li&gt;&#xA;&lt;li&gt;Coming up with your own graphics objects that are akin to the objects from the framework (such as MTLCommandEncoder or MTLTexture) and use those to build you app and just use the implantation that matches your graphics frameworks. Essentially recode the functions one of your graphics libraries has that you use and just add an if statement to your implementation is called on a OpenGL supporting device.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;When you have to code a software to support multiple graphics libraries how do you generally do it? Do you loose any efficiency with the technique you use?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2018-01-01T16:55:08.603" Title="How do you design the code of a graphics engine to target multiple frameworks" Tags="&lt;opengl&gt;&lt;metal&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6068" PostTypeId="2" ParentId="6067" CreationDate="2018-01-01T16:55:08.603" Score="6" Body="&lt;p&gt;You do it by abstracting away the underlying technology. You know, for example, at a very high level that you'll need to work with images, geometry, and I'm guessing you'll have to write shaders to do your rendering. The textures and geometry can be in the same format for both systems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So from that, you can design an interface for rendering. You'll probably have a scene of some sort that has the geometry in it. The geometry will likely have the textures applied to it. When rendering the geometry you'll need to use a shader. Those might be good places to start with your abstraction. You might need a scene object that holds all the different objects you want to render. Each object is made up of geometry and the images that will be applied to the geometry. The scene object, the geometry objects and the images can be the same between OpenGL and Metal because they aren't specific to either. (I'm assuming here that the geometry is just a buffer of floating point coordinates, normals, etc. and the image starts out as a buffer of RGBA pixels on the CPU.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next you need to come up with a way to render those things on the hardware you're currently running on with the framework you wish to use. So you create an abstract interface. Perhaps you have a &lt;code&gt;Renderer&lt;/code&gt; object. It would have methods that allow you to add a piece of geometry with an image to use as the texture. It would allow you to associate a shader with the geometry. And it would have a method to render the geometry to either a texture or the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You then either subclass the &lt;code&gt;Renderer&lt;/code&gt; class (assuming you're using something like C++) or write a new class that implements the &lt;code&gt;Renderer&lt;/code&gt; protocol (if you're using something like Objective-C or Swift). You have 2 different subclasses or implementations. One that does things using OpenGL and one that does things using Metal. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you might have an &lt;code&gt;OGLRenderer&lt;/code&gt; and a &lt;code&gt;MTLRenderer&lt;/code&gt;. The &lt;code&gt;OGLRenderer&lt;/code&gt; class will implement the &lt;code&gt;addGeometry()&lt;/code&gt; method by creating a Vertex Buffer Object and eventually calling &lt;code&gt;glBufferData()&lt;/code&gt; to actually upload the geometry to the GPU. In your &lt;code&gt;MTLRenderer&lt;/code&gt; you'll create a &lt;code&gt;MTLBuffer&lt;/code&gt; via &lt;code&gt;-newBufferWithLength:options:&lt;/code&gt;, and then copying the data into the buffer with &lt;code&gt;memcpy()&lt;/code&gt;. And so on for the other functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when writing the main code for your application, you'll code to the &lt;code&gt;Renderer&lt;/code&gt; interface without knowing whether the underlying renderer that you're actually going to use is an OpenGL renderer or a Metal renderer. (In fact, you could even make it so they can be switched at run time if that would help in some way.) You can have a factory that either decides at run time which to use based on the OS you're on, or you can decide at compile time by only including the appropriate subclass.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-01-01T16:55:08.603" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6070" PostTypeId="1" AcceptedAnswerId="6072" CreationDate="2018-01-03T22:14:27.280" Score="4" ViewCount="740" Body="&lt;p&gt;Hello I have a simple application with some bright 2d mono-color shapes I am hoping to make appear emissive with a nice glow around them. To do that I am producing multiple gaussian blurs of varying kernels and resolutions and adding them all together to create a composite glow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have seen many guides mention this and even mention what sizes and kernels they are using to produce their bloom however they never mention the math they used to put them all together. Right now I am assuming it was just regular additive blending.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering what tips you might have to put this glow effect together effectively as far as if I should do anything other than just adding pixels together to combine the various maps. Should I do something with the weight on certain textures used in the composite? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am just trying to composite everything in an optimal manner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main concern is whether or not I should gamma correct my glow map or if that is accounted with the weights from the gaussian sampling or source material. Should I gamma correct my blurred composite before adding it to the source image?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2018-01-03T23:15:48.667" Title="Does a gaussian blur based bloom/glow shader require gamma correction? Any other tips?" Tags="&lt;gaussian-blur&gt;&lt;gamma&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6071" PostTypeId="2" ParentId="6070" CreationDate="2018-01-03T22:34:00.917" Score="2" Body="&lt;p&gt;You can get fancy with individual weighting on the blur maps if you want to adjust the look, but an equally weighted mix (and yes, it should be additive) will work too. I’m not sure about whether you need to gamma-correct the blurred image before adding it to the source one, but you should definitely get it into linear space before doing the blur; &lt;a href=&quot;https://ninedegreesbelow.com/photography/linear-gamma-blur-normal-blend.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; has some good illustrations as to why.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-01-03T22:34:00.917" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6072" PostTypeId="2" ParentId="6070" CreationDate="2018-01-03T23:15:48.667" Score="4" Body="&lt;h2&gt;In short:&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;You should not gamma correct your glow map. In fact, you should do everything in a &lt;strong&gt;linear color space&lt;/strong&gt;. At the very end, when doing any color grading (which is the very last step), you convert the final image to the right color space. The color space include that gamma correction.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;In long:&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Gamma correction is a step in the encoding of images. It is usually done so that we use more bits to store the shadows and less bits to store the highlights, since we see less detail in the highlights anyway. It is also part of some color spaces. These color spaces make sure the image looks the way it is supposed to. It is the final step, often part of color grading. Just before it is send out to the display, or saved to a file. This means that everything before should be in a linear color space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually things would look like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Load textures and convert them to a linear space, so you do not double gamma correct..&lt;/li&gt;&#xA;&lt;li&gt;Render the image.&lt;/li&gt;&#xA;&lt;li&gt;Do the post effects.&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Convert the image to the final color space with color grading. Probably sRGB Gamma. Converting to the color space includes the gamma correcting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Color grading is not necessary, but optional.&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;When having everything at linear and doing the gamma correction at the very end, you will need a high precision for the color. Using floating point framebuffers is recommended. When using the default 8-bit framebuffer the whole way, you end up getting banding effects when gamma correcting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This setup is not always done for games, to my knowledge, since most people will barely notice it or even care about it. In the film industry, VFX and animation, using the proper color space is more important.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When not doing it the 'right' way, the textures are not converted to linear and at the end, there is no gamma correction. Lights are supposed to have a quadratic falloff to be physically correct, but when gamma correcting it with a gamma of 2.0, it becomes a linear falloff. Lights can therefore get a linear falloff and look normal. As Noah Witherspoon pointed out, when blending and blurring you should use a linear color space, however this is not always done either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reasons for not doing it the 'right' way, is probably that it still looks fine. You do not need to do it this way, to end up with good graphics. It is always a matter of what the artist likes the most.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-01-03T23:15:48.667" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6073" PostTypeId="1" CreationDate="2018-01-05T04:53:47.597" Score="3" ViewCount="361" Body="&lt;p&gt;I'm trying to generate a random halftone like below image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/16706911/34595885-b1cf12fa-f1f0-11e7-95ee-4f255f522db8.jpg&quot; alt=&quot;2018-01-05_8-16-16&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;this is a simple halftone that I tried, but I need a random halftone&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float PI = 3.14159265359;&#xA;&#xA;    void mainImage(out vec4 fragColor, in vec2 fragCoord) {&#xA;        vec2 p = (fragCoord.xy / iResolution.xy - 0.5)/0.5;&#xA;&#xA;            vec3 n = vec3(p, sqrt(dot(p, p)));&#xA;            vec2 s = vec2(acos(n.z), atan(n.y, n.x))/PI;&#xA;            vec2 uv = fract(s * vec2(30.0, 30.0));&#xA;            float r = ceil(s.x * 30.0) / 17.0;&#xA;            fragColor =  vec4(1.)*step(length(uv - 0.5),r);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/MljBRw&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/MljBRw&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also tried using &lt;code&gt;for-loop&lt;/code&gt; and &lt;code&gt;sin&lt;/code&gt;,&lt;code&gt;cos&lt;/code&gt;, but I need a low computing method because I want generate it in the game engine.&lt;/p&gt;&#xA;" OwnerUserId="6541" LastEditorDisplayName="user7566" LastEditDate="2018-01-07T18:51:38.593" LastActivityDate="2018-05-10T12:17:33.680" Title="How to generate chaotic halftone pattern?" Tags="&lt;shader&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6075" PostTypeId="1" AcceptedAnswerId="6077" CreationDate="2018-01-05T15:49:18.350" Score="1" ViewCount="61" Body="&lt;p&gt;$A_{v}^{-1}$ = $A_{v}^{T}$&lt;br/&gt;&lt;br/&gt;&#xA;$A_{v}$ = Allignment matrix that alligns vector v with z axis&lt;br/&gt;&#xA;$=$\begin{bmatrix}&#xA;    \frac{\lambda}{|v|}       &amp;amp; \frac{-ab}{\lambda|v|} &amp;amp; \frac{-ac}{\lambda|v|} &amp;amp;   0 \\&#xA;    0 &amp;amp; \frac{c}{|v|} &amp;amp; \frac{-b}{|v|} &amp;amp;   0 \\&#xA;    \frac{a}{|v|}       &amp;amp; \frac{b}{|v|} &amp;amp; \frac{c}{|v|} &amp;amp;   0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&lt;br/&gt;&#xA;here, $\lambda = \sqrt{b^2+c^2} $&lt;br/&gt;&#xA;$|v| = \sqrt{a^2+b^2+c^2} $&lt;br/&gt;&#xA;And vector $v = (a, b, c)$&lt;/p&gt;&#xA;" OwnerUserId="7993" LastActivityDate="2018-01-05T17:26:08.587" Title="Why inverse of an allignment matrix is the same as its transpose?" Tags="&lt;matrix&gt;&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6076" PostTypeId="2" ParentId="5852" CreationDate="2018-01-05T16:31:55.403" Score="1" Body="&lt;p&gt;A rotation around the x-axis is achieved by this matrix&#xA;$$&#xA;\mathtt{T}_\mathrm{rot X} = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0&amp;amp; \cos \alpha&#xA;            &amp;amp; -\sin \alpha&amp;amp; 0 \\ 0 &amp;amp; \sin \alpha &amp;amp; \cos \alpha &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp;1 \\ \end{bmatrix} &#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to rotate around the x-axis in the viewing space, one needs to think about when to apply the above transformation in the chain of transformations that is applied to the 3D model vertices $\mathbf{X}_{\mathrm{3d}}$ in the employed rendering pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A typical transformation chain is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\mathbf{X}_{\mathrm{view}} = \mathtt{T}_{\mathrm{projection}} \,\mathtt{T}_{\mathrm{camera\ transform}}\,&#xA;\mathtt{T}_{\mathrm{mesh\ transform}}\,\mathbf{X}_{\mathrm{3d}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's split the camera tranformation into its rotational and translational part:&#xA;$$&#xA;\mathbf{X}_{\mathrm{view}} = \mathtt{T}_{\mathrm{projection}} \,\underbrace{\mathtt{T}_{\mathrm{cam\ trans}}\,\mathtt{T}_{\mathrm{cam\ rot}}}_{\mathtt{T}_{\mathrm{camera\ transform}}}\,&#xA;\mathtt{T}_{\mathrm{mesh\ transform}}\,\mathbf{X}_{\mathrm{3d}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we need to apply the x-rotation in-between the camera rotation and translation, because we want to have the rotation of the camera applied beforehand, but not the camera's translation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\mathbf{X}_{\mathrm{view}} = \mathtt{T}_{\mathrm{projection}} \,\underbrace{\mathtt{T}_{\mathrm{cam\ trans}}\,\mathtt{T}_\mathrm{rot X}\,\mathtt{T}_{\mathrm{cam\ rot}}}_{\mathtt{T}_{\mathrm{new\ camera\ transform}}}\,&#xA;\mathtt{T}_{\mathrm{mesh\ transform}}\,\mathbf{X}_{\mathrm{3d}}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This would achieve the desired rotation, but typically we do not want to change the camera transformation but the the mesh transformation. This is achieved by&#xA;$$&#xA;\mathbf{X}_{\mathrm{view}} = \mathtt{T}_{\mathrm{projection}} \,\mathtt{T}_{\mathrm{cam\ trans}}\,\mathtt{T}_\mathrm{rot X}\,\mathtt{T}_{\mathrm{cam\ rot}}\,&#xA;\mathtt{T}_{\mathrm{mesh\ transform}}\,\mathbf{X}_{\mathrm{3d}}\\&#xA;\Leftrightarrow \mathbf{X}_{\mathrm{view}} = \mathtt{T}_{\mathrm{projection}} \,\mathtt{T}_{\mathrm{cam\ trans}}\,(\mathtt{T}_{\mathrm{cam\ rot}}\,\mathtt{T}_{\mathrm{cam\ rot}}^{-1})\,\mathtt{T}_\mathrm{rot X}\,\mathtt{T}_{\mathrm{cam\ rot}}\,&#xA;\mathtt{T}_{\mathrm{mesh\ transform}}\,\mathbf{X}_{\mathrm{3d}}\\&#xA;\Leftrightarrow \mathbf{X}_{\mathrm{view}} = \mathtt{T}_{\mathrm{projection}} \,\mathtt{T}_{\mathrm{camera\ transform}}\,\underbrace{\mathtt{T}_{\mathrm{cam\ rot}}^{-1}\,\mathtt{T}_\mathrm{rot X}\,\mathtt{T}_{\mathrm{cam\ rot}}\,&#xA;\mathtt{T}_{\mathrm{mesh\ transform}}}_{\mathtt{T}_{\mathrm{new\ mesh\ transform}}}\,\mathbf{X}_{\mathrm{3d}}&#xA;$$&#xA;&lt;strong&gt;Therefore, the short answer to your question is:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Left-multiply the current transformation matrix of your model with $\mathtt{T}_{\mathrm{cam\ rot}}^{-1}\,\mathtt{T}_\mathrm{rot X}\,\mathtt{T}_{\mathrm{cam\ rot}}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/plks2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/plks2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have generated an &quot;cow&quot; example scene in the GSN Composer that can be used for interactive testing in a WebGL-capable browser:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.gsn-lib.org/docs/gallery.php?projectName=CowQuestion&amp;amp;graphName=cow&quot; rel=&quot;nofollow noreferrer&quot;&gt;Example: CowQuestion | GSN Composer&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4652" LastEditorDisplayName="user7220" LastEditDate="2018-03-07T11:54:23.580" LastActivityDate="2018-03-07T11:54:23.580" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6077" PostTypeId="2" ParentId="6075" CreationDate="2018-01-05T17:20:28.070" Score="2" Body="&lt;p&gt;To align vectors, you are applying a rotation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you consider a simple rotation matrix, e.g. rotation of angle $\theta$ around Z axis, then you will trivially see that its inverse matrix, a rotation of $-\theta$, is the transpose,  since $sin(-\theta)=-sin(\theta)$ and $cos(-\theta)=cos(\theta)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An arbitrary rotation matrix, R, can be constructed by multiplication of other rotations, e.g $R = A \cdot B$.  If the inverse of A and B exist, then $R^{-1} = B^{-1} \cdot A^{-1}$.&lt;br&gt;&#xA;Similarly we know  $(A \cdot B)^T = (B^T \cdot A^T)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Put these together and you have your answer.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-01-05T17:26:08.587" LastActivityDate="2018-01-05T17:26:08.587" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6078" PostTypeId="1" CreationDate="2018-01-05T17:42:04.120" Score="5" ViewCount="151" Body="&lt;p&gt;I am following the &lt;a href=&quot;https://webgl2fundamentals.org/webgl/lessons/webgl-3d-lighting-directional.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;WebGL2Fundametals tutorial&lt;/a&gt;. Using some sample (cube) data I was able to successfully call &lt;code&gt;gl.drawElements();&lt;/code&gt; using index, normal and geometry data. This are my fragment and vertex shaders:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es    &#xA;precision mediump float;&#xA;&#xA;in vec3 v_normal;&#xA;in vec3 v_surfaceToLight;&#xA;in vec3 v_surfaceToView;&#xA;&#xA;uniform vec4 u_color;&#xA;uniform float u_shininess;&#xA;uniform vec3 u_lightDirection;&#xA;&#xA;uniform float u_innerLimit; // In dot space&#xA;uniform float u_outerLimit; // In dot space&#xA;&#xA;out vec4 outColor;&#xA;&#xA;void main() {&#xA;  vec3 normal = normalize(v_normal);&#xA;&#xA;  vec3 surfaceToLightDirection = normalize(v_surfaceToLight);&#xA;  vec3 surfaceToViewDirection = normalize(v_surfaceToView);&#xA;  vec3 halfVector = normalize(surfaceToLightDirection + surfaceToViewDirection);&#xA;&#xA;  float dotFromDirection = dot(surfaceToLightDirection, -u_lightDirection);&#xA;  float inLight = smoothstep(u_outerLimit, u_innerLimit, dotFromDirection);&#xA;  // Using normals for color calculation based on the incidence of light&#xA;  float light = inLight * dot(normal, surfaceToLightDirection);&#xA;  float specular = inLight * pow(dot(normal, halfVector), u_shininess);&#xA;&#xA;  outColor = u_color;&#xA;&#xA;  outColor.rgb *= light;&#xA;&#xA;  // Add in the specular&#xA;  outColor.rgb += specular;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;in vec4 a_position;&#xA;in vec3 a_normal;&#xA;&#xA;uniform mat4 u_world;&#xA;uniform mat4 u_worldViewProjection;&#xA;uniform mat4 u_worldInverseTranspose;&#xA;&#xA;uniform vec3 u_lightWorldPosition;&#xA;uniform vec3 u_viewWorldPosition;&#xA;&#xA;// varying to pass the normal to the fragment shader&#xA;out vec3 v_normal;&#xA;&#xA;out vec3 v_surfaceToLight;&#xA;out vec3 v_surfaceToView;&#xA;&#xA;void main() {&#xA;&#xA;  gl_Position = u_worldViewProjection * a_position;&#xA;&#xA;  // Orient the normals and pass to the fragment shader&#xA;  v_normal = mat3(u_worldInverseTranspose) * a_normal;&#xA;&#xA;  vec3 surfaceWorldPosition = (u_world * a_position).xyz;&#xA;  v_surfaceToLight = u_lightWorldPosition - surfaceWorldPosition;&#xA;  v_surfaceToView = u_viewWorldPosition - surfaceWorldPosition;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With the following call the cube is successfully rendered:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, this._indexBuffer);&#xA;GLHelper.setUniformValues(this._uniforms, uniformValues);&#xA;gl.drawElements(gl.TRIANGLES, 36, gl.UNSIGNED_SHORT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the working cube data:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; // Front face&#xA;-100, -100, 100,&#xA; 100, -100, 100,&#xA; 100,  100, 100,&#xA;-100,  100, 100,&#xA;&#xA; // Back face&#xA;-100, -100, -100,&#xA;-100,  100, -100,&#xA; 100,  100, -100,&#xA; 100, -100, -100,&#xA;&#xA; // Top face&#xA;-100,  100, -100,&#xA;-100,  100,  100,&#xA; 100,  100,  100,&#xA; 100,  100, -100,&#xA;&#xA; // Bottom face&#xA;-100, -100, -100,&#xA; 100, -100, -100,&#xA; 100, -100,  100,&#xA;-100, -100,  100,&#xA;&#xA; // Right face&#xA; 100, -100, -100,&#xA; 100,  100, -100,&#xA; 100,  100,  100,&#xA; 100, -100,  100,&#xA;&#xA; // Left face&#xA;-100, -100, -100,&#xA;-100, -100,  100,&#xA;-100,  100,  100,&#xA;-100,  100, -100,&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Normals:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; // Front&#xA; 0.0,  0.0,  1.0,&#xA; 0.0,  0.0,  1.0,&#xA; 0.0,  0.0,  1.0,&#xA; 0.0,  0.0,  1.0,&#xA;&#xA; // Back face&#xA; 0.0,  0.0, -1.0,&#xA; 0.0,  0.0, -1.0,&#xA; 0.0,  0.0, -1.0,&#xA; 0.0,  0.0, -1.0,&#xA;&#xA; // Top face&#xA; 0.0,  1.0,  0.0,&#xA; 0.0,  1.0,  0.0,&#xA; 0.0,  1.0,  0.0,&#xA; 0.0,  1.0,  0.0,&#xA;&#xA; // Bottom face&#xA; 0.0, -1.0,  0.0,&#xA; 0.0, -1.0,  0.0,&#xA; 0.0, -1.0,  0.0,&#xA; 0.0, -1.0,  0.0,&#xA;&#xA; // Right face&#xA; 1.0,  0.0,  0.0,&#xA; 1.0,  0.0,  0.0,&#xA; 1.0,  0.0,  0.0,&#xA; 1.0,  0.0,  0.0,&#xA;&#xA; // Left face&#xA;-1.0,  0.0,  0.0,&#xA;-1.0,  0.0,  0.0,&#xA;-1.0,  0.0,  0.0,&#xA;-1.0,  0.0,  0.0,&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Indices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 0,  1,  2,  0,  2,  3, // Front face&#xA; 4,  5,  6,  4,  6,  7, // Back face&#xA; 8,  9, 10,  8, 10, 11, // Top face&#xA;12, 13, 14, 12, 14, 15, // Bottom face&#xA;16, 17, 18, 16, 18, 19, // Right face&#xA;20, 21, 22, 20, 22, 23, // Left face&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I get it right the normals in this model should look something like the cube's normals in &lt;a href=&quot;https://webgl2fundamentals.org/webgl/lessons/webgl-3d-lighting-directional.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;the very first animation in the &quot;Introducing normals&quot; part&lt;/a&gt;. Now I was trying to create and import a cube using Blender.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately I wasn't able to recreate a cube with the same kind of normals. Blender generates only one (pink) normal per vertex and they also obviously have a totally different angle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JhiETm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JhiETm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://blender.stackexchange.com/a/14697&quot;&gt;Some sources&lt;/a&gt; suggest that smoothing the faces would fix this issue. It did not for me. Here is the Wavefront file:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;o Cube&#xA;v   1.000000 -1.000000 -1.000000&#xA;v   1.000000 -1.000000  1.000000&#xA;v  -1.000000 -1.000000  1.000000&#xA;v  -1.000000 -1.000000 -1.000000&#xA;v   1.000000  1.000000 -0.999999&#xA;v   0.999999  1.000000  1.000001&#xA;v  -1.000000  1.000000  1.000000&#xA;v  -1.000000  1.000000 -1.000000&#xA;vn  0.0000   -1.0000    0.0000&#xA;vn  0.0000    1.0000    0.0000&#xA;vn  1.0000   -0.0000    0.0000&#xA;vn  0.0000   -0.0000    1.0000&#xA;vn -1.0000   -0.0000   -0.0000&#xA;vn  0.0000    0.0000   -1.0000&#xA;s off&#xA;f 1//1 3//1 4//1&#xA;f 8//2 6//2 5//2&#xA;f 5//3 2//3 1//3&#xA;f 6//4 3//4 2//4&#xA;f 3//5 8//5 4//5&#xA;f 1//6 8//6 5//6&#xA;f 1//1 2//1 3//1&#xA;f 8//2 7//2 6//2&#xA;f 5//3 6//3 2//3&#xA;f 6//4 7//4 3//4&#xA;f 3//5 7//5 8//5&#xA;f 1//6 4//6 8//6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I try to import and to render this data using &lt;code&gt;gl.drawElements(gl.TRIANGLES, 72, gl.UNSIGNED_SHORT, 0);&lt;/code&gt; I get the following output:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;ERROR :GL_INVALID_OPERATION : glDrawElements: attempt to access out of&#xA;  range vertices in attribute 1&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If I use above (.obj) vertex and normal data six time each I do not get any more errors but instead of a cube only a single triangle seems to be rendered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JFspWm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JFspWm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am pretty sure that &lt;code&gt;attribute 1&lt;/code&gt; is &lt;code&gt;in vec3 a_normal;&lt;/code&gt; in my vertex shader. So I am mainly confused about one thing here:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;How do I modify my code in order to interpret and render the data&#xA;correctly?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After changing indices to be zero based I do get more than a single triangle, the object still looks wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VpR3l.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VpR3l.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result drawn with &lt;code&gt;gl.LINES&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/88klr.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/88klr.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2485" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T09:06:07.723" LastActivityDate="2018-03-06T09:06:07.723" Title="Unable to render a Waveront model in WebGL2" Tags="&lt;webgl&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6079" PostTypeId="2" ParentId="6073" CreationDate="2018-01-05T20:04:08.070" Score="0" Body="&lt;p&gt;Years ago, Pete Warden wrote either a blog post or perhaps it was an entry in one of the GPGPU Gems books where he described how to generate similar patterns. I believe that when he was at Apple, he implemented this as the &quot;Cellular&quot; generator in Motion. It looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PcrCm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PcrCm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm unable to find the original blog post or whatever it was, but if I recall correctly, it was generated like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Generate a list of random locations for the &quot;cells&quot;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;At each cell's location, draw a small circle where:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.1. the depth at each pixel is the inverse of the distance to the center (so highest at the center, and lowest at the edges)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2.2. the color is a radial gradient (in this case black at the center, white at the edges)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I think if you further modified this algorithm to make the radius of each cell be related to the luminance of an input image at its location or make its color lighter for higher luminance positions, you could get such a half-tone look.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-01-05T20:04:08.070" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6080" PostTypeId="2" ParentId="6040" CreationDate="2018-01-05T21:57:29.987" Score="1" Body="&lt;p&gt;As you’ve found, it’s hard to use a two-dimensional format, even from multiple viewpoints, to represent a 3D structure that’s not axis-aligned. I’m not sure I have a useful suggestion there—there’s a reason most 3D file formats support specifying translation/rotation/scaling of individual parts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A different direction you might try would be using the existing work in the &lt;a href=&quot;https://ldraw.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;LDraw&lt;/a&gt; project; their &lt;a href=&quot;http://www.ldraw.org/article/218&quot; rel=&quot;nofollow noreferrer&quot;&gt;file format&lt;/a&gt; is technically ASCII, and though it’s closer to a standard 3D format in that the fundamental parts (like studs) are built out of lists of vertices / triangles / etc., the higher-level pieces (bricks, plates, etc.) are built out of references to the fundamental ones, which sounds like it’s roughly along the lines of what you’re after. There’s an &lt;a href=&quot;http://www.ldraw.org/downloads-2/third-party-software.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;assortment&lt;/a&gt; of third-party design tools that provide GUIs on top of the LDraw parts library; of those, I’m partial to &lt;a href=&quot;http://bricksmith.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bricksmith&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-01-05T21:57:29.987" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6081" PostTypeId="1" AcceptedAnswerId="6097" CreationDate="2018-01-05T22:14:44.387" Score="4" ViewCount="1413" Body="&lt;p&gt;How does &lt;code&gt;Map()&lt;/code&gt; work? I would guess that it allocates memory to fit the resource size (or a range of it), but when are the bytes sent to the GPU?&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorUserId="506" LastEditDate="2018-01-05T22:32:31.453" LastActivityDate="2018-01-09T23:05:37.227" Title="How does ID3D12Resource::Map work?" Tags="&lt;directx12&gt;&lt;synchronization&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6082" PostTypeId="2" ParentId="5852" CreationDate="2018-01-06T12:27:57.693" Score="0" Body="&lt;p&gt;To get the axis of rotation you could multiply the x-axis by the inverse of the view matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$b = V^{-1} e_1$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $b$ is the axis of rotation in world space, $V$ is the view matrix and $e_1$ is the x-axis unit vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, to make the object to spin around the axis of rotation $b$, we have to translate the object back to the origin, spin it, and then translate it back to its position in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose you have a translation matrix $T$ that send the origin point to the object's location. The translated rotation (spin) of the object $M$ would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$M = T R T^{-1}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $R$ is the rotation matrix around the $b$ axis. The matrix $R$ could be obtained using the Rodrigues formula or from a Quaternion or through some other methods out there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally you need to multiply the matrix $M$ to the existing transformation matrix of the object $W$. $W' = M W$ and use $W'$ for transforming the object.&lt;/p&gt;&#xA;" OwnerUserId="7957" LastActivityDate="2018-01-06T12:27:57.693" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6084" PostTypeId="2" ParentId="6073" CreationDate="2018-01-06T18:20:57.127" Score="1" Body="&lt;p&gt;I could make it by Worley noise&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Worley noise is a noise function introduced by Steven Worley in 1996. In computer graphics it is used to create procedural textures,that is textures that are created automatically in arbitrary precision and don't have to be drawn by hand. Worley noise comes close to simulating textures of stone, water, or cell noise.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://thebookofshaders.com/12/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://thebookofshaders.com/12/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifdef GL_ES&#xA;precision mediump float;&#xA;#endif&#xA;&#xA;uniform vec2 u_resolution;&#xA;uniform float u_time;&#xA;&#xA;// Permutation polynomial: (34x^2 + x) mod 289&#xA;vec4 permute(vec4 x) {&#xA;  return mod((34.0 * x + 1.0) * x, 289.0);&#xA;}&#xA;vec3 permute(vec3 x) {&#xA;  return mod((34.0 * x + 1.0) * x, 289.0);&#xA;}&#xA;&#xA;// Cellular noise, returning F1 and F2 in a vec2.&#xA;// Speeded up by using 2x2x2 search window instead of 3x3x3,&#xA;// at the expense of some pattern artifacts.&#xA;// F2 is often wrong and has sharp discontinuities.&#xA;// If you need a good F2, use the slower 3x3x3 version.&#xA;vec2 cellular2x2x2(vec3 P) {&#xA;    #define K 0.142857142857 // 1/7&#xA;    #define Ko 0.428571428571 // 1/2-K/2&#xA;    #define K2 0.020408163265306 // 1/(7*7)&#xA;    #define Kz 0.166666666667 // 1/6&#xA;    #define Kzo 0.416666666667 // 1/2-1/6*2&#xA;    #define jitter 0.8 // smaller jitter gives less errors in F2&#xA;    vec3 Pi = mod(floor(P), 289.0);&#xA;    vec3 Pf = fract(P);&#xA;    vec4 Pfx = Pf.x + vec4(0.0, -1.0, 0.0, -1.0);&#xA;    vec4 Pfy = Pf.y + vec4(0.0, 0.0, -1.0, -1.0);&#xA;    vec4 p = permute(Pi.x + vec4(0.0, 1.0, 0.0, 1.0));&#xA;    p = permute(p + Pi.y + vec4(0.0, 0.0, 1.0, 1.0));&#xA;    vec4 p1 = permute(p + Pi.z); // z+0&#xA;    vec4 p2 = permute(p + Pi.z + vec4(1.0)); // z+1&#xA;    vec4 ox1 = fract(p1*K) - Ko;&#xA;    vec4 oy1 = mod(floor(p1*K), 7.0)*K - Ko;&#xA;    vec4 oz1 = floor(p1*K2)*Kz - Kzo; // p1 &amp;lt; 289 guaranteed&#xA;    vec4 ox2 = fract(p2*K) - Ko;&#xA;    vec4 oy2 = mod(floor(p2*K), 7.0)*K - Ko;&#xA;    vec4 oz2 = floor(p2*K2)*Kz - Kzo;&#xA;    vec4 dx1 = Pfx + jitter*ox1;&#xA;    vec4 dy1 = Pfy + jitter*oy1;&#xA;    vec4 dz1 = Pf.z + jitter*oz1;&#xA;    vec4 dx2 = Pfx + jitter*ox2;&#xA;    vec4 dy2 = Pfy + jitter*oy2;&#xA;    vec4 dz2 = Pf.z - 1.0 + jitter*oz2;&#xA;    vec4 d1 = dx1 * dx1 + dy1 * dy1 + dz1 * dz1; // z+0&#xA;    vec4 d2 = dx2 * dx2 + dy2 * dy2 + dz2 * dz2; // z+1&#xA;&#xA;    // Sort out the two smallest distances (F1, F2)&#xA;#if 0&#xA;    // Cheat and sort out only F1&#xA;    d1 = min(d1, d2);&#xA;    d1.xy = min(d1.xy, d1.wz);&#xA;    d1.x = min(d1.x, d1.y);&#xA;    return sqrt(d1.xx);&#xA;#else&#xA;    // Do it right and sort out both F1 and F2&#xA;    vec4 d = min(d1,d2); // F1 is now in d&#xA;    d2 = max(d1,d2); // Make sure we keep all candidates for F2&#xA;    d.xy = (d.x &amp;lt; d.y) ? d.xy : d.yx; // Swap smallest to d.x&#xA;    d.xz = (d.x &amp;lt; d.z) ? d.xz : d.zx;&#xA;    d.xw = (d.x &amp;lt; d.w) ? d.xw : d.wx; // F1 is now in d.x&#xA;    d.yzw = min(d.yzw, d2.yzw); // F2 now not in d2.yzw&#xA;    d.y = min(d.y, d.z); // nor in d.z&#xA;    d.y = min(d.y, d.w); // nor in d.w&#xA;    d.y = min(d.y, d2.x); // F2 is now in d.y&#xA;    return sqrt(d.xy); // F1 and F2&#xA;#endif&#xA;}&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord ){&#xA;&#xA;    vec2 uv = (fragCoord.xy - iResolution.xy*.5)/iResolution.y;&#xA;&#xA;    float w = 1. - dot(uv, uv)*3.;&#xA;&#xA;    uv *= 48.;    &#xA;    vec2 ip = floor(uv);&#xA;    vec2 v = cellular2x2x2(vec3(uv, iTime/2.));&#xA;&#xA;    float c = v.x; //v.y - v.x&#xA;&#xA;    c -= .35*w;&#xA;&#xA;    c = smoothstep(0., max(.1/c, 0.), c);&#xA;&#xA;    vec3 col = mix(vec3(0), vec3(1), c);&#xA;&#xA;    fragColor = vec4(sqrt(max(col, 0.)), 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;you can see this In shadertoy &lt;a href=&quot;https://www.shadertoy.com/view/XlSBDz&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/XlSBDz&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6541" LastActivityDate="2018-01-06T18:20:57.127" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6085" PostTypeId="1" CreationDate="2018-01-07T02:37:29.947" Score="1" ViewCount="307" Body="&lt;p&gt;I'm currently making a small 3D renderer and I got stuck in Phong shading.&lt;/p&gt;&#xA;&lt;p&gt;My questions are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Into which space should the light coordinate be converted?&lt;/p&gt;&#xA;&lt;p&gt;I have my light position at world coordinates (0,0,0). I'd like to calculate &amp;quot;phong shading&amp;quot; after converting all the vertices to screen space (viewport).&#xA;So Should I convert the light position to screen space too?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Is there a faster way to calculate Phong shading with normal interpolation if the camera's position equals the light's position?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="7999" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-06-26T03:03:45.330" Title="Light coordinate in Phong shading and Normal interpolation" Tags="&lt;rasterizer&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6086" PostTypeId="2" ParentId="6085" CreationDate="2018-01-07T04:24:10.463" Score="1" Body="&lt;p&gt;Typically, you calculate lighting in either world-space or view-space (or camera-space). The benefit to calculating it in camera-space is the increased precision, although this may involve introduce additional math operations in shaders depending on your setup. So it wouldn't be in screenspace, or you would need to reconstruct the positions (which could happen in deferred shading depending on your G-buffer layout).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume you are talking about a punctual light type (such as a point light). If so, if your light position equals your camera position, then the view and light angles are the same, which can be factored out in the BRDF that you use, so you save a dot product.&lt;/p&gt;&#xA;" OwnerUserId="2707" LastEditorUserId="2707" LastEditDate="2018-01-07T04:55:30.677" LastActivityDate="2018-01-07T04:55:30.677" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6087" PostTypeId="1" AcceptedAnswerId="6093" CreationDate="2018-01-07T05:29:13.453" Score="2" ViewCount="3930" Body="&lt;p&gt;I'm trying to figure out how to reverse Eye space -&gt; projection -&gt; clip(divide by w) -&gt; screen space conversion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, I want to get Screen space (still have z value for z-buffer) -&gt; undivide? by w -&gt; inverse projection. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found the inverse matrix for projection but can't figure out how to get the coordinate &quot;undivided&quot; by w.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="7999" LastActivityDate="2018-01-08T17:03:19.327" Title="Screen space coordinates to Eye space conversion" Tags="&lt;matrix&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6088" PostTypeId="1" AcceptedAnswerId="6107" CreationDate="2018-01-07T05:43:47.720" Score="1" ViewCount="292" Body="&lt;p&gt;I recently set up temporal super-sampling in my path-tracer, and now I'm trying to improve early samples by adding random offsets between -[PIXEL_WIDTH] and +[PIXEL_WIDTH] to each initial ray position. The jitter works &lt;em&gt;well enough&lt;/em&gt; and hides obvious aliasing artifacts, but it creates tattered edges (e.g: &lt;a href=&quot;https://imgur.com/a/VIWPK&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://imgur.com/a/VIWPK&lt;/a&gt; is my test shape after one sample/pixel) instead of regular grain. Is there any way to change that?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-01-07T06:00:24.390" LastActivityDate="2018-01-13T07:04:08.723" Title="Structural artifacts in ray jitter" Tags="&lt;pathtracing&gt;&lt;antialiasing&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6090" PostTypeId="1" CreationDate="2018-01-07T20:34:28.977" Score="2" ViewCount="58" Body="&lt;p&gt;At least on iOS every frame you are likely to get a completely new texture that you need to draw to due to the OS switching between a couple textures each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is essentially if the OS feels the need to use multiple textures should we also be using multiple textures for some reason when doing full screen post processing? Is there ever a time where switching between off screen textures can improve performance? &lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2018-01-07T23:25:01.763" Title="If the OS uses a frame-buffer with potentially different textures being displayed each frame why dont we?" Tags="&lt;texture&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6091" PostTypeId="2" ParentId="6090" CreationDate="2018-01-07T23:25:01.763" Score="3" Body="&lt;p&gt;The compositor in the OS wants to run at a consistent 60 FPS whatever rate your application runs at. If there were a single framebuffer for your application, then you might end up writing to it at the same time the compositor or overlay hardware wants to read from it to put it into the final frame. This would cause tearing. (Tearing could be avoided with a lock, but then the compositor might get stuck waiting for your frame to finish, which would also stop the user using the system GUI to get out of your slow/hanging app.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is pretty much the same reason double buffering is used when you're drawing to a monitor directly, just earlier in the pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This doesn't &lt;em&gt;usually&lt;/em&gt; apply for processing within your application, because generally everything has to run at the same rate, and you can't run multiple stages in parallel. Say you draw some 3D stuff and then use a full-screen fragment shader to add some film grain and vignetting. It doesn't help if your full-screen shader can run faster than the 3D work, because you'll just be processing the same intermediate frames again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can think of two situations really where it might help. The first is if it's not a post-process but something different, such as if you have a GUI or HUD that you want to run at full frame-rate even if you get frame drops in the main content. (This is the case the OS's window compositor falls into.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second is if you can run the multiple stages of your processing pipeline in parallel, e.g. on multiple GPUs. That way, you can start rendering the next 3D frame while the full-screen shader is vignetting your previous frame. You'd have to know your hardware pretty well to split the work appropriately. On something like a gaming PC or graphics workstation that's using SLI to use multiple GPUs, you might find your parallel processing is slower because the workload is unbalanced and one GPU is idling a lot.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-01-07T23:25:01.763" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6092" PostTypeId="2" ParentId="6087" CreationDate="2018-01-08T08:18:21.850" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;clip(divide by w) -&gt; screen space&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Be careful, if you're really in screen space. My guess is, you're doing picking or deferred rendering, in which case you're probably reading fragments in Normalized Device Space (i.e. x and y in range &lt;code&gt;[-1, 1]&lt;/code&gt;*).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so, you can do it like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Read out Normalized Device Coordinates as &lt;code&gt;vec4&lt;/code&gt; with depth as z value and &lt;code&gt;1.0&lt;/code&gt; as w value and bring them into &lt;code&gt;[0, 1]&lt;/code&gt; range by multiplying by &lt;code&gt;2&lt;/code&gt; and subtracting &lt;code&gt;1&lt;/code&gt;.&#xA;Convert them into Eye Space with the inverted projection matrix.&#xA;Divide your new vector by its &lt;code&gt;w&lt;/code&gt; coordinate (which is your undivide step). Now you're in Eye Space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are more ways to do this, you can have a look at &lt;a href=&quot;https://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Reconstructing Position From Depth&lt;/a&gt; to dive further into how.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;*I'm assuming OpenGL, ranges might be different in DirectX&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-01-08T08:18:21.850" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6093" PostTypeId="2" ParentId="6087" CreationDate="2018-01-08T17:03:19.327" Score="3" Body="&lt;p&gt;Object Space → World Space → Eye Space → Clip Space → Normalized Device Space → Window Space&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You get from Object Space to World Space by multiplying by the &quot;World&#xA;Matrix&quot; (This may actually be multiple matrices depending&#xA;on the parent-child object hierarchy of the scene.  Compose them all together to get a single &quot;World Matrix&quot; for a given object.)&lt;/li&gt;&#xA;&lt;li&gt;You get from World Space to Eye Space by multiplying by the &quot;View Matrix&quot;.&lt;/li&gt;&#xA;&lt;li&gt;You get from Eye Space to Clip Space by multiplying by the &quot;Projection Matrix&quot;.&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You get from Clip Space to Normalized Device Space by performing the &quot;perspective divide&quot; (divide by w in clip space coordinates).  &lt;strong&gt;This is a non-linear transformation&lt;/strong&gt; requiring a divide, and is not represented by a matrix.  &lt;strong&gt;Information can be destroyed in this step.&lt;/strong&gt;  If w is divided by w you just get 1, and there's no way to recover the original w.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PqSr6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PqSr6.png&quot; alt=&quot;Divide by w&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You get from Normalized Device Space to Window Space by performing the Viewport and Depth Range transform. (Simple linear relationship)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xGOwn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xGOwn.png&quot; alt=&quot;Viewport Transform&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vVEX9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vVEX9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The World Matrix, View Matrix, and Projection Matrix are all just 4x4 matrices and can be inverted to get the reverse transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, to go backwards...&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You get from Window Space to Normalized Device Space by performing the inverse of the Viewport and Depth Range transform.&lt;/li&gt;&#xA;&lt;li&gt;You can get from Normalized Device Space to Clip Space by performing the inverse of the perspective divide (multiply by w).  &lt;strong&gt;This is a non-linear transformation&lt;/strong&gt; requiring a multiply, and is not represented by a matrix.  In general this operation doesn't magically recover 3D data from 2D data.  You must know something about the depth externally to be able to recover the 3D position of a point on the 2D screen.&lt;/li&gt;&#xA;&lt;li&gt;You can get from Clip Space to Eye Space by multiplying by the inverse of the &quot;Projection Matrix&quot;&lt;/li&gt;&#xA;&lt;li&gt;You can get from Eye Space to World Space by multiplying by the inverse of the &quot;View Matrix&quot;.&lt;/li&gt;&#xA;&lt;li&gt;You can get from World Space to Object Space by multiplying by the inverse of the &quot;World Matrix&quot;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;May I suggest reading &lt;a href=&quot;http://www.songho.ca/opengl/gl_transform.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this explanation of the OpenGL Transformation&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8009" LastActivityDate="2018-01-08T17:03:19.327" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6094" PostTypeId="1" CreationDate="2018-01-08T23:38:21.603" Score="4" ViewCount="343" Body="&lt;p&gt;I want to create a &quot;river biome&quot; where there are rivers cutting to a flat land mass, to start I wrote a little js to generate a random height map (with simplex noise) but that's where I'm stuck.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;this is what it generates:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/FNwDW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FNwDW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as you can see there are clear diagonal lines in there.&#xA;I tried looking up how to fix this and on my search I found these:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/283/is-all-grid-based-noise-inevitably-anisotropic&quot;&gt;Is all grid based noise inevitably anisotropic?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2447/why-does-my-perlin-noise-look-blocky&quot;&gt;Why does my Perlin Noise look &amp;quot;blocky&amp;quot;?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I don't know if this is my problem of if it's something else entirely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;here's the significant part of my code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for(var y = 0;y &amp;lt; myRivers.height;y++){&#xA;    for(var x = 0;x &amp;lt; myRivers.width;x++){&#xA;        lightness = simplexnoise(x/50,y/50); // number between -1 and 1&#xA;        myRivers.context.fillStyle = lightnessToRgb(lightness); //maps lightness to a color&#xA;        myRivers.context.fillRect(x * 4, y * 4, 4, 4); // fills a pixel with the color&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;a codepen: &lt;a href=&quot;https://codepen.io/anon/pen/gooyMj&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://codepen.io/anon/pen/gooyMj&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5965" LastEditorUserId="5965" LastEditDate="2018-01-08T23:50:01.050" LastActivityDate="2020-07-21T20:06:40.580" Title="unwanted patterns in simplex noise" Tags="&lt;noise&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="6095" PostTypeId="2" ParentId="6081" CreationDate="2018-01-09T12:28:29.443" Score="1" Body="&lt;p&gt;First you may want to take a look at &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dn788712%28v=vs.85%29.aspx?f=255&amp;amp;MSPPError=-2147217396&quot; rel=&quot;nofollow noreferrer&quot;&gt;the doc&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Map basically allows you to retrieve a CPU pointer of a GPU resource. It performs a few operations on the background so the data is up to date. Depending on the type of resource you are mapping, you can perform different tasks like reading data or copying it. As far as I know, Map will only allocate an address not the memory of the resource.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope it helps!&lt;/p&gt;&#xA;" OwnerUserId="7107" LastActivityDate="2018-01-09T12:28:29.443" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6096" PostTypeId="2" ParentId="6078" CreationDate="2018-01-09T22:00:41.943" Score="3" Body="&lt;p&gt;The problem is with how wavefront files and OpenGL work with indices.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;OpenGL&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;OpenGL allows you to have different buffers, allowing your vertex to have multiple attributes. However, for every vertex in a face, it has only one index.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us say that we have a quad. It consists out of a position buffer and a uv buffer. The positions would look like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1, 1, 0;  -1, 1, 0;  -1, -1, 0;  1, -1, 0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The uv's would look like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0, 0;     1, 0;      1, 1;       0, 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The indices would look like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0, 1, 2, 0, 2, 3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When OpenGL does it's rendering, it looks at the index for the location of the data. If we have the very first vertex of the very first face, with the index of 0. It then picks the position with the index of 0: &lt;code&gt;(1, 1, 0)&lt;/code&gt;. Then it picks the uv with also the index of zero: &lt;code&gt;(0, 0)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the same index for each attribute means that all data can be sequentially stored in one long buffer. If OpenGL needs the data for a vertex, it only has to load one long strip of data. This is better for the cache than having to go to different parts of the memory to find all the information for just one vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;OpenGL uses the same index for all vertex attributes. You cannot tell OpenGL to take position number 3 with uv number 1.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Wavefront&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Wavefront works differently. When doing the indexing, it indexes each attribute separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a declaration of a face&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;f 5//3 2//3 1//3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We see three vertices, separated by a white space. Each vertex has two numbers. The first number is the index for the position. The second number is the index for the normal. They are both different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wavefront does not need to care about caching. It just needs to store the data by using the least amount of memory (if we load everything in to memory. Saving it in plain text is of course not efficient). When looking at your .obj file, we can see that we have 8 positions, but only 6 normals. We have been able to remove 6 floating point numbers in total (2 normals consisting of 3 floats).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Wavefront specifies different indices for each vertex attribute. For a vertex, the position could be number 5, but the normal is number 4.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Conclusion&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Wavefront and OpenGL use a different way of storing the data. This means that when parsing your wavefront file, you need to re-index the data to what OpenGL wants.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What happened with you, is that OpenGL thought that the indices for the normals were actually indices for positions and that you had twice as many faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I would do, is to save all that wavefront data to temporary lists. You create your main vertex buffers. You go through every vertex of every face. You look at the data of that vertex. Then you see if you already have that data combined in your buffers. If so, you use the index of that data, else you add the new data to your buffers and add that index.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-01-09T22:00:41.943" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6097" PostTypeId="2" ParentId="6081" CreationDate="2018-01-09T23:05:37.227" Score="3" Body="&lt;p&gt;There are two general ways the graphics driver can implement &lt;code&gt;Map()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way is to set up a virtual memory mapping that makes the resource's actual memory (could be system memory or GPU memory) visible as part of the application's address space. If it does happen to be GPU memory, any writes you do would typically be buffered up and sent across the PCIe bus to the GPU, using &lt;a href=&quot;https://en.wikipedia.org/wiki/Write_combining&quot; rel=&quot;nofollow noreferrer&quot;&gt;write combining&lt;/a&gt;. (Even on a unified-memory system, mapped resource memory probably has some different caching behavior from &quot;regular&quot; memory, since CPU and GPU caches aren't &lt;a href=&quot;https://en.wikipedia.org/wiki/Cache_coherence&quot; rel=&quot;nofollow noreferrer&quot;&gt;coherent&lt;/a&gt; with each other.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other way the driver can implement &lt;code&gt;Map()&lt;/code&gt; is to allocate memory and create a local copy of the resource, let your app edit it, then copy the modified memory back to the resource when &lt;code&gt;Unmap()&lt;/code&gt; is called. This might need to be done if the actual memory layout of the resource on the GPU is &quot;weird&quot; somehow, like having a nonstandard tiling scheme or some such.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The copying approach is clearly more expensive due to the extra copies required, so I'd expect the driver to use the memory mapping approach whenever possible.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-01-09T23:05:37.227" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6099" PostTypeId="1" CreationDate="2018-01-11T19:58:40.987" Score="3" ViewCount="102" Body="&lt;p&gt;In &lt;a href=&quot;http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;these&lt;/a&gt; slides, specifically page 11, the following formula is reported:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\frac{1}{N} \sum_{k=1}^N \frac{L_i(l_k)f(l_k,v)\cos(\theta_{l_k})}{p(l_k,v)} \approx \left( \frac{1}{N} \sum_{k=1}^N L_i(l_k) \right) \left( \frac{1}{N} \sum_{k=1}^N  \frac{f(l_k,v)\cos(\theta_{l_k})}{p(l_k,v)} \right)&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula above should be an approximation of the rendering equations. I'm looking for a paper that explains how that formula is derived, I cannot manage to find neither the title of a paper (other than the name &quot;Dimitar&quot; mentioned in the same page I pointed out).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've done some research about some possible method that would justify. &lt;a href=&quot;https://math.stackexchange.com/questions/337643/split-up-sum-of-products-suma-i-b-i-approx1-n-suma-i-sumb-i-for-uncor&quot;&gt;This&lt;/a&gt; is the closest thing I managed to find, however there's some hypothesis that doesn't seem to me fits.&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="48" LastEditDate="2018-01-11T22:37:12.807" LastActivityDate="2018-01-11T22:37:12.807" Title="Paper for the approximation formula provided by Brian Karis" Tags="&lt;mathematics&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6100" PostTypeId="2" ParentId="6099" CreationDate="2018-01-11T21:44:28.813" Score="3" Body="&lt;p&gt;I do not have a derivation but i can explain the reasoning behind its usage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the left side is a (monte carlo) estimator for the rendering equation. It states the very same thing that the rendering equation states but on a finite number of discrete samples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;on the right side we have the $L_i(l_k)$ factor separated and &quot;integrated&quot; on its own.&#xA;This approximation holds true when $L_i(l_k)$ is a constant, since $\sum_{k}f(k)\times n = n \times\sum_{k}f(k)$ - and, likewise, $\int_{k}f(k)\times n\space dk = n\times\int_{k}f(k)dk$ - when $n$ is a constant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_i(l_k)$ can be though of the colour of the incoming light and $\int_{k}f(l_k,v)dk$ can be thought of as the intensity of the reflected light. multiplying those together you get that now you can precompute $\int_{k}L_i(l_k)dk$, saving a lot of time in either texture lookups (in the case of sky / environment lighting / screen space ray marching) or raytracing calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, since $L_i(l_k)$ is usually not a constant, this integral is not separable. Yet, in some cases (like when dealing with diffuse lighting or, more specifically, diffuse ambient lighting), the information that $f(l_k,v)$ carries is low-frequency enough that it can reasonably be approximated as a constant with respect to the distribution of $L_i(l_k)$. Experimentally, it can be shown that the final result is not too different from what you would expect.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-01-11T21:44:28.813" CommentCount="10" ContentLicense="CC BY-SA 3.0" />
  <row Id="6101" PostTypeId="1" AcceptedAnswerId="6106" CreationDate="2018-01-12T01:51:16.290" Score="0" ViewCount="113" Body="&lt;p&gt;I recently set up a (very basic) ray-marched path-tracer, and I'm getting strange surface patterns on my area light [&lt;a href=&quot;https://imgur.com/a/PTgYh&quot; rel=&quot;nofollow noreferrer&quot;&gt;link&lt;/a&gt;]. I'm using known-valid analytical normals for the light's surface, and the same patterns appear when I use a well-tested gradient estimator anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ray bounce directions are calculated with &lt;a href=&quot;http://www.amietia.com/lambertnotangent.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;amietia's diffuse BRDF&lt;/a&gt;, and regenerated after each bounce. The random numbers in each bounce are uncorrelated (hashed integer versions of the intersecting ray positions) and I'm offsetting ray distances at the start of each bounce by [0.01f] to avoid shadow acne.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last time I saw this bug was several months ago, and that time it &lt;em&gt;was&lt;/em&gt; (probably) caused by shadow acne. What could it be now?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-01-13T05:23:55.747" Title="Ringlike artifacts produced by rays bouncing off a light source" Tags="&lt;lighting&gt;&lt;pathtracing&gt;&lt;diffuse&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6102" PostTypeId="1" AcceptedAnswerId="6104" CreationDate="2018-01-12T04:21:33.133" Score="3" ViewCount="359" Body="&lt;p&gt;So I am facing the following issue. Say I have a minecraft like mesh (i.e I have a bunch of cubes on top of one another).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wish to smooth out this mesh in such a way that only the regions where there are edges are smoothed out and such that the smoothing concentrates around the edges (e.g if I have a staircase the overall shape of the cubes that make the staircase should still be close to the staircase but instead of having straight edges I should have something much smoother). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I should be able to smooth things out locally, so that if a block is removed from this mesh, I can run the subdivision algorithm only on the newly generated coarse region that is created after the block is removed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anybody have any ideas as to which algorithm I could use?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-01-12T19:00:10.033" LastActivityDate="2018-01-12T19:00:10.033" Title="How to smooth out a voxel grid?" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;voxelization&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6104" PostTypeId="2" ParentId="6102" CreationDate="2018-01-12T18:17:42.530" Score="1" Body="&lt;p&gt;If you have this data in a 3d array where a block is a 1 and no block is a 0 you can apply a 3d blur and then set all voxels that are left with a value higher than 0.5 to 1 and those that arent to 0. this will smooth out sharp details and leave flats mostly uneffected &lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-01-12T18:17:42.530" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6105" PostTypeId="1" AcceptedAnswerId="6111" CreationDate="2018-01-13T04:34:03.477" Score="3" ViewCount="435" Body="&lt;p&gt;I've been having nightmares at work this week trying to get Unity's Standard shader, and my own custom car paint shader modded from it, to look good on Android. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most obvious problem was fractured specular highlights, which I  identified as a float precision issue, and solved by changing all the directional math to use float3 instead of half3. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It now looks fine on GLES3, but on GLES2, which we want to support, the glossy reflections coming from reflection probes look terrible, with noisy matte areas all over the place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I finally tracked this down to the cube map texture lookup itself - different blur levels are stored in different MIP levels, and a textureCubeLod lookup samples the reflection at the right smoothness level. Trouble is, GLES2 doesn't natively support lod texture lookups, so it relies on an extension. If the extension is not found, and it seems most Android devices don't have it, it falls back to a regular texture sample, with the lod parameter becoming a bias. This explains the matte areas - sharp features are causing the tex lookup to be kicked down the mip chain to the rougher maps, and the bias applied from there. From certain angles, a single bit of noise in the normal map is enough to cause the effect. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I want to know is, does any workaround exist for this? My first thought was to 'bias the bias' using dfdx, dfdy, but unfortunately these are also GLES3 only. I may just have to kill glossy reflections altogether on older droids otherwise.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-01-13T19:05:01.193" Title="Any way to fake textureLod on GLES2?" Tags="&lt;texture&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6106" PostTypeId="2" ParentId="6101" CreationDate="2018-01-13T05:23:55.747" Score="0" Body="&lt;p&gt;Fixed this today.&#xA;The artifacts were produced by shadow acne and worsened by dodgy averages (assuming every ray would complete the maximum number of bounces before returning or exiting the scene) + an undersized PRNG state buffer; maybe I was just really tired, but I still don't know why bouncing rays off my light sources by default seemed like a good idea. The &lt;em&gt;point&lt;/em&gt; of backward path tracing is to trace paths from the camera back to the light source(s) in a scene, and there's no reason to continue following a path (=&gt; evaluate bounces) if rays immediately intersect with a source after leaving the camera.&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-01-13T05:23:55.747" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6107" PostTypeId="2" ParentId="6088" CreationDate="2018-01-13T07:04:08.723" Score="0" Body="&lt;p&gt;Jitter is &lt;em&gt;supposed&lt;/em&gt; to make edges more irregular; that's how it masks aliasing in the first place. I didn't realise this when I made the question, but the noise in path tracers comes from undersampled global illumination; because each sample travels in a random direction, it's possible for a visually-significant number of samples to reach unrepresentative areas (e.g. for rays at the bottom of a curve to mostly hit the walls of the curve rather than travel upward towards), and the dissonance between these and the actual image function creates the fuzzy variance you get in path-tracing renderers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That sort of noise is completely different to the pseudo-one-dimensional edge variance you expect to get from ray jitter at one sample/pixel. Single-sample ray jitter essentially means pulling edges randomly closer to or further away from their actual tendency in order to hide the high-frequency patterns introduced by aliasing; it looks nothing like &quot;fuzzy&quot; GI noise because (at least at the single-sample scale I was thinking about when I made this question) it's one-dimensional (variance about an edge) rather than two-dimensional (variance over a surface).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, this question is invalid. It assumes that jittered edges are supposed to be fuzzy (as in GI noise), but forgets that edges are one-dimensional and that the jitter can't magically expand them to two dimensions and spread them over some domain (at least, not without spreading the aliasing as well (multi-pixel jitter)). Jitter doesn't produce fuzzy noise because it isn't supposed to; &lt;em&gt;it's only supposed to vary the relative distance of points &quot;on&quot; an edge from the actual edge positions given by the image signal&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-01-13T07:04:08.723" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6108" PostTypeId="1" CreationDate="2018-01-13T09:19:30.973" Score="4" ViewCount="561" Body="&lt;p&gt;I'm trying to create single-channel (no mipmaps) texture initialized with my custom pixel data, but it crashes on glTextureSubImage2D. Any idea why?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const std::vector&amp;lt;GLubyte&amp;gt; myData(1025 * 1025, 0);&#xA;GLuint texture;&#xA;glCreateTextures(GL_TEXTURE_2D, 1, &amp;amp;texture);&#xA;glTextureStorage2D(texture, 1, GL_R8, 1025, 1025);&#xA;glTextureSubImage2D(texture, 0, 0, 0, 1025, 1025, GL_RED, GL_UNSIGNED_BYTE, &amp;amp;myData[0]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8026" LastActivityDate="2018-01-13T16:57:47.890" Title="OpenGL: Why glTextureSubImage2D crashes?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6109" PostTypeId="1" CreationDate="2018-01-13T15:42:33.653" Score="1" ViewCount="46" Body="&lt;p&gt;I have been reading this paper : &lt;a href=&quot;http://openaccess.thecvf.com/content_iccv_workshops_2013/W21/papers/Sugiura_3D_Surface_Extraction_2013_ICCV_paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;3D Surface Extraction using Incremental Tetrahedra Carving .pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have already generated a tetrahedra for my mesh and I would like to create a surface mesh. I can't understand the algorithm. From my understanding, there is a camera that generates rays towards to the points of the tetrahedral, and I get the intersections, but how would I eliminate the triangles that are inside or outside ? how would I detect inside or outside polygons ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would someone give a pseudo code of the algorithm ?&lt;/p&gt;&#xA;" OwnerUserId="7918" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T08:57:34.463" LastActivityDate="2018-03-06T08:57:34.463" Title="Ray tracing and mesh extraction" Tags="&lt;computational-geometry&gt;&lt;subdivision&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6110" PostTypeId="2" ParentId="6108" CreationDate="2018-01-13T16:57:47.890" Score="4" Body="&lt;p&gt;Pixel transfer operations are governed by more than just your parameters to a pixel transfer function. They are also governed by &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Pixel_Transfer#Pixel_transfer_parameters&quot; rel=&quot;noreferrer&quot;&gt;parameters passed to the &lt;code&gt;glPixelStore&lt;/code&gt; functions&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of particular interest to you is &lt;code&gt;GL_PACK_ALIGNMENT&lt;/code&gt;. This tells OpenGL what the byte alignment for each row of data is in your array. By default, this value is &lt;em&gt;four&lt;/em&gt;, not one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that OpenGL will believe that the second row of your image starts at this address: &lt;code&gt;&amp;amp;myData[1028]&lt;/code&gt;, since 1025 is not aligned to 4 bytes. And that means it will run off the end of your allocated buffer eventually.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are using data with 1-byte alignment for rows, you must inform OpenGL of this by calling &lt;code&gt;glPixelStorei(GL_PACK_ALIGNMENT, 1);&lt;/code&gt;. Note that &lt;a href=&quot;https://stackoverflow.com/a/11045278/734069&quot;&gt;you should not do this by default; do it only when dealing with byte aligned data&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-01-13T16:57:47.890" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6111" PostTypeId="2" ParentId="6105" CreationDate="2018-01-13T19:05:01.193" Score="2" Body="&lt;p&gt;One way would be to break out the mip levels of the cube into a bunch of separate textures, then implement the mip selection and trilinear filtering yourself, by branching based on the LOD value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That doesn't sound fast, though, given you're targeting older devices. You could speed it up by forgoing trilinear filtering and just using the nearest-neighbor mip level. Gloss values would be effectively quantized to the number of mip levels, but maybe it won't look too bad.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-01-13T19:05:01.193" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6113" PostTypeId="1" CreationDate="2018-01-13T22:15:49.250" Score="0" ViewCount="46" Body="&lt;p&gt;Suppose I want to perform translate in the following order:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Scale by $S$&lt;/li&gt;&#xA;&lt;li&gt;Rotate by matrix $R_1$&lt;/li&gt;&#xA;&lt;li&gt;Rotate by matrix $R_2$&lt;/li&gt;&#xA;&lt;li&gt;Translate by $T%$.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;When I apply the matrix, should the overall transformation matrix be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$M = T \times R_1^{-1} \times R_2^{-1} \times S$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$M = T \times R_2^{-1} \times R_1^{-1} \times S$&#xA;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I always thought the transformations should be applied in reverse, so it should be the second case. But I'm told that it's the first case instead. Is there a special need to reverse the order of rotation apart from taking the inverse too?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, why must I take the inverse matrix for rotation?&lt;/p&gt;&#xA;" OwnerUserId="8027" LastActivityDate="2018-01-13T22:15:49.250" Title="Is this the correct application of model transformation?" Tags="&lt;raytracing&gt;&lt;model&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6115" PostTypeId="1" CreationDate="2018-01-14T20:47:16.220" Score="9" ViewCount="668" Body="&lt;p&gt;Say I have a model made up of vertices, each with &lt;code&gt;position&lt;/code&gt;, &lt;code&gt;normal&lt;/code&gt;, &lt;code&gt;tangent&lt;/code&gt;, and &lt;code&gt;texcoord&lt;/code&gt; attributes, where triangles are specified by index triples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we just focus on the vertex attributes, I'm aware of two broad strategies: the structure of arrays, and the array of structures. I've also heard that the array of structures is preferred because it increases the memory locality (and therefore cache locality) of the attributes for a given vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it really the case that this improves performance? The main way I could think that this would come about is by vertex indices that require the rasterizer to acquire vertex data that has long since been evicted from cache. If vertex data access is random like this, then keeping all the attributes for a vertex on the same cache line would certainly make things faster, but is this not an issue that could be mostly mitigated by optimizing the order of triangle specification?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, it's my understanding that modern GPUs may be better at unpacking long vectors of the same type, than vectors of structures of many types. Would it then be possible for a structure-of-arrays layout to consistently outperform an array-of-structures layout of the same vertex data, if the index order is optimized?&lt;/p&gt;&#xA;" OwnerUserId="7238" LastActivityDate="2019-10-09T21:40:36.390" Title="The most performant way to organize vertex data on modern GPUs" Tags="&lt;gpu&gt;&lt;performance&gt;&lt;optimisation&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6116" PostTypeId="1" CreationDate="2018-01-15T16:47:05.340" Score="2" ViewCount="415" Body="&lt;p&gt;I have a source texture (480x480) that was created with mipmapped set to true (error checking removed to simply this post), and a dest texture (100x100):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// source texture&#xA;var textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: MTLPixelFormat.r8Unorm, width: Int(480), height: Int(480), mipmapped: true)&#xA;textureDescriptor.usage = .unknown // .shaderWrite .shaderRead&#xA;srcTexture = metalDevice!.makeTexture(descriptor: textureDescriptor)&#xA;// Dest texture&#xA;textureDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: MTLPixelFormat.r8Unorm, width: Int(100), height: Int(100), mipmapped: false)&#xA;textureDescriptor.usage = .shaderWrite&#xA;destTexture = metalDevice!.makeTexture(descriptor: textureDescriptor)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The sampler is defined:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let samplerDescriptor = MTLSamplerDescriptor()&#xA;samplerDescriptor.magFilter = .linear&#xA;samplerDescriptor.minFilter = .linear&#xA;samplerDescriptor.rAddressMode = .clampToZero&#xA;samplerDescriptor.sAddressMode = .clampToZero&#xA;samplerDescriptor.tAddressMode = .clampToZero&#xA;samplerDescriptor.normalizedCoordinates = true&#xA;textureSampler = metalDevice!.makeSamplerState(descriptor: samplerDescriptor)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I populated the src texture with an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then generated the mipmaps:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let blitEncoder = metalCommandBuffer!.makeBlitCommandEncoder()&#xA;blitEncoder!.pushDebugGroup(&quot;Dispatch mipmap kernel&quot;)&#xA;blitEncoder!.generateMipmaps(for: srcTexture!);&#xA;blitEncoder!.popDebugGroup()&#xA;blitEncoder!.endEncoding()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And in the same command buffer, ran the resize kernel:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let computeEncoder = metalCommandBuffer!.makeComputeCommandEncoder()&#xA;computeEncoder!.pushDebugGroup(&quot;Dispatch resize image kernel&quot;)&#xA;computeEncoder!.setComputePipelineState(resizeImagePipeline)&#xA;computeEncoder!.setTexture(srcTexture, index: 0)&#xA;computeEncoder!.setTexture(destTexture, index: 1)&#xA;computeEncoder!.setSamplerState(textureSampler, index: 0)&#xA;let threadGroupCount = MTLSizeMake(20, 10, 1)&#xA;let threadGroups = MTLSizeMake(destTexture!.width / threadGroupCount.width, destTexture!.height / threadGroupCount.height, 1)&#xA;computeEncoder!.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)&#xA;computeEncoder!.popDebugGroup()&#xA;computeEncoder!.endEncoding()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The compute kernel is (remember, this is not a fragment shader which would automatically know how to set the mipmap level of detail):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;kernel void resizeImage(&#xA;texture2d&amp;lt;half, access::sample&amp;gt; sourceTexture [[texture(0)]],&#xA;texture2d&amp;lt;half, access::write&amp;gt; destTexture [[texture(1)]],&#xA;sampler samp [[sampler(0)]],&#xA;uint2 gridPosition [[thread_position_in_grid]])&#xA;{&#xA;float2 srcSize = float2(sourceTexture.get_width(0),&#xA;sourceTexture.get_height(0));&#xA;float2 destSize = float2(destTexture.get_width(0),&#xA;destTexture.get_height(0));&#xA;float2 sourceCoords = float2(gridPosition) / destSize;&#xA;/*+ The following attempts all produced a pixelated image&#xA;(no edges smoothed out like a fragment shader would)&#xA;half4 color = sourceTexture.sample(samp, sourceCoords);&#xA;float lod = srcSize.x / destSize.x;&#xA;float lod = 0.0;&#xA;float lod = 1.0;&#xA;float lod = 2.0;&#xA;float lod = 3.0;&#xA;float lod = 4.0;&#xA;float lod = 4.5;&#xA;float lod = 5.0;&#xA;float lod = 5.5;&#xA;*/&#xA;float lod = 6.0;&#xA;half4 color = sourceTexture.sample(samp, sourceCoords, level(lod));&#xA;destTexture.write(color, gridPosition);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;No matter what lod is set to, I get the same exact pixelated results. Why won't the mipmapping work?&#xA;Thanks for any help you can provide.&lt;/p&gt;&#xA;" OwnerUserId="8032" LastEditorUserId="8032" LastEditDate="2018-01-15T16:57:33.287" LastActivityDate="2018-01-24T17:01:02.543" Title="Mipmap sampler in Metal compute kernel (not vertex or fragment shader)" Tags="&lt;compute-shader&gt;&lt;mipmap&gt;&lt;metal&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6117" PostTypeId="1" AcceptedAnswerId="6118" CreationDate="2018-01-15T16:47:34.507" Score="2" ViewCount="79" Body="&lt;p&gt;When using an array texture I can call:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTextureStorage3D(m_texture_array, 1, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, m_num_billboards);&#xA;for (int i{}; i &amp;lt; 4; ==i) {&#xA;    glTextureSubImage3D(m_texture_array, 0, 0, 0, i, width, height, 1, GL_RGB, GL_UNSIGNED_BYTE, data);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which results in a compressed image. So when do I need to use &lt;code&gt;glCompressedTextureSubImage3D&lt;/code&gt; ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glCompressedTexSubImage3D.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;the docs&lt;/a&gt; say:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;internalformat must be a known compressed image format (such as GL_RGTC) or an extension-specified compressed-texture format&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Why can't it be a generic format?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2018-01-15T18:02:36.753" Title="glCompressedTextureSubImage3D Usage" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6118" PostTypeId="2" ParentId="6117" CreationDate="2018-01-15T18:02:36.753" Score="2" Body="&lt;p&gt;OK, when you call the regular &lt;code&gt;SubImage&lt;/code&gt; functions, you are passing pixel data. You are &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Pixel_Transfer&quot; rel=&quot;nofollow noreferrer&quot;&gt;provoking a pixel unpack operation&lt;/a&gt;, where the implementation will read the pixels from your data in the format specified and convert them to the internal format of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if already have compressed data, you don't &lt;em&gt;want&lt;/em&gt; that conversion. You just want to pass the compressed data to the GL, and have it use it directly. That's what the &lt;code&gt;Compressed&lt;/code&gt; functions are for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to compress uncompressed data, you use the non-&lt;code&gt;Compressed&lt;/code&gt; functions. But you really, &lt;em&gt;really&lt;/em&gt;, shouldn't. Indeed, with ASTC, you &lt;em&gt;can't&lt;/em&gt; compress the data online. And even for other formats, the quality of the result will be rather sketchy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you really want to rely on the quality of a compression algorithm written to be fast rather than &lt;em&gt;good&lt;/em&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Pixel_Transfer_Format&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;format&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Pixel_Transfer_Type&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;type&lt;/code&gt;&lt;/a&gt; transfer parameters describe a single pixel's worth of data, and compressed formats don't generally store data in units of &quot;pixels&quot;. Compressed formats usually use blocks of some size. Regular pixel transfers expect a 1:1 correspondence between a pixel in your data and a pixel in the GL-owned image. That simply isn't the case when dealing with compressed data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you need a new function, which just takes a block of bits of a known size, whose format is defined by the image's format, and jams it into the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason why you can't use a generic compressed format with the &lt;code&gt;Compressed&lt;/code&gt; transfer functions should be obvious by now. These functions are for providing compressed data in a specific format; &lt;em&gt;by definition&lt;/em&gt;, the generic formats are implementation defined. So there's no way you could possibly know what data to provide for generic compressed transfers.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-01-15T18:02:36.753" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6119" PostTypeId="1" CreationDate="2018-01-15T19:45:02.840" Score="1" ViewCount="107" Body="&lt;p&gt;Whenever you make a part in inventor, the software calculates de properties of the whole body given a constant density. Then, automatically,  it shows the inertial tensor. As you can recall from math, the inertia equation is &lt;span class=&quot;math-container&quot;&gt;$I_x= \rho\int(y^2+z^2)dV$&lt;/span&gt;&#xA;for the x axis. So, clearing rho, how can I get the right hand of the equation that is been solved in the underlying algorithm without doing any hand calculations?&lt;/p&gt;&#xA;" OwnerUserId="8033" LastEditorUserId="8033" LastEditDate="2019-08-17T21:01:54.363" LastActivityDate="2019-08-17T21:01:54.363" Title="How to obtain a parametric equation out of a part designed in Autodesk Inventor?" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6120" PostTypeId="1" AcceptedAnswerId="6125" CreationDate="2018-01-15T20:19:20.303" Score="3" ViewCount="120" Body="&lt;p&gt;I have two somewhat related questions to ask:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;What is the most accurate way to get the colors of a spectrum, without having to go deep into physics and simulating the universe? ;) Right now, I'm using &lt;a href=&quot;http://cvrl.ioo.ucl.ac.uk/cmfs.htm&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Color matching functions&quot;&gt;these&lt;/a&gt; color matching functions, and simply reading off the XYZ color of a particular wavelength and converting it to sRGB. I know sRGB can't represent most spectral colors, but let's ignore that.&lt;/li&gt;&#xA;&lt;li&gt;If I'm trying to make a color, say white, out of the spectral colors, how should I combine them? Should I add the color in XYZ space, or in RGB space, or is neither sufficient?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;My plan is to experiment with spectral rendering, so it should be accurate enough to avoid biased renders. It'll most likely be on the GPU, and I need accuracy over speed.&lt;/p&gt;&#xA;" OwnerUserId="6838" LastEditorUserId="6" LastEditDate="2018-01-20T19:51:57.803" LastActivityDate="2018-01-20T19:51:57.803" Title="Generating and Combining Spectral Colors" Tags="&lt;color&gt;&lt;color-science&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6121" PostTypeId="1" AcceptedAnswerId="6126" CreationDate="2018-01-15T23:48:15.377" Score="1" ViewCount="347" Body="&lt;p&gt;Multiple Importance Sampling (MIS) is a technique used by Veach's VCM technique to balance responses of different surfaces to different types of importance sampling for direct illumination. My understanding is that specular surfaces are best lit without sampling the light at all; instead, you pull a direction from the BRDF and hope that it hits the light source. Diffuse surfaces &quot;spread&quot; light more broadly over their domain, so firing rays towards random points on the area covered by the light produces good results without the wastage produced by sampling over the BRDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm still unsure about a few things, though:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Veach's demonstration images show flat specular surfaces eventually converging with light sampling; how is this possible? All rays fired towards random points on the light will reach the light (assuming no obstructions), so shouldn't the specular surfaces wash out under all the assumed illumination?&lt;/li&gt;&#xA;&lt;li&gt;&quot;&lt;strong&gt;Multiple&lt;/strong&gt; Importance Sampling&quot; implies that tracing gather rays towards the light is an importance-sampled technique (which makes sense, it's very difficult to have invalid rays if all rays approximate the direction of light relative to the surface); does this mean I need to be dividing my direct gathers by a PDF? Given that the &quot;direction&quot; of the light could be anywhere on the unit sphere surrounding the lit point, should the PDF be $4\pi$?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-01-17T17:17:50.317" Title="Direct illumination, specular surfaces, and MIS" Tags="&lt;specular&gt;&lt;monte-carlo&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6123" PostTypeId="1" CreationDate="2018-01-16T06:55:49.813" Score="1" ViewCount="134" Body="&lt;p&gt;I have multiple 3D polygons meshes (sketchup format) in the world, for any specified point (x,y,z), how do I get the direct closest polygon face below this point? and how to get the height for the projected intersection point on the face?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone point me the direction how to get started?&lt;/p&gt;&#xA;" OwnerUserId="8035" LastActivityDate="2018-01-16T07:45:40.977" Title="How to get the nearest polygon face and height of intersection point" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6124" PostTypeId="2" ParentId="6123" CreationDate="2018-01-16T07:45:40.977" Score="1" Body="&lt;p&gt;To get the height intersection once you have found the polygon, you can build a plane of the polygon and calculate the distance to the plane. For example you can displace the point along the planes normal and calculate the length of the normal for when the point is displaced into the plane. Implicit planes are neat for this, they are build with the normal of the plane (which is the normal of the polygon) and one constant $d$. $d$ can be calculated by arbitrary point on the plane (e.g. one of your polygon vertices). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$d = -\vec{n} \cdot q$ and $\vec{n} + d = 0$ (where $\vec{n}$ is the normal and $q$ the point/vertex).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The neat part is: if you calculate the dot product of your point you want the distance of, you have the signed distance toward the plane, i.e. if $p$ is your point and $l$ is the distance between the point and the plane, then&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$l = (\vec{n} + d) \cdot p$ (for this you assume the fourth coordinate of a point as $1$)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that you have the distance to the plane, you need to check, weather the intersection of normal through point with plane also intersects the polygon. You could for example take the vectors $\vec{v}_i = v_i - p$ where $v_i$ are your polygons, and then take the dot product $\vec{n} \cdot \vec{v}$. If they all have the same sign, your intersection doesn't hit the polygon (assuming the polygon to be convex). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Iff it doesn't hit the vertices you need the distance to the closest two vertices. Since you have already done the dot product test (with the sign) for all polygon vertices, you know that the shortest distance can't be to the edge between the two vertices, and thus it suffices to take the shortest of the two point-&gt;vertex distances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to which polygon is closest, I'm not sure if there is a better trick, but I'd just transform the point into Model Space of the mesh and calculate the distance to any front facing face.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-01-16T07:45:40.977" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6125" PostTypeId="2" ParentId="6120" CreationDate="2018-01-16T15:21:31.213" Score="4" Body="&lt;p&gt;Your way of calculating XYZ functions is probably the most efficient way to go about calculating accurate colors from a spectrum. It is standard practice afaik, for examples the books Physically Based Rendering (3rd) and Real-Time Rendering (3rd) both use this method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can add the colors in RGB space, but only if you convert from sRGB to linear RGB first. Otherwise you need to take into account, that sRGB sums will not lead to correct colors. The blogpost &lt;a href=&quot;http://renderwonk.com/blog/index.php/archive/adventures-with-gamma-correct-rendering/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Adventures with Gamma-Correct Rendering&lt;/a&gt; by Naty Hoffman is a good read regarding this, topc:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Computing shading in sRGB space is like doing math in a world where 1+1=3.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is the problem you have when adding colors in sRGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to whether $XYZ$ can be summed, I think so. If we look at the definition of the coordinates (for $S$ is the spectral function and $x, y, z$ are the CIE functions):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$X = \frac{1}{\int_\lambda y(\lambda) d\lambda} \int_\lambda S(\lambda) x(\lambda) d\lambda$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now two $X$ coordinates $X_1, X_2$ would have the same definition, only the spectrals are different ($S_1, S_2$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus you have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$X_1 + X_2 = \frac{1}{\int_\lambda y(\lambda) d\lambda} \int_\lambda S_1(\lambda) x(\lambda) d\lambda + \frac{1}{\int_\lambda y(\lambda) d\lambda} \int_\lambda S_2(\lambda) x(\lambda) d\lambda\\&#xA;= \frac{1}{\int_\lambda y(\lambda) d\lambda} \left(\int_\lambda S_1(\lambda) x(\lambda) d\lambda + \int_\lambda S_2(\lambda) x(\lambda) d\lambda\right)\\&#xA;= \frac{1}{\int_\lambda y(\lambda) d\lambda}\int_\lambda S_1(\lambda) x(\lambda) + S_2(\lambda) x(\lambda) d\lambda \\&#xA;= \frac{1}{\int_\lambda y(\lambda) d\lambda}\int_\lambda (S_1(\lambda)  + S_2(\lambda)) x(\lambda) d\lambda\\&#xA;=X$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same holds for other coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, your best option is probably to sum your XYZ coordinates and convert them to sRGB space in the end.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-01-16T15:21:31.213" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6126" PostTypeId="2" ParentId="6121" CreationDate="2018-01-16T16:24:40.533" Score="2" Body="&lt;p&gt;Specular surfaces which use MIS are not perfectly specular like a mirror. They have a small amount of blur, otherwise there is indeed no point in sampling the light as all the samples will evaluate the BRDF as 0. In fact, you would only need to trace a single reflection ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A small amount of blur means that a given camera ray will see a small area of the lightsource (assuming it hits where the specular highlight is visible). Thus, a small fraction of the light samples will get a BRDF which is not 0 so it will eventually converge. The less blur, the more samples it will take.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You are correct that such a case will converge faster if you sample only the BRDF. Likewise, a very diffuse BRDF will usually converge faster if you sample only the light. But this is not true if your light is very large and your surface very close to it&lt;sup&gt;1&lt;/sup&gt;. Where MIS shines is that it handles those cases as well as the BRDFs which are neither very diffuse nor very specular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you choose to ignore it, what you have to do is a simple integral. There are a few ways to go about it but if you start from MIS equations, just use 0 as the PDF of the BRDF since you're not generating those samples. And be prepared for some cases which won't converge well.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The assumption is that the light samples all have a similar contribution to the final result. Even with very good sampling of the light, this must assume that the BRDF will be similar for all light samples. At least I don't know of any direct light sampling formula which takes the cosine term of the diffuse surface into account. Pushing this to the extreme, you can build an example where most of the light is behind the surface, so most of the light samples will contribute nothing at all to the final result. BRDF samples are obviously sent only on the front side of the surface so they might converge faster, even if only a small % of them hit the light.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2018-01-17T17:17:50.317" LastActivityDate="2018-01-17T17:17:50.317" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6127" PostTypeId="1" CreationDate="2018-01-17T00:10:14.130" Score="0" ViewCount="427" Body="&lt;p&gt;I have some images that I know will be stored with either PVR or ETC compression. I would like to be able to convert these images into uncompressed RGB. However, because of binary size constraints, I would like to do so without adding a dedicated library for the conversion. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does there exist any ways to do this? I know functions like glCompressedTexImage2D will let me load the compressed image to GPU. However, I'm having issues reading the decoded version out. For extra context, I am trying to do this with OpenGL ES 2.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="8038" LastEditorUserId="2654" LastEditDate="2018-01-17T06:06:05.530" LastActivityDate="2018-01-17T22:36:16.387" Title="Loading compressed image to GPU and reading back decompressed on CPU" Tags="&lt;opengl-es&gt;&lt;compression&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6128" PostTypeId="2" ParentId="5022" CreationDate="2018-01-17T00:51:52.407" Score="1" Body="&lt;p&gt;Revisiting this question from awhile ago. It turns out this sort of histogram is created by iterating through every pixel value in both the normal image and gradient magnitude image plotting it in the 2d image. (x intensity, y gradient magnitude). The count/occurrences of the 2d histogram are represented by the intensity of the grayscale in figure b. So the brighter a pixel in figure b is, the more pixels with that (intensity, gradient magnitude).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For volume rendering this is called a 2d transfer function which lets users filter out or assign lower opacities to pixels with large/small gradient magnitudes. This is especially helpful in real time volume rendering with lighting. Real time volume rendering typically uses a BSDF at every point along a ray march as an approximation (Assuming that light reaches every point in the volume). IE: Dot product of the incoming light direction with the gradient as the normal. Using the gradient as the normal means that homogeneous areas are not well represented as they have low gradient magnitudes. Small noise in these areas can easily cause the gradient and normal to flip.&lt;/p&gt;&#xA;" OwnerUserId="113" LastActivityDate="2018-01-17T00:51:52.407" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6129" PostTypeId="2" ParentId="6127" CreationDate="2018-01-17T06:11:32.500" Score="3" Body="&lt;p&gt;Desktop OpenGL requires implementations to convert pixel data between the internal format of the image and the format you specify in the pixel transfer command.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL ES &lt;em&gt;does not&lt;/em&gt;. Indeed, it is so serious about not allowing this that it actually changes the &lt;em&gt;meaning&lt;/em&gt; of the parameters to functions like &lt;code&gt;glTexImage*d&lt;/code&gt;. In ES, you cannot use sized internal formats (well, outside of texture storage calls). Instead, the internal format is kinda there. What really defines the internal format is the pixel format and type parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is, when you tell OpenGL ES that the pixel data you're providing looks like X, it requires the implementation to create a texture whose real internal format exactly matches that. And if you're using &lt;code&gt;glTexSubImage*d&lt;/code&gt; or &lt;code&gt;glGetTexImage&lt;/code&gt;, you &lt;em&gt;must&lt;/em&gt; provide pixel transfer parameters that match those you provided to the &lt;code&gt;glTexImage*d&lt;/code&gt; call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So OpenGL ES doesn't allow any of that pixel conversion stuff.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-01-17T06:11:32.500" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6134" PostTypeId="2" ParentId="6127" CreationDate="2018-01-17T22:36:16.387" Score="0" Body="&lt;p&gt;The commentary in this thread is correct. OpenGL ES does not have built in support for reading textures directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best option it seems, given stated constraints, is to draw the compressed texture to a quad then read it back out. (Same as suggested by &quot;Simon F&quot; in the question comment thread above.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As reference for people stumbling upon this with the same problem, &lt;a href=&quot;https://stackoverflow.com/a/11947751&quot;&gt;this answer to a different, but similar question&lt;/a&gt; gives steps for doing the above. &lt;/p&gt;&#xA;" OwnerUserId="8038" LastActivityDate="2018-01-17T22:36:16.387" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6135" PostTypeId="1" CreationDate="2018-01-18T03:54:16.817" Score="1" ViewCount="793" Body="&lt;p&gt;I am trying to implement a path tracer, but I have some problem. The class &lt;code&gt;Spectrum&lt;/code&gt; is color. I implemented a mirror material like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Spectrum MirrorBSDF::f(const Vector3D&amp;amp; wo, const Vector3D&amp;amp; wi) &#xA;{&#xA;    return reflectance * (1.0 / abs_cos_theta(wo));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The reflectance is a Spectrum variable. And now I want to add a material &quot;Glass&quot; that can reflect and refract. It meets the Fresnel theorem. Can someone teach me how to implement this? The function &lt;code&gt;f&lt;/code&gt; is used like this:           &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Spectrum light_L = light-&amp;gt;sample_L(hit_p, &amp;amp;dir_to_light, &amp;amp;dist_to_light, &amp;amp;pdf);&#xA;&#xA;// convert direction into coordinate space of the surface, where surface normal is [0 0 1]&#xA;Vector3D w_in = w2o * dir_to_light;&#xA;double cos_theta = std::max(0.0, w_in[2]);&#xA;Spectrum f = isect.bsdf-&amp;gt;f(w_out, w_in);&#xA;&#xA;// TODO: Construct a shadow ray and compute whether the intersected surface is&#xA;// in shadow and accumulate reflected radiance&#xA;Ray shadow_ray(hit_p + EPS_D * dir_to_light, dir_to_light, &#xA;               dist_to_light - (EPS_D * dir_to_light).norm(), 0);&#xA;if (!bvh-&amp;gt;intersect(shadow_ray))&#xA;{&#xA;    L_out += (f * light_L * (cos_theta * scale / pdf));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I implemented it.But something is error.Where is error?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XuvAJ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XuvAJ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8048" LastEditorUserId="8048" LastEditDate="2018-03-06T10:54:58.097" LastActivityDate="2018-03-06T10:54:58.097" Title="How can I implement this BSDF?" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;material&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6136" PostTypeId="1" CreationDate="2018-01-18T20:07:34.193" Score="1" ViewCount="73" Body="&lt;p&gt;Let's say I have a point on a potential cubic sphere inflated using this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector3 v = new Vector3(x, y, z) * 2f / gridSize - Vector3.one;&#xA;float x2 = v.x * v.x;&#xA;float y2 = v.y * v.y;&#xA;float z2 = v.z * v.z;&#xA;Vector3 s;&#xA;s.x = v.x * Mathf.Sqrt(1f - y2 / 2f - z2 / 2f + y2 * z2 / 3f);&#xA;s.y = v.y * Mathf.Sqrt(1f - x2 / 2f - z2 / 2f + x2 * z2 / 3f);&#xA;s.z = v.z * Mathf.Sqrt(1f - x2 / 2f - y2 / 2f + x2 * y2 / 3f);&#xA;normals[i] = s;&#xA;vertices[i] = normals[i] * radius;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;from: &lt;a href=&quot;http://catlikecoding.com/unity/tutorials/cube-sphere/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cube Sphere | Unity C# Tutorial&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After finding the cube face the point belong to, how do I find which spatial hash it belong to, ie which grid cells for any given arbitrary division?&lt;/p&gt;&#xA;" OwnerUserId="7138" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T08:56:32.670" LastActivityDate="2018-03-06T08:56:32.670" Title="Hashing a point on cubic sphere" Tags="&lt;mathematics&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6137" PostTypeId="1" AcceptedAnswerId="8637" CreationDate="2018-01-21T09:02:09.767" Score="1" ViewCount="58" Body="&lt;p&gt;Supposing a behavior function $C(x_1, \ldots, x_n)$, then we have a scalar potential energy function  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$E = \frac{k_s}{2}C\cdot C$ where $k_S$ is stiffness constant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence, the force is as follows $f_i = -\frac{\partial E}{\partial x_i} = -k_sC\frac{\partial C}{\partial x_i}$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I caught up so far, but couldn't understand when adding damping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper read $f_i = (-k_sC - k_d\dot{C})\frac{\partial C}{\partial x_i}$ , where $k_d$ is damping constant and $\dot{C}$ is derivative of $C$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to derive the damping part?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know damping equation is $f_d = -k_dv$, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In detail, supposing there are two end of points in a spirng, called $p_a, p_b$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then the damping force $f_d = -k_d\frac{\dot{l}\cdot l}{|l|}\frac{l}{|l|}$ in 3D sapce ($\dot{l}$ is $v_a - v_b$, $l = p_a - p_b$)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I could not correspond this equation to the above damping part.&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2019-02-26T06:44:38.757" Title="Spring damping in Energy Function" Tags="&lt;physics&gt;&lt;simulation&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6138" PostTypeId="1" AcceptedAnswerId="6140" CreationDate="2018-01-21T13:45:00.533" Score="3" ViewCount="145" Body="&lt;p&gt;I am trying and learning to develop a low level graphics API.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I want to know, how do modern graphics APIs manage to communicate with graphic card drivers (to tackle GPU) so efficiently and in an optimized manner? &lt;/li&gt;&#xA;&lt;li&gt;Which technologies should I understand other than C/C++ and Assembly?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="8043" LastEditorUserId="6" LastEditDate="2018-01-21T13:53:02.273" LastActivityDate="2018-01-21T17:34:00.967" Title="What mechanisms are being used by Directx12 and Vulkan APIs in order to communicate with graphic card drivers internally?" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;directx12&gt;&lt;vulkan&gt;&lt;driver&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6139" PostTypeId="1" CreationDate="2018-01-21T15:24:33.440" Score="4" ViewCount="1451" Body="&lt;p&gt;I'm finding myself increasingly interested in rendering techniques utilizing multisampling for anti-aliasing (obviously), out-of-order transparency, volumes etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Searching the web for performance numbers of MSAA in the range only gets me to gamer verdicts for this and that game, and even then MSAA is only used for AA, and being compared to screen based post process AA which can hardly be used for anything else than AA.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any rule of thumb (other than memory consumption) of how much it costs having x2, x4, x8, x16 MSAA? Linear? Logarithmic?&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2018-02-02T09:40:46.430" Title="How does MSAA performance scale?" Tags="&lt;performance&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6140" PostTypeId="2" ParentId="6138" CreationDate="2018-01-21T17:34:00.967" Score="7" Body="&lt;p&gt;It's very different between the Khronos standards (including Vulkan) and DirectX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In DirectX, Microsoft implements the API, but they publish to GPU vendors a HAL API. There's actually two HALs: one that runs in kernel-mode, to communicate with the card directly; and one that runs in user-space, to do other tasks (like manage memory, set up data structures, and compile shaders).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Vulkan, Khronos only publishes the specification and a test suite. It's up to each GPU vendor to ship an implementation of the library. The application's interface to the driver is a normal C API, like any other library. You'll get confused if you try to think of an &quot;API part&quot; communicating with a &quot;graphics card driver&quot;: the driver &lt;em&gt;is&lt;/em&gt; the API implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why it's very hard for third-parties to make open-source OpenGL (or Vulkan) implementations: you need to know all the details of the GPU hardware to do it. These graphics APIs are defined by industry groups consisting of the same people who design the hardware (at a high level), and deep understanding of the GPU architecture is what you need to design an efficient graphics API.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-01-21T17:34:00.967" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6141" PostTypeId="1" AcceptedAnswerId="6146" CreationDate="2018-01-21T21:24:38.050" Score="2" ViewCount="2623" Body="&lt;p&gt;I'm sending a large number of data to the &lt;code&gt;vertex shader&lt;/code&gt;. I use &lt;code&gt;glBufferData&lt;/code&gt; to generate my &lt;code&gt;VBO&lt;/code&gt;. Later on I have to replace the data in my &lt;code&gt;VBO&lt;/code&gt; so I do the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(VAO);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;glBufferSubData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * models().size(), &amp;amp;models[0], GL_DYNAMIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What I noticed is when I used the above code (I'm assuming) that some of the previous data is left in the &lt;code&gt;VBO&lt;/code&gt; because I not only draw the new objects I want to but also some of the old ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore I had to change my code to the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(VAO);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(glm::mat4) * models().size(), &amp;amp;models[0], GL_DYNAMIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The reason I don't like the above aproach is because according to &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferSubData.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;Khronos&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;When replacing the entire data store, consider using glBufferSubData rather than completely recreating the data store with glBufferData. This avoids the cost of reallocating the data store.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;How do I replace the whole &lt;code&gt;VBO&lt;/code&gt; with my new data, but if my new data is smaller than the old data then how do I reallocated the &lt;code&gt;VBO&lt;/code&gt; efficiently? Or is there something equivalent to a &lt;code&gt;NULL terminating character&lt;/code&gt; where the graphics card can know not to read any further data?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason I ask this is because from my understanding &lt;code&gt;glBufferStorage&lt;/code&gt; is like &lt;code&gt;glBufferData&lt;/code&gt; except that the &lt;code&gt;data store&lt;/code&gt; generated by &lt;code&gt;glBufferStorage&lt;/code&gt; is immutable meaning that the size of the &lt;code&gt;data store&lt;/code&gt; cannot be changed, as stated &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferStorage.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;on Khronos&lt;/a&gt; and on &lt;a href=&quot;https://stackoverflow.com/questions/27810542/what-is-the-difference-between-glbufferstorage-and-glbufferdata&quot;&gt;Stackoverflow&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;glBufferStorage and glNamedBufferStorage create a new immutable data store.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But if &lt;code&gt;glBufferData&lt;/code&gt; creates a &lt;code&gt;data store&lt;/code&gt; which cannot shrink in size then what's the point of it? (Unless I'm misunderstanding its intended use)&lt;/p&gt;&#xA;" OwnerUserId="6546" LastEditorUserId="6546" LastEditDate="2018-01-22T04:29:25.860" LastActivityDate="2018-01-22T19:23:56.733" Title="Replacing Vertex Attributes (glBufferData vs glBufferSubData)" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6142" PostTypeId="1" CreationDate="2018-01-22T07:45:13.940" Score="1" ViewCount="85" Body="&lt;p&gt;I read the corresponding chapter of PBRT-v3, as well as Veach's thesis which introduced BDPT. However I didn't quite understand why we use the measurement equation. It seems that the measurement equation can be further formulated to obtain different light transport algorithms, such as photon map and bdpt. But why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've searched for other literature but didn't find anything really useful. Can anyone give some hint?&lt;/p&gt;&#xA;" OwnerUserId="7334" LastActivityDate="2018-01-22T07:45:13.940" Title="How should I understand path-space measurement equation?" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;photon-mapping&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6144" PostTypeId="1" AcceptedAnswerId="6150" CreationDate="2018-01-22T14:35:40.417" Score="3" ViewCount="607" Body="&lt;p&gt;My question is about spherical harmonic lightning, in the context of computing the coefficients with an expensive GI algorithm and passing them to the vertex shader&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way is to just use an expensive GI algorithm to compute vertex colors and just use them instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the advantage of using the former method? I'm thinking that you can't do reflections with the latter method, and also there's rotational symmetry in SH (i don't know much about) that allows you to do some very simple dynamics with your lights and meshes. Is there any more points i'm missing?&lt;/p&gt;&#xA;" OwnerUserId="7035" LastEditorUserId="48" LastEditDate="2018-01-23T05:45:39.367" LastActivityDate="2018-01-23T09:09:35.907" Title="Advantages of spherical harmonics over baked vertex lighting?" Tags="&lt;real-time&gt;&lt;spherical-harmonics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6145" PostTypeId="1" CreationDate="2018-01-22T15:22:35.833" Score="1" ViewCount="214" Body="&lt;p&gt;&lt;a href=&quot;https://developer.apple.com/library/content/documentation/3DDrawing/Conceptual/MTLBestPracticesGuide/BufferBindings.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metal Best Practices Guide&lt;/a&gt; states that &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The setVertexBytes:length:atIndex: method is the best option for binding a very small amount (less than 4 KB) of dynamic buffer data to a vertex function&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I believe this means that instead storing uniforms in an overly complicated manually memory managed dynamic buffer, it's best to simply update model/view/projection matrices without using any buffer at all, by using &lt;code&gt;setVertexBytes&lt;/code&gt; and &lt;code&gt;setFragmentBytes&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, that in this case, as there is no dynamic buffer at all (only static vertex data), what are we calling triple buffering?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it simply because we have a semaphore with &lt;code&gt;value: 3&lt;/code&gt; left now?&lt;/p&gt;&#xA;" OwnerUserId="8068" LastActivityDate="2018-01-22T15:22:35.833" Title="Triple buffering without buffers?" Tags="&lt;metal&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6146" PostTypeId="2" ParentId="6141" CreationDate="2018-01-22T19:23:56.733" Score="2" Body="&lt;p&gt;There is a difference between &quot;can&quot; and &quot;should&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You &quot;should&quot; not use &lt;code&gt;glBufferData&lt;/code&gt; to change the size of an existing non-immutable buffer. You &lt;em&gt;can&lt;/em&gt; still do so, but don't expect this to be advantageous.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You &quot;can&quot; &lt;em&gt;not&lt;/em&gt; change the size of an immutable buffer with any function.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;How do I replace the whole VBO with my new data, but if my new data is smaller than the old data then how do I reallocated the VBO efficiently?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Why would you want to? If the size of your data got smaller, then it is entirely possible that a few frames from now it will be &lt;em&gt;bigger&lt;/em&gt; again. Perhaps bigger than it was before. That extra storage isn't waste; it is extra storage you're keeping around because you intend to use it at some point in the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cost of &lt;em&gt;allocating&lt;/em&gt; memory is high; you should avoid it whenever possible. If you need to increase the size of a buffer, then the implementation must allocate new storage for it. You want to avoid that whenever possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you ought to be doing is figuring out what a reasonable maximum size would be for this data, and then allocate a buffer of &lt;em&gt;that&lt;/em&gt; size.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Or is there something equivalent to a NULL terminating character where the graphics card can know not to read any further data?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That's up to you. You tell OpenGL exactly how many vertices to read from a vertex buffer. This is determined based on:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The vertex format for each attribute.&lt;/li&gt;&#xA;&lt;li&gt;The offset within the buffer for each attribute.&lt;/li&gt;&#xA;&lt;li&gt;The number of vertices you send in the &lt;code&gt;glDraw*&lt;/code&gt; command.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;OpenGL doesn't arbitrarily process data; it reads the data you &lt;em&gt;tell it&lt;/em&gt; to read. If you want it to not read past a certain point, stop telling it to read past that point ;)&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-01-22T19:23:56.733" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="6147" PostTypeId="1" AcceptedAnswerId="6149" CreationDate="2018-01-22T20:12:54.480" Score="3" ViewCount="1070" Body="&lt;p&gt;I recently implemented Mitchell-Netravali filtering in my path-tracer with 16x (4x4) temporal anti-aliasing. PBR's demonstration image shows it &lt;em&gt;should&lt;/em&gt; give significantly better results than the box filter, but my test pictures barely show any improvement at all (and the sharpening in Mitchell-Netravali actually highlights jaggies that would have been blurred out by the box filter).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this filter designed for a higher sampling rate? My samples are spread over an even sub-pixel grid, and I'm using $B$ and $C$ constants on the line $B + 2C = 1$. I'm also using the implementation recommended by PBR.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Function for $f(x, y)$:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Small functions returning the Mitchell-Netravali filter coefficient&#xA;// for a given 2D point&#xA;// Mitchell-Netravali interpolates sparse samples much more effectively&#xA;// than naive filtering (=&amp;gt; applying a box filter), allowing for more&#xA;// effective anti-aliasing at lower sampling rates&#xA;&#xA;// Core filter polynomial&#xA;float MitchellNetravaliPerAxis(float filtVal)&#xA;{&#xA;    // Mitchell-Netravali parameters&#xA;    // Mitchell and Netravali recommend parameters of the&#xA;    // form [B + 2C = 1]&#xA;    const float B = 0.35f;&#xA;    const float C = 0.325f;&#xA;&#xA;    // Powers of [filtVal] used during the filtering process&#xA;    float filtValCub = filtVal * filtVal * filtVal;&#xA;    float filtValSqr = filtVal * filtVal;&#xA;&#xA;    // Polynomial filter application&#xA;    if (filtVal &amp;gt; 1.0f)&#xA;    {&#xA;        // Filtering for values greater-than/equal-to one but less than two&#xA;        return ((B * -1.0f) - (6.0f * C)) * filtValCub +&#xA;               ((6.0f * B) + (30.0f * C)) * filtValSqr +&#xA;               ((-12.0f * B) - (48.0f * C)) * filtVal +&#xA;               ((8.0f * B) + (24.0f * C));&#xA;    }&#xA;    else&#xA;    {&#xA;        // Filtering for other possible values (less than one; values greater than&#xA;        // two are cancelled out by the division by pixel radius in [MitchellNetravali(...)]&#xA;        // (see below))&#xA;        return (12.0f - (9.0f * B) - (6.0f * C)) * filtValCub +&#xA;               (-18.0f + (12.0f * B) + (6.0f * C)) * filtValSqr +&#xA;               (6.0f - (2.0f * B));&#xA;    }&#xA;}&#xA;&#xA;// Wrapper function applying Mitchell-Netravali to the given sampling point within the&#xA;// given sampling radius&#xA;float MitchellNetravali(float2 sampleXY,&#xA;                        float sampleRad)&#xA;{&#xA;    float2 filtAxes = abs((sampleXY / sampleRad) * 2.0f);&#xA;    return (MitchellNetravaliPerAxis(filtAxes.x) *&#xA;            MitchellNetravaliPerAxis(filtAxes.y)) / 36.0f; // Dividing by 6 in each filter is equivalent to dividing the product of the filters by thirty-six (since 36 == 6^2)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Temporal integrator:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 FrameSmoothing(float3 rgb,&#xA;                  float filtCoeff,&#xA;                  uint linPixID)&#xA;{&#xA;    // Cache a local copy of the given pixel's smoothing history&#xA;    PixHistory pixHistory = aaBuffer[linPixID];&#xA;&#xA;    // Update the given pixel's sample count&#xA;    uint sampleCount = pixHistory.sampleCount.x + 1;&#xA;    uint sampleNdx = pixHistory.sampleCount.x % NUM_AA_SAMPLES;&#xA;&#xA;    // Update accumulated filter values&#xA;    float4 currChanFilt = filtCoeff.xxxx;&#xA;    float4 prevChanFilt = pixHistory.filtSet[sampleNdx];&#xA;    float4 accumFilt = (pixHistory.filtAccum - prevChanFilt) + filtCoeff.xxxx;&#xA;&#xA;    // Filter the pixel, update accumulated pixel values&#xA;    float4 currChanSample = float4(rgb, 1.0f) * filtCoeff;&#xA;    float4 prevChanSample = pixHistory.sampleSet[sampleNdx];&#xA;    float4 accumRGB = (pixHistory.sampleAccum - prevChanSample) + currChanSample;&#xA;&#xA;    // Pass the updated pixel history back into the AA buffer&#xA;    // (also update the pixel's sample-set to include the current sample)&#xA;    aaBuffer[linPixID].sampleAccum = accumRGB;&#xA;    aaBuffer[linPixID].filtAccum = accumFilt;&#xA;    aaBuffer[linPixID].sampleSet[sampleNdx] = currChanSample;&#xA;    aaBuffer[linPixID].filtSet[sampleNdx] = filtCoeff;&#xA;    aaBuffer[linPixID].sampleCount = sampleCount.xxxx;&#xA;&#xA;    // Return the updated sample&#xA;    // Some filter functions can push average values below zero; counter this clamping out negative channels&#xA;    // with [max(...)]&#xA;    return max(accumRGB.rgb / accumFilt.xxx, 0.0f.xxx);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Mitchell-Netravali, unjittered:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/mm0v9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mm0v9.png&quot; alt=&quot;Mitchell-Netravali, no jitter&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mitchell-Netravali, jittered:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Uwut6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Uwut6.png&quot; alt=&quot;Mitchell-Netravali, with jitter&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unjittered/jittered box-filtered images for comparison:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/hVrYR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hVrYR.png&quot; alt=&quot;Box filter, no jitter&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/PK0cs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PK0cs.png&quot; alt=&quot;Box filter, jittered&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-01-23T09:32:36.770" LastActivityDate="2018-01-23T09:32:36.770" Title="Unexpected results from Mitchell-Netravali" Tags="&lt;antialiasing&gt;&lt;hlsl&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6148" PostTypeId="1" AcceptedAnswerId="6151" CreationDate="2018-01-23T05:53:25.353" Score="5" ViewCount="579" Body="&lt;p&gt;Why sending data from gpu to cpu is slower than cpu to gpu?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I heard the relation is similar to network situation, in detail, the upload is slower than download. However, I could not understand the meaning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my opinion,  the sending operation should be same because the two sending buses (cpu to gpu and gpu to cpu) can be made with the same performance (I mean bendwith). &lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2018-01-26T20:56:24.617" Title="Why sending data from gpu to cpu is slower than cpu to gpu?" Tags="&lt;gpu&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6149" PostTypeId="2" ParentId="6147" CreationDate="2018-01-23T06:01:14.710" Score="3" Body="&lt;p&gt;Mitchell–Netravali has negative lobes, which are generally not recommended for small sample counts from what I understand; you tend to end up with both the positive and negative areas undersampled. Also, negative lobes do produce a sharpening or ringing effect that looks like what you're seeing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd try a nonnegative filter, such as a cut-off Gaussian or a &lt;a href=&quot;https://en.wikipedia.org/wiki/Window_function#Blackman%E2%80%93Harris_window&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blackman–Harris window&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-01-23T06:01:14.710" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6150" PostTypeId="2" ParentId="6144" CreationDate="2018-01-23T09:09:35.907" Score="3" Body="&lt;p&gt;Spherical harmonics are generally used for dynamic objects in your scene, while fully-baked lighting is used for static objects. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A typical game engine will use both. During the GI pass, all surfaces marked as static will have their global lighting fully baked - generally into a lightmap texture rather than per-vertex. At the same time, a bunch of light probes distributed throughout your scene will receive omnidirectional lighting, and this gets converted into SH. Since SH coefficients interpolate nicely, a mesh moving through your scene can pick up the nearest few light probes (generally 4), and use the weighted average to decode a good approximation of the ambient lighting at its current location.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another use for SH is to render less-important dynamic lights in a scene with many lights in it. The most important light or two can be rendered fully dynamically per-pixel, then for each renderer, the SH coefficients of the less-important lights are calculated and added to the light probe data. This allows the lights to change in real-time, and be rendered effectively for free per-vertex in the shader, with a small CPU overhead.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-01-23T09:09:35.907" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6151" PostTypeId="2" ParentId="6148" CreationDate="2018-01-23T12:04:46.377" Score="7" Body="&lt;p&gt;The actual sending of data is the same. The PCIe bus is the same speed in both directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However when programming there is a big difference namely that when you send you can immediately start doing something else (including queuing other operations using that new data) while the actual transfer is going on. But when receiving you need to synchronize on the completion of the transfer before you can use the data that was sent.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2018-01-26T20:56:24.617" LastActivityDate="2018-01-26T20:56:24.617" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="6153" PostTypeId="1" AcceptedAnswerId="6154" CreationDate="2018-01-24T09:24:04.060" Score="2" ViewCount="268" Body="&lt;p&gt;Quadrilateral linear basis functions(generalized barycentric coordinates) are defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OvNLJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OvNLJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the steps to calculate the above functions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to obtain basis functions for a 5 sided polygon(pentagon) or in general n-sided polygon? &lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2018-01-24T11:06:24.627" LastActivityDate="2018-01-24T20:58:42.627" Title="How to obtain generalized barycentric coordinates for n-sided polygon?" Tags="&lt;transformations&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6154" PostTypeId="2" ParentId="6153" CreationDate="2018-01-24T11:56:24.903" Score="3" Body="&lt;p&gt;Quadrilateral basis functions can be calculated using an outer product of the basis of two linear functions (1-r, r) and (1-s, s). The same thing does not apply for arbitrary $n$-sided domains. For this we use generalised barycentric coordinates. Wachspress coordinates are arguably the simplest generalised barycentric coordinates available, are fast to evaluate and are defined for arbitrary $n$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a point $p$ on a planar convex polygon defined by vertices $v_1, v_2, \ldots, v_n$, ordered counter-clockwise, you can find weights&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$w_i(p) = \frac{A(v_{i-1}, v_i, v_{i+1})}{A(v_{i-1}, v_i, p)A(v_{i}, v_{i+1}, p)}. $$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here, $A(v_1, v_2, v_3)$ denotes the signed triangle area. The coordinate functions $\phi_i$ can then be found be normalising the weights $w_i(p)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\phi_i(p) = \frac{w_i(p)}{\sum_{j=1}^n w_j(p)}.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the coordinate functions correctly parametrise the point (linear reproduction property)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$p = \sum_{i=1}^n v_i \phi_i(p).$$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;At vertices the coordinates satisfy the Lagrange property $\phi_i(v_j) = \delta_{ij},$ where $\delta_{ij}$ is the Kronecker delta, meaning that the corresponding coordinate function evaluates to 1 at its vertex and linearly interpolate on the edges. It is also important to notice that the coordinate partition unity $\sum_{i=1}^n \phi_i(p) = 1.$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For, non-convex polygons you could use &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.104.6059&amp;amp;rep=rep1&amp;amp;type=pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;mean value coordinates.&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2018-01-24T20:58:42.627" LastActivityDate="2018-01-24T20:58:42.627" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6155" PostTypeId="1" CreationDate="2018-01-24T14:23:31.153" Score="3" ViewCount="61" Body="&lt;p&gt;Currently I'm trying to reproduce the result by the academic papers &lt;strong&gt;&lt;em&gt;Sub-pixel Shift Estimation of Image based on the Least Squares Approximation in Phase Region by Fujimoto, Fujisawa and Ikehara&lt;/em&gt;&lt;/strong&gt; (Proceedings of 26th European Signal Processing Conference, EUSIPCO '16, pp. 91–95. IEEE, 2016 &lt;a href=&quot;https://mega.nz/#!vp9WFDbb!pEG8pem9n2SaX8IHxbUxnD4JT6ngp0nF608T3zAeiJY&quot; rel=&quot;nofollow noreferrer&quot;&gt;PDF&lt;/a&gt;). However there's a part that I don't understand, hope you guys could help me out!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, the author uses phase to determine the subpixel shifting of two images instead the conventional way of fitting the peak POC. The overview of the method is described in this chart:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Od10d.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Od10d.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I got stuck at the subtraction junction. If you refer to the &lt;a href=&quot;https://mega.nz/#!vp9WFDbb!pEG8pem9n2SaX8IHxbUxnD4JT6ngp0nF608T3zAeiJY&quot; rel=&quot;nofollow noreferrer&quot;&gt;PDF&lt;/a&gt; file I attached, Figure 3 shows the phase over-wrap between &lt;code&gt;-pi&lt;/code&gt; and &lt;code&gt;pi&lt;/code&gt;, and the author proposed that the phase can be split into two components, that's the integer shift and decimal shift so that the phase can be smoother out as shown in Fig. 4. This is where I don't understand, according to the &lt;em&gt;Eqn. 14&lt;/em&gt;, the decimal phase could be obtained via:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/96yLM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/96yLM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is where things get confused, the subtraction of &lt;code&gt;(a'k1 + b'k2)&lt;/code&gt; gets me nowhere. The author said that the value of &lt;code&gt;a'&lt;/code&gt; and &lt;code&gt;b'&lt;/code&gt; (the slopes) is obtained via the conventional POC (paragraph above Eqn. 14). My question is, how? I could retrieve the integer shift using the cross power spectrum, &lt;strong&gt;but not the slopes&lt;/strong&gt;. Hope you guys could help me out! I got stuck for months!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the information provided is not adequate, let me know and I'll do my best! Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="8078" LastActivityDate="2018-01-24T14:23:31.153" Title="Sub-pixel image registration using phase" Tags="&lt;image-processing&gt;&lt;fourier-transform&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6156" PostTypeId="1" CreationDate="2018-01-24T15:54:36.527" Score="5" ViewCount="582" Body="&lt;p&gt;I was reading &quot;3D Math Primer for Computer Graphics and Game Development&quot; and there was something the author had said that I thought was particularly interesting, he stated &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;It is important to understand that this matrix multiplication is still a&#xA;  linear transformation. Matrix multiplication cannot represent “translation”&#xA;  in 4D, and the 4D zero vector will always be transformed back into the 4D&#xA;  zero vector. The reason this trick works to transform points in 3D is that&#xA;  we are actually shearing 4D space. (Compare Equation (6.11) with the&#xA;  shear matrices from Section 5.5.) The 4D hyperplane that corresponds to&#xA;  physical 3D space does not pass through the origin in 4D. Thus, when we&#xA;  shear 4D space, we are able to translate in 3D.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm familiar with the shearing transformation, and I can see how a translation matrix in 4D resembles that of a 3D shear. I did not quite understand how this translation in 3D though. So, restating the question I had asked, how does a shear in 4D equate to a translation in 3D space? A geometric visual would also be nice to help me understand this a bit more.&lt;/p&gt;&#xA;" OwnerUserId="8079" LastActivityDate="2018-01-25T10:52:33.637" Title="why is translating in 3D space the same as shearing in 4D space?" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;matrix&gt;&lt;affine-transformations&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6157" PostTypeId="1" AcceptedAnswerId="6166" CreationDate="2018-01-24T16:44:27.910" Score="2" ViewCount="373" Body="&lt;p&gt;I have a scene set up with an orthographic projection with the near / far set from -5000 to 5000.  The model view is centered at 0 in the z-axis.  I am rendering a sphere centered at z=0 with lighting, and the specular component appears as to be calculated as if the eye were infinity far back.  See image below, in which the light only has a red specular component, no diffuse or other parameters.  However, if i render this with a custom shader that implements &lt;a href=&quot;https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_shading_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;blinn&lt;/a&gt; lighting, the sphere appears black, because the &quot;viewDir&quot; calculation is negative, since the eye is centered inside the sphere.  How does fixed function get around this?  Does it some how know about the ortho projection and get around it?  Sources I've seen online say lighting is not supposed to take the projection into account.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ire0b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ire0b.png&quot; alt=&quot;fixed function specular with ortho projection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3332" LastEditorUserId="3332" LastEditDate="2018-01-26T20:39:09.377" LastActivityDate="2018-01-26T20:39:09.377" Title="How does opengl fixed function pipeline determine specular lighting with an orthographic projection" Tags="&lt;opengl&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6159" PostTypeId="1" CreationDate="2018-01-24T16:51:40.940" Score="3" ViewCount="302" Body="&lt;p&gt;Nvidia discusses their lossless delta color compression is on its fourth generation in Pascal, and that it transparently saves bandwidth behind the scenes for rendering workloads. AMD has a similar technology, discussed in detail here: &lt;a href=&quot;https://gpuopen.com/dcc-overview/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gpuopen.com/dcc-overview/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do the same limitations apply to Nvidia's compression? They don't seem to discuss it in context of developer guidance.&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2018-01-24T16:51:40.940" Title="Is Nvidia's delta color compression supported in CUDA, or with DirectX UAVs?" Tags="&lt;gpu&gt;&lt;compression&gt;&lt;cuda&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6160" PostTypeId="2" ParentId="6116" CreationDate="2018-01-24T17:01:02.543" Score="2" Body="&lt;p&gt;You havent' set the &lt;code&gt;mipFilter&lt;/code&gt; property for your &lt;code&gt;samplerDescriptor&lt;/code&gt;.  The default value for &lt;code&gt;mipFilter&lt;/code&gt; is &lt;code&gt;notMipped&lt;/code&gt; which means the sampler will never access anything other than level 0. Set it to &lt;code&gt;nearest&lt;/code&gt; or &lt;code&gt;linear&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2018-01-24T17:01:02.543" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6162" PostTypeId="1" AcceptedAnswerId="6163" CreationDate="2018-01-25T04:27:55.110" Score="6" ViewCount="1305" Body="&lt;p&gt;The Lambertian BRDF is defined as $R / \pi$, where the division by $\pi$ is there to maintain conservation of energy. The derivation is provided &lt;a href=&quot;http://rorydriscoll.com/2009/01/25/energy-conservation-in-games/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The maths makes sense, and I can understand where the BRDF comes from in a mechanical sense. But I'm struggling to understand what it &lt;em&gt;represents&lt;/em&gt;; how does division by $\pi$ relate to reflectance within the unit hemisphere?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-01-25T05:35:27.713" LastActivityDate="2018-01-25T06:41:28.923" Title="Intuitively understanding conservation of energy for the Lambertian BRDF" Tags="&lt;brdf&gt;&lt;diffuse&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6163" PostTypeId="2" ParentId="6162" CreationDate="2018-01-25T06:41:28.923" Score="3" Body="&lt;p&gt;A perfect Lambert reflector actually reflects light in a cosine distribution - that is, the amount of light per unit area reflected in any given direction $R$ is proportional to $N.R$. The reason the radiance appears constant for all angles is that as the view direction moves away from the normal, the reflected light per unit area decreases, but the surface area per projected beam area (and hence per pixel) increases by the same amount - the cosine factors cancel out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given this distribution, to be energy conserving, the probability density for the reflected light in all possible directions cannot sum to more than 1. If you integrate the cosine function over the whole hemisphere around the normal, you get $\pi$, so this is the normalization factor you need.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-01-25T06:41:28.923" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6164" PostTypeId="2" ParentId="6156" CreationDate="2018-01-25T10:52:33.637" Score="4" Body="&lt;p&gt;In a linear transformation system, your origin is always a fixed point, since 0*anything = 0. So imagine you have a cinema screen, and the origin is at the centre of the screen. Using linear transformations, you can rotate, scale or shear the image, what you can't do is move it, since you have a fixed point in the middle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now add a dimension, and move your origin out of the screen through this new dimension. Your origin is now at the projector, at &amp;lt;0, 0, 0&gt;, and the centre of your screen is at &amp;lt;0, 0, 1&gt;. So as well as the image transforms you had available before, you can now effectively move your image, by shearing through the space in between the projector and the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Add another dimension and you have the 4D -&gt; 3D case.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-01-25T10:52:33.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6165" PostTypeId="1" AcceptedAnswerId="6168" CreationDate="2018-01-25T11:06:29.373" Score="2" ViewCount="433" Body="&lt;p&gt;When using &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Transform_Feedback&quot; rel=&quot;nofollow noreferrer&quot;&gt;Transform Feedback&lt;/a&gt; to capture the vertices generated by the primtive generation stage, we can use &lt;code&gt;glDrawTransformFeedback&lt;/code&gt; to directly draw the generated data without the need for querying the number of generated primitives and thus &lt;strong&gt;without CPU-GPU synchronization&lt;/strong&gt;, which is especially useful with geometry shaders generating a possibly unknown number of primitives.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in my case I'm not using the generated primitive data per-vertex, but &lt;strong&gt;per-instance&lt;/strong&gt; (it's basically a classic GPU-based instance culling scenario). So I need to &lt;strong&gt;supply the number of generated primitives into the instance count parameter of &lt;code&gt;glDraw...Instanced&lt;/code&gt;&lt;/strong&gt;. But the various &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Rendering#Transform_feedback_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;Transform Feedback rendering functions&lt;/a&gt; only ever use the primitive count as vertex count and never as instance count. Now this &lt;em&gt;does&lt;/em&gt; require me to wait for the transform feedback to finish and get the result of the corresponding query object, thus instroducing a synchronization point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I considered that I could also use the quite powerful &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Rendering#Indirect_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;Indirect Rendering&lt;/a&gt; functionality and together with a &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Query_Object#Query_buffer_object&quot; rel=&quot;nofollow noreferrer&quot;&gt;Query Buffer Object&lt;/a&gt; route the result of the transform feedback query directly into the instance count field of the draw indirect buffer. But this has the problem that I'm &lt;strong&gt;not only issuing a single &lt;code&gt;glDraw...Instanced&lt;/code&gt; call, but multiple different ones&lt;/strong&gt; (each with their own state, per-vertex attributes and draw parameters, but all with the same instance count and per-instance attributes). So I would actually have to scatter the query result into multiple drawing parameter sets (though, possibly in the same buffer), probably by use of a compute shader. But this just seems like overkill to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is, &lt;strong&gt;is there any other less involved way to just use the number of primitives/vertices generated from transform feedback directly as the instance count in (preferably multiple different) instanced rendering commands without the need to explicitly query that count onto the CPU?&lt;/strong&gt; In light of GPU-based scene culling techniques I can't imagine this to be a rare use-case (but maybe in that case you just have to go the way over indirect drawing commands anyway). I'm not afraid of using extensions if available, so maybe there's some obscure little extension that does exactly that? Or I'm just missing something else obvious here.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2018-01-25T18:07:07.553" LastActivityDate="2018-01-25T18:13:29.840" Title="Directly use Transform Feedback primitive count as instance count for drawing" Tags="&lt;opengl&gt;&lt;synchronization&gt;&lt;transform-feedback&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6166" PostTypeId="2" ParentId="6157" CreationDate="2018-01-25T12:41:26.880" Score="2" Body="&lt;p&gt;This isn't necessarily due to the orthographic projection per se, but rather the classic two-sided lighting problem together with a little optimization that the old OpenGL did. When the eye space origin is inside the object, you are basically &lt;strong&gt;looking at the object from the inside&lt;/strong&gt; and it's only the peculiarities of orthographic projection and the near/far planes you chose that makes the outsides appear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It depends on how you actually implement your shader. I &lt;em&gt;assume&lt;/em&gt; though, when you compute your &lt;code&gt;viewDir&lt;/code&gt;, you just use the vector from the eye space vertex to the origin (or rather the negative normalized eye space vertex position). You are basically trying to &lt;strong&gt;light the backfaces of the sphere&lt;/strong&gt; and if you haven't taken account for that, the angle between the view vector and the normal will thus be larger than 90°, usually resulting in a negative or 0-clamped specular term (or whatever other unexpected results).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A common way to accomodate for that would be to negate the normal vector whenever it is facing away from the camera, or maybe the light, or when dealing with backfacing fragments,... But this depends on your specific use-case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, &lt;strong&gt;why doesn't this happen in old deprecated OpenGL&lt;/strong&gt; when using orthographic projection?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this we have to look at the specificities of how it did its lighting computations. There was a function &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glLightModel.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glLightModel&lt;/code&gt;&lt;/a&gt; which controlled some of the global properties of lighting computations. Specifically, the paramter &lt;code&gt;GL_LIGHT_MODEL_LOCAL_VIEWER&lt;/code&gt;. This controls an optimization where the specular computation does &lt;em&gt;not&lt;/em&gt; use the actual vector from the vertex to the camera, but &lt;strong&gt;always just uses the z-axis&lt;/strong&gt; instead. i.e. as you said it assumes an infinitely far away viewer along the z-axis. This is the reason why even in perspective projection the specular highlight on an object is always at the same position, even if you move it around in the view. If you change this setting from the default of &lt;code&gt;GL_FALSE&lt;/code&gt; to &lt;code&gt;GL_TRUE&lt;/code&gt;, it should perform an actual view vector computation and you should get the same results as with your own shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There was also another option that controls a property related to your general issue, too. &lt;code&gt;GL_LIGHT_MODEL_TWO_SIDE&lt;/code&gt; enables two-sided lighting, which means that back-facing polygons will be lit like their front faces (however, possibly using different material settings) by using the inverted normal. If you activate this, this still won't change anything in your orthographic scene, since &lt;strong&gt;you &lt;em&gt;are&lt;/em&gt; seeing the front faces&lt;/strong&gt; of the sphere here. But once you change to perspective projection, the lighting should be black, but this time because you're seeing the backfaces, which you can enable lighting for with this option.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-01-25T12:41:26.880" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6167" PostTypeId="1" CreationDate="2018-01-25T14:09:04.967" Score="2" ViewCount="103" Body="&lt;p&gt;Problem: I'm trying to dynamically texture a mesh of the real world generated by the Hololens over time using photos also captured from the Hololens, perhaps one photo per second. Each of the photos includes positional information of the Hololens from the time when the photo was taken, which allows me to project the images onto the existing mesh and figure out the UV mapping for each image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case of a single image, this seems fairly simple, as it is just standard projective texturing of the mesh. But I will be capturing a potentially endless stream of images over a span of time which will be taken from different positions and orientations. For acceptable performance, I cannot simply store and iterate through all photos and do projective texturing for each.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I perhaps generate a texture atlas &amp;amp; accompanying UV mapping for the real world mesh and update it after each image?&lt;/p&gt;&#xA;" OwnerUserId="72" LastActivityDate="2018-01-30T05:59:28.620" Title="Projective texturing from many images" Tags="&lt;texture&gt;&lt;projections&gt;&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6168" PostTypeId="2" ParentId="6165" CreationDate="2018-01-25T15:07:37.197" Score="2" Body="&lt;p&gt;The complexity of this makes it seem like you don't really want to use transform feedback; you want to use a &lt;em&gt;compute shader&lt;/em&gt;. Then, through &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Indirect_Rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;indirect rendering&lt;/a&gt; and &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;SSBOs&lt;/a&gt;, you can write whatever vertex commands data you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is that you have some number of indirect rendering commands (one command per set of instances). And for each instance you create, the CS invocation needs to bump the instance count of each of those commands (atomically, of course).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, because there are state changes between the commands, you wouldn't be able to use a multi-draw indirect command. But by using indirect commands and a CS, you can at least keep all of the data on the GPU, without having to do things like buffer copies to multiple locations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Transform feedback is merely an ad-hoc mechanism for something that modern OpenGL allows you to just do directly. If you need to broadcast the &quot;primitive&quot; count to multiple locations (or really, if you're doing anything besides rendering the feedbacked data), then you should be using a compute shader, not TF.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2018-01-25T18:13:29.840" LastActivityDate="2018-01-25T18:13:29.840" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6169" PostTypeId="1" AcceptedAnswerId="6174" CreationDate="2018-01-25T23:11:35.143" Score="1" ViewCount="772" Body="&lt;p&gt;According to: &lt;a href=&quot;https://www.cs.virginia.edu/~jdl/importance.doc&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.cs.virginia.edu/~jdl/importance.doc&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a specular sample: (page 4 of the document) $$pdf(\theta_{i}) = \frac{n+1}{2\pi} \cos^n(a)$$  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is how you choose an incoming direction according to a specular sample of the BRDF (page 4 of the document):&#xA;$$ \vec{w_{i}} = (\alpha, \phi) = (\arccos(\varepsilon_{1}^{  \frac{1}{n+1}  }), \ \  2\pi\varepsilon_{2})$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But according to the figure on page 4, a specular sample has a BRDF favoring a direction which is highly dependent on the incoming ray, but the $ \phi $ angle is decided by uniformly sampling a circle, disregarding completely the incoming direction, which to me makes no sense&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shouldn't the $ \phi $ angle favor the specular direction, which is dependent on the incoming ray? Why we're not using at all the incoming ray to calculate the sampled direction which is supposedly sampling the brdf?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;No matter where I look for it, I haven't seen an implementation using a BRDF which takes into account the incoming direction, which makes me think I've misunderstood the theory behind it&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, assuming a standard backward path tracer, is this pseudocode the right way of computing the results?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color =  float3(1,1,1)&#xA;ray   =  getRayFromCamera()&#xA;&#xA;for NUM_BOUNCES:&#xA;    primitive = world.intersect(ray)    &#xA;&#xA;    // assuming primitive is non null, I'm omitting the code where we sample a background&#xA;    albedo           = primitive.albedo&#xA;&#xA;    // computeOutGoingRay will return a Ray and a PDF&#xA;    outgoingRay, pdf = primitive.material.computeOutGoingRay(ray, normal, etc..)&#xA;&#xA;    // of the incoming radiance, how much is scattered along the new direction?&#xA;    brdf             = primitive.brdf(outgoingRay, ray)&#xA;&#xA;    color = (color * albedo * brdf) / pdf&#xA;&#xA;    // assigning the new ray to keep our backward recursion&#xA;    ray   = outGoingRay&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7871" LastActivityDate="2018-01-26T22:25:05.040" Title="Phong Modified BRDF Implementation" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;physically-based&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6172" PostTypeId="1" CreationDate="2018-01-26T14:32:31.200" Score="4" ViewCount="361" Body="&lt;p&gt;I'm writing a halftone algorithm, which takes standards RGB intensities in the range of $0-255$ and outputs black and white elements with a corresponding size ratio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I apply a gamma expansion on the input luminance to get the ratio?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I.e. is it correct to do the following?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{w_\text{white}}{w_\text{white}+w_\text{black}} = (0.299 R + 0.587 G + 0.114 B)^{2.2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I apply the exponent of $2.2$?&lt;/p&gt;&#xA;" OwnerUserId="8097" LastActivityDate="2018-03-28T17:40:33.560" Title="Gamma correction and halftone" Tags="&lt;gamma&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6173" PostTypeId="2" ParentId="6172" CreationDate="2018-01-26T14:32:31.200" Score="1" Body="&lt;p&gt;Yes and no. The RGB values are most likely gamma compressed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider gamma calibration images like the one below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a well calibrated monitor the gray value should look the same as the pattern of black and white lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you load in the image you will likely find RGB values of $186$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(186/255)^{2.2} \approx 0.5$, which means that a halftone pattern of black and white lines of equal width correspond to RGB values of 186.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HLZNI.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HLZNI.gif&quot; alt=&quot;gamma calibration image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;However, the gamma compression applied was more likely the sRGB gamma compression than an overall gamma of $2.2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\frac{w_\text{white}}{w_\text{white}+w_\text{black}} =&#xA;\begin{cases}&#xA;12.92V  &amp;amp;\text{ if } V \leq 0.0031308 \\&#xA;1.055 V^{1/2.4} + 0.055 &amp;amp;\text{ if } V &amp;gt; 0.0031308 &#xA;\end{cases}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $V = 0.299R+0.587G+0.114B$&lt;/p&gt;&#xA;" OwnerUserId="8097" LastEditorUserId="8097" LastEditDate="2018-01-27T16:40:15.027" LastActivityDate="2018-01-27T16:40:15.027" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6174" PostTypeId="2" ParentId="6169" CreationDate="2018-01-26T22:25:05.040" Score="1" Body="&lt;p&gt;Consider the following scheme that mimicks the generation of a sample for phong shading. where V is the viewer direction, N is the normal, R is the specular reflection direction and $S_i$ is some sample. This space (commonly called tangent space) uses the normal as one of its basis vectors. you can think of it as the 'Z axis'&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xYz3F.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xYz3F.png&quot; alt=&quot;tangent space&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, when we generate samples for Phong shading wo do not generate them in this space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rather, we use a different reference system where the Specular reflection direction is the 'z axis', thus, our angle $\theta$ is the angle between the reflected direction and the sample direction, and the angle $\phi$ is the angle between some $S_{ix}$ that is the projection of our sample direction onto the plane perpendicular to $R$ and some arbitrary but constant vector perpendicular to our reflected direction&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MxqAm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MxqAm.png&quot; alt=&quot;ray space&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\phi$ is a number that is sampled uniformly in the range $(0,2\pi)$ this means that rays will be generated around the reflected direction with no bias towards any particular direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generated rays will, however, be biased to have a direction close to $R$ due to the way that $\theta$ is sampled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When we generate rays in a backwards pathtracer we use the view direction to get the directions where the light is likely to come from, instead of throwing light around and seeing where it falls. The later technique is closer to photon mapping.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-01-26T22:25:05.040" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6175" PostTypeId="1" CreationDate="2018-01-27T05:47:23.827" Score="1" ViewCount="272" Body="&lt;p&gt;All &quot;scene graphs&quot; I've seen in practice are actually trees, but I have some vague memories about somebody saying a while ago that sometimes they can actually be graphs (technically, trees are already graphs, but you get the point).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If they can actually be graphs, what are some practical examples?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If they're always just trees, is there some history behind why it was originally called &quot;scene graph&quot;?&lt;/p&gt;&#xA;" OwnerUserId="8101" LastEditorUserId="8101" LastEditDate="2018-01-27T05:57:25.307" LastActivityDate="2018-02-26T06:53:03.133" Title="is a scene graph actually a tree?" Tags="&lt;data-structure&gt;&lt;scene-graph&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6176" PostTypeId="2" ParentId="6175" CreationDate="2018-01-27T06:50:30.843" Score="1" Body="&lt;p&gt;Yes, scene graphs can be non-tree graphs. Your question is a little vague, but assuming you're talking about something like the scene graph in rendering a frame of video, for say a feature film, then yes, there are often references between objects. For example, in a compositing application, you might have a piece of footage with an effect applied. The effect may have as one of its inputs another piece of footage which is also in the scene. (It might use the other image for blending, as a reflection map, as a diffuse or specular lighting map, a bump map etc.) So you could have a scene that looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;scene contains:&#xA;    footage A contains:&#xA;        filter &quot;Multiply Blend&quot; which takes input:&#xA;            footage B&#xA;    footage B&#xA;    footage C&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In something like a game, you might objects that refer to other objects that they can collide with:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;scene contains:&#xA;    ground which can collide with:&#xA;        player&#xA;        ball&#xA;        goal&#xA;    player which can collide with:&#xA;        ground&#xA;        ball&#xA;        goal&#xA;    ball which can collide with:&#xA;        player&#xA;        ground&#xA;        goal&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;etc.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-01-27T06:50:30.843" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6177" PostTypeId="1" AcceptedAnswerId="6179" CreationDate="2018-01-27T19:43:47.653" Score="2" ViewCount="250" Body="&lt;p&gt;I want to create a histogram of intensities 0.1, 0.2, .... 0.9, 1, from an image rendered using OpenGL and C++. How can I do this? Can I access the pixel intensities in the framebuffer somehow? Also, I'm not using any glsl shaders, and don't intend to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I tried:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned char *framebuffer = frameBuffer = new unsigned char[1920*1080 * 4];&#xA;&#xA;glReadPixels(0, 0, 1920, 1080, GL_RGBA, GL_UNSIGNED_BYTE, frameBuffer);&#xA;&#xA;for (int j = 0; j&amp;lt;1920*1080 * 4; j += 4){&#xA;    if(frameBuffer[j] == 0.1)&#xA;        // find pixel with R channel at 0.1: this is where the problem is.&#xA;        // I know I have surfaces with this intensity but I never enter the if statement&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5183" LastEditorDisplayName="user7220" LastEditDate="2018-03-06T22:12:10.657" LastActivityDate="2018-03-06T22:12:10.657" Title="Histogram of image intensities" Tags="&lt;opengl&gt;&lt;image-processing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6178" PostTypeId="1" AcceptedAnswerId="6196" CreationDate="2018-01-27T23:30:33.477" Score="6" ViewCount="1295" Body="&lt;p&gt;I recently replaced the Lambertian BRDF in my path-tracer with Oren-Nayar, under the assumption that I could adjust it to use the GGX distribution model with appropriate masking/shadowing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PBR suggests this is't viable, though - Oren-Nayar is formulated without any clear $D$/$F$/$G$ parameters, and a note under the Torrance-Sparrow model states that &quot;one of the nice things about the Torrance-Sparrow model is that &lt;strong&gt;the derivation doesn't depend on the particular microfacet distribution being used&lt;/strong&gt;&quot; (implying this isn't the case for Oren-Nayar).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If Oren-Nayar &lt;em&gt;is&lt;/em&gt; extensible, how would I do that? I suspect I could replace my $\sigma$ values with an NDF taking some $\alpha$ parameter (effectively convolving against the implicit Gaussian in the Oren-Nayar definition), and multiply the evaluated Oren-Nayar function against $G$ to capture masked segments of $dA$, but won't this clash with assumptions made by the derivation? PBR states that the function natively accounts for Gaussian-distributed masking, so applying another function over the top should result in over-darkening...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it isn't extensible, can I adjust Torrance-Sparrow instead? Locking $F(\omega_o)$ to $1$ should remove Fresnel effects, and the specular assumption can be negated by extracting the $d\omega_h = \frac{d\omega_o}{4\cos\theta_o}$ relationship to create the modified BRDF $f(\omega_o, \omega_i) = \frac{D(\omega_h)G(\omega_o,\ \omega_i)d\omega_h}{d\omega_o\cos\theta_o}$ &lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-01-27T23:52:51.197" LastActivityDate="2018-02-05T09:12:31.940" Title="Microfacet shading for diffuse materials" Tags="&lt;mathematics&gt;&lt;brdf&gt;&lt;pbr&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6179" PostTypeId="2" ParentId="6177" CreationDate="2018-01-27T23:35:46.803" Score="2" Body="&lt;p&gt;Due the way floating point values work, you probably don't want to do an exact equality check. You probably want something more like this in your loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uint32 sums [ 11 ] = { 0 };&#xA;for (int j = 0; j &amp;lt; 1920 * 1080 * 4; j += 4) {&#xA;    size_t bucket = static_cast&amp;lt;size_t&amp;gt;(framebuffer [ j ] * 10.0);&#xA;    sums [ bucket ]++;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that there are 11 buckets because the range includes both 0 and 1. If you want only 10 buckets and want to put any pixels that have a value of 1 in them into the top bucket, you could do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uint32 sums [ 10 ] = { 0 };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and change the bucket index calculation to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;size_t bucket = static_cast&amp;lt;size_t&amp;gt;(framebuffer [ j ] * 10.0);&#xA;bucket = std::min(bucket, 9);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-01-27T23:35:46.803" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6180" PostTypeId="1" CreationDate="2018-01-28T00:36:51.950" Score="2" ViewCount="467" Body="&lt;p&gt;I'm trying to implement a simple Phong shader that supports non-physically-based materials and textures. Even though the material has a texture for each light component I still want the respective material coefficient to have some effect. My doubt is how to handle both of them. Should I mix, multiply or sum them?&#xA;Right now I've multiplied them:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ambient  = material.ambient_color  * light.ambient  * texture_ambient;&#xA;diffuse  = material.diffuse_color  * light.diffuse  * diffuse_strength  * texture_diffuse;&#xA;specular = material.specular_color * light.specular * specular_strength * texture_specular;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It seems kinda dark, is this the correct way to combine material coefficients and textures?&lt;/p&gt;&#xA;" OwnerUserId="7925" LastActivityDate="2018-09-12T03:35:18.603" Title="Combine material coefficients and textures in Phong Shading" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;glsl&gt;&lt;shading&gt;&lt;material&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6181" PostTypeId="1" CreationDate="2018-01-29T09:36:56.203" Score="2" ViewCount="110" Body="&lt;p&gt;I'm reading the Loper et al. 2015 paper on the Skinned Multi-Person Linear Model and I came across this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;What we would like is a vertex-based model that has the expressive&#xA;  power of the triangle deformation models so that it can capture&#xA;  a whole range of natural shapes and poses.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm not a Computer Science student, I'm actually a Physics student, so I only have an elementary understanding of these matters. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the difference between a triangle-based and a vertex-based skinning model? &#xA;Why is the triangle-based one more &quot;expressive&quot;?&lt;/p&gt;&#xA;" OwnerUserId="8107" LastActivityDate="2018-01-29T09:36:56.203" Title="Triangle-based and vertex-based skinning models?" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;animation&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6182" PostTypeId="2" ParentId="6167" CreationDate="2018-01-29T10:04:27.857" Score="1" Body="&lt;p&gt;Apologies in advance for the poor quality of this answer, but this sounds a little like what an ex-colleague was doing as part of his PhD. The &quot;Free-Viewpoint video&quot; papers listed at the bottom of &lt;a href=&quot;https://www.researchgate.net/profile/James_Imber&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.researchgate.net/profile/James_Imber&lt;/a&gt; might be useful, or at least a starting point to find related work. &lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2018-01-29T10:04:27.857" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6183" PostTypeId="1" AcceptedAnswerId="6184" CreationDate="2018-01-29T10:32:17.417" Score="3" ViewCount="279" Body="&lt;p&gt;My professor gave me the following example exam question:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Given 4 spheres with diameter = 1. Their centers are located on&#xA;  coordinates (2,4,0), (4,2,0), (4,6,0) and (6,4,0), as seen in the&#xA;  picture below. Three different hierarchies of tightest possible&#xA;  axis-aligned bounding volumes (AABB) are given:&lt;/p&gt;&#xA;  &#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;A single AABB around every sphere&lt;/li&gt;&#xA;  &lt;li&gt;An AABB around the spheres with center (2,4,0) and (4,2,0) and    another around the spheres located at (4,6,0) and (6,4,0).&lt;/li&gt;&#xA;  &lt;li&gt;An AABB around the spheres with center (2,4,0) and (6,4,0) and    another around the spheres located at (4,2,0) and (4,6,0).&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;  &#xA;  &lt;p&gt;For every one of these the all-containing AABB is constructed.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IEBNK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IEBNK.png&quot; alt=&quot;Assignment&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The questions are:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;Rank these 3 structures based on efficiency for intersecting a ray    with these spheres (best to worst)&lt;/li&gt;&#xA;  &lt;li&gt;Does this ranking change if we change the spheres with a (scaled) tea-pot that still fits within the bounding volume?&lt;/li&gt;&#xA;  &lt;li&gt;Can this ranking depend on the position of the camera, when we only    consider visibility rays (so no shadow rays, for example)? You can assume you're working with an orthographic camera.&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;He insisted on not giving a 'philosophical' answer (like: 'this depends on ...') but rather actually calculating the cost using the surface are heuristic etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Only, I have no idea how to start. The cost function we have seen is defined as follows&#xA;$$Cost(cell) = C_t + \frac{S_L}{S_{Cell}} \times N_L \times t_i + \frac{S_R}{S_{Cell}} \times N_R \times t_i$$&#xA;With:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$C_t$ the cost of traversal (which is an arbitrary constant, I think)&lt;/li&gt;&#xA;&lt;li&gt;$S_L$/$S_R$ the surface area of the left/right child cell&lt;/li&gt;&#xA;&lt;li&gt;$S_{cell}$ the surface area of the entire cell&lt;/li&gt;&#xA;&lt;li&gt;$N_L$/$N_R$ the number of objects in the left/right child cell&lt;/li&gt;&#xA;&lt;li&gt;$t_i$ the cost of object intersection (which is also an arbitrary&#xA;constant)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;However, the first hierarchy has 4 child cells, how would I calculate the cost here? Any tips on how to start this exercise would be very helpful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; Okay, so for the second and third setup, is it as simple as filling in the formula? For the second setup, this would lead to (assuming I made no numerical errors :) ):&#xA;$$\begin{align*}Cost(cell) &amp;amp;= C_t + \frac{2*3^2 + 4*3*1}{2*5^2 + 4*5*1} * 2 * t_i + \frac{2*3^2 + 4*3*1}{2*5^2 + 4*5*1} * 2 * t_i \\ &amp;amp;= C_t + \frac{120}{70} * t_i \end{align*}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the third setup this would, analogously, lead to:&#xA;$$Cost(cell) = C_t + \frac{88}{70}*t_i$$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;So now my question would boil down to: can I just do the same for the first setup, but instead evaluate 4 sub-cells? Also, am I correct in assuming $C_t$ and $t_i$ are fixed constants or do they depend on the setup?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="8108" LastEditorUserId="8108" LastEditDate="2018-01-29T19:41:09.203" LastActivityDate="2018-01-29T19:41:09.203" Title="Classify acceleration structure using surface area heuristic" Tags="&lt;raytracing&gt;&lt;ray&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6184" PostTypeId="2" ParentId="6183" CreationDate="2018-01-29T11:45:02.767" Score="1" Body="&lt;p&gt;You gave the formula as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$Cost(cell) = C_t + \frac{S_L}{S_{Cell}} \times N_L \times t_i + \frac{S_R}{S_{Cell}} \times N_R \times t_i$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(You put $r_i$ at the right-hand end, but I assume that was a typo.) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a more general form of this formula&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$Cost(cell) = C_t + \sum_{k\ \in\ K} \frac{S_k}{S_{Cell}} \times N_k \times t_i$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $K$ is the set of all child nodes; that is, to get back to the two-children form you started with, $K = \{L, R\}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By generalising the formula like this, you can now calculate the cost for the first possibility the same way as the second two.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You're right that this is a slightly odd question. In practice, your traversal cost is going to be less for a binary tree than a $(&amp;gt; 2)$-ary tree.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;Does this ranking change if we change the spheres with a (scaled) tea-pot that still fits within the bounding volume?&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;To answer this, you'll need to consider how this affects the surface area, and how this changes each score in turn.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;Can this ranking depend on the position of the camera, when we only    consider visibility rays (so no shadow rays, for example)? You can assume you're working with an orthographic camera.&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There's two things to consider here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Does any part of the heuristic depend on the position of the camera? Can moving the camera change any of the numbers that feed into the score?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Moving the camera can change how the boxes overlap. Remember that rays that pass through the box need to be tested against the box behind, so needless overlaps make the structure worse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the point is that the heuristic is &lt;em&gt;only&lt;/em&gt; a general rule. It's not hard to construct an example with two proposals &lt;em&gt;a&lt;/em&gt; and &lt;em&gt;b&lt;/em&gt;, where &lt;em&gt;a&lt;/em&gt; scores much better but &lt;em&gt;b&lt;/em&gt; is actually a better split for a particular camera, and this last part of the question is trying to get you to think about this.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-01-29T11:45:02.767" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6185" PostTypeId="2" ParentId="6167" CreationDate="2018-01-30T05:59:28.620" Score="0" Body="&lt;p&gt;I've not done this, but it seems like you could keep a store of a single image and update it with each new image you receive. For example, you capture the first image and project it onto the scene. It likely won't cover the entire scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you capture the next image, assuming it's not from exactly the same place as the previous, you can combine it with the first image by mixing them 50/50. When you get the next image, you want to mix the existing image at 66.666% and the new image at 33.333%, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I think you'd need to keep the combined image, and a second image that is the count of how many images have covered each pixel. Then:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for each pixel in the output that the new projection covers {&#xA;    existing_pixel = current pixel in the existing image&#xA;    num_pixels_mixed = current pixel in the image containing the count of images&#xA;    new_pixel = current pixel in the newly acquired image&#xA;    mix_amount = num_pixels_mixed / (num_pixels_mixed + 1)&#xA;    resulting_pixel = mix_amount * existing_pixel + (1 - mix_amount) * new_pixel&#xA;    increment the current pixel in the image containing the count of images&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-01-30T05:59:28.620" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6186" PostTypeId="1" CreationDate="2018-01-30T07:59:20.310" Score="1" ViewCount="259" Body="&lt;p&gt;I guess most of you are familiar with environment maps, they represent distant lighting distribution, and are used to render objects given their BRDF or SVBRDF distribution. Many papers map the spherical environment maps to 2D representation via a octahedron as described by &lt;a href=&quot;http://hhoppe.com/sphereparam.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Spherical parametrization and remeshing (E Praun - ‎2003)&lt;/a&gt;. Wavelet transform is applied on 2D representation, for the resultant sparsity in representation. Is there a code available for Domain to sphere mapping described in the above paper. If not anyone can help explaining me the implementation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are few doubts I have about the paper. The mapping from Domain to Sphere according to the paper is done the same way Sphere to Mesh parameterization is done, that is (according to what I have understood), the Domain (octahedron) is reduced to a tetrahedron using a progressive mesh favouring triangles with good aspect ratio (described in section 3.5), then progressively they apply vertex split transformation and optimize the vertex positions around the inserted vertex. This doesn't make sense to me because they could directly fit a octahedron to a sphere ( as it is also an regular polygon) rather than reducing to tetrahedron. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another doubt I have is how they calculate the inverse function's Jacobin (mentioned in 3.4). They say that estimate it from the stretch calculated from the planar approximation of circular triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think there aught to be an implementation of this spherical parameterization to 2D in internet because alot of people have used to parameterize environment maps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks :)&lt;/p&gt;&#xA;" OwnerUserId="8115" LastActivityDate="2018-01-30T07:59:20.310" Title="Octahedral mapping for Spherical functions" Tags="&lt;transformations&gt;&lt;mesh&gt;&lt;global-illumination&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6187" PostTypeId="1" CreationDate="2018-01-30T14:53:45.637" Score="1" ViewCount="134" Body="&lt;p&gt;In my class I often need to work with color map images. I would show the image and try to make inferences/observations about different subjects. Often times I need to actually quantify some aspects, but it is always very approximate and somehow vague because the images are provided &quot;as is&quot; and I do not necessarily know their content a priori.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's imagine I'm working with two images (*). Is it possible to indicate the computer &lt;strong&gt;&quot;learn&quot; the color scale&lt;/strong&gt; bar so I can &lt;strong&gt;click at any point&lt;/strong&gt; in the map and get the &lt;strong&gt;value of altitude at that point&lt;/strong&gt;? Image 1 is a discrete color scale bar, while Image 2 has a continuous color mapping. I included both examples because maybe there are differences in the approach of how to do this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is there a software/way to do this? Preferably open source. I tried &lt;code&gt;ImageJ&lt;/code&gt; and couldn't come up with a decent solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Image 1:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ARuLS.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ARuLS.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Image 2:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/fqCAE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fqCAE.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the color scale is part of the image in all cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(*) I do not own any of these images, just examples I found online to illustrate my point.&lt;/p&gt;&#xA;" OwnerUserId="8116" LastEditorUserId="7989" LastEditDate="2018-02-01T10:39:50.340" LastActivityDate="2020-12-19T15:06:24.307" Title="Can I get numeric data from a color map?" Tags="&lt;image-processing&gt;&lt;color&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="6188" PostTypeId="2" ParentId="6187" CreationDate="2018-01-30T16:24:46.963" Score="1" Body="&lt;p&gt;I don't know of any software that could do this for you. However, it should be possible to reverse engineer the colour map to create a kind of look-up table structure. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, take a one pixel wide column (or row) of the colour map and store this as an array of colour values. Then, create a secondary array, for the data/altitude values, of the same length. Try to mark to the best of you ability the marked values of the colour map on this second array. A simple solution would be to also take a pixel wide column (or row) featuring the markings of the colour map to get the exact one-to-one pixel correspondence. Now you have a secondary array containing the marked off values and the rest of the values can be filled in by figuring out the step size of the colour map. The step size would be the difference in absolute value between subsequent markings divided by the number of pixels between these same markings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now when you read a colour from the mapped figure you can look up the colour in the colour array and use the index of this value to look up the altitude in the secondary array.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2018-01-30T16:24:46.963" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6189" PostTypeId="1" AcceptedAnswerId="6192" CreationDate="2018-01-30T18:10:46.643" Score="3" ViewCount="239" Body="&lt;p&gt;I am currently building a pathtracer, which has support for vertex normals and face normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There seems to be an issue when it comes to rendering objects with triangles exported from Blender. Regardless of how I calculate the normal, the result always shows inconsistent shading of triangles. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/53xUF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/53xUF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shading seems to change per triangle, with the ones more aligned to the camera being correct. It seems to depend on where the objects are in the scene relative to the camera. Below is the intersection algorithm for the triangle.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Triangle::intersection(Ray &amp;amp;ray, HitInfo &amp;amp;hit)&#xA;{&#xA;    float3 edge1 = v1-&amp;gt;pos - v0-&amp;gt;pos;&#xA;    float3 edge2 = v2-&amp;gt;pos - v0-&amp;gt;pos;&#xA;&#xA;    float3 h = ray.getDirection().cross(edge2);&#xA;    float a = edge1.dot(h);&#xA;&#xA;    float f = 1.0 / a;&#xA;    float3 s = ray.getOrigin() - v0-&amp;gt;pos;&#xA;    float u = f * (s.dot(h));&#xA;&#xA;    if (u &amp;lt; 0.0 || u &amp;gt; 1.0)&#xA;        return false;&#xA;&#xA;    float3 q = s.cross(edge1);&#xA;    float v = f * ray.getDirection().dot(q);&#xA;    if (v &amp;lt; 0.0 || u + v &amp;gt; 1.0)&#xA;        return false;&#xA;&#xA;    float t = edge2.dot(q) * f;&#xA;    if (t &amp;gt; 1e-9 &amp;amp;&amp;amp; t &amp;lt; ray.tmin)&#xA;    {&#xA;        hit.t = t;&#xA;        float3 temp_normal = unit(edge2.cross(edge1)); //unit(v1-&amp;gt;normal*u + v2-&amp;gt;normal*v + v0-&amp;gt;normal*(1. - u - v));&#xA;        if (unit(ray.getDirection()).dot(temp_normal)&amp;lt; 1e-9) temp_normal = temp_normal * (-1);&#xA;        hit.normal = temp_normal;&#xA;        return true;&#xA;    }&#xA;    else&#xA;    {&#xA;        return false;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The intersection algorithm calculate the normal using the cross product of the edges, however using the normals provided by blender does not change much either.&#xA;I use the Moller Trumbore intersection algorithm, exporting obj's from Blender (enabling &quot;keep vertex order&quot; doesn't change anything). I have also tried different materials but the problem still persists.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cWBqI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cWBqI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PWyxJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PWyxJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above image is the normals being rendered with an emissive shader. This is the result I would expect, so I don't think this is the issue.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 cosineSampleHemi(float u1, float u2)&#xA;{&#xA;    float z = std::pow(1.0 - u1, 3.0 / 5.0);&#xA;    float phi = 2.0 * M_PI * u2;&#xA;    float theta = sqrt(std::max(0.0, 1.0 - z * z));&#xA;    float x = theta * cos(phi);&#xA;    float y = theta * sin(phi);&#xA;&#xA;    return float3(x, y, z);&#xA;}&#xA;&#xA;&#xA;float3 random_in_unit_sphere() {&#xA;    float3 p;&#xA;    do {&#xA;        p = float3(drand48(),drand48(),drand48())*2.0 - float3(1.0);&#xA;    } while (p.dot(p) &amp;gt;= 1.0);&#xA;    return p;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The above code is for the sampling, I have tried both functions and it produces similar results. Below is the lambertian scatter function, which uses the hemisphere sampling methods.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Lambertian::scatter(Ray &amp;amp;ray, HitInfo &amp;amp;hit, float3 &amp;amp;attenuation, Ray &amp;amp;new_ray) const&#xA;{&#xA;    new_ray = Ray(ray.getHit(hit.t), cosineSampleHemi(drand48(), drand48()));&#xA;    attenuation = m_colour;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If any more info is needed I will be happy to supply it, as I am completely stumped at this point.&lt;/p&gt;&#xA;" OwnerUserId="6760" LastEditorUserId="6760" LastEditDate="2018-01-31T16:14:53.457" LastActivityDate="2018-01-31T17:35:15.170" Title="Inconsistent shading in pathtraced image" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;shading&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6190" PostTypeId="2" ParentId="6189" CreationDate="2018-01-30T21:24:42.060" Score="1" Body="&lt;p&gt;Your normal calculation looks backwards: &lt;code&gt;edge2.cross(edge1)&lt;/code&gt;, but (assuming CCW winding) it should be edge1 × edge2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sign flip for back facing normals is also reversed; the ray direction and triangle normal &lt;em&gt;should&lt;/em&gt; be facing in opposite directions, thus should have negative dot product, but it looks like you're flipping it to make the dot product always positive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe there's another differing convention elsewhere in your shading code that accounts for this? In any case, I'm not sure this is actually related to your problem, but it jumped out at me as being odd.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-01-30T21:24:42.060" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6191" PostTypeId="1" CreationDate="2018-01-31T15:24:33.433" Score="0" ViewCount="78" Body="&lt;p&gt;I want to insert a logo into an RGB image with proper 3D transformations. I can get the estimated pixel normals of this image using the code here: &lt;a href=&quot;https://github.com/yindaz/surface_normal&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/yindaz/surface_normal&lt;/a&gt;. Pixel normals are encoded into RGB channels as described as follows:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The estimated normal will be saved in 16-bit PNG format, where 0-65535 in R,G,B channel correspond to [-1, 1] for the X,Y,Z component of the normal vector. We use the camera coordinates defined as - X points to the camera right, Y points to the camera forward, and Z points to the camera upward. For example, right facing wall are very red, floor are very blue, and you rarely see green as it's parallel to the camera viewing direction.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;How can I transform the 2D logo to put it onto a planar surface in the image? I have tried to calculate the rotation angles of the normal to rotate it so that it has the same direction as the camera normal, and rotate the logo according to these angles, but I have no success so far.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I understand from the quote above, normal of the untransformed logo should be $(x:0, y:-1, z:0)$ and let the pixel normal be $(x:a, y:b, z:c)$ with magnitude $M$. I rotate the logo around $X$ by $arccos(a/M)*180/pi$, around $Y$ by $arccos(b/M)*180/pi$, around $Z$ by $arccos(c/M)*180/pi$, and if $b &amp;lt; 0$ rotate around $Y$ by an additional 180 degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there anything reasonable in these? Is it possible that I can do this using the estimated normals?&lt;/p&gt;&#xA;" OwnerUserId="8112" LastEditorUserId="7989" LastEditDate="2018-02-01T10:38:21.460" LastActivityDate="2018-02-01T10:38:21.460" Title="Image warping using pixel normals" Tags="&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6192" PostTypeId="2" ParentId="6189" CreationDate="2018-01-31T17:35:15.170" Score="4" Body="&lt;p&gt;I have managed to fix the error. It turns out the error was never situated in the normal calulation it was the shading algorith. The floating point precision error caused the new ray to be slightly below the surface, which meant it would intersect itself and become darker. This is a problem common in biased raytracers, the phenomenon known as &quot;Shadow acne&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix it I added the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Lambertian::scatter(Ray &amp;amp;ray, HitInfo &amp;amp;hit, float3 &amp;amp;attenuation, Ray &amp;amp;new_ray) const&#xA;{&#xA;    float3 offset = hit.normal*(1e-5);&#xA;    new_ray = Ray(ray.getHit(hit.t) + offset, cosineSampleHemi(drand48(), drand48()));&#xA;    attenuation = m_colour;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the offset variable moves the ray origin to slightly above the surface by a small amount and that seems to fix the issue.&lt;/p&gt;&#xA;" OwnerUserId="6760" LastActivityDate="2018-01-31T17:35:15.170" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6193" PostTypeId="1" CreationDate="2018-01-31T19:54:01.317" Score="1" ViewCount="483" Body="&lt;p&gt;&lt;a href=&quot;https://twitter.com/notch?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor%22@notch%22&quot; rel=&quot;nofollow noreferrer&quot;&gt;@notch&lt;/a&gt; has recently been posting on an engine he is developing. He claims that it is voxel-based and supports deformable terrain, with a render distance of almost 1000 000 voxels and real-time reflections, &lt;a href=&quot;https://twitter.com/notch/status/952333638028398592&quot; rel=&quot;nofollow noreferrer&quot;&gt;running at 99fps in WebGL&lt;/a&gt;. Even with heavy LOD reduction, such a thing sounds too good to be true. He has not published any source code as of now, so does anyone have an idea how this is done? Is it just many small optimizations or could this be a new approach to real time 3D?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: He also mentions a &quot;&lt;a href=&quot;https://twitter.com/notch/status/952104406157332481&quot; rel=&quot;nofollow noreferrer&quot;&gt;signed density field&lt;/a&gt;&quot;. What does that mean exactly?&lt;/p&gt;&#xA;" OwnerUserId="8125" LastEditorUserId="8125" LastEditDate="2018-01-31T20:00:37.600" LastActivityDate="2018-01-31T22:09:05.220" Title="How does notch's new graphics engine work?" Tags="&lt;webgl&gt;&lt;optimisation&gt;&lt;reflection&gt;&lt;compression&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6194" PostTypeId="2" ParentId="6193" CreationDate="2018-01-31T21:43:05.873" Score="2" Body="&lt;p&gt;Notch's engine most likely works using volume raymarching in a volume field. This means that you shoot rays that move a certain distance and check whether they are inside and object or not. Once they are, they return the position of the colission and some other data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can either advance rays by a set amount per step until you hit something or refine the final collision position by doing a binary search along the last walked ray segment once you hit something. Both of these aproaches have the problem that they can overshoot, missing small geometry, or take a large amount of steps to traverse empty space where there is no geometry to hit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Binary search can add precision and reduce overshoots somewhat but comes at an extra runtime cost for doing a binary search per ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Signed distance fields are essentially 3d arrays  tell you how far away from any surface you are. This allows you to do raymarching with ray step sizes equal to that number and being sure that you wont overshoot, as well as stepping through large empty spaces quite quickly. This greatly enhances performance and reduces overshoots from a regular step size or binary search based approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This last technique trades off runtime speed for precompute time and extra memory. So it is not always adequate for rendering exteriors or large scenes. Its memory usage an runtime speed can be further improved by using a hierachical data structure that gets re built every so often with more detail and data density near the camera and less further away from it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: Oh it seems i misread density for distance&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I really have no idea what a signed density field is. I've never heardthe term before. A quick goolge search throws results that talk about signed distance fields. I would guess it was either a mistake to write that, some obscure tech or something that Notch made up himself.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastEditorUserId="5703" LastEditDate="2018-01-31T22:09:05.220" LastActivityDate="2018-01-31T22:09:05.220" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6195" PostTypeId="1" AcceptedAnswerId="6199" CreationDate="2018-02-01T01:15:16.627" Score="5" ViewCount="629" Body="&lt;p&gt;I am trying to understand when it makes sense to use the &lt;code&gt;glDrawRangeElements&lt;/code&gt; function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The OpenGL wiki says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;for optimization purposes, it is useful for implementations to know the range of indexed rendering data&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So, as I interpret it, if I had one large buffer (containing say, multiple meshes' data) and I was planning to call &lt;code&gt;glDrawRangeElements&lt;/code&gt; if I instead specify the minimum and maximum index values that this call will use, I could achieve a speedup.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is this a correct use case for &lt;code&gt;glDrawRangeElements&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like I would almost always know the minimum and maximum index values (because I would know ahead of time what I am going to draw) so it seems like &lt;code&gt;glDrawRangeElements&lt;/code&gt; should be just a drop in replacement for &lt;code&gt;glDrawElements&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, &lt;a href=&quot;https://gamedev.stackexchange.com/a/116838/77716&quot;&gt;this answer&lt;/a&gt; implies that &lt;code&gt;glDrawRangeElements&lt;/code&gt; might actually be slower.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, &lt;strong&gt;what are the pros and cons of using glDrawRangeElements?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2018-02-03T13:57:40.853" Title="When does it make sense to use drawRangeElements" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6196" PostTypeId="2" ParentId="6178" CreationDate="2018-02-01T06:19:35.653" Score="7" Body="&lt;p&gt;You can combine Oren-Nayar with GGX, if your normalize the result. A BRDF is defined by two properties: Helmholtz reciprocity and energy conservation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f(l_i, l,_o) = f(l_o, l_i)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$f(l_i, l_o) \leq 1$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your Oren-Nayar is the diffuse part $f_d(l_i, l_o)$ and your GGX is your specular part $f_s(l_i, l_o)$. If both are energy conserving, then both are at most $1$, but combined they may be $\geq 1$ and here lies your problem. Oren-Nayar has been combined with specular terms before (see for example &lt;a href=&quot;http://www.crytek.com/download/2014_03_25_CRYENGINE_GDC_Schultz.pdf&quot; rel=&quot;noreferrer&quot;&gt;The Rendering of Ryze from Crytek&lt;/a&gt;, you should have a look at how others did it. If you combine them, keep in mind that you need two different roughness values. The ones of Oren-Nayar and GGX don't match (which by the looks of it you know already) but neither can you convert from one to the other via an algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A better solution imo is to use a different diffuse term. Have a look at the papers &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;noreferrer&quot;&gt;Physically Based Shading at Disney by Brent Burley&lt;/a&gt; and &lt;a href=&quot;https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX&quot; rel=&quot;noreferrer&quot;&gt;PBR diffuse Lighting for GGX+Smith Microsurfaces by Earl Hammon Jr.&lt;/a&gt;. Physically Based Shading discusses several diffuse lighting BRDFs, including Oren-Nayar and then goes on to introduce an own diffuse BRDF which can use the same roughness value as GGX (be careful, as the roughness here is squared before using, iirc, because that was easier to use for artists). This resulting BRDF is not energy conserving, which was accepted by the author, since&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;This seems to provide a reasonable match to the MERL data and was also found to be artistically pleasing.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;A solution for this was introduced by &lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;noreferrer&quot;&gt;Sebastien Lagarde and Charles de Rousiers in Moving Frostbite to Physocally Based Rendering&lt;/a&gt;, they renormalized the entire BRDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PBR diffuse Lighting for GGX+Smith Microsurfaces by Earl Hammon takes a different approach, he calculates an approximation like Oren and Nayar did, only he did it for GGX NDF and Smith shadowing/masking. Both the Disney Diffuse and Hammon's Diffuse BRDF can easily be combined with the GGX specular term and are visually more pleasing than Lambert.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2018-02-05T09:12:31.940" LastActivityDate="2018-02-05T09:12:31.940" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="6197" PostTypeId="2" ParentId="6191" CreationDate="2018-02-01T08:23:23.140" Score="-1" Body="&lt;p&gt;Maybe you should try to find Virtual Tangent Plane like in &lt;a href=&quot;https://arxiv.org/abs/1704.02956&quot; rel=&quot;nofollow noreferrer&quot;&gt;Surface Normal In the Wild&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8130" LastActivityDate="2018-02-01T08:23:23.140" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6199" PostTypeId="2" ParentId="6195" CreationDate="2018-02-01T15:34:50.167" Score="6" Body="&lt;p&gt;The problem &lt;code&gt;glDrawRangeElements&lt;/code&gt; was invented to fix was effectively removed by the advent of vertex buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What &lt;code&gt;glDrawRangeElements&lt;/code&gt; allows the implementation to do is to know exactly what range of values will be used as indices for the vertex arrays. Given that knowledge, they can read that range of values into a separate buffer, and then render from that buffer. Without knowing the range of indices, that wouldn't be possible, since an index list could pick from any index.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But that's only useful if you're reading from &lt;em&gt;client memory&lt;/em&gt;. Copying that range out of client memory allows you to render asynchronously. You copy out the values you know you need, issue a rendering command with that, and then return to the caller.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're reading from buffer objects, this isn't a useful thing to do. And since core OpenGL doesn't even allow you the option of using client memory, the &lt;code&gt;Range&lt;/code&gt; commands are no longer useful.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="137" LastEditDate="2018-02-02T13:40:46.433" LastActivityDate="2018-02-02T13:40:46.433" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6200" PostTypeId="1" CreationDate="2018-02-01T16:21:10.300" Score="0" ViewCount="383" Body="&lt;p&gt;I'm working on an engine for Win32 exclusively. Can I safely assume that the flag VK_PRESENT_MODE_FIFO_KHR will always generate 2 and only 2 images for the swapchain? &lt;/p&gt;&#xA;" OwnerUserId="8118" LastActivityDate="2018-02-01T16:43:15.797" Title="Vulkan: Swapchain image count with VK_PRESENT_MODE_FIFO_KHR" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6201" PostTypeId="2" ParentId="6200" CreationDate="2018-02-01T16:43:15.797" Score="1" Body="&lt;p&gt;There is nothing in Vulkan which guarantees or requires this. So even if it were a safe assumption &lt;em&gt;today&lt;/em&gt; (if it were enforced by Windows in some way), all it would take would be one Windows update to break you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's best to work with what you're given, even if what you're given may be more than you would prefer.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-02-01T16:43:15.797" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6203" PostTypeId="2" ParentId="6139" CreationDate="2018-02-02T07:12:44.040" Score="3" Body="&lt;p&gt;Roughly speaking, what the &lt;strong&gt;Supersampling Anti-Aliasing&lt;/strong&gt; method does is:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For each pixel in the image to render&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&quot;Split&quot; the pixel of a target image, usually in 2, 4, 8 or 16.&lt;br&gt;&#xA;Actually this step is more: pick the 2, 4, 8 or 16 locations (&quot;samples&quot;) inside the pixel  &lt;/li&gt;&#xA;&lt;li&gt;Compute the color that the image will have at each of those locations (sample or &quot;split part&quot;).&lt;br&gt;&#xA;So instead of only computing the color that the image will have in that single pixel, we compute 2x, 4x, 8x or 16x times a similar value  &lt;/li&gt;&#xA;&lt;li&gt;Compute the average of all the 2, 4, 8 or 16 sample colors to decide the final color or the initial pixel&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can see that Super-sampling cost is proportional to the cost of computing one pixel's color in the image. Therefore it depends on the cost of shading.&lt;br&gt;&#xA;It also depends on the number of pixels, i.e the resolution of the image.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the context of Ray-Tracing applications, this means that 2, 4, 8 or 16 times more rays will have to be computed.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the context of GPU-accelerated graphics computation, this means that 2, 4, 8 or 16 times more pixel shaders (&quot;fragment programs&quot;) will be executed.  &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Now roughly speaking, what the &lt;strong&gt;Multisampling Anti-Aliasing&lt;/strong&gt; method does is:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For each pixel in the image to render&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Pick 2, 4, 8 or 16 locations (&quot;samples&quot;) inside the pixel     &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For each primitive (triangle) in the scene (actually, only for those that overlap the pixel):  &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Determine which of these samples are covered by the current triangle&lt;/li&gt;&#xA;&lt;li&gt;If there is at least one such sample, compute a single color of the contribution of that triangle to the pixel, and store it for each sample covered&lt;br&gt;&#xA;The worse case happens if each sample is overlapped by a different triangle ;  in that case the color must be computed for each triangle&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Compute the average of all the gathered sample colors to decide the final color or the initial pixel&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can see that evaluating the performance of Multisampling Anti-Aliasing is more complicated than that of Supersampling, since it also depends on the topology of the scene (the size and shape of the triangles).&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="110" LastEditDate="2018-02-02T09:40:46.430" LastActivityDate="2018-02-02T09:40:46.430" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6204" PostTypeId="1" AcceptedAnswerId="6213" CreationDate="2018-02-02T16:31:22.500" Score="5" ViewCount="312" Body="&lt;p&gt;I've implemented a ray tracer that uses kd-trees for acceleration. To help debug kd-tree construction, I also created a crude OpenGL view of the same scene that shows the axis-aligned bounding boxes (AABBs) for each node in the tree (along with the shapes in the scene), and allows the user to highlight a specific node in the tree. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example of a scene with a bunch of spheres, the tree's nodes' AABBs, and one node selected:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/f9Skf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/f9Skf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can clearly see that the AABB for the highlighted node contains a lot of empty space. In general, this is because, during creation, at node split time, the parent's AABB is split into two by an axis-aligned plane at whatever location is found to be optimal, and each child gets one of the two resulting AABBs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I added a step to the splitting procedure that, after the steps above, reduces the size of each child's AABB such that its min/max extents in all axes are reduced to the min/max AABB extents of its shapes. Note that the node's AABB is never expanded, so it's still possible to have shapes partially outside the node's AABB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the same node selected with reduction turned on:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YA8oB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YA8oB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I see a slight improvement in performance, since the probability of an arbitrary ray hitting a given node's AABB is now less, since the AABB is smaller. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, is there any disadvantage to doing this? &lt;/p&gt;&#xA;" OwnerUserId="8140" LastEditorUserId="8140" LastEditDate="2018-02-02T16:41:13.597" LastActivityDate="2018-02-04T13:15:20.610" Title="Reduce kd-tree's nodes' bounding box sizes to their shapes' extents?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6205" PostTypeId="1" AcceptedAnswerId="6208" CreationDate="2018-02-02T16:40:50.003" Score="0" ViewCount="207" Body="&lt;p&gt;Firstly, I would like to tell this is my first question on stackexchange and I am a senior school student. Please bear with me, if I am not able to express myself clearly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to solve a question based on euler's formula: V - E + F = 2 (1 - G)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been given a closed mesh of a sphere. Number of Edges and Faces and number of Vertices with valence 4 are given.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/BEW7L.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BEW7L.png&quot; alt=&quot;Valence with Vertices and Faces&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I have to compute V, x_1, x_2 and x_3. The vertices for valence 4 are some how not printed in my book and I assume them to be 137 (274/2) relating to table on the right. I know F = 2 V, but 275 = 2V gives a decimal point number which is not possible !&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pardon for my brevity and correct me if I am not clear :)&lt;/p&gt;&#xA;" OwnerUserId="8141" LastActivityDate="2018-02-02T23:20:08.703" Title="Topology: Polygonal Meshes, Euler's Formula" Tags="&lt;mesh&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6206" PostTypeId="2" ParentId="4952" CreationDate="2018-02-02T21:27:29.960" Score="1" Body="&lt;p&gt;I would say 'no' to the question about normal mapping, it probably isn't worth it. Geological &quot;texture&quot; from local surface orientation seems to have a very minor effect on the appearance of the earth from space. Getting the atmospheric scattering and variations in diffuse albedo (diffuse / specular maps) correct is probably 100x more important. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The analogy to the apple made by another user, while may be correct, is less relevant than it seems,  since the apple's surface is very shiny and has no atmosphere. &lt;/p&gt;&#xA;" OwnerUserId="3386" LastActivityDate="2018-02-02T21:27:29.960" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6208" PostTypeId="2" ParentId="6205" CreationDate="2018-02-02T23:07:07.800" Score="0" Body="&lt;p&gt;Let &lt;code&gt;g&lt;/code&gt; be the number of vertices of valence 4. A closed sphere has &lt;code&gt;G=0&lt;/code&gt; and we have the equation &lt;code&gt;V-E+F=2&lt;/code&gt;. Now &lt;code&gt;V=x1+g+x2&lt;/code&gt; and &lt;code&gt;F=275&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a first step let us count the edges. If we multiply each face by its valence and sum those up, we get &lt;em&gt;twice&lt;/em&gt; the number of edges (as each edge is shared by two faces), so:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(1)   2*E = (274*4 + x3*1)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Immediately we can see that &lt;code&gt;2&lt;/code&gt; divides &lt;code&gt;x3&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly if we multiply each vertex with its valence we get again &lt;em&gt;twice&lt;/em&gt; the number of edges, as each edge is shared by two vertices, so:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(2)   2*E = 3*x1 + 4*g + 5*x2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And again we see that &lt;code&gt;x1&lt;/code&gt; and &lt;code&gt;x2&lt;/code&gt; must have the same parity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Plugging the first of this equation (with the very first ones) into &lt;code&gt;V-E+F=2&lt;/code&gt; we get&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(3)   2 = V-E+F = x1 + g + x2 - (1096+x3)/2 + 275 = x1 + x2 - x3/2 + g + 548&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Equating the two equations we derived above we get &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(4)   1096 + x3 = 3*x1 + 4*g + 5*x2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now the system of equations &lt;code&gt;(3)&amp;amp;(4)&lt;/code&gt; has all the information encoded (excluding the parity information), so it appears you don't already have everything you need to know to determine these four unknowns.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I made a small Haskell program that does some bruteforcing with these conditions: &lt;a href=&quot;https://tio.run/##dZDLCoMwEEX3@YpZdOEjsZrUQqHd9BdciqDUV9BG8VGy6L/biSspOhAYZs69E26djU3RtsvCGGhx5gAP0AG4oLF1ocIXhj7BbeDfrmYukBDOylycde9oTua@L4aoGLJX/exmlSMU@FikxC62dEA1p1rQyoav8biz2Kfc8/51CQUCO4X3jMTzLC3SXH5SbjP82BFeHdD73hzhDWmOMePB4Fi0iWMnj4QQFXXtPMlOjSYL8s6kwqYfpJrgBFPWFLBBoFyWHw&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Haskell – Try It Online&quot;&gt;Try it online!&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first solution it does get is &lt;code&gt;(0,732,2564,0) = (x1,x2,x3,g)&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="1981" LastEditorUserId="1981" LastEditDate="2018-02-02T23:20:08.703" LastActivityDate="2018-02-02T23:20:08.703" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6209" PostTypeId="1" AcceptedAnswerId="6212" CreationDate="2018-02-03T11:47:25.550" Score="-1" ViewCount="224" Body="&lt;p&gt;After binding the data to the vertex buffer object as follows, how to modify the buffer data?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Each subdata size is 3$*$ data size (three elements per index) &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 vertex;&#xA;vertex.push_back(glm::vec3(0.0f, 0.0f, 0.0f));&#xA;vertex.push_back(glm::vec3(0.0f, 0.0f, 1.0f));&#xA;vertex.push_back(glm::vec3(1.0f, 0.0f, 0.0f));&#xA;&#xA;glm::vec3 color;&#xA;color.push_back(glm::vec3(1.0f, 0.0f, 0.0f));&#xA;color.push_back(glm::vec3(0.0f, 1.0f, 0.0f));&#xA;color.push_back(glm::vec3(0.0f, 0.0f, 1.0f));&#xA;&#xA;glBufferData(GL_ATTRAY_BUFFER, vertex_data_size+color_data_size, NULL, GL_DYNAMIC_DRAW);&#xA;glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_data_size, data);&#xA;glBufferSubData(GL_ARRAY_BUFFER, vertex_data_size, color_data_size, data);&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;glEnableVertexAttribArray(1);&#xA;glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, (void*)vertex_data_size);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In detail, supposing I want to change the second vertex element to (1.0f, 1.0f, 1.0f). I know it with compute shader, but I just wnat to know how to do it without compute shader or OpenCl.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to change the buffer data uploaed directly without uploading the whole data again? &lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2018-02-03T15:47:10.620" Title="How to modify a part of VBO data without Compute Shader or OpenCL?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6211" PostTypeId="2" ParentId="6195" CreationDate="2018-02-03T13:57:40.853" Score="0" Body="&lt;p&gt;From the OpenGL 4.5 spec, &lt;code&gt;glDrawRangeElements&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Implementations denote &lt;strong&gt;recommended maximum&lt;/strong&gt; amounts of vertex and index&#xA;  data, which may be queried by calling GetIntegerv with pnames&#xA;  &lt;strong&gt;MAX_ELEMENTS_VERTICES&lt;/strong&gt; and &lt;strong&gt;MAX_ELEMENTS_INDICES&lt;/strong&gt;. &lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;If end − start + 1 is greater than the value of MAX_ELEMENTS_VERTICES,&#xA;  or if count is greater than the value of MAX_ELEMENTS_INDICES, &lt;strong&gt;then&#xA;  the call may operate at reduced performance&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;My interpretation of this is &lt;code&gt;glDrawElements&lt;/code&gt; &lt;strong&gt;may&lt;/strong&gt; perform worse than &lt;code&gt;glDrawRangeElements&lt;/code&gt; if the index count or implicit range exceed that of the implementation dependent GL_MAX_ELEMENTS_{INDICES|VERTICES}. For platforms where &lt;code&gt;glDrawElements&lt;/code&gt; is always superior I would expect &lt;code&gt;glDrawRangeElements&lt;/code&gt; to ignore &lt;code&gt;start&lt;/code&gt; and &lt;code&gt;end&lt;/code&gt; all together, and the value of GL_MAX_ELEMENTS_{INDICES|VERTICES} to be &quot;infinite&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Correct usage according to spec is therefore whenever &lt;code&gt;glDrawElements&lt;/code&gt; exceeds GL_MAX_ELEMENTS_{INDICES|VERTICES} and &lt;code&gt;glDrawRangeElements&lt;/code&gt; does not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For reference, on my GTX 970 the value is 1048576 for both.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2018-02-03T13:57:40.853" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6212" PostTypeId="2" ParentId="6209" CreationDate="2018-02-03T15:47:10.620" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it possible to change the buffer data uploaed directly without uploading the whole data again?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&quot;Again&quot;? You didn't upload &quot;the whole data&quot; the &lt;em&gt;first time&lt;/em&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_data_size, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That only affects the first &lt;code&gt;vertex_data_size&lt;/code&gt; bytes of the buffer. And your second one only affects the data on the byte range [vertex_data_size, color_data_size + vertex_data_size).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's no limit on how many bytes you can modify with a &lt;code&gt;glBufferSubData&lt;/code&gt; call. Or more to the point, there's no limit on how &lt;em&gt;few&lt;/em&gt; bytes you can modify. If you want to upload 12 bytes worth of data, you can.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, you &lt;em&gt;shouldn't&lt;/em&gt;. You should avoid making lots of small uploads of data like that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have access to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object#Persistent_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;persistent mapping&lt;/a&gt;, it would be better to persistently map the buffer and simply modify the location(s) at the appropriate time (using &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object_Streaming#Persistent_mapped_streaming&quot; rel=&quot;nofollow noreferrer&quot;&gt;proper synchronization and multiple buffering&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-02-03T15:47:10.620" CommentCount="7" ContentLicense="CC BY-SA 3.0" />
  <row Id="6213" PostTypeId="2" ParentId="6204" CreationDate="2018-02-03T16:02:25.753" Score="2" Body="&lt;p&gt;No disadvantage that I can see but what you have is not a kd-tree if you have axis-aligned bounding boxes in every node.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A kd-tree only has a splitting plane in every node, so there is no AABB to shrink. The way to deal with empty space in them is to split the node further into an empty node and a smaller node with the same objects as its parent, when justified by whatever heuristic is used. It is just one more possible split to consider when picking how to split a node.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-02-03T16:02:25.753" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6214" PostTypeId="1" AcceptedAnswerId="6215" CreationDate="2018-02-04T11:46:06.893" Score="0" ViewCount="491" Body="&lt;p&gt;One of the hardest things for me with the modern closer to the metal graphics APIs is understanding synchronization. I usually try to simplify things in order to understand the concept better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Directx12, we can use a set of &quot;x&quot; fences (x being the number of back buffers) to allow the CPU to work ahead of the GPU. This could be the code we use to wait for a previous fence (&lt;a href=&quot;https://www.braynzarsoft.net&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.braynzarsoft.net&lt;/a&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (fence[frameIndex]-&amp;gt;GetCompletedValue() &amp;lt; fenceValue[frameIndex])&#xA;{&#xA;    hr = fence[frameIndex]-&amp;gt;SetEventOnCompletion(fenceValue[frameIndex], fenceEvent);&#xA;    if (FAILED(hr))&#xA;    {&#xA;        Running = false;&#xA;    }&#xA;    WaitForSingleObject(fenceEvent, INFINITE);&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there a reason why we can´t just:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;while(fence[frameIndex]-&amp;gt;GetCompletedValue() &amp;lt; fenceValue[frameIndex])&#xA;{&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7107" LastActivityDate="2018-02-05T11:43:05.400" Title="Do we really need a fence event?" Tags="&lt;directx12&gt;&lt;synchronization&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6215" PostTypeId="2" ParentId="6214" CreationDate="2018-02-05T09:37:04.103" Score="4" Body="&lt;p&gt;In your first example, the call to &lt;code&gt;WaitForSingleObject&lt;/code&gt; &lt;em&gt;blocks&lt;/em&gt; the thread. This puts it into a waiting state, which takes it off the run queue and allows other threads to run on this CPU core. If no threads can run, the CPU will idle. When the &lt;code&gt;fenceEvent&lt;/code&gt; completes, it wakes up this thread.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your proposed replacement is called a &lt;em&gt;spinlock&lt;/em&gt;. The thread keeps running, using 100% of a core until the fence's completed flag changes. No other code can run on this core, so there's no interleaving of CPU and GPU work. Worse yet, this code has to read from memory to check the flag every time around the loop, so it'll slow down any threads on other cores that are also accessing memory. Finally, because it's keeping the core and the memory bus active, it'll burn more power and generate more heat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why fence events are needed: to enable the CPU to wait efficiently.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="7107" LastEditDate="2018-02-05T11:43:05.400" LastActivityDate="2018-02-05T11:43:05.400" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6217" PostTypeId="1" AcceptedAnswerId="6230" CreationDate="2018-02-05T21:39:58.190" Score="-5" ViewCount="126" Body="&lt;p&gt;&quot;How does the Shadow of The Colossus™ engine perform its seamless long distance rendering?&quot;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/PIa8J.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PIa8J.jpg&quot; alt=&quot;SS from http://www.businessinsider.com/shadow-of-the-colossus-remake-playstation-4-video-2017-9&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8150" LastActivityDate="2018-02-06T23:56:58.570" Title="&quot;How does the Shadow of The Colossus's™ proprietary (Sony's) engine perform its seamless long distance rendering?&quot;" Tags="&lt;rendering&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6218" PostTypeId="1" CreationDate="2018-02-06T06:17:28.353" Score="2" ViewCount="130" Body="&lt;p&gt;Why is there necessarily a hierarchy in Euler rotations?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example I need to decide that I want&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x to affect y and z&#xA;z to affect y&#xA;y to affect nothing.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What if I wanted to have something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x to affect y and z&#xA;z to affect x and y&#xA;y to affect nothing&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(x, y and z refer to rotations about x, y and z)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand for a physical gimbal there is a restriction, but that need not be necessary for a computer graphics system, right?&lt;/p&gt;&#xA;" OwnerUserId="8152" LastActivityDate="2018-07-12T13:44:06.660" Title="Heirarchy in Euler rotations" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6219" PostTypeId="1" CreationDate="2018-02-06T07:23:22.657" Score="-3" ViewCount="87" Body="&lt;p&gt;When a cell phone is used to take a photo or capture video the display continuously displays what a camera can see, does that mean the ccd/cmos device is exposed to light continuously? or is it displayed by some other means(with out involving ccd/cmos)? Is the difference between displaying and capturing a video(or photo) is only storage? Is cellphone continuously taking pictures for displaying, even if you don't take a picture?&lt;/p&gt;&#xA;" OwnerUserId="8153" LastActivityDate="2018-02-06T20:27:00.793" Title="How does cell phone display image or video even before you start to capture?" Tags="&lt;rendering&gt;&lt;camera&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6221" PostTypeId="1" AcceptedAnswerId="6226" CreationDate="2018-02-06T10:55:21.930" Score="2" ViewCount="112" Body="&lt;p&gt;I'm sorry I'm bringing this topic up again, but I need to expound some of the topics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With reference to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/6099/paper-for-the-approximation-formula-provided-by-brian-karis&quot;&gt;this question&lt;/a&gt;, I was wondering if someone can help me out in expanding some of the details.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the answer to that question we have:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;However, since $L_i(l_k)$ is usually not a constant, this integral is&#xA;  not separable. Yet, in some cases (like when dealing with diffuse&#xA;  lighting or, more specifically, diffuse ambient lighting), the&#xA;  information that $f(l_k,v)$ carries is low-frequency enough that it&#xA;  can reasonably be approximated as a constant with respect to the&#xA;  distribution of $L_i(l_k)$. Experimentally, it can be shown that the&#xA;  final result is not too different from what you would expect.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm not sure I understand the specific bit &quot;the information that $f(l_k,v)$ carries is low-frequency enough&quot; and also the bit &quot;with repsect to the distribution of $L_i(l_k)$&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been reading something about radiometry lately. The only clue I have is that since $f(l_k,v)$ is also function of the wavelength, which is inverse w.r.t. the frequency. Therefore low frequency means high wavelength, which in turn translates some specific assumption about the colour of both incoming and reflected light I guess. Experimental results are also mentioned and I'd like to find out those if they've been published.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is my reasoning correct? If yes, I still have the feeling I'm missing something. If not what am I missing yet? Experimental results are also mentioned, can you point out any paper so I can read about those?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="228" LastEditDate="2018-02-06T11:04:09.427" LastActivityDate="2018-02-06T17:11:12.747" Title="Why is the approximation valid, in the formula provided by Brian Karis?" Tags="&lt;mathematics&gt;&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6222" PostTypeId="2" ParentId="6219" CreationDate="2018-02-06T11:40:01.293" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;does that mean the ccd/cmos device is exposed to light continuously?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Unless there is a physical shutter it will be continuously exposed to light.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is the difference between displaying and capturing a video(or photo) is only storage?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;yes. &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is cellphone continuously taking pictures for displaying, even if you don't take a picture?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If the data from the capture chip is not collected then it is lost. The phone will only capture the data when it needs to (either for displaying or storing). It can also cut power to the sensor to save battery.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-02-06T11:40:01.293" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6223" PostTypeId="2" ParentId="6218" CreationDate="2018-02-06T14:39:09.160" Score="1" Body="&lt;p&gt;Euler rotations work around the axes. This is represented in 3 angles (rot_x, rot_y, rot_z). The order of the rotation needs to be determined as the order affects the result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if we have a point (1, 0, 0) and we rotate 90 degrees around the Y and then 90 degrees around the Z, then the result will be&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;v1 = (1,0,0)&#xA;v2 = rotate_y(v1, 90) # v2 = (0,0,1)&#xA;v3 = rotate_z(c2, 90) # v3 = (0,0,1)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When doing the other order first Z and then Y, the result is different:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;v1 = (1,0,0)&#xA;v2 = rotate_z(v1, 90) # v2 = (0,1,0)&#xA;v3 = rotate_y(c2, 90) # v3 = (0,1,0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In computer graphics systems, quaternion rotations are often used, which allows rotation around any axis. This then solves many of the problems with Euler systems.&lt;/p&gt;&#xA;" OwnerUserId="8060" LastEditorUserId="209" LastEditDate="2018-07-12T13:44:06.660" LastActivityDate="2018-07-12T13:44:06.660" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="6224" PostTypeId="2" ParentId="6221" CreationDate="2018-02-06T15:32:53.880" Score="0" Body="&lt;p&gt;In computer graphics, one rarely uses the term &quot;frequency&quot; to refer to the inverse of wavelength of light. Usually, the meaning from &lt;strong&gt;signal theory&lt;/strong&gt; is implied instead, i.e. the frequency of signal, or &lt;strong&gt;detail&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Low-frequency information&quot; in this case means that diffuse lighting is usually &quot;blurry,&quot; i.e. it does not carry high-resolution detail, and is approximately the same, or has a smooth gradient, over relatively large regions of space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To put it simply, &quot;low frequency with respect to the distribution of $ L_i(l_k) $&quot; intuitively means &quot;the incoming light signal has low detail&quot;.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2018-02-06T15:32:53.880" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6225" PostTypeId="1" CreationDate="2018-02-06T16:49:13.887" Score="0" ViewCount="69" Body="&lt;p&gt;Suppose I have parallel lines running along the ground (into the horizon). If I have a camera and I know its tilt angle, is there a way to calculate the slopes of the lines as projected to the 2D image plane? That is, the green angles:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SQyPf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SQyPf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the distance from the lines are not known. What parameters of the camera are used in the calculation?&lt;/p&gt;&#xA;" OwnerUserId="8158" LastEditorUserId="8158" LastEditDate="2018-02-06T17:00:30.867" LastActivityDate="2018-04-07T20:49:31.890" Title="Determining slopes of lines in perspective projection" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6226" PostTypeId="2" ParentId="6221" CreationDate="2018-02-06T17:11:12.747" Score="3" Body="&lt;p&gt;&quot;the information that $f(l_k,v)$ carries is low-frequency enough&quot;: As IneQuation explains, low-frequency was used to refer to the detail of the brdf function. I did actually mean that $f_r$ was low frequency though (which is the case with diffuse lighting), not $L_i$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;with respect to $L_i$&quot;: what this means it that, since there aren't any large peaks in $f_r$, no part of $L_i$ will be wheighted much more heavily than any other in the integral.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If each function was, say, reciprocal of the other (meaning in this case that the peaks in each one would cancel out when multiplied by the other) the correct integral would be very different to the separated integral where this cancelation does not occurr. but since the two functions are not correlated (or they shouldn't be) this difference is likely to be fairly small.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, if you use a really high frequency BRDF that takes into acount only incident light around the normal and you separate it, you will get something that's way off. in this example the estimate using separation is 4x larger that the correct result: &lt;a href=&quot;https://www.desmos.com/calculator/c4zgypthrc&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.desmos.com/calculator/c4zgypthrc&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Experimental results can be generated easily. here is an example: &lt;a href=&quot;https://www.desmos.com/calculator/poyswojjsa&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.desmos.com/calculator/poyswojjsa&lt;/a&gt; it shows a low frequency brdf $f_r$ and a high frequency incident light $L_i$ function being multiplied before and after integration. the ratio between the correct result and the one obtained using separation is of about 1.6&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Addendum regarding your latest comment on my other answer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\frac{1}{N}\sum^{N}_{k=1}f(L_k) = \sum^{N}_{k=1}(f(L_k)\cdot \frac{1}{N})$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here we have &quot;moved&quot; or distributed $\frac{1}{N}$ into the sum. This formulation is equivalent but looks a bit more similar to an integral. if we set $\Delta L = \frac{1}{N}$ then, we can get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\sum^{N}_{k=1}f(L_k)\Delta L\approx \int_{L}f(L)dL$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;keeping in mind that the separation that occurs is, conceptually, separation of integrals, and that every integral &quot;needs&quot; its own $dL$. it follows that every montecarlo estimator needs its own $1/N$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps you understand where the extra$\frac{1}{N}$ comes from&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-06T17:11:12.747" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="6227" PostTypeId="2" ParentId="6225" CreationDate="2018-02-06T19:31:00.137" Score="1" Body="&lt;p&gt;You definitely need to know distances and angle of view of the camera.  For example, if you add lines that are slightly further apart, they will be at different angles.  Like a multi-lane highway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AjNpc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AjNpc.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8009" LastActivityDate="2018-02-06T19:31:00.137" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6228" PostTypeId="2" ParentId="6219" CreationDate="2018-02-06T20:27:00.793" Score="1" Body="&lt;p&gt;The answer is: it depends.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the preview is active in your camera app, the camera is always taking pictures so that it can provide a live preview image.  The CCD is constantly binning and resetting charge accumulated from photons hitting it.  The phone is also processing the captured image and displaying it - all this requires battery power.  So if the live preview is not active then it will likely not be taking pictures to save on battery.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, some phones have a smart sensor where you can unlock it with your face.  It might be taking pictures of your face even though it is not showing you a preview.  Some phones also have a mode where it takes pictures of you to see if you are looking at the screen.  This takes more battery power to leave engaged but it also will not show you a live preview so it saves some processing power there.  It all depends on the mode the camera is in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your phone will also continually adjust other settings though such as sensitivity, exposure time, and focus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a dark environment, the &quot;preview&quot; image that is displayed during live capture will be taken with high sensitivity (high ISO) with a short exposure time.  But when you take a photo, it might switch to a lower sensitivity (low ISO) and use a longer exposure time, which should produce a higher quality image -- provided you can hold the phone still for the entire exposure time.  Some phones will provide &quot;modes&quot; like sports mode or night mode, that will prefer either a short exposure time (to prevent blur - as in sports mode) or a higher quality image (as in night mode).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, in a dark environment in video mode, before you hit record as it displays a live preview, it might use a higher sensitivity and longer exposure time (but effectively lower frame rate - like maybe only 5-10 fps) but then when you hit record, in order to maintain 60fps it could only take pictures with an exposure no more than 16ms, which might make the video appear darker than the live preview was showing, but motion will be smooth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, when you use a flash, the phone goes through a variety of different settings, switching between live preview, and flash on/off for focus and exposure estimation vs the conditions under which the final exposure are taken.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a lot of tweaking that goes into creating a good camera application.  And the front and back facing cameras can work in concert to provide other features beyond the camera application - and may be active even when not providing a preview image - depending on the application.&lt;/p&gt;&#xA;" OwnerUserId="8009" LastActivityDate="2018-02-06T20:27:00.793" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6229" PostTypeId="1" AcceptedAnswerId="6235" CreationDate="2018-02-06T22:24:04.317" Score="4" ViewCount="406" Body="&lt;p&gt;The three most popular shadowing techniques for real time applications are:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Shadow maps&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Advantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Fast&lt;/li&gt;&#xA;&lt;li&gt;&quot;Simple&quot;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Disadvantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Numerical limitations lead to artifacts and jaggy shadows &lt;/li&gt;&#xA;&lt;li&gt;You only get the information of the first object hit by the light, not the last (important for more photorealistic effects)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Volume shadows&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Advantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Almost no numerical instability&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Hardware built-in support through stenciling&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Disadvantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Slower than shadow maps&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Finding the last object that the light hits isn't easy&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Volumetric rendering&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Advantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Analytic precision &lt;/li&gt;&#xA;&lt;li&gt;Allows for great photorealistic shadows&lt;/li&gt;&#xA;&lt;li&gt;Finding the last object hit by the light is trivial&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Disadvantages:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;SLOW, VERY SLOW&lt;/li&gt;&#xA;&lt;li&gt;Has an awful asymptotic running time for ray intersection calculations (linear in the number of primitives without hashing)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Are there any new experimental shadowing techniques that can improve on the advantages of any of these while eliminating some of the disadvantages?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="209" LastEditDate="2018-02-08T15:56:51.393" LastActivityDate="2018-02-08T15:56:51.393" Title="Experimental real-time shadowing techniques?" Tags="&lt;lighting&gt;&lt;shadow&gt;&lt;volumetric&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6230" PostTypeId="2" ParentId="6217" CreationDate="2018-02-06T23:56:58.570" Score="2" Body="&lt;p&gt;Taken from &lt;a href=&quot;http://www.froyok.fr/documents/making_of_sotc.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Making Of &amp;quot;Shadow Of The Colossus&amp;quot;:&#xA;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The rough algorithm is outlined below:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Rendering the distant view, and save it.&lt;/li&gt;&#xA;&lt;li&gt;Foreground rendering.&lt;/li&gt;&#xA;&lt;li&gt;Composite the distant view and foreground together. It uses the contents of the Z-buffer like a mask pattern (see image 2).&lt;/li&gt;&#xA;&lt;li&gt;Again using the Z-buffer, generate a separate image of the mask pattern.&lt;/li&gt;&#xA;&lt;li&gt;Reduce this to 64x64 pixels, using a bilinear filter. (This makes it ultra-low resolution.) This gets reused in step (8).&lt;/li&gt;&#xA;&lt;li&gt;Blend in the previous frame (from step 7) using a percentage specified in the scene box.&lt;/li&gt;&#xA;&lt;li&gt;Store the image for use in step (6). It is used for drawing the next frame.&lt;/li&gt;&#xA;&lt;li&gt;Expand step (5) to a suitable resolution, using the bilinear filter. Thus, it becomes the material for the bloom effect where the&#xA;distant view starts bleeding out from the shape of the foreground.&lt;/li&gt;&#xA;&lt;li&gt;Blend (7) and (8) using a ratio specified in the scene box.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ePJ61.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ePJ61.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Landscape rendering is divided into 3 stages, the furthest background&#xA;being either a rendered image or a texture, which is stuck on a&#xA;distant polygon. The internal development team nicknamed this &amp;quot;Super&#xA;Low&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;Consequently, most of the medium range which goes from nearby to&#xA;just past the furthest background, is rendered using a low-resolution&#xA;landscape. This is managed in units of 600x600m, and as the player&#xA;approaches it, once he gets nearer than a certain fixed distance, it&#xA;changes to the high-res landscape model for the foreground. This&#xA;switch is designed to blend well so it not obvious.&lt;/p&gt;&#xA;&lt;p&gt;In addition before&#xA;being combined down into one picture for the Super Low, most of the&#xA;distant scenery being managed in 600x600m chunks has been reduced to&#xA;around 1/30th - 1/100th of the polygons. Because there is little&#xA;memory, we usually try and spread it around the landmark which&#xA;represents that area. The combined image for the most distance scenery&#xA;is done using this low-res model. With this, the low-resolution model&#xA;appears seamlessly out of the Super Low image. By connecting the&#xA;foreground and distant background well, we are able to produce a&#xA;landscape rendering system which seems very natural.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/UTSjG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UTSjG.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="5349" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-02-06T23:56:58.570" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6231" PostTypeId="1" CreationDate="2018-02-07T12:27:13.780" Score="1" ViewCount="108" Body="&lt;p&gt;In relation to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/6221/why-is-the-approximation-valid-in-the-formula-provided-by-brian-karis?noredirect=1#comment9519_6221&quot;&gt;this question&lt;/a&gt;, in the accepted answer I have a trivial question probably.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;W.r.t. the following integral&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;L_o(x\rightarrow \Theta) = \int_{\Omega_x} f_r(x,\Psi\rightarrow\Theta)L_i(x\leftarrow \Psi) cos(N_x,\Psi)d\omega_{\Psi}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;in the accepted answer, one of the comments it is stated that $f_r(l,v) = f_r(x,\Psi\rightarrow\Theta)$ and $L_i(l) = L(x\leftarrow \Psi)$ are not correlated. As usual... I wanna understand why... My reference on this subject is &lt;a href=&quot;https://books.google.co.uk/books?id=TB1jDAAAQBAJ&amp;amp;printsec=frontcover&amp;amp;dq=advanced%20global%20illumination&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0ahUKEwighpjR5JPZAhWJLMAKHbOZC4oQ6AEIKTAA#v=onepage&amp;amp;q=advanced%20global%20illumination&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;this book&lt;/a&gt;. In such book the brdf $f_r(l,v)$ is &lt;strong&gt;&lt;em&gt;defined&lt;/em&gt;&lt;/strong&gt; as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;f_r(x,\Psi \rightarrow \Theta) = \frac{dL(x \rightarrow \Theta)}{dE(x \leftarrow \Psi)} = \frac{dL(x \rightarrow \Theta)}{L(x\leftarrow\Psi)cos(N_x,\Psi) d\omega_\Psi},&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the last equation I can see that the two are actually related, unless there's something I'm missing. Why are they not correlated?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A note about the notation used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L(x\rightarrow\Theta)$ : this is the radiance from $x$ toward direction $\Theta$&#xA;$f_r(x,\Psi\rightarrow\Theta)$ is the BRDF coming from direction $\Psi$ in $x$ and exiting in direction $\Theta$&#xA;$L(x\leftarrow\Psi)$ : radiance from direction $\Psi$ toward $x$&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="228" LastEditDate="2018-02-09T13:56:47.887" LastActivityDate="2018-02-09T13:56:47.887" Title="Why are BRDF and the lighting uncorrelated?" Tags="&lt;mathematics&gt;&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6232" PostTypeId="1" AcceptedAnswerId="6234" CreationDate="2018-02-07T13:24:08.980" Score="4" ViewCount="331" Body="&lt;p&gt;I'm trying to implement &lt;a href=&quot;http://casual-effects.blogspot.com.tr/2015/03/implemented-weighted-blended-order.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Weighted, Blended Order-Independent Transparency&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are three passes:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;3D opaque surfaces to a primary framebuffer&lt;/li&gt;&#xA;&lt;li&gt;3D transparency accumulation to an off-screen framebuffer&lt;/li&gt;&#xA;&lt;li&gt;2D compositing transparency over the primary framebuffer&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I need to test transparent objects against default depth buffer. I created a framebuff for transparency pass and also created a depth buffer for maybe I can copy default depth to this buffer if this is the only way. But I don't know how to do that because I created depth buffer with &lt;code&gt;GL_DEPTH_COMPONENT24&lt;/code&gt; but I don't know default depth format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to bind default framebuffer's depth buffer to another framebuffer? If not, how can I copy default depth to another depth buff, or what is best way to do this?&lt;/p&gt;&#xA;" OwnerUserId="6929" LastActivityDate="2018-02-07T17:47:30.067" Title="using default depth buffer in off-screen framebuffer" Tags="&lt;opengl&gt;&lt;transparency&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6233" PostTypeId="1" AcceptedAnswerId="6247" CreationDate="2018-02-07T14:39:55.343" Score="3" ViewCount="979" Body="&lt;p&gt;Already asked this question on mathexchange but didn't got any promising answers so posting it here Since I'm from a CG background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I really can't understand how and why gimbal lock occurs using euler angles.&#xA;First of all let me clear this &quot;&lt;strong&gt;&lt;em&gt;I know that gimbal lock occurs when 2 gimbals/axes coincide thus losing 1 degree of freedom&lt;/em&gt;&lt;/strong&gt;&quot; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However what I'm interested in why the axes are coinciding in the first place when they are supposed to remain perpendicular when we move anyone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to wikipedia &lt;a href=&quot;https://en.wikipedia.org/wiki/Davenport_chained_rotations&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; :&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The general problem of decomposing a rotation into three composed&#xA;  movements about intrinsic axes was studied by P. Davenport, under the&#xA;  name &quot;generalized Euler angles&quot;, but later these angles were named&#xA;  &quot;Davenport angles&quot; by M. Shuster and L. Markley.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Davenport proved that any orientation can be achieved by composing&#xA;  three elemental rotations using &lt;strong&gt;&lt;em&gt;non-orthogonal axes&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That's what I want to hear about more. Why &quot;non-orthogonal&quot; ? I can't see any problems with making the axes orthogonal? What does making the axes non-orthogonal give us?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) After the above one has been answered. How is this all tied up to rotational matrices? How can we achieve gimbal lock through the matrices when they only rotate a given point/vector around global axis. For example If i multiply a column vector with a Rotation matrix around X-axis &lt;code&gt;Rx&lt;/code&gt;  and then with &lt;code&gt;Ry&lt;/code&gt; It will rotate around the global X-axis first, then global Y-axis second. So how can I achieve the lock situation using matrices?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- &#xA;To make it more clear I've also heard about rotation orders like in the order &lt;code&gt;Y-Z-X&lt;/code&gt; when Y axis rotates then &lt;code&gt;Z&lt;/code&gt; and &lt;code&gt;X&lt;/code&gt; rotate with it but when &lt;code&gt;Z&lt;/code&gt; rotates only &lt;code&gt;X&lt;/code&gt; rotates with it. thus making the axes non-orthogonal. I am assuming that's what it means by non-orthogonal mentioned in the wiki article. Here is a picture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FejAW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FejAW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see in the Y-Z-X order, the Y axis remains there as in 3rd picture causing the axes to coincide...&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2021-04-11T16:20:37.697" Title="Euler Angles - Gimbal lock, why non-orthogonal axes" Tags="&lt;geometry&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6234" PostTypeId="2" ParentId="6232" CreationDate="2018-02-07T17:47:30.067" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it possible to bind default framebuffer's depth buffer to another framebuffer?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;First, you &quot;attach&quot; images to framebuffers. You &quot;bind&quot; objects to the context; you &quot;attach&quot; objects to other objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, no, you cannot attach images of the default framebuffer to anything.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If not, how can I copy default depth to another depth buff, or what is best way to do this?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You render to your own depth buffer entirely. Just copy/render the image data out to the default framebuffer when its time to display it.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-02-07T17:47:30.067" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6235" PostTypeId="2" ParentId="6229" CreationDate="2018-02-07T21:03:26.543" Score="7" Body="&lt;p&gt;There’s an interesting technique that’s been used in demoscene and Shadertoy projects for a while, and an analogue of which recently made it into Unreal Engine 4: using &lt;a href=&quot;https://en.wikipedia.org/wiki/Signed_distance_function&quot; rel=&quot;noreferrer&quot;&gt;signed-distance fields&lt;/a&gt; and raymarching to produce high-quality soft shadows with accurate penumbras.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/M3eET.jpg&quot; alt=&quot;example distance-field shadows in Unreal Engine 4&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There’s a good writeup of the idea, with some visual examples, by Íñigo Quílez &lt;a href=&quot;http://www.iquilezles.org/www/articles/rmshadows/rmshadows.htm&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;—I’m not sure whether he invented the technique or was just one of the first to write about it:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The trick is to think what happens when a shadow ray doesn't hit any object, but was just pretty close to do so. Then, perhaps, you want to put that point you are shading under penumbra. Probably, the closest your point was to hit an object, the darker you want to make it. Also, the closest this happened from the point you are shading, the darker too. Well, it happens that as we raymarched our shadow ray, both these distances were available to us! … So, we can simply compute a penumbra factor for every step point in our marching process and take the darkest of all penumbras.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The documentation on the corresponding Unreal feature is &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/RayTracedDistanceFieldShadowing/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;; their description of the technique is a little vaguer, but still helpful.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;To calculate shadowing, a ray is traced from the point being shaded through the scene's Signed Distance Fields (SDF) toward each light. The closest distance to an occluding object is used to approximate a cone trace for about the same cost as the ray trace. It allows for high-quality area shadowing from spherical light source shapes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The main advantage of this approach is its high visual quality—most other techniques don’t handle varying penumbras well, and it doesn’t suffer as much from the aliasing problems of shadow maps. The main disadvantage is needing a distance-field representation of your scene geometry to trace rays through; unless you built it that way in the first place (there’s a &lt;a href=&quot;https://www.youtube.com/watch?v=u9KNtnCZDMI&quot; rel=&quot;noreferrer&quot;&gt;fascinating talk&lt;/a&gt; about how the team behind “Dreams” did exactly that), you’ll need a way to construct the SDFs out of your mesh geometry, which is an expensive and sometimes error-prone operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UE4 handles the SDF generation by building them offline beforehand and then stamping them into a volume around the camera at runtime (more information on that &lt;a href=&quot;https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/MeshDistanceFields/index.html&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;), but it’s not a cheap process so UE’s approach is only viable on high-end hardware for now. That said, if you &lt;em&gt;do&lt;/em&gt; already have your scene geometry in SDF form, it’s quite easy to implement—see &lt;a href=&quot;https://www.shadertoy.com/view/MsfGz8&quot; rel=&quot;noreferrer&quot;&gt;this Shadertoy&lt;/a&gt; for an example.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-02-07T21:03:26.543" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6237" PostTypeId="1" CreationDate="2018-02-08T17:22:02.540" Score="0" ViewCount="267" Body="&lt;p&gt;I wanted to make a little demo for a console with Realm of the Mad God esc graphics to brush up my C and SDL skills.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AtTDe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AtTDe.png&quot; alt=&quot;View of the walls I&amp;#39;m trying to recreate&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One problem I'm running in to is creating the 3D walls. &#xA;The console I'm working with does not actually allow for 3D hardware acceleration at this moment of time and thus I can't really use real 3D. &#xA;I noticed the perspective looked off in RotMG as well so I figured they must be using fake 3D also.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have tried layering 2d textures on top of eachother as detailed &lt;a href=&quot;http://www.like100bears.com/writing/2d-3d-in-gamemaker-studio&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; although this didn't quite work out so I modified the algorithm a bit and the blocks looked a lot better. Problem is they wouldn't sit next to eachother convincingly so I figured this is not the right tool for the job.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What type of algorithm should I use to recreate the 3D walls without actually using GL or other real 3D technologies?&lt;/p&gt;&#xA;" OwnerUserId="8171" LastActivityDate="2021-02-08T17:12:44.943" Title="What technique would I use to create fake 3d walls as seen in Realm of the Mad God" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6238" PostTypeId="2" ParentId="6237" CreationDate="2018-02-08T22:02:25.857" Score="3" Body="&lt;p&gt;What they're using in this game is called an &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;orthographic projection&lt;/a&gt;. It is a special type of a projection, which does not bend objects, it does not mean that they are not using 3D. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, of course you can achieve this kind of effect using 2D coordinates only if you want. But it requires some mathematical understanding of the situation, as you need to do 3D calculations in order to calculate the correct 2D coordinates to use. If you do it this way, you can draw points or lines between the points after calculating the positions, and it  will give the effect you want. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But here in RotMG, they are also doing texture mapping on those walls, which uses information about the actual size of the surface in 3D space. This information is lost if you simply calculate the 2D positions of the corners without also doing the texture mapping yourself. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So here you have two options:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You can give up your console and start doing some real 3D stuff (OpenGL, etc...).&lt;/li&gt;&#xA;&lt;li&gt;You can become very good at linear algebra, preferably including &lt;a href=&quot;https://en.wikipedia.org/wiki/Homogeneous_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;homogenous coordinates&lt;/a&gt;, project the points from 3D to 2D space, draw your lines/points in your console, or interpolate the 3D positions with some form of rasterization, if you want to decorate the wall using texture mapping. But once you understand all of that, I'm afraid you won't want to use your limited console anymore. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="8118" LastEditorUserId="8118" LastEditDate="2018-02-08T22:09:14.723" LastActivityDate="2018-02-08T22:09:14.723" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6239" PostTypeId="2" ParentId="6231" CreationDate="2018-02-09T03:07:51.730" Score="1" Body="&lt;p&gt;When rendering an image you are trying to find the outgoing light from a point into the camera $L(x \rightarrow \Theta$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do this you solve &quot;The rendering equation&quot;, which means you integrate the product of the brdf and the incoming light for every incoming direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L(x\rightarrow\Theta )=\int_\Omega f_r(x, \omega\rightarrow\Theta)\cdot L(x\leftarrow\omega)d\omega$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you don't have the outgoing light you cannot use the definition of the brdf to calculate it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f_r(x,\omega\rightarrow\Theta )=\frac{L(x\rightarrow\Theta)}{E(x\leftarrow\omega)}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, you use a formula to compute $f_r(x,\omega\rightarrow\Theta )$ and some operation to find the incoming light $L(x\leftarrow\omega)$ (a raytrace, a env map sample, etc.), and use those to compute the outgoing light $L(x\rightarrow\Theta)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These two calculations are usually done in a completely separate way. So there is no way the incoming light can effect the brdf in any way.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-09T03:07:51.730" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6240" PostTypeId="2" ParentId="6187" CreationDate="2018-02-09T05:05:43.903" Score="1" Body="&lt;p&gt;I took a few days and wrote something to do this.  It was not really as straightforward as I was expecting so I'll share what I learned.&lt;/p&gt;&#xA;&lt;h1&gt;What was hard&lt;/h1&gt;&#xA;&lt;p&gt;Here are the major headaches I encountered.&lt;/p&gt;&#xA;&lt;h3&gt;Dealing with JPEG Compression Artifacts&lt;/h3&gt;&#xA;&lt;p&gt;When sampling the values for the legend, I encountered many JPEG compression artifacts. This required me to apply a median filter.  The median filter width needed to be a parameter of the function (needs different values depending on how big the legend is.)&lt;/p&gt;&#xA;&lt;h3&gt;Dealing with &amp;quot;bands&amp;quot; in the legend&lt;/h3&gt;&#xA;&lt;p&gt;The legend in your first example is divided into discrete sections (bands) and the numeric quantity desired is probably the middle of the range that the colour spans.  For example, the left-most box covers values from -6500 to -6000 and should probably return &amp;quot;-6250&amp;quot; when trying to sample a single colour of that value.  Also, consequently, no pixel will return the value &amp;quot;0&amp;quot;.  There is no colour representation for &amp;quot;0&amp;quot; (in that first map anyway.)&lt;/p&gt;&#xA;&lt;h3&gt;Dealing with differences in tone / value.&lt;/h3&gt;&#xA;&lt;p&gt;Sometimes the exact colour in the map doesn't exist in the legend, especially due to the text labels, so you have to do a &amp;quot;closest&amp;quot; matching algorithm and the hue seems to be more important than the value (black&amp;amp;white-ness) so it was better to evaluate &amp;quot;distance&amp;quot; between colours in a colourspace other than RGB.&lt;/p&gt;&#xA;&lt;h3&gt;Text overwrites data&lt;/h3&gt;&#xA;&lt;p&gt;There are plenty of black pixels in the map due to the labels, but these need to be ignored somehow.  It makes sense to try to infer what the value behind the text is, and only colours that are not in the legend qualify for this kind of inference.&lt;/p&gt;&#xA;&lt;h3&gt;Manually selecting points on the legend is not precise&lt;/h3&gt;&#xA;&lt;p&gt;Each time I eye-balled it and manually found a point that looked like approximately the end-point, I'd choose a slightly different pixel, resulting in slightly different values between attempts.  Perhaps a snapping technique would be better where I could &amp;quot;hint&amp;quot; where the legend is, but it would find the high-contrast edge markings and snap the hint point to the exact point.&lt;/p&gt;&#xA;&lt;h3&gt;Most maps don't have continuous legends.&lt;/h3&gt;&#xA;&lt;p&gt;Most other images that I went searching for with test data had discontinuities in their legend (discrete boxes of colour) as opposed to a nice continuous linear gradient like you provided.  This makes it extra difficult to automatically come up with the mapping from colour to value just by analyzing the positions of the colours in the legend.  I was disappointed when trying to apply it to most maps.&lt;/p&gt;&#xA;&lt;h3&gt;Visualization tips&lt;/h3&gt;&#xA;&lt;p&gt;It was very useful (especially while debugging) to visually show the point on the legend that it thought best corresponded to the colour being picked in the map.&lt;/p&gt;&#xA;&lt;h3&gt;Persistence&lt;/h3&gt;&#xA;&lt;p&gt;It's useful to persist the location of the endpoints of the linear gradient portion of the legend and the values that are associated with them between runs of the application.  Don't underestimate the value of this.  It's annoying to have to specify all that stuff every time.&lt;/p&gt;&#xA;&lt;h1&gt;What worked well&lt;/h1&gt;&#xA;&lt;h3&gt;Represent the legend as all the pixels along a line segment&lt;/h3&gt;&#xA;&lt;p&gt;Specify two (x,y) locations of the start and end of a linear gradient (the legend) and manually define the values that are associated with them.&lt;/p&gt;&#xA;&lt;h3&gt;build up a discrete sample set for the gradient&lt;/h3&gt;&#xA;&lt;p&gt;Sample all the pixels in between the start and end points to build a linear gradient dataset.&lt;/p&gt;&#xA;&lt;h3&gt;Median filter&lt;/h3&gt;&#xA;&lt;p&gt;Apply a median filter to the linear gradient dataset to filter out JPEG noise.&lt;/p&gt;&#xA;&lt;h3&gt;Quantize the dataset to locate centroids&lt;/h3&gt;&#xA;&lt;p&gt;Optionally filter out bands (long runs of samples in the linear gradient dataset that have approximately the same colour) and replace them with a single sample at the centroid (average position).&lt;/p&gt;&#xA;&lt;h3&gt;Use bilinear sampling when picking a pixel&lt;/h3&gt;&#xA;&lt;p&gt;Pick a pixel in the map and perform a bilinear sample to smooth out pixellation.  This seems to help improve the smoothness and resolution of the map.&lt;/p&gt;&#xA;&lt;h3&gt;Linear search is fine&lt;/h3&gt;&#xA;&lt;p&gt;Linearly search for the data point in the linear gradient for the closest colour.  For an interactive picker working from mouse clicks, you have lots of time to perform a linear search.  No fancy hashing, indexing or optimized searching was required.&lt;/p&gt;&#xA;&lt;h3&gt;Hue is important in the colour distance function&lt;/h3&gt;&#xA;&lt;p&gt;Compare distance between colours using a distance function in a colourspace that tolerates brightness difference more than hue difference.  (like YUV, for example)&lt;/p&gt;&#xA;" OwnerUserId="8009" LastEditorUserId="8009" LastEditDate="2020-12-19T15:06:24.307" LastActivityDate="2020-12-19T15:06:24.307" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="6241" PostTypeId="1" CreationDate="2018-02-09T07:14:13.500" Score="-1" ViewCount="58" Body="&lt;p&gt;What is the process involved in calculating the resolution of image to be displayed when the screen of my phone(android) is rotated? My screen resolution is 1920x1080. It displays some videos only in the center while top and bottom of the video are blacked(when phone is held vertical), where as full screen video is shown when phone is held in horizontal position.&lt;/p&gt;&#xA;" OwnerUserId="8153" LastActivityDate="2018-02-10T15:56:50.583" Title="How does image resolution change(process involved in calculation), when a screen on phone is rotated?" Tags="&lt;rendering&gt;&lt;image-processing&gt;&lt;computational-geometry&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6242" PostTypeId="1" CreationDate="2018-02-09T09:39:25.283" Score="1" ViewCount="74" Body="&lt;p&gt;I have two aligned meshes: I have exact mapping from each vertex of low poly mesh to surface of a high poly mesh. High poly (~100K vertices) mesh is non-manifold, low poly (~1K vertices) is manifold and allows cylindrical texture mapping and each vertex has a normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What algorithms can I use to project supersampled texture (albedo/diffuse and normal maps) from high poly mesh to low poly mesh? It would be great to have not only a paper, but implementation as well.&lt;/p&gt;&#xA;" OwnerUserId="2750" LastEditorUserId="2750" LastEditDate="2018-02-09T18:15:32.970" LastActivityDate="2018-02-09T18:15:32.970" Title="How to automatically project texture from high poly mesh to low poly mesh?" Tags="&lt;texture&gt;&lt;3d&gt;&lt;diffuse&gt;&lt;3dtexture&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6243" PostTypeId="1" CreationDate="2018-02-09T13:23:33.373" Score="0" ViewCount="74" Body="&lt;p&gt;I want to learn is it good or bad idea.&lt;/p&gt;&#xA;&lt;p&gt;Let's assume video RAM is not a problem.&lt;/p&gt;&#xA;&lt;p&gt;For source texture create a texture of texels: spherical functions. Spherical functions defined by small arrays of spherical harmonics coefficients up to some reasonable degree (say 3). To gather single sample for particular texel and particular coordinates on sphere (theta, phi) it is needed to integrate over the footprint (here I mean &lt;em&gt;footprint assembly&lt;/em&gt; method) started from the textel and use this value later when spherical harmonic coefficients are calculated. Phi is exactly polar angle of the footprint on &lt;code&gt;uv&lt;/code&gt; plane. Theta is length of the footprint up to (and from, as optimization) some reasonable length. I almost sure, that continuity is almost preserved, except bottom of the sphere (and to, where theta begins, if we starts from some threshold minimal length of a footprint).&lt;/p&gt;&#xA;&lt;p&gt;There are possible some optimizations when performed backing of a footprints: save value of integrated color in both pixels footprint begins and ends. Calculate values for fixed number of directions and radii (and on power of two proximities). And, maybe others.&lt;/p&gt;&#xA;&lt;p&gt;The advantage of the method is possibility to get color of whole screen pixel footprint in single sampling act. The disadvantage is requirement to prepare (&lt;span class=&quot;math-container&quot;&gt;$O(N^4) \approx x_{resolution} \cdot y_{resolution} \cdot n_\phi \cdot n_\theta$&lt;/span&gt;?) such a texture for every LOD (separately? or bilinear scaling applicable?) and huge amount of memory even for coefficients of spherical harmonics to represent a spherical function of even 3 degree (&lt;span class=&quot;math-container&quot;&gt;$3^2 = 9$&lt;/span&gt; RGB values) for better angular and &lt;em&gt;footprint length&lt;/em&gt; resolution.&lt;/p&gt;&#xA;&lt;h3&gt;ADDITIONAL&lt;/h3&gt;&#xA;&lt;p&gt;Now I think there is no need to have mips. All other LODs can be modeled &lt;strong&gt;continuously&lt;/strong&gt; by using different cone angle to make convolution with saved spherical function. It is very smooth.&lt;/p&gt;&#xA;&lt;p&gt;It seems also better to save value of color itself, not integral over footprint, because spherical harmonics allow to easily calculate integrals (just a scalar product). Especially with zonal sperical functions like integral into a solid angle inside of arbitrary oriented cone.&lt;/p&gt;&#xA;&lt;p&gt;I think this format of textures is best for cartoon industry.&lt;/p&gt;&#xA;" OwnerUserId="5430" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-04-17T07:11:22.197" Title="Baked anisotropic filtering using spherical harmonics" Tags="&lt;antialiasing&gt;&lt;filtering&gt;&lt;spherical-harmonics&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6244" PostTypeId="1" AcceptedAnswerId="6245" CreationDate="2018-02-10T01:10:49.117" Score="3" ViewCount="77" Body="&lt;p&gt;I'm currently taking a graphics course and we've recently covered cross-correlation with regards to using a filter matrix that is applied to a region of pixels in a sort of continual raster-type scan across a larger input image to produce some output image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula is denoted here:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZTbzk.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZTbzk.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;G is the output image, h is the kernel/box filter matrix, F is the input image&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The classic one that was introduced is a 3x3 box filter for blurring an input image. The box filter is a 3x3 matrix with each cell value being equally set to 1/9. We've been dealing primarily with grayscale images with values 0 (black) to 255 (white).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, the largest possible output pixel value would be if the 3x3 input image area contained all white pixels in which case we'd have:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;[(1/9) * 255 ] * 9 = 255&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is fine, but what if our kernel filter matrix instead had 9 cell values all equal to 0.5?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the largest potential output value would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;[0.5 * 255] * 9 = 1147.5&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once we've completely finished producing our new output image matrix, how do we handle values above 255 and below 0?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like there are three possible approaches:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Capping&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Cap all output values to 0 and 255. Any value below 0 is capped to 0, any value above 255 is capped to 255.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Modulo&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Use modulo. In this case it would be 1147.5 % 255 = 125.5 rounded to 126.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Scaling&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Take the highest output value and use it to scale all the values proportionally. If our example output image pixel values were 1147.5, 100, and 255, then we would perform the following operations:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;(1147.5 / 1147.5) * 255 = 255&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;(100 / 1147.5)    * 255 = 22.2 = 22&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;(255 / 1147.5)    * 255 = 56.6 = 57&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I just don't get which one of these I'm supposed to be using for common graphics operations. I have the same question when combining images together (such as multiply, divide, screen, etc).&lt;/p&gt;&#xA;" OwnerUserId="8180" LastActivityDate="2018-02-10T06:40:20.057" Title="Modulo vs Scaling vs Capping when performing filters" Tags="&lt;mathematics&gt;&lt;matrix&gt;&lt;blur&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6245" PostTypeId="2" ParentId="6244" CreationDate="2018-02-10T02:26:32.000" Score="2" Body="&lt;p&gt;When doing a filter operation such as a blur, in many cases the filter itself will be normalized so its values sum to 1.0, precisely to avoid this problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In cases where out-of-range outputs do need to be handled, the most common way is what you called capping. In graphics it's more commonly known as clamping or saturating. This is the default behavior if, for instance, you run a pixel shader on a GPU and output out-of-range values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Renormalizing the output image might be necessary in some special cases depending on what you're doing. I can't think of anytime that I've seen the modulo behavior used—it would be a pretty weird operation to do on a visual image.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-02-10T02:26:32.000" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6246" PostTypeId="2" ParentId="6244" CreationDate="2018-02-10T06:40:20.057" Score="2" Body="&lt;p&gt;While clamping or saturating may be the most common way of handling this situation, it's usually not the best. (But wrapping/modulus is one of the worst.) Another way of handling it is to either convert the input to 16 or 32-bit ints or floats and do all calculations in the higher bit depth. You may want to down-convert the final output, if required by your processing tools. Or, if you can choose the output format you can leave it in a higher bit depth. Most professional tools these days do their work in higher bit depths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding your question:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;is it common to add/multiply images together?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, it's quite common in tools that allow compositing. In Photoshop, for example, there are blend modes that are even named &quot;Add&quot; and &quot;Multiply&quot; and they do just that. (Though they assume the values are normalized to a 0-1 range.) If you are working with 8-bit per channel images, they will clamp, but if you are working with 32-bit per channel images, they will simply have values greater than 1. If done with linear RGB, this mimics light fairly naturally, and you can apply natural photographic operations to the results, like decreasing the exposure and it will bring those blown-out highlights back into the displayable range. As we move into the era of High Dynamic Range output devices, this type of processing will only become more common and useful.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-02-10T06:40:20.057" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6247" PostTypeId="2" ParentId="6233" CreationDate="2018-02-10T13:26:35.587" Score="3" Body="&lt;p&gt;OK I think I know what your problem is, gimbal lock does not really lock anything from a mathematical point if view, only for certain operations. See euler suggested that euler angles can define all space angles. And that is true. Its just that euler does not say that the space is uniform. Highly mathematical people also say that the euler space has impossible solutions since some positions are overlapping, but in practice this is not really a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now since you can reach any angle, and you can always unwind your angle you can reach any angle in the body. Provided that your ready to unravel the situation and start over for a computer program doing animation and a mathematician this seems reasonable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this is not what most people are doing. Instead if you try to do some physical things like calculating the distance between 2 positions, the energy needed to rotate, use a external force to move the system or make a delta move in the gimbals space then this non uniformity kicks in. Simply the space is not uniform the same way that a real space is at the poles the distance to a position next to you in real space can be surprisingly far away in Euler rotation space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when somebody is euler locked it does not mean they can not move anywhere they just can not move in the direction they would want to move in that particular orientation of the gimbal, and close to it. Its a bit like living in the suburbs and wanting to reach your neighbors house (that is 100 m away) but being forced to go trough the center of the city (15 km away). Energetically or time wise highly wasteful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a problem in 3D graphics only if you choose to interpolate in Euler angles. But for a control engineer or a mechanical engineer this can be  a nightmare, since you can suddenly have a discrepancy between what your mechanism and your control logic is saying.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now it is possible to construct the gimbal so that the pole does not really happen, just not with the orthogonal axes the space is still not uniform but it does not experience the extreme case. However it might just be easier to use some other formulation like quaternionions, or axis angle instead. (quaternionions aren't really practical if your building a real mechanism though, its possible but very convoluted)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I would draw an image, its just that drawing something the wraps perfectly upon itself and is a 3d field is a bit difficult to do.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2018-02-10T13:34:01.327" LastActivityDate="2018-02-10T13:34:01.327" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6248" PostTypeId="2" ParentId="6241" CreationDate="2018-02-10T15:56:50.583" Score="1" Body="&lt;p&gt;Usually the resolution of the video is changed on-the-fly to match the size being displayed. So if you have video that has a 16:9 aspect ratio and 1920 x 1080 pixels and you turn your phone into the vertical position, you'll now have a width of 1080 pixels instead of height. So the width changed from 1920 to 1080. Now you have to figure out how to change the height by the same ratio:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;newHeight = 1080 * (1080 / 1920)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Or, using the aspect ratio of the footage:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;newHeight = 1080 * (9 / 16)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So the new height would be 607.5, but it probably gets rounded up to 608 since that's an even number. So now, when each frame is displayed, it first gets scaled down (probably using the GPU since it's very fast at that) from 1920 x 1080 to 1080 x 608.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-02-10T15:56:50.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6249" PostTypeId="1" CreationDate="2018-02-10T16:46:28.533" Score="1" ViewCount="1889" Body="&lt;p&gt;On the CPU side, I have a structure I want to pass to the compute kernel:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  private struct BoundingBoxParameters {&#xA;    var x: Float = 0&#xA;    var y: Float = 0&#xA;    var width: Float = 0&#xA;    var height: Float = 0&#xA;    var levelOfDetail: Float = 1.0&#xA;    var dummy: Float = 1.0  // Needed for success&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Before running the kernel, I pass in the data to the MTLComputeCommandEncoder:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Option 1 (directly):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;commandEncoder!.setBytes(&amp;amp;params, length: MemoryLayout&amp;lt;BoundingBoxParameters&amp;gt;.size, index: 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Option 2 (indirectly via MTLBuffer):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;boundingBoxBuffer.contents().copyBytes(from: &amp;amp;params, count: MemoryLayout&amp;lt;BoundingBoxParameters&amp;gt;.size)&#xA;commandEncoder!.setBuffer(boundingBoxBuffer, offset: 0, index: 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Either option works fine if the 'dummy' variable exists in the structure, but fails if the 'dummy' variable does not exists. The code fails in the call to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;commandEncoder!.dispatchThreadgroups(threadGroups, threadsPerThreadgroup: threadGroupCount)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With the error:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;validateComputeFunctionArguments:820: failed assertion `Compute Function(resizeImage): argument params[0] from buffer(0) with offset(0) and length(20) has space for 20 bytes, but argument has a length(24).'&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;On the Metal Kernel Side, here's the relevant code snippets:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct BoundingBoxParameters {&#xA;  float2 topLeft;&#xA;  float2 size;&#xA;  float levelOfDetail;&#xA;};&#xA;&#xA;kernel void resizeImage(constant BoundingBoxParameters *params [[buffer(0)]],&#xA;                        texture2d&amp;lt;half, access::sample&amp;gt; sourceTexture [[texture(0)]],&#xA;                        texture2d&amp;lt;half, access::write&amp;gt; destTexture [[texture(1)]],&#xA;                        sampler samp [[sampler(0)]],&#xA;                        uint2 gridPosition [[thread_position_in_grid]]) {&#xA;  float2 destSize = float2(destTexture.get_width(0), destTexture.get_height(0));&#xA;  float2 sourceCoords = float2(gridPosition) / destSize;&#xA;  sourceCoords *= params-&amp;gt;size;&#xA;  sourceCoords += params-&amp;gt;topLeft;&#xA;  float lod = params-&amp;gt;levelOfDetail;&#xA;  half4 color = sourceTexture.sample(samp, sourceCoords, level(lod));&#xA;  destTexture.write(color, gridPosition);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I also get a similar issue when trying to pass in a 3x3 matrix to the compute kernel. It complains that 36 bytes are provided but expecting 48.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone got any ideas on the issue?&lt;/p&gt;&#xA;" OwnerUserId="8032" LastActivityDate="2019-02-26T09:50:00.073" Title="Passing parameters in Metal Compute Kernel using Swift 4" Tags="&lt;image-processing&gt;&lt;compute-shader&gt;&lt;metal&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6251" PostTypeId="2" ParentId="6233" CreationDate="2018-02-10T17:17:31.187" Score="3" Body="&lt;p&gt;So thanks to joojaa I finally got a hint, and I searched on the net further and found &lt;a href=&quot;https://matthew-brett.github.io/transforms3d/gimbal_lock.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link&lt;/a&gt; which cleared all the doubts and has my answer. Though I am still posting it here as a summary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So anyone reading this and who has similar problem to mine here is what I understood. Suppose we are considering the tait-bryan angle order X-Y-Z that is rotate first along X then Y and finally Z. Also to make it clear we are rotating around the &quot;fixed&quot; axes since a rotation matrix always rotates around the fixed axes. The matrix doesn't know anything about the axes moving or anything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/agrEP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/agrEP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So suppose I have my initial frame like in my picture (original post) leftmost. If I use &lt;code&gt;Ax&lt;/code&gt; with &lt;code&gt;angle = 90 degrees&lt;/code&gt; then my &lt;code&gt;Y&lt;/code&gt; axis becomes &lt;code&gt;Z&lt;/code&gt; and &lt;code&gt;Z&lt;/code&gt; becomes &lt;code&gt;-Y&lt;/code&gt;. However if I now rotate with &lt;code&gt;Ay&lt;/code&gt; the matrix will still be rotating around the previous/original fixed &lt;code&gt;Y&lt;/code&gt; axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that's clear take this plane as an example. We want to rotate in the order X-Y-Z.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5jGNQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5jGNQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we rotate around the X-axis we can see that the plane will either roll left or right. Suppose we rotate a little around the X-axis and then rotate around &lt;code&gt;Y-axis&lt;/code&gt; so that it is pointing straight up like this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7cgdo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7cgdo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we have to rotate around Z as this is the last in the order. But notice that the rotation around &lt;code&gt;Z&lt;/code&gt; is similar to the previous rotation we performed around &lt;code&gt;X&lt;/code&gt;. The plane will roll either towards the left or right. This means we lost 1 degree of freedom. I think this is what joojaa was trying to explain to me. So everywhere where people are saying the axis coincide its the local, moving frame coinciding with the original frame. Initially both the local and global frames are coinciding. In this case when we rotated around &lt;code&gt;Y&lt;/code&gt; by 90 the local moving X-axis collapsed on to the fixed original &lt;code&gt;Z&lt;/code&gt;- axis causing this gimbal lock &lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-02-10T17:17:31.187" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6254" PostTypeId="1" AcceptedAnswerId="6267" CreationDate="2018-02-11T19:58:23.250" Score="2" ViewCount="11258" Body="&lt;p&gt;This has been haunting me for several days now. I want to find the component that makes up of this 4x4 perspective projection matrix, with $l$(left), $r$(right), $b$(bottom), $t$(top), $n$(near), $f$(far) defining the frustum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\left(&#xA;\begin{array}{cccc}&#xA;\frac{2n}{r-l}&amp;amp;        0&amp;amp;  \frac{r+l}{r-l}&amp;amp;         0\\&#xA;0&amp;amp; \frac{2n}{t-b}&amp;amp;  \frac{t+b}{t-b}&amp;amp;         0\\&#xA;0&amp;amp;        0&amp;amp; -\frac{f+n}{f-n}&amp;amp;-\frac{2fn}{f-n}\\&#xA;0&amp;amp;       0&amp;amp;           -1&amp;amp;         0&#xA;\end{array}&#xA;\right)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my approach so far. The first matrix component would just copy $z$ over to $w$ coordinate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\left(&#xA;\begin{array}{cccc}&#xA;    1&amp;amp; 0&amp;amp;  0&amp;amp; 0\\&#xA;    0&amp;amp; 1&amp;amp;  0&amp;amp; 0\\&#xA;    0&amp;amp; 0&amp;amp;  1&amp;amp; 0\\&#xA;    0&amp;amp; 0&amp;amp; -1&amp;amp; 0&#xA;\end{array}&#xA;\right)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second matrix translates the eye ($at = \left(0, 0, 0\right)$) to ($\frac{l+r}{2}$, $\frac{t+b}{2}$, $\frac{n+f}{2}$, the center of the frustum because canonical coordinate is just a cube of size $2$ with its centroid at the origin $\left(0, 0, 0\right)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\left(&#xA;\begin{array}{cccc}&#xA;    1&amp;amp; 0&amp;amp; 0&amp;amp; \frac{l+r}{2}\\&#xA;    0&amp;amp; 1&amp;amp; 0&amp;amp; \frac{b+t}{2}\\&#xA;    0&amp;amp; 0&amp;amp; 1&amp;amp; \frac{n+f}{2}\\&#xA;    0&amp;amp; 0&amp;amp; 0&amp;amp;       1&#xA;\end{array}&#xA;\right)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last matrix just scales the thing so that the frustum fits into the cube of size $2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\left(&#xA;\begin{array}{cccc}&#xA;    \frac{2}{r-l}&amp;amp;       0&amp;amp;       0&amp;amp; 0\\&#xA;          0&amp;amp; \frac{2}{t-b}&amp;amp;       0&amp;amp; 0\\&#xA;          0&amp;amp;       0&amp;amp; \frac{2}{f-n}&amp;amp; 0\\&#xA;          0&amp;amp;       0&amp;amp;       0&amp;amp; 1 &#xA;\end{array}&#xA;\right)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the multiplication of these 3 matrices isn't equal to the perspective projection matrix. What am I missing?&lt;/p&gt;&#xA;" OwnerUserId="8191" LastEditorUserId="7008" LastEditDate="2018-02-13T13:21:59.140" LastActivityDate="2019-08-02T08:17:15.157" Title="How to derive a perspective projection matrix from its components?" Tags="&lt;3d&gt;&lt;matrix&gt;&lt;projections&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6256" PostTypeId="1" AcceptedAnswerId="6257" CreationDate="2018-02-12T01:46:30.437" Score="6" ViewCount="4548" Body="&lt;p&gt;for better accuracy, instead of GLfloat, I bound double data and tried to use the data in shader as follow: (I just tested to draw single triangle.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;cpp.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// xyzw three vertices&#xA;double points[] = { 0.0, 0.0, 0.0, 1.0 , 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0 };&#xA;&#xA;glGenVertexArrays(1, VAO);&#xA;glBindVertexArray(VAO);&#xA;&#xA;glGenBuffers(1, &amp;amp;VBO);&#xA;glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;glBufferData(GL_ARRAY_BUFFER, 96, points, GL_STATIC_DRAW);&#xA;&#xA;&#xA;int data = 0;&#xA;glEnableVertexAttribArray(0);&#xA;glVertexAttribPointer(0, 4, GL_DOUBLE, GL_FALSE, 0, (void*)data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;shader.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;layout(location = 0) in dvec4 vPos;&#xA;&#xA;&#xA;void main() {&#xA;    gl_Position = vec4(vPos);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What's worng with me? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(If I changed the dvec4 in the above shader to vec4, the triangle was drawn, but maybe it's not double anymore. I want to use double in shader.)&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2018-02-12T02:03:20.120" Title="Double precision in shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6257" PostTypeId="2" ParentId="6256" CreationDate="2018-02-12T02:03:20.120" Score="13" Body="&lt;p&gt;The problem is, &lt;code&gt;glVertexAttribPointer(0, 4, GL_DOUBLE...&lt;/code&gt; doesn't do what you think it does.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using actual double-precision vertex attributes and performing double precision computations is a very modern hardware feature (GL4/DX12) and is different from specifying the type &lt;code&gt;GL_DOUBLE&lt;/code&gt; in the good old &lt;code&gt;glVertexAttribPointer&lt;/code&gt; call. This always worked and does nothing else than specify the &lt;em&gt;input&lt;/em&gt; type, i.e. the type of your vertex data in memory. All it does is make the GL convert your doubles into singles and feeding them into a normal single-precision attribute (and failing when there is none), same with other input types like &lt;code&gt;GL_SHORT&lt;/code&gt; or &lt;code&gt;GL_UNSIGNED_BYTE&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When specifying data for genuine double-precision attributes, you have to use &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribPointer.xhtml&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;glVertexAttribLPointer&lt;/code&gt;&lt;/a&gt; (note the &lt;strong&gt;L&lt;/strong&gt;) instead. The same holds for genuine integer attributes (&lt;code&gt;ivecX&lt;/code&gt;/&lt;code&gt;uvecX&lt;/code&gt;), which use &lt;code&gt;glVertexAttribIPointer&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;Of course the answer isn't complete without some general advise, that you should really make sure you actually need double precision vertex attributes, or even double precision computation. Even on modern hardware that's still significantly slower and not what those GPUs are really made for, not to speak of the doubled memory consumption for the vertex data. More precision is not always better if it isn't actually necessary and you might be surprised what a lousy little &lt;code&gt;float&lt;/code&gt; is able to accomplish when used well.&lt;/sub&gt;&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-02-12T02:03:20.120" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6258" PostTypeId="2" ParentId="6249" CreationDate="2018-02-12T04:47:31.577" Score="2" Body="&lt;p&gt;The float2 type in the Metal structure requires an alignment of 8 bytes. The stride of the struct then becomes 24 so every value is aligned properly if you use it in an array.  Your Swift structure only uses float which requires an alignment of 4 bytes, and an overall stride of 20.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://devstreaming.apple.com/videos/wwdc/2014/604xxg7crkljcr8/604/604_working_with_metal_fundamentals.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;This presentation by Apple&lt;/a&gt; goes into some detail (starting at 30:20 of &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2014/604/&quot; rel=&quot;nofollow noreferrer&quot;&gt;the video&lt;/a&gt;). The &lt;a href=&quot;https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metal Shading Language&#xA;Specification &lt;/a&gt; lists the alignment of vector and matrix data types in sections 2.2 and 2.3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, float3x3 has a size of 48 and an alignment of 16 in Metal. But an array of 9 floats would only have a size of 36 and an alignment of 4. Using the simd module can provide you data types in Swift with the same size and alignment requirements as those used in Metal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a side note, you should be using MemoryLayout&amp;lt;&gt;.stride instead of MemoryLayout&amp;lt;&gt;.size when you call setBytes.  The following Swift structure has a stride of 24 but a size of only 20.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct BoundingBoxParameters {&#xA;    var topLeft: float2 = float2(0)   // float2 is from &quot;import simd&quot;&#xA;    var size: float2 = float2(0)&#xA;    var levelOfDetail: Float = 1.0&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7271" LastActivityDate="2018-02-12T04:47:31.577" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6259" PostTypeId="1" AcceptedAnswerId="6261" CreationDate="2018-02-12T09:32:28.407" Score="1" ViewCount="1090" Body="&lt;p&gt;The OpenGL &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Layout_Qualifier_(GLSL)#Image_formats&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki entry&lt;/a&gt; for layout qualifiers says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Image uniform variables have qualifiers that define the format that all reading operations will convert the data into...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;When is it a good idea to declare the image format in a shader?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;i.e. &lt;code&gt;layout (binding = 0, r32f) readonly uniform image2D input_image&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wouldn't this shader work just as well if I did not specify the &lt;code&gt;r32f&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2018-02-13T06:52:56.020" Title="Why would I specify image format in a shader layout qualifier?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6261" PostTypeId="2" ParentId="6259" CreationDate="2018-02-12T11:49:27.387" Score="1" Body="&lt;p&gt;From the same &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Load_Store&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Image variables can be declared with a format qualifier; this&#xA;  specifies the format for any read operations done on the image.&#xA;  &lt;strong&gt;Therefore, a format qualifier is required if you do not declare the&#xA;  variable with the writeonly memory qualifier. Write-only variables&#xA;  cannot be used as in any reading operations; this includes calling&#xA;  load and atomic (read/modify/write) functions. So if you want to read&#xA;  from an image, you must declare the format.&lt;/strong&gt;&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;The format defines how the shader interprets the bits of data that it&#xA;  reads from the image. It also defines how it converts the data passed&#xA;  for write operations when it writes it into the image. This allows the&#xA;  actual Image Format of the image to differ between what the shader&#xA;  sees and what is stored in the image, sometimes substantially.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-02-12T11:49:27.387" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6262" PostTypeId="1" AcceptedAnswerId="6266" CreationDate="2018-02-12T16:54:00.027" Score="2" ViewCount="782" Body="&lt;p&gt;In a BRDF $f_r$, assume Cook-Torrance model, we have a microfacets distribution $D$. This distribution essentially models the rougheness of the material as far as I've understood. Given a direction $v$ it models the amount of microfacets having that orientation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now say we have a material, for each point $p$ in theory we have a 3D function that tell us the orientation in a given direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This explantion (not detailed) makes sense to me, however when I read about the roughness map what I see is that it's a kind of texture where each pixel has values between 0 and 1 (from black to white) I do struggle to understand the relationship between this map and the microfacets distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone clarify?&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="2479" LastEditDate="2018-02-12T17:47:09.323" LastActivityDate="2018-02-13T07:36:47.343" Title="Relationship between roughness and BRDF" Tags="&lt;shader&gt;&lt;brdf&gt;&lt;distribution&gt;&lt;microfacet&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6264" PostTypeId="2" ParentId="6259" CreationDate="2018-02-13T06:52:56.020" Score="-1" Body="&lt;p&gt;I had the exact same question until I learned about Compute shaders &amp;amp; was playing around with it. I think Compute shader is one possible use case where you read/write into an image. This is where specifying these formats is important. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2018-02-13T06:52:56.020" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6265" PostTypeId="2" ParentId="6262" CreationDate="2018-02-13T07:34:05.740" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;for each point $p$ in theory we have a 3D function that tells us the orientation in a given direction&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You have missunderstood this. $D$ is a Normal &lt;em&gt;Distribution&lt;/em&gt; Function (or short NDF), so it doesn't really give you a single normal, but a distribution. In a (specular) BRDF you are always using the normal that is the half vector between the incoming and outgoing light, since via your theory, every microfacet is a perfect mirror and thus every microfacet reflects light exactly along the (micro) surface and that one only.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You also must not confuse &lt;em&gt;roughness&lt;/em&gt; with &lt;em&gt;microfacet normal&lt;/em&gt;. The roughness is a more or less arbitrary value (and a scalar, so a single one at that). The roughness is being used differently, depending on the overall BRDF (e.g. roughness in GGX(/Trowbridge-Reitz) is different from the Roughness in Oren-Nayar) and therefore can have different ranges. Still, if you look at one specific NDF, you will see, how the roughness is used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$D(\omega_m) = \frac{\alpha^2}{\pi((\omega_n \cdot \omega_m)^2 (\alpha^2-1)+1)^2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;with $\alpha = roughness^2$ (a common remapping), $\omega_m$ is the microfacet normal, $\omega_n$ is the geometry normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see here, that the roughness is being treated like a single value. The higher the roughness is, the more random your microfacets (or normals thereof) are distributed. The more that happens, the less your surface will reflect light concentrated into the same direction (i.e. the less highlights you will have). Thus, your material is more diffuse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since now your roughness is a single value, the map makes sense to have only values in $\left[0, 1\right]$ and therefore is a gray scale image.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-02-13T07:34:05.740" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6266" PostTypeId="2" ParentId="6262" CreationDate="2018-02-13T07:36:47.343" Score="3" Body="&lt;p&gt;Most normal distribution functions (NDFs) are parametrized by some variable (tipically $m$ or $\alpha$) that determines the &quot;roughness&quot; or &quot;spikiness&quot; of the NDF (this is often meant to be the rms slope of the surface).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an example of how a roughness parameter effects an NDF: &lt;a href=&quot;https://www.desmos.com/calculator/kcevxp3wm0&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.desmos.com/calculator/kcevxp3wm0&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;we can think of the NDF as a function of the direction as well as of the roughness value (as in $D(\theta,\phi,m)$. Here, $\phi$ and $\theta$ were used to represent spherical coordinates for the microsurface normal direction).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A roughness map can also be thought of as a function: one that returns a value for $m$ for every point $p$ on a surface. Hence, $m(p)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since $m$ is an argument of the NDF we can write the previous expression like this: $D(\theta,\phi,m(p))$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And, because $m(p)$ may be different for every $p$ but stays fixed when we only vary $\phi$ and $\theta$, we effectively get a whole different NDF on every point on the surface.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-13T07:36:47.343" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6267" PostTypeId="2" ParentId="6254" CreationDate="2018-02-13T07:57:56.177" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;The second matrix translates the eye [...]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You don't do that in a projection matrix. You do that with your view matrix:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Model (/Object) Matrix transforms an object into World Space&lt;/li&gt;&#xA;&lt;li&gt;View Matrix transforms all objects from world space to Eye (/Camera) Space (no projection so far!)&lt;/li&gt;&#xA;&lt;li&gt;Projection Matrix transforms from Eye Space to Clip Space&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Therefore you don't do any matrix multiplications to get to a projection matrix. Those multiplications happen in the shader, where you do &lt;span class=&quot;math-container&quot;&gt;$Projection\cdot View \cdot Model$$^1$&lt;/span&gt; Matrix (for example in the vertex shader to specify your position output).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, remember that a perspective projection changes angles (i.e. parallel lines won't be parallel anymore). As far as I can see that is missing in your derivation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Edit&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to how you actually derive it, I'll largely use the explanation by&lt;a href=&quot;http://ogldev.atspace.co.uk/www/tutorial12/tutorial12.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Etay Meiri&lt;/a&gt;. It has some additional information and illustration, so you may want to check it, if something seems unclear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, your camera is (as mentioned earlier) positioned in the origin.&#xA;Now assume, you will only project onto a plane of distance &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; and the plane you project onto is bounded by the aspect ration &lt;span class=&quot;math-container&quot;&gt;$ar$&lt;/span&gt; (that is &lt;span class=&quot;math-container&quot;&gt;$ar = \frac{window\text{ }width}{window\text{ }height}$&lt;/span&gt; in positive and negative &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; direction and by &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; in positive and negative &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can now determine &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; by your vertical field of view &lt;span class=&quot;math-container&quot;&gt;$\alpha$&lt;/span&gt; (since looking from the side, your camera, the center at the top of your projection plane and the center of the bottom of your projection plane build a triangle and your vertical field of view is the angle at your camera):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{1}{d} = \tan(\frac{\alpha}{2})\\&#xA;\implies d = \frac{1}{\tan(\frac{\alpha}{2})}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you go about calculating projected points. Assume you have an arbitrary point &lt;span class=&quot;math-container&quot;&gt;$v = (v_x, v_y, v_z)$&lt;/span&gt;, and you want to calculate the point on your plane &lt;span class=&quot;math-container&quot;&gt;$p = (p_x, p_y, d)$&lt;/span&gt;. Looking at it from the side again, the triangle with your camera, your projection plane top center point and your projected point is similar to the triangle with your camera, your projection plane top center prolonged to have the same z coordinate, as your point &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; and the point &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt;, i.e. they have the same angles&lt;span class=&quot;math-container&quot;&gt;$^2$&lt;/span&gt;. Therefore, you can now calculate the projected &lt;span class=&quot;math-container&quot;&gt;$p_x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p_y$&lt;/span&gt; coordinate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\frac{p_y}{d} = \frac{v_y}{v_z} \implies p_y = \frac{v_y\cdot d}{v_z} = \frac{v_y}{v_z \cdot \tan(\frac{\alpha}{2})}\\&#xA;\frac{p_x}{d} = \frac{v_x}{v_z} \implies p_x = \frac{v_x\cdot d}{v_z} = \frac{v_x}{v_x \cdot \tan(\frac{\alpha}{2})}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To additionally take into account, that the projection plane ranges from &lt;span class=&quot;math-container&quot;&gt;$-ar$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$ar$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; direction, you would add &lt;span class=&quot;math-container&quot;&gt;$ar$&lt;/span&gt; to the denominator in order to make the projected &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; range be &lt;span class=&quot;math-container&quot;&gt;$\left[-1, 1\right]$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;p_x = \frac{v_x}{ar \cdot v_x \cdot \tan(\frac{\alpha}{2})}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you think about applying this to a matrix now, you need to take into account the division by &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;, which is different for any point with differing &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; value. Therefore, the division by z is deferred until after the projection matrix is applied (and is done without any code of you, i.e. for OpenGL you'd specify the &lt;code&gt;gl_Position&lt;/code&gt; in Clip Space (&lt;span class=&quot;math-container&quot;&gt;$\implies$&lt;/span&gt; after projection) and the division is done for you).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The depth test (Z-Test) still needs the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; value though, so it needs to be &quot;safed&quot; from the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; divide. Therefore you copy your &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; value to the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component (which is what you got right in your assumption) and end up with the following matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\left(&#xA;\begin{array}{cccc}&#xA;\frac{1}{ar\cdot\tan(\frac{\alpha}{2})}&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;\frac{1}{\tan(\frac{\alpha}{2})}&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;1&amp;amp;0&#xA;\end{array}&#xA;\right)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next step is to not project onto a plane, but into a &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; range of &lt;span class=&quot;math-container&quot;&gt;$\left[-1, 1\right]$&lt;/span&gt; (this range is for correct clipping, as is the same range when handling the &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and the &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; coordinate). To be more specific, you don't want all points to end up in that range, but all points between your near and your far plane, so you map &lt;span class=&quot;math-container&quot;&gt;$[n, f]$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$[-1, 1]$&lt;/span&gt;.&#xA;The resulting range is &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt;, so you first scale your near-to-far range to &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt;. Then you move it to be &lt;span class=&quot;math-container&quot;&gt;$[-1, 1]$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;f(z) = A\cdot z + B&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And now taking into account that we want to safe the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; value from &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; divide, we get to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f(z) = A + \frac{B}{z}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mapping this scaling to &lt;span class=&quot;math-container&quot;&gt;$[-1, 1]$&lt;/span&gt; is a little bit of leg work: you know that any point with &lt;span class=&quot;math-container&quot;&gt;$z = n$&lt;/span&gt; (on your near plane) will be projected to &lt;span class=&quot;math-container&quot;&gt;$p_z = -1$&lt;/span&gt; and any point with &lt;span class=&quot;math-container&quot;&gt;$z = f$&lt;/span&gt; (on your far plane) will be projected to &lt;span class=&quot;math-container&quot;&gt;$p_z = 1$&lt;/span&gt;. This leads to the following equation system:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;A + \frac{B}{n} = -1\\&#xA;A + \frac{B}{f} = 1&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solving this for &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; leads to&lt;span class=&quot;math-container&quot;&gt;$^3$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;A = \frac{-n-f}{n-f}\\&#xA;B = \frac{2fn}{n-f}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your third row of the projection matrix must produced the (undivided) &lt;span class=&quot;math-container&quot;&gt;$p_z$&lt;/span&gt; (projected) z value. Therefore, you can now choose the individual elements of said row &lt;span class=&quot;math-container&quot;&gt;$(\begin{array}{cccc}a&amp;amp;b&amp;amp;c&amp;amp;d\end{array})$&lt;/span&gt; such that the correct &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; value is produced when multiplying with your point. The correct &lt;span class=&quot;math-container&quot;&gt;$p_z$&lt;/span&gt; value is (as established earlier):&#xA;&lt;span class=&quot;math-container&quot;&gt;$p_z = A\cdot z + B$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore this must be the right hand side of your multiplication. Assume your point to project is &lt;span class=&quot;math-container&quot;&gt;$(x, y, z, w)$&lt;/span&gt;, then &#xA;you must achieve the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;a \cdot x + b \cdot y + c \cdot z + d \cdot w = A \cdot z + B&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously, your point's &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; coordinate should not influence the projected &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; coordiante, so you can set &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;c \cdot z + d \cdot w = A \cdot z + B&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you know that &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; for any point is &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt;, you're left with&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;c \cdot z + d = A \cdot z + B&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And thus, you have &lt;span class=&quot;math-container&quot;&gt;$c = A$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$d = B$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now your matrix is complete for projection&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\left(&#xA;\begin{array}{cccc}&#xA;\frac{1}{ar\cdot\tan(\frac{\alpha}{2})}&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;\frac{1}{\tan(\frac{\alpha}{2})}&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;\frac{-n-f}{n-f}&amp;amp;\frac{2fn}{n-f}\\&#xA;0&amp;amp;0&amp;amp;1&amp;amp;0&#xA;\end{array}&#xA;\right)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously, the tutorial works a little differently in projecting with the vertical field of view, so we can take a look at how you can additionally get to that (with the help of &lt;a href=&quot;http://mathfor3dgameprogramming.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Eric Lengyel&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of projecting onto a plane at &lt;span class=&quot;math-container&quot;&gt;$z = d$&lt;/span&gt;, we will project onto the near plane, and thus get for a point &lt;span class=&quot;math-container&quot;&gt;$v = (v_x, v_y, v_z)$&lt;/span&gt; the projected point &lt;span class=&quot;math-container&quot;&gt;$p = (p_x, p_y, n)$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;p_x = \frac{v_x \cdot n}{v_z}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, you want to map any point with &lt;span class=&quot;math-container&quot;&gt;$l\leq x \leq r$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$\left[-1, 1\right]$&lt;/span&gt;, as before.&#xA;Thus you get &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f(x) = (x-l) \frac{2}{r-l}-1$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Combine those two and you achieve&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$p_x = \frac{2n}{r-l}\left(-\frac{v_x}{v_y}\right)- \frac{r+l}{r-l}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now put this (and the term for &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt;) into the matrix and you get to the first row, first column being  &lt;span class=&quot;math-container&quot;&gt;$\frac{2n}{r-l}$&lt;/span&gt;, and the first row, third column being &lt;span class=&quot;math-container&quot;&gt;$\frac{r+l}{r-l}$&lt;/span&gt;. Since you may assume &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; to be different, here you can see why those two matrices differ. &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; are guaranteed to be the same in the tutorial's matrix and therefore you get &lt;span class=&quot;math-container&quot;&gt;$r+l = ar-ar = 0$&lt;/span&gt; in the denominator, making the third row first column (and second column accordingly) &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt;Assuming you have Column-Major matrices like in OpenGL$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^2$&lt;/span&gt;For the &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; calculation, you will need to take a different point of your projection plane of course, but the idea is the same&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^3$&lt;/span&gt;The differences of the sign come from how you orient your camera: in your assumption it is along the negative &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; axis, whereas in the tutorial it is along the positive &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; axis&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2019-08-02T08:17:15.157" LastActivityDate="2019-08-02T08:17:15.157" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="6268" PostTypeId="1" CreationDate="2018-02-13T15:05:42.060" Score="-3" ViewCount="202" Body="&lt;p&gt;Why don't we just use an hash function to reduce the size of an bitmap,rgb raw image?isn't it more efficient of storage data and it produces lossless image after being decoded?The decoder is also very simple and they would use an universal standard hash code for all images,some private image would have its own hash code.It's an opportunity for us to compress a file to very low capacity without any complicated algorithm and entropy code?&lt;/p&gt;&#xA;" OwnerUserId="8204" LastActivityDate="2018-02-13T15:27:03.897" Title="why not use hash function image instead of jpeg?" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6269" PostTypeId="2" ParentId="6268" CreationDate="2018-02-13T15:27:03.897" Score="3" Body="&lt;p&gt;Unlike a &lt;em&gt;compression&lt;/em&gt; function, which can be reversed to recover (an approximation to) the original data, a &lt;em&gt;hash&lt;/em&gt; function is irreversible. You can hash your image, and the hash is a lot smaller than the original image, but you can't get the original image back from the hash.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A hash function &lt;em&gt;is&lt;/em&gt; useful for cases where there are only a small number of possible images, which everyone knows about. An example use-case might be something like Telegram or WhatsApp stickers, where there's a fixed set of images, and centrally assigning ID numbers causes distributed systems problems.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-02-13T15:27:03.897" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="6270" PostTypeId="2" ParentId="6180" CreationDate="2018-02-13T18:16:20.457" Score="1" Body="&lt;p&gt;When applying various types of attenuation you are just multiplying by some number smaller than 1.  This is akin to every atom of your material having some probability of absorbing the light that hits it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something to note is that these calculations should be performed ( in the context of &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Gamma_correction&quot; rel=&quot;nofollow noreferrer&quot;&gt;gamma correction&lt;/a&gt; and colour spaces ) in a linear space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't perform the calculations in linear space you might end up with overly bright, overly dark, overly saturated or under saturated colours.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-13T18:16:20.457" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6271" PostTypeId="1" CreationDate="2018-02-13T21:13:35.323" Score="1" ViewCount="1006" Body="&lt;p&gt;This question perhaps has been asked and answered a thousand times, and yet I haven't found any that satisfy me. The reasons are often these:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1/ You need a 4 dimensional vector to work with 4x4 matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2/ You need to have z stored in some way so that you could later use it for z-buffering, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3/ You need a matrix that is independent of z so that you could multiply matrices together and save computations. Instead of having to multiply each vector with each of the matrix, you could multiply 1 result matrix with each of the vector. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the problems I have with each of them.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;We can pretend that the 3 dimensional vector is 4 dimensional (imaginary w = 1). This is after all Computer Science, not math. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;When multiply matrices with vector, we don't need to crush z. Keep it and use it. When drawing, we can pretend that z is already crushed. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You will have to do division by w after projection matrix anyway. Why not divide by z then and get something like [x/z, y/z, z] (I'm not dividing by z because it will be used for z-buffering). Both of them cost 1 computation. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So why do we need homogenous divide?&lt;/p&gt;&#xA;" OwnerUserId="8191" LastActivityDate="2018-02-20T16:17:00.433" Title="What is the use of homogenous divide?" Tags="&lt;3d&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6273" PostTypeId="1" CreationDate="2018-02-13T23:14:24.200" Score="2" ViewCount="81" Body="&lt;p&gt;A long time ago I made an application that used volumetric rendering and I developed some shadowing equations that I felt very happy with, since they have pretty good results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For these equations to work one needs the object that occludes the light that is closest to the currently-being-shaded fragment (rather than the one closest to the light source)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, with shadow maps, you invariably get the first point that occludes the light, even if there are points behind it that also occlude the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had originally intended to use volumetric rendering over shadow maps and use clever hashing for optimization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But 800 triangles consume 90% of a GTX 1070's cpus power. In other words, just 800 triangle checks per fragment are enough to lag the entire pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wanted to know if there is a way to get the distance to the closest point occluding the light (from the fragment perspective) using shadow maps. Or if I have to give away with my pretty shadows&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I refer to distance I am speaking about distance from the occluded point to the light. So if A is a surface and R is the ray from that surface to the light, then the &quot;closest&quot; point is a point right on A and the &quot;farthest&quot; point is a point right on the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As per request, a poorly drawn diagram of what I mean. There are 2 walls occluding the light and one is closer to the shadow point than the other&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4L3u7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4L3u7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="5703" LastEditDate="2018-02-16T21:25:14.430" LastActivityDate="2018-02-16T21:25:14.430" Title="How can you efficiently get the last element occluding light when rendering shadows?" Tags="&lt;shadow&gt;&lt;shading&gt;&lt;shadow-mapping&gt;" AnswerCount="0" CommentCount="9" ContentLicense="CC BY-SA 3.0" />
  <row Id="6274" PostTypeId="2" ParentId="6271" CreationDate="2018-02-14T08:51:25.613" Score="1" Body="&lt;p&gt;Some very quick answers:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We can pretend that the 3 dimensional vector is 4 dimensional (imaginary w =1). This is after all Computer Science, not math. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Ahh.. but sometimes in graphics we don't have w=1. Some examples that come to mind are&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Placing a vertex at &quot;infinity&quot;, e.g. for shadow volumes &lt;/li&gt;&#xA;&lt;li&gt;Representing directions rather than absolute positions&lt;/li&gt;&#xA;&lt;li&gt;Doing rational curves. e.g. $\frac{Quadratic Bezier()}{Quadratic Bezier()}$ to represent, say, conic sections.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I'm sorry, I've no idea what you mean by &lt;em&gt;&quot;to crush z&quot;&lt;/em&gt;, but sometimes, if chosen carefully, after the projection transform you may be able to get by with just 3 terms, e.g. (X/W, Y/W, 1/W) assuming you also have the post-projection texture coordinates, (U/W, V/W).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I'm not dividing by z because it will be used for z-buffering&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Typically, despite the name, the Z-buffer contains an interpolated 1/W, 1/Z, or some linear function of one of these.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;-&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2018-02-14T08:51:25.613" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6275" PostTypeId="2" ParentId="6271" CreationDate="2018-02-14T11:23:27.570" Score="7" Body="&lt;p&gt;First of all we need to understand why do we need 4x4 matrices in the first place. With 3x3, we couldn't represent translation as it wasn't a linear transformation (it displaces the origin). So in order to avoid extra work, homogeneous coordinates and affine transformation was introduced. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now instead of doing&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$v' = Lv + t$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;L&lt;/code&gt; is a linear transform and &lt;code&gt;t&lt;/code&gt; is the translation, we can do&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$v' = Av$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;A&lt;/code&gt; is the affine matrix. This makes it cleaner. So 4x4 matrices are a real necessity, we just can't work without them. In order to distinguish between vectors and points we use &lt;code&gt;w = 1&lt;/code&gt; for points and &lt;code&gt;w = 0&lt;/code&gt; for vectors. So you are suggesting to make this 4th dimension implicit and don't store it as it'll actually use space/memory.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We can pretend that the 3 dimensional vector is 4 dimensional (imaginary w = 1). This is after all Computer Science, not math.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This works but up-to a certain extent. Using this approach we would have 4x4 matrices and 3 dimensional row/column vectors. But now when doing multiplication we will have to make a check whether it's point or vector and based on that we multiply the elements of the 4th column of the transformation matrix by &lt;code&gt;0&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This alone starts creating mess, check every time whether it's a point or a vector so why not just use the space for a single float more and get rid of this stupid check.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That aside most modern CPUs have SIMD registers 128 bits wide perfect to fit 4D vectors. If you are doing your calculations on the GPU, all the more reason to store 4D vectors as branching instructions are much more costly on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you start feeling the need to use 4D, great. If not then we still have the problem of composing matrix transformations. Instead of multiplying individual transformations with our vector we would like to pre-multiply all of the transformations then do a single vector-matrix multiplication. This can't work with projective transformations where we need to divide by &quot;something&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's come to reason number 3.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;You will have to do division by w after projection matrix anyway. Why not divide by z then and get something like [x/z, y/z, z]. Both of them cost 1 computation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is the simple case for just a projective transformation. Consider the vector going through 5 or 6 transformations  and in the last comes the projective transformation. If we pre-multiply all these transformation to create a single matrix, you will notice that now when we multiply the vector with this combined transformation matrix the division factor isn't just a simple &lt;code&gt;-z&lt;/code&gt; value. The 4th row of the matrix won't be &lt;code&gt;0 0 -1 0&lt;/code&gt; as in the standard projection matrix. It might have changed due to multiplying all the transformations together. Now when you multiply that 4th row with the 4D vector, you will get your &lt;code&gt;w&lt;/code&gt; value by which you need to divide now. &lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-02-14T11:23:27.570" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6278" PostTypeId="1" CreationDate="2018-02-14T18:02:32.777" Score="4" ViewCount="752" Body="&lt;p&gt;I have a quad-based 3D mesh. I want to:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;remesh it while keeping the shape the same&lt;/li&gt;&#xA;&lt;li&gt;the end output should be in quads&lt;/li&gt;&#xA;&lt;li&gt;ideally it should have a similar number of verts / polys as the input&lt;/li&gt;&#xA;&lt;li&gt;ideally the remeshing would be random, and output mesh would be distinct from the input&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Right now I'm remeshing with Meshlab, which outputs tris. I then use the Tris to Quads function from Blender. The problem is that that function is not perfect, and leaves many tris. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So ideally there'd be a quad-based random remesh tool, but if anyone knows of a better tri-to-quad tool that would also be helpful?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="7622" LastEditorUserId="7622" LastEditDate="2018-02-28T18:54:59.557" LastActivityDate="2018-10-05T17:57:53.560" Title="Best way to remesh a quad 3D mesh?" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6279" PostTypeId="2" ParentId="5933" CreationDate="2018-02-15T04:44:21.353" Score="1" Body="&lt;p&gt;After some testing and some research I have found that both the $\sin(\theta)$ and the $\cos(\theta)$ should be removed from the denominator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the reasoning is that, since we want a probability function of steradians instead of angles, the $\sin(\theta)$ factor (which is essentially used to convert from steradians on a unit sphere to radians on the two polar axis) should be dropped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, $\cos(\theta)$ (as Nathan Reed explains in &lt;a href=&quot;http://reedbeta.com/blog/hows-the-ndf-really-defined/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; blog post) is there to convert from microfacet area to macrosurface area. Since we are generating microsurface samples, this should be removed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After these corrections we get the formula&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o(p,\omega_o)\approx\frac{1}{N}\sum_{i=1}^{N}\frac{L_i(p,\omega_i)FG}{4(n\cdot\omega_o)}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is free of the artifacts of the formula on the question.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-15T04:44:21.353" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6280" PostTypeId="2" ParentId="6135" CreationDate="2018-02-15T06:16:06.530" Score="3" Body="&lt;p&gt;When implementing transmission into a path tracer you have to keep in mind that neither BRDF's nor your previous sampling method are gonna cut it. You will need to think about what happens to light on both sides of your surface, which is where BTDF's and, more generally, BSDF's come in (the T and the S stand for Transmittance and Scattering, respectively).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It can be somewhat non-trivial to implement transmission to a path tracer that currently only supports reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While i can't offer help with implementation details i can give you a few starting points and things you might want to read while you embarc on implementing this capabilty on your path tracer.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;On refraction.&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Pure and/or glossy refraction is a very common way of transmission, it is the type of transmission that happens on glass and probably what you are looking to implement.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Snell%27s_law&quot; rel=&quot;nofollow noreferrer&quot;&gt;Snell's Law.&lt;/a&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Light directions in refraction follow a simple mathematical law.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$n_1\sin(\theta_1)=n_2\sin(\theta_2)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;this reads as: the sine of the transmitted angle $\theta_2$ equals the sine of the incoming direction $\theta_1$ times the ratio of the &quot;outside&quot; &lt;a href=&quot;https://en.wikipedia.org/wiki/Refractive_index&quot; rel=&quot;nofollow noreferrer&quot;&gt;index of refraction&lt;/a&gt; and the &quot;inside&quot; index of refraction $\frac{n_1}{n_2}$&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;&lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;The GGX paper.&lt;/a&gt;&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;There is a wonderful paper titled &quot;Microfacet Models for Refraction through Rough Surfaces&quot; that goes over a good piece of the theory behind microfacet models for refraction and presents a really quite good model for it.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Fresnel and Monte-Carlo.&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;when rendering a material that has both reflective and transmissive components there are a few different approaches that you can take to mix the two.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;two main ways come to mind&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;1. The Monte-Carlo way&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Do a &quot;coin flip&quot; with probabilities weighted according to the calculated fresnel value for each rendered point. Depending on the result you do transmission or reflection&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;2. The recursive branching way&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Generate a reflected ray and path trace.&#xA;Generate a transmitted ray and path trace.&#xA;Mix the two found color values according to Fresnel value for every rendered point.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I really hope this information is of use in solving your issue, and good luck! Great to see new users on the site.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-15T06:16:06.530" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6281" PostTypeId="1" AcceptedAnswerId="6283" CreationDate="2018-02-15T14:57:45.743" Score="1" ViewCount="273" Body="&lt;p&gt;In my vertex shader I am using a &lt;code&gt;sin&lt;/code&gt; function to offset vertices. But as I change the frequency of my &lt;code&gt;sin&lt;/code&gt; function I notice some &quot;flickering&quot; or &quot;jumps&quot;. I guess that this comes from the fact that the phase is not synchronised any more.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float s = sin(frequency * _Time);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there a way to avoid those flickering effect while changing the frequency ?&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2018-02-15T16:37:13.300" Title="Changing sin frequency smoothly in shader" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;mathematics&gt;&lt;hlsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6283" PostTypeId="2" ParentId="6281" CreationDate="2018-02-15T16:37:13.300" Score="3" Body="&lt;p&gt;You could go the calculus way and have an explicit rate of change that is outside your shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float frequency = getFrequency();&#xA;sineTime += frequency * deltaTime;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(&lt;code&gt;sineTime&lt;/code&gt; could be a float that is scoped right outside of your render loop, so that it retains its value)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if you pass &lt;code&gt;sineTime&lt;/code&gt; into your shader you can just do&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float s = sin(sineTime);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-15T16:37:13.300" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6284" PostTypeId="1" AcceptedAnswerId="6287" CreationDate="2018-02-15T18:08:40.973" Score="2" ViewCount="3060" Body="&lt;p&gt;So I want to implement a path tracer and I am confused between GPGPU computing or using OpenGL's compute shaders. I've already implemented a raytracer using GL's compute shaders. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the main differences between CUDA/OpenCL and CS? And is it possible to see a significant speed up if I prefer one over the other? Some main differences I already know are that using CS will make it vendor independent so I could run it on PCs having Nvidia/Amd GPUs alike. CUDA supports recursion while openCL/opengl CS don't. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are other significant functionalities that would make a person prefer opencl/cuda over CS?&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-02-16T23:31:19.157" Title="CUDA/OpenCL vs OpenGL compute shader for Path tracer" Tags="&lt;compute-shader&gt;&lt;opencl&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6285" PostTypeId="1" AcceptedAnswerId="6286" CreationDate="2018-02-16T11:28:38.973" Score="0" ViewCount="490" Body="&lt;p&gt;I am trying to scale and repeat a Cubemap with Latitude-Longitude mapping layout just as you would do with classical UV mapping but without any interesting result. This should be used as a skybox.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This comes from the fact that the coordinates are in 3D space and we can't apply this simple formula &lt;code&gt;texcoord.xy * scale.xy + offset.xy&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How would you handle such features : scaling which involves tiling and offsetting.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;samplerCUBE _TexCube;&#xA;texCUBE(_TexCube, float3);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2018-02-16T12:53:17.267" Title="How to scale and offset a cubemap using sphere mapping" Tags="&lt;texture&gt;&lt;shader&gt;&lt;glsl&gt;&lt;hlsl&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6286" PostTypeId="2" ParentId="6285" CreationDate="2018-02-16T12:53:17.267" Score="0" Body="&lt;p&gt;This doesn't really answer the question but is a workaround. Beware it's hack time :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of using the &lt;code&gt;texCUBE&lt;/code&gt; and &lt;code&gt;samplerCube&lt;/code&gt; I'll be using the &lt;code&gt;tex2D&lt;/code&gt; method and a simple &lt;code&gt;sampler&lt;/code&gt; to sample the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I am using a sphere mesh, I generate 2D UVs like this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float x = atan2(vertex.x, vertex.z) / PI;&#xA;x = x / 2.0 + 0.5; // To remap from 0 to 1&#xA;float y = vertex.y / 2.0 + 0.5; // Also remap from 0 to 1&#xA;float3 color = tex2D(sampler, float2(x, y) * scale.xy + offset.xy);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It's a bit hacky but using this I have 2D texture coordinates for my texture.&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2018-02-16T12:53:17.267" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6287" PostTypeId="2" ParentId="6284" CreationDate="2018-02-16T23:31:19.157" Score="4" Body="&lt;p&gt;To first clear your confusion around the terms:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPGPU stands for &lt;strong&gt;G&lt;/strong&gt;eneral &lt;strong&gt;P&lt;/strong&gt;urpose computing on GPUs&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;CUDA&lt;/strong&gt; is the specific NVIDIA API to perform GPGPU only on their hardware&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;OpenGL&lt;/strong&gt; is a graphics specific API and is vendor independent&lt;br&gt;&#xA;&lt;strong&gt;OpenCL&lt;/strong&gt; is a parallel programming compute API and is vendor independent&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Compute Shaders&lt;/strong&gt; are a way to perform general purpose computations within&lt;br&gt;&#xA;a rendering system but without being part of a fixed rendering architecture.&lt;br&gt;&#xA;They exist for OpenGL (&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Compute_Shader&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengl/wiki/Compute_Shader&lt;/a&gt;)&lt;br&gt;&#xA;but also for other graphics APIs like DirectX (DirectCompute) etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenCL is not only built for GPUs and can also be used to write code&lt;br&gt;&#xA;for example to run massive parallel computations on supercomputers. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;NVIDIA develops their own ray tracer based on CUDA and GPU computing.&lt;br&gt;&#xA;The project is called Optix (&lt;a href=&quot;https://developer.nvidia.com/optix&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/optix&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To your performance question. It depends, as always on your setup and use case.&lt;br&gt;&#xA;Some people did already the effort to measure differences. &#xA;One paper for example is this:&#xA;&lt;a href=&quot;https://arxiv.org/ftp/arxiv/papers/1005/1005.2581.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://arxiv.org/ftp/arxiv/papers/1005/1005.2581.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another one is this:&#xA;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2066955&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://dl.acm.org/citation.cfm?id=2066955&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or one thesis about it:&#xA;&lt;a href=&quot;https://liu.diva-portal.org/smash/get/diva2:909410/FULLTEXT01.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://liu.diva-portal.org/smash/get/diva2:909410/FULLTEXT01.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In their comparisons did CUDA often show good results. But when they for example used image processing algorithms that can be parallized very efficiently from the GPU then the comparison is nearly worthless compared what you might do in your path tracing code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do not use any &quot;classic&quot; rendering, which you wanna combine your path traced results, I see not why you should use compute shaders for a pure path tracer. If platform independence is important OpenCL might be interesting for you since you then can take the code and run it on a complete other hardware for comparison. If you will stick to NVIDIA GPUs anyways you will likely get better performance using directly CUDA.&lt;/p&gt;&#xA;" OwnerUserId="8222" LastActivityDate="2018-02-16T23:31:19.157" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6288" PostTypeId="2" ParentId="6012" CreationDate="2018-02-17T16:21:31.047" Score="1" Body="&lt;p&gt;Not sure if Ogre does it implicitely, but using a 4x4 matrix to transform a 3D point to get the correct 2D coordinates (as it would be rendered with the same matrix),  requires a transition from homogeneous coordinates by dividing the result by w. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, you must multiply the matrix by a 4-component vector (x,y,z,1.0f) instead of a 3-component vector. And then the resulting vector will look like (X,Y,Z,W) and you need to divide by W to get the position like it would be rendered. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Like this: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Transform world coordinates.&#xA;Ogre::Vector4 transformedWorldPosition = worldViewProjection * Ogre::Vector4(worldPosition,1.0);&#xA;&#xA;//Divide by w &#xA;transformedWorldPosition = transformedWorldPosition / transformedWorldPosition.w; &#xA;&#xA;// Calculate screen coordinates from world coordinates.&#xA;Ogre::Vector2 screenPosition;&#xA;screenPosition.x = (int) ( ( ( transformedWorldPosition.x + 1 ) / 2.0 ) * screenRes.width + 0.5 );&#xA;screenPosition.y = (int) ( ( ( 1 - transformedWorldPosition.y ) / 2.0 ) * screenRes.height + 0.5 );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8118" LastActivityDate="2018-02-17T16:21:31.047" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6289" PostTypeId="1" AcceptedAnswerId="6293" CreationDate="2018-02-17T20:29:55.617" Score="1" ViewCount="222" Body="&lt;p&gt;I am writing a simple ray tracer. I was working on my camera matrix when I encountered a problem. When I changed the look vector, so that it headed down, the image, which was supposed to go up, actually went down as well. Likewise, if I changed the look vector so that it headed up, the image went with it.&#xA;I understand that the camera matrix's job is to change world coordinate into eye coordinate. Since I am using column matrices, here's my camera matrix, with $r$ being right vector, $l$ being lookAt vector and $u$ being up vector&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;r_x &amp;amp; u_x &amp;amp; -l_x &amp;amp; 0 \\&#xA;r_y &amp;amp; u_y &amp;amp; -l_y &amp;amp; 0 \\&#xA;r_z &amp;amp; u_z &amp;amp; -l_z &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the transpose of the gluLookAt matrix of openGL. I dont understand why openGL use their matrix though, since they are also using column matrices. &lt;/p&gt;&#xA;" OwnerUserId="8191" LastEditorUserId="48" LastEditDate="2018-02-17T23:13:36.213" LastActivityDate="2018-08-09T15:44:47.723" Title="Is there something wrong with a column camera matrix?" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;camera-matrix&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6290" PostTypeId="2" ParentId="6289" CreationDate="2018-02-17T23:27:20.947" Score="1" Body="&lt;p&gt;What you have there is the matrix that goes &lt;em&gt;from&lt;/em&gt; eye space (camera space) &lt;em&gt;to&lt;/em&gt; world space. You can see this by observing that, for instance, if you apply this matrix to the column vector $[1, 0, 0, 0]^T$, which is the right-vector in eye space, then it will return $[r_x, r_y, r_z, 0]^T$, the right-vector in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You want the matrix that transforms the other direction, which would be the inverse of this one. And assuming $r, u, l$ form an orthonormal basis, the inverse will simply be the transpose.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-02-17T23:27:20.947" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6291" PostTypeId="1" CreationDate="2018-02-18T15:43:14.983" Score="1" ViewCount="1049" Body="&lt;p&gt;I'm rendering transparent objects in separate framebuffer then compositing it with opaque one to get final image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The transparent pass has additive blending:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBlendFunci(0, GL_ONE,  GL_ONE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;so transpareny seems work perfect (I used weighted, blended OIT). Now I have problem if I set all surfaces' alpha to &lt;strong&gt;1&lt;/strong&gt;. Transparency works if alpha is between 0 and &amp;lt; 1 but not work as expected if alpha = 1. In this case (alpha=1) transparency surface seems opaque on opaque surface[s], but it also appears as semi-transparent on transparent surface[s].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think additive blending causes this issue/artifact, how can I fix this? I want to transparent surfaces appear opaque if alpha is set to 1 in fragment shader. I can't disable blending because it will disable whole transparency process. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I want to do is control blending in fragment shader or per-fragment blending; is this possible? Overriding old values of some fragments in framebuff e.g. to zero (0,0,0,0) could also help to fix/control blending, because I can put some values in blend equation to get what I want. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm asking this because maybe there is a way to simulate this which I don't know yet. Maybe I can fix this with another rendering passes/targets, I will give a try, any help would be appreciated  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first image is rendered with alpha = 0.5 and the second one is rendered with alpha = 1.0. As you can see transparency is still active among transparent objects. The pink plane overrides Suzanne mesh and bottom plane but not sphere :( Both sphere and pink plane are rendered in transparency pass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/c2uGw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c2uGw.png&quot; alt=&quot;Alpha = 0.5&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Wa8Kq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wa8Kq.png&quot; alt=&quot;Alpha = 1.0&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6929" LastEditorUserId="6929" LastEditDate="2018-02-18T19:18:06.013" LastActivityDate="2018-06-19T01:28:51.843" Title="Is it possible to override or disable blending per pixel" Tags="&lt;opengl&gt;&lt;transparency&gt;&lt;fragment-shader&gt;&lt;blending&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="6292" PostTypeId="2" ParentId="6291" CreationDate="2018-02-18T23:16:46.410" Score="2" Body="&lt;p&gt;You seem to be using additive blending against its purpose. Additive blending is supposed to represent light from multiple sources being combined. It is not physically possible for one source of light to eclipse another.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, even if you hack an alpha of exactly 1 to mean &quot;opaque&quot;, you will get a strange circumstance where an alpha of 0.99 is quite far from &quot;nearly opaque&quot;. So if you're animating &quot;opacity&quot;, then you're going to get a sudden jump from appearing to be transparent to completely opaque.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, opacity with blending can &lt;em&gt;only&lt;/em&gt; be achieved if you render the objects in the correct &lt;em&gt;order&lt;/em&gt;. So even if you use this hack on the pink square, it will only eclipse the sphere if the sphere is rendered before the square. Using this hack will lose you the order-independency of additive blending.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That last part makes what you want essentially impossible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you wish to persist in this, there is a way to do what you've asked for. You need to use &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Dual_Source_Blending&quot; rel=&quot;nofollow noreferrer&quot;&gt;dual-source blending&lt;/a&gt; (which means you can only be rendering to a single render target). This is a technique whereby you output two values from the FS to the same render target:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(location = 0, index = 0) out vec4 outputColor0;&#xA;layout(location = 0, index = 1) out vec4 outputColor1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Both values can be used in the blending equation. This means there are two source colors. The &lt;code&gt;index&lt;/code&gt; zero source color is the source color used directly in the additive blending equation. The &lt;code&gt;index&lt;/code&gt; one source color is how you turn off the destination color and achieve opacity:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBlendFunci(0, GL_ONE,  GL_SRC1_ALPHA);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With this blend function, if you want a fragment shader's output to be opaque, you set &lt;code&gt;outputColor1.a&lt;/code&gt; to 0. Otherwise you set it to 1. The other components are irrelevant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, you must still suffer the limitations of dual-source blending. Namely, that you can only render to a single render target on most hardware.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-02-18T23:16:46.410" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6293" PostTypeId="2" ParentId="6289" CreationDate="2018-02-19T09:11:43.233" Score="1" Body="&lt;p&gt;It was getting a little big to fit in the comments so posting it as an answer instead. Might not be a solution to your problem but the concept is related.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;People usually forget that whenever you define a transformation matrix by placing respective basis vectors in respective columns, you are specifying that with respect to another basis usually the right-handed or left handed world coordinate space. For example your above matrix&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{bmatrix}&#xA;r_x &amp;amp; u_x &amp;amp; -l_x &amp;amp; 0 \\&#xA;r_y &amp;amp; u_y &amp;amp; -l_y &amp;amp; 0 \\&#xA;r_z &amp;amp; u_z &amp;amp; -l_z &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Reason why you put &lt;code&gt;-&lt;/code&gt; sign in the third column is you are working with a right handed coordinate system and the camera is looking in the negative direction (the -Z axis). So all these basis vectors are also with respect to another basis vector. &lt;strong&gt;This means your camera's Z axis is actually the negative of the viewing direction.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's make this matrix simple so we can understand what happens when we multiply a matrix with a vector. Let the matrix $M$ be &#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The above matrix is wrong. The correct one is,&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is your camera initially without any rotation/translation etc. &lt;strike&gt;This means your camera space $+Z$ axis maps to world space $-Z$ axis. Now consider a camera space coordinate $[2,3,6,0]^T$. Multiplying this vector by the matrix gives you $[2,3,-6,0]^T$. This is the world space representation of $[2,3,6,0]^T$.&lt;/strike&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Actually after clearing my concepts a little more, Both the camera space and the world space are aligned for Right handed coordinate systems. This means the &lt;code&gt;X,Y,Z&lt;/code&gt; axis of world space align with &lt;code&gt;X,Y,Z&lt;/code&gt; of the camera space.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 3rd column of the matrix actually points to $-V_{dir}$ which basically says &quot;The Z-axis of the camera space is negative of the viewing direction&quot;. Since &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$V_{dir} = [0,0,-1]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The negative of it is simply the positive $Z$ axis. This means, points/vectors in world space remains the same as in camera space (when camera is at initial position)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So as Nathan pointed your matrix transforms from camera space to world space. To do the inverse we just take the inverse of the matrix which is the transpose if the basis is ortho-normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of the reasons the transformation matrix is built this way is because it's much easier. It's easier to think about the transformed basis vectors of camera or any other space with respect to the world, write the matrix then invert it to go from the world space to that target space.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-08-09T15:44:47.723" LastActivityDate="2018-08-09T15:44:47.723" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="6296" PostTypeId="1" AcceptedAnswerId="6298" CreationDate="2018-02-19T16:47:36.650" Score="2" ViewCount="53" Body="&lt;p&gt;I am learning GLSL and want to raytrace a sphere. I am rendering rectangles which sit between the camera and sphere, and do a ray-sphere intersection test in the fragment shader. It almost works:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/72env.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/72env.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the rectangles are a little too small. Here is how I calculated them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/L8gJB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/L8gJB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Point $C$ is the centre of the rectangle, a distance $R$ from the radius of the sphere. Taking basis vectors $i,j$ I can construct the corners as $C+(\pm i, \pm j)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Point $C$ is a fraction $1-\frac{R}{||V||}$ along the vector $V$ from the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can direct $i$ and $j$ given the vector $V$ and the &quot;up&quot; vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How long should $i$ and $j$ be? By similar triangles, they should have length $R\times (1-\frac{R}{||V||})$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the code (I'm new to GLSL so please ignore bad habits, for now I just want to get the geometry right).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A vertex array containing four $(\pm 1, \pm 1, 0)$ vectors forms a triangle strip.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;in  vec2 position;&#xA;out vec3 vs_fs_position;&#xA;&#xA;uniform vec3 i;&#xA;uniform vec3 j;&#xA;uniform vec3 centre;&#xA;&#xA;uniform mat4 pvm; // projection * view * model&#xA;&#xA;void main ()&#xA;{&#xA;    vec3 p = centre + position.x * i + position.y * j;&#xA;&#xA;    vs_fs_position = p; // world space coordinate sent to fragment&#xA;&#xA;    gl_Position = pvm * vec4 (p, 1); // to screen space&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The fragment shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;precision mediump float;&#xA;out mediump vec4 out_colour;&#xA;in  mediump vec3 vs_fs_position;&#xA;&#xA;uniform mediump vec3 camera_position;&#xA;uniform mediump vec3 camera_to_sphere;&#xA;uniform float radius;&#xA;&#xA;void main ()&#xA;{&#xA;    vec3 direction = vs_fs_position - camera_position;&#xA;&#xA;    float A = dot (direction, direction);&#xA;    float B = 2.0 * dot (direction, camera_to_sphere);&#xA;    float C = dot (camera_to_sphere, camera_to_sphere)&#xA;            - radius * radius;&#xA;&#xA;    float det = B * B - 4.0 * A * C;&#xA;&#xA;    if (det &amp;lt; 0.0)&#xA;        out_colour = vec4 (0.0, 0.0, 0.0, 1.0);&#xA;    else&#xA;        out_colour = vec4 (0.5, 0.5, 0.5, 1.0);&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Some C++ to draw it&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;shader .camera_position = m_camera_position;&#xA;&#xA;const float EPSILON = 0.0;&#xA;&#xA;for (auto &amp;amp; s : SPHERES)&#xA;{&#xA;    auto R = s .position - m_camera_position;&#xA;&#xA;    float ratio = 1.0 - (s .radius + EPSILON) / length (R);&#xA;&#xA;    float width = ratio * s .radius;&#xA;&#xA;    auto &amp;amp; up = m_camera_up;&#xA;&#xA;    const float W = width * (1 + EPSILON);&#xA;&#xA;    glm :: vec3 i = normalize (cross (up, R)) * W;&#xA;    glm :: vec3 j = normalize (cross (R,  i)) * W;&#xA;&#xA;    shader .i = i;&#xA;    shader .j = j;&#xA;&#xA;    shader .centre = s .position;&#xA;    shader .radius = s .radius;&#xA;&#xA;    shader .camera_to_sphere = s .position - m_camera_position;&#xA;&#xA;    glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If it runs with &lt;code&gt;EPSILON=0.5&lt;/code&gt;, I get this output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gdFdL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gdFdL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Theoretically, I should be able to get a perfect fit with &lt;code&gt;EPSILON=0&lt;/code&gt;, that way I can be confident it will work at all scales/positions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's wrong with my calculation of the &lt;code&gt;width&lt;/code&gt; parameter?&lt;/p&gt;&#xA;" OwnerUserId="8233" LastActivityDate="2018-02-19T20:06:16.347" Title="calculating size of rectangle which fully obscures a sphere" Tags="&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6298" PostTypeId="2" ParentId="6296" CreationDate="2018-02-19T18:38:55.863" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;How long should $i$ and $j$ be? By similar triangles, they should have length $R\times (1-\frac{R}{\lVert V\rVert})$.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I believe this is where you went wrong. If you draw the 2D version of this on a sheet of paper, it will be obvious that the edge of your triangle which touches the side of your square goes through the sphere. More so as the camera comes closer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That line needs to be tangent to the sphere. So your large similar triangle will have its right angle at the contact point with the sphere, not at the sphere's center as you did. If my trigonometry is not too rusty, this gives&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\frac{R}{\sqrt{\lVert V\rVert^2-R^2}} \times \left(\lVert V\rVert-R\right)$&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2018-02-19T20:06:16.347" LastActivityDate="2018-02-19T20:06:16.347" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6299" PostTypeId="1" CreationDate="2018-02-19T21:10:02.260" Score="1" ViewCount="1268" Body="&lt;p&gt;I'm aware that it's technically possible to connect a large number of GPUs to a PC for mining purposes &lt;a href=&quot;https://www.pcgamer.com/asus-has-a-motherboard-that-supports-up-to-19-gpus/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.pcgamer.com/asus-has-a-motherboard-that-supports-up-to-19-gpus/&lt;/a&gt;, but how many of these can actually be used simultaneously for graphics output?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if I wanted to use these all independently for a CAVE &lt;a href=&quot;https://en.wikipedia.org/wiki/Cave_automatic_virtual_environment&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Cave_automatic_virtual_environment&lt;/a&gt; like system, where each GPU will render its own independent view to its own monitor. There should be very little interaction between GPUs. Is there some limitation of the OS, or graphics driver that would prevent me from doing this with more than something like four cards?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be clear, I'm not interested in anything like SLI here, just using each GPU independently from a single application (think split screen rendering, but each player having their own monitor). I'm currently experimenting with this from Vulkan with two GPUs, but the graphics API isn't important to me if that puts some limit on this. I'm just curious what the upper limit is for this kind of setup.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an older example of the kind of system I have in mind: &lt;a href=&quot;https://www.jvrb.org/past-issues/9.2012/3511&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.jvrb.org/past-issues/9.2012/3511&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7385" LastActivityDate="2018-02-19T22:18:17.177" Title="How many GPUs can you simultaneously output from using a single PC?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6300" PostTypeId="2" ParentId="6299" CreationDate="2018-02-19T22:18:17.177" Score="3" Body="&lt;p&gt;I don't think there are any specific limits. Each GPU can probably drive three or four monitors, and with multiple GPUs in a system, I don't think there's any barrier to hooking up the maximum number of monitors to each GPU. &lt;a href=&quot;https://youtu.be/nthOpo5tQDk?t=321&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here's a video&lt;/a&gt;, for instance, detailing a 16-monitor machine with 4 GPUs, on Windows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Googling around, I did find some people stating that Windows has a 16-monitor or 64-monitor overall limit, but I couldn't verify this from any official documentation. I also saw some claims that Windows has a limit on the overall desktop size that the monitors are virtually placed within, but again could not verify that. In Linux any such limits (if they exist) would naturally be different, and presumably would depend on which window system you're using.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other potential limiting factor would be CPU performance and PCIe bus bandwidth for keeping all those GPUs fed with data.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-02-19T22:18:17.177" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6301" PostTypeId="1" AcceptedAnswerId="6302" CreationDate="2018-02-19T22:55:43.323" Score="0" ViewCount="223" Body="&lt;p&gt;I am learning GLSL and trying to raytrace a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a fragment shader. It correctly discards fragments which are not on the sphere, but when I try to calculate the point of intersection (and hence, the normal), I get nonsense.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;precision mediump float;&#xA;out mediump vec4 out_colour;&#xA;&#xA;in  mediump vec3 X;      // intersection of ray with polygon&#xA;&#xA;uniform mediump vec3 C;  // camera position&#xA;uniform mediump vec3 CS; // sphere position - camera position&#xA;uniform         float r; // sphere radius&#xA;&#xA;void main ()&#xA;{&#xA;    vec3 CX = X - C;&#xA;&#xA;    // |t.CX-CS|=r, CX.CX.t.t - 2.CS.CX.t + CS.CS - r.r = 0&#xA;&#xA;    float a = dot (CX, CX);&#xA;    float b = -2.0 * dot (CX, CS);&#xA;    float c = dot (CS, CS) - r * r;&#xA;&#xA;    float det = b * b - 4.0 * a * c;&#xA;&#xA;    if (det &amp;lt; 0.0)&#xA;        discard;&#xA;&#xA;    float t = (-b - sqrt (det)) / 2.0 * a;&#xA;&#xA;    if (t &amp;lt;= 0.0)&#xA;        discard;&#xA;&#xA;    vec3 N = normalize (t * CX - CS);&#xA;&#xA;    out_colour = vec4 (N, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here's an illustration of the variable names&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/m2gPL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/m2gPL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was expecting the normals to be illustrated with a wide-ranging rgb colour across the sphere, but as you can see...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XlwR9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XlwR9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What went wrong?&lt;/p&gt;&#xA;" OwnerUserId="8233" LastActivityDate="2018-02-20T06:10:25.333" Title="What's wrong with my computation of the intersection of a ray with a sphere" Tags="&lt;raytracing&gt;&lt;glsl&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6302" PostTypeId="2" ParentId="6301" CreationDate="2018-02-20T05:32:56.110" Score="2" Body="&lt;p&gt;This line doesn't look quite right:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float t = (-b - sqrt (det)) / 2.0 * a;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You're missing parentheses around &lt;code&gt;(2.0 * a)&lt;/code&gt;. Remember that multiplication and division have equal operator precedence, so the expression as it's currently written means &lt;code&gt;((-b - sqrt (det)) / 2.0) * a&lt;/code&gt;, putting the &lt;code&gt;a&lt;/code&gt; in the numerator instead of the denominator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Oh and this is a nitpick, but the thing you named &lt;code&gt;det&lt;/code&gt; is called a “discriminant”, not a determinant.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2018-02-20T06:10:25.333" LastActivityDate="2018-02-20T06:10:25.333" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6303" PostTypeId="1" CreationDate="2018-02-20T15:27:20.117" Score="0" ViewCount="262" Body="&lt;p&gt;I am implementing a water simulation program using OpenGL. However I could not decide which technique to use for reflection and refraction. The water is wavy and there are dynamic objects around the water.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I considered dynamic environment mapping. However, it seems that it is not quite suitable for small environment, because the close objects are not reflected correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, I considered SSR technique, but it does not reflect non visible objects and because realism is more important than performance for this project I gave up on SSR.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any other good algorithms to do reflection and refraction?&lt;/p&gt;&#xA;" OwnerUserId="8235" LastActivityDate="2018-02-20T15:27:20.117" Title="What is a good way to do reflection and refraction in small environment for bumpy planar surface?" Tags="&lt;opengl&gt;&lt;reflection&gt;&lt;refraction&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6304" PostTypeId="2" ParentId="6271" CreationDate="2018-02-20T16:17:00.433" Score="0" Body="&lt;p&gt;We use projective geometry and homogeneous coordinates so that we can make use of &lt;strong&gt;linear algebra&lt;/strong&gt; to do our transformations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And by the way, this &lt;strong&gt;is&lt;/strong&gt; math.  I think you should read wikipedia's pages about &lt;a href=&quot;https://en.wikipedia.org/wiki/Projective_geometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;Projective Geometry&lt;/a&gt;, and the clever idea to introduce a &lt;a href=&quot;https://en.wikipedia.org/wiki/Point_at_infinity&quot; rel=&quot;nofollow noreferrer&quot;&gt;Point at Infinity&lt;/a&gt;, and use &lt;a href=&quot;https://en.wikipedia.org/wiki/Homogeneous_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;Homogeneous Coordiantes&lt;/a&gt; to allow you to deal with projective geometry transformations using &lt;strong&gt;linear algebra&lt;/strong&gt; as opposed to dealing with the ugly math required to do transformations after the divide (because projections are non-linear).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At some point, you must divide though, so this technique is a way of deferring that divide to the very end.  All the other transformations can be dealt with in a linear fashion with nice simple matrices and such - even though we are dealing with projection.  In terms of OpenGL (and others) we only divide when we go from &lt;em&gt;Clip Space&lt;/em&gt; to &lt;em&gt;Normalized Device Space&lt;/em&gt; - long after all the 3D transformations have been applied.&lt;/p&gt;&#xA;" OwnerUserId="8009" LastActivityDate="2018-02-20T16:17:00.433" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6305" PostTypeId="1" CreationDate="2018-02-21T04:22:55.307" Score="0" ViewCount="169" Body="&lt;p&gt;I don't even know where to start. So far, the only progress I have gotten is checking the z value of each vertex of each triangle. If all three vertices' z values &gt; absolute value of far or &amp;lt; absolute value of near, then I dont draw that triangle. It seems wrong somehow, though I dont get why. &#xA;Im using the right hand rule, if that info is necessary. &lt;/p&gt;&#xA;" OwnerUserId="8191" LastEditorUserId="8191" LastEditDate="2018-02-21T04:34:51.373" LastActivityDate="2018-02-21T04:34:51.373" Title="How to do clipping in camera space?" Tags="&lt;3d&gt;&lt;clipping&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6307" PostTypeId="1" CreationDate="2018-02-21T12:55:28.560" Score="0" ViewCount="618" Body="&lt;p&gt;I am rendering the sun in an image, and the sun comes out white and is basically very unrealistic. I have tried searching for  tone mapping algorithms but I'm very lost. Can someone guide me to do this? or perhaps help me with the pseudo&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IqqlS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IqqlS.png&quot; alt=&quot;Sun&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8242" LastEditorUserId="8242" LastEditDate="2018-02-21T17:50:28.013" LastActivityDate="2018-02-21T17:50:28.013" Title="Tone mapping bright images" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6308" PostTypeId="1" AcceptedAnswerId="6309" CreationDate="2018-02-21T14:29:11.357" Score="3" ViewCount="1525" Body="&lt;p&gt;I am raytracing in GLSL. My &lt;code&gt;gl_FragDepth&lt;/code&gt; calculation wasn't right, so I did some hunting and found this solution (&lt;code&gt;P&lt;/code&gt; is the world-space coordinate of the pixel and &lt;code&gt;pv&lt;/code&gt; is proj*view):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    vec4 Pclip = pv * vec4 (P, 1);&#xA;&#xA;    float ndc_depth = Pclip.z / Pclip.w;&#xA;&#xA;    gl_FragDepth = (&#xA;        (gl_DepthRange.diff * ndc_depth) +&#xA;        gl_DepthRange.near + gl_DepthRange.far) / 2.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It works. But why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Okay, so I need to divide by &lt;code&gt;w&lt;/code&gt; and scale it to the expected z-range. That makes sense qualitatively, but the calculation surprised me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you told me to &quot;divide by &lt;code&gt;w&lt;/code&gt; and scale to &lt;code&gt;gl_DepthRange&lt;/code&gt;&quot; I would have written&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float ndc_depth = Pclip.z / Pclip.w;&#xA;&#xA;gl_FragDepth = gl_DepthRange.diff * ndc_depth + glDepthRange.near;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;At this point I'd like to point out that this depth calculation looks correct with the raytraced geometry which is intersecting with my normal triangle models, so I guess OpenGL is performing the same depth-scaling implicitly for those triangles as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Three questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Why add &lt;code&gt;gl_DepthRange.far&lt;/code&gt; to the calculation?&lt;/li&gt;&#xA;&lt;li&gt;Why divide by 2?&lt;/li&gt;&#xA;&lt;li&gt;I set the &lt;code&gt;pv&lt;/code&gt; matrix in C++ with &lt;code&gt;glm::perspective(...)*glm::lookAt(...)&lt;/code&gt; so how the hell does &lt;code&gt;gl_DepthRange&lt;/code&gt; know what the near and far planes are?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="8233" LastActivityDate="2019-08-27T08:28:16.433" Title="Why does this gl_FragDepth calculation work?" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6309" PostTypeId="2" ParentId="6308" CreationDate="2018-02-21T15:08:41.313" Score="3" Body="&lt;p&gt;What you are missing is, that in OpenGL's NDC space (i.e. clip space after division by &lt;code&gt;w&lt;/code&gt;) all 3 coordinates are in the range &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt;. So &lt;strong&gt;&lt;code&gt;ndc_depth&lt;/code&gt; is in the range &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt;&lt;/strong&gt;, while your computation assumes a range of &lt;span class=&quot;math-container&quot;&gt;$[0,1]$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So let's take your computation but add an initial step to map &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$[0,1]$&lt;/span&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float ndc_depth = Pclip.z / Pclip.w;&#xA;float win_depth = (ndc_depth + 1.0) / 2.0;&#xA;gl_FragDepth = gl_DepthRange.diff * win_depth + gl_DepthRange.near;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If we do some transformations (and realizing that &lt;code&gt;gl_DepthRange.diff&lt;/code&gt; is just convenience for &lt;code&gt;gl_DepthRange.far - gl_DepthRange.near&lt;/code&gt;), we get&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;gl_FragDepth = gl_DepthRange.diff * (ndc_depth + 1.0) / 2.0 + gl_DepthRange.near;&#xA;&#xA;gl_FragDepth = (gl_DepthRange.diff * ndc_depth + gl_DepthRange.diff) / 2.0 &#xA;               + gl_DepthRange.near;&#xA;&#xA;gl_FragDepth = (gl_DepthRange.diff * ndc_depth + gl_DepthRange.diff + &#xA;                2.0 * gl_DepthRange.near) / 2.0;&#xA;&#xA;gl_FragDepth = (gl_DepthRange.diff * ndc_depth + &#xA;                gl_DepthRange.far - gl_DepthRange.near + 2.0 * gl_DepthRange.near) / 2.0;&#xA;&#xA;gl_FragDepth = (gl_DepthRange.diff * ndc_depth + &#xA;                gl_DepthRange.far + gl_DepthRange.near) / 2.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So, to answer your specfic questions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;That's just a result from simplifying the calculation based on the fact that &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Built-in_Variable_(GLSL)#Shader_uniforms&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;gl_DepthRange.diff&lt;/code&gt; is nothing else than &lt;code&gt;gl_DepthRange.far - gl_DepthRange.near&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Because the depth range in NDC space is &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt;, which has a width of &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;It doesn't. These values have nothing to do with the near and far values you used to construct your projection matrix, in fact you could use any arbitrary projection matrix (or none at all). They are the depth range values set with &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDepthRange.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glDepthRange&lt;/code&gt;&lt;/a&gt;, which have a totally different meaning (okay, let's say slightly different but related).&lt;/p&gt;&#xA;&lt;p&gt;Basically, and special situations notwithstanding, the projection matrix defines where you near and far clipping planes are in eye-space, i.e. which eye-space range is mapped to the &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt; NDC depth range. Then the depth range defines what these NDC near/far values of -1 and 1 are mapped to in the actual depth buffer. So the names &amp;quot;near&amp;quot;/&amp;quot;far&amp;quot; &lt;em&gt;do&lt;/em&gt; relate to the near and far clipping planes. But both transformations are basically independent of each other, using the general NDC (i.e. the &lt;em&gt;normalized&lt;/em&gt; device space) as a mediator between both stages. This way &lt;code&gt;glDepthRange&lt;/code&gt; more or less just extends what &lt;code&gt;glViewport&lt;/code&gt; does onto the z-dimension.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-08-27T08:28:16.433" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="6310" PostTypeId="1" AcceptedAnswerId="6312" CreationDate="2018-02-21T16:06:42.977" Score="1" ViewCount="1083" Body="&lt;p&gt;This is sort of an API design question. Why do vulkan instance/device extensions need to be specifically enabled, in order for their calls to be available?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wouldn't it make more sense to have extensions just always “be there” if they're supported in this environment, and then the API user can query which ones are actually available after device creation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way of phrasing this question might be: Is there any reason &lt;em&gt;not&lt;/em&gt; to enable every supported extension when creating a vulkan instance/device?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason I'm asking is because I'm specifically worried about vulkan interop between multiple programs. The fact that each program's VkDevice is distinct means you can't just straight up share VkImages. But agreeing on a common VkDevice is tricky because they may have different extensions/features enabled, so the interop API must account for the fact that both users may provide a set of extensions that they want enabled on the resulting VkDevice. This seems needlessly complex - wouldn't it be easier to just create one VkInstance and one VkDevice with everything enabled?&lt;/p&gt;&#xA;" OwnerUserId="7215" LastActivityDate="2018-02-21T16:33:23.330" Title="Why do vulkan extensions need to be enabled?" Tags="&lt;vulkan&gt;&lt;api&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6311" PostTypeId="2" ParentId="6307" CreationDate="2018-02-21T16:28:07.693" Score="5" Body="&lt;p&gt;There are multiple different ways to do tone-mapping, including both local and global methods. I won't discuss local methods (i.e. methods based on using surrounding information as part of the tone mapping process) here. Global methods can be broken down into two components:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;A formula for mapping from $[0,\infty)$ to $[0,1]$.&lt;/li&gt;&#xA;&lt;li&gt;A method of applying this to the color.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The simplest formula out there is just $out = in / (in + 1)$, but the results are also fairly boring. A fancier curve is the filmic tone mapping function developed by John Hable, which is &lt;a href=&quot;http://frictionalgames.blogspot.de/2012/09/tech-feature-hdr-lightning.html&quot; rel=&quot;noreferrer&quot;&gt;popular in the video gaming industry&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float hable(float x)&#xA;{&#xA;    float A = 0.15;&#xA;    float B = 0.50;&#xA;    float C = 0.10;&#xA;    float D = 0.20;&#xA;    float E = 0.02;&#xA;    float F = 0.30;&#xA;&#xA;    return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can also get even fancier if you can constrain the input domain to a known, fixed peak value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for how to apply this function to an actual color value, there are again multiple techniques. A very simple way is to do it per-channel, i.e. &lt;code&gt;color.r = map(color.r); color.g = map(color.g); color.b = map(color.b);&lt;/code&gt;. But this has the downside of warping the appearance of bright colors towards white (e.g. orange becomes yellowish under tone-mapping). Some in the movie industry tend to like this look, for whatever reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do color-preserving tone mapping, you can perform the calculation on a single value only and then apply the same scale to all three channels. A good choice for the value to use is to choose the “brightest” of the three components:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sig = max(color.r, max(color.g, color.b));&#xA;color.rgb *= vec3(map(sig) / sig);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, this approach also has downsides, namely that it takes very bright objects to unnaturally saturated versions of&#xA;themselves. For example, a bright sun might suddenly appear various shades of yellow and orange - which also looks unnatural on photographic content.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So ultimately, what I do is first desaturate the color based on how bright it is, and then apply tone mapping after the fact, leading to an algorithm that looks something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Calculate the desaturation coefficient based on the brightness&#xA;float sig = max(color.r, max(color.g, color.b));&#xA;float luma = dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));&#xA;float coeff = max(sig - 0.18, 1e-6) / max(sig, 1e-6);&#xA;coeff = pow(coeff, 20.0);&#xA;&#xA;// Update the original color and signal&#xA;color.rgb = mix(color.rgb, vec3(luma), coeff);&#xA;sig = mix(sig, luma, coeff);&#xA;&#xA;// Perform tone-mapping&#xA;color.rgb *= vec3(map(sig) / sig);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But YMMV.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;References:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/haasn/libplacebo/blob/master/src/shaders/colorspace.c#L664&quot; rel=&quot;noreferrer&quot;&gt;https://github.com/haasn/libplacebo/blob/master/src/shaders/colorspace.c#L664&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;You can also poke at ITU-R Report BT.2390-2 for some more ideas and guidelines.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7215" LastEditorUserId="7215" LastEditDate="2018-02-21T16:33:53.197" LastActivityDate="2018-02-21T16:33:53.197" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6312" PostTypeId="2" ParentId="6310" CreationDate="2018-02-21T16:33:23.330" Score="1" Body="&lt;p&gt;Extensions can change the visible behavior of the implementation, not to mention the implementation of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider KHR_external_semaphore and its various sub-extensions. If you don't specify them, then the &lt;code&gt;VkDevice&lt;/code&gt;'s implementation knows that you're not going to need to be able to turn a VkSemaphore into an externally-accessible mutex and back. So the implementation may be able to use a more efficient &lt;code&gt;VkSemaphore&lt;/code&gt; implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the extension is always on, the device &lt;em&gt;must&lt;/em&gt; assume that you're going to use it. And thus, any possible efficiency is lost.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;wouldn't it be easier to just create one VkInstance and one VkDevice with everything enabled?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;How? If you have two &lt;code&gt;VkDevice&lt;/code&gt;s, unless they are both attached to the same &lt;code&gt;VkPhysicalDevice&lt;/code&gt;, there's no guarantee that &quot;everything&quot; is the same thing for both devices.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Cross-process Vulkan interop is &lt;em&gt;not&lt;/em&gt; something external code is expected to define. There are extensions that provide various aspects of such interop.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-02-21T16:33:23.330" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6313" PostTypeId="1" AcceptedAnswerId="6325" CreationDate="2018-02-22T01:45:59.690" Score="5" ViewCount="374" Body="&lt;p&gt;I've been hunting around the internet for a while now, and I can't find anything about the specific shadow technique that I'm looking for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can only recall one game in particular that used it, and I know that it happens on the PC port of the game too. The game in question is &quot;Sonic Adventure 2: Battle&quot; for GameCube. I remember it happening on &quot;Super Mario Sunshine&quot;, but I could be mistaken.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The shadows are only cast from the main player character.&lt;/li&gt;&#xA;&lt;li&gt;It is 100% sharp, no matter the resolution the game is rendered at.&lt;/li&gt;&#xA;&lt;li&gt;They are cast perfectly parallel down onto the surface the player stands on.&lt;/li&gt;&#xA;&lt;li&gt;Interestingly, if the shadow intersects with a vertical wall, the shadow is drawn all the way up the wall, even higher than the original intersection.&lt;/li&gt;&#xA;&lt;li&gt;You can also see the shadow on ceilings directly above the player character, and even on floors above ceilings. It's as if there's a big character-silhouette shaped tube being cast onto surfaces.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;How does this technique work, and how can I learn more about it?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm going to hunt for a picture of this particular technique, but I don't have one right now.&lt;/p&gt;&#xA;" OwnerUserId="8245" LastActivityDate="2018-02-27T05:00:21.323" Title="How did the hard, accurate shadows, work in early 3d (2000 - 2004) games?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;gpu&gt;&lt;shadow&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6314" PostTypeId="1" CreationDate="2018-02-22T04:26:18.883" Score="0" ViewCount="85" Body="&lt;p&gt;So I'm working on an assignment where we have to design a simple ray tracer. The program has two objects that it can use, sphere and cube. It can render the cube and spheres, it also does shading on the objects and will cast a shadow of light for the spheres; however, the boxes are not casting shadows. Instead I think it is casting it upon the actual cube instead of &quot;the ground&quot;. Any ideas on how to fix that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is my code for the cube and the image it should be vs the image it produces. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;package ray.surface;&#xA;&#xA;import ray.Intersections;&#xA;import ray.Ray&#xA;import ray.math.Point3;&#xA;import ray.math.Vector3;&#xA;public class Box extends Surface {    &#xA;/* The corner of the box with the smallest x, y, and z components. */&#xA;protected final Point3 minPt = new Point3();&#xA;public void setMinPt(Point3 minPt) { this.minPt.set(minPt); }&#xA;&#xA;/* The corner of the box with the largest x, y, and z components. */&#xA;protected final Point3 maxPt = new Point3();&#xA;public void setMaxPt(Point3 maxPt) { this.maxPt.set(maxPt); }&#xA;&#xA;/**&#xA; * @param outRecord the output Intersections&#xA; * @param ray the ray to intersect&#xA; * @return true if the surface intersects the ray&#xA; */&#xA;public boolean intersect(Intersections outRecord, Ray rayIn) {&#xA;&#xA;    double tNear = 0;&#xA;    double tFar = Double.POSITIVE_INFINITY;&#xA;&#xA;    double x,y,z;&#xA;    // Compute the t values &#xA;    double txmin;&#xA;    double txmax;&#xA;    double tymin;&#xA;    double tymax;&#xA;    double tzmin;&#xA;    double tzmax;&#xA;&#xA;&#xA;        txmin = (minPt.x - rayIn.origin.x) / rayIn.direction.x;&#xA;        txmax = (maxPt.x - rayIn.origin.x) / rayIn.direction.x;&#xA;        x=1;&#xA;        if (txmin &amp;gt; txmax) {&#xA;            double tmp1 = txmin;&#xA;            txmin = txmax;&#xA;            txmax = tmp1;&#xA;            x=-1;&#xA;        }&#xA;        if (txmin &amp;gt; tNear)&#xA;            tNear = txmin;&#xA;        if (txmax &amp;lt; tFar)&#xA;            tFar = txmax;&#xA;        if (tNear &amp;gt; tFar)&#xA;            return false;&#xA;        if (tFar &amp;lt; 0)&#xA;            return false;&#xA;&#xA;&#xA;    //ray y direction is parallel to plane&#xA;&#xA;        tymin = (minPt.y - rayIn.origin.y) / rayIn.direction.y;&#xA;        tymax = (maxPt.y - rayIn.origin.y) / rayIn.direction.y;&#xA;        y=1;&#xA;&#xA;        if (tymin &amp;gt; tymax) {&#xA;            double tmp2 = tymin;&#xA;            tymin = tymax;&#xA;            tymax = tmp2;&#xA;            y=-1;&#xA;        }&#xA;        if (tymin &amp;gt; tNear)&#xA;            tNear = tymin;&#xA;        if (tymax &amp;lt; tFar)&#xA;            tFar = tymax;&#xA;        if (tNear &amp;gt; tFar)&#xA;            return false;&#xA;        if (tFar &amp;lt; 0)&#xA;            return false;&#xA;&#xA;&#xA;    //ray z direction is parallel to plane&#xA;&#xA;        tzmin = (minPt.z - rayIn.origin.z) / rayIn.direction.z;&#xA;        tzmax = (maxPt.z - rayIn.origin.z) / rayIn.direction.z;&#xA;        z=1;&#xA;&#xA;        if (tzmin &amp;gt; tzmax) {&#xA;            double tmp3 = tzmin;&#xA;            tzmin = tzmax;&#xA;            tzmax = tmp3;&#xA;            z=-1;&#xA;        }&#xA;        if (tzmin &amp;gt; tNear)&#xA;            tNear = tzmin;&#xA;        if (tzmax &amp;lt; tFar)&#xA;            tFar = tzmax;&#xA;        if (tNear &amp;gt; tFar)&#xA;            return false;&#xA;        if (tFar &amp;lt; 0)&#xA;            return false;&#xA;&#xA;    double t = Math.min(tNear, tFar);&#xA;    // Set the location point.&#xA;&#xA;    rayIn.evaluate(outRecord.location, tNear);&#xA;    //rayIn.start=0;&#xA;    rayIn.end=t;&#xA;&#xA;    outRecord.surface=this;&#xA;    outRecord.t=t;&#xA;    // Set the Normal Vector.&#xA;    if(tNear==txmin) {&#xA;        outRecord.normal.set(new Vector3(x,0,0));&#xA;    } else if (tNear==tymin) {&#xA;        outRecord.normal.set(new Vector3(0,y,0));&#xA;    } else if (tNear==tzmin) {&#xA;        outRecord.normal.set(new Vector3(0,0,z));&#xA;    }&#xA;    outRecord.normal.normalize();&#xA;&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;/**&#xA; * @see Object#toString()&#xA; */&#xA;public String toString() {&#xA;    return &quot;Box &quot; + minPt + &quot; &quot; + maxPt + &quot; &quot; + shader + &quot; end&quot;;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gLYrp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gLYrp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/h71Tq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/h71Tq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8246" LastEditorUserId="8246" LastEditDate="2018-02-22T04:33:39.547" LastActivityDate="2018-02-22T04:33:39.547" Title="Ray Tracer Shadowing" Tags="&lt;raytracing&gt;&lt;shader&gt;&lt;image-processing&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6316" PostTypeId="1" AcceptedAnswerId="6317" CreationDate="2018-02-22T07:52:03.217" Score="1" ViewCount="265" Body="&lt;p&gt;From the  sources that I have read about deferred rendering they all mention &quot;handling transparency is hard&quot; without much more information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However a solution that I see is, handle the scene once without the transparent geometry, once assuming the geometry is fully opaque, then interpolate between the 2 based on the transparency coefficient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this a bad solution because it's slow due to the additional render pass or is it that there is something else I am not seeing?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-02-22T21:04:19.873" LastActivityDate="2018-02-22T21:04:19.873" Title="Why is this not a proper solution to handling transparency in deferred rendering?" Tags="&lt;rendering&gt;&lt;transparency&gt;&lt;deferred-rendering&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6317" PostTypeId="2" ParentId="6316" CreationDate="2018-02-22T08:15:05.907" Score="5" Body="&lt;p&gt;PaulHK is right in what he said: you have to consider that there may be more than 2 transparent objects behind each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, the idea of deferred shading is to render the geometry only once to be more efficient. If you render the geometries multiple times, you lose (part of) your efficiency. Moreover, the lighting is deferred, thus you'd need to do lighting calculations for all your geometries before you can do the correct color calculations from transparency. So what you're really doing is going back to forward shading.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, one solution is to first render any opaque geometry with deferred shading and afterwards render the transparent objects with forward shading, so maybe you weren't too far off. Those transparent objects however shouldn't be affected by too many lights to still render frames &quot;fast&quot;.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="209" LastEditDate="2018-02-22T14:54:24.150" LastActivityDate="2018-02-22T14:54:24.150" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6319" PostTypeId="2" ParentId="6316" CreationDate="2018-02-22T12:19:11.880" Score="1" Body="&lt;p&gt;A fundamental assumption of deferred shading is that there will be only one surface, and therefore only one depth, at a given pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An effect that contradicts that assumption will require some sort of special handling in a deferred renderer. Translucency, because it allows to see through multiple layers, is such an effect and therefore will need its own rendering pass, or use some sort of compromise.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2018-02-22T12:19:11.880" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6320" PostTypeId="1" CreationDate="2018-02-22T13:57:48.367" Score="3" ViewCount="624" Body="&lt;p&gt;I was reading a paper about voxel cone tracing and came across this term. So, what is a Gaussian Lobe or a Lobe in general?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am asking in the context of Computer Graphics, BRDF and NDF.&lt;/p&gt;&#xA;" OwnerUserId="8250" LastActivityDate="2018-02-22T18:25:04.567" Title="What is a Gaussian Lobe concerning BRDF and NDF?" Tags="&lt;mathematics&gt;&lt;brdf&gt;&lt;ndf&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6321" PostTypeId="2" ParentId="6320" CreationDate="2018-02-22T16:49:56.507" Score="1" Body="&lt;p&gt;Having a gaussian lobe usually means that your ndf is one or a weighted sum of gaussian distributions. Instead of your ndf, you can define your brdf in the same way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Normal_distribution&quot; rel=&quot;nofollow noreferrer&quot;&gt;gaussian distribution&lt;/a&gt; is a function of the form $$\frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It has a hat shape common to many ndfs; this is good because it mimicks how normals align in most real world materials&lt;/p&gt;&#xA;" OwnerUserId="5703" LastEditorUserId="48" LastEditDate="2018-02-22T18:25:04.567" LastActivityDate="2018-02-22T18:25:04.567" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6322" PostTypeId="2" ParentId="6320" CreationDate="2018-02-22T18:22:44.773" Score="2" Body="&lt;p&gt;In a BRDF or NDF this most likely refers to a &lt;a href=&quot;https://mynameismjp.wordpress.com/2016/10/09/sg-series-part-2-spherical-gaussians-101/&quot; rel=&quot;nofollow noreferrer&quot;&gt;spherical Gaussian&lt;/a&gt; distribution, also known as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Von_Mises%E2%80%93Fisher_distribution&quot; rel=&quot;nofollow noreferrer&quot;&gt;von Mises–Fisher distribution&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's similar to the usual Gaussian, but using the dot product between two unit vectors as a measure of distance to the mean:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ p(\hat v) = a \exp(\lambda(\hat \mu \cdot \hat v))$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $a$ is a normalization factor, $\lambda$ is a number controlling the width of the lobe (roughly corresponds to $1/2\sigma^2$ in the usual Gaussian), $\hat \mu$ is the unit direction vector for the mean of the lobe, and $\hat v$ is the unit direction vector at which we're evaluating the lobe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(You'll also sometimes see it defined with $\lambda(\hat \mu \cdot \hat v - 1)$ in the exponent, but the $-1$ term can be pulled out and rolled into the normalization factor.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-02-22T18:22:44.773" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6323" PostTypeId="1" CreationDate="2018-02-22T19:11:35.117" Score="1" ViewCount="71" Body="&lt;p&gt;Obj files give pre-calculated normals which are in model coordinates. So I wonder if they have to be transformed into eye coordinate (where I use them to calculate lighting)? I'm thinking yes because it makes sense, but only rotation and scale because translation doesnt really make sense for free vectors.&lt;/p&gt;&#xA;" OwnerUserId="8191" LastActivityDate="2018-04-23T22:55:45.283" Title="Do normals in obj files have to be changed into eye coordinate before being used?" Tags="&lt;3d&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6325" PostTypeId="2" ParentId="6313" CreationDate="2018-02-22T20:28:11.593" Score="5" Body="&lt;p&gt;Having not worked on these games, I can only speculate... but from your description, it sounds like a crude shadow map with orthogonal projection and no depth information. It probably has (or had) a specific name but the way I suspect they did it is:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Render the character from above to a binary texture (eg. white there there's nothing, black where the character is), using an orthographic camera.&lt;/li&gt;&#xA;&lt;li&gt;When rendering the scene, perform a lookup in that texture and multiply by that color. You would of course exclude your characters from that.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The calculations involved for the texture lookup would be trivial as everything is 2D, in a plane of the world coordinates. It also does not need programmable shaders which IIRC were not around yet at that time. What you would need as texture coordinates is simply the (x,z) location of the vertex (assuming y is toward the sky here), along with an offset equal to the (x,z) location of your character. In OpenGL, I believe that could be achieved by &lt;code&gt;glTexGen&lt;/code&gt; along with a texture transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason for the artifacts is that this really does make a &quot;character-silhouette shaped tube&quot;, as you put it. Looking from above, the shadow is painted on every surface regardless of it being in front of or behind the character (above or below, from the camera's view). It's like you're dropping black ink from the sky inside the outline of the character and it goes through everything.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2018-02-23T14:47:18.880" LastActivityDate="2018-02-23T14:47:18.880" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6326" PostTypeId="2" ParentId="6323" CreationDate="2018-02-22T21:35:22.653" Score="2" Body="&lt;p&gt;Yes, all vectors used for lighting need to be in the same coordinates. If you do lighting in eye space, the normals would need to be transformed to eye space as well. Lighting calculations can also be done in world space, or any other space that's convenient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You're right that normal vectors shouldn't receive translation; likewise other vectors that represent directions or displacements rather than points in space. If you represent transformations as 4×4 matrices, it's simple to skip the translation by just leaving off the last column.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, one subtlety that comes up is that if your transformations contain non-uniform scaling (different scale factors along different axes) or shear, then you need to use the &lt;strong&gt;inverse transpose&lt;/strong&gt; matrix for normals. This is to ensure that the normals stay perpendicular to the polygons. (The inverse transpose will be the same as the original matrix if neither scaling nor shearing is present.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-02-22T21:35:22.653" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6327" PostTypeId="1" AcceptedAnswerId="6328" CreationDate="2018-02-22T23:25:35.593" Score="0" ViewCount="504" Body="&lt;p&gt;Ok so I am trying to understand how to combine these 2 techniques and I am failing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main goal is to reach the O(lights+fragments) complexity of deferred rendering, instead of O(lights*fragments) of naive/forward rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how I am currently doing things:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say we have n lights. Then we generate n shadow maps O(n)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we do one render pass to generate the normal, diffuse color, depth.... information in the geometry buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we check for every fragment whether it is occluded in ALL lights. and shadow it if it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This has an O(Lights*Fragments) complexity, which is wrong, so how can you reach the ideal asymptotic complexity? What should you do?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-02-23T00:32:40.353" Title="How to use shadow mapping and deferred rendering to create a large amount of lights?" Tags="&lt;shadow&gt;&lt;shading&gt;&lt;shadow-mapping&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6328" PostTypeId="2" ParentId="6327" CreationDate="2018-02-23T00:32:40.353" Score="2" Body="&lt;p&gt;Deferred rendering does not have an asymptic complexity of O(lights+fragments). It has a complexity of O(fragments+visibleFragments*lights).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you are doing in deferred rendering is preventing having to calculate lighting for many fragments that cover the same screen pixel. Once you have found which ones are visible, all of those still have to calculate lighting from every light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is faster than forward rendering on the premise that lighting calculations are heavier than geometry calculations and that most fragments are ocluded by other fragments.&lt;/p&gt;&#xA;" OwnerUserId="5703" LastActivityDate="2018-02-23T00:32:40.353" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6330" PostTypeId="1" AcceptedAnswerId="6332" CreationDate="2018-02-23T05:18:11.177" Score="1" ViewCount="894" Body="&lt;p&gt;All the books and reference I have read say that the view vector is calculated by subtracting the point where eye is at, from the point where we want to calculate light. But since, eye is at (0, 0, 0) the view vector would be just the negative of the point where eye is at? Is my understanding correct?&lt;/p&gt;&#xA;" OwnerUserId="8191" LastActivityDate="2018-02-23T09:59:35.340" Title="How to calculate the view vector in Phong Lighting Model?" Tags="&lt;3d&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6331" PostTypeId="1" CreationDate="2018-02-23T06:00:08.867" Score="0" ViewCount="569" Body="&lt;p&gt;I'm interpolating normals for Phong lighting models. Since I am calculating in the light of each pixel, I'm doing the interpolating after the viewport transform has been applied. So I save a version of the vertices in eye coordinate in order to do barycentric coordinate on them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get all these weird negative barycentric coordinates though. For example one is (-14928, 18491, -3562). What am I doing wrong? This very barycentric coordinate I also use for my texture mapping, and since it gets weird big negative result, it broke the index of my texture map.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int Y = minY; Y &amp;lt;= maxY; Y++) {&#xA;    for (int X = minX; X &amp;lt;= maxX; X++) {&#xA;        float lambda1, lambda2, lambda3;&#xA;        getBarycentricCoordinate(v1, v2, v3, X, Y, &amp;amp;lambda1, &amp;amp;lambda2, &amp;amp;lambda3);&#xA;        if ((0.0f &amp;lt;= lambda1 &amp;amp;&amp;amp; 0.0f &amp;lt;= lambda2 &amp;amp;&amp;amp; 0.0f &amp;lt;= lambda3)) {&#xA;            float zValue = lambda1 * zA + lambda2 * zB + lambda3 * zC;&#xA;            if (abs(zValue) &amp;lt; abs(raster.zBuffer[Y * rasterWidth + X])) {// If a point is closer to the eye, which is at (0, 0, 0) then draw. zBuffer check&#xA;                float lamb1, lamb2, lamb3;&#xA;                getBarycentricCoordinate(eyeCoorV1, eyeCoorV2, eyeCoorV3, X, Y, &amp;amp;lamb1, &amp;amp;lamb2, &amp;amp;lamb3);&#xA;&#xA;                Vector4f incidentPoint = lamb1 * eyeCoorV1 + lamb2 * eyeCoorV2 + lamb3 * eyeCoorV3;&#xA;                Vector4f l = lightInEyeCoor - incidentPoint;&#xA;&#xA;                //transforming normals to eye coordinates&#xA;                Vector4f normal1 = modelViewMatrix * objects[k].vertexNormal[vn1Index];&#xA;                Vector4f normal2 = modelViewMatrix * objects[k].vertexNormal[vn2Index];&#xA;                Vector4f normal3 = modelViewMatrix * objects[k].vertexNormal[vn3Index];&#xA;                Vector4f normal = lamb1 * normal1 + lamb2 * normal2 + lamb3 * normal3; // lamb1,lamb2 lamb3 are getting weird results&#xA;&#xA;                l.normalize();&#xA;                normal.normalize();&#xA;&#xA;                Colorf color = pointLight.LdLs * objects[k].KaKd * fmaxf(l*normal, 0.0f); // add diffuse color&#xA;                color = color + ambientLight * objects[k].KaKd; // add ambient color&#xA;                Vector4f r = 2 * (normal * l) * normal - l;&#xA;                Vector4f v = -incidentPoint; // because eye is at (0, 0, 0) in eye coordinate, view vector is just negative incidentPoint&#xA;                r.normalize();&#xA;                v.normalize();&#xA;                //specular lighting &#xA;                color = color + pointLight.LdLs * objects[k].Ks * powf(fmax(r*v, 0.0f), objects[k].Ks.A);&#xA;                raster.pixels[Y * rasterWidth + X] = floatColorToIntColor(color);&#xA;                raster.zBuffer[Y * rasterWidth + X] = zValue;&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Below is the code for my barycentric coordinate&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void getBarycentricCoordinate2D(Vector3f &amp;amp; v1, Vector3f &amp;amp; v2, Vector3f &amp;amp; v3, int X, int Y, float * l1, float * l2, float * l3) {&#xA;    float denonimator = (float)((v2.y - v3.y) * (v1.x - v3.x) + (v3.x - v2.x) * (v1.y - v3.y));&#xA;    float lambda1 = ((v2.y - v3.y)*(X - v3.x) + (v3.x - v2.x)*(Y - v3.y)) / denonimator;&#xA;    float lambda2 = ((v3.y - v1.y)*(X - v3.x) + (v1.x - v3.x)*(Y - v3.y)) / denonimator;&#xA;    *l1 = lambda1;&#xA;    *l2 = lambda2;&#xA;    *l3 = 1 - lambda1 - lambda2;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8191" LastEditorUserId="6" LastEditDate="2018-02-24T19:38:20.543" LastActivityDate="2018-02-25T00:38:52.080" Title="How to interpolate vertex normals for Phong lighting when barycentric coordinates are negative?" Tags="&lt;3d&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6332" PostTypeId="2" ParentId="6330" CreationDate="2018-02-23T06:47:13.970" Score="1" Body="&lt;p&gt;&lt;strong&gt;&lt;em&gt;EDIT&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While the basic principle of vector calculation below is correct, as Sebastián Mestre pointed out, in lighting you would use the vector from the lighted fragment to the eye position. Therefore, you would in fact use $v = -(point - eye) = eye - point = -point$, so you were actually correct in your &quot;negative&quot; assumption. Still (what might have been more a typo than a misunderstanding), it is the negative position of the lighted fragment, rather than the negative eye (which would still be the origin).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Sebastián also said in a comment to you, you would usually normalize the view vector after you have calculated it. Sebastián is the MVP.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Calculating a vector $v$ from point $A$ to point $B$ is subtracting the values of $B$ from $A$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$v = \left(\begin{array}{c}x\\y\\z\end{array}\right) = B - A = \left(\begin{array}{c}b_x - a_x\\b_y-a_y\\b_z-a_z\end{array}\right)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in your case, you need to subtract the $eye$ point from the point you're calculating light ($pos$) for:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;v = point -eye&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your $eye$ is the origin, so remaining is only the $point$. Therefore: no, it is not the negative position of the lighted point, but the positive position.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2018-02-23T07:16:05.573" LastActivityDate="2018-02-23T07:16:05.573" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6333" PostTypeId="2" ParentId="6330" CreationDate="2018-02-23T09:59:35.340" Score="0" Body="&lt;p&gt;It's correct as far as it goes, but there's more. The view vector goes from the shading point to the eye point, but it's normalized (divided by its length so that it has length 1). So if you're shading $p$ and the eye is at the origin, the view vector is $\tfrac{-p}{|-p|}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's not always this simple, because the &quot;eye&quot; isn't always at the origin. In a scanline rasteriser, you use the view transform to move things to the origin, because that's the only way to make the projection work - but not in a ray-tracer. The camera can be anywhere in a ray-tracer, and when you trace secondary rays (for reflections, refractions, or some other effects), it's definitely not in the same place as the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case you're working on right now, it sounds like you can just normalize $-p$, but you need to remember that it's really the direction from the shading point to the eye point, so that you can do the right thing when the eye point &lt;em&gt;isn't&lt;/em&gt; the origin.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-02-23T09:59:35.340" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6336" PostTypeId="1" CreationDate="2018-02-24T11:44:02.233" Score="2" ViewCount="170" Body="&lt;p&gt;For some time I have been working on UV unwrapper for radiosity computation. The information online about it is very sparse, except how to do it in some high end software. So far I have used triplanar method. The mesh I am testing is Sponza obj file - which consist of 384 objects in single file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This method computes normal of each triangle and depending on its direction take into consideration two components of position of model in world space.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 faceNormal = glm::normalize( glm::cross( v1-v0, v2-v0 ) );&#xA;float NdotXAxis = std::abs( faceNormal.x );&#xA;float NdotYAxis = std::abs( faceNormal.y );&#xA;float NdotZAxis = std::abs( faceNormal.z );&#xA;&#xA;if (NdotXAxis &amp;gt; NdotYAxis &amp;amp;&amp;amp; NdotXAxis &amp;gt; NdotZAxis)&#xA;{&#xA;    Triangle t;&#xA;    t.v[0] = {v0.z, v0.y};&#xA;    t.v[1] = {v1.z, v1.y};&#xA;    t.v[2] = {v2.z, v2.y};&#xA;    clustersX[i].triangles.push_back(t);&#xA;&#xA;}&#xA;else if (NdotYAxis &amp;gt; NdotXAxis &amp;amp;&amp;amp; NdotYAxis &amp;gt; NdotZAxis)&#xA;{&#xA;    Triangle t;&#xA;    t.v[0] = {v0.x, v0.z};&#xA;    t.v[1] = {v1.x, v1.z};&#xA;    t.v[2] = {v2.x, v2.z};&#xA;    clustersY[i].triangles.push_back(t);&#xA;}&#xA;else&#xA;{&#xA;    Triangle t;&#xA;    t.v[0] = {v0.x, v0.y};&#xA;    t.v[1] = {v1.x, v1.y};&#xA;    t.v[2] = {v2.x, v2.y};&#xA;    clustersZ[i].triangles.push_back(t);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Each object has three clusters of triangles in each axis. These clusters have bounding rectangle positions. Then they are packed into single image using recursive rectangle packing algorithm and normalized to $[0, 1]$ range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this creates problems, which exist among triangles in single cluster - if these triangles have, for example, major $x$ axis component and similar $z$ and $y$ positions, they will overlap in final texture. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to detect this and then pack overalapping triangles to different clusters and it works but it is tedious (check every triangle with every other triangle in each cluster) and not very efficient in further packing process. So is there other better method for UV unwrapping or more elegant solution for correction in this method?&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2018-02-26T13:01:47.097" LastActivityDate="2018-02-26T13:01:47.097" Title="Triplanar UV unwrapping - overlapping triangles" Tags="&lt;texture&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6337" PostTypeId="2" ParentId="6331" CreationDate="2018-02-25T00:38:52.080" Score="1" Body="&lt;p&gt;I have figured out the solution to this, and want to share it. What I am doing is I calculate different barycentric coordinate for each of the step I need to do: z-buffer, interpolation of normal, etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct way is to use the barycentric coordinate that is calculated when checking z-buffer to test whether a pixel inside a triangle. Because that barycentric coordinate is guaranteed to be inside the [0, 1] range (otherwise the pixel wouldnt have been drawn), it is the correct barycentric coordinate to use.    &lt;/p&gt;&#xA;" OwnerUserId="8191" LastActivityDate="2018-02-25T00:38:52.080" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6338" PostTypeId="1" AcceptedAnswerId="6339" CreationDate="2018-02-25T00:40:11.890" Score="1" ViewCount="237" Body="&lt;p&gt;If I have a rotation, $A$, and a translation, $B$, which I multiply like so&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$C = AB$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does the inverse of $C$ not only inverse the magnitudes of $A$ and $B$ but also become the reverse of operations?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g. $C^{-1} = BA$?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does the inverse of a matrix also inverse the order of original operations (or am I conflating inverse with reverse)?&lt;/p&gt;&#xA;" OwnerUserId="8268" LastActivityDate="2018-02-25T10:59:44.840" Title="Inverse matrix order of operation" Tags="&lt;matrix&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6339" PostTypeId="2" ParentId="6338" CreationDate="2018-02-25T10:59:44.840" Score="4" Body="&lt;p&gt;Yes. If you're compounding operations to make a matrix, then the inverse matrix will be the compound of the inverse operations, in the reverse order. So if $C = AB$ then $C^{-1} = B^{-1}A^{-1}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Think of it geometrically. Taking a 2D example, if you have an object at the origin, and you want to move it +2 units in X then rotate around the origin by +45 degrees. To undo this transformation, you need to first rotate by -45 degrees then translate by -2 units in X.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-02-25T10:59:44.840" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6341" PostTypeId="1" CreationDate="2018-02-26T08:49:17.900" Score="1" ViewCount="62" Body="&lt;p&gt;I know about the standard methods to pass floats, ints, or vectors. However, I'm curious whether there is an elegant way to pass data from libGDX Java code directly into a shader struct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking for a libGDX method to pass a whole structure &lt;em&gt;or&lt;/em&gt; best practice examples on how to pass structured data in case libGDX does not support this natively.&lt;/p&gt;&#xA;" OwnerUserId="8177" LastActivityDate="2018-02-26T08:49:17.900" Title="How to pass *struct*ured data from libGDX to openGL shader?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;data-structure&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6343" PostTypeId="2" ParentId="6313" CreationDate="2018-02-27T05:00:21.323" Score="2" Body="&lt;p&gt;Don't know the game but hard shadows are usually shadow volumes, often implemented with help of a stencil buffer. You can find a short description of the algorithm on Wikipedia.&lt;/p&gt;&#xA;" OwnerUserId="8283" LastActivityDate="2018-02-27T05:00:21.323" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6345" PostTypeId="1" AcceptedAnswerId="6347" CreationDate="2018-02-28T17:15:24.017" Score="1" ViewCount="535" Body="&lt;p&gt;(sorry for my english)&lt;br&gt;&#xA;&lt;strong&gt;The task:&lt;/strong&gt;&lt;br&gt;&#xA;A triangle is specified. To realize its motion on the basis of mirror reflection with respect to an arbitrary line ax + by + c = 0, the coefficients of which are entered by the user.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Already done:&lt;/strong&gt;&lt;br&gt;&#xA;I read from the fields on the form the coordinates of the three points of the triangle.&lt;br&gt;&#xA;Putting them into objects of class &lt;code&gt;Point&lt;/code&gt; (&lt;code&gt;left (x, y)&lt;/code&gt;, &lt;code&gt;top (x, y)&lt;/code&gt;, &lt;code&gt;right (x, y)&lt;/code&gt;).&lt;br&gt;&#xA;Make an array of &lt;code&gt;points&lt;/code&gt; from the points of a triangle:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Point[] points = new Point[3] { left, top, right };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Draw a coordinate system:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;DrawField();&#xA;DrawCoordinateSystem();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Draw a triangle:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;graph.FillPolygon(Brushes.ForestGreen, points);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Make a mirror reflection of the triangle:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Point[] pointsCopy = (Point[]) points.Clone();   &#xA;for (int i = 0; i  pointsCopy.Length; i++)&#xA;    pointsCopy[i].Y = -pointsCopy[i].Y; &#xA;graph.FillPolygon(Brushes.RoyalBlue, pointsCopy);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Read the coefficients (&lt;code&gt;a&lt;/code&gt;, &lt;code&gt;b&lt;/code&gt;, &lt;code&gt;c&lt;/code&gt;) from the fields on the form for the equation &lt;code&gt;ax + by + c = 0&lt;/code&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/f6tXI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/f6tXI.png&quot; alt=&quot;affine transformations of triangle&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt;&lt;br&gt;&#xA;Tell me how to move it further relative to the line &lt;code&gt;ax + by + c = 0&lt;/code&gt; ?&lt;/p&gt;&#xA;" OwnerUserId="8294" LastActivityDate="2018-03-18T06:54:33.687" Title="How to make a translation relative to the line ax + by + c = 0, affine transformations" Tags="&lt;vector-graphics&gt;&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6346" PostTypeId="2" ParentId="6345" CreationDate="2018-02-28T19:41:04.990" Score="1" Body="&lt;p&gt;To mirror an object in relation to an arbitrary line, you first have to find the coordinates of that object in the frame of reference of that line. For convenience, we will define a frame of reference where the $X$ axis is colinear with the line itself and the $Y$ axis will be perpendicular to the line. Then, we can flip the Y coordinate in that frame of reference to obtain the mirrored point and finally we will reverse the transform from the line coordinate system and back to the global coordinate system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To define a coordinate system, we will need to use one point the line passes through as the origin $O$ of that coordinate system. This can be obtained easily by setting $x = 0$ or $y = 0$ in the line equation and we end up with the point $\{-c/a, 0\}$ or $\{0, -c/b\}$. Getting the $X$ and $Y$ axis of the new coordinate system is easy. The $X$ axis vector $\{X_x, X_y\}$ will be computed by normalizing $\{a, b\}$ from the line equation. Then we need a perpendicular vector for the $Y$ axis direction. This is easily obtained by using either $\{-X_y, X_x\}$ or $\{X_y, -X_x\}$ (you can verify that by taking the dot product between $X$ and $Y$ which will be zero).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that you have an origin and a coordinate system, let's find a mirrored point of vector P on that system. First we need to express it in the new coordinate system. This can be done by projecting $P-O$ to the basis vectors $X$ and $Y$, so the coordinates in the new system will be $\{\langle(P - O), X\rangle, \langle(P - O), Y\rangle\}$.&#xA;To obtain the mirrored point, we simply flip the Y coordinate. To obtain the final vector in the original space, we simply invert the first transform. The final point should be $O + X\cdot\langle(P-O), X\rangle - Y\cdot\langle(P-O), Y\rangle$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A note on notation: $\langle u,v\rangle$ was used for dot product between vectors. $u\cdot k$ was used for product between vector and scalar&lt;/p&gt;&#xA;" OwnerUserId="5079" LastEditorUserId="5703" LastEditDate="2018-02-28T20:31:27.667" LastActivityDate="2018-02-28T20:31:27.667" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6347" PostTypeId="2" ParentId="6345" CreationDate="2018-03-01T09:31:29.877" Score="1" Body="&lt;p&gt;If I understand correctly, you want to draw 2 objects mirrored with respect to an arbitrary line. Then when you move 1 object you want the other (reflection) to move with respect to that reflected line. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A more sophisticated way of doing this would be using transformation matrices. That way you wouldn't have to worry about moving the mirrored triangle. You will move the original triangle, apply a transformation matrix to find the position of the mirrored triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose we have an arbitrary line $ax+by+c = 0$ making an arbitrary angle (measured counter clockwise) with the +X axis. We can easily find slope in the form of $ y = mx + c$ and the angle $\theta = tan^-1(m)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The mirror transformation with respect to this line can be broken in 3 affine transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Rotate the line by  $-\theta$ to coincide it with the X-axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\begin{bmatrix}&#xA;cos(-theta) &amp;amp; -sin(-theta) &amp;amp; 0\\&#xA;sin(-theta) &amp;amp; cos(-theta)  &amp;amp; 0\\&#xA;0           &amp;amp; 0            &amp;amp; 1&#xA;\end{bmatrix}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Reflect about the X-axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\begin{bmatrix}&#xA;1 &amp;amp; 0  &amp;amp; 0\\&#xA;0 &amp;amp; -1 &amp;amp; 0\\&#xA;0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) Rotate again by $\theta$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\begin{bmatrix}&#xA;cos(theta) &amp;amp; -sin(theta) &amp;amp; 0\\&#xA;sin(theta) &amp;amp; cos(theta)  &amp;amp; 0\\&#xA;0           &amp;amp; 0            &amp;amp; 1&#xA;\end{bmatrix}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you concatenate all 3 and you get a matrix that reflects about an arbitrary line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we only move 1 triangle and find out the other by applying the matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- &lt;strong&gt;As pointed out by Anthony in the comments this is only for lines passing through the origin. For arbitrary lines first translate them to the origin, then perform all these steps, then translate it back.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to do this you can find out the x and y intercepts by putting &lt;code&gt;y=0&lt;/code&gt; and  &lt;code&gt;x=0&lt;/code&gt; respectively then translate the respective coordinate by that amount.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-03-18T06:54:33.687" LastActivityDate="2018-03-18T06:54:33.687" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6348" PostTypeId="1" CreationDate="2018-03-01T11:01:32.803" Score="1" ViewCount="95" Body="&lt;p&gt;I currently perform several operations on polyhedra with cgal. These operations include&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Union of two or more polyhedra&lt;/li&gt;&#xA;&lt;li&gt;Difference of two or more polyhedra&lt;/li&gt;&#xA;&lt;li&gt;Intersection of two or more polyhedra&lt;/li&gt;&#xA;&lt;li&gt;Cutting Plane&lt;/li&gt;&#xA;&lt;li&gt;Ray intersection with polyhedra&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;and some more.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The polyhedra are not necessarily convex, but are otherwise simple (i.e. non-selfintersecting)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am now trying to find a way to hardware-accelerate these operations for speed efficiency reasons and thought, that GPUs might be capable to handle this task. However, most interfaces (i.e. OpenGL) I have seen focus on rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a good interface for performing these calculations with GPU support and retrieving the result subsequently?&lt;/p&gt;&#xA;" OwnerUserId="8297" LastActivityDate="2018-03-05T11:54:56.907" Title="Efficient operations on polyhedra" Tags="&lt;3d&gt;&lt;gpu&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6349" PostTypeId="1" CreationDate="2018-03-01T13:09:32.273" Score="1" ViewCount="91" Body="&lt;p&gt;Anisotropic filtering and multisample anti-aliasing both imply supersampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In &lt;a href=&quot;https://www.cs.cmu.edu/~ph/texfund/texfund.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;EWA&lt;/a&gt; and (derived) &lt;a href=&quot;http://watkins.cs.queensu.ca/~jstewart/454/notes/WRL-99-1.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Feline&lt;/a&gt; AF algorithms a non-uniform weighted average is used. But in case of MSAA not. Why this is the case? Isn't it better to use weighted average in case of MSAA?&lt;/p&gt;&#xA;" OwnerUserId="5430" LastActivityDate="2018-03-01T13:09:32.273" Title="Anisotropic filtering and multisample anti-aliasing" Tags="&lt;antialiasing&gt;&lt;supersampling&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6350" PostTypeId="1" CreationDate="2018-03-01T14:49:32.047" Score="2" ViewCount="164" Body="&lt;p&gt;I'm playing with a grid-based lighting system, where light is transported and accumulated through a grid. I initially tried attenuation based on &lt;code&gt;1/(distance*distance)&lt;/code&gt;, but that doesn't work when the distance between each node is 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pzbdi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pzbdi.png&quot; alt=&quot;Here&amp;#39;s a picture&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried hacks like adding an epsilon or clamping the distance, but nothing looks right. I'm sure there's something obvious I'm missing. Any guidance?&lt;/p&gt;&#xA;" OwnerUserId="8305" LastActivityDate="2020-06-26T04:07:25.713" Title="Light Falloff through a grid" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;grid&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6351" PostTypeId="1" AcceptedAnswerId="6354" CreationDate="2018-03-01T15:10:09.080" Score="1" ViewCount="111" Body="&lt;p&gt;I am looking for a way to efficiently compute ray-triangle intersections for a large number of rays (~1k) and a large set of triangle-mesh bodies (~100k) with each composed of several hundred faces. My current approach towards optimization consists of &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;thread parallelism for each ray&lt;/li&gt;&#xA;&lt;li&gt;pre-select bodies by testing for ray-bounding box intersections&lt;/li&gt;&#xA;&lt;li&gt;loop over faces of pre-selected bodies to detect ray-triangle intersections using the Möller-Trumbore algorithm.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Not impressed with performance so far. (Admittedly using python). Are there alternative solutions ?&lt;/p&gt;&#xA;" OwnerUserId="8303" LastActivityDate="2018-03-02T08:59:05.157" Title="Rays (~1k) intersecting triangle meshes (~100k) with ca. 100 vertices each" Tags="&lt;raytracing&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6353" PostTypeId="2" ParentId="6350" CreationDate="2018-03-02T06:03:51.793" Score="1" Body="&lt;p&gt;It looks to me like you're resetting the distance calculation at each grid intersection? So every time you march another grid cell you're dividing the light intensity by $gridsize^2$ ? That would explain your observed results, since dividing by $1^2$ equals no change. It won't give you the correct result though, since to get the right attenuation you need to track the &lt;em&gt;total distance&lt;/em&gt; back to the light source and square that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note that the attenuation term used in rendering is usually a bit more complicated than just $1/D^2$ - generally it's a quadratic, $1/(aD^2 + bD + c)$. While not physically correct, it's more tunable and easier to get visually pleasing results. In your case, for example, using $1/(D^2 + 1)$ would prevent the edges immediately surrounding the light from being brighter than the light itself.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="3003" LastEditDate="2018-03-03T16:43:57.903" LastActivityDate="2018-03-03T16:43:57.903" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6354" PostTypeId="2" ParentId="6351" CreationDate="2018-03-02T08:59:05.157" Score="1" Body="&lt;p&gt;Your procedure could be optimized in two directions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;If your rays are structured you could possibly take advantage of space coherence: if a ray intersects a given triangle, then a nearby rays has high possibility of intersecting the same triangle or an neighboring one. Therefore simple parallelism over the rays may not be optimal, you could at least process them in batches based on adjacency.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you have adjacency information on the triangles of your meshes, you could possibly exploit it when testing a ray against the mesh: the Möller-Trumbore algorithm can inform you if the intersection point of the ray and the triangle plane lies inside or outside each of the edges, so you may have a hint at which (neighboring) triangle to check next. That said, your meshes are quite small so the extra overhead may not be worth it.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6725" LastActivityDate="2018-03-02T08:59:05.157" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6356" PostTypeId="1" CreationDate="2018-03-03T03:56:10.963" Score="1" ViewCount="218" Body="&lt;p&gt;I want to write code for a cube rotating 10 degrees back and forth on its y-axis in an OpenGL application. Right now I have this written in my display method, however it depends on processor speed, and it may be more complicated than it needs to be. I would like to make the code independent of processor speed.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat rot = 10;&#xA;GLfloat angle = 0, angle2 = 0, angle3 = 0;&#xA;&#xA;if (angle &amp;lt; rot){&#xA;   glRotated(angle, 0, 1,0);                                  &#xA;   angle++;&#xA;}&#xA;else{&#xA;   if (angle2 &amp;lt; rot * 2 ){&#xA;     glRotated(rot - angle2, 0, 1, 0);      &#xA;     angle2++;&#xA;    }&#xA;&#xA;else{&#xA;    if (angle3 &amp;lt; rot ){&#xA;     glRotated(-rot + angle3, 0, 1, 0);     &#xA;     angle3++;&#xA;    }&#xA;&#xA;else{ angle = 0, angle2 = 0, angle3 = 0; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5183" LastEditorUserId="5183" LastEditDate="2018-03-03T04:01:56.373" LastActivityDate="2018-03-03T05:25:14.560" Title="Back and forth rotation on Y-axis" Tags="&lt;opengl&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6357" PostTypeId="2" ParentId="6356" CreationDate="2018-03-03T05:18:42.913" Score="1" Body="&lt;p&gt;In order to dissociate the rotation from the CPU speed, you need to use some sort of timing in your function. I recommend passing in a time value of some sort. The easiest thing is to pass in the number of seconds since the app started. How you do that depends on your particular OS, which you didn't specify. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have a timing constant, you can generate a triangle wave to control the rotation. This formula will oscillate between 0 and 1 over time:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double rotation = 2.0 * fabs(fmod(time, 1.0) - 0.5);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can make it go from 0 to 10 by multiplying the result by 10:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;rotation *= 10.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then you plug that into your &lt;code&gt;glRotated()&lt;/code&gt; call:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glRotated(rotation, 0, 1, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you want to make the motion a little smoother, you could replace the triangle wave with a sine wave, like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double rotation = 0.5 * (sin(time * 2.0 * M_PI + M_PI / 2.0) + 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2018-03-03T05:25:14.560" LastActivityDate="2018-03-03T05:25:14.560" CommentCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="6358" PostTypeId="1" CreationDate="2018-03-03T18:45:17.280" Score="3" ViewCount="442" Body="&lt;p&gt;My question is oriented towards the generation of depth map using any of the state of the art &lt;a href=&quot;https://en.wikipedia.org/wiki/Structured-light_3D_scanner&quot; rel=&quot;nofollow noreferrer&quot;&gt;depth sensor&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, each of these method required the presence of an 3-D object in front of the sensor. Is it possible the generate a depth map even if a 2-D image is presented to the sensor?&lt;/p&gt;&#xA;" OwnerUserId="8311" LastActivityDate="2018-04-03T07:19:17.723" Title="Creating depth map from a 2-D image?" Tags="&lt;image-processing&gt;&lt;camera&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6359" PostTypeId="1" AcceptedAnswerId="8342" CreationDate="2018-03-03T22:58:17.557" Score="3" ViewCount="189" Body="&lt;p&gt;I am trying to fetch a given geometry and, through (potentially multiple) render passes, create a 3D texture that stores the color value of said geometry into an associated texel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words there is a 3D box that i am trying to color based on the geometry inside of that box.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I am attempting to do so with the following vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;#define PI 3.1415926535897932384626433832795&#xA;&#xA;layout(location = 0) in vec3 position; //(x,y,z) coordinates of a vertex&#xA;layout(location = 1) in vec3 norm; //a 3D vertex representing the normal to the vertex &#xA;layout(location = 2) in vec2 texture_coordinate; // texture coordinates&#xA;&#xA;layout(std430, binding = 3) buffer instance_buffer&#xA;{&#xA;    vec4 cubes_info[];//first 3 values are position of object &#xA;};&#xA;&#xA;out vec3 normalized_pos;&#xA;out vec3 normal; &#xA;out vec2 texture_coord;&#xA;&#xA;uniform float width = 128;&#xA;uniform float depth = 128;&#xA;uniform float height = 128;&#xA;&#xA;uniform float voxel_size = 1;&#xA;uniform vec3 origin = vec3(0,0,0);&#xA;&#xA;uniform float level=0;&#xA;&#xA;void main()&#xA;{&#xA;    texture_coord = texture_coordinate; &#xA;    vec4 pos = (vec4(position, 1.0) + vec4(vec3(cubes_info[gl_InstanceID]),0));&#xA;&#xA;    pos-=vec4(origin, 0);&#xA;&#xA;    pos.x = (2.f*pos.x-width)/(width);&#xA;    pos.y = (2.f*pos.y-depth)/(depth);&#xA;    pos.z = (2.f*pos.z-depth)/(height);&#xA;&#xA;    gl_Position = pos;&#xA;&#xA;    normalized_pos = vec3(pos);&#xA;&#xA;    normal = normalize(norm);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the following fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;in vec3 normalized_pos;&#xA;in vec3 normal;//Normal to the vertex&#xA;in vec2 texture_coord;&#xA;&#xA;out vec4 outColor;//Final color of the pixel&#xA;&#xA;uniform sampler2D text;&#xA;&#xA;void main()&#xA;{&#xA;    outColor = vec4(0,1,0,1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Currently the color is ahrd set to green, just to test whether I am doing things in the correct fashion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I seem to have failed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How exactly would you design a shading program that voxelizes a 3D grid of a space?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="9622" LastEditDate="2019-10-09T11:42:31.347" LastActivityDate="2019-10-09T11:42:31.347" Title="How to voxelize geometry using textures and shaders?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;voxelization&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="6360" PostTypeId="1" AcceptedAnswerId="6376" CreationDate="2018-03-04T04:31:04.867" Score="2" ViewCount="45" Body="&lt;p&gt;The OpenGL SuperBible &lt;a href=&quot;https://books.google.com/books?id=Nwo0CgAAQBAJ&amp;amp;pg=PT981&amp;amp;lpg=PT981&amp;amp;dq=gltexturestoragesubimage2d&amp;amp;source=bl&amp;amp;ots=LpPMWjKtq8&amp;amp;sig=YrK4Hatro5CFcAstr5MSo34C04E&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0ahUKEwj6itGQ59HZAhVE5mMKHaPxCloQ6AEIJzAA&quot; rel=&quot;nofollow noreferrer&quot;&gt;mentions glTextureStorageSubImage2D&lt;/a&gt;; however, a &lt;a href=&quot;https://www.google.com/search?q=gltexturestoragesubimage2d&amp;amp;oq=gltexturestoragesubimage&amp;amp;aqs=chrome.0.69i59j69i57.3359j0j4&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8&quot; rel=&quot;nofollow noreferrer&quot;&gt;Google search&lt;/a&gt; currently shows no other mention of this function and I can not find any prototype or signature anywhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this call actually exist and if so, what are its parameters?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="48" LastEditDate="2018-03-04T05:25:29.133" LastActivityDate="2018-03-07T05:54:56.653" Title="Does glTextureStorageSubImage2D exist?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6362" PostTypeId="2" ParentId="6358" CreationDate="2018-03-04T06:40:23.607" Score="3" Body="&lt;p&gt;No, it's not. The way many of the 3D sensors work is by projecting an infrared pattern onto the surface and measuring how it distorts. But with a 2D image, the pattern will simply be projected onto the flat 2D image, not onto the objects in the scene. So the 3D sensor will only sense a flat card.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other methods work by combining 2 images taken with different cameras at different angles. This will have the same result as above. The 2D photo will be interpreted as a 2D surface by the combination of the 2 cameras.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-03-04T06:40:23.607" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6365" PostTypeId="1" AcceptedAnswerId="6366" CreationDate="2018-03-04T18:29:47.143" Score="4" ViewCount="1147" Body="&lt;p&gt;I am a new leaner of computer graphics. I'm trying to understand a code I found online and I got stuck in the following formula:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;topLeft = [-tan(vfov/2)*(output_width/output_height), -tan(vfov/2), 1];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/rayryeng/equi2cubic/blob/master/equi2cubic.m&quot; rel=&quot;noreferrer&quot;&gt;Source&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;looking on the internet I found that the formula is that of the Perspective Matrix. However the formula of the code has:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;tan(vfov/2)*(output_width/output_height)&lt;/code&gt; instead of&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1 / tan(vfov/2)*(output_width/output_height)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the Perspective Matrix I found online. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you explain to me why I have inverse values?&#xA;What does it mean?&#xA;Thank you so much&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/C9PST.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/C9PST.jpg&quot; alt=&quot;Perspective Matrix&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8317" LastEditorUserId="209" LastEditDate="2018-03-05T11:22:20.213" LastActivityDate="2018-07-03T12:34:09.713" Title="Inverse value in a Perspective Matrix" Tags="&lt;c++&gt;&lt;matrix&gt;&lt;perspective&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6366" PostTypeId="2" ParentId="6365" CreationDate="2018-03-04T21:25:19.617" Score="2" Body="&lt;p&gt;There is the whole derivation of it but I'll be discussing a brief overview.&#xA;This is for the perspective projection  where the line joining the eye and the center of the projection/image plane is perpendicular to it. Like here&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WmmPi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WmmPi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As we can easily see, by similar triangles $\triangle ABC$ and $\triangle AEF$ we have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Y_p / Y = D/-Z$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $Y_p$ is the projected $Y$ coordinate on to the image plane. $AB = D$ is the total distance from eye to the image plane and is usually set to 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence we have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Y_p = (Y*D)/-Z$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most APIs also set that the camera is facing towards the negative Z axis following the convention for right handed coordinate system, hence the negative sign. The projection plane is also assumed to be a rectangle instead of a square. It's 2 units long in the $Y$ direction and centered at the origin i.e in the range [-1,1] so it's 1 unit long in the positive Y axis and 1 unit long in the negative. However horizontally, its in the range $[-A, A]$ so when calculating $X_p$ we have to correct for this factor. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$A = Width\ of\ rectangle/Height\ of\ rectangle$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly for $X_p$ and $Z_p$ we have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$A*X_p = (X*D)/(-Z)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$X_p = (X*D)/(-Z*A)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Z_p = D$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can easily see see that&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$tan(Y_{fov}/2) = BC/D = 1/D$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$D = 1/tan(Y_{fov}/2)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here, $Y_{fov}$ is the angle of field of view in the Y axis. Since we are only talking about the upper half its $Y_{fov}/2$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence one way to write $X_p$ and $Y_p$ is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$X_p = \frac{X}{-Z} * \frac{1}{A*tan(Y_{fov}/2)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Y_p = \frac{Y}{-Z} * \frac{1}{tan(Y_{fov}/2)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what you are seeing in the matrix. The $X$ and $Y$ come from the vector at which the transformation matrix is applied and the $-Z$ term is accounted for by the $-1$ in the 4th row. This $-Z$ is stored as the $w$ coordinate which is then used in perspective division in which we divide by $w$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more information you can check this site &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/opengl-perspective-projection-matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note:- Haven't discussed properly about NDC space, perspective divide and about near and far planes in $Z_p$ as that would take too much time. Just wanted to show you that it can be derived.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-03-05T09:49:05.723" LastActivityDate="2018-03-05T09:49:05.723" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6370" PostTypeId="1" CreationDate="2018-03-05T21:54:01.593" Score="2" ViewCount="708" Body="&lt;p&gt;I'm trying to calculate what the effective pitch, yaw, and roll are for an image.&#xA;I have the image's original pitch, yaw, and roll.  Then the image (camera) is rolled at some arbitrary angle.  I want to calculate the new relative pitch, yaw, and roll.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know if pitch and yaw are 0, the new roll is just original roll + camera rotation angle. Likewise, if yaw and roll are 0, the new pitch is just the original pitch + camera rotation angle. For an arbitrary angle, I know both pitch and roll are affected. I imagine there is a simple equation for this, but I'm having trouble finding a reference.&lt;/p&gt;&#xA;" OwnerUserId="8323" LastActivityDate="2018-06-04T00:11:52.323" Title="Camera rotation effect on pitch, yaw, roll" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6371" PostTypeId="2" ParentId="6370" CreationDate="2018-03-05T23:07:59.583" Score="1" Body="&lt;p&gt;Thanks for the suggestion to look up Euler angle rotations.  &lt;a href=&quot;https://www.learnopencv.com/rotation-matrix-to-euler-angles/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.learnopencv.com/rotation-matrix-to-euler-angles/&lt;/a&gt; is a good reference to answer this question.&lt;/p&gt;&#xA;" OwnerUserId="8323" LastActivityDate="2018-03-05T23:07:59.583" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6373" PostTypeId="1" CreationDate="2018-03-06T05:03:47.667" Score="1" ViewCount="548" Body="&lt;p&gt;Given a 3D model, is there a way to &lt;a href=&quot;https://en.wikipedia.org/wiki/Stereographic_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;stereographically project&lt;/a&gt; it to a 2D image? In particular, I would only need a little more than half the model (the lower half) to be mapped to the plane (mapping the whole 3D model would be impossible, since the stereographic projection is infinite).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using Linux, if that makes any difference. Also, I would prefer to use free software.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Note: If I could increase the viewing angle, I could do this with most any 3D viewing software, since the stereographic projection is just the view from a certain point with a wide viewing angle. In particular, I was able to get a small portion of the stereographic projection from meshlab.)&lt;/p&gt;&#xA;" OwnerUserId="8325" LastEditorUserId="8325" LastEditDate="2018-03-06T18:18:30.817" LastActivityDate="2018-11-03T06:00:39.260" Title="How to generate the stereographic projection of a 3D model" Tags="&lt;image-processing&gt;&lt;projections&gt;&lt;raster-image&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6374" PostTypeId="1" AcceptedAnswerId="6375" CreationDate="2018-03-06T13:42:06.910" Score="2" ViewCount="367" Body="&lt;p&gt;I have just come across &lt;a href=&quot;http://www.yosoygames.com.ar/wp/2018/03/vertex-formats-part-1-compression&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article about half, snorm and unorm&lt;/a&gt;, but I don't get some of the points (or why they work).&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;According to the article, a &lt;code&gt;half&lt;/code&gt; is basically a 16 bit float and an &lt;code&gt;snorm&lt;/code&gt; is a signed &lt;s&gt;float&lt;/s&gt; integer$^1$ dividied by &lt;code&gt;65535&lt;/code&gt;. Therefore, they are basically the same, just that the snorm is represented in $[-1, 1]$ whereas the half is in $[-65520; 65520)$ (where did those 32 values go?) but doesn't need another multiplication to get to the &quot;real&quot; value.  Now the article says:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Other people prefer 16-bit xNORM variants because they tend to give really good precision and it is evenly distributed.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Why do they give a &quot;good precision&quot; and are &quot;evenly distributed&quot; (as opposed to the half)?&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;For &lt;code&gt;snorm&lt;/code&gt; a division is suggested, by either $64$ or the maximum AABB value. I get the latter, that can be used for more or less any model then, but why use the magic number $64$ if I don't want to calculate it? Is it common to have models that don't exceed this specific value?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If I get good precision with &lt;code&gt;half&lt;/code&gt; (or &lt;code&gt;xnorm&lt;/code&gt; respectively) to save bandwidth, but in my application actually need really large position values, can I leverage the better precision of &lt;code&gt;xnorm&lt;/code&gt; with a multiplication for &quot;full&quot; &lt;code&gt;float&lt;/code&gt; and save myself from using  &lt;code&gt;double&lt;/code&gt; variables?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;$^1$ Edit for future readers. I wrongly assumed it was a float.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2018-03-07T06:52:00.537" LastActivityDate="2018-03-07T06:52:00.537" Title="How to work with half and snorm" Tags="&lt;float&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6375" PostTypeId="2" ParentId="6374" CreationDate="2018-03-06T16:43:26.390" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;According to the article, a half is basically a 16 bit float and an snorm is a signed float dividied by 65535. Therefore, they are basically the same&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, they're not, and you do the article a great disservice by suggesting that it says such a thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, Half-floats are 16-bit floats. But they are &lt;em&gt;floating point numbers&lt;/em&gt;, as &lt;a href=&quot;https://en.wikipedia.org/wiki/IEEE_754&quot; rel=&quot;nofollow noreferrer&quot;&gt;defined in IEEE-754&lt;/a&gt;. Which means that they can express a relatively large range of values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Normalized_Integer&quot; rel=&quot;nofollow noreferrer&quot;&gt;Normalized integers&lt;/a&gt; can only directly express values in the range [0, 1] (for unsigned) and [-1, 1] (for signed). Floating-point numbers can extend beyond this range. &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Small_Float_Formats&quot; rel=&quot;nofollow noreferrer&quot;&gt;16-bit floats&lt;/a&gt; can express numbers approximately on the range [-6.55*10&lt;sup&gt;4&lt;/sup&gt;, 6.55*10&lt;sup&gt;4&lt;/sup&gt;], and it can handle decimal values in-between them.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Why do they give a &quot;good precision&quot; and are &quot;evenly distributed&quot; (as opposed to the half)?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Because that's how IEEE-754 works. After all, normalized 16-bit values and 16-bit float values have the same size. 16-bits of storage gives you 65536 different values, no matter how you interpret them. Therefore, to get the range of values outside of [-1, 1], 16-bit floats sacrifice some bits to define additional values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;16-bit floats give you about 3 decimal digits of precision. Normalized 16-bit values give you at most 5 (though the closer to zero you get, the fewer significant digits you get, unlike floating-point values).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;why use the magic number 64 if I don't want to calculate it?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No reason; it's just a made-up number.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it common to have models that don't exceed this specific value?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Not particularly.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If I get good precision with half (or xnorm respectively) to save bandwidth, but in my application actually need really large position values, can I leverage the better precision of xnorm with a multiplication for &quot;full&quot; float and save myself from using double variables?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally speaking, model space positions do not &lt;em&gt;need&lt;/em&gt; &quot;really large position values&quot;. They're in model space, so they're generally expressed relative to a center position that's quite close to them. They don't really have to be in scale with the rest of the world either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if your model space positions really do need &quot;really large position values&quot;, then you have to use whatever gives you the precision you need. That's pretty much never &lt;code&gt;double&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2018-03-06T18:57:15.493" LastActivityDate="2018-03-06T18:57:15.493" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6376" PostTypeId="2" ParentId="6360" CreationDate="2018-03-07T05:54:56.653" Score="1" Body="&lt;p&gt;There is no such function. Given the context of the text, it is almost certainly referring to &lt;code&gt;glTextureSubImage*&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-03-07T05:54:56.653" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6378" PostTypeId="1" CreationDate="2018-03-07T11:59:08.563" Score="1" ViewCount="94" Body="&lt;p&gt;I implemented a simulation for the colour of the sky a while ago by following the scratch a pixel tutorial: &lt;a href=&quot;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/simulating-sky&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I adapted it for the actual sun position and am able to get realistic sky colours during the day. However, I noticed that after sunset/ before sunrise, the colours are greyish when they should be deep blue. After researching about this, I read that this is due to the ozone absorption not being present in my model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used extinction coefficients : (3.426,8.298,0.356) * 0.06e-5 -&gt; found on &lt;a href=&quot;https://media.contentapi.ea.com/content/dam/eacom/frostbite/files/s2016-pbs-frostbite-sky-clouds-new.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://media.contentapi.ea.com/content/dam/eacom/frostbite/files/s2016-pbs-frostbite-sky-clouds-new.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and also read that since the ozone does not scatter, it should only be added to the transmittance value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cAiJu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cAiJu.jpg&quot; alt=&quot;more info about ozone&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, I modified the code from scratchapixel as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        for (uint32_t i = 0; i &amp;lt; numSamples; ++i) {&#xA;            vec3 samplePosition = ray_in2.origin() + (tCurrent + &#xA;            segmentLength * 0.5f) * ray_in2.direction();&#xA;            float height = samplePosition.length() - atmosphere.earthRadius;&#xA;&#xA;            // compute optical depth for light&#xA;            float hr = exp(-height / atmosphere.Hr) * segmentLength;&#xA;            float hm = exp(-height / atmosphere.Hm) * segmentLength;&#xA;            float ho = exp(-height / atmosphere.Hr)* segmentLength*(6e-7);&#xA;            opticalDepthR += hr;&#xA;            opticalDepthM += hm;&#xA;            opticalDepthO += ho;&#xA;&#xA;            // light optical depth&#xA;            float t0Light, t1Light;&#xA;&#xA;                ...&#xA;            for (j = 0; j &amp;lt; numSamplesLight; ++j) {&#xA;                vec3 samplePositionLight = samplePosition + (tCurrentLight + &#xA;                segmentLengthLight * 0.5f) * sunDir;&#xA;                float heightLight = samplePositionLight.length() - &#xA;                atmosphere.earthRadius;&#xA;&#xA;                if (heightLight &amp;lt; 0) break;&#xA;                opticalDepthLightR += exp(-heightLight / atmosphere.Hr) * &#xA;                segmentLengthLight;&#xA;                opticalDepthLightM += exp(-heightLight / atmosphere.Hm) * &#xA;                segmentLengthLight;&#xA;                opticalDepthLightO += exp(-heightLight / atmosphere.Hr) * &#xA;                segmentLengthLight*(6e-7); ;&#xA;                tCurrentLight += segmentLengthLight;&#xA;            }&#xA;            if (j == numSamplesLight) {&#xA;                vec3 tau = (betaR) * (opticalDepthR + opticalDepthLightR) + &#xA;               betaM * 1.1f * (opticalDepthM + opticalDepthLightM)+ betaO*&#xA;              (opticalDepthO + opticalDepthLightO);&#xA;                vec3 attenuation(exp(-tau.x()), exp(-tau.y()), exp(-&#xA;                tau.z()));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;summary : &#xA;-I added variable opticalDepthO and opticalDepthLightO which are calculated same as the optical depth for Rayleigh, but multiplied by 6e-7. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;-Then, the sum of opticalDepthLightO and opticalDepthO is multiplied by the extiction coefficient for ozone and added to variable tau.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Problem is, I see no difference in my sky colour before and after adding ozone. Can someone guide me to what it is that I'm doing wrong? Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="8242" LastActivityDate="2018-03-07T11:59:08.563" Title="Adding Ozone to my sky simulation" Tags="&lt;c++&gt;&lt;scattering&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6379" PostTypeId="2" ParentId="6373" CreationDate="2018-03-07T15:38:18.230" Score="0" Body="&lt;p&gt;Using blender, you can position the camera at the north pole of the sphere you are stereographically projecting, and then set a really wide &lt;a href=&quot;https://docs.blender.org/manual/en/dev/render/cycles/camera.html#perspective&quot; rel=&quot;nofollow noreferrer&quot;&gt;field of view&lt;/a&gt;. For example, I had to set my focal length to around 5 mm to get a hemisphere in the stereographic projection, but it will depend on the model, of course. Then simply render and you're done!&lt;/p&gt;&#xA;" OwnerUserId="8325" LastActivityDate="2018-03-07T15:38:18.230" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6381" PostTypeId="2" ParentId="96" CreationDate="2018-03-07T22:11:50.263" Score="2" Body="&lt;p&gt;The solution that worked for me is compilation of shader code to C++ - as mentioned by Nobody. It prooved very efficient when working on a complex code even though it requires a bit of setup.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been working mostly with HLSL Compute Shaders for which I have developed a proof-of-concept library available here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/cezbloch/shaderator&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/cezbloch/shaderator&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It demonstrates on a Compute Shader from DirectX SDK Samples, how to enable C++ like HLSL debugging and how to setup Unit Tests.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compilation of GLSL compute shader to C++ looks easier than HLSL. Mainly due to syntax constructions in HLSL. I have added a trivial example of executable Unit Test on a GLSL ray tracer Compute Shader which you can also find in the Shaderator project's sources under link above.&lt;/p&gt;&#xA;" OwnerUserId="8335" LastActivityDate="2018-03-07T22:11:50.263" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6382" PostTypeId="2" ParentId="6373" CreationDate="2018-03-08T01:29:58.833" Score="1" Body="&lt;p&gt;If instead of stereographic projection you can use other conformal projection. I would recommend you the &quot;Least Squares Conformal Maps&quot; algorithm. There are several implementations out there, including the prominent CGAL (&lt;a href=&quot;https://doc.cgal.org/latest/Surface_mesh_parameterization/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://doc.cgal.org/latest/Surface_mesh_parameterization/index.html&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="7957" LastActivityDate="2018-03-08T01:29:58.833" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6383" PostTypeId="1" AcceptedAnswerId="6384" CreationDate="2018-03-08T03:35:33.607" Score="1" ViewCount="73" Body="&lt;p&gt;I am reading a model from an obj file and draw it using glDrawElements. For some reasons, only a small part of it is drawn, even though I dont even have back-face culling turned on. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// vertices &#xA;glEnableVertexAttribArray(0);&#xA;float * objectGeometry = scene.objects[k].verticesAsFloatArray();&#xA;glVertexAttribPointer(0, 4, GL_FLOAT, 0, 0, objectGeometry);&#xA;&#xA;// normals&#xA;glEnableVertexAttribArray(1);&#xA;float * objectNormals = scene.objects[k].normalsAsFloatArray();&#xA;glVertexAttribPointer(1, 3, GL_FLOAT, 0, 0, objectNormals);&#xA;&#xA;// indices&#xA;int * indices = scene.objects[k].facesAsIndiceArray();&#xA;glDrawElements(GL_TRIANGLES, scene.objects[k].vertices.size(), GL_UNSIGNED_INT, indices);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8191" LastEditorUserId="2654" LastEditDate="2018-03-08T04:53:50.150" LastActivityDate="2018-03-08T14:38:27.463" Title="What is wrong with my glDrawElement code" Tags="&lt;opengl-es&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6384" PostTypeId="2" ParentId="6383" CreationDate="2018-03-08T14:38:27.463" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawElements.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;glDrawElements&lt;/a&gt; specifies the second argument to be the number of elements to be taken from the buffer of indices, not the number of vertices. The correct number would be the number of triangles times three.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2018-03-08T14:38:27.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6385" PostTypeId="1" CreationDate="2018-03-08T17:04:57.583" Score="2" ViewCount="111" Body="&lt;p&gt;I drew simple &lt;a href=&quot;https://en.wikipedia.org/wiki/Triangle_wave&quot; rel=&quot;nofollow noreferrer&quot;&gt;triangle wave&lt;/a&gt; (that you can see It on &lt;a href=&quot;http://www.iquilezles.org/apps/graphtoy/&quot; rel=&quot;nofollow noreferrer&quot;&gt;graph toy&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/16706911/37163629-80fb47c2-230d-11e8-9210-736648fb74a4.png&quot; alt=&quot;triangle wave&quot; /&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;   f1(x) = frac(x/(PI+5))*(PI+5)&#xA;   f2(x) = frac(-x/(PI+5))*(PI+5)&#xA;   f3(x) = min(f1(x),f2(x))*1.5&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;I want to change above shape like &lt;a href=&quot;https://www.desmos.com/calculator/hmcutwfumj&quot; rel=&quot;nofollow noreferrer&quot;&gt;Approximating Pi&lt;/a&gt; and repeat It periodically along the horizontal axis.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/16706911/37164290-167419cc-230f-11e8-9e65-75aca83d33c5.gif&quot; alt=&quot;Approximating Pi&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;then I want to cut negative parts of the vertical axis:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/16706911/36645755-be8cd206-1a82-11e8-9046-dd2923095e16.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;&#xA;&lt;h1&gt;Update&lt;/h1&gt;&#xA;&lt;p&gt;Note that I know how can I draw It by shader In &lt;a href=&quot;https://www.shadertoy.com/view/XsVyzR&quot; rel=&quot;nofollow noreferrer&quot;&gt;ShaderToy&lt;/a&gt;.I Just need drawing mathematics In desmos or graphtoy,because I want Extract values of wave.I want to create polygon &lt;a href=&quot;https://en.wikipedia.org/wiki/Waveform&quot; rel=&quot;nofollow noreferrer&quot;&gt;wave form&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I drew Periodic shape that I want to change the number of polygons&#xA;&lt;a href=&quot;https://www.desmos.com/calculator/gh7fmcrbys&quot; rel=&quot;nofollow noreferrer&quot;&gt;Desoms Link&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6541" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-03-12T07:34:18.177" Title="How can I draw regular polygons along the horizontal axis?" Tags="&lt;mathematics&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6386" PostTypeId="1" CreationDate="2018-03-08T18:56:51.097" Score="0" ViewCount="55" Body="&lt;p&gt;My problem is about tangent plane. I have an image (m by n). I obtain surface normal vector using machine learning methods. Then i would like to obtain tangent plane for this surface normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To imagine my problem, you can look this paper; &lt;a href=&quot;https://arxiv.org/abs/1704.02956&quot; rel=&quot;nofollow noreferrer&quot;&gt;Surface Normals in the Wild&lt;/a&gt;. In this paper, authors find surface normal and draw/find virtual tangent plane around this point (Figure 4 in above paper).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this problem, i have really no idea. Any tips or starter idea will be acceptable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you&lt;/p&gt;&#xA;" OwnerUserId="8130" LastActivityDate="2018-03-08T18:56:51.097" Title="Tanget plane of an image" Tags="&lt;transformations&gt;&lt;image-processing&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;image&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6387" PostTypeId="1" CreationDate="2018-03-09T03:11:53.570" Score="1" ViewCount="82" Body="&lt;p&gt;I was looking at the &lt;a href=&quot;https://www.amd.com/Documents/Mantle-Programming-Guide-and-API-Reference.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mantle API documentation&lt;/a&gt; and noticed that everything is prefixed with &quot;gr&quot;, but it's never explained why the functions are prefixed with it and the letters &quot;gr&quot; do not appear anywhere in the name Mantle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does the prefix mean?&lt;/p&gt;&#xA;" OwnerUserId="8345" LastActivityDate="2018-03-09T03:11:53.570" Title="Why are functions and structs in the Mantle API prefixed with &quot;gr&quot;?" Tags="&lt;api&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6388" PostTypeId="2" ParentId="6385" CreationDate="2018-03-09T03:23:31.073" Score="1" Body="&lt;p&gt;You can use the equation of a circle to do this. A circle can be drawn using the equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$r^2 = x^2 + y^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can solve for the upper half of this by rewriting it in terms of $y$ like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$y^2 = r^2 - x^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;so&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$y = ±√(r^2 - x^2)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But we only want the positive half. So we say just:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$y = √(r^2 - x^2)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can then repeat it by using (((x - 2) % 4) - 2) as the input value. In the end the equation is this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$y = √(1^2 - (((x - 2) mod 4) - 2)^2)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/A1OgD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A1OgD.png&quot; alt=&quot;semicircles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In graph toy, it would be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;sqrt(1 - pow((((abs(x) - 2) % 4) - 2),2))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-03-09T03:23:31.073" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="6393" PostTypeId="1" AcceptedAnswerId="6400" CreationDate="2018-03-10T17:37:14.193" Score="5" ViewCount="686" Body="&lt;p&gt;These older but informative article talks about how a Kaiser windowed sinc filter is a good way to generate mips.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://number-none.com/product/Mipmapping,%20Part%201/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Inner Product - Mipmapping - Part 1 | Jonathan Blow&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://number-none.com/product/Mipmapping,%20Part%202/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Inner Product - Mipmapping - Part 2 | Jonathan Blow&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the source code it mentions isn't anywhere to be found.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain how a kaiser windowed sinc filter is calculated and/or give the kernel weights to use for convolution?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorDisplayName="user7220" LastEditDate="2018-03-23T17:29:49.200" LastActivityDate="2018-03-23T17:29:49.200" Title="Kaiser windowed sinc filter for mip mapping" Tags="&lt;texture&gt;&lt;filtering&gt;&lt;mipmap&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6395" PostTypeId="1" CreationDate="2018-03-11T06:36:55.603" Score="-1" ViewCount="351" Body="&lt;p&gt;For example, I have two transform matrix: WVP_Left and WVP_Right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I render geometry (like a rabbit) using instancing to generate left texture and right texture?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The left texture should just have only one rabbit with the WVP_Left effect, and the right texture should just have one rabbit with the WVP_Right effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For now, I get two textures which both have 2 rabbit with some overlap part.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I fix it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't want to render the left and right scene into one texture, and split it to 2 texture in another pass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I don't want to use geometry shader to finish the thing, because geometry shader will add the workload of GPU&lt;/p&gt;&#xA;" OwnerUserId="5048" LastEditorUserId="5048" LastEditDate="2018-03-12T02:20:01.680" LastActivityDate="2018-03-15T06:08:25.593" Title="How can I use instancing to generate 2 single different texture?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="6396" PostTypeId="2" ParentId="6395" CreationDate="2018-03-11T12:01:01.020" Score="1" Body="&lt;p&gt;No, this is the opposite of what instancing is for. Instancing lets you have multiple copies of the same geometry in one viewport. In your case, it would let you render into one FBO to have one texture containing multiple rabbits. To generate two separate textures, you need to do two render passes, one for each FBO. If the geometry is the same in both cases and only the transform is different, you don't need to send the geometry to the GPU twice, so it's pretty fast.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-03-11T12:01:01.020" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6397" PostTypeId="1" AcceptedAnswerId="6405" CreationDate="2018-03-11T13:23:33.390" Score="0" ViewCount="196" Body="&lt;p&gt;Where's this algorithm come from? Any references?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And a specific question, when the authors compute the transformation from world space to ray-triangle intersection coordinate space, what's the &lt;strong&gt;permutation&lt;/strong&gt; step for?&lt;/p&gt;&#xA;" OwnerUserId="7334" LastActivityDate="2018-03-13T17:50:58.540" Title="What is the algorithm used in pbrt-v3 for triangle intersection?" Tags="&lt;raytracing&gt;&lt;transformations&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6399" PostTypeId="1" CreationDate="2018-03-12T10:42:31.793" Score="2" ViewCount="103" Body="&lt;p&gt;Consider something like the following for webgl (untested but should work):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const lookup = new Map();&#xA;const isEqual3fv = (v1, v2) =&amp;gt; {&#xA; return v1[0] === v2[0] &amp;amp;&amp;amp; v1[1] === v2[1] &amp;amp;&amp;amp; v1[2] === v2[2];&#xA;}&#xA;&#xA;const setUniform3fv = (location, value) =&amp;gt; {&#xA;  if(!lookup.has(location) || !isEqual3fv(lookup.get(location), value)) {&#xA;    gl.uniform3fv(location, value);&#xA;    lookup.set(location, value);&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Would this be an optimization in most cases? Is caching the values and comparing for equality before setting the uniform generally a worthwhile optimization - or is the difference pretty negligible?&lt;/p&gt;&#xA;" OwnerUserId="8360" LastActivityDate="2018-03-12T10:42:31.793" Title="Is it worth caching uniform values?" Tags="&lt;webgl&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6400" PostTypeId="2" ParentId="6393" CreationDate="2018-03-12T13:09:41.907" Score="4" Body="&lt;p&gt;I was curious so I tried it. I used the &lt;a href=&quot;https://en.wikipedia.org/wiki/Kaiser_window&quot; rel=&quot;nofollow noreferrer&quot;&gt;Kaiser Window&lt;/a&gt; from Wikipedia: $\frac{I_0\left(\alpha\sqrt{1-x^2}\right)}{I_0\left(\alpha\right)}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Window_function#Kaiser_window&quot; rel=&quot;nofollow noreferrer&quot;&gt;This page&lt;/a&gt; has a slightly different formulation using $\pi\alpha$ instead of $\alpha$. Given the comments in the page you linked about the Kaiser window being very similar to Lanczos and how they even overlap in the graph, I suspect they also used the former formula. You can see how close they are if you &lt;a href=&quot;http://www.wolframalpha.com/input/?i=plot+I_0(4*sqrt(1-x%5E2))%2FI_0(4),+sin(PI*x)%2F(PI*x),+x%3D0+to+1&quot; rel=&quot;nofollow noreferrer&quot;&gt;plot both on Wolfram&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This left me wondering if that's what Mitchell originally meant as it's not &quot;noticably better&quot;. I could not see the difference at all with my test texture (it's there, just not noticeable). However, using the second formula, the difference in the &lt;a href=&quot;http://www.wolframalpha.com/input/?i=plot%20I_0(PI*4*sqrt(1-x%5E2))%2FI_0(PI*4),%20sin(PI*x)%2F(PI*x),%20x%3D0%20to%201&quot; rel=&quot;nofollow noreferrer&quot;&gt;plots&lt;/a&gt; is much more striking. And there is a noticeable difference in the resulting images. Whether it's better is a matter of interpretation and depends on the filter size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With $x \in \left[-1,1\right]$ , I used this C++ windowing function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;boost/math/special_functions/bessel.hpp&amp;gt;&#xA;float bessel_i0( float x )&#xA;{&#xA;    return boost::math::cyl_bessel_i( 0, x );&#xA;}&#xA;&#xA;float window_kaiser( float x )&#xA;{&#xA;    const float alpha = 4.0f * M_PI;&#xA;    float k =&#xA;        bessel_i0( alpha * sqrtf( 1.0f - x * x ) ) /&#xA;        bessel_i0( alpha );&#xA;    return k;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is the second version. Remove the &lt;code&gt;M_PI&lt;/code&gt; to get the first version which is more like Lanczos.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The modified Bessel function of the first kind seems to be a C++17 / boost thing. If you have neither, this quick hack will do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float bessel_i0( float x )&#xA;{&#xA;    float r = 1.0f;&#xA;    float term = 1.0f;&#xA;    for( int k = 1; true; ++k )&#xA;    {&#xA;        float f = x / float(k);&#xA;        term *= 0.25f * f * f;&#xA;        float new_r = r + term;&#xA;        if( new_r == r )&#xA;            break;&#xA;        r = new_r;&#xA;    }&#xA;    return r;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Just don't consider that a general replacement for a proper bessel function. However, it's fine for computing the window as far as I could tell.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the second wikipedia page I linked shows, that &lt;code&gt;window_kaiser&lt;/code&gt; can be used on a symmetric filter with $N$ weights by using $x = \frac{2n}{N-1}-1$, where $n$ is $0, 1, 2 \dots N-1$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Computing the weights of the sinc filter itself is another thing entirely as it depends on filter size, how much you're resizing, etc. I suggest posting a separate question if you don't know how do to that.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2018-03-12T13:14:47.820" LastActivityDate="2018-03-12T13:14:47.820" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6402" PostTypeId="1" AcceptedAnswerId="8619" CreationDate="2018-03-13T00:11:11.723" Score="0" ViewCount="78" Body="&lt;p&gt;I am attempting to code a simple spring mass system simulation in which a sphere pendulus hangs from a string (a spring) by the top and then another sphere (controlled by the user) can move and interact (collide) with this hanging sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have already coded the dynamics of the spring part of the simulation, but I do not know enough to add the rigid body dynamics. I would like either an explanation or a source to understand how to algorithmicaly do this simulation.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-03-13T00:16:36.620" LastActivityDate="2019-02-26T21:46:41.207" Title="kinematics and dynamics of a sphere in a spring mass system?" Tags="&lt;physically-based&gt;&lt;animation&gt;&lt;simulation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6403" PostTypeId="1" CreationDate="2018-03-13T02:51:10.990" Score="1" ViewCount="38" Body="&lt;p&gt;Can we cut bandwidth by &lt;code&gt;N&lt;/code&gt; (for &lt;code&gt;N×MSAA&lt;/code&gt;) if we access only one slice of a multisampled texture in a shader ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm thinking of doing a manual resolve in a shader, because some targets may make no sense to average. e.g. depth, encoded normals, IDs..  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the memory layout may be so that MSAA slices are close in memory which means that a fetch nearby would cache the whole line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A solution to get an answer would be to measure the performance difference of accessing all slices vs 1. But I suppose there are no guarantees of repetition across hardware ?&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2018-03-13T02:51:10.990" Title="Texture2DMS slice access and bandwidth saving" Tags="&lt;directx11&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6405" PostTypeId="2" ParentId="6397" CreationDate="2018-03-13T17:50:58.540" Score="0" Body="&lt;p&gt;The permutation is described in section 3.6.2, page 158-159.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A reason behind this permutation is that a shear matrix (which involves dividing z component of ray direction) is computed to transform from world space to ray triangle intersection coordinate space.&#xA;Permuting the coordinates is to avoid divide-by-0 error by mapping nonzero component to +z.&lt;/p&gt;&#xA;" OwnerUserId="120" LastActivityDate="2018-03-13T17:50:58.540" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6406" PostTypeId="1" CreationDate="2018-03-13T23:01:17.403" Score="5" ViewCount="160" Body="&lt;p&gt;I need to identify certain topological entities (circular holes) in a given geometry, that is, given the boundary representation of a solid, I need to identify the exact coordinates of all holes in the solid. I have been told to use a topological sweep, yet the information available is not clear to me as in how it fits in the solution of such problem. Does anyone have a recommendation or more information about what exactly is a topological sweep?&lt;/p&gt;&#xA;" OwnerUserId="8369" LastEditorUserId="6" LastEditDate="2018-03-19T20:28:07.407" LastActivityDate="2018-06-24T15:54:47.990" Title="Topological Sweep" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="6407" PostTypeId="1" AcceptedAnswerId="6413" CreationDate="2018-03-14T13:58:36.110" Score="1" ViewCount="129" Body="&lt;p&gt;&lt;a href=&quot;https://graphicdesign.stackexchange.com/q/106742/116486&quot;&gt;I asked this on Graphic Design&lt;/a&gt; but was unable to get any relevant help from them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to reverse engineer a blending mode I've seen &lt;a href=&quot;https://i.stack.imgur.com/uJS8R.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;on a picture&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/xQnci.jpg&quot; width=&quot;270&quot; height=&quot;160&quot;&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This image was created by someone else using &lt;em&gt;Adobe's Scene7&lt;/em&gt; during a &lt;em&gt;Displacement Map Filter&lt;/em&gt; operation. &lt;strong&gt;I'm only interested in the blending mechanism, not the distortion&lt;/strong&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, I was unable to reproduce this effect on other raster graphics editors. It almost looks like the images were blended with &lt;em&gt;Multiply&lt;/em&gt; followed by a recolor operation of some sort. Anyway, I'm trying to figure out the equation used for this type of blending.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at the top left corner of where the images overlap, you can see just a little bit of the background leaking to the foreground image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The original images have the same dimensions and can be found below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/U4AM4.jpg&quot; width=&quot;180&quot; height=&quot;270&quot;&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/KKgjQ.jpg&quot; width=&quot;180&quot; height=&quot;270&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea on how to duplicate this effect?&lt;/p&gt;&#xA;" OwnerUserId="8371" LastActivityDate="2018-03-15T05:26:53.837" Title="What blend mode is this?" Tags="&lt;shader&gt;&lt;image-processing&gt;&lt;blending&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6408" PostTypeId="1" AcceptedAnswerId="7816" CreationDate="2018-03-14T17:08:41.387" Score="2" ViewCount="392" Body="&lt;p&gt;I've been working on writing functions for 5 and 6 dimensional simplex noise, working off &lt;a href=&quot;https://github.com/Auburns/FastNoise/blob/master/FastNoise.cpp#L1340&quot; rel=&quot;nofollow noreferrer&quot;&gt;FastNoise's 4D function&lt;/a&gt; as a base. 2D, 3D and 4D noise all follow a very similar and recognizable pattern which can be easily extended to higher dimensions, however the output isn't looking so great:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WBMWx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WBMWx.png&quot; alt=&quot;5D Simplex Noise with visible artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Visible diagonal areas (lines) where values are all very similar, as well as diamond shapes where values don't blend together. (Does that count as discontinuous?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The full 5D Noise function is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static const FN_DECIMAL F5 = (sqrt(FN_DECIMAL(6)) - 1) / 5;&#xA;static const FN_DECIMAL G5 = (6 - sqrt(FN_DECIMAL(6))) / 30;&#xA;&#xA;FN_DECIMAL FastNoise::SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w, FN_DECIMAL v) const&#xA;{&#xA;  FN_DECIMAL n0, n1, n2, n3, n4, n5;&#xA;  FN_DECIMAL t = (x + y + z + w + v) * F5;&#xA;  int i = FastFloor(x + t);&#xA;  int j = FastFloor(y + t);&#xA;  int k = FastFloor(z + t);&#xA;  int l = FastFloor(w + t);&#xA;  int h = FastFloor(v + t);&#xA;  t = (i + j + k + l + h) * G5;&#xA;  FN_DECIMAL X0 = i - t;&#xA;  FN_DECIMAL Y0 = j - t;&#xA;  FN_DECIMAL Z0 = k - t;&#xA;  FN_DECIMAL W0 = l - t;&#xA;  FN_DECIMAL V0 = h - t;&#xA;  FN_DECIMAL x0 = x - X0;&#xA;  FN_DECIMAL y0 = y - Y0;&#xA;  FN_DECIMAL z0 = z - Z0;&#xA;  FN_DECIMAL w0 = w - W0;&#xA;  FN_DECIMAL v0 = v - V0;&#xA;&#xA;  int rankx = 0;&#xA;  int ranky = 0;&#xA;  int rankz = 0;&#xA;  int rankw = 0;&#xA;  int rankv = 0;&#xA;&#xA;  if (x0 &amp;gt; y0) rankx++; else ranky++;&#xA;  if (x0 &amp;gt; z0) rankx++; else rankz++;&#xA;  if (x0 &amp;gt; w0) rankx++; else rankw++;&#xA;  if (x0 &amp;gt; v0) rankx++; else rankv++;&#xA;&#xA;  if (y0 &amp;gt; z0) ranky++; else rankz++;&#xA;  if (y0 &amp;gt; w0) ranky++; else rankw++;&#xA;  if (y0 &amp;gt; v0) ranky++; else rankv++;&#xA;&#xA;  if (z0 &amp;gt; w0) rankz++; else rankw++;&#xA;  if (z0 &amp;gt; v0) rankz++; else rankv++;&#xA;&#xA;  if (w0 &amp;gt; v0) rankw++; else rankv++;&#xA;&#xA;  int i1 = rankx &amp;gt;= 4 ? 1 : 0;&#xA;  int j1 = ranky &amp;gt;= 4 ? 1 : 0;&#xA;  int k1 = rankz &amp;gt;= 4 ? 1 : 0;&#xA;  int l1 = rankw &amp;gt;= 4 ? 1 : 0;&#xA;  int h1 = rankv &amp;gt;= 4 ? 1 : 0;&#xA;&#xA;  int i2 = rankx &amp;gt;= 3 ? 1 : 0;&#xA;  int j2 = ranky &amp;gt;= 3 ? 1 : 0;&#xA;  int k2 = rankz &amp;gt;= 3 ? 1 : 0;&#xA;  int l2 = rankw &amp;gt;= 3 ? 1 : 0;&#xA;  int h2 = rankv &amp;gt;= 3 ? 1 : 0;&#xA;&#xA;  int i3 = rankx &amp;gt;= 2 ? 1 : 0;&#xA;  int j3 = ranky &amp;gt;= 2 ? 1 : 0;&#xA;  int k3 = rankz &amp;gt;= 2 ? 1 : 0;&#xA;  int l3 = rankw &amp;gt;= 2 ? 1 : 0;&#xA;  int h3 = rankv &amp;gt;= 2 ? 1 : 0;&#xA;&#xA;  int i4 = rankx &amp;gt;= 1 ? 1 : 0;&#xA;  int j4 = ranky &amp;gt;= 1 ? 1 : 0;&#xA;  int k4 = rankz &amp;gt;= 1 ? 1 : 0;&#xA;  int l4 = rankw &amp;gt;= 1 ? 1 : 0;&#xA;  int h4 = rankv &amp;gt;= 1 ? 1 : 0;&#xA;&#xA;  FN_DECIMAL x1 = x0 - i1 + G5;&#xA;  FN_DECIMAL y1 = y0 - j1 + G5;&#xA;  FN_DECIMAL z1 = z0 - k1 + G5;&#xA;  FN_DECIMAL w1 = w0 - l1 + G5;&#xA;  FN_DECIMAL v1 = v0 - h1 + G5;&#xA;&#xA;  FN_DECIMAL x2 = x0 - i2 + 2*G5;&#xA;  FN_DECIMAL y2 = y0 - j2 + 2*G5;&#xA;  FN_DECIMAL z2 = z0 - k2 + 2*G5;&#xA;  FN_DECIMAL w2 = w0 - l2 + 2*G5;&#xA;  FN_DECIMAL v2 = v0 - h2 + 2*G5;&#xA;&#xA;  FN_DECIMAL x3 = x0 - i3 + 3*G5;&#xA;  FN_DECIMAL y3 = y0 - j3 + 3*G5;&#xA;  FN_DECIMAL z3 = z0 - k3 + 3*G5;&#xA;  FN_DECIMAL w3 = w0 - l3 + 3*G5;&#xA;  FN_DECIMAL v3 = v0 - h3 + 3*G5;&#xA;&#xA;  FN_DECIMAL x4 = x0 - i4 + 4*G5;&#xA;  FN_DECIMAL y4 = y0 - j4 + 4*G5;&#xA;  FN_DECIMAL z4 = z0 - k4 + 4*G5;&#xA;  FN_DECIMAL w4 = w0 - l4 + 4*G5;&#xA;  FN_DECIMAL v4 = v0 - h4 + 4*G5;&#xA;&#xA;  FN_DECIMAL x5 = x0 - 1 + 5*G5;&#xA;  FN_DECIMAL y5 = y0 - 1 + 5*G5;&#xA;  FN_DECIMAL z5 = z0 - 1 + 5*G5;&#xA;  FN_DECIMAL w5 = w0 - 1 + 5*G5;&#xA;  FN_DECIMAL v5 = v0 - 1 + 5*G5;&#xA;&#xA;  t = FN_DECIMAL(0.5) - x0*x0 - y0*y0 - z0*z0 - w0*w0 - v0*v0;&#xA;  if (t &amp;lt; 0) n0 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n0 = t*t * GradCoord5D(offset, i, j, k, l, h, x0, y0, z0, w0, v0);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.5) - x1*x1 - y1*y1 - z1*z1 - w1*w1 - v1*v1;&#xA;  if (t &amp;lt; 0) n1 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n1 = t*t * GradCoord5D(offset, i + i1, j + j1, k + k1, l + l1, h + h1, x1, y1, z1, w1, v1);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.5) - x2*x2 - y2*y2 - z2*z2 - w2*w2 - v2*v2;&#xA;  if (t &amp;lt; 0) n2 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n2 = t*t * GradCoord5D(offset, i + i2, j + j2, k + k2, l + l2, h + h2, x2, y2, z2, w2, v2);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.5) - x3*x3 - y3*y3 - z3*z3 - w3*w3 - v3*v3;&#xA;  if (t &amp;lt; 0) n3 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n3 = t*t * GradCoord5D(offset, i + i3, j + j3, k + k3, l + l3, h + h3, x3, y3, z3, w3, v3);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.5) - x4*x4 - y4*y4 - z4*z4 - w4*w4 - v4*v4;&#xA;  if (t &amp;lt; 0) n4 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n4 = t*t * GradCoord5D(offset, i + i4, j + j4, k + k4, l + l4, h + h4, x4, y4, z4, w4, v4);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.5) - x5*x5 - y5*y5 - z5*z5 - w4*w4 - v5*v5;&#xA;  if (t &amp;lt; 0) n5 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n5 = t * t * GradCoord5D(offset, i + 1, j + 1, k + 1, l + 1, h + 1, x5, y5, z5, w5, v5);&#xA;  }&#xA;&#xA;  return 8 * (n0 + n1 + n2 + n3 + n4 + n5); // TODO: Find value scaler&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;GradCoord5&lt;/code&gt; consists of:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;inline FN_DECIMAL FastNoise::GradCoord5D(unsigned char offset, int x, int y, int z, int w, int v, FN_DECIMAL xd, FN_DECIMAL yd, FN_DECIMAL zd, FN_DECIMAL wd, FN_DECIMAL vd) const&#xA;{&#xA;  unsigned char lutPos = Index5D_80(offset, x, y, z, w, v) * 5;&#xA;&#xA;  return xd * GRAD_5D[lutPos] + yd * GRAD_5D[lutPos + 1] + zd * GRAD_5D[lutPos + 2] + wd * GRAD_5D[lutPos + 3] + vd * GRAD_5D[lutPos + 4];&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And &lt;code&gt;Index5D_80&lt;/code&gt; consists of:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned char FastNoise::Index5D_80(unsigned char offset, int x, int y, int z, int w, int v) const&#xA;{&#xA;  return m_perm80[(x &amp;amp; 0xff) + m_perm[(y &amp;amp; 0xff) + m_perm[(z &amp;amp; 0xff) + m_perm[(w &amp;amp; 0xff) + m_perm[(v &amp;amp; 0xff) + offset]]]]];&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The array &lt;code&gt;GRAD_5D&lt;/code&gt; is an array 400 items long, each 5 values representing a diagonal vector.&#xA;The array &lt;code&gt;m_perm&lt;/code&gt; is a 512 item long array of permutations, the values 0 to 255, in a random order, the second half of the array the same as the first half.&#xA;The array &lt;code&gt;m_perm80&lt;/code&gt; is also a 512 item long array, but the values of &lt;code&gt;m_perm&lt;/code&gt; have been modulo'd by 80. (Because there are 80 gradients in &lt;code&gt;GRAD_5D&lt;/code&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I'm not sure if the &lt;code&gt;FN_DECIMAL(0.5)&lt;/code&gt;s should actually be &lt;code&gt;FN_DECIMAL(0.6)&lt;/code&gt; as is seen in the 3D &amp;amp; 4D simplex noise functions and &lt;a href=&quot;http://staffwww.itn.liu.se/~stegu/simplexnoise/SimplexNoise.java&quot; rel=&quot;nofollow noreferrer&quot;&gt;SimplexNoise.java&lt;/a&gt; by Stefan Gustavson who wrote &lt;a href=&quot;http://staffwww.itn.liu.se/~stegu/simplexnoise/simplexnoise.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Simplex noise demystified&lt;/a&gt; in which he says the value should be changed to 0.5 (and yet doesn't do it in his own source code?). &lt;a href=&quot;https://www.csee.umbc.edu/~olano/s2002c36/ch02.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ken Perlin uses 0.6&lt;/a&gt; in his paper on Simplex Noise, but it's just a magic number which he doesn't explain the significance or origin of.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am also not sure if the &lt;code&gt;8&lt;/code&gt; used to &quot;normalise&quot; the sum of the n components when returning the final value is correct, though it's doing a reasonable job of keeping the values within a usable range. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've puzzled over &lt;a href=&quot;https://math.stackexchange.com/questions/474638/radius-and-amplitude-of-kernel-for-simplex-noise/1901116#1901116&quot;&gt;this math stackexchange question&lt;/a&gt; which purports that the normalisation value should actually be &lt;a href=&quot;https://www.wolframalpha.com/input/?i=1%2F((n%2Fsqrt(n%2B1))*(0.5-(n%2F(4*(n%2B1))))%5E4)+where+n%3D5&quot; rel=&quot;nofollow noreferrer&quot;&gt;67.6953&lt;/a&gt;.  That value does make the noise closer to 4D noise in its variation in values but causes some values to go beyond -1 and 1. It also makes the diagonal areas more obvious and the diamond artifacts clearer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/blPFq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/blPFq.png&quot; alt=&quot;Other normalisation factor, more obvious artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The normalisation factor doesn't seem to be the issue however, as it just brings the values in the -1 to 1 range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whatever the &lt;code&gt;FN_DECIMAL(0.5)&lt;/code&gt; value is officially called (I think it might be the spherical kernel radius, I can't find any hard proof), reducing it brings the values closer to 0 (effectively making the image flatter, because it makes it more likely that &lt;code&gt;t&lt;/code&gt; will be less than 0 and therefore not use the contribution from that vertex). Ken Perlin does mention &lt;em&gt;&quot;the exact radius and amplitude of the hypersphere-shaped kernel centered at each simplex need to be tuned so as to produce the best visual results for each choice of n&quot;&lt;/em&gt;, and indeed pushing the value up to &lt;code&gt;0.8&lt;/code&gt; (and bringing the normalisation value down to 6) does produce a more appealing image however it doesn't get rid of the odd diamond shapes and the diagonals can still sort of be seen as the slightly fuzzier areas under the diamond artifacts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vph7s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vph7s.png&quot; alt=&quot;Changed radius, better but still artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What could be causing these artifacts? Is it an indexing issue perhaps? Something else?&lt;/p&gt;&#xA;" OwnerUserId="6406" LastActivityDate="2018-07-15T16:48:52.890" Title="What might be causing these artifacts in 5D &amp; 6D simplex noise?" Tags="&lt;noise&gt;&lt;procedural-generation&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6409" PostTypeId="1" CreationDate="2018-03-14T18:54:37.533" Score="1" ViewCount="703" Body="&lt;p&gt;I want to write (fragment) shaders in OpenCL rather than GLSL. Is there a standard mechanism for this (from OpenGL, and ideally also from DirectX)? Are there any drawbacks to doing this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also want to write screenspace effects in OpenCL. Is the mechanism the same? Are there any drawbacks?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="8375" LastActivityDate="2018-03-15T02:59:23.777" Title="Writing OpenCL Shaders" Tags="&lt;shader&gt;&lt;opencl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6410" PostTypeId="2" ParentId="6395" CreationDate="2018-03-14T22:37:54.450" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;geometry shader will add the workload of GPU&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Everything&lt;/em&gt; you're trying to do will &quot;add the workload of GPU&quot;. The only question that matters is how much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your choices are:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Redraw everything with different FBOs. You can't just use different &lt;code&gt;glDrawBuffers&lt;/code&gt; settings, because you also need to change the depth buffers between the two draws.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Use &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Layered_Rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;layered rendering&lt;/a&gt;. Your two textures would instead be one texture object with two array layers (the same for the depth texture). There are multiple ways of going about this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render the scene twice, using a &lt;code&gt;uniform&lt;/code&gt; variable of some kind to determine which layer gets rendered to. This means having to read and execute the VS on all of the vertex data twice.&lt;/li&gt;&#xA;&lt;li&gt;Render the scene once with &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Instanced_Rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;Instanced Rendering&lt;/a&gt;, using &lt;code&gt;gl_InstanceID&lt;/code&gt; to determine which layer that particular rendering gets rendered to. This means having to read and execute the VS on all of the vertex data twice.&lt;/li&gt;&#xA;&lt;li&gt;Render the scene with a Geometry Shader that spits out two triangles for each triangle it gets, one for each layer. This only reads the vertex data and executes the VS on it once.&lt;/li&gt;&#xA;&lt;li&gt;Render the scene with &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Geometry_Shader#Instancing&quot; rel=&quot;nofollow noreferrer&quot;&gt;Geometry Shader instancing&lt;/a&gt;. The GS will be executed twice for each primitive, with a different &lt;code&gt;gl_InvocationID&lt;/code&gt; value specifying which instance the GS is being executed for. You use that ID to determine which layer to send the primitive to, as well as how to transform it. This only reads the vertex data and executes the VS on it once.&lt;/li&gt;&#xA;&lt;/ol&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;All of the variations of layered rendering will require either a Geometry Shader or access to the ARB_shader_viewport_layer_array extension or the AMD_vertex_shader_layer &amp;amp; AMD_vertex_shader_viewport_index extensions (equivalent to the ARB version). Obviously, since Options 2.3 and 2.4 already require a GS, there's no downside to using them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You should profile these options to find out which is faster for your needs. However, despite the fact that GS's are generally not fast things, the fact that 2.3 and 2.4 will eliminate lots of redundant reading and processing of vertex data, it's highly likely that the GS options will be &lt;em&gt;faster&lt;/em&gt; than using instanced rendering.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2018-03-15T06:08:25.593" LastActivityDate="2018-03-15T06:08:25.593" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6411" PostTypeId="2" ParentId="6407" CreationDate="2018-03-14T23:48:45.950" Score="1" Body="&lt;p&gt;That looks like multiplying the front image by the luminance of the shirt behind it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are multiple definitions of luminance but for a start, I think you could assume your data is sRGB and follow the &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_reverse_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;transformation to CIE&lt;/a&gt; to get the CIE Y component.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-03-14T23:48:45.950" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6412" PostTypeId="2" ParentId="6409" CreationDate="2018-03-15T02:59:23.777" Score="2" Body="&lt;p&gt;OpenCL isn't really a drawing API, it's designed for doing compute workloads across different devices, not necessarily GPUs. You can certainly write a kernel that renders to a texture in OpenCL, and have this texture be available to Open GL or D3D. AFAIK, though, you wouldn't have access to the fixed-function hardware like rasterization, attribute interpolation, and fragment blending, so you'd have to implement it yourself (unless you're writing a ray tracer). You'd also likely have to use one of the drawing APIs to present your texture to the screen, by rasterizing a full screen quad and sampling your texture at each pixel. This carries a synchronization penalty - although OpenGL and D3D can interoperate with OpenCL, they can't access the same memory at the same time, so you need to wait for control to transfer from one API to the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using compute on an already rendered buffer for screenspace effects is a good idea, since you save the fillrate of rasterizing a full screen quad every time you apply a new effect compared to the fragment shader approach. These days though, OpenGL and D3D have compute shaders built-in to handle this kind of use case. Why do you want to use OpenCL exactly? Seems to me you'd be better off using one of the rendering APIs.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-03-15T02:59:23.777" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6413" PostTypeId="2" ParentId="6407" CreationDate="2018-03-15T05:26:53.837" Score="0" Body="&lt;p&gt;To answer the question definitively, I figured out that the blending used is a combination of &lt;strong&gt;Multiply&lt;/strong&gt; and &lt;strong&gt;Hue&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After executing a &lt;em&gt;Multiply&lt;/em&gt; blend on the input images, pass the result as the background for a &lt;em&gt;Hue&lt;/em&gt; blend while using the same foreground image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/rKDMg.jpg&quot; width=&quot;292&quot; height=&quot;320&quot;&gt; &lt;img src=&quot;https://i.stack.imgur.com/DRvqw.jpg&quot; width=&quot;292&quot; height=&quot;320&quot;&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Background and foreground images for the Hue blend: on the left, the background (generated by a previous Multiply); on the right, the original foreground.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The resulting image can be seen &lt;a href=&quot;https://jsfiddle.net/f0akv7yq/9/&quot; rel=&quot;nofollow noreferrer&quot;&gt;on this JSFiddle&lt;/a&gt;. Don't panic! If you see the code you'll notice it is using the &lt;em&gt;luminosity&lt;/em&gt; blend instead of the &lt;em&gt;hue&lt;/em&gt; blend. I talked about this problem at the end of &lt;a href=&quot;https://graphicdesign.stackexchange.com/a/106807/116486&quot;&gt;my other answer&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.w3.org/TR/compositing-1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Equations&lt;/a&gt; for &lt;a href=&quot;https://www.w3.org/TR/compositing-1/#blendingmultiply&quot; rel=&quot;nofollow noreferrer&quot;&gt;all&lt;/a&gt; &lt;a href=&quot;https://www.w3.org/TR/compositing-1/#blendinghue&quot; rel=&quot;nofollow noreferrer&quot;&gt;these&lt;/a&gt; &lt;a href=&quot;https://www.w3.org/TR/compositing-1/#valdef-blend-mode-luminosity&quot; rel=&quot;nofollow noreferrer&quot;&gt;blending&lt;/a&gt; modes can be found on &lt;a href=&quot;https://www.w3.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;W3C website&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8371" LastActivityDate="2018-03-15T05:26:53.837" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6414" PostTypeId="1" CreationDate="2018-03-16T00:05:07.530" Score="0" ViewCount="103" Body="&lt;p&gt;There are 2 problems i am trying to solve involving rasterization of geometry in 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first is, my 3D texture is created with a top down viewd, so triangles that are perfectly orthogonal to the planes represented by the texture are not visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second is, due to how rasterization in OpenGL works, if a triangle is visible inside of a voxel, but too small to cover the middle of  it, it will be discarded. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general I am looking for a method that guarantees that if a voxel contains a triangle or part of a triangle ti will be marked as occupied.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-03-16T00:05:07.530" Title="How to guarantee rasterization of triangles in a voxel representation" Tags="&lt;opengl&gt;&lt;algorithm&gt;&lt;rasterizer&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6415" PostTypeId="1" AcceptedAnswerId="6416" CreationDate="2018-03-16T01:46:29.680" Score="0" ViewCount="436" Body="&lt;p&gt;So I am doing a simple FPS camera with openGL. I store the camera as 4 vector, a position vector, a lookAt vector, an up vector and a right vector. When the user presses a key, I create a rotation matrix that rotates around the up vector 10 degree then multiply the three vectors that specify the orientation of the camera with it. With these new values I create a new view matrix from glm::lookAt. However, the result I get is very weird. When I press the button to rotate, the object the camera is initially pointing at dissapears, no matter how small I set the rotation. After pressing the rotate button several more time, it appears again, then if i press more it dissappears once more.&lt;br&gt;&#xA;I feel like the code is not wrong, but my understanding of the math behind it and therefore the implementation is wrong. Can anyone explain to me this weird behavior? &#xA;Below is my code.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;look = glm::vec3(glm::rotate(theta, axis) * glm::vec4(look, 1.0f)); // theta set at 2 degree&#xA;right = glm::vec3(glm::rotate(theta, axis) * glm::vec4(right, 1.0f));&#xA;up = glm::vec3(glm::rotate(theta, axis) * glm::vec4(up, 1.0f));&#xA;glm::mat4 cameraMat = glm::lookAt(eyePos, eyePos+camera.look, camera.up);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8191" LastEditorUserId="8191" LastEditDate="2018-03-16T04:14:18.013" LastActivityDate="2018-03-16T15:00:30.807" Title="How to rotate a camera?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;camera-matrix&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="6416" PostTypeId="2" ParentId="6415" CreationDate="2018-03-16T15:00:30.807" Score="2" Body="&lt;p&gt;Promoting my comment into an answer since it identified the problem...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is confusion between degrees and radians for the angle parameter. GLM, up to version 0.9.5, was very inconsistent in how it dealt with angles, accepting degrees for some functions and radians for others. This behaviour could be overridden with &lt;code&gt;#define GLM_FORCE_RADIANS&lt;/code&gt; before including the header.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In version 0.9.6, radians everywhere became the default. Unfortunately, if you Google 'glm rotate' at the time of writing, the top result is the 0.9.4 doc page, which still describes the parameters as taking degrees, so you need to be aware of which version you are using and its default behaviour in this regard. If you still want to use degrees for your angle variables, you can convert them with &lt;code&gt;glm::radians(angle)&lt;/code&gt; before passing them as arguments.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-03-16T15:00:30.807" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6418" PostTypeId="1" CreationDate="2018-03-17T04:54:13.693" Score="2" ViewCount="230" Body="&lt;p&gt;Oblique meaning not a regular cone; its apex makes an angle to the base. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An alternate way of visualizing this: consider a sphere centered at the origin. The sphere traces a circle on the XY-plane. Now consider a point A anywhere on the sphere, and another point B on the circle. Now as B traces around the circle, length AB varies. I an trying to draw the solid (or surface) with AB as the generator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The pics and video below would give you the final idea of the solid I want to generate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UpHAr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UpHAr.png&quot; alt=&quot;orthographic view with the sphere&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/TvGlA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TvGlA.png&quot; alt=&quot;View from the top without the sphere for clarity0&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://youtu.be/Z8RAn6Dkz7w&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/Z8RAn6Dkz7w&lt;/a&gt; - animation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://ggbm.at/vrEC7tDs&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://ggbm.at/vrEC7tDs&lt;/a&gt; - geogebra worksheet (3d)&lt;/p&gt;&#xA;" OwnerUserId="8356" LastActivityDate="2018-03-18T10:40:39.580" Title="What is the technique to generate an oblique 3d cone?" Tags="&lt;webgl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6419" PostTypeId="1" AcceptedAnswerId="7422" CreationDate="2018-03-17T05:20:56.420" Score="3" ViewCount="1005" Body="&lt;p&gt;When doing random sampling, you can get noisy results if you don't use enough samples like in the shadows below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that if you use high frequency noise (aka blue noise), the noise pattern can be high frequency content only, which can then be low pass filtered (aka blur) to remove the high frequencies and leave just the lower frequency content which would be less noisy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is denoising ALWAYS about doing a low pass filter / blur? Or are there other ideas and techniques for removing noise?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SmLkV.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SmLkV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2018-03-17T05:26:13.497" LastActivityDate="2018-03-17T14:43:24.377" Title="What is the basic idea of denoising?" Tags="&lt;noise&gt;&lt;denoise&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="6420" PostTypeId="2" ParentId="6419" CreationDate="2018-03-17T10:02:43.867" Score="2" Body="&lt;p&gt;It certainly isn't &lt;em&gt;always&lt;/em&gt; about low pass filters (see for example &lt;a href=&quot;https://en.wikipedia.org/wiki/Noise_reduction#Removal&quot; rel=&quot;nofollow noreferrer&quot;&gt;here on WP on &quot;Noise Reduction&quot;&lt;/a&gt;) &lt;em&gt;but&lt;/em&gt; you have to keep in mind that in your case the noise will always have a high frequency because you can basically consider each pixel with a independent noise realization. So any way of removing noise in this situation &lt;em&gt;will&lt;/em&gt; have a low pass effect.&lt;/p&gt;&#xA;" OwnerUserId="1981" LastActivityDate="2018-03-17T10:02:43.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6421" PostTypeId="2" ParentId="6418" CreationDate="2018-03-17T11:03:53.153" Score="3" Body="&lt;p&gt;The general equation for a upright cone with the tip at $Z=0$ is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ 0 = X^2 + Y^2 - Z^2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Ignoring the points for which $Z&amp;gt;0$). If you consider slices for some constant $Z$ you get circles centered on the line $X=Y=0$. To make an oblique cone with circles along the line $X=aZ,Y=bZ$ we can just shift the coordinates accordingly and get the equation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ 0 = (X-aZ)^2 + (Y-bZ)^2 - Z^2$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(again for $Z&amp;lt;0$). You can make it narrower or wider by scaling the $Z$ coordinate. To position the tip at some other point $(x,y,z)$ you can just shift the whole thing using the transform $(X',Y',Z') := (X-x,Y-y,Z-z)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With the same idea you can easily parametrize the (upright) cone by&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(u,v) \mapsto (u\cos(v),u\sin(v),u)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or the oblique cone by&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$(u,v) \mapsto (u\cos(v)-au,u\sin(v)-bu,u)$$&lt;/p&gt;&#xA;" OwnerUserId="1981" LastEditorUserId="1981" LastEditDate="2018-03-17T16:41:08.700" LastActivityDate="2018-03-17T16:41:08.700" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="6422" PostTypeId="1" CreationDate="2018-03-17T13:07:21.043" Score="3" ViewCount="1958" Body="&lt;p&gt;Im writting a raytracer, for which I want to be able to test intersections with implicit surfaces (in my case spheres). Without applying any transformation it works great, but I would like to upgrade it to test intersections against non-uniform scaled spheres. For such purpose, I have computed the object's local to world matrix, as well as the world to local matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;During the intersection test, I first transform the ray origin and direction to the object local space:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    Vector o = ray.getOrigin();&#xA;    Vector l = ray.getDirection();&#xA;&#xA;#ifdef _RT_TRANSFORM_RAY_TO_LOCAL_SPACE&#xA;    o = worldToLocalMatrix * o;&#xA;    l = worldToLocalMatrix * Vector(l.x, l.y, l.z, 0.0f);&#xA;    l = l.Normalize();&#xA;#endif&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I perform the test, compute the intersection point in object's local space and then transform it back to world space:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector hitPoint(o + (l * distance));&#xA;        Vector hitNormal((hitPoint - center) / radius);&#xA;        hitNormal = hitNormal.Normalize();&#xA;#ifdef _RT_TRANSFORM_RAY_TO_LOCAL_SPACE&#xA;        hitPoint = localToWorldMatrix * hitPoint;&#xA;        hitNormal = localToWorldMatrix * Vector(hitNormal.x, hitNormal.y, hitNormal.z, 0.0f);&#xA;#endif&#xA;        hitNormal = hitNormal.Normalize();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I run the raytracer, it works great:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/pwN09.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pwN09.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, from some points of view (not all), I obtain wrong renders from the dielectric sphere (center in the above image) and the perfect specular (right in the above image), as well as one of the cubes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dro4c.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dro4c.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I just apply the affine transformations to the object's vertices and normals during start up(in the case of the sphere, I only apply translation since its an implicit surface), the render works flawlessly, so my guess its that the problem comes from the transformations applied to the ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To compute the local to world matrix:&#xA;&lt;code&gt;Model = rotation * translation * scale&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To compute the world to local matrix:&#xA;&lt;code&gt;InvModel = inverse(scale) * inverse(translation) * inverse(rotation)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to know if I'm applying the transformation to the ray as well as to the output hit properly&lt;/p&gt;&#xA;" OwnerUserId="8394" LastEditorUserId="209" LastEditDate="2018-03-22T12:37:41.187" LastActivityDate="2018-07-20T16:11:24.350" Title="Ray tracing: transforming ray to object's local space for intersection test" Tags="&lt;raytracing&gt;&lt;transformations&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7422" PostTypeId="2" ParentId="6419" CreationDate="2018-03-17T14:43:24.377" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is denoising ALWAYS about doing a low pass filter / blur?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, but this is the most obvious technique. A &lt;em&gt;good&lt;/em&gt; denoiser isn't just a filter that runs on the image, but actually performs the reconstruction; i.e. it's a function from random samples to an image, not a function from an image to an image.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Or are there other ideas and techniques for removing noise?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes. For years, the main family of denoise techniques worked in two parts. First, a line detection algorithm would detect the true edges in the image. Then, the output in this would set weights in a filter kernel to perform some kind of guided blur, so that the blur would be strongest (i.e. remove more frequencies) where there are no edges, and weakest (i.e. allow high frequencies) where there were edges. This would remove more noise from gradients while preserving edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nowadays, deep learning has provided a new family of techniques. Using the same technique that's producing the noise (i.e. path tracing if you want to denoise path-tracer renders), produce lots of image pairs where one has high noise (few samples) and one has low noise (high sample rate). Feed these pairs into a convolutional network, to train it to produce the low-noise images from the high-noise images. Then feed your high-noise image into the trained network, and enjoy the low-noise output. Variations on this technique include having the network produce a filter kernel for each image patch, instead of learning the output image directly; or classifying an image patch according to its structure (what edges are present), so similar patches can be handled similarly. Some networks can even take the raw samples as input and directly produce a denoised image; others can guide your adaptive sampling algorithm.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-03-17T14:43:24.377" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7423" PostTypeId="2" ParentId="6422" CreationDate="2018-03-17T16:22:03.813" Score="1" Body="&lt;p&gt;I figured out the problem. It was not related to the ray / point transformation itself, but to a problem with the camera update after moving it (Up vector wasn't being computed properly).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I leave the answer in case someone have similar issues.&lt;/p&gt;&#xA;" OwnerUserId="8394" LastActivityDate="2018-03-17T16:22:03.813" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7425" PostTypeId="2" ParentId="6418" CreationDate="2018-03-18T10:40:39.580" Score="0" Body="&lt;p&gt;Suppose you have a circle in 3D space. It can be described by its radius $r$, its center point $\mathbf{C}$, and two orthogonal unit vectors $\mathbf{A}$ and $\mathbf{B}$ that span the plane parallel to the circle. Then the parametric equations of the circle are:&#xA;$$&#xA;\mathbf{P}(u) = \mathbf{C} + r\cos(u)\mathbf{A} + r\sin(u)\mathbf{B}&#xA;$$&#xA;Now suppose you want to form an oblique cone that contains this circle and an apex point $\mathbf{Q}$. The parametric equations of this surface are:&#xA;$$&#xA;\mathbf{S}(u,v) = (1-v)\mathbf{Q} + v\mathbf{P}(u)&#xA;$$&#xA;If $v=0$, then $\mathbf{S}(u,v) = \mathbf{Q}$ for all $u$, and if $v=0$, then $\mathbf{S}(u,v) = \mathbf{P}(u)$ is a point on the circle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you fix $u$, then, as $v$ varies, you travel along a straight line through the points $\mathbf{Q}$ and $\mathbf{P}(u)$.&lt;/p&gt;&#xA;" OwnerUserId="6968" LastActivityDate="2018-03-18T10:40:39.580" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7426" PostTypeId="1" AcceptedAnswerId="7427" CreationDate="2018-03-20T10:07:33.523" Score="2" ViewCount="295" Body="&lt;p&gt;I have the parametric model of an ellipsoid like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{cases}&#xA;x=a_1\,cos \,\eta \:cos\,\omega  &amp;amp; -\pi\leq\omega\leq\pi \\ = _2\,cos\,\eta\:sin\,\omega \\ z=a_3\,sin \,\eta &amp;amp; -\frac{\pi}{2}\leq\eta\leq\frac{\pi}{2}&#xA;\end{cases}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and&lt;/p&gt;&#xA;&#xA;&lt;p&gt;\begin{cases}&#xA;n_x=\frac{1}{a_1}\,cos \,\eta \:cos\,\omega  &amp;amp; -\pi\leq\omega\leq\pi \\n_ = \frac{1}{a_2}\,cos\,\eta\:sin\,\omega \\ n_z=\frac{1}{a_3}\,sin \,\eta &amp;amp; -\frac{\pi}{2}\leq\eta\leq\frac{\pi}{2}&#xA;\end{cases}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all I do not understand the last system of equation what it represents.&#xA; Shouldn't  parameterisation of an ellipsoid be the first system alone?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have to create a polygon mesh (in webgl) from parametric model of ellipsoid. I can choose dimensions of semiaxes (namely values of $a_1$ $a_2$ and  $a_3$) and the sampling step of 2 angles (the parameters).  In this way I'm able to create in javascript with a little of code several vertices of ellipsoid. But I can't imagine how to realise the triangulation. Namely given the vertex buffer, I have to create the index buffer but in what way do I choose the indexes of the vertices to tessellate in a correct way ellipsoid surface? Is there a clever/smart way to proceed? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I implemented  that myself, in javascript (the code works):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; function degToRad(degrees)&#xA;     {&#xA;        return degrees * Math.PI / 180.0;&#xA;     }&#xA;&#xA;     function calculateVNI()&#xA;     {&#xA;     var indices = [];&#xA;     var vertices = [];&#xA;     var normals=[]&#xA;     var a1 =10;&#xA;     var a2 =5;&#xA;     var a3 =7;&#xA;     //var pi = Math.PI;&#xA;&#xA;     var step_eta   = 4; //step in degree (choose a divisor of 360)&#xA;         var step_omega = 2; //step in degree (choose a divisor of 180)&#xA;&#xA;&#xA;     var eta,omega;&#xA;     var eta_rad,omega_rad;&#xA;     var index=0;&#xA;     var x=0;&#xA;     var y=1;&#xA;     var z=2;&#xA;&#xA;     for(eta = -90 ; eta &amp;lt;= 90 ; eta+=step_eta) //I could do the cycle in rad but I can have problems in condition of termination of the cycle (float value)&#xA;         {&#xA;            eta_rad = degToRad(eta);&#xA;&#xA;            for(omega = -180 ; omega &amp;lt;= 180 ; omega +=step_omega , index+=3)&#xA;            {&#xA;               omega_rad = degToRad(omega) &#xA;               vertices[index+x]= a1 * Math.cos(eta_rad) * Math.cos(omega_rad);&#xA;               vertices[index+y]= a2 * Math.cos(eta_rad) * Math.sin(omega_rad);&#xA;               vertices[index+z]= a3 * Math.sin(eta_rad);&#xA;&#xA;                   normals[index+x]= vertices[index+x] /(Math.pow(a1,2.0)) ;&#xA;               normals[index+y]= vertices[index+y] /(Math.pow(a2,2.0));&#xA;               normals[index+z]= vertices[index+z] /(Math.pow(a3,2.0));&#xA;            }&#xA;         }&#xA;&#xA;             //Now triangolation. I believe that it needs a counterclockwise specification of vertices (else I have back-face)&#xA;     //each triangle is specified with 3 indices (gl.TRIANGLES).&#xA;&#xA;             var num_samples_omega = 360/step_omega ;   //Actually there is another sample that coincides with the first sample.&#xA;     var num_samples_eta   = 180/step_eta ;&#xA;&#xA;             var i,j;&#xA;     for(i=0,index=0 ; i&amp;lt;num_samples_eta ; i++) //il primo e l'ultimo campionamento coincidono con un solo punto ma va bene uguale&#xA;     {&#xA;         for(j=0 ; j&amp;lt;num_samples_omega ; j++,index+=6)&#xA;         {&#xA;            //Si definiscono ad ogni ciclo gli indici dei 2 triangoli del poligono formato da 4 campioni (due per ciascuna sezione di ellisse adiacente)&#xA;             indices[index]=i*num_samples_omega +i+j; //I could use index++ but like this is more clear.&#xA;                             indices[index+1]=(i+1)*num_samples_omega +2+i+j;&#xA;             indices[index+2]=(i+1)*num_samples_omega +1+i+j;&#xA;&#xA;             indices[index+3]=i*num_samples_omega +i+j;&#xA;             indices[index+4]=i*num_samples_omega +1 +i+j;&#xA;             indices[index+5]=(i+1)*num_samples_omega +2 +i+ j;&#xA;         }&#xA;     }&#xA;&#xA;  //alert(&quot;num vertici&quot;+vertices.length+&quot;\n&quot;+&quot;indice massimo:&quot;+ indices[index-1])&#xA;&#xA;&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4981" LastEditorUserId="4981" LastEditDate="2018-03-20T20:49:57.600" LastActivityDate="2018-03-21T09:00:21.007" Title="Triangulation of vertices of an ellipsoid" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;webgl&gt;&lt;triangulation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7427" PostTypeId="2" ParentId="7426" CreationDate="2018-03-20T12:08:21.617" Score="4" Body="&lt;p&gt;If you sample the two parameters $\eta$ and $\omega$ with steps $d\eta$ and $d\omega$, then you'll get a grid of points $v_{ij} = f(i\;d\eta,j\;d\omega)$.  Any four adjacent points will define a quadrilateral.  To get triangles, you just have to split each quad in two by a diagonal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Fm0tG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Fm0tG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in the example, you'd split the quadrilateral $\{v_{00},v_{01},v_{11},v_{10}\}$ into two triangles $\{v_{00},v_{01},v_{10}\}$ and $\{v_{01},v_{11},v_{10}\}$.  You'll want to make sure the points come in the right order so the triangle orientations match (or you'll end up backface-culling half of your triangles.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your second equation, for $n_{xyz}$, is finding the &lt;em&gt;normal&lt;/em&gt; of each vertex, which you can use for shading.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastEditorUserId="7647" LastEditDate="2018-03-21T09:00:21.007" LastActivityDate="2018-03-21T09:00:21.007" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7428" PostTypeId="1" CreationDate="2018-03-20T15:15:08.173" Score="2" ViewCount="3275" Body="&lt;p&gt;Inside of my application I am trying to convert a MTLTexture into a CGImage or CIimage for use in other parts of the app. I am having a difficult time doing so because none of the example code I find seems to work properly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For some reason something breaks on each and every one of them. Here are my attempts and why they dont work. If you could give me ideas on why that would be appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of my textures are in brga8Unorm format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Method 1&lt;/strong&gt; is to copy the pixels into an unsafe mutable pointer and use that to directly create a CGTexture. It creates a textures of all 0s&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;func toImage() -&amp;gt; NSImage? {&#xA;    let texture = self&#xA;    let width = texture.width&#xA;    let height = texture.height&#xA;    let bytesPerRow = width * 4&#xA;    let data = UnsafeMutableRawPointer.allocate(bytes: bytesPerRow * height, alignedTo: 4)&#xA;    defer {&#xA;        data.deallocate(bytes: bytesPerRow * height, alignedTo: 4)&#xA;    }&#xA;&#xA;    let region = MTLRegionMake2D(0, 0, width, height)&#xA;    texture.getBytes(data, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0)&#xA;    var buffer = vImage_Buffer(data: data, height: UInt(height), width: UInt(width), rowBytes: bytesPerRow)&#xA;&#xA;    let map: [UInt8] = [2, 1, 0, 3]&#xA;    vImagePermuteChannels_ARGB8888(&amp;amp;buffer, &amp;amp;buffer, map, 0)&#xA;&#xA;    guard let colorSpace = CGColorSpace(name: CGColorSpace.genericRGBLinear) else { return nil }&#xA;    guard let context = CGContext(data: data, width: width, height: height, bitsPerComponent: 8, bytesPerRow: bytesPerRow,&#xA;            space: colorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipLast.rawValue) else { return nil }&#xA;    guard let cgImage = context.makeImage() else { return nil }&#xA;&#xA;    return NSImage(cgImage: cgImage, size: NSSize(width: width, height: height))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Method 2&lt;/strong&gt; tries to use CImage to do the job however CImage reports &lt;code&gt;Cannot render image (with an input Metal texture) using a metal context.&lt;/code&gt; and returns nil&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;extension MTLTexture {&#xA;    func toImage() -&amp;gt; CGImage? {&#xA;        let context = CIContext()&#xA;        let texture = self&#xA;        let cImg = CIImage(mtlTexture: texture, options: nil)!&#xA;        let cgImg = context.createCGImage(cImg, from: cImg.extent)!&#xA;        return cgImg&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;This last method&lt;/strong&gt; doesnt even try to convert the image it is just trying to determine if the image is blank (all 0s) or not however even on fully green or even textured images it says they are blank.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;func anythingHere(_ texture: MTLTexture) -&amp;gt; Bool {&#xA;    let width = texture.width&#xA;    let height = texture.height&#xA;    let bytesPerRow = width * 4&#xA;&#xA;    let data = UnsafeMutableRawPointer.allocate(bytes: bytesPerRow * height, alignedTo: 4)&#xA;    defer {&#xA;        data.deallocate(bytes: bytesPerRow * height, alignedTo: 4)&#xA;    }&#xA;&#xA;    let region = MTLRegionMake2D(0, 0, width, height)&#xA;    texture.getBytes(data, bytesPerRow: bytesPerRow, from: region, mipmapLevel: 0)&#xA;    var bind = data.assumingMemoryBound(to: UInt8.self)&#xA;&#xA;    var sum:UInt8 = 0;&#xA;    for i in 0..&amp;lt;width*height {&#xA;        sum += bind.pointee&#xA;        bind = bind.advanced(by: 1)&#xA;    }&#xA;    return sum != 0&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Clearly I am doing something fundamentally wrong as none of these methods are actually producing results. What am I doing wrong? What is the right way to do this?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorDisplayName="user7220" LastEditDate="2018-03-23T17:26:10.143" LastActivityDate="2018-09-23T17:46:17.997" Title="MTLTexture getBytes returning blank image" Tags="&lt;texture&gt;&lt;mobile&gt;&lt;metal&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7429" PostTypeId="1" CreationDate="2018-03-20T17:24:04.687" Score="4" ViewCount="68" Body="&lt;p&gt;I had an application that was originally &lt;strong&gt;single threaded&lt;/strong&gt; and worked as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;gather the items to be drawn (occlusion / frustrum culling / sorting into batches)&lt;/li&gt;&#xA;&lt;li&gt;draw items using an immediate context&lt;/li&gt;&#xA;&lt;li&gt;present&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I decided to use a deferred context and &lt;strong&gt;parallelize step 2&lt;/strong&gt; as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;gather the items to be drawn (occlusion / frustrum culling / sorting into batches)&lt;/li&gt;&#xA;&lt;li&gt;draw items in parallel used a deferred context &lt;/li&gt;&#xA;&lt;li&gt;execute the command lists for step 2)&lt;/li&gt;&#xA;&lt;li&gt;present&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;However, I saw almost no performance benefit.  I finally decided move the &quot;execute command lists&quot; after &lt;strong&gt;present&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;gather the items to be drawn (occlusion / frustrum culling / sorting into batches)&lt;/li&gt;&#xA;&lt;li&gt;draw items in parallel used a deferred context&lt;/li&gt;&#xA;&lt;li&gt;present (is actually presenting the previous frame's scene now)&lt;/li&gt;&#xA;&lt;li&gt;execute the command lists&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I saw a huge increase in performance with this method.  My theory as to why is this worked is that the are basically 3 bottlenecks&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;graphics card (triggered by present)&lt;/li&gt;&#xA;&lt;li&gt;my app's cpu thread &lt;/li&gt;&#xA;&lt;li&gt;device driver cpu thread (triggered by executing the command lists)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In my original order, each successive stage was blocked by the previous one to be finished.  However now, I believe that all three are running in parallel:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;present with (frame - 2) data&lt;/li&gt;&#xA;&lt;li&gt;device driver thread with (frame - 1) data&lt;/li&gt;&#xA;&lt;li&gt;my cpu thread to run with this frame's data&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;My question is, is this a common pattern or is there some better way to achieve maximum parallization while using deferred context rendering?&lt;/p&gt;&#xA;" OwnerUserId="3332" LastEditorUserId="3332" LastEditDate="2018-03-21T02:10:18.263" LastActivityDate="2018-03-21T02:10:18.263" Title="Drawing &quot;after&quot; Present to achieve better performance" Tags="&lt;directx11&gt;&lt;directx&gt;&lt;multithreading&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7430" PostTypeId="2" ParentId="2410" CreationDate="2018-03-21T14:54:14.850" Score="1" Body="&lt;p&gt;Taken from &lt;a href=&quot;https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia's article on Cohen-Sutherland&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Both endpoints are in different regions: in case of this nontrivial situation the algorithm finds one of the two points that is outside the viewport region (there will be at least one point outside). The intersection of the outpoint and extended viewport border is then calculated (i.e. with the parametric equation for the line), and this new point replaces the outpoint. The algorithm repeats until a trivial accept or reject occurs.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So yes, since your new first point is inside the viewport, but your second point is outside, the situation is non-trivial (i.e. no &quot;go render it all&quot; or &quot;go discard it all&quot;), it will repeat with the second point. Afterwards, both points will be inside the viewport, therefore it is a trivial draw and no further action is needed.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-03-21T14:54:14.850" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7431" PostTypeId="1" AcceptedAnswerId="7432" CreationDate="2018-03-21T15:46:05.993" Score="4" ViewCount="215" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rRahN.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rRahN.jpg&quot; alt=&quot;Picture here&quot;&gt;&lt;/a&gt;&#xA;I unwrap UV from sphere mesh to grid and put texture to align with UV grid too. When white and black border of texture fall between UV columns, I get jagged edge like in the picture. This only happens with double-curve mesh. I want to know what cause this to happens?&lt;/p&gt;&#xA;" OwnerUserId="8415" LastEditorUserId="506" LastEditDate="2018-03-22T06:30:10.683" LastActivityDate="2018-03-22T06:30:10.683" Title="Jagged texture's edge on perfectly straight UV of sphere mesh" Tags="&lt;texture&gt;&lt;shader&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7432" PostTypeId="2" ParentId="7431" CreationDate="2018-03-21T19:54:33.507" Score="5" Body="&lt;p&gt;It looks like distortion because the trapezoids are rendered as two triangles by the GPU. This leads to incorrect UV interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Try this: draw a horizontally symmetrical trapezoid with the top being much shorter than the bottom. Then draw one of its diagonals to split it into two triangles. Place a mark at the midpoint of that diagonal. It should be obvious the mark is not at the horizontal center of the trapezoid. Yet that mark is where the middle of the interpolated texture coordinates will be. Your border will go through the mark but also through the center of the top and bottom edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You should not have that problem when producing a final image with any decent renderer.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-03-21T19:54:33.507" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7433" PostTypeId="1" CreationDate="2018-03-23T12:35:11.467" Score="1" ViewCount="142" Body="&lt;p&gt;Here are its docs: &lt;a href=&quot;https://processing.org/reference&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://processing.org/reference&lt;/a&gt;.&#xA;Processing is described as a 'language built with the purpose of teaching non-programmers the fundamentals of computer programming in a visual context'.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, &lt;strong&gt;how does this language relate to the real-world computer graphics tools&lt;/strong&gt;?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is it similar to some low-level library maybe?   &lt;/li&gt;&#xA;&lt;li&gt;Is the concept of a repeating &lt;code&gt;draw() { background(255) }&lt;/code&gt; (in order to draw each new frame of an animation) used in real-world libraries? &lt;/li&gt;&#xA;&lt;li&gt;Are the same&#xA;methods/concepts used (&lt;code&gt;pushMatrix&lt;/code&gt;, &lt;code&gt;popMatrix&lt;/code&gt;, &lt;code&gt;rotate&lt;/code&gt;,&#xA;&lt;code&gt;translate&lt;/code&gt;)?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="8434" LastActivityDate="2018-04-26T08:15:39.913" Title="How does Processing language relate to the industry standard?" Tags="&lt;processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7434" PostTypeId="1" AcceptedAnswerId="7435" CreationDate="2018-03-23T13:37:40.120" Score="4" ViewCount="245" Body="&lt;p&gt;One of my friend got a pretty pretty Chinese hand-writing font. However, the font has no bold version, since it is handwritten. And I would like to help generate a bold one automatically by code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I searched the Internet but didn't find any materials about it. My friend told me that his Kindle could &quot;bold&quot; that font automatically by setting &quot;contrast&quot;. So I tried to firstly convert the outline font to bitmap, then change the contrast of the glyphs one by one, and finally output a bitmap &quot;bolded&quot; font. Everything went well except the processed font is aliased, i.e. looks blocky, since that the bitmaps is binary images, i.e. there are no gray pixels. But I can't find a popular font type that supports bitmap plus gray pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is there an algorithm to bold an outline font? What is it?&lt;/p&gt;&#xA;" OwnerUserId="8435" LastEditorUserId="8435" LastEditDate="2020-07-24T04:26:03.147" LastActivityDate="2020-07-24T04:26:03.147" Title="Is there an algorithm to bold an outline font?" Tags="&lt;font-rendering&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7435" PostTypeId="2" ParentId="7434" CreationDate="2018-03-23T15:46:21.137" Score="6" Body="&lt;p&gt;I think &lt;a href=&quot;https://en.wikipedia.org/wiki/Dilation_(morphology)&quot; rel=&quot;noreferrer&quot;&gt;dilation&lt;/a&gt; would be close enough to what you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is likely that font processing software would have more advanced algorithms to avoid rounding all the corners, among other things. Fonts are a whole separate world with a lot of rules about how things should be done to look right. No simple image processing algorithm will respect all those rules.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-03-23T15:46:21.137" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7436" PostTypeId="2" ParentId="7433" CreationDate="2018-03-23T17:47:15.733" Score="1" Body="&lt;p&gt;It does not relate to low level libraries. Yes, usually each frame is drawn separately, nothing can change if i dont change anything. However the draw loop is often handled by somebody else in for example game engines, etc. So in fact processing is often lower level stuff than what many people would do day to day.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pushing matrix state is pretty common, it exists even in graphics languages from 1970's.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2018-03-23T18:48:26.047" LastActivityDate="2018-03-23T18:48:26.047" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7437" PostTypeId="1" CreationDate="2018-03-23T18:14:18.193" Score="2" ViewCount="394" Body="&lt;p&gt;New to writing shaders, please forgive any naivety in the question!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Parallax mapping in any of its ray-marchy variants (e.g. steep parallax, cone step mapping, POM) generates fake geometry on a material, generally nearly indistinguishable from real geometry and at a much higher resolution than is practical using GPU tessellation. However, the geometry created does not extend outside the initial bounds of the triangle being rendered (unlike with GPU tessellation) - so e.g. a parallax mapped sphere still has circular edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm want to try adapting a parallax shader (preferably OpenGL, any high quality variation of parallax mapping will do though I gather cone stepping is pretty much the state of the art) to write outside of the poly bounds using gl_FragDepth (and enabling conservative depth output).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems to be theoretically possible (see this Unity example &lt;a href=&quot;https://forum.unity.com/threads/modifying-depth-when-parallax-mapping.364037/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Modifying depth when parallax mapping | Unity Community&lt;/a&gt;). However that post did not include any shader code and got no responses.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is anyone aware of an existing implementation of this (with source available), or else could give me a good idea of how I should proceed with implementing it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many thanks.   &lt;/p&gt;&#xA;" OwnerUserId="8375" LastEditorDisplayName="user7220" LastEditDate="2018-04-09T09:41:42.090" LastActivityDate="2018-05-10T04:54:47.027" Title="Parallax/relief mapping with gl_FragDepth and conservative depth" Tags="&lt;shader&gt;&lt;raymarching&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7438" PostTypeId="1" CreationDate="2018-03-23T18:43:14.263" Score="0" ViewCount="49" Body="&lt;p&gt;I have a white line on black background. Because of the pixel geometry the line does not look really white; one edge looks red-isch, the other blue-isch. Other fore- and background yield other sensations. Pixel geometry is striped RGB, DPI is ~90, viewing distance about an arms length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any software based solution or maybe visual design that makes this less appearant, assuming we know the screen pixel geometry in advance?&lt;/p&gt;&#xA;" OwnerUserId="3041" LastActivityDate="2018-03-23T18:46:29.013" Title="What remedies are there for percieved color artifacts due to pixel geometry?" Tags="&lt;color&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7439" PostTypeId="2" ParentId="7438" CreationDate="2018-03-23T18:46:29.013" Score="1" Body="&lt;p&gt;In computer typography, the technique for adjusting strokes so that they align with the pixel grid is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Font_hinting&quot; rel=&quot;nofollow noreferrer&quot;&gt;hinting&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The color artifacts you are seeing are due to another technique called &lt;a href=&quot;https://en.wikipedia.org/wiki/Subpixel_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;subpixel rendering&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8436" LastActivityDate="2018-03-23T18:46:29.013" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7440" PostTypeId="2" ParentId="7434" CreationDate="2018-03-24T03:55:32.083" Score="7" Body="&lt;p&gt;The best way to do proper outlines, is unfortunately, also the hardest. It involves calculating an offset curve, usually from the &lt;a href=&quot;https://en.wikipedia.org/wiki/Medial_axis&quot; rel=&quot;noreferrer&quot;&gt;medial axis&lt;/a&gt; or &lt;a href=&quot;https://en.wikipedia.org/wiki/Straight_skeleton&quot; rel=&quot;noreferrer&quot;&gt;straight skeletons&lt;/a&gt;, which are non-trivial to calculate. Once you have those, you can calculate the distance of any point from the input object and decide whether to draw the outline or bolding, or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simpler way to do it, which doesn't look quite as nice, is to use a MinMax filter. This is a sliding 2D box filter that calculates either the minimum or maximum value within the box at each input pixel. If you have black text on a white background, you can use the min filter to generate an outline. Use the max if it's white text on a black background. Other shapes, such as a circular area will produce different results that may be better for some fonts. In most cases, you'll end up either rounding off or squaring off corners as the size of the filter increases.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-03-24T03:55:32.083" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7442" PostTypeId="2" ParentId="6406" CreationDate="2018-03-25T04:04:30.360" Score="1" Body="&lt;p&gt;Since nobody else has provided a more useful and to the point solution, I'll offer some crude theoretical grounds to a solution of a simpler but related problem. The issue of knowing at least if there are holes (let alone describing them). You could use the methods employed to solve Poincaré conjecture but for 3d sphere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the 3d mesh can be suitably represented by a nice enough manifold, Ricci flow can be used. So in theory it is a matter of turning the discrete polygons into curved surfaces, and matching their curvature at boundaries. A suitable algorithm should exist for this, then solving roughly a diffusion differential equation once the continuous surface has been correctly parameterized. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intuitively I can only wager in cases that the surface is not homomorphic to a sphere, the solution would be the minimum radius of the hole, thus describing the hole. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also I'm not sure that in cases there are more than one whole you would have multiple unique solutions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure either if there are discretized theorems rather that go the other way and probably are better in terms of performance. &lt;/p&gt;&#xA;" OwnerUserId="8444" LastEditorUserId="209" LastEditDate="2018-03-26T14:32:51.263" LastActivityDate="2018-03-26T14:32:51.263" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7443" PostTypeId="2" ParentId="306" CreationDate="2018-03-25T18:41:47.993" Score="3" Body="&lt;p&gt;Quite interesting! I'm the author of the valve signed distance paper. Sorry that it's a little sparse on implementation details.&#xA;I only included the two channel example as future work - I didn't have a generator. I figured something like generating a high res sdf and then segmenting based upon the angle of the gradient of the sdf would be a reasonable tactic. But never got to it.&#xA;Any multichannel scheme has to be weighed against using higher res single channel data of the same memory footprint, for the magnification ratios your app needs.&lt;/p&gt;&#xA;" OwnerUserId="8448" LastActivityDate="2018-03-25T18:41:47.993" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7444" PostTypeId="1" CreationDate="2018-03-25T19:38:04.183" Score="2" ViewCount="3483" Body="&lt;p&gt;The Core i3 says it has &quot;integrated graphics&quot; with Intel 630.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this mean it is like a mini GPU?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In which case can use things like CUDA to speed up C sharp programs?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there much software that takes advantage of integrated graphics? Like does photoshop access the integrated graphics?&lt;/p&gt;&#xA;" OwnerUserId="8449" LastActivityDate="2018-03-26T15:28:20.163" Title="Can you do GPGPU on integrated graphics like Intel HD 630 on Core i3?" Tags="&lt;cuda&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7445" PostTypeId="2" ParentId="7444" CreationDate="2018-03-25T20:15:46.217" Score="2" Body="&lt;p&gt;CUDA is only available on nvidia cards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The open technology is OpenCL: &lt;a href=&quot;https://es.wikipedia.org/wiki/OpenCL&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://es.wikipedia.org/wiki/OpenCL&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another alternative is to use Compute Shaders. DirectX, OpenGL, and Vulkan all support compute shaders&lt;/p&gt;&#xA;" OwnerUserId="8450" LastEditorUserId="310" LastEditDate="2018-03-26T15:28:20.163" LastActivityDate="2018-03-26T15:28:20.163" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7446" PostTypeId="1" CreationDate="2018-03-26T15:14:28.467" Score="3" ViewCount="110" Body="&lt;p&gt;What improvements and alternatives have been developed since HLBVH was introduced in the 2010 paper &lt;a href=&quot;http://research.nvidia.com/publication/hlbvh-hierarchical-lbvh-construction-real-time-ray-tracing&quot; rel=&quot;nofollow noreferrer&quot;&gt;HLBVH: Hierarcihcal LBVH Construction for Real-Time Ray Tracing of Dynamic Geometry&lt;/a&gt; by J. Pantaleoni and D. Luebke?&lt;/p&gt;&#xA;" OwnerUserId="2500" LastEditorUserId="2479" LastEditDate="2018-03-29T12:08:17.183" LastActivityDate="2018-03-29T12:08:17.183" Title="What techniques are used to build ray intersection acceleration structures on the GPU?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;gpu&gt;&lt;data-structure&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="7448" PostTypeId="2" ParentId="44" CreationDate="2018-03-27T14:23:54.927" Score="1" Body="&lt;p&gt;The great thing is we can finally predict scan-line exact raster accuracy with no access to a per-scanline query:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=OZ7Loh830Ec&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=OZ7Loh830Ec&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have come up with the exact microsecond-accurate formulas as a VSYNC offset, to predict the position of a tearline.  Tearlines during VSYNC OFF are always raster-exact, so you can steer them out of visibility during strip-level &quot;simulated front-buffer rendering&quot; via repeated VSYNC OFF buffer swapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pay attention to forum thread -- there is some open source code being continually added -- &lt;a href=&quot;https://forums.blurbusters.com/viewtopic.php?f=10&amp;amp;p=32002&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://forums.blurbusters.com/viewtopic.php?f=10&amp;amp;p=32002&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8460" LastActivityDate="2018-03-27T14:23:54.927" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7449" PostTypeId="1" CreationDate="2018-03-27T14:59:41.983" Score="1" ViewCount="236" Body="&lt;p&gt;I'm planning the port of our DX based renderer to OpenGL. The target will be Desktop OpenGL 4.x. For DX we use shader reflection but as far as I know OpenGL just has &lt;em&gt;glGetProgramInterfaceiv&lt;/em&gt; , &lt;em&gt;glGetUniform&lt;/em&gt; and frieds. Theres also SPIR-V (I have never worked with it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main concerns right now are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Using gl*:&lt;/strong&gt; it will be done at runtime, so this will be potentially slow as there are a lot of shaders to load (+ the interface is ugly as fuck). &lt;em&gt;EDIT: I guess this could be done on a prebuild step too (?).&lt;/em&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Use SPIR-V:&lt;/strong&gt; means that we need to add another build step and I don't see much doc around. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I would like to hear advice from people with experience with this.&#xA;Thanks a lot!&lt;/p&gt;&#xA;" OwnerUserId="7107" LastEditorUserId="7107" LastEditDate="2018-03-31T23:31:14.933" LastActivityDate="2018-03-31T23:31:14.933" Title="Dealing with GL reflection" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7450" PostTypeId="1" CreationDate="2018-03-27T19:55:48.717" Score="6" ViewCount="214" Body="&lt;p&gt;I'm encountering some issues supersampling in HDR for an SDR result and was curious what the usual method for doing this is.  Notice how pixelated the edge of the white sphere is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IRvHA.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IRvHA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's how I render the image:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Get the (linear HDR) shaded color for 4 stratified samples per pixel.&lt;/li&gt;&#xA;&lt;li&gt;Apply a box blur (average them)&lt;/li&gt;&#xA;&lt;li&gt;Convert from linear to sRGB&lt;/li&gt;&#xA;&lt;li&gt;Clamp to [0,1]&lt;/li&gt;&#xA;&lt;li&gt;Convert from [0,1] to [0,255] and write the result.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I believe the issue here is that along the edge of the white ssphere, the values are either very low (background color aprox 0.02) or very high (the sphere has a color of 10,10,10), and that combining them makes a number much larger than 1 which ends up getting clamped to 1, completely destroying the blending at the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That makes sense but now I'm not quite sure how to solve it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried applying Reinhard tone mapping after step 3, thinking that would help by keeping everything in the [0,1] range, and preserving the smoothness between the colors.  That helped only a very small amount.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HjhjK.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HjhjK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My only other ideas for doing this are...&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Blend my samples in sRGB space. This would be incorrect though.&lt;/li&gt;&#xA;&lt;li&gt;At step 1.5 apply tone mapping to the samples, then at step 2.5, apply inverse tone mapping to the combined result.  This feels like a hack.&lt;/li&gt;&#xA;&lt;li&gt;Use harmonic mean to combine the colors instead of a regular mean, to make the average favor smaller numbers when present.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="56" LastActivityDate="2018-03-27T19:55:48.717" Title="Supersampling HDR" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;subpixel-rendering&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="7451" PostTypeId="2" ParentId="44" CreationDate="2018-03-28T08:01:55.717" Score="0" Body="&lt;p&gt;If it's of interest, the Dreamcast had a &quot;racing the beam&quot; rendering mode, whereby it was able to dedicate a relatively small fraction of memory to framebuffer pixels (e.g.  64 scan lines) and it would render rows of 32 in turn, synchronised to the display update.  This however, was only used to save memory. I doubt anyone was generating &quot;modified&quot; geometry for latter parts of the display.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2018-03-28T08:01:55.717" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7452" PostTypeId="2" ParentId="7449" CreationDate="2018-03-28T08:34:31.547" Score="1" Body="&lt;p&gt;opengl has several methods that together let you reflect the shader IO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However it is much simpler if the shader IO is uniform across all your shaders. IOW have a set of default bindings/locations for everything. Then you only need some meta data for each shader where you deviate from those defaults for some reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You then only need to query that the binding exists to see whether you need to provide the data. This has the added bonus that if an input gets optimized out you'll not waste time giving data it doesn't need.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-03-28T08:34:31.547" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7453" PostTypeId="1" CreationDate="2018-03-28T13:16:43.943" Score="1" ViewCount="71" Body="&lt;p&gt;I have some OpenGL based software and I would like to set up some automated testing using image comparison, but one problem we always have is that the screenshots we take always have some small differences across machines, usually due to graphics driver difference or something else (?).  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What strategies are there for getting consistent screenshots across machines with varying hardware and graphics drivers?&lt;/p&gt;&#xA;" OwnerUserId="3332" LastActivityDate="2018-03-28T15:38:56.060" Title="How to take consistent screenshots across multiple machines?" Tags="&lt;opengl&gt;&lt;opengl-es&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7455" PostTypeId="1" CreationDate="2018-03-28T14:36:44.767" Score="2" ViewCount="297" Body="&lt;p&gt;I suspect the answer is no, but thought I'd ask anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems that other than using nearest neighbour and bilinear interpolations, there is nothing you can do to determine how two adjacent pixels are interpolated ... such as applying an edge preserving interpolation, or adding some procedural variation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd love to be wrong! If indeed there is no way to do this, might there be a practical solution which involves creating a higher resolution (maybe much higher) texture (like a &quot;mipmap level -2&quot;) on the fly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If done naively I guess it would be very memory-hungry ... perhaps there is some way it could be done to a reusable buffer, or some way ensuring only part of the image would be processed at a time (like an OpenCL/CUDA/Compute Shader workgoup) thus limiting the buffer size. (Perhaps Vulkan could help somehow?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously it would be done on a LOD basis ... no need to do it on far away textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks  &lt;/p&gt;&#xA;" OwnerUserId="8375" LastActivityDate="2018-03-28T17:14:12.423" Title="Is sub-texel shading possible?" Tags="&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7456" PostTypeId="2" ParentId="7453" CreationDate="2018-03-28T15:16:58.927" Score="2" Body="&lt;p&gt;What you want cannot reasonably be done. No graphics API defines byte-accurate results. Every implementation will have its own variances, which will be visible in the results. OpenGL provides no insurance that you will get invariant results across implementations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the end of the day, you can't do testing in this fashion.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-03-28T15:16:58.927" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7457" PostTypeId="2" ParentId="7453" CreationDate="2018-03-28T15:38:56.060" Score="5" Body="&lt;p&gt;Nicol Bolas explains why you can't expect pixel-accurate reproductions, but that doesn't mean you can't test with screenshots.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't compare the screenshots byte-for-byte. Instead, use a &lt;em&gt;perceptual diff&lt;/em&gt; to quantify how different the renders are. You can then set a threshold in your test and have the test fail if the renders are too different. A harsh threshold will let you filter out the rounding differences between platforms, and the slight differences around object silhouettes, but still detect objects in the wrong place or inconsistent texturing. A more forgiving threshold will allow bigger differences in texturing (or even with different shader versions or extensions, if you have different rendering paths for different hardware), and only complain if you have gross differences such as missing lights or a completely different scene being rendered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;http://pdiff.sourceforge.net/&quot; rel=&quot;noreferrer&quot;&gt;pdiff tool&lt;/a&gt; is commonly used for this task, and I've set up test systems based on it before.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-03-28T15:38:56.060" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7458" PostTypeId="2" ParentId="7455" CreationDate="2018-03-28T17:14:12.423" Score="4" Body="&lt;p&gt;The GPU hardware only supports nearest-neighbor, bilinear, trilinear, and anisotropic texture filtering. However, nothing stops you from implementing your own texture filtering in the pixel shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do this, you'd use &lt;a href=&quot;http://docs.gl/sl4/textureGather&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;textureGather&lt;/code&gt;&lt;/a&gt; to grab a 2×2 block of texels around your sample point. Then you'd manually calculate the position of the sample point relative to the texel centers. Armed with the raw texels and the interpolation position, you can then apply whatever interpolation function you like.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The position calculation would be something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 textureSize; // texture's width and height&#xA;vec2 offset = fract(texCoord * textureSize + (-0.5 + 1.0/512.0));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The 1/512 offset in there is needed as a rounding correction on certain GPUs, to ensure that &lt;code&gt;fract()&lt;/code&gt;'s output steps from 1 to 0 at the exact same point that &lt;code&gt;textureGather&lt;/code&gt; switches texels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an example, to re-implement bilinear filtering, you'd do this (assuming a single-channel texture for simplicity):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 texels = textureGather(...);&#xA;float result = mix(mix(texels.w, texels.z, offset.x),&#xA;                   mix(texels.x, texels.y, offset.x),&#xA;                   offset.y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But in practice, you'd be replacing the above with your own interpolation logic. This will for sure be slower than using hardware bilinear interpolation, but it may be an acceptable cost for your app.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need more than 2×2 block of texels, you can also use multiple calls to &lt;a href=&quot;http://docs.gl/sl4/textureGatherOffset&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;textureGatherOffset&lt;/code&gt;&lt;/a&gt; to grab more of the surrounding region, 2×2 at a time.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;As for generating a higher-resolution version of the texture on the fly, that can certainly also be done. It would be an extension of texture streaming techniques that load larger mip levels from disk only when needed. Here, you'd be procedurally generating the larger mip levels instead of loading them, but it's a similar idea. Unfortunately I don't have a good reference handy for how to do this. (It's somewhat related to &lt;a href=&quot;http://mrelusive.com/publications/presentations/2012_siggraph/Virtual_Texturing_in_Software_and_Hardware_final.pdf&quot; rel=&quot;noreferrer&quot;&gt;virtual texturing&lt;/a&gt;, but less complicated—for just plain texture streaming, you don't need sparse textures or a page table, etc.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there is unfortunately no GPU hardware support for doing the thing you suggested of avoiding the extra storage, by processing the texture only a piece at a time. Doing that in hardware (“texel shaders” that would generate texel values on-demand as they are sampled by fragment shaders) is an idea that has been proposed many times but so far has not happened.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It might be possible to do it in software by having fragment shaders append sample requests into a queue, then switching to a different shader to service those requests, then re-running the fragment shaders with the results...but that would take a lot of work and might not be very fast. It would for sure be a research project. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unless you have a good way of determining in advance which texels are likely to be needed, it would be a lot more practical to just generate the entire texture, assuming memory and performance budgets allow for it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-03-28T17:14:12.423" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7460" PostTypeId="1" CreationDate="2018-03-29T22:50:01.100" Score="3" ViewCount="396" Body="&lt;p&gt;I'm receiving a non-energy conserving output while trying to importance sample the GGX Distributionof the Microfacet model, which is generally 3-4 times bigger than the resulting PDF&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm following this blog post: &lt;a href=&quot;https://agraphicsguy.wordpress.com/2015/11/01/sampling-microfacet-brdf/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sampling microfacet BRDF | Cao Jiayin Blog&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I'm sampling the $\theta $ angle with the following formula / code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ \theta = acos(\sqrt{ \frac{1 - \epsilon}{\epsilon(\alpha^2 - 1) +1} }) $$&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sampleTheta(float roughness) {&#xA;    float random = rnd();&#xA;    return acos(&#xA;             sqrt(              (1.0f - random) /&#xA;                    ((roughness * roughness - 1.0f) * random + 1.0f)&#xA;                 )&#xA;           );&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The GGX Distribution function i'm using is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$  \frac{ \alpha^2 }{\pi((\alpha^2 - 1) cos^2\theta + 1)^2}  $$&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float MicroFacetMaterial::Distribution(vec3 normal, vec3 halfvector, float alpha) {&#xA;    float NoH = dot(normal, halfvector);&#xA;    float NoH2 = NoH * NoH;&#xA;    float alpha2 = alpha * alpha;&#xA;&#xA;    float a1 = (NoH2 * (alpha2 - 1.0f) + 1.0f);&#xA;&#xA;    return alpha2 / (M_PI * a1 * a1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And finally, the blog post derived this PDF to use along with the BRDF:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$ p_{h}(\theta) = \frac{2\alpha^2 \ cos\theta \ sin\theta}{((\alpha^2 - 1)cos^2\theta + 1 )^2 } \\ \ \\ \ \\ p(\theta) = \frac{p_{h}(\theta)}{ 4 (\omega o \cdot \omega h)} $$&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float get_pdf(vec3 wo, vec3 normal, vec3 halfvector, float roughness) {&#xA;    float NoH = dot(normal, halfvector);&#xA;    float NoH2 = NoH * NoH;&#xA;    float sin = sqrt(1.0f - NoH2);&#xA;    float alpha2 = roughness * roughness;&#xA;&#xA;    float a1 = (NoH2 * (alpha2 - 1.0f) + 1.0f);&#xA;&#xA;    float pdf_h = (2.0f * alpha2 * NoH * sin) / (a1 * a1);&#xA;&#xA;    return pdf_h / (4.0f * dot(wo, halfvector));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And as a final step I'm calculating incident radiance as follow for an RGB non-recursive path tracer &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  float cosT = clampDot(newdirection, normal);&#xA;  vec3 halfVector = HalfwayVector(-ray.direction, newdirection);&#xA;&#xA;  float pdf = get_pdf(-ray.direction, normal, halfVector, _roughness);&#xA;&#xA;  float distribution = Distribution(normal, halfVector, _roughness);&#xA;  vec3 fresnel = FresnelColor(newdirection, halfVector, clampDot(halfVector, -ray.direction));&#xA;  float geometry = Geometry(-ray.direction, newdirection, normal, halfVector);&#xA;&#xA;  float denominator = 4.0f * clampDot(normal, -ray.direction) * clampDot(normal, newdirection);&#xA;&#xA;  vec3 brdf = (distribution * fresnel * geometry) / (denominator);&#xA;&#xA;  mask = (albedo * brdf * cosT) / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The output I'm getting is a model that behaves almost like a lightsource - while debugging, I saw the Distribution term normally is up to 4 times bigger than the respective PDF, I've also decided not to post the Geometry and Fresnel term since at least from the debugging I've done those are not contributing as much as the Distribution term (as expected)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anyone can confirm the above looks alright, I'll try to look for the error elsewhere&lt;/p&gt;&#xA;" OwnerUserId="7871" LastEditorDisplayName="user7220" LastEditDate="2018-04-08T20:37:19.843" LastActivityDate="2018-04-08T20:37:19.843" Title="Wrong output while implementing GGX importance sampling" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;importance-sampling&gt;&lt;microfacet&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7461" PostTypeId="1" AcceptedAnswerId="7564" CreationDate="2018-03-30T19:03:41.637" Score="1" ViewCount="497" Body="&lt;p&gt;I'm trying to implement radiosity normal maps from the old Valve paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.valvesoftware.com/publications/2004/GDC2004_Half-Life2_Shading.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Half-Life® 2 /&#xA;Valve Source™ Shading.pdf | valvesoftware.com&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried generating the light maps using Vray and 3dStudio max, by overriding the normals to point in these three directions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CnS5u.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CnS5u.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It works to an extent, applying normal maps over walls and such makes them appear like they are light mapped and bumpy. It's when I set the normal map to (128,128,255) that i can't get the same result as if it were a regular light map and i see artifacts. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if understand at all how the basis is used to capture light, so i omitted the GI part and tried to bake just a directional light. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If i set a directional light at &lt;code&gt;(-1,0,0)&lt;/code&gt; in the basis from the picture above, the first dot product (red arrow) will be less than 0, however both the green and the blue will get some value from that light. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Same way if i set it at &lt;code&gt;(1,0,0)&lt;/code&gt; there will be some value greater than 0, and two less than.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This doesn't make sense, the directional light at this angle shouldn't contribute any light to this surface?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/bw1Iv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bw1Iv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The white arrow represents the light dir to be baked. The red one is pretty affected by it, but then scaling it by 1/3 doesn't really help much. &#xA;It feels like it's missing some negative light (?). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LrMt0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LrMt0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here it is with (1,1,1) normalized ^&lt;/p&gt;&#xA;" OwnerUserId="5005" LastEditorDisplayName="user7220" LastEditDate="2018-04-08T22:47:54.983" LastActivityDate="2018-04-29T19:33:40.217" Title="Radiosity normal map light baking" Tags="&lt;lighting&gt;&lt;real-time&gt;&lt;global-illumination&gt;&lt;radiosity&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7462" PostTypeId="1" AcceptedAnswerId="7463" CreationDate="2018-04-01T07:08:29.850" Score="2" ViewCount="686" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ldc8H.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ldc8H.png&quot; alt=&quot;Task&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I calculate angle &lt;code&gt;C&lt;/code&gt;?&#xA;I can only know what angle between vector and x positive vector {1, 0}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Angle between green and red is 60 degrees.&#xA;Angle between blue and red is -170 degrees.&#xA;Shortest angle between green and blue is 130 degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What formula should I use to calculate it?&lt;br&gt;&#xA;It must be positive value.&lt;/p&gt;&#xA;" OwnerUserId="8487" LastEditorUserId="67" LastEditDate="2018-04-01T11:56:57.393" LastActivityDate="2018-04-01T14:55:12.950" Title="Delta angle of two vectors about positive x axis" Tags="&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7463" PostTypeId="2" ParentId="7462" CreationDate="2018-04-01T14:55:12.950" Score="3" Body="&lt;p&gt;Generally when wanting the smallest angle between two vectors, the dot product is used.&#xA;$$&#xA;\vec A \cdot{} \vec B = \cos{\angle \alpha}&#xA;$$&#xA;Where $\vec A$ and $\vec B$ are vectors with the length of $1.0$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, you do not have access to the actual vectors themselves, if I understand your question correctly. You just have access to the angles between the vectors and a common direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a different way you could calculate that angle. You take the absolute value of the difference between the two angles, given that both angles are from a common direction and either both clock-wise or both counter clock-wise.&#xA;$$&#xA;\angle \phi = |\angle \alpha - \angle \beta|&#xA;$$&#xA;Where&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$\angle \phi$ is the smallest positive angle between the two vectors.&lt;/li&gt;&#xA;&lt;li&gt;$\angle \alpha$ and $\angle \beta$ are angles in the range from $[0, 360)$, between a common direction and the vector, and either both clock-wise or both counter clock-wise.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What do I mean with how I defined those angles?&lt;br&gt;&#xA;First off all, that both angles are between a common direction and the vector. In this case it means that the angles should be between the vector and the red vector where the red vector is the common direction. Which is the case for the angles you provided. It is difficult for me to properly explain why they need to share a common direction, but it should be self explanatory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do I mean with that they should be either both clock-wise or both counter clock-wise? When having an angle between two directions, it can either be clock-wise or counter clock-wise. The angle between red and green is 60° and if you start at the red vector (which will be the common direction) you go counter clock-wise with an angle of 60°. The other angle should then also be counter clock-wise. This is the case between red and blue with an angle of -170°. If you look at the red vector, then you go clock-wise. However, the angle is negative, so you go backwards. This means that you actually go counter clock-wise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And lastly, the angles should be in the range from $[0, 360)$. This makes the formula work a bit better. It is not needed, but then you would have to do some stuff with $\angle \phi$ instead. Basically, if the angle is larger than 360° you just keep subtracting 360° until it is within the range. If the angle is smaller than 0° you keep adding 360° until it is within the range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us try this method with your example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have three vectors. $\vec Red$, $\vec Blue$ and $\vec Green$. We now the angles between $\vec Red$ and $\vec Blue$ and between $\vec Red$ and $\vec Green$. &#xA;$$\angle RB = -170$$&#xA;$$\angle RG = 60$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\angle RG$ is within our range, but $\angle RB$ is not. So we add 360° to $\angle RB$ and we get.&#xA;$$\angle RB = 190$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They also both have a common direction, $\vec Red$ and are both counter clock-wise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When adding them into the formula, we get;&#xA;$$\angle \phi = |190-60| = 130$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And there we have it. The answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I do not know if this is a formula with a name or something like that. This method is something I just came up with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Good luck!&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-04-01T14:55:12.950" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7464" PostTypeId="1" AcceptedAnswerId="7477" CreationDate="2018-04-01T15:48:58.753" Score="1" ViewCount="69" Body="&lt;p&gt;I have implemented a couple of classes which are drawn using shaders where the vertex position is always calculated the same way:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;gl_Position = u_worldViewProjection * a_position;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;u_worldViewProjection&lt;/code&gt;-uniform is calculated using a &lt;code&gt;viewProjectionMatrix&lt;/code&gt; which comes from a camera class. This is how I calculate the &lt;code&gt;viewProjectionMatrix&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const projectionMatrix = mat4.create();&#xA;mat4.perspective(projectionMatrix, this._fieldOfViewRadians, this._aspect, this._zNear, this._zFar);&#xA;mat4.rotateY(projectionMatrix, projectionMatrix, MathHelper.degToRad(this._cameraAngleDeg));&#xA;&#xA;// Setup camera&#xA;const cameraMatrix = mat4.create();&#xA;const up = vec3.fromValues(0, 1, 0);&#xA;mat4.lookAt(cameraMatrix, this._cameraPosition, this._viewDirection, up);&#xA;&#xA;const viewProjectionMatrix = mat4.create();&#xA;mat4.multiply(viewProjectionMatrix, projectionMatrix, cameraMatrix);&#xA;&#xA;return viewProjectionMatrix;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After that I would draw some component where I would set the &lt;code&gt;u_worldViewProjection&lt;/code&gt;-uniform something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;protected _calculateMatrixData(viewProjectionMatrix: mat4): void {&#xA;// Set the world-matrix aka model matrix, position rotation and scaling&#xA;const worldMatrix = mat4.create();&#xA;mat4.translate(worldMatrix, worldMatrix, this.translation);&#xA;mat4.scale(worldMatrix, worldMatrix, vec3.fromValues(this._scale[0], this._scale[1], this._scale[2]));&#xA;mat4.rotateX(worldMatrix, worldMatrix, MathHelper.degToRad(this._rotationAngleDegree[0]));&#xA;mat4.rotateY(worldMatrix, worldMatrix, MathHelper.degToRad(this._rotationAngleDegree[1]));&#xA;mat4.rotateZ(worldMatrix, worldMatrix, MathHelper.degToRad(this._rotationAngleDegree[2]));&#xA;&#xA;this._worldMatrixData.value = worldMatrix;&#xA;&#xA;// Create worldViewProjection matrix&#xA;const worldViewProjectionMatrix = mat4.create();&#xA;mat4.multiply(worldViewProjectionMatrix, viewProjectionMatrix, worldMatrix);&#xA;// ...&#xA;// set the uniforms some time later&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Until now this worked for every object. Now I introduced a new shader-pair:&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;vertex shader:&lt;/h3&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;&#xA;in vec4 a_position;&#xA;uniform mat4 u_worldViewProjection;&#xA;&#xA;void main() {&#xA;&#xA;  gl_PointSize = 10.5;&#xA;  gl_Position = u_worldViewProjection * a_position;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h3&gt;fragment shader:&lt;/h3&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;&#xA;// Set fragment shader's precision to &quot;medium precision&quot;&#xA;precision mediump float;&#xA;&#xA;out vec4 outColor;&#xA;&#xA;void main() {&#xA;  outColor = vec4(1, 0, 0.1, 0.5);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Seems simple. The problem is those do not render the component. I did realize that the component is being drawn if I omit the &lt;code&gt;u_worldViewProjection&lt;/code&gt; in the &lt;code&gt;gl_Position&lt;/code&gt; calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;gl_Position = a_position;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above snippet will draw the component, but of course this will not take any changes in account that were made to the camera. Thus I guess that my &lt;code&gt;u_worldViewProjection&lt;/code&gt; is the source of the false behaviour.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how I calculate the &lt;code&gt;worldViewProjectionMatrix&lt;/code&gt; for the above shaders:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const worldMatrix = mat4.create();&#xA;mat4.scale(worldMatrix, worldMatrix, vec3.fromValues(1.0, 1.0, 1.0));&#xA;&#xA;// Create worldViewProjection matrix&#xA;const worldViewProjectionMatrix = mat4.create();&#xA;mat4.multiply(worldViewProjectionMatrix, viewProjectionMatrix, worldMatrix);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The resulting matrix is &lt;strong&gt;not&lt;/strong&gt; null or undefined.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know it is kind of impossible to point out the origin of the problem but maybe there some approach to find the source or maybe I am doing something completely wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help would be appreciated. If there is some other information I should provide please let me know.&lt;/p&gt;&#xA;" OwnerUserId="2485" LastEditorUserId="7457" LastEditDate="2018-04-03T10:19:46.147" LastActivityDate="2018-04-11T17:15:00.037" Title="`worldViewProjection` doesn't work for a single component" Tags="&lt;webgl&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7465" PostTypeId="1" CreationDate="2018-04-02T20:41:03.447" Score="3" ViewCount="320" Body="&lt;p&gt;Im trying to complain the algorithm to calculate the HSL value form a RGB color. I understand the algorithm for the Hue, but im lost with the Lightness and saturation. Someone can explain why?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;There is the algorithm:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$R'=R/255$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$G'=G/255$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$B'=B/255$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$C_{max}=\max\left(R',G',B'\right)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$C_{min}=\min\left(R',G',B'\right)$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\Delta=C_{max}-C_{min}$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Hue Calculation:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$H = \begin{cases}&#xA;0^\circ &amp;amp; ,\Delta=0\\&#xA;60^\circ \times \left(\frac{G'-B'}{\Delta}\mod 6\right) &amp;amp; ,C_{max}=R'\\&#xA;60^\circ \times \left(\frac{B'-R'}{\Delta}+2\right) &amp;amp; ,C_{max}=G'\\&#xA;60^\circ \times \left(\frac{R'-G'}{\Delta}+4\right) &amp;amp; ,C_{max}=B'&#xA;\end{cases}$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Lightness calculation:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L=\frac{C_{max} + C_{min}}{2}$$&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Saturation calculation:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$S=\begin{cases}&#xA;0 &amp;amp; ,\Delta=0\\&#xA;\frac{\Delta}{1-|2L-1|} &amp;amp; ,\Delta &amp;lt;&amp;gt; 0&#xA;\end{cases}$$&lt;/p&gt;&#xA;" OwnerUserId="8494" LastEditorUserId="7431" LastEditDate="2018-07-31T05:15:14.167" LastActivityDate="2018-07-31T16:01:54.800" Title="Can someone explain this formula for parse RGB to HSL?" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;color&gt;&lt;color-science&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7467" PostTypeId="1" CreationDate="2018-04-03T19:02:51.347" Score="4" ViewCount="455" Body="&lt;p&gt;What actually happens inside computer when the text, pdf, jpeg, ms-word or any other document(file) is scrolled? Does it generate a new bitmap image sufficient for the screen to display even for tiny scroll or are does it show part of bit map image for each scroll? Please describe what is the basic idea behind the working of scroll in laymen terms? &lt;/p&gt;&#xA;" OwnerUserId="8153" LastEditorUserId="8153" LastEditDate="2018-04-04T07:38:36.080" LastActivityDate="2018-04-04T10:08:37.103" Title="What actually happens in frame buffer when an image or document is scrolled?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;webgl&gt;&lt;gui&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7468" PostTypeId="2" ParentId="7467" CreationDate="2018-04-04T10:08:37.103" Score="6" Body="&lt;p&gt;In the olden days of text-mode terminals, the &quot;frame buffer&quot; was a buffer of text, not an image. Scrolling worked in the way you described. The buffer was larger than would fit on the screen, and to &quot;scroll&quot; it would change an offset in the display controller, so it would display different lines. This only makes sense when the whole framebuffer is scrolled at once, which never happens in a windowing system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nowadays, it depends on the application. A word processor will rasterise the text separately each frame: there's no off-screen buffer at all. It wouldn't make sense to store an image of the whole document, because the memory use would be huge, and the whole thing would have to be recreated every time the text changed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, an image editor will probably store the whole image, possibly as a texture in GPU memory. A program on the GPU copies the visible section of the image to the application's frame buffer, each frame. This can be done by simply having the view parameters (offset and zoom level) as uniforms and updating them as the view is changed. This is actually very fast even though it's essentially a copy, because GPUs are good at drawing textures efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A web browser might use either technique, or something more sophisticated. There was a trend in mobile browsers a couple of years ago to render in tiles. The structure of the page would be rasterised to a set of off-screen tiles: enough to more than cover the screen. A program on the GPU draws all the visible tiles into the correct place in the application's framebuffer, clipping the edges. That way, small scrolls or zooms can be performed by changing the offsets of the tiles, without having to rasterise the page again. When you scroll too close to the edge of the tiles, a new row of tiles can be rasterised in a separate thread.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This tile approach is fast to display, uses a fixed number of fixed-size textures, and allows a trade-off between responsiveness and scroll speed. It also allows lower-resolution tiles to be used if the page is too slow to rasterise during a fast scroll. It does require a lot more sophistication in the way you rasterise the page to the tiles, to know which parts of the page can affect which tiles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whichever technique the application uses for managing off-screen content, it's responsible itself for producing a new frame each time. The windowing system or compositor doesn't give it a way to specify a window of a larger texture to use without copying.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-04-04T10:08:37.103" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7469" PostTypeId="1" CreationDate="2018-04-04T16:47:35.537" Score="3" ViewCount="80" Body="&lt;p&gt;There are three principal ways to obtain a BRDF. We can&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Derive an analytic formula using physical principles&lt;/li&gt;&#xA;&lt;li&gt;Use simulation given an assumed or measured model of the surface&#xA;microgeometry&lt;/li&gt;&#xA;&lt;li&gt;Measure the BRDF based on empirical observation&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;A number of analytic formulae have been proposed for BRDFs. Many Formulae have been derived from physical principles. A number of models such as the Torrance-Sparrow model have been derived from the distribution of microfacet orientations. One may postulate a certain microgeometry for the surface, and simulate the resulting BRDF by using a software raytracer.&lt;/p&gt;&#xA;&lt;p&gt;Once the scattering of light on a surface is understood how is a reflectance function derived? Can anyone recommend any resources on this topic?&lt;/p&gt;&#xA;" OwnerUserId="5256" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-04-05T07:21:11.677" Title="Predicting reflectance functions from complex surfaces" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;pbr&gt;&lt;scattering&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7470" PostTypeId="1" AcceptedAnswerId="7471" CreationDate="2018-04-04T19:30:45.687" Score="0" ViewCount="110" Body="&lt;p&gt;So I have a small (8x8 pixel) image in 24-bit color. I want to be able to (quickly) generate a color-quantized version of the image that only has two colors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One naive approach is to cluster a luma histogram of the image (1-dimensional clustering is &lt;a href=&quot;https://stackoverflow.com/a/11516590/498680&quot;&gt;easier&lt;/a&gt; than the 2D or 3D case). The chroma can be generated by averaging the pixels in each cluster. Unfortunately, this technique doesn't really work well if the the image has uniform luma.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="6380" LastEditorUserId="6380" LastEditDate="2018-04-04T19:40:19.573" LastActivityDate="2018-04-06T08:35:13.163" Title="Quick 2-color quantization for small images" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;color&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7471" PostTypeId="2" ParentId="7470" CreationDate="2018-04-05T08:36:43.173" Score="1" Body="&lt;p&gt;The approach I would use, and indeed have used, would be to&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;run principal component analysis on your image data to generate &quot;the&quot; main axis&lt;/li&gt;&#xA;&lt;li&gt;Project your pixels onto that axis (i.e. compute the dot product of each colour value against the axis)&lt;/li&gt;&#xA;&lt;li&gt;Using the dot prods, sort the the colour values from smallest to largest and&lt;/li&gt;&#xA;&lt;li&gt;Find the &quot;partitioning&quot; point, i.e. that splits smaller values in one set, larger in the other, that minimises, say, the mean squared error. i.e. each partition is represented by the average of its members and you compute the total error.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This last step, i.e. finding the best partition, can be done in linear time by starting with the &quot;least&quot; item in partition &quot;A&quot;, all the rest in partition &quot;B&quot;, and progressively shifting the next smaller over from &quot;B&quot; to &quot;A, one at a time. You just need to keep separate sums of the values and sums of squares of the values for each partition and then you can compute the total MSE relatively cheaply. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the function should follow a quadratic curve so it (should) begin decreasing until it reaches the minimum. Once it starts increasing again you can stop the search.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A cheap way to find the principal axis is to first generate the 3x3 covariance matrix and then use the &quot;repeated matrix vector multiplication&quot; trick to find the principal eigenvector (i.e. the principal axis)&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-04-06T08:35:13.163" LastActivityDate="2018-04-06T08:35:13.163" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7472" PostTypeId="1" AcceptedAnswerId="7478" CreationDate="2018-04-05T10:33:21.667" Score="3" ViewCount="179" Body="&lt;p&gt;I'm looking into a problem that first occured very trivial to me, but i got stuck and it's becoming a major issue right now. I'd like to subdivide a triangle by its given UVs, e.g. if the UVs are going from -n...+m or if they are greater than 1. So for example if i have a U coordinate from -1.5 ... 4 i'd like to subdivide at -1.0, 0.0, 1.0, 2.0, 3.0. Here's a visualization of the polygons that can be generated. Triangulation is trivial of course. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/afHHS.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/afHHS.jpg&quot; alt=&quot;This is how it renders with a UV texture&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My idea was to subdivide each edge separately for U and V and then find intersections and use these intersections to spawn triangles. However, i can't even find the rule how each line is constructed. Maybe someone can shed some light?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="8508" LastActivityDate="2018-04-07T08:04:28.363" Title="Subdivide a triangle along its UVs" Tags="&lt;geometry&gt;&lt;triangulation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7475" PostTypeId="1" AcceptedAnswerId="7476" CreationDate="2018-04-06T04:58:07.457" Score="-1" ViewCount="46" Body="&lt;p&gt;I don't know how to do this. I need help. My code looks like the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 120&#xA;&#xA;uniform sampler2D sampler;&#xA;varying vec2 tex_coords;&#xA;&#xA;void main() {   &#xA;     vec2 p = tex_coords;    &#xA;     vec4 red = vec4(1.0,0.0,0.0,1.0);&#xA;     vec4 green = vec4(0.0,1.0,0.0,1.0);     &#xA;     gl_FragColor = green + red; //I want to display green and red side by side      &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am trying to display red and green side by side using two &lt;code&gt;vec4&lt;/code&gt;s. &#xA;Any help?&lt;/p&gt;&#xA;" OwnerUserId="8517" LastEditorUserId="67" LastEditDate="2018-04-10T03:17:39.747" LastActivityDate="2018-04-10T03:17:39.747" Title="How to merge two vec4s and display side by side?" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7476" PostTypeId="2" ParentId="7475" CreationDate="2018-04-06T05:54:49.223" Score="1" Body="&lt;p&gt;This is not how Shaders work, if you add the colors, you add the final color for the fragment that is being worked on by the fragment shader - if you use this shader for a whole triangle, then all the fragments would end up with &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;gl\_FragColor = \left(\begin{array}{c}1.0\\1.0\\0.0\\1.0\end{array}\right)&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;i.e. the color vectors are just summed. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If you want to display two colors next to each other, you would typically add two objects to your scene next to each other, draw one of them with your shader that only displays red color and the other with your shader that only displays green color.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Another possibility is to calculate the position of your fragment in Model Space, World Space or another space of your choosing. Once you know that, you set a threshold up to which you color the object red and over which color the object green.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your fragment shader you would do something like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[...]&#xA;out vec3 vPos_ModelSpace;&#xA;&#xA;void main()&#xA;{&#xA;    //do all your vertex shader stuff here&#xA;&#xA;    //I assume your vertex position attribute is called aPosition&#xA;    vPos_ModelSpace = aPosition.xyz;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then in your fragment shader you can go about it like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;in vec3 vPos_ModelSpace;&#xA;void main()&#xA;{&#xA;    if(vPos_ModelSpace.x &amp;lt; 0)&#xA;    {&#xA;        gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);&#xA;    }&#xA;    else&#xA;    {&#xA;        gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This assumes of course, that your model has vertices on either side of 0 on the x-axis. You shouldn't generally use &lt;code&gt;if&lt;/code&gt; statements in shaders, since they are bad for perfomance, but this shader is so simple that it doesn't matter. Also, if you go about it this way, then simply outputting the x coordinate from your model space position suffices, no need really to use the whole &lt;code&gt;vec3&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2018-04-06T07:26:47.867" LastActivityDate="2018-04-06T07:26:47.867" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7477" PostTypeId="2" ParentId="7464" CreationDate="2018-04-06T16:38:49.477" Score="-1" Body="&lt;p&gt;This was entirely my fault. I simply forgot to set the uniform locations before rendering!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I implemented a function &lt;code&gt;setUniformLocations()&lt;/code&gt; which sets the uniform locations passed to it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static setUniformLocations(&#xA;    gl: WebGL2RenderingContext, &#xA;    uniforms: IUniform[], &#xA;    program: WebGLProgram): IUniform[] {&#xA;&#xA;    const vao = gl.createVertexArray();&#xA;    gl.bindVertexArray(vao);&#xA;&#xA;    for (const uniform of uniforms) {&#xA;        uniforms.find((u) =&amp;gt; u.name === uniform.name).location = gl.getUniformLocation(program, uniform.name);&#xA;    }&#xA;&#xA;    return uniforms;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I normally call this function in the constructor of the according class.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;this._uniforms = GLHelper.setUniformLocations(this.gl, this._uniforms, this._program);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This time I forgot.&lt;/p&gt;&#xA;" OwnerUserId="2485" LastEditorUserId="2485" LastEditDate="2018-04-11T17:15:00.037" LastActivityDate="2018-04-11T17:15:00.037" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7478" PostTypeId="2" ParentId="7472" CreationDate="2018-04-07T08:04:28.363" Score="1" Body="&lt;p&gt;You can use barycentric coordinates to calculate points inside the triangle with a determinate value for uv.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The process is easy =&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say that the UV coordinates of each vertex of the triangle are:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex 0 =&gt; u0,v0&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex 1 =&gt; u1,v1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex 2 =&gt; u2,v2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A point inside the triangle has UV coordinates value expressed in function of its barycentric coordinates:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;u coord = p0 * u0 + p1 * u1 + p2 * u2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;v coord = p0 * v0 + p1 * v1 + p2 * v2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where p0,p1,p2 are the barycentric coordinates of this point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As barycentric coordinates has the property:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;p0 + p1 + p2 = 1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;you can calculate the barycentric coordinates of a point with a specific value for UV just by solving these equations. I mean, for example, you want to know which point inside the triangle has&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UV = (1,2)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To calculate such a point just do:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1 = p0 * u0 + p1 * u1 + p2 * u2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2 = p0 * v0 + p1 * v1 + p2 * v2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;p0 + p1 + p2 = 1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as you know the values for (u0,v0), (u1,v1) and (u2,v2),  you can easily calculate the barycentric coordinates of this point, (p0, p1, p2).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have the barycentric coordinates, you can calculate the coordinates (px,py,pz) of the point:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(px,py,pz) = p0 * vertex0 coordinates + p1 * vertex 1 coordinates + p2 * vertex 2 coordinates  &lt;/p&gt;&#xA;" OwnerUserId="7696" LastActivityDate="2018-04-07T08:04:28.363" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7480" PostTypeId="1" AcceptedAnswerId="7481" CreationDate="2018-04-07T17:32:56.340" Score="-1" ViewCount="50" Body="&lt;p&gt;I have ever browsed a website focusing on cloud (cloud in the sky, not cloud computing) simulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's a company devoted to developing cloud simulation software and offer cloud simultation solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone knows this website or the company?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2018-04-07T18:54:09.423" Title="Cloud simulation software" Tags="&lt;simulation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ClosedDate="2018-04-10T21:13:36.840" ContentLicense="CC BY-SA 3.0" />
  <row Id="7481" PostTypeId="2" ParentId="7480" CreationDate="2018-04-07T18:54:09.423" Score="1" Body="&lt;p&gt;There are a couple of companies doing middleware cloud simulation and rendering. It might have been &lt;a href=&quot;http://sundog-soft.com/features/real-time-3d-clouds/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SilverLining&lt;/a&gt; by Sundog, or &lt;a href=&quot;https://simul.co/truesky/&quot; rel=&quot;nofollow noreferrer&quot;&gt;trueSKY&lt;/a&gt; by Simul.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-04-07T18:54:09.423" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7482" PostTypeId="1" AcceptedAnswerId="7547" CreationDate="2018-04-09T05:11:32.783" Score="0" ViewCount="462" Body="&lt;p&gt;I'm having some issues with my multi-threaded ray tracing implementation. It seems to only render about half of the image. Here is the picture:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kbYe6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kbYe6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int max = (nx * ny); //width * height&#xA;volatile std::atomic&amp;lt;int&amp;gt; count(0);&#xA;&#xA;int cores = std::thread::hardware_concurrency();&#xA;cores -= 1;&#xA;vector&amp;lt;future&amp;lt;vector&amp;lt;rgbpacket&amp;gt;&amp;gt;&amp;gt; future_vector;&#xA;cout &amp;lt;&amp;lt; &quot;Threads supported: &quot; &amp;lt;&amp;lt; cores &amp;lt;&amp;lt; &quot;\n&quot;;&#xA;while (cores--) {&#xA;    future_vector.emplace_back(&#xA;        std::async([=, &amp;amp;world, &amp;amp;cam, &amp;amp;dim, &amp;amp;orth, &amp;amp;count] {&#xA;            vector&amp;lt;rgbpacket&amp;gt; stack;&#xA;            while (true) {&#xA;&#xA;                int index = count++;&#xA;&#xA;                if (index &amp;gt;= max) {&#xA;&#xA;                    return stack;&#xA;                } else {&#xA;                    int k = (index % nx); //mod width to get column&#xA;                    int j = (index / nx); //divide width to get row&#xA;&#xA;                    rgbpacket curpx = render(j, k, dim, world, cam, orth);&#xA;                    curpx.k = (unsigned int)k;&#xA;                    curpx.j = (unsigned int)j;&#xA;                    stack.push_back(curpx);&#xA;&#xA;                }&#xA;            }&#xA;        })&#xA;    );&#xA;}&#xA;&#xA;//parse the image buffer&#xA;for (unsigned int i = 0; i &amp;lt; future_vector.size(); i++) {&#xA;    vector&amp;lt;rgbpacket&amp;gt; stack = future_vector[i].get();&#xA;    for (unsigned int k = 0; k &amp;lt; stack.size(); k++) {&#xA;        rgbpacket rgb_comp = stack.back();&#xA;&#xA;        //Using the new compressed packet&#xA;        rgbaColor conv;&#xA;        conv.r = rgb_comp.r;&#xA;        conv.g = rgb_comp.g;&#xA;        conv.b = rgb_comp.b;&#xA;&#xA;        hslaColor pix = rgb2hsl(conv);&#xA;        HSLAPixel newpixel(pix.h, pix.s, pix.l);&#xA;&#xA;        HSLAPixel &amp;amp;imgpx = img.getPixel(rgb_comp.k, rgb_comp.j);&#xA;        imgpx = newpixel;&#xA;&#xA;        stack.pop_back();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For some preface, I am calculating the pixel with respect to the position with the &lt;strong&gt;index&lt;/strong&gt; variable. Once I calculate it, I store it (along with the position) in the vector. After I calculate all of the pixel values, I parse them into an image buffer and later print that image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've narrowed the issue (I think) to where I am calculating the rendered pixel and storing it in the vector. For some reason, it does not store all of the pixels in the vector and I am not sure why? Any help is appreciated. Thanks!&lt;/p&gt;&#xA;" OwnerUserId="8532" LastActivityDate="2018-04-24T06:37:36.247" Title="Issues with Multi-threaded Raytracing" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 3.0" />
  <row Id="7483" PostTypeId="1" AcceptedAnswerId="7502" CreationDate="2018-04-09T19:19:33.450" Score="3" ViewCount="894" Body="&lt;p&gt;I'm reading &lt;a href=&quot;https://blogs.msdn.microsoft.com/directx/2018/04/09/dxgi-flip-model/&quot; rel=&quot;nofollow noreferrer&quot;&gt;DXGI flip model&lt;/a&gt; article and some parts are not clear:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;blockquote&gt;&#xA;  &lt;p&gt;DirectFlip with panel fitters: Your window client region covers the screen, and your swapchain buffers are within some hardware-dependent scaling factor (e.g. 0.25x to 4x) of the screen. The GPU scanout hardware is used to scale your buffer while sending it to the display.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What is this hardware-dependent scaling factor? What it does? Why?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;blockquote&gt;&#xA;  &lt;p&gt;The traditional pattern for apps in the past has been to provide the user with a list of resolutions to choose from when the user selects exclusive fullscreen mode. With the ability of modern displays to seamlessly begin scaling content, consider providing users with the ability to choose a rendering resolution for performance scaling, independent from an output resolution, and even in windowed mode.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I understand what they mean by the &lt;em&gt;traditional pattern&lt;/em&gt;, it's pretty common - I'm selecting a resolution in the options screen and enjoying fullHD 800*600 picture. But I have no clue what are they describing next - &lt;em&gt;displays seamlessly scaling content&lt;/em&gt;, &lt;em&gt;resolution for performance scaling&lt;/em&gt;, &lt;em&gt;output resolution&lt;/em&gt;. Could someone explain the same with simple words and examples (I bet there are already games out there that uses the technology)?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="386" LastEditorUserId="5778" LastEditDate="2018-12-05T09:02:20.457" LastActivityDate="2018-12-05T09:02:20.457" Title="What is a scaling factor of the screen?" Tags="&lt;pixels&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7484" PostTypeId="2" ParentId="7437" CreationDate="2018-04-10T04:10:41.130" Score="1" Body="&lt;p&gt;Unfortunately, &lt;code&gt;gl_FragDepth&lt;/code&gt; won't enable you to write outside of the rasterized triangle's screen-space bounds. All it enables is to modify the values written to the depth buffer within the triangle, replacing the triangle's true depth with a shader-calculated value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you're seeing in the screenshot in the Unity forum thread you linked to is two intersecting parallax-mapped surfaces, where the depth output enables occlusion between the two surfaces to be correctly resolved in the screen-space region they both cover. But if you look at the right side of the screenshot, you can see the straight-line edge of the bottom brick polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However! You might still be able to accomplish the goal of getting correct silhouette edges by using &lt;code&gt;discard&lt;/code&gt; in the fragment shader when the parallax ray gets outside the bounds of the original polygon. This would involve modifying the ray-march code to check if the march has crossed a triangle edge, and exit with &lt;code&gt;discard&lt;/code&gt; if so, rather than continuing to march.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'd have to find a way to get the information about triangle edges into the fragment shader, though, as this isn't provided by OpenGL. Maybe make your vertex/index buffers available via SSBOs; then you can use &lt;code&gt;gl_PrimitiveID&lt;/code&gt; in the fragment shader to index into them and lookup the vertex data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately I don't know offhand of any implementation of something like this, although I'm sure someone out there must have tried it before.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-04-10T04:10:41.130" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="7485" PostTypeId="1" AcceptedAnswerId="7488" CreationDate="2018-04-10T07:25:29.727" Score="4" ViewCount="885" Body="&lt;p&gt;I'm trying to understand all primitives In &lt;a href=&quot;http://iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt;.After hard work I just learn Sphere and Cube , I wrote description &lt;a href=&quot;https://stackoverflow.com/questions/35326366/glsl-cube-signed-distance-field-implementation-explanation/49726668#49726668&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could draw 2D shapes but I have trouble understanding 3D below codes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YjRDv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YjRDv.png&quot; alt=&quot;Tours 2D&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Torus - signed - exact&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/o8H2x.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o8H2x.png&quot; alt=&quot;Tour 3D&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sdTorus( vec3 p, vec2 t )&#xA;{&#xA;  vec2 q = vec2(length(p.xz)-t.x,p.y);&#xA;  return length(q)-t.y;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7ehcE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7ehcE.png&quot; alt=&quot;Length&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't imagine how this shape drew and I don't know why two length used here.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JDBUy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JDBUy.png&quot; alt=&quot;Cone 2D&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cone - signed - exact&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZiPLs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZiPLs.png&quot; alt=&quot;Cone 3D&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sdCone( vec3 p, vec2 c )&#xA;{&#xA;    // c must be normalized&#xA;    float q = length(p.xy);&#xA;    return dot(c,vec2(q,p.z));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't know why dot product used here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm confused please help me to understand this shapes.I hope someone explain each shape.&lt;/p&gt;&#xA;" OwnerUserId="6541" LastEditorUserId="6541" LastEditDate="2018-04-11T13:00:36.237" LastActivityDate="2018-04-11T13:00:36.237" Title="GLSL shapes signed distance field implementation explanation?" Tags="&lt;glsl&gt;&lt;mathematics&gt;&lt;signed-distance-field&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7486" PostTypeId="1" AcceptedAnswerId="7492" CreationDate="2018-04-10T09:40:08.730" Score="1" ViewCount="1378" Body="&lt;p&gt;I'm rendering a full screen quad using &lt;code&gt;gl_VertexID&lt;/code&gt; as &lt;code&gt;GL_TRIANGLE_STRIP&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const vec2 kVertices[4] = vec2[]&#xA;(&#xA; vec2(-1.0,  1.0),&#xA; vec2(-1.0, -1.0),&#xA; vec2( 1.0,  1.0),&#xA; vec2( 1.0, -1.0)&#xA; );&#xA;&#xA;void main() {&#xA;    gl_Position = vec4(kVertices[gl_VertexID], 1.0, 1.0);&#xA;    vs_out.texCoords = gl_Position.xy / 2.0 + 0.5;&#xA;    vs_out.instanceID = gl_InstanceID;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Geometry shader just passes coordinates through into the output called &lt;code&gt;vTexCoords&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, in fragment shader, I output red and green into 2x2 texture using following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (vTexCoords.x &amp;gt;= 0.95) {&#xA;    oFragData0 = vec4(0.0, 1.0, 0.0, 1.0);&#xA;} else {&#xA;    oFragData0 = vec4(1.0, 0.0, 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I always assumed texture coordinates (0; 0), (0; 1), (1; 0), (1; 1) would map to the vertices, but the output is completely red, which means X value never reaches 1.0. &#xA;Then I'm trying to use 0.75 (&lt;code&gt;vTexCoords.x &amp;gt;= 0.75&lt;/code&gt;), which is a texel center, and half of the texture becomes green, as expected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I misunderstanding here?&lt;/p&gt;&#xA;" OwnerUserId="8541" LastActivityDate="2018-04-11T12:41:03.570" Title="Full screen quad texture coordinates mapping" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7487" PostTypeId="1" CreationDate="2018-04-10T15:53:10.130" Score="2" ViewCount="151" Body="&lt;p&gt;I have an .OBJ 3D model with many complex meshes shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The meshes are complex because each of them have multiple internal mesh located in it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Meshes with internal geometry is defined as a mesh, which consists of many nested geometry.&#xA;For example: a tank in .OBJ file is represented by 1 outer geometry with several nested small geometry in it. Total number of geometry to represent that tank would be 5-7.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to simplify the tank mesh object above to be represented by 1 geometry instead of multiple geometries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What tool and what programming language can I use to iterate all the meshes object, remove all internal geometry in .OBJ file?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please ask if you need clarification.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="8547" LastActivityDate="2018-05-14T11:11:25.787" Title="How to remove internal geometry programmatically in all meshes in .OBJ file?" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7488" PostTypeId="2" ParentId="7485" CreationDate="2018-04-10T16:46:34.303" Score="6" Body="&lt;h1&gt;Torus&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;A torus is defined by two parameters: the major radius, and the minor radius. The major radius (&lt;code&gt;t.x&lt;/code&gt;) is the radius of the big ring (in red in the diagram), and the minor radius (&lt;code&gt;t.y&lt;/code&gt;) is the radius of the circular cross-section. The &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; here are just indices into the vector: they're unrelated to the x and y axes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The left side of the diagram shows the xz plane, and the right side shows a cross-section with y going horizontally.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pvGwn.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pvGwn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;p.xz&lt;/code&gt; is the projection of the point onto the plane of the torus, so &lt;code&gt;length(p.xz)-t.x&lt;/code&gt; gives the distance from that projected point to the inside of the torus. (I've labelled it $r$ on the diagram.) &lt;code&gt;p.y&lt;/code&gt; is the distance from the point to the plane of the torus, so the length of the vector ($r$, &lt;code&gt;p.y&lt;/code&gt;) is the distance from the point to the inside of the torus. (Computing the length of a two-element vector is a handy way to use Pythagoras' theorem to find the hypotenuse of the triangle.)&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Cone&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Like the torus, the cone code uses the fact that the shape is symmetric about an axis: the z axis in this case. The cone is defined by a unit vector &lt;code&gt;c&lt;/code&gt; that's normal to the surface of the cone, and the apex of the cone is at the origin. Similar to the above, &lt;code&gt;length(p.xy)&lt;/code&gt; gets the distance from the point to the z axis, so that we can work in the plane where the cone is a triangle. &lt;code&gt;vec2(q,p.z)&lt;/code&gt; is the projection of &lt;code&gt;p&lt;/code&gt; into this plane. The dot product projects this vector onto the direction &lt;code&gt;c&lt;/code&gt;: how far the point is along this direction tells us how far it is from the surface of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eDKgu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eDKgu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-04-10T16:46:34.303" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7489" PostTypeId="1" CreationDate="2018-04-10T18:24:21.500" Score="4" ViewCount="236" Body="&lt;p&gt;I'm new to OpenGL, and I'm wondering what I need to pay attention to regarding versioning. The things I've been reading have been clear about there being version differences, and needing the appropriate OpenGL version for the functionality you're using. But they've mainly been talking about compiling and running programs on a single machine. For the most part they haven't explicitly dealt with complexities regarding compiling on one machine and running on another. (Specifically, what happens if the computer you're running on has an older version of OpenGL than the one you're compiling on.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, take &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawElementsInstanced.xhtml&quot; rel=&quot;noreferrer&quot;&gt;glDrawElementsInstanced&lt;/a&gt;. The Khronos page indicates this is available with OpenGL 3.1 and later. Obviously, if the headers for OpenGL on the machine I'm compiling for are version 3.0 or earlier, I'll get a compiler error. So on the machine I'm compiling on, I'll need to have OpenGL 3.1+ available.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I'm wondering what might happen if the machine I compile for has OpenGL 3.1+ available, but the machine I'm running on only has support for 3.0 or earlier? Will the program that uses glDrawElementsInstanced refuse to load? Will it run but crash once I call the glDrawElementsInstanced() function? Will it work fine because the actual implementation is compiled into my program, and it only uses common back-end functionality? Is the answer different for static versus dynamic linkage? -- And perhaps most importantly, if it wasn't glDrawElementsInstanced but some other function, is there a way I can determine this on my own?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm interested in distributing on Windows, Mac and Linux, so if there's any differences in behavior between the platforms in this regards, I'd be interested in knowing.&lt;/p&gt;&#xA;" OwnerUserId="8497" LastActivityDate="2020-04-16T03:18:29.073" Title="Dealing with OpenGL versions across multiple computers" Tags="&lt;opengl&gt;&lt;compatibility&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7492" PostTypeId="2" ParentId="7486" CreationDate="2018-04-11T02:30:11.227" Score="1" Body="&lt;p&gt;I may have misunderstood, but it sounds like the frame buffer you're rendering to is only 2×2 pixels? In that case, the fragment shader will be evaluated at each pixel center, which will be at 0.25 and 0.75 in UV space. So with a threshold of 0.95 you will indeed not get any pixels green.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you use a larger framebuffer, say 100×100, then the last 5 pixels of each row should come out green.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-04-11T02:30:11.227" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7493" PostTypeId="2" ParentId="1493" CreationDate="2018-04-11T08:59:48.827" Score="-1" Body="&lt;p&gt;There are no parabolas or hyperbolas formed when slicing a sphere once. There are no ellipses either except for the special case which is a circle.The result is always a circle. If you project the sphere onto a tilted plane you get an ellipse&lt;/p&gt;&#xA;" OwnerUserId="8551" LastEditorUserId="8551" LastEditDate="2018-04-11T09:18:58.903" LastActivityDate="2018-04-11T09:18:58.903" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7494" PostTypeId="1" CreationDate="2018-04-11T11:34:58.113" Score="1" ViewCount="212" Body="&lt;p&gt;I wonder if there exists any shader prototyping framework where I can debug (on cpu) my shaders, experiment with them and instantly see results and even write unit tests. The framework does not have to emulate rendering pipeline, compute only will do.&lt;/p&gt;&#xA;" OwnerUserId="8553" LastActivityDate="2018-06-13T17:50:38.483" Title="Shader Prototyping Frameworks" Tags="&lt;shader&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="7495" PostTypeId="2" ParentId="7486" CreationDate="2018-04-11T12:41:03.570" Score="1" Body="&lt;p&gt;An alternative solution would be to avoid the vertex/geometry shader completely and draw your fullscreen quad with &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glRecti(-1, -1, 1, 1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then just compile a fragment shader and generate your UVs with:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = gl_FragCoord.xy / framebufferSize.xy;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't know what you're doing but this could be potentially a fast forward solution for what you require. Maybe you're doing something else and you just broke down your problem to the bare minimum, i think in this case my answer should be still helpful for people seeking help in the problem as summarized in the headline.&lt;/p&gt;&#xA;" OwnerUserId="8508" LastActivityDate="2018-04-11T12:41:03.570" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7496" PostTypeId="1" CreationDate="2018-04-11T13:57:34.360" Score="6" ViewCount="272" Body="&lt;p&gt;I have a complex geometry mesh object, which is an irregular shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to redraw that complex geometry mesh object using multiple simple primitive shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I want to use cuboid, sphere and cylinder to represent a complex geometry mesh object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am given only the vertices points, triangular of that complex geometry mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I decompose the geometry shape into cuboid, sphere, cylinder.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please ask if you need details.&#xA;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="8547" LastActivityDate="2018-06-11T00:41:24.090" Title="How to decompose a complex mesh to simple geometry shape programmatically?" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7497" PostTypeId="1" CreationDate="2018-04-11T18:35:32.203" Score="1" ViewCount="236" Body="&lt;p&gt;I've been looking &lt;a href=&quot;http://advances.realtimerendering.com/s2015/The%20Real-time%20Volumetric%20Cloudscapes%20of%20Horizon%20-%20Zero%20Dawn%20-%20ARTR.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Real-time Volumetric Cloudscapes of Horizon-Zero Dawn&lt;/a&gt;, but I'm very confused by a few terms.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The presentation mentions &quot;The Henyey-Greenstein phase function&quot; on page 54, however does not mention how it is used nor what parameters are needed for it.  In fact they act like it is a constant, but it doesn't appear as if it is.  I've seen a &lt;a href=&quot;http://www.astro.umd.edu/~jph/HG_note.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;couple&lt;/a&gt; different &lt;a href=&quot;http://glossary.ametsoc.org/wiki/Henyey-greenstein_phase_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;formulations&lt;/a&gt; of the same equation, and I don't understand how to use it.  If &lt;code&gt;theta&lt;/code&gt; corresponds to the scattering angle, I'm not sure what actually constitutes the scattering angle in our rendering.  Is it the initial ray march angle, or light source marching angle? If theta corresponds to the light source march angle, that would be confusing since there isn't just one angle, there are 6 that they randomly select in a cone progressively further out according to page 83. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally the final equation used on page 77 is &lt;code&gt;e^(-d*r)*HG*P&lt;/code&gt;.  Where I assume &lt;code&gt;P&lt;/code&gt; is powder equation &lt;code&gt;(1.0 - e^(-d *2))&lt;/code&gt;, HG is Henyey-Greenstein, and where &lt;code&gt;d&lt;/code&gt; corresponds with &quot;depth&quot;, but normally combines both depth and density and where it looks like &lt;code&gt;r&lt;/code&gt; is &quot;absorption increasing for rain clouds&quot; otherwise it just came out of nowhere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm further confused by how they use the equations, they seem to sample &lt;em&gt;alpha&lt;/em&gt; with forward marching, then sample &lt;em&gt;energy&lt;/em&gt; with the light cone/ light direction marching.  The lack of a separate depth and density coefficient is what is concerning.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Going off of the presentation and other sources, my perception of the approach is as follows (ignoring the optimizations of the coarse steps, the fine grained steps, and the cone method for shadow marching): &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Forward march with a fixed size until you have a non zero density.  &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Then march in the direction of the light accumulating the density values at each step.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;plugin this summed density into the equation as &lt;code&gt;d&lt;/code&gt;,  &lt;code&gt;e^(-d*r)*HG*(1.0 - e^(-d *2))&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;multiply this product by our current forward marched density&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;multiply this value by some sort of transmittance value which is a function of how much &quot;stuff&quot; we've gone through in our cloud. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;return this value of transmittance, and the value of the light intensity as our final result, transmittance will represent our alpha in some form (either as the actual value, or 1.0 - transmittance) with range 0.0 to 1.0. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Are these steps correct and what does theta correspond to for this application in Henyey-Greenstein &lt;code&gt;HG&lt;/code&gt; and which form of the &lt;code&gt;HG&lt;/code&gt; equation do I need to use?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="6530" LastActivityDate="2018-04-11T18:35:32.203" Title="Not understanding the lighting equation for volumetric cloud rendering" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;lighting&gt;&lt;volumetric&gt;&lt;raymarching&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7498" PostTypeId="2" ParentId="7489" CreationDate="2018-04-11T23:24:45.870" Score="3" Body="&lt;p&gt;After running across &lt;a href=&quot;https://open.gl/context#Onemorething&quot; rel=&quot;nofollow noreferrer&quot;&gt;an aside in a tutorial&lt;/a&gt; and doing some further digging, I think I understand this now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/ABI/#4&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL ABI specification&lt;/a&gt;, only the functions defined in OpenGL 1.2 need to be present in the &lt;code&gt;GL/gl.h&lt;/code&gt; header file. (At least for Linux - other platforms may be different. &lt;a href=&quot;https://stackoverflow.com/a/17555881/3022952&quot;&gt;This answer&lt;/a&gt; indicates that Windows may expose only OpenGL 1.1 functions by default.) Functionality from more recent OpenGL versions (even commonly used functions) may not even be defined in the header files. -- This seems to be the case for glDrawElementsInstanced. In the headers of one Linux version I looked at, by default glDrawElementsInstanced isn't exposed by the the headers, even though OpenGL 4.5 is supported.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, the functionality from newer OpenGL versions are apparently handled through the OpenGL extension system. (Even if it's not strictly an &quot;extension&quot;, but part of standard functionality.) That is, each individual user is nominally responsible for loading the function address into the appropriate function variable using the appropriate (platform-specific) &lt;code&gt;*GetProcAddress()&lt;/code&gt; function from the &lt;code&gt;GL/glext.h&lt;/code&gt; header. &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glXGetProcAddress.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;The usage&lt;/a&gt; is to pass the appropriate string to the function, which will return a function pointer to the appropriate function (if present), or a null pointer if the functionality can't be found. (See the &lt;a href=&quot;https://open.gl/context#Onemorething&quot; rel=&quot;nofollow noreferrer&quot;&gt;tutorial section&lt;/a&gt; for more detail on usage.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is, obviously, somewhat less than satisfactory if you're using modern OpenGL features. There is a preprocessor define GL_GLEXT_PROTOTYPES which, when defined prior to including &lt;code&gt;GL/glext.h&lt;/code&gt;, will enable the definitions of a large number of standard functions. However, this may not work robustly if you're running on a computer which doesn't implement all of those functions which you're using. (You're likely to get missing symbol error during shared library loading.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The better way to handle things is to use the &lt;a href=&quot;http://glew.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Extension Wrangler&lt;/a&gt; (GLEW). This hides the heavy lifting of the whole &lt;code&gt;*GetProcAddress()&lt;/code&gt; process, defining symbols like &lt;code&gt;glDrawElementsInstanced&lt;/code&gt; directly in the &lt;code&gt;glew.h&lt;/code&gt; header. So long as you call &lt;code&gt;glewInit()&lt;/code&gt; after initializing OpenGL but before using any version dependent function, these functions should be initialized appropriately if available, or to a null pointer if not. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can either test for the function pointer being non-null, or use the GLEW-provided version test variables like &lt;code&gt;GLEW_VERSION_3_1&lt;/code&gt;, which are booleans (not compile-time defines) indicating if that OpenGL version is supported on the computer the program is running on. Alternatively, you can &lt;a href=&quot;http://glew.sourceforge.net/basic.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;test on a feature-by-feature level&lt;/a&gt; by using &lt;code&gt;glewIsSupported()&lt;/code&gt;/&lt;code&gt;glewGetExtension()&lt;/code&gt;. You can look up the respective strings for individual extensions at the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/index_gl.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Registry&lt;/a&gt;. It doesn't lend itself to forward searching, but may permit use of features prior to the nominal version of OpenGL in use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So why wasn't this clearer to me before? I think it's because most of the tutorials and documentation about OpenGL simply assume that you're using GLEW. Despite its name, GLEW isn't just about extensions, it also abstracts much of the version-to-version compatibility issues. As long as you put use behind version checks and don't actually attempt to call a non-supported function, GLEW hides all the pesky details about functions which aren't actually being implemented.&lt;/p&gt;&#xA;" OwnerUserId="8497" LastActivityDate="2018-04-11T23:24:45.870" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7499" PostTypeId="2" ParentId="7496" CreationDate="2018-04-11T23:36:27.537" Score="1" Body="&lt;p&gt;It might be a bit of an overkill, but you could use spatial partitioning, such as Octrees. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have it built, you can start evaluating partitions, given a max depth level of your choice, and form bounding volumes with the vertices inside each partition.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can test all of your shapes for each partition and choose the one that approximates the best all vertices you are enclosing in it (you can measure this by, for example, the volume which, while enclosing all vertices, takes up the less volume).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I've never tried anything like this, is purely theoretical&lt;/p&gt;&#xA;" OwnerUserId="8394" LastActivityDate="2018-04-11T23:36:27.537" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7500" PostTypeId="1" CreationDate="2018-04-12T09:29:05.083" Score="0" ViewCount="71" Body="&lt;p&gt;I'm studying Unreal Engine, this chapter is talk about visual effects: &lt;a href=&quot;https://docs.unrealengine.com/en-us/Engine/Rendering/Overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rendering Overview&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some of them has obvious picture I can see whats the differences. But not all of them. Is there a site can let me input the keyword, like 'bloom', then it shows the description, a image contains 'no bloom' and 'has bloom' both?&lt;/p&gt;&#xA;" OwnerUserId="5222" LastEditorUserId="5222" LastEditDate="2018-04-16T05:58:29.663" LastActivityDate="2018-04-16T05:58:29.663" Title="Where can I find those visual effect demonstration?" Tags="&lt;rendering&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7501" PostTypeId="2" ParentId="7500" CreationDate="2018-04-12T20:56:19.803" Score="3" Body="&lt;p&gt;The Unreal Engine documentation has good explanations for their various post-processing effects like Bloom. You can find more information about it here: &lt;a href=&quot;https://docs.unrealengine.com/en-us/Engine/Rendering/PostProcessEffects/Bloom&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.unrealengine.com/en-us/Engine/Rendering/PostProcessEffects/Bloom&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of UE4, bloom becomes observable once color values push beyond the 1.0 value.&lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2018-04-12T20:56:19.803" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7502" PostTypeId="2" ParentId="7483" CreationDate="2018-04-12T21:34:46.770" Score="4" Body="&lt;p&gt;What they're saying is you don't have to &lt;em&gt;render&lt;/em&gt; the game at the same resolution that it's displayed. For example you could be in a display mode of 1920×1080, but have the game rendering at only 1280×720, to run faster. The OS and display hardware can automatically upscale the frames to the display resolution under the hood.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually, the OS runs a window compositor, a background process that draws the desktop, all app windows, menus, etc and presents them to the display. In windowed mode, any upscaling needed would be done by the compositor. However if the game's window is covering the whole display ('borderless fullscreen') and nothing else is on top, then the OS can switch off the compositor and let the game present to the display directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But then if the game is at a lower resolution than the display, it still needs to be upscaled. The GPU can do this in hardware (scanout) &lt;em&gt;as long as&lt;/em&gt; the scaling factor isn't too big. For instance, there may be a limit of 4x scaling. So, if your rendering resolution is more than 4x smaller than the display, the OS can't use the hardware upscaling and would need to keep using the window compositor instead. All of this stuff happens automatically in Windows 10, without the app needing to know about it or do anything special.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given all this, they point out that there's no real reason for the &lt;em&gt;rendering&lt;/em&gt; resolution of the game to be limited to the classic display modes like 800×600, 1024×768, 1280×720, etc. You might as well have a continuous resolution slider instead of a fixed set of modes. There's no problem with choosing a &quot;weird&quot; resolution like, say, 1000×562 or something. The upscaler/compositor will just take care of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This what they mean by &quot;consider providing users with the ability to choose a rendering resolution for performance scaling, independent from an output resolution&quot;. In other words, in your game's options screen, you should give the user a slider to control rendering resolution, so they can tune it for performance vs visual quality. But it need not be tied to the actual display resolution.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-04-12T21:34:46.770" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7503" PostTypeId="1" CreationDate="2018-04-13T17:53:45.510" Score="14" ViewCount="12675" Body="&lt;p&gt;Currently I am reading the BRDF section from Real Time Rendering and I am having a hard time to visually understand the definition of this function. BRDF is the ratio between the radiance in outgoing direction and irradiance of incoming direction. I can't visually understand what does irradiance of a certain direction means? And what is the difference with radiance of certain direction? They both represents the power of light. What does irradiance of a certain direction means? Doesn't we associate a direction with radiance? Isn't radiance defined as irradiance in a single direction? I feel like i misunderstand something here. Is E(v) &amp;lt;= L(v) where v is direction?&lt;/p&gt;&#xA;" OwnerUserId="8565" LastActivityDate="2021-02-22T12:10:53.687" Title="What is the difference between radiance and irradiance in BRDF" Tags="&lt;brdf&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="8" ContentLicense="CC BY-SA 3.0" />
  <row Id="7504" PostTypeId="1" AcceptedAnswerId="7507" CreationDate="2018-04-13T18:38:47.533" Score="5" ViewCount="2009" Body="&lt;p&gt;I have a memory that is persistently mapped. It is both HOST_VISIBLE and HOST_COHERENT but not DEVICE_LOCAL. (My physical device offers no memory that is exclusively HOST_VISIBLE without also being HOST_COHERENT.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This memory contains vertex buffers. I send commands every frame to draw those buffers. Some of those, I change the content every frame, and others more rarely. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe buffers somehow need to be transfered by the driver into the GPU before it can draw them, yes? Here, I never need to invalidate/flush anything because the memory is HOST_COHERENT. How does the driver know what to update/transfer and when? Does it have to a way to detect parts where I change stuff, or does it compulsively retransfer data every frame? &lt;/p&gt;&#xA;" OwnerUserId="8118" LastActivityDate="2018-04-14T02:10:19.103" Title="Vulkan: how does host coherence work?" Tags="&lt;vulkan&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7505" PostTypeId="2" ParentId="7494" CreationDate="2018-04-13T20:50:19.290" Score="2" Body="&lt;p&gt;If you really need this level of debugging (spoiler: you don't, more on that later), AFAIK only NVIDIA's NSight can provide it. However, in order to remain interactive, you probably need two machines - one to actually run your shader, and the other to debug it - because stopping a GPU for debugging will - quite understandably - freeze the display of the computer, making it unusable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One step down from that is &lt;a href=&quot;http://www.renderdoc.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;RenderDoc&lt;/a&gt; and its ability to swap shaders in a capture on the fly, as well as step through Direct3D bytecode and inspect its registers (i.e. a virtual machine for the DXBC, it's most often sufficiently detailed to actually find shader bugs).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And what most graphics programmers do most days is simply what I like to call &quot;your mom's debugger&quot;, which on the CPU means sprinkling your code with print statements with the intention of later reviewing the log; but in shaders, you just stuff your shader outputs with debug values instead and inspect those values. There are also ways to &quot;print text&quot; from shaders (for instance, &lt;a href=&quot;https://www.shadertoy.com/view/4dtGD2&quot; rel=&quot;nofollow noreferrer&quot;&gt;this ShaderToy&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2018-04-13T20:50:19.290" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7506" PostTypeId="2" ParentId="7504" CreationDate="2018-04-13T21:49:23.310" Score="3" Body="&lt;p&gt;I don't think this kind of under-the-hood data transfer should happen in low-level APIs like Vulkan. The GPU is capable of reading directly from host memory, via the PCIe interconnect. So when you render from a host memory buffer, it should dynamically &quot;pull&quot; the vertices referenced by the draw call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure exactly how host coherence works with this, but my guess is the CPU's memory controller is probably smart enough to snoop PCIe read requests, and do the right thing with regard to the CPU caches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you &lt;em&gt;wanted&lt;/em&gt; to transfer the data into GPU memory first, I think you would have to implement that yourself, by allocating some device-local memory and doing a copy into it. (For a vertex buffer that's pretty much consumed linearly once per frame, there's probably no benefit to doing that, but it could be worthwhile for a buffer that's updated more rarely, or that has a more random access pattern.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-04-13T21:49:23.310" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7507" PostTypeId="2" ParentId="7504" CreationDate="2018-04-14T02:10:19.103" Score="6" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;How does the driver know what to update/transfer and when?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It doesn't. There is no transfer or update in that fashion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All memory allocated through a Vulkan device represents memory that &lt;em&gt;some&lt;/em&gt; device operations can read directly. If a Vulkan device advertises that it can use visible/coherent memory as source vertex data for rendering operations, that does not mean that some kind of upload is going on to make this happen. The device is reading that data from the memory you write to. The &lt;code&gt;vkFlushMappedRange&lt;/code&gt; function merely expunges writes from CPU cache lines, so that they actually reach the memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Memory that is host-coherent and host-visible would represent memory that either:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Is not cached by the CPU, and therefore the GPU sees the memory as it is. This also means that CPU writes and reads tend to be slow.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The GPU can directly access the CPU's caches, to one degree or another.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Usually, #2 happens when the GPU is on-die with the CPU. Which would also mean that this would be device-local memory. Since you've said that it isn't device-local, odds are good that it is simply not cached. It may use write-combining (which improves the efficiency of sequential writes), but CPU writes otherwise are delivered as they are. Given that the memory does not seem to include &quot;cached&quot; in its description, I'd say #1 is the most likely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that just because you don't need to explicitly flush memory does not change the fact that you still need a dependency between the CPU operation writing that data and the GPU command(s) that read it. This would generally be some from of event with a memory dependency.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-04-14T02:10:19.103" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7509" PostTypeId="2" ParentId="7487" CreationDate="2018-04-14T10:23:22.133" Score="1" Body="&lt;p&gt;This would not be perfect but should probably work well enough for your use case - you could render the objects from lots of different angles with a different solid color for each mesh component (without lighting) then remove any meshes that didn't appear in the final image by counting the pixel colours.&#xA;If the objects aren't split up into separate meshes then do this by repeatedly merging groups of triangles which share a vertex into the same group, starting with one group per triangle or polygon.&lt;/p&gt;&#xA;" OwnerUserId="8570" LastActivityDate="2018-04-14T10:23:22.133" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7511" PostTypeId="2" ParentId="7503" CreationDate="2018-04-14T16:49:34.570" Score="7" Body="&lt;p&gt;It is helpful if you always look at the units that a certain physical quantity measures. Since you use Real-Time Rendering, I'll also quote from that (3rd edition). Also, for the sake of completeness, I'll go through all quantities and units related. I will however assume you understand solid angles. The time $t$ is measured in &lt;em&gt;seconds&lt;/em&gt; $\left[s\right]$ and the solid angles $\omega$ are measured in &lt;em&gt;steradians&lt;/em&gt; $\left[sr\right]$.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;radiant energy $Q$&lt;/em&gt; (in &lt;em&gt;joules&lt;/em&gt;, $\left[J\right]$) measures the energy, i.e. the energy of a photon times the number of photons.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;radiant flux $\Phi$&lt;/em&gt; (in &lt;em&gt;watts&lt;/em&gt;, $\left[W]\right]= \left[\frac{J}{s}\right])$ measures the energy per time, e.g. don't just count the number of photons but the number of photons per second. $\Phi = \frac{Q}{t}$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;a) &lt;em&gt;irradiance $E$&lt;/em&gt; (in &lt;em&gt;watts per square meter&lt;/em&gt;, $\left[\frac{W}{m^2}\right]$) measures the energy per time and surface area, or the flux per surface area. $E = \frac{Q}{t A} = \frac{\Phi}{A}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;b) &lt;em&gt;radiosity $M$&lt;/em&gt; (in some papers also $B$) is the same as irradiance, only it's leaving a surface and not arriving at it&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;em&gt;radiance $L$&lt;/em&gt; (&lt;em&gt;watts per sqaure meter per steradian&lt;/em&gt;, $\left[\frac{W}{m^2 sr}\right]$) is the radiant flux per area and solid angle, or the irradiance per solid angle. $L = \frac{\Phi}{A w}$&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Now there is one thing to consider: $E$ is measured with regards to a a surface $A$ that is perpendicular to the light direction (in other words, the normal of the surface is parallel to the light direction). Therefore we project $A$ onto a plane that fullfills this requirement. If the angle between the surface normal and the light direciton is $\theta$, then our projected surface $A_{proj}$ is calculated thus: $A_{proj} = \frac{A}{cos\theta}$&lt;a href=&quot;https://i.stack.imgur.com/aJrFR.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aJrFR.png&quot; alt=&quot;Surface $A$ is being projected on a plane, the result is $A_{proj}$, from &amp;quot;Parameterbasierte Texturgenerierung und echtzeitfähiges Rendering von nassen und trockenen Straßenoberflächen in kamerabasierten ADAS Tests&amp;quot;, Tim Lobner&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With this, we can of course also further our radiance calculation to $L = \frac{E}{\omega}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But still, $E$ only considers the amount of energy per time, not from which direction it comes. Why is this important? Because of the way you usually look at lighting in computer graphics. You calculate how much light is being reflected from a surface to your viewer (/camera), which also means, that you want to know from which light source it originates (seeing as you would like to have the right amount of energy and the correct color). Additionally, you usually use point lights, meaning that you can view the lighting calculation as that of a ray from a single point (the light source) onto a single point on a surface (your pixel/fragment) and then to your viewer. These directions are written in the matter of solid angles, or to make the theory even easier, in differential solid angles. Another point is that your surface may reflect light differently depending on the where it comes from, which also makes important the direction part. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to sum this up a bit:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I can't visually understand what does irradiance of a certain direction means?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It basically means photons from a specific light source, not from any place in space.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;And what is the difference with radiance of certain direction?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I hope it is clear, that radiance is irradiance from a certain direction. If not, please try to specify which part still bothers you.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;They both represents the power of light&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes they do. In fact, &lt;em&gt;steradian&lt;/em&gt; is a dimensionless unit, since it is $\left[\frac{m^2}{m^2}\right]$, and therefore it doesn't really add anything. I see how this is confusing. I hope I could clear up why you do this.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;What does irradiance of a certain direction means? Doesn't we associate a direction with radiance?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Careful. We don't associate direction (other than considerung only surfaces perpendicular to the light direction) with irradiance. We do however with radiance.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Isn't radiance defined as irradiance in a single direction?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, you can say that.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is E(v) &amp;lt;= L(v) where v is direction?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'd say it is the other way round, $L(v) \leq E(v)$, since $E(v)$ would consider any light source emitting light onto a surface, whereas $L(v)$ only considers light form $v$ (if you consider $v$ as the light source to surface direction. In my writing earlier, this is $\omega$ and in Real Time Rendering specifically, this is $\omega$ as well, or $l$ in chapter 5 as well as in the BRDF Theory chapter). Also, remember that these two physical quantities don't have the same units and should not really be compared this way.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-04-14T16:49:34.570" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7512" PostTypeId="2" ParentId="7503" CreationDate="2018-04-15T12:58:41.717" Score="10" Body="&lt;p&gt;First of all, &lt;strong&gt;irradiance&lt;/strong&gt; at a certain point of a surface is the density of radiant flux (power) per unit of surface area, while &lt;strong&gt;radiance&lt;/strong&gt; at a certain point of a surface in a certain direction is the density of radiant flux per unit of surface area and unit of solid angle. Vaguely speaking, &lt;strong&gt;irradiance&lt;/strong&gt; is the amount of light incoming to a certain point from possibly all directions, while &lt;strong&gt;radiance&lt;/strong&gt; is the amount of light incoming to a point from a single direction. Why on Earth do we talk about irradiance from a direction then?&lt;/p&gt;&#xA;&lt;p&gt;The thing is that the BRDF definition assumes that there is radiance &lt;span class=&quot;math-container&quot;&gt;$L_i\left(\omega_i\right)$&lt;/span&gt; incoming to point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; through an infinitesimal cone &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}\omega_{i}$&lt;/span&gt; around the direction &lt;span class=&quot;math-container&quot;&gt;$\omega_i$&lt;/span&gt; with solid angle size denoted &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}\sigma\left(\omega_{i}\right)$&lt;/span&gt;, which then generates some irradiance on the surface. This &amp;quot;partial&amp;quot; irradiance is then denoted &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}E\left(\omega_{i}\right)$&lt;/span&gt;. This incident light can be partially absorbed by the surface and partially scattered in all directions. The out-scattered contribution of &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}E\left(\omega_{i}\right)$&lt;/span&gt; to radiance outgoing in direction &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt; is denoted as &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}L_{o}\left(\omega_{o}\right)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;It can be shown experimentally that the amount of outgoing radiance &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}L_{o}\left(\omega_{o}\right)$&lt;/span&gt; is proportional to the incoming irradiance &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}E\left(\omega_{i}\right)$&lt;/span&gt; and the BRDF is then defined simply as the ratio between the two:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f_{r}\left(\omega_{i}\rightarrow\omega_{o}\right) = \frac{\mathrm{d}L_{o}\left(\omega_{o}\right)}{\mathrm{d}E\left(\omega_{i}\right)}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="15810" LastEditDate="2021-02-22T12:10:53.687" LastActivityDate="2021-02-22T12:10:53.687" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7513" PostTypeId="1" CreationDate="2018-04-15T15:07:44.220" Score="7" ViewCount="4946" Body="&lt;p&gt;I can easily make models by &lt;a href=&quot;http://iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;noreferrer&quot;&gt;Modeling with Distance Functions&lt;/a&gt; but I need make mesh from It so I decide to use voxelizing and make triangles for my &lt;a href=&quot;https://www.gamasutra.com/blogs/DavidArppe/20170405/295240/How_to_get_Stunning_Graphics_with_Raymarching_in_Games.php&quot; rel=&quot;noreferrer&quot;&gt;signed distance field torus&lt;/a&gt; like &lt;a href=&quot;https://www.youtube.com/watch?v=B_xk71YopsA&quot; rel=&quot;noreferrer&quot;&gt;this video&lt;/a&gt;.but I haven't Idea that how can I do this.&#xA;you can see this torus on &lt;a href=&quot;https://github.com/smkplus/UnityRayMarching&quot; rel=&quot;noreferrer&quot;&gt;my github&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jF5Ng.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jF5Ng.png&quot; alt=&quot;torus&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h1&gt;Update&lt;/h1&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YoSlj.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YoSlj.png&quot; alt=&quot;Snail IQ&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/ld3Gz2&quot; rel=&quot;noreferrer&quot;&gt;Snail SDF&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I found a software as &lt;strong&gt;SDF Mesher&lt;/strong&gt;.this is what I want but not released.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.instagram.com/aiekick/&quot; rel=&quot;noreferrer&quot;&gt;aiekick instagram&lt;/a&gt;,&#xA;&lt;a href=&quot;https://twitter.com/hashtag/sdfmesher&quot; rel=&quot;noreferrer&quot;&gt;aiekick twitter&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;he converted shader to mesh?! how could be Implemented!?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://sketchfab.com/Aiekick&quot; rel=&quot;noreferrer&quot;&gt;aiekick sketchfab&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;In short I need a way to convert sdf to mesh.for example this:&lt;/p&gt;&#xA;&lt;p&gt;Input : &lt;a href=&quot;https://www.shadertoy.com/view/4tc3WB&quot; rel=&quot;noreferrer&quot;&gt;SDF Model&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Output : &lt;a href=&quot;https://sketchfab.com/models/e1ebf9fcd38444d88e45f84204781db9&quot; rel=&quot;noreferrer&quot;&gt;Mesh&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6541" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-09-07T15:00:27.583" Title="How can I convert signed distance field to a mesh?" Tags="&lt;glsl&gt;&lt;mesh&gt;&lt;raymarching&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="7514" PostTypeId="1" CreationDate="2018-04-15T19:48:29.537" Score="1" ViewCount="41" Body="&lt;p&gt;I need to contract(offset) a mesh by a small amount(around 5mm), the mesh itself is quite big (say, 1000mm). The problem is that, I need to contract it based on local mean curvature. That is, for places with higher mean curvature(protruding) less contraction is wanted; and vice versa.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The best approximation I can find now is CGAL's mesh skeletonization. The skeletonization is done with iterative contraction by mean curvature. So instead of contraction many times, I contract only once, and get what I need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with this approach is that the intermediate mesh is not garanteed to be self-intersection free, forbidding further processing. I don't have reliable way to automatically repair intersection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can of course, compute mean curvature at vertices myself and contract accordingly. Problem is I don't know to which direction I should offset a vertex. If I just use the vertex normal, the resulted mesh is very messy(not smooth).&lt;/p&gt;&#xA;" OwnerUserId="8575" LastActivityDate="2018-04-15T19:48:29.537" Title="contract mesh based on mean curvature?" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7515" PostTypeId="2" ParentId="7513" CreationDate="2018-04-15T19:50:22.117" Score="2" Body="&lt;p&gt;with CGAL you can generate mesh by implicit function. &lt;a href=&quot;https://doc.cgal.org/latest/Mesh_3/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://doc.cgal.org/latest/Mesh_3/index.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Search for &quot;implicit&quot;. There is an example of generating meshes from the funciton of a sphere.&lt;/p&gt;&#xA;" OwnerUserId="8575" LastActivityDate="2018-04-15T19:50:22.117" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7516" PostTypeId="2" ParentId="7513" CreationDate="2018-04-16T06:00:59.563" Score="1" Body="&lt;p&gt;After many research I figured out how it works:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;he defined three buffer in glsl and i get 3 sampler2D for multipass, in each fbo attachments. the params are (buffer : file : id) file is the targeted shader, here we want the current so no file. id is the fbo attachment (0 to 7).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/byRkM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/byRkM.png&quot; alt=&quot;Result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then he could make the mesh easily:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://user-images.githubusercontent.com/16706911/38791232-cfe1def2-415b-11e8-8961-d93c06dd87d4.gif&quot; alt=&quot;SDF Mesher&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="6541" LastActivityDate="2018-04-16T06:00:59.563" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="7517" PostTypeId="2" ParentId="7503" CreationDate="2018-04-16T18:08:32.713" Score="2" Body="&lt;p&gt;To be honest, terms like these are very confusing as they aren't clear cut and on one side of the border. They are more grayish.&lt;/p&gt;&#xA;&lt;p&gt;I'm gonna tell you how I convinced myself, as I too had this confusion as soon as I read your question. But I managed to convince myself through this argument.&lt;/p&gt;&#xA;&lt;p&gt;First of all we are gonna clear up 4 terms, Radiance, Irradiance, Differential radiance and Differential Irradiance.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;&amp;quot;Radiance&amp;quot; is what you say associated with a certain direction. To be more formal and according to wikipedia,&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;It's the amount of radiant flux emitted/transmitted/received per unit&#xA;projected area, per unit solid angle.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;Next is differential radiance. We can think of it as an infinitesimal quantity of radiance emitted or recieved in a very small solid angle &lt;span class=&quot;math-container&quot;&gt;$d\omega$&lt;/span&gt;.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Next is Irradiance. Irradiance isn't normally associated with a direction. According to Wikipedia it's&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Radiant flux received by a surface per unit area&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;But more commonly and what makes more sense to me, and to the answer of your question, think of irradiance as the integration of radiances over a set of directions.&lt;/p&gt;&#xA;&lt;p&gt;So we can say&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$E = \displaystyle\int_{\Omega} L(\omega)\;  \omega.n \;d\omega\\\omega \in \Omega$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So if we integrate the radiances from every direction that leads us to the original definition of irradiance where direction isn't of concern. However usually we are concerned with only a subset of all the directions such as the Upper hemisphere or the lower hemisphere. This means for example,&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\Omega = \{ \omega : \omega.n \geq 0 \}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;As we can see here, we have limited the irradiance to a set of directions, the upper hemisphere. This doesn't necessarily change it into radiance which is associated by direction. Instead what this means is, when calculating irradiance we are concerned with the light coming only from these directions, although we haven't incorporated the directional quantity into the formula like with radiance.&lt;/p&gt;&#xA;&lt;p&gt;This is the difference between irradiance from a certain direction and radiance. Think of it like this. You are holding a paper and there are 2 light bulbs in front of you. You want to measure the irradiance. Normally it would just be the radiant flux received by both bulbs per unit area. But now let's say I limit the direction so I am only concerned with the first bulb. Note that I am still calculating the &amp;quot;irradiance&amp;quot;. If I move farther away the flux will decrease thus the irradiance even tho I am concerned with a specific direction. However this isn't the case with radiance where moving farther away won't change it since we divide by the solid angle too balancing the change.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The last quantity is differential irradiance. I thought of it as a tiny amount of irradiance from a specific direction. (Again direction gets involved)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;If you think of irradiance as not assosciated with direction at all, even then when you try to think of differential irradiance you are gonna say it's a tiny amount of irradiance from a small range of direction or maybe a specific direction. That's the reason why it's small.&lt;/p&gt;&#xA;&lt;p&gt;But if you think of irradiance as the sum of all the radiances over a specific set of directions. You'll see that it makes things clearer and you'll naturally arrive at the conclusion that differential irradiance will then refer to an irradiance from a specific direction.&lt;/p&gt;&#xA;&lt;p&gt;So coming back to your question at last, I hope you might have gotten some intuition as to what &amp;quot;irradiance in a direction means&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;Mathematically proving it is no hard feat tho. The answer &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/3757/why-isnt-a-brdf-a-ratio-of-radiances&quot;&gt;here&lt;/a&gt; explains it quite well. I'm just gonna give a brief explanation. We know the rendering equation is given as&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_{outgoing} = L_{emission} + \displaystyle\int_{\Omega} L_{incoming} \;f_{BRDF}(\omega_i, \omega_o)\; \omega_i.n \; d\omega_i$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Assuming for the moment that emission part is zero. we end up with,&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_{outgoing} = \displaystyle\int_{\Omega} L_{incoming} \;f_{BRDF}(\omega_i, \omega_o)\; \omega_i.n \; d\omega_i$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now as I wrote before, if you forget the BRDF for the time being, we are just integrating the radiances over a given set of direction which is the same as irradiance.&lt;/p&gt;&#xA;&lt;p&gt;If we look at one instance of this summation/integration, it's gonna be&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$dL_{outgoing} =  L_{incoming} \; \omega_i.n \; d\omega_i \; f_{BRDF}(\omega_i, \omega_o)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$dL_{outgoing} =  dE \; f_{BRDF}(\omega_i, \omega_o)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;We put &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; with the outgoind radiance and irradiance because it's a very small part (we are looking at just one instance of that summation/integration)&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f_{BRDF}(\omega_i, \omega_o) = \displaystyle\frac{dL_{outgoing}}{dE} $&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Which is the ratio of the outgoing radiance to the incoming irradiance.&lt;/p&gt;&#xA;&lt;p&gt;Again this was just the way I convinced myself and might have some mistakes. Though this is the best I came up with.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-04-16T18:08:32.713" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="7519" PostTypeId="1" AcceptedAnswerId="7520" CreationDate="2018-04-17T17:37:57.943" Score="2" ViewCount="2137" Body="&lt;p&gt;I've read the reference guide about the file but I am really confused. Why the hell are there &quot;min&quot; and &quot;max&quot; values ?? A single vertex has only one coordinate array not min and max..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also in the structure of the meshes why is there an &quot;indices&quot; reference to the &quot;accessors&quot; if we already put the indices to the &quot;attributes&quot; like &quot;NORMAL: 2&quot;? &lt;/p&gt;&#xA;" OwnerUserId="8587" LastActivityDate="2018-04-17T19:51:09.247" Title="How mesh geometry data (vertex coordinates) stored in glTF?" Tags="&lt;gltf&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7520" PostTypeId="2" ParentId="7519" CreationDate="2018-04-17T19:51:09.247" Score="2" Body="&lt;p&gt;The &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; values provide an outer bounding box for all &lt;code&gt;POSITION&lt;/code&gt; data within a given accessor.  Accessors typically contain multiple vertices, for example all of the vertices of a particular primitive, and then &lt;code&gt;min: [x, y, z]&lt;/code&gt; and &lt;code&gt;max: [x, y, z]&lt;/code&gt; will offer the bounding box for that primitive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your second question, let's look at the mesh structure from &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/blob/0bc74b12b2de22a1267ccab819efcf8c6a4f3dc8/2.0/BoxTextured/glTF/BoxTextured.gltf#L44-L56&quot; rel=&quot;nofollow noreferrer&quot;&gt;BoxTextured.gltf&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;meshes&quot;: [&#xA;    {&#xA;        &quot;primitives&quot;: [&#xA;            {&#xA;                &quot;attributes&quot;: {&#xA;                    &quot;NORMAL&quot;: 1,&#xA;                    &quot;POSITION&quot;: 2,&#xA;                    &quot;TEXCOORD_0&quot;: 3&#xA;                },&#xA;                &quot;indices&quot;: 0,&#xA;                &quot;mode&quot;: 4,&#xA;                &quot;material&quot;: 0&#xA;            }&#xA;        ],&#xA;        &quot;name&quot;: &quot;Mesh&quot;&#xA;    }&#xA;],&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In the above example, &lt;code&gt;mode: 4&lt;/code&gt; is an enum, where &lt;code&gt;4&lt;/code&gt; means &lt;code&gt;TRIANGLES&lt;/code&gt;.  The &lt;code&gt;indices&lt;/code&gt; are stored in accessor &lt;code&gt;0&lt;/code&gt;, and the &lt;code&gt;POSITION&lt;/code&gt; data is stored in accessor &lt;code&gt;2&lt;/code&gt;.  So, accessor &lt;code&gt;2&lt;/code&gt; will contain a list of vertex positions, but each vertex is allowed to be referenced by multiple triangles.  The indices in accessor &lt;code&gt;0&lt;/code&gt; declare the triangles by indexing into the list of vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a sample of the start of accessor &lt;code&gt;0&lt;/code&gt; from this model:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0 &#xA;1 &#xA;2 &#xA;&#xA;3 &#xA;2 &#xA;1 &#xA;&#xA;4 &#xA;5 &#xA;6 &#xA;&#xA;7 &#xA;6 &#xA;5 &#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this is a sample of the contents from the start of accessor &lt;code&gt;2&lt;/code&gt; in this model:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;-0.50000    -0.50000     0.50000 &#xA; 0.50000    -0.50000     0.50000 &#xA;-0.50000     0.50000     0.50000 &#xA; 0.50000     0.50000     0.50000 &#xA; 0.50000     0.50000     0.50000 &#xA; 0.50000    -0.50000     0.50000 &#xA; 0.50000     0.50000    -0.50000 &#xA; 0.50000    -0.50000    -0.50000 &#xA; ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In this manner, the sample model builds a cube by winding triangles around vertices at the corners.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a more graphical explanation of this, check out the &lt;a href=&quot;https://raw.githubusercontent.com/KhronosGroup/glTF/master/specification/2.0/figures/gltfOverview-2.0.0a.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;glTF Overview Card&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastActivityDate="2018-04-17T19:51:09.247" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="7521" PostTypeId="2" ParentId="2510" CreationDate="2018-04-18T00:37:45.463" Score="0" Body="&lt;p&gt;The left bounds are defined as edges where the interior of the polygon is on the right. Think of them as just being the left edge of the shape. You can see from the given polygon that one left edge (the one furthest on the left) starts at P0 and goes to P6. This is the leftmost edge of the polygon. The only other area of the polygon that has an edge on the left side is the part that looks like a devil horn on the right. Its left edge starts at P4 and goes up to P2.&lt;/p&gt;&#xA;" OwnerUserId="8591" LastActivityDate="2018-04-18T00:37:45.463" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7522" PostTypeId="1" CreationDate="2018-04-18T01:38:55.257" Score="-2" ViewCount="111" Body="&lt;p&gt;Crossposted here &lt;a href=&quot;http://forum.lwjgl.org/index.php?topic=6724&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://forum.lwjgl.org/index.php?topic=6724&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hello guys I am trying to blur image using fragment shader but it is not smooth.. I search the internet and I found similar problem... some one answer his question but unfortunately I cannot fallow it.. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question here are similar to my problem. this one &lt;a href=&quot;https://stackoverflow.com/questions/33778381/how-to-blur-image-using-glsl-shader-without-squares&quot;&gt;https://stackoverflow.com/questions/33778381/how-to-blur-image-using-glsl-shader-without-squares&lt;/a&gt; and this one &#xA;&lt;a href=&quot;https://stackoverflow.com/questions/44829671/smooth-blur-gaussian-in-opengl-es-2-0&quot;&gt;https://stackoverflow.com/questions/44829671/smooth-blur-gaussian-in-opengl-es-2-0&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I am trying this code but I got error. cannot call a non-function&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 120&#xA;&#xA;uniform sampler2D sampler;&#xA;varying vec2 tex_coords;&#xA;&#xA;vec4 funcBlurTexture() {&#xA;    float blur = 1.0/387.; //?? original settings: 2.0/720.; &#xA;    //float blur = 1.0/1280.;&#xA;&#xA;     vec4 sum = vec4(0.0);&#xA;     vec2 tc = tex_coords;&#xA;&#xA;     float hstep = tex_coords.x;&#xA;     float vstep = tex_coords.y;&#xA;&#xA;     float horizontalOffset = 2.0;&#xA;     float radius = 2.0;&#xA;     float verticalOffset = 2.0;&#xA;     float gaussFactorForOffset = 1.0;&#xA;&#xA;     //Trying to use this&#xA;     for(horizontalOffset = -radius; horizontalOffset&amp;lt;radius; horizontalOffset  += step) {&#xA;        for(verticalOffset = -radius; verticalOffset&amp;lt;radius; verticalOffset += step) {&#xA;            sum += texture2D(sampler, tex_coords+vec2(horizontalOffset, verticalOffset))*gaussFactorForOffset(sqrt(horizontalOffset*horizontalOffset + verticalOffset*verticalOffset)/radius);&#xA;        }&#xA;     }&#xA;&#xA;     /*&#xA;    //Old Code&#xA;     sum += texture2D(sampler, vec2(tc.x - 4.0*blur*hstep, tc.y)) * 0.0162162162;&#xA;     sum += texture2D(sampler, vec2(tc.x - 3.0*blur*hstep, tc.y)) * 0.0540540541;&#xA;     sum += texture2D(sampler, vec2(tc.x - 2.0*blur*hstep, tc.y)) * 0.1216216216;&#xA;     sum += texture2D(sampler, vec2(tc.x - 1.0*blur*hstep, tc.y)) * 0.1945945946;&#xA;     sum += texture2D(sampler, vec2(tc.x, tc.y)) * 0.2270270270;&#xA;     sum += texture2D(sampler, vec2(tc.x + 1.0*blur*hstep, tc.y)) * 0.1945945946;&#xA;     sum += texture2D(sampler, vec2(tc.x + 2.0*blur*hstep, tc.y)) * 0.1216216216; &#xA;     sum += texture2D(sampler, vec2(tc.x + 3.0*blur*hstep, tc.y)) * 0.0540540541;&#xA;     sum += texture2D(sampler, vec2(tc.x + 4.0*blur*hstep, tc.y)) * 0.0162162162;&#xA;     */&#xA;&#xA;        vec4 vColor = texture2D(sampler, tex_coords); &#xA;        vec4 bluredTexture = vColor * vec4(sum.rgb, 1.0);&#xA;    return bluredTexture;&#xA;}&#xA;&#xA;void main() {&#xA;    gl_FragColor = funcBlurTexture();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How to apply this code in my shader?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for(horizontalOffset = -radius; horizontalOffset&amp;lt;radius; horizontalOffset  += step) {&#xA;    for(verticalOffset = -radius; verticalOffset&amp;lt;radius; verticalOffset += step) {&#xA;        sum += texture2D(texture, textureCoordinate+vec2(horizontalOffset, verticalOffset))*gaussFactorForOffset(sqrt(horizontalOffset*horizontalOffset + verticalOffset*verticalOffset)/radius);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any Help?&lt;/p&gt;&#xA;" OwnerUserId="8517" LastActivityDate="2018-04-18T06:33:36.040" Title="gaussFactorForOffset cannot call a non-function how to fixed this code?" Tags="&lt;fragment-shader&gt;&lt;gaussian-blur&gt;&lt;blur&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7523" PostTypeId="2" ParentId="7522" CreationDate="2018-04-18T06:33:36.040" Score="1" Body="&lt;p&gt;It would be helpful if you posted some more information about what you're trying to do (rather than problem links) and some screenshots of what is actually happening. Being here I basically see &quot;My code doesn't work, fix it.&quot;, which is not motivating to answer your question...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, you calculate an offset for reading out from your texture. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;texture2D(sampler, tex_coords+vec2(horizontalOffset, verticalOffset))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Texture coordinates are $u, v \in \left[0, 1\right]$, otherwise they will stay on the edge, border, go back to the opposite side or start from the opposide side again (depending on your set up). So this is offset is a problem at the borders in any case, but that is normal. If we now look at your offset&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float radius = 2.0;&#xA;for(horizontalOffset = -radius; horizontalOffset&amp;lt;radius; horizontalOffset  += step)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So you start with an offset of &lt;code&gt;-2.0&lt;/code&gt;, which far exceeds the texture coordinate interval and go up to &lt;code&gt;2.0&lt;/code&gt; which again exceeds the interval. This is probably the biggest problem you have in your code, calculation wise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, you use a variable &lt;code&gt;step&lt;/code&gt; to increase your &lt;code&gt;horizontalOffset&lt;/code&gt; and your &lt;code&gt;verticalOffset&lt;/code&gt; variables, but this &lt;code&gt;step&lt;/code&gt; has never been created. This should not even compile. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since your &lt;code&gt;horizontalOffset&lt;/code&gt; and &lt;code&gt;verticalOffset&lt;/code&gt;are meant for the gaussian blur, I guess a new variable is needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your next problem is, that iirc a gaussian blur should offset the texture coordinates, not the color. You multiply the readout color though, with your &lt;code&gt;gaussFactorForOffset&lt;/code&gt; method, which may be wrong. In any case, you don't even have the method, and it is not a standard &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;glsl&lt;/a&gt; method. Again this should not compile. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;What you need is to think about what your kernel must look like. In a simple box filter, you would sample a texel and every neighbouring texel, giving you 9 values. You add up the 9 values, divide by 9 to normalize and write the output. Your gauss blur can work the same way, only that you have to properly weigh the individual values depending on their position. You can also sample more pixels, than the direct neighbour, say the second neighbour as well - this will give you a nicer blur but will also be a lot slower since you have to do more texture look ups.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, start with hardcoding that, like you did in your old code. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In image processing, &lt;a href=&quot;https://stackoverflow.com/questions/20746172/blur-an-image-using-3x3-gaussian-kernel&quot;&gt;they also use these kernels&lt;/a&gt;, so you can look at them. The linked one would translate to your problem thus:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float verticalStep = 1/numberOfVerticalPixels;&#xA;float horizontalsteps = 1/numberOfHorizontalPixels; //these two variables you have to set yourself&#xA;//top row of kernel&#xA;sum += texture2D(sampler, vec2(tc.x - horizontalstep, tc.y - verticalStep)) * (1/16);&#xA;sum += texture2D(sampler, vec2(tc.x, tc.y - verticalStep)) * (1/8);&#xA;sum += texture2D(sampler, vec2(tc.x + horizontalstep, tc.y - verticalStep)) * (1/16);&#xA;//middle row&#xA;sum += texture2D(sampler, vec2(tc.x - horizontalstep, tc.y)) * (1/8);&#xA;sum += texture2D(sampler, vec2(tc.x, tc.y)) * (1/4);&#xA;sum += texture2D(sampler, vec2(tc.x + horizontalstep, tc.y)) * (1/8);&#xA;//bottom row&#xA;sum += texture2D(sampler, vec2(tc.x - horizontalstep, tc.y + verticalStep)) * (1/16);&#xA;sum += texture2D(sampler, vec2(tc.x, tc.y + verticalStep)) * (1/8);&#xA;sum += texture2D(sampler, vec2(tc.x + horizontalstep, tc.y + verticalStep)) * (1/16);&#xA;return sum;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now once you get this to work, then you can start optimizing. and cleaning up your code.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-04-18T06:33:36.040" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7525" PostTypeId="2" ParentId="4463" CreationDate="2018-04-19T09:15:50.597" Score="2" Body="&lt;p&gt;Back in the days, MSDN defined a couple of values which in most cases are useless (total crap):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/dd144877%28v=vs.85%29.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://msdn.microsoft.com/en-us/library/windows/desktop/dd144877%28v=vs.85%29.aspx&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int width_mm = GetDeviceCaps(hdx, HORZSIZE);&#xA;int height_mm = GetDeviceCaps(hdx, VERTSIZE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, there is a way to retrieve the information through VESA. Any modern monitor should be able to handle that. Only I have no clue how that's done. Under Linux you have a command called &lt;code&gt;xrandr&lt;/code&gt; which can be used to find out the info:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;% xrandr -q&#xA;Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384&#xA;VGA-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 553mm x 311mm&#xA;   1920x1080     60.00*+&#xA;   1680x1050     59.95  &#xA;   1600x1200     60.00  &#xA;   1440x900      59.89  &#xA;   1280x1024     60.02  &#xA;   1280x960      60.00  &#xA;   1280x720      60.00  &#xA;   1024x768      60.00  &#xA;   800x600       60.32  &#xA;   640x480       59.94  &#xA;DVI-D-0 disconnected (normal left inverted right x axis y axis)&#xA;HDMI-0 disconnected (normal left inverted right x axis y axis)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Note that I verified and my monitor dimensions in mm are correct in the output of my &lt;code&gt;xrandr -q&lt;/code&gt; command.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I would suggest you look at how that &lt;code&gt;xrandr&lt;/code&gt; tool does it and you'd get your info right at hand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I've read over the years, the VESA info can be wrong once in a while, but it's quite reliable now a day, I would think.&lt;/p&gt;&#xA;" OwnerUserId="8595" LastEditorUserId="8595" LastEditDate="2018-04-20T15:57:51.577" LastActivityDate="2018-04-20T15:57:51.577" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7526" PostTypeId="1" CreationDate="2018-04-19T09:24:43.877" Score="2" ViewCount="617" Body="&lt;p&gt;I want to create a scene where a room includes a projector and a white screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is a Ray Tracing environment functioning in such a setup? Is the light from the projector going through a slide and then the color reflecting on the white screen? If so, wouldn't any light ray bounce on that screen creating a mess?&lt;/p&gt;&#xA;" OwnerUserId="8595" LastActivityDate="2018-04-19T14:58:20.250" Title="How is a projector handled in a Ray Tracing environment?" Tags="&lt;raytracing&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7527" PostTypeId="2" ParentId="7526" CreationDate="2018-04-19T09:32:00.323" Score="4" Body="&lt;p&gt;Just treat it as a special case of a point light + shadow ray. Whenever a ray hits the screen (or any surface onto which you'd like to project the slide), fire another &quot;projector&quot; ray back towards the projector. If it is not obscured, then use the X &amp;amp; Y angles (relative to the coordinate system of the projector) to look up a texture map of the slide.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-04-19T09:51:15.437" LastActivityDate="2018-04-19T09:51:15.437" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7528" PostTypeId="2" ParentId="7526" CreationDate="2018-04-19T09:32:50.317" Score="3" Body="&lt;p&gt;Graphics is all about cheating when possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The projector can be a spotlight where the color of the light depends on the direction of the light vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's the same math required for shadow mapping with it.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-04-19T09:32:50.317" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7529" PostTypeId="1" CreationDate="2018-04-19T13:01:48.040" Score="5" ViewCount="340" Body="&lt;p&gt;I have a problem with precision on AMD in shaders (&lt;code&gt;hlsl&lt;/code&gt;). In vertex shader I calculate &lt;code&gt;UVs&lt;/code&gt; for particle using modulus operator on float. With simple &lt;code&gt;%&lt;/code&gt; there is a problem on Nvidia and on AMD (e.g. &lt;code&gt;7 % 7 = 7&lt;/code&gt;) so I have written modulus as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Mod( float x, float y )    &#xA;{       &#xA;     return x - floor(x / y) * y;    &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This have fixed the problem on Nvidia but AMD still returns wrong values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea what is going on? And how to fixed it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know I can use:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float( int( x ) % int( y ) )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;but I think it is slower and I wonder if there is any better way.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2018-12-15T23:03:40.700" Title="Precision problem on AMD" Tags="&lt;hlsl&gt;&lt;hardware&gt;&lt;float&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7530" PostTypeId="2" ParentId="7526" CreationDate="2018-04-19T14:58:20.250" Score="3" Body="&lt;p&gt;This is kind-of the same as ratchet freak's answer, but fleshed out a little more.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The usual way to handle this is with a special projector light type. It's like a spotlight, but (usually) with a square instead of circular fall-off. That is, when you cast a shadow ray to the light, you don't just measure a single angle (or radius) from the light's axis, you measure $(x, y)$ co-ordinates in the light's space. You divide these co-ordinates by the size of the projection (a parameter of the light just like the cone spotlight's angle parameter), and use the result for a texture look-up in the image you want to project.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If so, wouldn't any light ray bounce on that screen creating a mess?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If you're using a GI system, the high-frequency lighting detail that you get from a projector light will create a more challenging GI environment. You can control the badness by making the albedo of the surface you're projecting onto as small as you can get away with. If you don't need accurate GI results, you can use a proxy in the GI system instead of the real projector map. The proxy could have an aggressively blurred image, or even a normal spot-light whose colour is the average of the whole image. The blur technique is very applicable to a path tracer, while a single colour would be simplest for a radiosity or virtual lights implementation.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-04-19T14:58:20.250" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7531" PostTypeId="2" ParentId="7529" CreationDate="2018-04-19T18:30:58.200" Score="1" Body="&lt;p&gt;In HLSL, you can use the built-in &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/bb509601(v=vs.85).aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;fmod&lt;/code&gt;&lt;/a&gt; function for this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure what's going wrong with your implementation, though. It looks mathematically correct. It's conceivable you're encountering a precision issue with the subtraction, depending on the inputs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, an alternative implementation which avoids the subtraction is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float Mod(float x, float y)&#xA;{&#xA;    return frac(x / y) * y;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-04-19T18:30:58.200" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7533" PostTypeId="1" CreationDate="2018-04-20T11:47:22.317" Score="0" ViewCount="28" Body="&lt;p&gt;I have a parchment animation at singingdays.co.uk that is a rather large file of about 80mb which obviously is taking a long time to download. I have managed to compress it down to about 60mb using convert and decreasing the colourmap for all the images down to 256 colours, but would like to compress it more without losing the quality. If I could somehow only dispose of part of the background, so that I'm only disposing the part of the background where the parchment is unfurling and keep the top part after the rolled up animation and shadow has passed I think that would help, but must admit that it is boggling my head trying to work it out, if you can even do that with convert, let alone figure it out. If you can do it with convert could you work out the command line and pass it on? If not could you recommend something else? I am working on linux. &lt;/p&gt;&#xA;" OwnerUserId="8601" LastActivityDate="2018-04-20T12:45:06.933" Title="compression of gif animation" Tags="&lt;animation&gt;&lt;compression&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7534" PostTypeId="2" ParentId="7533" CreationDate="2018-04-20T12:45:06.933" Score="2" Body="&lt;p&gt;GIF animation compressors normally do this automatically, using transparency in a given frame to avoid storing what has not changed from the previous frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason it's not working in your case is that your input is bad. The flat part of the parchment is not really static. It is moving slowly upwards, at a rate of about 1 pixel every 20 frames. Fix your animation so the non moving parts are perfectly identical between frames and you should get a much smaller file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You would also get a smaller file if you avoided the noise in the unfurling part (most visible in the shadow). Such noise barely compresses at all. This looks like it came out of some 3D software so crank up the quality settings until the input is noise free.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If dithering, which is really added noise, is used when producing the images, make sure it does not change from frame to frame. Or just turn it off entirely. You might get a little banding but the file will be smaller. You'll need to decide which you prefer.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-04-20T12:45:06.933" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7535" PostTypeId="2" ParentId="3645" CreationDate="2018-04-20T15:56:31.030" Score="-2" Body="&lt;p&gt;OpenGL (scanline rendering) is always going to be way faster than ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ray tracing computes pixels one by one using physics (at least a good 90% of the time it's going to be real physics). Although some of it can now be done with a GPU, it is not really helping as much as one would expect. Calculating speculative lightning is not something you can easily do in parallel (ray 1 will bounce from object A to object B, ray 2 will bounce from object A to object C... you can't parallelize the computations on B and C.) The GPU helps with the matrix math, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In comparison, OpenGL is a total fake in comparison. It renders triangles really fast with shades coming from textures and fast gradient computations from your various light sources.&lt;/p&gt;&#xA;" OwnerUserId="8595" LastEditorUserId="8595" LastEditDate="2018-04-20T16:53:12.957" LastActivityDate="2018-04-20T16:53:12.957" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7536" PostTypeId="1" AcceptedAnswerId="7537" CreationDate="2018-04-20T18:27:16.967" Score="3" ViewCount="436" Body="&lt;p&gt;From what I'm reading, it looks like a ray tracer views a pixel as one color and computes that color using the ray starting in the center of that pixel. Yet a pixel has a width and a height.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do we ever use the actual square (now a day pixels are considered squares) that the pixel represents to calculate it true color from all possible source within that entire square?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am thinking that this is how we come up with colors on edges of shapes in scanline rendering and was wondering whether the same could be applied to ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a picture which I hope better represents what I am trying to ask here. Should we only consider the pixels to be single points? Or are we to consider pixels as &lt;em&gt;large&lt;/em&gt; areas?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CV39G.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CV39G.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8595" LastActivityDate="2018-04-21T08:50:52.313" Title="Do we ever consider the size of the pixel to calculate the color in Ray Tracing?" Tags="&lt;raytracing&gt;&lt;pixels&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 3.0" />
  <row Id="7537" PostTypeId="2" ParentId="7536" CreationDate="2018-04-21T08:50:52.313" Score="4" Body="&lt;p&gt;Yes, and there are several ways this can apply. First off though, we need to fix a misconception in your diagram. Even if pixels really were square, the volume contributing to the pixel gets wider as it gets further away from the image plane, because of perspective. For a square pixel, the volume would be a square pyramid, whose apex is at the camera. It's not quite a &lt;em&gt;regular&lt;/em&gt; square pyramid, because the apex is not in the centre of the square: the outer pixels are very skewed. But pixels aren't square anyway, they're cone-shaped.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First off, some people have experimented with &lt;em&gt;cone tracing&lt;/em&gt;, where instead of a single ray, you trace a cone with a half-angle determined from the area of the image covered. It's not very popular, because when the cone intersects the edge of a polygon, you need special handling for the remainder of the cone - the part that wasn't blocked by the polygon. For a square pyramid, it's a little easier, because you can change the shape of the base as parts of the pyramid are blocked, but it's still tricky and slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You also don't gain much from this technique compared to just &lt;em&gt;supersampling&lt;/em&gt;. Even if you trace rays, you don't just trace a single ray through the centre of each pixel. You trace many rays across the area of the pixel, and use a &lt;em&gt;reconstruction filter&lt;/em&gt; to take the shape of the pixel into account. This technique has many possibilities that cone tracing doesn't offer: it works better with volumes, you can jitter your samples to avoid structured artefacts, you can use full path-tracing techniques, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another area where the pixel size matters is in texture sampling. If you want to get nice texturing, you don't just take a point sample of the texture, you set some &lt;em&gt;filter width&lt;/em&gt; according to the area of the texture the sample relates to. This doesn't just make your sampling more efficient by using the right mipmap level: it is required for correct sampling to avoid sampling artefacts. In a GPU fragment shader, you might use the &lt;code&gt;dFdx&lt;/code&gt; and &lt;code&gt;dFdy&lt;/code&gt; functions to do this. In a ray-tracer, you might have use a cone-tracing style of carrying the filter width with the ray, initially based on the level of supersampling at the camera, but updated whenever a child ray is spawned.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-04-21T08:50:52.313" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7538" PostTypeId="1" AcceptedAnswerId="8281" CreationDate="2018-04-21T13:57:37.907" Score="4" ViewCount="335" Body="&lt;p&gt;I'm implementing &lt;a href=&quot;https://drive.google.com/file/d/0BzvWIdpUpRx_d09ndGVjNVJzZjA/view&quot; rel=&quot;noreferrer&quot;&gt;Real-Time Polygonal-Light Shading with Linearly Transformed Cosines&lt;/a&gt; from Siggraph 2016.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm stuck on the texture prefiltering (section &lt;strong&gt;5.3&lt;/strong&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I understand they use &lt;code&gt;Gaussian Blur&lt;/code&gt; on the texture, but clamp and normalize kernel to fragments that intersect the original texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But how do they create the margin? I have tried proper Gaussian with 2D kernel and 2 pass Gaussian but neither seems similar to what is in the paper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also how should weight of Gaussian be chosen? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or maybe I'm totally wrong and it is something more than simple Gaussian?&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2018-11-17T16:38:56.010" Title="Texture prefiltering for Linearly Transformed Cosines" Tags="&lt;texture&gt;&lt;pbr&gt;&lt;filtering&gt;&lt;gaussian-blur&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7539" PostTypeId="1" CreationDate="2018-04-21T19:55:59.817" Score="1" ViewCount="666" Body="&lt;p&gt;Bilinear interpolation can be achieved by interpolating two values across the x axis, and then interpolating between the results across the y axis, like in the image below (from &lt;a href=&quot;https://blog.demofox.org/2015/04/30/bilinear-filtering-bilinear-interpolation/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.demofox.org/2015/04/30/bilinear-filtering-bilinear-interpolation/&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lTXtu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lTXtu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A way to write this mathematically is like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x,y,P_{xy} \in \mathbb{R}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$x,y \in [0,1]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$z = (P_{00}(1-x) + P_{10}x)(1-y) + (P_{01}(1-x)+P_{11}x)y$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing some algebra, you can get it into a polynomial form:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$z = (P_{00}-P_{10}-P_{01}+P_{11})xy + (P_{10}-P_{00})x + (P_{01}-P_{00})y + P_{00}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to find the (geometric?) intuition for this form of bilinear interpolation but the first term doesn't make much sense to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second term makes some sense because it's saying &quot;add in the difference across the x axis, multiplied by how far you are down the x axis&quot;.  The third term is the same, but for the y axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last term is just adding the value at the &quot;starting coordinate&quot; that everything else adds to, so that makes sense as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't figure out how that first term fits in though, or what exactly it's calculating.  it is the only term that deals with the $P_{11}$ so it is obviously doesn't something meaningful, but I can't quite figure out what it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain bilinear interpolation from this point of view?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: $P_{00}$ is (0,0), $P_{01}$ is (0,1), $P_{10}$ is (1,0) and $P_{11}$ is (1,1).&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2018-04-21T21:29:54.220" LastActivityDate="2018-04-21T21:47:55.373" Title="Geometric interpretation of this bilinear interpolation equation?" Tags="&lt;mathematics&gt;&lt;interpolation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7540" PostTypeId="2" ParentId="7539" CreationDate="2018-04-21T20:36:06.580" Score="2" Body="&lt;p&gt;If we look at the two terms with only x or only y they fully describe what happens when you go right or up from the starting point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The xy-terms does not come into play at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you want to go &quot;into the square&quot; or along the upper or the right edge then the xy-term comes into play. It cancels out the x/y-terms and introduce the P11-value that it should obtain in upper-right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;No full explanation here, just nudging along towards insight!&lt;/p&gt;&#xA;" OwnerUserId="286" LastEditorUserId="286" LastEditDate="2018-04-21T21:01:05.637" LastActivityDate="2018-04-21T21:01:05.637" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7541" PostTypeId="2" ParentId="7539" CreationDate="2018-04-21T21:47:55.373" Score="1" Body="&lt;p&gt;An answer was provided to me via twitter by two people independently.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://twitter.com/nothings/status/987797966789341184&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://twitter.com/nothings/status/987797966789341184&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://twitter.com/DarrenMoo/status/987796950274764802&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://twitter.com/DarrenMoo/status/987796950274764802&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The intuition is that without the xy term, that equation describes a plane defined by the 3 points involved (all points except $P_{11}$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The xy term is there to correct it to be a bilinear surface, which is defined additionally by the point $P_{11}$.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2018-04-21T21:47:55.373" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7542" PostTypeId="1" CreationDate="2018-04-22T10:02:51.093" Score="-1" ViewCount="232" Body="&lt;p&gt;I've been thinking about this question for a quite long time.And my implementation seems to be correct for some cases but wrong with few others.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I comprehensive test the algorithm? Is there any provided test cases?&lt;/p&gt;&#xA;" OwnerUserId="7334" LastActivityDate="2018-04-24T03:52:28.990" Title="How to test my triangle intersection implementation?" Tags="&lt;raytracing&gt;&lt;algorithm&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="7546" PostTypeId="2" ParentId="7542" CreationDate="2018-04-24T03:52:28.990" Score="0" Body="&lt;p&gt;The way of detecting intersection is two steps. (I referred to  &lt;a href=&quot;http://www-bcf.usc.edu/~jbarbic/cs420-s18/runuscedu/cs420-s18/16-geometric-queries/16-geometric-queries-6up.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www-bcf.usc.edu/~jbarbic/cs420-s18/runuscedu/cs420-s18/16-geometric-queries/16-geometric-queries-6up.pdf&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Check intersection between the plane that includes the given triangle and given ray.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Let's suppose the start point of the ray $R$ is $(x_0, y_0, z_0)$ and direction is $(x_d, y_d, z_d)$,  then $R = (x_0, y_0, z_0) + (x_d, y_d, z_d)t$ , and the plane is $ax + by + cz + d = 0$. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To check intersection between the ray and plane, calculate the below equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$t = \frac{-(ax_0 + by_0 + cz_0 + d)}{ax_d + by_d + cz+d}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If $t \ge 0$, then there is a possibility of intersection, so go second step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;else there is not intersection.&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Test the point inside triangle. &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Since $t \ge 0 $, we know the point on the plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xikMu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xikMu.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hnece, we can get the $\alpha, \beta, \gamma$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If $0 \le\alpha, \beta, \gamma \le 1$ and $\alpha+ \beta + \gamma = 1$, then there is intersecton.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;else No intersection!.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(The page 19, 20 is explaining how to calculate the 'Area'. (Actually, we can project the 3D space points to 2D space  for performance, but avoid the perpendicular projection!)  )&lt;/p&gt;&#xA;" OwnerUserId="6806" LastActivityDate="2018-04-24T03:52:28.990" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7547" PostTypeId="2" ParentId="7482" CreationDate="2018-04-24T06:37:36.247" Score="0" Body="&lt;p&gt;I fixed it, It was just a coding mistake, there was nothing wrong with the implementation. So the error was in fact in the 2nd for-loop when I was parsing the image buffer. I was reaching for the last pixel in the vector and then popping it off from the back of the stack. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that in the for loop condition, the vector size will be changing but k will still be incrementing the same, so it will effectively only do half of the elements per vector. Because as K is incrementing stack.size() is decrementing so they meet in the middle and the loop is done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this, I just used index notation, so:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;rgbpacket &amp;amp;rgbpixel = stack[index];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and then I deleted the line where I was popping off from the stack.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even though this is a stupid bug,&#xA;I hope this helps other people.&lt;/p&gt;&#xA;" OwnerUserId="8532" LastActivityDate="2018-04-24T06:37:36.247" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7548" PostTypeId="1" AcceptedAnswerId="7560" CreationDate="2018-04-24T09:44:57.420" Score="0" ViewCount="617" Body="&lt;p&gt;I have a CAD model in Solidworks (which can be converted to STL, OBJ, STEP , VRML etc.) that I need to render in an old application, which still uses fixed pipeline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally, I would like to convert my model into a series of &lt;code&gt;glMaterialfv&lt;/code&gt;, &lt;code&gt;glBegin&lt;/code&gt;, &lt;code&gt;glVertex3f&lt;/code&gt;, &lt;code&gt;glEnd&lt;/code&gt; commands that I can compile directly into a C library so that I can avoid loading data from an external file. If this approach will be too painful, however, perhaps someone could alternatively suggest an open-source lightweight fixed pipeline model renderer that I can embed into my code.&lt;/p&gt;&#xA;" OwnerUserId="8621" LastActivityDate="2018-04-27T12:49:30.413" Title="How to convert a 3D model into an OpenGL fixed pipeline representation" Tags="&lt;rendering&gt;&lt;legacy-opengl&gt;" AnswerCount="2" CommentCount="5" FavoriteCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7550" PostTypeId="2" ParentId="7548" CreationDate="2018-04-24T11:01:22.070" Score="1" Body="&lt;p&gt;You can compile it into a &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vertex vertices[] = {{posx, posy, posz, texu, texv, ..}, &#xA;                     {posx, posy, posz, texu, texv, ..}, &#xA;                     //...&#xA;                    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and then loop over them:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBegin(GL_TRIANGLES);&#xA;for (int i = 0; i &amp;lt; arraycount(vertices); i++){&#xA;&#xA;    glTexCoord2f(vertices[i].texu, vertices[i].texv);&#xA;    //... &#xA;    glVertex3f(vertices[i].posx, vertices[i].posy, vertices[i].posz);&#xA;}&#xA;glEnd();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Another solution would be to mimic what the modern vertex buffer based solutions do by creating a VertexAttributeLayout struct and setting it up. Then in the loop you interpret the layout struct and interpret the data as needed.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2018-04-25T11:43:24.877" LastActivityDate="2018-04-25T11:43:24.877" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="7552" PostTypeId="1" CreationDate="2018-04-25T11:00:23.553" Score="1" ViewCount="85" Body="&lt;p&gt;A &lt;code&gt;bounding box&lt;/code&gt;, if I understood correctly is a box that frames the box in which we work. It allows to align the box on the left, on the right, in the center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Its use can be found in LaTeX package like &lt;code&gt;pgf/tikz&lt;/code&gt;, &lt;code&gt;graphicx&lt;/code&gt;, &lt;code&gt;tcolorbox&lt;/code&gt; and certainly in other LaTeX packages as well as in the &lt;code&gt;Adobe Post Script&lt;/code&gt; reference manual.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We do not find this notion, except error of my part in &lt;code&gt;LaTeX2e&lt;/code&gt; written by L. Lamport.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the historical point of view who (or what computer language) introduced this notion?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the concept of &lt;code&gt;bounding box&lt;/code&gt; equivalent in all LaTeX packages? in all languages?&lt;/p&gt;&#xA;" OwnerUserId="8629" LastActivityDate="2018-04-25T11:00:23.553" Title="What is the history of the bounding box concept?" Tags="&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="7554" PostTypeId="1" AcceptedAnswerId="7555" CreationDate="2018-04-26T14:01:54.803" Score="0" ViewCount="144" Body="&lt;p&gt;I've found a site that provides an overview of the OpenGL pipeline: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rendering pipeline overview&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now in the 3th phase (vertex processing) it says that after the transform feedback, there is the primitive clipping. If I am not mistaken, the primitive clipping must occur after that the vertices are multiplied by the projection matrix, otherwise it's impossible to determine if the primitives are inside or outside the view volume defined with &lt;em&gt;glFrustum()&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that in a typical GLSL shader you need to apply the modelview matrix to the vertices, so that you obtain a vertex in eye coordinates. So if I am not mistaken, at the end of the vertex shader you don't have vertices defined in clip coordinates yet. But this makes me think: where is the projection matrix applied? it seems like it's missing in this pipeline overview. &lt;/p&gt;&#xA;" OwnerUserId="8597" LastActivityDate="2018-04-26T14:23:31.700" Title="At which stage of the pipeline is the projection transform applied?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7555" PostTypeId="2" ParentId="7554" CreationDate="2018-04-26T14:23:31.700" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I know that in a typical GLSL shader you need to apply the modelview matrix to the vertices, so that you obtain a vertex in eye coordinates.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is not quite correct, you need to apply the modelview&lt;em&gt;projection&lt;/em&gt; matrix and thus transform your vertices into Clip Space Coordinates. &#xA;You can apply the ModelView Matrix in certain instances, e.g. if you want to calculate light in Eye Space. However, the &lt;code&gt;gl_Position&lt;/code&gt; will then still not use the ModelView but the ModelViewProjection Matrix and your light/whatever- position will use the ModelView Matrix and be transferred to the fragment shader via the &lt;code&gt;out&lt;/code&gt; variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a more detailed discussion, you can look into &lt;a href=&quot;https://stackoverflow.com/questions/49259363/how-to-get-screen-widget-coordinates-from-world-coordinates/49260694#49260694&quot;&gt;the comments on this question&lt;/a&gt;, I had to be corrected about that myself (since not all literature is clear/correct about Normalized Device Space and Clip Space).&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-04-26T14:23:31.700" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7556" PostTypeId="1" CreationDate="2018-04-26T17:27:37.120" Score="2" ViewCount="290" Body="&lt;p&gt;In PBS context what is the metalness map? Are my interpretation of Normal, Roughness and Albedo map correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know almost for sure that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normal map : Models the normals per differential region in our material (kind of).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Roughness map : Together with the normal map allow to define a microfacet distribution in a differential region of our material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Albedo map : This models the percentage of light that is diffusely reflected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normal + Roughness allow to define the amount of energy that is specularly reflected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I struggle to understand the physical meaning of the metalness though, I understand it's related to have a material look like metal of course, but physically speaking I don't get what it models.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2018-04-27T09:34:09.723" Title="What is the physical interpretation of Normal, Roughness, Albedo and Metalness map?" Tags="&lt;rendering&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7557" PostTypeId="1" CreationDate="2018-04-27T08:48:02.000" Score="2" ViewCount="97" Body="&lt;p&gt;Crossposted &lt;a href=&quot;https://forum.openframeworks.cc/t/shader-cannot-move-texture-x-y-location/29395&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://forum.openframeworks.cc/t/shader-cannot-move-texture-x-y-location/29395&lt;/a&gt;&#xA;Hello I am trying to move the x y location of the texture using this code but it doest not work.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Fragment shader&#xA;#version 120&#xA;#extension GL_ARB_texture_rectangle : enable&#xA;#extension GL_EXT_gpu_shader4 : enable&#xA;&#xA;uniform sampler2DRect texture0;&#xA;&#xA;void main(){&#xA;    //Getting coordinates of the current pixel in texture&#xA;    vec2 pos = gl_TexCoord[0].xy;&#xA;&#xA;    // pos.x = (pos.x/0.5); //working&#xA;    pos.x += 0.2 //&amp;lt;-- not working how to fixed this?&#xA;&#xA;    //Getting the pixel color from the texture texture0 in pos&#xA;    vec4 color = texture2DRect(texture0, pos);&#xA;&#xA;    //Changing the color - invert red, green, blue components&#xA;    //color.r = 1.0 - color.r;&#xA;    color.g = 1.0 - color.g; //working..&#xA;    //color.b = 1.0 - color.b;&#xA;&#xA;    //Output the color of shader&#xA;    gl_FragColor = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Vertex shader&#xA;#version 120&#xA;#extension GL_ARB_texture_rectangle : enable&#xA;#extension GL_EXT_gpu_shader4 : enable&#xA;&#xA;void main() {&#xA;    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;&#xA;    gl_TexCoord[0] = gl_MultiTexCoord0;&#xA;    gl_FrontColor = gl_Color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;whats wrong with this code?&#xA;pos.x += 0.2 //not working how to fixed this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;////////////////////////////////////////////////////////////////////////&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found the solution  pos.x += 0.2 already working but it is not visible.&#xA;if I tried bigger number like  pos.x += 100 it is clear that the textures moves.&lt;/p&gt;&#xA;" OwnerUserId="8517" LastEditorUserId="8517" LastEditDate="2018-04-27T10:05:01.397" LastActivityDate="2018-06-27T05:07:35.980" Title="Shader cannot move texture x, y location" Tags="&lt;shader&gt;&lt;fragment-shader&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 3.0" />
  <row Id="7558" PostTypeId="2" ParentId="7557" CreationDate="2018-04-27T09:25:48.270" Score="1" Body="&lt;p&gt;What you do is shifting the texture coordinates. This will move the texture on your polygon, and depending on your settings it will handle the borders which are now probably wrong. however, this will not move your polygon - if you want to move an entire object, you should not do that within the shader. you do that via modifying your model matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume you have a rectangle, and you want to move it by &lt;code&gt;0.2&lt;/code&gt; along the x axis. Then you would edit the correct element of your model matrix for the rectangle. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//depending on your setup, you may need [0][3] rather than [3][0]&#xA;modelMatrix[3][0] += 0.2;&#xA;//now upload the matrix to your shader&#xA;//the entire object will be moved by 0.2 units &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If that is what you wanted, then you need to remove the fragment shader position calculation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a sidenote: I had problems with using &lt;code&gt;+=&lt;/code&gt; in a shader the other day, so it might just be that this doesn't compile. Try using &lt;code&gt;position = position + 0.2;&lt;/code&gt; instead.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-04-27T09:25:48.270" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7559" PostTypeId="2" ParentId="7556" CreationDate="2018-04-27T09:34:09.723" Score="2" Body="&lt;p&gt;Those parameters have no direct physical equivalent. They were chosen to be intuitive and to range from 0-1. See the Burley's &lt;a href=&quot;https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically-Based Shading at Disney&lt;/a&gt; for the full rationale and derivation of what is now commonly referred to as &quot;PBR&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &quot;metalness&quot; parameter is a simple blend between two models - one dielectric BSDF with a coloured diffuse and white specular, and a metallic BSDF without diffuse and a coloured specular component.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2018-04-27T09:34:09.723" CommentCount="4" ContentLicense="CC BY-SA 3.0" />
  <row Id="7560" PostTypeId="2" ParentId="7548" CreationDate="2018-04-27T12:49:30.413" Score="-2" Body="&lt;p&gt;As pointed out in the comments, the most straightforward way to do this is to loop over an array of vertices, which is supported by both fixed and programmable pipelines in OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The motivation for requesting a fixed pipeline solution in question is simple: that is what the existing code base uses! At the moment, the code base has no means of importing models and the models that do already exist in the code base have been hand coded using a series of fixed pipeline OpenGL function calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All things considered, I believe the best workflow (and answer to this question) would be as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Export the CAD models to Wavefront OBJ format&lt;/li&gt;&#xA;&lt;li&gt;Integrate the fixed-pipeline rendering implementation of this &lt;a href=&quot;http://www.dhpoware.com/demos/glObjViewer.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;open-source OBJ viewer&lt;/a&gt; into the code base.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="8621" LastActivityDate="2018-04-27T12:49:30.413" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7561" PostTypeId="2" ParentId="7557" CreationDate="2018-04-28T00:51:45.160" Score="0" Body="&lt;p&gt;When you use &lt;code&gt;GL_TEXTURE_RECTANGLE&lt;/code&gt; in your source code and &lt;code&gt;texture2DRect()&lt;/code&gt; in your shader, you're telling OpenGL that you want to represent the texture coordinates as 0 to width of texture and 0 to height of texture rather than using normalized (0-1) coordinates in both directions, which you would get with &lt;code&gt;GL_TEXTURE_2D&lt;/code&gt; and &lt;code&gt;texture2D()&lt;/code&gt;. A shift of 0.2 might be hard to notice on a large texture, as it's less than 1 texel. If you want to move it by 20% of the width, you need to pass in the texture width and height to the shader and calculate it (or just pass in what 20% of the width is).&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2018-04-28T04:01:58.617" LastActivityDate="2018-04-28T04:01:58.617" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7564" PostTypeId="2" ParentId="7461" CreationDate="2018-04-29T19:33:40.217" Score="1" Body="&lt;p&gt;The lightmap representation used in Valve's stuff, like any finite-storage representation of the surfaces response to light, is only approximate, and the error in the approximation is higher or lower in different scenarios.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since it doesn't store the light in a direction tangent to the surface (where it would be exactly zero), you don't get an exact zero for this case. However, this isn't that important:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Normal maps generated from height maps will never yield a normal vector exactly perpendicular to the geometry, and tend not to be not that steep anyway.&lt;/li&gt;&#xA;&lt;li&gt;The 3 generated lightmaps are normalized so that their sum is equal to the light for the &quot;straight up&quot; direction. This reduces directional contrast, but also eliminates light from the tangent direction.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="8448" LastActivityDate="2018-04-29T19:33:40.217" CommentCount="0" ContentLicense="CC BY-SA 3.0" />
  <row Id="7565" PostTypeId="1" AcceptedAnswerId="7574" CreationDate="2018-05-01T12:08:34.603" Score="1" ViewCount="290" Body="&lt;p&gt;I have a running particle system which emits particles in a given radius. Now I want to add some gravity to it. The particles and velocities of each particle is saved in a 2D Texture, now I want another 2D Texture, where I can save the gravity, but i'm missing the knowledge to do so.&#xA;What's the actual formula on creating some gravitation or how can it be simulated?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example to save particle's vel, I have&#xA;    &lt;code&gt;uniform sampler2D pv;&lt;/code&gt;&#xA;which is just an image which outputs an image and takes the output as input into the shader. (Kind of transform feedback)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;uniform float spread;&#xA;vec2 vel = ...;&#xA;gl_FragColor = vec4(spread*vel, 0.0, 0.0);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Part of my code)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And now I simply want another &lt;code&gt;uniform sampler2D pg;&lt;/code&gt; which holds gravity and right here, I'm missing the math...&lt;/p&gt;&#xA;" OwnerUserId="8651" LastEditorUserId="8651" LastEditDate="2018-05-01T12:15:45.813" LastActivityDate="2018-05-04T05:21:19.980" Title="Gravitational calculation of a particle via GLSL / WebGL" Tags="&lt;glsl&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 3.0" />
  <row Id="7566" PostTypeId="1" AcceptedAnswerId="7569" CreationDate="2018-05-01T18:56:36.970" Score="3" ViewCount="147" Body="&lt;p&gt;I am trying to implement rough dielectrics on my renderer. I compared the results of my renderer and Mitsuba renderer. However, a thin glass plate which is a cube scaled by (0.4, 0.4, 0.01) magnifies the object in front of it in Mitsuba while it does not magnify in my renderer. Do I miss something or does Mitsuba renderer do something wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;edit: IOR of glass is 1.1 and outside is air.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result of my renderer:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4r0rF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4r0rF.png&quot; alt=&quot;Result of my renderer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result of mitsuba:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/A6vLt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A6vLt.png&quot; alt=&quot;Result of mitsuba&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6698" LastEditorUserId="6698" LastEditDate="2018-05-01T19:08:25.637" LastActivityDate="2018-05-02T05:47:49.847" Title="Can a glass plate act like a lens?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;refraction&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7567" PostTypeId="1" AcceptedAnswerId="7568" CreationDate="2018-05-01T20:05:48.497" Score="2" ViewCount="94" Body="&lt;p&gt;so I am in the process of making my own GPU path tracer based on OpenCL as part of my bachelor thesis. I have already made a CPU and a GPU ray tracer based on OpenGL compute shaders but all I have ray-traced are simple spheres and planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Onto the main question, what do I need to path trace actual models like the teapot/dragon etc. Are there any standard, well known libraries for this purpose? Or do I have to write my own model loader? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Writing my own loader seems all nice but I won't just have to read the data but maintain a proper data structure for all the triangles (K-d tree or octree perhaps) as well and then pass that structured data onto the GPU. If there is a library that can give me the data structure it'd be nice as I'll have to write the code for traversing it on the GPU only as I have already written one to traverse octrees for my GPU raytracer.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-05-02T02:35:24.490" Title="Path Tracer - Model loading Libraries?" Tags="&lt;pathtracing&gt;&lt;geometry&gt;&lt;model&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 3.0" />
  <row Id="7568" PostTypeId="2" ParentId="7567" CreationDate="2018-05-02T02:35:24.490" Score="2" Body="&lt;p&gt;AssImp library may be a good choice for you, assuming you are using C++ ?. It supports a decent number of model formats.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2018-05-02T02:35:24.490" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7569" PostTypeId="2" ParentId="7566" CreationDate="2018-05-02T05:47:49.847" Score="8" Body="&lt;p&gt;The &lt;code&gt;box.obj&lt;/code&gt; file has no vertex normals, and by default Mitsuba will generate smooth normals for OBJ files that don't specify their own normals. This creates the magnification effect: the box with smooth normals forms a convex lens!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By adding this line to the box object in the scene file:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;boolean name=&quot;faceNormals&quot; value=&quot;true&quot;/&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I got results that look equivalent to yours:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/LNG6X.png&quot; alt=&quot;Mitsuba render with face normals&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-05-02T05:47:49.847" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7570" PostTypeId="1" AcceptedAnswerId="7571" CreationDate="2018-05-03T03:56:47.520" Score="1" ViewCount="1947" Body="&lt;p&gt;I'd like to understand how the process of building the &quot;tangent space&quot; matrix for &lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;normal mapping&lt;/a&gt; works. I'm following several tutorials, and other stackexchange questions, but I'm unfamiliar with the math involved, and a lot of resources seem to be telling me &quot;just do this and it'll work&quot;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://learnopengl.com/Advanced-Lighting/Normal-Mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;the LearnOpenGL tutorial&lt;/a&gt;, you should build your tangent space matrix with the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 T = normalize(vec3(model * vec4(aTangent,   0.0)));&#xA;vec3 B = normalize(vec3(model * vec4(aBitangent, 0.0)));&#xA;vec3 N = normalize(vec3(model * vec4(aNormal,    0.0)));&#xA;mat3 TBN = mat3(T, B, N)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first three lines are variations of:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 worldSpaceVec = normalize(vec3(modelMatrix * vec4(modelSpaceVec, 0)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Other implementations I've seen do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 worldSpaceVec = normalize(mat3(modelMatrix) * modelSpaceVec);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(by the way, I'm not sure I visualize why the LearnOpenGL tutorial doesn't use &lt;code&gt;vec4(modelSpaceVec, 1)&lt;/code&gt;; I'm not sure what either value would represent or how it would change the results. I assume this just a property of normals that we always represent them with a &lt;code&gt;w&lt;/code&gt; of 0, but I don't get why it applies to the tangent and bitangent)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But more importantly, I don't understand the &lt;code&gt;modelMatrix * ...&lt;/code&gt; part of the equation. According to &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1506/8660&quot;&gt;this answer&lt;/a&gt;, normals are bivectors, a different type of data which is represented by a row matrix instead of a column matrix (that is, bivectors are $\begin{bmatrix} x &amp;amp; y &amp;amp; z \end{bmatrix}$ where vectors are$\begin{bmatrix} x \\ y \\ z \end{bmatrix}$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If my understanding is correct, then normals are of a different type than regular vectors, just like kilograms and liters are similar but different types; and they need to be treated differently in regard to transformations. So why does the tutorial use:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 worldSpaceVec = normalize(vec3(modelMatrix * vec4(modelSpaceVec, 0)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and not&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 worldSpaceVec = inverse(transpose(modelMatrix)) * modelSpaceVec;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;or even&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 worldSpaceVec = inverse(transpose(mvpMatrix)) * modelSpaceVec;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, should the tangent and bitangent vectors of a vertex be converted from one space to another using the same transformation matrix as the vertex's normal vector, and if so, why?&lt;/p&gt;&#xA;" OwnerUserId="8660" LastActivityDate="2018-05-03T07:02:19.550" Title="How do I build my tangent space matrix?" Tags="&lt;transformations&gt;&lt;matrix&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7571" PostTypeId="2" ParentId="7570" CreationDate="2018-05-03T06:52:28.357" Score="0" Body="&lt;p&gt;In Normal Mapping, you want to go to &quot;Tangent Space&quot;, that is the space where the center of the coordinate system is your Vertex (/Fragment). Just like you go from Model Space to World Space and from World Space to Eye Space, you can go to Tangent Space with a matrix multiplication.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Tangent Space, the vector $n_T=\left(\begin{array}{c}0\\0\\1\end{array}\right)$ is always the Normal - since you read the normal $n_N$ out of the Normal Map in your Fragment Shader, you will obviously not use $n_T$ but $n_N$ for lighting calculations and this choice of $n_N$ rather than $n_T$ brings about the nice effect normal mapping has.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's a bit special is that every vertex has its own Tangent Space, which is why you need the tangent, bitangent$^1$ and (geometry) normal of every vertex to construct your TBN matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So much for theory - since you didn't really ask about that specifically, I assume you understand this (otherwise just edit your question).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;by the way, I'm not sure I visualize why the LearnOpenGL tutorial doesn't use vec4(modelSpaceVec, 1); I'm not sure what either value would represent or how it would change the results. I assume this just a property of normals that we always represent them with a w of 0, but I don't get why it applies to the tangent and bitangent&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Vectors in general are represented with a $0$ in the $w$ coordinate. If you look into a translation matrix, you will notice that the last row is the one that moves points around. For vectors, this is not a wanted behaviour - a vector is the same, no matter where, since it is a direction. So to avoid &quot;translating&quot; a vector, you set the $w$ coordinate to $0$. Since your tangent and bitangent vectors are vectors, the $w$ coordinate is $0$ here as well. &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;But more importantly, I don't understand the modelMatrix * ... part of the equation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Using the the model matrix $M$ at this point is correct in &lt;em&gt;most&lt;/em&gt; cases - but not all of them. The normal matrix $N$ is (as the answer you linked correctly said) the inverse transpose of the model matrix. But, since normals are vectors, you don't need a 4x4 matrix, a 3x3 matrix is just fine. And if you leave out that translation part, and you scale the same amount in all three coordinates, then the transpose of your model matrix is the same as the inverse of your model matrix. Therefore you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$&#xA;N = (M^{-1})^T = (M^T)^T = M&#xA;$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And that is why in most cases (i.e. everytime you use the same scaling in every coordinate) the normal matrix is the same as the model matrix.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;code&gt;vec3 worldSpaceVec = inverse(transpose(modelMatrix)) * modelSpaceVec;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is correct, however&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;code&gt;vec3 worldSpaceVec = inverse(transpose(mvpMatrix)) * modelSpaceVec;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;this is not correct. Once you have transformed your normals into world space, you &lt;em&gt;need to&lt;/em&gt; use the same view and projection matrix as before. Your view matrix brings your viewer into the origin (or rather it moves everything such that your viewer is the origin), inverse transposing this doesn't make sense (and similarly it doesn't make sense for the projection matrix. plus, the order in matrix multiplications is important, which is the next problem... don't do it ;-) )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, since you know that the model matrix &lt;em&gt;may&lt;/em&gt; be the same as the normal matrix, you can (mathematically correctly) just go with the inverse transpose of the model matrix. Obviously this costs quite a lot of performance, especially inverting a matrix is costly. It is therefore more efficient to just go with the model matrix.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In other words, should the tangent and bitangent vectors of a vertex be converted from one space to another using the same transformation matrix as the vertex's normal vector, and if so, why?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Unlike normals, tangent and bitangent vectors should be transformed with the model matrix, independently of the whether the normal matrix equals the modal matrix. A normal is always supposed to be perpendicular to a surface, and that's why simply taking the model matrix may be incorrect - in some cases the normal matrix would not be perpendicular to the surface anymore. Tangents however are always &quot;lying&quot; on the surface, so if you rotate a surface, the tangent must be rotated the same way to still &quot;lie&quot; on the surface.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;$^1$ Sometimes this is called &lt;em&gt;binormal&lt;/em&gt;, however Eric Lengyel explains why this is an incorrect term in &lt;a href=&quot;http://www.mathfor3dgameprogramming.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mathematics for 3D Game Programming and Computer Graphics&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="8660" LastEditDate="2018-05-03T07:02:19.550" LastActivityDate="2018-05-03T07:02:19.550" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7572" PostTypeId="1" AcceptedAnswerId="7579" CreationDate="2018-05-03T23:48:12.623" Score="3" ViewCount="161" Body="&lt;p&gt;I'm wondering whether some of you would have tested and seen quite a difference in using a compressed texture even when the OpenGL environment does not need saving any memory (i.e. the card has more memory than necessary to support the textures uncompressed.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm thinking that a compressed texture would use less RAM and thus reading it and decompressing in the GPU would be faster because the number of memory accesses is lower. Whereas, a non-compressed texture would rely more on memory access (GPU I/O) than processing and that is likely slower.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main things I've read about texture compression has been about how the compression saves space. Not so much about how it can save execution time with the GPU. (Note that I specifically will be using an nVidia, Pascal for now. But I would hope that it works similarly whatever the GPU.)&lt;/p&gt;&#xA;" OwnerUserId="8595" LastActivityDate="2018-05-04T16:16:49.260" Title="If I have more than enough memory, can it still be beneficial to use compressed textures?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;gpu&gt;&lt;opengl-es&gt;&lt;compression&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7574" PostTypeId="2" ParentId="7565" CreationDate="2018-05-04T05:21:19.980" Score="0" Body="&lt;p&gt;Gravity is a form of acceleration. So what I've done in the past is continually add it into the velocity. On each frame, for each particle, I'd do something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Gravitational acceleration, adjust as necessary&#xA;const vec2 gravity = vec2(0.0, -9.8);&#xA;&#xA;// Calculate the new velocity for the particle &#xA;velocity = (particleVelocity + gravity) * timeDelta;&#xA;&#xA;// Calculate the new position given the new velocity&#xA;newParticlePosition = particlePosition + velocity;&#xA;&#xA;// Update our parameters for the next time around&#xA;particleVelocity = velocity / timeDelta;&#xA;particlePosition = newParticlePosition;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In this case &lt;code&gt;timeDelta&lt;/code&gt; is the fraction of a second between the previous frame and the current frame. So if you're running your animation at 60 fps, it would be 1.0 / 60.0 = 0.01666…&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure that using a texture for the gravity would help you here as gravity is usually a constant when you're close to the surface of the planet, as it sounds like your particles are from the description given.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-05-04T05:21:19.980" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="7575" PostTypeId="1" AcceptedAnswerId="7576" CreationDate="2018-05-04T07:41:48.027" Score="1" ViewCount="70" Body="&lt;p&gt;Is there a technique for implementing non-point lights (i.e. light that has actual physical dimensions)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't think of anything except than making a light source out of multiple point lights, but that doesn't seem feasible for real-time rendering.&lt;/p&gt;&#xA;" OwnerUserId="8607" LastActivityDate="2018-05-04T08:07:02.187" Title="Non-point lights" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7576" PostTypeId="2" ParentId="7575" CreationDate="2018-05-04T08:07:02.187" Score="2" Body="&lt;p&gt;Yes, there are other physically based lighting concepts. You can have a look at image based lighting and Area Lights (such as Sphere or Tube lights). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have access, have look into &lt;a href=&quot;http://www.pbrt.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically Based Rendering&lt;/a&gt;, if i recall correctly, that has a chapter or two about non-point lights.&#xA;Free on the internet is for example &lt;a href=&quot;https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real Shading in Unreal Engine 4&lt;/a&gt;. Furthermore, there is the &lt;a href=&quot;https://graphics.pixar.com/library/PhysicallyBasedLighting/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically Based Lighting at Pixar&lt;/a&gt; paper, although I am not sure how real-time suitable this is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This should give you a starting point into the topic. You should read up on it and then perhaps come back, if you have more detailed questions.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-05-04T08:07:02.187" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7577" PostTypeId="1" CreationDate="2018-05-04T09:19:52.833" Score="0" ViewCount="120" Body="&lt;p&gt;I am given an irregular geometry shape with its vertices, bounding box information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to draw a smooth mesh equal distance from that irregular geometry shape's bounding box? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please refer to the image here:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SraGv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SraGv.png&quot; alt=&quot;Smooth mesh equal distance from irregular shape&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My attempt:&#xA;1) I have tried to create 8 spheres at 8 corners of a bounding box and a box for X, Y, Z direction. The result looks very ugly and not smooth like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YFkz9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YFkz9.png&quot; alt=&quot;My attempt&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any algorithm or formula I can utilise to draw mesh around a bounding box?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you&lt;/p&gt;&#xA;" OwnerUserId="8547" LastActivityDate="2018-10-13T10:53:22.290" Title="how to draw mesh equal distance from irregular shape geometry bounding box" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7578" PostTypeId="1" AcceptedAnswerId="7988" CreationDate="2018-05-04T11:06:36.973" Score="4" ViewCount="859" Body="&lt;p&gt;I don't understand how to normalize the BRDF.&#xA;the constraint is that for each incoming ray, the exitant ray will be $1$ at most&#xA;ie integral of hemisphere of $f_r\cdot\cos(\theta)$ where $f_r$ is the BRDF and $\theta$&#xA;is the elevation angle.&#xA;the integral over hemisphere is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$0 &amp;lt; \phi &amp;lt; 2\pi$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$0 &amp;lt; \theta &amp;lt; \frac{\pi}{2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for lambertian the brdf is uniform i.e $f_r$ = constant&#xA;the integral is summed to $2\pi$ so the constant should be $2\pi$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this is not the case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;someone knows why?&#xA;I saw answer here:&#xA;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4322/why-normalise-lambertian-brdf-by-1-pi&quot;&gt;Why normalise Lambertian BRDF by 1/pi?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but I didn't understand it, why is it matter what the incoming ray is?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;let's assume the incoming ray comes in $\theta=0$ so the value is $1$ and the sum over the hemisphere is again $2\pi$ instead of $\pi$.&lt;/p&gt;&#xA;" OwnerUserId="8672" LastEditorUserId="7008" LastEditDate="2018-05-04T12:02:52.727" LastActivityDate="2018-08-29T13:02:16.037" Title="BRDF normalization" Tags="&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7579" PostTypeId="2" ParentId="7572" CreationDate="2018-05-04T13:57:42.957" Score="4" Body="&lt;p&gt;Because memory bandwidth is not free.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;No matter how much RAM you have, it takes less time to read 1024 bytes than it does to read 1024 KB. Compressed textures, relative to 32-bpp, can offer compression ratios of 4:1 or better. That's at least one quarter of the memory bandwidth costs of fetching the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your rendering uses lots of textures, reducing bandwidth pressure can improve performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, the more memory you have available, the more memory you can &lt;em&gt;use&lt;/em&gt;. If you consider 1GB to be &quot;plenty of memory&quot;, then using compressed textures allows you to store the equivalent of maybe 2-3GB worth of textures. So now your textures can be larger, more detailed, or more varied, all within the same &quot;plenty of memory&quot; space. Or you can use some of that reclaimed storage for more meshes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's &lt;em&gt;never&lt;/em&gt; enough memory; there's only a question of how much you're willing/able to use.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2018-05-04T16:16:49.260" LastActivityDate="2018-05-04T16:16:49.260" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7581" PostTypeId="2" ParentId="4668" CreationDate="2018-05-04T23:42:54.507" Score="1" Body="&lt;p&gt;Both the question and its answer is confusing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all the matrix you have &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LV0gi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LV0gi.png&quot; alt=&quot;The Look-At Matrix&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is a column &quot;Look at&quot; view matrix rather than a model matrix. A correct column &quot;Look At&quot; model matrix would be &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\begin{bmatrix}&#xA;side_x&amp;amp;side_y&amp;amp;side_z&amp;amp;0\\&#xA;up_x&amp;amp;up_y&amp;amp;up_z&amp;amp;0\\&#xA;Forward_x&amp;amp;Forward_y&amp;amp;Forward_z&amp;amp;0\\&#xA;eye_x&amp;amp;eye_y&amp;amp;eye_z&amp;amp;1&#xA;\end{bmatrix}^T$$, which is what the other answer is saying. This means that matrix in the book is the inverse of the matrix given by me and the other answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First matrix will be used to transform the objects in the world space to the view space of the camera. Second matrix will be used to transform the camera from its local space to the world space such that camera is pointing at whatever the &quot;target&quot; vector is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is nothing special about the second matrix, you can use it on a dog to point to food, provided its mouth is along the +z direction in its local space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in summary, first matrix is a view matrix is used transform objects from world space to view and the second matrix is a regular model matrix which can be applied to any object in the scene to transform it from its local space to the &#xA;world space with &quot;eye&quot; as its world position and +z direction looking at &quot;target&quot;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is nothing wrong with either matrices just that they are used for accomplishing total different tasking.&lt;/p&gt;&#xA;" OwnerUserId="8677" LastEditorUserId="8677" LastEditDate="2018-05-04T23:48:44.257" LastActivityDate="2018-05-04T23:48:44.257" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7582" PostTypeId="2" ParentId="4211" CreationDate="2018-05-05T02:55:04.490" Score="0" Body="&lt;p&gt;As @Quinchilion mentioned, the calculation is done using three weights applied to the color components:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;luminance = color.r * r_weight + color.g * g_weight + color.b * b_weight;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There are many coefficients that can be found on the internet, there are two sample in an old OpenGL note:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.opengl.org/archives/resources/code/samples/advanced/advanced97/notes/node140.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.opengl.org/archives/resources/code/samples/advanced/advanced97/notes/node140.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The weights that @Quinchilion presents in his answer are used in the &lt;a href=&quot;https://en.wikipedia.org/wiki/YCbCr&quot; rel=&quot;nofollow noreferrer&quot;&gt;Analog YPbPr&lt;/a&gt; (0.299, 0.587, 0.114) standard. It's also called BT 601 luma (a.k.a. &quot;luminance&quot;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ones proposed by SGI (link above) are (0.3086, 0.6094, 0.0820). These probably better apply to a nice CRT color monitor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As shown in the link proposed by @Quinchilion and mentioned by @troy_s, the BT 709 uses (0.2126, 0.7152, 0.0722). This is what modern HDTV and monitors use. This is a video thing that happens in your video board or your monitor (it depends the type of connector you're using.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Older HDTV monitors use (0.212, 0.701, 0.087). I'm not too sure how you can know which one you have, though. They say 1035i is the cutoff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the analog video Y component calculation should definitely not be used if you're working on images being displayed on a modern 1080p or better monitor. The BT 709 is certainly the best choice today. If you work on a software that various people will use, having a preference screen where the end user can choose would be best (unless you want to be able to compare what they see and what you see software wise, then stick to one specific set of weights.)&lt;/p&gt;&#xA;" OwnerUserId="8595" LastEditorUserId="8595" LastEditDate="2018-05-05T03:54:21.360" LastActivityDate="2018-05-05T03:54:21.360" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7584" PostTypeId="1" CreationDate="2018-05-05T04:35:41.063" Score="1" ViewCount="135" Body="&lt;p&gt;I'm working on a universal shader, and have a function for calculating reflections and a function for textures. When I run the shader, it seems to give up and discard all fragments. The texture and reflection work fine when run independently, however, when I try to calculate both the texture and the reflection at the same time, it gives up. Even if I leave the result of the reflection alone and don't do anything with it, the fragment gets discarded.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;in vec3 FragPos;&#xA;in vec3 Normal;&#xA;in vec2 TexCoords;&#xA;&#xA;uniform vec3 ViewPos;&#xA;&#xA;uniform sampler2D texture_diffuse1;&#xA;uniform samplerCube skybox;&#xA;&#xA;vec3 CalcReflection(vec3 normal, vec3 frag, vec3 view, float shine);&#xA;&#xA;void main() {&#xA;    // properties&#xA;    vec3 norm = normalize(Normal);&#xA;&#xA;    //Both of these statements work as long as the other isn't called&#xA;    vec4 texColor = vec4(texture(texture_diffuse1, TexCoords).rgb, 1.0); &#xA;&#xA;    vec4 reflection = vec4(CalcReflection(norm, FragPos, ViewPos, mat.shininess), 1.0);&#xA;&#xA;&#xA;    FragColor = texColor; //I'm not doing anything with reflection, yet it still discards the fragment&#xA;}&#xA;&#xA;vec3 CalcReflection(vec3 normal, vec3 frag, vec3 view) {&#xA;    vec3 I = normalize(frag - view);&#xA;    vec3 R = reflect(I, normal);&#xA;    return vec3(texture(skybox, R).rgb);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm not too worried about blending the texture and reflection yet, but to start on that I need to know why this doesn't work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The answer is probably obvious, but I've been stuck on this for a while and need a fresh perspective&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: Added more things from my actual code (skybox definition, alpha values)&lt;/p&gt;&#xA;" OwnerUserId="8437" LastEditorUserId="8437" LastEditDate="2018-05-05T16:50:54.883" LastActivityDate="2018-05-05T16:50:54.883" Title="GLSL can't calculate texture and reflection" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7586" PostTypeId="1" AcceptedAnswerId="7587" CreationDate="2018-05-06T00:19:19.613" Score="1" ViewCount="135" Body="&lt;p&gt;The &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glMapBufferRange.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;docs&lt;/a&gt; for &lt;code&gt;glMapNamedBufferRange&lt;/code&gt; list several optional flags that can be used when a buffer is mapped such as &lt;code&gt;GL_MAP_INVALIDATE_RANGE_BIT&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The docs say:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The following optional flag bits in access may be used to modify the mapping:&#xA;  GL_MAP_INVALIDATE_RANGE_BIT indicates that the previous contents of the specified range may be discarded. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It seems like the right thing to do would be to always specify that flag yet it is optional.  Even if you do not specify &lt;code&gt;GL_MAP_INVALIDATE_RANGE_BIT&lt;/code&gt; or the other, similar flags I do not see how you could retrieve this data or what its value would be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there performance reasons (or other reasons) why you would not want to invalidate the data that is in a buffer that you are writing over?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-05-06T08:36:45.493" LastActivityDate="2018-05-06T08:36:45.493" Title="What are the performance implications of the optional flags used when mapping a buffer?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7587" PostTypeId="2" ParentId="7586" CreationDate="2018-05-06T04:30:12.290" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;It seems like the right thing to do would be to always specify that flag yet it is optional.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You can map buffers for &lt;em&gt;reading&lt;/em&gt;; invalidation is negatively useful for that. Also, you can map a buffer and only overwrite part of it. Invalidation is negatively useful for that too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;glMapBufferRange&lt;/code&gt; has to be able to work outside of the narrow use case of mapping for overwriting an entire range.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Are there performance reasons (or other reasons) why you would not want to invalidate the data that is in a buffer that you are writing over?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Invalidation is a mechanism to allow the implementation to not delay the act of mapping the buffer (due to prior GPU commands that read from it) if you're going to overwrite all of the area in the buffer. The implementation can allocate a chunk of memory, and you can write to that. Then, it'll schedule the DMA from that chunk into the actual buffer storage when you unmap it, handling the synchronization operations as well. For whole buffer invalidation, it can allocate GPU-accessible memory and completely &lt;em&gt;replace&lt;/em&gt; the buffer's storage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, this only matters if you're mapping frequently. If you're using &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object#Persistent_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;persistent mapped buffers&lt;/a&gt; for &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object_Streaming#Persistent_mapped_streaming&quot; rel=&quot;nofollow noreferrer&quot;&gt;streaming&lt;/a&gt; (and you should be, if you're using DSA), then you don't care about invalidation. You're going to handle synchronization manually.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-05-06T04:30:12.290" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7589" PostTypeId="1" CreationDate="2018-05-07T07:40:38.783" Score="1" ViewCount="63" Body="&lt;p&gt;I have a list of vertices, I want to clip these inside the view frustum. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's what I am planning to do :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;First I will loop through my list and check vertex $v$ for $|v.x| \le |v.w|$, $|v.y| \le |v.w|$ and $|v.z| \le |v.w|$. &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;If it fails then I will remove it from the list and add it to a &lt;code&gt;failedVertex&lt;/code&gt; list. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If it passes the test, then I will set up a inner loop to iterate through &lt;code&gt;failedVertex&lt;/code&gt; list. For each vertex in &lt;code&gt;failedVertex&lt;/code&gt;, I will find the intersection of the line between my &quot;passed&quot; vertex and current failed vertex with the view frustum. I will then add the intersection point to my &lt;code&gt;out&lt;/code&gt; list. &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Eg: if $v$ is a passed vertex and $w^i$ is &lt;code&gt;failedVertex[i]&lt;/code&gt;, then I need the intersection between $r = v + \lambda(v - w^i)$ and my view frustum.     &lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;At the end of the inner loop I will add the passed vertex to my &lt;code&gt;out&lt;/code&gt; list.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I have one problem with this approach, how do I find the intersection between my line and the view frustum ? I don't know the equations of the six planes of my view frustum, I don't really want to calculate the equation of the 6 planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not using OpenGL or Direct3D ...&lt;/p&gt;&#xA;" OwnerUserId="8677" LastActivityDate="2018-05-07T07:40:38.783" Title="How to do clipping in 3D?" Tags="&lt;clipping&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7590" PostTypeId="1" CreationDate="2018-05-07T12:32:08.410" Score="5" ViewCount="1143" Body="&lt;p&gt;Ignoring emission and shadowing for simplicity, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Rendering_equation&quot; rel=&quot;noreferrer&quot;&gt;rendering equation&lt;/a&gt; can be stripped down to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L(x, \, \vec \omega) = \int_{\Omega}{f_r(x, \, \vec \omega^\prime, \, \vec \omega) \, (\vec \omega^\prime \cdot \vec n) \, d\vec \omega^\prime}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $f_r$ is the BRDF and $(\vec \omega^\prime \cdot \vec n)$ is the cosine of the angle between light and surface normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the Lambertian diffuse BRDF $\frac{\rho}{\pi}$ this is fine - we're multiplying it with the cosine, seeing Lambert's cosine law in action.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now for the specular part of the Phong BRDF, you would commonly calculate a pixel's color like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$I_{out} = I_{in} \, k_{specular} \, (\vec w \cdot \vec r)^\alpha$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $I_{in}$ is the incident light, $k_{specular}$ is the specular reflectivity of the surface, and $\alpha$ is the Phong exponent. Note the absence of $(\vec \omega^\prime \cdot \vec n)$ in this equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To use the rendering equation and end up with the same pixel value as the common Phong equation above, we'd need to write:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$f^{Phong}_r(x, \, \vec \omega^\prime, \, \vec \omega) = \frac{1}{(\vec \omega^\prime \cdot \vec n)} \, k_{specular} \, (\vec w \cdot \vec r)^\alpha$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note the cosine in the denominator that cancels out the cosine in $L(x, \, \vec \omega)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In his &lt;a href=&quot;http://www.farbrausch.de/~fg/articles/phong.pdf&quot; rel=&quot;noreferrer&quot;&gt;derivation of the Phong normalization factor&lt;/a&gt;, Fabian Giesen states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;[...] this is the derivation for the original Phong formulation, where the $R \cdot V$ term is not multiplied by $cos \theta$. If you write that version of the Phong model as a BRDF, you end up with a $cos \theta$ in the numerator to cancel out the $cos \theta$ factor in the reflection equation. This numerator is complete nonsense physically, so the modern formulation of the Phong model removes it.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I don't understand why he speaks about the numerator here, instead of the denominator. Is this a slip in the article, or a misunderstanding on my part?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the 'modern formulation' of Phong? What does it mean that cancelling out is 'complete nonsense physically'? With the normalization factor, $\frac{\alpha + X}{2 \pi}$ when should you use $X=1$ and when $X=2$?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a path traced side-by-side comparison of a reflective sphere, Phong exponent 100, $X=2$ for the normalization. The left image has the cosine cancelled out, while the right image includes it, noticably darkening the borders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/FcNFnm.png&quot; width=&quot;300&quot; /&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/8IstA.png&quot; width=&quot;300&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="385" LastEditorUserId="385" LastEditDate="2018-05-07T14:14:32.323" LastActivityDate="2018-05-12T13:20:58.187" Title="Phong and the Rendering Equation: What's with the cosine?" Tags="&lt;rendering&gt;&lt;brdf&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7591" PostTypeId="1" CreationDate="2018-05-08T01:04:17.583" Score="1" ViewCount="46" Body="&lt;p&gt;I've read Wikipedia's &lt;a href=&quot;https://en.wikipedia.org/wiki/Order-independent_transparency&quot; rel=&quot;nofollow noreferrer&quot;&gt;article on the topic&lt;/a&gt;, and a &lt;a href=&quot;https://trackdancer.deviantart.com/art/MMD-Understanding-MMD-Draw-Order-494465598&quot; rel=&quot;nofollow noreferrer&quot;&gt;tutorial&lt;/a&gt; on how it affects MikuMikuDance. I tried to read &lt;a href=&quot;https://patents.google.com/patent/US20080316214&quot; rel=&quot;nofollow noreferrer&quot;&gt;a patent&lt;/a&gt; on &quot;packing the 3D array with a prefix sum scan, or linearizing&quot;, but I have no idea what &quot;a prefix sum pass on the generated count buffer to calculate locations in a fragment buffer in which to store all the fragments linearly,&quot; means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wikipedia says exact OIT requires &quot;storing all fragments before sorting and compositing&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would the following be compatible with current technology?&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;find the minimum and maximum Z-depth of each transparent material, or object.&lt;/li&gt;&#xA;&lt;li&gt;order materials that don't collide in Z-depth, and determine which ones do exist at the same Z-depth.&lt;/li&gt;&#xA;&lt;li&gt;blend transparent materials until you reach materials that have the same Z-depth, so draw order is uncertain.&lt;/li&gt;&#xA;&lt;li&gt;store only the fragments for the potentially intersecting materials, whether it's two or more.&lt;/li&gt;&#xA;&lt;li&gt;sort these fragments by depth and blend them.&lt;/li&gt;&#xA;&lt;li&gt;continue on with nearer materials.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Instead of just Z-depth, could maybe also use X and Y coordinates or even an efficiently-created shape of a different orientation, like a box around a pane of glass to the side of another transparent object. These would reduce the number of times steps 4 and 5 would have to be done, but are steps 5 and 6 compatible with current or potential future GPUs?&lt;/p&gt;&#xA;" OwnerUserId="8682" LastActivityDate="2018-05-08T01:04:17.583" Title="Can order-independent transparency sort fragments for a subset of all transparent objects?" Tags="&lt;rendering&gt;&lt;transparency&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7592" PostTypeId="1" AcceptedAnswerId="7596" CreationDate="2018-05-08T01:35:04.797" Score="0" ViewCount="56" Body="&lt;p&gt;My GPU supports OpenGL 4.4 but looking at the OpenGL extensions viewer the only part of 4.5 that it does not support is the GLSL version.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am able to use all DSA functions without specifying any sort of Extension Prefix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, I have been able to run code that uses DSA on GPUs that only support OpenGL 4.2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is this possible?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought that, if my GPU does not support a version of OpenGL I have to use extension prefixes to use those features.&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2018-05-08T16:46:47.147" Title="How can DSA functions be used without extension names on lower versions of OpenGL?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7593" PostTypeId="2" ParentId="7592" CreationDate="2018-05-08T05:34:35.757" Score="1" Body="&lt;p&gt;Your GPU does support OpenGL 4.5, basically. Mine shows exactly the same result, all features supported except the GLSL version. This seems to be fairly common, I'm not sure what the delay is in updating the shader language support, or what GLSL 4.5 brings to the table. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to say a GPU fully supports a GL version, it has to support all the features specified by the ARB for that version number, which is why your driver and mine show up as only supporting 4.4 despite having the full 4.5 feature set on the CPU side. In practice, vendors can add part of a feature level to their driver without fully supporting the version number. It's all pretty messy, which is why we need things like GL3W or GLAD in the first place.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-05-08T05:34:35.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7594" PostTypeId="1" AcceptedAnswerId="7595" CreationDate="2018-05-08T12:23:17.120" Score="3" ViewCount="1448" Body="&lt;p&gt;I am new to optimizing shader code. Now that I have written an &quot;optimzation&quot;, I want to make sure that it really speeds things up and is not just an unreadable version of what I intend to do. For this, I wanted to look into the assembly version of my shader, but I couldn't really find out how to do that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use CodeXL and APITrace, but the former doesn't have any Assembly view as far as I could see and the latter didn't work for my program for some reason. Most other debugging tools don't work (properly) because I program using OpenSceneGraph, meaning there is some Legacy OpenGL Code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore my question: How would I get to seeing assembly code of my shaders?&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-05-08T15:52:48.687" Title="How to get assembly code from GLSL Shader" Tags="&lt;glsl&gt;&lt;assembly&gt;&lt;optimization&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7595" PostTypeId="2" ParentId="7594" CreationDate="2018-05-08T15:52:48.687" Score="4" Body="&lt;p&gt;In unextended OpenGL that's indeed a little difficult, if possible at all. There is really &lt;strong&gt;no actual notion of &quot;GLSL assembly code&quot;, or not one that's remotely vendor-independent&lt;/strong&gt;, let alone a way to retrieve that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a few extensions that might help you get that information, though, albeit in a not entirely intuitive or even platform-dependent way (but well, you're talking about micro-optimizations, so we're firmly in platform-dependent territory anyway).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all, there's &lt;strong&gt;&lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_get_program_binary.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;GL_ARB_get_program_binary&lt;/a&gt; (core since 4.1), which let's you retrieve a platform-dependent binary&lt;/strong&gt; version of the program (after linking). At least on NVidia hardware (maybe others, too, but I wouldn't know) this binary blob also contains ASCII assembly listings of all the contained shaders in NVidia-extended ARB syntax (continuously refined in the &lt;code&gt;GL_NV_gpu_programX&lt;/code&gt; extensions). Those listings are quite easy to find in the binary when opening it with a normal text editor and the syntax is quite straight forward if you know your way around shaders and general assembly programming principles. As said, other vendors &lt;em&gt;might&lt;/em&gt; offer similar listings inside their binaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there's also external programs that might compile your shader into some &lt;strong&gt;intermediate form, the most platform-independent of those being &lt;a href=&quot;https://www.khronos.org/opengl/wiki/SPIR-V&quot; rel=&quot;nofollow noreferrer&quot;&gt;SPIR-V&lt;/a&gt;&lt;/strong&gt;, for which Khronos-approved external compilers exist. Being an &lt;em&gt;intermediate&lt;/em&gt; language this is somewhat of a &quot;high-level assembly language&quot; with an &quot;assembly-like&quot; structure but with many high-level abstractions that builds a bit of a compromise between the easy interpretability of assembly and the easy programability and platform-independence of a high-level language (think of Java bytecode).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_gl_spirv.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;GL_ARB_spirv&lt;/a&gt; extension (core since 4.6) you can directly use (externally precompiled) SPIR-V programs in OpenGL in place of GLSL shaders. I don't know if there is currently a way to let your &lt;em&gt;driver&lt;/em&gt; compile GLSL into SPIR-V and then retrieve that. Otherwise some external SPIR-V module created from a reference compiler would &lt;strong&gt;&lt;em&gt;not&lt;/em&gt; necessarily be equal to the machine code that your driver's actual GLSL compiler produces&lt;/strong&gt;. It might also be that such an intermediate representation might already be &lt;strong&gt;too high-level&lt;/strong&gt; for analysing micro-optimizations anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All in all, and especially if you just want to use it for debugging/analyzing purposes on a dedicated machine, trying to look for a whatever-natured assembly listing in your driver's binary blob retrieved with &lt;code&gt;glGetProgramBinary&lt;/code&gt; might be the easiest and most &quot;close-to-the metal&quot; way to get some insight into the compiled product. I use it occasionally just out of interest.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But of course no answer to this question would be complete without a warning that you shouldn't make too much out of it either. As on the CPU, generally trusting your compiler is a good default approach and you &lt;strong&gt;shouldn't let micro-optimizations like this guide your practice too much, let alone rely on any of that guidance being remotely portable&lt;/strong&gt; (let alone assume that the assembly listed in the binary is &lt;em&gt;actually&lt;/em&gt; what's uses as machine code). But if you want to know what your driver &lt;em&gt;might&lt;/em&gt; make of it, it can be quite interesting and helpful, especially when deciding between two equally meaningful ways to write some function that might have unexpected differences in the &quot;assembly&quot;.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-05-08T15:52:48.687" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7596" PostTypeId="2" ParentId="7592" CreationDate="2018-05-08T16:46:47.147" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;How is this possible?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Because &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_direct_state_access.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_direct_state_access&lt;/a&gt; is an extension. Note that the function/enumerator names in that extension lack the ARB suffix. There are dozens of ARB extensions that work like that. &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Core_Extension&quot; rel=&quot;nofollow noreferrer&quot;&gt;Suffix-less extensions&lt;/a&gt; were introduced in OpenGL 3.0 for compatibility purposes. You could write code that could work on OpenGL 3.0 &lt;em&gt;or&lt;/em&gt; extensions that expose 3.0 functionality, without having to write different function calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same goes here. You're not using OpenGL 4.5; you're using OpenGL 4.4+some extensions.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-05-08T16:46:47.147" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7597" PostTypeId="1" AcceptedAnswerId="7631" CreationDate="2018-05-08T18:02:05.887" Score="0" ViewCount="419" Body="&lt;p&gt;The typical scenario for using a texture would simply be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Create texture&#xA;glGenTextures(1, &amp;amp;textureID);&#xA;glBindTexture(target, textureID);&#xA;glTexImage2D(target, 0, color_format, width, height, 0,&#xA;    color_format, GL_UNSIGNED_BYTE, data);&#xA;&#xA;glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;&#xA;//load to program&#xA;glActiveTexture(texture_unit);&#xA;glBindTexture(target, textureID);&#xA;//Get the uniform location in the program and attach the texture unit&#xA;GLuint location = /*get_uniform_location*/;&#xA;glUniform1i(location,texture_unit - GL_TEXTURE0);&#xA;&#xA;//Draw&#xA;render();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However image load store are somewhat different. First, they don't use texture units but image units. Second you need to manually set memory barriers yourself to ensure completion of writing stage before reading. Amgon other things.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have read the documentation and attempted to implement things myself but It seems I am doing things wrong. I'd rather just forget about what I have tried and understand properly how this needs to be done step by step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know what a typical, minimum example use of image load stores qould be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So creation of the image, writing to the image, reading from the image.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-05-13T19:24:41.620" LastActivityDate="2018-05-16T04:40:49.207" Title="What is the typical use case for rendering to an image through imageStore?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;image&gt;&lt;memory&gt;&lt;image-load-store&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7598" PostTypeId="1" AcceptedAnswerId="7600" CreationDate="2018-05-09T02:55:03.437" Score="1" ViewCount="944" Body="&lt;p&gt;I understand the theory behind z buffering - that I have to check for each pixel if its depth value is less than the one on z buffer or not, if yes then draw else not - but I don't understand how would I actually get the z value of each pixel ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At first I thought I will use the equation of the plane of the polygon I am drawing, but then I have to call the inverse of viewport transform for every pixel. Isn't this every inefficient ?&lt;/p&gt;&#xA;" OwnerUserId="8677" LastActivityDate="2018-05-09T09:14:10.157" Title="How to implement Z-buffering?" Tags="&lt;z-buffer&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7599" PostTypeId="1" AcceptedAnswerId="7679" CreationDate="2018-05-09T09:11:41.137" Score="3" ViewCount="337" Body="&lt;p&gt;I'm developing a light probe based GI solution and currently dealing with light leaks due to interpolation between probes located on opposite sides of the walls. I want to tackle the problem by incorporating precomputed shadow maps assigned for each probe to determine which ones are occluded and therefore which probes need to be interpolated for the current fragment in the fragment shader. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question is, how would I even store tens of thousands of shadow maps and access them in a fragment shader? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe store them continuously in a huge buffer texture? Hmm, or maybe pack them to a huge texture atlas? That also makes me wonder which method would provide a better cache behavior..&lt;/p&gt;&#xA;" OwnerUserId="8541" LastEditorUserId="8541" LastEditDate="2018-05-09T10:42:19.533" LastActivityDate="2018-06-01T08:17:56.800" Title="How to access several textures from huge amount of textures in a shader?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;glsl&gt;&lt;lighting&gt;" AnswerCount="4" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7600" PostTypeId="2" ParentId="7598" CreationDate="2018-05-09T09:14:10.157" Score="2" Body="&lt;p&gt;The values for each pixel in the Z-buffer are interpolated from the values at the corners of the triangle during rasterization. To make this work, the projection matrix produces depth values that are a function of the reciprocal of the original depth value in camera-space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is, the $Z'$ value in each transformed vertex is of the form $aZ + b$, where $a$ and  $b$ together determine the near and far planes, and the transformed $W'$ value is just the original $Z$. After doing the homogeneous divide by $W'$, the transformed $Z'$ becomes $a + b/Z$. By using the reciprocal of $Z$ in the depth value like this, you can then just interpolate linearly in screen space from the three corners to each pixel to get correct results. Since the last step produces floating point results, and most Z-buffers use unsigned integer values, you'll need to bias, scale and quantize before writing to the  actual buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I seriously recommend Eric Lengyel's book Mathematics for 3D Game Programming for the nitty-gritty details of all this kind of stuff, he also explains perspective-correct interpolation of vertex attributes and all the other math you'll need to know to write a rasterizer. &lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-05-09T09:14:10.157" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7601" PostTypeId="2" ParentId="7599" CreationDate="2018-05-09T11:36:10.280" Score="0" Body="&lt;p&gt;You can invert the shadow maps. Render a cube shadowmap at each probe. Then you can filter out any probes influence that would come from beyond a wall by comparing where the new point is in relation to the shadow map's depth in that direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then if the point is beyond the wall you set the interpolation weight for that probe to 0.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-05-09T11:36:10.280" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7602" PostTypeId="2" ParentId="7599" CreationDate="2018-05-09T13:23:02.783" Score="6" Body="&lt;p&gt;Well, it's unlikely that 10,000 cubemaps could fit into memory at all (at 128x128x4-bytes-per-pixel, 10,000 cubemaps would require upwards of 4GB of RAM). But as far as the mechanism to use a large number of such textures, that's pretty easy. You have two options.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The option that's widely available is to use &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Cubemap_Array_Texture&quot; rel=&quot;noreferrer&quot;&gt;cubemap array textures&lt;/a&gt;. You allocate the storage for the array cubemap with the number of cubemaps you want * 6. Each set of 6 array layer-faces is a single cubemap. In your shader, you just provide an array index for the cubemap layer (not layer-face) that you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other option is to employ &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Bindless_Texture&quot; rel=&quot;noreferrer&quot;&gt;bindless textures&lt;/a&gt;. You create however many cubemaps you want, then provide them to the shader as an SSBO array of 64-bit integer handles. You index this array as needed and convert the handle into a sampler value before fetching.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-05-09T13:23:02.783" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7603" PostTypeId="1" AcceptedAnswerId="7604" CreationDate="2018-05-09T15:25:20.160" Score="2" ViewCount="1961" Body="&lt;p&gt;I am trying to do skeletal animation using Assimp and the inverse bind pose matrix just trips me up. I will give a little example to illustrate my point.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Root&#xA;    Bone A&#xA;        Bone B&#xA;            Bone C&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Let's say we have a hierarchy like above. To get a vertex in root space into C space, I would have to do (CBA) * v. The inverse bind pose, which is supposed to get a vertex from bone space to root space, should be the inverse of this. Therefore, the way to calculate inverse bind matrix should be (CBA)^-1 or (A^-1)(B^-1)(C^-1). The formula then is (A^-1)(B^-1)(C^-1) * v, which makes sense. However, I am not able to reproduce the result of Assimp's mOffsetMatrix (inverse bind matrix caculated by Assimp) with (CBA)^-1. (ABC)^-1, however, surprisingly produces the correct result, albeit a little marginal error here and there which I attribute to floating point error.&lt;/p&gt;&#xA;" OwnerUserId="8699" LastActivityDate="2018-05-09T15:58:58.557" Title="Confusion about how inverse bind pose is actually calculated and used?" Tags="&lt;opengl&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7604" PostTypeId="2" ParentId="7603" CreationDate="2018-05-09T15:58:58.557" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;To get a vertex in root space into C space, I would have to do (CBA) * v.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Well, yes. But that's not actually what you want to do in skeletal animation. &lt;strong&gt;You have it reverse.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's the other way around. You assume you have a point in C space and want to compute its position in root/global space, in order to pump it further through the transformation pipeline, which gets &lt;strong&gt;increasingly more global with each transformation&lt;/strong&gt; until your point ends up in eye-space (and further). That's why A doesn't transform from root space into A space, it transforms from A space into root space. So $ABC$ transforms from C space into root space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now your mesh vertices already are in root space, that's where the inverse bind pose comes into play, which transforms a point &lt;strong&gt;from root space into C space&lt;/strong&gt;. So you basically transform your point from root space to C (or whatever joint) space with the inverse bind matrix that's only dependent on the joint and constant over the whole animation and then from that joint space back into root space with the animation-dependent joint transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So C's transformation matrix for frame $t$, that transforms a vertex from &lt;em&gt;unanimated&lt;/em&gt; root space, which is how your mesh is defined, into &lt;em&gt;animated&lt;/em&gt; (with respect to C's joint angle) root space would be $(A_RB_RC_R)^{-1}A(t)B(t)C(t)$, where $M(t)$ is the &lt;em&gt;local&lt;/em&gt; joint matrix at animation time $t$ and $M_R$ is the &lt;em&gt;local&lt;/em&gt; joint matrix corresponding to the rest pose, the pose in which the mesh is defined, and thus $(A_RB_RC_R)^{-1}$ is C's inverse bind pose.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-05-09T15:58:58.557" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="7605" PostTypeId="1" AcceptedAnswerId="7606" CreationDate="2018-05-09T16:07:44.197" Score="0" ViewCount="73" Body="&lt;p&gt;So with the idea that I want to load in an object with morph targets and for simplicity sake I know it will have between 1-8 position morph targets. Ultimately I want to do&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;renderedPrimitive.POSITION = primitive.POSITION + &#xA;   weights[0] * primitive.targets[0].POSITION +&#xA;   ....&#xA;   weights[N] * primitive.targets[N].POSITION;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But being open to load in any model how do you go about knowing the number of vertex input attributes to allocate. Getting the CPU side dynamically is not an issue, but am I wrong that the ONLY way around this is building your shader with some &lt;code&gt;#define&lt;/code&gt; and compiling during runtime?&lt;/p&gt;&#xA;" OwnerUserId="4820" LastActivityDate="2018-05-09T17:37:54.177" Title="Dynamically allocating morph targets in shaders" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7606" PostTypeId="2" ParentId="7605" CreationDate="2018-05-09T17:37:54.177" Score="1" Body="&lt;p&gt;With modern hardware, morph targets probably should not be VS inputs. They should be SSBOs or the D3D equivalent. The vertex shader should fetch from these arrays of positions and act on them appropriately. You can pass the number of targets as a uniform or something.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-05-09T17:37:54.177" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7607" PostTypeId="1" AcceptedAnswerId="7608" CreationDate="2018-05-09T19:00:41.447" Score="2" ViewCount="782" Body="&lt;p&gt;I have an animated cube with 5 keyframes and when I export it to glTF with blender, in the file I can only see 3 keyframes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ep6Jc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ep6Jc.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But when I viewed the gltf model with viewer all 5 keyframes worked well in the animation. Whats the explanation of this ? &#xA;My blend file if you are interested: &lt;a href=&quot;https://files.fm/u/ujs4w23g&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://files.fm/u/ujs4w23g&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8587" LastEditorUserId="8587" LastEditDate="2018-05-10T05:38:45.670" LastActivityDate="2018-05-10T05:38:45.670" Title="glTF animation keyframe question" Tags="&lt;animation&gt;&lt;gltf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7608" PostTypeId="2" ParentId="7607" CreationDate="2018-05-09T20:44:57.930" Score="3" Body="&lt;p&gt;You're seeing channels and samplers there, not individual keyframes.  In this case, one animation is simultaneously targeting the translation, rotation, and scale channels of the same node, with three separate &quot;samplers&quot; (sets of keyframes per channel).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not shown above, your glTF file has a section called &lt;code&gt;accessors&lt;/code&gt; that tells viewers how to slice out portions of binary data from an associated &lt;code&gt;.bin&lt;/code&gt; file.  The &lt;code&gt;.bin&lt;/code&gt; file contains mostly mesh position/normal/UV data, but also contains the keyframe times and values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in the above snippet, that first channel targets the &lt;code&gt;translation&lt;/code&gt; of node 3 with sampler 0 (the first sampler).  The sampler there asks for &lt;code&gt;LINEAR&lt;/code&gt; interpolation of keyframes from animation times (&lt;code&gt;input: 8&lt;/code&gt;) for translation keyframe values (&lt;code&gt;output: 9&lt;/code&gt;).  In the &lt;code&gt;accessors&lt;/code&gt; section, accessors 8 and 9 (using zero-based indexing) are references to the keyframe times (in 8) and values (in 9).  They are separate because the data type of the output depends on what's being targeted (rotations are vec4 quaternions for example, while translations and scales are vec3, and the input times are just floats).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;accessors&lt;/code&gt; in question (8 and 9 for example) will contain a value &lt;code&gt;&quot;count&quot;&lt;/code&gt; that effectively tells you the number of keyframes.  If you have 5 keyframes for example, accessor 8 should have &lt;code&gt;&quot;count&quot;: 5&lt;/code&gt; keyframe times, and accessor 9 will also have &lt;code&gt;&quot;count&quot;: 5&lt;/code&gt; keyframe values.  The glTF Validator will flag an error if these counts don't match.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastActivityDate="2018-05-09T20:44:57.930" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7611" PostTypeId="1" AcceptedAnswerId="7615" CreationDate="2018-05-10T13:51:06.040" Score="3" ViewCount="1056" Body="&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Möller–Trumbore intersection algorithm&lt;/a&gt; compares the determinant with an epsilon. What is this epsilon and how is its value chosen?&lt;/p&gt;&#xA;" OwnerUserId="8702" LastEditorUserId="8820" LastEditDate="2018-06-03T19:22:05.567" LastActivityDate="2018-06-03T19:22:05.567" Title="What is the use of epsilon in the Möller–Trumbore intersection algorithm?" Tags="&lt;raytracing&gt;&lt;algorithm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7612" PostTypeId="1" CreationDate="2018-05-11T01:25:29.377" Score="1" ViewCount="522" Body="&lt;p&gt;Let's say I have the following hierarchy:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Bone A&#xA;    Bone B&#xA;        Bone C&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here's how most tutorial is telling me how to calculate the finalMatrix to be sent to shader.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bonePoseToWorldPose(Joint * joint, glm::mat4 &amp;amp; parentTransform, glm::mat4 &amp;amp; globalInverseTransform) {&#xA;    joint-&amp;gt;finalTransform = parentTransform * joint-&amp;gt;localTransform; // local transform is the result of interpolating 2 keyframes&#xA;    for (int i = 0; i &amp;lt; joint-&amp;gt;children.size(); i++) {&#xA;        bonePoseToWorldPose(joint-&amp;gt;children[i], joint-&amp;gt;finalTransform, globalInverseTransform);&#xA;    }&#xA;    joint-&amp;gt;finalTransform = joint-&amp;gt;finalTransform * joint-&amp;gt;inverseBindTransform;  &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Doing it this way, the final transform in bone C for example, would be localTransformA * localTransformB * localTransformC * jointInverseBindTransform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which does not make sense to me, and none of the tutorial satisfactorily explains that. Let's go back to the example again. the inverse bind transform would bring a vertex V from mesh space to bone space of Bone C. At bone space C, it would be multiplied with the localTransformC (or interpolated transform C), which I guess would set the model to our desired pose. But what are A and B doing there? &lt;/p&gt;&#xA;" OwnerUserId="8699" LastActivityDate="2018-05-11T04:26:48.890" Title="Skeletal animation: What is the purpose of multiplying interpolated bone matrix with parent's matrix?" Tags="&lt;opengl&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7613" PostTypeId="2" ParentId="7612" CreationDate="2018-05-11T04:26:48.890" Score="3" Body="&lt;p&gt;The bone transforms are relative to their parent in the hierarchy. That's the point of the hierarchy, i.e. when you move your arm, your hand and fingers go along with it. So when an animation (or whatever) changes the transform of A, then bones B and C are supposed to move along with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is accomplished by defining bone B relative to A, and C relative to B, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, to get the final transform from bone local space to world space, you have to combine all the transforms from the current bone up the hierarchy to the root.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To put it another way:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The &lt;code&gt;localTransform&lt;/code&gt; of C takes you to B's local space.&lt;/li&gt;&#xA;&lt;li&gt;Then the &lt;code&gt;localTransform&lt;/code&gt; of B takes you to A's local space.&lt;/li&gt;&#xA;&lt;li&gt;Then the &lt;code&gt;localTransform&lt;/code&gt; of A takes you to world space (since A is the root).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-05-11T04:26:48.890" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7615" PostTypeId="2" ParentId="7611" CreationDate="2018-05-11T07:29:11.860" Score="2" Body="&lt;p&gt;The epsilon is there to counter &lt;a href=&quot;https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems&quot; rel=&quot;nofollow noreferrer&quot;&gt;floating-point accuracy problems&lt;/a&gt;.  Note that the code checks that the algorithm is between $-\epsilon$ and $\epsilon$; that is, close to zero.  If the determinant is zero, then the ray lies in the plane of the triangle and can be safely said to not intersect it (as the alternative, an edge-on intersection, should be caught by neighbouring triangles in the mesh).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Cramer's rule computation of the intersection point then &lt;em&gt;divides&lt;/em&gt; by the determinant, and here's where the floating-point accuracy comes in.  If the determinant is merely very close to zero, not exactly equal to it, then its reciprocal will be very large.  We multiply the other determinants by this reciprocal, so small floating-point errors in their values will be blown up into significance and make the difference between an intersection and a non-intersection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't tested it, but I suspect that leaving out the epsilon will cause intersections on the silhouette of a mesh (i.e. with triangles close to parallel with the ray direction) to become very nondeterministic.  This would result in nearby rays either missing or hitting the triangles unpredictably and giving you speckling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The value of the epsilon depends on the floating-point precision you're using. It should be small enough that only very grazing intersections are culled, but large enough that it avoids the speckling problem.  It can be determined by experiment, or by just eyeballing it.  The implementation you linked to uses $\epsilon = 10^{-7}$, which is a reasonable choice for single-precision arithmetic; you may want to use $10^{-9}$ or $10^{-10}$ for double-precision computations.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2018-05-11T07:29:11.860" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7616" PostTypeId="1" CreationDate="2018-05-11T09:22:19.260" Score="2" ViewCount="237" Body="&lt;p&gt;I display text using OpenGL which is aligned with (2D) objects that can have any rotation on display, making the text also appear at any angle on display. So far I've used FreeType to render raster for each supported symbol to file and load the files into OpenGL as textures at application start.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the text is rotated (other than 90 degree increments) the hinting goes all bad. My plan so far to remedy the situation is to render a few rotated (transformed) variants of each symbol and linearly interpolate between the two closest variants. As an example I may render variants in 15 degree increments between 0-75 degrees inclusive, and if text is rotated by 5 degrees on display I'd take 1/3 from the 0 degree raster and 2/3 from the 15 degree raster.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;...but this is only a theory of mine. Should work if having small enough increments, but if there are too many of them I'll run out of memory resources and making the shader awfully inefficient. I imagine the increment count depends on the pixel size of each symbol which could turn problematic...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I reach out to the expert community: How to render rotated text with proper font hinting in real-time?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using OpenGL ES 2.0. Font size ~16pix. If you need more info ask away.&lt;/p&gt;&#xA;" OwnerUserId="3041" LastEditorUserId="2654" LastEditDate="2018-05-11T13:23:09.003" LastActivityDate="2018-05-11T13:23:09.003" Title="How to rendered arbitrary rotated text with decent hinting in real time?" Tags="&lt;opengl-es&gt;&lt;font-rendering&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7617" PostTypeId="1" AcceptedAnswerId="7618" CreationDate="2018-05-11T09:46:13.190" Score="0" ViewCount="597" Body="&lt;p&gt;Consider a situation where there are 3 different buffers describing a particular mesh piece: &lt;code&gt;vBuffer&lt;/code&gt;, &lt;code&gt;nBuffer&lt;/code&gt;, &lt;code&gt;iBuffer&lt;/code&gt; (vertices, normals, and indices) which equate to &lt;code&gt;totalBufferSize&lt;/code&gt; in aggregate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to save these 3 buffers to the same default heap (D3D12_HEAP_TYPE_DEFAULT).  I know I still need to use an upload heap (D3D12_HEAP_TYPE_UPLOAD) as an intermediary but I can't figure out how to eliminate extra copies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently my code (which works) does the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    const D3D12_HEAP_PROPERTIES defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);&#xA;    const D3D12_HEAP_PROPERTIES uploadHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD);&#xA;&#xA;...&#xA;&#xA;    const CD3DX12_RESOURCE_DESC resourceDescV = CD3DX12_RESOURCE_DESC::Buffer(totalBufferSize);&#xA;    DX::ThrowIfFailed(device-&amp;gt;CreateCommittedResource(&#xA;        &amp;amp;defaultHeapProperties,&#xA;        D3D12_HEAP_FLAG_NONE,&#xA;        &amp;amp;resourceDescV,&#xA;        D3D12_RESOURCE_STATE_COPY_DEST,&#xA;        nullptr,&#xA;        IID_PPV_ARGS(meshPart.m_mainBuffer.ReleaseAndGetAddressOf())));&#xA;&#xA;    DX::ThrowIfFailed(device-&amp;gt;CreateCommittedResource(&#xA;        &amp;amp;uploadHeapProperties,&#xA;        D3D12_HEAP_FLAG_NONE,&#xA;        &amp;amp;resourceDescV,&#xA;        D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;        nullptr,&#xA;        IID_PPV_ARGS(meshPart.m_uploadBuffer.ReleaseAndGetAddressOf())));&#xA;&#xA;    uint8_t * bufferStart{};&#xA;    const CD3DX12_RANGE readRange(0, 0);&#xA;    DX::ThrowIfFailed(meshPart.m_uploadBuffer-&amp;gt;Map(0, &amp;amp;readRange, reinterpret_cast&amp;lt;void **&amp;gt;(&amp;amp;bufferStart)));&#xA;&#xA;    // Can these be eliminated?&#xA;    uint32_t offset{};&#xA;    std::memcpy(bufferStart, vBuffer.data, vBuffer.totalSize);&#xA;    offset += vBuffer.totalSize;&#xA;    std::memcpy(bufferStart + offset, nBuffer.data, nBuffer.totalSize);&#xA;    offset += nBuffer.totalSize;&#xA;    std::memcpy(bufferStart + offset, iBuffer.data, iBuffer.totalSize);&#xA;&#xA;    D3D12_SUBRESOURCE_DATA bufferData{};&#xA;    bufferData.pData = bufferStart;&#xA;    bufferData.RowPitch = totalBufferSize;&#xA;    bufferData.SlicePitch = totalBufferSize;&#xA;&#xA;    UpdateSubresources&amp;lt;1&amp;gt;(commandList, meshPart.m_mainBuffer.Get(), meshPart.m_uploadBuffer.Get(), 0, 0, 1, &amp;amp;bufferData);&#xA;    CD3DX12_RESOURCE_BARRIER barrier = CD3DX12_RESOURCE_BARRIER::Transition(meshPart.m_mainBuffer.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER);&#xA;    commandList-&amp;gt;ResourceBarrier(1, &amp;amp;barrier);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, I'm trying to figure out if I can eliminate those std::memcpy calls.   All examples of UpdateSubresources I've seen do not explicitly Map+memcpy into the upload buffer.  They just set &lt;code&gt;D3D12_SUBRESOURCE_DATA.pData&lt;/code&gt; directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried calling using &lt;code&gt;UpdateSubresources&amp;lt;3&amp;gt;&lt;/code&gt; and passing in an array of D3D12_SUBRESOURCE_DATA, each pointing to the beginning of my mesh buffers, but the validation layer didn't like that and threw an exception.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to upload all 3 buffers in one step here -- without the explicit Map and memcpy steps?&lt;/p&gt;&#xA;" OwnerUserId="8705" LastActivityDate="2018-05-11T10:53:26.590" Title="DirectX 12: Uploading multiple buffers to 1 default heap using the UpdateSubresources API without explicit copies" Tags="&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7618" PostTypeId="2" ParentId="7617" CreationDate="2018-05-11T10:23:54.413" Score="0" Body="&lt;p&gt;&lt;code&gt;UpdateSubresources&lt;/code&gt; is a helper function. Inside it is another &lt;code&gt;memcpy&lt;/code&gt;. I would recommend simply rewriting it - source is in &lt;a href=&quot;https://code.msdn.microsoft.com/Direct3D-12-UAP-Sample-ecb1779f/sourcecode?fileId=139518&amp;amp;pathId=1775568253&quot; rel=&quot;nofollow noreferrer&quot;&gt;d3dx12.h&lt;/a&gt;. Then you will be able to copy your data no more than necessary.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorUserId="3123" LastEditDate="2018-05-11T10:53:26.590" LastActivityDate="2018-05-11T10:53:26.590" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7623" PostTypeId="1" CreationDate="2018-05-12T02:23:24.893" Score="0" ViewCount="266" Body="&lt;p&gt;Given two cuboids in 3D space (8 vertex coordinates each) that are arbitrarily oriented, how can we find the volume of overlap between them in the fastest manner? &lt;/p&gt;&#xA;" OwnerUserId="8719" LastActivityDate="2018-06-20T14:53:16.893" Title="How to compute volume of intersection of non-axis-aligned cuboids in 3D?" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;volumetric&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7624" PostTypeId="2" ParentId="7590" CreationDate="2018-05-12T13:20:58.187" Score="2" Body="&lt;p&gt;The cosine term in the rendering equation is to account the amount of light reaching the surface, and leaving it out from the rendering equation is what he refers as &quot;complete nonsense&quot;, which is right. The original Phong model didn't have the cosine term in the rendering equation, so if you want to model the original nonsensical Phong with proper rendering equation, you need to hack it by adding the cosine denominator to the Phong BRDF.&lt;/p&gt;&#xA;" OwnerUserId="1952" LastActivityDate="2018-05-12T13:20:58.187" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7627" PostTypeId="1" AcceptedAnswerId="7644" CreationDate="2018-05-13T07:40:35.490" Score="1" ViewCount="1313" Body="&lt;p&gt;I am using the de boors algorithm to generate B splines in python. However I am getting spikes in the final figure. I do not understand why this happens. I am posting my code here for reference &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def knot_values(n,k):&#xA;      t = np.zeros((1,n+k+1))&#xA;      for i in range(0,n+k+1):&#xA;            if i&amp;lt;k:&#xA;               t[0][i] = 0&#xA;            if i&amp;gt;=k and i&amp;lt;=n:&#xA;               t[0][i] = i-k+1&#xA;            if i&amp;gt;n:&#xA;               t[0][i] = n-k+2&#xA;&#xA;      return t&#xA;&#xA;def basis_spline(u,t,i,k):&#xA;    if k==1:&#xA;        if u&amp;gt;=t[0][i] and u&amp;lt;=t[0][i+1]:&#xA;             sol = 1&#xA;        else:&#xA;             sol = 0&#xA;    else:&#xA;        a = (u - t[0][i])*basis_spline(u,t,i,k-1)&#xA;        b = t[0][i+k-1] - t[0][i]&#xA;        c = (t[0][i+k] - u)*basis_spline(u,t,i+1,k-1)&#xA;        d = t[0][i+k] - t[0][i+1]       &#xA;        if b == 0:&#xA;            temp1 = 0&#xA;        else:&#xA;            temp1 = a/b&#xA;&#xA;        if d == 0:&#xA;            temp2 = 0&#xA;        else:&#xA;            temp2 = c/d    &#xA;&#xA;&#xA;        sol = (temp1) + (temp2)&#xA;&#xA;    return sol&#xA;&#xA;def curve_generator(n,k,ctrl_x,ctrl_y):&#xA;&#xA;    t = knot_values(n,k)&#xA;    print(t)&#xA;    u = np.arange(t[0][k-1],t[0][n+1],0.001);&#xA;    length = u.shape;&#xA;&#xA;    x = np.zeros((1,length[0]));&#xA;    y = np.zeros((1,length[0]));&#xA;&#xA;    for i in range(0,n+1):&#xA;        for j in range(0,length[0]): &#xA;            x[0][j] = x[0][j] + basis_spline(u[j],t,i,k)*ctrl_x[i];&#xA;            y[0][j] = y[0][j] + basis_spline(u[j],t,i,k)*ctrl_y[i];&#xA;&#xA;    return x,y &#xA;&#xA;    n = 6&#xA;    k = 3&#xA;    ctrl_x = np.array([0,3,6,9,10,12,15])&#xA;    ctrl_y = np.array([0,4,2,3,7,8,5])&#xA;&#xA;    [x,y] = curve_generator(n,k,ctrl_x,ctrl_y)&#xA;&#xA;    n = x.shape&#xA;    a = [0]*n[1]&#xA;    b = [0]*n[1]&#xA;    for i in range(0,n[1]):&#xA;        a[i] = x[0][i]&#xA;        b[i] = y[0][i]&#xA;&#xA;    plt.plot(a,b)&#xA;    plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5ag7U.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5ag7U.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8723" LastEditorUserId="2041" LastEditDate="2018-05-13T10:02:09.597" LastActivityDate="2018-05-17T13:30:48.573" Title="B spline curve generation in Python" Tags="&lt;bezier-curve&gt;&lt;curve&gt;&lt;nurbs&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7628" PostTypeId="1" CreationDate="2018-05-13T19:13:52.070" Score="5" ViewCount="1121" Body="&lt;p&gt;I'm implementing manual interpolation between texels in a 3D texture to be able to discard some of them when needed. Compared to hardware interpolation, this process takes a lot of time. If I simply leverage hardware interpolation using &lt;code&gt;texture&lt;/code&gt; function, rendering takes ~5ms, but with manual fetch using &lt;code&gt;texelFetch&lt;/code&gt; it rises to ~13ms (using &lt;code&gt;texture&lt;/code&gt; to fetch 8 texels manually increases frame time even further - to ~35ms). The multiplication/summing part of the manual lerp does't matter much - I've tried fetching same texel manually 8 times and the performance is close to hardware interpolation. I thought fetching neighboring texels should give me good cache behavior, but maybe that only applies to 2D textures because neighboring layers of 3D tex are not so cache friendly? Don't know what to think here.. It would be nice if there was some way to use hardware interpolation but discard some texels from the process. The absence of a &lt;code&gt;textureGather&lt;/code&gt; function taking a 3D texture also makes me think I'm missing something here.&lt;/p&gt;&#xA;" OwnerUserId="8541" LastEditorUserId="8541" LastEditDate="2018-05-14T09:34:37.103" LastActivityDate="2018-09-14T00:01:18.653" Title="Manually fetching 8 neighboring texels from 3D texture greatly decreases performance" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;fragment-shader&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7629" PostTypeId="1" AcceptedAnswerId="7630" CreationDate="2018-05-13T21:44:43.470" Score="2" ViewCount="413" Body="&lt;p&gt;I was wondering if anyone could explain how the Painter's algorithm would handle transparent objects? Can the Painter's algorithm handle transparency?&lt;/p&gt;&#xA;" OwnerUserId="8725" LastActivityDate="2019-12-04T09:26:40.030" Title="How does the Painter's Algorithm handle transparency?" Tags="&lt;rendering&gt;&lt;algorithm&gt;&lt;transparency&gt;&lt;pixel-graphics&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7630" PostTypeId="2" ParentId="7629" CreationDate="2018-05-13T23:49:57.573" Score="7" Body="&lt;p&gt;The common way to render transparent polygons in a rasterizer is by use of &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Alpha_compositing&quot; rel=&quot;noreferrer&quot;&gt;Alpha Blending&lt;/a&gt;, which basically combines the colour of the supposedly transparent pixel with the colour of the background at that pixel's position&lt;/strong&gt;, this way rendering the pixel transparently onto what was already rendered before. This technique, however, requires your polygons (or at least the transparent ones) to be sorted from back to front, at least in general non-trivial cases, since you can only combine the transparent colour with what has already been rendered behind it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But since the &lt;strong&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Painter%27s_algorithm&quot; rel=&quot;noreferrer&quot;&gt;Painter's Algorithm&lt;/a&gt; &lt;em&gt;already&lt;/em&gt; requires ploygons to be sorted from back to front&lt;/strong&gt; (which is pretty much the entire essence of the algorithm), this just fits naturally into the rest of the algorithm. Thus, &lt;strong&gt;supporting transparency becomes rather straight forward&lt;/strong&gt; by simply doing any variant of alpha blending of the pixel with the background instead of overwriting the background.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-05-13T23:49:57.573" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7631" PostTypeId="2" ParentId="7597" CreationDate="2018-05-14T11:23:18.967" Score="2" Body="&lt;p&gt;I've used &lt;code&gt;imageStore&lt;/code&gt; as part of compute shaders doing surface extraction. I've only ever used it in compute shaders, to store the calculated data in a texture to be consumed by another shader - I know it's possible to do &lt;code&gt;imageStore&lt;/code&gt; in a fragment shader as well but I haven't come across a use case for it yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also haven't used &lt;code&gt;imageLoad&lt;/code&gt; at all, since apparently &lt;code&gt;texelFetch&lt;/code&gt; is often faster (benefits from using the texture cache), and at worst no slower, so I simply bound the same texture to both an image and a texture unit, and used &lt;code&gt;imageStore&lt;/code&gt; for writes and &lt;code&gt;texelFetch&lt;/code&gt; for reads.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code to get it all working looked something like this (using OpenGL 4.5 and DSA, and assuming &lt;code&gt;cShdr&lt;/code&gt; holds a compute program that does &lt;code&gt;imageStore&lt;/code&gt; on channel 0, &lt;code&gt;cShdr2&lt;/code&gt; is a second compute program that samples the generated texture on channel 0, and &lt;code&gt;rShdr&lt;/code&gt; is a rendering program that samples the texture on channel 0 - of course, if you don't want to hardcode the texture channel in the shader you can use &lt;code&gt;glGetUniformLocation&lt;/code&gt;):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//setting up texture and binding to image unit 0&#xA;GLuint tex;&#xA;glCreateTextures(GL_TEXTURE_2D, 1, &amp;amp;tex);&#xA;glTextureStorage2D(tex, 1, GL_RGBA32F, 256, 256)&#xA;glBindImageTexture(0, tex, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA32F);&#xA;&#xA;//Dispatch a compute shader to imageStore to the texture&#xA;//wait for completion before allowing sampling&#xA;glDispatchCompute(cShdr, numX, numY, numZ);&#xA;glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);&#xA;&#xA;//code that samples the texture in render loop&#xA;glBindVertexArray(vao);&#xA;glBindTextureUnit(0, tex);&#xA;glUseProgram(rShdr);&#xA;glDrawArrays(GL_TRIANGLES, 0, numVerts);&#xA;&#xA;//or if consuming data in second compute shader using texelFetch&#xA;glBindTextureUnit(0, tex); &#xA;glDispatchCompute(cShdr2, numX, numY, numZ); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first 3 parameters to &lt;code&gt;glBindImageTexture&lt;/code&gt; are image unit, texture, and mip level. The next two deal with binding arrays of textures, and should just be set to &lt;code&gt;GL_FALSE, 0&lt;/code&gt; when binding a single texture. The final two are access and format (for stores). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that although I've used the GL 4.5-specific functions for creating textures and binding the texture unit, the &lt;code&gt;glBindImageTexture&lt;/code&gt; works with every version that supports load/store - 4.2 and above.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="1937" LastEditDate="2018-05-16T04:40:49.207" LastActivityDate="2018-05-16T04:40:49.207" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7632" PostTypeId="1" CreationDate="2018-05-14T15:31:52.140" Score="1" ViewCount="104" Body="&lt;p&gt;I think this is one of the most important part when you write a physically-based renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The solution I came up with is to put a sphere to the scene with a constant background radiance. Solve the rendering equation analytically for constant radiance which you have chosen. There will be no recursion in the integral since the rays will not bounce more than one. After that, compare result of the rendered image and the analytic solution. Does this make sense?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any ways to this more effectively?&lt;/p&gt;&#xA;" OwnerUserId="6698" LastActivityDate="2018-05-14T15:31:52.140" Title="How to validate whether a reflection model is implemented correctly?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;physically-based&gt;&lt;global-illumination&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7633" PostTypeId="1" CreationDate="2018-05-14T23:54:35.233" Score="2" ViewCount="172" Body="&lt;p&gt;I am trying to verify that if I have my &lt;code&gt;inNormal&lt;/code&gt; and some &lt;code&gt;N&lt;/code&gt; amount of morph normals that I would want to do something such as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;outNormal = vec3(inNormal);&#xA;outNormal += morphNormal0 * morphWeight0;&#xA;outNormal += morphNormal1 * morphWeight1;&#xA;...&#xA;outNormal += morphNormalN * morphWeightN;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This seems to work for me (don't have a ground truth to compare) so I wanted to test it in Three.js knowing it would have an established method and I see &lt;a href=&quot;https://github.com/mrdoob/three.js/blob/master/src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;they use&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];&#xA;objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];&#xA;objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];&#xA;objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So now I am wondering how that math works out as it doesn't work for me. Both methods end up multiplying it by a &lt;code&gt;normalMatrix&lt;/code&gt;so not sure what would be different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;edit&lt;/strong&gt;: Assuming both are loading in glTF 2.0 models&lt;/p&gt;&#xA;" OwnerUserId="4820" LastEditorUserId="4820" LastEditDate="2018-05-15T19:39:35.710" LastActivityDate="2018-10-17T07:00:33.207" Title="Morph Targets Normal adding math" Tags="&lt;vectors&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7636" PostTypeId="1" AcceptedAnswerId="7639" CreationDate="2018-05-16T06:41:51.810" Score="1" ViewCount="527" Body="&lt;p&gt;I'm trying to figure out the correct math to rotate and translate a curve displayed in a fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I try to accomplish is to define a curve, for example a sine curve, in a local coordinate system, rotate it then translate it. Something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/v5vx0.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v5vx0.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That was made in MATLAB with the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;dens = 1080;&#xA;x = linspace(-1.0, 1.0, dens);        &#xA;y = 0.1*sin(25.0*x);&#xA;&#xA;imax = 25;&#xA;for i = 1:imax    &#xA;&#xA;    %transformation matrix:&#xA;    ang = (i/imax)*0.5*3.14;&#xA;    c = cos(ang); s = sin(ang);          &#xA;    T = [c,-s;s,c];&#xA;&#xA;    %translation:&#xA;    P = [0.5;0.5];&#xA;&#xA;    %transformed coordinates:&#xA;    xt = T(1,:)*[x;y] + P(1);&#xA;    yt = T(2,:)*[x;y] + P(2);&#xA;&#xA;    plot(xt,yt);&#xA;    xlim([0 1.0]); ylim([0 1.0]); drawnow;&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For the GLSL test I'm using the &lt;a href=&quot;http://editor.thebookofshaders.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Book of Shaders Editor&lt;/a&gt; with the following code (can also be seen interactively &lt;a href=&quot;http://thebookofshaders.com/edit.php?log=180516060952&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;): &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#ifdef GL_FRAGMENT_PRECISION_HIGH&#xA;precision highp float;&#xA;#else&#xA;precision mediump float;&#xA;#endif&#xA;&#xA;uniform float u_time;&#xA;uniform vec2 u_resolution;&#xA;&#xA;// Plot a line on Y using a value between 0.0-1.0&#xA;float plot(vec2 st, float pct){&#xA;  return  smoothstep( pct-0.02, pct, st.y) -&#xA;          smoothstep( pct, pct+0.02, st.y);&#xA;}&#xA;&#xA;float plotTransformed(vec2 st, float pct, vec2 transl, float ang){&#xA;&#xA;    float c = cos(ang); float s = sin(ang);    &#xA;    mat2 trans = mat2(c,-s,s,c);    &#xA;    st = trans * st;&#xA;&#xA;    st -= transl;&#xA;&#xA;    return  smoothstep( pct-0.02, pct, st.y) -&#xA;          smoothstep( pct, pct+0.02, st.y);&#xA;}&#xA;&#xA;void main(void) {&#xA;    bool use_plot_function = true;&#xA;&#xA;    float mx =  max(u_resolution.x, u_resolution.y);&#xA;    vec2 uv = gl_FragCoord.xy /mx;&#xA;    vec3 color = vec3(0.4,0.4,0.4);&#xA;&#xA;    //some screen position:&#xA;    vec2 p = vec2(0.5, 0.5);&#xA;&#xA;    //the curve:&#xA;    vec2 cp = vec2(&#xA;        uv.x,&#xA;        0.08*sin(uv.x*40.0)&#xA;    );&#xA;&#xA;    //the angle to rotate:&#xA;    float ang = -0.4 * 3.14 * sin(u_time);&#xA;&#xA;    //Transform coordinates:&#xA;    float c = cos(ang); float s = sin(ang);    &#xA;    mat2 trans = mat2(c,-s,s,c);    &#xA;    vec2 cp_t = trans * cp;    &#xA;    cp_t +=p;&#xA;&#xA;&#xA;&#xA;    if(use_plot_function){&#xA;        //Attempt 1: plot unrotated original curve translated upwards: &#xA;        float curve1 = plot(uv, cp.y + p.y);&#xA;        color.g *= curve1;    &#xA;&#xA;        //Attemp 2: plot the transformed curve using plotTransformed, rotates first, then translates:&#xA;        float curve2 = plotTransformed(uv, cp.y, p, ang);&#xA;        color.r *= curve2;&#xA;&#xA;        //Attempt 3: curve is transformed first then ploted:&#xA;        float curve3 = plot(uv, cp_t.y);&#xA;        color.b *= curve3;&#xA;    }            &#xA;    else{&#xA;        float plotThk = 0.02;&#xA;&#xA;         //Attempt 1: change color based on distance from unrotated original curve: &#xA;        float dist = distance(uv, cp + vec2(0.0, p.y));&#xA;        if(dist &amp;lt; plotThk)&#xA;            color.g *= (1.0 -dist)/plotThk;   &#xA;&#xA;        //Attempt 2: change color based on distance from transformed coordinates:&#xA;        dist = distance(uv, cp_t);&#xA;        if(dist &amp;lt; plotThk)&#xA;            color.r *= (1.0 -dist)/plotThk;   &#xA;&#xA;    }&#xA;&#xA;    gl_FragColor = vec4(color,1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In the code above, there are two modes which can be toggled with &lt;code&gt;use_plot_function&lt;/code&gt; set to &lt;code&gt;false&lt;/code&gt; or &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First mode attempts to plot using the functions &lt;code&gt;plot(&lt;/code&gt;) &amp;amp; &lt;code&gt;plotTransformed()&lt;/code&gt;.&#xA;Second mode sets a color to a fragment based on the distance from the calculated curve coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result of first mode with &lt;code&gt;use_plot_function&lt;/code&gt; set to &lt;code&gt;true&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ku8cE.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ku8cE.gif&quot; alt=&quot;Three different attempts with use_plot_function set to true&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result of second mode with &lt;code&gt;use_plot_function&lt;/code&gt; set to &lt;code&gt;false&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W6EAU.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W6EAU.gif&quot; alt=&quot;use_plot_function set to false&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously I'm misunderstanding how this should be done in a fragment shader. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I correctly define a transformed curve in GLSL fragment shader?&lt;/p&gt;&#xA;" OwnerUserId="3434" LastActivityDate="2018-05-16T15:56:13.220" Title="Curve rotation in GLSL fragment shader" Tags="&lt;transformations&gt;&lt;glsl&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7637" PostTypeId="1" CreationDate="2018-05-16T06:54:53.010" Score="1" ViewCount="265" Body="&lt;p&gt;I have a bunch of meshes in the .X format, which isn't supported by many 3D applications today. Therefore, I would like to convert these to a modern format like fbx or gltf/glb. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since these meshes are proprietary, an offline solution would be preferred. What would be an ideal way to achieve this lossless-ly?&lt;/p&gt;&#xA;" OwnerUserId="77" LastActivityDate="2018-05-30T09:34:37.440" Title="Convert a .X mesh to a modern format" Tags="&lt;mesh&gt;&lt;gltf&gt;&lt;conversion&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7638" PostTypeId="2" ParentId="7637" CreationDate="2018-05-16T14:14:27.710" Score="1" Body="&lt;p&gt;Blender appears to have a .X importer.  It's a plugin that ships with Blender, but is disabled by default, so you have to enable it in User Preferences.  See: &lt;a href=&quot;https://blender.stackexchange.com/a/8749/18161&quot;&gt;https://blender.stackexchange.com/a/8749/18161&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blender also has a glTF exporter.  For now that's a separate download, from here: &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Blender-Exporter&quot; rel=&quot;nofollow noreferrer&quot;&gt;glTF-Blender-Exporter&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1908" LastActivityDate="2018-05-16T14:14:27.710" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7639" PostTypeId="2" ParentId="7636" CreationDate="2018-05-16T15:56:13.220" Score="4" Body="&lt;p&gt;You are doing completely different things in Matlab than in your Fragment Shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Matlab you are generating bunch of points that can be drawn &lt;strong&gt;anywhere&lt;/strong&gt; on the screen and then you are transforming them. This would be loose equivalent of your Matlab code in Fragment Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define ARRAY_SIZE 256&#xA;&#xA;void main() {&#xA;    vec2 st = gl_FragCoord.xy / u_resolution.xy;&#xA;    st = st * 2.0 - 1.0;&#xA;    st.x *= u_resolution.x / u_resolution.y;&#xA;&#xA;    //the angle to rotate:&#xA;    float ang = u_time * 0.5;&#xA;&#xA;    //Transform coordinates:&#xA;    float c = cos(ang); &#xA;    float s = sin(ang);    &#xA;    mat2 trans = mat2(c, s, -s, c);&#xA;&#xA;    // our domain is from -1 to 1 so total length is 2.0&#xA;    float xStep = 2.0 / float(ARRAY_SIZE);&#xA;&#xA;    // How far we are from current pixel location to the curve&#xA;    float minDist = 1e3;&#xA;&#xA;    // initialize points&#xA;    for (int i = 0; i &amp;lt; ARRAY_SIZE; ++i) {&#xA;        float x = -1.0 + float(i) * xStep;&#xA;&#xA;        // initialize points&#xA;        vec2 cp = vec2(x, 0.08 * sin(x * 40.0));&#xA;&#xA;        // transform&#xA;        cp = trans * cp;&#xA;        minDist = min(minDist, distance(st, cp));&#xA;    }&#xA;&#xA;    // Add some contrast:&#xA;    float d = pow(minDist, 0.1);&#xA;&#xA;    vec3 col = vec3(fract(d));&#xA;    gl_FragColor = vec4(col, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(Here is the live version: &lt;a href=&quot;http://thebookofshaders.com/edit.php?log=180516153813&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://thebookofshaders.com/edit.php?log=180516153813&lt;/a&gt; ). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/92JjM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/92JjM.png&quot; alt=&quot;Matlab equivalent&quot;&gt;&lt;/a&gt;&#xA;For drawing I'm using distance to points because of simplicity, but better way would be to use distance to line segments that the points should be connected by.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the other hands, in your fragment shaders you are first calculating something relative to a &lt;strong&gt;fixed&lt;/strong&gt; pixel location (gl_FragCoord.xy), then transforming it in a way that it is not valid from the pixel's point of view any more, and then you are hoping that you can calculate proper distance to it.&#xA;Unfortunately this won't work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4GSag.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4GSag.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Example of fixed location of a Fragment Shader invocation)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what you can do is first rotate the domain (and not result of your calculations), and then perform all calculations in it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Plot a line on Y using a value between 0.0-1.0&#xA;float plot(vec2 st, float pct){&#xA;  return  smoothstep( pct-0.02, pct, st.y) -&#xA;          smoothstep( pct, pct+0.02, st.y);&#xA;}&#xA;&#xA;void main() {&#xA;    vec2 st = gl_FragCoord.xy / u_resolution.xy;&#xA;    st = st * 2.0 - 1.0;&#xA;    st.x *= u_resolution.x / u_resolution.y;&#xA;&#xA;    //the angle to rotate:&#xA;    float ang = u_time * 0.5;&#xA;&#xA;    //Transform coordinates:&#xA;    float c = cos(ang); &#xA;    float s = sin(ang);    &#xA;    mat2 trans = mat2(c, s, -s, c);&#xA;&#xA;#if 1&#xA;   // You need to transform domain first:&#xA;   st *= trans;    &#xA;&#xA;   // then perform the calculations:&#xA;   vec2 cp = vec2(st.x, 0.08 * sin(st.x * 40.0));&#xA;#else    &#xA;    // This won't work (your old way):&#xA;    vec2 cp = vec2(st.x, 0.08 * sin(st.x * 40.0));&#xA;    cp = trans * cp; &#xA;#endif&#xA;&#xA;    vec3 col = vec3(fract(distance(st, cp)));&#xA;    col.r += plot(st, cp.y);&#xA;&#xA;    gl_FragColor = vec4(col, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(Live version: &lt;a href=&quot;http://thebookofshaders.com/edit.php?log=180516154712&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://thebookofshaders.com/edit.php?log=180516154712&lt;/a&gt; )&#xA;&lt;a href=&quot;https://i.stack.imgur.com/qINJG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qINJG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5358" LastActivityDate="2018-05-16T15:56:13.220" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7640" PostTypeId="2" ParentId="7628" CreationDate="2018-05-16T22:01:28.303" Score="-1" Body="&lt;p&gt;What's probably happening is that you're doing indirect texture fetches. Are you doing something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 a = texture3D(sampler, coord);&#xA;vec4 b = texture3D(sampler, coord + vec4(0, 0, 1));&#xA;vec4 c = texture3D(sampler, coord + vec4(0, 1, 0));&#xA;vec4 d = texture4D(sampler, coord + vec4(1, 0, 0));&#xA;//...etc.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If so, that can slow you down. What you can do instead is to pass the texture coordinates for each sampler call into your vertex shader from your CPU code. You'd set it up as if you were doing multi-texturing, but all the texture units would point to the same texture, just sampled at different coordinates. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Taking the 2D case, instead of passing in a single texture coordinate like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 texCoords[] = { &#xA;    { 0, 0 },&#xA;    { width, 0 },&#xA;    { width, height },&#xA;    { 0, height }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You'd pass in 4 of them:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 texCoords[] = {&#xA;    // texture 0 coords&#xA;    { 0, 0 },&#xA;    { width, 0 },&#xA;    { width, height },&#xA;    { 0, height },&#xA;&#xA;    // texture 1 coords&#xA;    { 1, 0 },&#xA;    { width + 1, 0 },&#xA;    { width + 1, height },&#xA;    { 1, height },&#xA;&#xA;    // Texture 2 coords&#xA;    { 0, 1 },&#xA;    { width, 1 },&#xA;    { width, height + 1 },&#xA;    { 0, height + 1 },&#xA;&#xA;    // Texture 3 coords&#xA;    { 1, 1 },&#xA;    { width + 1, 1 },&#xA;    { width + 1, height + 1 },&#xA;    { 1, height + 1 }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In your fragment shader, you'd do something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 pixel0 = texture2D(sampler0, coord0);&#xA;vec4 pixel1 = texture2D(sampler1, coord1);&#xA;vec4 pixel2 = texture2D(sampler2, coord2);&#xA;vec4 pixel3 = texture2D(sampler3, coord3);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now you have the 4 pixels needed for interpolation, but there was no fragment shader math done to get the texture coords, so there are no indirect look-ups which are slower than direct look-ups.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-05-16T22:01:28.303" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7643" PostTypeId="1" CreationDate="2018-05-17T10:51:43.583" Score="4" ViewCount="328" Body="&lt;p&gt;When we convert from canonical space to screen space,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To map x from -1 to 1 to 0 to width,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;-1 &amp;lt; x &amp;lt; 1&#xA;0 &amp;lt; x+1 &amp;lt; 2&#xA;0 &amp;lt; x+1/2 &amp;lt; 1&#xA;0 &amp;lt; (x+1)w/2 &amp;lt; w&#xA;0 &amp;lt; xw/2 + w/2 &amp;lt; w&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Similarly for y,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;-1 &amp;lt; y &amp;lt; 1&#xA;0 &amp;lt; y+1 &amp;lt; 2&#xA;0 &amp;lt; y+1/2 &amp;lt; 1&#xA;0 &amp;lt; (y+1)h/2 &amp;lt; h&#xA;0 &amp;lt; yh/2 + h/2 &amp;lt; h&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RAs4q.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RAs4q.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the reason behind choosing a screen that has (xmin, ymin) = (0.5, 0.5) and (xmax, ymax) = (1920 - 0.5, 1080 - 0.5) where (nx, ny) = (1920, 1080)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ePX1x.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ePX1x.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8748" LastActivityDate="2018-11-13T23:02:30.470" Title="Canonical Space to Screen Space: Why do we have the strange -0.5?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7644" PostTypeId="2" ParentId="7627" CreationDate="2018-05-17T13:30:48.573" Score="2" Body="&lt;p&gt;In line 15 use the half-open interval, i.e.,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if u&amp;gt;=t[0][i] and u&amp;lt;t[0][i+1]:&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Otherwise, at knot values, you evaluate two basis functions at the k=1 basis when you only want one. This causes the wrong evaluation of the basis function at the knot values and therefore the spikes.  &lt;/p&gt;&#xA;" OwnerUserId="8749" LastActivityDate="2018-05-17T13:30:48.573" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7645" PostTypeId="2" ParentId="7643" CreationDate="2018-05-17T15:34:07.217" Score="1" Body="&lt;p&gt;I can't really answer this without the context so post some links where this is done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I can tell you is that the general formula for viewport transformation as done by OpenGL is given as (taken from &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#Viewport_transform&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BWAUb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BWAUb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here &lt;code&gt;x,y&lt;/code&gt; are the what your picture says &lt;code&gt;xmin, ymin&lt;/code&gt; and &lt;code&gt;width, height&lt;/code&gt; is &lt;code&gt;xmax, ymax&lt;/code&gt;. Now there is no specific reason I can think of why you would wanna do a shift of &lt;code&gt;-0.5&lt;/code&gt; but the viewport allows us to draw to a specific portion of the screen. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, in video games you would want to draw the minimap on the lower left corner of the screen, hence you could provide the values&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;x = 0, y = 0, width = 200, height = 200&lt;/code&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This would render a 200x200 minimap in the lower left corner. Your second picture does this but instead it chooses a value of&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;x = -0.5, y = -0.5, width = nx, height = ny&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you substitute it in the above matrix you'll get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ \frac{nx}{2} * x_{ndc} - \frac{1}{2} + \frac{nx}{2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for the $X$ value. This equals&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ \frac{nx}{2} * x_{ndc} + \frac{nx - 1}{2}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is the same as what is done in the picture you posted. Hope it helped somewhat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- &lt;code&gt;0.5&lt;/code&gt; offset is commonly used to get to the pixel center. See this image as an example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here the pixel &lt;code&gt;3,5&lt;/code&gt; has the center &lt;code&gt;3.5, 5.5&lt;/code&gt;. This is the 0.5 offset you are seeing. I was confused at first when you were talking about an offset of negative 0.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kL2i3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kL2i3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-05-17T20:00:01.713" LastActivityDate="2018-05-17T20:00:01.713" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7647" PostTypeId="1" CreationDate="2018-05-18T14:45:57.627" Score="1" ViewCount="156" Body="&lt;p&gt;I am trying to project a Polyhedron on the xy plane with CGAL, which should result in a (2D) polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wonder, if there is an elegant way to achieve it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, I can iterate over all surfaces and build 2D-Segments from the 3D-Segments by throwing away the z coordinate and then reassemble the polgon cycles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I feel, that somehow using &lt;code&gt;Projection_traits_xy_3&lt;/code&gt; it should be possible to solve that task more elegant, however, I couldn't find a way. Is this possible?&lt;/p&gt;&#xA;" OwnerUserId="8297" LastActivityDate="2018-06-20T10:53:16.917" Title="Projection of a Polyhedron on xy Plane with CGAL" Tags="&lt;computational-geometry&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7648" PostTypeId="2" ParentId="7633" CreationDate="2018-05-20T04:21:33.477" Score="1" Body="&lt;p&gt;It would seem that, in the second example, the morphNormals are targets while in in the first they are deltas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This explains the difference in math used between the two pieces of code.&lt;/p&gt;&#xA;" OwnerUserId="8680" LastActivityDate="2018-05-20T04:21:33.477" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7649" PostTypeId="1" CreationDate="2018-05-20T14:30:02.490" Score="3" ViewCount="93" Body="&lt;p&gt;I am trying to implement linear bending of a mesh by following what Alan H. Barr explained in his &lt;em&gt;Global and local deformations of solid primitives&lt;/em&gt; paper (&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=808573&quot; rel=&quot;nofollow noreferrer&quot;&gt;ACM link&lt;/a&gt;, &lt;a href=&quot;http://www.cs.drexel.edu/~david/Classes/Papers/p21-barr.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Direct Link hosted on a faculty page&lt;/a&gt;, pag.5). The issue I have is that I don't quite understand the formulas involved:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/EvNbb.png&quot; alt=&quot;y formula&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/qWYeF.png&quot; alt=&quot;z formula&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming we bend the mesh by an angle &lt;img src=&quot;https://i.stack.imgur.com/APqQB.png&quot; alt=&quot;theta angle&quot;&gt;, where &lt;img src=&quot;https://i.stack.imgur.com/gis7s.png&quot; alt=&quot;y hat&quot;&gt; is the clamped value of y between some specified ymin and ymax. k is the bending rate expressed in [rad/m] (and thus the radius of curvature is 1/k). The axis of bending is [s, y_0, 1/k]', where s is a free parameter and y0 is the bending center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can somebody explain, possibly with an image, the terms in the formulas above? I guess that I should look for an angle alpha = pi/2 + theta, since cos(alpha) = -sin(theta), sin(alpha) = cos(theta), but I am not able to figure it out. Thanks!&lt;/p&gt;&#xA;" OwnerUserId="8761" LastEditorUserId="8761" LastEditDate="2018-05-22T21:47:15.763" LastActivityDate="2018-05-22T21:47:15.763" Title="Linear bending of a mesh" Tags="&lt;transformations&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7650" PostTypeId="1" AcceptedAnswerId="7667" CreationDate="2018-05-20T22:19:42.473" Score="2" ViewCount="2066" Body="&lt;p&gt;I'm trying to build a toy path tracer using something similar to Disney's BSDF, where many materials can be represented as combinations of properties like color, metalness, roughness, transmission, ior.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to use the &lt;a href=&quot;http://www.graphics.cornell.edu/~bjw/microfacetbsdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;GGX microfacet BSDF&lt;/a&gt;, but without splitting the ray each time to get &amp;amp; sum the Fr and Ft terms for reflection and transmission. Is it normal/ok to use schlick's approximation to randomly choose between transmission and reflection (Ft vs Fr), and then to just use the BRDF and BTDF formulas separately depending on which path the system chooses?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, roughly:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;On hit (into)&#xA;- Reflect or Transmit via Schlick(i, o, n)&#xA;    - Reflect:&#xA;        - Direct (N times):&#xA;            - Choose point on disc of random light&#xA;            - Calc transmission t via BRDF(i, o, n)&#xA;            - Calc pdf by area of cone / area of hemisphere&#xA;            - Add light * t / pdf&#xA;        - Indirect (1 time):&#xA;            - Choose direction o by BRDF.Sample(i, n)&#xA;            - Calc transmission t via BRDF(i, o, n)&#xA;            - Calc pdf by BRDF.PDF(i, o, n) ??&#xA;            - Add trace(o) * t / pdf&#xA;    - Transmit:&#xA;        - Choose direction o by snell(i, n) + some kind of roughness * offset&#xA;        - (how do you apply the BTDF here? Or is it important?)&#xA;On hit (out of)&#xA;    - Choose direction o by snell(i, n) + some kind of roughness * offset&#xA;    - Reduce transmission via beer(distance)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I also wonder how diffused reflections factor in. For instance, does GGX only provide specular reflection &amp;amp; refraction? In that case, how do you also handle diffusion?&lt;/p&gt;&#xA;" OwnerUserId="5180" LastEditorUserId="5180" LastEditDate="2018-05-20T22:48:42.413" LastActivityDate="2018-05-29T01:38:14.320" Title="Is the microfacet GGX BSDF normally implemented as separate BRDF and BTDFs?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7651" PostTypeId="1" CreationDate="2018-05-20T23:39:20.583" Score="2" ViewCount="331" Body="&lt;p&gt;The format of SPIR-V bytecode is probably one of the least documented parts of both OpenGL and Vulkan that I am aware of. I have compiled a very basic fragment shaders into both the OpenGL and Vulkan SPIR-V formats. Looking at the files in a hex editor, I see no obvious differences, but when I hash the files, they give a different result. What are the differences between the OpenGL and Vulkan SPIR-V formats?&lt;/p&gt;&#xA;" OwnerUserId="8762" LastActivityDate="2018-05-21T05:50:03.010" Title="How different is the SPIR-V accepted by OpenGL (ARB_gl_spirv) from SPIR-V accepted by Vulkan?" Tags="&lt;opengl&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7652" PostTypeId="2" ParentId="7651" CreationDate="2018-05-21T05:50:03.010" Score="4" Body="&lt;p&gt;Vulkan and OpenGL use different models for their resource bindings. Vulkan uses descriptor sets + binding, while OpenGL uses binding indices. As such, the SPIR-V they consume use different decorations for their resources.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also a number of differences in terms of built-ins that the two APIs provide. For example, Vulkan accepts the &lt;code&gt;InstanceIndex&lt;/code&gt; built-in, while OpenGL does not. OpenGL uses &lt;code&gt;InstanceId&lt;/code&gt;, which has a different meaning from &lt;code&gt;InstanceIndex&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ARB_gl_spirv extension has a pretty exhaustive list of the differences between it and KHR_vulkan_glsl. Many of those are differences that the output SPIR-V will have to expose.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-05-21T05:50:03.010" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7654" PostTypeId="2" ParentId="7647" CreationDate="2018-05-21T10:14:55.670" Score="2" Body="&lt;p&gt;A possible way to do this is tracing the &lt;a href=&quot;https://en.wikipedia.org/wiki/Silhouette_edge&quot; rel=&quot;nofollow noreferrer&quot;&gt;silhouette edges&lt;/a&gt; of the polyhedron and projecting them to a 2d polygon only at the end of the process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A silhouette edge (in your context) is defined by its neighboring facets having one upwards and one downwards normal (i.e., one positive normal z-coordinate and one negative). This can be checked using Polyhedron_traits_with_normals_3 or you can compute the normals yourself on-the-fly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you only need the outside polygon, you can start with an extreme vertex (e.g., the one with minimal x-coordinate), circulate over its incident halfedges (using Halfedge_around_vertex_circulator), take the one that is a silhouette edge and continue tracing with its next vertex until you close the cycle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you also need inside (hole) polygons, a possible solution can be to gather the silhouette edges from all the polyhedron, and trace the cycles from this set.&lt;/p&gt;&#xA;" OwnerUserId="8749" LastActivityDate="2018-05-21T10:14:55.670" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7655" PostTypeId="2" ParentId="7623" CreationDate="2018-05-21T13:59:30.817" Score="1" Body="&lt;p&gt;You can use CGAL's &lt;a href=&quot;https://doc.cgal.org/latest/Convex_hull_3/group__PkgConvexHull3Functions.html#gade99e8e830ff439ae242b7ab04de06c8&quot; rel=&quot;nofollow noreferrer&quot;&gt;half_space_intersection_3&lt;/a&gt; or &lt;a href=&quot;https://doc.cgal.org/latest/Convex_hull_3/group__PkgConvexHull3Functions.html#ga7517c4cbbef41338397eda273af75eb1&quot; rel=&quot;nofollow noreferrer&quot;&gt;half_space_intersection_with_construction_3&lt;/a&gt; functions, where the half-spaces are defined by the faces of the cuboids.&lt;/p&gt;&#xA;" OwnerUserId="8749" LastActivityDate="2018-05-21T13:59:30.817" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7656" PostTypeId="1" CreationDate="2018-05-22T06:06:34.220" Score="6" ViewCount="2322" Body="&lt;p&gt;I have a renderer where the BxDF interface is Sample(), PDF(), and Eval(). The Lambertian BRDF is working well, and I believe I have properly implemented Eval for GGX based on &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/130/trying-to-implement-microfacet-brdf-but-my-result-images-are-wrong&quot;&gt;another user's question&lt;/a&gt;, but I'm struggling to find a resource I can understand that explains how to generate samples, and then calculate the corresponding PDFs, for a GGX distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've found some of the original papers, but unlike Lambert the Sampling and PDF seem based on spherical coordinates (which I don't really understand - 3D Vectors are about the limit of my math).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would really love to know how to translate &lt;a href=&quot;https://hal.archives-ouvertes.fr/hal-01509746/document&quot; rel=&quot;noreferrer&quot;&gt;&quot;A Simpler and Exact Sampling Routine for the GGX Distribution of Visible Normals&quot;&lt;/a&gt; into separate Sample() and PDF() functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's what I have for Lambert:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;type Lambert struct {&#xA;    R, G, B float64&#xA;}&#xA;&#xA;func (l Lambert) Sample(out, normal geom.Direction, rnd *rand.Rand) geom.Direction {&#xA;    return normal.RandHemiCos(rnd)&#xA;}&#xA;&#xA;func (l Lambert) PDF(in, normal geom.Direction) float64 {&#xA;    return in.Dot(normal) * math.Pi&#xA;}&#xA;&#xA;func (l Lambert) Eval(in, out, normal geom.Direction) rgb.Energy {&#xA;    return rgb.Energy{l.R, l.G, l.B}.Scaled(math.Pi * in.Dot(normal))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here's my in-progress work for Microfacets:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;func (m Microfacet) Sample(out, normal geom.Direction, rnd *rand.Rand) geom.Direction {&#xA;    // TODO: better sampling&#xA;    return normal.RandHemi(rnd)&#xA;}&#xA;&#xA;func (m Microfacet) PDF(in, normal geom.Direction) float64 {&#xA;    // TODO: PDF that matches a better sampling distribution&#xA;    return 1 / (2 * math.Pi)&#xA;}&#xA;&#xA;// https://computergraphics.stackexchange.com/questions/130/trying-to-implement-microfacet-brdf-but-my-result-images-are-wrong&#xA;// https://schuttejoe.github.io/post/ggximportancesamplingpart2/&#xA;func (m Microfacet) Eval(in, out, normal geom.Direction) rgb.Energy {&#xA;    F := schlick2(in, normal, m.F0.Mean())  // The Fresnel function&#xA;    D := ggx(in, out, normal, m.Roughness)  // The NDF (Normal Distribution Function)&#xA;    G := smithGGX(out, normal, m.Roughness) // The Geometric Shadowing function&#xA;    r := (F * D * G) / (4 * normal.Dot(in) * normal.Dot(out))&#xA;    return m.F0.Scaled(r)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The GGX BSDF relies on several physics functions I've also implemented:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Schlick's approximation of Fresnel&#xA;func schlick2(in, normal geom.Direction, f0 float64) float64 {&#xA;    return f0 + (1-f0)*math.Pow(1-normal.Dot(in), 5)&#xA;}&#xA;&#xA;// GGX Normal Distribution Function&#xA;// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&#xA;func ggx(in, out, normal geom.Direction, roughness float64) float64 {&#xA;    m := in.Half(out)&#xA;    a := roughness * roughness&#xA;    nm2 := math.Pow(normal.Dot(m), 2)&#xA;    return (a * a) / (math.Pi * math.Pow(nm2*(a*a-1)+1, 2))&#xA;}&#xA;&#xA;// Smith geometric shadowing for a GGX distribution&#xA;// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&#xA;func smithGGX(out, normal geom.Direction, roughness float64) float64 {&#xA;    a := roughness * roughness&#xA;    nv := normal.Dot(out)&#xA;    return (2 * nv) / (nv + math.Sqrt(a*a+(1-a*a)*nv*nv))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5180" LastEditorUserId="5180" LastEditDate="2018-05-22T08:17:19.897" LastActivityDate="2018-05-23T14:09:10.840" Title="Importance sampling microfacet GGX" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7658" PostTypeId="1" CreationDate="2018-05-22T19:24:55.317" Score="3" ViewCount="359" Body="&lt;p&gt;I'm struggling with light leaking through meshes (especially thin ones) due to interpolation between probes located on the opposite sides of those. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First approach I took was mapping all static geometry to 1 lightmap, then generating light probes for each texel center that can be mapped to some triangle. Compute probe world position using barycentric coords of a texel on a corresponding static geometry triangle and then, in fragment shader, bilinearly interpolate between probes using fragment's UV coordinate. Unfortunately, I had to throw all of this away, because automatic UV mapping (all of the tools available in Blender, for example) are absolutely not suitable for this task and the manual UV crafting is just too tedious to be viable. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I saw a Guerrilla Games presentation regarding GI tech in the Killzone which leverages shadow maps (kind of) to store occlusion data for each probe. I thought maybe I could pull off something similar. What I did was ray trace occlusions for each probe and store occlusion distances for respective ray directions in a huge texture atlas, then, in a fragment shader, determine which probes are occluded for the current pixel by comparing distance from probe to pixel with occlusion distance for the nearest ray and set interpolation weights for occluded probes to 0. But, there are 2 serious problems to this approach, which I found only after implementing the algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Let's consider the case, when distance from the current pixel to the probe is compared to ray 3 (see attached illustration). For pixels located in the range denoted 'l' distance to probe will be greater than occlusion distance for ray 3 and the probe will be considered occluded, but it's not!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uLUWk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uLUWk.jpg&quot; alt=&quot;First problem&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Let's imagine the first problem is solved. Now the problem of a thin mesh arises. For such mesh pixels on the opposite sides of it will have pretty much the same world location and distance tests will result in full interpolation of probes from both sides for both pixels. I guess a solution for this will require pixel's normal, but maybe it will come after the first issue is resolved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nsiIK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nsiIK.jpg&quot; alt=&quot;Second problem&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would greatly appreciate any help in solving there problems. Or maybe someone could point towards more viable algorithm instead?&lt;/p&gt;&#xA;" OwnerUserId="8541" LastActivityDate="2018-05-29T01:21:52.573" Title="How to deal with light leaks?" Tags="&lt;lighting&gt;&lt;interpolation&gt;&lt;occlusion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7659" PostTypeId="1" AcceptedAnswerId="7661" CreationDate="2018-05-22T19:27:50.823" Score="5" ViewCount="85" Body="&lt;p&gt;When the display hardware is physically rotated 90 degrees, your graphics can still be rendered with the correct side up. Where is this rotation accomplished?&#xA;I can imagine a few possibilities:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A) The code for every low-level graphics primitive contains something to converts its arguments, like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (portrait) {&#xA;   swap(x,y);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(or perhaps multiplying every coordinate with a matrix)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;B) The part of the graphics card that continuously scans its memory to create a video signal reads the data in a different order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;C) The monitor paints the received data column by column instead of row by row&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A and B sounds like they would be inefficient and C means that it would only work on monitors that has special hardware-support for rotation.&#xA;Which one is it?&lt;/p&gt;&#xA;" OwnerUserId="8770" LastActivityDate="2018-05-22T20:52:00.797" Title="What part of the graphics chain rotates computer displays when in portrait mode?" Tags="&lt;2d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7660" PostTypeId="1" AcceptedAnswerId="7665" CreationDate="2018-05-22T19:43:40.250" Score="1" ViewCount="168" Body="&lt;p&gt;All objects have two AABB (Axis Aligned Bounding Box), one in local space and one another in world space. The box in local space is calculated while importing scene from external source, and the box in world space is transformed version of local one&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The AABB of scene is combined of all child AABB boxes. I'm using the center of scene's AABB as center of scene. This is where my problems begins.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using the center point to rotate scene using a trackball. After scene is rotated around center of AABB, then new node transforms are applied to each AABB and new AABB for scene is re-computed by combining/joining all AABB boxes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&#xA;After rotation applied and new AABB is computed, then the new AABB's center is not same as previous one. So after rotation, center and scene is moving a little. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is no problem in these cases:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If there is only one object in scene then new center is not changing so scene doesn't move after rotation. Everything looks good here. Object/Model/Primitive may have local transform, this doesn't affect the result&lt;/li&gt;&#xA;&lt;li&gt;for instance if there are two cube without rotations then center is not moving too, except if one of cube has rotation or there are three cube then center is moving.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If my rotating-around-object codes are wrong then it wouldn't work for single object too, right? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here how I compute center of box, &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;center = (box.min + box.max) * 0.5&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;this is not actual code, because I'm using C.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it normal to have moving center after rotation? How do you get center of scene? Using center of AABB like I did?? Any suggestions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe it must work and maybe I have a weird bug is some place I don't know, I tried to find it but I had to ask because maybe it is wrong to get center of scene via AABB boxes :(&lt;/p&gt;&#xA;" OwnerUserId="6929" LastActivityDate="2018-05-27T11:45:49.417" Title="Rotating scene or complex object using center of AABB" Tags="&lt;transformations&gt;&lt;scene-graph&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7661" PostTypeId="2" ParentId="7659" CreationDate="2018-05-22T20:52:00.797" Score="2" Body="&lt;p&gt;On typical GPUs today it's option B: monitor rotation is done by the video output hardware (&quot;display engine&quot;) during scan-out. In addition to rotating/flipping, the display engine can also scale the image within certain limits, do simple color/gamma correction, and even composite multiple image layers (&quot;planes&quot;) together, all dynamically during scan-out.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-05-22T20:52:00.797" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7662" PostTypeId="2" ParentId="7656" CreationDate="2018-05-23T14:09:10.840" Score="5" Body="&lt;p&gt;Through help from several people, &amp;amp; referencing and re-referencing the commented urls, I managed to get a sampling scheme with matching PDF that handles everything from perfect mirror surfaces to roughness = 1. Here's the eventual result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6mTVc.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6mTVc.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Cook-Torrance microfacet model&#xA;type Microfacet struct {&#xA;    F0        rgb.Energy&#xA;    Roughness float64&#xA;}&#xA;&#xA;// https://schuttejoe.github.io/post/ggximportancesamplingpart1/&#xA;// https://agraphicsguy.wordpress.com/2015/11/01/sampling-microfacet-brdf/&#xA;func (m Microfacet) Sample(wo geom.Direction, rnd *rand.Rand) geom.Direction {&#xA;    r0 := rnd.Float64()&#xA;    r1 := rnd.Float64()&#xA;    a := m.Roughness * m.Roughness&#xA;    a2 := a * a&#xA;    theta := math.Acos(math.Sqrt((1 - r0) / ((a2-1)*r0 + 1)))&#xA;    phi := 2 * math.Pi * r1&#xA;    x := math.Sin(theta) * math.Cos(phi)&#xA;    y := math.Cos(theta)&#xA;    z := math.Sin(theta) * math.Sin(phi)&#xA;    wm := geom.Vector3{x, y, z}.Unit()&#xA;    wi := wo.Reflect2(wm)&#xA;    return wi&#xA;}&#xA;&#xA;// https://schuttejoe.github.io/post/ggximportancesamplingpart1/&#xA;// https://agraphicsguy.wordpress.com/2015/11/01/sampling-microfacet-brdf/&#xA;// https://en.wikipedia.org/wiki/List_of_common_coordinate_transformations#From_Cartesian_coordinates_2&#xA;func (m Microfacet) PDF(wi, wo geom.Direction) float64 {&#xA;    wg := geom.Up&#xA;    wm := wo.Half(wi)&#xA;    a := m.Roughness * m.Roughness&#xA;    a2 := a * a&#xA;    cosTheta := wg.Dot(wm)&#xA;    exp := (a2-1)*cosTheta*cosTheta + 1&#xA;    D := a2 / (math.Pi * exp * exp)&#xA;    return (D * wm.Dot(wg)) / (4 * wo.Dot(wm))&#xA;}&#xA;&#xA;// http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&#xA;func (m Microfacet) Eval(wi, wo geom.Direction) rgb.Energy {&#xA;    wg := geom.Up&#xA;    wm := wo.Half(wi)&#xA;    if wi.Y &amp;lt;= 0 || wi.Dot(wm) &amp;lt;= 0 {&#xA;        return rgb.Energy{0, 0, 0}&#xA;    }&#xA;    F := fresnelSchlick(wi, wg, m.F0.Mean()) // The Fresnel function&#xA;    D := ggx(wi, wo, wg, m.Roughness)        // The NDF (Normal Distribution Function)&#xA;    G := smithGGX(wo, wg, m.Roughness)       // The Geometric Shadowing function&#xA;    r := (F * D * G) / (4 * wg.Dot(wi) * wg.Dot(wo))&#xA;    return m.F0.Scaled(r)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5180" LastActivityDate="2018-05-23T14:09:10.840" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7663" PostTypeId="2" ParentId="6115" CreationDate="2018-05-23T14:49:17.707" Score="1" Body="&lt;p&gt;This may depend on target hardware and the API you are going to use. Can you provide more info? Here's some (very broad and general) best practices for OpenGL.&#xA;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Specification_Best_Practices&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengl/wiki/Vertex_Specification_Best_Practices&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, do you have a performance problem? Or are you just curious. &lt;/p&gt;&#xA;" OwnerUserId="8772" LastActivityDate="2018-05-23T14:49:17.707" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7665" PostTypeId="2" ParentId="7660" CreationDate="2018-05-27T11:45:49.417" Score="0" Body="&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of re-calculating center, pre-defined center is used for primitives. The pre-defined center is center of AABB if other value is not supplied. Averaging all center of mesh primitives gives mesh center and averaging all center of meshes gives scene center. After a mesh is transformed, center also gets transformed. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now center is not moving after rotations. Using center of scene's AABB seems not good idea. Because each shape of child AABB is changing after transformations. &lt;/p&gt;&#xA;" OwnerUserId="6929" LastActivityDate="2018-05-27T11:45:49.417" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7666" PostTypeId="2" ParentId="7658" CreationDate="2018-05-29T01:21:52.573" Score="1" Body="&lt;p&gt;I've also spent a good amount of time thinking about a solution for this problem. It seems like one those fundamental mismatches of taking a sparser, lower frequency structure (probe mesh, even if augmented with depth map) and lighting surfaces per pixel which themselves are occluders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at the SIGGRAPH'17 Precomputed lighting in CoD:IW (&lt;a href=&quot;http://advances.realtimerendering.com/s2017/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://advances.realtimerendering.com/s2017/index.html&lt;/a&gt;) you'll see they partitioned the precomputed lighting into light maps for large surfaces (which have lots of occlusion) and using a probe mesh for small static objects as well as characters. They take a similar approach of storing an occlusion depth map per tetrahedra face, however because they're not lighting the occluders with the probe mesh, the discontinuities introduced are likely not noticeable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Trying to light the occluders with the same map is extremely tricky because the probe mesh faces may not align well with the occluders. I.e. literally &quot;corner&quot; case where 3 planes meet doesn't encode well into a depth map. I have feeling they still get light leaks, but their density is probably fairly high and their evaluation points are distant enough from the pathologically bad cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sometimes it might be worth asking level artists to not make single sided meshes or thin walls XD, at least for the time being.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best of luck, if you find a robust solution to this, you should submit a paper to a conference and be graphics industry famous :D &lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-05-29T01:21:52.573" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7667" PostTypeId="2" ParentId="7650" CreationDate="2018-05-29T01:38:14.320" Score="1" Body="&lt;p&gt;In current common material models, Diffuse and Specular material properties are handled separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check out slide 43 on &lt;a href=&quot;http://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically use a diffuse BRDF (lambert, oren nayar) if the material's refraction is scattering is less than 1 pixel. Use refraction and subsurface models if the scattering is larger than a pixel. I.e. in a glass refraction case the light exit is much greater than 1 pixel away from the light entrance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may also be interested in a diffuse parameterization for GGX so that you can use share the same roughness term. &lt;a href=&quot;https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-05-29T01:38:14.320" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7668" PostTypeId="1" AcceptedAnswerId="7669" CreationDate="2018-05-29T06:29:53.157" Score="0" ViewCount="96" Body="&lt;p&gt;Suppose I am making my own C++ 3D engine; I can already load a 3D model using assimp, display it with phong lighting, and I now want to animate it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like features in my engine to, say, load a run animation with assimp, and apply it to my human character, preferably on the GPU side. Which techniques do I need to learn to develop this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a &quot;grocery list&quot; kind of question, where I don't necessarily need a step-by-step explanation, but more of an overview of the techniques involved to know what I need to research. (stuff like &quot;read this OpenGL tutorial&quot; or &quot;learn how X works&quot;)&lt;/p&gt;&#xA;" OwnerUserId="8660" LastActivityDate="2018-05-29T10:03:48.753" Title="Which techniques do I need to animate a 3D model in my homemade engine" Tags="&lt;3d&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7669" PostTypeId="2" ParentId="7668" CreationDate="2018-05-29T10:03:48.753" Score="2" Body="&lt;p&gt;First decide how you are going to animate the model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simplest way is to just have a separate mesh per frame of animation. This requires more memory to be dedicated to mesh data more artist time to create them and it locks you into only those poses.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next step upwards is interpolating between full meshes (keyword morph targets). This works great for facial expressions especially if you can give different weights for each vertex. It's not that great for full body animation because it's difficult to get proper circular motion into it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most common technique for full body animation is skeletal animation. Instead of full meshes for each frame of animation you instead have a set of model transform per &quot;bone&quot; and each vertex has a set of weights to decide which bones it follows. In the vertex shader you then interpolate the transforms as appropriate and then apply the interpolated transform to the vertex. This has the upside that different meshes can use the same animation data assuming the bones are set up the same.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-05-29T10:03:48.753" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7670" PostTypeId="1" CreationDate="2018-05-29T12:06:26.653" Score="2" ViewCount="581" Body="&lt;p&gt;As per &lt;a href=&quot;https://patents.google.com/patent/WO2006115784A2/en&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; resource, there is an easy way to convert from YCbCr to HSV. Saturation is sqrt(Cb^2 + Cr^2). Now here is my issue. If I take pure red (1,0,0), green(0,1,0), and blue(0,0,1) colors, convert them to YCrCb, and then compute saturation, I do not get 1. Infact, all the saturations are different no matter which matrix I use for RGB to YCrCb conversion. Am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="8758" LastActivityDate="2018-05-30T02:06:09.350" Title="YUV to HSV to RGB issues" Tags="&lt;color&gt;&lt;color-science&gt;&lt;color-management&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7671" PostTypeId="2" ParentId="7670" CreationDate="2018-05-30T02:06:09.350" Score="1" Body="&lt;p&gt;Think about it this way. To calculate YCbCr of (1, 0, 0), you'll end up with Y = 0.299, Cb = -0.16873, Cr = 0.5. If you take the magnitude of the chroma channels (&lt;code&gt;sqrt(Cb*Cb + Cr*Cr)&lt;/code&gt;), you get ~0.53 for the &quot;saturation&quot;. The YCbCr color space has a different shape than RGB, so it may represent values differently enough that you don't get the exact same answer in both cases. Furthermore, our perception of luminance and saturation is not consistent among colors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all you want is to calculate the saturation of an RGB component, it can be calculated by:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float saturation = max(r, g, b) - min(r, g, b);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that if you attempt to calculate perceptually uniform amounts of color saturation you end up with systems like the &lt;a href=&quot;https://en.wikipedia.org/wiki/Munsell_color_system&quot; rel=&quot;nofollow noreferrer&quot;&gt;Munsell Color System&lt;/a&gt; where the shape of the color space is highly irregular compared with the cubes and cylinders of other color spaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you tell us what you're trying to achieve, we might be able to offer an actual solution to whatever the problem is.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-05-30T02:06:09.350" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7672" PostTypeId="2" ParentId="4087" CreationDate="2018-05-30T07:06:33.280" Score="-1" Body="&lt;p&gt;Though polygons can be sent in any order some polygons may lie in the same plane. Their respective zs can be calculated using the formula z=(-Ax-By-D)/C, and if the two polygon surfaces are at same depth then they can have same value of z. &lt;/p&gt;&#xA;" OwnerUserId="8795" LastEditorUserId="209" LastEditDate="2018-06-04T07:42:53.117" LastActivityDate="2018-06-04T07:42:53.117" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7673" PostTypeId="2" ParentId="7637" CreationDate="2018-05-30T09:34:37.440" Score="1" Body="&lt;p&gt;Perhaps &lt;a href=&quot;https://github.com/assimp/assimp&quot; rel=&quot;nofollow noreferrer&quot;&gt;Assimp&lt;/a&gt; will work for you? In particular, it has a &lt;a href=&quot;https://github.com/assimp/assimp/tree/master/tools/assimp_cmd&quot; rel=&quot;nofollow noreferrer&quot;&gt;command line tool for converting between formats&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8796" LastActivityDate="2018-05-30T09:34:37.440" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7674" PostTypeId="1" AcceptedAnswerId="7675" CreationDate="2018-05-30T14:39:00.473" Score="4" ViewCount="1102" Body="&lt;p&gt;I'm trying to apply raymarching on top of 3D rasterization, ordering what 3D object gets displayed based on the depth of a rasterization pass and the raymarch depth.   After getting the transform right for &lt;em&gt;position&lt;/em&gt; (&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-generating-camera-rays/generating-camera-rays&quot; rel=&quot;nofollow noreferrer&quot;&gt;using the information here&lt;/a&gt;) I was able to have the position of the raymarched spheres coherent with the rasterized cubes.   I ran into issues however with depth being different at the edges of the screen compared to the middle, despite position never changing.&lt;/p&gt;&#xA;&lt;p&gt;These gifs should show what I'm talking about&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rZakQ.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rZakQ.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4fD5Z.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4fD5Z.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;higher res versions&#xA;&lt;a href=&quot;https://ibb.co/ebji0y&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://ibb.co/ebji0y&lt;/a&gt;&#xA;&lt;a href=&quot;https://ibb.co/dhUGLy&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://ibb.co/dhUGLy&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Something odd is going on with depth, but I don't understand what I'm doing wrong?  Here is my fragment shader for my depth texture render pass:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;layout(location = 0) out vec4 FragColor;&#xA;layout(location = 1) out float DepthColor;&#xA;in vec2 TexCoord;&#xA;&#xA;// texture samplers&#xA;uniform sampler2D texture0;&#xA;uniform sampler2D texture1;&#xA;uniform float near;&#xA;uniform float far;&#xA;&#xA;float LinearizeDepth(float depth)&#xA;{&#xA;    float z = depth * 2.0 - 1.0; // back to NDC&#xA;    return (2.0 * near * far) / (far + near - z * (far - near));&#xA;}&#xA;void main()&#xA;{&#xA;&#xA;    float depth = LinearizeDepth(gl_FragCoord.z);&#xA;    DepthColor = depth;&#xA;    FragColor = mix(texture(texture0, TexCoord), texture(texture1, TexCoord), 0.3);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and here is my shader for the final raymarch pass:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;out vec4 FragColor;&#xA;&#xA;in vec2 TexCoords;&#xA;&#xA;uniform sampler2D u_screen_texture;&#xA;uniform sampler2D u_depth_texture;&#xA;uniform float u_fov;&#xA;uniform vec3 u_rotation;&#xA;uniform vec3 u_origin;&#xA;uniform vec3 u_resolution;&#xA;&#xA;const float inf = uintBitsToFloat(0x7F800000u);&#xA;&#xA;vec3 rotVecX(in vec3 vector, in float theta){&#xA;    mat3 rotmat = mat3(1, 0, 0,&#xA;                       0, cos(theta), -sin(theta),&#xA;                       0, sin(theta), cos(theta));&#xA;    return vector * rotmat;&#xA;}&#xA;&#xA;vec3 rotVecY(in vec3 vector, in float theta){&#xA;    mat3 rotmat = mat3(cos(theta), 0, sin(theta),&#xA;                       0, 1, 0,&#xA;                       -sin(theta), 0, cos(theta));&#xA;    return vector * rotmat;&#xA;}&#xA;&#xA;vec3 calculateFragementRay(in vec2 fragCoord, in vec3 resolution){&#xA;    vec2 uv = fragCoord;&#xA;    uv.x = (uv.x * 2.0) - 1.0;&#xA;    uv.y = (2.0 * uv.y) - 1.0;&#xA;    if(resolution.x &amp;gt;= resolution.y){&#xA;        uv.x *= resolution.x/resolution.y;&#xA;    }else{&#xA;        uv.y *= resolution.y/resolution.x;&#xA;    }&#xA;    float tan_fov = tan(u_fov/2.0);&#xA;    vec2 pxy = uv * tan_fov;&#xA;    vec3 ray_dir = normalize(vec3(pxy, 1));&#xA;    return ray_dir;&#xA;}&#xA;&#xA;vec3 getRayDirection(in vec2 fragCoord, in vec3 resolution, in vec3 rotation){&#xA;    // Normalized pixel coordinates (from -1 to 1)&#xA;    vec3 ray_dir = calculateFragementRay(fragCoord, resolution);&#xA;    ray_dir = rotVecX(ray_dir, rotation.x);&#xA;    ray_dir = rotVecY(ray_dir, rotation.y);&#xA;&#xA;    return ray_dir;&#xA;}&#xA;&#xA;struct Ray{&#xA;    vec3 origin;&#xA;    vec3 direction;&#xA;};&#xA;&#xA;Ray getRay(in vec2 fragCoord, in vec3 resolution, in vec3 rotation, in vec3 origin){&#xA;    vec3 ray_dir = getRayDirection(fragCoord, resolution, rotation);&#xA;    vec3 ray_origin = origin;&#xA;    return Ray(ray_origin, ray_dir);&#xA;}&#xA;&#xA;struct RayMarchSettings{&#xA;    int max_steps;&#xA;    float max_distance;&#xA;    float min_distance;&#xA;    float depth_weight;&#xA;};&#xA;&#xA;struct Sphere{&#xA;    vec3 origin;&#xA;    float radius;&#xA;};&#xA;&#xA;float signedDistance(vec3 p, in Sphere sphere){&#xA;    return (length(p - sphere.origin) - sphere.radius);&#xA;}&#xA;&#xA;const int NULL_ID = -1;&#xA;const int SPHERE_ID = 0;&#xA;const int VSPHERE_ID = 1;&#xA;&#xA;Sphere test_sphere = Sphere(vec3(0.0, 4.0, 4.0),1.0);&#xA;Sphere volume_sphere = Sphere(vec3(0.0, 1.0, 0.0),2.0);&#xA;float signedDistance(vec3 ray_endpoint, out int obj_id){&#xA;    float d0 = signedDistance(ray_endpoint, test_sphere);&#xA;    float d1 = signedDistance(ray_endpoint, volume_sphere);&#xA;    float minval = min(d0, d1);&#xA;    obj_id = minval == d0 ? SPHERE_ID : VSPHERE_ID;&#xA;    return minval;&#xA;}&#xA;&#xA;bool rayMarch(Ray ray, in RayMarchSettings settings, in float rasterized_depth, out float out_depth, out int out_obj_id){&#xA;    float depth = 0.0;&#xA;    for( int i = 0; i &amp;lt; settings.max_steps; ++i){&#xA;        vec3 ray_endpoint = ray.origin + ray.direction * depth;&#xA;        int obj_id;&#xA;        float ray_distance = signedDistance(ray_endpoint, obj_id);&#xA;        depth += ray_distance * settings.depth_weight;&#xA;&#xA;        if( depth &amp;gt; rasterized_depth){&#xA;            break;&#xA;        }&#xA;        if(ray_distance &amp;lt;= settings.min_distance){&#xA;            out_depth = depth;&#xA;            out_obj_id = obj_id;&#xA;            return true;&#xA;        }&#xA;&#xA;        if(depth &amp;gt; settings.max_distance){&#xA;            break;&#xA;        }&#xA;    }&#xA;    out_depth = inf;&#xA;    out_obj_id = NULL_ID;&#xA;    return false;&#xA;}&#xA;&#xA;float checkerBoardTexture(in vec2 uv){&#xA;    vec2 q = floor(uv);&#xA;    return clamp(mod( q.x+q.y, 2.0 ), 0.25, 1.0);&#xA;}&#xA;float fogify(in float dist){&#xA;    return  1.0/ (1.0 + dist*dist * 0.1);&#xA;}&#xA;&#xA;RayMarchSettings rm_settings = RayMarchSettings(128, 100000.0, 0.0001, 0.5);&#xA;&#xA;void main()&#xA;{&#xA;&#xA;    vec3 origin = vec3(u_origin.x, u_origin.y, u_origin.z);&#xA;    origin = origin.zyx;&#xA;    Ray ray = getRay(TexCoords, u_resolution, u_rotation, origin);&#xA;    vec3 texture_color = texture(u_screen_texture, TexCoords).rgb;&#xA;    float rasterized_depth = texture(u_depth_texture, TexCoords).r;&#xA;&#xA;    float depth = inf;&#xA;    int obj_id = NULL_ID;&#xA;&#xA;&#xA;    vec3 color;&#xA;    if(rayMarch(ray, rm_settings,rasterized_depth,  depth, obj_id)){&#xA;        vec3 endpoint = ray.origin + ray.direction * depth;&#xA;        float pattern_value = checkerBoardTexture(endpoint.xz * 4.0);&#xA;&#xA;        if(obj_id == SPHERE_ID){&#xA;            color = vec3(1.0)*pattern_value;&#xA;        }&#xA;        if(obj_id == VSPHERE_ID){&#xA;            color = vec3(0.0,  1.0, 0.0)*pattern_value;&#xA;        }&#xA;&#xA;        switch(obj_id){&#xA;            case SPHERE_ID:&#xA;            color = vec3(1.0)*pattern_value;&#xA;            break;&#xA;            case VSPHERE_ID:&#xA;            color = vec3(0.0,  1.0, 0.0)*pattern_value;&#xA;            break;&#xA;            default:&#xA;            color = vec3(1.0,0.0,1.0)*pattern_value;&#xA;        }&#xA;     }else{&#xA;        float re_rasterized_depth = rasterized_depth == inf ? 0.0 : rasterized_depth;&#xA;        color = texture_color +re_rasterized_depth/100.f;&#xA;     }&#xA;    FragColor = vec4(color, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The &lt;code&gt;u_depth_texture&lt;/code&gt; is where the depth comes from (and what &lt;code&gt;DepthColor&lt;/code&gt; corresponds to)  The &lt;code&gt;u_screen_texture&lt;/code&gt; is just a texture of the rasterization pass information (output of &lt;code&gt;FragColor&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;h1&gt;UPDATE:&lt;/h1&gt;&#xA;&lt;p&gt;So &lt;a href=&quot;https://computergraphics.stackexchange.com/a/7675/6530&quot;&gt;this answer&lt;/a&gt; outlined exactly my problem.  I had to make the following changes:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 getRotatedRayDirection(vec3 ray_dir, in vec3 rotation){&#xA;    // Normalized pixel coordinates (from -1 to 1)&#xA;    //vec3 ray_dir = calculateFragementRay(fragCoord, resolution);&#xA;    ray_dir = rotVecX(ray_dir, rotation.x);&#xA;    ray_dir = rotVecY(ray_dir, rotation.y);&#xA;    return ray_dir;&#xA;}&#xA;&#xA;struct Ray{&#xA;    vec3 origin;&#xA;    vec3 direction;&#xA;    float cosA;&#xA;};&#xA;&#xA;Ray getRay(in vec2 fragCoord, in vec3 resolution, in vec3 rotation, in vec3 origin){&#xA;&#xA;    vec3 ray_dir = calculateFragementRay(fragCoord, resolution);&#xA;    vec3 rot_ray_dir = getRotatedRayDirection(ray_dir, rotation);&#xA;    vec3 ray_origin = origin;&#xA;    float cosA = ray_dir.z; // a.z/length(a), already normalized so length(a) == 1.0. &#xA;    return Ray(ray_origin, rot_ray_dir, cosA);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Above I basically added cosA as a seperate value onto the ray, as suggested by the linked answer, with the appropriate code changes to avoid re-running &lt;code&gt;calculateFragmentRay&lt;/code&gt;.  However I needed to figure out which cosine corresponded to the one in thier picture, I knew it was a lateral dimension, it happened to be Z in this case, and I used the standard method of retrieving cosine from a normalized vector.&lt;/p&gt;&#xA;&lt;p&gt;After that I did exactly what the linked answer said and made the following change:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;if( (depth * ray.cosA) &amp;gt; rasterized_depth){&#xA;    break;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And here are the results! No depth artifacts!&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IptJC.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IptJC.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kIzIU.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kIzIU.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6530" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-05-31T04:27:42.973" Title="How to align Ray Marching on top of traditional 3D rasterization?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;glsl&gt;&lt;rasterizer&gt;&lt;raymarching&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7675" PostTypeId="2" ParentId="7674" CreationDate="2018-05-30T18:22:04.123" Score="4" Body="&lt;p&gt;The problem, I think, is that you are comparing two different kinds of depth values. For want of better terms, the rasterizer's depth buffer stores 'parallel' depth, whereas raymarching calculates 'true' depth - that is, the rasterizer stores the distance to the plane parallel to the view plane which contains the point, but the raymarcher calculates the &lt;em&gt;actual&lt;/em&gt; 3D distance from camera to point.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ad4zF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ad4zF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see from the picture, the relation should be $rasterDepth = rayDepth*cos(A)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So try this - in your &lt;code&gt;getRayDirection&lt;/code&gt; function, &lt;em&gt;before&lt;/em&gt; you do your view rotation, save your fragment ray's original normalized Z value somewhere, maybe an extra field in your Ray struct. Let's call it &lt;code&gt;cosA&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then in your &lt;code&gt;rayMarch&lt;/code&gt; function the relevant code will be&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if( depth * cosA &amp;gt; rasterized_depth){&#xA;        break;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Hopefully that should fix the problem.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-05-30T18:22:04.123" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7676" PostTypeId="1" CreationDate="2018-05-31T02:25:27.737" Score="5" ViewCount="655" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bY0Kq.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bY0Kq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HusjL.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HusjL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The wall on the left of the red ball is perfectly reflective wall. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first image there's a point light that lies on the plane of the reflective wall and in the second image, it's 0.01 units ahead of it. Due to the light being on the reflective wall, I think, I am getting black dots all over my image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to know why putting a light on the same plane as the wall causes black dots ?&lt;/p&gt;&#xA;" OwnerUserId="8799" LastActivityDate="2018-06-01T14:00:39.260" Title="Grainy image in my simple ray tracer" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7677" PostTypeId="2" ParentId="7676" CreationDate="2018-05-31T03:19:33.277" Score="8" Body="&lt;p&gt;It's likely due to shadow rays. When the light source is exactly on the plane of the wall, a shadow ray traced to it may or may not be found to intersect the wall before it reaches the light. The result will depend on arithmetic roundoff error, and may appear as random noise, or stripes or some other artifact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix it, you can either keep the light offset slightly from the plane, or set up the wall object not to cast shadows (assuming it doesn't need to in the scene).&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-05-31T03:19:33.277" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7678" PostTypeId="1" CreationDate="2018-05-31T05:55:14.650" Score="1" ViewCount="3083" Body="&lt;p&gt;For general fixed-point scaling problem, If I want to scale twice about a fixed point (x, y), I need to first translate the object so that fixed point coincides with the origin, then do the scaling and then translate the object back to its position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the books, the matrix operation for this is given as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;|1 0 x| |s 0 0| |1 0 -x|&#xA;|0 1 y|*|0 s 0|*|0 1 -y|&#xA;|0 0 1| |0 0 1| |0 0  1|&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and my doubt is, why in the first matrix, we have used x, y? Don't we need -x, -y since we already are at some fixed point x, y and we want to shift that point to 0,0 and so we probably need to translate back by x, y ?&lt;/p&gt;&#xA;" OwnerUserId="8802" LastActivityDate="2018-05-31T05:55:14.650" Title="General fixed-point scaling" Tags="&lt;transformations&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7679" PostTypeId="2" ParentId="7599" CreationDate="2018-05-31T10:56:45.740" Score="2" Body="&lt;p&gt;I'd like to add the approach that worked for me in this particular situation as an answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My &quot;cubemaps&quot; are small, face is only 10x10 pixels and because of that I was able to shove thousands of those cubemaps in one big 2D texture atlas. Faces were laid out sequentially and atlas offsets were computed in fragment shader on the fly.&lt;/p&gt;&#xA;" OwnerUserId="8541" LastActivityDate="2018-05-31T10:56:45.740" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7682" PostTypeId="2" ParentId="7599" CreationDate="2018-06-01T08:17:56.800" Score="1" Body="&lt;p&gt;I'll throw in another possibility. The Morgan Mcguire light fields probe paper uses a tetrahedron mapping to replace cube maps and claims a 4x bandwidth increase. Basically cubemaps are inefficient in the corners. They also used an atlas layout. Given that you faces are 10x10 though it might not make much of a difference in your case. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mcguire &quot;Real-Time Global Illumination using Precomputed Light Field Probes&quot; p.2 (fig. 2)&#xA;&lt;a href=&quot;http://research.nvidia.com/sites/default/files/pubs/2017-02_Real-Time-Global-Illumination/light-field-probes-final.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://research.nvidia.com/sites/default/files/pubs/2017-02_Real-Time-Global-Illumination/light-field-probes-final.pdf&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Original mapping comes from Cigolle p.9&#xA;&lt;a href=&quot;http://jcgt.org/published/0003/02/01/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://jcgt.org/published/0003/02/01/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-06-01T08:17:56.800" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7685" PostTypeId="1" CreationDate="2018-06-02T09:48:06.060" Score="2" ViewCount="216" Body="&lt;p&gt;I wrote a program that displays points expressed in 3D in a 2D canvas, using perspective projection. The aim is to display a cube. Each face of the cube is drawn by linearly interpolating the points that define it. My cube can be translated, scaled and rotated thanks to transformation matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the moment, my program is not paralelized at all and uses CPU to make the various computations (e.g. : projection of 3D points into the 2D canvas using perspective projection, matrices computations, product of a point by a matrix, drawing cube's faces with linear interpolation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a speed problem. I described it below :&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Linear interpolation as I wrote it, which never calculates duplicates, costs a lot of accesses to RAM. Applied to each face, it requires also a lot of computations.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;My cube's faces should be drawn thanks to a linear interpolation with a very very small step (e.g. : &lt;code&gt;0.001&lt;/code&gt;) to be beautiful. However, it's simply a utopia. It would require too many computations and accesses to RAM. My program would freeze.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A given transformation matrice is multiplied by point N°&lt;code&gt;1&lt;/code&gt;, then by N°&lt;code&gt;2&lt;/code&gt;, then by N°&lt;code&gt;k&lt;/code&gt;, then by N°&lt;code&gt;8&lt;/code&gt;. Obviously, the matrices are not multiplied by the interpolated points ! (it implies a gain in computation speed).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h1&gt;Questions&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Without using any API :&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Are GPU util to paralelize linear interpolations ? If I remember well my courses, yes. So : &lt;strong&gt;&lt;em&gt;how could I send my points and my linear interpolation function to GPU ?&lt;/em&gt;&lt;/strong&gt; Note that I would be disapointed if I must use linear interpolation program of the GPU (if it exists) instead of mine.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How could I draw beautiful cube's faces without using a linear interpolation's step of &lt;code&gt;0.001&lt;/code&gt; ?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Less important : is it possible to increase computation speed in making the product of a sequence of points with a matrice ?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="8709" LastActivityDate="2018-06-02T09:48:06.060" Title="Using GPU instead of CPU in Scala" Tags="&lt;gpu&gt;&lt;performance&gt;&lt;perspective&gt;&lt;interpolation&gt;&lt;gpgpu&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7686" PostTypeId="1" AcceptedAnswerId="7688" CreationDate="2018-06-03T09:21:53.640" Score="1" ViewCount="45" Body="&lt;p&gt;I ran into this problem while trying to find the paint color of the doors in my house: is it in principe possible to automatically determine the paint color from a photo?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Different types of colour standards (such as RAL, &lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_RAL_colors&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/List_of_RAL_colors&lt;/a&gt;) mention RGB values, but of course lighting conditions, material, camera and probably other factors highly affect the RGB value that is measured.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does a solution to this problem already exist?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An idea I had is to hold an official color reference chart in the photo next to the target object (e.g. my door), so the transformation due to lighting conditions and camera between the known RGB values of the colors on the reference chart and those in the photo could somehow be established. Then the inverse transformation could be applied to the color of the target object and the closest matching paint color could be found.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could this idea work and if so, what kind of transformation between reference and measurement could be expected?&lt;/p&gt;&#xA;" OwnerUserId="8823" LastActivityDate="2018-06-03T17:03:06.140" Title="Determine paint color from a photo" Tags="&lt;color&gt;&lt;color-science&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7687" PostTypeId="1" AcceptedAnswerId="7691" CreationDate="2018-06-03T16:09:25.213" Score="8" ViewCount="7599" Body="&lt;p&gt;I have read the OpenGl documentation of texelFetch, which is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;gvec4 texelFetch(gsampler2D sampler, ivec2 P, int lod).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know the first argument &quot;sampler&quot; is just a texture. But I am very confused about the second and third arguments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to the documentation, the second argument &quot;P&quot; is a texture coordinate. But it has the type ivec2, which means that it is a vector of integers. Shouldn't a texture coordinate be in the range [0, 1]? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And for the third argument &quot;lod&quot;, in the documentation, it said &quot;If present, specifies the level-of-detail within the texture from which the texel will be fetched.&quot; I have no idea how to set this argument...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone explain this and give a real example of how to use texelFetch?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="8826" LastActivityDate="2018-06-05T15:06:35.423" Title="How to use GLSL texelFetch?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7688" PostTypeId="2" ParentId="7686" CreationDate="2018-06-03T17:03:06.140" Score="1" Body="&lt;p&gt;In theory yes, but practically speaking, I doubt it would be very easy. First, the color may not be representable by the color space that your camera of choice produces images in. We've recently started seeing wide color gamut (P3) cameras and displays. There are colors these cameras record and displays produce that fall outside of the sRGB color space that most cameras and displays support. Likewise, there are visible colors that are outside of the P3 color space. So the first hurdle is to have a device which records and stores the colors you're dealing with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next you have to do the lighting correction once you get the image into the computer. This is actually not as hard as it sounds. There are products that allow you to do this using a system similar to what you describe. &lt;a href=&quot;https://www.youtube.com/watch?v=1fcve4Dp1lo&amp;amp;feature=youtu.be&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here's a video&lt;/a&gt; for one that works with video rather than stills.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you've done all that, you need some way of translating that color from some RGB space into something that your local paint store can understand. I'm not sure how to do that. Most paint store employees are not trained in color science and have to use a limited toolset provided by the paint companies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way you could get a small, inconspicuous piece of the actual object? Most paint stores have a machine that will take a physical object and create a paint that's a fairly close match to that object. Whether their matches are close enough for your needs is something you'd have to determine. I've used them before and found that while they get very close, I'm still able to see the difference between the original and the new paint, unless I can paint up to corners.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-06-03T17:03:06.140" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7690" PostTypeId="1" CreationDate="2018-06-04T11:19:30.360" Score="2" ViewCount="49" Body="&lt;p&gt;I'm trying to show a 3D model on Facebook and display its edges and lines. I found that I could export a 3D model from Sketchup using glTF Export plugin to a glb file that I can drag and drop in a Facebook post.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried many ways to set material, width, styles on lines in my model but once imported in Facebook the lines don't appear. It's not a Facebook problem since the gtTF viewer has the same display. I also have the same rendering problem by ubloading an stl file to &lt;a href=&quot;https://sketchfab.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sketchfab&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Is there a missing implementation in glTF format?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Is there another freeware to export a 3D model to Facebook (showing edges)?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XfWql.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XfWql.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8831" LastActivityDate="2018-06-05T19:47:48.483" Title="How to display edges in a 3D file on Facebook" Tags="&lt;rendering&gt;&lt;3d&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7691" PostTypeId="2" ParentId="7687" CreationDate="2018-06-04T16:53:46.333" Score="13" Body="&lt;p&gt;OK, I have figured out this problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the texture coordinates, there are two kind of texture coordinates. One is normalized texture coordinates, which is in the range [0, 1]. The other is texel space, which is in the range [0, size), where size is the size of the texture. For texelFetch(), the texel space is used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For &lt;code&gt;lod&lt;/code&gt;, it means the level of detail in the mipmap. We can simply use 0 for the base level (the original size).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, an example of using &lt;code&gt;texelFetch()&lt;/code&gt; should be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 texelValue= texelFetch(texture2D, ivec2(gl_FragCoord.xy), 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8826" LastEditorUserId="8826" LastEditDate="2018-06-05T15:06:35.423" LastActivityDate="2018-06-05T15:06:35.423" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7692" PostTypeId="1" CreationDate="2018-06-05T08:15:49.853" Score="1" ViewCount="58" Body="&lt;p&gt;MIS weights for BDPT are calculated with ratios of PDFs for each vertex under different types of light transport (radiance vs. importance). These probabilities are regenerated for frontier vertices during subpath connection, which makes sense - the direction from the $t-1$-th camera vertex to the $s-1$-th light vertex will be different to the direction between the $t-1$-th and $t$th camera vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PBRT also reccomends updating reverse probabilities for &lt;em&gt;previous&lt;/em&gt; vertices, though. Why? The probability of tracing a ray from $s-1$ to $s-2$ won't be affected by the probability of tracing a ray between $s-1$ and $t-1$.&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-06-05T08:15:49.853" Title="Reverse PDF updates for s-2 or t-2 vertices in MIS for BDPT" Tags="&lt;pathtracing&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7693" PostTypeId="2" ParentId="7690" CreationDate="2018-06-05T19:42:45.167" Score="1" Body="&lt;p&gt;3D graphics are not images they are instructions for images. Now the formats that export data beween systems work on lowest common denominator. Geometry is fine, but any effects on top of geometry would require you to agree on a set of instructions to implement. (no such reffort has been made for npr rendering lines).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The lines are not really part of the model that has been exported trough the gltf pipeline. Simply because the line rendering is a special feature of the sketchup system. There is no generic format that support those, since they need to be generated frame by frame. And there is &#xA;quite possibly a infinite number of such features that could be implemented, none of these are part of the generally accepted set of things to export.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most likely your out of luck the engine in question simply has no way to do this. So there is no solution for your problem. STL is a even more rudimentary format it only has triangles nothing else.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: This is why it is called an export not save. Although many applications have gone so far as to call even partial implementations save. But you can not just expect all things to go from application to application, especially in 3D&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2018-06-05T19:47:48.483" LastActivityDate="2018-06-05T19:47:48.483" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7694" PostTypeId="1" AcceptedAnswerId="7699" CreationDate="2018-06-06T04:23:28.783" Score="8" ViewCount="576" Body="&lt;p&gt;I'm currently trying to create an amateur game engine, and I often run into very basic bugs (eg I change the node hierarchy code and suddenly nothing is displayed). Some of the methods I will use include to track down these bugs include:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Use my IDE's debugger and lots of &lt;code&gt;printf&lt;/code&gt; calls to look at what's in memory.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Make lots of tests with different parameters, placing the camera in different positions, to get a better feel of what the code is doing.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Just brute force my way through by re-reading each line of code until I find the one that's misbehaving.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;These methods all seem sluggish and inefficient to me. The problem is, that 3D rendering involves a lot of unintuitive operations with not much to visualize except the final &quot;product&quot;; when I'm running into a bug (especially &quot;nothing is displayed&quot; types of bugs), I often feel like I'm fumbling around blindly.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;So.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say you're a developer working on Unity, Godot, or some other 3D engine, and you just changed some steps in your rendering pipeline, and now, for whatever reason, the wireframe renderer displays incoherent results when entity batching is activated. The &quot;wires&quot; are crisscrossing all over the screen instead of representing the edges of the batched entity's triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do you track down and fix that bug? Do you have a specific workflow? Do you use some kind of GPU analysis tool? Or do you just fumble around blindly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, &lt;strong&gt;what methods, tools and best practices can engine developers&lt;/strong&gt; (not engine users) &lt;strong&gt;use to analyze the data and behavior&lt;/strong&gt; of their 3D graphics code (not just its performance) to efficiently address defects and bugs?&lt;/p&gt;&#xA;" OwnerUserId="8660" LastActivityDate="2018-06-07T21:37:49.843" Title="How do graphic engine developers debug their 3D graphics code?" Tags="&lt;3d&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7695" PostTypeId="2" ParentId="7694" CreationDate="2018-06-06T06:11:15.680" Score="4" Body="&lt;p&gt;I usually prefer &lt;a href=&quot;https://renderdoc.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;RenderDoc&lt;/a&gt; to debug a frame. Gives you enough information on particular frame was rendered right from Vertex to Pixel. There are other equally useful tools available like &lt;a href=&quot;http://www.nvidia.com/object/nsight.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nvidia Nsight&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, there is always color coding which can be useful when debugging shaders visually. Decomposing shader outputs into separate colors can be of help too. Not sure though if your case requires this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2018-06-06T06:11:15.680" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7697" PostTypeId="1" CreationDate="2018-06-06T13:59:59.287" Score="1" ViewCount="133" Body="&lt;p&gt;How is the solid angle subtended by a pixel calculated?&#xA;both in perspective and fish eye lens.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2018-06-06T13:59:59.287" Title="How to calculate solid angle subtended by a pixel?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7698" PostTypeId="1" AcceptedAnswerId="7700" CreationDate="2018-06-06T21:45:06.157" Score="2" ViewCount="62" Body="&lt;p&gt;I have been working with a &lt;a href=&quot;https://astrogeology.usgs.gov/search/map/Moon/LRO/LOLA/Lunar_LRO_LOLA_Global_LDEM_118m_Mar2014&quot; rel=&quot;nofollow noreferrer&quot;&gt;file from the USGS&lt;/a&gt; that is a heightmap of the Moon. I resized it to 65536 x 32768 px for use as a displacement map in Blender, and turned it into tiles. Then I created tiles from the original image and noticed that they were about a fifth of the file size of the ones from the resized image, even though they have twice the pixels. Image Magick had remapped the image using many tones of gray that weren't present in the original. Presumably this is why the files are now so much bigger.&lt;/p&gt;&#xA;&lt;p&gt;Original histogram:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/pkN30.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pkN30.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Resized histogram:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/eYqMu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eYqMu.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Is there any way I can resize this image without the process creating new gray tones?&lt;/p&gt;&#xA;" OwnerUserId="8841" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-06-07T01:58:43.927" Title="Is there a way to resize an image without creating new colors in the output image?" Tags="&lt;color-management&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7699" PostTypeId="2" ParentId="7694" CreationDate="2018-06-06T22:31:20.360" Score="6" Body="&lt;p&gt;I'm programming mostly in OpenGL. In this case, the very first thing I do is setting up &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_debug.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;KHR_debug&lt;/a&gt; extension. It provides a way to subscribe to messages generated by GL drivers - from errors to warnings to detailed information about what the driver is doing. Especially open source Linux drivers (Mesa) generate lots of useful messages.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it comes to tools, my first choice is usually ApiTrace. It allows you record a trace of all rendering API calls and then replay it and inspect state at any point in time (this includes contents of buffers, render targets, etc.). It also allows you to share a trace with other people, which is useful when working in a team. Then, there are other tools such as RenderDoc, NVIDIA Tegra Graphics Debugger, Xcode's graphics debugger and some others. Whichever you chose, it will improve your work a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another thing is testing. One thing is building a collection of simple scenes excercising single feature of the engine (such as different material settings, different animation techniques, etc.).&#xA;When a bug is introduced into the codebase, this helps debugging it (since you have simple to analyse test cases readily available) and verifying that a fix doesn't accidentally break something else. I guess it's quite common thing to do; Unity3D developers do it, for example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could extend this and automate it by creating test harness, which would build and run all test on regular basis, and verify that no regressions happened. If you have lots of test scenarios, this might be feasible, although obviously requires additional investments into infrastructure. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there are more &quot;standard&quot; unit tests. One area I've applied them is node-based material system, which can target different rendering techniques (forward, deferred, whatever) and APIs. I approached it by writing unit tests which generate shader code from material and other settings, compiler it and issues a simple draw calls with given inputs (pixel shader inputs). Outputs are written to a render target and fetched for comparison with expected values. IMHO this is a nice  thing to do when you have complex material system, esp. with shader code generation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, more &quot;traditional&quot; approaches can be applied to areas which can be separated from rendering. Things like spatial data structures, asset loading and similar can be unit/integration tested, as applicable in specific case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; &lt;a href=&quot;https://aras-p.info/blog/2011/06/17/testing-graphics-code-4-years-later/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here's a post&lt;/a&gt; from Unity3D developer describing how they test graphics code.&lt;/p&gt;&#xA;" OwnerUserId="8796" LastEditorUserId="8796" LastEditDate="2018-06-07T21:37:49.843" LastActivityDate="2018-06-07T21:37:49.843" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7700" PostTypeId="2" ParentId="7698" CreationDate="2018-06-07T01:58:43.927" Score="2" Body="&lt;p&gt;A nearest-neighbor resize will do what you ask but I am not certain it will give you much smaller tiles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is quite likely that the tiles made from the original image are smaller simply because they have less high frequency content and thus compress far better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can look at it the other way around: there are more terrain features in the tiles of the resized image so it takes more space to store them. That's a very gross simplification of the truth, of course. And it assumes a reasonably efficient compression algorithm.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-06-07T01:58:43.927" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7701" PostTypeId="2" ParentId="7694" CreationDate="2018-06-07T03:18:03.480" Score="4" Body="&lt;p&gt;I work mainly on macOS where the OpenGL tools are almost non-existent. (I'm starting to get into Metal where the tools are better.) So I feel your pain. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first thing I do is make frequent, small commits of my code to source control. This isn't always possible, but usually it is. If that could disrupt others, work on a branch. That way, if something goes horribly wrong, I can do a quick diff of the current code against HEAD or trunk, and isolate the problem to only the code in the diffs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next thing I do is try to analyze what the problem is. In your example, where geometry that was previously working is suddenly drawing the wrong shapes, I'd think about the situations that can cause that:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Sending a bogus pointer to &lt;code&gt;glBufferData()&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;Starting on the wrong byte of my buffer by setting an attribute pointer/offset incorrectly&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;There are numerous causes of general symptoms like the dreaded black screen. There are a number of techniques that are the graphics equivalent of &lt;code&gt;printf()&lt;/code&gt;. I start breaking down what's working and what's not. I start with really broad strokes. Is my drawing going to the right FBO? Set the clear color of the FBO to something garish like RGB=(1, 0.5, 0) or (0, 1, 1) and see if the screen turns orange or magenta. You might pick a different debug color for each FBO you normally use so you can tell at a glance which is going to screen on a given render. If that works, I check things like clipping planes - have I clipped all the geometry out? Check lighting - do I have lights on? Am I sending the correct lighting info to the shaders? Are textures correct? It can help to have some test textures with things like grids on them, or if you're dealing with cube maps, textures with face names on them. If you have shader issues, you can do things like simply output the texture coordinates as red and green (and blue if it's a 3D texture) at each point to make sure they're valid. Same with normals - normalize them and output the &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;, and &lt;code&gt;z&lt;/code&gt; in the &lt;code&gt;r&lt;/code&gt;, &lt;code&gt;g&lt;/code&gt;, and &lt;code&gt;b&lt;/code&gt; channels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you do more of this you'll learn tricks like these for displaying the data and verifying your assumptions. Being able to roll back quickly and easily is enormously helpful. And of course, don't forget about &lt;code&gt;glGetError()&lt;/code&gt;. The small numbers of errors it returns is frustrating, but it can often point you in the direction of where a problem is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you can get a tool that shows you what's different from the default OpenGL state, it can also direct where to spend your effort. On macOS there's OpenGL Profiler. You can set a breakpoint on any OpenGL function and examine the entire state machine. It will highlight differences from the defaults, or differences from the last time it stopped, or both.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-06-07T03:18:03.480" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7703" PostTypeId="1" CreationDate="2018-06-08T13:50:10.783" Score="3" ViewCount="69" Body="&lt;p&gt;&lt;strong&gt;NB please :&lt;/strong&gt; executable use cases are available at the end of this question. I begin this question by showing you the problems of my program, then I explain how the latter works, and finally I end up with these both executable use cases.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;What I want to do&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I want to draw the bottom face of a cube. To do that, I interpolate between the 4 vertices of this face. I use two kinds of interpolation :&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Linear&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Cosine&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;I know it's typically the aim of GPUs, but I wanted to implement it myself to learn and try the &quot;deep&quot; mechanisms of 3D rendering.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Results&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Each point of the following both pictures are interpolated between the 4 vertices of the bottom face (except the 8 vertices of my cube).&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;With linear interpolation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;It's OK, no problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/R5ovV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/R5ovV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;With cosine interpolation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Error. As you can see, there is some weird problem : face's points are inclined towards left.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2B5SW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2B5SW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;How do I interpolate between 4 points ?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I test all the combinations of interpolation's weights and, if the sum of the weights equals 1, I draw the resulting point. &lt;em&gt;I know this method is not very good (a lot of consumption of CPU and RAM), and there are &lt;code&gt;P&lt;/code&gt; duplicates. But this problem is (1) secondary and (2) out of the range of this StackOverflow question.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words : the definition of the interpolation between 4 points is : &lt;code&gt;P = aA + bB + cC + dD&lt;/code&gt;. &lt;code&gt;a + b + c + d&lt;/code&gt; must equals 1 to draw &lt;code&gt;P&lt;/code&gt;, otherwise it's not drawn. &lt;code&gt;(a;b;c;d) \in [0;1]^4&lt;/code&gt; by the way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A concrete example is (step = 1) :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;P = 0a + 0b + 0c + 0d&lt;/code&gt; is NOT drawn&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;P = 0a + 0b + 0c + 1d&lt;/code&gt; is drawn&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;P = 0a + 0b + 1c + 0d&lt;/code&gt; is drawn&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;P = 0a + 0b + 1c + 1d&lt;/code&gt; is NOT drawn&lt;/p&gt;&#xA;&#xA;&lt;p&gt;etc. (&quot;I test all the combinations&quot;). (Last is : &lt;code&gt;P = 1a + 1b + 1c + 1d&lt;/code&gt;, which is not drawn).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To test all these combinations, I iterates on the weights, with a step, using recursion.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Case of the linear interpolation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The above definition doesn't change : &lt;code&gt;P = aA + bB + cC + dD&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Case of the cosine interpolation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The above definition does change : &lt;code&gt;P = aA + bB + cC + dD&lt;/code&gt; becomes &lt;code&gt;P = a'A + b'B + c'C + d'D&lt;/code&gt;, with : &lt;code&gt;a' = 0.5(1 - cos(a * \pi))&lt;/code&gt; and the idea is the same for the three other weights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;This new definition is not random, I could explain how I found it, but it's out of the range of this topic (in résumé : a simple remap of the cosine function).&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Question&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Why does it works well with the linear interpolation, and not the cosine one ? Indeed, the cosine face's points are inclined towards left.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;By the way : interpolations between two points work well&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Linear and cosine interpolations both work very well when used between two points, as you can see below.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Linear interpolation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;It's OK, no problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oq5As.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oq5As.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Cosine interpolation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;It's OK, no problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rZiyL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rZiyL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Implementation and Executable&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;I wrote the program in Scala. First I show you the functions, then two use cases you can execute along with the given functions.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Tests all the combinations of interpolations between &lt;code&gt;n&lt;/code&gt; points of &lt;code&gt;k&lt;/code&gt; coordinates&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def computeAllPossibleInterpolatedPoints(step : Double, points : Seq[Seq[Double]], transform: (Double) =&amp;gt; Double) : Seq[Seq[Double]] = {&#xA;  var returned_object : Seq[Seq[Double]] = Seq.empty[Seq[Double]]&#xA;  recursiveInterpolation(0, Seq.empty[Double])&#xA;&#xA;  def recursiveInterpolation(current_weight_id : Int, building_weights : Seq[Double]) : Unit = {&#xA;&#xA;    (.0 to 1.0 by step).foreach(current_step =&amp;gt; {&#xA;      if (current_weight_id &amp;lt; points.size - 1) {&#xA;        recursiveInterpolation(current_weight_id + 1, building_weights :+ current_step)&#xA;      } else {&#xA;        val found_solution = building_weights :+ current_step&#xA;        if(BigDecimal(found_solution.sum).setScale(5, BigDecimal.RoundingMode.HALF_UP).toDouble == 1.0) {&#xA;          returned_object = returned_object :+ interpolation(found_solution, points, transform)&#xA;        }&#xA;      }&#xA;    })&#xA;  }&#xA;&#xA;  returned_object&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Interpolates between &lt;code&gt;n&lt;/code&gt; points of &lt;code&gt;k&lt;/code&gt; coordinates&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def interpolation(weights: Seq[Double], points: Seq[Seq[Double]], transform: (Double) =&amp;gt; Double) : Seq[Double] = {&#xA;  if(BigDecimal(weights.sum).setScale(5, BigDecimal.RoundingMode.HALF_UP).toDouble != 1) {&#xA;    println(&quot;ERROR : `SUM(weights) != 1`. Returning `null`.&quot;)&#xA;    return null&#xA;  }&#xA;  if(weights.exists(weight =&amp;gt; BigDecimal(weight).setScale(5, BigDecimal.RoundingMode.HALF_UP).toDouble &amp;lt; 0)&#xA;    ||&#xA;    weights.exists(weight =&amp;gt; BigDecimal(weight).setScale(5, BigDecimal.RoundingMode.HALF_UP).toDouble &amp;gt; 1)) {&#xA;    println(&quot;ERROR : `EXISTS(weight) / weight &amp;lt; -1 OR weight &amp;gt; 1`. Returning `null`.&quot;)&#xA;    return null&#xA;  }&#xA;&#xA;  weights.map(transform).zip(points).map(&#xA;    weight_point =&amp;gt; weight_point._2.map(coordinate =&amp;gt; weight_point._1 * coordinate)&#xA;  ).reduce((point_a : Seq[Double], point_b : Seq[Double]) =&amp;gt; point_a.zip(point_b).map(coordinate_points =&amp;gt; coordinate_points._1 + coordinate_points._2))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Interpolation functions&lt;/h2&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def linear(weight : Double) : Double = {&#xA;  weight&#xA;}&#xA;&#xA;def cosine(weight : Double) : Double = {&#xA;  (1 - Math.cos(weight * Math.PI)) * 0.5&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h2&gt;Two use cases : between 2 points, each made of 2 coordinates (first use case : linear interpolation, second use case : cosine interpolation)&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Note that you can add 2 new points to each of the following functions, to interpolate a face instead of a segment (for now, the below code indeed interpolates points of a segment).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;val interpolated_points : Seq[Seq[Int]] = interpolator.computeAllPossibleInterpolatedPoints(0.05, Seq(Seq(22, 22), Seq(33, 33)), interpolator.linear).map(_.map(_.intValue()))&#xA;&#xA;val interpolated_points : Seq[Seq[Int]] = interpolator.computeAllPossibleInterpolatedPoints(0.05, Seq(Seq(22, 22), Seq(33, 33)), interpolator.cosine).map(_.map(_.intValue()))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8709" LastEditorUserId="8709" LastEditDate="2018-06-08T16:29:21.603" LastActivityDate="2018-06-13T08:06:25.597" Title="Why my cosine interpolation of a cube's face doesn't work?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;interpolation&gt;&lt;drawing&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7704" PostTypeId="1" AcceptedAnswerId="7706" CreationDate="2018-06-10T12:28:41.437" Score="3" ViewCount="617" Body="&lt;p&gt;I was going through the &lt;a href=&quot;http://in1weekend.blogspot.com/2016/01/ray-tracing-in-one-weekend.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;raytracer in a weekend&lt;/a&gt; book by Peter Shirley and the subsequent book &lt;a href=&quot;http://in1weekend.blogspot.com/2016/01/ray-tracing-second-weekend.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;raytracing the next week&lt;/a&gt; and I couldn't make out what was the illumination model that was being used here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;all the previous raytracing samples that I have come across use the Phong shading model in which&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For a diffuse surface, a shadow ray is generated towards all the light sources and the final color is calculated based on the diffuse color and the non-occluded light intensities&lt;/li&gt;&#xA;&lt;li&gt;For reflective materials and dielectrics, reflective and refractive rays are generated which are then recursively projected into the scene&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The method used in the book (very briefly) is as follows (Please do correct me if my understanding is wrong in any way)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;For diffuse objects, a ray is traced recursively in a random direction biased towards the normal at the hitpoint and the color from the resulting ray is multiplied with the current object's albedo to give the final color&lt;/li&gt;&#xA;&lt;li&gt;For reflective and dielectrics, rays are cast using the law of reflection and the Snell's law respectively. &lt;/li&gt;&#xA;&lt;li&gt;Lights also scatter rays and also add their emitted parts.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The major differences I see in this approach are&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;We do not directly sample the light sources.&lt;/li&gt;&#xA;&lt;li&gt;Diffuse items also reflect rays (for inter-diffuse reflections)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What exactly is the illumination model used in this approach? and why does this approach seem so simple and yet produces pretty good results?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry if I missed something, I am relatively new to raytracing&lt;/p&gt;&#xA;" OwnerUserId="5098" LastActivityDate="2018-06-14T23:12:34.117" Title="Illumination model used in the &quot;Raytracer in a weekend&quot; series" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7705" PostTypeId="1" AcceptedAnswerId="7724" CreationDate="2018-06-10T15:39:11.013" Score="4" ViewCount="131" Body="&lt;p&gt;So I was reading this paper by Lafortune, &quot;Mathematical Models and Monte Carlo algorithms&quot; and in it he writes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have a function or integrand I we want to estimate given as,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$I = \int f(x) dx$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We then have a primary estimator for this as,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hat{I_p} = f(\xi)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where $\xi$ is a random number generated in the interval of the integrand $I$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The secondary estimator is defined as,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hat{I_{sec}} = \frac{1}{N} \sum f(\xi_i)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there is an explanation that goes to show how the expected value of the secondary estimator is equal to the function/integrand I. i.e,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$E(\hat{I_{sec}}) = I$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All fair. The problem comes when he tries to find the variance of this secondary estimator as follows. Im posting a screenshot of the paper here since it's getting a little complex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/56MPu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/56MPu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand how did step 2 follow from step 1 of Equation 3.5 in the variance calculation. Note that he has assumed $PDF = 1$ for now&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was trying to calculate the variance using a more standard approach and ignoring the multiple integrals. We know the variance of an estimator $\hat{\theta}$ is given as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Var(\hat{\theta}) = E[(\hat{\theta} - E(\hat{\theta}))^2]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we apply this to above we get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Var(\hat{I_{sec}}) =  E[(\hat{I_{sec}} - E(\hat{I_{sec}}))^2] $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[(\hat{I_{sec}} - I)^2]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[(\hat{I_{sec}})^2 - 2* I *(\hat{I_{sec}}) + I^2 ] $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[(\hat{I_{sec}})^2] - 2* I *E[\hat{I_{sec}}] + I^2 $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[(\hat{I_{sec}})^2] - 2* I^2 + I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[(\hat{I_{sec}})^2] - I^2 $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[(\frac{1}{N} \sum\limits_{i=1}^{N} f(\xi_i))^2] - I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I am stuck here, I could do this,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = E[\frac{1}{N^2} \sum\limits_{i=1}^{N} f^2(\xi_i) + \frac{1}{N^2}\sum\limits_{i\neq j}^{N} f(\xi_i) f(\xi_j) ] - I^2  \hspace{10mm} \because &#xA;[\sum\limits_{i=1}^{N} f(x_i) ]^2 =  \sum\limits_{i=1}^{N} f^2(x_i) + \sum\limits_{i\neq j}^{N} f(\xi_i) f(\xi_j)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = \frac{1}{N^2} \sum\limits_{i=1}^{N} E[f^2(\xi_i)] + \frac{1}{N^2}\sum\limits_{i\neq j}^{N} E[f(\xi_i) f(\xi_j) ] - I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = \frac{1}{N^2} \sum\limits_{i=1}^{N} \int f^2(x)dx + \frac{1}{N^2}\sum\limits_{i\neq j}^{N} E[f(\xi_i) f(\xi_j) ] - I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm} \because E[f(X)] = \int f(X) p(X) dx$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note $p(X) = 1$,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\hspace{20mm}      = \frac{1}{N} \int f^2(x)dx + \frac{1}{N^2}\sum\limits_{i\neq j}^{N} E[f(\xi_i) f(\xi_j) ] - I^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't know what to do next from here, any tips? Or did I do something wrong?&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-06-18T00:47:56.717" Title="Variance of estimator (Monte Carlo Integration)" Tags="&lt;monte-carlo&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7706" PostTypeId="2" ParentId="7704" CreationDate="2018-06-10T16:13:34.033" Score="3" Body="&lt;p&gt;It’s a “naive” Monte Carlo sampler so it’s too dumb to send rays toward lights— it shotguns.   But the light is just a hemisphere (like a cloudy day) so you don’t get punished with too much noise.   Cloudy days look pretty good in real life.   But if you try to add a small light it will work but get very very noisy.   The third book in that series uses one method to address this (basically sending more rate where lights are rather than shadow rays per se)&lt;/p&gt;&#xA;" OwnerUserId="6422" LastActivityDate="2018-06-10T16:13:34.033" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7707" PostTypeId="1" CreationDate="2018-06-10T20:02:25.870" Score="2" ViewCount="331" Body="&lt;p&gt;Consider this course : &lt;a href=&quot;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/procedural-patterns-noise-part-1/creating-simple-2D-noise&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/procedural-patterns-noise-part-1/creating-simple-2D-noise&lt;/a&gt; . In sub-part &lt;strong&gt;Introducing the Concept of Permutation&lt;/strong&gt; (use CTRL||CMD + F), the author explains Ken Perlin uses the array containing noise values to be interpolated (denoted A) in conjunction with another array, which is the &quot;permutation hash table&quot; (denoted B).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is : from any input (a point), we get its unique noise value in A, using B. A has always 256 cases (whatever the input point's dimension is) : it allows to gain in RAM consumption. B has 512 cases : the 255 first randomly contain numbers from {0...255}, idem for the last half part of B.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;How to use the permutation table, according to ScratchAPixel ?&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;There are 2 things I didn't understand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;First, (1/2) I didn't understand how the hash table is actually used.&lt;/strong&gt; The workflow I think I understood is the following :&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;For an input (coordinate), we find the both nearest pre-defined coordinates (i.e. : those present as indices in A). It's a multiple of 255.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The lower one is used to lookup in B&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;We get a number between [0;255] that we use to lookup in A &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;We get a number between [0;1] : the noise.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;But where is the interpolation between the both pre-defined coordinates' noise values ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In which way my understanding is wrong ? I believe you should really read this sub-part (&lt;strong&gt;Introducing the Concept of Permutation&lt;/strong&gt; (use CTRL||CMD + F), &lt;a href=&quot;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/procedural-patterns-noise-part-1/creating-simple-2D-noise&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/procedural-patterns-noise-part-1/creating-simple-2D-noise&lt;/a&gt;), it's very short and maybe your answer would fit my question more than if you were giving me explanations that possibly would be out of the range of those provided by ScratchAPixel. Thus, I would understand your answer better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way, &lt;strong&gt;(2/2) I didn't understand this paragraph neither&lt;/strong&gt; :&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;You may wonder why the permutation array is twice the size of the function period (512 in size instead of 256). If we deal with a 2D noise, we will first do a lookup in the permutation table using the integer value for the x coordinate of our input point (as described). This will return an integer value in the range [0:255]. We will add the result of this lookup to the integer value for the input point y coordinate and use the sum of these two numbers as an index of the permutation table again. Since the result of the first permutation lookup is in the range [0:255] and that the integer value for the point's y coordinate is also in the range [0:255], it means that the range of possible index value for the permutation table is [0:511]. Hence the size of the permutation array (512). &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm getting confused by all the different but likely terms (&quot;integer value&quot;, &quot;coordinate&quot;, ...).&lt;/p&gt;&#xA;" OwnerUserId="8709" LastActivityDate="2018-07-30T00:59:17.243" Title="ScratchAPixel : Understanding how to use Perlin's permutations hash table" Tags="&lt;interpolation&gt;&lt;noise&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7708" PostTypeId="1" AcceptedAnswerId="7709" CreationDate="2018-06-11T08:53:59.417" Score="4" ViewCount="549" Body="&lt;p&gt;When a simulating a camera, I may run into the situation that a black elliptic border is needed (rather than a rectangular image).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/E09UT.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/E09UT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case I have the option to discard the fragment in the fragment shader or draw it with a black color. Discarding obviously needs branching, so now I am not sure which option is faster. Generally I assume avoiding branching in shaders is the way to go, but does that hold true for discarding, especially if the branch contains only one call (the discard one)? Or is there no rule of thumb for this case at all and just benchmarking is the way to go?&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-06-11T09:13:04.763" Title="Is a branched discard to be avoided" Tags="&lt;glsl&gt;&lt;optimization&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7709" PostTypeId="2" ParentId="7708" CreationDate="2018-06-11T09:13:04.763" Score="7" Body="&lt;p&gt;You can use a stencil instead, This allows the gpu to do an early out test before the fragment shader even starts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You only have to build the stencil once (possibly with a discard in a simple shader) and you can reuse the stencil in future draws.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-06-11T09:13:04.763" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7711" PostTypeId="2" ParentId="7705" CreationDate="2018-06-13T08:00:33.657" Score="1" Body="&lt;p&gt;Quoting from &quot;Advanced global illumination&quot; book:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8ovuh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8ovuh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Monte Carlo estimator is defined as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KSMPl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KSMPl.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And its variance according to the above definition(continuous random variable) would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UhgvP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UhgvP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example for how the variance of an estimator G is calculated:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(note how the summation is written as N times the integrand and is cancelled out later.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eLSml.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eLSml.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2018-06-13T15:54:42.260" LastActivityDate="2018-06-13T15:54:42.260" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7714" PostTypeId="2" ParentId="7494" CreationDate="2018-06-13T17:50:38.483" Score="0" Body="&lt;p&gt;If you’re comfortable working in Metal, there’s a brand-new shader debugger which does exactly what you’re after—it’ll let you step through your code while showing the values of your variables, as well as edit the code and re-run it. It’s in the Xcode 10 beta; there’s a presentation about how to use it available &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2018/608/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-06-13T17:50:38.483" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7716" PostTypeId="1" CreationDate="2018-06-14T17:16:47.073" Score="4" ViewCount="518" Body="&lt;p&gt;I'm implementing the marching cubes, reference is &lt;a href=&quot;http://academy.cba.mit.edu/classes/scanning_printing/MarchingCubes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt;. I managed to get the geometric reconstruction (the mesh) however I do struggle with the normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In section 4 they explain the gradient can be firstly estimated using central difference using 8 cubes sharing the vertex $(i,j,k)$. However consider for example case 1 (figure 3) in the paper assume for example you have 8 cubes with one vertex &quot;on&quot; and all the other &quot;off&quot;. All the central difference (assuming binary values) would give you 0, therefore I wouldn't be able to estimate the normal in the cube vertex, and later linear interpolate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there some subtlety I'm missing? I wouldn't personally use central difference, but assuming I'm sweeping in a certain direction and then interpolate a point in a cube edge I would use for example forward difference, which to me make more sense, however I'm not 100% sure of the &quot;sense&quot; of this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In their scheme they give a good explanation of why their approach make sense.&#xA;Not sure I can justify mine. &lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2018-08-19T02:00:35.080" Title="Degenerate case of normal computation in marching cubes" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7717" PostTypeId="1" AcceptedAnswerId="7720" CreationDate="2018-06-14T22:37:46.180" Score="2" ViewCount="46" Body="&lt;p&gt;I have to create a orbiting camera. I created the model of sun (a sphere) around (0,0,0) , triangulated and Phong shaded it. I would have a camera that goes around the sun thus an orbiting camera and I would know if my way to proceed is right or not:&#xA;In WebGl there isn't a phisical camera. Nevertheless I imagine to place my camera at the center (0,0,0) and I have first to translate it of [0 0 100] ([0 0 100] is the point where early is located the camera) and later I rotate the camera around y ([0 1 0]) of some angle (Actually the angle is animated, i.e. the angle increases over time).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus cameraMatrix = R(angle,[0 1 0])T([0 0 100])&#xA;(First translation and later rotation)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in WebGl there isn't camera, then I have to move the world with inverse transformation namely:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ModelViewMatrix = inverse(cameraMatrix);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus&#xA;ModelViewMatrix =  inverse{R(angle,[0 1 0])T([0 0 100])} = inverse(T([0 0 100]))&lt;em&gt;inverse(R(angle,[0 1 0])= T([0 0 -100])&lt;/em&gt; R(-angle,[0 1 0])&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(In the last first rotation and later translation)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far is it all right?&#xA;Finally in drawScene namely the function of rendering cycle the order of call is inverted namely: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat4.translate(mvMatrix , [0,0,-100.0]);&#xA;mat4.rotate(mvMatrix , degToRad(-angle) , [0,1,0]); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;in this order does a rototranslation, namely it occurs first the rotation and later the translation (inverted respect the order of call functions).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would confirm if this is right because I'm a neophyte of Computer Graphics and I'm not sure.&#xA;(I know that I can use lookAt() or define the values of cameraMatrix by hand but I'm not interested in it).&#xA;Thanks in advance &lt;/p&gt;&#xA;" OwnerUserId="4981" LastEditorUserId="4981" LastEditDate="2018-06-14T22:42:54.993" LastActivityDate="2018-06-16T07:53:21.813" Title="Correctness or otherwise of the procedure for generating an orbiting camera in WebGl" Tags="&lt;rendering&gt;&lt;transformations&gt;&lt;webgl&gt;&lt;matrix&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7718" PostTypeId="2" ParentId="7704" CreationDate="2018-06-14T23:12:34.117" Score="1" Body="&lt;p&gt;I have not read the links but you remember that in the classical ray tracing ,namely Whitted rayTracing,  a single ray is traced from viewpoint to each pixel and alone if a complete diffusive surface is intercepted  the reflected ray (secundary ray) isn't calculated. Practically the contribution of indirect illumination on the specular diffusive surface is multiplied for $K_s$ i.e. the specularity coefficient of material and if diffusive coefficient $K_d$ is very hight $K_s$ will be very low and thus the reflective ray in that point isn't traced thus there will be a threashold to stop recursion. Furthermore the recursion tree is a binary tree because is launched between secundary ray the rifraction ray also.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this method there is   subsampling namely aliasing: in the real case more that a ray determines the color of a pixel and in Witthed is like to use a sample(a single ray) for each pixel. Thus we can launch more that a ray for each pixel but not one ray for each equally divided space of the pixel (otherwise supersampling namely aliasing to a bigger frequency) but the rays are sent  in a stochastic way like this they will hit the areas where the color variation is higher (these areas cause aliasing). The Witthed ray Tracing here is rephrased following Kajiha equation of rendering that bring to solve an integral of the BRDF with Montecarlo method choising with importance the samples to estimate the integral using the BRDF or its estime like a probability distribution. &#xA;Following these sthocatic approaches there are distributed ray tracing and path ray tracing for instance. &lt;/p&gt;&#xA;" OwnerUserId="4981" LastActivityDate="2018-06-14T23:12:34.117" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7720" PostTypeId="2" ParentId="7717" CreationDate="2018-06-16T07:53:21.813" Score="2" Body="&lt;p&gt;Your math looks correct to me. Your terminology is a little off - technically what you are creating here is just the 'view' matrix rather than the 'modelView'. If you're just drawing a single sphere at the origin then it doesn't make a difference, but normally the modelView is unique for each object in a scene - it's the object's model-to-world transform matrix multiplied by the view matrix you describe above.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-06-16T07:53:21.813" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7722" PostTypeId="1" AcceptedAnswerId="7802" CreationDate="2018-06-17T06:04:12.177" Score="0" ViewCount="187" Body="&lt;p&gt;I'm not sure this is the best place to post this, but it &lt;em&gt;definitely&lt;/em&gt; seemed more appropriate than programming. I'm one of the developers of Performous, essentially a karaoke (and instruments) game. We use mostly 2D graphics in OpenGL, I don't think anything particularly strange.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On most machines, everything works perfectly. There's a subset of Intel iGPUs (from what I've been able to ascertain, certain models ranging from around the Ivy Bridge generation to somewhere around Broadwell) that render incredibly distorted, on Windows machines. I've seen it happen on Windows 7 and 10 (presumably it also does on Win8)... never in Linux or OSX, I attempted to reproduce it on a mac mini (that should have been affected) running bootcamp, and was unable to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. If you want to see the code, it's on github at &lt;a href=&quot;https://github.com/performous/performous&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/performous/performous&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Relevant files most likely would be (under game/) &lt;code&gt;video_driver.cc/hh, surface.cc/hh, glutil.cc/hh, glshader.cc/hh&lt;/code&gt; and the actual shaders that live in &lt;code&gt;data/shaders&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fF2Af.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fF2Af.jpg&quot; alt=&quot;Distorted graphics on a win7 PC&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: actual drawing call, &lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;void VertexArray::draw(GLint mode) {&#xA;    GLErrorChecker glerror(&quot;VertexArray::draw&quot;);&#xA;    if (empty()) return;&#xA;    unsigned stride = sizeof(VertexInfo);&#xA;    GLint program;&#xA;    glGetIntegerv(GL_CURRENT_PROGRAM, &amp;amp;program);&#xA;    GLint vertPos = glGetAttribLocation(program, &quot;vertPos&quot;);&#xA;    GLint vertTexCoord = glGetAttribLocation(program, &quot;vertTexCoord&quot;);&#xA;    GLint vertNormal = glGetAttribLocation(program, &quot;vertNormal&quot;);&#xA;    GLint vertColor = glGetAttribLocation(program, &quot;vertColor&quot;);&#xA;    glerror.check(&quot;program and attribs&quot;);&#xA;    glBindVertexArray(m_vao);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, m_vbo);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(VertexInfo) * size(), &amp;amp;m_vertices.front(), GL_STATIC_DRAW);&#xA;    glerror.check(&quot;bind&quot;);&#xA;    if (vertPos != -1) {&#xA;        glEnableVertexAttribArray(vertPos);&#xA;        const GLvoid* ptr = m_vbo ? (GLvoid*)offsetof(VertexInfo, position) : &amp;amp;m_vertices[0].position;&#xA;        glVertexAttribPointer(vertPos, 3, GL_FLOAT, GL_FALSE, stride, ptr);&#xA;    }&#xA;    if (vertTexCoord != -1) {&#xA;        const GLvoid* ptr = m_vbo ? (GLvoid*)offsetof(VertexInfo, texCoord) : &amp;amp;m_vertices[0].texCoord;&#xA;        glEnableVertexAttribArray(vertTexCoord);&#xA;        glVertexAttribPointer(vertTexCoord, 2, GL_FLOAT, GL_FALSE, stride, ptr);&#xA;    }&#xA;    if (vertNormal != -1) {&#xA;        const GLvoid* ptr = m_vbo ? (GLvoid*)offsetof(VertexInfo, normal) : &amp;amp;m_vertices[0].normal;&#xA;        glEnableVertexAttribArray(vertNormal);&#xA;        glVertexAttribPointer(vertNormal, 3, GL_FLOAT, GL_FALSE, stride, ptr);&#xA;    }&#xA;    if (vertColor != -1) {&#xA;        const GLvoid* ptr = m_vbo ? (GLvoid*)offsetof(VertexInfo, color) : &amp;amp;m_vertices[0].color;&#xA;        glEnableVertexAttribArray(vertColor);&#xA;        glVertexAttribPointer(vertColor, 4, GL_FLOAT, GL_FALSE, stride, ptr);&#xA;    }&#xA;    glerror.check(&quot;enable arrays&quot;);&#xA;    glDrawArrays(mode, 0, size());&#xA;&#xA;    if (vertPos != -1) glDisableVertexAttribArray(vertPos);&#xA;    if (vertTexCoord != -1) glDisableVertexAttribArray(vertTexCoord);&#xA;    if (vertNormal != -1) glDisableVertexAttribArray(vertNormal);&#xA;    if (vertColor != -1) glDisableVertexAttribArray(vertColor);&#xA;    if (m_vbo) glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;    glBindVertexArray(0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Client-side vertex struct:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;struct VertexInfo {&#xA;    glmath::vec3 position{};&#xA;    glmath::vec2 texCoord{};&#xA;    glmath::vec3 normal{};&#xA;    glmath::vec4 color{ 1.0, 1.0, 1.0, 1.0 };&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2X29q.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2X29q.png&quot; alt=&quot;Distorted graphics on a win10 laptop&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/G6biw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/G6biw.png&quot; alt=&quot;Expected appearance, on my mac&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8889" LastEditorUserId="8889" LastEditDate="2018-07-09T15:22:42.153" LastActivityDate="2018-07-17T00:57:14.143" Title="Distorted OpenGL graphics in certain models of Intel GPUs under Windows; possible causes?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;gpu&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="7724" PostTypeId="2" ParentId="7705" CreationDate="2018-06-18T00:47:56.717" Score="1" Body="&lt;p&gt;So someone at mathstackexchange posted the answer I was satisfied with. Here is the &lt;a href=&quot;https://math.stackexchange.com/questions/2823164/variance-of-estimator-monte-carlo-integration/2823170#2823170&quot;&gt;link&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is the quoted answer.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;This computation really has nothing to do with the Monte Carlo&#xA;  integration context. It is a general fact that if $X_i$ are iid random&#xA;  variables with variance $\sigma^2$ then $\frac{1}{n} \sum_{i=1}^n X_i$&#xA;  has variance $\sigma^2/n$. This is because of two related facts.&#xA;  First, if you sum two independent random variables, you add their&#xA;  variances. This is because:&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;$$\sigma_{X+Y}^2=E[(X+Y-\mu_X-\mu_Y)^2] \\=E[((X-\mu_X)+(Y-\mu_Y))^2]&#xA;&amp;gt; \\&#xA;&amp;gt; =E[(X-\mu_X)^2]+E[(Y-\mu_Y)^2]+2E[(X-\mu_X)(Y-\mu_Y)] \\=\sigma_X^2+\sigma_Y^2.$$&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;In the last step you use that independent random variables are&#xA;  uncorrelated. This follows from the fact that $E[XY]=E[X]E[Y]$ if $X$&#xA;  and $Y$ are independent.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Second, if you multiply a random variable by a constant, you multiply&#xA;  its variance by the square of that constant. This is obvious from the&#xA;  definition and linearity of expectation.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;So in the context of $\frac{1}{n} \sum_{i=1}^n X_i$, the summation&#xA;  multiplies the variance by $n$ while the division by $n$ multiplies&#xA;  the variance by $1/n^2$, giving the result.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So if we apply this $E[XY]=E[X]E[Y]$, we get the final result.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-06-18T00:47:56.717" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7725" PostTypeId="1" AcceptedAnswerId="7726" CreationDate="2018-06-18T11:38:42.487" Score="6" ViewCount="265" Body="&lt;p&gt;I've recently become interested in photorealistic rendering, and I've been looking at the different rendering philosophies. I read this &lt;a href=&quot;https://benedikt-bitterli.me/bachelor-thesis.pdf&quot; rel=&quot;noreferrer&quot;&gt;Disney Research bachelor's thesis&lt;/a&gt;, which states both the radiative transfer equation (RTE)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$(\vec{w}\cdot\nabla)L(\vec{x},\vec{\omega}) = -(\sigma_{a}+\sigma_{s})L(\vec{x},\vec{\omega})+Q(\vec{x},\vec{\omega})+\sigma_{s} \int_{\Omega}L(\vec{x},\vec{\omega})\rho(\vec{\omega},\vec{\omega}')d\vec{\omega}'$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and that &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Exact BSSRDFs follow trivially from exact solutions to the RTE.&#xA;  Unfortunately, closed form solutions of the RTE for general 3D&#xA;  geometry, illumination and materials are rare, which motivates&#xA;  analysis on simplified, lower dimensional domains.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But most shaders use BSSRDF's and(/or?) the Rendering Equation instead, even high-end shaders like Disney's Hyperion, even though the &lt;a href=&quot;https://en.wikipedia.org/wiki/Rendering_equation&quot; rel=&quot;noreferrer&quot;&gt;Rendering Equation&lt;/a&gt; supposedly doesn't take into account sub-surface scattering, polarization, etc..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my two questions are &lt;strong&gt;a)&lt;/strong&gt; what is the reason for not using the radiative transfer equation for photorealistic rendering (or an approximation like the skin-shaders used for Big Hero and Moana), and &lt;strong&gt;b)&lt;/strong&gt; how are the parameters like the phase functions and coefficients found for different materials like skin, hair, water, metal, glass?&lt;/p&gt;&#xA;" OwnerUserId="8892" LastActivityDate="2018-06-18T21:00:29.777" Title="Radiative Transfer Equation for Photorealistic Rendering" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;computational-geometry&gt;&lt;brdf&gt;&lt;photo-realistic&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7726" PostTypeId="2" ParentId="7725" CreationDate="2018-06-18T21:00:29.777" Score="3" Body="&lt;p&gt;I suspect the answer to (a) is simply performance. Full volumetric path tracing / photon mapping based on the RTE can certainly be done (and I'm sure it sometimes is), but it's very expensive and requires enormous numbers of samples to converge to a noise-free result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is especially true when the scattering medium is very dense, like in human skin and hair, or materials like milk, plastic, marble, or jade. In such materials, the light scatters so quickly that it's essentially isotropic after a couple of millimeters, so a BSSRDF is a very good approximation to the true volumetric scattering, and far cheaper to evaluate. (Performance matters even for offline rendering!) A mixture of volumetric simulations and empirical data might be used to derive and validate the BSSRDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for how the coefficients are measured, one technique I've read about is to shine a narrow, bright beam of light (like a laser pointer) onto the material, then measure the light scattered back out using photosensors placed at different distances from the incident point. By processing this data you can then get an estimate of the scattering coefficients. &lt;a href=&quot;http://www.merl.com/publications/docs/TR2005-046.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;This paper&lt;/a&gt; shows a sensor based on this idea being applied to human skin, and &lt;a href=&quot;http://gfx.cs.princeton.edu/pubs/Donner_2008_ALH/donner08hskin.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt; has more details about setting up a sophisticated (multi-layer) BSSRDF based on empirical data.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-06-18T21:00:29.777" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7729" PostTypeId="2" ParentId="7716" CreationDate="2018-06-20T00:42:37.507" Score="2" Body="&lt;p&gt;The paper doesn't say to compute the normals for the 8 &quot;cubes&quot; around the cube in question. It is saying to compute the normals for all the vertices of the cube you are testing. To create those normals the algorithm would need density values from the surrounding cubes but not the normals of the surrounding cubes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The paper labels those vertices v1 to v8. So if v1 is the only vertex whose density value is 1 and the density value for all 7 other vertices is zero then v3,v6,v7 and v8 would have normals of zero (assuming the adjacent cubes were empty). But v1,v2,v4 and v5 would have non-zero normals since v1 is guaranteed to have a non-zero density and at least 1 of x,y or z would be non-zero. Interpolating those normals to the triangle with vertices at e1,e4 and e9 should give a normal pointing roughly at v7. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When reading a paper like this one (ie one that has been used around the world to visualize life saving data, and help countless people) if I think I have found an error I stop and take a long hard look for my mistake instead of looking for the mistake of the authors. Just saying.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2018-06-20T00:42:37.507" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="7730" PostTypeId="1" CreationDate="2018-06-20T18:32:55.793" Score="4" ViewCount="637" Body="&lt;p&gt;I am following &lt;a href=&quot;https://learnopengl.com/Getting-started/Camera&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial&lt;/a&gt; on how to implement a first person camera. So far I was able to implement &lt;a href=&quot;https://learnopengl.com/code_viewer_gh.php?code=includes/learnopengl/camera.h&quot; rel=&quot;nofollow noreferrer&quot;&gt;the entire (C++) class&lt;/a&gt; in TypeScript and it works as it is supposed to.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Problem&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;What I was not able to implement is a system which takes the camera direction only and initially orients the camera based on it. In the tutorial the author does set the camera direction to &lt;code&gt;(0.0, 0.0, -1.0)&lt;/code&gt; but it is instantly overwritten by calling &lt;code&gt;_updateCameraVectors()&lt;/code&gt; in the constructor. So as I see it, passing the camera direction to the class will always be ignored. Before looking at the code please note:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;In the tutorial the author referes to a variable &lt;code&gt;Front&lt;/code&gt;, which in my case is called &lt;code&gt;cameraDirection&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;In the tutorial only the view matrix is being calculated by the camera class. I am calculating the view-projection matrix.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3&gt;Code&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Here are the most important parts:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The constructor initializes all the important stuff, but most importantly calls &lt;code&gt;_updateCameraVectors()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;constructor(gl: WebGL2RenderingContext, program: WebGLProgram, position: vec3, cameraDirection = vec3.fromValues(0.0, 0.0, -1.0),&#xA;    yaw = -90.0, pitch = 0.0,&#xA;    aspect = gl.canvas.clientWidth / gl.canvas.clientHeight, zNear = 1, zFar = 2000) {&#xA;    this.gl = gl;&#xA;    this._program = program;&#xA;    this._aspect = aspect;&#xA;    this._zNear = zNear;&#xA;    this._zFar = zFar;&#xA;    this._yaw = yaw;&#xA;    this._pitch = pitch;&#xA;    this._cameraPosition = position;&#xA;    this._cameraDirection = cameraDirection;&#xA;&#xA;    this._updateCameraVectors();&#xA;    GLHelper.setUniformLocations(this.gl, this._unifroms, this._program);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In &lt;code&gt;_updateCameraVectors()&lt;/code&gt; the camera direction is being recalculated based on yaw and pitch values. Then the &lt;code&gt;cameraUp&lt;/code&gt; vector is calculated.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;protected _updateCameraVectors(): void {&#xA;    const front = vec3.create();&#xA;    front[0] = Math.cos(MathHelper.degToRad(this._yaw)) * Math.cos(MathHelper.degToRad(this._pitch));&#xA;    front[1] = Math.sin(MathHelper.degToRad(this._pitch));&#xA;    front[2] = Math.sin(MathHelper.degToRad(this._yaw)) * Math.cos(MathHelper.degToRad(this._pitch));&#xA;    vec3.normalize(this._cameraDirection, front);&#xA;&#xA;    const right = vec3.create();&#xA;    vec3.cross(right, this._cameraDirection, this._worldUp); // World up is always (0,1,0)&#xA;    vec3.normalize(this._cameraRight, right);&#xA;    const up = vec3.create();&#xA;    vec3.cross(up, this._cameraRight, this._cameraDirection);&#xA;    vec3.normalize(this._cameraUp, up);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Based on a &lt;code&gt;requestAnimationFrame&lt;/code&gt;-loop the &lt;code&gt;_computeviewProjectionMatrix&lt;/code&gt; simply calculates a view-projection matrix which is later used for rendering.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private _computeviewProjectionMatrix(): mat4 {&#xA;&#xA;    this._aspect = this.gl.canvas.clientWidth / this.gl.canvas.clientHeight;&#xA;&#xA;    const cameraTarget = vec3.create();&#xA;    vec3.add(cameraTarget, this._cameraPosition, this._cameraDirection); // Here the actual camera target is calculated.&#xA;&#xA;    const view = mat4.create();&#xA;    mat4.lookAt(view, this._cameraPosition, cameraTarget, this._cameraUp);&#xA;&#xA;    const projectionMatrix = mat4.create();&#xA;&#xA;    mat4.perspective(projectionMatrix, this._fieldOfViewRadians, this._aspect, this._zNear, this._zFar);&#xA;&#xA;    const viewProjectionMatrix = mat4.create();&#xA;    mat4.multiply(viewProjectionMatrix, projectionMatrix, view);&#xA;&#xA;    return viewProjectionMatrix;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;_handleMouseMovement&lt;/code&gt; function calls &lt;code&gt;_updateCameraVectors()&lt;/code&gt; every time the &lt;code&gt;pitch&lt;/code&gt; and &lt;code&gt;yaw&lt;/code&gt; values are updated via mouse movement.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private _handleMouseMovement = (event: MouseEvent): void =&amp;gt; {&#xA;&#xA;    if (this._firstMouseMove) {&#xA;        this._firstMouseMove = false;&#xA;        return;&#xA;    }&#xA;&#xA;    let xOffset = event.movementX;&#xA;    let yOffset = event.movementY;&#xA;&#xA;    xOffset *= this._sensitivity;&#xA;    yOffset *= this._sensitivity;&#xA;&#xA;    this._yaw += xOffset;&#xA;&#xA;    if (!this._inverseY) {&#xA;        this._pitch += yOffset;&#xA;    } else {&#xA;        this._pitch -= yOffset;&#xA;    }&#xA;&#xA;    if (this._pitch &amp;gt; 89) {&#xA;        this._pitch = 89;&#xA;    }&#xA;    if (this._pitch &amp;lt; -89) {&#xA;        this._pitch = -89;&#xA;    }&#xA;&#xA;    this._updateCameraVectors();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Last but not least there is a &lt;code&gt;_moveCamera&lt;/code&gt; function which updates the camera position based on WASD input. I will post only a excerpt because it is selfexplonatory.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private _moveCamera(): void {&#xA;    // INFO: 'W' - Move forward&#xA;    if (this._keyMap[87] === true) {&#xA;        const factor = vec3.create();&#xA;        vec3.scale(factor, this._cameraDirection, this._cameraSpeed * this._deltaTime);&#xA;        vec3.add(this._cameraPosition, this._cameraPosition, factor);&#xA;    }&#xA;&#xA;    // ...&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h3&gt;Question&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;How would I modify this class to initially &quot;lookAt&quot; a vec3 point passed to the constructor? Note I am not really asking for code only. Suggestion, ideas and any advice would be really helpful.&lt;/p&gt;&#xA;" OwnerUserId="2485" LastActivityDate="2019-12-14T02:00:50.350" Title="Computing a lookAt matrix by passing a vec3 to a camera object" Tags="&lt;webgl&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7731" PostTypeId="1" AcceptedAnswerId="7736" CreationDate="2018-06-21T15:56:09.910" Score="3" ViewCount="155" Body="&lt;p&gt;This is kind of a meta-question: We are a neuroscience lab looking for an engineer to develop virtual environments for experiments. Since it's not our usual field of job advertisement we do not know where computer graphics people usually look for job ads. A top-3 list of of places you would frequent to look for jobs would be very much appreciated. &lt;/p&gt;&#xA;" OwnerUserId="8907" LastActivityDate="2018-06-22T06:11:17.060" Title="Where do computer graphic engineers look for job ads?" Tags="&lt;virtual-reality&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7732" PostTypeId="2" ParentId="7731" CreationDate="2018-06-21T18:27:10.707" Score="2" Body="&lt;p&gt;That's a tough one. This is going to be anecdotal evidence, but in the case of other graphics programmers I know and myself, each of us has a selection of companies we hold in high esteem based on their achievements, and we watch their websites for job postings. Getting on people's &quot;employer wishlists&quot; is difficult for obvious reasons, though, especially if the job isn't &quot;glamourous&quot; like games or film VFX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does work sometimes is approaching candidates on LinkedIn (personally, I've had several instances where approaches led to successful processes and then job offers, and I accepted one of them), but I would strongly suggest being as up-front with the details as possible (preferably in the very first message you send). There's nothing more irritating than a recruiter who &quot;will tell you everything, but only over the phone/after we connect&quot;.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2018-06-21T18:27:10.707" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7733" PostTypeId="2" ParentId="7730" CreationDate="2018-06-21T20:54:50.043" Score="-1" Body="&lt;p&gt;Given that you already use yaw and pitch angles to describe the camera, the simplest solution is to compute yaw and pitch values for the vector (note: it must be a unit vector).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have &lt;code&gt;front&lt;/code&gt; vector given, you can compute angles:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pitch = MathHelper.radToDeg(Math.asin(front[1]));&#xA;yaw = MathHelper.radToDeg(Math.atan2(front[2], front[1]));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8796" LastActivityDate="2018-06-21T20:54:50.043" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7734" PostTypeId="1" CreationDate="2018-06-21T23:56:20.787" Score="4" ViewCount="183" Body="&lt;p&gt;Recently I ran into an odd issue with some of my DirectX11 DirectCompute code &#xA;when trying it on an AMD GPU for the first time where as on a NVIDIA one it had worked fine all through development. The fact that this only appeared on AMD either means that NVIDIA GPUs are more resistant to the issue or perhaps something about them such as a different wavefront size is not triggering the issue, or that it's not even an problem with my code and instead is a bug somewhere along the pipeline (driver, GPU itself, etc) for AMD things. After further testing however, it did appear to work on another more modern AMD card (the Vega 56), though this may be because it was running on Windows 7, or because the GCN 5 architecture (or its drivers) somehow fixed this issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A summary of the GPUs tested is as follows:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;NVIDIA GeForce GTX 960, Feature Set 11.0/11.1, Windows 10 (Ok)&lt;/li&gt;&#xA;&lt;li&gt;NVIDIA GeForce GTX 1060, Feature Set 11.1, Windows 10 (Ok)&lt;/li&gt;&#xA;&lt;li&gt;Radeon RX 580, Feature Set 11.0/11.1, Windows 10 (Fail)&lt;/li&gt;&#xA;&lt;li&gt;Radeon RX Vega 56, Feature Set 11.0, Windows 7 (Ok)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The general setup of the issue can be represented by the following pseudocode which I turned into a minimal test application to confirms the problem indeed exists to ensure nothing else in the other much larger codebase was causing the issues:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (condition) {&#xA;  globalArray[i].first = value &#xA;} else {&#xA;  globalArray[i].second = value&#xA;}&#xA;&#xA;DeviceMemoryBarrier()&#xA;&#xA;InterlockedExchange(globalArray[i].flag, true, oldFlag)&#xA;&#xA;if (!oldFlag) {&#xA;  return&#xA;}&#xA;&#xA;if (condition) {&#xA;  new_value = globalArray[i].second&#xA;} else {&#xA;  new_value = globalArray[i].first&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With this setup, an example of its functionality would be best represented by 2 threads executing this code (the important bit being that they may not be within the same work group, more on this later), one with &lt;code&gt;condition&lt;/code&gt; set to true and one with it set to false. Next, each thread sets the value they possess into a global buffer (both threads have the same index &lt;code&gt;i&lt;/code&gt;) in the &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;second&lt;/code&gt; slots of a structure. The interlocked exchange operation which follows attempts to set the flag (also stored in global memory) to true, allowing only one of the two threads to proceed (one will see that the flag was not set beforehand, meaning it was the first to set it and return). Finally, the remaining thread can now make the assumption that both &lt;code&gt;first&lt;/code&gt; and &lt;code&gt;second&lt;/code&gt; values have been set (as the other now terminated thread has already set the atomic along with the global memory barrier which should ensure this), allowing it to read the value written by the other thread to &lt;code&gt;new_value&lt;/code&gt; (based on the condition once again).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From a more higher level perspective, this code simply allows two arbitrary threads to combine their information into one which continues on, all through global memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue I observed however was that very rarely (only seen in about 1 in a million cases), &lt;code&gt;new_value&lt;/code&gt; would be set to something uninitialized, implying that the data it read from in the global array was. This however is confusing as the fact that the atomic flag is set should ensure that the value has been written to the proper location by the other thread. I thought perhaps that the atomic operation finished before the full write to the first/second value did for whatever reason but since there is a &lt;code&gt;DeviceMemoryBarrier&lt;/code&gt; after the value write but before the atomic exchange, it should be waiting on the write to finish before signaling the atomic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This behavior leads me to believe that it is something bizarre which is happening so rarely due to unlikely circumstances, such as threads from different wavefronts running into eachother at the exact same time as mentioned previously which should in theory work fine, but something such as caching preventing the writes from being seen properly. This further is strengthened by my testing which purposely collides threads together from random wavefronts, causing the issue to arise most frequently when the number of values to process is around 100,000 whereas counts too small have no effect and counts well into the millions do not either, likely as fewer threads are colliding at the proper exact time due to it being much more unlikely (even still, it sometimes takes 100+ iterations of the same test repeated to invoke the issue with 100,000 values). Most of that is simply speculation though since I do not know too much about the specifics of how GPU memory hierarchies function. Another possibility is that this kind of behavior simply isn't guaranteed by DirectCompute and I am using it incorrectly, though DirectX's documentation is very lacking on actual in-depth descriptions of functionality for intrinsics like &lt;code&gt;InterlockedExchange&lt;/code&gt;, so I am not sure what to think.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know why this might happen and what I can do to fix it? If it'd help, I can also make the proof of concept test application I made available to show a more specific example of the problem occurring (since the pseudocode did leave out a lot of &quot;irrelevant&quot; details which may actually be significant).&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Update:&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Upon more investigation, I decided to implement this same setup in OpenCL 1.2 to see if the issue persisted there as well. To my surprise, it did not and after much testing I seem to have narrowed down the potential cause. From what I can see, the &lt;code&gt;mem_fence(CLK_GLOBAL_MEM_FENCE)&lt;/code&gt; operation in OpenCL appears to generate slightly different ISA compared to &lt;code&gt;DeviceMemoryBarrier()&lt;/code&gt;, specifically both are the same (as far as I can tell, though I am not an expert at reading GPU ISA) except for the presence of a &lt;code&gt;BUFFER_WBINVL1_VOL&lt;/code&gt; instruction which seems to be consistent with how such a construct is described &lt;a href=&quot;https://github.com/ROCm-Developer-Tools/ROCm-ComputeABI-Doc/blob/master/AMDGPU-ABI.md#memory-fence-constraints&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Removing the memory fence from the working OpenCL implementation causes it to exhibit the same issue as the DirectCompute implementation which leads me to believe the presence of this instruction is somehow responsible for its success, which does make sense as something relating to cache does seem able to be responsible for such odd and rare behavior. This seems to me that it is an issue with how DXBC is converted to the AMD ISA if such an instruction is indeed required, but that is also just speculation. I will post the full ISA of the test implementations here soon-ish as well in case I have misinterpreted what is going on.&lt;/p&gt;&#xA;" OwnerUserId="4837" LastEditorUserId="4837" LastEditDate="2018-06-27T02:11:18.357" LastActivityDate="2018-06-27T02:11:18.357" Title="Direct3D Global Atomic Issue" Tags="&lt;hlsl&gt;&lt;compute-shader&gt;&lt;directx11&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7735" PostTypeId="1" CreationDate="2018-06-22T01:29:06.027" Score="0" ViewCount="351" Body="&lt;p&gt;I am trying to make a particular kind of raytracer, but there is some strange bug occurring when I attempt to &lt;a href=&quot;https://youtu.be/YqJKh0ntMr4&quot; rel=&quot;nofollow noreferrer&quot;&gt;rotate the camera&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, there is some important distortion ocurring when the voxels are closed to the camera and I am not sure what may be cuasing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how I am calculating my ray:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 r = (vec3(f_coord.xy,1.f/tan(radians(40)))) //initialize the ray for a field of view of 40, f_coord is the pizel coordinate in OpenGL (-1 to 1);&#xA;r.y /= aspect_ratio // crunch the y direction to fit the aspect ratio;&#xA;vec3 dir = vec3(view_m*vec4(normalize(r),1)); //rotate the ray by the camera's rotation&#xA;r+= camera_pos; //Set the ray at the camera's position&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-06-22T01:29:06.027" Title="How to properly modify a ray in a raytracer to achieve camera rotation" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;glsl&gt;&lt;voxelization&gt;&lt;debugging&gt;" AnswerCount="0" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7736" PostTypeId="2" ParentId="7731" CreationDate="2018-06-22T06:11:17.060" Score="5" Body="&lt;p&gt;There are several major Computer Graphics publications that have a jobs section. Try &lt;a href=&quot;https://www.siggraph.org/job-board&quot; rel=&quot;noreferrer&quot;&gt;Siggraph&lt;/a&gt; for example. I'm pretty sure I saw a similar thing for &lt;a href=&quot;https://www.eg.org/wp/&quot; rel=&quot;noreferrer&quot;&gt;Eurographics&lt;/a&gt;, but I can't find it right now.&#xA;Furthermore, you can look for applicants at the conferences themselves, if you have the resources to do so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you accept students that just finish university, you should put up an ad there (or tell the computer graphics professor to spread the word - my professor was kind enough to distribute offers to us every now and then).&#xA;Apart from that, you'll probably find most graphics programmers in computer games related fields. Gamasutra has a &lt;a href=&quot;http://jobs.gamasutra.com/&quot; rel=&quot;noreferrer&quot;&gt;jobs section&lt;/a&gt;, although I'm not sure they let non-games related companies advertise there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Moreover, Stackoverflow has a job offers section. I never really used it myself, but it's probably worth looking into. I got quite a few computer graphics related offers, so my guess is that you can advertise specifically to people with tags like &lt;em&gt;OpenGL&lt;/em&gt; and &lt;em&gt;Rendering&lt;/em&gt; as their favourite tags.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-06-22T06:11:17.060" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7737" PostTypeId="1" AcceptedAnswerId="7741" CreationDate="2018-06-22T08:55:40.817" Score="6" ViewCount="1527" Body="&lt;p&gt;How do I generate bokeh that simulates shallow depth of field given a perfect depth map?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's what I tried: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Generated a sample scene using blender and corresponding depth map&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AC8vN.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AC8vN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;Using Python, generated what sigma (standard deviation) to use at each pixel for gaussian blurring: This one makes it look like the far end of the pink cube is perfectly focused.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;sigma_map = np.array(np.round(abs(np.array(depth, dtype='float32') - preferred_focus_depth)).clip(0,255), dtype='uint8')&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q25t3.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q25t3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;black = 0, no blur; white = 255, large blur&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;Applied gaussian blurring (using the sigma_map) at every pixel and this is what I got&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ll8N6.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ll8N6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Flaws observed: Averaging kernels just near the edges are taking in the pink color nearby hence the pink bleed. &lt;strong&gt;How do I avoid this?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: It's not completely blurred look closely at the zoomed in image on the right. The pixels that I wanted to remain untouched are still untouched (even though it appears they were blurred as well because of the blurring near the edges)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This &lt;a href=&quot;https://ai.googleblog.com/2017/10/portrait-mode-on-pixel-2-and-pixel-2-xl.html?m=1&quot; rel=&quot;noreferrer&quot;&gt;blog&lt;/a&gt; on Portrait mode on Pixel 2 says, &quot;Actually applying the blur is conceptually the simplest part&quot;, &lt;strong&gt;is there any simpler way of doing it then?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="8748" OwnerDisplayName="Saravanabalagi Ramachandran" LastEditorUserId="8748" LastEditDate="2018-06-22T13:54:37.510" LastActivityDate="2018-06-23T21:10:21.280" Title="Bokeh from depth map" Tags="&lt;gaussian-blur&gt;&lt;blur&gt;&lt;depth-map&gt;&lt;depth-of-field&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7738" PostTypeId="1" AcceptedAnswerId="7758" CreationDate="2018-06-22T10:42:50.440" Score="0" ViewCount="2830" Body="&lt;p&gt;Below is a triangle with its vertices and uv coordinates. These are read from&#xA;the input model file. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand why the texture comes in different orientation than the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GRZtO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GRZtO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/XBtzs.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XBtzs.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;here is the method to calculate uv coordinate for the hit point(ray-triangle code from Moller, Trumbore):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;     public bool GetIntersection(Vector rayOrigin, Vector rayDirection, ref &#xA;              float hitDistance, out Vector uv)&#xA;    {&#xA;        uv = null;&#xA;&#xA;        // begin calculating determinant - also used to calculate U parameter&#xA;        Vector pvec = rayDirection.Cross(edge2);&#xA;&#xA;        // if determinant is near zero, ray lies in plane of triangle&#xA;        float det = edge1.Dot(pvec);&#xA;&#xA;        const float EPSILON = 0.000001f;&#xA;        if ((det &amp;gt; -EPSILON) &amp;amp;&amp;amp; (det &amp;lt; EPSILON))&#xA;            return false;&#xA;&#xA;        float inv_det = 1.0f / det;&#xA;&#xA;        // calculate distance from vertex 0 to ray origin&#xA;        Vector tvec = rayOrigin - verts[0];&#xA;&#xA;        // calculate U parameter and test bounds&#xA;        float u = tvec.Dot(pvec) * inv_det;&#xA;        if ((u &amp;lt; 0.0f) || (u &amp;gt; 1.0f))&#xA;            return false;&#xA;&#xA;        // prepare to test V parameter&#xA;        Vector qvec = tvec.Cross(edge1);&#xA;&#xA;        // calculate V parameter and test bounds&#xA;        float v = rayDirection.Dot(qvec) * inv_det;&#xA;        if ((v &amp;lt; 0.0f) || (u + v &amp;gt; 1.0f))&#xA;            return false;&#xA;&#xA;        Vector uvHit = uvVectors[0] * u + uvVectors[1] * v + uvVectors[2] * (1 - u - v);&#xA;        uv = new Vector(uvHit[0], uvHit[1], 0);&#xA;&#xA;        // calculate t, ray intersects triangle&#xA;        hitDistance = edge2.Dot(qvec) * inv_det;&#xA;&#xA;        // only allow intersections in the forward ray direction&#xA;        return hitDistance &amp;gt;= 0.0f;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is the method in ImageTexture class to convert the hit point uv coordinate:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    public Vector Interpolate(Vector uv)&#xA;    {&#xA;        float u = uv[0] - (float)Math.Floor(uv[0]);&#xA;        float v = uv[1] - (float)Math.Floor(uv[1]);&#xA;        u *= bmp.Width - 1;&#xA;        v *= bmp.Height - 1;&#xA;&#xA;        Color cuv = bmp.GetPixel((int)u, (int)v);&#xA;&#xA;        return new Vector(cuv.R, cuv.G, cuv.B);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also how are the uv coordinates that come from the input model are supposed to be calculated? If this is a big mesh(a terrain) with many triangles how is the uv coordinates for each triangle vertex is calculated?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2018-06-27T20:45:02.697" Title="How to assign/calculate triangle texture coordinates" Tags="&lt;raytracing&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7739" PostTypeId="1" CreationDate="2018-06-22T23:45:07.037" Score="1" ViewCount="34" Body="&lt;p&gt;I have a wavefront loader, however it only works with triangular meshes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been trying to think how to handle faces with arbitrarily many vertices but I have no idea how they are to be handled as ultimately everything needs to be given to the GPU as triangles and I cannot think fo a way to mape any arbitrary n-gon to triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Like I know how to convert a quadrilateral to two triangles, but my way won't work for quintalaterals for example.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-06-23T00:19:09.657" LastActivityDate="2018-06-23T00:19:09.657" Title="How are non-triangular wavefront meshes handled?" Tags="&lt;algorithm&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7741" PostTypeId="2" ParentId="7737" CreationDate="2018-06-22T23:56:44.777" Score="5" Body="&lt;p&gt;The blog post that you talked about, is not about generating bokeh for a computer generated image. It is instead about generating a believable depth of field effect from an image captured by a smartphone camera, as the effect is desired for portraits to make the subject stand out. It generally works by splitting the image in to two parts. One part is the subject, which should not be blurred. The other part is the background, which should be blurred but the pixels of the subject should have no influence and would thus have a weight of zero. Slightly more sophisticated algorithms may make the blur kernel size variable across an image to create a smoother transition, but the subject's pixels would still be ignored.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In games and CGI, post process depth of field is done differently. There are multiple ways for it. A simple google search shows multiple. You could do depth of field like you have, and simply ignore the pixels which should not be blurred to remove the ghosting. However, this is not true to how depth of field occurs inside of a camera. So, in order to get a good algorithm to simulate depth of field, I will first try to explain how you get the depth of field effect in an actual camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us say, that we have an object, a single lens and an image sensor. We look at them from the side.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/aud9f.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aud9f.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Light scatters in many different directions when hitting the object. To simplify we only take one point. From this point, I will show the light that would hit the lens as a gray solid.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/FK7bL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FK7bL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;The lens bends the light towards a single point. That is the focal point.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZD9BY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZD9BY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;You can see that the focal point is in front of the sensor. This causes the light from that single point on the object, to fall on a large portion of the sensor. If the focal point is behind the sensor, the same would happen. But, if the focal point lies on the sensor, there would only be one point on the sensor where the light falls on. This area where the light falls on the sensor, is called the circle of confusion (CoC). This is also the cause of the depth of field effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One important thing to know, is that when the point on the object moves around, the focal point also moves around. If the point moves closer to the lens, the focal point moves closer to the lens, which would alter the size of the circle of confusion. This gives you the gradual change in blurriness that you have with depth of field, since the circle of confusion gradually becomes larger when an object moves away from the area in focus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we add in an aperture we simply block out a part of the light, which causes the circle of confusion to be smaller. This allows us to determine how much light to let in (to make the image brighter or darker), and how strong the depth of field effect is.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/sxmta.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sxmta.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From this, we can conclude a few things on how we should implement depth of field.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Every point whose light enters the camera lens, has a circle of confusion.&lt;/li&gt;&#xA;&lt;li&gt;The circle of confusion is the area where the light, from that point, falls on.&lt;/li&gt;&#xA;&lt;li&gt;The circle of confusion changes size when the point moves closer to or further away from the lens, or when the aperture changes size.&lt;/li&gt;&#xA;&lt;li&gt;The area of the circle of confusion has no falloff. Every point inside the circle of confusion has the same weight. This results in a box blur.&lt;/li&gt;&#xA;&lt;li&gt;If a point is in focus, its circle of confusion would be either zero or something so small, that it is not noticed.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The algorithm is quite simple. For each pixel in the image, we use the depth to calculate the circle of confusion. Then, we add the colour of that pixel to all the other pixels that lie in the circle of confusion. However, if that other pixel is closer to the camera (a lower depth value), it would block the light from our pixel, and we should not add the colour of our pixel to the blocking pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In pseudo code it would look something like this;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// for each pixel in the all-focus image&#xA;for(x = 0; x &amp;lt; width; x++){&#xA;    for(y = 0; y &amp;lt; height; y++){&#xA;        // How much blur? Zero or close to it if it should be in focus.&#xA;        float CoCRadius = calcCoCRadius(depth(x, y));&#xA;&#xA;        // For every pixel in the square with the size of CoCRadius.&#xA;        for(i = x - CoCRadius; i &amp;lt;= x + CoCRadius; i++){&#xA;            for(j = y - CoCRadius; j &amp;lt;= y + CoCRadius; j++){&#xA;                // Discard pixels outside of the shape. Square -&amp;gt; Circle&#xA;                if(isInBokehShape(i - x, j - y)){&#xA;                    // Discard pixels that would block it.&#xA;                    if(depth(i, j) &amp;gt;= depth(x, y){&#xA;                        // Add the colour.&#xA;                        newColour[i, j] += colour(x, y);&#xA;                        // Add the weight, for normalizing.&#xA;                        weight[i, j] += 1.0f;&#xA;                    }&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;    }&#xA;}&#xA;//Normalize the values with the weight.&#xA;for(x = 0; x &amp;lt; width; x++){&#xA;    for(y = 0; y &amp;lt; height; y++){&#xA;        newColour[x, y] /= weight[x, y];&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This would give you a depth of field effect that is quite true, and does not give you the ghosting effect. $calcCoCRadius$ is a method that calculates the radius in pixels of the circle of confusion. It could be anything, but if you want it as true to an actual camera, then you can use the formula from &lt;a href=&quot;https://en.wikipedia.org/wiki/Circle_of_confusion&quot; rel=&quot;nofollow noreferrer&quot;&gt;this Wikipedia page&lt;/a&gt;. $isInBokehShape$ is a method which returns a boolean on whether the point is inside the bokeh shape. With the two for loops we just get a square, but if we want to get a circle shaped bokeh, we need to discard the pixels that would lie outside of the circle. This discarding is also the reason why we keep track of the weights and normalize afterwards with the weight, since we do not know how many pixels we need to discard. The weight is also useful if you do want a falloff in the circle of confusion, for example if you want a gaussian blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another important thing to know, is that the implementation listed here, is not very optimal. The problem is basically that you write to multiple different pixels. This causes race conditions. Instead, it is better to rework the algorithm so that you only need one write. Basically, you loop through every pixel and you then you check all other pixels (or pixels inside of a maximum CoC radius) whether their CoC radius is large enough that they contribute to the pixel's colour. This way, you can also put the normalizing of the values inside the first loop over all the pixels instead of having to do that later.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This should be a fairy good way of implementing depth of field as a post processing effect. There are also other ways, but this is one.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="4908" LastEditDate="2018-06-23T21:10:21.280" LastActivityDate="2018-06-23T21:10:21.280" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7742" PostTypeId="2" ParentId="7737" CreationDate="2018-06-23T01:28:20.373" Score="-1" Body="&lt;p&gt;Does the effect need to be physically accurate? I've implemented this using a cheat before. @bram0101's answer is great. If you need accuracy, then by all means, implement that. I've been able to get something convincing to the eye by simply doing a threshold of the luminance of the image and placing a semi-transparent polygon or circle centered at every point that's above the threshold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You also need to take into account distance from the focal plane. The distance can be used to control the size of the bokeh, with the size being 0 at the focal plane, and some maximum size at some farther distance.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2018-06-23T16:18:00.870" LastActivityDate="2018-06-23T16:18:00.870" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7744" PostTypeId="1" CreationDate="2018-06-23T15:35:55.327" Score="1" ViewCount="105" Body="&lt;p&gt;I am writing a raytracer in F# using montecarlo sampling&#xA;I would like to make my recursive calls tail recursive but I am not sure of this is possible with MC raytracing as one has to evaluate sampled hemisphere before returning.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The accululator variables are there to facilitate the tail recursion and works for naiive raytracers which just trace along a single ray until it terminates.&#xA;At the moment the problem is the for loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help / pointers / references I can read would be appreciated&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently my code looks as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        if surfaceGeometry.IntersectionAcceptable realSolution t 1.0f (PointForRay ray t)&#xA;        then&#xA;            let emittedShading = surface.Emitted&#xA;            let e = accEmitted + accScatter*emittedShading &#xA;            let mcSamples = surface.SampleCount&#xA;&#xA;            //TODO rewrite this to make it tail recursive&#xA;            let mutable totalShading = e/surface.MCNormalization&#xA;            for _ in 0..mcSamples-1 do&#xA;                let (doesRayContribute,outRay,cosOfIncidence) = surface.Scatter ray t ((int)newTraceDepth)&#xA;                let shading = surface.BRDF*cosOfIncidence / (surface.PDF*surface.MCNormalization)&#xA;                let s = accScatter*shading&#xA;                totalShading &amp;lt;- totalShading + (rayTrace newTraceDepth (outRay , e , s))&#xA;            totalShading&#xA;        else &#xA;           accEmitted + backgroundColor*accScatter&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8920" LastActivityDate="2018-06-23T15:35:55.327" Title="Tail Recursive Monte Carlo Raytracing" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7745" PostTypeId="1" AcceptedAnswerId="7747" CreationDate="2018-06-23T20:32:13.223" Score="4" ViewCount="365" Body="&lt;p&gt;so I am currently in the middle of implementing a path tracer for my bachelor thesis. And so far I have understood and mapped the general flow of the program except for 2 things. Note that I'm using OpenCL and will be using OpenGL-OpenCL interop for rendering the path traced image to the window created by openGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ok so here are my questions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt;  First of all, I know that GPU memory is quite limited as compared to the CPU and it's one of the reasons we don't see GPU path tracers that much in professional industries like Film industry etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I am interested in, is there any way to know the exact amount of memory available?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'll be loading model files and sending this whole model data to the GPU probably in a data structure (K-D tree etc). Now these models will probably contain millions of triangles. &lt;strong&gt;How is the GPU supposed to store that much amount of data? Or is there any other efficient way of doing this?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Secondly I also read that accesses to global memory within a work-group can be coalesced/combined if they are done at the same time. So I was thinking to use a memory barrier and once all the work items have reached it, I can copy the whole K-D tree from global to local memory for faster processing ofcourse. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Again can the local memory hold such amount of data?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; The second part I'm confused with is that, you usually hear that you turn on the path tracer and leave it for a few minutes and the Image gradually starts looking better and better as the samples are increased. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand yet, how should I be implementing this feature from coding point of view.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I have planned out, there will be a single main kernel that will loop over the Image (shared between openGL and openCL) sending out a fixed number of rays (suppose 8) per pixel. After this kernel finish executing I can either blit the opengl FBO to the default or draw the texture on quads whichever is faster.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;But all of this is just one instance. How can I gradually improve my image by increasing samples (1,2,4,8,16...) and each time blit the FBO to the default FB?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only thing I can think of at this moment is to relaunch the kernel, compute a new color value for a specified pixel and then take the average of this new one and the old one. Is this feasible or is there a better approach? &lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-06-25T04:52:25.083" Title="Path Tracer - implementation questions" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7747" PostTypeId="2" ParentId="7745" CreationDate="2018-06-25T04:52:25.083" Score="4" Body="&lt;p&gt;I'm not an expert on path tracing, maybe someone with more experience can come up with a better answer, but I'll have a go at answering your questions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Firstly, for the purposes of a college-project scale path-tracer, VRAM capacity shouldn't really be an issue. A vertex with position, normal, tangent and UV fits in 48 bytes, so with a GB of buffers you can hold ~20 million vertices, not counting the space for your index buffers and kd-trees of course. Even my crappy 5-year-old midrange laptop card has 2GB, and modern cards have significantly more, so i doubt you're gonna exhaust VRAM with model data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the local memory question, short answer is no. Group shared memory for shader cores is tiny, you shouldn't be allocating more than a few KB per shader group, so there's no way you'd get your acceleration structures in there. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of the main issues with path tracing is coherence, which is what makes it difficult to do on GPU. Since ray directions are chosen at random, each group of shaders processing a nearby group of pixels can end up sampling radically different parts of the scene, and hence memory. This can introduce a lot of branching and cache misses if not handled carefully, and negate a lot of the advantages of running on GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The current state of the art for production path tracers is probably Disney's Hyperion. This is a CPU path tracer that runs on absolutely enormous scenes (think San Fransokyo in Big Hero 6), that are potentially too big to fit into even main RAM, and need to be streamed in from disk on demand ('out-of-core' rendering). They mitigate the coherence problems by first generating rays en-masse, then sorting them into bundles with similar position and direction, so that consecutive ray solves are likely to touch the same part of the scene and utilize the cache. Even so, they're bound by memory and I/O speeds, not compute power. Good write up on it &lt;a href=&quot;https://www.disneyanimation.com/technology/innovations/hyperion&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; including a technical PDF. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your second question, that is more or less the way it's done. You just accumulate the light from consecutive passes onto your colour buffer, and divide by the number of passes to normalize - you probably want to use 32-bit float colour channels for this. Naive path tracers (which is probably what you're building to start with) just choose a truly random sample distribution and weight each sample by its probability. Smarter approaches bias the sampling towards the more significant directions then remove the bias when summing the color. For example, for a diffuse surface, you could (a) pick truly random directions in the hemisphere and weight each sample by $N.L$ or (b) sample in a cosine distribution (more samples around the normal and less around the horizon) and apply full weight to each sample. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you haven't seen it already, &lt;a href=&quot;http://raytracey.blogspot.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracey's blog&lt;/a&gt; has some good tutorials on optimizing path-tracing for GPU. Good luck with your project.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-06-25T04:52:25.083" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7748" PostTypeId="1" AcceptedAnswerId="7749" CreationDate="2018-06-25T06:20:25.803" Score="0" ViewCount="1625" Body="&lt;p&gt;I've got a new task related to image processing in a website. I am too confused in understanding different terms used with sizing of an image. What is the difference between:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Cropping an image&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Resizing an image&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Scaling an image&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Changing Aspect-ratio of an image&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Especially &lt;strong&gt;Resizing vs Scaling&lt;/strong&gt;!!!&lt;/p&gt;&#xA;" OwnerUserId="8930" LastActivityDate="2018-06-25T11:12:08.577" Title="Difference between Cropping, Scaling, Resizing &amp; Changing Aspect Ration of an Image?" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7749" PostTypeId="2" ParentId="7748" CreationDate="2018-06-25T11:12:08.577" Score="1" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&quot;Cropping an image&quot;&lt;/strong&gt; means some part of the image is removed in order for the image to fit a certain size. For example, removing the rightmost part of a rectangular image can result in a square.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&quot;Resizing an image&quot;&lt;/strong&gt; usually means to stretch and squeeze it as needed so it fits a given size. Width and height are modified independently. If the ratio between them is not the same in the original size and in the final size, the image will appear distorted.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;strong&gt;&quot;Scaling an image&quot;&lt;/strong&gt; usually means resizing, but by the same amount horizontally and vertically. The ratio between the width and height is not modified, therefore the final image is not distorted.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The &lt;strong&gt;&quot;aspect ratio&quot;&lt;/strong&gt; is the ratio between the width and the height. Changing the aspect ratio will perceptually stretch the image either horizontally or vertically.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Resizing might change the aspect ratio, and from the wording of your question I have assumed scaling meant not changing the aspect ratio.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2018-06-25T11:12:08.577" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7750" PostTypeId="2" ParentId="5652" CreationDate="2018-06-25T13:05:26.983" Score="3" Body="&lt;p&gt;While the existing answer adress your question quite well, I'd like to add some general advice, even if you might already be aware of that. Rather than just &lt;em&gt;wasting&lt;/em&gt; that fourth component on the GPU, you might as well &lt;strong&gt;use it for additional data&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It might be an obvious suggestion, but a 4th unused 32-bit word can store a variety of useful data:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;8-bit RGBA colour components.&lt;/li&gt;&#xA;&lt;li&gt;2D texture coordinates in either 16-bit half-precision floating point or normalized fixed-point format, depending on your precision and range requirements.&lt;/li&gt;&#xA;&lt;li&gt;packed normal data using some of the excellent normal compression formats discussed in &lt;a href=&quot;http://jcgt.org/published/0003/02/01/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this survey of unit vector representations&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This would let you use packed 128-bit SSE copy instructions for uploading data (especially since mapped buffer memory is usally well aligned) after just a bit of (easily SSE-optimizable) packing. Of course the viablity of this highly depends on your data. But if you have e.g. 5 floats for position and texCoord or 6 for position and normal, trying one of these schemes might be a neat consideration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And using 4-component vectors for your vertices on the GPU can have additional advantages beyond just SSEability on the CPU.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It &lt;em&gt;might&lt;/em&gt; help your &lt;strong&gt;GPU optimize on-chip memory reads/writes&lt;/strong&gt; if your data is well aligned (although, of course it has to be measured individually if there's a practical advantage).&lt;/li&gt;&#xA;&lt;li&gt;But even disregarding performance it can make development a little more convenient, too. Speaking from OpenGL experience, &lt;a href=&quot;https://computergraphics.stackexchange.com/q/5810/6&quot;&gt;using 3-component vertex data in shader storage buffers (i.e. for advanced memory access and/or compute shaders) is a bit of a hassle&lt;/a&gt; because of GLSL's data layout. A buffer filled with &lt;strong&gt;4-component vectors makes for generally cleaner and more streamlined code&lt;/strong&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-06-25T13:05:26.983" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7751" PostTypeId="1" CreationDate="2018-06-25T23:04:59.637" Score="0" ViewCount="764" Body="&lt;p&gt;i am a beginner to opengl following an online guide, &#xA;I am trying to make a simple translation to my triangle.&#xA;The triangle did render correctly when i made a float uniform to translate it, but when i multiply a mat4 to translate it, i get a black screen.&#xA;Opengl outputs no error, i can't tell where is the problem.&#xA;Here is the code:&#xA;&lt;a href=&quot;https://pastebin.com/en2zpPTh&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pastebin.com/en2zpPTh&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's my drawing loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Loop until window close&#xA;while (!glfwWindowShouldClose(mainWindow))&#xA;{&#xA;    //Get + Handle user input events&#xA;    glfwPollEvents();&#xA;&#xA;    if (direction)&#xA;    {&#xA;        triOffset += triIncrement;&#xA;    }&#xA;    else&#xA;    {&#xA;        triOffset -= triIncrement;&#xA;    }&#xA;&#xA;    if (abs(triOffset &amp;gt;= triMaxOffset))&#xA;    {&#xA;        direction = !direction;&#xA;    }&#xA;&#xA;    //Clear window&#xA;    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;    //Draw&#xA;    glUseProgram(shader);&#xA;&#xA;    glm::mat4 model;&#xA;    /*&#xA;    [1,0,0,0]&#xA;    [0,1,0,0]&#xA;    [0,0,1,0]&#xA;    [0,0,0,1]&#xA;    */&#xA;    model = glm::translate(model, glm::vec3(triOffset, 0.0f, 0.0f));&#xA;&#xA;    glUniformMatrix4fv(uniformModel, 1, GL_FALSE, glm::value_ptr(model));&#xA;&#xA;&#xA;    glBindVertexArray(VAO);&#xA;    glDrawArrays(GL_TRIANGLES, 0, 3);&#xA;&#xA;    glBindVertexArray(0);&#xA;    glUseProgram(0);&#xA;&#xA;    glfwSwapBuffers(mainWindow);&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and here's my vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Vertex Shader&#xA;static const char* vShader = &quot; \n&quot;&#xA;&quot;#version 330                  \n&quot;&#xA;&quot;layout (location = 0) in vec3 pos;\n&quot;&#xA;&quot;uniform mat4 model;                        \n&quot;&#xA;&quot;void main()\n&quot;&#xA;&quot;{\n&quot;&#xA;&quot;   gl_Position = model * vec4(pos, 1.0);\n&quot;&#xA;&quot;}\n&quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Fragment shader&#xA;static const char* fShader =  &quot; \n&quot;&#xA;&quot;#version 330                  \n&quot;&#xA;&quot;out vec4 color;               \n&quot;&#xA;&quot;void main()\n&quot;&#xA;&quot;{\n&quot;&#xA;&quot;   color = vec4(1.0, 1.0, 0.5, 1.0);\n&quot;&#xA;&quot;}\n&quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8935" LastEditorUserId="3003" LastEditDate="2018-06-26T02:34:57.873" LastActivityDate="2018-06-26T10:08:48.557" Title="Opengl black screen for a simple translation" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7753" PostTypeId="2" ParentId="7751" CreationDate="2018-06-26T10:08:48.557" Score="1" Body="&lt;p&gt;We fixed it ! it was glm::mat4(); no initializing to a identity matrix, glm::mat4(1.0f); works fine, thank you for helping me !&lt;/p&gt;&#xA;" OwnerUserId="8935" LastActivityDate="2018-06-26T10:08:48.557" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7754" PostTypeId="1" CreationDate="2018-06-26T13:11:22.913" Score="1" ViewCount="111" Body="&lt;p&gt;Having an HLSL shader like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct FragmentIn&#xA;{&#xA;    float4 Position : SV_Position;&#xA;    float4 Color : COLOR0;&#xA;};&#xA;&#xA;struct Oct&#xA;{&#xA;    ...&#xA;};&#xA;&#xA;float3 Camera;&#xA;float heading;&#xA;Oct data[9];&#xA;&#xA;float4 FS(FragmentIn input) : SV_Target0&#xA;{&#xA;    ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;... how would one supply the uniforms and execute it directly for all pixels?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the &lt;a href=&quot;https://mellinoe.github.io/veldrid-docs/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Veldrid&lt;/a&gt; framework.&lt;/p&gt;&#xA;" OwnerUserId="8125" LastActivityDate="2018-06-26T13:11:22.913" Title="Veldrid: Only execute fragment shader" Tags="&lt;fragment-shader&gt;&lt;uniform-buffer-object&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7755" PostTypeId="2" ParentId="5731" CreationDate="2018-06-27T07:43:02.357" Score="0" Body="&lt;p&gt;For a 3D terrain, you can triangulate using the points projected onto the XY-plane. This is easily implemented in CGAL using the &lt;a href=&quot;https://doc.cgal.org/latest/Kernel_23/classCGAL_1_1Projection__traits__xy__3.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Projection_traits_xy_3&lt;/a&gt; class, as in this terrain triangulation &lt;a href=&quot;https://doc.cgal.org/latest/Triangulation_2/index.html#Subsection_2D_Triangulations_Delaunay_Terrain&quot; rel=&quot;nofollow noreferrer&quot;&gt;example&lt;/a&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the fusion of the road triangulation you can use a &lt;a href=&quot;https://en.wikipedia.org/wiki/Constrained_Delaunay_triangulation&quot; rel=&quot;nofollow noreferrer&quot;&gt;constrained Delaunay triangulation&lt;/a&gt;. You constrain the road mesh and insert the regular grid points of the terrain mesh to construct the full triangulation. See this &lt;a href=&quot;https://doc.cgal.org/latest/Triangulation_2/index.html#Subsection_2D_Triangulations_Polygon_triangulation&quot; rel=&quot;nofollow noreferrer&quot;&gt;code&lt;/a&gt; for an example of how to use CGAL's constrained Delaunay triangulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This should enable you to solve the problem without going into the details of the triangles.&#xA;If the result is not good enough, you can always refine the mesh by inserting additional points in problematic triangles.&lt;/p&gt;&#xA;" OwnerUserId="8749" LastActivityDate="2018-06-27T07:43:02.357" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7756" PostTypeId="2" ParentId="7707" CreationDate="2018-06-27T13:33:21.860" Score="0" Body="&lt;p&gt;I really haven't read the whole thing. But I think what the author means for the second part is that: The position or coordinate is in a continuous space i.e x = 1.2345 , y = 2.3455 (floating point) The integer value of this is just 1 and 2 respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps!&lt;/p&gt;&#xA;" OwnerUserId="8920" LastActivityDate="2018-06-27T13:33:21.860" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7757" PostTypeId="1" AcceptedAnswerId="7765" CreationDate="2018-06-27T20:18:52.603" Score="5" ViewCount="122" Body="&lt;p&gt;It's easy to find guides to calculating the transmitted direction of light given an incoming direction, the normal, and indexes of refraction. However, I can't find anything about determining the normal, given all the other information. That's understandable because it's a bit of an odd thing to do, but I think I need it in my bidirectional path tracer to correctly weight paths that involve a microfacet surface. Even if it turns out that I don't, at this point I'm curious. I know that it's not possible if both indexes of refraction are the same, but that's fine.&lt;/p&gt;&#xA;" OwnerUserId="8946" LastEditorUserId="8946" LastEditDate="2018-06-27T21:03:42.957" LastActivityDate="2018-07-01T03:21:21.590" Title="Refraction: given an incoming and transmitted direction, can I deduce the normal?" Tags="&lt;brdf&gt;&lt;vectors&gt;&lt;refraction&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7758" PostTypeId="2" ParentId="7738" CreationDate="2018-06-27T20:35:02.033" Score="1" Body="&lt;p&gt;UV or barycentric coordinates represent a point on a triangle as a weighted average of the three vertexes. You can use those coordinates to smoothly interpolate any value over the triangle, like texture coordinates or the normal vector. So think of it like a two-step process. We map the world coordinates of the intersection point to uv coordinates in &quot;triangle space&quot;, and then use those to map to another space, in this case &quot;texture space&quot;. Your ray hits triangle ABC and you determine the uv coordinates of the intersection point, let's say (0.3, 0.5, 0.2). Intuitively, we're sort of saying the intersection point is 30% A, 50% B, and 20% C. Each vertex would have a texture coordinate, i.e. a pixel in the texture image, associated with it (that's part of modeling / setting up your scene, not something calculated at runtime). Mix the texture coordinates at A, B and C in that ratio and you'll get the point on the texture image associated with that point on the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/barycentric-coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;This scratchapixel page&lt;/a&gt; has some good diagrams and clear explanation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;edit: I'm sorry, I missed the part about how to calculate the coordinates in the first place. The page I linked explains it better than I could anyway.&lt;/p&gt;&#xA;" OwnerUserId="8946" LastEditorUserId="8946" LastEditDate="2018-06-27T20:45:02.697" LastActivityDate="2018-06-27T20:45:02.697" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7759" PostTypeId="2" ParentId="7757" CreationDate="2018-06-27T21:53:35.727" Score="0" Body="&lt;p&gt;It should be possible I think. Take the reflection equation: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;R = 2*Dot(N,I)*N -I, where I is the incidence.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Make an equation for every component of the vector i.e. x,y,z&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You now have 3 equations and 3 unknowns. However, due to Dot(N,I)*N, I don't think this system is linear. So a unique solution probably wont exist.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But why do you need this? If you have an intersection point at a surface, you should have the normal for that surface?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps&lt;/p&gt;&#xA;" OwnerUserId="8920" LastActivityDate="2018-06-27T21:53:35.727" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7760" PostTypeId="1" CreationDate="2018-06-28T07:30:51.393" Score="4" ViewCount="299" Body="&lt;p&gt;I have to do some operations on 2D grayscale images. The &quot;normal&quot; stuff like moving, alpha blending and resizing, but also &quot;3D like&quot; operations: Perspective projection, rotation around any axis (x, y, z).&lt;br&gt;&#xA;All this happens in an embedded system, where I can choose from microcontrollers with &quot;2D GPU&quot; (e.g. Vivante GC355), &quot;3D GPU&quot; (Vivante GC3000), &quot;no GPU&quot; (Arm A53).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Safe approach: Take the 3D GPU and use OpenGL operations (e.g. &quot;Rotate&quot;) to do the jobs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But how can I find out the &lt;strong&gt;minimum&lt;/strong&gt; requirements?&#xA;In case of the &quot;no GPU&quot; approach it's quite easy to estimate the CPU cycles for each operation and extrapolate.&lt;br&gt;&#xA;How to do this for a GPU? The specifications say things like &quot;x million pixels per second&quot; - but what can it do to these pixels in that second?&#xA;The tutorials I found so far say nothing about it.&lt;/p&gt;&#xA;" OwnerUserId="6346" LastActivityDate="2018-06-28T18:28:04.420" Title="How to estimate what GPU (2D/3D/none at all?) is necessary?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7761" PostTypeId="2" ParentId="7760" CreationDate="2018-06-28T18:28:04.420" Score="3" Body="&lt;p&gt;There are really two things you need to know about your application:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How many pixels do you need to push per second?&lt;/li&gt;&#xA;&lt;li&gt;How many cycles do you need to spend on each?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For the first, you need to sum the size of your output framebuffer and all the intermediates to count the number of pixels written in each frame. Make sure to include overdraw: if you draw a full-screen background, and then draw a foreground that covers half of the frame, you need to multiply by $1.5$. Then just divide that by your frame time (e.g. 33 ms if you need to reach 30 fps) to count the pixels per second.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To count cycles, you need to know what size of program will be run on each pixel. For a transformation or colour correction, it might just be a couple of multiply-adds. Somebody who would write the shader code (or the Neon code in the no-GPU case) should be able to work this out for you. It'll be easier if you have a prototype running on a desktop GPU already.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also two important properties of the hardware to consider. First is the pixel fill rate, which you've already seen. This tends to be limited by the memory bandwidth of the system-on-chip instead of by the CPU or GPU itself. If you're buying GPU IP and integrating it into the chip itself, you'll need to talk to the vendor's application support people to find out what your design can achieve. If you're buying a whole system-on-chip, just use the value from the spec sheet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second is your cycle budget. This depends on the GPU or FPU itself, not on the memory bandwidth, so it's easier to calculate. You just need to talk to the silicon vendor to determine this. For a GPU it'll be the number of cores times the clock speed divided by the instruction cycles per clock - but more realistically, look at a synthetic benchmark for this chip to see its megaflops.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Comparing your number of pixels per second with what the system can achieve is easy, but you also need to multiply this by the cycles per pixel you want to spend, to get the total number of cycles per second you need, and compare this with what the compute core offers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't forget you also need to weigh the difference in BOM cost and software complexity against the risk and cost of a board respin, and multiply your estimate by some fudge factor appropriate to your project risk. We can't help you with that part here :-)&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-06-28T18:28:04.420" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7762" PostTypeId="1" CreationDate="2018-06-29T19:17:39.573" Score="-1" ViewCount="79" Body="&lt;p&gt;i am trying to work through some of the &lt;a href=&quot;http://pyopengl.sourceforge.net/context/tutorials/shader_4.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;tutorials for pyopengl&lt;/a&gt; and cant seem to get it working.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the only message i'm getting is a warning:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;python tutorial4.py&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;No handlers could be found for logger &quot;OpenGL.arrays.numpymodule&quot;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;no opengl context/screen pops up. script just exits.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;id love any thoughts or feedback that might help me move forward,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/yvan/f34ad04c1ae32a41482ac1295871fffd&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gist.github.com/yvan/f34ad04c1ae32a41482ac1295871fffd&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8952" LastActivityDate="2018-07-01T08:48:53.460" Title="Cant seem to get pyopengl tutorial 4 to work" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7763" PostTypeId="1" CreationDate="2018-06-30T14:30:04.263" Score="1" ViewCount="73" Body="&lt;p&gt;What is the best way to prove if three points are linear dependent?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my current way to do it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\mathbf{v_a} = \mathbf{b}-\mathbf{a} \\&#xA;\mathbf{v_b} = \mathbf{c}-\mathbf{a} \\&#xA;\mathbf{v_c} = \begin{pmatrix} -\mathbf{v_{a,y}} \\ \mathbf{v_{a,x}} \end{pmatrix} \\&#xA;\phi = \mathbf{\hat{v}_c} \cdot \mathbf{\hat{v}_b} \\&#xA;\phi &amp;lt; 10^{-3}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\phi$ is the $arccos$ of the real angle between the two vectors. This works good if the polygon or the three points of the polygon have well defined distances. But what if the polygon looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SrXqi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SrXqi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The distance between $P_0$ and $P_1$ is much bigger than between $P_1$ and $P_2$. $P_0$, $P_1$ and $P_2$ are of clearly not linear dependent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm searching for a scale-independent algorithm for that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any ideas or a reference to a paper I can read about it?&lt;/p&gt;&#xA;" OwnerUserId="5828" LastActivityDate="2020-05-21T13:00:14.877" Title="Linear independence of three points" Tags="&lt;mathematics&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7764" PostTypeId="2" ParentId="7763" CreationDate="2018-06-30T23:47:55.377" Score="3" Body="&lt;p&gt;Normalize $v_a$ and $v_b$ and your algorithm should no longer depend on the length of the edges, unless you consider numerical stability.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the &quot;best way&quot;, I'm not sure there's a much better algorithm but I would try a better definition of the tolerance. Instead of a fixed value, I would use differentials to compute the change in the angle for a change of the inputs of a few &lt;a href=&quot;https://en.wikipedia.org/wiki/Unit_in_the_last_place&quot; rel=&quot;nofollow noreferrer&quot;&gt;ulps&lt;/a&gt;. If the resulting range overlaps 0, then I think the points are colinear within available precision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whether that complexity is justified depends on what you're doing with this, which you did not specify. A constant could be fine or even the best choice for some uses.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-06-30T23:47:55.377" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7765" PostTypeId="2" ParentId="7757" CreationDate="2018-07-01T03:21:21.590" Score="2" Body="&lt;p&gt;See equation (16) in &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt; : $-(\eta_i w_i + \eta_o w_o)$ which you'll probably want to normalize. $\eta$ are the two indices of refraction and $w$ the two vectors (they use $i$ and $o$ in the paper). Also look at the left part of figure 7 on the same page to see where all the vectors are pointing.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-07-01T03:21:21.590" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7766" PostTypeId="2" ParentId="7762" CreationDate="2018-07-01T08:48:53.460" Score="1" Body="&lt;p&gt;solved:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;i misspelled &lt;code&gt;glEnableVertexAttribArray&lt;/code&gt; as &lt;code&gt;glEnableVerexAttribArray&lt;/code&gt;. i'm not sure why opengl fails silently when i misspell the name of my pointer object. shouldn't it throw a name error or something? maybe &lt;code&gt;verex&lt;/code&gt; is a thing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ok well now we know.&lt;/p&gt;&#xA;" OwnerUserId="8952" LastActivityDate="2018-07-01T08:48:53.460" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7767" PostTypeId="2" ParentId="5652" CreationDate="2018-07-01T23:10:45.130" Score="1" Body="&lt;p&gt;The conversion from option A is likely faster than you think. See, for example, &lt;a href=&quot;https://software.intel.com/en-us/articles/3d-vector-normalization-using-256-bit-intel-advanced-vector-extensions-intel-avx&quot; rel=&quot;nofollow noreferrer&quot;&gt;Intel's version&lt;/a&gt; which claims to do the round trip at 1.5 cycles per vector with AVX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are also some operations which don't require the conversion at all. For example, if you want to compute a bounding box, you can do it directly with the packed data in chunks of 4 vectors and fix things up once you've gone through the entire array.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally a word of warning: a vector class as presented in the article is not how you write high performance code nor how you generally should use SIMD.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-07-01T23:10:45.130" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7769" PostTypeId="1" AcceptedAnswerId="9346" CreationDate="2018-07-03T09:33:20.267" Score="4" ViewCount="573" Body="&lt;p&gt;Is there some algorithm that keeps details when creating mipMaps for SDF?&#xA;For example group of 4 pixels when only one is above threshold will lose this pixel with bilinear and creating mipMaps with 'max' of those values will add noise. &#xA;When purpose of SDF is keeping the same image in lower resolution what is the best way to downsample this image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For generating SDF i use &lt;a href=&quot;http://www.codersnotes.com/notes/signed-distance-fields/&quot; rel=&quot;noreferrer&quot;&gt;8SSEDT&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3123" LastEditorUserId="3123" LastEditDate="2018-07-03T09:45:35.677" LastActivityDate="2019-11-14T02:59:30.000" Title="MipMaps for Signed Distance Field" Tags="&lt;texture&gt;&lt;signed-distance-field&gt;&lt;mipmap&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7771" PostTypeId="1" CreationDate="2018-07-04T19:27:55.407" Score="1" ViewCount="35" Body="&lt;p&gt;Currently I have a naive Mesh data structure to store wavefront files.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This data has 3 buffers for the vertices, normals and UVs. It works well to the point I can render the sponza scene, despite such a scene having multiple inner meshes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is, currently I can onlky render 1 &quot;thing&quot; (I can only have all the mesh associated to a single texture and material properties).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I want to be able to render the sponza scene properly (with all the textures), I need to associate with the vertices different textures and material properties. Based on the information of the associated mtl files.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the proper design to have a Mesh, transform and material objects wrapped in a containing structure such that you can handle complex geometry like the sponza scene?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-04T19:27:55.407" Title="Proper design of data structure to store wavefront file information?" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;mesh&gt;&lt;material&gt;&lt;data-structure&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7772" PostTypeId="1" CreationDate="2018-07-05T22:08:20.813" Score="1" ViewCount="1252" Body="&lt;p&gt;I have a grid with a variable width/height spacing. Let's say 100 horizontal lines separated by 80 pixels and 100 hundred vertical lines separated by 50 pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each cell of the grid in my logic have the same function as a pixel. So each of my pixels will be 50 px width and 100 px height.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to draw a circle filled with a color (let's say black) and without stroke.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also need my circle to (as it is made out of filled cells) be with the less rectangles as possible, so certain rectangles are bigger than other ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for example the center of the circle is made out of one big rectangle then as we go closer to the edge the rectangles becomes smaller.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for example here I have circle with a grid of same width/height spacing made out of 9 rectangles (sorry for the quality of the image)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TVQhu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TVQhu.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Any algorithm to do that?&lt;/p&gt;&#xA;" OwnerUserId="6844" LastEditorUserId="6844" LastEditDate="2018-07-05T22:18:57.430" LastActivityDate="2018-07-08T20:42:49.387" Title="How can I draw a filled circle on a grid with the less rectangle as possible?" Tags="&lt;algorithm&gt;&lt;javascript&gt;&lt;pixel-graphics&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7773" PostTypeId="1" AcceptedAnswerId="7776" CreationDate="2018-07-06T00:25:45.623" Score="1" ViewCount="1061" Body="&lt;p&gt;I have been reading the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Array_Texture&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL documentation&lt;/a&gt; but it is not clear to me how to achieve the following.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say we have an array of strings. Each string in the array is a valid relative path to an image file (.png, .jpeg...)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have a method that can read and store into a GLubyte array the image information of each file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We want to allocate the needed memory for the textures, and save said information into a texture array. However there's no guarantee that the textures are the same dimensions.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-06T14:15:00.110" Title="How do you load multiple textures into an array texture with OpenGL?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;data-structure&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7774" PostTypeId="2" ParentId="3575" CreationDate="2018-07-06T05:24:46.217" Score="4" Body="&lt;p&gt;I would like to give you my graphics beginner perspective on the subject. What I realised (in many years working as an engineer in another field) is that the fundamental concepts are the most important part. Once you have a solid understanding of those, learning the last shiny new API is the least difficult part. I don't know if you are a young hobbiest trying to program the new Skyrim or if you are looking for a job in the CG field.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tell you what I think it's the best approach &lt;strong&gt;in my opinion&lt;/strong&gt; to learn computer graphics &quot;like a pro&quot;.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Learn Linear Algebra and geometry like a pro. Without this, forget any fancy API or graphics&lt;/li&gt;&#xA;&lt;li&gt;Buy a good book on computer graphics (e.g. &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/1482229390&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fundamentals of computer graphics&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;While you study the book, set up a programming environment with something that allows you to draw on an image and implement the algorithms!&#xA;It can be Java 2D or C++ and SDL or even Python and Pygame for what it matters. At this stage you need to get your spinning textured gears with multiple camera views up and running &lt;strong&gt;before&lt;/strong&gt; trying to get 10000 FPS&lt;/li&gt;&#xA;&lt;li&gt;Now take on OpenGL, Vulkan or DirectX and repeat your fancy example (see above).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Starting to worry about performance before understanding how to draw a line is like worrying about the aerodynamics of your car before getting the driving license.&lt;/p&gt;&#xA;" OwnerUserId="3329" LastActivityDate="2018-07-06T05:24:46.217" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7776" PostTypeId="2" ParentId="7773" CreationDate="2018-07-06T14:07:36.593" Score="2" Body="&lt;p&gt;The memory layout of a (2D) array texture is pretty &lt;strong&gt;similar to a 3D texture, with the individual image layers stored one after the other in a big 3D-array of pixels&lt;/strong&gt;. So that's also how you set them. You either load each individual image into a big &lt;code&gt;GLubyte&lt;/code&gt; array one after the other and set it with &lt;code&gt;glTex(Sub)Image3D&lt;/code&gt; or you load each image into its own &lt;code&gt;GLubyte&lt;/code&gt; array and transmit that to the texture with &lt;code&gt;glTexSubImage3D&lt;/code&gt; one after the other (or any other more complex process involving buffers or whatever, but you get the idea).&lt;/p&gt;&#xA;&lt;p&gt;So much to the theory. The problem here is the part where you say&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;However there's no guarantee that the textures are the same dimensions.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This contradicts with how array textures work. As the corresponding documentation you link to says:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;An &lt;strong&gt;Array Texture&lt;/strong&gt; is a Texture where each mipmap level contains an array of images of the same size.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So the &lt;strong&gt;individual layers of an array texture &lt;em&gt;have&lt;/em&gt; to be the same size&lt;/strong&gt;. Simplifyingly said, an array texture is really just a 3D texture without filtering along the z-axis. So you can't get different-sized textures into such a regular box of pixels.&lt;/p&gt;&#xA;&lt;p&gt;There's a few options you have here, though:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;You could &lt;strong&gt;scale every image to a common size&lt;/strong&gt;, depending on &lt;em&gt;how&lt;/em&gt; different they really are and what rescaling means to your quality and/or memory demands.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You could just &lt;strong&gt;drop using array textures&lt;/strong&gt; and implement whatever you want to do with normal 2D textures and a likely more complicated process on the CPU side.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You could use &lt;strong&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Bindless_Texture&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bindless Textures&lt;/a&gt;&lt;/strong&gt;. This is a rather modern non-core feature (only usable through extensions yet) that is really flexible and allows you to &lt;strong&gt;access textures in a shader by using a unique GPU handle&lt;/strong&gt; (a 64-bit ID, so to say). This allows you to use whatever and how many textures you want in a shader, depending on some arbitrarily input value (even a vertex attribute).&lt;/p&gt;&#xA;&lt;p&gt;In this case you wouldn't just a have access to a continuous array of N textures, rather than the wealth of all the textures you have allocated. You would just use normal independent 2D textures and use their respective texture handles rather than an array index. Of course this comes with a few limitations and intricacies, too. But more about that in the corresponding documentation.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-07-06T14:15:00.110" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7777" PostTypeId="1" AcceptedAnswerId="7782" CreationDate="2018-07-06T22:57:27.447" Score="1" ViewCount="74" Body="&lt;p&gt;The C++ psuedo code to transmit the idea of what I want to do would be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Texture_array tarr = Texture_array(6);&#xA;tarr[0] = texture;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which I am attempting to do as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);&#xA;    glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, 894, 894, 6);&#xA;    glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 894, 894, 0, color_format, GL_UNSIGNED_BYTE, data);&#xA;    //Set the texture parameters of the image&#xA;    glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);&#xA;    glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);&#xA;    glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;    glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;On the fragment shader I attempt to read the value as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 c = vec3(texture(text, vec3(f_uv.xy,0)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However the end result is completely blak, despite data being an array of a valid texture (I have tested it and know data has been properly initialized, it works with normal textures, just not texture arrays)&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-09T05:52:47.547" Title="How to assign a texture to a single entry of a texture array?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;data-structure&gt;&lt;3dtexture&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7778" PostTypeId="2" ParentId="7777" CreationDate="2018-07-07T02:56:26.683" Score="2" Body="&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, 894, 894, 0, color_format, GL_UNSIGNED_BYTE, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You're transmitting 3D data. But you told OpenGL that the 3D block of data has a depth of 0. So the number of pixels you're transmitting is... 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have no idea why OpenGL doesn't provide an error when passing 0 for any of the sizing components (since that means you're not passing data). But that's your problem. You need to pass 1 for the depth if you're uploading a single 2D slice to the array.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2018-07-07T13:12:22.163" LastActivityDate="2018-07-07T13:12:22.163" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7779" PostTypeId="1" AcceptedAnswerId="7792" CreationDate="2018-07-08T11:00:42.953" Score="3" ViewCount="647" Body="&lt;p&gt;I've been making a simple game in OpenGL, and implemented a screen fade-out using the old 'draw a black fullscreen quad and ramp up the alpha' trick. I'm doing all my shaders in linear space and using &lt;code&gt;GL_FRAMEBUFFER_SRGB&lt;/code&gt; to automatically apply gamma. When fading out the screen I noticed that the alpha blending also becomes nonlinear - to fade to ~25% brightness I need to use an alpha of ~0.95. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I fired up Unity for comparison, and its alpha blending also seems to work this way - when rendering in linear mode most of the opacity is bunched towards the top of the alpha range. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this expected behaviour? Is it correct from a PBR point of view? It seems very unintuitive. As a workaround, to get more intuitive blending, would it be reasonable to apply gamma correction of 0.45 to the alpha channel before blending?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: this is the result I get after blending a .95 alpha black quad over a pure white button. It could be bad gamma on my display as Simon F suggested in the comments, but it looks a lot brighter than 5% to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/M7Ybs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M7Ybs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1937" LastEditorUserId="1937" LastEditDate="2018-07-09T16:29:23.813" LastActivityDate="2018-07-10T13:16:35.727" Title="Alpha blending in linear colour space" Tags="&lt;blending&gt;&lt;colorspace&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7780" PostTypeId="1" AcceptedAnswerId="7798" CreationDate="2018-07-08T11:40:49.660" Score="0" ViewCount="152" Body="&lt;p&gt;The BRDF takes two directions, $\omega_{o}$ and $\omega_{i}$. I've heard that both directions should point away from the surface (one towards the camera, one towards the light), but &lt;a href=&quot;https://www.shadertoy.com/view/ldBGz3&quot; rel=&quot;nofollow noreferrer&quot;&gt;iq's Oren-Nayar example shader&lt;/a&gt; has rays pointing away from the camera and works flawlessly. Are BRDFs &lt;em&gt;strictly&lt;/em&gt; defined for rays pointing away from the surface, or am I misreading things and iq's approach is preferred?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-07-12T05:19:16.937" LastActivityDate="2018-07-18T03:46:18.277" Title="BRDF ray directions" Tags="&lt;pathtracing&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="7781" PostTypeId="2" ParentId="186" CreationDate="2018-07-08T15:17:42.233" Score="3" Body="&lt;p&gt;As other answers have mentioned, there are multiple competing formats for storing 3D data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, one specific format has appeared since this question was asked, that has many characteristics you'd expect from a &quot;standard&quot;: &lt;strong&gt;the glTF format&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;glTF is a 3D standard published by the Khronos Group (the organization behind OpenGL and Vulkan), that aims to make up for the flaws in Collada.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Its main advantages are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;It's JSON-based, which makes it very easy to parse, serialize, read, and send over network.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;There is very little ambiguity or redundancy in the standard (though there is some*). The units, handedness, texture coordinates signs, etc are all standardized; everything is always index-based, which means there is no data redundancy. This makes it really easy to write an importer.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The documentation is very clean and exhaustive.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The layout of the data is based on the OpenGL/WebGL workflows, which means that imported models can be used as in-engine data with little plumbing.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The standard is Open Source, and the specification is hosted on Github. That means the standard will always be available, usable for free, and the development process is visible to everyone. By opposition, the future of closed-source standards is decided by private interests, which is inherently dangerous.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;glTF is supported by many industry giants through Khronos (Adobe, Google, Microsoft, Mozilla, Unity); it can be exported by Blender (exporting from Maya is still officially unsupported), and imported by Unreal, Unity and Godot.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;See also:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/gltf/&quot; rel=&quot;nofollow noreferrer&quot;&gt;The official glTF overview&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://godotengine.org/article/we-should-all-use-gltf-20-export-3d-assets-game-engines&quot; rel=&quot;nofollow noreferrer&quot;&gt;Why we should use glTF 2.0 by the Godot Engine team&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;* I'm pretty sure the variable-handedness tangents are pointless.&lt;/p&gt;&#xA;" OwnerUserId="8660" LastActivityDate="2018-07-08T15:17:42.233" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7782" PostTypeId="2" ParentId="7777" CreationDate="2018-07-08T17:38:15.103" Score="2" Body="&lt;p&gt;The full explanation of what I was doing wrong is: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The depth parameter in the &lt;code&gt;glTexSubimage3D&lt;/code&gt; refers to the depth of the data being sent. Since I am trying to send a single layer this depth should be 1 not 0 (the depth of an image/layer) (As explained by Nicol Bolas).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The zoffset parameter in the same function refers to the offset in layers where the data will be put inside the texture array.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, following the array analogy, this is the value inside of the brackets. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct approach would thus be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 2, 894, 894, 1, color_format, GL_UNSIGNED_BYTE, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which in C++ pseudo code would be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Texture_Array[2] = texture;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-07-09T05:52:47.547" LastActivityDate="2018-07-09T05:52:47.547" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7783" PostTypeId="2" ParentId="7772" CreationDate="2018-07-08T20:42:49.387" Score="1" Body="&lt;p&gt;To get a proper circle, you can use a transformation matrix to transform your cell coordinates into equally spaced cartesian coordinates. In the case of your 50 x 100 pixel cells, your transformation matrix would probably either double the width or halve the height. So something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;| 0.5 0.0 |&#xA;| 0.0 1.0 |&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you want to draw a circle of radius &lt;code&gt;r&lt;/code&gt; at a center point &lt;code&gt;(cx, cy)&lt;/code&gt;, you could iterate over the cells from &lt;code&gt;(cx - r, cy - r)&lt;/code&gt; to &lt;code&gt;(cx + r, cy + r)&lt;/code&gt; and test if each one is in the circle, and if so, fill it in, otherwise, don't. Something like this pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double rSquared = r * r;&#xA;for (int row = cy - r; row &amp;lt; cy + r; row++)&#xA;{&#xA;    for (int col = cx - r; col &amp;lt; cx + r; col++)&#xA;    {&#xA;        double x = col * transform[0][0] + row * transform[0][1];&#xA;        double y = col * transform[1][0] + row * transform[1][1];&#xA;        double distSquared = x * x + y * y;&#xA;        if (distSquared &amp;lt;= rSquared)&#xA;        {&#xA;            // inside the circle, fill in this cell (col, row)&#xA;        }&#xA;        else&#xA;        {&#xA;            // outside the circle, don't fill in this cell (col, row)&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As for drawing rectangles, it's not clear what you're trying to accomplish there. There's no need to use rectangles when drawing a circle.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-07-08T20:42:49.387" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7784" PostTypeId="1" CreationDate="2018-07-09T04:08:52.930" Score="1" ViewCount="110" Body="&lt;p&gt;It has often been recommended to avoid branching conditions in shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why? What happens exactly in modern GPUs in that case? &#xA;Is it still recommended to avoid branching?&lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="6" LastEditDate="2018-07-09T21:55:17.070" LastActivityDate="2018-07-09T21:55:17.070" Title="How do modern GPUs handle branching instructions in shader code?" Tags="&lt;shader&gt;&lt;gpu&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7785" PostTypeId="1" CreationDate="2018-07-09T04:18:45.017" Score="1" ViewCount="416" Body="&lt;p&gt;A compute shader defines the number of threads it requires to be executed.&lt;br&gt;&#xA;This number can be called &quot;local size&quot; or &quot;threadgroup size&quot; according to the API, and be factored into 3 separate dimensions X * Y * Z.&#xA;If an algorithm only requires at minimum a small number of threads to be executed, is it more performant to define this number as the local size, and let the GPU handle the parallelization of its execution over a large data-set?&lt;br&gt;&#xA;Or is there any benefit in using a bigger local size?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2018-07-09T04:18:45.017" Title="Is a smaller local-size/threadgroup-size better for compute shader performance?" Tags="&lt;performance&gt;&lt;compute-shader&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7786" PostTypeId="1" AcceptedAnswerId="7796" CreationDate="2018-07-09T21:54:29.177" Score="3" ViewCount="203" Body="&lt;p&gt;Perspective projection (or at least non-orthogonal) is by far the most common in photo-realistic graphics. When we use perspective projection, the (equally thick) slices of volume visualized by each pixel get larger with the distance. But with ray tracing we normally cast cylinder-like rays instead of cones. It seems to me that this must make quite a difference to the results: consider the two fields of view of pixels: cone-like one at the LHS, and cylinder-like one at the RHS, the pixels are at the bottom:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/X8rGB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X8rGB.jpg&quot; alt=&quot;pixels&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The colored lines here represent walls of randomly-distributed light sources with the same density in each wall. If we assume that the intensities of the light sources are the same, so that one of the pixels would &quot;see&quot; white average color, the other must necessarily have a color tint, because the left one samples more red compared to blue than the right one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I right in this? If so, why does then &lt;em&gt;ray&lt;/em&gt; tracing work? Why don't we do &quot;frustum tracing&quot; or &quot;cone tracing&quot; to get the colors/illuminances right? And if I'm wrong, then what is my mistake?&lt;/p&gt;&#xA;" OwnerUserId="4647" LastActivityDate="2018-07-11T18:37:33.133" Title="Why does _ray_ tracing work?" Tags="&lt;raytracing&gt;&lt;color&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7788" PostTypeId="1" CreationDate="2018-07-10T04:38:01.433" Score="1" ViewCount="56" Body="&lt;p&gt;Say we've idetified that we have a varying number of textures that are upper capped by 2 parametrs. thus we allocate the maximum amount of memory needed to store all textures as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8, max_width, max_height, texture_num);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;One by one we allocate each texture to each layer as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, file, width, height, 1, color_format,&#xA;            GL_UNSIGNED_BYTE, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now since for  some textures width &amp;lt; max_width and height &amp;lt; max_height, when sampling, our sample is off as trying to sample at a value of 1 would result in sampling outside of the bounds of the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One could naively try to solve the issue by multiplying the sampling coordinate by the stretching coefficient.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uv*=width/max_width.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However this only solves the problem for sampling that happens within the (-1,1) rnage. However, any texture that is meant to be tiled will be wrong. Thus we must do floating mod as well. the final calculation is thus:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;u = (u*width/max_width)%(width/max_width)&#xA;v = (v*height/max_height)%(height/max_height)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(Each coordinate is differnece since the vertical stretch could be different from the horizontal stretch)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus to do our final rendering we would need to create and store an array of vec2's where the first value is the horizontal stretching coefficient and the second value is the vertical stretching coefficient on teh CPU. Then load that into a uniform buffer or SSBO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And read these values on the shader side. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems a little bit cumbersome. Is there a way to instruct OpenGL to handle these varying sizes or is the only way to solve this issue the one I described?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-10T04:38:01.433" Title="Handling varying texture sizes in an array texture" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;c++&gt;&lt;uv-mapping&gt;&lt;3dtexture&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7789" PostTypeId="1" AcceptedAnswerId="7791" CreationDate="2018-07-10T08:36:30.167" Score="3" ViewCount="1195" Body="&lt;p&gt;I am getting weird artifacts in my simple ray tracer that I made using the book &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/B01B5AODD8&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing in One Weekend&lt;/a&gt; by Peter Shirley. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3Gl6W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3Gl6W.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;(circular pattern on the ground and black tint on the spheres.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect these artifacts are due to hit point of the primary rays being under or above the surface, which causes secondary rays to intersect with the object itself. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to fix this by moving the hit point of primary rays along the surface normal at that point. Here's the result :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bjk8e.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bjk8e.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The artifacts are gone but that broke the dielectric material (sphere on the left). It is acting as a reflective sphere rather than a transparent one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Code for the dielectric material :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;virtual bool scatter(const Ray &amp;amp;inRay, const HitInfo &amp;amp;hitInfo, Vector3 &amp;amp;attenuation, Ray &amp;amp;scatteredRay) const {&#xA;    attenuation = Vector3(1.0f);&#xA;    Vector3 normal;&#xA;    Vector3 refracted;&#xA;    float refractiveIndexRatio; //n1/n2 = sin(a2)/sin(a)&#xA;    float cosine = 0.0f;&#xA;&#xA;    if (hitInfo.hitNormal * inRay.direction() &amp;gt; 0) {&#xA;        normal = -hitInfo.hitNormal;&#xA;        refractiveIndexRatio = refractiveIndex;&#xA;        cosine = hitInfo.hitNormal * inRay.direction();&#xA;    }&#xA;    else {&#xA;        normal = hitInfo.hitNormal;&#xA;        refractiveIndexRatio = 1.0f/refractiveIndex;&#xA;        cosine = -hitInfo.hitNormal * inRay.direction();&#xA;    }&#xA;&#xA;&#xA;    float reflectProb = 0.0f;&#xA;&#xA;    if (Vector3::refract(inRay.direction(), normal, refractiveIndexRatio, refracted)) {&#xA;        reflectProb = schlickApproximation(cosine, refractiveIndex);&#xA;    }&#xA;    else {&#xA;        reflectProb = 1.0f;&#xA;    }&#xA;&#xA;    if (randomfloatGenerator() &amp;lt; reflectProb) {&#xA;        Vector3 reflected(Vector3::reflect(inRay.direction(), normal));&#xA;        scatteredRay = Ray(hitInfo.hitPoint + normal * CORRECTION_FACTOR, reflected);&#xA;    }&#xA;    else {&#xA;        scatteredRay = Ray(hitInfo.hitPoint + normal * CORRECTION_FACTOR, refracted);&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I changed &lt;code&gt;hitInfo.hitPoint&lt;/code&gt; to &lt;code&gt;hitInfo.hitPoint + normal * CORRECTION_FACTOR&lt;/code&gt;, in the &lt;code&gt;if - else&lt;/code&gt; case at the bottom of the function, to correct those artifacts. (&lt;code&gt;CORRECTION_FACTOR = 0.0001f&lt;/code&gt;)  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I correct this &quot;self intersection&quot; problem without breaking my materials ?&lt;/p&gt;&#xA;" OwnerUserId="9002" LastActivityDate="2018-07-10T09:32:54.727" Title="Weird artifacts in my ray tracer" Tags="&lt;rendering&gt;&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7790" PostTypeId="2" ParentId="7786" CreationDate="2018-07-10T08:59:04.867" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;But with ray tracing we normally cast cylinder-like rays instead of cones.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Rays aren't really cylinders: they're infinitely thin. This infinitely thin ray can be an approximation to the cone just as much as it can be an approximation to the cylinder.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If we assume that the intensities of the light sources are the same, so that one of the pixels would &quot;see&quot; white average color, the other must necessarily have a color tint ... Am I right in this?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Sort of. Your left-hand diagram &lt;em&gt;doesn't&lt;/em&gt; have a colour tint. Although it covers more of the red wall than the blue wall, both of them subtend the same solid angle from the camera's point of view. The same $\tfrac{1}{r^2}$ ratio between the amount of light included in the cone is exactly countered by the $\tfrac{1}{r^2}$ falloff of the light. If the world worked the way you describe, you could make anything brighter by moving it further away from your eye. The right-hand diagram would have a blue colour tint, because the blue light is closer, but this diagram is not how ray-tracing works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There has been research in a few variants of &lt;em&gt;beam tracing&lt;/em&gt;, where instead of tracing an infinitely thin ray, you trace a cylinder, or &lt;em&gt;cone tracing&lt;/em&gt;, where you trace a cone or frustum as a simple approximation to the irregular solid that contributes to the pixel. The maths (and therefore the algorithm) are somewhat more complex (and therefore slower) than simple ray tracing, and then you have to deal with what happens when the cone partially intersects an object, and you have to use the same shape to approximate the continued path of the cone. These approaches never caught on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, supersampling with rays offers the same advantages as cone tracing but with the performance advantage of doing the same simple algorithm many times. You don't supersample by moving the origin of the rays, which would make a cylinder shape, but by varying the directions, which makes a cone shape. Instead of approximating that cone by a single ray along its axis, you're approximating it by (say) 32 rays spread throughout its volume.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-10T08:59:04.867" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7791" PostTypeId="2" ParentId="7789" CreationDate="2018-07-10T09:32:54.727" Score="2" Body="&lt;p&gt;When spawning the refraction/transmission ray, don't adjust the ray origin by adding the normal: adjust it by &lt;em&gt;subtracting&lt;/em&gt; the normal. This moves the ray origin inside the object, so it won't immediately self-intersect. Your current problem is caused by all your refraction rays immediately hitting the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't forget that for accurate refractions, the ray needs to be able to intersect with the inside or back face of the object as well. If you're intersecting back-facing surfaces, you need to flip the normal before shading or adding/subtracting it to the origin.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-10T09:32:54.727" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7792" PostTypeId="2" ParentId="7779" CreationDate="2018-07-10T13:09:26.740" Score="3" Body="&lt;p&gt;&lt;em&gt;Just turning the comments into a fully-fledged answer as it&lt;/em&gt; may &lt;em&gt;prove useful to others&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IMHO, the alpha channel should always be linear and treated as such.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You described blending a black quad over a white background using alpha=0.95, and mapping the result back to non-linear space. We'd expect a resulting, physical intensity value of 0.05.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the non-linear space is sRGB, then a linear value of &quot;0.05&quot; would correspond to an sRGB value of &quot;0.248&quot; which, when mapped to 8-bit, is around 63 (or hex, 3D)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your display is reasonably calibrated, you can verify this by creating, say, a 5x4 black image, setting one pixel to white, and then tiling that to a suitable size, e.g 200x200 pixels. Then draw a, say, 50x50 square in the middle and fill it with 0x3D3D3D. Here's an example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cYTA5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cYTA5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you take a few steps back from your monitor and squint, the centre grey region and the dithered outer should be almost indistinguishable, demonstrating a correct physical model. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem you are describing appears to be related to the fact that our visual system is non-linear, much as our hearing is too (though probably not with the same curve). For example, the analogue volume control on a hifi amplifier will use a &lt;a href=&quot;http://electronics.stackexchange.com/questions/101191/&quot;&gt;logarithmic potentiometer rather than a linear one&lt;/a&gt; . &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You thus 'simply' need to change your per-frame alpha non-linearly to get a &lt;em&gt;perceptually&lt;/em&gt; even fade out.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-07-10T13:16:35.727" LastActivityDate="2018-07-10T13:16:35.727" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7793" PostTypeId="1" CreationDate="2018-07-10T13:46:37.680" Score="1" ViewCount="68" Body="&lt;p&gt;&lt;a href=&quot;https://youtu.be/f-qTGM5wsnM?t=114&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/f-qTGM5wsnM?t=114&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The entire video is a tutorial on how to achieve the desired effect, the snippet &lt;a href=&quot;https://youtu.be/f-qTGM5wsnM?t=114&quot; rel=&quot;nofollow noreferrer&quot;&gt;linked&lt;/a&gt; is a demo of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In words the image/video is taken, expanded to fill and blurred. Does it have a specific name I can google and read more about ?&lt;/p&gt;&#xA;" OwnerUserId="9003" LastActivityDate="2018-07-10T13:46:37.680" Title="Does this blur background effect have a specific name" Tags="&lt;terminology&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7794" PostTypeId="1" CreationDate="2018-07-10T20:05:06.457" Score="2" ViewCount="1097" Body="&lt;p&gt;I'm a newbie in terms of CG world. I'm curious to know about the applications that use Vulkan API and their performances compared to other APIs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As I read, Vulkan has more access to the graphic cards which helps in performance. If so, do the current rendering engines use it? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solidworks, Revit, Sketchup, Unity3D, Unreal Engine, After Effects, etc. ?&lt;/p&gt;&#xA;" OwnerUserId="9005" LastEditorUserId="5353" LastEditDate="2018-07-11T15:44:34.700" LastActivityDate="2018-11-08T18:01:50.317" Title="Which 3D applications currently uses Vulkan API?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7795" PostTypeId="2" ParentId="7794" CreationDate="2018-07-11T07:15:59.230" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I'm a newbie in terms of CG world. I'm curious to know about the applications that use Vulkan API and their performances compared to other APIs&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There are some popular magazine websites, such as &lt;a href=&quot;https://www.pcgamer.com/doom-benchmarks-return-vulkan-vs-opengl/2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;PCGamer&lt;/a&gt; and &lt;a href=&quot;https://www.anandtech.com/show/11223/quick-look-vulkan-3dmark-api-overhead&quot; rel=&quot;nofollow noreferrer&quot;&gt;AnandTech&lt;/a&gt; that has some comparison charts between other rendering APIs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;PCGamer compares OpenGL vs Vulkan for Doom (2016)&lt;/strong&gt;&#xA;&lt;img src=&quot;https://i.imgur.com/hkNEHEr.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;AnandTech compares Vulkan vs DirectX12 API Overhead&lt;/strong&gt;&#xA;&lt;img src=&quot;https://i.imgur.com/wCoORuf.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would argue that comparisons make sense on the application-level - one API wouldn't necessarily be better on all occasions than the others. It totally depends on how the graphics developers of the software have architected their system to unlock the APIs full potential.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;As I read, Vulkan has more access to the graphic cards which helps in performance. If so, do the current rendering engines use it?&#xA;  &amp;lt; &#xA;  Solidworks, Revit, Sketchup, Unity3D, Unreal Engine, After Effects, etc. ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Vulkan_(API)#Software_that_supports_Vulkan&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia: Software that supports Vulkan&lt;/a&gt; page has a list of software that supports Vulkan API. As for your question, quoting from Wiki page:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;Unreal Engine 4 – In February 2016, Epic Games announced Unreal Engine 4 support for Vulkan at Samsung's Galaxy S7 Unpacked&#xA;  event.[64][65]&lt;/li&gt;&#xA;  &lt;li&gt;Unity – The engine has support for Vulkan since version 5.6.&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There's plenty of others which are also popular, video games and game engines listed in the Wikipedia page, such as:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Dota 2&lt;/li&gt;&#xA;&lt;li&gt;Doom&lt;/li&gt;&#xA;&lt;li&gt;vkQuake&lt;/li&gt;&#xA;&lt;li&gt;Star Citizen&lt;/li&gt;&#xA;&lt;li&gt;Wolfenstein II&lt;/li&gt;&#xA;&lt;li&gt;CryEngine&lt;/li&gt;&#xA;&lt;li&gt;Source 2&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5353" LastActivityDate="2018-07-11T07:15:59.230" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7796" PostTypeId="2" ParentId="7786" CreationDate="2018-07-11T18:37:33.133" Score="1" Body="&lt;p&gt;It's useful to think of rays not as &quot;tubes&quot; or &quot;cones&quot; of vision, but as the units of bookkeeping of radiant power. This notion resembles that of photons: they also are emitted and detected as a whole, and, for a given frequency, light intensity is represented by density of these units, while the energy per unit doesn't change as the unit propagates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider, for example, the well-known inverse-square law for intensity of light emitted by an isotropic source. Starting with $N$ rays emitted by a surface of area $A$, you'll see that these rays, propagating outwards, have more and more space between them – their density reduces, while number of them, $N$, remains the same (in empty space). Calculate average number of rays per unit surface at distance $r$, and you'll see that it's indeed proportional to $r^{-2}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the above example was about forward ray tracing. Backward ray tracing is actually exactly the same, but the question of each ray is not &quot;what object might absorb me?&quot; – instead, it's &quot;where could this unit of light come from?&quot;.&lt;/p&gt;&#xA;" OwnerUserId="4647" LastActivityDate="2018-07-11T18:37:33.133" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7797" PostTypeId="1" AcceptedAnswerId="7799" CreationDate="2018-07-11T20:37:05.883" Score="1" ViewCount="248" Body="&lt;p&gt;I am reading this &lt;a href=&quot;http://paulbourke.net/dataformats/mtl/&quot; rel=&quot;nofollow noreferrer&quot;&gt;piece of documentation&lt;/a&gt; to understand mtl files&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I am stuck trying to understand the difference between ambient, diffuse and specular reflectivity (Ka, Kd, Ks).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I am correct specular is &quot;straight line&quot; reflectivity (the kind of reflectivity of mirors), diffuse is the reflectivity of scattered light (the kind of reflectivity of many rough plastics). But then what is ambient reflectivity?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-12T04:32:32.467" Title="Understanding material .mtl files" Tags="&lt;rendering&gt;&lt;color&gt;&lt;global-illumination&gt;&lt;reflection&gt;&lt;material&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7798" PostTypeId="2" ParentId="7780" CreationDate="2018-07-12T04:19:06.543" Score="3" Body="&lt;p&gt;&lt;img src=&quot;https://i0.wp.com/upload.wikimedia.org/wikipedia/commons/thumb/e/ed/BRDF_Diagram.svg/800px-BRDF_Diagram.svg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This diagram is accurate. Let's look at the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float OrenNayar( in vec3 l, in vec3 n, in vec3 v, float r )&#xA;{&#xA;&#xA;    float r2 = r*r;&#xA;    float a = 1.0 - 0.5*(r2/(r2+0.57));&#xA;    float b = 0.45*(r2/(r2+0.09));&#xA;&#xA;    float nl = dot(n, l);&#xA;    float nv = dot(n, v);&#xA;&#xA;    float ga = dot(v-n*nv,n-n*nl);&#xA;&#xA;    return max(0.0,nl) * (a + b*max(0.0,ga) * sqrt((1.0-nv*nv)*(1.0-nl*nl)) / max(nl, nv));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The first three parameters passed in (&lt;code&gt;l&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;v&lt;/code&gt;) correspond to &lt;code&gt;W_i&lt;/code&gt;, &lt;code&gt;n&lt;/code&gt;, and &lt;code&gt;W_o&lt;/code&gt; vectors, respectively. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, both &lt;code&gt;l&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt; are used in a &lt;a href=&quot;https://en.wikipedia.org/wiki/Dot_product&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;dot&lt;/code&gt; product&lt;/a&gt; with &lt;code&gt;n&lt;/code&gt;: This is done for a purpose.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The dot product gives you the cosine of the angle between the two parameters if both of the parameters are normalized vectors. Otherwise, it gives you the cosine of the angle between the vectors, scaled by the product of the length of those vectors &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;dot(l, n) = len(l) * len(n) * cos(theta) &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;theta&lt;/code&gt; is the angle between &lt;code&gt;l&lt;/code&gt; and &lt;code&gt;n&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/V9lbGcH.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sub&gt;&lt;a href=&quot;https://www.mathsisfun.com/algebra/vectors-dot-product.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;image source&lt;/a&gt;&lt;/sub&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As we normalize our vectors, we can forget about the length and directly associate the dot product with the &lt;code&gt;cos(theta)&lt;/code&gt; value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The value of the dot product ranges between [-1, +1] since cosine values, by definition, range between [-1, +1]. &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If dot product is 1, it means that both the vectors are pointing in the same direction&lt;/li&gt;&#xA;&lt;li&gt;If dot product is 0 (or very close to zero), it means that the vectors are exactly (or almost if its close to 0) perpendicular to each other.&lt;/li&gt;&#xA;&lt;li&gt;If dot product is -1, it means that the two vectors point in the opposite direction&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;In other words, dot product kind of measures how similar the vectors are in terms of the direction they point to.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since we compare how similar &lt;code&gt;v&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt; is to the &lt;code&gt;n&lt;/code&gt; vector, we kind of look into where &lt;code&gt;v&lt;/code&gt; and &lt;code&gt;l&lt;/code&gt; points to relative to the surface normal. Since the surface normal points away from the surface by definition, the vectors that have a dot product with &lt;code&gt;n&lt;/code&gt; larger than 0 also point &lt;em&gt;away&lt;/em&gt; from the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let's look at the last part of the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    return max(0.0,nl) * (a + b*max(0.0,ga) * sqrt((1.0-nv*nv)*(1.0-nl*nl)) / max(nl, nv));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Notice this: &lt;strong&gt;&lt;code&gt;max(0.0,nl)&lt;/code&gt;&lt;/strong&gt; ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This expression would evaluate to 0 if the &lt;code&gt;NdotL&lt;/code&gt; is less than 0. In other words, if the light direction is pointing &lt;em&gt;into&lt;/em&gt; the surface we don't take into account the contribution of that light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the code provided doesn't ignore the rule: In order for the BRDF to return a positive light contribution value, the light vector should point away from the surface.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;As for the view ray part of the question, I think you've spotted a bug. The view vector &lt;code&gt;v&lt;/code&gt; in the lighting calculation should point into the camera. The &lt;code&gt;rd&lt;/code&gt; parameter passed in to &lt;code&gt;OrenNayar()&lt;/code&gt; is a viewRay in world space, pointing away from the camera. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct interpretation of the parameter in this case is &lt;code&gt;-v&lt;/code&gt; when using the &lt;code&gt;dot()&lt;/code&gt; product. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/rgHmc6x.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="5353" LastEditorUserId="5353" LastEditDate="2018-07-18T03:46:18.277" LastActivityDate="2018-07-18T03:46:18.277" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7799" PostTypeId="2" ParentId="7797" CreationDate="2018-07-12T04:32:32.467" Score="1" Body="&lt;p&gt;@PaulHK explained it very well in the comment section:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Ambient is a (rough) approximation of indirect lighting. For example, an outdoor object would be lit by the sun but the surfaces facing away from sun would be black if using only lambert shading, we can use dark gray for the ambient colour to mimic the effect of indirect lighting from the ground and sky&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If you were to visualize this with a shading model, say Phong, the Ka, Kd and Ks values would correspond to the following lighting calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/Xes9imK.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="5353" LastActivityDate="2018-07-12T04:32:32.467" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7802" PostTypeId="2" ParentId="7722" CreationDate="2018-07-12T16:22:25.850" Score="1" Body="&lt;p&gt;As mentioned on a comment, after talking about it on IRC, they helped me realize the bug was in the geometry shader that was being used for Stereo 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Due to the way it was conceived (which was apparently a really bad idea), the shader was always compiled and linked if the hardware reported supporting OpenGL3.30 and &lt;strong&gt;GL_arb_viewport_array&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the stereo3d option was disabled, via a very hacky solution, the shader was put into a &quot;pass-through&quot; mode which is supposed to do nothing but (still not sure if it's a bug in the shader itself or a hardware/driver issue) it was sending a lot of undefined values to the fragment shader, instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the offending code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;#extension GL_ARB_viewport_array : require&#xA;&#xA;uniform float sepFactor;&#xA;uniform float z0;&#xA;&#xA;layout(triangles) in;&#xA;layout(triangle_strip, max_vertices = 6) out;&#xA;&#xA;struct vData {&#xA;    vec3 lightDir;&#xA;    vec2 texCoord;&#xA;    vec3 normal;&#xA;    vec4 color;&#xA;};&#xA;&#xA;in vData vertex[];&#xA;out vData fragv;&#xA;&#xA;void passthru(int i) {&#xA;    gl_Position = gl_in[i].gl_Position;&#xA;    fragv = vertex[i];&#xA;}&#xA;&#xA;// Process all the vertices, applying code to them before emitting (do-while to convince Nvidia of the code getting executed)&#xA;#define PROCESS(code) i = 0; do { passthru(i); code; EmitVertex(); } while (++i &amp;lt; 3); EndPrimitive();&#xA;&#xA;void main() {&#xA;    int i = 0;&#xA;    if (sepFactor == 0.0) {&#xA;        gl_ViewportIndex = 0; PROCESS(;); // No stereo&#xA;    } else {&#xA;        gl_ViewportIndex = 1; PROCESS(gl_Position.x -= sepFactor * (gl_Position.z - z0));  // Left eye&#xA;        gl_ViewportIndex = 2; PROCESS(gl_Position.x += sepFactor * (gl_Position.z - z0));  // Right eye&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have sort-of solved it by actually recompiling and relinking the shaders to include the geometry shader or not when stereo3d is toggled.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also rewritten the shader to look like this (it still produces skewed geometry but atleast akin to the first screenshot, instead of the second),&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;#extension GL_ARB_viewport_array : require&#xA;&#xA;uniform highp float sepFactor;&#xA;uniform highp float z0;&#xA;&#xA;layout(triangles) in;&#xA;layout(triangle_strip, max_vertices = 6) out;&#xA;&#xA;in vData {&#xA;    highp vec3 lightDir;&#xA;    highp vec2 texCoord;&#xA;    highp vec3 normal;&#xA;    highp vec4 color;&#xA;} vertices[];&#xA;&#xA;out vData {&#xA;    highp vec3 lightDir;&#xA;    highp vec2 texCoord;&#xA;    highp vec3 normal;&#xA;    highp vec4 color;&#xA;} fragv;&#xA;&#xA;void passthru(int vp, int i) {&#xA;        gl_Position = gl_in[i].gl_Position;&#xA;        gl_ViewportIndex = (sepFactor == 0.0) ? 0 : vp;&#xA;        gl_Position.x -= (sepFactor * (gl_Position.z - z0));&#xA;        fragv.lightDir = vertices[i].lightDir;&#xA;        fragv.texCoord = vertices[i].texCoord;&#xA;        fragv.normal = vertices[i].normal;&#xA;        fragv.color = vertices[i].color;&#xA;}&#xA;&#xA;void main() {&#xA;        // Render the left eye&#xA;    int i = 0;&#xA;    do {&#xA;        passthru(1, i);&#xA;        gl_Position.x -= (sepFactor * (gl_Position.z - z0));&#xA;        EmitVertex();       &#xA;        } while (++i &amp;lt; 3);&#xA;        EndPrimitive();&#xA;&#xA;    i = 0;&#xA;        // Render the right eye&#xA;    do {&#xA;        passthru(2, i);&#xA;        gl_Position.x += (sepFactor * (gl_Position.z - z0));&#xA;        EmitVertex();       &#xA;        } while (++i &amp;lt; 3);&#xA;        EndPrimitive();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In order to provide a more complete answer, in case somebody faces the same issue: I finally realized the issue appears to be with the way the loop was written. For some reason, not defining i in the loop itself resulted in trying to access undefined members of &lt;code&gt;vertices&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rewriting as follows fixed the issue:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i=0; i &amp;lt; gl_in.length(); i++) {&#xA;    passthru(1, i);&#xA;    gl_Position = gl_in[i].gl_Position;&#xA;    gl_Position.x -= (sepFactor * (gl_in[i].gl_Position.z - z0));&#xA;    EmitVertex();   &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8889" LastEditorUserId="8889" LastEditDate="2018-07-17T00:57:14.143" LastActivityDate="2018-07-17T00:57:14.143" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7804" PostTypeId="1" CreationDate="2018-07-13T10:11:07.267" Score="2" ViewCount="734" Body="&lt;p&gt;I'm writing a CAD program in vulkan. In my current design, I have line paths represented as large vertex buffers for rendering. I would like to implement an algorithm for extruding the path outwards, based off of cross products. Ideally I would like to implement this algorithm within a compute shader, using the vertex buffer in place of a storage buffer. The algorithm would work like this: for each vertex in original path, calculate cross product based off of the two surrounding vertices in the buffer, then normalize and multiply by a scalar.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm fairly certain that this could be done by copying the vertex buffer to a storage buffer temporarily, but I doubt that's optimal, unless it's not actually physically copied. I don't see why I should move large chunks of data from VRAM to VRAM like that. It would probably, be faster to implement this algorithm locally on the CPU in that case. I don't have much experience using compute shaders; any input is appreciated.&lt;/p&gt;&#xA;" OwnerUserId="9021" LastEditorUserId="2041" LastEditDate="2018-07-13T10:24:49.790" LastActivityDate="2021-03-29T18:03:50.400" Title="Feeding vertex data to a compute shader" Tags="&lt;algorithm&gt;&lt;compute-shader&gt;&lt;vulkan&gt;&lt;buffers&gt;&lt;cad&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7805" PostTypeId="2" ParentId="7804" CreationDate="2018-07-13T11:02:44.917" Score="0" Body="&lt;p&gt;You will need a new chunk of memory for the new surface anyway, so why not read from the original and store directly in the result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having precomputed normals will reduce a lot of the computation requirements though (especially needing to find&amp;amp;read each neighbour), the user action of the extrusion will probably be interactive so you will have multiple frames with different extrusion amounts but the normals of the original surface won't change. Having the normals be around will likely be helpful for other operations as well. You could make the temporary transformed geometry just a vertex shader trick as well and only commit the result once needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Computing normals is much simpler by going face per face and then summing the the non-normalized normals per vertex and normalizing after.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-07-13T11:02:44.917" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7806" PostTypeId="2" ParentId="7428" CreationDate="2018-07-13T16:40:18.160" Score="1" Body="&lt;p&gt;maybe you forget to call MTLBlitCommandEncoder.synchronizeTexture to sync VRAM to system memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;please check: &#xA;&lt;a href=&quot;https://forums.developer.apple.com/thread/30488&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://forums.developer.apple.com/thread/30488&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and document:&#xA;&lt;a href=&quot;https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400757-synchronize&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.apple.com/documentation/metal/mtlblitcommandencoder/1400757-synchronize&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8877" LastActivityDate="2018-07-13T16:40:18.160" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7807" PostTypeId="2" ParentId="7538" CreationDate="2018-07-13T17:24:53.467" Score="0" Body="&lt;p&gt;I have ported their WebGL demo in DX shader model 4, but I have not implemented such texture preprocessing. Instead, I use some abstract pattern (like a comuflage) that is twice wider and higher. So, in a reflected area only internal part is rendered if roughness is low, and with a greater roughness, mip-map with lower resolution is taken. That spreads pattern in zone of reflection realistically.&#xA;It could be some starting point for your implementation.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is possible to make some &quot;texture expansion&quot; like in article, but some special code to do this is needed. This is &quot;special&quot;, it modifies Gaussian. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in many cases, reflected pattern could be very simple, and such expansion can be eailly created by artist and mip chain generated. Again -good for start point.  &lt;/p&gt;&#xA;" OwnerUserId="9025" LastActivityDate="2018-07-13T17:24:53.467" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7809" PostTypeId="1" AcceptedAnswerId="7814" CreationDate="2018-07-14T15:23:13.830" Score="12" ViewCount="9413" Body="&lt;p&gt;I have played around with CPU assembly programming like Nasm, Tasm or Masm, but I'm really curious to know how GPU works now.&#xA;However, i'm quite confused when I look on internet. I've heard about Cuda and OpenCL, but it is not what I'm looking for.&#xA;I'd like to know how GPUs instructions are in RAM... What are the Nasm and Masm for most GPUs? What is the x86 or Z80 of GPUs (What are the different families of GPU)? Do you know a constructor opcodes reference manual?&#xA;I think I really need something to compare between the two Processing Units to make it clear, because GPU assembly programming seems to be an even harder subject to learn from on internet that CPU asm programming. I've also read that &amp;quot;NVIDIA never released details on the instructions actually understood by their hardware&amp;quot;, but it seems pretty surprising to me. Full post there: &lt;a href=&quot;https://stackoverflow.com/questions/4660974/how-to-create-or-manipulate-gpu-assembler?newreg=e31519279ce949f087df6322dbf2bf4d&quot;&gt;https://stackoverflow.com/questions/4660974/how-to-create-or-manipulate-gpu-assembler?newreg=e31519279ce949f087df6322dbf2bf4d&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Thanks for your help!&lt;/p&gt;&#xA;" OwnerUserId="9028" LastEditorUserId="8157" LastEditDate="2020-07-15T20:16:33.050" LastActivityDate="2020-09-23T08:54:53.390" Title="What does GPU assembly look like?" Tags="&lt;gpu&gt;&lt;assembly&gt;" AnswerCount="4" CommentCount="3" FavoriteCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7811" PostTypeId="1" AcceptedAnswerId="7820" CreationDate="2018-07-14T22:43:31.310" Score="3" ViewCount="586" Body="&lt;p&gt;I am currently rendering a scene in the most standard fashion possible (triangle projection and Blinn-Phong for shading)&lt;/p&gt;&#xA;&lt;p&gt;However I am getting some artifacts:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/n87Fg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n87Fg.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see the lion head is not rendered properly. Moreover, the artifacts are flickering, but the proportion of how much they flicker is proportional to the distance to the lion. That is to say. If you are close to the lion there are no artifacts. But the farther away you go the more artifacts appear. I believe this is due to Z buffer imprecision. How can I solve this?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-07-17T01:37:22.940" Title="How to solve Z buffer artifacts" Tags="&lt;opengl&gt;&lt;antialiasing&gt;&lt;buffers&gt;&lt;artifacts&gt;&lt;z-buffer&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7812" PostTypeId="1" AcceptedAnswerId="7815" CreationDate="2018-07-15T01:51:28.903" Score="1" ViewCount="69" Body="&lt;p&gt;So I'm in the midst of implementing a path-tracer. I have chosen to use Assimp library to load models and scene information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to it, it will provide mesh data and meshes may contain point, line, triangles and polygons primitives. It gives the option to triangulate polygons but I don't know what to do with lines and points. Should I ignore them?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This leads to a bigger question that came in my mind. Can we ray-trace points and lines? I wanted to use this kind of thing once to show my Bounding boxes in wire frame mode but didn't know how I would trace only the boundaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm guessing this has to do with providing a specific line/point width? Else they are too thin for intersection. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we can render lines and points, then should I ignore them or not in my path tracer? Will I be missing out on details etc? Don't know what are they used to represent in 3D models as I have only seen triangles/polygons. &lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-07-15T08:43:07.363" Title="Pathtracing line and point primitives?" Tags="&lt;raytracing&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7813" PostTypeId="2" ParentId="7809" CreationDate="2018-07-15T05:31:39.157" Score="4" Body="&lt;p&gt;What you've read is correct. In general, GPU vendors do not release lists of machine instructions for their GPUs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, you can do something similar to assembly programming on the GPU by using &lt;a href=&quot;https://en.wikipedia.org/wiki/ARB_assembly_language&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL ARB Assembly Language&lt;/a&gt;. It allows you to program in assembly style, writing 1 opcode and its operands per line. While this is not quite the same as writing assembly language for the CPU, it's as close as your likely to get. I believe it's deprecated in modern OpenGL (though not positive). It still worked as of OpenGL 2.1.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-07-15T05:31:39.157" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7814" PostTypeId="2" ParentId="7809" CreationDate="2018-07-15T08:27:37.640" Score="18" Body="&lt;p&gt;You're tilting at windmills trying to learn &quot;GPU assembly&quot;, and it's due to the differences between how CPUs and GPUs are made and sold.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each CPU has what's called an &lt;em&gt;instruction set architecture&lt;/em&gt;, for example x86 or ARMv8. The instruction set is the interface between the user of the CPU (i.e. the programmer) and the chip. The chip designer publishes the details of the instruction set so that compiler vendors can write compilers to target that instruction set. Any CPU that uses that instruction set can run the same binaries. (Extensions like SSE make that slightly untrue, but they only add new instructions: they don't change the structure of the binary.) When the vendor creates a new processor family, it could have completely different &lt;em&gt;micro-architecture&lt;/em&gt; internally, but the same instruction set.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPUs are not like this at all. For best efficiency, the instruction set is usually closely tied to the micro-architecture of the CPU. That means each new family of GPUs has a new instruction set. GPUs can't run binaries made for different GPUs. For this reason, the instruction set usually isn't published: instead, your interface to the GPU is the driver published by the vendor for each graphics API (OpenGL, Vulkan, DirectX, &amp;amp;c.). This is why the graphics APIs have functions to take the source code of a shader and run it: the compiled shader only runs on the same model or family of GPU it was compiled for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The closest you get to GPU assembly language is &lt;em&gt;SPIR-V&lt;/em&gt;. This is an industry-standard intermediate representation, which GPU vendors are starting to support. It's like a GPU equivalent of LLVM's intermediate representation. It allows you to do the parsing and source optimization parts of compilation up-front to get a SPIR-V file, and then the GPU driver only needs to compile that to the GPU's instruction set at load time.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-15T08:27:37.640" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7815" PostTypeId="2" ParentId="7812" CreationDate="2018-07-15T08:43:07.363" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I'm guessing this has to do with providing a specific line/point width? Else they are too thin for intersection.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Exactly. True points and lines have no spatial extent: a point is infinitely small, a line is infinitely thin. You can't intersect those with a ray. But a point with a size is just a sphere, and a line with a size is a cylinder, and those are classic ray-casting primitives, so of course you can intersect them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only difficulty is if your path-tracer currently only has one geometry primitive (the polygon or polygon mesh): adding new primitives might be hard for you, if you've structured it for just one. But even in that case, instead of intersecting the points and lines directly, you can just turn them both into polygon meshes inside the renderer, before casting any rays. If you know how to polygonise a sphere and a cylinder you already know what to do.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-15T08:43:07.363" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7816" PostTypeId="2" ParentId="6408" CreationDate="2018-07-15T16:48:52.890" Score="0" Body="&lt;p&gt;As it turns out, what was causing the visible diamond (simplex) shapes was an unfortunate typo. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The line&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;t = FN_DECIMAL(0.5) - x5*x5 - y5*y5 - z5*z5 - w4*w4 - v5*v5;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Should have been&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;t = FN_DECIMAL(0.5) - x5*x5 - y5*y5 - z5*z5 - w5*w5 - v5*v5;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I ran some iterations without a normalising value to find the natural min/max values of the function and used those to calculate a normalising value, and tweaked the falloff function to find a nice point where the output is visually appealing. The final function is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;FN_DECIMAL FastNoise::SingleSimplex(unsigned char offset, FN_DECIMAL x, FN_DECIMAL y, FN_DECIMAL z, FN_DECIMAL w, FN_DECIMAL v) const&#xA;{&#xA;  static const FN_DECIMAL norm = FN_DECIMAL(10.733025427569862289390260016388);&#xA;&#xA;  FN_DECIMAL n0, n1, n2, n3, n4, n5;&#xA;  FN_DECIMAL t = (x + y + z + w + v) * F5;&#xA;  int i = FastFloor(x + t);&#xA;  int j = FastFloor(y + t);&#xA;  int k = FastFloor(z + t);&#xA;  int l = FastFloor(w + t);&#xA;  int h = FastFloor(v + t);&#xA;  t = (i + j + k + l + h) * G5;&#xA;  FN_DECIMAL X0 = i - t;&#xA;  FN_DECIMAL Y0 = j - t;&#xA;  FN_DECIMAL Z0 = k - t;&#xA;  FN_DECIMAL W0 = l - t;&#xA;  FN_DECIMAL V0 = h - t;&#xA;  FN_DECIMAL x0 = x - X0;&#xA;  FN_DECIMAL y0 = y - Y0;&#xA;  FN_DECIMAL z0 = z - Z0;&#xA;  FN_DECIMAL w0 = w - W0;&#xA;  FN_DECIMAL v0 = v - V0;&#xA;&#xA;  int rankx = 0;&#xA;  int ranky = 0;&#xA;  int rankz = 0;&#xA;  int rankw = 0;&#xA;  int rankv = 0;&#xA;&#xA;  if (x0 &amp;gt; y0) rankx++; else ranky++;&#xA;  if (x0 &amp;gt; z0) rankx++; else rankz++;&#xA;  if (x0 &amp;gt; w0) rankx++; else rankw++;&#xA;  if (x0 &amp;gt; v0) rankx++; else rankv++;&#xA;&#xA;  if (y0 &amp;gt; z0) ranky++; else rankz++;&#xA;  if (y0 &amp;gt; w0) ranky++; else rankw++;&#xA;  if (y0 &amp;gt; v0) ranky++; else rankv++;&#xA;&#xA;  if (z0 &amp;gt; w0) rankz++; else rankw++;&#xA;  if (z0 &amp;gt; v0) rankz++; else rankv++;&#xA;&#xA;  if (w0 &amp;gt; v0) rankw++; else rankv++;&#xA;&#xA;  int i1 = rankx &amp;gt;= 4 ? 1 : 0;&#xA;  int j1 = ranky &amp;gt;= 4 ? 1 : 0;&#xA;  int k1 = rankz &amp;gt;= 4 ? 1 : 0;&#xA;  int l1 = rankw &amp;gt;= 4 ? 1 : 0;&#xA;  int h1 = rankv &amp;gt;= 4 ? 1 : 0;&#xA;&#xA;  int i2 = rankx &amp;gt;= 3 ? 1 : 0;&#xA;  int j2 = ranky &amp;gt;= 3 ? 1 : 0;&#xA;  int k2 = rankz &amp;gt;= 3 ? 1 : 0;&#xA;  int l2 = rankw &amp;gt;= 3 ? 1 : 0;&#xA;  int h2 = rankv &amp;gt;= 3 ? 1 : 0;&#xA;&#xA;  int i3 = rankx &amp;gt;= 2 ? 1 : 0;&#xA;  int j3 = ranky &amp;gt;= 2 ? 1 : 0;&#xA;  int k3 = rankz &amp;gt;= 2 ? 1 : 0;&#xA;  int l3 = rankw &amp;gt;= 2 ? 1 : 0;&#xA;  int h3 = rankv &amp;gt;= 2 ? 1 : 0;&#xA;&#xA;  int i4 = rankx &amp;gt;= 1 ? 1 : 0;&#xA;  int j4 = ranky &amp;gt;= 1 ? 1 : 0;&#xA;  int k4 = rankz &amp;gt;= 1 ? 1 : 0;&#xA;  int l4 = rankw &amp;gt;= 1 ? 1 : 0;&#xA;  int h4 = rankv &amp;gt;= 1 ? 1 : 0;&#xA;&#xA;  FN_DECIMAL x1 = x0 - i1 + G5;&#xA;  FN_DECIMAL y1 = y0 - j1 + G5;&#xA;  FN_DECIMAL z1 = z0 - k1 + G5;&#xA;  FN_DECIMAL w1 = w0 - l1 + G5;&#xA;  FN_DECIMAL v1 = v0 - h1 + G5;&#xA;&#xA;  FN_DECIMAL x2 = x0 - i2 + 2 * G5;&#xA;  FN_DECIMAL y2 = y0 - j2 + 2 * G5;&#xA;  FN_DECIMAL z2 = z0 - k2 + 2 * G5;&#xA;  FN_DECIMAL w2 = w0 - l2 + 2 * G5;&#xA;  FN_DECIMAL v2 = v0 - h2 + 2 * G5;&#xA;&#xA;  FN_DECIMAL x3 = x0 - i3 + 3 * G5;&#xA;  FN_DECIMAL y3 = y0 - j3 + 3 * G5;&#xA;  FN_DECIMAL z3 = z0 - k3 + 3 * G5;&#xA;  FN_DECIMAL w3 = w0 - l3 + 3 * G5;&#xA;  FN_DECIMAL v3 = v0 - h3 + 3 * G5;&#xA;&#xA;  FN_DECIMAL x4 = x0 - i4 + 4 * G5;&#xA;  FN_DECIMAL y4 = y0 - j4 + 4 * G5;&#xA;  FN_DECIMAL z4 = z0 - k4 + 4 * G5;&#xA;  FN_DECIMAL w4 = w0 - l4 + 4 * G5;&#xA;  FN_DECIMAL v4 = v0 - h4 + 4 * G5;&#xA;&#xA;  FN_DECIMAL x5 = x0 - 1 + 5 * G5;&#xA;  FN_DECIMAL y5 = y0 - 1 + 5 * G5;&#xA;  FN_DECIMAL z5 = z0 - 1 + 5 * G5;&#xA;  FN_DECIMAL w5 = w0 - 1 + 5 * G5;&#xA;  FN_DECIMAL v5 = v0 - 1 + 5 * G5;&#xA;&#xA;  t = FN_DECIMAL(0.7) - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0 - v0 * v0;&#xA;  if (t &amp;lt; 0) n0 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n0 = t * t * GradCoord5D(offset, i, j, k, l, h, x0, y0, z0, w0, v0);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.7) - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1 - v1 * v1;&#xA;  if (t &amp;lt; 0) n1 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n1 = t * t * GradCoord5D(offset, i + i1, j + j1, k + k1, l + l1, h + h1, x1, y1, z1, w1, v1);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.7) - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2 - v2 * v2;&#xA;  if (t &amp;lt; 0) n2 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n2 = t * t * GradCoord5D(offset, i + i2, j + j2, k + k2, l + l2, h + h2, x2, y2, z2, w2, v2);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.7) - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3 - v3 * v3;&#xA;  if (t &amp;lt; 0) n3 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n3 = t * t * GradCoord5D(offset, i + i3, j + j3, k + k3, l + l3, h + h3, x3, y3, z3, w3, v3);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.7) - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4 - v4 * v4;&#xA;  if (t &amp;lt; 0) n4 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n4 = t * t * GradCoord5D(offset, i + i4, j + j4, k + k4, l + l4, h + h4, x4, y4, z4, w4, v4);&#xA;  }&#xA;&#xA;  t = FN_DECIMAL(0.7) - x5 * x5 - y5 * y5 - z5 * z5 - w5 * w5 - v5 * v5;&#xA;  if (t &amp;lt; 0) n5 = 0;&#xA;  else&#xA;  {&#xA;    t *= t;&#xA;    n5 = t * t * GradCoord5D(offset, i + 1, j + 1, k + 1, l + 1, h + 1, x5, y5, z5, w5, v5);&#xA;  }&#xA;&#xA;  return (n0 + n1 + n2 + n3 + n4 + n5) * norm; // TODO: Find value scaler&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6406" LastActivityDate="2018-07-15T16:48:52.890" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7817" PostTypeId="2" ParentId="7809" CreationDate="2018-07-16T09:46:40.387" Score="4" Body="&lt;p&gt;As others have said, GPUs expose a higher-level language, which allows multiple different architectures i.e. different vendors and different GPU generations, to all support the same applications.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;[Update: Link to older ISA replaced with newer one]&lt;/em&gt;&lt;br&gt;&#xA;If, however, you're still curious, documentation for the recent &lt;a href=&quot;https://docs.imgtec.com/Architecture_Guides/PowerVR_ISR/topics/d0e75.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;PowerVR instruction set is available&lt;/a&gt; - my favourite opcodes being &amp;quot;FRED&amp;quot; and &amp;quot;FARCTANC&amp;quot; :-)&lt;/p&gt;&#xA;&lt;p&gt;Note that instructions sets can change from generation to generation so this is mainly for illustrative purposes.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-09-23T08:54:53.390" LastActivityDate="2020-09-23T08:54:53.390" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7818" PostTypeId="1" AcceptedAnswerId="7823" CreationDate="2018-07-16T22:48:05.637" Score="1" ViewCount="93" Body="&lt;p&gt;The way I learnt to send a texture to a shader is more or less&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Use program&#xA;//Bind texture to the texture unit to its appropriate target&#xA;glActiveTexture(GL_TEXTURE0 + texture_unit);&#xA;glBindTexture(target, textureID);&#xA;//Get the uniform location in the program and attach the texture unit&#xA;GLuint location = /*get the location somewhow*/;&#xA;glUniform1i(location,texture_unit);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However when dealing with buffers and SSBOS rather than trying to find a location through a string name, the object is declared as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(std430, binding = 2) buffer texture_meta_data&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For example. This means that the SSBO is to be bound at binding point 2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then on the C++ side one does something like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, SSBOID);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To bind the object to the binding point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can you do the same with textures?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-07-17T20:10:29.410" LastActivityDate="2018-07-17T20:10:29.410" Title="Can you avoid querying for a texture location in OpenGL?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;shader&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7819" PostTypeId="1" CreationDate="2018-07-17T01:28:02.133" Score="1" ViewCount="239" Body="&lt;p&gt;I'm working on a program which uses Kochanek-Bartels (&quot;TCB&quot;) splines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: How do I deal with the first/last points of the spline?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This type of spline needs a 'previous' and 'next' point at each node to generate the curve tangents, but the first and last points on the curve don't have them. How do graphics programs deal with this problem?&lt;/p&gt;&#xA;" OwnerUserId="9036" LastActivityDate="2018-07-17T01:28:02.133" Title="How should I generate Kochanek-Bartels spline endpoints?" Tags="&lt;curve&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7820" PostTypeId="2" ParentId="7811" CreationDate="2018-07-17T01:32:09.820" Score="5" Body="&lt;p&gt;Short answer: Move your near clip plane further away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depth buffer precision is very sensitive to the near clip plane distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Complicated answer: Use different math in your view projection. There are a few techniques that can help, some of them are outlined here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.nvidia.com/content/depth-precision-visualized&quot; rel=&quot;noreferrer&quot;&gt;https://developer.nvidia.com/content/depth-precision-visualized&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9036" LastEditorUserId="9036" LastEditDate="2018-07-17T01:37:22.940" LastActivityDate="2018-07-17T01:37:22.940" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7821" PostTypeId="1" AcceptedAnswerId="7822" CreationDate="2018-07-17T08:48:31.993" Score="1" ViewCount="232" Body="&lt;p&gt;For JPG, i can choose the &quot;quality&quot; from 100 to 0, which means that any pixel information is divided by 1 (quality = 100) or a very high number (quality = 0).&#xA;&lt;br&gt;This results in less or more &quot;artifacts&quot;, which are regions of the same color. The sizes of that regions depend on the image content and the selected &quot;quality level&quot;.&#xA;&lt;br&gt;But there are other compression formats using other algorithms. The common characteristic is that the resulting image has less information than the original uncompressed data. &lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way to specify those losses independently from both the used file format and the image content?&lt;/p&gt;&#xA;" OwnerUserId="6346" LastActivityDate="2018-07-17T10:43:59.080" Title="Is there a general way how to specify the &quot;image compression loss&quot;?" Tags="&lt;image&gt;&lt;compression&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7822" PostTypeId="2" ParentId="7821" CreationDate="2018-07-17T10:43:59.080" Score="1" Body="&lt;p&gt;First off, it's worth noting that not all artefacts are regions of the same colour. &lt;em&gt;Artefacts&lt;/em&gt; just means structured errors introduced by the compression, as opposed to noise or blurring. JPEG artefacts include flattened colours as you mention, but also edges introduced at block boundaries, and &quot;ringing&quot; around sharp edges in the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two popular metrics for specifying the losses, but they're &lt;strong&gt;not&lt;/strong&gt; independent of the image content, and they measure the whole loss, not just structured artefacts. &lt;a href=&quot;https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio&quot; rel=&quot;nofollow noreferrer&quot;&gt;PSNR&lt;/a&gt; is most commonly used to quantify the loss of image and video compression algorithms. It's not a very useful measure, because it measures the absolute reconstruction error: it doesn't take into account what kind of artefacts are introduced and how they appear. &lt;a href=&quot;https://en.wikipedia.org/wiki/Structural_similarity&quot; rel=&quot;nofollow noreferrer&quot;&gt;Structural similarity (SSIM)&lt;/a&gt; is better because it takes the structure of the image and the errors into account in the measure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The measure can't be independent of the image, for several reasons. Different images are easier or harder to reconstruct. For example, a completely flat colour will be perfectly reconstructed even with some very lossy algorithms and parameters. At the opposite end, completely random white noise will suffer some loss in almost any algorithm. Some images just contain more information than others. In addition, different domains have different requirements, so algorithms can be tuned for different kinds of images. JPEG is tuned for photographs, and performs badly on hard-edged synthetic images like diagrams. A texture compression algorithm might be tuned specifically to avoid block artefacts for tileable textures. JBIG2 is tuned for black-and-white document scans. A single generic measure wouldn't help you to understand the performance of the algorithm on the kind of image you're interested in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get a broader measure, it's common for researchers to quote a mean PSNR and/or SSIM measured across a corpus of images. The Kodak PCD0992 corpus has been used for many years, so it's an easy way to compare different papers, but it is waning in popularity now.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-17T10:43:59.080" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7823" PostTypeId="2" ParentId="7818" CreationDate="2018-07-17T15:14:59.503" Score="2" Body="&lt;p&gt;By using the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Sampler_(GLSL)#Version_4.20_binding&quot; rel=&quot;nofollow noreferrer&quot;&gt;exact same syntax&lt;/a&gt; as you did for SSBOs:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(binding = 0) uniform sampler2D texture_name;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is a GL 4.2 feature, so if you can use SSBOs, you can use this.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-07-17T15:14:59.503" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7824" PostTypeId="1" CreationDate="2018-07-17T16:16:15.653" Score="2" ViewCount="88" Body="&lt;p&gt;Are you aware of any sample implementation or demo application of Cem Yuksel's &quot;Mesh Colors&quot; or &quot;Mesh Color Textures&quot; (&lt;a href=&quot;http://www.cemyuksel.com/research/meshcolors/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.cemyuksel.com/research/meshcolors/&lt;/a&gt;) ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The author does not provide any links or pointers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I only saw very few references about these algorithms, but nothing executable to see the results.&lt;/p&gt;&#xA;" OwnerUserId="1615" LastActivityDate="2018-07-17T16:16:15.653" Title="Cem Yuksel's &quot;Mesh colors&quot; implementation/demo?" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;implementation&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7825" PostTypeId="1" CreationDate="2018-07-17T23:55:16.183" Score="3" ViewCount="254" Body="&lt;p&gt;I am doing a voxel based raytracer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, I first voxelize the scene using rasterization and I proceed to raytrace the volume in a 3D image to generate a final frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I noticed a circular pattern aliasing and I am not sure what could be causing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This video shows the aliasing (sorry for the awkward camera movement my controls are not good right now). The magenta cube is the light's position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=rtFDTQoKX_A&amp;amp;feature=youtu.be&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=rtFDTQoKX_A&amp;amp;feature=youtu.be&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a still from the video:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YttRQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YttRQ.png&quot; alt=&quot;Moire Patterns&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;This is the main function of the fragment shader. I can post more if it;s needed, btu won;t for now because the fragment is quite big and I think most of the function names are slef explanatory:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    float v_size = cube_dim/voxel_resolution;&#xA;    vec3 r = -(vec3(f_coord.xy,1.f/tan(radians(40))));&#xA;    r.y*=-1;&#xA;    r.y /= aspect_ratio;&#xA;    vec3 dir = vec3(view_m*vec4(normalize(r),0));&#xA;    dir = normalize(dir);&#xA;    r = camera_pos;&#xA;    r.z*=-1;&#xA;&#xA;    float t = boxIntersection(r, dir, -vec3(cube_dim), cube_dim*2);&#xA;&#xA;    if(isinf(t))&#xA;        discard;&#xA;&#xA;    if(!((r.x&amp;gt;=-cube_dim) &amp;amp;&amp;amp; (r.x&amp;lt;=cube_dim) &amp;amp;&amp;amp; (r.y&amp;gt;=-cube_dim) &amp;amp;&amp;amp;&#xA;        (r.y&amp;lt;=cube_dim) &amp;amp;&amp;amp; (r.z&amp;gt;=-cube_dim) &amp;amp;&amp;amp; (r.z&amp;lt;=cube_dim)))&#xA;        r += dir*t;&#xA;&#xA;    vec4 color = vec4(0);&#xA;    while(incube(r, cube_dim))&#xA;    {&#xA;        r += dir*v_size*0.5;&#xA;        vec4 val = imageLoad(normal_map, ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1)));&#xA;        if(val.w &amp;gt; 0)&#xA;        {&#xA;            break;&#xA;        }&#xA;    }&#xA;    vec4 normal = imageLoad(normal_map, ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1)));&#xA;    color = imageLoad(diffuse_map, ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1)));&#xA;&#xA;    fragment_color = blinn_phong(r, vec3(normal), color)*(10.f/log(length(r-light)));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-07-20T02:10:16.877" LastActivityDate="2020-04-13T06:58:06.010" Title="Circular pattern aliasing in voxel ray tracer" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;glsl&gt;&lt;antialiasing&gt;&lt;debugging&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="7826" PostTypeId="2" ParentId="5611" CreationDate="2018-07-18T11:04:21.220" Score="5" Body="&lt;p&gt;From the proof of premultiplied alpha blending, there is an assumption that &quot;the operator must respect the associative rule.&quot;&#xA;So, it may lead to confusion of the order of process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since this is not the commutative rule, blend(a,b) is not same as blend(b,a).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence, &#xA;blend(blend(a,b),c) returns same value of blend(a,blend(b,c)).&#xA;but,&#xA;blend(blend(a,b),c) does not return same value of blend(blend(b,a),c) like your example.&lt;/p&gt;&#xA;" OwnerUserId="9042" LastActivityDate="2018-07-18T11:04:21.220" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7827" PostTypeId="1" CreationDate="2018-07-18T14:54:28.767" Score="1" ViewCount="161" Body="&lt;p&gt;I'm trying to implement the solution to get the &lt;a href=&quot;https://stackoverflow.com/questions/5919298/algorithm-for-finding-the-fewest-rectangles-to-cover-a-set-of-rectangles-without&quot;&gt;minimum dissection into rectangles of a rectilinear polygon&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My shape is made out of pseudo-pixels (different width/height) but for the moment let's say it's only pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to find a way to convert my shape to a vertices loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for example a simple pixel of coordinate &lt;code&gt;{50, 25}&lt;/code&gt; would give me 4 vertices (to read clockwise) as follow &lt;code&gt;{{50, 25}{51, 25}{51, 26}{50, 26}}&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine now a more complex filled shape with holes in it like this one of 6 pixels height and 24 pixels width. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   S     &#xA;   |¯¯¯¯|    |¯¯¯¯¯¯|&#xA; __|    |____|  __  |__&#xA;|              |__|    |&#xA; ¯¯|    |¯¯¯¯|      |¯¯&#xA;   |____|    |______|&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I can't seem to find the logic to parse my shape and convert it to vertices. Only thing I know is I think I will start parsing with pixel of coordinate &lt;code&gt;S&lt;/code&gt; which is the top-left pixel of the shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance,&lt;/p&gt;&#xA;" OwnerUserId="6844" LastActivityDate="2018-07-18T14:54:28.767" Title="How can I convert a shape made out of pixels to vertices" Tags="&lt;vector-graphics&gt;&lt;polygon&gt;&lt;javascript&gt;&lt;pixel-graphics&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7828" PostTypeId="1" AcceptedAnswerId="7849" CreationDate="2018-07-19T04:46:35.307" Score="8" ViewCount="6763" Body="&lt;p&gt;So I'm currently reading up on acceleration data structures and so far I've heard there are 2 main schemes. Object Subdivision and Spatial Subdivision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Bounding Volume Hierarchy belongs to the Object Subdivision approach and K-d/Octree belong to the latter. However I'm having trouble distinguishing the two of them as both of them seem almost the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had implemented a data structure before for my GPU raytracer which I thought was an Octree but I am not sure anymore. This was according to the paper &quot;Ray tracing Complex Scenes&quot; by Kajiya. I'm gonna quote him directly.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We could spend additional computer time to construct a better&#xA;  hierarchy. A median-cut scheme will help group near objects together&#xA;  even if they aren't modeled coherently.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;The previous algorithm attempts to group objects based on their&#xA;  nearness to each other, but it does so along one dimension at a time.&#xA;  It might do better to group objects in along three dimensions at once&#xA;  by employing an octree. This preprocessing step would be very similar&#xA;  to the one described in [Glassner 84] or [Kaplan 85]. The difference&#xA;  is that, if an object straddles two or more octree cells, it is&#xA;  arbitrarily placed in exactly one of them. Furthermore, after the&#xA;  preprocessing is completed, the octree is used solely to define the&#xA;  hierarchy; each object must still be assigned a distinct bounding&#xA;  volume.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So I constructed this structure the same way. First I made an Octree, I inserted spheres into the cells if their center was in that cell. Every time I checked if the leaf nodes consisted of more than 2 spheres. If it did, I had to subdivide the cells again. After the octree was completed, I looped over all the compartments and resized them w.r.t the minimum &lt;code&gt;x,y,z&lt;/code&gt; and the maximum &lt;code&gt;x,y,z&lt;/code&gt; of the objects it had. This was done to avoid the case where some portion of a sphere would be outside the cell it's currently in (due to it's center lying in that cell).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now according to the paper the above structure is a BVH? But I'm thinking its an octree? What's the difference?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Secondly, so far I have only inserted spheres. What's the case with triangles? What should be the maximum threshold for leaf nodes after which I should subdivide i.e. The number of traingles?&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-07-23T18:37:11.323" Title="Difference between BVH and Octree/K-d trees" Tags="&lt;raytracing&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7829" PostTypeId="1" CreationDate="2018-07-19T07:30:57.797" Score="0" ViewCount="49" Body="&lt;p&gt;I have 2 shading models right now, one is using voxels the other one is the standard projection absed renderization method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Putting them side by side I have noticed that no matter what I do one is mirrored with respect to the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To show what I mean I have a program that renders the scene with both models simultaneously. Supposedly the model loads the same camera parameters to both shading programs, so both should &quot;see&quot; the same thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what I mean:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this screenshot pay attention to the color pairings. We have:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/s5paD.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/s5paD.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Left:&#xA;green-red at back;&#xA;red-blue at front&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right:&#xA;blue-red at back;&#xA;red-green at front&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On this image, which corresponds to a 180 rotation however we get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7ArxN.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7ArxN.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Left:&#xA;blue-red at back;&#xA;red-green at front&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right:&#xA;green-red at back;&#xA;red-blue at front&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the image seems to be mirrored. However I have tried inverting the polarity of multiple parameters without success. I tried negating the focal length of the camera. Negating the x value of the ray. Negating both...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However no matter which combination of parameters I try I get some form of mirroring (no always the same one).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I calculate the ray in teh raytracer as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 r = (vec3(f_coord.xy,1.f/tan(radians(40))));&#xA;r.y /= aspect_ratio;&#xA;vec3 dir = vec3(view_m*vec4(normalize(r),0));&#xA;dir = normalize(dir);&#xA;r = camera_pos;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where f_coord is the normalized -1 to 1 coordinate of the current pixel and &lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-23T18:18:47.710" Title="How to ensure that the raytrcing coordinate system is teh same as the projection one?" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;image-processing&gt;&lt;c++&gt;&lt;geometry&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7830" PostTypeId="1" AcceptedAnswerId="7839" CreationDate="2018-07-19T14:28:39.320" Score="3" ViewCount="104" Body="&lt;p&gt;So I'm teaching crash-course in CUDA that teaches students how to write good GPU code (CUDA 7.5 in this case). They kernels they will be running will do matrix multiply on 2048x2048 floating point matrices, some kernels involving multiple blocks and shared memory. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The students will be ssh-ing into servers that have the GPUs where they will compile and run their programmes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't a clue on how feasible this is and the only step I can imagine taking to prevent slowdown is to assign groups of students to different GPUs by telling them what value to pass cudaSetDevice().&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit for posterities' sake: &#xA;I ended up not taking any precautions and the lab ran smoothly. Wasn't much of test though, since only half (15 or so) students did the lab simultaneously, and we only got to cover really simple hello-world kernels. &#xA;Second edit:&#xA;There were two servers, with two GeForce GTX 650 Tis per server&lt;/p&gt;&#xA;" OwnerUserId="9047" LastEditorUserId="9047" LastEditDate="2018-08-02T15:27:00.017" LastActivityDate="2018-08-02T15:27:00.017" Title="How to avoid slowdown with 25-30 students running simple GPU kernels on 4 GeForce GTX 650 Ti s?" Tags="&lt;gpgpu&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7832" PostTypeId="5" CreationDate="2018-07-20T15:47:42.000" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2018-07-20T15:47:42.000" LastActivityDate="2018-07-20T15:47:42.000" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7833" PostTypeId="4" CreationDate="2018-07-20T15:47:42.000" Score="0" Body="For questions about words, phrases and definitions that are specific to computer graphics." OwnerUserId="5778" LastEditorUserId="5778" LastEditDate="2018-07-22T18:16:12.057" LastActivityDate="2018-07-22T18:16:12.057" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7834" PostTypeId="1" AcceptedAnswerId="7836" CreationDate="2018-07-20T20:36:37.807" Score="1" ViewCount="78" Body="&lt;p&gt;When a 3D scene is rendered to a 2D display, the image is distorted near the edges of the display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If a 3D scene is rendered onto a hemispherical display, will there still be warping?&lt;/p&gt;&#xA;" OwnerUserId="9050" LastActivityDate="2018-07-21T18:52:47.007" Title="If a 3D scene is rendered onto a hemispherical display, will there still be warping near the edges?" Tags="&lt;3d&gt;&lt;projections&gt;&lt;hemisphere&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7835" PostTypeId="2" ParentId="7834" CreationDate="2018-07-21T04:29:57.783" Score="1" Body="&lt;p&gt;Assuming each pixel is the same size then each pixel would cover the same viewing angle whether it is in the centre or towards the edge. So no, there would be no distortion. &lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2018-07-21T04:29:57.783" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7836" PostTypeId="2" ParentId="7834" CreationDate="2018-07-21T18:44:29.263" Score="2" Body="&lt;p&gt;There will be no distortion as long as you project the scene properly onto your virtual camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In traditional raster graphics the scene is projected onto a plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UfSMS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UfSMS.png&quot; alt=&quot;Projection&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This makes it so that two equal solid angles to the camera can take up vastly different amounts of space on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QPxQH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QPxQH.png&quot; alt=&quot;Distortion&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, the distortion does not come from the screen itself but from the projection used. Now, if you render your scene using a hemisphere projection, you should have no warping whatsoever. However, rendering using such projection might prove to be non trivial or straight up imposible using common methods (an exception to this is ray-tracing/marching/casting where all you need to change is how you generate your camera rays).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An alternative is to render various views (one facing the front, one facing upwards, etc) rendered in the classic flat projection and then &quot;stitch&quot; those together by mapping them to the screen somehow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a github repository of such a thing: &lt;a href=&quot;https://github.com/shaunlebron/blinky&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/shaunlebron/blinky&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; : The display has little to do with how distorted an image appears. It is the projection used by the software that creates warping. Therefore, Even when using a curved display, the image will still appear distorted, unless this is compensated for in software.&lt;/p&gt;&#xA;" OwnerUserId="8680" LastEditorUserId="8680" LastEditDate="2018-07-21T18:52:47.007" LastActivityDate="2018-07-21T18:52:47.007" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7838" PostTypeId="1" AcceptedAnswerId="7850" CreationDate="2018-07-21T22:56:25.773" Score="1" ViewCount="352" Body="&lt;p&gt;Is it possible to force Vulkan to execute a shader on vertices (data) in a semi-consecutive manner?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if the data passed to the shaders as a binary tree, shader would process it one layer at the time, starting from the root, while allowing multiple nodes to be processed concurrently only if they're on the same layer. I know that synchronicity is a big thing in Vulkan, but I'm unsure if it could be used at this layer of the pipeline. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A use for it would be in a structure where the results of parents influence the results of their children, while the work on the each element is done with the same code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example would be to calculate the effect of the wind on a tree - if nodes are the branching points of a tree, the location of each point would depend on the force applied to the source branch, but also on the force applied to each and every of it's ancestors, since each branch would bend, but also move with the rest of the tree - the rotations would add up. Doing it the way I described above would greatly speed up the computation for a single tree, possible increasing performance enough to scale the simulation maybe even several orders of magnitude. The benefits are even greater if you do it for all the trees in the scene at once.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this possible with Vulkan? What topics should I look into specifically in order to accomplish this?&lt;/p&gt;&#xA;" OwnerUserId="5215" LastActivityDate="2018-07-23T19:20:34.123" Title="Controling order of execution of a (compute) shader on an array of vertices (data) in Vulkan" Tags="&lt;shader&gt;&lt;compute-shader&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7839" PostTypeId="2" ParentId="7830" CreationDate="2018-07-22T10:31:14.960" Score="2" Body="&lt;p&gt;You need nvidia-docker. If your ssh server is in a Docker instance, you can assign each one to a different GPU. Then just set things up so only one team is sshing into each Docker instance. You don't need to do anything fancy with &lt;code&gt;cudaSetDevice()&lt;/code&gt;, or risk students using the wrong device and messing things up for others, because each instance looks like it only has one GPU.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-22T10:31:14.960" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7842" PostTypeId="1" AcceptedAnswerId="7844" CreationDate="2018-07-22T18:56:06.277" Score="2" ViewCount="135" Body="&lt;p&gt;I have a rudimentary understanding of COM and I know that its main purpose is to enable interoperability between programs written in different languages. However I dont understand why that is useful to the DirectX api. Is it because DirectX has to make calls to the windows api which are written in C whereas DirectX is written in C++?&lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2018-07-23T10:42:29.853" Title="Why does DirectX use COM pointers and interfaces?" Tags="&lt;c++&gt;&lt;directx&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7844" PostTypeId="2" ParentId="7842" CreationDate="2018-07-23T10:42:29.853" Score="4" Body="&lt;p&gt;C++ has no defined ABI, so C++ programs can't link to libraries that were compiled with a different compiler. In addition, MS's Visual Studio C++ compiler is not ABI-stable, so you don't just have to use the same compiler: you have to use the same version that the library was compiled with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This would be a huge problem for a widely-used library like DirectX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;COM doesn't just enable interoperability between different languages, but also between different C++ compilers. In fact, I'd say this is its main use, and language compatibility is less used. By being a COM library, DirectX can avoid application developers needing to care what compiler it was compiled with. Application developers are free to use a Visual Studio version of their choice, or a completely different C++ compiler.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-23T10:42:29.853" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7845" PostTypeId="1" AcceptedAnswerId="7846" CreationDate="2018-07-23T14:49:24.107" Score="1" ViewCount="146" Body="&lt;p&gt;I am writing a procedural terrain renderer for OpenGL. To shade the terrain I use multitexturing, that is 4 material textures and a blend map which distributes them across the terrain (encoded in RGBA).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I decide to split my terrain patch into two, blend map, consequently gets split too. Now there is a seam problem. Because of texture filtering, on the edges, the color &quot;bleeds&quot; from the opposite side of the texture. I recognize this can be fixed by setting texture repeat parameter to GL_MIRRORED_REPEAT or GL_CLAMP_TO_EDGE.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe that glTexParameteri function sets parameters for currently bound texture unit, still I'm unsure if these parameters get saved in texture unit's state, e.g. each texture unit &quot;remembers&quot; its parameters. Moreover, I know these parameters can be set per texture object. In that case whose parameters should take precedence?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a more concrete note, I sample blend map from GL_TEXTURE0. So I had an idea to set repeat parameters for GL_TEXTURE0 once before rendering all terrains, but it doesn't work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if I set this for every terrain rendered (absolutely the same code), it works. I'm inclined to believe that texture units don't &quot;remember&quot; their parameters. Is there something else I'm missing here?&lt;/p&gt;&#xA;" OwnerUserId="7282" LastActivityDate="2018-07-23T15:38:44.570" Title="Texture units parameters in OpenGL" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7846" PostTypeId="2" ParentId="7845" CreationDate="2018-07-23T15:38:44.570" Score="3" Body="&lt;p&gt;Your understanding of the behavior of texture units and state is confused. That's to be expected: OpenGL's pre-DSA API is not making it easy to understand this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as core profile OpenGL is concerned, the &lt;em&gt;only&lt;/em&gt; texture unit state is what textures are bound to which targets. That's all. Therefore, all &lt;code&gt;glTexParameter&lt;/code&gt; calls affect the state of the texture &lt;em&gt;object&lt;/em&gt; bound to the currently active texture unit, not of the texture unit itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So there is no &quot;precedence&quot;. Texture objects have state, which are modified by &lt;code&gt;glTexParameter&lt;/code&gt; calls. This is made more clear in direct state access APIs, because &lt;code&gt;glTextureParameter&lt;/code&gt; directly takes a texture object, rather than a bound texture target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you call &lt;code&gt;glTexParameter&lt;/code&gt; when texture object 0 is bound to the given texture target, then you're setting the parameter of the default texture object for that unit/target. And you shouldn't do that.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-07-23T15:38:44.570" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7849" PostTypeId="2" ParentId="7828" CreationDate="2018-07-23T18:37:11.323" Score="11" Body="&lt;p&gt;Well I researched quite a lot after that and this paper helped a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;&quot;Space Subdivision algorithms&quot; by Macdonald 1988.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So just summing what I understood. Some of them are obvious reasons but after reading the paper make much more sense and I'll try to do the same here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; In BVH we are subdividing objects into smaller pieces. So for example a model of dragon consisting of thousands of triangles, We first start with a Bounding Volume covering the whole dragon. Then we subdivide again and again until our conditions are met. In BVHs, the leafnodes usually have 1 object in contrast to octrees which can have many. However this isn't clear whether it's referring to an object (sphere) or a single triangle since spheres can contain hundreds of triangles if triangulated. Here is a picture explaining BVH.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H0QzQ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H0QzQ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In contrast, Octrees/K-d trees and other space subdivision, divide the space recursively. A simple picture of an octree given in the paper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/t15ok.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t15ok.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; The above pictures show another difference. That is, in Space subdivisions we have disjoint sets of space regions or voxels or cells whatever you wanna call them. In contrast, BVHs have disjoint sets of objects. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means in octrees one object may be assigned to more than 1 voxel. And thus we may have to check for that object again and again though this can be avoided using techniques like mailboxing etc.  In BVHs, however, this isn't the case as an object may be inside only 1 bounding volume at a time, thus it may be checked for intersection only once which is when the ray intersects the bounding volume it's currently in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; The other difference the paper mentions is that in Space subdivision traversal algorithms usually calculate the exit point of the ray from the current intersected child node and calculate a new point just past this exit point and from this information the next child node is found. The benefit of this is that traversal may stop as soon as it hits an object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, BVHs can't do this since in BVHs we may have object overlapping in nodes. In this case we will have to maintain a list of the intersected objects and find which is the closest one. A good example of this is given in &quot;&lt;strong&gt;&lt;em&gt;Raytracing Complex Scenes by Kajiya&lt;/em&gt;&lt;/strong&gt;&quot; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As we can see although the ray first intersects the upper BV, the closest object hit is actually inside the lower BV which the upper one has no information of unlike space subdivision structures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0nPx4.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0nPx4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And now on to the part of how I implemented the structure, it seems what Kajiya suggested was to use the octree scheme to define a traversing algorithm for the BVH. In the end when I recalculated the bounding volumes of each cells, this relaxed many voxels boundaries causing several to overlap. After this operation the structure didn't resemble &lt;em&gt;&quot;Disjoint sets of spaces&quot;&lt;/em&gt; rather it resembled &lt;em&gt;&quot;disjoint sets of objects&quot;&lt;/em&gt; hence it's essentially a BVH.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do note that this operation may sound like somewhat an efficient optimization to the space subdivision structure, that is relaxing the bounds of voxels to avoid having all the voxels keep track of the object that overlaps them. This way we assign 1 object to 1 voxel and relax it bounds. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But doing so we lose the traversing efficiency of space subdivision structure where we could have stopped after intersecting only 1 object. Other pros may also have been lost. That's what I have understood so far.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anybody would like to add some more feel free to do so.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-07-23T18:37:11.323" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7850" PostTypeId="2" ParentId="7838" CreationDate="2018-07-23T19:20:34.123" Score="3" Body="&lt;p&gt;Vulkan is not really suited to at least some of the task you're trying to accomplish. It has no mechanism to declare from within a shader that some additional work should be invoked. Or at least, not directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most effective way to execute this on the GPU would be to compute each level of &lt;em&gt;all&lt;/em&gt; of the trees as a distinct dispatch operation. So you process all root nodes first, then the first level for each tree, then the second level, etc. Each compute shader invocation will need to do the processing for its node and store that computed data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This also requires that you store your tree data in a fairly scrambled way. All of your trees need to live (on the GPU side) in the same general array, preferably with all nodes for a particular level stored contiguously with one another. This makes processing easier, but it makes adding new nodes harder.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The biggest performance problem will likely be the dependency issue. Each layer depends on the execution of the previous layer, which means you won't get much parallelism between layers. You're effectively inducing a stall between each set of layers. If you're executing thousands of nodes, you'll saturate your GPU's execution units just fine; it's the first few layers when you have few nodes that will have less performance than they could.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, you may be able to avoid this performance problem by using a different shader for the first couple of layers. Such a shader would have each invocation process, say, the first 3 levels of the tree. On the one hand, this mitigates synchronization costs. But on the other hand, each shader invocation has to read and process a lot more data. And reading/writing a bunch of data from multiple invocations can be expensive, compared to having a more pipelined operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you should profile it and see what works best.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Oh, and FYI: OpenGL compute shaders are just as capable of this as Vulkans.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-07-23T19:20:34.123" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7851" PostTypeId="1" AcceptedAnswerId="7855" CreationDate="2018-07-24T01:09:23.913" Score="0" ViewCount="422" Body="&lt;p&gt;I am developping a voxel raytracer for global illumination.&lt;/p&gt;&#xA;&lt;p&gt;I have been successful in multiple aspects but there is a problem I am not sure how to solve.&lt;/p&gt;&#xA;&lt;p&gt;The model works as most other Voxelization based algorithms work. We use rasterization to store the scene in a 3D volumetric structure and then we raytrace inside of said 3D structure.&lt;/p&gt;&#xA;&lt;p&gt;In the &amp;quot;pure&amp;quot; model (only voxels) I can generate prety decent shadows (ignore the circular artifacts):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/b76Fa.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/b76Fa.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However when I try to create a combined scene (normal rendering for colors, voxels for shadows) I sometimes get self intersection based artifacts:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sIamK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sIamK.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I can improve the image a bit by using an epsilon tolerance (considering that if we are too close to the original starting position we haven't collided with anything yet):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ngtYt.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ngtYt.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However doing this creates poor shadows by eliminating certain collissions (look at the archs for example, where the areas too close to the source should be darkened but are instead lightened).&lt;/p&gt;&#xA;&lt;p&gt;I want to know if there is a better way to check for self intersection, other than checking the original position?&lt;/p&gt;&#xA;&lt;p&gt;i.e I want to be able to get as close to the shadows in the first image as possible.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-07-24T08:08:41.727" Title="Self intersection artifacts in 3D image raytracing" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;antialiasing&gt;&lt;ray&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7852" PostTypeId="1" AcceptedAnswerId="7856" CreationDate="2018-07-24T03:18:53.347" Score="3" ViewCount="263" Body="&lt;p&gt;I am currently trying to understand IBL in Unreal Engine, and there are so much things that I don't understand about the formula. Unreal approximate the specular term of shading equation by doing split sum approximation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/77jXZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/77jXZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how unreal pre-filter the environment map for specular-irradiance term.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 PrefilterEnvMap(float Roughness, float3 R )&#xA;{&#xA;    float3 N = R;&#xA;    float3 V = R;&#xA;    float3 PrefilteredColor = 0;&#xA;    const uint NumSamples = 1024;&#xA;    for(uint i = 0; i &amp;lt; NumSamples; i++ )&#xA;    {&#xA;        float2 Xi = Hammersley( i, NumSamples );&#xA;        float3 H = ImportanceSampleGGX( Xi, Roughness, N );&#xA;        float3 L = 2 * dot  ( V, H ) * H - V;&#xA;        float NoL =saturate( dot  ( N, L ) );&#xA;        if ( NoL &amp;gt; 0 )&#xA;        {&#xA;            PrefilteredColor += EnvMap.SampleLevel( EnvMapSampler, L, 0 ).rgb * NoL;&#xA;            TotalWeight += NoL;&#xA;        }&#xA;    }&#xA;    return PrefilteredColor / TotalWeight;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My question is why does the total weight is the sum of saturate(dot(N,L)). My understanding on importance sampling is that we should divide our sample with the pdf we use to sample. In this case, from what I read at &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; the pdf should be &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$p_i(wm, wo) = \frac{D(wm)(wm \cdot wg)}{4|wo \cdot wm|}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My reference on pbr in unreal engine is &lt;a href=&quot;https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://learnopengl.com/PBR/IBL/Specular-IBL&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8565" LastEditorUserId="8565" LastEditDate="2018-07-24T03:42:49.327" LastActivityDate="2018-07-24T09:15:43.627" Title="Importance Sampling in Unreal Engine Formula Derivation (Irradiance term)" Tags="&lt;shader&gt;&lt;brdf&gt;&lt;real-time&gt;&lt;pbr&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7855" PostTypeId="2" ParentId="7851" CreationDate="2018-07-24T08:08:41.727" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I want to know if there is a better way to check for self intersection, other than checking the original position?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Since cubes are convex solids, a self-intersection check shouldn't introduce artefacts in your case, while it would in a more general ray-tracer (see &lt;a href=&quot;https://computergraphics.stackexchange.com/a/4987/2041&quot;&gt;my answer about the shadow terminator problem&lt;/a&gt; for more about that). In general, it's a good idea for your ray object to have a reference of some kind to the object it came from, as well as the kind of ray it is (primary, shadow, reflection, refraction). Normally the reference should be to the exact polygon, not just the whole object; in your case, it should be the particular cube. You could identify it by the co-ordinates of the cube, if you're using spatial hashing to store your voxel grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, in your intersection test, if your ray is a shadow ray, you should check whether the origin cube is the same as the cube being intersected, and discard that intersection if so.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-07-24T08:08:41.727" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7856" PostTypeId="2" ParentId="7852" CreationDate="2018-07-24T09:09:34.783" Score="3" Body="&lt;p&gt;I just read &lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;notes on moving frostbite to pbr&lt;/a&gt; and I found the derivation of the method above. So I will just show the derivation here and quote some of the explanation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/76tsj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/76tsj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;One can notice an extra〈n·l〉in the LD term as well as a different&#xA;  weighting 1/(∑Ni〈n·l〉). These empirical terms have been introduce by&#xA;  Karis to allows to improve the reconstructed lighting integral which&#xA;  suffers from coarse hypothesis of separability of this integral. &#xA;  There is no mathematical derivation for these terms, goal was to have&#xA;  an exact match with a constant L(l).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So it turns out the pdf is weighted on the DFG term. As for dot(N,l), the term is introduced to minimize the error that is caused by split sum approximation. But I am actually still wondering what is the intuition on that empirical term.&lt;/p&gt;&#xA;" OwnerUserId="8565" LastEditorUserId="8565" LastEditDate="2018-07-24T09:15:43.627" LastActivityDate="2018-07-24T09:15:43.627" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7857" PostTypeId="1" CreationDate="2018-07-25T05:17:31.807" Score="1" ViewCount="257" Body="&lt;p&gt;My path-tracer is generally fine and gives good output for regular test scenes, but I've noticed dense fireflies and dark speckles over fractal surfaces. The noise disappears if I render without light gathers (or zero every gather) and definitely isn't driven by hidden NaNs, so I suspect it's happening because fractals are naturally &quot;rough&quot; while my occlusion tests assume smooth surfaces (with constant shadow-ray offsets).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would it be possible to evaluate local distance variance at each intersection and scale my shadow-ray offsets appropriately? Would it have a significant effect if so, or would I be better off writing a denoiser?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few different test images with constant shadow offset; explicit light sampling is always performed with MIS (one BXDF sample, one spatial sample).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1h8gR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1h8gR.png&quot; alt=&quot;Explicit light sampling, 4096spp, $2\epsilon$ ray offset&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Explicit light sampling for a fractal surface, 4096spp, $2\epsilon$ ray offset&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/A92E9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A92E9.png&quot; alt=&quot;Classical path-tracing only, 4096spp, $2\epsilon$ ray offset&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Classical path tracing for a fractal surface, 4096spp, no explicit shadow rays&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ubFUd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ubFUd.png&quot; alt=&quot;Explicit light sampling for a sphere, 4096spp, $2\epsilon$ ray offset&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Explicit light sampling for a sphere, 4096spp, $2\epsilon$ ray offset&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Yc4bn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Yc4bn.png&quot; alt=&quot;Classical path tracing for a sphere, 4096spp, $2\epsilon$ ray offset&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Classical path tracing for a sphere, 4096spp, no explicit shadow rays&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-07-25T05:17:31.807" Title="Handling shadow acne for dynamic surfaces" Tags="&lt;pathtracing&gt;&lt;shadow&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="17" ContentLicense="CC BY-SA 4.0" />
  <row Id="7860" PostTypeId="1" CreationDate="2018-07-26T11:44:02.760" Score="0" ViewCount="574" Body="&lt;p&gt;I am testing the Intel RealSense D435 camera and have been able to create multiple Point Clouds (.ply) of a certain object. Each Point Cloud is taken in a different viewing angle of the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I wish to merge all these point clouds into a single, 3D Object. I have tried CloudCompare but this requires manual cropping of outliers and noisy data, as well as translating each Point cloud.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wonder if there is a piece of code that can merge point clouds together and remove noisy data in order to have a rough 3D Object?&lt;/p&gt;&#xA;" OwnerUserId="9068" LastActivityDate="2018-10-12T19:16:54.960" Title="Merge multiple Point Clouds into a single 3D object" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ClosedDate="2018-10-14T18:32:21.250" ContentLicense="CC BY-SA 4.0" />
  <row Id="7861" PostTypeId="1" CreationDate="2018-07-26T15:39:48.543" Score="4" ViewCount="197" Body="&lt;p&gt;OpenGL is not object-oriented, but more like &quot;switches you turn on&quot;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glEnable(...);&#xA;list_id = glGenLists(1);&#xA;glNewList(list_id, GL_COMPILE);&#xA;glBegin(GL_TRIANGLES);&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It seems like one's turning on switches on some machine which is contained somewhere, but it isn't seen as an object in object-oriented sense?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a name for this kind of programming or library paradigm?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using it from C++, but perhaps the way it's used is &quot;C-style&quot;?&lt;/p&gt;&#xA;" OwnerUserId="6029" LastActivityDate="2018-07-26T23:14:39.343" Title="What is OpenGL's paradigm?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7862" PostTypeId="2" ParentId="7861" CreationDate="2018-07-26T15:59:36.137" Score="5" Body="&lt;p&gt;It's generally referred to as a &quot;state machine&quot;. It has, as you noticed, a bunch of switches and parameters. All of them are globally accessible to any code that has access to the current context. Your program sets them and then issues draw calls. Anything you don't change, will remain in that state until you do change it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also a &lt;a href=&quot;https://en.wikipedia.org/wiki/Hardware_abstraction&quot; rel=&quot;noreferrer&quot;&gt;Hardware Abstraction&lt;/a&gt;. The same OpenGL routines should have roughly the same effect regardless of the hardware it's running on. If you upload 3 vertices for a triangle and then draw them, that should produce similar results on an ATI, Nvidia, or Intel GPU, for example. You don't need machine-specific instructions for each one.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-07-26T15:59:36.137" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7863" PostTypeId="1" CreationDate="2018-07-26T17:58:39.993" Score="1" ViewCount="1082" Body="&lt;p&gt;How to convert from glBegin() and glEnd() to VBOs (Vertex Buffer Objects)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found a simple example here:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat vertices[] = {...}; // 36 of vertex coords&#xA;...&#xA;// activate and specify pointer to vertex array&#xA;glEnableClientState(GL_VERTEX_ARRAY);&#xA;glVertexPointer(3, GL_FLOAT, 0, vertices);&#xA;&#xA;// draw a cube&#xA;glDrawArrays(GL_TRIANGLES, 0, 36);&#xA;&#xA;// deactivate vertex arrays after drawing&#xA;glDisableClientState(GL_VERTEX_ARRAY);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.songho.ca/opengl/gl_vertexarray.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.songho.ca/opengl/gl_vertexarray.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;So if I have code in very &quot;standard&quot; glBegin() and glEnd() fashion like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBegin(GL_TRIANGLES);&#xA;&#xA;    for(int j = 0; j &amp;lt; vecf.size(); j++){&#xA;        glNormal3f(vecn[vecf.at(j)[2]-1][0], vecn[vecf.at(j)[2]-1][1], vecn[vecf.at(j)[2]-1][2]);&#xA;        glVertex3f(vecv[vecf.at(j)[0]-1][0], vecv[vecf.at(j)[0]-1][1], vecv[vecf.at(j)[0]-1][2]);&#xA;        glNormal3f(vecn[vecf.at(j)[5]-1][0], vecn[vecf.at(j)[5]-1][1], vecn[vecf.at(j)[5]-1][2]);&#xA;        glVertex3f(vecv[vecf.at(j)[3]-1][0], vecv[vecf.at(j)[3]-1][1], vecv[vecf.at(j)[3]-1][2]);&#xA;        glNormal3f(vecn[vecf.at(j)[8]-1][0], vecn[vecf.at(j)[8]-1][1], vecn[vecf.at(j)[8]-1][2]);&#xA;        glVertex3f(vecv[vecf.at(j)[6]-1][0], vecv[vecf.at(j)[6]-1][1], vecv[vecf.at(j)[6]-1][2]);&#xA;    }&#xA;&#xA;glEnd();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then how do I convert this to VBOs?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Particularly, I already know that I need to supply vertices array and normals array, but I seem to confuse the orders of some vecs, because what's drawn becomes out as distorted.&lt;/p&gt;&#xA;" OwnerUserId="6029" LastEditorUserId="6029" LastEditDate="2018-07-26T21:15:02.133" LastActivityDate="2018-08-30T14:00:50.953" Title="How to convert from glBegin() and glEnd() to VBOs?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7866" PostTypeId="2" ParentId="7861" CreationDate="2018-07-26T23:14:39.343" Score="0" Body="&lt;p&gt;The proper term for this style is called &quot;imperative programming.&quot; You would be correct in thinking that it is similar to C because C is classified as an imperative programming language.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more about the paradigm, you can read about it here: &lt;a href=&quot;https://en.wikipedia.org/wiki/Imperative_programming&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Imperative_programming&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9086" LastActivityDate="2018-07-26T23:14:39.343" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7867" PostTypeId="1" CreationDate="2018-07-27T05:53:22.263" Score="1" ViewCount="471" Body="&lt;p&gt;Let's assume we have voxelized a scene, and all of our materials have an opacity level of 1. The reuslt would then look like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NxkZw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NxkZw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we raytraced the final volume that gets generated after rasterization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we wish to generate soft shadows, which is done by increasing the LOD sample level as we move further away from the source, sampling at discrete intervals and adding opacity values until we reach an opacity of 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If my understanding is correct that is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could soemone that is familiar with this technique give a better explanation and correct any mistakes I have made? Pictures and diagrams are appreciated too.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-27T05:53:22.263" Title="How exactly do soft shadows get generated using a voxel cone tracing rendering technique?" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;rendering&gt;&lt;global-illumination&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7868" PostTypeId="1" CreationDate="2018-07-27T07:34:32.563" Score="1" ViewCount="205" Body="&lt;p&gt;I am trying to generate soft shadows using voxel cone tracing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which gives me the next images:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qoXFk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qoXFk.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pAykT.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pAykT.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first image you can see an artifact of a sequence of horizontal shadows alternating with illuminated areas, which looks quite odd.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the second image you can see that the left side is shadowed and the right isn't, although both sides are equidistant to the light, so they should be equally illuminated. In addition to that, in the second image you can see that in the columns, the shadows are jaggy and the outline is clear (no soft shadows).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to solve these 3 problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I am currently generating my shadows from my 3D texture is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    fragment_color = blinn_phong();&#xA;&#xA;    float v_size = cube_dim/voxel_resolution;&#xA;    vec3 r = f_pos + f_norm*v_size*2;&#xA;    vec3 dir = normalize(light-r);&#xA;    vec3 start = r;&#xA;    float l=0;&#xA;    float acc=0;&#xA;    vec4 val;&#xA;    while(incube(r, cube_dim) &amp;amp;&amp;amp; (l&amp;lt;=length(start-light)) &amp;amp;&amp;amp; acc&amp;lt;1)&#xA;    {&#xA;        l=length(start-r);&#xA;        r += dir*v_size*0.5;&#xA;        val = textureLod(normal_map, (r-vec3(0.5))*0.5/cube_dim+vec3(0.5), l*0.0001);&#xA;        acc += val.w;&#xA;    }&#xA;    fragment_color *= (1-acc);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-27T07:34:32.563" Title="Voxel cone tracing artifacts (what causes them and how to solve them)?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shadow&gt;&lt;global-illumination&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7869" PostTypeId="1" CreationDate="2018-07-27T10:18:18.683" Score="1" ViewCount="871" Body="&lt;p&gt;Consider a ray tracer written in OpenGL and using GLFW as a window toolkit. There are basically 2 options to display the ray-traced image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1) Create a &lt;code&gt;RenderBuffer&lt;/code&gt; with image and blit this to the default framebuffer.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2) Render the scene to a texture and use a full screen quad to display that texture.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What if I want to render the scene in a resolution that is different from the window size? How do I handle rescaling of images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Case 1)&lt;/strong&gt; Render to high resolution image/texture and display to low resolution window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know how should I handle for downscaling the texture/image in both cases. I am particularly interested in the &lt;code&gt;Renderbuffer&lt;/code&gt; approach though. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Case 2)&lt;/strong&gt; Render to low resolution image/texture and display to high resolution window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am pretty sure case 2 could be easy to implement through textures by setting the filter to &lt;code&gt;LINEAR&lt;/code&gt; or &lt;code&gt;NEAREST&lt;/code&gt; perhaps, the sampling function would automatically upscale it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not sure what would happen to the renderBuffer approach in either case. I have read though that &lt;code&gt;Blit&lt;/code&gt; between buffers of different sizes are supported.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also in both cases, how would I handle the aspect ratio?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;:- What I mean by handling aspect ratio is, to my knowledge there are two ways I could handle it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Either stretch the whole image to fit the window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Or make it &quot;fit&quot; to the window like Windows 7 wallpaper setting. This way the original aspect ratio of the Image will be maintained. Any space not covered by the image would be black in the window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a crappy painting to show what I mean.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GvnOF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GvnOF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if the Red window is my RBO/Texture  and Black Window is the actual window ( default framebuffer) opened by GLFW. Left and right show two cases when either the RBO is greater or smaller than the default framebuffer with varying aspect ratio.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two ways, Either fit or stretch. I want to know if OpenGL provides functions for these sorts of settings or it does some or part of these things automatically. Plus I want to know this thing for both &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Case 1) RBO &lt;/p&gt;&#xA;&#xA;&lt;p&gt;and &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Case 2) Texture. &lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-07-28T11:06:28.813" LastActivityDate="2018-07-28T11:06:28.813" Title="OpenGL - Fit High/Low Resolution Image/Texture to a particular size Window" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;image&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="7871" PostTypeId="1" CreationDate="2018-07-27T21:30:49.750" Score="0" ViewCount="186" Body="&lt;p&gt;I have a scene rendered using texelFetch() and I am trying to modify the shader to use textureLod() instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the image generated with texelFetch:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9sMuT.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9sMuT.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I try to change the shader to use textureLod instead I get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mDO4r.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mDO4r.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So as you can see, areas that should not be darkend are now darkened. This seems like the downscaling to the 0-1 coordinate system was not done properly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how I generated the first image:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fragment_color = blinn_phong();&#xA;&#xA;float v_size = cube_dim/voxel_resolution;&#xA;vec3 r = f_pos + f_norm*v_size*2;&#xA;vec3 dir = normalize(light-r);&#xA;vec3 start = r;&#xA;ivec3 first = ivec3(((r)*0.5/(cube_dim)+vec3(0.5))*(voxel_resolution-1));&#xA;float hit = 1.f;&#xA;while(incube(r, cube_dim) &amp;amp;&amp;amp; (length(start-r)&amp;lt;=length(start-light)))&#xA;{&#xA;    r += dir*v_size*0.5;&#xA;    ivec3 hpos = ivec3(((r)*0.5/cube_dim+vec3(0.5))*(voxel_resolution-1));&#xA;    vec4 val = texelFetch(normal_map, hpos, 0);&#xA;    if(val.w &amp;gt; 0 &amp;amp;&amp;amp; (first != hpos))&#xA;    {&#xA;        hit=atan(length(start-r)/200.f)/(PI/2.f)*0.9 + 0.1;&#xA;        break;&#xA;    }&#xA;}&#xA;fragment_color *=hit;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this is how I generated the second:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fragment_color = blinn_phong();&#xA;&#xA;float v_size = cube_dim/voxel_resolution;&#xA;vec3 r = f_pos + f_norm*v_size*2;&#xA;vec3 dir = normalize(light-r);&#xA;vec3 start = r;&#xA;ivec3 first = ivec3(((r)*0.5/(cube_dim)+vec3(0.5)));&#xA;float hit = 1.f;&#xA;while(incube(r, cube_dim) &amp;amp;&amp;amp; (length(start-r)&amp;lt;=length(start-light)))&#xA;{&#xA;    r += dir*v_size*0.5;&#xA;    vec3 hpos = vec3(((r)*0.5/cube_dim+vec3(0.5)));&#xA;    vec4 val = textureLod(normal_map, hpos, 0);&#xA;    if(val.w &amp;gt; 0 &amp;amp;&amp;amp; (first != hpos))&#xA;    {&#xA;        hit=atan(length(start-r)/200.f)/(PI/2.f)*0.9 + 0.1;&#xA;        break;&#xA;    }&#xA;}&#xA;fragment_color *=hit;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In other words, the changes consist only on not scaling by the voxel  resolution, which should result in a 0 to 1 coordinate system, instead of the 0 to texture dimensions coordinate system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alas, it would seem that I am downscaling thins wrongly.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-07-27T21:30:49.750" Title="Changing coordinate system from texelFetch to textureLod is breaking the algebra" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;shadow&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7873" PostTypeId="1" AcceptedAnswerId="7890" CreationDate="2018-07-28T23:59:40.227" Score="4" ViewCount="141" Body="&lt;p&gt;Looking at the Wikipedia page for Circle of Confusion, and at such posts as &lt;a href=&quot;https://photo.stackexchange.com/questions/24826/is-there-a-formula-to-calculate-dof&quot;&gt;this one&lt;/a&gt;, I completely understand how to calculate the values for near, far, focal planes and hyperfocal distance. I am also aware of the Zeiss formula for my desired format.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What I'm trying to find out is how to take real camera parameters (focal distance, aperture, focal length) and get a &lt;em&gt;blur radius&lt;/em&gt; or similar usable value to configure a blur with them.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, I'm simply using this function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float getBlurSize(float depth, float focusPoint, float focusScale) {&#xA;    float coc = clamp((1.0 / focusPoint - 1.0 / depth)*focusScale, -1.0, 1.0);&#xA;    return abs(coc) * MAX_BLUR_SIZE;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;All real-world inputs are available to the shader - Aperture f-Number, focal distance, format dimensions (35mm in this case), maximum acceptable CoC from the Zeiss formula, focal length etc., as well as depth and colour. Currently, I am applying the calculations and blur in post.&lt;/p&gt;&#xA;" OwnerUserId="9041" LastEditorUserId="2041" LastEditDate="2018-07-31T06:45:59.080" LastActivityDate="2018-08-07T18:52:01.080" Title="Deriving blur from real optical formulae" Tags="&lt;blur&gt;&lt;camera&gt;&lt;post-processing&gt;&lt;depth-of-field&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7874" PostTypeId="1" AcceptedAnswerId="7875" CreationDate="2018-07-29T10:33:19.703" Score="2" ViewCount="189" Body="&lt;p&gt;I am analyzing the hex code for DDS files which are compressed via Nvidia's dds plugin in photoshop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I noticed something strange when having a 16 bit float file. This is the dialog: &#xA;&lt;a href=&quot;https://i.stack.imgur.com/J9PiD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/J9PiD.png&quot; alt=&quot;Dialog&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I look at the header of this file it appears to not follow the DDS spec. According to the DDS docs for the pixel format (&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3ddds/dds-pixelformat&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/desktop/direct3ddds/dds-pixelformat&lt;/a&gt;)&#xA;the dwFlags of 0x4 indicates a FOURCC but the next 4 bytes, which usually contain the FOURCC like &quot;DXT1&quot; etc contain only a &quot;o&quot;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/QOvKx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QOvKx.png&quot; alt=&quot;Hex viewl&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;AFAIK the for various other formats the locations and FOURCC (when present) are correctly displayed.&#xA;Here is a luminance 8 (dwFLags to 0x20000 and no FOURCC)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wU6Vu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wU6Vu.png&quot; alt=&quot;L8&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and here is a DXT1&#xA;&lt;a href=&quot;https://i.stack.imgur.com/1MC3r.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1MC3r.png&quot; alt=&quot;DXT1&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could somebody hint what happens for 16f here?&lt;/p&gt;&#xA;" OwnerUserId="9096" LastEditorUserId="6" LastEditDate="2020-04-09T15:16:50.467" LastActivityDate="2020-04-09T15:16:50.467" Title="Image saved as DDS with 16f format in photoshop has strange FOURCC text" Tags="&lt;directx&gt;&lt;raster-image&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7875" PostTypeId="2" ParentId="7874" CreationDate="2018-07-29T19:03:21.360" Score="2" Body="&lt;p&gt;The tool seems to be generating an unofficial extended version of DDS in which the FOURCC code is replaced by a value from the &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3d9/d3dformat&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;D3DFORMAT&lt;/code&gt; enum&lt;/a&gt;. The code &lt;code&gt;0x0000006F&lt;/code&gt; translates to decimal 111, which translates to &lt;code&gt;D3DFMT_R16F&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Microsoft DDS documentation notes that this is seen sometimes, although not recommended: &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3ddds/dx-graphics-dds-pguide#dds-variants&quot; rel=&quot;nofollow noreferrer&quot;&gt;DDS Variants&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;There are some common variants in use where the pixel format is set to a DDPF_FOURCC code where dwFourCC is set to a D3DFORMAT or DXGI_FORMAT enumeration value. There is no way to tell if an enumeration value is a D3DFORMAT or a DXGI_FORMAT, so it is highly recommended that the &quot;DX10&quot; extension and DDS_HEADER_DXT10 header is used instead to store the dxgiFormat when the basic DDS_PIXELFORMAT cannot express the format.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-07-29T19:03:21.360" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7876" PostTypeId="1" CreationDate="2018-07-29T22:35:45.530" Score="0" ViewCount="127" Body="&lt;p&gt;I am generating shadows using a voxel pyramid (commonly called voxel cone, although I hate that term).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some of my shadows come as expected, however some are very strange.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example in this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xGcQD.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xGcQD.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at the back column at the right, we have a neat soft shadow. However the shadows over the shield are hard, As are the shadows on the other columns.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not sure why or how these hard shadows are being created.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I am making my shadows is the standard shadow pyramid that increases as the ray advances, sampling at different LOD's&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, this is the shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{&#xA;    fragment_color = blinn_phong();&#xA;&#xA;    float v_size = cube_dim/voxel_resolution;&#xA;    vec3 r = f_pos + f_norm*v_size*6;&#xA;    vec3 dir = normalize(light-r);&#xA;    vec3 start = r;&#xA;    float l=0;&#xA;    float acc=0;&#xA;    vec4 val1, val2;&#xA;    while(incube(r, cube_dim) &amp;amp;&amp;amp; (l&amp;lt;=length(start-light)) &amp;amp;&amp;amp; acc&amp;lt;1)&#xA;    {&#xA;        l=length(start-r);&#xA;        r += dir*v_size*0.2;&#xA;        float coeff = 0.001;&#xA;        l = min(l, 7*1.f/(coeff));&#xA;        val1 = textureLod(normal_map, (r)*0.5/cube_dim+vec3(0.5), l*coeff);&#xA;        acc += val1.a;&#xA;    }&#xA;&#xA;    acc = min(acc, 1);&#xA;    fragment_color *= (1-acc)*0.8 + 0.2;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-08-01T22:33:16.560" LastActivityDate="2018-08-01T22:33:16.560" Title="Hard edges appearing in voxel cone tracing (how to remove them?)" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;global-illumination&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7877" PostTypeId="2" ParentId="7707" CreationDate="2018-07-30T00:59:17.243" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;strong&gt;First, (1/2) I didn't understand how the hash table is actually used.&lt;/strong&gt; The workflow I think I understood is the following :&lt;/p&gt;&#xA;  &#xA;  &lt;ol&gt;&#xA;  &lt;li&gt;&lt;p&gt;For an input (coordinate), we find the both nearest pre-defined coordinates (i.e. : those present as indices in A). It's a multiple of&#xA;  255.&lt;/p&gt;&lt;/li&gt;&#xA;  &lt;li&gt;&lt;p&gt;The lower one is used to lookup in B&lt;/p&gt;&lt;/li&gt;&#xA;  &lt;li&gt;&lt;p&gt;We get a number between [0;255] that we use to lookup in A &lt;/p&gt;&lt;/li&gt;&#xA;  &lt;li&gt;&lt;p&gt;We get a number between [0;1] : the noise.&lt;/p&gt;&lt;/li&gt;&#xA;  &lt;/ol&gt;&#xA;  &#xA;  &lt;p&gt;But where is the interpolation between the both pre-defined&#xA;  coordinates' noise values ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There are 4 of most of what you wrote here, then the interpolation. For example, if your 2D input is (2.7, 6.4):&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;You would truncate that to (2,6).&lt;/li&gt;&#xA;&lt;li&gt;Then perform the permutation and noise lookup steps for (2,6), (3,6), (2,7), (3,7).&lt;/li&gt;&#xA;&lt;li&gt;And finally perform a 2D interpolation (lerp) of the 4 lookups with the remainder of your input: (0.7, 0.4).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;As for the second part of your question, the table is just a creative way to get a &quot;(int, int) -&gt; int&quot; hashing function to go from input coordinates to an index to pick a value in the random data table. You could use any generic hash function instead. In fact, the method used is fairly obsolete for CPUs as it does not lend itself to SIMD implementation and has horrible memory dependencies. It might still have value for GPUs as they have different behavior. But it will have a visible period of 256 which can cause problems in images. So it is really a poor hash function but for the CPUs back then, it was fast and used little memory which is likely why it was picked.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2018-07-30T00:59:17.243" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7878" PostTypeId="2" ParentId="7863" CreationDate="2018-07-30T08:36:09.087" Score="0" Body="&lt;p&gt;You first need to put all the data into a VBO in the correct order, it's important that each vertex position corresponds with the normal it uses.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex{&#xA;    vec3 pos;&#xA;    vec3 normal;&#xA;}&#xA;&#xA;std::vector&amp;lt;Vertex&amp;gt; vertices;&#xA;vertices.reserve(vecf*3);&#xA;Vertex v;&#xA;&#xA;for(int j = 0; j &amp;lt; vecf.size(); j++){&#xA;    v.normal = vec3(vecn[vecf.at(j)[2]-1][0], vecn[vecf.at(j)[2]-1][1], vecn[vecf.at(j)[2]-1][2]);&#xA;    v.pos = vec3(vecv[vecf.at(j)[0]-1][0], vecv[vecf.at(j)[0]-1][1], vecv[vecf.at(j)[0]-1][2]);&#xA;    vertices.push_back(v);&#xA;    v.normal = vec3(vecn[vecf.at(j)[5]-1][0], vecn[vecf.at(j)[5]-1][1], vecn[vecf.at(j)[5]-1][2]);&#xA;    v.pos = vec3(vecv[vecf.at(j)[3]-1][0], vecv[vecf.at(j)[3]-1][1], vecv[vecf.at(j)[3]-1][2]);&#xA;    vertices.push_back(v);&#xA;    v.normal = vec3((vecn[vecf.at(j)[8]-1][0], vecn[vecf.at(j)[8]-1][1], vecn[vecf.at(j)[8]-1][2]);&#xA;    v.pos = vec3(vecv[vecf.at(j)[6]-1][0], vecv[vecf.at(j)[6]-1][1], vecv[vecf.at(j)[6]-1][2]);&#xA;    vertices.push_back(v);&#xA;}&#xA;&#xA;int vbo;&#xA;glGenBuffer(1, &amp;amp;vbo);&#xA;&#xA;glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex)*vertices.size(), vertices.data(), GL_STATIC_DRAW);&#xA;glVertexAttribPointer(posAttr, 3, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, pos));&#xA;glVertexAttribPointer(normalAttr, 3, GL_FLOAT, sizeof(Vertex), (void*)offsetof(Vertex, normal));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then you can draw it with &lt;code&gt;glDrawArrays(GL_TRIANGLES, 0, vertices.size());&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-07-30T08:36:09.087" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7879" PostTypeId="2" ParentId="7465" CreationDate="2018-07-31T06:08:56.077" Score="3" Body="&lt;p&gt;First it converts the red, green, and blue values from the 8-bit unsigned integer range to floating point values between 0 and 1. It then figures out which component is the maximum, which is the minimum and the distance between the minimum and maximum. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the min and max are equal, then the saturation is 0, and it makes no sense to calculate a hue. Here they are setting the hue to 0, but in reality, it's simply undefined. Assuming that no hue equals 0 hue can cause problem if you later manipulate the colors, so be careful with that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the min and max are not equal, then we can calculate a hue. The shape of the HSL color space is a double hexagonal cone. What the next part does is attempt to figure out which segment of the hexagonal cone the hue is in. If the maximum of the red, green, and blue, was the red channel, then it's in the area bounded by -60° to +60°. If green is the max, then the hue is between 60° and 180°, and if blue is the max, then the hue is between 180° and 300° (aka -60°). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The division in the hue calculation generates a value between -1 and 1. If red is the maximum component, then &lt;code&gt;green - blue&lt;/code&gt; is either the middle value minus the lower value, or it's the lower value minus the middle value. And since the middle and lower value are never greater than the maximum, dividing by the delta will always give a value between -1 and 1. Once you have a value between -1 and 1, you multiply it by 60 to get the degrees. For the other 2 cases, you add either 2 or 4 before the multiply in order to rotate it 120° or 240° for the green and blue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next it calculates the lightness by simply averaging the min and max components. (This is a very poor way to represent the perceived brightness of a color, by the way.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, it calculates the saturation. If the delta is 0, then saturation is 0. Otherwise it divides the delta by &lt;code&gt;1 - abs(2 * L - 1)&lt;/code&gt;. Essentially, it's saying that saturation is proportional to the distance between the minimum and the maximum values and inversely proportional to the lightness's distance from 50% lightness. In other words, as you move away from the vertical center of the double hex cone, towards the pointy ends, the distance between the min and max components has a bigger effect on saturation. A difference in the delta of, say, .1 at the center will not show much difference in saturation, but when the lightness is very close to either 0 or 1, it will make a large difference in saturation.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2018-07-31T16:01:54.800" LastActivityDate="2018-07-31T16:01:54.800" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7880" PostTypeId="2" ParentId="7863" CreationDate="2018-07-31T13:54:43.867" Score="3" Body="&lt;p&gt;Back when I did the transition from immediate mode to vertex buffer object (VBO) in my own code base, I have found it easier to proceed with these steps:&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;From naive immediate mode code...&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The original code was something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBegin(GL_TRIANGLES);&#xA;glNormal3f(nx, ny, nz);&#xA;glVertex3f(px, py, pz);&#xA;// [...] arbitrary long sequence of such function calls.&#xA;glEnd();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h1&gt;1. To array based immediate mode code...&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;First, keep using the immediate mode, but make sure that all values passed to the vertex functions come from an array. This seems to be already the state of the code described in the question.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float vertexData[] = { ... }; // Can be all together, or split by attribute type, as you prefer.&#xA;glBegin(GL_TRIANGLES);&#xA;for (int i = 0; i &amp;lt; numberOfVertices; ++i)&#xA;{&#xA;    // The indices are going to depend on the data layout.&#xA;    glNormal3f(vertexData[0], vertexData[1], vertexData[2]);&#xA;    glVertex3f(vertexData[3], vertexData[4], vertexData[5]);&#xA;}&#xA;glEnd();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h1&gt;2. To vertex array version...&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Second, you can replace the loop by a handful of calls with vertex arrays.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glEnableClientstate(GL_Vertex_Array);&#xA;glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), vertexData);&#xA;glNormalPointer(GL_FLOAT, 6 * sizeof(float), vertexData + 3);&#xA;glDrawArrays(GL_TRIANGLES, 0, numberOfVertices);&#xA;glDisableClientState(GL_VERTEX_ARRAY);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h1&gt;3. To vertex buffer version&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Finally from the vertex array based version, the transition to VBO is minimal:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// An initialization part will create and populate the vertex buffer:&#xA;GLuint vboId = 0;&#xA;glGenBuffers(1, &amp;amp;VBOid);&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, VBOid);&#xA;glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(float), vertexData, GL_STATIC_DRAW);&#xA;&#xA;&#xA;// A draw part will bind the vertex buffer and issue the drawcall.&#xA;// It's almost the same code as before, except:&#xA;// - We bind a VBO&#xA;// - We pass (0+offset) as the last parameter for the gl*pointer().&#xA;glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBOId);&#xA;&#xA;glEnableClientstate(GL_Vertex_Array);&#xA;glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (void*)(0));&#xA;glNormalPointer(GL_FLOAT, 6 * sizeof(float), (void*)(0 + 3));&#xA;glDrawArrays(GL_TRIANGLES, 0, numberOfVertices);&#xA;glDisableClientState(GL_VERTEX_ARRAY);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And that's it. Both vertex array and VBO allow to work directly with vertices or with vertex index, so be careful about possible confusion there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S.: I have written this answer without double checking the code, so it's probably ridden with typos and not meant for copy-pasting. I invite you to read the documentation, understand the API and refer to other examples when you implement it. At first, VBO can be really annoying to get to work properly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have used the same distinction when answering this other &lt;a href=&quot;https://computergraphics.stackexchange.com/a/36/182&quot;&gt;question about performance of VBO&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2018-07-31T13:54:43.867" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7881" PostTypeId="1" CreationDate="2018-07-31T14:44:33.153" Score="3" ViewCount="101" Body="&lt;p&gt;I pulled a .zip file from &lt;a href=&quot;https://www.deviantart.com/clairejones/art/Apophysis-Starter-Flames-V-67029474&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.deviantart.com/clairejones/art/Apophysis-Starter-Flames-V-67029474&lt;/a&gt; and the file I was interested was the &lt;code&gt;.flame&lt;/code&gt; file which contains parameters for several different Fractal Flames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of them looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;flame name=&quot;CJ_Starter_Flame_1&quot; version=&quot;Apophysis 2.06c beta&quot; size=&quot;640 512&quot; center=&quot;0.536884822382779 -0.626382357937026&quot; scale=&quot;764.167485097157&quot; angle=&quot;1.82997772071605&quot; rotate=&quot;-104.85&quot; oversample=&quot;2&quot; filter=&quot;1&quot; quality=&quot;5&quot; background=&quot;0 0 0&quot; brightness=&quot;2&quot; gamma=&quot;5&quot; &amp;gt;&#xA;   &amp;lt;xform weight=&quot;0.5&quot; color=&quot;0&quot; linear=&quot;0.98505982500501&quot; spherical=&quot;0.0149401749949902&quot; coefs=&quot;0.047466 -0.574133 0.524841 0.137706 0.620555 -0.116118&quot; /&amp;gt;&#xA;   &amp;lt;xform weight=&quot;0.5&quot; color=&quot;1&quot; spherical=&quot;0.17593513103202&quot; bubble=&quot;0.82406486896798&quot; coefs=&quot;0.268823 -0.261644 0.261644 0.268823 0.204257 0.083402&quot; /&amp;gt;&#xA;   &amp;lt;palette count=&quot;256&quot; format=&quot;RGB&quot;&amp;gt;&#xA;      253625384A3348593D5C664C6E685B7A7260827363938169&#xA;...&#xA;   &amp;lt;/palette&amp;gt;&#xA;&amp;lt;/flame&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Having read &lt;a href=&quot;http://flam3.com/flame.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;the original Draves &amp;amp; Reckase paper&lt;/a&gt; some of this is obvious.  The &lt;code&gt;coefs=&lt;/code&gt; probably contains the parameters of the affine transform.  The thing that really confuses me is how a single &lt;code&gt;xform&lt;/code&gt; clause mentions two variants, e.g. &lt;code&gt;linear&lt;/code&gt; and &lt;code&gt;spherical&lt;/code&gt;.  It appears that the values on each attribute sum to 1 so they are probably weights/probabilities.  But why are there two xform clauses?  Are they alternating weighted transform sets?&lt;/p&gt;&#xA;" OwnerUserId="8598" LastActivityDate="2018-09-18T19:28:52.547" Title="How do I interpret the format of the .flame files used by apophysis?" Tags="&lt;2d&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7882" PostTypeId="1" CreationDate="2018-08-02T04:53:14.720" Score="2" ViewCount="396" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/idwl1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/idwl1.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know how to deal with the color of object,Should i use diffuse reflection on the surface?&lt;/p&gt;&#xA;" OwnerUserId="9108" LastActivityDate="2018-08-07T07:21:48.570" Title="how to render colored glass object?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7883" PostTypeId="1" AcceptedAnswerId="7887" CreationDate="2018-08-02T10:04:07.693" Score="1" ViewCount="116" Body="&lt;p&gt;I wish to draw a plane (A building's floor in this case) over a canvas plane (assume the plane is smooth). The planes are drawn as QUADS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that both plane are located at the same height. This causes a flickering between the images as I zoom in/out. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wish for the floor texture / plane to have a higher priority over the base canvas plane. Is it possible? If so, how may I achieve it? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried putting the floor plane just slightly above the canvas plane, but it doesn't sit right with me considering my use case allows the user to set any building height and he/she may enter a very low value to height, cause a lot of problems. &lt;/p&gt;&#xA;" OwnerUserId="9113" LastActivityDate="2018-08-02T21:56:09.690" Title="Drawing a plane super-imposing over another plane" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7884" PostTypeId="1" CreationDate="2018-08-02T12:18:06.197" Score="1" ViewCount="594" Body="&lt;p&gt;Skia 2D's one notable backend in OpenGL, but how does it work under the hood to render?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Say, we need to draw an anti-aliased circle. Does Skia:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;make a quad (using 2 triangles) and paint the circle on top of it&#xA;using auto generated shaders?&lt;/li&gt;&#xA;&lt;li&gt;Or, makes hundreds of triangles and arrange them into a fan? (plus&#xA;possible tessellation)&lt;/li&gt;&#xA;&lt;li&gt;Or, something else?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4967" LastActivityDate="2018-08-02T12:18:06.197" Title="How Skia uses OpenGL backend?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;2d-graphics&gt;&lt;triangulation&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7885" PostTypeId="2" ParentId="7882" CreationDate="2018-08-02T12:22:27.860" Score="2" Body="&lt;p&gt;A common interpretation of surfaces for rendering is that of a BSDF (Bidirectional Scattering Distribution Function) made up of a BRDF (R stands for Reflectance) and a BTDF (T stands for Transmittance).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In such a model, the reflectance part is the light that 'bounces' off the surface, and the transmittance part is the light that penetrates the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When modeling the latter there are two common looks that we try to replicate. One is that of pure refraction (light goes through and bends at the surface), and the other is that of diffusion (light bounces around within the surface and is re-emitted (this is commonly called diffuse reflection). What determines which one of these happens is the turbidity of the material, which is analogous to the probability of a light ray changing its path while inside the material.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These two phenomena are opposite ends of a spectrum and therefore there cannot, on real materials, be a blend (e.g. alpha blend) between the two. though one could concieve a model where turbidity of the material is not at either end but somewhere in-between, however that would require taking into account the volume of a 3d model and not only the surfaces (this often called Volume Scatter or Sub Surface Scatter).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, what you are looking for is probably refraction. There are many ways to aproximate it. One such way that will get you the expected color but not the distortion you might want is multiplicative blending.&lt;/p&gt;&#xA;" OwnerUserId="8680" LastActivityDate="2018-08-02T12:22:27.860" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7887" PostTypeId="2" ParentId="7883" CreationDate="2018-08-02T21:56:09.690" Score="3" Body="&lt;p&gt;The problem that you encounter is called &quot;z-fighting&quot; and it occurs when two objects with the same depth (z value) are rendered. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this example, we take two objects called ObjA and ObjB. They are the same, but have different colors. Due to the very small error that you get with fixed precision floating point numbers, ObjA may have a lower fragment depth than ObjB for a given pixel and thus ObjA's color is saved to that pixel, but ObjB could have a lower fragment depth for another given pixel and ObjB's color is then saved to that pixel. Which object will have a lower depth value is quite random and causes that flickering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two ways to fix this. Which one works best for you, depends on the program.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Option #1&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Disabling depth testing on the second surface that is being drawn. The first surface obviously draws well, and the problem comes when drawing that second surface. By disabling the depth test, OpenGL just draws every fragment to the framebuffer and you do not have that problem with &quot;which fragment has the lowest depth&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you only disable the depth test for the second surface and enable it again for the other surfaces (and render the second surface after the first surface), then it should work as the first surface still writes the depth values. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This approach starts to break, when the second surface either does not fully align with the first surface or the second surface is shaped in a way so that it overlaps itself. (When rendering a sphere, for each pixel you always render two fragments, the front side and the back side of the sphere. The back side would then not be culled away.)&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Option #2&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;Adding a bias to the depth values of the first surface. The problem is that both surfaces have the same depth value for a given pixel, but if you offset the depth values for one of them, then you do not have that problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just like &lt;code&gt;gl_FragColor&lt;/code&gt; which allows you to set the color in the framebuffer, &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragDepth.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;gl_FragDepth&lt;/code&gt;&lt;/a&gt; allows you to set the depth in the depth buffer. You could get the normal depth value from &lt;code&gt;gl_FragCoord&lt;/code&gt; (as the documentation says) and add a small amount to it. Doing this, does not actually change anything of the mesh. The mesh does not move around and it does not go further into z-space. The shader simply writes a different depth value to the depth buffer. This depth buffer is only used for depth testing and can thus easily be changed to get the effect we want. This only needs to be done for the first surface and not the second surface or any other surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the bias is too large, artifacts can visibly show up around intersections with the surface, but when the bias is small it should not be noticeable.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-08-02T21:56:09.690" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7890" PostTypeId="2" ParentId="7873" CreationDate="2018-08-05T05:39:22.830" Score="3" Body="&lt;p&gt;First we can calculate the physical diameter of CoC in the image plane, given the lens parameters. This equation is from &lt;a href=&quot;https://en.wikipedia.org/wiki/Circle_of_confusion#Determining_a_circle_of_confusion_diameter_from_the_object_field&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia – Circle of confusion&lt;/a&gt;:&#xA;$$&#xA;c = {|S_2 - S_1| \over S_2} {f^2 \over N(S_1 - f)}&#xA;$$&#xA;where the variables are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$c$: the physical CoC diameter in the image plane&lt;/li&gt;&#xA;&lt;li&gt;$S_1$: focal distance (the distance at which a subject would be in perfect focus)&lt;/li&gt;&#xA;&lt;li&gt;$S_2$: actual distance to the subject (the point whose CoC we are calculating)&lt;/li&gt;&#xA;&lt;li&gt;$f$: the focal length of the lens&lt;/li&gt;&#xA;&lt;li&gt;$N$: the f-number at which the lens aperture is set.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Then, divide this CoC diameter by the film or sensor frame size to get the blur diameter in texture coordinates. You can additionally multiply it by your rendering resolution to get the blur diameter in pixels if desired.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an example calculation, suppose we render a 1920×1080 image, as if through a 85mm lens at f/1.4, on a 35mm camera (frame size 36×24 mm), and focused at 3m while our subject is 5m away. Then we can calculate:&#xA;$$&#xA;{|5\text{m} - 3\text{m}| \over 5\text{m}} {(85\text{mm})^2 \over 1.4(3\text{m} - 85\text{mm})} {1920\text{px} \over 36\text{mm}}&#xA;$$&#xA;(Don't forget to convert units, since we are mixing meters and millimeters here!) I get a blur diameter of ~38 px, so the radius would therefore be ~19 px.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2018-08-07T18:52:01.080" LastActivityDate="2018-08-07T18:52:01.080" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7894" PostTypeId="1" CreationDate="2018-08-06T08:14:20.967" Score="0" ViewCount="107" Body="&lt;p&gt;I am trying to retrieve OpenGL's color buffer with the following code. My program is crasing in the line that makes the call to &lt;strong&gt;glReadPixels()&lt;/strong&gt; apparently &lt;code&gt;image.data&lt;/code&gt; has not enough memory but how could it be if i'm getting the size from &lt;strong&gt;GL_VIEWPORT&lt;/strong&gt; ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I missing something else? I already checked for errors with &lt;strong&gt;glGetError()&lt;/strong&gt; and it returns 0 right before the call to glReadPixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void GLWidget::readGLBuffer(cv::Mat&amp;amp; image)&#xA;{&#xA;    GLint vp[4];&#xA;    glGetIntegerv(GL_VIEWPORT, vp);&#xA;&#xA;    const GLint&amp;amp; cols = vp[2];&#xA;    const GLint&amp;amp; rows = vp[3];&#xA;&#xA;    if (rows * cols &amp;lt;= 0)&#xA;        return;&#xA;&#xA;    image = cv::Mat(rows, cols, CV_8UC3);&#xA;&#xA;    glReadBuffer(GL_FRONT); // glReadPixels reads the back buffer by default&#xA;    glReadPixels(vp[0], vp[1], cols, rows, GL_RGB, GL_UNSIGNED_BYTE, image.data);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="116" LastActivityDate="2018-08-06T08:14:20.967" Title="How to compute size of OpenGL's image buffer?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7895" PostTypeId="1" AcceptedAnswerId="7896" CreationDate="2018-08-06T12:41:58.827" Score="1" ViewCount="51" Body="&lt;p&gt;I'm referring to this section: &lt;a href=&quot;https://www.w3.org/TR/compositing-1/#simplealphacompositing&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.w3.org/TR/compositing-1/#simplealphacompositing&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Considering the formula &lt;code&gt;co = Cs x αs + Cb x αb x (1 - αs)&lt;/code&gt; the docs state then, that &lt;code&gt;co&lt;/code&gt; is the &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the premultiplied pixel value after compositing&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I would argue that this is not the case, since in &lt;a href=&quot;http://jcgt.org/published/0004/02/03/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; the resulting color is depicted with a capital C and in the case of premultiplied version, the lower case is used (&lt;code&gt;c&lt;/code&gt;). I'm not really sure if this is the case, it's not too obvious from both docs and the article. So, is the result of  &lt;code&gt;co = Cs x αs + Cb x αb x (1 - αs)&lt;/code&gt; really a premultiplied value?&lt;/p&gt;&#xA;" OwnerUserId="9133" LastActivityDate="2018-08-06T18:48:36.140" Title="Are w3.org docs correct?" Tags="&lt;alpha&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7896" PostTypeId="2" ParentId="7895" CreationDate="2018-08-06T18:48:36.140" Score="0" Body="&lt;p&gt;Yes, the statement in the W3C doc is correct. You can tell because the background term includes premultiplication by the background alpha αb. If it were non-premultiplied, it wouldn't have an αb in it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-08-06T18:48:36.140" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7897" PostTypeId="1" CreationDate="2018-08-06T19:15:34.117" Score="1" ViewCount="435" Body="&lt;p&gt;Where should the ray origin be put in perspective camera ray tracing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following gives a picture of the ray tracing in the perspective camera setting:&#xA;&lt;a href=&quot;https://www.cs.cornell.edu/courses/cs4620/2011fa/lectures/06raytracingWeb.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.cs.cornell.edu/courses/cs4620/2011fa/lectures/06raytracingWeb.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and says that the &lt;span class=&quot;math-container&quot;&gt;$e$&lt;/span&gt; is the ray origin, which is the same for all rays. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I don't understand how &lt;span class=&quot;math-container&quot;&gt;$e$&lt;/span&gt; is supposed to be selected.&#xA;Can it be the zero vector? Or perhaps it is supposed to be the camera center?&lt;/p&gt;&#xA;" OwnerUserId="6029" LastEditorUserId="209" LastEditDate="2020-05-27T07:11:53.413" LastActivityDate="2020-05-27T07:11:53.413" Title="Where should the ray origin be put in perspective camera ray tracing?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7898" PostTypeId="2" ParentId="7897" CreationDate="2018-08-06T19:56:56.080" Score="1" Body="&lt;p&gt;I don't get what you don't understand. All rays originate from the camera so It's basically the start of the camera's pyramid or more technically the viewing frustum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P3Qs3.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P3Qs3.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depends on the system you are using. Maybe your camera is fixed at the origin and only the world rotates/moves. In this case, usually the camera is fixed at the origin looking in either the +Z or -Z direction depending on if it's left or right handed coordinates system. So the ray origins will be fixed at &lt;code&gt;(0,0,0)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your camera moves, however, the ray origins  also move to where you place the camera.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-08-06T19:56:56.080" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7900" PostTypeId="1" CreationDate="2018-08-07T04:03:07.437" Score="1" ViewCount="116" Body="&lt;p&gt;I recently learned about Delaunay triangulation algorithm.. This algorithm prevents the generation of skinny triangles.. I haven't really seen any good explanation of why we don't want skinny triangles.. Can anyone explain the reason?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks..&lt;/p&gt;&#xA;" OwnerUserId="2687" LastActivityDate="2018-08-07T15:26:18.420" Title="Why does skinny triangle is avoided in triangulation algorithm?" Tags="&lt;triangulation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7903" PostTypeId="1" CreationDate="2018-08-07T11:31:45.853" Score="1" ViewCount="344" Body="&lt;p&gt;I was reading other questions in this topic but I couldn't apply any viable solution to solve my use case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a crop area described with two dimensions (cropWidth, cropHeight)&#xA;I can easly compute center point of this area &lt;code&gt;C:[cx, cy]&lt;/code&gt;.&#xA;At the begining I have perfectly aligned image to the crop area.&#xA;We can assume that image width and height are equal to cropWidth and cropHeight (figure below). &#xA;We can also calculate &lt;code&gt;P1,P2,P3,P4&lt;/code&gt; points which corresponds to rectangle (image) vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iTj1I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iTj1I.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;I can:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;scale image (always from center C)&lt;/li&gt;&#xA;&lt;li&gt;translate it&lt;/li&gt;&#xA;&lt;li&gt;rotate around the C origin&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Let's say that I would like to do everything (translate, scale, rotate) and receive new image position &lt;code&gt;I1, I2, I3 ,I4&lt;/code&gt;.&#xA;I have access to object which describe all translations eg.:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const transform = {&#xA;    scaleRatio: 1.25,&#xA;    tx: 10,&#xA;    ty: 20,&#xA;    radians: 0.21&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What I'm trying to do is to follow transformation order:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Move origin&lt;/li&gt;&#xA;&lt;li&gt;Scale&lt;/li&gt;&#xA;&lt;li&gt;Rotate&lt;/li&gt;&#xA;&lt;li&gt;Translate back origin&lt;/li&gt;&#xA;&lt;li&gt;Translate tx, ty&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;How it looks like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const transformations = transform(&#xA;    translate(-cx, -cy),&#xA;    scale(scaleRatio),&#xA;    rotate(radians),&#xA;    transalte(cx, cy),&#xA;    translate(-tx, -ty)   &#xA;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where &lt;code&gt;transform&lt;/code&gt; function is simply matrix multiplication. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;After all transformations my image can look like below:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/IJ4lg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IJ4lg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;No matter what I'm not able to receive correct values of all image vertices. Can someone point me to right approach? &lt;/p&gt;&#xA;" OwnerUserId="9141" LastActivityDate="2018-08-07T11:31:45.853" Title="How to apply scale, translate, rotate with different origin and get new rectangle coordinates" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="7904" PostTypeId="1" CreationDate="2018-08-07T13:41:02.537" Score="1" ViewCount="417" Body="&lt;p&gt;I'm getting started with graphics and I'm having trouble implementing the Bresenham's algorithm. Now, I know that my implementation is incomplente, but I can't see why it doesn't make horizontal lines(same height(y) values, different width(x values). I get a floating point exception. Here's the algo:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int draw_line(void *mlx_ptr, void*win_ptr, t_2dpoint *initial_p, t_2dpoint *final_p)&#xA;{&#xA; 53     int delta_x;&#xA;&#xA; 53     int delta_x;&#xA; 54     int y;&#xA; 55     int delta_y;&#xA; 56&#xA; 57     delta_x = final_p-&amp;gt;x - initial_p-&amp;gt;x;&#xA; 58     delta_y = final_p-&amp;gt;y - initial_p-&amp;gt;y;&#xA; 59&#xA; 60     x = initial_p-&amp;gt;x;&#xA; 61     y = initial_p-&amp;gt;y;&#xA; 62     e = (float)(delta_x / delta_y) - 1.0;&#xA; 63&#xA; 64     while(x &amp;lt; final_p-&amp;gt;x - 1)&#xA; 65     {&#xA; 66         mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0XFF00FF);&#xA; 67         if ( e &amp;gt;= 0)&#xA; 68         {&#xA; 69             y += 1;&#xA; 70             e -= 1.0;&#xA; 71         }&#xA; 72         x += 1;&#xA; 73         e += (float)delta_x / delta_y;&#xA; 74     }&#xA; 75     mlx_pixel_put(mlx_ptr, win_ptr, x, y, 0XFF00FF);&#xA; 76 }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9143" LastActivityDate="2018-09-06T15:01:49.807" Title="Bresenham's Algorithm not drawing horizontal lines" Tags="&lt;vector-graphics&gt;&lt;line-drawing&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7905" PostTypeId="2" ParentId="7904" CreationDate="2018-08-07T14:11:50.857" Score="2" Body="&lt;pre&gt;&lt;code&gt;e = (float)(delta_x / delta_y) - 1.0;&#xA;&#xA;e += (float)delta_x / delta_y;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Either of these lines will cause a divide-by-zero error when &lt;code&gt;delta_y&lt;/code&gt; is zero, which is when the line is horizontal (or zero-length). You need to check for this condition and have some special-case code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an aside, I don't know why people still teach Bresenham's algorithm to new CG students. It's a good example of an algorithm but it's not very useful knowledge in itself: you're unlikely to need to know it unless it's for a job interview.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-08-07T14:11:50.857" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7906" PostTypeId="2" ParentId="7900" CreationDate="2018-08-07T14:28:27.837" Score="2" Body="&lt;p&gt;We don't want to avoid skinny triangles as much as we want to avoid really long triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Long triangles make interpolation of properties less accurate because the points in which the data is stored are farther apart. This is equivalent to – when using a 2160p (4K UHD) screen – the preference of watching a 1080p video in fullscreen mode to watching the same video but in 720p, also in fullscreen mode. The 720p video is streched 3 times when the image is rescaled to fullscreen while the 1080p video is only streched 2 times; hence the pixels in the 720p video are streched farther apart compared with the pixels in the 1080p video and the interpolation of the colors in the pixels become less acurate (simply because the 720p video &lt;a href=&quot;https://en.wikipedia.org/wiki/Nyquist_frequency&quot; rel=&quot;nofollow noreferrer&quot;&gt;can't contain&lt;/a&gt; as fine details as the 1080p video can), which is another way of saying that the 1080p video looks better than the 720p video when viewed in fullscreen on a 2160p screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the skinnier our triangles are, the longer they have to be in order to cover the same area, unless we use more triangles in total. The former is undesirable because of above mentioned reason. The latter is usually undesirable too since it increases the required memory consumption as well as the computational load on the algorithms that work with them since there are more triangles to loop through. We usually therefore want to avoid skinny triangles.&lt;/p&gt;&#xA;" OwnerUserId="5989" LastEditorUserId="5989" LastEditDate="2018-08-07T15:26:18.420" LastActivityDate="2018-08-07T15:26:18.420" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7908" PostTypeId="1" CreationDate="2018-08-09T07:44:12.513" Score="2" ViewCount="81" Body="&lt;p&gt;I'm trying to grasp how NURBS curves work. I think I understand the principle, but I'm unsure about the formula. Here, I base myself on &lt;a href=&quot;http://web.cs.wpi.edu/~matt/courses/cs563/talks/nurbs.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this course&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From a DXF file, I got the following parameters:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;knots (7): [0,0,0,0.5,1,1,1]&#xA;degree: 2&#xA;closed: false&#xA;control points (4): [(0,0), (-50,112.5), (150,112.5), (100,0)]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The knots vector looks good : non-decreasing, length of &lt;code&gt;#controls + degree + 1&lt;/code&gt;, max multiplicity of &lt;code&gt;degree+1&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are the formulas from the course:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$C(u) = \frac{\sum_{i=0}^n{w_i P_i N_{i,k}(u)}}{\sum_{i=0}^n{w_i P_i}}$&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$w_i$ : weights&lt;/li&gt;&#xA;&lt;li&gt;$P_i$ : control points (vector)&lt;/li&gt;&#xA;&lt;li&gt;$N_{i,k}$ : normalized B-spline basis functions of degree k&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;and the recursive B-spline basis function:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N_{i,k}(u) = \frac{u-t_i}{t_{i+k} - t_i} N_{i,k-1}(u) + \frac{t_{i+k+1}-u}{t_{i+k+1}-t_{i+1}} N_{i+1,k-1}(u)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$N_{i,0}(u) = 1$ if $t_i \leq u &amp;lt; t_{i+1}$ or $0$ otherwise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What I don't get is the fraction in the $N_{i,k}(u)$ function.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's take $i=0$ (calculating the influence of the first control point over the curve, if I understand correctly): because of the multiplicity, I've got $t_{i+k} = t_2 = 0$ and $t_i = t_0 = 0$, which makes me divide by zero ... What am I missing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: As usual, writing down the problem helps to solve it. By re-reading the material linked above, I realized I missed one line: 0/0 fractions should be considered as 0, not NaN. Is this right ? At least on the few toy examples I tried, my drawing matches the original DXF version.&lt;/p&gt;&#xA;" OwnerUserId="9150" LastEditorUserId="9150" LastEditDate="2018-08-10T14:01:33.910" LastActivityDate="2018-08-10T14:01:33.910" Title="drawing NURBS: knots, multiplicity, divide by zero?" Tags="&lt;nurbs&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7915" PostTypeId="1" AcceptedAnswerId="7922" CreationDate="2018-08-12T13:54:42.317" Score="3" ViewCount="794" Body="&lt;p&gt;I am using the book &lt;em&gt;Ray Tracing from the Ground Up&lt;/em&gt; by Kevin Suffern to build my first ray tracers in Java. Based on the theory, I expected that direct illumination and simple path tracers render the same scene equally bright (that is, when the resulting images are more of less converged and the path tracer only allows paths of maximal length 2). However, my implementation for a simple path tracer renders much darker images. Here is an example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RHsO4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RHsO4.png&quot; alt=&quot;Direct illumination&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HYiPq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HYiPq.png&quot; alt=&quot;Path tracer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The images on the left and right are respectively the result of direct illumination and path tracing with 225 rays per pixel. My path tracer does not use next event estimation; it returns black whenever the path becomes longer than a certain length without reaching the area light. For every pixel, the received radiances are averaged afterwards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I manually change the sensitivity, though (i.e. a simple post rendering scaling of the colours in the image), the path traced image becomes this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QTcUP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QTcUP.png&quot; alt=&quot;Lighter version of path tracer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, the brightened image is not near convergence, but it should at least be clear that the path tracer actually renders the same scene similarly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this normal behaviour? If so, could I just pick a larger power for the light source when using a path tracer? If not, please find some relevant code of my path tracer underneath.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;This is my code for shading an intersection point of a ray and a matte object. It is supposed to shoot an arbitrary ray from the intersection point along a cosine distribution (I have used a branch factor 1 for my images).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shadePath(Shading shading, BranchPathTracer tracer, int length) {&#xA;    int factor = tracer.getBranchFactor();&#xA;    cosinusSampler sampler = new cosinusSampler(factor);&#xA;    List&amp;lt;Point&amp;gt; samples = sampler.computeSamples();&#xA;    RGBSpectrum L = RGBSpectrum.BLACK;&#xA;&#xA;    for (Point sample : samples) {&#xA;        Vector w = shading.getIntersectionPoint().getNormal();&#xA;        Random PRNG = new Random();&#xA;        Vector r = new Vector(PRNG.nextDouble(), PRNG.nextDouble(), PRNG.nextDouble());&#xA;        Vector v = r.cross(w).normalize();&#xA;        Vector u = v.cross(w);&#xA;        Vector wi = u.scale(sample.x).add(v.scale(sample.y)).add(w.scale(sample.z)).normalize();&#xA;        Ray ray = new Ray(shading.getIntersectionPoint().toPoint(shading.getRay()), wi);&#xA;        L = L.add(tracer.trace(ray, length + 1));&#xA;    }&#xA;&#xA;    L = L.scale(1.0 / factor);&#xA;    return shading.getColour().scale(getDiffuseReflection()).multiply(L);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is how the cosine distributed samples are computed:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public List&amp;lt;Point&amp;gt; computeSamples() {&#xA;    List&amp;lt;Point&amp;gt; samples = new ArrayList&amp;lt;&amp;gt;();&#xA;    for (int i = 0; i &amp;lt; getSamples(); i++) {&#xA;        double phi = 2 * Math.PI * Math.random();&#xA;        double cosPhi = Math.cos(phi);&#xA;        double sinPhi = Math.sin(phi);&#xA;        double cosTheta = Math.sqrt(1 - Math.random());&#xA;        double sinTheta = Math.sqrt(1 - cosTheta * cosTheta);&#xA;        double pu = sinTheta * cosPhi;&#xA;        double pv = sinTheta * sinPhi;&#xA;        double pw = cosTheta;&#xA;        Point sample = new Point(pu, pv, pw);&#xA;        samples.add(sample);&#xA;    }&#xA;    return samples;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is the shading for emissive materials. &lt;code&gt;showPath&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; by default.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shadePath(Shading shading, BranchPathTracer tracer, int length) {&#xA;    Ray ray = shading.getRay();&#xA;    Vector n = shading.getIntersectionPoint().getNormal();&#xA;&#xA;    boolean showPath = tracer.getShowOnlyLength() == 0 || length == tracer.getShowOnlyLength();&#xA;    if (n.dot(ray.direction) &amp;lt; 0 &amp;amp;&amp;amp; showPath) {&#xA;        return getTexture().getColour().scale(getPower());&#xA;    } else {&#xA;        return RGBSpectrum.BLACK;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For reference, here is also my shading function for matte objects under direct illumination.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shade(Shading shading) {&#xA;    RGBSpectrum colour = shading.getColour();&#xA;    double L = 0;&#xA;    final Point intersection = shading.getIntersectionPoint().toPoint(shading.getRay());&#xA;&#xA;    for (Light light : shading.getScene().getLights()) {&#xA;        double l = 0;&#xA;&#xA;        for (Point sample : light.computeSamples()) {&#xA;            Vector wi = sample.subtract(intersection);&#xA;            double cos = shading.getIntersectionPoint().getNormal().dot(wi);&#xA;&#xA;            if (cos &amp;gt; 0) {&#xA;                Ray shadowRay = new Ray(intersection, wi);&#xA;&#xA;                if (!light.inShadow(shadowRay, shading.getScene())) {&#xA;                    if (light instanceof PointLight) {&#xA;                        double denom = 4 * Math.PI * wi.lengthSquared();&#xA;                        l += light.getPower() * cos / denom;&#xA;                    } else if (light instanceof RectangularLight) {&#xA;                        Rectangle rectangle = ((RectangularLight) light).getRectangle();&#xA;                        double cosp = -wi.dot(rectangle.getNormal());&#xA;                        l += light.getPower() * cos * cosp / (wi.lengthSquared() * rectangle.getArea());&#xA;                    }&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        L += l / light.getSamplesNumber();&#xA;    }&#xA;&#xA;    return colour.scale(getAmbientReflection() + L * getDiffuseReflection());&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I started to randomly change things in my code as a last desparate attempt to find the cause for my dark images. Funnily enough I found out that averaging over the square root of the number of rays per pixel (i.e. change &lt;code&gt;n * n&lt;/code&gt; into &lt;code&gt;n&lt;/code&gt; in the code underneath) seems to result in the correct brightness. Maybe this is a coincidence, because I don't use the number of rays per pixel anywhere else. Or maybe I'm still overlooking something.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// iterate over the contents of the tile&#xA;for (int y = tile.yStart; y &amp;lt; tile.yEnd; y++) {&#xA;    for (int x = tile.xStart; x &amp;lt; tile.xEnd; x++) {&#xA;        RGBSpectrum colour = scene.getBackground();&#xA;        Random PRNG = new Random(x * width + y);&#xA;&#xA;        // iterate over the contents of the subtile&#xA;        for (int p = 0; p &amp;lt; n; p++) {&#xA;            for (int q = 0; q &amp;lt; n; q++) {&#xA;                // create a ray through the center of the subtile.&#xA;                Double jitter1 = PRNG.nextDouble();&#xA;                Double jitter2 = PRNG.nextDouble();&#xA;                double rayX = x + (p + jitter1) / n;&#xA;                double rayY = y + (q + jitter2) / n;&#xA;                Ray ray = scene.getCamera().generateRay(new Sample(rayX, rayY));&#xA;&#xA;                // test the scene on intersections&#xA;                colour = colour.add(scene.getTracer().trace(ray));&#xA;            }&#xA;        }&#xA;&#xA;        // average the colours&#xA;        colour = colour.scale(1.0 / (n * n));&#xA;&#xA;        // add a color contribution to the pixel&#xA;        buffer.getPixel(x, y).add(colour);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9170" LastEditorUserId="9170" LastEditDate="2018-08-15T17:13:52.993" LastActivityDate="2018-08-15T19:12:51.530" Title="Should direct illumination and path tracers render the same scene equally bright?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7916" PostTypeId="1" AcceptedAnswerId="7918" CreationDate="2018-08-13T08:34:53.737" Score="1" ViewCount="4139" Body="&lt;p&gt;My phone is Sony Xperia XZ1 Compact which has Adreno 540 as gpu. My laptop's gpu is NVIDIA GeForce 940MX 4GB which seems to be much worse than my phone's gpu. My PC's OS is Ubuntu 16.04.&lt;/p&gt;&#xA;" OwnerUserId="9176" LastActivityDate="2019-12-25T19:43:41.230" Title="Can I use my phone's gpu as an external gpu for my laptop?" Tags="&lt;gpu&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7917" PostTypeId="1" CreationDate="2018-08-13T19:27:50.117" Score="1" ViewCount="98" Body="&lt;p&gt;I'm having problems when using the following statement on different GPUs:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexSubImage3D(target, 0, 0, 0, 0, width, height, layers, format, type, NULL);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;on NVIDIA cards &quot;format = GL_RGBA&quot; throws a fatal error that causes the program to crash, but it works and throws no errors if I use the sized version &quot;format = GL_RGBA8&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;on AMD cards &quot;format = GL_RGBA&quot; works and throws no errors, &quot;format = GL_RGBA8&quot; also works, but throws the error &quot;GL_INVALID_ENUMERATION&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;--&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently using GL_RGBA8, so it works on both cards, but I wonder if there is a way to do this that throws no errors on either card.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;--&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the spec for glTexSubImage3D from Khronos.org&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;format&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Specifies the format of the pixel data. The following symbolic values are accepted: GL_RED, GL_RG, GL_RGB, GL_BGR, GL_RGBA, GL_DEPTH_COMPONENT, and GL_STENCIL_INDEX.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;--&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using opengl 4.3 core profile, glfw and glew. Here is my texStorage statement called before glTexSubImage3D&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;internalFormat = GL_RGBA8;&#xA;glTexStorage3D(target, 1, internalFormat, width, height, layers);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;per the comments, the other values are&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;target = GL_TEXTURE_2D;&#xA;width = 4096;&#xA;height = 4096;&#xA;layers = 1;&#xA;format = GL_RGBA8;&#xA;type = GL_UNSIGNED_BYTE;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;--&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I using this incorrectly? Is there a way to satisfy both implementations?&lt;/p&gt;&#xA;" OwnerUserId="9180" LastEditorUserId="9180" LastEditDate="2018-08-13T21:38:00.743" LastActivityDate="2018-08-13T21:38:00.743" Title="glTexSubImage3D throws GL_INVALID_ENUMERATION on NVIDIA" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7918" PostTypeId="2" ParentId="7916" CreationDate="2018-08-13T21:19:08.323" Score="5" Body="&lt;p&gt;No. Your phone's GPU is in one chip with the CPU, some of the memory, and its display controller, and they're all tightly integrated together. Also, there'd be no way to connect it efficiently to the laptop. Only the latest generation of USB and Thunderbolt have enough bandwidth to be even worth considering for external GPUs, and even then, they're only used with dedicated hardware at the GPU end of the link - not a general-purpose processor. Apart from the fundamental problems, there's the very practical issue that your PC doesn't have any drivers for the GPU on the phone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know mobile GPUs are pretty effective, but if your phone's GPU seems faster than the Nvidia chip in your laptop, there's something wrong with your laptop. If you can give more information on the problem to the people at &lt;a href=&quot;//askubuntu.com/&quot;&gt;Ask Ubuntu&lt;/a&gt;, they can probably help with that.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-08-13T21:19:08.323" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7919" PostTypeId="1" CreationDate="2018-08-14T06:56:52.010" Score="1" ViewCount="410" Body="&lt;p&gt;So I want to path trace a Cornel Box scene, but I don't understand the values given here in section 2 and 3.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.graphics.cornell.edu/online/box/data.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cornell Box Data | Cornell University Program of Computer Graphics&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;No.2 Lists surface reflectances with respect to different wavelengths but I'm not using wavelengths. I thought this was done in spectral path/ray tracing where we are using photometry instead of radiometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly No.3 lists Light properties though I don't understand what do the values in the &lt;code&gt;light&lt;/code&gt; column (0, 8, 15.6, 18.4) suggest.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was merely expecting the specular and diffuse reflectivity in all 3 channels for each of the colors red, green and white.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorDisplayName="user7220" LastEditDate="2018-08-19T06:08:55.873" LastActivityDate="2018-08-19T06:08:55.873" Title="Interpreting Cornell Box data for path tracer" Tags="&lt;pathtracing&gt;&lt;physically-based&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="7922" PostTypeId="2" ParentId="7915" CreationDate="2018-08-15T15:57:01.463" Score="6" Body="&lt;p&gt;The results that you are getting, are not correct. More specifically, your direct illumination ray tracer is not correct. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When limiting a path tracer's bounces to only allow for any direct illumination (thus only the camera ray and one bounce ray for a total of two rays), its brightness should and will match any ray tracer doing only direct illumination. Once the path tracer's bounces are extended or unlimited, it will produce brighter images since it then recovers partially or all energy that would come in through the bouncing of light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you compare your path tracer to your direct illumination ray tracer, you will notice that in the path tracer on the blue wall, the brightest spot is closer to the light.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/MCRCi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MCRCi.png&quot; alt=&quot;Compare of his direct illumination ray tracer and path tracer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your path tracer here is correct, and it is the direct illumination ray tracer that does not give a correct image. To find out why, let us look at the math behind a path tracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To find out the radiance of a point for a given viewing angle ($w_{o}$), you integrate over the point's hemisphere. We currently ignore the term $L_{e}$ which is the light that the object emits at that point.&#xA;$$&#xA;L_{o}(x,w_{o})=\int_{\Omega }^{ }f_{r}(x, w_{i}, w_{o})L_{i}(x,w_{i})(w_{i}\cdot n)dw_{i}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;$L_{o}$ is the radiance of a point for a given viewing angle. a.k.a what a ray would return when traced.&lt;/li&gt;&#xA;&lt;li&gt;$x$ is the point.&lt;/li&gt;&#xA;&lt;li&gt;$w_{o}$ is the direction of outgoing light. a.k.a. viewing angle.&lt;/li&gt;&#xA;&lt;li&gt;$\int_{\Omega }^{ }$ is the integral over the hemisphere. a.k.a take a bunch of samples.&lt;/li&gt;&#xA;&lt;li&gt;$f_{r}$ is the result of the BRDF. a.k.a. the colour of the object.&lt;/li&gt;&#xA;&lt;li&gt;$L_{i}$ is the incoming radiance for that angle. a.k.a. what the rays, that you spawn in the shadePath() method, return.&lt;/li&gt;&#xA;&lt;li&gt;$w_{i}\cdot n$ is also written as $cos\theta _{i}$ and is used to weaken the incoming radiance due to how light actually works. You already did this by using cosine distributed samples.&lt;/li&gt;&#xA;&lt;li&gt;$dw_{i}$ is a part of the integral, and basically averages all the samples.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If we look at an example in 2D, we have a point with the hemisphere (here just half a circle) and a rectangular light (here just a line).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kPD72.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kPD72.png&quot; alt=&quot;A light covering 30° of a semicircle.&quot;&gt;&lt;/a&gt;&#xA;We see that the light takes up 30° of the 180° of the hemisphere (in 3D we would talk in area instead of degrees). If we move the light further back.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/OKHkY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OKHkY.png&quot; alt=&quot;A light that is covering 12° of a semicircle.&quot;&gt;&lt;/a&gt;&#xA;We see that the light now only takes up 12° of the 180° of the hemisphere. The further back a light is, the less it contributes to the final radiance of the point. In 2D this falloff is $1/d$ where $d$ is the distance. In 3D this falloff is $1/d^{2}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With a path tracer, this falloff is already done for you. If the light is further away, less samples would hit it and thus it contributes less.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wsY2L.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wsY2L.png&quot; alt=&quot;5 samples hitting a light&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/QGH34.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QGH34.png&quot; alt=&quot;3 samples hitting a light&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, with a direct illumination ray tracer or next-event-estimation, every sample will always hit the light (unless there is something blocking it). Therefore, we need to add that falloff back in. We do this by multiplying the incoming light from the area light by the falloff $1/d^{2}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we rotate the area light, we would notice that it would then also take up less area on the hemisphere. This should also be accounted for, and an easy way to approximate it is using the cosine between the normal of the area light and the outgoing direction. Which you already have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is the not having this falloff, that makes your direct illumination ray tracer not give correct results. You would need to make the area light brighter than, because of the falloff.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I have not missed anything else, that is all you need.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;EDIT&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Jeroen added the code for his direct illumination ray tracer later on, and I just noticed why it is giving incorrect results. The above is still correct, yet he already had my suggested fix implemented.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When looking at his code, there is one thing that he forgot to do a few times, and that was to normalize $w_{i}$ before using it in the dot product. The dot operator only gives the cosine of the angle between the two vectors, when both vectors have a length of 1 (a.k.a. they are normalized). Jeroen forgot to do this and $w_{i}$ had a longer length than 1. Below is the code of his direct illumination ray tracer's shade function where I added some comments to make it easier to understand.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shade(Shading shading) {&#xA;    RGBSpectrum colour = shading.getColour();&#xA;    double L = 0;&#xA;    final Point intersection = shading.getIntersectionPoint().toPoint(shading.getRay());&#xA;&#xA;    for (Light light : shading.getScene().getLights()) {&#xA;        double l = 0;&#xA;&#xA;        for (Point sample : light.computeSamples()) {&#xA;            Vector wi = sample.subtract(intersection);&#xA;            // In the line below, you calculate the cosine, &#xA;            // yet wi is not normalized. Later on you use wi again &#xA;            // to calculate a cosine and still forgot to normalize it. &#xA;            // Since you use the lengthSquared() of wi also, &#xA;            // I recommend to save that to a variable here, &#xA;            // and then you normalize wi. This way you only need to add &#xA;            // the following two lines (that I commented out)&#xA;            //&#xA;            // double lengthSquared = wi.lengthSquared();&#xA;            // wi = wi.normalize();&#xA;            double cos = shading.getIntersectionPoint().getNormal().dot(wi);&#xA;&#xA;            if (cos &amp;gt; 0) {&#xA;                Ray shadowRay = new Ray(intersection, wi);&#xA;&#xA;                if (!light.inShadow(shadowRay, shading.getScene())) {&#xA;                    if (light instanceof PointLight) {&#xA;                        double denom = 4 * Math.PI * wi.lengthSquared();&#xA;                        l += light.getPower() * cos / denom;&#xA;                    } else if (light instanceof RectangularLight) {&#xA;                        Rectangle rectangle = ((RectangularLight) light).getRectangle();&#xA;                        double cosp = -wi.dot(rectangle.getNormal());&#xA;                        l += light.getPower() * cos * cosp / (wi.lengthSquared() * rectangle.getArea());&#xA;                    }&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        L += l / light.getSamplesNumber();&#xA;    }&#xA;&#xA;    return colour.scale(getAmbientReflection() + L * getDiffuseReflection());&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="4908" LastEditDate="2018-08-15T19:12:51.530" LastActivityDate="2018-08-15T19:12:51.530" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7924" PostTypeId="1" AcceptedAnswerId="7925" CreationDate="2018-08-15T23:52:46.633" Score="1" ViewCount="131" Body="&lt;p&gt;I'm working on a game with a programmable robot. It uses a laser range finder to get the distance to walls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using DDA to generate a line from the robot, going in the direction it is pointing, then checking each pixel along the line to see if it hits anything. At that point, the number of pixels checked so far is used as the range, to save having to calculate the proper length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the line is horizontal or vertical, then there's no discrepancy, but how greatly does the number of pixels in a line differ from its real length in the worst case?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Notes:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The length of the line is never just a few pixels, say always at least 50px.&lt;/li&gt;&#xA;&lt;li&gt;Longer lines obviously have larger discrepancies, but the question is really about relative differences.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9196" LastEditorUserId="9196" LastEditDate="2018-08-16T00:10:20.817" LastActivityDate="2018-08-16T00:24:18.400" Title="How different can the number of pixels in a straight line be to its real length?" Tags="&lt;mathematics&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7925" PostTypeId="2" ParentId="7924" CreationDate="2018-08-16T00:24:18.400" Score="2" Body="&lt;p&gt;The worst case is when the line is at a 45-degree angle; then its length (in pixel-sized units) is a factor of $\sqrt{2}$ times the number of pixels, or about 40% longer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see this if you imagine starting with a vertical line of say 50px, then gradually sliding the endpoint away horizontally. Note that the number of pixels drawn doesn't change! You still have exactly one pixel turned on in each row that the line crosses. The pixels will adjust their horizontal positions but no new pixels will turn on, until the line surpasses 45 degrees from the vertical. The same is true if you start with a horizontal line and slide the endpoint vertically.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The number of pixels in the line effectively only looks at the vertical or horizontal distance, whichever is larger, and ignores the smaller dimension.&#xA;Mathematically, the number of pixels is $\max(|\Delta x|, |\Delta y|)$ while the Euclidean distance is $\sqrt{\Delta x^2 + \Delta y^2}$.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-08-16T00:24:18.400" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7928" PostTypeId="2" ParentId="2355" CreationDate="2018-08-16T10:39:15.173" Score="1" Body="&lt;p&gt;I don't have an exact answer for this, as the answer is far from trivial. I would suggest that you have a look into computational geometry as this clearly is a visibility problem - my guess is that a solution already exist. My own idea would be: for each line segment in polygon find the visible parts of the other line segments and then pick the pair of points that are furthest apart. Inspirational link: &lt;a href=&quot;https://en.wikipedia.org/wiki/Visibility_polygon&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia on 'visibility polygon'&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-08-16T10:39:15.173" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7929" PostTypeId="1" AcceptedAnswerId="7930" CreationDate="2018-08-16T17:27:40.460" Score="3" ViewCount="2314" Body="&lt;p&gt;I am trying to implement a simple path tracer with next-event estimation in Java. The general idea is to trace a ray through the scene as usual (using a cosine distribution to determine the next random direction at every bounce), while also taking the direct illumination into account at every bounce. I think I have most pieces of the puzzle available, but I can't fit them together correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is how I shade matte objects: add the direct illumination to the radiance coming from a random ray (chosen according to a cosine distribution), the latter multiplied by the BRDF.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shadePath(Shading shading, HybridPathTracer tracer, int length) {&#xA;    cosinusSampler sampler = new cosinusSampler(1);&#xA;    Point sample = sampler.computeSample();&#xA;&#xA;    Vector w = shading.getIntersectionPoint().getNormal();&#xA;    Random PRNG = new Random();&#xA;    Vector r = new Vector(PRNG.nextDouble(), PRNG.nextDouble(), PRNG.nextDouble()).normalize();&#xA;    Vector v = r.cross(w);&#xA;    Vector u = v.cross(w);&#xA;    Vector wi = u.scale(sample.x).add(v.scale(sample.y)).add(w.scale(sample.z));&#xA;    Ray ray = new Ray(shading.getIntersectionPoint().toPoint(shading.getRay()), wi);&#xA;    RGBSpectrum reflection = tracer.trace(ray, length + 1);&#xA;    RGBSpectrum brdf = shading.getColour().scale(getDiffuseReflection());&#xA;    return shade(shading).add(brdf.multiply(reflection));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When a ray reaches an emissive material, black is returned, unless the path length is equal to 1:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shadePath(Shading shading, HybridPathTracer tracer, int length) {&#xA;    Ray ray = shading.getRay();&#xA;    Vector n = shading.getIntersectionPoint().getNormal();&#xA;&#xA;    if (length == 1 &amp;amp;&amp;amp; n.dot(ray.direction) &amp;lt; 0) {&#xA;        return getTexture().getColour();&#xA;    } else {&#xA;        return RGBSpectrum.BLACK;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I read &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5153/9170&quot;&gt;Progressive Path Tracing with Explicit Light Sampling | Computer Graphics&lt;/a&gt; and thought that I was using the same idea in my code, but I must be doing something wrong, because my images are getting too bright when the maximal path length increases (see the examples for maximal length 2, 4 and 6 underneath). What is the problem?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yXEMz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yXEMz.png&quot; alt=&quot;Maximal length 2&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/iodfO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iodfO.png&quot; alt=&quot;Maximal length 4&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3qgye.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3qgye.png&quot; alt=&quot;Maximal length 6&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I know I should also consider some edge cases for specular surfaces, but maybe it's better to ignore those first and focus on matte objects. (I think I have prepared my code for specular surfaces anyway.) My shade function for direct illumination of matte objects should be fine, but here it is for reference:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public RGBSpectrum shade(Shading shading) {&#xA;    RGBSpectrum colour = shading.getColour();&#xA;    double L = 0;&#xA;    final Point intersection = shading.getIntersectionPoint().toPoint(shading.getRay());&#xA;&#xA;    for (Light light : shading.getScene().getLights()) {&#xA;        double l = 0;&#xA;&#xA;        for (Point sample : light.computeSamples()) {&#xA;            Vector wi = sample.subtract(intersection);&#xA;            double lengthSquared = wi.lengthSquared();&#xA;            wi = wi.normalize();&#xA;            double cos = shading.getIntersectionPoint().getNormal().dot(wi);&#xA;&#xA;            if (cos &amp;gt; 0) {&#xA;                Ray shadowRay = new Ray(intersection, wi);&#xA;&#xA;                if (!light.inShadow(shadowRay, shading.getScene())) {&#xA;                    if (light instanceof PointLight) {&#xA;                        double denom = 4 * Math.PI * lengthSquared;&#xA;                        l += light.getPower() * cos / denom;&#xA;                    } else if (light instanceof RectangularLight) {&#xA;                        Rectangle rectangle = ((RectangularLight) light).getRectangle();&#xA;                        double cosp = -wi.dot(rectangle.getNormal());&#xA;                        l += light.getPower() * cos * cosp * rectangle.getArea() / lengthSquared;&#xA;                    }&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        L += l / light.getSamplesNumber();&#xA;    }&#xA;&#xA;    return colour.scale(getAmbientReflection() + L * getDiffuseReflection());&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9170" LastEditorDisplayName="user7220" LastEditDate="2018-08-18T20:07:36.433" LastActivityDate="2018-08-18T20:07:36.433" Title="How does a path tracer with next-event estimation work?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7930" PostTypeId="2" ParentId="7929" CreationDate="2018-08-16T19:42:25.493" Score="3" Body="&lt;p&gt;I noticed three potential problems. First, this bit of code looks suspicious:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector r = new Vector(PRNG.nextDouble(), PRNG.nextDouble(), PRNG.nextDouble()).normalize();&#xA;Vector v = r.cross(w);&#xA;Vector u = v.cross(w);&#xA;Vector wi = u.scale(sample.x).add(v.scale(sample.y)).add(w.scale(sample.z));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The vectors &lt;code&gt;v&lt;/code&gt; and &lt;code&gt;u&lt;/code&gt; are not normalized, so the construction of &lt;code&gt;wi&lt;/code&gt; will be distorted. (Also, using a random vector &lt;code&gt;r&lt;/code&gt; to construct the basis is really more work than necessary; you might take a look at &lt;a href=&quot;http://jcgt.org/published/0006/01/01/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; for a faster way of doing that.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, you have a &lt;code&gt;getAmbientReflection()&lt;/code&gt; in your direct lighting code—that should not be there for path tracing, where &quot;ambient&quot; light is properly calculated by the recursive trace.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, I think the result of your direct illumination path ought to be scaled by $1/π$. This is because the Lambert BRDF is equal to $c_d/π$ where $c_d$ is the diffuse color. The direct illumination path needs to evaluate the full BRDF, including that $1/π$ factor, using the irradiance sample coming in from the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the cosine-weighted recursive trace does &lt;em&gt;not&lt;/em&gt; need a $1/π$, as it is cancelled out by the cosine PDF. That one should just use $c_d$, like you have it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can check that the $1/π$ factors are correct by checking that the average brightness is equal with and without next-event estimation (keeping the path length the same).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW, note that the image getting somewhat brighter as you increase the path length is to be expected, as longer paths = more bounces = more illumination. (Russian-roulette path termination fixes this.) Longer paths will also give stronger global illumination / &quot;color-bleeding&quot; effects. That seems to be what's happening in your images—look at the color of the shadow under the sphere; it gets progressively more influenced by the color of the walls and sphere as you increase the path length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this is undesirable, try reducing the diffuse reflection factors of all the materials in the scene; they might be unrealistically high, and cutting them down will reduce the bounce light and color-bleeding.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-08-16T19:42:25.493" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7931" PostTypeId="2" ParentId="5996" CreationDate="2018-08-17T08:22:36.720" Score="0" Body="&lt;p&gt;You cannot use Clipper and expect analytical results. Circle arcs will be composed by line segments. That said, you know your boolean operands so it should be possible and fairly easy to map all line segments back to their origin operand and extract the arcs yourself.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-08-17T08:22:36.720" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7932" PostTypeId="1" CreationDate="2018-08-17T09:14:43.320" Score="0" ViewCount="482" Body="&lt;p&gt;I have a scenario where I need rotate a vector ( unit vector) at a point in space by an angle along Z-axis. Is it possible to help me to understand a procedure to achieve this. I'm using vb.net programming to do this programattically. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the schematics for your understanding:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HvCwq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HvCwq.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9207" LastActivityDate="2018-10-14T18:31:15.790" Title="Rotation of a random unit vector at a point in 3D space by an angle" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;&lt;matrix&gt;&lt;vectors&gt;" AnswerCount="3" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="7933" PostTypeId="1" AcceptedAnswerId="7934" CreationDate="2018-08-17T10:58:45.520" Score="2" ViewCount="210" Body="&lt;p&gt;Suppose my path tracer is shooting 64 rays per pixel (in an 8x8 grid). The confusion is, when accounting for Global illumination, should I shoot additional &lt;code&gt;X&lt;/code&gt; number of random rays for each of those initial 64 rays? This would equal to shooting &lt;code&gt;64 * X *number of bounces&lt;/code&gt; rays (all sorts of) which is really large. And since I am making the path tracer on GPU memory is surely a concern.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OR I just shoot 1 random ray for indirect illumination. This would mean that the total secondary rays cast for GI would equal 64 per pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The problem here is, all those 64 rays cast per pixel aren't guaranteed to intersect at the same point albeit close enough. If the intersection positions aren't the same then this would mean I am calculating indirect illumination using just 1 sample which is ofcourse very low.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now this is again for just GI. What about Area light sources? Should I be explicitly sampling X number of rays for Area Light for each of those initial 64 rays? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think this is what Cook mentioned in his paper on &lt;strong&gt;Distributed Ray Tracing&lt;/strong&gt;. He says&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Rather than adding more rays for each dimension, the existing rays are&#xA;  distributed in each dimension according to the values of the&#xA;  corresponding parameter. The key is that no extra rays are needed beyond&#xA;  those used for oversampling.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I am confused because mostly I have seen algorithms and code snippets following the second approach. Casting X number of rays for GI.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; Secondly for direct illumination is the light path explicitly calculated or it's taken from the samples created for GI? The former means if I am sampling 1 ray for GI for each of the 64 rays per pixel, then I am also shooting another ray explicitly for the light path. The random sampled ray, if points to the light source I ignore it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The latter means, I sample only 1 ray, if it doesn't hits the light source that's my GI, and if it hits the light source I accumulate it's color as direct lighting.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-08-20T06:19:07.423" Title="Path Tracer - sampling dimensions confusion" Tags="&lt;pathtracing&gt;&lt;sampling&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7934" PostTypeId="2" ParentId="7933" CreationDate="2018-08-17T11:56:43.567" Score="3" Body="&lt;p&gt;Only one path per sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you had 64 bounces per first hit and 64 per second hit and so forth you'd never get an image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: And that's why you need to sample each pixel so many times (easily more than 1024 samples) in order to get it to converge, ie get rid of the noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As per 2) (from comment below) The 64 primary rays will not hit the same object in the same spot so you will have to calculate everything for each sample.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastEditorUserId="9194" LastEditDate="2018-08-20T06:19:07.423" LastActivityDate="2018-08-20T06:19:07.423" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7936" PostTypeId="1" AcceptedAnswerId="7956" CreationDate="2018-08-18T16:42:57.203" Score="1" ViewCount="293" Body="&lt;p&gt;Kevin Beason's &lt;a href=&quot;http://www.kevinbeason.com/smallpt/&quot; rel=&quot;nofollow noreferrer&quot;&gt;smallpt&lt;/a&gt; estimates the pixel radiance by accumulating $2\times2$ subpixel radiance estimates using the following expression:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;c[i] = c[i] + Vec(clamp(r.x),clamp(r.y),clamp(r.z))*.25;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here, &lt;code&gt;c[i]&lt;/code&gt; represents the radiance estimate of the pixel with flattened index &lt;code&gt;i&lt;/code&gt;, &lt;code&gt;r&lt;/code&gt; represents the radiance estimate of one of its four subpixels. As one notices a &lt;code&gt;clamp&lt;/code&gt; operation is used to clamp the radiance estimate of each subpixel &lt;strong&gt;separately&lt;/strong&gt; to the $[0,1]^3$ range &lt;strong&gt;before&lt;/strong&gt; accumulation. But this seems wrong from an unbiased path tracing perspective, since this effectively introduces bias to the radiance estimate of each pixel. So I wonder if I am missing something (e.g., clever trick at the cost of bias), given that Kevin Beason's smallpt is already around and known for nearly ten years?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apparently, Kevin Beason also added a &lt;a href=&quot;https://drive.google.com/file/d/0B8g97JkuSSBwUENiWTJXeGtTOHFmSm51UC01YWtCZw/view&quot; rel=&quot;nofollow noreferrer&quot;&gt;presentation&lt;/a&gt; by David Cline explaining every line. The aforementioned expression is explained as follows:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Add the gamma-corrected subpixel color estimate to the Pixel color&#xA;  &lt;code&gt;c[i]&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This seems, however, completely unrelated since no gamma correction is involved yet at this stage in the code. And since exponential functions are non-linear transformations. (Obviously &lt;code&gt;clamp&lt;/code&gt; does not involve any exponential functions at all. ;-) )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Reference code&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int y=0; y&amp;lt;h; y++){                       // Loop over image rows &#xA;    fprintf(stderr,&quot;\rRendering (%d spp) %5.2f%%&quot;,samps*4,100.*y/(h-1)); &#xA;    for (unsigned short x=0, Xi[3]={0,0,y*y*y}; x&amp;lt;w; x++)   // Loop cols &#xA;        for (int sy=0, i=(h-y-1)*w+x; sy&amp;lt;2; sy++)     // 2x2 subpixel rows &#xA;            for (int sx=0; sx&amp;lt;2; sx++, r=Vec()){        // 2x2 subpixel cols &#xA;                for (int s=0; s&amp;lt;samps; s++){ &#xA;                    double r1=2*erand48(Xi), dx=r1&amp;lt;1 ? sqrt(r1)-1: 1-sqrt(2-r1); &#xA;                    double r2=2*erand48(Xi), dy=r2&amp;lt;1 ? sqrt(r2)-1: 1-sqrt(2-r2); &#xA;                    Vec d = cx*( ( (sx+.5 + dx)/2 + x)/w - .5) + &#xA;                            cy*( ( (sy+.5 + dy)/2 + y)/h - .5) + cam.d; &#xA;                    r = r + radiance(Ray(cam.o+d*140,d.norm()),0,Xi)*(1./samps); &#xA;                } // Camera rays are pushed ^^^^^ forward to start in interior &#xA;                c[i] = c[i] + Vec(clamp(r.x),clamp(r.y),clamp(r.z))*.25; &#xA;            } &#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2018-08-18T16:51:31.573" LastActivityDate="2018-08-23T18:04:10.240" Title="smallpt's early clamping" Tags="&lt;pathtracing&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7937" PostTypeId="2" ParentId="5823" CreationDate="2018-08-18T18:25:09.500" Score="5" Body="&lt;h1&gt;Illumination components&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;If our scenes only contain point lights (e.g., omni lights, spotlights, etc.) and emissive surfaces, the illumination contributions at a surface position, $x$, are computed as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The self emission associated with the emissive surface (i.e. 0 bounces/surface interactions) is computed as usual without using the scene's voxelization (as is the case for adding this illumination contribution to the scene's voxelization);&lt;/li&gt;&#xA;&lt;li&gt;The direct illumination associated with the point lights (i.e. 1 bounce/surface interaction) is computed as usual without using the scene's voxelization (as is the case for adding this illumination contribution to the scene's voxelization);&lt;/li&gt;&#xA;&lt;li&gt;The direct illumination associated with the emissive surfaces (i.e. 1 bounce/surface interaction) is obtained from the scene's voxelization using voxel cone tracing;&lt;/li&gt;&#xA;&lt;li&gt;The indirect illumination associated with the point lights (i.e. 2 bounces/surface interactions) is obtained from the scene's voxelization using voxel cone tracing.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;By computing the diffuse illumination for all the voxels from the scene's voxelization using voxel cone tracing, the diffuse illumination from additional bounces/surface interactions can be (optionally) accumulated inside the voxels. This requires each voxel to store (an approximation) to the normal distribution of the scene's surfaces overlapping those voxels as well.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Illumination from the scene's voxelization (3)-(4)&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The outgoing radiance obtained from the scene's voxelization ($L_v$):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o\!\left(x, \hat\omega_o\right) = \int_\Omega f_{r}\!\left(x, \hat\omega_o, \hat\omega_i\right) L_v\!\left(x, \hat\omega_i\right) \left(\hat{n} \cdot \hat\omega_i\right) \mathrm{d}\hat\omega_i.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a &lt;strong&gt;diffuse BRDF&lt;/strong&gt; $f_{r}\!\left(x, \hat\omega_o, \hat\omega_i\right) = \frac{k_d}{\pi}$:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o\!\left(x, \hat\omega_o\right) = \frac{k_d}{\pi} \int_\Omega L_v\!\left(x, \hat\omega_i\right) \left(\hat{n} \cdot \hat\omega_i\right) \mathrm{d}\hat\omega_i.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a partitioning of $\Omega$ in $N$ disjunct subdomains, $\Omega_j$, (e.g., $\approx$ cones) (i.e. $\Omega_1 \cup~...~\cup \Omega_N = \Omega$ and $\Omega_i \cap \Omega_j = \emptyset$ for each $i \ne j$):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o\!\left(x, \hat\omega_o\right) = \frac{k_d}{\pi} \sum_{j = 1}^{N} \int_{\Omega_{j}}  L_v\!\left(x, \hat\omega_{j,i}\right) \left(\hat{n} \cdot \hat\omega_{j,i}\right) \mathrm{d}\hat\omega_{j,i}.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Relying on a single cone with a direction, $\hat\omega_{j}$, and an aperture, $\alpha_{j}$, instead of individual rays with a direction, $\hat\omega_{j,i}$, for each subdomain, $\Omega_j$: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o\!\left(x, \hat\omega_o\right) \approx \frac{k_d}{\pi} \sum_{j = 1}^{N} L_v\!\left(x, \hat\omega_{j}, \alpha_{j}\right) \int_{\Omega_{j}} \left(\hat{n} \cdot \hat\omega_{j,i}\right) \mathrm{d}\hat\omega_{j,i}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\hat{W}_j = \frac{1}{\pi} \int_{\Omega_{j}} \left(\hat{n} \cdot \hat\omega_{j,i}\right) \mathrm{d}\hat\omega_{j,i}$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$L_o\!\left(x, \hat\omega_o\right) \approx k_d \sum_{j = 1}^{N} \hat{W}_j L_v\!\left(x, \hat\omega_{j}, \alpha_{j}\right).$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can use for example the following six cones, each with an aperture of $\frac{\pi}{6}$.&lt;/p&gt;&#xA;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/TbALB.png&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The normalized weight of the blue cone about the surface normal is equal to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\hat{W}_{\mathrm{blue}} = \frac{1}{\pi} \int_{0}^{2\pi} \int_{0}^{\frac{\pi}{6}} \cos\!\theta \sin\!\theta \, \mathrm{d}\theta \, \mathrm{d}\phi = \frac{1}{4}.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The normalized weight of the other cones is approximately equal to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$\hat{W}_{\mathrm{purple|red|green|orange|brown}} \approx \frac{1-\hat{W}_{\mathrm{blue}}}{5} = \frac{3}{20}.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a &lt;strong&gt;specular BRDF&lt;/strong&gt;, one typically uses a single cone with a direction, $2 \left(\hat{n} \cdot \hat\omega_o\right) \hat{n}-\hat\omega_o$ (i.e. reflected direction of $\hat\omega_o$ about $\hat{n}$), and an aperture based on the roughness of the surface material.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Voxel Cone Tracing&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;$L_v\!\left(x, \hat\omega_{j}, \alpha_{j}\right)$ is computed using voxel cone tracing, which can be implemented by marching the mip-mapped 3D voxel texture in UVW texture space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Our accumulated radiance (red, green, blue channels) and opacity (alpha channel) are initialized to zero. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Lv ← [0, 0, 0, 0]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Our cone marching distance is initialized to an offset to avoid sampling the self emission associated with the emissive surfaces and the direct illumination associated with the point lights twice. We need to basically skip the voxel containing the surface position for which the outgoing radiance needs to be estimated.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;distance ← voxel_offset&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Marching continues until we reach an accumulated opacity of 1 or more:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;while Lv.alpha &amp;lt; 1:&#xA;    compute diameter (i.e. cone voxel footprint)&#xA;    compute mip_level&#xA;    compute position at distance&#xA;    if mip_level &amp;gt;= max_mip_level or position ∉ [0,1]^3&#xA;        break&#xA;    sample Lv_step(position, mip_level)&#xA;    Lv ← Lv + (1-Lv.alpha) * Lv_step // blend equation&#xA;    distance ← distance + cone_step  // marching -&amp;gt; diameter and mip_level will increase&#xA;return Lv&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/dGx7V.png&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2018-08-19T11:33:26.277" LastActivityDate="2018-08-19T11:33:26.277" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7938" PostTypeId="2" ParentId="7936" CreationDate="2018-08-18T22:51:50.560" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;This seems, however, completely unrelated since no gamma correction is involved yet at this stage in the code.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The values are indeed not gamma corrected. Earlier in the presentation (On page 32) you have the toInt function which does the gamma correction. This function is called when the image is written to a file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the clamping itself.&#xA;If we have a list of 5 samples.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.1; 0.4; 0.2; 0.8; 0.6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It averages to 0.42. However, if one samples becomes very bright.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.1; 0.4; 8.0; 0.8; 0.6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The average would become 1.98. That is a lot brighter. Because we take random samples, it could be that these two averages are neighboring pixels. This would cause a few pixels in the entire image to be much brighter than their neighbors. This is called a &lt;strong&gt;firefly&lt;/strong&gt;. These fireflies are often not wanted, as they stick out in the image and make it look a lot more noisy. Therefore we want to try and remove these fireflies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example image of this can be found in &lt;a href=&quot;https://docs.blender.org/manual/en/dev/render/cycles/optimizations/reducing_noise.html#clamp-fireflies&quot; rel=&quot;nofollow noreferrer&quot;&gt;blender's cycles documentation here&lt;/a&gt;. The bright pixels are fireflies and are unwanted.&lt;a href=&quot;https://i.stack.imgur.com/DKQnc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DKQnc.jpg&quot; alt=&quot;Image with fireflies&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are three ways to remove a firefly.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Add more samples. By adding more samples, you get a truer image and that one bright sample would end up with less influence. This does however take longer to render.&lt;/li&gt;&#xA;&lt;li&gt;Some sort of denoising algorithm. The algorithm could find these fireflies and remove them. However, it will almost always change other parts of the image which is often unwanted, and there is also no room for it in smallpt.&lt;/li&gt;&#xA;&lt;li&gt;Discarding the bright sample or similar. This bright sample is the culprit of the problem and we could always decide to just ignore it. However, that bright sample is there for a reason and removing it would most of the times not be the greatest idea (it also makes things more complicated). Clamping however would still allow us to somewhat discard the bright sample without actually discarding it and is very simple and easy to implement. We just make it not have such a big influence on the image.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Clamping is often the choice for most render engines. If you would look at any commercial render engine, or even hobby path tracers, they allow you to clamp the samples. Normally you clamp the individual samples instead of the sub-pixels and more specifically you clamp indirect samples with its own clamping value, but they have about the same effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This clamping does change the image as it makes some areas or all darker since it removes energy (by clamping the color values) from the scene. This would become unbiased, yet it is often done (and almost always available in unbiased render engines) simply because it produces visually nicer images, because there are no fireflies and fireflies are generally worse than noise. Often you would not notice any artifacts when clamping, other than the removed fireflies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the case of smallpt, clamping it between 0.0 and 1.0 seems to work well for that one scene. However, I do recommend to just tinker with the code and render two images out for yourself, one with clamping and one without.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="2287" LastEditDate="2018-08-19T16:32:11.233" LastActivityDate="2018-08-19T16:32:11.233" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7940" PostTypeId="1" CreationDate="2018-08-19T21:47:37.213" Score="2" ViewCount="48" Body="&lt;p&gt;I have used a library to perform a Constructive Solid Geometry difference operation, which has left me with orphaned geometry as well as imperfections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an approach/algorithm that will allow me clean the geometry so all that remains is the two cuboids?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dWM1b.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dWM1b.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9218" LastActivityDate="2018-08-22T09:06:54.760" Title="Remove orphaned geometry after Constructive Solid Geometry operation" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7942" PostTypeId="2" ParentId="5287" CreationDate="2018-08-20T06:43:40.957" Score="1" Body="&lt;p&gt;Iridesence can be seen in several variations: diffraction as seen in CDs and DVDs (see Stam's SIGGRAPH 1999 paper on this), phase shifting and modulation in multi-layered surfaces as you see in oilspills on water, or structural coloration as you see in butterfly wings. (Also there is the related pearlescence). However, it's not trivial in any way, probably worth a paper or two.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-08-20T06:43:40.957" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7943" PostTypeId="1" AcceptedAnswerId="7944" CreationDate="2018-08-21T10:24:21.260" Score="4" ViewCount="597" Body="&lt;p&gt;So I was reading up on how to sample Rectangular Area lights, and the procedure is pretty straightforward. That is, I can get random points using the equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ p = X_o + \epsilon_1V_1 + \epsilon_2V_2$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$X_o$&lt;/span&gt; is my corner point for the rectangle and &lt;span class=&quot;math-container&quot;&gt;$V_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$V_2$&lt;/span&gt; are the 2 vectors spanning it And the epsilons are the uniform random numbers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing is almost every where I go, they talk about how the PDF of this sampling is &lt;span class=&quot;math-container&quot;&gt;$1/A$&lt;/span&gt; (constant) with the exception of 1 place discussed below, and that when calculating the radiance coming from this area light when sampled by this way we should thus multiply the whole thing by the Area of the rectangle. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However when I check their algorithms, they leave out this Area factor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Compute Graphics Principles and Practice&lt;/strong&gt; and &lt;strong&gt;Fundamental of Computer Graphics by Peter Shirley&lt;/strong&gt; describes the calculation of the radiance returned by sampling a point on the area light, (Notice the black underlined factor describing Area of the jth light source)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jEkzn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jEkzn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However both of these books when describing their pseudocode, leave out this &lt;span class=&quot;math-container&quot;&gt;$Area$&lt;/span&gt; factor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However when I read Peter Shirley's research paper regarding Direct illumination techniques, He gives the PDF for rectangular Area lights as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ 1/ \frac{||V_1 \times V_2||}{2}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is the area of the triangle not a rectangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So ultimately I have 2 questions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1) What is the correct PDF term for rectangular area lights?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2) Do I need to multiply this term when calculating the radiance emitted from this light source.&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-09-21T09:18:09.103" LastActivityDate="2018-11-20T10:00:36.427" Title="PDF when sampling from Rectangular Area Lights" Tags="&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7944" PostTypeId="2" ParentId="7943" CreationDate="2018-08-21T18:09:52.720" Score="1" Body="&lt;p&gt;The correct PDF for an area light is indeed $1/A$. The reason why you see the area term at the top is because you are importance sampling the light, meaning you need to divide by its PDF. This is a Monte Carlo estimator with one sample. Shirley simplifies this by simply writing $1/(1/A) = A$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not sure how he got the $1 / \frac{\|V_1 \times V_2\|}{2}$.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastActivityDate="2018-08-21T18:09:52.720" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7945" PostTypeId="1" AcceptedAnswerId="7947" CreationDate="2018-08-21T20:19:36.113" Score="3" ViewCount="897" Body="&lt;p&gt;I want to calculate the average color+opacity of an image. First I thought about just averaging all ARGB values component-wise, but this got really dark on images with a lot of transparency. I also don't think mixing RGB colors is a good idea in general since they are nonlinear due to Gamma or something. I also had a look at HSV/HSB but this seems a pretty stupid idea.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;So, what is a reasonably physically correct way to average the color of an ARGB image?&lt;/strong&gt; I prefer solutions in Java and using 8 bit per color channel. The solution should also take care that the image may have an arbitrary amount of transparent or semi-transparent pixels.&lt;/p&gt;&#xA;" OwnerUserId="6092" LastActivityDate="2018-08-22T16:02:19.990" Title="Calculate the average color of an image" Tags="&lt;image-processing&gt;&lt;color&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7946" PostTypeId="1" AcceptedAnswerId="7957" CreationDate="2018-08-21T21:09:06.010" Score="1" ViewCount="135" Body="&lt;p&gt;I’ve been trying to render a texture on the whole screen in OpenGL 4.1 using the Core profile and followed a few tutorials on the matter, but all I have so far is a blank screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried using my texture coordinates as color components and got the result I expected so the vertice data must be in order, but using the dimensions of the texture as color components I determined the size of the texture in my shader is 1x1 when it should be 2x2, so I guess I am doing something wrong when uploading it to the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my pixel data:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const GLubyte pixels[] = {&#xA;    255, 255, 255, 255,     0, 0, 0, 255,&#xA;    0, 0, 0, 255,           255, 255, 255, 255,&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is how I load my texture:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;texture);&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D, texture);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)pixels);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I also tried using a buffer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;texture);&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D, texture);&#xA;glGenBuffers(1, &amp;amp;texture_buffer);&#xA;glBindBuffer(GL_PIXEL_UNPACK_BUFFER, texture_buffer);&#xA;glBufferData(GL_PIXEL_UNPACK_BUFFER, sizeof(pixels), pixels, GL_STATIC_DRAW);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this is how I render:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glUseProgram(shader_program);&#xA;// Binding my vba and vbo, uploading vertices.&#xA;glUniform1i(texture_location, 0);&#xA;// Enabling vertex attrib arrays.&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D, texture);&#xA;// Drawing arrays, disabling vertex attrib arrays.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have also put the whole source file &lt;a href=&quot;https://pastebin.com/gmN50u50&quot; rel=&quot;nofollow noreferrer&quot;&gt;on pastebin&lt;/a&gt;, it uses GLFW for windowing and does some basic error checking.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I’d be really grateful if someone could point out what I am missing here.&lt;/p&gt;&#xA;" OwnerUserId="9216" LastEditorUserId="6" LastEditDate="2018-08-24T11:06:39.100" LastActivityDate="2018-08-24T11:06:39.100" Title="Issue with loading a texture on the GPU with OpenGL 4.1 Core profile" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7947" PostTypeId="2" ParentId="7945" CreationDate="2018-08-22T02:20:40.710" Score="4" Body="&lt;p&gt;Averaging RGB should be correct assuming you do it in linear RGB. If your images are in sRGB, you can remove the gamma correction by doing something like the following for each of the R, G, and B components:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sRGBToLinear(UInt8 component)&#xA;{&#xA;    float tempComponent = (float)component / 255.0;&#xA;    if (tempComponent &amp;lt;= 0.04045)&#xA;    {&#xA;        tempComponent = tempComponent / 12.92;&#xA;    }&#xA;    else&#xA;    {&#xA;        tempComponent = pow((tempComponent + 0.055) / (1.055), 2.4);&#xA;    }&#xA;    return tempComponent;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can then average together all of the red values in the image, all of the green values in the image, and all of the blue values in the image after they've been run through the above conversion. You can then do the opposite conversion to get back to sRGB:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;UInt8 linearRGBTosRGB(float component)&#xA;{&#xA;    float tempComponent =  0.0;&#xA;    if (component &amp;lt;= 0.00318308)&#xA;    {&#xA;        tempComponent = 12.92 * component;&#xA;    }&#xA;    else&#xA;    {&#xA;        tempComponent = 1.055 * pow(component, 1.0 / 2.4) - 0.055;&#xA;    }&#xA;    return (UInt8)(tempComponent * 255.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(My apologies if I've messed up the syntax. I'm a C/C++ programmer and don't know the intricacies of Java.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that alpha makes things slightly more complicated. If you're using premultiplied alpha, you can simply apply the above calculations for the average. If you're using straight alpha, you'll want to multiply each of the R, G, and B components by the alpha before doing the averaging.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2018-08-22T16:02:19.990" LastActivityDate="2018-08-22T16:02:19.990" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7948" PostTypeId="2" ParentId="7945" CreationDate="2018-08-22T08:05:29.910" Score="1" Body="&lt;p&gt;Sounds like you could be using the sum of all pixels disregarding the transparency for each pixel, and that the image has black pixels where it is transparent which leads to the issue. Instead add the pixels with their alpha value as weight, and divide the result with the total weight. Premultiplied alpha you should handle also as suggested above.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-08-22T08:05:29.910" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7949" PostTypeId="2" ParentId="7940" CreationDate="2018-08-22T09:06:54.760" Score="1" Body="&lt;p&gt;I've not done CSG per se, but I did work on a, not-unrelated, problem of triangulation of arbitrary, self-intersecting, multi-contoured polygons. If you don't get the implicit intersections correct, all sorts of nasty artefacts can result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Initially, I tried using standard, floating-point maths to compute intersections etc, but this is fraught with precision problems and no amount of trickery of ordering etc eliminated these accuracy issues.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end, I replaced all intersection calculations with rational maths (high precision integer numerator and denominators) with sufficient precision that all intersections would be represented &lt;em&gt;exactly&lt;/em&gt;. Once the process was completed, then these high precision results could be reduced to back to floating point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perhaps a quick way to start would be to use a package such as &lt;a href=&quot;https://gmplib.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;GNU's GMP&lt;/a&gt; which supports arbitrary rational representations.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2018-08-22T09:06:54.760" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7950" PostTypeId="1" AcceptedAnswerId="7951" CreationDate="2018-08-22T09:18:30.670" Score="1" ViewCount="456" Body="&lt;p&gt;Using The DSA Ext with opengl , API calls to guide opengl to the buffer format are :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glVertexArrayAttribFormat(  GLuint vaobj,&#xA;GLuint attribindex,&#xA;GLint size,&#xA;GLenum type,&#xA;GLboolean normalized,&#xA;GLuint relativeoffset);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and another one is :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glVertexArrayVertexBuffer(  GLuint vaobj,&#xA;GLuint bindingindex,&#xA;GLuint buffer,&#xA;GLintptr offset,&#xA;GLsizei stride);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;my question is what's the difference between relativeOffset and the offset in both function calls ? when i set one the results are ok but when you set both your layout will be incorrected and thus the results are wrong.&lt;/p&gt;&#xA;" OwnerUserId="2430" LastActivityDate="2018-08-22T11:02:14.317" Title="Difference between relativeOffset and offset in VAO with Direct Access Ext" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7951" PostTypeId="2" ParentId="7950" CreationDate="2018-08-22T11:02:14.317" Score="2" Body="&lt;p&gt;The offset in &lt;code&gt;glVertexArrayVertexBuffer&lt;/code&gt; is the common offset for all attributes bound to that buffer. It's where the vbo data starts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The offset in &lt;code&gt;glVertexArrayAttribFormat&lt;/code&gt; is added to that common offset for that attribute. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This allows you to interleave attributes using a single vbo binding point. and change the vbo binding for those attributes in a single call.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make an example: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex {&#xA;    vec3 pos;&#xA;    vec3 normal;&#xA;}&#xA;&#xA;glVertexAttribFormat(posAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, pos));&#xA;glVertexAttribBinding(posAttrLoc, vertexBindingPoint);&#xA;glEnableVertexAttribArray(posAttrLoc);&#xA;&#xA;glVertexAttribFormat(normalAttrLoc, 3, GL_FLOAT, false, offsetof(Vertex, normal));&#xA;glVertexAttribBinding(normalAttrLoc, vertexBindingPoint);&#xA;glEnableVertexAttribArray(normalAttrLoc);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;then to bind the buffer you pass the offset to where you put in where the data was uploaded to, this is 0 in the basic case.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexBuffer(vertexBindingPoint, mesh.vbo, mesh.vboOffset, sizeof(Vertex));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-08-22T11:02:14.317" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7952" PostTypeId="1" AcceptedAnswerId="7953" CreationDate="2018-08-22T12:14:54.933" Score="2" ViewCount="153" Body="&lt;p&gt;I hope I'm not off topic here, but this seemed like a good place to ask something like this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been hearing about SLI and Crossfire for a long time and how support for it is lacking.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I never could understand why were the developers ones that needed to support it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;GPUs are immensely parallel things. They have thousands of cores that run same code at the same time (generally speaking). The game will run with same code on a GPU with 100 cores and with 1000 cores, it will just scale itself differently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know what stopped the GPU companies from dealing with this within the drivers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why not have the driver detect two physical GPUs and present them to the system as a one logical GPU? It would then make sure that the workload is evenly distributed, while using the SLI bridge to synchronise and exchange the data across the GPUs as needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this was really that great as it looks to be, I'm sure they'd be doing it that way, but they aren't. My question is, why not, where does this idea fall apart?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Only reason I can think of is that the GPUs can't handle both the communication with the CPU and with each other fast enough to make the whole thing feasible, and in order to do so, architectural changes would be need which would not yield any improvements in single GPU systems, but only multi GPU system, which would be far, far rarer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What gives?&lt;/p&gt;&#xA;" OwnerUserId="5215" LastActivityDate="2018-08-22T14:47:29.330" Title="Why isn't multi-gpu handled by the driver?" Tags="&lt;gpu&gt;&lt;driver&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7953" PostTypeId="2" ParentId="7952" CreationDate="2018-08-22T14:47:29.330" Score="2" Body="&lt;h2&gt;Your assumption is wrong&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/43811699/opengl-multi-gpu-support&quot;&gt;It actually &lt;em&gt;was&lt;/em&gt; this way&lt;/a&gt;, in fact, things have changed &lt;em&gt;the other direction&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;h2&gt;History&lt;/h2&gt;&#xA;&lt;p&gt;Currently (&lt;a href=&quot;https://en.wikipedia.org/wiki/NVLink&quot; rel=&quot;nofollow noreferrer&quot;&gt;pre nvidia link consumer graphics&lt;/a&gt;) you've got to copy the memory over from separate GPUs to render in cross fire and SLI, as global memory transfer speeds will slow down scaling, and as far as I can tell it did not work as a general direct memory acessor, with only 2G/s bandwidth even with the &lt;a href=&quot;https://en.wikipedia.org/wiki/Scalable_Link_Interface&quot; rel=&quot;nofollow noreferrer&quot;&gt;HB version&lt;/a&gt;, it is only meant to be a framebuffer copier.   You otherwise had to send the same information across all GPUs via PCIE.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;SLI allows two, three, or four graphics processing units (GPUs) to share the workload when rendering real-time 3D computer graphics. Ideally, identical GPUs are installed on the motherboard that contains enough PCI-Express slots, set up in a master-slave configuration. &lt;em&gt;&lt;strong&gt;All graphics cards are given an equal workload to render, but the final output of each card is sent to the master card via a connector called the SLI Bridge&lt;/strong&gt;&lt;/em&gt;. For example, in a two graphics card setup, the master works on the top half of the scene, the slave the bottom half. Once the slave is done, it sends its render to the master to combine into one image before sending it to the monitor.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;(emphasis mine).&lt;/p&gt;&#xA;&lt;p&gt;But you didn't typically actually treat this set up as one GPU in the way &lt;em&gt;you&lt;/em&gt; want in old times because if you wanted to &lt;em&gt;cooporate&lt;/em&gt; work loads instead of merely &lt;em&gt;splitting workloads&lt;/em&gt; that required GPU-&amp;gt;GPU communication, which necessarily had to be done VIA pcie, which would be very slow.&lt;/p&gt;&#xA;&lt;p&gt;At least for opengl, SLI/Xfire rendering was handled via Driver treating the two as the same. &lt;a href=&quot;https://stackoverflow.com/a/43812678/2036035&quot;&gt;https://stackoverflow.com/a/43812678/2036035&lt;/a&gt; You didn't have the &lt;em&gt;option&lt;/em&gt; of treating them as separate if they were linked.&lt;/p&gt;&#xA;&lt;h2&gt;Modern&lt;/h2&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://arstechnica.com/gadgets/2018/03/vulkan-1-1-adds-multi-gpu-directx-compatibility-as-khronos-looks-to-the-future/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Today however&lt;/a&gt;, vulkan and DX12 essentially give &lt;strong&gt;more control&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;One feature in particular goes a long way toward filling a Vulkan gap relative to Microsoft's API: explicit multi-GPU support, which allows one program to spread its work across multiple GPUs. &lt;em&gt;&lt;strong&gt;Unlike SLI and Crossfire of old, where the task of divvying up the rendering between GPUs was largely handled by the driver&lt;/strong&gt;&lt;/em&gt;, this support gives control to the developer. With the addition, developers can create &amp;quot;device groups&amp;quot; that aggregate multiple physical GPUs into a single virtual device and choose how work is dispatched to the different physical GPUs. &lt;em&gt;&lt;strong&gt;Resources from one physical GPU can be used by another GPU, different commands can be run on the different GPUs, and one GPU can show rendered images that were created by another GPU&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;(emphasis mine)&lt;/p&gt;&#xA;&lt;p&gt;Today &lt;em&gt;you can&lt;/em&gt; look at these GPUs separately.&lt;/p&gt;&#xA;" OwnerUserId="6530" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-08-22T14:47:29.330" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7954" PostTypeId="1" AcceptedAnswerId="7971" CreationDate="2018-08-23T02:15:55.240" Score="0" ViewCount="241" Body="&lt;p&gt;I've been working on a new ray tracer recently, but after adding reflections I'm seeing these strange small highlights on my models, particularly on the ear of the silver rabbit below. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read that these can be caused by my reflection rays re-colliding with the object they're reflection from, but I believe I'm properly accounting for this by slightly translating the outgoing rays away from the intersect point. They also seem to consistently occur on the same parts of the model (the ears, and &quot;creases&quot;) regardless of the scene. I am taking 8 random samples per pixel, which seems to help a bit, but not entirely.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any thoughts on what could be causing this? is it possible that I'm simply not taking enough samples or structuring them well enough? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eirtt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eirtt.png&quot; alt=&quot;Rendering&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've added the code for my recursive coloring/reflectance function and my shadow function below, sorry if it's messy&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public Color getIntersectColor(Scene theScene, Vector3D theNormal, Vector3D theIntersectPoint, Vector3D theRay, int aDepth)&#xA;{&#xA;    // Initialize to ambient colors&#xA;    double aRed = myKa * myDiffuseColor.getDecimalRed();&#xA;    double aBlue = myKa * myDiffuseColor.getDecimalBlue();&#xA;    double aGreen = myKa * myDiffuseColor.getDecimalGreen();&#xA;&#xA;    final Color aColor = new Color(aRed, aGreen, aBlue);&#xA;&#xA;    theScene.getLights().parallelStream().forEach(theLight -&amp;gt;&#xA;    {&#xA;        Vector3D L = theLight.getL(theIntersectPoint);&#xA;        Vector3D V = theScene.getCamera().getPosition().subtract(theIntersectPoint).normalize();&#xA;        Vector3D H = L.add(V).scale((1.0 / (L.add(V).getLength()))).normalize();&#xA;&#xA;        Color aLC = theLight.getColor();&#xA;        Double aI = Math.abs(theNormal.dot(L));&#xA;        Double aR = Math.abs(theNormal.dot(H));&#xA;&#xA;       double aLightDistance = theLight.getDistance(theIntersectPoint);&#xA;&#xA;       double aShadow = 1.0;&#xA;&#xA;       if (hasShadows)&#xA;       {&#xA;           aShadow = getShadow(theIntersectPoint, L, aLightDistance, theScene);&#xA;       }&#xA;&#xA;        double aR = aLC.getDecimalRed() * aShadow *&#xA;                                  ((myKd * myDiffuseColor.getDecimalRed() * aI) +&#xA;                                      (myKs * mySpecularColor.getDecimalRed() * (Math.pow(aR, myShininess)))&#xA;                                  );&#xA;&#xA;        double aG = aLC.getDecimalGreen() * aShadow *&#xA;                                    ((myKd * myDiffuseColor.getDecimalGreen() * aI) +&#xA;                                        (myKs * mySpecularColor.getDecimalGreen() * (Math.pow(aR, myShininess)))&#xA;                                    );&#xA;&#xA;        double aB = aLC.getDecimalBlue() * aShadow *&#xA;                                    ((myKd * myDiffuseColor.getDecimalBlue() * aI) +&#xA;                                        (myKs * mySpecularColor.getDecimalBlue() * (Math.pow(aR, myShininess)))&#xA;                                    );&#xA;&#xA;        aColor.setRed(aColor.getDecimalRed() + aR);&#xA;        aColor.setBlue(aColor.getDecimalBlue() + aB);&#xA;        aColor.setGreen(aColor.getDecimalGreen() + aG);&#xA;&#xA;        if (isReflective &amp;amp;&amp;amp; aDepth &amp;gt; 0)&#xA;        {&#xA;            double aReflectionAngle = theRay.dot(theNormal);&#xA;&#xA;            Vector3D aReflectionVector = theRay.subtract(theNormal.scale(2.0 * aReflectionAngle)).normalize();&#xA;&#xA;            double F0 = ((myIndexOfRefraction - 1)  /(1 + myIndexOfRefraction)) *&#xA;                    ((myIndexOfRefraction - 1) / (1 + myIndexOfRefraction));&#xA;&#xA;            double FR = F0 + (1 - F0) * ((1 - Math.cos(aReflectionAngle)) * (1 - Math.cos(aReflectionAngle)) *&#xA;                                         (1 - Math.cos(aReflectionAngle)) * (1 - Math.cos(aReflectionAngle))&#xA;                                            * (1 - Math.cos(aReflectionAngle)));&#xA;&#xA;            Vector3D anAdjustedIntersect = theIntersectPoint.add(aReflectionVector.scale(.00001));&#xA;&#xA;            Color aRefColor = theScene.getKDFilteredObjects(aReflectionVector, anAdjustedIntersect)&#xA;                .parallelStream()&#xA;                .unordered()&#xA;                .map(thePObject -&amp;gt; new Pair&amp;lt;&amp;gt;(thePObject, thePObject.intersects(aReflectionVector, anAdjustedIntersect)))&#xA;                .filter(thePair -&amp;gt; thePair.getValue() != null)&#xA;                .reduce((thePair, theOtherPair) -&amp;gt; thePair.getValue() &amp;gt;= theOtherPair.getValue() ? theOtherPair : thePair)&#xA;                .map(theIntersect -&amp;gt;&#xA;                {&#xA;                    Vector3D aIntersectPoint = theIntersectPoint.add(aReflectionVector.scale(theIntersect.getValue()));&#xA;                    return theIntersect.getKey().getMaterial().getIntersectColor(theScene, theIntersect.getKey().getIntersectNormal(aIntersectPoint), aIntersectPoint, aReflectionVector, aDepth - 1);&#xA;                })&#xA;                .orElse(theScene.getBackgroundColor());&#xA;&#xA;            aColor.setRed(aColor.getDecimalRed() + (FR * aRefColor.getDecimalRed()));&#xA;            aColor.setBlue(aColor.getDecimalBlue() + (FR * aRefColor.getDecimalBlue()));&#xA;            aColor.setGreen(aColor.getDecimalGreen() + (FR * aRefColor.getDecimalGreen()));&#xA;        }&#xA;    });&#xA;&#xA;    return aColor;&#xA;}&#xA;&#xA;// TODO: factor in opacity&#xA;public double getShadow(Vector3D theOrigin, Vector3D theLightDirection, double theLightDistance, Scene theScene)&#xA;{&#xA;    // Avoid self-collision&#xA;    Vector3D aAdjustedOrigin = theOrigin.add(theLightDirection.scale(.00001));&#xA;&#xA;    return theScene.getKDFilteredObjects(theLightDirection, aAdjustedOrigin)&#xA;            .parallelStream()&#xA;            .unordered()&#xA;            .map(theObject -&amp;gt; theObject.intersects(theLightDirection, aAdjustedOrigin))&#xA;            .filter(Objects::nonNull)&#xA;            .filter(theT -&amp;gt; theT &amp;gt; 0 &amp;amp;&amp;amp; theT &amp;lt; theLightDistance)&#xA;            .findAny()&#xA;            .map(theT -&amp;gt; 0.0)&#xA;            .orElse(1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9231" LastEditorUserId="9231" LastEditDate="2018-08-23T23:07:43.267" LastActivityDate="2018-08-26T23:20:55.320" Title="Bright artifacts in ray tracer rendering seemingly caused by reflections" Tags="&lt;raytracing&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7955" PostTypeId="1" AcceptedAnswerId="7958" CreationDate="2018-08-23T16:31:35.013" Score="6" ViewCount="1340" Body="&lt;p&gt;I often hear that tessellation shaders aren't great for performance reasons. Something along the lines that if you try to use a tessellation shader, you'll find that the data you get out isn't sufficient and you'll have to re-do calculations anyways. Or it might have been that this path was less efficient than going another route and wasn't a good use of bandwidth?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain the details of why tessellation shaders are not advised, and if there are any exception cases where tessellation is a good thing?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="2654" LastEditDate="2018-08-23T22:10:30.740" LastActivityDate="2018-08-24T21:04:18.447" Title="Why are tessellation shaders disliked?" Tags="&lt;shader&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7956" PostTypeId="2" ParentId="7936" CreationDate="2018-08-23T18:04:10.240" Score="1" Body="&lt;p&gt;The clamping is done for the otherwise-jagged edge along the bright light. For pixels with the edge of the light in them, the radiance in the direction away from the center of the light is a very strong step function from (12,12,12) down to roughly (0.5,0.5,0.5) as you move across the pixel.&#xA;This edge is smoothly anti-aliased as long as your pixel values can go up to (12,12,12), but once you clamp the pixels to (1,1,1) the outline of the light edge becomes very jagged (pixelated).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clamping is technically adding bias but it's a limitation of the file format and display output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One possible solution that wouldn't introduce bias would be tone-mapping or underexposing the image, such as dividing the radiance values by 12, but that would change the look of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clamping prior to averaging (and then averaging) the subpixels is effectively the same as down-sampling the clamped subpixel image with a box filter. The subpixels are unbiased (before clamping), but the pixels written out are down-sampled from them after clamping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for down-sampling, I don't know if it's biasing but it's the same operation one would do to shrink an image to fit a smaller display, for example. It typically makes images look better but smaller.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could down-sample before clamping but it would look worse. But either way you will have to clamp when writing the file to PPM format unless you get all the radiance values below 1.&lt;/p&gt;&#xA;" OwnerUserId="8045" LastActivityDate="2018-08-23T18:04:10.240" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7957" PostTypeId="2" ParentId="7946" CreationDate="2018-08-23T19:08:08.787" Score="2" Body="&lt;p&gt;You seem to not change &lt;code&gt;GL_TEXTURE_MIN_FILTER&lt;/code&gt; and not fill all the mipmap layers. This will usually result in the texture not being applied, since by default the filter uses mipmapping.&lt;/p&gt;&#xA;" OwnerUserId="4647" LastActivityDate="2018-08-23T19:08:08.787" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7958" PostTypeId="2" ParentId="7955" CreationDate="2018-08-23T21:21:26.117" Score="3" Body="&lt;p&gt;An answer with details gotten elsewhere:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It's bad on mobile: ARM doesn't have a tessellation unit so is emulated in software. Tiled based architectures will write vertex data to main memory before pixel shading which is a bandwidth issue. qualcom switches to direct rendering mode if you enable tessellation which isn't cheap.&lt;/li&gt;&#xA;&lt;li&gt;It's bad on AMD / Console&lt;/li&gt;&#xA;&lt;li&gt;There is complexity in setting the tessellation factors to give good results &lt;/li&gt;&#xA;&lt;li&gt;it sounds like it's difficult not to get too much resolution in some ways (aliasing), and not enough in others (low quality results). You essentially need to know screen space derivatives of vertices to calculate good tessellation factors, and this is not easy to get even decent approximations of.&lt;/li&gt;&#xA;&lt;li&gt;A bummer about tessellation shaders is that they basically work by sampling discrete sample points (at vertices) so for a better result, you need a denser mesh to start with, which sort of defeats the purpose of dynamic tessellation.  Can be addressed a bit with mipmapping type strategies.&lt;/li&gt;&#xA;&lt;li&gt;Tessellation is still used by major games in specific cases though, and terrain does seem to be one usage case&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2018-08-24T21:04:18.447" LastActivityDate="2018-08-24T21:04:18.447" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7959" PostTypeId="2" ParentId="7932" CreationDate="2018-08-24T13:40:34.333" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rotation matrix | wikipedia.org&lt;/a&gt; in section that says &quot;in three dimensions&quot;. It's the first search result when searching about rotating a vector about an axis. Let me know if you have any questions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your specific problem: bring the point P to the origin, then rotate the vector about the Z axis, then bring the point P back to its original location.&lt;/p&gt;&#xA;" OwnerUserId="9180" LastEditorDisplayName="user7220" LastEditDate="2018-10-14T18:31:15.790" LastActivityDate="2018-10-14T18:31:15.790" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7961" PostTypeId="1" CreationDate="2018-08-24T15:08:17.033" Score="2" ViewCount="68" Body="&lt;p&gt;I am currently trying to reduce the tessellation levels on front facing triangles, but I also want to keep tessellation levels high on edges (so when the view vector is orthogonal to the triangle normal).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some background information. My terrain system tessellates the terrain and displaces the newly created triangles using the heightfield texture. That means that each triangle edge must always have the same tessellation levels as the other triangles that share the same edge, otherwise holes will be created in the terrain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't find a way to keep the calculations consistent for shared edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;edit: I have been trying to use non-divergent data by sampling the heightfield to calculate the normal for the edges. That way regardless of the triangle. The edge tessellation levels will always be the same, but I seem to be having issues.&lt;/p&gt;&#xA;" OwnerUserId="8893" LastEditorUserId="8893" LastEditDate="2018-08-24T15:15:50.380" LastActivityDate="2018-08-24T15:15:50.380" Title="Proper way to reduce tessellation on front faces?" Tags="&lt;tesselation&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7963" PostTypeId="1" AcceptedAnswerId="7964" CreationDate="2018-08-25T16:04:30.987" Score="1" ViewCount="378" Body="&lt;p&gt;pretend the images and the monitor have same color profile&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is every image from the internet commonly got gamma corrected?&#xA;Or our monitor is automatically gamma corrected all the image showed up?&lt;/p&gt;&#xA;" OwnerUserId="9248" LastActivityDate="2018-08-25T19:08:55.227" Title="Gamma correction is done in an image or a monitor?" Tags="&lt;gamma&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7964" PostTypeId="2" ParentId="7963" CreationDate="2018-08-25T19:08:55.227" Score="6" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is every image from the internet commonly got gamma corrected?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Every image is encoded with a color profile. Most color profiles do have a gamma correction, but not every color profile has that (raw for example). Most images on the internet are encoded in sRGB, which is gamma corrected. If you would download a random image from the internet, you will more than likely have an image that is in sRGB and thus gamma corrected.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Or our monitor is automatically gamma corrected all the image showed up?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The monitor receives its image in the color profile of the monitor (let's just say sRGB), it then decodes the image from sRGB to the actual intensity of the pixels and then displays it. Basically, the monitor receives a gamma corrected image and removes the gamma correction just before it displays it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Images that are saved to a file or that are sent to the monitor, are generally gamma corrected. This is for a very simple reason. We only have 256 values per RGB component to define the color of a pixel. Our eyes are very good at picking up small differences in dark parts of an image, but relatively terrible at picking up small differences in bright parts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we try to save an image without any gamma correcting as an 8-bit image (thus 256 values per RGB component), we end up with having the same amount of precision for dark parts in the image and bright parts in the image. However, our eyes cannot see small differences in bright parts of the image, so all that precision in the bright parts is simply wasted. Gamma correction fixes this. Before we convert the image to 8 bits, we first gamma correct it so that we allocate more precision to that darker parts of the image than the brighter parts of the image. When displayed, the monitor will remove that gamma correction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Left is an image that was gamma corrected before being saved to 8 bits and right is an image that was not gamma corrected before 8 bits. You can clearly see the lack of precision in the darker parts without gamma correction, but not in the bright parts.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/PDOqx.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PDOqx.png&quot; alt=&quot;Gamma correction VS no Gamma Correction&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gamma correction is a very useful trick to make our images with finite bits, look better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to read more about it, &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_correction&quot; rel=&quot;noreferrer&quot;&gt;you can do so here.&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-08-25T19:08:55.227" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7965" PostTypeId="1" CreationDate="2018-08-26T12:06:34.100" Score="3" ViewCount="392" Body="&lt;p&gt;Metropolis Light Transport is an application of the Metropolis-Hastings algorithm. Its variants differ only in the used &quot;mutation strategy&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there ongoing research on other Markov Chain Monte Carlo algorithms (with faster convergence rates) for use in ray tracing?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so, I'm interested in any paper.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="2287" LastEditDate="2018-08-27T09:50:58.307" LastActivityDate="2018-08-27T09:50:58.307" Title="Is there ongoing research on Markov Chain Monte Carlo algorithms (other than Metropolis-Hastings) for use in ray tracing?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7966" PostTypeId="1" AcceptedAnswerId="7968" CreationDate="2018-08-26T14:19:43.260" Score="1" ViewCount="299" Body="&lt;p&gt;So I just completed a naive path tracer that uses explicit direct light sampling.&#xA;Problem is the path tracer isn't converging. It's like a raytracer, showing a single image on each pass. More info on how am I doing this is provided below. I am using OpenCL 1.1.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  __kernel void render(__write_only image2d_t outputImage, __read_only image2d_t inputImage, int reset)&#xA;{&#xA;    float total_color;  // initalized to black&#xA;    for(int i = 0; i &amp;lt; samples_x; i++)&#xA;    {&#xA;        for(int j = 0; j &amp;lt; samples_y; j++)&#xA;        {       &#xA;            float4 direct_color, indirect_color; initialized black.&#xA;            Shoot ray through pixel.&#xA;&#xA;            HitInfo new_info, old_info;&#xA;            If( !intersects(ray, old_info) )&#xA;            {&#xA;                total_color += Background_color&#xA;                continue;&#xA;            }&#xA;            else&#xA;            {&#xA;                direct_color = computeDirectLighting(old_info);             &#xA;                float4 color_arr[BOUNCES];&#xA;                float cosine_falloff[BOUNCES];&#xA;                for(int i = 0; i &amp;lt; BOUNCES; i++)&#xA;                {       &#xA;                    new_ray = sampleHemisphere();&#xA;&#xA;                    if( !intersects(new_ray, new_info) )&#xA;                    {&#xA;                        color_arr[i] = sky_color;&#xA;                        cosine_falloff[i] = max(dot(old_info.normal, new_ray.dir), 0.0f);&#xA;                        break;&#xA;                    }&#xA;                    else if ( intersects light source)&#xA;                    {&#xA;                        i--;&#xA;                        continue;&#xA;                        (Sample again)                      &#xA;                    }&#xA;&#xA;                    color_arr[i] = computeDirectLighting(new_info);&#xA;                    cosine_falloff[i] = max(dot(old_info.normal, new_ray.dir), 0.0f);&#xA;                    old_info = new_info;&#xA;                }&#xA;&#xA;                for(i = color_arr.length() - 1; i &amp;gt;= 0; i--)&#xA;                {&#xA;                    indirect_color += color_arr[i];&#xA;                    indirect_color *= cosine_falloff[i];&#xA;                }&#xA;            }&#xA;&#xA;            total_color += direct_color + indirect_color;&#xA;&#xA;        }&#xA;    }&#xA;&#xA;&#xA;    }&#xA;    color /= (samples_x * samples_y);&#xA;&#xA;    if ( reset == 1 )&#xA;    {   &#xA;        write_imagef(outputImage, pixel, color);&#xA;    }&#xA;    else&#xA;    {           &#xA;        float4 prev_color = read_imagef(outputImage, sampler, pixel);&#xA;        color += prev_color;&#xA;        color /= 2.0f;&#xA;        write_imagef(outputImage, pixel, color);    &#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So this is the main outline. When the kernel runs the first time, &lt;code&gt;reset = 1&lt;/code&gt;. Thus it writes the color directly into the output image. At each iteration, the buffers of &lt;code&gt;outputImage&lt;/code&gt; and &lt;code&gt;inputImage&lt;/code&gt;get swapped. After iteration 1, &lt;code&gt;reset = 0&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means at iteration 2, the kernel reads from the image it wrote to, in iteration 1. It then averages the new color and the previous color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought taking 64 samples 2 times, and averaging them would be analogous to taking 128 samples once. If this is true then my image should converge, but it isn't. It shows only this image constantly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;:- &#xA;I think I should clear how I am calculating GI. After the first intersection. I send 1 ray directly to the light source (explicit direct light sampling). Then uniformly sample the hemisphere w.r.t area, and send another ray in this sampled direction. If the new ray hits light source, we sample again. This goes on &lt;code&gt;bounces times&lt;/code&gt;. Each bounce the program stores the direct color due to explicit direct light sampling at each hit point. The indirect color is the sum of all these direct colors. Added a simple algo of what I did to the code snippet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;cosine_falloff&lt;/code&gt; array holds all the weakening factors that should be multiplied to the respective indirect colors brought by secondary GI rays.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mueb5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mueb5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-08-26T15:53:04.640" LastActivityDate="2018-08-26T16:51:40.470" Title="Path tracer isn't converging" Tags="&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;sampling&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7967" PostTypeId="1" CreationDate="2018-08-26T14:50:33.180" Score="3" ViewCount="37" Body="&lt;p&gt;I am not an expert in 3D nor computer graphics. Please forgive me if I use wrong wording.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;High level problem description: For an online shop, I would like to create mockup images of apparel (t-shirts, tank tops, hoodies) with a print placed on them. There are loads of information how to do this with photoshop, but I would like to have an automated way to handle this. The image manipulation should happen with imagemagick finally.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The images should be captured on a dummy under a controlled setting. The image creation should include following steps:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Capture a image from the front of a white shirt.&lt;/li&gt;&#xA;&lt;li&gt;Capture a series of images of the dummy with the shirt as the dummy rotates around itself to create a photogrammetry 3D model of the dummy with the shirt.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The image taken from the front will be the basis of the product image later on. The 3D model should be used to create analyse the distortion which has to be applied to the design/print on the shirt. This is the step i am interested in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image composition should happen in this steps:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;use the image from the front as the base.&lt;/li&gt;&#xA;&lt;li&gt;Extract the shadows of the image.&lt;/li&gt;&#xA;&lt;li&gt;Blend a color layer over the shirt, to get the different product color.&lt;/li&gt;&#xA;&lt;li&gt;Map the design (a graphic or a text) over the white shirt using a distortion method to squeeze and pull apart the design following the perspective change created through the shape of the dummy.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My idea had been to use a 3D method an image of a grid as the design on the 3D model somehow and analyse the the created 2D image for the distortion of the grid to get a model of how to squeeze and pull the design then in the image stacking process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any recommendations how to do this in practical steps? Or can you suggest me an different approach to get the desired result?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="9255" LastEditorUserId="9255" LastEditDate="2018-08-27T17:13:21.230" LastActivityDate="2018-08-27T17:13:21.230" Title="Possible approach for product mockup creation including distortion created through perspective" Tags="&lt;3d&gt;&lt;projections&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7968" PostTypeId="2" ParentId="7966" CreationDate="2018-08-26T16:51:40.470" Score="3" Body="&lt;p&gt;I can find two possible reasons for the image not converging.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;#1. Every sample is the same&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;For every sample, you generate random rays. You do that when you shoot the ray through a pixel (for anti-aliasing and DoF) and when you sample the hemisphere (for a new indirect bounce). The problem would be if for every sample, it would generate the same direction, then every sample is the exact same colour and you would not be doing any converging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the times when generating random numbers on the GPU, we generate them in advance and save them to a texture. When we need a number, we just sample the texture. Of course, for every pixel you want a different random value, and you would then use something like the thread id or the pixel coordinate to sample the texture. Then, every frame must also be different, so you would also use the frame counter to offset the thread id. But, notice how there is nothing to make sure that every sample also has a new random number. If for every sample you generate the same random direction, then every sample is the exact same colour and you would not be doing any converging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can often easily be fixed by keeping track of how many random numbers you &#xA;already have generated and use that to offset every lookup. Basically, have a struct that holds the u and v values for the texture lookup. You initialize it with the thread id or pixel coordinate together with either the frame count or just a random number you generate on the CPU and pass it to the kernel as a global offset to the random values. Make sure that the struct is initialized in the very beginning of the kernel (where you initialize total_color). Then when you need a random number, you pass a reference to that struct to the method that generates a random number, it then looks up the random number in the texture and then it offsets the u and v values in the struct so that the next time you will get a different number.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, I have not seen how you generate the rays (both on shooting a ray through a pixel and sampling a hemisphere), so I cannot say for sure if this is the problem, but it does seem very much like it.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;#2. Not properly averaging multiple frames&lt;/h2&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I thought taking 64 samples 2 times, and averaging them would be analogous to taking 128 samples once.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is actually true. You average samples to get an image.&#xA;$$IMG1 = \frac{sample1 + sample2 + sample3 + samples4}{4}$$&#xA;Which you then do again for the second image.&#xA;$$IMG2 = \frac{sample5 + sample6 + sample7 + samples8}{4}$$&#xA;Which you then combine.&#xA;$$RESULT = \frac{IMG1 + IMG2}{2}=$$&#xA;$$\frac{\frac{sample1 + sample2 + sample3 + samples4}{4}+ \frac{sample5 + sample6 + sample7 + samples8}{4}}{2}=$$&#xA;$$\frac{\frac{sample1 + sample2 + sample3 + samples4 + sample5 + sample6 + sample7 + samples8}{4}}{2}=$$&#xA;$$\frac{sample1 + sample2 + sample3 + samples4 + sample5 + sample6 + sample7 + samples8}{8}$$&#xA;As you can see, it would indeed be like sampling twice as much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, your piece of code does not properly combine two images.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 prev_color = read_imagef(outputImage, sampler, pixel);&#xA;color += prev_color;&#xA;color /= 2.0f;&#xA;write_imagef(outputImage, pixel, color);    &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When we look at what you are doing.&#xA;$$outColor = \frac{newColor + oldColor}{2}$$&#xA;Where $outColor$ is the colour saved in the image.&#xA;$newColor$ is the colour you just calculated.&#xA;$oldColor$ is the color of the previous frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We see that it does what it is supposed to do, it averages both frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, when the third frame comes around, $outColor$ becomes $oldColor$ as you swap the buffers of outputImage and inputImage. Thus, we can substitute it.&#xA;$$outColor = \frac{newColor + \frac{prevColor + oldColor}{2}}{2}$$&#xA;Where $prevColor$ was the color calculated the previous frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although, this does not seem that good.&#xA;$newColor$ contributes &lt;strong&gt;50%&lt;/strong&gt;, while $prevColor$ and $oldColor$ only contribute &lt;strong&gt;25%&lt;/strong&gt;. This is a problem. You want every frame to contribute equally because then you are just adding up the samples. This means that you need to compensate for this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is an extremely simple solution to this. Multiply $oldColor$ by the amount of frames &lt;em&gt;excluding the current frame&lt;/em&gt; and to then divide by the amount of frames &lt;em&gt;including the current frame&lt;/em&gt;. you would then get this.&#xA;$$outColor = \frac{newColor + 2*\frac{prevColor + oldColor}{2}}{2 + 1}$$ Which would cancel out the divide and give you.&#xA;$$outColor = \frac{newColor + prevColor + oldColor}{3}$$ (The $+1$ is because we multiplied by 2 at the top, basically making it a total of 3 parts, and thus we need to divide by 3.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you would be calculating the fifth frame you would do it like this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 prev_color = read_imagef(outputImage, sampler, pixel);&#xA;color += prev_color * 4.0f;&#xA;color /= 5.0f;&#xA;write_imagef(outputImage, pixel, color);  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If you would be calculating the tenth frame you would do it like this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 prev_color = read_imagef(outputImage, sampler, pixel);&#xA;color += prev_color * 9.0f;&#xA;color /= 10.0f;&#xA;write_imagef(outputImage, pixel, color);  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This does mean that you need to pass through a counter which tells you how many frames you already have calculated. Most progressive or interactive path tracers actually only do one sample per frame (make sure that the ray through the pixel is randomly jittered), since it would take less time to calculate one frame, so that you see changes much earlier and often it is fine if you edit your scene using only one sample since you still get enough information.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-08-26T16:51:40.470" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="7969" PostTypeId="1" CreationDate="2018-08-26T17:27:26.213" Score="4" ViewCount="374" Body="&lt;p&gt;Is it possible to gain performance boost using new 4x4 MAD from &lt;a href=&quot;https://devblogs.nvidia.com/programming-tensor-cores-cuda-9/&quot; rel=&quot;nofollow noreferrer&quot;&gt;NVIDIA'a tensor cores&lt;/a&gt; for ray-triangle intersection tests?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Really there are two questions:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is it possible to modify some of the ray-triangle algorithms (say, Möller-Trumbore algorithm) to base it on 4x4 matrix MAD.&lt;/li&gt;&#xA;&lt;li&gt;Would it be a performance improvement?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="5430" LastEditorUserId="5430" LastEditDate="2018-09-08T14:36:22.337" LastActivityDate="2018-09-08T14:36:22.337" Title="Using multiply and accumulate of 4x4 matrices for ray-triangle intersection tests on GPU" Tags="&lt;raytracing&gt;&lt;gpu&gt;&lt;gpgpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7970" PostTypeId="2" ParentId="7965" CreationDate="2018-08-26T17:51:07.630" Score="5" Body="&lt;h1&gt;Overview&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Here is a short overview of the most used space representations, MLT variants and mutation strategies for these MLT variants. As you can see, there are quite some papers dating back to &lt;strong&gt;2017&lt;/strong&gt; (e.g., three papers explore combining the &lt;em&gt;Path Space&lt;/em&gt; and the &lt;em&gt;Primary Sample Space&lt;/em&gt; by jumping back and forth between the two).&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Path Space (PS) representation, Metropolis Light Transport (MLT)&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=258775&quot; rel=&quot;nofollow noreferrer&quot;&gt;Veach E., Guibas L. J.: Metropolis Light Transport. In Proceedings of the 24th Annual Conference on Computer Graphics and Interactive Techniques (New York, NY, USA, 1997), SIGGRAPH ’97, ACM Press/Addison-Wesley Publishing Co.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://graphics.stanford.edu/papers/veach_thesis/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Veach E.: Robust monte carlo methods for light transport simulation. Stanford University PhD thesis, 1997.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://graphics.cs.kuleuven.be/publications/WFBD2017TCFMLT/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Van de Woestijne J., Frederickx R., Billen N., Dutré P.: Temporal Coherence for Metropolis Light Transport. Eurographics Symposium on Rendering - Experimental Ideas &amp;amp; Implementations 2017.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;[Example implementation available in &lt;a href=&quot;https://github.com/mitsuba-renderer/mitsuba&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitsuba&lt;/a&gt;]&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Primary Sample Space (PSS) representation, PSSMLT&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://onlinelibrary.wiley.com/doi/pdf/10.1111/1467-8659.t01-1-00703&quot; rel=&quot;nofollow noreferrer&quot;&gt;Kelemen C., Szirmay-Kalos L., Antal G., Csonka F.: A Simple and Robust Mutation Strategy for the Metropolis Light Transport Algorithm.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2&gt;Extended Primary Sample Space (EPSS) representation, Multiplexed MLT (MMLT)&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2601138&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hachisuka T., Kaplanyan A. S., Dachsbacher C.: Multiplexed Metropolis Light Transport. ACM Trans. Graph. 33, 4 (July 2014).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that MMLT improves upon PSSMLT. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;[Example implementation available in &lt;a href=&quot;https://github.com/mmp/pbrt-v3&quot; rel=&quot;nofollow noreferrer&quot;&gt;pbrt-v3&lt;/a&gt;]&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Manifold Exploration MLT (MEMLT)&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2185554&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jakob W., Marschner S.: Manifold Exploration: A Markov Chain Monte Carlo Technique for Rendering Scenes with Difficult Specular Transport. ACM Trans. Graph. 31, 4 (July 2012).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://ecommons.cornell.edu/handle/1813/34189&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jakob W.: Light Transport On Path-Space Manifolds. Cornell University PhD thesis, 2013.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;[Example implementation available in &lt;a href=&quot;https://github.com/mitsuba-renderer/mitsuba&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitsuba&lt;/a&gt;]&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Half Vector Space representation, Half Vector Space Light Transport (HSLT)&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2601108&quot; rel=&quot;nofollow noreferrer&quot;&gt;Kaplanyan A. S., Hanika J., Dachsbacher C.: The Natural-constraint Representation of the Path Space for Efficient Light Transport Simulation. ACM Trans. Graph. 33, 4 (July 2014).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2853798&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hanika J., Kaplanyan A., Dachsbacher C.: Improved half vector space light transport. In Computer Graphics Forum (2015), vol. 34, Wiley Online Library.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that HSLT is more general than MEMLT: MEMLT is an &lt;em&gt;optional&lt;/em&gt; add-on mutation for MLT, whereas HSLT replaces the complete Path Space representation.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Gradient Domain representation, GDMLT&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2461943&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lehtinen J., Karras T., Laine S., Aittala M., Durand F., Aila T.: Gradient-domain Metropolis Light Transport. ACM Trans. Graph. 32, 4 (July 2013).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2661291&quot; rel=&quot;nofollow noreferrer&quot;&gt;Manzi M., Rousselle F., Kettunen M., Lehtinen J., Zwicker M.: Improved Sampling for Gradient-domain Metropolis Light Transport. ACM Trans. Graph. 33, 6 (Nov. 2014).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that there are variants for path tracing and bidirectional path tracing exploiting the Gradient Domain representation as well.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Path Space &amp;lt;-&gt; Primary Sample Space representations&lt;/h2&gt;&#xA;&#xA;&lt;h3&gt;Reversible Jump MLT (RJMLT)&lt;/h3&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://benedikt-bitterli.me/master-thesis/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bitterli B.: Informed Choices In Primary Sample Space. Master’s thesis, Swiss Federal Institute of Technology Zurich, 2015.&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=3132704&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bitterli B., Jakob W., Novák J., Jarosz W.: Reversible Jump Metropolis Light Transport Using Inverse Mappings. ACM Transactions on Graphics 37, 1 (Oct. 2017).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3&gt;Charted MLT (CMLT)&lt;/h3&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=3073677&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pantaleoni J.: Charted Metropolis Light Transport. ACM Trans. Graph. 36, 4 (July 2017).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h3&gt;Fusing State Spaces&lt;/h3&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=3073691&quot; rel=&quot;nofollow noreferrer&quot;&gt;Otsu H., Kaplanyan A. S., Hanika J., Dachsbacher C., Hachisuka T.: Fusing State Spaces for Markov Chain Monte Carlo Rendering. ACM Transactions on Graphics (Proc. of SIGGRAPH) 36, 4 (2017).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2&gt;Genetic operators in Path Space and Extended Primary Sample Space, Genetic MLT (GMLT)&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Delabie M.: Genetic Operators in Metropolis Light Transport. Master’s thesis, KU Leuven, Belgium, 2018.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that the &lt;em&gt;Path Space&lt;/em&gt; is represented via 3D path vertex positions instead of directions to facilitate crossovers (compared to MLT).&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Post Scriptum&lt;/h1&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Its variants differ only in the used &quot;mutation strategy&quot;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Different mutation strategies and &lt;strong&gt;space representations&lt;/strong&gt; are used. Furthermore, GMLT replaces and extends Markov states representing single paths to &lt;strong&gt;complete path populations&lt;/strong&gt; (&lt;em&gt;Evolutionary Monte Carlo&lt;/em&gt;, &lt;em&gt;Evolutionary Markov Chain Monte Carlo&lt;/em&gt; &amp;lt;&gt; &lt;em&gt;Markov Chain Monte Carlo&lt;/em&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some references to &lt;em&gt;Evolutionary Monte Carlo&lt;/em&gt;:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.jstor.org/stable/24306722?seq=1#page_scan_tab_contents&quot; rel=&quot;nofollow noreferrer&quot;&gt;Liang F., Wong W. H.: Evolutionary Monte Carlo: Applications to Cp Model Sampling and Change Point Problem. STATISTICA SINICA 10 (2000).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.jstor.org/stable/2670304?seq=1#page_scan_tab_contents&quot; rel=&quot;nofollow noreferrer&quot;&gt;Liang F., Wong W. H.: Real-Parameter Evolutionary Monte Carlo With Applications to Bayesian Mixture Models. Journal of the American Statistical Association 96, 454 (2001).&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2018-08-27T08:04:15.833" LastActivityDate="2018-08-27T08:04:15.833" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7971" PostTypeId="2" ParentId="7954" CreationDate="2018-08-26T23:20:55.320" Score="0" Body="&lt;p&gt;So this does in fact seem to be a self-collision issue. I was able to determine this by giving each triangle/sphere an ID and filtering that ID out when checking collisions. &lt;/p&gt;&#xA;" OwnerUserId="9231" LastActivityDate="2018-08-26T23:20:55.320" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7972" PostTypeId="1" AcceptedAnswerId="7974" CreationDate="2018-08-27T02:11:46.797" Score="1" ViewCount="66" Body="&lt;p&gt;I am trying to find an equation for a camera projection.&#xA;The goal is to map the point $P(P_x, P_y, P_z)$ from the world coordinates onto the window coordinates $Q(Q_x, Q_y)$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hlTMG.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hlTMG.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The eye of viewing is located a distance D from the $\hat{e_1}$-$\hat{e_2}$ plane, and in the direction of -$\hat{e_3}$.&#xA;$\hat{e_1}$, $\hat{e_2}$ and $\hat{e_3}$ are unit vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the equation to map P from world coordinates to window coordinates?&#xA;$\vec{Q}(Q_x, Q_y) = f(\vec{P}, \hat{e_1}, \hat{e_2}, \hat{e_3}, \vec{v}, \vec{c})$&#xA;with all the vectors on the right side described in terms of world coordinates, eg&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\vec{P} = (P_x, P_y, P_z)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\vec{C} = (C_x, C_y, C_z)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\vec{e_1} = ({e_1}_x, {e_1}_y, {e_1}_z)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\vec{e_2} = ({e_2}_x, {e_2}_y, {e_2}_z)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\vec{e_3} = ({e_3}_x, {e_3}_y, {e_3}_z)$&lt;/p&gt;&#xA;" OwnerUserId="9260" LastEditorUserId="9260" LastEditDate="2018-08-27T15:02:37.563" LastActivityDate="2018-08-27T15:02:37.563" Title="Equation for camera projection" Tags="&lt;camera&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7973" PostTypeId="2" ParentId="7932" CreationDate="2018-08-27T06:33:32.473" Score="0" Body="&lt;p&gt;Thank you for the suggestions provided. As @gallickgunner mentioned, I shall rephrase the question will all the possible information which I could provide. I had attached also the schematic to depict my question.&lt;/p&gt;&#xA;&lt;p&gt;1)I need to rotate the vector V with the base point P by an angle and find the new vector V'.&#xA;2) The rotation axis is say for is about a local y axis at point P (which is parallel to global Y axis)&#xA;3) Subsequently, I need to rotate the initial vector V about x axis which is parallel to global Y axis.&#xA;The main reason for the rotation is to find the new vector V' at point P. Both the rotations are independent and each of the rotation provides a new V'.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/MTiJX.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MTiJX.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Thank you for the support. Looking forward for an answer at the earliest.&lt;/p&gt;&#xA;" OwnerUserId="9207" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-08-27T06:33:32.473" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7974" PostTypeId="2" ParentId="7972" CreationDate="2018-08-27T07:23:47.593" Score="1" Body="&lt;p&gt;This is pretty straightforward matrix math and can be found on &lt;a href=&quot;https://en.wikipedia.org/wiki/3D_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;. It's quite elaborate, though, if you want to learn the math behind it and the other types of projection that exist. I will encourage you to checkout either &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/1568814240&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real-Time Rendering&lt;/a&gt; or &lt;a href=&quot;https://www.amazon.co.uk/Computer-Graphics-Principles-Practice-Practices/dp/0321399528&quot; rel=&quot;nofollow noreferrer&quot;&gt;Computer Graphics, Principles and Practice&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-08-27T07:23:47.593" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7975" PostTypeId="1" CreationDate="2018-08-27T08:20:26.167" Score="2" ViewCount="1722" Body="&lt;p&gt;Forgive me, I dont really understand the basis of alpha blending. Like I know the formula but when it comes to the terms blending operation, source blend factor, and destination blend factor I am absolutely lost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The goal is to do additive blending like in photoshop so black items would be invisible and items with any color would add their color resulting in an effect that pixels with many layers underneath are close to white.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is I have no clue how to translate this to metal. For example this is how I am currently doing alpha blending (although t&lt;a href=&quot;https://stackoverflow.com/questions/52035162/metal-alpha-blending-is-not-working&quot;&gt;his currently isnt working&lt;/a&gt; for whatever reason). What should I be doing for additive blending?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;descriptor.colorAttachments[0].blendingEnabled = YES;&#xA;descriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;&#xA;descriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorSourceAlpha;&#xA;descriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOneMinusSourceAlpha;&#xA;descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOneMinusSourceAlpha;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2020-08-11T18:04:18.350" Title="How to perform additive blending in Metal. What do these terms mean?" Tags="&lt;blending&gt;&lt;metal&gt;&lt;alpha&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="7976" PostTypeId="1" CreationDate="2018-08-27T14:22:43.880" Score="0" ViewCount="202" Body="&lt;p&gt;I am currently trying to implement SSAO on my graphics engine. I am following John Chapman's tutorial &lt;a href=&quot;http://john-chapman-graphics.blogspot.com/2013/01/ssao-tutorial.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. This is a pretty popular article that is used as reference in many SSAO articles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The part that confuses me is on the generation of rotation vector.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; noiseSize; ++i) {&#xA;   noise[i] = vec3(&#xA;      random(-1.0f, 1.0f),&#xA;      random(-1.0f, 1.0f),&#xA;      0.0f&#xA;   );&#xA;   noise[i].normalize();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Notice that the z component of the vector is zero. In the article John explain that he want to rotate the sample vector around the z axis. But later when he construct the TBN matrix, he use it as if it is a view space coordinate.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 rvec = texture(uTexRandom, vTexcoord * uNoiseScale).xyz * 2.0 - 1.0;&#xA;vec3 tangent = normalize(rvec - normal * dot(rvec, normal));&#xA;vec3 bitangent = cross(normal, tangent);&#xA;mat3 tbn = mat3(tangent, bitangent, normal);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't see any reason why the z vector of the noise vector should be zero. I think that the zero component could be any component. And then what happen if the normal vector is parallel with the noise vector, wouldn't it create a wrong TBN matrix?&lt;/p&gt;&#xA;" OwnerUserId="8565" LastEditorUserId="2287" LastEditDate="2018-09-05T05:56:56.113" LastActivityDate="2018-09-14T15:11:34.273" Title="SSAO random noise vector generation" Tags="&lt;glsl&gt;&lt;ssao&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7977" PostTypeId="2" ParentId="7975" CreationDate="2018-08-27T15:01:04.483" Score="1" Body="&lt;h1&gt;Terminology&lt;/h1&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The &lt;em&gt;source&lt;/em&gt; color is the value written by the fragment/pixel shader. &lt;/li&gt;&#xA;&lt;li&gt;The &lt;em&gt;destination&lt;/em&gt; color is the color from the image currently in the frame buffer (that will be overridden).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h1&gt;Additive blending&lt;/h1&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// The blend formula is defined as:&#xA;// (source.rgb * sourceRGBBlendFactor  )   rgbBlendOperation (destination.rgb * destinationRGBBlendFactor  ) &#xA;// (source.a   * sourceAlphaBlendFactor) alphaBlendOperation (destination.a   * destinationAlphaBlendFactor)&#xA;// &amp;lt;=&amp;gt;&#xA;// (source.rgba * 1) + (destination.rgba * 1)&#xA;&#xA;descriptor.colorAttachments[0].blendingEnabled             = YES;&#xA;descriptor.colorAttachments[0].rgbBlendOperation           = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].alphaBlendOperation         = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].sourceRGBBlendFactor        = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].sourceAlphaBlendFactor      = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].destinationRGBBlendFactor   = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the clear color is equal to &lt;code&gt;{0.0f,0.0f,0.0f,_}&lt;/code&gt; and we draw &lt;code&gt;{0.1f,0.1f,0.1f,_}&lt;/code&gt; to the same pixel a couple of times, the pixel color eventually becomes &lt;code&gt;{1.0f,1.0f,1.0f,_}&lt;/code&gt; (white). Drawing &lt;code&gt;{0.0f,0.0f,0.0f,_}&lt;/code&gt; (black) has no effect. We do not care about the alphas.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2018-08-27T18:40:53.603" LastActivityDate="2018-08-27T18:40:53.603" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7978" PostTypeId="2" ParentId="7975" CreationDate="2018-08-27T17:38:40.370" Score="5" Body="&lt;p&gt;The “blend factors” are the amount that the specified component is multiplied by while blending. “Destination” is the existing content that’s being blended “on top of”, while “source” is the new content that’s being blended “onto” it. When the blend operation is set to “add”, the final pixel value is calculated like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;value = source * sourceBlendFactor + destination * destinationBlendFactor&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;…so a blend factor of “one” means the value is used unchanged (multiplied by 1), “[x]Alpha” means the value is multiplied by the alpha value of x (source or destination), and “oneMinus[x]Alpha” means the value is multiplied by (1 - the alpha value of x).&lt;/p&gt;&#xA;&lt;p&gt;For additive blending, you most likely want the following:&lt;/p&gt;&#xA;&lt;p&gt;Objective-C:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;descriptor.colorAttachments[0].blendingEnabled = YES;&#xA;descriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorSourceAlpha;&#xA;descriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Swift 5:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;descriptor.colorAttachments.colorAttachments[0].isBlendingEnabled = true&#xA;descriptor.colorAttachments.colorAttachments[0].rgbBlendOperation = .add&#xA;descriptor.colorAttachments.colorAttachments[0].alphaBlendOperation = .add&#xA;descriptor.colorAttachments.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha&#xA;descriptor.colorAttachments.colorAttachments[0].sourceAlphaBlendFactor = .one&#xA;descriptor.colorAttachments.colorAttachments[0].destinationRGBBlendFactor = .one&#xA;descriptor.colorAttachments.colorAttachments[0].destinationAlphaBlendFactor = .one&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;There’s a really helpful tool for visualizing the different options &lt;a href=&quot;https://www.andersriggelsen.dk/glblendfunc.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;—it’s written for OpenGL, but the Metal stuff works the same way.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2020-08-11T18:04:18.350" LastActivityDate="2020-08-11T18:04:18.350" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7979" PostTypeId="1" CreationDate="2018-08-28T07:26:55.860" Score="1" ViewCount="129" Body="&lt;p&gt;Here is my predicament. I am trying to draw a multitude of dots that leave trails behind them real time. Heres the difficulty, that line fades. Each dot line has a defined z position and the goal would be for everything to blend properly, in real time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am currently doing this geometry with a series of triangles that form a triangle strip (I am not using a triangle strip due to the edge case in the circle buffer and spacial locality). This strip is currently implemented as a sort of circle buffer where old triangles are overridden. Each vertex gets passed in the time it was created and thus it knows how to fade (make transparent) its own color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make things more complicated I am also drawing caps on the ends of the dot so there is essentially a half rectangle at the end with fragments of it discarded to shape it into a circle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of this presents a predicament for alpha testing as alpha testing requires drawing to be sorted in order of depth. Just about all the geometry is transparent in some form. Even if I can get the triangle strip to do this properly getting the half circle working would be quite difficult.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I set the z position based on the dot's id and use the same value that is used to dim the dot's trail to get the triangle strip to have non-conflicting depth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the half circle part does this mean I am going to have to do two draw calls per circle? One to render their segment of the triangle buffer and the other to draw the semi-circle?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I am using the following memory layout:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;const int MAX_INDEX = 200;&#xA;const int MAX_DOTS = 10000;&#xA;int bufferIndex = (bufferIndex + 1) % MAX_INDEX;&#xA;int dotIndex = 0..&amp;lt;MAX_DOTS&#xA;Rect = triangleStripBuffer[bufferIndex * MAX_DOTS + dotIndex];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You can see that data in there is not naturally sorted by anything other than time but even that cycles and there is no consideration for drawing order.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I suppose I really need ideas on how I can get the geometry to draw in order so that alpha testing can occur. How do I combine these two different drawing goals in a good way?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I figure this problem is fairly platform-agnostic but if it is not I am working with Metal and eventually Vulkan can do this.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="11180" LastEditDate="2019-09-23T11:23:17.897" LastActivityDate="2019-09-23T11:23:17.897" Title="Sorting my geometry for alpha testing" Tags="&lt;geometry&gt;&lt;depth-map&gt;&lt;blending&gt;&lt;metal&gt;&lt;alpha&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7980" PostTypeId="1" AcceptedAnswerId="7982" CreationDate="2018-08-28T12:39:32.947" Score="2" ViewCount="896" Body="&lt;p&gt;This picture depicts my current immagination of the coordinate systems involved in ray tracing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/42lEsNq.png&quot; alt=&quot;my current imagination of the coordinate systems involved&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&#xA;So the green rectangle is the [-0.5, nx-0.5] x [-0.5, ny-0.5] coordinate system and you can translate that coordinate system to the {u, v, w} coordinate system's coordinates (the world coordinate system) w/ the equations near the green rectangle.&#xA;&lt;br&gt;&#xA;From the origin of the world coordinate system, you can cast rays into the [l, r] x [b, t] coordinate system w/ the equation near the red rectangle ($s = e + u_{s} * u + v_{s} * v + w_{s} * w$).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The [-0.5, nx-0.5] x [-0.5, ny-0.5] matches a classic windowing systems coordinate sytem while the [l, r] x [b, t] seems to be the &quot;ray tracer's screen&quot;/&quot;ray tracer's view area&quot;.&#xA;&lt;br&gt;&#xA;Both apparently define the view frustum depicted above. This however is counterintuitive for me since I expect the screen directly in front of the world coordinate system. So the screen I am seeing is the green rectangle, the [-0.5, nx-0.5] x [-0.5, ny-0.5]. That means everything goes backwards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The ray tracer algorithm in my own words (and with my current understanding):&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Cause&quot; the world space to shoot a ray so that it goes through each pixel of the window screen [-0.5, nx-0.5] x [-0.5, ny-0.5] and check for an intersection within the frustum along the way. If there is an intersection color it, if not leave it at the background color.&#xA;&lt;br&gt;&#xA;IOW: I am a &quot;commander&quot; and as I go through each pixel of [-0.5, nx-0.5] x [-0.5, ny-0.5] I cause the world space to shoot/cast a ray so that it goes through the pixel that I am currently at as well while checking for intersections within the frustum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With my current understanding I tried to implement a ray tracer on the basis of a set_pixel() function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My implementation attempt (w/ a skewed green sphere as a result):&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void game::Engine::run()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;{   &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int nx = window_width; // 1366&#xA;int ny = window_heigth; // 768&#xA;// Construct the &quot;ray tracer window&quot;/&quot;ray tracer screen&quot;&#xA;int left = -200;&#xA;int right = 200;&#xA;int top = 100;&#xA;int bottom = -100;&#xA;int distance = 10;&#xA;// Create the {u, v, w} coordinate system&#xA;Vec3f e{ 0, 0, float(distance) };&#xA;Vec3f u{ 1, 0, 0 };&#xA;Vec3f v{ 0, 1, 0 };&#xA;Vec3f w{ 0, 0, float(distance) };&#xA;// Create the sphere&#xA;Vec3f center{ -50, -20, 11 };&#xA;float radius = 3.0f;&#xA;&#xA;// Game loop&#xA;bool running{ true };&#xA;SDL_Event event{};&#xA;while (running)&#xA;{&#xA;    // Clear buffer&#xA;    SDL_SetRenderDrawColor(renderer, 153, 153, 153, 255);&#xA;    SDL_RenderClear(renderer);&#xA;&#xA;    // Draw&#xA;    for (int i = 0; i &amp;lt;= window_width; ++i) {&#xA;        for (int j = 0; j &amp;lt; window_heigth; ++j) {&#xA;            // Calculate the scalar factors from the pixel position for each axis of the {u, v, w} coordinate system&#xA;            float u_s = (left + (right - left) * (i + 0.5)) / nx;&#xA;            float v_s = (bottom + (top - bottom) * (j + 0.5)) / ny;&#xA;            float w_s = -distance;&#xA;            // Cast a ray (in a perspective manner)&#xA;            Ray3f s{ e, u * u_s + v * v_s + w * w_s};&#xA;            Vec3f co = center - s.origin_vector;&#xA;            // Calculate the intersection between the sphere and the ray&#xA;            float a = Vec3f::dot_product(s.direction_vector, s.direction_vector);&#xA;            float b = 2 * Vec3f::dot_product(co, s.direction_vector);&#xA;            float c = Vec3f::dot_product(co, co) - radius * radius;&#xA;            float discriminant = b * b - 4 * a * c;&#xA;            Vec3f color_vec{ 0, 0, 0 }; // default background color&#xA;            if (discriminant &amp;gt; 0)&#xA;            {&#xA;                // Make the hit sphere green&#xA;                color_vec.x = 0;&#xA;                color_vec.y = 1;&#xA;                color_vec.z = 0;&#xA;            }&#xA;            set_pixel(renderer, i, j, 255 * color_vec.x, 255 * color_vec.y, 255 * color_vec.z, 255);&#xA;        }&#xA;    }&#xA;&#xA;    // Swap buffers&#xA;    SDL_RenderPresent(renderer);&#xA;    // Process event queue&#xA;    while (SDL_PollEvent(&amp;amp;event))&#xA;    {&#xA;        switch (event.type)&#xA;        {&#xA;        case SDL_QUIT:&#xA;            running = false;&#xA;            break;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;br&gt;&lt;br&gt;&#xA;&lt;strong&gt;The result:&lt;/strong&gt;&#xA;&lt;img src=&quot;https://i.imgur.com/sqEsS7S.png&quot; alt=&quot;result&quot;&gt;&#xA;&lt;br&gt;&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My conclusion:&lt;/strong&gt;&#xA;I got the coordinate system totally wrong thus the skewed result.&#xA;So the window 1366 x 768 and the ray tracer's screen 400 x 200 as well as the world coordinate system that is spanned with the standard basis in the code doesn't lead to the expected result the sphere beeing on the center of the screen and not looking skewed. Plus, the coordinate system acts weird and seems to be arbitrary.&#xA;&lt;br&gt;&#xA;Thus something is fundamentally wrong with my current understanding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&#xA;&lt;br&gt;&#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=zQIvR_6IayM&amp;amp;feature=youtu.be&amp;amp;t=27m16s&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lecture on ray tracing&lt;/a&gt;&#xA;&lt;br&gt;&#xA;&lt;a href=&quot;https://www.cs.utah.edu/~shirley/books/fcg2/rt.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Peter Shirley's treatise on ray tracing&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9266" LastEditorUserId="9266" LastEditDate="2018-08-29T15:40:16.370" LastActivityDate="2018-08-29T19:22:14.090" Title="Problem of understanding the coordinate systems involved in ray tracing" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="7981" PostTypeId="2" ParentId="7969" CreationDate="2018-08-28T13:23:49.310" Score="3" Body="&lt;p&gt;Yes, it is possible.  For one however, Möller-Trumbore is not the only algorithm out there for ray triangle intersection, &lt;a href=&quot;http://jcgt.org/published/0005/03/03/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;there exist others&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However all of these rely on linear algebra vector multiplications and matrix operations.  These can be combined into 4x4 tensor core operations (and each tensor core can do 4x4x4, but there are 8 cuda cores to every tensor core).   You can compute multiple intersections in Möller-Trumbore at a time with tensor cores.  You could say, combine multiple cross products or dot products into a single matrix operation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The catches?  Well first, the precision of tensor cores matrix multiplication is &lt;strong&gt;16bit&lt;/strong&gt; float.  But don't fret, given decent spatial subdivision of, say, a raytraced environment, that precision should only matter &lt;em&gt;per spatial block/voxel/subdivision&lt;/em&gt; which is necessary in ray-tracing in order to not test all triangles in the scene. 16 bit for a 10 km area might be a big deal in terms of poor position precision, but for a 2x2 meter area it isn't (mantissa alone will handle 1024 different values). Note the addition part &lt;em&gt;is&lt;/em&gt; 32bit float. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, &lt;a href=&quot;https://devblogs.nvidia.com/programming-tensor-cores-cuda-9/&quot; rel=&quot;nofollow noreferrer&quot;&gt;you have to move data around in such a way that tensor cores can actually access it&lt;/a&gt;, which, because it is unlikely that any of us on this entire site have direct access to a machine with tensorcores, has a yet unknown performance cost.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Third, I'm not entirely sure its possible to do &lt;em&gt;both&lt;/em&gt; tensor core calculations and &lt;em&gt;scalar&lt;/em&gt; calculations at the same time.  This could end up &lt;em&gt;slowing&lt;/em&gt; many tasks to the point that any advantage tensor cores gave becomes negligible.  But I could be wrong and we can actually hide things like latency for tensor core memory moves with multiple floating point and tensor core instructions interleaved. &lt;/p&gt;&#xA;" OwnerUserId="6530" LastActivityDate="2018-08-28T13:23:49.310" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7982" PostTypeId="2" ParentId="7980" CreationDate="2018-08-28T15:13:48.017" Score="2" Body="&lt;p&gt;I gave it a quick look and I found several places which need attention. First of all you forgot transforming the view space to NDC space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We are working with 3 spaces. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; The world space, which is the global reference frame. You usually define spheres in this frame. Or if you are reading model data, you might want to multiply by a model matrix to bring them into world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; The camera space. This is the part of the world the camera views. The correct equation for generating rays in the camera space as i mentioned in the comments are given by.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ x = l + (r-l)*(pixel_i * 0.5)/Width$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ y = b + (t-b)*(pixel_y * 0.5)/Height$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ z = -View Plane Distance$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; The third is the NDC space which is usually in the range $[-1,1]$ Some API's have this range in $[0,1]$ For ray tracing however, we are concerned with $[-1,1]$. The concept here is, imagine your whole image which is $Width \times Height$ to be mapped to a plane which is $2 \times 2$ units wide centered at the origin. This is somewhat a generalization. We don't need to mess with the width and height anymore. We introduced an intermediary space where everything is in the range [-1,1]. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However this is true only for square images. What happens when &lt;code&gt;width != height&lt;/code&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have to account for it by doing,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ x = [-a, a]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ y = [-1, 1]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $a$ is Aspect Ratio given by. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ a = Width/Height $ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The NDC space is usually calcualted as,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ x_{ndc} = [ (2 * ( i+ 0.5)/Width) - 1] * Aspect Ratio$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ y_{ndc} = [ (2 * ( y+ 0.5)/Width) - 1]$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note tho depending on the image coordinates, we might need to flip $y_{ndc}$. The calculation above assumes Image has the origin at the top left corner. If the origin is at the bottom left, we will need to flip.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However this assumes the camera is positioned at the origin. How do take into account for camera rotation and position. Normally this is done by the use of a camera matrix which transforms from world space to camera or vice versa. You calculate ray direction in the NDC space, multiply it by this matrix and then normalize it. I will not go into details about this one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way you are calculating the rays in camera space, haven't seen much like this but there is a simple fix to get a moving camera and transform it in NDC space. You divide by the width and height of the camera volume. So your equations become. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ x = [l + (r-l)*(pixel_i * 0.5)/Width] / (r-l)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\therefore x = l/(r-l) + (pixel_i * 0.5)/Width $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ y = [b + (t-b)*(pixel_y * 0.5)/Height] / (t-b)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\therefore y = b/(t-b) + (pixel_y * 0.5)/Height$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ z = -View Plane Distance$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You don't need to account for aspect ratio in this scenario as it's already being done by $l/(r-l)$ and $b/(t-b)$ factors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the proper way of intersecting spheres (if you are normalizing direction, which you should, would be)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; t = -1.0f;&#xA; co = ray.origin - sphere.center // Note we subtract center FROM origin.&#xA; b = dot(co, ray.dir);&#xA; c = dot(co, co) - sphere.radius * sphere.radius;&#xA; disc = b*b - c;&#xA; if disc &amp;gt;= 0&#xA;   t = -b + sqrt(disc); // wrong&#xA;   t = -b - sqrt(disc); // correct&#xA; if ( t &amp;gt;= 0)&#xA; {&#xA;  ray.length = t;       /* you can add a length parameter in ray as &#xA;                           direction is normalized&#xA;                           Set other parameters such as sphere id, or if &#xA;                           there is only 1 sphere, set color here. */&#xA;  return true;&#xA; }&#xA; else&#xA;  return false;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also forgot to mention your spheres $Z$ coordinates should be negative. Since rays are generating in the $-Z$ direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- I corrected my sphere intersection. There was a mistake. To answer the questions in your comments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) About the spaces, scratchapixel seems to follow RenderMan's coordinate system. Since I'm more from an OpenGL background, I'll talk with that in mind.&#xA;When I talk about NDC space that equals scratchapixels's definition of screen space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Screen space usually means screen/window coordinates which range from 0 to image width/height and that's why scratchapixel can be confusing sometimes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2 and 3) About the sphere intersection and why rays need a length parameter. First of all rays are defined by this formula.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ R = e + t*\hat{d}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $e$ is the origin, $\hat{d}$ is the direction vector of that ray and $t$ is the length of that ray. In raytracing we initialize all our rays to have the length infinity. Then whenever we intersect anything, we set this $t$ parameter if it's less than the previous value. For the first time, the $t$ value is set to the distance to the first object hit. After that whenever we find that the same ray hits another object we compare the $t$ values to see which one is closer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can't directly set color by checking discriminant only because when a Ray interseccts a sphere it can be the case that it intersects at two points (when ray isn't tangent to the sphere). Both of these are given by,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ t = -b + sqrt(disc)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ t = -b - sqrt(disc)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However in the case for spheres, the closest point is always given by the second one. I mistakenly provided you the first one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However this doesn't mean we dont have a view frustum. If we want we can define near and far planes to get a closed view frustum and initialize all rays with the &lt;code&gt;length = distance to far plane&lt;/code&gt;. Then any objects farther than this far plane will not get intersected. In other words, &lt;code&gt;discriminant&lt;/code&gt; will be greater than zero but the &lt;code&gt;t&lt;/code&gt; check would fail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also I don't see where you have declared &lt;code&gt;window_width&lt;/code&gt; in your code but make sure when dividing by &lt;code&gt;width&lt;/code&gt; or &lt;code&gt;height&lt;/code&gt; the division should have a float value in it (cast width/height into float if declared as int) other wise aspect ratio would be rounded off to an integer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And try placing your sphere further in the -Z direction. Let's say &lt;code&gt;(0,0, -6)&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-08-29T19:22:14.090" LastActivityDate="2018-08-29T19:22:14.090" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="7983" PostTypeId="1" AcceptedAnswerId="7992" CreationDate="2018-08-28T19:34:58.110" Score="1" ViewCount="543" Body="&lt;p&gt;As mentioned &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4623/multiple-vao-share-a-vbo&quot;&gt;here&lt;/a&gt;, multiple VAOs can share a single VBO. However, can multiple VAOs share a single EBO?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I want to create 2 rectangles. So, I do the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const GLuint indices[6] = {&#xA;    0, 1, 2,&#xA;    0, 3, 2&#xA;};&#xA;&#xA;// First&#xA;glGenVertexArrays (1, &amp;amp;VAO1);&#xA;glBindVertexArray (VAO1);&#xA;glGenBuffers (1, &amp;amp;EBO1);&#xA;glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, EBO1);&#xA;glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);&#xA;// creating VBO, setting attributes etc&#xA;// Second&#xA;glGenVertexArrays (1, &amp;amp;VAO2);&#xA;glBindVertexArray (VAO2);&#xA;glGenBuffers (1, &amp;amp;EBO2);&#xA;glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, EBO2);&#xA;glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;glBufferData(GL_ELEMENT_ARRAY_BUFFER)&lt;/code&gt; is called twice for different EBOs with same data. As I understand, this leads to double GPU memory consumption and takes twice loading time. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, would the following be correct?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const GLuint indices[6] = {&#xA;    0, 1, 2,&#xA;    0, 3, 2&#xA;};&#xA;glGenBuffers (1, &amp;amp;EBO);&#xA;glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;glBufferData (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);&#xA;&#xA;// First&#xA;glGenVertexArrays (1, &amp;amp;VAO1);&#xA;glBindVertexArray (VAO1);&#xA;glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;// creating VBO, setting attributes etc&#xA;// Second&#xA;glGenVertexArrays (1, &amp;amp;VAO2);&#xA;glBindVertexArray (VAO2);&#xA;glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9270" LastActivityDate="2018-08-29T16:59:27.003" Title="Multiple VAO share a EBO (OpenGL 3.3)" Tags="&lt;opengl&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7984" PostTypeId="1" AcceptedAnswerId="8043" CreationDate="2018-08-28T19:51:48.443" Score="5" ViewCount="304" Body="&lt;p&gt;I am generating plane vertices where the y values are generated by a heightmap (noise) algorithm. This is how I produce my vertex array:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (let row = 0; row &amp;lt; noise.length; row++) {&#xA;    for (let col = 0; col &amp;lt; noise[0].length; col++) {&#xA;        color = noise[row][col];&#xA;        positions.push(row, color, col);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After that I generate index values like this (I know that there is a lot of optimization that can be done here):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const height = noise.length + 1;&#xA;const width = noise[0].length + 1;&#xA;&#xA;for (let row = 0; row &amp;lt; height - 1; row++) {&#xA;    if (row % 2 === 0) {&#xA;        if (row === height - 2) break;&#xA;        for (let col = 0; col &amp;lt; width - 1; col++) {&#xA;            indices.push(col + row * (width));&#xA;            indices.push(col - 1 + (row + 1) * (width));&#xA;        }&#xA;    } else {&#xA;        for (let col = width - 2; col &amp;gt;= 0; col--) {&#xA;            indices.push(col - 2 + (row + 1) * (width));&#xA;            indices.push(col - 2 + row * (width));&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;indices.pop();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Finally I draw the plane using:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;gl.drawElements(gl.TRIANGLE_STRIP, buffers.numIndices, gl.UNSIGNED_SHORT, 0);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if I use &lt;code&gt;POINTS&lt;/code&gt; as mode, the plane seem to look as it should:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JVCye.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JVCye.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whereas if I am using &lt;code&gt;TRINGLE_STRIP&lt;/code&gt; the result looks wrong:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PbGXw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PbGXw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First I thought wrong indices might be the reason but then I checked by scaling to a 3x3 grid/plane and the vertex and index output looked as I would have expected:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[-1, -43.89, -1, &#xA;-1,  -82.27,  0, &#xA;-1,  -23.06,  1, &#xA; 0,  -43.43, -1, &#xA; 0,  -54.85,  0, &#xA; 0,  -66.27,  1, &#xA; 1,  -61.89, -1, &#xA; 1,  -27.43,  0, &#xA; 1,  -59.89,  1]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The vertices might not exactly correspond to what you would have&#xA;  expected from above loop. That is because I am centering the &lt;code&gt;mesh&lt;/code&gt;&#xA;  around origin after the loop.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Indices:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[0, 3, 1, 4, 2, 5, 8, 4, 7, 3, 6]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So my guess is that the problem is that I am pushing my triangles counterclockwise, that is why I tried to enable culling and depth testing but that did not help either:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.enable(gl.DEPTH_TEST);&#xA;gl.enable(gl.CULL_FACE);&#xA;gl.cullFace(gl.FRONT);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IhodK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IhodK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any guess what might be the reason for wrong &lt;code&gt;TRIANGLE_STRIP&lt;/code&gt; rendering?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update 1:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to @PaulHK's recommendation I changed my index creation loop to insert the last index of a single strip twice. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (let row = 0; row &amp;lt; rows - 1; row++) {&#xA;    if (row % 2 === 0) {&#xA;        for (let col = 0; col &amp;lt; cols; col++) {&#xA;            indices.push(col + row * cols);&#xA;            indices.push(col + (row + 1) * cols);&#xA;        }&#xA;    } else {&#xA;        for (let col = cols - 1; col &amp;gt;= 0; col--) {&#xA;            indices.push(col + (row) * cols);&#xA;            indices.push(col + (row + 1) * cols);&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For a 3x3 grid this produces:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Vertices:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[-1, -9.6, -1,&#xA; -1, -64.6, 0,&#xA; -1, -11.1, 1,&#xA; 0, -38.8, -1,&#xA; 0, -32.8, 0,&#xA; 0, -26.8, 1,&#xA; 1, -37.0, -1,&#xA; 1, -1, 0,&#xA; 1, -47.5, 1]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Indices:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[0, 3, 1, 4, 2, 5, 5, 8, 4, 7, 3, 6]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Unfortunately the rendered object still looks the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update 2:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use the Diamond-square algorithm to generate the mesh. This requires a grid of size &lt;code&gt;(2^n) + 1&lt;/code&gt;.&#xA;I.e.:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;2, 3, 5, 9, 17, 33, 65, 129, 257, 513 ...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Maybe it's just a coincidence but it seems to me that the grid can be displayed correctly for sizes &lt;code&gt;3 - 129&lt;/code&gt; with the procedure from &lt;strong&gt;Update 1&lt;/strong&gt;. For a size of 257 and above the mesh has errors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3x3 looks fine:&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/KQNSfm.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KQNSfm.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;129x129 looks fine:&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kK8wom.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kK8wom.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;257x257 seems wrong:&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cRGdom.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cRGdom.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2485" LastEditorUserId="2485" LastEditDate="2018-09-05T18:15:16.210" LastActivityDate="2018-09-11T02:59:56.690" Title="Problems rendering a plane via `drawElements`" Tags="&lt;webgl&gt;" AnswerCount="1" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7985" PostTypeId="1" AcceptedAnswerId="7987" CreationDate="2018-08-29T07:02:30.167" Score="4" ViewCount="427" Body="&lt;p&gt;So, the german wikipedia states about ambient occlusion:&lt;br&gt;&lt;blockquote&gt;The ambient occlusion method is based on the assumption that an object, a set of objects or an entire scene is surrounded by a unit sphere of light.&lt;/blockquote&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, let's suppose we've got a scene in which the only object is a pipe, closed at one end, at the center of the scene. If I got this right, then to get the ambient occlusion this object would now be evenly light from every direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But wouldn't lighting the object evenly from everywhere mean that for every point in the pipe there would also be a ray of light that would directly reach it, leading to no ambient occlusion at all (no shadows inside the pipe)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What did I get wrong here?&lt;/p&gt;&#xA;" OwnerUserId="9274" LastActivityDate="2018-08-29T08:05:56.890" Title="Ambient occlusion of a sole object in a scene" Tags="&lt;ambient-occlusion&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7986" PostTypeId="2" ParentId="7985" CreationDate="2018-08-29T08:02:06.750" Score="3" Body="&lt;p&gt;Ambient occlusion is basically shooting out a large number of rays diffusely from a surface point. In a pipe some of the rays will intersect with the pipe itself, which means that this surface point will not receive as much ambience as points that don't have intersecting rays. The inside of the pipe vs the outside of the pipe will be different.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-08-29T08:02:06.750" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7987" PostTypeId="2" ParentId="7985" CreationDate="2018-08-29T08:05:56.890" Score="4" Body="&lt;p&gt;When you compute ambient occlusion (AO) for a point on an object's surface, you sample multiple directions and measure what fraction of them escape. That is, you're trying to approximate what fraction of the unit hemisphere is visible to that point on the surface. (Note that it's a unit &lt;em&gt;hemisphere&lt;/em&gt; because half of the unit sphere is on the wrong side of the surface to start with.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So in your pipe example, the outside of the pipe is not at all occluded. From every point on the outside, any ray fired in that hemisphere will escape without intersecting the object. All of the outside would be lit with 100% of the ambient light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The inside is another matter. The inside of the end cap can only see a small circle of that hemisphere, through the other end of the pipe. The exact fraction depends on the radius and length of the pipe, but call it 10% for the example. 90% of rays fired from a point on the end cap will hit the inside of the cap, and the other 10% will escape along the length of the pipe and out of the other end. These points are 90% occluded, so they'll be lit with 10% of the ambient light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider a point at the open end of the pipe, but on the inside. This point is 50% occluded. Half of the rays fired from it go into the pipe and intersect with it at some point. The other half go straight out and escape to the unit hemisphere. This point will be lit with 50% of the ambient light, and it's easy to see that the 50% will smoothly decrease to the 10% (or however much is the minimum) as you travel down the inside of the pipe towards the end cap, as less of that hole is visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The important point I think you misunderstood is that you measure or estimate what &lt;em&gt;fraction&lt;/em&gt; of the unit hemisphere is visible from the point you're shading, not whether it's visible at all. Casting many rays and counting what fraction escape is one way of estimating this.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-08-29T08:05:56.890" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="7988" PostTypeId="2" ParentId="7578" CreationDate="2018-08-29T12:38:08.673" Score="2" Body="&lt;p&gt;A surface with a Lambertian BRDF has the characteristic that independent of the direction from which one looks at that surface, one receives the same amount of reflected energy (i.e. a diffuse surface point looks the same from all possible directions). Lets consider a small plane orthogonal to this looking direction: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If one looks straight at the surface (i.e. the looking direction is parallel to the surface normal), the projected surface area of that plane onto the surface along the looking direction is &lt;strong&gt;equal&lt;/strong&gt; to the surface area of the plane (i.e. orthogonal projection).&lt;/li&gt;&#xA;&lt;li&gt;If one looks along a sharp angle at the surface, the projected surface area of that plane onto the surface along the looking direction is &lt;strong&gt;much larger&lt;/strong&gt; than the surface area of the plane.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Assume an isotropic BRDF (i.e. the same reflection factor independent of the looking direction), the following normalization factor and probability density distribution over the hemisphere are obtained:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\int_\Omega 1 \, d\omega = \int_{0}^{2\pi} \int_{0}^{\pi/2} \sin\theta \, \mathrm{d}\theta \, \mathrm{d}\phi = \int_{0}^{2\pi} \int_{0}^{1} \, \mathrm{d}\!\left(\cos\theta\right) \, \mathrm{d}\phi = 2\pi$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\mathrm{pdf}\!\left(\theta, \phi\right) \equiv \frac{1}{2\pi}$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the differences in projected surface area dependent of the looking direction remain and thus this isotropic BRDF violates the above definition of a Lambertian BRDF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To counteract the differences in projected surface area dependent of the looking direction, the reflection factor must compensate and be dependent of the looking direction as well. This compensating factor is $\cos\theta$ (i.e. decreases from orthogonal, $\theta=0$, to glancing, $\theta=\pi/2$ directions). The following normalization factor and probability density distribution over the hemisphere are obtained:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\int_\Omega \cos\theta \, d\omega = \int_{0}^{2\pi} \int_{0}^{\pi/2} \cos\theta \sin\theta \, \mathrm{d}\theta \, \mathrm{d}\phi = \int_{0}^{2\pi} \int_{0}^{1} \cos\theta \, \mathrm{d}\!\left(\cos\theta\right) \, \mathrm{d}\phi = \pi$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\mathrm{pdf}\!\left(\theta, \phi\right) = \mathrm{pdf}\!\left(\theta\right) = \frac{\cos\theta}{\pi}$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Alternatively&lt;/strong&gt;, one can start reasoning from the amount of incident energy as well (dual). &lt;strong&gt;Lambert's cosine law&lt;/strong&gt; + &lt;strong&gt;conservation of energy&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\rho_d \int_\Omega \cos\theta \, d\omega = \rho_d \pi \le 1$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(For more info see &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/diffuse-lambertian-shading&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt;, thanks to @Tare.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that diffuse is not the same as isotropic:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The reflection from a surface with a Lambertian BRDF is diffuse and non-isotropic. &lt;/li&gt;&#xA;&lt;li&gt;The brightness perceival from a surface with a Lambertian BRDF is non-diffuse and isotropic (i.e. looks the same from all possible directions).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;(Similar for diffuse area light sources.)&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2018-08-29T13:02:16.037" LastActivityDate="2018-08-29T13:02:16.037" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7989" PostTypeId="1" CreationDate="2018-08-29T13:04:20.890" Score="1" ViewCount="38" Body="&lt;p&gt;I want to put a segment of an image to another image. But to make it realistic I applied poisson blending. But the output is not good at all. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Output without poisson blending. The kid was cropped from another image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0WYFo.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0WYFo.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With poisson blending&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gIWRY.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gIWRY.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have no clue what else to try. I though of calculating average value of the image segment where the kid is placed and then scaling the kids color to that average. But it should not work properly if that image segment is very white or black etc.&lt;/p&gt;&#xA;" OwnerUserId="7299" LastActivityDate="2018-09-18T15:44:00.640" Title="How to blend a segment of an image with another image" Tags="&lt;image-processing&gt;&lt;color&gt;&lt;blending&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7991" PostTypeId="1" AcceptedAnswerId="7995" CreationDate="2018-08-29T16:08:32.230" Score="6" ViewCount="2227" Body="&lt;p&gt;If I calculate the average (mean) hue of a set of colours naively, I will get silly answers sometimes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, in HSB/HSL, the average of hue=10 (slightly orange red) and hue=350 (slightly blue red) would arithmetically be hue=(10+350)/2=180 (cyan).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Considering the hue channel only, how should I calculate averages in order to get results which match intuition in these cases?&lt;/p&gt;&#xA;" OwnerUserId="8233" LastActivityDate="2018-08-30T08:26:18.623" Title="How do I calculate average hue, since the numbers loop around?" Tags="&lt;color&gt;&lt;color-science&gt;&lt;colorspace&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7992" PostTypeId="2" ParentId="7983" CreationDate="2018-08-29T16:59:27.003" Score="1" Body="&lt;p&gt;Your code is non-functional, but only because (in the core profile) you cannot bind a buffer to &lt;code&gt;GL_ELEMENT_ARRAY_BUFFER&lt;/code&gt; unless a VAO is also bound. So the part that creates the buffer would need to use a different binding point, which is totally fine:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const GLuint indices[6] = {&#xA;    0, 1, 2,&#xA;    0, 3, 2&#xA;};&#xA;glGenBuffers (1, &amp;amp;EBO);&#xA;glBindBuffer (GL_ARRAY_BUFFER, EBO);&#xA;glBufferData (GL_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Everything else is perfectly valid.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-08-29T16:59:27.003" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="7994" PostTypeId="1" CreationDate="2018-08-30T05:26:25.997" Score="6" ViewCount="187" Body="&lt;p&gt;So I have a bit of a predicament I am trying to solve. I have 10,000 triangle strips I am trying to draw. Each one has a z-order for the entire strip and within each strip the most recent triangles need to have a higher z order than the older one. So essentially the z order of a triangle is &lt;code&gt;(stripIndex / 10000) + (age / MAX_AGE)&lt;/code&gt; where MAX_AGE is somewhere around 100 frames. I am not sure about this number yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At start time all of the data to store this is initialized and a ring buffer of some form is used so that the most recent triangle's are in a new position each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This ring buffer is useful because only 2 triangles will have to be written for each frame per triangle strip so no data has to shift or move. You just over-write the oldest data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The trick is I want to do alpha blending between these triangle strips so I need to have the geometry drawn in order from front to back. I am experimenting with different layouts that will allow me to minimize draw calls and CPU stress required. This is an unsolved problem for me but I think I am going to have to do 10001 draw calls. But that is not what this question is about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So while trying to do this I ran into an odd GPU phenomenon I cant explain. Right now I am rendering with a simple no-depth additive blending Metal pipeline that looks like this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;id&amp;lt;MTLFunction&amp;gt; vertex_f = [MetalCore compileShader:vertex];&#xA;id&amp;lt;MTLFunction&amp;gt; fragment_f = [MetalCore compileShader:fragment];&#xA;&#xA;MTLRenderPipelineDescriptor *descriptor = [[MTLRenderPipelineDescriptor alloc] init];&#xA;descriptor.sampleCount = 1;&#xA;descriptor.fragmentFunction = fragment_f;&#xA;descriptor.vertexFunction = vertex_f;&#xA;descriptor.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;&#xA;descriptor.colorAttachments[0].blendingEnabled = YES;&#xA;descriptor.colorAttachments[0].rgbBlendOperation = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].alphaBlendOperation = MTLBlendOperationAdd;&#xA;descriptor.colorAttachments[0].sourceRGBBlendFactor = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].sourceAlphaBlendFactor = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].destinationRGBBlendFactor = MTLBlendFactorOne;&#xA;descriptor.colorAttachments[0].destinationAlphaBlendFactor = MTLBlendFactorOne;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As I said at the beginning I create a buffer that holds all of the triangles necessary to draw each of the strips. The buffer is the same size every time and the triangle count is also constant. The buffers do have indices and that is also constant and created at the beginning. The underlying simulation that controls these triangle strips is also constant. However under two different memory layout conditions there are significantly different frame rates even under multiple trials. I cant figure out why. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;From now on I will refer to 10000 as MAX_STRIPS&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Memory configuration 1 has a triangle for the n'th strip in the i'th ring buffer position located in the triangle buffer at &lt;code&gt;i*MAX_STRIPS*4 + n*4&lt;/code&gt; th position in the buffer. So in memory a single strips triangles are very spread out but a concentrated chunk of memory is updated each frame. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Memory configuration 2 has a triangle for the n'th strip in the i'th ring buffer position located in the triangle buffer at the &lt;code&gt;n*MAX_AGE*4 + i*4&lt;/code&gt; th position in the buffer. All of a single triangle strips vertices are close together in memory however writing is more spread out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For whatever reason configuration 1 takes significantly longer than configuration 2 to render.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I could understand a small difference in CPU time but what I dont get is this difference in GPU time. Any clue as to why this might be happening.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The following compares debugging information of these two methods. The left side is memory configuration 1. The right is memory configuration 2. Big difference are highlighted.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/OFdDU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OFdDU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the vertex shader for all interested &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct VertexOutAlpha {&#xA;    float4 position [[ position ]];&#xA;    float4 color;&#xA;};&#xA;struct StripVertex {&#xA;    float3 data; //z value is the z value for the entire strip. Triangles will have different z positions&#xA;    float2 color;//x = color, y = time&#xA;};&#xA;vertex VertexOutAlpha strip_vertex(constant StripVertex * vertexBuffer [[ buffer(0) ]],&#xA;                              indexType vid [[ vertex_id ]],&#xA;                              constant matrix_float3x3* matrix [[buffer(1)]],&#xA;                              constant float* gameTime [[buffer(2)]]) {&#xA;    StripVertex vert = vertexBuffer[vid];&#xA;    VertexOutAlpha out;&#xA;    float dimmer = 1.0 - clamp(((*gameTime - 0.016) - vert.color.y) * 10.0, 0.0, 1.0);&#xA;    const float levelSize = 1.0 / (MAX_STRIPS + 0.01);&#xA;    out.position = float4((*matrix * float3(vert.data.x, vert.data.y, 1.0)).xy, vert.data.z + (1 - dimmer) * levelSize, 1.0);&#xA;&#xA;     out.color = float4(HSVtoRGB(vert.color.x, 1.0, dimmer), 1.0);&#xA;    return out;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the generation of the vertex buffer for all interested&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    //triangleStripDataPtr is pre-allocated and alligned to the page size&#xA;    triangleStripDataBuffer = [self.device newBufferWithBytesNoCopy:triangleStripDataPtr length:4 * MAX_STRIPS *  MAX_AGE options:MTLResourceStorageModeShared deallocator:nil];&#xA;    assert(triangleStripDataBuffer != nil);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Does anyone have a good explanation for why this is happening?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastEditorUserId="2308" LastEditDate="2018-09-03T19:51:52.070" LastActivityDate="2018-09-04T01:20:59.480" Title="Same draw call causing extremely different GPU usage under different triangle orders" Tags="&lt;gpu&gt;&lt;vertex-buffer-object&gt;&lt;metal&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="7995" PostTypeId="2" ParentId="7991" CreationDate="2018-08-30T07:46:17.923" Score="2" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;How do I calculate average hue, since the numbers loop around?&lt;/p&gt;&#xA;&lt;p&gt;I will get silly answers sometimes. For example, in HSB/HSL, the average of hue=10 (slightly orange red) and hue=350 (slightly blue red) would arithmetically be hue=(10+350)/2=180 (cyan).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/q/8169654/3648282&quot;&gt;How to calculate mean and standard deviation for hue values from 0 to 360?&#xA;&lt;/a&gt; &lt;strong&gt;and&lt;/strong&gt; &lt;a href=&quot;https://stackoverflow.com/q/13959276/3648282&quot;&gt;Averaging circular values (particularly Hues in HSL color scheme)&lt;/a&gt; which provides C++ source code.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;What if the values were 0° and 180°, then there are two answers: 90° and 270°; the same thing applies whenever the two inputs are opposite, there's two answers and no clear choice.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The program &amp;quot;&lt;a href=&quot;http://mkweb.bcgsc.ca/color-summarizer/?download&quot; rel=&quot;nofollow noreferrer&quot;&gt;Image Color Summarizer&lt;/a&gt;&amp;quot; (Linux version) has a file called &amp;quot;peravg.pm&amp;quot; which says: &amp;quot;compute the average and median of a periodic data set, like a set of angles or hues&amp;quot;. The &lt;a href=&quot;http://mkweb.bcgsc.ca/color-summarizer/&quot; rel=&quot;nofollow noreferrer&quot;&gt;main page&lt;/a&gt; offers a Windows version and a webpage image upload along with an API.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The author explains:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The colour summarizer will produce descriptive colour statistics for an image. Reported will be the average, median, minimum and maximum of each component of RGB, HSV, LCH and Lab. Average hues are calculated using &lt;a href=&quot;https://en.wikipedia.org/wiki/Mean_of_circular_quantities&quot; rel=&quot;nofollow noreferrer&quot;&gt;mean of circular quantities&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Some of the questions the summarizer will answer are:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;what is the average color hue, saturation and value in my image?&lt;/li&gt;&#xA;&lt;li&gt;what are the colours that are most representative of the image?&lt;/li&gt;&#xA;&lt;li&gt;what is the image's human readable colour description (e.g. dark pure blue)?&lt;/li&gt;&#xA;&lt;li&gt;what do the RGB, HSV, LCH and Lab histograms look like?&lt;/li&gt;&#xA;&lt;li&gt;what are the RGB, HSV, LCH and Lab pixel values?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The paper: &amp;quot;&lt;a href=&quot;https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3979548/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Perceiving the average hue of color arrays&lt;/a&gt;&amp;quot; (May 1 2014), by Jacquelyn Webster, Paul Kay, and Michael A. Webster examines the subject from the viewpoint of an observer's perception of color.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Dq2Ch.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Dq2Ch.png&quot; alt=&quot;HSL&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9258" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-08-30T08:26:18.623" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7996" PostTypeId="1" CreationDate="2018-08-30T08:24:23.253" Score="2" ViewCount="47" Body="&lt;p&gt;I created two ellipses,&lt;br/&gt;$\hspace{150px}$&lt;a href=&quot;https://i.stack.imgur.com/WfzOU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WfzOU.png&quot; width=&quot;300&quot;/&gt;&lt;/a&gt;,&lt;br/&gt;where the red ellipsis is as the blue one, except translated to the right and rotated by ${30}^{\circ} .$ Using rotation matrix, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\left[&#xA;  \begin{array}{cc}&#xA;    x  \\[2px]&#xA;    y   \end{array}&#xA;\right]&#xA;\&#xA;\phantom{F} ~=~&#xA;\left[&#xA;  \begin{array}{cc}&#xA;    cos(30^{\circ})  &amp;amp; -sin(30^{\circ})  \\[2px]&#xA;    sin(30^{\circ}) &amp;amp; \phantom{}cos(30^{\circ})&#xA;  \end{array}&#xA;\right]&#xA;\&#xA;*&#xA;\left[&#xA;  \begin{array}{cc}&#xA;    X  \\[2px]&#xA;    Y   \end{array}&#xA;\right]&#xA;\&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next I tried to calculate deformation gradient by using principal axes(a and b for initial ellipsis,c and d for translated one), and then I decomposed $\vec{c}$ and $\vec{d}$ vectors,$$&#xA;\begin{alignat}{7}&#xA;\vec{c} &amp;amp;~~=~~ 1.0021 \, \vec{b} &amp;amp;~&amp;amp;+ &amp;amp;~&amp;amp;0.8654 \, \vec{a} \\[5px]&#xA;\vec{d} &amp;amp;~~=~~ 0.8654 \, \vec{b} &amp;amp;&amp;amp;- &amp;amp;&amp;amp;0.2505 \, \vec{a}&#xA;\end{alignat}&#xA;$$and created the deformation gradient as$$&#xA;F ~=~&#xA;\left[&#xA;  \begin{array}{cc}&#xA;    \phantom{-} 0.8654  &amp;amp;    1.0021  \\[2px]&#xA;             -  0.2505  &amp;amp;    0.8654&#xA;  \end{array}&#xA;\right]&#xA;\,.&#xA;$$But it is obvious that, this is not the same as the ${30}^{\circ}$ rotation matrix that I had expected it to be,$$&#xA;\phantom{F} {\llap{\textsf{rotation matrix}}} ~=~&#xA;\left[&#xA;  \begin{array}{cc}&#xA;    0.8660  &amp;amp;            -  0.5000  \\[2px]&#xA;    0.5000  &amp;amp;   \phantom{-} 0.8660&#xA;  \end{array}&#xA;\right]&#xA;\,.&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt;  Why aren't the deformation gradient, $F ,$ and and the rotation matrix, $\textsf{rotation matrix} ,$ the same?&lt;/p&gt;&#xA;" OwnerUserId="9280" LastEditorUserId="9280" LastEditDate="2018-08-30T09:11:40.277" LastActivityDate="2018-08-30T09:11:40.277" Title="What is wrong with my deformation gradient calculation?" Tags="&lt;transformations&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="7997" PostTypeId="1" CreationDate="2018-08-30T14:34:33.357" Score="2" ViewCount="755" Body="&lt;p&gt;I am writing a ray tracer using openCL, and following this tutorial &lt;a href=&quot;http://raytracey.blogspot.com/2016/11/opencl-path-tracing-tutorial-2-path.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://raytracey.blogspot.com/2016/11/opencl-path-tracing-tutorial-2-path.html&lt;/a&gt;&#xA;However, I find that the author has two copies of the Sphere code, one in host in c++ and one in device in cl. This causes duplication, which I would like to avoid if possible. &#xA;Is there any way to avoid this? If there is, should the code for, say a sphere struct be in host or in device?&lt;/p&gt;&#xA;" OwnerUserId="8699" LastActivityDate="2019-08-26T10:02:25.410" Title="OpenCL ray tracer: which is better, geometry code on device side or on host side?" Tags="&lt;raytracing&gt;&lt;opencl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="7999" PostTypeId="2" ParentId="7997" CreationDate="2018-08-31T07:36:55.160" Score="1" Body="&lt;p&gt;In order to pass data to the device side, in OpenCL you must create the sphere structure on the device as well (that is in the kernel). So you first create your structures as classes or structs on the CPU. The variables in the structs should be of &lt;code&gt;cl_*&lt;/code&gt; datatypes. OpenCL provides typedefs for all primitive data types. Then create these structures on the GPU as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Care should be taken about data alignment when passing structures from CPU to GPU. If you have passed data in OpenGL, you'll know what this is about.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After you create your structures on the CPU, you encode them in a OpenCL buffer, and pass this buffer to the kernel.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-08-31T07:36:55.160" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8003" PostTypeId="1" CreationDate="2018-09-01T08:21:28.047" Score="1" ViewCount="52" Body="&lt;p&gt;How do I create a vertex shader that allows to choose 3 non aligned direction vectors and then allows to morph all vectors positions such that every vertex is remapped so that two vertices that are parallel to one of the axis, now become parallel to the direction between the vertex and a choosen vanishing points coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Axis 1 : (1,0,0)&lt;/li&gt;&#xA;&lt;li&gt;Axis 2 : (0,1,0)&lt;/li&gt;&#xA;&lt;li&gt;Axis 3 : (0,0,1)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Vanishing points:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;P1 : Axis 1*10000&lt;/li&gt;&#xA;&lt;li&gt;P2 : Axis 2*10000&lt;/li&gt;&#xA;&lt;li&gt;P3 : Axis 3*10000&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Assume then we have 2 points&#xA;(3,0,100) and (6,0,100)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Those are parallel to axis 1 so if i set the vanishing points 1 to (10000,10000,0) I expect  the coordinates of the points to become parallel to the new axe&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(3,3,100) and (6,6,100).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically I want to choose 3  Axis and rotate Them indipendently around the origin and then the geometry should morph accordingly. The rotation is performed using &quot;target far away points&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is not necessary to handle huge rotation angles. 45 spherical degrees is more than enough&lt;/p&gt;&#xA;" OwnerUserId="4503" LastEditorUserId="4503" LastEditDate="2018-09-01T08:33:38.443" LastActivityDate="2018-09-01T08:33:38.443" Title="Simulating vanishing points shader" Tags="&lt;shader&gt;&lt;geometry&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8006" PostTypeId="1" AcceptedAnswerId="8027" CreationDate="2018-09-02T20:06:16.873" Score="2" ViewCount="388" Body="&lt;p&gt;Is there any 3d software that supports rendering an artificial scene to a light field image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With that I mean an image capturing light from more than one point in a scene, more lika a spherical volume of evenly distributed points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is &lt;a href=&quot;https://www.blog.google/products/google-ar-vr/experimenting-light-fields/&quot; rel=&quot;nofollow noreferrer&quot;&gt;research&lt;/a&gt; being done by for instance P Debevec for Google VR that does this for physical scenes with an expensive camera rig. I would like to be able to render the same output but from an artificial scene, in for instance 3dsmax. And then preferably use this in for instance Unity 3D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would be awesome for a Myst-like game with high fidelity ray traced graphics instead of low-poly rasterized real time graphics. But I guess animations would be almost out of the question. It should at least in theory be easier to incorporate animations in cgi-light fields than in real photos.&lt;/p&gt;&#xA;" OwnerUserId="9293" LastEditorUserId="9293" LastEditDate="2018-09-05T10:48:51.963" LastActivityDate="2018-09-06T09:08:10.780" Title="Light field rendering for 3d software?" Tags="&lt;raytracing&gt;&lt;3d&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8007" PostTypeId="1" CreationDate="2018-09-03T03:28:28.203" Score="2" ViewCount="85" Body="&lt;p&gt;in future, will sRGB which is a common standard monitor color space nowadays be taken the place by the wider gamut color spaces?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;since wide gamut monitor keep publishing in the market and may be affordable for anyone one day, will the majority change to use the wider gamut in like coming 20 to 30 years?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or stay with sRGB and not worth to change.&lt;/p&gt;&#xA;" OwnerUserId="9248" LastActivityDate="2018-09-04T16:21:06.593" Title="Will sRGB color space get replaced by wider gamut" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="0" ClosedDate="2018-09-05T05:58:12.567" ContentLicense="CC BY-SA 4.0" />
  <row Id="8008" PostTypeId="1" CreationDate="2018-09-03T05:08:56.200" Score="1" ViewCount="106" Body="&lt;p&gt;I should preface with currently this question is mostly asking about Metal and iOS GPUs. That being said if this is GPU or OS specific and you can go into detail about other platforms that would be great to as this application will eventually be cross platform.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am drawing some geometry in two draw calls.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Opaque geometry is drawn. Discards happen. No particular triangle draw order. Fragments in this draw call occupy only 5% of the screens pixels.&lt;/li&gt;&#xA;&lt;li&gt;Transparent geometry is drawn. No discards happen. Triangles are drawn in depth order. Fragments in this call occupy a bulk of the screen pixels.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The question is essentially should I convert draw call 1 to ordered triangles with alpha=0 where I would generally discard. There will be a cost to ordering the triangles in draw 1 however it will not be two costly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason I am unsure is that I know the second you call discard on a fragment you remove the possibility of Metal preforming early depth test which is allegedly quite an optimization. What I dont know is if discards disable early depth test on draw call 1 do they also disable the optimization for draw call 2's geometry?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does the fragment stage happen after each draw calls vertex phase or after all of them?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you think I should explore sorting the triangles and using alpha blending on draw call 1? Again this would be a negligible CPU cost would it actually help the GPU? &lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2018-09-04T08:33:02.747" Title="Are the benefits of a Metal early depth test limited to one draw call" Tags="&lt;metal&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8009" PostTypeId="1" AcceptedAnswerId="8012" CreationDate="2018-09-03T07:36:01.903" Score="4" ViewCount="541" Body="&lt;p&gt;I am migrating code from CUDA to OpenGL compute shaders.&#xA;I could not find a way to set the local workgroup size outside the shader; is there a way to set gl_WorkGroupSize in the calling program like one can do for gl_NumWorkGroups?&#xA;Thanks in advance&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2018-09-04T13:03:35.783" Title="Can gl_WorkGroupSize be set outside the compute shader?" Tags="&lt;opengl&gt;&lt;compute-shader&gt;&lt;cuda&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8010" PostTypeId="2" ParentId="8008" CreationDate="2018-09-03T09:47:57.040" Score="1" Body="&lt;p&gt;I don't know what Apple have done with Metal per se, but as the iOS devices have PowerVR-derived GPUs, normally I would think that doing as much opaque-only drawing &quot;up front&quot; would usually be beneficial, but &lt;em&gt;if&lt;/em&gt;, as in your case, only 5% of the screen is covered by opaque geometry, I'm not sure how much the software overhead will affect things.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The reason I am unsure is that I know the second you call discard on a fragment you remove the possibility of Metal preforming early depth test which is allegedly quite an optimization. What I dont know is if discards disable early depth test on draw call 1 do they also disable the optimization for draw call 2's geometry?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;With PowerVR devices, a depth test can &quot;always&quot; be done as the first step in the pipeline, so any geometry that was submitted earlier in the scene &lt;em&gt;can&lt;/em&gt; cull later things prior to fragment shading. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;With alpha-tested (AKA &quot;punch-though&quot;), the Z-test can thus be done against previous geometry, but there may be a cost of then doing the texturing/shading and feeding that back to update the depths for subsequent geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you aren't doing alpha-test/discards, and are doing your own sorting, then this feedback is not required (but obviously there may be more shading/texturing work to perform).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Such a pity, though, that we removed the OIT feature from the early PowerVR hardware)&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Does the fragment stage happen after each draw calls vertex phase or after all of them?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm not sure what you are asking, but for a given scene, all the vertex shading (across multiple calls) is performed**, the geometry buffered, and only then rendering commences on the entire scene.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;**There are some caveats here but that probably doesn't affect you&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Do you think I should explore sorting the triangles and using alpha blending on draw call 1? Again this would be a negligible CPU cost would it actually help the GPU? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Are you asking &quot;should I profile/time the results and see what is best for my use case?&quot;.  Probably &quot;yes&quot;.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-09-04T08:33:02.747" LastActivityDate="2018-09-04T08:33:02.747" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8011" PostTypeId="1" CreationDate="2018-09-03T13:08:08.583" Score="3" ViewCount="79" Body="&lt;p&gt;Let's say that I want to render something like &lt;a href=&quot;http://fairlyoddparents.wikia.com/wiki/File:OddOddWest294.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dimmadome's hat&lt;/a&gt;, a hat which has the height of infinity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A quick answer to this would be to place the top side of the hat high enough for the crown(cylinder) to be cropped(like y=9999999...) half way in the view. I don't like this idea. So what I came up with is using &lt;a href=&quot;https://stackoverflow.com/questions/10435253/glsl-infinity-constant&quot;&gt;IEEE 754 infinity&lt;/a&gt; in vertices.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(-0.5, INF, -0.5)&#xA;(0.5, INF, -0.5)&#xA;(0.5, INF, 0.5)&#xA;(-0.5, INF, 0.5)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(assuming the crown is a cube)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that after multiplying with the transform matrix, the vertices end up being all &lt;code&gt;(INF, INF, INF)&lt;/code&gt;, making them unrenderable. I just wrote this to give you an idea.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any technique that can be used to achieve this? rather than using huge number? I wonder how they implemented &lt;a href=&quot;https://steamcommunity.com/sharedfiles/filedetails/?id=628176154&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerDisplayName="user8054" LastActivityDate="2018-09-15T00:11:56.263" Title="Infinitely long 3D model" Tags="&lt;3d&gt;&lt;model&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8012" PostTypeId="2" ParentId="8009" CreationDate="2018-09-03T17:01:34.620" Score="4" Body="&lt;p&gt;Core OpenGL has no mechanism for this. The &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_compute_variable_group_size.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_compute_variable_group_size&lt;/a&gt; extension provides such a feature. It doesn't allow for indirect compute operations though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It &lt;a href=&quot;http://opengl.gpuinfo.org/listreports.php?extension=GL_ARB_compute_variable_group_size&quot; rel=&quot;nofollow noreferrer&quot;&gt;doesn't seem to have much AMD support&lt;/a&gt; though (outside of open source Linux drivers). And Intel support is nil.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-09-03T17:01:34.620" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8013" PostTypeId="1" AcceptedAnswerId="8016" CreationDate="2018-09-03T20:07:01.420" Score="2" ViewCount="522" Body="&lt;p&gt;So I am in the midst of writing my own path traced renderer and right now I have only implemented the old Blinn-Phong models where we separately calculated the diffuse and specular components of the material and each object had a specular and a diffuse color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now going towards the more general side I want to be able to render different types of objects wood, polished wood, perfect mirror like reflections etc. However all this information confuses me on how should I implement these BSDFs or in other words how should I choose when to apply a certain BSDF or maybe a combination of two?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is usually done using a material approach. The material being diffuse, glossy or perfect specular would define which BSDFs should I use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read PBRT for clues and they break surface reflection into 4 types. Diffuse, Glossy Specular, Specular and retro reflective. Then they implement an &lt;code&gt;enum&lt;/code&gt; that stores the type corresponding to these reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The enum has the types&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;BSDF_REFLECTION&#xA;BSDF_TRANSMISSION&#xA;BSDF_DIFFUSE&#xA;BSDF_GLOSSY&#xA;BSDF_SPECULAR&#xA;BSDF_ALL&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;The users are supposed to select a bitwise combination of the first two and &#xA;the next 3 ones. Where &lt;code&gt;BSDF_ALL&lt;/code&gt; is a combination of&#xA;all the flags. This interface seems nice but there is one little&#xA;confusion. If &lt;code&gt;BSDF_ALL&lt;/code&gt; combines all flags, then this means the&#xA;surface can be &lt;code&gt;diffuse&lt;/code&gt; and &lt;code&gt;specular&lt;/code&gt;. However this seems odd, a&#xA;perfectly specular surface can't be diffuse. While &lt;code&gt;Glossy + Diffuse&lt;/code&gt; make &#xA;sense (polished wood, paint on a rough wall), &lt;code&gt;diffuse + specular&lt;/code&gt; and &#xA;&lt;code&gt;glossy + specular&lt;/code&gt; don't make sense to me.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Assuming we have solved the above problem consider an object that is &#xA;glossy+diffuse like an orange or lemon skin. How do we&#xA;calculate the color for this surface? Suppose I am using&#xA;&lt;a href=&quot;https://en.wikipedia.org/wiki/Oren%E2%80%93Nayar_reflectance_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;Oran-Nayar&lt;/a&gt; model (ON) for diffuse surfaces and&#xA;&lt;a href=&quot;https://en.wikipedia.org/wiki/Specular_highlight#Cook%E2%80%93Torrance_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cook-Torrance&lt;/a&gt; (CT) for specular ones. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I compute the diffuse component through ON and specular&#xA;through (CT) then add them together? However both of these models&#xA;have their own parameters which define the slope distribution for&#xA;microfacet. For ON that's $\sigma^2$, the variance of the Gaussian&#xA;distribution and for CT that's $m$, which wiki describes as &quot;RMS&#xA;slope of microfacets&quot; (check respective links). Which one of these&#xA;will govern the roughness of the surface?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Moving on further there is a more general question. In the older models such &#xA;as Blinn-Phong we used to have a separate diffuse and specular color. The &#xA;specular color, from what I understand is nothing more than the Fresnel &#xA;Reflectance. This is because Fresnel&#xA;reflectance is dependent on wavelength. In case of Dielectrics this&#xA;isn't discernable but for metals it usually is (gold gives of a&#xA;yellowish tint). Hence for dielectrics the specular color would just&#xA;be the plain old Fresnel reflectance replicated across RGB channels&#xA;while for metals this would be the color of the tint. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing that confuses me is the lingering concept of diffuse and&#xA;specular reflectivity. Consider Cook-Torrance's original paper where&#xA;they describe their model as.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R = dR_d + sR_s$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where $d$ and $s$ are the coeffecients for diffuse and specular&#xA;reflectivity respectively and they must hold the condition.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$d+s \leq 1$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$R_d$ is any diffuse BRDF (they assume lambertian) while $R_s$ is&#xA;their new proposed BRDF for specular surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's where my biggest confusion is. I was thinking the diffuse and&#xA;specular colors as the object's respective reflectivities in each&#xA;channel. The above equation however separates the color from&#xA;reflectivity. &lt;strong&gt;Which concept is used in PBR?&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-09-04T18:00:58.423" LastActivityDate="2018-09-04T20:20:28.243" Title="PBR - How to handle multiple BSDFs and material type" Tags="&lt;brdf&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8014" PostTypeId="1" CreationDate="2018-09-03T21:10:16.860" Score="3" ViewCount="333" Body="&lt;p&gt;For simplicity, assume we're only dealing with surfaces which have either a Lambertian or perfectly specular material. Morever, assume that the only type of lights are area lights (i.e. surfaces with an emissive material) and we stop tracing at lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In path tracing, we start by tracing a ray from the eye through a random point on the area of the view plane corresponding to the $i$th pixel. Now, depending on the BRDF of the hitted surface, we choose either a uniformly distributed direction on the hemisphere over the normal at the hit point (in the case of a Lambertian surface) or the direction of perfect mirror reflection (in the case of a perfectly specular surface). This process stops, when either no surface or a surface with an emissive material (i.e. an area light) was hit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Quesiton 1&lt;/strong&gt;: Now, PSSMLT constructs a sequence $(X_n)_{n\in\mathbb N}\subseteq[0,1]$. Actually, it's even clear to me how this sequence is modified by small step and large step modifications. However, what are the components $X_n$ exactly? Are $(X_1,X_2)$ the (normialized) coordinates of the randomly chosen area of the view plane corresponding to a pixel? If so, which pixel? And what is $(X_3,X_4)$? Maybe randomly chosen points on a unit square which need to be mapped to the hemisphere of the corresponding hit point? If so, we would need to store the normal and the BRDF together with $(X_3,X_4)$, don't we? And what if the surface which was hit has a perfectly specular material? Are then $(X_3,X_4)$ simply ignored?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 2&lt;/strong&gt;: I've read that initial sequence $(X_n)_{n\in\mathbb N}$ is chosen by approximating the &quot;luminance of path contribution&quot; which is said to be independent of the pixel. I don't get that at all. And I have no idea how it is approximated by using path tracing.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2018-11-03T00:01:45.747" Title="How does Primary Sample Space Metropolis Light Transport work?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8015" PostTypeId="2" ParentId="8014" CreationDate="2018-09-03T23:00:41.957" Score="1" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;PSSMT operates directly on the space of random numbers that generate valid light paths. As such, mutations in the unit hypercube &lt;em&gt;lose&lt;/em&gt; their physical interpretation since they do not have direct knowledge of the actual light path constructed. Recent research in rendering has shown that it is possible to bridge the gap between path space (that acts directly on the paths) and primary sample space (that acts on uniform variates) to some extent. See &lt;a href=&quot;https://benedikt-bitterli.me/rjmlt/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bitterli 2018&lt;/a&gt;, &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=3073677&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pantaleoni 2017&lt;/a&gt; and &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=3073691&quot; rel=&quot;nofollow noreferrer&quot;&gt;Otsu 2017&lt;/a&gt; if that interests you.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I am not entirely sure what you mean here, but typically an initial path of length $k$ will be formed using path tracing, and thus random numbers will be used along the way ($k+2$ if you are using BDPT). PSSMLT will mutate this path by acting only on the random numbers. Path throughput is indeed independent of the pixel but you only care about paths actually reaching the eye. At the end of the day, you are importance sampling paths according to their contribution to the final image, and luminance is what is commonly used. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6588" LastActivityDate="2018-09-03T23:00:41.957" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8016" PostTypeId="2" ParentId="8013" CreationDate="2018-09-03T23:23:25.243" Score="1" Body="&lt;p&gt;Although the specular term of the Cook-Torrance BRDF is widely used in Path Tracing, the original BRDF was meant initially for rasterization (it was proposed before the advent of Path Tracing). The idea of summing weighted diffuse and specular components (&lt;em&gt;i.e.&lt;/em&gt; $R=dR_d+sR_s, d + s \leq 1$) is not capable of representing the complex results that may emerge from the interaction between diffuse and specular material elements (e.g. refraction, Fresnel for plastics, etc).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Actually, a better physically based model for material representation would be that of layers. For instance, smooth and rough conductors could be modeled through a unique layer represented by the specular term of the Cook-Torrance BRDF. Smooth and rough dielectrics could be modeled through a unique BSDF. Plastics, on the other hand, could be modeled through the use two layers: the topmost layer representing a dielectric (a BSDF) and the second layer, underneath the dieletric, representing a diffuse material (e.g. a lambertian or Oren-Nayar BRDF). That two-layer setup for plastics is capable of simulating the Fresnel reflectance of plastics (through the dielectric layer), the plastic color (through the light reflected by the colored diffuse layer underneath the dielectric), the light absorbed by the dielectric (through the implementation of Beer's Law), etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The layer-based material model approximates quite well what actually happens in real life. I have already written a related answer, with more details, and that may help you (I've included some references in that answer): &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5761/5681&quot;&gt;https://computergraphics.stackexchange.com/a/5761/5681&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The original Cook-Torrance does not properly conserve energy (I've already posted a question about that &lt;a href=&quot;https://computergraphics.stackexchange.com/q/4394/5681&quot;&gt;here&lt;/a&gt;). In 2007, Walter &lt;em&gt;et al&lt;/em&gt;. have published the paper &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Microfacet Models for Refraction through Rough Surfaces&lt;/a&gt;, where they propose a Cook-Torrance based model amenable for Path Tracing. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding layered material, I've implemented the system presented in the paper by Weidlich and Wilkie, &#xA;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1321292&quot; rel=&quot;nofollow noreferrer&quot;&gt;Arbitrarily layered micro-facet surfaces&lt;/a&gt;, where a quite general layered material model is presented. After that, more sophisticated layered material models have been proposed. One of them is &#xA;&lt;a href=&quot;https://dl.acm.org/citation.cfm?id=2601139&quot; rel=&quot;nofollow noreferrer&quot;&gt;A comprehensive framework for rendering layered materials&lt;/a&gt;&#xA;, by Wenzel Jakob. There is a new paper (published in 2017, I think), that supports subsurface scattering for top layers (I will add it here when I find it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that PBRT uses layer-based materials too, but I do not know how they have actually implemented it.&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorDisplayName="user5681" LastEditDate="2018-09-04T20:20:28.243" LastActivityDate="2018-09-04T20:20:28.243" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8017" PostTypeId="1" CreationDate="2018-09-04T00:01:22.947" Score="8" ViewCount="2893" Body="&lt;p&gt;&lt;em&gt;Background:&lt;/em&gt;&lt;br&gt;&#xA;I found that it is very easy to use a linear depth buffer, using only a slight modification to the canonical vertex transformation. The simplest method is found at the bottom of &lt;a href=&quot;https://www.mvps.org/directx/articles/linear_z/linearz.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.mvps.org/directx/articles/linear_z/linearz.htm&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the caveat is that it only works for triangles that don't need to be clipped against the near or far planes. (And an alternate solution, of performing the perspective divide in the vertex shader, will yield a similar problem for the other four frustum planes.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because clipping requires linear interpolation to work across all four clip space coordinates, I think it's impossible to work with linear depth, using  only a vertex shader. But the reason for that is all down to Z being divided by W.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is that done? X and Y need to be divided by distance from the camera, but the Z coordinate does not, to fit perfectly into the NDC box.&lt;/p&gt;&#xA;" OwnerUserId="504" LastEditorUserId="504" LastEditDate="2018-09-08T00:27:07.297" LastActivityDate="2019-01-30T09:25:08.350" Title="Why do GPUs divide clip space Z by W, for position?" Tags="&lt;projections&gt;&lt;clipping&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8018" PostTypeId="1" AcceptedAnswerId="8020" CreationDate="2018-09-04T00:40:34.907" Score="1" ViewCount="107" Body="&lt;p&gt;I have a two different codes with a little difference  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Case 1. I used a + operator before _myColor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;void surf(Input IN, inout SurfaceOutput o) {&#xA;       o.Albedo = (tex2D(_myTexture, IN.uv_myTexture) + _myColor).rgb;&#xA;    }&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Case 2. I used a * operator before _myColor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;void surf(Input IN, inout SurfaceOutput o) {&#xA;       o.Albedo = (tex2D(_myTexture, IN.uv_myTexture) * _myColor).rgb;&#xA;    }&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In first case It gives bright color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QaAmi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QaAmi.png&quot; alt=&quot;Case 1&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in second case it gives very dark color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VzObL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VzObL.png&quot; alt=&quot;Case 2&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is why and how this is happening? &lt;/p&gt;&#xA;" OwnerUserId="9298" LastActivityDate="2018-09-04T03:11:59.103" Title="Difference between using + and * operator after tex2D to add albedo color?" Tags="&lt;shader&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8019" PostTypeId="2" ParentId="7994" CreationDate="2018-09-04T01:20:59.480" Score="2" Body="&lt;p&gt;I think you're seeing cache effects. The GPU will begin vertex processing for each strip in sequential order, and in configuration 1 the GPU will fetch a different chunk of memory for each triangle in the strip (since, as you said, the strips themselves are not contiguous in memory in this configuration).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I understand correctly, each entry in the ring buffer you are referring to is a triangle, so you will have at least 3 vertices adjacent to each other (in configuration 1). This has decent &lt;a href=&quot;https://en.wikipedia.org/wiki/Locality_of_reference&quot; rel=&quot;nofollow noreferrer&quot;&gt;spatial locality&lt;/a&gt;, but fetching this memory will probably also pull in memory for adjacent vertices, which won't be immediately useful (since it belongs to a different strip).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In configuration 2, the adjacent vertices &lt;em&gt;will&lt;/em&gt; be immediately useful, since they're the next vertices the GPU will need to render for the current triangle strip. The result is, probably, less total memory traffic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a somewhat simplified explanation (for example, it brushes over the parallelism occurring on the GPU), but it seems to match what you're observing. One way to justify the choice of configuration 2 over configuration 1 is that you're making it easier on the GPU at the cost of the CPU—however, the CPU has 1/MAX_AGE of the work to do as the GPU each frame, so optimizing for CPU updating (&quot;a concentrated chunk of memory is updated each frame&quot;) will be less valuable.&lt;/p&gt;&#xA;" OwnerUserId="196" LastActivityDate="2018-09-04T01:20:59.480" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8020" PostTypeId="2" ParentId="8018" CreationDate="2018-09-04T03:11:59.103" Score="0" Body="&lt;p&gt;In a shader, colors in the viewable range are assumed to be in the range 0 to 1. If you take a value that's between 0 and 1 and add a positive value to it, it will get brighter. However, if you take a value between 0 and 1 and multiply it by a value between 0 and 1, it will get darker. To understand, think about multiplying 0.5 by 0.5. The result is 0.25.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More generally, any value between 0 and 1 can be thought of as a percentage. 0.05 = 5%. 0.25  = 25%. So multiply any value between 0 and 1 by a percentage between 0 and 1, and it will be less than the original value. (50% of 50% is 25% in the earlier example.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have a photo editing application like Photoshop or GIMP, you can see the difference between the 2 by creating 2 layers with image data in them, and setting the blend mode of the top layer to either Add or Multiply. It's particularly revealing if you use a left-to-right gradient of black to white over the same gradient rotated 90°. You'll see how all the values react to the current blend mode.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-09-04T03:11:59.103" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8022" PostTypeId="2" ParentId="8017" CreationDate="2018-09-04T12:25:06.293" Score="13" Body="&lt;p&gt;If you are doing a perspective image and your model has implicit intersections then, if you use &quot;linear Z&quot;, those intersections will appear in the wrong places. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, consider a simple ground plane with a line of telephone poles, receding into the distance,  which pierce the ground (and continue below). The implicit intersections will be determined by the interpolated depth values. If those are not interpolated with &lt;code&gt;1/Z&lt;/code&gt;, then when the projected vertices have been computed with perspective, the image will look incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I apologise for the non-aesthetic quality of the following illustrations but I did them back in '97. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first image shows the required rendering effect. (Note that the blue &quot;pylons&quot; go quite a long distance under the ground plane so are clipped at the bottom of the images)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/E1PME.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/E1PME.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This second image shows the result of using a non-reciprocal depth buffer: (Apologies for the change of scale - these were copied out of an old MS Word doc and I've no idea what has happened with the scaling.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fouWc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fouWc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the results are incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On another note, are sure you &lt;em&gt;really&lt;/em&gt; want a linear Z representation? If you are rendering perspective, surely one wants more precision closer to the camera than at a distance?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Re your later comment:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;“if those are not interpolated with 1/Z” that I don’t understand. What interpolation is that?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The first thing to note is that, with a standard perspective projection, straight lines in world space remain straight lines in perspective space. Distances/lengths, however, are not preserved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For simplicity, let us assume a trivial perspective transform is used to project the vertices, i.e.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$X_{Screen} = \frac{X_{World}}{Z_{World}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$Y_{Screen} = \frac{Y_{World}}{Z_{World}}$$&lt;/span&gt;&#xA;We &lt;em&gt;should&lt;/em&gt; also compute a reciprocal screen-space depth, e.g. &lt;span class=&quot;math-container&quot;&gt;$$Z_{Screen} = \frac{1}{Z_{World}}$$&lt;/span&gt; but linear Z in the depth buffer would, to me, require something like: &lt;span class=&quot;math-container&quot;&gt;$$Z_{Screen} = scale*Z_{World}$$&lt;/span&gt; &lt;em&gt;(We can assume here that scale=1)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume we have a line with world space end points&lt;span class=&quot;math-container&quot;&gt;$$&#xA;  \begin{matrix} \begin{bmatrix}&#xA;    0 \\&#xA;    0 \\&#xA;    1 \\&#xA;    \end{bmatrix} and &#xA;   \begin{bmatrix}&#xA;    200 \\&#xA;    0   \\&#xA;    10  \\&#xA;    \end{bmatrix}\\&#xA;  \end{matrix}&#xA;$$&lt;/span&gt;&#xA;With the perspective mapping these map to screen space coordinates&#xA; &lt;span class=&quot;math-container&quot;&gt;$$ \begin{matrix}   \begin{bmatrix}&#xA;    0 \\&#xA;    0 \\&#xA;    1 \\&#xA;    \end{bmatrix} and \begin{bmatrix}&#xA;    20 \\&#xA;    0  \\&#xA;    0.1 \\&#xA;    \end{bmatrix}&#xA; \end{matrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The rendering system/hardware will linearly interpolate the screen space z, so at the 1/2 way point of the line, as it appears on-screen, i.e. at pixel (10, 0), we would get a projected (inverse) Z value of 0.55, which corresponds to to a world space Z value value of ~1.818. Given the starting and end Z values, this is about 20% along the length of the line.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If instead, we tried to interpolate using the original Z values, we'd end up with Z corresponding to a world space value of 5.5. As long as nothing intersects, you might be ok (I've not thought about it too thoroughly) but anything with implicit intersections &lt;em&gt;will&lt;/em&gt; be incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I haven't mentioned is that once you introduce perspective correct texturing (or even perspective correct shading), you must do per-pixel interpolation of 1/w and, additionally, also compute, per pixel, the reciprocal of that interpolated value.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-01-30T09:25:08.350" LastActivityDate="2019-01-30T09:25:08.350" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8023" PostTypeId="2" ParentId="8009" CreationDate="2018-09-04T13:03:35.783" Score="1" Body="&lt;p&gt;In addition to the more direct existing answer, there &lt;em&gt;is&lt;/em&gt; a way to work around this in unextended OpenGL to some degree, feeding from the fact that in contrast to CUDA OpenGL compute shaders are &lt;em&gt;not&lt;/em&gt; pre-compiled with application build (well, they &lt;em&gt;can&lt;/em&gt; nowadays, but aren't by default). Instead you &lt;em&gt;usually&lt;/em&gt; compile your compute shaders at some point during application runtime.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So a way to achieve a somewhat customizable workgroup size is to use a &lt;strong&gt;macro for it and then redefine this dynamically during application runtime but &lt;em&gt;before&lt;/em&gt; shader compile time&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(local_size_x = BLOCKSIZE) in;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And in the application all you have to do is prepend a &lt;code&gt;&quot;#define BLOCKSIZE &amp;lt;whatever&amp;gt;\n&quot;&lt;/code&gt; to the shader source string you feed into &lt;code&gt;glCompileShader&lt;/code&gt;. Of course in practice you have to care about stuff like the &lt;code&gt;#version&lt;/code&gt; directive being the first line in a shader. You could as well have the define in the shader code already (maybe with a meaningful default size) and do a text replacement instead. But you get the idea.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course this means &lt;strong&gt;recompiling your compute shader for each and every workgroup size&lt;/strong&gt; you're using. It's practically not much different from just having different shaders for each workgroup size. But at least it's a way to dynamically select the workgroup size during runtime while maintaining a single shader source.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2018-09-04T13:03:35.783" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8024" PostTypeId="2" ParentId="8007" CreationDate="2018-09-04T16:21:06.593" Score="1" Body="&lt;p&gt;Displays are already moving towards wider gamuts. I believe that newer iPhones, for example, are all P3 displays. So there is no doubt that sRGB usage will be replaced by wider gamuts in the future.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are really 2 important questions here:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Which gamuts will people end up using?&lt;/li&gt;&#xA;&lt;li&gt;When can/should we move our apps to using wider gamuts?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The answer to the first question will depend on the market. People have been pretty happy with sRGB for a few decades. P3 is better, but most consumers probably can't tell the difference. There are much wider gamuts like ACEScg, Rec. 2020, etc. Will it be affordable to move to those? If it is, will consumers care?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The answer to the second question depends entirely on what your target audience is using. If you can guarantee they're using devices with P3 displays (say, if you require the iPhone X's IR sensor), then you should move to P3. If your users are high-end users creating output for professional use, it's probably wise to move to P3. If your users need to create content that looks reasonably good on end-user devices like web pages rendered on aging machines, then it is probably a waste of effort to move away from sRGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that there is a cost to moving to a wider gamut. You will need to do significantly more work to ensure that all of your processing is done in the right color space because input images to your app will likely come in a variety of gamuts and you now have to convert them all to your working space, process them, and  then convert to the output space. That's not cheap to do and not easy to get right.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-09-04T16:21:06.593" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8027" PostTypeId="2" ParentId="8006" CreationDate="2018-09-04T23:46:36.673" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is there any 3D software that supports rendering an artificial scene to a light field image?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I took a look at Myst and &lt;a href=&quot;https://youtu.be/m2kKsFjZwx8?t=5m16s&quot; rel=&quot;nofollow noreferrer&quot;&gt;realMyst&lt;/a&gt;, and found this YouTube video: &quot;&lt;a href=&quot;https://youtu.be/e18brgSS_F0&quot; rel=&quot;nofollow noreferrer&quot;&gt;LightField synthesis &amp;amp; realtime render in Unity - sneak preview (raw footage)&lt;/a&gt;&quot; with accompanying background &lt;a href=&quot;https://www.reddit.com/r/oculus/comments/2qjqr3/i_got_lightfield_synthesis_and_rendering_working/&quot; rel=&quot;nofollow noreferrer&quot;&gt;introductory information from Frooxius on Reddit&lt;/a&gt;. You can see the pipeline he used to convert lightfields, though copying it may be a challenge. He has obtained pretty good results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the answer is yes.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I guess animations would be out almost of the question. It should at least in theory be easier to incorporate animations in cgi-light fields than in real photos.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's an interesting experiment but the scene is baked, adding characters or new objects will kind of look like cutting out one photograph and pasting onto another - thus what you hoped to gain in speed is lost trying to smooth the two scenes together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To walk into a scene and see a moving object you essentially need to create a dynamic 'lightfield movie' so the moving object can move normally and then you simply walk/look around the dynamic lightfield. That will be somewhat computationally intensive but most of all it will take a lot of memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check out Frooxius' video and let me know if that's the &lt;em&gt;look&lt;/em&gt; you were hoping for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This webpage: &quot;&lt;a href=&quot;https://www.fxguide.com/featured/light-fields-the-future-of-vr-ar-mr/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Light fields – the future of VR-AR-MR&lt;/a&gt;&quot; by Mike Seymour (May 26, 2015) says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&quot;The Octane renderer has plugins for a range of products from 3DsMax to Maya and even Nuke.&quot;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There's mention of OTOY and on their website the latest announced is: &quot;&lt;a href=&quot;https://home.otoy.com/unreal-engine-announcement-siggraph/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OTOY and Epic announce OctaneRender® 2019 for UnrealEngine 4&lt;/a&gt;&quot;, their &lt;a href=&quot;https://home.otoy.com/render/octane-render/demo/&quot; rel=&quot;nofollow noreferrer&quot;&gt;DEMO version&lt;/a&gt; is free, the least expensive paid version is U$400.&lt;/p&gt;&#xA;" OwnerUserId="9258" LastEditorUserId="9258" LastEditDate="2018-09-06T09:08:10.780" LastActivityDate="2018-09-06T09:08:10.780" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8028" PostTypeId="2" ParentId="4369" CreationDate="2018-09-05T07:35:56.257" Score="2" Body="&lt;p&gt;In the paper you referenced $f$ refers to the fraction of water covered by foam that modifies optical properties on the water’s surface. It is explained on page 256 in: &quot;&lt;a href=&quot;https://books.google.ca/books?id=WqDsCAAAQBAJ&amp;amp;pg=PA256&amp;amp;source=gbs_toc_r&amp;amp;cad=4#v=onepage&amp;amp;q=foam&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;Oceanic Whitecaps: Their Role in Air Sea Exchange Processes&lt;/a&gt;&quot; (1986), by E. Monahan and G. MacNiocaill.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;How could I generate the waves for a water body with whitecaps &amp;amp; foam and variable intensity of the waves? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There are more techniques for rendering oceans than there are oceans to render. Some are based on speed (with reasonable results) and some are based on accuracy. On the fourth page of &quot;&lt;a href=&quot;https://www.gamasutra.com/view/feature/131445/deep_water_animation_and_rendering.php?page=5&quot; rel=&quot;nofollow noreferrer&quot;&gt;Deep Water Animation and Rendering&lt;/a&gt;&quot; is a discussion of rendering foam, with the prior pages covering other calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maya has a number of preset demos that can be altered or you can start from scratch. See this YouTube tutorial &quot;&lt;a href=&quot;https://youtu.be/GixnCnb2mJI&quot; rel=&quot;nofollow noreferrer&quot;&gt;Crafting the Wave: How to Render an Ocean in Maya&lt;/a&gt;&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which of those references is more applicable depends on: if you simply want to understand more about it, if you are writing your own software, or if you want to render realistic oceans without necessarily knowing all the calculations behind it.&lt;/p&gt;&#xA;" OwnerUserId="9258" LastActivityDate="2018-09-05T07:35:56.257" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8029" PostTypeId="1" CreationDate="2018-09-05T13:43:58.493" Score="1" ViewCount="253" Body="&lt;p&gt;Let's say I have a cube map that has a resolution of 256x256 for each face and I want to generate mip maps for it using a box filter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's tempting to just mip each face individually, cutting the resolution of each face in half for each mip, by averaging each 2x2 group of pixels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing this, information never crosses the boundary of a cube map face though, which feels like it might be incorrect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the correct way to generate mips for a cube map?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2018-09-05T13:52:07.010" LastActivityDate="2018-09-05T13:52:07.010" Title="Generating Mip Maps For A Cube Map" Tags="&lt;texture&gt;&lt;mipmap&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8030" PostTypeId="1" AcceptedAnswerId="8031" CreationDate="2018-09-05T13:58:46.110" Score="2" ViewCount="1530" Body="&lt;p&gt;So I have a framebuffer image which later acts as input to a compute shader, and some frames there is geometry drawn to the framebuffer, but some frames this is not necessary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing is, in my current process, when I don't draw anything to that framebuffer, the image contents are undefined which leads to incorrect output of my compute shader.  So on frames where there is no geometry drawn, I would like to simply clear the framebuffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL this would be easy: &lt;code&gt;glClearColor(...)&lt;/code&gt; but so far I have not been able to get it working on Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried just doing an empty renderpass: i.e: &lt;code&gt;vkCmdBeginRenderPass&lt;/code&gt;/&lt;code&gt;vkCmdEndRenderpass&lt;/code&gt; with the correct clear values defined in the &lt;code&gt;VkRenderPassBeginInfo&lt;/code&gt; struct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also tried doing a renderpass with only &lt;code&gt;vkCmdClearAttachments&lt;/code&gt; between the bein/end commands.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I haven't had any luck.  What's the best way to accomplish this?&lt;/p&gt;&#xA;" OwnerUserId="9157" LastActivityDate="2018-09-05T16:13:01.913" Title="Best way to clear a framebuffer image without drawing?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8031" PostTypeId="2" ParentId="8030" CreationDate="2018-09-05T14:23:46.173" Score="5" Body="&lt;p&gt;You are looking for &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#clears-outside&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;vkCmdClearColorImage&lt;/code&gt;,&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It does exactly what it says on the tin, it clears an image to a specified color. This command uses the Transfer stage as far as barriers are concerned. You will need to add one between the clear and the &lt;code&gt;vkCmdDispatch&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is also a &lt;code&gt;vkCmdClearDepthStencilImage&lt;/code&gt; if you need it.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2018-09-05T16:13:01.913" LastActivityDate="2018-09-05T16:13:01.913" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8032" PostTypeId="1" CreationDate="2018-09-05T16:29:06.800" Score="2" ViewCount="261" Body="&lt;p&gt;In Chapter 14.5.3 of &lt;em&gt;Physically Based Rendering - From Theory to Implementation&lt;/em&gt; (3rd edition), the authors claim that a probability density $p_\omega$ according to solid angle can be converted to a density $p_A$ according to area by $$p_A=p_\omega\frac{\left|\cos\theta_i\right|}{\left|p_i-p_{i+1}\right|^2},\tag1$$ where $\theta_i$ is the angle between the surface normal at $p_{i+1}$ and the vector to $p_i$.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The problem is: $(1)$ doesn't make sense. If $p_\omega$ is a density with respect to the surface measure on the upper unit hemisphere $\Omega_{p_i}$ over $p_i$, then $p_\omega$ is by definition a function $\Omega_{p_i}\to[0,\infty]$. Analogously, if $p_A$ is supposed to be a density with respect to the surface measure on the manifold $M$ build by all surfaces in the scene, then $p_A$ is by definition a function $M\to[0,\infty]$.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;So, there's at least an argument transformation missing. I would really appreciate, if anybody could clarify.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2018-09-08T16:15:33.160" Title="How can we convert a probability density according to solid angle to a density according to area?" Tags="&lt;raytracing&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="8033" PostTypeId="1" AcceptedAnswerId="8036" CreationDate="2018-09-05T21:16:50.217" Score="4" ViewCount="845" Body="&lt;p&gt;I made an audio visualizer using Unity3D (you can see it &lt;a href=&quot;https://www.youtube.com/watch?v=s8ORkq8ZR3Q&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;here&quot;&gt;here&lt;/a&gt;) but I am not satisfied on the video quality, as the compression destroys the graphics. I recorded the screen during a real-time rendering. I tried many screen recorders, but always the same disappointment. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to try another approach, using non real-time rendering. I know Unity is made for real time rendering, but do you know if such a thing is possible ?&lt;/p&gt;&#xA;" OwnerUserId="9307" LastActivityDate="2018-09-07T08:20:45.620" Title="Non real-time rendering on Unity3D" Tags="&lt;rendering&gt;&lt;unity&gt;&lt;video&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8034" PostTypeId="1" CreationDate="2018-09-06T09:43:28.607" Score="4" ViewCount="451" Body="&lt;p&gt;I have created a quite large point cloud with about 800M RGB points. The exported .ply file is about 12GB large.&#xA;The commercial software I used to create it can render the cloud very smoothly on my Ryzen 1800X/64GB/Geforce 1080Ti.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I would like to work with this point cloud - programmatically put trajectories into it, combine multiple clouds, have more control over the point size ...&#xA;Expectedly, using PyntCloud in a Jupyter Notebook failed miserably :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before I start learning something like Unity, are there any better suggestions? Potree maybe?&#xA;Due to my lack of experience, I cannot judge yet where I would have which possibilities for working with the data.&lt;/p&gt;&#xA;" OwnerUserId="9309" LastEditorUserId="9309" LastEditDate="2018-09-06T09:48:46.020" LastActivityDate="2018-10-09T03:00:25.187" Title="How to visualize and programmatically work with huge point cloud" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8036" PostTypeId="2" ParentId="8033" CreationDate="2018-09-07T08:20:45.620" Score="5" Body="&lt;p&gt;Yes, there's a better approach than using a screen recorder. You can capture frames directly inside Unity, using &lt;a href=&quot;https://docs.unity3d.com/ScriptReference/ScreenCapture.CaptureScreenshot.html&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;ScreenCapture.CaptureScreenshot&lt;/code&gt;&lt;/a&gt;. There's a choice of formats to save as, and you can use PNG so that, when you later assemble the frames into a video (using ffmpeg or another tool), you have full control over how much compression to use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This function is very slow, because it reads back the framebuffer, encodes the image, and writes it to disk, all in the main thread. You may want to use it in combination with setting the &lt;a href=&quot;https://docs.unity3d.com/ScriptReference/Time-captureFramerate.html&quot; rel=&quot;noreferrer&quot;&gt;&lt;code&gt;Time.captureFramerate&lt;/code&gt;&lt;/a&gt; value. This setting lets you slow down Unity by completely disconnecting the in-game frame rate from real time. That is, if you set it to 30, the game will run at 30 fps as measured by &lt;code&gt;Time.deltaTime&lt;/code&gt; and the calls to &lt;code&gt;Update&lt;/code&gt; on your components, regardless of whether a frame takes a millisecond or a minute as measured by wall-clock time.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-09-07T08:20:45.620" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8037" PostTypeId="1" AcceptedAnswerId="8038" CreationDate="2018-09-07T16:24:49.147" Score="3" ViewCount="62" Body="&lt;p&gt;I have two RGBA colors in linear [0..1] space, &lt;code&gt;src&lt;/code&gt; and &lt;code&gt;dst&lt;/code&gt; and I want to alpha blender &lt;code&gt;src&lt;/code&gt; over/under &lt;code&gt;dst&lt;/code&gt; n times. Of course, I could call the respective operation n times using the result from the previous one (which is what I am currently doing), but I want to optimize it into a single operation. I think just calculating the correct alpha on &lt;code&gt;src&lt;/code&gt; should be sufficient, but I may be wrong. Here's what I currently use:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static final Color alphaOver(Color dst, Color src) {&#xA;    float src1A = 1 - src.a;&#xA;    float outA = src.a + dst.a * src1A;&#xA;&#xA;    if (outA == 0)&#xA;        return Color.TRANSPARENT;&#xA;    return new Color(&#xA;            outA,&#xA;            (src.r * src.a + dst.r * dst.a * src1A) / outA,&#xA;            (src.g * src.a + dst.g * dst.a * src1A) / outA,&#xA;            (src.b * src.a + dst.b * dst.a * src1A) / outA);&#xA;}&#xA;&#xA;public static final Color alphaUnder(Color dst, Color src) {&#xA;    return alphaOver(src, dst);&#xA;}&#xA;&#xA;public static final Color alphaOver(Color dst, Color src, int times) {&#xA;    Color ret = dst;&#xA;    for (int i = 0; i &amp;lt; times; i++)&#xA;        ret = alphaOver(ret, src);&#xA;    return ret;&#xA;}&#xA;&#xA;public static final Color alphaUnder(Color dst, Color src, int times) {&#xA;    Color ret = dst;&#xA;    for (int i = 0; i &amp;lt; times; i++)&#xA;        ret = alphaUnder(ret, src);&#xA;    return ret;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How can I optimize the last two functions?&lt;/p&gt;&#xA;" OwnerUserId="6092" LastActivityDate="2018-09-08T05:28:58.053" Title="Repeating alpha over/under operation multiple times" Tags="&lt;color&gt;&lt;blending&gt;&lt;alpha&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8038" PostTypeId="2" ParentId="8037" CreationDate="2018-09-07T20:28:32.237" Score="1" Body="&lt;p&gt;So taking source over as an example, the math works out to:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;dst = a * src + (1 - a) * dst&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Taking Nathan Reed's suggestion of replacing &lt;code&gt;(1 - a)&lt;/code&gt; with &lt;code&gt;b&lt;/code&gt;, that gives us:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;dst = a * src + b * dst&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If we perform the next iteration, it becomes:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;dst = a * src + ab * src + b^2 * dst&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Doing it again, we get:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;dst = a * src + ab * src + ab^2 * src + b^3 * dst&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And then:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;dst = a * src + ab * src + ab^2 * src + ab^3 * src + b^4 * dst&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The pattern appears to be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int exponent;&#xA;for (exponent = 0; exponent &amp;lt; numIterations; exponent++)&#xA;{&#xA;    newDst += a * pow(b, exponent) * src;&#xA;}&#xA;newDst += pow(b, exponent) * dst;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2018-09-08T05:28:58.053" LastActivityDate="2018-09-08T05:28:58.053" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="8039" PostTypeId="2" ParentId="8032" CreationDate="2018-09-08T16:15:33.160" Score="1" Body="&lt;p&gt;I don't understand what's the problem. We want to make a change of variables so that instead of integrating over the range of directions $d\omega_i$ in the upper hemisphere we integrate over patches of area $dA$ of a region $R$.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This whole thing is given in section 5.5 as Hubble said but let me post it again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We know by definition that,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$\omega = A *  cos(\theta)/r^2$  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you differentiate this, you get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$d\omega = dA * cos(\theta) / r^2$ &lt;/p&gt;&#xA;&#xA;&lt;p&gt;where,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$Jacobian = cos(\theta) / r^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as Hubble said. I don't know what are you trying to do by calculating Jacobian through determinant but as far as I know, that Jacobian determinant is for multi-variables and involves partial derivatives. For change of variables involving a single variable the Jacobian can be gotten by simply derivating as I did.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now this might seem the inverse but wait a moment. What you posted in the question is a relation between the PDFs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider a single sample of the rendering equation integrated over the domain of $\omega_i$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_s = BRDF * L_f * (\omega_i . n) / p(\omega)  $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After changing the domain by above equations this would become&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_s = BRDF * L_f * (\omega_i . n) (\omega_i . n_r)\, / \,  (p(A) * r^2)  $&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$L_s = BRDF * L_f * (\omega_i . n) * JN\, / \,  p(A) $&lt;br&gt;&#xA;where $Jacobian = JN$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means, &#xA;$ 1 / p(\omega) =  JN/p(A)$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ p(A) = p(\omega) * JN$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$ p(A) = p(\omega) * cos(\theta)/r^2$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what you see above. Simple as ****.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-09-08T16:15:33.160" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8040" PostTypeId="2" ParentId="8034" CreationDate="2018-09-09T02:19:40.630" Score="1" Body="&lt;p&gt;Depends how 'deep' you want to go.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With Unity/Unreal doesn't have to be 'programatically' - they do have GUI, you can just load your data with few button clicks. Potentially you could parse/convert your data to readable format &lt;a href=&quot;https://programminglinuxgames.blogspot.com/2010/09/parsing-wavefront-obj-file-format-using.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;obj might be easiest&lt;/a&gt; with for eg. python.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So not sure what programming language you have in mind but as you are mentioning some python modules I guess python.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you could display it in many different ways.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://pypi.org/project/PyOpenGL/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL&lt;/a&gt; (there are many Python bindings over the internet, check them out and choose one that suits you best)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://matplotlib.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Matplot&lt;/a&gt;, &lt;a href=&quot;https://github.com/pyqtgraph/pyqtgraph&quot; rel=&quot;nofollow noreferrer&quot;&gt;pygraph&lt;/a&gt; and similar also have an ability to plot in 3D&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;explore &lt;a href=&quot;https://pandas.pydata.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;pandas&lt;/a&gt; as it is a great python library to deal with this types of datas&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;And for eg. you could put it all together inside a &lt;a href=&quot;https://pythonspot.com/pyqt5/&quot; rel=&quot;nofollow noreferrer&quot;&gt;QT&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7012" LastActivityDate="2018-09-09T02:19:40.630" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8041" PostTypeId="2" ParentId="8017" CreationDate="2018-09-09T04:49:52.037" Score="6" Body="&lt;p&gt;Using Z/W for the depth buffer goes deeper than just clipping against the near and far planes. As Simon alluded to, this has to do with interpolation between the vertices of a triangle, during rasterization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Z/W is the unique option that allows NDC depth values to be correctly calculated for points in the interior of the triangle, by simply linearly interpolating the NDC depth values from the vertices, &lt;em&gt;in screen space&lt;/em&gt;. In principle, we could use any function we like to map camera-space Z to the depth buffer value—but any other choice than Z/W would require more complicated math to be done per pixel, which would be slower, and more difficult to build in hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that if you use a linear depth buffer, then of course linearly interpolating depth values will be correct in &lt;em&gt;world&lt;/em&gt; space...but not, in general, in screen space! And it is screen space that matters for rasterization, as we need to be able to generate perspective-correct depth values (and other attribute values, like UVs) for each pixel center, or other sample point, within the screen-space bounds of a triangle being rasterized.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-09-09T04:49:52.037" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8043" PostTypeId="2" ParentId="7984" CreationDate="2018-09-10T02:11:35.150" Score="3" Body="&lt;p&gt;This looks like a case of 16bit truncation in your indice buffer. For a 257x257 grid you will be addressing more than 65536 vertices so you will need to use a 32bit indice buffer.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.drawElements(gl.TRIANGLE_STRIP, buffers.numIndices, gl.UNSIGNED_SHORT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;change to :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.drawElements(gl.TRIANGLE_STRIP, buffers.numIndices, gl.UNSIGNED_INT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also change your buffer allocation code to match this type (Uint16Array -&gt; Uint32Array for Javascript).&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2018-09-11T02:59:56.690" LastActivityDate="2018-09-11T02:59:56.690" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8044" PostTypeId="1" CreationDate="2018-09-10T10:55:04.877" Score="2" ViewCount="186" Body="&lt;p&gt;I've spent about 2 days trying to understand this piece of code (from &lt;a href=&quot;https://github.com/nilx/megawave/blob/master/src/image/domain/fproj.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;) that applies an affine/projective transformation to an image. I will link bits of the code that I'm struggling to understand and add comments on what I think it's trying to do. In particular, the author's original comments I'll label as &lt;code&gt;//&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//      COMPUTE NEW BASIS&#xA;// X1, Y1 : upleft corner&#xA;// X2, Y2 : upright corner&#xA;// X3, Y3 : downleft corner &#xA;// sx     : x-size of output image&#xA;// sy     : y-size of output image&#xA;x12 = (X2-X1)/(float)(*sx); &#xA;y12 = (Y2-Y1)/(float)(*sx);&#xA;x13 = (X3-X1)/(float)(*sy);&#xA;y13 = (Y3-Y1)/(float)(*sy);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Q1. I can see that this part as the comment says, finds a new normalized basis but I'm unsure exactly why we need to find one to model an affine transformation?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// x4, y4 : downright corner (for projective transform)&#xA;&#xA;if (y4) &#xA;{ &#xA;    xx=((x4-X1)*(Y3-Y1)-(y4-Y1)*(X3-X1))/((X2-X1)*(Y3-Y1)-(Y2-Y1)*(X3-X1));&#xA;    yy=((x4-X1)*(Y2-Y1)-(y4-Y1)*(X2-X1))/((X3-X1)*(Y2-Y1)-(Y3-Y1)*(X2-X1));&#xA;    a = (yy-1.0)/(1.0-xx-yy);&#xA;    b = (xx-1.0)/(1.0-xx-yy);&#xA;} &#xA;else &#xA;{&#xA;    a=b=0.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After doing some internet search, I manage to find equations from &lt;a href=&quot;http://paulbourke.net/geometry/pointlineplane/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; that the &lt;code&gt;xx&lt;/code&gt; and &lt;code&gt;yy&lt;/code&gt; equations solve for the &quot;intersection point of two line segments in 2 dimensions&quot;. An image will be linked below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;START IMAGE.&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ANCv2m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ANCv2m.png&quot; alt=&quot;Intersection of two lines&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;END IMAGE.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Q2. I don't understand how he uses the &lt;code&gt;xx&lt;/code&gt; and &lt;code&gt;yy&lt;/code&gt; equations to solve for a &amp;amp; b? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Q3. I am unsure of what &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; are. My best guess is that they are the bottom row of a projective transformation matrix shown below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;a_{11} &amp;amp; a_{12} &amp;amp; a_{13} \\&#xA;a_{21} &amp;amp; a_{22} &amp;amp; a_{23} \\&#xA;a &amp;amp; b &amp;amp; 1 \\&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is because the code sets &lt;code&gt;a = b = 0.0&lt;/code&gt; if we're not doing a projective transform, which should then make it an affine transformation matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now is where the main loop happens:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (x=0;x&amp;lt;sx;x++) &#xA;    for (y=0;y&amp;lt;sy;y++) {&#xA;        fx = (float)x + 0.5;&#xA;        fy = (float)y + 0.5;&#xA;        d = a*fx/(float)(*sx)+b*fy/(float)(*sy)+1.0;&#xA;        xx = (a+1.0)*fx/d;&#xA;        yy = (b+1.0)*fy/d;&#xA;        xp = X1 + xx*x12 + yy*x13;&#xA;        yp = Y1 + xx*y12 + yy*y13;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Q4. Why does he add 0.5 to the original x and y coordinate? My best guess is that the code's trying to map the centre of each pixel rather than the edge to the new image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vnPXU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vnPXU.png&quot; alt=&quot;Pixels&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Q5. In &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;d = a*fx/(float)(*sx)+b*fy/(float)(*sy)+1.0;&#xA;xx = (a+1.0)*fx/d;&#xA;yy = (b+1.0)*fy/d;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;what are they trying to accomplish here? My best guess is that &lt;code&gt;d&lt;/code&gt; is the third component of the output homogeneous coordinate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;xx\\&#xA;yy\\&#xA;d\\&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;calculated from the dot product of the third row of the (now normalised) transformation matrix from earlier and the input homogeneous vector:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;\frac{a}{sx} &amp;amp; \frac{b}{sy} &amp;amp; 1 \\    &#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;fx\\&#xA;fy\\&#xA;1\\&#xA;\end{bmatrix}&#xA;=&#xA;a*fx/sx+b*fy/sy+1.0&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the division&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;xx = (a+1.0)*fx/d;&#xA;yy = (b+1.0)*fy/d;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;would just transform the homogeneous coordinates back to Euclidean coordinates, corresponding to the output image pixel location. I noted that if &lt;code&gt;a=b=0.0&lt;/code&gt; (so not projective), then &lt;code&gt;(a+1.0)=(b+1.0)=d=1.0&lt;/code&gt;. I'm however not sure about why we have to multiply by &lt;code&gt;(a+1.0)&lt;/code&gt; or &lt;code&gt;(b+1.0)&lt;/code&gt;. But again, I do not know if I'm on the right track or not as I do not have anyone to help me with this code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Q7. The final operation&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;xp = X1 + xx*x12 + yy*x13;&#xA;yp = Y1 + xx*y12 + yy*y13;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I suppose is literally the dot product of the first two rows of the transformation matrix with the Euclidean coordinates as so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;$$&#xA;\begin{bmatrix}&#xA;x12 &amp;amp; x13 &amp;amp; X_{1} \\ &#xA;y12 &amp;amp; y13 &amp;amp; Y_{1}  &#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;xx\\&#xA;yy\\&#xA;1\\&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;xp\\&#xA;yp\\&#xA;\end{bmatrix}&#xA;$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which brings me to my question, how does this achieve an affine transformation? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect my lack of formal training could be why I'm not understanding how the code models an affine transformation. I'd appreciate some light shed on this piece of code!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cheers!&lt;/p&gt;&#xA;" OwnerUserId="9322" LastEditorUserId="9322" LastEditDate="2018-09-10T12:59:28.803" LastActivityDate="2019-07-20T22:01:50.260" Title="Deciphering Affine/Projective Transformation Code" Tags="&lt;transformations&gt;&lt;algorithm&gt;&lt;affine-transformations&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8045" PostTypeId="1" CreationDate="2018-09-10T12:13:39.607" Score="2" ViewCount="145" Body="&lt;p&gt;In Metropolis Light Transport, we need to approximate the integral of the measurement contribution function. I've read that this can be done using a traditional approach like path tracing. However, how exactly do we need to implement this approximation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read the explanation in PBR3, but I still don't understand how this approximation is done exactly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More precisely, let's make the following definitions (ignoring rigor): Let $M\subseteq\mathbb R^3$ denote the scene surfaces, $\sigma_M$ denote the surface measure on $M$, $$\Omega_n:=\left\{x\in M^{\mathbb N_0}:x_i\ne x_j\text{ for all }0\le i&amp;lt;j\le n\text{ and }x_N=x_n\text{ for all }N\ge n\right\}$$ $$\iota_n:\Omega_n\to M^{\left\{0,\:\ldots\:,\:n\right\}}\;,\;\;\;x\mapsto(x_0,\ldots,x_n)$$ $$\mu_n(A):=\sigma_M^{\otimes\left\{0,\:\ldots\:,\:n\right\}}(\iota_n(A))\;\;\;\text{for }A\subseteq\Omega_n$$ $$\Omega:=\biguplus_{n\in\mathbb N}\Omega_n$$ $$\mu(A):=\sum_{n=1}^\infty\mu_n(A\cap\Omega_n)\;\;\;\text{for }A\subseteq\Omega$$ Moreover, with the usual notation, let $$T(x_0,\ldots,x_n):=\prod_{i=1}^{n-1}f_r(x_{i+1}\to x_i\to x_{i-1})G(x_i\leftrightarrow x_{i+1})$$ $$f(x):=L_e(x_n\to x_{n-1})T(x_0,\ldots,x_n)\;,\;\;\;\text{if }x\in\Omega_n$$ $$h_j(x):=G(x_0\leftrightarrow x_1)W_e^{(j)}(x_0\to x_1)$$ Then, the measurement $I_j$ of the $j$th pixel is $$I_j=\int fh_j\:{\rm d}\mu.$$&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the question is: How exactly is $$b:=\int f\:{\rm d}\mu$$ approximated using (unidirectional) path tracing?&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2018-09-11T18:00:35.210" LastActivityDate="2018-09-11T18:00:35.210" Title="How do we approximate the integral of the measurement contribution function in Metropolis Light Transport?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8046" PostTypeId="1" CreationDate="2018-09-10T13:28:39.117" Score="0" ViewCount="86" Body="&lt;p&gt;More of a question about what's possible in DX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some people have reported that when running games on higher settings they get less CPU load but when dropping the settings the CPU load increases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What would be causing increased CPU load in these cases? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Someone suggested that the DirectX API falls back to software when certain features are turned off, but is this something that can happen - can DirectX do a mixed render where some stuff in the render pipeline is pushed through the CPU and the rest goes to the GPU?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My thoughts were texture quality and downsampling and potentially physics processing not being offloaded but does anyone actually know what the cause might be?&lt;/p&gt;&#xA;" OwnerUserId="9325" LastActivityDate="2018-09-10T13:56:58.903" Title="CPU load in games - what is the GPU/DirectX doing to make CPU load higher?" Tags="&lt;directx&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8047" PostTypeId="2" ParentId="8046" CreationDate="2018-09-10T13:56:58.903" Score="3" Body="&lt;p&gt;The most likely explanation is that the game is GPU-bounded and not running at a fixed frame rate. If reducing the quality in the settings allows the game to reach a higher frame rate, the GPU load will be the same, but the CPU load will increase: the CPU is doing the same amount of work per frame (or possibly less), but there are more frames per second, so the total amount of CPU work per second increases. If the game does some non-graphics work per frame as well (for example, if physics updates are at the same rate, or if input is polled once per frame), the effect will be even greater.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Forcing rendering to a fixed frame-rate would allow a controlled comparison.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your hypothesis about software emulation of features may apply to some features in some games. A particular hardware feature might be exposed as an option because it's slow on some GPUs, and turning the feature off uses a CPU implementation in the game instead. If you have more specific questions about that, be sure to ask a new question which includes the source code you're working on and the benchmark results.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-09-10T13:56:58.903" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8048" PostTypeId="2" ParentId="8045" CreationDate="2018-09-10T15:59:17.943" Score="1" Body="&lt;p&gt;This approximation is typically done by running a bidirectional path tracer with a modest amount of samples per pixel. This means multiple paths per pixel to approximate the integral of $f_j$, the measurement contribution function. &lt;a href=&quot;https://graphics.stanford.edu/papers/metro/metro.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Veach's original MLT paper&lt;/a&gt; explains how it can be done in a way that eliminates start-up bias (see Section 5.1).&lt;/p&gt;&#xA;" OwnerUserId="6588" LastEditorUserId="6588" LastEditDate="2018-09-10T20:40:33.350" LastActivityDate="2018-09-10T20:40:33.350" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8049" PostTypeId="1" AcceptedAnswerId="8056" CreationDate="2018-09-11T16:03:36.047" Score="1" ViewCount="69" Body="&lt;p&gt;I am reading the percentage closer filtering (PCF) paper by Reeves, W. et al. (&lt;a href=&quot;https://graphics.pixar.com/library/ShadowMaps/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://graphics.pixar.com/library/ShadowMaps/paper.pdf&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At at section 3.2, it mentioned that &quot;each shading calculation represents some region on a surface&quot;. And &quot;each region to be shaded is mapped to a region in the shadow map&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For my understanding, using Opengl fragment shader, for each shading calculation, we just operate on each pixel. We do the shadow calculation on each pixel in the camera image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone explain what does that &quot;region to be shaded&quot; mean? Thanks!&lt;/p&gt;&#xA;" OwnerUserId="8826" LastActivityDate="2018-09-12T17:42:20.953" Title="What does &quot;region to be shaded&quot; mean in the PCF paper?" Tags="&lt;opengl&gt;&lt;shading&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8051" PostTypeId="2" ParentId="4597" CreationDate="2018-09-11T22:34:39.573" Score="1" Body="&lt;p&gt;You have a background color and the color of your line, an antialiased line has additional lines drawn on either side of the first that are simply part way between the color and brightness of your origonal line and the background.&lt;/p&gt;&#xA;&lt;p&gt;If the line you are drawing is horizontal or vertical the additional antialiasing lines (however many, depending upon the intended resulting line thickness) should be closer in color and brightness to the intended color - there is absolutely minimal antialiasing on such lines, that there is a tiny amount is due to offset &lt;a href=&quot;https://en.wikipedia.org/wiki/Subpixel_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;subpixel rendering&lt;/a&gt; on &lt;em&gt;&lt;strong&gt;some&lt;/strong&gt;&lt;/em&gt; but not all matrixes.&lt;/p&gt;&#xA;&lt;p&gt;This shows the difficulty:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iBhZr.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iBhZr.jpg&quot; alt=&quot;Subpixels Matrix&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;When the lines are not horizontal or vertical it gets more complicated ...&lt;/p&gt;&#xA;&lt;p&gt;If the additional lines drawn on each side of your line are drawn:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;with color and brightness more &lt;strong&gt;closely matching the background's color&lt;/strong&gt; then your &lt;strong&gt;line remains sharper&lt;/strong&gt; and the &lt;strong&gt;background color near your line is fuzzier&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;with color and brightness more &lt;strong&gt;closely matching your line's color&lt;/strong&gt; then your &lt;strong&gt;line becomes fuzzier&lt;/strong&gt; (wider) and the &lt;strong&gt;background color near your line remains sharper&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;That means that if you intend to draw a thin line, a single pixel wide line, you would use the first option. (Make the result skinny).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you want a two pixel wide line you would choose the second option but weigh the color of the background more towards the background's color and brightness. (Make the result not as skinny as a single line, with each of the two additional lines forming almost ~50% of the total width).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you want a three pixel wide line you still use the second option but would instead weigh the color of the background more towards the line's color and brightness. (Make the result clearly much fatter than a single line).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;For a four pixel wide line go back to the first method where you draw two lines of the intended color and brightness surrounded by two lines using the second method, making the two lines wider. (Sort of a blending of the first and second methods)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;For five pixel wide lines the center is exactly your intended color, the two nearest surrounding line are very close to the color and brightness of the center line, with the outer two fairly close to the color of the center line (but less than the ones immediately next to the center line)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;For a six pixel wide line there are two central lines of the intended drawing color and brightness, surrounded by two very similar lines, surrounded by another two less similar to the central two's color and brightness; but still very different from (lighter or darker) than the background color.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A seven pixel line or greater follows number 5 or 6 above.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The weighing of the additional lines more towards the intended color gives a sharper line, if you thought of it from a sideview analogy it would be top hat shaped. If you weighed additional lines more towards the background color the  (impossible) sideview analogy is that the profile of the 2D line would be rounded or triangular. If you are drawing 2D shapes it is in your interest to weigh towards the intended color. If you are rendering a 3D shape on a 2D screen then favoring the background color blends towards subsequent lines of a different Z depth.&lt;/p&gt;&#xA;&lt;p&gt;A &lt;strong&gt;simplistic&lt;/strong&gt; but effective algorithm with good speed is the &lt;a href=&quot;http://www.ece.mcmaster.ca/%7Exwu/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Xiaolin Wu&lt;/a&gt; improvement to Bresenham's line drawing &lt;a href=&quot;https://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;algorithm to implement antialiasing&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Pascal&#xA;function plot(x, y, c) is&#xA;    plot the pixel at (x, y) with brightness c (where 0 ≤ c ≤ 1)&#xA;&#xA;// integer part of x&#xA;function ipart(x) is&#xA;    return floor(x)&#xA;&#xA;function round(x) is&#xA;    return ipart(x + 0.5)&#xA;&#xA;// fractional part of x&#xA;function fpart(x) is&#xA;    return x - floor(x)&#xA;&#xA;function rfpart(x) is&#xA;    return 1 - fpart(x)&#xA;&#xA;function drawLine(x0,y0,x1,y1) is&#xA;    boolean steep := abs(y1 - y0) &amp;gt; abs(x1 - x0)&#xA;    &#xA;    if steep then&#xA;        swap(x0, y0)&#xA;        swap(x1, y1)&#xA;    end if&#xA;    if x0 &amp;gt; x1 then&#xA;        swap(x0, x1)&#xA;        swap(y0, y1)&#xA;    end if&#xA;    &#xA;    dx := x1 - x0&#xA;    dy := y1 - y0&#xA;    gradient := dy / dx&#xA;    if dx == 0.0 then&#xA;        gradient := 1.0&#xA;    end if&#xA;&#xA;    // handle first endpoint&#xA;    xend := round(x0)&#xA;    yend := y0 + gradient * (xend - x0)&#xA;    xgap := rfpart(x0 + 0.5)&#xA;    xpxl1 := xend // this will be used in the main loop&#xA;    ypxl1 := ipart(yend)&#xA;    if steep then&#xA;        plot(ypxl1,   xpxl1, rfpart(yend) * xgap)&#xA;        plot(ypxl1+1, xpxl1,  fpart(yend) * xgap)&#xA;    else&#xA;        plot(xpxl1, ypxl1  , rfpart(yend) * xgap)&#xA;        plot(xpxl1, ypxl1+1,  fpart(yend) * xgap)&#xA;    end if&#xA;    intery := yend + gradient // first y-intersection for the main loop&#xA;    &#xA;    // handle second endpoint&#xA;    xend := round(x1)&#xA;    yend := y1 + gradient * (xend - x1)&#xA;    xgap := fpart(x1 + 0.5)&#xA;    xpxl2 := xend //this will be used in the main loop&#xA;    ypxl2 := ipart(yend)&#xA;    if steep then&#xA;        plot(ypxl2  , xpxl2, rfpart(yend) * xgap)&#xA;        plot(ypxl2+1, xpxl2,  fpart(yend) * xgap)&#xA;    else&#xA;        plot(xpxl2, ypxl2,  rfpart(yend) * xgap)&#xA;        plot(xpxl2, ypxl2+1, fpart(yend) * xgap)&#xA;    end if&#xA;    &#xA;    // main loop&#xA;    if steep then&#xA;        for x from xpxl1 + 1 to xpxl2 - 1 do&#xA;           begin&#xA;                plot(ipart(intery)  , x, rfpart(intery))&#xA;                plot(ipart(intery)+1, x,  fpart(intery))&#xA;                intery := intery + gradient&#xA;           end&#xA;    else&#xA;        for x from xpxl1 + 1 to xpxl2 - 1 do&#xA;           begin&#xA;                plot(x, ipart(intery),  rfpart(intery))&#xA;                plot(x, ipart(intery)+1, fpart(intery))&#xA;                intery := intery + gradient&#xA;           end&#xA;    end if&#xA;end function&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9258" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-09-11T22:34:39.573" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8052" PostTypeId="1" AcceptedAnswerId="8054" CreationDate="2018-09-12T02:21:51.167" Score="12" ViewCount="477" Body="&lt;p&gt;For example, Filament's documentation at &lt;a href=&quot;https://google.github.io/filament/Filament.md.html&quot; rel=&quot;noreferrer&quot;&gt;https://google.github.io/filament/Filament.md.html&lt;/a&gt; uses the term &quot;dielectrics&quot; when contrasting nonconductors to conductors, which it calls &quot;metallics&quot;. And here on stackexchange, &lt;a href=&quot;https://computergraphics.stackexchange.com/search?page=2&amp;amp;tab=Relevance&amp;amp;q=dielectric&quot;&gt;https://computergraphics.stackexchange.com/search?page=2&amp;amp;tab=Relevance&amp;amp;q=dielectric&lt;/a&gt; also produces many hits for &quot;dielectric&quot;. I would have normally expected the word &quot;insulator&quot; in these instances. Does &quot;dielectric&quot; stem from some historical source, or is it the accurate term to use?&lt;/p&gt;&#xA;" OwnerUserId="9334" LastActivityDate="2018-09-14T14:53:43.573" Title="Why does graphics speak of &quot;dielectrics&quot; rather than insulators?" Tags="&lt;material&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8054" PostTypeId="2" ParentId="8052" CreationDate="2018-09-12T06:47:09.490" Score="16" Body="&lt;p&gt;Strictly speaking, dielectrics are not necessarily insulators. For example, salt water is a reasonable conductor but also a dielectric.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The term &quot;dielectric&quot; tends to show up in discussion of the &lt;a href=&quot;http://www.graphics.cornell.edu/~westin/misc/fresnel.html&quot; rel=&quot;noreferrer&quot;&gt;Fresnel effect&lt;/a&gt;—how reflectance and transmittance vary with angle. Dielectric materials (i.e. nonmetals) are contrasted with metallic materials as they have different Fresnel behavior, which can be traced back to how the materials react on a microscopic scale to the electromagnetic field of an incident light wave.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, for computer graphics purposes, the axis &quot;dielectric/metallic&quot; is more relevant than that of &quot;insulator/conductor&quot;, since the former directly affects the appearance of materials.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-09-12T06:47:09.490" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8055" PostTypeId="1" CreationDate="2018-09-12T14:01:15.550" Score="1" ViewCount="55" Body="&lt;p&gt;I was studying the DDA Algorithm and learnt that initially we calculate both the &lt;strong&gt;x-difference&lt;/strong&gt; and the &lt;strong&gt;y-difference&lt;/strong&gt; between the start and the end points of the given line, and &lt;strong&gt;if dx &gt; dy&lt;/strong&gt;, we choose &lt;strong&gt;xIncrement as 1&lt;/strong&gt; and get the successive y-values. The &lt;strong&gt;opposite happens when dy &gt; dx&lt;/strong&gt;, in that case we choose yIncrement as 1 and &lt;strong&gt;get the successive x-values&lt;/strong&gt; using the slope of the line. Why do we do that?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it just that if there are more number of steps, then we get higher accuracy and more definition in our line that is drawn on a raster display?&lt;/p&gt;&#xA;" OwnerUserId="9339" LastEditorUserId="6" LastEditDate="2018-09-15T12:41:06.050" LastActivityDate="2018-09-15T12:41:06.050" Title="Why the interval for which there are more number of steps is chosen while implementing DDA Algorithm?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8056" PostTypeId="2" ParentId="8049" CreationDate="2018-09-12T17:42:20.953" Score="1" Body="&lt;p&gt;Texture mapping is the process of providing a mapping from the surface to a location on the texture. That is, given a particular point on a surface, you can find a specific point in a texture that corresponds to it. Giving positions a UV texture coordinate is a common means of defining a texture mapping, but you can use a function of arbitrary complexity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Texture mapping is at least theoretically reversible. That is, given a particular texel, you can use the texture mapping to determine where on an object that texel appears. Of course, not every texture mapping &lt;em&gt;is&lt;/em&gt; reversible. Some mapping cause a texel to be used in multiple locations on a surface, and not every mapping uses every texel in the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But the important part of the reverse mapping operation is this: a texel maps to some &lt;em&gt;area&lt;/em&gt; of the surface, not a single point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shadow mapping is a form of texture mapping. It defines a mapping from the scene to a texture by performing perspective projection of the points in the scene onto the surface of a texture, based on a light position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you reverse this mapping, a texel in the shadow map maps to an &lt;em&gt;area&lt;/em&gt; in the scene. This is the &quot;region in the scene&quot;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-09-12T17:42:20.953" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8057" PostTypeId="1" CreationDate="2018-09-12T18:19:39.690" Score="6" ViewCount="338" Body="&lt;p&gt;If you have a dielectric (non metallic) sphere with a large roughness value (say, 0.95), and put it in a lighting environment that has a constant onmidirectional lighting value (such as 0.5) Cook-Torrance ggx PBR renderers seem to be missing a darkening at glancing angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought this was a bug in my PBR implementation at first when comparing vs a mitsuba ggx render, but I've found the same issue in google filament (&lt;a href=&quot;https://github.com/google/filament&quot; rel=&quot;noreferrer&quot;&gt;https://github.com/google/filament&lt;/a&gt;) as well as in substance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, below is the iray version from substance compared to the opengl version from substance. 0 metalness, 1 roughness, omnidirectional ibl of 0.5, albedo of (1,1,1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jMt7C.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jMt7C.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this a known limitation of cook-torrance ggx based PBR? Can anyone explain why this limitation is here, and the reason for the difference?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've noticed that it's much closer to the path traced &quot;ground truth&quot; at lower roughness values (like up to around 0.5-0.75), and that the most commonly interesting roughness values are near the lower end of roughness. 0.5 even looks almost &quot;completely rough&quot; for instance.  Is the issue that the approximations used don't really try to make these less important higher roughness values look correct?&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2018-09-12T18:26:48.027" LastActivityDate="2018-09-12T21:03:11.910" Title="PBR missing rim darkening on non metallic rough surfaces" Tags="&lt;lighting&gt;&lt;shading&gt;&lt;pbr&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8059" PostTypeId="2" ParentId="8057" CreationDate="2018-09-12T18:44:25.757" Score="3" Body="&lt;p&gt;The problem is in the diffuse term, which can be seen by making the specular portion of IBL not be added into the result.  The diffuse only render will not have the darkening, and of course, the specular can't make the diffuse darker. (Note, fresnel vs no fresnel is not the issue here).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The core problem is that lambertian diffuse is being used, which is view independent. There are other view independent diffuse terms which give results closer to the ground truth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Two example diffuse terms are Burley (Disney) and Oren-Nayar.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Burley is talked about here: &lt;a href=&quot;https://google.github.io/filament/Filament.md.html#toc4.5&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://google.github.io/filament/Filament.md.html#toc4.5&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An approach used in Titanfall is described here:&#xA;&lt;a href=&quot;https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2018-09-12T18:44:25.757" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8060" PostTypeId="2" ParentId="8057" CreationDate="2018-09-12T21:03:11.910" Score="2" Body="&lt;p&gt;This is not related to the edge but in &lt;a href=&quot;https://eheitzresearch.wordpress.com/240-2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://eheitzresearch.wordpress.com/240-2/&lt;/a&gt; you can clearly see that energy is lost for the microfacet stuff when roughness is increased. The issue is that the rougher the surface is, the more occlusion you get from the shadowing function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a few &quot;hacks&quot; to boost the energy. One can be found in &lt;a href=&quot;http://www.cs.cornell.edu/projects/layered-sg14/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.cs.cornell.edu/projects/layered-sg14/&lt;/a&gt; section 5.3. Maybe the rasterized version uses one of these &quot;hacks&quot; and doesn't have that issue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also see 5.1 here &lt;a href=&quot;https://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.selfshadow.com/publications/s2015-shading-course/burley/s2015_pbs_disney_bsdf_notes.pdf&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="286" LastActivityDate="2018-09-12T21:03:11.910" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8061" PostTypeId="1" AcceptedAnswerId="8062" CreationDate="2018-09-13T10:04:21.327" Score="15" ViewCount="10601" Body="&lt;p&gt;I am learning about normal mapping. I understood that RGB values are converted into XYZ, but my question is &lt;strong&gt;how is it converted and why is the normal map blue and purple in color?&lt;/strong&gt; &lt;/p&gt;&#xA;" OwnerUserId="9298" LastEditorUserId="209" LastEditDate="2019-03-13T09:38:56.167" LastActivityDate="2019-03-13T09:38:56.167" Title="Why are normal maps blue and purple in color?" Tags="&lt;shader&gt;&lt;lighting&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8062" PostTypeId="2" ParentId="8061" CreationDate="2018-09-13T10:17:45.383" Score="14" Body="&lt;p&gt;Because a normal map is covering vectors from -1 to 1 it makes sense to stretch this range into 0-&gt;1 so all of it can be fit inside the range of RGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So usually we apply a transform on the normal to convert it into something we can see.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 colour = vec3(0.5) + normal * 0.5;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The blue colour  is because normal maps are supposed to be used relative to the primitive (triangle/etc) normal with a default (0,0,1) direction to indicate no deviation from the triangle normal. Usually the fragment shader needs to rotate this normal in relation to the current per-pixel normal at runtime.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2018-09-13T10:17:45.383" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8063" PostTypeId="2" ParentId="8061" CreationDate="2018-09-13T11:34:35.320" Score="23" Body="&lt;p&gt;Only tangent space normal maps are primarily blue. This is because the colour blue represents a normal of (0,0,1) which would be an unchanged normal when the triangle lies in the plane x and y, i.e. perpendicular to the surface. The tangent, x and bi-tangent, y (also referred to as bi-normal) are encoded in the red and green channels and these form to create the a tangent space normal for a point on the surface of the triangle. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If a tangent space normal map was to encode a colour only in red (1.0, 0.0, 0.0) this would generate a tangent-space normal parallel to the triangle surface. This is never seen because it would mean that the triangle would only ever be lit at 90degrees from the surface and view vector at which point you wouldn't be able to see the triangle anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;World space normal maps encode the unit normal over a sphere so can be primarily different colours once encoded from [-1, 1] to [0, 1] per channel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A comparison can be seen here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Mfunv.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mfunv.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practise normal maps are usually encoded in a 2 channel format such as &lt;a href=&quot;http://www.reedbeta.com/blog/understanding-bcn-texture-compression-formats/#bc2-bc3-and-bc5&quot; rel=&quot;noreferrer&quot;&gt;BC5&lt;/a&gt; which actually only stores the x and y with the z being reconstructed as we know it's a unit vector. This allows you to maintain higher precision with more bits without increasing the file size. &lt;/p&gt;&#xA;" OwnerUserId="3331" LastActivityDate="2018-09-13T11:34:35.320" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8065" PostTypeId="2" ParentId="3969" CreationDate="2018-09-13T21:11:54.653" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I guess that this is related to the sum of the three functions having a minimum there. See the sum plotted against wavelength&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is actually a wrong way to sum these functions: sRGB model specifies that to get luminosity one must weigh the RGB components with appropriate weights. Then luminosity, unsurprisingly, will become equal to the Y component of the XYZ representation.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the problem with it is that the image seems to have a dip in intensity somewhere around 490 nm&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I can actually see the dip not only near 490 nm, but also a smaller one near 570 nm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyway, I think I've found the reason for this. First of all, let's plot the desaturated colors used in the rendering on the chromaticity diagram:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eJ8kx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eJ8kx.png&quot; alt=&quot;chromaticity diagram with the desaturated spectrum inside&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The dashed triangle is the sRGB gamut, and the cusp formed by the lower two lines of the green curve corresponds to the D65 white (gray) point. Notice that there are three &quot;bumps&quot; away from the white point, corresponding to violet, bluish-green and red. Or, that there is a large dip in saturation in the direction of 490 nm and a moderate decrease in the direction of around 570 nm. Let's characterize this graphically, plotting the norm of difference of the rendered points from white point:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/89eU3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/89eU3.png&quot; alt=&quot;plot of a saturation measure&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is &lt;strong&gt;exactly&lt;/strong&gt; what I perceive visually in the image in terms of saturation and thus blending with the background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where does this strange shape come from, you may wonder. And the answer is, from the spectral locus in full XYZ space. See the following figure: the blue curve is the spectral locus, and the orange is its projection onto a plane normal to vector &lt;code&gt;{1,1,1}&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ov2gQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ov2gQ.png&quot; alt=&quot;spectral locus in XYZ space&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, the shape we got on the chromaticity diagram is something like a planar unfolding of the spectral locus.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to realism of this rendering, I'm reasonably sure that if we try projecting real spectrum onto a gray non-fluorescent surface, we'll also see these two &quot;strange&quot; dips. And they will become less noticeable as you increase brightness of the spectrum relative to the brightness of the surface.&lt;/p&gt;&#xA;" OwnerUserId="4647" LastEditorUserId="4647" LastEditDate="2018-10-09T20:24:40.690" LastActivityDate="2018-10-09T20:24:40.690" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8067" PostTypeId="2" ParentId="8052" CreationDate="2018-09-14T14:53:43.573" Score="2" Body="&lt;p&gt;It is not especially related to graphics but physics, and especially, interaction between electromagnetic waves (like light) and matter, i.e. microphysics of optics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Metals have free electrons, and thus it's quite a sea of almost free moving charges that are interacting with the EM field. Ideally, it would be totally reflected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In dielectrics the electrons are not free, but still the atoms and molecules behave as a non-neutral set of central positive charges (the nucleus) and peripheral negatives charges (the electrons), smoothly locked in position by forces (you might see that as springs), thus the dielectric term (or dipolar in simplest configurations). So, the whole thing reacts to EM waves by distorting, and when restoring (+oscillating) also causes an EM wave emission (since moving charges). Note that it is the interference of these direct and reactive fields that makes the &quot;EM field in the material&quot; with characteristic light velocity, and thus tilt the propagation angle at material border (also named &quot;refraction).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus, the behavior to light is quite different in both cases.&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2018-09-14T14:53:43.573" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8068" PostTypeId="1" CreationDate="2018-09-14T14:54:57.093" Score="5" ViewCount="3895" Body="&lt;p&gt;Given point-cloud data :&#xA;For example. &#xA;position + color and normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What will you use to generate mesh of this data &#xA;and keep reasonable quality for real time cases ? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additional info to consider:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;In some cases given also&#xA;3D cameras world transforms which generated the PCL.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Number of input vertices : ~50k and up to millions .&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Target latency from input to output : &amp;lt; 40ms&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Output triangle mesh (preferably not a must) &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;More info about mesh reconstruction&lt;br&gt;&#xA;&lt;a href=&quot;http://www.cs.utah.edu/~bergerm/recon_bench/&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Benchmark for Surface Reconstruction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Any inputs are welcome.&lt;br&gt;&#xA;FAQ:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How the data look like ?&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Float* Position  [x1,y1,z1,x2,y2,z2...]&lt;/li&gt;&#xA;&lt;li&gt;Float* Normal    [nx1,ny1,nz1,nx2,ny2,nz2...]&lt;/li&gt;&#xA;&lt;li&gt;float or int8 for the color.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9359" LastEditorDisplayName="user7220" LastEditDate="2018-10-14T18:28:37.547" LastActivityDate="2018-10-14T18:28:37.547" Title="Generate mesh from pointcloud data" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8069" PostTypeId="2" ParentId="7976" CreationDate="2018-09-14T15:11:34.273" Score="1" Body="&lt;p&gt;Because you are working on screen space, the view ray points towards the eye (being Z the camera space depth). In order to create an orthonormal base, the vectors must be perpendicular to each other. To do this, you set the coordinate z to 0 for the tangents and bitangets, which ensures these vectors will live in the plane perpendicular to the view ray. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly, you need to make the tangent and bitangent perpendicular to each other, which is accomplished with this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 tangent = normalize(rvec - normal * dot(rvec, normal));&#xA;vec3 bitangent = cross(normal, tangent);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8394" LastActivityDate="2018-09-14T15:11:34.273" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8070" PostTypeId="2" ParentId="8011" CreationDate="2018-09-15T00:11:56.263" Score="1" Body="&lt;p&gt;You can render with a raymarcher and using distance fields. For the hat you would define the center and radius of the cylinder, and would draw any march which falls within such circle, no matter what &quot;height&quot; you are in, it will be infinite. You can also add a restriction, like y &gt; 0 to put a beginning to your hat.&lt;/p&gt;&#xA;" OwnerUserId="8394" LastActivityDate="2018-09-15T00:11:56.263" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8071" PostTypeId="2" ParentId="8068" CreationDate="2018-09-16T06:14:58.727" Score="6" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;one popular Real time surface reconstruction method is TSDF (Truncated Signed Distance Function) used by Microsoft for the Kinect. It is based on the VRIP method but it is faster. It is based on depth maps from different (known) camera positions. &#xA;you can read more:&#xA;&lt;a href=&quot;https://cs.nyu.edu/courses/fall12/CSCI-GA.2945-001/dl/jiakai-slides.pdf&quot; rel=&quot;noreferrer&quot;&gt;https://cs.nyu.edu/courses/fall12/CSCI-GA.2945-001/dl/jiakai-slides.pdf&lt;/a&gt;&#xA;file:///C:/Users/chaim.dryzun/Downloads/kinectfusion.pdf&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;From the methods in the reference you gave the fastest is Wavelet based surface reconstruction. If the overall point cloud is good and regular (uniform point density) and without holes and the normals are correct than it gives a very good mesh in a short time.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A more robust and popular method is the Poisson based surface reconstruction. You will need the normals. It gives very good mesh although it takes more time.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Another good method is the PowerCrust surface reconstruction method. It gives very good and accurate mesh, and it does not need the normals. This method produces a polygonal mesh and not triangular mesh, but it is very easy to transform it to triangular. The original code is very slow, but as it is based on calculating Voronoi cells - you can easily re-write it so it will run much faster.&#xA;You can read more: &#xA;&lt;a href=&quot;http://web.cs.ucdavis.edu/~amenta/powercrust.html&quot; rel=&quot;noreferrer&quot;&gt;http://web.cs.ucdavis.edu/~amenta/powercrust.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Regarding the time, working with million of points will take much more than 40 ms, no matter which method you choose (except maybe TSDF). You will have to downsample the point cloud before meshing.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="9366" LastActivityDate="2018-09-16T06:14:58.727" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8072" PostTypeId="1" AcceptedAnswerId="8077" CreationDate="2018-09-17T13:05:18.060" Score="2" ViewCount="92" Body="&lt;p&gt;This isn't a pure CG question but it's more of a programming one related to CG. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main problem that occurs is both the GUI and the rendered scene need to be drawn regularly by swapping buffers. If the rendering of the scene takes much longer say 5 or 6 FPS, then if the GUI is drawn together with this scene it wouldn't be responsive and lag a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to overcome this problem we could make the path tracer render an image in a separate thread and the GUI in the main one. However this still doesn't solve the problem since we only have 1 window, we need to &lt;code&gt;swapbuffers&lt;/code&gt; in order to display both the GUI as well as the rendered scene. Let's say we swapbuffers in the main thread using this logic...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;render_thread.start();  // render thread sets a flag when it finishes generating an image. This flag is accessible to the main gui thread.&#xA;while(window_open)&#xA;{&#xA;   glClear(GL_COLOR_BUFFER_BIT);&#xA;   if(image_generated)  // flag set by the render thread.&#xA;       draw_image();&#xA;   draw_GUI();&#xA;   swapbuffers();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However here the &lt;code&gt;glClear()&lt;/code&gt; call will clear our rendered scene if the render_thread doesn't finish in time. So basically we need a form of a layered framebuffer where we can clear and draw the top layer separately. Afaik this maybe done through overlay planes but i think those are platform specific?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I have 2 or 3 solutions in mind but I don't know what's the standard people or most softwares follow. If anybody can guide me I'd appreciate it.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;You use multiple windows, possibly the render window being embedded into the GUI window as a subset. The GUI window would be transparent everywhere except the GUI widgets (menu bars etc) leaving the space for the render window to display whatever.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You use the same window but use Scissor tests to clear only the part of the window covered by the menu and redraw the menu again. This sounds nice but provides problem when for example a dropbox covers the rendered scene or when using transparent Widgets.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You save your rendered scene in a texture. Re-draw this texture and&#xA;then the GUI over the top until the render thread gives us a new&#xA;image. The snipped above then would look like,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;render_thread.start();  // render thread sets a flag when it finishes generating an image. This flag is accessible to the main gui thread.&#xA;while(window_open)&#xA;{&#xA;   glClear(GL_COLOR_BUFFER_BIT);&#xA;   if(image_generated)  // flag set by the render thread.&#xA;   {&#xA;       draw_image();&#xA;       save image in a texture;&#xA;   }&#xA;   else&#xA;      Re-draw the saved texture;&#xA;   draw_GUI();&#xA;   swapbuffers();&#xA;   sleep(33.33ms) or until render_thread finishes // sleep either for 33ms which equals 30FPS or till render thread finishes. If the render thread finishes in less than 33ms (&amp;gt; 30FPS) than we don't need to re-draw the saved texture.&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Option 3 could be done through blitting as well. Since I'm using an&#xA;FBO and two RBOs (will explain later why). The snippet would look&#xA;like this.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;render_thread.start();  // render thread sets a flag when it finishes generating an image. This flag is accessible to the main gui thread.&#xA;while(window_open)&#xA;{&#xA;   glClear(GL_COLOR_BUFFER_BIT);&#xA;   if(image_generated)  // flag set by the render thread.&#xA;   {&#xA;       draw_image();&#xA;       save handle to RBO that has the image.&#xA;   }&#xA;   else&#xA;     Blit from the saved RBO to default framebuffer.&#xA;   draw_GUI();&#xA;   swapbuffers();&#xA;   sleep(33.33ms) or until render_thread finishes // sleep either for 33ms which equals 30FPS or till render thread finishes. If the render thread finishes in less than 33ms (&amp;gt; 30FPS) than we don't need to blit again.&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Options 3 and 4 seem to do the job. Is there any other method it's done?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for why am I using 2 RBOs, I'm actually using OpenCL-OpenGL interop. So in OpenCL 1.1, need two Image objects (since we can't read/write to 1) for taking average with the previous frame (that's how it will converge). These two Image objects are wrapped around OpenGL's RBOs. Hence in option 4. when the render thread has finished I will save the handle to the RBO which currently has the image. For details on what libraries I'm using, (GLFW for windowing and nanogui for widgets).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more details on how the path tracer is setup you can read this problem which I was having earlier.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/7966/path-tracer-isnt-converging&quot;&gt;Path tracer isn&amp;#39;t converging&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-09-17T13:48:26.260" LastActivityDate="2018-09-19T09:15:00.197" Title="How to handle GUI in a path traced renderer?" Tags="&lt;pathtracing&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8073" PostTypeId="1" CreationDate="2018-09-17T14:20:29.150" Score="2" ViewCount="27" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PHONR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PHONR.png&quot; alt=&quot;Sample scenario&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given point sets $Y$ and $M$, I'd like to register articulated $M$ to $Y$ without changing the edge distances of $M$. The point correspondences between $Y$ and $M$ are known and points have a fixed connectivity map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see from the above sample, the edge distances of $Y$ are corrupted, and I'd like to correct them using $M$ while sacrificing some localization precision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know ICP and RANSAC algorithms, but none of them solve the articulation problem. I'm looking for any kind of algorithms that can solve this articulated body registration problem.&lt;/p&gt;&#xA;" OwnerUserId="7013" LastActivityDate="2018-09-17T14:20:29.150" Title="How can I register an articulated model to noisy predictions?" Tags="&lt;transformations&gt;&lt;algorithm&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8074" PostTypeId="1" AcceptedAnswerId="8076" CreationDate="2018-09-17T14:24:44.067" Score="3" ViewCount="902" Body="&lt;p&gt;This is a simple question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that in OpenGL or other graphics API, the values stored in the depth buffer are automatically clamped to (0,1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I just want to know why people do this instead of just keeping the actual depth values as float. Is that just because of the non-linear depth equation which makes the closer depth values more precise and the further depth values less precies?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="8826" LastEditorUserId="209" LastEditDate="2018-09-18T09:45:54.190" LastActivityDate="2019-05-06T04:53:38.723" Title="Why are depth buffer values clamped to (0, 1)?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;depth-map&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8075" PostTypeId="1" AcceptedAnswerId="8081" CreationDate="2018-09-17T22:13:52.920" Score="1" ViewCount="812" Body="&lt;p&gt;A few years ago I started creating a procedural planet engine/renderer for a game in Unity, which after a couple of years I had to stop developing due to lack of time. At the time i didn't know too much about shaders so I did everything on the CPU. Now that I have plenty of time and am more aware of what shaders can do I'd like to resume development with the GPU in mind.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the terrain mesh I'm using a cubed-sphere and chunked LODs. Since terrain never changes, heights for each chunk need to be calculated just once.The way I calculate heights is rather complex since it's based on a noise tree, which is created from an artist/designer-provided XML for each main planet/asteroid. Leaf nodes in the tree would be noise generators like Simplex, Value, Sine, Voronoi, etc. while branch nodes would be filters and modifiers (FBM, abs, neg, sum, ridged, billow, blender, selectors, etc). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To calculate the heights for a mesh you'd call &lt;code&gt;void CalcHeights( Vector3[] meshVertices, out float[] heights )&lt;/code&gt; on the noise's root node, somewhere in the game code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This approach offers a lot of flexibility but also introduces a lot of load in the CPU. The first obvious thing to do would be (I guess) to move all generators to the GPU via compute shaders, then do the same for the rest of the filters. But, depending on the complexity of the noise tree, a single call to CalcHeights could potentially cause dozens of calls back and forth between the CPU and GPU, which I'm not sure it's a good thing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I go about this?&lt;/p&gt;&#xA;" OwnerUserId="9372" LastEditorUserId="6" LastEditDate="2018-09-22T15:19:04.913" LastActivityDate="2018-09-22T15:19:04.913" Title="Procedural terrain: What's the best approach to calculate noise in the GPU?" Tags="&lt;gpu&gt;&lt;compute-shader&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8076" PostTypeId="2" ParentId="8074" CreationDate="2018-09-18T08:36:03.673" Score="3" Body="&lt;p&gt;(Just converting comment into an answer)&#xA;It seems you might be asking one of two possible questions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you meant &lt;em&gt;&quot;Why doesn't the Depth buffer contain camera space Z&quot;&lt;/em&gt;&#xA;&lt;br&gt;then it's perhaps worth reading &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8017/why-do-gpus-divide-clip-space-z-by-w-for-position]&quot;&gt;Why do GPUs divide clip space Z by W, for position?&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If, OTOH, you just meant &lt;em&gt;&quot;why is it restricted to [0,1)?&quot;&lt;/em&gt;, then that's &lt;em&gt;probably&lt;/em&gt; because old systems represented the Z-buffer depth with fixed point numbers, hence a natural [0,1) range.&lt;br&gt;&lt;br&gt;&#xA; Of course, later hardware arrived that could use floating-point depths; IIRC Dreamcast's depth representation was an arbitrary positive float representing $\frac{1}{w}$.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-09-18T09:41:27.240" LastActivityDate="2018-09-18T09:41:27.240" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8077" PostTypeId="2" ParentId="8072" CreationDate="2018-09-18T15:10:42.047" Score="3" Body="&lt;p&gt;Turns out I was an effin idiot. I didn't need to use multithreading or whatsoever. Since the main path tracer work is executing in the kernel, I don't need to wait for the kernel to finish right after call to &lt;code&gt;EnqueueKernel&lt;/code&gt; by using &lt;code&gt;clFinish()&lt;/code&gt; ,instead I can tell opencl to set the flag when kernel finishes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, the main time extensive work is done on the GPU while on the CPU side we draw the GUI regularly. Once the kernel finishes we can check through &lt;code&gt;clGetEventInfo()&lt;/code&gt; and draw the rendered scene then. No need to wait for the kernel to finish.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- Although I don't need to use multi threading, I still need to use 1 of the above options, that is if the kernel takes much longer to finish I will have to redraw the previous scene, hence I'm doing this through option 4 i.e. by blitting the previously drawn image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anybody thinks this can be done more efficiently I'm all ears. The only problem with option 3/4 is that, since both my RBO's are being used by OpenCL, so if OpenCL takes much longer to render a frame, in order to draw the previously drawn image I need to blit from the previously written RBO to the default framebuffer. However this is being used by the OpenCL currently for reading purposes. Hence I need to keep a copy of this costing an additional &lt;code&gt;blit&lt;/code&gt; each time the kernel completes.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2018-09-19T09:15:00.197" LastActivityDate="2018-09-19T09:15:00.197" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8078" PostTypeId="2" ParentId="7989" CreationDate="2018-09-18T15:44:00.640" Score="1" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Move the child down slightly so the right foot is behind the shoulder.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Reduce their size almost 50%.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Blend only the outline of the child with the background, at most a few pixels.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The men appear to be standing straight while the child appears to be leaned forward slightly - rotate the top of the inserted image backwards ~5°.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Reduce the brightness of the child slightly.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Doing the above should result in a realistic result.&lt;/p&gt;&#xA;" OwnerUserId="9258" LastActivityDate="2018-09-18T15:44:00.640" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8079" PostTypeId="2" ParentId="7881" CreationDate="2018-09-18T19:28:52.547" Score="2" Body="&lt;p&gt;There is some information about the &lt;a href=&quot;https://github.com/scottdraves/flam3/wiki/XML-File-Format&quot; rel=&quot;nofollow noreferrer&quot;&gt;XML file format&lt;/a&gt; used for .flame files. There are a number of forks of this program written in different languages, the &lt;a href=&quot;https://sourceforge.net/projects/apophysis/&quot; rel=&quot;nofollow noreferrer&quot;&gt;original site&lt;/a&gt; is by definition the place to go for answers; unless you are using a fork - the original  seems to have been abandoned years ago.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Coefs is 6 floats which defines the coefficients for the affine part of the function, in row order (a d b e c f). Xform has an &lt;strong&gt;interpolation_type&lt;/strong&gt; which is a string describing the method for interpolation of xform positions: options are &quot;log&quot;, &quot;linear&quot;, &quot;old&quot;, etc. (a &lt;a href=&quot;https://github.com/mebigfatguy/apophysis-j/tree/master/src/org/apophysis/variations&quot; rel=&quot;nofollow noreferrer&quot;&gt;list of a few dozen options is here&lt;/a&gt;). There can be multiple xforms, each applies a transformation to the previous state.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The spherical transform is complex, there's a 19 page .docx tutorial with 9 pages of examples at: &quot;&lt;a href=&quot;https://www.deviantart.com/universalkinase/art/Understanding-Spherical-Transforms-Apophysis-Tut-506110933&quot; rel=&quot;nofollow noreferrer&quot;&gt;Understanding Spherical Transforms: Apophysis Tut&lt;/a&gt;&quot; by UniversalKinase (direct link to &lt;a href=&quot;https://www.deviantart.com/download/506110933/understanding_spherical_transforms__apophysis_tut_by_universalkinase-d8dbpp1.zip?token=e603ea5d429e198913d7f60f3aaddc4620d78399&amp;amp;ts=1537297719&quot; rel=&quot;nofollow noreferrer&quot;&gt;.ZIP&lt;/a&gt; file). Another tutorial is &quot;&lt;a href=&quot;https://www.deviantart.com/fiery-fire/art/Apo-Tuto-Sphericals-146647576&quot; rel=&quot;nofollow noreferrer&quot;&gt;Apo-Tuto Sphericals&lt;/a&gt;&quot; by Fiery-Fire.&lt;/p&gt;&#xA;" OwnerUserId="9258" LastActivityDate="2018-09-18T19:28:52.547" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8080" PostTypeId="2" ParentId="1" CreationDate="2018-09-19T04:14:12.783" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I was wondering, given a model, which transformations I should apply to get the different projections needed to produce this effect?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There are at least 2 types of videos and many ways to produce them. It is technically correct to call this effect &lt;a href=&quot;https://en.wikipedia.org/wiki/Pepper%27s_ghost&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pepper's ghost&lt;/a&gt; but you will obtain more relevant search results by searching for: &quot;&lt;a href=&quot;https://www.google.com/search?ei=OLGhW9ScGtq50PEP0LWyiAY&amp;amp;q=Smartphone%203D%20Hologram&quot; rel=&quot;nofollow noreferrer&quot;&gt;Smartphone 3D Hologram&lt;/a&gt;&quot; (over 2 million hits).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make the projector you'll need: graph paper, CD case, marker or pen, pair of scissors, Cellotape and/or superglue, craft knife or glass cutter, and a smartphone or computer monitor.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Draw one side of a square &lt;a href=&quot;https://en.wikipedia.org/wiki/Frustum&quot; rel=&quot;nofollow noreferrer&quot;&gt;frustum&lt;/a&gt; on graph paper and cut out 4 shapes from a CD case.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Tape and/or glue them together and place it top down on the center of your cellphone screen.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pHNay.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pHNay.png&quot; alt=&quot;Holographic Smartphone Projector&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make videos there are two kinds to choose from, one image rotated 90° and repeated, or four different images representing each side of the image. Whichever style is chosen each image is placed in a quadrant around the center of the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Use this for a template:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NuZ2P.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NuZ2P.jpg&quot; alt=&quot;Holographic Template&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make the simple rotated image use a program such as &lt;a href=&quot;http://www.avs-plus.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;AVISynth&lt;/a&gt; or PowerDirector, load the video into the Timeline, add a grid, duplicate the track 3 times, rotate each track 90° and place it in one of the quadrants.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dOJ3t.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dOJ3t.jpg&quot; alt=&quot;4 Videos, rotated 90°&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second type of video is produced from 4 seperate images each rotated 90°, this provides a different view from each side. It's difficult to produce a live video of this type, align everything perfectly, and not get the opposing cameras in each other's shot. It's easier to create an animation for this purpose. It should look like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mySpZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mySpZ.png&quot; alt=&quot;Dancing Girl&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9258" LastActivityDate="2018-09-19T04:14:12.783" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8081" PostTypeId="2" ParentId="8075" CreationDate="2018-09-19T09:14:05.137" Score="3" Body="&lt;p&gt;r a similar problem (a tree of combined noise functions, evaluated on the GPU), I found a good method is to generate a shader from the expression tree.  Each predefined node corresponds to a single shader function, e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float simplexNode(vec3 pos) {&#xA;  // ... implementation of simplex noise&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float sumNode(float val1, float val2) {&#xA;  return val1 + val2;  // ... possibly clipped or whatever&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You'd then create a shader like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 core&#xA;// ... include node definitions here&#xA;in vec3 vertexPos;&#xA;out float vertexHeight;&#xA;void main() {&#xA;  float f1 = simplexNode(vertexPos);&#xA;  float f2 = worleyNode(vertexPos);&#xA;  float f3 = sumNode(f1,f2);&#xA;  // .. a bunch more&#xA;  vertexHeight = f76;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Constant parameters could either be &lt;code&gt;uniform&lt;/code&gt;s, or just pasted straight into the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One limitation of this method is that the noise functions and methods have to be local, i.e. the evaluation can be done pointwise.  In my case, some nodes were blends and convolutions, so I had to evaluate pieces of the expression tree into textures, blend or convolve the textures into new textures, then use these textures as leaves for the rest of the expression tree.  All of the combinators you mentioned seem to be local, so this may not be a problem for you.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2018-09-19T09:14:05.137" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8083" PostTypeId="1" CreationDate="2018-09-18T23:56:17.667" Score="2" ViewCount="86" Body="&lt;p&gt;I'm researching generative art using computers, and I'm looking to see if there's a more specific term for types of image manipulation techniques like ASCII art or photo mosaics that can narrow down my search. Basically it's anything that uses a real image as input and outputs something other than individual pixels from the image. Some examples would be &lt;a href=&quot;https://i.stack.imgur.com/zK9XH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zK9XH.png&quot; alt=&quot;this photo mosaic&quot;&gt;&lt;/a&gt; or this &lt;a href=&quot;https://twitter.com/i/status/1040608438236143616&quot; rel=&quot;nofollow noreferrer&quot;&gt;plotter print of a woman&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My sense is that &quot;generative art&quot; is a phrase that properly describes what these techniques do. However, there are other generative art techniques that don't rely on images for input and have a more abstract art look to them when final images come out, so I feel like the term is more broad than the techniques I'm describing.&lt;/p&gt;&#xA;" OwnerDisplayName="Matt Phillips" LastEditorUserId="231" LastEditDate="2018-09-23T10:34:54.037" LastActivityDate="2018-09-23T10:34:54.037" Title="Is &quot;generative art&quot; the best term for describing graphical techniques like ASCII art or photo mosaics?" Tags="&lt;terminology&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8084" PostTypeId="2" ParentId="8083" CreationDate="2018-09-19T05:55:27.887" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://en.m.wikipedia.org/wiki/Generative_art&quot; rel=&quot;nofollow noreferrer&quot;&gt;Generative art (Wikipedia)&lt;/a&gt; doesn't necessarily start with an image as the input, and &lt;a href=&quot;https://en.wikipedia.org/wiki/ASCII_art&quot; rel=&quot;nofollow noreferrer&quot;&gt;ASCII art&lt;/a&gt; can be drawn/typed by hand (in a text editor) especially for ASCII line art (which I've often used for diagrams) or &quot;oldskool&quot; ASCII art.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While there may be overlap, &lt;em&gt;generative art&lt;/em&gt; is neither a synonym nor a hypernym for &lt;em&gt;ASCII art&lt;/em&gt;.  Note that your pen-plotter example is different again in that the computer-controlled physical output (e.g. choice of pen or even brush on similar devices) is a crucial part of the process but a human is likely to do a fair bit of image manipulation first.  ASCII art and photo-mosaics are essentially the same on screen or printed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sticking with Wikipedia, &lt;a href=&quot;https://en.wikipedia.org/wiki/Algorithmic_art&quot; rel=&quot;nofollow noreferrer&quot;&gt;algorithmic art&lt;/a&gt; seems closer, if you exclude hand-typed ASCII art, but this still doesn't fit the robotic drawing of your second example (&lt;em&gt;not&lt;/em&gt; &lt;a href=&quot;https://en.wikipedia.org/wiki/Robotic_art&quot; rel=&quot;nofollow noreferrer&quot;&gt;robotic art&lt;/a&gt;, which is art consisting of robots rather than made by robots).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you're looking for is actually quite broad, and &lt;a href=&quot;https://en.wikipedia.org/wiki/Computer_art&quot; rel=&quot;nofollow noreferrer&quot;&gt;computer art&lt;/a&gt; may be as close as you're going to get, though &lt;em&gt;computer art&lt;/em&gt; includes things like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6psnD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6psnD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (example borrowed from &lt;a href=&quot;https://english.stackexchange.com/a/437597/48571&quot;&gt;a previous answer of mine&lt;/a&gt;)&lt;/p&gt;&#xA;" OwnerUserId="9380" OwnerDisplayName="Chris H" LastActivityDate="2018-09-19T09:07:01.697" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8085" PostTypeId="1" CreationDate="2018-09-20T17:54:34.457" Score="3" ViewCount="224" Body="&lt;p&gt;I'm rendering a scene using scanline method. In order to get rid of aliasing we need to render a scene with higher resolution (2x, for example). I'm trying to figure out how to calculate the color of a sample when it is not taken from the center of the subpixel. For example, we have 4 subpixels per 1 pixel, where the blue circle is the center of the subpixel, and the red circle is the sample position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2XIXR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2XIXR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to find information about sample calculation, but got nothing. I assume that I need to calculate sample color using 4 neighboring subpixels and apply bilinear interpolation to them to find the color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XRwq5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XRwq5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is my guess true, or does it have to somehow calculate the color of the sample in a different way?&lt;/p&gt;&#xA;" OwnerUserId="9382" LastEditorUserId="9382" LastEditDate="2018-09-21T09:45:39.043" LastActivityDate="2018-09-21T09:45:39.043" Title="Sample color calculation in rotated grid supersampling" Tags="&lt;antialiasing&gt;&lt;subpixel-rendering&gt;&lt;supersampling&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8086" PostTypeId="1" CreationDate="2018-09-20T23:35:32.560" Score="1" ViewCount="61" Body="&lt;p&gt;I'm trying to add some details like grass, rocks, trees, etc. to my little procedurally-generated planet. The meshes for the terrain are created from a spherified cube which is split in chunks (chunked LOD).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do this I've wrote a geometry shader that takes a mesh as input and uses its vertex positions as locations where the patches of grass will be placed (as textured quads).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For an infinite flat world (not spherical) I'd use the terrain mesh as input to the geometry shader, but I've found that this won't work well on a sphere, since the vertex density is not homogeneous across the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the main question would be: How to create a point cloud for each terrain chunk whose points were equally distributed across the chunk? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: I've seen some examples where these points are calculated from intersecting a massive rain of totally random perpendicular rays from above... but I found this solution overkill, to say the least.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another related question would be: Is there something better/faster than the geometry shader approach, maybe using compute shaders and instancing?&lt;/p&gt;&#xA;" OwnerUserId="9372" LastActivityDate="2018-09-21T09:13:03.090" Title="Evenly distributed point cloud for a grass renderer on a sphere" Tags="&lt;shader&gt;&lt;gpu&gt;&lt;procedural-generation&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8088" PostTypeId="1" AcceptedAnswerId="8098" CreationDate="2018-09-21T19:08:48.283" Score="0" ViewCount="66" Body="&lt;p&gt;I would need to translate a vtkCellLocator, without rebuilding it entirely. I suppose that it should be possible to apply an offset to all the buckets in the octree. Do you know if is it possible to do this (or to apply a translation to any other cell locator structure) with the tools already provided by vtk?&lt;/p&gt;&#xA;" OwnerUserId="9348" LastEditorUserId="6" LastEditDate="2018-09-22T15:17:37.217" LastActivityDate="2018-09-25T00:34:20.640" Title="Translate vtkCellLocator" Tags="&lt;space-partitioning&gt;&lt;vtk&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8089" PostTypeId="1" CreationDate="2018-09-21T21:12:50.113" Score="-1" ViewCount="77" Body="&lt;p&gt;It sounds crazy, but I've been doing a lot of reading on exactly why WoW &lt;strong&gt;performs very poorly&lt;/strong&gt;, even on a 1080Ti / 8700k OC'd and overall, a high-end machine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Overclocking the CPU yielded great results, but after ~4.7&amp;nbsp;GHz, my returns were, at best, minimal, as such, running at 5.0&amp;nbsp;GHz makes no difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I was thinking:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The server issues data to the CPU. The CPU issues draw calls to my GPU. My GPU can be downclocked by ~40-50%, and it still won't affect FPS. My CPU is clearly hitting its ceiling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, then, could it very well be that, say, on a ~80-90&amp;nbsp;ms connection, my FPS would be limited due to how much it could output, since the GPU is basically waiting?&lt;/p&gt;&#xA;" OwnerUserId="9393" LastEditorUserId="209" LastEditDate="2018-09-24T08:22:41.650" LastActivityDate="2018-09-24T08:22:41.650" Title="Are MMORPGs, specifically WoW, limited by their latency in terms of FPS?" Tags="&lt;performance&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8091" PostTypeId="1" CreationDate="2018-09-22T08:25:57.660" Score="1" ViewCount="124" Body="&lt;p&gt;In &lt;a href=&quot;https://books.google.de/books?id=iNMVBQAAQBAJ&amp;amp;pg=PA950&amp;amp;lpg=PA950&amp;amp;dq=%22for+pinhole+apertures,+we+compute%22&amp;amp;source=bl&amp;amp;ots=ivwhEhZqRF&amp;amp;sig=yCpEAaOMpYlA9Vj-LykM5_VHnoQ&amp;amp;hl=de&amp;amp;sa=X&amp;amp;ved=2ahUKEwjvirbRlM7dAhXFzaQKHW2KB3EQ6AEwAHoECAAQAQ#v=onepage&amp;amp;q=%22for%20pinhole%20apertures%2C%20we%20compute%22&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;section 16.1.1 of &lt;em&gt;Physically Based Rendering&lt;/em&gt;&lt;/a&gt; the authors describe how we can check, if a given ray &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; corresponds to one starting from the film area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They implement this check such that it works for cameras with finite and pinhole apertures. They assume that &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; has origin &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; and direction &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt;. Maybe I didn't get it, but are they assuming that &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is a point on the lens? That seems to be the case from Figure 16.1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now they want to find the point on the film that &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; corresponds to. Let &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; denote the camera viewing direction &lt;span class=&quot;math-container&quot;&gt;$(0,0,1)$&lt;/span&gt; in world coordinates. Then they compute the cosine of the angle &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; between &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$$\cos(\theta)=\langle\omega,w\rangle.$$&lt;/span&gt; Assuming we're dealing with a pinhole aperture, why do we find the point on the film by intersecting the ray with a plane arbitrary set at &lt;span class=&quot;math-container&quot;&gt;$z=1$&lt;/span&gt;? And why is this intersection at &lt;span class=&quot;math-container&quot;&gt;$p+t\omega$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$t=1/\cos(\theta)$&lt;/span&gt;? Shouldn't the intersection be at &lt;span class=&quot;math-container&quot;&gt;$t=\frac{\langle w-p,w\rangle}{\langle\omega,w\rangle}$&lt;/span&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And anyway, doesn't &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; need to be equal to the eye point of the camera?&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2018-09-22T11:54:12.973" LastActivityDate="2018-09-22T11:54:12.973" Title="Compute emitted importance of a pinhole camera" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8092" PostTypeId="2" ParentId="8089" CreationDate="2018-09-22T09:14:35.757" Score="4" Body="&lt;p&gt;Online games do not work the way you describe. The server doesn't give the client one frame's worth of data every frame. That would be awful. Instead, every client has its own copy of the game state, and the rendering happens as if it were an offline game: every frame, the game state is updated locally. That means your inputs such as moving the mouse to control the view take effect immediately. Things that aren't under players' control (such as the movement of projectiles in flight) are also updated locally. Many games also have some kind of motion prediction for other players' characters - in the simplest case, just updating the state as if they kept going in the same direction.&lt;/p&gt;&#xA;&lt;p&gt;These state updates are performed by the CPU on its scene-graph, and they result in some update to GPU state too. The frame is then rendered by the GPU, usually in parallel with the CPU starting work on the next frame's updates.&lt;/p&gt;&#xA;&lt;p&gt;When an update arrives from the server, this also updates the state on the CPU. This update will include new projectiles, replacements for the predicted motions of other player characters, and replacements for the motions of the local player's character (e.g. if they bumped into another player or were hit by some unpredicted projectiles).&lt;/p&gt;&#xA;&lt;p&gt;Resolving conflicts between the predicted state on the client and the new state from the server, and applying the lag to the server state before applying it, are important parts of the game's architecture that really determine how the game feels to play and what lag looks like. Applying the updates from the server is done within one frame update on the client, so if an update takes too long to apply, it'll cause some frames to be much slower, but the age of the update doesn't really affect that.&lt;/p&gt;&#xA;&lt;h2&gt;Summary&lt;/h2&gt;&#xA;&lt;p&gt;Client-server latency doesn't usually increase the frame time, because the client doesn't wait for a server round-trip each frame.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-09-22T09:14:35.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8093" PostTypeId="1" AcceptedAnswerId="8097" CreationDate="2018-09-22T12:01:25.687" Score="3" ViewCount="1486" Body="&lt;p&gt;I want to represent ovaloids with ray-marching. I have ovaloids defined with an implicit equation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, we can consider the equation of an ellipsoid given as: &lt;span class=&quot;math-container&quot;&gt;$$ \frac{x^2}{a^2} + \frac{y^2}{b^2} + \frac{z^2}{c^2} -1 = 0, $$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$a, b, c$&lt;/span&gt; are constant. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given this equation I need to caculate the normal for the shading of the suface. In an standard course of Curves and Surfaces I would take &lt;span class=&quot;math-container&quot;&gt;$f(x,y,z) = \frac{x^2}{a^2} + \frac{y^2}{b^2} + \frac{z^2}{c^2} -1 $&lt;/span&gt; and compute &lt;span class=&quot;math-container&quot;&gt;$N(p) = \frac{\nabla f(p)}{|\nabla f(p)|}$&lt;/span&gt; as the normal of the surface. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here I have to check that &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; is a regular value of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; and that &lt;span class=&quot;math-container&quot;&gt;$f  $&lt;/span&gt; is differentiable. However, the second check is not automate.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;How is it done in real-world systems? &lt;/li&gt;&#xA;&lt;li&gt;Can you give an explanation of the methods used and ideally point me some implementations that exist?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Please, answer in full generality and not only considering the example given above. &lt;/p&gt;&#xA;" OwnerUserId="9120" LastEditorUserId="9120" LastEditDate="2018-09-23T11:00:02.493" LastActivityDate="2018-09-24T18:41:23.123" Title="How to compute normal of surface from implicit equation for ray-marching?" Tags="&lt;shading&gt;&lt;normal-mapping&gt;&lt;raymarching&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8094" PostTypeId="2" ParentId="7428" CreationDate="2018-09-23T17:46:17.997" Score="1" Body="&lt;p&gt;This is more a comment than an answer, but since I'm new here with no reputation, I can't comment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was trying to use your method 2 to read a metal texture (having hit problems with your other methods, too, as well as half a dozen other methods from other threads).  I used a .waitUntilCompleted method, so figured my problem didn't have to deal with flushing.  My shader is a toy example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;kernel void compute_main(&#xA;                     texture2d&amp;lt;float, access::read&amp;gt; inTexture [[texture(0)]],&#xA;                     texture2d&amp;lt;float, access::write&amp;gt; outTexture [[texture(1)]],  // this doesn't work&#xA;                     //texture2d&amp;lt;float, access::read_write&amp;gt; outTexture [[texture(1)]],  // this does&#xA;                     uint2 gid [[thread_position_in_grid]])&#xA;{&#xA;    float4 inColor = inTexture.read(gid);&#xA;    float4 outColor (inColor.g, inColor.r, inColor.b, inColor.a);&#xA;    outTexture.write(outColor, gid);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I initially was getting this error:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;validateComputeFunctionArguments:857: failed assertion `Compute Function(ciKernelMain): reads texture ([1]) whose usage (0x02) doesn't specify MTLTextureUsageShaderRead (0x01)'&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I realize it isn't the same error you were getting, but maybe something has changed in metal/swift/xcode.  I'm running Xcode 9.4.1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After changing the output texture to read_write (the commented line in the code above), and setting up the texture descriptor appropriately,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//textureDescriptor.usage = MTLTextureUsage.shaderWrite // not this&#xA;textureDescriptor.usage = [.shaderWrite, .shaderRead] // this works&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;it worked.  Seems the CI library for this uses metal (I'm guessing from the error) and it reads the texture I thought I only needed to write to.  Not obvious until you run it and get the error.  I'm not sure if our situations were different or what, but in mine, at least I got an error message that was useful.&lt;/p&gt;&#xA;" OwnerUserId="9399" LastActivityDate="2018-09-23T17:46:17.997" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8095" PostTypeId="1" CreationDate="2018-09-23T18:15:52.493" Score="4" ViewCount="685" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;If I have an image of x/y resolution and display it on a monitor, does this mean that between a 15-inch monitor and a 42-inch, the same amount of pixels (x/y) will be displayed, only that each pixel will be of different size?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;In relation to my first question, if I connect a 25-inch monitor or a 13-inch monitor to a computer, will the GPU/CPU work harder when connected to the 25 inch one? Could there be more lags on the bigger screen, or is it simply a matter of pixels' stretching?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="9398" LastActivityDate="2018-11-11T07:22:41.867" Title="Difference in pixels between different monitors' sizes" Tags="&lt;rendering&gt;&lt;gpu&gt;&lt;pixel-graphics&gt;&lt;pixels&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8096" PostTypeId="2" ParentId="8095" CreationDate="2018-09-24T07:55:58.750" Score="4" Body="&lt;p&gt;The answer to both your questions is the same: the physical size of the monitor makes no difference at all. If your screen is 1920x1080 pixels, and you display a 960x540 image without any scaling, the image will stake up a quarter of the screen, and it won't take any more GPU time to display on a larger monitor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only caveat is that most OSes have some kind of pixel scaling method now, so that icons, buttons, and text aren't unusably small on modern high-resolution displays. In Windows the option is called &quot;Change the size of text, apps and other items&quot;. If this setting isn't set to 100%, most things on the screen are scaled up even if the program isn't scaling them. This is more likely to be set high on a small, high-resolution screen than on a large, high-resolution screen. If you try to test displaying the same image on different-sized monitors, and they are using different values for this setting, the image probably won't be the same number of pixels on the monitors, because it's being scaled up according to this setting.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-09-24T07:55:58.750" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8097" PostTypeId="2" ParentId="8093" CreationDate="2018-09-24T18:41:23.123" Score="1" Body="&lt;p&gt;The usual way of doing this with raymarching is to define your surface as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Signed_distance_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;signed-distance field&lt;/a&gt; and use &lt;a href=&quot;https://en.wikipedia.org/wiki/Finite_difference#Relation_with_derivatives&quot; rel=&quot;nofollow noreferrer&quot;&gt;finite differences&lt;/a&gt; to get the gradient of the distance function at the point you’re sampling. In other words, if you have a function &lt;code&gt;map(p)&lt;/code&gt; that returns the signed distance value at a point &lt;code&gt;p&lt;/code&gt;, the normal at &lt;code&gt;p&lt;/code&gt; is given by:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float epsilon = 0.001; // arbitrary — should be smaller than any surface detail in your distance function, but not so small as to get lost in float precision&#xA;float centerDistance = map(p);&#xA;float xDistance = map(p + float3(epsilon, 0, 0));&#xA;float yDistance = map(p + float3(0, epsilon, 0));&#xA;float zDistance = map(p + float3(0, 0, epsilon));&#xA;float3 normal = (float3(xDistance, yDistance, zDistance) - centerDistance) / epsilon;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that you can improve the accuracy by taking an extra 3 samples on the other “side” of the center position and subtracting those from the first three, then dividing by 2× the epsilon value, but if your distance function is complicated then that can be a lot of additional work for not much visible benefit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sample function you provide isn’t a signed-distance function as-is, and I don’t know of a straightforward way to convert it into one, but there’s an article by Íñigo Quílez (kind of a legend in this field) &lt;a href=&quot;https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; with various functions you can make use of, including one for an ellipsoid. There’s also a lot of reference material available on &lt;a href=&quot;https://shadertoy.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Shadertoy&lt;/a&gt;—search for “raymarching” and you’ll find plenty of examples.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-09-24T18:41:23.123" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8098" PostTypeId="2" ParentId="8088" CreationDate="2018-09-25T00:34:20.640" Score="1" Body="&lt;p&gt;In order to translate a vtkCellLocator, you have only to translate a bounding box of root octant. However this bounding box cannot be publicly accessible. So it is necessary to create a new class inheriting from a vtkCellLocator and provide access functions to get and set it directly. The following is a simple example.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;vtkTransform.h&amp;gt;&#xA;#include &amp;lt;vtkTransformPolyDataFilter.h&amp;gt;&#xA;#include &amp;lt;vtkSmartPointer.h&amp;gt;&#xA;#include &amp;lt;vtkSphereSource.h&amp;gt;&#xA;&#xA;#include &amp;lt;vtkCellLocator.h&amp;gt;&#xA;#include &amp;lt;vtkObjectFactory.h&amp;gt;&#xA;&#xA;class vtkMyCellLocator : public vtkCellLocator&#xA;{&#xA;public:&#xA;  static vtkMyCellLocator *New();&#xA;&#xA;  vtkSetVectorMacro(Bounds,double,6);&#xA;  vtkGetVectorMacro(Bounds,double,6);&#xA;};&#xA;vtkStandardNewMacro(vtkMyCellLocator);&#xA;&#xA;int main(int, char *[])&#xA;{&#xA;  auto sphereSource = vtkSmartPointer&amp;lt;vtkSphereSource&amp;gt;::New();&#xA;  sphereSource-&amp;gt;Update();&#xA;&#xA;  // Create the tree&#xA;  auto cellLocator = vtkSmartPointer&amp;lt;vtkMyCellLocator&amp;gt;::New();&#xA;  cellLocator-&amp;gt;SetDataSet(sphereSource-&amp;gt;GetOutput());&#xA;  cellLocator-&amp;gt;BuildLocator();&#xA;&#xA;  double translate[3] = {10.0, 0, 0};&#xA;  auto transform = vtkSmartPointer&amp;lt;vtkTransform&amp;gt;::New();&#xA;  transform-&amp;gt;Translate(translate);&#xA;&#xA;  auto transformFilter = vtkSmartPointer&amp;lt;vtkTransformPolyDataFilter&amp;gt;::New();&#xA;  transformFilter-&amp;gt;SetTransform(transform);&#xA;  transformFilter-&amp;gt;SetInputConnection(sphereSource-&amp;gt;GetOutputPort());&#xA;  transformFilter-&amp;gt;Update();&#xA;  cellLocator-&amp;gt;SetDataSet(transformFilter-&amp;gt;GetOutput());&#xA;&#xA;  double bounds[6];&#xA;  cellLocator-&amp;gt;GetBounds(bounds);&#xA;  for (int i = 0; i &amp;lt; 3; ++i)&#xA;  {&#xA;    bounds[2*i] += translate[i];&#xA;    bounds[2*i+1] += translate[i];&#xA;  }&#xA;  cellLocator-&amp;gt;SetBounds(bounds);&#xA;&#xA;  double testPoint[3] = {2.0, 0.0, 0.0};&#xA;&#xA;  //Find the closest points to TestPoint&#xA;  double closestPoint[3];//the coordinates of the closest point will be returned here&#xA;  double closestPointDist2; //the squared distance to the closest point will be returned here&#xA;  vtkIdType cellId; //the cell id of the cell containing the closest point will be returned here&#xA;  int subId; //this is rarely used (in triangle strips only, I believe)&#xA;  cellLocator-&amp;gt;FindClosestPoint(testPoint, closestPoint, cellId, subId, closestPointDist2);&#xA;&#xA;  std::cout &amp;lt;&amp;lt; &quot;Coordinates of closest point: &quot; &amp;lt;&amp;lt; closestPoint[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; closestPoint[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; closestPoint[2] &amp;lt;&amp;lt; std::endl;&#xA;  std::cout &amp;lt;&amp;lt; &quot;Squared distance to closest point: &quot; &amp;lt;&amp;lt; closestPointDist2 &amp;lt;&amp;lt; std::endl;&#xA;  std::cout &amp;lt;&amp;lt; &quot;CellId: &quot; &amp;lt;&amp;lt; cellId &amp;lt;&amp;lt; std::endl;&#xA;&#xA;  return EXIT_SUCCESS;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9405" LastActivityDate="2018-09-25T00:34:20.640" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8099" PostTypeId="1" AcceptedAnswerId="8100" CreationDate="2018-09-25T12:54:15.490" Score="2" ViewCount="122" Body="&lt;p&gt;For research purpose, I have to implement z-buffering algorithm to render 3D face models. But I got a problem that the triangles are too small to be rendered (i.e. there is no pixel covered completely  by any of the triangles).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried to increase the resolution of the output image (so that the triangles get bigger) but it's been &lt;span class=&quot;math-container&quot;&gt;$10,000 \times 10,000$&lt;/span&gt; so far (I think it's pretty high) and my computer can't suffer from higher resolutions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you give me some solution for this problem ?&lt;/p&gt;&#xA;" OwnerUserId="9408" LastEditorUserId="9408" LastEditDate="2018-09-25T13:01:27.160" LastActivityDate="2018-09-26T12:03:15.117" Title="Z-buffering implementation with small triangles" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;z-buffer&gt;&lt;implementation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8100" PostTypeId="2" ParentId="8099" CreationDate="2018-09-25T13:07:07.380" Score="3" Body="&lt;p&gt;Assuming the small triangles form continuous surfaces, although many of the small triangles &quot;fall through the gaps&quot; (so to speak), some should still cover the samples. If on the other hand, they are separate/independent triangles then it will alias very badly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One possible alternative to just doing higher resolutions would be to simulate an &lt;a href=&quot;https://www.cse.msu.edu/~cse872/tutorial5.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Accumulation Buffer&lt;/a&gt;. In essence, do &lt;em&gt;N&lt;/em&gt; XxY pixel renders, but for every render, offset the X&amp;amp;Y screen coordinates by a sub-pixel amounts. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can then combine the &lt;em&gt;N&lt;/em&gt; images, (perhaps initially with a simple box filter, but a Gaussian would be better) to produce your final XxY image.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Can you explain what does &quot;offset the X&amp;amp;Y screen coordinates by a sub-pixel amounts.&quot; mean ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Perhaps it'd be a good idea to read  &lt;a href=&quot;https://graphics.stanford.edu/courses/cs248-02/haeberli-akeley-accumulation-buffer-sig90.pdf&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;The Accumulation Buffer&quot;&gt;Haeberli and Akeley's original paper&lt;/a&gt; but I'll try to put in a bit of an explanation on how I would try to do the XY shifts. (&lt;em&gt;I apologise in advance if I've made some fundamental flaw in the following logic...&lt;/em&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume we want to shift the image by &lt;span class=&quot;math-container&quot;&gt;$(x_{offset}, y_{offset})$&lt;/span&gt; in pixels where, &lt;em&gt;probably&lt;/em&gt;, &lt;span class=&quot;math-container&quot;&gt;$|x_{offset}| &amp;lt; 0.5$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$|y_{offset}|&amp;lt;0.5$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We want to add this offset to each vertex &lt;em&gt;after&lt;/em&gt; it's been projected into screen coordinates. Now since we don't have much control of the pipeline post clipping and projection, we'll need to do that by adjusting the projection matrix. If we assume our default projection matrix, P, does something of the following:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(X_{world}, Y_{world}, Z_{world}, 1).P=(X_{clip},Y_{clip},Z_{clip}, W_{clip})$$&lt;/span&gt;&#xA;i.e. maps from world space to clip space, then to shift the points in image space we'll need an additional &quot;matrix&quot; adjustment which, off the top of my head, will be &lt;em&gt;something&lt;/em&gt; like...&#xA;&lt;span class=&quot;math-container&quot;&gt;$$Adjust= \begin{bmatrix}&#xA;    1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;    0 &amp;amp; 1 &amp;amp; 0&amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp;1&amp;amp; 0 \\&#xA;    scaledX_{offset} &amp;amp; scaledY_{offset} &amp;amp;0&amp;amp; 1 \\&#xA;    \end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;The &quot;scaling&quot; should take into account the resolution of the target image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Create a new, per offset, projection matrix from &lt;span class=&quot;math-container&quot;&gt;$P.Adjust$&lt;/span&gt; for each &quot;offset&quot; image you want to accumulate.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-09-26T12:03:15.117" LastActivityDate="2018-09-26T12:03:15.117" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8101" PostTypeId="1" CreationDate="2018-09-25T17:56:37.497" Score="1" ViewCount="44" Body="&lt;p&gt;Current mainstream technology does not really model the density functions very well. Yeah, we can use volumetric grids, FEM, voxel representations and particle clouds that define densities. But these files dont scale, worse theres no practical way to model the distributions effectively. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But we are, slowly but surely, entering a new age of manufacturing where it is not enough to know just what the surface looks like, but know what is inside the structure, not just that its one material. But rather some amalgamation of properties that can change smoothly or abruptly depending on your need. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But how would we handle this in a way that is still editable? Is anybody aware of any methods that might eventually lead us to next level of model definition? The best i have so far seen is some general implicit density representations like extended meta balls but its still not accurate enough, or usable for me.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2018-09-25T18:15:37.067" LastActivityDate="2018-09-25T18:15:37.067" Title="Has anybody extended parametric surfaces to volume density representations usefully?" Tags="&lt;model&gt;&lt;volumetric&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8102" PostTypeId="1" CreationDate="2018-09-25T22:55:19.760" Score="2" ViewCount="543" Body="&lt;p&gt;I have been following &lt;a href=&quot;https://learnopengl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;LearnOpenGL.com&lt;/a&gt;'s tutorials on PBR. Everything makes sense and I wrote up a shader for my physically based renderer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I noticed that the results look great, however all of my metal objects have such a strong specular on the edges thanks to my Fresnel calculation, and it is producing specular aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://imgur.com/a/gqySuGl&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.imgur.com/1blISHK.png&quot; alt=&quot;Illustration of shading aliasing&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't seem to figure out why, or how to fix this. I also uploaded a simplified version of my PBR fragment shader. If someone could take a look, I would really appreciate it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simplified PBR fragment shader: &lt;a href=&quot;https://textuploader.com/dv3h1&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://textuploader.com/dv3h1&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the tutorial I am following: &lt;a href=&quot;https://learnopengl.com/PBR/Lighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://learnopengl.com/PBR/Lighting&lt;/a&gt;&#xA;It doesn't seem to have any of these specular aliasing issues.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="8893" LastEditorUserId="182" LastEditDate="2018-11-20T04:23:19.393" LastActivityDate="2019-04-19T05:03:40.727" Title="PBR and Specular Aliasing" Tags="&lt;physically-based&gt;&lt;specular&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8105" PostTypeId="1" AcceptedAnswerId="8106" CreationDate="2018-09-30T01:23:13.883" Score="1" ViewCount="90" Body="&lt;p&gt;I've watched the &lt;a href=&quot;https://www.khanacademy.org/computing/pixar/rendering/rendering-2/a/rendering-lesson-brief&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pixar In A Box, Maths of Rendering Tutorial&lt;/a&gt; on Khan Academy. I've started writing a raytracing program and have come to the point where I must solve for &lt;code&gt;t&lt;/code&gt; (the parameter for the parametric ray through the camera and a point on the view plane).&lt;/p&gt;&#xA;&lt;p&gt;In the tutorial, this is done by simply substituting the parametric formula for each &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;, and &lt;code&gt;z&lt;/code&gt; into the equation of the plane that the triangle lies on. This leaves a single unknown (&lt;code&gt;t&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;p&gt;However, in all the examples and exercises that are given by the tutorial the camera is located at [0,0,0]. As I'm sure you'll understand, this is in many cases unrealistic. Because the camera is at 0, they simplify as follows:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$i=\frac{1}{t}C+tP$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;becomes simply:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$tP$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Which makes for an easy solve. My question is when the camera is not at [0,0,0] should I:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Calculate the coordinates of the plane relative to the camera. (So the camera acts as if it is [0,0,0]&lt;/li&gt;&#xA;&lt;li&gt;Solve the equation as a quadratic. I'm still confused a bit about why this is quadratic in the first place. Could someone explain this? And which solution do I use?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Of the two options, which is more acceptable for use in this community? Why? Is one more computationally efficient?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt;&#xA;I think I have found a solution as follows:&#xA;The parametric equation (which is effectively just a weighted average) is represented like this in the tutorial:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$x(t) = \frac{1}{t}C_{x}+tP_{x}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;But I realize now that is the same as:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$x(t)=C_{x}+t(P_{x}-C_{x})$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Which is dramatically easier to solve.&lt;/p&gt;&#xA;&lt;p&gt;So my final question is, which of the three is the most acceptable way to solve for t? I'm assuming the third one.&lt;/p&gt;&#xA;" OwnerUserId="9429" LastEditorUserId="13095" LastEditDate="2021-02-04T11:25:41.800" LastActivityDate="2021-02-04T11:25:41.800" Title="How to raytrace triangular faces when camera is not at origin?" Tags="&lt;raytracing&gt;&lt;3d&gt;&lt;pixel-graphics&gt;&lt;ray&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8106" PostTypeId="2" ParentId="8105" CreationDate="2018-09-30T04:33:23.613" Score="1" Body="&lt;p&gt;Wow I'm stupid, the whole problem was I thought it was &lt;code&gt;1/t&lt;/code&gt; and it is actually &lt;code&gt;1-t&lt;/code&gt; in parametric form. Hope this helps someone anyway.&lt;/p&gt;&#xA;" OwnerUserId="9429" LastEditorUserId="9429" LastEditDate="2018-10-03T21:50:00.827" LastActivityDate="2018-10-03T21:50:00.827" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8107" PostTypeId="1" AcceptedAnswerId="8108" CreationDate="2018-10-01T17:24:11.883" Score="0" ViewCount="1094" Body="&lt;p&gt;I don't think there is much to explain here, since the question is pretty much in the title, but i'll try to explain myself better:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My current laptop's gpu does not support Vulkan, so i was wondering if it was possible to do something like d3d12 does, where if a specific function is not able to be performed by the gpu, it can be emulated by the cpu, while maintaing the program running and functioning, at the obvious cost of performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I achive something like that using Vulkan?&lt;/p&gt;&#xA;" OwnerUserId="9436" LastActivityDate="2018-10-01T20:49:34.253" Title="Is it possible to emulate Vulkan on a non Vulkan compatible gpu?" Tags="&lt;rendering&gt;&lt;gpu&gt;&lt;vulkan&gt;&lt;gpgpu&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8108" PostTypeId="2" ParentId="8107" CreationDate="2018-10-01T18:56:56.767" Score="4" Body="&lt;p&gt;It's possible to emulate Vulkan on a sufficiently capable non-Vulkan API.  This is the point of the Vulkan Portability Initiative.  Indeed, there is already a Vulkan implementation on top of the Apple proprietary API Metal, and there is work being done to implement Vulkan on top of D3D12.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It probably &lt;em&gt;would&lt;/em&gt; be possible to implement a version of Vulkan that ran partially on a GPU (to which you had some other API access) and partially in software on the CPU, but unless you're working with some kind of mobile device with integrated memory, the performance of such a system would probably be utter garbage.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your goal is to better understand and develop for Vulkan, I'd suggest you investigate some of the existing efforts at creating a fully software Vulkan implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're just trying to get some game to run better, I suggest you get a better laptop.&lt;/p&gt;&#xA;" OwnerUserId="9306" LastActivityDate="2018-10-01T18:56:56.767" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8109" PostTypeId="2" ParentId="8107" CreationDate="2018-10-01T20:49:34.253" Score="0" Body="&lt;p&gt;Yes this is exactly what &lt;a href=&quot;https://en.wikipedia.org/wiki/Mesa_(computer_graphics)&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mesa&lt;/a&gt; does. Also note that many older GPU's (prior to 2015, when Vulkan got released) support Vulkan (approx 2012, both nVidia and AMD), although this isn't the case for the Laptop variants. ymmv.&lt;/p&gt;&#xA;" OwnerUserId="9438" LastActivityDate="2018-10-01T20:49:34.253" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8110" PostTypeId="1" CreationDate="2018-10-01T21:23:18.093" Score="3" ViewCount="183" Body="&lt;p&gt;I have multiple separate shapes for which I have generated signed distance fields by merging and clipping them against each other. &lt;strong&gt;Is there a generic analytical solution for merge and clip operations of signed distance fields?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, the result of clipping a horizontal and vertical edge, producing the convex corner (green), the MAX operation results in a correct shape interior, but incorrect exterior. The points in the bottom-right quadrant of the image have values closer than they should.  This is the result of the formerly-closest points no longer being present in the post-clipped image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KtnVS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KtnVS.png&quot; alt=&quot;Incorrect Clip Result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct SDF should look like this, with the bottom-right quadrant being a conic/radial shape, as for all points in that quadrant, their closest point is the shape corner itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SSm0a.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SSm0a.png&quot; alt=&quot;Correct Clip Result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1992" LastActivityDate="2018-10-01T21:23:18.093" Title="Merging/Clipping Signed Distance Fields" Tags="&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8111" PostTypeId="1" AcceptedAnswerId="8112" CreationDate="2018-10-02T05:43:19.687" Score="4" ViewCount="4474" Body="&lt;p&gt;I'm making a cross-platform application, and i need my shaders to be compiled to SPIR-V for both Opengl and Vulkan. It seems that the only way to do so is to call a separate program, called &quot;glslangValidator.exe/.deb/.dmg&quot;. This sort of makes it cross-platform, but it requires me to change the command that calls the program on each platform (and that's not ideal to me). Can i embed some code or use something else to compile shaders directly from my application?&lt;/p&gt;&#xA;" OwnerUserId="9436" LastActivityDate="2020-01-07T03:55:38.967" Title="Can i compile my shaders to SPIR-V without using glslangValidator?" Tags="&lt;shader&gt;&lt;vulkan&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8112" PostTypeId="2" ParentId="8111" CreationDate="2018-10-02T08:36:18.160" Score="6" Body="&lt;p&gt;Typically compiling GLSL to SPIRV would be something you do as part of the build process, so that you end up distributing SPIRV instead of GLSL.  Then you don't need to compile it at runtime.  Assuming you're using the Vulkan SDK, the binary for glslangValidator (or a shell script to build it) should be part of the installed SDK.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, if you want to compile GLSL to SPIRV at runtime, you can link against the glslang library and do that.  Take a look at the &lt;em&gt;Programatic Interface&lt;/em&gt; section in the &lt;a href=&quot;https://github.com/KhronosGroup/glslang/blob/master/README.md&quot; rel=&quot;noreferrer&quot;&gt;readme&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="9306" LastActivityDate="2018-10-02T08:36:18.160" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8113" PostTypeId="1" CreationDate="2018-10-03T21:01:44.997" Score="0" ViewCount="42" Body="&lt;p&gt;I have the following image and depth map from a CV paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QsXCt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QsXCt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to know if there is an existing way to apply screen space rendering to a pre-existing image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before someone yells ate me saying &quot;Why render over a literal picture when you can only make it worse!&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a program that changes multiple aspects of the original image, (color of certain objects and re-texturing of some surfaces).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the original colors are wrong with respect to the modified image.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-10-03T21:01:44.997" Title="How to apply SSRT to an existing image with associated depth map?" Tags="&lt;rendering&gt;&lt;human-vision&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8114" PostTypeId="1" CreationDate="2018-10-04T20:21:49.400" Score="1" ViewCount="174" Body="&lt;p&gt;I'd like to simulate a rubber-like material. This material if deformed would experience a restoring force to its original shape, a bit like a school rubber ereaser. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried with a spring-mass system but the system become quickly instable, moreover it's computational expansive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing some research I found out I could simulate this behaviour through finite element method If I understood well. The problem is I haven't got the right mathematical tools to understand this method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how would you face up to this problem?&#xA;Resources, links, tutorials, papers are welcome.&lt;/p&gt;&#xA;" OwnerUserId="9448" LastActivityDate="2018-10-10T08:14:48.547" Title="How to simulate elastic material with restoring shape" Tags="&lt;mathematics&gt;&lt;simulation&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8115" PostTypeId="1" AcceptedAnswerId="8116" CreationDate="2018-10-04T21:13:49.600" Score="0" ViewCount="1565" Body="&lt;p&gt;Assume eye position e, gaze direction g, view-up vector t, right-handed base. As the graphs shows:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/G3CWy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/G3CWy.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/fDzVi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fDzVi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$w=-\frac{g}{||g||}$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$u=\frac{t\times w}{||t\times w||}$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$v=w\times u$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am really confused about the 2nd equation &lt;span class=&quot;math-container&quot;&gt;$u=\frac{t\times w}{||t\times w||}$&lt;/span&gt;.&lt;br&gt;&#xA;What if the camera rotate around its gaze direction? The v rotates while the t stays the same.&lt;br&gt;&#xA;Then the vector t will not in the plane that w and v lies in which means the second equation is wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know I have something misunderstood.&lt;br&gt;&#xA;Could someone please give me some clues?  &lt;/p&gt;&#xA;" OwnerUserId="3416" LastEditorUserId="3416" LastEditDate="2018-10-05T02:12:04.243" LastActivityDate="2018-10-05T02:58:54.803" Title="Understanding of Camera Up Vector" Tags="&lt;camera&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8116" PostTypeId="2" ParentId="8115" CreationDate="2018-10-05T02:58:54.803" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;What if the camera rotate around its gaze direction? The v rotates while the t stays the same.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The camera's orientation is defined by two directions: &lt;strong&gt;g&lt;/strong&gt; and &lt;strong&gt;t&lt;/strong&gt;. If the camera &quot;rotates around its gaze direction&quot;, &lt;strong&gt;g&lt;/strong&gt; will not be changing; that is what it means to &quot;rotate around its gaze direction&quot;. If &lt;strong&gt;g&lt;/strong&gt; isn't changing, and the camera's orientation is defined by two directions, then you can only get a different orientation if &lt;strong&gt;t&lt;/strong&gt; is changing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, your second statement is a contradiction of the first. Changing &lt;strong&gt;t&lt;/strong&gt; is &lt;em&gt;precisely how&lt;/em&gt; you cause the camera to &quot;rotate around its gaze direction&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To put it a different way, there are changes to &lt;strong&gt;t&lt;/strong&gt; which will &lt;em&gt;not&lt;/em&gt; affect the values of &lt;strong&gt;u&lt;/strong&gt;, &lt;strong&gt;v&lt;/strong&gt;, or &lt;strong&gt;w&lt;/strong&gt;. However, none of those changes will cause the camera to &quot;rotate around its gaze direction&quot;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-10-05T02:58:54.803" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8118" PostTypeId="2" ParentId="8114" CreationDate="2018-10-05T10:39:29.090" Score="1" Body="&lt;p&gt;A good introduction to finite element methods for deformable body animation is Sifakis and Barbič's course &lt;em&gt;&lt;a href=&quot;http://www.femdefo.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;FEM Simulation of 3D Deformable Solids&lt;/a&gt;&lt;/em&gt; from SIGGRAPH 2012.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, since you say&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I tried with a spring-mass system but the system become quickly instable, moreover it's computational expansive.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;you should know that a finite element model is usually &lt;em&gt;more&lt;/em&gt; expensive than a mass-spring system. If you're having problems with instability, you should try keeping your mass-spring system but (i) reducing the time step, or (ii) doing implicit integration; see the &quot;Implicit Methods&quot; chapter of the &lt;a href=&quot;https://www.pixar.com/assets/pbm2001/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Witkin and Baraff notes&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also consider &lt;a href=&quot;http://www.interactive-graphics.de/index.php/research/108-a-survey-on-position-based-dynamics-2017&quot; rel=&quot;nofollow noreferrer&quot;&gt;position-based dynamics&lt;/a&gt; or &lt;a href=&quot;https://www.projectivedynamics.org/Projective_Dynamics/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;projective dynamics&lt;/a&gt;, which are fast, stable, and easier to implement than FEM. They may be good enough for your needs, unless you require high accuracy or nonlinear material models.&lt;/p&gt;&#xA;" OwnerDisplayName="user106" LastEditorDisplayName="user106" LastEditDate="2018-10-10T08:14:48.547" LastActivityDate="2018-10-10T08:14:48.547" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8119" PostTypeId="1" CreationDate="2018-10-05T17:21:43.630" Score="1" ViewCount="140" Body="&lt;p&gt;&lt;strong&gt;What is the fastest known method for bucketing triangles into an unbounded regular 3D grid?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically, I need an array of buckets. Random queries (which bucket is here) are not necessary, as this is not for ray-tracing (though I will include the tag because of algorithm similarity). The triangles form a closed 2-manifold mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently, I'm inserting into grid cells that intersect the bounding box of the triangle (in my case, triangles are smaller than cells, so this is ok). I'm using a hash table for my grid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also tried outputting a list of (bucket-position, triangle-index) pairs and sorting them lexicographically, which has comparable performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus far, I've only tried CPU approaches. I'm thinking a faster method would be to produce the pairs on the GPU, then sort on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm having trouble finding directly relevant research papers (though it's easy to find papers on GPU sorting).&lt;/p&gt;&#xA;" OwnerUserId="9444" LastActivityDate="2018-10-05T17:21:43.630" Title="fastest way to bucket triangles into a grid?" Tags="&lt;raytracing&gt;&lt;mesh&gt;&lt;gpgpu&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8120" PostTypeId="2" ParentId="6278" CreationDate="2018-10-05T17:57:53.560" Score="4" Body="&lt;p&gt;I'd recommend using &lt;a href=&quot;http://www.openvdb.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenVDB&lt;/a&gt;. It's quite battle-tested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Use &lt;code&gt;meshToVolume&lt;/code&gt; to voxelize the mesh. Then use &lt;code&gt;volumeToMesh&lt;/code&gt; to produce a high-quality quad mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;meshToVolume&lt;/code&gt; voxelizes the mesh into a &lt;a href=&quot;https://en.wikipedia.org/wiki/Signed_distance_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;SDF&lt;/a&gt;. &lt;code&gt;volumeToMesh&lt;/code&gt; seems to use dual contouring / SurfaceNets.&lt;/p&gt;&#xA;" OwnerUserId="9444" LastActivityDate="2018-10-05T17:57:53.560" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8121" PostTypeId="1" AcceptedAnswerId="8138" CreationDate="2018-10-06T04:50:33.630" Score="2" ViewCount="73" Body="&lt;p&gt;A well-known property of Perlin noise (with FBM) is that if you take a slice of it, the result is still Perlin noise.  So, by taking successive slices of 4D  noise, you get smoothly shifting 3D noise, like a cloud or a lava lamp.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What other noises have this property?&lt;/p&gt;&#xA;" OwnerUserId="8288" LastActivityDate="2018-10-11T11:46:55.943" Title="What noises can be sliced?" Tags="&lt;animation&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8122" PostTypeId="1" AcceptedAnswerId="8124" CreationDate="2018-10-07T03:35:18.103" Score="2" ViewCount="119" Body="&lt;p&gt;To give context to the question, I am reading Peter Shirley's Ray Tracing in one weekend. In his code for sphere/ray intersection, when the quadratic formula returns only 1 solution, he discards it, which strikes me as odd. Is there any graphics theory that support it or is it just his personal preference?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the link to the code I am talking about on github.&#xA;&lt;a href=&quot;https://github.com/petershirley/raytracinginoneweekend/blob/master/sphere.h&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/petershirley/raytracinginoneweekend/blob/master/sphere.h&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8699" LastActivityDate="2018-10-07T17:36:59.567" Title="why doesn't a ray hitting a sphere at only 1 point count as a hit in sphere/ray intersection?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8124" PostTypeId="2" ParentId="8122" CreationDate="2018-10-07T17:36:59.567" Score="6" Body="&lt;p&gt;It is mainly personal preference, but it does have some logic behind it which would make it a better option. It should not have any big impact on your final image, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the discriminant is 0, then that means that there is only one solution. For a sphere, when there is only one solution, that means that the ray is tangent to the sphere. When a line or ray is tangent to a sphere, that means that there is a 90° angle between the line/ray and the normal of the sphere at the intersection. When comparing that situation to ray-triangle and ray-plane intersections, they always ignore the hit when it has an angle of 90° with the normal. This is because the ray would then not really be able to hit it, and in real life you cannot see an infinitely thin plane or triangle that is perfectly parallel to your viewing direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Discarding hits when the angle is 90° could also help with shading. Depending on the shader, a 90° angle might always return black or start giving funky results, while when the angle is less than 90° it is just perfectly fine. Also as @Rahul has said, if you would calculate a reflected ray, it would end up in the same direction as your original ray and with most shaders that reflection ray would contribute to 100% of the ray's colour and not be coloured, so it would give the exact same colour as if you just discarded the ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing that makes this basically personal preference, is the fact that it would practically not happen that a ray would hit the sphere perfectly tangent, in an average render engine (as Rahul has also said). When looking at a sphere from a certain point, there would be a single circle with an infinitely small thickness that could create the occurrence of the discriminant being 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, it basically does not matter a single bit if you discard those hits or not. &lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-10-07T17:36:59.567" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8125" PostTypeId="1" CreationDate="2018-10-07T23:09:49.020" Score="-1" ViewCount="173" Body="&lt;p&gt;I'm currently taking a Computer Graphics class at university, and have been given an assignment which involves loading an obj file and manipulating it with keyboard and mouse controls (eg. arrow keys translate, mouse wheel for zoom, hold mouse and drag for rotation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Being new to OpenGL, I'm a bit overwhelmed by the project on hand, and would really appreciate if anyone could give me some tips regarding implementation of this project. Our previous (and first) project involved creating a clock based on system time, which was relatively straightforward, using simple rotation/translation techniques on OpenGL primitive objects created within the draw() function. I was able to easily figure out and understand this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main questions I have are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Within the draw() function, how do I take the changes made by the keyboard/mouse and apply them to the object? More specifically, what exactly should be going on here in relation to the input methods?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Draw() &#xA;{&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);     // Clear The Screen And The Depth Buffer&#xA;&#xA;// Write your own code below (Hint:Translation Rotation &amp;amp; Scaling)&#xA;&#xA;&#xA;// Write your own code above&#xA;&#xA;&#xA;if (obj_data != NULL)&#xA;    obj_data-&amp;gt;Draw();&#xA;else&#xA;    glutSolidTeapot(1.0);   //draw a teapot when no argument is provided&#xA;&#xA;glFlush();&#xA;glutSwapBuffers();&#xA;&#xA;// Write your own code below (Hint:reset translate and scale value)&#xA;&#xA;&#xA;// Write your own code above&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;How does the mouseMotion() method work? More specifically, how might I go about getting the coordinates of the mouse location and use them within the program?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void mouseMotion(int x, int y)&#xA;{&#xA;//code here&#xA;glutPostRedisplay();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I know this may be a vague and/or ambiguous question, but I really do not know where to start on this. My professor has not given much information as to how to implement this, and any pointers or tips that may guide me in the right direction would be incredibly appreciated!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just so you know, I'm not posting this here for an easy answer so I can copy/paste. I'm mainly looking for a greater understanding of how OpenGL works, especially in relation to user input!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: The full source code for the project can be found &lt;a href=&quot;https://pastebin.com/fKEH9zkm&quot; rel=&quot;nofollow noreferrer&quot;&gt;here.&lt;/a&gt; There is also an objLoader.cpp file as well used to load a predrawn object into the workspace.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let me know if more clarification is required. I've tried my best to consolidate this into smaller questions that might help me understand the project as a whole.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks again!&lt;/p&gt;&#xA;" OwnerUserId="9467" LastActivityDate="2018-10-09T09:48:24.337" Title="Relatively new to OpenGL, need guidance/tips on an assignment with interactive user input" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;c++&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8126" PostTypeId="2" ParentId="8125" CreationDate="2018-10-08T07:44:21.030" Score="2" Body="&lt;p&gt;OpenGL itself is purely a graphics library.  It doesn't give you access to keyboard input.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;However,&lt;/em&gt; if you're using OpenGL, you're also probably using a cross-platform &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Related_toolkits_and_APIs#Context.2FWindow_Toolkits&quot; rel=&quot;nofollow noreferrer&quot;&gt;context/window toolkit&lt;/a&gt; to create a desktop window and set up an OpenGL context for drawing into that window.  These toolkits usually also give you basic keyboard and mouse input.  (The idea is, I guess, if they're abstracting platform-specific window creation, they may as well abstract platform-specific window input at the same time.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your context toolkit looks to be FreeGLUT, so you should refer to the &lt;a href=&quot;http://freeglut.sourceforge.net/docs/api.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;FreeGLUT documentation&lt;/a&gt; for details.&lt;/p&gt;&#xA;" OwnerUserId="8288" LastActivityDate="2018-10-08T07:44:21.030" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8130" PostTypeId="1" AcceptedAnswerId="8146" CreationDate="2018-10-09T00:34:25.087" Score="4" ViewCount="394" Body="&lt;p&gt;I'm following Peter Shirley book, Ray tracing in one weekend. In the last chapter, he talks about how to make defocus blur by using thin len approximation. His camera class accepts a parameter called focus_dist, which he then uses to compute the distance to the image plane. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;lower_left_corner = origin  - half_width*focus_dist*u -half_height*focus_dist*v - focus_dist*w; // lower_left_corner of image plane&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This subject was new to me, so I went searching around online. From what i understand, the distance to the image plane is governed by the equation 1/f = 1/d + 1/d prime with f being focal length and d being the focus distance. d prime will be the answer. The lack of this equation in Peter Shirley's code and the fact that he seems to be putting the image plane at the focus distance makes me completely lost. Can anyone explain it to me?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the link to the code I talked about. &#xA;&lt;a href=&quot;https://github.com/petershirley/raytracinginoneweekend/blob/master/camera.h&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/petershirley/raytracinginoneweekend/blob/master/camera.h&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8699" LastEditorUserId="8699" LastEditDate="2018-10-09T00:42:01.767" LastActivityDate="2019-07-18T17:57:19.937" Title="Defocus blur: Computing the pixel plane distance" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8131" PostTypeId="1" CreationDate="2018-10-09T05:19:14.777" Score="1" ViewCount="250" Body="&lt;p&gt;I am currently experiencing a very obvious artifact that occurs when looking at objects on very grazing angles&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a picture of the artifact:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZNQL3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZNQL3.png&quot; alt=&quot;artifact&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I noticed that the issue was coming from my implementation of Cook-Torrance's Specular BRDF. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the equation for the Cook-Torrance Specular BRDF: &#xA;&lt;a href=&quot;https://imgur.com/a/f6da9ZG&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://imgur.com/a/f6da9ZG&quot; alt=&quot;Cook-Torrance Specular BRDF&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More specifically, calculating the denominator is causing the issue:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float denominator = 4 * max(dot(viewDir, normal), 0.0) * max(dot(lightDir, normal), 0.0) + 0.001;  // Prevents any division by zero&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I change the calculation of dot(viewDir, normal) to dot(halfway, normal), the artifact disappears:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float denominator = 4 * max(dot(halfway, normal), 0.0) * max(dot(lightDir, normal), 0.0) + 0.001;  // Prevents any division by zero&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this equation is no longer correct. I was wondering if anyone knows why my implementation causes these artifacts?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to see my fragment shader you can find the code here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Ershany/Arcane-Engine/blob/WIP_PBR/Arcane%20Engine%20Core/src/shaders/pbr_model.frag&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Ershany/Arcane-Engine/blob/WIP_PBR/Arcane%20Engine%20Core/src/shaders/pbr_model.frag&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="8893" LastEditorUserId="8893" LastEditDate="2018-11-08T19:44:54.610" LastActivityDate="2018-11-08T19:44:54.610" Title="Normal Artifacts On Grazing Angles" Tags="&lt;brdf&gt;&lt;specular&gt;&lt;normal-mapping&gt;&lt;artifacts&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8132" PostTypeId="2" ParentId="8125" CreationDate="2018-10-09T09:42:34.980" Score="1" Body="&lt;p&gt;OpenGL is  is a cross-language, cross-platform application programming interface (API), and it acts as a bridge between your CPU and your GPU.&lt;/p&gt;&#xA;&lt;p&gt;It's not an input handling library, since that is something that is OS specific (on Windows for instance you would use DirectInput) and that has nothing to do with the GPU.&lt;/p&gt;&#xA;&lt;p&gt;Now, as stated by the other answers, you are probably using a framework to handle context creation, setting up the pixelFormatDescriptor and creating the OS window (you would use the Win32 api on Windows), like Freeglut.&lt;/p&gt;&#xA;&lt;p&gt;Freeglut at this point in time, is quite outdated (and probably not even supported anymore, i can't remember correctly).&#xA;GLFW on the other hand, is a very well maintained and documented library for both input and window handling (that also includes context creation).&#xA;In addition to that, the brand new Vulkan API is also avaiable for use.&#xA;Input and Window handling is done through callbacks with a very intuitive API.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.glfw.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLFW&lt;/a&gt; is written in C and licenced under the z-lib licence.&lt;/p&gt;&#xA;" OwnerUserId="9436" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-10-09T09:48:24.337" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8133" PostTypeId="1" CreationDate="2018-10-10T03:59:43.720" Score="0" ViewCount="106" Body="&lt;p&gt;If I had two right handed frames where one has vectors [i, j, k] and another with corresponding vectors [u v w], how would I derive the transform M[i j k] &amp;lt;-- [u v w] when applied to any point P in [u v w] we get its representation in [i j k] ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They noted that for every unit we move in the [i j k] frame we move 2 units in the [u v w] frame and the origin of the [u v w] frame can be represented as [4i 6j 2k]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone help me derive this? I'm fairly new to computer graphics and need some help in detail.&lt;/p&gt;&#xA;" OwnerUserId="9482" LastActivityDate="2018-11-09T11:02:00.390" Title="How do I derive this transformation" Tags="&lt;transformations&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8135" PostTypeId="2" ParentId="8133" CreationDate="2018-10-10T10:21:22.357" Score="1" Body="&lt;p&gt;I'm not going to dive into much details about affine transformations and such, you are better off reading up on these concepts from good graphics books.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think The matrix you need is this. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}&#xA;0.5 &amp;amp; 0 &amp;amp; 0 &amp;amp; 4\\&#xA;0 &amp;amp; 0.5 &amp;amp; 0 &amp;amp; 6\\&#xA;0 &amp;amp; 0 &amp;amp; 0.5 &amp;amp; 2\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\\&#xA;\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason why we need 4x4 matrices is because of affine transformations. For more details on why we have 4x4 matrices and why are we using 4D representation you can check my answer &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/6271/what-is-the-use-of-homogenous-divide/6275#6275&quot;&gt;here&lt;/a&gt;. Briefly speaking, Vectors representing direction have an extra &lt;code&gt;0&lt;/code&gt; at the end since translations don't affect these sort of vectors and Vectors representing points have an extra &lt;code&gt;1&lt;/code&gt; at the end. This makes our vectors 4D so we can apply 4x4 transformation matrices. Since here we are concerned with points we will append an extra &lt;code&gt;1&lt;/code&gt; to each vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's begin by how did I derive it. First of all we can see that they provided the origin of the &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; frame in terms of &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt; frame. This is &lt;span class=&quot;math-container&quot;&gt;$[4i, 6j, 2k]$&lt;/span&gt;. In other words the vector &lt;span class=&quot;math-container&quot;&gt;$[0,0,0]$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; frame must correspond to &lt;span class=&quot;math-container&quot;&gt;$[4i, 6j, 2k]$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt; frame. Let's forget the 0.5's in the diagonal for now. We have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 4\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 6\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 2\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\\&#xA;\end{bmatrix}&#xA;* &#xA;\begin{bmatrix}&#xA;0\\&#xA;0\\&#xA;0\\&#xA;1\\&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;4\\&#xA;6\\&#xA;2\\&#xA;1\\&#xA;\end{bmatrix} $&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next the condition is if we move 1 unit in &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt; we move 2 units in &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; or in other words if we move 1 unit in &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; we move 0.5 units in &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt;. This means if we move from origin to &lt;span class=&quot;math-container&quot;&gt;$[1,1,1]$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; we moved half a unit in the &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt; frame in each of the axis. Testing the original matrix now we have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}&#xA;0.5 &amp;amp; 0 &amp;amp; 0 &amp;amp; 4\\&#xA;0 &amp;amp; 0.5 &amp;amp; 0 &amp;amp; 6\\&#xA;0 &amp;amp; 0 &amp;amp; 0.5 &amp;amp; 2\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\\&#xA;\end{bmatrix}&#xA;* &#xA;\begin{bmatrix}&#xA;1\\&#xA;1\\&#xA;1\\&#xA;1\\&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;4.5\\&#xA;6.5\\&#xA;2.5\\&#xA;1\\&#xA;\end{bmatrix} $&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When constructing matrices this way, you want the translation factor in the last column. This factor is given to you by telling you the origin of the &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; frame in terms of &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt; frame. This means the &lt;span class=&quot;math-container&quot;&gt;$UVW$&lt;/span&gt; frame is that much displaced/translated when viewed from &lt;span class=&quot;math-container&quot;&gt;$IJK$&lt;/span&gt; frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Secondly any scaling factor goes along the diagonal like above. This factor was given to you by telling you &quot;If you move &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; units in 1 frame, you move &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; units in the other&quot;.&#xA;Which is what we want I guess. Is that what you need?&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-10-10T10:21:22.357" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8136" PostTypeId="1" CreationDate="2018-10-10T15:49:56.947" Score="5" ViewCount="215" Body="&lt;p&gt;I am trying to render implicit surfaces given by a polynomial equation &lt;span class=&quot;math-container&quot;&gt;$F(x,y,z) = 0$&lt;/span&gt; using &lt;a href=&quot;https://en.wikipedia.org/wiki/Sturm%27s_theorem&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sturm's theorem&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Plugging the parametric ray equation &lt;span class=&quot;math-container&quot;&gt;$r(t) = o + td$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$o\in\mathbb{R}^3$&lt;/span&gt; is the ray origin and &lt;span class=&quot;math-container&quot;&gt;$d\in\mathbb{R}^3\backslash\{0\}$&lt;/span&gt; is the ray direction,  into &lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt; yields a polynomial equation &lt;span class=&quot;math-container&quot;&gt;$p(t) = 0$&lt;/span&gt; for the intersections of the ray with the surface. I noticed that the straightforward implementation of calculating a Sturm sequence as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$p_0 = p, \\ p_1 = p', \\ p_{i} = -\text{rem}(p_{i-2},p_{i-1}) \quad\forall i\ge2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is numerically unstable. When rendering a torus for example, the equation for one particular ray in my program was&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$p(t) := t^4 + 0.00329589844t^2 - 660.766052t + 9627.17676 = 0.$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In single precision, the associated Sturm sequence is computed as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$p_0(t) = t^4 + 0.00329589844t^2 - 660.766052t + 9627.17676,\\&#xA;  p_1(t) = 4t^3+0.00659179688t-660.766052,\\&#xA;  p_2(t) = -0.001647949220t^2+495.5745390t-9627.17676,\\&#xA;  p_3(t) = -3.617114498\cdot 10^{11}t+7.027166964\cdot 10^{12},\\&#xA;  p_4(t) = 0,$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which indicates that (up to multiplicity) &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; has exactly one real root. But in fact &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; has no real roots, which can easily be verified with a computer algebra system. If the same computation is done with higher precision, it turns out that &lt;span class=&quot;math-container&quot;&gt;$p_4(t)\approx 0.000039&amp;gt;0$&lt;/span&gt;. In this case the correct number of roots is calculated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there anything that can be done to avoid this problem when calculating a Sturm sequence?&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastEditorDisplayName="user9485" LastEditDate="2018-10-10T21:56:12.820" LastActivityDate="2021-02-22T11:02:40.197" Title="Ray tracing implicit surfaces using Sturm's theorem" Tags="&lt;raytracing&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8137" PostTypeId="2" ParentId="8068" CreationDate="2018-10-11T04:59:29.623" Score="3" Body="&lt;p&gt;You can use CloudCompare or MeshLab to generate a mesh from a point cloud using many algorithms. In my experience, marching-cube method results in accurate meshes.&lt;/p&gt;&#xA;" OwnerUserId="8484" LastActivityDate="2018-10-11T04:59:29.623" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8138" PostTypeId="2" ParentId="8121" CreationDate="2018-10-11T11:15:56.943" Score="2" Body="&lt;p&gt;&lt;a href=&quot;http://www.rhythmiccanvas.com/research/papers/worley.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Worley noise&lt;/a&gt;, also known as &lt;a href=&quot;https://thebookofshaders.com/12/&quot; rel=&quot;nofollow noreferrer&quot;&gt;cellular noise&lt;/a&gt;, has the same property. It just as easily implemented as Perlin noise and easily extends to higher dimensions. Thus the slicing of 4D Worley noise will produce a 3D Worley noise. However, it is not necessarily a noise function but rather a texture function, producing cellular-like characteristics. With FBM applied to Worley noise some interesting patterns can be created.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find additional types of procedural noise functions in &lt;a href=&quot;http://graphics.cs.kuleuven.be/publications/LLCDDELPZ10STARPNF/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; survey paper. &lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2018-10-11T11:46:55.943" LastActivityDate="2018-10-11T11:46:55.943" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8139" PostTypeId="2" ParentId="7860" CreationDate="2018-10-11T15:06:22.740" Score="1" Body="&lt;p&gt;CloudCompare has statistical outlier removal (called SOR) function that can eliminate all lonely points for you. I would filter each *.ply first and then try to carry out a cloud to cloud registration. For registration, you can use MeshLab or use 30 days trails of commercially available software such as Faro Scene. Scene won't accept *.ply file though, so you need to convert your files to *.e57 first. Good luck. &lt;/p&gt;&#xA;" OwnerUserId="8484" LastEditorUserId="8484" LastEditDate="2018-10-12T19:16:54.960" LastActivityDate="2018-10-12T19:16:54.960" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8140" PostTypeId="1" AcceptedAnswerId="8141" CreationDate="2018-10-11T17:39:41.710" Score="1" ViewCount="58" Body="&lt;p&gt;I need to store user-drawn images from an online whiteboard. The amount of data gets huge quickly which is obviously not good. What I need is to store something drawn through a tablet for example in as little space as possible without too much of accuracy loss as for example letters should be distiniguishable. Bonus points for a solution with the ability to determine when what was drawn.&lt;/p&gt;&#xA;" OwnerUserId="9495" LastActivityDate="2018-10-12T10:04:49.380" Title="Compression of user-drawn &quot;whiteboard&quot; image" Tags="&lt;compression&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8141" PostTypeId="2" ParentId="8140" CreationDate="2018-10-12T10:04:49.380" Score="2" Body="&lt;p&gt;Don't store the rasterized image instead store the drawn strokes as vector graphics. Those should compress pretty well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Adding timestamps to each stroke should then be very simple.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can caching the rasterized image during execution to avoid needing to rerender every stroke every frame.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-10-12T10:04:49.380" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8144" PostTypeId="2" ParentId="7932" CreationDate="2018-10-12T19:14:00.353" Score="0" Body="&lt;p&gt;One other solution is to identify the vector's endpoint with respect to the point P. Then, rotate the endpoint as desired and recompute the new vector based on the rotated endpoint and the point P.&lt;/p&gt;&#xA;" OwnerUserId="8484" LastActivityDate="2018-10-12T19:14:00.353" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8145" PostTypeId="2" ParentId="7577" CreationDate="2018-10-13T10:53:22.290" Score="1" Body="&lt;p&gt;One way to visualize an object's bounding box would be like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\hskip2.5in$&lt;/span&gt;&lt;a href=&quot;https://i.stack.imgur.com/hhNw4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hhNw4.png&quot; alt=&quot;Bounding box&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Rahul mentioned in a comment, you can achieve this by adding a total of 12 cylinders at the edges of the bounding box, connecting the spheres at the corners.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to render the bounding box transparently, I don't see an easy way to hide the intersections of the spheres and cylinders without knowing what program you are using. You could try to use partial spheres for the corners and see if that helps, i.e.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\hskip2.5in$&lt;/span&gt;&lt;a href=&quot;https://i.stack.imgur.com/c3sAn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c3sAn.png&quot; alt=&quot;Partial sphere&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe this is already sufficient for your purpose. (This is exactly 1/8th of a full sphere.)&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastActivityDate="2018-10-13T10:53:22.290" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8146" PostTypeId="2" ParentId="8130" CreationDate="2018-10-13T20:58:34.520" Score="4" Body="&lt;p&gt;You don't need that equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You know your focus point (point on y-axis with focus_distance as z component) and the ray origin. All that needs to be done then is to compute the ray direction from the origin through that focus point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For what it's worth, I think a camera space formulation of a thin lens makes it easier to understand the concept:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float fov = 2.0f * atan((sensorWidth / (2.0f * focal_length))); // in radians&#xA;float tan_fov = tanf(fov / 2.0f);&#xA;&#xA;// create point on lens, screen space samples are in [-1, 1] domain&#xA;vec3 p(screen_space_sample_x * tan_fov, screen_space_sample_y * tan_fov, 1.0);&#xA;&#xA;// calculate direction vector from origin to point on lens&#xA;dir = normalize(p - origin);&#xA;&#xA;// get uniformly distributed points on the unit disk&#xA;vec2 lens(0.0, 0.0);&#xA;concentricDiskSample(random1, random2, &amp;amp;lens);&#xA;&#xA;// scale points in [-1, 1] domain to actual aperture radius&#xA;lens *= apertureRadius;&#xA;&#xA;// new origin is these points on the lens&#xA;origin.x = lens.x;&#xA;origin.y = lens.y;&#xA;origin.z = 0.0;&#xA;&#xA;// Compute point on plane of focus, intersection on z axis&#xA;float intersection = std::abs(focus_distance / dir.z);&#xA;vec3 focusPoint = dir * intersection;&#xA;dir = normalize(focusPoint - origin);&#xA;&#xA;// now looking down -Z (optional depending on your coordinate system)&#xA;dir.z *= -1.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9505" LastEditorUserId="9505" LastEditDate="2018-10-13T21:18:01.693" LastActivityDate="2018-10-13T21:18:01.693" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8147" PostTypeId="1" AcceptedAnswerId="8150" CreationDate="2018-10-14T12:37:19.387" Score="0" ViewCount="88" Body="&lt;p&gt;I'm caching distances for SDF functions in volume textures for faster rendering, and I'd like to use trilinear interpolation for smoother edges. I know that I'll need distance values at each corner; can I blend adjacent voxels, or will I need to store eight separate distances in each sample?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-10-14T22:48:36.847" LastActivityDate="2018-10-15T19:14:03.233" Title="Choosing corner values for trilinear interpolation" Tags="&lt;interpolation&gt;&lt;sampling&gt;&lt;volumetric&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8148" PostTypeId="5" CreationDate="2018-10-14T17:01:41.520" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2018-10-14T17:01:41.520" LastActivityDate="2018-10-14T17:01:41.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8149" PostTypeId="4" CreationDate="2018-10-14T17:01:41.520" Score="0" Body="OpenCL (Open Computing Language) is a framework for writing programs that execute across heterogeneous platforms consisting of CPUs, GPUs, DSPs, FPGAs and other processors or hardware accelerators. " OwnerDisplayName="user7220" LastEditorDisplayName="user7220" LastEditDate="2018-10-14T18:30:28.897" LastActivityDate="2018-10-14T18:30:28.897" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8150" PostTypeId="2" ParentId="8147" CreationDate="2018-10-15T19:14:03.233" Score="1" Body="&lt;p&gt;As a rule, SDFs do much better under interpolation than regular images do—it’s why you can mostly get away with using tiny textures for e.g. font data. You should be fine interpolating neighboring voxels.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-10-15T19:14:03.233" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8151" PostTypeId="1" CreationDate="2018-10-16T06:00:28.530" Score="4" ViewCount="537" Body="&lt;p&gt;I wish to understand the specific application of Multiple Importance Sampling (MIS) to weighting BSDF sampling and light sampling together.&#xA;Refer to the following diagram from &lt;a href=&quot;https://graphics.stanford.edu/courses/cs348b-03/papers/veach-chapter9.pdf&quot; rel=&quot;noreferrer&quot;&gt;these Stanford course notes&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UnvBZ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UnvBZ.png&quot; alt=&quot;Multiple Importance Sampling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand the source of noise in the left diagram &lt;strong&gt;(a)&lt;/strong&gt;, but not in the right &lt;strong&gt;(b)&lt;/strong&gt;, and I think this stems from understanding what &quot;sampling the BSDF&quot; means, but not understanding what &quot;sampling the light sources&quot; means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To confirm my understanding I'm going to grossly simplify the general path tracing procedure, and specialize it to a single bounce in this scene, to get the point across:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;BSDF sampling (diagram &lt;strong&gt;(a)&lt;/strong&gt;) procedure:&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Cast a ray from the camera for a given pixel.&lt;/li&gt;&#xA;&lt;li&gt;Upon hitting the glossy surface, sample the surface's BSDF, then continue along the newly sampled ray.&lt;/li&gt;&#xA;&lt;li&gt;Hopefully, you hit the light, in which case you contribute energy to the given pixel.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This will obviously yield the noise profile we see in diagram &lt;strong&gt;(a)&lt;/strong&gt;; the noise goes down as the surface gets glossier (sharpening the distribution of the BSDF) and as the light gets bigger (making the target easier to hit by chance).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I don't understand the nature of the noise in diagram &lt;strong&gt;(b)&lt;/strong&gt;, and I therefore clearly don't understand what &quot;sampling the light source&quot; means. My guess would be a procedure like:&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Light source sampling (diagram &lt;strong&gt;(b)&lt;/strong&gt;) procedure(???):&lt;/h2&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Cast a ray from the camera for a given pixel.&lt;/li&gt;&#xA;&lt;li&gt;Upon hitting the glossy surface, uniformly sample the solid angle that subtends the light source (i.e., a &quot;shadow ray&quot;), then continue along the newly sampled ray.&lt;/li&gt;&#xA;&lt;li&gt;If you hit the light (i.e., no obstructions) contribute energy to the given pixel, weighted inversely by the BSDF of the glossy surface evaluated at the shadow ray, (and probably also multiplied by some other weight representing the fraction of our total solid angle that the light takes up, as in regular importance sampling).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;(Again, I have grossly simplified, and have reduced the problem to a single bounce in this particular scene for illustrative purposes.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the procedure I have described above cannot possibly be what is meant by &quot;light source sampling&quot; in the linked paper, because then it wouldn't result in more noise with larger area lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's going on in diagram &lt;strong&gt;(b)&lt;/strong&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; I suddenly understood the issue. The noise in the top right corner of &lt;strong&gt;(b)&lt;/strong&gt; is because it's struggling to find the tiny fraction of angles in which the BSDF is not extremely close to zero. My assertion &quot;... because then it wouldn't result in more noise with larger area lights&quot; is precisely wrong, because larger area lights correspond to sampling over a larger fraction of the solid angle, and thus sampling the inverse BSDF weights with higher variance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm now looking for how to delete my question. Hitting the &quot;flag&quot; button just sends me to the top of the page, and doesn't do anything else...&lt;/p&gt;&#xA;" OwnerUserId="9513" LastEditorUserId="9513" LastEditDate="2018-10-16T06:35:03.390" LastActivityDate="2020-12-08T02:00:40.090" Title="BSDF sampling versus light sampling" Tags="&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8152" PostTypeId="1" AcceptedAnswerId="8163" CreationDate="2018-10-16T08:27:04.653" Score="13" ViewCount="3763" Body="&lt;p&gt;sRGB is often contrasted with &quot;linear RGB.&quot;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Images are stored on disk and passed to displays in &lt;strong&gt;sRGB,&lt;/strong&gt; which is approximately perceptually uniform in intensity.&lt;/li&gt;&#xA;&lt;li&gt;Shader math is done in &lt;strong&gt;linear RGB,&lt;/strong&gt; which is physically uniform in intensity.&lt;/li&gt;&#xA;&lt;li&gt;Gamma correction can be applied to convert between the two.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Now, sRGB has a standard that colorimetrically specifies its gamut, saying exactly where pure red, green, blue and white lie.  But there is no corresponding standard for just &quot;linear RGB.&quot;  &lt;em&gt;Any&lt;/em&gt; triangle on a chromaticity diagram could be said to be linear, and, indeed, there are several well known gamuts to choose from:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gJHM8.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gJHM8.png&quot; alt=&quot;RGB gamuts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice, when we say &quot;linear RGB,&quot; we mean &quot;sRGB without the gamma correction.&quot;  (This is implicitly what we're doing when we apply sRGB gamma correction as a final post-processing step but ignore color spaces for the rest of the rendering pipeline.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But why is &lt;em&gt;that&lt;/em&gt; RGB gamut the correct one to use for interpolation and lighting calculations?  It seems arbitrary.  If anything, wouldn't we want to use the largest possible gamut for internal calculations, and then clip or scale colors to the output device's gamut at the very end?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it that RGB lighting is going to be approximate no matter what, so it doesn't matter which gamut we pick, and we may as well pick the one closest to what the display natively supports?  Is it just negligence?  Or do calculations in these different gamuts actually yield the exact same results, somehow?&lt;/p&gt;&#xA;" OwnerUserId="8288" LastActivityDate="2018-10-21T04:49:23.513" Title="For shader math, why should linear RGB keep the gamut of sRGB?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;color&gt;&lt;physically-based&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8153" PostTypeId="1" CreationDate="2018-10-16T16:13:27.120" Score="3" ViewCount="258" Body="&lt;p&gt;I am building an algorithm which takes a bitmap image as input and render the image as an embroidery design. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The different steps are : &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Vectorize the image, I keep only 5 colors  (Done) &lt;/li&gt;&#xA;&lt;li&gt;Generate&#xA;stitches lines (Done) &lt;/li&gt;&#xA;&lt;li&gt;Apply wire embroidery texture to the lines,&#xA;add lights and show a realistic rendering ( It's this step that I am&#xA;having trouble with)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Let's take an example.&#xA;The original image is : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/jUzQwCZ.png&quot; alt=&quot;Original image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From there, I vectorize the image and obtain an SVG file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After that, I generate stitches lines automatically which you can find here (svg file): &lt;a href=&quot;https://www.dropbox.com/s/jmi6rz1ixgkjjpb/flowers_fill_0.7_vLongShort_space_randomLength.svg?dl=0&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.dropbox.com/s/jmi6rz1ixgkjjpb/flowers_fill_0.7_vLongShort_space_randomLength.svg?dl=0&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you zoom in, it looks like this : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/vfIaHV3.png&quot; alt=&quot;stitches&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I export the svg as png, I get : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/l3vqawX.png&quot; alt=&quot;ExportPng&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see; having this result is not enough to render realistically the embroidery design. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am looking to have a texture more like this : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://s3.amazonaws.com/threadsmagazine.s3.tauntoncloud.com/app/uploads/4411/86/11133110/86-machine-embroidery-03.jpg&quot; alt=&quot;Real&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried generating a normal map and the use it adds some depth, but again, the result looks very plastic ... : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/0QLi5SO.png&quot; alt=&quot;Rendering with normal map&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know what I should do now to have a realistic rendering ...&#xA;At first, it wasn't supposed to be a computer graphic problem so I am not a specialist in the area, but I think using webgl or opengl is the best choice. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I don't know how to give the rights textures to the lines ...&lt;/p&gt;&#xA;" OwnerUserId="9515" LastEditorUserId="9515" LastEditDate="2018-10-16T16:30:21.083" LastActivityDate="2018-10-20T16:06:47.707" Title="How to apply wire texture for realistic rendering of embroidery?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;texture&gt;&lt;2d-graphics&gt;&lt;three.js&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8154" PostTypeId="2" ParentId="8152" CreationDate="2018-10-16T16:13:36.600" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;In practice, when we say &quot;linear RGB,&quot; we mean &quot;sRGB without the gamma correction.&quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It would be more correct to say that there is the &quot;sRGB colorspace&quot; and the &quot;linearized sRGB colorspace&quot;, with the sRGB specification definition the conversion from one to another.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, there are infinitely many &quot;linear RGB&quot; color spaces. But the thing that all of these &quot;linear RGB&quot; colorspaces have in common is that they are &lt;em&gt;linear&lt;/em&gt;. This means that, if you double the value of any component, you double the intensity of the light that the component represents. That's essentially what it means to be &quot;linear&quot;: there is a linear mapping between color values and the resulting intensity of that light color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is important because lighting equations don't work if the color values do not linearly map to light intensities. But the equations don't care &lt;em&gt;which&lt;/em&gt; linear colorspace you use; you just have to pick one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the linearized sRGB colorspace is not more correct than a linearized Adobe RGB colorspace or a linearized SWOP CMYK colorspace. What matters is precisely two things:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The colorspace represents a linear mapping of values to light intensities.&lt;/li&gt;&#xA;&lt;li&gt;The colorspace chosen is &lt;em&gt;consistently&lt;/em&gt; used in the lighting equation. That is, all colors used in the lighting equation come from the same (linear) colorspace.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it that RGB lighting is going to be approximate no matter what, so it doesn't matter which gamut we pick, and we may as well pick the one closest to what the display natively supports?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That, and the fact that sRGB conversion is built into hardware these days, while other colorspace conversion frequently is not. So if you want to use linearized Adobe RGB colorspace, you have to do a lot of work in your shaders to linearize the texel values and perform bilinear/trilinear interpolation on them correctly (which needs to be done after linearization) before you can even apply them to the lighting equation. And then you have to do the conversion from linearized Adobe RGB to linearized sRGB, so that you can write to an sRGB framebuffer image for display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or you can just use linearized sRGB everywhere and have performance. The latter tends to win out.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-10-16T16:13:36.600" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8156" PostTypeId="1" AcceptedAnswerId="8411" CreationDate="2018-10-17T17:15:37.017" Score="2" ViewCount="121" Body="&lt;p&gt;Assume the screen is axis aligned with origin at 0 and there is absolutely no view transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;in other words we will simply try to project the model onto the screen  plane following perspective. Say our FOV is 60 degrees, so the focal length is tan(30).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am given a vertex &lt;span class=&quot;math-container&quot;&gt;$V=(x,y,z)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is the projected vertex &lt;span class=&quot;math-container&quot;&gt;$V_p = V/(z*tan(30))$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$V_p = V/(z/tan(30))$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-12-20T12:59:08.370" Title="Computing perspective directly" Tags="&lt;rendering&gt;&lt;geometry&gt;&lt;projections&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8157" PostTypeId="1" AcceptedAnswerId="8218" CreationDate="2018-10-18T16:54:45.563" Score="4" ViewCount="203" Body="&lt;p&gt;I'm reading through &lt;a href=&quot;https://books.google.co.uk/books?id=8zX-2VRqBAkC&amp;amp;printsec=frontcover&amp;amp;dq=polygon%20mesh%20processing&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0ahUKEwip4tz8t5DeAhUrL8AKHZHQCcsQ6AEIKTAA#v=onepage&amp;amp;q=polygon%20mesh%20processing&amp;amp;f=false&quot; rel=&quot;noreferrer&quot;&gt;Polygon Mesh Processing&lt;/a&gt;, section 4.3 (Surface fairing).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reference I mentioned defined defines &quot;Surface Fairing&quot; as&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The goal of surface fairing is to compute shapes that are as smooth as possible... in general fair surface should follow the principle of simplest shapes, the surfaces should be free by any unnecessary details or oscillation&quot;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It continues...&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;This can be modeled by a suitable energy that penalizes unaesthetic behavior of the surface. A minimization of this fairness energy - subject to user defined constraints - eventually yields to the desired shape.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The energy defined is function of a surface &lt;span class=&quot;math-container&quot;&gt;$x : \Omega \to \mathcal{S}$&lt;/span&gt; and the form is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;E_M(x) = \int_{\Omega} \sqrt{det(\bf{I})}dudv&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$\bf{I}$&lt;/span&gt; is the first fundamental form, however instead of this the dirichlet energy&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\tilde{E}_M(x) = \int_{\Omega} \lVert x_u \rVert^2 + \lVert x_v \rVert^2 dudv&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the one usually used. Higher order energies are also used, depending on how smooth is the shape we're looking for. Using the Euler-Lagrange equation (in a continuous setting) we end up with the simple PDE&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\Delta x = 0,&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;subject to suitable boundary conditions. Discretazion to meshes is done by means of the Laplace-beltrami operator which I'll define below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general it is my understanding that everything boils down to solve a problem of the form&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\Delta^k x = 0&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$x = x(u,v)$&lt;/span&gt; is our surface. If we descretize to a mesh the equation above might be rewritten as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L^k x = 0&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$L^k$&lt;/span&gt; is the &lt;span class=&quot;math-container&quot;&gt;$k^{th}$&lt;/span&gt; power of the Laplacian matrix, and &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; itself is defined using the Discrete Laplace Beltrami operator, which is something like&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\Delta x = \frac{1}{2A_T} \sum_{j} (cotg (\alpha_{i,j}) + cotg (\beta_{i,j}))(x_j - x_i)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However despite the fact it might be very simple to understand in principle at least I'm trying to figure how this would be implemented.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is because to me the angles depends from the mesh vertices and therefore the system isn't actually linear. The other approach I was thinking is to use a gradient flow (diffusion) approach of the form&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{\partial x}{\partial t} = -\Delta^k x&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the above, in principle can be discretized as follows&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;x(t + h) = x(t) - h L^k x(t)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; might be computed on the current known state of the surface &lt;span class=&quot;math-container&quot;&gt;$x(t)$&lt;/span&gt;, however the above is an explicit integrator which might lead to instability, and solving the issue would be done by solving&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;(id + h L^k) x(t + h) = x(t)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in such case there's the problem of &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; which would depend from the unknown state &lt;span class=&quot;math-container&quot;&gt;$x(t+h)$&lt;/span&gt;, so the problem I'm having here is actually similar to the first one I exposed...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the actual question is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the mesh &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is unknown so is the discretization of &lt;span class=&quot;math-container&quot;&gt;$\Delta^k$&lt;/span&gt;, how is this operator constructed then?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe I've found the &lt;a href=&quot;http://multires.caltech.edu/pubs/ImplicitFairing.pdf&quot; rel=&quot;noreferrer&quot;&gt;original paper&lt;/a&gt;, and I quote the bit I find interesting for my question:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From section 5.4.:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We can however proceed in exactly the same way, as the changes induced in a time step will be small. We simply compute the non-zero coefficients of the matrix:&#xA;  &lt;span class=&quot;math-container&quot;&gt;$I - \lambda dt K$&lt;/span&gt;&#xA;  where &lt;span class=&quot;math-container&quot;&gt;$K$&lt;/span&gt; represents the matrix of the curvature normals...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So I guess the idea is actually what has been suggested already in one of the comments, we compute the matrix &lt;span class=&quot;math-container&quot;&gt;$I - \lambda dt K$&lt;/span&gt; for the current iteration (say &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;) and we keep the very same matrix for a small number of iterations &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; after such number of iterations we update again the matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However in the paper the autors confirm that the Laplace-Beltrami operator isn't linear and therefore the system isn't in general linear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone confirm if my understanding is correct?&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="228" LastEditDate="2018-10-22T09:36:24.773" LastActivityDate="2018-11-04T13:15:15.707" Title="Surface fairing, implementation detail" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8158" PostTypeId="1" AcceptedAnswerId="8159" CreationDate="2018-10-18T20:36:49.783" Score="2" ViewCount="1447" Body="&lt;p&gt;I am involved in a project that had been modified to run on Apple and Linux computers, when it was originally Windows only. Specifically, Metal and Vulkan renderers have been written alongside the Direct3D one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something I have noticed is that there is a static startup image for 3-4 mins with the text &quot;warming shaders&quot;, which is not there in the Windows version. This screen is not present after the first launch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Searching online did not give me any results that shed light on this. The one SO question asked about &quot;background prewarming&quot; which I presume could be used to avoid a long load screen? In any case, it doesn't explain what it IS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simply put, what is shader warming, and why does Metal and Vulkan seem to require it? I have experience with OpenGL from many years ago where shaders were compiled from source at runtime. Is this a related concept? As I understand it, both Metal and Vulkan use binary/bytecode shaders, so compiling shouldn't be necessary.&lt;/p&gt;&#xA;" OwnerUserId="7674" LastActivityDate="2018-10-18T21:17:53.863" Title="What is shader warming, and why does Direct3D seem to avoid it?" Tags="&lt;shader&gt;&lt;terminology&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8159" PostTypeId="2" ParentId="8158" CreationDate="2018-10-18T21:17:53.863" Score="5" Body="&lt;p&gt;I hadn't heard the phrase 'shader warming' before, but from some googling around, it seems that some games/engines use this term for a method of forcing the shaders to be fully compiled during level load, &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1634/48&quot;&gt;as explained in this answer&lt;/a&gt;, to avoid hitches during gameplay.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Metal/Vulkan/D3D12, it's true that shaders are precompiled to a bytecode form, but this is hardware-independent bytecode; the shaders still need to be &lt;em&gt;further&lt;/em&gt; compiled to the GPU-specific machine code, which (in those APIs) is done by the graphics driver when a pipeline state object is created. If there are a lot of shaders, that can potentially take awhile. The fully compiled shaders can also be cached, so this only needs to be done the first time you run the app (at least until you update the driver, which could invalidate the cached results).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my guess about what's going on in your app is that the Metal/Vulkan renderers are calling it 'shader warming' when they go through and create all the pipeline state objects they're going to need—which entails compiling all the shaders. Meanwhile, in the Windows renderer, assuming it's D3D11 or earlier (not D3D12), perhaps the app is relying on the driver to compile shaders in the background, which lets it appear to load faster—at the cost of potentially having hitches a bit later if it tries to use a shader that's not finished compiling yet.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-10-18T21:17:53.863" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8160" PostTypeId="1" AcceptedAnswerId="8161" CreationDate="2018-10-19T06:18:35.227" Score="6" ViewCount="132" Body="&lt;p&gt;I have just started implementing a fluid simulator based on the navier stokes equation.&#xA;I am following Jos Stam's paper to do so.&#xA;In this paper, it says that the velocity field must be mass conserving. Which I understand as, the velocity that flows into a cell should be the same the velocity that flows out.&#xA;To get this mass conserving field, the hodge decomposition is used, and the text says:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;every vector field is the sum of a mass conserving field and a gradient field.&quot; &#xA;Velocity field = mass conserving field + gradient field&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;1) Is there a intuitive way to understand why this statement above is true? Maybe I have to read more on Hodge decomposition to understand this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) The text also says that the gradient field can be computed by solving the poisson equation, Is there a simple explantion of why the poisson equation can be used to approximate this field? I'm wondering what else could be used instead. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you point me to some resources that help understand my two questions intuitively, before delving into all the math?&lt;/p&gt;&#xA;" OwnerUserId="9528" LastActivityDate="2018-10-19T12:22:48.717" Title="Hodge Decomposition in fluid simulations" Tags="&lt;fluid-sim&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8161" PostTypeId="2" ParentId="8160" CreationDate="2018-10-19T12:22:48.717" Score="7" Body="&lt;p&gt;Suppose I have a fluid which, like water, is incompressible; that is, its density is constant. I can find out how this fluid is flowing; let's say I inject dye at various points and follow how the dye particles move. I can estimate a velocity at each point, a velocity field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt;. But water is incompressible; this means that the true velocity field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{u}$&lt;/span&gt; has to be mass-conserving. I want to &quot;correct&quot; my estimate &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt; to find the closest mass-conserving velocity field.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The local accumulation or depletion of the fluid is computed with the &lt;em&gt;divergence&lt;/em&gt; of the vector field, &lt;span class=&quot;math-container&quot;&gt;$\operatorname{div}\mathbf{w}$&lt;/span&gt;. (Stam writes the divergence of &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt; as &lt;span class=&quot;math-container&quot;&gt;$\nabla\cdot\mathbf{w}$&lt;/span&gt;.) The divergence is a &lt;em&gt;derivative&lt;/em&gt;, which is important here because that means it's &lt;em&gt;linear&lt;/em&gt;; the divergence of the sum of two vector fields is the sum of their divergences:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \operatorname{div}(\mathbf{u} + \mathbf{v}) = \operatorname{div}\mathbf{u} + \operatorname{div}\mathbf{v}. $$&lt;/span&gt;&#xA;We want to find a mass-conserving field; that is, we want to find a field with &lt;em&gt;zero divergence&lt;/em&gt;. That means that we want to construct a field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}$&lt;/span&gt; with the same divergence as &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt;; then&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \operatorname{div}\mathbf{w} - \operatorname{div}\mathbf{v} = \operatorname{div}(\mathbf{w} - \mathbf{v}) = 0 $$&lt;/span&gt;&#xA;so we can get our mass-conserving field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{u} = \mathbf{w} - \mathbf{v}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only question is how we construct a field with a given divergence. For reasons I'll explain a few paragraphs down, we say that &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}$&lt;/span&gt; is the gradient of some scalar field &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v} = \operatorname{grad}q$&lt;/span&gt;. (Stam writes this as &lt;span class=&quot;math-container&quot;&gt;$\nabla q$&lt;/span&gt;.) Then we have&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \operatorname{div}\mathbf{w} = \operatorname{div}\mathbf{v} =&#xA;\operatorname{div}\operatorname{grad}q.$$&lt;/span&gt;&#xA;It's worth looking at what this says. The divergence of a vector field is a scalar field; at each point, it gives the local accumulation or depletion of the fluid. Both the divergence and the gradient are derivatives (which is why they can also both be written with &lt;span class=&quot;math-container&quot;&gt;$\nabla$&lt;/span&gt;). The equation is thus saying that the scalar field (the divergence of &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt;) is a particular second derivative of the scalar field &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;. This derivative is called the &lt;em&gt;Laplacian&lt;/em&gt; (Stam writes it as &lt;span class=&quot;math-container&quot;&gt;$\nabla^2 q$&lt;/span&gt;). The differential equation relating scalar fields &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \operatorname{div}\mathrm{grad}\ q = a $$&lt;/span&gt;&#xA;is the &lt;em&gt;Poisson equation&lt;/em&gt;. It's not so much that you use it to &lt;em&gt;estimate&lt;/em&gt; &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; as that it's the actual &lt;em&gt;definition&lt;/em&gt; of &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, to &quot;correct&quot; our estimate &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt;, we can compute its divergence (a scalar field)&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ f = \operatorname{div}\mathbf{w}, $$&lt;/span&gt;&#xA;solve the Poisson equation to find the scalar field &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \operatorname{div}\operatorname{grad} q = f, $$&lt;/span&gt;&#xA;then subtract &lt;span class=&quot;math-container&quot;&gt;$\operatorname{grad}q$&lt;/span&gt; from &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt; to find our mass-conserving velocity field&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \mathbf{u} = \mathbf{w} - \operatorname{grad}q. $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Above we just assumed that &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v} = \operatorname{grad}q$&lt;/span&gt; for some &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;. What we actually want is to find a field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}$&lt;/span&gt; that is in some sense the &quot;smallest&quot; field with the given divergence, so we can find the &quot;closest&quot; mass-conserving field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{u} = \mathbf{w} - \mathbf{v}$&lt;/span&gt;; here I'll explain how the gradient of a scalar field satisfies this requirement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have a fixed amount of fluid moving through our space. &#xA;If our flow is mass-conserving, then we have a conserved amount of fluid, without local accumulation or depletion. If we have any motion at all, then, the fluid must move in &lt;em&gt;cycles&lt;/em&gt;. In the same way as we measure the local accumulation with the divergence operator, we can measure the local cyclic behaviour of the flow by using another vector operator, the &lt;em&gt;curl&lt;/em&gt; (which can be written &lt;span class=&quot;math-container&quot;&gt;$\nabla\times\mathbf{v}$&lt;/span&gt;). The curl at a point gives, broadly speaking, the axis about which the flow is circling near that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, consider the gradient of a scalar field, &lt;span class=&quot;math-container&quot;&gt;$\operatorname{grad} q$&lt;/span&gt;. (For instance, &lt;span class=&quot;math-container&quot;&gt;$q(x,y) = \sin x \cos y$&lt;/span&gt;.) The potential can be drawn as a height field:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/sVzgE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sVzgE.png&quot; alt=&quot;plot of z = sin(x)*cos(y)&quot;&gt;&lt;/a&gt;&#xA;Then the gradient of this field puts at each point a vector pointing in the steepest uphill direction:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Okc02.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Okc02.png&quot; alt=&quot;vector field grad(sin(x) * cos(y))&quot;&gt;&lt;/a&gt;&#xA;But since you're always going &quot;uphill&quot; as quickly as you can, I think it's clear that there's &lt;em&gt;no circulation&lt;/em&gt; in this vector field! In fact, for &lt;em&gt;any&lt;/em&gt; scalar potential &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \operatorname{curl}\operatorname{grad}q = 0 ! $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's also a second similar identity: &lt;span class=&quot;math-container&quot;&gt;$\operatorname{div}\operatorname{curl}\mathbf{v} = 0$&lt;/span&gt;; unfortunately, I can't think of a good intuition for that one. (But look at &lt;a href=&quot;https://math.stackexchange.com/a/27010/152310&quot;&gt;this Math.SX answer&lt;/a&gt; for a more mathematical explanation.) We can use these two identities to explicitly write the Hodge decomposition: &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w} = \mathbf{v} + \mathbf{u}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}$&lt;/span&gt; has no curl, and &lt;span class=&quot;math-container&quot;&gt;$\mathbf{u}$&lt;/span&gt; has no divergence, or&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \mathbf{w} = \operatorname{grad}q + \operatorname{curl}\mathbf{\nu},¹ $$&lt;/span&gt;&#xA;for some scalar field &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; and vector field &lt;span class=&quot;math-container&quot;&gt;$\mathbf{\nu}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;¹The Hodge decomposition is actually more complicated if your space isn't simple, i.e. finite and ball-like; on more complicated spaces, like say the surface of a torus, we have curl-free fields which aren't the gradient of anything, and divergence-free fields which aren't the curl of anything. For most fluid modelling in CG, though, this isn't usually an issue.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2018-10-19T12:22:48.717" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8162" PostTypeId="2" ParentId="8153" CreationDate="2018-10-19T19:42:02.563" Score="2" Body="&lt;p&gt;Picking up from step 2, where you generated line segments to represent individual stitches, I would first suggest that you apply rounded ends to each segment, rather than square ends.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would then convert each segment to an &lt;strong&gt;outline&lt;/strong&gt;, (i.e. each rounded stitch becomes an separate poly-line representing the outer boundary.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, suppose you start with point A &amp;amp; point B, representing a single stitch in line segment form. We can derive the rounded outline of this segment with the following Javascript code using &lt;strong&gt;THREE.js&lt;/strong&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    function outlineSegment (Ax, Ay, Bx, By, radius){&#xA;        var radius = radius || 0.5; //millimeters?&#xA;        var A = new THREE.Vector2(Ax, Ay);&#xA;        var B = new THREE.Vector2(Bx, By);&#xA;        var C = B.clone().sub(A).normalize().multiplyScalar(radius);&#xA;        var angle = C.angle();&#xA;        var outline = new THREE.Shape();&#xA;        outline.moveTo( B.x + C.y, B.y - C.x );&#xA;        outline.absarc(B.x, B.y, radius, angle-Math.PI/2, angle+Math.PI/2);&#xA;        outline.lineTo(A.x - C.y, A.y + C.x);&#xA;        outline.absarc(A.x, A.y, radius, angle+Math.PI/2, angle+Math.PI*3/2);&#xA;        outline.autoClose = true;&#xA;        return new THREE.ShapeGeometry(outline);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The above function finishes by &lt;strong&gt;triangulating&lt;/strong&gt; the polyline into faces, (See the orange area in the included picture.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next, send these faces to be rendered by the &lt;strong&gt;GPU&lt;/strong&gt;, applying a &lt;strong&gt;vertex shader&lt;/strong&gt; which sets a &lt;strong&gt;&lt;em&gt;vec2&lt;/strong&gt; varying variable&lt;/em&gt; (sounds redundant, but it's not) indicating the vertex position relative to the original line segment (which we have included as &lt;em&gt;vertex attributes&lt;/em&gt;) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we move on to the &lt;strong&gt;fragment shader&lt;/strong&gt;, where we use the varying variable created in the vertex shader to derive a &lt;strong&gt;normal&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say that &quot;linePos&quot; is the position along the line segment, (i.e. the x-value, if the line is horizontal. y-value if it is vertical, etc.) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, let's say &quot;lineDist&quot; is the distance from the central line segment, e.g. -2 if it's 2 units to the left of the line (purple arrows) or +5 if it's on the right (blue arrows).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can use these two values, derived from the varying variable, to create a normal for the point on the thread. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A bit of this code might be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;abs(sin(linePos+lineDist))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;but there's a fair bit more than that to write.&#xA;I can't go through and write the entire program for you here &amp;amp; now, but hopefully these ideas &amp;amp; diagram will shine some light in the right direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best of luck.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0nXwY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0nXwY.png&quot; alt=&quot;embroidery geometry diagram&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6596" LastEditorUserId="6596" LastEditDate="2018-10-20T16:06:47.707" LastActivityDate="2018-10-20T16:06:47.707" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8163" PostTypeId="2" ParentId="8152" CreationDate="2018-10-20T07:58:52.687" Score="13" Body="&lt;p&gt;Talking about &lt;em&gt;Linear RGB&lt;/em&gt; must be avoided because it does not tell you anything about the RGB colourspace intrinsics, i.e., Primaries, Whitepoint and Colour Component Transfer Functions. A few years ago, assuming it was sRGB was middling but nowadays with DCI-P3 and BT.2020 being very common, it must be ruled out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ideal gamut for rendering is the one that will minimize errors in respect to a real-world reference or more conveniently a ground truth spectral render. The first takeaway from this sentence is that the various RGB colourspaces are not equivalent and will not produce similar results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One might think that performing two renders with the same base colours but one where they are encoded with sRGB/BT.709 and the other one where they are encoded with DCI-P3 and then converting the two resulting images to for example ACES2065-1 will yield the same images but it is not the case. Some mathematical operations because of the nature of linear algebra and matrices are dependent on the given RGB colourspace primaries, i.e., on the colourspaces basis. The same operations performed in different RGB colourspace will yield different tristimulus values once converted back to CIE XYZ color space. For example multiplication, division and power operations are RGB colourspace primaries dependent while addition and subtraction are not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7SQRJ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7SQRJ.png&quot; alt=&quot;RGB Colourspaces and Exponentiation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This image illustrates the effect of multiplying various colours by themselves into different RGB colourspaces: the resulting colours are different. The various samples are generated as follows: 3 random sRGB colourspace values are picked and converted to the three studied RGB colourspaces, they are exponentiated, converted back to sRGB colourspace, plotted in the CIE 1931 Chromaticity Diagram on the left and displayed as swatches on the right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Tests and research conducted by &lt;a href=&quot;http://diglib.eg.org/handle/10.2312/EGWR.EGWR02.117-124&quot; rel=&quot;noreferrer&quot;&gt;Ward and Eydelberg-Vileshin (2002)&lt;/a&gt;, &lt;a href=&quot;https://www.colour-science.org/anders-langlands/&quot; rel=&quot;noreferrer&quot;&gt;Langlands and Mansencal (2014)&lt;/a&gt; and &lt;a href=&quot;https://www.colour-science.org/posts/about-rgb-colourspace-models-performance/&quot; rel=&quot;noreferrer&quot;&gt;Mansencal (2014)&lt;/a&gt; showed that gamuts with primaries closest to the spectral locus, i.e. spectrally sharp primaries, tend to minimize the errors compared to spectral ground truth renders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is an image I recently rendered with Mitsuba to re-validate our findings with Anders:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7GseL.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7GseL.jpg&quot; alt=&quot;Rendering Colourspaces&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Those are renders of the same scene using BT.709 primaries (first row), 47 spectral bins (second row), BT.2020 primaries (third row), spectral minus BT.709 primaries renders residuals (fourth row), spectral minus BT.2020 primaries renders residuals (fifth row). The last row showcases composite images assembled with three vertical stripes of respectively the BT.709 primaries, spectral and, BT.2020 primaries renders. Direct illumination tends to match between the renders. Areas that show the effect of multiple light bounces, i.e., the ceiling, in the BT.709 and BT.2020 primaries renders tend to exhibit increased saturation, especially in the BT.709 primaries render or slight loss of energy, especially in the BT.2020 render. Excluding outliers, e.g., the visible light source, the RMSE with the spectral render are &lt;strong&gt;0.0083&lt;/strong&gt; and &lt;strong&gt;0.0116&lt;/strong&gt; for respectively the BT.2020 primaries and BT.709 primaries renders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now it does not mean they will always perform better, and one might be able to produce examples that will exhibit a bias toward BT.709/sRGB. The main takeaway is that RGB renders cannot match spectral renders and sharp wide gamuts tend to perform better. As for choosing a rendering colourspace, I would pick one with a wide gamut that encompasses Pointer's Gamut and DCI-P3, &lt;strong&gt;BT.2020&lt;/strong&gt; or &lt;strong&gt;ACEScg&lt;/strong&gt; are excellent candidates for that.&lt;/p&gt;&#xA;" OwnerUserId="9533" LastActivityDate="2018-10-20T07:58:52.687" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8164" PostTypeId="1" AcceptedAnswerId="8181" CreationDate="2018-10-20T16:57:28.040" Score="7" ViewCount="237" Body="&lt;p&gt;I would like to know the magic behind this tiny fractal shader; I didn't really understand the code and the mentioned thread...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an accessible explaination?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/4ttBWM&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/4ttBWM&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="2173" LastActivityDate="2018-10-23T19:34:27.590" Title="How does this small fractal shader work?" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8165" PostTypeId="1" CreationDate="2018-10-20T19:37:52.150" Score="2" ViewCount="2393" Body="&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDispatchCompute.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;glDispatchCompute&lt;/a&gt; has the number of work groups as arguments.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the point of having work groups? How are they useful, compared to just having NxM independent pixel calculations with a known (x,y) input parameter in the shader?&lt;/p&gt;&#xA;" OwnerUserId="8233" LastActivityDate="2018-10-21T07:20:53.663" Title="What's the point of &quot;work groups&quot; for OpenGL compute shaders?" Tags="&lt;opengl&gt;&lt;compute-shader&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8166" PostTypeId="2" ParentId="8152" CreationDate="2018-10-21T02:33:26.677" Score="0" Body="&lt;p&gt;There are two sides to why sRGB particularly. For input non-HDR images, it is claimed that those should be assumed to be compressed to sRGB (whether this claim is accurate is a different story). Hence, before you can do any linear math operation on them, you need to decompress them from sRGB. It is also possible that an image was captured and compresssd to a different representation that is not sRGB, in which case you need to decompress that specific representation. In any case, the encoding implies a certain gamut that the input image will never escape (because sRGB-stored images are typically truncated to 8-bits per channel), but your shader math doesn't have to stay in that gamut after the input image is decompressed. But in the end you have to consider the display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have an image and it is time to display it, you encode it in a representation that the display device requires. CRTs chose sRGB, then LCDs emulated that, so sRGB compression for monitor display has been the common choice for the last decades, and that restricted the output to stick within sRGB gamut, or else clipping will occur. Wider-range displays don't have to stick to that exact gamut.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I think the basis for the claim that human-made images are sRGB-encoded is because those images were assumed to have been authored on sRGB displays)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now you can probably see better why sRGB in particular was supported in hardware for shader math input and image display. It is the common case. Plus, it has good merits for reducing perceptual color banding artifacts, so it is a good way to compress colors in 8 bits and keep them looking plausible to humans.&lt;/p&gt;&#xA;" OwnerUserId="9535" LastEditorUserId="9535" LastEditDate="2018-10-21T02:58:38.967" LastActivityDate="2018-10-21T02:58:38.967" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8167" PostTypeId="2" ParentId="8152" CreationDate="2018-10-21T04:49:23.513" Score="0" Body="&lt;p&gt;If you allow values outside the 0..1 range, then even with sRGB's fairly limited primaries, you can still address the entire human visual gamut. So for storing floating point  light color values it shouldn't matter too much which primaries you use. &#xA;However, doing any kind of multiplicative math gets a bit funky though, as the arbitrary coordinates of the primaries act as the scaling 'pivot'.&#xA;sRGB primaries are generally used because traditionally your input data is sRGB encoded and out output display is sRGB or rec709... With rec2020, half of that has changed, but for now, most of your input data is still probably sRGB encoded, so using the same primaries as your storage is just the easiest option. &lt;/p&gt;&#xA;" OwnerUserId="9537" LastActivityDate="2018-10-21T04:49:23.513" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8168" PostTypeId="2" ParentId="8165" CreationDate="2018-10-21T06:14:08.330" Score="4" Body="&lt;p&gt;Work groups share resources. The most notable resources they share are barriers and LDS (Local Data Storage aka shared memory in GL lingo, aka Thread Group Shared Memory).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See &lt;a href=&quot;http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2012/10/Efficient%20Compute%20Shader%20Programming.pps&quot; rel=&quot;nofollow noreferrer&quot;&gt;Efficient Compute Shader Programming&lt;/a&gt; for an example where LDS/TGSM is used to accelerate a simple gaussian blur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is an interesting thought exercise of how a simple algorithm (weight average N values and output the result) can be rewritten to better leverage the hardware. Basically with a kernel radius of 5, Pixel A will load pixels [A; E] to average them, pixel B loads pixels [A; F] to average, pixel C loads pixels [A; G], and so on until we hit pixel F which will load pixels [B; J] to average them. So the paper asks the question: why do we load pixels A through F from main RAM so many times? (note: GPUs DO have caches, but if multiple threads are requesting all the same regions is likely many of these loads will miss the cache or have bank conflicts) and instead tries to load A through F ONCE (each thread loads only one pixel) and store it into TGSM memory which is much faster (and can also be accessed directly by the HW). It's basically very similar to manual cache management.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also if the workgroup happens to be &amp;lt;= than the GPU's native workgroup size, barriers are much cheaper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note not all GPUs are created equal. For example current Mali's GPU do not have LDS, and shared memory is &quot;emulated&quot; via RAM fetches, thus trying to use LDS like a cache is only going to hurt performance.&lt;/p&gt;&#xA;" OwnerUserId="9539" LastEditorUserId="9539" LastEditDate="2018-10-21T06:19:25.227" LastActivityDate="2018-10-21T06:19:25.227" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8169" PostTypeId="2" ParentId="8165" CreationDate="2018-10-21T07:20:53.663" Score="2" Body="&lt;p&gt;I won't be discussing the usefulness of workgroups here as you can find it pretty much anywhere. However I am going to touch up on GPU architecture to understand why do we have workgroups in the first place. Most GPUs are designed in such a way that the concept of workgroup is useful. I won't go into details but give a brief overview as to how the mainstream GPUs are designed (AMD/NVIDIA).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So basically both AMD and NVIDIA have hundreds of thousands of cores inside them. AMD groups these cores into what is called compute unit (CU) While NVIDIA groups them to call them a streaming multiprocessor (SM). Here is a picture from AMD architecture as I am more used to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/g3HeG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g3HeG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see GPU device consists of CU or SM in NVIDIA's case. These then further contain the actual processing elements. AMD has 64 of them for the GCN architecture.&#xA;Now you are gonna say &quot;so what?&quot; Why do we still have workgroups why don't we use these individual &quot;processing elements&quot; or &quot;cores&quot; by themselves and ditch the concept of workgroup.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Well the thing is, as Matias told above, the compute unit doesn't consist of only these cores, it has much more. The processing elements are just ALUs and they can't do anything on their own. The actual logic that tells them what to do such as the &quot;Branch Unit&quot; the &quot;Instruction Decoding Logic&quot;, &quot;Cache&quot; etc are present inside the Compute Unit. Here is another picture for the Compute Unit of GCN Architecture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AHVfr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AHVfr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So as you see this looks more like a miniature CPU processor with the instruction register and other stuff built in. Here comes the concept of workgroup. In programmer's terms a Workgroup equals or you can say gets assigned to a Compute Unit or thread block equals a Streaming Multiprocessor (in NVIDIA's terms). There are subtle differences such as hardware and software threads which leads to wavefronts and warps but I am not going to touch them here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So this is somewhat the general architecture how work gets assigned to a GPU. Hence workgroups are necessary. The idea of shared memory and everything Matias said above stems from the underlying GPU architecture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when working with images we usually divide it into smaller 2D blocks called workgroups and hand these blocks to get processed by the underlying Compute Units/SMs.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-10-21T07:20:53.663" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8170" PostTypeId="1" AcceptedAnswerId="8171" CreationDate="2018-10-22T11:09:49.407" Score="1" ViewCount="917" Body="&lt;p&gt;When creating a VkInstance, you need to setup the API's extensions that are going to be used by your application (for example you need an extension to interface with the window system on desktop platforms).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are these extensions? What do they represent? Are they just a way to tell Vulkan to use a certain feature implemented by a driver?&lt;/p&gt;&#xA;" OwnerUserId="9436" LastEditorUserId="2654" LastEditDate="2018-10-22T14:01:05.450" LastActivityDate="2018-10-22T14:01:05.450" Title="What is a &quot;Vulkan Extension&quot;?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8171" PostTypeId="2" ParentId="8170" CreationDate="2018-10-22T13:59:13.807" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Are they just a way to tell Vulkan to use a certain feature implemented by a driver?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Well... yes. Vulkan extensions are simply additional features that Vulkan implementations &lt;em&gt;may&lt;/em&gt; provide if they so choose to. They add new functions, structs, and valid enumerators to the API, and they can change some of the behavior of existing functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You have to detect whether the implementation supports these extensions before creating an instance/device. And you have to explicitly ask for such extensions when you create the instance/device.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-10-22T13:59:13.807" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8172" PostTypeId="1" CreationDate="2018-10-22T23:06:56.127" Score="-1" ViewCount="42" Body="&lt;p&gt;I have a question that I am stuck on, I am wondering what style is this image considered? And what program do people generally use to create this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RbTEv.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RbTEv.jpg&quot; alt=&quot;Image in question&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9551" LastActivityDate="2018-10-23T10:55:57.840" Title="Confused about graphic art and what software is used to create the environment of it?" Tags="&lt;vector-graphics&gt;&lt;pixel-graphics&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2018-10-24T21:26:12.327" ContentLicense="CC BY-SA 4.0" />
  <row Id="8173" PostTypeId="1" AcceptedAnswerId="8187" CreationDate="2018-10-23T02:00:34.493" Score="6" ViewCount="152" Body="&lt;p&gt;I have seen in some computer graphics software's code bases that sometimes the higher bits of RGB565-format image data are replicated into the lower bits when converting to higher-bit-depth format RGBA8888.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have found for example the comment by user &quot;eq&quot; in &lt;a href=&quot;https://www.gamedev.net/forums/topic/385638-rgb8888-to-rgb565-pixel-format-conversion/&quot; rel=&quot;noreferrer&quot;&gt;this gamedev.net thread&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I prefer to replicate the higher bits into the undefined lower bits:&lt;br&gt;&#xA;  R8 = (R5 &amp;lt;&amp;lt; 3) | (R5 &gt;&gt; 2);&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;However I do not understand the reason behind.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What use the purpose of replicating those bits into the converted data?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2018-10-25T09:33:36.313" Title="Why replicating the higher bits of RGB565 when converting to RGBA8888?" Tags="&lt;color-management&gt;&lt;conversion&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8174" PostTypeId="1" AcceptedAnswerId="8177" CreationDate="2018-10-23T05:16:01.320" Score="0" ViewCount="79" Body="&lt;p&gt;I'm reading the &lt;a href=&quot;http://developer.download.nvidia.com/CgTutorial/cg_tutorial_chapter08.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;chapter 8&lt;/a&gt; of the Cg tutorial and I could not understand 8.4.1 :&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Because all these coordinates lie in the plane of the same triangle, it is possible to derive plane equations for x, y, and z in terms of s and t:&lt;/p&gt;&#xA;&lt;p&gt;A_0 x + B_0 s + C_0 t + D_0 = 0&lt;/p&gt;&#xA;&lt;p&gt;A_1 y + B_1 s + C_1 t + D_1 = 0&lt;/p&gt;&#xA;&lt;p&gt;A_2 z + B_2 s + C_2 t + D_2 = 0&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;How are these equations derived?&lt;/p&gt;&#xA;" OwnerUserId="6407" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-10-23T12:01:35.050" Title="How are the three plane equations derived in the NVIDIA's CG Tutorial chapter 8?" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8175" PostTypeId="1" CreationDate="2018-10-23T08:46:51.917" Score="1" ViewCount="60" Body="&lt;p&gt;I have somewhat generalized version of this question: &lt;a href=&quot;https://stackoverflow.com/questions/52475104/how-to-show-visible-part-of-planar-world-rendered-with-3d-perspective-on-topside&quot;&gt;https://stackoverflow.com/questions/52475104/how-to-show-visible-part-of-planar-world-rendered-with-3d-perspective-on-topside&lt;/a&gt; -‎ I would also like to know which part(s) of a given plane (not necessarily infinite) is visible to the camera, but I would like the solution to also consider objects in front of the plane that may be obstructing it's visibility.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since that may be very hard problem to solve analyticaly (if at all in OpenGL) I would be happy also with solution based on &quot;rasterisation&quot;. The problem would then be restated as: How to map rendered pixels of a plane back to it's 3D representation. Or in other (maybe too naive) words - how to transform rendered visible area of a plane to it's texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm a beginner in computer graphics so I would be glad even for pointing out the right study materials.&lt;/p&gt;&#xA;" OwnerUserId="9553" LastActivityDate="2018-10-23T08:46:51.917" Title="Identification of visible area of a plane in OpenGL" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8176" PostTypeId="2" ParentId="8172" CreationDate="2018-10-23T10:55:57.840" Score="1" Body="&lt;p&gt;This would be considered &lt;a href=&quot;https://en.wikipedia.org/wiki/Isometric_video_game_graphics&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;isometric&lt;/strong&gt;&lt;/a&gt;. Isometric graphics were originally used to give a 3D look, when computers could not handle actual 3D graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The creation of this image, however, is different than described in the Wikipedia article. The creator started by making the scene in 3D. This means, doing normal three dimensional modeling. After the scene is modeled and shaded, the creator simply created an orthographic camera. The orthographic camera is probably rotated to a yaw of 45° and a pitch of 45° downwards, although I am not sure about that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is quite simply it. The scene is a normal 3D scene, but the difference is that the creator used an orthographic camera, placed in such a way that you get an isometric-looking image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, when it comes to what program people use, simply any somewhat feature rich modeling software (Blender, 3Ds Max, Autodesk Maya (LT version is generally for games), Cinema 4D). Most 3D game engines also support orthographic cameras and can thus also be used.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2018-10-23T10:55:57.840" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8177" PostTypeId="2" ParentId="8174" CreationDate="2018-10-23T11:06:55.367" Score="1" Body="&lt;p&gt;In this context, deriving the plane equations does not refer to the equations themselves, but to the coefficients &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The equations are simply plane equations for a plane defined by three points, where the first plane is defined by the three points &lt;span class=&quot;math-container&quot;&gt;$(x_i,s_i,t_i)_{i=1..3}$&lt;/span&gt;, the second plane is defined by &lt;span class=&quot;math-container&quot;&gt;$(y_i,s_i,t_i)_{i=1..3}$&lt;/span&gt; and the third plane by &lt;span class=&quot;math-container&quot;&gt;$(z_i,s_i,t_i)_{i=1..3}$&lt;/span&gt;. They can be seen as auxiliary objects in deriving equations for &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; in terms of &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastEditorDisplayName="user9485" LastEditDate="2018-10-23T12:01:35.050" LastActivityDate="2018-10-23T12:01:35.050" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8178" PostTypeId="1" AcceptedAnswerId="8188" CreationDate="2018-10-23T13:08:33.107" Score="2" ViewCount="240" Body="&lt;p&gt;It seems that every image format (jpeg, png, tiff, bmp, jp2000...) doesn't place their origin at the same corner.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you know where I could find some info about this differences?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can only say that PNG and JPEG are different.&lt;/p&gt;&#xA;" OwnerUserId="9557" LastEditorUserId="9557" LastEditDate="2018-10-24T10:22:15.450" LastActivityDate="2018-10-25T18:02:18.193" Title="Why is pixel 0,0 at the top left of some formats and bottom left of others?" Tags="&lt;2d&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8179" PostTypeId="2" ParentId="8173" CreationDate="2018-10-23T13:27:41.900" Score="6" Body="&lt;p&gt;There's actually a reasonably good mathematical reason for doing bit replication:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First note that the n-bit string, &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt;, actually represents the value &lt;span class=&quot;math-container&quot;&gt;$\frac{N}{2^n-1}$&lt;/span&gt; and we want to produce the m-bit string, &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$n&amp;lt;m$&lt;/span&gt; and&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{N}{2^n-1}\approx\frac{M}{2^m-1}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We first scale numerator and denominator with&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{N.(2^n+1)}{(2^n-1)(2^n+1)}\approx \frac{M}{2^m-1}$$&lt;/span&gt;&#xA;and this simplifies to &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{N.(2^n+1)}{2^{2n}-1}\approx \frac{M}{2^m-1}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case, &lt;span class=&quot;math-container&quot;&gt;$n\in \{5,6\}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$m=8$&lt;/span&gt; and we can &quot;stop&quot; here, but but the process can be repeated, (ad nauseum), if m &gt;&gt; n.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We next make the approximation...&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{N.(2^n+1)}{2^{2n}}\approx \frac{M}{2^m}$$&lt;/span&gt; which simplifies to &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{N.(2^n+1)}{2^{2n-m}}\approx M $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that &lt;span class=&quot;math-container&quot;&gt;$N.(2^n+1)$&lt;/span&gt; is equivalent to repeating the n-bit string, to create a 2n-bit string, and the division shifts off the &lt;span class=&quot;math-container&quot;&gt;$2n-m$&lt;/span&gt; LSBs to leave an M bit result. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;QED&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, the  'correct' calculation is &lt;span class=&quot;math-container&quot;&gt;$M=\lfloor(\frac{(2^m-1) N}{2^n-1}+\frac{1}{2}\rfloor$&lt;/span&gt; but this approximation, in general, works &lt;em&gt;most&lt;/em&gt; of the time. Of course there are times when it's inaccurate, but IIRC only by one bit and relatively infrequently.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2018-10-24T08:16:38.870" LastActivityDate="2018-10-24T08:16:38.870" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8181" PostTypeId="2" ParentId="8164" CreationDate="2018-10-23T19:34:27.590" Score="10" Body="&lt;p&gt;Here is a line by line breakdown of my shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define mainImage(o,p)\&#xA;    for( vec2 r = iResolution.xy, q = 2.*(p+p-r)/r.y; o.a++ &amp;lt; 30.; )\&#xA;        o += length( q = abs(q)/dot(q,q) - iMouse.xy/r) / 2e2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;First, it is important to know that the “\” at the end of the first two lines do not count towards the character count and merely serve to make the code more readable by splitting it onto multiple lines.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define mainImage(o,p)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Begins the definition of the function which would normally be written&#xA;void mainImage(out fragColor, in fragCoord){...}&#xA;This saves a few characters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first part of the loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 r = iResolution.xy, q = 2.*(p+p-r)/r.y;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Establishes two variables of type Vector2:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;r is the resolution which allows me to refer to iResolution several times later in fewer characters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;q is the coordinate in the fractal which is calculated from the fragCoord p and is then iterated in each loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of fragCoord starting at (0,0) in the bottom left corner and extending to the (r.x,r.y) in the top right, (p+p-r) transforms each fragCoord so that the center of the screen is (0,0). This doubles the fragCoord value and then subtracts the resolution of the window.&#xA;The division by r.y fits the coordinates such that the top has a y value of 1 and the bottom has a y value of -1. With this, the x is scaled accordingly without stretching.&#xA;Finally, the multiplication by 2 just zooms out by a factor of 2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then for the iterator, I use o.a (the alpha channel of o).&#xA;o is the output color which is a vec4. As defined by Shadertoy, o begins with the value vec4(0,0,0,1). I use this so that I do not need to use characters declaring a new float as an iterator. o.a++&amp;lt;30 combines the test expression and the iterator in the for loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The content of the loop is one line where a number gets added to each channel of the output color. This line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;o += length( q = abs(q)/dot(q,q) - iMouse.xy/r) / 2e2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Can be broken down into a few parts.&#xA;Each iteration of the coordinates in the fractal occurs here:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;q = abs(q)/dot(q,q) - iMouse.xy/r&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where iMouse.xy/r is a way to transform mouse coordinates from pixel to the range (0,0) to (1,1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each iteration of this function changes the value of q to be used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What produces this fractal is the idea that some initial values for q will escape to infinity and others will converge or cycle around a few small values. Each iteration I increase the lightness of the pixel based how far q is from (0,0). This length of q is then divided by the constant 2e2 (200) which is to prevent o.rgb from increasing too rapidly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The contents of the loop could be understood as two steps:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;q = abs(q)/dot(q,q) - iMouse.xy/r;&#xA;o += length(q) / 2e2;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In the end, even if o contains a value in one of its channels that is greater than 1, it gets clamped by Shadertoy automatically, and a trailing semi-colon is not needed on the last line.&lt;/p&gt;&#xA;" OwnerUserId="9561" LastActivityDate="2018-10-23T19:34:27.590" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8183" PostTypeId="2" ParentId="4172" CreationDate="2018-10-24T14:50:19.370" Score="6" Body="&lt;p&gt;I can't say for certain, but I was interested in this myself and trying to look it up (with little success). I did analyze the many macro photos you can find on the web of these kinds of displays, though.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RGB pixels      Pentile Subpixels (RGBG Layout)&#xA;&#xA;--+---+--           --+---+--&#xA;X | X | X           G r G b G&#xA;--+---+--   --&amp;gt;     --+---+--&#xA;X | X | X           G b G r G&#xA;--+---+--           --+---+--&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As far as I can tell, it looks like the green subpixels' locations exactly match the framebuffer pixel locations (X) and the intensity is transferred 1:1. The red and blue subpixels are shared between the &lt;em&gt;two&lt;/em&gt; neighbouring pixels &lt;em&gt;horizontally&lt;/em&gt; and their intensity seems to be the average of the red/blue channels of the two neighbouring framebuffer pixels left and right, effectively halving the horizontal resolution of R and B.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This strategy seems to carry over to the diamond Pentile layout even though the the red and blue subpixels are shifted downwards (or upwards) by half a pixel:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RGB Pixels       Diamond Pentile subpixels&#xA;                         _________&#xA;X   X   X                G | G | G&#xA;              --&amp;gt;        __r___b__ &#xA;X   X   X                G | G | G&#xA;                         __b___r__&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Due to the additional half pixel vertical shift for red and blue of this layout that isn't accounted for in driving the red and blue subpixels, you might be able to notice that a horizonal edge between a black area and a white area might appear green or magenta. You can see this effect in macro photos of diamond Pentile subpixel matrices rendering text. But there is actually no consistent shift. In some photos it's downwards and in others it's upwards.  I don't know if the displays were manufactured differently or just installed upside-down in some devices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, yes, you can easily control all subpixels of a Pentile display. Each color channel value in your frame buffer is used exactly once and for only one pixel. It's just that for the red and blue subpixels two frame buffer pixels' red and blue values are averaged.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Knowing this, you could try to do a more sophisticated subpixel rendering. But keep in mind that your typical color space like sRGB is nonlinear. The filtering should be done in a linear domain. For example, a checker board of alternating 0 and 255 will have the same brightness as a flat area with value around 185 (if I remember correctly) instead of 128.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally, I want to point out that it's possible to come up with anti-alias filters for non-rectangular sampling lattices. For example, for this checkerboard sampling lattice you have for the red and blue subpixels, the ideal lowpass filter would have a pass band in form of a diamond shape in the spectral domain. If you tried to reduce the resolution by dropping every 2nd sample in a checkerboard fashion, reasonable anti-alias filters would be these 5x5 and 3x3 kernels while the 5x5 version retains more detail:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 0   -1    0   -1    0&#xA;-1    0   10    0   -1              0  1  0&#xA; 0   10   32   10    0              1  4  1&#xA;-1    0   10    0   -1              0  1  0&#xA; 0   -1    0   -1    0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;These can be applied in-place due to the zeros' locations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might also want to include a half-pixel shift for one or two dimensions in there to account for the relative positioning of the red blue and green subpixels. For example, for the diamond pentile layout you might want to use one of these filters:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  3    0    0    0    0    3&#xA;  0  -25    0    0  -25    0          -1   0   0  -1&#xA;  0    0  150  150    0    0           0   9   9   0&#xA;  0    0  150  150    0    0           0   9   9   0&#xA;  0  -25    0    0  -25    0          -1   0   0  -1&#xA;  3    0    0    0    0    3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;to come up with the right red/blue subpixels instead of just averaging four values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The RGBG (non-diamond) Pentile pattern would require only a half-pixel shift horizontally, leading to a filter like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; -3   3   3  -3&#xA;  2  30  30   2&#xA; -3   3   3  -3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Some care must be taken with clipping due to the negative filter coefficients. For example, you could try to redistribute the residual to surrounding pixels to keep the average brightness.&lt;/p&gt;&#xA;" OwnerUserId="9566" LastEditorUserId="9566" LastEditDate="2018-10-25T09:25:50.903" LastActivityDate="2018-10-25T09:25:50.903" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8185" PostTypeId="1" CreationDate="2018-10-24T18:04:55.973" Score="9" ViewCount="6521" Body="&lt;p&gt;I keep coming across the terms 'Metal' and 'Vulkan' on this site.&#xA;Guessing this to be some CG software, I'm interested to know what these are exactly and what the intended and most common usage is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A quick search shows me a video about why metal in CG looks fake: &lt;a href=&quot;https://www.youtube.com/watch?v=NjbLYFXrfFU&quot; rel=&quot;noreferrer&quot;&gt;https://www.youtube.com/watch?v=NjbLYFXrfFU&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously not the answer, most answers talk about compute kernels. I'm familiar with kernel inversion in machine learning but not like Android kernels and the such. Hope you can help me out. Your input would be most valuable.&lt;/p&gt;&#xA;" OwnerUserId="9567" LastEditorUserId="11180" LastEditDate="2019-09-19T07:41:54.760" LastActivityDate="2019-09-19T07:41:54.760" Title="What are Metal and Vulkan?" Tags="&lt;vulkan&gt;&lt;metal&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8186" PostTypeId="2" ParentId="8185" CreationDate="2018-10-24T18:54:13.723" Score="22" Body="&lt;p&gt;Metal and Vulkan are low-level 3D graphics APIs, in much the same way that OpenGL and Direct3D are 3D graphics APIs. Metal is Apple's API, usable on iOS and MacOS. Vulkan was developed by the Khronos Group, who also oversees the various forms of OpenGL. Vulkan is directly usable on all non-Apple platforms, and there is the MoltenVK project which provides a translation layer from Vulkan to Metal (since the APIs are not &lt;em&gt;that&lt;/em&gt; different), thus allowing Vulkan applications to run even on Apple platforms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Metal, Vulkan, and Direct3D v12 represent a dramatic departure API-wise from prior low-level graphics APIs. They use a command-buffer-based interface, where you record rendering commands into a command buffer object, then execute those commands at some later period. The more immediate style of APIs like OpenGL and D3D-pre-12 have no intermediary command buffer. When you call a rendering function, it is given to the GPU &quot;right then&quot; and that's the end of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These styles of API are important because they allow threaded creation of rendering commands. In the immediate APIs, you can only effectively have one thread issuing rendering commands. In command-buffer APIs, multiple threads can build multiple CBs simultaneously, and then one thread submits them all as a single bunch of work. This allows better utilization of CPU resources for CPUs with lots of cores.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-10-24T18:54:13.723" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8187" PostTypeId="2" ParentId="8173" CreationDate="2018-10-25T02:03:36.403" Score="6" Body="&lt;p&gt;Without replicating the bits the LSBs will be 0, so for the maximum value of 0x1f (max for 5 bits) it would expand to 0xf8 when converted to 8 bit. What you want is 0xff so the range of 0x00-&gt;0x1f will be mapped to 0x00-&gt;0xff instead of 0x00-&gt;0xf8. Without merging the LSB you would not be able to convert 0x1f,0x1f,0x1f to white (0xff,0xff,0xff). Incidentally this is the same as N*0xff/0x1f.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Example: &#xA;&#xA;left shift only (&amp;lt;&amp;lt; 3)&#xA;%---00001 -&amp;gt; %00001000     (0x01 -&amp;gt; 0x08)&#xA;%---10000 -&amp;gt; %10000000     (0x10 -&amp;gt; 0x80)&#xA;%---11111 -&amp;gt; %11111000     (0x1f -&amp;gt; 0xf8)&#xA;&#xA;merging MSB to LSB &#xA;%---00001 -&amp;gt; %00001000     (0x01 -&amp;gt; 0x08)&#xA;%---10000 -&amp;gt; %10000100     (0x10 -&amp;gt; 0x84)&#xA;$---11111 -&amp;gt; %11111111     (0x1f -&amp;gt; 0xff)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2018-10-25T09:33:36.313" LastActivityDate="2018-10-25T09:33:36.313" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8188" PostTypeId="2" ParentId="8178" CreationDate="2018-10-25T18:02:18.193" Score="3" Body="&lt;p&gt;It comes down to history. The original interfaces for drawing stuff on the screen were for text, not images. Since the people who designed those early computers spoke languages that are read left-to-right, top-to-bottom, it made sense for the first glyph to be the top-left one. This also works conveniently with how the image was transmitted to the display. TV signals also start in the top-left, so those CRT displays also started displaying a frame with the top-left pixel. When computers added &quot;graphics modes&quot; to their &quot;text modes&quot;, it made sense for the origin to stay in the same place. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This all changed with packages specifically designed for mathematical and scientific computing. Charts are usually drawn with (0,0) at the bottom-left, so scientists wanted their co-ordinate system to work that way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why we have two common options. Generally for an image format, it depends on the use-case the format was originally designed to satisfy, and what kind of people worked on it. Image formats are usually designed by engineers with experience of low-level graphics implementation, so top-down is more popular, but some formats support both for flexibility.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-10-25T18:02:18.193" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8189" PostTypeId="1" CreationDate="2018-10-27T01:33:20.423" Score="1" ViewCount="469" Body="&lt;p&gt;I'm working on an image processing app which uses WebGL to apply shaders to a bunch of input photos. At one point in the algorithm, I need to create some &lt;a href=&quot;https://en.wikipedia.org/wiki/Pyramid_(image_processing)&quot; rel=&quot;nofollow noreferrer&quot;&gt;image pyramids&lt;/a&gt; where I downscale the input photos by a factor of two each time, until I reach the smallest possible level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For my downscaling routine, I'm using a really simple process:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create a new, blank texture using &lt;code&gt;texImage2D&lt;/code&gt; which is half the size of the original.&lt;/li&gt;&#xA;&lt;li&gt;Attach this texture to a frame buffer and use it as a render target (&lt;code&gt;bindFrameBuffer&lt;/code&gt;). I also set the viewport to match the new texture's size.&lt;/li&gt;&#xA;&lt;li&gt;Draw a flat quad whose vertices cover the screen-space coordinates (-1 -&gt; 1) using a 'copy-paste' shader which samples the original (full-size) texture. &lt;em&gt;Note that the texture parameters are always NEAREST and CLAMP_TO_EDGE.&lt;/em&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Here's the source code for my fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;&#xA;uniform sampler2D u_inputImage;  // Original full-size texture&#xA;&#xA;varying vec2 v_texCoords;&#xA;&#xA;void main()&#xA;{&#xA;    gl_FragColor = vec4(texture2D(u_inputImage, v_texCoords).rgb, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The result looks sensible, but the quality of the downscaled texture is pretty poor. In the following example, you can see how it looks jagged compared to the original, particularly along the edges of the table on the bottom-right. There are also some glitchy pixels on the top of the chair, and under the door handle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7Tpr9.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7Tpr9.jpg&quot; alt=&quot;Original&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/a3UHF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a3UHF.png&quot; alt=&quot;Downsampled&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know why this simple method doesn't seem to work? Is there a better way of creating a downsampled texture using WebGL/OpenGL?&lt;/p&gt;&#xA;" OwnerUserId="9577" LastEditorUserId="2654" LastEditDate="2018-10-27T01:54:26.340" LastActivityDate="2018-11-26T07:39:31.013" Title="WebGL - issues doing a simple texture downsample" Tags="&lt;texture&gt;&lt;webgl&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8190" PostTypeId="1" AcceptedAnswerId="8193" CreationDate="2018-10-27T19:53:57.320" Score="4" ViewCount="274" Body="&lt;p&gt;I am pretty new to Quaternions so please bear with me. I want to draw random Quaternion samples so that their Euler angle equivalent would range within &lt;code&gt;[-30, +30]&lt;/code&gt; degrees on each axis. Currently, I know how to sample Quaternions from the full range (&lt;code&gt;[-180, +180]&lt;/code&gt;) using the code below but I don't know how to modify the code so that I can get samples within the range &lt;code&gt;[-30, +30]&lt;/code&gt;. Can anyone help me with that? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if this is helpful to answer this question but here's a piece of information: I eventually want to convert the sampled Quaternion to Euler angles an apply the Euler rotation in some 3D shapes. The order of rotation in the software I'm using to do this is &lt;code&gt;XYZ&lt;/code&gt; meaning that it first rotates the 3D shape along the &lt;code&gt;X&lt;/code&gt; axis, then &lt;code&gt;Y&lt;/code&gt; axis and then &lt;code&gt;Z&lt;/code&gt; axis.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;def sample_Quaternion():&#xA;    r = np.random.uniform(0, 1 - 0.001, 3)&#xA;    while np.linalg.norm(r) &amp;gt; 1:&#xA;        r = np.random.uniform(0, 1 - 0.001, 3) # Just to keep the L2 norm within [0, 1.0)&#xA;    w = [np.sqrt(1 - (r[0]*r[0] + r[1]*r[1] + r[2]*r[2]))]&#xA;    r = np.concatenate(r, w) # the output of this would represent (x, y, z, w)&#xA;    return r&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2018-10-27T20:38:06.113" LastActivityDate="2018-10-27T22:31:41.873" Title="How to randomly draw Quaternions within a specific range of Euler angles for rotation?" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8191" PostTypeId="1" CreationDate="2018-10-27T21:51:47.480" Score="1" ViewCount="95" Body="&lt;p&gt;I am following &lt;a href=&quot;https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-1&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nvidia's DXR tutorial: D3D12HelloTriangle&lt;/a&gt;. I call below code before creating device and it returns &lt;strong&gt;true&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;UUID experimentalFeatures[] = { D3D12RaytracingPrototype };&#xA;HRESULT hr = D3D12EnableExperimentalFeatures(1, experimentalFeatures, NULL, NULL);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this causes later for &lt;code&gt;D3D12CreateDevice&lt;/code&gt; to fail. I am using Nvidia Geforce GTX 1050  : &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; Card name: NVIDIA GeForce GTX 1050&#xA;       Chip type: GeForce GTX 1050&#xA;        DAC type: Integrated RAMDAC&#xA;     Device Type: Full Device&#xA;      Device Key: Enum\PCI\VEN_10DE&amp;amp;DEV_1C8D&amp;amp;SUBSYS_12651025&amp;amp;REV_A1&#xA;   Device Status: 0180200A [DN_DRIVER_LOADED|DN_STARTED|DN_DISABLEABLE|DN_NT_ENUMERATOR|DN_NT_DRIVER] &#xA;  Driver Version: 23.21.13.8873&#xA;     DDI Version: 12&#xA;  Feature Levels: 12_1,12_0,11_1,11_0,10_1,10_0,9_3,9_2,9_1&#xA;    Driver Model: WDDM 2.3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2018-10-27T21:51:47.480" Title="D3D12EnableExperimentalFeatures causes D3D12CreateDevice to fail" Tags="&lt;directx12&gt;&lt;directx&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8192" PostTypeId="1" CreationDate="2018-10-27T22:23:47.460" Score="0" ViewCount="580" Body="&lt;p&gt;I'm implementing basic volumetric lighting using deferred shading (gbuffer + render to screen quad) and basic shadow mapping. So,  I am sending the position texture and shadow map to a separate shader, applying ray-marching for every position and computing the scattering accumulation when is not in shadow. The question is , how do I know I am getting the right results? is it just by rendering the volumetric lighting texture to quad and look for colored patches in the scene? these are my results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Original Scene&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2FrTy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2FrTy.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Volumetric Light buffer&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M1pmp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M1pmp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the code of my volumetric fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler2D positionMap; &#xA;uniform sampler2D shadowMap;&#xA;float NB_STEPS = 3.0f;&#xA;int NB_STEPS_INT = 3;&#xA;float G_SCATTERING = 0.7f;&#xA;out vec4 fragColor;&#xA;&#xA;void main()&#xA;{ &#xA;&#xA;vec2 texCoord = vec2(gl_FragCoord.x/width,gl_FragCoord.y/height);&#xA;vec3 worldPosition = texture2D(positionMap,texCoord).xyz;&#xA;vec3 startPosition = ViewPos;&#xA;&#xA;vec3 rayVector = worldPosition.xyz- startPosition;&#xA;float rayLength = length(rayVector);&#xA;vec3 rayDirection = normalize(rayVector);&#xA;float stepLength = rayLength / NB_STEPS;&#xA;vec3 step = rayDirection * stepLength;&#xA;&#xA;vec3 currentPosition = startPosition;&#xA;&#xA;vec3 accumFog = vec3(0.0f);&#xA;for(int i = 0;  i &amp;lt; NB_STEPS_INT; i++)&#xA;{&#xA;  bool shadow = ShadowCalculation(currentPosition);&#xA;  if(!shadow)&#xA;  {&#xA;    accumFog += ComputeScattering(dot(rayDirection, light.position)) * light.diffuse;&#xA;    //accumFog +=  light.diffuse;&#xA;  }&#xA;  currentPosition += step;&#xA;}&#xA;&#xA;accumFog /= NB_STEPS;&#xA;&#xA;fragColor = vec4(accumFog, 1);&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am computing the scattering factor like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float ComputeScattering(float lightDotView)&#xA;{&#xA;  float result = 1.0f - G_SCATTERING * G_SCATTERING;&#xA;  result /=  (4.0f * PI * pow(1.0f + G_SCATTERING * G_SCATTERING - (2.0f * G_SCATTERING) *    lightDotView, 1.5f));&#xA;  return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;At the end should I just blend the volumetric light buffer with the deferred shading final buffer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I appreciate the help.&lt;/p&gt;&#xA;" OwnerUserId="9506" LastActivityDate="2018-11-28T09:01:15.687" Title="GLSL Debugging Volumetric light" Tags="&lt;glsl&gt;&lt;deferred-rendering&gt;&lt;volumetric-scattering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8193" PostTypeId="2" ParentId="8190" CreationDate="2018-10-27T22:31:41.873" Score="2" Body="&lt;p&gt;The simplest way to do this would be to generate the Euler angles randomly, then use them to create the quaternion. Most existing quaternion implementations in game engines and 3D math libraries will have a &lt;code&gt;FromEuler ( Vector3 )&lt;/code&gt; function. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you seem to be rolling your own quaternions rather than using a library, here's the &lt;a href=&quot;https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Euler_Angles_to_Quaternion_Conversion&quot; rel=&quot;nofollow noreferrer&quot;&gt;conversion formula&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a small optimization, since quaternions use half-angles, you could generate random values in the range ±15 degrees (pi/12) and feed these to the sin and cos functions directly.&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-10-27T22:31:41.873" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8194" PostTypeId="1" CreationDate="2018-10-28T12:56:40.047" Score="4" ViewCount="66" Body="&lt;p&gt;I've been using standard 32-bit Xorshift in my GPU path-tracer for a while, following Nathan Reed's approach with hashed seeds and decorrelated state. I (finally) discovered today that Xorshift is considered obsolete and I should use a 64-bit+ PRNG instead for better-distributed values, but I obviously can't fake the operations needed for PCG and modern Xorshift without expensive software arithmetic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I've been considering the MRG32k3a hash by Pierre L'Ecuyer. It uses doubles instead of uint64s, it's included in Intel's Math Kernel Library, and &lt;a href=&quot;http://www.thesalmons.org/john/random123/papers/random123sc11.pdf&quot; rel=&quot;noreferrer&quot;&gt;some authors&lt;/a&gt; claim it has good statistical performance. It's also nearly twenty years old, though, and the paper linked above is dated from 2011.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is MRG32k3a still considered an effective PRNG? Is it an effective alternative to PCG and modern Xorshift?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If not, what else should I use? Philox seems &lt;a href=&quot;https://www.shadertoy.com/view/XslBR4&quot; rel=&quot;noreferrer&quot;&gt;interesting&lt;/a&gt;, but it's another old technique (published 2011) and I'm not sure if it's been superseded in the meantime.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;MRG32k3a MKL &lt;a href=&quot;https://software.intel.com/en-us/mkl-vsnotes-mrg32k3a&quot; rel=&quot;noreferrer&quot;&gt;entry&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://simul.iro.umontreal.ca/rng/MRG32k3a.c&quot; rel=&quot;noreferrer&quot;&gt;Example&lt;/a&gt; implementation from L'Ecuyer's paper&lt;/li&gt;&#xA;&lt;li&gt;The &lt;a href=&quot;https://www.researchgate.net/publication/261858547_Good_Parameters_and_Implementations_for_Combined_Multiple_Recursive_Random_Number_Generators&quot; rel=&quot;noreferrer&quot;&gt;paper&lt;/a&gt; itself&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2018-10-28T12:56:40.047" Title="Does MRG32k3a compare well with PCG and Xorshift256*?" Tags="&lt;pathtracing&gt;&lt;gpu&gt;&lt;sampling&gt;&lt;noise&gt;&lt;simulation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8195" PostTypeId="1" AcceptedAnswerId="8229" CreationDate="2018-10-28T16:43:46.143" Score="4" ViewCount="11411" Body="&lt;p&gt;I am rotating n 3D shape using Euler angles in the order of XYZ meaning that the object is first rotated along the &lt;code&gt;X&lt;/code&gt; axis, then &lt;code&gt;Y&lt;/code&gt; and then &lt;code&gt;Z&lt;/code&gt;. I want to convert the Euler angle to Quaternion and then get the same Euler angles back from the Quaternion using some [preferably] Python code or just some pseudocode or algorithm. Below, I have some code that converts Euler angle to Quaternion and then converts the Quaternion to get Euler angles. However, this does not give me the same Euler angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think the problem is I don't know how to associate &lt;em&gt;yaw, pitch and roll&lt;/em&gt; to X, Y an Z axes. Also, I don't know how to change order of conversions in the code to correctly convert the Euler angles to Quaternion and then convert the Quaternion to Euler angle so that I am able to get the same Euler angle back. Can someone help me with this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here's the code I used:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This function converts Euler angles to Quaternions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def euler_to_quaternion(yaw, pitch, roll):&#xA;&#xA;        qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)&#xA;        qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)&#xA;        qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)&#xA;        qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)&#xA;&#xA;        return [qx, qy, qz, qw]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this converts Quaternions to Euler angles:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def quaternion_to_euler(x, y, z, w):&#xA;&#xA;        import math&#xA;        t0 = +2.0 * (w * x + y * z)&#xA;        t1 = +1.0 - 2.0 * (x * x + y * y)&#xA;        X = math.degrees(math.atan2(t0, t1))&#xA;&#xA;        t2 = +2.0 * (w * y - z * x)&#xA;        t2 = +1.0 if t2 &amp;gt; +1.0 else t2&#xA;        t2 = -1.0 if t2 &amp;lt; -1.0 else t2&#xA;        Y = math.degrees(math.asin(t2))&#xA;&#xA;        t3 = +2.0 * (w * z + x * y)&#xA;        t4 = +1.0 - 2.0 * (y * y + z * z)&#xA;        Z = math.degrees(math.atan2(t3, t4))&#xA;&#xA;        return X, Y, Z&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I use them as follow:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;euler_Original = np.random.random(3) * 360).tolist() # Generate random rotation angles for XYZ within the range [0, 360)&#xA;quat = euler_to_quaternion(euler_Original[0], euler_Original[1], euler_Original[2]) # Convert to Quaternion&#xA;newEulerRot = quaternion_to_euler(quat[0], quat[1], quat[2], quat[3]) #Convert the Quaternion to Euler angles&#xA;&#xA;print (euler_Original)&#xA;print (newEulerRot)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The print statements print different numbers for &lt;code&gt;euler_Original&lt;/code&gt; and &lt;code&gt;newEulerRot&lt;/code&gt; which I don't want to be the case. For example if &lt;code&gt;euler_original&lt;/code&gt; contains numbers like &lt;code&gt;(0.2, 1.12, 2.31)&lt;/code&gt; in radians I get this Quaternion --&gt; &lt;code&gt;[0.749, 0.290, -0.449, 0.389]&lt;/code&gt; and converting the Quaternion to Euler angles gives me this --&gt; &lt;code&gt;(132.35, 64.17, 11.45)&lt;/code&gt; which is pretty wrong. I wonder how I can fix this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although I'm interested in getting the above code to work by making changes to it but, I would rather learn how to set up the equations correctly. This way I would know how I can get the correct Quaternions even if the order of rotations (XYZ --&gt; YZX etc) for applying Euler angles is changed.&lt;/p&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2018-10-28T20:28:59.110" LastActivityDate="2018-11-06T16:40:43.313" Title="How to convert Euler angles to Quaternions and get the same Euler angles back from Quaternions?" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8196" PostTypeId="1" AcceptedAnswerId="8202" CreationDate="2018-10-28T17:10:34.150" Score="1" ViewCount="75" Body="&lt;p&gt;I currently have a 4K monitor and want to buy a new graphics card. My choice would either be the RTX 2080 or the RTX 2080 Ti. Now I need to know which one I really need. The Ti variant has 12 GB of GDDR6 instead of just 8 GB (and more shader cores of course, which makes the card faster)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, what elements do actually get loaded into the GDDR6 memory? Is it only the textures or is there other stuff that needs to be loaded into the GPU memory? Does the memory consumption differ when comparing 1080p(HD) and 2160p(4K)? What if you would run a game at 4320p (8K)? People say that you need more GPU memory if you have a higher resolution, is this really true? And what things do you need to take into account when calculating the rough memory usage?&lt;/p&gt;&#xA;" OwnerUserId="9582" LastActivityDate="2018-10-30T09:42:00.020" Title="What objects do get loaded into GDDR?" Tags="&lt;gpu&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8197" PostTypeId="2" ParentId="8192" CreationDate="2018-10-29T08:24:50.503" Score="1" Body="&lt;p&gt;This question is a bit too broad to answer, but I'll try.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Right now you have a screenshot and you are not really sure whether it's correct or not, and if it turns out it is not, it will be difficult to know what is incorrect about it. I would recommend to split your problem into smaller, isolated, problems that can be validated separately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, is the lighting information correct at each point? Are the coordinates (screen space vs world space) correct? To answer these questions you could maybe represent the distance from the light at each point, with something like the following, and check that the visual result is consistent with your scene.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;color = fract(length(light.position - currentPosition));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Similarly, is the shadowing correct? This problem is unrelated to scattering so you can check that it  is correct by just having a constant light contribution (your commented code seems to indicate that you have tried so already). You will see quickly if a volumetric shadow is properly cast from occluding geometry.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (!shadow)&#xA;{&#xA;    accumFog += light.diffuse;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Finally you can test the scattering without any shadow, and make sure it behaves as expected. For example, you should get the same fog color when changing the number of steps. Moreover, the scattering contribution should be less noticeable when there is geometry close to the camera (make sure you stop marching when you reach the scene depth).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you are confident the separate parts are working, you can combine them until you reach the final result. I have suggested a few points to check, but you might check other points as well, as you see fit.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;At the end should I just blend the volumetric light buffer with the deferred shading final buffer?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Since the lighting is additive, you just need to do an additive blend of the resulting buffer on your scene. However if you later decide to also handle distance fog (contrast fading in the distance), then a different blending will be necessary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S.: I happen to have written &lt;a href=&quot;http://www.ctrl-alt-test.fr/2018/a-dive-into-the-making-of-immersion/&quot; rel=&quot;nofollow noreferrer&quot;&gt;about volumetric lighting in this article&lt;/a&gt; (see part &quot;Volumetric lighting&quot;). It doesn't go into details, but maybe it will be helpful nonetheless.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2018-10-29T08:24:50.503" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8201" PostTypeId="1" AcceptedAnswerId="8212" CreationDate="2018-10-29T16:58:10.443" Score="0" ViewCount="58" Body="&lt;p&gt;Wonder if anyone has experienced this. When generating png image icons for macos. its recommended at 19x19 pixels. However, based on that, the icon (shield) that is generated is pixellated compared with the next in line. I have tried using 38x38, which effectively doubles the pixels. It looks much finer in preview but when attached, it because a large icon cropped off the bottom. Are there are specifics to generating a retina compatible icon for mac status bar?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/658Ge.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/658Ge.png&quot; alt=&quot;screenshot of menu bar&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9594" LastEditorUserId="3003" LastEditDate="2018-11-01T05:06:42.807" LastActivityDate="2018-11-01T20:54:22.970" Title="Resolution issue of generating a PNG icon for macOS menu bar" Tags="&lt;image-processing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8202" PostTypeId="2" ParentId="8196" CreationDate="2018-10-30T02:01:59.900" Score="1" Body="&lt;p&gt;Typically you will need VRAM to store your frame buffer (memory used to store pixels for use with the display and for rendering). This would usually be 4 bytes per pixel so a 1080p frame buffer is 1920x1080x4 bytes (1 byte each for R,G,B components + 1 padding byte). Your card is going to use 2 of these for double buffering so it can use one for display output and the other for constructing the next frame. Any increase in resolution will require an increase in VRAM usage. If HDR is used then you're looking at 16 bytes per pixel so you can use floating point accuracy. Certain types of post-processing special effects may also need additional rendering buffers which are some division of the screen resolution so will consequently use more VRAM if using a higher resolution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After that the majority of VRAM is going to be allocated for textures which for a typical game is the biggest user of VRAM. Then mesh data needs storing in VRAM which usually consists of vertices storing information like geometry position/normals/colours/transformation matrices/etc. Finally compiled shaders will need to occupy VRAM but they should be low down on memory usage compared to textures and mesh data. There will be other uses for VRAM too depending on how the game was engineered so this is not an exhaustive list of what VRAM is used for.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short: Display resolution will change the amount of VRAM required but not by a large amount. For a video game most VRAM is from textures which are usually defined by the quality settings of the game and are not affected by display resolution. The 12gb card you mentioned will allow higher texture resolution but with your choice of 1080p or 4k display resolution making little difference in VRAM usage. However for 4k it makes sense to use the highest texture quality.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2018-10-30T09:42:00.020" LastActivityDate="2018-10-30T09:42:00.020" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8205" PostTypeId="1" CreationDate="2018-10-30T11:01:34.277" Score="2" ViewCount="96" Body="&lt;p&gt;Does anyone know what software was used in many old scientific papers (please see attached example). I love the clean look of the graph and the typeface.&#xA;Thanks.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/uLABG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Graph example&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9603" LastActivityDate="2018-10-30T11:01:34.277" Title="Plotting software used in old scientific papers" Tags="&lt;vector-graphics&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8206" PostTypeId="2" ParentId="8189" CreationDate="2018-10-30T11:20:32.910" Score="2" Body="&lt;p&gt;The downscaled picture is not smooth because you use &quot;nearest&quot; filtering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each block of 2x2 pixels in the original image is transformed into a single pixel in the downscaled image. Put another way, each pixel in the downscaled image represents the contents of 4 original pixels. Your current solution considers just one of those 4 pixels and ignores the others. This is what produces blockiness in the downscaled picture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this, each downscaled pixel must contain information from more than one original pixel. The simplest way to do this is by using a &quot;box filter&quot; where each downscaled pixel is computed as the mean of the 4 original pixels it covers. This can be achieved in a single texture fetch with linear filtering and the proper sampling position:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;+---+---+&#xA;| A | B |  // ABCD =&amp;gt; original pixels&#xA;+---X---+  // X =&amp;gt; sample position in the middle of the 4 pixels (texels)&#xA;| C | D |&#xA;+---+---+&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Linear filtering sampled at position &lt;code&gt;0&lt;/code&gt; will give &lt;code&gt;(A+B+C+D) / 4&lt;/code&gt; or the average value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another computer graphic term for what you're doing is &quot;mipmap generation&quot;. There are other filters which give better quality than the simple box filter I described.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2018-10-30T11:20:32.910" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8209" PostTypeId="1" CreationDate="2018-10-31T12:20:17.933" Score="0" ViewCount="172" Body="&lt;p&gt;I want to open a .off file and view the content 3d model using libQGLViewer, qt-creator.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know how to display the 3d model after opening its .off file.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;QString fileName = QFileDialog::getOpenFileName(this,tr(&quot;Open .off model&quot;), &quot;/home&quot;, tr(&quot;*.off&quot;));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9462" LastEditorUserId="231" LastEditDate="2018-11-05T20:09:53.327" LastActivityDate="2021-04-24T01:36:08.547" Title="qt - view geomview (.off ) file" Tags="&lt;3d&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8210" PostTypeId="2" ParentId="8209" CreationDate="2018-10-31T12:57:14.707" Score="0" Body="&lt;p&gt;From a quick gander through the examples it looks like QGLViewer is a thin wrapper around a opengl window using the legacy api. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what you really need is a way to load a .off file to render in legacy opengl. &lt;a href=&quot;https://en.wikipedia.org/wiki/OFF_(file_format)&quot; rel=&quot;nofollow noreferrer&quot;&gt;it looks like a very simple format&lt;/a&gt;, even simpler than .obj. So simple that IMO it is worth it for you to figure out on your own.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2018-10-31T12:57:14.707" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8212" PostTypeId="2" ParentId="8201" CreationDate="2018-11-01T20:54:22.970" Score="4" Body="&lt;p&gt;The issue is the difference between pixel and point sizes. On macOS and other Apple platforms, the user interface is measured in points, which don’t necessarily map one-to-one to pixels; on a Retina screen like the one you’re using, 1 point is 2 pixels. Since there’s no way for the system to know whether your image’s scale is the same as the screen’s, it’s assuming that each pixel in your larger image is meant to be one point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to resolve this would be to explicitly set the &lt;a href=&quot;https://developer.apple.com/documentation/appkit/nsimage/1519987-size&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;size&lt;/code&gt;&lt;/a&gt; property on your NSImage to the point size your image is supposed to be drawn at, i.e. 19×19; you’d have to handle loading different images for 1x and 2x screens on your own, though, which is inconvenient. A better way would be to use an &lt;a href=&quot;https://developer.apple.com/library/archive/documentation/ToolsLanguages/Conceptual/Xcode_Overview/AddingImages.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;asset catalog&lt;/a&gt; in your project, which will let you specify assets for 1x and 2x screens and allow you to load the appropriate image by name.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Simon F pointed out, future questions in this vein probably belong on &lt;a href=&quot;https://stackoverflow.com&quot;&gt;Stack Overflow&lt;/a&gt;—it’s more about API usage than graphics concepts.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2018-11-01T20:54:22.970" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8213" PostTypeId="1" AcceptedAnswerId="8214" CreationDate="2018-11-02T05:19:58.200" Score="8" ViewCount="3068" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FEEVq.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FEEVq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/yBUh2.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yBUh2.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some context. Above are the code and the resulting image for it in Peter Shirley's Raytracing in one weekend's book. As you can see from the code, he adds in some spheres. And yet in the final image there are 2 ellipsoids side by side. I just can't fathom why it is so, no matter how many time I looked at the code. Can anyone explain to me? Here's the link to the source code.&#xA;&lt;a href=&quot;https://github.com/petershirley/raytracinginoneweekend&quot; rel=&quot;noreferrer&quot;&gt;https://github.com/petershirley/raytracinginoneweekend&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8699" LastActivityDate="2018-11-02T07:50:54.963" Title="Raytracing: why are the spheres in the image below appear stretched?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8214" PostTypeId="2" ParentId="8213" CreationDate="2018-11-02T07:07:36.833" Score="16" Body="&lt;p&gt;Shapes appearing stretched in the periphery is a consequence of perspective projection. The wider the field of view (FOV) is, the stronger the stretching effect gets.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To demonstrate the effect I wrote a quick example on ShaderToy: &lt;a href=&quot;https://www.shadertoy.com/view/MltBW2&quot; rel=&quot;noreferrer&quot;&gt;https://www.shadertoy.com/view/MltBW2&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see on the images below (corresponding to FOV of 40, 80 and 120; if I didn't make any mistake), this becomes especially noticeable with wide FOV, like 90° and above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/MltBW2&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/99bS1.png&quot; alt=&quot;FOV 40°&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/MltBW2&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pSDlz.png&quot; alt=&quot;FOV 80°&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://www.shadertoy.com/view/MltBW2&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/K2fI7.png&quot; alt=&quot;FOV 120°&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2018-11-02T07:50:54.963" LastActivityDate="2018-11-02T07:50:54.963" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8216" PostTypeId="2" ParentId="2288" CreationDate="2018-11-02T21:08:20.193" Score="3" Body="&lt;p&gt;The Flurry screensaver written by Calum Robinson is available as a part of the XScreenSaver package. You can download its source code from &lt;a href=&quot;https://www.jwz.org/xscreensaver/download.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.jwz.org/xscreensaver/download.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The flurry* files are in the hacks/glx directory. It's not an easy job to reverse engineer the algorithm from the source code, but debugging might help.&lt;/p&gt;&#xA;" OwnerUserId="9628" LastActivityDate="2018-11-02T21:08:20.193" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8217" PostTypeId="1" AcceptedAnswerId="8221" CreationDate="2018-11-03T11:05:30.260" Score="1" ViewCount="166" Body="&lt;p&gt;I am well aware that there are several ways to find the tangents to a Bezier curve. However, I choose to just substitute the result of differentiating the Bezier curve equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, given four control points, &lt;code&gt;ptOne&lt;/code&gt;, &lt;code&gt;ptTwo&lt;/code&gt;, &lt;code&gt;ptThree&lt;/code&gt; and &lt;code&gt;ptFour&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Differentiate x with respect to t&#xA;float dxdt = -3*(1 - t)*(1 - t)*ptOne.x&#xA;+ 3*(1 - 4*t + 3*t*t)*ptTwo.x&#xA;+ 3*(2*t - 3*t*t)*ptThree.x&#xA;+ 3*t*t*ptFour.x;&#xA;&#xA;// Differentiate y with respect to t&#xA;float dydt = -3*(1 - t)*(1 - t)*ptOne.y&#xA;+ 3*(1 - 4*t + 3*t*t)*ptTwo.y&#xA;+ 3*(2*t - 3*t*t)*ptThree.y&#xA;+ 3*t*t*ptFour.y;&#xA;&#xA;// Find the tangent, dy/dx&#xA;float dydx = dydt * (1/dxdt);&#xA;&#xA;// Find the rotation angle in degrees&#xA;float angle = atan(dydx) * 180/M_PI;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The strange thing is that this does not seem to be working for all kinds of curve. For example, if I draw a curve like this, with the first control point being the second leftmost point and then in a clockwise direction:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eSfoL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eSfoL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and attempt to draw the tangents:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/i0Kdk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/i0Kdk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see that some tangents (in particular, the first two and very last one) are not oriented in the right direction. Why might this be happening? I triple checked my differentiation and can't find anything wrong...&lt;/p&gt;&#xA;" OwnerUserId="9631" LastEditorUserId="2654" LastEditDate="2018-11-03T13:49:02.847" LastActivityDate="2018-11-05T05:26:49.550" Title="Wrong tangential directions for cubic bezier curve" Tags="&lt;mathematics&gt;&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8218" PostTypeId="2" ParentId="8157" CreationDate="2018-11-04T08:16:36.350" Score="3" Body="&lt;p&gt;Yes, your understanding it correct. The Laplace-Beltrami depends on the current state &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and you have to recompute &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; if &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; changes. Therefore you cannot write matix of &lt;span class=&quot;math-container&quot;&gt;$\Delta$&lt;/span&gt; without knowing the state &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To expand on solving &lt;span class=&quot;math-container&quot;&gt;$\frac{\partial x}{\partial t} = -\Delta x$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Discretization in space turns &lt;span class=&quot;math-container&quot;&gt;$\Delta$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;, discretization in time turns &lt;span class=&quot;math-container&quot;&gt;$\frac{\partial x}{\partial t}$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$\frac{x_{n+1} - x_n}{h}$&lt;/span&gt; and decide if we evaluate the right hand side at time &lt;span class=&quot;math-container&quot;&gt;$t_n$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$t_{n+1}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Option 1 = Forward Euler&lt;/strong&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;x_{n+1} - x_n = h L_n x_n&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$L_n = L(x_n)$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; is considered as a function of the state &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;. As you have mentioned this method can be unstable if we take too big step &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt;. Therefore, we often resort to the second option.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Option 2 = Backward Euler&lt;/strong&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;x_{n+1} - x_n = h L_{n+1} x_{n+1}&#xA;$$&lt;/span&gt;&#xA;Because &lt;span class=&quot;math-container&quot;&gt;$L_{n+1}$&lt;/span&gt; depends on &lt;span class=&quot;math-container&quot;&gt;$x_{n+1}$&lt;/span&gt; the above equation is non-linear system, we cannot solve it with a simple linear solve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The common approach is to Taylor expand &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; around the point &lt;span class=&quot;math-container&quot;&gt;$x_n$&lt;/span&gt;, general Taylor expansion around point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L(x + \Delta x) = L(x) + \nabla L(x) \cdot \Delta x + \dots&#xA;$$&lt;/span&gt;&#xA;therefore for &lt;span class=&quot;math-container&quot;&gt;$x= x_n$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\Delta x = x_{n+1} - x_n$&lt;/span&gt; we get&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L_{n+1} = L(x_{n+1}) = L(x_n + \Delta x) = L(x_n) + \nabla L(x_n) \cdot \Delta x + \dots&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simplest thing to do is to take just the first term of the Taylor expansion, i.e. we replace &lt;span class=&quot;math-container&quot;&gt;$L_{n+1}$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$L_n$&lt;/span&gt;. This way, we end up with a linear problem&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;x_{n+1} - x_n = h L_{n} x_{n+1}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can take higher order terms or solve the Backward Euler equation with non-linear solver. However, in your case that is probably unnecessary and the headache of computing the gradient of &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; is not worth it(I might be wrong here, I do not have hands on experience with solving this equation). &lt;/p&gt;&#xA;" OwnerUserId="1613" LastEditorUserId="1613" LastEditDate="2018-11-04T13:15:15.707" LastActivityDate="2018-11-04T13:15:15.707" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8219" PostTypeId="1" CreationDate="2018-11-04T20:18:11.737" Score="0" ViewCount="137" Body="&lt;p&gt;I'm trying to compute a projection matrix to transform from view space to NDC with a near clip plane at -1 and far plane at +1. The general form of this matrix (disregarding aspect ratio and focal length) should be&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}1&amp;amp;0&amp;amp;0&amp;amp;0\\0&amp;amp;1&amp;amp;0&amp;amp;0\\0&amp;amp;0&amp;amp;A&amp;amp;B\\0&amp;amp;0&amp;amp;-1&amp;amp;0\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I followed SongHo's guide at &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.songho.ca/opengl/gl_projectionmatrix.html&lt;/a&gt; which sets &lt;span class=&quot;math-container&quot;&gt;$A=-(f+n)/(f-n)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B=-2fn/(f-n)$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, setting the near clip plane at &lt;span class=&quot;math-container&quot;&gt;$n=-1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$f=-10$&lt;/span&gt; (in view space) and using these &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt;, I get points with &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; values on the interval &lt;span class=&quot;math-container&quot;&gt;$[-1, -10]$&lt;/span&gt; transformed to &lt;span class=&quot;math-container&quot;&gt;$[3.04, 1.04]$&lt;/span&gt; (after homogenisation). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I do the derivations myself, I'd like to set &lt;span class=&quot;math-container&quot;&gt;$A=(n+f)/(n-f)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B=(-2fn)/(n-f)$&lt;/span&gt; instead, which indeed transforms to &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt; instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I doing something wrong?&lt;/p&gt;&#xA;" OwnerUserId="4650" LastActivityDate="2018-11-04T21:40:54.783" Title="How to compute A and B in projection matrix" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8220" PostTypeId="2" ParentId="8219" CreationDate="2018-11-04T21:01:35.200" Score="1" Body="&lt;p&gt;Note: I'll be using column vector notation (eg. &lt;span class=&quot;math-container&quot;&gt;$Ax=y$&lt;/span&gt;), thus if you are using row notation, transpose the matrix and multiply from the left instead of the right. (eg. &lt;span class=&quot;math-container&quot;&gt;$y=x^TA^T$&lt;/span&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A perspective transformation matrix transforms a view frustum into a rectangular view volume. Note that the resulting view volume might &lt;strong&gt;not&lt;/strong&gt; be a cube and might &lt;strong&gt;not&lt;/strong&gt; be centered at 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One &lt;em&gt;example&lt;/em&gt; of a perspective transformation matrix. There are &lt;strong&gt;many more&lt;/strong&gt;, and yours is included.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$l=left,\\ r = right,\\ b = bottom,\\ t = top,\\ n = near,\\ f = far$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{persp}=\begin{bmatrix}&#xA;1&amp;amp; &amp;amp; &amp;amp; \\&#xA; &amp;amp;1&amp;amp; &amp;amp; \\&#xA; &amp;amp; &amp;amp;\frac{n+f}{n}&amp;amp;-f\\&#xA; &amp;amp; &amp;amp;\frac{1}{n}&amp;amp; &#xA;\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the resulting view volume is not the canonical view volume, we need to apply another matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A orthographic transformation matrix transforms a rectangular view volume into a cubic view volume with two corners at (-1, -1, -1) and (1, 1, 1), which happens to be the canonical view volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intuitively it will need one translation and one scaling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\text{T}_{ortho} = S\left(\frac{2}{r-l},\frac{2}{t-b},\frac{2}{n-f}\right)T\left(\frac{-(l+r)}{2},\frac{-(b+t)}{2}\frac{-(n+f)}{2}\right)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{ortho} = &#xA;\begin{bmatrix}&#xA;    \frac{2}{r-l}&amp;amp; &amp;amp; &amp;amp; \\&#xA;    &amp;amp; \frac{2}{t-b} &amp;amp; &amp;amp; \\&#xA;    &amp;amp; &amp;amp; \frac{2}{n-f} &amp;amp; \\&#xA;    &amp;amp; &amp;amp; &amp;amp; 1&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;    1 &amp;amp; &amp;amp; &amp;amp; \frac{-(l+r)}{2} \\&#xA;    &amp;amp; 1 &amp;amp; &amp;amp; \frac{-(b+t)}{2} \\&#xA;    &amp;amp; &amp;amp; 1 &amp;amp; \frac{-(n+f)}{2} \\&#xA;    &amp;amp; &amp;amp; &amp;amp; 1&#xA;\end{bmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{ortho} = &#xA;\begin{bmatrix}&#xA;    \frac{2}{r-l}&amp;amp; &amp;amp; &amp;amp; -\frac{l+r}{r-l} \\&#xA;    &amp;amp; \frac{2}{t-b} &amp;amp; &amp;amp; -\frac{t+b}{t-b} \\&#xA;    &amp;amp; &amp;amp; \frac{2}{n-f} &amp;amp; -\frac{n+f}{n-f}\\&#xA;    &amp;amp; &amp;amp; &amp;amp; 1&#xA;\end{bmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can combine them together to form a &lt;strong&gt;perspective projection&lt;/strong&gt; matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{proj} = M_{ortho}M_{persp}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{proj} = &#xA;\begin{bmatrix}&#xA;    \frac{2}{r-l}&amp;amp; &amp;amp; &amp;amp; -\frac{l+r}{r-l} \\&#xA;    &amp;amp; \frac{2}{t-b} &amp;amp; &amp;amp; -\frac{t+b}{t-b} \\&#xA;    &amp;amp; &amp;amp; \frac{2}{n-f} &amp;amp; -\frac{n+f}{n-f}\\&#xA;    &amp;amp; &amp;amp; &amp;amp; 1&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;1&amp;amp; &amp;amp; &amp;amp; \\&#xA; &amp;amp;1&amp;amp; &amp;amp; \\&#xA; &amp;amp; &amp;amp;\frac{n+f}{n}&amp;amp;-f\\&#xA; &amp;amp; &amp;amp;\frac{1}{n}&amp;amp; &#xA;\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{proj} = &#xA;\begin{bmatrix}&#xA;    \frac{2n}{r-l}&amp;amp; &amp;amp; \frac{l+r}{l-r} &amp;amp; \\&#xA;    &amp;amp; \frac{2n}{t-b} &amp;amp; \frac{b+t}{b-t} &amp;amp; \\&#xA;    &amp;amp; &amp;amp; \frac{n+f}{n-f} &amp;amp; \frac{2fn}{f-n}\\&#xA;    &amp;amp; &amp;amp; 1 &amp;amp;&#xA;\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have a free-moving camera you will need a camera matrix too, thus the final projection matrix centered on the camera is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M_{proj} = M_{ortho}M_{persp}M_{camera}$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="9637" LastEditorUserId="9637" LastEditDate="2018-11-04T21:40:54.783" LastActivityDate="2018-11-04T21:40:54.783" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8221" PostTypeId="2" ParentId="8217" CreationDate="2018-11-05T05:26:49.550" Score="0" Body="&lt;p&gt;Using what Rahul kindly suggested in the comments, I realised that my tangent can be rotated in the opposite direction for two cases:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;if &lt;code&gt;dy/dt&lt;/code&gt; and &lt;code&gt;dx/dt&lt;/code&gt; are both negative, yet &lt;code&gt;dy/dx&lt;/code&gt; ends up being positive&lt;/li&gt;&#xA;&lt;li&gt;if &lt;code&gt;dy/dt&lt;/code&gt; is negative and &lt;code&gt;dx/dt&lt;/code&gt; is positive, so the overall &lt;code&gt;dy/dx&lt;/code&gt; is negative&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This is because my angle calculation, which is done by &lt;code&gt;float angle = atan(dydx) * 180/M_PI;&lt;/code&gt; will only calculate acute angles from the horizontal, and hence miss out the opposite cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a bunch!&lt;/p&gt;&#xA;" OwnerUserId="9631" LastActivityDate="2018-11-05T05:26:49.550" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8223" PostTypeId="1" AcceptedAnswerId="8224" CreationDate="2018-11-06T01:47:24.333" Score="1" ViewCount="862" Body="&lt;p&gt;I understand that HDR files are images encoded with a higher precision in order to keep more details.&lt;br&gt;&#xA;When loading such images in real-time rendering applications using common Graphics APIs (DirectX, OpenGL, Vulkan), which are the &quot;HDR texture formats&quot; that ensure details will be preserved?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2018-11-18T08:50:41.157" Title="Which graphics APIs texture formats are HDR texture formats?" Tags="&lt;texture&gt;&lt;api&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8224" PostTypeId="2" ParentId="8223" CreationDate="2018-11-06T03:53:38.973" Score="3" Body="&lt;p&gt;In general, using floating point textures will help preserve HDR values. They can be 16-bit or 32-bit floats for the color channels, usually. In OpenGL you could choose the type to be &lt;code&gt;GL_FLOAT&lt;/code&gt; for 32-bits per channel or &lt;code&gt;GL_HALF_FLOAT&lt;/code&gt; for 16-bits per channel. In my experience, for image processing, 16-bits is usually enough and is half as much data.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-11-06T03:53:38.973" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8225" PostTypeId="1" AcceptedAnswerId="8228" CreationDate="2018-11-06T09:50:54.360" Score="0" ViewCount="188" Body="&lt;p&gt;I have a scene with camera facing billboards drawn with depth write off so they appear on top of other objects. I would like to draw each sprite so that any  obscured pixels are drawn with a very low opacity. So that obscured portions of each sprite are visible but very faint.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone point me in the direction of a solution? I am using Threejs but I imagine the solution will be shader (glsl) based. I already have the depth texture for the scene available.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2iJbr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2iJbr.png&quot; alt=&quot;Diagram showing desired effect&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sketchfab implements this with its annotations, which is the effect I would like to acheive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jItdi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jItdi.png&quot; alt=&quot;Sketchfab example of desired effect&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9647" LastActivityDate="2018-11-06T14:43:46.397" Title="Using depth texture to mask local pixels" Tags="&lt;glsl&gt;&lt;webgl&gt;&lt;three.js&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8226" PostTypeId="1" AcceptedAnswerId="8243" CreationDate="2018-11-06T14:18:57.807" Score="0" ViewCount="79" Body="&lt;p&gt;I import a mesh in Blender, export it with setting &lt;code&gt;axis_forward='-Z', axis_up='Y'&lt;/code&gt;, import in NVIDIA's FleX, rotate it and store it on disk; I call this mesh &lt;code&gt;X&lt;/code&gt;. I also import the mesh in Blender and rotate it the same amount; I call this mesh &lt;code&gt;Y&lt;/code&gt;. After I imported &lt;code&gt;X&lt;/code&gt; in Blender (setting &lt;code&gt;axis_forward='-Z', axis_up='Y'&lt;/code&gt;) I realized that &lt;code&gt;X&lt;/code&gt; has a different rotation which means that FleX is either using a different global axes (I think it's &lt;code&gt;-Y&lt;/code&gt; forward and &lt;code&gt;Z&lt;/code&gt; up) or it applies the rotations in a different order or a combination of both. So I am pretty confused now. I do not want to change anything on the FleX side. However, I want to rotate &lt;code&gt;Y&lt;/code&gt; in a way that it matches with what FleX exports (&lt;code&gt;X&lt;/code&gt;) after rotation. I also tried with Quaternions but I'm still unable to figure out the way FleX is transforming the object. The only thing that I've been able to figure out empirically is that the value for &lt;code&gt;rx&lt;/code&gt; rotation is applied the same way for both FleX and Blender. This means that objects &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; would overlap completely if imported in on scene in Blender. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My goal&lt;/strong&gt; is to rotate the object in FleX so that object &lt;code&gt;Y&lt;/code&gt;'s rotation matches exactly with object &lt;code&gt;X&lt;/code&gt; when I import &lt;code&gt;X&lt;/code&gt; in Blender. For instance, I want FleX rotate the object the same way as Blender rotates it with the Euler rotation vector of &lt;code&gt;[rx, ry, rz]&lt;/code&gt;. How can I achieve this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that I am not changing the rotation order in Blender and I'm using the default &lt;code&gt;XYZ&lt;/code&gt; rotation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here I are some images of the visual differences between FleX and Blender for such transformations:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Euler rotation vector: &lt;code&gt;[0, 89.9, 0]&lt;/code&gt; in for object &lt;code&gt;Y&lt;/code&gt; in Blender.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After applying the rotation in Blender (object &lt;code&gt;Y&lt;/code&gt;):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/BoZEo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BoZEo.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After applying the same rotation (&lt;code&gt;[0, 89.9, 0]&lt;/code&gt;) in FleX and importing the object &lt;code&gt;X&lt;/code&gt; in Blender:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/FDQIH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FDQIH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Euler rotation vector: &lt;code&gt;[0, 0, 89.9]&lt;/code&gt; for object &lt;code&gt;Y&lt;/code&gt; in Blender.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HJYPn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HJYPn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After applying the same rotation (&lt;code&gt;[0, 0, 89.9]&lt;/code&gt;) in FleX and importing the object &lt;code&gt;X&lt;/code&gt; in Blender:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/lU597.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lU597.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It might look it is easy to guess from the images that FleX swaps the &lt;code&gt;ry&lt;/code&gt; and &lt;code&gt;rz&lt;/code&gt; when applying the rotation. If I also swap &lt;code&gt;ry&lt;/code&gt; and &lt;code&gt;rz&lt;/code&gt; when applying the rotations in Blender then both &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; overlap. However, this only works if all components of the rotation vector are zero except one of them. If the rotation vector is something like &lt;code&gt;[-43.964176, 20.641195, -1.2689421]&lt;/code&gt; &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; do not overlap anymore and discrepancies start to show up as shown below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/27rIH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/27rIH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The discrepancies are more visible if I put a cloth on &lt;code&gt;X&lt;/code&gt; in FleX, import the cloth and &lt;code&gt;Y&lt;/code&gt; in Blender and rotate &lt;code&gt;Y&lt;/code&gt; by &lt;code&gt;[-43.964176, -1.2689421, 20.641195]&lt;/code&gt; (notice that I've swapped &lt;code&gt;ry&lt;/code&gt; and &lt;code&gt;rz&lt;/code&gt; when applying the rotation in Blender, not in FleX):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DxlAh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DxlAh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that if I import &lt;code&gt;X&lt;/code&gt; here, the cloth would be perfectly covering it while touching it on the surface:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hhzeO.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hhzeO.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After doing some hacking for the last example, I noticed that if I apply the rotation vector &lt;code&gt;[-43.964176, 1.2689421, 20.641195]&lt;/code&gt; (rx, -rz, ry) the objects overlap almost perfectly:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TfeI5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TfeI5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For another example, I want to apply the rotation &lt;code&gt;[87.68034, 79.94778, 82.697876]&lt;/code&gt; in Blender which should &lt;strong&gt;ideally&lt;/strong&gt; give me something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eSJ3o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eSJ3o.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, FleX is giving me the following (no swapping before passing the rotation vector to FleX):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZfScD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZfScD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was thinking maybe applying the rotation in order of &lt;code&gt;(rx, -rz, ry)&lt;/code&gt; in Blender would give me the perfectly overlapping result that I got for the previous example, but instead I got very weird results for another as shown below. Note that I wanted to rotate the object by [87.68034, 79.94778, 82.697876]`:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P01F0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P01F0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By manually rotating the object in Blender I could eventually get it as close as possible to &lt;code&gt;Y&lt;/code&gt; (exported from FleX). Surprisingly, the rotation vector that overlaps &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; is way different than &lt;code&gt;[87.68034, 79.94778, 82.697876]&lt;/code&gt; in &lt;code&gt;(rx, ry, rz)&lt;/code&gt; or &lt;code&gt;[87.68034 -82.697876, 79.94778]&lt;/code&gt; in &lt;code&gt;(rx, -rz, ry)&lt;/code&gt;. It is something around &lt;code&gt;[5.38, -10.1, 88.6]&lt;/code&gt; in `(rx, ry, rz) as shown below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Jm2jS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Jm2jS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although you might need more information to figure out exactly what's going out but below I post the code that is used in FleX to compute its rotation matrices. The top one is used when Euler angles are used and the second one is used when Quaternions are input:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// generate a rotation matrix around an axis, from PBRT p74&#xA;inline Mat44 RotationMatrix(float angle, const Vec3&amp;amp; axis)&#xA;{&#xA;    Vec3 a = Normalize(axis);&#xA;    float s = sinf(angle);&#xA;    float c = cosf(angle);&#xA;&#xA;    float m[4][4];&#xA;&#xA;    m[0][0] = a.x * a.x + (1.0f - a.x * a.x) * c;&#xA;    m[0][1] = a.x * a.y * (1.0f - c) + a.z * s;&#xA;    m[0][2] = a.x * a.z * (1.0f - c) - a.y * s;&#xA;    m[0][3] = 0.0f;&#xA;&#xA;    m[1][0] = a.x * a.y * (1.0f - c) - a.z * s;&#xA;    m[1][1] = a.y * a.y + (1.0f - a.y * a.y) * c;&#xA;    m[1][2] = a.y * a.z * (1.0f - c) + a.x * s;&#xA;    m[1][3] = 0.0f;&#xA;&#xA;    m[2][0] = a.x * a.z * (1.0f - c) + a.y * s;&#xA;    m[2][1] = a.y * a.z * (1.0f - c) - a.x * s;&#xA;    m[2][2] = a.z * a.z + (1.0f - a.z * a.z) * c;&#xA;    m[2][3] = 0.0f;&#xA;&#xA;    m[3][0] = 0.0f;&#xA;    m[3][1] = 0.0f;&#xA;    m[3][2] = 0.0f;&#xA;    m[3][3] = 1.0f;&#xA;&#xA;    return Mat44(&amp;amp;m[0][0]);&#xA;}&#xA;&#xA;&#xA;inline Mat44 RotationMatrix(Quat q)&#xA;{&#xA;    Matrix33 rotation(q);&#xA;&#xA;    Matrix44 m;&#xA;    m.SetAxis(0, rotation.cols[0]);&#xA;    m.SetAxis(1, rotation.cols[1]);&#xA;    m.SetAxis(2, rotation.cols[2]);&#xA;    m.SetTranslation(Point3(0.0f));&#xA;&#xA;    return m;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here's how I apply the Euler rotation vector:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;obj-&amp;gt;Transform(RotationMatrix(op.rotate.x, Vec3(1.0f, 0.0f, 0.0f)));&#xA;obj-&amp;gt;Transform(RotationMatrix(op.rotate.y, Vec3(0.0f, 1.0f, 0.0f)));&#xA;obj-&amp;gt;Transform(RotationMatrix(op.rotate.z, Vec3(0.0f, 0.0f, 1.0f)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I think this should be how &lt;code&gt;Transform()&lt;/code&gt; is defined:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Mesh::Transform(const Matrix44&amp;amp; m)&#xA;{&#xA;    for (uint32_t i=0; i &amp;lt; m_positions.size(); ++i)&#xA;    {&#xA;        m_positions[i] = m*m_positions[i];&#xA;        m_normals[i] = m*m_normals[i];&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2018-11-07T11:46:44.210" LastActivityDate="2018-11-09T01:55:10.900" Title="How to rotate a shape in another 3D software so that the rotation matches with the rotation in Blender?" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;geometry&gt;&lt;physics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8228" PostTypeId="2" ParentId="8225" CreationDate="2018-11-06T14:43:46.397" Score="0" Body="&lt;p&gt;Use the depth texture you mentioned, comparing it to the fragment's current depth to apply an alpha factor to your color. Remember to enable blending on the host. You can also upload the color texture and apply a more controlled blending on the shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shader code involved would look like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;out vec4 finalColor;&#xA;&#xA;...&#xA;&#xA;in vec2 screenUV;&#xA;&#xA;...&#xA;&#xA;uniform sampler2D depthTexture;&#xA;&#xA;...&#xA;&#xA;void main()&#xA;{&#xA;    float texDepth = texture(depthTexture, screenUV).r;&#xA;    float alpha = texDepth &amp;lt; gl_FragDepth? 0.5 : 1.0;&#xA;&#xA;    ...&#xA;&#xA;    finalColor = vec4(..., alpha);&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8394" LastActivityDate="2018-11-06T14:43:46.397" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8229" PostTypeId="2" ParentId="8195" CreationDate="2018-11-06T16:40:43.313" Score="1" Body="&lt;p&gt;I had to change the order of inputs to &lt;code&gt;def euler_to_quaternion&lt;/code&gt; as follow and have to convert the inputs to radians:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def euler_to_quaternion(roll, pitch, yaw):&#xA;&#xA;        qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)&#xA;        qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)&#xA;        qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)&#xA;        qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)&#xA;&#xA;        return [qx, qy, qz, qw]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also, quaternion_to_euler was returning degrees and I had to change it to radians:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def quaternion_to_euler(x, y, z, w):&#xA;&#xA;    t0 = +2.0 * (w * x + y * z)&#xA;    t1 = +1.0 - 2.0 * (x * x + y * y)&#xA;    roll = math.atan2(t0, t1)&#xA;    t2 = +2.0 * (w * y - z * x)&#xA;    t2 = +1.0 if t2 &amp;gt; +1.0 else t2&#xA;    t2 = -1.0 if t2 &amp;lt; -1.0 else t2&#xA;    pitch = math.asin(t2)&#xA;    t3 = +2.0 * (w * z + x * y)&#xA;    t4 = +1.0 - 2.0 * (y * y + z * z)&#xA;    yaw = math.atan2(t3, t4)&#xA;    return [yaw, pitch, roll]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9581" LastActivityDate="2018-11-06T16:40:43.313" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8231" PostTypeId="1" CreationDate="2018-11-07T04:52:08.323" Score="0" ViewCount="184" Body="&lt;p&gt;I have a modern OpenGL project hosted publicly.  I want to create the easiest experience so someone can just clone the repo and have it just work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far, I have included (as git submodules) the window creation library GLFW and the image loading library which is header only.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only other part I have to handle is the OpenGL function loading part.  During development I have been using the webservice offered by &lt;a href=&quot;https://github.com/Dav1dde/glad&quot; rel=&quot;nofollow noreferrer&quot;&gt;glad&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The two files I need from GLAD are roughly ~10k lines each.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other than asking a user to downloading these files  and place them in the correct folder themselves, is there any way to get around including these files directly in my project?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any other drawbacks to included the function loading code directly in my project?&lt;/p&gt;&#xA;" OwnerUserId="7000" LastEditorUserId="7000" LastEditDate="2018-11-07T05:43:01.827" LastActivityDate="2018-11-07T15:43:31.950" Title="How to include OpenGL extension loader in my project" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8232" PostTypeId="2" ParentId="8231" CreationDate="2018-11-07T15:43:31.950" Score="1" Body="&lt;p&gt;GLAD is &lt;em&gt;designed&lt;/em&gt; around you simply including it directly in your project. That's the point of it; it is easy to use because you don't have to deal with any external dependencies. No messy libraries or DLLs to generate. It's just another source/header file in your build process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, your code will (presumably) be written to expect GLAD generation with a specific OpenGL version and set of extensions. If you require the user to use GLAD to generate the file, you also have to tell them what version+extensions to use, or else your code won't compile. If you just ship the GLAD-generated files with your program, there's no chance of breakage (or at least, you could detect the breakage because your own build doesn't work anymore).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-11-07T15:43:31.950" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8233" PostTypeId="1" AcceptedAnswerId="8235" CreationDate="2018-11-07T21:13:01.410" Score="2" ViewCount="242" Body="&lt;p&gt;I have to load a mesh in Blender (which uses &lt;code&gt;Z&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; as &lt;em&gt;up&lt;/em&gt; and &lt;em&gt;forward&lt;/em&gt; axes), modify it and export it (with setting &lt;em&gt;up&lt;/em&gt; and &lt;em&gt;forward&lt;/em&gt; axes to &lt;code&gt;Y&lt;/code&gt; and &lt;code&gt;-Z&lt;/code&gt;) and import it into another software which uses a coordinate system with &lt;code&gt;Y&lt;/code&gt; up and &lt;code&gt;-Z&lt;/code&gt; forward. Later on I export the mesh from this software and import it in Blender for rendering. Since I wanted to get the same rotation in the other software that I get in Blender, I changed the rotation matrix of the other software from Identity to the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[1.0, 0.0, 0.0;&#xA;0.0, 0.0, -1.0;&#xA;0.0, 1.0, 0.0]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now I get the same exact rotation in that software that I get in Blender when using Euler angles. However, I have to actually use Quaternions and I realized that Quaternions do not have a rotation matrix. I wonder, what is the equivalent version of rotation matrix for Quaternions? Also, how can I change that equivalent-rotation-matrix of Quaternions so that I get the same rotation that I get in Blender?&lt;/p&gt;&#xA;" OwnerUserId="9581" LastActivityDate="2018-11-08T00:40:51.257" Title="What is the equivalent of rotation matrix in Euler angle space for Quaternions?" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8234" PostTypeId="1" AcceptedAnswerId="8236" CreationDate="2018-11-07T23:41:10.797" Score="5" ViewCount="391" Body="&lt;p&gt;I have a server and my only monitor is plugged into its graphics card.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is - do all programs (Windows explorer, Excel whatever) draw their output using the graphics card and more specifically an API such as OpenGL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output is coming from the graphics card so I do not see how it could not be but it seems like that would require anyone who is using a server to have a GPU to any visual output.&lt;/p&gt;&#xA;" OwnerUserId="7000" LastActivityDate="2018-11-08T03:35:16.917" Title="Do operating programs such as Microsoft Office or Windows Explorer use OpenGL to draw?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8235" PostTypeId="2" ParentId="8233" CreationDate="2018-11-08T00:40:51.257" Score="2" Body="&lt;p&gt;It's not true to say quaternions don't have a rotation matrix. They are both ways of completely describing a rotation in 3D, so they are freely convertible. Each quaternion corresponds to exactly one rotation matrix, and each rotation matrix corresponds to one quaternion and its negative. Quaternions are just more compact and easier to interpolate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To work out the rotation matrix for a quaternion, you need to take the effect of the quaternion, &lt;span class=&quot;math-container&quot;&gt;$q = (w, x, y, z) = (w, \textbf{v}) $&lt;/span&gt; on some point &lt;span class=&quot;math-container&quot;&gt;$\textbf{p}$&lt;/span&gt;, that is, &lt;span class=&quot;math-container&quot;&gt;$(w, \textbf{v}) * (0, \textbf{p}) * (w, \textbf{-v}) $&lt;/span&gt;, and express this formula as a matrix operating on &lt;span class=&quot;math-container&quot;&gt;$\textbf{p}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Multiplying out using the rules of quaternions gives us &lt;span class=&quot;math-container&quot;&gt;$(w^2 - \textbf{v.v})\textbf{p} + 2( w\textbf{v}\times \textbf{p} + \textbf{(v.p)v})  $&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can be rearranged into 3 matrix terms - the first part is just a constant value down the diagonal, the second part with the cross product has values everywhere &lt;em&gt;except&lt;/em&gt; the diagonal, and the third one is simply &lt;span class=&quot;math-container&quot;&gt;$\textbf{v}_m *  \textbf{v}_n $&lt;/span&gt; for rows m and columns n.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Adding these 3 matrices together gives you &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix} 1-2(y^2+z^2) &amp;amp;2(xy-zw) &amp;amp; 2(xz+yw)\\2(xy + zw)&amp;amp;1-2(x^2+z^2) &amp;amp; 2(yz-xw)\\2(xz-yw) &amp;amp; 2(yz + xw) &amp;amp; 1 - 2(x^2+y^2)\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is the conversion you need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your particular use case, though, you are just doing a simple rotate-x through 90 degrees, which simplifies things a lot. Remember a quaternion is &lt;span class=&quot;math-container&quot;&gt;$ ( cos(\theta/ 2) , sin(\theta/ 2)\textbf{a})$&lt;/span&gt;   where &lt;span class=&quot;math-container&quot;&gt;$\textbf{a}$&lt;/span&gt;  is your normalized axis of rotation. So the quaternion representing ±90 degrees rotation around x will be &lt;span class=&quot;math-container&quot;&gt;$( \frac{1}{\sqrt{2}},±\frac{1}{\sqrt{2}},0,0)$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="1937" LastActivityDate="2018-11-08T00:40:51.257" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8236" PostTypeId="2" ParentId="8234" CreationDate="2018-11-08T03:35:16.917" Score="6" Body="&lt;p&gt;In general, no. Most applications, unless they are games, or 3D applications like CAD or animation software, will use OS APIs to do their drawing. On Windows, this can be things like &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-gdi-start&quot; rel=&quot;noreferrer&quot;&gt;GDI or GDI+&lt;/a&gt;. On macOS you would usually use CoreGraphics or one of its derivatives. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;At a lower level than the application level, the operating system talks to the graphics driver to tell  it to draw things on the screen. They may do so using OpenGL or a proprietary API that's not usually exposed directly to applications. (For example on older macOS versions, the Window Server used OpenGL directly to do its compositing. I believe it uses Metal now.) Additionally, some drawing may not be done by the graphics card at all, but the results may be sent to the graphics card for display. For example, the original Windows GDI did its drawing using the CPU, as hardware accelerated graphics were not included on every machine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So really, there are a variety of ways for applications to do their drawing. They rarely use OpenGL, DirectX, etc. directly unless they have heavy graphics requirements. However, under the hood, the OS may be using those technologies or something similar, or something even lower-level.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-11-08T03:35:16.917" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8237" PostTypeId="1" AcceptedAnswerId="8238" CreationDate="2018-11-08T11:26:06.593" Score="0" ViewCount="40" Body="&lt;p&gt;Assume a color X with alpha 1 and RGB 255,230,210.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can i find another color with alpha A ( or an array of colors ) that blended with a background of color Y ( e.g 255,255,255 ) would produce the original color  ?&lt;/p&gt;&#xA;" OwnerUserId="9655" LastEditorUserId="9655" LastEditDate="2018-11-08T11:34:43.327" LastActivityDate="2018-11-08T12:48:49.557" Title="Converting color to equivalent with opacity" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8238" PostTypeId="2" ParentId="8237" CreationDate="2018-11-08T12:48:49.557" Score="1" Body="&lt;p&gt;This depends on what function you're blending with. Since you don't say where you're doing this, I'll just take OpenGL as an example.&lt;/p&gt;&#xA;&lt;p&gt;As you can see in the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBlendFunc.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;API&lt;/a&gt;, there are several ways of blending two colours (or rather how to interpret these two colours for a given blend function).&lt;/p&gt;&#xA;&lt;p&gt;You speak of a colour and a background colour, so let's say your result is &lt;span class=&quot;math-container&quot;&gt;$c_r$&lt;/span&gt;, your object in the foreground has colour &lt;span class=&quot;math-container&quot;&gt;$c_s$&lt;/span&gt; (for Source, the new colour value being &amp;quot;added&amp;quot; someway) and your background has colour &lt;span class=&quot;math-container&quot;&gt;$c_d$&lt;/span&gt; (for Destination, the old colour value that has been in the buffer already).&lt;/p&gt;&#xA;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$c_s = \left(\begin{array}{c} R_s\\G_s\\B_s\\A_s \end{array}\right)$&lt;/span&gt; (and analogously for &lt;span class=&quot;math-container&quot;&gt;$c_r$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$c_d$&lt;/span&gt;).&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;To determine the blended RGBA values of a pixel, the system uses the following equations:&#xA;&lt;span class=&quot;math-container&quot;&gt;$R_d = min(k_{R'}, R_s s_R + R_d d_R) \ G_d = min(k_{G'}, G_s S_G + G_d d_G) \ B_d = min(k_{B'}, B_s s_B + B_d d_B) A_d = min(k_{A'}, A_s s_A + A_d d_A)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;A bit confusing with the doubled &lt;span class=&quot;math-container&quot;&gt;$R_d$&lt;/span&gt; and so forth, so I'll rewrite it to the denomination I defined earlier:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$R_r = min(k_{R'}, R_s s_R + R_d d_R) \ G_r = min(k_{G'}, G_s S_G + G_d d_G) \ B_r = min(k_{B'}, B_s s_B + B_d d_B) A_r = min(k_{A'}, A_s s_A + A_d d_A)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The min function is there for not going above a certain constant (and &lt;span class=&quot;math-container&quot;&gt;$k_{R'},\ k_{G'},\ k_{B'},\ k_{A'}$&lt;/span&gt; are simply constants). For our purposes, let's just assume that we don't surpass this threshold, so we end up with&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$R_r = R_s s_R + R_d d_R$&lt;/span&gt; (and of course the same for the other channels).&lt;/p&gt;&#xA;&lt;p&gt;The rest of the components &lt;span class=&quot;math-container&quot;&gt;$s_R$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$d_R$&lt;/span&gt; which are some scaling factors for combining the two colours.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Transparency is best implemented using blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This helps, because now we know what the factors &lt;span class=&quot;math-container&quot;&gt;$s_R$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$d_R$&lt;/span&gt; actually are: the alpha values of the &lt;strong&gt;Source&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This leaves us with&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$R_r = R_s A_s + (1 - R_d A_d)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Therefore, to come back to your example, we have (for the green channel, since that is not &lt;span class=&quot;math-container&quot;&gt;$255$&lt;/span&gt;):&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$G_r = 230$&lt;/span&gt;, an undefined &lt;span class=&quot;math-container&quot;&gt;$\alpha$&lt;/span&gt; value for the source, the background green &lt;span class=&quot;math-container&quot;&gt;$G_d = 255$&lt;/span&gt; and probably a solid background, meaning &lt;span class=&quot;math-container&quot;&gt;$A_d = 255$&lt;/span&gt;. We need the values to be in &lt;span class=&quot;math-container&quot;&gt;$\left[0, 1\right]$&lt;/span&gt;, therefore we get &lt;span class=&quot;math-container&quot;&gt;$G_r = \frac{230}{255} = 0.90196078431$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$G_d = 1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$A_d = 1$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Filling this in we get:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$0.90196078431 = G_s A_s + (1 - 1 \cdot A_s)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Your question lets me believe, that you know &lt;span class=&quot;math-container&quot;&gt;$A_s$&lt;/span&gt;, thus only &lt;span class=&quot;math-container&quot;&gt;$G_s$&lt;/span&gt; (and of course the same for the other colour channels) is missing. This can then be calculated by isolating the respective colour component.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-11-08T12:48:49.557" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8239" PostTypeId="1" CreationDate="2018-11-08T14:11:14.990" Score="0" ViewCount="65" Body="&lt;p&gt;I am currently experiencing a very obvious artifact that occurs when looking at objects on very grazing angles&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a picture of the artifact:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZNQL3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZNQL3.png&quot; alt=&quot;artifact&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I noticed that the issue was coming from my implementation of Cook-Torrance's Specular BRDF. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the equation for the Cook-Torrance Specular BRDF: &#xA;&lt;a href=&quot;https://imgur.com/a/f6da9ZG&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://imgur.com/a/f6da9ZG&quot; alt=&quot;Cook-Torrance Specular BRDF&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More specifically, calculating the denominator is causing the issue:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float denominator = 4 * max(dot(viewDir, normal), 0.0) * max(dot(lightDir, normal), 0.0) + 0.001;  // Prevents any division by zero&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When I change the calculation of dot(viewDir, normal) to dot(halfway, normal), the artifact disappears:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float denominator = 4 * max(dot(halfway, normal), 0.0) * max(dot(lightDir, normal), 0.0) + 0.001;  // Prevents any division by zero&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But this equation is no longer correct. I was wondering if anyone knows why my implementation causes these artifacts?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to see my fragment shader you can find the code here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Ershany/Arcane-Engine/blob/WIP_PBR/Arcane%20Engine%20Core/src/shaders/pbr_model.frag&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Ershany/Arcane-Engine/blob/WIP_PBR/Arcane%20Engine%20Core/src/shaders/pbr_model.frag&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="8893" LastActivityDate="2018-11-08T14:11:14.990" Title="Cook-Torrance Specular BRDF Artifact" Tags="&lt;brdf&gt;&lt;specular&gt;" AnswerCount="0" CommentCount="2" ClosedDate="2018-11-08T21:18:47.393" ContentLicense="CC BY-SA 4.0" />
  <row Id="8240" PostTypeId="1" CreationDate="2018-11-08T12:08:22.940" Score="0" ViewCount="161" Body="&lt;p&gt;My book says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;After a scene has been constructed we transfer object descriptions to the viewing-coordinate reference frame. This conversion of object descriptions is equivalent to a sequence of transformations that superimposes the viewing reference frame onto the world frame, so we translate  the  view reference frame onto the origin and  rotate by an angle to align the view to the world.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So, my confusion is: if we're transferring object descriptions from the world to view, shouldn't we superimpose the world onto the view,   and hence take the inverse  of  the above transformation? Why is my book saying things the other way around?&lt;/p&gt;&#xA;" OwnerUserId="9661" OwnerDisplayName="mathmaniage" LastEditorUserId="5778" LastEditDate="2018-12-05T09:00:06.087" LastActivityDate="2018-12-05T09:00:06.087" Title="3D scene construction and change of coordinates" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8242" PostTypeId="1" CreationDate="2018-11-08T22:57:07.020" Score="3" ViewCount="228" Body="&lt;p&gt;Line strips and triangle strips are drawing modes supported across 3D graphics APIs, such as OpenGL, Direct3D, and Vulkan. When using indices to control drawing, a more recent feature is &quot;strip cutting&quot;, also called &quot;primitive restart&quot;, whereby a special index value can be inserted to indicate that the current strip has finished, and any following indices are part of a new strip.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On OpenGL, you can enable strip cutting by calling &lt;code&gt;glEnable(GL_PRIMITIVE_RESTART)&lt;/code&gt; and disable it by calling &lt;code&gt;glDisable(GL_PRIMITIVE_RESTART)&lt;/code&gt;. In Vulkan, you control this feature by setting the &lt;code&gt;primitiveRestartEnable&lt;/code&gt; boolean field of the &lt;code&gt;VkPipelineInputAssemblyStateCreateInfo&lt;/code&gt; structure. In Direct3D 12 you can use the &lt;code&gt;IBStripCutValue&lt;/code&gt; member of the &lt;code&gt;D3D12_GRAPHICS_PIPELINE_STATE_DESC&lt;/code&gt; structure to enable or disable strip cutting. Under Direct3D 11, this feature is on by default.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, under Direct3D 11, can you turn this feature off in any way? &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3d11/d3d10-graphics-programming-guide-primitive-topologies#generating-multiple-strips&quot; rel=&quot;nofollow noreferrer&quot;&gt;The documentation&lt;/a&gt; on this is very brief, and indicates no way to disable it. Is there some magic setting lurking in the API somewhere that I've missed?&lt;/p&gt;&#xA;" OwnerUserId="9659" LastActivityDate="2018-11-08T22:57:07.020" Title="Can you disable strip cutting (AKA primitive restart) on Direct3D 11?" Tags="&lt;directx11&gt;&lt;line-drawing&gt;&lt;direct3d&gt;&lt;drawing&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8243" PostTypeId="2" ParentId="8226" CreationDate="2018-11-09T01:55:10.900" Score="1" Body="&lt;p&gt;I just had to make the following changes to [manually] change the coordinate system of FleX to the one that Blender uses:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;obj-&amp;gt;Transform(RotationMatrix(op.rotate.x, Vec3(1.0f, 0.0f, 0.0f)));&#xA;obj-&amp;gt;Transform(RotationMatrix(op.rotate.y, Vec3(0.0f, 0.0f, -1.0f)))&#xA;obj-&amp;gt;Transform(RotationMatrix(op.rotate.z, Vec3(0.0f, 1.0f, 0.0f)));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The way I figured this was I generated three rotation vectors &lt;code&gt;[90, 0, 0]&lt;/code&gt;, &lt;code&gt;[0, 90, 0]&lt;/code&gt; and &lt;code&gt;[0, 0, 90]&lt;/code&gt; and rotated the shapes in FleX. Then I loaded the shapes in Blender and empirically figured rotation on which axis in Blender matches to the shape imported from FleX. I learned that when I rotate the shape on the &lt;code&gt;Y&lt;/code&gt;axis by 90 degrees in Blender, it matches the 90-degree rotation on the &lt;code&gt;Z&lt;/code&gt; axis in FleX. Also, I learned that rotating the object by -90 degrees on the &lt;code&gt;Z&lt;/code&gt; axis in Blender matches with the 90-degree rotation on the &lt;code&gt;Y&lt;/code&gt; axis in FleX.&lt;/p&gt;&#xA;" OwnerUserId="9581" LastActivityDate="2018-11-09T01:55:10.900" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8246" PostTypeId="1" AcceptedAnswerId="8248" CreationDate="2018-11-09T22:22:32.290" Score="0" ViewCount="177" Body="&lt;p&gt;Is it possible to add vbos to vbos after their creation? For example (pseudo-code):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenVertexArrays(1, &amp;amp;_vao);&#xA;glBindVertexArray(_vao);&#xA;// do init stuff&#xA;glBindVertexArray(0);&#xA;&#xA;// Much much later in a galaxy far away&#xA;glBindVertexArray(_vao);&#xA;glGenBuffers(1, &amp;amp;_instance_vbo);&#xA;glBindBuffer(GL_ARRAY_BUFFER, _instance_vbo);&#xA;glBufferData(GL_ARRAY_BUFFER, sizeof(blee), blee, GL_STATIC_DRAW);&#xA;glEnableVertexAttribArray(_vpos_att);&#xA;glVertexAttribPointer(_vpos_att, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;&#xA;// Draw&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So far it hasn't really worked. Looking at the bound vbos to my vao (using &lt;code&gt;GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING&lt;/code&gt;) shows no buffers bound. Though that may be another problem altogether.&lt;/p&gt;&#xA;" OwnerUserId="5978" LastActivityDate="2019-04-09T01:02:20.573" Title="Adding vbos to a vao once it has been created" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8247" PostTypeId="1" AcceptedAnswerId="9629" CreationDate="2018-11-10T00:11:38.013" Score="1" ViewCount="1467" Body="&lt;p&gt;I'm trying to write code (in any language) to render this 3D grid, matching the look and colors as closely as possible:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4vTSd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4vTSd.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9668" LastActivityDate="2020-03-05T09:59:46.053" Title="How can I draw this style of grid?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;3d&gt;&lt;color&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8248" PostTypeId="2" ParentId="8246" CreationDate="2018-11-10T00:37:34.167" Score="0" Body="&lt;p&gt;So after debugging some more, I've found that yes it is possible. You cam add buffers later on but they will need to point to their own attributes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My issues came from thinking I could have multiple vbos contributing to a single attribute. That doesn't work. You need multiple vaos for that scenario.&lt;/p&gt;&#xA;" OwnerUserId="5978" LastActivityDate="2018-11-10T00:37:34.167" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8249" PostTypeId="1" AcceptedAnswerId="8250" CreationDate="2018-11-10T03:45:15.613" Score="1" ViewCount="132" Body="&lt;p&gt;Attached is page 34 of &quot;Advanced Global Illumination&quot;, 2nd edition, by Dutre et al. I don't understand how (2.22) is derived from (2.21) and the given incident radiance distribution &lt;span class=&quot;math-container&quot;&gt;$L(x\leftarrow\Psi)=L_{in}\delta(\Psi-\Theta)$&lt;/span&gt;. Could you please give me a detailed derivation? Thanks a lot!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bytVm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bytVm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4839" LastActivityDate="2018-11-10T12:36:01.930" Title="Ask for detailed derivation of a formula in &quot;Advanced Global Illumination&quot;" Tags="&lt;brdf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8250" PostTypeId="2" ParentId="8249" CreationDate="2018-11-10T12:05:06.943" Score="2" Body="&lt;p&gt;The only thing you really need to know in order to derive (2.22) from (2.21) is that the &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt;-distribution satisfies&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ \int \delta(x) f(x)\,\text{d}x = f(0). $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(The &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt;-distribution is not a function in the common sense, so the above integral is merely a useful notation and not to be read as e.g. a Lebesgue or Riemann integral.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, the notation that the authors use for the substitution of the incident radiance distribution is misleading. The &lt;span class=&quot;math-container&quot;&gt;$\Theta$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$L(x\leftarrow\Psi) = L_{in}\delta(\Psi-\Theta)$&lt;/span&gt; is completely unrelated to the integration variable &lt;span class=&quot;math-container&quot;&gt;$\omega_\Theta$&lt;/span&gt;, so I chose to denote it by &lt;span class=&quot;math-container&quot;&gt;$\tilde\Psi$&lt;/span&gt; instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the derivation of (2.22) from (2.21):&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Substitute &lt;span class=&quot;math-container&quot;&gt;$L(x\leftarrow\Psi) = L_{in}\delta(\Psi-\tilde\Psi)$&lt;/span&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\int_{\Omega_x} \int_{\Omega_x} f_r(x, \Psi \rightarrow \Theta) L_{in}\delta(\Psi-\tilde\Psi)\cos(N_x,\Theta)\cos(N_x,\Psi)\,\text{d}\omega_\Psi\,\text{d}\omega_\Theta}{\int_{\Omega_x}L_{in}\delta(\Psi-\tilde\Psi)\cos(N_x,\Psi)\,\text{d}\omega_\Psi}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Substitute &lt;span class=&quot;math-container&quot;&gt;$\Psi$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$\Psi+\tilde\Psi$&lt;/span&gt;:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\int_{\Omega_x} \int_{\Omega_x-\tilde\Psi} f_r(x, \Psi+\tilde\Psi \rightarrow \Theta) L_{in}\delta(\Psi)\cos(N_x,\Theta)\cos(N_x,\Psi+\tilde\Psi)\,\text{d}\omega_\Psi\,\text{d}\omega_\Theta}{\int_{\Omega_x-\tilde\Psi}L_{in}\delta(\Psi)\cos(N_x,\Psi+\tilde\Psi)\,\text{d}\omega_\Psi}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;Use the above property of the &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt;-distribution:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\int_{\Omega_x} f_r(x, \tilde\Psi \rightarrow \Theta) L_{in}\cos(N_x,\Theta)\cos(N_x,\tilde\Psi)\,\text{d}\omega_\Theta}{L_{in}\cos(N_x,\tilde\Psi)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;4&quot;&gt;&#xA;&lt;li&gt;Simplify:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_{\Omega_x} f_r(x, \tilde\Psi \rightarrow \Theta) \cos(N_x,\Theta)\,\text{d}\omega_\Theta$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you only need to notice that we want equation (2.21) to be true for all such &quot;test functions&quot; &lt;span class=&quot;math-container&quot;&gt;$L_{in}\delta(\Psi-\tilde\Psi)$&lt;/span&gt; for the incident radiance, i.e. for all possible values of &lt;span class=&quot;math-container&quot;&gt;$\tilde\Psi$&lt;/span&gt;. &lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastEditorDisplayName="user9485" LastEditDate="2018-11-10T12:36:01.930" LastActivityDate="2018-11-10T12:36:01.930" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8251" PostTypeId="1" CreationDate="2018-11-10T21:04:05.953" Score="3" ViewCount="609" Body="&lt;p&gt;I'm building a software renderer but I think there might be some problem with my ray-triangle intersection accuracy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I implemented the algorithm referring to &lt;code&gt;pbrt-v3&lt;/code&gt; without some components which I think have little influence on the intersection test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the code perform intersection test:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Triangle::intersectP(const Ray &amp;amp;r, Point3f p0, Point3f p1, Point3f p2) const {&#xA;    // translate&#xA;    Point3f p0_ = p0 - r._o;&#xA;    Point3f p1_ = p1 - r._o;&#xA;    Point3f p2_ = p2 - r._o;&#xA;&#xA;    // permute, to make sure z-dimension is not zero&#xA;    // permutation is just like to circular move right/left until z is largest dimemsion.&#xA;    int kz = r._d.maxDim();&#xA;    int kx = kz+1; if (kx == 3) kx = 0;&#xA;    int ky = kx+1; if (ky == 3) ky = 0;&#xA;&#xA;    // swap coord&#xA;    Vec3f d_ = r._d.permute(kx, ky, kz);&#xA;    p0_ = p0_.permute(kx, ky, kz);&#xA;    p1_ = p1_.permute(kx, ky, kz);&#xA;    p2_ = p2_.permute(kx, ky, kz);&#xA;    // shear&#xA;    float Sx = -d_.x()/d_.z();&#xA;    float Sy = -d_.y()/d_.z();&#xA;    float Sz = 1.0f/d_.z();&#xA;&#xA;    // perform transform (p.z doesn't matter now)&#xA;    p0_[0] += Sx*p0_[2];&#xA;    p0_[1] += Sy*p0_[2];&#xA;    p1_[0] += Sx*p1_[2];&#xA;    p1_[1] += Sy*p1_[2];&#xA;    p2_[0] += Sx*p2_[2];&#xA;    p2_[1] += Sy*p2_[2];&#xA;&#xA;    // signed edge function to judge whether origin's projection in projected triangle&#xA;    float e0 = p1_.x()*p2_.y() - p2_.x()*p1_.y();   // p1 -&amp;gt; p2&#xA;    float e1 = p2_.x()*p0_.y() - p0_.x()*p2_.y();   // p2 -&amp;gt; p0&#xA;    float e2 = p0_.x()*p1_.y() - p1_.x()*p0_.y();   // p0 -&amp;gt; p1&#xA;&#xA;    // perform high-precision at edges&#xA;    if (e0 == 0.0f || e1 == 0.0f || e2 == 0.0f) {&#xA;        double p0xp1y = (double)p0_.x() * (double)p1_.y();&#xA;        double p1xp0y = (double)p1_.x() * (double)p0_.y();&#xA;        e2 = (float)(p0xp1y - p1xp0y);&#xA;        double p1xp2y = (double)p1_.x() * (double)p2_.y();&#xA;        double p2xp1y = (double)p2_.x() * (double)p1_.y();&#xA;        e0 = (float)(p1xp2y - p2xp1y);&#xA;        double p2xp0y = (double)p2_.x() * (double)p0_.y();&#xA;        double p0xp2y = (double)p0_.x() * p2_.y();&#xA;        e1 = (float)(p2xp0y - p0xp2y);&#xA;    }&#xA;&#xA;    // edge detection&#xA;    if ( (e0 &amp;lt; 0 || e1 &amp;lt; 0 ||  e2 &amp;lt; 0) &amp;amp;&amp;amp; (e0 &amp;gt; 0 || e2 &amp;gt; 0 || e1 &amp;gt; 0) )&#xA;        return false;&#xA;&#xA;    float det = e0 + e1 + e2;&#xA;    if (det == 0)   // on edge&#xA;        return false;&#xA;&#xA;    // compute z value (i.e. t)&#xA;    p0_[2] *= Sz;&#xA;    p1_[2] *= Sz;&#xA;    p2_[2] *= Sz;&#xA;&#xA;    float tScaled = e0*p0_.z() + e1*p1_.z() + e2*p2_.z();&#xA;    if (det &amp;lt; 0 &amp;amp;&amp;amp; (tScaled &amp;gt;= 0 || tScaled &amp;lt; r._tmax*det) ) return false;&#xA;    else if (det &amp;gt; 0 &amp;amp;&amp;amp; (tScaled &amp;lt;= 0 || tScaled &amp;gt; r._tmax*det) ) return false;&#xA;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Unlike pbrt, my implement use right-hand coordinate and row-major matrices, but I think this do not influence the correctness of this piece of code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the time, this function works fine. However, artifacts appears when I do occlusion test to the light sources, where &lt;code&gt;r._tmax&lt;/code&gt; has a specific value (the distance between intersection point and light sample point).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tested the algorithm with a plane and a point light above it, however just use the position of the light, radiance is not computed, and this is why I think the problem is caused by intersection implementation.&#xA;If unoccluded, a value is returned as radiance, otherwise zero.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vec3f PointEmitter::evalDirect(std::shared_ptr&amp;lt;Scene&amp;gt; scene, const IntersectInfo &amp;amp;isect_info, const Point2f &amp;amp;u) const {&#xA;    Vec3f wi;&#xA;    float light_pdf;&#xA;    VisibilityTester vt;&#xA;    Vec3f Li_sampled = sample_Li(isect_info, wi, light_pdf, vt, u);&#xA;    Vec3f f = isect_info._bsdf-&amp;gt;f(isect_info._wo, wi)*std::abs(isect_info._shading._n.dot(wi));&#xA;&#xA;    return (scene-&amp;gt;intersectP(IntersectInfo(_p).spawnRayTo(isect_info))) *100;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dFLQd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dFLQd.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And another open box-like polygon, with same light:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/8EziQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8EziQ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;There's a circle-like region obviously stands out on the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I consider this comes from the float point error when comparing &lt;code&gt;r_tmax&lt;/code&gt; and the distance. But the code already uses double-precision. Can anyone help?&lt;/p&gt;&#xA;" OwnerUserId="7334" LastActivityDate="2018-11-10T21:04:05.953" Title="ray-triangle intersection precision - c++" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;geometry&gt;&lt;ray&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8252" PostTypeId="2" ParentId="8095" CreationDate="2018-11-11T07:22:41.867" Score="1" Body="&lt;p&gt;Ad 1) Yes, if both monitors have the same resolution but different screen sizes, this means the pixels of the larger monitor are bigger. It could also mean the space between the pixels is different. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ad 2) No, the physical size of a monitor makes no difference for the GPU. It only cares about the resolution, for example 1920x1080 vs 3840x2160. The latter has 4 times the number of pixels, so it requires 4x the amount of memory and a simple operation like &lt;code&gt;glClear&lt;/code&gt; might take 4 times longer to complete. More complex operations might even be slower than that, due to their implementation details.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regarding lag: I believe the time it takes to send the color information for each pixel is determined by a hardware standard and should be the same for each monitor. However, the monitor's chipset, which consumes that signal, may be faster or slower than a monitor of a different make or model. Same goes for the panel technology (e.g. TN, IPS, etc.), which might have a different refresh rate. But the hardware specifics have no effect on the GPU with one important exception: &lt;em&gt;vertical sync&lt;/em&gt;. If vertical sync is enabled, your GPU will wait for a signal from your display before it starts sending the latest color frame. This &lt;strong&gt;will&lt;/strong&gt; introduce latency, which can be pretty severe. There are solutions to that, but that's outside the scope of this answer. I recommend you to watch &lt;a href=&quot;https://youtu.be/seyAzw9zEoY&quot; rel=&quot;nofollow noreferrer&quot;&gt;this video&lt;/a&gt; about it.&lt;/p&gt;&#xA;" OwnerUserId="4943" LastActivityDate="2018-11-11T07:22:41.867" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8254" PostTypeId="1" AcceptedAnswerId="8265" CreationDate="2018-11-12T02:31:59.727" Score="0" ViewCount="1978" Body="&lt;p&gt;In one text,  the  derivation for  perspective  projection  goes like  this:   &lt;a href=&quot;https://i.stack.imgur.com/ZHCE0.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZHCE0.jpg&quot; alt=&quot;image1&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$x',y',z'$&lt;/span&gt; represent any point along  the  projection line,and &lt;span class=&quot;math-container&quot;&gt;$x_{prp},y_{prp},z_{prp}$&lt;/span&gt; are the projection reference point, then:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$x'=x-(x-x_{prp})u$$&lt;/span&gt;&lt;br&gt;&#xA; &lt;span class=&quot;math-container&quot;&gt;$$y'=y-(y-y_{prp})u$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$z'=z-(z-z_{prp})u$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$0\le u \le 1$&lt;/span&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now,   finding the value of u from the third equation above and  replacing in the first and  second  equations,   we get at  &lt;span class=&quot;math-container&quot;&gt;$z_vp$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ x_p=x'= x.\frac{z_{vp}-z_{prp}}{z-z_prp}+x_{prp}.\frac{z-z_{vp}}{z-z_{prp}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ y_p=y'= y.\frac{z_{vp}-z_{prp}}{z-z_prp}+y_{prp}.\frac{z-z_{vp}}{z-z_{prp}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and there is no projection transformation matrix  given.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the second text,  the  derivation is using  similar triangles:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SakPQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SakPQ.jpg&quot; alt=&quot;image2&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;comparing the  similar triangles  we  get:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$x_p=\frac{-x_c}{\frac{z_c}{d}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$y_p=\frac{y_c}{\frac{z_c}{d}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and  the projection transformation for  homogeneous coordinates x,y,z is  given by:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{bmatrix}&#xA;-1&amp;amp;&amp;amp;0&amp;amp;&amp;amp;0&amp;amp;&amp;amp;0\\&#xA;0&amp;amp;&amp;amp;1&amp;amp;&amp;amp;0&amp;amp;&amp;amp;0\\&#xA;0&amp;amp;&amp;amp;0&amp;amp;&amp;amp;1&amp;amp;&amp;amp;0\\&#xA;0&amp;amp;&amp;amp;0&amp;amp;&amp;amp;\frac{1}{d}&amp;amp;&amp;amp;0&#xA;\end{bmatrix}&#xA;$$&lt;/span&gt;    &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;so,  my questions are:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;How do I find the projection matrix of coordinates as found from &#xA;derivation 1?&lt;/li&gt;&#xA;&lt;li&gt;Both are given in the perspective projection area of&#xA;these different texts,  are both transformations the  same? If not, &#xA;how  are  they different?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9661" LastActivityDate="2018-11-14T16:40:37.993" Title="perspective projection transformation matrix" Tags="&lt;projections&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8255" PostTypeId="1" AcceptedAnswerId="8261" CreationDate="2018-11-12T05:41:57.470" Score="0" ViewCount="1454" Body="&lt;p&gt;I found the derivation for two point and three point perspective &lt;a href=&quot;https://people.eecs.berkeley.edu/~barsky/perspective.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here on this site&lt;/a&gt;,  even though it says review on one point perspective,  it  doesn't give a link to previous pages, but I'd like to know how the matrix for one  point perspective was derived. If possible please give me a detailed derivation for this projection matrix.&lt;/p&gt;&#xA;" OwnerUserId="9661" LastActivityDate="2018-11-15T03:23:45.957" Title="finding the projection matrix for one point perspective" Tags="&lt;projections&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8257" PostTypeId="2" ParentId="8240" CreationDate="2018-11-12T11:06:11.270" Score="2" Body="&lt;p&gt;I assume the term &lt;em&gt;object description&lt;/em&gt; refers to the set of 3D vertices a mesh is made of. And I also assume &lt;em&gt;reference frame&lt;/em&gt; actually means &lt;em&gt;coordinate space&lt;/em&gt;. For a book on computer graphics, it sure uses some very uncommon words. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In computer graphics, we often have to transform a set of vertices from one coordinate space to another. For example, an artist may have modelled a rubber ducky, aligned in such a way that it looks down the positive x-axis and it uses centimeters for its units. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When we place the ducky in our world (let's say it uses &lt;em&gt;meters&lt;/em&gt; as the primary unit), we scale, rotate and translate it so that it neatly floats on the water in a bath tub.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then we have our camera, which can move freely around in our scene with its own translation and rotation parameters. And finally there is the notion of &lt;em&gt;projection&lt;/em&gt;, which takes into account the field of view and the aspect ratio of our frame to project the 3D point onto a 2D image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Our job is to calculate exactly where in our 2D image the 3D vertex ends up, if at all. And for this, we will have to go through the sequence of all our coordinate spaces: from object to world to camera (a.k.a. view) to projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So that's how most graphics programmers visualise this process and hence why the book also follows this sequence: it takes the object and follows it through its transformations until it ends up in our 2D image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems you prefer it the other way around: you take the camera as a fixed object and rotate the world around it. But you have to admit this isn't very logical, as the camera sure isn't fixed and the world does not revolve around it.&lt;/p&gt;&#xA;" OwnerUserId="4943" LastActivityDate="2018-11-12T11:06:11.270" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8258" PostTypeId="1" CreationDate="2018-11-12T14:41:25.110" Score="2" ViewCount="52" Body="&lt;p&gt;I recently learnt about the binary representation of Pascal's triangle. Here is what it looks like&lt;a href=&quot;https://i.stack.imgur.com/j2D4J.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j2D4J.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;I am a java learner. Is there a way for me to find the java source code to graph this binary representation?&lt;/p&gt;&#xA;" OwnerUserId="9678" LastActivityDate="2018-11-12T14:41:25.110" Title="Binary representation of Pascal's triangle" Tags="&lt;javascript&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ClosedDate="2018-11-14T12:45:52.340" ContentLicense="CC BY-SA 4.0" />
  <row Id="8259" PostTypeId="1" CreationDate="2018-11-12T20:40:40.417" Score="4" ViewCount="362" Body="&lt;p&gt;I'm testing my path tracer for specular surfaces. Images rendered with my own code have very noisy appearance, and I think they look like variance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use point light and the bunny is of mirror material, walls are matte. If it is the problem with sampling, how should I modify the program. To my understanding, point lights are specially handled and thus the sampling results should be a constant value. So I don't think the noise is caused by light sampling. So could there be any bugs?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When only matte material exists in the scene, there are also variance, but not that bad, and global illumination effects are visible. So what could the problem?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;specular bunny:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PLlZu.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PLlZu.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;matte bunny:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LH2Ei.jpg&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LH2Ei.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the specular bunny image, spp is 4. Since it is a point light, wi is directly set to the vector between point light and intersection point when calculating direct illumination, so there is actually no &quot;sampling&quot;. When computing scattering directions, BRDF is matte when intersecting the wall, and BRDF is specular reflection when the ray hit the bunny.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Matte BRDF is cosine weighted sampled, while specular reflection just use the perfect reflection direction.&lt;/p&gt;&#xA;" OwnerUserId="7334" LastEditorUserId="7334" LastEditDate="2018-11-13T00:26:12.687" LastActivityDate="2018-11-15T03:42:40.713" Title="High variance in path tracing specular objects" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8260" PostTypeId="1" CreationDate="2018-11-13T13:00:28.957" Score="3" ViewCount="401" Body="&lt;p&gt;I'm trying to re-implement Blenders (&lt;a href=&quot;https://github.com/libmv/libmv&quot; rel=&quot;nofollow noreferrer&quot;&gt;libmv&lt;/a&gt;) &lt;a href=&quot;https://github.com/sobotka/blender/blob/master/intern/libmv/libmv/simple_pipeline/distortion_models.h#L66&quot; rel=&quot;nofollow noreferrer&quot;&gt;polynomial lens distortion model&lt;/a&gt; using &lt;a href=&quot;https://www.shadertoy.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;shadertoy&lt;/a&gt;, in order to apply the lens distortion in another application ideally by generating a STMap for that. I think I'm close, but when passing the same values &lt;code&gt;k1=0.1 k2=0.0 k3=0.0&lt;/code&gt; the resulting distortion is still too heavy in comparison to the distorted image out of Blender.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Based on: &#xA;// https://www.shadertoy.com/view/lslGRN&#xA;// https://www.shadertoy.com/view/XdfGzH&#xA;&#xA;vec3 color = vec3(0.4,0.4,0.4);&#xA;float lens = 24.0; &#xA;&#xA;//note: period of 2, [-1;1]=/\ &#xA;float sawtooth( float t ) &#xA;{&#xA;    return abs(mod(abs(t), 2.0)-1.0);&#xA;}&#xA;&#xA;vec2 BarrelDistort(vec2 p)&#xA;{&#xA;    float theta  = atan(p.y, p.x);&#xA;    float radius = length(p);&#xA;    radius = pow(radius, 1.2);&#xA;    p.x = radius * cos(theta);&#xA;    p.y = radius * sin(theta);&#xA;    return (1.0 * (p));&#xA;}   &#xA;&#xA;vec2 BlenderDistort(vec2 p)&#xA;{&#xA;    // https://en.wikipedia.org/wiki/Distortion_(optics)&#xA;    // https://github.com/sobotka/blender/blob/master/intern/libmv/libmv/simple_pipeline/distortion_models.h#L66&#xA;    float x = p.x;&#xA;    float y = p.y;&#xA;&#xA;    float k1 = .1/2.0;&#xA;    float k2 = .0;&#xA;    float k3 = .0;&#xA;&#xA;    float p1 = .0;&#xA;    float p2 = .0;&#xA;&#xA;    float r2 = x*x + y*y;&#xA;    float r4 = r2 * r2;&#xA;    float r6 = r4 * r2;&#xA;    //float r_coeff = (T(1) + k1*r2 + k2*r4 + k3*r6);&#xA;    float r_coeff = (1.0 + k1*r2 + k2*r4 + k3*r6);&#xA;    //float xd = x * r_coeff + T(2)*p1*x*y + p2*(r2 + T(2)*x*x);&#xA;    float xd = x * r_coeff + 2.0*p1*x*y + p2*(r2 + 2.0*x*x);&#xA;    float yd = y * r_coeff + 2.0*p2*x*y + p1*(r2 + 2.0*y*y);&#xA;&#xA;    return vec2(xd, yd);&#xA;}&#xA;&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;    vec2 uv = fragCoord.xy / iResolution.xy;    &#xA;    vec2 normalizedUV = (fragCoord.xy/(iResolution.xy/2.0))-1.0;&#xA;&#xA;    vec2 dist = BlenderDistort(normalizedUV);   &#xA;    vec2 uv_transform = vec2(.5)+vec2(.5)*dist;&#xA;&#xA;    vec3 outcol = vec3(0.0);&#xA;    //outcol += texture( iChannel0, vec2(0,1)+vec2(1,-1)*uv ).rgb;&#xA;    outcol += texture( iChannel0, uv_transform ).rgb;&#xA;&#xA;&#xA;    // Draw Lines&#xA;    vec2 div = 30.0 * vec2(1.0, iResolution.y / iResolution.x );&#xA;    float lines = 0.0;&#xA;    lines += smoothstep( 0.2, 0.0, sawtooth( dist.x*2.0*div.x ) );&#xA;    lines += smoothstep( 0.2, 0.0, sawtooth( dist.y*2.0*div.y ) );&#xA;    lines = clamp( lines, 0.0, 1.0 );&#xA;&#xA;    //outcol *= vec3(1.0-lines); //black&#xA;    //outcol += vec3(lines); //white&#xA;&#xA;    //note: force black outside valid range &#xA;    vec2 valid = step( vec2(-1.0), dist ) * step( dist, vec2(1.0) );&#xA;    outcol *= valid.x*valid.y;&#xA;&#xA;    fragColor = vec4( outcol,1.0 );&#xA;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/s2evX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/s2evX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Test image undistorted&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hPh8I.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hPh8I.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;em&gt;Test image distorted in Blender k1=0.1 k2=0.0 k3=0.0&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Q:&lt;/strong&gt; What I'm missing in order to match Blender's polynomial lens distortion model?&lt;/p&gt;&#xA;" OwnerUserId="9684" LastEditorUserId="9684" LastEditDate="2018-11-13T16:07:32.140" LastActivityDate="2021-04-28T07:07:05.650" Title="How to match Blenders polynomial lens distortion model with GLSL?" Tags="&lt;shader&gt;&lt;mathematics&gt;&lt;fragment-shader&gt;&lt;camera&gt;&lt;distortion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8261" PostTypeId="2" ParentId="8255" CreationDate="2018-11-13T21:26:08.210" Score="0" Body="&lt;p&gt;When reading on transformation matrices over a range of distinct source material, there are some main concepts that you must understand, which are as follows.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Column vs Row Notation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Some authors write vectors as a single row matrix (1x3), while others write them as a single column matrix (3x1). The latter seems to be the preferred representation in most modern books on computer graphics. The main difference between the two notations is that when using the former, matrices will be multiplied on the right side of the vector, and when using the latter they will be multiplied on the left. When dealing with linear transformations, such as rotation matrices, in a particular notation, they are represented as the transposed matrix in the other notation. For instance, the rotation of point &lt;span class=&quot;math-container&quot;&gt;$p=(1, 1)$&lt;/span&gt; for an angle &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; in the plane is shown below. As you can easily see, &lt;span class=&quot;math-container&quot;&gt;$Row(x)^T = Column(x)$&lt;/span&gt;, i.e., one notation is the transpose of the other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;Row(p) =&amp;amp; &#xA;\begin{bmatrix}&#xA;1 &amp;amp; 1&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;\cos(\theta) &amp;amp; sin(\theta)\\&#xA;\text{-}sin(\theta) &amp;amp; \cos(\theta)&#xA;\end{bmatrix}\\&#xA;Column(p) =&amp;amp; &#xA;\begin{bmatrix}&#xA;\cos(\theta) &amp;amp; \text{-}\sin(\theta)\\&#xA;\sin(\theta) &amp;amp; \cos(\theta)&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;1 \\ 1&#xA;\end{bmatrix}&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://people.eecs.berkeley.edu/~barsky/perspective.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;website you linked&lt;/a&gt; uses &lt;strong&gt;row&lt;/strong&gt; notation. This is important because if you read about the perspective matrix in other sources, you may see the result written as the transpose matrix if the author used column notation.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Basis Orientation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://people.eecs.berkeley.edu/~barsky/perspective.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;In the website&lt;/a&gt;, the camera basis vectors &lt;span class=&quot;math-container&quot;&gt;$X_1$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$Y_1$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$Z_1$&lt;/span&gt; form a left-handed coordinate system, because &lt;span class=&quot;math-container&quot;&gt;$X_1 \times Y_1 = - Z_1$&lt;/span&gt;. This is important as well, as you may notice some sign changes in the perspective matrix if the system was right-handed. You can read more about handedness in &lt;a href=&quot;https://en.wikipedia.org/wiki/Orientation_%28vector_space%29&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;. As with row notation, this is another arbitrary decision that the author has taken.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Perspective Projection&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Given the appropriate basis, and a projection plane at a distance d from the origin, perspective projection is a simple exercise in similar triangles, as shown below.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Eh4rc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Eh4rc.jpg&quot; alt=&quot;Perspective Projection Diagram)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The point &lt;span class=&quot;math-container&quot;&gt;$\mathbf{P} = (x,y,z)$&lt;/span&gt; when projected onto the plane gives another point &lt;span class=&quot;math-container&quot;&gt;$\mathbf{p} = (x_p, y_p, z_p)$&lt;/span&gt; that can be written as (in row notation) &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\mathbf{p} = \begin{bmatrix}&#xA; d \displaystyle \frac{x}{z} &amp;amp; d \displaystyle \frac{y}{z} &amp;amp; d&#xA;\end{bmatrix}.$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we just need to put this formula into matrix form (again, in row notation).&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Homogeneous/Projective Coordinates&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;If we just use the raw 3D coordinates of &lt;span class=&quot;math-container&quot;&gt;$\bf P$&lt;/span&gt; there is no way to represent the formula for &lt;span class=&quot;math-container&quot;&gt;$\bf p$&lt;/span&gt; as a matrix multiplication. The use of &lt;a href=&quot;https://en.wikipedia.org/wiki/Homogeneous_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;homogeneous coordinates&lt;/a&gt; allows us exactly to do that. We start by augmenting &lt;span class=&quot;math-container&quot;&gt;$\bf P$&lt;/span&gt; onto the fourth dimension, by defining it as &lt;span class=&quot;math-container&quot;&gt;$\mathbf{P} = (x, y, z, 1)$&lt;/span&gt;, and we use 4x4 homogeneous matrices instead of 3x3 matrices to represent transformations. I strongly urge you to read on &lt;a href=&quot;https://en.wikipedia.org/wiki/Projective_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;projective spaces&lt;/a&gt;, as otherwise the following explanation will look like too much hand-waving as I am not going to dwell on mathematical formalities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, in this new space every point with coordinates &lt;span class=&quot;math-container&quot;&gt;$(wx,wy,wz,w)$&lt;/span&gt; can be mapped onto the point &lt;span class=&quot;math-container&quot;&gt;$(x,y,z,1)$&lt;/span&gt; by a simple division by w. We can use this property in our advantage to fill-out a matrix in such a way that after the division by w is made, we get exactly the perspective projection formula for our point.     &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{bmatrix}&#xA;x &amp;amp; y &amp;amp; z &amp;amp; \displaystyle\frac{z}{d}&#xA;\end{bmatrix}&#xA;= &#xA;\begin{bmatrix}&#xA;x &amp;amp; y &amp;amp; z &amp;amp; 1&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\&#xA;0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0\\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; \displaystyle \frac{1}{d}\\&#xA;0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0&#xA;\end{bmatrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if we take the point &lt;span class=&quot;math-container&quot;&gt;$(x, y, z, \frac{z}{d})$&lt;/span&gt; and we divide it by its last coordinate, we get &lt;span class=&quot;math-container&quot;&gt;$(d\displaystyle\frac{x}{z}, d\displaystyle\frac{y}{z}, d, 1)$&lt;/span&gt;, which are exactly the coordinates of our projected point if we just ignore the augmentation onto fourth dimensional space that we did (i.e., discard the last coordinate).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the &quot;perspective matrix&quot; does not actually do any perspective transformation, it just &quot;prepares&quot; the transformation by coding a specific value in the last coordinate, such that after all coordinates are divided by it, we get the true projection.&lt;/p&gt;&#xA;" OwnerUserId="4768" LastEditorUserId="4768" LastEditDate="2018-11-15T03:23:45.957" LastActivityDate="2018-11-15T03:23:45.957" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8262" PostTypeId="1" CreationDate="2018-11-14T02:20:22.877" Score="1" ViewCount="412" Body="&lt;p&gt;Consider this figure for projection.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qmXdM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qmXdM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;There are two equations that give value for the xp and yp coordinates:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$x_p=x.\frac{(z_{vp}-z_{prp})}{h}+ x_{prp}.\frac{(z-z_{vp})}{h}$&lt;/span&gt; and&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$y_p=y.\frac{(z_{vp}-z_{prp})}{h}+ y_{prp}.\frac{(z-z_{vp})}{h}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;and then it explains in a paragraph: &quot;Setting up matrix elements for obtaining the homogeneous-coordinate &lt;span class=&quot;math-container&quot;&gt;$x_h$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y_h$&lt;/span&gt; values in the given equations is straightforward, but we must also structure the matrix to preserve depth (z-value) information. Otherwise, the z coordinates are distorted by the homogeneous-division parameter h. We can do this by setting up the matrix elements for the z transformation so as to normalize the perspective-projection &lt;span class=&quot;math-container&quot;&gt;$z_p$&lt;/span&gt; coordinates. There are various ways that we could choose the matrix elements to produce the homogeneous coordinates  and the normalized &lt;span class=&quot;math-container&quot;&gt;$z_p$&lt;/span&gt; value for spatial position (x, y, z).&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I have some questions regarding this:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What does it mean to preserve depth(z-values)?&lt;/li&gt;&#xA;&lt;li&gt;What does it mean to normalize the perspective-projection zp coordinates?&lt;/li&gt;&#xA;&lt;li&gt;How to perform this normalization?&lt;/li&gt;&#xA;&lt;li&gt;How does this normalization preserve z-values?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9661" LastActivityDate="2018-11-16T06:43:08.937" Title="preserving z-values during projection?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8265" PostTypeId="2" ParentId="8254" CreationDate="2018-11-14T16:40:37.993" Score="0" Body="&lt;p&gt;Given your equations (which i just assume are correct):&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;x_p &amp;amp;= x \frac{z_{vp}-z_{prp}}{z-z_{prp}}+x_{prp} \frac{z-z_{vp}}{z-z_{prp}}\\&#xA;y_p &amp;amp;= y \frac{z_{vp}-z_{prp}}{z-z_{prp}}+y_{prp} \frac{z-z_{vp}}{z-z_{prp}}&#xA;\end{align},&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;if we take &lt;span class=&quot;math-container&quot;&gt;$(x_{prp}, y_{prp}, z_{prp}) = (0, 0, 0)$&lt;/span&gt;, then we have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;x_p &amp;amp;= x\frac{z_{vp}}{z}\\&#xA;y_p &amp;amp;= y\frac{z_{vp}}{z}&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming the projection plane is at distance &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; from the origin, and, by your drawing, that the projection plane is on the negative side of the Z axis, we have &lt;span class=&quot;math-container&quot;&gt;$z_{vp} = -d$&lt;/span&gt;, which leads to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;x_p &amp;amp;= - x\frac{d}{z}\\&#xA;y_p &amp;amp;= - y\frac{d}{z}&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we can follow the same reasoning (homogeneous coordinates) as &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8255/finding-the-projection-matrix-for-one-point-perspective&quot;&gt;in my answer to your other question&lt;/a&gt; (using column notation) to write&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\begin{bmatrix}&#xA;x\\y\\z\\ \frac{-z}{d}&#xA;\end{bmatrix}&#xA;=&#xA;\begin{bmatrix}&#xA;1&amp;amp;0&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;1&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;1&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;\frac{-1}{d}&amp;amp;0&#xA;\end{bmatrix}&#xA;\begin{bmatrix}&#xA;x\\y\\z\\1&#xA;\end{bmatrix}&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which after the division by the last coordinate will give the projected point. Notice that because we are writing it in column notation, the perspective matrix is the transpose of the matrix in your &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8255/finding-the-projection-matrix-for-one-point-perspective&quot;&gt;other question&lt;/a&gt;. Also, the negative sign is because the camera reference frame is a right-handed one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the second textbook that you are reading, I cannot understand why you would have a negative sign only in the x axis without knowing more about the camera reference frame. By the diagram you posted, there should not be a negative sign.&lt;/p&gt;&#xA;" OwnerUserId="4768" LastActivityDate="2018-11-14T16:40:37.993" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8266" PostTypeId="2" ParentId="4632" CreationDate="2018-11-14T17:58:25.930" Score="2" Body="&lt;p&gt;Suballocating from a larger buffer is absolutely the way to go, with caveats. I'm coming more from a DirectX/Vulkan side of things, but this should apply equally to OpenGL (I just won't have direct API calls here in this answer). The things to consider are the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Do you need to index into the larger buffer, or are you OK with binding the resource to the offset each time?&lt;/li&gt;&#xA;&lt;li&gt;Have you taken care of any/all alignment restrictions for your uniforms that are packed together (256 byte alignment is common)?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Newer graphics APIs have a &quot;dynamic offset&quot; you can specify with the draw command which is a pretty fast way to indirectly access a subregion of a buffer. However, assuming you are triple-buffering data that's mutable, there should be little to no contention in the driver for binding the data (just some fixed overhead).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In summary, yes, allocating larger regions of memory/buffers and subleasing those regions is considered best practice. This applies even to objects with different shaders (if your allocator can handle it).&lt;/p&gt;&#xA;" OwnerUserId="87" LastActivityDate="2018-11-14T17:58:25.930" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8267" PostTypeId="1" CreationDate="2018-11-14T20:07:59.903" Score="4" ViewCount="441" Body="&lt;p&gt;I have a bunch of points that are the control vertices of a cubic catmull-rom spline. I would like to convert these to the control vertices of a cubic bspline.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe I can do this using this following relation:&#xA;&lt;span class=&quot;math-container&quot;&gt;$\boldsymbol{t} * \boldsymbol{B}_{\text{catmull}} * \boldsymbol{V}_{\text{catmull}} = \boldsymbol{t} * \boldsymbol{B}_{\text{bspline}} * \boldsymbol{V}_{\text{bspline}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$\boldsymbol{B}$&lt;/span&gt; is the basis matrix and &lt;span class=&quot;math-container&quot;&gt;$\boldsymbol{V}$&lt;/span&gt; is a vector of the control vertices. To get the control vertices of the bspline, the formula just becomes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\boldsymbol{V}_{\text{bspline}} = \boldsymbol{B}^{-1}_{\text{bspline}} * \boldsymbol{B}_{\text{catmull}} * \boldsymbol{V}_{\text{catmull}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is once I process say 4 control vertices of the catmull rom spline, to get 4 vertices of the bspline, how do I process other vertices (i.e the order). If a catmull-rom spline has n-vertices with cubic segments, then we have at the most &lt;span class=&quot;math-container&quot;&gt;$n-3$&lt;/span&gt; segments. So if we have say 5 vertices, &lt;span class=&quot;math-container&quot;&gt;$v_0, v_1, v_2, v_3$&lt;/span&gt; gives us 4 vertices for bspline. How would I go about computing the other curve segment in the bspline?&lt;/p&gt;&#xA;" OwnerUserId="1940" LastActivityDate="2020-12-03T09:05:43.413" Title="Conversion from cubic catmull-rom spline to cubic b-spline" Tags="&lt;curve&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8268" PostTypeId="2" ParentId="8259" CreationDate="2018-11-15T03:42:40.713" Score="5" Body="&lt;p&gt;If your bunny is purely specular, then sampling the light directly at the shade point would give no contribution since the specular BSDF is a delta BSDF. It generally evaluates to zero for any direction other than the mirror direction. If it was a glossy BSDF, then it might be possible that the pdf value could be very small so that the monte-carlo estimator &lt;span class=&quot;math-container&quot;&gt;$\frac{f(X)}{P(X)}$&lt;/span&gt; just explodes (which is generally the source of fireflies i.e having a very small pdf and the function is large).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it was a mirror direction, then you should just see a black bunny for direct illumination and just the reflection of the surrounding scene for multiple bounces. Multiple bounces from the specular bunny should not be cause fireflies, because if you're sampling based on cosine term at the matte surface, the estimator becomes &lt;span class=&quot;math-container&quot;&gt;$\frac{L_i(X)f_r(X)\cos(\theta_i)}{\text{pdf}(\theta_i)}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\theta_i$&lt;/span&gt; is the sampled direction using BSDF sampling at the matte surface. The pdf and the &lt;span class=&quot;math-container&quot;&gt;$\cos(\theta_i)$&lt;/span&gt; should cancel out each other perfectly. However since you're using a point light, you can never sample from the BSDF since the light is a delta light and needs an explicit connection. Hence the pdf for the estimator would be 1 all the time. The only way for large values to creep up are in the numerator. So I would suggest you to check the values by increasing bounce one by one to see when the problems start creeping in.&lt;/p&gt;&#xA;" OwnerUserId="1940" LastActivityDate="2018-11-15T03:42:40.713" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8269" PostTypeId="1" AcceptedAnswerId="8280" CreationDate="2018-11-15T05:49:46.203" Score="2" ViewCount="116" Body="&lt;p&gt;I am trying to implement the Loop-Blinn cubic curve in java using the following source codes &lt;a href=&quot;https://github.com/azer89/GPU-Curve-Rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;GPU-Curve-Rendering&lt;/a&gt; and &lt;a href=&quot;https://opensource.apple.com/source/WebCore/WebCore-1298.39/platform/graphics/gpu/&quot; rel=&quot;nofollow noreferrer&quot;&gt;WebCore&lt;/a&gt;. Both of them are showing few arteffects and i cannot figure out why. Here are my source code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public class CubicBezier {&#xA;public enum CurveType {&#xA;    UNKNOWN, SERPENTINE, LOOP, CUSP, QUADRATIC, LINE&#xA;};&#xA;&#xA;private FloatArray klm;&#xA;public boolean drawAdditionalTri;&#xA;public Array&amp;lt;Vertex&amp;gt; tris;&#xA;public Array&amp;lt;Vertex&amp;gt; plainTris;&#xA;public final float M_EPS = .00001f;&#xA;&#xA;public Vector2 start;&#xA;public Vector2 ctrl1;&#xA;public Vector2 ctrl2;&#xA;public Vector2 end;&#xA;&#xA;boolean once = true;&#xA;&#xA;public CubicBezier(Vector2 start, Vector2 ctrl1, Vector2 ctrl2, Vector2 end) {&#xA;    this.start = start;&#xA;    this.ctrl1 = ctrl1;&#xA;    this.ctrl2 = ctrl2;&#xA;    this.end = end;&#xA;    drawAdditionalTri = false;&#xA;    tris = new Array&amp;lt;Vertex&amp;gt;();&#xA;    plainTris = new Array&amp;lt;Vertex&amp;gt;();&#xA;&#xA;    compute(start.x, start.y, ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y, -1);&#xA;}&#xA;&#xA;public void compute() {&#xA;    tris.clear();&#xA;    plainTris.clear();&#xA;    drawAdditionalTri = false;&#xA;    compute(start.x, start.y, ctrl1.x, ctrl1.y, ctrl2.x, ctrl2.y, end.x, end.y, -1);&#xA;}&#xA;&#xA;boolean flipSerpent = false;&#xA;public void compute(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3,&#xA;        int recursiveType) {&#xA;    Float fd1 = new Float();&#xA;    Float fd2 = new Float();&#xA;    Float fd3 = new Float();&#xA;    CurveType curve_type = determineType(fd1, fd2, fd3);&#xA;    float d1 = fd1.value, d2 = fd2.value, d3 = fd3.value;&#xA;    System.out.println(curve_type);&#xA;    plainTris.clear();&#xA;&#xA;    float OneThird = 1.0f / 3.0f;&#xA;    float TwoThirds = 2.0f / 3.0f;&#xA;&#xA;    float t1;&#xA;    float ls;&#xA;    float lt;&#xA;    float ms;&#xA;    float mt;&#xA;&#xA;    float ltMinusLs;&#xA;    float mtMinusMs;&#xA;    float lsMinusLt;&#xA;    float ql;&#xA;    float qm;&#xA;&#xA;    // bool flip&#xA;    boolean flip = false;&#xA;&#xA;    // artifact on loop&#xA;    int errorLoop = -1;&#xA;    float splitParam = 0;&#xA;&#xA;    klm = new FloatArray(12);&#xA;    for (int i = 0; i &amp;lt; 12; i++) {&#xA;        klm.add(0);&#xA;    }&#xA;&#xA;    switch (curve_type) {&#xA;    case UNKNOWN:&#xA;        break;&#xA;    case SERPENTINE:&#xA;        t1 = (float) Math.sqrt(9.0f * d2 * d2 - 12 * d1 * d3);&#xA;        ls = 3.0f * d2 - t1;&#xA;        lt = 6.0f * d1;&#xA;        ms = 3.0f * d2 + t1;&#xA;        mt = lt;&#xA;        ltMinusLs = lt - ls;&#xA;        mtMinusMs = mt - ms;&#xA;&#xA;        klm.set(0, ls * ms);&#xA;        klm.set(1, ls * ls * ls);&#xA;        klm.set(2, ms * ms * ms);&#xA;&#xA;        klm.set(3, OneThird * (3.0f * ls * ms - ls * mt - lt * ms));&#xA;        klm.set(4, ls * ls * (ls - lt));&#xA;        klm.set(5, ms * ms * (ms - mt));&#xA;&#xA;        klm.set(6, OneThird * (lt * (mt - 2.0f * ms) + ls * (3.0f * ms - 2.0f * mt)));&#xA;        klm.set(7, ltMinusLs * ltMinusLs * ls);&#xA;        klm.set(8, mtMinusMs * mtMinusMs * ms);&#xA;&#xA;        klm.set(9, ltMinusLs * mtMinusMs);&#xA;        klm.set(10, -(ltMinusLs * ltMinusLs * ltMinusLs));&#xA;        klm.set(11, -(mtMinusMs * mtMinusMs * mtMinusMs));&#xA;        System.out.println(&quot;d1 &quot; + d1);&#xA;        for (int i = 0; i &amp;lt; 12; i++) {&#xA;            System.out.println(i+&quot;: &quot;+klm.get(i));&#xA;        }&#xA;        if (d1 &amp;lt; 0.0f) {&#xA;            flip = true;&#xA;            flipSerpent = true;&#xA;        }&#xA;        break;&#xA;    case LOOP:&#xA;        t1 = (float) Math.sqrt(4.0f * d1 * d3 - 3.0f * d2 * d2);&#xA;        ls = d2 - t1;&#xA;        lt = 2.0f * d1;&#xA;        ms = d2 + t1;&#xA;        mt = lt;&#xA;&#xA;        // Figure out whether there is a rendering artifact requiring&#xA;        // the curve to be subdivided by the caller.&#xA;        ql = ls / lt;&#xA;        qm = ms / mt;&#xA;        if (0.0f &amp;lt; ql &amp;amp;&amp;amp; ql &amp;lt; 1.0f) {&#xA;            errorLoop = 1;&#xA;            splitParam = ql;&#xA;        }&#xA;&#xA;        if (0.0f &amp;lt; qm &amp;amp;&amp;amp; qm &amp;lt; 1.0f) {&#xA;            errorLoop = 2;&#xA;            splitParam = qm;&#xA;        }&#xA;&#xA;        ltMinusLs = lt - ls;&#xA;        mtMinusMs = mt - ms;&#xA;&#xA;        System.out.println(d1);&#xA;&#xA;        klm.set(0, ls * ms);&#xA;        klm.set(1, ls * ls * ms);&#xA;        klm.set(2, ls * ms * ms);&#xA;        klm.set(3, OneThird * (-ls * mt - lt * ms + 3.0f * ls * ms));&#xA;        klm.set(4, -OneThird * ls * (ls * (mt - 3.0f * ms) + 2.0f * lt * ms));&#xA;        klm.set(5, -OneThird * ms * (ls * (2.0f * mt - 3.0f * ms) + lt * ms));&#xA;        klm.set(6, OneThird * (lt * (mt - 2.0f * ms) + ls * (3.0f * ms - 2.0f * mt)));&#xA;        klm.set(7, OneThird * (lt - ls) * (ls * (2.0f * mt - 3.0f * ms) + lt * ms));&#xA;        klm.set(8, OneThird * (mt - ms) * (ls * (mt - 3.0f * ms) + 2.0f * lt * ms));&#xA;        klm.set(9, ltMinusLs * mtMinusMs);&#xA;        klm.set(10, -(ltMinusLs * ltMinusLs) * mtMinusMs);&#xA;        klm.set(11, -ltMinusLs * mtMinusMs * mtMinusMs);&#xA;&#xA;        if (recursiveType == -1)&#xA;            flip = ((d1 &amp;gt; 0.0f &amp;amp;&amp;amp; klm.get(0) &amp;lt; 0.0f) || (d1 &amp;lt; 0.0f &amp;amp;&amp;amp; klm.get(0) &amp;gt; 0.0f));&#xA;        break;&#xA;&#xA;    case CUSP:&#xA;        ls = d3;&#xA;        lt = 3.0f * d2;&#xA;        lsMinusLt = ls - lt;&#xA;        klm.set(0, ls);&#xA;        klm.set(1, ls * ls * ls);&#xA;        klm.set(2, 1.0f);&#xA;        klm.set(3, ls - OneThird * lt);&#xA;        klm.set(4, ls * ls * lsMinusLt);&#xA;        klm.set(5, 1.0f);&#xA;        klm.set(6, ls - TwoThirds * lt);&#xA;        klm.set(7, lsMinusLt * lsMinusLt * ls);&#xA;        klm.set(8, 1.0f);&#xA;        klm.set(9, lsMinusLt);&#xA;        klm.set(10, lsMinusLt * lsMinusLt * lsMinusLt);&#xA;        klm.set(11, 1.0f);&#xA;        break;&#xA;&#xA;    case QUADRATIC:&#xA;        klm.set(0, 0);&#xA;        klm.set(1, 0);&#xA;        klm.set(2, 0);&#xA;        klm.set(3, OneThird);&#xA;        klm.set(4, 0);&#xA;        klm.set(5, OneThird);&#xA;        klm.set(6, TwoThirds);&#xA;        klm.set(7, OneThird);&#xA;        klm.set(8, TwoThirds);&#xA;        klm.set(9, 1);&#xA;        klm.set(10, 1);&#xA;        klm.set(11, 1);&#xA;        if (d3 &amp;lt; 0)&#xA;            flip = true;&#xA;        break;&#xA;    case LINE:&#xA;        break;&#xA;    }&#xA;&#xA;    if (errorLoop != -1 &amp;amp;&amp;amp; recursiveType == -1) {&#xA;        System.out.println(&quot;error&quot;);&#xA;        float x01 = (x1 - x0) * splitParam + x0;&#xA;        float x12 = (x2 - x1) * splitParam + x1;&#xA;        float x23 = (x3 - x2) * splitParam + x2;&#xA;        float y01 = (y1 - y0) * splitParam + y0;&#xA;        float y12 = (y2 - y1) * splitParam + y1;&#xA;        float y23 = (y3 - y2) * splitParam + y2;&#xA;&#xA;        float x012 = (x12 - x01) * splitParam + x01;&#xA;        float x123 = (x23 - x12) * splitParam + x12;&#xA;        float y012 = (y12 - y01) * splitParam + y01;&#xA;        float y123 = (y23 - y12) * splitParam + y12;&#xA;&#xA;        float x0123 = (x123 - x012) * splitParam + x012;&#xA;        float y0123 = (y123 - y012) * splitParam + y012;&#xA;&#xA;        drawAdditionalTri = true;&#xA;        plainTris.add(new Vertex(x0, y0));&#xA;        plainTris.add(new Vertex(x0123, y0123));&#xA;        plainTris.add(new Vertex(x3, y3));&#xA;&#xA;        if (errorLoop == 1) // flip second&#xA;        {&#xA;            compute(start.x, start.y, x01, y01, x012, y012, x0123, y0123, 0);&#xA;            compute(x0123, y0123, x123, y123, x23, y23, end.x, end.y, 1);&#xA;        } else if (errorLoop == 2) // flip first&#xA;        {&#xA;            compute(start.x, start.y, x01, y01, x012, y012, x0123, y0123, 1);&#xA;            compute(x0123, y0123, x123, y123, x23, y23, end.x, end.y, 0);&#xA;        }&#xA;&#xA;        return;&#xA;    } else if (errorLoop == -1 &amp;amp;&amp;amp; recursiveType == -1) {&#xA;        drawAdditionalTri = false;&#xA;    }&#xA;&#xA;    if (recursiveType == 1)&#xA;        flip = !flip;&#xA;&#xA;    if (flip) {&#xA;        klm.set(0, -klm.get(0));&#xA;        klm.set(1, -klm.get(1));&#xA;        klm.set(3, -klm.get(3));&#xA;        klm.set(4, -klm.get(4));&#xA;        klm.set(6, -klm.get(6));&#xA;        klm.set(7, -klm.get(7));&#xA;        klm.set(9, -klm.get(9));&#xA;        klm.set(10, -klm.get(10));&#xA;    }&#xA;&#xA;    Triangulation(x0, y0, x1, y1, x2, y2, x3, y3, klm.toArray());&#xA;&#xA;}&#xA;&#xA;public CurveType determineType(Float fd1, Float fd2, Float fd3) {&#xA;    float d1 = 0, d2 = 0, d3 = 0;&#xA;    Vector3 b0 = new Vector3(start.x, start.y, 1f);&#xA;    Vector3 b1 = new Vector3(ctrl1.x, ctrl1.y, 1f);&#xA;    Vector3 b2 = new Vector3(ctrl2.x, ctrl2.y, 1f);&#xA;    Vector3 b3 = new Vector3(end.x, end.y, 1f);&#xA;&#xA;    float a1 = b0.dot(b3.cpy().crs(b2).cpy());&#xA;    float a2 = b1.dot(b0.cpy().crs(b3).cpy());&#xA;    float a3 = b2.dot(b1.cpy().crs(b0).cpy());&#xA;&#xA;    d1 = a1 - 2 * a2 + 3 * a3;&#xA;    d2 = -a2 + 3 * a3;&#xA;    d3 = 3 * a3;&#xA;&#xA;    Vector3 d = new Vector3(d1, d2, d3);&#xA;    d.nor();&#xA;    d1 = d.x;&#xA;    d2 = d.y;&#xA;    d3 = d.z;&#xA;    System.out.println(&quot;a1 &quot;+ d1);&#xA;    fd1.value = d1;&#xA;    fd2.value = d2;&#xA;    fd3.value = d3;&#xA;&#xA;    float D = 3.0f * d2 * d2 - 4.0f * d1 * d3;&#xA;    float disc = d1 * d1 * D;&#xA;&#xA;    if(disc == 0) {&#xA;        if (d1 == 0 &amp;amp;&amp;amp; d2 == 0) {&#xA;            if(d3 == 0)&#xA;                return CurveType.LINE;&#xA;        return CurveType.QUADRATIC;&#xA;        }&#xA;        if(d1 == 0)&#xA;            return CurveType.CUSP;&#xA;        if(D &amp;lt; 0)&#xA;            return CurveType.LOOP;&#xA;    }&#xA;    if (disc &amp;gt; 0)&#xA;        return CurveType.SERPENTINE;&#xA;&#xA;&#xA;    return CurveType.LOOP;&#xA;}&#xA;&#xA;public void Triangulation(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float[] klm) {&#xA;&#xA;    Vertex[] vertices = new Vertex[4];&#xA;    vertices[0] = new Vertex(x0, y0, klm[0], klm[1], klm[2]);&#xA;    vertices[1] = new Vertex(x1, y1, klm[3], klm[4], klm[5]);&#xA;    vertices[2] = new Vertex(x2, y2, klm[6], klm[7], klm[8]);&#xA;    vertices[3] = new Vertex(x3, y3, klm[9], klm[10], klm[11]);&#xA;&#xA;&#xA;    for (int i = 0; i &amp;lt; 4; ++i) {&#xA;        for (int j = i + 1; j &amp;lt; 4; ++j) {&#xA;            if (approxEqual(vertices[i].xy, vertices[j].xy)) {&#xA;                int indices[] = { 0, 0, 0 };&#xA;                int index = 0;&#xA;                for (int k = 0; k &amp;lt; 4; ++k)&#xA;                    if (k != j)&#xA;                        indices[index++] = k;&#xA;&#xA;                tris.add(vertices[indices[0]]);&#xA;                tris.add(vertices[indices[1]]);&#xA;                tris.add(vertices[indices[2]]);&#xA;&#xA;                return;&#xA;            }&#xA;        }&#xA;    }&#xA;&#xA;    for (int i = 0; i &amp;lt; 4; ++i) {&#xA;        int indices[] = { 0, 0, 0 };&#xA;        int index = 0;&#xA;        for (int j = 0; j &amp;lt; 4; ++j)&#xA;            if (i != j)&#xA;                indices[index++] = j;&#xA;&#xA;        if (pointInTriangle(vertices[i].xy, vertices[indices[0]].xy, vertices[indices[1]].xy,&#xA;                vertices[indices[2]].xy)) {&#xA;            tris.add(vertices[indices[0 % 3]].print());&#xA;            tris.add(vertices[indices[(0 + 1) % 3]].print());&#xA;            tris.add(vertices[i].print());&#xA;&#xA;            tris.add(vertices[indices[1 % 3]].print());&#xA;            tris.add(vertices[indices[(1 + 1) % 3]].print());&#xA;            tris.add(vertices[i].print());&#xA;&#xA;            tris.add(vertices[indices[2 % 3]].print());&#xA;            tris.add(vertices[indices[(2 + 1) % 3]].print());&#xA;            tris.add(vertices[i].print());&#xA;            System.out.println(&quot;insude triangle&quot;);&#xA;            return;&#xA;        }&#xA;    }&#xA;&#xA;    if (intersect(vertices[0].xy, vertices[2].xy, vertices[1].xy, vertices[3].xy)) {&#xA;        if ((vertices[2].xy.cpy().sub(vertices[0].xy)).len2() &amp;lt; (vertices[3].xy.cpy().sub(vertices[1].xy)).len2()) {&#xA;            tris.add(vertices[0]);&#xA;            tris.add(vertices[1]);&#xA;            tris.add(vertices[2]);&#xA;&#xA;            tris.add(vertices[0]);&#xA;            tris.add(vertices[2]);&#xA;            tris.add(vertices[3]);&#xA;        } else {&#xA;            tris.add(vertices[0]);&#xA;            tris.add(vertices[1]);&#xA;            tris.add(vertices[3]);&#xA;&#xA;            tris.add(vertices[1]);&#xA;            tris.add(vertices[2]);&#xA;            tris.add(vertices[3]);&#xA;        }&#xA;    }&#xA;&#xA;    else if (intersect(vertices[0].xy, vertices[3].xy, vertices[1].xy, vertices[2].xy)) {&#xA;        if ((vertices[3].xy.cpy().sub(vertices[0].xy)).len2() &amp;lt; (vertices[2].xy.cpy().sub(vertices[1].xy)).len2()) {&#xA;            tris.add(vertices[0].print());&#xA;            tris.add(vertices[1].print());&#xA;            tris.add(vertices[3].print());&#xA;&#xA;            System.out.println(&quot;true&quot;);&#xA;            tris.add(vertices[0].print());&#xA;            tris.add(vertices[3].print());&#xA;            tris.add(vertices[2].print());&#xA;        } else {&#xA;            tris.add(vertices[0].print());&#xA;            tris.add(vertices[1].print());&#xA;            tris.add(vertices[3].print());&#xA;&#xA;            tris.add(vertices[2].print());&#xA;            tris.add(vertices[0].print());&#xA;            tris.add(vertices[3].print());&#xA;        }&#xA;    } else {&#xA;        if ((vertices[1].xy.cpy().sub(vertices[0].xy)).len2() &amp;lt; (vertices[3].xy.cpy().sub(vertices[2].xy)).len2()) {&#xA;            tris.add(vertices[0]);&#xA;            tris.add(vertices[2]);&#xA;            tris.add(vertices[1]);&#xA;&#xA;            tris.add(vertices[0]);&#xA;            tris.add(vertices[1]);&#xA;            tris.add(vertices[3]);&#xA;        } else {&#xA;            tris.add(vertices[0]);&#xA;            tris.add(vertices[2]);&#xA;            tris.add(vertices[3]);&#xA;&#xA;            tris.add(vertices[3]);&#xA;            tris.add(vertices[2]);&#xA;            tris.add(vertices[1]);&#xA;        }&#xA;    }&#xA;&#xA;}&#xA;&#xA;public boolean approxEqual(Vector2 v0, Vector2 v1) {&#xA;    return (v0.cpy().sub(v1)).len2() &amp;lt; M_EPS * M_EPS;&#xA;}&#xA;&#xA;public boolean pointInTriangle(Vector2 point, Vector2 a, Vector2 b, Vector2 c) {&#xA;    float x0 = c.x - a.x;&#xA;    float y0 = c.y - a.y;&#xA;    float x1 = b.x - a.x;&#xA;    float y1 = b.y - a.y;&#xA;    float x2 = point.x - a.x;&#xA;    float y2 = point.y - a.y;&#xA;&#xA;    float dot00 = x0 * x0 + y0 * y0;&#xA;    float dot01 = x0 * x1 + y0 * y1;&#xA;    float dot02 = x0 * x2 + y0 * y2;&#xA;    float dot11 = x1 * x1 + y1 * y1;&#xA;    float dot12 = x1 * x2 + y1 * y2;&#xA;    float denominator = dot00 * dot11 - dot01 * dot01;&#xA;    if (denominator == 0)&#xA;        return false;&#xA;&#xA;    float inverseDenominator = 1.0f / denominator;&#xA;    float u = (dot11 * dot02 - dot01 * dot12) * inverseDenominator;&#xA;    float v = (dot00 * dot12 - dot01 * dot02) * inverseDenominator;&#xA;&#xA;    return (u &amp;gt; 0.0f) &amp;amp;&amp;amp; (v &amp;gt; 0.0f) &amp;amp;&amp;amp; (u + v &amp;lt; 1.0f);&#xA;}&#xA;&#xA;public int orientation(Vector2 p1, Vector2 p2, Vector2 p3) {&#xA;    float crossProduct = (p2.y - p1.y) * (p3.x - p2.x) - (p3.y - p2.y) * (p2.x - p1.x);&#xA;    return (crossProduct &amp;lt; 0.0f) ? -1 : ((crossProduct &amp;gt; 0.0f) ? 1 : 0);&#xA;}&#xA;&#xA;public boolean intersect(Vector2 p1, Vector2 q1, Vector2 p2, Vector2 q2) {&#xA;    return (orientation(p1, q1, p2) != orientation(p1, q1, q2)&#xA;            &amp;amp;&amp;amp; orientation(p2, q2, p1) != orientation(p2, q2, q1));&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;attribute vec3 a_position;&#xA;attribute vec3 a_texCoord;&#xA;uniform mat4 u_projTrans;&#xA;varying vec3 tex;&#xA;void main() {&#xA;    tex = a_texCoord;&#xA;    gl_Position =  u_projTrans * vec4(a_position.xy, 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform vec4 u_color;&#xA;varying vec3 tex;&#xA;&#xA;void main() {&#xA;    vec3 uv = tex;&#xA;    float val = pow(uv.x, 3) - uv.y * uv.z;&#xA;&#xA;    vec4 mycol = vec4(u_color.xyz, 1.0);&#xA;&#xA;    if(val &amp;lt; 0.0 )  mycol = vec4(1.0, 0.0, 0.0, 1.0);&#xA;    gl_FragColor = mycol;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;here are few screenshot of the problems:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CZLsp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CZLsp.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/iORNX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iORNX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They suppose to be like these&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4Ny1x.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Ny1x.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;This is an executable &lt;a href=&quot;https://drive.google.com/open?id=1_kBPPsNSs6L_NURDYLm9Rxs2lAr5SWlE&quot; rel=&quot;nofollow noreferrer&quot;&gt;jar file&lt;/a&gt; of the application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone tell me how to fix this issue? i'm pulling my hair for few weeks now.&lt;/p&gt;&#xA;" OwnerUserId="3024" LastEditorUserId="3024" LastEditDate="2018-11-15T21:39:13.600" LastActivityDate="2018-11-18T21:51:54.920" Title="LoopBlinn Cubic Curve Rendering - Serpentine arteffect" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;vector-graphics&gt;&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8270" PostTypeId="2" ParentId="8267" CreationDate="2018-11-15T09:04:10.937" Score="4" Body="&lt;p&gt;Quoting the comments above for context:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Just to confirm, are you asking, given a set of &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; CatRom control points,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\{CR_0, CR_1, CR_2, CR_3 ... CR_{n-1}\}$$&lt;/span&gt;&#xA;forming a piecewise curve, what is the equivalent &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; points, &lt;span class=&quot;math-container&quot;&gt;$$\{B_0,B_1,B_2...B_{n-1}\}$$&lt;/span&gt; for a matching piecewise uniform cubic bspline?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;em&gt;Exactly. That is what I'm looking for. I think conversion to cubic bezier's are easy. But I would like to know if this is even possible/doable with bsplines&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I think it's a bit complicated: Using the approach you described above, i.e. &lt;span class=&quot;math-container&quot;&gt;$$ V_{targetformat} = M_{targetformat}^{-1} . M_{sourceformat}.V_{sourceformat}$$&lt;/span&gt;&#xA;you can easily go from a sequence of &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; control points of Catmull-Rom to  &lt;span class=&quot;math-container&quot;&gt;$(n-3)$&lt;/span&gt; &lt;em&gt;sets&lt;/em&gt; of 4 Uniform BSpline control points, i.e. a &lt;em&gt;total&lt;/em&gt; of &lt;span class=&quot;math-container&quot;&gt;$4n-12$&lt;/span&gt; control points , but I can't see that this will allow you to stitch them together to obtain just &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; points...&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Assuming&lt;/em&gt; I've got the correct matrices for the 'typical' Catmull-Rom,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$M_{CR}=\frac{1}{2}\begin{bmatrix} &#xA;-1 &amp;amp; 3 &amp;amp; -3 &amp;amp; 1\\&#xA;2 &amp;amp; -5 &amp;amp; 4 &amp;amp; -1 \\&#xA;-1 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;0 &amp;amp; 2 &amp;amp; 0 &amp;amp; 0\\&#xA; \end{bmatrix}$$&lt;/span&gt;&#xA;and uniform B-Spline:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$M_{UB}=\frac{1}{6}\begin{bmatrix} &#xA;-1 &amp;amp; 3 &amp;amp; -3 &amp;amp; 1\\&#xA;3 &amp;amp; -6 &amp;amp; 3 &amp;amp; 0 \\&#xA;-3 &amp;amp; 0 &amp;amp; 3 &amp;amp; 0 \\&#xA;1 &amp;amp; 4 &amp;amp; 1 &amp;amp; 0\\&#xA; \end{bmatrix}$$&lt;/span&gt;&#xA;then &lt;span class=&quot;math-container&quot;&gt;$M^{-1}_{UB}.M_{CR}$&lt;/span&gt; should be &lt;br/&gt;&#xA;&lt;em&gt;[UPDATE: Fixed errors in coefficents]&lt;/em&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{1}{6}\begin{bmatrix} &#xA;7 &amp;amp; -4 &amp;amp; 5 &amp;amp; -2\\&#xA;-2 &amp;amp; 11 &amp;amp; -4 &amp;amp; 1 \\&#xA;1 &amp;amp; -4 &amp;amp; 11 &amp;amp; -2 \\&#xA;-4 &amp;amp; 13 &amp;amp; -26 &amp;amp; 11\\&#xA; \end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;It seems to me that, in any batch of four points, every output vertex thus depends on &lt;em&gt;every&lt;/em&gt; input vertex, so it seems the neighbouring points can't be shared.&lt;/p&gt;&#xA;&lt;p&gt;Having said this, I think perhaps there &lt;em&gt;might&lt;/em&gt; be a way of getting an &lt;em&gt;approximate&lt;/em&gt; solution (but I've not tried rendering it myself to check it so take with a grain of salt)&lt;/p&gt;&#xA;&lt;p&gt;We know that a Catmull-Rom spline defined by &lt;span class=&quot;math-container&quot;&gt;$(CR_A, CR_B, CR_C, CR_D)$&lt;/span&gt;, passes through &lt;span class=&quot;math-container&quot;&gt;$CR_B$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$CR_C$&lt;/span&gt; at t=0 and t=1 respectively.&lt;/p&gt;&#xA;&lt;p&gt;Similarly, using &lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}t^3 &amp;amp; t^2 &amp;amp; t &amp;amp; 1\end{bmatrix}.M_{UB}$&lt;/span&gt;, we should see that at t=0 and t=1, a B-spline passes through &lt;span class=&quot;math-container&quot;&gt;$\frac{B_A + 4 B_B + B_C}{6}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\frac{B_B + 4 B_C + B_D}{6}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;First consider trying to go from BSpline to CR. If we had a 'loop' formed by N control points one would map from BSpline to CR with...&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}CR_0\\CR_1\\ ...\\CR_{n-1} \end{bmatrix} = M_{NxBtoCR}.\begin{bmatrix}B_0\\B_1\\ ...\\B_{n-1} \end{bmatrix}$$&lt;/span&gt;&#xA;where&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;M_{NxBtoCR}= \frac{1}{6}.\begin{bmatrix}&#xA;4 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; ... &amp;amp; 0 &amp;amp; 1\\&#xA;1 &amp;amp; 4 &amp;amp; 1 &amp;amp; 0 &amp;amp; ... &amp;amp; 0 &amp;amp; 0\\&#xA;0 &amp;amp; 1 &amp;amp; 4 &amp;amp; 1 &amp;amp; ... &amp;amp; 0 &amp;amp; 0\\&#xA;: &amp;amp; : &amp;amp;   &amp;amp;   &amp;amp; ... &amp;amp; : &amp;amp; :\\&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; ... &amp;amp; 1 &amp;amp; 4\\&#xA;\end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;If we invert that matrix to get &lt;span class=&quot;math-container&quot;&gt;$M_{NxBtoCR}^{-1}$&lt;/span&gt;, one should then be able to map the other way.&lt;/p&gt;&#xA;&lt;p&gt;Using a maths package such as Maple, one finds that each row of &lt;span class=&quot;math-container&quot;&gt;$M_{NxBtoCR}^{-1}$&lt;/span&gt; consists of the same set of values, all non-zero, which are progressively offset in each row. If we ignore the smaller terms, it suggests that &lt;span class=&quot;math-container&quot;&gt;$$B_i \approx 1.732 CR_i -0.464 (CR_{i-1}+CR_{i+1}) + 0.1243 (CR_{i-2}+CR_{i+2}) - 0.033(CR_{i-3}+CR_{i+3}) $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;There's probably some nice algebraic expression for this but I hope this might &amp;quot;do the trick&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Update&lt;/em&gt; Those weights don't &lt;em&gt;quite&lt;/em&gt; sum to 1.0 - you'll need to normalise them slightly.&lt;/p&gt;&#xA;&lt;p&gt;Obviously, this has assumed the curve is a loop. It's probably possible to adjust the weights for the end points but I'll leave that as an exercise for the reader.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-12-03T09:05:43.413" LastActivityDate="2020-12-03T09:05:43.413" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8271" PostTypeId="2" ParentId="8262" CreationDate="2018-11-16T06:43:08.937" Score="2" Body="&lt;p&gt;As you can see in the figure above, during a perspective &lt;em&gt;projection&lt;/em&gt;, the goal is to essentially &quot;splat&quot; points within the view frustum onto the near frustum plane. That means that the final z coordinate is actually just fixed at &lt;span class=&quot;math-container&quot;&gt;$z_{vp}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if we did this poorly, we could just map &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$z_{vp}$&lt;/span&gt; directly in our projection matrix by setting the third row of the matrix to &lt;span class=&quot;math-container&quot;&gt;$\left[0, 0, \frac{z_{vp}}{z_{prp}}, 0\right]$&lt;/span&gt; and setting the final homogenous coordinate to &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; (so no divide by &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; happens at the end). This approach is problematic because squashing all this depth information to &lt;span class=&quot;math-container&quot;&gt;$z_{vp}$&lt;/span&gt; &lt;em&gt;loses information&lt;/em&gt; and we can no longer do things like a depth test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why, instead of mapping all &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; values to the same fixed distance from the camera, we opt to map it into a range of &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; values instead. This is the &quot;normalization&quot; that the text is referring to. Furthermore, we aren't preserving the &quot;values&quot; at all. The wording in the text is confusing, but what we are preserving is the &lt;em&gt;information&lt;/em&gt; about what points lie further away from the view origin. When it says that we have a choice about how to do this normalization, well, we can choose to map &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; into any range that we wish, and in graphics contexts, we normally want something that preserves precision well enough that we can do nice things like get crisp shadows and such.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at standard texts, the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; value will be mapped via the matrix row:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\left[ 0, 0, \frac{-(f + n)}{f - n}, \frac{-2fn}{f - n} \right]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; coordinate is mapped to &lt;span class=&quot;math-container&quot;&gt;$-z_{prp}$&lt;/span&gt;. This should look similar to the other entries that map &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; between the right-left and top-bottom frustum planes respectively. In this case, we're mapping &lt;span class=&quot;math-container&quot;&gt;$z_{prp}$&lt;/span&gt; between &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;. Now, we have a &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; coordinate that is mapped in a range such that after the divide-by-&lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; to get back to normal 3-coordinate space from homogeneous space, maps back to &lt;span class=&quot;math-container&quot;&gt;$z_{vp}$&lt;/span&gt; as expected, but until that occurs, can be used to perform depth comparisons. The choice of &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; is arbitrary, but too narrow and you end up clipping &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; values that lie outside the range, and too wide and you lose precision. Some people use a &lt;span class=&quot;math-container&quot;&gt;$-\log$&lt;/span&gt; depth computation instead to gain as much precision as possible, but I digress.&lt;/p&gt;&#xA;" OwnerUserId="87" LastActivityDate="2018-11-16T06:43:08.937" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8272" PostTypeId="2" ParentId="8247" CreationDate="2018-11-16T07:16:17.220" Score="0" Body="&lt;p&gt;Make a tiling texture of a cross. When this texture repeats in all dimensions, it will make a grid-like pattern. Next render a ground plane as above and unwrap the texture on it with the appropriate tiling rate. Change the intensity of the color based on the dot product of the ground plane normal and the view direction to get the lighting/fade effect (you can experiment with different falloff functions and ranges).&lt;/p&gt;&#xA;" OwnerUserId="87" LastActivityDate="2018-11-16T07:16:17.220" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8273" PostTypeId="1" AcceptedAnswerId="8274" CreationDate="2018-11-16T10:46:46.913" Score="1" ViewCount="113" Body="&lt;p&gt;I am working on a texture mapping problem. I use vtk C++ library for my work. I have a very dense mesh with lots of vertices. I want to apply image texture to this mesh. Should I set texture coordinates for every vertex ? Or can I skip few vertices and setup the texture coordinates and still expect the texture to be set properly? Please see the image attached. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/ux0Z6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ux0Z6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If A,B,C,D, E, F are the vertices of 4 faces in a mesh, can I set the texture coordinates only to A,C,F,D ? Will the texture drape the faces stretching equally?&lt;/p&gt;&#xA;" OwnerUserId="8957" LastEditorUserId="8957" LastEditDate="2018-11-16T12:07:36.843" LastActivityDate="2018-11-16T14:52:17.820" Title="In texture mapping, should we set texture coordinate to every vertex or can I skip vertices in between?" Tags="&lt;texture&gt;&lt;uv-mapping&gt;&lt;vtk&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8274" PostTypeId="2" ParentId="8273" CreationDate="2018-11-16T14:52:17.820" Score="1" Body="&lt;p&gt;Typically, texture coordinates are interpolated from the vertices of a triangle during rendering. This can be seen in two ways. evaluating your texture at vertices and the interpolating the result or interpolating the texture coordinates and evaluating your texture at the fragment level. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you do not supply vertices with corresponding texture coordinates then there is no guarantee that the interpolated texture coordinates or colours for the fragments of the rendered triangle will behave nicely. By skipping a few vertices, the vertices would need some default texture coordinate such as &lt;span class=&quot;math-container&quot;&gt;$(0,0)$&lt;/span&gt;, which would show up as a weird artefact in your rendering. The vertices B and E in your example are required to have texture coordinates in order to have a continuous set of interpolated texture coordinates or colour values.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2018-11-16T14:52:17.820" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8275" PostTypeId="2" ParentId="8247" CreationDate="2018-11-16T17:08:20.320" Score="3" Body="&lt;p&gt;You can do it by only rendering a flat plane and then making a grid in fragment shader. This is actually a nice exercise. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get these two color values, you can use color selector, which is available in any graphic software for example MS Paint&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some code hints:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 coord = worldPos.xz / stepSize; //square size in world space&#xA;vec2 frac = fract(coord); //fractional parts of squares&#xA;//interpolation, grad is smoothness of line gradients&#xA;vec2 mult = smoothstep(0.0, grad, frac) - smoothstep(1.0-grad, 1.0, frac);&#xA;vec3 col = mix(col1, col2, mult.x * mult.y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2018-11-16T17:08:20.320" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8276" PostTypeId="2" ParentId="8260" CreationDate="2018-11-16T22:43:30.033" Score="0" Body="&lt;p&gt;Not sure what's wrong with your implementation, but it looks like the blender's distortion model is not proportional to the image aspect ratio, producing equal curvature in both axis..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you compare the input coordinates between the two implementations?&lt;/p&gt;&#xA;" OwnerUserId="9505" LastActivityDate="2018-11-16T22:43:30.033" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8280" PostTypeId="2" ParentId="8269" CreationDate="2018-11-17T14:14:05.963" Score="0" Body="&lt;p&gt;found the problem, it was the shader. I am using following shader, that works fine&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Cubic.fsh&#xA;uniform vec4 insideColor;&#xA;varying vec4 v_textCoord;&#xA;&#xA;void main(void) {&#xA;    vec3 v_klm = v_textCoord.xyz;&#xA;    float t = v_klm.x * v_klm.x * v_klm.x - v_klm.y * v_klm.z;&#xA;    float alpha = clamp(sign(t), 0.0, 1.0);&#xA;    gl_FragColor = insideColor * alpha;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3024" LastEditorUserId="3024" LastEditDate="2018-11-18T21:51:54.920" LastActivityDate="2018-11-18T21:51:54.920" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8281" PostTypeId="2" ParentId="7538" CreationDate="2018-11-17T16:23:10.853" Score="0" Body="&lt;p&gt;I achieved similar result to theirs. First, the target texture for mip generation is base texture size + two margins, each equals 0.125 of base size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then during generation of base mip level, there are two cases:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;inside the square, then just sample original texture,&lt;/li&gt;&#xA;&lt;li&gt;beyond the central square, then blur the original texture with varying sigma, which depends on distance of current fragCoord from central square borders. While blurring texcoord is clamped to central square borders.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;How to compute distance: &lt;a href=&quot;https://gamedev.stackexchange.com/a/44496/91268&quot;&gt;https://gamedev.stackexchange.com/a/44496/91268&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gaussian one pass blur I used: &lt;a href=&quot;https://www.shadertoy.com/view/XdfGDH&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/XdfGDH&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are code fragments:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 coord = gl_FragCoord.xy;&#xA;vec2 minCorner = margin;&#xA;vec2 maxCorner = filteredMipRes - margin;&#xA;if(insideBox(coord, minCorner, maxCorner) &amp;gt; 0.5)&#xA;{&#xA;    fragColor = textureLod(sourceTexture, tc, 0.0).rgb;&#xA;}&#xA;else&#xA;{&#xA;    vec2 center = filteredMipRes / 2.0;&#xA;    vec2 d = max(abs(coord - center) - baseTextureRes / 2.0, vec2(0.0));&#xA;    float dist = sqrt(d.x * d.x + d.y * d.y);&#xA;    sigma = max(dist*2.0, 0.5);&#xA;    fragColor = blur(sigma);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Rest of mipmaps are just equally gaussian blurred, each based on one level higher mip.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2018-11-17T16:38:56.010" LastActivityDate="2018-11-17T16:38:56.010" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8284" PostTypeId="2" ParentId="8223" CreationDate="2018-11-18T08:50:41.157" Score="4" Body="&lt;p&gt;Also consider these alternatives for reducing bandwidth in comparison to R16G16B16A16.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;DXGI_FORMAT_BC6H_UF16 is block compressed fp16 (half) RGB.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3d11/bc6h-format&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/desktop/direct3d11/bc6h-format&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;DXGI_FORMAT_R11G11B10 unsigned small float&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;a href=&quot;https://bartwronski.com/2017/04/02/small-float-formats-r11g11b10f-precision/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://bartwronski.com/2017/04/02/small-float-formats-r11g11b10f-precision/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Common image file formats for HDR are exrs or dds. They're pretty trivially encoded as 32-bit or 16-bit per channel floats.&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-11-18T08:50:41.157" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8285" PostTypeId="2" ParentId="8102" CreationDate="2018-11-18T09:14:21.967" Score="1" Body="&lt;p&gt;I'll point out that even if you did implement it correctly, at 1 sample per pixel with low roughness materials you'll still see heavy specular aliasing. It's not uncommon to see the firefly pattern on edges on low roughness materials.&lt;/p&gt;&#xA;&lt;p&gt;For reference see the Infiltrator demo without TAA&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://advances.realtimerendering.com/s2014/epic/TemporalAA_Compare.mov&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://advances.realtimerendering.com/s2014/epic/TemporalAA_Compare.mov&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://advances.realtimerendering.com/s2014/index.html#_HIGH-QUALITY_TEMPORAL_SUPERSAMPLING&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://advances.realtimerendering.com/s2014/index.html#_HIGH-QUALITY_TEMPORAL_SUPERSAMPLING&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="1582" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-11-18T09:14:21.967" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8286" PostTypeId="1" CreationDate="2018-11-18T09:55:48.450" Score="1" ViewCount="271" Body="&lt;p&gt;I'm trying to render thick cubic Bezier curves using the whole OpenGL 4.5 pipeline:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I render a patch with 4 control points.  &lt;/li&gt;&#xA;&lt;li&gt;Vertex shader is simply pass-through to tessellation control shader.  &lt;/li&gt;&#xA;&lt;li&gt;TCS - sendng 4 vertices to tessalator with &lt;code&gt;gl_TessLevelOuter[1] = 10&lt;/code&gt; &lt;/li&gt;&#xA;&lt;li&gt;TES - calculating position for every of those 10 tessellated isoline points using Bezier curve equation  &lt;/li&gt;&#xA;&lt;li&gt;Geometry shader - making quads out of every line it receives extruding vertices along line's normal vector.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;So far so good but this will obviously lead to cracks between adjacent quads. To solve this problem I would need to know the position of adjacent lines in TES or GS to correct edges. Is this information available?&lt;/p&gt;&#xA;" OwnerUserId="9722" LastEditorUserId="6" LastEditDate="2018-11-20T13:56:54.210" LastActivityDate="2018-11-20T13:56:54.210" Title="Is it possible to access adjacent vertex data in tessellation evaluation shader?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8287" PostTypeId="1" AcceptedAnswerId="8288" CreationDate="2018-11-18T12:20:54.077" Score="0" ViewCount="867" Body="&lt;p&gt;I am working on a simple graph viewer with OpenGL. My problem with is directed edges. I tried to draw arrow endings with GL_TRIANGLES but somehow my calculations are off. I've used direction cosine vector to calculate triangle position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Actually triangle positions are almost correct but angles are a bit off for some triangles. Here is a screenshot:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NjBhk.pngm&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NjBhk.pngm&quot; alt=&quot;screenshot&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and here is my code to draw arrow endings:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;foreach (Edge e in m_graph.EdgeList.Values)&#xA;{&#xA;    if (e.Source == e.Target)&#xA;    {&#xA;        //TO DO: loops&#xA;    }&#xA;    if (e.Directed)&#xA;    {&#xA;        GL.Begin(PrimitiveType.Triangles);&#xA;&#xA;        Vector2 p1, p2;&#xA;        e.Source.GetAttribute(&quot;pos&quot;, out p1);&#xA;        e.Target.GetAttribute(&quot;pos&quot;, out p2);&#xA;&#xA;        Vector2 direction = p2 - p1;&#xA;        direction.Normalize();&#xA;&#xA;        Vector2 perpendicular = (Vector2)direction.Clone();&#xA;        perpendicular.Perpendicu();&#xA;&#xA;        Vector2 c_pt = p2 - direction * VERTICLE_SIZE * 3;&#xA;        Vector2 pt1 = c_pt - perpendicular * VERTICLE_SIZE;&#xA;        Vector2 pt2 = c_pt + perpendicular * VERTICLE_SIZE;&#xA;&#xA;        GL.Vertex2(p2.X, p2.Y);&#xA;        GL.Vertex2(pt1.X, pt1.Y);&#xA;        GL.Vertex2(pt2.X, pt2.Y);&#xA;&#xA;        GL.End();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;also Normalize and Perpendicu methods from Vector2 class:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    /// &amp;lt;summary&amp;gt;&#xA;    /// Normalizes the vector&#xA;    /// &amp;lt;/summary&amp;gt;&#xA;    public void Normalize()&#xA;    {&#xA;        m_x /= this.Length;&#xA;        m_y /= this.Length;&#xA;    }&#xA;&#xA;    /// &amp;lt;summary&amp;gt;&#xA;    /// Perpedicus the vector&#xA;    /// &amp;lt;/summary&amp;gt;&#xA;    public void Perpendicu()&#xA;    {&#xA;        float _x = m_x;&#xA;        m_x = -m_y;&#xA;        m_y = _x;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9723" LastActivityDate="2018-11-18T16:01:32.003" Title="Drawing Directed Lines (with arrow endings)" Tags="&lt;opengl&gt;&lt;line-drawing&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8288" PostTypeId="2" ParentId="8287" CreationDate="2018-11-18T16:01:32.003" Score="0" Body="&lt;p&gt;I don't see anything wrong with your code except for possibly the normalization of the direction. If the length of the vector gets updated automatically, it will change after the division of the x coordinate by the length. What you probably want is&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void Normalize()&#xA;{&#xA;    float len = this.Length;&#xA;    m_x /= len;&#xA;    m_y /= len;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;instead. This would also explain why the arrow endings look more off for horizontal directions than for vertical directions. If the x component of the direction is small, then a division of m_x by the length only leads to a small change in the length of the direction. (Try to change the order of the two divisions in your Normalize function; then it should be the other way around.)&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastActivityDate="2018-11-18T16:01:32.003" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8289" PostTypeId="2" ParentId="8286" CreationDate="2018-11-18T16:22:55.583" Score="2" Body="&lt;p&gt;If you want to prevent cracks between the tessellated lines in a single curve, what you need to know is how to &lt;a href=&quot;https://en.wikipedia.org/wiki/Miter_joint&quot; rel=&quot;nofollow noreferrer&quot;&gt;miter the quads&lt;/a&gt; correctly. Your GS's extrusion is presumably based on taking the 2D perpendicular to the line direction and extending the quad in that direction. Well, don't do that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, have the TES compute the perpendicular direction for each vertex in the tessellation. You can compute this by taking the first derivative of the Bezier curve (its tangent), which can be computed exactly, and then finding the perpendicular of that. Each vertex will have its own perpendicular value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It should be this perpendicular which you feed to the GS to do the quad extrusion. And you should be guaranteed to have invariant results. The TES's computation of the position and perpendicular will be based solely on the positions of the control points and the tessellation coordinates. The control points are fixed for all invocations of a TES over a patch, and the tessellator guarantees the invariance of &lt;code&gt;gl_TessCoord&lt;/code&gt; for the &quot;same vertex&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Invariance &lt;em&gt;between&lt;/em&gt; patches will be something of a problem. That is, invariance between the end of one set of 4 control points and the beginning of an attached one. The tessellation system only guarantees invariance at edges between patches if the computations that lead to the positions of the vertices are all based &lt;em&gt;solely&lt;/em&gt; on data that is binary identical between the two edge vertices. And that's not generally the case for bezier curves; you achieve C1 continuity by ensuring that the slope between boundary control points is the same. And that slope is &lt;em&gt;not&lt;/em&gt; passed as a parameter; it is computed. And thus, two edge vertices on different patches could have slightly different slope computations, which leads to different vertices, which leads to invariance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only way to handle this is to have your Bezier spline defined by &lt;em&gt;six&lt;/em&gt; control points rather than four. You pass as the first and last control points the previous/next control points for the Bezier spline (you'll have to make something up at the edges). This allows your computations to be invariant, since at the edges, you will be doing computations based on the exact same data.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-11-18T16:22:55.583" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8290" PostTypeId="1" AcceptedAnswerId="8294" CreationDate="2018-11-18T18:29:31.287" Score="1" ViewCount="469" Body="&lt;p&gt;What I have:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;a plane given by its normal&lt;span class=&quot;math-container&quot;&gt;$\ n $&lt;/span&gt; and a point on the plane&lt;span class=&quot;math-container&quot;&gt;$\ p $&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;li&gt;a 3D-point&lt;span class=&quot;math-container&quot;&gt;$\ v $&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;li&gt;a direction&lt;span class=&quot;math-container&quot;&gt;$\ d$&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What I need:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the projection of&lt;span class=&quot;math-container&quot;&gt;$\ v$&lt;/span&gt; along&lt;span class=&quot;math-container&quot;&gt;$\ d$&lt;/span&gt; onto the plane.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;How can I calculate this? Thank you!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S.: I need to implement that in GLSL, in case this is of any information. I would be fine with the formula so that I can work out the implementation myself, anyways. :-)&lt;/p&gt;&#xA;" OwnerUserId="9726" LastEditorUserId="182" LastEditDate="2018-11-19T07:16:51.843" LastActivityDate="2018-11-19T16:41:26.647" Title="Project vertex onto plane" Tags="&lt;opengl&gt;&lt;projections&gt;&lt;shading&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8291" PostTypeId="1" CreationDate="2018-11-18T19:23:52.167" Score="0" ViewCount="442" Body="&lt;p&gt;This problem is giving me a really hard time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm always looking at the origin and have a camera that moves around it in an arcball mode. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That part works beautifully:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4cEd5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4cEd5.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm calculating the camera position as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;camera.pos.x = origin.x + distance (arrow) * cos(angleX)&#xA;camera.pos.z = origin.z + distance * sin(angleX)&#xA;camera.pos.y : Float = origin.y + distance * sin(angleY)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But now I also want to be able to shift the position of the camera laterally, i.e. on (or parallel to) the tangent plane to the sphere between the origin and the camera position. (That tangent plane being the screen plane.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I.e. I want to shift the view matrix to the left/right and upwards/downwards, so that the camera is shifted laterally. (I need this for features such as moving the view on a touchscreen [two-finger gesture] or texture projection).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How should I go about this?&lt;/p&gt;&#xA;" OwnerUserId="9727" LastEditorUserId="9727" LastEditDate="2018-11-18T19:34:32.417" LastActivityDate="2021-05-19T03:06:50.633" Title="Translate an arcball camera upwards or left-right" Tags="&lt;opengl&gt;&lt;mathematics&gt;&lt;matrix&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8292" PostTypeId="2" ParentId="8151" CreationDate="2018-11-18T21:05:15.733" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Edit: I suddenly understood the issue. The noise in the top right corner of (b) is because it's struggling to find the tiny fraction of angles in which the BSDF is not extremely close to zero. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes your reasoning here is correct. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Taken to the extreme if the top most surface was perfectly mirror (dirac delta BRDF), then it would never* sample the right ray from the light source that was perfectly aligned with the camera's view direction. For such a BRDF &lt;span class=&quot;math-container&quot;&gt;$\omega_i$&lt;/span&gt; must equal &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;. &lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-11-18T21:05:15.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8294" PostTypeId="2" ParentId="8290" CreationDate="2018-11-19T07:15:46.407" Score="2" Body="&lt;p&gt;To answer your question we just need to write it as linear algebra equations and solve them. Although your question doesn't state it, I assume that &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; are unit vectors. Let's call the projected point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, because the projected point is in the direction &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt;, we can write:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{vx} = \lVert\vec{vx}\rVert d $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, because &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; are on the plane and &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is the plane normal, we can write:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{vx}\cdot n = \vec{vp}\cdot n$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can now work on the equation until we get a definition for &lt;span class=&quot;math-container&quot;&gt;$\vec{vx}$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{align}&#xA;\vec{vx}\cdot n &amp;amp; = \vec{vp}\cdot n \\&#xA;\lVert\vec{vx}\rVert d\cdot n &amp;amp; = \vec{vp}\cdot n \\&#xA;\lVert\vec{vx}\rVert &amp;amp; = \frac{\vec{vp}\cdot n}{d\cdot n} \\&#xA;\vec{vx} &amp;amp; = \frac{\vec{vp}\cdot n}{d\cdot n}d \\&#xA;\end{align}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or written differently:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$x = v + \frac{(p-v)\cdot n}{d\cdot n}d$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;The result is undefined when the scalar product &lt;span class=&quot;math-container&quot;&gt;$d \cdot v$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;, which happens when &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; are orthogonal, when &lt;span class=&quot;math-container&quot;&gt;$d=0$&lt;/span&gt;, or when &lt;span class=&quot;math-container&quot;&gt;$n=0$&lt;/span&gt;. The first case means &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; is parallel to the plane and the projection doesn't have a point solution, and the two other cases mean that either the plane or the projection are not defined.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="182" LastEditorUserId="182" LastEditDate="2018-11-19T16:41:26.647" LastActivityDate="2018-11-19T16:41:26.647" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8295" PostTypeId="1" CreationDate="2018-11-19T08:34:52.877" Score="3" ViewCount="469" Body="&lt;p&gt;I am currently building a graphics engine. I have a slight confusion on the imaging pipeline of computer screen. My question is how does computer transform the colour in the final frame buffer to radiance on the screen. My assumption is that the final colour in the render target should be proportional to luminance instead of radiance. Then, there is some function in the pipeline that will apply transform inverse of the photometric curve of this value to get the radiance of each RGB value. Am I correct?&lt;/p&gt;&#xA;" OwnerUserId="8565" LastActivityDate="2018-12-04T07:44:53.527" Title="Luminance and Radiance in computer screen" Tags="&lt;pbr&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8296" PostTypeId="1" CreationDate="2018-11-19T22:37:18.153" Score="0" ViewCount="169" Body="&lt;p&gt;I've been implementing a path tracer, referring pbrt-v3. However, I'm a bit confused about its implementation. Code is &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/9f717d847a807793fa966cf0eaa366852efef167/src/core/reflection.cpp#L477&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems when we sample to do transmission, it tests if it meets a total internal reflection, but it doesn't assign a proper value to the &lt;code&gt;pdf&lt;/code&gt;, instead, after the function returns &lt;code&gt;Vec3f(0,0,0)&lt;/code&gt; as BTDF value, it then tests if &lt;code&gt;pdf&lt;/code&gt; is 0, if 0 then directly jumps out of the tracing loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't think this make sense since there should be radiance value if this ray continues to trace and does out of the specular object and hit a surface which is illuminated. But this implementation seems to leave out all such kind of radiance, and rely on the &lt;code&gt;sample_f&lt;/code&gt; function to sample a reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how to properly compute the &lt;code&gt;pdf&lt;/code&gt; of total internal reflection?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        // Account for the indirect subsurface scattering component&#xA;        Spectrum f = pi.bsdf-&amp;gt;Sample_f(pi.wo, &amp;amp;wi, sampler.Get2D(), &amp;amp;pdf,&#xA;                                       BSDF_ALL, &amp;amp;flags);&#xA;        if (f.IsBlack() || pdf == 0) break;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7334" LastEditorUserId="182" LastEditDate="2018-11-20T04:12:49.440" LastActivityDate="2019-05-01T07:03:00.840" Title="total internal reflection implementation in pbrt-v3" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;physically-based&gt;&lt;specular&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8297" PostTypeId="1" CreationDate="2018-11-20T00:46:11.523" Score="5" ViewCount="236" Body="&lt;p&gt;What algorithm can I use to reassemble a broken image?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Wmwt6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Wmwt6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any technique? algorithm? Can I use graphs? machine learning? computer graphics?&lt;/p&gt;&#xA;" OwnerUserId="9256" LastEditorUserId="3003" LastEditDate="2018-11-24T17:02:57.397" LastActivityDate="2018-12-17T04:03:21.507" Title="What algorithm to reassemble a broken image?" Tags="&lt;image&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8299" PostTypeId="1" CreationDate="2018-11-20T11:07:20.470" Score="2" ViewCount="146" Body="&lt;p&gt;so I am not new to interactive graphics programming, but I wanted to try out advanced techniques. Currently I am struggling to understand how the author of the 2011 paper &quot;Interactive Indirect Illumination Using Voxel Cone Tracing&quot; (Crassin et al) manages to solve the rendering equation. Specifically in section 6 he claims that the hemisphere can be partitioned into a sum of integrals. I know about the Riemann sum, but this doesn't look like it.&#xA;So my question:&#xA;How does cone tracing as explained in the paper solve the rendering equation?&lt;/p&gt;&#xA;" OwnerUserId="9364" LastActivityDate="2018-11-20T11:07:20.470" Title="How does Voxel Cone Tracing solve the rendering equation?" Tags="&lt;global-illumination&gt;&lt;voxelization&gt;&lt;raymarching&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="1" ClosedDate="2018-12-08T10:15:57.740" ContentLicense="CC BY-SA 4.0" />
  <row Id="8300" PostTypeId="2" ParentId="8297" CreationDate="2018-11-20T14:33:17.420" Score="3" Body="&lt;p&gt;If the pieces are fairly close to where they were, &lt;a href=&quot;https://en.wikipedia.org/wiki/Iterative_closest_point&quot; rel=&quot;nofollow noreferrer&quot;&gt;ICP&lt;/a&gt; could be of help (under the assumption that the pieces are planar polygons).&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-11-20T14:33:17.420" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8302" PostTypeId="1" AcceptedAnswerId="8303" CreationDate="2018-11-21T22:51:29.940" Score="1" ViewCount="376" Body="&lt;p&gt;I have a flood-fill algorithm (&lt;a href=&quot;https://en.wikipedia.org/wiki/Flood_fill&quot; rel=&quot;nofollow noreferrer&quot;&gt;Flood-fill&lt;/a&gt;) to fill a 24x24 matrix as follows (matrix is 24x24 here but will be much bigger in production):  &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Main code:&#xA;&#xA;  var cspots,    // number of spots per group&#xA;      gArr=[];   // global array which contains all group spots&#xA;&#xA;  var tArr = new Array(gArr.length);   // touch array for flood-fill&#xA;  for(var spot in inArr) {&#xA;    for (var tspot in tArr)  // initialise touch array &#xA;      tArr[tspot]=0;&#xA;    for(gspot in gArr) {     // find lowest open y*24+x ordinal&#xA;      if (gArr[gspot][0] == 0) &#xA;        break;&#xA;      tArr[gspot]=1;&#xA;    }&#xA;    cspots = inArr[spot].GD;&#xA;    userFill(gArr[gspot][1],gArr[gspot][2],inArr[spot].KY,tArr);&#xA;  }&#xA;&#xA;function userFill(x,y,elem,tArr) {&#xA;  var gord, qt=0;&#xA;  if (!cspots) return;&#xA;  if ((x &amp;gt;= 0) &amp;amp;&amp;amp; (x &amp;lt;= 23) &amp;amp;&amp;amp; (y &amp;gt;= 0) &amp;amp;&amp;amp; (y &amp;lt;= 23)) {&#xA;    gord = y*24 + x;&#xA;    if (gArr[gord][0] != 0 || tArr[gord]) &#xA;      return;&#xA;    gArr[gord][0] = elem;&#xA;    tArr[gord] = 1;&#xA;    --cspots;&#xA;    userFill(x+1,y,elem,tArr);&#xA;    userFill(x-1,y,elem,tArr);&#xA;    // before the y-change we need to see if there are any open spots on this line&#xA;    for(gord=y*24; gord&amp;lt;=(y*24)+23; gord++) {&#xA;      if (gArr[gord][0] == 0) {&#xA;        qt=1;&#xA;        break;&#xA;      }&#xA;    }&#xA;    if (!qt) {&#xA;      userFill(x,y+1,elem,tArr);&#xA;      userFill(x,y-1,elem,tArr);&#xA;    }&#xA;  }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is a standard flood-fill recursive algorithm (with an accompanying touch array to mark any touches) with the additional code that I check if all x-values are set to non-zero on each x-plane before changing the y-value. This produces a matrix like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8FjCF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8FjCF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that it doesn't look very good (imo) as most of the areas are strung-out along the x-plane. What I want is each different group area to be in the shape of a square as much as I can. Sort-of like this example (using letters to indicate the different group areas):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;V V V W W W W X X X X X&#xA;V V Y W W W W X X X X Z&#xA;Y Y Y W W W W Z Z Z Z Z&#xA;Y Y   W W W W Z Z Z Z Z&#xA;... and so on&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So I have changed the userFill to look at a boxX variable which is just the (sqrt of each area)+1, which hopefully I can use to limit each area to make a square-shape. And a preX variable to store the anchor point from each group area so I know how many spots have been added. Here's the new userFill:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Main code:&#xA;&#xA;  var tArr = new Array(gArr.length);&#xA;  for(var spot in inArr) {&#xA;    for (var tspot in tArr)  // initialise touch array &#xA;      tArr[tspot]=0;&#xA;    for(gspot in gArr) {     // find lowest open y*24+x ordinal&#xA;      if (gArr[gspot][0] == 0) &#xA;        break;&#xA;      tArr[gspot]=1;&#xA;    }&#xA;    cspots = inArr[spot].GD;&#xA;    boxX = Math.ceil(Math.sqrt(cspots));&#xA;    preX = gArr[gspot][1];&#xA;    userFill(gArr[gspot][1],gArr[gspot][2],inArr[spot].KY,tArr);&#xA;  }&#xA;&#xA;function userFill(x,y,elem,tArr) {&#xA;  var gord, qt=0;&#xA;  if (!cspots) return;&#xA;  if ((x &amp;gt;= 0) &amp;amp;&amp;amp; (x &amp;lt;= 23) &amp;amp;&amp;amp; (y &amp;gt;= 0) &amp;amp;&amp;amp; (y &amp;lt;= 23)) {&#xA;    gord = y*24 + x;&#xA;    if (gArr[gord][0] != 0 || tArr[gord]) &#xA;      return;&#xA;    gArr[gord][0] = elem;&#xA;    tArr[gord] = 1;&#xA;    --cspots;&#xA;    // before the x-change we need to see if we have done a boxX number of changes to maintain square-shape&#xA;    if (Math.abs(x-preX) == boxX) {&#xA;      userFill(preX,y+1,elem,tArr);&#xA;      userFill(preX,y-1,elem,tArr);&#xA;      return;&#xA;    }&#xA;    userFill(x+1,y,elem,tArr);&#xA;    userFill(x-1,y,elem,tArr);&#xA;    // before the y-change we need to see if there are any open spots on this line&#xA;    for(gord=y*24; gord&amp;lt;=(y*24)+boxX; gord++) {&#xA;      if (gArr[gord][0] == 0) {&#xA;        qt=1;&#xA;        break;&#xA;      }&#xA;    }&#xA;    if (!qt) {&#xA;      userFill(x,y+1,elem,tArr);&#xA;      userFill(x,y-1,elem,tArr);&#xA;    }&#xA;  }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The only difference is that I check if boxX spots have been added and then call userFill recursively to change the y-plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the output and it looks better as most areas are square-like but obviously it needs work (missing most of the spots, pale-blue group area is very oddly-shaped and not square-like at all), but I wonder if there is a better algorithm out there that changes a flood-fill from line-based to square based.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HL3gn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HL3gn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think I figured out an algorithm. You start with a single point at the lowest point in the matrix. You then add a surrounding square of points around that point followed by a larger square until cspots is exhausted. So:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0     (first spot in matrix (0,0))&#xA;&#xA;1 1&#xA;0 1   (add 3 spots to make it a 2x2 square)&#xA;&#xA;2 2 2&#xA;1 1 2&#xA;0 1 2   (add 5 spots to make it a 3x3 square)&#xA;&#xA;and so on&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This can be done even if a number of squares are drawn and you are building on top of other squares. For example (X and Y are preexisting squares):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  X&#xA;X X Y Y&#xA;X X Y Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Place first spot of new group in the lowest point in matrix (0,2)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0 X&#xA;X X Y Y&#xA;X X Y Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Try and build 1st level square  (an 'X' will be blocking one of the 1-level spots)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1 1&#xA;0 X&#xA;X X Y Y&#xA;X X Y Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Try to build 2nd level square&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;2 2 2&#xA;1 1 2&#xA;0 X 2&#xA;X X Y Y&#xA;X X Y Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;3rd level&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;3 3 3 3&#xA;2 2 2 3&#xA;1 1 2 3&#xA;0 X 2 3&#xA;X X Y Y&#xA;X X Y Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;4th level&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;4 4 4 4 4&#xA;3 3 3 3 4&#xA;2 2 2 3 4&#xA;1 1 2 3 4&#xA;0 X 2 3 4&#xA;X X Y Y&#xA;X X Y Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;.. and so on. I just need to find the implementation now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE 2&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have created the breadth-first algorithm as suggested below and it works much better. Here's the code and the image produced (which is very square-like for each of the 10 groups).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function bfsFill(x,y,elem,tArr) {&#xA;  var gord, i=0, pt, queue=[], cnt=0;&#xA;  if (!cspots) return;&#xA;  if (isOutOfBounds(x,y)) return;&#xA;  queue.push([x,y]);&#xA;  while(cspots&amp;gt;0 &amp;amp;&amp;amp; queue.length&amp;gt;0) {&#xA;    pt = queue.shift(); &#xA;    gord = pt[1]*24 + pt[0];&#xA;    tArr[gord] = 1;&#xA;    gArr[gord][0] = elem;&#xA;    --cspots;&#xA;    var rArr = neighbours(pt);&#xA;    async.eachSeries(rArr, function(el, cb2) {&#xA;      if (!isOutOfBounds(el[0],el[1])) {&#xA;        gord = el[1]*24 + el[0];&#xA;        if (tArr[gord] == 0 &amp;amp;&amp;amp; gArr[gord][0] == 0) {&#xA;          for(var qi in queue) {&#xA;            if (queue[qi][0] == el[0] &amp;amp;&amp;amp; queue[qi][1]==el[1]) {&#xA;              cb2();&#xA;              return;&#xA;            }&#xA;          }&#xA;          queue.push(el);&#xA;        }&#xA;      }&#xA;      cb2();&#xA;    }, function(err) {&#xA;    });&#xA;  }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Image file produced:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ylMKg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ylMKg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9742" LastEditorUserId="9742" LastEditDate="2018-11-22T05:13:43.710" LastActivityDate="2018-11-22T09:41:30.903" Title="Flood-Fill and scanLine algorithms are line-based floods but I want square based floods" Tags="&lt;algorithm&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8303" PostTypeId="2" ParentId="8302" CreationDate="2018-11-22T01:16:32.930" Score="0" Body="&lt;p&gt;Your code, as seen on your post at the time of posting this answer, looks sort of like this (the following was thrown together rather quickly and may or may not work) :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function fill ( x, y, touched, elem ) {&#xA;    if ( count &amp;lt;= 0 ) return;&#xA;    if ( isOutOfBounds(x,y) ) return;&#xA;&#xA;    const idx = y*24 + x;&#xA;&#xA;    if ( gArr[idx][0] != 0 || touched[idx] ) return;&#xA;&#xA;    touched[idx] = true;&#xA;    gArr[idx][0] = elem;&#xA;    count--;&#xA;&#xA;    fill(x+1, y, touched, elem);&#xA;    fill(x-1, y, touched, elem);&#xA;    fill(x, y+1, touched, elem);&#xA;    fill(x, y-1, touched, elem);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the problem with this style of writing a flood fill is that it always takes the path to the right before considering the other 3 paths it can take. This leads the program to use up its spots by moving only to the right. Such a search is called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Depth-first_search&quot; rel=&quot;nofollow noreferrer&quot;&gt;Depth-First Search (DFS)&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, it would be nice if we could move around our grid starting from a point and growing out instead of blindly following the first path we find. A well known algorithm that does such a thing exists and it is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Breadth-first_search&quot; rel=&quot;nofollow noreferrer&quot;&gt;Breadth-First Search (BFS)&lt;/a&gt;. It goes roughly as follows (once again, this code probably wouldn't work, even if you implemented the missing bits):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function fill ( starting_point, count, elem ) {&#xA;    if ( count &amp;lt;= 0 ) return;&#xA;    if ( isOutOfBounds(starting_point) ) return;&#xA;&#xA;    let touched = Array(gArr.length).fill(false);&#xA;    let queue = [starting_point];&#xA;&#xA;    while ( count &amp;gt; 0 &amp;amp;&amp;amp; queue.length &amp;gt; 0 ) {&#xA;        let p = queue.shift();&#xA;&#xA;        touched[p.idx] = true;&#xA;        gArr[p.idx][0] = elem;&#xA;&#xA;        for ( let neighbor of neighbors(p) ) {&#xA;            if ( !isOutOfBounds( neighbor ) ) {&#xA;                if ( !touched[ neigbor.idx ] &amp;amp;&amp;amp; gArr[ neigbor.idx ][0] == 0 ){&#xA;                    touched[ neighbor.idx ] = true;&#xA;                    queue.push(neighbor);&#xA;                }&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What this is does is that it puts points to be painted in a queue and then looks at them in the same order that they were put in.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Naturally, the first set of points that are added into the queue are the neighbors of the starting point of your flood fill, then the neighbors of those points, and so on. Effectively building a square of increasing size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps! &lt;/p&gt;&#xA;" OwnerUserId="8680" LastEditorUserId="8680" LastEditDate="2018-11-22T09:41:30.903" LastActivityDate="2018-11-22T09:41:30.903" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8304" PostTypeId="2" ParentId="8291" CreationDate="2018-11-22T08:12:27.827" Score="0" Body="&lt;p&gt;Here's a basic camera with panning (some parts removed for brevity). It's not arcball but should get the idea across. Basically it just transforms some directions of a plane in view space to one that is in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;rotate and pan are called on mouse move with the change in mouse position.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Updates the view matrix based on parameters&#xA;void updateCam()&#xA;{&#xA;    // Calc eye position on sphere&#xA;    glm::vec3 eyePos = glm::vec3(&#xA;        rho * sin(phi) * cos(theta),&#xA;        rho * cos(phi),&#xA;        rho * sin(phi) * sin(theta));&#xA;&#xA;    setEyePos(eyePos + focalPt);&#xA;    setFocalPt(focalPt);&#xA;    updateLookAt(); // Uses eyePos and focalPt to calculate a view matrix&#xA;}&#xA;&#xA;// Input is a change in position&#xA;void rotate(glm::vec2 diff)&#xA;{&#xA;    theta += diff.x * rotateSpeed;&#xA;    phi -= diff.y * rotateSpeed;&#xA;&#xA;    // Clamp to prevent user flipping camera at top of sphere&#xA;    phi = clamp(phi, 0.01f, 3.14f);&#xA;    updateCam();&#xA;}&#xA;void pan(glm::vec2 diff)&#xA;{&#xA;    // Up and right are the directions to pan when camera is facing forward&#xA;    glm::mat3 invView = glm::inverse(view);&#xA;    glm::vec3 dx = invView * glm::vec3(1.0f, 0.0f, 0.0f);&#xA;    glm::vec3 dy = invView * glm::vec3(0.0f, 1.0f, 0.0f);&#xA;&#xA;    // Scale shift with scale so shift is relative to how far you are zoomed out&#xA;    focalPt += (dy * diff.y - dx * diff.x) * shiftSpeed;&#xA;    updateCam();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2018-11-22T22:38:02.137" LastActivityDate="2018-11-22T22:38:02.137" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8307" PostTypeId="1" AcceptedAnswerId="8315" CreationDate="2018-11-24T03:51:09.333" Score="1" ViewCount="77" Body="&lt;p&gt;To simplify, assume faces and corners of the square are labeled and the camera lens if whatever makes this simplest (a 90 degree field of view projection?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The application: using a known and labeled unit square to assist an AR app.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the case of a perfectly centered rotated on one axis, we can use the estimated distance from the axis the square was rotated around plus the ratio of sizes of the distorted sides.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But for an arbitrary view, the problem becomes much much harder.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Links to the general case of this problem in projective geometry also appreciated&lt;/p&gt;&#xA;" OwnerUserId="7743" LastEditorUserId="7743" LastEditDate="2018-11-24T04:02:32.567" LastActivityDate="2018-11-27T11:08:41.650" Title="Given a picture of a unit square at an arbitrary angle and position, how can I reconstruct the distance and orientation?" Tags="&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8308" PostTypeId="1" CreationDate="2018-11-25T19:04:24.730" Score="1" ViewCount="411" Body="&lt;p&gt;I'm hoping to port my existing toy raytracer to a window so that I can see samples accumulate over time. And then port over to Pixar's pmj02:&#xA;&lt;a href=&quot;https://graphics.pixar.com/library/ProgressiveMultiJitteredSampling/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://graphics.pixar.com/library/ProgressiveMultiJitteredSampling/paper.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm working within DX12 because the idea is to begin porting elements of the raytracer slowly into DX compute (or DXR), which I'm already familiar with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a simple quad fragment shader that samples a single Texture2D and writes to a quad on screen. At the moment, I am only writing data on startup, so that I can prove that copying over arbitrary 2D data to a texture2D is possible. However, I can only seem to write a black quad. I've flipped the sampler in hlsl with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;return 1.0f - g_WindowTexture.Sample(g_SamLinearWrap, pin.TexCoordF) &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and the quad went white, so the texture definitely has zeros for data. This leads me to believe that I'm not correctly copying data over to the GPU resource.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The window build code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;m_windowQuad.Initialize(m_D3dDevice, m_CommandList);&#xA;&#xA;D3D12_DESCRIPTOR_HEAP_DESC SrvHeapDesc = {};&#xA;SrvHeapDesc.NumDescriptors = 1;&#xA;SrvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;&#xA;SrvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;&#xA;ThrowIfFailed(m_D3dDevice-&amp;gt;CreateDescriptorHeap(&amp;amp;SrvHeapDesc, IID_PPV_ARGS(&amp;amp;m_SrvDescriptorHeap)));&#xA;&#xA;// Fill heap with actual descriptor&#xA;CD3DX12_CPU_DESCRIPTOR_HANDLE hDescriptor(&#xA;    m_SrvDescriptorHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart());&#xA;&#xA;// Load initial texture&#xA;auto texture = std::make_unique&amp;lt;ImageTexture&amp;gt;();&#xA;// texture data&#xA;const uint width = 16;&#xA;const uint pitch = 16 * sizeof(u8) * 4;&#xA;const uint height = 16;&#xA;char colors[width * height * 4];&#xA;DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;for (int i = 0; i &amp;lt; height*width * 4; i++)&#xA;    colors[i] = i % 256;&#xA;&#xA;D3D12_RESOURCE_DESC texDesc = {};&#xA;texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;&#xA;texDesc.Width = width;&#xA;texDesc.Height = height;&#xA;texDesc.DepthOrArraySize = 1;&#xA;texDesc.MipLevels = 1;&#xA;texDesc.Format = format;&#xA;texDesc.SampleDesc.Count = 1;&#xA;texDesc.SampleDesc.Quality = 0;&#xA;texDesc.Flags = D3D12_RESOURCE_FLAG_NONE;&#xA;&#xA;CD3DX12_HEAP_PROPERTIES HeapProperties(D3D12_HEAP_TYPE_DEFAULT);&#xA;&#xA;ThrowIfFailed(m_D3dDevice-&amp;gt;CreateCommittedResource(&amp;amp;HeapProperties, D3D12_HEAP_FLAG_NONE, &amp;amp;texDesc, &#xA;    D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(texture-&amp;gt;Resource.ReleaseAndGetAddressOf())));&#xA;&#xA;D3D12_SUBRESOURCE_DATA texResource;&#xA;texResource.pData = colors;&#xA;texResource.RowPitch = (pitch + (D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1)) &amp;amp; ~(D3D12_TEXTURE_DATA_PITCH_ALIGNMENT - 1);&#xA;texResource.SlicePitch = texResource.RowPitch * height;&#xA;&#xA;D3D12_SHADER_RESOURCE_VIEW_DESC SrvDesc = { };&#xA;SrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;&#xA;SrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;&#xA;SrvDesc.Texture2D.MostDetailedMip = 0;&#xA;SrvDesc.Texture2D.ResourceMinLODClamp = 0.0f;&#xA;SrvDesc.Format = texture-&amp;gt;Resource-&amp;gt;GetDesc().Format;&#xA;SrvDesc.Texture2D.MipLevels = texture-&amp;gt;Resource-&amp;gt;GetDesc().MipLevels;&#xA;SrvDesc.Texture2D.MostDetailedMip = 0;&#xA;SrvDesc.Texture2D.ResourceMinLODClamp = 0.0f;&#xA;&#xA;Microsoft::WRL::ComPtr&amp;lt;ID3D12Resource&amp;gt; IntResource;&#xA;ThrowIfFailed(m_D3dDevice-&amp;gt;CreateCommittedResource(&#xA;    &amp;amp;CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),&#xA;    D3D12_HEAP_FLAG_NONE,&#xA;    &amp;amp;CD3DX12_RESOURCE_DESC::Buffer(texResource.SlicePitch * 16),&#xA;    D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;    nullptr,&#xA;    IID_PPV_ARGS(IntResource.ReleaseAndGetAddressOf())));&#xA;&#xA;m_CommandList-&amp;gt;ResourceBarrier(1, &amp;amp;CD3DX12_RESOURCE_BARRIER::Transition(texture-&amp;gt;Resource.Get(),&#xA;    D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST));&#xA;UpdateSubresources(m_CommandList.Get(), texture-&amp;gt;Resource.Get(), IntResource.Get(), 0, 0, 1, &amp;amp;texResource);&#xA;m_CommandList-&amp;gt;ResourceBarrier(1, &amp;amp;CD3DX12_RESOURCE_BARRIER::Transition(texture-&amp;gt;Resource.Get(),&#xA;    D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));&#xA;&#xA;m_D3dDevice-&amp;gt;CreateShaderResourceView(texture-&amp;gt;Resource.Get(), &amp;amp;SrvDesc, hDescriptor);&#xA;texture-&amp;gt;SRVHeapIndex = 0;&#xA;m_Textures[&quot;quad&quot;] = std::move(texture);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then per frame the following draw calls are made:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void PBRApp::DrawWindowQuad(ID3D12GraphicsCommandList* cmdList)&#xA;{&#xA;    cmdList-&amp;gt;IASetVertexBuffers(0, 1, &amp;amp;m_windowQuad.VertexBufferView());&#xA;    cmdList-&amp;gt;IASetIndexBuffer(&amp;amp;m_windowQuad.IndexBufferView());&#xA;    cmdList-&amp;gt;IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);&#xA;&#xA;    CD3DX12_GPU_DESCRIPTOR_HANDLE Tex(m_SrvDescriptorHeap-&amp;gt;GetGPUDescriptorHandleForHeapStart());&#xA;    Tex.Offset(0, m_cbvSrvDescriptorSize);&#xA;&#xA;    cmdList-&amp;gt;SetGraphicsRootDescriptorTable(0, Tex);&#xA;    cmdList-&amp;gt;DrawIndexedInstanced(m_windowQuad.IndexCount, 1, &#xA;        m_windowQuad.StartIndexLocation, m_windowQuad.BaseVertexLocation, 0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So, I'm fairly confident in my root signature, PSO, and draw calls.&#xA;But I can't figure out why I keep getting a black quad (possibly empty data) drawn to the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I just going about this the wrong way?&lt;/p&gt;&#xA;" OwnerUserId="9753" LastActivityDate="2018-11-26T17:04:58.103" Title="Writing data to a shader resource at runtime in DX12" Tags="&lt;raytracing&gt;&lt;fragment-shader&gt;&lt;directx12&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8309" PostTypeId="2" ParentId="8189" CreationDate="2018-11-26T07:39:31.013" Score="1" Body="&lt;p&gt;Thanks for the input everyone. The problem turned out to be an issue with texture coordinates. I was sampling right on the edge of each pixel in the full-size image, causing causing it to shift to the next pixel in line. To fix this, I translated the texture coordinates left/up by half a pixel and I get the intended result.&lt;/p&gt;&#xA;" OwnerUserId="9577" LastActivityDate="2018-11-26T07:39:31.013" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8310" PostTypeId="2" ParentId="8308" CreationDate="2018-11-26T08:42:56.740" Score="0" Body="&lt;p&gt;Resource Views are read-only in DirectX. Have you tried using an unordered-access view instead?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The CPU-side setup for these is similar to standard resource views (at least in DX11, I haven't used DX12), just with more detail and slightly different objects:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/ns-d3d12-d3d12_unordered_access_view_desc&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/ns-d3d12-d3d12_unordered_access_view_desc&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/nf-d3d12-id3d12device-createunorderedaccessview&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/nf-d3d12-id3d12device-createunorderedaccessview&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the GPU side:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't see your shader, but I assume you've declared something like&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;Texture2D&amp;lt;float4&amp;gt; tex : register(t0)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so you'll need to change the binding for &lt;code&gt;tex&lt;/code&gt; into a write-allowed unordered-access texture, which would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;RWTexture2D&amp;lt;float4&amp;gt; tex : register(u0)&lt;/code&gt; &lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2018-11-26T10:34:11.823" LastActivityDate="2018-11-26T10:34:11.823" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8311" PostTypeId="1" AcceptedAnswerId="8314" CreationDate="2018-11-26T15:50:55.633" Score="6" ViewCount="3332" Body="&lt;p&gt;I am aware of libraries that already do this (like GLFW), but I would actually prefer do all of the window and context creation by myself.&lt;/p&gt;&#xA;" OwnerUserId="9436" LastActivityDate="2021-02-08T07:24:12.743" Title="How do I create a Win32 window with a Vulkan context?" Tags="&lt;c++&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8312" PostTypeId="2" ParentId="8308" CreationDate="2018-11-26T17:04:58.103" Score="1" Body="&lt;p&gt;So, I figured it out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While UAV will be necessary when I start manipulating data in Compute Shaders, for the time being, SRV works fine provided the resource is read-only from the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The two big problems were&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Creating an ImageTexture that was receiving the data. Note that the data copy was occurring just fine, but the texture was never used in the rest of the code. The correct place was to copy the code into the resource within m_WindowQuad.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Creating the ImageTexture (later m_WindowQuad) resource as&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;D3D12_RESOURCE_STATE_COPY_DEST&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;when it should have been defined as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;D3D12_RESOURCE_STATE_COMMON&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Near as I can tell, those two were the bulk of the problems.&#xA;The code rewritten, now functional:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;m_windowQuad.Initialize(m_D3dDevice, m_CommandList);&#xA;&#xA;D3D12_DESCRIPTOR_HEAP_DESC HeapDesc = {};&#xA;HeapDesc.NumDescriptors = 1;&#xA;HeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;&#xA;HeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;&#xA;ThrowIfFailed(m_D3dDevice-&amp;gt;CreateDescriptorHeap(&amp;amp;HeapDesc, IID_PPV_ARGS(&amp;amp;m_DescriptorHeap)));&#xA;&#xA;// Fill heap with actual descriptor&#xA;CD3DX12_CPU_DESCRIPTOR_HANDLE hDescriptor(&#xA;    m_DescriptorHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart());&#xA;&#xA;// texture data&#xA;const uint width = 16;&#xA;const uint pitch = 16 * sizeof(u8) * 4;&#xA;const uint height = 16;&#xA;char colors[width * height * 4];&#xA;DXGI_FORMAT format = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;for (int i = 0; i &amp;lt; height*width * 4; i++)&#xA;    colors[i] = i % 256;&#xA;&#xA;D3D12_RESOURCE_DESC texDesc = {};&#xA;texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;&#xA;texDesc.Width = width;&#xA;texDesc.Height = height;&#xA;texDesc.DepthOrArraySize = 1;&#xA;texDesc.MipLevels = 1;&#xA;texDesc.Format = format;&#xA;texDesc.SampleDesc.Count = 1;&#xA;texDesc.SampleDesc.Quality = 0;&#xA;texDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;&#xA;&#xA;D3D12_SUBRESOURCE_DATA texResource;&#xA;texResource.pData = colors;&#xA;texResource.RowPitch = pitch;&#xA;texResource.SlicePitch = texResource.RowPitch * height;&#xA;&#xA;&#xA;ThrowIfFailed(m_D3dDevice-&amp;gt;CreateCommittedResource(&#xA;    &amp;amp;CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),&#xA;    D3D12_HEAP_FLAG_NONE, &#xA;    &amp;amp;texDesc,&#xA;    D3D12_RESOURCE_STATE_COMMON,&#xA;    nullptr, &#xA;    IID_PPV_ARGS(m_windowQuad.Texture.ReleaseAndGetAddressOf())));&#xA;m_windowQuad.Texture-&amp;gt;SetName(L&quot;Window Texture&quot;);&#xA;&#xA;ThrowIfFailed(m_D3dDevice-&amp;gt;CreateCommittedResource(&#xA;    &amp;amp;CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),&#xA;    D3D12_HEAP_FLAG_NONE,&#xA;    &amp;amp;CD3DX12_RESOURCE_DESC::Buffer(texResource.SlicePitch * 16),&#xA;    D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;    nullptr,&#xA;    IID_PPV_ARGS(m_windowQuad.TextureUploader.ReleaseAndGetAddressOf())));&#xA;m_windowQuad.TextureUploader-&amp;gt;SetName(L&quot;Window Texture Uploader&quot;);&#xA;&#xA;D3D12_SHADER_RESOURCE_VIEW_DESC SrvDesc = { };&#xA;SrvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;&#xA;SrvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;&#xA;SrvDesc.Texture2D.MostDetailedMip = 0;&#xA;SrvDesc.Texture2D.ResourceMinLODClamp = 0.0f;&#xA;SrvDesc.Format = m_windowQuad.Texture-&amp;gt;GetDesc().Format;&#xA;SrvDesc.Texture2D.MipLevels = m_windowQuad.Texture-&amp;gt;GetDesc().MipLevels;&#xA;SrvDesc.Texture2D.MostDetailedMip = 0;&#xA;SrvDesc.Texture2D.ResourceMinLODClamp = 0.0f;&#xA;&#xA;m_CommandList-&amp;gt;ResourceBarrier(1, &amp;amp;CD3DX12_RESOURCE_BARRIER::Transition(m_windowQuad.Texture.Get(),&#xA;    D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_COPY_DEST));&#xA;UpdateSubresources(m_CommandList.Get(), m_windowQuad.Texture.Get(), m_windowQuad.TextureUploader.Get(), 0, 0, 1, &amp;amp;texResource);&#xA;m_CommandList-&amp;gt;ResourceBarrier(1, &amp;amp;CD3DX12_RESOURCE_BARRIER::Transition(m_windowQuad.Texture.Get(),&#xA;    D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_GENERIC_READ));&#xA;&#xA;m_D3dDevice-&amp;gt;CreateShaderResourceView(m_windowQuad.Texture.Get(), &amp;amp;SrvDesc, hDescriptor);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9753" LastActivityDate="2018-11-26T17:04:58.103" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8313" PostTypeId="1" AcceptedAnswerId="8340" CreationDate="2018-11-26T17:28:36.993" Score="1" ViewCount="150" Body="&lt;p&gt;What is the method used in overlaying a grid (agonostic of the grid type) on to a height map? It seems it's some sort of projection, but what are the technical details in how to implement it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example here is a hexagon grid overlayed onto the map in Civ5 that nicely handles spatial distance regardless of how high the height map is at a position - &#xA;&lt;a href=&quot;https://i.stack.imgur.com/yN0HQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yN0HQ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9562" LastActivityDate="2018-12-02T04:22:03.387" Title="Overlaying a grid on to a height map" Tags="&lt;3d&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8314" PostTypeId="2" ParentId="8311" CreationDate="2018-11-26T22:07:50.050" Score="7" Body="&lt;p&gt;There's no such thing as a Vulkan &lt;em&gt;context&lt;/em&gt;, the way there is with OpenGL.  This is because Vulkan is a lower level API and an OpenGL context ties together a number of concepts that are distinct in the Vulkan API.&lt;/p&gt;&#xA;&lt;p&gt;For example, the OpenGL context ties together the concept of extension management, memory management, draw commands and surface presentation.  In Vulkan those are all managed through independent interfaces.&lt;/p&gt;&#xA;&lt;p&gt;There are a number of things in Vulkan that &lt;em&gt;kind of&lt;/em&gt; correspond to an OpenGL context in different ways, depending on what you're trying to do.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;VkInstance&lt;/code&gt; encapsulates access to the Vulkan libraries on the system, including enumerating the global extensions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;VkPhysicalDevice&lt;/code&gt; lets you query the hardware capabilities and hardware specific extensions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;VkDevice&lt;/code&gt; lets you actually interact with the hardware to do things like allocate memory.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;VkCommandBuffer&lt;/code&gt; is the interface for setting up and executing draw calls.&lt;/p&gt;&#xA;&lt;p&gt;However, since you're focused on windows, what you're probably interested in is &lt;code&gt;VkSurfaceKHR&lt;/code&gt;.  This encapsulates interaction with a windowing system, including initializing a surface from the OS specific window handles and doing presentation calls.&lt;/p&gt;&#xA;&lt;p&gt;On Windows, to interact with a window, you need to have an existing &lt;code&gt;VkInstance&lt;/code&gt;, and you need to call &lt;a href=&quot;https://vulkan.lunarg.com/doc/view/1.0.33.0/linux/vkspec.chunked/ch29s02.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;vkCreateWin32SurfaceKHR&lt;/code&gt;&lt;/a&gt; and pass it a structure containing an &lt;code&gt;HWND&lt;/code&gt; and an &lt;code&gt;HINSTANCE&lt;/code&gt;.  If it succeeds then you have a surface to which you can then present images.&lt;/p&gt;&#xA;" OwnerUserId="9306" LastEditorUserId="9306" LastEditDate="2021-02-08T07:24:12.743" LastActivityDate="2021-02-08T07:24:12.743" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8315" PostTypeId="2" ParentId="8307" CreationDate="2018-11-27T11:08:41.650" Score="1" Body="&lt;p&gt;This problem is known as &lt;em&gt;camera calibration&lt;/em&gt;. The goal is estimating the various parameters of a &quot;camera&quot;:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The intrinsic parameters: Things like focal length, distortion of the lens, sensor parameters etc.&lt;/li&gt;&#xA;&lt;li&gt;Extrinsic parameters: Orientation of position of the camera.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;To robustly determine those from an image that contains labelled points you usually need more than one image. A typical way to do this is recording many images of a chessboard pattern. But as soon as you have determined all the intrinsic parameters, you could save those for future applications as they do not have to be estimated over and over again. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I recommend reading the introduction to camera calibration of openCV: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://docs.opencv.org/3.1.0/dc/dbb/tutorial_py_calibration.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.opencv.org/3.1.0/dc/dbb/tutorial_py_calibration.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://docs.opencv.org/3.1.0/d9/db7/tutorial_py_table_of_contents_calib3d.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.opencv.org/3.1.0/d9/db7/tutorial_py_table_of_contents_calib3d.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1981" LastActivityDate="2018-11-27T11:08:41.650" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8316" PostTypeId="1" AcceptedAnswerId="8361" CreationDate="2018-11-27T19:21:02.320" Score="5" ViewCount="174" Body="&lt;p&gt;While implementing the &quot;Artist Friendly Metallic Fresnel&quot; paper by Ole Gulbrandsen (&lt;a href=&quot;http://jcgt.org/published/0003/04/03/paper.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://jcgt.org/published/0003/04/03/paper.pdf&lt;/a&gt;), I read that it is fully reversible:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;(section 2.3.2): for all r,g ∈ (0,1), the map from (n, k) to (r,g) is a bijection&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;However, this doesn't seem to be the case? When converting (r, g) to (n, k) and back to (r, g), I do not get a matching output to my initial parameters. &lt;strong&gt;Is this expected?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;r: 0.7 0.55 0.075&#xA;g: 0.8 0.65 0.35&#xA;n: 2.39006 2.5479 1.44145&#xA;k: 4.98834 3.604 0.537046&#xA;r_check: 0.737183 0.601524 0.0773389&#xA;g_check: 0.827686 0.699977 0.35995&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is the implementation to verify, note that I only implemented &lt;code&gt;get_k()&lt;/code&gt;, the other functions were already supplied by the paper. &lt;code&gt;get_k()&lt;/code&gt; is derived from the following formula in the paper:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$k(r, n(r,g)) = \sqrt{ \frac {1}{1-r}(r(n(r,g)+1)^2 - (n(r,g) -1)^2)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;#include &amp;lt;cmath&amp;gt;&#xA;&#xA;float n_min(float r) {&#xA;  return (1.0-r)/(1.0+r);&#xA;}&#xA;&#xA;float n_max(float r) {&#xA;  return (1.0 + std::sqrt(r))/(1.0-std::sqrt(r));&#xA;}&#xA;&#xA;float get_n(float r, float g) {&#xA;  return g*n_min(r) + (1.0-g)*n_max(r);&#xA;}&#xA;&#xA;float get_k(float r, float n) {&#xA;  return std::sqrt( (1.0/(1.0-r)) * (r * std::pow(n+1.0, 2)) - std::pow(n-1.0, 2) );&#xA;}&#xA;&#xA;//float get_k2(float r, float n) {&#xA;//  float nr = (n+1.0)*(n+1.0)*r-(n-1.0)*(n-1.0);&#xA;//  return nr/(1.0-r);&#xA;//}&#xA;&#xA;float get_r(float n, float k) {&#xA;  return (std::pow(n-1.0, 2)+std::pow(k, 2)) / (std::pow(n+1.0, 2)+std::pow(k, 2));&#xA;}&#xA;&#xA;float get_g(float n, float k) {&#xA;  float r = get_r(n, k);&#xA;  return (n_max(r)-n)/(n_max(r)-n_min(r));&#xA;}&#xA;&#xA;&#xA;&#xA;int main() {&#xA;  std::vector&amp;lt;float&amp;gt; r = {0.7, 0.55, 0.075};&#xA;  std::vector&amp;lt;float&amp;gt; g = {0.8, 0.65, 0.35};&#xA;  std::cout &amp;lt;&amp;lt; &quot;r: &quot; &amp;lt;&amp;lt; r[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; r[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; r[2] &amp;lt;&amp;lt; std::endl;&#xA;  std::cout &amp;lt;&amp;lt; &quot;g: &quot; &amp;lt;&amp;lt; g[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; g[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; g[2] &amp;lt;&amp;lt; std::endl;&#xA;&#xA;&#xA;  std::vector&amp;lt;float&amp;gt; n(3);&#xA;  std::vector&amp;lt;float&amp;gt; k(3);&#xA;  for (int i = 0; i&amp;lt;3; i++) {&#xA;    n[i] = get_n(r[i], g[i]);&#xA;    k[i] = get_k(r[i], n[i]);&#xA;  }&#xA;  std::cout &amp;lt;&amp;lt; &quot;n: &quot; &amp;lt;&amp;lt; n[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; n[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; n[2] &amp;lt;&amp;lt; std::endl;&#xA;  std::cout &amp;lt;&amp;lt; &quot;k: &quot; &amp;lt;&amp;lt; k[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; k[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; k[2] &amp;lt;&amp;lt; std::endl;&#xA;&#xA;&#xA;  std::vector&amp;lt;float&amp;gt; r_check(3);&#xA;  std::vector&amp;lt;float&amp;gt; g_check(3);&#xA;  for (int i = 0; i&amp;lt;3; i++) {&#xA;    r_check[i] = get_r(n[i], k[i]);&#xA;    g_check[i] = get_g(n[i], k[i]);&#xA;  }&#xA;  std::cout &amp;lt;&amp;lt; &quot;r_check: &quot; &amp;lt;&amp;lt; r_check[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; r_check[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; r_check[2] &amp;lt;&amp;lt; std::endl;&#xA;  std::cout &amp;lt;&amp;lt; &quot;g_check: &quot; &amp;lt;&amp;lt; g_check[0] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; g_check[1] &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; g_check[2] &amp;lt;&amp;lt; std::endl;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9505" LastActivityDate="2018-12-04T19:54:07.357" Title="&quot;Artist Friendly Metallic Fresnel&quot; reversible?" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;shading&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8317" PostTypeId="1" AcceptedAnswerId="8323" CreationDate="2018-11-27T23:28:19.873" Score="1" ViewCount="5144" Body="&lt;p&gt;What measurement/monitoring tools could I use to get the FPS values for a simple Vulkan app?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2018-11-30T14:30:29.783" Title="FPS counter for a simple Vulkan app" Tags="&lt;vulkan&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8318" PostTypeId="2" ParentId="8317" CreationDate="2018-11-27T23:52:37.397" Score="6" Body="&lt;p&gt;You might want to try the VK_LAYER_LUNARG_monitor layer from the LunarG Vulkan SDK.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Download the SDK from the LunarXchange &lt;a href=&quot;https://vulkan.lunarg.com/&quot; rel=&quot;noreferrer&quot;&gt;site&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After SDK installation, you can activate the layer by setting this environment variable:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;VK_INSTANCE_LAYERS=VK_LAYER_LUNARG_monitor&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The monitor layer displays the FPS value in the application window's title bar.&lt;/p&gt;&#xA;" OwnerUserId="9762" LastEditorUserId="9762" LastEditDate="2018-11-30T14:30:29.783" LastActivityDate="2018-11-30T14:30:29.783" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8319" PostTypeId="1" AcceptedAnswerId="8336" CreationDate="2018-11-28T03:08:19.023" Score="2" ViewCount="1108" Body="&lt;p&gt;I have some existing OpenGL code that I am porting to Vulkan. The question is somewhat relevant to both OpenGL and Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am rendering some primitives using textures, some single channel, others RGBA, as well as flat colored primitives with per-vertex colors. The GL code that I am porting frequently switches shader programs with &lt;code&gt;glUseProgram&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Vulkan, using two distinct sets of shaders requires two pipelines created with &lt;code&gt;vkCreateGraphicsPipelines&lt;/code&gt; and later bound with &lt;code&gt;vkCmdBindPipeline&lt;/code&gt; plus &lt;code&gt;vkCmdBindDescriptorSets&lt;/code&gt;, thus changing shader programs equates program switches with graphics pipeline reconfiguration.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am wondering whether it is efficient to switch to a single shader program and hence a single graphics pipeline with a vertex layout that contains texture coordinates, a color, and texture sampler. When I want to draw flat colored objects, the code would set the color in the vertex and bind a 1x1 white sampler and when I want to render images the code can bind a full image. I currently render the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;flat color using color from vertex&lt;/li&gt;&#xA;&lt;li&gt;alpha from sampler and color from vertex&lt;/li&gt;&#xA;&lt;li&gt;RGBA from sampler and alpha from vertex &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The question is from a hardware, driver/performance perspective, is it more efficient to use a single pipeline and descriptor layout and only performing uniform updates and have a slightly larger Vertex, or is switching pipelines low enough cost to warrant two or three pipelines and two of three sets of shaders and different vertex formats. i.e. where is the best balance between these concerns?&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;three sets of shaders, three small vertex structs; program, uniform, and sampler switches&lt;/li&gt;&#xA;&lt;li&gt;one set of shaders, one slightly larger vertex struct and just uniform, and sampler switches&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;We could benchmark this but wonder if someone already has data to compare these approaches. I am aware of Ubershaders however this is hardly an Ubershader (see below) rather concerns any data on the ratio of program switch cost overhead versus the overhead of a 1x1 NOP texture lookups and texture color versus switching to a shader with no texture lookups.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With multiple shaders, the required program switches are likely to be in the order of 100's or possibly 1000's because of transparent content that requires a specific rendering order. In my case, it is for a &lt;em&gt;mostly&lt;/em&gt; 2D app with a mix of line/block/bezier art, fonts using single alpha channel texture atlas plus vertex color and finally, RGBA images, typically just using the vertex alpha value and all currently using an orthographic projection with no lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ideally, I would like data on pipeline/program switch cost versus descriptor set switch cost.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the shared program model, I am thinking about using the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the vertex struct:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex {&#xA;    glm::vec3 vertex;&#xA;    glm::vec2 texcoord;&#xA;    uint32_t color;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and this is the vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout (location = 0) in vec4 vcolor;&#xA;layout (location = 1) in vec2 vtexcoord;&#xA;&#xA;layout (binding = 1) uniform sampler2D tex;&#xA;&#xA;layout (location = 0) out vec4 outColor;&#xA;&#xA;void main()&#xA;{&#xA;    outColor = vcolor * texture(tex, vtexcoord);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and this is the fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout (location = 0) in vec3 vertex;&#xA;layout (location = 1) in vec2 texcoord;&#xA;layout (location = 2) in vec4 color;&#xA;&#xA;layout (binding = 0) uniform UBO &#xA;{&#xA;    mat4 modelViewProjection;&#xA;} ubo;&#xA;&#xA;layout (location = 0) out vec4 vcolor;&#xA;layout (location = 1) out vec2 vtexcoord;&#xA;&#xA;out gl_PerVertex &#xA;{&#xA;    vec4 gl_Position;&#xA;};&#xA;&#xA;void main()&#xA;{&#xA;    vcolor = color;&#xA;    vtexcoord = texcoord;&#xA;    gl_Position = ubo.modelViewProjection * vec4(vertex.xyz, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note: as pointed out in the comments, swizzle masks in &lt;code&gt;VkImageViewCreateInfo&lt;/code&gt; &lt;code&gt;components&lt;/code&gt; field can be used to create &lt;code&gt;VkImageView&lt;/code&gt; that translates the color and alpha channels instead of tieing shader code to the number of image channels in the sampler.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To broadcast the first color channel to all elements in OpenGL:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA,&#xA;    (GLint[]) { GL_RED, GL_RED, GL_RED, GL_RED } );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and for Vulkan, use the &lt;code&gt;VkImageViewCreateInfo&lt;/code&gt; &lt;code&gt;components&lt;/code&gt; field:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;VkImageViewCreateInfo imageViewInfo;&#xA;imageViewInfo.components = {&#xA;    VK_COMPONENT_SWIZZLE_R,&#xA;    VK_COMPONENT_SWIZZLE_R,&#xA;    VK_COMPONENT_SWIZZLE_R,&#xA;    VK_COMPONENT_SWIZZLE_R&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9763" LastEditorUserId="9763" LastEditDate="2018-12-03T19:55:43.970" LastActivityDate="2018-12-03T23:10:26.130" Title="Is a single shader and 1x1 pixel white sampler more efficient than frequent switching between shaders with and without samplers?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8320" PostTypeId="1" CreationDate="2018-11-28T06:58:19.127" Score="4" ViewCount="56" Body="&lt;p&gt;Although I have tried for a long time, I cannot understand Eq.(11) of paper &quot;Microfacet Models for Refraction through Rough Surfaces&quot; written by Bruce Walter, Stephen Marschner, Hongsong Li and Kenneth Torrance, Eurographics Symposium on Rendering(2007). My knowledge of change of variable is no more than what are described in this webpage: &lt;a href=&quot;http://tutorial.math.lamar.edu/Classes/CalcIII/ChangeOfVariables.aspx&quot; rel=&quot;noreferrer&quot;&gt;http://tutorial.math.lamar.edu/Classes/CalcIII/ChangeOfVariables.aspx&lt;/a&gt;. Because I am not a smart people, can you please help me understand how this equation is derived based on the knowledge of that webpage and in a way that a common human can follow? Specifically, one of the questions I cannot answer is: what is the variable to be changed and changed to, &lt;span class=&quot;math-container&quot;&gt;$\mathbf{i}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\mathbf{o}$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$\mathbf{m}$&lt;/span&gt;? The paper is famous so it can be easily found from Google search. For your convenience, I copied the pertaining page here. Thank you for your help.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UN5Uu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UN5Uu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4839" LastActivityDate="2018-11-28T06:58:19.127" Title="Ask for help on understanding a formula related to change of variable" Tags="&lt;brdf&gt;&lt;microfacet&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8321" PostTypeId="1" CreationDate="2018-11-28T07:40:19.993" Score="3" ViewCount="142" Body="&lt;p&gt;I cannot understand an algorithm which combines stratified sampling and importance sampling of Monte Carlo. It is introduced in Page 73 of a textbook &quot;Advanced Global Illumination&quot;, 2nd edition, written by Philip Dutre, Philippe Bekaert and Kavita Bala. The text gives almost no explanation on the algorithm so I got stuck at the line &lt;span class=&quot;math-container&quot;&gt;$N_i=\lfloor Pn+u\rfloor-N_{sum}$&lt;/span&gt;. I tried my best but I think I'm at my wit's end to figure out how this line or the whole psudo-code works. I just don't have any understanding. I read the text again and again and stared at Fig 3.9 above the algorithm for a long time but could not find any clue. Could you please give me an explanation of this algorithm in a way a common human can follow? For your convenience, I copied this section as follows. I know there is &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5480/an-example-of-combining-stratified-sampling-and-importance-sampling-in-agi&quot;&gt;another question thread&lt;/a&gt; but that question has not been answered and I think my post is more detailed so please do not merge mine to his.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot for your help.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ydkVN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ydkVN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/oDB4P.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oDB4P.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4839" LastActivityDate="2021-04-20T06:04:49.893" Title="Ask for help on understand an algorithm which combines stratified sampling and importance sampling of Monte Carlo" Tags="&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8322" PostTypeId="2" ParentId="8295" CreationDate="2018-11-28T09:53:33.253" Score="0" Body="&lt;p&gt;&lt;strong&gt;About screens:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Short answer: yes, it SHOULD, it would be nice. But the technology currently used does not make that possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The long answer: it's complicated. First, the signal that your computer sends to the screen is an electric signal. To make it easy to understand, take a look at this &lt;a href=&quot;https://electronics.stackexchange.com/questions/93078/soldering-a-vga-cable-number-of-wires-doesnt-match&quot;&gt;post about the old VGA connector&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The signal still contains R G and B channels, that's what lights your pixels in a given color. So to try to answer your question: the conversion from RGB electric signal to light (meaning radiance) depends on the screen, not on your PC. Different screens and brands behave differently, that's why they don't all look the same. The technology used for the pixels also matters: LED, LCD, cathodic, OLED, plasma... all behave in different ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The signal coming from your computer tells the screen the color and the intensity of each pixel. The intensity is transmitted using a &lt;a href=&quot;https://www.researchgate.net/figure/Two-measures-of-electrical-power-signals-for-LED-control-with-D-Type-flip-flop-register_fig6_224222964&quot; rel=&quot;nofollow noreferrer&quot;&gt;pulse&lt;/a&gt; (the leds blink fast enough so the human eye can't see it and the % of time it's on determines how bright it looks... to human eye). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if that was not the case, and the pixels were analogic, you would still send an electric signal: some ampères at a given voltage, in other words some watts. And that's why it's all about radiance: it's a &lt;a href=&quot;https://en.wikipedia.org/wiki/Radiance&quot; rel=&quot;nofollow noreferrer&quot;&gt;radiometric measure&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In simple words, your computer sends current to pixels. The way the current is transformed into light (meaning luminance) is related to the pixels technology, quality, age, heat: there are too many factors that are not under the screen's control. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Luminance vs Radiance:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(following your comment)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference is that when you speak about luminance, you need to take into consideration the spectrum of the light. RGB is not a good discretisation of the full spectrum, it's just 3 channels for the visible light and 0 for non-visible. When you speak about radiance, you're working with watts (energy): as shown f.ex. on this &lt;a href=&quot;https://socratic.org/questions/5348556b02bf347bedff8fed&quot; rel=&quot;nofollow noreferrer&quot;&gt;page&lt;/a&gt; &quot;short wavelenghts carry more energy&quot;. In other words, if you wanted to convert luminance to radiance you would need to know the light spectrum (a slope) and convert it into watts (a quantity - energy has no color, so to speak). But it is not feasible at the time of writing to render light sources that have a spectrum, all you can get is RGB... also because RGB is what screens are able to display.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The screens are calibrated so that (1,1,1) appears white, (x,x,x) appears as a gray shade and so on. This somehow compensates the fact that short wavelengths &lt;em&gt;have&lt;/em&gt; more energy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You probably understood: it's quite a mess. You can only get as near to physically based as the technology allows you (as pointed by Wyck in his comment). To do so, I can suggest you to read &lt;strong&gt;&lt;em&gt;&quot;Physically based rendering - From theory to implementation&quot; by M. Pharr and G. Humphreys&lt;/em&gt;&lt;/strong&gt; (The second edition ISBN: 978-0-12-375079-2 , I think there's also a third edition). It is unfortunately not feasible to go through all the aspects of the problem in an answer on StackExchange (moreover because I won't rewrite the 1000 pages with my own words, sorry). The book is definitely worth reading.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Last, but not least, in your comment you spoke about &quot;perceived light&quot;: you probably also want to read something about &lt;a href=&quot;https://en.wikipedia.org/wiki/Tone_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;tonemapping&lt;/a&gt; (a.k.a. the methods/algorithms to mimic the human eye perception of luminance). It really depends if you're trying to display lumiance or human perceived brightness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this helps you seeing how deep the rabbit hole is... up to you to decide how deep you want to go into it!&lt;/p&gt;&#xA;" OwnerUserId="9755" LastEditorUserId="9755" LastEditDate="2018-11-29T14:22:53.010" LastActivityDate="2018-11-29T14:22:53.010" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8323" PostTypeId="2" ParentId="8317" CreationDate="2018-11-28T18:59:14.363" Score="1" Body="&lt;p&gt;Try AMD's &lt;a href=&quot;https://github.com/GPUOpen-Tools/OCAT&quot; rel=&quot;nofollow noreferrer&quot;&gt;OCAT&lt;/a&gt; tool. It can overlay an FPS counter on a Vulkan or D3D12 app, similar to how FRAPS works for D3D11/OpenGL. (It should work on all Vulkan-supporting GPUs, btw, not just AMD ones.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-11-28T18:59:14.363" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8328" PostTypeId="1" AcceptedAnswerId="8329" CreationDate="2018-11-30T20:24:47.210" Score="4" ViewCount="927" Body="&lt;p&gt;I just wanted to find out for sure how GLSL code gets loaded and compiled. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does the g++ compiler do it? &lt;/p&gt;&#xA;" OwnerUserId="9778" LastEditorUserId="2654" LastEditDate="2018-12-03T16:56:04.370" LastActivityDate="2018-12-03T16:56:04.370" Title="How does GLSL code get “loaded” and “compiled”?" Tags="&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8329" PostTypeId="2" ParentId="8328" CreationDate="2018-11-30T22:56:30.067" Score="3" Body="&lt;p&gt;No, g++/gcc are not involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL (prior to Vulkan), GLSL code is submitted to the driver as source code strings via a &lt;a href=&quot;http://docs.gl/gl4/glShaderSource&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glShaderSource&lt;/code&gt;&lt;/a&gt; call. The driver is fully responsible for compilation, i.e. the driver must provide a built-in GLSL compiler for that GPU architecture. This would typically happen on startup of an app, or during level loading for a game.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With Vulkan, &lt;a href=&quot;https://en.wikipedia.org/wiki/Standard_Portable_Intermediate_Representation&quot; rel=&quot;nofollow noreferrer&quot;&gt;SPIR-V&lt;/a&gt; was introduced, which is a device-independent bytecode for shaders (vaguely based on &lt;a href=&quot;https://en.wikipedia.org/wiki/LLVM#Intermediate_representation&quot; rel=&quot;nofollow noreferrer&quot;&gt;LLVM IR&lt;/a&gt;). Now, GLSL code can be pre-compiled to SPIR-V offline using the &lt;a href=&quot;https://github.com/google/shaderc&quot; rel=&quot;nofollow noreferrer&quot;&gt;shaderc&lt;/a&gt; toolchain. The developers would do this ahead of time and ship the SPIR-V bytecode with their app. Then at runtime the SPIR-V gets submitted to the Vulkan driver and compiled the rest of the way to GPU machine code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's also possible to compile other languages to SPIR-V; for instance, Microsoft's &lt;a href=&quot;https://github.com/Microsoft/DirectXShaderCompiler&quot; rel=&quot;nofollow noreferrer&quot;&gt;dxc&lt;/a&gt; compiler for HLSL can optionally output SPIR-V, so you can use this to write Vulkan shaders in HLSL. Also, SPIR-V support has been backported to OpenGL 4.6, so you can now also &lt;a href=&quot;https://www.khronos.org/opengl/wiki/SPIR-V&quot; rel=&quot;nofollow noreferrer&quot;&gt;load precompiled SPIR-V shaders in OpenGL&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-11-30T22:56:30.067" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8333" PostTypeId="1" CreationDate="2018-12-01T20:32:05.020" Score="4" ViewCount="482" Body="&lt;p&gt;I'm new to computer graphics and just wanted a solid understanding of why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is it so important that polygons you push through the pipeline be &quot;&lt;strong&gt;simple&lt;/strong&gt;&quot; and &quot;&lt;strong&gt;convex&lt;/strong&gt;&quot;? &lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-05T19:00:08.230" Title="Why do polygons have to be &quot;simple&quot; and &quot;convex&quot;?" Tags="&lt;polygon&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8335" PostTypeId="2" ParentId="8321" CreationDate="2018-12-02T02:26:05.830" Score="0" Body="&lt;p&gt;It's difficult to parse, but here's my best understanding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case the goal is determine number of &lt;span class=&quot;math-container&quot;&gt;$N_i$&lt;/span&gt; out of &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; samples to distribute to each strata with probability given by the discrete pdf in &lt;span class=&quot;math-container&quot;&gt;$\{p_0, ..., p_n\}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The summation of &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt; += &lt;span class=&quot;math-container&quot;&gt;$p_i$&lt;/span&gt; is computing the CDF for &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe &quot;sample the ith term &lt;span class=&quot;math-container&quot;&gt;$N_i$&lt;/span&gt; times&quot; means to take a jittered sample within that strata using new random variables.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's take a small example where we have the pdf with 4 elements.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;PDF = \{0.2, 0.1, 0.6, 0.1\}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And it's corresponding cdf, each element corresponds to &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt; in the ith iteration in the pseudo code.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;CDF = \{0.2, 0.3, 0.9, 1.0\}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now given &lt;span class=&quot;math-container&quot;&gt;$\left \lfloor{P*n + u}\right \rfloor$&lt;/span&gt; we can illustrate for a few example cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With &lt;span class=&quot;math-container&quot;&gt;$u = 0$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\left \lfloor{P*n + u}\right \rfloor = \{0, 1, 3, 4\}&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;N_i = {0, 1, 2, 1}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With &lt;span class=&quot;math-container&quot;&gt;$u = 0.5$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\left \lfloor{P*n + u}\right \rfloor = \{1, 1, 4, 4\}&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;N_i = {1, 0, 3, 0}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With &lt;span class=&quot;math-container&quot;&gt;$u = 0.99$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\left \lfloor{P*n + u}\right \rfloor = \{1, 2, 4, 4\}&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;N_i = {1, 1, 2, 0}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Notice how for example &lt;span class=&quot;math-container&quot;&gt;$N_3$&lt;/span&gt; corresponds to a higher number of samples. When we now sample the 3rd element &lt;span class=&quot;math-container&quot;&gt;$N_3$&lt;/span&gt; times we are weighting that strata in proportion to its pdf.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I don't see any reason that the sample count has to be the same &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; as the # of discrete elements in the pdf.&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T02:26:05.830" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8336" PostTypeId="2" ParentId="8319" CreationDate="2018-12-02T02:40:51.407" Score="3" Body="&lt;p&gt;This is a really hardware-dependent question. But in general the best way to think about this is bottlenecks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You mentioned:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;one set of shaders, one &lt;strong&gt;slightly&lt;/strong&gt; larger vertex struct and just uniform, and sampler switches&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The slightly larger vertex struct doesn't seem like it will be the more likely bottleneck compared to:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;With multiple shaders, the required program switches are likely to be in the order of 100's or possibly 1000's &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;On modern desktop/console hardware each graphics pipe might have a single-digit # of active contexts. Switching the state too frequently is sometimes to referred to as a context roll stall.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case whether you hit that stall case is also dependent on how fast your shader and blend operations complete to make the context available. Given that you're going to do a lot of alpha blending, you might be bound by blending operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way modern GPUs are much better at dynamic branching, and skipping over fetches with a shader uniform is possible so you don't need to pay the additional memory reads. That said, a 1x1 dummy texture is going to be in the texture cache anyway so again it probably doesn't matter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd say try using a single shader first before you introduce new shader permutations. And in general, do the easiest implementation first, measure on your target hardware, then optimize :) &lt;/p&gt;&#xA;" OwnerUserId="1582" LastEditorUserId="506" LastEditDate="2018-12-03T23:10:26.130" LastActivityDate="2018-12-03T23:10:26.130" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8337" PostTypeId="2" ParentId="8295" CreationDate="2018-12-02T03:33:50.673" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;1, 1, 1, the output value is white. If this represents radiance than the output should be green, because when the signal radiance is the same, the pixel should be perceived as green. Am I correct?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is not correct. Your frame buffer most likely contains sRGB values. Of which 1,1,1 is used to represent white. Standard displays do not use spectral radiance values in the frame buffer. sRGB does not map directly or make any guarantees about the spectral power distribution (SPD) of the display. So &quot;G&quot; of 1 does not guarantee some wave with amplitude using W⋅sr−1⋅m−2 centered on the 550nm. Part of the problem is that different type of displays have different SPDs that map to the same perceived color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;[Evaluation of an organic light-emitting diode display for precise visual stimulation, Ito et. al]&#xA;(&lt;a href=&quot;https://jov.arvojournals.org/article.aspx?articleid=2121657&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://jov.arvojournals.org/article.aspx?articleid=2121657&lt;/a&gt;)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/GD4E2.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GD4E2.jpg&quot; alt=&quot;SPDs for different display types&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you want to physically accurate rendering, you could store all of your lighting values as Radiance with SPDs. As L.C. mentioned, Physically Based Rendering describes that this is done with piece-wise linear functions with like 16+ channels per color. However even if you can get this to be performant, good luck converting all your RGB data into SPDs (there's an infinite # of SPDs for a given RGB value).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead what most renderers try to do is to treat the RGB as pseudo-radiance values for the purposes of lighting calculation. This isn't accurate, hence your lighting result changes if you are using Rec.709 or Rec.2020 primaries for instance (if you notice they have different values for mapping to luminance), but it's good enough for real time and even offline in most cases. At this point you can convert RGB Rec709 and Rec2020 values to a single scalar luminance using the Y values of it's primaries.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Y values of the RGB primaries for Rec709 are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    R       G       B&#xA;Y   0.2126  0.7152  0.0722&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/SRGB&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus Rec709 Linear has the following nits conversion:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;nits = dot(linear709Rgb, float3(0.2126, 0.7152,0.0722));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Probably one of the results of doing our calculations in RGB is that G and B add at equal weights, so it's likely to get some color shifting. There was a presentation at SIGGRAPH 2015 from Weta digital that had some examples, but it doesn't seem like the slides are available. As far as I know they are the only ones using a spectral renderer.&lt;/p&gt;&#xA;" OwnerUserId="1582" LastEditorUserId="1582" LastEditDate="2018-12-04T07:44:53.527" LastActivityDate="2018-12-04T07:44:53.527" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8338" PostTypeId="2" ParentId="2365" CreationDate="2018-12-02T04:12:48.333" Score="2" Body="&lt;p&gt;Compute queues in general don't necessarily mean you can now do 2x dispatches in parallel. A single queue that fully saturates the compute units will have better throughput. Multiple queues are useful if one queue consumes less resources (shared memory or registers), then secondary queues can then overlap on the same compute unit. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For real-time rendering this is especially the case with things like shadow rendering that are very light on compute/shaders but heavy on fixed function hardware, thus freeing the GPU scheduler to run the secondary queue async.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also found this in the release notes. Don't know if it's the same issue, but could just be that CodeXL is not great. I would expect that it might have not have the best instrumentation for which dispatches are in flight.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.amd.com/wordpress/media/2013/02/AMD_CodeXL_Release_Notes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.amd.com/wordpress/media/2013/02/AMD_CodeXL_Release_Notes.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;For an application that performs simultaneous asynchronous data transfer and kernel execution,&#xA;  the timeline shown in the Application Trace session view will not show these operations being&#xA;  overlapped. This is because the driver and hardware force these operations to be synchronous&#xA;  while profiling. (333981)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T04:12:48.333" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8339" PostTypeId="1" CreationDate="2018-12-02T04:19:34.877" Score="0" ViewCount="206" Body="&lt;p&gt;I'm new to this forum and topic but wanted to figure out specifically how are normals assigned to vertices in &lt;strong&gt;flat shading, gouraud shading, and phong shading&lt;/strong&gt;? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a difference between any? &lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-02T07:59:55.460" Title="How are normals assigned to vertices in different types of shading?" Tags="&lt;shading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8340" PostTypeId="2" ParentId="8313" CreationDate="2018-12-02T04:22:03.387" Score="1" Body="&lt;p&gt;Deferred decals are a common way to achieve this without re-rendering the same geometry. It also allows you to change the appearance, i.e. add some gap or smooth out the details.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Draw a box around your height field, the size should be as tight as possible to avoid over draw. &lt;/li&gt;&#xA;&lt;li&gt;sample the depth buffer to get the world-space position of the current pixel (the height field / other geo)&lt;/li&gt;&#xA;&lt;li&gt;Project your box down in world space&lt;/li&gt;&#xA;&lt;li&gt;Use the projected box coordinate to sample from your overlay texture.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T04:22:03.387" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8341" PostTypeId="2" ParentId="8296" CreationDate="2018-12-02T04:36:05.500" Score="1" Body="&lt;p&gt;The code does seem a bit ugly since it doesn't assign pdf and instead returns 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By returning 0 it's basically saying the same thing as pdf = 0 because &lt;code&gt;f.IsBlack()&lt;/code&gt; returns true.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is acceptable, it's basically saying the BSDF doesn't allow light go through at the given &lt;span class=&quot;math-container&quot;&gt;$w_o$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T04:36:05.500" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8342" PostTypeId="2" ParentId="6359" CreationDate="2018-12-02T04:55:26.397" Score="1" Body="&lt;p&gt;A fragment shader executes for a 2D rasterized position. When you output the normalized position it's still being projected onto the 2D xy image plane onto a render target. The render target is 2D, so you can't use the fragment shader output to achieve this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You need to bind a 3D texture as a read/write texture in order to store values. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other thing is how you're expecting to voxelize the geometry, are you trying to voxelize the surfaces? If so you can use a pixel shader but you need to render all faces (disable back face culling).&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T04:55:26.397" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8343" PostTypeId="1" AcceptedAnswerId="8344" CreationDate="2018-12-02T06:32:29.193" Score="0" ViewCount="2467" Body="&lt;p&gt;In hidden surface removal, how does the Z-buffer algorithm work vs. painter's algorithm?&lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2019-03-22T08:40:16.513" Title="Z-Buffer algorithm vs Painter's algorithm?" Tags="&lt;algorithm&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8344" PostTypeId="2" ParentId="8343" CreationDate="2018-12-02T07:45:10.007" Score="3" Body="&lt;p&gt;In short painter's algorithm can't deal with intersecting geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose that you draw a plane angled away from the camera, and a plane angled towards the camera. The planes intersect in an 'X' shape.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Camera ------&amp;gt; X&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;With painter's algorithm no such ordering exists that will render the shape exactly. You would only see whichever plane you decided to draw last.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Z-Buffer or Depth-Buffer stores the nearest depth per each pixel relative from the camera. If another triangle is rasterized and has a depth less than the current depth buffer value it is accepted, if it's depth is greater, it is rejected. This is called a depth test.&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T07:45:10.007" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8345" PostTypeId="2" ParentId="8339" CreationDate="2018-12-02T07:59:55.460" Score="3" Body="&lt;p&gt;Flat shading uses the same normal for each vertex of the triangle. In this case the normal is constant, and one color is evaluated for the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For Gouraud and Phong shading normals are different per vertex and can represent a curved surface (even though the face is flat). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, for Gouraud shading is evaluated per vertex, and the resulting color is interpolated. For Phong, the normals are interpolated first and the shading is evaluated per pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note there's a bit of an overloaded term between the Phong Lighting/Reflection model and Phong Interpolation, Per-pixel shading which is what you're referring to here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given these 3 shading types, the next logical step is actually normal maps shading. This is basically where the normal is provided per pixel, and shading is evaluated per pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And so you have the trend of doing more calculation at finer details / higher resolution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a table!&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;                 Normal         |   Lighting&#xA;Flat:            Per Triangle   |   Per Triangle&#xA;Gouraud:         Per Vertex     |   Per Vertex&#xA;Phong:           Per Vertex     |   Per Pixel&#xA;Normal Mapping:  Per Pixel      |   Per Pixel&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2018-12-02T07:59:55.460" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8348" PostTypeId="1" AcceptedAnswerId="8356" CreationDate="2018-12-03T00:14:48.707" Score="0" ViewCount="3387" Body="&lt;p&gt;I know OpenGL likes the texel resolution of textures be some power of 2 in each direction because of &lt;strong&gt;mipmapping&lt;/strong&gt;. (They say that this is not a totally stringent condition, but it is preferred)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone explain what is mipmapping and what is it for?&lt;/p&gt;&#xA;" OwnerUserId="9778" LastEditorUserId="2654" LastEditDate="2018-12-03T16:53:54.570" LastActivityDate="2018-12-04T08:50:18.510" Title="What is mipmapping?" Tags="&lt;mapping&gt;&lt;mipmap&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8349" PostTypeId="1" AcceptedAnswerId="8350" CreationDate="2018-12-03T03:27:59.867" Score="-2" ViewCount="610" Body="&lt;p&gt;Can someone please explain what are the 3 types of light reflection from surfaces in the Phong Lighting Model? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe possibly using a diagram to help me understand it better? &lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-03T07:11:01.317" Title="What are the 3 types of light reflection from surfaces in the Phong Lighting Model?" Tags="&lt;lighting&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8350" PostTypeId="2" ParentId="8349" CreationDate="2018-12-03T07:11:01.317" Score="1" Body="&lt;p&gt;The three types you are referring to are specular, diffuse and ambient reflection.&#xA;I find the &lt;a href=&quot;https://upload.wikimedia.org/wikipedia/commons/6/6b/Phong_components_version_4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;example image on wikipedia&lt;/a&gt; to show the individual parts quite nicely:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CZEvi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CZEvi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First the ambient light is showing. This is not really a reflection, but more of a way to make up for global illumination in a cheap way. You simply assume that a small portion of light is always reaching every point on your object, no matter where that object is or how its positioned. Even when standing on the ground, the parts that touch the ground are lighted here. Because the light is the same everywhere, you can't even tell if it is a 3D object or just a drawing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next is the diffuse reflection. This is an approximation of light that enters your object, bounces around a bit and leaves the object again. Naturally, more light reaches surfaces that are angled &quot;towards&quot; the light, this is why in the image you can see shadows in the left pointing parts but increasingly more light on the right pointing parts. Due to the bouncing within the object, the exit direction of the light is somewhat random, therefore no concentrated highlights are created.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Highlights you can see are the specular reflection in the third image. Specular reflection is that part of light, that reaches the object and immedeately bounces of it again. Thereby it keeps most of the light (from the same light source) directed into more or less the same direction, thus the highlights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last part of the image is everything combined, giving you a nice and cheap approximation of real light.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-12-03T07:11:01.317" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8352" PostTypeId="2" ParentId="8333" CreationDate="2018-12-03T16:53:31.577" Score="5" Body="&lt;p&gt;Polygon rasterization (the conversion of the analog polygon data into a &lt;a href=&quot;https://en.wikipedia.org/wiki/Raster_graphics&quot; rel=&quot;nofollow noreferrer&quot;&gt;raster image&lt;/a&gt;) is a key operation in rasterization-based rendering. As such, performing this operation fast, and with predictable performance, is key to the performance of graphics rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is possible to rasterize any arbitrary polygon. But rasterizing triangles is extremely simple to code and offers numerous efficiency improvements over general polygon rasterization.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Triangle rasterization is done by something called &quot;scan conversion&quot;: you break the triangle up into a series of horizontal scan-lines (one pixel tall) of a length determined by the sides of the triangle. Building these scan-lines and getting their lengths is something you can do through basic integer math involving only additions and multiplications. Furthermore, each scan-line can be constructed &lt;em&gt;independently&lt;/em&gt; of the others, so highly threaded hardware can be employed to perform this process efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;None of this is true for arbitrary polygons. Concave polygons in particular require much more complex math. A concave polygon can have multiple lines in the same horizontal row.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, interpolation of values across the surface of a triangle can be done by relatively simple math. For each scanline, you can compute a gradient that represents how much each value changes from one end of the line to the other. So given a starting value at one line, you can easily compute the interpolated position at any point on the scanline simply by multiplication and addition. If you're computing them in sequence, you don't even need the multiplication; successive addition is adequate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Interpolation of values across an arbitrary polygonal surface is much more complicated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given all of these advantages, and the fact that you can use a series of triangles to build any arbitrary polygon, there's really no reason to rasterize any more complex shape.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2018-12-05T19:00:08.230" LastActivityDate="2018-12-05T19:00:08.230" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8353" PostTypeId="1" AcceptedAnswerId="8355" CreationDate="2018-12-03T17:52:54.367" Score="0" ViewCount="208" Body="&lt;p&gt;How does the Modified Phong lighting model also known as the Blinn-Phong differ from the Phong Lighting Model? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I distinguish the two?&lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-03T18:36:23.487" Title="How does the Modified Phong Lighting Model from the Phong Lighting Model?" Tags="&lt;lighting&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8354" PostTypeId="1" AcceptedAnswerId="8370" CreationDate="2018-12-03T18:02:02.823" Score="0" ViewCount="387" Body="&lt;p&gt;If I try to read the screen with &lt;code&gt;glreadpixels&lt;/code&gt; and then draw the same thing again using &lt;code&gt;gldrawpixels&lt;/code&gt; it works, BUT if and only if I use anything else to draw than &lt;code&gt;gldrawarrays&lt;/code&gt; and &lt;code&gt;gldrawelements&lt;/code&gt; (&lt;code&gt;gluSphere/gluCylinder&lt;/code&gt; work just fine). I'm trying to draw an object to the screen and save the pixels in an array. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried reading/writing to front/back buffers, reading after I swap buffers, all to no avail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;here is the code that I use to draw the object: (please note that I do not use any kind of buffers outside of this scope).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; void CCssample5View::DrawCylinder(Model obj)&#xA;    {&#xA;    GLuint VertexArrayID;&#xA;    glGenVertexArrays(1, &amp;amp;VertexArrayID);&#xA;    glBindVertexArray(VertexArrayID);&#xA;&#xA;    Shader castingShader(&quot;casting.vs&quot;, &quot;casting.fs&quot;);&#xA;    Shader lightShader(&quot;light.vs&quot;, &quot;light.fs&quot;);&#xA;&#xA;    GLuint MatrixID = glGetUniformLocation(castingShader.ID, &quot;MVP&quot;);&#xA;    GLuint ViewMatrixID = glGetUniformLocation(castingShader.ID, &quot;V&quot;);&#xA;    GLuint ModelMatrixID = glGetUniformLocation(castingShader.ID, &quot;M&quot;);&#xA;&#xA;    GLuint textur = loadBMP_custom(&quot;flower.bmp&quot;);&#xA;    GLuint TextureID = glGetUniformLocation(castingShader.ID , &quot;myTextureSampler&quot;);&#xA;&#xA;&#xA;    indexVBO(obj.vertices, obj.uvs, obj.normals, obj.indices, obj.indexed_vertices, obj.indexed_uvs, obj.indexed_normals);&#xA;&#xA;    GLuint vertexbuffer;&#xA;    glGenBuffers(1, &amp;amp;vertexbuffer);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);&#xA;    glBufferData(GL_ARRAY_BUFFER, obj.indexed_vertices.size() * sizeof(glm::vec3), &amp;amp;obj.indexed_vertices[0], GL_STATIC_DRAW);&#xA;&#xA;    GLuint uvbuffer;&#xA;    glGenBuffers(1, &amp;amp;uvbuffer);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);&#xA;    glBufferData(GL_ARRAY_BUFFER, obj.indexed_uvs.size() * sizeof(glm::vec2), &amp;amp;obj.indexed_uvs[0], GL_STATIC_DRAW);&#xA;&#xA;    GLuint normalbuffer;&#xA;    glGenBuffers(1, &amp;amp;normalbuffer);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);&#xA;    glBufferData(GL_ARRAY_BUFFER, obj.indexed_normals.size() * sizeof(glm::vec3), &amp;amp;obj.indexed_normals[0], GL_STATIC_DRAW);&#xA;&#xA;    GLuint elementbuffer;&#xA;    glGenBuffers(1, &amp;amp;elementbuffer);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, obj.indices.size() * sizeof(unsigned short), &amp;amp;obj.indices[0], GL_STATIC_DRAW);&#xA;&#xA;&#xA;&#xA;    castingShader.use();&#xA;&#xA;    GLuint LightID = glGetUniformLocation(castingShader.ID, &quot;LightPosition_worldspace&quot;);&#xA;    computeMatricesFromInputs();&#xA;    GLfloat gProjectionMatrix[16];&#xA;    glGetFloatv(GL_PROJECTION_MATRIX, gProjectionMatrix);&#xA;    glm::mat4 ProjectionMatrix = glm::make_mat4(gProjectionMatrix);// = glm::mat4(gProjectionMatrix);   &#xA;&#xA;    GLfloat gViewMatrix[16];&#xA;    glGetFloatv(GL_MODELVIEW_MATRIX, gViewMatrix);&#xA;    glm::mat4 ViewMatrix = glm::make_mat4(gViewMatrix);// = glm::mat4(gProjectionMatrix);&#xA;&#xA;    glm::vec3 lightPos = glm::vec3(4, 4, 4);&#xA;    glUniform3f(LightID, lightPos.x, lightPos.y, lightPos.z);&#xA;    glUniformMatrix4fv(ViewMatrixID, 1, GL_FALSE, &amp;amp;ViewMatrix[0][0]);&#xA;&#xA;    glm::mat4 ModelMatrix1 = glm::mat4(1.0);&#xA;    glm::mat4 MVP1 = ProjectionMatrix * ViewMatrix * ModelMatrix1;&#xA;&#xA;&#xA;    glActiveTexture(GL_TEXTURE0);&#xA;    glBindTexture(GL_TEXTURE_2D, textur);&#xA;&#xA;    glUniform1i(TextureID, 0);&#xA;    // Send our transformation to the currently bound shader, &#xA;    // in the &quot;MVP&quot; uniform&#xA;    glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &amp;amp;MVP1[0][0]);&#xA;    glUniformMatrix4fv(ModelMatrixID, 1, GL_FALSE, &amp;amp;ModelMatrix1[0][0]);&#xA;    glEnableVertexAttribArray(0);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);&#xA;    glVertexAttribPointer(&#xA;        0,                  // attribute&#xA;        3,                  // size&#xA;        GL_FLOAT,           // type&#xA;        GL_FALSE,           // normalized?&#xA;        0,                  // stride&#xA;        (void*)0            // array buffer offset&#xA;    );&#xA;&#xA;    // 2nd attribute buffer : UVs&#xA;    glEnableVertexAttribArray(1);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);&#xA;    glVertexAttribPointer(&#xA;        1,                                // attribute&#xA;        2,                                // size&#xA;        GL_FLOAT,                         // type&#xA;        GL_FALSE,                         // normalized?&#xA;        0,                                // stride&#xA;        (void*)0                          // array buffer offset&#xA;    );&#xA;&#xA;    // 3rd attribute buffer : normals&#xA;    glEnableVertexAttribArray(2);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, normalbuffer);&#xA;    glVertexAttribPointer(&#xA;        2,                                // attribute&#xA;        3,                                // size&#xA;        GL_FLOAT,                         // type&#xA;        GL_FALSE,                         // normalized?&#xA;        0,                                // stride&#xA;        (void*)0                          // array buffer offset&#xA;    );&#xA;&#xA;    // Index buffer&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer);&#xA;&#xA;    // Draw the triangles !&#xA;    glDrawElements(&#xA;        GL_TRIANGLES,      // mode&#xA;        obj.indices.size(),    // count&#xA;        GL_UNSIGNED_SHORT,   // type&#xA;        (void*)0           // element array buffer offset&#xA;    );&#xA;&#xA;    //glFlush(); glFinish(); readScreen(screen, GL_RGB, true);&#xA;&#xA;    glDisableVertexAttribArray(0);&#xA;    glDisableVertexAttribArray(1);&#xA;    glDisableVertexAttribArray(2);&#xA;&#xA;    glDeleteBuffers(1, &amp;amp;vertexbuffer);&#xA;    glDeleteBuffers(1, &amp;amp;uvbuffer);&#xA;    glDeleteBuffers(1, &amp;amp;normalbuffer);&#xA;    glDeleteBuffers(1, &amp;amp;elementbuffer);&#xA;    glDeleteProgram(castingShader.ID);&#xA;    glDeleteTextures(1, &amp;amp;textur);&#xA;    glDeleteVertexArrays(1, &amp;amp;VertexArrayID);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;These are my read and draw screen functions:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void CCssample5View::readScreen(GLubyte* screen, GLenum format, bool back)&#xA;{&#xA;    check();&#xA;&#xA;&#xA;    if (format == GL_RGB) {&#xA;&#xA;&#xA;        check();&#xA;        if (back) {&#xA;            glReadBuffer(GL_BACK);&#xA;            check();&#xA;        }&#xA;        else {&#xA;            glReadBuffer(GL_FRONT);&#xA;            check();&#xA;        }&#xA;&#xA;    }&#xA;    //glRasterPos2i(00, 00);&#xA;    //glDisable(GL_DEPTH_TEST);&#xA;    glPixelStorei(GL_PACK_ALIGNMENT, 1);&#xA;    glReadPixels(0, 0, w, h, format, GL_UNSIGNED_BYTE, screen);&#xA;&#xA;&#xA;    glFlush();&#xA;    glFinish();&#xA;    bool found = false;&#xA;    for (size_t u = 0; u &amp;lt;= w * h * 4; u++) {&#xA;        if (screen[u] != 0) {&#xA;            found = true;&#xA;            break;&#xA;        }&#xA;    }&#xA;    assert(found);&#xA;    check();&#xA;&#xA;&#xA;}&#xA;void CCssample5View::drawScreen(GLubyte *screen, GLenum format, bool back)&#xA;{&#xA;&#xA;&#xA;    glClear(GL_COLOR_BUFFER_BIT);&#xA;    //glGetIntegerv(GL_CURRENT_RASTER_POSITION, rasterpos);&#xA;    if (back) {&#xA;        glDrawBuffer(GL_BACK);&#xA;    }&#xA;    else {&#xA;        glDrawBuffer(GL_FRONT);&#xA;    }    &#xA;&#xA;    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);&#xA;    glDrawPixels(w, h, format, GL_UNSIGNED_BYTE, screen);&#xA;    check();&#xA;&#xA;    glFlush();&#xA;    glFinish();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Can not seem to figure out whats wrong when the drawing is perfect except the reading screen part..&lt;/p&gt;&#xA;" OwnerUserId="9789" LastActivityDate="2018-12-06T17:09:57.663" Title="Why is glreadpixels only working in certain cases?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8355" PostTypeId="2" ParentId="8353" CreationDate="2018-12-03T18:36:23.487" Score="1" Body="&lt;p&gt;The Phong lighting model computes the specular response as the dot product between the mirror reflection direction and the viewing direction, raised to a power.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if &lt;span class=&quot;math-container&quot;&gt;$\vec{V}$&lt;/span&gt; is the viewing direction, &lt;span class=&quot;math-container&quot;&gt;$\vec{L}$&lt;/span&gt; the incoming light direction and &lt;span class=&quot;math-container&quot;&gt;$\vec{R}$&lt;/span&gt; the perfect specular reflection direction for &lt;span class=&quot;math-container&quot;&gt;$\vec{L}$&lt;/span&gt;, then the specular response is &lt;span class=&quot;math-container&quot;&gt;$\text{max}(\vec{V}.\vec{R},0)^p$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is the exponent that controls the fall-off of the specular response. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Blinn-Phong model uses a half vector &lt;span class=&quot;math-container&quot;&gt;$\vec{H}$&lt;/span&gt;, which is computed as &lt;span class=&quot;math-container&quot;&gt;$\vec{H} = \frac{\vec{L}+\vec{V}}{|\vec{L}+\vec{V}|}$&lt;/span&gt;, which is then used to compute the specular response as &lt;span class=&quot;math-container&quot;&gt;$\text{max}(\vec{H}.\vec{N},0)^p$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\vec{N}$&lt;/span&gt; is the surface normal. The idea is that when the eye vector &lt;span class=&quot;math-container&quot;&gt;$\vec{V}$&lt;/span&gt; is aligned perfectly with the perfect mirror direction &lt;span class=&quot;math-container&quot;&gt;$\vec{R}$&lt;/span&gt;, the half vector &lt;span class=&quot;math-container&quot;&gt;$\vec{H}$&lt;/span&gt; would be exactly aligned with the surface normal &lt;span class=&quot;math-container&quot;&gt;$\vec{N}$&lt;/span&gt;. Hence the Blinn-Phong can get away with computing an expensive mirror direction &lt;span class=&quot;math-container&quot;&gt;$\vec{R}$&lt;/span&gt; everytime by using the half vector which can model the specular response.&lt;/p&gt;&#xA;" OwnerUserId="1940" LastActivityDate="2018-12-03T18:36:23.487" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8356" PostTypeId="2" ParentId="8348" CreationDate="2018-12-04T08:50:18.510" Score="1" Body="&lt;p&gt;Mipmapping is a pre-computed texture scheme that tries to solve the problem of texturemap aliasing. When a screen pixel from a textured polygon covers many texture pixels, the pixel should be sampled more than only once (nearest neighbor or bilinearly) to get a &quot;correct&quot; average color. So instead of having a regular texture a mipmap is created. The mipmap level is chosen from the objects distance to the camera, and can be per pixel, per object, bi- or trilinearly interpolated, etc. Mipmapping in its nature does not take perspective projection into account.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 1-channel mipmap texture usually is divided into four parts, holding Red, Green, Blue in the first three, while the last is divided into four parts, holding the downsampled 2x2 average of R, G and B, and so on recursively until a pres-elected depth. I'm sure google has pictures of this.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-12-04T08:50:18.510" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8358" PostTypeId="1" AcceptedAnswerId="8363" CreationDate="2018-12-04T14:50:13.060" Score="0" ViewCount="90" Body="&lt;p&gt;I have an application where I simulate a camera distortion. There are two ways to go about it: calculate the distortion per pixel in the shader or precalculate the distortion and store the distortion as a 2D texture. In either case I first render the undistorted image, then calculate different texture coordinates in a new render pass for every pixel and thus read from the original image at a different position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the latter case I store tex coords, meaning that for my texture coordinate &lt;span class=&quot;math-container&quot;&gt;$(u_d, v_d)$&lt;/span&gt; in the shader I read out the texture coordinate &lt;span class=&quot;math-container&quot;&gt;$(u, v)$&lt;/span&gt; and thus have a distortion from the original point &lt;span class=&quot;math-container&quot;&gt;$(u, v)$&lt;/span&gt; to my distorted point &lt;span class=&quot;math-container&quot;&gt;$(u_d, v_d)$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can set up my distortion to have no distortion at all (i.e. &lt;span class=&quot;math-container&quot;&gt;$(u, v) = (u_d, v_d)$&lt;/span&gt;). This works fine when I calculate the distortion in the shader, but if I precalculate the distortion and store my new tex coords, read them out in the shader and then apply that &quot;distortion&quot;, I get a somewhat blurry image. I have checked my texture with the new texture coordinates, but they seem to store exactly what I want them to (basically their own position).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the same excerpt from my results, first with the shader calculated distortion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ty5aj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ty5aj.png&quot; alt=&quot;Distortion calculation done in the shader&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then with the precalculated distortion and blurry result:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M3IkC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M3IkC.png&quot; alt=&quot;Distortion precalculated and new texture coordinates read in the shader&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm a bit at a loss as to why I get this blurry image now, especially when there is actually no offset between the original and the distorted tex coords.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The texture is using &lt;code&gt;GL_FLOAT&lt;/code&gt; as the data type and &lt;code&gt;GL_RG32F&lt;/code&gt; as the internal format, I don't use mip mapping and the image is usually non power of 2 and non square (e.g. in this case 1920*1079), the prerendered image has the same size as my precalculated texture coordinate texture. This effect occurs with filtering set to &lt;code&gt;GL_LINEAR&lt;/code&gt; as well as set to &lt;code&gt;GL_NEAREST&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Edit2&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have managed to reproduce the problem in a more minimal example, excluding any distortion calculations.&#xA;That is, in OpenSceneGraph I have two cameras, one (&lt;code&gt;rttCamera&lt;/code&gt;) rendering a scene into a texture and one (&lt;code&gt;displayCamera&lt;/code&gt;) rendering this texture to the framebuffer. I precalculate a texture which stores texture coordinates, but basically they should return the same texture coordinates at every pixel as the geometry of the screen quad does:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; res[0]; i++)&#xA;{&#xA;    for (int j = 0; j &amp;lt; res[1]; j++)&#xA;    {&#xA;        reinterpret_cast&amp;lt;float*&amp;gt;(img-&amp;gt;data(i, j))[0] = i / res[0];&#xA;        reinterpret_cast&amp;lt;float*&amp;gt;(img-&amp;gt;data(i, j))[1] = j / res[1];&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;img-&amp;gt;data&lt;/code&gt; is the buffer for the texture, &lt;code&gt;i, j&lt;/code&gt; are the pixel coordinates, &lt;code&gt;res&lt;/code&gt; stores the resolution (1920 * 1080 in this case). The texture itself is again &lt;code&gt;GL_RG32F&lt;/code&gt; with data type &lt;code&gt;GL_FLOAT&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fragment shader code for the &lt;code&gt;displayCamera&lt;/code&gt;is the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 400&#xA;&#xA;uniform sampler2D uRenderedImage;&#xA;uniform sampler2D uTexCoordLut;&#xA;&#xA;uniform bool uIsLutUsed;&#xA;&#xA;in vec2 vTexCoord;&#xA;out vec4 gl_FragColor;&#xA;&#xA;void main()&#xA;{&#xA;    vec2 texCoord = texture(uTexCoordLut, vTexCoord).rg;&#xA;    // gl_FragColor = vec4(texCoord, 0, 1);&#xA;    gl_FragColor = texture(uRenderedImage, vTexCoord);&#xA;    if(uIsLutUsed)&#xA;    {&#xA;        gl_FragColor = texture(uRenderedImage, texCoord);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where the boolean uniform is for me to switch between the geometry texcoord version and my precalculated texcoord version.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The resulting images are the following (again cropped), first the version without the precalculated texture coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F4db8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F4db8.png&quot; alt=&quot;Using the geometry texture coordinates&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and then the version with precalculated texture coordinates&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/czNSb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/czNSb.png&quot; alt=&quot;Using the precalculated texture coordinates&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Edit3&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried around a bit, and I found one solution (although that doesn't answer my question of 'why').&#xA;Currently my prerendered image and my 2D texture that stores my new texture coordinates both have the same resolution. However, in my minimal example from Edit2, if keep the prerendered image at 1920*1080 pixel and increase the texture with my precalculated coordinates to 10000*10000, the difference between precalculated texture coordinates and geoemtry texture coordinates (or the rendered image with said coordinates) is minimal, barely noticable at all.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2018-12-05T13:22:31.863" LastActivityDate="2018-12-05T14:39:41.607" Title="Why is precalculating a distortion different from calculating it in the shader?" Tags="&lt;texture&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8359" PostTypeId="1" CreationDate="2018-12-04T16:47:36.467" Score="1" ViewCount="201" Body="&lt;p&gt;Does anyone know any method to remove ghosting in volumetric lighting? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When light move it leaves trail behind, i would like to remove it.&#xA;Volumetrics are Bart Wronski style (in frustum) with exponential temporal accumulation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried neighborhood clamp, Karis and variance clipping, both remove ghosting but also introduce other artifacts.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2019-10-03T05:00:37.680" Title="Ghosting in volumetric lighting" Tags="&lt;lighting&gt;&lt;artifacts&gt;&lt;volumetric&gt;&lt;fog&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8360" PostTypeId="2" ParentId="8359" CreationDate="2018-12-04T18:22:55.713" Score="1" Body="&lt;p&gt;Temporal by definition will ghost. I’d limit past frame sampling, apply weight &amp;lt; 0.5, limit movement etc. &lt;/p&gt;&#xA;" OwnerUserId="5385" LastActivityDate="2018-12-04T18:22:55.713" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8361" PostTypeId="2" ParentId="8316" CreationDate="2018-12-04T19:54:07.357" Score="4" Body="&lt;p&gt;I wasn't really expecting that, no. The formula in the paper is not the most elegant - there's quite a few parentheses in there. In this case I think it's just a matter of shuffling the parentheses around a little in the get_k implementation - both terms should be divided by &lt;code&gt;(1-r)&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    float get_k(float r, float n) {&#xA;        return std::sqrt( 1.0/(1.0-r) * ( r*std::pow(n+1.0, 2) - std::pow(n-1.0, 2) ));&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9800" LastActivityDate="2018-12-04T19:54:07.357" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8362" PostTypeId="2" ParentId="8358" CreationDate="2018-12-05T11:23:09.617" Score="0" Body="&lt;p&gt;It's a bit hard to tell with the images, but I assume the whole viewport is distorted?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first thought is that there is a difference between the 2 distortion computation methods which might not be obvious. A good first debugging step would be to output only &lt;span class=&quot;math-container&quot;&gt;$(u_d, v_d)$&lt;/span&gt; as a color with the two methods. This will allow isolating (or not) the problem to this computation since this is likely where the problem is. If this is the problem, it will be much easier to reason about and debug with all other factors removed from the final image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you add a (simplified) version of your distortion computation shader and the matching texture generation code?&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2018-12-05T11:23:09.617" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8363" PostTypeId="2" ParentId="8358" CreationDate="2018-12-05T14:39:41.607" Score="1" Body="&lt;p&gt;I finally found the problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My precalculation was done with pixel coordinates from &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;res[0] - 1&lt;/code&gt; (i.e. the resolution width):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; res[0]; i++)&#xA;{&#xA;    for (int j = 0; j &amp;lt; res[1]; j++)&#xA;    {&#xA;        reinterpret_cast&amp;lt;float*&amp;gt;(img-&amp;gt;data(i, j))[0] = i / res[0];&#xA;        reinterpret_cast&amp;lt;float*&amp;gt;(img-&amp;gt;data(i, j))[1] = j / res[1];&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, pixels in OpenGL are accessed via their center, as can be read &lt;a href=&quot;https://stackoverflow.com/questions/5879403/opengl-texture-coordinates-in-pixel-space&quot;&gt;in another SO answer&lt;/a&gt; or &lt;a href=&quot;http://www.realtimerendering.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;in Real-Time Rendering (3rd and 4th Edition, p.21)&lt;/a&gt;. Meaning, that if I have a pixel with 0 as its left border and 0.1 as its right border, then 0.05 is its center.&#xA;That means in my case, I have to offset the precalculated texture coordinate by half a pixel to read out of my prerendered image:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; res[0]; i++)&#xA;{&#xA;    for (int j = 0; j &amp;lt; res[1]; j++)&#xA;    {&#xA;        reinterpret_cast&amp;lt;float*&amp;gt;(img-&amp;gt;data(i, j))[0] = i / res[0] + 0.5 * pixelWidth;&#xA;        reinterpret_cast&amp;lt;float*&amp;gt;(img-&amp;gt;data(i, j))[1] = j / res[1] + 0.5 * pixelHeight;&#xA;    }&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2018-12-05T14:39:41.607" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8364" PostTypeId="1" AcceptedAnswerId="8397" CreationDate="2018-12-05T18:27:17.267" Score="9" ViewCount="1546" Body="&lt;p&gt;When reading papers I commonly find Oct tree implementations of geometry representations to sort the data. However whenever I think about the problem hash tables seem better overall.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hash tables have a better average and worse case scenarios for most applications:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example for ray tracing an oct tree, near misses will cause you to iterate through a binary tree substructure, which is O(nlogn) whereas the hash table is O(n).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hash tables are easier to generate in the GPU, as they do not require any logical position in memory other than their hash position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most advantages tree structures have over hash tables do not seem to hold on the GPU either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In graphics we don't like re-allocating memory so we usually over allocate memory in VRAM just to be able to reuse a data structure. So the property binary trees have (being memory efficient) doesn't seem very relevant for GPU applications.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Data coherence for caching doesn't seem to hold either. For a GPU generated tree, asynchronicity makes it very difficult to guarantee that logically close values also get stored close to one another in the underlying memory. So you will end up jumping around pointers anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is also much easier to enforce certain GPU friendly heuristics in a hash table than in a tree. For example limiting the number of hash lookups to a fixed number, say 20 and using the same logic to prevent warps from executing different branch code. in essence you can always check the 20 potential collisions and just interpolate the result with the cell containing the key. In a tree the traversal through the data structure is a lot more dependent on the data itself and less on the data structure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So why are oct trees used so much more than hash tables?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-12-19T18:09:04.513" Title="Why are oct trees so much more common than hash tables?" Tags="&lt;shader&gt;&lt;algorithm&gt;&lt;gpu&gt;&lt;geometry&gt;&lt;data-structure&gt;" AnswerCount="2" CommentCount="6" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8367" PostTypeId="2" ParentId="8364" CreationDate="2018-12-05T23:28:46.143" Score="9" Body="&lt;p&gt;Lots of things here.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&quot;When reading papers&quot;. What papers? If the topic of the paper is about something other than the spatial partitioning structure, it could be fair to use whatever knowing that the basic ideas will translate to other structures. Or not, hard to say.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&quot;For example for ray tracing an oct tree, near misses will cause you to iterate through a binary tree substructure, which is O(nlogn) whereas the hash table is O(n)&quot;. Big O notation means nothing at all in this context. You are dealing with a particular technology at a particular scale when you talk about things that depend on implementation details. An O(nlogn) algorithm might be much slower than an O(n) one for the &quot;n&quot; that is realistic today, it happens all the times. And while you might say, in 10 years that might change, sure, that might be the case, but in the same 10 years your GPU might look completely different and thus the state of the art algorithms need to change regardless. That's common, if you look at GPU algorithms (and GPUs specifically are still evolving quite a bit)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What octree? What hash table? There are lots of choices there. For example &quot;...as they do not require any logical position in memory other than their hash position&quot;. That's true only if you have no hash collisions, yes? If you have collisions then whatever strategy you use (probing or linked lists) you'll need to synchronize between threads, so the build is not so easy to implement on a GPU. Conversely, for octrees if you wanted to &quot;overallocate&quot; as you suggest then you could allocate a full tree, and indexing would then be equally only dependent on position. In fact, if you do some math you can see that in such cases octrees become just a way to swizzle a grid (e.g. compare the van Ende Boas layout with a grid in Morton order... nice exercise).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There are lots of other things I could say, but let me cut to the chase here.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;For raytracing specifically, neither Octrees nor Hash tables are -that- popular. BVHs of AABBs are the way to go.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The main benefit of Octrees over hashed grid is that your cell resolution adapts to the geometry. Grids won't, you have to chose a cell size and that might be too small in certain parts of the scene and too big in certain others.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;There are a -lot- of variants and a -lot- of implementation details. Naive octrees should probably never be used in practice as they are too deep / not wide enough. If you make an octree &quot;larger&quot; by having say, a 4x4x4 grid with 4x4x4 grids nested in each non-empty cells, you create what it's called a hierarchical grid. So grids and octrees exist on a spectrum, where octrees are the most &quot;deep&quot;, grids are the most &quot;shallow&quot; (just one level, a single grid globally in the scene), and hierarchical grids can trade between the two&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;This might help! &lt;a href=&quot;http://www.realtimerendering.com/Real-Time_Rendering_4th-Real-Time_Ray_Tracing.pdf&quot; rel=&quot;noreferrer&quot;&gt;http://www.realtimerendering.com/Real-Time_Rendering_4th-Real-Time_Ray_Tracing.pdf&lt;/a&gt; ;)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9809" LastActivityDate="2018-12-05T23:28:46.143" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8368" PostTypeId="1" AcceptedAnswerId="8369" CreationDate="2018-12-06T03:45:37.850" Score="2" ViewCount="43" Body="&lt;p&gt;In Cohen-Sutherland clipping, it assigns outcodes to the points on lines that are drawn to specify their orientation relative to the clipping window. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the diagram below, I'm confused on what outcodes that would be assigned to p1, p2, p3, p4? Can someone explain?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7oXm7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7oXm7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-06T06:43:25.410" Title="What are the outcodes that would be assigned to these points?" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8369" PostTypeId="2" ParentId="8368" CreationDate="2018-12-06T06:43:25.410" Score="2" Body="&lt;p&gt;The diagram on the &lt;a href=&quot;https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia entry for Cohen-Sutherland Clipping&lt;/a&gt; explains it pretty well:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        left    central right&#xA;top     1001    1000    1010&#xA;central 0001    0000    0010&#xA;bottom  0101    0100    0110&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So in your example, &lt;code&gt;p1&lt;/code&gt; would be left, central, so its code  would be 0001.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;p2&lt;/code&gt; would be central, bottom, so 0100&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;p3&lt;/code&gt; would  be  central, central, so 0000&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;p4&lt;/code&gt; would be central, top, so 1000&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-12-06T06:43:25.410" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8370" PostTypeId="2" ParentId="8354" CreationDate="2018-12-06T17:09:57.663" Score="0" Body="&lt;p&gt;I figured it out. All I had to do was add &lt;code&gt;glUseProgram(0)&lt;/code&gt; at the very end of the draw cylinder function. After more than 3 weeks of looking into this.&lt;/p&gt;&#xA;" OwnerUserId="9789" LastActivityDate="2018-12-06T17:09:57.663" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8371" PostTypeId="1" AcceptedAnswerId="8372" CreationDate="2018-12-07T06:22:43.013" Score="1" ViewCount="194" Body="&lt;p&gt;In line drawing, bresenham's algorithm was explicitly derived for lines with slopes between 0 and 1 in the first octant from point P1 to point P2, where the x value of P1 is less than that for P2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the incremental version of this algorithm, once a pixel is drawn, we need to choose the next pixel to draw. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the choices? How do we go about choosing which pixel to draw next? (assuming a line width of 1 pixel)&lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-07T08:07:09.833" Title="Bresenham's algorithm next pixel?" Tags="&lt;algorithm&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8372" PostTypeId="2" ParentId="8371" CreationDate="2018-12-07T08:07:09.833" Score="1" Body="&lt;p&gt;Well, for the first octant you can either step EAST or NORTH-EAST. Depending on the distance to the actual line you choose the appropriate. In many integer &lt;a href=&quot;https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;implementations&lt;/a&gt;, this is done with regard to the sign of D.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-12-07T08:07:09.833" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8373" PostTypeId="1" AcceptedAnswerId="8375" CreationDate="2018-12-07T12:39:54.153" Score="1" ViewCount="1065" Body="&lt;p&gt;I was following this tutorial on Vulkan &lt;a href=&quot;https://vulkan-tutorial.com/Vertex_buffers/Staging_buffer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://vulkan-tutorial.com/Vertex_buffers/Staging_buffer&lt;/a&gt; and I decided to do this bit:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The buffer copy command requires a queue family that supports transfer operations, which is indicated using VK_QUEUE_TRANSFER_BIT. The good news is that any queue family with VK_QUEUE_GRAPHICS_BIT or VK_QUEUE_COMPUTE_BIT capabilities already implicitly support VK_QUEUE_TRANSFER_BIT operations.&lt;/p&gt;&#xA;&lt;p&gt;The implementation is not required to explicitly list it in queueFlags in those cases.&#xA;If you like a challenge, then you can still try to use a different queue family specifically for transfer operations. It will require you to make the following modifications to your program:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Modify QueueFamilyIndices and findQueueFamilies to explicitly look for a queue family with the VK_QUEUE_TRANSFER bit, but not the VK_QUEUE_GRAPHICS_BIT.&lt;/li&gt;&#xA;&lt;li&gt;Modify createLogicalDevice to request a handle to the transfer queue&lt;/li&gt;&#xA;&lt;li&gt;Create a second command pool for command buffers that are submitted on the transfer queue family&lt;/li&gt;&#xA;&lt;li&gt;Change the sharingMode of resources to be VK_SHARING_MODE_CONCURRENT and specify both the graphics and transfer queue families&lt;/li&gt;&#xA;&lt;li&gt;Submit any transfer commands like vkCmdCopyBuffer (which we'll be using in this chapter) to the transfer queue instead of the graphics queue&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;It's a bit of work, but it'll teach you a lot about how resources are shared between queue families.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Are there any benefits of using a second queue only for transfer operations ?&lt;/p&gt;&#xA;" OwnerUserId="8454" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2018-12-07T20:01:06.580" Title="Do I need separate Graphics and Transfer commands?" Tags="&lt;c++&gt;&lt;gpu&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8374" PostTypeId="1" AcceptedAnswerId="8376" CreationDate="2018-12-07T14:55:20.440" Score="4" ViewCount="295" Body="&lt;p&gt;I have seen people using either vertices or triangles as a quick heuristic to estimate mesh memory usage and mesh rendering time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I always thought vertices were better, because the number of vertices processed in the vertex shader is known, whereas the number of fragments rendered varies depending on depth complexity, distance to the screen, area of the triangles....&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However it seems triangles are used just as often as vertices, if you need one to do a naive estimation, which one is better?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2018-12-09T13:07:03.310" Title="Should you measure mesh complexity in triangles or vertices?" Tags="&lt;geometry&gt;&lt;mesh&gt;&lt;performance&gt;&lt;memory&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8375" PostTypeId="2" ParentId="8373" CreationDate="2018-12-07T15:09:39.367" Score="0" Body="&lt;p&gt;Your question seems... very confused. The &quot;challenge&quot; you tried to do specifically stated to &quot;use a different queue family specifically for transfer operations&quot;. But that's not what your code is trying to do; you used the same queue family.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The point of creating a &quot;transfer queue&quot; is to allow you to perform transfer operations without having to submit them as part of another batch. &lt;code&gt;vkQueueSubmit&lt;/code&gt; cannot be called on the same queue from multiple threads. So if one thread builds some transfer work, but the other thread is doing some graphics work, if you only have one queue then the two threads &lt;em&gt;must&lt;/em&gt; have some communication mechanism to submit that work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have a transfer queue, that inter-thread communication is no longer necessary. Or at least, it is no longer necessary for the basic submission action. Obviously whichever batch of work that uses the results of the transfer commands will have to receive a semaphore to wait on from the thread that submitted the transfer work. But that is usually a less contentious inter-thread communication path, which can easily be done with a lockless queue of some kind.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The challenge in question is specifically talking about a queue family that only has the &lt;code&gt;VK_QUEUE_TRANSFER_BIT&lt;/code&gt; flag set (or more specifically, does not have graphics or compute capabilities). Such transfer-only queues are usually tied to specialized hardware that (potentially) perform transfers faster than a graphics queue, but likely with extra limitations (as defined in &lt;code&gt;VkQueueFamilyProperties::minImageTransferGranularity&lt;/code&gt; and other properties).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So basically, you're doing the challenge wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do keep in mind that Vulkan does not require implementations to provide a transfer-only queue. So if you want to take advantage of the presence of such a queue, you also have to take into account the possibility that no such queue exists.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, here's the thing: the term &quot;queue family&quot; is used because you can potentially get &lt;em&gt;multiple&lt;/em&gt; queues from the same family. &lt;code&gt;VkQueueFamilyProperties::queueCount&lt;/code&gt; tells you how many queues a particular family allows you to get.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if a GPU does not provide a dedicated transfer-only queue, but you still want the asynchronous benefits of submitting transfer operations outside of non-transfer work, you can create a second graphics queue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, Vulkan &lt;em&gt;also&lt;/em&gt; doesn't require implementations to provide more than one graphics or compute queue. So again, you have to have a synchronous fallback plan in case the hardware only provides you with one queue.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-12-07T15:09:39.367" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8376" PostTypeId="2" ParentId="8374" CreationDate="2018-12-07T16:10:31.380" Score="3" Body="&lt;p&gt;Vertex count may be more accurate of a measurement of &quot;mesh memory usage and mesh rendering time&quot;, but vertex count is not nearly as easily &lt;em&gt;measured&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Yes, given a specific mesh with all of its attributes, it's easy to tell how many vertices are in it. But how many modelling tools can tell an artist how many vertices a given mesh will produce?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After all, the vertex count is usually based on the &lt;em&gt;topology&lt;/em&gt; of the various attributes of a mesh. That topology changes when new positions are added or removed. That topology changes when texture coordinate vertices are added or removed. When smoothing groups are modified to create sharp edges. And so forth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, most modelling tools can't really give an accurate vertex count anyway, since they usually don't store vertices in the fashion that the rendering application will use them in. They tend to store the vertices as individual arrays with individual array indices, which is typically not how the renderer will see them. So most modelling packages cannot tell the user what the vertex count is, outside of writing a plugin to provide that information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if you're trying to communicate a limitation to artists, the easiest way to give them an approximation of what they have to work with is to provide a triangle count. Yes, the hard limit is the number of vertices, and the asset conditioning pipeline should certainly reject meshes/whatever that are too big for the available memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But triangle count is more useful as a &quot;quick heuristic&quot; than vertex count.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-12-07T16:10:31.380" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8377" PostTypeId="2" ParentId="8374" CreationDate="2018-12-07T16:15:10.033" Score="4" Body="&lt;p&gt;Since you're talking about &quot;vertex shaders&quot; and &quot;fragments&quot;, I assume that your question is to be interpreted in the context of real-time rendering using the graphics pipeline on a modern GPU through some modern graphics API. Even if we narrow down the question like that, I don't think a general answer can be given to what you're asking. It depends a lot on what kind of meshes/scenes/application you're dealing with. In general, it's not even clear what &quot;number of vertices&quot; or &quot;number of triangles&quot; should mean exactly. There isn't really &lt;em&gt;the&lt;/em&gt; number of vertices and &lt;em&gt;the&lt;/em&gt; number of triangles. If you're rendering a non-indexed triangle strip, then there's a direct relation between the number of vertices and the number of triangles. If you're rendering an indexed triangle list, then do we count the number of vertices that were referenced, the number of vertices that were shaded, or do we count the number of indices that were used to form triangles? If you're rendering patches with tessellation, then is the number of vertices the number of control points or is it the number of vertices produced by the tessellation? What if I have a geometry shader that eats a few points, and turns them into loads of overlapping triangles? What if my geometry shading streams the odd triangle to a stream output buffer but doesn't send anything to the rasterizer at all!? The point is, there's a great many different places in a graphics pipeline where something that one might call a &quot;vertex&quot; or a &quot;triangle&quot; could pop up…&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a typical triangle mesh that is supposed to represent the boundary surface of some physical object, there will be a &lt;a href=&quot;https://math.stackexchange.com/questions/425968/eulers-formula-for-triangle-mesh&quot;&gt;direct relationship&lt;/a&gt; between the numbers of vertices and triangles. In such cases, either the number of vertices or the number of triangles is arguably as good a measure as the other when it comes to giving an estimate of mesh complexity. But then, what &quot;complexity&quot; are we talking about exactly? Complexity in terms of storage can probably be estimated from either number of vertices or triangles as explained above. Complexity in terms of rendering time is a whole different story. Depending on your application, it might be that neither the number of triangles nor the number of vertices is a good predictor for performance at all. It's actually trivial to write a program that makes even the latest and greatest graphics card sweat by rendering only a single triangle using no vertex buffer. Because your bottleneck is rasterization, fragment processing, or the framebuffer, for example. In such a case, you'd probably be more interested in the number of fragments produced, or the depth complexity…&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2018-12-09T13:07:03.310" LastActivityDate="2018-12-09T13:07:03.310" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8378" PostTypeId="1" AcceptedAnswerId="8380" CreationDate="2018-12-07T20:37:16.447" Score="3" ViewCount="276" Body="&lt;p&gt;In what way is a &quot;cheat&quot; when using smooth shading on a sphere approximation? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Y3eQ0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y3eQ0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not understanding how it's a cheat to use smooth shading on this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other questions that are lead after this may be: &#xA;Why does it look better than the Gouraud Shaded Model and why is this not necessary generally applicable to any surface?&lt;/p&gt;&#xA;" OwnerUserId="9778" LastActivityDate="2018-12-10T04:45:48.070" Title="Smooth shading on sphere approximation" Tags="&lt;shading&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8380" PostTypeId="2" ParentId="8378" CreationDate="2018-12-08T09:29:41.833" Score="3" Body="&lt;p&gt;Sphere's don't have edges like the ones in that picture. The &quot;silhouette&quot; should be a circle. This is because the sphere was rendered as triangles and rasterized. Triangles can only approximate a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compare this to ray casting for instance. Where we can directly test the intersection between a sphere and ray thus no need to approximate a sphere with other primitives.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What smooth shading lets us do is interpolate values across the face of a triangle to cheat and make something appear smoother. In reality a sphere (a uv sphere) would look like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/e3mf0.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e3mf0.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two common ways to make the above sphere look smooth without adding anymore geometry. Both of which involve linearly interpolating values across the face of a triangle. Like barycentric interpolation. With barycentric interpolation, given values at 3 points (on a triangle) and a point we want to know the value for we can calculate a mix between the 3 values at the corners such that it smoothly varies across the face of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vqX5e.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vqX5e.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In rasterization there are two popular ways to smooth shade. The later being used more often.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gouraud: We calculate the post-lighting (shaded) color at each vertex and interpolate the color across the face of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Phong: We calculate the shaded color at every pixel across the triangle, interpolating things like normals across the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: The difference between gouraud and phong is that gouraud assumes the color and light intensity change linearly with the normal. Whereas phong does not. For a simple light intensity = dot(normal, lightDir) = cos(angle between normal and lightDir) we can see the relationship between intensity and the normal is nonlinear. This can be well illustrated with the below image (see the seams on the specular highlight. This is the consequence of our linear interpolation):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2qmpn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2qmpn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2018-12-10T04:45:48.070" LastActivityDate="2018-12-10T04:45:48.070" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8381" PostTypeId="1" AcceptedAnswerId="8383" CreationDate="2018-12-09T11:48:44.637" Score="1" ViewCount="418" Body="&lt;p&gt;I was recently told &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8311/how-do-i-create-a-win32-window-with-a-vulkan-context&quot;&gt;here&lt;/a&gt; how to manage the integration between Vulkan and Win32.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am writing a windowing library like &quot;GLFW&quot;, that is only going to support Vulkan; I have now come to the point where I need to implement &lt;code&gt;SwapBuffers(Window)&lt;/code&gt; type of function; I have tried to reverse engineer Glfw's &lt;code&gt;glfwSwapBuffers(GLFWWindow*)&lt;/code&gt; function to see how they implemented it in their framework, but I wasn't able to understand it fully.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I &quot;swap the buffers&quot; in a Win32 window?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S: The library is written in C&lt;/p&gt;&#xA;" OwnerUserId="9436" LastEditorUserId="9436" LastEditDate="2018-12-09T13:00:30.603" LastActivityDate="2018-12-09T14:46:35.987" Title="How do I swap the buffers when using a Win32 window with Vulkan?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8382" PostTypeId="1" AcceptedAnswerId="8384" CreationDate="2018-12-09T13:34:20.380" Score="2" ViewCount="799" Body="&lt;p&gt;I am trying to convert a ray hit on an infinite plane, defined by an origin and a normal vector, into UV coordinates, so I can find the appropriate texel at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Code I have is close to functional, however, when the plane has a normal of (0, 0, -1) the result is a plain white plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code that calculates the UV coordinates is pasted below:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Calculate UV coordinates for the texture&#xA;vec3 u = vec3( normal.y, -normal.x, 0 ).normalized();&#xA;vec3 v = normal.cross( u );&#xA;&#xA;h.u = u.dot( h.coordinates );&#xA;h.v = v.dot( h.coordinates );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;h is a Hit struct that stores relevant data from a ray-primitive intersection, coordinates is the vec3 where the intersection occurred.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The current situation is shown in the following image; The floor plane properly shows the texture, however, the back wall does not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mhRdL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mhRdL.png&quot; alt=&quot;Example of current situation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when I change the normal of the back wall ever so slightly, the texture appears&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IH1kH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IH1kH.png&quot; alt=&quot;Situation with slightly changed normal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In image 1 the normal of the back plane was (0, 0, -1), while it was (0.0001, 0, -1) in the second image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have been trying to figure this one out, but I am hitting a dead end.&lt;/p&gt;&#xA;" OwnerUserId="9820" LastActivityDate="2018-12-09T16:59:28.967" Title="How do I convert a hit on an infinite plane to UV coordinates for texturing in a Raytracer?" Tags="&lt;raytracing&gt;&lt;texture&gt;&lt;uv-mapping&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8383" PostTypeId="2" ParentId="8381" CreationDate="2018-12-09T14:46:35.987" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I have now come to the point where I need to implement SwapBuffers(Window) type of function&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Then stop doing that. You need that function in OpenGL because the windowing code is explicitly not part of OpenGL, so to write cross-platform GL code, you need an encapsulation layer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is &lt;em&gt;not&lt;/em&gt; the case for Vulkan. While you still need a layer to &lt;em&gt;create&lt;/em&gt; the window, handling the display, swap-chain images, and so forth is all &lt;em&gt;part&lt;/em&gt; of the Vulkan API. The user's code should have complete and total control over this stuff; your abstraction layer need not be involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Indeed, since Vulkan has no concept of a &quot;default framebuffer&quot;, there's no way for you to abstract away presentable images without user support. Just do what GLFW3 does in &lt;a href=&quot;https://www.glfw.org/docs/latest/group__vulkan.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;its Vulkan support&lt;/a&gt;: provide a cross-platform way for the user to create a Vulkan surface.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2018-12-09T14:46:35.987" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8384" PostTypeId="2" ParentId="8382" CreationDate="2018-12-09T16:45:50.090" Score="5" Body="&lt;p&gt;If your plane has a normal of &lt;span class=&quot;math-container&quot;&gt;$\begin{pmatrix}0 &amp;amp; 0 &amp;amp; z\end{pmatrix}^T$&lt;/span&gt;, then your computation&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 u = vec3( normal.y, -normal.x, 0 ).normalized();&#xA;vec3 v = normal.cross( u );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;will result in &lt;code&gt;u&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt; both being &lt;span class=&quot;math-container&quot;&gt;$\begin{pmatrix}0 &amp;amp; 0 &amp;amp; 0\end{pmatrix}^T$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A more general approach would be, for example, to compute the cross product of your normal with each of the three base vectors and use whichever result happens to be the longest as your direction for &lt;code&gt;u&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 computePrimaryTexDir(vec3 normal)&#xA;{&#xA;    vec3 a = cross(normal, vec3(1, 0, 0));&#xA;    vec3 b = cross(normal, vec3(0, 1, 0));&#xA;&#xA;    vec3 max_ab = dot(a, a) &amp;lt; dot(b, b) ? b : a;&#xA;&#xA;    vec3 c = cross(normal, vec3(0, 0, 1));&#xA;&#xA;    return normalize(dot(max_ab, max_ab) &amp;lt; dot(c, c) ? c : max_ab);&#xA;}&#xA;&#xA;  …&#xA;&#xA;    vec3 u = computePrimaryTexDir(normal);&#xA;    vec3 v = cross(n, u);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2018-12-09T16:59:28.967" LastActivityDate="2018-12-09T16:59:28.967" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8385" PostTypeId="1" AcceptedAnswerId="8386" CreationDate="2018-12-09T23:01:43.887" Score="2" ViewCount="115" Body="&lt;p&gt;I'm looking for a way to make my surface semitransparent, and for now i ended up using this configuration:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;eglChooseConfig(eglDisplay, new int[] {&#xA;            EGL10.EGL_ALPHA_SIZE,   8,&#xA;            EGL10.EGL_RED_SIZE,     8,&#xA;            EGL10.EGL_GREEN_SIZE,   8,&#xA;            EGL10.EGL_BLUE_SIZE,    8,&#xA;            EGL10.EGL_NONE&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My default configuration was:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;eglChooseConfig(eglDisplay, new int[] {&#xA;            EGL10.EGL_RED_SIZE,     8,&#xA;            EGL10.EGL_GREEN_SIZE,   8,&#xA;            EGL10.EGL_BLUE_SIZE,    8,&#xA;            EGL10.EGL_DEPTH_SIZE    16,&#xA;            EGL10.EGL_NONE&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can see, i added EGL_ALPHA_SIZE attribute and removed EGL_DEPTH_SIZE, since my application is a simple 2D drawing on a surface and it doesn't need a depth buffer. It works, but for some reason results in somewhat unexpected results for this simple fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;uniform sampler2D uSampler;&#xA;varying vec2 vTextureCoord;&#xA;void main() {&#xA;    vec4 originalColor = texture2D(uSampler, vTextureCoord);&#xA;    gl_FragColor = originalColor + vec4(0, 0, 0, -0.5);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The alpha component seems to be affecting rest of the parts of the color and changes it at some extent. The first image below is the original one, second is what I have, and the last one is what I want to achieve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FigTB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FigTB.png&quot; alt=&quot;Original image&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/A6Pmq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A6Pmq.png&quot; alt=&quot;What i have&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/WQwMt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WQwMt.png&quot; alt=&quot;What i want to achieve&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any advice is appreciated, thanks!&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;For the sake of clarity&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;OpenGL ES Version: 2.0&lt;/p&gt;&#xA;" OwnerUserId="9697" LastActivityDate="2018-12-10T06:28:04.183" Title="Alpha component in color buffer affects RGB components?" Tags="&lt;glsl&gt;&lt;opengl-es&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8386" PostTypeId="2" ParentId="8385" CreationDate="2018-12-10T06:28:04.183" Score="2" Body="&lt;p&gt;It looks like you're drawing with pre-multiplied alpha. This means that the red, green, and blue channels have been multiplied by the alpha channel. So your shader should look more like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;uniform sampler2D uSampler;&#xA;varying vec2 vTextureCoord;&#xA;void main() {&#xA;    vec4 originalColor = texture2D(uSampler, vTextureCoord);&#xA;    vec4 tempColor = originalColor + vec4(0, 0, 0, -0.5);&#xA;    tempColor.rgb *=  tempColor.a;&#xA;    gl_FragColor = tempColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I believe you also need to set &lt;code&gt;glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA)&lt;/code&gt; to get the correct blending (and of course, &lt;code&gt;glEnable(GL_BLEND)&lt;/code&gt;).&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-12-10T06:28:04.183" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8387" PostTypeId="1" AcceptedAnswerId="8400" CreationDate="2018-12-10T07:31:16.820" Score="3" ViewCount="533" Body="&lt;p&gt;I've read about Lagrangian and Eulerian fluid simulations and here's what I take from their methods:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Lagrangian - Simulating fluid particles by calculating displacement for each particle&lt;/li&gt;&#xA;&lt;li&gt;Eulerian - Simulating fluid particles by calculating interactions between finite spaces containing group of fluid particles.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;(?) Do each method have different rendering technique suitable for it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My guess is that you can take the finite space or 'voxel' data for Eulerian simulation, but I would like an expert's say in my hypothesis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(?) Also regarding MPM (Material Point Method) which is a hybrid of both worlds, if Lagrangian and Eulerian sims &lt;strong&gt;does&lt;/strong&gt; have different rendering technique, does it mean that I can use either techniques? &lt;/p&gt;&#xA;" OwnerUserId="9822" LastActivityDate="2018-12-18T08:01:33.587" Title="Rendering Fluid Simulations?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;fluid-sim&gt;&lt;theory&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8389" PostTypeId="1" AcceptedAnswerId="8390" CreationDate="2018-12-10T19:43:14.067" Score="6" ViewCount="125" Body="&lt;p&gt;I'd like to create a GUI in my first Unity-game (2D). I want my GUI appear sharp in all resolutions (e.g. 1920x1200 or 3840x2160).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I am facing now is that I don't know if I should save my bitmap-images of my GUI in the highest resolution (so that it scales down when my game is played with a lower resolution) or should I use SVGs instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This may be a stupid question but it's the first time that I create a GUI in Unity and I'm really struggling with this kind of problem...&lt;/p&gt;&#xA;" OwnerUserId="9825" LastActivityDate="2018-12-12T09:03:39.260" Title="Bitmap-images or SVG" Tags="&lt;image&gt;&lt;unity&gt;&lt;bitmap-graphics&gt;&lt;gui&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8390" PostTypeId="2" ParentId="8389" CreationDate="2018-12-10T20:46:33.053" Score="7" Body="&lt;p&gt;Neither of your suggestions is a solution for crisp 2D graphics at all resolutions. SVGs are great and infinitely scalable, but since you don't know where the pixel boundaries will lie in the final render, you can't get crisp edges at all resolutions. For example, say your GUI is a red box on a green background. If the edge between the red and the green falls in the middle of a pixel, and the SVG renderer does anti-aliasing, you'll get a row or column of half-red, half-green pixels, which will look like mush. If the renderer doesn't anti-alias, you instead get the edge in the wrong place, which might be fine for a single rectangle, but for a repeating pattern each instance of the pattern might come out a different width, which is just as noticeable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Downscaling a bitmap to the display resolution is just as bad. Again, imagine your green-red edge is on a pixel boundary that will not be a pixel boundary in the downscaled bitmap. You're again going to get a row or column of pixels that are a mushy red-green mix. The lowest resolutions are the most important to have crisp edges, but they're going to be the worst-affected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can make either one of these techniques work somewhat, if you can accept a restriction: instead of handling &lt;em&gt;any&lt;/em&gt; resolution, you're willing to handle a set of resolutions, ideally powers of two apart (e.g. icon sizes of 512x512, 256x256, 128x128, etc.) When you're designing your UI, draw a large bitmap (512x512) or a vector image, but use guides in your editor to show the minimum size (e.g. 64x64). Make sure all your important edges line up with those guides, but you can still use curves, gradients etc. That way, you know you won't get the blurry mush at low resolutions, but you can still get the benefit of smooth diagonals and curves at high resolutions. This is a quick way to design scalable UI.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mobile OSes (which are designed for a range of screen dpis) use a similar technique, but with two differences. First, they &quot;bucket&quot; the screen's actual dpi to the nearest &quot;standard&quot; dpi. This means a UI might show slightly larger or smaller on different screens, but you know exactly how many pixels will be in each icon or widget. To make this work out, they don't limit the resolutions to powers of two, but have some intermediate ones as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, they let designers specify a different bitmap for each resolution. This means that you can make a higher-detail design for a higher-dpi screen, without it being too busy on a low-dpi screen. (For example, you can use a fine checkerboard or ruler pattern, and have it show up correctly at each resolution.) You could consider doing this too, but it makes designing and managing the bitmap assets a little more time-consuming.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your buckets are powers of two apart, you can use mipmaps to store the images (instead of using the built-in mipmap generation), whether you're creating different images for each resolution or just downscaling. That way you avoid the runtime memory bandwidth cost of downscaling.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2018-12-10T20:46:33.053" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8392" PostTypeId="1" CreationDate="2018-12-11T16:58:24.220" Score="3" ViewCount="112" Body="&lt;p&gt;I have created a closed 3D mesh using a parametric function. The shape is constructed by taking an arbitrary closed b-spline and scaling it based on one of the parameters (similar idea to a parametric sphere, except that rather than drawing circles it's a b-spline)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My current problem is, although I can generate the geometry of the shape just fine, it often results in thin triangles for many shapes. And these thin triangles in turn lead to numerical errors when trying to compute the normal to the triangles that make up the shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An easy way to avoid having thin triangles is just to just increase the number of samples you do along the parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g you can do 20 calculation steps along both u and v, or you can do 100.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More samples usually leads to thicker triangles in almost every parametric shape.&#xA;The issue of doing it this way is that I also increase the triangle and vertex count.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming I cannot modify the mesh once it is generated, is there a way to sample the parametrization such that I can get thicker triangles with few samples?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2018-12-12T15:35:39.527" LastActivityDate="2018-12-12T15:35:39.527" Title="How can you avoid thin triangles in a parametric shape in a smart way?" Tags="&lt;mathematics&gt;&lt;geometry&gt;&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="8395" PostTypeId="1" CreationDate="2018-12-13T13:22:47.690" Score="-2" ViewCount="342" Body="&lt;p&gt;I have to draw cubes with faces of different colors (each per face), but I don't know how to accomplish this task: I draw cubes using CPU and GPU meshes (no vertexBuffer or three.js &quot;style&quot;) and I don't know how to assign to each vertex different colors (I don't even know if this is possible).&#xA;I can upload my code to GitHub if my problem isn't clear enough, let me know.&#xA;All of this is coded in JavaScript and WebGL.&lt;/p&gt;&#xA;" OwnerUserId="9844" LastActivityDate="2018-12-14T09:26:59.430" Title="How can I make a cube with faces of different colors? Webgl" Tags="&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8396" PostTypeId="2" ParentId="8395" CreationDate="2018-12-14T09:26:59.430" Score="-2" Body="&lt;p&gt;There are many tutorials covering this - Google is your friend. Maybe &lt;a href=&quot;https://jameshfisher.com/2017/10/21/webgl-cube.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; covers your demands?&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2018-12-14T09:26:59.430" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8397" PostTypeId="2" ParentId="8364" CreationDate="2018-12-14T21:13:45.380" Score="5" Body="&lt;p&gt;My 2 cents from writting the Chipmunk2D physics engine is that spatial hashing is great when you have a lot of objects that are all the same size. I had a demo 10 years ago that ran with 20k interacting particles on a Core 2 Duo in real time. The spatial hash worked great for that &lt;em&gt;if you tuned it&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've since replaced the spatial hash with a binary AABB tree as the the default structure. It's far from perfect, but it was faster than the spatial hash in the average case &lt;em&gt;with no tuning&lt;/em&gt;. It also was easier to add a temporal component to it so I could incrementally update a set of potential collisions. With all of that in place, the &lt;em&gt;only&lt;/em&gt; test I had that ran faster with the spatial hash were the ones with thousands of particles and no static geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for octrees... Meh, I never use them. Basic quad/octrees don't really fit real data as well as the plethora of other BVHs you can use. Basic AABB trees are nearly as simple, and &lt;em&gt;way&lt;/em&gt; more effective.&lt;/p&gt;&#xA;" OwnerUserId="9853" LastEditorUserId="9853" LastEditDate="2019-12-19T18:09:04.513" LastActivityDate="2019-12-19T18:09:04.513" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8398" PostTypeId="1" AcceptedAnswerId="8407" CreationDate="2018-12-15T15:27:51.600" Score="2" ViewCount="1290" Body="&lt;p&gt;I had a z-fighting/z-clipping issue with a scene containing some very large objects yesterday in 3ds max. It can be seen in the image below:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/byoar.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/byoar.png&quot; alt=&quot;z-fighting issue&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For some reason downscaling the scene significantly (a factor of 100 approx) resolves the z-fighting issues... &lt;strong&gt;Please help me understand how reducing scene scale could resolve this issue and why this issue only occurs with very large scenes/objects.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what i understand z-fighting occurs in this case because the near and far planes are very far apart compared to the minimum and maximum distance of the rendered object(s) relative to the viewport. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please correct me if I'm wrong, &lt;strong&gt;my basic understanding of the z-buffer is as follows:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; The distance of each rendered pixel of the object(s) is compared to a standard value stored in the z-buffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; if the depth of the current pixel is smaller than the currently stored value for this pixel location in this image...the value for this pixel in the z-buffer is overwritten with the new and lower value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; before the z-depth value is stored in the z-buffer it is divided by a certain value (floating point type value), not sure why the number is devided. perhaps to reduce memory usage by storing smaller values...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I managed to fix the z-fighting in the viewports by increasing the near plane (in viewport settings) from 0.1 ish to a larger value. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please take a look at the image below:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/bqUux.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bqUux.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;The red planes are the camera's near and far planes. The green planes I have drawn myself and they indicate the minimum distance of the object relative to the camera and the maximum distance of the object relative to the camera. When scaling the scene by a factor x &lt;strong&gt;the ratio between the variables A,B,C,D&lt;/strong&gt; (please see the dimensions drawn in the image) &lt;strong&gt;should stay approximately the same&lt;/strong&gt; (as in the ratios A/B , A/C, A/D, B/A etc. should be approximately equal before and after the scaling process takes place).&#xA;Therefore the max and min depth relative to the near and far viewport planes should be approximately equal. And as a result the depth precision of the object should not change when scaling (I think). &#xA;My understanding is clearly incorrect since the z-fighting disappears when downscaling. &lt;strong&gt;Why is it that scaling has any effect on the z-fighting?&lt;/strong&gt; Does 3ds max automatically adjust the far and near plane distances relative to the viewport when scaling the object/scene?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read about something called depth precision (&lt;a href=&quot;https://developer.nvidia.com/content/depth-precision-visualized&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/content/depth-precision-visualized&lt;/a&gt;). Assuming this  (objects(their pixels) that are closer to the camera being stored more accurately in the z-buffer) is true in 3ds max it makes sense that when zooming in really close to the object in the viewport...the z-fighting disappears. however, when I zoom out quite a lot in the viewport, the z-fighting also isn't visible anymore even though it should in my mind get worse since the precision of the depth info stored in the z-buffer is lower for objects further away from the camera. Am I missing something ?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4hCPb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4hCPb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: the viewport clipping distances are set to the default in the image below and the first image of this post.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I have been unclear or incomplete about anything please let me know and I will try my best to explain/elaborate. Any help will be greatly appreciated. Thank you very much!&lt;/p&gt;&#xA;" OwnerUserId="9855" LastActivityDate="2019-05-01T11:13:53.913" Title="3ds max: Z-fighting when working with Large Objects" Tags="&lt;3d&gt;&lt;projections&gt;&lt;shading&gt;&lt;depth-map&gt;&lt;z-buffer&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8400" PostTypeId="2" ParentId="8387" CreationDate="2018-12-17T09:49:35.697" Score="3" Body="&lt;p&gt;Here's a more complete answer from the extent of my knowledge. A sort of brief overview you can google more about. I'm sure I didn't cover all the different techniques but most branch off the mentioned ones. Note: if it's a liquid we are more concerned with getting an accurate surface representation.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Surface Extraction Methods: The most common way would be to rasterize the particles into a 3d image/grid using a basis function, unless they're already in a grid. Then extract the polygonal surface from the image using marching cubes or some variant of it. Then render that polygon. There are some methods to extract polygonal surfaces directly from particles without rasterizing.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Ray Marching with an Implicit Surface: Again we rasterize the particles into an image but quickly convert into an implicit surface in our 3d image then ray march render the implicit surface, very fast.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Splat Volume Rendering (doing it in screen space): Splatting is good for visualizing extremely large datasets and used to be used a lot for volume rendering because of how fast it is. Basic idea is to rasterize all or most points as discs from the volume. You can do many effects, lighting, etc. Nvidia's screen space fluids is a form of this (SSF). Simple, fast, quality is acceptable for many cases.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Slicing/Texture Based Volume Rendering: Here we overlay 2d semi transparent images. You can just overlay some precomputed textures on various particles or compute a series of sliced 2d images a set distance apart in the 3d image/volume given the camera angle. More expensive. Gives better results than splatting.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Ray cast Volume Rendering: Similar to ray marching, we march along the ray from every pixel but instead of looking for an implicitly defined surface we sample the volume directly and map it too color and transparency then composite it back along the ray. For lighting we can do it similar to surface based rendering but use the gradient of the image as the normal. There are many other tricks.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Ray traced Volume Rendering: Basically the same as the ray casting but we bounce the rays around inside of the volume. They're distributed according to a phase function. I'm sure all the clouds in your favorite animated movies were rendered this way. Disney did this for their MPM simulated Snow in Frozen. The ray tracing approach is the most expensive of all of them, more expensive then surface based ray tracing. Not for real time as of writing this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Note: The first two methods aren't for gasses. The last 3 are best for gasses due to their lack of surface representation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think it's also worth noting the value of having a stored representation for post processing effects. For manual deformations or effects by an artist. Procedural effects like spray, foam, bubbles, etc. Or just some extra geometric processing (smoothing or whatever).&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2018-12-18T08:01:33.587" LastActivityDate="2018-12-18T08:01:33.587" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8401" PostTypeId="1" AcceptedAnswerId="8412" CreationDate="2018-12-17T10:36:46.737" Score="3" ViewCount="213" Body="&lt;p&gt;This might sound stupid for you but I really don't know how it works in the domain of 3d animation and motion capture, but I need to work with ASF/AMC files at the moment and I find it a little bit complex to understand (being a non-native english speaker does not help).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is, why motion captures main file types don't use simple joint coordinates for the skeleton? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I am particularly thinking about Acclaim ASF/AMC format mainly because I need to use it with an imlementation of an algorithm that use joint vertex positions and deltas from initial position for the motion part. Having looked at how the data are represented it makes more sense to me to represent skeletons as joint vertex and motion as deltas between the intial skeleton and the new moved one. &lt;/p&gt;&#xA;" OwnerUserId="9864" LastEditorUserId="9864" LastEditDate="2018-12-18T16:16:34.870" LastActivityDate="2018-12-21T09:18:32.913" Title="Why MOCAP data don't use simple point coordinates?" Tags="&lt;motion&gt;&lt;capture&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8402" PostTypeId="1" AcceptedAnswerId="8403" CreationDate="2018-12-17T18:14:33.213" Score="4" ViewCount="287" Body="&lt;p&gt;Considering the fact that Vulkan and DX12 delegate most of the memory management / work scheduling tasks to the application itself, how much do drivers affect performance?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To put my question into context, people on the internet talk a lot about NVIDIA drivers being more finely tuned and optimized (especially for the most popular games) compared to AMD drivers. Now that DX12/Vulkan are becoming more common, is it safe to assume that AMD video cards will become more competitive even if they have less optimized drivers?&lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2018-12-17T19:49:14.200" Title="How much does driver quality affect Vulkan and DX12 compared to OpenGL and DX11?" Tags="&lt;gpu&gt;&lt;vulkan&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8403" PostTypeId="2" ParentId="8402" CreationDate="2018-12-17T19:49:14.200" Score="5" Body="&lt;p&gt;TL;DR:  There's some room for optimization in Vulkan drivers, but not nearly to the degree that there is in GL / DX11 drivers.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;how much do drivers affect performance?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It depends a great deal on how the application is written and the hardware.  Specifically it depends on whether you're using features where there are large opportunities for optimization on the driver side. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if an application is written to take full advantage of renderpass subpasses and properly specifies the subpass dependencies and properly sets up transient attachments for intermediate work, then the difference between an extremely naive Vulkan driver and a well written one could easily be an order of magnitude.  But at the same time, this is basically the difference between naive client code and well written code both running on a well written driver.  &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;people on the internet talk a lot about NVIDIA drivers being more finely tuned and optimized (especially for the most popular games) &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This isn't just a matter of driver tuning.  It's arguably a form of cheating.  It's pretty well known that in the case of certain AAA games, nVidia will actually swap out functionality from the game with baked functionality from it's own drivers, doing things like swapping out shaders that were bundled in the game with their own customized shaders, or toggling internal flags that conventional developers have no access to.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that DX11 and GL are both very old APIs with lots of legacy functionality.  Their very design in some places is at odds with modern GPU hardware, especially in the area of bundling individual commands together before actually sending them to be executed.  This is why all modern APIs like Metal, Vulkan and DX12 have the concept of a command buffer or batch.  So that the developer can actually be involved in the process of bundling lots of small bind and draw commands together in a logical way.  Older API's like OpenGL have to guess at where the command buffer boundaries should be and (one assumes) drivers tend to have a variety of strategies for doing this depending on how the client application is calling functions.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is where the driver level optimizations come in, where nVidia or AMD can look at how a given game is calling functions and decide that strategy A is better than the strategy B (the one that driver version X is using), and so they release driver X + 1, and it forces the use of strategy A, or even a new strategy C that they came up with for this specific game.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The end result is that OpenGL (and I assume DX &amp;lt; 12) drivers end up being &lt;em&gt;monstrously&lt;/em&gt; complex, not just because of the enormous amount of legacy functionality they have to support, but also because of this per-game baggage that they accumulate (although I suspect that such per-game baggage has some kind of finite lifetime.... no one is going to be benchmarking a RTX 2080 with Battlefield 1942).&lt;/p&gt;&#xA;" OwnerUserId="9306" LastActivityDate="2018-12-17T19:49:14.200" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8404" PostTypeId="1" CreationDate="2018-12-17T22:31:10.937" Score="2" ViewCount="113" Body="&lt;p&gt;With GPU isolation : multiple processes use the single GPU will be serialized, cause OOM easily&#xA;link&#xA;&lt;a href=&quot;https://www.slideshare.net/mobile/Hadoop_Summit/deep-learning-on-yarn-running-distributed-tensorflow-etc-on-hadoop-cluster-v3&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.slideshare.net/mobile/Hadoop_Summit/deep-learning-on-yarn-running-distributed-tensorflow-etc-on-hadoop-cluster-v3&lt;/a&gt;&#xA;slide number 17&lt;/p&gt;&#xA;" OwnerUserId="9869" LastEditorUserId="9869" LastEditDate="2018-12-17T23:27:26.600" LastActivityDate="2018-12-18T08:33:28.627" Title="What does GPU serialized mean?" Tags="&lt;gpu&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8406" PostTypeId="2" ParentId="8404" CreationDate="2018-12-18T08:33:28.627" Score="4" Body="&lt;p&gt;It's saying that if you're using a single GPU, the multiple processes attempting to use the GPU will be queued up and run one at a time rather than some or all being run in parallel. If you have multiple GPUs some of the processes can be run at the same time.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2018-12-18T08:33:28.627" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8407" PostTypeId="2" ParentId="8398" CreationDate="2018-12-18T16:32:13.363" Score="1" Body="&lt;p&gt;Unfortunately, I don't know how 3ds max handles its Z-buffer or its near and far planes so I can't give a definite answer. There are many ways the software could handle this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, you are on the right track. Z-fighting occurs when there is not enough numerical precision to distinguish two &quot;objects&quot; from the scene rendered at the same pixel. In such cases, the two pixels &quot;fight&quot; one another over which one is closest to the camera and flickering occurs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These factors influence how a scene is susceptible to Z-fighting:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Number of bits used by the depth buffer (typically 24 or 32).&lt;/li&gt;&#xA;&lt;li&gt;Whether the depth buffer uses float values or integers.&lt;/li&gt;&#xA;&lt;li&gt;Whether the Z value &lt;code&gt;0&lt;/code&gt; is used for the near or far plane (inverted depth buffer).&lt;/li&gt;&#xA;&lt;li&gt;How close objects are to each other.&lt;/li&gt;&#xA;&lt;li&gt;The size of the range between the near and far planes.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Of these, you really only have control over the near and far planes from what you say.  It looks like your model is too big for the default way 3ds max handles this so I suggest making the near plane value bigger. An increase of the near plane from &lt;code&gt;0.1&lt;/code&gt; to &lt;code&gt;1.0&lt;/code&gt; (&lt;code&gt;*10&lt;/code&gt;) will give the same precision increase as dividing the far plane by 10.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your other question, you usually get less Z-fighting when an object is closer because there is more precision in the depth buffer closer to the near plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, for your other question: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8017/why-do-gpus-divide-clip-space-z-by-w-for-position?rq=1&quot;&gt;Why do GPUs divide clip space Z by W, for position?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A nice Z precision visualizer: &lt;a href=&quot;http://dev.theomader.com/depth-precision/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://dev.theomader.com/depth-precision/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2018-12-18T16:32:13.363" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8409" PostTypeId="1" CreationDate="2018-12-18T23:35:50.493" Score="1" ViewCount="65" Body="&lt;p&gt;I am developing a MacOS program using MacOS MetalKit and ModelIO. The ultimate goal is to use the 3D model to analyze the acoustic properties of a performance space. Initially I'm just creating a visual image of the space (stage, walls, seating, etc). I create a wavefront file (.obj and accompanying .mtl file).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can define the vertex color for every vertex in the .obj file. But I would like to use the Kd properties of the mtl file to set the color so that specific colors are associated with specific named materials in the mtl file.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use ModelIO to create an asset and then extract both the modelio mesh and metal mesh. Here is the bit of Swift code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Extract both the MetalKit meshes and the original ModelIO meshes&#xA;    var meshes: (modelIOMeshes: [MDLMesh], metalKitMeshes: [MTKMesh])&#xA;    meshes = try MTKMesh.newMeshes(asset: asset, device: device)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I see all of the mtl properties for all of the 147 submeshes in the imported modelio data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I specify the vertex colors in the obj file then I see all of those colors in the 147 metalKitMeshes submeshes. But if I do not specify all of the vertex colors in the obj file then all colors in the metalKitMeshes submeshes are Black (0,0,0). The colors specified in the mtl file are ignored.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The primary question: Is there a way to use the material colors in the mtl file to automatically set the metal submesh colors?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Secondary question: In the more general case, what is the best way to convey all of the material parameters from the modelio data to the shader?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I asked this on the Apple Developer forum, but got no response.&#xA;I also asked on StackOverflow but then realized that this may be a more appropriate forum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can import my wavefront file into Blender and all of the objects in the scene are rendered with the correct colors from the materials file. So the structures of my .obj and .mtl files seem to be correct.&lt;/p&gt;&#xA;" OwnerUserId="9880" LastActivityDate="2018-12-18T23:35:50.493" Title="What is best way to use wavefront material file color parameter Kd to set vertex color in MetalKit submeshes?" Tags="&lt;metal&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8410" PostTypeId="1" AcceptedAnswerId="8416" CreationDate="2018-12-19T23:07:45.653" Score="2" ViewCount="511" Body="&lt;p&gt;I am writing 3D graphics software in Java using the LibGDX framework (which is a front-end for OpenGL), and am baffled by a transformation problem.  How do I rotate the orientation of the camera or models being displayed by the dx and dy inputs from a mouse?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/mbrown85209/Space/blob/master/Space.java&quot; rel=&quot;nofollow noreferrer&quot;&gt;Click here&lt;/a&gt; to view the full source code of a concise demo in github.com&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, here is the method where I'm certain the problem and solution will be found:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;@Override public boolean touchDragged( int screenX, int screenY, int pointer )&#xA;{&#xA;    lastX = screenX-lastX;&#xA;    lastY = screenY-lastY;&#xA;&#xA;    // distance of mouse movement&#xA;    screenAng = (float) Math.sqrt( lastX*lastX + lastY*lastY );&#xA;    // direction vector of the AOR&#xA;    screenAOR.set( lastY/screenAng, lastX/screenAng, 0f );&#xA;    if ( touchedButton == 0 )&#xA;    {&#xA;        cubes[ selectedCube ].modelInstance.transform.rotate( screenAOR, screenAng );&#xA;    }&#xA;    else&#xA;    {&#xA;        camera.rotateAround( Vector3.Zero, screenAOR, -screenAng/5.5f );&#xA;        camera.update();&#xA;    }&#xA;&#xA;    lastX = screenX;&#xA;    lastY = screenY;&#xA;    Gdx.graphics.requestRendering();&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;EDIT: Thanks to Andrew Wilson for his comment below.  I edited the camera section and it works properly now.  Still working on the model section...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    {&#xA;&#xA;        // transform the screen AOR to a world AOR&#xA;&#xA;        // get the camera transformation matrix&#xA;        tempMat = new Matrix4( camera.view );&#xA;        tempMat.translate( camera.position );&#xA;        tempMat.inv();&#xA;&#xA;        // transform the screen AOR to a world AOR&#xA;        worldAOR = transformThings( tempMat, screenAOR, new Vector3() ).nor();&#xA;&#xA;        // apply the rotation of the angle about the world AOR to the camera&#xA;        camera.rotateAround( Vector3.Zero, worldAOR, screenAng/5.5f );&#xA;        camera.update();&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;EDIT: I edited the model section and it still is giving me some grief - it looks like it's orbiting the world origin instead of rotating around the model origin.  Here's what it looks like so far:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    {&#xA;&#xA;        // transform the screen AOR to a model AOR&#xA;&#xA;        // get inverse of the camera transformation matrix&#xA;        tempMat.set( camera.view );&#xA;        tempMat.translate( camera.position );&#xA;        tempMat.inv();&#xA;&#xA;        // get inverse of the model transformation matrix&#xA;        Vector3 tempPos = cubes[ selectedCube ].position;&#xA;        cubes[ selectedCube ].modelInstance.transform.translate( tempPos.cpy().scl( -1 ) );&#xA;        tempMat2.set( cubes[ selectedCube ].modelInstance.transform );&#xA;        tempMat2.inv();&#xA;&#xA;        // multiply the camera and model matrices together&#xA;        tempMat.mul( tempMat2 );&#xA;&#xA;        // transform the screen AOR to a model AOR&#xA;        modelAOR = transformThings( tempMat, screenAOR, modelAOR ).nor();&#xA;&#xA;        // apply the rotation of the angle about the model AOR to the model&#xA;        cubes[ selectedCube ].modelInstance.transform.rotate( modelAOR, -screenAng );&#xA;        cubes[ selectedCube ].modelInstance.transform.translate( tempPos );&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is an image that the demonstrates the problem:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/i3fNL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/i3fNL.png&quot; alt=&quot;results of wonky math&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want the object to rotate in the direction it is dragged by the mouse, no matter which direction it happens to be orientated at the time. As it is now, when I first drag the mouse to the right, the object rotates to the right about the screen Y axis as expected; but then when I drag the mouse upward I want the object to rotate upward about the screen X axis, but instead it spins to the left about the screen Z axis. Think of it like a floating ball in a bowl of water - whichever way you swipe at it, it ought to rotate in that direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems to me that the mouse movement is transforming the objects directly in their local coordinate system; but instead I think I need to transform the axis of rotation itself from the Screen Coordinate System into the Object Coordinate System before applying it to the object. I just can't figure out how to do it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would really appreciate any insight or help to resolve this; I'm running out of hair to pull out... Thanks in advance. &lt;/p&gt;&#xA;" OwnerUserId="9886" LastEditorUserId="9886" LastEditDate="2018-12-22T05:31:11.440" LastActivityDate="2018-12-30T07:39:13.133" Title="Rotate a model or a view with mouse input to produce intuitive results" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8411" PostTypeId="2" ParentId="8156" CreationDate="2018-12-20T12:59:08.370" Score="3" Body="&lt;p&gt;Copying this from another thread where i posted this as the answer but as Wyck suggested, the correct answer is the first one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is the whole derivation of it but I'll be discussing a brief overview.&#xA;This is for the perspective projection  where the line joining the eye and the center of the projection/image plane is perpendicular to it. Like here&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WmmPi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WmmPi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As we can easily see, by similar triangles &lt;span class=&quot;math-container&quot;&gt;$\triangle ABC$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\triangle AEF$&lt;/span&gt; we have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$Y_p / Y = D/-Z$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$Y_p$&lt;/span&gt; is the projected &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; coordinate on to the image plane. &lt;span class=&quot;math-container&quot;&gt;$AB = D$&lt;/span&gt; is the total distance from eye to the image plane and is usually set to 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence we have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$Y_p = (Y*D)/-Z$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We  can easily ee from here that,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$tan(\theta_{fov}/2) = 1/AB$&lt;/span&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$tan(\theta_{fov}/2) = 1/D$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$D = 1 /tan(\theta_{fov}/2)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence we have,&#xA;&lt;span class=&quot;math-container&quot;&gt;$Y_p = \frac{Y}{-Z*tan(\theta_{fov}/2)}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more details check the complete answer &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/6365/inverse-value-in-a-perspective-matrix/6366#6366&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2018-12-20T12:59:08.370" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8412" PostTypeId="2" ParentId="8401" CreationDate="2018-12-21T07:44:32.520" Score="3" Body="&lt;p&gt;Joint coordinates alone don't give you enough information about rotation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, hold out your arm to your side. Notice that you still have one degree of freedom to twist the arm without affecting the positions of your elbow or wrist. Thus, if you had a motion capture format that stored only those coordinates, you would not be able to distinguish these poses.&lt;/p&gt;&#xA;" OwnerDisplayName="user106" LastActivityDate="2018-12-21T07:44:32.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8413" PostTypeId="2" ParentId="8401" CreationDate="2018-12-21T09:18:32.913" Score="2" Body="&lt;p&gt;I'm not familiar with different motion capture file formats and exactly what they contain, but I have done some work on animating skeletons of life forms so here's my take on it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you draw something using a skeleton to animate it, you start with a &quot;root&quot; bone which will obviously have a position as can be seen in this &lt;a href=&quot;http://research.cs.wisc.edu/graphics/Courses/cs-838-1999/Jeff/walk.asf&quot; rel=&quot;nofollow noreferrer&quot;&gt;example walk.asf file&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;:root&#xA;   axis XYZ&#xA;   order TX TY TZ RZ RY RX&#xA;   position 0.0 0.0 0.0&#xA;   orientation 0.0 0.0 0.0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The next &lt;code&gt;bonedata&lt;/code&gt; section defines all the bones:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;:bonedata&#xA;begin&#xA;   id 1&#xA;   name hips&#xA;   direction 0.000000 1.000000 0.000000&#xA;   length 0.000000&#xA;   axis 0.00000 0.00000 0.00000 XYZ&#xA;   dof rx ry rz&#xA;   limits (-180.0 180.0)&#xA;      (-180.0 180.0)&#xA;      (-180.0 180.0)&#xA;end&#xA;# other bone definitions follow&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There is then a hierarchy of bones starting from this root bone:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;begin&#xA;   root hips&#xA;   hips hips1 hips2 hips3&#xA;   hips1 chest&#xA;   chest chest1 chest2 chest3&#xA;   chest1 neck&#xA;   # ...&#xA;   hips2 leftupleg&#xA;   # ...&#xA;   hips3 rightupleg&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(by the way, this is the kind of information I asked for in my comments and that you should have provided for a clearer question.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each &quot;child&quot; bone is connected to the endpoint of its parent and it defines its own orientation relative to that parent. This picture helps (taken from &lt;a href=&quot;http://help.autodesk.com/view/MOBPRO/2017/ENU/?guid=GUID-C42E4E6A-5149-4128-873C-08B2353A44B9&quot; rel=&quot;nofollow noreferrer&quot;&gt;Autodesk Motionbuilder's doc&lt;/a&gt;)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZqUhU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZqUhU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To position any given bone, you need to go up the bone hierarchy to the root bone and combine all their transformation matrices together. For example, to position bone &lt;code&gt;chest&lt;/code&gt;, the following sequence is used: &lt;code&gt;root -&amp;gt; hips -&amp;gt; hips1 -&amp;gt; chest&lt;/code&gt;. Each of these bones has its own transformation (rotation, stretch) based on the motion capture data which affects the position of its children. The &lt;code&gt;root&lt;/code&gt; bone is a special case that has no parents and represents the position and orientation of the whole model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Motion capture data cannot contain only bone positions because rotation in the axis of the bone cannot be expressed otherwise. Finally, it makes more sense to have motion capture data in terms of rotation and stretch because these values can be interpolated more easily than position and it's what is used anyway to render the skeleton.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2018-12-21T09:18:32.913" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8415" PostTypeId="1" AcceptedAnswerId="8427" CreationDate="2018-12-23T05:08:00.953" Score="4" ViewCount="121" Body="&lt;p&gt;I’m a weaver and textile maker with no prior coding or programming experience. In researching and reading through posts on this and other message boards, I was able to find a lot of useful information, but nothing that I could clearly map on what it is I’m trying to do. I’m hoping someone can steer me in the right direction. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I’m working with a set of 18x18 (324px), 8 bit RGB color PNGs which will ultimately be converted into weave structures. I am interested in implementing a script which will allow me to change the value of all pixels of a particular color channel. I’m seeing a number of posts describing how to change the color values of specific pixels, but little about making global changes to the color channels themselves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to be able to manipulate each color channel separately. For example, I'd like to be able to edit all RED pixels in an image such that all R pixel values increase by, say, 2, while pixels containing no R remain unchanged. Additionally, I want to be able to specify a limit, e.g. if the maximum R value in the image is 178, all R pixel values equaling 178 will remain unchanged, while all pixels with R values less than 178 will increase in value by 2. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope to be able to specify the channel (e.g. RED), amount of change (e.g. 2, 1, etc.), type of change (e.g. increase/decrease), and limit (e.g. n = 178, n = 0, n = 255, etc.) as those variables will need to be adjusted to satisfy different color palettes and weave structures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried achieving this in Photoshop and other graphics editors, but outside of selecting like pixels and adjusting their values manually, I haven't had luck in finding an effective solution for this.&#xA; &#xA;I’m wondering - 1) how feasible this is, 2) what program (e.g. Gimp, ImageMagick, etc.) and/or programming language might provide the most straightforward, expedient solution and 3) if anybody has any tips about how go about writing a script like this, as this is all quite new to me.&lt;/p&gt;&#xA;" OwnerUserId="9896" LastEditorUserId="6" LastEditDate="2018-12-23T13:34:18.497" LastActivityDate="2018-12-25T17:52:23.550" Title="How to shift color values of a single RGB channel" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;color&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8416" PostTypeId="2" ParentId="8410" CreationDate="2018-12-23T05:58:48.093" Score="1" Body="&lt;p&gt;Here's a more complete answer from my comment. The end product we want is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Projection * ViewTranslate * Model * ViewRotate&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;All are 4x4 matrices. Where model is your models transformations. To implement you can just separate out the view's translate and rotate during your draw.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're using an abstraction that requires you to use Proj * View * Model. Or you just really don't want to ruin your own abstraction that follows that pattern. You'll need to modify model to cancel out views rotational part and put it on the right side:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Model = ModelTranslate * View^-1 * ViewTranslate * ModelRotate * ViewRotate &#xA;      = ModelTranslate * ViewRotate^-1 * ModelRotate * ViewRotate&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here's some of my code that does the above. It does not matter if model or view is translated, objects will still rotate around their local origins:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec2 diff = (prevMousePos - mousePos) * rotSpeed;&#xA;glm::mat4 rotX = MathHelp::matrixRotateY(diff.x);&#xA;glm::mat4 rotY = MathHelp::matrixRotateX(diff.y);&#xA;&#xA;// Decompose the translate and rotate part of view&#xA;glm::mat4 viewT, viewR;&#xA;Decompose(cam-&amp;gt;view, viewT, viewR);&#xA;&#xA;// Decompose the translate and rotate part of model&#xA;glm::mat4 modelT, modelR;&#xA;Decompose(exampleObj-&amp;gt;model, modelT, modelR);&#xA;&#xA;exampleObj-&amp;gt;model = modelT * glm::inverse(viewR) * rotX * rotY * viewR * modelR;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This preserves the existing rotation and translation in exampleObj-&gt;model as the function gets called continually applying small rotations. And assumes you'll be using Proj * View * Model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly decompose just separates out the 3x3 rotation/scaling from the translational part:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void Decompose(glm::mat4 m, glm::mat4&amp;amp; t, glm::mat4&amp;amp; r)&#xA;{&#xA;    glm::mat4 I4 = glm::mat4(1.0f); // Identity&#xA;    for (unsigned int i = 0; i &amp;lt; 4; i++)&#xA;    {&#xA;        for (unsigned int j = 0; j &amp;lt; 4; j++)&#xA;        {&#xA;            if (i == 3 || j == 3)&#xA;            {&#xA;                r[i][j] = I4[i][j];&#xA;                t[i][j] = m[i][j];&#xA;            }&#xA;            else&#xA;            {&#xA;                r[i][j] = m[i][j];&#xA;                t[i][j] = I4[i][j];&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="113" LastActivityDate="2018-12-23T05:58:48.093" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8417" PostTypeId="1" AcceptedAnswerId="8419" CreationDate="2018-12-23T09:23:51.470" Score="2" ViewCount="155" Body="&lt;p&gt;I want to use PCF shadow map on my d3d11 app. My shadow map is an R16_FLOAT texture. When I use SampleCmpLevelZero it didn't give a correct result. After enabling debug layer, it shows:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The Shader Resource View in slot 1 of the Pixel Shader unit is using the Format (R16_FLOAT). This format does not support 'SampleCmp' or 'SampleCmpLevelZero', at least one of which is being used on the Resource by the shader. This mismatch is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But when I query whether the format support SampleCmp using the code below, it returns 0 which means success. Can someone explain why?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Renderer::InitRenderer(HWND hwnd)&#xA;{&#xA;    if (!InitD3D11App(hwnd)) return false;&#xA;    InitViewport();&#xA;&#xA;    UINT formatSupport = D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;&#xA;    printf(&quot;Support?\n&quot;);&#xA;    HRESULT hr = d3d11Device-&amp;gt;CheckFormatSupport(DXGI_FORMAT_R16_FLOAT, &amp;amp;formatSupport);&#xA;    printf(&quot;result: %d\n&quot;, hr);&#xA;    if (!SUCCEEDED(hr))&#xA;    {&#xA;        printf(&quot;Nope!\n&quot;);&#xA;        return false;&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9901" LastEditorUserId="6" LastEditDate="2018-12-23T13:36:01.863" LastActivityDate="2019-01-22T18:01:11.247" Title="R16_FLOAT, SampleCmp and CheckFormatSupport" Tags="&lt;shadow&gt;&lt;hlsl&gt;&lt;directx11&gt;&lt;shadow-mapping&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8418" PostTypeId="1" AcceptedAnswerId="8420" CreationDate="2018-12-23T16:32:24.447" Score="1" ViewCount="2948" Body="&lt;p&gt;I have a class Ray and Square&lt;/p&gt;&#xA;&#xA;&lt;p&gt;public class Rayo {&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public Point origen;&#xA;public Vector direction;&#xA;&#xA;Square{&#xA;X,Y,Widht, height;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I need intersection between this two, how? my code crossProduct in java is &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static Vector productoCruz(Vector a, Vector b) {&#xA;        return new Vector(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To apply the product point you need two vectors, and I only have 1 (the ray vector), where do I get the other vector?&lt;/p&gt;&#xA;" OwnerUserId="9256" LastEditorUserId="9256" LastEditDate="2018-12-24T15:14:46.053" LastActivityDate="2020-05-30T09:27:04.613" Title="Get intersection Ray with square" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8419" PostTypeId="2" ParentId="8417" CreationDate="2018-12-23T18:00:50.500" Score="1" Body="&lt;p&gt;Because I was using the CheckFormatSupport wrong. The second parameter is supposed to be an input.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is what it should be like.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Renderer::InitRenderer(HWND hwnd)&#xA;{&#xA;    if (!InitD3D11App(hwnd)) return false;&#xA;    InitViewport();&#xA;&#xA;    UINT formatSupport;&#xA;    HRESULT hr = d3d11Device-&amp;gt;CheckFormatSupport(DXGI_FORMAT_R16_FLOAT, &amp;amp;formatSupport);&#xA;    if (!SUCCEEDED(hr) || !(formatSupport &amp;amp; D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON))&#xA;    {&#xA;        printf(&quot;Not supported!\n&quot;);&#xA;        return false;&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.gamedev.net/forums/topic/700419-r16_float-samplecmp-and-checkformatsupport/?tab=comments#comment-5397459&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.gamedev.net/forums/topic/700419-r16_float-samplecmp-and-checkformatsupport/?tab=comments#comment-5397459&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9901" LastActivityDate="2018-12-23T18:00:50.500" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8420" PostTypeId="2" ParentId="8418" CreationDate="2018-12-23T18:05:51.967" Score="2" Body="&lt;p&gt;The best algorithm depends on the condition like whether or not the square is axis aligned for example. I'm gonna discuss the more general case which can find find intersection for any arbitrary oriented square. The algorithm works by first checking the intersection of ray with the plane containing the square or rectangle etc. Then check if the ray is within bounds of the square.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this you require the following information&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ray's in the form &lt;span class=&quot;math-container&quot;&gt;$R =e+td $&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$e$&lt;/span&gt; is the origin or eye point and &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; is the direction vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Secondly you need to define your square by using the following information  &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;Poisition&lt;/strong&gt; - This might be the vector to the center or any corner of the square. The algorithm I'm describing assumes it is one of the corners.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Normal&lt;/strong&gt; - Self explanatory.&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Width&lt;/strong&gt; and &lt;strong&gt;Height&lt;/strong&gt; not as scalars but as vectors. These can be called the two edge vectors. I will denote them as &lt;span class=&quot;math-container&quot;&gt;$e1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$e2$&lt;/span&gt;. &lt;em&gt;Note that both edge vectors need to grow outward from the corner of the square chosen in point 1.&lt;/em&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;After you have the following information you first need to compute Ray - plane intersection. The plane being where your square lies. This is done as follows. We know the point normal form of a plane as,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$(p-p1).n= 0$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we suppose &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is our ray here and &lt;span class=&quot;math-container&quot;&gt;$p1 = position$&lt;/span&gt;, then we will have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$(e+td - p1).n=0$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$(e+td - p1).n=0$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$e.n + td.n - p1.n = 0$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$t = p1.n - e.n/d.n$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$t = (p1-e).n/d.n$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$t \geq 0$&lt;/span&gt; then we have an intersection. Now all we need to do is check whether the ray lies inside the square or anywhere else on the plane. This is easy to do.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$intersect\_point = e + td$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$v = intersect\_point - p1$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$width = ||e1||$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$height = ||e2||$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$proj1 = v.e1 /width $&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$proj2 = v.e2 / height$&lt;/span&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$if((proj1 &amp;lt; width \;\&amp;amp;\&amp;amp;\; proj1 &amp;gt; 0) \;\&amp;amp;\&amp;amp;\; (proj2  &amp;lt; height \;\&amp;amp;\&amp;amp;\; proj2 &amp;gt; 0) )$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$return \, true$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the above assumes that the edge vectors grow outward from the corner, i.e. A square with the corners A,B,C,D in clockwise fashion starting from  the top left. If we choose corner &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; then the edge vectors are &lt;span class=&quot;math-container&quot;&gt;$\vec{AB}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{AD}$&lt;/span&gt;. &lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-02-14T06:52:00.253" LastActivityDate="2019-02-14T06:52:00.253" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="8422" PostTypeId="1" CreationDate="2018-12-16T14:24:52.203" Score="2" ViewCount="178" Body="&lt;p&gt;I am trying to understand the mathematical/physical foundations of photon mapping better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the forward photon tracing step it is established, that the rays are carrying portions of total power (flux) rather than radiance as it is typically done in other types of ray-tracing algorithms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in all articles and tutorials I could never find a precise explanation how such flux-carrying path interacts with materials? In other words - what is the rendering equation for interaction between flux-path and a surface?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I typically found is an algorithm, based on Russian Roulette, for building a light path. But not a foundation equation that lead to that algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In particular, I am interested in:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Should the equation include the cosine of the incident angle or not? I suspect it shouldn't be there, as the power remains constant, but it is spread over a bigger area (thus reducing the radiance at each point, but not total flux).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Should the BRDF function be somehow (re)normalized? For example, for a perfect diffusive material, the BRDF is a constant not greater than 1/pi, so that it is energy conserving. But for a flux-based equation, assuming it is different, energy conservation may set a different maximum value.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Note, the very similar question:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/13713580/rendering-equation-for-photon-mapping&quot;&gt;Rendering equation for Photon Mapping&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;refers to a different step of the photon mapping algorithm. It asks for the rendering equation where the radiance is being estimated based on the nearest stored photons. Instead, I am asking for the flux-surface interaction in an earlier stage of the algorithm, when photons are being generated and propagated.&lt;/p&gt;&#xA;" OwnerUserId="9911" OwnerDisplayName="CygnusX1" LastEditorUserId="9911" LastEditDate="2018-12-25T19:29:47.877" LastActivityDate="2019-01-24T20:01:15.220" Title="Rendering Equation for photons carrying flux" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;physically-based&gt;&lt;physics&gt;&lt;photon-mapping&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8423" PostTypeId="2" ParentId="8422" CreationDate="2018-12-19T07:34:36.780" Score="1" Body="&lt;p&gt;It'd be hell a lot easier if this were on graphicsexchange, since I can't use latex here but anyways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first pass of Photon Mapping you don't need to use the Flux form of rendering equation. You just divide the original flux coming from the light source among the N photons, then for each photon you use Russian Roulette to determine whether it reflects, transmits or gets absorbed and store the incoming flux.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the second pass you need to find radiance but you have information in Flux form. The rendering equation can be simply transformed. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qrXgH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qrXgH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/firlX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/firlX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/DqmCY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DqmCY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So all you need to do is divide the flux stored for each photon by the area. Note that the Area is often denoted as &lt;code&gt;A= pi r^2&lt;/code&gt; Since we are concerned with a hemisphere and the underlying area is just a circle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;About your 2nd point, I don't think the BRDF needs to be re-normalized or whatsoever since the equation is essentially the same. Note that the second term in the last equation is still a radiance written in flux form. (BRDF has units of inverse solid angle thus making the whole term radiance).&lt;/p&gt;&#xA;" OwnerUserId="6046" OwnerDisplayName="gallickgunner" LastActivityDate="2018-12-19T07:34:36.780" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="8424" PostTypeId="2" ParentId="3890" CreationDate="2018-12-24T10:51:55.420" Score="2" Body="&lt;p&gt;The simplest solution would be just a multiplication, which would give black edges:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;combinedColor = sceneColor * edgeRGB.r;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For more control I would suggest something very similar to what @PaulHK proposed in the comments:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float opacity = maxEdgeOpacity * (1. - edgeRGB.r);&#xA;combinedColor = mix(sceneColor, edgeColor, opacity);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;edgeColor&lt;/code&gt; is the desired edge color and &lt;code&gt;maxEdgeOpacity&lt;/code&gt; is meant to be a parameter between 0 (no edges at all) and 1 (opaque edges), that you both choose to your liking.&lt;/p&gt;&#xA;" OwnerUserId="182" LastActivityDate="2018-12-24T10:51:55.420" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8426" PostTypeId="1" AcceptedAnswerId="8428" CreationDate="2018-12-25T14:00:53.963" Score="2" ViewCount="152" Body="&lt;p&gt;Say I have a scene graph, and each node has a scale, rotation, and translation. Can I combine these into a single scale, rotation, and translation?&lt;/p&gt;&#xA;" OwnerUserId="9909" LastActivityDate="2018-12-25T21:26:40.780" Title="Composition of decomposed transformations" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8427" PostTypeId="2" ParentId="8415" CreationDate="2018-12-25T17:52:23.550" Score="4" Body="&lt;p&gt;I don't have any direct experience doing this so I might be missing an obvious solution or tool. That said, what you describe is in programming terms comparatively easy to achieve. The basic structure of such a custom processing would be:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Open the image file and get access to the array of pixels it contains.&lt;/li&gt;&#xA;&lt;li&gt;Iterate over all the pixels and inspect/transform however you want.&lt;/li&gt;&#xA;&lt;li&gt;Write out the resulting modified image in the desired format.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Both Gimp (&lt;a href=&quot;https://developer.gimp.org/plug-ins.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;1&lt;/a&gt;, &lt;a href=&quot;https://www.gimp.org/docs/python/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;2&lt;/a&gt;) and Photoshop (&lt;a href=&quot;https://www.photoshoptutorials.ws/photoshop-tutorials/basics/manipulate-an-image-with-scripting/?doing_wp_cron=1545753669.9555869102478027343750&quot; rel=&quot;nofollow noreferrer&quot;&gt;tutorial&lt;/a&gt;) provide &lt;em&gt;scripting or plugins support&lt;/em&gt; which will allow you to provide custom logic for step 2 and handle the rest for you. I don't have any experience with either, but from a very quick overview, I recommend that you use Javascript, Python or another scripting language which will be much more accessible as a new programmer than a language like C.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another option I found outside of an image editor that looks good is the Python Imaging Library. Here is a very relevant other question on SO: &lt;a href=&quot;https://stackoverflow.com/questions/36468530/changing-pixel-color-value-in-pil&quot;&gt;https://stackoverflow.com/questions/36468530/changing-pixel-color-value-in-pil&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From it, I was able to write the following Python script that does what you asked:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;from PIL import Image&#xA;&#xA;img = Image.open(&quot;input.png&quot;)&#xA;pixels = img.load() # create the pixel map&#xA;&#xA;# configuration&#xA;channel = 0 # 0 = red, 1 = green, 2 = blue&#xA;change_amount = 2 # can be -2 for decrease&#xA;limit = 178&#xA;&#xA;for i in range(img.size[0]): # for every pixel (in 2D):&#xA;    for j in range(img.size[1]):&#xA;        if pixels[i,j][channel] &amp;lt; limit:&#xA;            # Only modify pixels below the set limit.&#xA;            # The following &quot;strange&quot; code is used because Python tuples can't be modified&#xA;            # directly. The tuple is transformed into a (mutable) list and moved back again&#xA;            # to a tuple afterwards. You can safely ignore this and concentrate on the&#xA;            # second line that actually modifies a channel's value.&#xA;            color = list(pixels[i,j])&#xA;            # Increase (or decrease for a negative change_amount value) the chosen channel.&#xA;            color[channel] += change_amount&#xA;            pixels[i,j] = tuple(color)&#xA;&#xA;img.save(&quot;out.png&quot;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is untested code, but it shows how to translate what you want into code. You already described what you wanted in a very programmer-friendly manner so the translation is almost direct. The sky is the limit then as to what you can do with pixels once you load them in a custom program to manipulate them.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2018-12-25T17:52:23.550" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8428" PostTypeId="2" ParentId="8426" CreationDate="2018-12-25T21:26:40.780" Score="2" Body="&lt;p&gt;Yes you can, provided that all the nodes' scales are only &lt;em&gt;uniform&lt;/em&gt; scaling—the same scaling factor along all three axes. If there is nonuniform scaling (different factors along different axes) then things get more complicated, and the composed transformation generally can't be decomposed cleanly into scale, rotation, and translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to accomplish this is to convert all the individual nodes' transforms into 4×4 matrix form, multiply the matrices down the tree from root to leaf, then decompose the resulting matrix (see &lt;a href=&quot;https://computergraphics.stackexchange.com/a/4282/48&quot;&gt;this answer&lt;/a&gt; for how to do the decomposition).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you have all the transforms in TRS form (translate, rotate, scale—assuming column vector convention) and you want the final transform in TRS form, you can also combine them directly.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The final scale is just the product of all the individual nodes' scales&lt;/li&gt;&#xA;&lt;li&gt;The final rotation is just the composition of all the individual nodes' rotations (in quaternion form for example)&lt;/li&gt;&#xA;&lt;li&gt;The final translation is made by summing the translation vectors, but transforming each vector by the composite scale and rotation of all the nodes above it in the tree. For example if you have a transformation &lt;span class=&quot;math-container&quot;&gt;$T_1 R_1 S_1 T_2 R_2 S_2 T_3 R_3 S_3$&lt;/span&gt; (numbering from the root down to the leaf), then the final translation is &lt;span class=&quot;math-container&quot;&gt;$t_1 + (R_1 S_1) t_2 + (R_1 S_1 R_2 S_2) t_3$&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="48" LastActivityDate="2018-12-25T21:26:40.780" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8431" PostTypeId="1" CreationDate="2018-12-28T05:26:55.727" Score="1" ViewCount="84" Body="&lt;p&gt;(Note that as far as attempts go, I can't find anything that helps me)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a 3D polygon, and for simplicity's sake it's going to be the one below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KQ8Ct.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KQ8Ct.png&quot; alt=&quot;Basic Textured Polygon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is textured using the UV map below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UaFcs.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UaFcs.jpg&quot; alt=&quot;Basic Texture UV&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Side Note: I just found the texture on Google. It is not being used in any manner other than solely to demonstrate my question.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I plan on 3D printing the polygon. Since I suck at painting, I want to print the textures for each face so I can glue/decal them onto the correct faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: How can I go from a UV texture map to individual polygon faces (and 1 texture per face) that is correctly scaled to fit the face. I want something like below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/s8hCn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/s8hCn.png&quot; alt=&quot;Desired Outcome&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there &lt;strong&gt;any&lt;/strong&gt; way to do this? I don't care about width * height as I can manage that on my own, but I need the textures to be distorted just like how they are on the corresponding face of the polygon.&lt;/p&gt;&#xA;" OwnerUserId="9922" LastEditorUserId="9922" LastEditDate="2018-12-28T14:40:04.470" LastActivityDate="2021-05-18T02:06:40.600" Title="Export Model Textures Per Face" Tags="&lt;texture&gt;&lt;3d&gt;&lt;uv-mapping&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8433" PostTypeId="2" ParentId="8431" CreationDate="2018-12-29T22:51:16.180" Score="0" Body="&lt;p&gt;UV mapping assigns fixed positions in the texture to each vertex. You'll have to distort the image so that it maps to a constant area in &quot;model size&quot; so to speak. I found the following other question that will probably give you a solution: &lt;a href=&quot;https://blender.stackexchange.com/questions/22872/unwrap-uv-map-proportionally-to-object-size&quot;&gt;https://blender.stackexchange.com/questions/22872/unwrap-uv-map-proportionally-to-object-size&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It won't give disjointed parts like in your image, but I think it will still provide what you're looking for.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2018-12-29T22:51:16.180" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8434" PostTypeId="2" ParentId="8410" CreationDate="2018-12-30T07:39:13.133" Score="0" Body="&lt;p&gt;Here is the change to the code that made the whole thing work correctly:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;@Override public boolean touchDragged( int screenX, int screenY, int pointer )&#xA;{&#xA;    lastX -= screenX;&#xA;    lastY -= screenY;&#xA;&#xA;    // distance of mouse movement&#xA;    screenAng = Vector3.len( lastX, lastY, 0f );&#xA;    // direction vector of the AOR&#xA;    screenAOR.set( lastY/screenAng, lastX/screenAng, 0f );&#xA;&#xA;    if ( touchedButton == 0 )&#xA;    {   // rotate the part&#xA;&#xA;        // transform the screen AOR to a model rotation&#xA;&#xA;        Matrix4 camT, camR, camRi, modT, modR;&#xA;        camT = new Matrix4();&#xA;        camR = new Matrix4();&#xA;        modT = new Matrix4();&#xA;        modR = new Matrix4();&#xA;&#xA;        decompose( camera.view, camT, camR );&#xA;        camRi = camR.cpy().inv();&#xA;&#xA;        decompose( cubes[ selectedCube ].modelInstance.transform, modT, modR );&#xA;&#xA;        tempMat.idt()&#xA;                .mul( modT )&#xA;                .mul( camRi )&#xA;                .rotate( screenAOR, -screenAng )&#xA;                .mul( camR )&#xA;                .mul( modR );&#xA;&#xA;        cubes[ selectedCube ].modelInstance.transform.set( tempMat );&#xA;    }&#xA;    else if ( touchedButton == 1 )&#xA;    {   // rotate the camera&#xA;&#xA;        // transform the AOR from screen CS to camera CS&#xA;&#xA;        // get the camera transformation matrix&#xA;        tempMat.set( camera.view );&#xA;        tempMat.translate( camera.position );&#xA;        tempMat.inv();&#xA;&#xA;        // transform the screen AOR to a world AOR&#xA;        worldAOR = transform( tempMat, screenAOR, worldAOR ).nor();&#xA;&#xA;        // apply the rotation of the angle about the world AOR to the camera&#xA;        camera.rotateAround( Vector3.Zero, worldAOR, screenAng/5.5f );&#xA;        camera.update();&#xA;    }&#xA;&#xA;    lastX = screenX;&#xA;    lastY = screenY;&#xA;    Gdx.graphics.requestRendering();&#xA;    return true;&#xA;}&#xA;&#xA;// --------------------------------------------------------------------- //&#xA;Vector3 transform( Matrix4 mat, Vector3 from, Vector3 to )&#xA;{&#xA;    // transform a vector according to a transformation matrix&#xA;&#xA;    to.x = from.dot( mat.val[ Matrix4.M00 ], mat.val[ Matrix4.M01 ],&#xA;            mat.val[ Matrix4.M02 ] )+mat.val[ Matrix4.M03 ];&#xA;    to.y = from.dot( mat.val[ Matrix4.M10 ], mat.val[ Matrix4.M11 ],&#xA;            mat.val[ Matrix4.M12 ] )+mat.val[ Matrix4.M13 ];&#xA;    to.z = from.dot( mat.val[ Matrix4.M20 ], mat.val[ Matrix4.M21 ],&#xA;            mat.val[ Matrix4.M22 ] )+mat.val[ Matrix4.M23 ];&#xA;    return to;&#xA;}&#xA;&#xA;// --------------------------------------------------------------------- //&#xA;void decompose( Matrix4 m, Matrix4 t, Matrix4 r )&#xA;{&#xA;    Matrix4 I4 = new Matrix4(); // Identity&#xA;    for ( int i = 0; i &amp;lt; 4; i++ )&#xA;    {&#xA;        for ( int j = 0; j &amp;lt; 4; j++ )&#xA;        {&#xA;            if (i == 3 || j == 3)&#xA;            {&#xA;                r.val[ i*4+j ] = I4.val[ i*4+j ];&#xA;                t.val[ i*4+j ] = m.val[ i*4+j ];&#xA;            }&#xA;            else&#xA;            {&#xA;                r.val[ i*4+j ] = m.val[ i*4+j ];&#xA;                t.val[ i*4+j ] = I4.val[ i*4+j ];&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9886" LastActivityDate="2018-12-30T07:39:13.133" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8435" PostTypeId="1" AcceptedAnswerId="8436" CreationDate="2018-12-30T15:24:24.067" Score="2" ViewCount="194" Body="&lt;p&gt;I am trying to implement conservative voxelization as part of real time GI in my hobby rendering engine. I find this &lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems2/gpugems2_chapter42.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt; by NVIDIA. I am stuck at understanding the second algorithm. The problem that I have is that I don't understand this section of the article&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;We describe both algorithms in window space, for clarity, but in&#xA;  practice it is impossible to work in window space, because the vertex&#xA;  program is executed before the clipping and perspective projection.&#xA;  Fortunately, our reasoning maps very simply to clip space. For the&#xA;  moment, let us ignore the z component of the vertices (which is used&#xA;  only to interpolate a depth-buffer value). Doing so allows us to&#xA;  describe a line through each edge of the input triangle as a plane in&#xA;  homogeneous (x c , y c , w c )-space. The plane is defined by the two&#xA;  vertices on the edge of the input triangle, as well as the position of&#xA;  the viewer, which is the origin, (0, 0, 0). Because all of the planes&#xA;  pass through the origin, we get plane equations of the form&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;ax c + by c + cw c = 0  a(xw c ) + b (yw c ) + cw c ) + cw c = 0  ax +&#xA;  by + c = 0&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;The planes are equivalent to lines in two dimensions. In many of our&#xA;  computations, we use the normal of an edge, which is defined by (a, b)&#xA;  from the plane equation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;First, I don't understand how to visualize a plane that use w value as one of this coordinates and what is the meaning of this plane. And then later in the article, they calculate this plane by doing a cross product like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Compute equations of the planes through the two edges&#xA;&#xA;float3 plane[2];&#xA;&#xA;plane[0] = cross(currentPos.xyw - prevPos.xyw, prevPos.xyw);&#xA;&#xA;plane[1] = cross(nextPos.xyw - currentPos.xyw, currentPos.xyw);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Again, I still don't understand why this is true. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any relation between the plane normal with the line normal because in the next part, the algorithm use this normal xy value to move the line outwards by substracting the z value of this plane.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Move the planes by the appropriate semidiagonal&#xA;&#xA;plane[0].z -= dot(hPixel.xy, abs(plane[0].xy));&#xA;&#xA;plane[1].z -= dot(hPixel.xy, abs(plane[1].xy));&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;// Compute the intersection point of the planes.&#xA;&#xA;float4 finalPos;&#xA;&#xA;finalPos.xyw = cross(plane[0], plane[1]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I can understand it if the xy component of the plane's normal is actually the normal of the line as well and the z value of the plane's normal represent the line distance from point (0, 0)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone please explain in more detail or provide me some visualization of this algorithm ?&lt;/p&gt;&#xA;" OwnerUserId="8565" LastEditorUserId="8565" LastEditDate="2018-12-31T02:45:44.980" LastActivityDate="2018-12-31T02:45:44.980" Title="Comprehensive explanation of conservative rasterization algorithm" Tags="&lt;global-illumination&gt;&lt;rasterizer&gt;&lt;voxelization&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8436" PostTypeId="2" ParentId="8435" CreationDate="2018-12-30T22:44:41.340" Score="5" Body="&lt;p&gt;I'm not sure what exactly you mean by &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;how to visualize a plane that use w value as one of this coordinates&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;but here's a sketch that will, hopefully, clarify this sentence:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;a line through each edge of the input triangle as a plane in homogeneous (x c , y c , w c )-space&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I've used uppercase letters for clip-space, and lowercase letters for window space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SHOvp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SHOvp.png&quot; alt=&quot;plane through 3D points that project onto a 2D screen&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say AB is an edge of your original triangle.&#xA;It projects to an edge ab in window coordinates.&#xA;Point A is defined using [X&lt;sub&gt;A&lt;/sub&gt;, Y&lt;sub&gt;A&lt;/sub&gt;, Z&lt;sub&gt;A&lt;/sub&gt;, W&lt;sub&gt;A&lt;/sub&gt;] coordinates. After projection it will have coordinates [x&lt;sub&gt;A&lt;/sub&gt;, y&lt;sub&gt;A&lt;/sub&gt;] = [X&lt;sub&gt;A&lt;/sub&gt;/W&lt;sub&gt;A&lt;/sub&gt;, Y&lt;sub&gt;A&lt;/sub&gt;/W&lt;sub&gt;A&lt;/sub&gt;] and the value Z&lt;sub&gt;A&lt;/sub&gt;/W&lt;sub&gt;A&lt;/sub&gt; will be used to determine which object is closer to the camera at this point.&#xA;So your [X, Y, Z, W] always turns into a [X/W, Y/W] in the end. You can see that Z doesn't play any role in where the point is going to end up on the screen. So we just throw it away for now and interpret the remaining [X, Y, W] as 3D coordinates of the points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we have point A = [X&lt;sub&gt;A&lt;/sub&gt;, Y&lt;sub&gt;A&lt;/sub&gt;, W&lt;sub&gt;A&lt;/sub&gt;] and B = [X&lt;sub&gt;B&lt;/sub&gt;, Y&lt;sub&gt;B&lt;/sub&gt;, W&lt;sub&gt;B&lt;/sub&gt;].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The projected point &lt;strong&gt;a&lt;/strong&gt; will lie on the line that connects [0, 0, 0] and A.&#xA;Point &lt;strong&gt;b&lt;/strong&gt; will lie on the line [0, 0, 0] and B. Three points define a plane, and a normal to the plane defined by 3 points can be found as a cross product of two vectors in this plane (OA and OB, for example). &#xA;&quot;For a convex polygon (such as a triangle), a surface normal can be calculated as the vector cross product of two (non-parallel) edges of the polygon.&quot;&#xA;More on why in Wikipedia &lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_(geometry)&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Cross_product&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally this moves your problem from 2D domain in the projected coordinates into a 3D domain of not-yet-projected points. The 2D and 3D are &quot;dual&quot; to each other. For example, if a point lies in the plane of OAB, it for sure lies on the line through &lt;strong&gt;ab&lt;/strong&gt; (and vice versa).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing you need to remember is that W is your 3'rd coordinate, not Z! I know, it's very counter-intuitive, but it is what it is, Z only carries depth information, it does not affect position of objects on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope I cleared it up for you a bit.&lt;/p&gt;&#xA;" OwnerUserId="9934" LastEditorUserId="9934" LastEditDate="2018-12-30T23:45:28.957" LastActivityDate="2018-12-30T23:45:28.957" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8437" PostTypeId="1" AcceptedAnswerId="8438" CreationDate="2019-01-01T04:35:46.590" Score="3" ViewCount="179" Body="&lt;p&gt;In &lt;a href=&quot;https://retrocomputing.stackexchange.com/q/8627/7118&quot;&gt;this question&lt;/a&gt; I generated the images below to explain why I can't use TTFs for that 1-bit display application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But now I would like to understand &lt;em&gt;from the perspective of a non-expert&lt;/em&gt;, why is some black-on-white text on my screen made from gray pixels, while other text is made from color pixels?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gray on left is a screenshot from the SE question editor window, color on right is from a Finder window in MacOS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &quot;Why?&quot; should have two elements, one might be &quot;because Apple does it that way&quot; but the other would hopefully help me understand &lt;em&gt;why Apple does it that way&lt;/em&gt; if that is in fact the case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;update:&lt;/strong&gt; The answer to &lt;a href=&quot;https://computergraphics.stackexchange.com/q/2034/5846&quot;&gt;why does black text have orange and blue pixels&lt;/a&gt; names this as &quot;sub-pixel rendering&quot; but I still do not understand why it is in color in some places, gray in others, and if and why the color is used at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wAiuH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wAiuH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;a href=&quot;https://i.stack.imgur.com/IyBx3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IyBx3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've done a rough analysis of the colors used in hopes that it might teach me something, but I can't really gain any insight beyond &quot;its a red-blue thing&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bTMCk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bTMCk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5846" LastEditorUserId="5846" LastEditDate="2019-05-03T00:04:09.890" LastActivityDate="2019-05-03T00:04:09.890" Title="Why does some text on my laptop have only gray-scale pixels while other text has color pixels?" Tags="&lt;font-rendering&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8438" PostTypeId="2" ParentId="8437" CreationDate="2019-01-01T12:34:28.337" Score="5" Body="&lt;p&gt;It's called subpixel rendering (there are different solutions on different platforms). Microsoft's one is called ClearType, just google for it, Wikipedia has a nice description.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Earlier, simple edge smoothing was used, antialising, that resulted in gray pixels added to the jagged lines to mask them, and although it technically created a more blurred outline, due to the way our brain works, we perceived the resulting forms more pleasing, more natural, easier to read.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Colored subpixels arrived when monitor technology moved from CRT screens to LCD where the RGB components making up a pixel are much more uniform. Very simply put, we treat our monitors as having thrice as many pixels horizontally than they actually do. When we render a character glyph, the body will be black, so no difference there. But if we calculate to need just a subpixel more to the left of a complete pixel, we will use that extra subpixel. Similarly, if we need to go just a subpixel to the right, we will use that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, using these individual subpixels rather than full pixels as with antialising, we will have color fringe inevitably because these subpixels are physically colored. Just look at your sample: all left edges have the same color fringe, yes, because that's the color of the last subpixel of the previous pixel. And right edges, similarly, have the color of the first subpixel of the next pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you can see in the screenshot is that the display sent to the monitor is pre-manipulated with the anticipation of the colored subpixels and displayed accordingly. Pixel colors are modified so that when they light up on the monitor screen, only those subpixels will be lit that are required by the calculations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Monitors might be different and, more importantly, individual sensitivity to this effect is different from person to person. Apple, using only their own monitors and in line with their usual stance of &quot;we tell you how to use it&quot;, only offers a way to switch this effect on or off in their user interface (although there is a way to select from a limited list of three different settings using the Terminal app and appropriate commands).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Windows or Linux, where the hardware selection is much broader and people don't normally accept to be allowed only a single way, ClearType can be adjusted to your individual needs. Depending on the settings you selected, the actual color fringes will be very different.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is just a compromise. In order to display text to be more legible, we sacrifice chrominance for luminance. Differences in intensity are more noticeable to the human brain than differences in color. So, even if it introduces color variations (which is absolutely not the intention but an inevitable consequence of the subpixels being colored), what we really see are the intensity differences. In simpler words, most of us will only perceive at that resolution and physical viewing distances that there is an extra subpixel, not that it has a different color.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And as to the final question of why gray in some places and colored in others, it's very probably a software issue. The browser you mentioned might have its own graphics rendering engine that simply works differently from what you normally have in the operating system. It's quite possible that it doesn't use the operating system's services to render text but renders everything by itself, pictures and texts as well, as a complete image and uses its own settings and techniques in the process.&lt;/p&gt;&#xA;" OwnerUserId="7555" LastEditorUserId="7555" LastEditDate="2019-01-01T13:53:50.913" LastActivityDate="2019-01-01T13:53:50.913" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8442" PostTypeId="1" CreationDate="2019-01-03T20:11:39.860" Score="1" ViewCount="648" Body="&lt;p&gt;I am rendering an infinite plane as described in the following answers:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/12965161/rendering-infinitely-large-plane&quot;&gt;https://stackoverflow.com/questions/12965161/rendering-infinitely-large-plane&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/7380250/how-to-render-a-plane-of-seemingly-infinite-size&quot;&gt;https://stackoverflow.com/questions/7380250/how-to-render-a-plane-of-seemingly-infinite-size&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Specifically, I am rendering an &quot;infinite&quot; XZ plane using the following five 4D vertices:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(0, 0, 0, 1)\quad(1, 0, 0, 0)\quad(0, 0, 1, 0)\quad(-1, 0, 0, 0)\quad(0, 0, -1, 0)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my engine, this is displayed as a ground plane at origin.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I would like to do is texture this plane. For now, it would be nice to just have a checkered grid. In my fragment shader, I am doing this via the varying &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; positions. This works fine for other &quot;non-infinite&quot; meshes, but for the infinite plane, it is incorrect. This is because the interpolated positions that are passed to the fragment shader don't really make sense in world space, as far as I can tell.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I compute the world-space position coordinates in my fragment shader?&#xA;Is it possible to compute them from the vertex positions, since they represent points at infinity?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The next step would be UV coordinates, but as I understand that might not be possible. I am interested more in being able to easily procedurally texture the plane rather than apply an image to it.&lt;/p&gt;&#xA;" OwnerUserId="9952" LastEditorUserId="9952" LastEditDate="2019-01-03T20:17:48.927" LastActivityDate="2019-01-04T13:53:13.523" Title="Texturing an &quot;infinite&quot; plane" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;texture&gt;&lt;geometry&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8443" PostTypeId="2" ParentId="8442" CreationDate="2019-01-03T21:30:47.527" Score="2" Body="&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\def\mvec#1{\begin{pmatrix}#1\end{pmatrix}}&#xA;\def\ivec#1{\left(\begin{smallmatrix}#1\end{smallmatrix}\right)}&#xA;\def\mmat#1{\begin{bmatrix}#1\end{bmatrix}}&#xA;\def\vec#1{\mathrm{\mathbf{#1}}}&#xA;\def\mat#1{\mathrm{\mathbf{#1}}}&#xA;$$&lt;/span&gt;&#xA;If you have the screen-space x and y coordinates as well as the depth of your fragment, you can directly compute the coordinates of the corresponding point in world-space. To do so, first compute the clip-space coordinates of your fragment&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;	\vec p'' = \mvec{&#xA;		2\cdot\frac{x}{r_x} - 1 \\&#xA;		2\cdot\frac{y}{r_y} - 1 \\&#xA;		2 \cdot z - 1 \\&#xA;		1&#xA;	}&#xA;\end{equation}&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; are the screen-space (pixel) coordinates of the fragment, &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; is the fragment depth, and &lt;span class=&quot;math-container&quot;&gt;$r_x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$r_y$&lt;/span&gt; are the width and height (resolution) of the viewport. The above computation is assuming that you're using OpenGL with the default depth range. If you're using Direct3D, use &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; directly without applying a scaling and offset. If you're using a depth range different from the default, apply whatever is the the appropriate inverse transformation in your case to get from screen-space to clip-space &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have the clip-space coordinates of your fragment, you can simply unproject the fragment by transforming with the inverse view-projection matrix:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;	\vec p' = \mat M^{-1} \vec p''&#xA;\end{equation}&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\mat M$&lt;/span&gt; would be your view-projection matrix. (Note: you will most likely want to pass the inverse view-projection matrix to the shader as a uniform as inverting the view-projection matrix in the shader for every fragment would most likely introduce quite some unnecessary overhead.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The final step is then to homogenize to get the world-space coordinates of the point&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;	\vec p = \frac{1}{p'_w} \cdot \mvec{&#xA;		p'_x \\&#xA;		p'_y \\&#xA;		p'_z&#xA;	}.&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By the way: It would seem to me that rendering this &quot;infinite plane&quot; should be possible using just a single triangle with all corners at infinity in different directions instead of four triangles. Since the boundary of your polygon is pushed to infinity, it shouldn't matter how many edges it has&amp;hellip;&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-01-04T13:53:13.523" LastActivityDate="2019-01-04T13:53:13.523" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8444" PostTypeId="1" AcceptedAnswerId="8631" CreationDate="2019-01-04T02:20:28.277" Score="5" ViewCount="1669" Body="&lt;p&gt;So I recently implemented Multiple Importance Sampling in my path tracer which was based on next event estimation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is without MIS I get images like,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7SL0B.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7SL0B.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is obtained by setting&lt;br&gt;&#xA;&lt;code&gt;light_sample *=  1/light_pdf;  // Note no mis_weight&lt;/code&gt;&lt;br&gt;&#xA;and just returning this sample alone. No BRDF sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where as with MIS as defined above I get darker images like,&#xA;&lt;a href=&quot;https://i.stack.imgur.com/QYyJw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QYyJw.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reason is surely the &lt;code&gt;mis_weight&lt;/code&gt; factor. From what I gathered over the internet my MIS code is ok but theoretically it doesn't seem right. For example suppose we performed Light Sampling first and obtained a &lt;code&gt;mis_weight&lt;/code&gt;. After that when we tried BRDF sampling, the ray didn't intersect any light source resulting in &lt;code&gt;light_pdf = 0&lt;/code&gt;. We neglected this estimate. Since we neglected this estimate isn't it wrong to weight our light sample by &lt;code&gt;mis_weight&lt;/code&gt; when we didn't even use multiple estimators, plus how is the sum of weights equal to 1 when we didnt even estimate anything using the BRDF pdf?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imo, &lt;code&gt;mis_weight&lt;/code&gt; factor in &lt;code&gt;light_sample&lt;/code&gt; should only be used when BRDF sampling also results in a light ray that intersects the light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anybody explain if these results are ok or there is something wrong with the code?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strike&gt;&lt;strong&gt;EDIT&lt;/strong&gt;:- There is another case which is a little confusing. I am currently using a heuristic (basically power/distance) to choose 1 light out of multiple lights. What if Light sampling and BRDF sampling choose different light sources. Is MIS still valid then? Since the PDF would change resulting the weights not being able to sum to 1 anymore&lt;/strike&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT2&lt;/strong&gt;:- So Stefan pointed out a mistake &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8469/naive-path-tracer-produces-much-darker-images-than-explicit-light-sampling?noredirect=1&amp;amp;lq=1&quot;&gt;here&lt;/a&gt;, that I was clamping radiance. And this solved that issue and changed the results I'm getting for MIS. I have double checked PBRT's implementation and it is similar to mine. I'm still getting darker images using MIS &lt;strike&gt;however now I'm getting more fireflies and I think I read that MIS reduces fireflies?&lt;/strike&gt; Updated the images. &lt;strong&gt;It seems fireflies are less in MIS however, the reflection seems harder to converge.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note the reflection is harder to converge. Both images are 1000 spp. Top is without MIS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WeiZN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WeiZN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/PPnyh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PPnyh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm removing the snippet and adding a link to github for the whole kernel. The core functions are &lt;code&gt;evaluateDirectLighting&lt;/code&gt;, &lt;code&gt;shading&lt;/code&gt;, &lt;code&gt;sampleLights&lt;/code&gt;. Link to code is &quot;&lt;a href=&quot;https://github.com/gallickgunner/Yune/blob/master/progressive-PT.cl&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;--&lt;strike&gt;Found a mistake. I was using the direct lighting equation when calculating the brdf sample. (multiplying by &lt;span class=&quot;math-container&quot;&gt;$\cos(\theta^{\prime})$&lt;/span&gt; and dividing by &lt;span class=&quot;math-container&quot;&gt;$r^2$&lt;/span&gt;). Removed it since we initially sampled through BSDF which is integral over solid angle not area. The image got a little brighter. Still don't know if MIS is working as intended.&lt;/strike&gt; See answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT3&lt;/strong&gt;:- Added a release as well. So if anybody wants, they can try changing the code in &quot;*.cl&quot; file and run the program to see the results. (You must have an OpenCL 1.1 supported GPU or CPU)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT4&lt;/strong&gt;:- Here's an overview of what I'm doing now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First I choose a single light source out of multiple using simple heuristic scheme like the distance, intensity, area and the cosine falloff angles. I appropriately set the weights for the light like this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$light\_pdf = weight/area$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where weight is in range 0-1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next I trace the ray to see if light source is visible. If it is I calculate the &lt;span class=&quot;math-container&quot;&gt;$light\_sample$&lt;/span&gt; using the direct lighting equation (integral over Area).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I calculate the BRDF PDF for this given ray. However I use Lafortune's algorithm for it. If a random number falls under the specular color I sample through the modfied Phong PDF else through Cosine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The weights are computed using power heuristic,&#xA;&lt;span class=&quot;math-container&quot;&gt;$ weight = light\_pdf^2/(light\_pdf^2+brdf\_pdf^2)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The MIS estimator is then calculated as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$light\_sample = light\_sample * weight/light\_pdf$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After that I come to BRDF sampling. I again sample through either Phong/Cosine based on what I did earlier during light sample calculation. If the sampled ray doesn't hit any light source or not the &lt;strong&gt;same&lt;/strong&gt; one. I set the &lt;span class=&quot;math-container&quot;&gt;$brdf\_sample$&lt;/span&gt; to zero. If it hits, I set the &lt;span class=&quot;math-container&quot;&gt;$light\_pdf$&lt;/span&gt; to same value as before. Calculate the weights like mentioned above and calculate brdf sample using the original equation (integral over solid angle).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT5&lt;/strong&gt;:- After lightxbulb suggestions, I think the problem has resolved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note the images might look a whole lot different but that's cause I implemented Tonemapping + Gamma Correction in the meantime :)&#xA;With MIS 700spp&#xA;&lt;a href=&quot;https://i.stack.imgur.com/1ZWKG.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1ZWKG.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Without MIS 700spp&#xA;&lt;a href=&quot;https://i.stack.imgur.com/jWrUa.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jWrUa.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-02-24T19:47:31.477" LastActivityDate="2019-02-24T19:47:31.477" Title="Multiple Importance Sampling in Path tracer produces Dark Images" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;&lt;importance-sampling&gt;" AnswerCount="2" CommentCount="13" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8445" PostTypeId="1" AcceptedAnswerId="8447" CreationDate="2019-01-06T07:04:02.643" Score="3" ViewCount="325" Body="&lt;p&gt;To be clear, I'm talking about behavior like &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Texture#Swizzle_mask&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengl/wiki/Texture#Swizzle_mask&lt;/a&gt;, not &quot;normal&quot; &lt;code&gt;myColorVariable.rbgr&lt;/code&gt; swizzling in a shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I really did start missing this feature after switching from OpenGL to Direct3D11, and ended up implementing a poor man's version in HLSL. Initially, I just assumed this was another &quot;feature&quot; of OpenGL that didn't actually exist on any hardware and was just being emulated by every driver, but then I noticed that Vulkan supports it as well. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My understanding is that the Vulkan specification is not supposed to include &quot;extras&quot; that aren't supported by hardware, so what gives? Why is this feature present in OpenGL/Vulkan and not Direct3D/Metal?&lt;/p&gt;&#xA;" OwnerUserId="9962" LastActivityDate="2019-01-06T18:20:40.817" Title="Why don't Direct3D/Metal support texture swizzles?" Tags="&lt;directx11&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8446" PostTypeId="1" AcceptedAnswerId="8448" CreationDate="2019-01-06T09:32:47.383" Score="1" ViewCount="44" Body="&lt;p&gt;What would be the best way to make a texture a clickable button? Suppose I have a Room (respresented by a 2D texture), where there are buttons. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would I in the main loop:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;check when the mouse is clicked if it is in any region of a button? (&lt;span class=&quot;math-container&quot;&gt;$\mathcal{O}(n_{Button})$&lt;/span&gt;)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Do something entirely different that I can't think of?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I may be overthinking this, maybe this isn't a problem at all, but somehow, what I came up with sounds way to &quot;stupid&quot; to me to be the right solution. It sounds like a hack to me, but maybe this is the way to do it? In 3D Games, would the check than be just radial coordinates (&lt;span class=&quot;math-container&quot;&gt;$r,\phi,\theta$&lt;/span&gt;)?&lt;/p&gt;&#xA;" OwnerUserId="9963" LastActivityDate="2019-01-06T17:15:20.493" Title="Make a texture a clickable Button" Tags="&lt;texture&gt;&lt;algorithm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8447" PostTypeId="2" ParentId="8445" CreationDate="2019-01-06T15:04:24.507" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Why is this feature present in OpenGL/Vulkan and not Direct3D/Metal?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's present in OpenGL because someone thought it would be a good idea, wrote an &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_swizzle.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL extension specification&lt;/a&gt; for it, released and supported the extension in their drivers, and the extension was eventually adopted into core profile. While it's usually pretty obvious why feature X &lt;em&gt;is&lt;/em&gt; present in some API (because it's a thing that makes sense to have), it's generally hard to say why feature X &lt;em&gt;is not&lt;/em&gt; present in some other API. There's a wide range of possible reasons. You would have to talk to whoever were the people responsible for the design of the API in question at the time to find out&amp;hellip;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Concerning hardware support: In case of doubt, you can simply convince yourself by comparing rendering times with and without using a texture swizzle. You would notice if you were hitting a software path there. The fact that the extension was introduced by NVIDIA would lead me to the conclusion that there's at least one hardware vendor that is able to support this on their hardware; otherwise, why would they introduce it!? If you think about it: Texture sampling hardware already has to support &lt;em&gt;lots&lt;/em&gt; of different formats (floating point, signed integer, unsigned integer, normalized signed integer, normalized unsigned integer, all for different numbers of components, component sizes, sRGB versions for some, compressed formats, &amp;hellip;) including some where the order of components is different on the output side from what it is on the input side (e.g., BGRA). Adding a few bits to the texture descriptor to control which components go where in the output is probably not a big deal. I'm not a hardware engineer, but it would seem to me that it probably even makes the hardware simpler because it reduces the number of special cases. So I'd say chances are that hardware was already using a swizzle mask internally long before it was exposed on the API side&amp;hellip;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apart from that, while I don't know about Metal, Direct3D 12 does allow you to specify a &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/ne-d3d12-d3d12_shader_component_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;shader component mapping&lt;/a&gt; when creating a resource view, which is effectively exactly the same thing as the OpenGL texture swizzle mask&amp;hellip;&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-01-06T18:20:40.817" LastActivityDate="2019-01-06T18:20:40.817" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8448" PostTypeId="2" ParentId="8446" CreationDate="2019-01-06T17:15:20.493" Score="3" Body="&lt;p&gt;In games and other 3D scenes, generally when the user clicks the mouse, a ray is cast into the scene in the direction the camera is facing, and a check is done to see what geometry in the scene it intersects. If it intersects nothing, it is ignored. If it intersects a single object, then the application processes a click on that object (at the location of the intersection). If more than one object is intersected, then usually the front-most object is assumed to be the on the user wanted to click on, so that is processed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, geometry is stored using x,y,z coordinates rather than spherical coordinates, as the GPU hardware works in cartesian coordinates.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-01-06T17:15:20.493" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8449" PostTypeId="1" AcceptedAnswerId="8454" CreationDate="2019-01-06T18:49:10.817" Score="3" ViewCount="1043" Body="&lt;p&gt;I'm reading up on coordinate systems and geometric transformations but the change of basis topic still confuses me. I found this exercise but, honestly, I wouldn't know how to begin:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Given a world coordinate system in which the camera is at &lt;span class=&quot;math-container&quot;&gt;$(3,3,0)$&lt;/span&gt; and pointed at the origin &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; write an orthonormal set &lt;span class=&quot;math-container&quot;&gt;$(e_1, e_2, e_3)$&lt;/span&gt; with an axis oriented like the camera axis and the matrix for the change of coordinates from world frame to camera frame &lt;span class=&quot;math-container&quot;&gt;$(O, e_1, e_2, e_3)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Do I need to use homogeneous coordinates or not? Currently, I'm using the book &lt;a href=&quot;https://www.pearson.com/us/higher-education/product/Angel-Interactive-Computer-Graphics-A-Top-Down-Approach-with-Shader-Based-Open-GL-6th-Edition/9780132545235.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;Interactive Computer Graphics: A Top-Down Approach with Shader-Based OpenGL&lt;/em&gt;&lt;/a&gt;. If anyone could suggest a better alternative I'd be grateful. &lt;/p&gt;&#xA;" OwnerUserId="9966" LastEditorUserId="9812" LastEditDate="2019-01-07T11:29:34.837" LastActivityDate="2019-01-14T08:57:39.057" Title="Need help with change of basis (world to camera frame)" Tags="&lt;transformations&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8451" PostTypeId="1" AcceptedAnswerId="8453" CreationDate="2019-01-07T06:22:09.143" Score="3" ViewCount="868" Body="&lt;p&gt;In Cg tuts, &lt;a href=&quot;http://developer.download.nvidia.com/CgTutorial/cg_tutorial_chapter05.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Diffuse Section&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Surfaces that face away from the light will produce negative dot-product values, so the max(N · L, 0) in the equation ensures that these surfaces show no diffuse lighting.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;My question is why not just leave it be negative? IMO, both the negative and zero will make the color be black. &lt;/p&gt;&#xA;" OwnerUserId="3416" LastActivityDate="2019-01-07T16:59:58.463" Title="Why Diffuse Light use max(N · H, 0) instead of just letting it be negative?" Tags="&lt;lighting&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8452" PostTypeId="2" ParentId="8451" CreationDate="2019-01-07T06:30:08.520" Score="2" Body="&lt;p&gt;Because negative shading values are undefined and don't play well with tonemapping. It is preferable to use values in &lt;span class=&quot;math-container&quot;&gt;$[0,1]$&lt;/span&gt; for low-dynamic-range or &lt;span class=&quot;math-container&quot;&gt;$[0,+\infty)$&lt;/span&gt; for high-dynamic-range images.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastActivityDate="2019-01-07T06:30:08.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8453" PostTypeId="2" ParentId="8451" CreationDate="2019-01-07T07:13:41.747" Score="10" Body="&lt;p&gt;If lighting with multiple lights, they add together to make the final lighting value. A negative light would darken other lights, which is incorrect.  This is also true if you add in specular reflections, emissive lighting, or other sources of lighting. The negative lighting from one source of lighting would darken some other source of non negative lighting.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2019-01-07T07:13:41.747" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8454" PostTypeId="2" ParentId="8449" CreationDate="2019-01-07T14:57:56.453" Score="4" Body="&lt;p&gt;Since the transformation that is asked for includes a translation (the camera is located at a position other than the origin), you will indeed have to use homogeneous coordinates to describe this transformation in matrix form.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are basically two ways to get to the matrix you're looking for. You can either set up the matrix that would transform from camera coordinates to world-space and then take the inverse of that, or you can build the matrix directly. The first approach is what is typically done and what the exercise seems to be aiming for since it explicitly asks for the base vectors of the camera system as seen from world-space, which is the first step in that process. The advantage of this approach is that it is arguably a bit more intuitive since what you're essentially doing is treat the camera as just another object that you place in world-space by setting up a matrix. Just that once you have that matrix, you invert it because you didn't actually want to get from camera-local coordinates to world coordinates but rather the other way around. I'll explain both approaches below using the concrete example given in your exercise. At least for now, I'll leave the generalization of the ideas presented below as an exercise to the reader (so that at least some of the fun remains for you ).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's look at a sketch of the whole situation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\def\mvec#1{\begin{pmatrix}#1\end{pmatrix}}&#xA;\def\ivec#1{\left(\begin{smallmatrix}#1\end{smallmatrix}\right)}&#xA;\def\mmat#1{\begin{bmatrix}#1\end{bmatrix}}&#xA;\def\vec#1{\mathrm{\mathbf{#1}}}&#xA;\def\mat#1{\mathrm{\mathbf{#1}}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/NnAhM.png&quot; width=&quot;320&quot; /&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your camera is located at &lt;span class=&quot;math-container&quot;&gt;$\vec o = \mvec{3 &amp;amp; 3 &amp;amp; 0}^T$&lt;/span&gt; and is supposed to be looking at the origin. By general convention, the camera is set up to be looking along the line of the z-axis of its local coordinate frame, while the local x-axis points right and the local y-axis points up. Therefore, we know that &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt; should be pointing either at or away from the origin. Since you're talking about OpenGL, I assumed right-handed world and camera coordinate systems as is typically done in OpenGL-land. To get a right-handed coordinate frame where the local x points to the right, local y points up, and local z lines up with the viewing direction, &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt; can only to be pointing in the direction away from the point at which the camera is looking. Once we have fixed &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt;, we have to define the remaining two base vectors. Note that no matter what we choose for &lt;span class=&quot;math-container&quot;&gt;$\vec e_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec e_2$&lt;/span&gt;, our camera will be looking at the origin. Our choice of &lt;span class=&quot;math-container&quot;&gt;$\vec e_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec e_2$&lt;/span&gt; basically just fixes the rotation of the camera around the viewing direction, which is set by &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt;. Generally, one choses &lt;span class=&quot;math-container&quot;&gt;$\vec e_1$&lt;/span&gt; such that it is orthogonal to both, &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt;, and a general &quot;up&quot; direction. &lt;span class=&quot;math-container&quot;&gt;$\vec e_2$&lt;/span&gt; is then simply computed to be orthogonal to both, &lt;span class=&quot;math-container&quot;&gt;$\vec e_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Approach 1&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;From the above sketch, it is immediately apparent that the coordinates of &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt; have to be&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \vec e_3 = \frac{1}{\sqrt{3^2 + 3^2 + 0}} \mvec{3 \\ 3 \\ 0} = \frac{1}{\sqrt{2\cdot3^2}} \mvec{3 \\ 3 \\ 0} = \mvec{\frac{1}{\sqrt2} \\ \frac{1}{\sqrt2} \\ 0}.&#xA;\end{equation}&lt;/span&gt;&#xA;Since our camera is located in the x-y-plane in this example, the base vector &lt;span class=&quot;math-container&quot;&gt;$\vec e_2$&lt;/span&gt; is just &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt; rotated by &lt;span class=&quot;math-container&quot;&gt;$90°$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \vec e_2 = \mvec{-\frac{1}{\sqrt2} \\ \frac{1}{\sqrt2} \\ 0},&#xA;\end{equation}&lt;/span&gt;&#xA;and &lt;span class=&quot;math-container&quot;&gt;$\vec e_1$&lt;/span&gt; just points in the direction opposite of the world-space z-axis:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \vec e_1 = \mvec{0 \\ 0 \\ -1}.&#xA;\end{equation}&lt;/span&gt;&#xA;Using the world-space base vectors of the camera frame, we can write down a matrix that transforms from camera-space to world-space. The camera matrix that transforms from camera to world coordinates is then simply the inverse of that matrix:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \mat M_{cam}^{-1} = \mmat{\vec e_1 &amp;amp; \vec e_2 &amp;amp; \vec e_3 &amp;amp; \vec o \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1}&#xA;         = \mmat{&#xA;    0 &amp;amp; -\frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 3 \\&#xA;    0 &amp;amp; \frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 3 \\&#xA;    -1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1}.&#xA;\end{equation}&lt;/span&gt;&#xA;Since the camera frame has an &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthonormality&quot; rel=&quot;nofollow noreferrer&quot;&gt;orthonormal base&lt;/a&gt; just offset by &lt;span class=&quot;math-container&quot;&gt;$\vec o$&lt;/span&gt;, this matrix is composed of just the rotation defined by the orthonormal base vectors followed by a translation:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \mat M_{cam}^{-1} = \mat T \mat R&#xA;\end{equation}&lt;/span&gt;&#xA;where&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;  \mat R &amp;amp;= \mmat{&#xA;    0 &amp;amp; -\frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 \\&#xA;    0 &amp;amp; \frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 \\&#xA;    -1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1} &amp;amp; &#xA;  \mat T &amp;amp;= \mmat{&#xA;    1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 3 \\&#xA;    0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 3 \\&#xA;    0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1}.&#xA;\end{align}&lt;/span&gt;&#xA;You can convince yourself that this is true by simply performing the multiplication. Knowing this, we can compute the camera matrix:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \mat M_{cam} = (\mat T \mat R)^{-1} = \mat R^{-1} \mat T^{-1}.&#xA;\end{equation}&lt;/span&gt;&#xA;Since &lt;span class=&quot;math-container&quot;&gt;$\mat R$&lt;/span&gt; is composed of orthonormal base vectors, it is an orthogonal matrix, which means that its inverse is just its transpose. &lt;span class=&quot;math-container&quot;&gt;$\mat T$&lt;/span&gt; is just a translation, its inverse is a translation in the opposite direction. Therefore,&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \begin{split}&#xA;  \mat M_{cam} &amp;amp;= \mmat{&#xA;    0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\&#xA;    -\frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 &amp;amp; 0 \\&#xA;    \frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1} \cdot \mmat{&#xA;    1 &amp;amp; 0 &amp;amp; 0 &amp;amp; -3 \\&#xA;    0 &amp;amp; 1 &amp;amp; 0 &amp;amp; -3 \\&#xA;    0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1} \\&#xA;    &amp;amp;= \mmat{&#xA;    0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\&#xA;    -\frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 &amp;amp; 0 \\&#xA;    \frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 &amp;amp; -3\sqrt2 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1}.&#xA;  \end{split}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Approach 2&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;An alternative to the approach above is to just directly compute the coordinates of the world-space base vectors as seen from the perspective of the camera. Given these coordinates, we can, again, just write down a matrix that applies the corresponding transformation from world to camera space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking at the figure again, we see that the coordinates of the world-space x-axis as seen from camera space are&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \vec x' = \mvec{0 \\ -\frac{1}{\sqrt2} \\ \frac{1}{\sqrt2}}.&#xA;\end{equation}&lt;/span&gt;&#xA;Analogously, we find the camera-space coordinates of the world-space y- and z-axes:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;  \vec y' &amp;amp;= \mvec{0 \\ \frac{1}{\sqrt2} \\ \frac{1}{\sqrt2}} &amp;amp; &#xA;  \vec z' &amp;amp;= \mvec{-1 \\ 0 \\ 0}.&#xA;\end{align}&lt;/span&gt;&#xA;Also looking at the figure, we note that the world-space origin as seen from the camera is simply located at a distance of &lt;span class=&quot;math-container&quot;&gt;$\sqrt{3^2 + 3^2} = 3\sqrt{2}$&lt;/span&gt; units along the negative &lt;span class=&quot;math-container&quot;&gt;$\vec e_3$&lt;/span&gt; axis. Therefore, the camera-space coordinates of the world origin are&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \vec o' = \mvec{0 \\ 0 \\ -3\sqrt{2}}.&#xA;\end{equation}&lt;/span&gt; and we can, once again, write down the matrix&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \begin{split}&#xA;  \mat M_{cam} &amp;amp;= \mmat{&#xA;    0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\&#xA;    -\frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 &amp;amp; 0 \\&#xA;    \frac{1}{\sqrt2} &amp;amp; \frac{1}{\sqrt2} &amp;amp; 0 &amp;amp; -3\sqrt2 \\&#xA;    0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1}&#xA;  \end{split},&#xA;\end{equation}&lt;/span&gt;&#xA;and sleep well tonight because both ways did indeed lead to the same result…&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-01-14T08:57:39.057" LastActivityDate="2019-01-14T08:57:39.057" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8455" PostTypeId="2" ParentId="8451" CreationDate="2019-01-07T16:59:58.463" Score="2" Body="&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$N \cdot L &amp;lt; 0$&lt;/span&gt; implies that the light is directed in the direction opposite the normal to the visible surface of the polygon. This means that the light is coming from behind and striking the back face of the polygon. In the analogous situation in real life, light striking one face of an opaque surface does not affect the illumination of a second face. Shining light on the back of a book (or other opaque object) does make the front of the book darker (that is it does not apply negative lighting): it simply has no effect on the front face of the book. This is the reason for the max() function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying negative illumination to a surface where &lt;span class=&quot;math-container&quot;&gt;$N \cdot L &amp;lt; 0$&lt;/span&gt; doesn't make sense physically. In geometric optics with incoherent light sources there is no such thing as negative illumination.&lt;/p&gt;&#xA;" OwnerUserId="9976" LastActivityDate="2019-01-07T16:59:58.463" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8456" PostTypeId="1" CreationDate="2019-01-08T05:17:53.997" Score="3" ViewCount="397" Body="&lt;p&gt;I am in the middle of implementing stochastic screen space reflection based on frostbite presentation &lt;a href=&quot;http://www.cse.chalmers.se/edu/course/TDA361/Advanced%20Computer%20Graphics/Screen-space%20reflections.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. On page number 39, it is stated that we need to reproject the ray intersection location instead of the reflected surface location. I don't really get what's the difference between the two. Isn't ray intersection location the same as the reflected surface location. Can someone explain this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then in another &lt;a href=&quot;https://www.ea.com/frostbite/news/stochastic-screen-space-reflections&quot; rel=&quot;nofollow noreferrer&quot;&gt;ppt&lt;/a&gt;, they mention that&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I mentioned temporal reprojection, so let’s have a quick look at it&#xA;  now. The idea is simple: given a pixel’s 3D coordinate, check where it&#xA;  was in the previous frame, project it, and we have the texcoord to&#xA;  sample.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;… except when we move the viewport, reflections exhibit parallax. That&#xA;  is, the reflected objects move according to their depth, not the depth&#xA;  of the surface which reflects them. Attempting to reproject&#xA;  reflections using the closer depth results in smearing. So we&#xA;  calculate the average depth of the reflected objects, and reproject&#xA;  using that. This results in much reduced smearing.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Again I don't understand this at all.&lt;/p&gt;&#xA;" OwnerUserId="8565" LastEditorUserId="5778" LastEditDate="2019-08-15T09:03:49.697" LastActivityDate="2020-11-19T14:08:21.353" Title="What to reproject when doing temporal filtering in stochastic screen space reflection?" Tags="&lt;projections&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8458" PostTypeId="1" CreationDate="2019-01-08T12:44:42.460" Score="0" ViewCount="366" Body="&lt;p&gt;I'm a newbie with OpenGl and I'm stuck in following the tutorial. &#xA;I found &lt;a href=&quot;https://open.gl/textures&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial&lt;/a&gt; with these shaders&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Shader sources&#xA;const GLchar* vertexSource = R&quot;glsl(&#xA;    #version 150 core&#xA;    in vec2 position;&#xA;    in vec3 color;&#xA;    in vec2 texcoord;&#xA;    out vec3 Color;&#xA;    out vec2 Texcoord;&#xA;    void main()&#xA;    {&#xA;        Color = color;&#xA;        Texcoord = texcoord;&#xA;        gl_Position = vec4(position, 0.0, 1.0);&#xA;    }&#xA;)glsl&quot;;&#xA;const GLchar* fragmentSource = R&quot;glsl(&#xA;    #version 150 core&#xA;    in vec3 Color;&#xA;    in vec2 Texcoord;&#xA;    out vec4 outColor;&#xA;    uniform sampler2D tex0;&#xA;    void main()&#xA;    {&#xA;        outColor = texture(tex0, Texcoord) * vec4(Color, 1.0);&#xA;    }&#xA;)glsl&quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I noticed that the proposed shaders couldn't compile in my computer, since my GLsl version is 1.30, but changing the version declaration into&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 130 core&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the ouput of this instruction is &lt;code&gt;glGetShaderInfoLog(vertexShader, 512, NULL, infoLog)&lt;/code&gt;;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;0:2(10): error: illegal text following version number&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I wuould like to understand what is wrong in this shader (in version 1.30) or at least where to find enough information to &quot;repair&quot; this situation.&#xA;Thanks&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;#UPDATE 1&lt;/strong&gt;&#xA;I managed to have compiling shaders with no errors, but still the program does not work.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Shader sources&#xA;//in --&amp;gt; attribute&#xA;//out --&amp;gt; varying&#xA;const GLchar* vertexSource = R&quot;glsl(&#xA;    #version 130&#xA;    attribute vec2 position;&#xA;    attribute vec3 color;&#xA;    attribute vec2 texcoord;&#xA;    varying vec3 Color;&#xA;    varying vec2 Texcoord;&#xA;    void main()&#xA;    {&#xA;        Color = color;&#xA;        Texcoord = texcoord;&#xA;        gl_Position = vec4(position, 0.0, 1.0);&#xA;    }&#xA;)glsl&quot;;&#xA;&#xA;//in --&amp;gt; varying&#xA;//out --&amp;gt; (delete)&#xA;const GLchar* fragmentSource = R&quot;glsl(&#xA;    #version 130&#xA;    varying vec3 Color;&#xA;    varying vec2 Texcoord;&#xA;    uniform sampler2D tex0;&#xA;    void main()&#xA;    {&#xA;       gl_FragColor = texture2D(tex0, Texcoord) * vec4(Color, 1.0);&#xA;    }&#xA;)glsl&quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I used some functions like this to confirm that shaders are successfully compiled and linked&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int success; char infoLog[512];&#xA;glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &amp;amp;success); &#xA;//can also use GL_LINK_STATUS flag&#xA;if(!success)&#xA;{&#xA;    glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);&#xA;    std::cout &amp;lt;&amp;lt; &quot;ERROR::SHADER::VERTEX::COMPILATION_FAILED\n&quot; &amp;lt;&amp;lt; infoLog &amp;lt;&amp;lt; std::endl;&#xA;    std::cout &amp;lt;&amp;lt;  glGetString(GL_SHADING_LANGUAGE_VERSION) &amp;lt;&amp;lt; std::endl;&#xA;    std::cout &amp;lt;&amp;lt;  success &amp;lt;&amp;lt; std::endl;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9982" LastEditorUserId="9982" LastEditDate="2019-01-09T13:57:16.580" LastActivityDate="2019-01-09T13:57:16.580" Title="Convert shader from GLsl 1.50 to 1.30" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8459" PostTypeId="2" ParentId="8458" CreationDate="2019-01-08T14:31:07.597" Score="4" Body="&lt;p&gt;There is no such thing as a core profile in GLSL 1.30. The concept of API profiles was introduced with OpenGL 3.2 which happened after GLSL 1.30 was released. The syntax for the version specification in &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.1.30.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLSL 1.30&lt;/a&gt; is &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version &amp;lt;number&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Apart from that, I highly recommend that you check to confirm that GLSL 1.30 &lt;em&gt;really&lt;/em&gt; is the maximum version you're supposed to be able to use on your system. It seems not unlikely that you just don't have a proper OpenGL driver installed. Even software implementations like MESA support more recent versions than that these days…&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-01-09T00:08:49.577" LastActivityDate="2019-01-09T00:08:49.577" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8460" PostTypeId="2" ParentId="8444" CreationDate="2019-01-08T14:46:33.790" Score="1" Body="&lt;p&gt;One of the first things that many people get wrong with MIS of direct lighting is that you have to always consider the same light source for both light sampling and BSDF sampling. For example, if you sampled Light &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; during light sampling and the ray spawned from BSDF sampling hit &lt;span class=&quot;math-container&quot;&gt;$L_j$&lt;/span&gt;, you cannot mix them together since the probabilities cannot be used together for weights. &lt;/p&gt;&#xA;" OwnerUserId="1940" LastActivityDate="2019-01-08T14:46:33.790" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8462" PostTypeId="1" CreationDate="2019-01-08T22:09:11.980" Score="2" ViewCount="868" Body="&lt;p&gt;I am working with an atlas shader that steps through various sprite tiles within a single png atlas page to playback an animation with sampler2D.  Looking at the shader code, I would expect to have to define a lower left and upper right point for each image area on the atlas image that I want to use for that frame.  However, it simply uses a Vec2 which is just a single x,y value.  How is this possible?  How is a single vec2 defining both position and range of the sampled area?  In a more broad sense how are these UV vec2s from varying UVs being interpreted in GLSL in general?  To me, you can't define an image area from just a vec2 so I am really confused???&lt;/p&gt;&#xA;" OwnerUserId="9983" LastActivityDate="2020-09-30T11:03:25.357" Title="How does a GLSL Sampler2D read a Vec2 UV coordinate to determine UV range" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;uv-mapping&gt;&lt;image&gt;&lt;tile-based-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8463" PostTypeId="2" ParentId="8462" CreationDate="2019-01-09T08:39:49.520" Score="1" Body="&lt;p&gt;It's hard to say without seeing the shader in question. My guess is that every animation frame in the atlas has the same size. This fixed size allows mapping any UV coordinates to the proper animation frame's UV extents.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, with 16 frames in a texture:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0 0.25 0.5 0.75 1.0&#xA;\  \   |   /  _/&#xA; +--+--+--+--+&#xA; | 0| 1| 2| 3|&#xA; +--+--+--+--+ 0.25&#xA; | 4| 5| 6| 7|&#xA; +--+--+--+--+ 0.5&#xA; | 8| 9|10|11|&#xA; +--+--+--+--+ 0.75&#xA; |12|13|14|15|&#xA; +--+--+--+--+ 1.0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This code should do the trick to convert UV coordinates (range [0, 1]) to a given frame's UV extents:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = ...&#xA;uint frameId = ... // [0, 15]&#xA;const uint rowFrameCount = 4; // implies frameUVWidth = 1 / 4 = 0.25&#xA;const vec2 frameUVSize = vec2(1.0 / rowFrameCount, 0.25);&#xA;&#xA;// Find the column and row offset&#xA;uvec2 frameOffset = uvec2(frameId % rowFrameCount, frameId / rowFrameCount);&#xA;&#xA;// Offset to the proper column&#xA;uv += frameOffset;&#xA;&#xA;// Scale the coordinates in the range of a single frame (here [f_0, f_0 + 0.25])&#xA;uv *= frameUVSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Some results:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uv = vec2(0, 1); frameId = 0; uv_out = vec2(0, 0.25);&#xA;uv = vec2(0, 0.5); frameId = 3; uv_out = vec2(0.75, 0.125);&#xA;uv = vec2(0.5, 0.5); frameId = 14; uv_out = vec2(0.625, 0.875);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In truth however, this kind of texture trickery is less useful these days since &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Array_Texture&quot; rel=&quot;nofollow noreferrer&quot;&gt;array textures&lt;/a&gt; are now widely available with better results and simpler indexing.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2019-01-09T08:39:49.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8465" PostTypeId="1" AcceptedAnswerId="8466" CreationDate="2019-01-10T03:11:58.123" Score="1" ViewCount="712" Body="&lt;p&gt;I've read many articles relating to importance sampling of GGX. However, I still feel confused.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The formula of GGX is :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jFUh6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jFUh6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And many article says we should use this formula to sample:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ecrsO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ecrsO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the formula, theta is the angle between the normal and the halfvector. So what the formula shows is how to sample a angle between normal and halfvector? But, in the article &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&lt;/a&gt;&#xA;it says &quot;To importance sample D(ω^m) we will use the inverse of the CDF of D(ω^m) to generate a microfacet normal ω^m. If you are familar with using GGX in game rendering this can be thought of as creating a half vector in tangent space.&quot; How is theta related to microfacet normal? How can I sample a Li based on the theta?&lt;/p&gt;&#xA;" OwnerUserId="9987" LastActivityDate="2019-01-10T07:36:57.330" Title="Can't understand the Importance sampling GGX" Tags="&lt;pbr&gt;&lt;importance-sampling&gt;&lt;microfacet&gt;&lt;ggx&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8466" PostTypeId="2" ParentId="8465" CreationDate="2019-01-10T07:36:57.330" Score="2" Body="&lt;p&gt;In microfacet BRDFs, the half-vector is the same as the microfacet normal. The half-vector is exactly the required normal for a microfacet to reflect light from the incident ray to the outgoing ray, by the law of reflection. So, for given incident and outgoing directions, only those microfacets whose normals are aligned with the half-vector are &quot;active&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Conversely, when importance-sampling a microfacet distribution, we wish to select a random microfacet normal, then reflect the incident ray through this normal to produce the outgoing ray. The incident and outgoing rays will then have the chosen microfacet normal as their half-vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For an isotropic BRDF, you will sample theta from the inverse CDF, and you must also sample phi, the azimuth angle about the normal, uniformly between 0 and 2π; then convert those into a unit vector using the usual spherical coordinates (as mentioned in the linked blog post), combined with a tangent-to-world transformation. For an anisotropic BRDF, both theta and phi would be supplied by sampling an inverse CDF.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-01-10T07:36:57.330" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8468" PostTypeId="2" ParentId="1736" CreationDate="2019-01-10T18:05:53.947" Score="4" Body="&lt;p&gt;Be careful, using a single frustum for culling only works if the combined field of view of the eyes is less than 180 degrees. There are now VR headsets with a larger field of view around 200 degrees, i.e. the &lt;a href=&quot;https://pimaxvr.com/products/pimax-5k-series&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pimax 5k+&lt;/a&gt; and &lt;a href=&quot;https://www.starvr.com/products/&quot; rel=&quot;nofollow noreferrer&quot;&gt;StarVR&lt;/a&gt;. It's impossible to construct a traditional view frustum or single projection matrix for a field of view over 180 degrees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These headsets use angled screens, so the projection planes and the forward vectors in view space are not parallel. The equations from the other answers here assume that they are parallel, and would produce incorrect results when that assumption is wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A single combined view frustum can still be useful, but your code should be prepared to deal with cases where this can't be constructed to ensure that it's future proof. Alternatively, consider doing culling per eye view, or switch to angle-based culling which can express a larger-than-180-degree FOV.&lt;/p&gt;&#xA;" OwnerUserId="9990" LastActivityDate="2019-01-10T18:05:53.947" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8469" PostTypeId="1" AcceptedAnswerId="8471" CreationDate="2019-01-11T17:45:40.243" Score="2" ViewCount="445" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Jyt1Z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Jyt1Z.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I just thought of comparing the results from a Naive Path tracer and one using Next Event Estimation aka Explicit Direct Light Sampling. However the results from the Naive PT are very dark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this expected? The one with next event estimation produces brighter images like in my &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8444/multiple-importance-sampling-in-path-tracer-produces-dark-images&quot;&gt;previous&lt;/a&gt; question which was related to MIS&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought that a Naive PT would produce images with the same brightness but more noise and it would take longer to converge. The main reason for dark images I think is because I'm averaging the colors obtained from the previous run with the next run. On each run I shoot 1 sample per pixel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means if I take 20 samples (20 passes) and only 2 samples (&lt;span class=&quot;math-container&quot;&gt;$S_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$S_2$&lt;/span&gt;) are useful (hit the light in the end) and 18 return 0 since they don't hit the light, I'd be doing, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\displaystyle{\frac{S_1 + S_2 + 0*18}{20}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The brighter colors will surely get averaged out. Moreover they won't converge or in other words they won't get brighter since the number of useless samples surely outweigh the number of useful samples. However in every implementation I could find over the net, people averaged it simply like I did. So is that actually a problem or is it expected?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I stumbled upon &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/7915/should-direct-illumination-and-path-tracers-render-the-same-scene-equally-bright?rq=1&quot;&gt;this&lt;/a&gt; question which is pretty much the same thing OP is asking but in the end they find problem with the raytracer and not the path tracer. I don't understand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you guys are interested in the code, &lt;a href=&quot;https://github.com/gallickgunner/Helion-Render/blob/master/naivept.cl&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; is my kernel. The main functions to look for are &lt;code&gt;shading()&lt;/code&gt; which contains the whole bouncing around portion. &lt;code&gt;EvaluateBRDF&lt;/code&gt; simply evaluates the blinn phong model. The averaging out is done in the main kernel &lt;code&gt;evaluatePixelRadiance&lt;/code&gt; in the end.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPDATE:- So I corrected what Stefan pointed out and removed color clamping. I was using an 8bit depth default framebuffer and RBO of 32 bit floating points. So I guess the data gets clamped automatically when blitting to the default framebuffer. And it seems to have solved the issue. I'll update the results shortly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think this solved my MIS issue as well, will share results on MIS post soon. Here is the one for naive-PT, 5000 samples in around 10 seconds. And it seems I was not getting fireflies since i was clamping radiance as expected. Good to learn new things :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HVXUg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HVXUg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-01-13T13:11:50.303" LastActivityDate="2019-01-13T13:11:50.303" Title="Naive Path tracer produces much darker images than Explicit light sampling" Tags="&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8470" PostTypeId="1" AcceptedAnswerId="8472" CreationDate="2019-01-11T18:33:23.003" Score="1" ViewCount="1060" Body="&lt;p&gt;I have a 3D triangular mesh(vertices, indices, uv coords) that I'm rendering to the screen. Let's assume that the UV mapping is one-to-one. I'm trying to find a way to find the 3D position of the point with UV coordinates equal to (0,0). I searched the internet but I only find answers that I don't find convincing. &#xA;The solution that I found: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Find, in UV space, the triangle that contains (0,0).. let's call it T &lt;/li&gt;&#xA;&lt;li&gt;Calculate barycentric coordinates for (0,0) with respect to T &lt;/li&gt;&#xA;&lt;li&gt;interpolate the 3D positions of T's vertices using barycentric coords to get the result. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;this seems wrong to me. Here's why: &#xA;Let M be the mapping between 3D space and UV space that associates UV coords for every vertex. &#xA;Let A,B and C be the vertices of T. &#xA;Let P be the origin of UV space ( P = (0,0) ). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have P = alpha*A + beta * B + gamma*C (alpha,beta and gamma are the barycentric coords of P with respect to T). &#xA;We assumed the UV mapping to be one-to-one, so let M° be the inverse of M. &#xA;We have : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;M°(P) = M°(alpha*A + beta * B + gamma*C)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The solution in question assumes that M° is linear.. if that was the case you can have: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;M°(P) = alpha*M°(A) + beta * M°(B) + gamma*M°(C)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But that is not the case (correct me if I'm wrong). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is there a way to find the 3D position of a point with specific UV coords? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="9994" LastActivityDate="2019-01-13T21:49:36.183" Title="How to get the 3D position for the point with (0,0) UV coordinates?" Tags="&lt;3d&gt;&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8471" PostTypeId="2" ParentId="8469" CreationDate="2019-01-11T20:04:39.607" Score="3" Body="&lt;p&gt;It looks like you're clamping all your samples to 0-1 in line 215. Apply clamping only when displaying the image, not when accumulating samples.&lt;/p&gt;&#xA;" OwnerUserId="4546" LastActivityDate="2019-01-11T20:04:39.607" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8472" PostTypeId="2" ParentId="8470" CreationDate="2019-01-11T20:25:47.640" Score="1" Body="&lt;p&gt;I realize that the solution I'm giving further below is basically the one you mentioned in your question. So let's begin by addressing this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The solution in question assumes that M° is linear.. if that was the case you can have:&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;M°(P) = alpha*M°(A) + beta * M°(B) + gamma*M°(C)&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;But that is not the case (correct me if I'm wrong). &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The solution in question works directly in UV space. I don't see where it would make any assumptions concerning the nature or even existence of a &quot;mapping from 3D to UV space&quot;!? All it does assume is that UV coordinates vary linearly across each triangle (note: each triangle, not the entire mesh)&amp;hellip;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\def\mvec#1{\begin{pmatrix}#1\end{pmatrix}}&#xA;\def\ivec#1{\left(\begin{smallmatrix}#1\end{smallmatrix}\right)}&#xA;\def\mmat#1{\begin{bmatrix}#1\end{bmatrix}}&#xA;\def\vec#1{\mathrm{\mathbf{#1}}}&#xA;\def\mat#1{\mathrm{\mathbf{#1}}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, the &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; coordinates at a point on a triangle's plane given by the affine coordinates &lt;span class=&quot;math-container&quot;&gt;$\lambda_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\lambda_2$&lt;/span&gt; are&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;  u &amp;amp;= u_1 + \lambda_1 (u_2 - u_1) + \lambda_2 (u_3 - u_1) \\&#xA;  v &amp;amp;= v_1 + \lambda_1 (v_2 - v_1) + \lambda_2 (v_3 - v_1)&#xA;\end{align}&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$u_i$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$v_i$&lt;/span&gt; are the &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; coordinates at vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;. We can rewrite this as&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \mmat{&#xA;    u_2 - u_1 &amp;amp; u_3 - u_1 \\&#xA;    v_2 - v_1 &amp;amp; v_3 - v_1&#xA;  } \cdot \mvec{&#xA;    \lambda_1 \\&#xA;    \lambda_2&#xA;  } = \mvec{&#xA;    u - u_1 \\&#xA;    v - v_1&#xA;  }.&#xA;\end{equation}&lt;/span&gt;&#xA;Knowing &lt;span class=&quot;math-container&quot;&gt;$u_i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v_i$&lt;/span&gt; at each vertex of a given triangle, we can compute&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \mat M = \mmat{&#xA;    u_2 - u_1 &amp;amp; u_3 - u_1 \\&#xA;    v_2 - v_1 &amp;amp; v_3 - v_1&#xA;  }.&#xA;\end{equation}&lt;/span&gt;&#xA;We can then find the affine coordinates corresponding to the point with whatever &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; coordinates we want:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \mvec{&#xA;    \lambda_1 \\&#xA;    \lambda_2&#xA;  } = &#xA;  \mat M^{-1} \cdot \mvec{&#xA;    u - u_1 \\&#xA;    v - v_1&#xA;  }.&#xA;\end{equation}&lt;/span&gt;&#xA;Note that these affine coordinates always exist as long as &lt;span class=&quot;math-container&quot;&gt;$\mat M^{-1}$&lt;/span&gt; exists (which makes sense; there will always be exactly one point somewhere in the plane of the triangle where &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; reach whatever value you may be looking for as long as &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; vary independently). However, they will not necessarily fall inside the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So one way to find the point you're looking for would be to iterate over all triangles of the mesh and, for each triangle, compute &lt;span class=&quot;math-container&quot;&gt;$\mat M^{-1}$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\lambda_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\lambda_2$&lt;/span&gt; for &lt;span class=&quot;math-container&quot;&gt;$u = 0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v = 0$&lt;/span&gt;, and check whether&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;  \lambda_1 &amp;amp;\geq 0 &amp;amp; &amp;amp;\land &amp;amp; \lambda_2 &amp;amp;\geq 0 &amp;amp; &amp;amp;\land &amp;amp; \lambda_1 + \lambda_2 &amp;amp;\leq 1.&#xA;\end{align}&lt;/span&gt;&#xA;If this is the case, you have found a triangle that contains a point at which &lt;span class=&quot;math-container&quot;&gt;$u = 0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v = 0$&lt;/span&gt;. You can then compute the coordinates of that point as&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;  \vec p = (1 - \lambda_1 - \lambda_2) \vec v_1 + \lambda_1 \vec v_2 + \lambda_2 \vec v_3&#xA;\end{equation}&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\vec v_1$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\vec v_2$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\vec v_3$&lt;/span&gt; are the coordinates of the respective triangle vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It may make sense to, for example, use an initial check against a given triangle's bounding rectangle in UV space and/or other methods to quickly rule out triangles that cannot contain the coordinates of interest to speed up the search&amp;hellip;&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-01-13T21:49:36.183" LastActivityDate="2019-01-13T21:49:36.183" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="8473" PostTypeId="2" ParentId="8470" CreationDate="2019-01-13T14:22:06.560" Score="0" Body="&lt;p&gt;Michael Kenzel's answer gives a good general algorithm, but here's a &quot;20% of the effort, 80% of the value&quot; answer. Because &lt;span class=&quot;math-container&quot;&gt;$(u,v) \in [0,1]$&lt;/span&gt; space is a square being filled with convex polygons, &lt;span class=&quot;math-container&quot;&gt;$(0,0)$&lt;/span&gt; can only be mapped in one of two conditions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$(0,0)$&lt;/span&gt; is at a vertex; or&lt;/li&gt;&#xA;&lt;li&gt;Some vertices have negative co-ordinates.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Generally 2 is avoided when unwrapping your mesh unless you're using a texture in wrapped mode, which is quite unusual because it makes the seams on your mesh look bad. It's also ruled out by the condition in your question that &quot;the UV mapping is one-to-one&quot;. So most of the time, if &lt;span class=&quot;math-container&quot;&gt;$(0,0)$&lt;/span&gt; is present at all, it's at a vertex. That makes your algorithm very simple: just look through your vertices until you find one with those exact texture co-ordinates, and then read out the object-space position of that vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's actually more common for &lt;span class=&quot;math-container&quot;&gt;$(0,0)$&lt;/span&gt; to not be present at all, (a) because you need to take special care with texture filtering when going up to the edge of the texture, and (b) unwrapping a shape into a mesh doesn't usually give you a convenient corner to place there. &lt;a href=&quot;https://www.google.com/search?q=uv+unwrap&amp;amp;tbm=isch&quot; rel=&quot;nofollow noreferrer&quot;&gt;The examples on this Google Image search&lt;/a&gt; are a good illustration: of a few dozen examples on the first few pages, I only found a couple of UV maps where the net touched any of the corners.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-01-13T14:22:06.560" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8474" PostTypeId="1" CreationDate="2019-01-14T08:59:49.830" Score="1" ViewCount="51" Body="&lt;p&gt;For the purpose of mapping caves, we survey new passages so that we take main polygon (survey from point A to point B) and on each &quot;node&quot; (survey station A in example), we shoot multiple &quot;splay shots&quot; around the passage (in more or less random directions), so we obtain more information which can later be used to draw a map of the cave.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing this, we get a polygon with a &quot;cloud&quot; of points around the main line. My question is, whether is there a way to create a convex hull around this main line, using those &quot;splay shots&quot;. This would be a great way to visualize cave passages.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each survey leg has information about direction, inclination and length, with which we are able to get the 3d coordinate in space of each node.&lt;/p&gt;&#xA;" OwnerUserId="10006" LastActivityDate="2019-01-14T08:59:49.830" Title="Convex hull around polygon for cave mapping" Tags="&lt;3d&gt;&lt;mapping&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8479" PostTypeId="1" AcceptedAnswerId="8491" CreationDate="2019-01-16T18:08:30.683" Score="1" ViewCount="3011" Body="&lt;p&gt;In &lt;a href=&quot;https://en.wikipedia.org/wiki/Ray_tracing_(graphics)&quot; rel=&quot;nofollow noreferrer&quot;&gt;ray-tracing&lt;/a&gt; technique critical point is to calculate rays which came out from eye &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; to target &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; through pixel &lt;span class=&quot;math-container&quot;&gt;$P_{ij}$&lt;/span&gt; on viewport. The &quot;viewport&quot; is represented as rectangle divided to square pixels - this rectangle is perpendicular to line which go through points &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; (viewport center) and &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;. The ray (red line on image) is represented by point &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; and unit  vector &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt; (not shown in picture but it lay on red line) - below is picture which show &quot;geometry&quot; - but what are the formulas to calculate &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt;? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The given input values are: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;eye position &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt;, &lt;/li&gt;&#xA;&lt;li&gt;target position &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;, &lt;/li&gt;&#xA;&lt;li&gt;field of view &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; (angle, for human eye &lt;span class=&quot;math-container&quot;&gt;$\approx 90^\circ$&lt;/span&gt;), &lt;/li&gt;&#xA;&lt;li&gt;number of square pixels &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; (horizontal direction) and &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; (vertical direction).&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$i,j$&lt;/span&gt; processed pixel indexes where &lt;span class=&quot;math-container&quot;&gt;$1\leq i\leq k$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$1\leq j\leq m$&lt;/span&gt;   &lt;/li&gt;&#xA;&lt;li&gt;we also know vertical &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; vector usually equal to &lt;span class=&quot;math-container&quot;&gt;$w=[wx,wy,wz]=[0,1,0]$&lt;/span&gt; (not shown on picture) which indicate where is up and where is down &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The orthogonal vectors &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt;  (and &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;) on picture are determined by &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t=T-E$&lt;/span&gt; and maybe will useful in &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt; calculations. The &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; and pixel size is arbitrary and don't change the result because of fixed &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;: How to calculate unit vector &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt; knowing input values described above?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aUdHD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aUdHD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9881" LastEditorUserId="9881" LastEditDate="2019-01-23T12:44:21.030" LastActivityDate="2021-03-16T19:28:58.373" Title="How to calculate ray" Tags="&lt;raytracing&gt;&lt;mathematics&gt;&lt;linear-algebra&gt;&lt;ray&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8481" PostTypeId="1" CreationDate="2019-01-16T22:41:59.697" Score="1" ViewCount="566" Body="&lt;p&gt;I'm currently trying to understand how works perspective correction texture mapping. I saw that actually it works by interpolating the z value of the three point of the triangle which the current rendered pixel is in, then, it divide the u and v affine texture coordinates by the interpolated z value in order to get the perspective corrected values of u and v.&#xA;I really can't wrap my head around this division by z to do perspective correction. Can someone explain me the point and the math behind it which makes it do the job ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks guys !&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Okay, after reading your advices guys, i dived into perspective correction algorithm.&#xA;I think i have understood what is done, but i want to expose it to you in order to see if it the right way to think.&#xA;When rendering pixels on screen you're in raster space, if you interpolate u and v values you will get affine texturing cause it does not take into account depth of the vertices.&#xA;The solution is to do so :&#xA;working in a &quot;specific space&quot; of three dimensions : (u,v,z). Each vertices can be represented in this space cause it have u and v tex coordinates and a z coordinate.&#xA;The idea is the following : you divide each u and v component of the vertices by z. The effect will be a perspective projection on the plane defined by the equation 0*u + 0*v + 1*z = 1. Doing so makes us able to do interpolation into raster space. Then, when we want to get the perspective corrected texel for a specific pixel of the current renderer triangle in raster space, we just have to multiply the interpolated u/z and v/z by interplated z (actually the algorithm divide u/z and v/z by interpolated 1/z which leads exacly to a multiplication by interpolated z). But this multiplication by interpolated z can be viewed as a scalar which multiplies the interpolated vector (u/z, v/z, 1) which will put back the vector from the plane at z=1 to the right place into the original three dimensions space giving us the u and v coordinates interpolated into the three dimension space, taking into account the z coordinates and leading to a correct perspective corrected texture mapping.&#xA;Am i right ? &lt;/p&gt;&#xA;" OwnerUserId="10022" LastEditorUserId="10022" LastEditDate="2019-01-17T16:38:09.483" LastActivityDate="2019-01-17T16:38:09.483" Title="Why do perspective correction based texture mapping do depth division" Tags="&lt;texture&gt;&lt;mapping&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8482" PostTypeId="1" CreationDate="2019-01-17T05:21:12.647" Score="0" ViewCount="339" Body="&lt;p&gt;It sounds like &lt;a href=&quot;http://graphics.stanford.edu/courses/cs468-12-spring/LectureSlides/10_Subdivision.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Subdivision Surfaces&lt;/a&gt; are better than NURBS but not as good as T-splines. I would like to know some of the disadvantages of Subdivision Surfaces, what they can't do or what they do inefficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am considering what type of system to use. Whether it be B-splines, NURBS, subdivision surfaces, or T-splines, or something else. Here I am mainly wondering how good subdivision surfaces are.&lt;/p&gt;&#xA;" OwnerUserId="8632" LastActivityDate="2019-01-17T12:22:40.237" Title="Problems with Subdivision Surfaces" Tags="&lt;3d&gt;&lt;2d&gt;&lt;nurbs&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8483" PostTypeId="2" ParentId="8482" CreationDate="2019-01-17T11:52:22.427" Score="2" Body="&lt;p&gt;Both T-splines and subdivision surfaces are capable of handling an arbitrary topology input mesh, whereas NURBS can only handle meshes with regular topology. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Complex NURBS objects are therefore made out of multiple regular meshes. These meshes are trimmed and fit together to form a single complex object. However, along the trimming lines of the mesh discontinuities can occur. This is because the boundary curve of a trimmed NURBS patch is not in general a NURBS curve. This complicates the joining of several NURBS patches, potentially sacrificing water tightness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Subdivision surfaces are able to handle meshes with arbitrary topology. This means your mesh can contain extraordinary faces (faces with more or less than four sides) and extraordinary vertices (vertices with a valency other than 4). The generated surfaces are in general curvature continuous in regular regions and tangent plane continuous at extraordinary vertices. The evaluation of a subdivision surface is an iterative process. Although regular regions can be converted to B-spline patches problems occur when rendering the irregular regions as an infinite number of B-spline patches will be generated. The &lt;a href=&quot;http://graphics.pixar.com/opensubdiv/docs/intro.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenSubDiv&lt;/a&gt; library by Pixar is a good start for speedy subdivision as it calculates many things on the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most subdivision surfaces are based on uniform subdivision and some work has been done to handle &lt;a href=&quot;https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-773.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;non-uniform and rational subdivision&lt;/a&gt;, but it is quite extensive and has some limitations. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;T-splines can do everything NURBS can do as well. The most striking feature of T-splines is the ability to handle T-junctions, as well as arbitrary topology, without sacrificing in surface continuity. This allows the designer to insert more detail in some places without it effecting the mesh in other regions. In this way it is possible for a very organic design process. Take for instance this &lt;a href=&quot;https://www.youtube.com/watch?v=4nbC6__gZfg&amp;amp;t=656s&quot; rel=&quot;nofollow noreferrer&quot;&gt;video&lt;/a&gt;. A downside of T-splines is that it is a patented technology.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2019-01-17T12:22:40.237" LastActivityDate="2019-01-17T12:22:40.237" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8486" PostTypeId="1" AcceptedAnswerId="8487" CreationDate="2019-01-17T23:38:06.093" Score="3" ViewCount="212" Body="&lt;p&gt;Is there a name for this type of effect where many area sizes are increased/decreased in relation to each other? I'm looking for some type of algorithm, formula, logic, etc. for recreating this. Here is the effect (which I believe was created in After Effects):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3cYuP.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3cYuP.gif&quot; alt=&quot;The Tatami Galaxy (Yojouhan Shinwa Taikei / 四畳半神話大系) - Clear END&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Source: &lt;a href=&quot;https://www.youtube.com/watch?v=ewICfFjc4CI&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Tatami Galaxy (Yojouhan Shinwa Taikei / 四畳半神話大系) - Clear END&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10028" LastActivityDate="2019-01-18T07:12:06.727" Title="What algorithm is used in this animation from Tatami Galaxy?" Tags="&lt;algorithm&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8487" PostTypeId="2" ParentId="8486" CreationDate="2019-01-18T07:12:06.727" Score="7" Body="&lt;p&gt;It looks like a &lt;a href=&quot;https://en.wikipedia.org/wiki/Voronoi_diagram&quot; rel=&quot;noreferrer&quot;&gt;voronoi diagram&lt;/a&gt; with a non-Euclidean distance metric. Probably not &lt;a href=&quot;https://en.wikipedia.org/wiki/Taxicab_geometry&quot; rel=&quot;noreferrer&quot;&gt;Manhattan L1&lt;/a&gt; but something close related, but maybe &lt;a href=&quot;https://en.wikipedia.org/wiki/Mahalanobis_distance&quot; rel=&quot;noreferrer&quot;&gt;Mahalanobis&lt;/a&gt; with some kind of restriction on seed point generation and movement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A similar result may be calculated with &lt;a href=&quot;https://link.springer.com/article/10.1007/s10707-006-0006-8&quot; rel=&quot;noreferrer&quot;&gt;Weight-proportional Space Partitioning Using Adaptive Voronoi Diagrams&lt;/a&gt; when reducing spatial resolution of the domain. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess yo'll find similar examples in &lt;a href=&quot;https://www.shadertoy.com/&quot; rel=&quot;noreferrer&quot;&gt;ShaderToy&lt;/a&gt; if you look for voronoi examples, which code you could study, and could be much simpler than the algorithm in the paper. &lt;/p&gt;&#xA;" OwnerUserId="9908" LastActivityDate="2019-01-18T07:12:06.727" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8488" PostTypeId="2" ParentId="8479" CreationDate="2019-01-18T07:13:57.957" Score="3" Body="&lt;p&gt;First, the viewport size:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$h_x = 2*d*tan(\theta_x/2)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$h_y = 2*d*tan(\theta_y/2)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each pixel (from your diagram) has the following size in the eye coordinate system:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$W = h_x / (k-1)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$H = h_y / (m-1)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that usually the field of view encompasses whole pixels and doesn't stop at the center of the edge pixels like your diagram shows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$P_c$&lt;/span&gt; is the viewport center in pixel coordinates, let:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\vec {P'_{ij}} = P_{ij} - P_c$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, &lt;span class=&quot;math-container&quot;&gt;$P_{ij}$&lt;/span&gt; in eye space becomes:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;[P_{ij}]_e =&#xA;    \begin{pmatrix}&#xA;    (W, 0) * \vec {P'_{ij}} \\&#xA;    (0, H) * \vec {P'_{ij}} \\&#xA;    d \\&#xA;    \end{pmatrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and in the standard base:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$[P_{ij}]_{std} = (\vec b, \vec v, \vec t) * [P_{ij}]_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normalize the one in the base you want to get &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Original answer&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;The last time I wanted to go from window coordinates (pixels) to eye coordinates, I followed the steps outlined here in the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL wiki&lt;/a&gt;. Once you have the eye coordinates, you can just normalize the vector to obtain &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastEditorUserId="7644" LastEditDate="2019-01-18T12:23:05.723" LastActivityDate="2019-01-18T12:23:05.723" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="8489" PostTypeId="1" AcceptedAnswerId="8493" CreationDate="2019-01-18T13:36:26.443" Score="2" ViewCount="136" Body="&lt;p&gt;I've seen how subdivision surfaces are good for 3D curves/modeling, but haven't seen anything on if it's good, or even usable, in 2D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is just that, if (a) you can even use subdivision surfaces in 2D, and (b) if you can use it for 2D, if it's a good solution for modeling curves in 2D, or if not, what a good solution for modeling curves in 2D might be (if it's just bezier curves, or ideally something better / more powerful).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.cl.cam.ac.uk/teaching/1617/AdvGraph/6.%20Subdivision%20surfaces.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt; it suggests subdivision surfaces could be used in 2D, but not sure if they would be considered good for it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CpFQz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CpFQz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8632" LastActivityDate="2019-01-21T13:43:30.953" Title="If you can use subdivision surfaces for 2D curves" Tags="&lt;3d&gt;&lt;2d&gt;&lt;curve&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8491" PostTypeId="2" ParentId="8479" CreationDate="2019-01-18T15:45:39.420" Score="4" Body="&lt;p&gt;Read up on the basics for ray-tracing &lt;a href=&quot;http://www.scratchapixel.com/index.php?redirect&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;,&lt;/p&gt;&#xA;&lt;p&gt;Usually we don't mess up with viewports and stuff in raytracing, So I'm just telling you for the case where viewport equals the Image Width and Height.&lt;/p&gt;&#xA;&lt;p&gt;There are two cases when the field of view changes. Either you move the image plane back and forth or you increase the size. We choose to change &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; ( former approach).&lt;/p&gt;&#xA;&lt;p&gt;Calculating ray is simple when the camera is aligned with the world, all you have to do is&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$d = 1/tan(\theta_{fov}/2))$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$P_x = P_x + 0.5$&lt;/span&gt;&lt;br /&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$P_y = P_y + 0.5$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$aspect\_ratio = width/height$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ray.dir.x = aspect\_ratio *(2*P_x/width) -1$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ray.dir.y = (2*P_y/height) - 1$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ray.dir.z = d$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; coordinate should be negative or positive depending on whether you are using a right handed or left handed coordinate system. &lt;span class=&quot;math-container&quot;&gt;$P_x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$P_y$&lt;/span&gt; are pixel coordinates offset by &lt;span class=&quot;math-container&quot;&gt;$0.5$&lt;/span&gt; to get the center of the pixel.&lt;/p&gt;&#xA;&lt;p&gt;The process is simple. You first map your image to NDC space (-1, 1). However to account for non-square images we scale the &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; coordinate by Aspect ratio so it's &lt;span class=&quot;math-container&quot;&gt;$[-a, a]$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$[-1,1]$&lt;/span&gt; in Y. The ray's direction through the pixel is then given by above formulas. You might have to flip the &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; coordinate if the image coordinate's origin is top left instead of bottom left.&lt;/p&gt;&#xA;&lt;p&gt;Note however the link bases all their coordinate systems and space names on RenderMan which is quite different from OpenGL. For camera that isn't aligned with the world coordinate you have to multiply by the transformation matrix as described by bernie in his answer&lt;/p&gt;&#xA;&lt;p&gt;EDIT:-&lt;/p&gt;&#xA;&lt;p&gt;First of all let's clear up on -ve and +ve &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt;. For right handed coordinate systems you always set &lt;span class=&quot;math-container&quot;&gt;$ray.dir.z = -d$&lt;/span&gt; and for left handed &lt;span class=&quot;math-container&quot;&gt;$ray.dir.z = d$&lt;/span&gt; This is because in camera space there is no concept of half rays having -ve Z and half +ve, that happens in world space. When you multiply by the transformation matrix it takes care of these cases for you since the transformation matrix is designed keeping in mind whether you are working on a left handed or right handed system. I know i said that you always set it to +ve &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; but i was wrong in the comments, sorry.&lt;/p&gt;&#xA;&lt;p&gt;Now coming to your other question. You need the vectors &lt;span class=&quot;math-container&quot;&gt;$b,v,t$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; for creating a transformation matrix. Usually in raytracing you create your camera and initialize its transformation matrix to the standard case (aligned with world space) Then when you move your mouse or something you create a respective rotation matrix and transform the original camera matrix to keep up with these changes. Then when calculating the ray you multiply it as I said above to get ray direction easily. So you probably need to manage your own Camera first.&lt;/p&gt;&#xA;&lt;p&gt;Since you aren't managing in this case you explicitly need to find these vectors. You mention you have the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; vector which is global up. &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; is easy to find as you say&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$t = T-E$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;However remember this is the viewing direction not the basis vector. For right handed coordinate systems, the basis vector for &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$-V_{dir}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;For &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; which is Camera's right vector. You do,&#xA;&lt;span class=&quot;math-container&quot;&gt;$ w \times t = b$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;This gets you the Camera's up vector. Then you do,&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ t \times b = v$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;to get the Camera's up vector. This works as long as &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; doesn't equal &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; which is the global up.&lt;/p&gt;&#xA;&lt;p&gt;So after you have these you can create a camera transformation matrix with &lt;span class=&quot;math-container&quot;&gt;$c_1, c_2, c_3, c_4 = b, v, t, E$&lt;/span&gt; respectively.&lt;/p&gt;&#xA;&lt;p&gt;EDIT2:-&#xA;Instead of following above approach you can also do Gram-Schmidt orthogonalization which is more standard in this case. Using this you get the Camera's up vector &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; as&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$v = w - (t.w)\hat{t}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Then side vector as,&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$b = v \times t$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;For right handed systems. For left handed systems you need to change the ordering of cross products.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-01-21T11:18:34.597" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8492" PostTypeId="1" AcceptedAnswerId="8494" CreationDate="2019-01-18T16:39:19.807" Score="0" ViewCount="708" Body="&lt;p&gt;I was able to write the following working code to draw any number of &quot;sprites&quot; (defined as 2 tringles, 6 vertices)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    Matrix.setIdentityM(mModelMatrix, 0);&#xA;&#xA;    Matrix.multiplyMM(mMVPMatrix, 0, getCamera().mViewMatrix, 0, mModelMatrix, 0);&#xA;    GLES20.glUniformMatrix4fv(mShader.getMVMatrixHandle(), 1, false, mMVPMatrix, 0);&#xA;&#xA;    Matrix.multiplyMM(mMVPMatrix, 0, getCamera().projMatrix, 0, mMVPMatrix, 0);&#xA;    GLES20.glUniformMatrix4fv(mShader.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0);&#xA;&#xA;    mPositions.position(0);&#xA;    mColors.position(0);&#xA;    mNormals.position(0);&#xA;    mTextureCoordinates.position(0);&#xA;&#xA;    GLES20.glVertexAttribPointer(mShader.getPositionHandle(), mPositionDataSize, GLES20.GL_FLOAT, false, 0, mPositions);&#xA;    GLES20.glVertexAttribPointer(mShader.getColorHandle(), mColorDataSize, GLES20.GL_FLOAT, false, 0, mColors);&#xA;    GLES20.glVertexAttribPointer(mShader.getNormalHandle(), mNormalDataSize, GLES20.GL_FLOAT, false, 0, mNormals);&#xA;    GLES20.glVertexAttribPointer(mShader.getTextureCoordinateHandle(), mTextureCoordinateDataSize, GLES20.GL_FLOAT, false, 0, mTextureCoordinates);&#xA;&#xA;    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6*numSprites);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Using a sprite atlas this code displays many different sprite textures in one fell swoop, which is very fast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I would also like to draw multiple copies of a 3D &lt;code&gt;.obj&lt;/code&gt; file. Now I've loaded in the necessary &lt;code&gt;FloatBuffers&lt;/code&gt; of positions, normals, texture coordinates, etc., so I can easily add these buffers to the &lt;code&gt;mPositions&lt;/code&gt;, &lt;code&gt;mTextureCoordinates&lt;/code&gt; buffers above, etc., no problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But these instances of the &lt;code&gt;.obj&lt;/code&gt; model I'm trying to display need to be in different x/y locations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is there an efficient way this can be achieved in OpenGL?&lt;/strong&gt; Maybe one of the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;I could displace the &lt;code&gt;.obj&lt;/code&gt; files &lt;code&gt;_positions&lt;/code&gt; buffer before adding to the  global &lt;code&gt;mPositions&lt;/code&gt; buffer to draw, but this seems rather inefficient.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;One solution is to run a separate instance of the above code for each &lt;code&gt;.obj&lt;/code&gt; 3D object, including an OpenGL translation for each instance. But I've heard this is costly if you have many 3D objects. (This is the reason I use a sprite atlas for 2D sprites in the above code)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&quot;Another&quot; approach that seems to work is to add the following example code, where &lt;code&gt;_positions&lt;/code&gt; etc are the buffers for the `.obj. file, and I draw 5 of the same object file in a row using a translation. It's very similar to (2) but without having to repeat the OpenGL initialisation code every time.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int c1 = 0; c1 &amp;lt; 5; c1++) {&#xA;&#xA;    _positions.position(0);&#xA;    _normals.position(0);&#xA;    _textureCoordinates.position(0);&#xA;&#xA;    Matrix.setIdentityM(mModelMatrix, 0);&#xA;    Matrix.translateM(mModelMatrix, 0, cx + dx * c1 * 4, cy, 0);&#xA;    Matrix.scaleM(mModelMatrix, 0, 0.1f, 0.1f, 0.03f);&#xA;    Matrix.rotateM(mModelMatrix, 0, -90, 1, 0, 0);&#xA;&#xA;    Matrix.multiplyMM(mMVPMatrix, 0, getCamera().mViewMatrix, 0, mModelMatrix, 0);&#xA;&#xA;    GLES20.glUniformMatrix4fv(mShader.getMVMatrixHandle(), 1, false, mMVPMatrix, 0);&#xA;    Matrix.multiplyMM(mMVPMatrix, 0, getCamera().projMatrix, 0, mMVPMatrix, 0);&#xA;    GLES20.glUniformMatrix4fv(mShader.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0);&#xA;    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, numFaces);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;But I'm not sure if this isn't just as inefficient as the (2) ?&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;4&quot;&gt;&#xA;&lt;li&gt;Maybe there's no way round it? Perhaps (2)/(3) is the only way and I'm just being over cautious because of my &quot;bad&quot; experience without using a sprite atlas for 2D sprites? After all, I was originally drawing 1000's of 2D sprites using method (1) originally, but I will only be drawing around 10-20 3D objects. In the 2D case, switching to a sprite atlas greatly speeded things up !&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;(I'm interested in OpenGL ES 2.0 primarily)&lt;/p&gt;&#xA;" OwnerUserId="9851" LastEditorUserId="9851" LastEditDate="2019-01-18T21:01:42.223" LastActivityDate="2019-01-18T21:01:42.223" Title="Efficiently drawing multiple instances of 3D objects" Tags="&lt;opengl&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8493" PostTypeId="2" ParentId="8489" CreationDate="2019-01-18T16:45:04.917" Score="4" Body="&lt;p&gt;Subdivision can be used for curves in 2D just as easily as for surfaces in 3D. Usually the subdivision algorithms applied to 2D are called subdivision curves. Subdivision curves do not suffer from the problem that subdivision surfaces have around extraordinary points and therefore all subdivision surfaces can easily be converted to (uniform) B-splines. This means that it equals to working with Bézier curves in most cases. This latter representation might be more advantageous as it possesses a closed form representation, such that curves can be evaluated easily at arbitrary parameter values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A simple subdivision algorithm for curves is the following. Consider a polyline consisting out of &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; points &lt;span class=&quot;math-container&quot;&gt;$P_0 \ldots P_{n-1}$&lt;/span&gt;. Than for every iteration do the following steps:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Every exisiting position &lt;span class=&quot;math-container&quot;&gt;$P_i =&amp;gt; (P_{i-1} + 6 P_{i} + P_{i+1})/8$&lt;/span&gt; then add new positions on every edge between existing points using &lt;span class=&quot;math-container&quot;&gt;$(4 P_i + 4 P_{i+1})/8$&lt;/span&gt; and repeat. In the limit this procedure will converge to uniform cubic B-splines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some useful extensions for subdivison curves exists such as &lt;a href=&quot;https://www.rug.nl/research/portal/files/50538260/Creases_and_boundary_conditions.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;(semi-sharp) creases and boundary conditions&lt;/a&gt; &lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2019-01-21T13:43:30.953" LastActivityDate="2019-01-21T13:43:30.953" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8494" PostTypeId="2" ParentId="8492" CreationDate="2019-01-18T16:59:09.813" Score="3" Body="&lt;p&gt;What you are looking for here is &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glDrawArraysInstanced.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;instanced rendering&lt;/a&gt;. Instanced rendering coupled with &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribDivisor.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;attribute divisors&lt;/a&gt; is a very powerful tool to render multiple copies of the same object using only one drawing call. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using instanced rendering you only have to specify the geometry of an object once on the GPU. Then, you could pass along an additional buffer of matrices, one matrix for each instance of the object you are rendering. Using attribute divisors you can tell the GPU that you will only need one single matrix per a number of vertices. Attribute divisors tell the GPU when and how to advance an index in a attribute buffer. This allows you to only define a single matrix per instance instead of passing along a single matrix for every vertex in a single model.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://ogldev.atspace.co.uk/www/tutorial33/tutorial33.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;, is an excellent tutorial on using instanced rendering and attribute divisors.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2019-01-18T16:59:09.813" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8495" PostTypeId="1" AcceptedAnswerId="8501" CreationDate="2019-01-18T18:21:59.740" Score="2" ViewCount="454" Body="&lt;p&gt;I'm trying to add bump mapping to my ray tracer, and I'm currently struggling to add bump mapping to it, as I don't seem to get the transformations from texture space to world space correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have an arbitary Triangle in world-Space defined by it's vertices.&#xA;Each of the vertices store a normalized UV-Coordinate to interpolate the position on the height map for an Intersection Point.&#xA;The height map is a gray-Scale Image&#xA;So when I intersect with the Triangle, I calculate the x and y derivatives of the height map at the corresponding uv-coordinate, transform the x and y unit Vectors (of the Texture) to world-Space, and calculate the changed normal. This currently looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        Point p = lerpbar(uv_vert1, uv_vert2, uv_vert3, &#xA;               intersection.barycentric.u, intersection.barycentric.v);&#xA;        float gx = this-&amp;gt;_bmap-&amp;gt;getColorDX(p);&#xA;        float gy = this-&amp;gt;_bmap-&amp;gt;getColorDY(p);&#xA;        Vector wx = (To_World_Matrix * Vector(1, 0, 0))).normalize();&#xA;        Vector wy = (To_World_Matrix * Vector(0, 1, 0))).normalize();&#xA;        Vector n = intersection.normal();&#xA;        return n + (gx * cross(n, wy) - gy * cross(n, wx));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, I just can't figure out what Matrix I'd need to use so this produces correct results, as I just don't really understand how to map from unit Vectors to World-Space Vectors when I only know how arbitay Triangle Edges relate to arbitay Vectors in Texture Space.&lt;/p&gt;&#xA;" OwnerUserId="10033" LastEditorUserId="209" LastEditDate="2019-01-21T08:48:52.040" LastActivityDate="2019-01-21T08:48:52.040" Title="Bump mapping with triangles and height maps" Tags="&lt;raytracing&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8498" PostTypeId="1" AcceptedAnswerId="8499" CreationDate="2019-01-20T01:07:48.487" Score="2" ViewCount="116" Body="&lt;p&gt;I am reading a paper about layered materials. However, I am confused on the implementation of this paper. The following picture describe the layered material. &lt;a href=&quot;https://i.stack.imgur.com/CTUZR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CTUZR.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;r_ab is a complex reflection coeffcient when going from medium a to medium b. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And in the code, there is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        float2 R12, phi12;&#xA;        fresnelDielectric(LdotH, 1.0, eta_2, R12, phi12);&#xA;        float2 R21 = R12;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I don't understand why is r_12 equal to r_21?&lt;/p&gt;&#xA;" OwnerUserId="9987" LastActivityDate="2019-01-21T05:35:53.683" Title="Confused on reflection coeffcient of Fresnel equations" Tags="&lt;pbr&gt;&lt;material&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8499" PostTypeId="2" ParentId="8498" CreationDate="2019-01-20T04:10:57.577" Score="1" Body="&lt;p&gt;We have &lt;span class=&quot;math-container&quot;&gt;$t_{12} = t_{21}$&lt;/span&gt;, by &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5286/the-reciprocity-of-brdf&quot;&gt;the law of reciprocity&lt;/a&gt;. Also, &lt;span class=&quot;math-container&quot;&gt;$$r_{12} + t_{12} = 1\\r_{21} + t_{21} = 1$$&lt;/span&gt;&#xA;It follows that &lt;span class=&quot;math-container&quot;&gt;$r_{12} = r_{21}$&lt;/span&gt; as well.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2019-01-21T05:35:53.683" LastActivityDate="2019-01-21T05:35:53.683" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8500" PostTypeId="1" CreationDate="2019-01-20T07:25:13.420" Score="4" ViewCount="144" Body="&lt;p&gt;Given a perspective projection matrix. How can one from it derive a set of matrices representing &quot;chunks&quot; of the viewport? So that the rendered chunks can be &quot;stiched&quot; &#xA;to form an image &quot;chunk times higher&quot; resolution than the viewport. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an image (drawn in ms paint, ik) describing what a chunk of the frustum would look like: &#xA;&lt;a href=&quot;https://i.stack.imgur.com/SOuZS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SOuZS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm planning on using this for a camera mod library to take images in &quot;super-resolution&quot;, in reality the chunks should overlap a little, to allow for exposure compensation and the blending of effects like lens flare. Most linear algebra in this project is done with a &lt;a href=&quot;https://github.com/sgorsten/linalg&quot; rel=&quot;nofollow noreferrer&quot;&gt;header-only library called linalg&lt;/a&gt; , so it'd be nice if any examples shown used that library. Thanks!&lt;/p&gt;&#xA;" OwnerUserId="10039" LastActivityDate="2019-01-20T12:30:09.450" Title="Modify camera matrix so that it renders a &quot;chunk&quot; of the frustum" Tags="&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8501" PostTypeId="2" ParentId="8495" CreationDate="2019-01-20T08:02:13.293" Score="2" Body="&lt;p&gt;The normal of a given point on the height map is perpendicular to the 2 vectors defined by &lt;code&gt;gx&lt;/code&gt; and &lt;code&gt;gy&lt;/code&gt;. The original surface normal is not relevant to this. So in tangent space, the normal is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector tangent = Vector(1, 0, gx);&#xA;Vector bitangent = Vector(0, 1, gy);&#xA;Vector normal = normalize(cross(tangent, bitangent));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;You then need to convert the normal from tangent space to world space. For this you need the so-called &quot;TBN matrix&quot; (tangent, bitangent, normal matrix). There are plenty of &lt;a href=&quot;https://learnopengl.com/Advanced-Lighting/Normal-Mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;articles&lt;/a&gt; &lt;a href=&quot;https://www.gamasutra.com/blogs/RobertBasler/20131122/205462/Three_Normal_Mapping_Techniques_Explained_For_the_Mathematically_Uninclined.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;around&lt;/a&gt; explaining this. But the gist is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector T = normalize(To_World_Matrix * intersection.tangent());&#xA;Vector B = normalize(To_World_Matrix * cross(intersection.tangent(), intersection.normal()));&#xA;Vector N = normalize(To_World_Matrix * intersection.normal());&#xA;mat3 TBN = mat3(T, B, N); // GLSL syntax&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The last thing is to do a change of basis to move the normal from tangent space to world space:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vector normal_world_space = normalize(TBN * normal);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that the order of some cross-products might be inverted in what I wrote if you get normals pointing inside the surface.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2019-01-20T08:02:13.293" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8502" PostTypeId="2" ParentId="8500" CreationDate="2019-01-20T12:30:09.450" Score="3" Body="&lt;p&gt;It depends a little how you construct the matrix. I assume that you use the function &lt;code&gt;perspective_matrix&lt;/code&gt; from your library, which actually works pretty much like good old &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/gluPerspective.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;gluPerspective&lt;/code&gt;&lt;/a&gt;). But what this actually does is nothing else than use the more general function &lt;code&gt;frustum_matrix&lt;/code&gt;, which in turn creates a common arbitrary view frustum matrix, like good old &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glFrustum.xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glFrustum&lt;/code&gt;&lt;/a&gt; did (from the (simplified) &lt;em&gt;linalg&lt;/em&gt; source code):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat4 perspective_matrix(T fovy, T aspect, T n, T f)&#xA;{&#xA;    T y = n*std::tan(fovy / 2), x = y*aspect;&#xA;    return frustum_matrix(-x, x, -y, y, n, f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this &lt;strong&gt;general frustum matrix function is actually all you need for creating arbitrary assymmetrical frustum matrices&lt;/strong&gt;, like the ones you want. The paramters it takes are exactly the left, right, bottom, and top boundaries of the near plane, i.e. the x and y boundaries of the frustum &lt;em&gt;on&lt;/em&gt; the z = &lt;code&gt;near&lt;/code&gt; (or &lt;code&gt;-near&lt;/code&gt;) plane. So all you actually need to do is &lt;strong&gt;take these left/right/bottom/top parameters and cut those ranges into whatever sub-intervals you need&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It depends a little on what information you actually have. If you have the parameters you construct your perspective matrix from (i.e. the &lt;code&gt;fovY&lt;/code&gt; and the &lt;code&gt;aspect&lt;/code&gt;) you can just replace the above procedure with something more elaborate that computes the frustum parameters from these two and then scale-biases them into the corresponding intervals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If all you have is an already constructed perspective matrix, you might have to retrieve the parameters from that matrix first, which shouldn't be too difficult when looking at how the matrix is constructed. If you &lt;em&gt;already&lt;/em&gt; have a general assymmetric frustum matrix, it might get a little more elaborate. But it always really all just comes down to &lt;strong&gt;tweaking the &lt;span class=&quot;math-container&quot;&gt;$M_{11}, M_{13}, M_{22}, M_{23}$&lt;/span&gt; elements of the matrix&lt;/strong&gt; a little with some scaling and offseting that I'm sure you can figure out when looking at how these matrices are constructed. The rest can stay as they are (provided you don't need chunking in the z-direction either, which would be used for different techniques than what you are trying to do).&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2019-01-20T12:30:09.450" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8503" PostTypeId="1" AcceptedAnswerId="8602" CreationDate="2019-01-20T16:00:53.367" Score="2" ViewCount="240" Body="&lt;p&gt;I departed slightly from the Vulkan tutorial I was following and decided to draw a wireframe instead of a solid triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As soon as I call &lt;code&gt;vkCreateGraphicsPipelines()&lt;/code&gt;, I get the following message from Validation Layer even though the call finishes with &lt;code&gt;VK_SUCCESS&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;code&gt;vkCreateGraphicsPipelines&lt;/code&gt; parameter, &lt;code&gt;VkPolygonMode&lt;/code&gt; &lt;code&gt;pCreateInfos-&amp;gt; pRasterizationState-&amp;gt;polygonMode&lt;/code&gt; cannot be &lt;code&gt;VK_POLYGON_MODE_POINT&lt;/code&gt; or &lt;code&gt;VK_POLYGON_MODE_LINE&lt;/code&gt; if &lt;code&gt;VkPhysicalDeviceFeatures-&amp;gt;fillModeNonSolid&lt;/code&gt; is false.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;For good measure I check the &lt;code&gt;VkPhysicalDeviceFeatures&lt;/code&gt; right after I call &lt;code&gt;vkCreateGraphicsPipelines()&lt;/code&gt; and &lt;code&gt;fillModeNonSolid&lt;/code&gt; is &lt;code&gt;VK_TRUE&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output is a wireframe triangle as expected but the message got me worried if I am missing something.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using Nvidia GeForce GTX 1050Ti (driver 417.22), Vulkan 1.1.82.1 on Windows 10(64-bit).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS: I am experiencing similar problem with wideLines feature as well:&lt;code&gt;VkPhysicalDeviceFeatures&lt;/code&gt; has &lt;code&gt;wideLines&lt;/code&gt; as &lt;code&gt;VK_TRUE&lt;/code&gt; but Validation Layer thinks it is set to false&lt;/p&gt;&#xA;" OwnerUserId="6496" LastEditorUserId="6496" LastEditDate="2019-01-20T19:15:48.213" LastActivityDate="2019-02-15T22:43:02.520" Title="Inconsistent behavior involving VkPhysicalDeviceFeatures.fillModeNonSolid" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8504" PostTypeId="2" ParentId="8479" CreationDate="2019-01-21T12:37:59.227" Score="0" Body="&lt;h2&gt;GPU friendly - full formulas&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;IDEA&lt;/strong&gt;: lets find position of center of each pixel &lt;span class=&quot;math-container&quot;&gt;$P_{ij}$&lt;/span&gt; which allows us to easily find ray which starts at &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; and go thought that pixel. To do it we find first &lt;span class=&quot;math-container&quot;&gt;$P_{1m}$&lt;/span&gt; and find others by move on vievports plane.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;ASSUMPTION&lt;/strong&gt;: Below we introduce formulas which includes distance &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; between eye and viewport however this value will be reduced during ray &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt; normalization (so you might as well accept that &lt;span class=&quot;math-container&quot;&gt;$d=1$&lt;/span&gt; and remove it from calculations).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;PRECALCULATIONS&lt;/strong&gt;: First we calculate normalized vectors &lt;span class=&quot;math-container&quot;&gt;$v_n, b_n$&lt;/span&gt; from picutre (which are parallel to viewport plane and give as direction for shifting)&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$t = T-E, \qquad b = w\times t  $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ &#xA;t_n = \frac{t}{||t||}, \qquad&#xA;b_n = \frac{b}{||b||}, \qquad&#xA;v_n = t_n\times b_n \\ &#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;notice: &lt;span class=&quot;math-container&quot;&gt;$C=E+t_nd$&lt;/span&gt;, then we calculate viewport size divided by 2 and including aspect ratio &lt;span class=&quot;math-container&quot;&gt;$\frac{m}{k}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$g_x=\frac{h_x}{2} =d \tan \frac{\theta}{2}, \qquad  g_y =\frac{h_y}{2} = g_x \frac{m}{k}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;and then we calculate shifting vectors &lt;span class=&quot;math-container&quot;&gt;$q_x,q_y$&lt;/span&gt; on viewport &lt;span class=&quot;math-container&quot;&gt;$x,y$&lt;/span&gt; direction and viewport left upper pixel&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ q_x = \frac{2g_x}{k-1}b_n, \qquad&#xA;q_y = \frac{2g_y}{m-1}v_n, \qquad&#xA;p_{1m} = t_n d - g_xb_n - g_yv_n$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;CALCULATIONS&lt;/strong&gt;: notice that &lt;span class=&quot;math-container&quot;&gt;$P_{ij} = E + p_{ij}$&lt;/span&gt; and ray &lt;span class=&quot;math-container&quot;&gt;$R_{ij} = P_{ij} -E = p_{ij}$&lt;/span&gt; so normalized ray &lt;span class=&quot;math-container&quot;&gt;$r_{ij}$&lt;/span&gt; is&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ p_{ij} = p_{1m} + q_x(i-1) + q_y(j-1)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ r_{ij} = \frac{p_{ij}}{||p_{ij}||} $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;TEST&lt;/strong&gt;: above formulas wast tested &lt;a href=&quot;https://kamil-kielczewski.github.io/fractals/mandelbulb.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;HERE&lt;/a&gt; (works in browser)&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;SUMMARY&lt;/strong&gt;: The above form is convenient to use it in shaders where in shader kernel we perform only final calculation based on prcarculated &lt;span class=&quot;math-container&quot;&gt;$q_x,q_y$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p_{1m}$&lt;/span&gt;. Wiki &lt;a href=&quot;https://en.wikipedia.org/wiki/Ray_tracing_(graphics)#Calculate_rays_for_rectangular_viewport&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="9881" LastEditorUserId="9881" LastEditDate="2021-03-16T19:28:58.373" LastActivityDate="2021-03-16T19:28:58.373" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8505" PostTypeId="1" AcceptedAnswerId="8521" CreationDate="2019-01-21T13:20:04.613" Score="2" ViewCount="196" Body="&lt;p&gt;I'm trying to write my own spectral path tracer and a bit stuck with converting computed SPDs to LDR RGB values. What I'm doing right now is convert sampled SPDs (in &lt;code&gt;W/m^-1&lt;/code&gt;) to XYZ using CIE 1931 color matching functions:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;Vec3 xyz(0, 0, 0);&#xA;float norm = 0;&#xA;&#xA;for (int i = 0; i &amp;lt; SPD_SAMPLE_COUNT; ++i) {&#xA;    const float wavelength =&#xA;        lerp(MIN_WAVELENGTH, MAX_WAVELENGTH, i / SPD_SAMPLE_COUNT);&#xA;    const Vec3 cieMatchingFunctionValue = cie1931(wavelength);&#xA;    xyz += cieMatchingFunctionValue * spd[i];&#xA;    norm += cieMatchingFunctionValue.y;&#xA;}&#xA;&#xA;xyz /= norm;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here implementation of &lt;code&gt;cie1931&lt;/code&gt; is an anylitic approximation from &lt;a href=&quot;http://jcgt.org/published/0002/02/01/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wyman et al&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then XYZ to xyY (i.e. chromaticity and luminance), normalise luminance to be in [0, 1] range across the whole image (for now by dividing my max luminance just to keep it simple):&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;float maxLuminance = 0;&#xA;&#xA;for (auto &amp;amp;xyz : image) {&#xA;    maxLuminance = std::max(maxLuminance, xyz.y);&#xA;}&#xA;&#xA;for (auto &amp;amp;xyz : image) {&#xA;    Vec2 chromaticity = Vec2(xyz.x, xyz.y) / (xyz.x + xyz.y + xyz.z);&#xA;    float luminance = xyz.y / maxLuminance;&#xA;&#xA;    // then to &quot;scaled&quot; XYZ and RGB, see below&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Also I've tried Reinhard tone mapping operator:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;float logSum = 0;&#xA;&#xA;for (auto &amp;amp;xyz : image) {&#xA;    logSum += std::log(xyz.y);&#xA;}&#xA;&#xA;float logAvgLuminance = std::exp(logSum / image.size());&#xA;&#xA;for (auto &amp;amp;xyz : image) {&#xA;    Vec2 chromaticity = Vec2(xyz.x, xyz.y) / (xyz.x + xyz.y + xyz.z);&#xA;    const float a = 0.18; // constant from Reinhard's paper.&#xA;    float luminance = a * xyz.y / logAvgLuminance;&#xA;    luminance /= luminance + 1;&#xA;&#xA;    // then to &quot;scaled&quot; XYZ and RGB, see below&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then back to XYZ, than to linear RGB (wia &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_forward_transformation_(CIE_XYZ_to_sRGB)&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; transform):&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;for (auto &amp;amp;xyz : image) {&#xA;    // XYZ to chromaticity and &quot;scaled luminance&quot;, see above&#xA;&#xA;    Vec3 scaledXyz(&#xA;        chromaticity.x * luminance / chromaticity.y,&#xA;        luminance,&#xA;        (1 - chromaticity.x - chromaticity.y) * luminance / chromaticity.y&#xA;    );&#xA;&#xA;    float r = dot(Vec3( 3.2406, -1.5372, -0.4986), scaledXyz);&#xA;    float g = dot(Vec3(-0.9689,  1.8758,  0.0415), scaledXyz);&#xA;    float b = dot(Vec3( 0.0557, -0.2040,  1.0570), scaledXyz);&#xA;&#xA;    // Output RGB, i.e. std::cout &amp;lt;&amp;lt; Vec3(r, g, b);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After that I still get RGB values outside of [0..1]. What am I doing wrong? It seems that &quot;max&quot; luminance should depend on chromaticities of the color. Is there an algorithm to account for that?&lt;/p&gt;&#xA;" OwnerUserId="2960" LastEditorUserId="2960" LastEditDate="2019-01-25T12:19:38.787" LastActivityDate="2019-01-27T00:06:35.283" Title="Computing sRGB color from SPDs" Tags="&lt;color&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8507" PostTypeId="1" CreationDate="2019-01-21T18:17:43.947" Score="2" ViewCount="36" Body="&lt;p&gt;I have a SVG with group of independent arcs that move around common origin.&#xA;On user event those arcs can change both their radii and start/end angles.&#xA;On other user event the user can change view from 2d to fake 3d (orthographic?) via following css transform, as described &lt;a href=&quot;https://beta.observablehq.com/d/190a4518cada1873&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;translate(0px, &lt;span class=&quot;math-container&quot;&gt;${t*5 - i*t*40}px)&#xA;rotateX($&lt;/span&gt;{t*60}deg)&#xA;rotateZ(${t*-30}deg)&#xA;scale(1.0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;t&lt;/code&gt; is a boolean flag telling if perspective view is on or off, if flag = 0 then no actual transformation is made.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code that illustrate the example can be viewed here: &#xA;&lt;a href=&quot;https://codepen.io/stopyransky/pen/MZPbjg&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://codepen.io/stopyransky/pen/MZPbjg&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you click button to trigger perspective view it changes correctly, but arc transitions (radii/angle) are now messed up. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is how to fix so the transitions of arcs will remain correct? &#xA;I assume I need to modify the functions that change how arc is build in &lt;code&gt;tweenAngles&lt;/code&gt; and &lt;code&gt;tweenRadii&lt;/code&gt; but I have no clue what those transitions should be. I tried to reverse transitions when flag is 0 but it does not help.&lt;/p&gt;&#xA;" OwnerUserId="9793" LastActivityDate="2019-01-21T18:17:43.947" Title="Transforming arcs and perspective change" Tags="&lt;transformations&gt;&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8510" PostTypeId="1" AcceptedAnswerId="8511" CreationDate="2019-01-23T02:45:43.430" Score="5" ViewCount="673" Body="&lt;p&gt;The Unity Engine manual page &lt;a href=&quot;https://docs.unity3d.com/Manual/BestPracticeLightingPipelines.html&quot; rel=&quot;noreferrer&quot;&gt;Best Practice: Setting up the Lighting Pipeline&lt;/a&gt; has a section &quot;Render pipelines&quot; with an illustration of Tile Rendering and Cluster Rendering:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tpMCt.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tpMCt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The section then mentions:  &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Opaque objects will most likely be shaded using the tile system,&#xA;  whereas transparent ones will rely on the cluster system.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What is the benefit of using Clustered Shading with transparent objects? Is it related to performance, or are transparent objects not supported by Tiled Shading?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why opaque objects will &quot;not likely&quot; be rendered with Clustered Shading?&lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2019-01-23T12:27:42.260" Title="Benefits of Clustered Shading vs Tiled Shading?" Tags="&lt;real-time&gt;&lt;transparency&gt;&lt;unity&gt;&lt;tile-based-rendering&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8511" PostTypeId="2" ParentId="8510" CreationDate="2019-01-23T09:52:13.957" Score="3" Body="&lt;p&gt;Both Unity's &quot;&lt;a href=&quot;https://docs.unity3d.com/Manual/RenderTech-DeferredShading.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Deferred shading rendering path&lt;/a&gt;&quot; and &quot;&lt;a href=&quot;https://docs.unity3d.com/Manual/RenderTech-DeferredLighting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Legacy Deferred Lighting Rendering Path&lt;/a&gt;&quot; work only for opaque surfaces. They both rely on a very similar set of passes:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render the opaque objects' lighting parameters to a number of render targets. This is referred to as the &quot;G-Buffer pass&quot; or &quot;base pass&quot;.&lt;/li&gt;&#xA;&lt;li&gt;Lighting is then computed in screen-space using the buffers of the first pass to compute lighting. The main benefit is that the cost of lighting is independent of scene complexity. This allows for much more complicated lighting equations with a greater number of lights.&lt;/li&gt;&#xA;&lt;li&gt;Full-screen pass to resolve all these buffers to a final color.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The reason this doesn't work for transparent objects is that they must be rendered back to front &lt;em&gt;completely shaded&lt;/em&gt; (lighting and all). If transparent object A is in front of transparent object B, B must be completely shaded when A blends its color with B. We need that final shaded color because the lighting parameters accumulated in G-Buffers cannot be blended.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, if you can use it (there are downsides), deferred shading has some very nice properties that produce very good results with good performance. That is why opaque objects will &quot;likely&quot; use deferred shading. Quoting from Unity doc:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;When using deferred shading, there is no limit on the number of lights that can affect a GameObject. All lights are evaluated per-pixel, which means that they all interact correctly with normal maps, etc. Additionally, all lights can have cookies and shadows.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Deferred shading has the advantage that the processing overhead of lighting is proportional to the number of pixels the light shines on. This is determined by the size of the light volume in the Scene regardless of how many GameObjects it illuminates. Therefore, performance can be improved by keeping lights small. Deferred shading also has highly consistent and predictable behaviour. The effect of each light is computed per-pixel, so there are no lighting computations that break down on large triangles.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I wasn't able to find much information about Unity's clustered rendering. From what I gather it's an optimization technique for forward rendering, but it's still fundamentally the same process. Here's a very nice write-up of &lt;a href=&quot;http://www.adriancourreges.com/blog/2016/09/09/doom-2016-graphics-study/&quot; rel=&quot;nofollow noreferrer&quot;&gt;how it works in Doom&lt;/a&gt; (go to the &quot;Clustered-Forward-Rendering of Opaque Objects&quot; section).&lt;/p&gt;&#xA;" OwnerUserId="7644" LastEditorUserId="7644" LastEditDate="2019-01-23T12:27:42.260" LastActivityDate="2019-01-23T12:27:42.260" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8515" PostTypeId="1" AcceptedAnswerId="8517" CreationDate="2019-01-25T10:54:30.140" Score="3" ViewCount="1164" Body="&lt;p&gt;So I wanted to know how do Game Engines like Unity3D and Unreal do lighting. I'm familiar with Ray-tracing, pathtracing based renderers etc. But not much with rasterization based engines. I do know a general overview of OpenGL's pipeline and things like vertex and fragment shaders but I don't know how exactly the color is computed. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm guessing Rasterization based pipelines use the same procedure for shading i.e. A ray is shot from the pixel and then from the triangle that got projected on that pixel to the light source?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For indirect lighting they use things like ambient occlusion I guess. Am I correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this is true then the only difference between rasterization and pathtracing would be the procedure for Visible Surface Determination and Indirect Illumination. Direct Illumination would be calculated the same way in both techniques?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you can provide a brief overview of the current state of the art techniques used in these engines for things like reflection/shadows etc it'd be appreciated.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-01-25T20:01:20.003" Title="How is lighting done in Rasterization based pipeline?" Tags="&lt;lighting&gt;&lt;shading&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8517" PostTypeId="2" ParentId="8515" CreationDate="2019-01-25T20:01:20.003" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I'm guessing Rasterization based pipelines use the same procedure for shading i.e. A ray is shot from the pixel and then from the triangle that got projected on that pixel to the light source?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Close, but not quite. There's no actual tracing of rays but the underlying linear algebra is the same. It sounds like you already understand the first part of rasterisation, as far as getting some fragments which need to be shaded. Each fragment knows the attributes of the triangle it came from (the world position, normal, etc.). In traditional forward shading, the fragment shader runs once per light, and it also knows the attributes of the light, including the world-space direction from the shading point to the light: the direction you would trace a shadow ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although no shadow ray is traced, the actual lighting calculation is exactly the same: you use the view and light directions and the surface normal in whatever BRDF you want. You just repeat the process for each light and sum the results. At the end, you have the same result that you'd get from a very simple ray-tracer, without any shadows, reflections, refractions, or indirect lighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to add those missing features? Well, there are several possible techniques for each, but I'll briefly go over the simplest. A simple way of getting shadows is using shadow maps. Before you render your main scene, you do a render into an off-screen buffer, but using the light as a camera. (The projection and shape depend on the light, e.g. orthogonal projection for a directional/cylindrical light.) The trick is, you don't render all the colours: you only draw into the depth buffer. What you get is a picture of the distance from the light to the closest thing in each direction. Later on, when you're shading for that light's contribution in the fragment shader, you calculate the distance from the light to the shading point, and compare it to the value in the depth buffer. That tells you whether the shading point is the closest thing to the light along that ray, without having to run an intersection test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Planar reflections and refractions are pretty simple too: just render the scene but with the camera transformed to produce the reflection or refraction image. For example, for a planar reflection in a lake or floor, you reflect the camera position about that plane to draw the whole scene upside-down. When you draw the real scene around it, any transparency shows that reflection.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-01-25T20:01:20.003" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8520" PostTypeId="1" CreationDate="2019-01-26T21:49:21.333" Score="1" ViewCount="42" Body="&lt;p&gt;I am reading a paper and there is a part I don't understand:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/anl7u.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/anl7u.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am wondering why the isotropic BRDF only depends on the view direction and roughness? Why is the light direction not related?&lt;/p&gt;&#xA;" OwnerUserId="9987" LastActivityDate="2019-01-26T21:49:21.333" Title="confused on isotropic BRDF" Tags="&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8521" PostTypeId="2" ParentId="8505" CreationDate="2019-01-27T00:06:35.283" Score="2" Body="&lt;p&gt;Getting sRGB values outside [0, 1] is expected and normal when using spectral rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sRGB gamut only covers a triangle in the middle of the CIE chromaticity space:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Y9z7W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y9z7W.png&quot; alt=&quot;CIE chromaticity diagram with sRGB gamut highlighted&quot;&gt;&lt;/a&gt;&#xA;(diagram from &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#/media/File:Cie_Chart_with_sRGB_gamut_by_spigget.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The big &quot;horseshoe&quot; shape is the set of all physically possible chromaticities (CIE xy coordinates) from any possible spectrum. So your xy coordinates should be expected to land somewhere in the horseshoe...but only the ones that land inside the triangle are representable as sRGB! The others are &quot;too saturated&quot; for sRGB, and will have to be clamped or remapped somehow. (Tone mapping per se doesn't fix this, as it's concerned with luminance rather than chromaticity.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a variety of approaches to deal with out-of-gamut colors depending on how sophisticated you want to be:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You can of course simply clamp the sRGB values, but this may change the hue and/or the luminance of the color in the process.&lt;/li&gt;&#xA;&lt;li&gt;To preserve both hue and luminance, you can edit the xy coordinates before calculating &lt;code&gt;scaledXyz&lt;/code&gt;. If the initial xy coordinates are outside the sRGB triangle, find the line segment from the xy coordinates to the white point (e.g. D65); then find the intersection of that line segement with the sRGB triangle. That's the closest sRGB point that has the same luminance and hue as the original point, but lower saturation. (The vertices of the sRGB triangle can be obtained by converting RGB(1, 0, 0), RGB(0, 1, 0), and RGB(0, 0, 1) to CIE xy space.)&lt;/li&gt;&#xA;&lt;li&gt;Alternatively, rather than clamping (which throws away any detail in the saturation outside the sRGB gamut), you could try doing a linear or non-linear remapping of saturation values in the image, similar to how you do for luminance. By &quot;saturation&quot; here I mean distance from the white point. The idea would be to squish the whole image toward the white point so as to bring everything within the gamut. But that may affect the apparent saturation of in-gamut colors in visually undesirable ways.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-01-27T00:06:35.283" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8523" PostTypeId="1" CreationDate="2019-01-28T15:10:16.060" Score="2" ViewCount="66" Body="&lt;p&gt;I am trying to determine whether two frusta intersect in 3D space and to quantify this intersection as a percentage of one frustum volume (eg. 100% intersection meaning that the two frusta occupy the same exact space, 0% the two frusta don't touch).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have all the possible data about each frustum, the six planes and their position and so on but I can't figure out what's a reliable method to get what I want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had a look at the Separating Axis Algorithm for collision detection but I don't understand if it's what I need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone direct me towards the right path?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="10074" LastActivityDate="2019-01-28T15:10:16.060" Title="Intersecting Frusta" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="15" ContentLicense="CC BY-SA 4.0" />
  <row Id="8524" PostTypeId="1" CreationDate="2019-01-28T17:45:33.633" Score="2" ViewCount="127" Body="&lt;p&gt;I am trying to get started with implementing a basic display (i.e a simple red screen) onto a VGA monitor by programming a Xilinx spartan3a fpga for the same.&#xA;I have studied about the signal timings for a 640x480 @ 60hz display and implemented the same,however it turns out, The monitor does not recognize it.I tried using a sample test file (it was a bit file so couldn't reverse engineer it), and it worked perfectly so i think there's no issue with the hardware.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;module main(&#xA;    clk,&#xA;    Hsync,&#xA;    Vsync,&#xA;    Red,&#xA;    Green,&#xA;    Blue,&#xA;    led&#xA;);&#xA;&#xA;//inputs:&#xA;input clk;&#xA;//outputs:&#xA;output Hsync;&#xA;output Vsync;&#xA;output[2:0] Red;&#xA;output[2:0] Green;&#xA;output [1:0] Blue;&#xA;output [7:0] led;&#xA;//wire&#xA;wire[9:0] hcounter;&#xA;wire[9:0] vcounter;&#xA;wire PixClk;&#xA;wire locked;&#xA;//regs:&#xA;reg reset;&#xA;&#xA;clkgen inst(&#xA;.CLKIN_IN(clk), &#xA;.RST_IN(1'b0), &#xA;.CLKIN_IBUFG_OUT(), &#xA;.CLK0_OUT(PixClk), &#xA;.LOCKED_OUT(locked)&#xA;);&#xA;&#xA;VGAcontroller controller1(&#xA;    .locked(locked),&#xA;    .pixel_clk(PixClk),&#xA;    .hsync(Hsync),&#xA;    .vsync(Vsync),&#xA;    .hcounter(hcounter),&#xA;    .vcounter(vcounter)&#xA;);&#xA;&#xA;generateRGB RedScreen(&#xA;    .RedPix(Red),&#xA;    .GreenPix(Green),&#xA;    .BluePix(Blue),&#xA;    .Hcount(hcounter),&#xA;    .Vcount(hcounter)&#xA;);&#xA;&#xA;assign led[0]=locked;&#xA;assign led[7:1]=7'b0;&#xA;endmodule&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the clockgen module generates a 25mhz signal, and led[0] goes &quot;ON&quot; when the dcm-pll has a locked onto the frequency.(works in the implementation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;'VGAcontroller' module is responsible for the 'Hsync' and 'Vsync' signal generation taking in 'Pixelclk' and locked as inputs with the rest as outputs. The 'generateRGB' module takes in the 'Hcounter' and 'Vcounter' values to provide the necessary analog values via 3 registers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;VGAcontroller.v&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//800 horizontal counts&#xA;//525 vertical counts&#xA;&#xA;module VGAcontroller(&#xA;    locked,&#xA;    pixel_clk,&#xA;    hsync,&#xA;    vsync,&#xA;    hcounter,&#xA;    vcounter&#xA;);&#xA;&#xA;input locked;&#xA;input pixel_clk;&#xA;output hsync;&#xA;output vsync;&#xA;output[9:0] hcounter;&#xA;output[9:0] vcounter;&#xA;&#xA;reg hsync;&#xA;reg vsync;&#xA;reg[9:0] hcounter;&#xA;reg[9:0] vcounter;&#xA;&#xA;always @(posedge pixel_clk or posedge locked)&#xA;begin&#xA;    if(locked)&#xA;    begin&#xA;        hcounter=hcounter+1'b1;&#xA;        case(hcounter)&#xA;            10'b0:              hsync=1'b1; //d&amp;lt;0&amp;gt;&#xA;            10'b1010010000: hsync=1'b0; //d&amp;lt;656&amp;gt;&#xA;            10'b1011110000: hsync=1'b1; //d&amp;lt;752&amp;gt;&#xA;            10'b1100100000:                 //d&amp;lt;800&amp;gt;&#xA;            begin&#xA;                hcounter=10'b0;&#xA;                vcounter=vcounter+1'b1;&#xA;            end&#xA;        endcase&#xA;        case(vcounter)&#xA;            10'b0:      vsync=1'b1;                 //d&amp;lt;0&amp;gt;&#xA;            10'b0111101010: vsync=1'b0;         //d&amp;lt;490&amp;gt;    &#xA;            10'b0111101100: vsync=1'b1;         //d&amp;lt;492&amp;gt;&#xA;            10'b1000001101: vcounter=10'b0; //d&amp;lt;525&amp;gt;&#xA;        endcase&#xA;    end else begin&#xA;        hcounter=10'b0;&#xA;        vcounter=10'b0;&#xA;    end&#xA;end&#xA;endmodule&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the timing sequence is as follows : [visible range]-&gt;[front porch]-&gt;[Sync pulse]-&gt;[back porch]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the reason for starting the counter with visible range is that the values of counters correspond to the location of the pixel on the screen.&#xA;As of now , the 'generateRGB' simply assigns the register responsible for the red color to have full voltage while green and blue to be 0 i.e to print a red screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;P.S. I am not exactly sure whether this question is valid for this forum or whether tags do good justice but if there is a better one, kindly recommend.thank you!&lt;/p&gt;&#xA;" OwnerUserId="10075" LastEditorUserId="2041" LastEditDate="2019-01-28T18:22:29.513" LastActivityDate="2019-01-28T18:22:29.513" Title="debugging VGA signal timings for 640x480 @ 60hz" Tags="&lt;frame-buffer&gt;&lt;video&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8525" PostTypeId="1" AcceptedAnswerId="8545" CreationDate="2019-01-28T19:40:42.307" Score="2" ViewCount="230" Body="&lt;p&gt;So I am currently in the process of implementing Physically based Shading in my pathtracer using microfacet models and I'm quite stuck at comprehending light interaction with diffuse surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all I want to get a clear concept of how surfaces actually get their color. We all know that the color of any surface is due to their property to absorb light of certain wavelength in the Visible region of the spectrum. More specifically, according to the answer &lt;a href=&quot;https://physics.stackexchange.com/questions/269201/what-is-the-actual-mechanism-behind-the-reflection-of-various-colored-light-by-m&quot;&gt;here&lt;/a&gt;, when light hits an atom or molecule it gets absorbed if the electrons have the same vibrational frequency as the light. Which is the reason for the color of a surface. Now let's see what happens when light interacts with a diffuse surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When Light hits a diffuse (dielectric or non-metal) surface 2 things happen. It gets reflected specularly or it gets refracted, scattered, and re-emitted which we call &quot;diffuse reflection&quot;. The amount of light that gets reflected/refracted depends on the Fresnel Equation which are wave-length dependent. This gives off the hint that an RGB triple also arises due to wavelength dependent IOR and thus maybe the reason for the color. So here's the main confusion.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;When light hits a diffuse surface and gets reflected specularly it's possible that the atoms or molecules at the interaction surface absorb some of the light. This might be the reason for the color. On the other hand, the composition of light also changes in each of the R, G, B spectrum due to wavelength dependent index of refraction and Fresnel equations. So what's the real reason for the color? Is it the former or the latter or a mix of the two?  I've read some notes by Naty Hoffman where he also suggests using the Fresnel Reflectance values as the specular color when calculating a specular BRDF like Cook torrance. Adds a lot more to my confusion.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;After the above has been clarified how does the whole thing tie with the light that got refracted, scattered and re-emitted?&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;Secondly since diffuse surfaces exhibit both specular and diffuse reflection why do I mostly see people using just lambertian model for diffuse surfaces? The proper way would be to use a BRDF for diffuse reflection + a BRDF for specular like Cook Torrance. Am I correct?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Thirdly shouldn't we be weighting the diffuse component with &lt;span class=&quot;math-container&quot;&gt;$(1-F_{in})(1-F_{out})...$&lt;/span&gt; or more fresnel terms depending on, if the refracted ray undergoes total internal reflection. Are these factors built-in by default or what?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-01-28T19:53:08.027" LastActivityDate="2019-02-02T15:41:57.170" Title="Physically Based Shading for Diffuse surfaces" Tags="&lt;lighting&gt;&lt;physically-based&gt;&lt;shading&gt;&lt;physics&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8527" PostTypeId="1" CreationDate="2019-01-29T09:21:45.970" Score="1" ViewCount="1249" Body="&lt;p&gt;I am new to shaders and I need to convert efficiently an RGB image to YUV420.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can convert the RGB image to YUV420 with a simple c++ program that uses the &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;long length = m_width * m_height;&#xA;&#xA;long yuv420FrameLength = (float)length * 1.5;&#xA;unsigned char *yuvdest = (unsigned char *)malloc(yuv420FrameLength * sizeof(unsigned char));&#xA;&#xA;int r, g, b, y, u, v, ypos, upos, vpos;&#xA;&#xA;for (int j = 0; j &amp;lt; m_height; ++j) {&#xA;    for (int i = 0; i &amp;lt; m_width; ++i) {&#xA;        r = (int)m_pRGBImage[(j * m_width + i) * 3 + 0];&#xA;        g = (int)m_pRGBImage[(j * m_width + i) * 3 + 1];&#xA;        b = (int)m_pRGBImage[(j * m_width + i) * 3 + 2];&#xA;&#xA;        y = ((66 * r + 129 * g + 25 * b + 128) &amp;gt;&amp;gt; 8) + 16;&#xA;        u = ((-38 * r - 74 * g + 112 * b + 128) &amp;gt;&amp;gt; 8) + 128;&#xA;        v = ((112 * r - 94 * g - 18 * b + 128) &amp;gt;&amp;gt; 8) + 128;&#xA;        ypos = j * m_width + i;&#xA;        upos = (j / 2) * (m_width / 2) + (i / 2) + length;&#xA;        vpos = (j / 2) * (m_width / 2) + (i / 2) + length + (length / 4);&#xA;&#xA;        yuvdest[ypos] = y;&#xA;        yuvdest[upos] = u;&#xA;        yuvdest[vpos] = v;&#xA;    }&#xA;}&#xA;std::ofstream myfile;&#xA;myfile.open(pPath, std::ios_base::trunc);&#xA;myfile &amp;lt;&amp;lt; yuvdest;&#xA;myfile.close();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I can transform the pixels and create the YUV with the following shader code (I did not test it, if I'm wrong, please tell me).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;sampler2D sampler0            : register(s0);&#xA;&#xA;struct VS_INPUT&#xA;{&#xA;  float4 Position   : POSITION;&#xA;  float2 Tex0       : TEXCOORD0;&#xA;};&#xA;&#xA;struct VS_OUTPUT&#xA;{&#xA;  float4 Position   : POSITION;&#xA;  float2 Tex0       : TEXCOORD0;&#xA;};&#xA;&#xA;struct PS_OUTPUT&#xA;{&#xA;  float4 Color   : COLOR0;&#xA;};&#xA;&#xA;PS_OUTPUT psmain(in VS_OUTPUT In)&#xA;{&#xA;  PS_OUTPUT Out;&#xA;  Out.Color = tex2D(sampler0, In.Tex0);&#xA;  int r = Out.Color.x;&#xA;  int g = Out.Color.y;&#xA;  int b = Out.Color.z;&#xA;  float y = ((66 * r + 129 * g + 25 * b + 128) &amp;gt;&amp;gt; 8) + 16;&#xA;  float u = ((-38 * r - 74 * g + 112 * b + 128) &amp;gt;&amp;gt; 8) + 128;&#xA;  float v = ((112 * r - 94 * g - 18 * b + 128) &amp;gt;&amp;gt; 8) + 128;;&#xA;  return Out;&#xA;};&#xA;&#xA;VS_OUTPUT vsmain(in VS_INPUT In)&#xA;{&#xA;  VS_OUTPUT Out;&#xA;  Out.Position = In.Position;&#xA;  Out.Tex0 = In.Tex0;&#xA;  return Out;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The thing that is missing to me is how to arrange the bytes formation correctly as the C++ code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ypos = j * m_width + i;&#xA;upos = (j / 2) * (m_width / 2) + (i / 2) + length;&#xA;vpos = (j / 2) * (m_width / 2) + (i / 2) + length + (length / 4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10080" LastActivityDate="2019-02-28T15:03:10.687" Title="Convert RGB image to YUV420 using a hlsl shader" Tags="&lt;shader&gt;&lt;image-processing&gt;&lt;hlsl&gt;&lt;pixel-graphics&gt;&lt;pixel-shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8528" PostTypeId="2" ParentId="8527" CreationDate="2019-01-29T14:18:10.777" Score="1" Body="&lt;p&gt;The problem here is that you're not storing the YUV values of a pixel at the same place in the result image. What you seem to be doing is first storing the full size Y image and after that the quarter-sized U image and then the quarter-sized V image after that (also with a strange gap of half the image size between the Y and the UV data).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This doesn't work when trying to map it to a standard pixel shader approach, since a pixel shader outputs the value of exactly 1 pixel in the output image, but you actually would need to write 3 different scattered pixels in the output image, at least as your image data is currently laid out in memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So there's a few ways you could get around that:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;You could output the YUV values directly into a full-sized YUV image (with the Y, u, and v values of a single pixel stored together in the RGB channels of the output) and then further compress this into the disparate memory layout you need, either on the CPU or in another pixel shader that just decides what channels to read from the Yuv image based on the pixel position inside of the output image.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You could combine the above two shaders into one, doing either the Y, the U or the V computation, based on which quarter of the output image you're in.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You can switch to a different layout for your YUV data, e.g. storing the Yuv values of a 2x2 pixel block of the input image in one compressed pixel of the output image. Then it might actually be useful to write into an unsigned integer image and do the converstion to bytes and the compression yourself in the shader.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You can use your C++ algorithm and write the data in a scattered fashion, but not using a pixel shader rather than a &lt;em&gt;compute shader&lt;/em&gt; and writing into a generalized buffer/image instead (or combining the two and writing into a generalized buffer/image rather than the frambuffer directly from the pixel shader).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;However, I left the above explanations decidedly vague and general for further studying, since there are a few more direct practical mistakes in your actual shader code (e.g. &lt;code&gt;Out.Color&lt;/code&gt; should contain your output values, you're also computing with float, so they're likely in the [0,1] range and you shouldn't do all these integer operations on them), which indicate that you might first want to delve a little deeper into how shaders and HLSL work.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2019-01-29T14:18:10.777" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8529" PostTypeId="1" AcceptedAnswerId="8566" CreationDate="2019-01-29T20:49:11.497" Score="2" ViewCount="91" Body="&lt;p&gt;I'm trying to port part of an OpenGL program into an existing DirectX 12 software, at some point in their shaders they use OpenGL &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Load_Store&quot; rel=&quot;nofollow noreferrer&quot;&gt;ImageLoadStore&lt;/a&gt; in order to store information in 3D Textures without having to use an FBO.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there something similar in the DirectX 12 API? &#xA;Or would I have to render to a custom FrameBuffer?&lt;/p&gt;&#xA;" OwnerUserId="10086" LastEditorUserId="209" LastEditDate="2019-02-08T16:44:41.903" LastActivityDate="2019-02-08T16:44:41.903" Title="Is there an analogue of OpenGL's ImageLoadStore in DirectX 12?" Tags="&lt;shader&gt;&lt;directx12&gt;&lt;image-load-store&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8531" PostTypeId="1" AcceptedAnswerId="8537" CreationDate="2019-01-30T16:18:01.577" Score="2" ViewCount="76" Body="&lt;p&gt;If I use a 4D noise function which returns a noise value and a four-part analytically derived gradient vector, I can create a 2D tile which is seamless (i.e. the opposite edges match) through remapping &lt;code&gt;x,y&lt;/code&gt; and &lt;code&gt;z,w&lt;/code&gt; coordinates to independent circles, i.e.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\ \theta = a*2*\pi$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\ \phi = b*2*\pi$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; are a point on the surface. They should be within the range &lt;span class=&quot;math-container&quot;&gt;$[0, size)$&lt;/span&gt; where size is some arbitrary shared dimension for the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can then plug &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\phi$&lt;/span&gt; into the below functions to get the equivalent point in 4D space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\ x = r_0*\cos(\theta)$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\ y = r_0*\sin(\theta)$&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\ z = r_1*\cos(\phi) $&lt;/span&gt;&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\ w = r_1*\sin(\phi)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Effectively the surface created through this coordinate mapping is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Torus#Flat_torus&quot; rel=&quot;nofollow noreferrer&quot;&gt;flat torus&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, since the noise function operates in 4D space I'm left with a 4D gradient vector. Is it possible to transform this 4D vector into a 2D vector which describes the gradient of the surface?&lt;/p&gt;&#xA;" OwnerUserId="6406" LastEditorUserId="6406" LastEditDate="2019-01-31T11:33:20.867" LastActivityDate="2019-01-31T15:43:52.293" Title="Finding the normals of a tileable 2D surface extracted from 4D space" Tags="&lt;noise&gt;&lt;normal-mapping&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="8" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8532" PostTypeId="1" AcceptedAnswerId="8542" CreationDate="2019-01-30T17:37:38.873" Score="3" ViewCount="515" Body="&lt;p&gt;I'm trying to integrate the thin-film interference effect described in the paper &quot;Belcour, L., &amp;amp; Barla, P. (2017). A practical extension to microfacet theory for the modeling of varying iridescence.&quot; (&lt;a href=&quot;https://hal.archives-ouvertes.fr/hal-01518344/document&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://hal.archives-ouvertes.fr/hal-01518344/document&lt;/a&gt;) into my material model, which is based on google/Filament's material model (&lt;a href=&quot;https://google.github.io/filament/Filament.md.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://google.github.io/filament/Filament.md.html&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I'm having trouble trying to understand the way to add them together. Let's say I'm shading a pixel, direct lighting goes like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 Fr = specularLobe();   // D * F * V&#xA;vec3 Fd = diffuseLobe();    // 1 / PI * diffuseColor&#xA;&#xA;return (Fd + Fr) * light.color * light.attenuation * NoL;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And on the other side, indirect lighting goes like this...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 Fd = diffuseIrradiance() * diffuseColor;&#xA;vec3 Fr = specularIrradiance() * DFG();&#xA;&#xA;return (Fd + Fr);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now, if I want to add the thin film/iridescence layer on top of the base material, in what way does it take into account to bottom layer for all the lighting?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been looking at this implementation in UE4 (&lt;a href=&quot;https://polycount.com/discussion/comment/2604578#Comment_2604578&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://polycount.com/discussion/comment/2604578#Comment_2604578&lt;/a&gt;), but they seem to input the result of the BRDF calculation directly into the 'Base Color' of the material, which I really don't think it is what I'm looking for, correct me if I'm wrong...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TMqe1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TMqe1.png&quot; alt=&quot;UE4-editor-example&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this other implementation in Unity (&lt;a href=&quot;https://github.com/Xerxes1138/Iridescence/blob/master/Iridescence.shader&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Xerxes1138/Iridescence/blob/master/Iridescence.shader&lt;/a&gt;) they seem to account for iridescence in both IBL and direct lighting separately, but the layer base is not taken much into account as far as I know.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, in the paper itself, the following statement is made:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Our extension consists in replacing the classic Fresnel reflectance&#xA;  term, F , by a more complex term, R accounting for all inter-reflections&#xA;  inside the thin-film layer, including constructive and destructive&#xA;  interference effects.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;From this I understand that simply by replacing the Fresnel Reflectance with the Airy Reflectance function should do the trick, but again, I'm not sure which would be the appropriate approach to being as physically correct as possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(The original supp-code from the paper can be obtained from: &lt;a href=&quot;https://hal.inria.fr/hal-01518344v2/file/supplemental-code%20%282%29.zip&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://hal.inria.fr/hal-01518344v2/file/supplemental-code%20%282%29.zip&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for the help!&lt;/p&gt;&#xA;" OwnerUserId="10091" LastActivityDate="2019-02-01T09:42:44.870" Title="Iridescence/Thin-film interference integration as a layer" Tags="&lt;lighting&gt;&lt;pbr&gt;&lt;rasterizer&gt;&lt;material&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8533" PostTypeId="2" ParentId="8525" CreationDate="2019-01-30T22:21:04.113" Score="0" Body="&lt;p&gt;When people talk about diffuse surfaces in CG they usually mean ideal diffuse surfaces. That is, the BRDF is simply: &lt;span class=&quot;math-container&quot;&gt;$f(\omega_o,x,\omega_i) = const$&lt;/span&gt;. We're talking about Lambertian reflectance. The colour you perceive is due to both the initial light colour and the albedo of the material. If you shine white light, then you'll really perceive what's left of it after absorption. So when you set &lt;span class=&quot;math-container&quot;&gt;$albedo = (r,g,b)$&lt;/span&gt; then your surface reflects &lt;span class=&quot;math-container&quot;&gt;$r \%$&lt;/span&gt; of the red light, &lt;span class=&quot;math-container&quot;&gt;$g\%$&lt;/span&gt; of the green light, and &lt;span class=&quot;math-container&quot;&gt;$b\%$&lt;/span&gt; of the blue light. Note that the tricolor formulation is not how it actually works in the real world, to be precise you should really be dealing with wavelengths, however &lt;span class=&quot;math-container&quot;&gt;$RGB$&lt;/span&gt; is a good approximation perceptually due to how the human visual system works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cosine term is not actually part of the diffuse BRDF either, it comes from Lambert's law (the cosine term in the rendering equation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly you should realise that even Cook-Torrance is an approximation to a class of semi-plausible BRDFs.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="209" LastEditDate="2019-01-31T08:46:12.480" LastActivityDate="2019-01-31T08:46:12.480" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="8534" PostTypeId="1" AcceptedAnswerId="8535" CreationDate="2019-01-31T09:54:57.343" Score="1" ViewCount="412" Body="&lt;p&gt;I am currently looking into alternatives to my current, somewhat slow but exact, OIT approach. Specifically, GL_SAMPLE_ALPHA_TO_COVERAGE to convert the alpha value into a per-sample mask.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// draw opaque objects&#xA;glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);&#xA;glEnable(GL_SAMPLE_ALPHA_TO_ONE);&#xA;glDisable(GL_CULL_FACE);&#xA;// draw translucent objects&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, if multiple alpha-blended faces are behind one another (such as the back faces which I would want to be visible) I am only seeing the front most one. Is depth testing not done per sample? Can I force it to be done per sample? According to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Depth_Test&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengl/wiki/Depth_Test&lt;/a&gt; it should already be per sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Multisampling is enabled and works fine for everything else (my OIT shaders in fact do sorting per sample which might be a reason for the slowness). The FBO being drawn into is provided by Qt.&lt;/p&gt;&#xA;" OwnerUserId="10099" LastEditorUserId="10099" LastEditDate="2019-01-31T10:03:17.193" LastActivityDate="2019-01-31T12:54:18.363" Title="GL_SAMPLE_ALPHA_TO_COVERAGE and depth testing" Tags="&lt;opengl&gt;&lt;blending&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8535" PostTypeId="2" ParentId="8534" CreationDate="2019-01-31T12:54:18.363" Score="1" Body="&lt;p&gt;(Promoting comment to answer)&#xA;Do the faces have the same alpha value? That might generate the same coverage mask for the surfaces and, hence, only the closest one would be seen.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2019-01-31T12:54:18.363" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8537" PostTypeId="2" ParentId="8531" CreationDate="2019-01-31T15:43:52.293" Score="2" Body="&lt;p&gt;Since the question was somewhat clarified I will formalize both the question and the answer for future readers.&#xA;Having a differentiable scalar field &lt;span class=&quot;math-container&quot;&gt;$f : \mathbb{R}^4 \rightarrow \mathbb{R}$&lt;/span&gt; we want to find the gradient of the field with respect to &lt;span class=&quot;math-container&quot;&gt;$\theta, \phi$&lt;/span&gt; on the 2-manifold defined parametrically by: &#xA;&lt;span class=&quot;math-container&quot;&gt;$$(x(\theta,\phi), y(\theta,\phi) z(\theta,\phi), w(\theta,\phi)) = (r_0\cos\theta, r_0\sin\theta, r_1\cos\phi,r_1\sin\phi)$$&lt;/span&gt;&#xA;Where &lt;span class=&quot;math-container&quot;&gt;$r_0,r_1$&lt;/span&gt; are constants. We can compute the partial derivatives as follows:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial f}{\partial \theta} = \frac{\partial f}{\partial x}\frac{\partial x}{\partial \theta} + \frac{\partial f}{\partial y}\frac{\partial y}{\partial \theta} + \frac{\partial f}{\partial z}\frac{\partial z}{\partial \theta} + \frac{\partial f}{\partial w}\frac{\partial w}{\partial \theta} \\&#xA;= -r_0\frac{\partial f}{\partial x}\sin\theta + r_0\frac{\partial f}{\partial y}\cos\theta$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial f}{\partial \phi} = &#xA;\frac{\partial f}{\partial x}\frac{\partial x}{\partial \phi} + \frac{\partial f}{\partial y}\frac{\partial y}{\partial \phi} + \frac{\partial f}{\partial z}\frac{\partial z}{\partial \phi} + \frac{\partial f}{\partial w}\frac{\partial w}{\partial \phi} \\ = -r_1\frac{\partial f}{\partial x}\sin\phi + r_1\frac{\partial f}{\partial y}\cos\phi$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming that the gradient &lt;span class=&quot;math-container&quot;&gt;$\nabla f = (\frac{\partial f}{\partial x},\frac{\partial f}{\partial y},\frac{\partial f}{\partial z},\frac{\partial f}{\partial w})$&lt;/span&gt; is known, it is straightforward to compute the 2d gradient.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that another possibility is to compute the gradient numerically (in case you don't have the partial derivatives of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;):&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \frac{\partial f}{\partial \theta} \approx \frac{f(r_0\cos(\theta+h_{\theta}), r_0\sin(\theta+h_{\theta}), r_1\cos\phi,r_1\sin\phi) - f(r_0\cos\theta, r_0\sin\theta, r_1\cos\phi,r_1\sin\phi)}{h_{\theta}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \frac{\partial f}{\partial \phi} \approx \frac{f(r_0\cos\theta, r_0\sin\theta, r_1\cos(\phi+h_{\phi}),r_1\sin(\phi+h_{\phi})) - f(r_0\cos\theta, r_0\sin\theta, r_1\cos\phi,r_1\sin\phi)}{h_{\phi}}$$&lt;/span&gt;&#xA;For &lt;span class=&quot;math-container&quot;&gt;$h_{\theta}, h_{\phi}$&lt;/span&gt; chosen adequately (note that the choice of these parameters is a nontrivial problem).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-01-31T15:43:52.293" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8539" PostTypeId="1" CreationDate="2019-02-01T06:32:34.783" Score="1" ViewCount="103" Body="&lt;p&gt;I'm having a problem with my model here. I draw an icosahedron using GLUT, and the radius is set to 0.8. The info of the coordinates are listed below: (X and Z are calculated since our radius is 0.8)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; private static final float X = .4205912828f;&#xA; private static final float Z = .6805166955f;&#xA; private static final float[][] idata =&#xA;{&#xA;   {-X, 0, Z},&#xA;   {X, 0, Z},&#xA;   {-X, 0, -Z},&#xA;   {X, 0, -Z},&#xA;   {0, Z, X},&#xA;   {0, Z, -X},&#xA;   {0, -Z, X},&#xA;   {0, -Z, -X},&#xA;   {Z, X, 0},&#xA;   {-Z, X, 0},&#xA;   {Z, -X, 0},&#xA;   {-Z, -X, 0}&#xA; };&#xA;&#xA;private static final int[][] index =&#xA; {&#xA;         {0, 4, 1},&#xA;            {0, 9, 4},&#xA;            {9, 5, 4},&#xA;            {4, 5, 8},&#xA;            {4, 8, 1},&#xA;            {8, 10, 1},&#xA;            {8, 3, 10},&#xA;            {5, 3, 8},&#xA;            {5, 2, 3},&#xA;            {2, 7, 3},&#xA;            {7, 10, 3},&#xA;            {7, 6, 10},&#xA;            {7, 11, 6},&#xA;            {11, 0, 6},&#xA;            {0, 1, 6},&#xA;            {6, 1, 10},&#xA;            {9, 0, 11},&#xA;            {9, 11, 2},&#xA;            {9, 2, 5},&#xA;            {7, 2, 11},&#xA; };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I calculate the vertex normal using the glut method as well: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private static void icosahedron(final GL2 gl) {&#xA;   int i;&#xA;   for (i = 0; i &amp;lt;= 19; i++) {&#xA;     drawtriangle(gl, i, idata, index);&#xA;   }&#xA; }&#xA; private static void diff3(final float[] a, final float[] b, final float[] c) {&#xA;        c[0] = a[0] - b[0];&#xA;        c[1] = a[1] - b[1];&#xA;        c[2] = a[2] - b[2];&#xA;      }&#xA;&#xA; private static void crossprod(final float[] v1, final float[] v2, final float[] prod) {&#xA;        final float[] p = new float[3];         /* in case prod == v1 or v2 */&#xA;&#xA;        p[0] = v1[1] * v2[2] - v2[1] * v1[2];&#xA;        p[1] = v1[2] * v2[0] - v2[2] * v1[0];&#xA;        p[2] = v1[0] * v2[1] - v2[0] * v1[1];&#xA;        prod[0] = p[0];&#xA;        prod[1] = p[1];&#xA;        prod[2] = p[2];&#xA;      }&#xA;&#xA; private static void normalize(final float[] v) {&#xA;        float d;&#xA;&#xA;        d = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);&#xA;        if (d == 0.0) {&#xA;          v[0] = d = 1.0f;&#xA;        }&#xA;        d = 1 / d;&#xA;        v[0] *= d;&#xA;        v[1] *= d;&#xA;        v[2] *= d;&#xA;      }&#xA;&#xA;&#xA; private static void recorditem(final GL2 gl, final float[] n1, final float[] n2, final float[] n3) {&#xA;        final float[] q0 = new float[3];&#xA;        final float[] q1 = new float[3];&#xA;        final float[] q2 = new float[3];&#xA;        diff3(n1, n2, q0);&#xA;        diff3(n2, n3, q1);&#xA;        crossprod(q0, q1, q2);&#xA;        normalize(q2);&#xA;        System.out.format(&quot;%.5f, %.5f, %.5f&quot;,q2[0],q2[1],q2[2]);&#xA;        gl.glBegin(GL.GL_TRIANGLES);&#xA;        gl.glNormal3fv(q2,0);&#xA;        gl.glVertex3fv(n1, 0);&#xA;        gl.glVertex3fv(n2, 0);&#xA;        gl.glVertex3fv(n3, 0);&#xA;        gl.glEnd();&#xA;      }&#xA;&#xA; private static void subdivide(final GL2 gl, final float[] v0, final float[] v1, final float[] v2) {&#xA;        int depth;&#xA;        final float[] w0 = new float[3];&#xA;        final float[] w1 = new float[3];&#xA;        final float[] w2 = new float[3];&#xA;        float l;&#xA;        int i, j, k, n;&#xA;&#xA;        depth = 1;&#xA;        for (i = 0; i &amp;lt; depth; i++) {&#xA;          for (j = 0; i + j &amp;lt; depth; j++) {&#xA;            k = depth - i - j;&#xA;            for (n = 0; n &amp;lt; 3; n++) {&#xA;              w0[n] = (i * v0[n] + j * v1[n] + k * v2[n]) / depth;&#xA;              w1[n] = ((i + 1) * v0[n] + j * v1[n] + (k - 1) * v2[n])&#xA;                / depth;&#xA;              w2[n] = (i * v0[n] + (j + 1) * v1[n] + (k - 1) * v2[n])&#xA;                / depth;&#xA;            }&#xA;            l = (float) Math.sqrt(w0[0] * w0[0] + w0[1] * w0[1] + w0[2] * w0[2]);&#xA;            w0[0] /= l;&#xA;            w0[1] /= l;&#xA;            w0[2] /= l;&#xA;            l = (float) Math.sqrt(w1[0] * w1[0] + w1[1] * w1[1] + w1[2] * w1[2]);&#xA;            w1[0] /= l;&#xA;            w1[1] /= l;&#xA;            w1[2] /= l;&#xA;            l = (float) Math.sqrt(w2[0] * w2[0] + w2[1] * w2[1] + w2[2] * w2[2]);&#xA;            w2[0] /= l;&#xA;            w2[1] /= l;&#xA;            w2[2] /= l;&#xA;            recorditem(gl, w0, w1, w2);&#xA;          }&#xA;        }&#xA;      }  &#xA;&#xA; private static void drawtriangle(final GL2 gl, final int i, final float[][] data, final int[][] ndx) {&#xA;       final float[] x0 = data[ndx[i][0]];&#xA;       final float[] x1 = data[ndx[i][1]];&#xA;       final float[] x2 = data[ndx[i][2]];&#xA;       subdivide(gl, x0, x1, x2);&#xA;     }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, the reflection of the light does not look right on the icosahedron. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My vertex shader: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;attribute vec3 inposition;//in vec3 position;          //for #version 130&#xA;attribute vec4 incolor;&#xA;attribute vec3 innormal;&#xA;attribute vec2 intexcoord0;&#xA;varying vec3 normal;&#xA;varying vec4 color;&#xA;varying vec2 texcoord;&#xA;varying vec3 pos;        &#xA;uniform mat4 mat[4];&#xA;&#xA;void main(void)&#xA;{&#xA;  normal = normalize((mat[3]*vec4(innormal,0.0)).xyz);&#xA;  color = incolor;&#xA;  texcoord = intexcoord0;&#xA;  gl_Position = mat[0]*mat[1]*vec4(inposition, 1.0);&#xA;//  gl_Position = vec4(inposition, 1.0);&#xA;  pos = gl_Position.xyz; &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here innormal is the vertex normal, and inposition are the coordinates of the vertices. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;And my frag shader is : &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform sampler2D texture0;&#xA;uniform vec3 lightpos;&#xA;uniform vec3 lightColor;&#xA;uniform vec3 objectColor;&#xA;varying vec3 normal;&#xA;varying vec4 color;&#xA;varying vec2 texcoord;&#xA;varying vec3 pos; &#xA;&#xA;void main (void){&#xA;//  gl_FragColor = max(texture2D(texture0, texcoord),color.xyzw);&#xA;//  gl_FragColor = texture2D(texture0, texcoord);&#xA;//  gl_FragColor = vec4(0.3, 0.8, 0.2, 1.0);&#xA;//  vec2 dfdx = abs(dFdx(texcoord));&#xA;//  vec2 dfdy = abs(dFdy(texcoord));&#xA;//  float d = max(max(dfdx.x,dfdx.y),max(dfdy.x,dfdy.y));&#xA;//  gl_FragColor = vec4(d*20,0,0,1);&#xA;&#xA;vec3 light = lightpos- pos;&#xA;    //light = lightpos;&#xA;&#xA;vec3 norm = normalize(normal);&#xA;vec3 eye_vector = vec3(0.0);&#xA;vec3 viewDir = normalize(eye_vector - pos);&#xA;vec3 lightDir = normalize(light);&#xA;vec3 reflectDir = reflect(lightDir,norm);&#xA;float spec = pow(dot(viewDir,reflectDir), 100.0);&#xA;float specularStrength = 0.5;&#xA;vec3 lightColor = vec3(1.0);&#xA;vec3 spect = spec*specularStrength*lightColor; &#xA;&#xA;gl_FragColor = vec4((0.9*max(dot(normal, normalize(light)),0.0)+0.1)*color.xyz,1.0) + vec4(vec3(spect),1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The lightpos is the position of the light which is (0,0,10);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Somehow the result looks like this: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YwDWN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YwDWN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which doesn't look right. Could anyone give me some hints please? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Cnp5F.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Cnp5F.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the vertex data and &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PKtgA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PKtgA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ocB8L.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ocB8L.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is how mat&lt;a href=&quot;https://i.stack.imgur.com/ocB8L.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;4&lt;/a&gt; produced. And the following is the normal output by @PaulHK 's idea, and it is broken. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VtaWY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VtaWY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10105" LastEditorUserId="10107" LastEditDate="2019-02-01T09:52:08.363" LastActivityDate="2019-02-01T09:52:08.363" Title="Specular/Diffuse light on an icosahedron opengl" Tags="&lt;opengl&gt;&lt;lighting&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8542" PostTypeId="2" ParentId="8532" CreationDate="2019-02-01T09:42:44.870" Score="3" Body="&lt;p&gt;Unfortunately, the iridescence model is not made to be applied to a diffuse term. Pascal and I made it for microfacet models only (that is the specular term).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way to understand how to include it to a game engine might be to look at Unity's HDRP implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the Lit.hlsl to see how to incorporate the iridescence Fresnel into a specular + diffuse BRDF:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/master/com.unity.render-pipelines.high-definition/Runtime/Material/Lit/Lit.hlsl&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PreLightData GetPreLightData(float3 V, PositionInputs posInput, inout BSDFData bsdfData) {&#xA;&#xA;    [...]&#xA;&#xA;    if (bsdfData.iridescenceMask &amp;gt; 0.0)&#xA;    {&#xA;        bsdfData.fresnel0 = lerp(bsdfData.fresnel0, EvalIridescence(topIor, viewAngle, bsdfData.iridescenceThickness, bsdfData.fresnel0), bsdfData.iridescenceMask);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;See the implementation of the &lt;code&gt;EvalIridescence&lt;/code&gt; in BSDF.hlsl:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/30f1b16c8094ca133c165e56380ebb7ab9e7c0d9/com.unity.render-pipelines.core/ShaderLibrary/BSDF.hlsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Unity-Technologies/ScriptableRenderPipeline/blob/30f1b16c8094ca133c165e56380ebb7ab9e7c0d9/com.unity.render-pipelines.core/ShaderLibrary/BSDF.hlsl&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What they are doing is to blend the standard Fresnel term with the iridescence one based on a iridescence mask value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this is helpfull.&lt;/p&gt;&#xA;" OwnerUserId="10103" LastActivityDate="2019-02-01T09:42:44.870" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8544" PostTypeId="1" AcceptedAnswerId="8546" CreationDate="2019-02-01T19:29:16.050" Score="4" ViewCount="93" Body="&lt;p&gt;I am looking for a stable way to find a contrast/inverted/opposite color to a given one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Application of this is to find best possible color for foreground to give background.&lt;/p&gt;&#xA;" OwnerUserId="10110" LastEditorUserId="6" LastEditDate="2019-02-03T14:59:10.030" LastActivityDate="2019-02-07T04:16:37.750" Title="Getting contrast color to a given color in RGB or ARGB or HEX" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8545" PostTypeId="2" ParentId="8525" CreationDate="2019-02-02T15:41:57.170" Score="1" Body="&lt;p&gt;So after reading up some more research papers and the concepts of most people working in this field here and there, I've reached an answer I'm satisfied with. If someone disagrees or thinks there is a better or more correct way to think the problem do share your ideas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) First to answer my point 1. I've noticed that most di-electric surfaces' Index of refraction remains fairly constant over the visible spectrum. This means the Fresnel Reflectances remain constant and are quite low over the visible spectrum for normal incidence. For angles near 90 degrees, even rough di-electric surfaces start reflecting the incoming light specularly. You can see this data &lt;a href=&quot;https://refractiveindex.info/?shelf=main&amp;amp;book=Au&amp;amp;page=Johnson&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However in the case of metals the IOR or more specifically the Fresnel Reflectances take on the exact same value as the color (in case of gold and copper). From this I conclude that, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For metals where Fresnel Reflectances (FR) vary greatly over the visible spectrum, FR is linked and is just a consequence of the surface of metals absorbing photons of certain frequencies. This means for Gold, the electrons at the surface absorb the blue-end of the spectrum, the remaining golden colored light either gets reflected or refracted. Thus the Fresnel Reflectance is golden in color which we can also call the &quot;Specular Color&quot;. &#xA;Note that the absorption depends on whether there are electrons available. It's possible for some blue photons to refract or reflect if there aren't much electrons for absorbing to begin with. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In-case of di-electrics the FR don't change much over the visible spectrum. However we can see color. The possible explanation is that the color in case of di-electrics comes from within the surface. That is, there are no such electrons present at the &quot;interface&quot; that absorb certain frequencies. Else we would have seen different FR for different wavelengths. The electrons absorbing wavelengths of certain frequencies come from within the surface, like pigments lying inside a liquid. Hence for di-electrics FR is not really linked to the concept of electrons absorbing certain frequencies imo.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This makes sense to me as colored metals (gold, copper) tint the reflections with their color. However certain di-electrics don't such as a polished marble floor. The reason for that again is that in case of metals the cause of color i.e. absorption by electrons occurs directly on the surface. The reflected light thus has a different composition for R,G,B giving us the tint. However for di-electrics the cause of color lies beneath the surface. Hence the reflection is non-tinted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Thus simply stating for metals FR is the same as the albedo/color of the surface. For non-metals or di-electrics FR is different from the albedo/color and just defines the amount of specular reflection.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) The proper way would surely be to use a BRDF with both diffuse and specular components since diffuse surfaces reflect greatly at near-grazing angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) Still don't know about this. It might be baked in or not. What I do know is that the diffuse component should surely get lesser and specular component larger as angle increases to 90.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another interesting point to note is that the basic Fresnel Equations apply for transparent and Flat surfaces. For metals we have complex IOR making the equations a little more complex. Sebastian Lagarde did a comparison &lt;a href=&quot;https://seblagarde.wordpress.com/2013/04/29/memo-on-fresnel-equations/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. Fresnel equations don't apply to rough surfaces but for microfacet models where we assume each facet to be perfectly specular we can maybe. Either way they are a good way to approximate the behaviour for increasing reflection near 90 degrees.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-02-02T15:41:57.170" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8546" PostTypeId="2" ParentId="8544" CreationDate="2019-02-03T01:54:46.523" Score="4" Body="&lt;p&gt;I read this in a magazine article probably 25 years ago. I don't recall the full derivation, but they said to take each component (red, green, and blue) and invert the high bit of the color. In a C-like programming language, you could do:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; component = (~component &amp;amp; 0x80) | (component &amp;amp; 0x7F);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This can be simplified to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;component ^= 0x80;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;for  a single component or to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;component ^= 0x80808000;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;if you want to do 4 components at once (and don't affect the alpha).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This assumes your components are 8-bit values. This avoids the problems you get with the middle values if you simply invert them. In that case 127 becomes 128, and vice-versa. But with the above solution, 127 becomes 255 and 128 becomes 0.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2019-02-07T04:16:37.750" LastActivityDate="2019-02-07T04:16:37.750" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8547" PostTypeId="1" AcceptedAnswerId="8554" CreationDate="2019-02-03T11:28:48.040" Score="2" ViewCount="101" Body="&lt;p&gt;Now I know this isn't the way this is normally done so please bear with me. I am doing this this way so I know I have a solid conceptual understanding of everything that goes beyond example code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to create a simple 2D game with sprites that and rotate, move, scale etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thus constructed the following matrices &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Transform&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want the sprites center to move from the origin by (&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;) units&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$T = \begin{bmatrix} &#xA;1 &amp;amp; 0 &amp;amp; x \\&#xA;0 &amp;amp; 1 &amp;amp; y \\&#xA;0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Rotation&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want the matrix to rotate by &lt;code&gt;d&lt;/code&gt; radians so I create the following variables where &lt;code&gt;s = sin(d)&lt;/code&gt; and &lt;code&gt;c = cos(d)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$R = \begin{bmatrix} &#xA;c &amp;amp; -s &amp;amp; 0 \\&#xA;s &amp;amp; c &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Scale&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want the rectangular sprite to occupy a horizontal units and b vertical units so I generated the following matrix&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$S= \begin{bmatrix} &#xA;a &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; b &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix} $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Center&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And finally I want the sprite to do all of these transformations with its center of movement being at (&lt;code&gt;u&lt;/code&gt;, &lt;code&gt;v&lt;/code&gt;) therefore I will plan to have to use a matrix sort of like this (you'll see why later) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$A = \begin{bmatrix} &#xA;1 &amp;amp; 0 &amp;amp; -u \\&#xA;0 &amp;amp; 1 &amp;amp; -v \\&#xA;0 &amp;amp; 0 &amp;amp; 1&#xA;\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the plan is to stream in the points (0, 0) (0, 1) (1, 1) and (1, 0) into my vertex shader and then use &lt;strong&gt;a single&lt;/strong&gt; matrix to translate the points to where they need to go.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I assumed that I could combine all these matrices as follows based on code examples etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$A * S * R * T$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I pulled these matrixes into Symbolab and got the following result&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KN4Jz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KN4Jz.png&quot; alt=&quot;Picture of symbolab result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Great! So time to pass it in. Now Metal uses SIMD but I need my engine to be completely cross platform so instead I read the SIMD alignment guides and tried to match them with this struct: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct float3x3 {&#xA;    float columns[3][4];&#xA;&#xA;    float3x3() {&#xA;        for (int i = 0; i &amp;lt; 3; i++) {&#xA;            for (int j = 0; j &amp;lt; 4; j++) {&#xA;                rows[i][j] = 0;&#xA;            }&#xA;        }&#xA;    }&#xA;} __attribute__ ((aligned(16))) ;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which means inside of my CPU code I can create the matrix like this (based on the symbolab result)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3x3 matrix;&#xA;matrix.columns[0][0] = a * c;&#xA;matrix.columns[1][0] = -a * s;&#xA;matrix.columns[2][0] = a * c * x - a * s * y + u;&#xA;matrix.columns[0][1] = s * b;&#xA;matrix.columns[1][1] = b * c;&#xA;matrix.columns[2][1] = b * s * x + b * c * y + v;&#xA;matrix.columns[2][2] = 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And pass it in like this &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[encoder setVertexBytes:&amp;amp;matrix length:sizeof(simd_float3x3) atIndex:2];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then finally I can pass it into my vertex shader which looks like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vertex ColorInOut tex_plain_vert(uint vid [[vertex_id]],&#xA;                                 constant matrix_float3x3* worldMatrix [[buffer(3)]],&#xA;                                 constant matrix_float3x3* localMatrix [[buffer(2)]]) {&#xA;    float2 coords[] = {float2(0, 0),&#xA;        float2(1.0, 0),&#xA;        float2(0, 1.0),&#xA;        float2(1.0, 1.0)};&#xA;&#xA;    const float2 texc[] = {float2(0.0, 1.0),&#xA;        float2(1.0, 1.0),&#xA;        float2(0.0, 0.0),&#xA;        float2(1.0, 0.0)};&#xA;&#xA;    const int lu[] = {0, 1, 2, 2, 1, 3};&#xA;&#xA;    ColorInOut out;&#xA;    out.texCoord = texc[lu[vid]];&#xA;    float3 padded = float3(coords[lu[vid]], 1.0);&#xA;    matrix_float3x3 w = *worldMatrix;&#xA;    matrix_float3x3 l = *localMatrix;&#xA;    float3 res = w * l * padded;&#xA;    out.position = float4(res.x, res.y, 0.0 , 1.0);&#xA;    return out;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However this doesnt work. Depending on how I have messed with things the square is either wildly off screen or doesn't translate to the (&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;) at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And yes my world matrix is VERY thoroughly tested and you will see in a bit that it is wrong even without that value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I pulled it into the vertex debugger and got the following information with the following variables&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x = 0&#xA;y = 50&#xA;s = 0&#xA;c = 1&#xA;a = 120&#xA;b = 120&#xA;u = 0.5&#xA;v = 0.5&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LM4g5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LM4g5.png&quot; alt=&quot;Vertex debugger&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;p2 is where you can really see the error with those settings &lt;code&gt;0,0&lt;/code&gt; should have translated to &lt;code&gt;-60,-10&lt;/code&gt; and &lt;code&gt;1, 0&lt;/code&gt; should have translated to &lt;code&gt;60, -60&lt;/code&gt;. None of these huge numbers and it is my inclination to think that it is mostly the 3rd column of the matrix at fault.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My inclination based on seeing these results is that the matrix I am passing in is wrong. But I dont know another way to do that math.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have also tried tweaking things like switching rows and columns changing multiplication order to no avial. The closest I have gotten was something that rotated and scaled but did not move and one that moved but had sheering effects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a lot of places in this process that I could have gone wrong (initial matrices, matrix multiplication\order, matrix struct, vertex shader, etc) and I would really appreciate your help finding it as I have spent awhile on this now.&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2019-02-05T09:45:52.040" Title="My 2D translation matrix causes the box to be off screen when it shouldnt be" Tags="&lt;transformations&gt;&lt;matrix&gt;&lt;2d&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8548" PostTypeId="1" CreationDate="2019-02-03T19:55:44.850" Score="2" ViewCount="727" Body="&lt;p&gt;I have created a 3D model of a local outdoor performance space and I have an app that uses Metal on MacOS 10.14.2 to display the model. I want to create an animation by flying the camera around the scene, while recording each frame (actually every other frame for 30 fps). I know how to do the animated fly-around and I know how to create a video frame-by-frame with AVFoundation. The step for which I can find no information is how I can capture each frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a completion handler so I know when the gpu has finished each command buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what is the best way to get the image in CPU space?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought perhaps I could do this by attaching a second texture to colorAttachments[1] but this has resulted in some odd behavior where the original scene that used to fill my MTKView window now occupies just the upper left quadrant of the window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I was trying to do is write the same color to both colorAttachments[0] (my screen) and to colorAttachments[1]. In my shader I defined:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct FragmentOut {&#xA;    float4 color0 [[ color(0) ]];&#xA;    float4 color1 [[ color(1) ]];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My fragment shader looks like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fragment FragmentOut grove_fragment_function(&#xA;    VertexOut vIn [[ stage_in ]],&#xA;    constant Uniforms &amp;amp;uniforms [[buffer(1)]]) {&#xA; ....&#xA;    float4 color = diffuseColor + ambientColor + specularColor;&#xA;    out.color0 = color;&#xA;    out.color1 = color;&#xA;    return out;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My hope was that I could then use something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;offScreenTextureBuffer?.getBytes(buffer, bytesPerRow: 4 * w, from: MTLRegionMake2D(0, 0, w, h), mipmapLevel: 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;to transfer the image data to a local buffer.&#xA;This doesn't seem to work, plus I have the unexpected display behavior noted above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am configuring the offScreenTextureBuffer thus:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let pixelFormat = MTLPixelFormat.bgra8Unorm_srgb&#xA;var offScreenBufferDescriptor =  MTLTextureDescriptor.texture2DDescriptor(pixelFormat: pixelFormat,                                                                             width: 1000,                                                                             height: 600,                                                                            mipmapped: false)&#xA;offScreenBufferDescriptor.usage = [.renderTarget, .shaderRead]&#xA;offScreenTextureBuffer = device.makeTexture(descriptor: offScreenBufferDescriptor)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I also tried to use the presentation layer from my MTKView. I can get the texture from the presentation layer but when I try to use the getBytes() func on the returned texture I get an error because the buffer is configured as &quot;framebufferonly&quot;. A presentation layer that can't be read doesn't seem particularly useful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any suggestions on how to capture each frame would be appreciated.&lt;/p&gt;&#xA;" OwnerUserId="10117" LastActivityDate="2019-03-09T00:52:19.703" Title="How to capture frames in a MacOS MTKView for recording to a video" Tags="&lt;metal&gt;&lt;frame-buffer&gt;&lt;capture&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8549" PostTypeId="1" AcceptedAnswerId="8550" CreationDate="2019-02-04T03:26:21.547" Score="3" ViewCount="225" Body="&lt;p&gt;I found this picture &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://mir-s3-cdn-cf.behance.net/project_modules/disp/9a556e13045459.5603449940365.jpg&quot; alt=&quot;picture&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you zoom in to any part of the image, the background looks a bit noisy/grainy. See pixels around &quot;violent violet&quot; label:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/0zhlvkB.png&quot; alt=&quot;grains&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to understand how to achieve the same effect programmatically?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was trying to change pixel color in rgb space by adding tiny gaussian offset, but it still doesn't look nearly as natural as in the image above:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/IXDUKN0.png&quot; alt=&quot;failed attempts&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I feel like I'm missing something very simple, but I don't even know where to start? How is this done in general?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe you can play with this jsbin to show me how this is done: &lt;a href=&quot;https://jsbin.com/fatecojolo/edit?js,output&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://jsbin.com/fatecojolo/edit?js,output&lt;/a&gt; ?&lt;/p&gt;&#xA;" OwnerUserId="7512" LastActivityDate="2019-02-04T13:09:09.137" Title="Adding noise to gradient" Tags="&lt;rendering&gt;&lt;image-processing&gt;&lt;post-processing&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8550" PostTypeId="2" ParentId="8549" CreationDate="2019-02-04T13:09:09.137" Score="4" Body="&lt;p&gt;It's generally a good idea to add noise like this when you're using a gradient, to avoid visible banding in the gradient, especially on smartphones. Often smartphone screens claim to be 24-bit colour but the panel itself is actually only 16 or 20 bit.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The chief difference between the example and your attempt to reproduce it is that your noise is in RGB space, while the example only adds luminance noise (i.e. brightness). You could achieve this by using HSV colours and only adding to the V channel, or with RGB colours and adding the same amount to each channel.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-02-04T13:09:09.137" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8551" PostTypeId="1" AcceptedAnswerId="8553" CreationDate="2019-02-04T15:39:35.177" Score="2" ViewCount="60" Body="&lt;p&gt;I have been working on a 3D engine and I am now implementing animations, but I can't find out whether or not to use the FPS of the engine or a fixed time method for the transformation's speed. Could someone please tell me the standard for animation timing. Thanks in advanced.&lt;/p&gt;&#xA;" OwnerUserId="10120" LastEditorUserId="2654" LastEditDate="2019-02-04T20:45:18.047" LastActivityDate="2019-02-05T07:41:46.873" Title="Should animations be locked to FPS or Fixed time" Tags="&lt;animation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8553" PostTypeId="2" ParentId="8551" CreationDate="2019-02-05T07:41:46.873" Score="2" Body="&lt;p&gt;You should use a fixed time for this. Consider the following: Your computer is super fast, you have high end hardware. Now you animate via FPS and make your animation look great. Let's say you had 120 fps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you did great work, you want to show me. I have bad hardware, everything takes ages. I have to work with just 30 fps - sufficient to call it real-time, but not too nice. It will take four times to completely play your animation on my computer, because you made it follow the fps. Therefore it doesn't convince me at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is even more problematic, if you do this in a multiplayer scenario. You could already start a new action after the animation, whereas I have to wait for the animation to finish. Therefore, there is an inconsistency in game state as well as an unfair game, because you can do things much faster.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2019-02-05T07:41:46.873" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8554" PostTypeId="2" ParentId="8547" CreationDate="2019-02-05T08:43:51.127" Score="1" Body="&lt;p&gt;The mistake was in the multiplication order during the composition of the matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the OP was working with column vectors the correct order for transformations should have been &lt;span class=&quot;math-container&quot;&gt;$TRSA∗v$&lt;/span&gt;. The OP did the other way around, &lt;span class=&quot;math-container&quot;&gt;$ASRT*v$&lt;/span&gt; thus the incorrect results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also there need to be another &lt;span class=&quot;math-container&quot;&gt;$A^{\prime}$&lt;/span&gt; matrix added which negates the  translation done by  &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt;. The first &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; matrix should have &lt;span class=&quot;math-container&quot;&gt;$-u, -v$&lt;/span&gt; to translate &lt;span class=&quot;math-container&quot;&gt;$u,v$&lt;/span&gt; to origin. The &lt;span class=&quot;math-container&quot;&gt;$A^{\prime}$&lt;/span&gt; matrix should have &lt;span class=&quot;math-container&quot;&gt;$u, v$&lt;/span&gt; to translate back.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence the correct composition should be, &lt;span class=&quot;math-container&quot;&gt;$TA^{\prime}RSA*v$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$A^{\prime}TRSA*v$&lt;/span&gt; depending on whether the translation is intended around &lt;span class=&quot;math-container&quot;&gt;$u,v$&lt;/span&gt; or the origin.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-02-05T09:45:52.040" LastActivityDate="2019-02-05T09:45:52.040" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8555" PostTypeId="1" AcceptedAnswerId="8987" CreationDate="2019-02-05T15:02:19.313" Score="7" ViewCount="1485" Body="&lt;h2&gt;Introduction&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I am implementing anisotropic GGX BRDF and have encountered strange behaviour of my implementation. I thought that if I compare the microfacet distribution function I have with the one of an isotropic GGX, then they should be equal when the anisotropy parameter is 0. I haven't been able to do that, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the GGX formula I have used:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3MkPf.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3MkPf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the anisotropic GGX formula I have used:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/evdjG.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/evdjG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anisotropy is 0, then &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Calpha_x&quot; alt=&quot;\alpha_x&quot;&gt; is equal to &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Calpha_y&quot; alt=&quot;\alpha_y&quot;&gt;, therefore I can get the following from the second formula:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TeG4e.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TeG4e.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Problem 1&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The problem now is that the third formula can never match the first one because of the negative 1 in the first one.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Problem 2&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The specific issue I have when rendering using my anisotropic GGX is that the normals seem to be ignored in the result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a visualization of the distribution function of isotropic GGX on a flat material patch with normal mapping:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Z5oHJ.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z5oHJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is the anisotropic one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uxw6j.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uxw6j.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Notation&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;To complete the explanation of my solution, I use &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=H&quot; alt=&quot;H&quot;&gt; for the half-vector, &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=N&quot; alt=&quot;N&quot;&gt; for the normal, &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Calpha&quot; alt=&quot;\alpha&quot;&gt; for roughness, &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=X&quot; alt=&quot;X&quot;&gt; for the tangent and &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=Y&quot; alt=&quot;Y&quot;&gt; for the bi-tangent (in my case these are simply aligned with the x and y axes respectively). &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Calpha_x&quot; alt=&quot;\alpha_x&quot;&gt; and &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Calpha_y&quot; alt=&quot;\alpha_y&quot;&gt; represent roughness in the corresponding directions.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Questions&lt;/h2&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is there a mistake in my reasoning? Is my anisotropic GGX correct?&lt;/li&gt;&#xA;&lt;li&gt;What is the relationship between the two? Is there a simple explanation for the extension from GGX to anisotropic GGX?&lt;/li&gt;&#xA;&lt;li&gt;Do you have any general tips for verifying the correctness of one's BRDF implementation?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h2&gt;References&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Here are my main references:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/Kink3d/AnisotropicStandardShader/blob/master/AnisotropicStandardShader/CGIncludes/UnityAnisotropicBRDF.cginc&quot; rel=&quot;noreferrer&quot;&gt;Anisotropic GGX implementation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&quot; rel=&quot;noreferrer&quot;&gt;BRDF formulas&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="10125" LastActivityDate="2019-07-09T09:05:12.937" Title="Anisotropic GGX BRDF implementation. How is it related to isotropic GGX BRDF?" Tags="&lt;rendering&gt;&lt;brdf&gt;&lt;ggx&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8556" PostTypeId="1" AcceptedAnswerId="8557" CreationDate="2019-02-05T20:51:52.390" Score="0" ViewCount="252" Body="&lt;p&gt;I'm trying to implement Skybox in DirectX 11 (DirectXTK) but when I'm rendering skybox, then texture is rendered to my sphere model instead of showing skybox outside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Rendering code:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;m_Camera-&amp;gt;Render();&#xA;&#xA;m_Camera-&amp;gt;GetViewMatrix(viewMatrix);&#xA;m_D3D-&amp;gt;GetWorldMatrix(worldMatrix);&#xA;m_D3D-&amp;gt;GetProjectionMatrix(projectionMatrix);&#xA;&#xA;m_D3D-&amp;gt;ChangeRasterizerCulling(D3D11_CULL_NONE);&#xA;m_D3D-&amp;gt;ChangeDepthStencilComparison(D3D11_COMPARISON_LESS_EQUAL);&#xA;&#xA;m_Model-&amp;gt;Render(m_D3D-&amp;gt;GetDeviceContext());&#xA;m_skyboxShader-&amp;gt;Render(m_D3D-&amp;gt;GetDeviceContext(), m_Model-&amp;gt;GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix);&#xA;&#xA;m_D3D-&amp;gt;ChangeRasterizerCulling(D3D11_CULL_BACK);&#xA;m_D3D-&amp;gt;ChangeDepthStencilComparison(D3D11_COMPARISON_LESS);&#xA;m_D3D-&amp;gt;EndScene();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Skybox.vs&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;cbuffer MatrixBuffer&#xA;{&#xA;    matrix worldMatrix;&#xA;    matrix viewMatrix;&#xA;    matrix projectionMatrix;&#xA;};&#xA;&#xA;struct VertexInputType&#xA;{&#xA;    float4 position : POSITION;    &#xA;};&#xA;&#xA;struct PixelInputType&#xA;{&#xA;    float4 positionSV : SV_POSITION;&#xA;    float4 position : POSITION;&#xA;};&#xA;&#xA;PixelInputType ColorVertexShader(VertexInputType input)&#xA;{&#xA;    PixelInputType output;&#xA;&#xA;    input.position.w = 1.0f;&#xA;    output.position = input.position;&#xA;&#xA;    output.positionSV = mul(input.position, worldMatrix).xyww;&#xA;    output.positionSV = mul(output.positionSV, viewMatrix).xyww;&#xA;    output.positionSV = mul(output.positionSV, projectionMatrix).xyww;&#xA;&#xA;    return output;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Skybox.ps&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;TextureCube shaderTexture;&#xA;SamplerState SampleType;&#xA;&#xA;struct PixelInputType&#xA;{&#xA;    float4 positionSV : SV_POSITION;&#xA;    float4 position : POSITION;&#xA;};&#xA;&#xA;float4 ColorPixelShader(PixelInputType input) : SV_TARGET&#xA;{&#xA;    return shaderTexture.Sample(SampleType, input.position.xyz);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wX7Hn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wX7Hn.png&quot; alt=&quot;DirectX Skybox error&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2019-02-06T19:27:55.200" Title="Skybox is rendered on the model instead of surroundings" Tags="&lt;directx&gt;&lt;direct3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8557" PostTypeId="2" ParentId="8556" CreationDate="2019-02-06T19:27:55.200" Score="0" Body="&lt;p&gt;A skybox is a (large) cube that encompasses the entire scene and contains 6 images of a surrounding environment, giving the player the illusion that the environment he's in is actually much larger than it actually is. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to do this, you need to draw a Cube (or a Sphere) in your Scene that will represent the Skybox. You then need to sample the Skybox Texture (shaderTexture in your shader) to project it into the geometry.&#xA;This is exactly what you are doing with your Sphere Model in your Pixel Shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem you have, is that your Model is too small and your Camera is outside of the Skybox. You need to make the Skybox way bigger, and place your camera inside of it.&#xA;The best solution is to center the Sky Sphere about the camera in world space, this way when you move the camera around, the Sky follows the camera, giving the illusion that it's infinitely far away and you can't get closer.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PixelInputType ColorVertexShader(VertexInputType input)&#xA;{&#xA;PixelInputType output;&#xA;&#xA;// Use local vertex position as cubemap lookup vector.&#xA;output.position = input.position;&#xA;&#xA;// Transform to world space.&#xA;float4 positionWorld = mul(float4(input.position, 1.0f), worldMatrix);&#xA;&#xA;// Always center sky about camera (You need to pass the camera position).&#xA;positionWorld.xyz += eyePositionWorld;&#xA;&#xA;// Set z = w so that z/w = 1 (i.e., skydome always on far plane).&#xA;output.positionSV = mul(posW, viewProjectionMatrix).xyww;&#xA;&#xA;return output;&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To keep the Skybox fragments always on the far plane (z component = 1.0) you can set the z component to w. This will turn into 1 after the perspective division is applied.&#xA;With this little hack you can render the SkySphere after having rendered all your meshes, and they would all be rendered on top of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may also want to do the matrix multiplication on the CPU and pass it in as another parameter for performance reasons.&lt;/p&gt;&#xA;" OwnerUserId="10086" LastActivityDate="2019-02-06T19:27:55.200" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8559" PostTypeId="1" AcceptedAnswerId="8560" CreationDate="2019-02-06T21:06:19.027" Score="2" ViewCount="338" Body="&lt;p&gt;On the picture below you can see mathematically perfect smooth transition from black to white. But I noticed that on all gradient picture I see strange strips and the color transition doesn't feel smooth. I even see that if you pass from black to white, there are some small jumps back to a bit darker color, when theoretically the color should become always whiter and whiter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can somebody explaing me this phenomena?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Jcf3t.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Jcf3t.png&quot; alt=&quot;Gradient from black to white&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10136" LastActivityDate="2019-02-07T16:42:15.693" Title="Strange stripes on the gradient" Tags="&lt;color-science&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8560" PostTypeId="2" ParentId="8559" CreationDate="2019-02-07T02:44:40.150" Score="4" Body="&lt;p&gt;The 'jumps' to 'a bit darker' are an optical illusion due to how human perception works. Check out Mach bands in wikipedia. Now as for why you get a step function even though you have a smooth transition in code: this is due to quantization. Your monitor can reproduce a finite amount of grey levels, so you quantize your otherwise continuous range.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-02-07T13:17:32.860" LastActivityDate="2019-02-07T13:17:32.860" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8561" PostTypeId="2" ParentId="8559" CreationDate="2019-02-07T09:02:40.953" Score="0" Body="&lt;p&gt;The image's histogram isn't entirely flat which could imply that some grey levels are represented more than others, I'm not sure this would cause the effects you see - I expect not. Try printing the image as a hight quality photo on glossy paper, this should eliminate the shortcomings of your screen.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2019-02-07T09:02:40.953" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8562" PostTypeId="1" AcceptedAnswerId="8827" CreationDate="2019-02-07T11:05:59.613" Score="1" ViewCount="1740" Body="&lt;p&gt;This is not homework. I'm self studying Computer Graphics, using the book &quot;3D Math Primer for Graphics and Game Development&quot; (2nd edition). So there is the exercise 6 in chapter 3 which I can't figure out how to solve exactly. It goes like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Assume that the robot is at the position (1, 10, 3), and her right, up, and forward vectors expressed in upright space are [0.866, 0, −0.500], [0, 1, 0], and [0.500, 0, 0.866], respectively. (Note that these vectors form an orthonormal basis.) The following points are expressed in object space. Calculate the coordinates for these points in upright and world space.&#xA;(a) (−1, 2, 0) (b) (1, 2, 0)&#xA;...&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I know that in order to convert from Object space to world space I have to first convert into inertial/upright space by performing a rotation and then into world space by performing a translation. So I assume that that the point (1,10,3) is expressed in world space coordinates. What I don't understand is which one is the matrix I have to use to do the rotation on point (-1,2,0)? I understand conceptually what is going on but I don't know which operations to do here. Help is greatly needed and will be appreciated. Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="5496" LastActivityDate="2019-05-07T10:45:00.733" Title="How to convert from Object space into World space (exercise from 3D Math Primer book)" Tags="&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8563" PostTypeId="1" AcceptedAnswerId="8564" CreationDate="2019-02-07T11:56:12.463" Score="0" ViewCount="124" Body="&lt;p&gt;Suppose we have a world coordinate system &lt;code&gt;W&lt;/code&gt; and a 3D model &lt;code&gt;m1&lt;/code&gt; defined in &lt;code&gt;W&lt;/code&gt;. &lt;code&gt;m1&lt;/code&gt; has its own local coordinate system &lt;code&gt;L&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;How would we define &lt;code&gt;L&lt;/code&gt;? Only by the transform from &lt;code&gt;W&lt;/code&gt; to the object?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;If we add a 3D model &lt;code&gt;m2&lt;/code&gt; to &lt;code&gt;W&lt;/code&gt; : How do we define its position and orientation in &lt;code&gt;L&lt;/code&gt; without worrying about the world coordinate system. Like just saying for instance that it's in (0,0,0) in &lt;code&gt;L&lt;/code&gt;? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS : If it's possible using algebraic or 3D geometry matrices transformation equations ? &lt;/p&gt;&#xA;" OwnerUserId="9739" LastActivityDate="2019-02-07T13:15:14.813" Title="Define position and orientation in a local coordinate system" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8564" PostTypeId="2" ParentId="8563" CreationDate="2019-02-07T13:15:14.813" Score="1" Body="&lt;p&gt;Assuming that your 'models' can be represented by collections of points, then these points' coordinates are defined with respect to some coordinate system. You said that &lt;span class=&quot;math-container&quot;&gt;$m_1$&lt;/span&gt; is defined wrt the coordinate system &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt;. And you have some other coordinate system &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; and want to find the positions of the points of &lt;span class=&quot;math-container&quot;&gt;$m_1$&lt;/span&gt; in it. To do this you need to multiply each of your points with the matrix used to go from &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;. To build this matrix you need to know the coordinates of the basis vectors of &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt; wrt &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;. Then you can make a 3x3 matrix where each column is a basis vector with which you can go from &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;. Note that a translation will also be necessary if the origins do not agree.&#xA;The solution for &lt;span class=&quot;math-container&quot;&gt;$m_2$&lt;/span&gt; is similar.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-02-07T13:15:14.813" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8565" PostTypeId="2" ParentId="8559" CreationDate="2019-02-07T16:42:15.693" Score="4" Body="&lt;p&gt;The non smooth appearance, or visual stripes you see, is called &lt;strong&gt;color banding&lt;/strong&gt;. (&lt;a href=&quot;https://en.wikipedia.org/wiki/Colour_banding&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;) It is produced since the medium, in this case your screen, is only capable of producing a finite array of colors and as the mathematical equation progressively passes through the color change you monitor &quot;jumps&quot; a visual amount of &quot;steps&quot;. Higher resolution monitors will suffer from banding less but still still have noticeable steps in high contrast gradients, such as from black to white.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &quot;jumps&quot; back to a darker color is, as &lt;strong&gt;lightxbulb&lt;/strong&gt; mentioned, an optical illusion called Mach bands. (&lt;a href=&quot;https://en.wikipedia.org/wiki/Mach_bands&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Printing a gradient will often have the same issue, no matter how high the resolution is. I have often had clients provide artwork for high quality printing and have been very disappointed with banding effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Banding is not only present in gradients but most noticeable in high contract change gradients and low resolution mediums.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are techniques to help with banding like dithering or adding noise. But these techniques will often require moving to pixel based artwork and not mathematical perfect vector.  Here is a great article to understand banding and how to avoid it using Photoshop. &lt;a href=&quot;https://www.slrlounge.com/remove-banding-photoshop/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.slrlounge.com/remove-banding-photoshop/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10142" LastActivityDate="2019-02-07T16:42:15.693" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8566" PostTypeId="2" ParentId="8529" CreationDate="2019-02-07T21:12:32.830" Score="2" Body="&lt;p&gt;You should be able to use &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture3d&quot; rel=&quot;nofollow noreferrer&quot;&gt;RWTexture3D&lt;/a&gt;.&lt;br&gt;&#xA;The &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-object-rwtexture2d&quot; rel=&quot;nofollow noreferrer&quot;&gt;hlsl documentation page about RWTexture2D&lt;/a&gt; also has sample code that you might find useful. &lt;/p&gt;&#xA;" OwnerUserId="110" LastEditorUserId="110" LastEditDate="2019-02-08T10:09:10.523" LastActivityDate="2019-02-08T10:09:10.523" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8567" PostTypeId="2" ParentId="8562" CreationDate="2019-02-08T21:31:23.550" Score="1" Body="&lt;p&gt;Let me try to translate the problem statement in a mathematical way so that it can be understood more easily.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Assume that the robot is at the position (1, 10, 3)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Assume there are a set of basis &lt;span class=&quot;math-container&quot;&gt;$\mathbf{e}_i$&lt;/span&gt; and origin &lt;span class=&quot;math-container&quot;&gt;$\mathbf{O}$&lt;/span&gt;, then the robot position &lt;span class=&quot;math-container&quot;&gt;$\mathbf{P}$&lt;/span&gt; expressed in this basis is the origin plus a linear combination of the basis and the coefficients &lt;span class=&quot;math-container&quot;&gt;$\mathbf{p}=(1,10,3)$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\mathbf{P}=p_i \mathbf{e}_i + \mathbf{O}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;and her right, up, and forward vectors expressed in upright space are [0.866, 0, −0.500], [0, 1, 0], and [0.500, 0, 0.866], respectively.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Now we have another set of basis denoted as &lt;span class=&quot;math-container&quot;&gt;$\mathbf{e}'_i$&lt;/span&gt; attached at &lt;span class=&quot;math-container&quot;&gt;$\mathbf{P}$&lt;/span&gt;, and the relation between these two basis &lt;span class=&quot;math-container&quot;&gt;$\mathbf{e}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\mathbf{e}'$&lt;/span&gt; are also expressed as linear combinations. That is, denote &lt;span class=&quot;math-container&quot;&gt;$\mathbf{m}_0=(0.866,0,-0.5)$&lt;/span&gt;,&lt;span class=&quot;math-container&quot;&gt;$\mathbf{m}_1=(0,1,0)$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\mathbf{m}_2=(0.5,0,0.866)$&lt;/span&gt;, then&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\mathbf{e}'_i=m_{ij} \mathbf{e}_j&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Calculate the coordinates for these points in upright and world space. (a) (−1, 2, 0) (b) (1, 2, 0) ...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The given coordinates are in object space and the problem asks us to compute their representations in frames &lt;span class=&quot;math-container&quot;&gt;$\{\mathbf{e}_i,\mathbf{P}\}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\{\mathbf{e}_i,\mathbf{O}\}$&lt;/span&gt; respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Take &lt;span class=&quot;math-container&quot;&gt;$\mathbf{x}=(-1,2,0)$&lt;/span&gt; as an example, we want to find the coordinates &lt;span class=&quot;math-container&quot;&gt;$\mathbf{l}$&lt;/span&gt; in upright space:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;x_i \mathbf{e}'_i + \mathbf{P} &amp;amp;= l_i \mathbf{e}_i + \mathbf{P}\\&#xA;x_j m_{ji} \mathbf{e}_i &amp;amp;= l_i \mathbf{e}_i&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;Written in matrix form: &lt;span class=&quot;math-container&quot;&gt;$\mathbf{M}^T \mathbf{x}=\mathbf{l}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next we find the coordinates &lt;span class=&quot;math-container&quot;&gt;$\mathbf{w}$&lt;/span&gt; in world space:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;x_i \mathbf{e}'_i + \mathbf{P} &amp;amp;= w_i \mathbf{e}_i + \mathbf{O} \\&#xA;x_i \mathbf{e}'_i + p_i\mathbf{e}_i &amp;amp;= w_i \mathbf{e}_i \\&#xA;x_j m_{ji} \mathbf{e}_i + p_i\mathbf{e}_i &amp;amp;= w_i \mathbf{e}_i \\&#xA;x_j m_{ji} + p_i &amp;amp;= w_i&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;Written in vector form:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\mathbf{M}^T \mathbf{x} + \mathbf{p} = \mathbf{w}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your idea is generally correct. And the &quot;upright&quot; matrix can be constructed by considering the relation (&lt;span class=&quot;math-container&quot;&gt;$m_{ij}$&lt;/span&gt;) between the two basis, as shown above.&lt;/p&gt;&#xA;" OwnerUserId="120" LastEditorUserId="120" LastEditDate="2019-02-08T21:57:34.983" LastActivityDate="2019-02-08T21:57:34.983" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8568" PostTypeId="1" CreationDate="2019-02-09T07:18:12.563" Score="1" ViewCount="43" Body="&lt;p&gt;I recently noticed that in all games, no matter what system you play on or what specs you have, your character will always move at the same speed even if there is  no frame rate limit. I was wondering how this worked because if you were to add the same value to a variable, the animation would be faster on faster processors or graphics cards. I heard somewhere that you could use the time between frames to reduce the speed. I do not see how this would work. So how would you get a consistent speed across all systems?&lt;/p&gt;&#xA;" OwnerUserId="10149" LastActivityDate="2019-02-09T10:41:08.787" Title="Consistent animation speed across systems" Tags="&lt;real-time&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8569" PostTypeId="2" ParentId="8568" CreationDate="2019-02-09T10:41:08.787" Score="1" Body="&lt;p&gt;It works exactly the way you describe. Most 3D games work on &lt;em&gt;keyframe&lt;/em&gt; animations, where the human animator sets the important positions (for each joint or whatever is being animated) and the times they should be shown. The times are usually a number of &quot;frames&quot;, but these are just intervals of 1/60 s, regardless of what frame rate is actually achieved on the client machine. The computer &lt;em&gt;interpolates&lt;/em&gt; between those keyframe positions to decide what to draw at any given time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, let's say an animation has keyframes on frame 0, 6, and 12. These are the positions to show at the beginning of the animation, 6/60 s later (that's 0.1 s), and 6/60 s after that. The first frame is drawn with the pose from the first keyframe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say the game is running really slowly, and the next frame starts being assembled 0.05 s later (which would give a 20 fps frame rate). The animation system uses interpolation to make a pose that's halfway between the first and second keyframes, because the time is halfway between 0 and 0.1. Next, imagine things are speeding up a bit, and the next frame is drawn 0.04 s later. It's 0.09 s since the start of the animation, so the animation system makes a pose that's 90% from the first keyframe to the second keyframe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this frame rate continues, the next frame will be generated at 0.13 s. This time the animation system has to interpolate between the second and third keyframes, taking 70% of the second and 30% of the third. Note that the second keyframe was never drawn in this example, but it contributed to the poses that were drawn, through interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now to finish off the example quickly, let's assume the computer really slows down so the next frame is another 0.07 s later, making 0.2 s since the start of the animation. This is exactly the time that the third keyframe was set for, so the animation system just uses that pose. Although the animation was designed to take 13 frames (including the one at the start), we've finished it in just 5 frames of jerkiness, but it still takes the same length of time, 0.2 s.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In summary, it doesn't matter what time each frame actually comes out on the end system, because we can make whatever pose we like via &lt;em&gt;interpolation&lt;/em&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-02-09T10:41:08.787" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8572" PostTypeId="1" AcceptedAnswerId="8573" CreationDate="2019-02-10T00:02:04.857" Score="3" ViewCount="1401" Body="&lt;p&gt;What is the oldest hardware or minimum requirements conceptually able to support a fully hardware-accelerated Vulkan implementation? I am not referring to what implementations are currently available or likely to be written, but what could possibly be written.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a specific set of features that must be provided by hardware in order for the manipulation primitives provided by Vulkan to be used?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can Vulkan drivers be written for every video card that supports OpenGL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, could one create a hardware Vulkan driver for the &lt;a href=&quot;https://en.wikipedia.org/wiki/Number_Nine_Visual_Technology#Number_Nine_Video_Cards_using_Number_Nine_GPUs&quot; rel=&quot;nofollow noreferrer&quot;&gt;Number Nine Imagine 128&lt;/a&gt;, with 4M VRAM?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I apologize for how naive my question must be, and thanks in advance for any reply.&lt;/p&gt;&#xA;" OwnerUserId="10051" LastActivityDate="2019-02-10T23:34:44.727" Title="What is the oldest hardware able to feasibly support Vulkan?" Tags="&lt;vulkan&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8573" PostTypeId="2" ParentId="8572" CreationDate="2019-02-10T08:28:19.003" Score="1" Body="&lt;p&gt;Khronos publishes a list of &lt;a href=&quot;https://www.khronos.org/conformance/adopters/conformant-products/vulkan&quot; rel=&quot;nofollow noreferrer&quot;&gt;Vulkan compliant hardware here&lt;/a&gt;. The list also shows compliance to different flavors of OpenGL. I don't know all the card models, but for NVIDIA at least the GeForce GT 630 is supposed to work with Vulkan.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To answer your question a bit more, to support Vulkan a video card must support a certain number of programmable shader stages. Shaders is probably the biggest evolution of graphic cards in the last 10 years in my opinion. This already eliminates the graphic card you mentioned in the question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This &lt;a href=&quot;https://www.khronos.org/assets/uploads/developers/library/overview/vulkan-overview.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;early Vulkan presentation from Khronos&lt;/a&gt;, states that &quot;Vulkan 1.0 provides access to OpenGL ES 3.1 / OpenGL 4.X-class GPU functionalitybut with increased performance and flexibility.&quot; That can give you a basis for finding which individual features a graphic cards must theoretically support to have a Vulkan driver. See the new features &lt;a href=&quot;https://en.wikipedia.org/wiki/OpenGL#OpenGL_4.0&quot; rel=&quot;nofollow noreferrer&quot;&gt;introduced in OpenGL 4 at Wikipedia&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Among them:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Tessellation shaders&lt;/li&gt;&#xA;&lt;li&gt;Indirect draw commands&lt;/li&gt;&#xA;&lt;li&gt;&lt;strike&gt;Transform feedback&lt;/strike&gt; (more flexibility in transform feedback)&lt;/li&gt;&#xA;&lt;li&gt;&lt;strike&gt;Texture buffer objects&lt;/strike&gt; (new texture formats only)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;See also the sections &quot;New Features&quot; of the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/index_gl.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL 4.x specs&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastEditorUserId="7644" LastEditDate="2019-02-10T23:34:44.727" LastActivityDate="2019-02-10T23:34:44.727" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8574" PostTypeId="1" AcceptedAnswerId="8577" CreationDate="2019-02-10T17:08:58.830" Score="0" ViewCount="32" Body="&lt;p&gt;For example, preparing a scene in Maya using standard lights and rendering out a panorama? &#xA;Could they also be made from scratch in photoshop using 32bit color? &#xA;Is there a reason why people don’t seem to do this more often?&#xA;Cheers&lt;/p&gt;&#xA;" OwnerUserId="6910" LastActivityDate="2019-02-11T05:57:02.433" Title="Can you generate your own HDRI maps without using photos?" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8575" PostTypeId="1" CreationDate="2019-02-10T21:29:48.247" Score="0" ViewCount="82" Body="&lt;p&gt;I try to solve this,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bWhcz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bWhcz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I used scaling: &lt;span class=&quot;math-container&quot;&gt;$Scale(S_x,S_y)=S(\sqrt 5,\sqrt 5)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I enlarge the bottom of the house and the sides, to the same size of B image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Later, I used rotation: &lt;span class=&quot;math-container&quot;&gt;$R(\theta)=R(cos^{-1}(2/\sqrt 5))$&lt;/span&gt;&#xA;the vertex that was &lt;span class=&quot;math-container&quot;&gt;$[\sqrt 5, 0, 1]$&lt;/span&gt; moved &lt;span class=&quot;math-container&quot;&gt;$[2, 1, 1]$&lt;/span&gt; I do that because I thought to translate it to &lt;span class=&quot;math-container&quot;&gt;$[5,3,1]$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I stuck with that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the idea of this question?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="10160" LastEditorUserId="10160" LastEditDate="2019-02-10T21:35:28.280" LastActivityDate="2019-02-12T15:08:34.640" Title="Using transformations to get from A to B image" Tags="&lt;transformations&gt;" AnswerCount="2" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8577" PostTypeId="2" ParentId="8574" CreationDate="2019-02-11T05:57:02.433" Score="1" Body="&lt;p&gt;Yes, it is possible to do this. If you use a tool like Photoshop in 32-bit per channel mode, any values less than 0 or greater than 1 should be usable as a high dynamic range values. I don't know that I agree with your contention that &quot;people don't seem to do this&quot;. Given that the tools exist, they must be supporting some workflow.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-02-11T05:57:02.433" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8578" PostTypeId="1" AcceptedAnswerId="8580" CreationDate="2019-02-11T08:11:58.460" Score="0" ViewCount="683" Body="&lt;p&gt;I'm trying to add BRDFs to a very basic path tracer. Starting out, I'd like to convert just the Lambertian material, with two different sampling methods, to ensure that everything is working right. Theoretically, a uniform sample and a cosine-weighted hemispherical sample should both render similar images with different amounts of noise.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I'm finding that the uniform sample yields a significantly darker image than the cosine-weighted sample. This makes sense as the uniform set will always be scaled by 1 whereas the weighted set will usually be scaled by more than one - but I don't know exactly how I should fix that. Maybe someone can enlighten me as to how these PDFs should work?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the relevant material code (edited based on the most recent):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;func (l *Lambert) Scatter(_, n geom.Unit, uv, p geom.Vec, rnd *rand.Rand) (in geom.Unit, bsdf Color, pdf float64) {&#xA;    in, pdf = sampleUniform(n, rnd) // should be able to swap this out, right?&#xA;    bsdf = l.texture.Map(uv, p).Scaled(in.Dot(n))&#xA;    return&#xA;}&#xA;&#xA;func sampleUniform(n geom.Unit, rnd *rand.Rand) (sample geom.Unit, pdf float64) {&#xA;    sample = n.RandInHemisphere(rnd)&#xA;    pdf = 0.5&#xA;    return&#xA;}&#xA;&#xA;func sampleCosWeighted(n geom.Unit, rnd *rand.Rand) (sample geom.Unit, pdf float64) {&#xA;    sample = n.RandInHemisphereCos(rnd)&#xA;    pdf = n.Dot(sample)&#xA;    return&#xA;}&#xA;&#xA;func sampleReflected(out, n geom.Unit, rnd *rand.Rand) (sample geom.Unit, pdf float64) {&#xA;    sample = reflect(out, n)&#xA;    pdf = 1&#xA;    return&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the relevant render loop code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;func color(r Ray, s Surface, depth int, rnd *rand.Rand) Color {&#xA;    if depth &amp;gt;= 50 {&#xA;        return black&#xA;    }&#xA;    hit := s.Hit(r, bias, math.MaxFloat64, rnd)&#xA;    if hit == nil {&#xA;        return black&#xA;    }&#xA;    out := r.Dir.Inv()&#xA;    emit := hit.Mat.Emit(hit.UV, hit.Pt)&#xA;    in, bsdf, pdf := hit.Mat.Scatter(out, hit.Norm, hit.UV, hit.Pt, rnd)&#xA;    if pdf &amp;lt;= 0 {&#xA;        return emit&#xA;    }&#xA;    indirect := color(NewRay(hit.Pt, in, r.T), s, depth+1, rnd).Times(bsdf).Scaled(1 / pdf)&#xA;    return emit.Plus(indirect)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5180" LastEditorUserId="5180" LastEditDate="2019-02-11T15:17:07.097" LastActivityDate="2019-02-11T18:26:34.420" Title="How to set equivalent PDFs for cosine-weighted and uniform-sampled hemispheres?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;physically-based&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8579" PostTypeId="2" ParentId="8578" CreationDate="2019-02-11T10:26:07.327" Score="1" Body="&lt;p&gt;You're simply not normalizing correctly, since you've picked the pdf for uniform to be &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; which it is not, and for cosine to be &lt;span class=&quot;math-container&quot;&gt;$\cos\theta$&lt;/span&gt; which it is not. The pdf for uniformly distributed points on the upper hemisphere is: &lt;span class=&quot;math-container&quot;&gt;$p_U(\theta, \phi) = \frac{\sin\theta}{2\pi}$&lt;/span&gt;. The pdf for cosine distributed points on the upper hemisphere is: &lt;span class=&quot;math-container&quot;&gt;$p_C(\theta, \phi) = \frac{\cos\theta\sin\theta}{\pi}$&lt;/span&gt;. The integrand of the rendering equation (formulated in terms of sampling the hemisphere and not the area formulation) is: &lt;span class=&quot;math-container&quot;&gt;$$brdf(\theta_i, \phi_i, x, \theta_o, \phi_o)L_i(x,\theta_i,\phi_i)\cos\theta_i\sin\theta_i$$&lt;/span&gt;&#xA;Since the estimator is the integrand divided by the pdf, then in the case of uniform sampling the sine cancels and you get:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$2\pi \cdot brdf(\theta_i, \phi_i, x, \theta_o, \phi_o)L_i(x,\theta_i,\phi_i)\cos\theta_i$$&lt;/span&gt;&#xA;In the case of cosine sampling the sine and cosine cancel and you get:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\pi \cdot brdf(\theta_i, \phi_i, x, \theta_o, \phi_o)L_i(x,\theta_i,\phi_i)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that for a Lambertian material you should use cosine sampling since it produces lower variance.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-02-11T10:33:03.303" LastActivityDate="2019-02-11T10:33:03.303" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8580" PostTypeId="2" ParentId="8578" CreationDate="2019-02-11T18:26:34.420" Score="2" Body="&lt;p&gt;So, for Uniform sampling the PDF is &lt;span class=&quot;math-container&quot;&gt;$1/2π$&lt;/span&gt;, For Cos-weighted its &lt;span class=&quot;math-container&quot;&gt;$cos(θ)/π$&lt;/span&gt;. The Lambertian BRDF has a &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt; term as well in the denominator for energy conservation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When not optimizing things you should be dividing by &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt; during the BRDF calculation, then dividing by the proper PDFs mentioned above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Considering all the factors into account, for uniform sampling you'd have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i*brdf*\cos(\theta) * \displaystyle{\frac{1}{pdf}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i * \frac{color}{\pi} * \cos(\theta) \displaystyle{\frac{1}{\frac{1}{2\pi}}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i * {color} * \cos(\theta) * 2$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly for Cosine-weighted hemispherical sampling you'd have&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i*brdf*\cos(\theta) * \displaystyle{\frac{1}{pdf}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i * \frac{color}{\pi} * \cos(\theta) \displaystyle{\frac{1}{\frac{\cos(\theta)}{pi}}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i * {color} $&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since you weren't dividing by &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt; in the BRDF, the division by the PDF should have been &lt;span class=&quot;math-container&quot;&gt;$1/2$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\cos(\theta)$&lt;/span&gt; as you suggested but couldn't understand since the actual pdfs have a factor of &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt; in them.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-02-11T18:26:34.420" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8581" PostTypeId="2" ParentId="8575" CreationDate="2019-02-12T08:59:03.130" Score="1" Body="&lt;p&gt;Just use linear algebra.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since parallel lines have remained parallel (i.e. meaning we can probably assume the &lt;em&gt;w&lt;/em&gt; component of homogeneous coordinates is always 1), we can just pick 3 starting points and their destinations, e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(0,0,1)-&amp;gt;(3,2,1),  (0,1,1)-&amp;gt;(1,3,1), and  (1,0,1)-&amp;gt;(5,3,1),&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;define M to be your (homogeneous) transformation matrix as &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ M =\begin{bmatrix}&#xA;a &amp;amp; b &amp;amp; c \\&#xA;d &amp;amp; e &amp;amp; f \\&#xA;0 &amp;amp; 0 &amp;amp; 1\\&#xA;\end{bmatrix}  $$&lt;/span&gt;&#xA;and then we have &#xA;&lt;span class=&quot;math-container&quot;&gt;$$ M.\begin{bmatrix}&#xA;0 &amp;amp; 0 &amp;amp; 1 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 \\&#xA;1 &amp;amp; 1 &amp;amp; 1\\&#xA;\end{bmatrix} = &#xA;\begin{bmatrix}&#xA;3 &amp;amp; 1 &amp;amp; 5 \\&#xA;2 &amp;amp; 3 &amp;amp; 3 \\&#xA;1 &amp;amp; 1 &amp;amp; 1\\&#xA;\end{bmatrix}&#xA; $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You just need to find the inverse of the 'starting point' matrix (&lt;em&gt;which is left as an exercise for the reader&lt;/em&gt; ) and rearrange to compute...&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ M= &#xA;\begin{bmatrix}&#xA;3 &amp;amp; 1 &amp;amp; 5 \\&#xA;2 &amp;amp; 3 &amp;amp; 3 \\&#xA;1 &amp;amp; 1 &amp;amp; 1\\&#xA;\end{bmatrix}&#xA;.\begin{bmatrix}&#xA;0 &amp;amp; 0 &amp;amp; 1 \\&#xA;0 &amp;amp; 1 &amp;amp; 0 \\&#xA;1 &amp;amp; 1 &amp;amp; 1\\&#xA;\end{bmatrix}^{-1}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be really thorough, you could also then check that all the remaining points are transformed correctly by your result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you don't want to work through the maths yourself, the resulting matrix is&lt;/p&gt;&#xA;&#xA;&lt;blockquote class=&quot;spoiler&quot;&gt;&#xA;  &lt;p&gt; &lt;span class=&quot;math-container&quot;&gt;$ M= \begin{bmatrix} 2 &amp;amp; -2 &amp;amp; 3 \\ 1 &amp;amp; 1 &amp;amp; 2 \\ 0 &amp;amp; 0 &amp;amp; 1\\ \end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-02-12T15:08:34.640" LastActivityDate="2019-02-12T15:08:34.640" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8582" PostTypeId="2" ParentId="8575" CreationDate="2019-02-12T11:44:33.470" Score="0" Body="&lt;p&gt;Since the only answer requires homogeneous coordinates, a &lt;span class=&quot;math-container&quot;&gt;$3\times3$&lt;/span&gt; matrix inversion, as well as a &lt;span class=&quot;math-container&quot;&gt;$3\times3$&lt;/span&gt; matrix multiplication, here's something simpler, not as tedious to compute, and also more geometrically intuitive (it also gives a better idea what a linear map can do, and what it cannot).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A linear &lt;span class=&quot;math-container&quot;&gt;$2\times2$&lt;/span&gt; transformation obviously cannot translate the origin, for this we will need a translation. We can find the translation from the difference between the lower left vertices of the house (since both should lie at the origin of their coordinate systems). We see that &lt;span class=&quot;math-container&quot;&gt;$(0,0)\rightarrow (3,2)$&lt;/span&gt;, then the translation is &lt;span class=&quot;math-container&quot;&gt;$(3,2)$&lt;/span&gt;. We can move the stretched and rotated house back to the origin: so that the lower left vertex coincides with &lt;span class=&quot;math-container&quot;&gt;$(0,0)$&lt;/span&gt; (the initial position of it) by translating with &lt;span class=&quot;math-container&quot;&gt;$-(3,2)$&lt;/span&gt;. We'll pick two 'nice' points (in the sense that they have &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; for one of their components and &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; for the other): &lt;span class=&quot;math-container&quot;&gt;$(1,0)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$(0,1)$&lt;/span&gt;. We can see from the image that &lt;span class=&quot;math-container&quot;&gt;$(1,0) \rightarrow (5,3) - (3,2) = (2,1)$&lt;/span&gt;  where the subtraction is necessary to move the transformed house back to the origin as already mentioned. Similarly: &lt;span class=&quot;math-container&quot;&gt;$(0,1) \rightarrow (1,3) - (3,2) = (-2,1)$&lt;/span&gt;. We want to find a matrix:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ M =\begin{bmatrix}&#xA;    a &amp;amp; b\\&#xA;    c &amp;amp; d\\&#xA;    \end{bmatrix}  $$&lt;/span&gt;&#xA;such that &lt;span class=&quot;math-container&quot;&gt;$M(1,0)^T = (2,1)^T$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$M(0,1)^T = (-2,1)^T$&lt;/span&gt;. But this is trivial, since we get &lt;span class=&quot;math-container&quot;&gt;$(a,c) = (2,1)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$(b,d) = (-2,1)$&lt;/span&gt;. Thus you have: &lt;span class=&quot;math-container&quot;&gt;$v'=Mv+(3,2)$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; is a point from the original house, and &lt;span class=&quot;math-container&quot;&gt;$v'$&lt;/span&gt; is the transformed such. Note that it is easy to see that this is simply scaling + rotation (45 degrees) + scaling:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ M =\begin{bmatrix} 2 &amp;amp; -2\\1 &amp;amp; 1\\ \end{bmatrix}   &#xA;= \begin{bmatrix} 2 &amp;amp; 0\\0 &amp;amp; 1\\ \end{bmatrix} \begin{bmatrix} 1 &amp;amp; -1\\1 &amp;amp; 1\\ \end{bmatrix} \\=  \begin{bmatrix} 2 &amp;amp; 0\\ 0 &amp;amp; 1\\ \end{bmatrix}&#xA;\begin{bmatrix} \frac{1}{\sqrt{2}} &amp;amp; -\frac{1}{\sqrt{2}}\\ \frac{1}{\sqrt{2}} &amp;amp; \frac{1}{\sqrt{2}}\\ \end{bmatrix}&#xA;\begin{bmatrix} \sqrt{2} &amp;amp; 0\\ 0 &amp;amp; \sqrt{2}\\ \end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The right scaling may be moved inside the left one (since the right is uniform scaling, hence commutative, or just a multiplication by the scalar &lt;span class=&quot;math-container&quot;&gt;$\sqrt{2}$&lt;/span&gt;, I just thought it's geometrically more intuitive this way).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-02-12T12:43:30.687" LastActivityDate="2019-02-12T12:43:30.687" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8584" PostTypeId="1" CreationDate="2019-02-12T18:38:14.657" Score="0" ViewCount="369" Body="&lt;p&gt;Given this graph in the 3d cartesian coordinates i should figure out the spherical coordinates representation but without the use of calculations .&#xA;I've been trying to solve this the whole day but i don't seem to get it and i've searched on all around the internet also no results .&#xA;I'll appreciate any help if anyone has an idea about the topic .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/o57c0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o57c0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NOTE: this is not a homework :)&lt;/p&gt;&#xA;" OwnerUserId="10168" LastActivityDate="2019-02-14T12:10:26.127" Title="transformation from cartesian coordinates to spherical coordinates without calculations" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;computational-geometry&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8585" PostTypeId="1" CreationDate="2019-02-12T20:43:40.670" Score="5" ViewCount="155" Body="&lt;p&gt;So I was just reading up on how to create more Physically Based Lights and wandered into the realm of photometry. I read the paper &quot;Moving FrostBite to PBR&quot; and in it the author claims he decided to have all the light sources in units of Photometry (Lumens/Luminance etc). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The author also writes how to convert between radiometric and photometric units earlier on. But later he decides to ditch this conversion and have his lights in photometric from the get go. I don't understand how is this compatible?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I want to use the same technique for my normal path tracer, is there a different form of the rendering equation for photometry? Should I just swap the radiometric parts for the photometric parts (radiance for luminance, radiant flux for lumens etc). Or maybe I should convert from photometric to radiometric like the paper mentioned. How does this all tie up, if anybody can clear it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- Just saw a &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1992/rendering-in-radiometric-units-or-photometric?rq=1&quot;&gt;similar&lt;/a&gt; question (sorry my net is slow). As nathan suggested in his answer rendering RGB images proceeds more naturally in radiometric units. If I opt the approach to convert between radiometric and photometric units using luminous efficacy for light sources will there still be a problem as Nathan suggested (wavelength dependance of photometric units) or that problem exists solely when rendering exclusively in Photometric units?&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-02-17T20:04:04.407" LastActivityDate="2019-02-17T20:04:04.407" Title="How to use Photometric Units with Rendering Equation?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;photometric&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8587" PostTypeId="1" CreationDate="2019-02-13T13:08:13.883" Score="0" ViewCount="245" Body="&lt;p&gt;I am looking for an algorithm that is able to cover with non-overlapping rectangles in a pre-defined number and minimum area a generic 2d-polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Polygons are usually free-hand draws, so they can be of really any shape and number of vertexes and having holes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found different articles like: &lt;a href=&quot;https://en.wikipedia.org/wiki/Polygon_covering&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Polygon_covering&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but I am not sure if it is what I am looking for. Can you point me to some source code or something readable for a non-graphic guy?&lt;/p&gt;&#xA;" OwnerUserId="9125" LastEditorUserId="209" LastEditDate="2019-03-22T09:01:00.870" LastActivityDate="2020-10-23T20:33:05.220" Title="An algorithms for covering a 2d polygon with a predetermined number of rectangles?" Tags="&lt;algorithm&gt;&lt;polygon&gt;" AnswerCount="3" CommentCount="9" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8588" PostTypeId="2" ParentId="8584" CreationDate="2019-02-13T14:52:39.603" Score="1" Body="&lt;p&gt;If we take some ring around the sphere such that &lt;span class=&quot;math-container&quot;&gt;$\theta=const$&lt;/span&gt;, we can see that such a ring transforms into a line on the polar space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Converting every possible ring to the polar space gives the desired surface. However this would involve computing many different values to get an approximation or doing some algebra, which we don't want. (I'm assuming you want to keep mathematical notation to a minimum here). However we can get a pretty close idea by figuring out just a few easy to compute values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now. If we grab the ring that goes around the center of the sphere and transform that one, it is clear that it ends up as a line with &lt;span class=&quot;math-container&quot;&gt;$\theta=45^o$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$r=\sqrt{2}R$&lt;/span&gt; (that is because its vertical distance from the origin equals its horizontal distance at every point).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two more rings that are useful to us here: the two very small rings around the poles of the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ring around the bottom pole transforms into a line with &lt;span class=&quot;math-container&quot;&gt;$\theta=90^o$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$r=0$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ring around the top pole transforms into a line with &lt;span class=&quot;math-container&quot;&gt;$\theta=0^o$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$r=2R$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We now have three lines through which we can fit our surface. You can do this with pen and paper. I'm not quite sure of what kind of curve you end up with (I haven't done the algebra haha) but my guess would be some kind of sideways parabola.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: I did the math, &lt;span class=&quot;math-container&quot;&gt;$r=2R\cos(\theta)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NOTE: I measure my &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; as the angle between some line crossing the origin and the Z axis&lt;/p&gt;&#xA;" OwnerUserId="8680" LastEditorUserId="8680" LastEditDate="2019-02-13T16:33:55.130" LastActivityDate="2019-02-13T16:33:55.130" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8589" PostTypeId="1" AcceptedAnswerId="8592" CreationDate="2019-02-13T18:11:59.373" Score="0" ViewCount="1775" Body="&lt;p&gt;I have an obj file, with texture coordinates (indicated by vt). How would I use this to load textures in OpenGL?&lt;/p&gt;&#xA;" OwnerUserId="10174" LastActivityDate="2019-02-14T13:42:31.297" Title="How do I use texture coordinates of a .obj file in OpenGL?" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8590" PostTypeId="2" ParentId="8589" CreationDate="2019-02-14T04:19:59.877" Score="1" Body="&lt;p&gt;If you are using vertex arrays and shaders, your vertices (v) can be indexed and stored in an element array buffer and your texture coordinates should be pass to the vertex shader to be send and used by the fragment shader. I recommend you to visit the site &lt;a href=&quot;https://learnopengl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://learnopengl.com/&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10178" LastActivityDate="2019-02-14T04:19:59.877" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8591" PostTypeId="2" ParentId="8584" CreationDate="2019-02-14T11:45:04.200" Score="0" Body="&lt;p&gt;I am still not sure whether this is what you actually want, but here's how to derive it mathematically. The equation of a sphere with center &lt;span class=&quot;math-container&quot;&gt;$(c_x, c_y, c_z)$&lt;/span&gt; and radius &lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt; is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(x-c_x)^2 + (y-c_y)^2 +(z-c_z)^2 =\rho^2$$&lt;/span&gt;&#xA;From the first image we can figure out that the sphere has center &lt;span class=&quot;math-container&quot;&gt;$(0,0,\rho)$&lt;/span&gt;, we also use the spherical coordinates substitution:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$x=r\cos\phi\sin\theta, y=r\sin\phi\sin\theta, z =r\cos\theta$$&lt;/span&gt;&#xA;Substituting yields:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(r\cos\phi\sin\theta - 0)^2 + (r\sin\phi\sin\theta-0)^2 + (r\cos\theta-\rho)^2 = \rho^2$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$r(r-2\rho\cos\theta) = 0$$&lt;/span&gt;&#xA;The roots to the last equation are &lt;span class=&quot;math-container&quot;&gt;$$r=0, r=2\rho\cos\theta, \theta\in [0, \pi/2]$$&lt;/span&gt;, we can drop the &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; since it is covered for &lt;span class=&quot;math-container&quot;&gt;$\theta = \pi/2$&lt;/span&gt;. Also &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; being in &lt;span class=&quot;math-container&quot;&gt;$[0, \pi/2]$&lt;/span&gt; restricts the sphere to being above the &lt;span class=&quot;math-container&quot;&gt;$xy$&lt;/span&gt; plane, whereas using the full range: &lt;span class=&quot;math-container&quot;&gt;$[0,\pi]$&lt;/span&gt; would produce also a sphere below. Thus you get the offset sphere in spherical coordinates:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$S=\{(r,\theta,\phi) : r=2\rho\cos\theta, \theta\in [0, \pi/2], \phi \in [0,2\pi]\}$$&lt;/span&gt;&#xA;If you want the ball and not only its boundary, then use &lt;span class=&quot;math-container&quot;&gt;$r\in [0,2\rho\cos\theta]$&lt;/span&gt; rather than &lt;span class=&quot;math-container&quot;&gt;$r=2\rho\cos\theta$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-02-14T12:10:26.127" LastActivityDate="2019-02-14T12:10:26.127" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8592" PostTypeId="2" ParentId="8589" CreationDate="2019-02-14T13:42:31.297" Score="3" Body="&lt;p&gt;The OBJ file itself doesn't contain the texture, only the texture co-ordinates (which describe how to map a texture onto the surface of the mesh.) The texture is an image file (such as a PNG) whose path is given by the accompanying .mtl file. You need to parse the .mtl file to get the path to the image file, then use an image-loading library (such as DevIL) to load the image into memory. Once you have the pixels of the image, you can use &lt;code&gt;glTexImage2D&lt;/code&gt; to load that image into a texture, which can be accessed from your fragment shader using a &lt;code&gt;sampler2D&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-02-14T13:42:31.297" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8593" PostTypeId="1" CreationDate="2019-02-15T03:16:17.093" Score="5" ViewCount="603" Body="&lt;p&gt;I'm writing a simple box blur for a graphics library.&#xA;The formula makes the average of a range of pixels by adding the ARGB amounts and then dividing by the blur range&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, with a blur range of 3;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel1 FF FF 00 00 +&#xA;pixel2 FF 00 FF 00 +&#xA;pixel3 FF 00 00 FF&#xA;/ 3 =&#xA;result FF 55 55 55&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which is correct.&#xA;A typical result shows as;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Z3A8X.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Z3A8X.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I am having difficulty with coming up with a formula to blur an image with alpha transparency.&#xA;The formula above gives this result for a yellow box on a transparent background;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OAlFT.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OAlFT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see that the yellow is surrounded by black colour - because the red and green are being diminished to 0. The result should actually look like so;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CTVCu.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CTVCu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So; the formula of &lt;code&gt;(pixel + pixel + pixel) / range&lt;/code&gt; is not working for alpha-blended images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone please give a correct formula?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="10184" LastEditorUserId="10184" LastEditDate="2019-02-15T03:46:38.300" LastActivityDate="2019-04-08T06:51:20.210" Title="Blur with alpha transparency" Tags="&lt;transparency&gt;&lt;blur&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8594" PostTypeId="1" CreationDate="2019-02-15T08:25:07.880" Score="1" ViewCount="244" Body="&lt;p&gt;I've been following these tutorials and i can't figure out how to send data to shaders using textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_02&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikibooks.org/wiki/OpenGL_Programming/Scientific_OpenGL_Tutorial_02&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this tutorial they are using GL_LUMINANCE which has been removed from OpenGL 3.1 and above. I was wondering what should i use instead of GL_LUMINANCE? I tried GL_RGB, GL_RED but i was unable to retrieve the values.&lt;/p&gt;&#xA;" OwnerUserId="10185" LastActivityDate="2019-03-17T12:01:45.463" Title="OpenGL Unable to retrieve the values of data sent to shader using textures" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8595" PostTypeId="2" ParentId="8593" CreationDate="2019-02-15T08:58:00.753" Score="7" Body="&lt;p&gt;Two suggestions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;If your data is from an image you are displaying on a standard monitor, the chances are it is (or you are implicitly assuming that it's) in sRGB format. This &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#The_sRGB_transfer_function_(%22gamma%22)&quot; rel=&quot;nofollow noreferrer&quot;&gt;means that the colour components are not linear&lt;/a&gt;. Ideally, you should first map into a linear colour space, do your filtering (e.g. blurring) operations, and then map back.&lt;br&gt;&#xA;*(If you just want to try a cheap and cheerful approach, squaring each of the R G B components is not a terrible approach to &quot;linearise&quot; the values&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;obviously, use sqrt() to map back)*.&lt;br&gt;&#xA;The alpha channel can be assumed to be linear.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Once in linear colour space, the next thing you want to do before filtering is to convert the pixels to a pre-multiplied-alpha format (AKA &quot;&lt;em&gt;associated colour&lt;/em&gt;&quot;).&lt;br&gt;&#xA;Basically, given 8bpc {A,R,G,B} pixel input, produce  {A, A*R/255, A*G/255, A*B/255}.  You then do your averaging on this premultiplied data as above on all four channels, and then map back by dividing through by the resulting alpha (if A=0 then, choose, RGB=0).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;This &lt;em&gt;should&lt;/em&gt; produce a better result. &#xA;For more info I suggest reading through Jim Blinn's &lt;a href=&quot;https://graphics.stanford.edu/courses/cs248-02/blinn_theory.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;Compositing, Part1: Theory&quot;&lt;/a&gt;.&lt;br&gt;&#xA;Particularly, note the line &quot;&lt;em&gt;Additionally, we must use associated colors for any filtering or interpolation operations&lt;/em&gt;&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Update&lt;/em&gt;: Seems I've posted a &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5517/209&quot;&gt;similar answer before&lt;/a&gt; &lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-04-08T06:51:20.210" LastActivityDate="2019-04-08T06:51:20.210" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8596" PostTypeId="1" CreationDate="2019-02-15T10:07:39.423" Score="3" ViewCount="439" Body="&lt;p&gt;I implemented a &lt;a href=&quot;https://github.com/zwcloud/CSharpPathTracer&quot; rel=&quot;nofollow noreferrer&quot;&gt;path tracer&lt;/a&gt; and got a similar result like &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/3972/is-it-expected-that-a-naive-path-tracer-takes-many-many-samples-to-converge&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sample: 4096, time used: 537.05s&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/lu4IP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lu4IP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm is exactly the same as &lt;a href=&quot;https://en.wikipedia.org/wiki/Path_tracing#Algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;the one&lt;/a&gt; in wikipedia, where only the &lt;strong&gt;Gathering Path&lt;/strong&gt; is considered.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In &lt;a href=&quot;https://computergraphics.stackexchange.com/a/3976/7114&quot;&gt;this answer&lt;/a&gt;, @Nathan Reed said that &quot;Without explicit light sampling, I'd expect very slow convergence.&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is &lt;em&gt;explicit light sampling&lt;/em&gt;? How to implement it? Do it mean &lt;em&gt;Shooting rays&lt;/em&gt; from &lt;a href=&quot;https://en.wikipedia.org/wiki/Path_tracing#Bidirectional_path_tracing&quot; rel=&quot;nofollow noreferrer&quot;&gt;bidirectional path tracing&lt;/a&gt;, namely the &lt;strong&gt;Shooting Path&lt;/strong&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Nathan Reed also said that &quot;Naive path tracing is more reasonable with e.g. a sky light, which almost every path can be expected to hit.&quot; So, BTW, what is a sky light? How to implement it?&lt;/p&gt;&#xA;" OwnerUserId="7114" LastEditorUserId="7114" LastEditDate="2019-02-15T10:22:29.803" LastActivityDate="2019-02-15T10:22:29.803" Title="How to implement explicit light sampling when implementing path tracing?" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8597" PostTypeId="2" ParentId="8587" CreationDate="2019-02-15T10:08:56.557" Score="1" Body="&lt;p&gt;(Not an answer but my comments are too large for a &quot;comment&quot;) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is more computational geometry than graphics. First of all, it would help if you could give an example (a drawing) which describes your input and your expected output. Are you working with low count polygons, or precise coastal maps? Do you want a real-time solution or is it off-line? It could be a big help if you would describe what you want to obtain with these rectangles covering your polygon. Also, what are your needs concerning the solution(s), for instance do you want the area of the rectangles to be as least as possible?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intrinsically this is NP-hard, this means there is a vast amount of possible solutions when the size of input data rises. Think of a circle covered by a square divided in two not necessarily equally sized rectangles. There is an infinite set of solutions already there concerning where they are split. Then just think of the amount of possible solutions for optimally packing a star shape into five or so rectangles, it's simply &quot;not possible&quot; if you want it done on a computer, in finite time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, you will be looking for a heuristic, that gives you a solution but not necessarily an optimal one. This means that you need to figure out what you want to accept being a solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: One variant of the problem at hand, that I didn't think of, could be that you already have N rectangles (size is given up front, they might be of the same size) that you wish to cover a polygon with. It's not simpler, also it could be impossible, for instance if the total area of the rectangles is less than the area of the polygon. So: Please describe your problem at bit more :)&lt;/p&gt;&#xA;" OwnerUserId="9194" LastEditorUserId="9194" LastEditDate="2019-02-15T13:10:43.083" LastActivityDate="2019-02-15T13:10:43.083" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8598" PostTypeId="2" ParentId="8594" CreationDate="2019-02-15T11:12:46.580" Score="3" Body="&lt;p&gt;What &lt;code&gt;GL_LUMINANCE&lt;/code&gt; as a texture format actually does is store one component of data per pixel that is used for the red, green and blue color components. So, a classic greyscale image (It doesn't use it for the alpha component, though, that's why there was also &lt;code&gt;GL_LUMINANCE_ALPHA&lt;/code&gt; for two compnent storage and &lt;code&gt;GL_INTENSITY&lt;/code&gt; that broadcasts it to all components).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using shaders you don't actually need this distinction anymore, though, since you can do the swizzling yourself in the shader. So you just use a proper typed 1-component internal format, most probably &lt;code&gt;GL_R8&lt;/code&gt; (i.e. 8-bit normalized fixed point red) in your case, but depending on your exact data type requirements really. And for setting it you would (in that case) use &lt;code&gt;GL_RED&lt;/code&gt; as the format of the data in your RAM storage. So something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, &amp;lt;width&amp;gt;, &amp;lt;height&amp;gt;, 0, GL_RED, &amp;lt;type&amp;gt;, &amp;lt;data&amp;gt;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And in the shader you can do with that red color component whatever you want. If you just need a single value per pixel, you use that. If you need a grey color (i.e. &lt;code&gt;GL_LUMINANCE&lt;/code&gt; behaviour), you swizzle it to the RGB components, and if you need it as color and opacity, you swizzle it into all four components. Or whatever else you want to do.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float data = texture(...).r;&#xA;vec4 luminance = texture(...).rrra;&#xA;vec4 intensity = texture(...).rrrr;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Though, this requires your shader to be somewhat aware of what texture you're working with. But if you want to use a more generic shader working with a 4-component color from an arbitrary texture, this might be too much of a hassle. In this case what you can also do is have the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Texture#Swizzle_mask&quot; rel=&quot;nofollow noreferrer&quot;&gt;texture itself control its own swizzling behaviour&lt;/a&gt;. This is an OpenGL 3.3+ feature and can be set with &lt;code&gt;glTexParameter&lt;/code&gt; and for good old &lt;code&gt;GL_LUMIMANCE&lt;/code&gt; behaviour this would be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameter(..., GL_TEXTURE_SWIZZLE_R, GL_RED);&#xA;glTexParameter(..., GL_TEXTURE_SWIZZLE_G, GL_RED);&#xA;glTexParameter(..., GL_TEXTURE_SWIZZLE_B, GL_RED);&#xA;glTexParameter(..., GL_TEXTURE_SWIZZLE_A, GL_ONE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For a broadcast into all components, i.e. &lt;code&gt;GL_INTENSITY&lt;/code&gt; behaviour, you can use the shortcut&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameter(..., GL_TEXTURE_SWIZZLE_RGBA, GL_RED);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So then you can retrieve a normal 4-component color from your texture in the shader and get the 1-component it's storing conveniently broadcast into the RGBA components of the result.&lt;/p&gt;&#xA;" OwnerUserId="6" LastEditorUserId="6" LastEditDate="2019-02-15T11:28:36.277" LastActivityDate="2019-02-15T11:28:36.277" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8599" PostTypeId="2" ParentId="2421" CreationDate="2019-02-15T15:27:58.447" Score="1" Body="&lt;p&gt;I read that paper as well last year. There's a strong assumption made by authors which is the &quot;stationary&quot;. What this means is that in absence of light in given 3000x2000 pixels image the material is more or less the same in each tile of 192x192. The reason for this is because we the surface is lit by white light is like they have a sample of BRDF for a set of angles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first shot is to get the stationarity of the material. The second shot is to get how each tile reacts to the interaction with the light from a different angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They collect the set of all tiles with the light and they later use their BRDF model to perform the fitting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The fitting, as you say, is done by using the L-M algorithm. There're few inconsistenties with the formula they use to perform the fitting, if I remember correctly the use non differentiable functions and they still perform the fitting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I remember correctly the actual fitting algorithm is constructed by one hand differentiating part of their cost function, while from the other hand they use a numerical approximation of the derivative/gradient/Jacobian.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The BRDF they use is parametrized using the several maps you mention in your question, therefore when they minimize the cost function they get optimal maps.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2019-02-15T15:27:58.447" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8602" PostTypeId="2" ParentId="8503" CreationDate="2019-02-15T22:43:02.520" Score="2" Body="&lt;p&gt;It turned out that the fillModeNonSolid feature needed to be explicitly enabled during logical device creation.&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2019-02-15T22:43:02.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8603" PostTypeId="1" AcceptedAnswerId="8604" CreationDate="2019-02-15T22:49:26.217" Score="1" ViewCount="429" Body="&lt;p&gt;I rely on this answer from Nathan Reed: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4969/how-much-precision-do-i-need-in-my-g-buffer/4971#4971?newreg=c82ae981d40148c1a38922de1b259a4c&quot;&gt;How much precision do I need in my G-Buffer?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is proposed to use two different texture formats for one Gbuffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However as far as I know, color texture attachments to framebuffer objects must have the same format: &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Framebuffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khronos.org/opengl/wiki/Framebuffer_Object&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Texture&#xA;      For the purposes of this article, a texture is an object that contains some number of images, as defined above. &lt;strong&gt;All of the images have the same format&lt;/strong&gt;, but they do not have to have the same size (different mip-maps, for example). Textures can be accessed from Shaders via various methods.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Is it possbile to use multiple render targets with different texture formats for a framebuffer? Or should just the lowest common format be choosen and manually pack and unpack the 16-Bit values in the shader?&lt;/p&gt;&#xA;" OwnerUserId="10188" LastActivityDate="2019-02-16T00:27:42.353" Title="GBuffer: Framebuffer with different texture format types?" Tags="&lt;opengl&gt;&lt;deferred-rendering&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8604" PostTypeId="2" ParentId="8603" CreationDate="2019-02-16T00:27:42.353" Score="3" Body="&lt;p&gt;You have a bit of a misunderstanding there. The paragraph you quoted doesn't actually say anything about framebuffer objects yet. It just talks about a single &lt;em&gt;texture&lt;/em&gt;. While we usually understand a texture as a single image, it is (or can be) &lt;em&gt;actually&lt;/em&gt; comprised of a &lt;em&gt;set of images&lt;/em&gt;. This might be because it is an &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Array_Texture&quot; rel=&quot;nofollow noreferrer&quot;&gt;Array Texture&lt;/a&gt; or, even more common, it just has a set of &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Texture#Mip_maps&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mip Map Levels&lt;/a&gt; (basically increasingly smaller filtered versions of the base image, used for advanced texture filtering). And yes, within a single texture, all those images have the same format. However &lt;em&gt;one&lt;/em&gt; such texture usually makes for &lt;em&gt;one&lt;/em&gt; render target.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All this has nothing to do with multiple render targets yet. And you will notice that the later parts of that article that speak about the actual framebuffer attachments, specifically the part about &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Framebuffer_Object#Completeness_Rules&quot; rel=&quot;nofollow noreferrer&quot;&gt;Framebuffer Completeness&lt;/a&gt; &lt;strong&gt;don't say anything of the sort of all attachments needing to have the same format, because there is no such restriction&lt;/strong&gt;. They don't even need to have the same dimensions. The only thing that is required is that they all have the same number of samples (if they're multisampled at all).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It &lt;em&gt;is&lt;/em&gt; possible that an implementation still doesn't support all kinds of image formats and combinations, but there are some that are required and a &quot;reasonable&quot; implementation will support a wide variety of format combinations, including ones with mixed pixel bit-depths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There &lt;em&gt;was&lt;/em&gt; a stricter limitation on the images in the original &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_framebuffer_object.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;GL_EXT_framebuffer_object extension&lt;/a&gt;, namely that all attachments have the same size and internal format. However, since it has found its way into OpenGL 3.0+ core (and was from there exported back as the more advanced &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_framebuffer_object.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;GL_ARB_framebuffer_object extension&lt;/a&gt;) they loosened these restrictions.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2019-02-16T00:27:42.353" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8606" PostTypeId="1" AcceptedAnswerId="8607" CreationDate="2019-02-16T13:09:28.590" Score="0" ViewCount="285" Body="&lt;p&gt;&lt;b&gt; Problem &lt;/b&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am following the book &lt;b&gt;Ray tracing in one weekend &lt;/b&gt;, and I got stuck after the implementation of the material Metal. I checked my code many times, and it looks exactly like the code implemented by Peter Shirley.&#xA;The problem is that, at this point, my code would need to generate this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EIo3S.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EIo3S.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead, my implementation results in this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/M0qkU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M0qkU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is no reflection on the left and right sphere, even if the code looks fine. I am not posting the code here since many classes are involved, and I implemented it following strictly the book. Did someone have a similar problem? I can post relevant parts of code that can help. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;b&gt; Possible solution &lt;/b&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The function of the reflection is not the problem, since it is very simple and it is exactly like the one proposed in the book. Also, when I set the sphere below (the floor) as Metal instead of Lambertian, it shows the reflections correctly:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vnLjf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vnLjf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This suggests that the problem is not the reflection function, nor the material. &lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-02-17T13:47:40.817" Title="Ray tracing in One weeked: issue with metal reflection" Tags="&lt;raytracing&gt;&lt;reflection&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8607" PostTypeId="2" ParentId="8606" CreationDate="2019-02-17T13:47:40.817" Score="0" Body="&lt;p&gt;The problem was in the way I was calculating the function &lt;code&gt;bool Sphere::hit()&lt;/code&gt;. The author eliminates some redundant 2's that cancel each other without explicitly showing it, and if you don't pay attention to this detail the code the &lt;code&gt;hit&lt;/code&gt; function will not work as it is supposed to. In case someone else is stuck, that might be the problem.&lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-02-17T13:47:40.817" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8608" PostTypeId="1" AcceptedAnswerId="8610" CreationDate="2019-02-17T23:20:54.137" Score="1" ViewCount="200" Body="&lt;p&gt;The D3D12 programming guide suggests specific &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/direct3d12/memory-management-strategies&quot; rel=&quot;nofollow noreferrer&quot;&gt;allocation strategies&lt;/a&gt; for command queues and allocators, but the creation methods for those objects &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/nf-d3d12-id3d12device-createcommandqueue&quot; rel=&quot;nofollow noreferrer&quot;&gt;operate&lt;/a&gt; &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/desktop/api/d3d12/nf-d3d12-id3d12device-createcommandallocator&quot; rel=&quot;nofollow noreferrer&quot;&gt;directly&lt;/a&gt; on queue/allocator pointers without taking a heap and an offset as an argument. How do I explicitly mark the memory I want to use for command processing?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2019-02-17T23:39:20.707" Title="How can I control memory for command allocators and command queues in D3D12?" Tags="&lt;c++&gt;&lt;gpu&gt;&lt;directx12&gt;&lt;memory&gt;&lt;api&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8609" PostTypeId="1" CreationDate="2019-02-17T23:38:26.360" Score="1" ViewCount="64" Body="&lt;p&gt;An efficient compute-shaded image filter would be emitted with (screenX / [kernel width], screenY / [kernel height], 1) groups and one kernel in each group, allowing texels to pass into groupshared memory and reducing the total number of samples at each pixel. But it seems like this will only apply the filter within the patches defined by each thread-group and create aliasing between them. Why doesn't this happen? If it does happen, how is it mitigated?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastEditorUserId="7868" LastEditDate="2019-02-18T00:19:07.520" LastActivityDate="2019-02-18T00:19:07.520" Title="Why don't discretization errors occur with compute-shaded kernel filters?" Tags="&lt;image-processing&gt;&lt;filtering&gt;&lt;gpgpu&gt;" AnswerCount="0" CommentCount="13" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8610" PostTypeId="2" ParentId="8608" CreationDate="2019-02-17T23:39:20.707" Score="2" Body="&lt;p&gt;You don't.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These objects typically work with CPU memory, not device memory. And to the extent that they involve device memory, such allocations tend to be rare and/or fixed in size (a queue may have a small spot of device memory that the hardware queue reads commands from or something, but even that is implementation-dependent).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan allows you to give objects which may allocate non-device memory allocation parameters to allow you to allocate said memory for them. But even then, there is no &lt;em&gt;guarantee&lt;/em&gt; that they will always allocate memory through your functions. Such systems can bypass your allocation routines, and only tell you allocator that it is allocating X bytes of memory (this is typically done for memory pages that have to be allocated in a special way). It doesn't let you actually provide it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That documentation does not seem to be talking about controlling how those objects allocate memory, but when and how you &lt;em&gt;create&lt;/em&gt; those objects. Command allocators and queues are critical, so you create X allocators and Y queues at the start and keep them around forever.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-02-17T23:39:20.707" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8612" PostTypeId="1" AcceptedAnswerId="8635" CreationDate="2019-02-18T18:02:18.913" Score="0" ViewCount="128" Body="&lt;p&gt;I have problem with creating diffuse irradiance map. As reference I am using &lt;a href=&quot;https://learnopengl.com/PBR/IBL/Diffuse-irradiance&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://learnopengl.com/PBR/IBL/Diffuse-irradiance&lt;/a&gt; and &lt;a href=&quot;https://github.com/TheEvilBanana/PhysicallyBasedRendering/blob/master/Game.cpp#L490&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/TheEvilBanana/PhysicallyBasedRendering/blob/master/Game.cpp#L490&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My map convolution looks not as it is supposed. I have black dot on every face. I use 2048x2048 which I render to 256x256 Texture2D and save each face which I then assemble. Below debug image. Up is +Y, Down is -Y, Middle is from the left -X, -Z, +X, +Z. What can I do to fix it? Also it looks like I am rendering same face twice somehow because +(plus) faces looks same like their -(minus) faces. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0NZGq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0NZGq.png&quot; alt=&quot;Skybox / irradiance map&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Render to texture method:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool GraphicsClass::ConvoluteShader(ID3D11ShaderResourceView * srcTex, RenderTextureClass * dstTex)&#xA;{&#xA;ifstream skyboxFile;&#xA;skyboxFile.open(&quot;Skyboxes/conv_cubemap.dds&quot;);&#xA;if (skyboxFile.fail() == false)&#xA;    return true;&#xA;&#xA;XMMATRIX worldMatrix, viewMatrix, projectionMatrix;&#xA;bool result;&#xA;&#xA;XMFLOAT3 position = XMFLOAT3(0, 0, 0);&#xA;XMFLOAT3 up[] = { XMFLOAT3(0, 1, 0), XMFLOAT3(0, 0, 1), XMFLOAT3(1, 0, 0), XMFLOAT3(0, -1, 0), XMFLOAT3(0, 0, -1), XMFLOAT3(-1, 0, 0) };&#xA;wchar_t* filenames[] = { L&quot;S﻿kyboxes/conv_posx.dds&quot;, L&quot;Skyboxes/conv_posy.dds&quot; , L&quot;Skyboxes/conv_posz.dds&quot;, L&quot;Skyboxes/conv_negx.dds&quot;, L&quot;Skyboxes/conv_negy.dds&quot;, L&quot;Skyboxes/conv_negz.dds&quot; };&#xA;for (int i = 0; i &amp;lt; 6; i++)&#xA;{&#xA;    dstTex-&amp;gt;SetRenderTarget(m_D3D-&amp;gt;GetDeviceContext(), m_D3D-&amp;gt;GetDepthStencilView());&#xA;    dstTex-&amp;gt;ClearRenderTarget(m_D3D-&amp;gt;GetDeviceContext(), m_D3D-&amp;gt;GetDepthStencilView(), 1.0f, 0.0f, 0.0f, 1.0f);&#xA;&#xA;    m_Camera-&amp;gt;Render();&#xA;    m_Camera-&amp;gt;GetViewMatrix(viewMatrix);&#xA;    m_D3D-&amp;gt;GetWorldMatrix(worldMatrix);&#xA;    m_D3D-&amp;gt;GetProjectionMatrix(projectionMatrix);&#xA;&#xA;    m_convoluteShader-&amp;gt;SetUpVector(up[i]);&#xA;&#xA;    m_D3D-&amp;gt;ChangeRasterizerCulling(D3D11_CULL_BACK);&#xA;    m_D3D-&amp;gt;ChangeDepthStencilComparison(D3D11_COMPARISON_LESS_EQUAL);&#xA;&#xA;    m_quadModel-&amp;gt;Render(m_D3D-&amp;gt;GetDeviceContext());&#xA;    m_convoluteShader-&amp;gt;Render(m_D3D-&amp;gt;GetDeviceContext(), m_quadModel-&amp;gt;GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix);&#xA;&#xA;    m_D3D-&amp;gt;ChangeRasterizerCulling(D3D11_CULL_BACK);&#xA;    m_D3D-&amp;gt;ChangeDepthStencilComparison(D3D11_COMPARISON_LESS);&#xA;&#xA;    m_D3D-&amp;gt;SetBackBufferRenderTarget();&#xA;    m_D3D-&amp;gt;ResetViewport();&#xA;&#xA;    m_renderTexturePreview-&amp;gt;BindTexture(dstTex-&amp;gt;GetShaderResourc﻿eView());&#xA;&#xA;    SaveDDSTextureToFile(m_D3D-&amp;gt;GetDeviceContext(), dstTex-&amp;gt;GetShaderResource(), filenames[i]);&#xA;}&#xA;&#xA;system(&quot;texassemble cube -w 256 -h 256 -f R8G8B8A8_UNORM -o Skyboxes/conv_cubemap.dds Skyboxes/conv_posx.dds Skyboxes/conv_negx.dds Skyboxes/conv_posy.dds Skyboxes/conv_negy.dds Skyboxes/conv_posz.dds Skyboxes/conv_negz.dds&quot;);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Vertex shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;cbuffer MatrixBuffer&#xA;{&#xA;    matrix worldMatrix;&#xA;    matrix viewMatrix;&#xA;    matrix projectionMatrix;&#xA;};&#xA;&#xA;struct VertexInputType&#xA;{&#xA;    float4 position : POSITION;    &#xA;};&#xA;&#xA;struct PixelInputType&#xA;{&#xA;    float4 positionSV : SV_POSITION;&#xA;    float4 position : POSITION;&#xA;};&#xA;&#xA;&#xA;PixelInputType ColorVertexShader(VertexInputType input)&#xA;{&#xA;    PixelInputType output;&#xA;&#xA;    output.position = input.position;&#xA;    input.position.w = 1.0f;&#xA;&#xA;    output.positionSV = mul(input.position, worldMatrix).xyww;&#xA;    output.positionSV = mul(output.positionSV, viewMatrix).xyww;&#xA;    output.positionSV = mul(output.positionSV, projectionMatrix).xyww;&#xA;&#xA;    return output;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Pixel Shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;TextureCube shaderTexture;&#xA;SamplerState SampleType;&#xA;&#xA;cbuffer UpVectorBuffer&#xA;{&#xA;    float3 g_upVectorVal;&#xA;    float g_upVectorPadding;&#xA;};&#xA;&#xA;struct PixelInputType&#xA;{&#xA;    float4 positionSV : SV_POSITION;&#xA;    float4 position : POSITION;&#xA;};&#xA;&#xA;static const float PI = 3.14159265359f;&#xA;&#xA;float4 ColorPixelShader(PixelInputType input) : SV_TARGET&#xA;{&#xA;    float3 normal = normalize(input.position.xyz);&#xA;&#xA;    float3 irradiance = float3(0.0f, 0.0f, 0.0f);&#xA;&#xA;    float3 up = g_upVectorVal;&#xA;    float3 right = cross(up, normal);&#xA;    up = cross(normal, right);&#xA;&#xA;    float sampleDelta = 0.025f;&#xA;    float nrSamples = 0.0f;&#xA;    for (float phi = 0.0f; phi &amp;lt; 2.0 * PI; phi += sampleDelta)&#xA;    {&#xA;        for (float theta = 0.0f; theta &amp;lt; 0.5 * PI; theta += sampleDelta)&#xA;        {&#xA;            float3 tangentSample = float3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));&#xA;            float3 sampleVec = (tangentSample.x * right) + (tangentSample.y * up) + (tangentSample.z * normal);&#xA;&#xA;            irradiance += shaderTexture.Sample(SampleType, sampleVec).rgb * cos(theta) * sin(theta);&#xA;            nrSamples++;&#xA;        }&#xA;    }&#xA;    irradiance = PI * irradiance * (1.0f / nrSamples);&#xA;    return float4(irradiance, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2019-02-25T21:26:38.327" Title="Weirdly looking diffuse irradiance map" Tags="&lt;pbr&gt;&lt;directx11&gt;&lt;directx&gt;&lt;ibl&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8613" PostTypeId="1" CreationDate="2019-02-18T18:03:36.223" Score="2" ViewCount="178" Body="&lt;p&gt;So usually texture samplers are set directly in the &lt;code&gt;D3D12_ROOT_SIGNATURE_DESC&lt;/code&gt; structure in DX12, at least that's how I've been setting them. I was wondering if it's possible to put them in an upload_heap and map a CPU pointer to it or something similar to make it possible to modify the samplers dynamicaly? &lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2019-07-19T13:03:05.450" Title="Is it possible to bind dynamic texture samplers to a shader in DX12?" Tags="&lt;shader&gt;&lt;directx12&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8614" PostTypeId="2" ParentId="8613" CreationDate="2019-02-19T12:34:22.417" Score="1" Body="&lt;p&gt;Yes it is possible by putting Samplers in descriptor tables to dynamically assign and index into them. Source: &lt;a href=&quot;https://youtu.be/Wbnw87tYqVg?t=754&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/Wbnw87tYqVg?t=754&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's an example that uses the HLSL root signature syntax to do this here:&#xA;&lt;a href=&quot;https://youtu.be/Wbnw87tYqVg?t=5277&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/Wbnw87tYqVg?t=5277&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2019-02-19T12:34:22.417" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8615" PostTypeId="2" ParentId="8587" CreationDate="2019-02-19T18:42:46.317" Score="0" Body="&lt;p&gt;I can't comment as I don't have enough reputation but I would take a look at packing algorithms, specially the ones using No/Inner Fit Polygon through computation of Minkowsky differences.&lt;/p&gt;&#xA;" OwnerUserId="9749" LastActivityDate="2019-02-19T18:42:46.317" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8617" PostTypeId="2" ParentId="8044" CreationDate="2019-02-20T21:55:41.273" Score="1" Body="&lt;p&gt;Your understanding of the matrix structure in Q3 is correct. This code just does not construct a matrix explicitly and the matrix multiplication is applied implicitly. I think this part might cause your confusion.&#xA;Instead of deciphering the code, I would rather derive the transform and compare it with the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The affine (6 degrees of freedom) and projective matrix (8 dof) map points to points. So you can build a system of equations for each pair of points in different frames. You will need to solve this system for the components of the matrix (Q1).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; be the transform matrix, then&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;M (0,0,1) &amp;amp;= (X_1,Y_1,1) \\&#xA;M (1,0,1) &amp;amp;= (X_2,Y_2,1) \\&#xA;M (0,1,1) &amp;amp;= (X_3,Y_3,1) \\&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;Each of above lines gives you two equations. Now you have 6 equations and the affine matrix can be derived.&#xA;For the projective matrix, we need extra two equations using the point &lt;span class=&quot;math-container&quot;&gt;$(X_4,Y_4)$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;H_4 &amp;amp;= M (1,1,1) \\&#xA;\frac{H_4}{H_4.z} &amp;amp;= (X_4,Y_4,1)&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;Note that I have to divide the homogeneous part for the transformed point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solve this linear system you can get an expression for your matrix &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt;. Perform &lt;span class=&quot;math-container&quot;&gt;$M (f_x,f_y,1)$&lt;/span&gt; you will see how it transforms the point. I believe this solves your Q2, Q3, Q5 and Q7.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For Q4, I think it is just a convention of pixel position and your understanding should be correct.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Appendix: maple code to verify the answer&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;with(ListTools):&#xA;# affine matrix&#xA;m:=&amp;lt;m11,m21,0|m12,m22,0|m13,m23,1&amp;gt;;&#xA;# Build equations&#xA;E:=[convert(m.&amp;lt;0,0,1&amp;gt; - &amp;lt;X1,Y1,1&amp;gt;,list),convert(m.&amp;lt;1,0,1&amp;gt; - &amp;lt;X2,Y2,1&amp;gt;,list), convert(m.&amp;lt;0,1,1&amp;gt; - &amp;lt;X3,Y3,1&amp;gt;,list)];&#xA;# E=[[m13 - X1, m23 - Y1, 0], [m11 + m13 - X2, m21 + m23 - Y2, 0],[m12 + m13 - X3, m22 + m23 - Y3, 0]]&#xA;# Solve E=0&#xA;sol:=eliminate(Flatten(E),indets(m));&#xA;# Plug the solution back to m:&#xA;subs(sol[1],m);&#xA;                           [-X1 + X2    -X1 + X3    X1]&#xA;                           [                          ]&#xA;                           [-Y1 + Y2    -Y1 + Y3    Y1]&#xA;                           [                          ]&#xA;                           [   0           0        1 ]&#xA;&#xA;&#xA;# projective matrix&#xA;p:=&amp;lt;m11,m21,a|m12,m22,b|m13,m23,1&amp;gt;;&#xA;# Compute transformed points&#xA;U0:=p.&amp;lt;0,0,1&amp;gt;;&#xA;U1:=p.&amp;lt;1,0,1&amp;gt;;&#xA;U2:=p.&amp;lt;1,1,1&amp;gt;;&#xA;U2:=p.&amp;lt;0,1,1&amp;gt;;&#xA;U3:=p.&amp;lt;1,1,1&amp;gt;;&#xA;# Build equations&#xA;E:=[convert(U0/U0[3]-&amp;lt;X1,Y1,1&amp;gt;,list),convert(U1/U1[3]-&amp;lt;X2,Y2,1&amp;gt;,list),convert(U2/U2[3]-&amp;lt;X3,Y3,1&amp;gt;,list),convert(U3/U3[3]-&amp;lt;X4,Y4,1&amp;gt;,list)];&#xA;# Sove E=0&#xA;solp:=eliminate(Flatten(E),indets(p));&#xA;# copy their code for xx and yy:&#xA;xx:=((X4-X1)*(Y3-Y1)-(Y4-Y1)*(X3-X1))/((X2-X1)*(Y3-Y1)-(Y2-Y1)*(X3-X1));&#xA;yy:=((X4-X1)*(Y2-Y1)-(Y4-Y1)*(X2-X1))/((X3-X1)*(Y2-Y1)-(Y3-Y1)*(X2-X1));&#xA;# Verify our a and b, compare ours with their expressing using xx and yy&#xA;subs(solp[1],a);&#xA;subs(solp[1],b);&#xA;simplify(subs(solp[1],a)-(yy-1)/(1-xx-yy));&#xA;# It is 0 as expected&#xA;simplify(subs(solp[1],b)-(xx-1)/(1-xx-yy));&#xA;# It is also 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="120" LastActivityDate="2019-02-20T21:55:41.273" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8618" PostTypeId="2" ParentId="2131" CreationDate="2019-02-21T03:08:51.373" Score="2" Body="&lt;p&gt;From your code snippet and your result for 2x2 example, I can see that you are actually simulating a domain with only Neumann boundary conditions (slip wall). In this case, the system contains a null space and your matrix is singular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this is the simulation configuration you want (i.e. no Dirichlet(pressure) BC), you will need to project out the null space from your solution. This is straightforward if you are using the conjugate gradient (CG) as suggested in that paper.&#xA;In each iteration of your CG iteration, just take the current solution vector &lt;span class=&quot;math-container&quot;&gt;$\mathbf{x}$&lt;/span&gt;, and do&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\mathbf{x}' &amp;amp;= (\mathbf{I}-\mathbf{\hat{u}}\mathbf{\hat{u}}^T)\mathbf{x}\\&#xA;&amp;amp;= \mathbf{x} - (\mathbf{\hat{u}} \cdot \mathbf{x} )\mathbf{\hat{u}}&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\mathbf{\hat{u}}$&lt;/span&gt; is the normalized null space of gradient operator:&#xA;&lt;span class=&quot;math-container&quot;&gt;$\mathbf{u} = (1,1,\dots,1)$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\mathbf{\hat{u}}=\frac{\mathbf{u}}{\lVert \mathbf{u} \rVert}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Otherwise if you do want to simulate air (free boundary or Dirichlet BC), you will need to distinguish a wall and an air cell (i.e. having a boolean &lt;code&gt;hasLiquid&lt;/code&gt; is not enough), and apply correct discretization for them (see below).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a final note, your diagonal entries are negative. You may want to flip the signs so that the CG method works.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Below I would like to show more details.&#xA;Consider the pressure projection process. Denote the velocity before the pressure projection as &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}^*$&lt;/span&gt;. It could be divergent, so we compute pressure to correct it and get the divergence free velocity &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}^{n+1}$&lt;/span&gt;. That is,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\mathbf{v}^{n+1} &amp;amp;= \mathbf{v}^* - \frac{\Delta t}{\rho} \nabla P&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;Take divergence of it, and since &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}^{n+1}$&lt;/span&gt; is divergence free,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\nabla \cdot \nabla P &amp;amp;= \nabla \cdot \mathbf{v}^*&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;Suppose that there is no pressure Dirichlet BC presesnt and we have one solution &lt;span class=&quot;math-container&quot;&gt;$P_0$&lt;/span&gt;, then &lt;span class=&quot;math-container&quot;&gt;$P_0+c$&lt;/span&gt; for any constant &lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt; is also a solution because &lt;span class=&quot;math-container&quot;&gt;$\nabla \cdot \nabla (P_0+c) = \nabla \cdot \nabla P_0 = \nabla \cdot \mathbf{v}^*$&lt;/span&gt;.&#xA;&lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt; is the null space we want to project out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To handle the Dirichlet BC, lets consider the 1D case as an example. Assume you are using staggered grid, where pressures &lt;span class=&quot;math-container&quot;&gt;$p_i$&lt;/span&gt; are located at grid centers and velocities &lt;span class=&quot;math-container&quot;&gt;$v_{i+1/2}$&lt;/span&gt; are located at the faces between nodes &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$i+1$&lt;/span&gt;. Then the general discretization for one cell is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{p_{i+1}-p_i-(p_i-p_{i-1})}{\Delta x^2} = \text{rhs}&#xA;$$&lt;/span&gt;&#xA;Suppose that &lt;span class=&quot;math-container&quot;&gt;$p_{i+1}$&lt;/span&gt; is an air cell, that is, its pressure has been specified,&#xA;then the &lt;span class=&quot;math-container&quot;&gt;$p_{i+1}$&lt;/span&gt; term is moved to the right hand side and disappears from the matrix. Note that the count of diagonal term &lt;span class=&quot;math-container&quot;&gt;$p_i$&lt;/span&gt; is still two. That is why I said your 2x2 example did not contain a Dirichlet BC.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With either Dirichlet or Neumann BC the matrix is always symmetric positive definite. That is why the authors said&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Static object and empty cells don’t disrupt this structure.&#xA;In that case pressure and velocity terms can disappear from both sides&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="120" LastActivityDate="2019-02-21T03:08:51.373" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8619" PostTypeId="2" ParentId="6402" CreationDate="2019-02-21T04:23:46.520" Score="1" Body="&lt;p&gt;The rigid body simulation is very similar to the point mass case except for&#xA;that we have to handle rotational motion (orientation and angular momentum).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition to common particle attributes such as mass, position, and linear velocity, we will need to store initial moment of inertia &lt;span class=&quot;math-container&quot;&gt;$\mathbf{\hat{I}}$&lt;/span&gt;,&#xA;current angular momentum &lt;span class=&quot;math-container&quot;&gt;$\mathbf{L}^n$&lt;/span&gt;, and current orientation &lt;span class=&quot;math-container&quot;&gt;$\mathbf{R}^n$&lt;/span&gt;.&#xA;If you are using a data driven particle system, this step is as easy as declaring a few new attributes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Contract to the mass, the moment of inertia at current time step &lt;span class=&quot;math-container&quot;&gt;$\mathbf{I}^n$&lt;/span&gt; depends on the current orientation &lt;span class=&quot;math-container&quot;&gt;$\mathbf{R}^n$&lt;/span&gt;: &lt;span class=&quot;math-container&quot;&gt;$\mathbf{I}^n=\mathbf{R}^n \mathbf{\hat{I}} (\mathbf{R}^n)^T$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The kinetic of a rigid body is analogous to the linear motion:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\dot{\mathbf{R}} &amp;amp;= \omega^* \mathbf{R} \\&#xA;\frac{\mathbf{R}^{n+1} - \mathbf{R}^n}{\Delta t} &amp;amp;= (\omega^{n*}) \mathbf{R}^n \\&#xA;\omega^n &amp;amp;= (\mathbf{I}^n)^{-1} \mathbf{L}^n&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt; is the angular velocity and &lt;span class=&quot;math-container&quot;&gt;$\omega^*$&lt;/span&gt; is the &quot;cross product&quot; matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For dynamics, we also have a similar version of Newton's &quot;f=ma&quot;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{\mathbf{L}^{n+1} - \mathbf{L}^n}{\Delta t} = \tau^n&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\tau$&lt;/span&gt; is the torque.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because there will be interactions between rigid spheres, you will also need to implement the collision detection for spheres.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we have known the kinematics and dynamics of rigids. The only thing left is how to solve (integrate) above equations. The naive forward Euler may not give stable result. A good introduction of this topic can be found at &lt;a href=&quot;http://www.cs.cmu.edu/~baraff/sigcourse/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Witkin and Baraff SIGGRAPH course&lt;/a&gt;, and here is an another more &lt;a href=&quot;https://www.cs.ucr.edu/~shinar/papers/2018_introduction_to_pba.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;recent SIGGRAPH course by Bargteil and Shinar&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="120" LastEditorDisplayName="user106" LastEditDate="2019-02-26T21:46:41.207" LastActivityDate="2019-02-26T21:46:41.207" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8621" PostTypeId="1" AcceptedAnswerId="8622" CreationDate="2019-02-21T12:08:12.017" Score="0" ViewCount="129" Body="&lt;p&gt;I'm just getting started trying to understand noise generation algorithms. What I'm trying to achieve is to get a 2D (or 3D) grid of random directional vectors (again, 2D or 3D) according to a noise distribution like Perlin, ie. not just a grid of totally randomly generated vectors (which would be easy to do).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before starting to figure this out, I had assumed that 1D noise functions would be those that produce a series of float values (ranging from -1 to 1, for example), and that 2D noise functions would produce float2 values, 3D noise would produce float3 values, and so on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, searching for so-called 2D noise functions, it seems that they are used to produce a 2D grid (ie. texture) of single float values. However, what I'm looking for is a 2D grid of 2D (float2 / vector2) values, or a 3D grid of 3D (float3 / vector3) values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From my (still pretty limited) understanding of a gradient-based noise like Perlin, I feel like I could probably hack something together from an existing Perlin function - doing a bi-linear/tri-linear interpolation of the surrounding gradient vectors which are ordinarily used for the subsequent dot product in Perlin noise. But I have no idea if that's the correct approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there existing libraries/methods for something like this?&lt;/p&gt;&#xA;" OwnerUserId="7023" LastActivityDate="2019-02-21T13:37:08.107" Title="How to create 2D (directional) noise?" Tags="&lt;noise&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8622" PostTypeId="2" ParentId="8621" CreationDate="2019-02-21T13:02:58.010" Score="3" Body="&lt;p&gt;Why don't you just use Perlin noise twice on the same grid, or volume? Each with slightly different parameters (a phase shift, or different pseudo-random vectors). In this case both component of your float2 are smoothly defined by a Perlin Noise field. A float2 &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; could be defined as &lt;span class=&quot;math-container&quot;&gt;$v = \{P(u,v), P(u+0.5, v+0.5)\},$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$P(u,v)$&lt;/span&gt; is the Perlin noise function. However, this will make the &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; component of &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; very close depending on the scaling of the grid values.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2019-02-21T13:06:32.227" LastActivityDate="2019-02-21T13:06:32.227" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8623" PostTypeId="2" ParentId="8621" CreationDate="2019-02-21T13:37:08.107" Score="1" Body="&lt;p&gt;You can use the gradient of the noise/hash which for a function &lt;span class=&quot;math-container&quot;&gt;$f:\mathbb{R}^n\rightarrow\mathbb{R}$&lt;/span&gt; would be &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; dimensional (depending on the application this may not work for you). Another possibility, as Reynolds mentioned is to generate the noise by calling the function multiple times.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-02-21T13:37:08.107" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8624" PostTypeId="1" CreationDate="2019-02-21T13:38:49.560" Score="1" ViewCount="314" Body="&lt;p&gt;Why do animated CG characters always feel fake?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually if a CG character is an animal (or humanoid creature), they tend too look kinda off. Their movement tends to look oddly smooth or lightweight, even if aided with motion capture. Compare to real human or animal movement which is jagged, and has slight irregularity or weight. It doesn't matter whether the texture looks photorealistic, the movement of CG characters always feels off.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm guessing it's because the animation curves for the final images are smoothed out or simplified, like smoothing a bezier curve or something. Is that the case? Is absolute, true-to-life movement possible for CG characters?&lt;/p&gt;&#xA;" OwnerUserId="10212" LastEditorUserId="6" LastEditDate="2019-02-25T23:28:00.200" LastActivityDate="2019-02-25T23:28:00.200" Title="Why do animated CG characters always feel fake?" Tags="&lt;3d&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8625" PostTypeId="2" ParentId="6119" CreationDate="2019-02-22T02:22:54.087" Score="1" Body="&lt;p&gt;I guess your question is how to compute the inertia tensor automatically. A parametric equation may not be always possible, but we could write a program to avoid hand calculations as much as possible.&lt;/p&gt;&#xA;&lt;p&gt;The inertia tensor &lt;span class=&quot;math-container&quot;&gt;$\mathbf{I}$&lt;/span&gt; is defined as an integral over the object domain &lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt; (see &lt;a href=&quot;https://en.wikipedia.org/wiki/Moment_of_inertia#Inertia_tensor&quot; rel=&quot;nofollow noreferrer&quot;&gt;Inertia tensor&lt;/a&gt;):&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\newcommand{\V}[1]{\mathbf{#1}}&#xA;\begin{align}&#xA;\V{I} &amp;amp;= \int_\Omega \rho (\V{r}\cdot\V{r} \delta - \V{r}\V{r}^T)\,dV&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\V{r}$&lt;/span&gt; is the position relative to the center of mass (COM),&lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt; is the density, and &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt; is the identity matrix.&lt;/p&gt;&#xA;&lt;p&gt;Note that &lt;span class=&quot;math-container&quot;&gt;$\text{tr}(\V{r}\V{r}^T) = \V{r}\cdot \V{r}$&lt;/span&gt;, the above definition  can be rearranged as&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\V{T} &amp;amp;= \V{r}\V{r}^T \\&#xA;\V{I} &amp;amp;= \int_\Omega \rho (\text{tr} \V{T} \delta - \V{T})\,dV&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;h2&gt;Analytic object&lt;/h2&gt;&#xA;&lt;p&gt;For analytic objects you can substitute their equations into the integral and do symbolic integration. This step can be automated with any symbolic computing software.&lt;/p&gt;&#xA;&lt;h2&gt;Object in tetrahedral mesh&lt;/h2&gt;&#xA;&lt;p&gt;We assume the object is simple and has a closed boundary.&#xA;An analytic solution is not possible in this case because we do not have an explicit equation for the object. But we could compute the inertia tensor numerically.&#xA;The only integral we have to compute is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\V{C} &amp;amp;=&#xA;\int_\Omega \rho \V{r}\V{r}^T\,dV&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;To compute this integral, &lt;a href=&quot;http://number-none.com/blow/inertia/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; could be helpful.&#xA;The general idea is to compute &lt;span class=&quot;math-container&quot;&gt;$\V{C}_t$&lt;/span&gt; for each tetrahedron &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;, and sum &lt;span class=&quot;math-container&quot;&gt;$\V{C}_t$&lt;/span&gt; to get &lt;span class=&quot;math-container&quot;&gt;$\V{C}$&lt;/span&gt;.&#xA;We first compute the integral for a canonical tetrahedron &lt;span class=&quot;math-container&quot;&gt;$t0$&lt;/span&gt; whose vertices are&#xA;&lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$(1,0,0)$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$(0,1,0)$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$(0,0,1)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In maple, this canonical integral &lt;span class=&quot;math-container&quot;&gt;$\V{C}_{t0}$&lt;/span&gt; is (assume &lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt; constant)&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;r:=&amp;lt;x,y,z&amp;gt;; &#xA;                                                    [x]&#xA;                                                    [ ]&#xA;                                               r := [y]&#xA;                                                    [ ]&#xA;                                                    [z]&#xA;&#xA;with(LinearAlgebra):                                &#xA;rrt:=r.Transpose(r);&#xA;                                             [ 2               ]&#xA;                                             [x      x y    x z]&#xA;                                             [                 ]&#xA;                                      rrt := [        2        ]&#xA;                                             [x y    y      y z]&#xA;                                             [                 ]&#xA;                                             [               2 ]&#xA;                                             [x z    y z    z  ]&#xA;&#xA;seq(seq(int(int(int(rrt[i,j],x=0..1-y-z),y=0..1-z),z=0..1),i=1..3),j=1..3);&#xA;                      1/60, 1/120, 1/120, 1/120, 1/60, 1/120, 1/120, 1/120, 1/60&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then the integral &lt;span class=&quot;math-container&quot;&gt;$\V{C}_t$&lt;/span&gt; can be computed by a change of variable.&#xA;Assume the coordinates of a world space tetrahedron can be represented as &lt;span class=&quot;math-container&quot;&gt;$\V{r}=\V{F}\V{r}_0 + \V{x}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\V{F}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\V{x}$&lt;/span&gt; are constant.&#xA;We have&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\V{C}_t &amp;amp;= \rho \int_{\Omega_t} \V{r}\V{r}^T\,dV \\&#xA;&amp;amp;= \rho \int_{\Omega_{t0}} (\V{F}\V{r}_0 + \V{x})(\V{F}\V{r}_0+\V{x})^T \det \V{F} \,dV_0 \\&#xA;&amp;amp;= \rho \int_{\Omega_{t0}} (\V{F}\V{r}_0\V{r}_0^T\V{F}^T + \V{x}\V{x}^T + \V{F}\V{r}_0\V{x}^T + \V{x}\V{r}_0^T\V{F}^T) \det \V{F} \,dV_0 \\&#xA;&amp;amp;= \det(\V{F}) \V{F}\V{C}_{t0}\V{F}^T + \det(\V{F}) m \V{x}\V{x}^T + \det(\V{F}) m \V{\bar{r}}\V{x}^T + \det(\V{F}) m \V{x}\V{\bar{r}}^T&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\V{\bar{r}}$&lt;/span&gt; is the COM and &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; is the mass.&lt;/p&gt;&#xA;&lt;h2&gt;Objects in other form&lt;/h2&gt;&#xA;&lt;p&gt;I did not use Inventor before but I suspect the part produced by it may have other formats, such as Bezier surface. For now I would suggest tetrahedralize the object and apply the above method.&lt;/p&gt;&#xA;" OwnerUserId="120" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-02-22T02:22:54.087" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8627" PostTypeId="1" AcceptedAnswerId="8629" CreationDate="2019-02-22T12:51:59.463" Score="0" ViewCount="125" Body="&lt;p&gt;My question is not about the code, but it's about the approach used by the author Peter Shirley (and apparently common practice in ray tracers) of handling Instances. To understand the question it's necessary to be familiar with the book, because posting the code for every class involved is not feasible.&#xA;Something I don't understand is how rays behave. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's consider the &lt;i&gt;traslation&lt;/i&gt;. The idea is to offset the origin, and check if the new ray - which is now shot from the new origin with the same direction of the original ray - hits the object. If so, we shift the hitting point by an equal and opposite offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lPSZh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lPSZh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Two questions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Why is it not sufficient to shoot rays from the &quot;standard&quot; origin, and offset the hitting point without actually shifting the origin first? Example: the ray is shot, if it hits the object in point (x,y) I move the hitting point by 2 (x+2, y+2) and store it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) The hit function of the class &lt;code&gt;translate&lt;/code&gt; is only called when the original ray hits the object? Because in that case, the translation would not result in the whole object, since it would only store those points that are first hit by the original ray, and for which the new ray hits the object again.&lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-02-22T15:51:29.927" Title="Ray tracing the next week: understanding Instances" Tags="&lt;raytracing&gt;&lt;shader&gt;&lt;transformations&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8628" PostTypeId="2" ParentId="8624" CreationDate="2019-02-22T14:49:45.697" Score="1" Body="&lt;p&gt;Because animators haven't fully bridged the uncanny valley. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are a ton of little details you notice subconsciously that hasn't been fully mapped out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things like how muscles and tendons move under the surface, how clothing and hair behaves as you move around. Even how you adjust your stance as you move your arms around, prepare to move, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even with mocap it is difficult to capture and recreate all that. It is also not trivial to capture the movement of the fingers. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-02-22T14:49:45.697" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8629" PostTypeId="2" ParentId="8627" CreationDate="2019-02-22T15:51:29.927" Score="1" Body="&lt;p&gt;There are two ways to 'translate' your object. The first is by moving each point of your object by the desired translation. The second is by translating the origin of your coordinate system. In this case it's the latter. Basically it turns out to be the same, whether you translate your object by a vector &lt;span class=&quot;math-container&quot;&gt;$\vec{t}$&lt;/span&gt; or whether you translate your origin by &lt;span class=&quot;math-container&quot;&gt;$-\vec{t}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For 2) note that you only care about the intersected points (since that is what you use to compute the pixel color), so you compute the offset only when you need it. So yes, you do translate the origin of the ray at each intersect, it's the same as translating the object though (at each ray intersect), since &lt;span class=&quot;math-container&quot;&gt;$\vec{p}+\vec{t} - \vec{o} = \vec{p} - (\vec{o}-\vec{t})$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-02-22T15:51:29.927" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8630" PostTypeId="1" CreationDate="2019-02-24T08:55:40.133" Score="0" ViewCount="342" Body="&lt;p&gt;So I read about tonemapping and Gamma Correction recently and have implemented it in my path tracer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the time being I'm using Reinhard tonemapping operator as described in his paper&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L_d = L_w * (1+L_w/L^2_{white})/(1+L_w)$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and applying it on the luminance channel and scaling it effectively so the colors wouldn't change. I'm applying a Gamma correction of 2.2. Here is the snippet.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float lum_world = getYluminance(hdr_col); //Find the Y channel of XYZ from RGB&#xA;float lum_display = lum_world * (1 + lum_world/(lum_white * lum_white) ) / (1+lum_world);&#xA;float4 ldr_color = lum_display *(hdr_col/lum_world); &#xA;ldr_color = pow(ldr_color, (float4) (1/2.2) );  // Gamma correction&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So apparently if I leave out the last step of Gamma Correction I feel I get more aesthetically pleasing images. If anybody can confirm if it's working as intended or there's something wrong. Note that I'm using OpenGL to display Images but nowhere am I using &lt;code&gt;GL_FRAMEBUFFER_SRGB&lt;/code&gt; so there's no implicit gamma correction being done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is gamma corrected (Light intensities are set to 8.0f)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/8y7wH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8y7wH.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is with tonemapping but without gamma correction. Light intensities were scaled to 18.0f. At 8.0f the image was very dark.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/06S7D.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/06S7D.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For comparison here is the gamma-corrected image at 18.0f. It's just the whole image got whiter/brighter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KwWiK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KwWiK.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can see that Gamma corrected one looks washed out, shadows are much much lighter and the back wall looks outright bad. I don't know what to call it but the GI in the un-corrected image looks better.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-02-24T09:14:42.633" LastActivityDate="2019-02-24T09:14:42.633" Title="Path tracing - Better images without Gamma correction?" Tags="&lt;pathtracing&gt;&lt;color&gt;&lt;gamma&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8631" PostTypeId="2" ParentId="8444" CreationDate="2019-02-24T17:59:53.187" Score="3" Body="&lt;p&gt;Throughout my answer I'll sometimes refer to some results in &lt;a href=&quot;https://sites.fas.harvard.edu/~cs278/papers/veach.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://sites.fas.harvard.edu/~cs278/papers/veach.pdf&lt;/a&gt; by using [MIS,section_number].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can skip the following derivation if you don't care about the mathematical explanation of why using MIS to combine estimators is valid.&#xA;I'll have to start with what the purpose of MIS is. The general idea is that you want to estimate some integral &lt;span class=&quot;math-container&quot;&gt;$I=\int_{\Omega}{f(x)\,d\mu(x)}$&lt;/span&gt; through Monte Carlo, and you have various sampling pdfs (in our case a pdf for sampling points on the light, and a pdf for sampling directions from the brdf). Additionally you want to sample using more than one technique and then combine the contributions optimally (in some sense). For simplicity I will restrict myself to the case where you have only two pdfs: &lt;span class=&quot;math-container&quot;&gt;$p_L(x), p_B(x)$&lt;/span&gt; with respect to the same measure &lt;span class=&quot;math-container&quot;&gt;$\mu(x)$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume that you also have the weighting functions &lt;span class=&quot;math-container&quot;&gt;$w_1(x), w_2(x) : \Omega \rightarrow [0,1], w_1(x) + w_2(x) = 1$&lt;/span&gt; and also &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; independently and identically distributed (i.i.d.) samples &lt;span class=&quot;math-container&quot;&gt;$x_{p_L,i}: i=1,...,n$&lt;/span&gt; according to &lt;span class=&quot;math-container&quot;&gt;$p_L$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; i.i.d. samples &lt;span class=&quot;math-container&quot;&gt;$x_{p_B,j} : j=1,...,m$&lt;/span&gt; according to &lt;span class=&quot;math-container&quot;&gt;$p_B$&lt;/span&gt;, we can use Monte Carlo with MIS to estimate the integral &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ I = \int_{\Omega}{f(x)\,d\mu(x)} = \int_{\Omega}{f(x)(w_1(x)+w_2(x))\,d\mu(x)}  \\&#xA;= \int_{\Omega}{\frac{w_1(x)f(x)}{p_L(x)}p_L(x)\,d\mu(x)} + \int_{\Omega}{\frac{w_2(x)f(x)}{p_B(x)}p_B(x)\,d\mu(x)} \\&#xA;= E\left[\frac{w_1(X_{p_L})f(X_{p_L})}{p_L(X_{p_L})}\right] + E\left[\frac{w_2(X_{p_B})f(X_{p_B})}&#xA;{p_B(X_{p_B})}\right] \\&#xA;= \frac{1}{n}\sum_{i=1}^{n}{E\left[\frac{w_1(X_{p_L,i})f(X_{p_L,i})}{p_L(X_{p_L,i})}\right]} + \frac{1}{m}\sum_{j=1}^{m}{E\left[\frac{w_2(X_{p_B,j})f(X_{p_B,j})}&#xA;{p_B(X_{p_B,j})}\right]} \\&#xA;= E\left[\frac{1}{n}\sum_{i=1}^{n}{\frac{w_1(X_{p_L,i})f(X_{p_L,i})}{p_L(X_{p_L,i})}}\right] + E\left[\frac{1}{m}\sum_{j=1}^{m}{\frac{w_2(X_{p_B,j})f(X_{p_B,j})}&#xA;{p_B(X_{p_B,j})}}\right] \\&#xA;\approx \frac{1}{n}\sum_{i=1}^{n}{\frac{w_1(x_{p_L,i})f(x_{p_L,i})}{p_L(x_{p_L,i})}} &#xA;+ \frac{1}{m}\sum_{j=1}^{m}{\frac{w_2(x_{p_B,j})f(x_{p_B,j})}&#xA;{p_B(x_{p_B,j})}}&#xA;$$&lt;/span&gt;&#xA;Where the second equality holds because &lt;span class=&quot;math-container&quot;&gt;$w_1(x)+w_2(x)=1$&lt;/span&gt;, the fourth follows from the definition of expected value, the fifth holds since &lt;span class=&quot;math-container&quot;&gt;$X_{p_L,i}$&lt;/span&gt; are independently and identically distributed (i.i.d.) according to &lt;span class=&quot;math-container&quot;&gt;$p_L$&lt;/span&gt; and similarly &lt;span class=&quot;math-container&quot;&gt;$X_{p_B,i}$&lt;/span&gt; are i.i.d. according to &lt;span class=&quot;math-container&quot;&gt;$p_B$&lt;/span&gt;. The sixth holds because of the properties of the expectation (which follows from the fact that integration is a linear operator). The last approximate equality follows from the strong law of large numbers (the average of the samples converges almost surely to the expected value with the number of samples going to infinity).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having this result the first thing to note is that both pdfs are defined with respect to the same measure &lt;span class=&quot;math-container&quot;&gt;$\mu(x)$&lt;/span&gt;. However I believe that in your code and overview you pdf for sampling the light &lt;span class=&quot;math-container&quot;&gt;$p_L$&lt;/span&gt; is defined with respect to the area measure, whereas the pdf for sampling the brdf &lt;span class=&quot;math-container&quot;&gt;$p_B$&lt;/span&gt; is defined with respect to the solid angle measure. The relationship between those being &lt;span class=&quot;math-container&quot;&gt;$d\sigma(x\rightarrow y) = \frac{\cos\theta_y}{||x-y||^2}dA(y)$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$x \in \mathbb{R}^3$&lt;/span&gt; is the current point for which you are computing the illumination (that is your intersection point), and &lt;span class=&quot;math-container&quot;&gt;$y \in \mathbb{R}^3$&lt;/span&gt; is a point on the surface of some light source. Additionally &lt;span class=&quot;math-container&quot;&gt;$(x\rightarrow y) = \frac{y-x}{||y-x||}$&lt;/span&gt; is simply the unit direction vector from &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\cos\theta_y = n_y \cdot (y\rightarrow x)$&lt;/span&gt; is the cosine of the angle between the normal &lt;span class=&quot;math-container&quot;&gt;$n_y$&lt;/span&gt; (also unit length) of the light surface at &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$-(x\rightarrow y)$&lt;/span&gt;. More specifically what you have produced as light pdf is really the probability of picking the light &lt;span class=&quot;math-container&quot;&gt;$weights[i]/sum$&lt;/span&gt; multiplied by the probability of picking uniformly a point on the light source that you have chosen &lt;span class=&quot;math-container&quot;&gt;$1/area$&lt;/span&gt;. The solid angle to area (or vice versa) conversion seems to be missing in your code and your overview, that is your pdf is with respect to the area measure, and you combine it with a pdf (the brdf's) that is with respect to the solid angle measure, which is clearly wrong as you can see from my derivation above. To get the  brdf pdf with respect to the area measure and not the solid angle measure you can use: &lt;span class=&quot;math-container&quot;&gt;$p_{\omega}(\omega)\,d\sigma(\omega) = p_A(y)\,dA(y)$&lt;/span&gt; then using the relationship between the measures &lt;span class=&quot;math-container&quot;&gt;$p_A(y) = p_{\omega}(\omega)\,d\sigma(\omega) / dA(y) = p_{\omega}(\omega) \frac{\cos\theta_y}{||x-y||^2}$&lt;/span&gt;. You can refer to [MIS, 2.3] equation (9). For a formal derivation of the relationship between the two measures you can refer to &lt;a href=&quot;http://www.dgp.toronto.edu/~lessig/dissertation/files/area_formulation.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.dgp.toronto.edu/~lessig/dissertation/files/area_formulation.pdf&lt;/a&gt; , another possible derivation of the same fact can be done through the divergence theorem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now as far as the practical part goes - you need to know when to apply the mis weighting. There are a few cases which occur. Initially for the very first ray, you should not use MIS since you shouldn't sample any light directly. Additionally if the last bounce was fully deterministic (ideal reflection/refraction) then you also should not use MIS, since sampling the light is useless in that case. Finally if you hit a light through sampling the bsdf, you should use MIS to add this contribution, and convert the bsdf pdf wrt the area measure, and then combine it with the probability of sampling this point on this light by using the light pdf and use the area formulation estimator of the rendering equation. When you sample a light, you should also use MIS, once again computing the area formulation estimator. Finally if you have point lights, those can be sampled only through NEE, so you should not use MIS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that there may be more mistakes that you have. Also I didn't understand anything of your explanation past &quot;After that I come to BRDF sampling.&quot;.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-02-24T17:59:53.187" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="8632" PostTypeId="2" ParentId="6249" CreationDate="2019-02-25T07:12:19.120" Score="0" Body="&lt;p&gt;Utilize &lt;code&gt;simd&lt;/code&gt; to synchronize your alignment:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;import simd&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private struct BoundingBoxParameters {&#xA;&#xA;    let topLeft: float2 = float2(0.0, 0.0)&#xA;    let size: float2 = float2(0.0, 0.0)&#xA;    let levelOfDetail: Float = 1.0&#xA;&#xA;    init(topLeft: float2,&#xA;         size: float2,&#xA;         levelOfDetail: Float) {&#xA;        self.topLeft = topLeft&#xA;        self.size = size &#xA;        self.levelOfDetail = levelOfDetail&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10227" LastEditorUserId="10227" LastEditDate="2019-02-26T09:50:00.073" LastActivityDate="2019-02-26T09:50:00.073" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8633" PostTypeId="1" AcceptedAnswerId="8634" CreationDate="2019-02-25T14:01:33.000" Score="2" ViewCount="827" Body="&lt;p&gt;I would like to segment picture of cloths in order to remove the background. The pictures come from online retailers, they usually have an homogeneous white background. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using Canny edge detector works in most of the cases, but sometimes the cloths are nearly as white as the background making the edges hard to detect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to play with the min and max parameters in opencv (python), but I can't recover the clean edge, either I do not get the surrounding of the cloths (holes in the reigion) or the the edge is noisy around the cloth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's one of the tricky example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Obe5E.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Obe5E.jpg&quot; alt=&quot;Original cloth&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/1cm5M.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1cm5M.png&quot; alt=&quot;Canny getting the contour of the cloth but noisy&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/TzYzJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TzYzJ.png&quot; alt=&quot;Canny not getting enough contour of the cloth&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Simple growing region for background detection also doesn't work well enough.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how do you detect the contour of an object if it has nearly the same color as the background?&lt;/p&gt;&#xA;" OwnerUserId="9864" LastEditorUserId="9864" LastEditDate="2019-02-25T14:35:46.433" LastActivityDate="2019-02-25T22:01:47.733" Title="Which method for detecting edges of white object on white background?" Tags="&lt;edge-detection&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8634" PostTypeId="2" ParentId="8633" CreationDate="2019-02-25T20:16:53.660" Score="4" Body="&lt;p&gt;It's quite difficult. There is so little contrast, even the JPEG compression artifacts have more contrast than the object on the background.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You would require a highly specialized deblock filter to eliminate the compression artifacts first. With knowledge about the block size of the used compression algorithm and the number of coefficients used per block you may be able to predict some of the edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For edges you could predict in the previous step, you may try to filter these from the detected edges.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;All around the shirt in the photo, there are over-swings due to an excessively  lossy compression. At the edge of each block, the over-swings form a hard edge which you also successfully detected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The block size is 8x8 pixels for JPEG (and hence also in this image), so every vertical or horizontal edge which falls directly onto position &lt;code&gt;8*n&lt;/code&gt; or &lt;code&gt;8n+1&lt;/code&gt; X or Y is most likely just a compression artifact and can be ignored.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This approach can only work though if the image hasn't been re-sampled after compression, respectively hasn't been re-compressed multiple times with potentially different block sizes. At that point, isolating the compression artifacts becomes nearly impossible.&lt;/p&gt;&#xA;" OwnerUserId="10217" LastEditorUserId="10217" LastEditDate="2019-02-25T22:01:47.733" LastActivityDate="2019-02-25T22:01:47.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8635" PostTypeId="2" ParentId="8612" CreationDate="2019-02-25T21:26:38.327" Score="1" Body="&lt;p&gt;I've actually managed to find problem thanks to @PaulHK, thanks!&#xA;I decided to pass which face I am currently working on and setting then coordinates manually per face. It is awful but it works rather good and since it is prefiltered and not done in runtime I found it good enough:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[branch] if (g_upVectorVal.z == 1.0f)&#xA;{&#xA;    input.position.z = -1.0f;&#xA;}&#xA;[branch] if (g_upVectorVal.z == -1.0f)&#xA;{&#xA;    input.position.z = 1.0f;&#xA;}&#xA;[branch] if (g_upVectorVal.x == 1.0f)&#xA;{&#xA;    input.position.z = input.position.x;&#xA;    input.position.x = -1.0f;&#xA;}&#xA;[branch] if (g_upVectorVal.x == -1.0f)&#xA;{&#xA;    input.position.z = -input.position.x;&#xA;    input.position.x = 1.0f;&#xA;}&#xA;[branch] if (g_upVectorVal.y == 1.0f)&#xA;{&#xA;    input.position.z = -input.position.y;&#xA;    input.position.y = -1.0f;&#xA;}&#xA;[branch] if (g_upVectorVal.y == -1.0f)&#xA;{&#xA;    input.position.z = -input.position.y;&#xA;    input.position.y = 1.0f;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;About discarding z coordinate too early - since I decided to pass my data through g_upVectorVal variable I has no need for view/projection space so I discarded them fully. I am just using code below for my vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PixelInputType ColorVertexShader(VertexInputType input)&#xA;{&#xA;    PixelInputType output;&#xA;&#xA;    output.position = input.position;&#xA;    input.position.w = 1.0f;&#xA;&#xA;    output.positionSV = mul(input.position, worldMatrix).xyww;&#xA;&#xA;    return output;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WQnGP.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WQnGP.jpg&quot; alt=&quot;IBL Diffuse&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2019-02-25T21:26:38.327" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8636" PostTypeId="1" CreationDate="2019-02-25T22:28:54.840" Score="1" ViewCount="179" Body="&lt;p&gt;I am trying to get a feel for how much effort I should put into this. I am building a basic 2D engine and for my use case there are only 8 textures. Each draw call in this engine currently requires that its 1 corresponding texture be bound to '0'. My question is essentially: Is there something faster than this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, what if I bound the texture for the first sprite to '0' the second to '1' etc etc. This would avoid the gpu having to &quot;switch out&quot; these textures. I am guessing that this wouldn't matter much however.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this something that is valid to be concerned about? Is it expensive for the GPU to swap out textures?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2019-02-26T22:24:17.837" Title="Are texture binds expensive?" Tags="&lt;texture&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8637" PostTypeId="2" ParentId="6137" CreationDate="2019-02-26T06:44:38.757" Score="1" Body="&lt;p&gt;The damping force you mentioned &lt;span class=&quot;math-container&quot;&gt;$f=-k \frac{\dot{l} \cdot l}{|l|} \frac{l}{|l|}$&lt;/span&gt; is a special case of &lt;span class=&quot;math-container&quot;&gt;$f=-k \dot{C} \frac{\partial C}{\partial \mathbf{x}}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;C(\mathbf{x}) &amp;amp;= \lVert\mathbf{l}\rVert-l_0 \\&#xA;\mathbf{l} &amp;amp;= \mathbf{x}_1 - \mathbf{x}_2 \\&#xA;\mathbf{\dot{l}} &amp;amp;= \mathbf{v}_1 - \mathbf{v}_2 \\&#xA;\mathbf{v} &amp;amp;= \dot{\mathbf{x}} = \begin{pmatrix}\mathbf{v}_1 \\ \mathbf{v}_2\end{pmatrix}&#xA;\end{align}&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$l_0$&lt;/span&gt; is the rest length of the spring, and &lt;span class=&quot;math-container&quot;&gt;$\mathbf{x}_1$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\mathbf{x}_2$&lt;/span&gt; are the positions of two end points.&#xA;The damping force is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{align}&#xA;\mathbf{f} &amp;amp;= -k \dot{C} \frac{\partial C}{\partial \mathbf{x}} \\&#xA;&amp;amp;= -k (\frac{\partial C}{\partial \mathbf{x}})^T \dot{\mathbf{x}} \frac{\partial C}{\partial \mathbf{x}}\\&#xA;&amp;amp;= -k (\mathbf{l}^T\mathbf{l})^{-1/2} \mathbf{l}^T \begin{pmatrix}\mathbf{I}&amp;amp; -\mathbf{I} \end{pmatrix} \dot{\mathbf{x}} (\mathbf{l}^T\mathbf{l})^{-1/2} \begin{pmatrix}\mathbf{I}&amp;amp; -\mathbf{I} \end{pmatrix}^T \mathbf{l} \\&#xA;&amp;amp;= -k (\mathbf{l}^T\mathbf{l})^{-1} \begin{pmatrix}\mathbf{l}^T&amp;amp; -\mathbf{l}^T \end{pmatrix} \mathbf{v} \begin{pmatrix}\mathbf{l} \\ -\mathbf{l} \end{pmatrix}\\&#xA;&amp;amp;= -k \frac{(\mathbf{l}\cdot \mathbf{\dot{l}}) }{\lVert \mathbf{l} \rVert^2}&#xA;\begin{pmatrix}\mathbf{l} \\ -\mathbf{l} \end{pmatrix}&#xA;\end{align}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This matches your damping force equation. The &lt;span class=&quot;math-container&quot;&gt;$-\mathbf{l}$&lt;/span&gt; part is just the force for the other particle, which has the opposite direction as expected. Bold letters are used to denote vector quantities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As mentioned in [baraff98], this damping force is along the direction &lt;span class=&quot;math-container&quot;&gt;$\frac{\partial C}{\partial \mathbf{x}}$&lt;/span&gt;,&#xA;and its magnitude is the projected component of velocity &lt;span class=&quot;math-container&quot;&gt;$\frac{\partial C}{\partial \mathbf{x}}^T \mathbf{v}=\frac{\partial C}{\partial \mathbf{x}}^T \mathbf{\dot{x}}=\dot{C}$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="120" LastActivityDate="2019-02-26T06:44:38.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8639" PostTypeId="1" AcceptedAnswerId="8641" CreationDate="2019-02-26T18:27:59.900" Score="0" ViewCount="871" Body="&lt;p&gt;gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have never seen this syntax before. Presumably glfGetProcAddres is a function, but it has the brackets behind it. Is this only possible in open gl or is my c++ trash.&lt;/p&gt;&#xA;" OwnerUserId="10235" LastActivityDate="2019-02-26T20:08:07.297" Title="This function syntax is confusing me" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8640" PostTypeId="2" ParentId="8636" CreationDate="2019-02-26T19:26:41.130" Score="2" Body="&lt;p&gt;It's hardware dependent, but as it stands, you shouldn't expect a performance drop on modern dedicated GPUs. Typically they have a pipeline state cache which fits such a small number of states easily.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only case when that cache even becomes relevant is if the workload performed in that state is insufficient to saturate the shaders, so execution of subsequent drawcalls overlaps. At that point you can eventually exceed the size of the cache if you have too many different pipeline states and effective utilization drops.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Except that when you do, you will also have trouble combining all the states into one, due to a limit on texture bindings per state and stage, so you would still end up with multiple states. Depending on the API you will have different limits, lower bound being set e.g. by OpenGL 3.x spec requiring 16 texture binding slots per shader, but realistically it doesn't even go much higher than 40-64 binding slots per shader even in high end hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At that point you are better off using a texture array instead - the level of indirection associated with that doesn't cause any significant performance penalty any more, on modern architectures. You &quot;only&quot; have to group your textures by size and tiling at that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The alternative is to bake the individual textures into a a single, large texture, which does still allow a certain level of mipmapping, but only down to a level at which pixels from different source textures don't blend. Also you loose the ability to use native tiling, but have to do it manually in shader code.&lt;/p&gt;&#xA;" OwnerUserId="10217" LastEditorUserId="10217" LastEditDate="2019-02-26T22:24:17.837" LastActivityDate="2019-02-26T22:24:17.837" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8641" PostTypeId="2" ParentId="8639" CreationDate="2019-02-26T20:08:07.297" Score="5" Body="&lt;p&gt;The signature of &lt;code&gt;glfwGetProcAddress&lt;/code&gt; is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;GLFWglproc glfwGetProcAddress(const char *);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It's a function that takes a string and returns a &lt;code&gt;GLFWglproc&lt;/code&gt;. which is defined as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef void(* GLFWglproc) (void);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Essentially, that means &lt;code&gt;glfwGetProcAddress&lt;/code&gt; is a function that takes a string and returns &lt;strong&gt;a pointer&lt;/strong&gt; to function with no parameters and no return value.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;GLADloadproc&lt;/code&gt; is a type alias defined as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;typedef void* (* GLADloadproc)(const char *name);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Essentially, this means that this is the type of a function that takes a string and returns &lt;strong&gt;a void pointer&lt;/strong&gt; (this is a type of pointer that can be safely converted to from every other type of pointer).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;in the expression&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Inside, there is the expression&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(GLADloadproc)glfwGetProcAddress&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where we have a &lt;strong&gt;type&lt;/strong&gt; in parenthesis followed by an identifier. This is known as a &lt;strong&gt;type cast&lt;/strong&gt;, it means we are taking some value of some type and converting it to some other type.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, we take our &lt;code&gt;GLADloadproc&lt;/code&gt; function that takes string and returns pointer to function and we 'disguise' it as a function that takes string and returns &lt;code&gt;void*&lt;/code&gt;. This works because we can convert any pointer to &lt;code&gt;void*&lt;/code&gt;, even in function pointer return types.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is all to end up passing it to &lt;code&gt;gladLoadGLLoader&lt;/code&gt;, which expects a value of type &lt;code&gt;GLADloadproc&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;TL;DR&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;gladLoadGLLoader&lt;/code&gt; takes a &lt;code&gt;GLADloadproc&lt;/code&gt; but we want to give it a &lt;code&gt;GLFWglproc (*)(const char *)&lt;/code&gt;. To be able to do this, we force the type system to take it anyways by using a &lt;strong&gt;type cast&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8680" LastActivityDate="2019-02-26T20:08:07.297" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8643" PostTypeId="1" CreationDate="2019-02-28T01:19:11.413" Score="3" ViewCount="121" Body="&lt;p&gt;In most cases today, image palettization consists of reducing the overall number of colors in an image to some fixed number globally. This is typically solved as a straightforward but computationally difficult clustering problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A more difficult version of this problem involves older graphics hardware where the palette is broken down into N subpalettes (e.g. of 4 colors each) and the image is broken down into XxY-pixel tiles where each tile can only use colors from a single subpalette and N &amp;lt;&amp;lt; the number of tiles. Here both the exact colors, the arrangement of colors into subpalettes, and the subpalette for each tile of the image are all unknowns that must be solved together.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How could this more difficult problem be solved, algorithmically?&lt;/p&gt;&#xA;" OwnerUserId="10243" LastActivityDate="2019-02-28T09:53:12.243" Title="Tiled Image Palettization Algorithm?" Tags="&lt;algorithm&gt;&lt;image-processing&gt;&lt;color&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8644" PostTypeId="1" CreationDate="2019-02-28T02:02:05.747" Score="2" ViewCount="78" Body="&lt;p&gt;What are the mathematical constraints required for a polyline, i.e., a piecewise linear curve, to appear as a smooth curve to human vision?  I've discovered one &lt;a href=&quot;https://www.stat.auckland.ac.nz/~ihaka/downloads/Curves-handouts.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;document&lt;/a&gt; that specifies only that the change of direction at each vertex must be less than 3°.  It seems to me that there also needs to be a limit on degrees turned per curve length, but that's a simple enhancement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main question is about how the maximum direction change angle is affected by segment length.  If you have two long segments connected at 3° then the change will be (to my eye anyway) much more visible than a 3° angle between short segments.  Is anyone aware of any studies in this area?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case it matters, my application is in polyline generalization for GIS.&lt;/p&gt;&#xA;" OwnerUserId="10244" LastActivityDate="2019-02-28T02:02:05.747" Title="Constraining a Polyline to Look Smooth" Tags="&lt;mathematics&gt;&lt;2d&gt;&lt;2d-graphics&gt;&lt;human-vision&gt;" AnswerCount="0" CommentCount="9" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8645" PostTypeId="2" ParentId="8643" CreationDate="2019-02-28T09:47:12.897" Score="2" Body="&lt;p&gt;An interesting problem. I've done a bit of work in texture compression and this sounds something like a generalisation of &lt;a href=&quot;https://en.wikipedia.org/wiki/Color_Cell_Compression&quot; rel=&quot;nofollow noreferrer&quot;&gt;Campbell et al's &quot;Color Cell Compression&quot;&lt;/a&gt;.  It's also a little like a feature we were asked to include in the Dreamcast VQ compressor so that sub-palettes could be swapped to create different colour schemes on textures. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was thus thinking that &lt;em&gt;maybe&lt;/em&gt; you could adapt a standard VQ algorithm, applied in stages, to the problem. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You say that &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;em&gt;&quot;the exact colors, the arrangement of colors into subpalettes, and the subpalette for each tile of the image are all unknowns&quot;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;but can we assume the X*Y tile size &lt;em&gt;is&lt;/em&gt; predetermined?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming that is the case, perhaps the following might be worth trying:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Guess an initial palette size for the entire image, perhaps, &#xA; &lt;span class=&quot;math-container&quot;&gt;$$Psize=(M * SizeOfEachSubpalette)$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$1 &amp;lt; M &amp;lt; N$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Use standard VQ quantisation to generate this palette and map the pixels to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Now consider each &lt;span class=&quot;math-container&quot;&gt;$X*Y$&lt;/span&gt; tile to be a &quot;super pixel&quot; with &lt;span class=&quot;math-container&quot;&gt;$Psize$&lt;/span&gt; channels. Set each channel value in the tile's &quot;super pixel&quot; to the number of pixels that mapped to the corresponding colour in our initial palette.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if in our initial palette, entry &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; is [0x11,0x21,0x31] and 5 pixels in the tile mapped to that colour, set the &lt;span class=&quot;math-container&quot;&gt;$j'th$&lt;/span&gt; component in the tile's superpixel to 5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Run a second VQ operation on the set of all &quot;super pixels&quot; using '&lt;span class=&quot;math-container&quot;&gt;$Psize$&lt;/span&gt;-dimensional space' to generate &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; &quot;palette&quot; entries. &lt;em&gt;(Actually, you don't need the 'palette' values - the VQ process is just meant as a means of partitioning the tiles into &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; sets)&lt;/em&gt;  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hopefully, this will now identify which tiles should share the same sub-palette.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) For each tile set, collect all the pixels in the tiles, and apply a 3rd VQ operation to identify the &lt;span class=&quot;math-container&quot;&gt;$SizeOfEachSubpalette$&lt;/span&gt; colours needed for all tiles in that set.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would think some sort of clever GLA/k-means process might be needed for step 2 to juggle the assignments of tiles to sub-palettes. The choice of M might also be interesting.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-02-28T09:53:12.243" LastActivityDate="2019-02-28T09:53:12.243" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8646" PostTypeId="1" CreationDate="2019-02-28T11:02:17.480" Score="2" ViewCount="73" Body="&lt;p&gt;I want to utilize shaders to not only discard fragments if they are on one side of a predefined plane but also render a contour along the intersection.&lt;/p&gt;&#xA;&lt;p&gt;My fragment shader currently does something along the lines of:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float dot = dot(world_coordinate, normalize(clipping_normal.xyz)) - clipping_normal.w;&#xA;if (dot &amp;gt; 0.0f) &#xA;    discard;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;this works but without the desired contour. I tried comparing the dot product against values close to 0.0 but this results in a contour with varying width depending on view etc...&lt;/p&gt;&#xA;&lt;p&gt;This is what I am trying to achieve. Notice that the white contour/edge of where the plane intersects the sphere is of consistent width:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/omrFH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/omrFH.png&quot; alt=&quot;cross-section&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10245" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-02-28T18:03:31.313" Title="Show the edges between the clipping plane and clipped objects" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;fragment-shader&gt;" AnswerCount="0" CommentCount="3" ClosedDate="2019-03-02T09:57:56.920" ContentLicense="CC BY-SA 4.0" />
  <row Id="8648" PostTypeId="1" CreationDate="2019-03-01T17:50:02.500" Score="5" ViewCount="177" Body="&lt;p&gt;Forward rendering is the 'classic' approach to the rendering pipeline. &#xA;Nowadays it is mostly replaced by a more flexible, deferred rendering approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did some research and had trouble finding something specific about the history of Forward Rendering.&#xA;It is my understanding, that Forward Shading evolved alongside the rendering pipeline. The pipeline provided the features for forward rendering and Forward Rendering incorporated the features of the pipeline. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering: When did a name for the classical shading approach come up and why was this specific name chosen?&lt;/p&gt;&#xA;" OwnerUserId="10254" LastEditorUserId="2479" LastEditDate="2019-03-08T16:27:44.377" LastActivityDate="2019-03-08T16:27:44.377" Title="Why is Forward Rendering/Shading named this way?" Tags="&lt;real-time&gt;&lt;shading&gt;&lt;deferred-rendering&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8649" PostTypeId="1" AcceptedAnswerId="8650" CreationDate="2019-03-02T06:02:11.513" Score="1" ViewCount="131" Body="&lt;p&gt;Currently I am learning PBR by Unity3D. I find that even I turn the smoothness to 1, I can still see the diffuse lighting effect, which does not make any sense to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine I trace a ray from my eye to the mirror, and I do importance sampling based on the material's brdf, there are only two options,  hit the light source or not. However, I find that if I set the metallic to be 0 and smoothness to 1, there will have large amount of area illuminated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1J2PH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1J2PH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9987" LastActivityDate="2019-03-02T22:57:50.327" Title="Why can I see the diffuse lighting effect on a perfect mirror?" Tags="&lt;pbr&gt;&lt;unity&gt;&lt;microfacet&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8650" PostTypeId="2" ParentId="8649" CreationDate="2019-03-02T22:57:50.327" Score="2" Body="&lt;p&gt;Dielectric materials (which is what you get when metalness is 0) don't exhibit a mirror-like effect. Think of a sheet of smooth, non-transparent plastic. Real-life mirrors are panes of glass or transparent plastic covered with a thin layer of metal. Try a white base colour (1,1,1) and full metalness (1) instead.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Hubble pointed out in his comment, Unity won't do full ray tracing for you out of the box, but it should be able to do some approximation with screen-space reflections and local reflection probes.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2019-03-02T22:57:50.327" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8652" PostTypeId="1" CreationDate="2019-03-04T19:19:10.550" Score="1" ViewCount="74" Body="&lt;p&gt;Imagine I render to an FBO some arbitrary geometry. Geometry can be rendered via single or multiple draw calls. For the sake of the question, assume I know nothing about geometry or transformation matrices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to efficiently read back the minimal screen-space bounding box of all drawn geometry after the rendering to FBO is finished.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I imagine this can be done with via use of atomics on an image (imageLoad/imageStore) or SSBO, sadly these are not available to me. Is there any other mechanism I can try?&lt;/p&gt;&#xA;" OwnerUserId="10267" LastActivityDate="2019-03-04T19:19:10.550" Title="Convey screenspace bounding box of rendering result" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8653" PostTypeId="1" CreationDate="2019-03-05T03:38:03.843" Score="0" ViewCount="279" Body="&lt;p&gt;Now the mainstream engine's approach is to use image-based lighting to achieve approximate global illumination, but such a technique seems to be only applicable to outdoor scenes.What kind of technology is used in the indoor scene to achieve global illumination?For example, in a room with natural light, or in a completely enclosed indoor environment&lt;/p&gt;&#xA;" OwnerUserId="10269" LastActivityDate="2019-03-05T12:00:31.907" Title="How Image Based Lighting is applied to indoor scene?" Tags="&lt;global-illumination&gt;&lt;pbr&gt;&lt;ibl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8654" PostTypeId="2" ParentId="8653" CreationDate="2019-03-05T12:00:31.907" Score="2" Body="&lt;p&gt;There's two main things it seems like you've not understood correctly.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;IBL is for indoor scenes and outdoor scenes&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;In the early days when IBL was hot, the Uffizi light-probe was probably the most popular for researchers. IBL works really well for indoor scenes with strong light coming from multiple directions, such as churches with stained glass. That kind of scene was the &quot;killer app&quot;, because for most outdoor scenes, skylight simulation was already a popular, fast, and useful method. Environment maps were originally popular for outdoor scenes because simulated clouds didn't &lt;em&gt;look&lt;/em&gt; right, even though the lighting was good.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The big limitation for indoor scenes is if the room is small. A light probe taken in the middle of a room won't be accurate for the corners of that room, because the light is coming from different directions. Just like with a reflection map, if your objects are moving far enough for that to be visible, you need to take multiple light probes and blend between them. This can also be a limit for outdoor scenes if the lighting is dominated by (say) the shadow of a building or tree, or a nearby artificial light.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;IBL is not a global illumination technique&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;It's more helpful to think of it as pre-baked lighting. Just as you might use a light map to bake GI computed from your static lights (with some offline technique) into the textures for your static objects, you can also have that pre-computed GI affect your dynamic objects. But it's not an approximation to full GI, because dynamic lights and objects don't contribute at all.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;So how do I use it indoors?&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;There's two ways. If you're trying to place CG objects into a real-world indoor scene, just capture a light probe of that scene exactly the same way as a real-world outdoor scene. If you're trying to light a CG scene (i.e. a room that only exists in your game), then put your scene into an offline renderer (such as a path-tracer with full GI) to create the light probe, then apply that light probe in your real-time engine.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-03-05T12:00:31.907" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8655" PostTypeId="1" AcceptedAnswerId="8656" CreationDate="2019-03-05T19:12:30.507" Score="-1" ViewCount="186" Body="&lt;p&gt;I am well aware of the existence of Blinn-Phong shading, which is a great tool when you are doing, for example, modelling algorithms and wan't to focus on the model. In this case a full BRDF result, even if fast, could make it harder to appreciate the geometry you are analysing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other end of the spectrum, we have full BRDF approximations through monte-carlo algorithms and ray traycing. Which give amazing results, but are very slow.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried to look for, but haven't found,a list of commonly used algorithms that have different levels of trade off between quality and speed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone know of a resource where I can find some algorithms, their performance and quality?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-03-06T15:44:37.510" Title="What is a list of common, cheap, real time rendering algorithms?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;algorithm&gt;&lt;real-time&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8656" PostTypeId="2" ParentId="8655" CreationDate="2019-03-05T20:07:46.410" Score="-1" Body="&lt;p&gt;For mostly offline rendering (some of those can be done in real-time, but in the majority of cases not for games, which is changing especially with NVIDIA RTX) you can refer to this: &lt;a href=&quot;https://people.mpi-inf.mpg.de/~ritschel/Papers/GISTAR.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://people.mpi-inf.mpg.de/~ritschel/Papers/GISTAR.pdf&lt;/a&gt;&#xA;At the bottom there's a very nice table that summarizes the findings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more real-time oriented stuff you can refer to this post:&#xA;&lt;a href=&quot;https://www.reddit.com/r/opengl/comments/28bs74/realtime_global_illumination_ispm_vs_cone_voxel/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.reddit.com/r/opengl/comments/28bs74/realtime_global_illumination_ispm_vs_cone_voxel/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-03-05T20:07:46.410" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8657" PostTypeId="2" ParentId="8655" CreationDate="2019-03-06T15:44:37.510" Score="0" Body="&lt;p&gt;I found a good article from 2009:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://pdfs.semanticscholar.org/09ea/c60a78c84f9048058cb9518ed30335b86169.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pdfs.semanticscholar.org/09ea/c60a78c84f9048058cb9518ed30335b86169.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-03-06T15:44:37.510" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8658" PostTypeId="1" CreationDate="2019-03-07T07:36:50.493" Score="1" ViewCount="435" Body="&lt;p&gt;I am implementing a GGX BRDF, this is the formula I used is from:&lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2rZhq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2rZhq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/z7l6j.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/z7l6j.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is my implementation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float BRDF(float3 viewDir, float roughness, float3 normal, float3 Li) {&#xA;            float3 halfDir = normalize(Li + viewDir);&#xA;            float nl = saturate(dot(normal, Li));&#xA;            float nh = saturate(dot(normal, halfDir));&#xA;&#xA;            half lv = saturate(dot(Li, viewDir));&#xA;            half lh = saturate(dot(Li, halfDir));&#xA;            half nv = abs(dot(normal, viewDir));&#xA;&#xA;            float a2 = roughness * roughness;&#xA;            float G2 = SmithGGXMaskingShadowing(nl, nv, a2);&#xA;&#xA;            float D = GGX(nh, roughness);&#xA;            return G2 * D /(4 * abs(nv) * abs(nl));&#xA;        }&#xA;&#xA;&#xA;float SmithGGXMaskingShadowing(float NdotL, float NdotV, float a2)&#xA;        {&#xA;&#xA;            float denomA = NdotV * sqrt(a2 + (1.0f - a2) * NdotL * NdotL);&#xA;            float denomB = NdotL * sqrt(a2 + (1.0f - a2) * NdotV * NdotV);&#xA;&#xA;            return 2.0f * NdotL * NdotV / (denomA + denomB);&#xA;        }&#xA;&#xA;float GGX(float NdotH, float a) {&#xA;            float a2 = sqr(a);&#xA;            return a2 / (UNITY_PI * sqr(sqr(NdotH) * (a2 - 1) + 1));&#xA;        }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I assume the fresnel term is constant: 1. However, I found that my BRDF sometimes give me number greater than 1.&lt;/p&gt;&#xA;" OwnerUserId="9987" LastActivityDate="2019-03-07T07:36:50.493" Title="GGX BRDF is greater than 1?" Tags="&lt;brdf&gt;&lt;pbr&gt;&lt;ggx&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8660" PostTypeId="1" CreationDate="2019-03-07T11:58:51.057" Score="2" ViewCount="36" Body="&lt;p&gt;I'm reading &lt;a href=&quot;https://www.cl.cam.ac.uk/~rkm38/pdfs/mantiuk06pfcphdri.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; and one thing sticks out at me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say I use the approximate transducer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;R = 54.09288 ·G^0.41850  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then I scale it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;R̂ = R * l&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Then I go back to  Ĝ :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Ĝ  =  7.2232 · 10^−5 · R̂  ^2.3895&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Combining these 3 calculations, we get:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Ĝ  =  7.2232 · 10^−5 · R̂  ^2.3895&#xA;   =  7.2232 · 10^−5 · (R*l)  ^2.3895 &#xA;   =  7.2232 · 10^−5 · R  ^2.3895 * l  ^2.3895 &#xA;   =  7.2232 · 10^−5 · (54.09288 ·G^0.41850)  ^2.3895 * l  ^2.3895 &#xA;   = G *  l  ^2.3895&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here, &lt;code&gt;l  ^2.3895&lt;/code&gt; is a constant. So the entire contrast mapping procedure appears to amount to a linear scaling of the physical contrast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OTOH, in the paper, it says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Since the contrast response R is perceptually linearized, scaling effectively enhances low physical contrast W, for which we are the most sensitive, and compresses large contrast magnitudes, for which the sensitivity is much lower.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This seems to contradict what I wrote above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="3085" LastActivityDate="2019-03-07T11:58:51.057" Title="Mantiuk's contrast mapping seems to amount to a gamma correction" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8661" PostTypeId="1" CreationDate="2019-03-07T15:41:08.497" Score="3" ViewCount="81" Body="&lt;p&gt;We are developing a PPI plot for a radar system, similar to the following: &lt;a href=&quot;https://i.stack.imgur.com/lGMg2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lGMg2.png&quot; alt=&quot;http://radar-review.blogspot.com/2014/04/&quot;&gt;&lt;/a&gt;&#xA;&lt;strong&gt;NOTE: 1 radial is defined as a single slice of data within the circle, and 1 range gate is defined as a single point along a radial.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Our application must operate in real time, with large throughput and with a varying number of range gates per radial. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have two implementations at the moment, both which stream radials to the GPU as vertex and/or texture data. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One version defines each range gate as separate primitives, then colors them using vertex coloring. The problem here is that the vertex buffer size must be rather large to accommodate a suitable amount of radials / range gates; this memory is not something we can necessarily rely on.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am exploring another option, which generates one quad to represent each radial, then colors the range gates using texture mapping. The range gate texture buffer is a large 2D texture (2D to increase the maximum texture buffer size); 1D subsets of this texture are mapped to radials represent range gates. The problem with this method is that when a large number of fragments are being processed, each must perform a texture lookup to determine its color, which is wasteful since most fragments are redundant. This problem is compounded when zooming in, as every pixel in the window must sample the texture. The program's GPU usage skyrockets in these instances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've wondered if maybe it would be possible to sample each radial's 1D subset at the vertex level (since all vertices share a single 1D texture) then pass the sampled version to the fragment shader which then sample the subset. Each radial can have up to a thousand unique color samples. This would theoretically reduce the number of texture reads, but of course I don't even know if it's possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an some way to optimize this process, or perhaps a way to reimagine the software that avoids some of these bottlenecks? &lt;/p&gt;&#xA;" OwnerUserId="10286" LastActivityDate="2019-03-07T15:41:08.497" Title="Trying to optimize texture mapping" Tags="&lt;texture&gt;&lt;fragment-shader&gt;" AnswerCount="0" CommentCount="17" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8662" PostTypeId="1" CreationDate="2019-03-07T18:02:09.673" Score="2" ViewCount="106" Body="&lt;p&gt;&lt;strong&gt;Many hair simulations render their hair as lines (usually splines). Since hair is a really thin object.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;if the hair is braided, rather than having thin infinitesimally small cylinders, you have something much thicker and with more volume per individual strand.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The line method is  efficient, since lines are computationally cheap to render.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However for braids it would seem you would need triangles, which would imply a high concentration of really small triangles on each individual braid, which sounds very expensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any algorithms that attempt at dealing with this issue? Particularily ones that are good at trading quality for memory useage?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="209" LastEditDate="2019-03-18T16:09:59.440" LastActivityDate="2019-03-18T16:09:59.440" Title="How to model braids?" Tags="&lt;rendering&gt;&lt;mesh&gt;&lt;model&gt;&lt;particles&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8663" PostTypeId="2" ParentId="8548" CreationDate="2019-03-07T22:42:40.907" Score="2" Body="&lt;p&gt;I've seen no answer to my question. But after lots of experimentation and further study of Apple documentation for clues I have figured out how to capture GPU generated frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I gave up on the attempt to have the shader write to the screen and an offscreen buffer in the same render pass. The odd (and undocumented as far as I can tell) behavior of MTKView in which the onscreen view occupies only a portion of the original area of the screen. I think this a bug in MTKView. It seems to act as if each attachment should appear somewhere on the screen. MTKView is not checking to see if the attachments are all on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since MTKView calls the draw() function 60 times per second I decided to alternate. One draw() goes to the screen and the following draw() goes to my off screen buffer. This gives me a 30 Hz frame rate for the captured video frames, which is what I wanted anyway. I can watch the screen and see what will appear in the video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the video capture draw() calls I now define the MTLTextureDescriptor in this way:&#xA;     &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let offScreenPixelFormat = MTLPixelFormat.rgba32Float   // 32Float is convenient for AVFoundation video recording&#xA;let offScreenBufferDescriptor = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: offScreenPixelFormat,&#xA;          width: offW, height: offH, mipmapped: false)&#xA;offScreenBufferDescriptor.usage = [.shaderWrite, .renderTarget]&#xA;offScreenBufferDescriptor.storageMode = .managed&#xA;offScreenBufferDescriptor.resourceOptions = [.storageModeManaged]&#xA;offScreenBufferDescriptor.textureType = MTLTextureType.type2D&#xA;offScreenTextureBuffer = device.makeTexture(descriptor:    offScreenBufferDescriptor)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It turns out this still did not work. I got nothing back from the GPU. That is, I got nothing back until I added this code to the end of the commandBuffer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;  &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  let blitCommandEncoder = commandBuffer.makeBlitCommandEncoder()&#xA;  blitCommandEncoder?.synchronize(resource: offScreenTextureBuffer!)&#xA;  blitCommandEncoder?.endEncoding()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This causes the GPU memory version of the offScreenTextureBuffer to be copied back to the CPU memory version. I figured this out by looking at the Apple documentation. Like all Apple documentation, it doesn't tell you why you might want to synchronize. But you definitely do need to do this. I have seen several online code examples where this is NOT done and they claim to get data back from the GPU.&#xA;I tried one example code without the synchronize command and nothing was returned. So I assume the requirement to synchronize is a new feature and the online code is just out of date. It would be nice if the Apple documentation made it clear this is now a requirement.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With these changes I can retrieve GPU frames. I have created a short video using GPU-generated frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anyone is interested in seeing a complete code sample let me know.&lt;/p&gt;&#xA;" OwnerUserId="10117" LastActivityDate="2019-03-07T22:42:40.907" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8664" PostTypeId="1" AcceptedAnswerId="8671" CreationDate="2019-03-08T18:05:11.350" Score="1" ViewCount="139" Body="&lt;p&gt;I am creating Forward-Rendering DX11 engine and I have some troubles with shadow-mapping algorithm as it doesn't work as supposed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/N2ZcY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N2ZcY.png&quot; alt=&quot;Shadowmap texture&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ehipa.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ehipa.png&quot; alt=&quot;Rendered scene&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see - shadow is peter-panning and looks totally not releated. Basically as I have tested, comparision in PixelShader has no effect. Only projected shadowmap texture is returned, &lt;em&gt;if statement&lt;/em&gt; doesn't do anything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;MyVertexShader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PixelInputType ColorVertexShader(VertexInputType input)&#xA;{&#xA;    PixelInputType output;&#xA;    float4 worldPosition;&#xA;&#xA;    input.position.w = 1.0f;&#xA;    worldPosition = mul(input.position, worldMatrix);&#xA;    output.normal = input.normal;&#xA;&#xA;    // Calculate the position of the vertex against the world, view, and projection matrices.&#xA;    output.position = mul(input.position, worldMatrix);&#xA;    output.position = mul(output.position, viewMatrix);&#xA;    output.position = mul(output.position, projectionMatrix);&#xA;&#xA;    //Calculate object seen by light&#xA;    output.lightViewPosition = mul(input.position, worldMatrix);&#xA;    output.lightViewPosition = mul(output.lightViewPosition, g_lightViewMatrix);&#xA;    output.lightViewPosition = mul(output.lightViewPosition, g_lightProjectionMatrix);&#xA;&#xA;    //Calculate light-object vector&#xA;    output.lightPos = g_lightPosition.xyz - worldPosition.xyz;&#xA;    output.lightPos = normalize(output.lightPos);&#xA;&#xA;    return output;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;MyPixelShader:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 ColorPixelShader(PixelInputType input) : SV_TARGET&#xA;{&#xA;    float4 color = float4(0.0, 0.0, 0.0, 1.0);&#xA;    float depthValue;&#xA;    float lightDepthValue;&#xA;    float bias = 0.001f;&#xA;    float4 textureColor = float4(1.0, 1.0, 1.0, 1.0);&#xA;    float4 ambientColor = float4(1.0, 0.0, 1.0, 1.0);&#xA;    float2 tex;&#xA;    float lightIntensity = 0.0f;&#xA;&#xA;    input.lightViewPosition.xyz /= input.lightViewPosition.w;&#xA;&#xA;    tex.x = input.lightViewPosition.x / 2.0f + 0.5f;&#xA;    tex.y = -input.lightViewPosition.y / 2.0f + 0.5f;&#xA;&#xA;    return depthValue = shadowMap.Sample(SampleType, tex).r;&#xA;    color = float4(depthValue, depthValue, depthValue, 1.0f);&#xA;&#xA;    lightDepthValue = input.lightViewPosition.z;// / input.lightViewPosition.w;&#xA;    lightDepthValue = lightDepthValue - bias;&#xA;    if(lightDepthValue &amp;lt; depthValue)&#xA;    {&#xA;        lightIntensity = saturate(dot(input.normal, input.lightPos));&#xA;&#xA;        if(lightIntensity &amp;gt; 0.0f)&#xA;        {&#xA;            // Determine the final diffuse color based on the diffuse color and the amount of light intensity.&#xA;            color += (ambientColor * lightIntensity);&#xA;&#xA;            // Saturate the final light color.&#xA;            color = saturate(color);&#xA;        }&#xA;    }&#xA;    return color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2019-03-14T18:03:04.743" Title="ShadowMap peter-panning and wrong direction" Tags="&lt;shadow&gt;&lt;directx11&gt;&lt;shadow-mapping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8666" PostTypeId="1" CreationDate="2019-03-09T00:55:35.870" Score="0" ViewCount="130" Body="&lt;p&gt;I'm interested in simulating the way a laser line deforms when it strikes an object and runs along the surface of it. Which concepts would be involved? Is there any 3D modeling software out there that does this already? I'd like to implement it into my Eyeshot-based program at some point.&lt;/p&gt;&#xA;" OwnerUserId="10290" LastActivityDate="2019-04-26T05:36:09.783" Title="How to simulate a line laser diode?" Tags="&lt;raytracing&gt;&lt;lighting&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8667" PostTypeId="1" AcceptedAnswerId="8668" CreationDate="2019-03-10T13:09:01.627" Score="1" ViewCount="306" Body="&lt;p&gt;The &lt;a href=&quot;https://anteru.net/blog/2018/intro-to-compute-shaders/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt; says that L1 cache is shared by work items in the same work group(aka. SM) and L2 cache is shared by different work groups.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Direct3D, it seems that a thread group (which is specified by &lt;code&gt;numthread(x, y, z)&lt;/code&gt;) is mapped to multi work groups, and &lt;code&gt;groupshared&lt;/code&gt; could be accessed by all threads of the thread group (which belong to different work groups).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is &lt;code&gt;groupshared&lt;/code&gt; the L2 cache of GPU? If it is, could I manipulate L1 cache directly in Direct3D?&lt;/p&gt;&#xA;" OwnerUserId="6407" LastActivityDate="2019-03-11T00:37:35.983" Title="Is `groupshared` memory stored in L2 cache of GPU?" Tags="&lt;directx11&gt;&lt;gpgpu&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8668" PostTypeId="2" ParentId="8667" CreationDate="2019-03-10T17:28:59.783" Score="5" Body="&lt;p&gt;There seems to be some confusion of terminology here. In Direct3D, you have &lt;em&gt;threads&lt;/em&gt; and &lt;em&gt;thread groups&lt;/em&gt;. &quot;work item&quot; and &quot;work group&quot; are generally encountered in OpenCL terminology, where a &quot;work item&quot; would be what a &lt;em&gt;thread&lt;/em&gt; is in Direct3D and a &quot;work group&quot; corresponds to a Direct3D &lt;em&gt;thread group&lt;/em&gt;. &lt;code&gt;groupshared&lt;/code&gt; memory is memory accessible to all threads that are part of the same thread group.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is unclear what exactly you mean by &quot;manipulating L1 cache directly&quot;. A cache is a hardware component that is used to transparently optimize memory access. The word &quot;transparent&quot; is crucial here. While, at the hardware level, caches necessarily contain some form of memory, they are generally not explicitly &quot;accessible&quot; as a region of storage. You can't have a pointer that points into a cache. You can have a pointer that points into memory. Memory accesses will typically go through a cache, i.e., any memory request will be handed off to the next cache, which can then check whether it can serve the request directly or has to go further down the memory hierarchy. There's more to a cache than just the memory it uses to cache stuff. A cache also contains additional logic for managing the cache on top of just the storage itself. Caches are implicit by nature. As you manipulate memory, you will typically also cause some caches to manipulate their memory along the way. But you generally can't &quot;manipulate&quot; a cache directly in the sense of explicitly defining what is when to be stored where in the cache. As soon as you can explicitly point into it and read/write from/to it, it kinda stops being a cache and starts being just some form of storage. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, &lt;code&gt;groupshared&lt;/code&gt; memory is generally located in fast on-chip storage just like caches are. The whole point of &lt;code&gt;groupshared&lt;/code&gt; memory is to take advantage of the knowledge that certain threads reside on the same part of the chip to allow them to communicate faster. And on some hardware (e.g., most of the recent NVIDIA architectures), &lt;code&gt;groupshared&lt;/code&gt; memory and the L1 cache will actually use the same physical memory. However, that just means that one part of that memory is used as &quot;normal&quot; memory, accessed directly via addressing through some load-store-unit, while another part is used by the L1 cache to cache stuff&amp;hellip;&lt;/p&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-03-11T00:37:35.983" LastActivityDate="2019-03-11T00:37:35.983" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8669" PostTypeId="2" ParentId="8666" CreationDate="2019-03-11T11:36:28.750" Score="1" Body="&lt;p&gt;It's a variant to &lt;a href=&quot;https://en.wikipedia.org/wiki/Projective_texture_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;projective texture mapping&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simple way to do this in the fragment shader by using the position of the fragment to decide whether it is close enough to the plane of the laser to light up.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-03-11T11:36:28.750" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8671" PostTypeId="2" ParentId="8664" CreationDate="2019-03-13T17:57:25.150" Score="1" Body="&lt;p&gt;I found out that simply removing minus sign in shader in converting coords to [0, 1] solved direction problem. But scale is still off - here is an example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/v6lK0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v6lK0.png&quot; alt=&quot;Wrong scale - peter panning&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void LightClass::GenerateViewMatrix()&#xA;{&#xA;    XMVECTOR eyePos = { m_position.x, m_position.y, m_position.z };&#xA;    XMVECTOR focusPos = { m_lookAt.x, m_lookAt.y, m_lookAt.z };&#xA;    XMVECTOR upVec = { 0, 1, 0 };&#xA;&#xA;    m_viewMatrix = XMMatrixLookAtLH(eyePos, focusPos, upVec);&#xA;}&#xA;&#xA;void LightClass::GenerateProjectionMatrix(float screenDepth, float screenNear)&#xA;{&#xA;    float fieldOfView = (float)3.14f / 2.0f;&#xA;    float screenAspect = 16.0f / 9.0f;&#xA;&#xA;    m_projectionMatrix = XMMatrixPerspectiveFovLH(fieldOfView, screenAspect, screenNear, screenDepth);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit [Actual solution - ignore previous posts]:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I followed PaulHK solution (thanks, it's second time you've helped me) about checking once again View/Projection matrix. Basically my calculations were wrong. I debugged my convertions from model to lightspace and changed &lt;strong&gt;Vertex Shader&lt;/strong&gt; from:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;output.lightViewPosition = mul(input.position, worldMatrix);&#xA;output.lightViewPosition = mul(output.lightViewPosition, g_lightViewMatrix);&#xA;output.lightViewPosition = mul(output.lightViewPosition, g_lightProjectionMatrix);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To correct:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;matrix lightViewProj = mul(g_lightProjectionMatrix, g_lightViewMatrix);&#xA;output.lightViewPosition = mul(input.position, lightViewProj);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;That simple changed fixed my results. With simple &lt;strong&gt;Pixel shader&lt;/strong&gt; code below I am getting this results:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;input.lightViewPosition.xyz /= input.lightViewPosition.w;&#xA;&#xA;tex.x = input.lightViewPosition.x / 2.0f + 0.5f;&#xA;tex.y = -input.lightViewPosition.y / 2.0f + 0.5f;&#xA;&#xA;depthValue = shadowMap.Sample(SampleType, tex).r;&#xA;return color = float4(depthValue, depthValue, depthValue, 1.0f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ylu0o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ylu0o.png&quot; alt=&quot;Correct shadow-map&quot;&gt;&lt;/a&gt;&#xA;However, even if it seems correct, my suspicion is that I need to compare my shadowmap to light Z-buffer so I modified my Pixel Shader and added little tint:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;input.lightViewPosition.xyz /= input.lightViewPosition.w;&#xA;&#xA;tex.x = input.lightViewPosition.x / 2.0f + 0.5f;&#xA;tex.y = -input.lightViewPosition.y / 2.0f + 0.5f;&#xA;&#xA;depthValue = shadowMap.Sample(SampleType, tex).r;&#xA;color = float4(depthValue, depthValue, depthValue, 1.0f);&#xA;&#xA;lightDepthValue = input.lightViewPosition.z - bias;&#xA;if(lightDepthValue &amp;lt; depthValue)&#xA;{&#xA;    lightIntensity = saturate(dot(input.normal, input.lightPos));&#xA;&#xA;    if(lightIntensity &amp;gt; 0.0f)&#xA;    {&#xA;        // Determine the final diffuse color based on the diffuse color and the amount of light intensity.&#xA;        color += (ambientColor * lightIntensity);&#xA;&#xA;        // Saturate the final light color.&#xA;        color = saturate(color);&#xA;    }&#xA;}&#xA;return color;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I may not be right, but without this checking, you would get errors with more complicated shadows. Because my previous PixelShader code basically just project shadowmap on plane without any actual depth checking. Therefore it would lay shadowmap on everything it can without even checking if that's correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/X5fzu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X5fzu.png&quot; alt=&quot;Correct shadow-map with depth checking&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2019-03-14T18:03:04.743" LastActivityDate="2019-03-14T18:03:04.743" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8672" PostTypeId="1" AcceptedAnswerId="8674" CreationDate="2019-03-13T19:23:22.000" Score="-1" ViewCount="150" Body="&lt;p&gt;I have no prior experience with any other graphics low level libraries and I have barely any clue how shaders work, any book related to shadings is bloated with opengl code and is demoralizing.&lt;/p&gt;&#xA;" OwnerUserId="10307" LastActivityDate="2019-03-14T06:28:48.133" Title="Where should I learn shaders as a vulkan user?" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8674" PostTypeId="2" ParentId="8672" CreationDate="2019-03-14T06:28:48.133" Score="5" Body="&lt;p&gt;Perhaps you should begin with classic opengl shaders in a more friendly enviroment. &lt;a href=&quot;https://www.shadertoy.com/&quot; rel=&quot;noreferrer&quot;&gt;ShaderToy&lt;/a&gt; is a great community where you'll find tons of tutorials, code examples, masterpieces and great experts that comment everyday.&lt;/p&gt;&#xA;" OwnerUserId="9908" LastActivityDate="2019-03-14T06:28:48.133" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8676" PostTypeId="1" AcceptedAnswerId="8679" CreationDate="2019-03-14T20:13:19.960" Score="1" ViewCount="330" Body="&lt;p&gt;I am following the &lt;b&gt;&quot;Ray Tracing - the Rest of your Life&quot;&lt;/b&gt; book by Peter Shirley and I am facing some troubles in the implementation of Monte Carlo importance sampling, and  Direct light sampling.&lt;br&gt;&#xA;Monte Carlo theory is clear to me. During the implementation, the way rays are scattered does not actually change and remains random. What changes looks to be the contribution of each ray.&lt;br&gt;&#xA;So my first question is:&lt;br&gt;&lt;br&gt;&#xA;&lt;i&gt;Do I understand this correctly? Rays, after hitting a surface, are still scattered randomly, but the value of the color is adjusted based on the probability of that direction?&lt;/i&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;b&gt;For those familiar with the book&lt;/b&gt; &lt;br&gt;&#xA;When the author implements the Direct light sampling, he modifies the function &lt;i&gt;color()&lt;/i&gt;, while we previously modified &lt;i&gt;scatter()&lt;/i&gt; and &lt;i&gt;scattering_pdf()&lt;/i&gt;. This way, &lt;i&gt;scatter()&lt;/i&gt; and &lt;i&gt;scattering_pdf()&lt;/i&gt; are sampling based on a specific pdf - proportional to cos(theta) - while &lt;i&gt;color()&lt;/i&gt; introduces a new pdf related to the direction of the light. It is not clear to me how these two things coexist, and if I am supposed to disregard the previous changes to &lt;i&gt;scatter()&lt;/i&gt; and &lt;i&gt;scattering_pdf()&lt;/i&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-03-15T22:06:21.530" Title="Monte Carlo Importance Sampling" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8677" PostTypeId="1" CreationDate="2019-03-15T17:14:32.567" Score="1" ViewCount="95" Body="&lt;p&gt;I know this question may be a little basic, but still I haven't found an answer for it anywhere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say I have a normalized cube; vertices at (+-0.5, +-0.5, +-0.5)&#xA;If I render it on screen (omitting the Z axis), I'll see a square.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I rotate it along the Z axis with 45 degrees, I'll see two rectangles:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EulxU.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EulxU.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I would like to see it with perspective, so it should look something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4bxmR.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4bxmR.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the matrix multiplication that transfers the original points to the rotated+perspective points?&lt;/p&gt;&#xA;" OwnerUserId="10319" LastActivityDate="2019-03-15T18:08:01.363" Title="Simple Two Point Perspective of a Cube" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8678" PostTypeId="2" ParentId="8677" CreationDate="2019-03-15T18:08:01.363" Score="2" Body="&lt;p&gt;Your first image employs an orthographics projection, while the second uses a perspective projection. You can look up the perspective matrix derivation in: &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.songho.ca/opengl/gl_projectionmatrix.html&lt;/a&gt; Note that there's a division at the end to account for perspective projection being a non-linear transformation.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-03-15T18:08:01.363" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8679" PostTypeId="2" ParentId="8676" CreationDate="2019-03-15T22:06:21.530" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;During the implementation, the way rays are scattered does not actually change and remains random.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Actually the way rays are scattered does change, specifically when you sample a light. In chapter 8 he makes a mixture pdf in order to sample either the light or the bsdf.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;What changes looks to be the contribution of each ray.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This does change, but not specifically due to the sampling of the lights but rather due to importance sampling. But that was already introduced in chapter 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically you have the following:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$I = \int_{\Omega}f(x)\,dx = \int_{\Omega}\frac{f(x)}{p(x)}p(x)\,dx = E\left[\frac{f(X)}{p(X)}\right] = \frac{1}{N}\sum_{i=1}^{N}E\left[\frac{f(X_i)}{p(X_i)}\right] \approx \frac{1}{N}\sum_{i=1}^{N}\frac{f(x_i)}{p(x_i)}$$&lt;/span&gt;&#xA;Where &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$X_i$&lt;/span&gt; are distributed according to the probability density &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;.&#xA;As evident the main difference to the Monte Carlo formulation you are probably used to is the &lt;span class=&quot;math-container&quot;&gt;$p(x)$&lt;/span&gt; factor, and the fact that &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt; are not uniformly sampled but rather sampled according to &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;. Note that for uniform sampling &lt;span class=&quot;math-container&quot;&gt;$p(x)=1$&lt;/span&gt; and the equality still holds. Thus this is simply a generalization.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-03-15T22:06:21.530" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8681" PostTypeId="1" CreationDate="2019-03-18T06:45:52.623" Score="1" ViewCount="215" Body="&lt;p&gt;I have many objects that store their color values. At the moment I'm storing them as vec4 values, that is four 4-byte values for RGBA, mainly because this is how the shader reads them. I was thinking of storing these colors as a vector or 4 unsigned single-byte integers. Anyway, with storing color values as one byte integers I can have a combination of 255^3, which is 16,581,375.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a couple of question about this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I store the red color as 128, this ends up being a floating point value of about 0.502, and a color of 129 ends up being a floating point value of about 0.506. My question is whether there is any discernible difference to speak of, either consciously or unconsciously between the intensity of a color being 0.502 or 0.506, or shades in between. Does this depend on the limitations of your graphics adaptor or video display? Or is there simply no discernible difference that one could tell with the eye for a value in between those two?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further, I have a similar inquiry about things like color changes over time. If for example we use a 0 to 255 value to do a fade to black over a significant period of time, would one integer jumps on the 0-255 scale in terms of brightness, which would result in about 0.004 in floating point on each change, be detectable as opposed to calculating the change in floating point to begin with?  &lt;/p&gt;&#xA;" OwnerUserId="10333" LastActivityDate="2019-03-18T19:14:20.567" Title="Some questions about working in 0-255 integers instead of single precision floating point colors" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8683" PostTypeId="2" ParentId="8681" CreationDate="2019-03-18T19:14:20.567" Score="4" Body="&lt;p&gt;First, a quick correction:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;storing color values as one byte integers I can have a combination of 255^3&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You mean &lt;span class=&quot;math-container&quot;&gt;$256^3$&lt;/span&gt;. There are 256 eight-bit integers (including zero), not 255. But here comes the more fundamental thing you need to understand.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If I store the red color as 128, this ends up being a floating point value of about 0.502&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It doesn't end up being a floating-point value at all: it ends up as an 8 bit (or possibly 10 bit) integer on your display. Whatever extra precision you had in the floats to start with is thrown away when the final colour goes into the framebuffer. So the rest of what I'm going to say shouldn't influence your choice of &lt;em&gt;what&lt;/em&gt; to store, because everything will end up as 8 bit colour channels.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that doesn't mean there's never any value in using a higher-precision number earlier on. More precision in the intermediate data means you'll get the full precision in your output format. e.g. if you start out with these normalized integers, and you multiply them all by 2 in the shader, you'll only end up with the even-numbered integers in your output: you lost half of your precision.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for the question you really asked, about visible differences, it's easy to test that in live conditions. Just make a grey colour gradient from &lt;span class=&quot;math-container&quot;&gt;$(0, 0, 0)$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$(1, 1, 1)$&lt;/span&gt; in whatever representation you like (floats or normalized integers) and show it in place of your real computation. If you see &lt;a href=&quot;https://en.wikipedia.org/wiki/Mach_bands&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mach bands&lt;/a&gt; on your gradient, then yes, you can tell the difference between adjacent intensities. In general, for adults with normal sight and 8 bit-per-channel RGB in common lighting conditions, there &lt;em&gt;is&lt;/em&gt; a visible difference in a grey gradient. That doesn't mean there's a visible difference between every adjacent pair: the eye is less sensitive to contrast in red and blue than in green, and less sensitive to changes in hue, so it strongly depends on the colours involved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there are techniques to make the differences invisible most of the time. Check out &lt;a href=&quot;https://stackoverflow.com/a/12894053/967945&quot;&gt;my answer explaining what sRGB is for&lt;/a&gt; on SO for some examples.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-03-18T19:14:20.567" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8684" PostTypeId="1" CreationDate="2019-03-18T21:25:36.497" Score="0" ViewCount="365" Body="&lt;p&gt;I tried to follow Nathan Reed post &lt;a href=&quot;http://www.reedbeta.com/blog/antialiasing-to-splat-or-not/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Antialiasing: To Splat Or Not&lt;/a&gt; to implement splat method. The image I am getting thorugh the Lanczos filter is very different than Nathan. I do not understand where the problem is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://en.wikipedia.org/wiki/Lanczos_resampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia page&lt;/a&gt; Lanczos filter is defined as either of below formulas:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UEPNb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UEPNb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oqq67.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oqq67.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://gist.github.com/Reedbeta/893b63390160e33ddb3c&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nathan implementation&lt;/a&gt; seems to have missed a division by pi**2 and a multiplication by filter radius.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;elif options.kernel == 'lanczos':&#xA;        weight = &#xA;          (np.sin(np.pi * sampleOffsetX) * np.sin(np.pi * sampleOffsetY) *&#xA;           np.sin(np.pi * sampleOffsetX / options.radius) * &#xA;           np.sin(np.pi * sampleOffsetY / options.radius) /                           &#xA;          (sampleOffsetX**2 * sampleOffsetY**2))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is my code which borrowed most of the filter implementation from pbrt code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;private void btn_Render_Click(object sender, EventArgs e)&#xA;{&#xA;    Random rand = new Random();&#xA;    int samples = 16;&#xA;    ImageFilm film = new ImageFilmSplat(pictureBox1.Width, pictureBox1.Height);&#xA;    film.Filter = new SincFilter(tau: 4, width: 4);&#xA;&#xA;    for (int i = 0; i &amp;lt; film.Width; i++)&#xA;    {&#xA;        for (int j = 0; j &amp;lt; film.Height; j++)&#xA;        {&#xA;            EvaluatePixel(i, j, samples, rand, film);&#xA;        }&#xA;    }&#xA;&#xA;    for (int i = 0; i &amp;lt; film.Width; i++)&#xA;    {&#xA;        for (int j = 0; j &amp;lt; film.Height; j++)&#xA;        {&#xA;            Pixel px = film.GetPixel(i, j);&#xA;&#xA;            if (px.filterWeightSum != 0)&#xA;            {&#xA;                px.radiance = px.radiance / px.filterWeightSum;&#xA;&#xA;                film.SetPixel(i, j, px);&#xA;            }&#xA;        }&#xA;    }&#xA;&#xA;    pictureBox1.Image = film.GetImage();&#xA;}&#xA;&#xA;void EvaluatePixel(int i, int j, int nSamples, Random rand, ImageFilm film)&#xA;{&#xA;    Vector halfpixel = new Vector(.5 / film.Width, .5 / film.Height, 0);&#xA;&#xA;    //all samples between [0,1]&#xA;    Sample[] samples = sampler.Random(rand, nSamples);&#xA;&#xA;    for (int n = 0; n &amp;lt; nSamples; n++)&#xA;    {&#xA;        //set sample coord at centre of the pixel&#xA;        double cx = ((double)i / film.Width) + halfpixel.X;&#xA;        double cy = ((double)j / film.Height) + halfpixel.Y;&#xA;&#xA;        //jitter the centre&#xA;        cx += ((samples[n].X * 2) - 1) * halfpixel.X&#xA;        cy += ((samples[n].Y * 2) - 1) * halfpixel.Y&#xA;&#xA;        //sample the function&#xA;        double f = func(cx, cy);&#xA;&#xA;        film.AddToPixel(i, j, new Vector(f));&#xA;    }&#xA;}&#xA;&#xA;//ImageFilm class&#xA;public void AddToPixel(int i, int j, Vector radiance)&#xA;{ &#xA;    //splat the value to neighbor pixels&#xA;    //find neighbour pixels based on filter width&#xA;    int x0 = (int)Math.Max(0, i - Filter.Width);&#xA;    int x1 = (int)Math.Min(Width - 1, i + Filter.Width);&#xA;    int y0 = (int)Math.Max(0, j - Filter.Width);&#xA;    int y1 = (int)Math.Min(Height - 1, j + Filter.Width);&#xA;&#xA;    for (int x = x0; x &amp;lt;= x1; x++)&#xA;    {&#xA;        for (int y = y0; y &amp;lt;= y1; y++)&#xA;        {&#xA;            double weight = this.Filter.eval(x - i, y - j);&#xA;&#xA;            Pixel pxl = GetPixel(x, y);&#xA;&#xA;            pxl.radiance += radiance * weight;&#xA;            pxl.filterWeightSum += weight;&#xA;&#xA;            SetPixel(x, y, pxl);&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;public class SincFilter&#xA;{&#xA;    private double tau;&#xA;&#xA;    public SincFilter(double tau1, double width)&#xA;    {&#xA;        Width = width;&#xA;        tau = tau1;&#xA;    }&#xA;    double Sinc(double x)&#xA;    {&#xA;        x = Math.Abs(x);&#xA;        if (x &amp;lt; 1e-5) return 1;&#xA;        return Math.Sin(Math.PI * x) / (Math.PI * x);&#xA;    }&#xA;    double WindowedSinc(double x, double radius)&#xA;    {&#xA;        x = Math.Abs(x);&#xA;        if (x &amp;gt; radius) return 0;&#xA;        return Sinc(x) * Sinc(x / tau);&#xA;    }&#xA;    public override double eval(double x, double y)&#xA;    {&#xA;        return WindowedSinc(x, Width) * WindowedSinc(y, Width);&#xA;    }&#xA;}&#xA;&#xA;double func(double x, double y)&#xA;{&#xA;    double minPeriod = 2e-5;&#xA;    double maxPeriod = 0.2;&#xA;&#xA;    double period = minPeriod + (maxPeriod - minPeriod) * (y * y);&#xA;    double phase = x / period;&#xA;    phase -= Math.Floor(phase);&#xA;&#xA;    return Math.Round(phase);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is Nathan image : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/R5VlB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/R5VlB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is mine for lanczos filter width 4, tau 4&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/e3thP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e3thP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My implementation is quite noisy for some reason. It doesn't look any better than box filter.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2019-03-18T21:25:36.497" Title="Lanczos filter implementation issue" Tags="&lt;image-processing&gt;&lt;interpolation&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8685" PostTypeId="1" CreationDate="2019-03-20T16:18:26.780" Score="1" ViewCount="56" Body="&lt;p&gt;Assume I have a texture with a repeating line pattern. The lines are exactly 2 texels wide (really thin). Ans very spaced out (50 texels in between each line).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am now struggling with the minification issue. The goal is to have as many of these lines to show up when rendering them in a textured map plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using OpenGL's standard mipmaping is not good enough, most of the lines are blurred out of existence, especially when the lines have certain orientations with the screen. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming the lines are white and the background is black.&#xA;A slightly better technique is to, in addidition to mipmapping and anisotropic filtering, multisample a disk around the uv coordinate and look for white texels. If the result is white we discard the previous sample in favour of the white texels we just got.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above gives slightly better results, but it's not perfect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried looking for papers and resources, but all I get on how to deal with this issue is &quot;minification and anisotropic filtering&quot; which I am already doing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to preserved thin/small details in a texture?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I can't show the images displaying the problem)&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-03-20T16:18:26.780" Title="Anti aliasing thin features in textures" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;sampling&gt;&lt;antialiasing&gt;&lt;fragment-shader&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8688" PostTypeId="1" AcceptedAnswerId="8692" CreationDate="2019-03-21T21:43:53.483" Score="3" ViewCount="204" Body="&lt;p&gt;I am wondering is there a difference in performance between using floating point textures as my 2D float4 array vs just passing in 2D float4 arrays? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;2D float arrays eliminate the need to do texture look ups to get the colour value, but i am not sure if perhaps textures have some kinda performance boost on GPUs that an array would not due to what ever clever optimisations GPUs can do.&lt;/p&gt;&#xA;" OwnerUserId="10332" LastActivityDate="2019-04-21T19:02:25.477" Title="Compute shader textures compared 2D float4 arrays" Tags="&lt;performance&gt;&lt;compute-shader&gt;&lt;optimisation&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8689" PostTypeId="2" ParentId="8343" CreationDate="2019-03-22T08:40:16.513" Score="5" Body="&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;painter's algorithm&lt;/strong&gt;, you first sort all graphics elements&#xA;on depth (deepest first) and&#xA;then one-by-one fully paint them into the image on top of each other.&#xA;That way, deeper elements are obscured by less deep element.&#xA;(Intersecting graphics element require special attention.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;depth-buffering algorithm&lt;/strong&gt;,&#xA;you store the current depth of each pixel in the image&#xA;(in addition to other pixel info),&#xA;and fully paint each graphics element pixel-by-pixel,&#xA;where an image pixel is updated&#xA;only if its depth is more than that of the new pixel.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So, there is a time-memory tradeoff:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The &lt;strong&gt;painter's algorithm&lt;/strong&gt; requires an extra sorting step (&lt;strong&gt;costs time&lt;/strong&gt;),&#xA;but avoids storing additional (depth) information per pixel (&lt;strong&gt;saves memory&lt;/strong&gt;).&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Depth-buffering&lt;/strong&gt; avoids sorting (&lt;strong&gt;saves time&lt;/strong&gt;),&#xA;but stores extra (depth) information per pixel (&lt;strong&gt;costs memory&lt;/strong&gt;).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="10353" LastActivityDate="2019-03-22T08:40:16.513" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8691" PostTypeId="1" CreationDate="2019-03-22T10:45:02.347" Score="5" ViewCount="386" Body="&lt;p&gt;I'm working on a hybrid real time ray tracing project and trying to tackle the problem of self-intersection with larger scenes due to loss of float accuracy. The logic I'm trying to use is based on &lt;a href=&quot;http://www.realtimerendering.com/raytracinggems/&quot; rel=&quot;noreferrer&quot;&gt;Ray Tracing Gems&lt;/a&gt; chapter 6 with the code bellow adapted to work with HLSL. In the snippet, &lt;code&gt;p&lt;/code&gt; is the unadjusted ray origin and &lt;code&gt;n&lt;/code&gt; the surface normal.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;float origin() { return 1.0f / 32.0f; }&#xA;float float_scale() { return 1.0f / 65536.0f; }&#xA;float int_scale() { return 256.0f; }&#xA;&#xA; // Normal points outward for rays exiting the surface, else is flipped.&#xA; float3 offset_ray(const float3 p, const float3 n)&#xA; {&#xA;    int3 of_i = {int_scale() * n.x, int_scale() * n.y, int_scale() * n.z};&#xA;&#xA;    float3 p_i = {&#xA;    asfloat(asint(p.x)+((p.x &amp;lt; 0) ? -of_i.x : of_i.x)),&#xA;    asfloat(asint(p.y)+((p.y &amp;lt; 0) ? -of_i.y : of_i.y)),&#xA;    asfloat(asint(p.z)+((p.z &amp;lt; 0) ? -of_i.z : of_i.z))};&#xA;&#xA;    return float3(&#xA;    (abs(p.x) &amp;lt; origin() ? p.x+ float_scale()*n.x : p_i.x),&#xA;    (abs(p.y) &amp;lt; origin() ? p.y+ float_scale()*n.y : p_i.y),&#xA;    (abs(p.z) &amp;lt; origin() ? p.z+ float_scale()*n.z : p_i.z));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm testing this system with Ray Traced Ambient Occlusion and &lt;a href=&quot;https://sketchfab.com/3d-models/kv-2-heavy-tank-1940-ba8b84d78c0a42038cf2eaa4210ef296&quot; rel=&quot;noreferrer&quot;&gt;a single model&lt;/a&gt; with plenty of detail. Since the model is rather small I'm not encountering any issues at a scale of 1 with the model centered around the origin. The &lt;a href=&quot;https://i.stack.imgur.com/4WTrZ.png&quot; rel=&quot;noreferrer&quot;&gt;output of the AO GBuffer&lt;/a&gt; therefore looks plausible. When changing the scale to 100 there is a huge amount of self-intersection with the floor always self-intersecting and other parts of the model flickering when moving the camera and large parts are often being falsely occluded (&lt;a href=&quot;https://i.stack.imgur.com/pGGSN.png&quot; rel=&quot;noreferrer&quot;&gt;output of the GBuffer&lt;/a&gt;). When translating the model by &lt;a href=&quot;https://i.stack.imgur.com/XnGvr.png&quot; rel=&quot;noreferrer&quot;&gt;10000 units on each axis&lt;/a&gt; and back to a scale of 1 the problem is way less prevalent but still visible. The flickering only happens on parts of the model and underneath the tracks but overall fewer artifacts appear than with the scaling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already have taken a look at the shaders used by UE4 but could only find a method to offset depending on the ray angle instead of the translation and is not a system that will solve my issue as the largest offset used in their system is not sufficient in our test scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm curious why the problem is far more severe with a scale of 100 than with a translation of 10000 and what is causing the issues I'm experiencing. Is it a false translation of the shader code? Miss use of it? Or am I approaching the issue completely the wrong way?&lt;/p&gt;&#xA;" OwnerUserId="10354" LastActivityDate="2019-03-22T10:45:02.347" Title="How to account for self intersection with large ray tracing scenes?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;directx12&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8692" PostTypeId="2" ParentId="8688" CreationDate="2019-03-22T19:01:46.110" Score="1" Body="&lt;p&gt;It depends on what you’re doing. If any given thread of your shader is working with data from multiple nearby pixels, like by sampling from fractional between-pixel locations or doing some calculation involving a pixel’s immediate neighbors, then you should probably use a texture: the GPU can do some caching and even load multiple values in a single operation in that case. If your threads are more independent and working on individual values, an array is fine.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-03-22T19:01:46.110" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8693" PostTypeId="1" CreationDate="2019-03-24T23:16:27.460" Score="5" ViewCount="365" Body="&lt;p&gt;I'm using a renderer developed by other people, and I found there are fireflies. It is strange that in a completely diffuse scene, there are still fireflies presented.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To my understanding, I think it is possible to have fireflies in diffuse scene depending on what sampling strategy I use. For example, if I use a very small area light, and the probability of hitting the light by sampling the BRDF will be very small, resulting in an extremely large radiance value. (I'm not sure because I also heard that fireflies will not appear in complete diffuse scene, so correct me if I'm wrong!)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to locate the bug, if there are any, or improve the program, if the fireflies come with some reason. But after googling for a while, most things I found was how to fight fireflies, other than clearly analyzing where they come from.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering if anyone knows any good materials, or if you could kindly summarize a bit. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm particularly interested in the sources of the fireflies related to the sampling strategies, BRDF sampling, light sampling or MIS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also think fireflies should be considered separately with &lt;strong&gt;noise&lt;/strong&gt;, since they also seem to be caused by numerical stability (from &lt;a href=&quot;https://en.wikipedia.org/wiki/Fireflies_(computer_graphics)&quot; rel=&quot;noreferrer&quot;&gt;Wiki&lt;/a&gt;).&lt;/p&gt;&#xA;" OwnerUserId="10365" LastEditorUserId="209" LastEditDate="2019-03-25T09:37:38.673" LastActivityDate="2019-03-26T16:50:19.487" Title="Where do &quot;fireflies&quot; come from?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;sampling&gt;&lt;noise&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8694" PostTypeId="1" CreationDate="2019-03-25T11:17:46.270" Score="1" ViewCount="133" Body="&lt;p&gt;I have a very big geometry in three.js and I want to hide a section of that geometry along an axis (for example every vertex with a Z&gt;N must be hidden). My idea is to create a custom shader in GLSL that does something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if vertex.z&amp;gt;n {&#xA;vertex.hide= True&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have 2 questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I have to do that in real time several times with different N&#xA;values provided by the user, can I use something that &quot;tells&quot; to the shader the N value dynamically without creating and assign every time a new shader with just a different value?  &lt;/li&gt;&#xA;&lt;li&gt;Maybe that's a better way? You must consider that to compute a new&lt;br&gt;&#xA;geometry and rendering it takes like 10 seconds, so I would&lt;br&gt;&#xA;definitely avoid creating a new &quot;cut&quot; geometry every time.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Sorry for my poor English and thanks.&lt;/p&gt;&#xA;" OwnerUserId="10368" LastEditorUserId="10368" LastEditDate="2019-04-01T14:19:48.787" LastActivityDate="2019-04-01T14:19:48.787" Title="How to hide a part of a geometry dynamically using a shader in three.js" Tags="&lt;glsl&gt;&lt;three.js&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8695" PostTypeId="1" CreationDate="2019-03-26T15:49:19.307" Score="3" ViewCount="397" Body="&lt;p&gt;I am currently working on an algorithm to calculate visibility in a 2D top-down level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The level contains&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;actors, with &lt;code&gt;position&lt;/code&gt; and &quot;sight&quot; information&lt;/li&gt;&#xA;&lt;li&gt;walls, with &lt;code&gt;start&lt;/code&gt; &amp;amp; &lt;code&gt;end&lt;/code&gt; positions&lt;/li&gt;&#xA;&lt;li&gt;light sources, with &lt;code&gt;position&lt;/code&gt; and &lt;code&gt;range&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I have written a fragment shader that renders my scene based on a texture I compose of the informations above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rnsp4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rnsp4.png&quot; alt=&quot;basic line of sight calculation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wrNqK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wrNqK.jpg&quot; alt=&quot;Left side: my level rendered, right side: the actual texture that is fed to the shader&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Red channel = line of sight for actors (in the example just the selected token is an actor)&lt;/li&gt;&#xA;&lt;li&gt;Green channel = light sources with their range and their respective line of sight&lt;/li&gt;&#xA;&lt;li&gt;Blue channel (not present in example) = night-vision of actors (means areas are shaded despite no light present)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I am using &lt;a href=&quot;https://github.com/BabylonJS/Babylon.js/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Babylonjs&lt;/a&gt; and am naively rendering all those calculations one after the other into a DynamicTexture using the canvas 2d context.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I use the GPU for some of these calculations (or all?) I am no expert for shader programming and don't know where to start / look.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code for my line-of-sight calculation can be found here: &lt;a href=&quot;https://gitlab.com/aiacta/visibility&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gitlab.com/aiacta/visibility&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10372" LastActivityDate="2021-04-20T20:46:53.550" Title="2D Line of Sight + Visibility Calculations" Tags="&lt;shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8699" PostTypeId="1" AcceptedAnswerId="8700" CreationDate="2019-03-27T07:54:48.500" Score="2" ViewCount="656" Body="&lt;p&gt;So I have a uniform block that looks something lile this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;{&#xA;mat4;&#xA;mat4[128];&#xA;uint[16]&#xA;}&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The block should total up to 8320 bytes. After aligning by 256 bytes for nvidia, that brings the total allocation size to 8448 bytes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, according to renderdoc and spirv-cross the total block size should be 8512 bytea. Can someone explain to me why there is a 64 byte padding at the end?&lt;/p&gt;&#xA;" OwnerUserId="6331" LastActivityDate="2019-03-27T13:50:05.703" Title="Clarifying vulkan glsl std140" Tags="&lt;glsl&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8700" PostTypeId="2" ParentId="8699" CreationDate="2019-03-27T13:50:05.703" Score="6" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;The block should total up to 8320 bytes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, it shouldn't. You use a &lt;code&gt;uint[16]&lt;/code&gt; array. Well, std140 layout makes it clear that the array stride for &lt;em&gt;any array&lt;/em&gt; is always rounded up to the stride of a &lt;code&gt;vec4&lt;/code&gt;. So that array takes up 256 bytes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You should instead use a &lt;code&gt;uvec4[4]&lt;/code&gt; instead, which you would index from like a multidimensional array.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-03-27T13:50:05.703" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8701" PostTypeId="1" AcceptedAnswerId="8707" CreationDate="2019-03-27T17:17:48.477" Score="0" ViewCount="294" Body="&lt;p&gt;I am trying to implement SSAO using DirectX11 but instead I got white screen with few black dots on model. &lt;strong&gt;My suspect is that kernel generation or usage might be wrong&lt;/strong&gt;. I've tried &lt;strong&gt;changing order of TBN matrix and sample multiplication order in pixel shader and it doesn't change results&lt;/strong&gt; in any way:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/otLHt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/otLHt.png&quot; alt=&quot;Final buffer&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact those &quot;dots&quot; are small models of model itself that appear on it instead of dark creases (Example with sphere model):&lt;a href=&quot;https://i.stack.imgur.com/vEnCe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vEnCe.png&quot; alt=&quot;Sphere model SSAO&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My G-Buffers looks like this (Position, normal, tangent, bitangent):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/pLjAp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pLjAp.png&quot; alt=&quot;Position&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jJq6E.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jJq6E.png&quot; alt=&quot;Normal&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EI8iI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EI8iI.png&quot; alt=&quot;Tangent&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qwNo7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qwNo7.png&quot; alt=&quot;Bitangent&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;myKernelGeneration.cpp&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Create kernel for SSAO&#xA;std::uniform_real_distribution&amp;lt;float&amp;gt; randomFloats(0.0f, 1.0f);&#xA;std::default_random_engine generator;&#xA;XMFLOAT3 tmpSample;&#xA;for (int i = 0; i &amp;lt; SSAO_KERNEL_SIZE; i++)&#xA;{&#xA;    //Generate random vector3 ([-1, 1], [-1, 1], [0, 1])&#xA;    tmpSample.x = randomFloats(generator) * 2.0f - 1.0f;&#xA;    tmpSample.y = randomFloats(generator) * 2.0f - 1.0f;&#xA;    tmpSample.z = randomFloats(generator);&#xA;&#xA;    //Normalize vector3&#xA;    XMVECTOR tmpVector;&#xA;    tmpVector.m128_f32[0] = tmpSample.x;&#xA;    tmpVector.m128_f32[1] = tmpSample.y;&#xA;    tmpVector.m128_f32[2] = tmpSample.z;&#xA;&#xA;    tmpVector = XMVector3Normalize(tmpVector);&#xA;&#xA;    tmpSample.x = tmpVector.m128_f32[0];&#xA;    tmpSample.y = tmpVector.m128_f32[1];&#xA;    tmpSample.z = tmpVector.m128_f32[2];&#xA;&#xA;    //Multiply by random value all coordinates of vector3&#xA;    //float randomMultiply = randomFloats(generator);&#xA;    //tmpSample.x *= randomMultiply;&#xA;    //tmpSample.y *= randomMultiply;&#xA;    //tmpSample.z *= randomMultiply;&#xA;&#xA;    //Scale samples so they are more aligned to middle of hemisphere&#xA;    float scale = float(i) / 64.0f;&#xA;    scale = lerp(0.1f, 1.0f, scale * scale);&#xA;    tmpSample.x *= scale;&#xA;    tmpSample.y *= scale;&#xA;    tmpSample.z *= scale;&#xA;&#xA;    //Pass value to array&#xA;    m_ssaoKernel[i] = tmpSample;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;myPixelShader.ps&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Texture2D textures[3]; //position, normal, noise&#xA;SamplerState SampleType;&#xA;&#xA;//////////////&#xA;// TYPEDEFS //&#xA;//////////////&#xA;&#xA;cbuffer KernelBuffer&#xA;{&#xA;    float3 g_kernelValue[64];&#xA;};&#xA;&#xA;struct PixelInputType&#xA;{&#xA;    float4 positionSV : SV_POSITION;&#xA;    float2 tex : TEXCOORD0;&#xA;    float4x4 projection : TEXCOORD1;&#xA;};&#xA;&#xA;const float2 noiseScale = float2(1280.0f / 4.0f, 720.0f / 4.0f);&#xA;const float radius = 0.5f;&#xA;const float bias = 0.025f;&#xA;////////////////////////////////////////////////////////////////////////////////&#xA;// Pixel Shader&#xA;////////////////////////////////////////////////////////////////////////////////&#xA;float4 ColorPixelShader(PixelInputType input) : SV_TARGET&#xA;{&#xA;    float3 position = textures[0].Sample(SampleType, input.tex).xyz;&#xA;float3 normal = normalize(textures[1].Sample(SampleType, input.tex).rgb);&#xA;float3 randomVector = normalize(textures[2].Sample(SampleType, input.tex * noiseScale).xyz);&#xA;&#xA;float3 tangent = normalize(randomVector - normal * dot(randomVector, normal));&#xA;float3 bitangent = cross(normal, tangent);&#xA;float3x3 TBN = { tangent, bitangent, normal };&#xA;&#xA;float3 sample = float3(0.0f, 0.0f, 0.0f);&#xA;float4 offset = float4(0.0f, 0.0f, 0.0f, 0.0f);&#xA;float occlusion = 0.0f;&#xA;&#xA;for (int i = 0; i &amp;lt; 64; i++)&#xA;{&#xA;    sample = mul(TBN, g_kernelValue[i]);&#xA;    sample = position + sample * radius;&#xA;&#xA;    offset = float4(sample, 1.0f);&#xA;    offset = mul(input.projection, offset);&#xA;    offset.xyz /= offset.w;&#xA;    offset.xyz = offset.xyz * 0.5f + 0.5f;&#xA;&#xA;    float sampleDepth = textures[0].Sample(SampleType, offset.xy).z;&#xA;    occlusion += (sampleDepth &amp;gt;= sample.z + bias ? 1.0 : 0.0);&#xA;}&#xA;occlusion = 1.0f - (occlusion / 64.0f);&#xA;&#xA;return float4(occlusion, occlusion, occlusion, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-21T12:06:10.910" Title="SSAO - artifacts appearing" Tags="&lt;directx11&gt;&lt;directx&gt;&lt;post-processing&gt;&lt;ssao&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8702" PostTypeId="1" CreationDate="2019-03-28T03:32:36.807" Score="1" ViewCount="46" Body="&lt;p&gt;I am creating a quad tree from ground zero, because I am going to collapse it from bottom up I am refining it with a certain LoD level.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using glm for mathematics and opengl for rendering. Instead of pointing to a vertex each quad points to an index from a list of vertex to avoid vertex redundancy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I start by computing the medians and the center, then I check in the list if any of these vertices exist. For a small amount of vertices this is trivial, however it became&#xA;apparent that this strategy is ineffective.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The code for this split is in the &lt;a href=&quot;https://github.com/worldrender/worldrender/blob/343780997086babcdc964c3239e95d001e34e9d2/QuadTree.cpp#L95-L165&quot; rel=&quot;nofollow noreferrer&quot;&gt;following repo&lt;/a&gt;, if anyone can help me in finding another strategy, even showing me a code snippet, I would really appreciate it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance&lt;/p&gt;&#xA;" OwnerUserId="10387" LastActivityDate="2019-03-28T03:32:36.807" Title="Help with efficient quadtree vertices indexing to avoid redundancy" Tags="&lt;algorithm&gt;&lt;c++&gt;&lt;data-structure&gt;&lt;procedural-generation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8704" PostTypeId="1" CreationDate="2019-03-28T19:40:53.297" Score="4" ViewCount="669" Body="&lt;p&gt;What I managed to figure out is that the first 3*3 is used for rotation and scale and the 1*3 at the end is used for position, but what is the bottom row used for? &#xA;is it only for clipping related things?&lt;/p&gt;&#xA;" OwnerUserId="10396" LastActivityDate="2020-07-16T20:01:41.413" Title="Why does opengl use 4d matrices for everything?" Tags="&lt;matrix&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8705" PostTypeId="2" ParentId="8704" CreationDate="2019-03-29T05:14:16.323" Score="4" Body="&lt;p&gt;The bottom row allows you to create &lt;a href=&quot;https://en.wikipedia.org/wiki/Perspective_(graphical)#Foreshortening&quot; rel=&quot;nofollow noreferrer&quot;&gt;perspective foreshortening&lt;/a&gt;. That is, it makes lines that are getting further away appear to converge. When arranged this way, we call this a perspective projection matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are other ways to arrange a projection matrix where that foreshortening doesn't happen. For example in an &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;orthographic projection&lt;/a&gt;. &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection#/media/File:Graphical_projection_comparison.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;This graphic&lt;/a&gt; shows some different projections that are possible by  changing the values in the last row of a 4x4 matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematically, the difference between a perspective projection and an orthographic projection is that the last row of a &lt;a href=&quot;https://en.wikipedia.org/wiki/3D_projection#Perspective_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;perspective matrix has a division in the z component&lt;/a&gt;, whereas the &lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection#Geometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;orthographic projection has a 0 in the z component&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2019-03-29T15:36:27.630" LastActivityDate="2019-03-29T15:36:27.630" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8706" PostTypeId="1" AcceptedAnswerId="8715" CreationDate="2019-03-29T15:09:45.837" Score="1" ViewCount="112" Body="&lt;p&gt;For those familiar with smallpt, the ray tracer in 99 lines: I am checking the code, and there is something that is not clear to me in the DIFFUSE ray scattering.&#xA;After the rays are shot, they keep bouncing until the if-statement with the Russian Roulette stops them. &lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (++depth&amp;gt;5) if (erand48(Xi)&amp;lt;p) f=f*(1/p); else return obj.e;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This means that, when rays are scattered and hit the light source, they don't actually stop there (which is what I thought at first: rays bounce until they hit the light source, or until they reach a specific amount of bounces). Am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="10191" LastEditorUserId="10191" LastEditDate="2019-04-01T09:44:15.990" LastActivityDate="2019-04-01T09:44:15.990" Title="smallpt: when to stop diffuse ray scattering" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="9" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8707" PostTypeId="2" ParentId="8701" CreationDate="2019-03-29T19:40:46.097" Score="0" Body="&lt;p&gt;Offset.xy is definatelly off because it just return XY coordinates from screenspace:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/pTk24.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pTk24.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clamping solved 'small copies of model' on the model itself, thanks!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;sampleDepth actually looks like this and indeed is not in viewspace and it may really explain those little models now:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/edGRY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/edGRY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using viewspace (&lt;em&gt;offset = mul(projection, offset) ---&gt; offset = mul(view, offset)&lt;/em&gt;) solves depth problem but final buffer is clear white. No effects are actually visible. What next step do you suggest? If depth comparing is correct now, what might be off?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cEhHh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cEhHh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&#xA;Comparision is working but in a wrong way. Below line results in just fully white buffer screen:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;occlusion += (sampleDepth &amp;gt;= sample.z + bias ? 1.0 : 0.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Changing it to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;occlusion += (sampleDepth &amp;gt;= sample.z - bias ? 1.0 : 0.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Actually gives us comparision but it is really bold and doesn't include only holes and creases but whole model. Changing bias to small values like 0.001f doesn't help:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/mtO9k.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mtO9k.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update #2:&lt;/strong&gt;&#xA;Directly comparing gives result presented below. However it doesn't seem satisfying enough to use as it seems to present rather edges than creases and holes:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;occlusion += (sampleDepth == sample.z ? 1.0 : 0.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qsHyi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qsHyi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2019-03-30T08:04:05.120" LastActivityDate="2019-03-30T08:04:05.120" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8708" PostTypeId="1" CreationDate="2019-03-30T01:41:50.860" Score="1" ViewCount="71" Body="&lt;p&gt;Hi I'm trying to get a better understanding of the BRDF modeling. I only implemented naive diffuse(lambert), specular and microfacet BRDF before, but I don't have much experience in mixed BRDFs and also rendering using 3D softwares like Maya, etc. Now I have to figure out the metal-rough or spec-gloss &quot;work flows&quot;, or PBR materials used in most industrial standard products.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At first, I didn't understand what metallic and roughness are really doing so I read the long paper by Brent Burley on Disney's principal BRDF. However, more and more questions pops up..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Oh I also read the useful and clear slides &lt;a href=&quot;https://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.selfshadow.com/publications/s2015-shading-course/hoffman/s2015_pbs_physics_math_slides.pdf&lt;/a&gt; , in which I learn about the specular/diffuse decomposition. I think this is essentially decoupling the reflection into two separate lobes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I want to understand the PBR materials in such a decoupling scheme.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically we have a diffuse + specular pattern, where&lt;/p&gt;&#xA;&#xA;&lt;p&gt;diffuse is usually enough to model by simply Lambert (not always true though..)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;specular term is usually modeled by a microfacet BRDF (contains specularD, specularG, specularF terms)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I start from the metal-rough model, there are usually three parameters&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1. base color&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2. metalness&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3. roughness&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My questions are as follows:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;What is base color for? Is it the same as the diffuse color? Will it influence the specular behavior?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Regarding metalness, is it true that we only consider the diffuse term when the material is non-metal, and only specular reflection should be considered when rendering metal materials?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What's the relationship between &lt;strong&gt;roughness&lt;/strong&gt; and &lt;strong&gt;specular D (surface normal distribution)&lt;/strong&gt;?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In general, I'm very confused by this three-parameter representation, instead of the diffuse+specular(microfacet) one. What's the relationship between the three parameters and the other ones (diffuse color, specular D/G/F)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to understand this because I want to add the conversion (metal-rough -&gt; diffuse+specular) in my own code..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance!!&lt;/p&gt;&#xA;" OwnerUserId="10365" LastActivityDate="2019-03-30T01:41:50.860" Title="Questions about BRDF parameterization" Tags="&lt;brdf&gt;&lt;pbr&gt;&lt;material&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8709" PostTypeId="2" ParentId="2146" CreationDate="2019-03-30T04:35:53.013" Score="0" Body="&lt;p&gt;check this &lt;a href=&quot;https://community.khronos.org/t/oblique-frustum/49436/6&quot; rel=&quot;nofollow noreferrer&quot;&gt;link&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;quotations ：&lt;/p&gt;&#xA;&#xA;&lt;p&gt;“The points (+/-1, +/-1, 1, 1) are the four corners of the view frustum on the far plane in clip space.”&lt;/p&gt;&#xA;&#xA;&lt;p&gt;this should be the point Q' which equals (sgn(Cx), sgn(Cy), 1, 1)&lt;/p&gt;&#xA;" OwnerUserId="10399" LastActivityDate="2019-03-30T04:35:53.013" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8710" PostTypeId="1" CreationDate="2019-03-30T16:15:13.383" Score="1" ViewCount="220" Body="&lt;p&gt;I am trying to understand why my explicit light sampling implemetation does not produce the same results as my naive path tracer. Here are my results :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Naive Version :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/B7O0q.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/B7O0q.jpg&quot; alt=&quot;Naive version&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Explicit light sampling version :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MSHoh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MSHoh.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Diff :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LZxDB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LZxDB.png&quot; alt=&quot;Diff with tweaked contrast&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's not that different, but the top and back planes have a stronger &quot;glow&quot; in the explicit light version. The shadow also seems softer in the explicit light version.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I made for the explicit light sampling, based on PBRT and &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5152/progressive-path-tracing-with-explicit-light-sampling&quot;&gt;this&lt;/a&gt; answer :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 pathTrace( const Ray&amp;amp; ray, int bounces, const std::vector&amp;lt; std::pair&amp;lt; Plane, Material &amp;gt; &amp;gt;&amp;amp; planes, const std::vector&amp;lt; std::pair&amp;lt; Sphere, Material &amp;gt; &amp;gt;&amp;amp; spheres, bool firstBounce = false )&#xA;{&#xA;    if( bounces == 0 )&#xA;        return vec3( 0.0 );&#xA;&#xA;    Hit hit = sceneIntersects( ray, planes, spheres );&#xA;    if( !hit._any )&#xA;        return vec3( 0.0 );&#xA;&#xA;    // Cast a new ray from the hit position to a random direction on the hemisphere&#xA;    Ray secondRay( hit._position, sampleHemisphereUniform( hit._normal ) );&#xA;&#xA;    vec3 radiance = pathTrace( secondRay, bounces - 1, planes, spheres );&#xA;&#xA;    vec3 brdf = hit._material._albedo / Pi;&#xA;    double pdf = 1.0 / ( 2.0 * Pi );&#xA;&#xA;#ifdef NAIVE&#xA;    return hit._material._emissive + radiance * brdf * dot( hit._normal, secondRay._direction ) / pdf;&#xA;#else&#xA;    // Remove the emission since its taken into account in the directLighting part&#xA;    vec3 indirectLighting = radiance * brdf * dot( hit._normal, secondRay._direction ) / pdf;&#xA;&#xA;    if( firstBounce &amp;amp;&amp;amp; hit._isLight )&#xA;    {&#xA;        // Unlesss we hit a light at first bounce, to avoid black lights&#xA;        indirectLighting += hit._material._emissive;&#xA;    }&#xA;&#xA;    vec3 directLighting;&#xA;&#xA;    // For testing purposes, the sphere area light is hardcoded&#xA;    const vec3 lightPosition( 0.0, 8.0, -2.5 );&#xA;    const double lightRadius = 1.1;&#xA;    const vec3 lightEmission( 4.0 );&#xA;&#xA;    // Sample a random point on an hemisphere oriented to the point instead of a sphere&#xA;    vec3 lightSample = sampleHemisphereUniform( normalize( hit._position - lightPosition ) );&#xA;    lightSample *= lightRadius;&#xA;    lightSample += lightPosition;&#xA;&#xA;    vec3 lightDir = normalize( lightSample - hit._position );&#xA;&#xA;    // Cast a ray to the light&#xA;    Hit hitLight = sceneIntersects( Ray( hit._position, lightDir ), planes, spheres );&#xA;    if( !hit._isLight &amp;amp;&amp;amp; hitLight._any &amp;amp;&amp;amp; hitLight._isLight )&#xA;    {&#xA;        // Use the area form of the rendering equation&#xA;        double G = dot( hit._normal, lightDir ) * dot( hitLight._normal, -lightDir ) / length2( hitLight._position - hit._position );&#xA;&#xA;        // The light is sampled using an hemisphere, so the area is the area of an hemisphere&#xA;        double lightArea = 2.0 * Pi * 1.1 * 1.1;&#xA;        double lightPdf = 1.0 / lightArea;&#xA;&#xA;        directLighting = lightEmission * brdf * G / lightPdf;&#xA;    }&#xA;&#xA;    return directLighting + indirectLighting;&#xA;#endif&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4288/path-weight-for-direct-light-sampling&quot;&gt;This&lt;/a&gt; answer says that because I am sampling twice, I should divide my twice the number of samples, but it gives me even more different results so I'm not sure if I to do that or not. Anyway I test both every time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was also wondering if it was because 1 bounce of the naive path tracer is not equal to one bounce of the explicit light sampling version (The first bounce of naive will only output color when it hits a light, while the explicit light version will output direct lighting), so I tested with 30 bounces, and bounces - 1, and got almost no difference. Same thing with samples. I am just not able to get the light sampling version with the naive version, and to me it's not a convergence time issue, since the naive version doesn't change much after a 3 min render (other than the noise, of course), so I'm pretty sure the images converges to a different result. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't know if I need multiple importance sampling here, I'd say no because I am not trying to cast a light ray based on the brdf (for now) but I'm again not sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm also not sure if I can sample the sphere using an hemisphere. I did that because I had the hemisphere sampling code ready. But intuitively it seems good to me, because the spherical light would have twice of the samples occluded, which is taken into account when dividing by the pdf of an hemisphere instead of the pdf of a sphere.&lt;/p&gt;&#xA;" OwnerUserId="8925" LastActivityDate="2021-05-24T19:34:00.800" Title="Should I expect differences with explicit light sampling other that the noise?" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="8712" PostTypeId="1" AcceptedAnswerId="8713" CreationDate="2019-03-31T22:02:11.343" Score="0" ViewCount="97" Body="&lt;p&gt;Let's say I designed a housing model and rendered it using a rendering engine. how can I measure the performance of my rendering? &lt;/p&gt;&#xA;" OwnerUserId="10388" LastActivityDate="2019-04-17T03:10:08.733" Title="What are the parameters measure the performance of a rendering?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2019-04-15T11:17:48.937" ContentLicense="CC BY-SA 4.0" />
  <row Id="8713" PostTypeId="2" ParentId="8712" CreationDate="2019-03-31T23:09:07.760" Score="0" Body="&lt;p&gt;I assume you mean performance of the numerical algorithm responsible for generating the image?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Usually the performance of a rendering algorithm is assessed through a pixel-wise comparison with a ground truth, converged image. This image is typically rendered for a very long time using a standard and (ideally) unbiased technique like unidirectional path tracing. For a fixed time and sampling budget, you then run your custom algorithm and track a meaningful error (e.g. relative MSE) between your intermediate image and the ground truth image. Plotting the error over time on a logarithmic scale should give you a sense of how your algorithm is performing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When comparing algorithms, you need to make sure that you are actually comparing images that were output by the &lt;em&gt;same&lt;/em&gt; rendering engine. This is crucial if you want to report a faithful metric, otherwise the comparison is unfair and inherently depends on the implementation. For instance, if rendering engine &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; takes twice as long as engine &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; to fetch and load a texture, your reported error will be higher, even though the main algorithm you are testing is the same (assuming you are treating materials as blackboxes). The main downside is that rendering researchers are typically required to implement other algorithms in their engine to report the true performance of their new algorithm.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastEditorUserId="6588" LastEditDate="2019-04-17T03:10:08.733" LastActivityDate="2019-04-17T03:10:08.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8715" PostTypeId="2" ParentId="8706" CreationDate="2019-04-01T06:04:50.273" Score="0" Body="&lt;p&gt;&lt;code&gt;p&lt;/code&gt; is gonna be zero for light sources. Light sources are defined by emission variable and color is zero for them. Hence the reflectance parameter calculated previous to this line &lt;code&gt;p&lt;/code&gt; would be zero giving us &lt;code&gt;obj.e&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-04-01T06:04:50.273" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8716" PostTypeId="1" AcceptedAnswerId="8717" CreationDate="2019-04-01T09:41:12.970" Score="1" ViewCount="253" Body="&lt;h1&gt;Introduction&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;For those familiar with &lt;b&gt;smallpt&lt;/b&gt; by Kevin Beason: &lt;br&gt;&#xA;In path tracing, when rays hit a surface, they are scattered and the theta angle (the angle between the normal to the surface and the scattered ray) depends on a probability density function. For cosine importance sampling, this probability depends on cos(theta). This is the case implemented in the basic smallpt. Multiple rays should be scattered for each hitting point, and their contribution needs to be calculated to return the color value of the specific pixel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Sv5IS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Sv5IS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Problem&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Looking at how rays are scattered, this doesn't actually happen in the smallpt code. Multiple rays per pixel are shot at slightly different positions. That means, they don't always land in the same spot on the surface. For this reason, the image posted above does not represent what is happening. Indeed, it is not true that multiple rays are scattered FROM EVERY HITTING POINT, but multiple rays are shot for each pixel. Is my interpretation correct?&lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-04-01T14:36:11.170" Title="smallpt: ray scattering and Importance Sampling" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8717" PostTypeId="2" ParentId="8716" CreationDate="2019-04-01T13:58:41.347" Score="2" Body="&lt;p&gt;Let me first address some misconceptions you have:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the theory states that we need to shoot x number of rays for each&#xA;  intersection&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, the &quot;theory&quot; doesn't state such a thing. Note also that the paper @gallickgunner is referring to is inapplicable in this case since smallpt is based on the rendering equation and not the limited variant present in Cook's paper. Thus you actually need to refer to Kajiya's paper or Veach's path formulation. What @gallickgunner is right about is the canceling of the cosine term (but there's a missing &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt; factor).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now onto the bigger misconception you have:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Multiple rays should be scattered for each hitting point, and their contribution needs to be calculated to return the color value of the specific pixel. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;There's no such requirement, in fact Kajiya proved that scattering multiple rays at each bounce is bad since you get an exponential explosion of the ray count later down the bounce tree where the actual contribution is actually very small. In MC terms you perform splitting where the contribution is small thus wasting computational power which would be a lot more useful in reducing variance in other places. To understand why this is the case, one has to dig deeper into the theory of how raytracing works and how you estimate the rendering equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You start with a Fredholm integral equation of the second kind:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L_o(x,\omega_o) = L_e(x, \omega_o) + \int_{\Omega}{f(\omega_o,x,\omega_i)L_i(x,\omega_i)\cos\theta\,d\omega_i}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As long as the integral converges (which happens when the operator is a contraction, or when it is not but enough energy can escape the scene for there to be a steady state), you can find the solution as the Liouville-Neumann expansion. To do this however I'll first rewrite the equation in operator form:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + TL$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(I-T)L = L_e$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = (I-T)^{-1}L_e = \sum_{i=0}^{\infty}T^iL_e$$&lt;/span&gt;&#xA;Where the last equality holds as long as &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; is a contraction (&lt;span class=&quot;math-container&quot;&gt;$||T||&amp;lt;1$&lt;/span&gt;). Note that &lt;span class=&quot;math-container&quot;&gt;$T^0$&lt;/span&gt; represents &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; bounces, &lt;span class=&quot;math-container&quot;&gt;$T^1$&lt;/span&gt; represents &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; bounce, and &lt;span class=&quot;math-container&quot;&gt;$T^n$&lt;/span&gt; represents &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; bounces. Thus you can look at the solution as accumulating contributions from all light paths of length &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt; etc. till infinity. Now to actually write this out explicitly it's more convenient to rewrite the rendering equation in terms of integration over all scene surface points &lt;span class=&quot;math-container&quot;&gt;$S$&lt;/span&gt; rather than the upper hemisphere (this was actually how Kajiya derived it initially, not precisely the form below but in an equivalent form):&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L_o(x_1\rightarrow x_0) = L_e(x_1 \rightarrow x_0) + \int_{S}{f(x_2 \rightarrow x_1 \rightarrow x_0)L_o(x_2 \rightarrow x_1) G(x_1 \leftrightarrow x_2)\,dA(x_2)}$$&lt;/span&gt;&#xA;Where &lt;span class=&quot;math-container&quot;&gt;$G$&lt;/span&gt; is defined as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$G(x \leftrightarrow y) = \frac{|\cos\theta_x\cos\theta_y|}{||x-y||}V(x,y)$$&lt;/span&gt;&#xA;Where &lt;span class=&quot;math-container&quot;&gt;$\theta_x$&lt;/span&gt; is the angle between the vector &lt;span class=&quot;math-container&quot;&gt;$y-x$&lt;/span&gt; and the normal at &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\theta_y$&lt;/span&gt; is the angle betwen the vector &lt;span class=&quot;math-container&quot;&gt;$x-y$&lt;/span&gt; and the normal at &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; (the cosines can be written as dot products provided you have the normals). &lt;span class=&quot;math-container&quot;&gt;$V(x,y)$&lt;/span&gt; is the visibility function and it is 1 only if there's no surface point between &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; (if you shoot a ray from &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; the first thing you hit will be &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt;), and &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; otherwise. The visibility function is implicit in the solid angle formulation inside &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; (through the ray-casting function). Now let us rewrite the operator expansion in terms of what we have above, we get:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L_o(x_1\rightarrow x_0) = L_e(x_1 \rightarrow x_0) + \int_{S}{f(x_2 \rightarrow x_1 \rightarrow x_0)L_e(x_2 \rightarrow x_1) G(x_1 \leftrightarrow x_2)\,dA(x_2)} + $$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\int_{S}\int_{S}{{L_e(x_3 \rightarrow x_2)f(x_3 \rightarrow x_2 \rightarrow x_1) G(x_3 \leftrightarrow x_2)f(x_2 \rightarrow x_1 \rightarrow x_0) G(x_2 \leftrightarrow x_1)\,dA(x_3)\,dA(x_2)}}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$+ ...$$&lt;/span&gt;&#xA;This sum continues till infinity with iterated integrals corresponding to &lt;span class=&quot;math-container&quot;&gt;$T^i$&lt;/span&gt;, the part expanded above is &lt;span class=&quot;math-container&quot;&gt;$T^0L_e + T^1L_e + T^2L_e$&lt;/span&gt;. Note that usually you have an extra integration over the area of the pixel (then there's a factor &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt; to account for the sensor sensitivity). When you do pathtracing (what smallpt does) you're actually estimating this infinite sum of integrals through Monte Carlo (this is also the reason why Monte Carlo is employed, since the convergence doesn't depend on the dimension, which in this case is infinite). You can estimate each term in the sum by Monte Carlo integration, that is for a &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;-iterated integral your samples are really paths starting from the camera with length &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;: &lt;span class=&quot;math-container&quot;&gt;$x_0x_1x_2...x_{n+1}$&lt;/span&gt; for a path of length &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;. Note that you do not require that you split the path for each subsequent integral.&#xA;What path tracing implementations do, is create this path &lt;span class=&quot;math-container&quot;&gt;$x_0x_1...x_{n+1}$&lt;/span&gt; incrementally, and reuse the path for earlier terms in the sum. That means that you start by picking some point &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; inside a pixel, pick some point &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; in the scene compute the value of the integrand of the term &lt;span class=&quot;math-container&quot;&gt;$T^0L_e$&lt;/span&gt; for the path &lt;span class=&quot;math-container&quot;&gt;$x_0x_1$&lt;/span&gt;, pick a point &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt; in the scene and compute the value of the integrand of the term &lt;span class=&quot;math-container&quot;&gt;$T^1L_e$&lt;/span&gt; for the path &lt;span class=&quot;math-container&quot;&gt;$x_0x_1x_2$&lt;/span&gt;, and so on. In an implementation you usually use the solid angle formulation (at least for bsdf sampling), but there's not major difference, you still end up with paths of the form &lt;span class=&quot;math-container&quot;&gt;$x_0x_1...x_{n+1}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The takeaway from this is that &lt;strong&gt;path&lt;/strong&gt;tracing works with &lt;strong&gt;paths&lt;/strong&gt; where, a path starts at the camera and ends at a lightsource. Using different paths that do not split (in general) to estimate the sum of integrals is usually more efficient than splitting each path into more paths at each bounce. I am not saying there's no place for splitting (actually smallpt uses it for the first few bounces for materials that refract), you just have to know when to apply it (when the contribution is large and is inadequately sampled by only 1 or a few samples). Note that the opposite of splitting is early path termination in the form of the Russian roullete - basically kill off paths with small contributions since it's not worth it wasting computational resources on those (it also lets you make your estimator unbiased, but in practice there's usually a ceiling to the number of bounces allowed, since for most scenes your estimator being &quot;fully unbiased&quot; is not worth it in terms of performance).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-04-01T14:36:11.170" LastActivityDate="2019-04-01T14:36:11.170" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="8718" PostTypeId="2" ParentId="8695" CreationDate="2019-04-01T15:42:08.473" Score="0" Body="&lt;p&gt;In this &lt;a href=&quot;http://gmrv.es/Publications/2016/CMTKPO16/main.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;SIGGRAPH paper&lt;/a&gt; is described a similar operation for the visibility calculation from every pixel in the domain (you only need calculate it from actors position), which has been implemented in GPU. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although it is oriented to fluid dynamics, it may be a starting point to look.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can see other related shader examples like &lt;a href=&quot;https://www.shadertoy.com/view/4d2SzG&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt; with implicit geometry.&lt;/p&gt;&#xA;" OwnerUserId="9908" LastActivityDate="2019-04-01T15:42:08.473" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8720" PostTypeId="2" ParentId="8704" CreationDate="2019-04-02T05:30:42.943" Score="1" Body="&lt;p&gt;If we put homogeneous ordinates to the backburner for a second. Then there is also a second reason:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mathematical completeness. A 3 by 4 or 4 by 3 matrix is not invertible (although that does not mean you couldn't calculate a inverse by other means just not by standard matrix algebra). Inverse is critical for hierarchy calculations. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you could posit that the  last computer part is always same and be done with it. But having worked for a company that in their main software did just this i would say that it is a mistake. Well, sure now the matrices are invertible but not general. I can now not safely transpose my matrices for example. The truth is that i lose out on a lot of possible mathematics knowledge that i could use because this one part is missing. At the end this was a common source of errors, anger and confusion among clients.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Homogeneous coordinates are just one possible application of this mathematical completeness. It turns out to be very useful if you want to model perspective. But its far from the only benefit.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2019-04-03T15:36:20.957" LastActivityDate="2019-04-03T15:36:20.957" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8721" PostTypeId="1" CreationDate="2019-04-02T12:15:51.570" Score="1" ViewCount="183" Body="&lt;p&gt;I'm trying to perfectly align two or more equirectangular photos of the same place taken from slightly different positions. &#xA;Using an example provided by openMVG I managed to get the relative position between the two shots, but I can't figure out how to translate the center of the projection according to the data obtained. &#xA;I tried with Hugin without success, editing the camera position information (it doesn't seem to be able to export the entire equirectangular photo) and I didn't found any useful panotools. I found some literature about the problem but not any real implementation to adapt.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could you advise me of a possible path to follow?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My requirement is to do it programmatically because I will have to apply it to thousands of photos.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot.&lt;/p&gt;&#xA;" OwnerUserId="10415" LastActivityDate="2021-04-23T09:04:50.457" Title="How to translate the center of an equirectangular projection?" Tags="&lt;rendering&gt;&lt;image-processing&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8723" PostTypeId="1" CreationDate="2019-04-03T05:08:48.307" Score="1" ViewCount="86" Body="&lt;p&gt;I'm looking for a code to generate organic 2d trees like thiskind of shapes&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jNBs5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jNBs5.png&quot; alt=&quot;Organic tree 01 &quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/82g8O.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/82g8O.png&quot; alt=&quot;Organic tree 02&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Gerard Ferrandez has an example to generate some tree but not organic like the picture shape &lt;a href=&quot;https://codepen.io/ge1doot/pen/BGWzgW?editors=0010&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://codepen.io/ge1doot/pen/BGWzgW?editors=0010&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any recomendation will be much appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many thanks!&lt;/p&gt;&#xA;" OwnerUserId="10418" LastActivityDate="2019-04-04T07:58:25.887" Title="Organic 2d tree generation" Tags="&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8724" PostTypeId="2" ParentId="8723" CreationDate="2019-04-03T07:16:35.973" Score="2" Body="&lt;p&gt;It could be generated as a Lindenmayer System (L-system) with some rules for branch widths (plus some fractal noise) and branch bifurcation. They are parameters you can play with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find lots of resources in the &lt;a href=&quot;http://algorithmicbotany.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;website&lt;/a&gt; of the Biological Modeling and Visualization research group in the Department of Computer Science at the University of Calgary. Professor Przemyslaw Prusinkiewicz is the researcher who popularized these systems, and he has made his &lt;a href=&quot;http://algorithmicbotany.org/papers/abop/abop.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;main book&lt;/a&gt; &lt;em&gt;The algorithmic beauty of plants&lt;/em&gt; available for free.&lt;/p&gt;&#xA;" OwnerUserId="9908" LastEditorUserId="209" LastEditDate="2019-04-04T07:58:25.887" LastActivityDate="2019-04-04T07:58:25.887" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8725" PostTypeId="1" CreationDate="2019-04-03T08:47:59.967" Score="0" ViewCount="79" Body="&lt;p&gt;Normally when we talk about realistic transparent volumes, we care about refraction (and total internal reflection), and we care about scattering. But there's a much simpler case of volume transparency, where the opacity of the object depends on the distance that light travels through it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm writing a real-time visualization with a forward-rendering pipeline (on WebGL) and I'd like to show transparent solids this way, without having to resort to path tracing. My solids are homogeneous and isotropic, and I'm not interested in scattering or refraction. I just want thin parts of the solid to be very transparent and thicker parts of the solid to be more opaque.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like most real-time transparency algorithms (e.g. OIT) are mainly for getting surfaces/sheets right, instead of volumes, and are more concerned about correct stacking, refraction, and scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like making the colour of the object depend on the thickness of material behind each fragment should be easily achievable with something like an extra depth pass where I draw opaque objects that intersect transparent objects, and back faces of transparent objects, possibly with some extra correction where the notional ray for one pixel goes through a torus-like object more than once. Intuition tells me that this ought to be a standard algorithm, but I don't know of one. Does this algorithm already exist, or do I just need to get my pencil and paper out and write one?&lt;/p&gt;&#xA;" OwnerUserId="2041" LastEditorUserId="2041" LastEditDate="2019-04-04T13:47:28.953" LastActivityDate="2019-04-04T16:20:06.560" Title="How to draw depth-based volume in real-time" Tags="&lt;real-time&gt;&lt;transparency&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8726" PostTypeId="2" ParentId="8725" CreationDate="2019-04-03T12:30:42.633" Score="1" Body="&lt;p&gt;The issue is that an extra depth pass won't cut it. You may need an arbitrary number of extra depth passes. Just imagine the volume between two sinusoidal surfaces, you would have infinitely many alternating z-intervals of volume/empty space as long as you're looking from a specific direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit:&#xA;Taking into consideration the updated formulation, here's my suggestion for a rather general algorithm with different attenuation coefficients &lt;span class=&quot;math-container&quot;&gt;$\kappa_i$&lt;/span&gt; for each volume. Note that there are non-trivial parts that are missing, also if you do not require different attenuation coefficients it can be optimized even further.&#xA;The algorithm relies on you drawing the volumes pixels in reverse z-order (this is the non-trivial missing part). You draw your volumes in a separate pass. You keep an attenuation density accumulation variable &lt;span class=&quot;math-container&quot;&gt;$\kappa$&lt;/span&gt; for each pixel (initialize to &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;), as well as a distance time stamp &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt; (initialize to the the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; of the far plane, which I will denote &lt;span class=&quot;math-container&quot;&gt;$\max$&lt;/span&gt;), and a &quot;color&quot; variable &lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt; (initialize to &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;). Whenever you draw a pixel:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;if &lt;span class=&quot;math-container&quot;&gt;$\delta==\max$&lt;/span&gt; and you drew a front face of volume &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; then:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d = \delta-pixelDepth$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$c = attenuate(c,\kappa_i,d)$$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$\kappa_i$&lt;/span&gt; is the attenuation of the currently drawn pixel (you can simply draw the volumes in the &quot;color&quot; of their attenuation and use that).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;if &lt;span class=&quot;math-container&quot;&gt;$\delta&amp;lt;\max$&lt;/span&gt; and you drew a back face of volume &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; then:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$d = \delta - pixelDepth$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\delta = pixelDepth$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$c = attenuate(c,\kappa, d)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\kappa = \kappa + \kappa_i$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;if &lt;span class=&quot;math-container&quot;&gt;$\delta&amp;lt;\max$&lt;/span&gt; and you drew a front face of volume &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; then:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d = \delta -pixelDepth$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\delta = pixelDepth$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$c = attenuate(c,\kappa, d)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\kappa = \kappa - \kappa_i$$&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;after you've drawn all pixels if &lt;span class=&quot;math-container&quot;&gt;$\kappa &amp;gt; 0$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$c = attenuate(c,\kappa,\delta)$$&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Note that the 4th check handles the case where the camera is inside a volume (and it ends behind the camera), but the frustum is not entirely inside it. Similarly the first check handles the case where a volume is cutoff by the frustum. However, the case where the camera frustum is totally inside a volume is not handled (you can try to check this by verifying that the camera is inside a volume and then simply adding a constant to &lt;span class=&quot;math-container&quot;&gt;$\kappa$&lt;/span&gt;, then you have to modify the end case too, to check &lt;span class=&quot;math-container&quot;&gt;$&amp;gt;const$&lt;/span&gt;, or just not have such large volumes).&#xA;Note that the &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt; part can be handled by the depth buffer. Obviously you can use a compute shader, or use additional buffers to perform all of this. The function &lt;span class=&quot;math-container&quot;&gt;$attenuate$&lt;/span&gt; can be standard Beer-Lambert uniform attenuation or whatever else you want. Combining the volumes with the original scene happens by setting the &quot;far plane&quot; for each pixel to the closest drawn solid geometry depth (that is initialize &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt; based on what you have in the depth buffer for your solid geometry).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-04-04T16:20:06.560" LastActivityDate="2019-04-04T16:20:06.560" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8728" PostTypeId="2" ParentId="8704" CreationDate="2019-04-03T15:15:33.603" Score="4" Body="&lt;p&gt;So,&lt;/p&gt;&#xA;&lt;p&gt;A lot of folks would tell you that a 4x4 matrix is used so you can get a translation component rolled into your linear transformation. Meaning that with a 3x3 matrix you can only compute rotations, scales, and shears. (and some would argue that a shear is really another type of rotation) This same person might also go into great detail about affine transformations and homogeneous coordinate systems. And they would be right.&lt;/p&gt;&#xA;&lt;p&gt;But that's not the reason.&lt;/p&gt;&#xA;&lt;p&gt;All this might leave the astute observer thinking, well wouldn't a 3x3 matrix get the transformation out of the way then just use vector math to add our translation on at the end saving lots of special math, hardware, and precious resources?&lt;/p&gt;&#xA;&lt;p&gt;Well this is perfectly plausible, and a little extra thinking would leave use with the idea of adding a 4th column/row to our matrix giving a 3x4 matrix. Now, a translation is suddenly perfectly plausible and would create a pretty world where you can do all the operations needed to move and deform objects all day long saving lots of math and resource. And you would be right. You can in fact&#xA;do this very thing when computing your Model and View matrices. Handling vectors would require a little extra trickery but we could manage it.&lt;/p&gt;&#xA;&lt;p&gt;So, now, on this theoretical video card, since all this has to be implemented in hardware, we have gotten or world models/meshs/blobs whatnots and whathaveyous all into place and are ready to project them from our 3D world onto our 2D screen. And we think: this too isn't a problem since a projection is really just a non-linear scaling operation that squeezes things around so the stuff we want to see falls inside our clipping volume.&lt;/p&gt;&#xA;&lt;p&gt;A little bit of algebra later...&lt;/p&gt;&#xA;&lt;p&gt;We have mountains of triangles all of which are ready to have their attributes computed, and interpolations...well interpolated. We then use standard interpolation, check our work very carefully and what we get on our video monitor looks like some kind of star trek space anomaly got hold of it.&lt;/p&gt;&#xA;&lt;p&gt;This is where the problem comes up: It turns out that you can't just interpolate values directly after performing a perspective projection. Instead you must use a special form of interpolation called...wait for it...Perspective Correct Interpolation. And the solution to perspective correct interpolation leads use to the correct form of the projection matrix which has 4 rows and 4 columns. That matrix after being applied to a 4 component position vector results in a nonzero value in the w component of the vector. This value will be specific to each triangle depending on how it is oriented. And, at long last, the video card hardware can perform interpolation on all the values for our triangles, including colors, texture coordinates, normal vectors, ect. Then when that it is all done, hardware can perform the &amp;quot;perspective divide&amp;quot; resulting in correctly interpolated values for the triangles, along with correctly interpolated attributes.&lt;/p&gt;&#xA;&lt;p&gt;And that is the real reason everyone everywhere uses 4x4 matrices in hardware and why they are littered throughout API's like OpenGL. Hardware vendors could probably hack their way around some of the math related to translations and transformations but when it comes to projection, you really can't get away from the 4x4 matrix. (but you can sure optimize the heck out of it)&lt;/p&gt;&#xA;&lt;p&gt;The math for deriving the correct form of a projection isn't to terribly complicated, but the full explanation is fairly long so I will defer to a good book for that, and the best explanation I have seen for deriving a projection matrix that will allow perspective correct interpolation is chapter 6, section 6.2 of the Lengyel book, &amp;quot;Foundations of Game Engine Development&amp;quot;.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2020-07-16T20:01:41.413" LastActivityDate="2020-07-16T20:01:41.413" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8729" PostTypeId="1" AcceptedAnswerId="8735" CreationDate="2019-04-03T17:01:30.820" Score="1" ViewCount="63" Body="&lt;p&gt;Is there an efficient way to identify the plane of symmetry in a 3D mesh? Preferably with existing code / software but if anyone knows how to implement it that would also be helpful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example of the problem: you have a 3D mesh of a duck that is centered at the origin. The correct answer in this case would be the plane where x = 0.&lt;/p&gt;&#xA;" OwnerUserId="7622" LastActivityDate="2019-04-04T06:11:13.430" Title="Identify plane of symmetry in 3D mesh" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8730" PostTypeId="1" CreationDate="2019-04-03T17:03:39.923" Score="1" ViewCount="1632" Body="&lt;p&gt;I was wondering if there's any known technique/algorithm that would compute a mesh generated by the marching cubes but hierarchically (like a divide and conquer strategy), in the implementation I know (that follows the original paper) the marching cubes is an incremental algorithm that iterates through all the voxels (regardless if they're empty or not) and it will produce from 1 to 4 triangles per voxel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Either this or a very fast implementation of marching cubes is fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I cannot manage to find any reference.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2019-07-12T13:01:10.113" Title="Very efficient/fast marching cube implementation" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8731" PostTypeId="1" CreationDate="2019-04-03T17:54:26.537" Score="-1" ViewCount="993" Body="&lt;p&gt;I have been trying to implement GLM (math library) into Visual Studio with OpenGL. I have followed and watched many online resources that point me to include only the GLM folder inside the downloadable zip file into Visual Studio. I believe I have also put the correct relative path in the additional include directories tab. I put the GLM folder into a file I named src/vendor, along with another header file that already works correctly. Visual Studio also is able to be include GLM as #include &quot;glm/glm.hpp&quot;. The configuration is set properly as well, as in it matches debug/x86. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is apparent when I build the project though, as it is saying that it cannot find any files with the path &quot;src\vendor\glm\test\core\&lt;em&gt;randomheaderfiles&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All the resources have not said to include the test file of the downloadable zip, or any other file for that matter, except the &quot;glm&quot; file. So what is the issue? I also get a warning saying &quot;Two or more files with the name of glm.cpp will produce outputs to the same location&quot;, but they both have the same path of &quot;src\vendor\glm\detail\glm.cpp&quot;, and I only found one of those files with that name there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I did try to put the &quot;test&quot; file of the GLM downloadable zip file into the project as well, but that did not seem to help.&lt;/p&gt;&#xA;" OwnerUserId="10426" LastActivityDate="2019-05-04T07:02:25.503" Title="Difficulty including GLM into Visual Studio with OpenGL" Tags="&lt;opengl&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8732" PostTypeId="1" CreationDate="2019-04-03T18:50:52.213" Score="1" ViewCount="122" Body="&lt;p&gt;According to this &lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;note&lt;/a&gt;, Frostbite use photometry unit in their calculation. I am trying to mimic this feature, but I am not sure what transformation need to be done. I will try to explain what I have in mind.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First we do gamma correction(pow(2.2)) to the albedo texture. Then we apply the BRDF that takes luminance as input and will produce output luminance. After that we do tonemapping(say we use filmic tone mapping) and then inverse gamma correct pow(1/2.2) and store it to the framebuffer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this process correct? Should I transform the luminance to radiance first before doing the tonemap or maybe I should convert it even before that when doing BRDF calculation? Do I need to convert the albedo with photometry curve after doing gamma correction?&lt;/p&gt;&#xA;" OwnerUserId="8565" LastActivityDate="2019-04-05T09:45:14.540" Title="How to implement physically based unit in pbr renderer" Tags="&lt;pbr&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8733" PostTypeId="2" ParentId="8721" CreationDate="2019-04-04T05:10:28.810" Score="0" Body="&lt;p&gt;An &lt;a href=&quot;https://en.wikipedia.org/wiki/Equirectangular_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;equirectangular projection&lt;/a&gt; treats the x coordinate as the angle theta around the vertical axis going from 0 to 360 degrees. These angles match the longitudinal angles of a globe. The y coordinate is treated as the angle phi that represents the latitudes of a globe. They typically go from +90° at the zenith (or north pole) to -90° at the nadir (or south pole).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So to translate the center of projection of an image by some amount (x0, y0), you  can simply add x0 to the x value of every coordinate (wrapping around to the other side at the edges). The y coordinate is similar - add y0 to every coordinate.  However, instead of wrapping around, you need to reflect the value. So if your new coordinate is less than 0, simply take the absolute value. If it's greater than the height, take the difference between the new value and the height of the image and subtract that from the height of the image. If it was less than 0 or greater than height then you need to also add half the width to the x coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So putting it in pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;newY = oldY + translateY;&#xA;if (newY &amp;lt; 0)&#xA;{&#xA;    newY = fabs(newY);&#xA;    translateX = fmod((translateX + (width / 2.0)), width);&#xA;}&#xA;else if (newY &amp;gt;= height)&#xA;{&#xA;    newY = height - (newY - height);&#xA;    translateX = fmod((translateX + (width / 2.0)), width);&#xA;}&#xA;newX = oldX + translateX;&#xA;if (newX &amp;lt; 0)&#xA;{&#xA;    newX = width + newX;&#xA;}&#xA;else if (newX &amp;gt;= width)&#xA;{&#xA;    newX = newX - width;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-04-04T05:10:28.810" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8734" PostTypeId="2" ParentId="8731" CreationDate="2019-04-04T06:06:36.230" Score="0" Body="&lt;p&gt;Most likely it's a problem with how you have provided relative path to library in visual studio &quot;Additional Include Directories&quot; section. What happens when you right click on  #include &quot;glm/glm.hpp&quot; line in visual studio and say &quot;Open document &quot;glm/glm.hpp&quot;? I am sure you have tried this but just minor check to see if include path is correct or not. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2019-04-04T06:06:36.230" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8735" PostTypeId="2" ParentId="8729" CreationDate="2019-04-04T06:11:13.430" Score="2" Body="&lt;p&gt;You can look into this: &lt;a href=&quot;https://cescg.org/wp-content/uploads/2017/03/Dvo%C5%99%C3%A1k-Estimating-Approximate-Plane-of-Symmetry-of-3D-Triangle-Meshes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://cescg.org/wp-content/uploads/2017/03/Dvo%C5%99%C3%A1k-Estimating-Approximate-Plane-of-Symmetry-of-3D-Triangle-Meshes.pdf&lt;/a&gt;&#xA;There are definitely other papers on the subject though&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-04-04T06:11:13.430" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8736" PostTypeId="2" ParentId="8730" CreationDate="2019-04-04T17:03:32.227" Score="1" Body="&lt;p&gt;This seems to be eluding to a Marching Cubes LOD algorithm such as: Place the entire volume in one giant cube. Break that volume into NxNxN cubes. And continue doing so until the cubes are at the finest granularity needed for the density function about 8 level works. Each volume then responds with either: No voxels - stop processing that sub volume OR Yes there are voxels -- process the sub volumes and keeping doing this until:  the voxel level is reached. Finally set a LOD - such as equating a screen space distance range to each subvolume level and treat the subvolume for that LOD as the final voxel. Cracks are a major issue with this algorithm and why you won't see many implementation of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is also Eric Lengyel's Transvoxel algorithm: &lt;a href=&quot;https://transvoxel.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://transvoxel.org&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and here is a link an implementation of it&#xA;&lt;a href=&quot;https://github.com/stoyannk/voxels&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/stoyannk/voxels&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2019-04-04T17:13:35.787" LastActivityDate="2019-04-04T17:13:35.787" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8737" PostTypeId="1" AcceptedAnswerId="8738" CreationDate="2019-04-05T00:35:06.787" Score="4" ViewCount="140" Body="&lt;p&gt;My lecturer for a computer graphics (raytracing) paper has stated that &lt;i&gt;'It is easier to apply the inverse transform to the world than it is to apply the transform to the camera.'&lt;/i&gt; The example given was that is it easier to shift all objects in a scene 5 units to the left than it is to shift the camera 5 units to the right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems to imply that it's easier to iterate through and transform multiple objects in a scene than it is to apply a single transformation to the camera. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this correct, and if so, why is this the case?&lt;/p&gt;&#xA;" OwnerUserId="10431" LastActivityDate="2019-05-05T06:01:20.423" Title="Why is it easier to inverse transform every object in a scene than to transform a camera?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8738" PostTypeId="2" ParentId="8737" CreationDate="2019-04-05T04:49:23.210" Score="2" Body="&lt;p&gt;That's actually incorrect. You can transform every ray of your camera if you wish (and numerous implementations do so). There are some advantages and disadvantages to each method (e.g. if your rays are more than your vertices you end up doing more transformations, however you don't incur cache misses by running over all vertices).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-04-05T04:49:23.210" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8739" PostTypeId="2" ParentId="8732" CreationDate="2019-04-05T09:45:14.540" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;First we do gamma correction&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Make sure you actually need to do gamma correction on the albedo texture (or rather &quot;uncorrection&quot;, i.e. making it linear). Not all textures are stored in sRGB color space. Also, you're doing it the wrong way around: Going from sRGB to linear color space you need to do the &lt;code&gt;pow(1/2.2)&lt;/code&gt; part here and the &lt;code&gt;pow(2.2)&lt;/code&gt; part in the end.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Should I transform the luminance to radiance first before doing the tonemap or maybe I should convert it even before that when doing BRDF calculation?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;Yes you should convert before doing the BRDF calculation. Tonemapping is not a feature that's part of the actual physical simulation of light, therefore it doesn't &quot;need&quot; any physical units. The BRDF however is, and here you should make sure that your units &quot;add up&quot;. E.g. you wouldn't calculate the surface area of a rectangle by using meters as the unit for one side and inches as the unit for another side.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Do I need to convert the albedo with photometry curve after doing gamma correction?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;I'm not entirely sure here, but I think you don't need to do that. The albedo color basically tells you, how much of a certain light will be reflected. Since you change your light to photometric units (if you do it as suggested in the Frostbite notes), than I would say this already taken care of. You could also look at it like this: Since the color is a ratio and thus unit-less, there is no need to convert it from unit to another.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2019-04-05T09:45:14.540" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8740" PostTypeId="1" CreationDate="2019-04-05T09:59:59.973" Score="0" ViewCount="512" Body="&lt;p&gt;I am trying to generate UV coordinates automatically to map a texture on a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is with seams when going from 0.8 to 0.2 there is a discontinuity and interpolation in fragment shader is incorrect. It should go from 0.8 to 1 and then from 1 to 0.2. But instead it will interpolate directly between 0.8 to 0.2.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/UV_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/UV_mapping&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2HK25.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2HK25.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UPDcX.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UPDcX.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to handle this discontinuity from 1 -&gt; 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is what is currently happening at the seams &#xA;&lt;a href=&quot;https://i.stack.imgur.com/6Fg4m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6Fg4m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10435" LastActivityDate="2019-04-05T15:57:45.490" Title="Sphere Texture Mapping Algorithm" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;uv-mapping&gt;&lt;directx&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8741" PostTypeId="2" ParentId="8740" CreationDate="2019-04-05T15:57:45.490" Score="1" Body="&lt;p&gt;A few options:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Make the 0-1 discontinuity explicit in the mesh. That is create a 2 sets of vertices that lie exactly on the line where the value would be 1 or 0 (one set gets 1 and one gets 0) then connect the vertices up like they would makes sense.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Switch to a different texture mapping projection, I prefer a cubemap because it minimizes distortion at the poles and you don't need to have seams in the mesh.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-04-05T15:57:45.490" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8742" PostTypeId="1" AcceptedAnswerId="8746" CreationDate="2019-04-06T14:04:33.583" Score="4" ViewCount="353" Body="&lt;p&gt;If I have a straight line in 3D space and I use a camera matrix to do a perspective projection into a 2D plane/screen will the resulting line always be straight too? If I project the start point and end point and join the dots is that equivalent to having projected the line?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect this is true, but have no basis for this assumption. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this still true for off-centre perspective projection or a cylindrical projection? I assume this isn't true for real cameras as they have all kinds of non-ideal optical effects right?&lt;/p&gt;&#xA;" OwnerUserId="10447" LastActivityDate="2019-04-09T16:23:05.473" Title="Do straight lines always remain straight when projected with a perspective camera?" Tags="&lt;geometry&gt;&lt;projections&gt;&lt;perspective&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8743" PostTypeId="1" CreationDate="2019-04-06T17:13:08.450" Score="3" ViewCount="56" Body="&lt;p&gt;I am having trouble implementing an algorithm for 3rd degree NURBS.&#xA;I have been able to program 2nd degree ones from the equations described &lt;a href=&quot;https://www.codeproject.com/Articles/996281/NURBS-curve-made-easy&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;equations&quot;&gt;here&lt;/a&gt; but I am not able to derive an equation for Rational B-Splines of degree 3. The author describes the Rational Knot Equation as &lt;a href=&quot;https://i.stack.imgur.com/kmIJK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kmIJK.jpg&quot; alt=&quot;NURBS&quot;&gt;&lt;/a&gt; that is a non-recursive form of the &lt;a href=&quot;https://en.m.wikipedia.org/wiki/De_Boor%27s_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;De Boor's Algorithm&lt;/a&gt; from there I was able to program &lt;strong&gt;Rational Internal Control Points: Bn&lt;/strong&gt; and &lt;strong&gt;Cn&lt;/strong&gt; as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/* Note that I had to modify the equations to work from the first point on the list as the ones described in the article only took into account points from the second index **Pn+1**. I though that could have been the problem and rewrote them as they where originally written but that did not solve the issue, so I am posting the ones that work from **Pn** */&#xA;&#xA;// Point B. &#xA;/* Iterate over the points(3d vector), knots(double) and weights(double) lists to get the Internal Control Points(3d vector) for the 3rd degree Bézier curves. */&#xA;&#xA; // Precompute:&#xA;double knotE = ( knots[i + 4] - knots[i + 2] ) / ( knots[i + 4] - knots[i + 1] );&#xA;double knotEO = ( knots[i + 2] - knots[i + 1] ) / ( knots[i + 4] - knots[i + 1] );&#xA;&#xA;double rationalWeight = (  weights[i] * knotE ) + ( weights[i + 1] * knotEO );&#xA;double w1 = weights[i] / rationalWeight;&#xA;double w2 = weights[i + 1] / rationalWeight;&#xA;&#xA;/* Our Point3d class lets us multiply a vector by a scalar. */&#xA;Point3d b = new Point3d( ( knotE * points[i] * w1 ) + ( knotEO * points[i + 1] * w2 ) );&#xA;&#xA;// Point C. &#xA;/* Iterate over the points, knots and weights lists to get the Internal Control Points for the 3rd degree Bézier curves. */&#xA;&#xA; // Precompute:&#xA;double knotE = ( knots[i + 4] - knots[i + 3] ) / ( knots[i + 4] - knots[i + 1] );&#xA;double knotEO = ( knots[i + 3] - knots[i + 1] ) / ( knots[i + 4] - knots[i + 1] );&#xA;&#xA;double rationalWeight = (  weights[i] * knotE ) + ( weights[i + 1] * knotEO );&#xA;double w1 = weights[i] / rationalWeight;&#xA;double w2 = weights[i + 1] / rationalWeight;&#xA;&#xA;/* Our Point3d class lets us multiply a vector by a scalar. */&#xA;Point3d c = new Point3d( ( knotE * points[i] * w1 ) + ( knotEO * points[i + 1] * w2 ) );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But when I apply the same process for point &lt;strong&gt;Vn&lt;/strong&gt; I get results that are not the ones I am looking for:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Point V. &#xA;/* Iterate over the c, b, knots and weights lists to get the Internal Control Points for the 3rd degree Bézier curves. */&#xA;&#xA; // Precompute:&#xA;double knotE = ( knots[i + 4] - knots[i + 3] ) / ( knots[i + 4] - knots[i + 2] );&#xA;double knotEO = ( knots[i + 3] - knots[i + 2] ) / ( knots[i + 4] - knots[i + 2] );&#xA;&#xA;double rationalWeight = (  weights[i] * knotE ) + ( weights[i + 1] * knotEO );&#xA;double w1 = weights[i] / rationalWeight;&#xA;double w2 = weights[i + 1] / rationalWeight;&#xA;&#xA;/* Our Point3d class lets us multiply a vector by a scalar. */&#xA;Point3d v = new Point3d( ( knotE * c[i] * w1 ) + ( knotEO * b[i + 1] * w2 ) );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When all the weights are the same the points respond as expected, when the weights are not the same points &lt;strong&gt;Bn&lt;/strong&gt; and &lt;strong&gt;Cn&lt;/strong&gt; work as they should but &lt;strong&gt;Vn&lt;/strong&gt; responds incorrectly. So my &lt;strong&gt;Vn Equation&lt;/strong&gt; must be wrong. As the function inputs &lt;strong&gt;Bn&lt;/strong&gt; and &lt;strong&gt;Cn&lt;/strong&gt; lists of points my guess is that I am missing a relationship between those two equations with the one I am having trouble with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As my problem is with the mathematical concept instead of an inplementation this is considered a language agnostic question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a picture of a 3d degree UniformBSpline &lt;a href=&quot;https://i.stack.imgur.com/29xeO.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/29xeO.jpg&quot; alt=&quot;UBS&quot;&gt;&lt;/a&gt; which I programmed succesfully already but that may help if the link to the resource goes down.&lt;/p&gt;&#xA;" OwnerUserId="9749" LastEditorUserId="9749" LastEditDate="2019-04-06T19:11:50.997" LastActivityDate="2019-04-06T19:11:50.997" Title="NURBS Weights De Boor's Algorithm" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8746" PostTypeId="2" ParentId="8742" CreationDate="2019-04-08T19:20:37.263" Score="2" Body="&lt;p&gt;&quot;A not so simple approach&quot;. I may have messed a little bit too much with grouping the terms, do forgive my elementary math skills, it's a side effect of using tools like wolfram and mathematica too much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Without loss of generality we can assume that the near plane is given as &lt;span class=&quot;math-container&quot;&gt;$z=1$&lt;/span&gt; (that is having normal &lt;span class=&quot;math-container&quot;&gt;$(0,0,1)$&lt;/span&gt; and a point on it &lt;span class=&quot;math-container&quot;&gt;$(0,0,1)$&lt;/span&gt;) and the camera center (the reflected pinhole camera aperture point) is at &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt;. Let &lt;span class=&quot;math-container&quot;&gt;$p,q \in \mathbb{R}^3$&lt;/span&gt; be two points on a line (non-degenerate, meaning &lt;span class=&quot;math-container&quot;&gt;$p\ne q$&lt;/span&gt;, otherwise it's just a point and the projection is also a point - unless it's at &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; then it's undefined). If the line defined by &lt;span class=&quot;math-container&quot;&gt;$p,q$&lt;/span&gt; passes through &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; the projection is a point and the requirement is trivially satisfied.&#xA;Now let this not be the case. A perspective projection onto the plane through &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt; is given by &lt;span class=&quot;math-container&quot;&gt;$p' = \frac{p}{p_z}$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$q' = \frac{q}{q_z}$&lt;/span&gt;. The line defined by &lt;span class=&quot;math-container&quot;&gt;$p,q$&lt;/span&gt; is given as &lt;span class=&quot;math-container&quot;&gt;$r(\lambda) = p + \lambda(q-p), \lambda \in  \mathbb{R}$&lt;/span&gt;. Its projection is given by &lt;span class=&quot;math-container&quot;&gt;$r'(\lambda) = \frac{r(\lambda)}{r_z(\lambda)}$&lt;/span&gt;. Since &lt;span class=&quot;math-container&quot;&gt;$z=1$&lt;/span&gt; for all projected points, then we need only study the &lt;span class=&quot;math-container&quot;&gt;$x,y$&lt;/span&gt; coordinates. We want to show that any projected point &lt;span class=&quot;math-container&quot;&gt;$r'(\lambda)$&lt;/span&gt; can be written as an affine combination of &lt;span class=&quot;math-container&quot;&gt;$p',q'$&lt;/span&gt; (this defines a line). Taking that into account:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$p'+\mu(q'-p') = \frac{r(\lambda)}{r_z(\lambda)}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(1-\mu)\frac{p}{p_z} + \mu\frac{q}{q_z} = \frac{p + \lambda(q-p)}{p_z + \lambda(q_z-p_z)}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(1-\mu)q_z(p_z+\lambda(q_z-p_z))p + \mu p_z(p_z+\lambda(q_z-p_z))q = q_zp_z(p + \lambda(q-p))$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$q_zp_z(p - \lambda p) + q^2_z\lambda p - \mu q_z(p_z+\lambda(q_z-p_z))p + \mu p_z(p_z+\lambda(q_z-p_z))q - q_zp_z(p - \lambda p) - q_zp_z\lambda q = 0$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(1-\mu)\lambda q^2_z p -\mu(1-\lambda)q_zp_z p + \mu(1-\lambda)p^2_zq - (1-\mu)\lambda p_zq_z q = 0$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(1-\mu)\lambda q_z(q_zp - p_zq) - \mu(1-\lambda)p_z(q_zp-p_zq) = 0$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$((1-\mu)\lambda q_z - \mu(1-\lambda)p_z)(q_zp - p_zq) = 0$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this to be satisfied one of the terms must be &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;. The first case concerns the second term: &lt;span class=&quot;math-container&quot;&gt;$p' = q'$&lt;/span&gt;, which we already considered as the trivial case. Then we must show that we can always pick a &lt;span class=&quot;math-container&quot;&gt;$\mu$&lt;/span&gt; such that &lt;span class=&quot;math-container&quot;&gt;$(1-\mu)\lambda q_z - \mu(1-\lambda)p_z = 0$&lt;/span&gt;. Solve for &lt;span class=&quot;math-container&quot;&gt;$\mu$&lt;/span&gt; and you get: &lt;span class=&quot;math-container&quot;&gt;$\mu = \frac{\lambda q_z}{(1-\lambda)p_z + \lambda q_z}$&lt;/span&gt;. Thus I have not only found that it is a straight line, but also the relationship between the parameterizations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general a projection onto a different 2-manifold (not a plane) will not result in the lines remaining straight (think of a sphere or a cylinder).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-04-09T16:23:05.473" LastActivityDate="2019-04-09T16:23:05.473" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8747" PostTypeId="1" CreationDate="2019-04-09T13:47:48.937" Score="2" ViewCount="189" Body="&lt;p&gt;Background: I'm reading &lt;a href=&quot;https://learnopengl.com/PBR&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://learnopengl.com/PBR&lt;/a&gt; to learn about PBR. In the theory slide (&lt;a href=&quot;https://learnopengl.com/PBR/Theory&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://learnopengl.com/PBR/Theory&lt;/a&gt;), the author has the reflectant equation as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LViWC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LViWC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The theta (the angle between normal vector and the incoming light) is in the denominator. However, on the lighting slide (&lt;a href=&quot;https://learnopengl.com/PBR/Lighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://learnopengl.com/PBR/Lighting&lt;/a&gt;) he has the familiar code for the radiance of a light source, which makes the &lt;span class=&quot;math-container&quot;&gt;$\cos(\theta)$&lt;/span&gt; on the numerator.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3  lightColor  = vec3(23.47, 21.31, 20.79);&#xA;vec3  wi          = normalize(lightPos - fragPos);&#xA;float cosTheta    = max(dot(N, Wi), 0.0);&#xA;float attenuation = calculateAttenuation(fragPos, lightPos);&#xA;float radiance    = lightColor * attenuation * cosTheta;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Can someone explain this fine point to me?&lt;/p&gt;&#xA;" OwnerUserId="10461" LastEditorUserId="5778" LastEditDate="2019-04-12T17:17:54.563" LastActivityDate="2019-04-12T17:17:54.563" Title="Why is cos() in the denominator in the reflectance equation and in the numerator in the shading equation?" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8748" PostTypeId="2" ParentId="8747" CreationDate="2019-04-09T15:12:57.577" Score="1" Body="&lt;p&gt;The first is a definition of radiance in terms of the flux - it's a the derivative of flux with respect to both area and direction. It's simply a relation between &lt;span class=&quot;math-container&quot;&gt;$\Phi$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;. It simply says that if you integrate radiance over the area of some surface, and for each point you integrate over all possible directions, then you will get the flux arriving/leaving that surface.&#xA;The second part comes from the restriction of the rendering equation to a single point light source.&#xA;Remember that:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L(x,\omega_o) = L_e(x,\omega_o) + \int_{\Omega}{f(\omega_o,x,\omega_i)L_i(x,\omega_i)\cos\theta_i \,d\omega_i}$$&lt;/span&gt;&#xA;Where &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is a point on some surface, and &lt;span class=&quot;math-container&quot;&gt;$L(x,\omega_o)$&lt;/span&gt; gives you the radiance incoming from &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; in the direction &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;. This radiance is the sum of emitted radiance from &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; in direction &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;: &lt;span class=&quot;math-container&quot;&gt;$L_e(x,\omega_o)$&lt;/span&gt;, and the scattered radiance by &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; in direction &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;. The integral is necessary, since light may arrive from any direction at &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, so you need to integrate over all directions. &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; is the brdf, which really tells you how much of the light arriving from direction &lt;span class=&quot;math-container&quot;&gt;$\omega_i$&lt;/span&gt; is reflected towards &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt; at &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$L_i(x,\omega_i)$&lt;/span&gt; is the incoming radiance from direction &lt;span class=&quot;math-container&quot;&gt;$\omega_i$&lt;/span&gt; at &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, and the cosine is there to account for Lambert's law. What happens when you evaluate only direct lighting from a point light is that the integral is over a domain that is a single point, so you get only the integrand part, which you have in your code. Note that this is just an intuitive explanation, there are various issues with radiance not being defined for point lights.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-04-09T15:12:57.577" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8750" PostTypeId="1" CreationDate="2019-04-10T10:46:50.000" Score="-1" ViewCount="124" Body="&lt;p&gt;What problems haven't been solved yet when it comes for instance in rendering,deferred rendering, Volumetric lighting, ambient occlusion or in any other interesting area. When i say unsolved problems, i mean topics in computer graphics that haven't been entirely solved and need serious improvement and maybe new techniques.&lt;/p&gt;&#xA;" OwnerUserId="10468" LastActivityDate="2019-04-10T13:00:37.867" Title="Unsolved Problems in CQ to this day?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;deferred-rendering&gt;&lt;volumetric&gt;&lt;ambient-occlusion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8751" PostTypeId="2" ParentId="8750" CreationDate="2019-04-10T13:00:37.867" Score="-1" Body="&lt;p&gt;I am unsure whether you're talking about realistic image synthesis or realtime rendering, but either way these two are somewhat connected. The biggest issues in real time rendering are really finding good approximations of the algorithms used in realistic image synthesis, and the effective implementation of those, as well as hardware that supports this - think RTX atm. RTX in games however is pretty limited - it is highly biased (you can't even call it a good approximation of the rendering equation for most non-trivial scenes), so we're still at a point where rasterization based graphics dominate. Ray tracing has many advantages however, like its average O(logn) complexity versus rasterization's O(n) (where you can think of n as number of triangles in a scene). Note that this is asymptotic notation, so the main reason why ray tracing is not currently faster than rasterization is that: 1) the current hardware is highly optimized for rasterization, 2) the number of drawn triangles needs to be relatively large to offset the constant (it's unclear whether so many triangles would even be necessary for a realistic representation of shapes). There are however effects and realism which you simply cannot achieve with the &quot;hacks&quot; from rasterization graphics, ray tracing (or more precisely path tracing) is what we're aiming at- when you hit that for complex enough scenes/materials/participating media at interactive rates you've basically achieved photorealism.&#xA;Now as far as unsolved problems in realistic image synthesis go, there are many. They range from good sampling distributions (the best samplers that we know of currently for CG are usually Owen scrambled Sobol, and some low-discrepancy sequences with blue noise properties - but those usually do not extend as well to higher dimensions), good approximations of the radiance in a scene (there are some recent papers from Vorba and Muller on the topic, they usually call it path guiding), dealing with participating media and complex brdfs (think subsurface scattering), spectral rendering (while there are several techniques for this, you can prove that each of those is bad in some aspect), the theory in general dates back to &quot;Lambert's antiquated framework&quot;, and while there have been attempts to modernize it similar to what's been done to other fields in physics for example, the best attempt at that as far as I am aware is Christian Lessig's thesis and the publications following it (which btw do not manage to solve the issue outlined fully). You can say that most problems in realistic image synthesis are actually unsolved - the problem is simply very hard mathematically.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-04-10T13:00:37.867" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8752" PostTypeId="1" CreationDate="2019-04-11T00:06:28.447" Score="2" ViewCount="653" Body="&lt;p&gt;When it comes to line drawing, &lt;a href=&quot;https://www.geeksforgeeks.org/dda-line-generation-algorithm-computer-graphics/&quot; rel=&quot;nofollow noreferrer&quot;&gt;DDA&lt;/a&gt; is the simplest and most intuitive algorithm, the core idea being:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;compute the slope of the line&lt;/li&gt;&#xA;&lt;li&gt;for every increment in x, increment y by the slope&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;However, DDA is not favored due to its use of floating point operations. In fact, avoiding floating point operations is a common theme in graphics. I am wondering about the relative cost of floating point operations versus integer operations in modern GPU's&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I could do some benchmarking but my CUDA is rusty. There is a &lt;a href=&quot;https://stackoverflow.com/q/2550281/1382487&quot; title=&quot;Floating point vs integer calculations on modern hardware&quot;&gt;question on SO&lt;/a&gt; and the common wisdom there seems to be, &quot;it depends&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is specific to computer graphics and line drawing. If a more general answer can be given, that will also be appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To state my question specifically, is it important with modern GPU architectures to avoid floating point operations in favor of integer operations?&lt;/p&gt;&#xA;" OwnerUserId="10475" LastActivityDate="2019-04-12T04:14:37.567" Title="Floating Point Operations in Line Drawing Algorithms" Tags="&lt;gpu&gt;&lt;line-drawing&gt;&lt;efficiency&gt;&lt;float&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8754" PostTypeId="1" CreationDate="2019-04-11T02:31:28.173" Score="3" ViewCount="375" Body="&lt;p&gt;I followed the book &lt;a href=&quot;http://www.realtimerendering.com/raytracing/Ray%20Tracing%20in%20a%20Weekend.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing in One Weekend&lt;/a&gt; and implemented a simple ray tracing procedure. There are 100 &lt;strong&gt;random&lt;/strong&gt; samples every pixel for antialiasing, but the render result looks weird: There is a unnatural circle at the center of the screen, and a strange line lies on the center of the ground, Why?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/UrdGyPm.png&quot; alt=&quot;render result&quot;&gt;&lt;/p&gt;&#xA;" OwnerUserId="10476" LastEditorUserId="10476" LastEditDate="2019-04-11T09:08:42.887" LastActivityDate="2019-04-12T02:27:54.017" Title="Why the ray tracing result looks weird?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8755" PostTypeId="2" ParentId="8754" CreationDate="2019-04-11T04:42:12.117" Score="1" Body="&lt;p&gt;Those are &lt;a href=&quot;https://en.wikipedia.org/wiki/Moir%C3%A9_pattern&quot; rel=&quot;nofollow noreferrer&quot;&gt;moire patterns&lt;/a&gt;. They are  an aliasing artifact that usually occurs when sampling on a regular grid. Did you jitter the positions of your samples? If you just sampled an evenly spaced 10x10 grid within each pixel, that could explain it. Also, numerical errors or inaccuracy could it.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2019-04-12T02:27:54.017" LastActivityDate="2019-04-12T02:27:54.017" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8757" PostTypeId="1" CreationDate="2019-04-11T06:12:37.130" Score="1" ViewCount="363" Body="&lt;p&gt;Suppose I have code to generate a bunch of frames, each of which is a depth map(I have access to the matrices which represent depth) which in turn is used to generate a point cloud. One frame would look like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mo5TN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mo5TN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short I have a point cloud corresponding to each frame. How would I generate a video where each point cloud in a frame is meshed together? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there frameworks which handle this kind of data? I am assuming OpenGL should help but I am not sure if it can do this.&lt;/p&gt;&#xA;" OwnerUserId="10478" LastActivityDate="2021-05-06T01:14:43.213" Title="Rendering 3-D point clouds obtained from depth maps as a 2.5D video" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;video&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8758" PostTypeId="2" ParentId="8757" CreationDate="2019-04-11T06:32:48.300" Score="1" Body="&lt;p&gt;Depending on your application, you could use image-based solutions that are much cheaper than meshing a uniformly sampled set of points. For example, you could use the depth map as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Heightmap&quot; rel=&quot;nofollow noreferrer&quot;&gt;height map&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many techniques that allow you to render it in an efficient way, the more realistic the more difficult to code as a shader (but not too much). From easiest to harder:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Heightmap&quot; rel=&quot;nofollow noreferrer&quot;&gt;height maps&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;normal maps&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Displacement_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;displacement mapping&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Parallax_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;parallax mapping&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;geometry shaders to recreate the actual mesh from a set of primitives and the depth map&lt;/li&gt;&#xA;&lt;li&gt;and so on. &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9908" LastActivityDate="2019-04-11T06:32:48.300" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8760" PostTypeId="5" CreationDate="2019-04-11T23:49:00.667" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2019-04-11T23:49:00.667" LastActivityDate="2019-04-11T23:49:00.667" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8761" PostTypeId="4" CreationDate="2019-04-11T23:49:00.667" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2019-04-11T23:49:00.667" LastActivityDate="2019-04-11T23:49:00.667" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8762" PostTypeId="5" CreationDate="2019-04-11T23:50:02.757" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2019-04-11T23:50:02.757" LastActivityDate="2019-04-11T23:50:02.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8763" PostTypeId="4" CreationDate="2019-04-11T23:50:02.757" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2019-04-11T23:50:02.757" LastActivityDate="2019-04-11T23:50:02.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8764" PostTypeId="2" ParentId="8752" CreationDate="2019-04-12T04:14:37.567" Score="4" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;is it important with modern GPU architectures to avoid floating point operations in favor of integer operations?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Almost certainly not. CPUs have a long history where for many years they only handled integers natively and floating point operations were all done with slow math libraries. That changed about 20-25 years ago, but the thinking has remained entrenched for many years. (And certain applications like finance may require it for other reasons.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern GPUs, though, have always been about doing lots of floating point calculations in parallel. If you think about how most 3D rasterizers (like OpenGL, Metal, DirectX, etc.) work, they take all the vertices, transform them into normalized device coordinates, and then interpolate between them to draw the actual geometry. While you certainly could do that all with fixed point math, it probably wouldn't gain you much. But you also aren't doing those calculations yourself, unless you've written your own rasterizer as a compute kernel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now depending on what type of work you're doing, the precision of the floating point operations may be reduced. In a language like glsl (in OpenGL ES, anyway) you can &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Type_Qualifier_(GLSL)#Precision_qualifiers&quot; rel=&quot;nofollow noreferrer&quot;&gt;specify the precision&lt;/a&gt; of the uniforms. On mobile hardware, it might be worth doing the calculations as floating point, but with only 16 or 24 bits instead of 32 because it saves power,   for example. (And even some desktop GPUs have used lower-precision floating point in the past.) But the desktop hardware of today is optimized for doing floating point work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, I don't see a compelling reason to stick to integer math when working on the GPU.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-04-12T04:14:37.567" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8765" PostTypeId="1" CreationDate="2019-04-13T10:24:12.573" Score="4" ViewCount="145" Body="&lt;p&gt;I am trying to reproduce the results obtained by Dahm et al. in the paper &lt;a href=&quot;https://arxiv.org/pdf/1701.07403v1.pdf?utm_content=buffer5b1d2&amp;amp;utm_medium=social&amp;amp;utm_source=twitter.com&amp;amp;utm_campaign=buffer&quot; rel=&quot;nofollow noreferrer&quot;&gt;Learning Light Transport the Reinforced Way&lt;/a&gt;. &lt;br&gt;&#xA;This method takes advantage of the similarity between the Bellman equation (Q-Learning) and the rendering equation. &lt;br&gt;&#xA;Here's the overview of the code authors inserted in the first version of their paper: &lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VEMXA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VEMXA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 1&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is, in the first function, &lt;code&gt;idxPrev&lt;/code&gt;? Intuition suggests it is the index of the previous cell. &lt;br&gt;&#xA;EDIT: &lt;code&gt;ray.o&lt;/code&gt; is probably the origin. &lt;br&gt;&#xA;Moreover, in the same function, I understand that &lt;code&gt;getLastAttenuation()&lt;/code&gt; returns the color of &lt;code&gt;idxCurr&lt;/code&gt;. How is getLastAttenuation calculated?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question 2&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The action space is discretized, apparently, dividing the hemisphere built on the hitting point in different stratums. According to what I understand, the Q-Learning algorithm finds the best action (so the best stratum) for each cell in the space, and then a ray is scattered randomly in that stratum. But a stratum covers 360 degrees, so I don't see how this is helpful to scattered a ray towards the light. &lt;br&gt;&#xA;In the function &lt;code&gt;sampleScatteringDIrFromQtable()&lt;/code&gt;, the PDF is calculated based on the &lt;code&gt;ps&lt;/code&gt; (not clear) multiplied by the number of patches. So, the action is related to circular stratums of the hemisphere, or the number of patches?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt; &lt;br&gt;&#xA;&lt;strong&gt;Question 3&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I divide the hemispheres over the hitting points in 24 equally-sized patches. Then I scatter rays, for now, not based on a uniform distribution on the hemisphere, but through the center of these 24 equally-sized patched. In this case, what would the PDF be? &lt;/p&gt;&#xA;" OwnerUserId="10191" LastEditorUserId="10191" LastEditDate="2019-05-22T17:53:32.360" LastActivityDate="2019-05-22T17:53:32.360" Title="Learning light transport using Q-Learning" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8766" PostTypeId="1" CreationDate="2019-04-13T17:00:41.700" Score="3" ViewCount="221" Body="&lt;p&gt;When doing clipping in homogeneous coordinates, we need to find the coordinates of the intersection of the viewing frustum with the line to be clipped. This can be done easily if we want those coordinates to be in screen space(simply divide by the fourth coordinate). But how can we find those coordinates in 3D space? And do we need to do so in the first place?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="10492" LastActivityDate="2019-04-24T14:48:28.203" Title="3D coordinates of intersection point in clipping for a rasterizer" Tags="&lt;clipping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8768" PostTypeId="5" CreationDate="2019-04-14T18:20:24.490" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2019-04-14T18:20:24.490" LastActivityDate="2019-04-14T18:20:24.490" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8769" PostTypeId="4" CreationDate="2019-04-14T18:20:24.490" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2019-04-14T18:20:24.490" LastActivityDate="2019-04-14T18:20:24.490" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8770" PostTypeId="1" CreationDate="2019-04-15T05:59:53.510" Score="1" ViewCount="211" Body="&lt;p&gt;I have an ellipse which has -45 degree axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can I transform the ellipse into a circle? Can I use shear transformation along the x/y axis?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aMJhX.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aMJhX.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10500" LastEditorUserId="6" LastEditDate="2019-04-18T11:14:56.143" LastActivityDate="2019-04-20T21:42:43.427" Title="How can I transform an ellipse into a circle?" Tags="&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8771" PostTypeId="1" CreationDate="2019-04-15T10:57:27.440" Score="2" ViewCount="357" Body="&lt;p&gt;Does anyone have experience with open-mesh or computational geometry and can kindly explain what exactly happens in the function below?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PolyConnectivity::FaceHandle&#xA;PolyConnectivity::add_face(const VertexHandle* _vertex_handles, size_t _vhs_size)&#xA;{&#xA;  VertexHandle                   vh;&#xA;  size_t                         i, ii, n(_vhs_size);&#xA;  HalfedgeHandle                 inner_next, inner_prev,&#xA;                                 outer_next, outer_prev,&#xA;                                 boundary_next, boundary_prev,&#xA;                                 patch_start, patch_end;&#xA;&#xA;&#xA;  // Check sufficient working storage available&#xA;  if (edgeData_.size() &amp;lt; n)&#xA;  {&#xA;    edgeData_.resize(n);&#xA;    next_cache_.resize(6*n);&#xA;  }&#xA;&#xA;  size_t next_cache_count = 0;&#xA;&#xA;  // don't allow degenerated faces&#xA;  assert (n &amp;gt; 2);&#xA;&#xA;  // test for topological errors&#xA;  for (i=0, ii=1; i&amp;lt;n; ++i, ++ii, ii%=n)&#xA;  {&#xA;    if ( !is_boundary(_vertex_handles[i]) )&#xA;    {&#xA;      omerr() &amp;lt;&amp;lt; &quot;PolyMeshT::add_face: complex vertex\n&quot;;&#xA;      return InvalidFaceHandle;&#xA;    }&#xA;&#xA;    // Initialise edge attributes&#xA;    edgeData_[i].halfedge_handle = find_halfedge(_vertex_handles[i],&#xA;                                                 _vertex_handles[ii]);&#xA;    edgeData_[i].is_new = !edgeData_[i].halfedge_handle.is_valid();&#xA;    edgeData_[i].needs_adjust = false;&#xA;&#xA;    if (!edgeData_[i].is_new &amp;amp;&amp;amp; !is_boundary(edgeData_[i].halfedge_handle))&#xA;    {&#xA;      omerr() &amp;lt;&amp;lt; &quot;PolyMeshT::add_face: complex edge\n&quot;;&#xA;      return InvalidFaceHandle;&#xA;    }&#xA;  }&#xA;&#xA;  // re-link patches if necessary&#xA;  for (i=0, ii=1; i&amp;lt;n; ++i, ++ii, ii%=n)&#xA;  {&#xA;    if (!edgeData_[i].is_new &amp;amp;&amp;amp; !edgeData_[ii].is_new)&#xA;    {&#xA;      inner_prev = edgeData_[i].halfedge_handle;&#xA;      inner_next = edgeData_[ii].halfedge_handle;&#xA;&#xA;&#xA;      if (next_halfedge_handle(inner_prev) != inner_next)&#xA;      {&#xA;        // here comes the ugly part... we have to relink a whole patch&#xA;&#xA;        // search a free gap&#xA;        // free gap will be between boundary_prev and boundary_next&#xA;        outer_prev = opposite_halfedge_handle(inner_next);&#xA;        outer_next = opposite_halfedge_handle(inner_prev);&#xA;        boundary_prev = outer_prev;&#xA;        do&#xA;          boundary_prev =&#xA;            opposite_halfedge_handle(next_halfedge_handle(boundary_prev));&#xA;        while (!is_boundary(boundary_prev));&#xA;        boundary_next = next_halfedge_handle(boundary_prev);&#xA;&#xA;        // ok ?&#xA;        if (boundary_prev == inner_prev)&#xA;        {&#xA;          omerr() &amp;lt;&amp;lt; &quot;PolyMeshT::add_face: patch re-linking failed\n&quot;;&#xA;          return InvalidFaceHandle;&#xA;        }&#xA;&#xA;        assert(is_boundary(boundary_prev));&#xA;        assert(is_boundary(boundary_next));&#xA;&#xA;        // other halfedges' handles&#xA;        patch_start = next_halfedge_handle(inner_prev);&#xA;        patch_end   = prev_halfedge_handle(inner_next);&#xA;&#xA;        assert(boundary_prev.is_valid());&#xA;        assert(patch_start.is_valid());&#xA;        assert(patch_end.is_valid());&#xA;        assert(boundary_next.is_valid());&#xA;        assert(inner_prev.is_valid());&#xA;        assert(inner_next.is_valid());&#xA;&#xA;        // relink&#xA;        next_cache_[next_cache_count++] = std::make_pair(boundary_prev, patch_start);&#xA;        next_cache_[next_cache_count++] = std::make_pair(patch_end, boundary_next);&#xA;        next_cache_[next_cache_count++] = std::make_pair(inner_prev, inner_next);&#xA;      }&#xA;    }&#xA;  }&#xA;&#xA;  // create missing edges&#xA;  for (i=0, ii=1; i&amp;lt;n; ++i, ++ii, ii%=n)&#xA;    if (edgeData_[i].is_new)&#xA;      edgeData_[i].halfedge_handle = new_edge(_vertex_handles[i], _vertex_handles[ii]);&#xA;&#xA;  // create the face&#xA;  FaceHandle fh(new_face());&#xA;  set_halfedge_handle(fh, edgeData_[n-1].halfedge_handle);&#xA;&#xA;  // setup halfedges&#xA;  for (i=0, ii=1; i&amp;lt;n; ++i, ++ii, ii%=n)&#xA;  {&#xA;    vh         = _vertex_handles[ii];&#xA;&#xA;    inner_prev = edgeData_[i].halfedge_handle;&#xA;    inner_next = edgeData_[ii].halfedge_handle;&#xA;    assert(inner_prev.is_valid());&#xA;    assert(inner_next.is_valid());&#xA;&#xA;    size_t id = 0;&#xA;    if (edgeData_[i].is_new)  id |= 1;&#xA;    if (edgeData_[ii].is_new) id |= 2;&#xA;&#xA;&#xA;    if (id)&#xA;    {&#xA;      outer_prev = opposite_halfedge_handle(inner_next);&#xA;      outer_next = opposite_halfedge_handle(inner_prev);&#xA;      assert(outer_prev.is_valid());&#xA;      assert(outer_next.is_valid());&#xA;&#xA;      // set outer links&#xA;      switch (id)&#xA;      {&#xA;        case 1: // prev is new, next is old&#xA;          boundary_prev = prev_halfedge_handle(inner_next);&#xA;          assert(boundary_prev.is_valid());&#xA;          next_cache_[next_cache_count++] = std::make_pair(boundary_prev, outer_next);&#xA;          set_halfedge_handle(vh, outer_next);&#xA;          break;&#xA;&#xA;        case 2: // next is new, prev is old&#xA;          boundary_next = next_halfedge_handle(inner_prev);&#xA;          assert(boundary_next.is_valid());&#xA;          next_cache_[next_cache_count++] = std::make_pair(outer_prev, boundary_next);&#xA;          set_halfedge_handle(vh, boundary_next);&#xA;          break;&#xA;&#xA;        case 3: // both are new&#xA;          if (!halfedge_handle(vh).is_valid())&#xA;          {&#xA;            set_halfedge_handle(vh, outer_next);&#xA;            next_cache_[next_cache_count++] = std::make_pair(outer_prev, outer_next);&#xA;          }&#xA;          else&#xA;          {&#xA;            boundary_next = halfedge_handle(vh);&#xA;            boundary_prev = prev_halfedge_handle(boundary_next);&#xA;            assert(boundary_prev.is_valid());&#xA;            assert(boundary_next.is_valid());&#xA;            next_cache_[next_cache_count++] = std::make_pair(boundary_prev, outer_next);&#xA;            next_cache_[next_cache_count++] = std::make_pair(outer_prev, boundary_next);&#xA;          }&#xA;          break;&#xA;      }&#xA;&#xA;      // set inner link&#xA;      next_cache_[next_cache_count++] = std::make_pair(inner_prev, inner_next);&#xA;    }&#xA;    else edgeData_[ii].needs_adjust = (halfedge_handle(vh) == inner_next);&#xA;&#xA;&#xA;    // set face handle&#xA;    set_face_handle(edgeData_[i].halfedge_handle, fh);&#xA;  }&#xA;&#xA;  // process next halfedge cache&#xA;  for (i = 0; i &amp;lt; next_cache_count; ++i)&#xA;    set_next_halfedge_handle(next_cache_[i].first, next_cache_[i].second);&#xA;&#xA;&#xA;  // adjust vertices' halfedge handle&#xA;  for (i=0; i&amp;lt;n; ++i)&#xA;    if (edgeData_[i].needs_adjust)&#xA;      adjust_outgoing_halfedge(_vertex_handles[i]);&#xA;&#xA;  return fh;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;More specifically, at the moment, I'd like to understand what exactly happens in the for loop below:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// re-link patches if necessary&#xA;  for (i=0, ii=1; i&amp;lt;n; ++i, ++ii, ii%=n)&#xA;  {&#xA;    if (!edgeData_[i].is_new &amp;amp;&amp;amp; !edgeData_[ii].is_new)&#xA;    {&#xA;      inner_prev = edgeData_[i].halfedge_handle;&#xA;      inner_next = edgeData_[ii].halfedge_handle;&#xA;&#xA;&#xA;      if (next_halfedge_handle(inner_prev) != inner_next)&#xA;      {&#xA;        // here comes the ugly part... we have to relink a whole patch&#xA;&#xA;        // search a free gap&#xA;        // free gap will be between boundary_prev and boundary_next&#xA;        outer_prev = opposite_halfedge_handle(inner_next);&#xA;        outer_next = opposite_halfedge_handle(inner_prev);&#xA;        boundary_prev = outer_prev;&#xA;        do&#xA;          boundary_prev =&#xA;            opposite_halfedge_handle(next_halfedge_handle(boundary_prev));&#xA;        while (!is_boundary(boundary_prev));&#xA;        boundary_next = next_halfedge_handle(boundary_prev);&#xA;&#xA;        // ok ?&#xA;        if (boundary_prev == inner_prev)&#xA;        {&#xA;          omerr() &amp;lt;&amp;lt; &quot;PolyMeshT::add_face: patch re-linking failed\n&quot;;&#xA;          return InvalidFaceHandle;&#xA;        }&#xA;&#xA;        assert(is_boundary(boundary_prev));&#xA;        assert(is_boundary(boundary_next));&#xA;&#xA;        // other halfedges' handles&#xA;        patch_start = next_halfedge_handle(inner_prev);&#xA;        patch_end   = prev_halfedge_handle(inner_next);&#xA;&#xA;        assert(boundary_prev.is_valid());&#xA;        assert(patch_start.is_valid());&#xA;        assert(patch_end.is_valid());&#xA;        assert(boundary_next.is_valid());&#xA;        assert(inner_prev.is_valid());&#xA;        assert(inner_next.is_valid());&#xA;&#xA;        // relink&#xA;        next_cache_[next_cache_count++] = std::make_pair(boundary_prev, patch_start);&#xA;        next_cache_[next_cache_count++] = std::make_pair(patch_end, boundary_next);&#xA;        next_cache_[next_cache_count++] = std::make_pair(inner_prev, inner_next);&#xA;      }&#xA;    }&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Just to give some context, the &lt;code&gt;add_face&lt;/code&gt; (which is reused in other subclasses of &lt;code&gt;PolyConnectivity&lt;/code&gt;) essentially creates a face given a set of vertices, the first part of the function, prior the for loop I've just mentioned, checks if the vertices are boundary vertices and if there's a potential edge connecting two consecutive vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The for loop I don't understand is supposed to do something when three consecutive vertices &lt;code&gt;v[i],v[i+1],v[i+2]&lt;/code&gt; are not connected (I think).&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2019-04-27T00:19:13.893" Title="HalfEdge data structure in openmesh, create_face function explanation" Tags="&lt;algorithm&gt;&lt;c++&gt;&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8772" PostTypeId="2" ParentId="8770" CreationDate="2019-04-16T10:46:31.853" Score="4" Body="&lt;p&gt;You can use a shear, or equivalently a rotation by 45, scale along one of the axes, rotate back (which is equivalent to the shear which you are looking for).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: On second thought, you don't need to even rotate back unless your circle is marked, since a circle is rotation invariant (if the rotation is around its center).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-04-20T21:42:43.427" LastActivityDate="2019-04-20T21:42:43.427" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8773" PostTypeId="1" CreationDate="2019-04-17T13:02:45.657" Score="2" ViewCount="251" Body="&lt;p&gt;In an effort to improve cascaded shadow maps, I have looked into using GL_DEPTH_CLAMP and moving the near and far plane just around the actual view frustum instead of the global bounding box. But the use of GL_DEPTH_CLAMP appears to have no effect and the near plane clips the geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use reverse z as per &lt;a href=&quot;https://nlguillemot.wordpress.com/2016/12/07/reversed-z-in-opengl/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Reversed-Z in OpenGL&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The tl/dr version is:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Change clip control to 0/1&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Use a floating point depth buffer.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Clear the depth buffer to 0&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindFramebuffer(GL_FRAMEBUFFER, fbo);&#xA;&#xA;glClearDepth(0.0f);&#xA;glClear(GL_DEPTH_BUFFER_BIT);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Change depth test to grater&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glDepthFunc(GL_GREATER);&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Change the projection matrix to match&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The reverse z works really fine, but apparently it messes with GL_DEPTH_CLAMP. If I switch off reverse z GL_DEPTH_CLAMP appears to work as designed; but many other bits in the code get messed up. (It's just not switchable anymore.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look at the documentation of &lt;a href=&quot;https://www.khronos.org/opengl/wiki/GLAPI/glEnable&quot; rel=&quot;nofollow noreferrer&quot;&gt;GL_DEPTH_CLAMP&lt;/a&gt; it states the following:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If enabled, the -wc ≤ zc ≤ wc plane equation is ignored by view volume clipping (effectively, there is no near or far plane clipping).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;My guess is that GL_DEPTH_CLAMP's implementation is just not compatible with reverse z. But I feel like I am missing something. Any idea on how to get GL_DEPTH_CLAMP to working with reverse z?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See the following image of the depth buffers:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Shjvy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Shjvy.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see in the the first cascade, the near plane clips the geometry, it should be all white.&lt;/p&gt;&#xA;" OwnerUserId="9387" LastActivityDate="2019-05-06T05:13:56.403" Title="GL_DEPTH_CLAMP has no effect (reverse z)" Tags="&lt;opengl&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8774" PostTypeId="1" AcceptedAnswerId="8785" CreationDate="2019-04-18T05:51:32.187" Score="3" ViewCount="795" Body="&lt;p&gt;I'm trying to unfold a 3D mesh onto a 2D plane. My general idea to do this, would be to cycle through all the faces of the meshes and perform a hierarchical transformation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I would start at the first face and transform it's vertices to the plane, then go to the next face and transform the vertices, that were not already transformed (since the mesh consists of triangles, each face shares 2 vertices with the next triangle) with the transformation of the last face and then add another transformation to get it to the plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is I don't really have an idea how to calculate the transformation matrices.&#xA;Can someone help me?&#xA;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="8757" LastEditorUserId="10527" LastEditDate="2019-04-24T10:18:06.927" LastActivityDate="2019-04-24T10:18:06.927" Title="Unfold a 3D mesh to a 2D plane" Tags="&lt;3d&gt;&lt;2d&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8776" PostTypeId="1" AcceptedAnswerId="8794" CreationDate="2019-04-18T18:55:59.923" Score="2" ViewCount="107" Body="&lt;p&gt;Please help. I'm trying to implement a ray tracer, going by the PBRT book and got stuck on an issue that I fail to find the answer to. My scenes are made from objects and light sources. From that, I can get the spectral power distribution(SPD) of radiance for each pixel (in watts per steradian per meter squared per meter of wavelength). The problem is, how to correctly convert them to RGB color values? It appears that I should first get the XYZ color, and then convert to RGB. But how do you go from an SPD to the XYZ color? I could just integrate the SPD with the xyz-color-mathing-functions, but they work with &quot;relative power distributions&quot;, and I have absolute. The problem is with this scaling that needs to be done. So, if my understanding is correct so far, then the question is, how should I scale my SPDs so that the final image is correct and the XYZ values don't fly far out of the 0..1 range? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not an expert in color, and it's possible that my undestanding of the situation is wrong. Does it make sense to ask, what &lt;em&gt;absolute&lt;/em&gt;(i.e. not relative) SPD of radiance should the pixel get(watts per steradian per meter cubed), so that its RGB value is exactly white (1, 1, 1) ?&lt;/p&gt;&#xA;" OwnerUserId="10512" LastEditorUserId="10512" LastEditDate="2019-04-19T17:54:22.100" LastActivityDate="2019-04-23T18:55:37.477" Title="how many watts are in the SPD of the color white?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;lighting&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8777" PostTypeId="2" ParentId="5904" CreationDate="2019-04-19T08:06:28.697" Score="1" Body="&lt;p&gt;I've simplified Mikkel Gjoel's idea of dithering with triangular noise to a simple function that only needs a single RNG call. I've stripped away all unecessary bits so it should be pretty readable and understandable what's going on:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;// Dithers and quantizes color value c in [0, 1] to the given color depth.&#xA;// It's expected that rng contains a uniform random variable on [0, 1].&#xA;uint dither_quantize(float c, uint depth, float rng) {&#xA;    float cmax = float(depth) - 1.0;&#xA;    float ci = c * cmax;&#xA;&#xA;    float d;&#xA;    if (ci &amp;lt; 0.5 || ci &amp;gt;= cmax - 0.5) {&#xA;        // Uniform distribution on [-0.5, 0.5] for edges.&#xA;        d = rng - 0.5;&#xA;    } else {&#xA;        // Symmetric triangular distribution on [-1, 1].&#xA;        d = (rng &amp;lt; 0.5) ? sqrt(2.0 * rng) - 1.0 : 1.0 - sqrt(2.0 - 2.0*rng);&#xA;    }&#xA;&#xA;    return uint(clamp(ci + d + 0.5, 0.0, cmax));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For the idea and context I'll refer you to Mikkel Gjoel's answer.&lt;/p&gt;&#xA;" OwnerUserId="10515" LastActivityDate="2019-04-19T08:06:28.697" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8778" PostTypeId="2" ParentId="8774" CreationDate="2019-04-19T10:19:10.797" Score="0" Body="&lt;p&gt;Unfolding the mesh the way you describe it, most likely you will end up with overlapping triangles in the 2D plane unless your 3D geometry is simple. If that's ok, one laborious way is to compute the distances of the triangle sides and the angles and construct the triangle again in the 2D plane.&#xA;For example, set:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;a = (0,0)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;b = (0,D1)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;c = (D2*cos(phi), D2*sin(phi))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;/p&gt;&#xA;&#xA;&lt;p&gt;D1 is the distance between a and b in 3D, &lt;/p&gt;&#xA;&#xA;&lt;p&gt;D2 is the distance between a and c in 3D,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and phi is the angle at the a point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then using an affine transformation you can transform the triangle where you want.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UV unwrapping, which was mentioned, is the way to go only if its not important to keep the shapes of the 3D triangles intact.&lt;/p&gt;&#xA;" OwnerUserId="10521" LastActivityDate="2019-04-19T10:19:10.797" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8779" PostTypeId="1" CreationDate="2019-04-19T15:34:34.343" Score="1" ViewCount="327" Body="&lt;p&gt;I was following &lt;a href=&quot;https://youtu.be/GgGBR4z8C9o&quot; rel=&quot;nofollow noreferrer&quot;&gt;this guide&lt;/a&gt; for drawing circles using shadertoy. Now I am trying to mimic the examples behaviour in WebGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a working shadertoy example I try to mimic. The code is not mine, see link above:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;float Circle(vec2 uv, vec2 p, float r, float blur) {&#xA;    float d = length(uv-p);&#xA;    float c = smoothstep(r, r - blur, d);&#xA;    return c;&#xA;}&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;    // Normalized pixel coordinates (from 0 to 1)&#xA;    vec2 uv = fragCoord.xy/iResolution.xy;&#xA;    uv -= .5;&#xA;    uv.x *= iResolution.x / iResolution.y;&#xA;&#xA;    float c = Circle(uv, vec2(.2, -.1), .1, .01);&#xA;&#xA;    // Output to screen&#xA;    fragColor = vec4(vec3(c), 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And this is the fragment shader I am using:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;#version 300 es&#xA;precision mediump float;&#xA;&#xA;uniform vec2 iResolution;&#xA;&#xA;out vec4 outColor;&#xA;&#xA;float Circle(vec2 uv, vec2 p, float r, float blur) {&#xA;    float d = length(uv-p);&#xA;    float c = smoothstep(r, r - blur, d);&#xA;    return c;&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;    // Normalized pixel coordinates (from 0 to 1)&#xA;    vec2 uv = gl_FragCoord.xy/iResolution.xy;&#xA;    uv -= .5;&#xA;    uv.x *= iResolution.x / iResolution.y;&#xA;&#xA;    float c = Circle(uv, vec2(-.5, .2), .1, .01);&#xA;&#xA;    // I am discarding all &quot;blackish&quot; values in order to discard &quot;transparent&quot; pixels&#xA;    if (c &amp;lt; .1 ){&#xA;        discard;&#xA;    }&#xA;    outColor = vec4(vec3(c), 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am using another &lt;code&gt;program&lt;/code&gt; before rendering this one for transparency I am discarding some pixels, see comment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is the my drawing class, basically I am drawing two Triangles:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;class Hud {&#xA;  constructor(gl, hudShader) {&#xA;    this.hudShader = hudShader;&#xA;    this.gl = gl;&#xA;    this.glCanvas = document.getElementById(&quot;glcanvas&quot;);&#xA;&#xA;    const positionBuffer = this.gl.createBuffer();&#xA;    gl.bindBuffer(this.gl.ARRAY_BUFFER, positionBuffer);&#xA;&#xA;    gl.bufferData(&#xA;      gl.ARRAY_BUFFER,&#xA;      new Float32Array([&#xA;        -1.0, -1.0,&#xA;        1.0, -1.0,&#xA;        -1.0, 1.0,&#xA;        -1.0, 1.0,&#xA;        1.0, -1.0,&#xA;        1.0, 1.0&#xA;      ]),&#xA;      this.gl.STATIC_DRAW&#xA;    );&#xA;  }&#xA;&#xA;  Update() {}&#xA;&#xA;  Draw() {&#xA;    this.gl.useProgram(this.hudShader.program);&#xA;&#xA;    this.gl.uniform2f(&#xA;      this.hudShader.config.uniformLocations.iResolution,&#xA;      this.glCanvas.clientWidth,&#xA;      this.glCanvas.clientHeight&#xA;    );&#xA;&#xA;    this.gl.enableVertexAttribArray(&#xA;      this.hudShader.config.attributeLocations.position&#xA;    );&#xA;    this.gl.vertexAttribPointer(&#xA;      this.hudShader.config.attributeLocations.position,&#xA;      2, this.gl.FLOAT, false, 0, 0);&#xA;&#xA;    this.gl.drawArrays(gl.TRIANGLES, 0, 6);&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This produces weird behaviour. For example the position of the circle does not correspond to the example. Also if I scale the viewport the circle seems to change position and scale:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RTa7v.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RTa7v.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What am I doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="2485" LastActivityDate="2020-12-22T19:04:35.363" Title="Mimic shadertoy in WebGL" Tags="&lt;glsl&gt;&lt;webgl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8780" PostTypeId="1" AcceptedAnswerId="8784" CreationDate="2019-04-19T15:57:59.387" Score="0" ViewCount="78" Body="&lt;p&gt;I wonder how is it possible to scale all shapes so that they are within boundaries of a [unit] sphere? I know how to do this for a cube: if radius of the sphere is &lt;code&gt;S&lt;/code&gt; I set the length of &lt;code&gt;X&lt;/code&gt;, &lt;code&gt;Y&lt;/code&gt; and &lt;code&gt;Z&lt;/code&gt; of the cube to &lt;code&gt;S * math.sqrt(3)/3&lt;/code&gt;. This way, the corners of the cube are barely touching the surface of the sphere. But I don't know how to do this for other objects such as torus, cylinder and cone in &lt;a href=&quot;https://www.blender.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender&lt;/a&gt;. I wonder, is there a general rule/equation to calculate the scaling factor of a shape so that it fits into a sphere with radius &lt;code&gt;S&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="9581" LastActivityDate="2019-04-19T23:44:01.747" Title="How to scale primitive shapes [in Blender] so that they are within a [unit] sphere?" Tags="&lt;transformations&gt;&lt;algorithm&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8783" PostTypeId="2" ParentId="8766" CreationDate="2019-04-19T22:43:16.630" Score="2" Body="&lt;p&gt;I think it depends on what your goal is and what kind of initial data you are provided with. I don't think that dividing by the forth coordinate solves a clipping task. What it does is switching of the coordinates of your objects from 3D projective (four components) to 3D Euclidean (three components).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would say, the basic component you need is a procedure of calculating the intersection point in projective coordinates of a line and a plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An arbitrary point in projective three space is written as a four-vector column:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$X = \begin{bmatrix}X_1\\X_2\\X_3\\x_4\end{bmatrix}$$&lt;/span&gt; and a plane in projective three space can be expressed as &#xA;&lt;span class=&quot;math-container&quot;&gt;$$N^T X = 0$$&lt;/span&gt; where&#xA;&lt;span class=&quot;math-container&quot;&gt;$$N^T X = \begin{bmatrix}N_1 \,\, N_2 \,\, N_3\,\, N_4\end{bmatrix} \begin{bmatrix}X_1\\X_2\\X_3\\x_4\end{bmatrix} = N_1X_1 + N_2X_2 + N_3X_3 + N_4X_4$$&lt;/span&gt;&#xA;A line in projective three space is traditionally given by a pair of points &#xA;&lt;span class=&quot;math-container&quot;&gt;$$A = \begin{bmatrix}A_1\\A_2\\A_3\\A_4\end{bmatrix} \,\, \text{ and }\,\, &#xA;B = \begin{bmatrix}B_1\\B_2\\B_3\\B_4\end{bmatrix}$$&lt;/span&gt; and any point &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; on the line is expressed as&#xA;&lt;span class=&quot;math-container&quot;&gt;$$X = t_1 A + t_2 B$$&lt;/span&gt; for two real numbers &lt;span class=&quot;math-container&quot;&gt;$t_1, \, t_2$&lt;/span&gt; not equal to zero simultaneously. Tho find the intersection point of the line &lt;span class=&quot;math-container&quot;&gt;$X = t_1 A + t_2 B$&lt;/span&gt; with the plane &lt;span class=&quot;math-container&quot;&gt;$N^TX = 0$&lt;/span&gt; we simply plug &#xA;&lt;span class=&quot;math-container&quot;&gt;$$0 = N^TX = N^T \big(t_1 A + t_2 B \big) = t_1(N^TA) + t_2 (N^TB)$$&lt;/span&gt; and since &lt;span class=&quot;math-container&quot;&gt;$t_1, \, t_2$&lt;/span&gt; are determined uniquely up to a common factor, a solution to the equation &#xA;&lt;span class=&quot;math-container&quot;&gt;$$t_1(N^TA) + t_2 (N^TB) = 0$$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$t_1 = -\, (N^TB)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t_2 = (N^TA)$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore, given a plane &lt;span class=&quot;math-container&quot;&gt;$N^TX = 0$&lt;/span&gt; and a line determined by a pair of points &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt;, the unique intersection point of the line with the plane is calculated as&#xA;&lt;span class=&quot;math-container&quot;&gt;$$P = - (N^TB)\, A + (N^TA)\, B$$&lt;/span&gt; We us projective coordinates, because it may happen that one of the points on the line, say &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; is &quot;at infinity&quot; with respect to our perferred choice of Cartesian coordinates. That means that &#xA;&lt;span class=&quot;math-container&quot;&gt;$B = \begin{bmatrix}B_1\\B_2\\B_3\\0\end{bmatrix}$&lt;/span&gt;. In this case, the line is interpreted in Cartesian coordinates as the line passing through the 3D Cartesian point &lt;span class=&quot;math-container&quot;&gt;$A = \begin{bmatrix}\frac{A_1}{A_4}\\\frac{A_2}{A_4}\\\frac{A_3}{A_4}\end{bmatrix}$&lt;/span&gt; and aligned with the 3D vector &lt;span class=&quot;math-container&quot;&gt;$\vec{V}_B = \begin{bmatrix}B_1\\B_2\\B_3\end{bmatrix}$&lt;/span&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to clip a line, you can go about it in two different ways, both of which can use the formula for the intersection between a line and a plane. You can find the (projective) equations of the planes of the frustum, intersect the 3d line with them and then project the points onto the screen, which is again intersection of a plane with lines passing through the origin. Alternatively, you can project the two points that determine the line onto the screen (again you can use the formula for the intersection of the line connecing the origin with any of the two points with the plane of the screen), which allows you to know the projection of the 3D line on the screen, and then find the intersection points of the projected line with the borders of the screen. Maybe the second scenario is simpler?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The screen is parallel to the &lt;span class=&quot;math-container&quot;&gt;$x,\,y$&lt;/span&gt; plane of the 3D Cartesian frame, while the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; axis is perpendicular to the screen and the screen is at a distance &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; from the origin of the coordinate system. Therefore, the Cartesian equation of the plane of the screen is &lt;span class=&quot;math-container&quot;&gt;$z = l$&lt;/span&gt;. In projective coordinates, &lt;span class=&quot;math-container&quot;&gt;$z = \frac{X_3}{X_4}$&lt;/span&gt;, which means that &lt;span class=&quot;math-container&quot;&gt;$\frac{X_3}{X_4} = l$&lt;/span&gt;  so the projective equation is &lt;span class=&quot;math-container&quot;&gt;$X_3 = l\, X_4$&lt;/span&gt; and can be also expressed as&#xA;&lt;span class=&quot;math-container&quot;&gt;$$0 = X_3 - l\, X_4 = S^TX = \begin{bmatrix} 0 \,\,\, 0 \,\,\, 1 \,\, - l\end{bmatrix} \begin{bmatrix}X_1\\X_2\\X_3\\x_4\end{bmatrix} $$&lt;/span&gt; where &#xA;&lt;span class=&quot;math-container&quot;&gt;$S = \begin{bmatrix}0 \\ 0 \\ 1 \\ -l\end{bmatrix}$&lt;/span&gt;&#xA;so if the 3D line is determined by the pair of points &lt;span class=&quot;math-container&quot;&gt;$A = \begin{bmatrix}A_1\\A_2\\A_3\\A_4\end{bmatrix} $&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B = \begin{bmatrix}B_1\\B_2\\B_3\\B_4\end{bmatrix}$&lt;/span&gt; Hence, with &lt;span class=&quot;math-container&quot;&gt;$O = \begin{bmatrix}0\\0\\0\\1\end{bmatrix}$&lt;/span&gt;, the projection of &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; on the screen is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{A} =  - (S^TO)\, A + (S^TA)\, O = l\, A + (A_3-l\, A_4)\, O = \begin{bmatrix}l\,A_1\\l\,A_2\\l\,A_3\\l\,A_4\end{bmatrix} + \begin{bmatrix}0\\0\\0\\A_3-l\, A_4\end{bmatrix} = \begin{bmatrix}l\,A_1\\l\,A_2\\l\,A_3\\A_3\end{bmatrix}$$&lt;/span&gt;  and the projection of &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; on the screen is &lt;span class=&quot;math-container&quot;&gt;$$\hat{B}= \begin{bmatrix}l\,B_1\\l\,B_2\\l\,B_3\\B_3\end{bmatrix}$$&lt;/span&gt; So one can write this projection in  matrix form as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$P_{scr} = - (S^TO)\, \text{Id} + O\,S^T$$&lt;/span&gt;&#xA;because &lt;span class=&quot;math-container&quot;&gt;$P_{scr}A = \Big(- (S^TO)\, \text{Id} + O\,S^T\Big)\,A = - (S^TO)\,A + O\,(S^TA) = - (S^TO)\,A + (S^TA)\,O = \hat{A}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;P_{scr} &amp;amp;= - (S^TO)\, \text{Id} + O\,S^T\\&#xA;&amp;amp;\\&#xA;&amp;amp;= - (-l)\begin{bmatrix}1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix} + \begin{bmatrix}0\\0\\0\\1\end{bmatrix} &#xA;\begin{bmatrix}0\,\,\, 0\,\,\, 1 \,\,\, - l\end{bmatrix}\\ &#xA;&amp;amp;\\&#xA;&amp;amp;= \begin{bmatrix}l &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\0 &amp;amp; l &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; l &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 0 &amp;amp; l\end{bmatrix} + \begin{bmatrix}0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 1 &amp;amp; -l \end{bmatrix}\\&#xA;&amp;amp;\\&#xA;&amp;amp; = \begin{bmatrix}l &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; l &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; l &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0\end{bmatrix}&#xA;\end{align}&lt;/span&gt;&#xA;And thus&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{A} = P_{scr}\, A \,\, \text{ and } \,\, &#xA;\hat{B} = P_{scr}\, B$$&lt;/span&gt; &#xA;When you have your points projected on the screen plane, you would like to get rid of the &lt;span class=&quot;math-container&quot;&gt;$z-$&lt;/span&gt;coordiante, so you need to remove the third (out of our) component of your projected points, i.e.:&#xA;&lt;span class=&quot;math-container&quot;&gt;$\hat{A} = \begin{bmatrix}l\,A_1\\l\,A_2\\l\,A_3\\A_3\end{bmatrix} \mapsto \begin{bmatrix}l\,A_1\\l\,A_2\\A_3\end{bmatrix}$&lt;/span&gt; so if you take the projection from four vectors to three vectors&#xA;&lt;span class=&quot;math-container&quot;&gt;$$P_0 = \begin{bmatrix} 1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1\end{bmatrix}$$&lt;/span&gt; and muptiply it by  &lt;span class=&quot;math-container&quot;&gt;$P_{scr}$&lt;/span&gt; from the right as &lt;span class=&quot;math-container&quot;&gt;$P_0P_{scr}$&lt;/span&gt;, we can take the projective map from the projective three space to the projective plane of the screen&#xA;&lt;span class=&quot;math-container&quot;&gt;$$P = P_0P_{scr} = \begin{bmatrix} l &amp;amp; 0 &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; l &amp;amp; 0 &amp;amp; 0\\0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0\end{bmatrix}$$&lt;/span&gt; &#xA;So, to recap, given  a line in projective three space, passing through the pair of points &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt;, their screen images, in projective coordinates of the screen, are&#xA;&lt;span class=&quot;math-container&quot;&gt;$\hat{A} = P\, A$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\hat{B} =P \, B$&lt;/span&gt;. The formula for the intersection of a line with a plane in projective three space translates verbatim to the intersection of a line given by a pair of points &lt;span class=&quot;math-container&quot;&gt;$\hat{A}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\hat{B}$&lt;/span&gt; with another line given as an equation &lt;span class=&quot;math-container&quot;&gt;$N^T\hat{X} = 0$&lt;/span&gt; in the projective plane, where &lt;span class=&quot;math-container&quot;&gt;$N = \begin{bmatrix} n_1\\n_2\\n_3\end{bmatrix}$&lt;/span&gt;, &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{X}_N = (- N^T\hat{B})\hat{A} + (N^T\hat{A})\hat{B}$$&lt;/span&gt; so &#xA;alltogether &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{X}_N = (- N^TP{B})\,P{A} + (N^TP{A})\,P{B}$$&lt;/span&gt; So this is the formula for the projected points of intersection of the three dimensional line with the frustum's boundary. For example,  the right vertical boundary of the screen is given by an &lt;span class=&quot;math-container&quot;&gt;$N_{right\, vert} = \begin{bmatrix} w\\0\\0\end{bmatrix}$&lt;/span&gt; and the bottom horizontal boundary of the screen is given by an &lt;span class=&quot;math-container&quot;&gt;$N_{bottom\, hor} = \begin{bmatrix} 0\\- h\\0\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="8851" LastEditorUserId="8851" LastEditDate="2019-04-24T14:48:28.203" LastActivityDate="2019-04-24T14:48:28.203" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8784" PostTypeId="2" ParentId="8780" CreationDate="2019-04-19T23:44:01.747" Score="2" Body="&lt;p&gt;Yes, there is a fairly general algorithm to calculate this scaling factor, which works for all shapes with a known parametric representation. First, substitute the parametric equation of the shape (e.g. a torus, cylinder or cone) into the implicit equation of the sphere, &lt;span class=&quot;math-container&quot;&gt;$x^2 + y^2 + z^2 = S^2$&lt;/span&gt;. Then, solve this equation for the radius of the sphere. The result will be one or more intervals for values of &lt;span class=&quot;math-container&quot;&gt;$S$&lt;/span&gt; for which the shape intersects the sphere with radius &lt;span class=&quot;math-container&quot;&gt;$S$&lt;/span&gt;. The largest value of &lt;span class=&quot;math-container&quot;&gt;$S$&lt;/span&gt; is the radius of the shape's bounding sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Example (torus): Substituting the parametric equation of the torus centered at the origin with major radius &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; and minor radius &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; into the implicit equation of the sphere yields &lt;span class=&quot;math-container&quot;&gt;$2Rr \cos(\phi) + R^2 + r^2 - S^2 = 0$&lt;/span&gt;, which is equivalent to &lt;span class=&quot;math-container&quot;&gt;$S\in[R-r,R+r]$&lt;/span&gt;. So if you want a torus to fit into a unit sphere, you need to choose the major radius and minor radius such that &lt;span class=&quot;math-container&quot;&gt;$R+r\le 1$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastActivityDate="2019-04-19T23:44:01.747" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8785" PostTypeId="2" ParentId="8774" CreationDate="2019-04-19T23:44:39.760" Score="1" Body="&lt;p&gt;When performing the unfolding the way you want, after you have unfolded one triangle in the plane, the next one should be one of the three triangles, adjacent to the unfolded one, i.e. the next triangle to be unfolded shares a common edge with the unfolded one.&lt;/p&gt;&#xA;&lt;p&gt;Assume you have a triangle &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt; in three space with vertices  &lt;span class=&quot;math-container&quot;&gt;$$A = [A_1, A_2, A_3], \,\, B = [B_1, B_2, B_3],\,\, C = [C_1, C_2, C_3]$$&lt;/span&gt; which is one of the triangles from the 3D mesh.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt; is the first triangle you are starting the unfolding with, then:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;calculate &lt;span class=&quot;math-container&quot;&gt;$l_{AB} = ||A - B|| = \sqrt{(A_1 - B_1)^2 + (A_2 - B_2)^2 + (A_3 - B_3)^2}$&lt;/span&gt;;&lt;/li&gt;&#xA;&lt;li&gt;set the 2D vertices &lt;span class=&quot;math-container&quot;&gt;$a = [0,0]$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b = [l_{AB}, 0]$&lt;/span&gt; as well as $$l_{ab} = l_{AB};&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;strong&gt;Else if&lt;/strong&gt; &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt; is a next triangle to be unfolded in the plane, i.e. you have already unfolded one of &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt;'s adjacent (neighboring) triangles, therefore one of &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt;'s edges is already unfolded in the plane. Say that this edge is &lt;span class=&quot;math-container&quot;&gt;$AB$&lt;/span&gt; and it is unfolded in the plane as the edge with vertices &lt;span class=&quot;math-container&quot;&gt;$a = [a_1, a_2]$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b = [b_1, b_2]$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$l_{ab} = ||a-b|| = \sqrt{(a_1 - b_1)^2 + (a_2 - b_2)^2} = ||A-B|| = l_{AB}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Either way, for the triangle &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt; you already have the edge &lt;span class=&quot;math-container&quot;&gt;$AB$&lt;/span&gt; unfolded as &lt;span class=&quot;math-container&quot;&gt;$ab$&lt;/span&gt; in the plane, so that &lt;span class=&quot;math-container&quot;&gt;$l_{ab} = l_{AB}$&lt;/span&gt; (i.e. you already know &lt;span class=&quot;math-container&quot;&gt;$a, \, b$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$l_{ab}$&lt;/span&gt;). The question is, how do you find the coordinates of the third vertex &lt;span class=&quot;math-container&quot;&gt;$c = [c_1, c_2]$&lt;/span&gt; so that &lt;span class=&quot;math-container&quot;&gt;$l_{bc} = l_{BC}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$l_{ca} = l_{CA}$&lt;/span&gt;? We impose the latter two conditions because two triangles that have pairwise equal edge-lengths are congruent (isometric, i.e. identical copies of each other).&lt;/p&gt;&#xA;&lt;p&gt;For your information, I will write vectors like &lt;span class=&quot;math-container&quot;&gt;$B - A = [B_1 - A_1, \, B_2 - A_2, \, B_3 - A_3]$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$C - A = [C_1 - A_1, \, C_2 - A_2, \, C_3 - A_3]$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b-a = [b_1 - a_1, b_2-a_2]$&lt;/span&gt; and will use dot product &lt;span class=&quot;math-container&quot;&gt;$\cdot$&lt;/span&gt; and cross product &lt;span class=&quot;math-container&quot;&gt;$\times$&lt;/span&gt; between vectors. You already know what &lt;span class=&quot;math-container&quot;&gt;$||B-A|| = l_{AB}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$||C-A|| = l_{CA}$&lt;/span&gt; are and that &lt;span class=&quot;math-container&quot;&gt;$l_{AB} = l_{ab} = \|b-a\|$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate &lt;span class=&quot;math-container&quot;&gt;$$s = \frac{\|(B-A)\times(C-A)\|}{l_{ab}^2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate &lt;span class=&quot;math-container&quot;&gt;$$c = \frac{(B-A)\cdot(C-A)}{l_{ab}^2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate both pairs of coordinates&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;&amp;amp;c'_1 = a_1 + c(b_1-a_1) - s(b_2 - a_2)\\&#xA;&amp;amp;c'_2 = a_2 + c(b_2-a_2) + s(b_1 - a_1)&#xA;\end{align}&lt;/span&gt;&#xA;and&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;&amp;amp;c''_1 = a_1 + c(b_1-a_1) + s(b_2 - a_2)\\&#xA;&amp;amp;c''_2 = a_2 + c(b_2-a_2) - s(b_1 - a_1)&#xA;\end{align}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You have two candidate points &lt;span class=&quot;math-container&quot;&gt;$c' = [c'_1, c'_2]$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$c'' = [c''_1, c''_2]$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Perform a check whether &lt;span class=&quot;math-container&quot;&gt;$c'$&lt;/span&gt; is on the same side of the edge &lt;span class=&quot;math-container&quot;&gt;$ab$&lt;/span&gt; as the  triangle unfolded right before &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;strong&gt;If&lt;/strong&gt; it is not, then &lt;span class=&quot;math-container&quot;&gt;$c = c'$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;else if&lt;/strong&gt; it is, then &lt;span class=&quot;math-container&quot;&gt;$c = c''$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;As a result of this procedure, you have constructed the planar unfolding &lt;span class=&quot;math-container&quot;&gt;$abc$&lt;/span&gt; of triangle &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt; and the next triangle from the 3D mesh to be unfolded (if any), should be the one that shares either edge &lt;span class=&quot;math-container&quot;&gt;$BC$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$CA$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$ABC$&lt;/span&gt;. Either way, for that next triangle, you already know the unfolding &lt;span class=&quot;math-container&quot;&gt;$bc$&lt;/span&gt; of the edge &lt;span class=&quot;math-container&quot;&gt;$BC$&lt;/span&gt; and the unfolding &lt;span class=&quot;math-container&quot;&gt;$ca$&lt;/span&gt; of &lt;span class=&quot;math-container&quot;&gt;$CA$&lt;/span&gt; (whichever is relevant), so you can apply the same procedure for that next triangle. And so on and so forth, until you have unfolded all triangles from the mesh.&lt;/p&gt;&#xA;&lt;p&gt;Have in mind that there are 3D meshes that do not posses unfolding that do not self overlap, no matter what you do. For such meshes there no greedy algorithms or any other algorithm that can do it.&lt;/p&gt;&#xA;" OwnerUserId="8851" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-04-20T20:36:10.593" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="8787" PostTypeId="1" AcceptedAnswerId="8818" CreationDate="2019-04-20T08:36:48.623" Score="2" ViewCount="131" Body="&lt;p&gt;What I would like to do is to create a crater on a field. To do so, I thought that creating a universal crater object (something cone-shaped) and then subtracting it from the field on a specified point might be a good idea. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I would specify a &quot;middle point&quot; on the field, take the lowest point of the crater and move the crater by its lowest point onto the middle point of the field and then push it by its size of the crater into the field. Then apply said subtracting operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: Are there any techniques/libraries which help me accomplish this? They should be either openGL-compatible or work on .obj file format.&lt;/p&gt;&#xA;" OwnerUserId="10525" LastEditorUserId="10525" LastEditDate="2019-04-21T20:26:20.503" LastActivityDate="2019-06-07T14:58:01.187" Title="How to do CSG on 3D triangulated objects, originally stored as a .obj file, using openGL or other libraries?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8788" PostTypeId="2" ParentId="165" CreationDate="2019-04-21T01:30:51.013" Score="4" Body="&lt;p&gt;I'm not sure what happens there. Looking at the rendering of &quot;considerations&quot; in your example, the &quot;cons&quot; looks like what you get when you do crude sub pixel anti-aliasing, without applying the necessary &quot;fix up&quot; to make it look good. But then the &quot;der&quot; in the same word looks like there's no sub-pixel anti-aliasing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find a good article about how good looking sub-pixel anti-aliasing works here &lt;a href=&quot;https://www.grc.com/ct/ctwhat.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.grc.com/ct/ctwhat.htm&lt;/a&gt; and for the &quot;fix up&quot; part here &lt;a href=&quot;https://www.grc.com/ct/freeandclear.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.grc.com/ct/freeandclear.htm&lt;/a&gt; and here &lt;a href=&quot;https://www.grc.com/ct/cttech.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.grc.com/ct/cttech.htm&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What it comes down to is: if you just compute the R/G/B intensities by calculating the covered area for each sub-pixel, the resulting color fringes are very ugly/irritating. To fix it you have to apply a horizontal blur/low-pass filter to the sub-pixel image. The result is an image that's less sharp but also has far less saturated colors. I.e. something like your &quot;Check you&quot; example.&lt;/p&gt;&#xA;" OwnerUserId="10526" LastEditorUserId="10526" LastEditDate="2019-04-21T01:40:39.120" LastActivityDate="2019-04-21T01:40:39.120" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8790" PostTypeId="1" CreationDate="2019-04-21T11:28:20.037" Score="2" ViewCount="166" Body="&lt;p&gt;I am novice lacking professional terminology.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to create from 3D object (let's say from polygon mesh) a slice through to PNG file in order to create something like reverse medical MRI scan from which volumetric renders are created.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How it's called? It will enable me to find methods of achieving it. Bonus points for pointing to a library doing that.&lt;/p&gt;&#xA;" OwnerUserId="10528" LastEditorUserId="10528" LastEditDate="2019-04-21T16:12:15.437" LastActivityDate="2020-10-18T08:03:55.500" Title="3D object to slices like in medical scan" Tags="&lt;polygon&gt;" AnswerCount="4" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8791" PostTypeId="2" ParentId="8790" CreationDate="2019-04-21T13:19:28.003" Score="1" Body="&lt;p&gt;Some terminology: Intersection of a polyhedron with a plane.&#xA;&lt;hr /&gt;&#xA;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#xA;&lt;img src=&quot;https://i.stack.imgur.com/KileD.png&quot; width=&quot;260&quot; /&gt;&#xA;&lt;br /&gt;&#xA;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#xA;&lt;sup&gt;&#xA;&lt;a href=&quot;http://demonstrations.wolfram.com/IntersectionOfAConvexPolyhedronAndAPlane/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wolfram Demo&lt;/a&gt;.&#xA;&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr /&gt;&#xA;" OwnerUserId="4748" LastActivityDate="2019-04-21T13:19:28.003" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8792" PostTypeId="2" ParentId="8779" CreationDate="2019-04-22T11:53:16.807" Score="1" Body="&lt;p&gt;I did not go into much detail with your code but the first thing that comes to mind is that you are rendering with respect to the resolution passed into the shader.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = fragCoord.xy/iResolution.xy;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;hope this helps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe calculate the aspect ratio?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float aspect = float(iResolution.x) / float(iResolution.y ? iResolution.y: 1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10534" LastEditorUserId="12056" LastEditDate="2020-03-27T17:06:55.930" LastActivityDate="2020-03-27T17:06:55.930" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8793" PostTypeId="1" CreationDate="2019-04-23T01:49:34.853" Score="6" ViewCount="145" Body="&lt;p&gt;The context of this question is correct dithering of color with gamma correction. In dithering we add (shaped) noise &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; to a signal &lt;span class=&quot;math-container&quot;&gt;$s \in [0, 1]$&lt;/span&gt; based on a random variable &lt;span class=&quot;math-container&quot;&gt;$r \in [0, 1]$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$s' = s + n(s, r)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;such that when we quantize the signal to &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; steps the rounding will end up distorting the signal less.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already have a function that works in a linear world from &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5904/whats-a-proper-way-to-clamp-dither-noise/8777#8777&quot;&gt;here&lt;/a&gt;, where &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is a symmetric triangular distribution on &lt;span class=&quot;math-container&quot;&gt;$[-1, 1]$&lt;/span&gt; (with the caveat that for &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; close to &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; we switch to a uniform distribution on &lt;span class=&quot;math-container&quot;&gt;$[-\frac{1}{2}, \frac{1}{2}]$&lt;/span&gt;), as it has mean &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; and appropriately smoothes out the rounding (demo that incorrectly ignores gamma: &lt;a href=&quot;https://www.shadertoy.com/view/Wts3zH&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/Wts3zH&lt;/a&gt;). This function written out is (matching top to bottom in priority for the cases):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$n(s, r) \cdot (m - 1) = \begin{cases}&#xA;r - \frac{1}{2}&amp;amp;s \leq \frac{1}{2(m-1)} \vee s \geq 1-\frac{1}{2(m-1)}\\&#xA;\sqrt{2r} - 1&amp;amp;r &amp;lt; \frac{1}{2}\\&#xA;1 - \sqrt{2 - 2r}&amp;amp;r \geq \frac{1}{2}\\&#xA;\end{cases}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However in sRGB files we have to deal with gamma. Essentially we have an invertable transform &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; (often &lt;span class=&quot;math-container&quot;&gt;$t(x) = x^{2.4}$&lt;/span&gt;) that is applied before/after quantization to allocate more steps to lower intensities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that the average color when viewing is no longer (ignoring quantization for now):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_0^1\left(s + n(s, r)\right)\text{d}r = s$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But is instead:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_0^1 t^{-1}\left(s + n(s, r)\right)\text{d}r &amp;gt; s$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How can we change our noise function &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; so that the average color is again &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; after dithering, while maintaining our properties from the triangular distribution as much as possible?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the record, the main property the triangular distribution gives is that the variance after rounding becomes constant:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_0^1\left(\left[(s + n(s, r))(m-1)\right]/(m-1) - s\right)^2\text{d}r = c$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$[x]$&lt;/span&gt; denotes &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; rounded to the closest integer. Note that this only holds in the triangular part of the domain of &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;, so when &lt;span class=&quot;math-container&quot;&gt;$\frac{1}{2(m-1)} \leq s \leq 1-\frac{1}{2(m-1)}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to give a shot, here is a demo that can show you the error from dithering, which has gamma correction: &lt;a href=&quot;https://www.shadertoy.com/view/3tf3Dn&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/3tf3Dn&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10515" LastEditorUserId="10515" LastEditDate="2019-05-01T10:04:35.337" LastActivityDate="2019-05-01T10:04:35.337" Title="Noise shaping for dithering with gamma?" Tags="&lt;noise&gt;&lt;gamma&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8794" PostTypeId="2" ParentId="8776" CreationDate="2019-04-23T18:48:20.897" Score="0" Body="&lt;p&gt;There is no unique answer or approach and it's not simple either. I'm afraid that once you know the absolute spectral distribution of light that falls onto your camera, you've only computed half the story. What happens now depends on what observer you are trying to simulate, and to what accuracy. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can highly recommend &lt;a href=&quot;https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moving Frostbite to Physically Based Rendering 3.0&lt;/a&gt; from SIGGRAPH 2014. It contains many details especially section 4.3 and 5.1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are trying to simulate a camera you need to answer some other questions for yourself:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What ISO am I simulating?&lt;/li&gt;&#xA;&lt;li&gt;What is my shutter speed?&lt;/li&gt;&#xA;&lt;li&gt;What is my aperture?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;With the answers to that you can correct how much light falls onto your sensor and how sensitive it is to that light. Perhaps you don't have to correct for aperture if you already simulate this for depth-of-field.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then knowing that you need to know how that sensor responds to light of different wavelengths. Perhaps you can find some spectral responsitivity diagrams for the camera sensor you are interested in simulating? Then you can divide by integrate for each sensor type (R, G, B) to get RAW exposure, which still needs processing to turn into sRGB (which involves choosing a whitepoint). It's not simple.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I'm not an expert in color, and it's possible that my undestanding of the situation is wrong. Does it make sense to ask, what absolute(i.e. not relative) SPD of radiance should the pixel get(watts per steradian per meter cubed), so that its RGB value is exactly white (1, 1, 1) ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Absolutely not. If you are indoors and look at a piece of paper, that is white, right? Now if you move outdoors, a much greater amount of light hits your eye, yet you still view it as white.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming you view your image on a monitor, there's a lot of color spaces involved: the absolute spectral distribution, the camera, the stored image, the monitor used to display the image and your eyes. They all have different ideas of what 'white' means, and they all have different settings to tweak it: brightness, whitepoint, exposure, viewing conditions, etc.&lt;/p&gt;&#xA;" OwnerUserId="10515" LastEditorUserId="10515" LastEditDate="2019-04-23T18:55:37.477" LastActivityDate="2019-04-23T18:55:37.477" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8795" PostTypeId="1" AcceptedAnswerId="8796" CreationDate="2019-04-25T12:52:49.957" Score="2" ViewCount="158" Body="&lt;p&gt;In GLSL, what is the difference between &lt;code&gt;isnan(x)&lt;/code&gt; and &lt;code&gt;!(x == x)&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="10547" LastEditorUserId="6" LastEditDate="2019-04-26T13:51:30.167" LastActivityDate="2020-03-08T18:37:08.140" Title="Difference between isnan and comparison to self" Tags="&lt;glsl&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8796" PostTypeId="2" ParentId="8795" CreationDate="2019-04-25T15:10:08.283" Score="4" Body="&lt;p&gt;IEEE-754 defines the &lt;code&gt;isNaN&lt;/code&gt; property, which determines if a value is NaN. However, it is also defined to be a non-signaling operation; calling &lt;code&gt;isNaN&lt;/code&gt; on an sNaN will never result in a signaled failure. By contrast, equality testing may signal when given sNaN values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, GLSL explicitly states that signaling doesn't matter:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Support for signaling NaNs is not required and exceptions are never raised.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But of course, there's also the fact that &lt;code&gt;isnan&lt;/code&gt; is a vector function, while &lt;code&gt;!(x == x)&lt;/code&gt; only works on scalars. So if you want to test if any of the elements of a &lt;code&gt;vec3&lt;/code&gt; are NaN, you can do &lt;code&gt;any(isnan(some_vec))&lt;/code&gt;, while the equality-testing equivalent would be even more obtuse and verbose: &lt;code&gt;any(not(equal(some_vec, some_vec)))&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And all of that ignores the simple usability reasons for having &lt;code&gt;isnan&lt;/code&gt;. &lt;code&gt;!(x == x)&lt;/code&gt; is an idiom which must be learned, while &lt;code&gt;isnan&lt;/code&gt; is an easily looked up function whose name tells you want it does. After all, most users of floats tend to forget about NaN, so such an expression seems like a tautology, while &quot;isnan&quot; explicitly reminds such people that NaNs are a real thing and they are reading code where that fact is important.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, as previously stated, &lt;code&gt;isNaN&lt;/code&gt; is a property defined by IEEE-754. It is also a function provided by the standard libraries of C99, C++11, Java, C#, Swift, Go, JavaScript, and I can keep going, but I think my point is clear.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-03-08T18:37:08.140" LastActivityDate="2020-03-08T18:37:08.140" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8798" PostTypeId="2" ParentId="4919" CreationDate="2019-04-26T05:05:03.950" Score="0" Body="&lt;p&gt;If you plan to build 3d wireframe or mesh from the slice images, you can consider to use marching cube method - as someone mentioned already in the answer, ITK/VTK can provide the pointer to start with.&lt;/p&gt;&#xA;" OwnerUserId="10552" LastActivityDate="2019-04-26T05:05:03.950" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8799" PostTypeId="2" ParentId="8790" CreationDate="2019-04-26T05:08:35.027" Score="0" Body="&lt;p&gt;I just answered the question: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4919/how-to-build-a-3d-model-from-2d-pictures/8798#8798&quot;&gt;How to build a 3d model from 2d pictures&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and the answer is applicable here. In short, to build wiremesh from the 2d slice, you can take a look marching cube method. In this case you need to assume (or provide) the thickness of each pixel (hence a voxel) so that the MC algorithm can work.&#xA;ITK/VTK should have some implementation for that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The term could be called: 3d mesh reconstruction from volumetric data&lt;/p&gt;&#xA;" OwnerUserId="10552" LastActivityDate="2019-04-26T05:08:35.027" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8803" PostTypeId="1" CreationDate="2019-04-27T08:25:19.537" Score="2" ViewCount="24" Body="&lt;p&gt;Will unaccessed bindings consume cache or bandwidth? I want to improve cache usage by splitting the per-path information in my renderer across different resources, but I also want to keep my binding model simple by having every resource I might need declared in a single .hlsli included at the top of each shader file. I'm concerned that the GPU might try to load part of each resource, even if a particular shader doesn't access it - is that reasonable? Should I prefer more descriptor heaps and fewer resources/shader instead?&lt;/p&gt;&#xA;" OwnerUserId="7868" LastActivityDate="2019-04-27T08:25:19.537" Title="Should I use common resource bindings across all my shaders in HLSL/D3D12?" Tags="&lt;gpu&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8805" PostTypeId="1" AcceptedAnswerId="8808" CreationDate="2019-04-28T19:33:38.567" Score="3" ViewCount="202" Body="&lt;p&gt;I am relatively new to path tracing, and I am trying to implement next event estimation. I am following the Monte Carlo integral used to compute the direct illumination from an area light:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{1}{N}\sum\limits_{i=1}^{N}f_r(p,\omega_o,\omega_i)L_i(p,\omega_i)Vis(p \leftrightarrow p')cos\theta_i\frac{A_Lcos\theta_o}{||p-p'||^2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(where &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is the surface intersection point, &lt;span class=&quot;math-container&quot;&gt;$A_L$&lt;/span&gt; is the area of the light, &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; is a random point on the surface of the light (uniformly distributed), and &lt;span class=&quot;math-container&quot;&gt;$Vis$&lt;/span&gt; returns 1 only if &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; are mutually visible).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I would like to support transformed area lights, that is, lights which have their own model coordinate space separate from the world space (for example, a stretched and rotated sphere).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Samples can easily be generated uniformly in model space (since in model space this light is just a sphere), but obviously then the samples are not uniformly distributed in world space. Does this formula need to be modified to account for the samples being generated uniformly in model space, and what parts need to be computed in model space vs. world space?&lt;/p&gt;&#xA;" OwnerUserId="10565" LastActivityDate="2019-04-29T03:26:05.190" Title="How does Next Event Estimation work with transformed lights?" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;lighting&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8806" PostTypeId="1" CreationDate="2019-04-28T20:22:53.117" Score="0" ViewCount="36" Body="&lt;p&gt;I am solving the task that is as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt; a polygon. Can be any kind of polygon without self intersections. Can be a non-convex and with holes inside.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Goal:&lt;/strong&gt; to cover it with 2 (at least) or more parallelograms that together are equal to or contain the whole polygon. The following criteria should be met:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;There is no point of the polygon that lies beyond parallelograms.&lt;/li&gt;&#xA;&lt;li&gt;The number of the parallelograms should be the least possible. I.e. we want to find largest parallelograms that cover the polygon.&lt;/li&gt;&#xA;&lt;li&gt;These parallelograms must not intersect within the polygon.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; Is this task solved and if it is solved - how? I am looking for a direction where to start with and what related algorithms/theory to learn.&lt;/p&gt;&#xA;" OwnerUserId="10564" LastEditorUserId="10564" LastEditDate="2019-04-30T07:50:38.313" LastActivityDate="2019-04-30T07:50:38.313" Title="Cover a polygon with least amount of parallelograms" Tags="&lt;computational-geometry&gt;&lt;polygon&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8807" PostTypeId="1" CreationDate="2019-04-29T01:36:46.940" Score="1" ViewCount="78" Body="&lt;p&gt;I'm making a lattice based volume FFD and I'm having trouble with gaps in my data resulting from doing a typical deformer. I think I need to go through the voxels in the deformed lattice and then find the corresponding undeformed coordinate, that is, go from having the deformed position to getting the local (s,t,u) coordinate that was deformed to that position and then write the interpolated value of the original voxel. This is obviously the opposite way of doing a lattice based FFD with vector valued trivariate Bernstein polynomials.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am struggling to figure out a way to get the local coordinates of a point in the deformed volume. If anyone has any advice it would be much appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="10567" LastActivityDate="2020-09-23T01:08:00.937" Title="Local Coordinates of Deformed Lattice" Tags="&lt;volumetric&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8808" PostTypeId="2" ParentId="8805" CreationDate="2019-04-29T03:26:05.190" Score="1" Body="&lt;p&gt;Sampling is typically done in local coordinates first and &lt;em&gt;then&lt;/em&gt; mapped to world space. You don't have to change the formula for this, but &lt;span class=&quot;math-container&quot;&gt;$\mathbf{p}'$&lt;/span&gt; needs to be in world space when you compute the solid-angle-to-area Jacobian determinant. For a sphere for instance, you would have a warping function that maps two canonical uniform random numbers to a 3D point on the unit sphere. Only then would you apply the local-to-world matrix on this sample. If this matrix is a rigid motion (e.g. a combination of translations and/or rotations) with a possible scaling factor, then your samples will remain uniformly distributed in world space. However, if you apply a mapping that distorts areas (e.g. stretching), this will not be the case. It technically still &quot;works&quot; for sampling but some regions of your sphere can be overrepresented. You would have to implement an area-preserving sampling mechanism taking into account this stretching factor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice, it's better to stick with rigid transformations and avoid non area-preserving mappings for analytical shapes. If you truly wish to sample a stretched sphere uniformly, your best bet would be to use an ellipsoid mesh. Then you could sample by area by first choosing a triangle proportional to its area and then picking a point on it by barycentric interpolation. In fact, this is what people have to do to sample area lights of arbitrary shapes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a small discussion at the end &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Retrospective_and_The_Future/Design_Retrospective.html#TrianglesOnly&quot; rel=&quot;nofollow noreferrer&quot;&gt;pbrt&lt;/a&gt; that addresses the possibility of removing analytical shapes from a rendering engine. Analytical geometry primitives are fun because they can teach you stuff like subtended solid angle sampling when you learn GI and importance sampling, but they are limited and your question highlights one such limitation.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastActivityDate="2019-04-29T03:26:05.190" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8809" PostTypeId="1" CreationDate="2019-04-29T09:01:39.747" Score="1" ViewCount="31" Body="&lt;p&gt;I am asking this question purely our of curiosity. I do not look for step-by-step tutorial on how to manipulate a photo and making sure that it will be hard to detect it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering, because tools like &lt;a href=&quot;http://fotoforensics.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://fotoforensics.com/&lt;/a&gt; make it easy to detect modifications of photographs in software like Photoshop. I can see that it is based on things like Error Level Analysis. Is there a way to modify a photo but &quot;cover the tracks&quot; so there will be no easy way of detecting modifications by &quot;ELA&quot; or other metods? Is it hard, easy to do? Is it widely used?&lt;/p&gt;&#xA;" OwnerUserId="10568" LastActivityDate="2019-04-29T09:01:39.747" Title="Are there some methods of preventing tools like FotoForensics from detecting manipulations?" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8811" PostTypeId="1" CreationDate="2019-04-30T17:31:05.780" Score="1" ViewCount="85" Body="&lt;p&gt;I'm trying to optimize a geometry pass for a game using dx11 and deferred rendering. (All test are performed on Nvidia GTX 1060 at fixed clock rate)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After profiling with NSight it seems to have very bad utilization of GPU.&#xA;&lt;strong&gt;With the top SOL% being SM:36%&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AHpxo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AHpxo.png&quot; alt=&quot;NSight Capture with texture sampling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I decided to investigate and tried to remove all texture sampling and have a pass that would only write constants to the GBuffer and obtain a very different profiling in NSight but not much difference in timing.&#xA;I would have expected much more throughput for a shader that basically writes constants.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tb0N4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tb0N4.png&quot; alt=&quot;NSight Capture without any texture sampling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to reduce the GBuffer layout which was originally (FP16 + 2x ARGB32, ARGB32) to 3x ARGB32 with absolutely no difference.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I'd like to know if somebody has an idea what could be done to improve this pass. Especially if I could be missing something that slows down.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;More precise question: &lt;strong&gt;WHAT THE HELL IS Stall Short Scoreboard ???&lt;/strong&gt; &#xA;The only info I found about this counter was that&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Warp was stalled waiting for a scoreboard dependency on a&#xA;  MIO (memory input/output) operation&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But I don't understand how I could reduce it. &#xA;Thanks in advance for any help. Hit me if you need any info that could be useful.&lt;/p&gt;&#xA;" OwnerUserId="10578" LastActivityDate="2019-04-30T17:31:05.780" Title="Optimisation of Geometry Pass" Tags="&lt;rendering&gt;&lt;directx11&gt;&lt;deferred-rendering&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8812" PostTypeId="2" ParentId="8398" CreationDate="2019-05-01T11:13:53.913" Score="-2" Body="&lt;p&gt;Right Click on the viewport PERSPECTIVE and enable viewport Clipping.&#xA;On the right of the screen, 2 yellow arrows will appear. Drag the bottom arrow up a little. Worked for me.&lt;/p&gt;&#xA;" OwnerUserId="10580" LastActivityDate="2019-05-01T11:13:53.913" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8813" PostTypeId="2" ParentId="8807" CreationDate="2019-05-01T22:39:54.980" Score="1" Body="&lt;p&gt;Maybe something quick (to set up, no guarantees of actual speed) and dirty. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whatever your method was, it probably boiled down to a vector function &#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;\begin{bmatrix} x,\, y,\, z\end{bmatrix} = F\Big([s,\, t,\, u] \,\, \Big| \,\, V_{ijk} \, : i,j,k = 1..N\Big)&#xA;\end{align}&lt;/span&gt;  where &lt;span class=&quot;math-container&quot;&gt;$V_{ijk} \in \mathbb{R}^3$&lt;/span&gt;are the vertices of the three dimensional lattice.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, you currently have the new coordinates &lt;span class=&quot;math-container&quot;&gt;$[x,\, y,\, z]$&lt;/span&gt; of a point, and you want to find the original ones &lt;span class=&quot;math-container&quot;&gt;$[s,\, t,\, u]$&lt;/span&gt;. I hope you still have the coordinates of the lattice vertices &lt;span class=&quot;math-container&quot;&gt;$V_{ijk}$&lt;/span&gt;. To retrieve the initial coordinates &lt;span class=&quot;math-container&quot;&gt;$[s,\, t,\, u]$&lt;/span&gt; you have to solve for &lt;span class=&quot;math-container&quot;&gt;$[s,\, t,\, u]$&lt;/span&gt; the system of equations&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;\begin{bmatrix} x,\, y,\, z\end{bmatrix} = F\Big([s,\, t,\, u] \,\, \Big| \,\, V_{ijk} \, : i,j,k = 1..N\Big)&#xA;\end{align}&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$[x,\, y,\, z]$&lt;/span&gt; is given and the points &lt;span class=&quot;math-container&quot;&gt;$V_{ijk}$&lt;/span&gt; are given &#xA;For simplicity, I am going to write &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix} x,\, y,\, z\end{bmatrix} = F\big([s,\, t,\, u] \,\, \big| \,\, V \,\big)$$&lt;/span&gt;&#xA;To solve it, use a type of Newton's method.&#xA;Set a small enough number &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Set your initial &lt;span class=&quot;math-container&quot;&gt;$s_0=x, t_0=y, u_0=z$&lt;/span&gt; and set up your error equal to &lt;span class=&quot;math-container&quot;&gt;$err = 1$&lt;/span&gt; (or whatever).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While &lt;span class=&quot;math-container&quot;&gt;$err \geq h^2$&lt;/span&gt; execute the following iteration:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Assume you have a current approximation &lt;span class=&quot;math-container&quot;&gt;$[s_n,\, t_n,\, u_n]$&lt;/span&gt;;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate the following three three-vector (as rows) &#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;&amp;amp;\Delta_s F_n = \frac{1}{h} \Big( \, F\big([s_n+h,\, t_n,\, u_n] \,\, \big| \,\, V \,\big) - F\big([s_n,\, t_n,\, u_n] \,\, \Big| \,\, V \,\big) \, \Big)\\&#xA;&amp;amp;\Delta_t F_n = \frac{1}{h} \Big( \, F\big([s_n,\, t_n+h,\, u_n] \,\, \big| \,\, V \,\big) - F\big([s_n,\, t_n,\, u_n] \,\, \Big| \,\, V \,\big) \, \Big)\\&#xA;&amp;amp;\Delta_u F_n = \frac{1}{h} \Big( \, F\big([s_n,\, t_n,\, u_n+h] \,\, \big| \,\, V \,\big) - F\big([s_n,\, t_n,\, u_n] \,\, \Big| \,\, V \,\big) \, \Big)&#xA;\end{align}&lt;/span&gt;   &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Set the following three by three matrix &#xA;&lt;span class=&quot;math-container&quot;&gt;$$M_n = \begin{bmatrix} \Delta_s F_n \\  \Delta_t F_n \\ &#xA;   \Delta_u F_n\end{bmatrix}$$&lt;/span&gt; (the vectors are the ones computed above but transposed and are therefore vector-columns);&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate the inverse matrix &lt;span class=&quot;math-container&quot;&gt;$M_n^{-1}$&lt;/span&gt;;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate the update&#xA;&lt;span class=&quot;math-container&quot;&gt;$$[s_{n+1},\, t_{n+1},\, u_{n+1}] = [s_n,\, t_n,\, u_n] + \Big(\,[x,\, y,\, z] - F\big([s_n,\, t_n,\, u_n] \,\, \Big| \,\, V \,\big)\,\Big)\, M_n^{-1}$$&lt;/span&gt; &#xA;(all of this is written as vector matrix multiplication, where you are working with &lt;span class=&quot;math-container&quot;&gt;$1 \times 3$&lt;/span&gt; row-vectors and multiplying such&lt;span class=&quot;math-container&quot;&gt;$1 \times 3$&lt;/span&gt; row-vectors with the &lt;span class=&quot;math-container&quot;&gt;$3 \times 3$&lt;/span&gt; matrix &lt;span class=&quot;math-container&quot;&gt;$M_n^{-1}$&lt;/span&gt; on the right)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate the error &lt;span class=&quot;math-container&quot;&gt;$$err = \Big\|\, [x,\, y,\, z] - F\big([s_{n+1},\, t_{n+1},\, u_{n+1}] \,\, \Big| \,\, V \,\big)\, \Big\|^2$$&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Go back to the beginning of the iteration to check whether &lt;span class=&quot;math-container&quot;&gt;$err \geq h^2$&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The result of this iteration is an approximation of the coordinates &lt;span class=&quot;math-container&quot;&gt;$[s,\, t,\, u]$&lt;/span&gt;. I hope this works. &lt;/p&gt;&#xA;" OwnerUserId="8851" LastActivityDate="2019-05-01T22:39:54.980" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8815" PostTypeId="1" AcceptedAnswerId="8817" CreationDate="2019-05-02T12:07:21.657" Score="4" ViewCount="369" Body="&lt;p&gt;I am implementing my own simple ray tracing and I came across some sort of confusion. When defining the verticies in the world I multiply them by the modelView transformation system (the matrix similar to the one generated by glm::lookAt function) in order to transform them to the camera coordinate. However, the verticies are invisible in the world when I do this transformation. My question is: are we supposed to transform the veriticies in Ray tracing with the model view transformation matrix as we do in OpenGL ?&lt;/p&gt;&#xA;" OwnerUserId="10590" LastEditorUserId="10590" LastEditDate="2019-05-02T12:21:44.030" LastActivityDate="2019-05-03T13:34:16.350" Title="Camera Model View transformation in Ray Tracing" Tags="&lt;raytracing&gt;&lt;transformations&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8817" PostTypeId="2" ParentId="8815" CreationDate="2019-05-03T13:34:16.350" Score="4" Body="&lt;p&gt;The space at which you transform your vertices is completely up to you, because it depends on what algorithms and kind of effects that you are trying to achieve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As of my personal experience, I usually shoot rays in world space because eventually we all need some sort of &quot;world-space&quot; acceleration data structure, such as a space-partition tree, that gathers all objects into a single space. As this data structure is probably going to be pre-computed for static objects, world space seems to be the most preferred one, as the vertices representation never change when you move the camera around. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When it comes the time to actually test the ray-object intersection, I transform the ray direction onto object space by using the inverse of the model matrix. This makes it possible for all intersection tests to be implemented as if the object were axis-aligned. Thus, you can easily use AABBs (axis-aligned bounding boxes) for coarse intersection testing, even when your models are rotated in world space. This is also a good optimisation for dynamic objects, as the AABB does not change in object space.&lt;/p&gt;&#xA;" OwnerUserId="4768" LastActivityDate="2019-05-03T13:34:16.350" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8818" PostTypeId="2" ParentId="8787" CreationDate="2019-05-03T14:01:49.637" Score="2" Body="&lt;p&gt;Describing a full CSG algorithm in a forum post is something really hard, and probably you will not find a complete answer to what you are asking here, but I can give you some suggestions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First of all, CSG on polygon meshes is not usually employed on real-time graphics, because the algorithms are still considered to be too much resource-intensive. If you are looking for these kinds of algorithms, I would suggest reading books on computational geometry, of which Mark De Berg's is commonly considered a good introduction to the topic. If you are planning to pre-compute everything, then classic CSG algorithms are the way to go.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, for just adding craters on a field, CSG seems to be too much overkill to me, and I would suggest some completely different approaches. If you want just a visual result (i.e., your player won't be able to go into the crater), you could use techniques such as z-buffer carving or parallax occlusion mapping, combined with some sort of decal system (preferably, using some deferred-like rendering system). Otherwise, if you need proper collision detection, you will actually need to change your mesh. You can easily apply some vertex modification operators around the center of each crater, such as pushing them down according to a radial-basis function (i.e., spheres, gaussians, etc). To accomplish this in realtime graphics, I would suggest using compute shaders or vertex feedback transforms, instead of computing everything in the CPU. These techniques will even allow you to add craters dynamically. Think of some really nice meteor strikes taking place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm sorry for not being too descriptive, but I hope that some of the keywords that I have put here may help you out on finding a solution to your problem.&lt;/p&gt;&#xA;" OwnerUserId="4768" LastEditorUserId="4768" LastEditDate="2019-05-03T14:07:56.703" LastActivityDate="2019-05-03T14:07:56.703" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8820" PostTypeId="1" CreationDate="2019-05-05T17:31:13.800" Score="4" ViewCount="418" Body="&lt;p&gt;Perfect mirror's brdf is simple,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$F\frac{\delta(\omega_i-\omega_r)}{|\cos(\theta_r)|}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as in &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Reflection_Models/Specular_Reflection_and_Transmission.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Reflection_Models/Specular_Reflection_and_Transmission.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As shown in several articles, microfacet brdf can have zero roughness by definition then they should be able to represent a perfect mirror. But I cannot derive them to above correct perfect brdf.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, when I put zero roughness into GGX model,&#xA;(&lt;a href=&quot;https://www.graphics.cornell.edu/~bjw/microfacetbsdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.graphics.cornell.edu/~bjw/microfacetbsdf.pdf&lt;/a&gt; )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;D(m) = D(H) goes to infinity by divided by 0 and G is just one. However, the brdf I got is,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$F\frac{DG}{4|N\cdot V||N\cdot L|}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then rendering equation is,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\int F\frac{D(H)G(L,V, H)}{4|N\cdot V||N\cdot L|} \cos\theta_id\omega_i = \int F\frac{D(H)G(L,V, H)}{4|N\cdot V|} d\omega_i$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this was correct, &lt;span class=&quot;math-container&quot;&gt;$\frac{D(H)G(L,V,H)}{4|N\cdot V|}$&lt;/span&gt; should be a dirac delta function. But I don't think so.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where am I wrong? How can I derive a perfect mirror from microfacet brdf?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I concluded that Cook-Torrance's brdf can not represent a perfect mirror. The equation has some small value greater than zero when H &lt;span class=&quot;math-container&quot;&gt;$\neq$&lt;/span&gt; N even if roughness is zero. So, normalization factor &lt;span class=&quot;math-container&quot;&gt;$4|N\cdot V|$&lt;/span&gt; should be not be removed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Correct me if I was wrong.&lt;/p&gt;&#xA;" OwnerUserId="10601" LastEditorUserId="10601" LastEditDate="2019-05-06T08:07:21.380" LastActivityDate="2019-05-07T06:24:24.303" Title="Can microfacet BRDF (including ggx) represent perfect mirror?" Tags="&lt;brdf&gt;&lt;microfacet&gt;&lt;ggx&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8822" PostTypeId="2" ParentId="8074" CreationDate="2019-05-06T04:53:38.723" Score="1" Body="&lt;p&gt;Depth buffer values are clamped to that range because usually they are using fixed-point representation, so if clipping is disabled (by &lt;code&gt;glEnable(GL_DEPTH_CLAMP)&lt;/code&gt;) then they can't hold anything beyond that range.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, there isn't really a good reason for this clamping when floating point depth buffers are used. In fact &lt;code&gt;GL_NV_depth_buffer_float&lt;/code&gt; extensions allows you to disable this clamping on Nvidia hardware for floating point buffers. Unfortunately other vendors don't have any documented way of doing that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also it's worth noting that unclamped floating point depth values have a minor complication: their depth offset is trickier to define. OpenGL spec resolves this by making the depth offset depend on the range of z-coordinates of the primitive. In fixed-point depth buffers, on the other hand, the offset is a function of the triangle slope only.&lt;/p&gt;&#xA;" OwnerUserId="7057" LastActivityDate="2019-05-06T04:53:38.723" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8823" PostTypeId="2" ParentId="8773" CreationDate="2019-05-06T05:13:56.403" Score="1" Body="&lt;p&gt;It is compatible, but instead of clipping it now clamps (hence the name). If the depth of your primitives is outside the [0,1] range it ends up behaving as if you have no depth-test at all. The only way to mitigate that is to either scale down the depth range so it fits in [0,1] or to use &lt;code&gt;GL_NV_depth_buffer_float&lt;/code&gt; to disable clipping and clamping completely.&lt;/p&gt;&#xA;" OwnerUserId="7057" LastActivityDate="2019-05-06T05:13:56.403" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8824" PostTypeId="1" AcceptedAnswerId="8830" CreationDate="2019-05-06T17:50:36.397" Score="3" ViewCount="343" Body="&lt;p&gt;I'm going through the &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/rasterization-stage&quot; rel=&quot;nofollow noreferrer&quot;&gt;rasterizer tutorial from Scratchapixel&lt;/a&gt;, but I encountered a problem with the generation of the .ppm file. Since something was off, I reduced the example to the bare minimum, so I currently simply generate a 512x512 image of a plain color.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;fstream&amp;gt;&#xA;&#xA;using Rgb = unsigned char[3];&#xA;int main()&#xA;{&#xA;    const uint32_t w = 512;&#xA;    const uint32_t h = 512;&#xA;&#xA;    Rgb *framebuffer = new Rgb[w * h];&#xA;    for (uint32_t j = 0; j &amp;lt; h; ++j) {&#xA;        for (uint32_t i = 0; i &amp;lt; w; ++i) {&#xA;            framebuffer[j * w + i][0] = static_cast&amp;lt;unsigned char&amp;gt;(255);&#xA;            framebuffer[j * w + i][1] = static_cast&amp;lt;unsigned char&amp;gt;(0);&#xA;            framebuffer[j * w + i][2] = static_cast&amp;lt;unsigned char&amp;gt;(0);&#xA;        }&#xA;    }&#xA;&#xA;    std::ofstream ofs;&#xA;    ofs.open(&quot;./example.ppm&quot;);&#xA;    ofs &amp;lt;&amp;lt; &quot;P6\n&quot; &amp;lt;&amp;lt; w &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; h &amp;lt;&amp;lt; &quot;\n255\n&quot;;&#xA;    ofs.write((char*)framebuffer, w * h * 3);&#xA;    ofs.close();&#xA;&#xA;    delete[] framebuffer;&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The code above should generate a red square image, but if I open the file with Gimp, I get a green image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LgOJV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LgOJV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have any idea of what's happening?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: This is the .ppm file with a hex editor:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vA9dG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vA9dG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8807" LastEditorUserId="2289" LastEditDate="2020-12-18T23:02:41.210" LastActivityDate="2020-12-18T23:02:41.210" Title="Wrong color in .ppm file" Tags="&lt;c++&gt;&lt;image-processing&gt;&lt;raster-image&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8825" PostTypeId="1" AcceptedAnswerId="8833" CreationDate="2019-05-07T05:59:40.460" Score="2" ViewCount="400" Body="&lt;p&gt;Here's the problem :&#xA;I have multiple noise generators in my program I Can't change.&#xA;Perlin Noise, Diamond Square, Voronoi, etc.&#xA;Unfortunately for me, I want the noise to be tileable, no matter the generator :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea is to create a torus-like strategy game with the user choosing a noise and then having it tiled to play on it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm very well aware it's a rather poor design to make it tileable afterwards, but it's a time saver for the coding part.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you in advance for your help and ideas.&lt;/p&gt;&#xA;" OwnerUserId="10605" LastActivityDate="2020-02-27T05:03:00.460" Title="Nice way to make noise seamless (without tampering with the noise generator)" Tags="&lt;texture&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8826" PostTypeId="2" ParentId="8820" CreationDate="2019-05-07T06:24:24.303" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;If this was correct, &lt;span class=&quot;math-container&quot;&gt;$\frac{D(H)G(L,V,H)}{4|N⋅V|}$&lt;/span&gt; should be a dirac delta function. But I don't think so.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Actually, you're close to your answer - you just are trying to find out, what the assumption was in the very beginning - if you're talking about a specular BRDF. The term  &lt;span class=&quot;math-container&quot;&gt;$F\frac{DG}{4|N⋅V||N⋅L|}$&lt;/span&gt; only works, if you start with the precondition, that you're dealing with a perfect mirror, otherwise this would be an integral itself. Have a look at &lt;a href=&quot;https://www.gdcvault.com/play/1024478/PBR-Diffuse-Lighting-for-GGX&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBR Diffuse Lighting for GGX+SmithMicrosurfaces&lt;/a&gt; by Earl Hammon Jr., where explains how to get to the specular BRDF. Especially have a look at slide 29:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Microfacet BRDF is a perfect mirror &#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I.e., light reflects if and only if &lt;span class=&quot;math-container&quot;&gt;$m = H$&lt;/span&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Mathematically, BRDF is a scaled dirac delta &lt;span class=&quot;math-container&quot;&gt;$\delta_m(H, m)$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So the perfect mirror is your model in the beginning&lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt; - but only for the specular BRDF! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are trying to see, if including the diffuse BRDF into your BRDF is a perfect mirror, then this assumption does not hold any more and thus you don't have the dirac delta function.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt; Note that he speaks about a microfacet being a perfect mirror. However, if all your microfacets are perfectly aligned, then your microgeometry &quot;equals&quot; your macrogeometry&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2019-05-07T06:24:24.303" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8827" PostTypeId="2" ParentId="8562" CreationDate="2019-05-07T10:45:00.733" Score="2" Body="&lt;p&gt;For others who might have this question, here a perhaps more straight forward numeric answer (I'm now working myself on this book as well). Consider that:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;We are given object space coordinates that need to be transformed into upright and subsequently world space coordinates.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;We know that a vector &lt;span class=&quot;math-container&quot;&gt;$\vec{v}$&lt;/span&gt; can be represented as a linear transformation of its axises in relation to the set of basis vectors &lt;span class=&quot;math-container&quot;&gt;$\vec{p}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\vec{q}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\vec{r}$&lt;/span&gt;, when these are &lt;strong&gt;&lt;em&gt;orthonormal&lt;/em&gt;&lt;/strong&gt; (perpendicular to each other and with length &lt;span class=&quot;math-container&quot;&gt;$l = 1$&lt;/span&gt;)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The equation to represent this is thus: &lt;span class=&quot;math-container&quot;&gt;$\vec{v} = v_{x}p + v_{y}q + v_{z}r$&lt;/span&gt; &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Given the basis vectors we can computed this for each object reference using the above equation. So, the first example would be:&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\vec{u} = -1 \begin{bmatrix}0.866\\ 0\\ -0.500 \end{bmatrix} + 2 \begin{bmatrix}0\\ 1\\ 0\end{bmatrix} + 0 \begin{bmatrix}0.500\\ 0\\ 0.866\end{bmatrix} = \begin{bmatrix}-0.866\\ 2\\ 0.500\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, to compute this in world space, you simply need to add your world space reference to the upright vector. Meaning:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\vec{w} = o + u$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the first example in the book that would be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\vec{w} = \begin{bmatrix}1\\ 10\\ 3\end{bmatrix} + \begin{bmatrix}-0.866\\ 2\\ 0.500\end{bmatrix} = \begin{bmatrix}0.134\\ 12\\ 3.500\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="10607" LastActivityDate="2019-05-07T10:45:00.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8830" PostTypeId="2" ParentId="8824" CreationDate="2019-05-09T00:59:46.153" Score="2" Body="&lt;p&gt;The issue is that on your system, writing out &quot;\n&quot; is writing out 0x0D0A, whereas on my system, it's only writing out 0x0A. If you explicitly write out 0x0A instead of &quot;\n&quot; I think it will work for you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a hex dump on macOS Mojave:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;50 36 0A 35 &#xA;31 32 20 35 &#xA;31 32 0A 32 &#xA;35 35 0A &#xA;FF 00 00 // &amp;lt;- pixels start here&#xA;FF 00 00 &#xA;FF 00 00 &#xA;FF 00 00 &#xA;FF 00 00 &#xA;FF 00 00&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-05-09T00:59:46.153" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8831" PostTypeId="1" CreationDate="2019-05-09T04:56:37.033" Score="2" ViewCount="71" Body="&lt;p&gt;I am currently trying to implement &lt;a href=&quot;https://graphics.stanford.edu/papers/bssrdf/bssrdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jensen's paper on subsurface scattering&lt;/a&gt;, but I am getting confused when I am trying to implement it in my pathtracer. I have questions about the data types of certain variables.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;On page 3, &lt;span class=&quot;math-container&quot;&gt;$z_r$&lt;/span&gt; is defined as &lt;span class=&quot;math-container&quot;&gt;$1 / \sigma_t'$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\sigma_t' = \sigma_s' + \sigma_a$&lt;/span&gt;. Based on Figure 5, &lt;span class=&quot;math-container&quot;&gt;$\sigma_s'$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\sigma_a$&lt;/span&gt; are RGB values, which are &lt;code&gt;Spectrum&lt;/code&gt; types in my pathtracer. However, &lt;span class=&quot;math-container&quot;&gt;$z_r$&lt;/span&gt; is expected to be a distance above the surface, which I presume must be a float, not a &lt;code&gt;Spectrum&lt;/code&gt;. How do I handle this discrepancy? Does each RGB wavelength have its own &lt;span class=&quot;math-container&quot;&gt;$z_r$&lt;/span&gt;?&lt;/li&gt;&#xA;&lt;li&gt;There is a similar issue in the single scattering term in section 4. &lt;span class=&quot;math-container&quot;&gt;$s_o'$&lt;/span&gt; is a distance along the refracted outgoing ray, which is presumably a float. However, the formula for this term uses &lt;span class=&quot;math-container&quot;&gt;$\sigma_t$&lt;/span&gt;, which is a &lt;code&gt;Spectrum&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;What about &lt;span class=&quot;math-container&quot;&gt;$\sigma_{tr}$&lt;/span&gt;? This value is &lt;span class=&quot;math-container&quot;&gt;$\sqrt{3\sigma_a\sigma_t'}$&lt;/span&gt;. Is this also a &lt;code&gt;Spectrum&lt;/code&gt; or a float?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="10624" LastActivityDate="2019-05-09T07:02:52.477" Title="Confusion about data types in Jensen's subsurface scattering paper" Tags="&lt;c++&gt;&lt;brdf&gt;&lt;subsurface-scattering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8832" PostTypeId="2" ParentId="8831" CreationDate="2019-05-09T07:02:52.477" Score="2" Body="&lt;p&gt;The heading row of Figure 5(b) says that the units of &lt;span class=&quot;math-container&quot;&gt;$\sigma_s'$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\sigma_a$&lt;/span&gt; are inverse millimetres, that is, inverse distance. Hence, &lt;span class=&quot;math-container&quot;&gt;$1/\sigma_t'$&lt;/span&gt; has units of distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you send a beam of photons through a medium with scattering coefficient &lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt; and measure it at distance &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt;, then the probability that a photon has made it that far without being scattered is &lt;span class=&quot;math-container&quot;&gt;$e^{-\sigma l}$&lt;/span&gt;. Since &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; has units of distance, &lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt; must have units of inverse distance.&lt;/p&gt;&#xA;" OwnerUserId="159" LastActivityDate="2019-05-09T07:02:52.477" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8833" PostTypeId="2" ParentId="8825" CreationDate="2019-05-09T16:32:44.307" Score="1" Body="&lt;p&gt;If you can't change the textures, I see 2 possibilities:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Use mirrored repeat on the noise textures so they tile seamlessly. &lt;a href=&quot;https://i.stack.imgur.com/TEM45.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TEM45.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; (taken from &lt;a href=&quot;https://open.gl/textures&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Do like &lt;a href=&quot;https://www.gimp.org/tutorials/Tileable_Textures/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Gimp does&lt;/a&gt; (or many other alternatives) and create tilable versions of the noise textures. The idea is to blend the left and right, and bottom and top edges together in pairs. Here's how to do it in an image editor: translate the image by 1/2 in both axis so the corners are in the middle. Blur, smudge, etc. to remove the seams. Revert the translation.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/b7PI0.jpg&quot; alt=&quot;enter image description here&quot;&gt; &lt;img src=&quot;https://i.stack.imgur.com/O17G1.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Keep in mind that the randomness and quality of the noise will of course be affected by either technique.&lt;/p&gt;&#xA;" OwnerUserId="7644" LastActivityDate="2019-05-09T16:32:44.307" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8835" PostTypeId="1" AcceptedAnswerId="8842" CreationDate="2019-05-11T11:38:11.620" Score="3" ViewCount="1513" Body="&lt;p&gt;This question is regarding a homework assignment (want to be upfront because many people on stack exchange don't like helping with homework questions).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a triangular mesh, which is defined by a set of vertices and a set of faces.&#xA;I want to calculate the discrete gradient of the mesh, and I even got instructions on how to implement it. The problem is that even after reading them multiple times, I don't understand them...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The implementation instructions:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MTZ2w.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MTZ2w.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My Problem:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't understand how to implement the marked sum, which in turn prevents me from constructing the following E matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would appreciate any help. I'm not looking for specific code examples, rather an explanation/example of the calculation for a single triangle. &lt;/p&gt;&#xA;" OwnerUserId="10633" LastActivityDate="2021-02-20T00:38:32.060" Title="Calculating the gradient of a triangular mesh" Tags="&lt;computational-geometry&gt;&lt;matlab&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8836" PostTypeId="1" CreationDate="2019-05-11T23:00:52.860" Score="5" ViewCount="357" Body="&lt;p&gt;I am trying to render a teapot within a simple raytracing that can handle reflection, refraction, and shadowing from point and directional lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am very confused about one detail of the raytracer and that is the interpolated normals. This question was brought on when my raytracer rendered this image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/c3SRI.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c3SRI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now there are more than a couple issues with this render however it did bring up an important point. Not using interpolated normals causes blocking reflections like this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had previously figured that I should not use interpolated normals when calculating reflection or refraction rays. I had previously figured that I should not do it because that might introduce edge cases as reflecting off an interpolated normal would have the ray bouncing off the wrong position since I am shading it like its smooth. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also feel like this might introduce edge cases when it comes time to implement accelerating spatial data structures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I guess my question is where should/shouldn't I be using interpolated normals in my ray-tracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am betting there is a different protocol if you are rendering a feature animated film vs just creating a toy/lightweight/quick raytracer. I would love to know the answer for both.&lt;/p&gt;&#xA;" OwnerUserId="7072" LastActivityDate="2019-05-12T10:53:05.347" Title="Dealing with interpolated normals within a raytracer" Tags="&lt;raytracing&gt;&lt;ray&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8838" PostTypeId="2" ParentId="8836" CreationDate="2019-05-12T10:53:05.347" Score="1" Body="&lt;p&gt;Disclaimer: It's been a long time since I looked at this sort of thing but here goes...&lt;br&gt;&#xA;Disclaimer2: On re-reading your question(s) I realised I might have misunderstood what you were asking. I'll leave this here just in case you were looking for this sort of reply.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are you rendering from the original Bezier patch definition (e.g. &lt;a href=&quot;https://www.cs.utah.edu/gdc/projects/alpha1/help/man/html/model_repo/model_teapot/teapot.pts&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.cs.utah.edu/gdc/projects/alpha1/help/man/html/model_repo/model_teapot/teapot.pts&lt;/a&gt;)  or from a (post tessellation) triangle representation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the former, then you should, in the &lt;strong&gt;vast majority&lt;/strong&gt; of cases, be able to 'trivially' generate the normals directly from the Bezier representation, by computing surface partial derivatives at each ray intersection point, to give tangent vectors, and computing the cross product. The cases you &lt;em&gt;do&lt;/em&gt; have to watch out for are at very centres of the bottom and top of the teapot where the patches, though &lt;em&gt;geometrically&lt;/em&gt; well-defined, have a zero partial derivative because the rectangular patch has been squeezed into a triangle, e.g. control points for U,V = (0,0), (0,1/3), (0,2/3), (0,1) are all identical, so dPos/dv is 0.  All you need do is compute dPos/du at (0,0) and (0,1) to get valid tangents.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are rendering from triangles, I assume you already have normals at the triangle vertices. If you use an appropriate ray-triangle intersection test you can get the barycentric coordinates of the intersection point. Use these to blend the vertex normals (and after renormalising) you'll have a 'reasonable' surface normal (though it will only be C0 continuous).&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2019-05-12T10:53:05.347" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8839" PostTypeId="1" CreationDate="2019-05-12T11:30:24.513" Score="0" ViewCount="32" Body="&lt;p&gt;Imagine I have an x value that ranges from 1-100. The light source is pointed at x=50.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From points 35 to 65 I want intensity to be 1&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At the ends (ie 1 and 100), intensity should be 0&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What formula should be used to model the in between values ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cosine ? Inverse square law ? ratio ?&lt;/p&gt;&#xA;" OwnerUserId="10635" LastActivityDate="2019-05-12T11:30:24.513" Title="gradual transition of light intensity formula" Tags="&lt;lighting&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8840" PostTypeId="1" CreationDate="2019-05-12T16:12:09.457" Score="2" ViewCount="73" Body="&lt;p&gt;I have come across this image that's labelled a bump map to be used with a 3D model. It looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WimNC.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WimNC.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this map, which is an RGB map, it seems we have pixels whose normals face upwards shaded lighter, and normals pointing downward shaded darker. I have isolated just one part of this map, a little mound with a whole in the middle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eQaRw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eQaRw.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried to recreate this shape in an image editing program just using white colour for height, it's essentially a heightmap, or bumpmap. It looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jxIQ4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jxIQ4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's basically a circular mound that rises gradually, and then falls off steeply into a hole.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I know that this is one way normals and height can be stored. This is essentially a heightmap, but some people and programs call this a bumpmap. In 3DS Max the bumpmap essentially expects a heightmap.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then there's the normal map, which looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Hw3GH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Hw3GH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inside the red channel the information about how flat or inclined the surface is from left to right:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fhPaa.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fhPaa.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And same as in the green, except from up to down:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uOP5N.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uOP5N.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I understand this, I think. However in the original image, this strange &quot;bumpmap&quot;, it only seems to contain the information of the flatness of the surface from up to down, not left to right. What I've shown is how it appears as an RGB image. Here is each of the channels:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9VLiF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9VLiF.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kq7EN.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kq7EN.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cC1Uh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cC1Uh.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They all contain the same information, that is, facing of the surface from up to down. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How is this map supposed work? I've come across a few maps like these but I don't see how they're supposed to work. Can someone explain if this is possible?&lt;/p&gt;&#xA;" OwnerUserId="10333" LastActivityDate="2019-05-12T16:54:19.887" Title="How is this normals map supposed to work?" Tags="&lt;normal-mapping&gt;&lt;mapping&gt;&lt;height-field&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8841" PostTypeId="2" ParentId="8840" CreationDate="2019-05-12T16:54:19.887" Score="1" Body="&lt;p&gt;Yeah, that doesn’t look like any bump, height, or normal map I’ve ever seen—as you’ve identified, there’s only information about the surface contour along a single axis. If anything, it looks like it’s meant to be overlaid on a texture as a cheap form of fake bump-mapping in an era where it was too expensive to do it for real.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-05-12T16:54:19.887" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8842" PostTypeId="2" ParentId="8835" CreationDate="2019-05-13T03:07:30.967" Score="2" Body="&lt;p&gt;A function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; on your triangulated surface is an assignment of real numbers on the vertices of the triangulation and therefore &lt;span class=&quot;math-container&quot;&gt;$f \in \mathbb{R}^{|\mathcal{V}|}$&lt;/span&gt;. According to the continuous theory, the gradient should be a linear (differential) operator that takes a function and spits out a vector field. Hence, in the discrete theory, the gradient should be a linear operator that takes a function &lt;span class=&quot;math-container&quot;&gt;$f \in \mathbb{R}^{|\mathcal{V}|}$&lt;/span&gt; and spit out some kind of a discrete version of a vector field. In your case, the vector field is given as an assignment of a vector to each triangle of the triangulation. That is why the discrete gradient operator should be a linear operator, i.e. a linear transformation&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\text{grad} : \mathbb{R}^{\mathcal{|V|}} \to \mathbb{R}^{3|\mathcal{F}|}$$&lt;/span&gt;&lt;br&gt;&#xA;which is represented by a matrix &lt;span class=&quot;math-container&quot;&gt;$\text{grad} \in \mathbb{R}^{3|\mathcal{F}| \times |\mathcal{V}|}$&lt;/span&gt;. In the continuous theory, the gradient is determined only by local data, i.e. the behaviou of the function near the point at which the gradient is being calculated and by the geometry near that point. Therefore, in the discrete theory, the gradient is determined only by the geometry of one triangle and the values of the function at the triangle's vertices. Let the triangle &lt;span class=&quot;math-container&quot;&gt;$j \in  \mathcal{F}$&lt;/span&gt; have vertices denoted (according to the instructions' convention) by &lt;span class=&quot;math-container&quot;&gt;$1, 2, 3$&lt;/span&gt;. The labels are set up so that the vertices &lt;span class=&quot;math-container&quot;&gt;$1,2,3$&lt;/span&gt; define the labels of the opposing edges &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_1}, \vec{e}_{j_2}, \vec{e}_{j_3}$&lt;/span&gt;, i.e. for the vertex  &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; the edge opposite to the vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; is denoted by &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_i}$&lt;/span&gt;, where the latter vector is oriented so that the vectors form a closed chain of vectors summing to zero in a counterclockwise direction.&lt;br&gt;&#xA;Hence, the gradient can be defined as&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(\text{grad}\,f)(j) = \frac{1}{2\text{Area}(j)}\, \sum_{i=1}^{3} f_i\, J\vec{e}_{j_i}$$&lt;/span&gt; Or to write it in coordinates, &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix} (\text{grad}\,f)(j)_1\\ (\text{grad}\,f)(j)_2\\(\text{grad}\,f)(j)_3\end{bmatrix} = \frac{1}{2\text{Area}(j)}\left( f_1\, \begin{bmatrix} (Je_{j_1})_1\\ (Je_{j_1})_2\\(Je_{j_1})_3\end{bmatrix} + &#xA;f_2\, \begin{bmatrix} (Je_{j_2})_1\\ (Je_{j_2})_2\\(Je_{j_2})_3\end{bmatrix} + f_3\, \begin{bmatrix} (Je_{j_3})_1\\ (Je_{j_3})_2\\(Je_{j_3})_3\end{bmatrix}\right)$$&lt;/span&gt; and in matrix form&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix} (\text{grad}\,f)(j)_1\\ (\text{grad}\,f)(j)_2\\(\text{grad}\,f)(j)_3\end{bmatrix} = \frac{1}{2\text{Area}(j)}\, \begin{bmatrix} (Je_{j_1})_1 &amp;amp;  (Je_{j_2})_1 &amp;amp; (Je_{j_3})_1 \\ (Je_{j_1})_2 &amp;amp; (Je_{j_2})_2 &amp;amp; (Je_{j_3})_2\\(Je_{j_1})_3 &amp;amp; (Je_{j_2})_3 &amp;amp; (Je_{j_3})_3 \end{bmatrix} \begin{bmatrix} f_1\\ f_2\\f_3\end{bmatrix} $$&lt;/span&gt;&#xA;So, for the matrix &lt;span class=&quot;math-container&quot;&gt;$E \in \mathbb{R}^{3|\mathcal{F}|\times|\mathcal{V}|}$&lt;/span&gt; is defined as follows. Let &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; be a triangle and &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; one of its vertices. Take the edge &lt;span class=&quot;math-container&quot;&gt;$e_{j_i}$&lt;/span&gt; of triangle &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; opposite to the vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;, and consider the vector &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_i}$&lt;/span&gt; along the edge, starting from one vertex, different from &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;, to the other vertex, different from &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;, oriented so that the the vector follows counterclockwise orientation of the boundary of the triangle &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;. Then rotate the vector &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_i}$&lt;/span&gt; by &lt;span class=&quot;math-container&quot;&gt;$90^{\circ}$&lt;/span&gt; so that it points inside the triangle &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;. Denote this rotated vector by  &lt;span class=&quot;math-container&quot;&gt;$$J\vec{e}_{j_i} = \begin{bmatrix} (Je_{j_i})_1\\ (Je_{j_i})_2\\(Je_{j_i})_3\end{bmatrix}$$&lt;/span&gt; Then fill up the following entries of the matrix &lt;span class=&quot;math-container&quot;&gt;$E \in \mathbb{R}^{3|\mathcal{F}|\times|\mathcal{V}|}$&lt;/span&gt;:&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align}&#xA;&amp;amp;E(j,i) = (Je_{j_i})_1\\&#xA;&amp;amp;E(j + |\mathcal{F}|, i) = (Je_{j_i})_2\\&#xA;&amp;amp;E(j + 2|\mathcal{F}|, i) = (Je_{j_i})_3&#xA;\end{align}&lt;/span&gt;&lt;br&gt;&#xA;You can rotate the vector &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_i}$&lt;/span&gt; by using the cross-product operation twice. Take two of the edge-vectors of the triangle &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;, say &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_1}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{e}_{j_2}$&lt;/span&gt;, and calculate the unit normal vector to the triangle &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{n}_j = \frac{1}{\|\vec{e}_{j_1} \times \vec{e}_{j_2}\|}\,\Big(\vec{e}_{j_1} \times \vec{e}_{j_2}\Big)$$&lt;/span&gt; It doesn't matter whcih two out of the three edge-vector you would choose, the result is always the same unit normal &lt;span class=&quot;math-container&quot;&gt;$\vec{n}_j$&lt;/span&gt;. Then&#xA;&lt;span class=&quot;math-container&quot;&gt;$$J\vec{e}_{j_i} = \vec{n}_j \times \vec{e}_{j_i}$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="8851" LastEditorUserId="8851" LastEditDate="2019-05-13T22:43:40.147" LastActivityDate="2019-05-13T22:43:40.147" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8843" PostTypeId="1" CreationDate="2019-05-13T08:31:42.307" Score="3" ViewCount="168" Body="&lt;p&gt;I'm trying to complete a look-up table for an energy-conserving variation of microfacet GGX as implemented here: &lt;a href=&quot;https://patapom.com/blog/BRDF/MSBRDFEnergyCompensation/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://patapom.com/blog/BRDF/MSBRDFEnergyCompensation/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a (pretty standard) GGX form of the microfacet equation and my white furnace test behaves similar to what is shown elsewhere (i.e., it loses energy as roughness increases).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when I attempt to integrate the brdf and store the total energy in a texture, I get results that are inverse to my expectation - higher roughness yields more total energy in the integral. Some code below (this is done in a compute shader):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float evalSum = 0.0;&#xA;const float theta_i = 0.05;&#xA;const float phi_i = 0.05;&#xA;for (float phiWi = 0.0; phiWi &amp;lt; PI2; phiWi += phi_i)&#xA;{&#xA;    for (float NoL = 0.0; NoL &amp;lt; 1.0; NoL += theta_i)&#xA;    {&#xA;        float nohA = 1.0 + NoL * NoV + (1.0 - NoV * NoV) * (1.0 - NoL * NoL) * cos(phiWi);&#xA;        float NoH = (NoL + NoV) / sqrt(2.0 * nohA);&#xA;&#xA;        float D = Fs.eNDF(NoH, roughness);&#xA;        float G = Fs.eGS(NoV, NoL, roughness);&#xA;        float Fr = D * G;&#xA;&#xA;        evalSum += Fr * NoL;&#xA;    }   &#xA;}&#xA;&#xA;outBuf[idx] = evalSum * phi_i * theta_i;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is my texture output:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Oi3iT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Oi3iT.png&quot; alt=&quot;LUT&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm expecting something more like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SvxNN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SvxNN.png&quot; alt=&quot;energycomp&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the Y axis goes down, roughness increases, and as the X axis goes to the right, &lt;code&gt;NoV&lt;/code&gt; (N dot V) increases. Total energy increases with roughness and I also get a strange valley to the energy which I wasn't expecting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the two GGX terms:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float getNDF(const float NoH, float linearRoughness)&#xA;{&#xA;    float a2 = linearRoughness * linearRoughness;&#xA;    float b = NoH * NoH * (a2 - 1.0) + 1.0;&#xA;&#xA;    return a2 / (PI * (b * b));&#xA;}&#xA;&#xA;float getGS(const float NoV, const float NoL, const float linearRoughness)&#xA;{&#xA;    float a2 = linearRoughness * linearRoughness;&#xA;    float G_V = NoV + sqrt((NoV - NoV * a2) * NoV + a2);&#xA;    float G_L = NoL + sqrt((NoL - NoL * a2) * NoL + a2);&#xA;    return rcp(G_V * G_L);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Pretty stumped here. I must be doing the integral wrong somehow because the in-engine renders look correct - the brdf code seems straightforward. Any ideas on why my LUT is not producing the expected result?&lt;/p&gt;&#xA;" OwnerUserId="10270" LastEditorUserId="10270" LastEditDate="2019-05-15T01:11:38.457" LastActivityDate="2019-05-15T01:11:38.457" Title="Microfacet GGX not integrating as expected" Tags="&lt;brdf&gt;&lt;microfacet&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8847" PostTypeId="1" CreationDate="2019-05-16T14:32:26.623" Score="4" ViewCount="173" Body="&lt;p&gt;I'm reading through &lt;a href=&quot;https://learnopengl.com/PBR/IBL/Specular-IBL&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt;, and more specifically I'm trying to derive the equation that would explain the implementation the following shader (still in the same article):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;out vec4 FragColor;&#xA;in vec3 localPos;&#xA;&#xA;uniform samplerCube environmentMap;&#xA;uniform float roughness;&#xA;&#xA;const float PI = 3.14159265359;&#xA;&#xA;float RadicalInverse_VdC(uint bits);&#xA;vec2 Hammersley(uint i, uint N);&#xA;vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);&#xA;&#xA;void main()&#xA;{       &#xA;    vec3 N = normalize(localPos);    &#xA;    vec3 R = N;&#xA;    vec3 V = R;&#xA;&#xA;    const uint SAMPLE_COUNT = 1024u;&#xA;    float totalWeight = 0.0;   &#xA;    vec3 prefilteredColor = vec3(0.0);     &#xA;    for(uint i = 0u; i &amp;lt; SAMPLE_COUNT; ++i)&#xA;    {&#xA;        vec2 Xi = Hammersley(i, SAMPLE_COUNT);&#xA;        vec3 H  = ImportanceSampleGGX(Xi, N, roughness);&#xA;        vec3 L  = normalize(2.0 * dot(V, H) * H - V);&#xA;&#xA;        float NdotL = max(dot(N, L), 0.0);&#xA;        if(NdotL &amp;gt; 0.0)&#xA;        {&#xA;            prefilteredColor += texture(environmentMap, L).rgb * NdotL;&#xA;            totalWeight      += NdotL;&#xA;        }&#xA;    }&#xA;    prefilteredColor = prefilteredColor / totalWeight;&#xA;&#xA;    FragColor = vec4(prefilteredColor, 1.0);&#xA;}  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which is my understanding suppose to implement the computation of the integral&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;I = \int_{\Omega} L(\omega_i)d\omega_i&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I'm not entirely sure since &lt;code&gt;NdotL&lt;/code&gt; is also used in the computation so I might be wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems to me the idea is given &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; to sample a random halfway vector &lt;span class=&quot;math-container&quot;&gt;$H$&lt;/span&gt;, and based on this we can construct, by reflection, the light direction vector &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;, which would be random as well by construction. The article also mentions that &lt;span class=&quot;math-container&quot;&gt;$H$&lt;/span&gt; is sampled from a normal distribution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But anyway suppose I have samples &lt;span class=&quot;math-container&quot;&gt;$H^{1} ,\ldots, H^{N}$&lt;/span&gt; and therefore &lt;span class=&quot;math-container&quot;&gt;$L^{1},\ldots, L^{N}$&lt;/span&gt; samples, the latter I suppose would define &lt;span class=&quot;math-container&quot;&gt;$\omega_{i}^{1} \ldots, \omega_{i}^{N}$&lt;/span&gt; (solid angles).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By importance sampling &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;I \approx \frac{1}{N} \sum_{j=1}^{N} \frac{L(\omega_i^{j})}{pdf(\omega_i^{j})} \;\;\;\; (1)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If what I wrote is correct than I don't know where the dot product and the normalization factor&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;W = \sum_{j=1}^{N} N\cdot L^{j}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;comes from, namely how do I go from &lt;span class=&quot;math-container&quot;&gt;$(1)$&lt;/span&gt; to&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;I \approx &#xA;\frac{\sum_{j=1}^{N}L(\omega_i^{j}) N \cdot L^{j}}&#xA;{\sum_{j=1}^{N} N \cdot L^{j}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: I'm pretty sure many of you know this already, but the shader above is for a pre-filtered environment map. Which means in this context the actual integral should be given by&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;I(N) = \int_{\Omega} L(\omega_i) N \cdot L d\omega&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This explains the factor &lt;span class=&quot;math-container&quot;&gt;$N \cdot L$&lt;/span&gt; in the shader, the distribution function used is the GGX distribution, I assume plugging this stuff together might give me the formula.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Just updating because it might give a better clue.&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="228" LastEditDate="2019-05-27T15:22:01.327" LastActivityDate="2019-05-27T15:22:01.327" Title="Pre-filtered environment map, deriving the equation" Tags="&lt;algorithm&gt;&lt;lighting&gt;&lt;mathematics&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="12" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8848" PostTypeId="1" CreationDate="2019-05-16T16:01:19.563" Score="2" ViewCount="364" Body="&lt;p&gt;I have a group of low polygon meshes, with associated normal maps. The normal maps were created by baking from high polygon meshes, which I no longer have access to. Is it possible to recreate anything approximating the original high polygon meshes from my inputs? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wouldn't expect the output to have the same kind of mesh structure, but want any kind of mesh that would have the same shape / volume as the original high polygon meshes. I would prefer the output to be a mesh, but it could also work if I could get a point cloud or set of voxels that recreated the volume of the original high polygon mesh. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further clarification: the low poly mesh was created manually from the high poly mesh by retopologising and deleting polygons. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also attached a screenshot showing what I mean (as well as the original mesh file in .obj format). It shows a close-up of two meshes of the handle of a sword. The left one is a high poly one (you can see the ridges in the handle), while the one on the right is the low poly version (it is flat instead of having ridges, because the ridges are captured by the normal map). In my use case, I have the low poly mesh (like the one on the right) and a normal map, and want to get the high poly version (like the one on the left). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://imgur.com/a/WADsMw4&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sword handles image file&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://drive.google.com/open?id=1MKwP8jGjLTU_4r-MoDWeRB6W99cO3JVe&quot; rel=&quot;nofollow noreferrer&quot;&gt;Swords mesh file&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7622" LastEditorUserId="7622" LastEditDate="2019-06-06T16:51:37.500" LastActivityDate="2019-06-06T16:51:37.500" Title="Recreate geometry from normal map" Tags="&lt;mesh&gt;&lt;normal-mapping&gt;" AnswerCount="0" CommentCount="10" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8852" PostTypeId="2" ParentId="5086" CreationDate="2019-05-20T12:46:58.460" Score="0" Body="&lt;p&gt;This can be achieved without trigonometric functions by scaling down the &lt;a href=&quot;http://mathworld.wolfram.com/Incircle.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;incircle&lt;/a&gt; of the triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;incircle()&lt;/code&gt; computes the incircle of the triangle formed by the vertices &lt;code&gt;A,B,C&lt;/code&gt;, it returns center and radius as &lt;code&gt;vec4&lt;/code&gt;. The vertices &lt;code&gt;X=A,B,C&lt;/code&gt; are then moved inwards by the fraction of their distance to the incircle center (&lt;code&gt;Q-X&lt;/code&gt;) which is equal to the ratio of desired margin to incircle radius (&lt;code&gt;m/Q.w&lt;/code&gt;).&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;vec4 incircle(vec3 A, vec3 B, vec3 C) {&#xA;    float a = length(B - C), b = length(C - A), c = length(A - B);&#xA;    float abc = a + b + c;&#xA;    // http://mathworld.wolfram.com/Incenter.html&#xA;    vec3 I = (a * A + b * B + c * C) / abc;&#xA;    // http://mathworld.wolfram.com/Inradius.html&#xA;    float r = 0.5&#xA;            * sqrt((-a + b + c) * (a - b + c) * (a + b - c) / abc);&#xA;    return vec4(I, r);&#xA;}&#xA;&#xA;vec3 A,B,C; // vertices&#xA;float m; // margin&#xA;vec4 Q = incircle(A,B,C);&#xA;A += clamp(m / Q.w, 0.0, 1.0) * (Q.xyz - A);&#xA;B += clamp(m / Q.w, 0.0, 1.0) * (Q.xyz - B);&#xA;C += clamp(m / Q.w, 0.0, 1.0) * (Q.xyz - C);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10670" LastActivityDate="2019-05-20T12:46:58.460" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8854" PostTypeId="1" CreationDate="2019-05-21T09:54:14.010" Score="1" ViewCount="145" Body="&lt;p&gt;I spent quite some time looking for books on rasterization of vector graphics and related challenges. The best I found is &quot;Raster Tragedy in Low Resolution&quot;,which is old and focused on fonts. There are assorted papers on new renderer here and there, but nothing comprehensive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is ththere something good I missed? &lt;/p&gt;&#xA;" OwnerUserId="10674" LastEditorUserId="10674" LastEditDate="2019-05-21T10:39:48.427" LastActivityDate="2019-06-30T06:50:00.183" Title="Any good sources on advaced/special rasterization algorithms and techniques and theory behind them?" Tags="&lt;vector-graphics&gt;&lt;rasterizer&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8855" PostTypeId="1" AcceptedAnswerId="8856" CreationDate="2019-05-23T00:53:49.707" Score="0" ViewCount="103" Body="&lt;p&gt;For a Lambertian surface, the radiance at a point is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = \frac{\alpha}{\pi}\cos\theta_i E_0$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we have an infinite flat surface, albedo = 1, illuminated directly normal, then we get &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = \frac{E_0}{\pi}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But now suppose we are sitting very close to the surface. The surface occupies &lt;span class=&quot;math-container&quot;&gt;$2\pi$&lt;/span&gt; sr of our view, so the irradiance we measure is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$E_r = 2\pi L = 2E_0$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this correct? I was expecting to get &lt;span class=&quot;math-container&quot;&gt;$E_0$&lt;/span&gt; back again. &lt;span class=&quot;math-container&quot;&gt;$2E_0$&lt;/span&gt; makes it feel like we're violating the conservation of energy or something.&lt;/p&gt;&#xA;" OwnerUserId="10685" LastActivityDate="2019-05-23T01:57:06.720" Title="Factor of 2 converting radiance to irradiance" Tags="&lt;global-illumination&gt;&lt;reflection&gt;&lt;diffuse&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8856" PostTypeId="2" ParentId="8855" CreationDate="2019-05-23T01:57:06.720" Score="1" Body="&lt;p&gt;I don't really understand what are you doing. I think your first equation shouldn't have a cos factor in it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have the relation,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$BRDF = dL_r / dE_i$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is the brdf is the ratio of reflected radiance to incoming &quot;irradiance&quot;. Re-arranging this gives us,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ dL_r =  BRDF * dE_i$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For diffuse surfaces we know,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$BRDF = \alpha/\pi$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Substituting in above equation we have,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$dL_r = \alpha/\pi * dE_i$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Irrespective of what angle we view, the radiance is the same. Now for a diffuse surface with albedo = 1 we have what you said,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$dL_r = dE_i/\pi$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now in order to measure Irradiance, we can use the relation,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$E = \int_{2\pi} L \cos(\theta) d\omega$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$E = \displaystyle\int_{\phi = 0}^{2\pi} \displaystyle\int_{\theta = 0}^{\pi/2} L \cos(\theta) \sin(\theta) d\theta d\phi$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$E = E/\pi * \pi$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$E = E$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you got back the same irradiance.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-05-23T01:57:06.720" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8857" PostTypeId="1" CreationDate="2019-05-25T20:58:56.210" Score="2" ViewCount="94" Body="&lt;p&gt;I am using the Bresenham algorithm from wikipedia:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; plotLine(x0,y0, x1,y1)&#xA;      dx = x1 - x0&#xA;      dy = y1 - y0&#xA;      D = 2*dy - dx&#xA;      y = y0&#xA;&#xA;     for x from x0 to x1&#xA;        plot(x,y)&#xA;        if D &amp;gt; 0&#xA;           y = y + 1&#xA;           D = D - 2*dx&#xA;        end if&#xA;        D = D + 2*dy&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have the following two points:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;P1 = (10, 120) and P2 = (18, 117)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I wrote a C program to run the algorithm and I got as output:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ePlot the following points: &#xA;10, 120&#xA;11, 120&#xA;12, 120&#xA;13, 120&#xA;14, 120&#xA;15, 120&#xA;16, 120&#xA;17, 120&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which is totally wrong, is there any other version of this algorithm which works for this scenario or it does not exist?&lt;/p&gt;&#xA;" OwnerUserId="10698" LastActivityDate="2019-05-29T11:23:19.093" Title="Why the Bresenham's algorithm does not work for those two points?" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;offline&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8858" PostTypeId="1" CreationDate="2019-05-27T13:23:42.247" Score="1" ViewCount="204" Body="&lt;p&gt;I &lt;a href=&quot;https://stackoverflow.com/a/5814107/1305036&quot;&gt;found out&lt;/a&gt; that I should use spherical linear interpolation to blend two poses of a joint. I cannot find what to do if I have hundreds of poses to blend except applying the SLERP iteratively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the default methods to interpolate between multiple skeletal poses? For example, which algorithms are used by Unity3D, UE4, 3DS Max, Maya, etc? How do they solve the problem of rotation non-commutativity?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm looking for an analytical well-differentiable (with respect to blending weights) formula if one exists.&lt;/p&gt;&#xA;" OwnerUserId="2750" LastActivityDate="2019-05-30T00:00:07.483" Title="How to calculate interpolation between multiple skeleton poses?" Tags="&lt;transformations&gt;&lt;mathematics&gt;&lt;interpolation&gt;&lt;blending&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8859" PostTypeId="1" CreationDate="2019-05-27T14:01:05.097" Score="2" ViewCount="216" Body="&lt;p&gt;I'm studying Microsoft Windows Bitmap File Format, extension BMP.&lt;br&gt;&#xA;I'm curious to know why scanlines are stored on file from bottom to up: the last scanline on image is the first line on file and the first scanline on image is the last line on file.&lt;br&gt;&#xA;The documents that I have read do not explain it.&lt;/p&gt;&#xA;" OwnerUserId="9083" LastEditorUserId="6" LastEditDate="2020-04-09T15:17:28.017" LastActivityDate="2020-04-09T15:17:28.017" Title="Why BMP file format last line of image is first line on file?" Tags="&lt;image&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8860" PostTypeId="2" ParentId="8854" CreationDate="2019-05-28T02:11:38.067" Score="1" Body="&lt;p&gt;One rasterization method I like is Haar wavelet rasterization:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://faculty.cs.tamu.edu/schaefer/research/wavelet_rasterization.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://faculty.cs.tamu.edu/schaefer/research/wavelet_rasterization.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It can render polygons and Bezier curve shape and good for different resolution. I not see this algorithm in computer graphics books.&lt;/p&gt;&#xA;" OwnerUserId="10707" LastActivityDate="2019-05-28T02:11:38.067" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8861" PostTypeId="2" ParentId="8859" CreationDate="2019-05-28T02:32:01.300" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Here's a quote from Petzold:&lt;/p&gt;&#xA;  &#xA;  &lt;blockquote&gt;&#xA;    &lt;p&gt;So, in DIBs, the bottom row of the image is the first row of the file,&#xA;    and the top row of the image is the last row in the file. This is&#xA;    called a bottom-up organization. Because this organization is&#xA;    counterintuitive, you may ask why it's done this way.&lt;/p&gt;&#xA;    &#xA;    &lt;p&gt;Well, it all goes back to the OS/2 Presentation Manager. Someone at&#xA;    IBM decided that all coordinate systems in PM—including those for&#xA;    windows, graphics, and bitmaps—should be consistent. This provoked a&#xA;    debate: Most people, including programmers who have worked with&#xA;    full-screen text programming or windowing environments, think in terms&#xA;    of vertical coordinates that increase going down the screen. However,&#xA;    hardcore computer graphics programmers approach the video display from&#xA;    a perspective that originates in the mathematics of analytic geometry.&#xA;    This involves a rectangular (or Cartesian) coordinate system where&#xA;    increasing vertical coordinates go up in space.&lt;/p&gt;&#xA;    &#xA;    &lt;p&gt;In short, the mathematicians won. Everything in PM was saddled with a&#xA;    bottom-left origin, including window coordinates. And that's how DIBs&#xA;    came to be this way.&lt;/p&gt;&#xA;  &lt;/blockquote&gt;&#xA;  &#xA;  &lt;p&gt;&lt;strong&gt;Source:&lt;/strong&gt; Charles Petzold, &lt;em&gt;Programming for Windows 5th Edition&lt;/em&gt;, Chapter&#xA;  15.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;from&#xA;&lt;a href=&quot;https://stackoverflow.com/questions/8346115/why-are-bmps-stored-upside-down&quot;&gt;https://stackoverflow.com/questions/8346115/why-are-bmps-stored-upside-down&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10708" LastEditorUserId="6" LastEditDate="2019-05-28T09:44:03.240" LastActivityDate="2019-05-28T09:44:03.240" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8863" PostTypeId="1" CreationDate="2019-05-28T10:16:43.690" Score="2" ViewCount="69" Body="&lt;p&gt;I did not know where to ask, I will try it here. I work in a local planetarium and I wonder if it is possible to edit an image in such way, that when projected on spherical cupola (diameter 8 m), it would not look too much distorted. Is there any easy way to edit an image this way?&lt;/p&gt;&#xA;" OwnerUserId="10710" LastActivityDate="2019-05-28T10:16:43.690" Title="How to project an image on spherical surface with least possible distortion" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8865" PostTypeId="1" AcceptedAnswerId="8866" CreationDate="2019-05-28T21:50:30.633" Score="0" ViewCount="67" Body="&lt;p&gt;Let's say I had a binary image (i.e. only contains black and white pixels). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, this one:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Zbw7g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Zbw7g.png&quot; alt=&quot;face&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How would I make all the lines in this image dotted or dashed?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In other words, the eyes would be left alone, but everything else (including the circle on the nose) would become dotted or dashed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that, for example, kernels can be used to blur, sharpen, etc - but I don't know if a kernel could do this. &lt;/p&gt;&#xA;" OwnerUserId="10712" LastActivityDate="2019-05-29T09:35:39.567" Title="How to make the lines of a (binary) image dotted or dashed?" Tags="&lt;image-processing&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8866" PostTypeId="2" ParentId="8865" CreationDate="2019-05-29T09:35:39.567" Score="0" Body="&lt;p&gt;A kernel can (probably) not help you, because they are very localized. However, you need to know, where a line is, and that may be out of the reach of a kernel (e.g. a 3x3 Pixel kernel would only be able to detect a line 3 pixels wide. Is that meeting your demands of being a line?)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rather you need to define, when a line is a line with the information you have. For simplicity you could say &quot;Having at least 5 pixels in either X or Y direction black next to each other, but not having any pixels black in any other direction makes a line&quot;. Then you can scan the image for those lines and store them in some data structure. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that you have your lines figured out, you need to define what to do with them, e.g. &quot;Every line longer than 20 pixels needs to be dashed, every other line dotted&quot;. &#xA;Also &quot;A dashed line has a white pixel at every third and fourth pixel, except the first and last pixel may not be white&quot; and &quot;A dotted line has a white pixel at every other pixel, except the first and last pixel may not be white&quot;. Since you know the lines, you either know or can check the lines, and therefore you can edit them one by one to be dotted or dashed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is of course a pretty high level description, but you don't give much to go on with your question. Perhaps though, this suffices for you to get started.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The hard part of course is to identify lines. Try to think what makes a line for you (e.g. direction, thickness/width vs height), what edge cases you may have (a single pixel or square block of pixels) and then you can go about finding them in your image. Note that in a rasterized image, non horizontal and non vertical lines will have &quot;strange&quot; patterns of how they fill the image and you will have to decide how to treat those on your own. &#xA;Also, make sure to not have any lines stored twice (or more) when scanning, because your dotting / dashing process could possibly lead to an unwanted outcome.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2019-05-29T09:35:39.567" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8867" PostTypeId="2" ParentId="8858" CreationDate="2019-05-29T10:01:13.723" Score="0" Body="&lt;p&gt;The simplest way is to use n-way nlerp (normalized lerp) instead. It does mean slight inaccuracies in the blend but careful (manual) tweaking of the weights and good key pose selection can take care of that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;nlerp&lt;/code&gt; will approximate &lt;code&gt;slerp&lt;/code&gt; when the key poses are close to each other. So you will very likely get away with not tweaking the weights at all in most cases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also keep in mind that not all bones need to be blended the same way. &lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2019-05-29T11:59:25.727" LastActivityDate="2019-05-29T11:59:25.727" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8868" PostTypeId="2" ParentId="8857" CreationDate="2019-05-29T11:23:19.093" Score="2" Body="&lt;p&gt;Like Rahul said that algorithm is only in the case where &lt;span class=&quot;math-container&quot;&gt;$0 \lt \Delta y \lt \Delta x$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you need to adjust the coordinates to fit within that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are 8 cases:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$0 \lt \Delta y \lt \Delta x$&lt;/span&gt; the normal base case&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$0 \lt \Delta x \lt \Delta y$&lt;/span&gt; swap x and y except for the drawPixel call.&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\Delta x \lt 0 \lt \Delta y$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$|\Delta y &amp;lt; \Delta x|$&lt;/span&gt; use case 1 but negate &lt;span class=&quot;math-container&quot;&gt;$\Delta x$&lt;/span&gt; and instead of counting from x0 to x1 you count from x1 to x0&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\Delta x \lt 0 \lt \Delta y$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$|\Delta x \lt \Delta y|$&lt;/span&gt; use case 2 but negate &lt;span class=&quot;math-container&quot;&gt;$\Delta x$&lt;/span&gt; and instead of counting from x0 to x1 you count from x1 to x0&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The remaining cases have &lt;span class=&quot;math-container&quot;&gt;$\Delta y \lt 0$&lt;/span&gt; so swap the 2 points and it will fall within the previous 4 cases.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-05-29T11:23:19.093" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8869" PostTypeId="2" ParentId="8858" CreationDate="2019-05-29T17:24:02.990" Score="1" Body="&lt;p&gt;I will suggest something for the rotational part but I do not know how fast it is. Assume you have a 3D coordinate system centered at the pivoting point of the joint and fixed with respect to one of the bars that meet at the joint. The other bar moves in this coordinate system always attached the origin of the system. So its motion is a curve on a sphere centered at the joint's pivoting point and radius the bar's length &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt;. Assume you have a sequence of positions &lt;span class=&quot;math-container&quot;&gt;$\vec{x}_0, \, \vec{x}_1, \, \vec{x}_2, \, ..., \vec{x}_m$&lt;/span&gt; of the moving bar with respect to this system. Recall the bar has length &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt;. Then calculate the cross products: &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{n}_j = \vec{x}_0 \times \vec{x}_j$$&lt;/span&gt; and the cosine of the angle &lt;span class=&quot;math-container&quot;&gt;$$c_j = \cos(\theta_{j}) =  \frac{1}{l^2} \, (\vec{x}_0 \cdot \vec{x}_j) $$&lt;/span&gt; as well as the magnitude &lt;span class=&quot;math-container&quot;&gt;$\|\vec{n}_j\| = \sqrt{ (\vec{n}_{j} \cdot \vec{n}_j) }$&lt;/span&gt;. Normalize &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{N}_j = \frac{\vec{n}_j}{\|\vec{n}_j\|}$$&lt;/span&gt;&lt;br&gt;&#xA;So now you have the list of pairs &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\big(\vec{N}_1, \, c_1\big), \, \big(\vec{N}_2, \, c_2\big), \, ... ,\, \big(\vec{N}_m, \, c_m\big)$$&lt;/span&gt;&#xA;Apply a cubic or some other appropriate spline interpolation to the list of data. The result is the pair of smooth families&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{N}(t), \, c(t)$$&lt;/span&gt;&#xA;Use  &lt;a href=&quot;https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rodrigues' rotation formula&lt;/a&gt; to obtain the smooth family of rotation matrices&#xA;&lt;span class=&quot;math-container&quot;&gt;$$U(t) = \text{Id} \, \pm \, \Big(\,\sqrt{1 - c(t)^2}\, \Big)\, \hat{N}(t) \, + \, \big(1 - c(t)\big)\, \hat{N}(t)^2$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\hat{N}(t) = \big( \vec{N}(t) \times \cdot \big) $&lt;/span&gt; is the three by three skew symmetric matrix that acts on a vector &lt;span class=&quot;math-container&quot;&gt;$\vec{x}$&lt;/span&gt; by&#xA;&lt;span class=&quot;math-container&quot;&gt;$\hat{N}(t)\, \vec{x} = \vec{N}(t) \times \vec{x}$&lt;/span&gt;. Notice the presence of the &lt;span class=&quot;math-container&quot;&gt;$\pm$&lt;/span&gt; sign, which is negative when the angle between the vectors &lt;span class=&quot;math-container&quot;&gt;$\vec{x}_0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{x}_j$&lt;/span&gt; starts to exceed &lt;span class=&quot;math-container&quot;&gt;$180^{\circ}$&lt;/span&gt;. This really depends on the range of motion of the joint. Anyway, then the joint moves smoothly by &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{x}(t) = U(t)\, \vec{x}_0$$&lt;/span&gt; and at each moment of time &lt;span class=&quot;math-container&quot;&gt;$t_j$&lt;/span&gt; for which&#xA;&lt;span class=&quot;math-container&quot;&gt;$c(t_j) = c_j$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{N}(t_j) = \vec{N}_j$&lt;/span&gt; due to the interpolation scheme we get&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{x}_j = U(t_j)\, \vec{x}_0$$&lt;/span&gt;&#xA;All of this can be done with quaternions, the idea is analogous. It is up to you.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The case of framed joint:&lt;/strong&gt; If you have one coordinate system attached firmly to the first bar of the joint and a second coordinate system attached firmly to the second bar of the joint (both have origin at the pivoting point of the joint, i.e. I am ignoring translations), then the position of the second bar with respect to the coordinate system of the first one is described by the position of the second coordinate system with respect to the first. Then, if &lt;span class=&quot;math-container&quot;&gt;$\vec{u}_1, \, \vec{u}_2, \vec{u}_3$&lt;/span&gt; are the unit orthogonal column-vectors of the second coordinate system written with respect to the first coordinate system, the orthogonal matrix that maps the first system to the second is &lt;span class=&quot;math-container&quot;&gt;$U = [\vec{u}_1 \,\, \vec{u}_2 \,\, \vec{u}_3]^T$&lt;/span&gt; (the vectors are 3 x 1 columns of coordinates of the basis vectors of the second coordinate system with respect to the first coordinate system). Consequently, in this case (of framed joint motion) you may actually have a sequence of orthogonal matrices, describing the positions of the second system relative to the first at different times:&#xA;&lt;span class=&quot;math-container&quot;&gt;$U_1, \, U_2, \, ..., \, U_m$&lt;/span&gt;. In this case, calculate the skew symmetric matrices &lt;span class=&quot;math-container&quot;&gt;$$\hat{n}_j = \frac{1}{2} \big( U_j - U_j^T \big)$$&lt;/span&gt; and calculate the traces&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\|\hat{n}_j\| = \sqrt{ - \frac{1}{2} \, \text{trace}\big(\hat{n}_j^2\big) }$$&lt;/span&gt; Then &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{N}_j = \left(\frac{1}{\|\hat{n}_j\|}\right) \, \hat{n}_j$$&lt;/span&gt; is a skew symmetric matrix with the property that there exists a unique unit vector &lt;span class=&quot;math-container&quot;&gt;$\vec{N}_j$&lt;/span&gt; such that for any vector &lt;span class=&quot;math-container&quot;&gt;$\vec{x}$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{N}_j \, \vec{x} = \vec{N}_j \times \vec{x}$$&lt;/span&gt;&#xA;and &#xA;&lt;span class=&quot;math-container&quot;&gt;$$c_j = \cos(\theta_j) = \frac{\text{trace}(U_j) - 1}{2}$$&lt;/span&gt;&#xA;As before, you have the list of pairs &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\big(\vec{N}_1, \, c_1\big), \, \big(\vec{N}_2, \, c_2\big), \, ... ,\, \big(\vec{N}_m, \, c_m\big)$$&lt;/span&gt; or equvialently the list of pairs (whichever works better for you, although they are equivalent)&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\big(\hat{N}_1, \, c_1\big), \, \big(\hat{N}_2, \, c_2\big), \, ... ,\, \big(\hat{N}_m, \, c_m\big)$$&lt;/span&gt;&#xA;Apply again a cubic or some other spline interpolation to either of the lists of data. The result is the pair of smooth families&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\hat{N}(t), \, c(t)$$&lt;/span&gt;&#xA;Just as before,  &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;by the properties of rotational matrices&lt;/a&gt;, you obtain the smooth family of rotation matrices&#xA;&lt;span class=&quot;math-container&quot;&gt;$$U(t) = \text{Id} \, \pm \, \Big(\,\sqrt{1 - c(t)^2}\, \Big)\, \hat{N}(t) \, + \, \big(1 - c(t)\big)\, \hat{N}(t)^2$$&lt;/span&gt; This &lt;span class=&quot;math-container&quot;&gt;$U(t_j) = U_j$&lt;/span&gt; for all &lt;span class=&quot;math-container&quot;&gt;$j = 1, .., m$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8851" LastEditorUserId="8851" LastEditDate="2019-05-30T00:00:07.483" LastActivityDate="2019-05-30T00:00:07.483" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8870" PostTypeId="1" AcceptedAnswerId="8871" CreationDate="2019-05-29T23:04:09.300" Score="3" ViewCount="1039" Body="&lt;p&gt;I would like to change/add/remove some mesh vertices in existing VBO's (while deforming and remeshing 3D objects) . With OpenGL I would have to reload whole vertex VBO's. I suppose with Vulkan there could be a way to directly access VBO's to only change/add/remove the changed vertex data. Is there some sample code out there demonstrating how this can be achieved? &#xA;Many thanks for any help. &lt;/p&gt;&#xA;" OwnerUserId="8314" LastActivityDate="2019-10-27T06:01:30.347" Title="Vulkan: efficient way to update VBO mesh vertices?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;vulkan&gt;&lt;vertex-buffer-object&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8871" PostTypeId="2" ParentId="8870" CreationDate="2019-05-30T01:55:58.180" Score="5" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;With OpenGL I would have to reload whole vertex VBO's.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No you wouldn't.  You can use &lt;code&gt;glBufferSubData&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I suppose with Vulkan there could be a way to directly access VBO's to only change/add/remove the changed vertex data&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If you know the memory layout of the vertex buffer, you can find the offset of the contents you want to change, populate a transfer buffer with the new data and then uss &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/vkCmdCopyBuffer.html&quot; rel=&quot;noreferrer&quot;&gt;vkCmdCopyBuffer&lt;/a&gt; to copy the data.  The &lt;code&gt;VkBufferCopy&lt;/code&gt; parameter lets you specify the size as well as the source and destination offsets.  In other words, every call to &lt;code&gt;vkCmdCopyBuffer&lt;/code&gt; is basically the equivalent of N calls to &lt;code&gt;glBufferSubData&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify, updating a vertex buffer on Vulkan is almost the same as populating it.  If you're on a desktop architecture where &lt;em&gt;device local&lt;/em&gt; memory is typically not mappable, then you have to create a transfer buffer that is &lt;em&gt;host visible&lt;/em&gt;.  You can populate that buffer with a memcpy (or whatever), and then use &lt;code&gt;vkCmdCopyBuffer&lt;/code&gt; to transfer it to the &lt;em&gt;device local&lt;/em&gt; memory backed buffer.  If you're on a mobile architecture with unified memory, then &lt;em&gt;device local&lt;/em&gt; memory is typically also &lt;em&gt;host visible&lt;/em&gt; and so you can just map it directly and update it with your &lt;code&gt;memcpy&lt;/code&gt; (or whatever)&lt;/p&gt;&#xA;" OwnerUserId="9306" LastEditorUserId="9306" LastEditDate="2019-05-30T04:05:46.257" LastActivityDate="2019-05-30T04:05:46.257" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8872" PostTypeId="2" ParentId="5846" CreationDate="2019-05-30T04:34:39.833" Score="1" Body="&lt;p&gt;Perlin noise not good for real planet surface because planet surface is not random. Planet structure is create by geology/physics and interaction between different parts.&lt;br/&gt;&#xA;&lt;br/&gt;&#xA;This video show geology simulator have name PlaTec (have link in text below video):&lt;br/&gt;&#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=bi4b45tMEPE&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=bi4b45tMEPE&lt;/a&gt;&lt;br/&gt;&#xA;&lt;br/&gt;&#xA;Link have source code at SourceForge web site too.&lt;/p&gt;&#xA;" OwnerUserId="10707" LastActivityDate="2019-05-30T04:34:39.833" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8873" PostTypeId="1" CreationDate="2019-05-30T20:20:16.183" Score="3" ViewCount="813" Body="&lt;p&gt;I've been scanning the specifications for both OpenGL and GLSL, and I can't find a definitive answer as to &lt;em&gt;how exactly&lt;/em&gt; are &lt;code&gt;gl_FragCoord&lt;/code&gt;'s &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; components computed, other than they are the &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;fragment’s window-space position&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;(&lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL 4.6 specification&lt;/a&gt;, page 491)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which does not help me understand why &lt;code&gt;glViewport()&lt;/code&gt; doesn't seem to affect the values of &lt;code&gt;gl_FragCoord&lt;/code&gt; in the fragment stage, since that is the case for window-space coordinates in the vertex stage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The actual problem I'm trying to solve is rendering a bunch of draws (that depend on &lt;code&gt;gl_FragCoord&lt;/code&gt; for their shading) to an atlas, without modifying the shaders of the draws to be aware of the atlas. Here's pseudocode for the driving part (all viewports have identical dimensions, just different offsets):&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;    for (size_t i = 0; i &amp;lt; FrameCount; ++i)&#xA;    {&#xA;        auto&amp;amp; Vp = Viewports[i];&#xA;        glViewport(Vp.X, Vp.Y, Vp.X + Vp.Width, Vp.Y + Vp.Height);&#xA;        BindConstants(Vp.Width, Vp.Height);&#xA;        glDrawArrays(GL_TRIANGLES, 0, Triangles);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;BindConstants()&lt;/code&gt; simply binds a uniform with the viewport's width &amp;amp; height. When trying to simply output the UVs with the following shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330&#xA;uniform vec2 Resolution;&#xA;&#xA;void main(void)&#xA;{&#xA;    vec2 UV = gl_FragCoord.xy / Resolution;&#xA;    gl_FragColor = vec4(UV, 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I get the following image, which clearly shows that colour is being clipped to 1.0 beyond the first viewport in a 5x5 atlas:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GIh9o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GIh9o.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've also done additional simple tests that show that &lt;code&gt;gl_FragCoord&lt;/code&gt; is based off of the entire frame buffer's origin, rather than what's specified via &lt;code&gt;glViewport()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have worked around this issue by rendering to a temporary FBO and blitting to the target frame buffer at the desired offset, but it's silly to go to such lengths for a dead-simple use-case like this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I missing something? Is it possible at all without a temporary FBO, and, above all, &lt;strong&gt;without modifying the shaders?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="2817" LastActivityDate="2020-11-23T16:37:02.947" Title="gl_FragCoord and glViewport" Tags="&lt;opengl&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8874" PostTypeId="1" CreationDate="2019-05-30T20:25:32.230" Score="0" ViewCount="168" Body="&lt;p&gt;I wrote the code for checking intersection of ray and meshes on scene. It consist of two parts - broad phase and narrow phase.&#xA;In broad phase I build an oriented bounding box around each mesh and check intersection of ray with boxes.&#xA;In narrow phase I check intersection of ray and each triangle of the meshes from broad phase using Möller-Trumbore algorithm. In general it works well.&#xA;Now my task is to optimize broad phase using Octree. Octree as data structure is well-described and trivial enough. However, I have no idea how to apply it for raytracing and I can't find nothing about it. Could you please give me a hint? &lt;/p&gt;&#xA;" OwnerUserId="10716" LastActivityDate="2019-05-30T20:25:32.230" Title="Using octree for cheking intersection of ray and meshes" Tags="&lt;raytracing&gt;&lt;3d&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8875" PostTypeId="2" ParentId="8873" CreationDate="2019-05-31T05:33:52.360" Score="3" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;since that is the case for window-space coordinates in the vertex stage.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;There are no &amp;quot;window-space coordinates in the vertex stage&amp;quot;. Or at least, not in the vertex &lt;em&gt;shader&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Window-space is not relative to the viewport; it's relative to the &lt;em&gt;window&lt;/em&gt; (or framebuffer, in this case). The viewport transform is used to convert from NDC-coordinates (which are relative to the viewport) to window coordinates (which are not).&lt;/p&gt;&#xA;&lt;p&gt;If you need your fragment shader to have viewport-relative coordinates, then you need to either compute them in the fragment shader (by providing the viewport as a &lt;code&gt;uniform&lt;/code&gt;) or pass NDC coordinates from the vertex shader as an &lt;code&gt;in&lt;/code&gt;/&lt;code&gt;out&lt;/code&gt; variable pair (just compute &lt;code&gt;gl_Position.xy/gl_Position.w&lt;/code&gt;).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-11-23T16:37:02.947" LastActivityDate="2020-11-23T16:37:02.947" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8876" PostTypeId="1" AcceptedAnswerId="8980" CreationDate="2019-05-31T08:47:17.083" Score="3" ViewCount="2520" Body="&lt;p&gt;I have a need to generate a series of GLB files. I have a base template for a GLTF file which I have to derive off of. The models thus generated will only have varying textures on them. The base mesh doesn't change at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What Im stuck with&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Im able to generate the GLB, GLTF files from blender when exporting 3D models. After feeding these two files to: &lt;a href=&quot;https://sbtron.github.io/makeglb/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://sbtron.github.io/makeglb/&lt;/a&gt; Im able to create a GLB file which loads and works fine, with all the textures included.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I am unable to generate the bin file programmatically. Ive tried searching google for &lt;code&gt;generate bin file from images&lt;/code&gt;, but the first few pages dont seem to have anything relating to this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;What Ive tried&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Went through this question, but the selected answer there isnt dealing with images:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2338/how-to-generate-binary-gltf-array-buffers&quot;&gt;How to generate binary gltf array buffers?&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I go about generating a BIN file from a series of images?&lt;/p&gt;&#xA;" OwnerUserId="10720" LastActivityDate="2019-07-08T07:02:35.267" Title="Programmatically generating bin files for GLTF models" Tags="&lt;3d&gt;&lt;3dtexture&gt;&lt;gltf&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8877" PostTypeId="1" AcceptedAnswerId="8879" CreationDate="2019-05-31T12:02:45.297" Score="1" ViewCount="293" Body="&lt;p&gt;I'm kind of stuck on this one. When following a conventional, high-level shading tutorial, you'll come across these images that are like ambient + diffuse + specular = result, but I can tell that it's not straight addition (otherwise the picture would seem overexposed).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KnXE6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KnXE6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's the &quot;formula&quot; for mixing two rgb colors?&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-06-01T14:38:22.987" Title="How are colors really mixed?" Tags="&lt;color&gt;&lt;shading&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8879" PostTypeId="2" ParentId="8877" CreationDate="2019-05-31T13:38:09.373" Score="4" Body="&lt;p&gt;With an old-style Phong shader (as in your example), they really are just added together. Each of those things is a &lt;em&gt;contribution&lt;/em&gt; to the overall amount of light, so they're just added together, the same way you add together the contribution from each light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your intuition is right that you often end up with overexposed specular highlights with this style of shading. In a modern, physically-based pipeline, it's common to instead use an &lt;em&gt;energy-conserving&lt;/em&gt; shader. The contributions of each layer (specular, clear-coat/lacquer, diffuse, subsurface) are still added together, but the amount of light in each layer reduces the &lt;em&gt;input&lt;/em&gt; amount of light for the next layer. That is, if the surface is giving a strong specular reflection, it's reflecting most of the light, so less light is available for the diffuse layer. In the same way, any light that's reflected by the diffuse layer reduces the amount of light available for subsurface scattering.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-05-31T13:38:09.373" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8881" PostTypeId="2" ParentId="8876" CreationDate="2019-05-31T14:23:54.663" Score="1" Body="&lt;p&gt;The &lt;code&gt;.bin&lt;/code&gt; file that goes with a &lt;code&gt;.gltf&lt;/code&gt; only includes mesh data (position, normal, uv, other vertex attributes as needed).  It does not normally include any images (unless you're using the base64 export &quot;glTF Embedded&quot;, but don't use that for this, use &quot;glTF Separate&quot; instead).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you look in the JSON text of the .gltf file, you'll see an &lt;code&gt;images&lt;/code&gt; array, where image files are called out by &lt;code&gt;uri&lt;/code&gt; (filename, if local, or relative URLs for the web).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's look at the &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/DamagedHelmet&quot; rel=&quot;nofollow noreferrer&quot;&gt;Damaged Helmet&lt;/a&gt; sample model for an example.  The JPG images are &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/blob/77f1a295e65c3a59c7131e6a15552c69817c9449/2.0/DamagedHelmet/glTF/DamagedHelmet.gltf#L92-L114&quot; rel=&quot;nofollow noreferrer&quot;&gt;called out in the &lt;code&gt;.gltf&lt;/code&gt; file&lt;/a&gt;, separately from the &lt;code&gt;.bin&lt;/code&gt; file.  The data from the &lt;code&gt;.bin&lt;/code&gt; file is used by &lt;code&gt;buffers&lt;/code&gt;, which in turn are used by &lt;code&gt;bufferViews&lt;/code&gt;, &lt;code&gt;accessors&lt;/code&gt;, and then mesh primitives.  It is exclusively vertex mesh data, no images.  This is a separate chain from how the JPGs are being used.  The JPGs are called out by &lt;code&gt;images&lt;/code&gt;, which are referenced by &lt;code&gt;textures&lt;/code&gt; which in turn are used by &lt;code&gt;materials&lt;/code&gt;, which are referenced by mesh primitives.  For a more graphical version of this explanation, take a look at the &lt;a href=&quot;https://github.com/KhronosGroup/glTF#overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;Overview Chart&lt;/a&gt; for glTF.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So when exporting from Blender, choose &lt;code&gt;glTF Separate&lt;/code&gt; from the combo box in the export options panel.  This will produce a &lt;code&gt;.gltf&lt;/code&gt; file, a &lt;code&gt;.bin&lt;/code&gt; file, and may copy several images (be sure to export to a different folder from your source files, so nothing gets overwritten).  To change the images, just update the &lt;code&gt;uri&lt;/code&gt; fields in the &lt;code&gt;images&lt;/code&gt; array inside of the &lt;code&gt;.gltf&lt;/code&gt; file, and keep the same &lt;code&gt;.bin&lt;/code&gt; file around (the one that came out of Blender).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That way, you can swap out images with other images, but keep the same mesh data.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastEditorUserId="1908" LastEditDate="2019-06-03T13:52:25.887" LastActivityDate="2019-06-03T13:52:25.887" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8882" PostTypeId="2" ParentId="8877" CreationDate="2019-05-31T20:53:26.313" Score="1" Body="&lt;p&gt;You are somewhat right: the rightmost image is not the sum of the three images to the left of it. It's easiest to see that the rightmost image doesn't even have the ambient contribution on the left-hand side of the central spheroid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've done an experiment with two modes of addition of the three images. In the resulting images below, on the LHS, with the label &quot;Addition&quot;, is my result, on the RHS is the rightmost image from the OP.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Simple, naive addition — as if the images were in linear RGB space (and retaining the result in this space). Here's the result:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/16AC8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/16AC8.png&quot; alt=&quot;simple addition comparison&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;sRGB addition, i.e. the addition where we consider the images being in sRGB space (the default assumption on the web when no color profile is present), and so undo the sRGB gamma before actually adding color values, and apply it back afterwards. This will give the following result:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tfGhF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tfGhF.png&quot; alt=&quot;sRGB addition comparison&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, you can see that both ways of adding colors result in a sharp border from the ambient lighting contribution — the leftmost image in the OP, while the rightmost supposed result doesn't have such a border on some sides.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not really sure how the rightmost &quot;Phong Reflection&quot; image was created. It may have been manipulated, e.g. some gamma adjustment or something like that. But in any case, in both ways of addition above the image didn't get overexposed as you supposed it would.&lt;/p&gt;&#xA;" OwnerUserId="4647" LastEditorUserId="4647" LastEditDate="2019-06-01T14:38:22.987" LastActivityDate="2019-06-01T14:38:22.987" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8883" PostTypeId="1" AcceptedAnswerId="8884" CreationDate="2019-06-01T09:49:42.820" Score="0" ViewCount="47" Body="&lt;p&gt;A simple question. I know that non-manifold meshes are problematic for physics simulations, boolean operations, and 3D printing. I was wondering if they can be problematic for a virtual reality environment as well.&lt;/p&gt;&#xA;" OwnerUserId="9978" LastActivityDate="2019-06-01T11:23:25.093" Title="Are non manifold meshes problematic for Virtual Reality?" Tags="&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8884" PostTypeId="2" ParentId="8883" CreationDate="2019-06-01T11:23:25.093" Score="0" Body="&lt;p&gt;No, VR is no different to flat graphics applications in this respect. If your VR experience has physics, CSG (Boolean geometry), or any of the things that would have problems with non-manifolds in a flat application, then it'll have the same problems. If your application wouldn't have problems with non-manifolds as a flat application, it won't have problems as a VR application.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only real difference is that it's harder to stop the camera being inside objects in VR, since it's attached to the user's head. In a flat application, you might override the camera position or adjust the camera controls to avoid the camera moving through objects in the first place. In VR, those techniques don't really apply, so you might want to have an inside-outside test, so that you can react if the user puts their head inside an object (e.g. by blanking the view completely and/or asking them to move). The inside-outside test would obviously have problems with non-manifolds. It's the same problem as in a flat application, but in a flat application you might not be doing the test at all.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-06-01T11:23:25.093" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8886" PostTypeId="1" CreationDate="2019-06-04T07:26:23.320" Score="0" ViewCount="137" Body="&lt;p&gt;I'm trying to understand and learn WebGL and computer graphics from the bottom  up, that is why I started to work on my own little library for that. I've spent a couple of days looking for a right answer but I can't make it work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have column major matrices and I'm just trying to render a basic rectangle but for some reason no matter what I do after multiplication by a perspective matrix the vertex's Z is always out of bounds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My perspective matrix calculation : &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static perspective(fov, aspect, near, far) {&#xA;    const r = fov * aspect;&#xA;    const l = -4;&#xA;    const t = r;&#xA;    const b = l;&#xA;    const matrix = new Matrix4();&#xA;    matrix.n11 = (2 * near) / (r - l);&#xA;    matrix.n12 = 0;&#xA;    matrix.n13 = (r+l)/(r-l);&#xA;    matrix.n14 = 0;&#xA;    matrix.n21 = 0;&#xA;    matrix.n22 = (2 * near) / (t - b);&#xA;    matrix.n23 = (t+b)/(t-b);&#xA;    matrix.n24 = 0;&#xA;    matrix.n31 = 0;&#xA;    matrix.n32 = 0;&#xA;    matrix.n33 = (near + far) / (near - far);&#xA;    matrix.n34 = (2 * near * far) / (near - far);&#xA;    matrix.n41 = 0;&#xA;    matrix.n42 = 0;&#xA;    matrix.n43 = -1;&#xA;    matrix.n44 = 0;&#xA;    return matrix;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; this.vertexShaderScript =&#xA;        '\r\n' +&#xA;        'precision highp float;\r\n' +&#xA;        'uniform mat4 u_model;\r\n' +&#xA;        'uniform mat4 u_view;\r\n' +&#xA;        'uniform mat4 u_projection;\r\n' +&#xA;        'attribute vec3 a_position;\r\n' +&#xA;        'attribute vec4 a_color;\r\n' +&#xA;        'varying vec4 v_color;\r\n' +&#xA;        'void main(void) {\r\n' +&#xA;        '    v_color = a_color;\r\n' +&#xA;        '    gl_Position = u_projection * u_view *  u_model * vec4(a_position, 1.0);\r\n' +&#xA;        '}\r\n';&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10460" LastEditorUserId="11503" LastEditDate="2019-11-25T12:11:27.643" LastActivityDate="2021-04-18T15:46:24.983" Title="WebGL Can't render anything, wrong projection?" Tags="&lt;webgl&gt;&lt;projections&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8888" PostTypeId="1" CreationDate="2019-06-06T09:29:11.300" Score="0" ViewCount="280" Body="&lt;p&gt;I'm working on a scene in Unity where I have textures loaded at runtime. As a result of that, the scene is being slowed down (even with co-routines), so I thought maybe I could move the texture loading task to a plugin and have it run as a parallel thread..&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to load a texture with OpenGL in a Unity native plugin, and return a pointer back to the scene for further use?&lt;/p&gt;&#xA;" OwnerUserId="7525" LastEditorUserId="7525" LastEditDate="2019-06-06T09:41:42.623" LastActivityDate="2021-02-27T16:07:10.720" Title="Unity: Pass texture pointer from OpenGL to Unity" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8891" PostTypeId="1" CreationDate="2019-06-07T16:00:54.567" Score="1" ViewCount="37" Body="&lt;p&gt;I want to randomly generate polyhedrons which need not be convex. What is the most efficient way for doing so?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can think of an algorithm for generating random convex polyhedrons, but am unable to figure out a way for generating non-convex ones. How to generate a general polyhedron?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Taking it a step further, generalising my question to an n dimension space, how to randomly generate bounded finite polytopes?&lt;/p&gt;&#xA;" OwnerUserId="10745" LastActivityDate="2019-06-07T16:00:54.567" Title="Algorithm for randomly generating polyhedrons?" Tags="&lt;computational-geometry&gt;&lt;mathematics&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8893" PostTypeId="2" ParentId="8888" CreationDate="2019-06-08T13:11:02.003" Score="0" Body="&lt;p&gt;I am not sure if doing this is right or wrong or actually needed in practice. However, I was curious once &amp;amp; wanted to learn about Unity Native plugins, so i decided to do exactly what you need. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, I wrote a native plugin, which loads image data using C++ &amp;amp; stb_image library, it then passes byte[] to Unity C# side where it gets applied on a quad. There are many things you need to consider if it's a cross platform app, I was able to run it on both PC &amp;amp; Android during the experiment. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let me know if this is what you want to achieve &amp;amp; I can pass on the code to you. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Best. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2019-06-08T13:11:02.003" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8895" PostTypeId="1" CreationDate="2019-06-10T23:47:31.100" Score="0" ViewCount="214" Body="&lt;p&gt;I am updating my scene graph in response to user input and the network. What is the best way to do this? The updating threads are separate. Some approaches I am thinking about:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;double buffer. There are 2 copies of the scene graph, one is used for rendering and the other for updates. The rendering graph is updated at the end of the render loop. This update can be expensive for a large graph,&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;synchronization objects, like mutices, probably unsuitable,&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;dumping updating functors into a FIFO queue while rendering, then executing the functors at the end of the rendering loop. Updating the queue may block.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Is there something better and which approach is best?&lt;/p&gt;&#xA;" OwnerUserId="10734" LastEditorUserId="10734" LastEditDate="2019-06-11T00:44:25.040" LastActivityDate="2019-06-11T15:56:25.933" Title="how to update my scene graph?" Tags="&lt;rendering&gt;&lt;multithreading&gt;&lt;synchronization&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8896" PostTypeId="2" ParentId="8886" CreationDate="2019-06-11T12:27:49.050" Score="0" Body="&lt;p&gt;Try This... I guess you got the matrix wrong.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;matrix.n11 = -(2 * near) / (r - l);&#xA;matrix.n12 = 0;&#xA;matrix.n13 = 0;&#xA;matrix.n14 = -near*(r+l)/(r-l);&#xA;matrix.n21 = 0;&#xA;matrix.n22 = (2 * near) / (t - b);&#xA;matrix.n23 = 0;&#xA;matrix.n24 = -near*(t+b)/(t-b);&#xA;matrix.n31 = 0;&#xA;matrix.n32 = 0;&#xA;matrix.n33 = (near + far) / (near - far);&#xA;matrix.n34 = (2 * near * far) / (near - far);&#xA;matrix.n41 = 0;&#xA;matrix.n42 = 0;&#xA;matrix.n43 = -1;&#xA;matrix.n44 = 0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I referred the following site after I googled =&gt;&lt;a href=&quot;http://learnwebgl.brown37.net/08_projections/projections_perspective.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Link&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10760" LastActivityDate="2019-06-11T12:27:49.050" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8897" PostTypeId="2" ParentId="8895" CreationDate="2019-06-11T15:56:25.933" Score="2" Body="&lt;p&gt;A few more options:&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;4&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;don't use a scenegraph. They don't map well to the data a gpu needs for rendering. A flat array of object tends to work much better for the cache as well&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;separate the scenegraph into render-related data and non-render-related data. Then only double buffer the render-related data. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The render related data would end up in a flat array containing per rendered object: reference to the mesh, the final model matrix, a reference to the texture&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Flat arrays are much easier to double buffer than node-based data structures.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-06-11T15:56:25.933" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8898" PostTypeId="1" AcceptedAnswerId="8903" CreationDate="2019-06-11T19:08:20.823" Score="1" ViewCount="233" Body="&lt;p&gt;I'm implementing a pbr ray tracer. Let's say that I'm at the end of the process:&#xA;for each pixel pi, I accumulated the radiance value in vector pi = (radR, radG, radB). At this point, these values are unbounded, so I use the Reinhard tone mapper to have values between 0 and 1. Then I can scale it in the device range, for instance [0, 255] for usual computer images. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my problem, the Reinhard tone mapping &lt;strong&gt;is not aware of the range of radiance in the whole scene&lt;/strong&gt;. I mean to compute the tone mapping I do: pi = pi / (1 + pi). &#xA;So if pi = (100, 100, 100), the tone mapped pi is (100/101, 100/101, 100/101), but if pi = (1000, 1000, 1000), the tone mapped pi is (1000/10001, 1000/1001, 1000/10001). So the &lt;strong&gt;final values will be really close&lt;/strong&gt; after tone mapping but &lt;strong&gt;one should be a lot greater than the other&lt;/strong&gt;, right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I doing something wrong, or missing something?&lt;/p&gt;&#xA;" OwnerUserId="10762" LastActivityDate="2019-06-12T14:05:45.290" Title="Tone Mapping in a physically based rendering ray tracer" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;lighting&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8899" PostTypeId="1" CreationDate="2019-06-11T22:40:36.200" Score="0" ViewCount="50" Body="&lt;p&gt;I've read some tutorials about Phong and Blinn lighting models and tried to implement a rendered myself.&#xA;To my knowledge, the basic approach consists of the following steps:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;calculate the vector from the current fragment to the light &lt;code&gt;rayToLight&lt;/code&gt; (and normalize it)&lt;/li&gt;&#xA;&lt;li&gt;calculate the diffuse color intensity using &lt;code&gt;diffuseIntensity = max(dot(rayToLight, normal))&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;calculate the vector from the current fragment and the camera &lt;code&gt;rayToCamera&lt;/code&gt; (and normalize it)&lt;/li&gt;&#xA;&lt;li&gt;reflect &lt;code&gt;rayToLight&lt;/code&gt;: &lt;code&gt;reflected = reflect(-rayToLight, normal)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;calculate the &lt;code&gt;specularIntensity = pow(max(dot(reflected, rayToCamera), 0.0), shininess)&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The problem is that &lt;code&gt;specularIntensity&lt;/code&gt; ( &lt;code&gt;dot(reflected, rayToCamera)&lt;/code&gt; to be precise), can be non-zero even if the light and the camera are on the opposite sides of a surface. Take the following example&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4lM81.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4lM81.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;It is possible that the angle between &lt;code&gt;reflected&lt;/code&gt; and &lt;code&gt;rayToCamera&lt;/code&gt; is less than 90 deg even if the camera and the light are on the opposite sides of a surface.&#xA;This means that despite the surface is not lit by the diffuse light, it can show specular reflections which is, of course, not wanted.&#xA;I wasn't aware of this problem until it occurred when I was trying to implement a simple phong lighting model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have I done something wrong or is it just the way it should work?&#xA;Thanks&lt;/p&gt;&#xA;" OwnerUserId="10759" LastActivityDate="2019-06-11T22:40:36.200" Title="Clarification about Phong lighting model" Tags="&lt;lighting&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8900" PostTypeId="1" AcceptedAnswerId="8906" CreationDate="2019-06-12T02:26:15.940" Score="6" ViewCount="1019" Body="&lt;p&gt;I am new to Vulkan. Compared to DX12, the resource binding procedure seems a little bit complicated. In terms of per draw call uniform buffers, I currently have two approaches in mind, and they both seem to work (haven't tested/benchmarked yet). Can someone shine some light on which is the standard way to do this, with pros and cons. You are welcome to provide other ways but I am not considering push constants because I want a universal approach that I can apply to other kinds of uniform buffers as well (i.e. per pass, per frame, per scene and etc.). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;approach A) One descriptor set and multiple buffers (one buffer for each object). Bind the descriptor set to pipeline only once before rendering. Bind buffers to the only descriptor set between draw calls using vkCmdPushDescriptorSetKHR. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;approach B) Multiple descriptor sets (one descriptor set for each object). (Multiple or single buffers, it doesn't really matter. If single buffer is used, I think it's called a dynamic uniform buffer and all that I need to do is to specify the offset when binding the descriptor set.) Bind buffer/buffers to descriptor sets only once before rendering. Bind the matching descriptor set to the pipeline between draw calls using vkCmdBindDescriptorSets. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am used to DX12 so approach A seems more natural because in my understanding vkCmdPushDescriptorSetKHR in Vulkan is just like SetGraphicsRootConstantBufferView in DX12, because they both bind buffer to pipeline and this operation is buffered with other commands. But the Vulkan one do feels a little bit slower mainly because 1) it is not a root descriptor, 2) Vulkan does not use GPU address and also 3) a descriptor set write operation is needed. &lt;/p&gt;&#xA;" OwnerUserId="9901" LastActivityDate="2019-06-13T02:53:03.897" Title="Is vkCmdPushDescriptorSetKHR efficient?" Tags="&lt;gpu&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8901" PostTypeId="2" ParentId="8730" CreationDate="2019-06-12T12:17:57.533" Score="0" Body="&lt;p&gt;Try these papers:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://doi.org/10.1145/130881.130882&quot; rel=&quot;nofollow noreferrer&quot;&gt;Octrees for faster isosurface generation&lt;/a&gt; by Wilhelms and Van Gelde (1992)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://doi.org/10.1109/2945.597798&quot; rel=&quot;nofollow noreferrer&quot;&gt;Speeding up isosurface extraction using interval trees&lt;/a&gt; by  Cignoni et al (1997)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://doi.org/10.1016/j.cag.2006.07.021&quot; rel=&quot;nofollow noreferrer&quot;&gt;A survey of the marching cubes algorithm&lt;/a&gt; by Newman and Yi (2006)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="192" LastEditorUserId="192" LastEditDate="2019-06-12T12:23:37.890" LastActivityDate="2019-06-12T12:23:37.890" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8903" PostTypeId="2" ParentId="8898" CreationDate="2019-06-12T14:05:45.290" Score="3" Body="&lt;p&gt;That's just how the Reinhard operator works. If the scene has very high dynamic range important detail may be lost near the high luminance region as you found since both will map near &lt;code&gt;0.99&lt;/code&gt;. Reinhard is a form of global operator. There are other types of algorithms using local operators which tonemap the pixel based on the intensity of the underlying neighborhood like a 3x3 or 5x5 region. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd recommend reading &lt;code&gt;HDR Imaging Acquisition, Display and Image Based Lighting&lt;/code&gt; by Erik Reinhard. It's a very good book and explains much of the concepts.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-06-12T14:05:45.290" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8904" PostTypeId="1" AcceptedAnswerId="8921" CreationDate="2019-06-12T20:27:28.650" Score="3" ViewCount="185" Body="&lt;p&gt;I'm currently looking into Mesh Simplification to batch-simplify a large amount of .obj files. It is necessary for these algorithms to preserve the visual representation of a mesh as well as possible.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;During research I've stumbled over Garland &amp;amp; Heckberts &lt;a href=&quot;https://www.cs.cmu.edu/~./garland/Papers/quadrics.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Surface Simplification Using Quadric Error Metrics&lt;/a&gt;. Most of the frameworks I've inspected are making use of this algorithm for Mesh Simplification.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is, why are most frameworks not making use of seemingly more advanced algorithms e.g. &lt;a href=&quot;https://mgarland.org/files/papers/quadric2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Simplifying Surfaces with Color and Texture using Quadric Error Metrics&lt;/a&gt; or comparable? Is the Quadric Error Metric currently state of the art concerning simplification algorithms?&lt;/p&gt;&#xA;" OwnerUserId="10765" LastEditorUserId="137" LastEditDate="2019-06-13T11:28:52.097" LastActivityDate="2019-06-19T16:52:31.163" Title="Mesh Simplification Algorithms" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8905" PostTypeId="1" CreationDate="2019-06-13T01:53:44.327" Score="0" ViewCount="52" Body="&lt;p&gt;the image below uses an RGB scale (the values of the scale are displayed on the image) to show the magnetic field strength at each point on the map. I've been struggling to find a way to convert this image into an array that shows the x and y coordinates of the pixel along with the magnetic field value at each coordinate (using MATLAB)&lt;a href=&quot;https://i.stack.imgur.com/Sz3BH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Sz3BH.jpg&quot; alt=&quot;Magentic field map u&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10767" LastActivityDate="2019-06-13T01:53:44.327" Title="RGB map into numerical data" Tags="&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8906" PostTypeId="2" ParentId="8900" CreationDate="2019-06-13T02:53:03.897" Score="6" Body="&lt;p&gt;What you're ultimately trying to do is, between draw calls, change some state that allows one to select which set of read-only data to use in the rendering process. There are many techniques for this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Push constants can be used to provide an index into an array of arbitrary size stored in an SSBO. Indeed, a single push constant can be used to provide multiple indices into multiple SSBOs, for different frequencies of state (per-frame vs. per-object). The upper 16-bits can be for one frequency, with the lower 16-bits for another.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That may sound slower than other methods, since you're accessing global data rather than an actual UBO. But on some hardware, it won't change anything. AMD hardware for example doesn't actually have any specialized hardware for UBOs, so they implement UBOs as just read-only SSBOs. Even on hardware with dedicated UBOs, the state data you're reading will likely be quickly cached, since all invocations will be reading the same values from the array. So unless your thrashing the SSBO caches, this shouldn't impact performance much.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Dynamic UBO descriptors also exist, given the &lt;code&gt;VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC&lt;/code&gt; type. Basically, the idea is that, when you call &lt;code&gt;vkCmdBindDescriptorSets&lt;/code&gt;, you provide a dynamic offset for any dynamic descriptors. The offset represents a byte offset from the buffer attached to that descriptor to where the UBO data you want to fetch lives. So you would have all of your data in a large buffer, and you would select which particular data you're using for a particular render call by invoking &lt;code&gt;vkCmdBindDescriptorSets&lt;/code&gt; with a different dynamic offset.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now &lt;code&gt;vkCmdBindDescriptorSets&lt;/code&gt; may seem like a more heavyweight call than setting push constant. But the implementation has all the information needed to be able to see that you are using the same descriptor as you used in the previous call in that command buffer, and thus not do the actual heavy part of that operation, simply applying the dynamic offsets to any dynamic descriptors. So that part should not be a concern.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Push descriptors are mainly intended for texture/sampler/image bindings, which don't have a convenient mechanism like dynamic offsets that would allow you to quickly switch which image/sampler you're using. That being said, push descriptors are a useful concept even for UBO/SSBOs. Whether they are &lt;em&gt;faster&lt;/em&gt; than dynamic descriptors is a matter of profiling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The principle downside is the obvious: push descriptors is an extension. Dynamic UBO offsets and push constants are mandatory, required by every Vulkan 1.0 implementation. Push descriptors aren't even optional features of Vulkan. They're important enough to get a KHR extension, but they didn't go into Vulkan 1.1 as an optional feature. This is not a theoretical issue: &lt;a href=&quot;http://vulkan.gpuinfo.org/listdevices.php?platform=windows&amp;amp;extension=VK_KHR_push_descriptor&quot; rel=&quot;noreferrer&quot;&gt;NVIDIA and Intel seem to support it on desktop, but no official AMD drivers do&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I would go with dynamic UBOs; this is exactly what they were made for, after all.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-06-13T02:53:03.897" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8907" PostTypeId="1" AcceptedAnswerId="8908" CreationDate="2019-06-13T06:50:12.367" Score="0" ViewCount="651" Body="&lt;p&gt;I'm using shaderc to compile glsl code in to spirv module and pass to pipelie in REAL-TIME. I want to use #include to reuse some of the shader code but shaderc is having problems recognizing it. Any one know how to solve this? (I'm NOT using command line to compile shader upfront.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The error I got from shaderc is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;standard.vert:6: error: '#include' : #error unexpected include directive for header name: GlobalInclude.glsl&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here are my shaders and client codes:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;standard.vert&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;#extension GL_ARB_separate_shader_objects : enable&#xA;#extension GL_KHR_vulkan_glsl : enable&#xA;#extension GL_GOOGLE_include_directive : enable&#xA;&#xA;#include &quot;GlobalInclude.glsl&quot;&#xA;&#xA;layout(location = 0) in vec3 inPosition;&#xA;layout(location = 1) in vec3 inColor;&#xA;layout(location = 2) in vec2 inTexCoord;&#xA;&#xA;layout(location = 0) out vec3 fragColor;&#xA;layout(location = 1) out vec2 fragTexCoord;&#xA;&#xA;void main() {&#xA;  gl_Position = passUBO.proj * passUBO.view * objectUBO.model * vec4(inPosition, 1.0);&#xA;  fragColor = inColor;&#xA;  fragTexCoord = inTexCoord;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;standard.frag&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;#extension GL_ARB_separate_shader_objects : enable&#xA;#extension GL_KHR_vulkan_glsl : enable&#xA;#extension GL_GOOGLE_include_directive : enable&#xA;&#xA;#include &quot;GlobalInclude.glsl&quot;&#xA;&#xA;layout(set = PASS_SET, binding = TEXTURE_SLOT(0)) uniform sampler2D texSamplerAlbedo;&#xA;&#xA;layout(location = 0) in vec3 fragColor;&#xA;layout(location = 1) in vec2 fragTexCoord;&#xA;&#xA;layout(location = 0) out vec4 outColor;&#xA;&#xA;void main() {&#xA;  //outColor = vec4(fragTexCoord, 0.0, 1.0);&#xA;  outColor = texture(texSamplerAlbedo, fragTexCoord);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;GlobalInclude.glsl&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define FRAME_SET 0//per frame&#xA;#define SCENE_SET 1//per scene&#xA;#define PASS_SET 2//per pass&#xA;#define OBJECT_SET 3//per draw call&#xA;&#xA;#define UNIFORM_BUFFER_BINDING_START 0&#xA;#define TEXTURE_BINDING_START 1&#xA;&#xA;#define TEXTURE_SLOT(NUMBER) TEXTURE_BINDING_START + NUMBER&#xA;&#xA;layout(set = SCENE_SET, binding = UNIFORM_BUFFER_BINDING_START + 0) uniform SceneUniformBufferObject {&#xA;  uint time;&#xA;} sceneUBO;&#xA;&#xA;layout(set = PASS_SET, binding = UNIFORM_BUFFER_BINDING_START + 0) uniform PassUniformBufferObject {&#xA;  mat4 proj;&#xA;  mat4 view;&#xA;  uint passNum;&#xA;} passUBO;&#xA;&#xA;layout(set = OBJECT_SET, binding = UNIFORM_BUFFER_BINDING_START + 0) uniform ObjectUniformBufferObject {&#xA;  mat4 model;&#xA;} objectUBO;&#xA;&#xA;layout(set = FRAME_SET, binding = UNIFORM_BUFFER_BINDING_START + 0) uniform FrameUniformBufferObject {&#xA;  uint frameNum;&#xA;} frameUBO;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Compile shader using shaderc API:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool Shader::CreateShaderFromFile(shaderc_shader_kind kind, bool optimize)&#xA;{&#xA;  // read shader string&#xA;  if (!ReadShaderFromFile())&#xA;      return false;&#xA;&#xA;  shaderc::Compiler compiler;&#xA;  shaderc::CompileOptions options;&#xA;&#xA;  // like -DMY_DEFINE=1&#xA;  //options.AddMacroDefinition(&quot;MY_DEFINE&quot;, &quot;1&quot;);&#xA;  if (optimize) options.SetOptimizationLevel(shaderc_optimization_level_size);&#xA;&#xA;  std::cout &amp;lt;&amp;lt; &quot;output 1:&quot; &amp;lt;&amp;lt; shaderString &amp;lt;&amp;lt; std::endl;&#xA;&#xA;  // preprocess&#xA;  shaderc::PreprocessedSourceCompilationResult preprocessed = compiler.PreprocessGlsl(shaderString, kind, fileName.c_str(), options);&#xA;&#xA;  if (preprocessed.GetCompilationStatus() != shaderc_compilation_status_success) &#xA;  {&#xA;      throw std::runtime_error(preprocessed.GetErrorMessage());&#xA;      return false;&#xA;  }&#xA;&#xA;  shaderString = { preprocessed.cbegin(), preprocessed.cend() };&#xA;&#xA;  std::cout &amp;lt;&amp;lt; &quot;output 2:&quot; &amp;lt;&amp;lt; shaderString &amp;lt;&amp;lt; std::endl;&#xA;&#xA;  // compile&#xA;  shaderc::SpvCompilationResult module = compiler.CompileGlslToSpv(shaderString, kind, fileName.c_str(), options);&#xA;&#xA;  if (module.GetCompilationStatus() != shaderc_compilation_status_success)&#xA;  {&#xA;      throw std::runtime_error(module.GetErrorMessage());&#xA;      return false;&#xA;  }&#xA;&#xA;  shaderBytecode = { module.cbegin(), module.cend() };// not sure why sample code copy vector like this&#xA;&#xA;  return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9901" LastActivityDate="2021-05-26T20:20:22.027" Title="shaderc compile through api with #include" Tags="&lt;shader&gt;&lt;vulkan&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8908" PostTypeId="2" ParentId="8907" CreationDate="2019-06-13T17:00:01.503" Score="3" Body="&lt;p&gt;It is &lt;em&gt;your&lt;/em&gt; responsibility to support includes by instantiating an &lt;a href=&quot;https://github.com/google/shaderc/blob/master/libshaderc/include/shaderc/shaderc.hpp#L182&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;IncluderInterface&lt;/code&gt;&lt;/a&gt; instance and calling &lt;a href=&quot;https://github.com/google/shaderc/blob/master/libshaderc/include/shaderc/shaderc.hpp#L199&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;SetIncluder(...)&lt;/code&gt;&lt;/a&gt; on the &lt;code&gt;options&lt;/code&gt; instance.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The interface includer API consists of the following methods:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Handles shaderc_include_resolver_fn callbacks.&#xA;virtual shaderc_include_result* GetInclude(const char* requested_source,&#xA;                                           shaderc_include_type type,&#xA;                                           const char* requesting_source,&#xA;                                           size_t include_depth) = 0;&#xA;&#xA;// Handles shaderc_include_result_release_fn callbacks.&#xA;virtual void ReleaseInclude(shaderc_include_result* data) = 0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It will therefore also be your responsibility to implement these functions and interpret the &lt;code&gt;#include&lt;/code&gt; directives from the GLSL into &lt;code&gt;shaderc_include_result&lt;/code&gt; instances that will be used by shaderc to complete the preprocessing of the GLSL.&lt;/p&gt;&#xA;" OwnerUserId="9306" LastActivityDate="2019-06-13T17:00:01.503" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8909" PostTypeId="1" AcceptedAnswerId="8910" CreationDate="2019-06-16T20:58:17.180" Score="2" ViewCount="861" Body="&lt;p&gt;I am integrating imgui into my app using glfw + vulkan example.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The function vkCreateSwapchainKHR() is also called by imgui setup logic in addition to my app on the same device and it fails with &quot;internal drawable creation failed&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Under what circumstances, if any, would this be a valid approach?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should my app and imgui share the same swapchain?&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2019-08-03T19:22:20.637" Title="Multiple swapchains in Vulkan app with ImGui" Tags="&lt;vulkan&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8910" PostTypeId="2" ParentId="8909" CreationDate="2019-06-17T02:11:06.240" Score="3" Body="&lt;p&gt;The Vulkan specification is very clear on this:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;A native window &lt;strong&gt;cannot&lt;/strong&gt; be associated with more than one non-retired swapchain at a time.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You can create a new swapchain for a surface, but only by passing the old swapchain as the &lt;code&gt;oldSwapchain&lt;/code&gt; parameter, which will cause the old swapchain to enter the retired state.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So yes, both you and imGUI should get on the same page about who owns the swapchain.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-06-17T02:11:06.240" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8911" PostTypeId="1" CreationDate="2019-06-17T02:39:04.613" Score="0" ViewCount="311" Body="&lt;p&gt;I've read multiple tutorials, but I still can't understand how do I properly rotate an object in 3D space on all 3 axis at once. For example, I'd like to give the object a pitch of 60 degrees, yaw of 20 degrees and roll of 70 degrees. &lt;strong&gt;How can I properly do this in OpenGL, preferrably using GLM?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="10784" LastActivityDate="2019-06-17T02:39:04.613" Title="How to rotate an object in OpenGL on the X, Y and Z axis on its local coordinates?" Tags="&lt;opengl&gt;&lt;glm&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8912" PostTypeId="1" AcceptedAnswerId="8954" CreationDate="2019-06-17T04:46:07.910" Score="1" ViewCount="3206" Body="&lt;p&gt;The 2D pipeline involves with the construction of world coordinate scene followed by converting world coordinate to viewing coordinate, then transforming viewing coordinate to normalized coordinate and lastly converting normalized coordinate to device coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am confused. Isn't viewing coordinate and device coordinate the same things?&#xA;Can someone give me the detail differentiation among these?&lt;/p&gt;&#xA;" OwnerUserId="10786" LastActivityDate="2019-06-28T00:21:15.337" Title="What is the difference between world coordinate, viewing coordinate and device coordinate in computer graphics?" Tags="&lt;transformations&gt;&lt;2d&gt;&lt;normal-mapping&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8913" PostTypeId="1" CreationDate="2019-06-17T09:35:29.093" Score="3" ViewCount="191" Body="&lt;p&gt;As we know, tiles can make it quicker to update large portions of the display at once, as compared with a bitmap. To put, say a letter, on the screen, the Commodore 64 typically does two writes (the screencode and the attribute), but the ZX Spectrum typically does 9 (eight bytes which make up an 8x8 bitmap, plus 1 for the attribute).&lt;/p&gt;&#xA;&lt;p&gt;Recently, a demo for the SEGA Genesis was released called Red Eyes. My understanding is that the 3D scenes were rendered on a PC, and some kind of program converted these animations to a tileset so that each frame can quickly be written into VRAM.&lt;/p&gt;&#xA;&lt;p&gt;But, however hard I search I cannot find any contemporaneous games for these retro systems which use a tileset to render (an approximation of) three-dimensional graphics. So is there a technical reason for that?&lt;/p&gt;&#xA;&lt;p&gt;I am asking because of a game I'm trying to write for the Commodore 64. My choice of platform has meant that the compute budget really is quite miserly, so of course I need to cut down on the amount of time spent pushing pixels to the framebuffer, and tile-based graphics are an obvious solution to that problem on this platform. Also I need to keep in mind the amount of time spent in 3D projection, and I believe this problem can also be solved with tile graphics, since for example a raycaster could cast one ray tile instead of one ray per pixel. But I'm unsure about that.&lt;/p&gt;&#xA;&lt;p&gt;So the camera in my game is restricted to movement in one plane in the same way that the camera in DOOM is. It pans left and right only, and moves forward and sometimes backward. Plus I know that the walls in my game always are East-West or North-South. No diagonal walls. I think that this will mean that a manageably small number of pre-computed tiles will be enough to show the walls at various angles depending on how the camera is positioned.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;The nature of this question is such that it could be answered in the following ways:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;It wouldn't work because ...&lt;/li&gt;&#xA;&lt;li&gt;You obviously weren't looking hard enough because here's an example of a game that does that. Here's a disassembly or source code so you can figure out how it worked&lt;/li&gt;&#xA;&lt;li&gt;It might be possible, but you'd have to watch out for ...&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="10771" LastEditorUserId="10771" LastEditDate="2021-03-15T19:43:57.083" LastActivityDate="2021-04-15T20:58:15.463" Title="Why don't I see tile-based 3D graphics?" Tags="&lt;3d&gt;&lt;tile-based-rendering&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8914" PostTypeId="1" CreationDate="2019-06-17T10:46:15.140" Score="1" ViewCount="52" Body="&lt;p&gt;I saw it here &lt;a href=&quot;https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#features-and-technical-specifications__technical-specifications-per-compute-capability&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#features-and-technical-specifications__technical-specifications-per-compute-capability&lt;/a&gt; , I don't know if it also happens for AMD.&lt;/p&gt;&#xA;" OwnerUserId="10788" LastActivityDate="2019-06-17T10:46:15.140" Title="Why cache working set per multiprocessor for texture memory in Nvidia has a variable size?" Tags="&lt;texture&gt;&lt;memory&gt;&lt;gpgpu&gt;&lt;opencl&gt;&lt;cuda&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8915" PostTypeId="1" CreationDate="2019-06-17T19:11:27.663" Score="0" ViewCount="301" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bE0In.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bE0In.png&quot; alt=&quot;source: wikipedia&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;download: &lt;a href=&quot;https://upload.wikimedia.org/wikipedia/commons/5/57/Subpixel-rendering-RGB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://upload.wikimedia.org/wikipedia/commons/5/57/Subpixel-rendering-RGB.png&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The  above picture is an example for sub pixel rendering. I tried resizing the image to very small size in editor by saving it onto my local machine. As I resize the image, group of pixels (sometimes all of them) turn either into Red, Green or Blue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When all 3 diodes(RGB) in a single pixel emits light, to human visual perception it produces White(1,1,1). What happens when i try to reduce the image size? How does one of the RGB color becomes dominant over the other, emitting colors other than white?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2oQfu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2oQfu.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Device used: Macbook Pro 15&quot; 2018&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My assumption on this is considering single pixel block which has three RGB sub pixels. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/0JU2p.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0JU2p.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While resizing(upto its limit) the above pixel block(1x1) sits onto either one of the three sub pixel in my physical device screen(3x3 since image size is reduced) which could emit only one color. Thus any of the 3 colors become prevalent based on where the one pixel block in the image above is placed on one of the 3 subpixels of one pixel block in my physical machine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am a newbie to computer graphics. Any clarification or brief explanation on why this happens is much appreciated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Update: @Olivier I resized the image using mousepad(Zoom out using two finger pinch) on Preview app in mac&lt;/p&gt;&#xA;" OwnerUserId="10789" LastEditorUserId="10794" LastEditDate="2019-06-22T09:29:45.283" LastActivityDate="2019-06-22T09:29:45.283" Title="Sub pixel rendered white text on black background changes color when resized to a very small size" Tags="&lt;color&gt;&lt;pixel-graphics&gt;&lt;pixel-shader&gt;&lt;pixels&gt;&lt;subpixel-rendering&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8916" PostTypeId="1" CreationDate="2019-06-17T21:23:57.623" Score="0" ViewCount="1052" Body="&lt;p&gt;I'm trying to learn computer graphics, but when I tried to get this very simple windower running with c&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xA;&#xA;#include &amp;lt;SDL2/SDL.h&amp;gt;&#xA;&#xA;static const int width = 320;&#xA;static const int height = 180;&#xA;&#xA;int main(int argc, char **argv)&#xA;{&#xA;    SDL_Init(SDL_INIT_VIDEO);&#xA;&#xA;    SDL_Window *window = SDL_CreateWindow(&quot;Hello, SDL2&quot;, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);&#xA;&#xA;    SDL_DestroyWindow(window);&#xA;    SDL_Quit();&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I try to compile and...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vke@komputilo:~/dev/MiaLudo/source$ gcc -g main.c -o ../ludo&#xA;/tmp/ccfVU5ua.o: In function `main':&#xA;/home/vke/dev/MiaLudo/source/main.c:11: undefined reference to `SDL_Init'&#xA;/home/vke/dev/MiaLudo/source/main.c:13: undefined reference to `SDL_CreateWindow'&#xA;/home/vke/dev/MiaLudo/source/main.c:15: undefined reference to `SDL_DestroyWindow'&#xA;/home/vke/dev/MiaLudo/source/main.c:16: undefined reference to `SDL_Quit'&#xA;collect2: error: ld returned 1 exit status&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Hoping someone can help me out, I'm running Trisquel Linux if that's important&lt;/p&gt;&#xA;" OwnerUserId="10790" LastActivityDate="2020-09-19T12:37:45.167" Title="sdl2: Compiler throws &quot;Undefined Reference&quot;" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8917" PostTypeId="1" AcceptedAnswerId="8923" CreationDate="2019-06-18T19:24:40.133" Score="2" ViewCount="117" Body="&lt;p&gt;I'm trying to draw a line between two specified points, by updating values in an array which is heightxWidth with each element a set of four bytes (r,g,b,a). In my naive implementation I get the top line which reaches a point with jagged steps in the top line shown below. My question is, how do I accomplish the standard canvas line effect without jumps seen here as the lower line shown below? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6uPsq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6uPsq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10787" LastActivityDate="2019-06-21T08:25:26.283" Title="Non jagged line algorithm for javascript canvas" Tags="&lt;algorithm&gt;&lt;javascript&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8919" PostTypeId="1" CreationDate="2019-06-19T08:26:27.210" Score="0" ViewCount="119" Body="&lt;p&gt;I am after a simple (not necessarily efficient) algorithm to &quot;continuously&quot; transform a closed surface mesh into a sphere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems that Blender is able to do this quite well: &lt;a href=&quot;https://docs.blender.org/manual/en/latest/modeling/meshes/editing/transform/to_sphere.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.blender.org/manual/en/latest/modeling/meshes/editing/transform/to_sphere.html&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I cannot find a reference, or technical description of the algorithm they use. I tried looking at &lt;a href=&quot;https://github.com/sobotka/blender/blob/5767dcbe60c07cd9ef113e2f54eaad6981a47bce/source/blender/editors/transform/transform.c#L4168&quot; rel=&quot;nofollow noreferrer&quot;&gt;the code&lt;/a&gt; but did not managed to figure out what it does unfortunately.&lt;/p&gt;&#xA;" OwnerUserId="10798" LastActivityDate="2019-06-19T08:58:49.617" Title="Inflate 3D mesh into sphere" Tags="&lt;transformations&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8920" PostTypeId="2" ParentId="8919" CreationDate="2019-06-19T08:58:49.617" Score="2" Body="&lt;p&gt;The core calculation seems to be &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  sub_v3_v3v3(vec, td-&amp;gt;iloc, tc-&amp;gt;center_local);&#xA;&#xA;  radius = normalize_v3(vec);&#xA;&#xA;  tratio = ratio * td-&amp;gt;factor;&#xA;&#xA;  mul_v3_fl(vec, radius * (1.0f - tratio) + t-&amp;gt;val * tratio);&#xA;&#xA;  add_v3_v3v3(td-&amp;gt;loc, tc-&amp;gt;center_local, vec);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which in C-ish psuedo code looks like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec = pos - center; //find vector from center to point&#xA;radius = length(vec); // get the length of the vector&#xA;vec = vec / radius;  //normalize the vector&#xA;&#xA;tratio = ratio * individual_sensitivity; // adjust sensitivity per vertex &#xA;&#xA;vec = lerp(vec * radius, vec * t-&amp;gt;val, tratio); //linearly interpolate between the original and where the point would be on the sphere&#xA;&#xA;pos = center + vec; // store result&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So the code projects the point to the sphere and linearly interpolates the point between the original location and the sphere location. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-06-19T08:58:49.617" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8921" PostTypeId="2" ParentId="8904" CreationDate="2019-06-19T16:52:31.163" Score="2" Body="&lt;p&gt;According to &lt;a href=&quot;https://books.google.co.uk/books?id=8zX-2VRqBAkC&amp;amp;printsec=frontcover&amp;amp;dq=polygon%20mesh%20processing&amp;amp;hl=en&amp;amp;sa=X&amp;amp;ved=0ahUKEwj6tK_o__XiAhWFY8AKHanSCBYQ6AEIKjAA#v=onepage&amp;amp;q=polygon%20mesh%20processing&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;Polygon-Mesh-Processing&lt;/a&gt;, section 7.2.2. paragraph &quot;Error quadrics&quot;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Error quadrics have major advantages regarding memory consumption and computational efficiency: each vertex &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; stores a symmetric 4x4 matrix &lt;span class=&quot;math-container&quot;&gt;$Q$&lt;/span&gt; only, and the error can efficiently be computed in constant time as &lt;span class=&quot;math-container&quot;&gt;$x^T Q x$&lt;/span&gt; - no matter how many planes are associated to vertex &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; during decimation. Because of this, error quadrics are one of the most frequently employed techniques in mesh decimation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The author of the reference I mentioned specifically refers to the paper you mention in your question. My interpretation is that more recent methods might be more sophisticated but resource-wise quadric errors are still better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also I'd add is relatively easy to implement anyway.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2019-06-19T16:52:31.163" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8923" PostTypeId="2" ParentId="8917" CreationDate="2019-06-21T08:25:26.283" Score="1" Body="&lt;p&gt;The problem you are seeing, i.e. &quot;jaggies&quot; or &quot;staircasing&quot;, is an example of the more general problem known as &lt;em&gt;&quot;aliasing&quot;&lt;/em&gt; and, in the graphics field, the term you want to search for is &lt;em&gt;&quot;Antialiasing&quot;&lt;/em&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Aliasing occurs when you undersample a signal. If a signal contains frequencies &lt;em&gt;at&lt;/em&gt; or above the &lt;a href=&quot;https://en.wikipedia.org/wiki/Nyquist_frequency&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nyquist Frequency&lt;/a&gt;, which is 1/2 the sampling frequency, those higher frequencies will come back &quot;in disguise&quot; i.e. &quot;under an alias&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The example I often give to new starters to explain the problem is:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;em&gt;Imagine you've started at a new job and work solidly, 9 to 5, &lt;strong&gt;except&lt;/strong&gt; for a 1hr break from 12 to 1. &lt;br&gt;&#xA;  The boss, however, regularly walks around the building at 12:30 and never sees you at your desk. He therefore concludes you are lazy and so don't get a pay rise&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That is an example of aliasing. The boss needs to sample at a (much) higher rate. (Randomised/stratified sampling would also help :-) )&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your line drawing example, I expect you are taking one sample per pixel, but if you do a Fourier analysis of a line, you will see it contains an infinite spread of frequencies. It's these higher frequencies (plus the reconstruction of the sampled results - which I've ignored) that can lead to the jaggy results. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The ideal solution is to low pass filter your incoming signal before sampling it, but that's 'nontrivial' with geometric data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are, however, multiple practical approaches to mitigating the problem, including supersampling (SSAA) and multispampling (MSAA), but in your case, perhaps something like &lt;a href=&quot;https://en.wikipedia.org/wiki/Xiaolin_Wu&amp;#39;s_line_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wu's method&lt;/a&gt; for antialiased line drawing will suffice.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2019-06-21T08:25:26.283" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8925" PostTypeId="1" CreationDate="2019-06-21T20:11:48.200" Score="5" ViewCount="181" Body="&lt;p&gt;I am trying to understand this seminal &lt;a href=&quot;http://www.robots.ox.ac.uk/~vgg/research/affine/det_eval_files/vibes_ijcv2004.pdf&quot; rel=&quot;noreferrer&quot;&gt;paper&lt;/a&gt;. I read this &lt;a href=&quot;https://computergraphics.stackexchange.com/q/391/10808&quot;&gt;post&lt;/a&gt; on what affine transformations and my understanding is that &lt;strong&gt;affine transformations&lt;/strong&gt; are transformations that preserve parallelism of lines such as rotation, translation, etc, but &lt;em&gt;NOT&lt;/em&gt; distortions of partials of the image, and other related transformations that cause previously parallel lines to no longer be parallel. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also understand that &lt;strong&gt;covariant regions&lt;/strong&gt; are the same region being detected from two different view points. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, in the paper, they use the term &quot;&lt;strong&gt;affine covariant regions&lt;/strong&gt;&quot; and state that they can be &quot;exploited to cope with geometric and photometric deformations&quot; (5th paragraph if introduction). This sentence throws off my understanding because I don't quite understand what it means when both terms are combined (affine - covariant). It's probably a subtle difference. Can someone please clarify?&lt;/p&gt;&#xA;" OwnerUserId="10808" LastActivityDate="2019-08-20T08:46:12.323" Title="What are affine covariant regions" Tags="&lt;transformations&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8926" PostTypeId="2" ParentId="5373" CreationDate="2019-06-21T20:28:22.657" Score="2" Body="&lt;p&gt;We're actually going through that paper for our own GGX BRDF metallic &amp;amp; edge_tint model, and we've spotted one crucial problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hammon is still using the Fresnel Schlick approximation for his microfacet field ray-trace which in reality only works for dielectrics (and conductors but with a hack).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But we went all out on actual Fresnel (discarding polarization) and do the full calculation, enabling us to set &lt;span class=&quot;math-container&quot;&gt;$F_0=0$&lt;/span&gt; when we do not wish for specular on a surface at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/Crisspl/IrrlichtBAW/commit/914b50d7238fc4a30f23fc2a4ea570e467f4ab75#r34031272&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Crisspl/IrrlichtBAW/commit/914b50d7238fc4a30f23fc2a4ea570e467f4ab75#r34031272&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that Schlick falls apart for &lt;span class=&quot;math-container&quot;&gt;$F_0&amp;lt;0.02$&lt;/span&gt;, so the GGX diffuse would be too dark for those materials (because its still assuming low transmittivity at glancing angles).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an aside, something that stinks to me is that DIS and PBR use &#xA;&lt;span class=&quot;math-container&quot;&gt;$(1-F(\theta_i))(1-F(\theta_o))$&lt;/span&gt; which is a split-sum approximation (fresnel with average facet normal) instead of the proper calculation which would be weighted average of fresnel with every facet normal possible, weighted of course by the normal distribution function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In PBR the &lt;code&gt;smooth&lt;/code&gt; component could stay as-is (except that the Schlick would need replacing by proper Fresnel) but I wonder what &lt;code&gt;rough&lt;/code&gt; and &lt;code&gt;multi&lt;/code&gt; would have to become with an &lt;span class=&quot;math-container&quot;&gt;$F_0&amp;lt;0.02$&lt;/span&gt; .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess that &lt;code&gt;rough&lt;/code&gt; would probably change very little, but enough to make a difference (since with &lt;span class=&quot;math-container&quot;&gt;$\alpha=1$&lt;/span&gt; GGX NDF is a constant) if &lt;span class=&quot;math-container&quot;&gt;$F_0=0$&lt;/span&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope we could drop E. Hammon an email and see if the simulation could be re-run for full Fresnel and the extended IoR (F0) range, 1.0 (0.0) inclusive.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: Seb. Lagarde also has the same concern as I did about the Fresnel used &lt;a href=&quot;http://openproblems.realtimerendering.com/s2017/02-PhysicallyBasedMaterialWhereAreWe.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://openproblems.realtimerendering.com/s2017/02-PhysicallyBasedMaterialWhereAreWe.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10809" LastEditorUserId="10809" LastEditDate="2019-06-22T13:22:41.810" LastActivityDate="2019-06-22T13:22:41.810" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8927" PostTypeId="1" AcceptedAnswerId="9586" CreationDate="2019-06-22T13:22:55.483" Score="2" ViewCount="126" Body="&lt;p&gt;I have a working renderer implemented with Java in JOGL with &lt;a href=&quot;https://jogamp.org/jogl/doc/NEWT-Overview.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;NEWT&lt;/a&gt;. Now I want to implement a Material Editor which should run in a second window. However I can't get a second window up and render in it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My main window is implemented as follows:&#xA;I have a class &lt;code&gt;Backend&lt;/code&gt; which implements the &lt;code&gt;GLEventListener&lt;/code&gt;. The two important methods are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public static void initOpenGl()&#xA;{&#xA;    GLProfile.initSingleton();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which is called before anything else happens on start up and, to create the window itself&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void createWindow(int windowWidth, int windowHeight, boolean isFullscreen, String windowTitle&#xA;        , Program program)&#xA;{&#xA;    GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3));&#xA;    caps.setBackgroundOpaque(false);&#xA;    glWindow = GLWindow.create(caps);&#xA;&#xA;    glWindow.setTitle(windowTitle);&#xA;    glWindow.setSize(windowWidth, windowHeight);&#xA;    glWindow.setUndecorated(false);&#xA;    glWindow.setPointerVisible(true);&#xA;    glWindow.setVisible(true);&#xA;&#xA;    m_program = program;&#xA;    glWindow.addGLEventListener(this);&#xA;    glWindow.addKeyListener(m_program);&#xA;    glWindow.addMouseListener(m_program);&#xA;    m_program.setBackend(this);&#xA;&#xA;    Animator animator = new Animator();&#xA;    animator.add(glWindow);&#xA;    animator.start();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;TRY 1&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my first attempt, I created a subwindow thus:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public void createSubWindow(int windowWidth, int windowHeight, boolean isFullscreen, String windowTitle&#xA;        , Program program)&#xA;{&#xA;&#xA;    Display display = NewtFactory.createDisplay(&quot;mystring&quot;);&#xA;    display.addReference();&#xA;&#xA;    Screen screen = NewtFactory.createScreen(display, 0);&#xA;    screen.addReference();&#xA;&#xA;    GLProfile profile = GLProfile.get(GLProfile.GL3);&#xA;    GLCapabilities caps = new GLCapabilities(profile);&#xA;    GLWindow window = GLWindow.create(screen, caps);&#xA;    //the following line does not work, context is null&#xA;    GLContext context = window.createContext(GLContext.getCurrent());&#xA;&#xA;    window.setSize(windowWidth, windowHeight);&#xA;    window.setVisible(true);&#xA;    window.setTitle(windowTitle);&#xA;&#xA;    System.out.println(windowTitle + &quot; window is open!&quot;);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Since the context is null however, an exception is thrown:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;No OpenGL context current on this thread&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;TRY2&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my second try I created a &lt;code&gt;SubWindow&lt;/code&gt; class much like the &lt;code&gt;Backend&lt;/code&gt; class, which implements &lt;code&gt;GLEventListener&lt;/code&gt; and has the same &lt;code&gt;createWindow&lt;/code&gt; method. This throws a different exception:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;com.jogamp.opengl.GLException: Caught ThreadDeath: null on thread main-Display-.windows_nil-1-EDT-1-AWTAnimator#01&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Perhaps the question would be better stated as &quot;how to create a second GL Context&quot;, I am not exactly sure.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2020-02-18T14:53:09.987" Title="How to open and render in a second window with OpenGL / JOGL with NEWT" Tags="&lt;opengl&gt;&lt;java&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8933" PostTypeId="1" CreationDate="2019-06-24T10:05:33.653" Score="0" ViewCount="56" Body="&lt;p&gt;I have a list of 3D points defined by Cartesian coordinates, i.e. &lt;em&gt;[(x1,y1,z1), (x2,y2,z2), ..., (xn,yn,zn)]&lt;/em&gt;. I want to project them to a 2D plane which has origin in the center (0,0,0) but which is rotated by polar angle theta, and azimuthal angle phi (*).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I understand I need some kind of 3x2 matrix that when multiplied  with my points matrix nx3 will give me my projection in 2D.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;nx3 matrix-multiply 3x2 = nx2&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to calculate this matrix if I know the angles of the plane rotation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If it helps here's a quick explanation what I'm trying to do. I have a 3d object consisting of point cloud, which is centered in the origin and I want to calculate how it looks from a camera placed on different points that are on equal distance from the origin,  looking directly toward the origin, and with light coming from the camera and toward the origin. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(*) I'm not sure does does those two angle define the plane in a unique way. &lt;/p&gt;&#xA;" OwnerUserId="10826" LastActivityDate="2019-06-24T10:05:33.653" Title="How to find matrix that projects 3d points into 2d plane centered in the origin?" Tags="&lt;transformations&gt;&lt;matrix&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8935" PostTypeId="1" CreationDate="2019-06-25T15:11:41.940" Score="2" ViewCount="81" Body="&lt;p&gt;Inkscape has a feature called Power Stroke which is a form of path effect.  When you apply it to a stroke you gain 3 control points that allow you to adjust the thickness of the stroke.  (I have not yet figured out how to add more control points through the UI, but it can be done in the XML editor).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Inspecting the SVG reveals that the stroke gets turned into a fill with a path@d that specifies the outline, allowing the SVG file to be rendered by applications that know nothing of Power Stroke.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applications that do understand Power Stroke will be looking for these attributes on the &lt;code&gt;&amp;lt;path&amp;gt;&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   inkscape:path-effect=&quot;#path-effect881&quot;&#xA;   inkscape:original-d=&quot;m 109.59491,132.23789 c -19.148152,28.51854 -37.80734,35.62606 -46.969458,22.13393 -9.383889,-13.81871 -39.69277,-3.57313 -46.276359,5.34215 -16.01795169,21.691 17.695947,71.79071 39.993907,62.61593 17.000232,-6.99496 23.845432,-20.30176 23.845432,-20.30176&quot;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The definition of the PowerStroke control points occurs inside the &lt;code&gt;&amp;lt;defs&amp;gt;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;inkscape:path-effect&#xA;   effect=&quot;powerstroke&quot;&#xA;   id=&quot;path-effect881&quot;&#xA;   is_visible=&quot;true&quot;&#xA;   offset_points=&quot;0.11606368,4.5282059 | 0.61857805,2.0941625 | 1.992627,6.538108 | 2.7945971,4.4492524&quot;&#xA;   sort_points=&quot;true&quot;&#xA;   interpolator_type=&quot;CubicBezierFit&quot;&#xA;   interpolator_beta=&quot;0.2&quot;&#xA;   start_linecap_type=&quot;round&quot;&#xA;   linejoin_type=&quot;bevel&quot;&#xA;   miter_limit=&quot;4&quot;&#xA;   end_linecap_type=&quot;butt&quot; /&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I have concluded that the @offset_points list can be interpreted as a list of t,r tuples, where t=0 is the first &quot;major&quot; control point in the path@d, and t=1 is the next.  A segment that is a cubic bezier curve is traditionally interpreted as having 4 control points, but for the purpose of path effects, the first and last control points are what I have termed &quot;major&quot; control points, and are shared with the segments on either side.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I do not yet understand is the @interpolator_type, likewise the @interpolator_beta.  I assume this controls how you interpolate the radius you calculate between the different offset_points, but I'm not sure what exact formula to use.  When I think Bezier, I think of Bezier curves, and how they only match up with their control points at the end of the segment.  I think the _beta corresponds to the &quot;smoothness&quot; field in the UI.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I wanted to calculate the Power Stroke radius at t=1.32, what formula would I use?&lt;/p&gt;&#xA;" OwnerUserId="8598" LastActivityDate="2021-02-23T22:03:45.390" Title="What is the mathematics behind inkscape's power stroke path effect interpolator_type and interpolator_beta attributes?" Tags="&lt;bezier-curve&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8936" PostTypeId="1" AcceptedAnswerId="8939" CreationDate="2019-06-25T16:19:50.057" Score="1" ViewCount="50" Body="&lt;p&gt;Could someone please provide me with/point me to a description of the process involved in displaying a digital image? &lt;strong&gt;Starting from reading the data from a file to displaying the image on the screen&lt;/strong&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am puzzled regarding which parts of this process are handled by the OS and which are handled by the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am especially interested in the transition from the initial, device-independent representation of the image to controlling the actual physical pixels on the screen. For example, how does a 1920x1080 image eventually get displayed on screens with higher or lower display resolutions? &lt;/p&gt;&#xA;" OwnerUserId="10834" LastActivityDate="2019-06-26T06:58:29.853" Title="Description of the process involved in displaying digital images" Tags="&lt;image&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8939" PostTypeId="2" ParentId="8936" CreationDate="2019-06-26T06:58:29.853" Score="2" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Starting from reading the data from a file to displaying the image on the screen.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;As was pointed out in the comments, this is an extremely broad question, and depends on what operating system you're using, and which tool sets for that OS you're using. That said, I think it is possible to talk generally about the process with much of it (if not all) being similar from machine to machine, and OS to OS.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I am puzzled regarding which parts of this process are handled by the OS and which are handled by the GPU.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I'll try to point out which parts are handled strictly by the OS, your program, and the graphics hardware, and I'll even provide C-like pseudo code. My pretend code will not be efficient, simply illustrative, and I'll be pretending to read &lt;a href=&quot;https://en.wikipedia.org/wiki/Netpbm_format#PPM_example&quot; rel=&quot;nofollow noreferrer&quot;&gt;this example&lt;/a&gt; image file.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;For example, how does a 1920x1080 image eventually get displayed on screens with higher or lower display resolutions?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I think some of my pretend pseudo code will illustrate that, but the short answer is that you will manually resize your image to better fit the screen (or any other drawing area) inside your program.&lt;/p&gt;&#xA;&lt;h1&gt;The Long Answer&lt;/h1&gt;&#xA;&lt;p&gt;The first step is to open the image file. It doesn't matter what the format of the image is, from the view of your program it'll simply be a list of bytes. Some languages have tools and libraries that can be used to open files in a generic (OS independent) way, but often this step is OS specific. However, even though the task of opening and/or reading the file is dependent on the operating system, once your program has copied the content into memory it's just bytes for your program to deal with however you desire.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;File imgFile = OS_OPEN_FILE(&amp;quot;sample.ppm&amp;quot;); // Ask the OS for a file.&#xA;byte buffer[imgFile.size()];               // Set aside memory to hold the file's content.&#xA;for(int i = 0; i &amp;lt; imgFile.size(); ++i) {  // Start a reading loop.&#xA;    buffer[i] = OS_READ_BYTE(imgFile);     // Ask the OS for all bytes in the file, one by one.&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Once you have access to all of the bytes in the entire image file it is up to you, the programmer, to know what each byte means, then to make your program read and interpret them correctly. For example, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Netpbm_format&quot; rel=&quot;nofollow noreferrer&quot;&gt;portable bitmap format&lt;/a&gt; starts with a couple of bytes letting you know if the picture file is color, gray scale, or black and white. There are bytes that let you know what size the picture is, bytes that should be ignored because they're comments intended for humans to read, and finally bytes that are the dots of color to be sent to the screen. It is up to the program to sort through all of that.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int bufSize = imgFile.size();&#xA;for(int i = 0; i &amp;lt; bufSize; ++i) {  // loop through all the bytes read earlier.&#xA;    if(buffer[i] == 'P' &amp;amp;&amp;amp; buffer[i+1] == '3') {  // Handle the image header.&#xA;        /* Do something */&#xA;    }&#xA;    else if(buffer[i] == '#') {  // Handle comments&#xA;        /* Do something */&#xA;    }&#xA;    else if(buffer[i] == /*...*/) {&#xA;        /* Do something */&#xA;    }&#xA;   /* ... etc. */&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The next task is OS specific. You'll need to somehow ask the operating system to give your program access to a &amp;quot;drawing surface&amp;quot;. Again, there are libraries such as &lt;a href=&quot;https://www.libsdl.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SDL&lt;/a&gt; or &lt;a href=&quot;https://www.sfml-dev.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;SFML&lt;/a&gt; that provide surfaces in a generic way, but they are hiding the surface the system gave them behind an easy to use wrapper.&lt;/p&gt;&#xA;&lt;p&gt;Often the drawing surface given by the OS is just a big block of bytes and you can simply copy data into it. Again, it is up to you to know which byte does what (like, which bytes represent red, green, or blue), but the task itself is usually just to copy from one chunk of memory into another. This is known as a &lt;strong&gt;Bl&lt;/strong&gt;ock &lt;strong&gt;I&lt;/strong&gt;mage &lt;strong&gt;T&lt;/strong&gt;ransfer, or a BLIT, and it's at this point that you may be handling memory inside the graphics card. Ultimately, it's up to the OS to decide where the drawing surface keeps the bytes that represent colors, but you can usually request that those bytes be on the GPU.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Surface sampleImage = OS_GET_GPU_DRAWING_SURFACE();&#xA;if(sampleImage.good()) {&#xA;    /* Copy in bytes from buffer[], sorting or converting data as needed. */&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Depending on what tools you're using, and what task you're performing, a drawing surface you request from the OS can be the screen itself, and other times the screen is something that you can't touch directly but can only send surfaces to. Even when you &lt;em&gt;can&lt;/em&gt; draw directly to the screen you will want to draw to a hidden surface, then blit the finished work over to the screen to prevent flickering and other visual problems. This is called &lt;a href=&quot;https://gameprogrammingpatterns.com/double-buffer.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;double buffering&lt;/a&gt;, and mostly applies to the screen because it's always visible to the user.&lt;/p&gt;&#xA;&lt;p&gt;Generally you will have many small drawing surfaces that represent things like, buttons, pieces of terrain in a game, letters, or whatever, and you'll use those to assemble a larger image on a bigger (usually screen sized) drawing surface that you will finally send to the screen as one big block.&lt;/p&gt;&#xA;&lt;p&gt;Just to reiterate, these steps are all being done by your program, but the way your program has to do them is OS specific, and much of the memory being handled at this late stage is &lt;em&gt;probably&lt;/em&gt; on the GPU.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Ready the screen and a drawing area.&#xA;Surface * screen = OS_GET_SCREEN_SURFACE();&#xA;Surface * screenBuffer = OS_GET_GPU_DRAWING_SURFACE();&#xA;&#xA;// Make the image 800% bigger!&#xA;sampleImage.resize(8.0f);&#xA;// Copy the image to the screen sized buffer, centering it.&#xA;// blitTo(surface, x, y)&#xA;// I'm assuming that in this pretend code images draw from their top left corner.&#xA;sampleImage.blitTo(screenBuffer,&#xA;                   screenBuffer.width()/2 - sampleImage.width()/2,&#xA;                   screenBuffer.height()/2 - sampleImage.height()/2);&#xA;/* ... etc. */&#xA;/* Do more image drawing work. */&#xA;&#xA;// Finally, display all our complex behind the scenes work to the user.&#xA;// This is called a buffer swap.&#xA;Surface * temp = NULL;&#xA;temp = screen;&#xA;screen = screenBuffer;&#xA;screenBuffer = temp;&#xA;temp = NULL;&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;h1&gt;The Short Answer&lt;/h1&gt;&#xA;&lt;p&gt;In summary...&lt;/p&gt;&#xA;&lt;p&gt;Task your program needs to do (what's primarily in charge):&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Open a file (OS)&lt;/li&gt;&#xA;&lt;li&gt;Read file (OS &amp;amp; Program)&lt;/li&gt;&#xA;&lt;li&gt;Interpret data (Program)&lt;/li&gt;&#xA;&lt;li&gt;Get a drawing surface (OS &amp;amp; GPU)&lt;/li&gt;&#xA;&lt;li&gt;Fill the drawing surface with image data. (Program &amp;amp; GPU)&lt;/li&gt;&#xA;&lt;li&gt;Assemble your final picture. (Program &amp;amp; GPU)&lt;/li&gt;&#xA;&lt;li&gt;Gain access to the screen (OS)&lt;/li&gt;&#xA;&lt;li&gt;Send your final picture to the screen. (OS and/or Program)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="10837" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-06-26T06:58:29.853" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8940" PostTypeId="1" AcceptedAnswerId="8942" CreationDate="2019-06-26T09:26:08.207" Score="5" ViewCount="232" Body="&lt;p&gt;Typically when coplanar or nearly coplanar polygons are rendered in OpenGL, the textures of each polygon mix together in a non-deterministic way. My understanding is that this is caused by the limited precision of the z-buffer as it uses floating point values. However, there seems to be an exception to this case. I've noticed that when two polygons are rendered with the exact same vertex positions, z-fighting does not occur. The polygon that was rendered last appears on top of the other coplanar polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why does this occur? Does this behavior always occur? Is this behavior guaranteed across all OpenGL implementations?&lt;/p&gt;&#xA;" OwnerUserId="10840" LastActivityDate="2019-06-26T17:06:01.140" Title="Why do identical polygons not z-fight in OpenGL?" Tags="&lt;opengl&gt;&lt;rendering&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8941" PostTypeId="2" ParentId="8940" CreationDate="2019-06-26T09:39:57.580" Score="2" Body="&lt;p&gt;That would be because the GPU is deterministic. For the same inputs (vertex positions) it should produce the exact same per pixel depth outputs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Z-Fighting usually occurs with polygons with different vertex positions but still on the same plane, so interpolation rounding errors show up as differences and hence Z-fighting.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2019-06-26T09:39:57.580" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="8942" PostTypeId="2" ParentId="8940" CreationDate="2019-06-26T17:06:01.140" Score="6" Body="&lt;p&gt;There are explicit rules in the OpenGL specification about invariance guarantees. For the purpose of this discussion, these rules boil down to the following.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given a particular series of vertex processing shaders (VS, tessellation, and GS), there are some set of input values, uniforms, and the like which lead to the computation of the final &lt;code&gt;gl_Position&lt;/code&gt; value for the primitives in that process. If all of these values are &lt;em&gt;binary identical&lt;/em&gt; (including the way the vertex format leads to any VS inputs), then you're guaranteed that &lt;code&gt;gl_Position&lt;/code&gt; will have binary identical values. And if two primitive of the same type have binary identical positions, the rasterizer is &lt;em&gt;required&lt;/em&gt; to generate binary identical fragment positions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And thus, no z-fighting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, that's kind of restrictive, as it only works with the same shaders. You can use different shaders, so long as:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;all shaders involved get binary identical values on expressions leading to the computation of &lt;code&gt;gl_Position&lt;/code&gt;,&lt;/li&gt;&#xA;&lt;li&gt;all shaders involved use the exact same expressions (and I mean &lt;em&gt;exact&lt;/em&gt;; &lt;code&gt;a + b&lt;/code&gt; isn't the &quot;same expression&quot; as &lt;code&gt;b + a&lt;/code&gt;, no matter what mathematics says) to compute &lt;code&gt;gl_Position&lt;/code&gt;, and&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;gl_Position&lt;/code&gt; and any inter-shader in/out variables leading to its computation are qualified with the &lt;code&gt;invariant&lt;/code&gt; qualifier in all shaders. This tells the compiler not to optimize certain things away in expressions leading to the computation of such values.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-06-26T17:06:01.140" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8944" PostTypeId="1" AcceptedAnswerId="8958" CreationDate="2019-06-27T00:58:59.197" Score="3" ViewCount="2042" Body="&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I wasn't 100% certain if this question belonged here or in Ask Ubuntu. I figured since it was about OpenGL programming I'd put it here, but if I should move it to Ask Ubuntu, please let me know.&lt;/p&gt;&#xA;&lt;h1&gt;Background&lt;/h1&gt;&#xA;&lt;p&gt;I'm new to OpenGL and needed to figure out which version I could program in on my PC. A few Google/Stack Exchange searches shows that the usual solution is to run &lt;code&gt;glxinfo | grep version&lt;/code&gt; and read the results, which I did and got the following:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;server glx version string: 1.4&#xA;client glx version string: 1.4&#xA;GLX version: 1.4&#xA;    Max core profile version: 4.5&#xA;    Max compat profile version: 3.0&#xA;    Max GLES1 profile version: 1.1&#xA;    Max GLES[23] profile version: 3.2&#xA;OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.0.5&#xA;OpenGL core profile shading language version string: 4.50&#xA;OpenGL version string: 3.0 Mesa 18.0.5&#xA;OpenGL shading language version string: 1.30&#xA;OpenGL ES profile version string: OpenGL ES 3.2 Mesa 18.0.5&#xA;OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The confusing part is the following three lines:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.0.5&#xA;OpenGL version string: 3.0 Mesa 18.0.5&#xA;OpenGL shading language version string: 1.30&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Everything I've read says to focus only on the Core Profile line, but I'm unable to draw anything unless I load functions and create a context under 3.0 or lower. Plus, when I call &lt;code&gt;glGetString(GL_VERSION)&lt;/code&gt; I get &lt;code&gt;3.0 Mesa 18.0.5&lt;/code&gt; printed to the terminal, but I'm not sure if that's because my hardware only supports 3.0 or if that's because I loaded functions for that level. Also, when I start writing shaders (I'm currently using Qt and an OpenGL Widget so haven't made a shader of my own yet) will I only be able to use GLSL 1.3 instead of 3.0+?&lt;/p&gt;&#xA;&lt;h1&gt;My Question&lt;/h1&gt;&#xA;&lt;p&gt;My big question is, what do the output strings actually mean? I can't find that answer. Which one tells me what my hardware can actually do? And, what do the other strings mean? Why am I getting a Core Profile of 4.5 when (as far as I can tell) I can't actually use 4.5? If my hardware &lt;em&gt;can&lt;/em&gt; perform 4.5 operations, how do I make it do so?&lt;/p&gt;&#xA;" OwnerUserId="10837" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-06-29T11:47:43.260" Title="What do the OpenGL version strings from glxinfo actually mean?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;c++&gt;&lt;hardware&gt;&lt;compatibility&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8946" PostTypeId="1" AcceptedAnswerId="8950" CreationDate="2019-06-27T09:57:45.787" Score="-1" ViewCount="313" Body="&lt;p&gt;I am learning about Cubemap and I learned that &lt;strong&gt;A cubemap is basically a texture that contains 6 individual 2D textures&lt;/strong&gt; but my question is &lt;strong&gt;Why does it contain 6 individual texture ?&lt;/strong&gt; and also I've read that it uses 3D directional vector for sampling, &lt;strong&gt;so what are the advantages of using 3D directional vector ?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="9298" LastActivityDate="2019-06-27T15:23:22.657" Title="Why does Cubemap have 6 individual textures?" Tags="&lt;shader&gt;&lt;texture&gt;&lt;reflection&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8947" PostTypeId="1" AcceptedAnswerId="8952" CreationDate="2019-06-27T10:25:41.493" Score="1" ViewCount="101" Body="&lt;p&gt;I would like to know what common techniques are used for rendering large models, when using rasterisation within a graphics API, for example OpenGL or Vulkan. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example if I had a model with &gt;10 million triangles, and it would be too slow to render the whole model, what optimisation steps or techniques could I use?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am currently aware of:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;Frustum culling&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;Occlusion culling&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I would not know how to apply frustum culling to a single model. I know it can be used for multiple models:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for( int i=0; i &amp;lt; numObjects; i++ )&#xA;{&#xA;    if( insideFrustrum( objects[i] )&#xA;    {&#xA;        addModelToBeRendered( objects[i] );&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Can frustum culling be applied to a single model/mesh?&lt;/li&gt;&#xA;&lt;li&gt;What other techniques besides the two stated can be used when rendering large data-sets?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="9902" LastEditorUserId="9902" LastEditDate="2019-06-27T13:08:18.010" LastActivityDate="2019-06-28T00:47:17.053" Title="Techniques for rendering high polycount models" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;occlusion&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8948" PostTypeId="2" ParentId="8946" CreationDate="2019-06-27T14:10:11.460" Score="3" Body="&lt;p&gt;Why starting from a 3D direction vector? Because that is most commonly the way you get the direction from the sight line where you want to sample the env map along.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Technically you can use any convex 3D shape as the surface of the map. For example a tetrahedron that gets unfolded into 2 rhomboids.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However the GPU is already optimized to render to a rectangle. This makes the cubemap easy to create at runtime. And the math to get which face to sample from and the coordinates from which to sample are extremely easy to calculate when dealing with an axis aligned cube. It boils down to finding the max value and dividing the other 2 coordinates with that max value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cubemap has some distortion around the corners of the cube but very much within reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also use another projection that lets you go from the direction to a coordinate on a single texture. These typically start from a latitude/longitude on a sphere direction and then map it to a texture using some &lt;a href=&quot;https://en.wikipedia.org/wiki/Map_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;map projection&lt;/a&gt;. Getting that lat/lon from a 3D direction vector requires using trig functions which are slower compared to the compares and divide the cubmap requires.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simplest possible projection from lat/long to UV will create a lot of distortion at the poles. Which leads to massive oversampling of that area and can lead to artifacts. &lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-06-27T14:10:11.460" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8949" PostTypeId="1" AcceptedAnswerId="8956" CreationDate="2019-06-27T14:45:26.523" Score="3" ViewCount="89" Body="&lt;p&gt;I am analysing a large number of PDF files from scientific articles, all of which contain images which (I think) were originally monochrome ( black/white). &#xA;The images have been extracted with Apache PDFBox and I am doing image processing on &lt;code&gt;*.png&lt;/code&gt;.&#xA;The images have severe colour distortion, and blurring which I do not think is due to the extraction process or to subpixel antialising (see &lt;a href=&quot;https://stackoverflow.com/questions/16242731/reconstructing-line-diagrams-from-subpixel-rendering&quot;&gt;https://stackoverflow.com/questions/16242731/reconstructing-line-diagrams-from-subpixel-rendering&lt;/a&gt;). Note that the effect is present on both lines and text.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The effect is present in all PNG files though in different amounts. I suspect it comes from the tool/s used to create the PDFs from the original images which &#xA;apply some softening process (antialising). I have analysed this visually and it consists of a narrow plane in HSV with only two colours mixed with a lot of white/grey/black.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to know what the algorithm is that creates this blurring and colour so that I can reverse it. Traditional sharpening is only partially successful.&#xA;I'd be delighted if anyone has code that does this (any language will do).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/iOWh8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iOWh8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;NOTE: I do not have originals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPDATE.&#xA;Here are some analyses of the colors with ImageJ ColorInspector3D plugin in YCbCr space&lt;/p&gt;&#xA;&#xA;&lt;p&gt;= YCbCr frequencies =&#xA;Note the &lt;em&gt;very&lt;/em&gt; sharp plane in which the colors lie&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/QvIAN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QvIAN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/h1c1f.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/h1c1f.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;and a histogram to show the distribution more clearly. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/UTbw8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UTbw8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;(The red/pink &lt;em&gt;is&lt;/em&gt; there on the RH sides - not very clear in this screen shot)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I intend to ask another question on how to sharpen this. (This Q is *where&quot; does the effect arise; the next will be &lt;em&gt;how to correct it&lt;/em&gt; even if we don't know the origin)&lt;/p&gt;&#xA;" OwnerUserId="10849" LastEditorUserId="10849" LastEditDate="2019-07-03T09:03:22.463" LastActivityDate="2019-07-03T09:03:22.463" Title="Origin of blurring and colour distortion in monochrome diagrams" Tags="&lt;image-processing&gt;&lt;antialiasing&gt;&lt;blur&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8950" PostTypeId="2" ParentId="8946" CreationDate="2019-06-27T15:23:22.657" Score="3" Body="&lt;p&gt;A texture is just a fancy lookup table; that's all it is. It's a function that you input some coordinate &lt;code&gt;T&lt;/code&gt; into, which returns a value for that particular &lt;code&gt;T&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are many ways that one might choose to build such a function. A 1D texture is a lookup table where the coordinate is a single value on the range [0, 1]. A 2D texture is a texture where the coordinate is a pair of values, each on the range [0, 1]. A 3D texture has its coordinates as a triple of values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can think of these textures as lookup tables that answer the question, &quot;what is the value at the position &lt;code&gt;T&lt;/code&gt; within a normalized [0, 1] space?&quot; 2D textures use a two-dimensional space. 3D textures use a three-dimensional space. But they're all asking about the value at a position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A cubemap is a lookup table that answers the question &quot;what is the value in the &lt;em&gt;direction&lt;/em&gt; &lt;code&gt;T&lt;/code&gt;?&quot; A 2D texture maps a position into a value; a cubemap maps a direction into a value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The purpose of &lt;em&gt;any&lt;/em&gt; texture, within a shader, is to fill in some parameter in the rendering equation. A texture might be used to define a surface's albedo, shininess, or some other surface property. But a texture might also be used to look up how much light reaches that particular point on the surface; that's what shadow mapping is all about. Textures are not just about changing material properties of a surface; they're useful for many kinds of math in shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Directional textures (ie: cubemaps) are often used for point-light shadow maps. Given a position on a surface, they answer the question &quot;can I see the light from here?&quot; Well, &quot;from here&quot; means using a direction towards the light. Since point lights are within the scene and cast light in all directions, a direction from the light to the current point on the surface represents the path the light would follow to reach that surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So a cube shadow map stores the distance from the light to the nearest occluding surface in all directions around the point light. And when a surface checks to see if it is in shadow from that light, it computes the direction from the point light to the surface and checks the directional shadow map.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Cubemaps have 6 &quot;textures&quot; (no, they don't have 6 textures. They have 6 sets of potentially mipmapped 2D &lt;em&gt;images&lt;/em&gt;. There's a difference between a texture and an image) because a cube has 6 faces. A cubemap implements its mapping from a direction to a value by taking that direction and figuring out which point(s) on these images correspond to that direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine being in the center of a cube. Each surface around you is one of these 6 images. For any pixel in those images, there is a unique direction from the center of the cube to that pixel. That creates the mapping from direction to pixel values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why are directional textures cubes instead of something else? Because it's the easiest way to create a directional texture. GPU hardware already knows how to deal with 2D images, how to access pixels from them, how to filter such accesses, and how to do mipmapping on them. All you really need to make cubemaps work is to tie together sets of 6 mipmap image chains and change the mapping algorithm, the means of converting a particular &lt;code&gt;T&lt;/code&gt; into a pixel location. You don't have to invent some way of storing spherical information or somesuch.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-06-27T15:23:22.657" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8952" PostTypeId="2" ParentId="8947" CreationDate="2019-06-27T16:14:56.843" Score="1" Body="&lt;p&gt;The straightforward solution is to simple not render the high poly model at all. Have a lower detail model that you can switch to once the model is too far away for it to make a difference. There is no point in rendering 20 triangles that all end up in the same pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Next option is to partition the model and then cull the individual parts. You can also make each (set of) patch have different Levels of detail. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This partition can take the form of patches that are mostly flat. That way you can use backface culling on the whole group by taking the dot product of the average normal and comparing it to the look vector, if it is too large only the backsides will be showing and there is no point in rendering that patch.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-06-27T16:14:56.843" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8953" PostTypeId="2" ParentId="6094" CreationDate="2019-06-27T17:19:12.630" Score="1" Body="&lt;p&gt;I know im a bit late, but hopefully this can help other people. you can add detail by using Fractal Brownian Motion. There is a great article &lt;a href=&quot;https://cmaher.github.io/posts/working-with-simplex-noise/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; that i used as a guide to make my own version in c#. Also I would check to make sure your vars are ints.&lt;/p&gt;&#xA;" OwnerUserId="10851" LastActivityDate="2019-06-27T17:19:12.630" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8954" PostTypeId="2" ParentId="8912" CreationDate="2019-06-28T00:21:15.337" Score="3" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;The 2D pipeline involves ... [coordinate transformation terms]&lt;/p&gt;&#xA;&lt;p&gt;Can someone give me the detail differentiation among these?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This is something I very recently learned while trying to understand how software handles 3D graphics behind the scenes. I've never encountered these terms in reference to 2D graphics before, but the ideas still apply. 2D graphics are just 3D graphics without a few fancy tricks.&lt;/p&gt;&#xA;&lt;h1&gt;Very Generally&lt;/h1&gt;&#xA;&lt;p&gt;Most of these different coordinate spaces don't technically exist. They come about by considering the objects you wish to draw from some reference point. When you change that reference point, you change the coordinate space. Math gets involved, but I won't do any here.&lt;/p&gt;&#xA;&lt;h1&gt;The Drawing Device and Device Coordinates&lt;/h1&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;... converting normalized coordinate to device coordinate.&lt;/p&gt;&#xA;&lt;p&gt;Isn't viewing coordinate and device coordinate the same things?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Short answer, no, but they can be in certain 2D cases. In 3D, pretty much never.&lt;/p&gt;&#xA;&lt;p&gt;There seems to be a confusion not just between view and device coordinates, but also with the distinction between normalized and device coordinates. Lets start with normalized and device, and we'll get to view later.&lt;/p&gt;&#xA;&lt;p&gt;In 3D systems (and 2D systems setup to work like them) you are presented with a &amp;quot;drawing device&amp;quot; consisting of two parts: drawing tools (usually functions accessed from application code) and a drawing area. Ignoring the tools, the important thing is that the drawing area has a coordinate system independent of pixels which adds a lot of flexibility and generality to the device.&lt;/p&gt;&#xA;&lt;p&gt;Any time something is setup to work numerically in a range from 0 to 1 it is &amp;quot;normal&amp;quot;, and often the range 0 to -1 is included too. With a drawing device the coordinates for both the X and Y directions of your drawing area range from -1 to 1, with -1 meaning &amp;quot;all the way left&amp;quot; for X and &amp;quot;all the way down&amp;quot; for Y, and 1 meaning &amp;quot;all the way right&amp;quot; or &amp;quot;all the way up&amp;quot; for X and Y respectively.&lt;/p&gt;&#xA;&lt;p&gt;You can easily add a Z direction too (also ranging from -1 to 1) for &amp;quot;3D&amp;quot; drawing, but all this does is give you a layered 2D image. There is no perspective (or &amp;quot;depth&amp;quot;) in your final drawing which is great for 2D games and graphics. The reason for this is that the drawing device will simply divide the space up into pixel size steps along X and Y then draw each pixel back to front (-Z to +Z). If you want real 3D though, you'll need some extra mathematical steps.&lt;/p&gt;&#xA;&lt;p&gt;It is possible (and common) for the device to understand and work with coordinates outside the -1 to 1 range. However, if we want an object to appear on screen than it must be &amp;quot;normalized&amp;quot; so that any coordinates it refers to are within -1 to 1. After this is done to an object the terms &amp;quot;normalized coordinates&amp;quot; and &amp;quot;device coordinates&amp;quot; are practically synonymous, just one refers to the object you altered so that it would fit within the drawing area and the other refers to the drawing area itself.&lt;/p&gt;&#xA;&lt;h1&gt;Object and World Spaces&lt;/h1&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The 2D [or 3D] pipeline involves with the construction of world coordinate scene ...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Yes, but you start in &amp;quot;object space&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;When someone creates a model of an object (or draws a sprite) all that matters to them, coordinate-wise, is where zero is within the space they're working. This consideration is called &amp;quot;object space&amp;quot; because the artist isn't concerned with the -1 to 1 drawing area, only accurately representing the object they'd like to draw. A model of a pen might be 6 units long and a model of a person might be 5.5 units tall. The important thing is that all of the points that make up some object are positioned with regard to the coordinate (0, 0, 0) and nothing else.&lt;/p&gt;&#xA;&lt;p&gt;When later loaded into memory they will be too big for the drawing area (which is only 2 units tall and wide) and the pen will appear larger than the person. It's up to us humans to know what the units mean and adjust them properly. Resizing and positioning all objects in relation to each other instead of each individually being sized with relation to zero transforms the objects into &amp;quot;world space&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;From the shortness of your question I wasn't sure if you knew that yet or not, but I thought I'd include that for completeness, as a good foundation for answering the next part of your question.&lt;/p&gt;&#xA;&lt;h1&gt;View Space&lt;/h1&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;... followed by converting world coordinate to viewing coordinate ...&lt;/p&gt;&#xA;&lt;p&gt;Isn't viewing coordinate and device coordinate the same things?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Note that in my explanation above nothing ever happened to the drawing device, or the coordinates of the drawing area. The only thing that ever changed was the objects we wanted to draw. The drawing area is fixed and unchanging, only ever drawing any object that fits within the coordinates -1 to 1.&lt;/p&gt;&#xA;&lt;p&gt;Each object loaded appears at the center of the drawing area at whatever size it was designed to have (object space) which is practically always too big for the drawing device. After rearranging and resizing every object around each other (object space → world space) we still have a final scene that is too big for the drawing area, and we have no way to move around within the scene. This is where we transform everything into &amp;quot;view space&amp;quot; and work with &amp;quot;eye coordinates&amp;quot;. Again, there is no such space, but what we do to work within it is to consider an imaginary camera and, treating the entire world as one giant object, we resize and reposition everything with respect to the position of the camera. That is &amp;quot;view space&amp;quot;, the movement of everything around a camera, and the terms &amp;quot;view coordinates&amp;quot; (or &amp;quot;eye coordinates&amp;quot;) refer to the positions of everything in relation to the camera.&lt;/p&gt;&#xA;&lt;h1&gt;View to Viewport&lt;/h1&gt;&#xA;&lt;p&gt;At this point everything that you want to see should be within the device space, but there are still a few last tasks to perform to get everything to draw.&lt;/p&gt;&#xA;&lt;p&gt;If you were working on a 3D scene instead of a 2D one, you would perform a &amp;quot;perspective transformation&amp;quot; to create the illusion of depth. This is where you squish and warp things to make them look like they're shrinking into the distance.&lt;/p&gt;&#xA;&lt;p&gt;Anything outside the drawing area needs to be thrown out. This saves on work for the computer, and it also is considered another transformation from view space to &amp;quot;clip space&amp;quot; because you are &amp;quot;clipping away&amp;quot; the extra data.&lt;/p&gt;&#xA;&lt;p&gt;And finally, after clipping, you'll do a &amp;quot;viewport&amp;quot; transformation that turns the -1 to 1 coordinates into pixel coordinates.&lt;/p&gt;&#xA;&lt;h1&gt;Summary&lt;/h1&gt;&#xA;&lt;p&gt;Well... I didn't intend for this answer to get so long. My apologies if I covered anything you already knew. It's hard to guess what someone does or does not already understand. Please leave a comment if you have any further questions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Object Coordinates:&lt;/strong&gt; The positions of points relative to a zero point. The points referred to are the building blocks of some single object.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;World Coordinates:&lt;/strong&gt; The positions of collections of points (objects) relative to a single shared standard zero point.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;View Coordinates:&lt;/strong&gt; The position of all points (the whole scene) relative to a camera.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Device Coordinates:&lt;/strong&gt; Any position within -1 to 1 on both the X and Y axis (and Z too for 3D). Any point within the drawing area of the device.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Normalized Coordinates:&lt;/strong&gt; The positions of points of any object (or the whole scene) that have been transformed to fit within the -1 to 1 space of the drawing device.&lt;/p&gt;&#xA;" OwnerUserId="10837" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-06-28T00:21:15.337" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8955" PostTypeId="2" ParentId="8947" CreationDate="2019-06-28T00:47:17.053" Score="0" Body="&lt;p&gt;My first thought (aside from culling) is to perform some sort of distance based level of detail algorithm. I've heard of systems in the past that could selectively remove edges and merge faces to produce lower detail sections on a single mesh, but most systems go for the far simpler method of simply loading in an entirely separate lower detail model once the higher detail model moves far enough from the camera.&lt;/p&gt;&#xA;" OwnerUserId="10837" LastActivityDate="2019-06-28T00:47:17.053" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8956" PostTypeId="2" ParentId="8949" CreationDate="2019-06-28T09:27:23.833" Score="3" Body="&lt;p&gt;This looks like JPEG artefacts so I guess the image went through a JPEG compression step at one stage and that permanently introduced noise into the image. The red channel is blurred stronger because JPEG additionally applies chroma subsampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect the original image was subpixel rendered as you shouldn't really have anything in the chroma channels for a monochrome input image.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2019-06-28T09:53:08.777" LastActivityDate="2019-06-28T09:53:08.777" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8957" PostTypeId="1" AcceptedAnswerId="8967" CreationDate="2019-06-29T09:14:23.763" Score="0" ViewCount="411" Body="&lt;p&gt;I want to split a couple of simple 2d forms into tri meshes. The meshes should conserve the original geometry and ideally I'd like a possibility to influence refinement vs. tris count.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have the 2d forms available as images (svg, png) and am happy to convert to something else if necessary (STL, ...?). Output should ideally be an IBO (index buffer containing points and triangle index numbers), but I will settle for something I can convert into that. I don't need a library, a manual process is fine, but I'm not above using one, if it gets the job done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found a number of possible solutions to this (gmsh, netgen, ... &lt;a href=&quot;https://stackoverflow.com/questions/4882993/mesh-generation-from-points-with-x-y-and-z-coordinates&quot;&gt;and more&lt;/a&gt;) but many of those seem too much (would require high time investment to learn) for my relatively simple problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am moderately proficient in python, blender and common linux software and am happy to come up with a small script to solve this, but don't want to dive deep into e.g. GL in order to solve this - hence my question: &lt;strong&gt;What is the easiest workflow to generate a trimesh from a svg or png?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This feels like a &quot;common&quot; issue, but I'm having a bit of hard time to find a solution with good effort/result ratio (maybe my google-fu is broken).&lt;/p&gt;&#xA;" OwnerUserId="10860" LastActivityDate="2019-07-03T08:02:02.763" Title="How to triangulate a simple 2d surface to generate a constrained surface trimesh" Tags="&lt;triangulation&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8958" PostTypeId="2" ParentId="8944" CreationDate="2019-06-29T11:47:43.260" Score="2" Body="&lt;p&gt;When creating a OpenGL context you have to specify a profile mask, which is a way of telling the driver whether you want to use compatibility (&quot;legacy&quot;) features or not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Drivers are required to implement all core profile features, but compatibility profile is optional - creating a compatibility context can fail even if the driver supports the version you've requested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The output from &lt;code&gt;glxinfo&lt;/code&gt; you've pasted shows that you can create GL context with version up to 4.5 only when using core profile. If you want to use compatibility profile, the highest version you can request is 3.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One reason of the problem you are having is that you:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;requested context version greater than 3.0, and&lt;/li&gt;&#xA;&lt;li&gt;requested a compatibility profile (by setting &lt;code&gt;GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB&lt;/code&gt; in &lt;code&gt;GLX_CONTEXT_PROFILE_MASK_ARB&lt;/code&gt;).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If removing compatibility bit doesn't help, you'll need to double check if other context attributes are correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;What I described above is documented in a more detailed way &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/GLX_ARB_create_context.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="8796" LastActivityDate="2019-06-29T11:47:43.260" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8959" PostTypeId="2" ParentId="8854" CreationDate="2019-06-30T06:50:00.183" Score="1" Body="&lt;p&gt;Quake subdivision rasterization comes to mind. &lt;a href=&quot;https://www.bluesnews.com/abrash/chap69.shtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.bluesnews.com/abrash/chap69.shtml&lt;/a&gt; , under ”An idea that did work”.&lt;/p&gt;&#xA;" OwnerUserId="2306" LastActivityDate="2019-06-30T06:50:00.183" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8960" PostTypeId="1" AcceptedAnswerId="8961" CreationDate="2019-06-30T08:38:56.903" Score="0" ViewCount="1228" Body="&lt;p&gt;A 3d Mesh on plot.ly online graph maker (&lt;a href=&quot;https://plot.ly/create/#/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://plot.ly/create/#/&lt;/a&gt;) takes 3 mandatory variables (X, Y, Z) and 3 optional variables (I, J, K).&#xA;I understand that if I want to draw a cube that I then have to use the IJK-variables, since without them nothing will be drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some googling I found that with i, j, k you can represent vectors. Though I do not understand how in the following examples they correspond to the XYZ values, so that a cube can be drawn.&#xA;There are several examples of cubes and cuboids on plot.ly, all of which share the same i, j, k, values. &#xA;f.e.&#xA;&lt;a href=&quot;https://plot.ly/create/?fid=RPlotBot%3A3933#/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://plot.ly/create/?fid=RPlotBot%3A3933#/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://plot.ly/create/?fid=markope%3A143#/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://plot.ly/create/?fid=markope%3A143#/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Taking the first link as an example:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x   y   z       i   j   k&#xA;0   0   0       7   3   0&#xA;0   1   0       0   4   7&#xA;1   1   0       0   1   2&#xA;1   0   0       0   2   3&#xA;0   0   1       4   5   6&#xA;0   1   1       4   6   7&#xA;1   1   1       6   5   1&#xA;1   0   1       6   2   1&#xA;                4   0   5&#xA;                0   1   5&#xA;                3   6   7&#xA;                2   3   6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This will draw a normal cube.&#xA;When I try my XYZ-coordinates, however, it will draw following:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/S4lkf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S4lkf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My xyz-coordinates are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;x   y   z&#xA;25  25  65&#xA;25  55  65&#xA;55  25  65&#xA;55  55  65&#xA;25  25  80&#xA;25  55  80&#xA;55  25  80&#xA;55  55  80&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;How can I calculate the according ijk-values so that I get a cuboid? Any tips or links to resources?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://help.plot.ly/make-a-3d-mesh-plot&quot; rel=&quot;nofollow noreferrer&quot;&gt;official tutorial&lt;/a&gt; for a 3d mesh on plot.ly online graph maker only mentions the ijk-values, doesn't explain them though.&lt;/p&gt;&#xA;" OwnerUserId="10863" LastActivityDate="2020-02-23T14:46:16.903" Title="What are the i,j,k components of a 3d mesh on plot.ly (online)?" Tags="&lt;3d&gt;&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8961" PostTypeId="2" ParentId="8960" CreationDate="2019-06-30T23:37:06.323" Score="3" Body="&lt;p&gt;Most mesh drawing tools use triangles to draw meshes, for technical reasons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You &lt;em&gt;could&lt;/em&gt; simply specify the coordinates of the three vertices of each triangle, but that is a bit wasteful in terms of memory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is done in many places is to specify a list of points in space, with their coordinates, and then specify a list of triangles, using indices of the points in the first list. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The exact same thing happens here. The x,y,z parameters form a list of points. The I,j,k parameters indicate triangles, using IDs in the list of points. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have a look at the function documentation for more details:&#xA;&lt;a href=&quot;https://plot.ly/python/reference/#mesh3d&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://plot.ly/python/reference/#mesh3d&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6647" LastActivityDate="2019-06-30T23:37:06.323" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8963" PostTypeId="1" CreationDate="2019-07-01T14:06:10.327" Score="3" ViewCount="517" Body="&lt;p&gt;So I'm trying to render participating media like clouds/sky/fog (Sky is the first step) etc. I had already implemented a normal pathtracer and I was thinking of extending it. But I heard terms like Ray marching/Sphere tracing are used for rendering volumes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A quick search brings up &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5520/using-monte-carlo-on-rayleigh-scattering&quot;&gt;this&lt;/a&gt; question where the guy is trying to use Monte Carlo methods to render the Sky. This has me confused. Does this mean we can use Path tracing together with ray marching? Or do we have to choose 1 over the other? Or is it that both are actually solving different problems? I have read up on what ray marching actually means, I just want to get a clear understanding of the connection between raymarching - raytracing/pathtracing.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-07-01T14:06:10.327" Title="Can I use Path tracing together with Ray Marching?" Tags="&lt;pathtracing&gt;&lt;volumetric&gt;&lt;raymarching&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="8964" PostTypeId="1" CreationDate="2019-07-02T16:49:33.233" Score="1" ViewCount="286" Body="&lt;p&gt;I am wondering how was first graphic or image libraries created,I know C and Python ,I want to create plotting application,and I cant imagine these libraries(QT,OpenGL,Vulkan) written by C,how can I create my image library,I just want to create basic graphic library.&lt;/p&gt;&#xA;" OwnerUserId="10871" LastActivityDate="2019-07-05T08:02:30.687" Title="How was computer graphics libraries or gtk,qt programmed?" Tags="&lt;opengl&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8965" PostTypeId="1" CreationDate="2019-07-02T14:14:09.990" Score="3" ViewCount="75" Body="&lt;h3&gt;Background&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;I am trying to create a node in Blender that would allow me to do what you would do with an audio equalizer but on the spatial frequencies of an image: A sort of panel with eight controllers, from low to high spatial frequencies, which allows me to attenuate or increase a certain frequency plus a second panel that allows me to increase the contrast on each of the eight frequencies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The idea came to me after playing a bit with &lt;a href=&quot;http://www.boundingboxsoftware.com/materialize/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Materialize&lt;/a&gt;, a well-known open-source software that serves to generate textures from a photograph and is used a lot in the world of video games.&#xA;To generate a height map (but also other maps) it offered a panel with various controllers that allowed to act on the frequency.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Question&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;On the Internet I have found practically nothing that is not the separation of frequencies made in Photoshop to correct skin imperfections. This procedure divides an image into low and high frequencies and then reassembles them.&#xA;My problem is: How do I split an image into several different spatial frequencies (not just two) and then reassemble them to get the original image again but with the possibility of modulating them individually.&#xA;Now, regardless of the software, what mathematical operations could I use fr this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm doing tests with Blender nodes. The node is a group of other nodes, I'm not using Python.&lt;/p&gt;&#xA;" OwnerDisplayName="Robert Angels" LastEditorUserId="5778" LastEditDate="2019-07-15T07:54:11.407" LastActivityDate="2019-07-15T10:10:31.590" Title="How to separate, modulate, and reassemble spatial frequencies?" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="8966" PostTypeId="1" CreationDate="2019-07-03T07:28:33.953" Score="3" ViewCount="257" Body="&lt;p&gt;I was recently learning about OpenGL and computer graphics development. I have a question regarding the usage of triangle as the basic building block, or basic shape to develop complex shapes. Is there a particular reason? Or just something that &quot;stuck&quot;?&lt;/p&gt;&#xA;" OwnerUserId="10873" LastActivityDate="2019-07-04T03:13:30.133" Title="Triangle - Why is it the basic building block for complex shapes" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8967" PostTypeId="2" ParentId="8957" CreationDate="2019-07-03T08:02:02.763" Score="0" Body="&lt;p&gt;The fastest and easiest way to do this is using &lt;a href=&quot;https://blender.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;blender&lt;/a&gt;. Simply import the svg (supported out of the box) into blender. The svg will be imported as a &quot;curve&quot;-type geometry. Optionally do some clean up/refinement. The curves can then be converted to a mesh. The mesh defaults to a trimesh. Voila - svg to trimesh in a couple of seconds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mesh refinement is not very fine-grained, but there is some measure of control via the &quot;beauty-fill&quot;, &quot;subdivide&quot; and &quot;triangulate&quot; as well as &quot;merge vertices by distance&quot; tools from within blender.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The IBO (vertices + triangle vertex indices) can then be extracted using a short python script:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import bpy&#xA;obdata = bpy.context.object.data # selected object&#xA;for v in obdata.vertices:&#xA;    fh.write('({}, {}),\n'.format(v.co.x, v.co.y))&#xA;for f in obdata.polygons:&#xA;    for v in f.vertices:&#xA;        print('{} '.format(v))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10860" LastActivityDate="2019-07-03T08:02:02.763" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8968" PostTypeId="2" ParentId="8966" CreationDate="2019-07-03T08:37:34.023" Score="5" Body="&lt;p&gt;In computer graphics, people are interested in modelling the &lt;em&gt;surface&lt;/em&gt; of the objects. And, since we are in the discrete world of computers, we need a discrete representation for surfaces, where we can easily check for stuff like intersections and angles, both vital for rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The triangle makes it very easy to compute intersections and surface normals, but also has some useful features: it is always convex (if not degenerate), which means that the mathematics is a lot simplified. Being so basic, you can also split pretty much any shape in triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But keep in mind that there are other basic shapes. Some hardware supports quads or nurbs, although it's much less common.&lt;/p&gt;&#xA;" OwnerUserId="6647" LastActivityDate="2019-07-03T08:37:34.023" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8969" PostTypeId="2" ParentId="8966" CreationDate="2019-07-04T03:13:30.133" Score="7" Body="&lt;p&gt;Triangles are always flat, unlike a quad which can be made in a way that is bent / not all vertices on the same plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you were to interpolate say vertex normals across each scanline, on a 4-edge bent quad it will render with horizontal (scanline) artefacts. If you made that same bent quad out of triangles, it will render correctly as each triangle has a different normal slope. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;That's one reason why triangles are preferable for scanline rasterising&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2019-07-04T03:13:30.133" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8970" PostTypeId="1" CreationDate="2019-07-04T19:53:25.140" Score="0" ViewCount="122" Body="&lt;p&gt;I've been doing some reading as to how to reduce input delay on modern computing devices. A lot of my understanding from this comes from the &lt;a href=&quot;https://danluu.com/latency-mitigation/&quot; rel=&quot;nofollow noreferrer&quot;&gt;VR research paper by Carmack&lt;/a&gt; explaining the numerous circumstances to reduce the latency between the CPU simulation/rendering -&gt; GPU buffering -&gt; video out stages.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So assuming the optimal case where we have a monitor with a ~60hz refresh rate with a simulation/render that fits in a single tick, I was wondering if software rendering bypasses the GPU buffer stage (G) shown below (but not the video out as we cant force the monitor to refresh).&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;I - Input, S = Simulation, R = Render, G = Gpu buffered commands, V - Video Out&#xA;CPU:ISSSSSRRRRRR----|&#xA;GPU:                |GGGGGGGGGGG----|&#xA;VID:                |               |VVVVVVVVVVVVVVVV|&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This would seem to trade off the need of synchronizing with GPU and GPU fencing that mentioned later at the cost of performance. I was wondering if this was accurate and a reasonable option to reduce display latency?&lt;/p&gt;&#xA;" OwnerUserId="10876" LastActivityDate="2019-07-04T19:53:25.140" Title="Software Rendering Display Latency" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;gpu&gt;&lt;performance&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8971" PostTypeId="2" ParentId="8964" CreationDate="2019-07-05T08:02:30.687" Score="3" Body="&lt;p&gt;You're asking about two different types of library. OpenGL and Vulkan aren't just libraries: they're hardware interfaces. They are implemented by GPU vendors so that application developers can access the GPU, like a special kind of hardware driver. They're implemented in C or C++ and the core functionality is implemented by writing some structures in memory that the GPU itself can understand, then writing to registers on the GPU to make it read those structures and do the work. There isn't any C code in OpenGL to transform triangles, compute their projection onto the screen, and shade them, because that work is all done by the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OTOH, Qt and Gtk are libraries for making applications. A lot of their work isn't about graphics: they provide a framework for applications to manage themes and interactivity, letting the application developer wire together different parts of the application with callbacks. This is just normal library code. They also provide GUI classes such as buttons and checkboxes. These will each have something like a &quot;draw&quot; function which draws the graphics on the screen. A few years ago this would commonly have been implemented using the OS's 2D drawing API (e.g. GDI on Windows), which offers operations like &quot;draw a filled rectangle&quot;, &quot;blit an image&quot;, but nowadays they're more likely to use OpenGL or Vulkan operations. The UI components are defined in images and they're used as textures to generate the image of the whole window via a sequence of OpenGL draw calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You wouldn't implement OpenGL or Vulkan: this is something that GPU vendors create. You can't really do it yourself without detailed knowledge of the GPU hardware. (However, &lt;em&gt;Mesa&lt;/em&gt; is an example of a software implementation of OpenGL, which doesn't depend on any GPU.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you wanted to implement a GUI library like Qt, you might start by defining an abstract &lt;code&gt;Widget&lt;/code&gt; class with a &lt;code&gt;draw&lt;/code&gt; method, and then implementing concrete subclasses of it to draw particular GUI components. Add extra methods and functionality as you need it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be honest, I don't think that would be a valuable project to work on. There are many smaller GUI frameworks already, and another toy one is not going to improve the world. You might treat it as just a learning project, but I think you'd learn more by studying one of the existing frameworks and writing an interesting GUI application on top of it.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-07-05T08:02:30.687" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8972" PostTypeId="1" AcceptedAnswerId="8998" CreationDate="2019-07-05T15:52:47.500" Score="3" ViewCount="75" Body="&lt;p&gt;When calculating fog along the ray we have two main part- transmittance and scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What happens when we have two different fogs? With different extinction and color?&#xA;Both extinction and color constant along the ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Transmittance seems easy to merge, probably something like this:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$T = e^{(\sigma_a+\sigma_b)d}$$&lt;/span&gt;&#xA;Where &lt;em&gt;d&lt;/em&gt; is ray length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What about color?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;General in-scattering equation looks like this:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$S=\sigma *Fog_{color}\int_0^dT(x,\omega x)dx$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What will happen with this equation when there are two fogs?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will it become:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$Fog_{color}=lerp(Fog_a,Fog_b,\sigma_b/(\sigma_a+\sigma_b))$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\sigma_t=\sigma_a+\sigma_b$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$S=\sigma_t*Fog_{color}*\int_0^de^{-\sigma_tx}dx$$&lt;/span&gt;&#xA;Or&#xA;&lt;span class=&quot;math-container&quot;&gt;$$S=\sum_0^n\sigma_i*Fog_i\int_0^dT_i(x,\omega x)dx$$&lt;/span&gt;&#xA;Where &lt;em&gt;n&lt;/em&gt; is fogs count.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or something else? &lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2019-07-13T10:12:35.283" Title="Adding two fogs" Tags="&lt;volumetric&gt;&lt;fog&gt;&lt;integral&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8975" PostTypeId="1" AcceptedAnswerId="9022" CreationDate="2019-07-06T14:28:44.860" Score="2" ViewCount="347" Body="&lt;p&gt;I am implementing a post-processing effect in my DirectX 11 pet renderer. The post-processing pass is implemented by rendering a full-screen quad covered with texture containing original rendered image, which works as it should, but I have problems with downscaling the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The non-processed testing scene looks like this (three very bright emmissive spheres):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/huGay.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/huGay.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I see no problem at this stage, but when I run the first post-processing pass, which just down-scales the image by the factor of 8 using the texture sampler, the result is very flickery (up-scaled for clarity):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4tOH8.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4tOH8.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I expected a mipmap would solve or at least reduce the flickering, but it didn't change a thing. What am I doing wrong?&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;RenderDoc Update&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;After investigating the issue using &lt;a href=&quot;https://renderdoc.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;RenderDoc&lt;/a&gt; I found that the mipmap is being generated successfully and it's third level looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/n8sy7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n8sy7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the output of the down-scaling pass looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WUppN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WUppN.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As if the sampler didn't use the mipmap at all. Don't get distracted by coloured object instead almost white ones. I lowered the sphere brightness a bit while investigating the bug.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even if I choose the mipmap level explicitly&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 vColor = s0.SampleLevel(LinearSampler, Input.Tex, 3);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;it changes nothing :-/&lt;/p&gt;&#xA;&#xA;&lt;p&gt;RenderDoc also says &quot;LOD Clamp 0-0&quot; for the used sampler. What is it? Couldn't this be the problem?&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;DirectX details&lt;/h1&gt;&#xA;&#xA;&lt;h3&gt;Samplers&lt;/h3&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_SAMPLER_DESC descSampler;&#xA;ZeroMemory(&amp;amp;descSampler, sizeof(descSampler));&#xA;descSampler.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;&#xA;descSampler.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;&#xA;descSampler.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;&#xA;&#xA;descSampler.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;&#xA;mDevice-&amp;gt;CreateSamplerState(&amp;amp;descSampler, &amp;amp;mSamplerStateLinear);&#xA;&#xA;descSampler.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;&#xA;hr = mDevice-&amp;gt;CreateSamplerState(&amp;amp;descSampler, &amp;amp;mSamplerStatePoint);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;...are set right before rendering the screen quad&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ID3D11SamplerState* aSamplers[] = { mSamplerStatePoint, mSamplerStateLinear };&#xA;mImmediateContext-&amp;gt;PSSetSamplers(0, 2, aSamplers);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;...and used within the down-scaling PS shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;SamplerState PointSampler  : register (s0);&#xA;SamplerState LinearSampler : register (s1);&#xA;&#xA;Texture2D s0 : register(t0);&#xA;&#xA;float4 Pass1PS(QUAD_VS_OUTPUT Input) : SV_TARGET&#xA;{&#xA;    return s0.Sample(LinearSampler, Input.Tex);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;h3&gt;Texture&lt;/h3&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_TEXTURE2D_DESC descTex;&#xA;ZeroMemory(&amp;amp;descTex, sizeof(D3D11_TEXTURE2D_DESC));&#xA;descTex.ArraySize = 1;&#xA;descTex.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;&#xA;descTex.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;&#xA;descTex.Usage = D3D11_USAGE_DEFAULT;&#xA;descTex.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;&#xA;descTex.Width  = width;&#xA;descTex.Height = height;&#xA;descTex.MipLevels = 0;&#xA;descTex.SampleDesc.Count = 1;&#xA;device-&amp;gt;CreateTexture2D(&amp;amp;descTex, nullptr, &amp;amp;tex);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;...it's render target view&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_RENDER_TARGET_VIEW_DESC descRTV;&#xA;descRTV.Format = descTex.Format;&#xA;descRTV.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;&#xA;descRTV.Texture2D.MipSlice = 0;&#xA;device-&amp;gt;CreateRenderTargetView(tex, &amp;amp;descRTV, &amp;amp;rtv);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;...it's shader resource view&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_SHADER_RESOURCE_VIEW_DESC descSRV;&#xA;ZeroMemory(&amp;amp;descSRV, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));&#xA;descSRV.Format = descTex.Format;&#xA;descSRV.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;&#xA;descSRV.Texture2D.MipLevels = (UINT)-1;&#xA;descSRV.Texture2D.MostDetailedMip = 0;&#xA;device-&amp;gt;CreateShaderResourceView(tex, &amp;amp;descSRV, &amp;amp;srv);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Explicit generation of mipmap is called after the scene was rendered into the texture and another texture was set as a render target.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ID3D11RenderTargetView* aRTViews[1] = { mPass1Buff.GetRTV() };&#xA;mImmediateContext-&amp;gt;OMSetRenderTargets(1, aRTViews, nullptr);&#xA;&#xA;mImmediateContext-&amp;gt;GenerateMips(mPass0Buff.GetSRV());&#xA;&#xA;ID3D11ShaderResourceView* aSRViews[1] = { mPass0Buff.GetSRV() };&#xA;mImmediateContext-&amp;gt;PSSetShaderResources(0, 1, aSRViews);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The code is compiled in debug and the D3D device was created with &lt;code&gt;D3D11_CREATE_DEVICE_DEBUG&lt;/code&gt; flag and I get no runtime errors on the console.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2019-07-21T17:02:06.137" LastActivityDate="2019-07-22T08:37:29.860" Title="Downscaling texture via mipmap [DirectX 11]" Tags="&lt;image-processing&gt;&lt;real-time&gt;&lt;sampling&gt;&lt;directx11&gt;&lt;post-processing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8979" PostTypeId="1" AcceptedAnswerId="8991" CreationDate="2019-07-07T15:15:17.770" Score="2" ViewCount="156" Body="&lt;p&gt;It's probably something obvious but there seems to be a strange issue with lighting in my pipeline. I'm trying to keep everything in world space at the moment for simplicity but cannot figure out what's going on here. Take a look at my code:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Geometry pass:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;helmet.vert&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;#version 410 core&#xA;&#xA;layout (location = 0) in vec4 aPos;&#xA;layout (location = 1) in vec4 aNormal;&#xA;layout (location = 2) in vec2 aTexCoords;&#xA;layout (location = 3) in vec3 aTangent;&#xA;layout (location = 4) in vec3 aBitangent;&#xA;&#xA;out vec3 FragPos;&#xA;out vec2 TexCoords;&#xA;out vec3 Normal;&#xA;out vec3 Tangent;&#xA;out vec3 Binormal;&#xA;&#xA;void main() {&#xA;    vec4 worldPos = model * aPos;&#xA;    FragPos = worldPos.xyz;&#xA;    TexCoords = aTexCoords;&#xA;&#xA;    mat3 normalMatrix = transpose(inverse(mat3(model)));&#xA;    Normal = normalize(normalMatrix * aNormal.xyz);&#xA;    Tangent = normalize(normalMatrix * aTangent);&#xA;    Binormal = normalize(normalMatrix * aBitangent);&#xA;&#xA;    gl_Position = projection * view * worldPos;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;helmet.frag&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;#version 410 core&#xA;&#xA;layout (location = 0) out vec3 gPosition;&#xA;layout (location = 1) out vec3 gNormal;&#xA;layout (location = 2) out vec4 gColor;&#xA;layout (location = 3) out vec4 gSpecular;&#xA;layout (location = 4) out vec4 gEmissive;&#xA;&#xA;in vec2 TexCoords;&#xA;in vec3 FragPos;&#xA;in vec3 Normal;&#xA;in vec3 Tangent;&#xA;in vec3 Binormal;&#xA;&#xA;// Textures passed from assimp&#xA;uniform sampler2D albedo;&#xA;uniform sampler2D material;&#xA;uniform sampler2D normalmap;&#xA;uniform sampler2D ambient;&#xA;uniform sampler2D emissive;&#xA;&#xA;void main() {&#xA;    // world space model fragment position&#xA;    gPosition = FragPos;&#xA;    // world space normals translated from tangent space&#xA;    mat3 tangentToWorld = mat3(Tangent, Binormal, Normal);&#xA;    gNormal = tangentToWorld * (texture(normalmap, TexCoords).rgb * 2.0 - 1.0);&#xA;    // diffuse per-fragment color&#xA;    gColor = texture(albedo, TexCoords);&#xA;    // Beyond here is material properties&#xA;    gSpecular = vec4(&#xA;        texture(material, TexCoords).rgb,&#xA;        texture(ambient, TexCoords).a&#xA;    );&#xA;    gEmissive = texture(emissive, TexCoords);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Lighting pass:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;pointlight.vert&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;#version 410 core&#xA;&#xA;layout (location = 0) in vec3 aPos;&#xA;layout (location = 1) in vec2 aTexCoords;&#xA;&#xA;out vec2 TexCoords;&#xA;&#xA;void main() {&#xA;    // rendering onto a framebuffer quad&#xA;    TexCoords = aTexCoords;&#xA;    gl_Position = vec4(aPos, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;pointlight.frag&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;#version 410 core&#xA;&#xA;in vec2 TexCoords;&#xA;out vec4 color;&#xA;&#xA;uniform sampler2D gPosition;&#xA;uniform sampler2D gNormal;&#xA;uniform sampler2D gColor;&#xA;uniform sampler2D gSpecular;&#xA;&#xA;// light position&#xA;uniform vec3 position;&#xA;&#xA;// phong (lambertian) diffuse term&#xA;float phong_diffuse() {&#xA;    return (1.0 / PI);&#xA;}&#xA;&#xA;&#xA;// compute fresnel specular factor for given base specular and product&#xA;vec3 fresnel_factor(in vec3 f0, in float product) {&#xA;    return f0 + (1.01 - f0)*pow(1.01 - product, 5.0);&#xA;}&#xA;&#xA;float D_GGX(in float roughness, in float NdH) {&#xA;    float m = roughness * roughness;&#xA;    float m2 = m * m;&#xA;    float d = (NdH * m2 - NdH) * NdH + 1.0;&#xA;    return m2 / (PI * d * d);&#xA;}&#xA;&#xA;float G_schlick(in float roughness, in float NdV, in float NdL) {&#xA;    float k = roughness * roughness * 0.5;&#xA;    float V = NdV * (1.0 - k) + k;&#xA;    float L = NdL * (1.0 - k) + k;&#xA;    return 0.25 / (V * L);&#xA;}&#xA;&#xA;// cook-torrance specular calculation&#xA;vec3 cooktorrance_specular(in float NdL, in float NdV, in float NdH, in vec3 specular, in float roughness) {&#xA;    float D = D_GGX(roughness, NdH);&#xA;&#xA;    float G = G_schlick(roughness, NdV, NdL);&#xA;&#xA;    float rim = mix(1.0 - roughness * texture(gSpecular, TexCoords).w * 0.9, 1.0, NdV);&#xA;&#xA;    return (1.0 / rim) * specular * G * D;&#xA;}&#xA;&#xA;void main() {&#xA;    // World space model vertex&#xA;    vec3 v_pos = texture(gPosition, TexCoords).rgb;&#xA;&#xA;    // light attenuation&#xA;    float A = 20.0 / dot(light_position - v_pos, light_position - v_pos);&#xA;&#xA;    // L, V, H, N vectors&#xA;    vec3 L = normalize(light_position - v_pos);&#xA;    vec3 V = normalize(-v_pos);&#xA;    vec3 H = normalize(L + V);&#xA;    vec3 N = normalize(texture(gNormal, TexCoords).rgb);&#xA;&#xA;    // albedo/specular base&#xA;    vec3 base = texture(gColor, TexCoords).xyz;&#xA;&#xA;    // roughness&#xA;    float roughness = texture(gSpecular, TexCoords).y;&#xA;&#xA;    // metallic&#xA;    float metallic = texture(gSpecular, TexCoords).x;&#xA;&#xA;    // mix between metal and non-metal material, for non-metal&#xA;    // constant base specular factor of 0.04 grey is used&#xA;    vec3 specular = mix(vec3(0.04), base, metallic);&#xA;&#xA;    // compute material reflectance&#xA;&#xA;    float NdL = max(0.0  , dot(N, L));&#xA;    float NdV = max(0.001, dot(N, V));&#xA;    float NdH = max(0.001, dot(N, H));&#xA;    float HdV = max(0.001, dot(H, V));&#xA;    float LdV = max(0.001, dot(L, V));&#xA;&#xA;    // specular reflectance with COOK-TORRANCE&#xA;    vec3 specfresnel = fresnel_factor(specular, HdV);&#xA;    vec3 specref = cooktorrance_specular(NdL, NdV, NdH, specfresnel, roughness);&#xA;&#xA;    specref *= vec3(NdL);&#xA;    vec3 diffref = (vec3(1.0) - specfresnel) * phong_diffuse() * NdL;&#xA;&#xA;&#xA;    // compute lighting&#xA;    vec3 reflected_light = vec3(0);&#xA;    vec3 diffuse_light = vec3(0);&#xA;&#xA;    // point light&#xA;    vec3 light_color = vec3(1.0) * A;&#xA;    reflected_light += specref * light_color;&#xA;    diffuse_light += diffref * light_color;&#xA;&#xA;    // final result&#xA;    vec3 result =&#xA;        diffuse_light * mix(base, vec3(0.0), metallic) +&#xA;        reflected_light;&#xA;&#xA;    color = vec4(result, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is before IBL is applied but I don't think that will make a difference here. Anyways, here's the weird result I'm getting (keep in mind the camera is the same as the point light position):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WI1U0.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WI1U0.jpg&quot; alt=&quot;camerapointlight&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For reference I'm using this model &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/DamagedHelmet&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/DamagedHelmet&lt;/a&gt; . Thanks to anyone who can help&lt;/p&gt;&#xA;" OwnerUserId="10886" LastEditorUserId="10886" LastEditDate="2019-07-08T16:48:24.433" LastActivityDate="2019-07-13T13:22:36.377" Title="Strange dark spot when lighting in deferred rendering PBR shaders" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="8980" PostTypeId="2" ParentId="8876" CreationDate="2019-07-08T07:02:35.267" Score="0" Body="&lt;p&gt;To anyone who is reading this in future:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I ended up taking an alternative route: Blender scripting.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blender comes with a built-in GLTF / GLB exporter. Here is what the render pipeline looks like in my code:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Define blender model which will act as template, complete with textures and materials.&lt;/li&gt;&#xA;&lt;li&gt;Define a meta JSON which defines the images for all sides&lt;/li&gt;&#xA;&lt;li&gt;In blenders Python script panel, read the meta JSON defined in #2 and start replacing the images in #1 in a loop&lt;/li&gt;&#xA;&lt;li&gt;After each replace, call the export plugins GLB functionality&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Profit!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, I am not allowed to post the script I wrote here / open source it.&lt;/p&gt;&#xA;" OwnerUserId="10720" LastActivityDate="2019-07-08T07:02:35.267" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8982" PostTypeId="1" CreationDate="2019-07-08T13:58:28.220" Score="1" ViewCount="46" Body="&lt;p&gt;i want some of your advices. To begin with i ve never studied computer graphics and i want to do a project with Path tracing which i didnt find the right materials to begin with. Is it recomeneded to start directly learn Path tracing or i have to learn something before. and i wish if someone can give some online examples and some materials  &lt;/p&gt;&#xA;" OwnerUserId="10892" LastActivityDate="2019-07-08T13:58:28.220" Title="Path tracing best materials to learn" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8983" PostTypeId="1" AcceptedAnswerId="8984" CreationDate="2019-07-08T17:41:47.480" Score="5" ViewCount="274" Body="&lt;p&gt;In the definition of Radiance, which according to PBRT is defined as&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;flux per unit solid angle &lt;span class=&quot;math-container&quot;&gt;$d\omega$&lt;/span&gt; per unit projected area &lt;span class=&quot;math-container&quot;&gt;$dA^\perp$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L_i=\frac{d\Phi}{d\omega\ dA^\perp}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My original assumption was that the &lt;span class=&quot;math-container&quot;&gt;$dA^\perp$&lt;/span&gt; term is used to weaken the irradiance contribution due to the incident angle (which I assume is just Lambert's cosine law). However, in the rendering equation, we've already explicitly apply Lambert's law with the &lt;span class=&quot;math-container&quot;&gt;$\cos\theta$&lt;/span&gt; term:&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\int_\Omega L_i(\omega_{i}) \, f_r(\omega_{i}\rightarrow \omega_{o}) \, \cos\theta_{i} \, d\omega_{i}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assume we arn't applying Lambert's law twice, so what exactly is this &lt;span class=&quot;math-container&quot;&gt;$dA^\perp$&lt;/span&gt; term?&lt;/p&gt;&#xA;" OwnerUserId="9420" LastEditorUserId="9420" LastEditDate="2019-08-01T05:44:24.690" LastActivityDate="2019-08-01T05:44:24.690" Title="What is the purpose of the projected solid angle $dA^\perp$ term in the definition of Radiance?" Tags="&lt;raytracing&gt;&lt;pbr&gt;&lt;radiosity&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8984" PostTypeId="2" ParentId="8983" CreationDate="2019-07-08T20:59:53.557" Score="5" Body="&lt;p&gt;Your main idea is more or less correct. The cosine hidden in the projected area measure &lt;span class=&quot;math-container&quot;&gt;$dA^\perp = dA\cos(θ)$&lt;/span&gt; compensates the weakening of irradiance due to incident angle (the Lambert's cosine law). This makes radiance independent from the incident angle. My guess is that the main motivation was to make it more practical to work with.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cosine in the rendering equation comes from the definition of BRDF:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f_{r}\left(\omega_{i}\rightarrow\omega_{o}\right) =\frac{\mathrm{d}L_{o}\left(\omega_{o}\right)}{\mathrm{d}E\left(\omega_{i}\right)} =\frac{\mathrm{d}L_{o}\left(\omega_{o}\right)}{L_{i}\left(\omega_{i}\right)\mathrm{d}\sigma^{\bot}\left(\omega_{i}\right)} =\frac{\mathrm{d}L_{o}\left(\omega_{o}\right)}{L_{i}\left(\omega_{i}\right)\cos\theta_{i}\mathrm{d}\omega_{i}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which can be rewritten as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\mathrm{d}L_{o}\left(\omega_{o}\right)&#xA;=f_{r}\left(\omega_{i}\rightarrow\omega_{o}\right) L_{i}\left(\omega_{i}\right) \cos\theta_{i} \mathrm{d}\omega_{i}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which can be integrated over the hemisphere the get the radiance reflected in a given direction &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int_\Omega f_{r}\left(\omega_{i}\rightarrow\omega_{o}\right) L_{i}\left(\omega_{i}\right) \cos\theta_{i} \mathrm{d}\omega_{i}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Voila, the rendering equation!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; Althought both cosines come from the same fundamental priciple, they serve different purposes.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2019-07-09T15:12:21.263" LastActivityDate="2019-07-09T15:12:21.263" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8985" PostTypeId="2" ParentId="5059" CreationDate="2019-07-09T01:49:24.947" Score="6" Body="&lt;p&gt;So, I'll start by saying I'm not a driver developer, but I have read many comments and docs in this regard.&lt;/p&gt;&#xA;&lt;p&gt;First of all, we can see how Khronos's own &lt;a href=&quot;https://www.khronos.org/assets/uploads/developers/library/overview/Vk_201602_Overview_Feb16.pdf#page=13&quot; rel=&quot;nofollow noreferrer&quot;&gt;slides&lt;/a&gt; on presentation day were mentioning some rather vague &amp;quot;any OpenGL ES 3.1 GPU&amp;quot; (or desktop 4.X). This means &lt;a href=&quot;https://www.anandtech.com/show/7867/khronos-announces-opengl-es-31&quot; rel=&quot;nofollow noreferrer&quot;&gt;something&lt;/a&gt; added around that mark would be the secret to it. Compute shaders are definitively [at least one of] the things, being confirmed &lt;a href=&quot;https://pcper.com/2015/03/gdc-15-what-is-vulkan-glnext-spir-v-and-opencl-2-1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, by an &lt;a href=&quot;https://youtu.be/2ryvYS47V0E?t=3176&quot; rel=&quot;nofollow noreferrer&quot;&gt;Intel developer&lt;/a&gt;, and in &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.1/pdf/vkspec.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;the spec&lt;/a&gt; with no possible unsupported value for &lt;code&gt;MaxComputeWorkGroupSize&lt;/code&gt; and this likely smoking gun:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;If an implementation exposes any queue family that supports graphics&#xA;operations, at least one queue family of at least one physical device&#xA;exposed by the implementation &lt;strong&gt;must&lt;/strong&gt; support both graphics and&#xA;compute operations.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;In addition to that though, it could &lt;em&gt;also&lt;/em&gt; be there are other mandatory capabilities (such as indirect draws or load&amp;amp;store, mentioned in the comments above too). But I have some slight difficulty interpreting the document. With the exception of &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.0/html/chap30.html#features-requirements&quot; rel=&quot;nofollow noreferrer&quot;&gt;robustBufferAccess&lt;/a&gt;, it seems like just about anything else big you could imagine is optional (from anisotropic filter, to geometry and tessellation shaders, to any special number format other than good old float32)&lt;/p&gt;&#xA;&lt;p&gt;This being the most hypothetically simple case then, doesn't mean it's all fine and dandy. Not having &lt;a href=&quot;https://www.phoronix.com/forums/forum/linux-graphics-x-org-drivers/open-source-amd-linux/1004192-r600-gallium3d-now-effectively-at-opengl-4-4-a-nudge-away-from-gl-4-5/page2#post1004523&quot; rel=&quot;nofollow noreferrer&quot;&gt;virtual memory&lt;/a&gt; will make your life a hell for example, and lack of other &lt;a href=&quot;https://www.phoronix.com/forums/forum/linux-graphics-x-org-drivers/vulkan/845690-amd-s-vulkan-driver-will-only-work-with-the-amdgpu-kernel-driver/page3#post845731&quot; rel=&quot;nofollow noreferrer&quot;&gt;architectural features&lt;/a&gt; may basically nullify whatever theoretical advantage in speed the API has.&lt;/p&gt;&#xA;&lt;p&gt;These links should also answer your wonders about ATi cards. Likely same story for NVidia then (aside of perhaps some microbenchmarks, I'm not sure how much &lt;em&gt;really&lt;/em&gt; workable &lt;a href=&quot;https://techreport.com/news/32191/nvidia-finally-lets-fermi-gpu-owners-enjoy-directx-12/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fermi's&lt;/a&gt; 2-years-delayed bare-bones DX12 support eventually is). As for Intel, I don't know what you are talking about, Gen8 is supported since &lt;a href=&quot;https://01.org/linuxgraphics/blogs/jekstrand/2016/open-source-vulkan-drivers-intel-hardware&quot; rel=&quot;nofollow noreferrer&quot;&gt;Day1&lt;/a&gt; and in fact even &lt;a href=&quot;https://stackoverflow.com/questions/41497142/can-i-install-a-vulkan-driver-on-my-3rd-gen-intel-ivy-bridge-integrated-gpu-on-u&quot;&gt;Gen7&lt;/a&gt; &lt;em&gt;shakily&lt;/em&gt; works now.&lt;/p&gt;&#xA;&lt;p&gt;Going even further back, I guess if any the question becomes &amp;quot;what's so special about compute shaders again&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;And, well, the thing isn't probably the very specific &lt;a href=&quot;https://www.anandtech.com/show/2716/5&quot; rel=&quot;nofollow noreferrer&quot;&gt;feature&lt;/a&gt; itself (because it's &lt;a href=&quot;https://en.wikipedia.org/wiki/BrookGPU&quot; rel=&quot;nofollow noreferrer&quot;&gt;not that&lt;/a&gt; you couldn't already do some sort of general purpose calculation even before the unified shader model), but more like the whole general GPU architecture needed to support it. Check &lt;a href=&quot;https://www.gamedev.net/forums/topic/666419-what-are-your-opinions-on-dx12vulkanmantle/5215019/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; for some backstory.&lt;/p&gt;&#xA;&lt;p&gt;Before DX11 raised &lt;a href=&quot;https://stackoverflow.com/questions/3332782/can-directcompute-really-be-used-on-a-dx10-1-gpu&quot;&gt;the bar&lt;/a&gt; for example, just think that you &lt;a href=&quot;https://www.anandtech.com/show/2977/nvidia-s-geforce-gtx-480-and-gtx-470-6-months-late-was-it-worth-the-wait-/3&quot; rel=&quot;nofollow noreferrer&quot;&gt;couldn't&lt;/a&gt; even run more than a single &amp;quot;task&amp;quot; on a Tesla GPU, without having to call a context switch (with comparable limitations also likely existing for TeraScale 1 and Gen6). And may God save us from when pixel and vertex units were separated hardware.&lt;/p&gt;&#xA;&lt;p&gt;fun fact: it turns out that if you are a low-end &lt;a href=&quot;https://www.anandtech.com/show/8649/arm-announces-mali-800-series-gpus-t860-t830-t820&quot; rel=&quot;nofollow noreferrer&quot;&gt;kind-of-modern&lt;/a&gt; mobile gpu (rather than an old desktop card from a time when certain concepts hadn't even been invented yet), engineers can cut you down so much that even if you just sport D3D 9_3 feature level that's still potentially &lt;a href=&quot;https://developer.arm.com/solutions/graphics/resources/faqs#vulkan_which&quot; rel=&quot;nofollow noreferrer&quot;&gt;enough&lt;/a&gt; to support Vulkan.&lt;/p&gt;&#xA;&lt;p&gt;EDIT: for such somewhat twisted reasons, it can also &lt;a href=&quot;https://github.com/Yours3lf/rpi-vk-driver/issues/1&quot; rel=&quot;nofollow noreferrer&quot;&gt;happen&lt;/a&gt; that while you are just GLES 2.0 compliant (and compute shaders themselves aren't supported atm, even though the architecture would be capable) a restricted version of Vulkan could also be possible. It doesn't give you everything, but it can still lead to benefits over just &amp;quot;old apis&amp;quot;.&lt;/p&gt;&#xA;" OwnerUserId="9500" LastEditorUserId="9500" LastEditDate="2020-06-20T13:10:56.007" LastActivityDate="2020-06-20T13:10:56.007" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8986" PostTypeId="2" ParentId="8983" CreationDate="2019-07-09T07:31:11.077" Score="0" Body="&lt;p&gt;The two cosine terms basically refer to the foreshortening effect which says: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The irradiance falling onto a patch must be modified by the cosine of the angle of the patch to the source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now from the definition of the irradiance:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/VdqDS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VdqDS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;irradiance is flux per unit area, therefore:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/X7zm9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/X7zm9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Reordering it gives:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZHsS8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZHsS8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is the definition of radiance, with the same cosine term that was in definition of irradiance(integrating irradiance on the hemisphere and multiplying it by BRDF gives rendering equation).&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;So both cosine terms refer to one effect but I think you are right that there are two cosine terms in rendering equation. The first which is visible in equation compensates for the weakening of irradiance on the receiver patch, and the second cosine implicit in radiance definition corresponds to the radiance of the source patch subtended foreshortened surface area. In path tracing this radiance (Li) either comes from a direct light with a known radiance value or an indirect which is unknown and will be solved recursively. But if you were to calculate the source radiance you need to multiply both terms too.&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2019-07-09T08:32:36.567" LastActivityDate="2019-07-09T08:32:36.567" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8987" PostTypeId="2" ParentId="8555" CreationDate="2019-07-09T09:05:12.937" Score="3" Body="&lt;p&gt;After coming back to the problem now with a fresh pair of eyes, I have managed to find my mistake.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Ad Question 1&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;Yes, the formula is correct. The problem is hidden in the tangent &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=X&quot; alt=&quot;X&quot;&gt; and bi-tangent &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=Y&quot; alt=&quot;Y&quot;&gt;. When performing normal mapping, the tangent frame has to be &lt;strong&gt;perpendicular&lt;/strong&gt; to the mapped normal, otherwise the term &#xA;&lt;img src=&quot;https://i.stack.imgur.com/9Wq9Q.gif&quot; alt=&quot;tangent-halfway dot&quot;&gt; will not carry any information about the normal mapping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another issue here might be that once the normal is mapped, the tangent frame is not uniquely determined. Some more info on that can be found here: &lt;a href=&quot;http://www.thetenthplanet.de/archives/1180&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.thetenthplanet.de/archives/1180&lt;/a&gt;. I have decided to solve this the same way as Blender does (look for &lt;code&gt;make_orthonormals_tangent()&lt;/code&gt; in their repo) because I need to be compatible with it. Here is my algorithm for that:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bitangent_ortho = norm(cross(normal, tangent))&#xA;tangent_ortho = cross(bitangent_ortho, normal)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(Assuming that the &lt;code&gt;normal&lt;/code&gt; is mapped and has unit length and the &lt;code&gt;tangent&lt;/code&gt; was a valid tangent before the normal was mapped.)&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;Ad Question 2&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;This was indeed well answered by user &lt;a href=&quot;https://computergraphics.stackexchange.com/users/10096/lightxbulb&quot;&gt;@lightxbulb&lt;/a&gt; in a comment to my question. My only problem with the &quot;Physically based shading at Disney&quot; course notes was that the variable symbols weren't very clearly explained. I have since learned that the convention is the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Ctheta_v&quot; alt=&quot;\theta_v&quot;&gt; is the angle between the normal and &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=v&quot; alt=&quot;v&quot;&gt; &lt;/li&gt;&#xA;&lt;li&gt;&lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=%5Cphi_v&quot; alt=&quot;\phi_v&quot;&gt; is the azimuthal angle between the tangent and &lt;img src=&quot;https://chart.googleapis.com/chart?cht=tx&amp;amp;chl=v&quot; alt=&quot;v&quot;&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;h2&gt;Ad Question 3&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;The only pieces of advice that were useful for me here were the following:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Always come up with the simplest toy examples possible&lt;/li&gt;&#xA;&lt;li&gt;Verify your assumptions&lt;/li&gt;&#xA;&lt;li&gt;Visualize everything&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h2&gt;Conclusion&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I hope this is helpful for somebody else than just me. Good luck implementing BRDFs!&lt;/p&gt;&#xA;" OwnerUserId="10125" LastActivityDate="2019-07-09T09:05:12.937" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8988" PostTypeId="2" ParentId="8983" CreationDate="2019-07-09T11:57:15.197" Score="1" Body="&lt;p&gt;Since you seem to want an explanation in terms of irradiance, consider both the radiance and irradiance definitions:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$E = \frac{d\Phi}{dA}, \quad  L = \frac{d^2\Phi}{d\omega dA^{\perp}}$$&lt;/span&gt;&#xA;We can reformulate the radiance definition as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d^2\Phi = L \cos\theta d\omega dA$$&lt;/span&gt;&#xA;Integrating both sides over the solid angle &lt;span class=&quot;math-container&quot;&gt;$d\omega$&lt;/span&gt; (in the sense of Lebesgue-Stieltjes) yields:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d\Phi = dA \int_{\Omega}{L\cos\theta d\omega}$$&lt;/span&gt;&#xA;And thus:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$E = \frac{d\Phi}{dA} = \int_{\Omega}{L\cos\theta d\omega}$$&lt;/span&gt;&#xA;So you can think of irradiance as the integral of radiance with respect to the solid angle measure, or vice versa, you can think of radiance as the derivative of irradiance with respect to the solid angle measure. The other answers also provide the link to the rendering equation. So no, you do not have the cosine two times. Though if you were to rewrite the rendering equation in its area formulation you do get another cosine term (which is due to the projection of a differential area patch onto the hemisphere). This uses the relationship:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d\omega = \frac{\cos\theta_y}{r^2}dA(y)$$&lt;/span&gt;&#xA;Then one can rewrite the rendering equation as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L_o(x_0 \rightarrow x_{-1}) = \int_{S}{f(x_1 \rightarrow x_0 \rightarrow x_{-1}) L(x_1 \rightarrow x_0) \cos\theta_{x_0} \frac{\cos\theta_{x_1}}{||x_1-x_0||^2} V(x_0,x_1) \,dA(x_1)}$$&lt;/span&gt;&#xA;Where the visibility term &lt;span class=&quot;math-container&quot;&gt;$V(x_0,x_1)$&lt;/span&gt; appears since it was originally implicit in the solid angle formulation. This is because you cannot get radiance on a straight line between point &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; if there is an occluder in-between, that's automatically taken care of in the solid angle formulation by using &lt;span class=&quot;math-container&quot;&gt;$L_i(x_0,\omega = x_0 \rightarrow x_1)$&lt;/span&gt;, which gives us the radiance arriving at &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; from direction &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt;, note that this considers the first point from which this radiance arrives, and not specifically &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt;. Formally &lt;span class=&quot;math-container&quot;&gt;$L_i(x_0, \omega) = L(r(x_0,\omega), -\omega))$&lt;/span&gt;, note the raycasting operator &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; in which the visibility term is implicitly hidden, since &lt;span class=&quot;math-container&quot;&gt;$r(x_0,x_0 \rightarrow x_1) \ne x_1$&lt;/span&gt; if there is an occluder inbetween.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-07-09T11:57:15.197" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="8989" PostTypeId="1" AcceptedAnswerId="9360" CreationDate="2019-07-09T20:30:45.683" Score="2" ViewCount="216" Body="&lt;p&gt;So Im trying to implement a Volume Renderer mainly for medical images like CT-scans and MRI images using GPU raymarching. I'm using the book &quot;Real Time Volume Graphics&quot; and &lt;a href=&quot;http://graphicsrunner.blogspot.com/2009/01/volume-rendering-101.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; tutorial as a refernce. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to render only grayscale images as a start. I understand that the &lt;code&gt;pvm2raw&lt;/code&gt; part gives us an 8-bit raw file so each voxel has the isovalue in the range [0-255]. So I decided map this single value on all color channels &lt;code&gt;rgba&lt;/code&gt; when taking a sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am taking the datasets from &lt;a href=&quot;http://schorsch.efi.fh-nuernberg.de/data/volume/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. &lt;strong&gt;You can see my Renderer's result in &lt;a href=&quot;https://www.reddit.com/r/GraphicsProgramming/comments/chntyk/help_volume_rendering_ray_marching_not_giving/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; video&lt;/strong&gt; (check the end of my post and sorry for not providing a direct link as I already uploaded on my reddit post)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the lobster dataset stretches when viewed from the side. My first guess was that I wasn't accounting for the aspect ratio correctly. I have tried scaling the Bounding box to account for the aspect ratio, then adjusting the stepsize according to that. I've also tried to ignore aspect ratio altogether. Both give similar images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried rendering more datasets like &quot;Knee&quot;, &quot;Bruce's head&quot;, &quot;DTI Scan&quot;, etc but those didn't even gave an image. There was just random noise everywhere. Here's an example of &quot;Bruce's head&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EXyYg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EXyYg.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This happens with both uniform and non-uniform datasets. If some datasets are getting rendered correctly like the &quot;Foot&quot; in my video, this should mean it's more a with that specific dataset itself rather the core algorithm. Nonetheless the link to the code is provided If anybody can point out some mistakes I'd be grateful.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;The link to the Compute shader is &lt;a href=&quot;https://github.com/gallickgunner/Volume-Renderer/blob/master/VolumeRenderer.cs&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. Main functions are &lt;code&gt;rayMarchVolume&lt;/code&gt;. I didn't scale the root bounding box to the dimensions of the volume, it's normalized &lt;code&gt;(0-1)&lt;/code&gt;, accounted for the aspect ratio &lt;code&gt;(0, ar)&lt;/code&gt; and adjusted so it's in the center &lt;code&gt;(-ar/2, ar/2)&lt;/code&gt;. The function &lt;code&gt;cartesianToTextureCoord(vec4 point)&lt;/code&gt; accounts for this fact and returns a texture coord in the range 0-1&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- If you are hesitating to post an answer here since it's only a suggestion, you can post on Reddit, then when the problem is solved you can post your answer here&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;:- I've provided a release to this project on github. If anybody is willing to help me with this, he can download the release and run the program. Since the algorithm is based entirely inside the compute shader you can change the file easily and test your findings on the spot. Thanks.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-09-25T06:37:23.400" LastActivityDate="2019-11-18T10:12:41.393" Title="Volume Rendering - Dataset not rendered correctly" Tags="&lt;raymarching&gt;&lt;volume-rendering&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8991" PostTypeId="2" ParentId="8979" CreationDate="2019-07-10T03:02:06.040" Score="1" Body="&lt;p&gt;Turns out it had to do with the V vector working differently in deferred rendering than it does in forward rendering, something that I overlooked and seems obvious now. Specifically, I passed the view direction calculated in the camera class to the lighting pass fragment shader then negated it like so &lt;code&gt;vec3 V = normalize(-(cameraPosition - v_pos));&lt;/code&gt;. Things seems to be working well now!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YphtI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YphtI.jpg&quot; alt=&quot;Fixed lighting helmet&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10886" LastEditorUserId="10886" LastEditDate="2019-07-13T13:22:36.377" LastActivityDate="2019-07-13T13:22:36.377" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8992" PostTypeId="1" CreationDate="2019-07-10T11:50:02.873" Score="0" ViewCount="27" Body="&lt;p&gt;I have a mesh that records some integer information for its vertices. I expect this information to be quite sparse, with possible large variations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How could I visualize this on a colorscheme (e.g. green to red)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can set the colors of the vertices according to their value and simply linearly interpolate the color along the face, but it might be the case where I have one point of large value in a dense region of the mesh, and that won't get rendered (or it would be a very small red point in a green region). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was thinking of a Gaussian smoothing over those values, but no idea how to apply this on a mesh.&lt;/p&gt;&#xA;" OwnerUserId="6647" LastActivityDate="2019-07-10T11:50:02.873" Title="Visualize a mesh with sparse vertex counts" Tags="&lt;texture&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8993" PostTypeId="1" AcceptedAnswerId="9471" CreationDate="2019-07-10T20:21:53.843" Score="2" ViewCount="106" Body="&lt;p&gt;I'm trying to implement a spectral path tracer and comparing results from my program with renders of the same scene done with &lt;code&gt;pbrt&lt;/code&gt; and &lt;code&gt;mitsuba&lt;/code&gt;. The scene is just some spheres in a box with one point light. All the surfaces have simple Lambertian BRDFs. The light has &quot;uniform&quot; spectral intensity (i.e., every wavelength has same power as others), same holds for surface reflectances. When I try to render the &lt;a href=&quot;https://gist.github.com/dmikis/3c66718d27fa672219d618a96c95f7ff#file-mitsuba-xml&quot; rel=&quot;nofollow noreferrer&quot;&gt;scene&lt;/a&gt; in &lt;code&gt;mitsuba&lt;/code&gt; I get a &quot;grayscale&quot; image, as expected:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xxBsY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xxBsY.png&quot; alt=&quot;Mitsuba render&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if &lt;code&gt;pbrt&lt;/code&gt;'s used to render the &lt;a href=&quot;https://gist.github.com/dmikis/3c66718d27fa672219d618a96c95f7ff#file-pbrt-pbrt&quot; rel=&quot;nofollow noreferrer&quot;&gt;same scene&lt;/a&gt;, result image has a reddish tint:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XhqUA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XhqUA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With my program I get similar result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/u8SyF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u8SyF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some digging through source code, I believe difference lies in &lt;code&gt;mitsuba&lt;/code&gt; &lt;a href=&quot;https://github.com/mitsuba-renderer/mitsuba/blob/master/src/librender/scenehandler.cpp#L592&quot; rel=&quot;nofollow noreferrer&quot;&gt;multiplying&lt;/a&gt; spectral intensities by D65 spectrum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it reasonable to expect the image of the described scene to be &quot;in grayscale&quot;? If so, do light intensity spectra indeed are required to be multiplied by D65 spectrum? Again, if so, why &lt;code&gt;pbrt&lt;/code&gt; doesn't do it?&lt;/p&gt;&#xA;" OwnerUserId="2960" LastActivityDate="2020-02-06T06:01:35.180" Title="Reddish tint with spectral renderer" Tags="&lt;raytracing&gt;&lt;color&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8994" PostTypeId="2" ParentId="5693" CreationDate="2019-07-10T20:23:22.760" Score="4" Body="&lt;p&gt;The CT5 was designed before 1981. I started working at E&amp;amp;S in May 1981. The CT5 was fully designed by then and 3 had been built. All 3 were still at E&amp;amp;S and hadn't shipped yet when I started. Two of them were on the test floor and the third was the engineering prototype that was later sold. The prototype was in the &quot;snake room&quot;, so called because of all the black power cords hanging from the ceiling. I also remember seeing the prototype in the snake room when I made a recruiting visit to E&amp;amp;S in early January 1981. So, the prototype, at least, was up and running before 1981.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first two CT5 systems were CH-46 helicopter simulators and the first one went to Cherry Point NAS. I don't think it shipped in 1981 as I remember it being there on the test floor for about a year after I joined the company. So, it probably shipped in 1982. As I recall, the two systems built after the CH-46 systems were AV8B Harrier jet simulators.&lt;/p&gt;&#xA;" OwnerUserId="10903" LastActivityDate="2019-07-10T20:23:22.760" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8995" PostTypeId="1" CreationDate="2019-07-11T13:40:41.843" Score="2" ViewCount="53" Body="&lt;p&gt;Look at this vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout(location = 0) in vec3 inPos;&#xA;&#xA;out gl_PerVertex {&#xA;    vec4 gl_Position;&#xA;};&#xA;&#xA;&#xA;layout (std430, binding = 1) buffer depth_range_t {&#xA;    int min;&#xA;    int max;&#xA;} depth_range;&#xA;&#xA;vec3 project(vec4 pt)&#xA;{&#xA;// somehow projects to (camera_x, camera_y, distance_to_camera)&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;    vec4 translated = ubo.worldToCamera * vec4(inPos.xyz, 1.0);&#xA;    vec3 projected = project(vec4(inPos.xyz, 1.0));&#xA;&#xA;    atomicMin(depth_range.min, int(projected.z));&#xA;    atomicMax(depth_range.max, int(projected.z));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you see, it uses two atomic operations, which occur to be embarrassingly slow. Using compute shaders I'd be able to utilize hierarchical architecture of a GPU by atomic operations on shared memory, but this in turn, as I see, would introduce hassle with separate writable buffer for vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is there any way to leverage device caches directly in vertex shader?&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm especially interested to find if it's possible using Vulkan API (maybe, SPIR-V tricks?), but would also appreciate any information about possible solutions using other popluar graphics API. &lt;/p&gt;&#xA;" OwnerUserId="10806" LastEditorUserId="10806" LastEditDate="2019-07-11T15:13:30.213" LastActivityDate="2019-07-11T15:13:30.213" Title="Communication between vertex shader executions" Tags="&lt;glsl&gt;&lt;vulkan&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="8996" PostTypeId="1" CreationDate="2019-07-11T13:53:47.120" Score="2" ViewCount="132" Body="&lt;p&gt;I'm learning light probes used for dynamic global illumination. I have a question regarding the placement of light probes, as based on most of the pictures I have seen, they seem to be placed uniformly in a grid. Is that a reasonable way for placement? I feel that more should be placed in corners than in the middle of an area.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is there any research on light probe placement that minimize the overall data needed for rendering?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;this GDC talk &lt;a href=&quot;http://twvideo01.ubm-us.net/o1/vault/gdc2012/slides/Programming%20Track/Cupisz_Robert_Light_Probe_Interpolation.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://twvideo01.ubm-us.net/o1/vault/gdc2012/slides/Programming%20Track/Cupisz_Robert_Light_Probe_Interpolation.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;mentioned irregular placement on tetrahedrons and how to do interpolation. but it doesn't seem to say much about placement itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;this paper &lt;a href=&quot;http://melancholytree.com/thesis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://melancholytree.com/thesis.pdf&lt;/a&gt; mentioned that only one probe is needed in a convex shape, but I don't seem to see people do this, is it because this is only for static global illumination without moving objects?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;what's the the latest development in light probe placement?&lt;/p&gt;&#xA;" OwnerUserId="10906" LastActivityDate="2019-12-10T14:03:00.530" Title="light probe (for global illumination) placement techniques?" Tags="&lt;rendering&gt;&lt;real-time&gt;&lt;global-illumination&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8997" PostTypeId="1" CreationDate="2019-07-12T14:03:18.680" Score="3" ViewCount="25" Body="&lt;p&gt;I have an experimental workflow that involves very finely subdivided meshes, above the 2 GB limit where signed 32-bit integers stop working, which often causes problems for various tools. I would need my users to be able to handle such mesh files. How big a problem will this be? Do commonplace mesh editing and DCC tools (commercial and free) have trouble with files with more than 2 GB size, or more than 2^31 vertices? I'd imagine at least movie industry tools would be fine with this kind of size, because they store a lot of intermediate files that may have been generated from displacement maps or by marching-cubes on volumes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not interested in problems caused by 32-bit OSes or 32-bit installs of tools: my product only supports 64-bit, so it's OK for me to just tell people to use the 64-bit versions of other tools if that's sufficient. But even with this advice, is my large-file-based workflow a non-starter (because users will keep having problems), is it a manageable problem, or is it not a problem at all?&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-07-12T14:03:18.680" Title="What expectations should I have of large (&gt; 2 GB) file support in common mesh workflow tools?" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="8998" PostTypeId="2" ParentId="8972" CreationDate="2019-07-13T10:12:35.283" Score="1" Body="&lt;p&gt;After some research i think i have final answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;General fog equation looks something like this:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ L(t)=L_p\color{red}{T(t)} + \int_0^t\color{blue}{T(x)}\color{green}{\sigma(x)L(x)}dx $$&lt;/span&gt;&#xA;Transmittance defined as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$T(x)=e^{-\int_0^x\sigma(x) dx}$$&lt;/span&gt;&#xA;With const &lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt; become&#xA;&lt;span class=&quot;math-container&quot;&gt;$$T(x)=e^{-\sigma x}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So color that will be visible is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Visible percent &lt;span class=&quot;math-container&quot;&gt;$\color{red}{T(t)}$&lt;/span&gt; of pixel color &lt;span class=&quot;math-container&quot;&gt;$L_p$&lt;/span&gt;, plus scattering probability &lt;span class=&quot;math-container&quot;&gt;$\color{green}{\sigma(x)L(x)}$&lt;/span&gt; multiplied by visible percent &lt;span class=&quot;math-container&quot;&gt;$\color{blue}{T(x)}$&lt;/span&gt; at distance &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; integrated on ray.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dgnqR.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dgnqR.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With two or more fogs we get multiple scatterings so equations become:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$T(x)=e^{-\int_0^x\sum_0^n\sigma_i(x)dx} = e^{-x\sum_0^n\sigma_i}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L(t)=L_p\color{red}{T(t)} + \int_0^t\color{blue}{T(x)}\sum_0^n\color{green}{\sigma_i(x)L_i(x)}dx=L_p\color{red}{T(t)} + \sum_0^n\color{green}{\sigma_iL_i}\int_0^t\color{blue}{T(x)}dx$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All assuming that &lt;span class=&quot;math-container&quot;&gt;$\sigma_i$&lt;/span&gt; and fog color &lt;span class=&quot;math-container&quot;&gt;$L(x)$&lt;/span&gt; are constant across ray.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The final equation for two fogs, after resolving &lt;span class=&quot;math-container&quot;&gt;$\int_0^t\color{blue}{T(x)}dx$&lt;/span&gt; will become.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L(x)=L_p\color{red}{T(t)} + (\color{green}{\sigma_0L_0 + \sigma_1L_1})\color{blue}{\frac{1-T(t)}{\sigma_0+\sigma_1}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's the same equation as in &lt;a href=&quot;https://graphics.pixar.com/library/DeepCompositing/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Deep Compositing&lt;/a&gt;. After combining it with Lie group/algebra it is possible to integrate only parts of fogs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course this integration isn't 100% correct if you have more complicated fog with not constant density etc.&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2019-07-13T10:12:35.283" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="8999" PostTypeId="2" ParentId="8996" CreationDate="2019-07-13T11:50:45.990" Score="2" Body="&lt;p&gt;Looking for answer for similar question, I found that work: &lt;a href=&quot;http://www.cse.chalmers.se/~uffe/xjobb/bowald_final_master_thesis_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.cse.chalmers.se/~uffe/xjobb/bowald_final_master_thesis_v2.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is based on automatic grid placement which depends on scene voxelization. Inspired by this I developed similar technique:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;First scene is voxelized with small voxel size (binary voxelization for memory saving)&lt;/li&gt;&#xA;&lt;li&gt;Result is downsampled to desired grid size (size of each cube with eight probes on each corner)&lt;/li&gt;&#xA;&lt;li&gt;Based on result - data structures are prepared&lt;/li&gt;&#xA;&lt;li&gt;Empty areas are optionally computed - cubes size can be bigger to save memory of volumes and probes buffers but it must be always multiplication of smallest cube size to fit in the grid&lt;/li&gt;&#xA;&lt;li&gt;Lighting for each probe is precomputed&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Data structures are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Volume map buffer - mapping world position to volume index&lt;/li&gt;&#xA;&lt;li&gt;Volumes buffer - each is array of eight probe indices&lt;/li&gt;&#xA;&lt;li&gt;Probes buffer - SH data of each probe&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;This way performance is constant, fast and independent of quality (size of cube) unlike in tetrahedra grid searching algorithm.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However I don't know if there is more recent advancement in that field. You might check &lt;a href=&quot;http://jcgt.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://jcgt.org&lt;/a&gt; if there are any new research papers. &lt;/p&gt;&#xA;" OwnerUserId="4958" LastActivityDate="2019-07-13T11:50:45.990" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9001" PostTypeId="1" CreationDate="2019-07-14T17:06:42.633" Score="1" ViewCount="28" Body="&lt;p&gt;I am trying to implement a custom add-on for Mitsuba, but when I use the Heightfield I have defined in another function call(WaveBrdfAccel) in main.cpp it compiles without any problems but when I try to render the scene I get an error that says:&#xA; &lt;strong&gt;undefined symbol: _ZTVN7mitsuba11HeightfieldE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there something special I need to do to implement this properly in Mitsuba's frameworks?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying this on Mitsuba version 0.5.0 (Linux, 64 bit).&#xA;If I remove the heightfield parameter from the WaveBrdfAccel declaration then This error does not occur which leads me to believe​ there is something wrong in the way I am calling it but I cannot figure it out.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my main.cpp file :&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;GPTWorkResultTest *spec;&#xA;                spec-&amp;gt;SpectrumInit(); &#xA;&#xA;            GPTWorkResultEXR heightfieldImage(heightfieldFilename);&#xA;            Heightfield heightfield(&amp;amp;heightfieldImage, texelWidth, vertScale);&#xA;            Query query;&#xA;                query.mu_p = Vector2(mu_x, mu_y);&#xA;                query.sigma_p = sigma_p;&#xA;                query.lambda = lambda;&#xA;&#xA;            WaveBrdfAccel waveBrdfAccel(&amp;amp;heightfield, diffModel); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the Heightfield and WaveBrdfAccel class both in waveBrdf.h:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;class Heightfield {&#xA;public:&#xA;     explicit Heightfield() {}&#xA;     Heightfield(GPTWorkResultEXR *heightfieldImage, Float texelWidth = 1.0, Float vertScale = 1.0)&#xA;        : mHeightfieldImage(heightfieldImage), mTexelWidth(texelWidth), mVertScale(vertScale) {}&#xA;    GaborKernel g(int i, int j, Float F, Float lambda);&#xA;&#xA;    Vector2 n(Float i, Float j);&#xA;public:&#xA;    GPTWorkResultEXR *mHeightfieldImage;&#xA;    Float mTexelWidth;      // in microns.&#xA;    Float mVertScale;&#xA;    MTS_DECLARE_CLASS()&#xA;&#xA;};&#xA;&#xA;class WaveBrdfAccel {&#xA;public:&#xA;&#xA;explicit WaveBrdfAccel(Heightfield *heightfield, string method);&#xA;&#xA; comp queryIntegral(const Query &amp;amp;query, int layer, int xIndex, int yIndex);&#xA;&#xA;&#xA;MTS_DECLARE_CLASS()&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and finally the inclusion in waveBrdf.cpp:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;WaveBrdfAccel::WaveBrdfAccel(Heightfield *heightfield, string method) {&#xA;cout &amp;lt;&amp;lt; &quot;IT IS ACTUALLY running wave&quot; &amp;lt;&amp;lt; endl;&#xA;}&#xA;&#xA;&#xA;MTS_IMPLEMENT_CLASS(WaveBrdfAccel, false, WorkResult)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;I am not sure exactly why this is the case but I managed to fix it by simply separating the class definitions into sperate header files. If anyone knows why this worked would love to know!&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="10913" LastEditorUserId="10913" LastEditDate="2019-07-19T03:39:49.873" LastActivityDate="2019-07-19T03:39:49.873" Title="Mitsuba builds targets with scons but throws &quot;undefined symbol&quot; error when trying to render scene" Tags="&lt;rendering&gt;&lt;c++&gt;&lt;microfacet&gt;&lt;height-field&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9002" PostTypeId="1" CreationDate="2019-07-14T22:57:06.833" Score="0" ViewCount="87" Body="&lt;p&gt;I have written a really basic ray tracer. It generates primary rays and sets the colour of the pixel to the colour of the object that I have set myself. The code for which can be seen below.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;from PIL import Image, ImageDraw&#xA;from Sphere import Sphere&#xA;import numpy as np&#xA;&#xA;imgx = 300&#xA;imgy = 300&#xA;&#xA;img = Image.new('RGB', (imgx, imgy), color = 'black')&#xA;pixelMap = img.load()&#xA;&#xA;#Place a Sphere in centre, distance 10 away.&#xA;#Sphere has a constructor (centre, colour, radius)&#xA;sphere1 = Sphere(np.array([0,0,-1]), (255, 255, 255), 100)&#xA;#sphere2 = Sphere(np.array([300,0,-1]), (255, 0, 0), 100)&#xA;&#xA;objects = [sphere1]&#xA;&#xA;for i in range(img.size[0]):&#xA;    for j in range(img.size[1]):&#xA;&#xA;        u = -imgx/2 + (imgx)*(i+0.5)/imgx&#xA;        v = -imgy/2 + (imgy)*(j+0.5)/imgy&#xA;&#xA;        rayDirection = -1*np.array([0,0,1]) + u*np.array([1,0,0]) + v*np.array([0,1,0])&#xA;        rayOrigin = np.array([0,0,0])&#xA;        #p(t) = rayorigin + t*raydirect&#xA;&#xA;        #Sphere intersection&#xA;        for obj in objects:     &#xA;            a = np.dot(rayDirection, rayDirection)&#xA;            b = np.dot(2*rayDirection, (rayOrigin - obj.centre))&#xA;            c = np.dot((rayOrigin - obj.centre), (rayOrigin - obj.centre)) - obj.radius**2&#xA;&#xA;            eminc = rayOrigin - obj.centre&#xA;&#xA;            discrim = (np.dot(rayDirection, eminc))**2 - ((np.dot(rayDirection, rayDirection))*(np.dot(eminc, eminc))-obj.radius**2)&#xA;            if(discrim &amp;gt;= 0):&#xA;                print(&quot;intersect&quot;)&#xA;                pixelMap[i,j] = obj.colour&#xA;            else:&#xA;                pixelMap[i,j] = (0, 0,0)&#xA;&#xA;img.save('output.png')&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cDdocs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cDdocs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It works in the sense that when I run the code, I get an image of a white circle. My issue arises when I change the centre of the sphere. Instead of shifting to the left, right, up or down. I get a skewed image. Seen below when I set the Sphere to have centre &lt;code&gt;np.array([3,0,-1])&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KqsPls.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KqsPls.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe the problem may be to do with the translation between world co-ordinates and camera co-ordinates? However, I am not sure what transformation matrix to use or how to use it. For what it's worth, my code takes ideas from Fundamentals of Computer Graphics by Pete Shirley and Steve Marschner.&lt;/p&gt;&#xA;" OwnerUserId="10912" LastActivityDate="2019-07-14T22:57:06.833" Title="Moving a sphere in a basic ray tracer" Tags="&lt;raytracing&gt;&lt;transformations&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9005" PostTypeId="1" AcceptedAnswerId="9006" CreationDate="2019-07-16T16:12:57.060" Score="3" ViewCount="226" Body="&lt;p&gt;I've been going though Peter Shirley's beginner raytracing books. Upon building the Cornell box and rendering an image, I get a much darker / dimmer image than expected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mP9YW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mP9YW.png&quot; alt=&quot;Picture one&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The color values are normalized (in the range [0.0f, 1.0f]). The author of the books has stated that for a brighter result, I need to gamma correct the values (calculating the nth root of the color values)The  above image has a gamma correction of 2 (square root). This is the same value that the author uses, but his result is much brighter &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DbVGq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DbVGq.png&quot; alt=&quot;picture two&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried making the gamma correction larger (increasing n) and after setting n=4 (each color gets set to the (1/4)th exponent), I get this image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/thqjM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/thqjM.png&quot; alt=&quot;picture three&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are obvious artifacts, like a lack of highlights near the light, and the over-saturated small number of pixels where a wall is close to the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way a pixel's color is calculated is like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for(int j = height - 1; j &amp;gt;= 0; j--)&#xA;{&#xA;    for(int i = 0; i &amp;lt; width; i++)&#xA;    {&#xA;        vec3 color(0.0f, 0.0f, 0.0f);&#xA;        for(int s = 0; s &amp;lt; samplesPerPixel; s++)&#xA;        {&#xA;            float u = ((float)i + RandomNumber(0.0f, 1.0f)) / width;&#xA;            float v = ((float)j + RandomNumber(0.0f, 1.0f)) / height;&#xA;&#xA;            ray r = cam.CastRay(u, v);&#xA;            color += Color(r, list, depth);&#xA;        }&#xA;&#xA;        color /= (float)samplesPerPixel;&#xA;        color = vec3(pow(color.x, gammaCorrection), pow(color.y, gammaCorrection), pow(color.z, gammaCorrection));&#xA;&#xA;        int ir = Map(0.0f, 1.0f, 0.0f, 255.0f, color.x);&#xA;        int ig = Map(0.0f, 1.0f, 0.0f, 255.0f, color.y);&#xA;        int ib = Map(0.0f, 1.0f, 0.0f, 255.0f, color.z);&#xA;&#xA;        output &amp;lt;&amp;lt; ir &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; ig &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; ib &amp;lt;&amp;lt; &quot;\n&quot;;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the resulting color values for each channel (red, green and blue) is in the range of [0, 255].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a problem with how I calculate a pixel's color based on all samples? My &lt;code&gt;color&lt;/code&gt; function is pretty much the same as it is in the book &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 Color(const ray&amp;amp; r, HitableList&amp;amp; hitables, int depth)&#xA;{&#xA;    float tmin = 0.001f;&#xA;    float tmax = 10000.0f; &#xA;&#xA;    HitData data;&#xA;&#xA;    // If the ray hit something&#xA;    if(hitables.Hit(r, tmin, tmax, data))&#xA;    {&#xA;        ray scattered;&#xA;        vec3 attenuation;&#xA;&#xA;        // If the material is a light, store its emitted color&#xA;        vec3 emitted = data.mat-&amp;gt;Emitted(data.u, data.v, data.point);&#xA;&#xA;        // If the number of bounces is below 50 and the ray gets scattered into a random direction&#xA;        if(depth &amp;lt; 50 &amp;amp;&amp;amp; data.mat-&amp;gt;Scatter(r, data, attenuation, scattered))&#xA;            return emitted + attenuation * Color(scattered, hitables, depth + 1);&#xA;        else&#xA;            return emitted;&#xA;    } else&#xA;        return vec3(0.0, 0.0f, 0.0f);&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Has anyone come across a similar issue before?&lt;/p&gt;&#xA;" OwnerUserId="9391" LastActivityDate="2019-07-16T17:55:38.327" Title="Offline path tracer produces a darker image than expected" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;gamma&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9006" PostTypeId="2" ParentId="9005" CreationDate="2019-07-16T17:55:38.327" Score="4" Body="&lt;p&gt;I have found the issue. The gamma correction was the correct value, the same as in the book (1/2), but the light source had the brightness of 1.0f. The book had set the light's brightness to 18.0f for all color channels. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This would introduce color overflow if left at that, and the very light areas (above 1.0f, and subsequently when converted, outside the range [0, 255]) would have wrong colors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To fix this clamp the the pixel's color values.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Go through all samples and calculate pixel color.&lt;/li&gt;&#xA;&lt;li&gt;Divide the color by number of samples&lt;/li&gt;&#xA;&lt;li&gt;Apply gamma correction&lt;/li&gt;&#xA;&lt;li&gt;Clamp colors in range [0, 1]&lt;/li&gt;&#xA;&lt;li&gt;Finally, convert values to range [0, 255]&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2VAj3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2VAj3.png&quot; alt=&quot;Result after fix&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I will accept this answer as a solution in 2 days because StackExchange doesn't let me to do it now.)&lt;/p&gt;&#xA;" OwnerUserId="9391" LastActivityDate="2019-07-16T17:55:38.327" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9007" PostTypeId="1" CreationDate="2019-07-16T23:37:24.830" Score="1" ViewCount="48" Body="&lt;p&gt;I've read about measured BDRFs and models like cook-torrance have parameters that need to be set. It isn't hard to imagine that these parameters and the measured properties would vary from point to point on a lot of surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do artists or scans ever give us textures for these kinds of values? Where could I find or purchase models and textures for these kinds of things? What representations would textures for these models typically have? If these are hard to find is it simply because artists have yet to start using these models?&lt;/p&gt;&#xA;" OwnerUserId="3385" LastActivityDate="2019-07-16T23:37:24.830" Title="Where to find BRDF textures" Tags="&lt;texture&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;model&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9008" PostTypeId="1" CreationDate="2019-07-17T13:30:50.970" Score="1" ViewCount="99" Body="&lt;p&gt;Does anyone know what applications has the computation of a parallel transport on a mesh?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm talking about methods such as &lt;a href=&quot;https://www.cs.cmu.edu/~kmcrane/Projects/VectorHeatMethod/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2019-09-11T17:44:21.307" Title="Application of parallel transport in computer graphics and mesh processing" Tags="&lt;mesh&gt;&lt;vectors&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9010" PostTypeId="1" CreationDate="2019-07-17T21:35:47.920" Score="2" ViewCount="55" Body="&lt;p&gt;I have a question about Nvidia Flex or any particle based simulation in general:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The particles are created by sampling the mesh, which can result in fewer particles than there are vertices in the mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After computing the new particle positions, how are the vertex positions updated based on the particle positions? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are they simply projected onto a point within the particle?&#xA;And is the mesh fully updated or is it just rendered in a modified way?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry for these unprofessional questions.&#xA;I appreciate any help.&lt;/p&gt;&#xA;" OwnerUserId="10744" LastEditorUserId="11003" LastEditDate="2019-08-05T10:41:26.403" LastActivityDate="2019-08-05T10:41:26.403" Title="Vertex positions from particle position" Tags="&lt;geometry&gt;&lt;interpolation&gt;&lt;simulation&gt;&lt;particles&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9011" PostTypeId="2" ParentId="6029" CreationDate="2019-07-18T11:34:56.477" Score="0" Body="&lt;p&gt;The question asks about branch avoidance, so doing that while retaining comparison is still fair play(*).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Checking if some scalar or vector equals its &lt;code&gt;clamp&lt;/code&gt;ed version is a terse, intuitive option:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Combine &lt;code&gt;float(clampN(d, dMin, dMax) == d)&lt;/code&gt;, which yields 0.0 if false or 1.0 if true, with whatever way you use this resulting value, for example, &lt;code&gt;mix&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;d&lt;/code&gt; can be scalar or any vector, while &lt;code&gt;dMin&lt;/code&gt;/&lt;code&gt;dMax&lt;/code&gt; are either scalars, or whatever &lt;code&gt;d&lt;/code&gt; is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &lt;code&gt;&amp;lt;&lt;/code&gt; needs to be distinguished from &lt;code&gt;&amp;lt;=&lt;/code&gt;, it gets a bit more tedious as additional comparisons are needed for the min/max values or subtracting the value from an extremum and getting a &lt;code&gt;sign&lt;/code&gt;, unless one can safely use some other approach such as introducing an epsilon value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For either case, performance may differ (or match) other solutions; in part, because...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(*) I'm not aware of anything that'd prevent the shader compiler from introducing its own branching if it feels like so; conversely, nothing prevents the shader compiler from converting branching (if) into single-track code, if it can tackle the data flow to the extent to be certain that the results are the same. IIRC the latter is actually done for at least simple cases.&lt;/p&gt;&#xA;" OwnerUserId="10904" LastActivityDate="2019-07-18T11:34:56.477" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9012" PostTypeId="1" AcceptedAnswerId="9013" CreationDate="2019-07-18T17:19:25.847" Score="0" ViewCount="73" Body="&lt;p&gt;I am trying to simulate the actual response of a camera given some object that is reflecting light.  I've written a ray tracer, and have a BRDF that I need to use, and I have a camera sensitivity in terms of signal/Watts.  But I am confused by one (rather important) detail:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each ray coming out of the camera has some solid angle associated with it (this part I've already figured out).  So each ray should then have a &quot;Radiance&quot; value associated with it (as radiance has units of W/(sr*m^2)).  That way each ray would just multiply its solid angle by its radiance value, and you'd get an &quot;Irradiance&quot; value of W/m^2.  However, I am unsure how to actually calculate this initial radiance value for each ray.  The reason I am confused is because this seems to be backwards from what the BRDF is giving me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A BRDF gives me the radiance leaving the surface in the direction of the camera, meaning the vertex of the solid angle is at the point of intersection.  The solid angle for the ray however is defined flipped, with the vertex of the solid angle at the camera itself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I bridge this gap?  My idea is that is that if I can actually calculate the radiance for each ray, then I can simply multiple the radiance of each ray by its corresponding solid angle to get an irradiance value, then apply the inverse square law, and finally add up the irradiance for each ray per pixel and divide by the area of the pixel to get the wattage it receives.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I am very lost as to how to calculate the radiance for each ray given that the only calculations I'm familiar with (the BRDF) returns a radiance value for a solid angle in the &quot;wrong direction&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I misunderstanding what is going on?  Am I approaching this incorrectly?  Any help would be really appreciated!&lt;/p&gt;&#xA;" OwnerUserId="10932" LastActivityDate="2019-07-18T17:59:35.397" Title="Physically realistic received irradiance values given some BRDF?" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9013" PostTypeId="2" ParentId="9012" CreationDate="2019-07-18T17:34:17.157" Score="0" Body="&lt;p&gt;I didn't get this part:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;That way each ray would just multiply its solid angle by its radiance&#xA;  value, and you'd get an &quot;Irradiance&quot; value of W/m^2.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'll try to explain how the whole thing works though. You have a light source, it emits light rays. Those light rays bounce around the scene and eventually end up at your camera film. So at the end of the day you have multiple rays hitting the film surface and the radiance of those gets multiplied with the sensitivity function. For efficiency reasons you usually start backwards - from the camera. But if you work with symmetric BRDFs this should not matter. So what arrives at your film is radiance, you multiply that radiance with the sensitivity function and integrate within a &quot;film pixel&quot; to get the result in terms of your screen pixel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: To clarify what I meant by integrated out:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you have radiance which is a measure of W/(sr * m^2), you can integrate out sr or m^2 like so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$E(x) = \int_{\Omega}{L(x,\omega)\cos\theta\,d\omega}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From where you get irradiance at a point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, which gives you the energy arriving from all directions at point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; (W/m^2). Now you can go further and find out the energy that arrives at some surface with area A, by integrating over all points on the surface:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\Phi = \int_{A}{E(x)\,d\mu(x)} = \int_{A}\int_{\Omega}{L(x,\omega)\cos\theta\,d\omega\,d\mu(x)}$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-07-18T17:59:35.397" LastActivityDate="2019-07-18T17:59:35.397" CommentCount="14" ContentLicense="CC BY-SA 4.0" />
  <row Id="9014" PostTypeId="2" ParentId="8130" CreationDate="2019-07-18T17:39:23.577" Score="1" Body="&lt;p&gt;Exactly the same happened to me as it did to you: I was reading the book, and quite following everything that I was reading, until that bit with the defocus blur. My issue was very specifically with the following bits:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;lower_left_corner: look_from - half_width*focus_dist*u - half_height*focus_dist*v - focus_dist*w,&#xA;horizontal: 2.0*half_width*focus_dist*u,&#xA;vertical: 2.0*half_height*focus_dist*v&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It was very clear to me that we should multiply &lt;code&gt;-w&lt;/code&gt; by &lt;code&gt;focus_dist&lt;/code&gt;, &lt;code&gt;-w&lt;/code&gt; being the vector pointing towards the subject. But I couldn't figure out why we should multiply the &lt;code&gt;u&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt; vectors by &lt;code&gt;focus_dist&lt;/code&gt; too. That made no sense to me. Was it about the dimensions of the focus plane or something? I couldn't make sense of it. But removing it made the generated image wrong, so it was really needed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The insight I had was 'where do we get &lt;code&gt;half_width&lt;/code&gt; from?' And the answer is...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let half_height = tan(theta/2.0);&#xA;let half_width = aspect * half_height;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And NOW everything makes sense! That is obviously wrong, as the code computing &lt;code&gt;half_height&lt;/code&gt; assumes a distance of 1.0 to the target! Therefore &lt;code&gt;half_height&lt;/code&gt; was miscalculated in the book, and the author compensated a little later by multiplying by &lt;code&gt;focus_dist&lt;/code&gt; when using &lt;code&gt;half_width&lt;/code&gt;...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Therefore the correct code (despite the fact that the original code worked 100%) would be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let half_height = tan(theta/2.0) * focus_dist;&#xA;let half_width = aspect * half_height;&#xA;// ...&#xA;lower_left_corner: look_from - half_width*u - half_height*v - focus_dist*w,&#xA;horizontal: 2.0*half_width*u,&#xA;vertical: 2.0*half_height*v,&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10930" LastEditorUserId="10930" LastEditDate="2019-07-18T17:57:19.937" LastActivityDate="2019-07-18T17:57:19.937" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9015" PostTypeId="1" AcceptedAnswerId="9016" CreationDate="2019-07-19T04:30:18.740" Score="3" ViewCount="249" Body="&lt;p&gt;Path tracing seems to perform Monte Carlo integration where the space being integrated over is the space of paths (e.g. chains of rays) but the rendering equation is stated in terms of outgoing rays. Naively you would have to perform the integration at each bounce to model the rendering equation but this would take exponential time. It seems that there should be a proof that either a) integration over the space of paths is equivalent to recursive integration over the space of rays or b) sampling paths is a valid numeric technique for evaluating the rendering equation. While somewhat intuitive neither of those facts is obvious to me. Is there a proof of some such claim?&lt;/p&gt;&#xA;" OwnerUserId="3385" LastActivityDate="2019-07-19T19:14:59.497" Title="Rendering equation in terms of paths rather than directions" Tags="&lt;pathtracing&gt;&lt;monte-carlo&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9016" PostTypeId="2" ParentId="9015" CreationDate="2019-07-19T09:14:10.740" Score="7" Body="&lt;p&gt;This is a very good question. There is a common misconception that Monte Carlo, or integration is applied &quot;recursively&quot; on the rendering equation. That is not what's happening. Numerical integration methods are tailored to problems of the form:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I = \int_{\Omega}{f(x)d\mu(x)} \approx \sum_{k=0}^{N-1}w(x_k)f(x_k)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this is not the case for the rendering equation. Namely the fact that it is an equation, and the unknown radiance function &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; shows up on both sides. In order to apply numerical integration techniques (such as Monte Carlo), one has to bring the rendering equation to the above form. Fortunately this is a well studied problem. The rendering equation is a specific case of a Fredholm integral equation of the second kind. If one can show that the scattering operator in that equation is a contraction &lt;span class=&quot;math-container&quot;&gt;$||T||&amp;lt;1$&lt;/span&gt; (which holds if brdfs are energy conserving, there are cases where this is not required but that goes outside the scope of my answer), then we may perform a Neumann expansion (&lt;a href=&quot;https://en.wikipedia.org/wiki/Liouville%E2%80%93Neumann_series&quot; rel=&quot;noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Liouville%E2%80%93Neumann_series&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The commonly used form of the rendering equation is the solid angle formulation (here &lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt; is the solid angle measure, &lt;span class=&quot;math-container&quot;&gt;$\sigma(\omega) = \sin\theta\,d\theta d\phi$&lt;/span&gt;):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(x,\omega_o) = L_e(x,\omega_o) + \int_{\Omega}{f(\omega_o,x,\omega_i)L_i(x,\omega_i)\cos\theta_i\,d\sigma(\omega_i)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to perform the expansion, I will rewrite this in the area formulation (here &lt;span class=&quot;math-container&quot;&gt;$\mu(x)$&lt;/span&gt; is the Lebesgue area measure):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(x_1 \rightarrow x_0) = L_e(x1 \rightarrow x_0) + \int_{M}{f(x_2 \rightarrow x_1 \rightarrow x_0)L(x_2 \rightarrow x_1)\cos\theta_{x_1}\frac{\cos\theta_{x_2}}{||x_2-x_1||^2}V(x_2,x_1)\,d\mu(x_2)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; is the set of all surface points in the scene, &lt;span class=&quot;math-container&quot;&gt;$V(x,y)$&lt;/span&gt; is the visibility function which is &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; if there is nothing between &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; otherwise. If the normals of the surfaces at point &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt; are respectively &lt;span class=&quot;math-container&quot;&gt;$N_{x_1}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$N_{x_2}$&lt;/span&gt;, then &lt;span class=&quot;math-container&quot;&gt;$\cos\theta_{x_1} = N_{x_1} \cdot \frac{x_2-x1}{||x_2-x_1||}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\cos\theta_{x_2} = N_{x_2} \cdot \frac{x_1-x2}{||x_2-x_1||}$&lt;/span&gt;. As for the radiance, &lt;span class=&quot;math-container&quot;&gt;$L(x_2 \rightarrow x_1)$&lt;/span&gt; gives the radiance arriving at &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; from the direction of &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt;. And the brdf notation relationship is: &lt;span class=&quot;math-container&quot;&gt;$f(x_2 \rightarrow x_1 \rightarrow x_0) = f(x_1 \rightarrow x_0, x_1, x_1 \rightarrow x_2)$&lt;/span&gt; (that means &lt;span class=&quot;math-container&quot;&gt;$\omega_o = x_1 \rightarrow x_0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\omega_i = x_1 \rightarrow x_2$&lt;/span&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will rewrite the above for simplicity and conciseness as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(x_1 \rightarrow x_0) = L_e(x1 \rightarrow x_0) + L_r(x_1 \rightarrow x_0)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us now split the incoming radiance into direct illumination arriving at &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; and indirect (at least one bounce) illumination. The direct illumination is obviously due to direct light source rays arriving at &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(x_1 \rightarrow x_0) = L_e(x1 \rightarrow x_0) + \int_{M}{f(x_2 \rightarrow x_1 \rightarrow x_0)(L_e(x_2 \rightarrow x_1) + L_r(x_2 \rightarrow x_1))\cos\theta_{x_1}\frac{\cos\theta_{x_2}}{||x_2-x_1||^2}V(x_2,x_1)\,d\mu(x_2)} = &#xA;L_e(x1 \rightarrow x_0) + \int_{M}{f(x_2 \rightarrow x_1 \rightarrow x_0)L_e(x_2 \rightarrow x_1)\cos\theta_{x_1}\frac{\cos\theta_{x_2}}{||x_2-x_1||^2}V(x_2,x_1)\,d\mu(x_2)} + $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_{M}f(x_2 \rightarrow x_1 \rightarrow x_0)\Bigg[\int_{M}f(x_3 \rightarrow x_2 \rightarrow x_1)L(x_3 \rightarrow x_2)\cos\theta_{x_2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\cos\theta_{x_3}}{||x_3-x_2||^2}V(x_3,x_2)\,d\mu(x_3)\Bigg]\cos\theta_{x_1}\frac{\cos\theta_{x_2}}{||x_2-x_1||^2}V(x_2,x_1)\,d\mu(x_2)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All I did here was separate the sum &lt;span class=&quot;math-container&quot;&gt;$L_e(x_2 \rightarrow x_1) + L_r(x_2 \rightarrow x_1)$&lt;/span&gt; into two integrals, and then I additionally expanded &lt;span class=&quot;math-container&quot;&gt;$L_r$&lt;/span&gt; into the corresponding integral using the recursive definition. You can expand this until infinity. For conciseness, I will rewrite the integration as an operator: &lt;span class=&quot;math-container&quot;&gt;$L_r = TL$&lt;/span&gt;. Now we can see the relationship to the Neumann expansion. Since the rendering equation can be written as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + TL$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The solution is formally given as: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(I-T)L = L_e$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = (I-T)^{-1}L_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying the Neumann expansion yields:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = \sum_{i=0}^{\infty}T^iL_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that each term of the sum is an increasingly dimensional integral. The first term is obviously just &lt;span class=&quot;math-container&quot;&gt;$L_e(x_1 \rightarrow x_0)$&lt;/span&gt;, the second term &lt;span class=&quot;math-container&quot;&gt;$TL_e$&lt;/span&gt; is the integral for &lt;span class=&quot;math-container&quot;&gt;$L_e(x_2 \rightarrow x_2)$&lt;/span&gt; that I wrote when I split &lt;span class=&quot;math-container&quot;&gt;$L_e$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$L_r$&lt;/span&gt;, and so on. What each term gives you is the energy coming from a light source after &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; bounces. The first term gives you the radiance emitted from &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; towards &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; (paths of length 0), the second term gives you the radiance that is due to direct illumination of &lt;span class=&quot;math-container&quot;&gt;$x_1$&lt;/span&gt; scattered towards &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; (paths of length 1), then you have the radiance due to lights two bounces away (paths of length 2) etc. With each bounce each new integral in the sum gains two dimensions (if we are just integrating over incoming directions). I would also like to emphasize that the integration variable &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$TL_e$&lt;/span&gt; is not the same &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt; as the one in &lt;span class=&quot;math-container&quot;&gt;$T^iL_e$&lt;/span&gt; (this means that in the example with integration, &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt; in the first integral is not the same as in the second one - they are just integration variables). Another important fact is that within each sum each path starts at the film &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; and ends at a light source (&lt;span class=&quot;math-container&quot;&gt;$L_e(x_2\rightarrow x_1)$&lt;/span&gt; is non-zero only for points &lt;span class=&quot;math-container&quot;&gt;$x_2$&lt;/span&gt; lying on light sources).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now that we have a sum of integrals, we can apply our numerical techniques to each integral to estimate the sum. An obvious optimization, is reusing the samples used to compute &lt;span class=&quot;math-container&quot;&gt;$T^iL_e$&lt;/span&gt; to compute &lt;span class=&quot;math-container&quot;&gt;$T^{i+1}L_e = T(T^iL_e)$&lt;/span&gt;. This yields a formulation where we can formally write out the sum of integrals as one integral with integration over all paths that start at the camera film and end at a light source. This also illustrates why Monte Carlo is a preferred technique: since we want to estimate an infinite dimensional integral, and Monte Carlo's convergence doesn't depend on the dimensionality unlike standard quadrature rules (there's also the point that it doesn't care about the smoothness of the integrand, but that's a double edged sword). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you may have noticed, with the path integration formulation an exponential path count growth is not required. Splitting a path into multiple new ones is a technique known as splitting. While it is beneficial for high energy paths, on average with each bounce the energy gets lower due to attenuation, so this is in most cases counterproductive. On the other hand early path termination (for low energy paths) is more often than not beneficial in terms of efficiency (that's simply cutting off the sum at some point and not computing the remaining infinitely many terms, because you deem they have a contribution that is too low), and that's where Russian roulette comes in. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of this is actually contained in Kajiya's paper on the rendering equation, even though he doesn't go into the details I went. He just refers to Rubinstein's book: &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=539488&quot; rel=&quot;noreferrer&quot;&gt;https://dl.acm.org/citation.cfm?id=539488&lt;/a&gt; (note - the first edition, later editions do not have the part he is referring to). In this book how to solve Fredholm integrals of the second kind is described (what I explained above, but more formally).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope my explanation was useful, and will continue being useful for future readers.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-07-19T19:14:59.497" LastActivityDate="2019-07-19T19:14:59.497" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9017" PostTypeId="1" AcceptedAnswerId="9019" CreationDate="2019-07-19T15:08:48.347" Score="0" ViewCount="83" Body="&lt;p&gt;I've been trying to implement a microfacet specular BRDF based on the equations in &lt;a href=&quot;https://cdn2.unrealengine.com/Resources/files/2013SiggraphPresentationsNotes-26915738.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real Shading in UE4&lt;/a&gt;, but I'm getting weird ring-shaped artifacts in the highlights of rough surfaces:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mYWcu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mYWcu.png&quot; alt=&quot;The artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the relevant pieces of the fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;float D(float NoH, float roughness) {&#xA;    float a = sqr(roughness);&#xA;    float a2 = sqr(a);&#xA;    float denom = PI * sqr(sqr(NoH) * (a2 - 1.0) + 1.0);&#xA;    return a2 / denom;&#xA;}&#xA;float G1(float NoV, float k) {&#xA;    float denom = NoV * (1.0 - k) + k;&#xA;    return NoV / denom;&#xA;}&#xA;float G(float NoL, float NoV, float roughness) {&#xA;    float k = sqr(roughness + 1) / 8.0;&#xA;    return G1(NoL, k) * G1(NoV, k);&#xA;}&#xA;float F(float VoH, float ior) {&#xA;    float f0 = sqr((1.0-ior)/(1.0+ior));&#xA;    return f0 + (1.0 - f0) * exp2((-5.55473*VoH - 6.98316) * VoH);&#xA;}&#xA;vec3 brdf(in vec3 V, in vec3 L, in vec3 N, in Material mat) {&#xA;    vec3 H = normalize(V+L);&#xA;    float NoL = dot(N, L);&#xA;    float NoV = dot(N, V);&#xA;&#xA;    float nom = D(dot(N, H), mat.roughness)&#xA;        * F(dot(V, H), mat.ior)&#xA;        * G(NoL, NoV, mat.roughness);&#xA;    float denom = 4.0 * NoL * NoV;&#xA;&#xA;    return vec3(1) * nom / denom;&#xA;}&#xA;&#xA;// ----------------------&#xA;&#xA;void main() {&#xA;    // ...&#xA;&#xA;    vec3 rd = normalize(frag_pos - camera_pos);&#xA;    Material mat = materials[mat_index];&#xA;    col = brdf(-rd, sun_dir, normal, mat);&#xA;&#xA;    // ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any idea what I'm doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="1578" LastEditorUserId="1578" LastEditDate="2019-07-19T21:39:49.163" LastActivityDate="2019-07-19T21:39:49.163" Title="Microfacet BRDF artifacts" Tags="&lt;brdf&gt;&lt;material&gt;&lt;artifacts&gt;&lt;microfacet&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9018" PostTypeId="1" CreationDate="2019-07-19T19:36:31.367" Score="0" ViewCount="29" Body="&lt;p&gt;I have finished Dennis Ritchie's C book, and I would like to create my own plotting software for enhancing my programming skill,I want sources,books or anything to reach this goal.Thanks for answers.&lt;/p&gt;&#xA;" OwnerUserId="10871" LastActivityDate="2019-07-19T19:36:31.367" Title="How can I create multivariable function plotting software" Tags="&lt;computational-geometry&gt;&lt;mathematics&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9019" PostTypeId="2" ParentId="9017" CreationDate="2019-07-19T21:39:31.090" Score="1" Body="&lt;p&gt;It turns out that the ring was happening from a negative divided by a negative, so adding &lt;code&gt;nom = max(nom, 0.0);&lt;/code&gt; fixed the problem. The new highlight, amplified:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/f6sev.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/f6sev.png&quot; alt=&quot;Correct result&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1578" LastActivityDate="2019-07-19T21:39:31.090" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9020" PostTypeId="1" AcceptedAnswerId="9021" CreationDate="2019-07-21T03:17:08.723" Score="2" ViewCount="280" Body="&lt;p&gt;Every frame I dispatch a compute shader which write data in a storage buffer. The cpu needs to readback this data and use it. I would expect this to work :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Dispatch compute shader&#xA;glDispatchCompute(x, y, z);&#xA;glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;void* data = glMapNamedBuffer(buffer, GL_READ_ONLY);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But it would introduce a sync point which I'd like to avoid. I'd like to hide the latency by reading the data written by the previous frame dispatch. If I was using textures I would have used PBOs, but I have not found a way to do this for storage buffers.&lt;/p&gt;&#xA;" OwnerUserId="8925" LastActivityDate="2019-07-21T03:33:02.410" Title="Async readback storage buffer" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9021" PostTypeId="2" ParentId="9020" CreationDate="2019-07-21T03:33:02.410" Score="5" Body="&lt;p&gt;First, that's the wrong memory barrier. The barrier is for how you intend to &lt;em&gt;use&lt;/em&gt; the memory, not how it was &lt;em&gt;written to&lt;/em&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I'd like to hide the latency by reading the data written by the previous frame dispatch.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is a general flaw in OpenGL: targeted synchronization of such memory operations is not possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Vulkan, you can be extremely specific about both execution and visibility operations. When you start the dispatch, you can stick an event after it, which you can wait on using a specific execution and memory barrier.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In OpenGL, you only really have two tools: fence sync objects and a broad memory barrier that covers &lt;em&gt;all&lt;/em&gt; prior commands which have executed. And sync objects don't actually ensure visibility. Yes, you can set a fence right after your dispatch, and spin on the CPU (doing actual work between checks of the fence). But even after the fence has completed, you can't guarantee visibility without firing off the barrier. And that barrier will affect &lt;em&gt;all memory operations&lt;/em&gt; that were submitted before the barrier was called.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So if you had two dispatch operations, and call &lt;code&gt;glMemoryBarrier&lt;/code&gt; after both of them, the barrier will wait on &lt;em&gt;all of them&lt;/em&gt;, even if you only care about waiting for the first one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The best you can really do is just delay the memory barrier call for as long as possible. But it's going to synchronize against all submitted commands when you call it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You might also try... cheating. Use a persistent/coherent mapped buffer, and use a fence sync object on the CPU &lt;em&gt;instead of&lt;/em&gt; calling the memory barrier. This is undefined behavior by the OpenGL specification, but on real systems, the fence sync should ensure execution of the operation, and the coherently-mapped buffer ought to ensure visibility.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But that doesn't mean it &lt;em&gt;will&lt;/em&gt;. So don't expect miracles.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-07-21T03:33:02.410" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9022" PostTypeId="2" ParentId="8975" CreationDate="2019-07-21T18:08:43.193" Score="1" Body="&lt;p&gt;I found the problem. By zeroing the sampler description I implicitly set LOD bounds to 0. After adding&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;descSampler.MinLOD = 0;&#xA;descSampler.MaxLOD = D3D11_FLOAT32_MAX;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the mipmap works as expected. Thank you for your attention :-)&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2019-07-22T08:37:29.860" LastActivityDate="2019-07-22T08:37:29.860" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9023" PostTypeId="1" AcceptedAnswerId="9024" CreationDate="2019-07-22T14:42:38.383" Score="1" ViewCount="65" Body="&lt;p&gt;I'm using a vertex shader to effectively wrap vertices on a sphere. Starting with &lt;code&gt;world_position&lt;/code&gt; already after multiplying the vertex by the model transform matrix to get the coordinates in world space, I calculate the new position via an inverse Mercator projection:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float theta = 2.0 * PI * world_position.x / world_radius;&#xA;float phi = 2.0 * atan(exp(world_position.y / world_radius)) - PI / 2.0;&#xA;float radius = world_position.z&#xA;&#xA;gl_Position = vec4(radius * vec3(sin(theta)*cos(phi), sin(phi), cos(theta)*cos(phi)), 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What I now need to do is take these angles, &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\varphi$&lt;/span&gt;, and use them to transform the normals as well. I've tried creating a rotation matrix to represent rotation first around the Y axis (for &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt;) and then around the X axis (for &lt;span class=&quot;math-container&quot;&gt;$\varphi$&lt;/span&gt;), and multiplying that by the vertex's normal (after multiplying the normal by the model matrix's inverse transpose), but that didn't give the results I expected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I use the angles to rotate the normals so they match the rotations of the vertices?&lt;/p&gt;&#xA;" OwnerUserId="10874" LastActivityDate="2019-07-22T15:24:23.673" Title="Wrapping normals around a sphere" Tags="&lt;glsl&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9024" PostTypeId="2" ParentId="9023" CreationDate="2019-07-22T15:24:23.673" Score="1" Body="&lt;p&gt;Turns out I needed to be looking at the former normal as a unit vector &lt;span class=&quot;math-container&quot;&gt;$(\hat{r}, \hat{\theta},\hat{\varphi})$&lt;/span&gt;, and then use a rotation matrix as outlined &lt;a href=&quot;https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; to find &lt;span class=&quot;math-container&quot;&gt;$(\hat{x},\hat{y},\hat{z})$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10874" LastActivityDate="2019-07-22T15:24:23.673" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9025" PostTypeId="1" CreationDate="2019-07-23T19:21:14.957" Score="1" ViewCount="543" Body="&lt;p&gt;I've been looking to play with ray tracing, starting with a simplest of minecraft clones (making something more akin to &lt;a href=&quot;https://www.youtube.com/watch?v=NEwKBy3babgg&amp;amp;usg=AOvVaw3X91bRH8o8Sxdz7jZIuyLt&quot; rel=&quot;nofollow noreferrer&quot;&gt;cave game&lt;/a&gt;, for starter). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I figured I'd define a voxel as a primitive and then use the regular voxel grid to trace the rays. I don't need to test (look) for intersections here, I can precisely calculate them, tracing the ray voxel by voxel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I do have an RTX card which does accelerate ray tracing with dedicated hardware, and I may be able to get faster results if I were to leverage it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I gathered, one of the components of the RTX system (or any ray tracer, really) is an acceleration structure that speeds up the process of testing for intersections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You give the card an octree or a BVH (or something similar) and it uses it to quickly find the closest hit (or any other hits, for that matter).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I'm not mistaken, the hardware accelerated part here is the hit test. It's power is in the ability to test many primitives against one or more rays in a very short amount of time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given the method I'm using for ray tracing, that is the one part that I don't really need, since I don't need to search for which primitives the ray intersects (I calculate them explicitly), I just need to check where the intersection on them is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I wrong? Can the architecture be used to accelerate what I'm doing?&#xA;If so, is it due to the fact that I misunderstood how it works, or can I adapt my plan in order to make it more friendly to the architecture, making the resulting plan faster than the original?&lt;/p&gt;&#xA;" OwnerUserId="5215" LastActivityDate="2019-07-26T14:36:58.483" Title="Regular voxel grids and RTX accelerated ray tracing" Tags="&lt;raytracing&gt;&lt;voxelization&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9027" PostTypeId="1" AcceptedAnswerId="9030" CreationDate="2019-07-24T12:05:21.130" Score="2" ViewCount="338" Body="&lt;p&gt;The shader takes an SSBO of Photons that have a position, direction, wavelength and intensity and each thread is responsible for tracing exactly one photon through the grid, where at each grid cell the photon hits, the intensity is accumulated for each wavelength to create a spectral distribution for each grid cell.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is that the shader works perfectly for 100,000 photons, but doesn't return a result for 1,000,000 photons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I looked into the sizes for the SSBOs and all were within my GPUs (NVIDIA Quadro P6000) limits of 2GB:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;SSBO Grid size: &lt;strong&gt;1.5GB&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;li&gt;SSBO Photons Size: &lt;strong&gt;0.02GB&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If I change the logic at some places it works with one million photons (see lines 87 and 114 for comments).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I currently can't see any explanation of why the shader fails for 1,000,000 photons, but works for 100,000 photons. The logic is the same and the buffer sizes are within limits. (That the buffer size can't be a problem is also confirmed by that it works when changing the logic.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the source code. If you want to try it yourself here is the code on github: &lt;a href=&quot;https://github.com/TheJhonny007/TextureTracerDebug&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/TheJhonny007/TextureTracerDebug&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Compute Shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430&#xA;&#xA;#extension GL_EXT_compute_shader: enable&#xA;#extension GL_EXT_shader_storage_buffer_object: enable&#xA;#extension GL_ARB_compute_variable_group_size: enable&#xA;&#xA;const uint TEX_WIDTH = 1024u;&#xA;const uint TEX_HEIGHT = TEX_WIDTH;&#xA;&#xA;const uint MIN_WAVELENGTH = 380u;&#xA;const uint MAX_WAVELENGTH = 740u;&#xA;const uint NUM_WAVELENGTHS = MAX_WAVELENGTH - MIN_WAVELENGTH;&#xA;&#xA;// Size: 24 bytes -&amp;gt; ~40,000,000 photons per available gigabyte of ram&#xA;struct Photon {&#xA;    vec2 position;// m&#xA;    vec2 direction;// normalized&#xA;    uint wavelength;// nm&#xA;    float intensity;// 0..1 should start at 1&#xA;};&#xA;&#xA;layout(std430, binding = 0) buffer Photons {&#xA;    Photon photons[];&#xA;};&#xA;&#xA;// Size: 1440 bytes -&amp;gt; ~700,000 pixels per available gigabyte of ram&#xA;struct Pixel {&#xA;    uint intensityAtWavelengths[NUM_WAVELENGTHS];// [0..1000]&#xA;};&#xA;&#xA;layout(std430, binding = 1) buffer Pixels {&#xA;//Pixel pixels[TEX_WIDTH][TEX_HEIGHT];&#xA;// NVIDIAs linker takes ages to link if the sizes are specified :(&#xA;    Pixel[] pixels;&#xA;};&#xA;&#xA;uniform float xAxisScalingFactor;&#xA;&#xA;vec2 getHorizontalRectangleAt(int i) {&#xA;    float x = pow(float(i), xAxisScalingFactor);&#xA;    float w = pow(float(i + 1), xAxisScalingFactor);&#xA;    return vec2(x, w);&#xA;}&#xA;&#xA;uniform float rectangleHeight;&#xA;&#xA;struct Rectangle {&#xA;    float x;&#xA;    float y;&#xA;    float w;&#xA;    float h;&#xA;};&#xA;&#xA;layout (local_size_variable) in;&#xA;&#xA;void addToPixel(uvec2 idx, uint wavelength, uint intensity) {&#xA;    if (idx.x &amp;gt;= 0u &amp;amp;&amp;amp; idx.x &amp;lt; TEX_WIDTH &amp;amp;&amp;amp; idx.y &amp;gt;= 0u &amp;amp;&amp;amp; idx.y &amp;lt; TEX_HEIGHT) {&#xA;        uint index = (idx.y * TEX_WIDTH) + idx.x;&#xA;        atomicAdd(pixels[index].intensityAtWavelengths[wavelength - MIN_WAVELENGTH], intensity);&#xA;    }&#xA;}&#xA;&#xA;/// Returns the rectangle at the given indices.&#xA;Rectangle getRectangleAt(ivec2 indices) {&#xA;    vec2 horRect = getHorizontalRectangleAt(indices.x);&#xA;    return Rectangle(horRect.x, rectangleHeight * float(indices.y), horRect.y, rectangleHeight);&#xA;}&#xA;&#xA;uniform float shadowLength;&#xA;uniform float shadowHeight;&#xA;&#xA;/// Returns the indices of the rectangle at the given location&#xA;ivec2 getRectangleIdxAt(vec2 location) {&#xA;    int x = 0;&#xA;    int y = int(location.y / rectangleHeight);&#xA;    return ivec2(x, y);&#xA;}&#xA;&#xA;float getRayIntersectAtX(Photon ray, float x) {&#xA;    float slope = ray.direction.y / ray.direction.x;&#xA;    return slope * (x - ray.position.x) + ray.position.y;&#xA;}&#xA;&#xA;ivec2 getRayRectangleExitEdge(Photon ray, Rectangle rect) {&#xA;    float intersectHeight = getRayIntersectAtX(ray, rect.x + rect.w);&#xA;&#xA;    // IF ONE OF THE FIRST TWO CONDITIONS GETS REMOVED IT WORKS WITH 1'000'000 PHOTONS OTHERWISE ONLY 100'000 WHY?&#xA;    if (intersectHeight &amp;lt; rect.y) {&#xA;        return ivec2(0, -1);&#xA;    } else if (intersectHeight &amp;gt; rect.y + rect.h) {&#xA;        return ivec2(0, 1);&#xA;    } else {&#xA;        return ivec2(1, 0);&#xA;    }&#xA;}&#xA;&#xA;void main() {&#xA;    uint gid = gl_GlobalInvocationID.x;&#xA;    if (gid &amp;gt;= photons.length()) return;&#xA;&#xA;    Photon photon = photons[gid];&#xA;&#xA;    ivec2 photonTexIndices = getRectangleIdxAt(photon.position);&#xA;    while (photonTexIndices.x &amp;lt; TEX_WIDTH &amp;amp;&amp;amp; photonTexIndices.y &amp;lt; TEX_HEIGHT &amp;amp;&amp;amp;&#xA;    photonTexIndices.x &amp;gt;= 0        &amp;amp;&amp;amp; photonTexIndices.y &amp;gt;= 0) {&#xA;        // need to convert to uint for atomic add operations...&#xA;        addToPixel(uvec2(photonTexIndices), photon.wavelength, uint(photon.intensity * 100.0));&#xA;&#xA;        ivec2 dir = getRayRectangleExitEdge(photon, getRectangleAt(photonTexIndices));&#xA;        photonTexIndices += dir;&#xA;&#xA;        // When the ray goes out of bounds on the bottom then mirror it to simulate rays coming from&#xA;        // the other side of the planet. This works because of the rotational symmetry of the system.&#xA;        // IF COMMENTET OUT IT WORKS WITH 1'000'000 PHOTONS OTHERWISE ONLY 100'000 WHY?&#xA;        if (photonTexIndices.y &amp;lt; 0) {&#xA;            photonTexIndices.y = 0;&#xA;            photon.position.y *= -1.0;&#xA;            photon.direction.y *= -1.0;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Tracer.hpp&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#ifndef TEXTURE_TRACER_HPP&#xA;#define TEXTURE_TRACER_HPP&#xA;&#xA;#include &amp;lt;glm/glm.hpp&amp;gt;&#xA;#include &amp;lt;random&amp;gt;&#xA;&#xA;namespace gpu {&#xA;&#xA;    // 6 * 4 = 24 Bytes&#xA;    struct Photon {&#xA;        glm::vec2 position;  // m&#xA;        glm::vec2 direction; // normalized&#xA;        uint32_t waveLength; // nm&#xA;        float intensity;     // 0..1 should start at 1&#xA;    };&#xA;&#xA;    class TextureTracer {&#xA;    public:&#xA;        TextureTracer();&#xA;        uint32_t createShadowMap(size_t numPhotons);&#xA;&#xA;    private:&#xA;        void initTextureTracer();&#xA;        void traceThroughTexture(uint32_t ssboPhotons, size_t numPhotons);&#xA;        Photon emitPhoton();&#xA;        std::vector&amp;lt;Photon&amp;gt; generatePhotons(uint32_t count);&#xA;&#xA;        struct {&#xA;            uint32_t uRectangleHeight;&#xA;            uint32_t uShadowLength;&#xA;            uint32_t uShadowHeight;&#xA;            uint32_t uXAxisScalingFactor;&#xA;        } mTextureTracerUniforms;&#xA;&#xA;        uint32_t mTextureTracerProgram;&#xA;&#xA;        std::mt19937_64 mRNG;&#xA;        std::uniform_real_distribution&amp;lt;&amp;gt; mDistributionSun;&#xA;        std::uniform_int_distribution&amp;lt;uint32_t&amp;gt; mDistributionWavelength;&#xA;        std::bernoulli_distribution mDistributionBoolean;&#xA;    };&#xA;&#xA;} // namespace gpu&#xA;&#xA;#endif // TEXTURE_TRACER_HPP&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Tracer.cpp&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#include &quot;TextureTracer.hpp&quot;&#xA;#include &amp;lt;GL/glew.h&amp;gt;&#xA;#include &amp;lt;algorithm&amp;gt;&#xA;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;random&amp;gt;&#xA;#include &amp;lt;string&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;&#xA;void GLAPIENTRY MessageCallback(GLenum source, GLenum type, GLuint id,&#xA;                                GLenum severity, GLsizei length,&#xA;                                const GLchar *message, const void *userParam) {&#xA;  if (type == GL_DEBUG_TYPE_ERROR)&#xA;    fprintf(stderr, &quot;GL ERROR: type = 0x%x, severity = 0x%x, message = %s\n&quot;,&#xA;            type, severity, message);&#xA;  else&#xA;    fprintf(stdout, &quot;GL INFO: type = 0x%x, severity = 0x%x, message = %s\n&quot;,&#xA;            type, severity, message);&#xA;}&#xA;&#xA;namespace gpu {&#xA;const double TEX_HEIGHT_TO_RADIUS_FACTOR = 4;&#xA;const double TEX_SHADOW_LENGTH_FACTOR = 8;&#xA;&#xA;const uint32_t TEX_WIDTH = 1024u;&#xA;const uint32_t TEX_HEIGHT = TEX_WIDTH;&#xA;&#xA;const double RADIUS = 6'371'000.0;&#xA;const double RADIUS_FACTORED = RADIUS * TEX_HEIGHT_TO_RADIUS_FACTOR;&#xA;&#xA;const double SUN_RADIUS = 695'510'000.0;&#xA;const double DIST_TO_SUN = 149'600'000'000.0;&#xA;const double ATMO_HEIGHT = 42'000.0;&#xA;&#xA;std::string loadShader(const std::string &amp;amp;fileName) {&#xA;  std::ifstream shaderFileStream(fileName, std::ios::in);&#xA;  if (!shaderFileStream.is_open()) {&#xA;    std::cerr &amp;lt;&amp;lt; &quot;Could not load the GLSL shader from '&quot; &amp;lt;&amp;lt; fileName &amp;lt;&amp;lt; &quot;'!&quot;&#xA;              &amp;lt;&amp;lt; std::endl;&#xA;    exit(-1);&#xA;  }&#xA;&#xA;  std::string shaderCode;&#xA;  while (!shaderFileStream.eof()) {&#xA;    std::string line;&#xA;    std::getline(shaderFileStream, line);&#xA;    shaderCode.append(line + &quot;\n&quot;);&#xA;  }&#xA;&#xA;  return shaderCode;&#xA;}&#xA;&#xA;void TextureTracer::initTextureTracer() {&#xA;  mTextureTracerProgram = glCreateProgram();&#xA;  uint32_t rayTracingComputeShader = glCreateShader(GL_COMPUTE_SHADER);&#xA;&#xA;  std::string code = loadShader(&quot;../resources/TextureTracer.glsl&quot;);&#xA;  const char *shader = code.c_str();&#xA;  glShaderSource(rayTracingComputeShader, 1, &amp;amp;shader, nullptr);&#xA;  glCompileShader(rayTracingComputeShader);&#xA;&#xA;  glAttachShader(mTextureTracerProgram, rayTracingComputeShader);&#xA;  glLinkProgram(mTextureTracerProgram);&#xA;&#xA;  mTextureTracerUniforms.uRectangleHeight =&#xA;      glGetUniformLocation(mTextureTracerProgram, &quot;rectangleHeight&quot;);&#xA;  mTextureTracerUniforms.uShadowHeight =&#xA;      glGetUniformLocation(mTextureTracerProgram, &quot;shadowHeight&quot;);&#xA;  mTextureTracerUniforms.uShadowLength =&#xA;      glGetUniformLocation(mTextureTracerProgram, &quot;shadowLength&quot;);&#xA;  mTextureTracerUniforms.uXAxisScalingFactor =&#xA;      glGetUniformLocation(mTextureTracerProgram, &quot;xAxisScalingFactor&quot;);&#xA;&#xA;  glDetachShader(mTextureTracerProgram, rayTracingComputeShader);&#xA;  glDeleteShader(rayTracingComputeShader);&#xA;}&#xA;&#xA;TextureTracer::TextureTracer()&#xA;    : mRNG(1L), mDistributionSun(&#xA;                    std::uniform_real_distribution&amp;lt;&amp;gt;(-SUN_RADIUS, SUN_RADIUS)),&#xA;      mDistributionWavelength(&#xA;          std::uniform_int_distribution&amp;lt;uint32_t&amp;gt;(380, 739)),&#xA;      mDistributionBoolean(std::bernoulli_distribution(0.5)) {&#xA;  glEnable(GL_DEBUG_OUTPUT);&#xA;  glDebugMessageCallback(MessageCallback, nullptr);&#xA;&#xA;  initTextureTracer();&#xA;}&#xA;&#xA;double raySphereDistance(glm::dvec2 origin, glm::dvec2 direction,&#xA;                         glm::dvec2 center, double radius) {&#xA;  glm::dvec2 m = origin - center;&#xA;  double b = glm::dot(m, direction);&#xA;  double c = glm::dot(m, m) - (radius * radius);&#xA;  if (c &amp;gt; 0.0 &amp;amp;&amp;amp; b &amp;gt; 0.0)&#xA;    return -1.0;&#xA;&#xA;  double discr = b * b - c;&#xA;&#xA;  // A negative discriminant corresponds to ray missing sphere&#xA;  if (discr &amp;lt; 0.0)&#xA;    return -1.0;&#xA;&#xA;  // Ray now found to intersect sphere, compute smallest t value of intersection&#xA;  return glm::max(0.0, -b - glm::sqrt(discr));&#xA;}&#xA;&#xA;Photon TextureTracer::emitPhoton() {&#xA;  std::uniform_real_distribution&amp;lt;&amp;gt; distributionEarth(0.0, ATMO_HEIGHT);&#xA;  glm::dvec2 target = {0.0, RADIUS + distributionEarth(mRNG)};&#xA;&#xA;  double d;&#xA;  do {&#xA;    d = glm::length(glm::dvec2(mDistributionSun(mRNG), mDistributionSun(mRNG)));&#xA;  } while (d &amp;gt; SUN_RADIUS);&#xA;&#xA;  glm::dvec2 startPosition =&#xA;      glm::dvec2(-DIST_TO_SUN, mDistributionBoolean(mRNG) ? d : -d);&#xA;  glm::dvec2 direction = glm::normalize(target - startPosition);&#xA;&#xA;  startPosition +=&#xA;      direction * raySphereDistance(startPosition, direction, {0.0, 0.0},&#xA;                                    RADIUS + ATMO_HEIGHT);&#xA;&#xA;  return {glm::vec2(0.0, startPosition.y), glm::vec2(direction),&#xA;          mDistributionWavelength(mRNG), 1.0f};&#xA;}&#xA;&#xA;std::vector&amp;lt;Photon&amp;gt; TextureTracer::generatePhotons(uint32_t count) {&#xA;  std::vector&amp;lt;Photon&amp;gt; photons(count);&#xA;  std::generate(photons.begin(), photons.end(),&#xA;                [this]() { return emitPhoton(); });&#xA;  return photons;&#xA;}&#xA;&#xA;void TextureTracer::traceThroughTexture(uint32_t ssboPhotons,&#xA;                                        size_t numPhotons) {&#xA;  glUseProgram(mTextureTracerProgram);&#xA;&#xA;  glUniform1f(mTextureTracerUniforms.uRectangleHeight,&#xA;              RADIUS_FACTORED / TEX_HEIGHT);&#xA;&#xA;  const double shadowLength =&#xA;      TEX_SHADOW_LENGTH_FACTOR * (DIST_TO_SUN * RADIUS) / (SUN_RADIUS - RADIUS);&#xA;&#xA;  glUniform1f(mTextureTracerUniforms.uShadowLength, shadowLength);&#xA;  glUniform1f(mTextureTracerUniforms.uShadowHeight, RADIUS_FACTORED);&#xA;&#xA;  const double xAxisScalingFactor =&#xA;      glm::log(shadowLength) / glm::log(static_cast&amp;lt;double&amp;gt;(TEX_WIDTH));&#xA;&#xA;  glUniform1f(mTextureTracerUniforms.uXAxisScalingFactor,&#xA;              static_cast&amp;lt;float&amp;gt;(xAxisScalingFactor));&#xA;&#xA;  const uint32_t MIN_WAVELENGTH = 380u;&#xA;  const uint32_t MAX_WAVELENGTH = 740u;&#xA;  const uint32_t NUM_WAVELENGTHS = MAX_WAVELENGTH - MIN_WAVELENGTH;&#xA;&#xA;  size_t pixelBufferSize =&#xA;      TEX_WIDTH * TEX_HEIGHT * NUM_WAVELENGTHS * sizeof(uint32_t);&#xA;  uint32_t ssboPixels;&#xA;  glGenBuffers(1, &amp;amp;ssboPixels);&#xA;  glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssboPixels);&#xA;  glBufferData(GL_SHADER_STORAGE_BUFFER, pixelBufferSize, nullptr,&#xA;               GL_DYNAMIC_COPY);&#xA;&#xA;  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ssboPhotons);&#xA;  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, ssboPixels);&#xA;&#xA;  const uint32_t numThreads = 32u;&#xA;  const uint32_t numBlocks = numPhotons / numThreads;&#xA;  std::cout &amp;lt;&amp;lt; &quot;numBlocks: &quot; &amp;lt;&amp;lt; numBlocks &amp;lt;&amp;lt; std::endl;&#xA;&#xA;  glDispatchComputeGroupSizeARB(numBlocks, 1, 1, numThreads, 1, 1);&#xA;  glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;&#xA;  struct Pixel {&#xA;    uint32_t intensityAtWavelengths[NUM_WAVELENGTHS];&#xA;  };&#xA;&#xA;  std::vector&amp;lt;Pixel&amp;gt; pixels(TEX_WIDTH * TEX_HEIGHT);&#xA;&#xA;  glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssboPixels);&#xA;  glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, pixelBufferSize,&#xA;                     pixels.data());&#xA;  glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);&#xA;&#xA;  for (int y = 0; y &amp;lt; TEX_HEIGHT; ++y) {&#xA;    printf(&quot;%4i | &quot;, y);&#xA;    for (int x = 0; x &amp;lt; TEX_WIDTH; ++x) {&#xA;      Pixel p = pixels[y * TEX_WIDTH + x];&#xA;      int counter = 0;&#xA;      for (uint32_t i : p.intensityAtWavelengths) {&#xA;        counter += i;&#xA;      }&#xA;&#xA;      if (counter == 0) {&#xA;        printf(&quot;  &quot;);&#xA;      } else if (counter &amp;gt; 100'000'000) {&#xA;        printf(&quot;%4s&quot;, &quot;\u25A0&quot;);&#xA;      } else if (counter &amp;gt; 10'000'000) {&#xA;        printf(&quot;%4s&quot;, &quot;\u25A3&quot;);&#xA;      } else if (counter &amp;gt; 1'000'000) {&#xA;        printf(&quot;%4s&quot;, &quot;\u25A6&quot;);&#xA;      } else if (counter &amp;gt; 100'000) {&#xA;        printf(&quot;%4s&quot;, &quot;\u25A4&quot;);&#xA;      } else {&#xA;        printf(&quot;%4s&quot;, &quot;\u25A1&quot;);&#xA;      }&#xA;    }&#xA;&#xA;    std::cout &amp;lt;&amp;lt; std::endl;&#xA;  }&#xA;&#xA;  glDeleteBuffers(1, &amp;amp;ssboPixels);&#xA;&#xA;  glUseProgram(0);&#xA;}&#xA;&#xA;uint32_t TextureTracer::createShadowMap(size_t numPhotons) {&#xA;  std::vector&amp;lt;Photon&amp;gt; photons = generatePhotons(numPhotons);&#xA;&#xA;  uint32_t ssboPhotons;&#xA;  glGenBuffers(1, &amp;amp;ssboPhotons);&#xA;  glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssboPhotons);&#xA;  glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Photon) * photons.size(),&#xA;               photons.data(), GL_DYNAMIC_COPY);&#xA;&#xA;  traceThroughTexture(ssboPhotons, photons.size());&#xA;&#xA;  glDeleteBuffers(1, &amp;amp;ssboPhotons);&#xA;  glDeleteProgram(mTextureTracerProgram);&#xA;&#xA;  glDisable(GL_DEBUG_OUTPUT);&#xA;  glDebugMessageCallback(nullptr, nullptr);&#xA;&#xA;  return 0;&#xA;}&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;main.cpp&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#include &amp;lt;GL/glew.h&amp;gt;&#xA;#include &amp;lt;GL/glut.h&amp;gt;&#xA;&#xA;#include &quot;TextureTracer.hpp&quot;&#xA;&#xA;int main(int argc, char *argv[]) {&#xA;    glutInit(&amp;amp;argc, argv);&#xA;    glutCreateWindow(&quot;OpenGL needs a window o.O&quot;);&#xA;    glewInit();&#xA;&#xA;    auto mapper = gpu::TextureTracer();&#xA;&#xA;    // WITH 100'000 PHOTONS IT WORKS, WITH 1'000'000 PHOTONS NOT WHY?&#xA;    mapper.createShadowMap(100'000);&#xA;&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10952" LastEditorUserId="10952" LastEditDate="2019-07-25T09:03:21.583" LastActivityDate="2019-07-26T09:03:13.480" Title="GLSL Compute Shader doesn't run for large inputs" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;glsl&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="10" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9029" PostTypeId="1" CreationDate="2019-07-25T20:09:51.353" Score="0" ViewCount="65" Body="&lt;p&gt;I have been trying to implement a simple GPU based volumetric renderer, somewhat similar to described &lt;a href=&quot;http://graphicsrunner.blogspot.com/2009/01/volume-rendering-101.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. I conceptually understand most of the stuff, and implemented some code, but my results are no where close to I would expect. Here is simple data I am trying to render. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/9w0jz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9w0jz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 3D texture used was programmatically created by me; it’s a 256*256*256 arrays where each element contains 4 floats (RGBA). Most of the texture is just green color, with red and blue colored region in between. The final output I get is kind of “pixelated” and “blurry”; I was hoping that the boundary between green area and red/blue area would be crisp and sharp. Please note that each voxel in my array contains all the information about the RGBA component, and when I am firing rays onto the volume, I collect all the color information from the voxel and blend together. The 3D texture parameters GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER are set to GL_LINEAR and not to GL_NEAREST. Hence I am surprised why this pixelated appearance? Perhaps performing some kind of anti-aliasing might help, in which case I could fire multiple rays in slightly different direction for each fragment in my fragment shader and that would possibly smoothen the appearance? Moreover, do you think this could be because my volume is relatively small, only 256*256*256?&lt;/p&gt;&#xA;" OwnerUserId="10955" LastActivityDate="2019-07-25T20:09:51.353" Title="Pixelated /aliased /blurry edges in volumetric rendering" Tags="&lt;antialiasing&gt;&lt;volume-rendering&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9030" PostTypeId="2" ParentId="9027" CreationDate="2019-07-26T08:40:04.667" Score="3" Body="&lt;p&gt;Operating systems cancel GPU program executions if they take too long. On Windows it is generally two seconds and on Linux it is five seconds most of the time, but it can vary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is to detect GPU programs that are stuck and cancel them. There are different methods to get around this timeout, but they all require admin/root privileges, which is not always available.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If possible the execution can be split up into multiple invocations like in the following snippet:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;const uint32_t passSize   = 2048u;&#xA;const uint32_t numPasses  = (numPhotons / passSize) + 1;&#xA;const uint32_t numThreads = 64u;&#xA;const uint32_t numBlocks  = passSize / numThreads;&#xA;&#xA;glUniform1ui(glGetUniformLocation(mTextureTracerProgram, &quot;passSize&quot;), passSize);&#xA;for (uint32_t pass = 0u; pass &amp;lt; numPasses; ++pass) {&#xA;  glUniform1ui(glGetUniformLocation(mTextureTracerProgram, &quot;pass&quot;), pass);&#xA;&#xA;  glDispatchComputeGroupSizeARB(numBlocks, 1, 1, numThreads, 1, 1);&#xA;  glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;  glFlush();&#xA;  glFinish();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;glFlush()&lt;/code&gt; and &lt;code&gt;glFinish()&lt;/code&gt; calls are important or the executions will get bundled together and the OS triggers a timeout anyways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the shader you just need to access the right sections of the input data like so:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;// other stuff&#xA;&#xA;uniform uint pass;&#xA;uniform uint passSize;&#xA;&#xA;void main() {&#xA;  uint gid = gl_GlobalInvocationID.x;&#xA;  uint passId = pass * passSize + gid;&#xA;  if (passId &amp;gt;= photons.length()) return;&#xA;&#xA;  Photon photon = photons[passId];&#xA;&#xA;  // rest of program&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to disable the OS timeouts here is a relevant post for Linux: &lt;a href=&quot;https://stackoverflow.com/a/30520538/5543884&quot;&gt;https://stackoverflow.com/a/30520538/5543884&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here is a post regarding Windows: &lt;a href=&quot;https://stackoverflow.com/a/29759823/5543884&quot;&gt;https://stackoverflow.com/a/29759823/5543884&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10952" LastEditorUserId="10952" LastEditDate="2019-07-26T09:03:13.480" LastActivityDate="2019-07-26T09:03:13.480" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9031" PostTypeId="2" ParentId="9025" CreationDate="2019-07-26T14:36:58.483" Score="3" Body="&lt;p&gt;As you said, the RTX Turing architecture comes with wired primitive-ray intersection, (to be more specific, triangle-ray intersection). The BVH is built by specifying the Bounding Box program to OptiX, the signature of which is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RT_PROGRAM void my_boundingbox_build_program( int, float result[6] )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As you can guess, the result must contain the minimun (3 first components) and maximum (3 last components) bounds of the bounding box. You can use this to build virtual bounding boxes even if you have no geometry (for instance, a chunk of 16x16x16 voxels).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you perform &lt;code&gt;rtTrace&lt;/code&gt; , the OptiX API will detect the collision through the BVH which it has build with the help of your bounding box program. In that momment, it will call the Intersection program, which you can specify and which signature is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RT_PROGRAM void my_intersection_program( int prim_index )&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where you will report any possible intersection within your 16x16x16 chunk of voxels (obviously you can ignore the prim_index, which is only useful when using geometry primitives). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if you would use their special structure &lt;code&gt;RTgeometrytriangles&lt;/code&gt; , the Turing RTX architecture would be able to make use of the wired primitive intersection, which is where performance boost would be gained, and you would not need to implement your own intersection program.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To sumarize:&#xA;Since you are not using the specific &lt;code&gt;RTgeometrytriangles&lt;/code&gt; , you will not access the intersection performance boost from the Turing architecture.&lt;/p&gt;&#xA;" OwnerUserId="8394" LastActivityDate="2019-07-26T14:36:58.483" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9032" PostTypeId="1" CreationDate="2019-07-27T01:32:03.067" Score="3" ViewCount="624" Body="&lt;p&gt;Decoding video will result in different pixel formats on different GPUs and drivers. I have an application which can render (using OpenGL), only the RGB8 pixel format, therefore I need to do color conversion from the decoded pixel format to RGB8. I can access the gl... functions in this program but I cannot edit the shader, so I'm stuck with RGB8.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This ffmpeg example demonstrates how to do hardware decoding: &lt;a href=&quot;https://github.com/FFmpeg/FFmpeg/blob/release/4.2/doc/examples/hw_decode.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/FFmpeg/FFmpeg/blob/release/4.2/doc/examples/hw_decode.c&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At line 109 it does this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;/* retrieve data from GPU to CPU */&#xA;            if ((ret = av_hwframe_transfer_data(sw_frame, frame, 0)) &amp;lt; 0) {&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I want to avoid this because it takes time. Therefore, I need a way to reuse that decoded video, which is in GPU memory, to redo color conversion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to create a shader program that takes input from the GPU memory, not CPU memory? If I want to pass image from CPU to my shader, I simply use &lt;code&gt;glTexImage2D&lt;/code&gt;. Is there a similar way to do it but from GPU memory?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I do even deeper and render the color decoded video on screen without copying from GPU memory too?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If what I wanna do is possible, are there shader programs available to color convert pixels for some major graphics cards/drivers? I don't want to support all of them, but I'd like to support at least the Jetson Nano board from NVIDIA.&lt;/p&gt;&#xA;" OwnerUserId="10964" LastEditorUserId="2479" LastEditDate="2019-08-05T05:43:30.263" LastActivityDate="2019-08-05T05:43:30.263" Title="Is it possible to do color conversion on decoded video without getting it from GPUmemory to CPU memory?" Tags="&lt;opengl&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9034" PostTypeId="1" CreationDate="2019-07-27T17:15:13.460" Score="1" ViewCount="54" Body="&lt;p&gt;I ran into strange problem. My HLSL VS won't compile for given lines:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 finalUV = input.tex;&#xA;[branch] if(isHorizontal)&#xA;{&#xA;    finalUV.y += finalOffset * stepLength;&#xA;}&#xA;else &#xA;{&#xA;    finalUV.x += finalOffset * stepLength;&#xA;}   &#xA;float4 finalColor = float4(screenTexture.Sample(SampleType, finalUV).rgb, 1.0f);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But when I remove &lt;strong&gt;finalOffset&lt;/strong&gt; variable - then it's compile fine and works. This HLSL code is actually part of FXAA shader based on &lt;a href=&quot;http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This code contains a lot of branching. I have no idea if that might be a problem. Here is my full HLSL code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;////////////////////////////////////////////////////////////////////////////////&#xA;// Filename: fxaa.ps&#xA;////////////////////////////////////////////////////////////////////////////////&#xA;&#xA;//Based on http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html&#xA;&#xA;Texture2D screenTexture : register(t0);&#xA;SamplerState SampleType : register(s0); &#xA;&#xA;//////////////&#xA;// TYPEDEFS //&#xA;//////////////&#xA;struct PixelInputType&#xA;{&#xA;    float4 position : SV_POSITION;&#xA;    float2 tex: TEXCOORD0;&#xA;};&#xA;&#xA;float rgb2luma(float3 rgb);&#xA;&#xA;static const float EDGE_THRESHOLD_MIN = 0.0312f;&#xA;static const float EDGE_THRESHOLD_MAX = 0.125f;&#xA;static const float SUBPIXEL_QUALITY = 0.75f;&#xA;static const int ITERATIONS = 12;&#xA;static const float QUALITY[ITERATIONS] = {0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 1.5f, 2.0f, 2.0f, 2.0f, 2.0f, 4.0f, 8.0f};&#xA;////////////////////////////////////////////////////////////////////////////////&#xA;// Pixel Shader&#xA;////////////////////////////////////////////////////////////////////////////////&#xA;float4 ColorPixelShader(PixelInputType input) : SV_TARGET&#xA;{&#xA;//TODO - Pass as parameter&#xA;    float2 inverseScreenSize = float2(1.0f / 1280.0f, 1.0f / 720.0f);&#xA;&#xA;    float3 colorCenter = screenTexture.Sample(SampleType, input.tex).rgb;   &#xA;&#xA;//DETECT EDGES  &#xA;    //Center luma&#xA;    float lumaCenter = rgb2luma(colorCenter);&#xA;&#xA;    //Direct neighbour luma&#xA;    float lumaDown = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(0, -1)).rgb);&#xA;    float lumaUp = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(0, 1)).rgb);&#xA;    float lumaLeft = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(-1, 0)).rgb);&#xA;    float lumaRight = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(1, 0)).rgb);&#xA;&#xA;    //Find max, min luma&#xA;    float lumaMin = min(lumaCenter, min(min(lumaDown, lumaUp), min(lumaLeft, lumaRight)));&#xA;    float lumaMax = max(lumaCenter, max(max(lumaDown, lumaUp), max(lumaLeft, lumaRight)));&#xA;&#xA;    //Delta (max-min)&#xA;    float lumaRange = lumaMax - lumaMin;&#xA;&#xA;    [branch] if (lumaRange &amp;lt; max(EDGE_THRESHOLD_MIN, lumaMax * EDGE_THRESHOLD_MAX))&#xA;    {&#xA;        //Difference between lumas too small - there is no edge (or pixel is in very dark area)&#xA;        return float4(colorCenter, 1.0f);&#xA;    }&#xA;//CHOOSE EDGE DIRECTION&#xA;    //Find corners lumas&#xA;    float lumaDownLeft = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(-1, -1)).rgb);&#xA;    float lumaUpRight = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(1, 1)).rgb);&#xA;    float lumaUpLeft = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(-1, 1)).rgb);&#xA;    float lumaDownRight = rgb2luma(screenTexture.Sample(SampleType, input.tex, float2(1, -1)).rgb);&#xA;&#xA;    //Combine lumas for future computation&#xA;    float lumaDownUp = lumaDown + lumaUp;&#xA;    float lumaLeftRight = lumaLeft + lumaRight;&#xA;    float lumaLeftCorners = lumaDownLeft + lumaUpLeft;&#xA;    float lumaDownCorners = lumaDownLeft + lumaDownRight;&#xA;    float lumaRightCorners = lumaDownRight + lumaUpRight;&#xA;    float lumaUpCorners = lumaUpRight + lumaUpLeft;&#xA;&#xA;    //Calculate horiozntal/vertical edges&#xA;    float edgeHorizontal =  abs(-2.0 * lumaLeft + lumaLeftCorners)  + abs(-2.0 * lumaCenter + lumaDownUp ) * 2.0    + abs(-2.0 * lumaRight + lumaRightCorners);&#xA;    float edgeVertical =    abs(-2.0 * lumaUp + lumaUpCorners)      + abs(-2.0 * lumaCenter + lumaLeftRight) * 2.0  + abs(-2.0 * lumaDown + lumaDownCorners);&#xA;&#xA;    //Check local edge direction&#xA;    bool isHorizontal = (edgeHorizontal &amp;gt;= edgeVertical);&#xA;&#xA;    //Get lumas of pixels of opposite directions&#xA;    float luma1 = isHorizontal ? lumaDown : lumaLeft;&#xA;    float luma2 = isHorizontal ? lumaUp : lumaRight;&#xA;&#xA;    //Calculate gradients for both&#xA;    float gradient1 = luma1 - lumaCenter;&#xA;    float gradient2 = luma2 - lumaCenter;&#xA;&#xA;    //Check which direction is steepest&#xA;    bool is1Steepest = abs(gradient1) &amp;gt;= abs(gradient2);&#xA;&#xA;    //Get strongest gradient and normalize it&#xA;    float gradientScaled = 0.25f * max(abs(gradient1), abs(gradient2));&#xA;&#xA;//CALCULATE NEW UV&#xA;    //Calculate step length based on screen size&#xA;    float stepLength = isHorizontal ? inverseScreenSize.y : inverseScreenSize.x;&#xA;&#xA;    //Average luma in correct direction&#xA;    float lumaLocalAverage = 0.0f;&#xA;&#xA;    [branch] if (is1Steepest)&#xA;    {&#xA;        //Switch direction, because is1Steepest indicates DOWN or LEFT&#xA;        stepLength *= -1.0f;&#xA;        lumaLocalAverage = 0.5f * (luma1 + lumaCenter);&#xA;    }&#xA;    else&#xA;    {&#xA;        lumaLocalAverage = 0.5f * (luma2 + lumaCenter);&#xA;    }&#xA;&#xA;    //Move UV by half a pixel to correct direction&#xA;    float2 currentUV = input.tex;&#xA;    [branch] if (isHorizontal)&#xA;    {&#xA;        currentUV.y += stepLength * 0.5f;&#xA;    }&#xA;    else&#xA;    {&#xA;        currentUV.x += stepLength * 0.5f;&#xA;    }&#xA;&#xA;//FIRST ITERATION&#xA;    float2 offset = isHorizontal ? float2(inverseScreenSize.x, 0.0f) : float2(0.0f, inverseScreenSize.y);&#xA;&#xA;    //Explore both sides&#xA;    float2 uv1 = currentUV - offset;&#xA;    float2 uv2 = currentUV + offset;&#xA;&#xA;    //Read lumas from both extremes - find delta&#xA;    float lumaEnd1 = rgb2luma(screenTexture.Sample(SampleType, uv1).rgb);&#xA;    float lumaEnd2 = rgb2luma(screenTexture.Sample(SampleType, uv2).rgb);&#xA;    lumaEnd1 -= lumaLocalAverage;&#xA;    lumaEnd2 -= lumaLocalAverage;&#xA;&#xA;    //If luma deltas is larger than local gradient - reached edge&#xA;    bool reached1 = abs(lumaEnd1) &amp;gt;= gradientScaled;&#xA;    bool reached2 = abs(lumaEnd2) &amp;gt;= gradientScaled;&#xA;    bool reachedBoth = reached1 &amp;amp;&amp;amp; reached2;&#xA;&#xA;    //If the side is not reached - continue exploration in given direction&#xA;    [branch] if (!reached1)&#xA;    {&#xA;        uv1 -= offset;&#xA;    }&#xA;    [branch] if (!reached2)&#xA;    {&#xA;        uv2 += offset;&#xA;    }&#xA;&#xA;//CONTINUE ITERATION&#xA;    [branch] if (!reachedBoth)&#xA;    {&#xA;        for (int i = 2; i &amp;lt; ITERATIONS; ++i)&#xA;        {&#xA;            [branch] if (!reached1)&#xA;            {&#xA;                lumaEnd1 = rgb2luma(screenTexture.Sample(SampleType, uv1).rgb);             &#xA;                lumaEnd1 -= lumaLocalAverage;&#xA;            }           &#xA;            [branch] if (!reached2)&#xA;            {&#xA;                lumaEnd2 = rgb2luma(screenTexture.Sample(SampleType, uv2).rgb);&#xA;                lumaEnd2 -= lumaLocalAverage;&#xA;            }&#xA;            reached1 = abs(lumaEnd1) &amp;gt;= gradientScaled;&#xA;            reached2 = abs(lumaEnd2) &amp;gt;= gradientScaled;&#xA;            reachedBoth = reached1 &amp;amp;&amp;amp; reached2;&#xA;&#xA;            [branch] if(!reached1)&#xA;                uv1 -= offset * QUALITY[i];&#xA;&#xA;            [branch] if(!reached2)&#xA;                uv2 += offset * QUALITY[i];&#xA;&#xA;            [branch] if(reachedBoth)&#xA;                break;&#xA;        }&#xA;    }&#xA;&#xA;//ESTIMATE OFFSET&#xA;    float distance1 = isHorizontal ? (input.tex.x - uv1.x) : (input.tex.y - uv1.y);&#xA;    float distance2 = isHorizontal ? (uv2.x - input.tex.x) : (uv2.y - input.tex.y);&#xA;&#xA;    //Get dinal distance with direction&#xA;    bool isDirection1 = distance1 &amp;lt; distance2;&#xA;    float distanceFinal = min(distance1, distance2);&#xA;&#xA;    //Length of edge&#xA;    float edgeThickness = (distance1 + distance2);&#xA;&#xA;    //UV offset&#xA;    float pixelOffset = -distanceFinal/edgeThickness + 0.5f;&#xA;&#xA;//CHECK LUMA&#xA;    bool isLumaCenterSmaller = lumaCenter &amp;lt; lumaLocalAverage;&#xA;&#xA;    // If the luma at center is smaller than at its neighbour, the delta luma at each end should be positive (same variation).&#xA;    // (in the direction of the closer side of the edge.)&#xA;    bool correctVariation = ((isDirection1 ? lumaEnd1 : lumaEnd2) &amp;lt; 0.0f) != isLumaCenterSmaller;&#xA;&#xA;    //If the luma variation is incorrect, do not offset&#xA;    float finalOffset = correctVariation ? pixelOffset : 0.0f;&#xA;&#xA;//SUBPIXEL ANTIALIASING&#xA;    //Weighted average&#xA;    float lumaAverage = (1.0f / 12.0f) * (2.0f * (lumaDownUp + lumaLeftRight)) + lumaLeftCorners + lumaRightCorners;&#xA;    //Radio of the delta between global average and the center luma&#xA;    float subPixelOffset1 = clamp(abs(lumaAverage - lumaCenter) / lumaRange, 0.0f, 1.0f);&#xA;    float subPixelOffset2 = (-2.0f * subPixelOffset1 + 3.0f) * subPixelOffset1 * subPixelOffset1;&#xA;&#xA;    float subPixelOffsetFinal = subPixelOffset2 * subPixelOffset2 * SUBPIXEL_QUALITY;&#xA;    // Pick the biggest of the two offsets.&#xA;    finalOffset = max(finalOffset, subPixelOffsetFinal);&#xA;&#xA;//FINAL READ    &#xA;    float2 finalUV = input.tex;&#xA;    [branch] if(isHorizontal)&#xA;    {&#xA;        finalUV.y += finalOffset * stepLength;&#xA;    }&#xA;    else &#xA;    {&#xA;        finalUV.x += finalOffset * stepLength;&#xA;    }   &#xA;    float4 finalColor = float4(screenTexture.Sample(SampleType, finalUV).rgb, 1.0f);&#xA;&#xA;    return finalColor;&#xA;}&#xA;&#xA;float rgb2luma(float3 rgb)&#xA;{&#xA;    return sqrt(dot(rgb, float3(0.299f, 0.587f, 0.114f)));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2019-07-27T17:15:13.460" Title="Cannot use variable as texture sample value - HLSL DirectX11" Tags="&lt;directx11&gt;&lt;hlsl&gt;&lt;pixel-shader&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9035" PostTypeId="2" ParentId="9032" CreationDate="2019-07-27T23:23:40.850" Score="2" Body="&lt;p&gt;So it sounds like the main issue you're having is how to render something when all resources are already on the GPU. I would do it like this:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Create the destination RGB texture that's the proper width and height&lt;/li&gt;&#xA;&lt;li&gt;Create an FBO&lt;/li&gt;&#xA;&lt;li&gt;Set the texture created in step 1 as the output (write) texture of the FBO&lt;/li&gt;&#xA;&lt;li&gt;Bind the NV12 texture to the texture unit you'll use in your shader&lt;/li&gt;&#xA;&lt;li&gt;Draw a textured quad that covers the entire output&lt;/li&gt;&#xA;&lt;li&gt;Apply a shader that samples the NV12 texture to generate the RGB value at each fragment&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;For step 1 you use &lt;code&gt;glGenTextures()&lt;/code&gt; and &lt;code&gt;glTexImage2D()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For steps 2 and 3 you use &lt;code&gt;glGenFramebuffers()&lt;/code&gt; and &lt;code&gt;glBindFramebuffer()&lt;/code&gt; passing &lt;code&gt;glBindFramebuffer()&lt;/code&gt; the texture created in step 1 to attach it to &lt;code&gt;GL_COLOR_ATTACHMENT0&lt;/code&gt;. (See &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Framebuffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; for more details.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For step 4 you use &lt;code&gt;glBindTexture()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For step 5 you can simply draw a quad that goes from (-1, -1) to (1, 1). You don't need any model view matrix or anything.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For step 6 you'll need to calculate where the red, green, and blue samples that correspond to the current output pixel are in the input texture and then sample them using the &lt;code&gt;texture()&lt;/code&gt; function. You'll need to do 3 different look-ups for each output pixel. &lt;a href=&quot;http://paulbourke.net/dataformats/nv12/&quot; rel=&quot;nofollow noreferrer&quot;&gt;This link has C code&lt;/a&gt; for figuring out where each sample is from. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you're done you can delete the frame buffer and use the texture created in step 1 in your next step (display it, process it, save it to disk, or whatever).&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-07-27T23:23:40.850" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9038" PostTypeId="1" CreationDate="2019-07-29T13:50:29.943" Score="1" ViewCount="211" Body="&lt;p&gt;I would like to know which is the most important ? More particularly in games or for the display of a desk (ex KDE Plasma, Windows 10 ...) ?&lt;/p&gt;&#xA;" OwnerUserId="10976" LastActivityDate="2019-07-29T13:50:29.943" Title="Which is more important : Texel or Pixel rate?" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;pixels&gt;" AnswerCount="0" CommentCount="2" ClosedDate="2019-07-30T08:13:28.403" ContentLicense="CC BY-SA 4.0" />
  <row Id="9039" PostTypeId="1" CreationDate="2019-07-30T02:28:11.250" Score="2" ViewCount="192" Body="&lt;p&gt;As described in &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBRT 14.5&lt;/a&gt;, the path tracer stops bouncing rays at a probability &lt;code&gt;q&lt;/code&gt;, which is determined by the throughput of the path.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&amp;lt;&amp;lt;Possibly terminate the path with Russian roulette&amp;gt;&amp;gt;= &#xA;if (bounces &amp;gt; 3) {&#xA;    Float q = std::max((Float).05, 1 - beta.y());&#xA;    if (sampler.Get1D() &amp;lt; q)&#xA;        break;&#xA;    beta /= 1 - q;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In my understanding, the probability &lt;code&gt;q&lt;/code&gt; should be a constant for paths of the same length, so that the Russian roulette estimator is unbiased. Would such a dynamic termination probability still produce biased results?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Update:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given an estimator &lt;code&gt;F&lt;/code&gt;, its corresponding Russian roulette estimator is defined to be&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;R = (F - qc) / (1 - q) , if xi &amp;gt; q&#xA;R = c                  , otherwise&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Since &lt;code&gt;E[R] = (1 - q)(E[F] - qc) / (1 - q) + qc = E[F]&lt;/code&gt;, as long as &lt;code&gt;F&lt;/code&gt; is a unbiased estimator, &lt;code&gt;R&lt;/code&gt; is a unbiased estimator as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specific to a path tracer, its path-integral form of LTE with Russian roulette can be written as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;1 / (1 - q1)(P(p1) + 1 / (1 - q2)(P(p2) + 1 / (1 - q3)(P(p3) + ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;if &lt;code&gt;q1, q2, qc, ...&lt;/code&gt; is not a constant, then the estimator for each path length is not an unbiased estimator, I think.&lt;/p&gt;&#xA;" OwnerUserId="10980" LastEditorUserId="10980" LastEditDate="2019-07-31T04:46:43.627" LastActivityDate="2019-07-31T04:46:43.627" Title="The termination probability of Russian roulette in PBRT" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="9041" PostTypeId="1" AcceptedAnswerId="9042" CreationDate="2019-08-02T08:25:04.683" Score="1" ViewCount="42" Body="&lt;p&gt;I am looking for a list that states which vendor does support which OpenGL extension.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example I wanted to use &lt;code&gt;ARB_shading_language_include&lt;/code&gt;, which was accepted in 2013, but from various forums on the internet I assume it isn't implemented on AMD drivers. But I can't find any official document that states where this extension is supported.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does such a list exist?&lt;/p&gt;&#xA;" OwnerUserId="10952" LastActivityDate="2019-08-02T11:26:42.537" Title="Is there a list of OpenGL extension support?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9042" PostTypeId="2" ParentId="9041" CreationDate="2019-08-02T11:26:42.537" Score="1" Body="&lt;p&gt;There is no official list, but a community driven one. It is largely up to date:&#xA;&lt;a href=&quot;https://opengl.gpuinfo.org/listextensions.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://opengl.gpuinfo.org/listextensions.php&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As can be seen &lt;a href=&quot;https://opengl.gpuinfo.org/listreports.php?extension=GL_ARB_shading_language_include&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; AMD doesn't support the &lt;code&gt;ARB_shading_language_include&lt;/code&gt; extension at the time I wrote this answer.&lt;/p&gt;&#xA;" OwnerUserId="10952" LastActivityDate="2019-08-02T11:26:42.537" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9043" PostTypeId="1" CreationDate="2019-08-02T14:30:19.410" Score="4" ViewCount="375" Body="&lt;p&gt;I'm working on a (toy-level) path/ray-tracer, currently trying to implement (and understand) improved sampling strategies.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The obvious next choice after uniform random sampling would be stratified/jittered sampling.&#xA;The idea itself is clear: You divide the domain to sample (let's say the unit square) into NxN sub regions/cells, place a sample into each of those and add noise to it. Afterwards you shuffle the sample array so the consumption order does not matter - at least that is my understanding for the shuffle step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This procedure is explained over and over in lots of sources and literature, but what most barely touch is how you would consume those in practise.&#xA;While it is clear for a single use case, like sampling a primary ray/camera pixel or sampling the surface of an area light, my understanding (which might be wrong) is&#xA;that those stratified [0,1]^N samples act as a general source of well distributed random numbers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example, say you want to render 1024 samples for some scene with area lights with a path tracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;per pixel:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;just generating 32 x 32 (camera ray) samples is not working out, as you will need more good 2D samples for the area lights. Generating 32x32 arrays for each occasion where you might need good 2D samples is probably not a good idea, or is it? Though, given that you know the max ray bounce number one could make a good upper limit guess for the necessary total amount of 2D samples per pixel.&lt;/li&gt;&#xA;&lt;li&gt;you will also need good 1D numbers for things like rolling the russian roulette dice or picking the BRDF to sample, the amount needed is probably unknown in advance, but again, guessing a reasonable upper limit would probably work out&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My immediate (and probably flawed) idea would be to create stratified sample arrays per pixel (or even for the full rendering) for dimensions 1+2 which do not necessarily match the requested total sample per pixel count, e.g. 64x64 each time, no matter the samples per pixel count. You would consume those in order, after shuffling, and if used up generate them fresh. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other alternatives i could think of:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;given number of pixel samples N, always generate N stratified samples on demand whenever needed&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;generate enough samples ahead of time per pixel, when running out fall back to uniform random numbers or generate new stratified samples (so eventually the same as above)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So long story short, the actual question is probably how do i properly consume those stratified samples? Are you even supposed to use such samples outside of primary pixel or area light samples? (Re)Use unused numbers per pixel sample,  per full rendering? Or am i generally on the wrong path, in that those stratified samples are not meant as a replacement for well distributed random numbers?&lt;/p&gt;&#xA;" OwnerUserId="10996" LastActivityDate="2019-08-03T09:06:37.843" Title="Proper way of consuming stratified samples in path/ray tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9045" PostTypeId="2" ParentId="8909" CreationDate="2019-08-03T19:22:20.637" Score="2" Body="&lt;p&gt;Dear ImGui doesn't attempt to create a swapchain for your main window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;strong&gt;example&lt;/strong&gt; code (main.cpp) in the Vulkan back-end calls a helper &lt;code&gt;ImGui_ImplVulkanH_CreateWindowSwapChain()&lt;/code&gt; which calls &lt;code&gt;vkCreateSwapchainKHR()&lt;/code&gt;... well, because it is an example app.. you should probably not call those helpers in those app, your app probably already creates a window and a swapchain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the multi-viewports feature enabled (only available in the 'docking' branch), it DOES create additional swap-chains for every secondary window it creates, those are not windows that you manage nor see at all so it shouldn't interferte with your window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All the functions with the &lt;code&gt;ImGui_ImplVulkanH_&lt;/code&gt; prefix are documented in imgui_impl_vulkan.h as serving two purposes: facilitating writing the demo app, and internally by the multi-viewports system. You shouldn't need to call those from your app and therefore there's should not be multiple swapchains trying to associate to a same window.&lt;/p&gt;&#xA;" OwnerUserId="10998" LastActivityDate="2019-08-03T19:22:20.637" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9046" PostTypeId="1" CreationDate="2019-08-03T19:49:05.940" Score="0" ViewCount="143" Body="&lt;p&gt;If I have a cube in OpenGL, how can I have it appear like rounded?&#xA; I think it's too complicated to really have the cube rounded so is there any &quot;light trick&quot; to have something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wtuxO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wtuxO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The cubes in the image seem to be rounded on the top. The screenshot is from the game &lt;a href=&quot;https://voxatron.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Voxatron&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another view of the cubes (see how they seem rounded on the top):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yQb4V.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yQb4V.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10928" LastEditorUserId="10928" LastEditDate="2019-08-03T19:55:58.190" LastActivityDate="2019-08-03T20:59:01.793" Title="Pseudo rounded cube in OpenGL" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9047" PostTypeId="2" ParentId="9046" CreationDate="2019-08-03T20:59:01.793" Score="3" Body="&lt;p&gt;If silhouette is not important, you could bend the shading normal near edges. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since it's a cube you can probably compute the normal procedurally in the shader based off of the uv. I.e. if uv is in range [0,0.1] or [0.9,1.0] start bending the normal towards horizontal. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If silhouette is important, drawing a rounded cube model with vertex normals would make the most sense. There are cube models which have the beveling to look like a rounded cube.&lt;/p&gt;&#xA;" OwnerUserId="1582" LastActivityDate="2019-08-03T20:59:01.793" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9048" PostTypeId="1" CreationDate="2019-08-04T15:31:56.767" Score="0" ViewCount="602" Body="&lt;p&gt;Please help me out with this thing and currently i am a little more than a beginner so please tell me in that context. i don't need any obsolete methods for creating this like using GLUT or GLEW.can you just tell me its algorithm to create the outline of it(like using icosphere or triangles) and how and where in the whole program do i implement this algorithm. currently i am referring the &quot;learnopengl.com&quot; tutorials.i know how to create triangles and 3d rotational cube.   &lt;/p&gt;&#xA;" OwnerUserId="10957" LastEditorUserId="10957" LastEditDate="2020-02-19T17:36:06.437" LastActivityDate="2021-03-15T19:02:25.283" Title="How can i wrap the earth image around a 3D Sphere using OpenGL, GLFW, GLAD, GLM?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;transformations&gt;&lt;algorithm&gt;&lt;glm&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9049" PostTypeId="2" ParentId="9048" CreationDate="2019-08-04T23:49:36.090" Score="0" Body="&lt;p&gt;I'm not going to post proper working code here just giving you a guideline. There might be an easier way but what I did back in my days was to create a sphere using Triangle Strips. There is an icosahedron approach as well but I haven't looked into that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So first of all look up on &lt;code&gt;GL_TRIANGLE_STRIPS&lt;/code&gt; and how they work. Secondly you need to look up on Spherical coordinates and how to convert them to Cartesian Coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A brief overview is that Spherical coordinates have parameters (radius, zenith, azimuth). Radius is pretty much self explanatory. Zenith angle is the inclination angle from the pole of the sphere (lines of longitude) While the Azimuth angle runs along the latitude. Zenith runs from &lt;code&gt;0-PI&lt;/code&gt; (assuming 0 starts from 1 pole and PI is the second pole) or &lt;code&gt;-PI/2 - PI/2&lt;/code&gt; (assuming the extreme at both poles and 0 is the center) and Azimuth from &lt;code&gt;0-2PI&lt;/code&gt; (all the way around the sphere).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now after that you can think of the sphere forming up from concentric Rings. At each fraction of the Zenith angle there is ring that runs around the sphere (the latitude lines). Then you create triangle strips between those rings to fill the sphere up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So basically you want something like,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;zenith = azimuth = 0&#xA;ring_increment = PI/num_rings;&#xA;sector_inrement = 2PI/num_sectors;&#xA;&#xA;for(i=0; i &amp;lt; PI; i+= ring_increment)&#xA;{&#xA;    for(j=0; j &amp;lt; 2PI; j+= sector_increment)&#xA;    {&#xA;        vertex_list.add(convertToCartesianCoord(radius, zenith, azimuth))&#xA;        zenith += ring_increment&#xA;        vertex_list.add(convertToCartesianCoord(radius, zenith, azimuth))&#xA;        zenith -= ring_increment&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The more the number of rings and the number of sectors the smoother the sphere will be.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-08-04T23:49:36.090" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9050" PostTypeId="1" AcceptedAnswerId="9051" CreationDate="2019-08-06T08:09:15.490" Score="1" ViewCount="180" Body="&lt;p&gt;in the vertex shader I have the vertex position &lt;code&gt;vpos&lt;/code&gt; which is in object space and I want to get the vector going from the camera to &lt;code&gt;vpos&lt;/code&gt;. Can I just do &lt;code&gt;vpos - cameraPos&lt;/code&gt; or do I need to do some matrix multiplication with the model-view inverse because &lt;code&gt;vPos&lt;/code&gt; and &lt;code&gt;cameraPos&lt;/code&gt; are not in the same space?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2019-08-06T15:26:22.720" Title="Camera position in vertex shader" Tags="&lt;opengl&gt;&lt;matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9051" PostTypeId="2" ParentId="9050" CreationDate="2019-08-06T15:26:22.720" Score="2" Body="&lt;p&gt;Operations between two vectors do not make sense unless both vectors are in the same space. So you must either transform the camera position into object space or transform the object position into camera space. I would suggest the latter, since you already likely have a matrix lying around for doing that for other reasons (lighting, etc).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-08-06T15:26:22.720" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9052" PostTypeId="1" AcceptedAnswerId="9059" CreationDate="2019-08-06T22:26:38.923" Score="0" ViewCount="80" Body="&lt;p&gt;A friend of mine offers a live-stream via TCP. I can view the live-stream in a browser by fetching it via web-socket. What I want to achieve is to segregate the video into frames. Furthermore, the frames have to be saved to disk as images (e.g. png). I don't want to use a screen recording tool, though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My idea was to access the graphics card buffer via OpenGL or any other library and get every frame of the video live stream there. I just don't know if this is possible and where to start. Of course I know that every more or less modern graphics card has its own frame buffer. Is it possible to access this buffer and get every frame during the live stream is played in the browser?&lt;/p&gt;&#xA;" OwnerUserId="3377" LastActivityDate="2019-08-08T18:22:19.383" Title="Access frames of livestream" Tags="&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9053" PostTypeId="1" AcceptedAnswerId="9121" CreationDate="2019-08-07T08:25:00.010" Score="2" ViewCount="114" Body="&lt;p&gt;Is there any way to compute the volume when a sphere intersects a AABB(cube), with different centers. Also i want to be able given a percentage of sphere's volume to  to place the sphere's center in a point in 3D space where it intersects the AABB and satisfies that intersected volume. &lt;/p&gt;&#xA;" OwnerUserId="10468" LastActivityDate="2019-09-06T06:30:13.217" Title="Volume of Intersection of Cube and Sphere" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9054" PostTypeId="1" CreationDate="2019-08-07T13:02:07.563" Score="2" ViewCount="301" Body="&lt;p&gt;Suppose there is a frame, which is larger that the device memory (I mean, dozens of Gb). And I would like to render to it from a set of textures, which is larger than the host memory (I mean, dozens to hundreds of Gb). Each texture is rendered to a different part of the frame.&lt;br&gt;&#xA;To give more context, I'm baking the texture of a 3D-model, using its several projections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I see two ways to handle it.&lt;br&gt;&#xA;1. Go out of core texture-first, i.e. for each texture perform rendering several times to render each part of the frame.&lt;br&gt;&#xA;2. Go out of core frame-first, i.e. for each frame part load every texture and render the frame part, then shift frame part and repeat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first way is definitely unfeasible, as PCI throughput is insufficient to load-unload the whole memory of a device for each renderpass.&lt;br&gt;&#xA;The second way is much better, but it does not scale with frame dimensions, as it requires loading all the textures from disk and rendering them for each part of the frame.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, is there any alternative to this I miss?&lt;/p&gt;&#xA;" OwnerUserId="10806" LastActivityDate="2019-08-07T13:02:07.563" Title="Out of core rendering" Tags="&lt;algorithm&gt;&lt;vulkan&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9055" PostTypeId="1" AcceptedAnswerId="9058" CreationDate="2019-08-08T11:43:00.450" Score="2" ViewCount="79" Body="&lt;p&gt;Input: Triangles which make up an arbitrary shape. Each triangle is represented by 3 3D points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Output: A set of particles which fills up the inside of the object (see image).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.nvidia.com/sites/all/modules/custom/gpugems/books/GPUGems3/elementLinks/29fig03.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://developer.nvidia.com/sites/all/modules/custom/gpugems/books/GPUGems3/elementLinks/29fig03.jpg&quot; alt=&quot;Particles generated from a shape&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have read the description made by &lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch29.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;GPU-Gems&lt;/a&gt;, and tried to implement the proposed solution that don't make the computations on the GPU. I have tried to take each triangle one at a time and see if they intersect with lines, and if so store the z-value which I later used to generate particles. This gave bad results, and in theory it is possible for a line to intersect with a lone point which would cause a bug.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone tell me how to easily on the CPU side create a set of particles that represent a shape? Where the shape is defined as a set of triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I prefer a solution that is simple and works well rather than an efficient solution that can have bugs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit:&lt;/strong&gt; I re-checked my code, and I found that I was not sorting the z-value arrays correctly like I thought I did, after fixing this I got a good result! If anyone still wants to answer this question that is ok, but I consider my problem to be solved now.&lt;/p&gt;&#xA;" OwnerUserId="11024" LastEditorUserId="11024" LastEditDate="2019-08-08T17:43:52.840" LastActivityDate="2019-08-08T17:52:16.307" Title="Represent shape as particles" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;&lt;simulation&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9056" PostTypeId="1" CreationDate="2019-08-08T14:45:13.807" Score="1" ViewCount="28" Body="&lt;p&gt;I have a 2-manifold with boundary, built with marching cubes. Are there any well-known algorithms for smoothing its boundary edges?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the papers I found are concerned with smoothing the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="11025" LastActivityDate="2019-08-08T14:45:13.807" Title="Boundary Smoothing Algorithms" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9058" PostTypeId="2" ParentId="9055" CreationDate="2019-08-08T17:52:16.307" Score="1" Body="&lt;p&gt;Solution: Check for the minimum x,y,z value for all points. Add these values multiplied by (-1) to all points in order to guarantee that all points are not negative. Then take the largest point and subtract with the minimum point (max and minimum x y z) in order to get a cube-like bound for the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then divide this cube by an arbitrary size constant representing the radius of each particle. Now you should have a 2D array for z-values, such that for any x, y position you can quickly store z-values that you find intersecting lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each triangle in the mesh, check all possible that have a large or small enough x-y value for intersections with a line going through the whole cube. If there is an intersection, save the z-value in the x-y array for z-values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Lastly loop through each possible z-values in the imaginary cube and check if it has an odd number of z-value hits before the current z-value. If that is the case, then we know that there is a particle here. Don't forget to add the minimum x,y,z values that we added in the beginning in order to make the particles have the correct positions again.&lt;/p&gt;&#xA;" OwnerUserId="11024" LastActivityDate="2019-08-08T17:52:16.307" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9059" PostTypeId="2" ParentId="9052" CreationDate="2019-08-08T18:22:19.383" Score="1" Body="&lt;p&gt;I wouldn't recommend trying to write this code yourself. It's not a question of using into OpenGL - which won't get you another process' framebuffer - but of asking the OS. This is not at all easy to do, and it's work you don't need to do yourself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Depending on what the streaming protocol is, the easiest way might be just to write or use a client for that protocol directly instead of hooking another application. Failing that, a screen capture tool such as &lt;a href=&quot;https://obsproject.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OBS&lt;/a&gt; can already do what you want. It can capture another application's frames or your desktop with relative efficiency. You can set up overlays or write a plugin to manipulate the video the way you want. If you access the stream through a web browser, you might not even need to capture a window: it has the built-in feature of being able to render into your video a web browser component it runs itself (you tell it what URL to point to) without having to run a separate web browser and capture it. This feature is how most streamers get things like a Twitch chat view, score board, or timings onto their video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OBS has &lt;a href=&quot;https://obsproject.com/docs/&quot; rel=&quot;nofollow noreferrer&quot;&gt;a C API for writing fast, native plugins as well as Python and Lua interfaces&lt;/a&gt;. And it's open-source, so in the unlikely event you can't write a plugin to do what you want, you could hack it into a private fork directly.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-08-08T18:22:19.383" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9060" PostTypeId="1" CreationDate="2019-08-09T05:10:33.003" Score="2" ViewCount="141" Body="&lt;p&gt;I have been experiencing issues over the past few days with implementing SSR on water into my engine. Looking straight forward, it appears to be alright. &#xA;However, when I look up or down, the reflections become shrunken or stretched. (Ignore colors being incorrect, and the sides of blocks looking messed up- that's not the problem)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/akZAv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/akZAv.png&quot; alt=&quot;This is the water looking decent.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, this is what happens when I look down. The reflections become increasingly stretched on the Y-axis.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ACztN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ACztN.png&quot; alt=&quot;The reflections become increasingly stretched and distorted the further down we look.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, when I look down further, the water begins to reflect terrain that is underneath it in a very distorted manner (when clearly it shouldn't, as the water is 100% flat and all the normals are (0, 1, 0)). It's like the rays are being cast down instead of up.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/FxAQQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FxAQQ.png&quot; alt=&quot;Water looking severely unwater-like when looking low.k&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Similarly, when I look up, the reflections become increasingly squashed and &quot;disappear&quot;.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dMIvr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dMIvr.png&quot; alt=&quot;Reflections being smashed when looking up.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My fragment shader code is primarily based on &lt;a href=&quot;https://gamedev.stackexchange.com/questions/165073/noise-when-using-sslr-screen-space-local-reflections&quot;&gt;this post&lt;/a&gt;, but uses a binary search algorithm from &lt;a href=&quot;https://gitlab.com/congard/algine/blob/master/src/resources/shaders/fragment_screenspace_shader.glsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; to refine the results. Here is the relevant fragment shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;flat in vec3 camNormal; // view space normal&#xA;uniform mat4 inv_projection;&#xA;uniform sampler2D ssr_depth; // straight-up depth&#xA;uniform sampler2D ssr_albedoSpec; // used solely for color information here&#xA;&#xA;// calculate view position of current fragment&#xA;vec3 calcViewPosition(in vec2 texCoord)&#xA;{&#xA;  // Combine UV &amp;amp; depth into XY &amp;amp; Z (NDC)&#xA;  vec3 rawPosition = vec3(texCoord, gl_FragCoord.z);&#xA;&#xA;  // Convert from (0, 1) range to (-1, 1)&#xA;  vec4 ScreenSpacePosition = vec4(rawPosition * 2. - 1., 1.);&#xA;&#xA;  // Undo Perspective transformation to bring into view space&#xA;  vec4 ViewPosition = inv_projection * ScreenSpacePosition;&#xA;&#xA;  // Perform perspective divide and return&#xA;  return ViewPosition.xyz / ViewPosition.w;&#xA;}&#xA;&#xA;// calculate view position with depth buffer&#xA;vec3 calcViewPositionDepthTex(in vec2 texCoord)&#xA;{&#xA;  vec3 rawPosition = vec3(texCoord, texture(ssr_depth, texCoord).r);&#xA;  vec4 ScreenSpacePosition = vec4(rawPosition * 2. - 1., 1.);&#xA;  vec4 ViewPosition = inv_projection * ScreenSpacePosition;&#xA;  return ViewPosition.xyz / ViewPosition.w;&#xA;}&#xA;&#xA;vec2 binarySearch(inout vec3 dir, inout vec3 hitCoord, inout float dDepth)&#xA;{&#xA;  float depth;&#xA;&#xA;  vec4 projectedCoord;&#xA;&#xA;  for(int i = 0; i &amp;lt; 20; i++)&#xA;  {&#xA;    projectedCoord = u_proj * vec4(hitCoord, 1.0);&#xA;    projectedCoord.xy /= projectedCoord.w;&#xA;    projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;&#xA;&#xA;    depth = calcViewPositionDepthTex(projectedCoord.xy).z;&#xA;&#xA;    dDepth = hitCoord.z - depth;&#xA;&#xA;    dir *= 0.5;&#xA;    if(dDepth &amp;gt; 0.0)&#xA;      hitCoord += dir;&#xA;    else&#xA;      hitCoord -= dir;    &#xA;  }&#xA;&#xA;  projectedCoord = u_proj * vec4(hitCoord, 1.0);&#xA;  projectedCoord.xy /= projectedCoord.w;&#xA;  projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;&#xA;&#xA;  return vec2(projectedCoord.xy);&#xA;}&#xA;&#xA;vec2 rayCast(vec3 dir, inout vec3 hitCoord, out float dDepth)&#xA;{&#xA;  dir *= .3;&#xA;&#xA;  for (int i = 0; i &amp;lt; 40; i++)&#xA;  {&#xA;    hitCoord += dir; &#xA;&#xA;    vec4 projectedCoord = u_proj * vec4(hitCoord, 1.0);&#xA;    projectedCoord.xy /= projectedCoord.w;&#xA;    projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5; &#xA;&#xA;    float depth = calcViewPositionDepthTex(projectedCoord.xy).z;&#xA;    dDepth = hitCoord.z - depth;&#xA;&#xA;    if(dDepth &amp;lt; 0.0)&#xA;      return binarySearch(dir, hitCoord, dDepth);&#xA;  }&#xA;&#xA;  return vec2(-1.0f);&#xA;}&#xA;&#xA;vec3 ssr()&#xA;{&#xA;  // compute texture coordinates&#xA;  ssTexCoords.x = gl_FragCoord.x / textureSize(ssr_positions, 0).x;&#xA;  ssTexCoords.y = gl_FragCoord.y / textureSize(ssr_positions, 0).y;&#xA;  vec2 texCoord = ssTexCoords;&#xA;&#xA;  // normal at initial ray position&#xA;  vec3 normal = camNormal;&#xA;  vec3 fViewPos = calcViewPosition(texCoord);&#xA;&#xA;  // Reflection vector&#xA;  vec3 reflected = normalize(reflect(normalize(fViewPos), normalize(normal)));&#xA;&#xA;  // Ray cast&#xA;  vec3 hitPos = fViewPos;&#xA;  float dDepth;&#xA;  float minRayStep = .05f;&#xA;  vec2 coords = rayCast(reflected * max(minRayStep, -fViewPos.z), hitPos, dDepth);&#xA;  if (coords != vec2(-1.0))&#xA;    return mix(vColor.rgb, texture(ssr_albedoSpec, coords).rgb / 2, .5005);&#xA;  else&#xA;    return vColor.ggg; // ray failed to intersect (use sky color in the future)&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The color returned from ssr() is currently 100% equal to the final fragment color to view the results most directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The primary deviation I make in this implementation is that instead of getting the depth and normal of the initial ray from stored textures, I am getting it from the values passed to the &lt;strong&gt;current fragment&lt;/strong&gt;. This is because the water is drawn in a separate forward-pass, and is never drawn to the depth or normal maps. Therefore I am using gl_FragCoord.z for the depth, and view-space normal passed from the vertex shader as the normal. I understand it is less expandable this way, but I only intend for water to be reflective.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I initially suspected that the problem was related to the normals of the water, but displaying the water normals (shifted from -1-1 range to 0-1) showed it to correctly be green. This has led me to believe the issue either has to do with A) the reflected angle being incorrect, which would mean calcViewPos is incorrect; or B) some of the information being used that I assumed to be correct to use in this context was not.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have very little experience with ray-tracing (and graphics programming in general), so my problem might be something really basic that I overlooked.&lt;/p&gt;&#xA;" OwnerUserId="11029" LastActivityDate="2019-08-09T05:10:33.003" Title="Screen space reflections become warped when looking up or down" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;reflection&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9063" PostTypeId="1" CreationDate="2019-08-10T15:35:28.547" Score="2" ViewCount="169" Body="&lt;p&gt;I started a ray tracing &lt;a href=&quot;https://github.com/Speterius/ray_tracing/&quot; rel=&quot;nofollow noreferrer&quot;&gt;project&lt;/a&gt; in Python. I made a CUDA kernel and a trace() function for each pixel. It works perfectly when calculating intersections, shadows and lambert shading, however when I introduce a reflection from the surface of a sphere I get a 'band' around the edge of the projected sphere disk and I cannot figure out why.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Image results: &lt;a href=&quot;https://imgur.com/a/LoXOyl5&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://imgur.com/a/LoXOyl5&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2&gt;My reflection algorithm:&lt;/h2&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Find point &lt;strong&gt;P&lt;/strong&gt; of the intersection.&lt;/li&gt;&#xA;&lt;li&gt;Find normal vector &lt;strong&gt;N&lt;/strong&gt; at the intersection with &lt;strong&gt;C&lt;/strong&gt; being the sphere center:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    N = P - C&#xA;    N = N / norm(N)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;Find reflection vector &lt;strong&gt;R&lt;/strong&gt; using (where D is the original ray direction:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    R = D - 2 * (D * N ) * N&#xA;    R = R / norm(R)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol start=&quot;4&quot;&gt;&#xA;&lt;li&gt;Shift point &lt;strong&gt;P&lt;/strong&gt; along &lt;strong&gt;R&lt;/strong&gt; a little bit (to avoid reflection acne, adding this didn't solve the problem)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    P = P + 1e-4 * R&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol start=&quot;5&quot;&gt;&#xA;&lt;li&gt;Call the ray trace function (only one more time) again as:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    color_refl = trace(ray_origin=P, ray_direction=R) &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ol start=&quot;6&quot;&gt;&#xA;&lt;li&gt;Add the reflected color using:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    color = color + color_refl * reflect_intensity&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Notes: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Between step 2 and step 3 I calculate the Lambert shading which works quite well.&lt;/li&gt;&#xA;&lt;li&gt;Reflections that bounce off a plane work perfectly.&lt;/li&gt;&#xA;&lt;li&gt;I use a CUDA kernel which does not support recursive function calls, so I made another trace function with a different name that doesn't calculate reflections. (that's why there is only one reflection call)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Here is the source code for the trace and reflection trace functions:&#xA;&lt;a href=&quot;https://github.com/Speterius/ray_tracing/blob/master/cuda_ray_tracing.py&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Speterius/ray_tracing/blob/master/cuda_ray_tracing.py&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11035" LastActivityDate="2019-08-10T16:48:01.383" Title="Strange sphere reflection effects in ray tracing project. I cannot figure out what causes them" Tags="&lt;raytracing&gt;&lt;reflection&gt;&lt;artifacts&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9064" PostTypeId="2" ParentId="9063" CreationDate="2019-08-10T16:48:01.383" Score="4" Body="&lt;p&gt;The issue was caused by an incorrect calculation of the reflection direction vector.&#xA;With D ray direction and N the normal vector:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;R = D - 2 * dot(D, N) * N&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The issue was caused by calculating the components of R as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;R[i] = D[i] - 2 * (D[i] * N[i]) * N[i]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It took me a while to find the mistake because this produced a correct reflection with the horizontal plane.&lt;/p&gt;&#xA;" OwnerUserId="11035" LastActivityDate="2019-08-10T16:48:01.383" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9065" PostTypeId="1" CreationDate="2019-08-12T08:27:41.967" Score="2" ViewCount="341" Body="&lt;p&gt;I am trying to write a ray-tracer. The lighting part is proving to work but not accurately. To debug I simplified the scene to a single sphere centered at the origin with a radius of 1 and a point light shining from above (0, 2, 0). The camera is at (0, 0, 4).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;ambient 0.2 0.2 0.2&#xA;specular 0 0 0&#xA;shininess 1&#xA;emission 0 0 0&#xA;diffuse 0 1 1 &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image I'm rendering seems wrong - should its cutoff be lower closer to the equator of the sphere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help would be appreciated.&lt;a href=&quot;https://i.stack.imgur.com/AWFWt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AWFWt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11041" LastActivityDate="2019-08-23T05:53:28.480" Title="Diffuse lighting calculations in ray-tracer" Tags="&lt;raytracing&gt;&lt;diffuse&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9067" PostTypeId="2" ParentId="9065" CreationDate="2019-08-12T15:29:31.173" Score="4" Body="&lt;p&gt;Some elementary trigonometry tells you what to expect from this situation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TluQN.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TluQN.png&quot; alt=&quot;Diagram of the situation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The angle to see the shadow terminator is marked on the diagram, and a use of SOHCAHTOA tells you it's &lt;span class=&quot;math-container&quot;&gt;$\cos^{-1}\tfrac{1}{2} = 60^\circ$&lt;/span&gt;. Yours looks higher than that so your intuition seems correct. Stepping through the lighting code will help you see where it's going wrong, and you should consider writing unit tests for it, so that it's easier to provoke bugs like this in isolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Something else you might try to help narrow down the problem space is replacing the diffuse calculation with 1 iff &lt;span class=&quot;math-container&quot;&gt;$L.N &amp;gt; 0$&lt;/span&gt; (i.e. if the light is in front of the surface), 0 o/w. That will give you a sharp line instead of a gradient, and if that sharp line is in the wrong place, you know the input vectors are wrong. If it's in the right place, the problem is in the diffuse shader itself.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-08-12T15:29:31.173" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9068" PostTypeId="1" AcceptedAnswerId="9069" CreationDate="2019-08-13T06:52:51.800" Score="2" ViewCount="268" Body="&lt;p&gt;In newer OpenGL it's encouraged to use shaders and pass the model-view-projection as parameters. But what if I drew a complex object, and wanted to translate/rotate it and draw many copies? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example I wanted to do something like this :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;{&#xA;    shader.bind();&#xA;&#xA;    glm::mat4 projectionMatrix = glm::perspective(20.0f, (float)SCRWIDTH/(float)SCRHEIGHT, 0.0f, 100.0f);&#xA;    glm::mat4 viewMatrix = glm::lookAt(&#xA;        glm::vec3(0, 0, 2), &#xA;        glm::vec3(0, 0, 0), &#xA;        glm::vec3(0, 1, 0)&#xA;    );&#xA;    glm::mat4 modelMatrix = glm::toMat4(quaternion);&#xA;    glm::mat4 MVP = projectionMatrix * viewMatrix * modelMatrix;&#xA;    GLint loc_MVP = glGetUniformLocation(shader.id(), &quot;MVP&quot;);    &#xA;    glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, &amp;amp;MVP[0][0]);&#xA;&#xA;    glTranslatef(1,0,0);&#xA;    gluSphere(...);&#xA;    glTranslatef(2,0,0);&#xA;    gluSphere(...);&#xA;&#xA;    shader.unbind();&#xA;}&#xA;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But my experiment shows that the glTranslatef doesn't work here, all the spheres are rendered at (0,0,0). I don't want to call the shader 100 times, each time calculating a different MVP matrix. Is there any easy way around this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vertex shader looks like this :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;uniform mat4 MVP;&#xA;in vec3 in_Position;&#xA;&#xA;void main(void) {&#xA;    gl_Position = MVP * vec4(in_Position, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11047" LastActivityDate="2019-08-13T08:45:07.247" Title="Use glTranslatef and shaders?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;transformations&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9069" PostTypeId="2" ParentId="9068" CreationDate="2019-08-13T08:45:07.247" Score="1" Body="&lt;p&gt;Update the uniform and draw again.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;auto tMVP = glm::translate(MVP, glm::vec3(1,0,0));&#xA;glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, &amp;amp;tMVP[0][0]);&#xA;gluSphere(...);&#xA;&#xA;tMVP = glm::translate(MVP, glm::vec3(2,0,0));&#xA;glUniformMatrix4fv(loc_MVP, 1, GL_FALSE, &amp;amp;MVP[0][0]);&#xA;gluSphere(...);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Using &lt;code&gt;glTranslate&lt;/code&gt; would have done the &lt;em&gt;exact same thing&lt;/em&gt; behind the scenes.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;You can instead use instancing instead where you upload all the transforms into a buffer and then tell the gpu to use that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However the more portable way involves allocating a vertex attribute for the data. This involves using &lt;code&gt;glVertexAttribDivisor&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So a full mat4 would need 4 vertex attributes. You can decrease that to 2 by separating out the translation as a vec3 and the rotation as a quaternion and pass the view-perspective as a uniform and combining it all in the vertex shader.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-08-13T08:45:07.247" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9071" PostTypeId="1" CreationDate="2019-08-13T16:54:41.710" Score="1" ViewCount="94" Body="&lt;p&gt;The code is&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glColor3f(1, 1, 1);&#xA;gluSphere(gluq, 0.2, 10, 10);&#xA;&#xA;glColor3f(1, 0, 0);&#xA;glTranslatef(1, 0, 0);&#xA;gluSphere(gluq, 0.2, 10, 10);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In short, when I draw directly to screen, it's correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZKAP9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZKAP9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But when I create a framebuffer object, attach a texture as color component, draw on the fbo, then draw the texture as rectangle on to the screen, the colors went wrong&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4fqnS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4fqnS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems like the right sphere at (1,0,0) changed the color of the sphere drawn before it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And even more bizzare is that if i change the first sphere's color to blue (0,0,1), it becomes black after the second sphere is drawn.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HZpHt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HZpHt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I rendered it is like this :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;{&#xA;    glViewport(0, 0, SCRWIDTH, SCRHEIGHT);&#xA;    glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45, (float)SCRWIDTH / (float)SCRHEIGHT, 0.0f, 100.0f);&#xA;    glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);&#xA;&#xA;&#xA;    glColor3f(0, 0, 1);&#xA;    gluSphere(gluq, 0.2, 10, 10);&#xA;&#xA;    glColor3f(1, 0, 0);&#xA;    glTranslatef(1, 0, 0);&#xA;    gluSphere(gluq, 0.2, 10, 10);&#xA;&#xA;}&#xA;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;glBindTexture(GL_TEXTURE_2D, fbo_tex[0]);&#xA;glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, SCRWIDTH, SCRHEIGHT, 0, -1, 1);&#xA;glMatrixMode(GL_MODELVIEW); glLoadIdentity();&#xA;{&#xA;    glBegin(GL_QUADS);&#xA;    glTexCoord2f(0, 0); glVertex3i(0, 0, 0);&#xA;    glTexCoord2f(0, 1); glVertex3i(0, SCRHEIGHT, 0);&#xA;    glTexCoord2f(1, 1); glVertex3i(SCRWIDTH, SCRHEIGHT, 0);&#xA;    glTexCoord2f(1, 0); glVertex3i(SCRWIDTH, 0, 0);&#xA;    glEnd();&#xA;}&#xA;glBindTexture(GL_TEXTURE_2D, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I created the fbo and texture like this :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;fbo_tex[0]);&#xA;&#xA;glBindTexture(GL_TEXTURE_2D, fbo_tex[0]);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, SCRWIDTH, SCRHEIGHT, 0, GL_RGBA, GL_FLOAT, 0);&#xA;glBindTexture(GL_TEXTURE_2D, 0);&#xA;&#xA;glGenFramebuffers(1, &amp;amp;fbo[0]);&#xA;glBindFramebuffer(GL_FRAMEBUFFER, fbo[0]);&#xA;glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, fbo_tex[0], 0);&#xA;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If feels like that consequtive glColor3f caused the colors to mix, taking the minimum RGB values of previous used colors. So white becomes red, but blue turns to black. And the first sphere has the color written to the texture, then the second sphere somehow picks the mixed color and overwrite the first one's pixels. How can I fix this?&lt;/p&gt;&#xA;" OwnerUserId="11047" LastActivityDate="2020-09-15T08:04:55.590" Title="Weird glColor3f results in framebuffer objects" Tags="&lt;opengl&gt;&lt;color&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9072" PostTypeId="1" AcceptedAnswerId="9073" CreationDate="2019-08-13T17:54:46.980" Score="0" ViewCount="116" Body="&lt;p&gt;I've managed to write a &quot;small&quot; Vulkan program that outputs a solid color using compute shader directly to swapchain.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, it doesn't work properly. ImageMemoryBarriers I've setup don't transition the layouts the way they should and only every third swapchain image (it has three in my implementation) is actually rendered to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Two most interesting functions are the one where I record the command buffers and the one where is submit them to the compute/present queue:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recording:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void createCommandBuffers() {&#xA;    commandBuffers.resize(swapchainImages.size());&#xA;&#xA;    vk::CommandBufferAllocateInfo allocInfo = {};&#xA;    allocInfo.commandPool = commandPool.get();&#xA;    allocInfo.level = vk::CommandBufferLevel::ePrimary;&#xA;    allocInfo.commandBufferCount = (uint32_t)commandBuffers.size();&#xA;&#xA;    commandBuffers = device-&amp;gt;allocateCommandBuffersUnique(allocInfo);&#xA;&#xA;    for (size_t i = 0; i &amp;lt; commandBuffers.size(); ++i) {&#xA;        vk::CommandBufferBeginInfo beginInfo = {};&#xA;        beginInfo.flags = vk::CommandBufferUsageFlagBits::eSimultaneousUse;&#xA;&#xA;        commandBuffers[i]-&amp;gt;begin(beginInfo);&#xA;&#xA;        commandBuffers[i]-&amp;gt;bindPipeline(vk::PipelineBindPoint::eCompute, *pipeline);&#xA;        commandBuffers[i]-&amp;gt;bindDescriptorSets(vk::PipelineBindPoint::eCompute, *pipelineLayout, 0, descriptorSets[i], nullptr);&#xA;&#xA;        vk::ImageMemoryBarrier imageMemoryBarrier = {};&#xA;        imageMemoryBarrier.oldLayout = vk::ImageLayout::eUndefined;&#xA;        imageMemoryBarrier.newLayout = vk::ImageLayout::eGeneral;&#xA;        imageMemoryBarrier.image = swapchainImages[i];&#xA;        imageMemoryBarrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;&#xA;        imageMemoryBarrier.subresourceRange.baseMipLevel = 0;&#xA;        imageMemoryBarrier.subresourceRange.levelCount = 1;&#xA;        imageMemoryBarrier.subresourceRange.baseArrayLayer = 0;&#xA;        imageMemoryBarrier.subresourceRange.layerCount = 1;&#xA;&#xA;        commandBuffers[i]-&amp;gt;pipelineBarrier(&#xA;            vk::PipelineStageFlagBits::eTopOfPipe,&#xA;            vk::PipelineStageFlagBits::eComputeShader,&#xA;            vk::DependencyFlagBits::eByRegion,&#xA;            nullptr,&#xA;            nullptr,&#xA;            imageMemoryBarrier);&#xA;&#xA;        commandBuffers[i]-&amp;gt;dispatch(WIDTH, HEIGHT, 1);&#xA;&#xA;        imageMemoryBarrier = {};&#xA;        imageMemoryBarrier.oldLayout = vk::ImageLayout::eGeneral;&#xA;        imageMemoryBarrier.newLayout = vk::ImageLayout::ePresentSrcKHR;&#xA;        imageMemoryBarrier.image = swapchainImages[i];&#xA;        imageMemoryBarrier.subresourceRange.aspectMask = vk::ImageAspectFlagBits::eColor;&#xA;        imageMemoryBarrier.subresourceRange.baseMipLevel = 0;&#xA;        imageMemoryBarrier.subresourceRange.levelCount = 1;&#xA;        imageMemoryBarrier.subresourceRange.baseArrayLayer = 0;&#xA;        imageMemoryBarrier.subresourceRange.layerCount = 1;&#xA;&#xA;        commandBuffers[i]-&amp;gt;pipelineBarrier(&#xA;            vk::PipelineStageFlagBits::eComputeShader,&#xA;            vk::PipelineStageFlagBits::eBottomOfPipe,&#xA;            vk::DependencyFlagBits::eByRegion,&#xA;            nullptr,&#xA;            nullptr,&#xA;            imageMemoryBarrier);&#xA;&#xA;        commandBuffers[i]-&amp;gt;end();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Submitting:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void drawFrame() {&#xA;    device-&amp;gt;waitForFences(*inFlightFences[currentFrame], VK_TRUE, std::numeric_limits&amp;lt;uint64_t&amp;gt;::max());&#xA;    device-&amp;gt;resetFences(*inFlightFences[currentFrame]);&#xA;&#xA;    uint32_t imageIndex;&#xA;&#xA;    try {&#xA;        device-&amp;gt;acquireNextImageKHR(*swapchain, std::numeric_limits&amp;lt;uint64_t&amp;gt;::max(), *imageAvailableSemaphores[currentFrame], {}, &amp;amp;imageIndex);&#xA;    }&#xA;    catch (vk::OutOfDateKHRError) {&#xA;        recreateSwapchain();&#xA;        return;&#xA;    }&#xA;&#xA;    vk::SubmitInfo submitInfo = {};&#xA;&#xA;    vk::Semaphore waitSemaphores[] = { *imageAvailableSemaphores[currentFrame] };&#xA;    submitInfo.waitSemaphoreCount = 1;&#xA;    submitInfo.pWaitSemaphores = &amp;amp;waitSemaphores[0];&#xA;&#xA;    submitInfo.commandBufferCount = 1;&#xA;    submitInfo.pCommandBuffers = &amp;amp;*commandBuffers[imageIndex];&#xA;&#xA;    vk::Semaphore signalSemaphores[] = { *renderFinishedSemaphores[currentFrame] };&#xA;    submitInfo.signalSemaphoreCount = 1;&#xA;    submitInfo.pSignalSemaphores = &amp;amp;signalSemaphores[0];&#xA;&#xA;    vk::PipelineStageFlags waitStages[] = { vk::PipelineStageFlagBits::eTopOfPipe };&#xA;    submitInfo.pWaitDstStageMask = waitStages;&#xA;&#xA;    computeQueue.submit(submitInfo, *inFlightFences[currentFrame]);&#xA;&#xA;    vk::PresentInfoKHR presentInfo = {};&#xA;    presentInfo.waitSemaphoreCount = 1;&#xA;    presentInfo.pWaitSemaphores = &amp;amp;signalSemaphores[0];&#xA;&#xA;    vk::SwapchainKHR swapchains[] = { *swapchain };&#xA;    presentInfo.swapchainCount = 1;&#xA;    presentInfo.pSwapchains = swapchains;&#xA;    presentInfo.pImageIndices = &amp;amp;imageIndex;&#xA;&#xA;    try {&#xA;        vk::Result result = computeQueue.presentKHR(presentInfo);&#xA;        if (result == vk::Result::eSuboptimalKHR || framebufferResized) {&#xA;            framebufferResized = false;&#xA;            recreateSwapchain();&#xA;        }&#xA;    }&#xA;    catch (vk::OutOfDateKHRError) {&#xA;        framebufferResized = false;&#xA;        recreateSwapchain();&#xA;    }&#xA;&#xA;    currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The last function is basically the main loop at this point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been staring at it for a while now and I don't get it. I don't know what is wrong. This is also the first Vulkan program I've written semi independently, so there's that as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the rest of the code, if something is unclear: &lt;a href=&quot;https://pastebin.com/bGS8Af6t&quot; rel=&quot;nofollow noreferrer&quot;&gt;pastebin&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, for completeness sake, here's the shader, as simple as can be:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout (binding = 0, rgba8) uniform image2D resultImage;&#xA;&#xA;void main() {&#xA;    vec4 green = vec4(0.0, 1.0, 0.0, 1.0);&#xA;&#xA;    imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), green);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="5215" LastEditorUserId="5215" LastEditDate="2019-08-13T19:22:52.057" LastActivityDate="2019-08-15T10:20:37.777" Title="Only each third image in swapchain is being used, causing flickering" Tags="&lt;vulkan&gt;&lt;compute-shader&gt;&lt;synchronization&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9073" PostTypeId="2" ParentId="9072" CreationDate="2019-08-14T16:50:08.270" Score="0" Body="&lt;p&gt;I have managed to find the culprit:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    std::vector&amp;lt;vk::WriteDescriptorSet&amp;gt; writeDescriptorSets;&#xA;&#xA;    for (int i = 0; i &amp;lt; swapchainImages.size(); ++i) {&#xA;        vk::DescriptorImageInfo descriptorImageInfo = {};&#xA;        descriptorImageInfo.imageView = *swapchainImageViews[i];&#xA;        descriptorImageInfo.imageLayout = vk::ImageLayout::eGeneral;&#xA;&#xA;        vk::WriteDescriptorSet writeDescriptorSet = {};&#xA;        writeDescriptorSet.dstSet = descriptorSets[i];&#xA;        writeDescriptorSet.dstBinding = 0;&#xA;        writeDescriptorSet.descriptorCount = 1;&#xA;        writeDescriptorSet.descriptorType = vk::DescriptorType::eStorageImage;&#xA;        writeDescriptorSet.pImageInfo = &amp;amp;descriptorImageInfo;&#xA;        writeDescriptorSets.push_back(writeDescriptorSet);&#xA;    }&#xA;&#xA;    device-&amp;gt;updateDescriptorSets((uint32_t)writeDescriptorSets.size(), writeDescriptorSets.data(), 0, nullptr);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Do you see it yet?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What if I told you this fixed it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    std::vector&amp;lt;vk::WriteDescriptorSet&amp;gt; writeDescriptorSets;&#xA;    std::vector&amp;lt;vk::DescriptorImageInfo&amp;gt; descriptorImageInfos;&#xA;&#xA;    for (int i = 0; i &amp;lt; swapchainImages.size(); ++i) {&#xA;        vk::DescriptorImageInfo descriptorImageInfo = {};&#xA;        descriptorImageInfo.imageView = *swapchainImageViews[i];&#xA;        descriptorImageInfo.imageLayout = vk::ImageLayout::eGeneral;&#xA;        descriptorImageInfos.push_back(descriptorImageInfo);&#xA;&#xA;        vk::WriteDescriptorSet writeDescriptorSet = {};&#xA;        writeDescriptorSet.dstSet = descriptorSets[i];&#xA;        writeDescriptorSet.dstBinding = 0;&#xA;        writeDescriptorSet.descriptorCount = 1;&#xA;        writeDescriptorSet.descriptorType = vk::DescriptorType::eStorageImage;&#xA;        writeDescriptorSet.pImageInfo = &amp;amp;descriptorImageInfos[i];&#xA;        writeDescriptorSets.push_back(writeDescriptorSet);&#xA;    }&#xA;&#xA;    device-&amp;gt;updateDescriptorSets((uint32_t)writeDescriptorSets.size(), writeDescriptorSets.data(), 0, nullptr);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;vk::DescriptorImageInfo for the first two images was being overwritten before updateDescriptorSets was called.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember kids, when you could swear you're treating several things in the absolute same way, but they somehow behave differently (in most cases, only the last one is working), you're probably overwriting something somewhere, or something is going out of scope before you thought it would.&lt;/p&gt;&#xA;" OwnerUserId="5215" LastEditorUserId="5215" LastEditDate="2019-08-15T10:20:37.777" LastActivityDate="2019-08-15T10:20:37.777" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9074" PostTypeId="1" CreationDate="2019-08-15T07:39:25.730" Score="1" ViewCount="211" Body="&lt;p&gt;I've been reading this &lt;a href=&quot;http://in2gpu.com/2015/05/17/view-matrix/&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt; about the look-at function. I don't understand the part when they're trying to inverse the matrix N.&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M1tEW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M1tEW.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;They say that R is orthogonal because all its row and column vectors are orthogonal unit vectors.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/abmQx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/abmQx.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;This means that for example  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$[s_x, v_x, f_x, 0]^T * [s_x, v_x, f_x, 0]^T = 1$&lt;/span&gt;   &lt;/p&gt;&#xA;&#xA;&lt;p&gt;or &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$[s_x, v_x, f_x, 0]^T * [s_y, v_y, f_y, 0]^T = 0$&lt;/span&gt;,  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;but why?&#xA;Could anyone explain it to me or give a hint about why it's true?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;br&gt;&#xA;I guess I have found the solution:&#xA;I can quite easily prove that &lt;span class=&quot;math-container&quot;&gt;$R^T*R=I$&lt;/span&gt;. So if I could prove that &lt;span class=&quot;math-container&quot;&gt;$R^T*R=I\Longrightarrow R*R^T=I$&lt;/span&gt;, then by definition R is orthogonal.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the following proof correct (I'm not really good at math)?&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$&#xA;R^T*R=I \Longleftrightarrow&#xA;R*(R^T*R)=R*(I) \Longleftrightarrow&#xA;(R*R^T)*R=R \Longleftrightarrow&#xA;R*R^T=I&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="11055" LastEditorUserId="11055" LastEditDate="2019-08-15T13:20:19.443" LastActivityDate="2019-08-15T13:20:19.443" Title="Help with understanding the look-at function (the view matrix)" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;matrix&gt;&lt;camera-matrix&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9075" PostTypeId="1" CreationDate="2019-08-15T19:57:32.690" Score="1" ViewCount="28" Body="&lt;p&gt;So I've been reading Physicall Based Rendering which in section 16.4.3 defines the &quot;image contribution function&quot; to be the following&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I_j = \int_\Omega h_j(X)L(X)d\Omega$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where the variables are defined in the following way as I understand them&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The domain &lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt; is the space of paths in the scene&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; is the &quot;image reconstruction filter&quot; for the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel on a given path. My understanding is that this really only depends on where the path is on image plane.&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$I_j$&lt;/span&gt; is the value of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; is the radiance delivered on a given path&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;They also give the following equation which is just an application of Monte Carlo importance sampling when drawing from a sample distribution &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_\Omega h_j(X)L(X)d\Omega \approx \frac{1}{N}\sum_i^N \frac{h_j(X_i)L(X_i)}{p(X_i)}$$&lt;/span&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Earlier in section 7.8 the define equation 7.12 to be the following&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I(x, y) = \frac{\sum_i f(x - x_i, y - y_i)w(x_i, y_i)L(x_i, y_i)}{\sum_i f(x - x_i, y - y_i)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where the variables are defined in the following way as I understand them&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$(x_i, y_i)$&lt;/span&gt; is the location on the image plane of the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th sample&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$L(x_i, y_i)$&lt;/span&gt; is the radiance delivered to &lt;span class=&quot;math-container&quot;&gt;$(x_i, y_i)$&lt;/span&gt; by the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th&#xA;sample&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$I(x, y)$&lt;/span&gt; is the value of the pixel at &lt;span class=&quot;math-container&quot;&gt;$(x, y)$&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; is a filter function like a tent or sinc filter&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; is a sample contribution weight. For simplicity of this&#xA;question. I'll assume this to just be the constantly &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; function. In&#xA;the later chapters where the &quot;importance function&quot; appears to subsume&#xA;this or be the same thing&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;So for a given pixel &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; at location &lt;span class=&quot;math-container&quot;&gt;$(x, y)$&lt;/span&gt; on the image I interpret &lt;span class=&quot;math-container&quot;&gt;$I(x, y) = I_j$&lt;/span&gt; and for a given sample &lt;span class=&quot;math-container&quot;&gt;$L(X_i) = L(x_i, y_i)$&lt;/span&gt; and given that I'm ignoring &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; the following equation should hold. Taking &lt;span class=&quot;math-container&quot;&gt;$f(X_i) = f(x_i, y_i)$&lt;/span&gt; as well&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\sum_i^N f(X_i)L(X_i)}{\sum_i^N f(X_i)} = \frac{1}{N}\sum_i^N \frac{h_j(X_i)L(X_i)}{p(X_i)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While its clear how to implement &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; it isn't clear to me how to implement &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt;. I considered that &lt;span class=&quot;math-container&quot;&gt;$L(x_i, y_i)$&lt;/span&gt; might actually be &lt;span class=&quot;math-container&quot;&gt;$\frac{L(X_i)}{p(X_i)}$&lt;/span&gt; in the importance sampling case which gets rid of the discrepancy caused by the probability distribution but that implies that &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; must be defined to be the following&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$h_j(X_i) = \frac{N \cdot f(X_i)}{\sum_i^N f(X_i)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it doesn't seem to me that &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; should be dependent on the number of samples &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; which means I must have made a mistake in some assumption that I've made. I made a lot of assumptions to attempt to connect these to equations but I'm still at a loss. What mistakes have I made so far? How does one implement &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; in the first equation from section 16.4.3?&lt;/p&gt;&#xA;" OwnerUserId="3385" LastActivityDate="2019-08-15T19:57:32.690" Title="Image contribution function and reconstruction using filters" Tags="&lt;pathtracing&gt;&lt;physically-based&gt;&lt;filtering&gt;&lt;photo-realistic&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9077" PostTypeId="1" CreationDate="2019-08-16T08:30:05.967" Score="1" ViewCount="86" Body="&lt;p&gt;Is there an efficient algorithm to convert a 3D object described with a set of triangles to a 3D object described with a set of polygons. Polygons can have an arbitrary number of points, more is better. I'd like to minimize the number of polygons necessary to describe the 3D object but it does not have to be optimal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 3D object should stay the same.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Polygons can be non-planar.&lt;/p&gt;&#xA;" OwnerUserId="11062" LastEditorUserId="11062" LastEditDate="2019-08-16T12:42:16.530" LastActivityDate="2019-08-16T19:32:40.680" Title="Convert triangulated object to a polygonized object" Tags="&lt;algorithm&gt;&lt;polygon&gt;&lt;triangulation&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9078" PostTypeId="2" ParentId="9077" CreationDate="2019-08-16T09:19:14.953" Score="-1" Body="&lt;p&gt;I guess what you wanna achieve is mesh simplification. Then those materials can be useful for you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://graphics.stanford.edu/courses/cs468-10-fall/LectureSlides/08_Simplification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphics.stanford.edu/courses/cs468-10-fall/LectureSlides/08_Simplification.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://pages.mtu.edu/~shene/COURSES/cs3621/SLIDES/Simplification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pages.mtu.edu/~shene/COURSES/cs3621/SLIDES/Simplification.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10980" LastActivityDate="2019-08-16T09:19:14.953" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9079" PostTypeId="1" CreationDate="2019-08-16T10:48:06.790" Score="2" ViewCount="116" Body="&lt;p&gt;When working with animating a rig, quaternions are often used for rotations. However sometimes we need to clear rotation along given local axis of a  joint. With quaternions it's not as simple as just clearing out one component of the quaternion. Doing this will clear out the rotation along that axis, but it will also affect rotation along other axes since the W value of quaternion is interdependent on all three axes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Take Blender3D as example. You can key a euler rotation for a given joint. If you then are not satisfied with rotation along say Y axis, you could just remove Y rotation channel for the whole animation. With quaternions this does not work as well. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do animators and riggers handle this problem?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2019-08-16T10:48:06.790" Title="Pitfalls of animating with quaternions" Tags="&lt;animation&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9080" PostTypeId="2" ParentId="9077" CreationDate="2019-08-16T19:32:40.680" Score="-1" Body="&lt;p&gt;I would try a rim-filling approach starting with a good guess for a central triangle. Rinse, repeat.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2019-08-16T19:32:40.680" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9081" PostTypeId="1" CreationDate="2019-08-16T22:18:51.167" Score="1" ViewCount="328" Body="&lt;p&gt;I'm running following compute shader in Vulkan. worldImage is device local memory that holds the world. resultImage is reference to the memory of the swapchain image:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout (binding = 0, rgba8) uniform writeonly image2D resultImage;&#xA;layout (binding = 1, r16ui) uniform readonly uimage3D worldImage;&#xA;&#xA;layout(push_constant) uniform PushConstants {&#xA;    vec3 rayOrigin;&#xA;    float viewGridTopLeftCornerX;&#xA;&#xA;    vec3 viewGridRight;&#xA;    float viewGridTopLeftCornerY;&#xA;&#xA;    vec3 viewGridDown;&#xA;    float viewGridTopLeftCornerZ;&#xA;&#xA;    float viewGridDensity;&#xA;} push;&#xA;&#xA;&#xA;void main() {&#xA;    vec3 viewGridTopLeftCorner = vec3(push.viewGridTopLeftCornerX, push.viewGridTopLeftCornerY, push.viewGridTopLeftCornerZ);&#xA;    vec3 samplePoint = viewGridTopLeftCorner + push.viewGridDensity * (gl_GlobalInvocationID.x * push.viewGridRight + gl_GlobalInvocationID.y * push.viewGridDown);&#xA;&#xA;    vec3 ray = normalize(samplePoint - push.rayOrigin);&#xA;    vec3 inverseRay = 1 / ray;&#xA;&#xA;    ivec3 voxelCoords = ivec3(floor(push.rayOrigin.x), floor(push.rayOrigin.y), floor(push.rayOrigin.z));&#xA;    ivec3 rayOrientation = ivec3(sign(ray));&#xA;    ivec3 rayPositivity = (1 + rayOrientation) &amp;gt;&amp;gt; 1;&#xA;    vec3 withinVoxelCoords = push.rayOrigin - voxelCoords;&#xA;&#xA;    uint blockID = 0;&#xA;    int smallestComponentIndex;&#xA;    do {&#xA;        // Calculate how far each of the neighbouring voxels are&#xA;        vec3 distanceFactor = (rayPositivity - withinVoxelCoords) * inverseRay;&#xA;&#xA;        // Pinpoint the closest voxel of the three candidates&#xA;        smallestComponentIndex = distanceFactor.x &amp;lt; distanceFactor.y&#xA;        ? (distanceFactor.x &amp;lt; distanceFactor.z ? 0 : 2)&#xA;        : (distanceFactor.y &amp;lt; distanceFactor.z ? 1 : 2);&#xA;&#xA;        // Move to that voxel&#xA;        voxelCoords[smallestComponentIndex] += rayOrientation[smallestComponentIndex];&#xA;&#xA;        // Advance the ray the distance to the closest voxel in all dimensions&#xA;        withinVoxelCoords += ray * distanceFactor[smallestComponentIndex];&#xA;&#xA;        // The axis towards the next voxel will now have value -1 or 1. Next line resets it to 0.&#xA;        // It can be imageined as going jumping the side of the previus voxel to the side of the next one.&#xA;        withinVoxelCoords[smallestComponentIndex] = 1 - rayPositivity[smallestComponentIndex];&#xA;&#xA;        blockID = imageLoad(worldImage, voxelCoords).r;&#xA;    } while (blockID == 0);&#xA;&#xA;    switch (blockID) {&#xA;        case 1:&#xA;            vec3 normal = vec3(0, 0, 0);&#xA;            normal[smallestComponentIndex] = rayOrientation[smallestComponentIndex];&#xA;            imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), vec4(0.0, 1.0 * dot(ray, normal), 0.0, 1.0));&#xA;            break;&#xA;        case 2:&#xA;            imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), vec4(1.0, 0.0, 0.0, 1.0));&#xA;            break;&#xA;        default:&#xA;            imageStore(resultImage, ivec2(gl_GlobalInvocationID.xy), vec4(0.0, 0.0, 1.0, 1.0));&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The code traces one ray per pixel until it hits a block (value 1) or the edge (value 2, every edge block has the value 2).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the parameters are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;32x32x32 world with player standing in the middle (so ray tracing itself goes through half of the voxels at worst)&lt;/li&gt;&#xA;&lt;li&gt;1280x720 resolution (gl_GlobalInvocationID x and y)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;It takes about 50ms to render one frame on GTX 1050 or about 5ms on RTX 2080 Ti.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main loop acquires the image, submits the command buffer which transitions the image to proper (general) layout, binds the pipeline and descriptor sets, pushes the push_constants, dispatches the compute shader and transitions image to present layout again. This is what happens in those 50ms/5ms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I ran similar code on a single CPU core (i5 4760K) and it takes about 250ms.&#xA;This would be equivalent to running just the shader code though.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't believe that something like this would be only five times faster on the GPU than on the CPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have no experience in graphics, so I can't really tell. Is this really the time it takes for this, or could I expect (hopefully a much) better performance, once I fix whatever is bogging this down?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could it be the memory access on the GPU? I don't know what else it could be.&lt;/p&gt;&#xA;" OwnerUserId="5215" LastActivityDate="2019-08-16T22:18:51.167" Title="Compute shader only 5 times faster on the GPU than on the CPU" Tags="&lt;raytracing&gt;&lt;vulkan&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9083" PostTypeId="1" CreationDate="2019-08-19T18:55:08.653" Score="0" ViewCount="253" Body="&lt;p&gt;I started a raytracing project using the python numba library which provides a just-in-time compiler for CUDA kernels. When the scene is rendered my result is a 1920 x 1080 x 3 RGB array in GPU memory. If I only want to display a single image I can grab the result and save it to a .PNG file. My results are great so far, however, my long-term goal is to make a real-time engine with ray-tracing computations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am aware that python numba does not support CUDA - OPENGL interoperability,  so currently I grab the image from CUDA, and then render it as a texture on the screen. This results in the raytracing being only 3% of computational time. (I can do 30 fps using python arcade and rendering one frame is about 1 ms.)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is there a way to interface CUDA with DirectX/Vulkan/OpenGL to show what the GPU already has in memory? &lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If not, then I am ready to port the project to a different language and use a different API.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What library/API/language should I port this raytracing project to display my algorithm real-time on the screen?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;PS: I am quite new to computer graphics, so I don't get the full picture yet. &lt;/p&gt;&#xA;" OwnerUserId="11035" LastActivityDate="2019-08-19T18:55:08.653" Title="How to display image from CUDA / What API to port my project to for real-time raytracing?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;real-time&gt;&lt;cuda&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9084" PostTypeId="2" ParentId="8925" CreationDate="2019-08-20T08:46:12.323" Score="2" Body="&lt;p&gt;Actually what it meant by Affine Covariant regions is that covariant regions in two images which are related by some affine transformation. So the regions found in one image and those are exactly same regions in other image which have been transformed through affine transformation.&lt;/p&gt;&#xA;" OwnerUserId="11073" LastActivityDate="2019-08-20T08:46:12.323" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9085" PostTypeId="1" CreationDate="2019-08-20T22:32:31.757" Score="1" ViewCount="204" Body="&lt;p&gt;I am trying to understand how the generation of irradiance maps works. I was reading &lt;a href=&quot;https://learnopengl.com/PBR/IBL/Diffuse-irradiance&quot; rel=&quot;nofollow noreferrer&quot;&gt;LearnOpengGL tutorial&lt;/a&gt; and &lt;a href=&quot;http://www.codinglabs.net/article_physically_based_rendering.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;Codinglabs article&lt;/a&gt;. Reading those articles, I got a bit confused about how we use convolution to generate the irradiance map.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do we apply the integral to the environment map to convolute it, and do we do it because our environment map is equirectangular?&lt;/p&gt;&#xA;" OwnerUserId="11077" LastActivityDate="2019-08-21T23:19:15.460" Title="Understanding the irradiance map generation" Tags="&lt;pbr&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9086" PostTypeId="1" AcceptedAnswerId="9088" CreationDate="2019-08-20T23:01:40.490" Score="4" ViewCount="86" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/saZHn.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/saZHn.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the above image, you can see that there is some slight variation of the height of each wood plank. These variations do NOT come from the wood texture itself, but from the way it was cut, i.e if a different tool had been used to cut the same plank, it would look different.= and exhibit the pattern of the tool used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to use a perlin noise generated heightmap to approximate, to the best of my ability, this &quot;wavy&quot; pattern exhibited.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This image is better to see the pattern:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ryqn4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ryqn4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have tried multiple strategies to modify perlin noise but I can't quite get heightmaps that look like the prior images.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My strategies so far are based around:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Stretching perlin noise along one direction, taking powers of linear combinations of the sampled noise to try to get a &quot;bowl&quot; shape, similar to the corner of the bottom image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone have suggestions?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2019-08-21T14:49:12.470" LastActivityDate="2019-08-21T23:03:09.233" Title="How to approximate the heightmap of processed wood?" Tags="&lt;shading&gt;&lt;noise&gt;&lt;procedural-generation&gt;&lt;height-field&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9087" PostTypeId="1" CreationDate="2019-08-21T15:00:29.163" Score="4" ViewCount="179" Body="&lt;p&gt;Are there any reasons to use power of two textures (like 128x128 sized) if one targets modern mobile platforms (with OpenGL ES 3.0, Metal and/or Vulkan)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With iOS the PVRTC only supports power of two textures that have equal width and height, but e.g. ETC2 and ASTC do not have limits like that. &lt;/p&gt;&#xA;" OwnerUserId="11080" LastActivityDate="2019-08-21T15:00:29.163" Title="Are there any reasons to use power of two textures with modern mobile platforms?" Tags="&lt;texture&gt;&lt;vulkan&gt;&lt;opengl-es&gt;&lt;metal&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9088" PostTypeId="2" ParentId="9086" CreationDate="2019-08-21T23:03:09.233" Score="4" Body="&lt;p&gt;A sine wave remapped to [0, 1] and raised to a power will give you periodic ridges: (&lt;a href=&quot;https://www.desmos.com/calculator/tyr0wno1n5&quot; rel=&quot;nofollow noreferrer&quot;&gt;Desmos graph&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NG092.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NG092.png&quot; alt=&quot;graph of sine wave to a power&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That could be a good place to start. It will make perfectly straight, even ridges; but you could then perturb the X position where the sine is evaluated using low-frequency Perlin noise, which will make the ridges bend and waver while still going mostly along the original axis. You could use noise to fluctuate the power that the sine is raised to as well, making the ridges smoother and sharper in different places.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-08-21T23:03:09.233" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9089" PostTypeId="2" ParentId="9085" CreationDate="2019-08-21T23:19:15.460" Score="2" Body="&lt;p&gt;Yes, the convolution is effectively evaluating the following integral:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\text{irradianceMap}(\vec n) = \frac{1}{\pi} \int \text{environmentMap}(\vec \omega_i) \, \max(\vec n \cdot \vec \omega_i, 0) \, d\omega_i&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This convolution isn't about whether the environment map is equirectangular, cubemap, or some other projection. We still have to do the convolution regardless, because we want to get the total diffuse light (irradiance) coming to a surface with a given normal, from all directions in the hemisphere around that normal. The environment map to start with just has light from one direction (radiance).&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-08-21T23:19:15.460" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9090" PostTypeId="2" ParentId="9071" CreationDate="2019-08-22T04:41:36.067" Score="3" Body="&lt;p&gt;You need to set the colour back to white before drawing the framebuffer to the screen. Otherwise, the whole framebuffer gets multiplied with red.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;glColor3f(1, 1, 1); // &amp;lt;------- add this (doesn't have to be exactly here)&#xA;&#xA;glBindTexture(GL_TEXTURE_2D, fbo_tex[0]);&#xA;glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, SCRWIDTH, SCRHEIGHT, 0, -1, 1);&#xA;glMatrixMode(GL_MODELVIEW); glLoadIdentity();&#xA;{&#xA;    glBegin(GL_QUADS);&#xA;    glTexCoord2f(0, 0); glVertex3i(0, 0, 0);&#xA;    glTexCoord2f(0, 1); glVertex3i(0, SCRHEIGHT, 0);&#xA;    glTexCoord2f(1, 1); glVertex3i(SCRWIDTH, SCRHEIGHT, 0);&#xA;    glTexCoord2f(1, 0); glVertex3i(SCRWIDTH, 0, 0);&#xA;    glEnd();&#xA;}&#xA;glBindTexture(GL_TEXTURE_2D, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2316" LastActivityDate="2019-08-22T04:41:36.067" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9091" PostTypeId="1" CreationDate="2019-08-22T08:59:42.520" Score="0" ViewCount="272" Body="&lt;p&gt;I have a textured 3D object and looking for ways to transform back the texture. Effectively, I think this is an inverse texture mapping task. Do you know of anything close to this? Some papers or implementations that already solved this task you know of?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As has been asked: The background is a &quot;complex 3d object&quot; (think of the shape/form of a non-regular potato, for example). Now, that object is randomly textured at run-time and I would like to restore that texture to the 2d space for further analysis (using machine learning techniques).&lt;/p&gt;&#xA;" OwnerUserId="11084" LastEditorUserId="11084" LastEditDate="2019-08-22T09:42:55.103" LastActivityDate="2019-08-22T09:42:55.103" Title="Inverse texture mapping" Tags="&lt;texture&gt;&lt;projections&gt;&lt;3dtexture&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9092" PostTypeId="1" CreationDate="2019-08-22T18:39:21.093" Score="1" ViewCount="28" Body="&lt;p&gt;I'm writing my own UV Unfold operation (similar to Maya's Optimize UV tool or 3DS Max's Relax Tool).  My code works great 90% of the time but in some instances, I'm getting faces and edges that flip on top of each other.  This causes the faces to orient in a different direction than intended.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to find a good approach to detecting when this flip occurs to either prevent it beforehand or correct it when it does happen.  I'm currently testing the dot product of the 2D normal compared with the dot product of the previous normal after I move the uvs.  Is this a decent approach?  Am I missing another simple algorithm or check that could prevent the overlap?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3D mesh for testing&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SLX9r.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SLX9r.jpg&quot; alt=&quot;Image of the 3D Mesh&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Results with my algorithm with overlapped faces and edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uoSFd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uoSFd.jpg&quot; alt=&quot;Current results with my code&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maya's optimize results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nYFg5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nYFg5.jpg&quot; alt=&quot;Maya Optimize Results&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11087" LastActivityDate="2019-08-22T18:39:21.093" Title="How can I detect if an edge has flipped during the UV unfold process?" Tags="&lt;3d&gt;&lt;texture&gt;&lt;algorithm&gt;&lt;mathematics&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9093" PostTypeId="1" CreationDate="2019-08-22T21:48:59.537" Score="2" ViewCount="122" Body="&lt;p&gt;I see two kinds of passing Instance Data to &lt;strong&gt;Vertex Shader&lt;/strong&gt; in different Examples.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;1&lt;/strong&gt; .Using a &lt;strong&gt;Uniform Buffer&lt;/strong&gt; and filling in an array, like below&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct UniformBlock&#xA;{&#xA;    mat4 mProjectView;&#xA;    mat4 mToWorldMat[MAX_INSTANCE];&#xA;    vec4 mColor[MAX_INSTANCES];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2&lt;/strong&gt;. Filling in buffers, and then define the buffer as &lt;strong&gt;RATE_PER_INSTANCE&lt;/strong&gt;  in vertex layout description (I assume this is the more usual way)&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;My Question is :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;How do these differ from &lt;strong&gt;hardware&lt;/strong&gt; or &lt;strong&gt;memory access&lt;/strong&gt; Point of View?&lt;/li&gt;&#xA;&lt;li&gt;Are there any cases which one is considered &quot;better&quot; or &quot;faster&quot; than the other?&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="11089" LastActivityDate="2019-08-22T21:48:59.537" Title="Difference between Passing Instance Data to Vertex Shader methods" Tags="&lt;vulkan&gt;&lt;directx12&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9094" PostTypeId="2" ParentId="9065" CreationDate="2019-08-23T05:53:28.480" Score="0" Body="&lt;p&gt;Thanks so much for everyone's replies. It really helped to see any reply that kind of encouraged me to continue.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So after some hours of working out the issue it turns out this is correct on the sphere. The above image is correct. As Dan kindly pointed out and as I later drew it out on paper and tried lights of different heights, the higher the light, the lower the cutoff. Because the light was so close to the sphere only its top was intensely illuminated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing I had gotten incorrect were actually the ellipses normal transforms, which I didn't include in the post because I thought it was more complex, get the basics right first. So it turns out I had to create a different stack to store the non-uniform transforms as it was being read from the file so that the ellipses' normals could be transformed correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So lesson learned - understand all the cases before implementing them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I really appreciate this platform! Thanks and cheers to all&lt;/p&gt;&#xA;" OwnerUserId="11041" LastActivityDate="2019-08-23T05:53:28.480" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9095" PostTypeId="1" AcceptedAnswerId="9118" CreationDate="2019-08-23T07:26:45.893" Score="1" ViewCount="237" Body="&lt;p&gt;As a quick reminder, &lt;a href=&quot;http://www.lighthouse3d.com/tutorials/glsl-12-tutorial/the-normal-matrix/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; is what normal matrix is and why do we need it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now the question - if I take the light position and transform it into an object space than I don't need the normal matrix at all and actually it will save me a good amount of calculations (don't need to multiply a normal by the matrix). By I can't draw a mental picture of how this could work for a scaled object, what does it mean to transform a point (light position) into a scaled object space? And what about a directional light where I have no position at all?&lt;/p&gt;&#xA;" OwnerUserId="386" LastActivityDate="2019-09-07T18:47:17.247" Title="Do I need a normal matrix if I calculate lighting in an objects space?" Tags="&lt;lighting&gt;&lt;matrix&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9096" PostTypeId="2" ParentId="4513" CreationDate="2019-08-24T18:54:50.743" Score="2" Body="&lt;p&gt;These are all good answers, and yet there is another way: (Isn't there always?)&lt;/p&gt;&#xA;&lt;p&gt;Due to the growing popularity of virtual reality, the folks at OculusVR have developed a trio of &amp;quot;Multiview&amp;quot; extensions called:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;OVR_multiview&lt;/strong&gt;,&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;OVR_multiview2&lt;/strong&gt;, &amp;amp;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;OVR_multiview_multisampled_render_to_texture&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;These extensions allow multiple views of the same scene to be rendered in a single draw call, eliminating the redundancy of rendering the same scene in the same state from the viewpoint of each eye. Although created for the purpose of VR, the developer is not necessarily limited to merely two views. Rather, this extension allows for as many views as &lt;strong&gt;MAX_VIEWS_OVR&lt;/strong&gt; specifies.&lt;/p&gt;&#xA;&lt;p&gt;Before using these extensions, the developer should check for their support in the user's graphics driver by adding the following code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;const GLubyte* extensions = GL_CHECK( glGetString( GL_EXTENSIONS ) );&#xA;char * found_extension = strstr( (const char*)extensions, &amp;quot;GL_OVR_multiview&amp;quot; );&#xA;if (NULL == found_extension)&#xA;{&#xA;     exit( EXIT_FAILURE );&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;From there, it is a matter of setting up your framebuffer to utilize this feature:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glFramebufferTextureMultisampledMultiviewOVR = PFNGLFRAMEBUFFERTEXTUREMULTISAMPLEDMULTIVIEWOVR(eglGetProcAddress(&amp;quot;glFramebufferTextureMultisampleMultiviewOVR&amp;quot;));&#xA;glFramebufferTextureMultisampledMultiviewOVR (GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureID, 0, 0, 2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and likewise in the shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 300 es&#xA;#extension GL_OVR_multiview : enable&#xA;&#xA;layout(num_views = 2) in;&#xA;in vec3 vertexPosition;&#xA;uniform mat4 MVP[2];&#xA;&#xA;void main(){&#xA;    gl_Position = MVP[gl_ViewID_OVR] * vec4(vertexPosition, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In a CPU-bound application, this extension can &lt;em&gt;dramatically&lt;/em&gt; reduce rendering time, &lt;em&gt;especially with more complex scenes&lt;/em&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6nrze.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6nrze.png&quot; alt=&quot;Relative CPU time between multiview and regular stereo. The smaller the better, with the number of cubes on the x-axis and the relative time on the y-axis.&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6596" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-08-24T18:54:50.743" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9097" PostTypeId="1" CreationDate="2019-08-24T22:23:29.933" Score="4" ViewCount="942" Body="&lt;p&gt;I've written a shader that writes depth to each face of a cube map, as part of rendering cube map shadows for a realtime 3D engine I'm writing with OpenGL and C++.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shader transforms each vertex into world space in the vertex shader, then transforms polygons to each of the cube map's 6 faces in the geometry shader, and then writes depth to the cube map in the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shader works correctly, but I receive the following error message when rendering with it for the first time:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Error:  OpenGL Error Callback:&#xA;Source:&#xA;Type: PERFORMANCE&#xA;id: 131218&#xA;Severity: MEDIUM&#xA;Message: Program/shader state performance warning: Vertex shader in program 89 is being recompiled based on GL state.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After that, the shader functions perfectly and I'm able to render depth to a cube map, and use it to render shadows for my point lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The shader has a vertex, geometry, and fragment shader component:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Vertex:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (location = 0) in vec3 in_position;&#xA;&#xA;uniform mat4 in_model;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position = in_model * vec4(in_position.xyz, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Geometry&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (triangles) in;&#xA;layout (triangle_strip, max_vertices = 18) out;&#xA;&#xA;uniform mat4 shadowCamCubeMap_vp[6];&#xA;&#xA;out vec4 FragPos;&#xA;&#xA;void main()&#xA;{&#xA;    for(int currentCubeFace = 0; currentCubeFace &amp;lt; 6; currentCubeFace++)&#xA;    {&#xA;        gl_Layer = currentCubeFace; // Set the cube map face we're rendering to&#xA;&#xA;        for(int currentVert = 0; currentVert &amp;lt; 3; currentVert++)&#xA;        {               &#xA;                FragPos = gl_in[currentVert].gl_Position; // World pos from vert shader&#xA;&#xA;                gl_Position = shadowCamCubeMap_vp[currentCubeFace] * gl_in[currentVert].gl_Position;&#xA;&#xA;            EmitVertex();&#xA;        }    &#xA;        EndPrimitive();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Fragment:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;uniform vec3 lightWorldPos; &#xA;&#xA;uniform float shadowCam_near;&#xA;uniform float shadowCam_far;&#xA;&#xA;in vec4 FragPos;&#xA;&#xA;void main()&#xA;{&#xA;    float lightDistance = length(FragPos.xyz - lightWorldPos);&#xA;&#xA;    lightDistance = lightDistance / shadowCam_far;&#xA;&#xA;    gl_FragDepth = lightDistance;&#xA;} &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I delete the geometry shader and just compile the vertex and fragment shaders together, the issue still occurs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I try and debug the program in RenderDoc, the error does not occur (!!).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm scratching my head here. The vertex shader looks near identical to other vertex shaders I'm using.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've poured over every google result I could find, but still don't have any idea what's going on here. One thread suggested that, possibly, some part of the OpenGL state was compiled into the program when the shader was first loaded. Then, at some point the state was changed, triggering a recompile when the shader is first used to render something... But it didn't offer any solutions and I'm not really sure if/how this could be the case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd appreciate any help I can get here!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&#xA;I have another 2D depth shader that I use to write depth for a key light that doesn't suffer this issue. If I completely replace the cube map depth shader code with the functional key light depth shader (and delete the geometry shader), the issue still persists.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I don't render the keylight at all (making the cube map depth shader the only depth shader that gets executed), the issue persists.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only difference between the cube and 2D depth map shaders is that the cube map depth shader is being rendered with cube map textures bound... Is it possible I'm screwing up their initialization somehow?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is my cube map setup:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool RenderTexture::BufferCubeMap(RenderTexture** cubeFaceRTs)&#xA;{&#xA;    // Bind Texture:&#xA;    glBindTexture(GL_TEXTURE_CUBE_MAP, this-&amp;gt;textureID);&#xA;    if (!glIsTexture(this-&amp;gt;textureID))&#xA;    {&#xA;        glGenTextures(1, &amp;amp;this-&amp;gt;textureID);&#xA;        glBindTexture(GL_TEXTURE_CUBE_MAP, this-&amp;gt;textureID);&#xA;&#xA;        if (! glIsTexture(this-&amp;gt;textureID))&#xA;        {&#xA;            glBindTexture(GL_TEXTURE_CUBE_MAP, 0);&#xA;            return false;&#xA;        }&#xA;    }&#xA;&#xA;    // Generate faces:&#xA;    for (int i = 0; i &amp;lt; CUBE_MAP_COUNT; i++)&#xA;    {&#xA;        glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_DEPTH_COMPONENT32F, this-&amp;gt;width, this-&amp;gt;height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);&#xA;    }&#xA;&#xA;    // Set texture params:&#xA;    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);  &#xA;&#xA;    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;&#xA;    // Bind sampler:&#xA;    glBindSampler(12, this-&amp;gt;samplerID);&#xA;    if (!glIsSampler(this-&amp;gt;samplerID))&#xA;    {&#xA;        glGenSamplers(1, &amp;amp;this-&amp;gt;samplerID);&#xA;        glBindSampler(12, this-&amp;gt;samplerID);&#xA;    }&#xA;&#xA;    // Set sampler params:&#xA;    glSamplerParameteri(this-&amp;gt;samplerID, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;    glSamplerParameteri(this-&amp;gt;samplerID, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);      &#xA;    glSamplerParameteri(this-&amp;gt;samplerID, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);&#xA;&#xA;    glSamplerParameteri(this-&amp;gt;samplerID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;    glSamplerParameteri(this-&amp;gt;samplerID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;&#xA;    // Bind framebuffer:&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, this-&amp;gt;frameBufferObject);&#xA;    if (!glIsFramebuffer(this-&amp;gt;frameBufferObject))&#xA;    {&#xA;        glGenFramebuffers(1, &amp;amp;this-&amp;gt;frameBufferObject);&#xA;        glBindFramebuffer(GL_FRAMEBUFFER, this-&amp;gt;frameBufferObject);&#xA;        if (!glIsFramebuffer(this-&amp;gt;frameBufferObject))&#xA;        {&#xA;            return false;&#xA;        }   &#xA;    }&#xA;&#xA;    // Attach framebuffer as a cube map render buffer:&#xA;    glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, this-&amp;gt;textureID, 0);&#xA;&#xA;    glDrawBuffer(GL_NONE);&#xA;    glReadBuffer(GL_NONE);&#xA;&#xA;    // Ensure all of the textures have the correct information stored in them:&#xA;    for (int i = 0; i &amp;lt; 6; i++)&#xA;    {&#xA;        if (cubeFaceRTs[i] != this)&#xA;        {&#xA;            cubeFaceRTs[i]-&amp;gt;textureID           = this-&amp;gt;textureID;&#xA;            cubeFaceRTs[i]-&amp;gt;samplerID           = this-&amp;gt;samplerID;&#xA;            cubeFaceRTs[i]-&amp;gt;frameBufferObject   = this-&amp;gt;frameBufferObject;&#xA;        }&#xA;    }&#xA;&#xA;    bool result = glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;&#xA;    if (!result)&#xA;    {&#xA;        LOG_ERROR(&quot;Cube map framebuffer is not complete!&quot;);&#xA;    }&#xA;&#xA;    // Cleanup:&#xA;    glBindTexture(GL_TEXTURE_CUBE_MAP, 0);&#xA;    glBindSampler(12, 0);&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, 0); &#xA;&#xA;    return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Finally, the cube map texture is bound with:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void RenderTexture::Bind(GLuint const&amp;amp; shaderReference)&#xA;{&#xA;&#xA;        glActiveTexture(GL_TEXTURE0 + 12);&#xA;        glBindTexture(GL_TEXTURE_CUBE_MAP, this-&amp;gt;textureID);&#xA;        glBindSampler(12, this-&amp;gt;samplerID);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I've edited my code to make it as brief and readable as possible, hopefully I didn't make any typos...&lt;/p&gt;&#xA;" OwnerUserId="11099" LastEditorUserId="11099" LastEditDate="2019-08-25T19:12:22.257" LastActivityDate="2019-08-25T19:12:22.257" Title="Why is OpenGL recompiling my depth map vertex shader based on the GL state?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;shadow-mapping&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9098" PostTypeId="2" ParentId="9097" CreationDate="2019-08-25T09:52:48.220" Score="5" Body="&lt;p&gt;This is an example of implementation details leaking through the abstraction. Parts of the GL state are often implemented via native GPU ISA instructions that the driver injects into user-defined shaders, such as fetching the geometry from vertex and index buffers, or interpolating VS outputs in the subsequent pipeline stages.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since we're looking at the GPU driver's black box here, it's difficult to know which state change exactly is triggering this behaviour. &lt;s&gt;But my guess would be that inserting a geometry shader stage into the pipeline is to blame. GS are notorious for poor performance due to the unpredictable workload (of course, we give it an upper bound, but still), and as such, the driver may choose to look for optimisation opportunities, looking at VS &amp;amp; GS together. This is what I think might be triggering a recompile.&lt;/s&gt; I just noticed that you've tested removing it from the pipeline and the problem persists. The other hypothesis I can offer is that you're overwriting fragment depth. The driver possibly needs to resolve this with the currently bound depth write state, and/or decide what to do about early depth tests (see &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Fragment_Shader/Defined_Outputs&quot; rel=&quot;noreferrer&quot;&gt;the documentation about gl_fragDepth&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As long as you only get this once at application start, it should be completely safe to ignore. The driver will put the compiled shader in its cache and use it on subsequent occasions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As to why you aren't getting it in RenderDoc - it suppresses debug messages while linking shaders and programs in the initial OpenGL state bring-up (i.e. state that existed before the captured frame), &lt;a href=&quot;https://github.com/baldurk/renderdoc/blob/4923aa9d88b232ef48f203fb3cb33f7643a3f756/renderdoc/driver/gl/gl_initstate.cpp#L1327&quot; rel=&quot;noreferrer&quot;&gt;see its source code&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2817" LastEditorUserId="2817" LastEditDate="2019-08-25T10:04:14.543" LastActivityDate="2019-08-25T10:04:14.543" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9099" PostTypeId="1" CreationDate="2019-08-28T11:47:10.753" Score="1" ViewCount="33" Body="&lt;p&gt;Attempting to deskew and crop scans of a CD booklet using ImageMagick.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's one image which I've been using as an example on which to build my one-liner - &lt;a href=&quot;https://mega.nz/#!jIQD3aqC!PbjG4_Xaq-YPhrPu1APaRmYLKmCSx6pxbIUkaoQzOgM&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://mega.nz/#!jIQD3aqC!PbjG4_Xaq-YPhrPu1APaRmYLKmCSx6pxbIUkaoQzOgM&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've been using something along the lines of;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;convert testscan.png -background white -deskew 80% -fuzz 40% -trim +repage edited_scan.png&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The deskewing step works very well, however I've been unable to achieve good results on the cropping stage. When deskewing the image ImageMagick expands it and adds additional pixels to fill in the blanks (here white, but could be transparent as well). This may be interfering with the ability of -trim to crop the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, -trim either;&#xA; - fails to crop any edges&#xA; - crops a single edge but not the others&#xA; - (upon raising -fuzz values) crops multiple sides but fails to accurately crop edges&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not exactly sure what the issue is, but I've tried a number of different alterations to -trim parameters without success.&lt;/p&gt;&#xA;" OwnerUserId="11106" LastActivityDate="2019-08-28T11:47:10.753" Title="Deskewing and Cropping Scans using ImageMagick" Tags="&lt;image-processing&gt;&lt;raster-image&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9101" PostTypeId="1" AcceptedAnswerId="9102" CreationDate="2019-08-29T02:09:30.493" Score="0" ViewCount="111" Body="&lt;p&gt;I want to study computer graphics but I don't have a strong foundation in mathematics. I am doing a computer science degree that doesn't cover computer vision, image processing or computer graphics, linear algebra, geometry, trigonometry, calculus etc. It does cover discrete math and other math relating to computer science. I don't meet the requirements for a mathematics degree so I can't pursue a minor in that. I want to know if I can teach myself the math necessary for CG or Would discrete math be adequate enough? Any advice would be nice.&lt;/p&gt;&#xA;" OwnerUserId="11108" LastActivityDate="2019-08-29T07:59:28.750" Title="Want to study computer graphics" Tags="&lt;image-processing&gt;&lt;mathematics&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9102" PostTypeId="2" ParentId="9101" CreationDate="2019-08-29T07:59:28.750" Score="3" Body="&lt;p&gt;First, graphics is full of linear algebra, so you'll need that whatever you do. If you want to do any research into shaders, or to write a ray-tracer, you'll also need to understand integration and probably some statistics (to understand Monte Carlo integration).&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I want to know if I can teach myself the math necessary for CG&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;We can't answer that question for you: only you know how good you are at teaching yourself. If you &quot;don't have a strong foundation in mathematics&quot; because you struggled with it at school, you'll probably struggle to learn harder maths with less help than you had before. If it's not like that, and you're generally good at self-study, then now's the time. You'll never have more access to the means of learning than when you're at university. Hang out with your local maths students and pay attention when they talk about work. Find out when they have lectures relevant to you that don't clash with your own lectures, and go to as many as you can. Find out what books they use for their course, and read the same books.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It'll also help to approach any graphics projects you start with the mindset that when you encounter some maths you don't understand, you might need to put the project to one side while you learn what you need to know. You'll probably do this a lot as soon as you get past the &quot;draw the first triangle on the screen&quot; stage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A counterpoint to this is that there are a lot of tools today that allow designers and artists to make really impressive graphics content without much maths knowledge, such as Unity and Processing. Maybe you can achieve what &lt;em&gt;you&lt;/em&gt; want without studying computer graphics as an academic field at all! Try making a Unity game, play around with shaders a bit, and see if it tickles you.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-08-29T07:59:28.750" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9103" PostTypeId="1" CreationDate="2019-08-29T09:44:37.553" Score="1" ViewCount="119" Body="&lt;p&gt;For a research project, I have written a Tessellation Shader to interpolate solution points of a 3-Dimensional mathematical equation. Therefore I don't use any techniques for displacement, I merely use the tessellation hardware to interpolate a lot of data points in parallel. I want to write a paragraph about the potential speed benefits compared with trivial interpolation on a CPU, but I can't find any resources about how fast tessellation is in terms of &quot;generating new points per second&quot; or &quot;subdividing triangles per second&quot;. Even more interesting would be &quot;new points per GPU clock cycle&quot;. But all resources I find are from the video game perspective talking about FPS-performance, which is useless in my case, because first I tessellate my model only once and second I don't use any displacement techniques which are normally used to increase visual quality but will lower the performance again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously the performance depends on the actual GPU, but a single data sheet as an anchor point would already help a lot.&lt;/p&gt;&#xA;" OwnerUserId="11111" LastEditorUserId="11111" LastEditDate="2019-08-29T13:32:14.040" LastActivityDate="2020-09-27T23:02:35.327" Title="Tessellation Speed in terms of interpolated points per second" Tags="&lt;gpu&gt;&lt;performance&gt;&lt;tesselation&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9104" PostTypeId="1" AcceptedAnswerId="9105" CreationDate="2019-08-29T13:44:44.220" Score="0" ViewCount="113" Body="&lt;p&gt;I have a noob level question about RGB images-&#xA;Pixels in RGB images are in the range of (0-255), so technically each channel ranges from 0(black) to 1(white), then why we say that each image has a Red, Green, Blue channel component, although they are only Gray channel. In short, how the image is formed?&lt;/p&gt;&#xA;" OwnerUserId="11114" LastActivityDate="2019-09-05T17:10:53.910" Title="How RGB images are formed" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9105" PostTypeId="2" ParentId="9104" CreationDate="2019-08-30T07:25:56.350" Score="3" Body="&lt;p&gt;Each channel ranges not from &lt;em&gt;black&lt;/em&gt; to &lt;em&gt;white&lt;/em&gt;, but from &lt;em&gt;off&lt;/em&gt; to &lt;em&gt;full intensity&lt;/em&gt;. What colour is meant by &lt;em&gt;full intensity&lt;/em&gt; is down to convention and the presentation technology.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, a given image file format might say there are three bytes, of which the first is the red channel, the second is the green channel, and the third is the blue channel. There are many different colours, so to be a real standard, it has to say exactly what that &quot;red&quot; means, usually by reference to a particular colour standard such as sRGB or CIELAB. These international standards provide an absolute way to describe colours.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some processing, your red, green, and blue values find their way to your LCD monitor. There, the electronics uses them to control the intensity of three sub-pixels: one of which is a red filter, one a green filter, and one a blue filter. The 0-255 value in the red channel is turned into some voltage which controls the transparency of the liquid crystal behind the red filter, turning it from &lt;em&gt;completely opaque&lt;/em&gt; at 0 to &lt;em&gt;lets all light through&lt;/em&gt; at 255. Since this is attached to a red filter, it contributes black or red to the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same idea is everywhere in computers. The only things inside a computer are numbers. They only mean what we say they mean because of conventions (all software interprets them the same way) and/or because they control some values inside some output hardware. e.g. one number means the red channel in a pixel on your screen, another number means a letter of the alphabet in an email, another number is a pressure sample in an audio file which will be sent to your sound card and control the voltage to a speaker, and so on.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-08-30T07:25:56.350" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9106" PostTypeId="1" AcceptedAnswerId="9108" CreationDate="2019-08-30T16:13:21.287" Score="2" ViewCount="232" Body="&lt;p&gt;I've been doing some searching online and it seems like I could improve my renderer by ordering my draw calls based on depth. For opaque objects render the closest items first and move backward in depth to hopefully take advantage of depth test rejection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The question I have is would this be worth the tradeoff of sacrificing instancing? It seems like the most straightforward approach would be to stop instancing completely and do each draw call one by one. I'm sure you could write some clever code to find groups within a new depth-first rendering order to instance but it seems like you'd get substantially less benefit.&lt;/p&gt;&#xA;" OwnerUserId="8704" LastActivityDate="2019-08-30T16:51:51.057" Title="Trading off instancing for render order" Tags="&lt;opengl&gt;&lt;directx11&gt;&lt;optimisation&gt;&lt;scene-graph&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9108" PostTypeId="2" ParentId="9106" CreationDate="2019-08-30T16:51:51.057" Score="4" Body="&lt;p&gt;It depends on your GPU. &quot;Tiled renderers&quot; do this for you so the benefit of doing it yourself is minimal (unless you have some more efficient way of knowing the order, e.g. sorting a fixed-viewpoint scene in advance). In this case, your best way of keeping efficiency is by ensuring they are allowed to draw the scene all in one go by avoiding &lt;code&gt;glReadPixels&lt;/code&gt; and similar sync points between draw calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even for a truly immediate-mode renderer, instancing can be hugely powerful and reducing overdraw is unlikely to be worth it, but the trade-off comes down to whether you're bottlenecked on the fragment shader or by the memory bandwidth used feeding vertices to the vertex shader. In turn that will depend on how big your instanced geometry is (and how many instances), and how long your fragment shader takes to execute. These are all specific to your application and to the GPU you're running on, so you can only really know by profiling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an outright guess I'd say it's unlikely that the change you're suggesting will improve performance, unless you have few instances and a big fragment shader on a non-tiled GPU architecture.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-08-30T16:51:51.057" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9111" PostTypeId="2" ParentId="8359" CreationDate="2019-09-03T04:25:41.973" Score="0" Body="&lt;p&gt;As a work around this, what I did was to separate static and dynamic lights, have the static illumination go through temporal accumulation and dynamic illumination not (and use a non-temporal de-noising method).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There could still be artifacts, especially on far-away dynamic lights, but could still be useful. I did this in a game where the flashlight was fixed in view-space, so in fact no denoising was even necessary.&lt;/p&gt;&#xA;" OwnerUserId="6442" LastActivityDate="2019-09-03T04:25:41.973" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9113" PostTypeId="2" ParentId="9103" CreationDate="2019-09-03T21:21:20.097" Score="1" Body="&lt;p&gt;If you’re only tessellating the model once and never changing the density of the mesh then tessellation is probably a waste of time here—any measurements you make would include all the extra work the GPU has to do to generate new points / triangles, which is orthogonal to what it sounds like you’re trying to measure. Tessellating the mesh ahead of time (in your tool of choice) and doing the interpolation / evaluation in a vertex shader would probably give you a better benchmark against a CPU implementation working on the same mesh.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-09-03T21:21:20.097" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9114" PostTypeId="2" ParentId="9095" CreationDate="2019-09-04T20:41:05.087" Score="1" Body="&lt;p&gt;If you compute the lighting in object space, before you scale the object then you will get false lighting. Imagine a small cube being lit by a single point light representing a light bulb. Now, scale that cube up to the size of a building. The lighting will have been calculated already, and now the entire building is being lit by a single light bulb. &lt;/p&gt;&#xA;" OwnerUserId="11136" LastActivityDate="2019-09-04T20:41:05.087" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9115" PostTypeId="2" ParentId="9104" CreationDate="2019-09-04T21:27:23.280" Score="1" Body="&lt;p&gt;CRT monitors are a thing of the past, but I think they are the best example to describe to you &quot;how the image is formed&quot;.&#xA;Each pixel on the monitor is actually a group of 3 phosphors. A green phosphor, a red phosphor and a blue phosphor. These phosphors will glow at a certain intensity when they are charged. Inside the monitor there is an electron beam that charges these phosphors. The intensity of which, is determined by the number 0-255 of that channel. So a completely black pixel would not be hit at all, whereas a bright red pixel would only strike the red phosphor, and at a high intensity  (around 200-255). This is, of course, a simplification of the process, but it answers &quot;how&quot; the red channel relates to a red pixel.&lt;/p&gt;&#xA;" OwnerUserId="11136" LastEditorUserId="11136" LastEditDate="2019-09-05T17:10:53.910" LastActivityDate="2019-09-05T17:10:53.910" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9116" PostTypeId="1" CreationDate="2019-09-05T06:39:32.050" Score="2" ViewCount="88" Body="&lt;p&gt;&lt;strong&gt;Introduction to my project:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We are machine learning scientists and working on a biomedical system for tracking tongue for speech pathology using a technology called EMA (Electromagnetic articulography). In EMA a coil is attached to tongue surface using a glue and its 3D pos and orientation (roll and pitch) are read by EMA measurement system. So, you can track the coil and thus a point on the surface of tongue while speech is made. Also let's assume we have a low density 3D model of tongue for the patient is obtained by 3D MRI and we know exactly that which vertex in 3D model corresponds to the point that coil is attached.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would be very valuable for our research if we can visualize the tongue for the patient. But the issue is that we just track 1 or 2 points on the tongue but our 3D model has more than 100 vertices which are not tracked. Now, we think it might be possible to estimate the position of those point given these two points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Here are some of the facts that we think it should be possible:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Although tongue is not a solid object, it has a degree of rigidity thus the position of these 100 vertexes are correlated by physics For example how much they can be stretched or bent (Something like spring and mass model in physics). &lt;/li&gt;&#xA;&lt;li&gt;by looking at a training set of 3D models for tongue during production of different sounds, we might say that the position of vertexes are not pure random and there is a distribution for them which might be estimated using the training dataset (sequence of MRI 3D models). &lt;/li&gt;&#xA;&lt;li&gt;we might assume that in our presentation the tongue can have just a bent toward the palate to simplify the modeling problem. or a 2D profile of tongue (like the line at the center) is enough for modeling. or any simplification that we can make. &lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Now my question:&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do you know in computer graphics literature which resembles to our problem (any model, method, tool, software, library,....)? What is your suggestion for us to do this task in more efficient way?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mike&lt;/p&gt;&#xA;" OwnerUserId="11138" LastActivityDate="2021-05-28T10:01:35.150" Title="Estimating the position of vertexes in a 3D model" Tags="&lt;rendering&gt;&lt;algorithm&gt;&lt;image-processing&gt;&lt;computational-geometry&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9117" PostTypeId="1" AcceptedAnswerId="9119" CreationDate="2019-09-05T13:59:41.147" Score="3" ViewCount="70" Body="&lt;p&gt;Red, Green and Blue apparently contribute differently to the luminosity perceived by humans:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Relative_luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Relative_luminance&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to find an algorithm to map unsigned 16 bit integers into RGB values such that the relative luminance of the RGB values to which the integers map respects their order (with integer 0 being black, integer 2^16-1 white and all other integers mapped to some RGB color).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't really care about how the colors evolve as one walks up from 0 to 2^16-1 as long as luminosity always increases and a reasonably large swathe of the RGB space is used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apparently I am missing the right words to describe what I am trying to accomplish as I've failed to google anything pertinent. A couple of weeks ago I had stumbled upon a paper that described such an algorithm in the form of a helix that is arranged diagonally in the three dimensional RGB space such that when one starts at the base of the helix and works his way towards the other end, luminosity always increases and a large variety of color is used. Alas, I can't find it any more.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;update&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Found the algorithm I was looking for. It is known as the 'cubehelix' color scheme by Dave Green and is described here:&#xA;&lt;a href=&quot;http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/&lt;/a&gt;. The original paper is here: &lt;a href=&quot;http://astron-soc.in/bulletin/11June/289392011.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://astron-soc.in/bulletin/11June/289392011.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11142" LastEditorUserId="11142" LastEditDate="2019-09-11T14:41:21.587" LastActivityDate="2019-09-11T14:41:21.587" Title="map 16-bit integers to RGB colors with monotonic relative luminosity" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9118" PostTypeId="2" ParentId="9095" CreationDate="2019-09-05T17:07:50.047" Score="3" Body="&lt;p&gt;By lighting in object space, sure, you could avoid transforming the normals into world space. However, you'd have to transform the light positions/vectors into the object's space. Also, if you want any view-dependent shading such as specular, you would have to transform the camera position into object space as well, to calculate view vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, all of this can be done straightforwardly using the inverse of the object's world matrix. The inverse world matrix will include the inverse of the object's scale (as well as correctly accounting for the inverse of its rotation and translation), so it will transform the light &amp;amp; camera positions to the appropriate points in the scaled coordinate system. Directional lights don't have a position, but you can transform their direction vector by the inverse world matrix to account for rotation and scale. All of this is fine so far.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, you will then run into trouble when doing lighting calculations like N·L or N·V. For exactly the same reason that normals don't transform correctly under non-uniform scaling without using a special normal matrix, these dot products will not come out with the same result when done in a non-uniformly scaled object space as compared to world space. Namely, non-uniform scaling distorts angles. So, all your lighting calculations and BRDFs that depend on angles are going to be messed up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While there &lt;em&gt;are&lt;/em&gt; ways one could correct this problem by using additional matrices when calculating dot products... it's generally easier and faster to do lighting in world space (or view space). In any case, transforming the normals to world space is a pretty trivial amount of math by modern GPU standards, especially as it only needs to be done per vertex.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="231" LastEditDate="2019-09-07T18:47:17.247" LastActivityDate="2019-09-07T18:47:17.247" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9119" PostTypeId="2" ParentId="9117" CreationDate="2019-09-05T17:39:44.717" Score="3" Body="&lt;p&gt;Since you want monotonically increasing luminance, it's probably best to work in a color space that separates luma from chroma, such as a &lt;a href=&quot;https://en.wikipedia.org/wiki/YUV#HDTV_with_BT.709&quot; rel=&quot;nofollow noreferrer&quot;&gt;Y'UV space&lt;/a&gt;. You can assign values in Y'UV and then convert it to RGB using the matrix at that link.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Start by setting &lt;span class=&quot;math-container&quot;&gt;$Y' = N / (2^{16} - 1)$&lt;/span&gt;, where N is your input 16-bit integer. Now you just need to make up some function to use for the U and V components.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It wasn't clear to me if you want the chroma part of the color to vary &lt;em&gt;continuously&lt;/em&gt; with the input N, or be pseudo-random. For a continuous curve, you could just have it be a circle in UV space:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;U = 0.5 \cos(2\pi N/2^{16}) \\&#xA;V = 0.5 \sin(2\pi N/2^{16})&#xA;$$&lt;/span&gt;&#xA;or whatever other curve you feel like coming up with. For a pseudo-random chroma, you could use a hash function, or a &lt;a href=&quot;https://en.wikipedia.org/wiki/Halton_sequence&quot; rel=&quot;nofollow noreferrer&quot;&gt;Halton sequence&lt;/a&gt; or another low-discrepancy sequence.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-09-05T17:39:44.717" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9120" PostTypeId="2" ParentId="9116" CreationDate="2019-09-06T06:02:52.700" Score="0" Body="&lt;p&gt;If you can construct a mesh that is representative of the tongue, like a spring mass system, then you can attach 'hooks' at your two control points and get a close approximation of the deformation of the tongue. &lt;/p&gt;&#xA;" OwnerUserId="11136" LastActivityDate="2019-09-06T06:02:52.700" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9121" PostTypeId="2" ParentId="9053" CreationDate="2019-09-06T06:24:41.467" Score="0" Body="&lt;p&gt;There are many ways, but the fastest I think is to create an octtree for your cube and choose a small subdivision level. Then do simple collision detection of the cube to the sphere. If the sphere collides with the cube, subdivide it into 8 smaller cubes. Test each of those cubes and repeat. When you are finished, you will know how many cubes have intersected the sphere, just multiply their dimensions by the number of intersections and you have a close approximation of total volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You may want to say that a cube collides with a sphere if its center lies within one radius of the spheres center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I recently did something similar for a CNC simulator I wrote.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Good luck!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as the second part of your question, there would have to be constraints. If the cube is substantially smaller than the sphere, it may not be possible to satisfy your volume requirements. Given that constraints are in place, this method is fast enough that you could just drive your sphere into the cube until your required volume is met.&lt;/p&gt;&#xA;" OwnerUserId="11136" LastEditorUserId="11136" LastEditDate="2019-09-06T06:30:13.217" LastActivityDate="2019-09-06T06:30:13.217" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9122" PostTypeId="1" CreationDate="2019-09-06T10:41:35.023" Score="0" ViewCount="209" Body="&lt;p&gt;I'd like to store arbitrary float depth, so I have to disable both primitive clipping and depth clamping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can disable clipping by setting &lt;code&gt;VkPipelineRasterizationStateCreateInfo::depthClampEnable&lt;/code&gt; to &lt;code&gt;VK_TRUE&lt;/code&gt;, but then I'd have to increase my viewport bounds to the range I wish to store (which is 0..FLT_MAX) and during rasterization my depth value would be multiplied by viewport depth range and would blow up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fortunately, I can disable both clipping and clamping using the VK_EXT_depth_clip_enable, but &lt;a href=&quot;https://vulkan.gpuinfo.org/listdevices.php?platform=linux&amp;amp;extension=VK_EXT_depth_clip_enable&quot; rel=&quot;nofollow noreferrer&quot;&gt;turns out&lt;/a&gt; it was supported by the drivers quite recently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way to disable both depth clamping and clipping on older drivers (i.e., without using VK_EXT_depth_clip_enable)?&lt;/p&gt;&#xA;" OwnerUserId="10806" LastActivityDate="2019-09-06T10:41:35.023" Title="Disable both depth clamp and depth clip in Vulkan (older drivers)" Tags="&lt;vulkan&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9123" PostTypeId="1" AcceptedAnswerId="9126" CreationDate="2019-09-06T14:16:19.670" Score="1" ViewCount="260" Body="&lt;p&gt;In my Direct Light Physically Based Renderer, when I set the roughness too low (ie. 0.0 or close) the specular reflection doesn't show, not even at high resolutions and at perfect angle with the camera / light position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm using Cook-Torrance's BRDF with Schlick Smith GGX Geometry Function, Shlick Fresnel Function and Trowbridge-Reitz GGX Normal Distribution Function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect the whole reason behind this is because when the roughness is 0.0, the result of the Normal Distribution Function is also 0.0 and, consequently, the specular part will also be null.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Trowbridge-Reitz GGX Normal Distribution Function&#xA;float NormalDistributionFunction(vec3 N, vec3 H, float roughness) {&#xA;    float a = roughness * roughness;&#xA;    float aSquare = a * a;&#xA;    float NdotH = max(dot(N, H), 0.0);&#xA;    float NdotHSquare = NdotH * NdotH;&#xA;&#xA;    float numerator = aSquare;&#xA;    float denominator = (NdotHSquare * (aSquare - 1.0) + 1.0);&#xA;    denominator = PI * denominator * denominator;&#xA;&#xA;    return numerator / denominator;&#xA;}&#xA;&#xA;// Cook-Torrance Bidirectional Reflective Distribution Function&#xA;vec3 BRDF(vec3 L, vec3 V, vec3 N, vec3 radiance, vec4 albedo, float metallic, float roughness, vec3 F0) {&#xA;    vec3 H = normalize (V + L);&#xA;&#xA;    float D = NormalDistributionFunction(N, H, roughness);   &#xA;    float G = GeometryFunction(N, V, L, roughness);      &#xA;    vec3  F = FresnelFunction(max(dot(H, V), 0.0), F0);&#xA;&#xA;    vec3 numerator = D * G * F; &#xA;    float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // Prevent division by zero.&#xA;    vec3 specular = numerator / denominator;&#xA;&#xA;    vec3 kS = F;&#xA;    vec3 kD = vec3(1.0) - kS;&#xA;    kD *= 1.0 - metallic;     &#xA;&#xA;    float NdotL = max(dot(N, L), 0.0);        &#xA;&#xA;    vec3 color = (kD * albedo.rgb / PI + specular) * radiance * NdotL;&#xA;    return color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zDaPU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zDaPU.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does this physically make sense?&lt;br&gt;&#xA;The only workaround I see is either not using a perfect mirror value of 0.0 roughness or always clamp the minimum value to something like 0.04.&lt;/p&gt;&#xA;" OwnerUserId="7925" LastActivityDate="2019-09-07T18:17:32.527" Title="Roughness Value of (Close to) Zero in Physically Based Rendering" Tags="&lt;lighting&gt;&lt;brdf&gt;&lt;physically-based&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9124" PostTypeId="1" AcceptedAnswerId="9128" CreationDate="2019-09-07T02:20:57.350" Score="2" ViewCount="108" Body="&lt;p&gt;As described by Shirley in his computer graphics book,&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Cubic curves provide the minimum-curvature interpolants to a set of points. That is, if you have a set of n + 3 points and define the “smoothest” curve that passes through them (that is the curve that has the minimum curvature over its length), this curve can be represented as a piecewise cubic with n segments.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Could you please give some hints or references about its proof?&lt;/p&gt;&#xA;" OwnerUserId="9522" LastEditorUserId="231" LastEditDate="2019-09-07T18:50:28.767" LastActivityDate="2019-09-07T22:39:48.397" Title="Why cubic curves provide the minimum curvature interpolants?" Tags="&lt;curve&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9125" PostTypeId="1" CreationDate="2019-09-07T11:18:13.700" Score="0" ViewCount="149" Body="&lt;p&gt;I am making ski jumping game (in Unity) with procedurally generated hill mesh. I want to add lines on hill like this (mesh is created by script, but I've manually assigned materials in Blender) &lt;a href=&quot;https://i.stack.imgur.com/g502s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g502s.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because this is procedurally generated (on runtime) (hills can have different sizes) I cannot bake texture in Blender. Mesh for large hill has around 800 vertices. There is my question - is it better to duplicate vertices and then use one material or use four different materials without duplicating vertices?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/k0CJH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/k0CJH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11150" LastActivityDate="2019-09-09T04:30:00.433" Title="What is performance better - add four materials to mesh or duplicate every vertex and use packed texture?" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;unity&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9126" PostTypeId="2" ParentId="9123" CreationDate="2019-09-07T18:17:32.527" Score="6" Body="&lt;p&gt;Yes, I think it's expected that setting roughness = 0, combined with using point lights for illumination, leads to no visible specular highlight. The size of the highlight is infinitesimally small, so the sample points (e.g. pixel centers) almost surely miss it. The math breaks down as well, as the reflectance would become infinite on the zero-sized highlight (a delta function).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clamping roughness to a minimum seems like a physically reasonable thing to do. 0.04 feels like too large a minimum, though; I might pick 0.001 or 0.0001 or something like that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you use area lights, then a perfect mirror surface (roughness = 0) could still work and would show the sharp reflected image of the area light. This would probably still require special-casing the perfect-mirror case in shading code, to avoid the problems with infinities.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-09-07T18:17:32.527" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9127" PostTypeId="2" ParentId="9124" CreationDate="2019-09-07T19:59:44.957" Score="2" Body="&lt;p&gt;Splines confuse me which is one reason I asked somebody else to write that chapter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I like this explanation:&#xA;&lt;a href=&quot;https://www.johndcook.com/blog/2009/02/06/the-smoothest-curve-through-a-set-of-points/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.johndcook.com/blog/2009/02/06/the-smoothest-curve-through-a-set-of-points/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6422" LastActivityDate="2019-09-07T19:59:44.957" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9128" PostTypeId="2" ParentId="9124" CreationDate="2019-09-07T22:33:31.893" Score="2" Body="&lt;p&gt;For a function &lt;span class=&quot;math-container&quot;&gt;$y = f(x)$&lt;/span&gt; the (signed) curvature at &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is given by:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\kappa(x) = \frac{f''(x)}{(1+f'^2(x))^{\frac{3}{2}}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you assume that the slope is very small compared to &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt;: &lt;span class=&quot;math-container&quot;&gt;$ f'^2&amp;lt;\!&amp;lt;1 $&lt;/span&gt;, then:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ k(x) \approx f''(x)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Suppose you are given data points (&lt;span class=&quot;math-container&quot;&gt;$x_0&amp;lt;x_1&amp;lt;\cdots&amp;lt;x_N$&lt;/span&gt;):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(x_0,y_0), (x_1,y_1), ..., (x_N, y_N)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You want to find an interpolating function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;, such that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$f(x_k) = y_k$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And we'll additionally require that it minimizes the energy:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$E[f] = \int_{x_0}^{x_N}\left(f''(x)\right)^2\,dx$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$f(x_k) = y_k \wedge \exists f''(x) \wedge f''(x_0)=f''(x_N) = 0$&lt;/span&gt;, and let &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; be piece-wise cubic, then:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\forall g \ne f : g(x_k) = y_k \wedge \exists g''(x) \implies $$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ E[g] = \int_{x_0}^{x_N}\left(g''(x)\right)^2\,dx &amp;gt; \int_{x_0}^{x_N}\left(f''(x)\right)^2\,dx = E[f]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Proof:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$E[g] - E[f] = \int_{x_0}^{x_N}\left(g''(x)\right)^2\,dx - \int_{x_0}^{x_N}\left(f''(x)\right)^2\,dx = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ \int_{x_0}^{x_N}\left(g''(x)\right)^2\,dx -2\int_{x_0}^{x_N}g''(x)f''(x)\,dx + \int_{x_0}^{x_N}\left(f''(x)\right)^2\,dx$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$- 2\int_{x_0}^{x_N}\left(f''(x)\right)^2\,dx + 2\int_{x_0}^{x_N}g''(x)f''(x)\,dx = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_{x_0}^{x_N}\left(g''(x)-f''(x)\right)^2\,dx + 2\int_{x_0}^{x_N}(g''(x)-f''(x))f''(x)\,dx $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clearly if &lt;span class=&quot;math-container&quot;&gt;$g \ne f$&lt;/span&gt; almost everywhere then &lt;span class=&quot;math-container&quot;&gt;$\int_{x_0}^{x_N}\left(g''(x)-f''(x)\right)^2\,dx &amp;gt; 0$&lt;/span&gt;, then to prove &lt;span class=&quot;math-container&quot;&gt;$E[g]-E[f]&amp;gt;0$&lt;/span&gt; it remains to show that: &lt;span class=&quot;math-container&quot;&gt;$2\int_{x_0}^{x_N}(g''(x)-f''(x))f''(x)\,dx \geq 0$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Integrating by parts yields:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$2\int_{x_0}^{x_N}(g''(x)-f''(x))f''(x)\,dx = 2\int_{x_0}^{x_N}f''(x)\,d[g'(x)-f'(x)] = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ 2(g'(x_N)-f'(x_N))f''(x_N) - 2(g'(x_0)-f'(x_0))f''(x_0)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$-2\int_{x_0}^{x_N}(g'(x)-f'(x))f'''(x)\,dx = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since &lt;span class=&quot;math-container&quot;&gt;$f''(x_N) = f''(x_0) = 0$&lt;/span&gt; the first two terms are 0, and we are left with:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$- 2\int_{x_0}^{x_N}(g'(x)-f'(x))f'''(x)\,dx = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; was chosen to be piece-wise cubic, then &lt;span class=&quot;math-container&quot;&gt;$f(x) = a_kx^3 + b_kx^2 + c_kx + d_k, x \in [x_k,x_{k+1})$&lt;/span&gt; and consequently &lt;span class=&quot;math-container&quot;&gt;$f'''([x_k,x_{k+1})) = 6a_k = &#xA;\operatorname{const}$&lt;/span&gt;, and we can take it out of the integral and integrate in each interval &lt;span class=&quot;math-container&quot;&gt;$[x_k,x_{k+1}]$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$-2\sum_{k=0}^{N-1}f'''([x_k,x_{k+1}))\int_{x_k}^{x_{k+1}}(g'(x)-f'(x))\,dx = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$-2\sum_{k=0}^{N-1}6a_k[g(x_{k+1})-f(x_{k+1}) - (g(x_k) - f(x_k))] = $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the interpolation constraint &lt;span class=&quot;math-container&quot;&gt;$f(x_k) = g(x_k) = y_k$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$-2\sum_{k=0}^{N-1}6a_k[y_{k+1} - y_{k+1} - (y_k-y_k)] = 0$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thus:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$E[g] - E[f] = \int_{x_0}^{x_N}\left(g''(x)-f''(x)\right)^2\,dx &amp;gt; 0$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And consequently:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$E[g] &amp;gt; E[f]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which proves the fact that an interpolating C2 cubic spline with natural end conditions minimizes the squared (approximate) &quot;curvature&quot; energy:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ E[f] = \int_{x_0}^{x_N}\left(f''(x)\right)^2\,dx $$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-09-07T22:39:48.397" LastActivityDate="2019-09-07T22:39:48.397" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9129" PostTypeId="1" AcceptedAnswerId="9134" CreationDate="2019-09-08T15:15:48.260" Score="1" ViewCount="47" Body="&lt;p&gt;There's one paper published at siggraph that captured my attention : &lt;a href=&quot;https://arxiv.org/pdf/1707.07070.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Steklov Spectral Geometry&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not an expert in geometry processing, but I'm trying to learn as much as I can.&#xA;You can easily read in the introduction:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In this paper we provide a practical and mathematically justified spectral approach to extrinsics geometry for geometry processing via an extrinsic alternative to the intrinsic Laplace-Beltrami operator.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I read through the paper and, for who like me enjoy signal processing, is a very nice read. It my understanding the operator they propose an alternative of the classic laplace beltrami operator:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\Delta_{\mathcal{S}} \psi(x) = 0 &#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The operator proposed is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\left\{&#xA;\begin{array}{ll}&#xA;\Delta \psi(x) = 0 &amp;amp; x \in \Omega \\&#xA;\nabla_n \psi(x) = \lambda \psi(x) &amp;amp; x \in \Gamma&#xA;\end{array}&#xA;\right.&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which is the &quot;Steklov eigenproblem&quot;. The first line of the system above is the laplace equation again (but volumetric) the second line is a condition on the normal derivative.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I don't understand is why does the former operator represent an &quot;intrinsics&quot; operator while the latter represent an extrinsic operator.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2019-09-09T06:00:54.840" Title="Stecklov operator vs Laplacian operator" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9130" PostTypeId="1" CreationDate="2019-09-08T16:01:53.950" Score="0" ViewCount="55" Body="&lt;p&gt;I am trying to create a raytracer following peter shirley's in a weekend series. I am getting weird color distortion artifacts when I am running the code on windows. However, the code runs fine when executed on the on my mac. The only difference in code being that I had to replace &lt;code&gt;drand48()&lt;/code&gt; with &lt;code&gt;(float)rand() / (RAND_MAX + 1.0)&lt;/code&gt; as the former is not supported on windows.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How the image looks on windows &#xA;&lt;a href=&quot;https://i.stack.imgur.com/S0Klb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S0Klb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How it should look&#xA;&lt;a href=&quot;https://i.stack.imgur.com/W2SoL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W2SoL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Heres the code I am using to generate the ppm file &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void writeToImgae(Vector3f *frameBuffer, RenderOptions *options)&#xA;{&#xA;    ofstream ofs(&quot;finalImage.ppm&quot;, ios::out);&#xA;    ofs &amp;lt;&amp;lt; &quot;P6\n&quot;&#xA;            &amp;lt;&amp;lt; options-&amp;gt;width &amp;lt;&amp;lt; &quot; &quot; &amp;lt;&amp;lt; options-&amp;gt;height &amp;lt;&amp;lt; &quot;\n255\n&quot;;&#xA;    for (uint32_t i = 0; i &amp;lt; options-&amp;gt;height * options-&amp;gt;width; ++i)&#xA;    {&#xA;        char r = (char)(255 * clamp(frameBuffer[i].x, 0.0f, 1.0f));&#xA;        char g = (char)(255 * clamp(frameBuffer[i].y, 0.0f, 1.0f));&#xA;        char b = (char)(255 * clamp(frameBuffer[i].z, 0.0f, 1.0f));&#xA;        ofs &amp;lt;&amp;lt; r &amp;lt;&amp;lt; g &amp;lt;&amp;lt; b;&#xA;    }&#xA;    ofs.close();&#xA;    delete[] frameBuffer;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Would really appreciate if someone could help me with this.&lt;/p&gt;&#xA;" OwnerUserId="5098" LastActivityDate="2019-09-08T16:01:53.950" Title="Weird Ray tracing artifacts when Code run on widows" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9131" PostTypeId="1" AcceptedAnswerId="9149" CreationDate="2019-09-08T21:26:29.543" Score="0" ViewCount="247" Body="&lt;p&gt;I'm trying to learn the fundamentals of 3d computer graphics by writing a toy framework in WebGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm currently working on mouse based camera controls. There are plenty of good resources in the ACM SIGGRAPH library to be found, but there are some aspects of this area that I can't find answers to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A lot of orbit controls simply use the origin as the pivot point, but other implementations can orbit around any arbitrary point in a scene and the camera stays 'still'. I'm trying to implement the latter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems that a good way to do this would be to simply get the cross product of the two vectors made by the pivot point and 3d coords of the corresponding pixels on the image plane, but I can't anything like this approach anywhere which leads me to believe I've misunderstood some fundamental aspect of image projection/image planes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the image plane an abstract construct that doesn't really have 3d coords or can pixels in the image plane actually be mapped to world coords?&lt;/p&gt;&#xA;" OwnerUserId="11153" LastActivityDate="2019-09-13T04:01:11.973" Title="Can pixels on the image plane be mapped to world space coordinates?" Tags="&lt;transformations&gt;&lt;projections&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9132" PostTypeId="2" ParentId="9125" CreationDate="2019-09-09T04:30:00.433" Score="1" Body="&lt;p&gt;Hello and welcome Jonek2208! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unity specific questions probably are better suited for the &lt;a href=&quot;https://forum.unity.com/categories/graphics.75/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unity Graphics Forum&lt;/a&gt;. However, I'll try to give you an answer as I do have some experience with the engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my opinion, the only way of knowing for sure which method is the best would be to implement both and profile them on your target device. Do not fool yourself in thinking that some basic algorithmic analysis is all you need to do. Always profile and compare your solutions, no matter the circumstances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One thing I can do is to tell you the trade-offs between the two methods, and also provide a hint at another possible solution. Let's go!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using the built-in rendering pipeline, Unity batches objects by materials. A batch is considered to be a change in GPU state followed by one or more draw calls. In other words, if you have four materials, you increase the number of batches when compared to having just one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are targeting mobile devices, reducing the batch count is one of the keys for achieving good performance, and most mobile developers would choose to use a single material. On the other hand, duplicating vertices incurs a cost in memory, and hence you get better batching at the expense of using more memory. If you are targeting consoles or PCs, you can have a much higher batch count and memory budget, so the solution that you think is simpler to implement, expand, and maintain should be your best bet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another solution would be to use textures instead of vertex colors. For this, you would need to compute the uv-map procedurally when generating the vertices. You could place all textures into an atlas and try to use a single material. This is the usual solution for mobile. If you are targeting PCs/consoles, you could even afford procedural textures in your fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are using the latest version of Unity, you can use the SRP Batcher, which batches per shader instead of per material. Hence, you can use 4 materials, but have a single batch if all of them use the same shader. Note some devices may not have this capability, especially on mobile.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All in all, there are a lot of things to consider in any kind of application. That is why I started talking about profiling on your target device. Honestly, it is the only way of knowing for sure which method is the best. You should build a test scene with thousands of generated meshes and then profile each method. Select the one that fits best in your budget (FPS/memory/etc) and the long-term goals of your project.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Good luck! :)&lt;/p&gt;&#xA;" OwnerUserId="4768" LastActivityDate="2019-09-09T04:30:00.433" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9134" PostTypeId="2" ParentId="9129" CreationDate="2019-09-09T05:55:30.447" Score="1" Body="&lt;p&gt;I'm not entirely sure, but I guess it might have to do with the notions of &lt;a href=&quot;https://www.maths.ox.ac.uk/about-us/departmental-art/theory/differential-geometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;intrinsic vs extrinsic curvature&lt;/a&gt;. The Laplace–Beltrami operator on a manifold is, I think, intrinsic in the sense that it can be constructed from the &quot;internal&quot; geometry within the manifold itself, and doesn't depend on any embedding in an ambient space. The Steklov operator, on the other hand, looks like it's written explicitly in terms of an embedding, so would be extrinsic in that sense.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2019-09-09T06:00:54.840" LastActivityDate="2019-09-09T06:00:54.840" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9135" PostTypeId="1" CreationDate="2019-09-09T14:04:31.513" Score="1" ViewCount="1541" Body="&lt;p&gt;looking for suggestion whether it is worth implementing a post process FXAA pass on modern mobile GPU's (mainly looking at apple A Series chip), or should i simply use the MSAA.&#xA;Did a basic test with implementing basic FXAA which took eight neighbouring samples and averaged them for result. The performance of this FXAA was even a bit slower than turning on MSAA. &#xA;I am using Metal API, if that helps.&lt;/p&gt;&#xA;" OwnerUserId="11155" LastActivityDate="2019-09-11T03:39:53.173" Title="FXAA vs MSAA on modern hardware" Tags="&lt;antialiasing&gt;&lt;metal&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9137" PostTypeId="2" ParentId="9135" CreationDate="2019-09-10T03:17:18.660" Score="4" Body="&lt;p&gt;Most mobile GPUs use &lt;a href=&quot;https://en.wikipedia.org/wiki/Tiled_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;tiled rendering&lt;/a&gt;, which can make MSAA surprisingly cheap relative to desktop GPUs. If the app is doing simple forward rendering without filtering/blurring passes, the GPU may be able to do MSAA rasterization and resolve directly on chip (per tile) without ever storing the MSAA samples out to memory. This may make MSAA both faster and less power-hungry than a technique like FXAA that relies on filtering the framebuffer (which necessitates storing it out to memory and reading it back in when sampling).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for image quality, it's difficult to compare (and is subjective anyway). FXAA might be better at reducing jaggies depending on the MSAA level, but at the cost of over-blurring edges. FXAA can also address shader aliasing, for example aliasing due to specular on a rough normal map and such things, which MSAA won't help with. Ultimately you'll have to make a choice whether the aesthetic benefits (if any) outweigh the increased cost.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-09-10T03:17:18.660" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9139" PostTypeId="1" CreationDate="2019-09-10T19:16:01.373" Score="0" ViewCount="67" Body="&lt;p&gt;I've been experimenting with raytracing using GLSL. I had success rendering a cube which encloses the object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I want to do a full-screen raytrace, and I want to construct a quad which covers the screen. This isn't working.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, for the working version, the shaders looked something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;in vec3 v_position;&#xA;&#xA;uniform mat4 u_proj_view;&#xA;&#xA;void main ()&#xA;{&#xA;    gl_Position = u_proj_view * vec4 (v_position, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment shader, which computes the word coordinate &lt;code&gt;W&lt;/code&gt; of the fragment, and given the eye coordinate &lt;code&gt;E&lt;/code&gt; solves &lt;code&gt;P=E+t(W-E)&lt;/code&gt; for &lt;code&gt;t&lt;/code&gt; given some surface intersection constraint on &lt;code&gt;P&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 W = screen_to_world (gl_FragCoord, inverse_proj_view, viewport);&#xA;vec3 EW = W - E;&#xA;// solve for t, etc etc.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;screen_to_world&lt;/code&gt; function I took from &lt;a href=&quot;https://stackoverflow.com/questions/38938498/how-do-i-convert-gl-fragcoord-to-a-world-space-point-in-a-fragment-shader&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 screen_to_world&#xA;(&#xA;    in vec4 screen_fragment_coordinate,&#xA;    in mat4 inverse_projection_view,&#xA;    in vec4 viewport&#xA;)&#xA;{&#xA;    vec4 S = screen_fragment_coordinate;&#xA;    vec4 NDC;&#xA;&#xA;    NDC.xy = ((2.0 * S.xy) - (2.0 * viewport.xy))&#xA;        / (viewport.zw) - 1.0;&#xA;&#xA;    NDC.z = (2.0 * S.z - gl_DepthRange.near - gl_DepthRange.far) /&#xA;        (gl_DepthRange.far - gl_DepthRange.near);&#xA;&#xA;    NDC.w = 1.0;&#xA;&#xA;    return vec4 (inverse_projection_view * (NDC / S.w)).xyz;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For the full-screen render, It would be nice to construct a quad directly in clip space, or directly in screen space. I tried using vertex data like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Vertex full_screen_quad [4] =&#xA;{&#xA;    {{-1, -1, 0.5}},&#xA;    {{+1, -1, 0.5}},&#xA;    {{-1, +1, 0.5}},&#xA;    {{+1, +1, 0.5}}&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And changed the vertex shader to&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl_Position = vec4 (v_position, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which omits the projection-view transformation. I was hoping that this would still produce valid values for &lt;code&gt;screen_to_world&lt;/code&gt; in the fragment shader, but no such luck. The screen is filled but the rays are wonky.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To investigate, I printed out the coordinates of the cube vertices when multiplied by the projection-view matrix and, when the cube was on screen, were something like&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4(-2.704530, -12.888471, 12.998095, 13.171925)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I was expecting values in the range &lt;code&gt;[0..1]&lt;/code&gt;, so clearly I don't understand which coordinate space I'm working in, or I don't understand w-coordinates, or viewports, or something.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there &lt;em&gt;fixed&lt;/em&gt; coordinates which I can &lt;em&gt;directly&lt;/em&gt; pass to &lt;code&gt;gl_Position&lt;/code&gt;, &lt;em&gt;untransformed&lt;/em&gt;, which will effectively cover the near plane of the viewing frustum, exactly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(When done correctly, passing such coordinates to the above &lt;code&gt;screen_to_world&lt;/code&gt; will yield the world-space coordinates of the near frustum plane.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can I describe these independently of the projection-view matrix, and still have &lt;code&gt;screen_to_world&lt;/code&gt; work correctly for each fragment?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, and less ideally, can I hack some world-space coordinates, given the arguments to &lt;code&gt;glm::lookAt&lt;/code&gt; and &lt;code&gt;glm::perspective&lt;/code&gt; (which produce the &lt;code&gt;projection*view&lt;/code&gt; matrix), such that they will cover the near frustum plane?&lt;/p&gt;&#xA;" OwnerUserId="8233" LastActivityDate="2019-09-10T19:16:01.373" Title="What quad will fill the screen, which can be inverse-projection-view transformed to map to the near frustum plane?" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;glsl&gt;&lt;projections&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9140" PostTypeId="2" ParentId="9135" CreationDate="2019-09-11T03:39:53.173" Score="2" Body="&lt;p&gt;It's important to understand that &quot;anti-aliasing&quot; techniques like FXAA were invented mainly to deal with the fact that standard methods like multisampling do not work well at all in deferred rendering situations. In order to do MSAA in a deferred renderer, you would need to have all of your G-buffers be multisampled, which dramatically increases the size of those g-buffers. Which puts more pressure on the GPU's memory bandwidth during the lighting passes, since you have that much more data to read. Plus, the lighting passes have to do per-sample rendering, so most of the benefit of MSAA compared to straight super-sampling gets tossed out with lighting passes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, all of that is only really true on standard desktop GPUs. Tile-based platforms (commonly found in the mobile space) can potentially avoid the memory cost increase entirely by keeping the multisampled g-buffers within tile memory alone. Of course, only modern APIs like Metal and Vulkan are capable of really expressing this concept at the API level, but the capability is there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Oh sure, MSAA on a TBR will still require lots more tiles and therefore lighting shader invocations. And the lighting passes still have to do per-sample computations. But the overall performance cost will scale much better than a desktop GPU for deferred rendering, as there will be a &lt;em&gt;lot&lt;/em&gt; less memory bandwidth pressure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Plus, there's the fact that FXAA-style techniques run roughshod over how TBRs work. FXAA-like techniques require reading from neighboring texels, which may be outside of the current tile. Well, that means you have to resolve all of your rendering before doing the FXAA pass. That's a bad thing. By contrast, multisampling, including the multisample resolve operation, can be done in-situ within a given tile.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it's not really a surprise that FXAA would not yield better performance than even relatively light MSAA on a TBR-style GPU. &lt;em&gt;Especially&lt;/em&gt; if you're not using deferred rendering.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-09-11T03:39:53.173" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9141" PostTypeId="2" ParentId="3575" CreationDate="2019-09-11T06:23:36.163" Score="0" Body="&lt;p&gt;I'm self taught in C++ without any formal education and throughout the past 15 years I've learned both OpenGL 1.0 up through Modern OpenGL and DirectX 9c, 10 and 11. I have not gotten into DirectX 12 and I've been wanting to try my hand at Vulkan. I have only completed a few basic tutorials to draw a simple triangle or a simple spinning cube with Vulkan. As with DirectX 11 and OpenGL 3.3+ I have written fully working 3D Game Engines and even used them Engines to build simple games.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would have to say that it depends on the overall environment of the person who is learning. If you are just getting into 3D Graphics Programming I would say for starters to jump into OpenGL or DirectX 11 since there is plenty of tutorials, resources, examples and already working applications out there. Learning 3D Graphics is by no means an easy subject.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we abstract away from the programming aspect of it and just focus on the notion of what kind of techniques are used involving the different levels of math leading into data sets and data structures and algorithms; there is a lot that you have to know and understand first before you can even try to build a 3D Game Engine or to use an existing one effectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if you already understand all of the math and theory behind it and you have some programming experience you can use already existing APIs, Libraries and Applications such as Unity or Unreal Engine and just write the source code and scripts you need to make your application work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So from my own understanding and the way that I see it is this if you are looking to build a quick game just for the sake of building a game; go with already existing frame works that would make your production time much smaller. On the other hand, if you want to understand the inner workings of how Game Engines / Physics Engines / Animation Engines and Simulators are designed and want to build one yourself, then this is where you have a choice between choosing your API such as DirectX, OpenGL or Vulkan. One of the determining factors here would also be your existing programming knowledge. What I mean by this is if you don't know anything about multi-threading, synchronous vs asynchronous calls, memory fences, data races, semaphores, and parallelism (parallel programming), then I would suggest to stay away from Vulkan and stick with either DirectX 11 or OpenGL versions 3.3 - 4.x.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I mention this because if you don't know how to properly manage your memory along with your threads and access time; Vulkan will bite you in the arse! Where OpenGL and DirectX will hold your hand all the way through consuming much more CPU power. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now if your level of programming knowledge is decent, and you have the following math backgrounds that involves all levels of Algebra, Geometry, Trigonometry, Boolean Algebra, Probability, Statistics, Vector - Matrix based Algebra, Calculus I,II,.... Infinty(lol). Vector Calculus, Linear Algebra, Systems of Linear Equations, Analytical Geometry with Vector Calculus of Multi-variable calculations, Number and Set Theory, Data Sets and Structures, Computational Analysis, Computational and Algorithmic Design. Then you can get into the concepts of what it takes to make an actual game engine and this is without any Applied Mathematics or any Physics equations which you will need. Once you have that background and enough programming experience especially memory management and pointer arithmetic then you can begin to build your Game Engine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the thing here is you have to understand all of the aspects of what it takes to make a Game Engine in order to Do Advanced Graphics Programming. If you are doing just 2D graphics then life isn't too hard as you can do that in Python without any of the aforementioned APIs! But if you want to be serious and design a full fledged power house Game Engine that is robust with many feature sets, then the choice here would be either C or C++ and using either OpenGL, Direct X or Vulkan. Any of them would be just fine. Now if you are building the Engine from Scratch and you are looking for the most &quot;efficient&quot; running Engine with the least amount of resource overhead then you would want to choose Vulkan. But if you go this route you should at least know everything that I had mentioned above and some! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So as you can see Vulkan is not really geared towards beginner programmers in this field. You have to have extensive knowledge of all of the math, programming paradigms, all of the different types of data sets and algorithms including threading, memory synchronization, parallel programming. And even then that's just to get the application to load a simple 2D triangle on to the screen. What can be done in about 100 lines of code in OpenGL or 250 lines of code in DirectX takes almost 1,000 lines of Code in Vulkan!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan leaves everything up to you as your are responsible for all aspects of how you are using Vulkan in your application. There is no hand holding, it doesn't get in your way, it'll allow you to shoot yourself in the foot or allow you to hang yourself buy a recursive noose!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now this isn't to say that beginners or those that are new to this field shouldn't learn Vulkan, but what I would suggest for them is this: First Learn enough of OpenGL and or DirectX to get your feet wet to see how a basic application is structured just to render a simple triangle or a spinning cube. Get familiar with their APIs and their recurring patterns of their structures. While learning that you could learn Vulkan on the side in Parallel then this way you can see how each of the three are accomplishing the same task, but know how they do it differently, then you can also compare the results between the different APIs and from there you can then make a choice of which is preferred to you. This method would also give you another tool in your tool box, and you could even write your application to support all 3 and have the &quot;User&quot; select which Renderer to choose at application start up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the end it is all up to that person to choose which route they want to go down, and from there their success will be determined by their dedication, constant study, hard work, trial and error, and most importantly their failures. If you don't fail then you are not successful! You are only successful if you have failed, found your mistake(s), fixed them, moved on and got back up and did it all over again! &lt;/p&gt;&#xA;" OwnerUserId="11163" LastActivityDate="2019-09-11T06:23:36.163" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9142" PostTypeId="1" CreationDate="2019-09-11T09:46:37.343" Score="1" ViewCount="500" Body="&lt;p&gt;I'm  using an app for face redaction that doesn't allow access to the source code but only allows me to pass pixel values for red, green and blue channel upon which it creates a matrix with the same average RGB values for every ROI pixel value. For eg. if I give Red=32,Blue=123 and Green=233 it will assign these RGB values for every pixel of the ROI and then draws a colored patch on the face.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I was wondering is there a general combination of RGB values of a pixel to distort it and make it look like it's blurred. I can also set the opacity value in the app.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="11165" LastActivityDate="2019-09-18T04:21:40.040" Title="Blurring image with RGB values without convolving it with a kernel" Tags="&lt;image-processing&gt;&lt;blur&gt;&lt;gaussian-blur&gt;" AnswerCount="3" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9144" PostTypeId="2" ParentId="9142" CreationDate="2019-09-11T17:24:42.940" Score="3" Body="&lt;p&gt;Blurring an image depends on being able to read from the image. If you don’t have access to the pixel data, or external information about the image contents (e.g. average hue / luminance), there’s no way to find an overlay color that will look like you’ve blurred what it’s on top of.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-09-11T17:24:42.940" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9145" PostTypeId="2" ParentId="9142" CreationDate="2019-09-12T07:26:56.790" Score="1" Body="&lt;p&gt;Since you know vaguely what the pixels you're covering up look like (they are faces), your best bet to get the appearance of a blur is to really blur an image of a face in a standard image editing tool, then use the colour picker to choose a representative colour from that region. That's the closest you can get, but it still won't look blurred: as Noah Witherspoon said, that's impossible given these constraints.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously it will work less well if the pictures you're operating on have different lighting conditions or faces of a different skin colour from the one you sample. And if the images being redacted are frames of a video, the motion of the video will give you away immediately.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another approach might be to choose a colour that you know won't show up in the real images (e.g. programmer pink). Then, instead of showing the image that comes out of your tool, use the marked pixels to generate a mask, and use an actual blur tool on the original image so that only the pixels selected by the mask are blurred.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-09-12T07:26:56.790" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9146" PostTypeId="1" CreationDate="2019-09-12T11:42:58.803" Score="1" ViewCount="173" Body="&lt;p&gt;I've developed a simple (Third-Person) Perspective Camera with Orbit controls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, my implementation doesn't handle the case where if the pitch goes over 90º it flips upside down. From what I've learned, the reason behind it has to do with using the Look-At function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My questions are:  &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is the problem really the Look-at function? How would I fix this, without restricting the camera's pitch?&lt;/li&gt;&#xA;&lt;li&gt;I want to develop a camera class that is control agnostic (can be fly, orbit, ...) and therefore not take into account that it's first/third-person. Are there methods on how to develop such a camera abstraction?  &lt;/li&gt;&#xA;&lt;li&gt;I also want it to be able to roll, can the advised solution for the last question support it? &lt;/li&gt;&#xA;&lt;li&gt;I haven't delved into quaternions yet, is the solution based on them? If so, are there also limitations to an implementation like that?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I'm basically looking for theory on developing proper robust cameras (with as few limitations as possible), so if you could point me into the right direction it would be nice, but a full answer is also very much appreciated. Code is not essential, but it would be also very helpful to see a proper (yet simple) implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My camera implementation (in Vulkan):&lt;br&gt;&#xA;Camera.hpp:  &lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#pragma once&#xA;&#xA;#define GLM_FORCE_RADIANS&#xA;#define GLM_FORCE_DEPTH_ZERO_TO_ONE&#xA;#include &amp;lt;glm/glm.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/quaternion.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/matrix_transform.hpp&amp;gt;&#xA;&#xA;#include &amp;lt;GLFW/glfw3.h&amp;gt;&#xA;&#xA;&#xA;class CameraControl;&#xA;&#xA;class Camera &#xA;{&#xA;private:&#xA;    glm::vec3 position = glm::vec3(0.0f, 0.0f, 1.0f);&#xA;    glm::vec3 target = glm::vec3(0.0f, 0.0f, 0.0f);&#xA;&#xA;    glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);&#xA;&#xA;    float fov = glm::radians(45.0f);&#xA;    float aspectRatio = 1.0f;&#xA;    float near = 0.1f;&#xA;    float far = 1000.0f;&#xA;&#xA;    glm::mat4 view;&#xA;    glm::mat4 projection;&#xA;&#xA;private:&#xA;    void updateViewMatrix();&#xA;    void updateProjectionMatrix();&#xA;&#xA;public:&#xA;    CameraControl *control;&#xA;&#xA;public:&#xA;    Camera();&#xA;    ~Camera();&#xA;    void setPosition(glm::vec3 position);&#xA;    void setTarget(glm::vec3 target);&#xA;    void setPerspective(float fov, float aspectRatio, float near, float far);&#xA;&#xA;    glm::mat4 inline getView() { return view; };&#xA;    glm::mat4 inline getProjection() { return projection; };&#xA;    glm::vec3 inline getPosition() { return position; };&#xA;    glm::vec3 inline getTarget() { return target; };&#xA;};&#xA;&#xA;&#xA;class CameraControl {&#xA;public:&#xA;    float orbitSensitivity = 0.2f;&#xA;    float zoomSensitivity = 0.0025f;&#xA;&#xA;private:&#xA;    Camera *camera;&#xA;&#xA;    bool firstMouse;&#xA;    float lastMouseX;&#xA;    float lastMouseY;&#xA;&#xA;    float distance;&#xA;    float pitch;&#xA;    float yaw;&#xA;&#xA;public:&#xA;    CameraControl(Camera *camera);&#xA;    void handleInput(GLFWwindow *window);&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Camera.cpp:  &lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#include &quot;Camera.hpp&quot;&#xA;&#xA;Camera::Camera() {&#xA;    control = new CameraControl(this);&#xA;    updateViewMatrix();&#xA;    updateProjectionMatrix();&#xA;}&#xA;&#xA;Camera::~Camera() {&#xA;    delete control;&#xA;}&#xA;&#xA;void Camera::setPosition(glm::vec3 position) {&#xA;    this-&amp;gt;position = position;&#xA;    updateViewMatrix();&#xA;}&#xA;&#xA;void Camera::setTarget(glm::vec3 target) {&#xA;    this-&amp;gt;target = target;&#xA;    updateViewMatrix();&#xA;}&#xA;&#xA;void Camera::setPerspective(float fov, float aspectRatio, float near, float far) {&#xA;    this-&amp;gt;fov = fov;&#xA;    this-&amp;gt;aspectRatio = aspectRatio;&#xA;    this-&amp;gt;near = near;&#xA;    this-&amp;gt;far = far;&#xA;    updateProjectionMatrix();&#xA;}&#xA;&#xA;void Camera::updateViewMatrix() {&#xA;    view = glm::lookAt(position, target, up);&#xA;}&#xA;&#xA;void Camera::updateProjectionMatrix() {&#xA;    projection = glm::perspective(fov, aspectRatio, near, far);&#xA;    projection[1][1] *= -1; // Vulkan coordinate system fix&#xA;}&#xA;&#xA;&#xA;CameraControl::CameraControl(Camera* camera) {&#xA;    this-&amp;gt;camera = camera;&#xA;    firstMouse = true;&#xA;    distance = 1.0f;&#xA;    pitch = 0.0f;&#xA;    yaw = 180.0f;&#xA;}&#xA;&#xA;void CameraControl::handleInput(GLFWwindow *window) {&#xA;    double xpos, ypos;&#xA;    glfwGetCursorPos(window, &amp;amp;xpos, &amp;amp;ypos);&#xA;&#xA;    if (firstMouse) {&#xA;        lastMouseX = xpos;&#xA;        lastMouseY = ypos;&#xA;        firstMouse = false;&#xA;    }&#xA;&#xA;    float xoffset = xpos - lastMouseX;&#xA;    float yoffset = lastMouseY - ypos;&#xA;&#xA;    lastMouseX = xpos;&#xA;    lastMouseY = ypos;&#xA;&#xA;    if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT)) {&#xA;        pitch -= yoffset * orbitSensitivity;&#xA;        yaw -= xoffset * orbitSensitivity;&#xA;    }&#xA;&#xA;    if(glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT)) {&#xA;        distance += yoffset * zoomSensitivity;&#xA;        distance = glm::max(distance, 0.0f);&#xA;    }&#xA;&#xA;    float verticalDistance = distance * glm::sin(glm::radians(pitch));&#xA;    float horizontalDistance = distance * glm::cos(glm::radians(pitch));&#xA;&#xA;    glm::vec3 position;&#xA;    position.x = camera-&amp;gt;getTarget().x - horizontalDistance * glm::sin(glm::radians(yaw));&#xA;    position.y = camera-&amp;gt;getTarget().y + verticalDistance;&#xA;    position.z = camera-&amp;gt;getTarget().z - horizontalDistance * glm::cos(glm::radians(yaw));&#xA;    camera-&amp;gt;setPosition(position);&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Thank you for your attention! Cheers!&lt;/p&gt;&#xA;" OwnerUserId="7925" LastActivityDate="2021-02-03T18:01:55.360" Title="Camera Implementation without Limitations" Tags="&lt;mathematics&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9147" PostTypeId="2" ParentId="9146" CreationDate="2019-09-12T13:40:43.507" Score="0" Body="&lt;p&gt;Attach your camera to some pivot (in a transformation hierarchical sense). Rotate the pivot rather than the camera (do not use look at). It boils down to using &lt;span class=&quot;math-container&quot;&gt;$T_{pivot} R_{pivot}  T_{cam}  R_{cam}$&lt;/span&gt;. Where &lt;span class=&quot;math-container&quot;&gt;$T_{pivot}$&lt;/span&gt; is a translation matrix derived from the position of the pivot in world space, &lt;span class=&quot;math-container&quot;&gt;$R_{pivot}$&lt;/span&gt; is the rotation matrix of the pivot (what you want), &lt;span class=&quot;math-container&quot;&gt;$T_{cam}$&lt;/span&gt; is a translation matrix derived from the position of the camera in the pivot's coord system, similarly for &lt;span class=&quot;math-container&quot;&gt;$R_{cam}$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-09-12T13:40:43.507" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9149" PostTypeId="2" ParentId="9131" CreationDate="2019-09-13T04:01:11.973" Score="1" Body="&lt;p&gt;What you are asking about is 'mouse picking'. If a user clicks a pixel on the screen how can you get corresponding world space coordinates of an object being clicked on. &#xA;Imagine a ray from that pixel, through the view volume all the way to the far plane. That ray is a set of all possible points the user is clicking on. So we want to perform ray/poly ntersections with every object in the scene, and return the first intersect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To transform the pixel into world space, you first have to turn your x,y point in screen space into NDC coordinates (-1 to 1) use -1 for your Z component and 1 for W to create a 4 float component vector and then multiply that vector by the inverse projection and then inverse view matrices.&#xA;There are many examples of this process if you want to see code, but this is the basic process. &#xA;Now we have a ray from the camera/eye position into the scene, we want to do intersection tests with our objects. There are many ways of achieving this, take your pick.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps, good luck!&lt;/p&gt;&#xA;" OwnerUserId="11136" LastActivityDate="2019-09-13T04:01:11.973" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9150" PostTypeId="1" CreationDate="2019-09-13T07:40:43.110" Score="0" ViewCount="61" Body="&lt;p&gt;The command,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;fb-test -f 0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;generates and displays a test pattern on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, the command,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;cp /home/root/test.jpg /dev/fb0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;copies test image into dev/fb0 file but fails to display anything on the screen?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to resolve this issue?&lt;/p&gt;&#xA;" OwnerUserId="11174" LastActivityDate="2019-09-13T08:06:22.600" Title="Framebuffer not detecting image" Tags="&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9151" PostTypeId="2" ParentId="9150" CreationDate="2019-09-13T08:06:22.600" Score="1" Body="&lt;p&gt;Copying the bytes of a JPEG file to the framebuffer device doesn't display the image represented by the JPEG file. The file needs to be decoded by an application that understands the JPEG format, to get the actual image. Your system is working normally. You can use a command like &lt;code&gt;display&lt;/code&gt; to decode the file and draw the image to the screen.&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-09-13T08:06:22.600" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9152" PostTypeId="1" CreationDate="2019-09-13T19:21:35.273" Score="0" ViewCount="121" Body="&lt;p&gt;I'm trying to understand the computation of the path density described in the book &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/contents.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically Based Rendering&lt;/a&gt;. They assume that a path &lt;span class=&quot;math-container&quot;&gt;$$x=(x_0,\ldots,x_{n-1})=(q_0,\ldots,q_{s-1},p_{t-1},\ldots,p_0)$$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; vertices on the light and camera path, respectively, has been generated. Along with each vertex &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt; they store two densites &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\rightarrow}} p(x_i)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\leftarrow}} p(x_i)$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\rightarrow}} p(x_i)$&lt;/span&gt; is the &quot;forward&quot; density of &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt;, which is probability per unit area of &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt; as generated by the path sampling algorithm. &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\leftarrow}} p(x_i)$&lt;/span&gt; is the hypothetical probability density of &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt; if the direction of light transport was reversed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let &lt;span class=&quot;math-container&quot;&gt;$p_i(x)$&lt;/span&gt; denote the density of sampling the same path &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; with the strategy &lt;span class=&quot;math-container&quot;&gt;$(i, j)$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$i + j = s + t$&lt;/span&gt;, instead (i.e. the strategy of considering &lt;span class=&quot;math-container&quot;&gt;$x_0,\ldots,x_{i-1}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x_i,\ldots,x_{n-1}$&lt;/span&gt; as being on the light and camera path, respectively). &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing.html#eq:path-density&quot; rel=&quot;nofollow noreferrer&quot;&gt;They claim&lt;/a&gt; that &lt;span class=&quot;math-container&quot;&gt;$$p_i(x)=\overset{{}_{\rightarrow}} p(x_0)\cdots\overset{{}_{\rightarrow}} p(x_{i-1})\overset{{}_{\leftarrow}} p(x_i)\cdots\overset{{}_{\leftarrow}} p(x_{n-1})\tag1.$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I can't make sense of &lt;span class=&quot;math-container&quot;&gt;$(1)$&lt;/span&gt;. Even if we take &lt;span class=&quot;math-container&quot;&gt;$i=s$&lt;/span&gt; (in which case the &lt;span class=&quot;math-container&quot;&gt;$(i, j) = (s, t)$&lt;/span&gt; is the strategy being used for generating &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;), the formula doesn't make sense to me. Shouldn't &lt;span class=&quot;math-container&quot;&gt;$p_s(x)$&lt;/span&gt; be the product of the densities of the light and camera subpaths? The density of the light subpath is clearly &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\rightarrow}} p(x_0)\cdots\overset{{}_{\rightarrow}} p(x_{i-1})$&lt;/span&gt;, since the sampling startet at a light source at &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; and all the densities on the way to &lt;span class=&quot;math-container&quot;&gt;$x_{i-1}$&lt;/span&gt; are &quot;forward densities&quot;. On the other hand, the density of the camera subpath should be &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\rightarrow}} p(p_0)\cdots\overset{{}_{\rightarrow}} p(p_{t-1})$&lt;/span&gt;, since from &lt;span class=&quot;math-container&quot;&gt;$x_{n-1}=p_0$&lt;/span&gt; all the densities are forward densities as well. However, according to &lt;span class=&quot;math-container&quot;&gt;$(1)$&lt;/span&gt; the density of the camera subpath is &lt;span class=&quot;math-container&quot;&gt;$\overset{{}_{\leftarrow}} p(p_{t-1})\cdots\overset{{}_{\leftarrow}} p(p_0)$&lt;/span&gt;. What am I missing?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2019-09-14T04:25:27.107" LastActivityDate="2019-09-14T04:25:27.107" Title="Multiple Importance Sampling in Bidirectional Path Tracing" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;pbr&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9153" PostTypeId="1" AcceptedAnswerId="9155" CreationDate="2019-09-15T00:27:34.230" Score="1" ViewCount="355" Body="&lt;p&gt;The Dolphin emulator for GameCube/Wii has the ability to use the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_buffer_storage.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;ARB_buffer_storage&lt;/a&gt; (or &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_buffer_storage.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;EXT_buffer_storage&lt;/a&gt; for GLES) to improve rendering performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the extension's description, a GPU driver implementation provides a means to allocate storage that can be marked as immutable, i.e. cannot be deallocated or resized while in use. What is required of the driver implementation for this to actually be useful? At one extreme, a naive implementation could allocate immutable memory buffers exactly the same way it allocates typical global memory buffers, functionally correct but not beneficial for performance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At least one user has suggested buffer_storage only matters in the case of discrete GPUs which carry their own dedicated RAM storage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, the Dolphin team continually requested buffer_storage for Mali's driver over the years, which suggests there is a performance improvement even in SoCs with integrated graphics and no dedicated GPU DRAM. If so, is the benefit at all comparable and how does the driver achieve it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does Vulkan have an equivalent or somehow avoid the need for such an extension?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The intent here is to understand the value in implementing EXT_buffer_storage in the driver for Broadcom's VideoCore VI.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;[1]&lt;/sup&gt; &lt;a href=&quot;https://forums.dolphin-emu.org/Thread-dolphin-on-the-pi-4?page=14&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;Dolphin on the pi 4&quot;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;[2]&lt;/sup&gt; &lt;a href=&quot;https://community.arm.com/developer/tools-software/graphics/f/discussions/9902/will-there-be-ext_buffer_storage-support-at-all&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;Will there be EXT_buffer_storage at all?&quot;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;[3]&lt;/sup&gt; &lt;a href=&quot;https://forums.dolphin-emu.org/Thread-ext-buffer-storage-is-now-supported-by-arm&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;EXT_buffer_storage is now supported by ARM&quot;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;sup&gt;[4]&lt;/sup&gt; &lt;a href=&quot;https://www.raspberrypi.org/forums/viewtopic.php?t=249636&quot; rel=&quot;nofollow noreferrer&quot;&gt;&quot;&#xA;Possible to add GLES EXT_buffer_storage driver support to Videocore VI on the Pi4?&quot;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11180" LastEditorUserId="11180" LastEditDate="2019-09-15T14:54:45.770" LastActivityDate="2019-09-15T21:08:38.323" Title="In what scenarios and how does GL_ARB_buffer_storage help performance?" Tags="&lt;opengl&gt;&lt;memory&gt;&lt;buffers&gt;&lt;driver&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9154" PostTypeId="1" AcceptedAnswerId="9162" CreationDate="2019-09-15T15:09:58.560" Score="2" ViewCount="384" Body="&lt;p&gt;For my application, I want to render models as polygonal surfaces in 3D space and have edges that are bent &quot;outwards&quot; to have a solid line and those who are bent &quot;inwards&quot; to have a dotted line. So if I look from the top of the edge if they &quot;bend towards me&quot; they are bending inwards, if they bend away from me, they bend outwards.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For this, I need to calculate the angle between two connected triangles.&#xA;How can I calculate this angle? How can I define if it is bent outwards or inwards (looking from the top it would always bend downwards if the angle is &gt;180 and inwards (so up) if the angle is &amp;lt;180, but how can I calculate this?&lt;/p&gt;&#xA;" OwnerUserId="8757" LastEditorUserId="6" LastEditDate="2019-09-15T16:11:36.013" LastActivityDate="2019-09-16T18:18:11.340" Title="Calculating the angle between two polygons" Tags="&lt;3d&gt;&lt;vectors&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9155" PostTypeId="2" ParentId="9153" CreationDate="2019-09-15T15:19:33.280" Score="3" Body="&lt;p&gt;The marquee feature of buffer storage is not immutability of the allocation itself, but instead is a feature you couldn't have without immutable allocation: &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object#Persistent_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;persistently mapped buffers&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Pre-buffer_storage, you could not use a buffer while it was mapped. This is done to allow implementations the freedom to play games with mapping behind your back. For example, it's legal for &lt;code&gt;glMapBufferRange&lt;/code&gt; to not actually return a mapped pointer; it could just return some CPU-accessible memory which, at unmap time, will get copied into the actual buffer. To permit such freedoms, mapping and unmapping a buffer is something you have to do semi-frequently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore, pre-buffer_storage, it is 100% legal to call &lt;code&gt;glBufferData&lt;/code&gt; (note the lack of &lt;code&gt;Sub&lt;/code&gt;) on that buffer again. This will cause the old data storage to be discarded and new storage allocated. So you couldn't keep a buffer mapped if you tried to reallocate its storage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, implementations couldn't really know where to allocate storage for GPUs with multiple kinds of memory, so they would tend to move the buffer's allocation around based on how you use it. If you frequently upload to it, they'll eventually put it into CPU accessible memory to speed up such operations. And so forth. But this is all done after allocating storage, and it's done based on how you use the buffer. So having the buffer be mapped would prevent such shuffling around of data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Making a buffer's storage immutable solves these problems. You cannot reallocate an immutable buffer's storage, so there's no problem with keeping it mapped forever. &lt;code&gt;glBufferStorage&lt;/code&gt; takes usage flags which unlike &lt;code&gt;glBufferData&lt;/code&gt;'s hints, explicitly &lt;em&gt;forbid&lt;/em&gt; you from using the memory in certain ways. So the implementation knows exactly where to put the storage and will not need to move it around after the fact. So there's no problem with persistently mapped storage.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I imagine that, for a console emulator, having persistently mapped storage would be very useful. After all, programs written for such consoles touch memory directly at any time, the same memory that the GPU can address. So storing it in a buffer and keeping that memory mapped all the time probably works out better than uploading pieces of it, or trying to figure out which pieces should be uploaded, or whatever.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2019-09-15T21:08:38.323" LastActivityDate="2019-09-15T21:08:38.323" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9157" PostTypeId="1" CreationDate="2019-09-15T18:32:32.730" Score="0" ViewCount="935" Body="&lt;p&gt;I am currently building a ray tracer and I came across a problem and confusion regarding the light calculations. For lighting, I am using the following mathematical model: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MzLVB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MzLVB.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;Ka&lt;/code&gt; is the ambient color component, &lt;code&gt;Ke&lt;/code&gt; is the emission color component. The summation calculates the phong and lambert components using specular and diffusion. The summation is over all the lights where &lt;code&gt;Li&lt;/code&gt; is the light color and &lt;code&gt;Vi&lt;/code&gt; is a binary variable that eliminates the lambert and phong components for the sake of producing the shadowing effect. On the other hand, the &lt;code&gt;Ks&lt;/code&gt; is the specular component and &lt;code&gt;Ir&lt;/code&gt; is the reflective color that is calculated recursively by producing a new ray and tracing this ray. All the color components are represented by a 3D vector that stores the R, G, B colors and they take a value from 0 to 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The model sums up all the color values which can end up producing values that are greater than and in a way overflowing the maximum value for the color channel. In my ray tracer implementation this was not a problem for all the terms highlighted in white because, for all the scenes I produced, none of them actually faced the problem where the sum of the colors were greater than zero. Now my attention was brought to this problem when I added the term highlighted in green which is the reflection term. I tried different things like setting the value of the color channel to 1 when it is going to overflow and taking the modulus or even setting it to zero. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;All my solutions produce reflections, but the reflections are not smooth and have a lot of noise in them which I can't seem to eliminate.&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I searched online for this issue but I did not find a lot of details. What would be a good solution for handling the possibility of the final color overflowing in one or more channels?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: my implementation works fine without reflection which makes me believe that the color implementation is correct. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One of my sample output images:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/67GBz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/67GBz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead the desired output should be:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Jvbrd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Jvbrd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Please ignore the size and aspect ratio differences of the two images.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="10590" LastEditorUserId="8009" LastEditDate="2019-09-19T07:41:30.860" LastActivityDate="2019-09-19T07:41:30.860" Title="Color shading and light calculation for ray tracing" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;shading&gt;&lt;reflection&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9158" PostTypeId="1" CreationDate="2019-09-16T09:54:45.887" Score="1" ViewCount="298" Body="&lt;p&gt;What is the difference between post-/pre- sampling, aliasing, filtering and processing?&lt;br&gt;&#xA;How do the terms post-/pre-&lt;strong&gt;aliasing&lt;/strong&gt;, post-/pre-&lt;strong&gt;processing&lt;/strong&gt;, post-/pre-&lt;strong&gt;sampling&lt;/strong&gt; and post-/pre-&lt;strong&gt;filtering&lt;/strong&gt; relate to each other?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;On many websites/articles these terms are often used &#xA;without clearly stating the differences. &#xA;Some even use them interchangeable, all tough they&#xA;seem to have different meanings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It would be very helpfull mentioning where in the &#xA;&lt;strong&gt;graphics-pipeline&lt;/strong&gt; these steps happen &#xA;(e.g. before/while/after rasterization, etc.),&#xA;and what the refence points for the name suffixes are&lt;br&gt;&#xA;(pre … before what?, post … after what?).&lt;/p&gt;&#xA;" OwnerUserId="11189" LastEditorUserId="11189" LastEditDate="2019-09-16T12:53:21.347" LastActivityDate="2019-09-16T12:53:21.347" Title="What is the difference between post-/pre- sampling, aliasing, filtering and processing?" Tags="&lt;sampling&gt;&lt;antialiasing&gt;&lt;filtering&gt;&lt;post-processing&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9159" PostTypeId="1" AcceptedAnswerId="9160" CreationDate="2019-09-16T11:44:07.527" Score="1" ViewCount="86" Body="&lt;p&gt;I am new to OpenGL and I am trying to code un optic flow with dots appearing from the background and moving towards the viewer. As a consequence of a perspective projection, the dots are faster and bigger when they move towards the viewer, but they are smaller and slower when they are farther away from the viewer. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As a result of OpenGL perspective projection, I got the dots moving faster when approaching the viewer, but their size does not change with the distance. Isn't the change of size a consequence of the projection -- just as the change of speed? If not, shall I compute it separately?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance for your help&lt;img src=&quot;https://i.stack.imgur.com/hMcPH.gif&quot; alt=&quot;![enter image description here&quot;&gt;]&lt;a href=&quot;https://i.stack.imgur.com/hMcPH.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;1&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11191" LastActivityDate="2019-09-16T13:32:59.430" Title="Change of speed but no change of size after OpenGL Perspective Projection" Tags="&lt;opengl&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9160" PostTypeId="2" ParentId="9159" CreationDate="2019-09-16T13:32:59.430" Score="1" Body="&lt;p&gt;When you draw a point with &lt;code&gt;GL_POINTS&lt;/code&gt;, it's not a 3D object with a size in world-space: its size is a fixed number of pixels. Because of that, the size of the point is independent of the distance from the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to draw dots whose size depends on distance, you either need to compute the perspective yourself and change the point size for each point (not recommended, because state changes like that are expensive); or use another method to draw them. For instance, you might draw a quad and use the fragment shader to make it a circle (e.g. by discarding the fragment if the world co-ordinate was more than a particular distance from the centre of the quad, or by using a transparent texture with a circle in it).&lt;/p&gt;&#xA;" OwnerUserId="2041" LastActivityDate="2019-09-16T13:32:59.430" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9162" PostTypeId="2" ParentId="9154" CreationDate="2019-09-16T15:08:25.950" Score="4" Body="&lt;p&gt;I suggest computing the normal vector for each polygon and compute the angle between the normal vector of one triangle and the normal vector of a plane perpendicular to the other surface that passes through the common edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;See the following illustration, where the red arrows are the normal vectors of the red polygons. The blue vector is the plane perpendicular to the left polygon that passes through the edge common to both polygons.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/NNxNR.png&quot; alt=&quot;this image&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If your polygons are planar, then you can compute the normal for any polygon ABC by computing the cross product &lt;code&gt;AB x AC&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To obtain the blue vector, take the cross product of the normal of the left polygon and the vector that is the common edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The angle you're looking for is formed between this blue vector and the normal to the other polygon (the red vector on the right in the diagram).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You then compute the cosine of the angle between two vectors &lt;code&gt;u&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt; by taking their dot product, then dividing by their magnitudes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://www.analyzemath.com/stepbystep_mathworksheets/3D_vectors/angle_vectors.png&quot; alt=&quot;Angle between vectors&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Image taken from &lt;a href=&quot;https://www.analyzemath.com/stepbystep_mathworksheets/vectors/vector3D_angle.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="8009" LastEditorUserId="8009" LastEditDate="2019-09-16T18:18:11.340" LastActivityDate="2019-09-16T18:18:11.340" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9163" PostTypeId="1" CreationDate="2019-09-17T07:59:59.187" Score="0" ViewCount="257" Body="&lt;p&gt;I was wondering if there are any techniques for calculating the intersection point/s between two or more distance fields.&lt;/p&gt;&#xA;" OwnerUserId="6378" LastActivityDate="2019-09-17T07:59:59.187" Title="SDF collision detection" Tags="&lt;mathematics&gt;&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9165" PostTypeId="2" ParentId="4142" CreationDate="2019-09-18T03:46:50.880" Score="1" Body="&lt;p&gt;Sometimes FX studios will use projection painting. The technique basically tracks the footage onto basic geometry and use different frames for different areas of the scene(an actor may be in front of a section of the background, but isn't in another frame.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;CGMatter has a great tutorial on it: &lt;a href=&quot;https://www.youtube.com/watch?v=gz4qV5_zuMo&amp;amp;t=202s&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=gz4qV5_zuMo&amp;amp;t=202s&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11204" LastActivityDate="2019-09-18T03:46:50.880" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9166" PostTypeId="2" ParentId="9142" CreationDate="2019-09-18T04:21:40.040" Score="1" Body="&lt;p&gt;While you can't do what you're asking, you might be able to use a compromise. It turns out that all human skin tones have the same hue. They vary only in saturation and brightness. You can see this on the scopes that television engineers use to calibrate their signals. There's a line where skin tones should be if everything's set correctly. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could choose that hue and some low saturation and middle value in HSV space, then convert it to RGB and use that as the color you put in the ROI. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks like on most vectorscopes the skin tone line is about 15° past red towards yellow. According to &lt;a href=&quot;https://larryjordan.com/articles/color-correction-make-people-look-normal/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article on skin tone correction&lt;/a&gt; if the lighting is typical studio lighting, caucasian skin would usually be around 50-75% brightness, asian and hispanic skin around 35-55% brightness and african skin around 15-50% brightness. So setting your color to HSV = (15°, 25% saturation, 50% brightness) is RGB = (128, 104, 96). If you know your subjects will be lighter or darker, adjust accordingly. Note that these values change when in bright outdoor light or dim indoor light, or when there's light with a strong color cast falling on them. But again, this is a compromise.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-09-18T04:21:40.040" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9168" PostTypeId="1" CreationDate="2019-09-19T00:46:47.057" Score="2" ViewCount="77" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hXjgh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hXjgh.jpg&quot; alt=&quot;Composition of HSV&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a question about the saturation channel.&#xA;1.) So far I know, that saturation channel only give intensity to Hue channel, but I do not understand, how saturation channel can be dark and what is the saturation value to be in saturation channel dark?.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I am not mistaken the range of value channel is from 0 to 100. 0 is black and 100 is white.&#xA;so I am trying to use &lt;a href=&quot;http://colorizer.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;online HSV simulator&lt;/a&gt; to figure it out what color can be produced after mixing each channel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I still searching the value for the black and white color in saturation channel so I can correct answer for each color on each box (a-d).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And how saturation channel can be dark if, the value channel has a value of 100 (based on onlie HSV simulator, H = 0-360, V = 100, S = ? )?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h2&gt;sofar my answer is :&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;a. hell white without saturation.&#xA;b. dark gray with little saturation.&#xA;c. half gray.&#xA;d. dark black with low saturation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is there any exact value for black and white in saturation channel?.&lt;/p&gt;&#xA;" OwnerUserId="11208" LastEditorUserId="3003" LastEditDate="2019-09-19T01:05:12.277" LastActivityDate="2019-10-19T02:01:45.220" Title="Mixing HSV Channel" Tags="&lt;rendering&gt;&lt;color&gt;&lt;image&gt;&lt;color-separation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9169" PostTypeId="2" ParentId="9168" CreationDate="2019-09-19T01:03:00.223" Score="2" Body="&lt;p&gt;I think your answer is a little off. When the saturation is 0, the hue is basically undefined. It has some numerical value, but that value is ignored. Saturation of 0 means achromatic, or uncolored. So it can only be a shade of gray. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Saturation is unrelated to value in HSV. You can have all of the following:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;dark unsaturated colors (basically dark grays or colors close to dark grays)&lt;/li&gt;&#xA;&lt;li&gt;dark saturated colors (think of a deep red wine color, for example)&lt;/li&gt;&#xA;&lt;li&gt;bright unsaturated colors (bright grays, pastels have a a little bit of saturation)&lt;/li&gt;&#xA;&lt;li&gt;bright saturated colors (like the red of a stop sign)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Looking at your example, it looks like the S channel has only 2 values: 0 and 100%.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-09-19T01:03:00.223" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9172" PostTypeId="1" AcceptedAnswerId="9173" CreationDate="2019-09-21T02:12:32.900" Score="2" ViewCount="94" Body="&lt;p&gt;I'm working on a small ray tracing project in my free time and I'm currently implementing boolean operations for spheres.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code is setup to calculate the intersection points of each of the spheres with any given ray and spit out the correct points to be rendered to the screen based on the type of boolean operation being performed (Union, Difference or Intersection).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't been at it for too long, but so far I have the code for the Intersection running nicely:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;v3df&lt;/code&gt; and &lt;code&gt;v2df&lt;/code&gt; are 3d and 2d float vectors respectively.&lt;br&gt;&#xA;&lt;code&gt;s1t&lt;/code&gt; and &lt;code&gt;s2t&lt;/code&gt; are the intersection points for each of the spheres with a ray.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;if(s1t.x == 0 &amp;amp;&amp;amp; s1t.y == 0 || s2t.x == 0 &amp;amp;&amp;amp; s2t.y == 0)&#xA;    return v2df();&#xA;&#xA;if(min(s1t.x, s1t.y) &amp;gt; max(s2t.x, s2t.y) || min(s2t.x, s2t.y) &amp;gt; max(s1t.x, s1t.y))&#xA;    return v2df();&#xA;&#xA;std::vector&amp;lt;float&amp;gt; values = { s1t.x, s1t.y, s2t.x, s2t.y };&#xA;std::sort(values.begin(), values.end());&#xA;v2df res(values[2], values[1]);&#xA;return res;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This produces the following output with variable spheres:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/qDFud.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qDFud.png&quot; alt=&quot;intersection of two spheres&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I would like to implement the normals for said intersection, and my basic idea would be to take the normals of each of the corresponding spheres where their geometry shows, but I'm at a loss for how to implement this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;here's the method stub I would like to use:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;v3df GetNormal(v3df point) {&#xA;    return v3df();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10600" LastActivityDate="2019-09-21T03:41:32.510" Title="Calculate Normals of Boolean Operation for Ray Tracer" Tags="&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9173" PostTypeId="2" ParentId="9172" CreationDate="2019-09-21T03:41:32.510" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;My code is setup to calculate the intersection points of each of the spheres with any given ray and spit out the correct points to be rendered to the screen based on the type of boolean operation being performed (Union, Difference or Intersection).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Then you need to do the exact same thing with the normals. Indeed, you would typically do this operation with all of the appropriate parametric values for the various leaf surfaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, you need to take into account how the operations affect the meaning of the intersections. With positions, an intersection is used to determine if you're inside an object or outside of it. An OR operation (union) makes any intersection of the two objects considered &quot;inside&quot;, with &quot;outside&quot; only happening if you're outside of all of them. An AND operation (intersection) only makes the composite object &quot;inside&quot; if you're inside all of the AND'd objects.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A negation &lt;em&gt;reverses&lt;/em&gt; the meaning of inside and outside for the object. So an AND with a negation (difference) means that the only part that is inside of the composite object is the part of the first object which is not also inside of the second.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normals use the same rules as positions, with one exception. When used with a difference operation, if the ray enters the negated object (and thus is still outside of the composite), then enters the primary object (but is still outside of the composite because it's still inside of the negated one), and then leaves the negated object, that intersection represents a visible point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Except that the normal is &lt;em&gt;backwards&lt;/em&gt;, since you're using the &lt;em&gt;inside&lt;/em&gt; of the negative surface to define the surface of the composite object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you negate a surface, you invert the meaning of its normals. So when you do a difference operation, you have to negate the normals of any intersections with the negative surface.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-09-21T03:41:32.510" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9174" PostTypeId="1" AcceptedAnswerId="9281" CreationDate="2019-09-19T12:02:02.800" Score="0" ViewCount="99" Body="&lt;p&gt;Here is an example&lt;/p&gt;&#xA;&#xA;&lt;p&gt;dots representing coordinates of pixels&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SFr02.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SFr02.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;added more representative example&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4E1ez.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4E1ez.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;added real example&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Y6bJS.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y6bJS.jpg&quot; alt=&quot;added real example&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;added main problem&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P8Y5p.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P8Y5p.jpg&quot; alt=&quot;main problem&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11226" OwnerDisplayName="Oleg" LastEditorUserId="11226" LastEditDate="2019-09-23T14:55:29.897" LastActivityDate="2019-10-26T13:27:00.077" Title="Is there way for polygon decomposition by thickness?" Tags="&lt;image-processing&gt;" AnswerCount="2" CommentCount="21" ContentLicense="CC BY-SA 4.0" />
  <row Id="9175" PostTypeId="2" ParentId="9174" CreationDate="2019-09-19T17:07:20.047" Score="1" Body="&lt;p&gt;It is a bad idea to try to abuse clustering algorithms for this. In particular k-means will &lt;em&gt;not&lt;/em&gt; cut vertically, nor consider rectangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you need to do is a trivial axis-aligned corner detection.it does not get much simpler than that!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You begin on the left, and whenever the location of the topmost pixel changes, a rectangle is complete.&lt;/p&gt;&#xA;" OwnerDisplayName="Anony-Mousse" LastActivityDate="2019-09-19T17:07:20.047" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9176" PostTypeId="1" CreationDate="2019-09-22T16:00:52.893" Score="1" ViewCount="26" Body="&lt;p&gt;I noticed that a common metrics for image quality assessment (Monte Carlo path tracing) is MSE between the generated image and a reference one. My question is: why isn't the standard deviation ever mentioned? Isn't it necessary? Shouldn't we generate n number of samples, compare them all with the reference, and then report the average and the standard deviation?&#xA;This is how I have always seen results in technical papers, except for papers in Graphics. I am wondering if the fact that path tracing is unbiased plays a role in the missing std dev. &#xA;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-09-22T16:00:52.893" Title="Report standard deviation in Rendering results" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9177" PostTypeId="1" CreationDate="2019-09-22T23:33:18.670" Score="1" ViewCount="23" Body="&lt;p&gt;When binding an attribute index using glVertexAttribPointer, what happens when a later bound program does not contain an attribute at said index?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is the behaviour undefined, or is the attribute ignored altogether?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have searched the docs quite extensively, and have not been able to find much info about the link between programs and dynamic attribute bindings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks all.&lt;/p&gt;&#xA;" OwnerUserId="11223" LastEditorUserId="209" LastEditDate="2019-09-23T11:22:21.980" LastActivityDate="2019-09-23T11:22:21.980" Title="Confusion about glVertexAttribPointer and non-active attributes" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;vertex-buffer-object&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9178" PostTypeId="1" CreationDate="2019-09-22T23:46:12.887" Score="2" ViewCount="149" Body="&lt;p&gt;I would like to imitate the orthographic projection that Matlab uses by default:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://uk.mathworks.com/help/matlab/creating_plots/understanding-view-projections.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Matlab View Projections&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://uk.mathworks.com/help/matlab/ref/camproj.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Matlab camproj&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems similar to the &quot;Trimetric&quot; projection described here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia on Orthographic Projection&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;see the picture here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Orthographic_projection#/media/File:Graphical_projection_comparison.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia picture - Comparison of projections&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but I don't know whether they are definitely the same. Does anyone know the exact details of the Matlab projection ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you !&lt;/p&gt;&#xA;" OwnerUserId="11224" LastActivityDate="2021-05-02T13:07:35.677" Title="What exactly is the orthographic projection used by Matlab" Tags="&lt;projections&gt;&lt;matlab&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9181" PostTypeId="1" AcceptedAnswerId="9184" CreationDate="2019-09-23T14:48:25.483" Score="2" ViewCount="1670" Body="&lt;p&gt;I am porting some code from Metal to OpenGL since we want to run our app on Windows too. Xcode is my preferred IDE, but the newer versions of Xcode do not support any OpenGL debugging.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Question: What do people usually use as a debugger for OpenGL? Eg: Frame capture on Metal is great and allows you to do shader debugging etc and nicely view the call hierarchy. Is there any thing similar for OpenGL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If there are some good solutions on Windows, i can consider switching to Visual Studio.  &lt;/p&gt;&#xA;" OwnerUserId="11155" LastActivityDate="2019-10-27T05:01:00.117" Title="Debugging tools for OpenGL on macOS" Tags="&lt;opengl&gt;&lt;metal&gt;&lt;debugging&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9182" PostTypeId="1" AcceptedAnswerId="9183" CreationDate="2019-09-24T05:47:39.253" Score="2" ViewCount="73" Body="&lt;p&gt;Looking at various assets (models / textures / scenes) available online, I have noticed a trend that conflicts with my assumptions. Many of the normal maps contain texels whose vector length deviates from unit length by a significant amount.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, this image from Wikimedia Commons (&lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Normal_map_example_-_Map.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://commons.wikimedia.org/wiki/File:Normal_map_example_-_Map.png&lt;/a&gt;) contains many vectors (hundreds) that are around 15%+ shorter than unit length, and it is hardly an outlier (in fact, it would seem to have been chosen as an exemplary basic example). In other cases, I have found normal maps where the z component is uniformly set to 1.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the specification side of things, I note that GLTF 2.0 merely states (&lt;a href=&quot;https://github.com/KhronosGroup/glTF/issues/993&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KhronosGroup/glTF/issues/993&lt;/a&gt;) that a shader implementation should renormalize after sampling, but that it is not required for the maps themselves to have vectors of unit length.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems to me that this poses an accuracy issue. Certainly if normals are sampled using bilinear filtering, the result will generally be shorter than the texels used to generate it, and thus renormalization will be necessary. However, if this is the argument as to why it is not necessary to store as unit length vectors, then it seems short-sighted to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When sampling with e.g. bilinear filtering, if the texels are not all of the same length, the resulting normal will be biased in direction towards the samples with greater length. Therefore, even if you renormalize after sampling, you will not be able to recover the accuracy lost by not starting with unit normals in the first place.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I would like to know why such low priority is seemingly placed on generating normal map textures that contain only unit-length normals. Is it just because the loss in accuracy isn't deemed to be significant enough subjectively/perceptually, or is there something else completely here that I am missing?&lt;/p&gt;&#xA;" OwnerUserId="11232" LastActivityDate="2019-09-24T06:55:07.817" Title="Normal Map Storage (Not Unit Length)" Tags="&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9183" PostTypeId="2" ParentId="9182" CreationDate="2019-09-24T06:55:07.817" Score="4" Body="&lt;p&gt;Maps with z = 1.0 everywhere are likely &lt;a href=&quot;http://diaryofagraphicsprogrammer.blogspot.com/2009/01/partial-derivative-normal-maps.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;partial derivative maps&lt;/a&gt;. This is a variant on normal maps that's become fairly widespread. There are a few reasons to prefer it, but probably the most important is it lets you store the map as just two channels (red and green), which allows using better quality BC5 compression, while being cheap to decode in the shader. The normals in such a map are of necessity not all unit length, and as you pointed out that will affect interpolation and blending slightly, but this is generally deemed an acceptable trade-off.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if it's purporting to be a traditional old-school normal map and it has pixels that are significantly off from unit length, that sounds odd and probably unintended. I'm not sure why that would have happened in the particular Wikimedia .png example you linked. However, non-unit-length normals could generally be introduced by doing filtering/blending/compositing operations on the image without renormalizing after (for example, if a normal map was rendered at a higher resolution and then downsampled using a standard image resampling algorithm). They could also be introduced by lossy compression.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-09-24T06:55:07.817" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9184" PostTypeId="2" ParentId="9181" CreationDate="2019-09-25T01:22:30.397" Score="4" Body="&lt;p&gt;There's nothing like frame capture for OpenGL on macOS, unfortunately. But there are 2 other tools that are useful for GL debugging: OpenGL Profiler and OpenGL Driver Monitor. You can read about them &lt;a href=&quot;https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_performance/opengl_performance.html#//apple_ref/doc/uid/TP40001987-CH213-SW1&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. (Warning the images in the article are &lt;em&gt;really&lt;/em&gt; old. They look like normal apps today without all the brushed metal, etc.) To download them, you need to log in to your developer account on developer.apple.com, click on &quot;Downloads&quot; on the left side. On the downloads page in the upper right is a tiny &quot;more&quot; link. If you click on that, you'll get the search tool. Enter &quot;OpenGL Profiler&quot; for your search and you'll be presented with a number of packages for different versions of Xcode. Choose the one that matches whichever version of Xcode you have. It's in the &quot;Graphics Tools&quot; section of the download.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL Profiler can show you the resources currently in use by a program. You can set breakpoints on any OpenGL call and when it breaks you can see all textures, shaders, FBOs, etc. and see what their contents are as well as all OpenGL state.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL Driver Monitor will graph over time how many textures are in use, or how much texture memory, etc. It can tell you the frequency of page-ons and page-offs for the GPU and other useful statistics.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2019-09-27T04:22:48.763" LastActivityDate="2019-09-27T04:22:48.763" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9185" PostTypeId="1" CreationDate="2019-09-25T11:30:11.570" Score="0" ViewCount="99" Body="&lt;p&gt;I' trying to write a monte carlo ray tracer in julia, but my main function returns stack overflow error. Below is my main function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function trace(ray::Ray, surfaces::Array{Any, 1}, depth::Int64, maxDepth::Int64)&#xA;material, t = findIntersection(ray, surfaces, Inf)&#xA;if typeof(material) == Empty&#xA;    Vec3(0,0,0)&#xA;end&#xA;if depth &amp;gt; maxDepth&#xA;    Vec3(0,0,0)&#xA;end&#xA;if material.isLight == true&#xA;    material.emittance&#xA;end&#xA;normal = material.normal&#xA;ρ = material.reflectance&#xA;BRDF = ρ/3.1415&#xA;R = randHemi(normal)&#xA;cosθ = dot(R,normal)&#xA;newRay = Ray(ray.s + t*ray.d, R)&#xA;In = trace(newRay, surfaces, depth+1, maxDepth)&#xA;2.0*3.1415*BRDF*In&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But when I run it, I receive this error:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;StackOverflowError:&#xA;&#xA;Stacktrace:&#xA; [1] findIntersection(::Ray, ::Array{Any,1}, ::Float64) at .\In[31]:10&#xA; [2] trace(::Ray, ::Array{Any,1}, ::Int64, ::Int64) at .\In[33]:2&#xA; [3] trace(::Ray, ::Array{Any,1}, ::Int64, ::Int64) at .\In[33]:18 (repeats &#xA;14493 times)&#xA; [4] top-level scope at In[35]:1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is my intersection function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function findIntersection(ray::Ray, surfaces::Array{Any, 1}, tmin::Float64)&#xA;hitSurface = Empty(Vec3(0,0,0), Vec3(0,0,0), Vec3(0,0,0), false)&#xA;for surface in surfaces&#xA;    t = intersect(surface, ray)&#xA;    if t &amp;lt; tmin&#xA;        hitSurface = surface&#xA;        tmin = t&#xA;    end&#xA;end&#xA;return hitSurface, tmin       &#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11237" LastActivityDate="2019-09-25T11:30:11.570" Title="Why does my julia ray tracer return stack overflow error?" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9186" PostTypeId="1" AcceptedAnswerId="9188" CreationDate="2019-09-25T17:11:31.420" Score="2" ViewCount="280" Body="&lt;p&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Intel740&quot; rel=&quot;nofollow noreferrer&quot;&gt;Intel 740&lt;/a&gt; AGP graphics card read textures directly from system RAM, using VRAM exclusively for depth buffers and the framebuffer. This has the effect of saving video RAM, and it could be implemented with AGP transfer speeds far lower than PCIe transfer speeds of today.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is such a method of zero-copy texture loading possible/optimal on modern &lt;strong&gt;discrete&lt;/strong&gt; graphics hardware? Is there a specific hardware feature that was present on the i740 requisite for this technique that is not present on modern graphics cards? Furthermore, could zero-copy texture access functionality be exposed by using mapped buffers in OpenGL?&lt;/p&gt;&#xA;" OwnerUserId="10051" LastEditorUserId="2654" LastEditDate="2019-09-25T20:45:44.513" LastActivityDate="2019-09-25T21:06:05.637" Title="Zero-copy texture reading from CPU memory" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;memory&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9188" PostTypeId="2" ParentId="9186" CreationDate="2019-09-25T21:06:05.637" Score="3" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is such a method of zero-copy texture loading possible/optimal on modern discrete graphics hardware?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You say that as though it were optimal &lt;em&gt;back then&lt;/em&gt;. The Intel 740 was not exactly warmly embraced by the market, as noted by the Wikipedia article in question:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The AGP Texture concept soon proved to be a tremendous error in design, because the card had to constantly access the textures over a channel that was upwards of eight times slower than RAM placed on the graphics card itself.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The disparity between available memory bandwidth/performance and available compute resources has only &lt;em&gt;increased&lt;/em&gt; in the last 20 years. So, will it be &quot;optimal&quot; to have a discrete GPU read from main memory?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;No.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could it be &quot;possible&quot;? Not in terms of marketability. Even $50 and below discrete GPUs carry their own on-board RAM. Anything much slower/smaller than that isn't worthwhile, because pretty much everyone already has Intel or AMD's on-die GPUs for when performance isn't of importance. If you have a discrete board, it will always be better to put some RAM on the board with its own bus than to have the board try to read most of its data directly from main memory.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Furthermore, could zero-copy texture access functionality be exposed by using mapped buffers in OpenGL?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No. Mapped buffers would be &lt;em&gt;buffers&lt;/em&gt;, not textures. They're different kinds of storage objects with (hypothetically) distinct allocations behind them. PBO is a means of asynchronously transferring data from a buffer to a texture. That is a &lt;em&gt;transfer&lt;/em&gt; of data, not an adoption of a memory allocation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Intel has an &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/INTEL/INTEL_map_texture.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;extension for mapping a texture's storage&lt;/a&gt;, but that requires that the texture be in a linear format. It's not widely supported, and likely never will be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan provides for the &lt;em&gt;possibility&lt;/em&gt; of something similar, but using linear texture as sources in sampler read operations from a shader is not required to be supported. You'd have to ask each implementation whether it allows it and in which formats, and for which usages are allowed.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-09-25T21:06:05.637" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9189" PostTypeId="1" CreationDate="2019-09-26T03:20:06.997" Score="1" ViewCount="202" Body="&lt;p&gt;As we know in C/C++ there is &quot;graphics.h&quot; header file with the help of which we can do graphics programs in C. &#xA;There is a function &lt;strong&gt;pieslice&lt;/strong&gt; in that header file,its syntax is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;graphics.h&amp;gt;&#xA;&#xA;void pieslice(int x, int y, int stangle, int endangle, int radius);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;[x,y are the center of the circle,stangle and endangle are the starting and end angles respectively]&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can we make a pieslice in C/C++ without using this in-built function.Please help. Tried making it with the help of the lines and arc function of the &#xA;&lt;code&gt;graphics.h&lt;/code&gt; but i am still not able to figure out how to connect the lines with the arc. &#xA;Thank You in advance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code so far:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;&#xA;#include&amp;lt;graphics.h&amp;gt;&#xA;#include&amp;lt;math.h&amp;gt;&#xA;&#xA;int main()&#xA;{&#xA;    int gd=DETECT,gm;&#xA;    initgraph(&amp;amp;gd,&amp;amp;gm,NULL);&#xA;    int xc,yc,r,st_angle,ed_angle,StartX,StartY;&#xA;    printf(&quot;Enter the centers of pieslice:\n&quot;);&#xA;    scanf(&quot;%d %d&quot;,&amp;amp;xc,&amp;amp;yc);&#xA;    printf(&quot;Enter the radius:\n&quot;);&#xA;    scanf(&quot;%d&quot;,&amp;amp;r);&#xA;    printf(&quot;Enter the starting angle:\n&quot;);&#xA;    scanf(&quot;%d&quot;,&amp;amp;st_angle);&#xA;    printf(&quot;Enter the end angle:\n&quot;);&#xA;    scanf(&quot;%d&quot;,&amp;amp;ed_angle);&#xA;&#xA;    double startRadians = (double)st_angle * M_PI /180.0;&#xA;    double endRadians = (double)ed_angle * M_PI /180.0;&#xA;&#xA;    for(int k=0; k&amp;lt;startRadians;k++)&#xA;    {   &#xA;        startX = xc+ cos(startRadians) * r;&#xA;        startY = yc+ sin(startRadians) * r;&#xA;    }&#xA;    for(int l=o; l&amp;lt;endRadians; l++)&#xA;    {&#xA;        endX = xc+ cos(endRadians) * r;&#xA;        endY = yc+ sin(endRadians) * r;&#xA;    }&#xA;&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11239" LastEditorUserId="11239" LastEditDate="2019-10-01T05:00:04.133" LastActivityDate="2021-02-22T05:05:10.807" Title="Program to make &quot;Pieslice&quot; without using library function?" Tags="&lt;c++&gt;&lt;vector-graphics&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9190" PostTypeId="1" CreationDate="2019-09-26T12:35:23.023" Score="1" ViewCount="24" Body="&lt;p&gt;My first issue is getting a set of planes and a set of points as input, an find the projection of the those points on the nearest plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That was pretty easy, where i just calculate the normal of the plan and do some linear algebra to find the best plane to project  onto.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now i do not have just normal planes, i have a set of freeform surfaces, like &lt;span class=&quot;math-container&quot;&gt;$\textit{Bspline}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\textit{Nurbs}$&lt;/span&gt; and i have to project my given points on those surfaces. i Struggle to find the  minimum distance between the point and the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea how to do that?&lt;/p&gt;&#xA;" OwnerUserId="11241" LastActivityDate="2019-09-26T12:35:23.023" Title="Projecting a point on a Freefrom surface" Tags="&lt;c++&gt;&lt;projections&gt;&lt;nurbs&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9191" PostTypeId="1" CreationDate="2019-09-26T17:05:51.743" Score="1" ViewCount="95" Body="&lt;p&gt;I've been reading up on images with indexed color, and while most indexed image formats are limited to 256 colors, there are apparently image formats that support larger palettes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://en.wikipedia.org/wiki/Indexed_color&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Indexed color images with palette sizes beyond 256 entries are rare&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I did some extra searching, but I can't seem to find any clear list or mention of specific image formats that support larger color palettes.&lt;/p&gt;&#xA;" OwnerUserId="11243" LastActivityDate="2019-09-26T17:05:51.743" Title="What image formats support indexed color palettes with more than 256 colors?" Tags="&lt;color&gt;&lt;image&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9192" PostTypeId="1" CreationDate="2019-09-27T01:40:05.277" Score="1" ViewCount="99" Body="&lt;p&gt;A spherical camera is pretty easy to define.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We have an anchor point C the camera always looks at and a relative position P where the camera is, which can be expressed in spherical coordinates, centered around the point C.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this type of camera the the up direction is always the up vector of the world.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The implementation isn't terribly complex. given the parameters, we will calucate the position of the camera by doing:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;rotation around the x axis by phi, rotation around the y axis by theta, multiply by the radius then translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And then we calculate the orientation of the camera with lookAt, centering the view at the anchor point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The trackball camera is different however, it allows for orientations of the view in which the camera up isn't necessarily 0,1,0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, in a spherical camera, the deltas around the x axis are mapped to one angle and the deltas around the y axis to the other. I am not 100% sure on how to represent nor map mouse movement to camera orientation in the case of a trackball.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-09-27T01:40:05.277" Title="Difference between a spherical camera and a trackball camera" Tags="&lt;mesh&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9193" PostTypeId="2" ParentId="9189" CreationDate="2019-09-27T04:19:41.063" Score="0" Body="&lt;p&gt;You can use the sine and cosine functions to do this. Normally they start on the x axis and rotate counter-clockwise. The start point can be found by calculating:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;startX = x + cos(startRadians) * radius;&#xA;startY = y + sin(startRadians) * radius;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Likewise the ending coordinates are:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;endX = x + cos(endRadians) * radius;&#xA;endY = y + sin(endRadians) * radius;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that &lt;code&gt;sin()&lt;/code&gt; and &lt;code&gt;cos()&lt;/code&gt; take their parameters in radians. Given that &lt;code&gt;stangle&lt;/code&gt; and &lt;code&gt;endangle&lt;/code&gt; are integers, I'm guessing they're probably in degrees so you'll need to convert them by doing something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;double startRadians = (double)stangle * M_PI / 180.0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to draw the entire pie wedge, you'll need to iterate from the start angle to the end angle and calculate every &lt;code&gt;n&lt;/code&gt; degrees along the curve.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-09-27T04:19:41.063" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9194" PostTypeId="1" AcceptedAnswerId="9195" CreationDate="2019-09-27T14:40:45.957" Score="1" ViewCount="108" Body="&lt;p&gt;I am solving an image segmentation problem. To increase the accuracy of the model, I came across the following preprocessing step-&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;First, the set of pixels of the exterior border of the ROI is de-&#xA;termined, i.e., pixels that are outside the ROI and are neighbors&#xA;(using four-neighborhood) to pixels inside it. Then, each pixel value&#xA;of this set is replaced with the mean value of its neighbors (this&#xA;time using eight-neighborhood) inside the ROI. Finally, the ROI is&#xA;expanded by inclusion of this altered set of pixels. This process is&#xA;repeated and can be seen as artificially increasing the ROI.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The image after applying the following algorithm is below-&#xA;&lt;a href=&quot;https://i.stack.imgur.com/jgBZe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jgBZe.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Can anyone please help me how to approach this problem, I am pretty much clue-less how to do it, how to detect the boundary of the image.My image is of the following type-&#xA;&lt;a href=&quot;https://i.stack.imgur.com/sbVhg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sbVhg.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Any help in solving this kind of problem is highly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="11114" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2019-10-01T01:19:02.713" Title="Artificially increase the region of interest of an image" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9195" PostTypeId="2" ParentId="9194" CreationDate="2019-09-28T02:39:55.920" Score="1" Body="&lt;p&gt;It looks like your image will always have the same black area due to the mechanism used to take the picture. If that's the case then you don't need to detect the edges. Instead, you can create a static mask ahead of time. The mask can be a single channel image that's white where the eye image is and black elsewhere. You can use that 1 channel mask as the alpha mask for the RGB image you have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the image can move around, it looks to me that you could threshold the red channel and say any red value under 0.1, say, is outside of the eye. Another possibility is just let the user select a circular region for the big circle, and then let them select a smaller one for the bump.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To expand the ROI once you've got the mask, you can go pixel by pixel and if the mask is black, follow the vector from the current pixel towards the center of the image until you hit a non-black pixel. When you hit one, just copy that pixel to the one you started with. Do that with each pixel that's not in the eye portion of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: Given that the mask is static there's an even easier way. In &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/9196/how-to-create-static-alpha-masks-of-an-image&quot;&gt;your other question&lt;/a&gt; I pointed out that the center of the larger circle was at approximately (279, 283.5) and its radius was approximately 265. So what you could do is simply iterate over all the pixels in the image and if they're farther than 265 pixels away from the center, replace them with the pixel that is 265 pixels away from the center in the same direction. Something like this untested pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float centerX = 279;&#xA;float centerY = 283.5;&#xA;float radius = 265;&#xA;for (int row = 0; row &amp;lt; MAX_ROWS; row++)&#xA;{&#xA;    for (int col = 0; col &amp;lt; MAX_COLS; col++)&#xA;    {&#xA;        float deltaX = col - centerX;&#xA;        float deltaY = row - centerY;&#xA;        float dist = sqrt(deltaX * deltaX + deltaY * deltaY);&#xA;        if (dist &amp;gt; radius)&#xA;        {&#xA;            float dirX = deltaX / dist;&#xA;            float dirY = delatY / dist;&#xA;            float edgeX = centerX + radius * dirX;&#xA;            float edgeY = centerY + radius * dirY;&#xA;            SetPixel(col, row, GetPixel(edgeX, edgeY));&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note that the smaller circle presents another issue. You can test whether a given pixel is in the big circle as above, and if not, then see what the distance to the smaller circle is. If that distance is smaller than the distance to the larger circle, then get the pixel from the smaller circle rather than the larger one.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastEditorUserId="3003" LastEditDate="2019-10-01T01:19:02.713" LastActivityDate="2019-10-01T01:19:02.713" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9196" PostTypeId="1" AcceptedAnswerId="9197" CreationDate="2019-09-29T12:39:37.387" Score="1" ViewCount="68" Body="&lt;p&gt;I have an image of following type-&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ayESL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ayESL.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to create mask of the following type where the inside area is white and rest of it is black. How to do it?&#xA;&lt;a href=&quot;https://i.stack.imgur.com/NzDB9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NzDB9.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11114" LastActivityDate="2019-09-29T20:33:07.340" Title="How to create static alpha masks of an image" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9197" PostTypeId="2" ParentId="9196" CreationDate="2019-09-29T20:33:07.340" Score="1" Body="&lt;p&gt;You can either use a threshold, or, since you know the location and size of the 2 circles, simply generate one programatically. In this case, you have a circle that's centered at (279, 283.5) and has a radius of 265. (I haven't calculated the center and radius of the smaller circle, but you should be able to do that fairly easily by looking at the image in any image editor that shows you mouse coordinates.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have the smaller circle radius, for each pixel in the mask find the distance to the large circle center and if it's less than the large radius, color it white. Otherwise take the distance to the smaller circle and if it's less than the smaller radius, color it white. Otherwise, color it black.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-09-29T20:33:07.340" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9198" PostTypeId="2" ParentId="9178" CreationDate="2019-09-29T20:38:14.647" Score="0" Body="&lt;p&gt;All of the above. If you look on matlabs page a little further down, it becomes apparent that matlab initializes a canvas (the screen), then looks for each pixel what is directly behind that screen. This gets rid of perspective. When you set the camera angle to 45 degrees down and 45 degrees left/right, you will get an implicit isometric projection. So really the &quot;projection&quot; just depends on your camera angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sidenote: if you would want to keep a 3d perspective, you would need to draw the ray from the camera origin to the position on the canvas. That gives the ray the direction it needs to create perspective.&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-09-29T20:38:14.647" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9199" PostTypeId="1" CreationDate="2019-09-29T21:48:29.800" Score="0" ViewCount="690" Body="&lt;p&gt;Let's suppose we have an object consisting of only 3d points, and triangle faces that each take a subset of these 3d points. How can I interpolate the normal vectors to get that Phong smooth shading? The actual algorithm seems impossible to find yet everybody is doing it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is one post on here, but I still have no idea how to implement it: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5097/normal-interpolation-for-phong-shading&quot;&gt;Normal Interpolation for Phong shading&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, it seems wrong to me that this supposed formula only takes in account two normals. What if you have a triangle surrounded by 3 other triangles? Then how do you blend the normals?&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2021-02-22T02:02:30.333" Title="What is the algorithm used for phong shading normal interpolation?" Tags="&lt;shading&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9200" PostTypeId="2" ParentId="9199" CreationDate="2019-09-30T02:06:06.230" Score="0" Body="&lt;p&gt;EDIT: I misunderstood your question, so please disregard this answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Phong shading model assumes a surface normal &lt;span class=&quot;math-container&quot;&gt;$\mathbf{n}$&lt;/span&gt; at the shading point &lt;span class=&quot;math-container&quot;&gt;$\mathbf{x}$&lt;/span&gt; but it is independent of its &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5486/whats-the-difference-between-geometric-surface-normal-and-shading-surface-norma&quot;&gt;type&lt;/a&gt;, so either the shading normal or the geometric normal will work. Moreover, this reflectance model requires an incoming and outgoing directions. In that sense, you can't just &quot;interpolate the normals&quot; to get the desired effect since you need to take into account the positions of the camera and the light, as well as the roughness parameters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The (normalized) Phong BRDF is a sum of a diffuse and specular term:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f_r(\mathbf{x},\omega_i,\omega_o) = \frac{\rho_d}{\pi} + \rho_s \frac{n+2}{2\pi}\max(0,\cos^n\alpha),&#xA;$$&lt;/span&gt;&#xA;where&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\rho_d$&lt;/span&gt; is the &lt;em&gt;diffuse albedo&lt;/em&gt;, i.e. the fraction of the incoming energy that is reflected diffusely,&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\rho_s$&lt;/span&gt; is the &lt;em&gt;specular albedo&lt;/em&gt;, i.e. the fraction of the incoming energy that is reflected specularly,&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is the &lt;em&gt;Phong exponent&lt;/em&gt;; higher values yield more mirror-like specular reflection, and&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\alpha$&lt;/span&gt; is the &lt;em&gt;angle&lt;/em&gt; between the perfect specular reflection direction &lt;span class=&quot;math-container&quot;&gt;$\omega_r$&lt;/span&gt; and the outgoing direction &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You can compute &lt;span class=&quot;math-container&quot;&gt;$\omega_r$&lt;/span&gt; from the surface normal &lt;span class=&quot;math-container&quot;&gt;$\mathbf{n}$&lt;/span&gt; and the lighting direction &lt;span class=&quot;math-container&quot;&gt;$\omega_i$&lt;/span&gt;, which is just&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\omega_r = 2\mathbf{n}(\mathbf{n}\cdot\omega_i) - \omega_i.&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Typically you pick the albedos such that &lt;span class=&quot;math-container&quot;&gt;$\rho_d + \rho_s \leqslant 1$&lt;/span&gt; to conserve energy.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastEditorUserId="6588" LastEditDate="2019-09-30T22:52:14.493" LastActivityDate="2019-09-30T22:52:14.493" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9201" PostTypeId="1" AcceptedAnswerId="9203" CreationDate="2019-09-30T15:56:03.473" Score="2" ViewCount="85" Body="&lt;p&gt;I currently can not solve a ray-quad intersection with a quad that bends, because it is impossible to solve (because really a quad can't/shouldn't bend).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sadly, often times, models with quadrilaterals have impossible surfaces: some quads &quot;bend&quot; rather than be a perfect plane/polygon. You could break the quads up into triangles, but there are two ways to do that. And even then, what do you do with the normals? Keep the quad normal onto the two resulting triangles or just recalculate the normals? What is the industry standard for this process?&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-11-01T10:01:30.347" Title="How to handle quads?" Tags="&lt;model&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9203" PostTypeId="2" ParentId="9201" CreationDate="2019-10-01T08:27:09.497" Score="2" Body="&lt;p&gt;It sounds like you want to know how to ray trace &lt;strong&gt;&lt;em&gt;a bilinear surface patch&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A quick search &lt;a href=&quot;https://www.cs.utah.edu/~ramsey/bp/&quot; rel=&quot;nofollow noreferrer&quot;&gt;turned up this page&lt;/a&gt; by Ramsey, Potter &amp;amp; Hansen, which includes a &lt;a href=&quot;https://www.cs.utah.edu/~ramsey/bp/ramseybilinear.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; and, probably better still, &lt;em&gt;source code&lt;/em&gt;!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you just want a &quot;cheap and cheerful&quot; &lt;strike&gt;hack&lt;/strike&gt; approach, you could try replacing the quad with &lt;strong&gt;4&lt;/strong&gt; triangles. That is, by a new vertex at the 'centre' (i.e. computing the average of the corners) and joining each edge to that new vertex. This is generally produces a better looking, and order-independent result than just using a pair of triangles.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-10-02T09:55:05.433" LastActivityDate="2019-10-02T09:55:05.433" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9204" PostTypeId="1" CreationDate="2019-10-01T20:04:48.853" Score="2" ViewCount="79" Body="&lt;p&gt;Given the &lt;strong&gt;Point A&lt;/strong&gt; with the coordinates &lt;code&gt;gl_FragCoord.xy&lt;/code&gt;, I have to find the distance to the &lt;strong&gt;Center&lt;/strong&gt; of the cube face to which it belongs in screen coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically what I need is the formula to convert the &lt;strong&gt;Center&lt;/strong&gt; of every face of the cube in screen coordinates, in order to compare it with &lt;code&gt;gl_FragCoord&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This the fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;&#xA;uniform vec2 u_resolution;&#xA;&#xA;varying vec2 v_uv;&#xA;&#xA;void main() {&#xA;  gl_FragColor = vec4(v_uv.x, v_uv.y, 0.0, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This the vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision mediump float;&#xA;&#xA;attribute vec3 a_position;&#xA;attribute vec2 a_uv;&#xA;&#xA;uniform mat4 u_view;&#xA;uniform mat4 u_projection;&#xA;&#xA;varying vec2 v_uv;&#xA;&#xA;void main() {&#xA;  v_uv = a_uv;&#xA;&#xA;  gl_Position = u_projection * u_view * vec4(a_position, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NMCNY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NMCNY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11255" LastEditorUserId="2654" LastEditDate="2019-10-01T20:35:27.157" LastActivityDate="2019-10-01T20:35:27.157" Title="Calculate the distance between two 3d points in screen coordinates" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;webgl&gt;&lt;fragment-shader&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9205" PostTypeId="1" CreationDate="2019-10-01T22:34:12.757" Score="3" ViewCount="79" Body="&lt;p&gt;In &lt;a href=&quot;https://en.wikipedia.org/wiki/Phong_shading&quot; rel=&quot;nofollow noreferrer&quot;&gt;Phong shading&lt;/a&gt; model (and other shading models as well), the light color is multiplied together with the surface color component-wise. I want to know the justification for this. Is this some what related to the physics of light?&lt;/p&gt;&#xA;" OwnerUserId="11256" LastActivityDate="2019-10-02T10:20:59.457" Title="What's the justification of multiplying colors together?" Tags="&lt;shading&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9206" PostTypeId="2" ParentId="9205" CreationDate="2019-10-02T08:52:19.420" Score="5" Body="&lt;p&gt;When you multiply colors together the surface color acts as a filter. Remember that colors are scaled from 0 to 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That way with white incoming light a green object will remain looking green.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This does bring a few issues because physical light isn't as orthogonal (where the 3 primary colors are actually overlapping frequency response functions) but for the vast majority of cases you can tweak the values enough for it to stay looking realistic.&lt;/p&gt;&#xA;" OwnerUserId="137" LastEditorUserId="137" LastEditDate="2019-10-02T10:20:59.457" LastActivityDate="2019-10-02T10:20:59.457" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9207" PostTypeId="1" CreationDate="2019-10-02T20:34:00.397" Score="3" ViewCount="159" Body="&lt;p&gt;I have a set of unordered points that I'm getting from an image attached. I'd like to simply fit a parametrized curve such as a catmull-rom curve to with n control points (n = 4 to 10, and can be assumed to be known). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've explored ways of doing this and it seems there doesn't seem to be some library function that simply does this. I explore b-spline fitting (as I read that it's possible to convert b-spline to catmull-rom afterwards) with scipy that simply seems to unable to fit this properly.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import scipy.interpolate as interpolate&#xA;tck, u = interpolate.splprep([x, y], s=6)&#xA;&#xA;N = 100&#xA;xmin, xmax = 0, 1.01&#xA;unew = np.linspace(xmin, xmax, N)&#xA;spline = interpolate.splev(unew, tck)&#xA;&#xA;plt.plot(x, y, 'bo', label='Original points')&#xA;plt.plot(spline[0], spline[1], 'r', label='BSpline')&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm now thinking of doing a robust regression approach now &lt;a href=&quot;https://scipy-cookbook.readthedocs.io/items/robust_regression.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;(https://scipy-cookbook.readthedocs.io/items/robust_regression.html&lt;/a&gt;). But, I'm lost on how to convert my set of [x, y] points to a parametric formulation for catmull-rom spline to write the loss function needed for least squares fit. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated with a relevant code sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/9Qc1y.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9Qc1y.png&quot; alt=&quot;as&quot;&gt;&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Original:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/j3hxf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j3hxf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9562" LastActivityDate="2019-12-08T14:01:25.367" Title="Non least squares formulation to fit catmull rom spline" Tags="&lt;curve&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9208" PostTypeId="1" CreationDate="2019-10-03T00:38:51.523" Score="0" ViewCount="101" Body="&lt;p&gt;I was trying to determine if an object (sphere) is inside a view frustum. My strategy was first to get the view matrix:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::lookAt(cameraPosition, lookAtPosition, cameraUp);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where &lt;code&gt;cameraPosition&lt;/code&gt; is the position of the camera, &lt;code&gt;lookAtPosition&lt;/code&gt; is calculate by &lt;code&gt;cameraPosition + cameraDirection&lt;/code&gt; and &lt;code&gt;cameraUp&lt;/code&gt; is pretty much self-explanatory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After obtaining the view matrix, I calculate the 8 vertices of the frustum in the camera view, then multiply the inverse of the view matrix by each point to get the coordinate of them in the world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using these 8 points in the world space, I can construct the 6 planes by using cross products (so their normals will point inward). Then I take the dot product of the object vector (I get the vector by subtracting the object position with an arbitrary point on that plane) with the normal vector of each plane, if it is positive for all 6, I know it's inside the frustum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my questions are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is the camera view is always set at (0,0,0) and looking at the positive z direction?&lt;/li&gt;&#xA;&lt;li&gt;The view matrix transform the world view into the camera view, if I use the inverse of it to transform the camera view to the world view, is it correct?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My frustum is opposite with my &lt;code&gt;cameraDirection&lt;/code&gt; which causes nothing to be seen on the screen (but it still drawing stuff in the back of my camera).&lt;/p&gt;&#xA;" OwnerUserId="11259" LastActivityDate="2019-10-03T20:22:01.893" Title="About view matrix and frustum culling" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9209" PostTypeId="2" ParentId="9208" CreationDate="2019-10-03T20:22:01.893" Score="1" Body="&lt;p&gt;It is  common that the camera is pointing towards negative Z, in order to satisfy right hand rule. So you need to know the convention.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for theinverse matrix of the camera matrix. Sort of yes. You can do it. However the camera matrix is a homogeneous space. While generally our other matrixes are affine spaces. If you take care of the distinction and do the proper camera divide, if tge camera needs one. Then yes you could do that.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2019-10-03T20:22:01.893" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9210" PostTypeId="1" CreationDate="2019-10-03T20:44:14.147" Score="2" ViewCount="219" Body="&lt;p&gt;I am currently implementing the GGX specular BRDF in a DXR raytracer using the importance sampling method describe by &lt;a href=&quot;http://jcgt.org/published/0007/04/01/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Heitz&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am sampling the VNDF with:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//https://hal.archives-ouvertes.fr/hal-01509746/document&#xA;inline float3 VNDF_GGX(in float3 wo, float roughness2, float rand1, float rand2)&#xA;{&#xA;    //Strecht view vector&#xA;    float3 view = normalize(float3(wo.x * roughness2, wo.y, wo.z * roughness2));&#xA;&#xA;    //Orthonormal basis&#xA;    float3 lensq = pow(view.x, 2) + pow(view.z, 2);&#xA;    float3 t1 = (lensq &amp;gt; 0.0f) ? normalize(cross(view, float3(0.0f, 1.0f, 0.0f))) : float3(1, 0, 0);&#xA;    float3 t2 = cross(view, t1);&#xA;&#xA;    //project&#xA;    float r = sqrt(rand1);&#xA;    float phi = 2.0f * pi * rand2;&#xA;    float p1 = r * cos(phi);&#xA;    float p2 = r * sin(phi);&#xA;&#xA;    float s = 0.5f * (1.0f + view.y);&#xA;    p2 = (1.0f - s) * sqrt(1.0f - pow(p1, 2.0f)) + s * p2;&#xA;&#xA;    float3 n = p1 * t1 + p2 * t2 + sqrt(max(0.0f, 1.0f - pow(p1, 2.0f) - pow(p2, 2.0f))) * view;&#xA;&#xA;    //unstrech normal and renormalize&#xA;    float3 n_out = normalize(float3(roughness2 * n.x, max(0.0f, n.y), roughness2 * n.z));&#xA;&#xA;    return n_out;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;where wo is the view direction in tangent space, roughness2 is the material roughness [0;1] squared and rand1/rand2 are uniform random numbers [0;1] sampled from a texture. I am using the exact algorithm described by Heitz except using y-up instead of z-up.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using the microfacet normal  &lt;strong&gt;&lt;em&gt;m&lt;/em&gt;&lt;/strong&gt; calculated like this I then acquire the sample direction &lt;strong&gt;&lt;em&gt;wi&lt;/em&gt;&lt;/strong&gt; by reflecting the world ray direction &lt;strong&gt;&lt;em&gt;-wo&lt;/em&gt;&lt;/strong&gt; in tangent space about the microfacet normal &lt;strong&gt;&lt;em&gt;m&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void ImportanceSampleGGXVNDF(float3 wo, Material material, inout float3 wi, inout float reflectance, float2 randSeed, bool isInVec, inout float fschlick)&#xA;{&#xA;    float roughness2 = pow(material.roughness, 2.0f);&#xA;    float3 m = VNDF_GGX(wo, roughness2, randSeed.x, randSeed.y);&#xA;&#xA;    wi = normalize(reflect(-wo, m));&#xA;&#xA;    float3 normalTangentSpace = float3(0.0f, 1.0f, 0.0f);&#xA;&#xA;    fschlick = FresnelSchlick(m, wi, isInVec ? material.ior1 : 1.0f, isInVec ? 1.0f : material.ior1);&#xA;    float G1 = SmithMaskingGGX(wi, wo, normalTangentSpace, pow(roughness2, 2));&#xA;    float G2 = SmithShdowingGGX(wo, wi, normalTangentSpace, pow(roughness2, 2));&#xA;&#xA;    reflectance = fschlick *(G2 / G1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where wo is the view direction, wi is the sample direction in tangent space, reflectance equaling the BRDF term (everything else cancels out according to Heitz! See &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; details of the derivation)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This however seems to be producing invalid sampling Directions for ray directions with negative values in y or z component resulting in invalid light probes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UMbMB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UMbMB.png&quot; alt=&quot;invalid samples for negative z direction&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Comparing with similar implementations (including: &lt;a href=&quot;https://gist.github.com/mebiusbox/32995b0d133a82a05b4023e512addb77&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; implementing the exact same method, &lt;a href=&quot;https://github.com/NVIDIA/Q2RTX/issues/40&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; also implementing the same method and &lt;a href=&quot;https://github.com/TheRealMJP/DXRPathTracer/blob/master/SampleFramework12/v1.02/Shaders/Sampling.hlsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; using an algorithm described in an older paper also published by &lt;a href=&quot;https://hal.archives-ouvertes.fr/hal-01509746/document&quot; rel=&quot;nofollow noreferrer&quot;&gt;Heitz&lt;/a&gt;) sadly yielded no solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The final output color is computed via&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    ImportanceSampleGGXVNDF(tangentSpaceDir, halfVec, l_materialCB[0], rayDir, reflectance, rand, isInVec, fschlick);&#xA;&#xA;    newRayDir = tangentToWorldSpace(rayDir, tangent, bitangent, triangleNormal);&#xA;&#xA;    ray.Direction = newRayDir;&#xA;    ray.TMin = 0.0001f;&#xA;    ray.TMax = 10000.0; //Maximum travel distance of ray&#xA;    reflected = TraceReflectiveRay(ray, currNumRecursions);&#xA;&#xA;    reflected *= reflectance;&#xA;&lt;span class=&quot;math-container&quot;&gt;```&lt;/span&gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11265" LastActivityDate="2019-10-03T20:44:14.147" Title="Implementing GGX VNDF importance sampling with DXR" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;shader&gt;&lt;brdf&gt;&lt;hlsl&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9211" PostTypeId="2" ParentId="9207" CreationDate="2019-10-04T09:32:23.427" Score="1" Body="&lt;p&gt;&lt;em&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: I've done some work in the past with wavelet decomposition of &lt;strong&gt;image&lt;/strong&gt; data but it occurred to me that it may be applicable to your problem.  Admittedly, I don't actually know if the following will work well in practice but, given how simple the approach is, and, as no other answer has been put forward, it seems to warrant investigation&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's assume you have a sequence of 2D (or &lt;strong&gt;n&lt;/strong&gt;D) vertices, &lt;span class=&quot;math-container&quot;&gt;$\small[P_0,P_1,P_2,...P_{N-1}]$&lt;/span&gt;, and you want to reduce those to a sequence of just &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; which form your Catmull-Rom control points. For the &lt;em&gt;moment&lt;/em&gt; let's assume &lt;span class=&quot;math-container&quot;&gt;$\small N=2^kM$&lt;/span&gt;, for some small value of &lt;span class=&quot;math-container&quot;&gt;$\small k$&lt;/span&gt;. We will apply &lt;em&gt;k&lt;/em&gt; wavelet decompositions to reduce N to M points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For our purposes, a single wavelet decomposition step takes a sequence of &lt;strong&gt;2&lt;/strong&gt;R points, &lt;span class=&quot;math-container&quot;&gt;$\small P=[P_0,P_1,...P_{2R-1}]$&lt;/span&gt;, and replaces it with two sequences of R points each: a &lt;em&gt;low frequency&lt;/em&gt; set, &lt;span class=&quot;math-container&quot;&gt;$\small L=[L_0,...L_{R-1}]$&lt;/span&gt;, and a high frequency set, &lt;span class=&quot;math-container&quot;&gt;$\small H=[H_0,...H_{R-1}]$&lt;/span&gt;. I suspect in your use case you might only be interested in the low frequency sequence(s).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are multiple different wavelets that can be used - the simplest being the Haar wavelet - but I think a linear (see &lt;a href=&quot;https://9p.io/who/wim/papers/athome/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sweldens &amp;amp; Schröder&lt;/a&gt; for an easy introduction)  or perhaps a 'Catmull-Rom-based' cubic wavelet might be suitable (though I don't know if this appears in any literature).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For each wavelet decomposition step we perform two passes; a 'lifting' operation to create all the high frequency terms, i.e. either...&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;em&gt;Linear&lt;/em&gt;:  &lt;span class=&quot;math-container&quot;&gt;$$H_i := P_{2i+1} - \frac{(P_{2i} +P_{2i+2})}{2}$$&lt;/span&gt;&#xA;  &lt;em&gt;CR-cubic&lt;/em&gt;:&lt;span class=&quot;math-container&quot;&gt;$$H_i := P_{2i+1} - \frac{9(P_{2i} +P_{2i+2})-(P_{2i-2} +P_{2i+4})}{16}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;...followed by an 'update'  which filters some of the high frequency terms back into the 'even'/low frequency terms as a correction. (We'll just assume, perhaps sub-optimally, this is the same for both linear and cubic)&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L_i := P_{2i} + \frac{(H_{i-1} + H_{i})}{4}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/strong&gt;: Actually, in practice, with clever indexing, these calculations can be done 'in place' on the original array.&lt;br/&gt;&#xA;This has also glossed over what happens when exceeding the bounds of the arrays, e.g. at &lt;span class=&quot;math-container&quot;&gt;$P_{2N}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$L_{-1}$&lt;/span&gt;, but one approach is to simply repeat values and/or pad with zeros.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To do the next wavelet decomposition, you repeat the process with the low frequency data, e.g. &quot;P:=L&quot; and repeat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I imagine that the final set of low frequency points, L, will form a &lt;em&gt;reasonable&lt;/em&gt; set of control points for a piecewise Catmull-Rom curve.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;More notes&lt;/strong&gt;: In this I've assumed that all the original points were 'equally important' and probably 'reasonably evenly spread'. It could be that you may want to look at the magnitudes of some of the {H_i} terms and if some are relatively large (compared to their neighbours) perhaps take action, e.g. say, re-insert them into the lower frequency set?&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As requested in the comments, I've put together a little bit of C code to do the &quot;cubic&quot; decomposition. For simplicity, this just uses separate arrays for each of the lower frequency results rather than, say, doing the calculation &quot;in place&quot; in the original array.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xA;#include &amp;lt;assert.h&amp;gt;&#xA;&#xA;#define IS_EVEN(X) (((X)&amp;amp;1)==0)&#xA;#define MAX(X,Y) ((X)&amp;gt;=(Y)?(X):(Y))&#xA;#define MIN(X,Y) ((X)&amp;lt;=(Y)?(X):(Y))&#xA;&#xA;typedef unsigned int UINT;&#xA;&#xA;&#xA;#define NUM_DIMS (2)&#xA;&#xA;typedef struct&#xA;{&#xA;    float pos[NUM_DIMS];&#xA;}vec_t;&#xA;&#xA;/*&#xA;// Lift&#xA;//&#xA;// Applies a wavelet &quot;lift&quot; step, i.e. computes high frequency terms, by&#xA;// predicting using Catmull-Rom spline through even points, and computing&#xA;// differences from odd&#xA;*/&#xA;static void Lift(const vec_t  PointsIn[], &#xA;                 const UINT NumPtsIn,&#xA;                 vec_t HFOut[])&#xA;{&#xA;    //this *example* assumes an even number of input values&#xA;    assert(IS_EVEN(NumPtsIn) &amp;amp;&amp;amp;  NumPtsIn&amp;gt;=2);&#xA;&#xA;    /*&#xA;    // step through odd values doing a &quot;lifting&quot; step, i.e. predicting &#xA;    // a position from neighbourhood of even points and computing the difference&#xA;    */&#xA;    for(UINT i = 1; i &amp;lt; NumPtsIn; i+= 2)&#xA;    {&#xA;        /*&#xA;        // get 2 neighbours on either side of this odd point. IF we step out of range, then&#xA;        // clamp to nearest valid point&#xA;        //&#xA;        // If you want more efficient code, move these decisions out of the loop&#xA;        */&#xA;        const vec_t * pv_m3 = &amp;amp;PointsIn[MAX(i, 3) - 3];&#xA;        const vec_t * pv_m1 = &amp;amp;PointsIn[i-1];&#xA;        const vec_t * pv_p1 = &amp;amp;PointsIn[MIN(i+1, NumPtsIn - 1)];&#xA;        const vec_t * pv_p3 = &amp;amp;PointsIn[MIN(i+3, NumPtsIn - 1)];&#xA;        const vec_t * pv    = &amp;amp;PointsIn[i];&#xA;&#xA;        vec_t *pResult = &amp;amp;HFOut[i/2];&#xA;&#xA;        for(UINT j = 0; j &amp;lt; NUM_DIMS; j++)&#xA;        {&#xA;            //Predict using Catmull-Rom interpolation - &#xA;            //i.e. mid point of CR spline through the even points {p[i-3], p[i-1], p[i+1], p[i+3]}&#xA;            const float PredictedPos = (9.0/16.0) * (pv_m1-&amp;gt;pos[j] + pv_p1-&amp;gt;pos[j]) - (1.0/16.0) * (pv_m3-&amp;gt;pos[j] + pv_p3-&amp;gt;pos[j]);&#xA;&#xA;            //Compute the difference from actual pos&#xA;            pResult-&amp;gt;pos[j] =pv-&amp;gt;pos[j] - PredictedPos;&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;/*&#xA;// Update&#xA;//&#xA;// Applies a wavelet &quot;Update&quot; step, i.e. computes the low frequency terms, &#xA;// by filtering in the 'errors' in the prediction (i.e the HF terms) into the&#xA;// 'even' vals&#xA;*/&#xA;static void Update(const vec_t  PointsIn[], &#xA;                   const UINT NumPtsIn,&#xA;                   const vec_t HFIn[],&#xA;                   vec_t LFOut[])&#xA;{&#xA;&#xA;    static const vec_t TheZeroVec = {0};&#xA;&#xA;    //this *example* assumes an even number of input values&#xA;    assert(IS_EVEN(NumPtsIn));&#xA;&#xA;    //init as if for the &quot;i = -1&quot; iteration&#xA;    const vec_t * pHFToRight = &amp;amp;TheZeroVec;&#xA;&#xA;    /*&#xA;    // step through even values doing an &quot;update&quot; step,&#xA;    */&#xA;    for(UINT i = 0; i &amp;lt; NumPtsIn; i+= 2)&#xA;    {&#xA;        /*&#xA;        // move one spot over in HF data&#xA;        */&#xA;        const vec_t *pHFToLeft = pHFToRight;&#xA;        pHFToRight = &amp;amp;HFIn[i/2];&#xA;&#xA;        const vec_t * pv    = &amp;amp;PointsIn[i];&#xA;&#xA;        vec_t *pResult = &amp;amp;LFOut[i/2];&#xA;&#xA;        for(UINT j = 0; j &amp;lt; NUM_DIMS; j++)&#xA;        {&#xA;            //Add in 1/2 of the average of the adjacent HF/Odd terms&#xA;            pResult-&amp;gt;pos[j] = pv-&amp;gt;pos[j] + (pHFToLeft-&amp;gt;pos[j] + pHFToRight-&amp;gt;pos[j]) * 0.25;&#xA;        }&#xA;    }&#xA;}&#xA;&#xA;//Some test data ...&#xA;#define NUM_ORIG_POINTS (512u)&#xA;static const vec_t PointsIn[NUM_ORIG_POINTS]=&#xA;{&#xA;#include &quot;fjord.h&quot;&#xA;};&#xA;&#xA;&#xA;#define NUM_ADDITIONAL_PASSES (4)&#xA;extern int main(int argc, const char *argv[])&#xA;{&#xA;&#xA;    vec_t HighFreq[NUM_ORIG_POINTS/2];&#xA;    vec_t LowFreqs[NUM_ADDITIONAL_PASSES+1][NUM_ORIG_POINTS/2];&#xA;&#xA;    /*&#xA;    // Do initial wavelet pass&#xA;    */&#xA;    Lift(PointsIn, NUM_ORIG_POINTS, HighFreq);&#xA;    Update(PointsIn, NUM_ORIG_POINTS, HighFreq, LowFreqs[0]);&#xA;&#xA;    /*&#xA;    // Do a few more wavelet passes&#xA;    */&#xA;    for(UINT Pass=0; Pass &amp;lt; NUM_ADDITIONAL_PASSES; Pass++)&#xA;    {&#xA;        const UINT CurrentNumSrcPoints = NUM_ORIG_POINTS &amp;gt;&amp;gt; (Pass+1);&#xA;&#xA;        Lift(LowFreqs[Pass],   CurrentNumSrcPoints, HighFreq);&#xA;        Update(LowFreqs[Pass], CurrentNumSrcPoints, HighFreq, LowFreqs[Pass+1]);&#xA;    }   &#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;br/&gt;&#xA;The above has been run on the outline on a section of a map (a section of a fjord apparently) which I've plotted using Excel's scatter plot tools (&lt;em&gt;which I hope will give a 'reasonable' approximation of Catmull-Rom splines without me having to write (or find) my own rendering code&lt;/em&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This shows an original set of 512 points:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/t456F.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t456F.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;..the set of 256 low-frequency points obtained from one wavelet step...&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ZktUd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZktUd.png&quot; alt=&quot;One Wavelet Step&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;...through to the 128 points obtained by two steps:&lt;a href=&quot;https://i.stack.imgur.com/OfdKt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OfdKt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-11-08T12:07:13.197" LastActivityDate="2019-11-08T12:07:13.197" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9212" PostTypeId="1" CreationDate="2019-10-04T09:45:35.743" Score="1" ViewCount="100" Body="&lt;p&gt;Full disclaimer, this was a test question, but I couldn't find any information online.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my opinion, this depends on if the primitive assembly stage happens before or after perspective division. If before, then it must be in homogeneous clip space. If after, NDC space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which of the two is it? Or am I completely wrong and its neither?&lt;/p&gt;&#xA;" OwnerUserId="9420" LastActivityDate="2019-11-03T12:01:05.223" Title="In the rendering pipeline, in what coordinate space are vertices when they arrive at the primitive assembly stage?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9213" PostTypeId="2" ParentId="9212" CreationDate="2019-10-04T10:11:15.477" Score="1" Body="&lt;p&gt;As pointed out by Simon F, the clipping stage needs to clip against edges (and thus triangles/primitives). Thus the primitive assembly stage cannot happen after clipping, even though the Pipeline is described such that primitive assembly happens after clipping.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Slide 16 of Ohio university's Han-Wei Shen's 2010 course &lt;a href=&quot;http://web.cse.ohio-state.edu/~shen.94/781/Site/Slides_files/pipeline.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;The OpenGL Rendering Pipeline&lt;/a&gt; suggests that vertices are transformed to Clip Space, then the primitive assembly happens and only afterwards is clipping actually done.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;s&gt;According to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;Khronos' wiki&lt;/a&gt; the primitive assembly happens after clipping, which includes the following:&lt;/s&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The vertex positions are transformed from clip-space to window space via the Perspective Divide and the Viewport Transform.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#Viewport_transform&quot; rel=&quot;nofollow noreferrer&quot;&gt;Window Space&lt;/a&gt; is described as the space after the viewport transform and that means after NDC space:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The viewport transform defines the transformation of vertex positions from NDC space to window space. These are the coordinates that are rasterized to the output image.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Since the viewport transform includes a scaling for the width and height of the viewport, as well as a translation with the viewports position on screen, you should end up with pixel coordiantes of your screen.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2019-10-04T11:05:27.920" LastActivityDate="2019-10-04T11:05:27.920" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9214" PostTypeId="1" AcceptedAnswerId="9215" CreationDate="2019-10-04T21:53:10.493" Score="4" ViewCount="2898" Body="&lt;p&gt;In a tutorial about OpenGL both words are mentioned, unfortunately without a good explanation.&lt;br&gt;&#xA;To find out, I have read &lt;a href=&quot;http://www.differencebetween.net/technology/software-technology/difference-between-clipping-and-culling/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; three times, but I fear I'm a too common man... my understanding is this:&lt;br&gt;&#xA;The video frame is rectangular, and the camera can't take the complete scene, so everything outside the camera's rectangular view is &quot;cut&quot; - or &quot;clipped&quot;.&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the other hand, &quot;culling&quot; means that those polygons are dismissed in further calculation that can't be seen anyway, because of other polygons in the foreground.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess this is what the linked article tries to describe in summary items 1. and 2. Correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I still don't get are these points:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;4.When compared to culling, clipping establishes the highest polygon. In video games, more of the clipping method is used than the culling&#xA;  technique.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So... I have a choice whether to use culling &lt;em&gt;or&lt;/em&gt; clipping? Then my understanding above is wrong...?&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;5.The clipping technique is used when the objects are partially visible. By utilizing the clipping technique, the video quality is&#xA;  increased and the frame rate is improved. Moreover, clipping also&#xA;  increases the presentation speed.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I understand that framerate increases when I don't have to waste time calculating polygons I don't need (which applies to both clipping and culling).&lt;br&gt;&#xA;But how does this increase video quality?&lt;br&gt;&#xA;And why should clipping do so, but culling not? Or does it? &lt;/p&gt;&#xA;" OwnerUserId="6346" LastActivityDate="2019-10-05T00:07:46.663" Title="What's the difference between Clipping and Culling?" Tags="&lt;opengl&gt;&lt;3d&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9215" PostTypeId="2" ParentId="9214" CreationDate="2019-10-05T00:07:46.663" Score="4" Body="&lt;p&gt;When it comes to graphics, the term &quot;culling&quot; by itself doesn't really have a single definition or location within the pipeline. The term is sometimes applied to primitives and it is sometimes applied to fragments. It is sometimes applied to faces based on orientation relative to the camera, and it is sometimes applied to primitives based on various parameters. So it's not useful to talk about &quot;culling&quot; as though it is a single thing; there are a lot of things called &quot;culling&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By contrast, &quot;clipping&quot; with regard to the graphics pipeline is almost always used to refer to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#Clipping&quot; rel=&quot;nofollow noreferrer&quot;&gt;what happens to the vertices of primitives after any programmable shading, but before rasterization&lt;/a&gt;. Clipping happens differently for different kinds of primitives, but the basic idea is to take a primitive and split it into one or more primitives, such that all of the new primitives are &lt;em&gt;entirely&lt;/em&gt; within the clip-space volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If a primitive is partially outside of the clip-space boundary, the process of clipping creates one or more new triangles that are entirely within that boundary. The clip-space boundary, through &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#Viewport_transform&quot; rel=&quot;nofollow noreferrer&quot;&gt;the viewport transform&lt;/a&gt;, defines everything which is visible with the current rendering state, so if something is outside of the clip-space boundary, it is not visible. Well, in theory; in practice, there are ways to draw stuff outside of the viewport (point size, line width, multisampling, etc), but nevermind those now.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now this describes the abstract model of how OpenGL and similar specifications talk about rendering. What actually happens in the hardware is often a different matter. Because clipping has the potential to generate many primitives from one (and thus make the pipeline choke a bit, since it has to run more rasterization cycles), hardware tends to avoid performing actual clipping unless absolutely necessary. So the notion that it is a performance optimization is not really true.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that a primitive which is entirely outside of the clip-space boundary gets clipped into nothingness. This particular case is often called &quot;culling&quot; the primitive, which is why the terms sometimes get used in similar places. Point primitives are either rasterized or culled; they don't ever undergo real clipping (since there is only one vertex). But overall, this process of reducing primitives to those within the clip-space boundary is referred to as &quot;clipping&quot;, not &quot;culling&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Clipping also allows users to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#User-defined_clipping&quot; rel=&quot;nofollow noreferrer&quot;&gt;define some user-defined clipping parameters&lt;/a&gt;, which clip primitives based on values provided by the previous vertex processing stages. You can use these to implement clipping planes, such that primitives are clipped at the intersection of an invisible plane. All parts of a primitive on one side of the plane are visible, but not on the other side.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Things which are referred to as &quot;culling&quot; formally within rendering APIs:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Face_Culling&quot; rel=&quot;nofollow noreferrer&quot;&gt;Face culling&lt;/a&gt;. Discarding triangle primitives based on their winding order relative to the viewport.&lt;/li&gt;&#xA;&lt;li&gt;Vertex-based culling (a relatively new feature), whereby entire primitives can be culled based on vertex processing parameters.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The article you're talking about seems to mostly equate &quot;culling&quot; with visibility culling techniques. These are computations implemented by user code which chooses to render or not render an object based on whether it is visible. These can range from the very simple frustum culling test (ie: asking if the object is even close to the visible region) to complex BSP systems or portal visibility culling (which attempt to detect if objects are entirely behind static geometry). But these are not part of the GPU's rendering pipeline, even if GPU processes are sometimes used to do such testing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Overall, that article gets more wrong than it does right, so it's best to just pretend you never read it.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-10-05T00:07:46.663" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9216" PostTypeId="1" CreationDate="2019-10-05T04:16:22.733" Score="2" ViewCount="270" Body="&lt;p&gt;Is there a way when looking at the source of a glTF file that you can determine what the boundingBox values of the object are?&lt;/p&gt;&#xA;" OwnerUserId="11268" LastActivityDate="2019-10-07T14:38:37.060" Title="Determining the Bounding Box values of a glTF file" Tags="&lt;gltf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9219" PostTypeId="1" CreationDate="2019-10-05T20:00:11.100" Score="1" ViewCount="80" Body="&lt;p&gt;I've tried looking everywhere, but I just don't get it. How is multiple shaders assigned to a mesh if you can only bind a single shader in OpenGL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume I have a mesh with a texture shader and now I do a ray-cast from the mouse position to select the object from the editor. In this case I would like to apply a selection shader that highlights that the mesh is selected, but still preserves the texture shader of the mesh. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to apply the selection shader on top of the texture shader of the mesh. How is this generally done in game engines?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way of doing this would be to make a completely third shader that is combination of both shaders and just apply the third shader. But that doesn't seem efficient and would become tedious when trying to add new shaders; now you have to specify a selection shader for every shader in the game, in case it's selected in the editor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated and if you can guide to some reading material that would be amazing.&lt;/p&gt;&#xA;" OwnerUserId="11119" LastActivityDate="2019-10-05T20:00:11.100" Title="How to render multiple shaders per mesh" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9220" PostTypeId="1" CreationDate="2019-10-05T20:03:12.173" Score="1" ViewCount="48" Body="&lt;p&gt;I'm trying to implement Oren-Nayar reflectance and I don't quite understand the Wikipedia article on it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the article, it has this diagram:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2jinS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2jinS.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can't figure out what &lt;span class=&quot;math-container&quot;&gt;$(\theta_i, \phi_i)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$(\theta_r, \phi_r)$&lt;/span&gt; represent. They are used in the equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="7950" LastEditorUserId="10096" LastEditDate="2019-10-05T21:40:12.877" LastActivityDate="2019-10-05T21:40:12.877" Title="Oren-Nayar Reflectance" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;diffuse&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9221" PostTypeId="1" CreationDate="2019-10-06T00:20:30.370" Score="1" ViewCount="20" Body="&lt;p&gt;Currently the graphics API I am using is Vulkan, but I am trying to find a general enough way to represent the following.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In graphics, drawing can be generalized as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Get vertex buffers and send them to the GPU&#xA;Get all uniform information (samplers, camera, offsets, light positions) and set them in the relevant shader&lt;/p&gt;&#xA;&#xA;&lt;p&gt;call the draw command.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously the above may be needed to be done multiple times for the same geometry for certain effects. But in general, that's the gist of the situation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am currently trying to setup a generalized &quot;draw&quot; scheme, in which I would like to just declare the geometry, declare the uniform values, and then just render that geometry with those uniforms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering if there is a data structure to organize this already.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;i.e, is there an existing scheme for arbitrary draw state declaration?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-10-06T00:20:30.370" Title="How to handle object drawables?" Tags="&lt;real-time&gt;&lt;vulkan&gt;&lt;data-structure&gt;&lt;drawing&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9222" PostTypeId="2" ParentId="5947" CreationDate="2019-10-06T06:25:57.107" Score="1" Body="&lt;p&gt;Although this is an old post, I feel I should add an important correction. The Human Visual System (HVS) is more sensitive to relative differences in darker tones rather&#xA;than brighter tones.&lt;/p&gt;&#xA;" OwnerUserId="11274" LastActivityDate="2019-10-06T06:25:57.107" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9223" PostTypeId="2" ParentId="9216" CreationDate="2019-10-07T14:38:37.060" Score="1" Body="&lt;p&gt;There isn't a bounding box for the whole glTF file, but individual primitives have &lt;code&gt;POSITION&lt;/code&gt; accessors that indicate &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; values.  This is specified in the &lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes&quot; rel=&quot;nofollow noreferrer&quot;&gt;Meshes section&lt;/a&gt;, with the following text:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;code&gt;POSITION&lt;/code&gt; accessor must have &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; properties defined.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;For a concrete example of this, take a look at the Box sample model, which assigns &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/blob/18912e96c60245f71a3775d365c990009307a11a/2.0/Box/glTF/Box.gltf#L48&quot; rel=&quot;nofollow noreferrer&quot;&gt;accessor 2 as &lt;code&gt;POSITION&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;meshes&quot;: [&#xA;    {&#xA;        &quot;primitives&quot;: [&#xA;            {&#xA;                &quot;attributes&quot;: {&#xA;                    &quot;NORMAL&quot;: 1,&#xA;                    &quot;POSITION&quot;: 2&#xA;                },&#xA;                &quot;indices&quot;: 0,&#xA;                &quot;mode&quot;: 4,&#xA;                &quot;material&quot;: 0&#xA;            }&#xA;        ],&#xA;        &quot;name&quot;: &quot;Mesh&quot;&#xA;    }&#xA;],&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The accessor at index &lt;code&gt;2&lt;/code&gt; (the third one in the list) looks &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/blob/18912e96c60245f71a3775d365c990009307a11a/2.0/Box/glTF/Box.gltf#L89-L105&quot; rel=&quot;nofollow noreferrer&quot;&gt;like this&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&quot;accessors&quot;: [&#xA;    { ... },&#xA;    { ... },&#xA;    {&#xA;        &quot;bufferView&quot;: 1,&#xA;        &quot;byteOffset&quot;: 288,&#xA;        &quot;componentType&quot;: 5126,&#xA;        &quot;count&quot;: 24,&#xA;        &quot;max&quot;: [&#xA;            0.5,&#xA;            0.5,&#xA;            0.5&#xA;        ],&#xA;        &quot;min&quot;: [&#xA;            -0.5,&#xA;            -0.5,&#xA;            -0.5&#xA;        ],&#xA;        &quot;type&quot;: &quot;VEC3&quot;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In this accessor, &lt;code&gt;min&lt;/code&gt; and &lt;code&gt;max&lt;/code&gt; are arrays of &lt;code&gt;x, y, z&lt;/code&gt; raw position data of the primitive.  This particular sample model is a unit cube, with values ranging from &lt;code&gt;-0.5&lt;/code&gt; to &lt;code&gt;0.5&lt;/code&gt; along each axis.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To understand how this affects the whole model though, one must walk the tree of scene nodes, and look at how these mesh primitives are being transformed by the nodes.  Also, if there are any animations or morph targets taking effect, they can influence the final positions of these meshes as well.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastActivityDate="2019-10-07T14:38:37.060" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9225" PostTypeId="1" AcceptedAnswerId="9226" CreationDate="2019-10-08T18:40:07.083" Score="0" ViewCount="56" Body="&lt;p&gt;I'm reading the book 3d Math Primer for Graphics and Game Development 1st edition by Fletcher Dunn and Ian Parberry. On page 61 there's this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yscWk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yscWk.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How does it derive &lt;span class=&quot;math-container&quot;&gt;$ v_{||} $&lt;/span&gt; there? It doesn't follow from what preceded this point in the book, unless I'm missing something. Also I'm not sure, is &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; supposed to be unit vector here? This should probably be in the errata but I didn't find anything. Anyway, how did he deduce this equation? Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="5496" LastEditorUserId="5496" LastEditDate="2019-10-08T19:38:21.487" LastActivityDate="2019-10-08T19:49:45.373" Title="3d Math Primer book equation derivation - Projecting One vector onto another" Tags="&lt;projections&gt;&lt;vectors&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9226" PostTypeId="2" ParentId="9225" CreationDate="2019-10-08T19:49:33.687" Score="1" Body="&lt;p&gt;Since &lt;code&gt;v∥&lt;/code&gt; is parallel to &lt;code&gt;n&lt;/code&gt;, it can be expressed as some multiple of &lt;code&gt;n&lt;/code&gt;. The multiple is the ratio of the length of &lt;code&gt;v∥&lt;/code&gt; to the length of &lt;code&gt;n&lt;/code&gt;. The &lt;code&gt;n&lt;/code&gt; vector doesn’t have to be normalized, but if it is, then &lt;code&gt;|n|&lt;/code&gt; is 1, so the equation becomes &lt;code&gt;v∥ = n * |v∥|&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-10-08T19:49:33.687" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9227" PostTypeId="2" ParentId="9225" CreationDate="2019-10-08T19:49:45.373" Score="1" Body="&lt;p&gt;Since we have:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\pmb{v}_{\parallel} \parallel \pmb{n},$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\pmb{v}_{\parallel} = k\pmb{n}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We want that the length of &lt;span class=&quot;math-container&quot;&gt;$\pmb{v}_{\parallel}$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$\|\pmb{v}_{\parallel}\|$&lt;/span&gt;, then:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\|\pmb{v}_{\parallel}\| =|k|\|\pmb{n}\| \implies |k| = \frac{\|\pmb{v}_{\parallel}\|}{\|\pmb{n}\|}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then the sign of &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; is simply chosen to match the direction of &lt;span class=&quot;math-container&quot;&gt;$\pmb{v}$&lt;/span&gt; (if the angle between &lt;span class=&quot;math-container&quot;&gt;$\pmb{v}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\pmb{n}$&lt;/span&gt; is more than 90 degrees, the sign is negative, otherwise it is positive).&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-10-08T19:49:45.373" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9229" PostTypeId="1" CreationDate="2019-10-09T17:52:39.170" Score="1" ViewCount="36" Body="&lt;p&gt;(Crossposting from here: &lt;a href=&quot;https://softwareengineering.stackexchange.com/questions/399331/fuse-3d-points-in-bundel-adjustment&quot;&gt;https://softwareengineering.stackexchange.com/questions/399331/fuse-3d-points-in-bundel-adjustment&lt;/a&gt;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm actually implementing my own Pose-Estimation/- and -Refinement pipeline. For this purpose I use one moving mono-camera. Then I take the consecutive images to estimate the pose and triangulate the points (nothing special). In the last step I refine the poses and 3D-points with a bundle adjustment approach. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generating 3D points with triangulation from consecutive image pairs will give me multiple estimations for one real-world 3D point. In fact, all the estimations refer to the same point. For my understanding, these estimations of the same 3D-points have to be fused in some way. Otherwise the poses were not linked anymore through a common point (see also image below). Further, looking at the equation for the re-projection error in different publications:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5Bmdqm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5Bmdqm.png&quot; alt=&quot;Core equation Bundle Adjustment&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;turns out, that 3D point (vector a) is only related to &lt;strong&gt;j&lt;/strong&gt; and not to the cameraindex &lt;strong&gt;i&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hl3QAm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hl3QAm.png&quot; alt=&quot;Stolen from: SBA: A Software Package for Generic Sparse Bundle Adjustment, MANOLIS I. A. LOURAKIS and ANTONIS A. ARGYROS&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I understand that right or do I have to use a different set of 3D points for each camera view? Suppose I've to merge the 3D points, is there any preferable strategy?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know, there are already countless implementations for BA. I want to use it for further development...&lt;/p&gt;&#xA;" OwnerUserId="11290" LastEditorUserId="209" LastEditDate="2019-10-10T08:05:59.740" LastActivityDate="2019-10-10T08:05:59.740" Title="Fuse 3D-Points in Bundle Adjustment?" Tags="&lt;image-processing&gt;&lt;optimization&gt;" AnswerCount="0" CommentCount="2" ClosedDate="2019-10-11T15:28:37.487" ContentLicense="CC BY-SA 4.0" />
  <row Id="9230" PostTypeId="1" AcceptedAnswerId="9232" CreationDate="2019-10-09T21:24:47.333" Score="3" ViewCount="50" Body="&lt;p&gt;I have a polyline and I want to simplify it with Douglas-Peucker. It's an easy algorithm, but what if there are points with the same distance. What point should I select? Is there a reasonable solution?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PLKly.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PLKly.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5828" LastActivityDate="2019-10-09T21:45:42.840" Title="Douglas-Peuker and equal distances" Tags="&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9231" PostTypeId="2" ParentId="6115" CreationDate="2019-10-09T21:40:36.390" Score="2" Body="&lt;p&gt;Apologies, I was going to add a comment to your question thread but found I ended up elaborating too much.  My development experience is from a DX 11 perspective so some of this may not hold in OpenGL&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The memory locality of the data does certainly play a major part.  But there is a few other items that do play into this, the width of the data as you know.  I've had a few GPUs and have had a stark performance hit on some based upon certain tipping points.  That is the for example, on my old AMD r290 if I recall, you could basically pass up to 4 float4s through to the vertex buffer with no additional cost over 1, but once I posted &gt; 4 then there was a measurable drop (in frame rate).   This is purely off my recollection and so is anecdotal as best.  But it holds that GPU architecture is changing all the time, and what niche techniques that give you a performance edge today maybe the bane of your performance tomorrow.  I've tried myself to stick to the advised known best on the assumption that hardware vendors will build their GPUs to the most common techniques of passing payloads via VB (obviously with some looks from constant buffers).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said that, you have asked the question about ordering the vertices, and certainly that will help marginally.  The performance gain is when you combine this with index buffers which then allows the hardware to optimise and cache already calculated vertices.    You certainly may get even more gains from Triangle strips etc which specifically ordered as per your thoughts.  Most of model rendering I do is indice/vertex based optimised models with instancing, I use a small amount of lookups for cyclic motion effects (tree branches for example), in these cases the entire branch of the tree is looking up the same value.  So caching can be taken advantage of here also.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All I can say in summary from myself is:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Try not to overthink optimisation at the start, while your still developing your game/application try not to prematurely optimise.  If you need to come back and add new capabilities, you might lose all the effort.  You have my habit maybe &gt;&amp;lt;, love trying to get the best performance and techniques&lt;/li&gt;&#xA;&lt;li&gt;GPU architectures are varied, and strengths of one can reflect weaknesses in another.  AMD and Nvidia are famous for getting devs to optimise games to their architecture, for a reason, each has advantages/disadvantages.  Taking the middle road on development might be the best place, don't use any hardware vendor based features (opinion here).  (add to that, some packed formats only exist in AMD).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;These are just a few thoughts and experiences I have had.  There are a lots books out there that you should get your hands on around these very topics.  I've not seen to many prescribe what you're proposing, but that doesn't mean its wrong.  Good luck.&lt;/p&gt;&#xA;" OwnerUserId="11291" LastActivityDate="2019-10-09T21:40:36.390" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9232" PostTypeId="2" ParentId="9230" CreationDate="2019-10-09T21:45:42.840" Score="2" Body="&lt;p&gt;I would consider the curvature in that case too. If the curvature is small - then it is a flat region - so you can safely remove it - your 4th point for example. If the curvature is large (your 5th point for example), even if the distance is the same, you should most likely leave it alone.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would actually recommend a curvature based method coming before Douglas-Peucker.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-10-09T21:45:42.840" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9233" PostTypeId="1" AcceptedAnswerId="9236" CreationDate="2019-10-10T18:52:45.440" Score="0" ViewCount="44" Body="&lt;p&gt;&lt;a href=&quot;https://www.glfw.org/docs/latest/quick.html#quick_swap_buffers&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt; I was reading about buffers and found such text: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;When the entire frame has been rendered, the buffers need to be swapped with one another, so the back buffer becomes the front buffer and vice versa.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And also this &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The swap interval indicates how many frames to wait until swapping the buffers, commonly known as vsync.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The question is: what is a frame? And how does it differ from buffer?&lt;/p&gt;&#xA;" OwnerUserId="11296" LastActivityDate="2019-10-11T01:49:34.977" Title="GLFW | What is a frame?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9234" PostTypeId="1" CreationDate="2019-10-10T22:26:58.093" Score="1" ViewCount="650" Body="&lt;p&gt;I'm working on a game set in space with procedurally generated planets, and I'm trying to write a shader that puts an atmosphere over a planet given the color of the atmosphere and the strength of the atmosphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks ok at low strengths:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ndp1Y.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ndp1Y.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But at high strengths the planet looks really bright:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GomKM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GomKM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And neither of them look realistic. For example in space engine the atmosphere really affects every part of the planet including the oceans without necessarily looking very bright:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5FBOW.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5FBOW.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the relevant part of the shader code I'm using (in glsl):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Final atmosphere color to use&#xA;vec4 atmo_pixel_color;&#xA;&#xA;if(r &amp;gt; radius_percent)&#xA;{&#xA;    //This is in space, cut off the color quickly&#xA;    float atmo_alpha = clamp(0.5 - pow((r - radius_percent), 2) * 600, 0, 1);&#xA;    atmo_pixel_color = atmo_color * atmo_strength;&#xA;    atmo_pixel_color.w = atmo_alpha;&#xA;}&#xA;else&#xA;{&#xA;    //Atmosphere is thicker near the edges of the planet&#xA;    float thickness = pow((r / radius_percent), 2) * 0.1f;&#xA;    atmo_pixel_color = atmo_color * (atmo_strength + thickness);&#xA;}&#xA;&#xA;gl_FragColor = planet_color + atmo_pixel_color;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;r is the distance from the center of the planet. radius_percent is the percentage of the texture that is in the planet (above that is empty space). planet_color is the final base color of the planet itself, or empty black if the pixel is in space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have very little experience doing graphics programming and I didn't really know where to start to research this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What kind of algorithm should I be using here to make the atmosphere look correct?&lt;/p&gt;&#xA;" OwnerUserId="11297" LastEditorUserId="11297" LastEditDate="2019-10-11T05:21:01.177" LastActivityDate="2019-11-12T15:02:25.377" Title="Shader code for putting an atmosphere over a planet" Tags="&lt;glsl&gt;&lt;color&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9236" PostTypeId="2" ParentId="9233" CreationDate="2019-10-11T01:49:34.977" Score="1" Body="&lt;p&gt;Conceptually, a frame is the image you're trying to create, presumably for the purpose of display. It is the product of your entire rendering operation for a specific slice of time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A &quot;buffer&quot; is the memory &lt;em&gt;for&lt;/em&gt; the image you either are trying to create or have already created. Hence the common term: framebuffer. Indeed, the choice of the word &quot;buffer&quot; is because you are typically &lt;em&gt;buffering&lt;/em&gt; multiple images. That is, one buffer will currently be in the process of being displayed, while another buffer is being rendered.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-10-11T01:49:34.977" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9237" PostTypeId="1" AcceptedAnswerId="9264" CreationDate="2019-10-11T07:49:54.757" Score="0" ViewCount="101" Body="&lt;p&gt;I'm a software engineer student with a big projet idea but low graphic knowledge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My goal is to compare two people dancing. One person would be the teacher with perfect moves and the other would be a dance trainee.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From my beginner point of view, all I need to retrieve is both skeletons with a motion tracking camera (like Kinect?) then I can do maths with the different reference points (X,Y,Z).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a motion tracking camera + API or Library you would recommand me ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I do not want to open a 3D software like MeshLab. I would like to retrieve the reference points through line of codes and manipulate them as I wish.&lt;/p&gt;&#xA;" OwnerUserId="11295" LastActivityDate="2019-10-18T05:41:30.960" Title="How can I reproduce the MatchMoving/MotionTracking technique from Just Dance?" Tags="&lt;camera&gt;&lt;motion&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9238" PostTypeId="1" AcceptedAnswerId="9245" CreationDate="2019-10-11T22:14:33.690" Score="4" ViewCount="138" Body="&lt;p&gt;I am trying to find (or maybe create) an algorithm for creating a smooth, rounded 3D mesh given a 2D outline. I'm trying to recreate a system from a Gamecube game called Amazing Island, and you can see an example of how it works &lt;a href=&quot;https://youtu.be/8xI2sZwYg10?t=62&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;. A more modern example of what I'm trying to do would be the &lt;a href=&quot;https://youtu.be/Zl_Gimw62mM?t=98&quot; rel=&quot;noreferrer&quot;&gt;Soft Edge 3D Doodle tool in Paint 3D&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, you draw a shape with a freeform pen tool, and the shape is &quot;inflated&quot; into a 3D mesh. The result should have smooth, curved, somewhat organic-looking edges, rather than simply extruding the shape into a prism. Each shape can be assumed to be simply connected (meaning shapes with holes through them are not possible), and it can be assumed that the outline won't self-intersect. It would be nice if I could find a way to have non-simply connected shapes, but it's not necessary, and seems like it would be significantly more complicated.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The closest thing that I've been able to find is how to take an outline and triangulate it to make a flat 2D mesh. I'm pretty lost on how I can take that and turn it into what I want though. I can get a list of points representing the vertices of the outline, which seems like it should be the first step.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm implementing this in C#, in Unity, but I'm not necessarily looking for code. A description of an algorithm, or even a good idea for how I could approach the problem, would be great. Thank you for your time.&lt;/p&gt;&#xA;" OwnerUserId="11300" LastActivityDate="2019-10-15T12:39:39.810" Title="Creating a Smooth 3D Mesh from a 2D Outline" Tags="&lt;3d&gt;&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;procedural-generation&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9239" PostTypeId="1" CreationDate="2019-10-12T18:42:21.877" Score="0" ViewCount="306" Body="&lt;p&gt;Here's something that's been bothering me while learning graphics. We have two core concatenated matrix sets: &quot;TRS&quot; for transforms, and &quot;MVP&quot; for moving everything into the canonical view volume.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TRS is applied in this manner: T(R(S(p))), i.e. the scale is applied first, then the rotation, then the translation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;MVP is applied in this manner: P(V(M(p))), i.e. we apply the model matrix first, then the view matrix, and finally the projection matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is the order in which we name these sets not consistent? I feel like I am getting something very obvious wrong, but I can't help but be confused by this.&lt;/p&gt;&#xA;" OwnerUserId="11304" LastActivityDate="2019-10-12T20:21:18.687" Title="Why do we call it TRS and MVP, instead of SRT and MVP or TRS and PVM?" Tags="&lt;matrix&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9240" PostTypeId="2" ParentId="9239" CreationDate="2019-10-12T20:15:22.553" Score="1" Body="&lt;p&gt;Because whether you use &lt;span class=&quot;math-container&quot;&gt;$MVP$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$PVM$&lt;/span&gt; actually depends on how you perform the multiplication: &lt;span class=&quot;math-container&quot;&gt;$vMVP$&lt;/span&gt; versus &lt;span class=&quot;math-container&quot;&gt;$PVMv$&lt;/span&gt;, note that you have:&#xA;&lt;span class=&quot;math-container&quot;&gt;$(PVMv)^T = v^TM^TV^TP^T=vM^TV^TP^T$&lt;/span&gt;, where the last identity does not hold in math, but holds in glsl since vectors can be reinterpreted as either row or column vectors for convenience.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same holds for &lt;span class=&quot;math-container&quot;&gt;$TRS$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$SRT$&lt;/span&gt;. In general CG code and applications have an issue with sticking to standard established conventions, so you get all kinds of funny conventions.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-10-12T20:21:18.687" LastActivityDate="2019-10-12T20:21:18.687" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9241" PostTypeId="1" AcceptedAnswerId="9243" CreationDate="2019-10-13T11:39:48.907" Score="1" ViewCount="344" Body="&lt;p&gt;What is the difference between all these techniques? I know what a lightning model does, eg Phong, Flat, Gouraud. As far as I know both Ray Tracing and Global Illumination are just lighting models different from the classic ones mentioned above that simulate physical light more accurately, taking into account light ray bouncing, indirect light etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As for shadows, I believe not all lighting models can support shadows. Are shadows something implemented on top of a lighting model, ie they can't be used without a proper one that supports them, or are they used independently of lighting?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that the rendering equation is a general technique for the approximation of lighting in a 3D world. Is the rendering equation used in conjuction with a lighting model, or is a &quot;lighting model&quot; an implementation of the redering equation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does the rendering equation account for shadows as well (from its form on wikipedia I think not) and if not should an &quot;extended&quot; rendering equation be developed for a particular 3d world that enables shadows?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to clarify this foggy cloud of concepts in my mind. Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="5496" LastActivityDate="2019-10-13T14:30:42.087" Title="Difference betwen Rendering Equation, Lighting model, Ray Tracing, Global Illumination and Shadows?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;global-illumination&gt;&lt;shading&gt;&lt;theory&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9242" PostTypeId="2" ParentId="9234" CreationDate="2019-10-13T12:47:16.817" Score="1" Body="&lt;p&gt;I believe that Space Engine as a base algorithm still uses Precomputed Atmospheric Scattering by E. Bruneton. It is released on &lt;a href=&quot;https://github.com/ebruneton/precomputed_atmospheric_scattering&quot; rel=&quot;nofollow noreferrer&quot;&gt;github&lt;/a&gt;. So it is good starting point if you want to implement atmospheric scattering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For beginner this algorithm is pretty advanced stuff written in C++11, and modern OpenGL, so such knowledge is required. In short, to avoid a cost of solving rendering equation for scattering in participating medium (single as well as multiple scattering) it uses precomputed lookup textures where it is possible and equations for Rayleigh and Mie scattering based on physical model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is also &lt;a href=&quot;https://www.shadertoy.com/view/lslXDr&quot; rel=&quot;nofollow noreferrer&quot;&gt;simpler demo&lt;/a&gt; computed in real time on shadertoy. This is probably better place to start. It involves raycasting a sphere and integrating Rayleigh and Mie scattering along a ray in real time. It is based on &lt;a href=&quot;https://developer.nvidia.com/gpugems/GPUGems2/gpugems2_chapter16.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;GPU Gems article&lt;/a&gt;, which provides some good information how it works.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2019-10-13T13:24:35.587" LastActivityDate="2019-10-13T13:24:35.587" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9243" PostTypeId="2" ParentId="9241" CreationDate="2019-10-13T14:24:12.247" Score="6" Body="&lt;p&gt;The rendering equation aims to describe what the light distribution for a specific scene is, under several assumptions. The most important assumption is that we are working in a &lt;strong&gt;geometrical optics framework&lt;/strong&gt; - so we do not consider the wave properties of light - meaning no diffraction for example, we also do not consider quantum effects, such as phosphorescence. If the rendering equation is not in its spectral form, then there's also no dispersion. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are additional constraints on top of what we have for geometrical optics, like &lt;strong&gt;light travels instantaneously&lt;/strong&gt;, light rays traveling in &lt;strong&gt;straight paths&lt;/strong&gt; from surface to surface (no spatially continuously varying indices of refraction), no polarization, etc. Many of the constraints can be removed in more general formulations (which are also available), but usually that incurs heavier computations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the rendering equation serves as an approximation to how light works in the real world, but since we want to model only a subset of light effects, various simplification are made in order to make the problem easier to solve. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us consider the commonly shown formulation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pTB8o.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pTB8o.png&quot; alt=&quot;The rendering equation&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/zDg2Q.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zDg2Q.png&quot; alt=&quot;The rendering equation&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The above images are linked from: &lt;a href=&quot;http://viclw17.github.io/2018/06/30/raytracing-rendering-equation/&quot; rel=&quot;noreferrer&quot;&gt;Raytracing - Rendering Equation Insight&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe these images are fairly self-explanatory. The function &lt;span class=&quot;math-container&quot;&gt;$f_r$&lt;/span&gt; referred to as the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function&quot; rel=&quot;noreferrer&quot;&gt;BRDF&lt;/a&gt; (or more generally the &lt;a href=&quot;https://en.wikipedia.org/wiki/Bidirectional_scattering_distribution_function&quot; rel=&quot;noreferrer&quot;&gt;BSDF&lt;/a&gt;) describes the interaction of materials with light. Often in real-time graphics this is referred to as the illumination or reflectance model - one such example is &lt;a href=&quot;https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model&quot; rel=&quot;noreferrer&quot;&gt;the Blinn–Phong reflection model&lt;/a&gt;, there is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Specular_highlight#Cook%E2%80%93Torrance_model&quot; rel=&quot;noreferrer&quot;&gt;Cook-Torrance model&lt;/a&gt; too, and several others. All of those are brdfs/bsdfs, or constituent parts of brdfs/bsdfs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Flat, Gouraud, and Phong shading (or more correctly Gouraud and Phong &lt;strong&gt;interpolation&lt;/strong&gt;) is really referring to how the normals of a model are treated (interpolated). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Shading#Flat_shading&quot; rel=&quot;noreferrer&quot;&gt;Flat shading&lt;/a&gt; simply uses the actual normals of an object. If we could render objects made up of infinitely many triangles, even flat shading would be ideal. However, as for most things in graphics, efficiency is key, so we cannot use infinitely may triangles. For that reason people have chosen to modify the surface normals of objects, in order to get a smoother appearance - as if they used a lot more triangles. How is this achieved? Well, one can find per-vertex normals, that are a weighted sum of the face normals, so that a smooth like appearance is achieved. For example by using approaches such as the one described in the following publication: &lt;a href=&quot;https://www.semanticscholar.org/paper/Weights-for-Computing-Vertex-Normals-from-Facet-Max/f6eb2950de296424d35338893f193fb3adb74367&quot; rel=&quot;noreferrer&quot;&gt;Weights for Computing Vertex Normals from Facet Normals&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Gouraud_shading&quot; rel=&quot;noreferrer&quot;&gt;Gouraud shading&lt;/a&gt; (Gouraud interpolation), refers to computing the illumination per vertex, using these normals, and then &lt;strong&gt;interpolating&lt;/strong&gt; the resulting color over the triangle - this explains why it has discontinuities at edges and vertices. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Phong_shading&quot; rel=&quot;noreferrer&quot;&gt;Phong shading&lt;/a&gt; (Phong interpolation) &lt;strong&gt;interpolates&lt;/strong&gt; the normals over the triangle (by using barycentric coordinates) and then computes the shading using those per-pixel which results in an overall smoother appearance. Note that discontinuities at the outline of the object can still be visible - this modifies only the shading of the object, and not its actual geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One can go further and use &lt;a href=&quot;https://en.wikipedia.org/wiki/Bump_mapping&quot; rel=&quot;noreferrer&quot;&gt;bump mapping&lt;/a&gt;, &lt;a href=&quot;http://johnwhigham.blogspot.com/2015/03/derivative-mapping.html&quot; rel=&quot;noreferrer&quot;&gt;derivative mapping&lt;/a&gt;, or &lt;a href=&quot;https://en.wikipedia.org/wiki/Normal_mapping&quot; rel=&quot;noreferrer&quot;&gt;normal mapping&lt;/a&gt;, in order to further enrich the shading information over an otherwise flat surface, by modifying the normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All of those normal modifications (Gouraud and Phong interpolation; bump, derivative, and normal mapping) produce normals which are commonly referred to as shading normals. Note that those violate energy conservation principles in general, and may cause various artifacts. But obviously this is the trade-off for performance. So &lt;strong&gt;all of those techniques fall under the umbrella of normals modification and are not illumination models in their own right&lt;/strong&gt; (but those normals are used in the brdf and the rendering equation to compute shading - where the shading part in the terms goes - I still believe interpolating is a better naming).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To understand the shadow conundrum, let's look at the solution of the rendering equation. The rendering equation in mathematics is known as a &lt;a href=&quot;https://en.wikipedia.org/wiki/Fredholm_integral_equation#Equation_of_the_second_kind&quot; rel=&quot;noreferrer&quot;&gt;Fredholm integral equation of the second kind&lt;/a&gt;, under some assumptions, its solution is given through the sum of increasingly dimensional integrals: &lt;a href=&quot;https://en.wikipedia.org/wiki/Liouville%E2%80%93Neumann_series&quot; rel=&quot;noreferrer&quot;&gt;Liouville–Neumann series&lt;/a&gt;. I will avoid writing out the integrals explicitly, since it will get ugly very quickly, you can find the expansion in Veach's thesis however. I will just use the operator formulation of the rendering equation. Let &lt;span class=&quot;math-container&quot;&gt;$L = L_o$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; be that integral from the images. Then the rendering equation can be written concisely as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + L_r = L_e + TL$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L-TL = L_e$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(I-T)L = L_e$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = (I-T)^{-1}L_e = \sum_{k=0}^{\infty}T^kL_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last equality holds due to the Liouville-Neumann expansion that I talked about. This is a sum of increasingly dimensional integrals similar to the one you had in the rendering equation (with a few additions) - usually this is also done with respect to the area formulation of the rendering equation (the images here provide the solid angle formulation). Informally &lt;span class=&quot;math-container&quot;&gt;$T^k$&lt;/span&gt; means that there were &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; bounces before reaching the light source, so it's a sum of the energy coming from paths starting at the eye and ending at a light source, of length &lt;span class=&quot;math-container&quot;&gt;$1, 2, 3, ..., \infty$&lt;/span&gt;. Let's look at the area formulation of the rendering equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(\pmb{x}_0\leftarrow\pmb{x}_1) = L_e(\pmb{x}_0\leftarrow\pmb{x}_1) + \\ \int_{\mathcal{M}}f_r(\pmb{x}_0\leftarrow\pmb{x}_1\leftarrow\pmb{x}_2)L(\pmb{x}_1\leftarrow\pmb{x}_2)\frac{\cos\theta_{\pmb{x}_1}\cos\theta_{\pmb{x}_2}}{\|\pmb{x}_2-\pmb{x}_1\|^2_2}V(\pmb{x}_1,\pmb{x}_2)\,d\pmb{x}_2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here &lt;span class=&quot;math-container&quot;&gt;$\mathcal{M}$&lt;/span&gt; is the set of all surface points of the scene (including lights), &lt;span class=&quot;math-container&quot;&gt;$L(\pmb{x}_0\leftarrow\pmb{x}_1)$&lt;/span&gt; gives you the radiance traveling from surface point &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_0$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$L_e(\pmb{x}_0\leftarrow\pmb{x}_1)$&lt;/span&gt; gives you the emission from &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_1$&lt;/span&gt; towards &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_0$&lt;/span&gt;. To relate the brds to the previous formulation, one can set: &lt;span class=&quot;math-container&quot;&gt;$\omega_o = \frac{\pmb{x}_0-\pmb{x}_1}{\|\pmb{x}_0-\pmb{x}_1\|}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\omega_i = \frac{\pmb{x}_2-\pmb{x}_1}{\|\pmb{x}_2-\pmb{x}_1\|}$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\pmb{x} = \pmb{x}_1$&lt;/span&gt;. Furthermore, &lt;span class=&quot;math-container&quot;&gt;$\cos\theta_{\pmb{x}_1} = \omega_i \cdot \pmb{n}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\pmb{n}$&lt;/span&gt; is the surface normal at &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_1$&lt;/span&gt;, similarly &lt;span class=&quot;math-container&quot;&gt;$\cos\theta_{\pmb{x}_2} = -\omega_i \cdot \pmb{n}_{\pmb{x}_2}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\pmb{n}_{\pmb{x}_2}$&lt;/span&gt; is the surface normal at &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_2$&lt;/span&gt;. The squared Euclidean distance in the denominator is due to the &lt;a href=&quot;https://en.wikipedia.org/wiki/Inverse-square_law&quot; rel=&quot;noreferrer&quot;&gt;inverse-square law&lt;/a&gt; (it's implicitly encoded in the solid angle formulation). Finally, &lt;span class=&quot;math-container&quot;&gt;$V(\pmb{x}_1,\pmb{x}_2)$&lt;/span&gt; is the visibility function - it is equal to &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; if there is nothing between &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_2$&lt;/span&gt; (no occlusion), and &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; otherwise (it is also implicit in the solid angle formulation) - this is the function that encodes shadows. Approximations, that do not produce shadows, have simply thrown away or modified that visibility function (one such modification is replacing &lt;span class=&quot;math-container&quot;&gt;$V$&lt;/span&gt; with the ambient occlusion or with information from a shadow map). This is done for efficiency reasons once again, as instead you would have to trace a ray from &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}_2$&lt;/span&gt; and intersect against the scene to check for occlusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us consider the simplifications that are usually made in real-time graphics. Most implementations, simply cut the Neumann sum to the 2nd term:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + TL_e + T^2L_e + ... \approx L_e + TL_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So anything beyond direct illumination and emission is thrown away. This has important implications - such as: no indirect illumination or scattering effects. Let's consider what this amounts to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + TL_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(\pmb{x}_0\leftarrow\pmb{x}_1) = L_e(\pmb{x}_0\leftarrow\pmb{x}_1) + \\ \int_{\mathcal{M}}f_r(\pmb{x}_0\leftarrow\pmb{x}_1\leftarrow\pmb{x}_2)L_e(\pmb{x}_1\leftarrow\pmb{x}_2)\frac{\cos\theta_{\pmb{x}_1}\cos\theta_{\pmb{x}_2}}{\|\pmb{x}_2-\pmb{x}_1\|^2_2}V(\pmb{x}_1,\pmb{x}_2)\,d\pmb{x}_2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is one small difference compared to the area formulation, and that is the fact that we have &lt;span class=&quot;math-container&quot;&gt;$L_e$&lt;/span&gt; in the integral and not &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;, so it is not a recursive integral anymore. It is still an integral however, which implies an infinite sum - this is currently not very fast to compute, unless you have specialized hardware like RTX, especially for more complex scenes. Note that the integral is over all surface points emitting light, so you would in general need to sum up the light coming from area lights, skyboxes etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the next simplification that is usually done, is using point lights. Point lights have the computationally efficient property, that they are represented through &lt;a href=&quot;https://en.wikipedia.org/wiki/Dirac_delta_function&quot; rel=&quot;noreferrer&quot;&gt;Dirac delta functions&lt;/a&gt;. A Dirac delta function, essentially allows you to get rid of the integral - the light comes only from a single direction. Then your integral turns into a finite sum over all point lights in the scene (a similar argument may be made for directional or spot lights, note that the light cosine term disappears, since informally there's no normal to speak of):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(\pmb{x}_0\leftarrow\pmb{x}_1) = L_e(\pmb{x}_0\leftarrow\pmb{x}_1) + \\ \sum_{k=1}^{N}f_r(\pmb{x}_0\leftarrow\pmb{x}_1\leftarrow\pmb{y}_k)L_k(\pmb{x}_1\leftarrow\pmb{y}_k)\frac{\cos\theta_{\pmb{x}_1}}{\|\pmb{y}_k-\pmb{x}_1\|^2_2}V(\pmb{x}_1,\pmb{y}_k)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$L_e$&lt;/span&gt; is generally constant, &lt;span class=&quot;math-container&quot;&gt;$L_k$&lt;/span&gt; is the radiance of light source &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\pmb{y}_k$&lt;/span&gt; is the position of light source &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt;. If your material is diffuse then &lt;span class=&quot;math-container&quot;&gt;$f_r$&lt;/span&gt;  and the radiance of the point light do not change with directions, then &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$f_r$&lt;/span&gt; are also constant so you get the (possibly) familiar expression:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + \sum_{k=1}^{N}f_rL_k\cos\theta_k V(\pmb{x}_1,\pmb{y}_k)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$color = emission + \sum_{k=1}^{N}ObjectColor * LightColor * \cos\theta_k * VisibilityFromLight\_k$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only thing that is usually not there is the &lt;span class=&quot;math-container&quot;&gt;$V$&lt;/span&gt; term, since it requires tracing rays through the scene, which standard rasterization algorithms don't do. So it's either set to &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt;, or replaced with information from a shadow map (for each summand the shadow map from this light's perspective ought to be used for semi-correct results). Often times the remaining terms that were cut off &lt;span class=&quot;math-container&quot;&gt;$T^2L_e + T^3L_e + ... + T^{\infty}L_e$&lt;/span&gt; are substituted with a constant ambient light term or with an ambient occlusion term.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Path tracing usually solves the rendering equation without any of the above simplifications (but requires a lot more computational power), that is the reason why images produced by it look so realistic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Whole books may be written on this matter. But I hope I managed to clarify at least some things regarding Gouraud, Phong interpolation, shadows, and how all of this ties into the rendering equation.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-10-13T14:30:42.087" LastActivityDate="2019-10-13T14:30:42.087" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9245" PostTypeId="2" ParentId="9238" CreationDate="2019-10-14T02:04:25.693" Score="4" Body="&lt;p&gt;One algorithm that's pretty good for this, but very difficult to implement is to find the &lt;a href=&quot;https://en.wikipedia.org/wiki/Medial_axis&quot; rel=&quot;nofollow noreferrer&quot;&gt;Medial Axis&lt;/a&gt; of the shape and then have various profiles that are based on the signed distance from the medial axis. You can also use the &lt;a href=&quot;https://en.wikipedia.org/wiki/Straight_skeleton&quot; rel=&quot;nofollow noreferrer&quot;&gt;Straight Skeleton&lt;/a&gt; instead of the Medial Axis, but it's also a bit of a pain to calculate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An easier way that's not quite as accurate, but usually good enough is described here: &lt;a href=&quot;https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://steamcdn-a.akamaihd.net/apps/valve/2007/SIGGRAPH2007_AlphaTestedMagnification.pdf&lt;/a&gt;. You can take a bitmap of the shape the user drew, shrink it down to some manageable size, calculate the distance of every pixel from the edges of the shape, then scale it to the size you need (and scale the distances accordingly). Once you have signed distances you can use them with the same 3D profiles mentioned above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, the pillow in the video you showed is basically drawn as a square. Your 3D profile would set the front face height to 0 at the squares edges, and increasing up to some maximum as you moved towards the center, peaking after a short distance and holding up to the center. The back face height would be the same but in the opposite direction.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-10-14T02:04:25.693" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9247" PostTypeId="1" AcceptedAnswerId="9250" CreationDate="2019-10-14T09:22:24.930" Score="1" ViewCount="84" Body="&lt;p&gt;This is a screen shot from an animation generated by &lt;a href=&quot;https://matplotlib.org/1.2.1/examples/mplot3d/wire3d_animation_demo.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;a matplotlib example&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JbI9h.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JbI9h.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the key part in the code is &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    R = 1 - np.sqrt(X**2 + Y**2)&#xA;    Z = np.cos(2 * np.pi * X + phi) * R&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;corresponding equation is&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\left(- \sqrt{X^{2} + Y^{2}} + 1\right) \cos{\left (2 \pi X + \phi \right )}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could some give an explanation or hint about this kind of equation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a name of this type of graphics?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;usually cosine/sine could generate something like a (half) circle, what does &lt;code&gt;R&lt;/code&gt; part do?&lt;/p&gt;&#xA;" OwnerUserId="11312" LastActivityDate="2019-10-14T18:30:55.167" Title="Could some give an explanation or hint about this kind of equation? $\left(- \sqrt{X^{2} + Y^{2}} + 1\right) \cos{\left (2 \pi X + \phi \right )}$" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9248" PostTypeId="1" CreationDate="2019-10-14T16:04:13.560" Score="2" ViewCount="117" Body="&lt;p&gt;I am trying to render a dielectric sphere inside the Cornell Box. Some circles are generated on the sphere. Here is the photo generated by path tracer:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kEAYT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kEAYT.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And below is my main function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function trace(surfaces::Array{Surfaces, 1}, ray::Ray, depth::Int64, maxDepth::Int64)&#xA;if depth &amp;gt;= maxDepth&#xA;    return Vec3(0,0,0)&#xA;end&#xA;t, material = nearest(surfaces, ray, Inf)&#xA;if typeof(material) == Empty&#xA;    return Vec3(0,0,0)&#xA;end&#xA;if material.isLight == true&#xA;    return material.emittance&#xA;end&#xA;ρ = material.reflectance&#xA;n = material.normal&#xA;if material.isDielectric == true&#xA;    cosθ = -dot(n, ray.d)&#xA;    ref = material.ni/material.nt&#xA;    if cosθ &amp;lt; 0&#xA;        cosθ = -cosθ&#xA;        n = -1.0*n&#xA;        ref = 1/ref&#xA;    end&#xA;    disc = 1 - ref*ref*(1-cosθ*cosθ)&#xA;    if disc &amp;lt; 0&#xA;        R = ray.d - 2*dot(ray.d, n)*n&#xA;        In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)&#xA;        return In&#xA;    elseif disc &amp;gt; 0&#xA;        R0 = (ref-1)/(ref+1)&#xA;        R0 = R0*R0&#xA;        Rθ = R0 + (1-R0)*(1-cosθ)*(1-cosθ)*(1-cosθ)*(1-cosθ)*(1-cosθ)&#xA;        u = rand()&#xA;        if u &amp;lt; Rθ&#xA;            R = ray.d - 2*dot(ray.d, n)*n&#xA;            In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)&#xA;            return In&#xA;        else&#xA;            R = ref*ray.d + (ref*cosθ - sqrt(disc))*n&#xA;            In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)&#xA;            return In&#xA;        end&#xA;    end&#xA;end      &#xA;BRDF = ρ/Π&#xA;R = hemiRand(n)&#xA;In = trace(surfaces, Ray(ray.s + t*ray.d, R), depth+1, maxDepth)&#xA;return Π*BRDF*In&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And I think the fresenl effect of the area light on the sphere looks strange and wrong! Am I correct? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: I searched a bit and I guess it's the moire effect. But I don't know how to get rid of it.&lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-10-14T16:58:38.517" LastActivityDate="2019-10-15T17:53:48.767" Title="Strange artifacts while rendering a dielectric material" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9249" PostTypeId="1" CreationDate="2019-10-14T18:17:07.760" Score="0" ViewCount="42" Body="&lt;p&gt;We have a projector type display used in an automotive application, where a projector displays an application on the windshield.  Because the projector would normally warp a flat image, we have to counter this warping. The way we do this is:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render our content to a framebuffer&lt;/li&gt;&#xA;&lt;li&gt;Apply that frame buffer as a texture on a special mesh that counteracts the warping from the projector.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;As we've found, the final stages of the rendering pipeline (rendering pixels to a framebuffer / and or screen) are often the biggest bottlenecks on embedded hardware.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any potential method we could use to reduce steps 1 and 2 to a single pass?  Essentially going through multiple projections, but without using intermediate frame buffers?&lt;/p&gt;&#xA;" OwnerUserId="3332" LastActivityDate="2019-10-14T18:17:07.760" Title="How combine multiple projections into a single pass?" Tags="&lt;opengl&gt;&lt;projections&gt;&lt;opengl-es&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9250" PostTypeId="2" ParentId="9247" CreationDate="2019-10-14T18:30:55.167" Score="6" Body="&lt;p&gt;The &lt;code&gt;R&lt;/code&gt; part generates a cone where the point is at (0, 0, 1) and it spreads out below that. It meets the x-y plane at the unit circle:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jtZdE.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jtZdE.png&quot; alt=&quot;A cone with the point at (0, 0, 1) and spreading out downward&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;cos&lt;/code&gt; component defines an extruded cosine wave along the X-axis:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/dsszO.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dsszO.png&quot; alt=&quot;The graph of cos(2*π*x)&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the final equation takes the cosine wave and multiplies its amplitude by the cone. It will have full amplitude at the origin, and decrease to 0 at the unit circle on the x-y plane. Past that it becomes negative:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EviPs.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EviPs.png&quot; alt=&quot;Multiplying the second equation by the first&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;phi&lt;/code&gt; component shifts the sine wave forward or backward along the x axis.&lt;/p&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-10-14T18:30:55.167" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9251" PostTypeId="1" AcceptedAnswerId="9252" CreationDate="2019-10-15T01:46:04.590" Score="1" ViewCount="47" Body="&lt;p&gt;per this &lt;a href=&quot;https://computergraphics.stackexchange.com/a/9250/11312&quot;&gt;post&lt;/a&gt;, this formula&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$Z = 1 - \sqrt{X^{2} + Y^{2}}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;generates a cone where the point is at (0, 0, 1) and it spreads out below that. It meets the x-y plane at the unit circle&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jtZdE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jtZdE.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am trying to reproduce with Python&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ax = plt.figure().gca(projection='3d')&#xA;xx, yy = np.meshgrid(np.arange(-1,1.1,.1), np.arange(-1,1.1,.1))&#xA;zz = 1 - np.sqrt(xx**2, yy**2)&#xA;ax.plot_surface(xx, yy, zz, alpha=.5)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and get this &quot;roof&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8n6z6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8n6z6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;each of xx, yy, zz is a 21 by 21 matrix, even if I increase them to 210 by 210, nothing changes, what am I missing?&lt;/p&gt;&#xA;" OwnerUserId="11312" LastEditorUserId="11312" LastEditDate="2019-10-15T02:12:56.527" LastActivityDate="2019-10-15T02:31:20.297" Title="Why does my code to plot a cone actually generate a roof?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9252" PostTypeId="2" ParentId="9251" CreationDate="2019-10-15T02:31:20.297" Score="2" Body="&lt;p&gt;You need to change the call to &lt;code&gt;sqrt&lt;/code&gt; from:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;np.sqrt(xx**2, yy**2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;to:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;np.sqrt(xx**2 + yy**2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Otherwise you're passing an array of values to the function and will be returned an array of values for the answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://numpy.org/devdocs/reference/generated/numpy.sqrt.html?highlight=sqrt#numpy.sqrt&quot; rel=&quot;nofollow noreferrer&quot;&gt;See here&lt;/a&gt; for details:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt; np.sqrt([1,4,9])&lt;/code&gt;&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;array([ 1.,  2.,  3.])&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="3003" LastActivityDate="2019-10-15T02:31:20.297" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9253" PostTypeId="1" AcceptedAnswerId="9257" CreationDate="2019-10-15T03:48:47.487" Score="0" ViewCount="46" Body="&lt;p&gt;this &lt;a href=&quot;https://math.stackexchange.com/q/3391749/673047&quot;&gt;figure&lt;/a&gt; (fig_1) is an univariate normal distribution in 3D, the corresponding equation is in the top left hand corner&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/11wRJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/11wRJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;it seems that x varies from -5 to 5; sigma varies from 0 to 4.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This Python code is trying to reproduce this figure&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ax = plt.figure().gca(projection='3d')&#xA;xx, yy = np.meshgrid(np.arange(-5,5,.1), np.arange(0.1,4,.1))&#xA;zz = norm.pdf(xx,0,yy)&#xA;ax.plot_surface(xx, yy, zz, alpha=.5)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;and I got this figure&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uIylt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uIylt.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and this guy&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;zz = norm.pdf(xx,0,np.sqrt(yy))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;gives this figure&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rXfBq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rXfBq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is better although the kurtosis looks a little higher than fig_1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;any clue&lt;/p&gt;&#xA;" OwnerUserId="11312" LastActivityDate="2019-10-15T21:01:23.373" Title="Why does my code generate a figure whose kurtosis looks a little higher than the one I am trying to reproduce?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9254" PostTypeId="2" ParentId="9238" CreationDate="2019-10-15T12:39:39.810" Score="1" Body="&lt;p&gt;You could try the &lt;a href=&quot;https://www.semanticscholar.org/paper/FiberMesh%3A-designing-freeform-surfaces-with-3D-Nealen-Igarashi/25b7f1b06e60a39113ebc25049e13b58f84fec1b&quot; rel=&quot;nofollow noreferrer&quot;&gt;FiberMesh&lt;/a&gt; technique. Fibermesh takes 3D input curves and interprets them as the contours of the surface. It then creates a smooth surface by using an optimization technique. &lt;a href=&quot;https://www.youtube.com/watch?v=OsOauFjnYSo&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt; you can see a video, which demonstrates the technique. &lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2019-10-15T12:39:39.810" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9256" PostTypeId="2" ParentId="9248" CreationDate="2019-10-15T17:53:48.767" Score="4" Body="&lt;p&gt;I solved my problem by adding a small value to t value when the ray is getting refracted.&#xA;But I still doubt the result is true. Below is the new generated photo:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jziQ0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jziQ0.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is the area light reflected twice on top of the sphere? Is there still a bug in my path tracer? The glass sphere is closer to the camera than the area light.&lt;/p&gt;&#xA;" OwnerUserId="11316" LastActivityDate="2019-10-15T17:53:48.767" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9257" PostTypeId="2" ParentId="9253" CreationDate="2019-10-15T21:01:23.373" Score="2" Body="&lt;p&gt;The value 's' in the original graph is the variance, which is the square of the Gaussian sigma (i.e. the scale parameter of the normal distribution). So &lt;code&gt;norm.pdf(xx,0,np.sqrt(yy))&lt;/code&gt; should be correct.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the shape of the peak you see is very much dependent on the y value where the graph starts. Your starting point of 0.1 may be a little smaller than in the original graph, which looks like it starts at about 1/6 ~= 0.167, so you may see a narrower and taller peak for that reason. Also, the original graph doesn't quite have enough horizontal resolution to resolve the shape of the peak entirely, as you can see from how far apart the grid lines are spaced vertically on the sides of the peak.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-10-15T21:01:23.373" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9258" PostTypeId="1" AcceptedAnswerId="9259" CreationDate="2019-10-16T08:01:50.303" Score="4" ViewCount="251" Body="&lt;p&gt;Question from the graphics newbie:&lt;br&gt;&#xA;What I know by now is that &quot;usually&quot; double buffering is used: &lt;br&gt;You calculate the content of frame x+1 while frame x is shown on the screen, if you want to achieve the maximum update rate, calculation must not take longer than one frame time, otherwise the &quot;drawing process&quot; is visible.&lt;br&gt;&#xA;So, having two framebuffers absolutely makes sense, and I guess that's why we have that &quot;glfwSwapBuffers&quot; call in some OpenGL tutorials.&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But what if I program my things in a way that every primitive leads to fragments that are horizontal lines, and let the GPU process it from top to bottom line &quot;on the fly&quot;?&lt;br&gt;&#xA;In this case I would need only one framebuffer that could be filled with a static background, and I would only have to store the other objects in some much smaller memory.&lt;br&gt;&#xA;Is this possible at all?&lt;br&gt;&#xA;Is there even any GPU implementation that does it that way to save memory?&lt;/p&gt;&#xA;" OwnerUserId="6346" LastActivityDate="2019-10-25T08:10:08.830" Title="Double buffering always necessary?" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9259" PostTypeId="2" ParentId="9258" CreationDate="2019-10-16T09:12:42.743" Score="7" Body="&lt;p&gt;Indeed there are/were 'just in time' renderers. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, Dreamcast (PowerVR CLX2) had a mode where the 'frame buffer' only had to be a few rows of tiles in size. The system would be rendering into one row while the display was reading out of some subset of the others. It would then cycle through the buffers. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to do this, however, you &lt;em&gt;do&lt;/em&gt; need a display-list rendering system. A standard 'immediate mode' renderer is not appropriate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, scene complexity needs to be considered carefully for this sort of scheme to work. In particular, if one tiny section of the screen contains particularly complex geometry, the renderer might not finish it in time before the display needs to read it. Allocating more memory for the partial screen buffer allows for more variability in scene complexity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also have a feeling/seem to recall some old (e.g 60s/70s?) flight simulators might have rendered 'on the fly' because memory (for a frame buffer) was once fiendishly expensive. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, the PowerVR PCX1/PXC2 ports of Tomb Raider had an optional single buffered rendering mode. (This was primarily because one of the guys doing the port (cough, me, cough) only had a 2MB 2D graphics card which could only allocate a single 1024x768 framebuffer).  Again, since the system was tile-based, it didn't suffer from the nasty artefacts you'd get with single buffering on a traditional Z-buffer system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;UPDATE:&#xA;FWIW there's another related question on &lt;a href=&quot;https://computergraphics.stackexchange.com/q/44/209&quot;&gt;&quot;Racing the Beam&quot; here&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-10-25T08:10:08.830" LastActivityDate="2019-10-25T08:10:08.830" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9260" PostTypeId="1" CreationDate="2019-10-16T13:06:17.903" Score="1" ViewCount="40" Body="&lt;p&gt;By googling, I have found some definition of &lt;em&gt;squared magnitude&lt;/em&gt; &lt;a href=&quot;https://www.youtube.com/watch?v=nl24ps-IZIU&quot; rel=&quot;nofollow noreferrer&quot;&gt;about mathematical plane applied in the gaming field&lt;/a&gt;, but I am dubting this is what we would mean in the noise generation's field. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;thanks for any hint&lt;/p&gt;&#xA;" OwnerUserId="11315" LastActivityDate="2019-10-16T13:06:17.903" Title="Concerning the Procedural noise's function, how would you define a squared magnitude in plain word?" Tags="&lt;noise&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9261" PostTypeId="1" CreationDate="2019-10-16T14:59:23.677" Score="1" ViewCount="185" Body="&lt;p&gt;I have a sampler variable in a shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; uniform sampler2DArray tiles;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which I am trying to bind to a texture unit in GL:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    int tilesUniformIndex = glGetUniformLocation(shaderProgramId,&quot;tiles&quot;);&#xA;    System.out.println(&quot;tiles: &quot;+tilesUniformIndex);&#xA;    glUseProgram(shaderProgramId);&#xA;    glok();  // &amp;lt;- This calls glGetError() and throws exception if not-ok&#xA;    glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);&#xA;    glok();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;TILE_TEXTURE_UNIT_INDEX&lt;/code&gt; is a constant defined to be zero.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The location is being correctly introspected, output is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; tiles: 7&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which is the correct binding location I expect in context of the shader source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glUniform.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;the documentation&lt;/a&gt;, this can only happen if the &lt;code&gt;count&lt;/code&gt; parameter is less than zero.  But &lt;code&gt;glUniform1i&lt;/code&gt; /doesn't have a count parameter/!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glUniform1iv(tilesUniformIndex, 1, new int[]{GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output &lt;code&gt;value&lt;/code&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, what gives?   Anyone know how this function can possibly behave like this?   This is a simple, correct use case, right?&lt;/p&gt;&#xA;" OwnerUserId="11322" LastEditorUserId="11322" LastEditDate="2019-10-16T15:09:41.047" LastActivityDate="2019-10-16T15:09:41.047" Title="Why is glUniform1i() returning GL_INVALID_VALUE?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9262" PostTypeId="1" AcceptedAnswerId="9276" CreationDate="2019-10-17T17:10:28.830" Score="3" ViewCount="459" Body="&lt;p&gt;In the context of render targets or textures, what does &quot;resolve&quot; mean?&#xA;For example: To resolve a color texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From my understanding, it seems to mean, &quot;copy but process/convert at the same time&quot;, but I can't seem to find a good definition for it anywhere.&lt;/p&gt;&#xA;" OwnerUserId="6987" LastEditorUserId="2479" LastEditDate="2019-10-24T12:43:28.003" LastActivityDate="2019-11-04T23:19:25.093" Title="What does texture resolve mean?" Tags="&lt;texture&gt;&lt;image-processing&gt;&lt;sampling&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9264" PostTypeId="2" ParentId="9237" CreationDate="2019-10-18T05:41:30.960" Score="1" Body="&lt;p&gt;The Kinect SDK has a skeletal tracking demo in the c++ api (BodyBasics). The skeleton you get is the same &quot;topology&quot; unless it fails to acquire the skeleton. So you can easily compare the left shoulder of two captures as you always know which point it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You'll have to experience with metrics. A simple point to point metric would probably be sufficient though. Maybe with some weights on different body parts though.&lt;/p&gt;&#xA;" OwnerUserId="113" LastActivityDate="2019-10-18T05:41:30.960" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9265" PostTypeId="1" AcceptedAnswerId="9266" CreationDate="2019-10-18T17:02:57.463" Score="0" ViewCount="89" Body="&lt;p&gt;I am trying to implement next event estimation to reduce the noise of path tracer and I need a pseudocode. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: I know how to sample direct illumination but the visibility function is the real problem I face. How to code the visibility function without iterating over the objects in the scene?&lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-10-18T19:25:20.697" LastActivityDate="2019-10-18T20:36:19.130" Title="How can I implement next event estimation?" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9266" PostTypeId="2" ParentId="9265" CreationDate="2019-10-18T20:36:19.130" Score="1" Body="&lt;p&gt;You can provide an &lt;code&gt;intersect_any(ray, scene, min_t, max_t)&lt;/code&gt; function, that returns true at the first intersection. So it has the option to exit early compared to the usual &lt;code&gt;intersect&lt;/code&gt; function. Additionally you do not care about normals, texture coordinates, positions, so you can avoid computing those in many cases. You need &lt;code&gt;max_t&lt;/code&gt; though to limit the ray to the segment between the two points you are testing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the worst case scenario (there is nothing between the two points) you will still need to iterate over all objects unless you are using acceleration structures.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-10-18T20:36:19.130" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9267" PostTypeId="1" CreationDate="2019-10-18T21:01:55.893" Score="0" ViewCount="56" Body="&lt;p&gt;In 2d, matplotlib plots all 4 edges(spines) of a figure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xqSsr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xqSsr.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 3d, matplotlib plots 9 out of 12 edges of a cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IbLwG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IbLwG.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to set visible and color for all 12 edges(spines) of a cube in 3d?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried &lt;code&gt;ax.xaxis._axinfo['juggled'] = (2,0,1)&lt;/code&gt; and found that is something live move instead of setting visible or color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also tried &lt;code&gt;ax.collections&lt;/code&gt;, didn't work either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any clue?&lt;/p&gt;&#xA;" OwnerUserId="11312" LastActivityDate="2021-02-23T09:03:05.337" Title="Is it possible to set visible and color for all 12 edges(spines) of the figure (cube) in matplotlib?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9268" PostTypeId="1" AcceptedAnswerId="9269" CreationDate="2019-10-19T03:59:33.723" Score="1" ViewCount="135" Body="&lt;p&gt;Quoting the Khronos OpenGL &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetProgramResource.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation pages&lt;/a&gt; for the &lt;code&gt;glGetProgramResourceiv()&lt;/code&gt; function:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;For the property GL_TYPE, a single integer identifying the type of an&#xA;  active variable is written to params. The integer returned is one of&#xA;  the values found in table 2.16.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But, there is no &quot;table 2.16&quot; in that page, there is no &quot;table 2.16&quot; in the specification document (where the language also appears), and several search engines failed to return any other references to such a table.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, where is it?   What are the full list of type codes that can be returned by this introspection function (which can presumably represent all GLSL types)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I'm using GL core 4.3)&lt;/p&gt;&#xA;" OwnerUserId="11322" LastActivityDate="2019-10-21T16:59:14.967" Title="What are the type constants that the documentation for glGetProgramResourceiv() refers to?" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9269" PostTypeId="2" ParentId="9268" CreationDate="2019-10-19T05:02:39.043" Score="1" Body="&lt;p&gt;For whatever reason, the text for that function documentation was copied from the GL_ARB_program_interface_query extension. Extensions in OpenGL are always defined relative to a specific version of the OpenGL specification. So if an extension references something in a specification, it's talking about that version of the spec.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the OpenGL specification was &lt;em&gt;massively&lt;/em&gt; restructured between 4.2 and 4.3, with whole chapters moved around. This means that table references in 4.2 become completely wrong relative to 4.3 and above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Program interface query was written against the 4.2 specification. Oddly enough, there is no table 2.16 in that spec; the correct number for that table is 2.13 (so it's likely a typo, since 3 is right below 6 on a number-pad). But even if the extension did mention the right table number, that table moved to a whole different chapter in 4.3+ versions. It's been renumbered and moved since then, so you'll have to look at a particular specification's definition of &lt;code&gt;glGetProgramResourceiv&lt;/code&gt; to find it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In general, if you find something incongruous in the documentation pages, you should look at the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/index_gl.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;actual OpenGL specification&lt;/a&gt; to see what it says about the function's behavior. In this particular case, the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/GLAPI/glGetProgramResource&quot; rel=&quot;nofollow noreferrer&quot;&gt;docs in the OpenGL wiki&lt;/a&gt; for this function actually includes the table.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2019-10-21T16:59:14.967" LastActivityDate="2019-10-21T16:59:14.967" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9271" PostTypeId="1" CreationDate="2019-10-20T07:35:18.097" Score="0" ViewCount="67" Body="&lt;p&gt;I have the following problem. &lt;a href=&quot;https://en.wikipedia.org/wiki/3D_projection#Perspective_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;Perspective projection&lt;/a&gt; is often referred to when talking about camera models. I don’t think I understand it very well though this concept is taught when I was at junior high or even primary school. I think programmers with a computer vision background may be familiar with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read quite some “tutorials” on perspective projection, also computer vision textbooks like “Computer Vision: Algorithms and Applications”, “Multiple View Geometry in Computer Vision:Second Edition”. But the representation conventions seems to be quite a lot. It’s a little bit unfriendly to beginners. Just to get a feeling, here’s one of them:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/xmQtT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;example formula&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;May I ask if there’s some good, easy-to-read and self-contained articles that can help beginners like me understand perspective projection? It may explains quite clearly the physical meaning of the parameters of it, especially the “scale factor”.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas? Thanx in advance.&lt;/p&gt;&#xA;" OwnerUserId="11356" OwnerDisplayName="fatestayn" LastEditorUserId="209" LastEditDate="2019-10-23T10:12:26.257" LastActivityDate="2019-10-23T10:12:26.257" Title="Issue with perspective projection" Tags="&lt;perspective&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9272" PostTypeId="1" CreationDate="2019-10-20T11:06:41.020" Score="1" ViewCount="101" Body="&lt;p&gt;Is my understanding of MIS algorithm true?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I first generate a random number &lt;span class=&quot;math-container&quot;&gt;$x\in U(0,1)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$w_1=\frac{p_1(direct)}{p_1(direct)+p_2(hemisphere)}$&lt;/span&gt;, and then if &lt;span class=&quot;math-container&quot;&gt;$x &amp;lt; w_1$&lt;/span&gt; generate the sample directly from the light source, otherwise generate the sample randomly on the unit hemisphere around the hit point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And what should I do if the randomly generated samples on the hemisphere hit the light source? &lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-10-20T11:20:08.323" LastActivityDate="2019-10-20T11:20:08.323" Title="How does multiple importance sampling work and how should I generate the samples?" Tags="&lt;raytracing&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9273" PostTypeId="1" AcceptedAnswerId="9280" CreationDate="2019-10-20T11:42:49.337" Score="1" ViewCount="96" Body="&lt;p&gt;I'm trying to force perspective into the horizon of a Shadertoy scene by drawing horizontal lines at decreasing distances as y grows to create an outrun-esque scene, but can't figure out which functions to use. I know the spaces need to be asymptotic up to uv.y/2, and thought I could use a combination of smoothstep and modulo like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (mod(smoothstep(-0.07, 2.0, uv.y/1.5), 0.03) &amp;lt; 0.001) {&#xA;    fragColor = vec4(1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This does work, but the lines start wide and quickly become constant width rather than getting smaller. I'd like to offset these lines with iTime so will need to modulo that as well (eg below), but in other tests I get an effect which is nearly correct but the lines bug and either don't draw sometimes, or draw too thick. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (mod(round(fragCoord.y+mod(iTime*150.0, 500.0)), iResolution.y/2.0-fragCoord.y) &amp;lt; 10.0) {&#xA;        fragColor = 1.0;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Am I on the right lines?&lt;/p&gt;&#xA;" OwnerUserId="11335" LastActivityDate="2019-10-25T01:33:55.150" Title="GLSL - increasing line spacing with y" Tags="&lt;opengl&gt;&lt;shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9275" PostTypeId="1" CreationDate="2019-10-21T21:31:47.777" Score="1" ViewCount="161" Body="&lt;p&gt;I would like to intuitively understand the &lt;a href=&quot;https://en.wikipedia.org/wiki/Path_tracing#Algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Path Tracing&lt;/a&gt; equation/formula/pseudocode, but I'm not fully getting the last &lt;code&gt;return&lt;/code&gt; statement.&#xA;As per Wikipedia page:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Probability of the newRay&#xA;const float p = 1/(2*M_PI);&#xA;// Compute the BRDF for this ray (assuming Lambertian reflection)&#xA;float cos_theta = DotProduct(newRay.direction, ray.normalWhereObjWasHit);&#xA;Color BRDF = material.reflectance / M_PI ;&#xA;...&#xA;// Apply the Rendering Equation here.&#xA;return emittance + (BRDF * incoming * cos_theta / p);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I would understand:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;em&gt;p&lt;/em&gt; is the probability of new ray (not quite sure what this means), though it's &lt;code&gt;1 / (2 * PI)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;cos_theta&lt;/em&gt; is the angle between the normal of a given surface and the &lt;em&gt;incoming&lt;/em&gt; ray&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;BRDF&lt;/em&gt; is the material colour divided by &lt;code&gt;PI&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;After computing the &lt;em&gt;incoming&lt;/em&gt; colour, we add the &lt;em&gt;emittance&lt;/em&gt; component with the &lt;em&gt;Lambertian&lt;/em&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I would interpret the second part of the return statement as:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Reflect current colour based on how much is incoming &lt;code&gt;BRDF * incoming&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&quot;Weight&quot; it by the angle (rays that are next to the &lt;em&gt;normal&lt;/em&gt; would reflect more colour, energy) &lt;code&gt;* cos_theta&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;But then we &lt;code&gt;/ p&lt;/code&gt;, which if we consider the &lt;em&gt;BRDF&lt;/em&gt;, removed the PI component and leave a factor of &lt;strong&gt;2&lt;/strong&gt; (&lt;code&gt;BRDF / p = material.reflectance / M_PI * (2 * M_PI) = material.reflectance * 2&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Why is there such factor of &lt;strong&gt;2&lt;/strong&gt;?&#xA;What is the most logical explanation to this?&lt;/p&gt;&#xA;" OwnerUserId="11346" LastActivityDate="2019-10-21T21:31:47.777" Title="Why does the reflected component in Lambertian path tracing get multiplied by a factor of 2?" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;mathematics&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9276" PostTypeId="2" ParentId="9262" CreationDate="2019-10-22T11:02:20.180" Score="3" Body="&lt;p&gt;I don't know about other contexts, but for DirectX resolving a texture means blending multi-sampled texture into a non-multisampled one. For simple scenarios this is usually done automatically by the output merger, but is often needed to be done explicitly (e.g. &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-resolvesubresource&quot; rel=&quot;nofollow noreferrer&quot;&gt;ResolveSubresource&lt;/a&gt;) when using multi-sampled render target as an input for a next render pass (e.g. post-processing). Reasons being both performance and lower complexity of the following pass shaders.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2019-11-04T23:19:25.093" LastActivityDate="2019-11-04T23:19:25.093" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9277" PostTypeId="2" ParentId="9262" CreationDate="2019-10-22T16:11:34.400" Score="2" Body="&lt;p&gt;Perhaps some example usage from graphics papers might be helpful - it basically refers to computing a 'pixel' value potentially from multiple fragments...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;RealityEngine Graphics  (Akeley. 1993)&lt;/strong&gt; &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Thus the image is complete as soon as the last primitive&#xA;  has been rendered; there is no need for a final framebuffer operation&#xA;  to &lt;em&gt;resolve&lt;/em&gt; the multiple color samples at each pixel location to a&#xA;  single displayable color.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Hardware Accelerated Rendering Of Antialiasing Using A Modified A-buffer Algorithm. (Winner et al, 1997)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Pixels which are completely covered by opaque objects are &lt;em&gt;resolved&lt;/em&gt;&#xA;  in a single pass.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;or &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Otherwise multiple passes are required to &lt;em&gt;resolve&lt;/em&gt; the final color&#xA;  for each pixel in the scene.&#xA;  &lt;br/&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;A Directionally Adaptive Edge Anti-Aliasing Filter. (Iourcha et al, 2009)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Downsampling is performed by a &lt;em&gt;resolve&lt;/em&gt;, which is the aggregation of the samples with filtering.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-10-23T07:42:53.330" LastActivityDate="2019-10-23T07:42:53.330" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9280" PostTypeId="2" ParentId="9273" CreationDate="2019-10-25T01:33:55.150" Score="1" Body="&lt;p&gt;We tackle this problem by computing, like shaders do, the color of a certain pixel with position &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; at timestamp &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;, namely &lt;span class=&quot;math-container&quot;&gt;$I_{x, y}(t)$&lt;/span&gt;. All we want to know if that pixel must draw a bar on timestamp &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;. So simple as that, we start with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float horizon = 0.5;&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord ) &#xA;{&#xA;   // Normalized pixel coordinates (from 0 to 1)&#xA;   vec2 uv = fragCoord / iResolution.xy;&#xA;&#xA;   float position = uv.y;&#xA;   float time = iTime;&#xA;&#xA;   // everything above our horizon we make white&#xA;   if (position &amp;gt; horizon - 0.01) {&#xA;      fragColor = vec4(1.0);&#xA;      return;&#xA;   }&#xA;&#xA;   // check if pixel is on the bar, and if so color it white.&#xA;   float color = isOnBar(time, position);&#xA;&#xA;   fragColor = vec4(color, color, color, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Next step is to determine whether that pixel actually is on the bar.&#xA;This problem can be solved with the rules of gravity. We visualize the bars falling down from the horizon. For any pixel &lt;span class=&quot;math-container&quot;&gt;$I_{x, y}$&lt;/span&gt;, we can say the pixel is on the first bar if&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$h_{bar}(t) = I_{y}(t)$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;We know however that bars fall with gravity from the horizon, so:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$h_{bar}(t) = h_{horizon} - gt^{2}$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence, the falling time &lt;span class=&quot;math-container&quot;&gt;$ t_{\text{fall}} $&lt;/span&gt;, when the bar hits the pixel, can be calculated with &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$ t_{\text{fall}} = \sqrt{ \frac{h_{horizon} - I_{y}(t_{\text{fall}})}g } $&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this was just our first bar. Any other time a bar hitting that pixel, is when &lt;span class=&quot;math-container&quot;&gt;$ &#xA;(t - t_{\text{fall}}) \bmod a = 0 $&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$ a $&lt;/span&gt; is our falling frequency. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;e.g. first bar hits a pixel after 3 seconds, and every 2 seconds another bar falls, then for instance on the 7th second a bar again hits our pixel: &lt;span class=&quot;math-container&quot;&gt;$ (7 - 3) \bmod 2 $&lt;/span&gt; is indeed &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;.&lt;/em&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How much room we give when computing that modulo close to zero, is the width of our bar. Right now, we can incorporate the widening of the bars when they drop. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float gravity = 0.1;&#xA;float timeBetweenBars = 0.5; &#xA;&#xA;float isOnBar(float time, float position) {&#xA;   float timeOfHit = sqrt((horizon - position) / gravity);&#xA;   float moddedTime = mod(time - timeOfHit, timeBetweenBars);&#xA;&#xA;   // the lower the pixel, the more room we give to catching the bar with this pixel.&#xA;   if (moddedTime &amp;lt; 0.1 * (1.0 - position)) {&#xA;      return 1.0;&#xA;   };&#xA;   return 0.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/tscXD4&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here is the code on ShaderToy&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IIqXa.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IIqXa.gif&quot; alt=&quot;Horizon Outrun-esque scene&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7955" LastActivityDate="2019-10-25T01:33:55.150" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9281" PostTypeId="2" ParentId="9174" CreationDate="2019-10-26T13:27:00.077" Score="1" Body="&lt;p&gt;I would write an algorithm where you would iteratively fill lines into rectangles and create a rectangle merging and splitting procedure based on area and thickness. I will use the following image as an example image for the algorithm:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FYSIUs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FYSIUs.png&quot; alt=&quot;base image wall thickness decomposition&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;&#xA;Find all the uninterrupted horizontal and vertical lines in the image. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ISiSxs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ISiSxs.png&quot; alt=&quot;all horizontal uninterrupted lines&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/n3VYMs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n3VYMs.png&quot; alt=&quot;all vertical uninterrupted lines&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In python you would do something like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def horizontal_longest_lines(im):&#xA;   counts = {}&#xA;   on_a_line = False&#xA;   line = None&#xA;   for row_index, row in enumerate(im):&#xA;       for col_index, pixel in enumerate(row):&#xA;           coord = (row_index, col_index)&#xA;           if not pixel:&#xA;               on_a_line = False&#xA;               line = None&#xA;               continue&#xA;           if pixel:&#xA;               if not on_a_line:&#xA;                   on_a_line = True&#xA;                   line = (coord, coord)&#xA;                   counts[line] = 1&#xA;               else:&#xA;                   current = counts[line]&#xA;                   del counts[line]&#xA;                   line = (line[0], coord)&#xA;                   counts[line] = current + 1&#xA;   return counts&#xA;&#xA;def vertical_longest_lines(im):&#xA;   counts = horizontal_longest_lines(im.transpose())&#xA;   new_counts = {}&#xA;   for key in counts:&#xA;      new_counts[(key[0][::-1], key[1][::-1])] = counts[key]&#xA;   return new_counts&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt; fill the area around the lines to create rectangles from the lines:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/O4pk5s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/O4pk5s.png&quot; alt=&quot;from line to rectangle for wall thickness decomposition algorithm&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Mp8Zds.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mp8Zds.png&quot; alt=&quot;from line to rectangle for wall thickness decomposition algorithm&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/JN7Q9s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JN7Q9s.png&quot; alt=&quot;from line to rectangle for wall thickness decomposition algorithm&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cdchjs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cdchjs.png&quot; alt=&quot;from line to rectangle for wall thickness decomposition algorithm&quot;&gt;&lt;/a&gt; etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a more efficient algorithm, you could improve this step by trying to merge existing lines into rectangles. But that would probably a bit more complicated to write.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt; Since some lines will create the same rectangle, these duplicate rectangles need to be removed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt; Find overlapping rectangles, give preferences to rectangles that have a bigger area. Cut off the overlapping part from the smaller rectangle.&#xA;For these two rectangles:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AwUWOs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AwUWOs.png&quot; alt=&quot;overlapping rectangles&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SePJ7s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SePJ7s.png&quot; alt=&quot;overlapping rectangles&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result would then be:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HE6A1s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HE6A1s.png&quot; alt=&quot;split rectangles algorithm&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt; Some edge cases can happen, where the resulting cut-off does not result in a new rectangle. For these cases, split the resulting shape in new rectangles.&#xA;For instance in this case:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KfojYs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KfojYs.png&quot; alt=&quot;edge case wall splitting&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SbGUHs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SbGUHs.png&quot; alt=&quot;edge case wall splittinge&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/b0y2Ys.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/b0y2Ys.png&quot; alt=&quot;edge case wall splitting&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/z3ibYs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/z3ibYs.png&quot; alt=&quot;edge case wall splitting&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do note, there are two possibilities here in splitting up the resulting shape. You would need to fine-tune this process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt; Merge rectangles that have exactly the same width as the other rectangle's height and are touching each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All  the resulting rectangles are now the decomposed walls by thickness:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iOYp4s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iOYp4s.png&quot; alt=&quot;result wall thickness decomposition algorithm&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7955" LastActivityDate="2019-10-26T13:27:00.077" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9282" PostTypeId="1" AcceptedAnswerId="9309" CreationDate="2019-10-26T16:33:42.110" Score="2" ViewCount="217" Body="&lt;p&gt;I am trying to calculate the derivatives of a sampled data set by following an example in &lt;a href=&quot;https://books.google.co.uk/books/about/Data_Visualization.html?id=GPwYCwAAQBAJ&amp;amp;printsec=frontcover&amp;amp;source=kp_read_button&amp;amp;redir_esc=y#v=onepage&amp;amp;q=%20gllightfv&amp;amp;f=false&quot; rel=&quot;nofollow noreferrer&quot;&gt;this book&lt;/a&gt;. The data is a set of 2d quads(green area in below) and their vertices(4 each). The data is in the following example is sampled from &lt;span class=&quot;math-container&quot;&gt;$z=f(x,y)=e^{-(x^2+y^2)}$&lt;/span&gt; but, in general, the underlying function might not be known.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ySAtb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ySAtb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The book states that the derivatives of any points are calculated by:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iHqWJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iHqWJ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KdZ65.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KdZ65.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; are the quadrilateral basis functions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/opYtc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/opYtc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xrwjd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xrwjd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can calculate df/dx and df/dy. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But where I struggle is calculating df/dz. I assume&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YKxwY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YKxwY.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;and therefore df/dz = 0. But this cannot be correct since df/dz should be 1(by making the above analytic function implicit and differentiating it for z).&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="209" LastEditDate="2019-10-30T11:31:46.907" LastActivityDate="2019-11-08T17:44:55.533" Title="computing derivatives of sampled data" Tags="&lt;sampling&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9283" PostTypeId="1" CreationDate="2019-10-27T11:46:28.953" Score="0" ViewCount="51" Body="&lt;p&gt;I am trying to reproduce the results of 2017 paper &quot;Learning the light transport the reiforced way&quot; by Duhm and Keller. I already know how to generate random samples inside the equally-sized patches on sphere. The normal of hemisphere around the hit point is along z-axis. And each ray direction generated by:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$d = (sin(\phi)cos(\theta), sin(\phi)sin(\theta), cos(\phi))$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How could I apply rotations to this vectors by only knowing normals? Should I apply the rotations to patches or rays. For example, imagine the surface is a sphere and not a plane. I'm really confused how to do this!&lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-10-27T11:52:13.910" LastActivityDate="2019-10-27T11:52:13.910" Title="The correct way to apply 3d rotations?" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9284" PostTypeId="1" AcceptedAnswerId="9285" CreationDate="2019-10-27T21:09:48.447" Score="0" ViewCount="331" Body="&lt;p&gt;Given the up and focal vector of the perspective camera, the position of the camera and the vertical and horizontal opening angle of the FOV. How can I calculate a ray for given screen space coordinates (x, y) where x, y are between -1 and 1 (inclusive).&#xA;I tried this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) Calculate the vectors sx, sy that span the image plane&lt;/p&gt;&#xA;&#xA;&lt;p&gt;sy = -norm(up)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;sx = norm(cross(focal, sy))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Calculate the focal length f&lt;/p&gt;&#xA;&#xA;&lt;p&gt;f = 1 * sin(90 - vertical) / sin(vertical) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) Create the ray&lt;/p&gt;&#xA;&#xA;&lt;p&gt;dir = (center + x * sx + y * sy + f * forward) - center&lt;/p&gt;&#xA;&#xA;&lt;p&gt;r(t) = center + t * norm(dir)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But the resulting image does not turn out like the reference image. Someone know what I am doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="11375" LastActivityDate="2019-10-27T22:43:05.430" Title="Perspective Raytracing" Tags="&lt;raytracing&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9285" PostTypeId="2" ParentId="9284" CreationDate="2019-10-27T22:37:55.493" Score="0" Body="&lt;p&gt;Let the horizontal FOV be given as theta (in radians), and the vertical FOV be given as phi (in radians). The we know that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\tan\frac{\theta}{2}=\frac{w}{f}, \tan\frac{\phi}{2}=\frac{h}{f}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us pick &lt;span class=&quot;math-container&quot;&gt;$f = 1$&lt;/span&gt;, then &lt;span class=&quot;math-container&quot;&gt;$w = \tan\frac{\theta}{2}, h = \tan\frac{\phi}{2}$&lt;/span&gt;. Now your ray generation direction generation formula looks like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\pmb{d} = x w\pmb{u} + yh\pmb{v} + \pmb{w}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$\pmb{u},\pmb{v}, \pmb{w}$&lt;/span&gt; are your sx,sy, forward vectors. Essentially, I found the extent of the smallest/largest x and y respectively (&lt;span class=&quot;math-container&quot;&gt;$1w = w, -1w=-w$&lt;/span&gt;, etc.). You can premultiply &lt;span class=&quot;math-container&quot;&gt;$\pmb{u}, \pmb{v}$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$w, h$&lt;/span&gt; respectively, if you don't want to perform the multiplication per ray.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2019-10-27T22:43:05.430" LastActivityDate="2019-10-27T22:43:05.430" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9287" PostTypeId="1" CreationDate="2019-10-29T01:46:47.810" Score="3" ViewCount="104" Body="&lt;p&gt;I'm posting here after some time searching the Internet and reading presentations and papers, to find out the best options to solve the problem I have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm implementing irradiance field with spherical harmonics for diffuse global illumination. As any other developer, I'm facing the typical problem of not having enough lit probes to properly approximate irradiance in some parts of the scene, due to the fact that sometimes those irradiance fields are in shadow and therefore don't receive any light. Let's assume the irradiance fields are set in an uniform grid, and that there's no artist to tweak the position of those irradiance fields to avoid them falling in shaded areas.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's use the picture I uploaded as example. In this picture, the green dots represent irradiance fields which are receiving light, and the black ones, irradiance fields which are not receiving light, because of the red plane puts them in shadow (we can think of the red plane as a wall or floor).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem I have is to properly approximate the irradiance at the red plane, since the four irradiance fields in shadow will make the irradiance at the wall darker than it is because of the transition from lit to unlit irradiance fields (I'm using trilinear interplation between the eight irradiance fields surrounding each world position).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The closest option to solve this problem I've found is to use &quot;Irradiance Gradients&quot; (&lt;a href=&quot;https://developer.amd.com/wordpress/media/2012/10/Tatarchuk_Irradiance_Volumes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.amd.com/wordpress/media/2012/10/Tatarchuk_Irradiance_Volumes.pdf&lt;/a&gt;), but I'm not sure this is the only / best option, so I'm wondering, does anyone recommend this / another way to solve the problem?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Many thanks for your time and help,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alex&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IofC8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IofC8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11385" LastActivityDate="2019-10-29T15:58:55.387" Title="Irradiance field approximation with black probes" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;global-illumination&gt;&lt;shading&gt;&lt;interpolation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9291" PostTypeId="1" CreationDate="2019-11-02T18:52:25.683" Score="0" ViewCount="24" Body="&lt;p&gt;To calculate the cartesian coordinates for scattering rays over a hemisphere based on cosine-weighted importance sampling, one method can be to obtain the marginal and conditional PDF for the polar coordinates &lt;span class=&quot;math-container&quot;&gt;$\varphi$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt;.&#xA;Following the whole procedure, I obtained:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ p(\theta) = \int_0^{2\pi} p(\theta, \varphi) \mathrm{d}\varphi = \int_0^{2\pi} p(w) \ sin\theta d\phi = 2 \, \pi \, sin \theta \, f(\theta) = 2 sin\theta cos\theta  $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$  p(\varphi) = \frac{p(\theta, \varphi)}{p(\theta)} = \frac{1}{2\pi} $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; is the solid angle and &lt;span class=&quot;math-container&quot;&gt;$f(\theta) = \frac{cos\theta}{\pi}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, every book explains how to draw samples based on &lt;span class=&quot;math-container&quot;&gt;$p(\theta)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p(\varphi)$&lt;/span&gt; from a uniform random generator &lt;span class=&quot;math-container&quot;&gt;$\xi$&lt;/span&gt;.This is obtained calculating the CDF for both distributions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why is this last step necessary? Is it because it's efficient/convenient in coding, since there are uniform random generators already implemented in the majority of libraries? Thanks&lt;/p&gt;&#xA;" OwnerUserId="10191" LastActivityDate="2019-11-02T18:52:25.683" Title="Drawing non-uniform samples from uniform density" Tags="&lt;sampling&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9292" PostTypeId="1" AcceptedAnswerId="9293" CreationDate="2019-11-02T22:18:30.457" Score="1" ViewCount="47" Body="&lt;p&gt;In my procedurally generated mesh in Unity, not all vertices are vertexes of all neighbouring triangles - essentially, it's a grid with cells of varying sizes. This is messing up the calculation of normals however, making the lightning not smooth. How should I account for this? This is a part of the mesh to illustrate what I mean, in shaded wireframe and shaded mode:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CtwSH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CtwSH.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/8vTR6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8vTR6.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11409" LastActivityDate="2019-11-02T22:55:57.767" Title="Calculating normals for vertices which aren't a vertex of all neighbouring triangles" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9293" PostTypeId="2" ParentId="9292" CreationDate="2019-11-02T22:55:57.767" Score="3" Body="&lt;p&gt;For the shading to match, the normals (and any other vertex attributes) of the small triangles' verts would have to match the linear interpolation along the large triangle edge that they adjoin to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example: all the vertices in the green box below would need to be set by interpolating between the two blue vertices, based on their position along that edge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As Nicol alluded to however, you may not get perfectly watertight rendering—or a perfect match in the shading—when constructing a mesh with &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1461/why-do-t-junctions-in-meshes-result-in-cracks&quot;&gt;T-junctions&lt;/a&gt; like this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/pJ6zm.png&quot; alt=&quot;wireframe marked with vertices&quot;&gt;]&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-11-02T22:55:57.767" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9294" PostTypeId="1" AcceptedAnswerId="9296" CreationDate="2019-11-03T19:38:47.023" Score="1" ViewCount="157" Body="&lt;p&gt;I am having the following issue. I am working on a ray tracer for school and I am trying to render a sphere where the radiance of a intersection point is the dot product of the ray direction and the normal at the point of intersection. This works fine if return the inverted normal ( i.e. a vector going from the intersection point to the center of the sphere but not the other way around as it should be ) and I can't figure out what I messed up. Anyone have a intuitive clue on what I could have messed up? Can't really post code here as it's a school task but feel free to ask for further information and I am trying to provide as best as I can. (left: inverted normals, right: right normals)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/shvDJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/shvDJ.png&quot; alt=&quot;inverted_normals&quot;&gt;&lt;/a&gt;&lt;a href=&quot;https://i.stack.imgur.com/9ZwI2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9ZwI2.png&quot; alt=&quot;right normals&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;" OwnerUserId="11375" LastActivityDate="2019-11-03T20:33:07.540" Title="Inverted Normals in Raytracer" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9295" PostTypeId="2" ParentId="9294" CreationDate="2019-11-03T20:29:41.323" Score="0" Body="&lt;p&gt;When you take the dot product of two unit vectors, you are essentially calculating the cosine of the angle between them. This value can become negative when the two vectors are less than 90 degrees apart (which they are when you have outward normals).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Negate the normal before dotting it. That way you can have outward facing normals and also correct shading.&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-11-03T20:29:41.323" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9296" PostTypeId="2" ParentId="9294" CreationDate="2019-11-03T20:33:07.540" Score="2" Body="&lt;p&gt;The issue is, that you considered that the rays coming from the camera to be the light carrying rays. Instead, the rays bounce off the surface, and return to the light source (which you have decided to position at the camera). This means that your light direction is not &lt;span class=&quot;math-container&quot;&gt;$\pmb{d}$&lt;/span&gt; but rather &lt;span class=&quot;math-container&quot;&gt;$-\pmb{d}$&lt;/span&gt;, then &lt;span class=&quot;math-container&quot;&gt;$\cos\theta = - \pmb{d} \cdot \pmb{n}$&lt;/span&gt;, provided that both vectors are normalized.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, you really want to try to retirn the correct normal, as it is, your current code will return the wrong normal if the camera is inside the sphere. So your normal should be:&#xA;&lt;code&gt;n = dot(n,d)&amp;lt;0 ? n : -n;&lt;/code&gt;, where &lt;code&gt;n&lt;/code&gt; is the normal returned by your surface, and &lt;code&gt;d&lt;/code&gt; is the ray direction for the ray that intersected the surface.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-11-03T20:33:07.540" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9297" PostTypeId="1" AcceptedAnswerId="9301" CreationDate="2019-11-04T13:13:57.837" Score="2" ViewCount="556" Body="&lt;p&gt;If I'm not mistaken, you can make a hybrid renderer which lets a rasterizer solve the visibility problem, then shade all of the projected shapes with a raytracing algorithm. It seems that this isn't commonly done however, what's the reason for that? Oversight?&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-11-05T09:22:21.057" Title="Why isn't rasterization combined with raytracing more often?" Tags="&lt;raytracing&gt;&lt;rendering&gt;" AnswerCount="4" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9298" PostTypeId="2" ParentId="9297" CreationDate="2019-11-04T15:39:27.347" Score="1" Body="&lt;p&gt;There are renderes that do this. Most notably Pixars Renderman prefers to work this way. Hybrid renderers can work in other ways too...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It used to be that hybrid renderers like this were quite common, they still are somewhat  in software only implementations. They are slowly being replaced though by a new breed of trace only renderes though. Mostly the reason is that by foregoing the other you get a simpler piece of code.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2019-11-04T15:39:27.347" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9299" PostTypeId="2" ParentId="9297" CreationDate="2019-11-04T16:28:57.627" Score="0" Body="&lt;p&gt;Because when you test the visibility of a fragment during rasterization you already know (or can easily calculate) all the details that raytracing will give you.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So doing the ray-triangle collision calculation is redundant.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it is the additional lighting beyond the first hit where raytracing is helpful. However each ray is only a small part of what contributes to the lighting in a scene, so you need a lot of them per fragment. And each ray has relatively large cost to compute. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Those two properties make raytracing not very atractive for real-time rendering without some dedicated acceleration.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-11-04T16:28:57.627" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9300" PostTypeId="2" ParentId="9297" CreationDate="2019-11-04T17:29:57.407" Score="3" Body="&lt;p&gt;Rasterization is sometimes used for primary rays. However, it limits greatly what you can do - depth of field, motion blur, participating media, refraction, only basic camera models, no adaptive or custom sampling, etc.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-11-04T17:29:57.407" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9301" PostTypeId="2" ParentId="9297" CreationDate="2019-11-05T09:22:21.057" Score="1" Body="&lt;p&gt;&lt;em&gt;Disclosure: I work for &lt;a href=&quot;https://stackoverflow.com/jobs/companies/imagination-technologies&quot;&gt;IMG/PowerVR&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Indeed there are rendering systems that can do this: Imagination demonstrated hybrid rendering on their &quot;Wizard&quot; &lt;a href=&quot;https://www.imgtec.com/blog/imagination-technologies-the-ray-tracing-pioneers/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing/Rasterisation&lt;/a&gt; system. Scroll down to &quot;Making ray tracing happen&quot; and there is a screen grab of a hybrid demo.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As others have mentioned, there are pros and cons: Some advantages include that rasteriser can be extremely efficient at handling the first set of intersections and, for shadows, you don't spend effort pre-rendering portions of shadow maps that may never be visible in the final render. On the downsides, you are typically constrained to the standard pinhole camera model. &lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2019-11-05T09:22:21.057" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9303" PostTypeId="1" CreationDate="2019-11-05T18:25:36.750" Score="2" ViewCount="148" Body="&lt;p&gt;So I'm making a 2D pool game in OpenGL (you might've guessed as soon as I've mentioned collision of circles). I'm having a little trouble with collision detection. What I mean by that is that I have an algorithm that currently works but I'm thinking of improving it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far I've used discrete collision detection, disregarding the possibilities that it might not work at high velocities. However, I've noticed that I in fact sometimes do need the circles (pool balls) to travel at velocities at which the discrete collision detection might fail. The reason for that is that some of those velocities are quite realistic in a real-life game of pool (I've calculated that an average professional break shot in pool can make the ball travel as fast as six times the ball's diameter per 33 milliseconds which is the time interval that one frame lasts on 30FPS machines). Therefore in every such shot my discrete collision detection is very likely to fail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the idea I've had:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The dashed circles represent the positions of the balls in the previous frame. The lines from them represent the velocity vectors and, obviously, the circles that they're connected to are their positions in the current frame. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One thing I would do immediately is check whether the velocity vectors are collinear in which case there's no need to check for any kind of collision. If they're not collinear, I'd find the intersection point of the line segments represented by the points of previous position and the next position (if they don't intersect I just disregard everything) . After that I'd manually translate the balls &quot;before&quot; the point of intersection (I was too lazy to actually compute where the balls would touch so I just put them somewhere near that point for the purposes of illustration, but it doesn't really matter). After I've done all that I would just let the discrete collision detection algorithm, which I already have, do the work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DJFR6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DJFR6.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Couple of things I'm worried about here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(1) Since I have more than 2 balls on the table (16 to be precise) can the manual translation step somehow impact eventual collision of one of the balls that have been translated and some other, third ball? It seems to me like it shouldn't, but I'm not sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(2) On one hand I'm thinking that this might cause some glitching since I'm translating the balls &quot;back&quot; after I've already drawn them at their positions. On the other hand since this will only be happening at high velocities it might not matter that much. This also causes me to wonder whether I should do &lt;em&gt;draw - collide&lt;/em&gt; or &lt;em&gt;collide - draw&lt;/em&gt;. That is, should I use the principle I've described here (first draw the balls, then check whether they've been drawn too far) or maybe I should &quot;look ahead&quot;, as in check whether the next position could cause problems instead of whether the previous position has caused them?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not looking for any code, just ideas and thoughts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="11414" LastEditorUserId="209" LastEditDate="2019-11-08T12:02:54.283" LastActivityDate="2020-12-08T09:00:02.000" Title="An idea for an implementation of continuous collision detection of circles" Tags="&lt;opengl&gt;" AnswerCount="2" CommentCount="4" FavoriteCount="1" ClosedDate="2020-12-10T08:47:16.817" ContentLicense="CC BY-SA 4.0" />
  <row Id="9304" PostTypeId="1" AcceptedAnswerId="9306" CreationDate="2019-11-05T18:57:33.520" Score="0" ViewCount="110" Body="&lt;p&gt;There is a popular technique of normalising images by dividing each pixel with 255 so that it comes in the range of 0 and 1.&lt;br&gt;&#xA;But, then how the same colours are formed when we normalize images.&lt;br&gt;&#xA;for instance, there is a pixel with value &lt;code&gt;0 1 1&lt;/code&gt; and other &lt;code&gt;0 255 255&lt;/code&gt;, I checked on &lt;a href=&quot;https://www.rapidtables.com/web/color/RGB_Color.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;RGB colors chart&lt;/a&gt;, both are showing different colors, but if we normalise the second pixel values then its value will be same as the first one and it should produce different results but on plotting the set of normalized pixels, they come out to be same as the previous one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have previously asked this question - &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/9104/how-rgb-images-are-formed&quot;&gt;how RGB images are formed&lt;/a&gt;&#xA;so deriving out conclusions from the above question.&lt;/p&gt;&#xA;" OwnerUserId="11114" LastActivityDate="2019-11-06T03:53:59.523" Title="How RGB images are formed when normalized between 0 and 1" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9305" PostTypeId="1" CreationDate="2019-11-05T21:03:35.317" Score="0" ViewCount="52" Body="&lt;p&gt;I'm kind of lost here as I'm faced with a graphical bug the origin of which I don't even know. In an attempt to recreate a shadertoy I saw that had TXAA, I made a function TemporalAA that takes in 3 buffers: the current frame &lt;code&gt;buffer&lt;/code&gt;, the last frame &lt;code&gt;prevbuffer&lt;/code&gt;, and the frame to which we render the anti aliased image &lt;code&gt;aabuffer&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The original implementation: &lt;a href=&quot;https://www.shadertoy.com/view/4tcXD2&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/4tcXD2&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is that there's this weird overlay pattern, and I don't notice any edge smoothing whatsoever. Also note the brightly colored bands that the spheres get when in this overlay.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FSfg8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FSfg8.png&quot; alt=&quot;Weird artifacts&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's completely written in C.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: a frame consists of an &lt;code&gt;uint8&lt;/code&gt; width*height*3 array. (times three for three color channels. &lt;code&gt;[0] = red, [1] = green, [2] = blue&lt;/code&gt;). Please ignore the fact that everything is &lt;code&gt;static inline&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// YUV-RGB conversion routine from Hyper3D&#xA;static inline vec3 encodePalYuv(color3 clr)&#xA;{&#xA;    vec3 rgb = (vec3){ // pow = gamma correction&#xA;        pow((float)clr.r/255, 2),&#xA;        pow((float)clr.g/255, 2),&#xA;        pow((float)clr.b/255, 2)&#xA;    };&#xA;    return (vec3){&#xA;        dot3(rgb, (vec3){0.299f, 0.587f, 0.114f}),&#xA;        dot3(rgb, (vec3){-0.14713f, -0.28886f, 0.436f}),&#xA;        dot3(rgb, (vec3){0.615f, -0.51499f, -0.10001f})&#xA;    };&#xA;}&#xA;&#xA;static inline vec3 decodePalYuv(vec3 yuv)&#xA;{&#xA;    return (vec3){ // pow = gamma correction&#xA;        pow(dot3(yuv, (vec3){1.f, 0.f, 1.13983}), 0.5),&#xA;        pow(dot3(yuv, (vec3){1.f, -0.39465, -0.58060}), 0.5),&#xA;        pow(dot3(yuv, (vec3){1.f, 2.03211, 0.f}), 0.5)&#xA;    };&#xA;}&#xA;&#xA;// component wise multiplication&#xA;static inline vec3 compwisemult3(vec3 v, vec3 u){&#xA;    return (vec3){&#xA;        v.x*u.x,&#xA;        v.y*u.y,&#xA;        v.z*u.z&#xA;    };&#xA;}&#xA;&#xA;static inline void TemporalAA(uint8_t * buffer, uint8_t * prevbuffer, uint8_t * aabuffer, int width, int height) // out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;    int pitch = width*3;&#xA;&#xA;    for (int u = 1; u &amp;lt; width-1; ++u)&#xA;    {&#xA;        for (int v = 1; v &amp;lt; height-1; ++v) // we cant do the edge/corner pixels. That would be undefined behaviour&#xA;        {&#xA;            // index is the position in the buffers at which the current pixel resides&#xA;            // buffer[index], +1 and +2 for green &amp;amp; blue respectively.&#xA;            int index = (u&amp;lt;&amp;lt;2) + v*pitch; // leftshift 2 == multiply 4 but faster&#xA;&#xA;            vec3 antialiased = c3tov3( (color3){prevbuffer[index], prevbuffer[index+1], prevbuffer[index+2]} );&#xA;            // vec4 lastColor = texture(iChannel1, uv);&#xA;            float mixRate = 0.5f;//fminf(1/width, 0.5);&#xA;&#xA;            //vec3 in0 = texture(iChannel0, uv).xyz;&#xA;            color3 in[9];&#xA;            in[0] = ( (color3){buffer[index], buffer[index+1], buffer[index+2]} );&#xA;            vec3 in0 = c3tov3(in[0]);&#xA;&#xA;            antialiased = lerp3(compwisemult3(antialiased, antialiased), compwisemult3(in0, in0), mixRate);&#xA;            antialiased.x = sqrt(antialiased.x);&#xA;            antialiased.y = sqrt(antialiased.y);&#xA;            antialiased.z = sqrt(antialiased.z);&#xA;&#xA;            // PaulHK:&#xA;            // index = (nu + nv*pitch)*3 == (nu&amp;lt;&amp;lt;2) + nv*pitch&#xA;            int nu, nv; //vec2 off = 1.0 / iResolution.xy;&#xA;            nu = u+1; nv = v; // vec3 in1 = texture(iChannel0, uv + vec2(+off.x, 0.0)).xyz;&#xA;            in[1] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u-1; nv = v; // vec3 in2 = texture(iChannel0, uv + vec2(-off.x, 0.0)).xyz;&#xA;            in[2] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u; nv = v+1; // vec3 in3 = texture(iChannel0, uv + vec2(0.0, +off.y)).xyz;&#xA;            in[3] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u; nv = v-1; // vec3 in4 = texture(iChannel0, uv + vec2(0.0, -off.y)).xyz;&#xA;            in[4] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u+1; nv = v+1; // vec3 in5 = texture(iChannel0, uv + vec2(+off.x, +off.y)).xyz;&#xA;            in[5] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u-1; nv = v+1; // vec3 in6 = texture(iChannel0, uv + vec2(-off.x, +off.y)).xyz;&#xA;            in[6] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u+1; nv = v-1; // vec3 in7 = texture(iChannel0, uv + vec2(+off.x, -off.y)).xyz;&#xA;            in[7] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;            nu = u-1; nv = v-1; // vec3 in8 = texture(iChannel0, uv + vec2(-off.x, -off.y)).xyz;&#xA;            in[8] = ((color3){buffer[(nu + nv*pitch)*3], buffer[(nu + nv*pitch)*3 +1], buffer[(nu + nv*pitch)*3 +2]});&#xA;&#xA;            antialiased = encodePalYuv(v3toc3(antialiased));&#xA;                 in0 = encodePalYuv(in[0]);&#xA;            vec3 in1 = encodePalYuv(in[1]);&#xA;            vec3 in2 = encodePalYuv(in[2]);&#xA;            vec3 in3 = encodePalYuv(in[3]);&#xA;            vec3 in4 = encodePalYuv(in[4]);&#xA;            vec3 in5 = encodePalYuv(in[5]);&#xA;            vec3 in6 = encodePalYuv(in[6]);&#xA;            vec3 in7 = encodePalYuv(in[7]);&#xA;            vec3 in8 = encodePalYuv(in[8]);&#xA;&#xA;            vec3 minColor;&#xA;            minColor.x = fminf(fminf(fminf(in0.x, in1.x), fminf(in2.x, in3.x)), in4.x);&#xA;            minColor.y = fminf(fminf(fminf(in0.y, in1.y), fminf(in2.y, in3.y)), in4.y);&#xA;            minColor.z = fminf(fminf(fminf(in0.z, in1.z), fminf(in2.z, in3.z)), in4.z);&#xA;&#xA;            vec3 maxColor;&#xA;            maxColor.x = fmaxf(fmaxf(fmaxf(in0.x, in1.x), fmaxf(in2.x, in3.x)), in4.x);&#xA;            maxColor.y = fmaxf(fmaxf(fmaxf(in0.y, in1.y), fmaxf(in2.y, in3.y)), in4.y);&#xA;            maxColor.z = fmaxf(fmaxf(fmaxf(in0.z, in1.z), fmaxf(in2.z, in3.z)), in4.z);&#xA;&#xA;            vec3 lerpto1;&#xA;            lerpto1.x = fminf(fminf(fminf(in5.x, in6.x), fminf(in7.x, in8.x)), minColor.x);&#xA;            lerpto1.y = fminf(fminf(fminf(in5.y, in6.y), fminf(in7.y, in8.y)), minColor.y);&#xA;            lerpto1.z = fminf(fminf(fminf(in5.z, in6.z), fminf(in7.z, in8.z)), minColor.z);&#xA;&#xA;            minColor = lerp3(minColor, lerpto1, 0.5);&#xA;&#xA;            vec3 lerpto2;&#xA;            lerpto2.x = fmaxf(fmaxf(fmaxf(in5.x, in6.x), fmaxf(in7.x, in8.x)), maxColor.x);&#xA;            lerpto2.y = fmaxf(fmaxf(fmaxf(in5.y, in6.y), fmaxf(in7.y, in8.y)), maxColor.y);&#xA;            lerpto2.z = fmaxf(fmaxf(fmaxf(in5.z, in6.z), fmaxf(in7.z, in8.z)), maxColor.z);&#xA;&#xA;            maxColor = lerp3(maxColor, lerpto2, 0.5);&#xA;&#xA;            vec3 preclamping = antialiased;&#xA;            antialiased.x = clampf(antialiased.x, minColor.x, maxColor.x);&#xA;            antialiased.y = clampf(antialiased.y, minColor.y, maxColor.y);&#xA;            antialiased.z = clampf(antialiased.z, minColor.z, maxColor.z);&#xA;&#xA;            mixRate = 1.f / (1.f / mixRate + 1.f);&#xA;&#xA;            vec3 diff = sub3(antialiased, preclamping);&#xA;            float clampAmount = dot3(diff, diff);&#xA;&#xA;            mixRate += clampAmount * 4.f;&#xA;            mixRate = clampf(mixRate, 0.05f, 0.5f);&#xA;&#xA;            antialiased = decodePalYuv(antialiased);&#xA;&#xA;            //fragColor = vec4(antialiased, mixRate);&#xA;            color3 fragColor = v3toc3(scale3(antialiased, mixRate));&#xA;            aabuffer[index  ] = fragColor.r;&#xA;            aabuffer[index+1] = fragColor.g;&#xA;            aabuffer[index+2] = fragColor.b;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10615" LastEditorUserId="10615" LastEditDate="2019-11-06T08:42:10.317" LastActivityDate="2019-11-06T08:42:10.317" Title="Temporal anti-alliasing breaks the entire image" Tags="&lt;raytracing&gt;&lt;antialiasing&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9306" PostTypeId="2" ParentId="9304" CreationDate="2019-11-06T03:53:59.523" Score="1" Body="&lt;p&gt;Let's suggest an analogy. I have a distance of 1 centimeter and 2.54 centimeters. If I transform the latter distance to inches, then it's 1 inch. This has the same value as the first distance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But 1 inch is still longer than 1 centimeter, no matter the fact that they both use the numeral 1. These numbers are attached to &lt;em&gt;different units&lt;/em&gt;, so simply comparing their numerical values is meaningless.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it doesn't matter if the 8-bit unsigned, normalized value of 255 happens to have the same value of 1. Because you cannot compare them when they are in different spaces like that. Your original values were both in 8-bit normalized, unsigned integer space. If you want to compare them in a floating-point space, you have to transform &lt;em&gt;both&lt;/em&gt; of them.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-11-06T03:53:59.523" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9307" PostTypeId="1" CreationDate="2019-11-06T07:41:22.127" Score="0" ViewCount="140" Body="&lt;p&gt;It's the algorithm which combines path tracing and reinforcement learning. I can't understand what &lt;span class=&quot;math-container&quot;&gt;$p_\omega$&lt;/span&gt; is. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PWbSf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PWbSf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The algorithm is clear. The actions are the directions and the states are the hit points. For updating the Q-values, the hit points are considered as parts of a discretized diagram like Voronoi diagram and the directions of rays are generated by a discretization of a hemisphere surface which divides it into equal areas. The Q-values are initialized as equal for each state. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, we generate a camera ray, and when it hits a diffuse surface, it scatters according to a discrete PDF which is calculated by normalizing the Q-values of the state of hit point. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, The Q-values are updated along the path, we have the state &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; and the next state &lt;span class=&quot;math-container&quot;&gt;$s\prime$&lt;/span&gt; is generated from the direction generated by PDF of Q-values in &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The area of each path on the hemispheres is &lt;span class=&quot;math-container&quot;&gt;$2\pi/n$&lt;/span&gt;, and integral in the update equation of Q-values is calculated like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\dfrac{2\pi}{n}\sum_{k=0}^{n-1}Q_k(y)f_s(\omega_k, y, -\omega)cos\theta_k$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand all of the algorithm, but I don't know what &lt;span class=&quot;math-container&quot;&gt;$p_\omega$&lt;/span&gt; is in the second part. Is it &lt;span class=&quot;math-container&quot;&gt;$1/2\pi$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$n/2\pi$&lt;/span&gt; ? Could someone prove what it really is? I need the proof. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess it is &lt;span class=&quot;math-container&quot;&gt;$1/2\pi$&lt;/span&gt; because the path tracer here only use the PDF generated by Q-values. It doesn't use the Q-values at all. Am I correct? If I am correct, how can I prove it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: For clarification, a ray generated through a patch uniformly and the Q-values are generated as I said. Because we only change the directions so more samples are generated inside the patches which receive more light. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used &lt;span class=&quot;math-container&quot;&gt;$n/2\pi$&lt;/span&gt; , but scene was so dark, so the PDF must be either &lt;span class=&quot;math-container&quot;&gt;$1/2\pi$&lt;/span&gt; or a normalized combination of PDF's of patches. If the second is true, what it really is?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 2: Should I ask this question in the statistics community of stack exchange?&lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-11-06T08:16:29.080" LastActivityDate="2021-03-30T19:06:10.587" Title="What is the PDF for path tracing in the paper &quot;Learning the light transport the reinforced way" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9308" PostTypeId="2" ParentId="9303" CreationDate="2019-11-06T08:53:32.333" Score="0" Body="&lt;p&gt;I think you should determine the &quot;next collision point&quot; in your whole 16-ball-and-table-border system and adjust your simulation 'Delta t&quot; depending on it. Rendering should be de-coupled from this anyway, or it will show irregular ball movements... .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some further thoughts:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Collinear velocity vectors do not mean there is no collision - if v1 != v2 ...&lt;/li&gt;&#xA;&lt;li&gt;In good pool games you can define the 'hit point', where the queue hits the ball. Then &quot;curvy&quot; ball trajectories are generated, etc. etc. &lt;/li&gt;&#xA;&lt;li&gt;Your system should also consider friction, therefore: v-&gt;0 over time. This should also affect your collision calculations.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="8314" LastEditorUserId="8314" LastEditDate="2019-11-06T09:11:13.557" LastActivityDate="2019-11-06T09:11:13.557" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9309" PostTypeId="2" ParentId="9282" CreationDate="2019-11-06T14:59:45.760" Score="1" Body="&lt;p&gt;Rather than fit bilinear patches to your sample points, which are only C0 continuous&lt;span class=&quot;math-container&quot;&gt;$^\spadesuit$&lt;/span&gt; may I instead suggest fitting the surface using Catmull-Rom splines? These will give you C2 continuity. &#xA;Catmull-Rom is an interpolating spline which means it will pass through your sample points, as did the bilinear surface, but will do so smoothly from patch to patch.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^\spadesuit$&lt;/span&gt; &lt;em&gt;because the first derivatives won't generally match at the boundaries of your patches&lt;/em&gt; &lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Background/Assumption&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;You have a function &lt;span class=&quot;math-container&quot;&gt;$$F:\Re^2\to\Re^3$$&lt;/span&gt; of the form  &lt;span class=&quot;math-container&quot;&gt;$$F(s,t)=[s,t,f(s,t)]$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$f:\Re^2\to\Re$&lt;/span&gt;. The function, &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;, can be considered a 'black box' in the sense that we might not be given it explicitly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt; has been regularly sampled as &lt;span class=&quot;math-container&quot;&gt;$$S_{i,j}=F(x_{scale}.i, y_{scale}.j, f(x_{scale}.i,y_{scale}.j))$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$i,j\in\mathbb{Z}$&lt;/span&gt;.  You then want interpolate between these sample points using piecewise bicubic Catmull-Rom patches.&lt;/p&gt;&#xA;&#xA;&lt;h3&gt;Constructing patches&lt;/h3&gt;&#xA;&#xA;&lt;p&gt;To form a particular bicubic Catmull-Rom patch, &lt;span class=&quot;math-container&quot;&gt;$C_{i,j}$&lt;/span&gt;, which has a given 2x2 set of samples &lt;span class=&quot;math-container&quot;&gt;$\{S_{i,j},  S_{i+1,j}, S_{i,j+1},  S_{i+1,j+1}\}$&lt;/span&gt; at the corners, you need the set of 4x4 samples formed from the 2x2 at the centre and the surrounding 12 samples, i.e.&lt;span class=&quot;math-container&quot;&gt;$\{S_{i-1,j-1}$&lt;/span&gt; &lt;em&gt;through&lt;/em&gt; &lt;span class=&quot;math-container&quot;&gt;$S_{i+2,j+2}\}$&lt;/span&gt;,  as shown below.&#xA;(My apologies that this is 'hand placed' so is far from ideal)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/M48A3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M48A3.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we just consider the behaviour of the surface at sample, &lt;span class=&quot;math-container&quot;&gt;$S_{i,j}$&lt;/span&gt;, then the partial derivative in the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; direction is given by &#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial C_{ij}}{\partial i}=\frac{S_{i+1,j}-S_{i-1,j}}{2}$$&lt;/span&gt;&#xA;and similarly, in the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; direction by&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial C_{ij}}{\partial j}=\frac{S_{i,j+1}-S_{i,j-1}}{2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remembering these are vectors, you can use the cross product to generate a surface normal at any of the &lt;span class=&quot;math-container&quot;&gt;$S_{i,j}$&lt;/span&gt; points&lt;span class=&quot;math-container&quot;&gt;$^\clubsuit$&lt;/span&gt;. (Though you may need an extra set of boundary samples)&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;em&gt;Ali: You mentioned that both partial derivatives are vectors(in i,j directions). could you write each vector components plz&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Certainly: If we say &lt;span class=&quot;math-container&quot;&gt;$S_{i,j}=[x_{i,j},y_{i,j},z_{i,j}]^T$&lt;/span&gt; then &lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial C_{ij}}{\partial i}=\frac{1}{2}.[(x_{i+1,j}-x_{i-1,j}),(y_{i+1,j}-y_{i-1,j}),(z_{i+1,j}-z_{i-1,j})]^T$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial C_{ij}}{\partial j}=\frac{1}{2}.[(x_{i,j+1}-x_{i,j-1}),(y_{i,j+1}-y_{i,j-1}),(z_{i,j+1}-z_{i,j-1})]^T$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you've sampled the surface 'finely' enough you could probably choose to render the surface by just using 2 or 4 triangles per original patch. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, you can recursively subdivide your quad mesh to get a finer set of triangles. To double the number of points in the 'i' direction, simply insert a new point between each &lt;span class=&quot;math-container&quot;&gt;$S_{i,j}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$S_{i+1,j}$&lt;/span&gt; that equals ...&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{9(S_{i,j}+S_{i+1,j}) - (S_{i-1,j}+S_{i+2,j})}{16}$$&lt;/span&gt;&#xA; Once you have the finer grid in 'i' simply repeat with 'j' with the appropriate equivalent set of points. You can repeat this ad nauseam to get whatever triangle resolution you desire ;-)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^\clubsuit$&lt;/span&gt; (Copying some text from the comments below): I've made a couple of valid assumptions here.  Noting that if a given first (partial) derivative is non-zero (which is guaranteed in your case because of the way you construct the surface), then it also is locally tangential to that surface. Further, we know your two partial derivates aren't parallel, so the cross product will construct a valid normal. &#xA;FWIW For some arrangements of control points, i.e. in more general use cases, you can get so-called 'degenerate' surfaces where you can't naively apply the above rules, but you're safe here. &lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-11-08T17:44:55.533" LastActivityDate="2019-11-08T17:44:55.533" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9310" PostTypeId="2" ParentId="9307" CreationDate="2019-11-06T17:35:34.677" Score="0" Body="&lt;p&gt;I have to answer my question. &#xA;Consider that all patches have the same value. Then choosing a patch uniformly and selecting a random point uniformly on that patch is as the same as sampling the hemisphere uniformly. If &lt;span class=&quot;math-container&quot;&gt;$p_s=Pr(Q_k \in Q)=1/n$&lt;/span&gt;, which n is the number of patches, I can conclude that &lt;span class=&quot;math-container&quot;&gt;$p_\omega=p_s*(n/2\pi)=1/2\pi$&lt;/span&gt; .&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if patches don't have the same value, then &lt;span class=&quot;math-container&quot;&gt;$p_s=Pr(Q_k \in Q)=q_k/(q_1+...+q_n)$&lt;/span&gt; and &#xA;&lt;span class=&quot;math-container&quot;&gt;$p_\omega=p_s*(n/2\pi)=(q_k/(q_1+...+q_n))*(n/2\pi)$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="11316" LastActivityDate="2019-11-06T17:35:34.677" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9311" PostTypeId="1" CreationDate="2019-11-06T19:32:41.820" Score="0" ViewCount="74" Body="&lt;p&gt;I've implemented the algorithm in the paper &quot;Learning the light transport the reinforced way&quot;. What is the name of this effect and how should I solve it?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P95BI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P95BI.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-11-06T20:54:46.557" LastActivityDate="2019-11-06T20:54:46.557" Title="What is the name of this effect and how could I solve it?" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9312" PostTypeId="1" CreationDate="2019-11-07T02:18:21.480" Score="1" ViewCount="23" Body="&lt;p&gt;We are implementing a &quot;lazy container&quot; that caches renders of an object at various cutoffs and scales up/down the render-textures from those caches instead of drawing the actual object directly. This is done primarily is reduce the computational overhead of applying (multiple) shader filters.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Our renderer also implements a grid, which kicks in a high levels of zoom. If we render a downloaded image, then on zooming in we would find that each grid box contains only one color, e.g. it is one pixel in the image. This also applies if we apply any shader filter.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if we enable our &quot;lazy&quot; container, then we find that the grid box contain more than one color. Each texture pixel is not aligned with the grid's lines, sometimes even being smaller than one grid box.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An example of a zoomed in layer blur is given below (applied on a 320x180 image that is cached at 1024x576 on a 1024x1024 render-texture):&lt;a href=&quot;https://i.stack.imgur.com/n3usi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n3usi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an explanation for why this is happening?&lt;/p&gt;&#xA;" OwnerUserId="10715" LastActivityDate="2019-11-07T02:18:21.480" Title="Irregular subpixel behaviour using cached render textures" Tags="&lt;deferred-rendering&gt;&lt;subpixel-rendering&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9313" PostTypeId="1" CreationDate="2019-11-07T11:34:11.497" Score="1" ViewCount="44" Body="&lt;p&gt;My goal in my project is to render a procedural texture for a given mesh based on a predefined camera projection.&#xA;The way I choose to accomplish it is by creating tex coords based on only the visible triangles for a given projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Its important to note that the mesh is unindexed and each vertex is unique to each triangle.&#xA;After calculating the UV I pass the tex coords, vertices, MVP matrix to a shader program.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the vertex shader I define the gl_position as the generated tex coords so in the end of the pass i will get a texture that is defined by the tex coords.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(location = 0) in vec3 aPos;&#xA;layout(location = 1) in vec2 aTexCoord;&#xA;&#xA;out VS_OUT {&#xA;vec4 projector;&#xA;vec2 uv;&#xA;vec2 old_uv;&#xA;} vs_out;&#xA;void main()&#xA;{&#xA;gl_Position = vec4(aTexCoord*2.0f - 1.0f, 0.0f, 1.0f);&#xA;vs_out.projector = vec4(aPos, 1.0f);&#xA;vs_out.uv = aTexCoord;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bEBrC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bEBrC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;AN example of the output of the vertex shader&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then in the fragment shader, I color the mesh with a simple red color (in the future I hope to project images instead of the red color) :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;layout(location = 0) out vec4 FragColor;&#xA;in VS_OUT{&#xA;vec4 projector;&#xA;vec2 uv;&#xA;} vs_out;&#xA;uniform sampler2D shadowMap;&#xA;uniform mat4 model;&#xA;uniform mat4 projProj;&#xA;uniform mat4 projBias;&#xA;uniform mat4 projView;&#xA;float ShadowCalc(vec4 proj)&#xA;{&#xA;float closestDepth = texture2DProj(shadowMap, proj).r;&#xA;float currentDepth = proj.z / proj.w;&#xA;float shadow = currentDepth - 0.00005 &amp;gt; closestDepth ? 0.0 : 1.0;&#xA;return shadow;&#xA;}&#xA;void main()&#xA;{&#xA;vec4 ndcProj = (projBias * projProj * projView * model * vs_out.projector);&#xA;vec2 projUV = (ndcProj.xy / ndcProj.w);&#xA;float fDepth = ndcProj.z / ndcProj.w;&#xA;vec4 col = vec4(0.0, 0.0, 0.0, 1.0);&#xA;if (0.0 &amp;lt; projUV.x &amp;amp;&amp;amp; projUV.x &amp;lt; 1.0 &amp;amp;&amp;amp; 0.0 &amp;lt; projUV.y &amp;amp;&amp;amp; projUV.y &amp;lt; 1.0 &amp;amp;&amp;amp; ndcProj.w &amp;gt; 0.0 &amp;amp;&amp;amp; ShadowCalc(ndcProj) &amp;gt; 0.5)&#xA;{&#xA;col = vec4(1.0,0.0,0.0,1.0);&#xA;}&#xA;&#xA;FragColor = col;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/x1L8S.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/x1L8S.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;The result after the fragment shader (the texture is cleared with a green color before)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I then display the mesh with the texture using the same tex coords with the following program:&#xA;Vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;layout(location = 0) in vec3 aPos;&#xA;layout(location = 1) in vec2 aTexCoord;&#xA;uniform mat4 model;&#xA;uniform mat4 projProj;&#xA;uniform mat4 projView;&#xA;out vec2 texCoordOut;&#xA;void main()&#xA;{&#xA;gl_Position = projProj * projView * model * vec4(aPos, 1.0f);&#xA;texCoordOut = aTexCoord;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;in vec2 texCoordOut;&#xA;out vec4 out_color;&#xA;uniform sampler2D unwarp_image;&#xA;void main()&#xA;{&#xA;vec4 color = texture(unwarp_image, texCoordOut.st);&#xA;out_color = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The result:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iwqrj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iwqrj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;The mesh rendered with the texture on screen&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see, the mesh has these strange wireframe artifacts.&#xA;I've thought of several solutions such as enabling conservative conservative rasterization but none seem to work.&#xA;Any ideas on how to get a clean rendering of the mesh with the procedural texture?&lt;/p&gt;&#xA;" OwnerUserId="11431" LastActivityDate="2019-11-07T14:06:32.293" Title="Help with wireframe artifacts on mesh procedural UV texturing" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;uv-mapping&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9314" PostTypeId="2" ParentId="9313" CreationDate="2019-11-07T11:59:33.417" Score="1" Body="&lt;p&gt;This looks like a side effect of bilinear filtering where it can sample texels neighbouring those that are at the edges of the used areas of the texture - the red/green boundary in your case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One solution for this is to perform a &quot;colour bleed&quot; pass on the texture where for every 'empty'(Green) texel with none-empty (Red) neighbours you can output the average of all the none-empty neighbours, so what this will do is add a 1 pixel boundary to the red part of your image that matches its neighbours (In this case the average should be red) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a solution to a similar problem seen with alpha blended textures with sharp edges where colour bleeding can sometimes appear at the boundaries between semi-transparent and completely transparent pixels when magnifying the image. Most modern art packages will automatically colour bleed the RGB channels when saving RGBA images for this reason.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2019-11-07T12:05:13.237" LastActivityDate="2019-11-07T12:05:13.237" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9315" PostTypeId="2" ParentId="9313" CreationDate="2019-11-07T12:32:01.630" Score="0" Body="&lt;p&gt;Having read PaulHK's answer, it occurred to me that a possible alternative to the 'bleed', based on premultiplied alpha, would be to initialise your unfilled area to &lt;em&gt;transparent black&lt;/em&gt; rather than opaque green. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you then perform the bilinear filtering, if the returned alpha is non-zero (&lt;em&gt;not sure if this test is necessary or not as I can't remember the specifics of the shader rcp() function&lt;/em&gt;), multiply the returned, filtered (premultiplied) RGB components by the reciprocal of the alpha to get back the appropriate colour.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One would hope the alpha is always non-zero, ie. you never sample outside of regions of interest, but there may be inaccuracies in the pipeline so you might need to special case it. &lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-11-07T14:06:32.293" LastActivityDate="2019-11-07T14:06:32.293" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9316" PostTypeId="1" CreationDate="2019-11-07T20:09:04.200" Score="2" ViewCount="200" Body="&lt;p&gt;I want to start developing a hybrid renderer: it first applies a rasterizer, then stores for each pixel the surface pointer, normal vector, and distance to the camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then it raytraces reflections, refractions, lambertian diffuse, etc using those values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first problem however is rasterizing a sphere: while there are many tutorials for rasterizing quads and triangles, there aren't any on spheres, and I don't know how to do this myself while keeping perspective intact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how do you perfectly rasterize an explicit sphere (with radius, center)?&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-11-08T22:07:34.623" Title="Rasterizing spheres?" Tags="&lt;perspective&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9317" PostTypeId="1" CreationDate="2019-11-07T22:59:50.700" Score="1" ViewCount="148" Body="&lt;p&gt;I am programing a tessellation shader in OpenGL which computes the &lt;a href=&quot;https://reader.elsevier.com/reader/sd/pii/0010448595000461?token=4190E80EF50B0C8E2FB4EADFFEF26DF93ACEDF3AED59AA6B97D59B2C1FC52B0B965B255B27749ECC11F49B44C1610688&quot; rel=&quot;nofollow noreferrer&quot;&gt;quartic Walton-Meek's Gregory patch&lt;/a&gt;. I am searching for a local G1 method with good shading/visual results. So I am trying this patch. I didn't get good (visual/shading) results with PN-Triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've just had my first result with this WM patch, which isn't good as well. Perhaps the normal I am calculating is wrong. I am following these equations to compute it:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AQq0v.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AQq0v.png&quot; alt=&quot;Bézier-Bernstein Triangle and Derivatives Equations&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then, I actually compute it through normalizing the cross product between the derivatives (last image).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to take a look at the shader code, here it is (the first one is the tessellation control shader and the second one is the tessellation evaluation shader):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;layout (vertices = 3) out;&#xA;&#xA;in VertOut&#xA;{&#xA;    vec3 normal;&#xA;} vertOut[];&#xA;&#xA;out TescOut&#xA;{&#xA;    vec3 p0;&#xA;    vec3 p1;&#xA;    vec3 p2;&#xA;    vec3 p3;&#xA;    vec3 g0;&#xA;    vec3 g1;&#xA;    vec3 n;&#xA;} tescOut[];&#xA;&#xA;void main()&#xA;{&#xA;    const float kTessLevel = 12.0;&#xA;    gl_TessLevelOuter[gl_InvocationID] = kTessLevel;&#xA;    gl_TessLevelInner[0] = kTessLevel;&#xA;&#xA;    vec3 p0 = tescOut[gl_InvocationID].p0 = gl_in[gl_InvocationID].gl_Position.xyz;&#xA;    vec3 n = tescOut[gl_InvocationID].n = vertOut[gl_InvocationID].normal;&#xA;&#xA;    const int nextInvID = gl_InvocationID &amp;lt; 2 ? gl_InvocationID + 1 : 0;&#xA;    vec3 edge = gl_in[nextInvID].gl_Position.xyz - p0;&#xA;    vec3 nNext = vertOut[nextInvID].normal;&#xA;    float d = length(edge), a = dot(n, nNext);&#xA;    vec3 gama = edge / d;&#xA;    float a0 = dot(n, gama), a1 = dot(nNext, gama);&#xA;    float ro = 6.0 * (2.0 * a0 + a * a1)/(4.0 - a * a);&#xA;    float sigma = 6.0 * (2.0 * a1 + a * a0)/(4.0 - a * a);&#xA;&#xA;    vec3 v[4] = vec3[4]&#xA;    (&#xA;        p0,&#xA;        p0 + (d / 18.0) * (6.0 * gama - 2.0 * ro * n + sigma * nNext),&#xA;        gl_in[nextInvID].gl_Position.xyz - (d / 18.0) * (6.0 * gama + ro * n - 2.0 * sigma * nNext),&#xA;        edge = gl_in[nextInvID].gl_Position.xyz&#xA;    );&#xA;&#xA;    vec3 w[3] = vec3[3]&#xA;    (&#xA;        v[1] - v[0],&#xA;        v[2] - v[1],&#xA;        v[3] - v[2]&#xA;    );&#xA;&#xA;    vec3 A[3] = vec3[3]&#xA;    (&#xA;        cross(n, normalize(w[0])),&#xA;        vec3(0.0),&#xA;        cross(nNext, normalize(w[2]))&#xA;    );&#xA;&#xA;    A[1] = normalize(A[0] + A[2]);&#xA;&#xA;    vec3 l[5] = vec3[5]&#xA;    (&#xA;        v[0],&#xA;        0.25 * (v[0] + 3.0 * v[1]),&#xA;        0.25 * (2.0 * v[1] + 2.0 * v[2]),&#xA;        0.25 * (3.0 * v[2] + v[3]),&#xA;        v[3]&#xA;    );&#xA;&#xA;    vec3 p1 = tescOut[gl_InvocationID].p1 = l[1];&#xA;    vec3 p2 = tescOut[gl_InvocationID].p2 = l[2];&#xA;    vec3 p3 = tescOut[gl_InvocationID].p3 = l[3];&#xA;&#xA;    barrier();&#xA;&#xA;    const int previousInvID = gl_InvocationID &amp;gt; 0 ? gl_InvocationID - 1 : 2;&#xA;    vec3 D[4] = vec3[4]&#xA;    (&#xA;        tescOut[previousInvID].p3 - 0.5 * (p0 + p1),&#xA;        vec3(0.0),&#xA;        vec3(0.0),&#xA;        tescOut[nextInvID].p1 - 0.5 * (p3 + tescOut[nextInvID].p0)&#xA;    );&#xA;&#xA;    float mi[2] = float[2](dot(D[0], A[0]), dot(D[3], A[2]));&#xA;    float lambda[2] = float[2](dot(D[0], w[0])/dot(w[0], w[0]), dot(D[3], w[2])/dot(w[2], w[2]));&#xA;&#xA;    tescOut[gl_InvocationID].g0 = 0.5 * (l[1] + l[2]) + (2.0/3.0) * (lambda[0] * w[1] + mi[0] * A[1]) + (1.0/3.0) * (lambda[1] * w[0] + mi[1] * A[0]);&#xA;    tescOut[gl_InvocationID].g1 = 0.5 * (l[2] + l[3]) + (1.0/3.0) * (lambda[0] * w[2] + mi[1] * A[2]) + (2.0/3.0) * (lambda[1] * w[1] + mi[1] * A[1]);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;layout(triangles, equal_spacing, ccw) in;&#xA;&#xA;in TescOut&#xA;{&#xA;    vec3 p0;&#xA;    vec3 p1;&#xA;    vec3 p2;&#xA;    vec3 p3;&#xA;    vec3 g0;&#xA;    vec3 g1;&#xA;    vec3 n;&#xA;} tescOut[];&#xA;&#xA;out TeseOut&#xA;{&#xA;    vec3 normal;&#xA;    vec3 viewPosition;&#xA;} teseOut;&#xA;&#xA;uniform mat4 mvp;&#xA;uniform mat4 modelView;&#xA;uniform mat4 normalMatrix;&#xA;uniform bool isNormalLinearlyInterpolated;&#xA;&#xA;#define uvw     gl_TessCoord&#xA;&#xA;const float u = uvw.x, u2 = u * u, u3 = u2 * u, u4 = u2 * u2;&#xA;const float v = uvw.y, v2 = v * v, v3 = v2 * v, v4 = v2 * v2;&#xA;const float w = uvw.z, w2 = w * w, w3 = w2 * w, w4 = w2 * w2;&#xA;&#xA;#define p400    tescOut[0].p0&#xA;#define p310    tescOut[0].p1&#xA;#define p220    tescOut[0].p2&#xA;#define p130    tescOut[0].p3&#xA;#define G01     tescOut[0].g0&#xA;#define G02     tescOut[0].g1&#xA;#define p040    tescOut[1].p0&#xA;#define p031    tescOut[1].p1&#xA;#define p022    tescOut[1].p2&#xA;#define p013    tescOut[1].p3&#xA;#define G11     tescOut[1].g0&#xA;#define G12     tescOut[1].g1&#xA;#define p004    tescOut[2].p0&#xA;#define p103    tescOut[2].p1&#xA;#define p202    tescOut[2].p2&#xA;#define p301    tescOut[2].p3&#xA;#define G21     tescOut[2].g0&#xA;#define G22     tescOut[2].g1&#xA;&#xA;#define B400    u4&#xA;#define B040    v4&#xA;#define B004    w4&#xA;#define B310    (4.0 * u3 * v)&#xA;#define B031    (4.0 * v3 * w)&#xA;#define B103    (4.0 * u * w3)&#xA;#define B220    (6.0 * u2 * v2)&#xA;#define B022    (6.0 * v2 * w2)&#xA;#define B202    (6.0 * u2 * w2)&#xA;#define B130    (4.0 * u * v3)&#xA;#define B013    (4.0 * v * w3)&#xA;#define B301    (4.0 * u3 * w)&#xA;#define B211    (12.0 * u2 * v * w)&#xA;#define B121    (12.0 * u * v2 * w)&#xA;#define B112    (12.0 * u * v * w2)&#xA;&#xA;#define B300    u3&#xA;#define B030    v3&#xA;#define B003    w3&#xA;#define B210    (3.0 * u2 * v)&#xA;#define B021    (3.0 * v2 * w)&#xA;#define B102    (3.0 * w2 * u)&#xA;#define B120    (3.0 * u * v2)&#xA;#define B012    (3.0 * v * w2)&#xA;#define B201    (3.0 * w * u2)&#xA;#define B111    (6.0 * u * v * w)&#xA;&#xA;vec3 interpolate3D(vec3 p0, vec3 p1, vec3 p2)&#xA;{&#xA;    return gl_TessCoord.x * p0 + gl_TessCoord.y * p1 + gl_TessCoord.z * p2;&#xA;}&#xA;&#xA;void main()&#xA;{&#xA;    vec4 pos = vec4(interpolate3D(tescOut[0].p0, tescOut[1].p0, tescOut[2].p0), 1.0);&#xA;    vec3 normal = normalize(interpolate3D(tescOut[0].n, tescOut[1].n, tescOut[2].n));&#xA;&#xA;    if (u != 1.0 &amp;amp;&amp;amp; v != 1.0 &amp;amp;&amp;amp; w != 1.0)&#xA;    {&#xA;        vec3 p211 = (v * G12 + w * G21)/(v + w);&#xA;        vec3 p121 = (w * G02 + u * G11)/(w + u);&#xA;        vec3 p112 = (u * G22 + v * G01)/(u + v);&#xA;&#xA;        vec3 barPos =   p400 * B400 +&#xA;                        p040 * B040 +&#xA;                        p004 * B004 +&#xA;                        p310 * B310 +&#xA;                        p031 * B031 +&#xA;                        p103 * B103 +&#xA;                        p220 * B220 +&#xA;                        p022 * B022 +&#xA;                        p202 * B202 +&#xA;                        p130 * B130 +&#xA;                        p013 * B013 +&#xA;                        p301 * B301 +&#xA;                        p211 * B211 +&#xA;                        p121 * B121 +&#xA;                        p112 * B112;&#xA;&#xA;        pos = vec4(barPos, 1.0);&#xA;&#xA;        vec3 dpdu = p400 * B300 +&#xA;                    p130 * B030 +&#xA;                    p103 * B003 +&#xA;                    p310 * B210 +&#xA;                    p121 * B021 +&#xA;                    p202 * B102 +&#xA;                    p220 * B120 +&#xA;                    p112 * B012 +&#xA;                    p301 * B201 +&#xA;                    p211 * B111 ;&#xA;&#xA;        vec3 dpdv = p310 * B300 +&#xA;                    p040 * B030 +&#xA;                    p013 * B003 +&#xA;                    p220 * B210 +&#xA;                    p031 * B021 +&#xA;                    p112 * B102 +&#xA;                    p130 * B120 +&#xA;                    p022 * B012 +&#xA;                    p211 * B201 +&#xA;                    p121 * B111 ;&#xA;&#xA;        normal = normalize(cross(dpdu, dpdv));&#xA;    }&#xA;&#xA;    gl_Position = mvp * pos;&#xA;    pos = modelView * pos;&#xA;    teseOut.viewPosition = pos.xyz / pos.w;&#xA;&#xA;    teseOut.normal = (normalMatrix * vec4(normal, 0.0)).xyz;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Some screenshots from my current results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YIW42.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YIW42.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7bfza.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7bfza.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5rw2D.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5rw2D.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/a1MBK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a1MBK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the &quot;good ones&quot; images (first and third), the normals are computed by linear interpolation, while in the bad ones the normals are computed through the equations I said previously and are shown in the code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, how can I correctly compute the normals? Thanks in advance!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;@edit&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, I tried @Reynolds (see comment below) derivatives, but still it didn't work properly, unfortunately. These are the results: &lt;a href=&quot;https://i.stack.imgur.com/d26TV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d26TV.png&quot; alt=&quot;New results&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Results at the left (the dark ones) are using the code below and the ones at the right are flipping the normal (i.e., -normalize(cross(dpdu,dpdv)). The code:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;vec3 dpdu = 4.0 * (B300 * (p301 - p400) + B030 * (p031 - p130) + B003 * (p004 - p103) + B210 * (p211 - p310) +&#xA;                    B120 * (p121 - p220) + B201 * (p202 - p301) + B102 * (p103 - p202) + B021 * (p022 - p121) +&#xA;                    B012 * (p013 - p112) + B111 * (p112 - p211));&#xA;&#xA;vec3 dpdv = 4.0 * (B300 * (p310 - p400) + B030 * (p040 - p130) + B003 * (p013 - p103) + B210 * (p220 - p310) +&#xA;                    B120 * (p130 - p220) + B201 * (p211 - p301) + B102 * (p112 - p202) + B012 * (p022 - p112) +&#xA;                    B021 * (p031 - p121) + B111 * (p121 - p211));&#xA;normal = normalize(cross(dpdu, dpdv)); // -normalize(cross(dpdu, dpdv));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;@edit2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some more results:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AVd7g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AVd7g.png&quot; alt=&quot;Example of some errors&quot;&gt;&lt;/a&gt;&#xA;See as the bottom part of the mesh disappeared. It seems to me a problem with the zero singularity. Probably I am not treating this correctly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NaNdJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NaNdJ.png&quot; alt=&quot;Another example&quot;&gt;&lt;/a&gt;&#xA;Here, the normals of the bottom part of the mesh have a negative component in Y (vertical axis). In the previous picture, Y = 0 (for normals).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Top-left: raw mesh with normals in white&#xA;Top-right: raw mesh shading without tessellation (hence, without WM patch)&#xA;Bottom-left: wireframe mode of mesh with tessellation (hence with WM patch)&#xA;Bottom-right: mesh with tessellation (hence with WM patch)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?? Thanks!&lt;/p&gt;&#xA;" OwnerUserId="11436" LastEditorUserId="11436" LastEditDate="2019-11-19T17:09:36.607" LastActivityDate="2019-11-19T17:09:36.607" Title="How to compute normal in quartic Walton-Meek's Gregory patch in tessellation shader?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;computational-geometry&gt;&lt;tesselation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9318" PostTypeId="1" CreationDate="2019-11-08T05:09:01.187" Score="0" ViewCount="38" Body="&lt;p&gt;Assuming that I have pose information for a human, is there any ways/tools to apply that pose to a 3D model?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically, given continous pose information say from a dancing person, I like to animate a 3D model with that pose, so performing exactly the same dance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;e.g. here the left pose is applied to a model to become right:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zYpztm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zYpztm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Rjt8m.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Rjt8m.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="4678" LastEditorUserId="4678" LastEditDate="2019-11-08T17:43:33.670" LastActivityDate="2019-11-08T17:43:33.670" Title="Apply a pose to a 3D model/mesh" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;animation&gt;&lt;model&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9319" PostTypeId="1" CreationDate="2019-11-08T08:48:28.873" Score="0" ViewCount="70" Body="&lt;p&gt;I'm working (as a Post-doc) on an archaeological excavation point cloud dataset with over 2.5 Billion points. This points come from a trench, a cuboid 10 x 10 x 3 m. Each point cloud is a layer, the gaps between are the excavated volumes. There are 444 volumes from this trench, 700 individual point clouds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can anyone give me some direction to any deep learning algorithms which can mesh these empty spaces? I'm already doing this semi-automatically using Open3D and other python libraries, but if we could train the program to assess all the point clouds and deduce the volumes it would save us a lot of time and hopefully get better results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We excavate more trenches every year so the perfect place to test these out.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;reposted from here &lt;a href=&quot;https://stackoverflow.com/questions/58757853/deep-learning-for-3d-point-clouds-volume-detection-and-meshing&quot;&gt;https://stackoverflow.com/questions/58757853/deep-learning-for-3d-point-clouds-volume-detection-and-meshing&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;To clarify the nature of the data, as requested.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We gather a point cloud of the ground surface using Structure from Motion - photogrammetry. We then excavate a layer (e.g remove 10cm of soil across the trench) and record again. This process repeats until we hit bedrock, in this trench it is 3m deep. This is a vastly simplified example since we have fire pits, walls, and irregularly shaped features. each point cloud is between 1 - 20 million points, we are currently using a 1 - 10 % sample of this data and getting good results, however we would like to employ deep learning to eventually save time and produce more accurate results.&lt;/p&gt;&#xA;" OwnerUserId="11439" LastEditorUserId="11439" LastEditDate="2019-11-10T20:48:08.917" LastActivityDate="2019-11-10T20:48:08.917" Title="Deep Learning for 3D Point Clouds, volume detection and meshing" Tags="&lt;algorithm&gt;&lt;volumetric&gt;" AnswerCount="0" CommentCount="11" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9321" PostTypeId="2" ParentId="9317" CreationDate="2019-11-08T12:52:42.527" Score="4" Body="&lt;p&gt;Computing exact derivatives of Gregory patches is hard due to the rational blending that occurs for the inner control points. Many people thus opt for an easier solution where the rational blending functions are first evaluated and then the resulting control points are interpreted as the control points of a standard polynomial Bézier triangle. This technique is used for instance in &lt;a href=&quot;https://dl.acm.org/citation.cfm?id=1618497&quot; rel=&quot;nofollow noreferrer&quot;&gt;ACC-2&lt;/a&gt; to approximate the normal. This will introduce singularities at the vertices due a zero denominator in the blending functions of the control points but these can easily be fixed as the normal is simply just the vertex normal at these instances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Remember that the partial derivatives of a Bézier triangle  of degree &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is a Bézier triangle of degree &lt;span class=&quot;math-container&quot;&gt;$p-1$&lt;/span&gt; where the control points in that case are vectors between the control points. As seen from the figure below you can evaluate each partial derivative as a Bézier triangle. In your case you are using just control points, but you have to use differences between control points. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4dxSV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4dxSV.png&quot; alt=&quot;cubic derivatives&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial P}{\partial u} =  4 \left(B_{300} (P_{400} - P_{301}) + B_{030} (P_{130} - P_{031}) + B_{003} (P_{103} - P_{004} ) +  B_{210} ( P_{310} - P_{211} ) +  B_{120} (P_{220} - P_{121})  +  B_{201} (P_{301} - P_{202})  +  B_{102} (P_{202} - P_{103}) +  B_{021} (P_{121} - P_{022}) +  B_{012} (P_{112} - P_{013}) +  B_{111} (P_{211} - P_{112}) \right) $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;and&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial P}{\partial v} =  4 \left(B_{300} (P_{310} - P_{301}) + B_{030} (P_{040} - P_{031}) + B_{003} (P_{013} - P_{004}) +  B_{210} (P_{220} - P_{211}) +  B_{120} (P_{130} - P_{121})  +  B_{201} (P_{211} - P_{202})  +  B_{102} (P_{112} - P_{103}) +  B_{012} (P_{022} - P_{013}) +  B_{021} (P_{031} - P_{022}) +  B_{111} (P_{121} - P_{112}) \right). $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then proceed the same way in producing the normal by the cross product of the two partial derivatives. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get some intuition about why this is this case we can look at the simpler case of a cubic Bézier curve with control points &lt;span class=&quot;math-container&quot;&gt;$[P_{30}, P_{21}, P_{12}, P_{03}]$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$C(u) = (1-u)^3 P_{30} + 3 (1-u)^2 u P_{21} + 3 (1-u) u^2 P_{12} + u^3 P_{03},$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;if we take the derivative with respect to &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; we obtain&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial C(u)}{\partial u} = -3 (1-u)^2 P_{30} - 6 (1-u) u P_{21} + 3 (1-u)^2 P_{21} - 3 u^2 P_{12} +  6 (1-u) u P_{12} + 3 u^2 P_{03}.$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we then rearrange the terms we get&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial C(u)}{\partial u} = 3 \left((1-u)^2 (P_{21} - P_{30}) + 2 (1-u) u (P_{12}  - P_{21}) + u^2 ( P_{03} - P_{12})\right) .$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the derivative is a quadratic Bézier where the control points are the vectors between the control points of the initial cubic Bézier curve. This same principle holds for Bézier triangles.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2019-11-12T16:16:38.137" LastActivityDate="2019-11-12T16:16:38.137" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="9322" PostTypeId="1" AcceptedAnswerId="9330" CreationDate="2019-11-08T13:13:18.003" Score="1" ViewCount="50" Body="&lt;p&gt;I am about to implement the renderer for a simple particle system. Every particle has to be updated every frame (position, rotation, scale) and so I was wondering which way is usually faster:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate translation, rotation, scale and update the final positions in the vertexbuffer.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Calculate translation, rotation, scale into one transformation matrix and send that one to the GPU Shader for each particle.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="10780" LastActivityDate="2019-11-09T00:00:14.923" Title="Performance of particle implementation" Tags="&lt;gpu&gt;&lt;vertex-buffer-object&gt;&lt;particles&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9323" PostTypeId="1" CreationDate="2019-11-08T16:52:56.837" Score="1" ViewCount="62" Body="&lt;p&gt;I am experimenting with local (adaptive) grey threshold for the binarization of B&amp;amp;W photographs of yellowed manuscripts:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tAS67.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tAS67.png&quot; alt=&quot;Raw image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I got adaptive thresholding working in both scikit-image and cv2. In both cases (&lt;code&gt;grey &amp;lt; threshold_niblack()&lt;/code&gt; in scikit-image and &lt;code&gt;cv.adaptiveThreshold()&lt;/code&gt; in cv2 -- all Python) the result I get is successfully binarized, with the background pretty much uniform -- and completely full of noise:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8yuGR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8yuGR.png&quot; alt=&quot;Binarized image&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What kind of step do I now need to separate the text from this background noise?&lt;/p&gt;&#xA;" OwnerUserId="11443" LastActivityDate="2020-02-06T09:56:00.587" Title="What kind of denoising must follow locally adaptive binarization?" Tags="&lt;image-processing&gt;&lt;denoise&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9324" PostTypeId="1" CreationDate="2019-11-08T18:36:56.033" Score="1" ViewCount="101" Body="&lt;p&gt;I need some help understanding whats happening to my view space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have the following colour buffers coming out of my deffered renderer...&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Yeuak.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Yeuak.png&quot; alt=&quot;Depth buffer&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/QXHjT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QXHjT.png&quot; alt=&quot;Normal buffer&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/e5fgE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e5fgE.png&quot; alt=&quot;ViewSpace positions&quot;&gt;&lt;/a&gt;&#xA;My concern is with the view space buffer (third image), while this seems correct for the xy view space coordinate, should I not be seeing some purple/pink/white for the z component of the view space coordinate?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This scene is fairly large in an attempt to try to get varying depth values to see in the view space position buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For a small model (near and far clipping planes are sized according to scene bounding box), I get...&#xA;&lt;a href=&quot;https://i.stack.imgur.com/EL98Z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EL98Z.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Which, while it has gradient changes between the xy (not like the large scene which has sharp gradient changes, due to its size perhaps?) which makes sense to me. However I am still missing z/depth values it appears (pinks, purples and whites).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I pressume the view space in the range -1 &amp;lt; x &amp;lt; 1, -1 &amp;lt; y &amp;lt; 1, -1 &amp;lt; z &amp;lt; 1. Is this correct? Is there a problem with my view space coordinates? Could anyone spot anything I am doing wrong here?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are my shaders:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex shader of gBuffer...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout (std140) uniform MatrixPV&#xA;{&#xA;    mat4 P;&#xA;    mat4 V;&#xA;};&#xA;&#xA;layout(location = 0) in vec3 InPoint;&#xA;layout(location = 1) in vec3 InNormal;&#xA;layout(location = 2) in vec2 InUV;&#xA;&#xA;uniform mat4 M;&#xA;&#xA;out vec4 MVPosition;&#xA;out vec3 Normal;&#xA;out vec2 UV;&#xA;&#xA;void main()&#xA;{&#xA;    mat4 VM = V * M;&#xA;    gl_Position = P * VM * vec4(InPoint, 1.0);&#xA;    MVPosition = VM * vec4(InPoint, 1.0);&#xA;    Normal = mat3(M) * InNormal;&#xA;    UV = InUV;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment shader of gBuffer...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout(location = 0) out vec4 gBufferPicker;&#xA;layout(location = 1) out vec4 gBufferPosition;&#xA;layout(location = 2) out vec4 gBufferNormal;&#xA;layout(location = 3) out vec4 gBufferDiffuse;&#xA;&#xA;in vec3 Normal;&#xA;in vec4 MVPosition;&#xA;&#xA;vec4 Diffuse();&#xA;uniform vec4 PickerColour;&#xA;&#xA;void main()&#xA;{&#xA;    gBufferPosition = MVPosition;&#xA;    gBufferNormal = vec4(Normal.xyz, 1.0);&#xA;    gBufferPicker = PickerColour;&#xA;    gBufferDiffuse = Diffuse();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here is the 'lighting pass' shader to visualise the view space coordinate...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;uniform sampler2D debugBufferPosition;&#xA;&#xA;in vec2 UV;&#xA;out vec4 frag;&#xA;&#xA;void main()&#xA;{&#xA;    vec3 val = texture(debugBufferPosition, UV).xyz;&#xA;    frag = vec4(val.xyz, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated. Many thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="9438" LastActivityDate="2019-11-08T18:36:56.033" Title="gBuffer view/eye space missing z (depth) value?" Tags="&lt;opengl&gt;&lt;deferred-rendering&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9325" PostTypeId="1" CreationDate="2019-11-08T19:24:47.387" Score="1" ViewCount="114" Body="&lt;p&gt;Where can I find a pseudocode to parallelize a path tracer using multiple cpu threads? How should I change the normal path tracer to be capable of parallelization?  &lt;/p&gt;&#xA;" OwnerUserId="11316" LastActivityDate="2019-11-14T05:26:09.723" Title="A pseudocode to parallelize a path tracer?" Tags="&lt;raytracing&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9326" PostTypeId="2" ParentId="9316" CreationDate="2019-11-08T22:07:34.623" Score="2" Body="&lt;p&gt;Jim Blinn's book &lt;em&gt;Jim Blinn's Corner: Notation, Notation, Notation&lt;/em&gt; has a couple of chapters which go through this in detail with all of the edge cases. This book is a collection of essays from his column in &lt;em&gt;IEEE Computer Graphics and Applications&lt;/em&gt;. Highly recommended.&lt;/p&gt;&#xA;" OwnerUserId="11444" LastActivityDate="2019-11-08T22:07:34.623" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9327" PostTypeId="2" ParentId="9178" CreationDate="2019-11-08T22:30:41.123" Score="0" Body="&lt;p&gt;It's tricky because there are 2 non-uniform scales called &quot;DataAspectRatio&quot; and &quot;PlotBoxAspectRatio&quot;. I worked through a simple case in &lt;a href=&quot;https://www.mathworks.com/matlabcentral/answers/248362-screen-2d-projection-of-3d-plot&quot; rel=&quot;nofollow noreferrer&quot;&gt;the answer to this post&lt;/a&gt;, but I'm afraid that doesn't cover all of the edge cases.&lt;/p&gt;&#xA;" OwnerUserId="11444" LastActivityDate="2019-11-08T22:30:41.123" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9328" PostTypeId="1" CreationDate="2019-11-08T22:32:33.367" Score="1" ViewCount="270" Body="&lt;p&gt;Does anyone understand normal maps and what would color a uniformly 0 normal map be? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to convert a standard shader into an unlit shader, so (I think?) the idea is that the normal map should not contribute to the lighting. &lt;/p&gt;&#xA;" OwnerUserId="11445" LastActivityDate="2020-08-05T01:05:00.457" Title="What is a 0 &quot;null&quot; normal map? Or Unlit shader" Tags="&lt;shader&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9329" PostTypeId="2" ParentId="9328" CreationDate="2019-11-08T23:54:30.297" Score="1" Body="&lt;p&gt;In the most common normal map encoding, an RGB value of (0.5,0.5,1) would be uniformly flat. If the shader is meant to be unlit, you should be able to remove anything in the code that’s using the surface normal, light / view direction, etc.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-11-08T23:54:30.297" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9330" PostTypeId="2" ParentId="9322" CreationDate="2019-11-09T00:00:14.923" Score="1" Body="&lt;p&gt;Updating the position/rotation/scale in the vertex buffer will use less memory bandwidth—that’s 9 values, where a transform matrix would be either 12 or 16—and the GPU can parallelize the work of turning the position/rotation/scale into a transform for the vertices. I’d go with 1.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2019-11-09T00:00:14.923" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9331" PostTypeId="1" CreationDate="2019-11-09T00:01:53.957" Score="0" ViewCount="50" Body="&lt;p&gt;I am working with a 1 dimensional array of an RGBA struct composed of unsigned 8-bit integers. I have implemented a very basic line algorithm, and can draw lines from one point to another accurately, &lt;strong&gt;as long as they are within my 2D coordinate space&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For cases where one of my end points is outside of the range of my image, my system breaks down. I am trying to understand conceptually in computer graphics &lt;strong&gt;how one might implement an infinite (or perceptually infinite) coordinate space&lt;/strong&gt; to take into account lines that go outside the range of my pixel array.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, consider that my pixel array represents a 500x500 pixel space. If I draw a line from (0, 250) to (7000, 100), I would ideally like the line would be drawn to that coordinate that is out of view with the accurate slope of the line maintained.&lt;/p&gt;&#xA;" OwnerUserId="11446" LastActivityDate="2019-11-09T00:01:53.957" Title="Infinite 2D Coordinate Space" Tags="&lt;2d-graphics&gt;&lt;pixels&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9333" PostTypeId="1" CreationDate="2019-11-09T14:17:50.963" Score="1" ViewCount="125" Body="&lt;p&gt;I'm a student in computer science and I have a project where I need to create a 3d scene with a train. I loaded the model correctly but the texture is a .mtl file.&#xA;So I looked the official documentation and I saw the MTLLoader. The problem is it's not in three.js and I need to use the code from&#xA; &lt;a href=&quot;https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/MTLLoader.js&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/mrdoob/three.js/blob/master/examples/js/loaders/MTLLoader.js&lt;/a&gt; &#xA;and I have no idea how to do it. &#xA;I tried to do an import like my teacher did in the sample of code he gave us :&#xA; import { OBJLoader } from './threejs/OBJLoader.js';&#xA;But it didn't work, the console told me I couldn't use THREE. in my mtl file. So I ask for help here ! Thank you&lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS : Sorry if I made mistakes or if I didn't use the website correctly it's the first time I post here&lt;/p&gt;&#xA;" OwnerUserId="11450" LastActivityDate="2019-11-09T14:17:50.963" Title="How to use MTLLoader in THREE.js" Tags="&lt;three.js&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9334" PostTypeId="1" CreationDate="2019-11-10T11:34:18.787" Score="1" ViewCount="148" Body="&lt;p&gt;I have implemented a ray tracer using reinforcement learning. But I see some problems.&#xA;I tried to divide the planes into rectangular grids. I searched the moire effect and realized that I can solve my problem by adding noise ( for example &lt;span class=&quot;math-container&quot;&gt;$\epsilon = 1e-5$&lt;/span&gt;) to the hit points on the diffuse surfaces, but even after doing this, I haven't seen any change. I created grid using ceiling function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems that I shouldn't use the ceiling function (to understand which cell current hit point is in) and use another algorithm to find in which rectangular cells, the hit points are. Could someone tell me which algorithm to use?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1xPBD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1xPBD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 2: I sample primary rays randomly in each pixel without jittering. Is it the cause of moire effect? Do I have to use stratified sampling?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 3: I have to show some parts of code:&#xA;This function generates a ray inside patches on sphere:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function Q_dir(ith::Int64)&#xA;    i = ceil(Int64, ith/H)&#xA;    j = ith - H*(i-1)&#xA;    u = (i-rand())/V&#xA;    ϕ = 2π*(j-rand())/H&#xA;    return Vec3(cos(ϕ)*sqrt(1.0 - u*u), sin(ϕ)*sqrt(1.0 - u*u), u)&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This function returns the index of a rectangular cell on each plane which contains the hit point:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function find_state(a::Float64, a1::Float64, a2::Float64, b::Float64, b1::Float64, b2::Float64)&#xA;    return [ceil(Int64, M*(abs(a)/(a2-a1))),   ceil(Int64, N*(abs(b)/(b2-b1)))]&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Ant this intersection function, returns the hit point and the cell&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;function intersect!(plane::xzPlane, ray::Ray)&#xA;    x1 = plane.a1&#xA;    x2 = plane.a2&#xA;    z1 = plane.b1&#xA;    z2 = plane.b2&#xA;    t = (plane.y - ray.org.y)/ray.dir.y&#xA;    point = ray.org + t*ray.dir&#xA;    if x1 &amp;lt; point.x &amp;lt; x2 &amp;amp;&amp;amp; z1 &amp;lt; point.z &amp;lt; z2 &amp;amp;&amp;amp; 0 &amp;lt; t&#xA;        hsect, wsect = find_state(point.x, x1, x2, point.z, z1, z2)&#xA;        normal = Vec3(0,1,0)&#xA;        return HitPoint(t, point , normal, hsect, wsect)&#xA;    else&#xA;        return HitPoint()&#xA;    end&#xA;end&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem is surely related to this part, because I can reproduce the results of the paper. My only problem is this artifact.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 4: When I generate a ray uniformly through each uniformly selected stratum, everything works fine. But when I generate a ray uniformly through importance sampled stratum (each stratum has a different value), I encounter this problem. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT 5: Sampling discretized hemisphere is surely part of the problem. I guess the Q_dir function is causing some problems. Here is another generated photo:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/vmYeF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vmYeF.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;H in Q-dir function is equal to 6. The number of half-lines generated on the floor equals 6. So this sampling method is incorrect. &lt;/p&gt;&#xA;" OwnerUserId="11316" LastEditorUserId="11316" LastEditDate="2019-11-28T17:39:20.870" LastActivityDate="2019-11-28T17:39:20.870" Title="Strange behaviour when tracing rays through hemisphere patches" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9336" PostTypeId="1" AcceptedAnswerId="9348" CreationDate="2019-11-11T07:50:08.310" Score="0" ViewCount="116" Body="&lt;p&gt;So I've written a personal volume renderer which currently visualizes datasets (CT-Scans mostly) that have a &lt;code&gt;.raw&lt;/code&gt; extension and the values are in the range &lt;code&gt;0-255&lt;/code&gt; or &lt;code&gt;uint8&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I searched the net and found some datasets that had &lt;code&gt;uint16&lt;/code&gt; (ranging from &lt;code&gt;0-4095&lt;/code&gt;) and &lt;code&gt;float&lt;/code&gt; which was arbitrary but went from like &lt;code&gt;0-20&lt;/code&gt; or something. I think the &lt;code&gt;uint16&lt;/code&gt; dataset corresponds to values in Hounsfield scale but I'm unsure of how do I map these to 0-255.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I haven't implemented any fancy transfer functions currently. For the &lt;code&gt;uint8&lt;/code&gt; datasets I just read the isovalues from the dataset and use that value for all the channels (r,g,b) as it is giving me a grayscale image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:- To clarify further, I have implemented a gpu based ray marching algorithm taking help from this site &lt;a href=&quot;http://graphicsrunner.blogspot.com/2009/01/volume-rendering-101.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, I'm taking the datasets from &lt;a href=&quot;https://klacansky.com/open-scivis-datasets/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, As mentioned in the comments I don't really know how you should interpret these values, but a quick read shows that normally the CT data is based on Hounsfield units which represents density afaik.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2019-11-12T16:07:28.330" LastActivityDate="2019-11-15T09:51:20.147" Title="How to handle different data types (uint8, uint16, float) in Volume Datasets?" Tags="&lt;volumetric&gt;&lt;volume-rendering&gt;" AnswerCount="2" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9337" PostTypeId="2" ParentId="7769" CreationDate="2019-11-12T08:21:55.943" Score="2" Body="&lt;p&gt;From what I've found, signed distance fields are not suited for minification (drawing the text on fewer pixels on screen than it covers in the texture), no matter how you mip-map them. Their main use case is magnification, and they shine here, because you don't need to increase the size of the distance field texture when the renderered object increases in size on screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To render (e.g. text) with signed distance fields:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the texture should be large enough so that it represents the full geometric detail of the object you're trying to render. A good rule of thumb is that each line/stroke of your glyphs in the texture should be at least 2 pixels wide.&lt;/li&gt;&#xA;&lt;li&gt;the object that you draw on screen with a distance field-based texture should be larger on screen that in the texture (e.g. a glyph that covers 64x64 pixels in the distance field texture should cover at least 64 pixels in each direction on screen)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;If those properties don't hold for your use case then better use a directly rasterized texture - not a distance field - , as those mip-map much better.&lt;/p&gt;&#xA;" OwnerUserId="11456" LastActivityDate="2019-11-12T08:21:55.943" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9338" PostTypeId="2" ParentId="9336" CreationDate="2019-11-12T15:30:47.943" Score="1" Body="&lt;p&gt;It seems you want to work with values between 0-255. For uint16 datasets, you can put it inside 0-255 range like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$newValue = 255 * \frac{oldValue}{(2^{16} - 1)}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$oldValue$&lt;/span&gt; is an uint16 value and &lt;span class=&quot;math-container&quot;&gt;$2^{16} - 1$&lt;/span&gt; is the uint16 max number. For the float ones without any previous knowledge about its range, you could read all the values from the dataset in order to find out the min and the max values. Then, you could map this way:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$newValue = 255 * \frac{oldValue - min}{max - min}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The key idea is to map first to range 0-1 and then map it to 0-255 by multiplying it by 255. Don't forget to round/ceil/floor your value as you want an integer, not a float number.&lt;/p&gt;&#xA;" OwnerUserId="11436" LastActivityDate="2019-11-12T15:30:47.943" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9339" PostTypeId="1" AcceptedAnswerId="9340" CreationDate="2019-11-12T15:33:48.253" Score="1" ViewCount="516" Body="&lt;p&gt;Hi i am rather new to computergraphics but i am trying to map an equirectangular image (360 video) to the inside of a sphere now i found the following formula to do this. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;phi = 2*Pi*u&#xA;cos(theta) = 2*v -1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But how do i get &lt;code&gt;u&lt;/code&gt; and &lt;code&gt;v&lt;/code&gt; ? In the article he talks about this: &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;So we can just project the sphere points in the xy plane onto the unit radius cylinder and unwrap it!   If we have such an image with texture coordinates (u,v) in [0,1]^2&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;But how do i get those texture coordinates from and image with lets say the following dimensions 4096x2048 pixels?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry if this is a bit vague, i am trying to understand it myself. If clarification is needed i am happy to edit my question!&lt;/p&gt;&#xA;" OwnerUserId="11458" LastActivityDate="2019-11-12T15:55:46.733" Title="convert image pixel dimensions to UV" Tags="&lt;texture&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9340" PostTypeId="2" ParentId="9339" CreationDate="2019-11-12T15:55:46.733" Score="1" Body="&lt;p&gt;UV coordinates are defined such that (0, 0) is your lower left (or upper left, depending on what you're working with) corner of the image and (1, 1) the opposite corner (technically (1, 1) is outside the UV range, but we ignore this for easiness sake). Thus, if you want the exact middle, you obviously get (0.5, 0.5)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now with your image, the first pixel lower left is the pixel at (0, 0) as well. The pixel in the opposite corner is (4095, 2047). &#xA;To get to the (1, 1) corner, you need to take that corner pixel and divide it's coordinates by the image's width and height respectively. here you will see, that the (1, 1) does not fit exactly:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$u = 4095 / 4096 = 0.99976$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$v = 2047 / 2048 = 0.99951$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The same principle applies to any other pixel of your image, you just have to divide by the image's width in pixels.&#xA;Your center pixel is at (2047, 1023) (or the image borders on this pixel and three of its neighbours). The resulting UVs are:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$u = 2047 / 4096 = 0.49975$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$v = 1023 / 2048 = 0.49951$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2019-11-12T15:55:46.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9341" PostTypeId="1" CreationDate="2019-11-12T17:38:12.727" Score="2" ViewCount="86" Body="&lt;p&gt;I'm out of my wits. I've been working an a voxel game for the last couple of years, written in C# and OpenTK (=OpenGL backend)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've been struggling to achieve a stable frame rate and one of the major issues I can see after countless hours of frame profiling, is that the windows 10 nvidia graphics driver seems to act in some really strange ways.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It almost seems as if my card is in some sort of low power mode by default in which it renders at arbitrarily changing speeds, but once its put under load it renders reliably again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can reliably reproduce this by launching my game with non-demanding graphics setting, then up the GPU load with dynamic shadows, god rays and such, then lowering the demands again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is all with VSync enabled (and in the nvidia control panel the vsync option is set to &quot;Let the application decide&quot;)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are some frame rate graphs:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Low gpu load, draw calls randomly take a few milliseconds longer, then it almost seems to overcompensate by drawing the next frame too fast.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/odOeA.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/odOeA.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I increase the gpu load for a few seconds and lower it again. The frame rate gets buttery smooth:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nLDtH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nLDtH.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As mentioned I carefully profiled this issue and it always seems that the time is spend on various draw calls (usually GLMultiDrawElements), but highly inconsistent.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone have an idea what the heck is going on here and how I can fix this?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any call I could make to NVAPI to force it into this hypothetical high power mode?&lt;/p&gt;&#xA;" OwnerUserId="11459" LastActivityDate="2019-12-12T21:02:00.233" Title="Strange VSync issues on a GTX 1060" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9342" PostTypeId="2" ParentId="9341" CreationDate="2019-11-12T20:11:00.063" Score="1" Body="&lt;p&gt;Ok so setting the &quot;power management mode&quot; to &quot;prefer maximum performance&quot; in the nvidia control panel seems to fix it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I already create an optimus profile automatically through code all I had to do was to set this value as well.&lt;/p&gt;&#xA;" OwnerUserId="11459" LastActivityDate="2019-11-12T20:11:00.063" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9343" PostTypeId="1" AcceptedAnswerId="9345" CreationDate="2019-11-13T16:08:05.587" Score="0" ViewCount="111" Body="&lt;p&gt;In PBRT, a BSDF is represented as an array of BxDF lobes. Each lobe sets a bitflag representing what kind of lobe it is. (Specular, Diffuse, Reflection, Transmission, etc.) I'm investigating how PBRT implemented sampling a BSDF for an input direction, wi.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Following standard Monte Carlo sampling, I was expecting the code to randomly sample an appropriate lobe, then set the &lt;span class=&quot;math-container&quot;&gt;$pdf = pdf_{picked}/n$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is the number of lobes of the appropriate type. However this isn't what PBRT does. My question is why? To go in futher, this is the PBRT function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Spectrum BSDF::Sample_f(const Vector3f &amp;amp;woWorld, Vector3f *wiWorld,&#xA;                        const Point2f &amp;amp;u, Float *pdf, BxDFType type,&#xA;                        BxDFType *sampledType) const {&#xA;    // Choose which _BxDF_ to sample&#xA;    int matchingComps = NumComponents(type);&#xA;    if (matchingComps == 0) {&#xA;        *pdf = 0;&#xA;        if (sampledType)&#xA;            *sampledType = BxDFType(0);&#xA;        return Spectrum(0);&#xA;    }&#xA;    int comp = std::min((int)std::floor(u[0] * matchingComps), matchingComps - 1);&#xA;&#xA;    // Get _BxDF_ pointer for chosen component&#xA;    BxDF *bxdf = nullptr;&#xA;    int count = comp;&#xA;    for (int i = 0; i &amp;lt; nBxDFs; ++i)&#xA;        if (bxdfs[i]-&amp;gt;MatchesFlags(type) &amp;amp;&amp;amp; count-- == 0) {&#xA;            bxdf = bxdfs[i];&#xA;            break;&#xA;        }&#xA;&#xA;    // Remap _BxDF_ sample _u_ to &lt;span class=&quot;math-container&quot;&gt;$[0,1)^2$&lt;/span&gt;&#xA;    Point2f uRemapped(std::min(u[0] * matchingComps - comp, OneMinusEpsilon),&#xA;                      u[1]);&#xA;&#xA;    // Sample chosen _BxDF_&#xA;    Vector3f wi, wo = WorldToLocal(woWorld);&#xA;    if (wo.z == 0)&#xA;        return 0.;&#xA;    *pdf = 0;&#xA;    if (sampledType) *sampledType = bxdf-&amp;gt;type;&#xA;    Spectrum f = bxdf-&amp;gt;Sample_f(wo, &amp;amp;wi, uRemapped, pdf, sampledType);&#xA;&#xA;    if (*pdf == 0) {&#xA;        if (sampledType) *sampledType = BxDFType(0);&#xA;        return 0;&#xA;    }&#xA;    *wiWorld = LocalToWorld(wi);&#xA;&#xA;    // Compute overall PDF with all matching _BxDF_s&#xA;    if (!(bxdf-&amp;gt;type &amp;amp; BSDF_SPECULAR) &amp;amp;&amp;amp; matchingComps &amp;gt; 1)&#xA;        for (int i = 0; i &amp;lt; nBxDFs; ++i)&#xA;            if (bxdfs[i] != bxdf &amp;amp;&amp;amp; bxdfs[i]-&amp;gt;MatchesFlags(type))&#xA;                *pdf += bxdfs[i]-&amp;gt;Pdf(wo, wi);&#xA;    if (matchingComps &amp;gt; 1)&#xA;        *pdf /= matchingComps;&#xA;&#xA;    // Compute value of BSDF for sampled direction&#xA;    if (!(bxdf-&amp;gt;type &amp;amp; BSDF_SPECULAR)) {&#xA;        bool reflect = Dot(*wiWorld, ng) * Dot(woWorld, ng) &amp;gt; 0;&#xA;        f = 0.;&#xA;        for (int i = 0; i &amp;lt; nBxDFs; ++i)&#xA;            if (bxdfs[i]-&amp;gt;MatchesFlags(type) &amp;amp;&amp;amp;&#xA;                ((reflect &amp;amp;&amp;amp; (bxdfs[i]-&amp;gt;type &amp;amp; BSDF_REFLECTION)) ||&#xA;                 (!reflect &amp;amp;&amp;amp; (bxdfs[i]-&amp;gt;type &amp;amp; BSDF_TRANSMISSION))))&#xA;                f += bxdfs[i]-&amp;gt;f(wo, wi);&#xA;    }&#xA;&#xA;    return f;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In pseudo-code, it looks to be doing the following:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Get the number of lobes that match the ones we asked for&#xA;numMatchingLobes = NumComponents(type);&#xA;&#xA;// Early out check&#xA;if (numMatchingLobes == 0):&#xA;    return&#xA;&#xA;// Randomly pick one of the matching lobes&#xA;pickedBxDF = Rand()&#xA;&#xA;// Transform wo from world space to local space&#xA;// Then sample the chosen BxDF to get f, pdf, and wi&#xA;f, pdf, wi = pickedBxDF.sample_f(woWorld.ToLocal())&#xA;&#xA;// Early out check&#xA;if (pdf == 0):&#xA;    return&#xA;&#xA;// Transform wi to world space&#xA;wiWorld = wi.ToWorld()&#xA;&#xA;// Add all of the pdfs of the matching lobes if the picked BxDF wasn't specular&#xA;if pickedBxDF.type not Specular &amp;amp;&amp;amp; numMatchingLobes &amp;gt; 1:&#xA;    for BxDF in matchingLobes:&#xA;        pdf += BxDF.pdf(wi, wo)&#xA;&#xA;// Divide the resulting pdf by the number of matching lobes&#xA;pdf /= numMatchingLobes;&#xA;&#xA;&#xA;// Calculate the combined f if the picked BxDF isn't specular&#xA;if pickedBxDF.type not Specular:&#xA;    // Reset f to zero&#xA;    f = 0&#xA;&#xA;    // Add each BxDF's f, iff it matches reflection / transmission&#xA;    reflect = wo and wi on same hemisphere as geoNormal&#xA;    for BxDF in matchingLobes:&#xA;        // Add the &#xA;        if reflect and BxDF.type == Reflection:&#xA;            f += BxDF.f(wo, wi)&#xA;        elif !reflect and BxDF.type == Transmission:&#xA;            f += BxDF.f(wo, wi)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The part I'm not understanding is why it adds the pdf's of all the matching lobes on top of the already calculated pdf. This seems like it would double count the pdf of the picked lobe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if there are two matching lobes, called A and B. A is picked.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We calculate f, pdf, and wi with A. Then with a for loop, we add the pdf for A and B and divide by 2. Aka:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{A + A + B}{2}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This doesn't seem right. Is PBRT code wrong? Should it be resetting the pdf, similar to the f calculation code below it?&lt;/p&gt;&#xA;" OwnerUserId="310" LastActivityDate="2019-11-13T21:20:43.117" Title="How to calculate the PDF of a multi-lobe BSDF" Tags="&lt;sampling&gt;&lt;monte-carlo&gt;&lt;bsdf&gt;&lt;pbrt&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9345" PostTypeId="2" ParentId="9343" CreationDate="2019-11-13T21:20:43.117" Score="1" Body="&lt;p&gt;The summation doesn't include the BxDF that was picked for sampling. Look again at this line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if (bxdfs[i] != bxdf &amp;amp;&amp;amp; bxdfs[i]-&amp;gt;MatchesFlags(type))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here &lt;code&gt;bxdf&lt;/code&gt; is the one that was sampled earlier, so when it iterates to that one it skips it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-11-13T21:20:43.117" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9346" PostTypeId="2" ParentId="7769" CreationDate="2019-11-14T02:29:41.417" Score="3" Body="&lt;p&gt;When you are making an SDF, you commonly have infinitely detailed data (like, bezier curves making up a letter) that you are making into an SDF image of a specific size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you make one that is 64x64, the first mip will be 32x32. The right way to make that mip is to do the original process of creating the SDF texture from the source data, but do it at 32x32 instead of 64x64. Repeat for the other mips.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It will break down at lower resolutions though, but that is just the nature of how SDFs work. The more correct, but slower way is to do super sampling. Take multiple samples at different places in the pixel and average the result.&lt;/p&gt;&#xA;" OwnerUserId="56" LastEditorUserId="56" LastEditDate="2019-11-14T02:59:30.000" LastActivityDate="2019-11-14T02:59:30.000" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9347" PostTypeId="2" ParentId="9325" CreationDate="2019-11-14T05:26:09.723" Score="5" Body="&lt;p&gt;An easy way to parallelize a path tracer is to have different threads (or machines!) work on different parts of the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For instance, you could break the image into a 20x20 grid and have each thread grab a tile, render it, and try to grab another tile.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A way I like to divy out this work is to use an atomic integer. Each thread atomically increments the integer and uses the value as an index into the work to do. They repeat this process until the atomic integer goes out of bounds.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2019-11-14T05:26:09.723" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9348" PostTypeId="2" ParentId="9336" CreationDate="2019-11-15T09:51:20.147" Score="2" Body="&lt;p&gt;Ok after searching a whole lot on the internet I found a &lt;a href=&quot;https://humanhealth.iaea.org/HHW/MedicalPhysics/TheMedicalPhysicist/Studentscorner/HandbookforTeachersandStudents/Chapter_11.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;slide&lt;/a&gt; which answered most of my questions and doubts. I'm dumping it here in-case anybody else is curious what these datasets usually contain and what should be (in my opinion) the correct way to handle mappings.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So apparently the CT scanner always records the densities of the substances in Hounsfield Scale. The Hounsfield Scale itself is a little interesting. For body organs and stuff, the scale has the range from -1024 to 3000. This was the scale I talked about earlier as when normalized the values usually lie between 0-4096. However metals usually go past this 3k boundary and some metals like stainless steel and gold having HU number as high as 13k and 30k respectively. This is usually called the &quot;extended&quot; Hounsfield Scale.&#xA;Some volumetric datasets contain data for computer simulations mostly fluids etc. For these type of datasets either density or flow velocity is captured. Precision is important for these datasets hence &lt;code&gt;float&lt;/code&gt; is used.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hence the &lt;code&gt;uint8&lt;/code&gt; datasets are probably grey-scale data converted from the original HU units. &lt;code&gt;uint16&lt;/code&gt; datasets contain the original Hounsfield data while &lt;code&gt;float&lt;/code&gt; may contain density or velocity. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now for the mapping part, as others stated one way might be to just divide by the max value of the data type or the max value of the data itself, to get the &lt;code&gt;uint16&lt;/code&gt; or &lt;code&gt;float&lt;/code&gt; data in &lt;code&gt;0-1&lt;/code&gt; range then multiply by &lt;code&gt;255&lt;/code&gt; to get a grey-scale image. However doing so may lower the contrast and hide minute details. For example, dividing a &lt;code&gt;uint16&lt;/code&gt; dataset that contained only HU units in range &lt;code&gt;300-2000&lt;/code&gt; with the &lt;span class=&quot;math-container&quot;&gt;$2^{16}$&lt;/span&gt; will map the HU units to only a small range of grey values. Dividing by &lt;code&gt;2000&lt;/code&gt; in this case is surely better. However after reading how CT-scanners work, it's better to let the user set the minimum and maximum range of Hounsfield units they wish to observe. This is usually called the &lt;strong&gt;window width&lt;/strong&gt;. And then map this window width to the whole &lt;code&gt;0-255&lt;/code&gt; range of grey levels as YardenJ2R mentioned in his second formula. This is more in line with how radiologists visualise the data. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For fancy transfer functions which I haven't implemented yet, we might have to convert the Hounsfield units to opacity or grey scale as mentioned above then map that opacity to color or there might be a way to directly map it to colors using a LUT as defined by the user's control point settings.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-11-15T09:51:20.147" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9350" PostTypeId="1" CreationDate="2019-11-16T04:29:37.950" Score="1" ViewCount="65" Body="&lt;p&gt;I have two meshes that I want to align, I'll call the reference mesh the &lt;em&gt;template mesh&lt;/em&gt; and the other is the &lt;em&gt;target mesh&lt;/em&gt;. I have 1 point-to-point correspondence between my template and target mesh. &#xA;I am trying to find the uniform scale and translation to align these 2 meshes. &#xA;This is what I've been doing :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My optimal transformation matrix M = &lt;code&gt;[M11 0 0 M14; 0 M11 0 M24 ; 0 0 M11 M34; 0 0 0 1 ]&lt;/code&gt; , here M11 is my scale and M14, M24, M34 are the translation in x,y and z.&#xA;I represent my points from the template mesh as homogeneous coordinates -&gt; A = &lt;code&gt;[xt, yt, zt, 1]&lt;/code&gt;&#xA;the corresponding points on the target mesh -&gt; B = &lt;code&gt;[xp, yp, zp, 1]&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;xp = M11*xt + M14&#xA;yp = M11*xt + M24&#xA;zp = M11*xt + M34&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is how I form and solve my least sqauares problem :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;findMin((X*T - B)^2) &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where T, X and B are  :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  B  =      X      *   T&#xA;  [xp  [ xt 1 0 0    [M11&#xA;   yp =  yt 0 1 0  *  M14&#xA;   zp    zt 0 0 1     M24&#xA;   1]    1  1 1 1]    M34]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is how I find the least squares fit for T :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;(Inverse(X'*X))*X'*B&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am not sure if this is the right way to go about this, particularly&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is it acceptable to add the row of ones in the last row of matrix X&#xA;in my least sqaures problem? It has no physical meaning, I just&#xA;added it to make dimensions match and ensure that the matrix X is&#xA;invertible.&lt;/li&gt;&#xA;&lt;li&gt;With this I get negative scale values, is there a way I can add constraints in the least squares problem to ensure that I get a scale that is always greater than 0? Is this even the right approach to find a scale value?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="9528" LastActivityDate="2019-11-16T04:29:37.950" Title="Least squares for uniform scale and translation" Tags="&lt;optimisation&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9352" PostTypeId="1" CreationDate="2019-11-16T18:26:01.453" Score="0" ViewCount="41" Body="&lt;p&gt;&lt;a href=&quot;http://graphics.stanford.edu/papers/veach_thesis/chapter8.ps&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphics.stanford.edu/papers/veach_thesis/chapter8.ps&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In chapter 8 of his thesis which he talks about the three-point form of the transport equations, equation (8.1) in particular, it seems the integrand will expand into something that contains a &lt;span class=&quot;math-container&quot;&gt;$\cos^2(\theta_i^\prime)$&lt;/span&gt; term. One of the cosine terms comes from the &lt;span class=&quot;math-container&quot;&gt;$G$&lt;/span&gt;, and the other one comes the BSDF &lt;span class=&quot;math-container&quot;&gt;$f_s$&lt;/span&gt; which is defined with respect to the projected solid angle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I look at PBRT V3's implementation, BSDF is defined upon solid angle. However, the geometry term &lt;span class=&quot;math-container&quot;&gt;$G$&lt;/span&gt; is the same as Veach's.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;Spectrum G(const Scene &amp;amp;scene, Sampler &amp;amp;sampler, const Vertex &amp;amp;v0,&#xA;           const Vertex &amp;amp;v1) {&#xA;    Vector3f d = v0.p() - v1.p();&#xA;    Float g = 1 / d.LengthSquared();&#xA;    d *= std::sqrt(g);&#xA;    if (v0.IsOnSurface()) g *= AbsDot(v0.ns(), d);&#xA;    if (v1.IsOnSurface()) g *= AbsDot(v1.ns(), d);&#xA;    VisibilityTester vis(v0.GetInteraction(), v1.GetInteraction());&#xA;    return g * vis.Tr(scene, sampler);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This implies there is only one &lt;span class=&quot;math-container&quot;&gt;$\cos(\theta_i^\prime)$&lt;/span&gt; term. Am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="11474" LastActivityDate="2019-11-16T18:26:01.453" Title="Questions in Veach path-space formulation" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9353" PostTypeId="1" CreationDate="2019-11-16T19:11:49.630" Score="1" ViewCount="36" Body="&lt;p&gt;Let's say I have some shader program in DirectX or OpenGL rendering a full screen quad. And in a pixel/fragment shader I sample some huge textures at random texture coordinates. That is one same texture coordinate for all texture samplings in one shader invocation, but it is various among different shader invocations. These fetch operations produce performance drop, I even think that due to the size of the textures the GPU texture cache is not big enough and is used not efficiently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I have a theoretical question: can I optimize the performance by using some low-resolution like 32x32 &lt;em&gt;mask&lt;/em&gt; textures, which are built by mipmapping the large textures, and if a value in a mask texture at given texture coordinate at some higher mip level is not appropriate, then I don't need to perform texture fetches at full-size level 0? Something like this in HLSL (GLSL code is pretty similar, but there is no [branch] attribute):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float2 tc = calculateTexCoordinates();&#xA;bool performHeavyComputations = testValue(largeMipmappedTexture.SampleLevel(sampler, tc, 5));&#xA;&#xA;float result = 0;&#xA;&#xA;[branch]&#xA;if (performHeavyComputations)&#xA;{&#xA;    result += largeMipmappedTexture.SampleLevel(sampler, tc, 0);&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;About 50% of texels at mip level 5 will not pass the test. And so a lot of shader invocations should not sample the full-size textures.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I am introducing branching in the code. May this branching hurt the performance even worse than sampling the full-size texture even if that is not needed? Different GPUs may behave differently, some may not even support branching, will they perform &lt;strong&gt;two&lt;/strong&gt; fetches instead of one?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can test this code on some machines later, but my question is theoretical.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And can you suggest another optimizations, if this won't work properly ?&lt;/p&gt;&#xA;" OwnerUserId="10193" LastEditorUserId="10193" LastEditDate="2019-11-16T19:17:08.297" LastActivityDate="2019-11-16T19:17:08.297" Title="Optimizing texture fetches with higher mip levels" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;performance&gt;&lt;directx&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9354" PostTypeId="1" CreationDate="2019-11-17T08:12:14.837" Score="2" ViewCount="225" Body="&lt;p&gt;Does anyone happen to know the latency difference between copying a texture on cpu (using, say, &lt;code&gt;memcpy&lt;/code&gt;) compared to gpu (using, say, &lt;code&gt;CopyResource&lt;/code&gt;)? I would do a perf test myself, but I'm not actually sure how to do the trace for the &lt;code&gt;CopyResource&lt;/code&gt;. A rule of thumb would be fine, it doesn't have to be exact, I just figure that the GPU is faster than the cpu for this but am just curious how expensive a copy of, say, a 1920x1080 texture is.&lt;/p&gt;&#xA;" OwnerUserId="11475" LastActivityDate="2020-11-09T23:04:25.410" Title="Latency difference between texture copy on GPU vs CPU?" Tags="&lt;gpu&gt;" AnswerCount="3" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9355" PostTypeId="1" AcceptedAnswerId="9356" CreationDate="2019-11-17T14:29:32.617" Score="0" ViewCount="39" Body="&lt;p&gt;Is there a way to change a picture so it would fail to match against existing copy of the same picture on the big social networks such as Facebook, Twitter, Instagram, Tinder and others? Desired result should be as close as possible to the original.&lt;/p&gt;&#xA;" OwnerUserId="11476" LastActivityDate="2019-11-17T19:30:52.803" Title="How to change a picture to fail comparison algorithms?" Tags="&lt;image-comparison&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9356" PostTypeId="2" ParentId="9355" CreationDate="2019-11-17T19:30:52.803" Score="2" Body="&lt;p&gt;It's dependent on the algorithm used for comparison, but if you have access to that algorithm, you can add small amounts of noise to pixels randomly until it misclassifies the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you had deeper knowledge of the algorithm used, and it was differentiable, you could use gradient descent (ascent) to modify the image to increase the error of what was detected. This is the reverse of what you do when training image comparisons/classifiers which modify the weights to minimize the error.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in short, if you dont have much knowledge of how the algorithm used works, I personally would try adding noise to pixels randomly, such that the image was still easily recognizable, but a decent amount of noise was added in.&lt;/p&gt;&#xA;" OwnerUserId="56" LastActivityDate="2019-11-17T19:30:52.803" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9357" PostTypeId="1" AcceptedAnswerId="9362" CreationDate="2019-11-17T22:08:03.190" Score="2" ViewCount="205" Body="&lt;p&gt;I am currently implementing spherical lights in my DirectX game engine. I decided to build the shading formula from the classical rendering equation. Here is what I get:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/MiwIQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MiwIQ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The simplifications show that the cosine term should be removed for spherical lights since power is a Flux.&#xA;Here the problem. While looking for recourses online I found that engines always multiply by the cosine term, even for spherical lights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it wrong or am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="11479" LastEditorUserId="11479" LastEditDate="2019-11-18T19:34:17.680" LastActivityDate="2019-11-18T22:00:09.013" Title="Rendering equation for spherical lights" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;lighting&gt;&lt;brdf&gt;&lt;directx&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9360" PostTypeId="2" ParentId="8989" CreationDate="2019-11-18T10:12:41.393" Score="0" Body="&lt;p&gt;Sorry to post such a silly solution but apparently the problem was reading 16 bit uint data into 8bit uint array. This was the reason for inexplainable noise, interleaving and other artifacts. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;After I explored &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/9336/how-to-handle-different-data-types-uint8-uint16-float-in-volume-datasets?noredirect=1#comment14110_9336&quot;&gt;more&lt;/a&gt; about what the medical datasets actually represent and what flavors they come in (8,16,32bit) I managed to solve the problem.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2019-11-18T10:12:41.393" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9361" PostTypeId="1" CreationDate="2019-11-18T15:12:23.970" Score="0" ViewCount="95" Body="&lt;p&gt;I have created two animations:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;One where a &quot;camera&quot; moves towards the spheres creating an optic flow (1st GIF).The code can be found &lt;a href=&quot;https://www.codepile.net/pile/7pvd7rGJ&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;One where spheres move randomly in a 3D coordinates space (2nd GIF). To do so I have computed two angles theta and phi. The code can be found &lt;a href=&quot;https://www.codepile.net/pile/vWz91BKA&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I need to compute the speed of each sphere frame by frame in both animations, but I have no idea of the mathematics. I would assume that the formula would be different in the two animations. I have found only the calculation of 3D velocity, and I was wondering whether I could calculate the speed as a single value?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RKv9T.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RKv9T.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ETe7F.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ETe7F.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11191" LastActivityDate="2019-11-19T20:14:48.730" Title="Compute Speed of Spheres in 3D animation" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9362" PostTypeId="2" ParentId="9357" CreationDate="2019-11-18T22:00:09.013" Score="1" Body="&lt;p&gt;If you just want to explicitly sample an area light, then here's the general procedure you should follow. Pick light &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; out of &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; lights with some probability &lt;span class=&quot;math-container&quot;&gt;$p_i$&lt;/span&gt; (the other probabilities being &lt;span class=&quot;math-container&quot;&gt;$p_1,...,p_L$&lt;/span&gt;, a light may be picked through inverse transform sampling). Pick a point &lt;span class=&quot;math-container&quot;&gt;$\pmb{y}$&lt;/span&gt; on the surface of the light with some probability &lt;span class=&quot;math-container&quot;&gt;$q_i(\pmb{y})$&lt;/span&gt;. Then your estimator is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$I_N = \frac{1}{N}\sum_{k=1}^{N}\frac{1}{p_{i_k}q_{i_k}(\pmb{y}_k)}f(\pmb{z} \leftarrow \pmb{x} \leftarrow \pmb{y}_k)L_e(\pmb{y}_k\rightarrow\pmb{x})\frac{\cos\theta_x\cos\theta_{y_k}}{\|\pmb{x}-\pmb{y}_k\|^2_2}V(\pmb{x},\pmb{y}_k)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that this is only for direct illumination at point &lt;span class=&quot;math-container&quot;&gt;$\pmb{x}$&lt;/span&gt;. I have generalized it to a secondary estimator using &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; samples, so essentially you pick &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; points &lt;span class=&quot;math-container&quot;&gt;$\pmb{y}_1,...,\pmb{y}_N$&lt;/span&gt; on possibly different lights. This is an estimator that can directly be derived from the area formulation of the rendering equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L(\pmb{z} \leftarrow \pmb{x}) = L_e(\pmb{x} \leftarrow \pmb{z}) + \int_{\Omega}f(\pmb{z} \leftarrow \pmb{x} \leftarrow \pmb{y})L(\pmb{y}\rightarrow\pmb{x})\frac{\cos\theta_x\cos\theta_y}{\|\pmb{x}-\pmb{y}_k\|^2_2}V(\pmb{x},\pmb{y})\,dA(\pmb{y})$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The area formulation can be derived from the solid angle one, by using the identity:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$d\omega = \frac{\cos\theta_y}{r^2}dA$$&lt;/span&gt;,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;as well as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L_i(\pmb{x}, \omega) = L(r(\pmb{x},\omega) \rightarrow \pmb{x}) = L(\pmb{y} \rightarrow \pmb{x})V(\pmb{x},\pmb{y})$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-11-18T22:00:09.013" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9363" PostTypeId="2" ParentId="9361" CreationDate="2019-11-19T20:14:48.730" Score="1" Body="&lt;p&gt;I'd use the euclidean distance between two 3D positions. Velocity is distance over time. Time is a single frame in this case.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\sqrt{(x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you only move the camera, it is simply that frame of reference that moves, so all spheres have a relative velocity equal to the camera's velocity.&lt;/p&gt;&#xA;" OwnerUserId="9505" LastActivityDate="2019-11-19T20:14:48.730" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9364" PostTypeId="1" CreationDate="2019-11-20T02:16:08.820" Score="4" ViewCount="187" Body="&lt;p&gt;My major is mechanical, please forgive me for asking questions that may seem trivial to you. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I'm reading the following paper:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Dam, Erik B., Martin Koch, and Martin Lillholm. &lt;a href=&quot;https://archive.org/details/Erik_B_Dam_Martin_Koch_and_Martin_Lillholm___Quaternions_Interpolation_and_Animation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Quaternions, interpolation and animation&lt;/a&gt;. Vol. 2. Copenhagen: Datalogisk Institut, Københavns Universitet, 1998.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;On page 35, it says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Since quaternion space is four-dimensional, we cannot visualise the interpolated curves directly. We will always interpolate between unit quaternions, and the interpolated quaternions will always (with a few exceptions in chapter 6 on page 38 and 69) be unit quaternions. This means that we only need three dimensions to visualize the interpolation curves, &lt;strong&gt;because they lie on the surface of the unit sphere.&lt;/strong&gt; &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I don't quite get the last sentence: why only three dimensions are needed to visualize the unit quaternion or why unit quaternion lies on the surface of the unit sphere? I thought they lie on the unit hyper-sphere. Does the author assume that we are viewing the quaternions from the south pole of the hyper-sphere?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Second, I was also following this paper:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Ramamoorthi, R., &amp;amp; Barr, A. H. (1997). Fast construction of accurate quaternion splines.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I found they are also treating (plotting) a unit quaternion as a point on a unit sphere &lt;span class=&quot;math-container&quot;&gt;$\mathbb{S}^{2}$&lt;/span&gt;. I wonder if you could recommend some resources in why we can view a unit quaternion &lt;span class=&quot;math-container&quot;&gt;$q = (a+b\mathbf{i}+c\mathbf{j}+d\mathbf{k})$&lt;/span&gt; as a point on a unit sphere &lt;span class=&quot;math-container&quot;&gt;$\mathbb{S}^{2}$&lt;/span&gt;? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help is appreciated. Thank you. &lt;/p&gt;&#xA;" OwnerUserId="11492" LastEditorUserId="11492" LastEditDate="2019-11-20T22:00:10.297" LastActivityDate="2021-05-18T22:08:30.870" Title="Visualize the interpolated unit quaternion on the surface of the unit sphere" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;geometry&gt;" AnswerCount="3" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9365" PostTypeId="2" ParentId="9364" CreationDate="2019-11-20T13:02:34.687" Score="0" Body="&lt;p&gt;Because given 3 values of a unit quaterion we can derive the fourth value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which means there exists a &lt;a href=&quot;https://en.wikipedia.org/wiki/Bijection&quot; rel=&quot;nofollow noreferrer&quot;&gt;bijective&lt;/a&gt; mapping from unit quaternion to 3D space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Though for visualization you want the mapping that makes what is happening the most easily discernible. However a usable visualization doesn't need to be fully bijective.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2019-11-20T13:02:34.687" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9366" PostTypeId="1" CreationDate="2019-11-20T13:05:42.807" Score="1" ViewCount="46" Body="&lt;p&gt;In &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1718/what-is-the-simplest-way-to-compute-principal-curvature-for-a-mesh-triangle/9344?noredirect=1#comment14162_9344&quot;&gt;this post&lt;/a&gt;, Nathan-Reed gave a simple, neat, &quot;heuristic&quot; estimation for the discrete curvature at vertices of a mesh.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In a nutshell, it computes a curvature &lt;em&gt;along&lt;/em&gt; each edge incident to the vertex, then takes the geometric mean for the curvature in the vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is: why is it better to take the geometric mean, instead of the arithmetic mean?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it because that would resemble somewhat Gaussian curvature?&lt;/p&gt;&#xA;" OwnerUserId="11466" LastActivityDate="2019-11-20T13:05:42.807" Title="Question about simple estimation of the discrete curvature at vertices of a mesh" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9367" PostTypeId="1" CreationDate="2019-11-21T01:18:59.283" Score="0" ViewCount="561" Body="&lt;p&gt;In computer graphics Bresenham's line drawing algorithm used to draw line . But i want to know the properties why i can't draw vertical and horizontal line by this algorithm.&lt;/p&gt;&#xA;" OwnerUserId="11497" LastActivityDate="2019-11-21T01:18:59.283" Title="Is it possible to draw horizontal and vertical line with Bresenham's line drawing algorithm?" Tags="&lt;2d-graphics&gt;&lt;line-drawing&gt;&lt;pixel-graphics&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9368" PostTypeId="2" ParentId="9364" CreationDate="2019-11-21T08:18:16.893" Score="0" Body="&lt;p&gt;I think Fig. 1 in the referenced paper is only a 2D-sketch, as the unit quaternions lie on the 3-dimensional sphere embedded in four dimensions. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Quaternions are used to represent orientations / rotations and these can be associated with the axis-angle representation (determining the angle from the first quaternion coefficient and the axis from the last three coefficients.) However, I could think of a visualization in 3D, where a point in space is associated to a unit quaternion / or axis-angle: Place the point in direction of the axis &quot;angle&quot;-units away from the origin. This would be a sphere of radius two pi, where also internal points represent rotations. I dont know of a direct visualization in 3D of the quaternion coefficients. &lt;/p&gt;&#xA;" OwnerUserId="2695" LastActivityDate="2019-11-21T08:18:16.893" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9369" PostTypeId="1" CreationDate="2019-11-21T14:20:45.483" Score="1" ViewCount="278" Body="&lt;p&gt;After watching some Youtube tutorials I thought I had understood the concept of UV mapping:&lt;br&gt;&#xA;I have a net of triangles, and I have an image representing my texture.&lt;br&gt;&#xA;Now I tell the GPU which point of the image shall be mapped to which point of my triangle net, and then some magic happens inside the GPU to generate a textured object.&lt;br&gt;&#xA;IF I move a point of a triangle, the mapped texture is distorted accordingly.&lt;br&gt;&#xA;Correct so far?&lt;br&gt;&#xA;Now I read somewhere the following &quot;specification&quot; regarding UV mapping on a planar surface:&lt;br&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A three pixel wide texture belongs to every single triangle.&lt;br&gt;&#xA;Per triangle the following UV mapping shall be used:&lt;br&gt;&#xA;triangle point A: UV(0.2, 0.5)&lt;br&gt;&#xA;triangle point B: UV(0.5, 0.5)&lt;br&gt;&#xA;triangle point C: UV(0.8, 0.5)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem is that I don't understand what the author means:&lt;br&gt;&#xA;I have a three pixel wide texture, values are... whatever... 2,4,6. &lt;br&gt;Let's define coordinate 0, 0 for the left pixel and 1, 0 for the right one.&lt;br&gt; Then UV(0.2,0.5) means that point A of my triangle shall have value (0.8 * 2) + (0.2 * 4) = 2.4, point B then has value 4 (it's in the middle) and point C has value (0.2 * 4) + (0.8 * 6) = 5.6. &#xA;&lt;br&gt;Is it so?&lt;br&gt;&#xA;And all other points of the triangle are interpolated according to their coordinates based on these three corners? Or what happens to them?&lt;/p&gt;&#xA;" OwnerUserId="6346" LastEditorUserId="6346" LastEditDate="2019-11-21T15:52:09.027" LastActivityDate="2019-11-21T15:52:09.027" Title="UV mapping on triangles" Tags="&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9370" PostTypeId="1" CreationDate="2019-11-23T12:11:12.307" Score="1" ViewCount="116" Body="&lt;p&gt;I am not sure what is the correct way to do tone mapping and gamma correction in a Monte-Carlo Path Tracer. Should I apply tone mapping before or after averaging the samples?&lt;/p&gt;&#xA;" OwnerUserId="11452" LastActivityDate="2019-11-23T12:11:12.307" Title="Path tracing: How to do tone mapping and gamma correction?" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9371" PostTypeId="1" AcceptedAnswerId="9383" CreationDate="2019-11-23T21:03:09.270" Score="1" ViewCount="92" Body="&lt;p&gt;A &lt;a href=&quot;https://blender.stackexchange.com/q/158942/35559&quot;&gt;question&lt;/a&gt; has come up recently in Blender SE, remarking on the &lt;em&gt;absence&lt;/em&gt; of blur due to depth of field in reflections in a spherical surface. This is a real-life effect.. can anyone come up with a nice explanation of it?&lt;/p&gt;&#xA;" OwnerUserId="8432" LastActivityDate="2019-11-30T02:56:04.670" Title="Why are reflections in a spherical surface sharp, regardless of depth of field?" Tags="&lt;reflection&gt;&lt;depth-of-field&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9372" PostTypeId="1" AcceptedAnswerId="9375" CreationDate="2019-11-24T02:55:31.043" Score="0" ViewCount="188" Body="&lt;p&gt;I have an OpenGL based graphics engine coming along quite nicely, but I'm currently stumped on a problem that arose after adding a new vertex shader output array.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vertex shader is outputing the usual things one would calculate per vertex to minimise fragment processing - eg fragment locations in tangent and light space etc which are done on a per light basis with currently an 8 light max per lighting zone.  Structure as below.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 460&#xA;const int cMaxZoneLightCount = 8;&#xA;&#xA;out vData&#xA;{&#xA;    vec3 vFragmentLocationWorld;  //  This vertice's location in world coords&#xA;    vec2 vTextureUV;&#xA;    vec4 vNormal;&#xA;    vec4 vFragmentLocationLightSpace[cMaxZoneLightCount];  // Light space location per light (up to 8)&#xA;    vec4 vFragmentLocationTextureSpace[cMaxZoneLightCount]; //  Transform for projective texture lights&#xA;    vec4 vViewLocationTangent;&#xA;    vec4 vFragmentLocationTangent;  //  Tangent space transforms for normal mapping&#xA;    vec4 vLightLocationTangent[cMaxZoneLightCount];  // Light locations in tangent space (up to 8)&#xA;    vec4 vLightMRPTangent[cMaxZoneLightCount];  //  MRP for tube lights in tangent space (up to 8)&#xA;    vec4 vTangent;&#xA;    vec4 vBitangent;  //  Pre computed vertex tangent/bitangent data.&#xA;}   vDataOut;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Everything was working fine until I added the vLightMRPTangent[cMaxZoneLightCount] array.  Adding that brings the total number of vertex outputs to 153 and I receive error C5041 when the shader compiles - &quot;cannot located suitable resources to bind variable... possibly large array&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is strange though because an int mvoc = GL_MAX_VERTEX_OUTPUT_COMPONENTS returns 37,154.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, the interesting thing is - if I make vLightMRPTangent[2] instead of 8, this brings the number of vertex shader outputs down to 129 and it works.  Similarly, a vLightMRPTangent[3] which would put it up to 133 output components generates a different but verbose and nasty link failure message.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So it's looking a lot like my still formidible GTX970 only wants to send 128 components down the pipeline!! (tell me that can't be right...)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm developing on Windows 10 with GLEW v2.1 and the November 2019 nVidia driver.  I'm not using any other extensions/libraries, eg glm/glut (doing all my matrix work myself).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can get around this by implementing subsequent features per pixel rather than per vertex, but that's a real pain because its going to result in sub-optimal efficiency which could become a big problem later.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas anyone?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cheers,&#xA;MWS&lt;/p&gt;&#xA;" OwnerUserId="11518" LastActivityDate="2019-11-24T14:44:46.197" Title="Stumped on GLSL error C5041 (cannot located suitable resources to bind variable... possibly large array" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9373" PostTypeId="2" ParentId="9371" CreationDate="2019-11-24T08:08:59.683" Score="1" Body="&lt;p&gt;Because the ball doesn't &quot;see&quot; the world through an imperfect lens system, whereas your camera in that case does. If you were to introduce an imperfect visual system around it, with a resulting blurring point spread function, you will get a blurry reflection.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-11-24T08:08:59.683" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9374" PostTypeId="1" CreationDate="2019-11-24T14:43:33.590" Score="3" ViewCount="98" Body="&lt;p&gt;I've just worked my way through &lt;a href=&quot;https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;this OpenGL shadow mapping tutorial&lt;/a&gt;.&#xA;While I understand the basic algorithm, one thing puzzles me:&#xA;During the 2nd render pass all vertices are transformed into the clip space of the light source. This is done by multiplying them with the light's view-projection matrix in the vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vs_out.FragPosLightSpace = lightSpaceMatrix * vec4(vs_out.FragPos, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, for texture lookup into the shadow map a perspective division is needed. This is done in the fragment shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float ShadowCalculation(vec4 fragPosLightSpace)&#xA;{&#xA;    // perform perspective divide&#xA;    vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;&#xA;    //continue w. texture lookup&#xA;    [...]&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So my question is - why can't I perform the perspective division in the vertex shader? I did try moving the division from fragment to vertex shader in my otherwise finished shadow mapping code, and ended up with some really weird artifacts. So I guess it has something to do with the interpolation performed by the rasterizer, but I would like a more detailed explanation if possible.&lt;/p&gt;&#xA;" OwnerUserId="11519" LastActivityDate="2019-11-24T14:43:33.590" Title="Projective Texture / Shadow Mapping -- Why is the perspective division performed in the fragment shader?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;shadow-mapping&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9375" PostTypeId="2" ParentId="9372" CreationDate="2019-11-24T14:44:46.197" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;This is strange though because an int mvoc = GL_MAX_VERTEX_OUTPUT_COMPONENTS returns 37,154.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That's the value of the &lt;em&gt;enumerator&lt;/em&gt;; it's a static, compile-time value. The actual runtime limit is queried from the implementation &lt;em&gt;using&lt;/em&gt; that enumerator. Typically via &lt;code&gt;glGetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, &amp;amp;mvoc)&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;tell me that can't be right...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Why not? Sending 128 components &lt;em&gt;per vertex&lt;/em&gt; is plenty.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You shouldn't be doing transformations into light-space in your VS; that should happen in your fragment shader. You should be sending the basic information to the FS needed for it to do its job: normals (and tangent/bitangent as needed), texture coordinates, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you find that your FS's performance is not what it needs to be, then the best thing you can do is reduce the number of FS executions. You can use a depth pre-pass to eliminate overdraw, so the only FS executions that happen are those which produces an actual visible element. Or you can go to full-on deferred rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this method of pre-computing large quantities of data per-vertex is not going to work. Interpolation of vertex data is not free, nor are the caches between the VS and the rasterizer.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-11-24T14:44:46.197" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9376" PostTypeId="1" AcceptedAnswerId="9378" CreationDate="2019-11-25T16:37:21.293" Score="1" ViewCount="214" Body="&lt;p&gt;As far as I know path tracers (or super-sampling antialiasing) typically calculate the final color of a single pixel by averaging the result of all samples taken inside that pixel. This gives a nice anti-aliasing effect on the edges, however has the side effect of slightly blurring textures, because they most certainly do not have enough samples for each pixel, so samples have to be guessed with some kind of filter (like bilinear). From a mathematical point of view, averaging those samples applies a box low-pass filter to the reconstructed texture. This causes blurring.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do path traced renderers/SSAA usually deal with this blur? Is there no way around it?&lt;/p&gt;&#xA;" OwnerUserId="11521" LastActivityDate="2019-11-27T18:15:23.493" Title="Multiple samples per pixel and texture blurring" Tags="&lt;pathtracing&gt;&lt;sampling&gt;&lt;antialiasing&gt;&lt;supersampling&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9377" PostTypeId="1" AcceptedAnswerId="9400" CreationDate="2019-11-25T17:58:40.240" Score="1" ViewCount="62" Body="&lt;p&gt;Is the normal distribution term D in the Cook-Torrance BRDF supposed to be between 0 and 1? What does this number actually represent?&lt;/p&gt;&#xA;" OwnerUserId="11452" LastActivityDate="2019-12-07T03:29:34.110" Title="Value range of normal distribution function" Tags="&lt;brdf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9378" PostTypeId="2" ParentId="9376" CreationDate="2019-11-27T18:15:23.493" Score="1" Body="&lt;p&gt;In signal processing, it is well-understood that you cannot accurately reproduce an analog signal of higher frequency than half the frequency of your digital sampling rate. That's just how the math works. Various aspects of rendering are just forms of signal processing, so this applies here too.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So you're going to get some kind of artifact. You have a choice: aliasing or noise (aka: blur). You're always going to have some of these. Aliasing artifacts are usually very noticeable and considered quite distracting. Human vision tends to focus on motion, and aliasing artifacts almost always create motion where none existed (&lt;em&gt;especially&lt;/em&gt; when animating). Human vision is generally much more tolerant of noise, as noise patterns don't appear to move nearly as much. Plus, our eyes have their own anti-aliasing filters that impart some noise to what we see, so we're somewhat used to it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Broadly speaking, you deal with it by not dealing with it, because it's preferable to the alternative. Yes, you can reduce the effect of noise with better anti-aliasing mechanisms, but broadly speaking, you're still going to have noise.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-11-27T18:15:23.493" CommentCount="12" ContentLicense="CC BY-SA 4.0" />
  <row Id="9379" PostTypeId="1" CreationDate="2019-11-28T19:29:32.677" Score="2" ViewCount="300" Body="&lt;p&gt;Why should we use Russian Roulette? Does it reduce ray tracing artifacts? &lt;/p&gt;&#xA;" OwnerUserId="11316" LastActivityDate="2019-12-02T16:30:31.757" Title="Why is Russian Roulette used in ray tracing?" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9381" PostTypeId="1" AcceptedAnswerId="9382" CreationDate="2019-11-29T06:46:12.513" Score="3" ViewCount="312" Body="&lt;p&gt;I would like to create program in JavaScript (JS) which draws &lt;a href=&quot;https://en.wikipedia.org/wiki/Mandelbrot_set&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mandelbrot set&lt;/a&gt; with arbitrary precision (zoom). In JS there is build in integer type &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt&quot; rel=&quot;nofollow noreferrer&quot;&gt;BigInt&lt;/a&gt; which support simple operations like +,*,/,power on arbitrary precision integer numbers. JS not support calculations on arbitrary precision floating point numbers. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;: Is there a way to perform calculations of Mandelbrot set using calculations based only on integers (with arbitrary precision) - if yes how to do it?&lt;/p&gt;&#xA;" OwnerUserId="9881" LastEditorUserId="9881" LastEditDate="2019-11-29T06:51:35.153" LastActivityDate="2019-11-29T08:09:58.340" Title="Is there a way to perform calculations of Mandelbrot set using only integer numbers?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9382" PostTypeId="2" ParentId="9381" CreationDate="2019-11-29T08:09:58.340" Score="4" Body="&lt;p&gt;Probably the easiest way to get an arbitrary precision Mandelbrot set using full-precision integers is to combine two integers into a rational number &lt;span class=&quot;math-container&quot;&gt;$p/q$&lt;/span&gt;. These numbers are added by finding the common denominator:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \frac{m}{n} + \frac{p}{q} = \frac{mq + np}{nq} $$&lt;/span&gt;&#xA;and multiplied by just multiplying the respective numerators and denominators:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \frac{m}{n} * \frac{p}{q} = \frac{mp}{nq} $$&lt;/span&gt;&#xA;Then a single point &lt;span class=&quot;math-container&quot;&gt;$\vec{p}$&lt;/span&gt; would be represented in rational coordinates by&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \vec{p} = \left( \frac{n_x}{d_x} , \frac{n_y}{d_y} \right) $$&lt;/span&gt;&#xA;and the iteration for the point would proceed&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{eqnarray*}&#xA;\vec{z} &amp;amp;\rightarrow&amp;amp; \vec{z}^2 + \vec{p} \\&#xA;\left( \frac{a_x}{b_x} , \frac{a_y}{b_y} \right) &amp;amp;\rightarrow&amp;amp;&#xA;\left( \frac{a_x^2}{b_x^2} - \frac{a_y^2}{b_y^2}&#xA;, \frac{2 a_x a_y}{b_x b_y} \right) +&#xA;\left( \frac{n_x}{d_x} , \frac{n_y}{d_y} \right)\\&#xA;&amp;amp;=&amp;amp;&#xA;\left( \frac{a_x^2 b_y^2 - a_y^2 b_x^2}{b_x^2 b_y^2} +&#xA;\frac{n_x}{d_x}&#xA;, \frac{2 a_x a_y}{b_x b_y} + \frac{n_y}{d_y} \right) \\&#xA;&amp;amp;=&amp;amp; \left(&#xA;\frac{(a_x^2 b_y^2 - a_y^2 b_x^2)d_x + n_x b_x^2 b_y^2}&#xA;     {b_x^2 b_y^2 d_x},&#xA;\frac{2 a_x a_y d_y + b_x b_y n_y}{b_x b_y d_y}&#xA;\right).&#xA;\end{eqnarray*}&lt;/span&gt;&#xA;Easy this may be, but I can't claim it'll be &lt;em&gt;fast&lt;/em&gt;; near the boundaries of the Mandelbrot set, the numerators and denominators in the iteration will get pretty big fairly soon, even if you reduce the rationals by dividing by the greatest common denominator.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2019-11-29T08:09:58.340" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9383" PostTypeId="2" ParentId="9371" CreationDate="2019-11-30T02:56:04.670" Score="2" Body="&lt;p&gt;There's no &lt;strong&gt;visible&lt;/strong&gt; blur for the same reason you often don't see blur in very wide angle lenses: the circle of confusion is much smaller than a pixel. But it is still there. An extreme example of this is fisheye lenses.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you had a camera with infinite resolution, such that you could zoom into the reflection on the ball, you would eventually see the blur. And it would be exactly the same blur as if you had aimed a flat mirror at the part of the scene you're looking at through the ball.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, we don't have such a camera, but we have something even better: software! So I built this simple setup with two perfectly sharp checkered planes, a sphere and a camera with some depth of field:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nKdZu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nKdZu.png&quot; alt=&quot;scene setup&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rendering it with some depth of field at 512x512, you'd think the reflection in the sphere is perfectly sharp:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/K6EXH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/K6EXH.jpg&quot; alt=&quot;normal view&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But here is a central crop of the exact same scene rendered at 8192x8192:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UA3pm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UA3pm.jpg&quot; alt=&quot;zoom into sphere&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And we can see the exact same blur on the checker pattern. It's as simple as that: you don't see the blur because it's too small.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2019-11-30T02:56:04.670" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9384" PostTypeId="1" CreationDate="2019-11-30T09:54:05.463" Score="2" ViewCount="173" Body="&lt;p&gt;i wanted to ask if you know the best books or resources to understand light physics. I have heard that Subrahmanyan Chandrasekhar's book &quot;Radiance Transfer&quot; is very good. Any other books or suggestions will be appreciated&lt;/p&gt;&#xA;" OwnerUserId="10468" LastActivityDate="2020-04-23T21:52:18.183" Title="Understanding lighting for physically based rendering" Tags="&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9388" PostTypeId="2" ParentId="4094" CreationDate="2019-12-02T02:46:49.847" Score="1" Body="&lt;p&gt;If you want to warp the space as in the raymarching infinite spheres example,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float SDF (vec3 p) {&#xA;    p = mod(p+3., 6.)-3.;&#xA;    return length(p-vec3(0., 0., 0.))-2.;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;what you really need to do is &lt;i&gt;warp the space by turning it into a cyllindrical one&lt;/i&gt; and what that means is that you need to make it so that if a ray hits a wall, the wall is like a portal to the wall opposite it and it comes out of the same point on the opposite wall. To do this you could just here is some pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Color trace (vec3 p, vec3 d) {&#xA;    if (intersects sphere) {&#xA;        *return sphere color with recursive tracing blah*&#xA;    }&#xA;    Plane frontwall = plane(vec3(0, 0, 3), vec3(0, 0, -1));&#xA;    Plane backwall = plane(vec3(0, 0, -3), vec3(0, 0, 1));&#xA;    Plane leftwall = plane(vec3(-3, 0, 0), vec3(1, 0, 0));&#xA;    ...&#xA;    *find closest wall intersection and then*&#xA;    return recursively traced color from opposite wall than the one that got hit&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;of note is that to do this enough times for it to look infinite, you would need like thousands of recursion iterations which would probably be slow and whatever language would probably not allow it, so your other option is to use some kind of a for loop since each portal/wall-intersection only requires base-1 recursion and therefore can be easily tranformed into an iterative process.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And instead of downvoting, I would request anyone who found my answer unhelpful to elaborate on how I could improve it; if someone really is interested in seeing a proof of concept of this in action then I will provide one but until that seems to be the case I will not waste my time.&lt;/p&gt;&#xA;" OwnerUserId="11547" LastActivityDate="2019-12-02T02:46:49.847" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9389" PostTypeId="2" ParentId="7629" CreationDate="2019-12-02T08:53:50.780" Score="0" Body="&lt;p&gt;It may be worth mentioning that the &lt;a href=&quot;https://en.wikipedia.org/wiki/Painter%27s_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;reverse painter's algorithm&lt;/a&gt; &lt;strong&gt;does not handle&lt;/strong&gt; transparency. If you read and understand @Chris's answer the reason for this is straightforward. Combining the already rendered color (using alpha blending) does not work if the objects behind your transparent object have not been rendered yet.&lt;/p&gt;&#xA;" OwnerUserId="11548" LastActivityDate="2019-12-02T08:53:50.780" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9390" PostTypeId="2" ParentId="7629" CreationDate="2019-12-02T10:01:35.623" Score="3" Body="&lt;p&gt;I would like to add that Painters' algorithm &lt;strong&gt;can&lt;/strong&gt; be run from front to back with transparency &lt;em&gt;provided&lt;/em&gt; your blending operations are &lt;em&gt;associative&lt;/em&gt;. I would recommend reading Jim Blinn's &quot;Compositing, Part 1: Theory&quot;. (Indeed, reading anything graphics related by Jim Blinn is highly recommended).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this article, Blinn explains (amongst their other advantages) that &lt;em&gt;premultiplied alpha&lt;/em&gt; blending operations are associative and, assuming &quot;C&quot; is the furthest polygon and &quot;A&quot; the closest, the usual the back-to-front blend operation &lt;span class=&quot;math-container&quot;&gt;$$Result=Blend(A, Blend(B,C))$$&lt;/span&gt; can be replaced with &lt;span class=&quot;math-container&quot;&gt;$$Blend(Blend(A,B), C))$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It does mean that you need to keep a destination alpha value with each pixel - you can't just assume each pixel is 100% opaque.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you're unfamiliar with premultiplied alpha, the typical OpenGL  &quot;GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA&quot; blend, i.e. &lt;span class=&quot;math-container&quot;&gt;$$DstOut_{RGB} := Src_A * Src_{RGB} + (1-Src_A) * DstIn_{RGB}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;becomes &#xA; &lt;span class=&quot;math-container&quot;&gt;$$\left[DstOut_A, \overline{DstOut_{RGB}}\right] :=\\ \left[Src_A + (1-Src_A)*DstIn_A,  \overline{Src}_{RGB} + (1-Src_A) * \overline{DstIn_{RGB}}\right]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$$\overline{X_{RGB}}=X_{RGB}*X_A$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Notes:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The operations are generally not commutative so, sadly, you still can't just process the polygons in random order. &lt;/li&gt;&#xA;&lt;li&gt;(IIRC, some games use(d) additive-only blending, e.g. for lighting effects, which is of course commutative and so can be done in arbitrary order)&lt;/li&gt;&#xA;&lt;li&gt;Additive blending can also be expressed in a premultiplied form as the colour [0, RBG_to_Add].&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-12-04T09:26:40.030" LastActivityDate="2019-12-04T09:26:40.030" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9391" PostTypeId="1" AcceptedAnswerId="9393" CreationDate="2019-12-02T16:13:15.437" Score="3" ViewCount="345" Body="&lt;p&gt;What is the best way to synchronize resource access between the (async) compute engine and the 3d engine (aka. direct engine) in D3D 12?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3d12/user-mode-heap-synchronization#multi-queue-resource-access&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; paragraph about multi-engine synchronization on MSDN but it's not very detailed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can certainly use a fence for synchronization but then you'd have split the command lists for both engines since fences only operate on queues.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to the documentation, the 3d engine and the compute engine share the same resource state (only the copy engine has it's own resource state). So if you write to a resource using the async compute engine and then read from it using the 3d engine, is there a way to synchronize this via resource barriers?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I doubt that it works if you use the compute engine to submit a resource barrier since the 3d engine probably won't wait automatically if the resource state is wrong. Same issue if you use the 3d engine for the resource transition (it could happen that the resource state is being changed while the compute engine is still writing to the resource).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do you have to use &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3d12/using-resource-barriers-to-synchronize-resource-states-in-direct3d-12#split-barriers&quot; rel=&quot;nofollow noreferrer&quot;&gt;split barriers&lt;/a&gt;? You could use the compute engine with the D3D12_RESOURCE_BARRIER_FLAG_BEGIN_ONLY flag and the 3d engine with the D3D12_RESOURCE_BARRIER_FLAG_END_ONLY flag. Unfortunately, the documentation doesn't say whether split barriers can be used across engines. What happens if the direct engine executes the end barrier before the compute engine has executed the start barrier? &lt;/p&gt;&#xA;" OwnerUserId="8283" LastActivityDate="2019-12-02T21:47:19.207" Title="Can D3D12 resource barriers be used to synchronize between the compute and 3D engine?" Tags="&lt;directx12&gt;&lt;synchronization&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9392" PostTypeId="2" ParentId="9379" CreationDate="2019-12-02T16:30:31.757" Score="2" Body="&lt;p&gt;The most usual way of employing Russian roulette in path tracing is to cut paths with high attenuation (low throughput) without adding bias into the resulting estimator, which would occur if you just use constant maximum path length. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Although Russian roulette incorporates additional variance into the resulting estimator, it helps throwing away long paths consuming a lot of processing power while contributing little into the resulting image, possibly leading to increased performance of a renderer.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastActivityDate="2019-12-02T16:30:31.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9393" PostTypeId="2" ParentId="9391" CreationDate="2019-12-02T18:28:21.073" Score="3" Body="&lt;p&gt;My understanding would be that resource barriers are not at all about synchronization. They are about memory ordering, which is a related but separate concern. Basically, synchronization is about making sure that A happens before B. Memory ordering is about making sure that if A did X, someone how saw A happen will always also see X and no one will ever see X without first also having seen A happen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Direct3D terms, resource barriers are about making sure that if shader A writes to texture X, shader B running after shader A actually gets to see the result of shader A having written to texture X. Fences, on the other hand, are about making sure that shader A actually runs before shader B.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Direct3D resource barriers are just you stating in which way you are going to be using a resource. You cannot rely on just a resource barrier to automagically perform the necessary synchronization for you. The section you linked would seem to agree (emphasis mine):&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;Although resource state is shared across all Compute and 3D queues, it is not permitted to write to the resource simultaneously on different queues. &quot;Simultaneously&quot; here means unsynchronized, noting unsynchronized execution is not possible on some hardware. The following rules apply.  &#xA;  &#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;Only one queue can write to a resource at a time.&lt;/li&gt;&#xA;  &lt;li&gt;Multiple queues can read from the resource as long as they don’t read the bytes being modified by the writer (reading bytes being simultaneously written produces undefined results).  &lt;/li&gt;&#xA;  &lt;li&gt;&lt;strong&gt;A fence must be used to synchronize after writing before another queue can read the written bytes or make any write access.&lt;/strong&gt;&lt;/li&gt;&#xA;  &lt;/ul&gt;&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="9812" LastEditorUserId="9812" LastEditDate="2019-12-02T21:47:19.207" LastActivityDate="2019-12-02T21:47:19.207" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9395" PostTypeId="1" CreationDate="2019-12-03T14:22:30.217" Score="2" ViewCount="82" Body="&lt;p&gt;I have a video feed generating a stream of of Y'CbCr frames (specifically 8-bit component Y'CbCr 4:2:0, luma range of 16-235, chroma range of 16-240) from which I'd like to calculate relative luminance of specific pixels in each frame with a margin of error at ~2%.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My understanding is that the Y' channel in a Y'CbCr signal is not luminance but luma, and therefore further work is required to reverse that conversion into its linear form.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, to do that I need to know what values were used to compress the signal from its original linear RGB form into its current Y'CbCr state.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand there's usually a compression function used to convert linear RGB into R'G'B', so if I know what these are – I should have a fairly good shot at doing it. (That's assuming that &lt;em&gt;not&lt;/em&gt; having the camera response curves isn't a problem, as I'm hoping that these are used to transform non-linear raw camera data into a linear form – and so for my purposes there isn't a benefit to reversing the signal transform this far.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Available to me with the feed are references to a 'transfer function' (usually some ITU standard – BT.601-4 on my test device), a Y'CbCr Matrix (another ITU standard – BT.709-2 on my test device), and some color primaries  (P3 D65 on my test device) and white balance gain values.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What steps are required to convert 'luma' to luminance given the available data?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My naive approach is to simply apply the inverse of the transfer function to the luma channel but my concern is that this will be grossly inaccurate. Also, white balance might be a factor too, but perhaps marginally enough to be within the 2% margin of error.&lt;/p&gt;&#xA;" OwnerUserId="11553" LastEditorUserId="11553" LastEditDate="2019-12-03T18:15:36.240" LastActivityDate="2019-12-03T18:15:36.240" Title="Calculating Luminance From Y'CbCr" Tags="&lt;color&gt;&lt;color-science&gt;&lt;color-management&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9396" PostTypeId="1" AcceptedAnswerId="9399" CreationDate="2019-12-03T16:46:08.183" Score="2" ViewCount="54" Body="&lt;p&gt;I'm reading about BVH from PBRT. According to the book, in the linear bvh part using morton encoding:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;An efficient way to perform a front-to-back traversal without incurring the expense of intersecting the ray with both child nodes and comparing the distances is to use the sign of the ray’s direction vector for the coordinate axis along which primitives were partitioned for the current node: if the sign is negative, we should visit the second child before the first child, since the primitives that went into the second child’s subtree were on the upper side of the partition point. (And conversely for a positive-signed direction.)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm unable to understand how the sign of the ray's direction vector helps in deciding which child to visit. If the partitioning axis is x, doesn't the point with a lower x come in the 1st child? Or have I understood something wrong?&lt;/p&gt;&#xA;" OwnerUserId="8962" LastActivityDate="2019-12-04T07:18:37.963" Title="How to decide which child of BVH to visit based on sign of ray's direction vector?" Tags="&lt;raytracing&gt;&lt;bounding-volume-hierarchy&gt;&lt;pbrt&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9398" PostTypeId="1" CreationDate="2019-12-03T22:40:35.220" Score="1" ViewCount="109" Body="&lt;p&gt;I'm making a 2D cell simulation game. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The mesh for my cell is basically just a manually-generated triangle fan that looks like &lt;a href=&quot;https://nullprogram.s3.amazonaws.com/voronoi/triangle-fan.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to reproduce the wobbling/vibration effect on the cell membrane caused by inertia after a decelleration (e.g. collision), but I can't really figure out a way to do it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was thinking that I could apply a transformation to each vertex of the mesh in order to move it inwards and outwards alternately (with respect to the cell center) and then syncronize all the vertices based on a sinusoidal function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result would be a deformed cell shape but where all the triangles are still connected.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is it possible to apply transformations to the vertices inside the model separately without having to reconstruct the VBO? Is there a better way to achieve this?&lt;/p&gt;&#xA;" OwnerUserId="11556" LastActivityDate="2019-12-03T22:40:35.220" Title="Apply transformation to single vertices in OpenGL in order to deform mesh" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;mesh&gt;&lt;java&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9399" PostTypeId="2" ParentId="9396" CreationDate="2019-12-04T07:18:37.963" Score="1" Body="&lt;p&gt;In your example of a BVH cell partitioned along the x axis, if the ray is going left to right (increasing x), then the cell with the lower x comes first; but if it's going right to left (decreasing x), then the cell with the higher x comes first. So, you can look at the sign of the x component of the direction vector to determine which cell to test first.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2019-12-04T07:18:37.963" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9400" PostTypeId="2" ParentId="9377" CreationDate="2019-12-04T17:30:23.837" Score="2" Body="&lt;p&gt;The term D is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Probability_density_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;probability density function&lt;/a&gt; (PDF) of microfacets' directions. Vaguely speaking, it says what &quot;portion&quot; of all microfacets points in the given direction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since it is a PDF, it doesn't have to be less or equal to 1. It can, and often is, higher than 1 for some directions.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2019-12-07T03:29:34.110" LastActivityDate="2019-12-07T03:29:34.110" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9402" PostTypeId="2" ParentId="6" CreationDate="2019-12-06T11:36:49.733" Score="0" Body="&lt;p&gt;Monte Carlo integration is an unbiased estimator for the synthesis of lights that contributed to a pixel. While we cannot exactly simulate the real world light path because the amount of rays is infinite, we can use Monte Carlo integration to estimate the expected value. That's why it is much more realistic: from the statistics aspect, the expectation of Monte Carlo ray tracing is the &quot;real light paths&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can read &lt;a href=&quot;https://hsuanwei.codes/2019/12/06/pt/#more&quot; rel=&quot;nofollow noreferrer&quot;&gt;my blog&lt;/a&gt; for more math details.&lt;/p&gt;&#xA;" OwnerUserId="11571" LastActivityDate="2019-12-06T11:36:49.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9403" PostTypeId="1" CreationDate="2019-12-06T22:22:16.390" Score="2" ViewCount="105" Body="&lt;p&gt;I am currently implementing the Mandelbrot fractal on the GPU. I wrote two programs: the first in OpenGL (desktop C++ application) and the second in WebGL (static webpage). The two programs use almost the same fragment shader for generating the fractal, but picture on WebGL looks less detailed than the OpenGL one. I cannot understand the reason behind that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;WebGL version:&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CI7tS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CI7tS.png&quot; alt=&quot;WebGL version&quot;&gt;&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;OpenGL version:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V60I4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V60I4.png&quot; alt=&quot;OpenGL version&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I place here the fragment shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;precision highp float;&#xA;float xShift = 200.0;&#xA;float yShift = 50.0;&#xA;float fade = 0.02;&#xA;&#xA;struct ComplexNumber&#xA;{&#xA;  float Real;&#xA;  float Imagine;&#xA;};&#xA;&#xA;&#xA;ComplexNumber Product(in ComplexNumber first, in ComplexNumber second)&#xA;{&#xA;  ComplexNumber result;  &#xA;  result.Real = first.Real * second.Real - first.Imagine * second.Imagine;&#xA;  result.Imagine = first.Real * second.Imagine + first.Imagine * second.Real;&#xA;  return result;&#xA;}&#xA;&#xA;&#xA;ComplexNumber Add(in ComplexNumber first, in ComplexNumber second)&#xA;{&#xA;  ComplexNumber result;  &#xA;  result.Real = first.Real + second.Real;&#xA;  result.Imagine = first.Imagine + second.Imagine;&#xA;  return result;&#xA;}&#xA;&#xA;&#xA;float length2(in ComplexNumber number)&#xA;{&#xA;   return number.Real * number.Real + number.Imagine * number.Imagine;&#xA;}&#xA;&#xA;&#xA;vec4 linearExtrapolation(const vec4 first, const vec4 last, int min, int max, int x)&#xA;{&#xA;  float xDiff = float(max - min);&#xA;  return first + float(x - min) * (last - first) / xDiff;&#xA;}&#xA;&#xA;int getOutOfBoundsIdx()&#xA;{&#xA;  const int nMax = 1000;&#xA;&#xA;  ComplexNumber z;&#xA;  z.Real = 0.;&#xA;  z.Imagine = 0.;&#xA;&#xA;  ComplexNumber c;&#xA;  c.Real = float((gl_FragCoord.x - xShift ) * fade);&#xA;  c.Imagine = float((gl_FragCoord.y - yShift) * fade); &#xA;&#xA;  for (int i = 0; i &amp;lt; nMax; i++)&#xA;  {&#xA;     z = Add (Product(z,z), c);&#xA;     if (length2(z) &amp;gt; 4.)&#xA;     {&#xA;       return i;&#xA;     }&#xA;  }&#xA;&#xA;  return nMax;&#xA;} &#xA;&#xA;&#xA;void main()&#xA;{&#xA;&#xA;  const vec4 blue = vec4(166, 202, 240, 255) / 255.;&#xA;  const vec4 biruz = vec4(123, 228, 209, 255) / 255.;&#xA;  const vec4 red = vec4(255, 0, 0, 255) / 255.;&#xA;  const vec4 green = vec4(0, 255, 0, 255) / 255.;&#xA;  const vec4 black = vec4(0, 0, 0, 255) / 255.;&#xA;&#xA;&#xA;&#xA;  const int kThreshold0 = 0;&#xA;  const int kThreshold1 = 100;&#xA;  const int kThreshold2 = 150;&#xA;  const int kThreshold3 = 250;&#xA;  const int kThreshold4 = 390;&#xA;&#xA;&#xA;  int k = getOutOfBoundsIdx();&#xA;&#xA;&#xA;  vec4 color;&#xA;  if (k &amp;lt; kThreshold1)&#xA;  {&#xA;     color = linearExtrapolation(biruz, blue, kThreshold0, kThreshold1, k);&#xA;  }&#xA;  else if (k &amp;lt; kThreshold2)&#xA;  {&#xA;     color = linearExtrapolation(red, green, kThreshold1, kThreshold2, k);&#xA;  }&#xA;  else if (k &amp;lt; kThreshold3)&#xA;  {&#xA;     color = linearExtrapolation(biruz, blue, kThreshold2, kThreshold3, k);&#xA;  }&#xA;  else if (k &amp;lt; kThreshold4)&#xA;  {&#xA;     color = linearExtrapolation(biruz, green, kThreshold3, kThreshold4, k);&#xA;  }&#xA;&#xA;  else&#xA;  {&#xA;     color = black;  &#xA;  }&#xA;&#xA;  gl_FragColor = color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What can be a reason of such weird difference? I have a feeling that the float operations on WebGL are less precise than in OpenGL. &lt;/p&gt;&#xA;" OwnerUserId="10136" LastActivityDate="2019-12-06T22:22:16.390" Title="Why there are calculation differences in WebGL and OpenGL" Tags="&lt;opengl&gt;&lt;webgl&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9405" PostTypeId="1" CreationDate="2019-12-08T01:50:56.087" Score="1" ViewCount="361" Body="&lt;p&gt;Apologize for crossposting, but I posted this in Stack Overflow and thought it might be a better post here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recently, Spotify released their 2019 Spotify wrapped web application, which is essentially a way for both music artists and music listeners to rewind and review what they listened to/who listened to their music in the past year.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As part of their site, they dynamically created these images that people could either export or share to one of their social media networks.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/28fZc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/28fZc.jpg&quot; alt=&quot;Example of dynamically generated image from Spotify&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Above is an example of one of those dynamically generated images (of course, the image, and the text/statistics below change).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How would I go about doing this in code? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry if this is in the wrong place - just wasn't sure where I would post this. Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="11577" LastActivityDate="2020-01-08T14:36:28.360" Title="How do you add text dynamically to an image and export it?" Tags="&lt;image-processing&gt;&lt;vector-graphics&gt;&lt;image&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9406" PostTypeId="2" ParentId="5724" CreationDate="2019-12-08T08:20:21.087" Score="2" Body="&lt;p&gt;Refer to narthex's excellent answer for details and example, but simply put,&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to &lt;em&gt;map&lt;/em&gt; the pixel coordinate values to the range &lt;strong&gt;0&lt;/strong&gt; to &lt;strong&gt;1&lt;/strong&gt; , you divide by viewPortSize.&lt;/p&gt;&#xA;" OwnerUserId="11579" LastActivityDate="2019-12-08T08:20:21.087" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9407" PostTypeId="2" ParentId="7916" CreationDate="2019-12-08T11:18:29.990" Score="0" Body="&lt;p&gt;Your phone would have to do all of the CPU processing too then beam it to your laptop using scrcpy: &lt;a href=&quot;https://github.com/Genymobile/scrcpy&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Genymobile/scrcpy&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11580" LastEditorUserId="7724" LastEditDate="2019-12-25T19:43:41.230" LastActivityDate="2019-12-25T19:43:41.230" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9408" PostTypeId="1" CreationDate="2019-12-08T12:41:36.947" Score="2" ViewCount="129" Body="&lt;p&gt;I'm having a lot of trouble implementing Importance Sampling path tracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I understand it correctly, what I need to evaluate for a path tracer is this:&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\int_\Omega L_{in}(L) * fr(L, V) * \cos(\Theta_L) d\omega_L$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which for an Importance sampling PT is estimated by sampling &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; times &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; according to some pdf &lt;span class=&quot;math-container&quot;&gt;$p(L)$&lt;/span&gt;, i.e.:&lt;br&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\frac{1}{M} * \sum_1^n L_{in}(L) * \frac{fr(L, V) * \cos(\Theta_L)}{p(L_i)}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which in it's simplest form, for a single sample of a recursive reverse Path Tracer using an environment map, translates to roughly this pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;trace(scene, ray, throughput, depth) =&#xA;    if(depth &amp;gt; ...)&#xA;         return 0&#xA;    else&#xA;        intersection, normal, material = intersect(ray, scene)&#xA;        if(intersection)&#xA;            new_ray = material.sample_direction(normal, ray)&#xA;            new_throughput = material.brdf(normal, ray, new_ray)&#xA;                           * cos(normal, new_ray)&#xA;                           / material.pdf(normal, ray, new_ray)&#xA;            return trace(scene, new_ray, new_throughut, depth + 1)&#xA;        else&#xA;            return throughput * environment(ray)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Usually the &lt;span class=&quot;math-container&quot;&gt;$brdf * cos(theta)$&lt;/span&gt; and the &lt;span class=&quot;math-container&quot;&gt;$pdf$&lt;/span&gt; would be similar. In my case for Lambertian importance sampling, they are equal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I think this means is that if, instead of importance sampling the material, I sample a random direction in the &quot;&lt;span class=&quot;math-container&quot;&gt;$normal$&lt;/span&gt;-oriented&quot; hemisphere, and use constant &lt;span class=&quot;math-container&quot;&gt;$\frac{1}{2 * PI}$&lt;/span&gt; for the pdf, the radiance (for a sufficient number of samples) should be equal (up to some trivial variance):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;trace(scene, ray, throughput, depth) =&#xA;    if(depth &amp;gt; ...)&#xA;         return 0&#xA;    else&#xA;        intersection, normal, material = intersect(ray, scene)&#xA;        if(intersection)&#xA;            new_ray = sample_uniform_hemisphere(normal, ray)&#xA;            new_throughput = material.brdf(normal, ray, new_ray)&#xA;                           * cos(normal, new_ray)&#xA;                           / (1/(2 * PI))        &#xA;            return trace(scene, new_ray, new_throughut, depth + 1)&#xA;        else&#xA;            return throughput * environment(ray)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Instead, even for trivial Lambertian materials, IF i switch the sampling pdfs in a checkerboard pattern, it shows a large difference in luminance:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nUamC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nUamC.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;&lt;sup&gt;&lt;i&gt;Switching sampling PDFs in a checkerboard pattern shows a difference in luminance&lt;/i&gt;&lt;/sup&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more complex materials the problem is MUCH worse.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The actual Lambert implementation is (note the albedo is separated out):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glm::vec3 lambert::sample(glm::vec3 n, glm::vec3 v) const&#xA;{&#xA;    glm::vec2 xi{drand48(), drand48()};&#xA;    float th = acosf(sqrtf(xi.x));&#xA;    float ph = 2 * M_PIf32 * xi.y;&#xA;    glm::vec3 dir{sinf(th) * cosf(ph), sinf(th) * sinf(ph), cosf(th)};&#xA;    return local_to_normal(dir, n);&#xA;}&#xA;&#xA;float lambert::bxdf(glm::vec3 n, glm::vec3 v, glm::vec3 l) const&#xA;{&#xA;    return M_1_PIf32;&#xA;}&#xA;&#xA;float lambert::pdf(glm::vec3 n, glm::vec3 v, glm::vec3 l) const&#xA;{&#xA;    return glm::dot(n, l) * M_1_PIf32;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The actual trace routine is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;auto trace(ray r, scene const &amp;amp;s)&#xA;{&#xA;       float throughput = 1.0f;&#xA;       for(int num_bounces = 0; num_bounces &amp;lt; 6; ++num_bounces) {&#xA;           auto &amp;amp;&amp;amp;[i, hit] = intersect_scene(r, s);&#xA;           if(!i) {&#xA;                   return throughput * sample_environment(r.dir, s.environment);&#xA;           }&#xA;           auto out_direction = hit.mat-&amp;gt;sample(hit.x_norm, -r.dir);&#xA;           throughput *= hit.mat-&amp;gt;albedo * hit.mat-&amp;gt;bxdf(hit.normal, -r.dir, out_direction)  * glm::dot(hit.normal, out_direction)/ hit.mat-&amp;gt;pdf(hit.normal, -r.dir, out_direction);&#xA;           r.src = hit.pos + hit.normal * 1e-4f;&#xA;           r.dir = out_direction;    &#xA;       }&#xA;       return 0.f;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For the uniform hemispherical sampling I use this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    auto const r = sqrtf(1.f - u1 * u1);&#xA;    auto const phi = 2 * M_PIf32 * u2;&#xA;    return {r * cosf(phi), r * sinf(phi), u1};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And then change the basis to the intersection normal again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please, if anyone has any idea could you please help?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can provide more of the project if it's necessary.&lt;/p&gt;&#xA;" OwnerUserId="11581" LastEditorUserId="11581" LastEditDate="2019-12-08T15:35:25.230" LastActivityDate="2019-12-08T15:35:25.230" Title="Importance Sampling path tracer, Different pdfs result in different luminance?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9409" PostTypeId="1" CreationDate="2019-12-08T15:34:58.047" Score="1" ViewCount="212" Body="&lt;p&gt;In the accepted answer for the question &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4979/what-is-importance-sampling&quot;&gt;What is Importance Sampling?&lt;/a&gt;, in the example code there is this line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Accumulate the brdf attenuation&#xA;throughput = throughput * material-&amp;gt;Eval(wi, wo, normal) / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If the PDF is between 0.0 and 1.0, the division will potentially increase the throughput. I do not think it makes sense. What am I missing?&lt;/p&gt;&#xA;" OwnerUserId="11452" LastActivityDate="2020-10-08T08:38:55.080" Title="Should ray throughput always decrease when bouncing?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;" AnswerCount="2" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9410" PostTypeId="2" ParentId="9409" CreationDate="2019-12-08T20:18:25.643" Score="0" Body="&lt;p&gt;I have a similar question currently posted, so take the following with a grain of salt.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Throughput does not need to be smaller than 1. BRDF only needs to be non negative and to integrate to less than 1 (conservation of energy / albedo) over the hemisphere. It can be arbitrarily large - e.g. in the case of a mirror. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The pdf should approximate the BRDF to reduce variance. However, unless it is always larger than the BRDF, the throughput will be larger than 1 and should be able to reach infinity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;BRDF in your case corresponds to material-&gt;Eval(wi, wo, normal) / dot(normal, wi)&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="11581" LastEditorUserId="11581" LastEditDate="2020-05-09T20:00:46.437" LastActivityDate="2020-05-09T20:00:46.437" CommentCount="17" ContentLicense="CC BY-SA 4.0" />
  <row Id="9411" PostTypeId="2" ParentId="9405" CreationDate="2019-12-08T22:48:27.970" Score="1" Body="&lt;p&gt;To do this in a web app is trivial. Judging by the image, even the built-in HTML canvas should be able to do everything that you need.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have obtained your image and text, to give you a vague idea of the ammount of code involved, drawing them with the canvas API looks roughly as follows:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ctx.drawImage(img, x, y, width, height);&#xA;ctx.font = '12px serif';&#xA;ctx.fillText(txt, x, y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Saving the image is equally simple:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;canvas.toDataURL(&quot;image/png&quot;)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It's actually the obtaining and sharing of images are the scary parts. Spotify surely have all the images on their cloud and similarly that is where they export them to before sharing to social media. There are so many sollutions that without more detail this is probably something you'll need to find yourself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you just need a tutorial on html canvas, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_usage&quot; rel=&quot;nofollow noreferrer&quot;&gt;mozzilla usually have great interactive tutorials&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="11581" LastActivityDate="2019-12-08T22:48:27.970" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9413" PostTypeId="1" CreationDate="2019-12-09T15:41:31.030" Score="0" ViewCount="90" Body="&lt;p&gt;I wonder what is the reason that when z increase, the objects appear far away and when z is negative, the object is behind the camera?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastEditorUserId="209" LastEditDate="2019-12-10T08:49:39.287" LastActivityDate="2019-12-10T08:49:39.287" Title="Why is the z direction away from the screen/viewer?" Tags="&lt;3d&gt;&lt;projections&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9414" PostTypeId="2" ParentId="9413" CreationDate="2019-12-09T19:45:18.977" Score="1" Body="&lt;p&gt;If you want to use the traditional x is towards right and y is up you are used to in math and physics classes. Now if you follow a right handed coordinate space, which is also commonly used. Then the direction of the z follows from the x and y direction.  In this sceme positive z is pointing out from the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you can also choose a left handed coordinate system in which case the z is reversed. Its just a matter of choosing which convention you want to use. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Likewise if you choose y to be down, ala traditional windowing math then z is reversed even if you use right hand rule.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;None of these conventions are set in stone you can do whatever you want. A bit like you can choose row major or column major matrixes. You just need to know what comvention you follow.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2019-12-09T19:53:16.833" LastActivityDate="2019-12-09T19:53:16.833" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9415" PostTypeId="1" CreationDate="2019-12-10T09:44:12.827" Score="3" ViewCount="95" Body="&lt;p&gt;This question is in reference to the method described in ShaderX7 section 2.4 &quot;Fast Skin Shading&quot; by Hable et. al. The part I do not understand is how they derived the weights for the individual samples. They describe the process only very briefly like this: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;&quot;Since using a sum of Gaussian blurs is a good way to describe subsurface scattering, we&#xA;describe the blur in this way. Then, in an offline process, we combine the sum of the blurs into a&#xA;single blur, and then sample. This approach provides us with an intuitive way to tweak the blur&#xA;for different skin types.&quot;&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I assumed this means that they calculated the weight &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt; for a sample as&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$W = \sum_i w_iG(v_i, r)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but the result is completely off. So what is the correct way to calculate these?&lt;/p&gt;&#xA;" OwnerUserId="11586" LastEditorUserId="11586" LastEditDate="2019-12-12T09:53:03.277" LastActivityDate="2019-12-12T09:53:03.277" Title="How to calculate subsurface scattering weights for fast skin shading" Tags="&lt;subsurface-scattering&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9417" PostTypeId="1" CreationDate="2019-12-11T17:57:31.210" Score="1" ViewCount="59" Body="&lt;p&gt;I asked this in regular SO but I think people are not understanding the question so i will try here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, for anyone familiar with Google Maps, when you zoom, it does it around the cursor.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is to say, the matrix transformation for such a zoom is as simple as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TST^{-1}*x&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where T is the translation matrix representing the point of focus, S the scale matrix and x is any arbitrary point on the plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I want to produce a similar effect with a spherical camera, think &lt;a href=&quot;https://sketchfab.com/3d-models/poisonous-cfba7da278eb41bc941022ca9ecebabe&quot; rel=&quot;nofollow noreferrer&quot;&gt;sketchfab&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you zoom in and out, the camera needs to be translated so as to give a similar effect as the 2D zooming in Maps. To be more precise, given a fully composed MVP matrix, there exists a set of parallel planes that are parallel to the camera plane. Among those there exists a unique plane P that also contains the center of the current spherical camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given that plane, there exists a point x, that is the unprojection of the current cursor position onto the camera plane. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the center of the spherical camera is c then the direction from c to x is d = x - c.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And here's where my challenge comes. Zooming is implemented as just offsetting the camera radially from the center, given a change in zoom Delta, I need to find the translation vector u, colinear with d, that moves the center of the camera towards x, such that I get a similar visual effect as zooming in google maps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I know this is a bit hard to parse I tried to make a diagram:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/E2hqx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/E2hqx.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TL;DR&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to offset a spherical camera towards the cursor when I zoom, how do i pick my translation vector?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2019-12-11T17:57:31.210" Title="How to Pan Zoom a spherical camera?" Tags="&lt;projections&gt;&lt;camera&gt;&lt;linear-algebra&gt;&lt;ui&gt;" AnswerCount="0" CommentCount="12" ContentLicense="CC BY-SA 4.0" />
  <row Id="9418" PostTypeId="1" AcceptedAnswerId="9423" CreationDate="2019-12-11T21:47:13.260" Score="0" ViewCount="114" Body="&lt;p&gt;I'm trying to use open image denoise. Here's the code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int main() {&#xA;    int width, height, nrChannels;&#xA;    unsigned char* image = stbi_load(&quot;img_cornell_box.png&quot;, &amp;amp;width, &amp;amp;height, &amp;amp;nrChannels, 0);&#xA;    unsigned char* resultImage = new unsigned char[width*height*nrChannels];&#xA;    oidn::DeviceRef device = oidn::newDevice();&#xA;    device.commit();&#xA;    std::cout &amp;lt;&amp;lt; nrChannels &amp;lt;&amp;lt; std::endl;&#xA;    oidn::FilterRef filter = device.newFilter(&quot;RT&quot;);&#xA;    filter.setImage(&quot;color&quot;, image, oidn::Format::Float4, width, height);&#xA;    filter.setImage(&quot;output&quot;, resultImage, oidn::Format::Float4, width, height);&#xA;    filter.set(&quot;hdr&quot;, false);&#xA;    filter.set(&quot;srgb&quot;, true);&#xA;    filter.commit();&#xA;    filter.execute();&#xA;&#xA;    const char* errorMessage;&#xA;    if (device.getError(errorMessage) != oidn::Error::None) {&#xA;        std::cout &amp;lt;&amp;lt; &quot;Error: &quot; &amp;lt;&amp;lt; errorMessage &amp;lt;&amp;lt; std::endl;&#xA;    }&#xA;    else {&#xA;        stbi_write_png(&quot;img.png&quot;, width, height, nrChannels, resultImage, width * nrChannels);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm getting an error saying that the image format is unsupported.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I use jpg, and change Format::Float4 to Format::Float3 I get this error:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Exception thrown at 0x00007FFC5588E1F5 (OpenImageDenoise.dll) in oidntest.exe: 0xC0000005: Access violation reading location 0x0000021D9C42FA70.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Am I doing something wrong?&#xA;This is the image I'm using: &lt;a href=&quot;https://drive.google.com/open?id=1uSjsyWCRisXNFUJG6R8iL5AdVbM7_18u&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://drive.google.com/open?id=1uSjsyWCRisXNFUJG6R8iL5AdVbM7_18u&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="8962" LastActivityDate="2019-12-15T06:15:32.847" Title="Trouble using Open Image Denoise" Tags="&lt;image&gt;&lt;denoise&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9419" PostTypeId="1" CreationDate="2019-12-12T20:13:46.390" Score="1" ViewCount="45" Body="&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Getting a &lt;em&gt;polygon mesh&lt;/em&gt; as input, I have to construct a surface that looks exactly to the given input. My task is to generate a &lt;em&gt;b-spline&lt;/em&gt; surface that exactly looks like the connected polygon mesh. It is obvious that my &lt;em&gt;b-spline&lt;/em&gt; surface has to have a degree of one in both directions &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an output for my solution. I have to generate a matrix of &lt;em&gt;control points&lt;/em&gt; that represent that generated surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One property of this matrix is that each elements of each row and column are connected with each others.&#xA;If our control points matrix is a &lt;span class=&quot;math-container&quot;&gt;$ n \times m$&lt;/span&gt; matrix, then let &lt;span class=&quot;math-container&quot;&gt;$C_i$&lt;/span&gt; a column of this matrix with &lt;span class=&quot;math-container&quot;&gt;$C_i = \langle e_{1i}, e_{2i}, \dots, e_{mi} \rangle$&lt;/span&gt; then there must exist path in the polygon from &lt;span class=&quot;math-container&quot;&gt;$e_{1i}$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$e_{mi}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One thing to consider if there is no edge between  &lt;span class=&quot;math-container&quot;&gt;$e_{ji}$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$e_{(j+1)i}$&lt;/span&gt;, we can construct one as long as this edge lies inside the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My trivial idea:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming that the polygon has &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; nodes. I create &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; other nodes inside the polygon near each original node. I create then a &lt;span class=&quot;math-container&quot;&gt;$2 \times n$&lt;/span&gt; matrix. The first row contains all the points constructing the polygon. Second row contains the corresponding additional inserted node. In order to connect two additional inserted nodes, i have to make sure that the line between two nodes is kept inside the polygon.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This idea works only for simple structure and the complexer is the polygon the hard to find these additional points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any good solutions maybe?&lt;/p&gt;&#xA;" OwnerUserId="11241" LastEditorDisplayName="user106" LastEditDate="2019-12-13T14:19:50.497" LastActivityDate="2019-12-13T14:19:50.497" Title="Convert a polygon mesh to a bspline surface" Tags="&lt;polygon&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9420" PostTypeId="2" ParentId="9354" CreationDate="2019-12-13T05:35:12.407" Score="0" Body="&lt;p&gt;You can use Query for mesuring time on GPU. Idea is follow:&#xA;Create buffer with two int64 values. Write time stamp before and after CopyResource() on GPU to this buffer. Then retrive values on CPU and substract them. Substraction is time on GPU.&lt;/p&gt;&#xA;" OwnerUserId="9903" LastActivityDate="2019-12-13T05:35:12.407" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9421" PostTypeId="1" CreationDate="2019-12-13T21:59:29.790" Score="3" ViewCount="262" Body="&lt;p&gt;As the title suggests I'm trying to implement the last images of the &amp;quot;Microfacet Models for Refraction through Rough Surfaces&amp;quot; Paper by Walter et al. in OpenGL&lt;a href=&quot;https://i.stack.imgur.com/Xofnw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xofnw.png&quot; alt=&quot;see here for the picture&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I &amp;quot;think&amp;quot; (I had to put that into quotation marks) I know how the microfacet model should work and hopefully am only stuck on practical execution.&lt;/p&gt;&#xA;&lt;p&gt;So I started by implementing the GGX formulas for the Normal Distribution, Fresnel and Geometry Function.&lt;/p&gt;&#xA;&lt;p&gt;Initially and still I'm not so sure how to get the color of the object behind the glass into the formulas. My first thought was to create a cubemap around the slate of glass and then use the outgoing direction vectors (o_t and o_r) to sample the cubemap. But then I'm still not so sure how to incorporate that into the larger picture. Going by my first thought again I just multiplied the result of the BTFD with the sample of the o_t vector but apparently the BTDF was really big so the whole slate turned white (possible bug?). After dividing the result a few times some washed-up version of what was supposed to show up appeared.&lt;/p&gt;&#xA;&lt;p&gt;Also I think I read somewhere that the reflection and transmission should be handled seperatly depending on the result of the Fresnel formula.&#xA;Or should it be handled at the same time (possibly somethink like : BRDF * sample_of_reflection + BTDF * sample_of_refraction)?&lt;/p&gt;&#xA;&lt;p&gt;And another thing I found curious is the given equation for sampling:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\theta = arctan(a * sqrt(rand1) / sqrt(1 - rand1))$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\phi = 2 * \pi * rand2$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;After some playing around with this function I noticed that is basically something akin to a gaussian distribution pointing towards the positive z-axis. But shouldn't the distribution give samples which are distributed around the surface normal?&lt;/p&gt;&#xA;&lt;p&gt;I'm wondering if I have to add an additional pair of quotation marks to my earlier statement...&lt;/p&gt;&#xA;&lt;p&gt;So anyway here is the pseudocode for my implementation until now:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;for(#samplecount)&#xA;{&#xA; //get a sample m&#xA; vec3 m = drawsample();&#xA; &#xA; //calculate normal and incoming vector&#xA; vec3 i = normalize(viewPosition - fragmentPosition);&#xA; vec3 n = normalize(Normal); &#xA; &#xA; // calculate outgoing vector&#xA; vec3 o_r = calculate_like_paper();&#xA; vec3 o_t = calculate_like_paper();&#xA;&#xA; //sample cubemap&#xA; vec3 reflection = sampleCubemap();&#xA; vec3 refraction = sampleCubemap(); &#xA;&#xA; //calculate halfvectors&#xA; vec3 h_r = calculate_like_paper();&#xA; vec3 h_t = calculate_like_paper();&#xA;&#xA; //calculate NDF, Fresnel and Geometry&#xA; float D = GGX_D(h_r);&#xA; float G = GGX_G(i, o_r, h_r);&#xA; float F = GGX_F(i, h_r);&#xA;&#xA; //calculate BSDF, BRDF &amp;amp; BTDF&#xA; float BRDF = F * G * D / (4.0 * abs(dot(i, n)) * abs(dot(o_r, n)));&#xA; float BTDF = longFormula();&#xA;&#xA; float BSDF = BRDF + BTDF&#xA; &#xA; vec3 result += BRDF * reflection + BTDF * refraction //?&#xA;}&#xA;result /= #samplecount;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Thank you if you take your time to answer and I'm relatively new to StackExchange so I could definitely do with some feedback to improve the way I ask questions.&lt;/p&gt;&#xA;&lt;p&gt;Edit:&#xA;So if anyone found this question and has similar questions Epic Games has some nice notes on this topic:    &lt;a href=&quot;https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11598" LastEditorUserId="11598" LastEditDate="2020-07-26T20:10:14.380" LastActivityDate="2020-07-26T20:10:14.380" Title="Implementing the example of Walter et al. (2007) paper" Tags="&lt;opengl&gt;&lt;brdf&gt;&lt;microfacet&gt;&lt;bsdf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9422" PostTypeId="2" ParentId="9421" CreationDate="2019-12-14T02:28:41.630" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Initially and still I'm not so sure how to get the color of the object behind the glass into the formulas.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Normal, this was written with path / ray tracers in mind where that part is easy. Your idea of a cube map might be ok for some use cases (eg. reasonably rough surface for the distance to the surrounding objects). It is not a general solution however. That would likely require GPU ray tracing.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Going by my first thought again I just multiplied the result of the BTFD with the sample of the o_t vector but apparently the BTDF was really big so the whole slate turned white (possible bug?).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I'm writing this from memory but I think you need to divide by the PDF. Which means that your weights will be close to 1. But not quite 1 as the sampling distributions don't include the shadowing terms.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Also I think I read somewhere that the reflection and transmission should be handled seperatly depending on the result of the Fresnel formula. Or should it be handled at the same time (possibly somethink like : BRDF * sample_of_reflection + BTDF * sample_of_refraction)?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;A classic path tracer would randomly pick either reflection or refraction based on the fresnel coefficient. That does efficient sampling. But if you can easily get both from a cube map, you can also blend them with the fresnel coefficient.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;After some playing around with this function I noticed that is basically something akin to a gaussian distribution pointing towards the positive z-axis. But shouldn't the distribution give samples which are distributed around the surface normal?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Yes, you need to transform the generated direction. It is mentionned in section 5.2, after equation (24), that &lt;span class=&quot;math-container&quot;&gt;$\theta_m$&lt;/span&gt; is the angle between &lt;span class=&quot;math-container&quot;&gt;$m$&lt;/span&gt; (microfacet normal) and &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; (surface normal). They don't go into great detail as this way of defining microfacet models goes back to much older articles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The short version is that you build an orthonormal basis using the surface normal as z and two other perpendicular vectors as x and y. Here it does not matter which as the distribution is isotropic, as long as they are perpendicular to each other and to the normal. Then you transform using that basis.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2019-12-14T02:28:41.630" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9423" PostTypeId="2" ParentId="9418" CreationDate="2019-12-15T06:15:32.847" Score="0" Body="&lt;p&gt;As far as I remember, you need to input data in float array. Right now your input is unsigned char array. To quick check this, try loading any HDR image in float array &amp;amp; pass it on to the setImage functions, this seems to work. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In your case, you would need to read individual image channel data &amp;amp; cast it to float. If your image color is stored in [0-255] range, you would then need to bring it to [0-1] range (Not completely sure about this stage!) &amp;amp; then pass the data in float array to denoiser functions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hope this helps. &lt;/p&gt;&#xA;" OwnerUserId="5066" LastActivityDate="2019-12-15T06:15:32.847" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9424" PostTypeId="1" CreationDate="2019-12-16T20:50:57.737" Score="0" ViewCount="47" Body="&lt;h2&gt;The problem&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I'm using a 3D extension of the well-known &quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Turtle_graphics&quot; rel=&quot;nofollow noreferrer&quot;&gt;Turtle graphics&lt;/a&gt;&quot; to draw plants. My system works by maintaining a position &lt;span class=&quot;math-container&quot;&gt;$\vec{p}$&lt;/span&gt; and three vectors:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The heading &lt;span class=&quot;math-container&quot;&gt;$\vec{H}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;The &quot;up&quot; direction &lt;span class=&quot;math-container&quot;&gt;$\vec{U}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;The &quot;left&quot; direction &lt;span class=&quot;math-container&quot;&gt;$\vec{L}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;My problem is now that I want to be able to create 3D objects at the position of the turtle, but with the added difficulty of being &quot;transformed&quot; into the turtle's coordinate system defined by the vectors &lt;span class=&quot;math-container&quot;&gt;$\vec{H}, \vec{U}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{L}$&lt;/span&gt;, so that the model is &quot;aligned&quot; with the direction and orientation of the turtle. I basically want to achieve that the model is transformed in such a way, that:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The local origin becomes the turtle position&lt;/li&gt;&#xA;&lt;li&gt;The local x-Axis is rotated onto the heading vector &lt;span class=&quot;math-container&quot;&gt;$\vec{H}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;The local y-Axis is rotated onto the right vector &lt;span class=&quot;math-container&quot;&gt;$- \vec{L}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;The local z-Axis is rotated onto the up vector &lt;span class=&quot;math-container&quot;&gt;$\vec{U}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The reason I want this is to be able to spawn 3D models that describe the leaves of a plant on stalks generated by the turtle.&lt;/p&gt;&#xA;&#xA;&lt;h2&gt;My own idea so far&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;I'm not very good at linear algebra, but I thought of using a base change matrix of the form:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$A := \begin{pmatrix}\vec{H} &amp;amp; -\vec{L} &amp;amp; \vec{U} \end{pmatrix}$$&lt;/span&gt;&#xA;And combining that with the translation by &lt;span class=&quot;math-container&quot;&gt;$\vec{p}$&lt;/span&gt; to obtain the following model matrix:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$T := \begin{pmatrix} A &amp;amp; \begin{matrix} p_1 \\ p_2 \\ p_3\end{matrix}\\ &#xA;\begin{matrix}0 &amp;amp; 0&amp;amp; 0\end{matrix} &amp;amp; 1&#xA;\end{pmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would this achieve the effect I want? I am currently only in the planning phase of the project this will be used in, so I can't check this myself.&lt;/p&gt;&#xA;" OwnerUserId="11605" LastActivityDate="2019-12-16T20:50:57.737" Title="Transformation for aligning 3D object with reference frame of 3D turtle graphics" Tags="&lt;transformations&gt;&lt;model&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9426" PostTypeId="1" CreationDate="2019-12-17T06:22:20.217" Score="2" ViewCount="158" Body="&lt;p&gt;I am attempting to implement chunks/octrees to speed up my render times. However, sometimes the walls show horizontal or vertical lines (rays hitting the inside of voxels?) or some blocks disappear altogether, although sometimes everything renders fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: Yes, the chunks are stored fine. OctrA stands for OctreeA,  which is the chunk.&#xA;Edit: I reversed the ray for two steps after hitting a chunk. Although the glitches have gotten better, there is still the same problem.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;&#xA;      float cameraX = x/(float)HALFRESX -1;// -1 to 1&#xA;      struct Point3D rayd;&#xA;      rayd.x = dir.x + plane.x * cameraX;&#xA;      rayd.y = dir.y + plane.y * cameraX;&#xA;&#xA;      struct Point3D delta;&#xA;      delta.x = fabsf(1/rayd.x);&#xA;      delta.y = fabsf(1/rayd.y);&#xA;&#xA;      int zy = -HALFRESY;&#xA;&#xA;      struct pos map;&#xA;      map.x = (char)pos.x;&#xA;      map.y = (char)pos.y;&#xA;&#xA;      float sdistX;&#xA;      float sdistY;&#xA;      struct pos s;&#xA;      struct pos step;&#xA;      struct Point3D sdist;&#xA;      if(rayd.x &amp;lt; 0) {&#xA;        step.x = -1;&#xA;        s.x = 1;&#xA;        sdistX = (pos.x - map.x) * delta.x; &#xA;      }&#xA;      else {&#xA;        step.x = 1;&#xA;        s.x = 0;&#xA;        sdistX = (map.x + 1 - pos.x) * delta.x; &#xA;      }&#xA;      if(rayd.y &amp;lt; 0) {&#xA;        step.y = -1;&#xA;        s.y = 1;&#xA;        sdistY = (pos.y - map.y) * delta.y; &#xA;      }&#xA;      else {&#xA;        step.y = 1;&#xA;        s.y = 0;&#xA;        sdistY = (map.y + 1 - pos.y) * delta.y; &#xA;      }&#xA;&#xA;      for(int y = 0; y &amp;lt; RESY; y += 1) { &#xA;&#xA;        zy++;&#xA;        float cameraY = y/(float)HALFRESY - 1;&#xA;        rayd.z = dir.z + plane.z * cameraY;&#xA;        delta.z = fabsf(1/rayd.z);&#xA;&#xA;        map.x = (char)pos.x;&#xA;        map.y = (char)pos.y;&#xA;        map.z = (char)pos.z;&#xA;        sdist.x = sdistX;&#xA;        sdist.y = sdistY; &#xA;&#xA;        if(rayd.z &amp;lt; 0) {&#xA;          step.z = -1;&#xA;          s.z = 1;&#xA;          sdist.z = (pos.z - map.z) * delta.z; &#xA;        }&#xA;        else {&#xA;          step.z = 1;&#xA;          s.z = 0;&#xA;          sdist.z = (map.z + 1 - pos.z) * delta.z; &#xA;        }&#xA;#ifdef USE_OCTREE&#xA;&#xA;        while( !octrA[map.x/2][map.y/2][map.z/2]) {&#xA;          if(sdist.y &amp;lt; sdist.x ) {&#xA;            if(sdist.y &amp;lt; sdist.z) {&#xA;              sdist.y += delta.y*2;&#xA;              map.y += step.y*2;&#xA;            }&#xA;            else {&#xA;              sdist.z += delta.z*2;&#xA;              map.z += step.z*2;&#xA;            }&#xA;          }&#xA;          else {&#xA;            if(sdist.x &amp;lt; sdist.z) {&#xA;              sdist.x += delta.x*2;&#xA;              map.x += step.x*2;&#xA;            }&#xA;            else {&#xA;              sdist.z += delta.z*2;&#xA;              map.z += step.z*2; &#xA;            }&#xA;          }&#xA;        }&#xA;        if(octr) {&#xA;          if(sdist.y &amp;gt; sdist.x ) {&#xA;            if(sdist.y &amp;gt; sdist.z) {&#xA;              sdist.y -= delta.y*2;&#xA;              map.y -= step.y*2;&#xA;            }&#xA;            else {&#xA;              sdist.z -= delta.z*2;&#xA;              map.z -= step.z*2;&#xA;            }&#xA;          }&#xA;          else {&#xA;            if(sdist.x &amp;gt; sdist.z) {&#xA;              sdist.x -= delta.x*2;&#xA;              map.x -= step.x*2;&#xA;            }&#xA;            else {&#xA;              sdist.z -= delta.z*2;&#xA;              map.z -= step.z*2; &#xA;            }&#xA;          }&#xA;        }&#xA;&#xA;#endif&#xA;        char side; //either 0 (NS), or 1 (EW), or 2(UD)&#xA;        while( !MAP[map.x][map.y][map.z]) {&#xA;          if(sdist.y &amp;lt; sdist.x ) {&#xA;            if(sdist.y &amp;lt; sdist.z) {&#xA;              sdist.y += delta.y;&#xA;              map.y += step.y;&#xA;              side = 1; // y&#xA;            }&#xA;            else {&#xA;              sdist.z += delta.z;&#xA;              map.z += step.z;&#xA;              side = 2; &#xA;            }&#xA;          }&#xA;          else {&#xA;            if(sdist.x &amp;lt; sdist.z) {&#xA;              sdist.x += delta.x;&#xA;              map.x += step.x;&#xA;              side = 0; &#xA;            }&#xA;            else {&#xA;              sdist.z += delta.z;&#xA;              map.z += step.z; &#xA;              side = 2; &#xA;            }&#xA;          }&#xA;        }&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11609" LastEditorUserId="11609" LastEditDate="2019-12-18T09:52:44.763" LastActivityDate="2021-05-11T12:00:40.043" Title="How can I raycast with chunks?" Tags="&lt;raytracing&gt;&lt;3d&gt;" AnswerCount="1" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9427" PostTypeId="2" ParentId="9426" CreationDate="2019-12-17T13:26:14.657" Score="0" Body="&lt;p&gt;Have you confirmed that objects that clip a chunk border are stored in both chunks?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have you confirmed that octrA[map.x/2][map.y/2][map.z/2] can't point to anything weird?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In fact, what even is octrA? I assume that it's the array storing the chunks but I can't know for sure because I couldn't find it anywhere else in your code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other than that I'm having a bit of a hard time interpreting the problem and your code. Could you add some pictures and comments to your code?&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2019-12-17T13:26:14.657" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9428" PostTypeId="1" AcceptedAnswerId="9429" CreationDate="2019-12-17T13:36:55.263" Score="0" ViewCount="55" Body="&lt;p&gt;I'm trying to make the path tracer shown in the Ray Tracing in One Weekend series multithreaded.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the starting of my main function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//scene setup&#xA;    hitable* world = cornell_box();&#xA;    auto start = std::chrono::high_resolution_clock::now();&#xA;    light_hitable_list = hitable_list(lightsVector);&#xA;    string filePath = &quot;img.png&quot;;&#xA;&#xA;    Image image(nx, ny);&#xA;    TilePool tilePool(nx, ny, 50);&#xA;&#xA;    //maxThreads = std::thread::hardware_concurrency();&#xA;    maxThreads = 1;&#xA;    std::vector&amp;lt;std::thread&amp;gt; renderThreads;&#xA;    renderThreads.resize(maxThreads);&#xA;&#xA;    //RenderSettings renderSettings{world, &amp;amp;image, &amp;amp;tilePool, ns, BLACK_SKY, false, &quot;img.png&quot;};&#xA;&#xA;    for (unsigned int i = 0; i &amp;lt; maxThreads; i++)&#xA;    {&#xA;        renderThreads[i] = std::thread(&amp;amp;renderScene, world, &amp;amp;image, &amp;amp;tilePool);&#xA;    }&#xA;    for (unsigned int i = 0; i &amp;lt; maxThreads; i++)&#xA;    {&#xA;        if (renderThreads[i].joinable())&#xA;        {&#xA;            renderThreads[i].join();&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here's the renderScene function:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void renderScene(hitable* world, Image* image, TilePool* tilePool) {&#xA;&#xA;    while (tilePool-&amp;gt;getPoolSize() &amp;gt; 0)&#xA;    {   &#xA;        Tile tile = tilePool-&amp;gt;getNextTile();&#xA;&#xA;        for (int j = tile.yMax - 1; j &amp;gt;= tile.yMin; j--) {&#xA;&#xA;            for (int i = tile.xMin; i &amp;lt; tile.xMax; i++) {&#xA;                vec3 col(0, 0, 0);&#xA;                for (int s = 0; s &amp;lt; ns; s++) {&#xA;                    float u = (float(i) + random_number()) / float(nx);&#xA;                    float v = (float(j) + random_number()) / float(ny);&#xA;&#xA;                    ray r = cam.get_ray(u, v);&#xA;                    vec3 p = r.point_at_parameter(2.0);&#xA;                    col += de_nan(color(r, world, &amp;amp;light_hitable_list, 0));&#xA;                }&#xA;                col /= float(ns);&#xA;                col = vec3(sqrt(col[0]), sqrt(col[1]), sqrt(col[2]));&#xA;&#xA;                (*image)[3 * i + 3 * nx * (ny - 1 - j)] = col[0];&#xA;                (*image)[3 * i + 3 * nx * (ny - 1 - j) + 1] = col[1];&#xA;                (*image)[3 * i + 3 * nx * (ny - 1 - j) + 2] = col[2];&#xA;&#xA;            }&#xA;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;If I run the code above as it is I get this error:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Exception thrown at 0x00007FF70F601F2E in raytracer.exe: 0xC0000005:&#xA;  Access violation reading location 0x000001C200000190.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;here: &lt;a href=&quot;https://github.com/KarthikRIyer/RayTracer/blob/ec51999070218839e6aef2a65868e57fc6bb728d/src/objects/hitables/hitable_list.h#L29&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KarthikRIyer/RayTracer/blob/ec51999070218839e6aef2a65868e57fc6bb728d/src/objects/hitables/hitable_list.h#L29&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And instead of using just 1 thread if I use &lt;code&gt;maxThreads = std::thread::hardware_concurrency();&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I get this error:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Exception thrown at 0x00007FF79DE01FCE in raytracer.exe: 0xC0000005:&#xA;  Access violation reading location 0x0000015E0000012C.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;here: &lt;a href=&quot;https://github.com/KarthikRIyer/RayTracer/blob/ec51999070218839e6aef2a65868e57fc6bb728d/src/objects/hitables/hitable_list.h#L38&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KarthikRIyer/RayTracer/blob/ec51999070218839e6aef2a65868e57fc6bb728d/src/objects/hitables/hitable_list.h#L38&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These errors are not for the parameters passed into the function. I have checked if they are NULL. It seems to be for the function call.&#xA;I'm completely new to multithreaded programming. But it doesn't feel like the error might be due to multithreading because I get such an error even while using &lt;code&gt;maxThreads = 1&lt;/code&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of the cornell box scene if I use the &lt;code&gt;model_scene&lt;/code&gt; defined here: &lt;a href=&quot;https://github.com/KarthikRIyer/RayTracer/blob/ec51999070218839e6aef2a65868e57fc6bb728d/src/Source.cpp#L135&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KarthikRIyer/RayTracer/blob/ec51999070218839e6aef2a65868e57fc6bb728d/src/Source.cpp#L135&lt;/a&gt; sometimes I get the same error as above and sometimes it randomly starts working even with more than one threads.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can someone please shed light as to why this might be occuring and what points should I keep in mind while writing a multithreaded path tracer?&lt;/p&gt;&#xA;" OwnerUserId="8962" LastEditorUserId="8962" LastEditDate="2019-12-17T13:45:44.547" LastActivityDate="2019-12-18T20:41:28.847" Title="Trouble making path tracer multithreaded, read access violation" Tags="&lt;pathtracing&gt;&lt;multithreading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9429" PostTypeId="2" ParentId="9428" CreationDate="2019-12-18T20:41:28.847" Score="0" Body="&lt;p&gt;I found out what was wrong. It wasn't related to multithreading at all.&#xA;I was taking in a vector in a constructor &lt;code&gt;hitable_list(std::vector&amp;lt;hitable*&amp;gt; listVector)&lt;/code&gt; and using a pointer to the first element of the vector elsewhere. So as soon as the vector went out of scope the pointer became invalid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To solve this issue I just removed this constructor and whenever I need to pass in a vector I make sure that the vector stays in scope always and directly pass in the pointer to the first element of the vector, and it's size.&lt;/p&gt;&#xA;" OwnerUserId="8962" LastActivityDate="2019-12-18T20:41:28.847" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9430" PostTypeId="1" CreationDate="2019-12-19T15:42:55.813" Score="1" ViewCount="45" Body="&lt;p&gt;So I have been reading this wonderful book on ray tracing by Kevin Suffern, Ray tracing from Ground Up. I am reading this book after finishing Peter Shirley's first two book on ray tracing &amp;amp; implementing multi-threaded ray tracer, adding features like Intel's denoiser, assimp integration etc. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What struck me was before I read the third book, it would be good idea to read more on sampling. Which is why am skimming through this current book. At this moment, am stuck on a topic which explains how sample point in unit square is mapped onto unit radius disk. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lqjec.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lqjec.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am stuck at the part where book mentions how equations are mapped. Radius part is clear to me, however, am not very clear about the angle (phi) part. Is there any derivation as to how this was deduced? Or is it done to avoid atan() calculation and is a neat approximation of it? After putting in test values I have understood how values get converted, however, am very keen to understand how this formulas for Phi was deduced based on different quarters, unless it's very obvious and I have overlooked it :(  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regards. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&#xA;After more digging, i have understood that if i assume first quadrant value, then second, third &amp;amp; fourth values can be deduced by rotating/adding (Pi/2) to angle phi &amp;amp; switching axis due to quadrant change. However, first quadrant value is still not clear :|&lt;/p&gt;&#xA;" OwnerUserId="5066" LastEditorUserId="5066" LastEditDate="2019-12-19T17:17:19.683" LastActivityDate="2020-01-19T02:03:30.683" Title="Mapping sample to a disk" Tags="&lt;raytracing&gt;&lt;mathematics&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9432" PostTypeId="2" ParentId="9430" CreationDate="2019-12-20T01:53:06.793" Score="-1" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CGpwF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CGpwF.jpg&quot; alt=&quot;Simplified Map Equations&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Check the last column in the table for the deciphered version of the existing Map Equations for easier comprehension. &lt;/p&gt;&#xA;" OwnerUserId="11619" LastActivityDate="2019-12-20T01:53:06.793" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9434" PostTypeId="1" AcceptedAnswerId="9435" CreationDate="2019-12-21T05:45:14.220" Score="4" ViewCount="134" Body="&lt;p&gt;I am looking for a shader (or at least the right terminology) for crushing an image. It should be something very similar to barrel distortion, but instead of the center crushing outward to the edges, I want to edges to crush inward to the center.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, this image:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/AKqdd.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AKqdd.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;instead of being deformed like this:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5eWvg.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5eWvg.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should rather be deformed like this:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Sh5og.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Sh5og.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will be used for a Godot project, but even regular shading language would be tremendously helpful. I tried modifying &lt;a href=&quot;https://gist.github.com/quiglemj/971f4cec1b128c58b4864c5200bfc579&quot; rel=&quot;nofollow noreferrer&quot;&gt;this gist&lt;/a&gt; to no avail.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Edit&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Here is the final result using the accepted answer's solution:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HRIq8.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HRIq8.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11623" LastEditorUserId="11623" LastEditDate="2019-12-22T07:10:06.803" LastActivityDate="2019-12-23T00:33:39.583" Title="Shader or formula that distorts inward" Tags="&lt;shader&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9435" PostTypeId="2" ParentId="9434" CreationDate="2019-12-21T19:19:10.070" Score="4" Body="&lt;p&gt;Your example images do not make the desired effect very apparent, but the opposite of a barrel distortion is a pincushion distortion:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cD2a8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cD2a8.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found a &lt;a href=&quot;https://www.shadertoy.com/view/ll2GWV&quot; rel=&quot;nofollow noreferrer&quot;&gt;fisheye shader on ShaderToy&lt;/a&gt; which produces the following image:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hTDCV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hTDCV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By slightly modifying the shader code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// This shader is based on cafe's fisheye shader:&#xA;// https://www.shadertoy.com/view/ll2GWV&#xA;&#xA;vec3 checker(vec2 uv){&#xA;    return vec3(abs(floor(mod(uv.x*10.,2.))-floor(mod(uv.y*10.,2.))));   &#xA;}&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;    vec2 uv = fragCoord.xy*2. / iResolution.xy-vec2(1.);&#xA;&#xA;    //------------------------------------------------&#xA;    // To use in Godot, port this section:&#xA;    //------------------------------------------------&#xA;&#xA;    // I picked these somewhat arbitrarily&#xA;    const float BARREL = -1.0;&#xA;    const float PINCUSHION = 0.1;&#xA;&#xA;    float effect = PINCUSHION; // Set effect to either BARREL or PINCUSHION&#xA;    float effect_scale = 1.0;  // Play with this to slightly vary the results&#xA;&#xA;    /// Fisheye Distortion ///&#xA;    float d=length(uv);&#xA;    float z = sqrt(1.0 + d * d * effect);&#xA;    float r = atan(d, z) / 3.14159;&#xA;    r *= effect_scale;&#xA;    float phi = atan(uv.y, uv.x);&#xA;&#xA;    uv = vec2(r*cos(phi)+.5,r*sin(phi)+.5);&#xA;&#xA;    //------------------------------------------------&#xA;    // end relevant logic&#xA;    //------------------------------------------------&#xA;&#xA;    fragColor = vec4(checker(uv),1.);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;We can easily obtain &lt;a href=&quot;https://www.shadertoy.com/view/wtt3z2&quot; rel=&quot;nofollow noreferrer&quot;&gt;the opposite effect&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cZAYV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cZAYV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If this is not the exact effect you're looking for, I recommend playing around with the code a bit yourself. Change some signs from + to -, add scale factors and explore the possibilities. You may even stumble across a more interesting effect than what were you looking for.&lt;/p&gt;&#xA;" OwnerUserId="6145" LastEditorUserId="6145" LastEditDate="2019-12-23T00:33:39.583" LastActivityDate="2019-12-23T00:33:39.583" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9436" PostTypeId="1" CreationDate="2019-12-23T04:53:21.970" Score="1" ViewCount="105" Body="&lt;p&gt;I know how to generate the walls of a cylinder with triangle strips and the caps with triangle fans, but since I am working inside a geometry shader, I can only output triangle strips, so I am kind of lost here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This here is my current code, which only generates the hull of the cylinder based on a line segment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;    layout(lines) in;&#xA;    layout(triangle_strip, max_vertices = 32) out;&#xA;&#xA;    uniform mat4 projection;&#xA;    uniform mat4 view;&#xA;    uniform mat4 model;&#xA;&#xA;    in Vertex &#xA;    {&#xA;        vec4 color;&#xA;        float width;&#xA;    } vertex[];&#xA;&#xA;    out vec4 vertex_color;&#xA;    out vec3 normal_vector;&#xA;&#xA;    vec3 createPerp(vec3 p1, vec3 p2)&#xA;    {&#xA;        vec3 invec = normalize(p2 - p1);&#xA;        vec3 ret = cross( invec, vec3(0.0, 0.0, 1.0) );&#xA;        if ( length(ret) == 0.0 )&#xA;        {&#xA;            ret = cross(invec, vec3(0.0, 1.0, 0.0) );&#xA;        }&#xA;        return ret;&#xA;    }&#xA;&#xA;&#xA;    void main()&#xA;    {&#xA;        mat4 mvp = projection * view * model;&#xA;&#xA;        vec3 axis = gl_in[1].gl_Position.xyz - gl_in[0].gl_Position.xyz;&#xA;&#xA;        vec3 perpx = normalize(createPerp(gl_in[1].gl_Position.xyz, gl_in[0].gl_Position.xyz));&#xA;        vec3 perpy = cross(normalize(axis), perpx);&#xA;&#xA;        float r1 = vertex[0].width / 1000.0;&#xA;        float r2 = vertex[0].width / 1000.0;&#xA;&#xA;        int segs = 16;&#xA;        for(int i=0; i&amp;lt;segs; i++) {&#xA;            float a = i/float(segs-1) * 2.0 * 3.14159;&#xA;            float ca = cos(a); float sa = sin(a);&#xA;            vec3 normal = vec3( ca*perpx.x + sa*perpy.x,&#xA;                            ca*perpx.y + sa*perpy.y,&#xA;                            ca*perpx.z + sa*perpy.z );&#xA;&#xA;&#xA;&#xA;            vec3 p1 = gl_in[0].gl_Position.xyz + r1*normal;&#xA;            vec3 p2 = gl_in[1].gl_Position.xyz + r2*normal;&#xA;&#xA;            gl_Position = mvp * vec4(p1, 1.0);&#xA;            vertex_color = vertex[0].color;&#xA;            normal_vector = normal;&#xA;            EmitVertex();&#xA;&#xA;            gl_Position = mvp * vec4(p2, 1.0);&#xA;            vertex_color = vertex[0].color;&#xA;            normal_vector = normal;&#xA;            EmitVertex();       &#xA;        }&#xA;        EndPrimitive();   &#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there some simple way to integrate the generation of the endcaps here?&lt;/p&gt;&#xA;" OwnerUserId="11605" LastActivityDate="2020-01-24T09:51:46.233" Title="Generating the end caps of a cylinder using triangle strips for use in a geometry shader" Tags="&lt;opengl&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry-shader&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9437" PostTypeId="2" ParentId="9436" CreationDate="2019-12-23T09:54:50.367" Score="2" Body="&lt;p&gt;If the end of your cylinder is &lt;strong&gt;convex&lt;/strong&gt;, with vertices &lt;span class=&quot;math-container&quot;&gt;$V_0, V_1, V_2,...V_{N-1}$&lt;/span&gt; then just replace your fan order (i.e. as above) with this strip &lt;span class=&quot;math-container&quot;&gt;$V_0, V_1, V_{N-1}, V_2, V_{N-2}, V_3...$&lt;/span&gt;, i.e. just zig-zag across the polygon.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-01-24T09:51:46.233" LastActivityDate="2020-01-24T09:51:46.233" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9438" PostTypeId="1" CreationDate="2019-12-23T13:19:58.583" Score="3" ViewCount="114" Body="&lt;p&gt;I wonder why all the well known algorithms of drawing for example circles (bresenham, mid-point, etc) all use integer arithmetics? For example, here is a simple circle drawn with bresenham algorithm:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/N7Spm.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N7Spm.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And this is what I get with a circle drawn using naive algorithm (with real numbers):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nHCk1.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nHCk1.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The bresenham's version just look terrible and feels laggy while the floating point version is much smoother. So why do we read everywhere that &quot;integer&quot; versions are preferred? The integer version is maybe faster but horrible when it comes to animating a moving shape. So the question is: should I use floating point version or bresenham's version in my little toy rasterizer?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's a more real world example:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bresenham:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/69abW.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/69abW.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Floating point:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/G19fN.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/G19fN.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what which version is the correct one? The floating point looks wobbly but smoother than Bresenham. Should I stick with Bresenham integer or use a floating point version smoother (or even a fixed point version)?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastEditorUserId="10928" LastEditDate="2019-12-23T15:35:52.097" LastActivityDate="2019-12-23T16:50:12.230" Title="What is the point of having integer-based draw routines in software rasterizer?" Tags="&lt;animation&gt;&lt;rasterizer&gt;&lt;drawing&gt;&lt;midpoint&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9439" PostTypeId="1" CreationDate="2019-12-23T15:35:06.510" Score="2" ViewCount="58" Body="&lt;p&gt;Various operations on 2D vectors naturally generalise to 3D vectors simply by including the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;-coordinate. The ones that come to mind are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Vector sum and difference&lt;/li&gt;&#xA;&lt;li&gt;Dot product&lt;/li&gt;&#xA;&lt;li&gt;Magnitude (Euclidean norm)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Various graphics programming tasks also use 4D vectors, usually(?) to represent points in 3D projective space (AKA homogeneous coordinates). Given this, it would seem that the above operations should &lt;em&gt;not&lt;/em&gt; use the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;-coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, the magnitude of a 4D vector would be calculated in exactly the same way as the equivalent 3D vector:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\lVert \mathbf{v} \rVert = \sqrt{x^2+y^2+z^2}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;...and not with the inclusion of the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;-coordinate:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\lVert \mathbf{v} \rVert = \sqrt{x^2+y^2+z^2+w^2}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(For a point at infinity, where &lt;span class=&quot;math-container&quot;&gt;$w=0$&lt;/span&gt;, there wouldn't be a difference, but for finite points, there would. I'm also assuming that a finite 4D homogeneous vector is in canonical form, with &lt;span class=&quot;math-container&quot;&gt;$w=1$&lt;/span&gt;.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Is this always the case?&lt;/strong&gt; Is there any situation in graphics programming where calculations on 4D vectors should &lt;em&gt;not&lt;/em&gt; treat them as their 3D equivalents, but should actually make use of the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;-coordinate?&lt;/p&gt;&#xA;" OwnerUserId="11630" LastEditorUserId="11630" LastEditDate="2019-12-23T15:41:04.030" LastActivityDate="2019-12-23T15:41:04.030" Title="When should operations on 4D (homogeneous/projective) vectors use the w-coordinate?" Tags="&lt;mathematics&gt;&lt;vectors&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9440" PostTypeId="2" ParentId="9438" CreationDate="2019-12-23T16:44:51.590" Score="2" Body="&lt;p&gt;The following is really an assorted set of comments:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why integer? Floating-point hardware is (in general) far more complex than integer and so on many (old) CPUs it (a) might not have been available (because of silicon budget) and/or (b) took considerably more clock cycles to execute than integer operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Re &quot;Bresenham's&quot; algorithm: IIRC there is a branch/decision per pixel. On old CPUs (with relatively little or no pipelining) this would have not been a penalty, but with modern, highly pipelined/superscalar  CPUs, each mispredicted branch will be detrimental. &#xA;Presumably (as I can't see your code) using floating-point removes that decision from the loop but, then again, you could use fixed-point (i.e. integer) to get the same effect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said this, hardware rasterisation is probably using fixed-point (i.e. integer) maths when filling polygons as this (a) makes conforming to the OpenGL fill rules easier and (b) prevents some very nasty problems occuring with long/thin triangles.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2019-12-23T16:50:12.230" LastActivityDate="2019-12-23T16:50:12.230" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9441" PostTypeId="1" CreationDate="2019-12-25T02:26:10.413" Score="0" ViewCount="40" Body="&lt;p&gt;my question might come in a bit weird but I'm looking for something that would be considered very CPU-intensive video to decode (for playback I mean). I would like to have some sample of 1080p and 4k videos that would classify to see if my CPU can handle it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry if this is a bit of off-topic but I'm not sure where else on the internet to ask.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Backstory to prevent XY-problem: HW-accelerated video decoding on my GPU is not working and I'm trying to find if it actually is a problem or if my CPU can handle it fine.&lt;/p&gt;&#xA;" OwnerUserId="11634" LastActivityDate="2020-05-12T18:57:09.520" Title="What would be an example of decoding-intensive video?" Tags="&lt;video&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9442" PostTypeId="1" CreationDate="2019-12-25T09:18:44.583" Score="2" ViewCount="37" Body="&lt;p&gt;Consider a square S with vertices (1,1,0), (1,-1,0), (-1,-1,0) and (-1,1,0) and a plane P defined by &lt;span class=&quot;math-container&quot;&gt;$z=1$&lt;/span&gt;. Let the perspective projection of S on P is denoted by S'. &#xA;What coordinates of the Center of projection(COP) will convert the square S in rectangle or rhombus in S'? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found this question in my class test. As the object and the projection plane are parallel to each other, i think every coordinates for center of projection will generate square. But i can't find any valid mathematical proof for that. Is my assumption valid or not?  &lt;/p&gt;&#xA;" OwnerUserId="11636" LastActivityDate="2019-12-25T09:18:44.583" Title="Project a Square as rectangle in projection plane using perspective projection" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9444" PostTypeId="1" AcceptedAnswerId="9445" CreationDate="2019-12-26T06:04:01.220" Score="4" ViewCount="158" Body="&lt;p&gt;In the context of global illumination and the scattering equation, do we need to understand &quot;light sources&quot; as surfaces with a &quot;purely emissive&quot; material on which no scattering is present?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In contrast, any surface in the scene geometry could be equipped with a self-emissive material and hence being somehow a &quot;light source&quot; (it's kind of a philosophical question, I guess).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, since we often talk about light-carrying paths of &quot;length&quot; &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt;, where one endpoint is located on the camera and the other on a light source, I guess that's how we need to see it. Am I correct or is there something I'm missing?&lt;/p&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2019-12-26T10:13:55.317" Title="What is a &quot;light source&quot; in global illumination?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;material&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9445" PostTypeId="2" ParentId="9444" CreationDate="2019-12-26T10:13:55.317" Score="4" Body="&lt;p&gt;Like @lightxbulb said, a light source (i.e. an emissive surface whose &lt;code&gt;L_e&lt;/code&gt; term in the rendering equation is greater than zero) can also have a BRDF.&#xA;People usually do not model light sources really accurately down to the Tungsten filament geometry inside of a glass-enclosed gas chamber for incandescent light bulbs. Such light sources usually are modelled as simple geometries, like spheres, capsules, lines, rectangles or more generic polygons, etc.&#xA;So, most often, light sources are usually not exactly physically accurate anyways, because it would be too computationally expensive (imagine computing the intersection of a ray with the Tungsten filament in addition to account for a very little bit of volumetric scattering through the gas).&#xA;Therefore, in the simplest cases, such an incandescent light source is down to a simple sphere anyways. In that case, it would make most sense to model this light source with a translucent BTDF (Bidirectional Transmittance Distribution Function), because most of the rays will probably not hit the filament but would go straight through the glass.&#xA;What we would have to consider, however, is Fresnel and retro-reflection on the glass surface of the light bulb.&#xA;But it all depends on how accurately you want to model your light sources.&#xA;If, on the other hand, your light source is a milk glass light bulb, then you would probably need a BRDF + BTDF (or more generally a BSDF - bidirectional scattering distribution function) to account for the light that is reflected off the glass surface and the amount of light that is trasmitting through the glass.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, stopping a ray at the light source (as you pointed out) would only be actually physically correct, if the surface of the light source is a black body not reflecting any light but only emitting light due to its temperature.&lt;/p&gt;&#xA;" OwnerUserId="8592" LastActivityDate="2019-12-26T10:13:55.317" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9447" PostTypeId="1" CreationDate="2019-12-28T08:47:00.870" Score="1" ViewCount="32" Body="&lt;p&gt;I have paths in SVG file with &lt;code&gt;d&lt;/code&gt; attributes with values like &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;M 48.75521890547264 45.77014427860697 Q 48.756218905472636&#xA;  45.77114427860697 50.24875621890547 45.77114427860697 Q 51.74129353233831 45.77114427860697 55.72139303482587 46.26865671641791 Q 59.701492537313435 46.766169154228855 64.17910447761194 46.766169154228855 Q 68.65671641791045 46.766169154228855 73.6318407960199 47.2636815920398 Q 78.60696517412936 47.76119402985075 82.08955223880596 47.76119402985075 Q 85.57213930348259 47.76119402985075 88.55721393034827&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to classify this path into geometric shapes like circle, rectangle, ellipse etc programmatically. When I say programmatically I mean no image processing techniques should be involved i.e. strict requirement.&lt;br&gt;&#xA;Is there any way to do this. Please guide me.  &lt;/p&gt;&#xA;" OwnerUserId="7515" LastEditorUserId="11652" LastEditDate="2019-12-30T09:22:32.153" LastActivityDate="2019-12-30T09:22:32.153" Title="How to programmatically extract shape types like circle etc from SVG file path attributes" Tags="&lt;vector-graphics&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9448" PostTypeId="1" CreationDate="2019-12-28T09:29:30.683" Score="0" ViewCount="453" Body="&lt;p&gt;In 3d modeling, there is some &quot;triangle count&quot; which determines complexity. I am not sure but I think cubes have 12 triangles or somethong. But I see NONE. They have squares, no triangles! Can someone please help me understand what a triangle is? Where in the cube are these 12 &quot;triangles&quot; located?&lt;/p&gt;&#xA;" OwnerDisplayName="user11352" LastEditorDisplayName="user11352" LastEditDate="2020-02-09T21:48:10.373" LastActivityDate="2020-02-11T09:19:23.940" Title="What are &quot;Triangles&quot; in 3d modeling?" Tags="&lt;3d&gt;" AnswerCount="2" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9449" PostTypeId="1" AcceptedAnswerId="9451" CreationDate="2019-12-28T13:13:09.823" Score="2" ViewCount="285" Body="&lt;p&gt;When compiling a glsl fragment shader which reads &lt;code&gt;gl_PrimitiveID&lt;/code&gt; with glslc compiler I get the spirv-1.0 with Geometry capability enabled, which is technically correct, as it's stated in spirv spec. &#xA;Vulkan 1.0 spec says that Geometry capability must be supported if &lt;code&gt;geometryShader&lt;/code&gt; feature is enabled. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I assume that unless &lt;code&gt;geometryShader&lt;/code&gt; is enabled, one can't use &lt;code&gt;gl_PrimitiveID&lt;/code&gt;. Specifically, using &lt;code&gt;gl_PrimitiveID&lt;/code&gt; is impossible on moltenVK, as it does not support this feature, isn't it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my pipeline I used &lt;code&gt;gl_PrimitiveID&lt;/code&gt; to fetch per-face data from global ssbo and to render face ids to attachment for later reuse. Is it possible to achieve similar result without &lt;code&gt;gl_PrimitiveID&lt;/code&gt;?&lt;/p&gt;&#xA;" OwnerUserId="10806" LastActivityDate="2019-12-29T17:02:11.097" Title="Vulkan: using gl_PrimitiveID without geometryShader feature" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9450" PostTypeId="1" CreationDate="2019-12-29T13:45:14.423" Score="1" ViewCount="114" Body="&lt;p&gt;As a little project, I'd like to implement a BSP merging algorithm for Boolean operations on solids. But to even tell whether it works, I need some way to render the BSP tree. In other words, I have a BSP tree corresponding to some 3D solid, with all its leaves having an indicator value of &quot;0&quot; or &quot;1&quot;, and I'd like to render out the areas corresponding to the leaves with value 1.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand the general approach for doing the actual BSP tree merging, but I'm not really sure how to render a BSP tree. I'm not interested in efficiency, and I don't need to convert the BSP tree to an actual mesh/boundary representation - I just want to render the BSP tree somehow (as simply as possible), to have an idea whether the implementation works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd guess that one way to do this would be to go through the tree, and somehow progressively clip the space I have. So I might start with some sort of very large cube (that corresponds to the full 3D space), and I keep clipping it by half planes as  I go through the tree. If I reach a leaf with value 1, I &quot;save&quot; the mesh and render it. This might work, but it seems like a bit too much work, and honestly I'm not experienced in computer graphics, so I'd prefer if there was some easier way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd appreciate any advice.&lt;/p&gt;&#xA;" OwnerUserId="11656" LastActivityDate="2019-12-29T13:45:14.423" Title="BSP tree rendering" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;algorithm&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9451" PostTypeId="2" ParentId="9449" CreationDate="2019-12-29T17:02:11.097" Score="3" Body="&lt;p&gt;It seems likely that the mechanism by which the &lt;code&gt;gl_PrimitiveID&lt;/code&gt; is generated is, in some way, based on the hardware that makes geometry shaders possible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL ES 3.1 contains compute shaders but not geometry shaders (or tessellation). But it doesn't have &lt;code&gt;gl_PrimitiveID&lt;/code&gt;. By contrast, ES 3.2 contains GS's and &lt;code&gt;gl_PrimitiveID&lt;/code&gt;. The same goes for desktop OpenGL 3.1 vs. 3.2 and its GS functionality. Having a GS and having the ability to identify primitives in a sequence seem to be part of the same general functionality.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In my pipeline I used gl_PrimitiveID to fetch per-face data from global ssbo and to render face ids to attachment for later reuse.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Without the hardware functionality, there is no &lt;em&gt;general&lt;/em&gt; way to compute a count of primitives. There are only specific solutions for specific circumstances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if you are using non-index rendering of triangle lists, then you can use &lt;code&gt;gl_VertexID / 3&lt;/code&gt; to compute a primitive ID. Obviously that's a pretty tight restriction, but it would work in that circumstance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You could also provide each vertex with a per-vertex face ID. The VS would output this value using &lt;code&gt;flat&lt;/code&gt; interpolation. By carefully matching the face ID with the &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.1/html/chap19.html#drawing-primitive-topologies&quot; rel=&quot;nofollow noreferrer&quot;&gt;provoking vertex for the primitive topology&lt;/a&gt;, you can effectively assign a face ID to a face. This works best with indexed triangle lists, as you can play around with the order of indices in a triangle more than you can with strips. You basically have to decide which vertex maps to which face, and make sure that that face uses that vertex as the first one.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2019-12-29T17:02:11.097" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9452" PostTypeId="1" AcceptedAnswerId="9454" CreationDate="2019-12-29T23:36:33.577" Score="3" ViewCount="74" Body="&lt;p&gt;Given the rendering equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L_o(x, \theta_o) = L_e(x, \theta_o) + \int_{\Omega} \! f(x,\theta_i,\theta_o) L_i(x,\theta_i) \cos(\theta_i, \theta_o) \, \mathrm{d} \theta_i.&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Rewriting it using linear operator &lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt;, as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L_o = L_e + F \circ L_i.&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Consider the final state that &lt;span class=&quot;math-container&quot;&gt;$L = L_o = L_i$&lt;/span&gt;, then there are two ways to rewrite and interpret:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(1) (light tracing?)&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L_e = (I - F) \circ L.&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(2) (path tracing?)&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L = (I + F + F^2 + F^3 + \cdots ) \circ L_e.&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Questions&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Are the two classifications the correct intrepretation?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Thinking about (2) as path tracing is easy, in that rays starting from &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; go through multiple bounces and finally reaching &lt;span class=&quot;math-container&quot;&gt;$L_e$&lt;/span&gt;; while thinking of (1) as light tracing is difficult for me. Are there any intuitive explanations for both?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6470" LastEditorUserId="6470" LastEditDate="2019-12-29T23:57:09.977" LastActivityDate="2019-12-30T15:16:30.510" Title="Intrepret path/light tracing by rewriting light transport equation" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;physically-based&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9454" PostTypeId="2" ParentId="9452" CreationDate="2019-12-30T15:16:30.510" Score="3" Body="&lt;p&gt;Having the rendering equation one can rewrite it in operator form:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L = L_e + TL$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(I-T)L = L_e$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = (I-T)^{-1}L_e$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = \sum_{k=0}^{\infty}T^kL_e$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The last equality holds if &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; is a contraction (&lt;span class=&quot;math-container&quot;&gt;$\|T\| &amp;lt; 1$&lt;/span&gt;), and under very specific conditions if &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; is not a contraction. An example of when the 4th equality does not hold would be picking an enclosed volume bounded by some surface, that is made of a non-energy conserving material, and putting a light source inside. Then the radiance will keep increasing with every bounce so at some point &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; will be infinity everywhere on the inside of the volume. Meaning that the the series does not converge.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 4th equality is really the &lt;a href=&quot;https://en.wikipedia.org/wiki/Liouville%E2%80%93Neumann_series&quot; rel=&quot;nofollow noreferrer&quot;&gt;Liouville-Neumann&lt;/a&gt; expansion. So you get an infinite sum of increasingly-dimensional integrals, each subsequent term being a bounce away from the previous. Each term gives you the contribution due to a light path of length equal to the index of the term. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;More precisely, this solution gives you the steady state &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; if it exists (we assume that light travels instantaneously, that it is incoherent, linear etc). Note that &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; is simply the radiance function, so this formalism really gives you the solution at every point in the scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In practice you usually need only the radiance measured at the surface of a virtual camera film. So a straightforward optimization is to trace rays starting from the surface of the camera film. This does not guarantee that you get the solution for &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; at every point of the scene, but is a lot more efficient. You can also trace rays starting at the light source, but you are usually also interested in their contribution to the film, so the measurement function (see Veach's thesis) has to also make it in there, and only a subset of lights may be of interest. Finally you can do photon mapping, or light tracing where you are interested of the radiance over the whole scene, and that would be the closest thing to the original formulation.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2019-12-30T15:16:30.510" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9455" PostTypeId="1" CreationDate="2019-12-31T01:48:53.277" Score="0" ViewCount="92" Body="&lt;p&gt;I am doing some animation jobs. I need to pack some pivots into UV and then my shader can read them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need to pack 4 float3 into a float4. Therefore, I need to pack each float3 into a  float.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These 4 float3 are (model space position1, direction1, model space position2, direction2). I know how to handle the directions because they are normalized. I can use something like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; #define f3_f(c) (dot(round((c) * 255), float3(65536, 256, 1)))&#xA; #define f_f3(f) (frac((f) / float3(16777216, 65536, 256)))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But How can I pack these positions? I am using SM3.0 and I can't use bitwise operations&lt;/p&gt;&#xA;" OwnerUserId="9987" LastActivityDate="2019-12-31T01:48:53.277" Title="How to pack 3 floats into one?" Tags="&lt;shader&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9457" PostTypeId="1" AcceptedAnswerId="9458" CreationDate="2020-01-02T09:38:01.110" Score="0" ViewCount="88" Body="&lt;p&gt;I don't understand something about the near clipping plane. It's there to avoid the division by &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; but when we compute the pixel coordinates, we just need to multiply by the clipping plane to clip the object?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example in this code, from &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/3d-viewing-pinhole-camera/implementing-virtual-pinhole-camera&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.scratchapixel.com/lessons/3d-basic-rendering/3d-viewing-pinhole-camera/implementing-virtual-pinhole-camera&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;pScreen.x = pCamera.x / -pCamera.z * near; &#xA;pScreen.y = pCamera.y / -pCamera.z * near; &#xA;&#xA;Vec2f pNDC; &#xA;pNDC.x = (pScreen.x + r) / (2 * r); &#xA;pNDC.y = (pScreen.y + t) / (2 * t); &#xA;pRaster.x = (int)(pNDC.x * imageWidth); &#xA;pRaster.y = (int)((1 - pNDC.y) * imageHeight); &#xA;&#xA;bool visible = true; &#xA;if (pScreen.x &amp;lt; l || pScreen.x &amp;gt; r || pScreen.y &amp;lt; b || pScreen.y &amp;gt; t) &#xA;    visible = false; &#xA;&#xA;return visible; &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When do they actually discard points that have a z component smaller than the near clipping plane? They just discard those which have a x and y coordinate not visible to the screen.&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2020-01-02T16:29:49.687" Title="Understanding the near clipping plane" Tags="&lt;3d&gt;&lt;projections&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9458" PostTypeId="2" ParentId="9457" CreationDate="2020-01-02T16:29:49.687" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;When do they actually discard points that have a z component smaller than the near clipping plane?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;For actual rendering hardware, they don't. Clipping happens in clip space, before the NDC transform. &quot;Points&quot; outside of the clipping volume are never seen by the rasterizer (in theory, at least. In practice, guard-band clipping is often used to minimize the need for clipping against the sizes).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The renderer presented at that site doesn't appear to do clipping at all. It has an approximation of what &lt;em&gt;would&lt;/em&gt; be clipped, but it doesn't actually do the clipping. &lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-01-02T16:29:49.687" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9459" PostTypeId="1" AcceptedAnswerId="9485" CreationDate="2020-01-03T03:29:31.840" Score="0" ViewCount="98" Body="&lt;p&gt;I am a newbie in computer graphics and just started working on physically based rendering engines such as Mitsuba.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found it difficult to create my own scenes, that are xml files. To create one, there are three ways as I know so far:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Build a scene in &lt;a href=&quot;https://www.blender.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender&lt;/a&gt; and export it to a xml file using prasers, e.g. &lt;a href=&quot;https://www.mitsuba-renderer.org/plugins.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.mitsuba-renderer.org/plugins.html&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Download free xml scenes, e.g. from &lt;a href=&quot;https://benedikt-bitterli.me/resources/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://benedikt-bitterli.me/resources/&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Hand-write an xml scene with Python from scratch, e.g. this example &lt;a href=&quot;http://www.djmannion.net/psych_programming/vision/mitsuba/mitsuba.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.djmannion.net/psych_programming/vision/mitsuba/mitsuba.html&lt;/a&gt;. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;However, I am suffering from following issues:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;It takes long time for me to create a scene via 1 and 3, yet not customizable via 2.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I do not know where to get free meshes (and license issues?)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Questions&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Are there any better ways to create an xml scene?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;What is the canonical way to create delicate scenes, e.g. the ones in SIGGRAPH papers?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="6470" LastActivityDate="2020-02-11T02:00:42.133" Title="Standard ways to create xml scenes for research purposes" Tags="&lt;pbr&gt;&lt;scene-description&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9461" PostTypeId="1" CreationDate="2020-01-03T13:59:14.897" Score="1" ViewCount="114" Body="&lt;p&gt;I am working on a procedural placement system on the GPU, inspired by the work done by Guerrilla Games in Horizon Zero Dawn:&#xA;&lt;a href=&quot;https://www.guerrilla-games.com/read/gpu-based-procedural-placement-in-horizon-zero-dawn&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.guerrilla-games.com/read/gpu-based-procedural-placement-in-horizon-zero-dawn&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On slide 28 they are showing a sampling pattern, which they use to determine whether to place an object or not. The pattern consists of evenly distributed points, each with a threshold value, which they test a artist-authored density map against.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The threshold values are picked, such that they are evenly distributed and maximize the distance to neighboring sample points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have looked into circle packing on a unit square to generate the sampling points, and this seems fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The point I am having trouble with is how to create the threshold values with the specified requirement (even distribution between 0 and 1 and maximizing the distance to neighbors).&#xA;Can someone point me in the right direction, as to how to achieve this? Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="11679" LastActivityDate="2020-01-03T13:59:14.897" Title="GPU Procedural placement - Creating evenly distributed sampling points" Tags="&lt;mathematics&gt;&lt;sampling&gt;&lt;noise&gt;&lt;distribution&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9463" PostTypeId="1" CreationDate="2020-01-04T13:38:37.077" Score="0" ViewCount="66" Body="&lt;p&gt;I compute bounding box of a mesh:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;(xMin, xMax)&#xA;(yMin, yMax)&#xA;(zMin, zMax)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To get the bounding box, I need to go through all the mesh points and compute the min/max in X, Y and Z directions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aFosU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aFosU.png&quot; alt=&quot;Mesh not rotated&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then I rotate the mesh. To get the bounding box for the rotated mesh, I need to go through all the mesh points again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PrIUB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PrIUB.png&quot; alt=&quot;Mesh rotated&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a method to avoid going through all the mesh points &lt;strong&gt;again&lt;/strong&gt; when object is rotated?&lt;/p&gt;&#xA;" OwnerUserId="9169" LastActivityDate="2020-01-04T13:38:37.077" Title="Bounding box of a rotating mesh" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9464" PostTypeId="1" CreationDate="2020-01-04T16:16:26.547" Score="0" ViewCount="59" Body="&lt;p&gt;I have some photos of 3D cube. I also know the 3D pose of the cube in each photo (yaw, pitch, roll).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to estimate the new pose (yaw, pitch, roll) of the cube after performing 2D rotation to the photo (like 2D camera rotation).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't care its new position but the pose only.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, how can I calculate the new pose of 3D object after 2D rotation?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example:&lt;br&gt;&#xA;&lt;strong&gt;Original&lt;/strong&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/y8EFh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/y8EFh.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;After image rotation (-45 deg) - Yaw, Pitch &amp;amp; Roll are different&lt;/strong&gt; &#xA;&lt;a href=&quot;https://i.stack.imgur.com/FFhYq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FFhYq.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3305" LastEditorUserId="3305" LastEditDate="2020-01-05T20:57:13.860" LastActivityDate="2020-01-05T20:57:13.860" Title="Estimate 3D cube pose after camera rotation" Tags="&lt;3d&gt;&lt;transformations&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="9465" PostTypeId="1" CreationDate="2020-01-06T04:50:36.603" Score="0" ViewCount="159" Body="&lt;p&gt;I'm trying to write a raycaster similar to Voxlap, but it's many times slower. I've tried octrees, but the performance gains are marginal- only 10 to 20 percent. I use the algorithm from this site: &lt;a href=&quot;https://lodev.org/cgtutor/raycasting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://lodev.org/cgtutor/raycasting.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The full code: &lt;a href=&quot;https://pastebin.com/kYs9zs7S&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pastebin.com/kYs9zs7S&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The raycasting loop:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;      float cameraX = x/HALFRESX -1;&#xA;&#xA;      for(int y = 0; y &amp;lt; RESY; y ++) { &#xA;&#xA;&#xA;        float cameraY = y/HALFRESY -1;//cam vec, -1 to 1&#xA;&#xA;&#xA;        struct Point3D rayd;&#xA;        rayd.z = dir.z + plane.z*cameraY;&#xA;        rayd.x = dir.x + plane.x*cameraX;&#xA;        rayd.y = dir.y + plane.y*cameraX;&#xA;&#xA;        struct Point3D delta;&#xA;        delta.y = fabsf(1/rayd.y);&#xA;        delta.x = fabsf(1/rayd.x);&#xA;        delta.z = fabsf(1/rayd.z);&#xA;&#xA;&#xA;        struct pos map;&#xA;        map.x = (char)pos.x;&#xA;        map.y = (char)pos.y;&#xA;        map.z = (char)pos.z; &#xA;&#xA;        struct pos s;&#xA;        struct pos step;&#xA;        struct Point3D sdist;&#xA;        if(rayd.x &amp;lt; 0) {&#xA;          step.x = -1;&#xA;          s.x = 1;&#xA;          sdist.x = (pos.x - map.x) * delta.x; &#xA;        }&#xA;        else {&#xA;          step.x = 1;&#xA;          s.x = 0;&#xA;          sdist.x = (map.x + 1 - pos.x) * delta.x; &#xA;        }&#xA;        if(rayd.y &amp;lt; 0) {&#xA;          step.y = -1;&#xA;          s.y = 1;&#xA;          sdist.y = (pos.y - map.y) * delta.y; &#xA;        }&#xA;        else {&#xA;          step.y = 1;&#xA;          s.y = 0;&#xA;          sdist.y = (map.y + 1 - pos.y) * delta.y; &#xA;        }&#xA;&#xA;        if(rayd.z &amp;lt; 0) {&#xA;          step.z = -1;&#xA;          s.z = 1;&#xA;          sdist.z = (pos.z - map.z) * delta.z; &#xA;        }&#xA;        else {&#xA;          step.z = 1;&#xA;          s.z = 0;&#xA;          sdist.z = (map.z + 1 - pos.z) * delta.z; &#xA;        }&#xA;&#xA;&#xA;&#xA;        char side; //either 0 (NS), or 1 (EW), or 2(UD)&#xA;        while( !MAP[map.x][map.y][map.z]) {&#xA;          if(sdist.y &amp;lt; sdist.x ) {&#xA;            if(sdist.y &amp;lt; sdist.z) {&#xA;              sdist.y += delta.y;&#xA;              map.y += step.y;&#xA;              side = 1; // y&#xA;            }&#xA;            else {&#xA;              sdist.z += delta.z;&#xA;              map.z += step.z;&#xA;              side = 2; &#xA;            }&#xA;          }&#xA;          else {&#xA;            if(sdist.x &amp;lt; sdist.z) {&#xA;              sdist.x += delta.x;&#xA;              map.x += step.x;&#xA;              side = 0; &#xA;            }&#xA;            else {&#xA;              sdist.z += delta.z;&#xA;              map.z += step.z; &#xA;              side = 2; &#xA;            }&#xA;          }&#xA;        }&#xA;        char blockHit = MAP[map.x][map.y][map.z];&#xA;&#xA;&#xA;#ifdef USE_REFLECTIONS&#xA;        bool reflect = false;&#xA;reflect:;&#xA;        if(blockHit == 6){&#xA;          reflect = true;&#xA;          if(!side) {&#xA;            step.x*=-1;&#xA;            sdist.x += delta.x;&#xA;            map.x += step.x;&#xA;            rayd.x*=-1;&#xA;          }&#xA;          else if(side == 1) {&#xA;            step.y*=-1;&#xA;            sdist.y += delta.y;&#xA;            map.y += step.y;&#xA;            rayd.y*=-1;&#xA;          }&#xA;          else {&#xA;            step.z*=-1;&#xA;            sdist.z += delta.z;&#xA;            map.z += step.z;&#xA;            rayd.z*=-1;&#xA;          }&#xA;&#xA;          while( !MAP[map.x][map.y][map.z]) {&#xA;            if(sdist.y &amp;lt; sdist.x ) {&#xA;              if(sdist.y &amp;lt; sdist.z) {&#xA;                sdist.y += delta.y;&#xA;                map.y += step.y;&#xA;                side = 1; // y&#xA;              }&#xA;              else {&#xA;                sdist.z += delta.z;&#xA;                map.z += step.z;&#xA;                side = 2; &#xA;              }&#xA;            }&#xA;            else {&#xA;              if(sdist.x &amp;lt; sdist.z) {&#xA;                sdist.x += delta.x;&#xA;                map.x += step.x;&#xA;                side = 0; &#xA;              }&#xA;              else {&#xA;                sdist.z += delta.z;&#xA;                map.z += step.z; &#xA;                side = 2; &#xA;              }&#xA;            }&#xA;          }&#xA;&#xA;        blockHit = MAP[map.x][map.y][map.z];&#xA;        }&#xA;#endif&#xA;        struct Point3D lightDist;&#xA;        struct Point3D hit;&#xA;&#xA;        if(!side) {  // x side hit&#xA;&#xA;          hit.x = map.x + s.x;&#xA;          float relativeHit = hit.x-pos.x;&#xA;          hit.y = pos.y + relativeHit/rayd.x*rayd.y;&#xA;          hit.z = pos.z + relativeHit/rayd.x*rayd.z;&#xA;&#xA;        }&#xA;        else if(side == 1) {  // y side hit&#xA;&#xA;          hit.y = map.y + s.y;&#xA;          float relativeHit = hit.y-pos.y;&#xA;          hit.x = pos.x + relativeHit/rayd.y*rayd.x;&#xA;          hit.z = pos.z + relativeHit/rayd.y*rayd.z;&#xA;&#xA;        }&#xA;        else {  // z side hit&#xA;&#xA;          hit.z = map.z + s.z;&#xA;          float relativeHit = hit.z-pos.z;&#xA;          hit.x = pos.x + relativeHit/rayd.z*rayd.x;&#xA;          hit.y = pos.y + relativeHit/rayd.z*rayd.y;&#xA;        }&#xA;        lightDist.x = light[0][0] - hit.x;  // x&#xA;        lightDist.y = light[0][1] - hit.y;  // y&#xA;        lightDist.z = light[0][2] - hit.z;  // z&#xA;&#xA;        double lightdist = sqrt(lightDist.x*lightDist.x + lightDist.y*lightDist.y + lightDist.z*lightDist.z);&#xA;        if(lightdist &amp;gt; 32) {voxelColour = 32;}&#xA;        else if(lightdist &amp;gt; 4)  voxelColour = 1024/lightdist;&#xA;        else voxelColour = 255;&#xA;&#xA;&#xA;&#xA;#ifdef USE_REFLECTIONS&#xA;        if(reflect) voxelColour/=1.2;&#xA;#endif&#xA;&#xA;        void drawPixel( Uint32 colour) {&#xA;          pixels[y][x] = colour;&#xA;        }&#xA;&#xA;        if(blockHit &amp;lt;3) drawPixel(0x010101*voxelColour);&#xA;        else if(blockHit == 3) drawPixel(voxelColour);&#xA;        else if(blockHit == 4) drawPixel(0x10000*voxelColour);&#xA;#ifdef USE_REFLECTIONS&#xA;        else if(blockHit == 6) goto reflect;&#xA;#endif&#xA;        else drawPixel(0x100*voxelColour);&#xA;&#xA;      }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11609" LastActivityDate="2020-01-13T09:12:30.977" Title="Why is my raycaster so slow?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;optimization&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9466" PostTypeId="2" ParentId="9465" CreationDate="2020-01-06T09:28:40.417" Score="2" Body="&lt;p&gt;&lt;em&gt;Disclaimer: I've only skimmed through the code.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To be honest, the best thing to do would be to &lt;strong&gt;use a  profiler on your code&lt;/strong&gt; to identify what actually is costing CPU cycles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said that, some operations are more expensive than others - e.g. floating point division and sqrt OR, potentially far more detrimental to performance, cache misses.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;WRT to the former, for example, in...&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; double lightdist = sqrt(lightDist.x*lightDist.x + lightDist.y*lightDist.y + lightDist.z*lightDist.z);&#xA;        if(lightdist &amp;gt; 32) {voxelColour = 32;}&#xA;        else if(lightdist &amp;gt; 4)  voxelColour = 1024/lightdist;&#xA;        else voxelColour = 255;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;...it doesn't look to me like you always need to compute the sqrt in two of the branches. Perhaps instead, just keep the square of the distance and compare against SQ(32), SQ(4) etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;BTW: the following looks a little 'odd'&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;        rayd.z = dir.z + plane.z*cameraY;&#xA;        rayd.x = dir.x + plane.x*cameraX;&#xA;        rayd.y = dir.y + plane.y*cameraX;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Do you really intend to use cameraX twice? I've not really thought about it but it just looks suspicious.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-01-13T09:12:30.977" LastActivityDate="2020-01-13T09:12:30.977" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9470" PostTypeId="2" ParentId="8111" CreationDate="2020-01-07T03:55:38.967" Score="1" Body="&lt;p&gt;The new C interface for &lt;code&gt;glslang&lt;/code&gt; is coming.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glslang/pull/2038&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KhronosGroup/glslang/pull/2038&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a way how to use it:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const char* shaderCodeVertex = ...;&#xA;&#xA;const glslang_input_t input =&#xA;{&#xA;    .language = GLSLANG_SOURCE_GLSL,&#xA;    .stage = GLSLANG_STAGE_VERTEX,&#xA;    .client = GLSLANG_CLIENT_VULKAN,&#xA;    .client_version = GLSLANG_TARGET_VULKAN_1_1,&#xA;    .target_language = GLSLANG_TARGET_SPV,&#xA;    .target_language_version = GLSLANG_TARGET_SPV_1_3,&#xA;    .code = shaderCodeVertex,&#xA;    .default_version = 100,&#xA;    .default_profile = GLSLANG_NO_PROFILE,&#xA;    .force_default_version_and_profile = false,&#xA;    .forward_compatible = false,&#xA;    .messages = GLSLANG_MSG_DEFAULT_BIT,&#xA;};&#xA;&#xA;glslang_initialize_process();&#xA;&#xA;glslang_shader_t* shader = glslang_shader_create( &amp;amp;input );&#xA;&#xA;if ( !glslang_shader_preprocess(shader, &amp;amp;input) )&#xA;{&#xA;    // use glslang_shader_get_info_log() and glslang_shader_get_info_debug_log()&#xA;}&#xA;&#xA;if ( !glslang_shader_parse(shader, &amp;amp;input) )&#xA;{&#xA;    // use glslang_shader_get_info_log() and glslang_shader_get_info_debug_log()&#xA;}&#xA;&#xA;glslang_program_t* program = glslang_program_create();&#xA;glslang_program_add_shader( program, shader );&#xA;&#xA;if (!glslang_program_link(program, GLSLANG_MSG_SPV_RULES_BIT | GLSLANG_MSG_VULKAN_RULES_BIT))&#xA;{&#xA;    // use glslang_program_get_info_log() and glslang_program_get_info_debug_log();&#xA;}&#xA;&#xA;glslang_program_SPIRV_generate( program, input.stage );&#xA;&#xA;if ( glslang_program_SPIRV_get_messages(program) )&#xA;{&#xA;    printf(&quot;%s&quot;, glslang_program_SPIRV_get_messages(program));&#xA;}&#xA;&#xA;glslang_shader_delete( shader );&#xA;&#xA;const VkShaderModuleCreateInfo ci =&#xA;{&#xA;    .sType    = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,&#xA;    .codeSize = glslang_program_SPIRV_get_size(program) * sizeof(unsigned int),&#xA;    .pCode    = glslang_program_SPIRV_get_ptr(program)&#xA;};&#xA;&#xA;VkResult result = vkCreateShaderModule(device, &amp;amp;ci, nullptr, ...);&#xA;&#xA;glslang_program_delete( program );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="32" LastActivityDate="2020-01-07T03:55:38.967" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9471" PostTypeId="2" ParentId="8993" CreationDate="2020-01-07T05:20:49.280" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Is it reasonable to expect the image of the described scene to be &quot;in grayscale&quot;? If so, do light intensity spectra indeed are required to be multiplied by D65 spectrum? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;My expectation from a physically-based spectral rendered is that it would&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;compute the physical spectra&lt;/li&gt;&#xA;&lt;li&gt;use the CIE color matching functions to relate that to a quantified color space (eg CIEXYZ)&lt;/li&gt;&#xA;&lt;li&gt;convert that into the destination color space.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;D65 shall not appear anywhere till step 3, and only if we actually render into sRGB (or similar).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A flat spectra translates to &lt;code&gt;XYZ = (0.33, 0.33, 0.33)&lt;/code&gt;, which is &lt;code&gt;RGB = (1.20, 0.95, 0.91)&lt;/code&gt; prior to gamma compression. So the &quot;red tint&quot; is the expected result following the above procedure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't know why Mitsuba would have such a 'feature'.&lt;/p&gt;&#xA;" OwnerUserId="7057" LastActivityDate="2020-01-07T05:20:49.280" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9472" PostTypeId="1" AcceptedAnswerId="9473" CreationDate="2020-01-07T08:35:28.917" Score="4" ViewCount="125" Body="&lt;p&gt;I'm looking for a format where I could store a triangle mesh and multiple textures into a single file. Most formats only reference an external file for textures. I found that the FBX format should support this, but I need something with an open-source C++ library. And by single file I don't mean putting it into a single archive, I don't want users to have to deal with that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't need anything fancy, no animation, no shading, nothing. Just triangles + textures. Ideally this would be a binary format (or at least the textures would be stored in binary inside the file). This should be some well supported format, so that tools exist to open it. I'm currently looking at X3D but I can't figure out if it can include the textures directly.&lt;/p&gt;&#xA;" OwnerUserId="11696" LastActivityDate="2020-01-07T11:12:53.437" Title="Saving a mesh and textures into a single file" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9473" PostTypeId="2" ParentId="9472" CreationDate="2020-01-07T11:12:53.437" Score="3" Body="&lt;p&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF/blob/master/README.md&quot; rel=&quot;nofollow noreferrer&quot;&gt;glTF&lt;/a&gt; is capable if embedding both geometry and texture data in a single file. It also has binary version (*.glb). There are several open-source savers/loaders, one of them being header-only &lt;a href=&quot;https://github.com/syoyo/tinygltf&quot; rel=&quot;nofollow noreferrer&quot;&gt;tinygltf&lt;/a&gt; by Syoyo Fujita.&lt;/p&gt;&#xA;" OwnerUserId="2479" LastActivityDate="2020-01-07T11:12:53.437" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9474" PostTypeId="1" CreationDate="2020-01-07T12:19:42.683" Score="1" ViewCount="60" Body="&lt;p&gt;In the Multiplexed Metropolis Light Transport implementation of the book &lt;em&gt;Physically Based Rendering&lt;/em&gt;, the proposal samples are generated by the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html#PrimarySampleSpaceSampler&quot; rel=&quot;nofollow noreferrer&quot;&gt;Primary Sample Space Sampler&lt;/a&gt; &lt;code&gt;MLTSampler&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not sure if I really understand what the authors mean in the following paragraph:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In the context of MLT, the resulting sequence of sample requests creates a mapping between components &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; of and vertices on the camera or light subpath. With the process described above, the components &lt;span class=&quot;math-container&quot;&gt;$X_0,\ldots,X_n$&lt;/span&gt; determine the camera subpath (for some &lt;span class=&quot;math-container&quot;&gt;$n\in\mathbb N_0$&lt;/span&gt;), and the remaining values &lt;span class=&quot;math-container&quot;&gt;$X_{n+1},\ldots,X_m$&lt;/span&gt; determine the light subpath. If the camera subpath requires a different number of samples after a perturbation (e.g., because the random walk produced fewer vertices), then there is a shift in the assignment of primary sample space components to the light subpath. This leads to an unintended large-scale modification to the light path.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Does this mean that even for a fixed strategy with &lt;span class=&quot;math-container&quot;&gt;$n\in\mathbb N_0$&lt;/span&gt; vertices on the camera subpath, the number of random numbers needed to generate such a subpath may vary? Or do they mean that the shift in the assignment is happening only when we switch to an other strategy?&lt;/p&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2020-01-07T16:26:45.430" Title="In bidirectional path tracing, is a camera subpath with $n$ vertices determined by a fixed number of random numbers?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9475" PostTypeId="1" CreationDate="2020-01-07T14:07:53.597" Score="1" ViewCount="229" Body="&lt;p&gt;I'm trying to implement an hybrid renderer based on Vulkan extension VK_NV_ray_tracing. Basically, the rasterizer compute the albedo and depth map of the scene. Then I try to compute the distance from the depth buffer so that I can send a shadow ray from a raygen program to compute direct lighting. I linearize the depth to obtain a correct distance value from the depth buffer. What I am doing is this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const vec2 texcoord = vec2(gl_LaunchIDNV) / vec2(gl_LaunchSizeNV);&#xA;const double z_b = texture(depthBuffer, texcoord).x;&#xA;const double depth = (2.0 * near * far) / (far + near - z_b * (far - near));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I am then computing the ray position and direction&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const vec2 pixelCenter = vec2(gl_LaunchIDNV.xy) + vec2(0.5);&#xA;const vec2 inUV = pixelCenter / vec2(gl_LaunchSizeNV.xy);&#xA;const vec2 d = inUV * 2.0 - 1.0;&#xA;const vec4 camFront  = cam.viewInverse * vec4(0, 0, 1, 0);&#xA;const vec4 camPos    = cam.viewInverse * vec4(0, 0, 0, 1);&#xA;const vec4 camTarget = cam.projInverse * vec4(d.x, d.y, 1, 1);&#xA;const vec4 camDir    = cam.viewInverse * vec4(normalize(camTarget.xyz), 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the final ray position is then set using the depth I just computed.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const vec3 pos = camPos.xyz + camDir.xyz * float(depth);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The problem here is that the depth seems incorrect because shadows tend to curve at the edges of the screen and do not fit the geometry. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/CgIwK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CgIwK.png&quot; alt=&quot;bended shadows&quot;&gt;&lt;/a&gt;&#xA;I think this might be because of the depth buffer value that does not represent the distance from the origin of the camera but from the near plane, which would explain the problem, but I am not sure of that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any idea?&lt;/p&gt;&#xA;" OwnerUserId="11699" LastEditorUserId="6" LastEditDate="2020-01-08T18:47:34.337" LastActivityDate="2020-02-12T09:02:30.323" Title="Retrieve real distance from depth buffer for shadow ray (vulkan hybrid rendering)" Tags="&lt;raytracing&gt;&lt;glsl&gt;&lt;vulkan&gt;&lt;shadow&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9476" PostTypeId="2" ParentId="9474" CreationDate="2020-01-07T16:03:04.170" Score="2" Body="&lt;p&gt;For a fixed strategy, you can end up consuming a different number of samples depending on your mutation. This can happen for at least two reasons. If your perturbation changes some material along the path to, say, a multi-lobe BSDF, you would need more samples to account for the lobe choice. This would shift everything by the number of extra samples used. If your ray eventually escapes the scene as you are tracing your mutation, or it hits a light source prematurely, you would use fewer samples. In these cases, you'd have to reject this proposal automatically.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One way of mitigating this issue in practice is to separate the two random number vectors for the camera and light subpaths and always mutate &lt;em&gt;all&lt;/em&gt; dimensions of the unit hypercube &lt;span class=&quot;math-container&quot;&gt;$\mathcal{U}^{o(k)}$&lt;/span&gt;, regardless if they are being used or not by the mutation. This doesn't remove the shift caused by BSDF changes (which is unavoidable) but at least you're not spilling your samples between camera and light subpaths.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that changing the strategy can also lead to an undesired rippling effect as primary samples will be used to perform a slightly different task (i.e. tracing a different strategy). This can be handled by introducing inverse mappings to preserve the geometry of the path, which is what is done by &lt;a href=&quot;https://dl.acm.org/doi/10.1145/3132704&quot; rel=&quot;nofollow noreferrer&quot;&gt;Reversible Jump MLT&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastEditorUserId="6588" LastEditDate="2020-01-07T16:26:45.430" LastActivityDate="2020-01-07T16:26:45.430" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9478" PostTypeId="2" ParentId="9448" CreationDate="2020-01-08T18:57:29.487" Score="1" Body="&lt;p&gt;A literal triangle, as in 3 vertices connected by 3 edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They are the basic building block for any other shape, any polygon can be represented with a set of triangles (called triangulation).&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-01-08T18:57:29.487" CommentCount="22" ContentLicense="CC BY-SA 4.0" />
  <row Id="9479" PostTypeId="2" ParentId="9465" CreationDate="2020-01-09T10:51:40.013" Score="2" Body="&lt;p&gt;You have a lot of if condition affecting different components of various &lt;code&gt;Point3D&lt;/code&gt;. If conditions, especially hard to predict ones are very expensive, instead look into using SIMD to remove most of the conditions by replacing the false branches with identity operations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;for example      &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  if(!side) {&#xA;    step.x*=-1;&#xA;    sdist.x += delta.x;&#xA;    map.x += step.x;&#xA;    rayd.x*=-1;&#xA;  }&#xA;  else if(side == 1) {&#xA;    step.y*=-1;&#xA;    sdist.y += delta.y;&#xA;    map.y += step.y;&#xA;    rayd.y*=-1;&#xA;  }&#xA;  else {&#xA;    step.z*=-1;&#xA;    sdist.z += delta.z;&#xA;    map.z += step.z;&#xA;    rayd.z*=-1;&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;can be replaced with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;step = simd_xor(step, negateTable[side]); //negate can be done by xoring the sign bit&#xA;sdist = simd_add(sdist, simd_and(delta, addMask[side]));&#xA;map = simd_add(map, simd_and(step, addMask[side]));&#xA;rayd= simd_xor(step, negateTable[side]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="137" LastActivityDate="2020-01-09T10:51:40.013" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9480" PostTypeId="2" ParentId="9448" CreationDate="2020-01-09T15:12:03.967" Score="1" Body="&lt;p&gt;To expand on @Makogan and @lightxbulb's answers/comments: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are several reasons for using triangles as the basic primitive.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;(Non-degenerate) triangles are guaranteed to be &lt;em&gt;planar&lt;/em&gt;. This means that an individual single triangle cannot obscure itself (in terms of hidden surface removal) and thus cannot  form an internal silhouette edge (when being rendered)  nor, say, cast a shadow on itself.&lt;br/&gt;&lt;br/&gt;&#xA;This is also means that when scan converting a triangle, for each pixel, each attribute (e.g. depth, texture coordinate, shading) can only take a 'single' value.&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;They are guaranteed to be convex. Scan converting/filling convex polygons is &lt;em&gt;far&lt;/em&gt; simpler than a general polygon filling algorithm&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;An arbitrary polygonal mesh can always be &lt;em&gt;easily&lt;/em&gt; decomposed into triangles&lt;br/&gt;&#xA;[&lt;strong&gt;Update&lt;/strong&gt;: As @joojaa pointed out, you could still use quads by either&lt;br/&gt;&#xA;&lt;strong&gt;a)&lt;/strong&gt; Noting that any triangle can be represented as 3 quads by the addition of four more vertices - one at the centre of the triangle and one on each edge). You need to be careful, though, not to &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1464/209&quot;&gt;introduce T-Junctions&lt;/a&gt;. &lt;em&gt;or&lt;/em&gt;&lt;br/&gt;&#xA;&lt;strong&gt;b)&lt;/strong&gt; Using a degenerate quad to create a triangle - i.e. either collapse an edge by repeating a vertex &lt;em&gt;or&lt;/em&gt; (but this may have other problems due to precision) making 3 of the vertices collinear&#xA;Neither seems, to me at least, as particularly attractive].&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;If you are concerned about the 'cost' in vertices of supplying two triangles to represent your quad, remember that APIs (and HW) have triangle strips/fans/indexed representations which will, in most cases, eliminate the additional vertex overheads.&#xA;There is thus little point in adding additional hardware to support 'fast' quad rendering as (a) it wouldn't get used much and (b) is extremely unlikely to be the bottleneck in rendering!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said all this, the &lt;em&gt;original&lt;/em&gt; Series 1 PowerVR graphics chips (eg PCX1 and PCX2) used a lower-level primitive (the half plane) from which N-sided convex polygons (&lt;em&gt;or in fact N-sided polyhedra - e.g an entire cube was, at most, 6 half-planes&lt;/em&gt;) could be constructed. IIRC the driver tried to detect if two consecutive triangles actually formed a planar quad and then replaced them with a more efficient representation. Further, for a quad to be &quot;planar&quot;, not only did it need to be geometrically flat but the texture coordinates also had to be 'flat'. &lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-02-11T09:19:23.940" LastActivityDate="2020-02-11T09:19:23.940" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9481" PostTypeId="1" CreationDate="2020-01-09T20:53:47.880" Score="1" ViewCount="113" Body="&lt;p&gt;I am interested in Path Tracing, I currently follow the Ray Tracing in a weekend book. When implementing the metal material, I get a strange artifact on the edge of the sphere that does not appear in the book's result. I might be caused by the fuzz parameter, when it's set to zero, it does not occur.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wrote my code in Rust&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Screenshots:&lt;br&gt;&#xA;Fuzziness set to 0.0&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HC5l2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HC5l2.png&quot; alt=&quot;Fuzziness set to 0.0&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Fuzziness set to 0.5&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/zpF2k.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zpF2k.png&quot; alt=&quot;Fuzziness set to 0.5&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see there is a white outline-like artifact at the edge of the sphere.&lt;br&gt;&#xA;I am not sure what causes that...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The full code is available here: &lt;a href=&quot;https://github.com/AregevDev/pathtracer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/AregevDev/pathtracer&lt;/a&gt;&lt;br&gt;&#xA;Some highlights:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My random point function&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-rust prettyprint-override&quot;&gt;&lt;code&gt;fn random_double() -&amp;gt; f64 {&#xA;    let mut rnd = rand::thread_rng();&#xA;    rnd.gen::&amp;lt;f64&amp;gt;()&#xA;}&#xA;&#xA;// Generate a random point in the unit sphere&#xA;fn random_in_unit_sphere() -&amp;gt; Vector3 {&#xA;    loop {&#xA;        let p =&#xA;            2.0 * Vector3::new(&#xA;                random_double() as f32,&#xA;                random_double() as f32,&#xA;                random_double() as f32,&#xA;            ) - Vector3::new(1.0, 1.0, 1.0);&#xA;        if p.squared_length() &amp;lt;= 1.0 {&#xA;            return p;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My material scatter function, I match the material type and calculate the rays accordingly:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-rust prettyprint-override&quot;&gt;&lt;code&gt;pub fn scatter(&amp;amp;self, ray_in: Ray, record: &amp;amp;HitRecord) -&amp;gt; Option&amp;lt;Scatter&amp;gt; {&#xA;        match *self {&#xA;            Material::Lambertian { albedo } =&amp;gt; {&#xA;                let mut scattered = Scatter::default();&#xA;                let target = record.p + record.normal + random_in_unit_sphere();&#xA;&#xA;                scattered.color = albedo;&#xA;                scattered.ray = Some(Ray::new(record.p, target - record.p));&#xA;&#xA;                Some(scattered)&#xA;            }&#xA;            Material::Metal { albedo, fuzz } =&amp;gt; {&#xA;                let mut scattered = Scatter::default();&#xA;                let reflected = ray_in.direction.normalize().reflect(record.normal);&#xA;                let new_fuzz = fuzz.min(1.0);&#xA;&#xA;                scattered.color = albedo;&#xA;                scattered.ray = Some(Ray::new(&#xA;                    record.p,&#xA;                    reflected + new_fuzz * random_in_unit_sphere(),&#xA;                ));&#xA;&#xA;                if scattered.ray.unwrap().direction.dot(record.normal) &amp;gt; 0.0 {&#xA;                    Some(scattered)&#xA;                } else {&#xA;                    None&#xA;                }&#xA;            }&#xA;            _ =&amp;gt; None,&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="11709" LastEditorUserId="4958" LastEditDate="2020-01-10T16:24:56.773" LastActivityDate="2020-01-10T16:24:56.773" Title="Ray Tracing -Weird Edge Artifact" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9485" PostTypeId="2" ParentId="9459" CreationDate="2020-01-12T01:11:21.533" Score="0" Body="&lt;p&gt;(In case someone encounters similar issue)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I end-up in Way 1, and it seems the standard way in academia.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once I am familar with Blender, the scene creation becomes less challenging; still, it takes some time to create a simple scene. Fortunately for academic papers the number of scenes are a few (&amp;lt; 10).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately the old Mitsuba parser does not work for the latest Blender version. So I wrote a custom 2.8x Blender add-on for Mitsuba, as well as creating new, custom material nodes for my own renderer.&lt;/p&gt;&#xA;" OwnerUserId="6470" LastActivityDate="2020-01-12T01:11:21.533" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9487" PostTypeId="2" ParentId="9048" CreationDate="2020-01-12T21:31:16.000" Score="0" Body="&lt;p&gt;Build a hexahedron from 6 triangles(!), setting its 2 vertices at the poles of the sphere, and the other 3 vertices equally around the equator. Then iteratively or recursively subdivide all triangles, projecting the new vertices at the sphere surface (!). Triangle subdivision can be done by replacing an original triangle by 4 new ones, adding new vertices in the middle of all 3 edges and in the middle of the original triangle.&lt;/p&gt;&#xA;" OwnerUserId="8314" LastActivityDate="2020-01-12T21:31:16.000" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9489" PostTypeId="2" ParentId="9475" CreationDate="2020-01-13T09:00:10.583" Score="1" Body="&lt;p&gt;Thanks for your help, I fixed it by changing the way i am computing the depth :)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const double z_b = texture(depthBuffer, texcoord).x;&#xA;const vec4 clipSpacePosition = vec4(texcoord * 2.0 - 1.0, z_b, 1.0);&#xA;vec4 viewSpacePosition = cam.projInverse * clipSpacePosition;&#xA;viewSpacePosition /= viewSpacePosition.w;&#xA;float depth = length(viewSpacePosition.xyz);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11699" LastActivityDate="2020-01-13T09:00:10.583" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9490" PostTypeId="1" CreationDate="2020-01-13T11:05:03.000" Score="2" ViewCount="48" Body="&lt;p&gt;&lt;strong&gt;I've got a hard time to understand how we would implement the following in practice. I'd be great if someone could explain the details for the example below.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Assume we're generating a path &lt;span class=&quot;math-container&quot;&gt;${\rm x}=(\rm x_0,\rm x_1,\rm x_2)$&lt;/span&gt; of length &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt; using the &lt;span class=&quot;math-container&quot;&gt;$(s,t)$&lt;/span&gt;-strategy in bidirectional path tracing (see picture below). Assume that there is no participating media in the scene and we're using a pinhole camera.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now assume &lt;span class=&quot;math-container&quot;&gt;$s=0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t=3$&lt;/span&gt;. Since we're using a pinhole camera, &lt;span class=&quot;math-container&quot;&gt;$\rm x_0$&lt;/span&gt; is deterministically  fixed at the eye. A raster point is determined by drawing random numbers &lt;span class=&quot;math-container&quot;&gt;$u_1,u_2\in(0,1)$&lt;/span&gt; and mapping them uniformly to the raster space. The raster point determines a ray &lt;span class=&quot;math-container&quot;&gt;$r_1=(\rm x_0,\omega_1)$&lt;/span&gt; with origin &lt;span class=&quot;math-container&quot;&gt;$\rm x_0$&lt;/span&gt; and direction &lt;span class=&quot;math-container&quot;&gt;$\omega_1$&lt;/span&gt;. Assume that &lt;span class=&quot;math-container&quot;&gt;$r_1$&lt;/span&gt; hits a surface point &lt;span class=&quot;math-container&quot;&gt;${\rm x_1}$&lt;/span&gt;. Now another pair of random numbers &lt;span class=&quot;math-container&quot;&gt;$u_3,u_4\in(0,1)$&lt;/span&gt; are drawn and mapped to a direction &lt;span class=&quot;math-container&quot;&gt;$\omega_2$&lt;/span&gt; by the&lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt; bidirectional scattering distribution function at &lt;span class=&quot;math-container&quot;&gt;$\rm x_1$&lt;/span&gt; and thereby giving rise to the next ray &lt;span class=&quot;math-container&quot;&gt;$r_2=(\rm x_1,\omega_2)$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$r_2$&lt;/span&gt; might either hit another point &lt;span class=&quot;math-container&quot;&gt;$\rm x_2$&lt;/span&gt; (located on a surface or a light source) or escape the scene. In the last case, we assume that &lt;span class=&quot;math-container&quot;&gt;$\rm x_2$&lt;/span&gt; is located on an infinite light.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In summary, we've used the random numbers &lt;span class=&quot;math-container&quot;&gt;$u_1,u_2,u_3,u_4$&lt;/span&gt; to sample &lt;span class=&quot;math-container&quot;&gt;$\rm x=(\rm x_0,\rm x_1,\rm x_2)$&lt;/span&gt;. Now assume we're switching to the strategy. How can we determine random numbers &lt;span class=&quot;math-container&quot;&gt;$v_1,v_2,\ldots$&lt;/span&gt; which would have produced the same path &lt;span class=&quot;math-container&quot;&gt;$\rm x$&lt;/span&gt; under the &lt;span class=&quot;math-container&quot;&gt;$(1,2)$&lt;/span&gt;-strategy?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;We should clearly be able to reuse &lt;span class=&quot;math-container&quot;&gt;$u_1,u_2$&lt;/span&gt;, since &lt;span class=&quot;math-container&quot;&gt;$(\rm x_0,\rm x_1)$&lt;/span&gt; is still part of the truncated camera subpath of the &lt;span class=&quot;math-container&quot;&gt;$(1,2)$&lt;/span&gt;-strategy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The abstract process is described in Section 6.1 of the paper &lt;a href=&quot;https://arxiv.org/pdf/1612.05395.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Charted Metropolis Light Transport&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gmQlI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gmQlI.png&quot; alt=&quot;(s,t)-strategy&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt; It might actually be a composition of multiple BSDFs and &lt;span class=&quot;math-container&quot;&gt;$u_3$&lt;/span&gt; is used to select one of it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: I'm actually trying to implement this in &lt;a href=&quot;https://www.pbrt.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBRT&lt;/a&gt;. So, if necessary, feel free to assume that each BSDF has only a single component and that this component is of type &lt;code&gt;(pbrt::BSDF_REFLECTION | pbrt::BSDF_DIFFUSE)&lt;/code&gt;. Thus, you can assume that there is a single Lambertian BSDF at each surface point.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2020-01-15T15:51:19.213" LastActivityDate="2020-01-15T15:51:29.637" Title="Chart swaps and path inversion in bidirectional path tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;physically-based&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9492" PostTypeId="1" CreationDate="2020-01-14T06:43:24.213" Score="1" ViewCount="285" Body="&lt;p&gt;I was going through the camera matrix explained in the &lt;a href=&quot;https://en.wikipedia.org/wiki/Camera_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt; article and understand how the matrix &lt;strong&gt;K&lt;/strong&gt; &lt;span class=&quot;math-container&quot;&gt;\begin{bmatrix}f_x&amp;amp;s&amp;amp;x_0\\0&amp;amp;f_y&amp;amp;y_0\\0&amp;amp;0&amp;amp;1\end{bmatrix}&lt;/span&gt; is &lt;a href=&quot;http://ksimek.github.io/2013/08/13/intrinsic/&quot; rel=&quot;nofollow noreferrer&quot;&gt;built&lt;/a&gt;. The projection matrix is then essentially &lt;code&gt;K * [R | T]&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I am not able to understand what the &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/6254/how-to-derive-a-perspective-projection-matrix-from-its-components&quot;&gt;perspective projection&lt;/a&gt; matrix is and how is it same to the intrinsic matrix &lt;strong&gt;K&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="11735" LastEditorUserId="11735" LastEditDate="2020-01-14T08:10:54.780" LastActivityDate="2020-01-14T08:10:54.780" Title="Intrinsic Matrix vs Perspective projection matrix" Tags="&lt;3d&gt;&lt;projections&gt;&lt;camera-matrix&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9493" PostTypeId="1" CreationDate="2020-01-15T00:56:31.190" Score="1" ViewCount="71" Body="&lt;p&gt;I essentially know of 2 geometry processing data structures. one is the half edge (which has some really nice properties, but can't represent non manifold meshes nor tet meshes).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other is an extended adjacency list representation of the graph connectivity that also stores faces and edges.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there more?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-01-15T00:56:31.190" Title="What other geometry processing data structures are there?" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;data-structure&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9494" PostTypeId="1" CreationDate="2020-01-15T04:35:47.330" Score="2" ViewCount="39" Body="&lt;p&gt;I am working on a Renderer that should do a Depth Prepass before rendering the desired geometry.&lt;br&gt;&#xA;For this I have a Vertex and Pixel Shader that outputs to the Depth Texture.&#xA;After that it should render the same geometry using different shaders with texture and such.&lt;br&gt;&#xA;My question is how should I organize the Data on CPU side (classes/structs)?&#xA;The &quot;Main&quot; Vertex Buffer Layout contains&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Position&#xA;Normal&#xA;TexCoord&#xA;Color&#xA;(BoneWeight)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The Depth Pass only needs &lt;code&gt;Position&lt;/code&gt;&#xA;Do I need to store two different Layouts and keep two different Vertex Buffers to reduce Bandwidth?&lt;/p&gt;&#xA;" OwnerUserId="11739" LastActivityDate="2020-01-15T04:35:47.330" Title="Multipass Rendering Vertex Buffer Organisation" Tags="&lt;directx11&gt;&lt;hlsl&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9496" PostTypeId="1" CreationDate="2020-01-16T13:29:54.773" Score="0" ViewCount="185" Body="&lt;p&gt;I have a geometric shape (assuming that is a rectangle). I want to rotate it about it geometric center by an angle of 45° and plot the result using matplotlib with an equal aspect ratio, I get something like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/iXe7B.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iXe7B.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However for some reason, I want to plot the result in a figure with a non-equal aspect, I am getting this result:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3V3VD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3V3VD.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see, the rotated shape is deformed (skewed). But the original shape seems to be scaled only in the y direction.&lt;/p&gt;&#xA;&lt;p&gt;I am trying to understand what kind of transformation is occuring to the orange shape from a linear algebra perspective: Is it a shear? a combination of scaling and shear (Affine transformation)? if not what kind of transformation is that?&lt;/p&gt;&#xA;&lt;p&gt;My goal is to identify the type of transformation, then finding it's inverse to get the following result:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yhn2Z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yhn2Z.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I appreciate any help.&lt;/p&gt;&#xA;" OwnerUserId="11748" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-03-16T11:01:25.240" Title="What kind of transformation when the aspect is changed for a rotated shape?" Tags="&lt;transformations&gt;&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9497" PostTypeId="2" ParentId="9496" CreationDate="2020-01-16T14:49:16.780" Score="0" Body="&lt;p&gt;The transformation is non-uniform scale - it does not preserve angles. The only reason the angles for the other shape were preserved was because the scaling was in the same direction as the edge. To get the result that you want, you either have to scale by the same amount in each direction, or just rescale the &quot;viewing window&quot; and not the shapes.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2020-01-16T14:49:16.780" CommentCount="12" ContentLicense="CC BY-SA 4.0" />
  <row Id="9498" PostTypeId="1" CreationDate="2020-01-16T20:27:13.953" Score="0" ViewCount="47" Body="&lt;p&gt;Suppose we are sampling camera rays of a perspective camera with a finite aperture. The &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Camera_Models/Projective_Camera_Models.html#TheThinLensModelandDepthofField&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBRT implementation&lt;/a&gt; of the sampling scheme looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Float PerspectiveCamera::GenerateRay(const CameraSample &amp;amp;sample,&#xA;                                     Ray *ray) const {&#xA;    ProfilePhase prof(Prof::GenerateCameraRay);&#xA;    // Compute raster and camera sample positions&#xA;    Point3f pFilm = Point3f(sample.pFilm.x, sample.pFilm.y, 0);&#xA;    Point3f pCamera = RasterToCamera(pFilm);&#xA;    *ray = Ray(Point3f(0, 0, 0), Normalize(Vector3f(pCamera)));&#xA;    // Modify ray for depth of field&#xA;    if (lensRadius &amp;gt; 0) {&#xA;        // Sample point on lens&#xA;        Point2f pLens = lensRadius * ConcentricSampleDisk(sample.pLens);&#xA;&#xA;        // Compute point on plane of focus&#xA;        Float ft = focalDistance / ray-&amp;gt;d.z;&#xA;        Point3f pFocus = (*ray)(ft);&#xA;&#xA;        // Update ray for effect of lens&#xA;        ray-&amp;gt;o = Point3f(pLens.x, pLens.y, 0);&#xA;        ray-&amp;gt;d = Normalize(pFocus - ray-&amp;gt;o);&#xA;    }&#xA;    ray-&amp;gt;time = Lerp(sample.time, shutterOpen, shutterClose);&#xA;    ray-&amp;gt;medium = medium;&#xA;    *ray = CameraToWorld(*ray);&#xA;    return 1;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$X_0\in M$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\Omega_1\in S^2$&lt;/span&gt; denote the sampled point on the camera and direction, respectively. The next surface point in a path tracer would be &lt;span class=&quot;math-container&quot;&gt;$$Y:=X+d_M(X,\Omega)\Omega,$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$$d_M(x,\omega):=\inf\left\{t&amp;gt;0:x+t\omega\in M\right\}\;\;\;\text{for }x\in M\text{ and }\omega\in S^2.$$&lt;/span&gt; What is the conditional distribution of &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; given &lt;span class=&quot;math-container&quot;&gt;$(X,\Omega)$&lt;/span&gt;?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;From page 303 in &lt;a href=&quot;http://graphics.stanford.edu/papers/veach_thesis/thesis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Veach's thesis&lt;/a&gt; the conditional distribution of &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; given &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; should have a density with respect to the projected solid angle kernel &lt;span class=&quot;math-container&quot;&gt;$$\sigma_M^\perp(x,B):=\int_B\sigma_{S^2}({\rm d}\omega)|\langle\nu_M(x),\omega\rangle|\;\;\;\text{for }(x,B)\in M\times\mathcal B(S^2).$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Formally, we assume that the lens is part of our scene geometry &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt;, which is assumed to be an oriented embedded &lt;span class=&quot;math-container&quot;&gt;$C^1$&lt;/span&gt;-submanifold of &lt;span class=&quot;math-container&quot;&gt;$\mathbb R^3$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\nu_M$&lt;/span&gt; denotes the outer normal field on &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\sigma_M$&lt;/span&gt; denotes the surface measure on &lt;span class=&quot;math-container&quot;&gt;$\mathcal B(M)$&lt;/span&gt;. Moreover, let &lt;span class=&quot;math-container&quot;&gt;$S^2$&lt;/span&gt; denote the unit &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt;-sphere, &lt;span class=&quot;math-container&quot;&gt;$$S^2(x):=\left\{y\in\mathbb R^3:|x-y|=1\right\}=x+S^2\;\;\;\text{for }x\in\mathbb R^3$$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$$\omega_{x\to y}:=\frac{y-x}{|y-x|}\in S^2\;\;\;\text{for }x,y\in\mathbb R^3\text{ with }x\ne y.$$&lt;/span&gt; For simplicity, assume that &lt;span class=&quot;math-container&quot;&gt;$$d_M(x,\omega):=\inf\left\{t&amp;gt;0:x+t\omega\in M\right\}&amp;lt;\infty\;\;\;\text{for all }x\in M\text{ and }\omega\in S^2\tag1$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2020-01-16T20:27:13.953" Title="Distribution of the first vertex on a camera subpath in bidirectional path tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;pbr&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9499" PostTypeId="1" AcceptedAnswerId="9500" CreationDate="2020-01-17T02:29:25.803" Score="1" ViewCount="182" Body="&lt;p&gt;Peter Shirely's &lt;em&gt;Ray Tracing in One Weekend&lt;/em&gt; presents the following function to calculate the color of a lambertian material (See chapter's 7 and 8):&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;bool lambertian::scatter(ray ray_in, hit_record rec, vec3&amp;amp; attenuation, ray &amp;amp;scattered) {&#xA;  vec3 target = rec.p + rec.normal + random_in_unit_sphere();&#xA;  scattered = ray(rec.p, target - rec.p);&#xA;  attenuation = this-&amp;gt;albedo;&#xA;  return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I've read through other material that mentions Lambert's Cosine Law when discussing diffuse materials. Why is the &lt;code&gt;cos&lt;/code&gt; term omitted from Peter Shirely's text? Is it canceled out somehow? My expectation is that the attenuation term should look something like:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;  attenuation = this-&amp;gt;albedo * dot(rec.normal, ray_in.direction);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11750" LastEditorUserId="11750" LastEditDate="2020-01-17T02:36:23.217" LastActivityDate="2020-01-17T04:47:50.137" Title="Confusion around Lambert's Cosine Law in Ray Tracing in One Weekend" Tags="&lt;raytracing&gt;&lt;mathematics&gt;&lt;diffuse&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9500" PostTypeId="2" ParentId="9499" CreationDate="2020-01-17T04:47:50.137" Score="2" Body="&lt;p&gt;It is cancelled out by the probability density function in the estimator. The pdf in their case is exactly: &lt;span class=&quot;math-container&quot;&gt;$\frac{\cos\theta}{\pi}$&lt;/span&gt;, which is in the denominator: &lt;code&gt;att = albedo * cos_theta / pdf = albedo * pi&lt;/code&gt;. They have absorbed pi in the albedo. Note that there's an update on github to the code, since &lt;code&gt;random_in_unit_sphere()&lt;/code&gt; actually generates a &lt;span class=&quot;math-container&quot;&gt;$\cos^3\theta$&lt;/span&gt; distribution, they fixed it to &lt;code&gt;random_on_unit_sphere()&lt;/code&gt; which generates a &lt;span class=&quot;math-container&quot;&gt;$\cos\theta$&lt;/span&gt; distribution. So technically you are working with a &lt;span class=&quot;math-container&quot;&gt;$\cos^2\theta$&lt;/span&gt; brdf here and not constant.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2020-01-17T04:47:50.137" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9501" PostTypeId="1" CreationDate="2020-01-18T21:15:59.553" Score="0" ViewCount="106" Body="&lt;p&gt;I'm working on improving an open source rasterization library called Gudni that I started a few years ago. It's source repository and the branch I'm currently working on are here: &#xA;&lt;a href=&quot;https://github.com/ianmbloom/gudni/tree/texturetransformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/ianmbloom/gudni/tree/texturetransformation&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to implement a function that maps a quadratic bezier curve onto another curve (see illustration below). This is important for the library because it will not only allow one to describe things like dotted lines as just a series of rectangles projected onto a bezier path, but the same mechanism can (hopefully) be used to make text that follows a path or to make arrowheads etc and many other useful things. Using unified operation to do all of these things will hopefully make the library really easy to use and make a lot of useful figures very easy to describe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I've run into a bit of an impasse and I'm looking for some help.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The function I need has this description:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given two quadratic bezier curves, a source and a target curve, transform the target curve such that the targets x-axis corresponds to the arc-distance along the source curve and the targets y-axis corresponds to the distance from the curve.&#xA;In other words given a point (x,y) in the target curves coordinate space find a point and a normal vector that is x units along the arc-length of the source curve then take that point and add it to the normal vector * y.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This works great for points but it doesn't work for quadratic bezier curves because the control point must be transformed such that each point on the resulting curve approximates a projected point. I'm trying to find method of calculating a control point such that the resulting curve is consistent, well behaved, doesn't require excessive computation, and is visually pleasing (though not necessarily precisely accurate) and can be applied to arbitrary target curves. Probably the most important requirement for the result is that two consecutive bezier segments that share the same tangent, share the same tangent in the projected curves.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the control point of a quadratic bezier is always the intersection of the tangent lines through its start and end point, my solution so far is to take the tangent vectors from the original target curve, transform them relative to the source normal vectors and then calculate the intersection of the lines defined by these transformed tangent vectors. Unfortunately this appears to work well for horizontal target curves but somehow it is often wrong for diagonal curves. I think this is because of the arc-length transformation but I haven't figured it out yet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm curious if anyone has any thoughts on how to approach this problem.&#xA;The current (incorrect) implementation of the function in question can be found here:&#xA;&lt;a href=&quot;https://github.com/ianmbloom/gudni/blob/c65daed3e74a24c47db9d0488159104dbd1b8b62/src/Graphics/Gudni/Figure/Projection.hs#L243&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/ianmbloom/gudni/blob/c65daed3e74a24c47db9d0488159104dbd1b8b62/src/Graphics/Gudni/Figure/Projection.hs#L243&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let me know if reading haskell is a problem and I can find a way to walk you through it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Upon request, here is a link to a formalization of the problem:&#xA;&lt;a href=&quot;https://medium.com/@ianbloom/-6e88ea8e8888&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://medium.com/@ianbloom/-6e88ea8e8888&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Kind regards,&#xA;Ian Bloom&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Mbmpq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mbmpq.jpg&quot; alt=&quot;Projection of one quadratic bezier onto another.&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11754" LastEditorUserId="11754" LastEditDate="2020-01-19T22:13:38.277" LastActivityDate="2020-01-19T22:13:38.277" Title="Projecting one Quadratic Bezier Curve Onto Another" Tags="&lt;rasterizer&gt;&lt;curve&gt;&lt;bezier-curve&gt;&lt;opencl&gt;" AnswerCount="0" CommentCount="15" ContentLicense="CC BY-SA 4.0" />
  <row Id="9502" PostTypeId="1" CreationDate="2020-01-19T12:19:00.600" Score="0" ViewCount="44" Body="&lt;p&gt;I'm trying to make simple 3d modeling program in c++ with Opengl. So I don't know how to transfer/convert/export or save data of 3D model  in .dae file. &#xA;NOTE:- 3d model is made using Opengl programming. &lt;/p&gt;&#xA;" OwnerUserId="11757" LastActivityDate="2020-01-19T12:19:00.600" Title="After making any 3D model using Opengl how to export it's data in .dae file?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;c++&gt;&lt;gpu&gt;&lt;model&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9504" PostTypeId="1" AcceptedAnswerId="9506" CreationDate="2020-01-21T17:58:28.277" Score="3" ViewCount="265" Body="&lt;p&gt;There are plenty of well-known algorithms for determining &lt;em&gt;if&lt;/em&gt; a ray hit an Axis-Aligned Bounding Box (AABB), like Andrew Woo's covered in a response &lt;a href=&quot;https://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms&quot;&gt;here&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &lt;code&gt;exit = origin + (dir * tMax)&lt;/code&gt; will give you the exact position of exit using distance through the ray. (and same for tMin and the entry)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I need a way to not only do that, but also get if we hit the left, right, top, bottom, front, or rear face of the AABB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The naive approach would be to do some kind of floating-point comparison given the minpoint/maxpoint and try to see what side (if any) the point exactly equals in each dimension, or exactly equals within a tolerance. That seems error-prone, I was wondering if there was a better way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there an algorithm for this?&lt;/p&gt;&#xA;" OwnerUserId="11282" LastEditorUserId="11652" LastEditDate="2020-01-24T02:36:07.873" LastActivityDate="2020-02-24T07:33:41.633" Title="Ray vs AABB algorithm that also gives which side was hit?" Tags="&lt;raytracing&gt;&lt;algorithm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9505" PostTypeId="1" AcceptedAnswerId="9507" CreationDate="2020-01-21T18:45:19.317" Score="2" ViewCount="57" Body="&lt;p&gt;A point light is illuminating only a half of a scene in my small 3D renderer. It happens on every scene I've tried (conference room, cornell box, etc). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I go about debugging this? What could be wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RF9YY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RF9YY.png&quot; alt=&quot;sponza scene&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are the shaders. I'm not doing anything out of the ordinary. Light is positioned at (0, 1.0, 0) in world space.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//&#xA;// VERT SHADER&#xA;//&#xA;#version 410 core&#xA;&#xA;uniform mat4 M;&#xA;uniform mat4 V;&#xA;uniform mat4 P;&#xA;&#xA;layout (location = 0) in vec3 position;&#xA;layout (location = 1) in vec3 normal;&#xA;layout (location = 2) in vec3 color;&#xA;layout (location = 3) in vec2 texCoords;&#xA;&#xA;out vec3 fWorldPos;&#xA;out vec3 fNormal;&#xA;out vec3 fColor;&#xA;out vec2 fTexCoords;&#xA;&#xA;void main()&#xA;{&#xA;    mat4 normalMatrix = transpose(inverse(M));&#xA;&#xA;    fWorldPos = vec3(M * vec4(position, 1.0));&#xA;    fNormal = normal; // also tested multiplying with normal, M, and MV matrices&#xA;    fColor = color;&#xA;    fTexCoords = texCoords;&#xA;&#xA;    gl_Position = P * V * M * vec4(position, 1);&#xA;}&#xA;&#xA;&#xA;//&#xA;// FRAG SHADER&#xA;//&#xA;#version 410 core&#xA;#define MAX_POINT_LIGHTS 4&#xA;&#xA;struct PointLight {&#xA;    float strength;&#xA;    vec3 position;&#xA;    vec3 color;&#xA;    vec3 attenuation;&#xA;};&#xA;&#xA;struct Material {&#xA;    vec3 color;&#xA;};&#xA;&#xA;uniform Material material;&#xA;uniform int totalPointLights;&#xA;uniform PointLight pointLights[MAX_POINT_LIGHTS];&#xA;uniform vec3 cameraPosition;&#xA;&#xA;in vec3 fWorldPos;&#xA;in vec3 fNormal;&#xA;in vec3 fColor;&#xA;in vec2 fTexCoords;&#xA;&#xA;out vec4 color;&#xA;&#xA;float attenuate(float dist, const PointLight light) {&#xA;    return light.strength / (light.attenuation.x + light.attenuation.y * dist + light.attenuation.z * dist * dist);&#xA;}&#xA;&#xA;//&#xA;// MAIN&#xA;//&#xA;void main()&#xA;{&#xA;  vec3 normal = normalize(fNormal);&#xA;&#xA;  PointLight light = pointLights[0];&#xA;&#xA;  vec3 lightDir = light.position - fWorldPos;&#xA;  float lightDst = length(lightDir);&#xA;  lightDir = lightDir / lightDst;&#xA;&#xA;  float att = attenuate(lightDst, light);&#xA;  float diffuseFactor = max(dot(normal, lightDir), 0.0);&#xA;&#xA;  color = vec4(material.color * diffuseFactor * att, 1);&#xA;}&#xA;&lt;span class=&quot;math-container&quot;&gt;```&lt;/span&gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11771" LastActivityDate="2020-01-22T09:00:47.623" Title="Point light illuminating only half of a scene" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9506" PostTypeId="2" ParentId="9504" CreationDate="2020-01-22T01:35:51.820" Score="2" Body="&lt;p&gt;Given an intersection algorithm like &lt;a href=&quot;https://gamedev.stackexchange.com/a/18459&quot;&gt;the one you linked&lt;/a&gt; which first generates a &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; value for every plane of the AABB, then computes &lt;span class=&quot;math-container&quot;&gt;$t_{min}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t_{max}$&lt;/span&gt; from those, you simply need to figure out which of the six initial values correspond to your final &lt;span class=&quot;math-container&quot;&gt;$t_{min}$&lt;/span&gt;. There will be two matches if your ray hits an edge, three if it hits a corner. In that case, this may include a back face (see the fix below).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This will not require a tolerance as &lt;span class=&quot;math-container&quot;&gt;$t_{min}$&lt;/span&gt; is always one of the six values. In fact, it is always one of three intermediate values and you can use that to make your check simpler, faster and better. Given code, from the link above, such as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float tmin = max(max(min(t1, t2), min(t3, t4)), min(t5, t6));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;you could rewrite as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float tminx = min(t1, t2);&#xA;float tminy = min(t3, t4);&#xA;float tmin = max(max(tminx, tminy), min(t5, t6));&#xA;int axis = 2;&#xA;if (tmin == tminx) axis = 0;&#xA;if (tmin == tminy) axis = 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As an added bonus, unlike testing all six values, this will not match the back face in the event that a far edge is hit.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2020-01-22T01:35:51.820" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9507" PostTypeId="2" ParentId="9505" CreationDate="2020-01-22T08:46:36.273" Score="3" Body="&lt;p&gt;The normals were indeed wrong. Which was crazy, because I had even checked in Blender that they were correct (and they were). Turns out, when loading the mesh, I was passing the normal as color and vice versa. Valletin's normal visualization shader was great (&lt;a href=&quot;https://vallentin.dev/2015/02/16/visualizing-normals&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://vallentin.dev/2015/02/16/visualizing-normals&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for your help!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6Ifpz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6Ifpz.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11771" LastEditorUserId="11771" LastEditDate="2020-01-22T09:00:47.623" LastActivityDate="2020-01-22T09:00:47.623" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9508" PostTypeId="1" AcceptedAnswerId="9509" CreationDate="2020-01-23T16:37:12.880" Score="0" ViewCount="190" Body="&lt;p&gt;I am reading &lt;a href=&quot;https://static1.squarespace.com/static/559921a3e4b02c1d7480f8f4/t/596773e9f7e0ab3d29bb102f/1499952110561/Mroz+Michael_746.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this document&lt;/a&gt; that talks about signed distance field rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In that document section 6.3, on the topic of cone tracing, it says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Cone tracing is an extension of the sphere tracing algorithm. In&#xA;  addition to the ray, a cone is created and expanded in the marching&#xA;  direction. At each sampling step, the current cone radius is compared&#xA;  with the minimum distance from the distance field. If the SDF value is&#xA;  smaller than the current radius, the cone has intersected an object&#xA;  [14]. This incurs very little additional cost to the normal sphere&#xA;  trace, while providing useful intersection information.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;In particular: &lt;code&gt;If the SDF value is smaller than the current radius, the cone has intersected an object&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I reading this wrong? there's no way that's true. Consider the following diagram:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wGL7T.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wGL7T.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From that diagram, it seems obvious that for any cone radius &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; there exists an SDF value &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt; such that &lt;span class=&quot;math-container&quot;&gt;$R &amp;gt; \epsilon$&lt;/span&gt; and the cone doesn't intersect the sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I interpreting the document wrong?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-01-24T00:37:10.107" Title="Reading thesis on cone tracing, did the author make a mistake?" Tags="&lt;raytracing&gt;&lt;mathematics&gt;&lt;geometry&gt;&lt;raymarching&gt;&lt;ray&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9509" PostTypeId="2" ParentId="9508" CreationDate="2020-01-24T00:37:10.107" Score="1" Body="&lt;p&gt;It’s kind of inaccurately stated—by comparing the SDF with a linearly increasing radius, the shape that’s being traced out is a cone with a hemisphere on the end, something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zTeTH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zTeTH.png&quot; alt=&quot;diagram&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At any point along the horizontal center line, if the distance to the nearest surface is less than the current test radius, the cone-plus-hemisphere has intersected that surface.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2020-01-24T00:37:10.107" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9510" PostTypeId="1" CreationDate="2020-01-24T05:01:46.850" Score="0" ViewCount="71" Body="&lt;p&gt;The image shown below illustrate the process to break a cube down into 4 small equal cubes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a term to refer to this process, something like cube-break-down?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IOSrD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IOSrD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Why would I like to know the term?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because I am trying to perform this process by coding, and I am wondering if there existing code base to do this.&lt;/p&gt;&#xA;" OwnerUserId="11784" LastEditorUserId="11652" LastEditDate="2020-01-30T16:57:03.323" LastActivityDate="2020-03-07T07:02:05.213" Title="Is there a term to refer to a cube-break-down process?" Tags="&lt;terminology&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9514" PostTypeId="1" CreationDate="2020-01-26T13:28:34.383" Score="1" ViewCount="223" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick%27s_approximation&quot; rel=&quot;nofollow noreferrer&quot;&gt;The approximation&lt;/a&gt; writes the reflection coefficient as&lt;span class=&quot;math-container&quot;&gt;$$R(\theta)=R_0+(1-R_0)(1-\cos\theta)^5,\,R_0=\left(\frac{n_1-n_2}{n_1+n_2}\right)^2.$$&lt;/span&gt;Why is the exponent 5? &lt;a href=&quot;https://www.cs.virginia.edu/~jdl/bib/appearance/analytic%20models/schlick94b.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Schlick 1994&lt;/a&gt; introduces this exponent in Eq. (24), claiming it's the right Fresnel approximation, but with no explanation.&lt;/p&gt;&#xA;" OwnerUserId="11797" LastActivityDate="2020-01-26T13:28:34.383" Title="Why does Schlick's approximation contain a \$(1-\cos\theta)^5\$ term?" Tags="&lt;lighting&gt;&lt;mathematics&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9515" PostTypeId="1" CreationDate="2020-01-26T16:06:34.657" Score="0" ViewCount="108" Body="&lt;p&gt;I&lt;a href=&quot;https://i.stack.imgur.com/E0px9.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/E0px9.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt; want to do a non-linear transformation of a svg in python. My specific problem is to transform a rectangular svg image into a frustum like image, for which i have a mathematical equation of the form (x',y') = f(x,y).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far, I've been able to find a javascript library called warp.js (&lt;a href=&quot;https://github.com/benjamminf/warpjs&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/benjamminf/warpjs&lt;/a&gt;), which supports application of generic point-wise transformation on svg. But I'm unable to find any such tools for python or C++ except for basic transformation like skew, rotation etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any help would be greatly appreciated. Thanks!&lt;/p&gt;&#xA;" OwnerUserId="11799" LastActivityDate="2020-01-26T16:06:34.657" Title="Non linear transformation of vector graphic" Tags="&lt;c++&gt;&lt;vector-graphics&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9516" PostTypeId="1" AcceptedAnswerId="9520" CreationDate="2020-01-27T00:09:51.563" Score="4" ViewCount="62" Body="&lt;p&gt;In reading the wikipedia page about B-Splines &lt;a href=&quot;https://en.wikipedia.org/wiki/B-spline&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/B-spline&lt;/a&gt;, I am getting confused about the concept of knots.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we have a spline of order &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;, with a knot vector (&lt;span class=&quot;math-container&quot;&gt;$t_0, \cdots, t_k$&lt;/span&gt;),&#xA;then if the &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; knots are distinct, I think we have &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; polynomials that are pieced together, but if we have that &lt;span class=&quot;math-container&quot;&gt;$r \leq k$&lt;/span&gt; knots are distinct, then I am not sure what this means.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How many polynomials are we piecing together?&#xA; How is the overall piecewise curve defined?&lt;/p&gt;&#xA;" OwnerUserId="10079" LastActivityDate="2020-02-27T18:04:42.437" Title="Understanding distinct vs. not distinct knots in B-splines" Tags="&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9517" PostTypeId="1" CreationDate="2020-01-27T20:33:25.077" Score="0" ViewCount="41" Body="&lt;p&gt;I extract a mesh from a method similar to Marching cubes. I want to estimate the topological relationship between connected components.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, below, let's assume that we have 4 connected components. One is the outside sphere and inside it there are threes spheres.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I computed the connected components based on the edge information of the mesh. Do you have an idea about how to extract topology information?&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;My Idea is to make a tree where a node denotes an object and edge (a,b) represents that &lt;code&gt;a&lt;/code&gt; contains &lt;code&gt;b&lt;/code&gt;. I just compare their bounding boxes. But it can have some degenerate cases and I'm not sure how I can implement this efficiently. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4fEns.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4fEns.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11786" LastEditorUserId="7462" LastEditDate="2020-01-30T14:52:02.690" LastActivityDate="2020-01-30T14:52:02.690" Title="Find the inside and outside relationship of connected components in a mesh" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9518" PostTypeId="1" AcceptedAnswerId="9522" CreationDate="2020-01-28T11:41:06.460" Score="2" ViewCount="74" Body="&lt;p&gt;What is the correct way to invert the y axis during the 3D projection?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I see a lot a people doing:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;pixel_x = (x_world / z_world + 1) / 2 * ScreenWidth(); // This is right&#xA;pixel_y = (1 - y_world / z_world) / 2 * ScreenHeight();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But by inverting like this, we get an incorrect position of &lt;code&gt;pixel_y&lt;/code&gt; because what this does is saying that &lt;code&gt;pixel_y&lt;/code&gt; is 1 when &lt;code&gt;y_world&lt;/code&gt; is -1 and 1 when &lt;code&gt;y_world&lt;/code&gt; is -1. This seems right but don't forget that a point at &lt;code&gt;x == 1&lt;/code&gt; in NDC space will map to &lt;code&gt;pixel_x = ScreenWidth()&lt;/code&gt; and therefore won't be visible. In contrast, a point at &lt;code&gt;x == -1&lt;/code&gt; in NDC space will map to &lt;code&gt;pixel_x = 0&lt;/code&gt; and WILL be visible.&#xA;So if we invert like this, a point at &lt;code&gt;y == -1&lt;/code&gt; will become &lt;code&gt;pixel_y == ScreenHeight()&lt;/code&gt; and WON'T be visible but a point at &lt;code&gt;y == 1&lt;/code&gt; will become &lt;code&gt;pixel_y == 0&lt;/code&gt; and will be visible.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that the correct way of inverting y is by first calculating &lt;code&gt;pixel_y&lt;/code&gt; like &lt;code&gt;pixel_x&lt;/code&gt; and then and only then invert it in pixel space:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel_y = (y_world / z_world + 1) / 2 * ScreenHeight(); // Y points up&#xA;pixel_y = ScreenHeight() - 1 - pixel_y; // now it points down&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So what is the correct way to invert the y axis during the projection?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2020-01-29T06:11:42.507" Title="Y axis inversion in 3D rasterization" Tags="&lt;3d&gt;&lt;projections&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9519" PostTypeId="2" ParentId="5571" CreationDate="2020-01-28T18:07:51.260" Score="0" Body="&lt;p&gt;First of all, you talk about inverse orientation of points in matrix, this is needed because the subtraction logic in world transformations are directly relationed with screen rotation, instead it that the camera moviments (translation you mentioned) no are directly relationed of the screen position around center of projection.&lt;/p&gt;&#xA;" OwnerUserId="11807" LastActivityDate="2020-01-28T18:07:51.260" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9520" PostTypeId="2" ParentId="9516" CreationDate="2020-01-28T21:50:15.430" Score="4" Body="&lt;p&gt;So, the number of polynomials that you piece together depends on multiple factors, including the number of control points and the degree of the curve. If the number of points is equal to the order, then you have a single polynomial, if the order is &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; and you have &lt;span class=&quot;math-container&quot;&gt;$n+1$&lt;/span&gt; points, then you are piecing together 2 polynomials, etc...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Distinct points are points that are different from each other.&#xA;Take the vector [0,1,2,3,4] where all knots are distinct and contrast it with [0,1,2,2,3,4] where the knot 2 has multiplicity 2 (it's not distinct since it appears twice). These knots lower the degree of the curve locally by 1 for each repetition.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The overall curve can be defined in many ways, the simplest way to look at it is as DeDoor's algorithm, which is a generalisation of DeCastlejeau's.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am going to do a bit of self promotion and link my &lt;a href=&quot;https://gitlab.com/Makogan/mathproofs/blob/master/B-splines/b-splines.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;own notes of B-Splines&lt;/a&gt;. Gitlab's PDF viewer butchers them a bit so I recommend downloading them and reading them with Okular or Adobe reader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Regardless, that document has more information than what can be put into a stack exchange answer and does indeed try to convey the intuition about how to build B-Splines, both mathematically and algorithmically.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-02-27T18:04:42.437" LastActivityDate="2020-02-27T18:04:42.437" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9522" PostTypeId="2" ParentId="9518" CreationDate="2020-01-29T06:11:42.507" Score="1" Body="&lt;p&gt;Let's look at your formula:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel_y = (y_world / z_world + 1) / 2 * ScreenHeight();&#xA;pixel_y = ScreenHeight() - 1 - pixel_y;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Let's call &lt;code&gt;y_world / z_world&lt;/code&gt; for short &lt;code&gt;a&lt;/code&gt;, &lt;code&gt;H&lt;/code&gt; for &lt;code&gt;ScreenHeight()&lt;/code&gt;. So you have:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Y = (a + 1) / 2 *H&#xA;Y = H - 1 - Y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Let's replace the first in the second:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   Y = H - 1 - (a + 1) / 2 * H&#xA;=&amp;gt; Y = H * (1 - (a + 1) / 2) - 1&#xA;=&amp;gt; Y = H * ((2 - a - 1) / 2) - 1&#xA;=&amp;gt; Y = H * (1 - a) / 2 - 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which is the formula you said every one uses (except with an off-by-one error):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pixel_y = (1 - y_world / z_world) / 2 * ScreenHeight();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Off-by-one error aside, looks like you have the right understanding, just didn't work out that the formula everyone uses is the optimized version of what you came up with.&lt;/p&gt;&#xA;" OwnerUserId="6442" LastActivityDate="2020-01-29T06:11:42.507" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9524" PostTypeId="1" CreationDate="2020-01-29T08:09:47.407" Score="0" ViewCount="56" Body="&lt;p&gt;I have found the following from this link&#xA;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/api/d3d11/ns-d3d11-d3d11_mapped_subresource&quot; rel=&quot;nofollow noreferrer&quot;&gt;enter link description here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;pData&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Type: void*&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Pointer to the data. When ID3D11DeviceContext::Map provides the&#xA;  pointer, the runtime ensures that the pointer has a specific&#xA;  alignment, depending on the following feature levels:&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;For D3D_FEATURE_LEVEL_10_0 and higher, the pointer is aligned to 16&#xA;  bytes. For lower than D3D_FEATURE_LEVEL_10_0, the pointer is aligned&#xA;  to 4 bytes.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Would someone please explain if I can reinterpret cast the void pointer into OLE_COLOR* or not?&lt;/p&gt;&#xA;" OwnerUserId="9971" LastEditorUserId="9971" LastEditDate="2020-02-09T08:44:11.343" LastActivityDate="2020-02-09T08:44:11.343" Title="void* D3D11_MAPPED_SUBRESOURCE::pData to OLE_COLOR* possible?" Tags="&lt;c++&gt;&lt;directx11&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9525" PostTypeId="1" AcceptedAnswerId="9541" CreationDate="2020-01-29T12:58:34.423" Score="2" ViewCount="234" Body="&lt;p&gt;(possible duplicate)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to implement multiple importance sampling, as described in the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Direct_Lighting.html#fragment-SampleBSDFwithmultipleimportancesampling-0&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBRT book&lt;/a&gt; (no bouncing yet, I want to make MIS work first).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What my problem is, that while the BRDF sampling looks okay, the light sampling is much dimmer (yet according to the pictures in the book they should look the same in intensity).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W36nQm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W36nQm.jpg&quot; alt=&quot;sampling the BRDF&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2zQz2m.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2zQz2m.jpg&quot; alt=&quot;sampling the light&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I uploaded the &lt;em&gt;(updated)&lt;/em&gt; &lt;a href=&quot;https://www.dropbox.com/s/bkprhax5dgwpmu2/FOR_STACKEXCHANGE_1.zip?dl=0&quot; rel=&quot;nofollow noreferrer&quot;&gt;compilable code&lt;/a&gt; (VS 2015). The relevant parts can be found in &lt;em&gt;multipleimportance.frag&lt;/em&gt; (SampleLightsExplicit) and &lt;em&gt;pbr_common.head&lt;/em&gt; (ConeSampleSphere).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;(note that I don't apply the MIS weights yet)&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for (int k = 0; k &amp;lt; numLights; ++k) {&#xA;    SceneObject light = objects.data[k];&#xA;&#xA;    center = vec3(light.toworld[3].xyz);&#xA;    radius = light.toworld[0][0];&#xA;&#xA;    // importance sample light (xyz = direction, w = PDF)&#xA;    sample1 = ConeSampleSphere(p, center, radius, pixel, seed + float(k));&#xA;&#xA;    // cast shadow ray&#xA;    vis = Visibility(p, sample1.xyz, k);&#xA;    ndotl = vis * max(0.0, dot(sample1.xyz, n));&#xA;&#xA;    // evaluate BRDF&#xA;    fd = vec3(0.0); //obj.color.rgb * ONE_OVER_PI;&#xA;    fs = CookTorrance_General(sample1.xyz, v, n, vec3(0.04), roughness);&#xA;&#xA;    sum += (light.color.rgb * (fd + fs) * ndotl) / sample1.w;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;My question is why light sampling looks so dim? Did I misunderstand something?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Looking through the code I noticed some inconsistencies which probably originated from a typo in one of the older SIGGRAPH course notes (can't tell which one tho).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The PDF of the GGX distribution is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PDF = D(h) * dot(n, h)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;While some implementations (including UE4) incorrectly write it as&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;PDF = (D(h) * dot(n, h)) / (4 * dot(v, h))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;which essentially means that they include the Cook-Torrance denominator into this variable (&lt;em&gt;ndotl&lt;/em&gt; cancels out). Dividing with the correct PDF cancels out &lt;em&gt;D&lt;/em&gt; in the Cook-Torrance model, which I forgot to account for, while the &lt;em&gt;1 / (4 * dot(v, h))&lt;/em&gt; term goes into the &lt;em&gt;Vis_Schlick&lt;/em&gt; function.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So regarding intensity the second picture is the &quot;correct&quot; one. The dimness is still a problem tho. Changing the Fresnel &lt;em&gt;F0&lt;/em&gt; to 0.11 (as it supposedly is in the book) and applying the MIS weights, the picture looks a lot more promising, except for the topmost plate which should almost explicitly reflect the light sources:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lFnVt.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lFnVt.jpg&quot; alt=&quot;multiple importance sampling&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So this is &lt;em&gt;almost okay&lt;/em&gt; now. I'm gonna look deeper into the MIS part to see why it makes those highlights disappear.&lt;/p&gt;&#xA;" OwnerUserId="11811" LastEditorUserId="11811" LastEditDate="2020-02-01T11:00:03.620" LastActivityDate="2020-02-27T11:35:18.773" Title="Sampling the light vs. sampling the BRDF: difference in intensity" Tags="&lt;opengl&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9526" PostTypeId="1" CreationDate="2020-01-29T14:35:55.033" Score="2" ViewCount="78" Body="&lt;p&gt;I want to set the color of the lamps in my game with a black body curve, but the approximations I can find for it are all in sRGB color space; and I want it in linear floating RGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The closest thing i was able to find is this: &lt;a href=&quot;https://mathematica.stackexchange.com/questions/57389/convert-spectral-distribution-to-rgb-color&quot;&gt;https://mathematica.stackexchange.com/questions/57389/convert-spectral-distribution-to-rgb-color&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But i really don't understand most of the notation in the answer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Mainly I'm unsure: if i just use planck's law, using the wavelengths of the subpixels in a standard monitor--not that I know what those are--will it get the right answer, or would it need to be an integral with respect to cone response.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Furthermore I'm not sure how to normalize the resulting radiation density from.... whatever units its in, to 1.0 = X nits; as I'm unsure of the conversion between the units...&lt;/p&gt;&#xA;" OwnerUserId="11813" LastActivityDate="2020-01-29T18:16:23.403" Title="Blackbody curve to floating RGB" Tags="&lt;physics&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9527" PostTypeId="2" ParentId="9526" CreationDate="2020-01-29T15:17:22.400" Score="0" Body="&lt;p&gt;The code below is based on the article &lt;a href=&quot;http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code&quot; rel=&quot;nofollow noreferrer&quot;&gt;How to Convert Temperature (K) to RGB: Algorithm and Sample Code&lt;/a&gt; with Neil Bartlett modifications from the article &lt;a href=&quot;http://www.zombieprototypes.com/?p=210&quot; rel=&quot;nofollow noreferrer&quot;&gt;Color Temperature Conversion Of Homestar.io&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bartlett has released a javascript library &lt;a href=&quot;https://github.com/neilbartlett/color-temperature&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;neilbartlett/color-temperature&lt;/code&gt;&lt;/a&gt; which computes RGB from kelvin with the color components in the range &lt;code&gt;0&lt;/code&gt; to &lt;code&gt;255&lt;/code&gt;. The code below is adjusted for RGB components in the range &lt;code&gt;0.0&lt;/code&gt; to &lt;code&gt;1.0&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float t = kelvin / 100.0;&#xA;float x;&#xA;float red;&#xA;float green;&#xA;float blue;&#xA;if (t &amp;lt;= 66)&#xA;{&#xA;    red = 1.0;&#xA;}&#xA;else&#xA;{&#xA;    x = t - 55.0;&#xA;    red = clamp(&#xA;        1.38030159086 + 0.00044786845 * x - 0.15785750233 * log(x),&#xA;        0.0,&#xA;        1.0);&#xA;}&#xA;if (t &amp;lt;= 10)&#xA;{&#xA;    green = 0.0;&#xA;}&#xA;else if (t &amp;lt;= 66)&#xA;{&#xA;    x = t - 2.0;&#xA;    green = clamp(&#xA;        -0.60884257109 - 0.00174890002 * x + 0.40977318429 * log(x),&#xA;        0.0,&#xA;        1.0);&#xA;}&#xA;else&#xA;{&#xA;    x = t - 50.0;&#xA;    green = clamp(&#xA;        1.27627220616 + 0.0003115081 * x - 0.11013841706 * log(x),&#xA;        0.0,&#xA;        1.0);&#xA;}&#xA;if (t &amp;lt;= 20)&#xA;{&#xA;    blue = 0.0;&#xA;}&#xA;else if (t &amp;lt;= 66)&#xA;{&#xA;    x = t - 10.0;&#xA;    blue = clamp(&#xA;        -0.99909549742 + 0.00324474355 * x + 0.45364683926 * log(x),&#xA;        0.0,&#xA;        1.0);&#xA;}&#xA;else&#xA;{&#xA;    blue = 1.0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;code&gt;log&lt;/code&gt; refers to natural log.&lt;/p&gt;&#xA;" OwnerUserId="6284" LastActivityDate="2020-01-29T15:17:22.400" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9528" PostTypeId="2" ParentId="9526" CreationDate="2020-01-29T18:16:23.403" Score="2" Body="&lt;p&gt;The &lt;a href=&quot;https://github.com/imageworks/OpenShadingLanguage/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Open Shading Language&lt;/a&gt; has &lt;a href=&quot;https://github.com/imageworks/OpenShadingLanguage/blob/master/src/liboslexec/opcolor.cpp#L785&quot; rel=&quot;nofollow noreferrer&quot;&gt;a complete implementation&lt;/a&gt; which is based on &lt;a href=&quot;http://www.fourmilab.ch/documents/specrend/specrend.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;this source code&lt;/a&gt; from &lt;a href=&quot;https://www.fourmilab.ch/documents/specrend/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Color Rendering of Spectra&lt;/a&gt; by John Walker, according to the comments. I can't vouch for its theoretical correctness but I have used it and it appears to work reasonably well.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2020-01-29T18:16:23.403" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9533" PostTypeId="1" AcceptedAnswerId="9543" CreationDate="2020-01-31T23:30:25.133" Score="4" ViewCount="125" Body="&lt;p&gt;I've seen lots of spins on the ray-box intersection test, and a lot of them seem to boil down to this code: (omitting some details here)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  invRay.x = 1.0 / ray.x;&#xA;&#xA;  tx1 = (box.min.x - rayOrigin.x) * invRay.x;&#xA;  tx2 = (box.max.x - rayOrigin.x) * invRay.x;&#xA;&#xA;  tmin = min(tx1, tx2);&#xA;  tmax = max(tx1, tx2);&#xA;&#xA;  // Repeat for Y and Z&#xA;  // Then check to ensure tmin &amp;lt; tmax&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(I got mine specifically from &lt;a href=&quot;https://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms&quot;&gt;this discussion&lt;/a&gt; and &lt;a href=&quot;https://tavianator.com/cgit/dimension.git/tree/libdimension/bvh/bvh.c#n196&quot; rel=&quot;nofollow noreferrer&quot;&gt;this source&lt;/a&gt;. Also note that if you use std::min and std::max, it's far from branchless)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this raises a significant problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What if the ray's origin in one or more dimensions is equal to the min or max points?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I found is that I get this situation on an example ray and box:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Ray origin: (3.225, 0.243, 2.221)&lt;/li&gt;&#xA;&lt;li&gt;Ray direction: (0, 0, -1)&lt;/li&gt;&#xA;&lt;li&gt;Box min: (3.223, 0.241, 2.119)&lt;/li&gt;&#xA;&lt;li&gt;Box max: (3.225, 0.243, 2.121)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Is that when tx1 is calculated, it correctly gets -inf. However, when tx2 is calculated, it gets &lt;code&gt;(3.225 - 3.225) * inf&lt;/code&gt; which is coming out to &lt;code&gt;-nan&lt;/code&gt;. This means that later, when we do:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;float tmax = std::max(tx1, tx2);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We get &lt;code&gt;max(-inf, -nan)&lt;/code&gt; which comes out to &lt;code&gt;-inf&lt;/code&gt; and from that point on in the tests, tmax will always be -inf, making the overall ray-box test fail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is confirmed by some comments on the page where I got the code:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Something to consider here is that 0 * inf =nan which occurs when the ray starts exactly on the edge of a box&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;And&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Having read both this and part 2, I'm unable to work out what changes I need to make in order to reliably detect intersections when a ray is exactly on the edge of an AABB.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Does anyone know a fast method for ray-box intersection with edge and corner hits?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I should note &lt;strong&gt;this is not being used with a BVH&lt;/strong&gt;. I need an &lt;strong&gt;exact&lt;/strong&gt; intersection test, I cannot increase the size of the box at all.&lt;/p&gt;&#xA;" OwnerUserId="11282" LastEditorUserId="11282" LastEditDate="2020-02-04T18:38:31.407" LastActivityDate="2020-02-24T07:30:47.797" Title="Need a fast ray-box intersection that handles if a ray is parallel and in line with a plane of the box" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9537" PostTypeId="1" CreationDate="2020-02-02T23:38:38.570" Score="0" ViewCount="223" Body="&lt;p&gt;When I was writing a software rasterizer for my university class, we did culling in  eye coordinates. Essentially, we use cross product to get a normal from the 3 vertices (in eye coordinates), then we dot product that normal with one of the 3 vertices (since we are in eye coordinate, that vertex is essentially a vector from eye [0, 0, 0,.1] to triangle surface). If the dot product is &gt; 0, meaning the normal and the eye vector point in the same direction, we cull that triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OpenGL however doesn't do culling in eye space, since culling is after vertex shader. So all they have are vertices in clip space. So how do they know which triangle to do culling? Our triangles, when fed into the graphic pipeline, are always in CCW order. How do some turn into CW order?&lt;/p&gt;&#xA;" OwnerUserId="10461" LastActivityDate="2021-02-01T15:24:17.770" Title="How does graphics api like OpenGL determine which triangle is back face to cull?" Tags="&lt;opengl&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9538" PostTypeId="2" ParentId="9537" CreationDate="2020-02-03T09:51:12.430" Score="1" Body="&lt;p&gt;It's actually fairly simple (and in essence 'equivalent' to what you said above). If you represent triangle ABC's &lt;em&gt;projected&lt;/em&gt; XY coordinates as a matrix...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$M_{ABC} =   \begin{bmatrix}&#xA;    X_A &amp;amp; X_B &amp;amp; X_C \\&#xA;    Y_A &amp;amp; Y_B &amp;amp; Y_C \\&#xA;    1 &amp;amp; 1 &amp;amp; 1 \\&#xA;    \end{bmatrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;...then the sign of the determinant e.g. &lt;span class=&quot;math-container&quot;&gt;$X_A (Y_B - Y_C)+X_B(Y_C-Ya)+X_C(Y_A-Y_B)$&lt;/span&gt; will allow you to decide how to cull. &#xA;Further if the determinant is zero, then the on-screen triangle has zero area and can clearly be removed.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another reason to use this notation is that the adjoint of &lt;span class=&quot;math-container&quot;&gt;$M_{ABC}$&lt;/span&gt;  gives you equations for the edges.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2020-02-03T09:51:12.430" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9539" PostTypeId="1" AcceptedAnswerId="9545" CreationDate="2020-02-03T12:27:49.927" Score="2" ViewCount="60" Body="&lt;p&gt;Currently I have textures which need GL_NEAREST and some other need GL_LINEAR in the same texture2dArray. In the shader I perform a manual GL_NEAREST lookup via textureFetch().&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To avoid this my question is, is it possible to set the value of GL_TEXTURE_MIN/MAG_FILTER for each texture in a texture array to different values?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know of the same size restrictions, but could not find anything regarding mipmapping.&lt;/p&gt;&#xA;" OwnerUserId="10188" LastEditorUserId="2654" LastEditDate="2020-02-04T06:00:20.217" LastActivityDate="2020-02-04T06:06:29.833" Title="2D array texture with different filtering setting per texture?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;3dtexture&gt;&lt;mipmap&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9540" PostTypeId="2" ParentId="9537" CreationDate="2020-02-03T14:41:39.860" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;then we dot product that normal with one of the 3 vertices&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;That's incorrect. It's not difficult to construct a scenario where this will result in an incorrect determination of facing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Imagine a triangle that is nearly edge-on with the view, but is still facing the view. Now, imagine that this triangle has a normal that, when edge-on, is pointed slightly away from the view. Remember: vertex normals on a surface that is supposed to be curved represent the normal at that portion of the curved surface. And therefore they don't have to be aligned with the face normal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any case, the math for determining the facing of a triangle happens in &lt;em&gt;window&lt;/em&gt; space, not clip-space. It's pretty simple: you get the direction from the first position to the second and the direction from the second to the third. And you take the cross-product of them. If the Z component of the cross product is positive, then the triangle is counter-clockwise, relative to the window. So this doesn't even require the entire cross product; just the Z component (and just the sign of it at that).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-02-03T14:41:39.860" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9541" PostTypeId="2" ParentId="9525" CreationDate="2020-02-03T15:22:22.857" Score="1" Body="&lt;p&gt;Shoot me... After the fixes I posted above, I started debugging Mitsuba to see whether it does anything differently on a large scale. Of course it didn't; my code is completely correct, the dimness is due to this macro def:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#define EPSILON   1e-5&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is used in divisions to avoid dividing with zero. Unfortunately, it accumulates to a large value during the calculations. Changing it to 1e-9 fixes everything:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/URn4F.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/URn4F.jpg&quot; alt=&quot;mis_final&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For future generations I leave the source code up (just remember to change this value).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found another mistake in my calculations, but it isn't apparent in this scene. Microsurface-based BRDFs are usually sampled according to the microfacet normal distribution function (D(h, a), in this case GGX).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Don't forget however, that you also have a shadowing-masking function (G(l, v, a)) which has to be evaluated according to the chosen microfacet distribution. This means that I can't just mix-and-match f.e. GGX sampling and the &lt;em&gt;Smith-Schlick&lt;/em&gt; evaluation; I have to use the &lt;em&gt;Smith-GGX&lt;/em&gt; solution:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float G_Smith_GGX(float ndotl, float ndotv, float roughness)&#xA;{&#xA;    float a = roughness * roughness;&#xA;    float a2 = a * a;&#xA;&#xA;    float lambda_l = sqrt(a2 + (1.0 - a2) * ndotl * ndotl);&#xA;    float lambda_v = sqrt(a2 + (1.0 - a2) * ndotv * ndotv);&#xA;&#xA;    return (2.0 * ndotl * ndotv) / (ndotv * lambda_l + ndotl * lambda_v);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Which explains the UE4 approach, as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 F = F_Schlick(F0, ldoth);&#xA;float G = G_Smith_GGX(ndotl, ndotv, roughness);&#xA;&#xA;// PDF = (D(h) * dot(n, h)) / (4 * dot(v, h))&#xA;return (F * G * vdoth) / (ndotv * ndoth + EPSILON);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;See &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; for the derivation.&lt;/p&gt;&#xA;" OwnerUserId="11811" LastEditorUserId="11811" LastEditDate="2020-02-27T11:35:18.773" LastActivityDate="2020-02-27T11:35:18.773" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9542" PostTypeId="2" ParentId="9384" CreationDate="2020-02-03T17:04:47.317" Score="3" Body="&lt;p&gt;Here you have a full repository with a lot of papers about light transport. There's also a folder named 'theory' where you can get both intro and advanced refs regard light physics. And much more. I'm personally curating this and keeping up to date with latest advancements. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://drive.google.com/drive/folders/16A6Yj2esRTk0FP-ALr6XfxkGQvTb_1dD?usp=sharing&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://drive.google.com/drive/folders/16A6Yj2esRTk0FP-ALr6XfxkGQvTb_1dD?usp=sharing&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However here are the main books/papers I suggest to read :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1985 - Physically Based Lighting Calculations For Computer Graphics&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1986 - The Rendering Equation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1997 - A Framework for Realistic Image Synthesis&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1997 - Robust MonteCarlo Methods For Light Transport Simulation&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2011 - The State of the Art in Interactive Global Illumination&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2014 - The Path to Path-Traced Movies&lt;/p&gt;&#xA;" OwnerUserId="6114" LastEditorUserId="6114" LastEditDate="2020-04-23T21:52:18.183" LastActivityDate="2020-04-23T21:52:18.183" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9543" PostTypeId="2" ParentId="9533" CreationDate="2020-02-03T19:24:32.273" Score="3" Body="&lt;p&gt;Here is how I found this can be solved.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(The below also happens at the start, just fyi)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;  float tmin = std::numeric_limits&amp;lt;float&amp;gt;::lowest();&#xA;  float tmax = std::numeric_limits&amp;lt;float&amp;gt;::max();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Add an additional check:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;if(rayDir.x == 0.0f)&#xA;{&#xA;  if (rayOrigin.x() &amp;lt; box.min.x() || rayOrigin.x() &amp;gt; box.max.x())&#xA;  {     &#xA;    return false;&#xA;  }&#xA;}&#xA;else &#xA;{&#xA;  tx1 = (box.min.x - rayOrigin.x) * invRay.x;&#xA;  tx2 = (box.max.x - rayOrigin.x) * invRay.x;&#xA;&#xA;  tmin = std::max(tmin, std::min(tx1, tx2));&#xA;  tmax = std::min(tmax, std::max(tx1, tx2));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This way the tx1/tx2 values never get calculated if the ray's direction vector is zero in that direction, aka if it's parallel to that plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's not particularly compact or pretty, but it does neatly solve the issue.&lt;/p&gt;&#xA;" OwnerUserId="11282" LastActivityDate="2020-02-03T19:24:32.273" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9544" PostTypeId="1" AcceptedAnswerId="9565" CreationDate="2020-02-04T01:53:07.500" Score="2" ViewCount="74" Body="&lt;p&gt;Assume we have a mesh represented as a half edge datastructure.&lt;/p&gt;&#xA;&lt;p&gt;We want to subdivide faces without introducing unnecessary vertices (i.e the new number of vertices must be exactly V + E where V is the old number of vertices and E is the old number of edges).&lt;/p&gt;&#xA;&lt;p&gt;This is what a single subdivided triangle looks like:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/MYmhk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MYmhk.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If I naively try to iterate over every edge and reconnect faces I get the following sequence&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Jgn94.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Jgn94.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/D4SZe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/D4SZe.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/04SMi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/04SMi.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Clearly this is wrong.&lt;/p&gt;&#xA;&lt;p&gt;If instead I iterate over the faces I get the following pattern:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vWp6b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vWp6b.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is happening because at every step I am trying to to:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Focus on only one simplex at a time,&lt;/li&gt;&#xA;&lt;li&gt;Maintain the connectivity information of the mesh in a valid state (every edge has &amp;lt;2 faces, vertices only exist at the end of edges, faces only have 3 Half edges...), like for example, I am avoiding getting into this state:&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4SexY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4SexY.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Any suggestions?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-02-13T02:37:45.817" Title="How to subdivide faces with a half edge DS?" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9545" PostTypeId="2" ParentId="9539" CreationDate="2020-02-04T06:06:29.833" Score="4" Body="&lt;p&gt;Array textures do not contain textures; they are a single texture that contains a number of images, with each image being of the same size, format, mipmap depth, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As such, the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Texture#Texture_Objects&quot; rel=&quot;nofollow noreferrer&quot;&gt;sampling parameters that are part of the texture&lt;/a&gt; apply to sample fetches for all images within the texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That having been said:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In the shader I perform a manual GL_NEAREST lookup via textureFetch().&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This means your FS knows when to look the texture up with linear filtering and when not to. As such, you could have two different array texture samplers in the shader, one of which you expect to use linear sampling and one which uses nearest.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both of these samplers can be using the same texture object, just paired with a different &lt;em&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Sampler_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;sampler object&lt;/a&gt;&lt;/em&gt; (which contains all of the filtering parameters for the texture). One sampler would use nearest filtering, the other would use linear.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-02-04T06:06:29.833" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9546" PostTypeId="1" CreationDate="2020-02-04T14:51:10.570" Score="0" ViewCount="17" Body="&lt;p&gt;I am confronted with the problem to render 3D representations for objects marked on microscope slices.&#xA;So I have a set of aligned polygons in parallel planes from tracing the outline of the object in the slices. I want to turn this into a 3d mesh of an approximate surface of the object.&#xA;The curves can have vastly different point density per curve length and overall number of points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that there is not a unique solution, but I wonder if there is a fast algorithm to find A solution that looks reasonable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, this also has to be solved in MATLAB. Not expecting MATLAB code of course, I just want to say that use function X in Y, Y not being MATLAB, is not extremely helpful.&lt;/p&gt;&#xA;" OwnerUserId="9309" LastActivityDate="2020-02-04T14:51:10.570" Title="Turning layered curves to polygon mesh?" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;polygon&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9547" PostTypeId="1" CreationDate="2020-02-04T18:15:21.247" Score="0" ViewCount="275" Body="&lt;p&gt;Rendering is the process of computing a three-dimensional geometric description of a scene into a two-dimensional image representation that looks real. Ray-tracing and Radiosity are two of the most famous rendering techniques for photo realistic images, right?  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So which technique is suitable for rendering ten under-water images of marine creatures showing total internal reflection needed by ABC Marine Department. The department needs the images to be more natural and can wait for image generation for a month.&lt;/p&gt;&#xA;" OwnerUserId="11842" LastEditorUserId="11652" LastEditDate="2020-02-13T11:44:16.017" LastActivityDate="2020-02-13T11:44:16.017" Title="Which technique should be used for rendering under water images, Ray tracing or Radiosity?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;reflection&gt;&lt;radiosity&gt;&lt;render&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9548" PostTypeId="2" ParentId="9510" CreationDate="2020-02-06T06:21:38.517" Score="1" Body="&lt;p&gt;What about Division or subdivision? &lt;/p&gt;&#xA;" OwnerUserId="11739" LastActivityDate="2020-02-06T06:21:38.517" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9549" PostTypeId="1" CreationDate="2020-02-06T09:48:53.650" Score="1" ViewCount="144" Body="&lt;p&gt;I am not sure if this is the correct SE to ask this question. However, lets say I have been given 3D models of several enclosed spaces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to populate spaces with, lets say, planes flying through them, taking the optimum route from A to B. Since there are many of them, I want to write an algorithm that does this; I already have the 3D models of the planes. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am looking for resources I can use to learn how to do define the boundary conditions for the opimization algorithm given the 3D model. &lt;/p&gt;&#xA;" OwnerUserId="11850" LastEditorUserId="11850" LastEditDate="2020-02-06T16:23:41.580" LastActivityDate="2021-04-15T12:48:41.857" Title="Defining &quot;inside&quot; and &quot;outside&quot; of a 3D space" Tags="&lt;3d&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9550" PostTypeId="2" ParentId="9323" CreationDate="2020-02-06T09:56:00.587" Score="2" Body="&lt;p&gt;Besides the suggestions in comments, I would suggest a high pass filtering to get rid of the low frequency noise, before running your local thresholding. Here an example with GIMP, that you can probably easily reproduce with opencv as well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YPJ4s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YPJ4s.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11851" LastActivityDate="2020-02-06T09:56:00.587" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9551" PostTypeId="1" AcceptedAnswerId="9559" CreationDate="2020-02-06T12:44:25.517" Score="0" ViewCount="120" Body="&lt;p&gt;Is just read about image-dithering ? So I tried to implement that. Here is my result. Can someone verify it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/maifeeulasad/dithering-cg/blob/master/python/render.py&quot; rel=&quot;nofollow noreferrer&quot;&gt;My code&lt;/a&gt; :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;from numpy.random import default_rng&#xA;import matplotlib.pyplot as plt&#xA;&#xA;n = 300&#xA;real = np.random.randint(low = 0, high=256, size=(n,n), dtype='l')&#xA;#print(real)&#xA;&#xA;dn = 3&#xA;rng = default_rng()&#xA;dither = rng.choice(dn*dn, size=(dn,dn), replace=False)&#xA;print(dither)&#xA;&#xA;res = np.zeros((n,n))&#xA;for y in range (0,n):&#xA;    for x in range (0,n):&#xA;        i = x % dn&#xA;        j = y % dn&#xA;        res[x][y] = 255 if (real[x][y] &amp;gt; dither[i][j]) else 0&#xA;#print(res)&#xA;&#xA;&#xA;fig = plt.figure()&#xA;&#xA;ax1 = plt.subplot(1, 3, 1)&#xA;ax1.title.set_text('Real Image(300x300)')&#xA;plt.imshow(real, cmap=&quot;gray&quot;)&#xA;&#xA;ax2 = plt.subplot(1, 3, 2)&#xA;ax2.title.set_text('Dithering Matrix(3x3)')&#xA;plt.imshow(dither, cmap=&quot;gray&quot;)&#xA;&#xA;ax3 = plt.subplot(1, 3, 3)&#xA;ax3.title.set_text('Resultant Image(300x300)')&#xA;plt.imshow(res, cmap=&quot;gray&quot;)&#xA;&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;reduced value of  n to 6, so that image may become easily understandable.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Result :&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kOxfb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kOxfb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11853" LastActivityDate="2020-02-08T20:20:03.823" Title="basic of image dithering" Tags="&lt;image&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9553" PostTypeId="1" CreationDate="2020-02-06T17:47:36.223" Score="1" ViewCount="52" Body="&lt;p&gt;I'm trying to implement the derivation of the masking function G_1 by Smith.&#xA;The appendix of Walter et al &lt;a href=&quot;https://www.cs.cornell.edu/~srm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;1&lt;/a&gt;, Hammons presentation &lt;a href=&quot;https://twvideo01.ubm-us.net/o1/vault/gdc2017/Presentations/Hammon_Earl_PBR_Diffuse_Lighting.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;2&lt;/a&gt; and this research paper &lt;a href=&quot;https://docs.chaosgroup.com/display/RESEARCH/Deriving+the+Smith+shadowing+function+for+the+GTR+BRDF&quot; rel=&quot;nofollow noreferrer&quot;&gt;3&lt;/a&gt; talk in detail about it and I feel as I do understand the majority of the math behind it. But when it comes to turning this into code I cannot seem to get it right.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some of my questions entail:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the first integral from minus infinity to infinity over &lt;em&gt;P22(p, q)&lt;/em&gt;, the way I understand it I can simply iterate over all of my microfacets and use the previous formular (&lt;em&gt;P22(p, q) = D(&lt;strong&gt;m&lt;/strong&gt;) cos^4(theta_m)&lt;/em&gt;) and add them together for a riemann sum?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I understand is mu (&lt;em&gt;= |cot(theta_v)|&lt;/em&gt;) the slope of the view vector and when using an integral from mu to infinity the goal is to decrease te angle of theta_v until it is zero?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I naivly implemented it is as an nested loop of two riemann sums that aim to describe the two integrals. In pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;calculate mu from view angle&#xA;Aux = 0.0;&#xA;//for loop uses calculation of the angle theta_v to decide termination of loop&#xA;for(float q = mu; angleof(q) &amp;gt; 0.0001f; q += dq)&#xA;{&#xA;   float P2 = 0.0;&#xA;   for(iterate through all maicrofacets)&#xA;   {&#xA;      calulate theta of current microfacet&#xA;      calculate cos^4(theta)&#xA;      get D of current microfacet&#xA;&#xA;      P2 += D * cos^4(theta) * dp;&#xA;   }&#xA;   Aux += (q - mu) * P2 * dq;&#xA;}&#xA;&#xA;Aux *= 1.0 / mu;&#xA;return 1.0 / (1.0 + Aux)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I write in C++ but I would be very happy with any kind of code or hint as to how to solve this.&lt;/p&gt;&#xA;" OwnerUserId="11598" LastActivityDate="2020-02-06T17:47:36.223" Title="Implementing the derivation of the Smith Shadowing function for arbitrary distributions" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;microfacet&gt;&lt;masking&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9554" PostTypeId="1" CreationDate="2020-02-07T03:24:54.147" Score="0" ViewCount="68" Body="&lt;p&gt;I am trying to perform quad-based tessellation using GLSL on Unity to be able to render polynomial-based parametric surfaces on a Unity quad. The quad-based tessellation using GLSL seems to be incorrectly choosing the vertices for the patch to be tessellated. I am using this shader (&lt;a href=&quot;https://github.com/przemyslawzaworski/Unity3D-CG-programming/blob/master/GLSL/tessellation.shader&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/przemyslawzaworski/Unity3D-CG-programming/blob/master/GLSL/tessellation.shader&lt;/a&gt;) as a reference. However, modifying it to use quads in the domain shader stage messes up the ordering. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Shader &quot;Custom/Tessellation&quot;&#xA;{&#xA;    Properties&#xA;    {&#xA;        _MainTex (&quot;Texture&quot;, 2D) = &quot;white&quot; {}&#xA;        _factor(&quot;Tessellation scale&quot;,Range(1.0,64.0)) = 1.0&#xA;    }&#xA;    SubShader&#xA;    {&#xA;        Cull Off&#xA;        Pass&#xA;        {&#xA;            GLSLPROGRAM&#xA;            #version 460     &#xA;            uniform float _factor;&#xA;&#xA;            #ifdef VERTEX&#xA;                in  vec4 in_POSITION0;&#xA;                void main()&#xA;                {&#xA;                    gl_Position =  gl_ModelViewProjectionMatrix * in_POSITION0;&#xA;                }&#xA;            #endif&#xA;&#xA;            #ifdef HULL          //GLSL Tessellation Control Shader&#xA;&#xA;                layout (vertices = 4) out;&#xA;                void main()&#xA;                {&#xA;                    if (gl_InvocationID == 0)&#xA;                    {&#xA;                        gl_TessLevelInner[0] = _factor;   //Inside tessellation factor&#xA;                        gl_TessLevelInner[1] = _factor;   //Inside tessellation factor&#xA;&#xA;                        gl_TessLevelOuter[0] = _factor;   //Edge tessellation factor&#xA;                        gl_TessLevelOuter[1] = _factor;   //Edge tessellation factor&#xA;                        gl_TessLevelOuter[2] = _factor;   //Edge tessellation factor&#xA;                        gl_TessLevelOuter[3] = _factor;   //Edge tessellation factor&#xA;                    } &#xA;                    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;&#xA;                }&#xA;            #endif&#xA;&#xA;            #ifdef DOMAIN        //GLSL Tessellation Evaluation Shader&#xA;                layout (quads) in;&#xA;                void main()&#xA;                {   &#xA;                    vec4 p1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_TessCoord.x);&#xA;                    vec4 p2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, gl_TessCoord.x);&#xA;                    gl_Position = mix(p1, p2, gl_TessCoord.y);      &#xA;                }&#xA;            #endif&#xA;&#xA;            #ifdef GEOMETRY      //geometry shader for rendering wireframe&#xA;                layout(triangles) in;&#xA;                layout(line_strip, max_vertices = 3) out;&#xA;                void main()&#xA;                {&#xA;                    for(int i = 0; i &amp;lt; gl_in.length(); ++i)&#xA;                    {&#xA;                        gl_Position = gl_in[i].gl_Position;&#xA;                        EmitVertex();&#xA;                    }&#xA;                    gl_Position = gl_in[0].gl_Position;&#xA;                    EmitVertex();  &#xA;                    EndPrimitive();&#xA;                }    &#xA;            #endif&#xA;&#xA;            #ifdef FRAGMENT&#xA;                out vec4 color;&#xA;                void main()&#xA;                {&#xA;                    color = vec4(1,1,1,1);&#xA;                }&#xA;            #endif&#xA;&#xA;            ENDGLSL&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Please help me in identifying what modifications are incorrect. I would appreciate any and all the help. The following are the outputs both from the triangle-based shader as given in the link to the Github page above, and the quad-based shader with modifications for quads made by me. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/m8Cnk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/m8Cnk.png&quot; alt=&quot;Triangle-based Tessellation Working Properly&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KUUKV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KUUKV.png&quot; alt=&quot;Quad-based Tessellation Generating Incorrect Results&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11858" LastEditorUserId="6" LastEditDate="2020-02-07T09:58:18.840" LastActivityDate="2020-02-07T09:58:18.840" Title="Problem with Quad-based Tessellation in GLSL generating incorrect vertex ordered tessellation" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;unity&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9555" PostTypeId="1" CreationDate="2020-02-07T12:51:12.153" Score="1" ViewCount="39" Body="&lt;p&gt;I'm writing a path tracer and I have a problem with ray-triangle intersection tests. The problem happens most frequently with materials that implement random scattering of the ray. Here's a function that generates random vector on a unit hemisphere that's oriented along axis of normal vector:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-golang prettyprint-override&quot;&gt;&lt;code&gt;func RandInUnitHemisphere(generator rand.Rand, normal Tuple) Tuple {&#xA;    p := Tuple{0, 0, 0, 0}&#xA;    for {&#xA;        p = (Tuple{RandFloat(generator), RandFloat(generator), RandFloat(generator), 1}.Subtract(Tuple{0.5, 0.5, 0.5, 0})).MulScalar(2.0)&#xA;        if p.Dot(normal)/(p.Magnitude()*normal.Magnitude()) &amp;gt;= 0.0 {&#xA;            break&#xA;        }&#xA;    }&#xA;    return p&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;When a ray intersects part of a model where there's a cavity or a concave edge, it sometimes ends up in the model, like here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hO1RG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hO1RG.png&quot; alt=&quot;bunny with light sphere inside&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I placed a very bright sphere (RGB: 500,500,500) inside of the bunny. Bunny's material has a two-layer surface, top is for specular highlights and bottom is lambertian. When the ray scatters randomly that its direction is to the inside of the model, it goes inside, instead of bouncing off. The problem isn't visible when there's no emissive objects inside of the model, because I assume the color of bounce inside of the model gets averaged out. Obviously, I don't want to leave it this way. How could I fix it?&lt;/p&gt;&#xA;" OwnerUserId="11862" LastActivityDate="2020-02-07T12:51:12.153" Title="How do I fix skipping ray-triangle intersections on concave edges/cavities of model?" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9556" PostTypeId="1" CreationDate="2020-02-07T18:37:22.823" Score="0" ViewCount="323" Body="&lt;p&gt;In the godot game engine (using opengl) it is not possible to define custom shader attributes.&lt;br&gt;&#xA;A workaround is creating a sampler2D texture uniform instead and use vertexId (or in fact UV since vertexID also isn't exposed) to get the per vertex attributes.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am wondering are there any downsides to this approach and/or caveats one should keep in mind ?&lt;/p&gt;&#xA;" OwnerUserId="1865" LastActivityDate="2020-10-01T15:10:46.277" Title="Shader sampler2D uniforms instead of attributes" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9557" PostTypeId="2" ParentId="9547" CreationDate="2020-02-08T17:26:16.743" Score="6" Body="&lt;p&gt;Radiosity is only efficient for diffuse to diffuse rendering. Path tracing is more versatile on the type of light transport that could be computed. The main issue with underwater rendering is the caustics generated from specular from the water-air interface. These caustics are very important to generate a realistic underwater image (except for deepwater rendering here the sunlight is completely attenuated).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem of rendering caustics from path tracing is the lack of non-efficient sampling strategies to generate a valid path. Density estimation [1] (a.k.a. photon mapping) could be a good candidate for rendering these difficult caustics, but a large scene will require light subpaths guiding to get a reasonable rendering time. Metropolis light transport (MLT) [2,3] provide this guiding automatically and could be used in a density estimation framework [4].&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Recently, path guiding techniques [5,6] was proposed to render these difficult paths efficiently with unidirectional path tracing. The simplest approach to use/implement is the technique proposed by Muller et al. [5]. A Mitsuba code plugin is available on GitHub: &lt;a href=&quot;https://github.com/Tom94/practical-path-guiding&quot; rel=&quot;noreferrer&quot;&gt;https://github.com/Tom94/practical-path-guiding&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that, inside water, there might are volume scattering events [7] to take into account, depending on the amount of particle floating. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;[1] &quot;Stochastic progressive photon mapping&quot; Hachisuka et al., 2009&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[2] &quot;Metropolis light transport&quot; Veach et al. 1997 &lt;/p&gt;&#xA;&#xA;&lt;p&gt;[3] &quot;Primary sample space MLT&quot; Kelemen et al. 2002&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[4] &quot;Robust Adaptive Photon Tracing using Photon Path Visibility&quot;, Hachisuka et al., 2011&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[5] &quot;Practical path guiding for efficient light-transport simulation&quot;, Muller et al. 2017&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[6] &quot;On-line Learning of Parametric Mixture Models for Light Transport Simulation&quot;, Vorba et al. 2014&lt;/p&gt;&#xA;&#xA;&lt;p&gt;[7] &quot;Monte Carlo Methods for Physically Based Volume Rendering&quot;, Novak et al., 2018&lt;/p&gt;&#xA;" OwnerUserId="11702" LastActivityDate="2020-02-08T17:26:16.743" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9558" PostTypeId="1" AcceptedAnswerId="9563" CreationDate="2020-02-08T19:26:04.620" Score="2" ViewCount="108" Body="&lt;p&gt;Be it chaikin subdivision, loop subdivision, catmull-clark subdivision...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do people come up with the coefficients for an arbitrary subdivision scheme?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-02-19T18:28:51.727" LastActivityDate="2020-02-19T18:28:51.727" Title="How do people come up with subdivision schemes?" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;curve&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9559" PostTypeId="2" ParentId="9551" CreationDate="2020-02-08T20:20:03.823" Score="1" Body="&lt;p&gt;There is a small issue in the original code. Indeed, real array values ranging between [0, 255]. However, the mask values ranging between [0, 3*3] (as dn = 3 in the example above).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After fixing the issue:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/KUBRK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KUBRK.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The correct code (with image reading and all data normalized between [0, 1.0]):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;from numpy.random import default_rng&#xA;import matplotlib.pyplot as plt&#xA;from PIL import Image&#xA;&#xA;# Read an image from the disk&#xA;real = Image.open(&quot;example.jpeg&quot;)&#xA;real = np.array(real) / 255.0&#xA;# If it is a RGB image, transform it to a gray image&#xA;# TODO: Could use any function (like luminance)&#xA;real = (real[:,:,0] + real[:,:,1] + real[:,:,2]) / 3.0&#xA;&#xA;# Create the mask by shuffling&#xA;dn = 6&#xA;rng = default_rng()&#xA;# In the original code, there was a problem here.&#xA;# Indeed, the mask values ranging between [0, dn*dn]&#xA;# So the generated mask needs to be properly normalized&#xA;dither = rng.choice(dn*dn, size=(dn,dn), replace=False) / float(dn*dn)&#xA;print(dither)&#xA;&#xA;# Generate the results&#xA;res = np.zeros_like(real)&#xA;width, height = res.shape[1], res.shape[0]&#xA;for y in range (0,width):&#xA;    for x in range (0,height):&#xA;        i = x % dn&#xA;        j = y % dn&#xA;        res[x][y] = 1.0 if (real[x][y] &amp;gt; dither[i][j]) else 0.0&#xA;&#xA;# Display the result&#xA;fig = plt.figure()&#xA;ax1 = plt.subplot(1, 3, 1)&#xA;ax1.title.set_text('Real Image(300x300)')&#xA;plt.imshow(real, cmap=&quot;gray&quot;)&#xA;ax2 = plt.subplot(1, 3, 2)&#xA;ax2.title.set_text('Dithering Matrix(3x3)')&#xA;plt.imshow(dither, cmap=&quot;gray&quot;)&#xA;ax3 = plt.subplot(1, 3, 3)&#xA;ax3.title.set_text('Resultant Image(300x300)')&#xA;plt.imshow(res, cmap=&quot;gray&quot;)&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11702" LastActivityDate="2020-02-08T20:20:03.823" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9562" PostTypeId="1" CreationDate="2020-02-10T06:07:27.530" Score="0" ViewCount="47" Body="&lt;p&gt;I'm reading a graphics book and it talks about BRDFs being the ratio between differential outgoing radiance and differential irradiance. The formula it gives is &#xA;f(l, v) = dL(v)/dE(l)&#xA;Where l is the light vector and v is the outgoing direction vector, and L is outgoing radiance and E is incoming irradiance. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But then the book says that for non area lights like directional and point lights, the BRDF can be expressed without differentials:&#xA;f(l, v) = L(v) / E(l). &#xA;How is this possible? The first formula seems to be a derivative, how do we get to this formula? What is the difference between non area and area lights that would allow us to arrive at this simplification? &lt;/p&gt;&#xA;" OwnerUserId="11871" LastActivityDate="2020-02-10T06:07:27.530" Title="Formula for non area light BRDFs" Tags="&lt;lighting&gt;&lt;brdf&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9563" PostTypeId="2" ParentId="9558" CreationDate="2020-02-10T13:54:04.123" Score="6" Body="&lt;p&gt;The subdivision schemes are not arbitrary. Catmull-Clark, arguably the most used subdivision scheme, generalizes bicubic B-splines to meshes of arbitrary topology. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most, other subdivision schemes also generalize other degree B-splines to arbitrary topology. Doo-Sabin for biquadratic B-splines and Loop subdivision generalizes quartic box-splines defined over regular triangulations.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Most of the coefficients for subdivision are obtained by looking at &lt;a href=&quot;https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/single-insertion.html&quot; rel=&quot;noreferrer&quot;&gt;knot-insertion&lt;/a&gt;. Knot-insertion is the process of adding knots into B-splines such that the same curve is obtained by expressing it as more curve pieces, i.e. subdividing the original curves. The rules for subdivision and thus the coefficients are derived from these algorithms. However, these rules only hold for the regular regions of the control mesh. For the irregular regions the rules are generalized, such that they give a satisfactory result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way to look at it is through subdivision stencils and masks. The simplest subdivision stencil &lt;span class=&quot;math-container&quot;&gt;$[1,1]$&lt;/span&gt; applied to the control polygon with points &lt;span class=&quot;math-container&quot;&gt;$P_i, \ldots, P_N$&lt;/span&gt; will generate new points &lt;span class=&quot;math-container&quot;&gt;$Q_i = P_i$&lt;/span&gt;, will simply insert points at the same positions as the original points. &#xA;We can convolve the stencil with itself &lt;span class=&quot;math-container&quot;&gt;$[1,1] * [1,1] = [1,2,1]$&lt;/span&gt;. We can decompose this stencil into an even [1,1] and an odd mask [2] and again apply it to the control polygon by multiplying the coefficients in the mask and dividing by the sum of coefficients. The odd mask &lt;span class=&quot;math-container&quot;&gt;$Q_{i*2} = 2 P_i / 2$&lt;/span&gt; will keep the original points, but the even mask will generate points &lt;span class=&quot;math-container&quot;&gt;$Q_{i*2+1} = (1 P_i + 1 P_{i+1})/2$&lt;/span&gt; half-way between points. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Continuing the convolution process to the second stencil &lt;span class=&quot;math-container&quot;&gt;$[1,2,1] * [1,1] = [1, 3, 3, 1]$&lt;/span&gt; will generate odd &lt;span class=&quot;math-container&quot;&gt;$[1, 3]$&lt;/span&gt; and even &lt;span class=&quot;math-container&quot;&gt;$[3,1]$&lt;/span&gt; masks which will generate points one quarter and three quarters along the line piece between points &lt;span class=&quot;math-container&quot;&gt;$P_i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$P_{i+1}$&lt;/span&gt;. This are of course the exact coefficients used in Chaikin's corner cutting algorithm, which in the limit of subdivision will generate quadratic B-splines. Applying it again &lt;span class=&quot;math-container&quot;&gt;$[1,3, 3,1] * [1,1] = [1, 4, 6, 4, 1]$&lt;/span&gt; will generate the stencils that generate cubic B-splines. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To generalize this again to surfaces we can apply this convolution process in two parametric directions to obtain bi-degree B-splines. In the cubic case we obtain this matrix of coefficients through convolution:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}1 &amp;amp; 4 &amp;amp; 6 &amp;amp; 4 &amp;amp; 1\\&#xA;                4 &amp;amp; 16 &amp;amp; 24 &amp;amp; 16 &amp;amp; 4\\&#xA;                6 &amp;amp; 24 &amp;amp; 36 &amp;amp; 24 &amp;amp; 6\\&#xA;                4 &amp;amp; 16 &amp;amp; 24 &amp;amp; 16 &amp;amp; 4\\&#xA;                1 &amp;amp; 4 &amp;amp; 6 &amp;amp; 4 &amp;amp; 1\\ \end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We can decompose this matrix into vertex mask:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}1 &amp;amp;  6 &amp;amp; 1\\&#xA;                6 &amp;amp; 36 &amp;amp; 6\\&#xA;                1 &amp;amp;  6 &amp;amp; 1\\ \end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;edge point mask:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}4 &amp;amp;  24 &amp;amp; 4\\ 4 &amp;amp; 24 &amp;amp; 4\\ \end{bmatrix}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}4 &amp;amp; 4\\ 24 &amp;amp; 24\\ 4 &amp;amp; 4\\ \end{bmatrix}$&lt;/span&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;face point mask:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\begin{bmatrix}&#xA;16 &amp;amp; 16 \\&#xA;16 &amp;amp; 16 \\&#xA;\end{bmatrix}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying these as control point masks to a regular control grid will obtain bicubic B-splines. The observation made for the Catmull-Clark algorithm is that the inserted points through the face stencils are the average of the surrounding vertices. This can easily be generalized for arbitrary polygons, the same thing goes for the edge stencil. The hard case is the vertex stencil as the original is only valid for vertices with valency 4. Catmull-Clark came up with this expression&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{Q}{N} + \frac{2R}{N} + \frac{S(N-3)}{N}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$S$&lt;/span&gt; is the old vertex position &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; is the average of the points created by the edge mask for the outgoing edges of the vertex and &lt;span class=&quot;math-container&quot;&gt;$Q$&lt;/span&gt; the average of the points created by face mask for the surrounding faces. The ratios in this expression are such that it reproduces the regular vertex mask in the case &lt;span class=&quot;math-container&quot;&gt;$N=4$&lt;/span&gt; and is aesthetically pleasing for other &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2020-02-10T14:15:13.270" LastActivityDate="2020-02-10T14:15:13.270" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9565" PostTypeId="2" ParentId="9544" CreationDate="2020-02-13T02:37:45.817" Score="1" Body="&lt;p&gt;No one answered so I will. The solution is to do the subdivision in 2 passes, first generating new triangles as I showed in the question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then on the second pass you flip them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/75X6y.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/75X6y.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As described there:&#xA;&lt;a href=&quot;https://github.com/cmu462/Scotty3D/wiki/Loop-Subdivision&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/cmu462/Scotty3D/wiki/Loop-Subdivision&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-02-13T02:37:45.817" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9566" PostTypeId="1" AcceptedAnswerId="9567" CreationDate="2020-02-13T02:47:45.957" Score="1" ViewCount="191" Body="&lt;p&gt;Ok so let's say we have a portion of a mesh that looks somewhat like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Tk5F4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Tk5F4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A triangle fan with one of the triangles removed. If that triangles was not removed, we could get all the edges adjacent to that vertex this way:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;std::vector&amp;lt;GraphEdgePtr&amp;gt; GraphVertex::GetVertexEdges()&#xA;{&#xA;    std::vector&amp;lt;GraphEdgePtr&amp;gt; edges;&#xA;    auto current_edge = edge;&#xA;    do&#xA;    {&#xA;        edges.push_back(current_edge);&#xA;        current_edge = current_edge-&amp;gt;pair-&amp;gt;next;&#xA;    } while(current_edge != edges[0]);&#xA;&#xA;    return edges;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However, if the triangle is removed, the above will segfault. One could create an additional loop that iterates backwards from the starting edge in the case the first loop finds a null pointer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However that is a bit inelegant in my opinion. Is there a way to do it in a single loop? Using a stack or a queue or some sort for example?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-02-13T13:03:19.510" Title="How to handle Half edge boundary edge iteration from vertex?" Tags="&lt;algorithm&gt;&lt;c++&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9567" PostTypeId="2" ParentId="9566" CreationDate="2020-02-13T13:03:19.510" Score="2" Body="&lt;p&gt;It depends a little on your actual data structure and how it even encodes boundary edges. What I find more useful than representing the boundary with a null half edge pointer, and thus having this situation of a half edge without an opposite and thus a hard stop for any such iteration, is instead &lt;strong&gt;encoding the boundary with a full half edge pair too, but with one of the half edges having a null &lt;em&gt;face&lt;/em&gt; pointer&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the boundary edge actually does have an opposite (or &lt;code&gt;pair&lt;/code&gt; pointer) and that opposite is fully integrated into the pointer structure, complete with &lt;code&gt;next&lt;/code&gt; pointer and everything. Just that its face pointer in null, thus denoting an empty face or hole. So basically &lt;strong&gt;every hole is represented by a null face with half edges going around it&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In addition to being able to iterate around vertices regardless of the starting point, this also has the advantage that you can easily iterate around boundary curves. And you can even have more than one hole at a vertex (although, that can still be problematic in other situations). Of course you might still have to handle the boundary half edges specially in some situations, especially when you're using the face pointers, but you won't get around that anyway if your mesh can have holes.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;If that is too much of a hassle to restructure your data and algorithms this way, though, maybe you can instead adjust your &lt;strong&gt;vertex starting edge pointers to always point to the boundary edge&lt;/strong&gt; if there is one. You'd of course have to make sure that stays consistent, but if you can assume that as a precondition, you can just start iterating from there. And you can also check immediately if the vertex is at a boundary without having to iterate.&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2020-02-13T13:03:19.510" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9568" PostTypeId="2" ParentId="9549" CreationDate="2020-02-14T10:39:21.973" Score="0" Body="&lt;p&gt;As no one else seems to want to suggest something, given that you said you wanted to navigate within an arbitrary enclosed volume, perhaps you could use an approach similar to that of the 1995 game &lt;a href=&quot;https://en.wikipedia.org/wiki/Descent_(video_game)&quot; rel=&quot;nofollow noreferrer&quot;&gt;Descent&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;IIRC the world model of the 'mine' the spacecraft and enemy robots navigated was made up of &quot;cuboid&quot; units/voxels that pieced seamlessly together, &lt;em&gt;some&lt;/em&gt; of which had solid walls that then formed the boundaries of the enclosing volume. The source code is freely available online &lt;a href=&quot;https://archive.org/details/Descent_source&quot; rel=&quot;nofollow noreferrer&quot;&gt;e.g. here &lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If, in the likely scenario you can't force the enclosing volume to have quadrilateral facets, you might want to consider &quot;tetrahedral&quot; volumes.&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-02-18T08:10:53.970" LastActivityDate="2020-02-18T08:10:53.970" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9570" PostTypeId="2" ParentId="9496" CreationDate="2020-02-15T10:14:56.777" Score="1" Body="&lt;p&gt;Let's talk about linear geometric transformations in homogeneous coordinates.  In your question there are mainly two kind of geometric transformations involved: planar rotation and planar scaling, the computation-friendly analytical re-definitions of which are found here&lt;a href=&quot;https://arxiv.org/abs/1307.0998&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unified frameworks of elementary geometric transformations&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The 2D homogenous rotation matrix that rotates 2D objects clockwise by &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; radians is as below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$R=\left[&#xA;\begin{array}{ccc}&#xA; \cos \theta &amp;amp; \sin \theta&amp;amp; 0 \\&#xA; -\sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A 2D scaling due to unequal aspect ratio &lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt; in this case is a stereohomology with &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; axis &lt;span class=&quot;math-container&quot;&gt;$(0,1,0)^T$&lt;/span&gt; as the stereohomology interface (a line of invariant points), and the normal direction &lt;span class=&quot;math-container&quot;&gt;$(0,1,0)^T$&lt;/span&gt; as its stereohomology center per definition 3.9 in page 12 and line No. 5 in Table 1, page 9 of the article &lt;a href=&quot;https://arxiv.org/abs/1307.0998&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unified frameworks of elementary geometric transformations&lt;/a&gt;. Then its scaling matrix can be obtained as below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$S=\color{gray}{\left[&#xA;\begin{array}{ccc}&#xA; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]+\left(\rho-1\right)\dfrac{\left[&#xA;\begin{array}{c}&#xA; 0 \\&#xA; 1 \\&#xA; 0 \\&#xA;\end{array}&#xA;\right]\cdot \left[&#xA;\begin{array}{ccc}&#xA; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;\end{array}&#xA;\right]}{\left[&#xA;\begin{array}{ccc}&#xA; 0 &amp;amp; 1 &amp;amp; 0 \\&#xA;\end{array}&#xA;\right]\cdot \left[&#xA;\begin{array}{c}&#xA; 0 \\&#xA; 1 \\&#xA; 0 \\&#xA;\end{array}&#xA;\right]}=}\left[&#xA;\begin{array}{ccc}&#xA; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA; 0 &amp;amp; \rho  &amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When aspect ratio normally is &lt;span class=&quot;math-container&quot;&gt;$\rho=1$&lt;/span&gt;, suppose under this circumstance the original object has the homogeneous coordinates of &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; points in &lt;span class=&quot;math-container&quot;&gt;$3\times n$&lt;/span&gt; matrix &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt;, and the transformed object in &lt;span class=&quot;math-container&quot;&gt;$3\times n$&lt;/span&gt; matrix &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt;, then the geometric transformation between them is the rotation you have mentioned:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$Y=R\cdot X$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the aspect ratio abnormally is &lt;span class=&quot;math-container&quot;&gt;$\rho\ne 1$&lt;/span&gt;, both &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and the &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; after rotation are as a matter of fact scaled along the &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; axis:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$X'=S\cdot X$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$Y'=S\cdot Y$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you want to find the geometric transformation &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;  which satisfies &lt;span class=&quot;math-container&quot;&gt;$Y'=T\cdot X'$&lt;/span&gt;. Since:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$Y'=S\cdot Y=S\cdot R\cdot X =S\cdot R\cdot S^{-1}\cdot X'$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$T=S\cdot R\cdot S^{-1}$$&lt;/span&gt; &#xA;&lt;span class=&quot;math-container&quot;&gt;$$=\color{gray}{\left[&#xA;\begin{array}{ccc}&#xA; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA; 0 &amp;amp; \rho  &amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]&#xA;\cdot&#xA;\left[&#xA;\begin{array}{ccc}&#xA; \cos \theta &amp;amp; \sin \theta&amp;amp; 0 \\&#xA; -\sin\theta &amp;amp; \cos\theta &amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]\cdot&#xA;\left[&#xA;\begin{array}{ccc}&#xA; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA; 0 &amp;amp; \dfrac{1}\rho  &amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]=}\left[&#xA;\begin{array}{ccc}&#xA; \cos \theta &amp;amp; \dfrac{\sin \theta}{\rho } &amp;amp; 0 \\&#xA; -\rho  \sin\theta &amp;amp; \cos \theta&amp;amp; 0 \\&#xA; 0 &amp;amp; 0 &amp;amp; 1 \\&#xA;\end{array}&#xA;\right]$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is a rotation under the generalized meaning.&lt;/p&gt;&#xA;" OwnerUserId="11893" LastEditorUserId="11893" LastEditDate="2020-02-15T10:22:00.643" LastActivityDate="2020-02-15T10:22:00.643" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9571" PostTypeId="1" AcceptedAnswerId="9573" CreationDate="2020-02-15T13:14:05.210" Score="0" ViewCount="194" Body="&lt;p&gt;How does a CPU know which piece of code should be executed on GPU (i.e how to recognize whether a code is shader or not) and how is it been sent to GPU VRAM?Is it via DMA?&lt;/p&gt;&#xA;" OwnerUserId="11895" LastActivityDate="2020-02-16T12:34:39.370" Title="Sending programs from CPU to GPU" Tags="&lt;shader&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9572" PostTypeId="1" CreationDate="2020-02-16T11:02:51.030" Score="0" ViewCount="40" Body="&lt;p&gt;According to the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Introduction/pbrt_System_Overview.html#IntegratorInterfaceandSamplerIntegrator&quot; rel=&quot;nofollow noreferrer&quot;&gt;description in the book&lt;/a&gt;, &lt;code&gt;Scene::IntersectP()&lt;/code&gt; &quot;checks for the existence of intersections along the [passed] ray&quot;. This operatorion should be symmetric in the sense that if &lt;code&gt;i1&lt;/code&gt; and &lt;code&gt;i2&lt;/code&gt; are &lt;code&gt;pbrt::Interaction&lt;/code&gt;'s, then &lt;code&gt;scene.IntersectP(i1.SpawnRayTo(i2))&lt;/code&gt; should be &lt;code&gt;true&lt;/code&gt; if and only if &lt;code&gt;scene.IntersectP(i2.SpawnRayTo(i1))&lt;/code&gt; is true.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I've encountered the following contradiction to this expectation: For two &lt;code&gt;pbrt::Vertex&lt;/code&gt;'s &lt;code&gt;x1&lt;/code&gt; and &lt;code&gt;x2&lt;/code&gt;, &lt;code&gt;pbrt::VisibilityTester{ x1.GetInteraction(), x2.GetInteraction() }.Unoccluded(scene)&lt;/code&gt; and &lt;code&gt;pbrt::VisibilityTester{ x2.GetInteraction(), x1.GetInteraction() }.Unoccluded(scene)&lt;/code&gt; returned opposite values. Since &lt;code&gt;VisibilityTester::Unoccluded&lt;/code&gt; does nothing else than calling &lt;code&gt;Scene::IntersectP&lt;/code&gt; in the previously described way (see the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Sources/Light_Interface.html#VisibilityTesting&quot; rel=&quot;nofollow noreferrer&quot;&gt;description in the book&lt;/a&gt;), it seems like I'm missing something crucial here.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2020-02-16T11:02:51.030" Title="Is casting a shadow ray non-symmetric in pbrt?" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;global-illumination&gt;&lt;pbr&gt;&lt;pbrt&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9573" PostTypeId="2" ParentId="9571" CreationDate="2020-02-16T12:34:39.370" Score="1" Body="&lt;p&gt;Most, if not all, approaches to GPU programming require the developer to manually identify code that will be executed on the GPU. The code for the GPU is compiled separately from CPU code, so it is clear which binary code is for which processor type. Moving the GPU code to VRAM is often done with DMA, but may be moved to GPU accessible memory using other techniques such as CPU writes across PCIe, or direct CPU memory access by the GPU.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The GPU compiler often resides in userspace, and a system call will hand binary GPU code to the kernel, which can then make the code available to the GPU.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2020-02-16T12:34:39.370" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9574" PostTypeId="1" CreationDate="2020-02-16T16:33:27.773" Score="2" ViewCount="36" Body="&lt;p&gt;Say &lt;span class=&quot;math-container&quot;&gt;$E_j$&lt;/span&gt; is an estimator of the value &lt;span class=&quot;math-container&quot;&gt;$$I_j=\int f_j\:{\rm d}\lambda$$&lt;/span&gt; of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel given by the path space integral of the corresponding measurement contribution function &lt;span class=&quot;math-container&quot;&gt;$f_j$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$f_j$&lt;/span&gt; is of the form &lt;span class=&quot;math-container&quot;&gt;$f_j=h_jf$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; is essentially the image reconstruction filter of the pixel &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; (as described, for example, &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html#ApplicationtoRendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If we want to quantify the &quot;variance&quot; of the estimates &lt;span class=&quot;math-container&quot;&gt;$E_j$&lt;/span&gt; over all pixels &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;, which notion of variance should we consider? Since &lt;span class=&quot;math-container&quot;&gt;$f_j$&lt;/span&gt; is 3-dimensional, the natural choice would be given by the covariance matrix of &lt;span class=&quot;math-container&quot;&gt;$E_j$&lt;/span&gt;. Another option would be to take the variance &lt;span class=&quot;math-container&quot;&gt;$\operatorname{Var}\left[\left\|E_j\right\|^2\right]$&lt;/span&gt; of the squared Euclidean norm &lt;span class=&quot;math-container&quot;&gt;$\left\|E_j\right\|$&lt;/span&gt; of &lt;span class=&quot;math-container&quot;&gt;$E_j$&lt;/span&gt; (which is the trace of the covariance matrix), but this might not contain enough information.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I want to minimize the variances over all &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;, the covariance matrices are too complicated to handle.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;So, my question is: Can we somehow control the supremum of all variances in terms of a scalar-valued variance? Maybe in terms of the luminance?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="9254" LastActivityDate="2020-02-16T16:33:27.773" Title="Quantify the variance of pixel measurements" Tags="&lt;raytracing&gt;&lt;global-illumination&gt;&lt;sampling&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9576" PostTypeId="1" CreationDate="2020-02-17T00:18:29.643" Score="0" ViewCount="57" Body="&lt;p&gt;Ever since I was a small child, seeing the amazing 3D visuals that developed in the 1980s and 1990s, I was certain that photo-realism was &quot;just around the corner&quot;. In the year 2020, I certainly thought it was going to be a standard fact of life.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That never happened.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It's as if not only the technology halted, having taken a giant loap from the SNES to the Nintendo 64 in just a few years, but also the whole mentality of game developers seemed to shift around year 2000. Video games, even simulators, started looking more and more unreal and uninteresting to me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As the resolutions increased, it only became more and more apparent how crude and fake the 3D environments really were. To me, it seems like they tried to make up for this by adding heaps of visual filters on top, giving a thin illusion of &quot;visual eyecandy&quot;. But not realism. Or even something which looks appealing.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Movies started to look more and more like these ugly new video games, and the video games started looking less and less like video games, yet still not anywhere close to reality. They both blended together into &quot;generic CGI&quot; which really does look ugly to my eyes, and very far from &quot;real&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Today, in the year 2020, there isn't a single modern video game you would catch me dead playing. I'd rather watch paint dry or even sports than I'd play or watch somebody else play these modern video games. How can that be? I don't want it to be the case. I want it to be like how I dreamed it would be 20+ years ago. It seemed like video games and simulations would just keep on getting more and more fun and exciting, but they just... died.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, all I see are dead polygon models with nonexistent AI and which are lightyears away from even resembling real-life wax figures. They look nothing like reality, yet don't have the visual appeal of the &quot;early&quot; 3D games and simulations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My dream remains to get to run a program which literally looks like somebody is walking around with a camera in reality. Nothing has ever come close to resembling this, and in fact, we seem to be drifting &lt;em&gt;further away&lt;/em&gt; from it with each year. And I don't mean that extremely limited tech demo I saw a few years ago where they had made one single room in &quot;OK&quot; detail/realism. While slightly cool, it had zero interactivity and the room was too small and uninteresting for it to qualify. Not to mention it had no living entities in it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They don't even seem to be &lt;em&gt;attempting&lt;/em&gt; to make such things. Everything uses these ugly, unreal visuals with a bunch of uninteresting garbage story where they seem to have spent all their budget on voice actors and motion capture, which I couldn't care less about. I want a perfectly recreated realistic environment to explore with zero story/plot/cutscenes. Just me, walking around, in first-person view. It just starts like that, with no menus or settings or cutscenes or logos. I just double-click an EXE on the desktop and BAM! I'm in a 3D world of the size of perhaps a neighbourhood, free to explore it as if I were actually walking around in the real-life location.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I don't care if the resolution is 320 x 240 pixels or 4K. It's become clear to me that the resolution has zero to do with how it looks; an old black-and-white 1920s film camera or a 1980s cheap consumer camera will capture infinitely more realistic visuals than the biggest monster computer in existence today can produce. It has nothing to do with the resolution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What's stopping people with skills and resources from doing this? I know what's stopping &lt;em&gt;me&lt;/em&gt; -- I can't make a cube in Blender to save my life. But surely I can't be the only person on this planet who has this strong desire for such a digital, photo-realistic recreation of some -- any! -- location?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I remember seeing footage of a &quot;game&quot; in the mid-1990s where they had just taken a camera and walked around a real old castle, then made it into an interactive multimedia CD-ROM or something. I didn't understand what technique they had used, so it seemed like it was a photo-realistic simulation to me back then. Ever since that day, I have wanted such a thing &quot;for real&quot;, but not even the most impressive VR demos come anywhere near close.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: This does NOT need to be VR by any means. In fact, since I have sold my VR headset and won't be buying a new one for a very long time, if ever, I don't even want this to be VR.&lt;/p&gt;&#xA;" OwnerUserId="11903" LastActivityDate="2020-02-17T00:18:29.643" Title="What is it that really prevents photo-realistic, real-time, digital 3D simulations?" Tags="&lt;3d&gt;&lt;real-time&gt;&lt;simulation&gt;&lt;photo-realistic&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9577" PostTypeId="2" ParentId="5330" CreationDate="2020-02-17T05:11:32.777" Score="0" Body="&lt;p&gt;I think we should have both and also have a factor based on material&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some material has high diffusive so it will reflect only light of its own color. But some material can also reflect some light as it is. For the phong shader I think we use additive ambient because phong object tends to reflect all light and so ambient light could be lit it with that light's color, but other lights was used to make diffuse color&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On the contrary to lambert, if what I know is right, are material with high diffusion, and so the ambient light was added to the lit and multiply by material's color&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess modern shader should have a parameter to set this factor and write equation like this&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float factor; // 0.0 - 1.0 maybe reflectiveness?&#xA;float3 light = (factor * ambient.rgb); // ambient light&#xA;light += _MainLightColor.rgb * dot(normal,_MainLightDirection); // lambert&#xA;// maybe also specular&#xA;float3 color = ((1 - factor) * ambient.rgb) + (matColor * light);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Actually I take this concept from PBR material, there was a concept of energy conservation. All the light may lit the object by diffusion or reflection but to conserve energy, more diffuse color means lower reflection. And so ambient light just add more light energy, then get treat as the same as other light&lt;/p&gt;&#xA;" OwnerUserId="11904" LastActivityDate="2020-02-17T05:11:32.777" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9578" PostTypeId="1" CreationDate="2020-02-17T06:29:41.437" Score="0" ViewCount="38" Body="&lt;p&gt;I coded loop subdivision and ran it on a cube with triangle faces. I noticed this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nGaiv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nGaiv.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am using doubles to represent my vertex positions, I am not 100% sure these are caused by floating point imprecisions, but since the general shape looks ok I am not sure what else it could be.&lt;/p&gt;&#xA;&lt;p&gt;Any suggestions on how to find the cause? My linear algebra library is glm and I am coding this in C++.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-02-17T06:29:41.437" Title="Loop subdivision, certain areas converging towards degenerate geometry" Tags="&lt;c++&gt;&lt;mesh&gt;&lt;subdivision&gt;&lt;float&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9579" PostTypeId="1" CreationDate="2020-02-17T07:34:59.667" Score="0" ViewCount="185" Body="&lt;p&gt;Since a projection plane and a center of projection is used for achieving perspective projection, the shape of the view frustum doesn't change changing the focal length(which is the distance from the center of projection to the plane of projection i.e. the screen or buffer)  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then how is zooming done in computer graphics? It is mentioned in my textbook that this is done by changing the size of the view frustum and that the relationship that &lt;em&gt;field of view is inversely proportional to the zoom&lt;/em&gt; holds(somehow I don't know) but looks to me more like a bit conterintuitive, e.g.:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wCGAf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wCGAf.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11832" LastActivityDate="2020-02-17T07:34:59.667" Title="how is zooming done in computer graphics" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9580" PostTypeId="1" CreationDate="2020-02-17T20:47:15.803" Score="1" ViewCount="124" Body="&lt;p&gt;I am relatively new to computer vision and image processing. I have a single EXR file with 7 channels: 1-3 give me the RGB values, 4-6 give me the surface normals coded as RGB values and 7th channel contains depth information from the camera of the rendered image. I obtained this from the mitsuba renderer using the multi-channel plug-in. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering if there was any way to view these 7 channels separately. For eg. I would like an image showing only the depth values in grayscale. So far I haven't found a multi-channel EXR file viewer that does this for me. An example of what I'm talking about is shown in the link: &lt;a href=&quot;https://www.mitsuba-renderer.org/devblog/wp-content/uploads/2014/02/multichannel.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.mitsuba-renderer.org/devblog/wp-content/uploads/2014/02/multichannel.jpg&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Really looking forward to any help. Thanks!!&lt;/p&gt;&#xA;" OwnerUserId="11907" LastActivityDate="2020-02-18T04:11:50.787" Title="Extracting information from EXR Files" Tags="&lt;rendering&gt;&lt;image-processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9581" PostTypeId="2" ParentId="9580" CreationDate="2020-02-18T04:11:50.787" Score="1" Body="&lt;p&gt;I don't know any IDE-based tools that do this but a quick Python script should do the trick. I usually use Thijs Vogels' &lt;a href=&quot;https://github.com/tvogels/pyexr&quot; rel=&quot;nofollow noreferrer&quot;&gt;PyEXR&lt;/a&gt; to read the multi-channel EXR. Assuming your depth channel is called &lt;code&gt;distance&lt;/code&gt; (which needs to be specified in your Mitsuba XML file under your &lt;code&gt;hdrfilm&lt;/code&gt;), you can visualize it with the following code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import pyexr&#xA;&#xA;fp = pyexr.open('multichannel.exr')&#xA;img = fp.get('distance')&#xA;pyexr.write('distance.exr', img)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6588" LastActivityDate="2020-02-18T04:11:50.787" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9582" PostTypeId="1" AcceptedAnswerId="9585" CreationDate="2020-02-18T08:39:37.920" Score="0" ViewCount="73" Body="&lt;p&gt;From my understanding game developers used mostly proprietary, in-house graphics engines during the sixth console generation (Xbox, PS2, GC, DC) on a game to game basis. Why didn't standard engines like Unreal (for consoles), Unity etc. emerge earlier?&#xA;Wasn't it very inefficient to develop a new engine just for one (or probably a few) games?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bonus question: Are there any good ressources on graphics development during that time? I'm especially interested in articles about the effort needed to develop an engine for any of the mentioned consoles.&lt;/p&gt;&#xA;" OwnerUserId="11912" LastActivityDate="2020-02-18T12:53:28.157" Title="Graphics engines during the sixth console generation" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9583" PostTypeId="1" CreationDate="2020-02-18T11:09:56.907" Score="0" ViewCount="659" Body="&lt;p&gt;Now there has already been an answer &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/6254/how-to-derive-a-perspective-projection-matrix-from-its-components&quot;&gt;here in this stackexchange&lt;/a&gt;, but I don't understand certain aspects of it.  The author has &lt;a href=&quot;https://dovo329.github.io/DeriveOpenGLPerspectiveProjectionMatrix/&quot; rel=&quot;nofollow noreferrer&quot;&gt;MORE DETAILED DESCRIPTION HERE(#1)&lt;/a&gt; but the problem is he doesn't describe what the linear mapping is done or how is the frustum transformed into the bounding box, there's &lt;strong&gt;NOWHERE IN THE WORLD&lt;/strong&gt; mentioned how these two subspaces overlap or one is transformed to the other, for example:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/02bgu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/02bgu.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;br&gt;&#xA;Is this how these two spaces exist and after projecting the point from inside the view frustum to the near plane a linear mapping is done where the author says:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&quot;Our input to the linear mapping is x=x_near, and our output is the x coordinate in NDC space y=x_ndc, whose range is [-1.0, 1.0]&quot; &lt;a href=&quot;https://dovo329.github.io/DeriveOpenGLPerspectiveProjectionMatrix/&quot; rel=&quot;nofollow noreferrer&quot;&gt;from the above page&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It looks as if he somehow connects a line from the frustum to the NDC space but not clear on how it is done e.g. does he connect the top left vertex to the top left front vertex of the NDC cube?   Are the four corners of the frustum mapped to four corners of the cube?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As much I'd like to make this answer self contained, I don't know if I can copy his materials in here, please be kind enough to check the link out and help me understand this. Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="11832" LastEditorUserId="8009" LastEditDate="2020-02-26T10:21:43.923" LastActivityDate="2020-02-27T16:33:13.460" Title="perspective matrix derivation" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9584" PostTypeId="2" ParentId="9583" CreationDate="2020-02-18T12:06:47.277" Score="2" Body="&lt;p&gt;The key trick is the perspective divide, This divides the position by the &lt;code&gt;w&lt;/code&gt; component. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you swap z and w (using a identity matrix that has swapped 3rd and 4th rows) and then do a perspective divide you end up with a double pyramid with a angle between the side (FoV) of 90° if applied to a unit cube. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once you have that transformation you can remap you can do further remapping pre and post the swap to make the corners of the input and output match up. The well known algorithm to create a perspective matrix has all those remaps inlined as an optimization.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2020-02-18T12:06:47.277" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9585" PostTypeId="2" ParentId="9582" CreationDate="2020-02-18T12:46:10.550" Score="0" Body="&lt;p&gt;Renderware was common on the PS2. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/List_of_RenderWare_games&quot; rel=&quot;nofollow noreferrer&quot;&gt;List of PS2 Renderware titles&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would guess because these platforms were proprietary and none-standard from a graphics and resources POV that it would be a bigger effort to port Unreal along with all their existing content creation tools.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2020-02-18T12:53:28.157" LastActivityDate="2020-02-18T12:53:28.157" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9586" PostTypeId="2" ParentId="8927" CreationDate="2020-02-18T14:53:09.987" Score="0" Body="&lt;p&gt;So after letting this lie for quite a while, I just came back to it. Turns out, the error was in my code with a faulty &lt;code&gt;false&lt;/code&gt; return value which would lead to a &lt;code&gt;System.exit&lt;/code&gt;. I have no idea how I didn't catch this the last time round, but it now works with &lt;em&gt;Try 2&lt;/em&gt;. That is:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;public class SubWindow implements GLEventListener&#xA;{&#xA;    GLWindow glWindow;&#xA;    Program m_program;&#xA;&#xA;    public void createSubWindow(int windowWidth, int windowHeight, boolean isFullscreen, String windowTitle&#xA;            , Program program)&#xA;    {&#xA;        GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL3));&#xA;        caps.setBackgroundOpaque(false);&#xA;        glWindow = GLWindow.create(caps);&#xA;&#xA;        glWindow.setTitle(windowTitle);&#xA;        glWindow.setSize(windowWidth, windowHeight);&#xA;        glWindow.setUndecorated(false);&#xA;        glWindow.setPointerVisible(true);&#xA;        glWindow.setVisible(true);&#xA;&#xA;        m_program = program;&#xA;        glWindow.addGLEventListener(this);&#xA;        glWindow.addKeyListener(m_program);&#xA;        glWindow.addMouseListener(m_program);&#xA;&#xA;        Animator animator = new Animator();&#xA;        animator.add(glWindow);&#xA;        animator.start();&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where the &lt;code&gt;Program&lt;/code&gt; is one of my own classes handling the logic and the SubWindow class additionally implements the required &lt;code&gt;init&lt;/code&gt;, &lt;code&gt;display&lt;/code&gt;, etc. methods.&lt;/p&gt;&#xA;" OwnerUserId="7008" LastActivityDate="2020-02-18T14:53:09.987" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9587" PostTypeId="1" CreationDate="2020-02-18T16:20:18.180" Score="0" ViewCount="53" Body="&lt;p&gt;I have a situation where (due to floating point error) a ray that is &lt;em&gt;known&lt;/em&gt; to hit a bounding box fails due to floating point error. (1e-8 or so)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Expanding the box is not an acceptable solution in my specific use case. However, if I could &quot;snap&quot; the ray to the box, that would work out well.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In order to do so, I need to find the shortest vector from a given ray to a bounding box. In 2 dimensions, that would look like this: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LtRig.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LtRig.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I can get that red vector, I can add it to the origin and the ray will be shifted to the bounding box.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 2D this is apparently relatively easy, as you can get distance between two lines like &lt;a href=&quot;http://csharphelper.com/blog/2014/08/find-the-shortest-distance-between-two-line-segments-in-c/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, then find the smallest of the 4 lines and use that. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But in 3D I am not aware of how to do this. Does anyone know if there is a way?&lt;/p&gt;&#xA;" OwnerUserId="11282" LastEditorUserId="11282" LastEditDate="2020-02-18T16:26:51.333" LastActivityDate="2020-02-18T23:24:27.027" Title="Determining shortest vector between a ray and an axis-aligned 3D bounding box (correcting a near-miss)" Tags="&lt;raytracing&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9588" PostTypeId="2" ParentId="9587" CreationDate="2020-02-18T23:24:27.027" Score="1" Body="&lt;p&gt;If you know the rounding error, you could subtract the error from your vectors so that rays would overlap the bounding box. This could be done in your intersection tests.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 3D, computing shortest distance between a vector and face of a bounding box would be another way to shift the vector to overlap the bounding box. But I doubt this approach would work well as it essentially tries to fix a rounding problem. &lt;/p&gt;&#xA;" OwnerUserId="11915" LastActivityDate="2020-02-18T23:24:27.027" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9589" PostTypeId="1" CreationDate="2020-02-19T14:31:30.183" Score="2" ViewCount="136" Body="&lt;p&gt;I don't understand why the PBR implementation of Metorpolis Light Transport scales the final image by &lt;code&gt;b / mutationsPerPixel&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The authors write:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;em&gt;Each Metropolis iteration within &amp;quot;Run nChains Markov chains in parallel&amp;quot; has splatted contributions with weighted unit luminance to the Film so that the final average film luminance before Film::WriteImage() is exactly equal to mutationsPerPixel.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;(see &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html&lt;/a&gt; at the very end of the page.)&lt;/p&gt;&#xA;&lt;p&gt;For simplicity, assume that we are considering a fixed path length &lt;span class=&quot;math-container&quot;&gt;$k\in\mathbb N$&lt;/span&gt; and a single fixed &lt;span class=&quot;math-container&quot;&gt;$(s,t)$&lt;/span&gt;-strategy. Formally, let&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; denote the scene surface set, &lt;span class=&quot;math-container&quot;&gt;$\mathcal B(M)$&lt;/span&gt; denote the Borel &lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt;-algebra on &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\sigma_M$&lt;/span&gt; denote the surface measure on &lt;span class=&quot;math-container&quot;&gt;$\mathcal B(M)$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$E:=M^{\{0,\:\ldots\:,\:,k\}}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\mathcal E:={\mathcal B(M)}^{\otimes\{0,\:\ldots\:,\:,k\}}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\lambda:=\sigma_M^{\otimes\{0,\:\ldots\:,\:,k\}}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$f:E\to[0,\infty)^3$&lt;/span&gt; denote the measurement contribution function&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; be the probability density on &lt;span class=&quot;math-container&quot;&gt;$(E,\mathcal E,\lambda)$&lt;/span&gt; corresponding to the &lt;span class=&quot;math-container&quot;&gt;$(s,t)$&lt;/span&gt;-strategy satisfying &lt;span class=&quot;math-container&quot;&gt;$\{q=0\}\subseteq\{f=0\}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Once more, for simplicity, assume that the generated &lt;span class=&quot;math-container&quot;&gt;$(E,\mathcal E)$&lt;/span&gt;-valued chain &lt;span class=&quot;math-container&quot;&gt;$(X_n)_{n\in\mathbb N}$&lt;/span&gt; is independent and &lt;span class=&quot;math-container&quot;&gt;$$X_n\sim q\lambda\;\;\;\text{for all }n\in\mathbb N.$$&lt;/span&gt; If it's easier to understand for you, you might want to take a look at the &lt;code&gt;importance_sampling_integrator::render()&lt;/code&gt; method in &lt;a href=&quot;https://coliru.stacked-crooked.com/view?id=7f55a67c5e1dab10&quot; rel=&quot;nofollow noreferrer&quot;&gt;this code&lt;/a&gt;, where I've implemented these simplifications.&lt;/p&gt;&#xA;&lt;p&gt;Now let's consider the measurement of a single pixel value &lt;span class=&quot;math-container&quot;&gt;$$I:=\int hf\:{\rm d}\lambda,$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$h:E\to[0,\infty)$&lt;/span&gt; is the image reconstruction filter corresponding to this pixel. Assume (as PBRT does) that &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt; is a Box filter with radius 1/2. So, if &lt;span class=&quot;math-container&quot;&gt;$\psi:E\to R$&lt;/span&gt; is the canonical mapping from the path space &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; to the raster space &lt;span class=&quot;math-container&quot;&gt;$R=[0,a)\times[0,b)$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$a\in\mathbb N$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b\in\mathbb N$&lt;/span&gt; are the vertical and horizontal resolution of the image, respectively, and the pixel we've fixed is pixel &lt;span class=&quot;math-container&quot;&gt;$(i,j)\in J:=\{0,\ldots,a-1\}\times\{0,\ldots,b-1\}$&lt;/span&gt; then &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt; is simply the indicator function of the set &lt;span class=&quot;math-container&quot;&gt;$$B:=\left\{x\in E:\psi(x)\in\underbrace{[i,i+1)\times[j,j+1)}_{=:\:R_{(i,\:j)}}\right\},$$&lt;/span&gt; i.e. &lt;span class=&quot;math-container&quot;&gt;$h=1_B$&lt;/span&gt;. Now let &lt;span class=&quot;math-container&quot;&gt;$$U_n:=\psi(X_n)\;\;\;\text{for }n\in\mathbb N$$&lt;/span&gt; and note that, by construction of &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$$U_n\sim\mathcal U_R\;\;\;\text{for all }n\in\mathbb N\tag1,$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\mathcal U_R$&lt;/span&gt; denotes the uniform distribution on &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt;. This immediately yields that &lt;span class=&quot;math-container&quot;&gt;$$(q\lambda)(B)=\mathcal U_R\left(R_{(i,\:j)}\right)=\frac1{|J|}\tag2.$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$$g(x):=h(x)\left.\begin{cases}\displaystyle\frac fq(x)&amp;amp;\text{, if }q(x)&amp;gt;0\\0&amp;amp;\text{, otherwise}\end{cases}\right\}\;\;\;\text{for }x\in E.$$&lt;/span&gt; Now the naive estimator for &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$$\frac1n\sum_{i=1}^ng(X_i)\xrightarrow{n\to\infty} I\;\;\;\text{almost surely}\tag3.$$&lt;/span&gt; However, if I implement this (which corresponds to replacing &lt;code&gt;m_camera-&amp;gt;film-&amp;gt;WriteImage(pbrt::Float{ 1 } / m_sampler-&amp;gt;samplesPerPixel);&lt;/code&gt; in the last line of &lt;code&gt;importance_sampling_integrator::render()&lt;/code&gt; by &lt;code&gt;m_camera-&amp;gt;film-&amp;gt;WriteImage(pbrt::Float{ 1 } / m_n);&lt;/code&gt;), I end up with a black image. This is not surprising, since due to the very small support of &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt; compared to the whole image, only very few terms contribute to the sum in &lt;span class=&quot;math-container&quot;&gt;$(3)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So, it seems like that one needs to consider only the visits of &lt;span class=&quot;math-container&quot;&gt;$(X_n)_{n\in\mathbb N}$&lt;/span&gt; to the set &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt;, i.e. consider the process &lt;span class=&quot;math-container&quot;&gt;$$Y_k:=X_{\tau_k}\;\;\;\text{for }k\in\mathbb N$$&lt;/span&gt; instead, where &lt;span class=&quot;math-container&quot;&gt;$\tau_0:=0$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$$\tau_k:=\inf\left\{n&amp;gt;\tau_{k-1}:X_n\in B\right\}\;\;\;\text{for }k\in\mathbb N.$$&lt;/span&gt; It's easy to see that &lt;span class=&quot;math-container&quot;&gt;$(Y_k)_{k\in\mathbb N}$&lt;/span&gt; is independent with &lt;span class=&quot;math-container&quot;&gt;$$Y_n\sim (q\lambda)\left[\;\cdot\mid B\right]\;\;\;\text{for all }k\in\mathbb N\tag4.$$&lt;/span&gt; Moreover, &lt;span class=&quot;math-container&quot;&gt;$$\frac1k\sum_{i=1}^kg(Y_i)\xrightarrow{k\to\infty}(q\lambda)\left[g\mid B\right]=|J|I\tag5$$&lt;/span&gt; by &lt;span class=&quot;math-container&quot;&gt;$(2)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Now what the code does is independently drawing &lt;span class=&quot;math-container&quot;&gt;$X_1,\ldots,X_n\sim q\lambda$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$$n=n_0|J|\tag6$$&lt;/span&gt; for some &lt;span class=&quot;math-container&quot;&gt;$n_0\in\mathbb N$&lt;/span&gt; (called &lt;code&gt;mutationsPerPixel&lt;/code&gt; in PBRT).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;We may consider the number &lt;span class=&quot;math-container&quot;&gt;$$N_n:=\sum_{i=1}^n1_B(X_i)$$&lt;/span&gt; of visits to &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; up to time &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; and note that &lt;span class=&quot;math-container&quot;&gt;$$\operatorname E\left[N_n\right]=\frac n{|J|}\tag7$$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$$\frac{N_n}n\xrightarrow{n\to\infty}\frac1{|J|}\;\;\;\text{almost surely}.\tag8$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Now PBRT (and the code I've provided above as well) uses the estimator &lt;span class=&quot;math-container&quot;&gt;$$\frac1{n_0}\sum_{i=1}^ng(X_i)=\frac1{\operatorname E\left[N_n\right]}\sum_{i=1}^{N_n}g(Y_i),$$&lt;/span&gt; but I absolutely don't understand why this works. From &lt;span class=&quot;math-container&quot;&gt;$(5)$&lt;/span&gt; we should obtain &lt;span class=&quot;math-container&quot;&gt;$$\frac1{\operatorname E\left[N_n\right]}\sum_{i=1}^{N_n}g(Y_i)=\frac{|J|}n\sum_{i=1}^ng(X_i)\xrightarrow{n\to\infty}|J|I\tag9$$&lt;/span&gt; almost surely, but the left-hand side of &lt;span class=&quot;math-container&quot;&gt;$(9)$&lt;/span&gt;, dividied by &lt;span class=&quot;math-container&quot;&gt;$|J|$&lt;/span&gt;, is once again the pracitcally not working estimator &lt;span class=&quot;math-container&quot;&gt;$(3)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;What am I missing?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: Just to be completely sure I've built the image array by myself using the (supposed to be correct) estimator &lt;span class=&quot;math-container&quot;&gt;$(5)$&lt;/span&gt;:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;void render(pbrt::Scene const&amp;amp; scene)&#xA;{&#xA;    auto const light_distribution = pbrt::ComputeLightPowerDistribution(scene);&#xA;&#xA;    std::unordered_map&amp;lt;pbrt::Light const*, std::size_t&amp;gt; light_to_index;&#xA;    for (std::size_t i = 0; i &amp;lt; scene.lights.size(); ++i)&#xA;        light_to_index[scene.lights[i].get()] = i;&#xA;&#xA;    std::vector&amp;lt;vertex&amp;gt; z(m_t),&#xA;        y(m_s);&#xA;&#xA;    std::size_t const a = m_camera-&amp;gt;film-&amp;gt;GetSampleBounds().pMax.y,&#xA;        b = m_camera-&amp;gt;film-&amp;gt;GetSampleBounds().pMax.x;&#xA;    std::vector&amp;lt;pbrt::Spectrum&amp;gt; image(a * b);&#xA;    std::vector&amp;lt;std::size_t&amp;gt; n(a * b);&#xA;&#xA;    pbrt::MemoryArena arena;&#xA;    for (std::size_t i = 0; i &amp;lt; m_n; ++i)&#xA;    {&#xA;        pbrt::Point2f raster_point;&#xA;        auto const contribution = sample_path(scene, *m_camera, *light_distribution, light_to_index,&#xA;            arena, m_k, m_s, *m_sampler, raster_point, z.data(), y.data());&#xA;        arena.Reset();&#xA;&#xA;        std::size_t const index = static_cast&amp;lt;std::size_t&amp;gt;(raster_point.y) * b + static_cast&amp;lt;std::size_t&amp;gt;(raster_point.x);&#xA;&#xA;        image[index] += contribution.value_or(0);&#xA;        ++n[index];&#xA;    }&#xA;&#xA;    for (std::size_t i = 0; i &amp;lt; n.size(); ++i)&#xA;    {&#xA;        if (n[i] &amp;gt; 0)&#xA;            image[i] = image[i] / (n[i] /** a * b*/);&#xA;    }&#xA;    m_camera-&amp;gt;film-&amp;gt;SetImage(image.data());&#xA;    m_camera-&amp;gt;film-&amp;gt;WriteImage();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;At the end, I should devide each pixel value by &lt;span class=&quot;math-container&quot;&gt;$|J|=ab$&lt;/span&gt;. However, if I uncomment the devision in the code, I end up with a black image again. So, my guess right now is that the values provided by &lt;code&gt;BxDF::Sample_f()&lt;/code&gt; are not what I thought they are. Maybe they are &amp;quot;normalized&amp;quot; and maybe this is what they mean by &amp;quot;&lt;em&gt;Each Metropolis iteration within &amp;lt;&amp;gt; has splatted contributions with weighted unit luminance&lt;/em&gt;&amp;quot;.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-03-05T10:44:01.373" Title="Scaling of the final image in Metropolis Light Transport" Tags="&lt;raytracing&gt;&lt;global-illumination&gt;&lt;pbr&gt;&lt;monte-carlo&gt;&lt;pbrt&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9590" PostTypeId="1" CreationDate="2020-02-19T14:57:48.293" Score="1" ViewCount="143" Body="&lt;p&gt;I need to frequently perform depth testing for any given fragment at a different fragment location than the one rendered to. Since this isn't possible with normal builtin OpenGL depth testing functionality, what I actually do instead is disable the normal depth test and instead perform my own manual depth test inside the fragment shader by binding the depth buffer as a depth texture/sampler and discarding the fragment when the test at the corresponding texture coordinate fails. This works sufficiently well since I don't actually need to write anything to the depth buffer in those cases and there's also a more or less clear cut in my per-frame render order at which point the normal depth buffer is considered &quot;complete&quot; and I continue with my custom depth test, so I can just copy the depth buffer into a texture and use my manual depth test.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now what I considered is that if I am already rendering into an offscreen buffer anyway, I don't actually need to copy the depth buffer over. Instead I can just &lt;strong&gt;detach the depth texture from the depth attachment to use it as a texture&lt;/strong&gt;. This would play out nicely since in the cases where I do manual depth testing I &lt;strong&gt;don't need builtin depth testing&lt;/strong&gt; anyway. This would also make it possible to mix builtin and custom depth tests more freely without manual synchronization through framebuffer copies (although, switching attachments can probably cause implicit overhead).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I &lt;em&gt;also&lt;/em&gt; &lt;strong&gt;need builtin stencil testing&lt;/strong&gt; together with my custom in-shader depth test. This becomes a problem since I use a &lt;strong&gt;packed depth-stencil texture (specifically 24+8)&lt;/strong&gt;. So I would need to have that &lt;strong&gt;texture attached to the stencil attachment still, while reading from its (non-attached) depth channel in the shader&lt;/strong&gt;. Although I didn't find anything specifically about this configuration in the documentation (extension specs and wiki), all sources say that a &lt;strong&gt;texture image should not be attached for rendering while currently being used for sampling&lt;/strong&gt; or it's UB, which would still be the case here. This limitation also makes practical sense, since although I'm just using the depth component, it's still the same 32bit block and the whole point of packed depth-stencil is combining these into one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Separating depth and stencil into separate textures would work, but I'd like to avoid that since that doesn't necessarily have to be universally supported and might also be less space and time efficient. But other than that I don't know what else could alleviate this problem. The texture barrier extension from GL 4.5 does seem to have the same limitation and only loosens limitations for certain same-fragment accesses, but I need to sample from different locations (and possibly the same one for different fragments). What I don't know is if texture views could possibly work around that by having a depth texture view on only the depth component of a packed depth-stencil texture, but that doesn't seem technically feasible without more elaborate synchronization during sampling beyond the mere data reinterpretation facilities texture views seem to provide.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is there any way to achieve that, i.e. &lt;strong&gt;sampling the depth component of a packed depth-stencil texture while simultaneously testing/rendering the stencil component&lt;/strong&gt;, without having to separate the components into individual textures or manually copying the depth component to its own texture?&lt;/p&gt;&#xA;" OwnerUserId="6" LastActivityDate="2020-02-19T14:57:48.293" Title="Sampling the depth component of a packed depth-stencil texture while rendering to its stencil component" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;frame-buffer&gt;&lt;synchronization&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9591" PostTypeId="1" CreationDate="2020-02-19T18:56:41.740" Score="0" ViewCount="154" Body="&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; denote the measurement contribution function for paths of length &lt;span class=&quot;math-container&quot;&gt;$k\in\mathbb N$&lt;/span&gt;, i.e. &lt;span class=&quot;math-container&quot;&gt;$$f(x)=g(x_0\leftrightarrow x_1)W_{\text e}(x_1\to x_0)t_k(x_0,\ldots,x_k)L_{\text e}(x_k\to x_{k-1}),$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$$t_k(x)=\prod_{i=2}^kg(x_{i-1}\leftrightarrow x_i)f_{\text s}(x_i\to x_{i-1}\to x_{i-2}),$$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; denote the image reconstruction filter of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel so that the measurement &lt;span class=&quot;math-container&quot;&gt;$I_j$&lt;/span&gt; of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel color is given by &lt;span class=&quot;math-container&quot;&gt;$$I_j=\int h_jf\:{\rm d}\mu.$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What can we assume know about &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; in general? One thing is that it will only depend on first two vertices of a path.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two properties which I really would like to being able to assume: (a) &lt;span class=&quot;math-container&quot;&gt;$c:=\sup_j\left\|h_j\right\|&amp;lt;\infty$&lt;/span&gt; (b) &lt;span class=&quot;math-container&quot;&gt;$\int|g_j|^2\:{\rm d}\mu\le\alpha\int|f_0|^2\:{\rm d}\mu$&lt;/span&gt; for some &lt;span class=&quot;math-container&quot;&gt;$\alpha\ge0$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$g_j:=1_{\{\:h_j\:&amp;gt;\:0\:\}}\left(h_jf-\frac1{\mu\left(\left\{h_j&amp;gt;0\right\}\right)}I_j\right)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$f_0:=1_{\{\:f\:\ne\:0\:\}}\left(f-\frac1{\mu\left(\left\{f\ne0\right\}\right)}\int f\:{\rm d}\mu\right)$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, I know almost nothing about the mathematical properties of &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; and so it's hard for me to verify if these properties hold. I guess that generally &lt;span class=&quot;math-container&quot;&gt;$h_j\ge0$&lt;/span&gt;, but I'm even unsure about that. Maybe even &lt;span class=&quot;math-container&quot;&gt;$h_j\in[0,1]$&lt;/span&gt;? It would be great if someone could answer if (a) and/or (b) hold or link me to a reference.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2020-03-02T11:27:22.240" LastActivityDate="2021-04-27T00:04:40.463" Title="Properties of the image reconstruction filter in rendering" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;&lt;filtering&gt;" AnswerCount="2" CommentCount="12" ContentLicense="CC BY-SA 4.0" />
  <row Id="9593" PostTypeId="1" CreationDate="2020-02-19T19:39:43.223" Score="0" ViewCount="29" Body="&lt;p&gt;What is the size of the final filter after implement convolution of multiple gaussian filters with different sizes?&lt;/p&gt;&#xA;" OwnerUserId="11922" LastActivityDate="2020-02-19T19:39:43.223" Title="Convolution of multiple gaussian filters with different sizes" Tags="&lt;image-processing&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9594" PostTypeId="1" AcceptedAnswerId="9625" CreationDate="2020-02-20T12:04:00.063" Score="0" ViewCount="74" Body="&lt;p&gt;I know OBJ-files essentially are one or more lists of n-tuples containing information about the location of vertices, texture and normals. However, I am not sure how this is structured in an IFC-file. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, whenever I look for the data structure of IFC-files, I find information regarding the hierarchy of elements in IFC, but I cannot find information regarding how the geometry is saved. Also, how is this related to the hierarchy of entities in the model?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What should I learn to understand this?&lt;/p&gt;&#xA;" OwnerUserId="11850" LastActivityDate="2020-03-04T13:24:09.287" Title="Data structure of IFC-files" Tags="&lt;data-structure&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9596" PostTypeId="1" CreationDate="2020-02-20T20:21:34.007" Score="0" ViewCount="78" Body="&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$W_{\text e}$&lt;/span&gt; denote the camera sensor responsivity (i.e. importance) and &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$W_{\text e}^{(j)}$&lt;/span&gt; denote the  image reconstruction filter and sensor response associated with the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel, respectively, i.e. &lt;span class=&quot;math-container&quot;&gt;$$W_{\text e}^{(j)}=h_jW_{\text e}.\tag1$$&lt;/span&gt; The measurement of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel is given by &lt;span class=&quot;math-container&quot;&gt;\begin{equation}\begin{split}\Phi_j&amp;amp;:=\sigma_M({\rm d}x_0)\int\sigma_M({\rm d}x_1)g(x_0\leftrightarrow x_1)W_{\text e}^{(j)}(x_1\to x_0)L_{\text o}(x_1\to x_0)\\&amp;amp;=\int\lambda({\rm d}x)h_j(x_1\to x_0)f(x),\end{split}\tag2\end{equation}&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$g$&lt;/span&gt; denotes the geometry term, &lt;span class=&quot;math-container&quot;&gt;$\lambda$&lt;/span&gt; is the infinite-product area measure on the path space and &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; is the measurement contribution function, i.e. &lt;span class=&quot;math-container&quot;&gt;$$f(x)=g(x_0\leftrightarrow x_1)W_{\text e}(x_1\to x_0)\prod_{i=2}^kg(x_{i-1}\leftrightarrow x_i)f_{\text s}(x_i\to x_{i-1}\to x_{i-2})L_{\text e}(x_k\to x_{k-1}),\tag3$$&lt;/span&gt; if &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is a path of length &lt;span class=&quot;math-container&quot;&gt;$k\in\mathbb N$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Usually, in the context of Metropolis Light Transport, the scalar contribution function &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is defined to be the luminance of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;. So, by definition, &lt;span class=&quot;math-container&quot;&gt;$p(x)=0$&lt;/span&gt; whenever &lt;span class=&quot;math-container&quot;&gt;$(x_0,x_1)$&lt;/span&gt; doesn't belong to &lt;span class=&quot;math-container&quot;&gt;$$B:=\left\{(x_0,x_1):W_{\text e}(x_1\to x_0)\ne 0\right\}.$$&lt;/span&gt; Now let &lt;span class=&quot;math-container&quot;&gt;$$B_j:=\left\{(x_0,x_1):W_{\text e}^{(j)}(x_1\to x_0)\ne 0\right\}.$$&lt;/span&gt; We clearly have &lt;span class=&quot;math-container&quot;&gt;$$B=\bigcup_jB_j.\tag4$$&lt;/span&gt; However, in light of the way samples are splat to image (see &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html#fragment-Splatbothcurrentandproposedsamplestomonofilm-0&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html#fragment-Splatbothcurrentandproposedsamplestomonofilm-0&lt;/a&gt; or &lt;a href=&quot;https://pdfs.semanticscholar.org/a386/55316ee7f438ba115b38e8d0b1410c691a26.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pdfs.semanticscholar.org/a386/55316ee7f438ba115b38e8d0b1410c691a26.pdf&lt;/a&gt; and &lt;a href=&quot;https://computergraphics.stackexchange.com/q/9589/9254&quot;&gt;my other question&lt;/a&gt;), it seems like it is assumed that the union in &lt;span class=&quot;math-container&quot;&gt;$(4)$&lt;/span&gt; is disjoint. Is this really guaranteed to be the case?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Taking a look in Section 2.6.4, on page 51, of &lt;a href=&quot;https://backend.orbit.dtu.dk/ws/portalfiles/portal/51112612/phd240_awk_vers2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this PhD thesis&lt;/a&gt;, this seems at least to be the case when the camera is a pinhole camera. The authors write: &lt;span class=&quot;math-container&quot;&gt;$W_{\text e}^{(j)}$&lt;/span&gt; &lt;em&gt;is non-zero only for the set of directions within the pyramid formed by the pinhole and the four corners of the corresponding pixel&lt;/em&gt; &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This seems to indicate that (at least for the pinhole camera) the &quot;support&quot; of &lt;span class=&quot;math-container&quot;&gt;$W_{\text e}^{(j)}$&lt;/span&gt; is limited to the image rectangle region occupied by the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel. But is this really true for &lt;em&gt;any&lt;/em&gt; filter &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; or only for a special one?&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2020-02-23T16:18:22.737" LastActivityDate="2020-02-23T16:18:22.737" Title="Relation between camera sensor responsivity and image reconstruction filter associated with a pixel" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;global-illumination&gt;&lt;monte-carlo&gt;&lt;filtering&gt;" AnswerCount="0" CommentCount="53" ContentLicense="CC BY-SA 4.0" />
  <row Id="9597" PostTypeId="2" ParentId="9583" CreationDate="2020-02-21T10:53:46.600" Score="1" Body="&lt;p&gt;&lt;strong&gt;Note: This is a work in progress - working on LaTeX and useful illustrations.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;My derivation notes were based partially on the perspective projection matrix derivation in &lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/0201848406&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;Computer Graphics: Principles and Practice (2nd Ed)&lt;/code&gt;&lt;/a&gt;. My understanding is that the 3rd edition takes a more contemporary approach with references to OpenGL and Direct3D. I haven't read this edition, and can't vouch for it.&lt;/p&gt;&#xA;&lt;p&gt;This derivation also assumes an understanding of homogeneous coordinates and the notion of a projective space. The wikipedia entry is concise, but lacks the intuition provided by a few good &lt;strong&gt;2D&lt;/strong&gt; example illustrations. (If you're &lt;em&gt;really&lt;/em&gt; keen, search for early articles on the subject by &lt;a href=&quot;http://www.jimblinn.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jim Blinn&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;First, we need to outline a few assertions and conventions:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;We always assume a &lt;a href=&quot;https://en.wikipedia.org/wiki/Right-hand_rule#Coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;'right-handed' coordinate space&lt;/a&gt;, unless otherwise stated. The 'eye' is at: &lt;code&gt;(0, 0, 0)&lt;/code&gt;. &lt;code&gt;(+Z)&lt;/code&gt; may be considered the direction pointing 'out' of the screen (or window / viewport), while &lt;code&gt;(X, Y)&lt;/code&gt; are Cartesian coordinates, where: &lt;code&gt;(0, 0)&lt;/code&gt; corresponds to the centre of that viewport.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The &lt;a href=&quot;https://en.wikipedia.org/wiki/Viewing_frustum&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;strong&gt;view frustum&lt;/strong&gt;&lt;/a&gt; has a near plane at: &lt;code&gt;Z = - N&lt;/code&gt; and a far plane at: &lt;code&gt;Z = - F&lt;/code&gt;, with normals in the &lt;code&gt;+Z&lt;/code&gt; direction. The near plane: &lt;code&gt;Z = - N&lt;/code&gt;, has &lt;code&gt;X: L &amp;lt;= X &amp;lt;= R&lt;/code&gt;, and &lt;code&gt;Y: B &amp;lt;= Y &amp;lt;= T&lt;/code&gt;, which will eventually map to a &lt;strong&gt;3D viewport&lt;/strong&gt;. This frustum encapsulates all visible geometry. (Technically speaking, &lt;code&gt;R &amp;lt; L&lt;/code&gt;, &lt;code&gt;T &amp;lt; B&lt;/code&gt;, and &lt;code&gt;N &amp;gt; F &amp;gt; 0&lt;/code&gt; are permitted by &lt;code&gt;glFrustum&lt;/code&gt;. Arbitrary matrices are of course permitted in core profile OpenGL contexts.)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;The mathematics will use what are somewhat misleadingly called 'row-major' matrices, but I insist on the use of column vectors when describing a system of transforms, i.e., the &lt;em&gt;column&lt;/em&gt; vector is 'pre-multiplied' by the matrix: &lt;code&gt;v' = [M]v&lt;/code&gt;. Disagree all you want - just know that you are sick and need help.&lt;/p&gt;&#xA;&lt;p&gt;In all seriousness, either convention can be made to work; it's just a matter of being aware of the conventions and sticking with a choice. The 'column-vector' convention is typically the one taught in linear algebra. We apply &lt;em&gt;successive&lt;/em&gt; transforms: &lt;code&gt;[A]&lt;/code&gt;, &lt;code&gt;[B]&lt;/code&gt;, &lt;code&gt;[C]&lt;/code&gt; to a vector: &lt;code&gt;v&lt;/code&gt;, like we would apply functions: &lt;code&gt;C(B(A(v)))&lt;/code&gt;, hence: &lt;code&gt;v' = [C][B][A]v&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Any view frustum (camera) in space can be transformed by pre-multiplying the (homogeneous) coordinates by an 'orientation matrix'. That's beyond your question, but typically requires a general &lt;strong&gt;PRP&lt;/strong&gt; (camera eye point), &lt;strong&gt;VRP&lt;/strong&gt; (the centre of the 'near' projection plane), and the &lt;strong&gt;VUP&lt;/strong&gt; point, which references a point defining 'up'. In effect, it's sufficient to form a orthonormal coordinate system. This is the view coordinate space &lt;strong&gt;(VCS)&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The orthonormal basis, along with the &lt;strong&gt;PRP&lt;/strong&gt; translation, can be used to construct an inverse transform that 'premultiplies' geometry to world coordinate space &lt;strong&gt;(WCS)&lt;/strong&gt;. Again, you can save the concept of orthonormal basis / coordinate system transforms for a rainy day...&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;We do not &lt;em&gt;assume&lt;/em&gt; the view frustum is centred on the Z axis - although this is almost certainly the case for most projections. There are more exotic transforms (a mirror in a scene comes to mind); we'll concentrate on the general case.&lt;/p&gt;&#xA;&lt;p&gt;The direction of projection: &lt;span class=&quot;math-container&quot;&gt;$\small\\\mathbf{DOP}=\left[(R+L)/2,\: (T+B)/2,\: -N\right]\,^T$&lt;/span&gt;. The view frustum is typically symmetric about the Z axis s.t. &lt;code&gt;R = - L&lt;/code&gt;, &lt;code&gt;T = - B&lt;/code&gt;, yielding: &lt;span class=&quot;math-container&quot;&gt;$\small\\\mathbf{DOP}=\left[0,\: 0,\: -N\right]\,^T$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Of course, this is not &lt;em&gt;required&lt;/em&gt;, so our first step in the perspective projection derivation is to apply a &lt;em&gt;shear&lt;/em&gt; matrix that maps the &lt;span class=&quot;math-container&quot;&gt;$\small\\\mathbf{DOP}$&lt;/span&gt; to the (negative) Z-axis:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;(R + L) / 2 + shear.x (- N) = 0&lt;/code&gt; =&amp;gt; &lt;code&gt;shear.x = (R + L) / (2.N)&lt;/code&gt;&lt;br/&gt;&#xA;&lt;code&gt;(T + B) / 2 + shear.y (- N) = 0&lt;/code&gt; =&amp;gt; &lt;code&gt;shear.y = (T + B) / (2.N)&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Consider the shear transformation applied to the frustum's near-clipping plane vertex coordinates:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\tiny\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; (R+L)/(2.N) &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; (T+B)/(2.N) &amp;amp; 0 \\ &#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;R \\ T \\ -N \\ 1&#xA;\end{pmatrix}&#xA;= \begin{pmatrix}&#xA;(R-L)/2 \\ (T-B)/2 \\ -N \\ 1&#xA;\end{pmatrix}&#xA;\:,$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\tiny\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; (R+L)/(2.N) &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; (T+B)/(2.N) &amp;amp; 0 \\ &#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;L \\ B \\ -N \\ 1&#xA;\end{pmatrix}&#xA;= \begin{pmatrix}&#xA;(L-R)/2 \\ (B-T)/2 \\ -N \\1&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Following this transform, the &lt;span class=&quot;math-container&quot;&gt;$\small\\\mathbf{DOP}$&lt;/span&gt; is in direction of the &lt;code&gt;- Z&lt;/code&gt; axis; specifically, the centre of the near view plane: &lt;span class=&quot;math-container&quot;&gt;$\small\left((R+L)/2,\: (T+B)/2,\: -N,\: 1\right)\,^T$&lt;/span&gt; has been mapped to: &lt;span class=&quot;math-container&quot;&gt;$\small\left(0,\: 0,\: -N,\: 1\right)\,^T$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Now we want to scale the perspective projection transform such that the &lt;code&gt;R, L, T, B&lt;/code&gt; planes of the frustum have have a unit gradient. The current gradients are &lt;code&gt;(R - L) / (2.N)&lt;/code&gt; (right and left), and &lt;code&gt;(T - B) / (2.N)&lt;/code&gt; (top and bottom). The symmetry is due to the previous shearing transform.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;(R - L) / (2.N) * scale.x = 1&lt;/code&gt; =&amp;gt; &lt;code&gt;scale.x = 2.N / (R - L)&lt;/code&gt;&lt;br/&gt;&#xA;&lt;code&gt;(T - B) / (2.N) * scale.y = 1&lt;/code&gt; =&amp;gt; &lt;code&gt;scale.y = 2.N / (T - B)&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Furthermore, we want to scale by &lt;code&gt;(1 / F)&lt;/code&gt; s.t. the far clipping plane is mapped to: &lt;code&gt;Z = - 1&lt;/code&gt;, while the unit slopes of the right, left, top, and bottom clipping planes are preserved. These scaling factors premultiply the perspective projection matrix:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\tiny\begin{pmatrix}&#xA;2.N/(F(R-L)) &amp;amp; 0 &amp;amp; 0 &amp;amp; 1 \\ 0 &amp;amp; 2.N/(F(T-B)) &amp;amp; 0 &amp;amp; 1 \\ &#xA;0 &amp;amp; 0 &amp;amp; 1/F &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; (R+L)/(2.N) &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; (T+B)/(2.N) &amp;amp; 0 \\ &#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;=\\&#xA;\tiny\begin{pmatrix}&#xA;2.N/(F(R-L)) &amp;amp; 0 &amp;amp; (R+L)/(F(R-L)) &amp;amp; 0 \\ &#xA;0 &amp;amp; 2.N/(F(T-B)) &amp;amp; (T+B)/(F(T-B)) &amp;amp; 0 \\ &#xA;0 &amp;amp; 0 &amp;amp; 1/F &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;This transform yields what may be considered &lt;em&gt;the normalized frustum&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(TODO: need an image to show this transform)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The vertices of near clipping plane are mapped to: &lt;span class=&quot;math-container&quot;&gt;$\small\left(\pm N/F,\: \pm N/F,\: -N/F,\: 1\right)\,^T$&lt;/span&gt;, while the vertices of the far-clipping plane are mapped to: &lt;span class=&quot;math-container&quot;&gt;$\small\left(\pm 1,\: \pm 1,\: -1,\: 1\right)\,^T$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;(TODO: perspective (projection) transform unification -&amp;gt; CCS)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;As a homogeneous transform, the matrix can be simplified by scaling all elements by &lt;code&gt;F&lt;/code&gt;, since: &lt;span class=&quot;math-container&quot;&gt;$\small\left(X,\: Y,\: Z,\: W\right)\,^T \equiv \left(F.X,\: F.Y,\: F.Z,\: F.W\right)\,^T$&lt;/span&gt; :&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\tiny\begin{pmatrix}&#xA;2.N/(R-L) &amp;amp; 0 &amp;amp; (R+L)/(R-L) &amp;amp; 0 \\&#xA;0 &amp;amp; 2.N/(T-B) &amp;amp; (T+B)/(T-B) &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; F&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The normalized perspective projection view volume can be transformed into a parallel projection view volume:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(TODO: partial justification for this step. Perspective projection is just another homogeneous transform. Final CCS / NDCS have exquisite clip test properties)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\tiny\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; F/(F-N) &amp;amp; N/(F-N) \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;2.N/(R-L) &amp;amp; 0 &amp;amp; (R+L)/(R-L) &amp;amp; 0 \\&#xA;0 &amp;amp; 2.N/(T-B) &amp;amp; (T+B)/(T-B) &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; F&#xA;\end{pmatrix}&#xA;=\\&#xA;\tiny\begin{pmatrix}&#xA;2.N/(R-L) &amp;amp; 0 &amp;amp; (R+L)/(R-L) &amp;amp; 0 \\&#xA;0 &amp;amp; 2.N/(T-B) &amp;amp; (T+B)/(T-B) &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; F/(F-N) &amp;amp; F.N/(F-N) \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(TODO: need an image to show this transform)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Finally, we apply the following transforms to the current projection matrix:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Scale in &lt;code&gt;Z&lt;/code&gt; by &lt;code&gt;(2)&lt;/code&gt; to yield a cubic view volume.&lt;/li&gt;&#xA;&lt;li&gt;Translate by: &lt;span class=&quot;math-container&quot;&gt;$\small\left(0,\: 0,\: 1,\: 1\right)\,^T$&lt;/span&gt; to centre the cube at the origin.&lt;/li&gt;&#xA;&lt;li&gt;Convert to a left-handed coordinate system to satisfy &lt;strong&gt;NDCS&lt;/strong&gt; conventions.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\tiny\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 1 &amp;amp; 1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 2 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;=\&#xA;\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -2 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;This yields:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\tiny\begin{pmatrix}&#xA;1 &amp;amp; 0 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 1 &amp;amp; 0 &amp;amp; 0 \\ 0 &amp;amp; 0 &amp;amp; -2 &amp;amp; -1 \\ 0 &amp;amp; 0 &amp;amp; 0 &amp;amp; 1&#xA;\end{pmatrix}&#xA;\cdot&#xA;\begin{pmatrix}&#xA;2.N/(R-L) &amp;amp; 0 &amp;amp; (R+L)/(R-L) &amp;amp; 0 \\&#xA;0 &amp;amp; 2.N/(T-B) &amp;amp; (T+B)/(T-B) &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; F/(F-N) &amp;amp; F.N/(F-N) \\&#xA;0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0&#xA;\end{pmatrix}&#xA;=\\&#xA;\tiny\begin{pmatrix}&#xA;2.N/(R-L) &amp;amp; 0 &amp;amp; (R+L)/(R-L) &amp;amp; 0 \\&#xA;0 &amp;amp; 2.N/(T-B) &amp;amp; (T+B)/(T-B) &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; -(F+N)/(F-N) &amp;amp; -2.F.N/(F-N) \\&#xA;0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;(TODO: need an image to show this transform)&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;This is the canonical OpenGL perspective projection matrix:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$&#xA;\small\begin{pmatrix}&#xA;2.N/(R-L) &amp;amp; 0 &amp;amp; (R+L)/(R-L) &amp;amp; 0 \\&#xA;0 &amp;amp; 2.N/(T-B) &amp;amp; (T+B)/(T-B) &amp;amp; 0 \\&#xA;0 &amp;amp; 0 &amp;amp; -(F+N)/(F-N) &amp;amp; -2.F.N/(F-N) \\&#xA;0 &amp;amp; 0 &amp;amp; -1 &amp;amp; 0&#xA;\end{pmatrix}&#xA;$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="5574" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-02-27T16:33:13.460" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9600" PostTypeId="1" CreationDate="2020-02-22T01:00:29.017" Score="3" ViewCount="116" Body="&lt;p&gt;I'm curious if anyone has any insight into how one might procedurally generate 4D objects, as showcased in Miegakure (or the developer's other game, &lt;a href=&quot;https://4dtoys.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;4D Toys&lt;/a&gt; ).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I built a program a while back to do this, basically using &quot;shape definition&quot; files that I found (and subsequently processed) for the regular polychora like the hypercube, 120-cell, 600-cell etc. Example shape files can be found on &lt;a href=&quot;http://paulbourke.net/geometry/hyperspace/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Paul Bourke's website&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another way that I've recently discovered is, using a convex hull algorithm like Qhull to extract this information. You can first generate all of the vertices for your polytope (these are usually just even/odd permutations of certain 4-tuples). Then, you run Qhull to find how the vertices are connected to one another. The problem with this method is, it requires significant pre-processing, and the tetrahedral meshes that are generated aren't always very clean. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In 4D Toys, the author(s) are able to build shapes like a &quot;hollowed out&quot; 120-cell, so I'm curious if they are approaching this problem from a different angle - perhaps, one that is more flexible than the aforementioned approaches.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm curious if there are other ways of modeling and/or algorithmically generating shapes like those found in Miegakure that I haven't thought about? &#xA;What are other ways of approaching this design challenge?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance for any help or guidance.&lt;/p&gt;&#xA;" OwnerUserId="7656" LastActivityDate="2020-02-22T01:00:29.017" Title="Procedural Generation of 4D Shapes" Tags="&lt;rendering&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;procedural-generation&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9601" PostTypeId="2" ParentId="9583" CreationDate="2020-02-23T07:51:54.750" Score="1" Body="&lt;h1&gt;TL;DR:&lt;/h1&gt;&#xA;&lt;p&gt;The view frustum &lt;strong&gt;is&lt;/strong&gt; the NDC box.  It's just that NDC space is nonlinear because it occurs &lt;strong&gt;after&lt;/strong&gt; the perspective divide by w.  The tops and sides of the frustum are &lt;em&gt;parallel&lt;/em&gt; in NDC space. All lines that project to the viewpoint are parallel in NDC space.&lt;/p&gt;&#xA;&lt;h1&gt;Explanation:&lt;/h1&gt;&#xA;&lt;p&gt;I don't like math.  I dislike sites that try to explain all this with math and matrices and boring stuff like that.  I prefer pictures.  So I'll try to explain it with mainly pictures and descriptions.  Unfortunately the one thing that I must refer to mathematically is the fact that we have to &lt;em&gt;divide by Z&lt;/em&gt; to transform 3D points to 2D points according to the perspective transformation.  But &amp;quot;divide by Z&amp;quot; is as mathematical as I'll get, I promise.&lt;/p&gt;&#xA;&lt;h3&gt;The spaces&lt;/h3&gt;&#xA;&lt;p&gt;Recall the different spaces.  The View and Projection matrices are all linear transformations.  World Space, Camera Space, and Homogeneous Clip Space are all linear spaces.  The Normalized Device Coordinates are in a non-linear (projective) space and the Divide by w is a non-linear transformation.  We reinterpret these coordinates as screen coordinates and do a linear transform from NDC to viewport coordinates.&lt;/p&gt;&#xA;&lt;p&gt;The whole point of clip space is to keep the space linear and defer dividing by Z until the very end.  The denominator of the perspective transformation is kept as its own coordinate in linear space and called W (it's the divisor for the homogeneous coordinates).  At some point we can no longer defer this divide because we need screen coordinates so we must ultimately go from (X,Y,Z,W) to (X/W, Y/W, Z/W) and wind up in NDC space.  (Technically we go from homogeneous coordinates to 3-space.)&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;So I think this is the mathematical part of the answer to your question:  &lt;code&gt;(X,Y,Z,W) → (X/W, Y/W, Z/W)&lt;/code&gt; is called the &lt;strong&gt;Perspective Divide by W&lt;/strong&gt; and it's the operation you're looking for that maps from Clip space to NDC.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h3&gt;The transformations&lt;/h3&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qJyXv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qJyXv.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3&gt;Visualizing NDC&lt;/h3&gt;&#xA;&lt;p&gt;I've always hated how people draw the frustum with straight lines and draw the NDC box with straight lines but never show what's going on in the interior.  It really betrays our understanding of the non-linearity of relationship between the two spaces.  So here's a better diagram to help visualize the non-linearity of NDC space after the perspective projection.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zaLzI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zaLzI.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Imagine you stand where the person with the camera is and take a picture.  The red lines are the boundaries of what the camera can see.&#xA;Some familiar properties:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;All points along the top of the red frustum will be at the top of the camera image&lt;/li&gt;&#xA;&lt;li&gt;All points along the bottom of the red frustum will be at the bottom of the camera image.&lt;/li&gt;&#xA;&lt;li&gt;The side of the frustum closest to the camera (left of this diagram) is the near clipping plane&lt;/li&gt;&#xA;&lt;li&gt;The side of the frustum farthest from the camera (right of this diagram) is the far clipping plane.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The top part of the diagram is World / View / Clip clip space. They are all linear transforms of one another, so for this diagram they are all basically the same.&lt;/p&gt;&#xA;&lt;p&gt;The bottom part of the diagram is Normalized Device Coordinate space. In NDC space the top and bottom of that frustum are &lt;em&gt;parallel&lt;/em&gt;.  Notice the frustum in Clip space became a rectangle in NDC space.  Because the near clipping plane and the far clipping plane both become the same size as the camera image (camera sensor / camera frame).&lt;/p&gt;&#xA;&lt;p&gt;Note that any line that passes through the viewpoint is parallel to the top and bottom of this frustum in NDC space -- the magenta line is an example of this.   Notice that the magenta line passes just over the roof of the first (near) car and just over the back tire of the yellow (far) car.  Yet in NDC space, this line is parallel to the top of the frustum and the bottom of the frustum.  All the points along that magenta line will have the same coordinates in the final camera image (will appear at the same point on the screen in your rendering).  Cool, right?&lt;/p&gt;&#xA;&lt;p&gt;The frustum becomes a box in NDC space, which, I'll admit, is deceptively linear-seeming.  But you can tell the NDC space is non-linear (has that &amp;quot;divides by Z&amp;quot; property) because the lines of the sidewalk (which are parallel in world space or view/camera space) are not parallel in NDC space.  They follow that characteristic 1/x style curve in the diagram.&lt;/p&gt;&#xA;&lt;p&gt;In the diagram, for some distance away from the camera, everything is proportionally the same distance away from the top and bottom of the camera frustum in both Clip space, and NDC.&lt;/p&gt;&#xA;&lt;h3&gt;Summary&lt;/h3&gt;&#xA;&lt;p&gt;Hopefully this is a useful visual explanation of how to get between World / View / Clip space and NDC.  This is intended to supplement the mathematical descriptions you've already been given, not replace them.  Hopefully this gives you a visual with which you can ground your understanding of the non-linearity of projective transformations.&lt;/p&gt;&#xA;&lt;p&gt;Just remember:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;That although all the camera boundaries (red lines in the diagram) match between&#xA;World space and NDC, it's a &lt;strong&gt;frustum in World space&lt;/strong&gt; and a &lt;strong&gt;rectangle in NDC space&lt;/strong&gt;.  (So &lt;em&gt;yes&lt;/em&gt;, the corners of the view frustum &lt;em&gt;are&lt;/em&gt; the corners of the NDC &amp;quot;cube&amp;quot;)&lt;/li&gt;&#xA;&lt;li&gt;That straight lines (that run closer or farther to the camera and don't pass through the viewpoint) like the edges of the sidewalk are &lt;strong&gt;straight in World space&lt;/strong&gt; but &lt;strong&gt;may be curved in NDC space&lt;/strong&gt;. :)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="8009" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-02-23T07:51:54.750" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9603" PostTypeId="1" CreationDate="2020-02-24T00:40:16.143" Score="1" ViewCount="45" Body="&lt;p&gt;I am reading the paper &lt;em&gt;Blockwise Multi-Order Feature Regression for Real-Time Path Tracing&#xA;Reconstruction&lt;/em&gt; and the authors use a term several times which I am not sure what it means. This is in the context of reconstruction algorithms (denoising) for path traced fraces at 1 spp.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They write :&quot;Since the quality of&#xA;the interactive methods is not as good as in offline methods (for path tracing), extra&#xA;care needs to be taken to address temporal stability of the results.&quot;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What does &quot;temporal stability&quot; mean in this context?&lt;/p&gt;&#xA;" OwnerUserId="10079" LastEditorUserId="10079" LastEditDate="2020-02-24T00:55:22.940" LastActivityDate="2020-02-24T00:55:22.940" Title="Terminology Question: Temporal Stability" Tags="&lt;pathtracing&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9604" PostTypeId="2" ParentId="9533" CreationDate="2020-02-24T07:30:47.797" Score="0" Body="&lt;p&gt;This is a C++ implementation. Slab is the space between a pair of parallel planes.Test if ray R(t) = p + t * d intersect against bounding box bb.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bool IntersectRayBB( const double* p, const double* d, const BoundingBox&amp;amp; bb, double&amp;amp; tmin, double* q )&#xA;{&#xA;    double tolerance = 1e-9;&#xA;    tmin = 0.0;&#xA;    double tmax = FLOAT32_MAX; // Set to max distance ray can travel&#xA;    for( int i = 0; i &amp;lt; 3; i++ )&#xA;    {&#xA;        if( Abs( d[i] ) &amp;lt; tolerance )&#xA;        {&#xA;            // Ray is parallel to slab. No hit if origin not within slab.&#xA;            if( p[i] &amp;lt; bb.min[i] || p[i] &amp;gt; bb.max[i] )&#xA;                return false;&#xA;        }&#xA;        else&#xA;        {&#xA;            // Compute intersection t value of ray within near and far plane of slab&#xA;            double denom = 1.0 / d[i];&#xA;            double t1 = ( bb.min[i] - p[i] ) * denom;&#xA;            double t2 = ( bb.max[i] - p[i] ) * denom;&#xA;            // Make t1 be intersection with near plane, t2 with far plane&#xA;            if( t1 &amp;gt; t2 )&#xA;                std::Swap( t1, t2 );&#xA;            // Compute the intersection of slab intersection intervals&#xA;            if( t1 &amp;gt; tmin )&#xA;                tmin = t1;&#xA;            if( t2 &amp;gt; tmax )&#xA;                tmax = t2;&#xA;            // Exit with no collision as soon as slab intersection becomes empty&#xA;            if( tmin &amp;gt; tmax )&#xA;                return false;&#xA;        }&#xA;    }&#xA;&#xA;    //Ray intersects all 3 slabs. Return point (q) and intersesction t value (tmin)&#xA;    q = p + d * tmin;&#xA;    return true;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10769" LastActivityDate="2020-02-24T07:30:47.797" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9606" PostTypeId="1" CreationDate="2020-02-24T12:16:18.060" Score="1" ViewCount="91" Body="&lt;p&gt;I'm trying to implement a simple BDPT without MIS as described in Lafortune's paper. I've used the weighting scheme defined in the paper in which they suggest that the weight be based on the surface specularity i.e. specular surfaces should add more weight to continue following the eye path rather than connect with the light path (which makes sense since the eye path is based on the current surface BRDF sampling).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I shoot rays from the light source and the camera a fixed number of times. Each bounce stores the Hit Information and the PDF of the next ray generated. The light path can easily be inverted to get the directions similar to the eye path and by connecting both the paths and using the weighting scheme we can use the simple path tracer algorithm to calculate the total radiance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are only 2 things that are different from what happens in a normal path tracer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) First is the determinstic ray step i.e. the connection of each eye path vertex with the light vertex. This ray is not sampled from a PDF but instead shot deterministically. What should I use the value for the PDF for this step? Do I need to inverse sample the determinstic ray direction from the eye vertex BRDF PDF to get the probability? Or perhaps from the light vertex?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) The first ray shot from the light has its own PDF unlike in the normal path tracer where light is found explicitly using Direct Light Sampling. How can I incorporate this factor when I have path tracer that uses Next Event Estimation and Direct Light Sampling? I suppose I can fallback to the naive algorithm (no NEE or explicit Direct Light Sampling) since I already have pin pointed the light source from the light path. Just wanted clarification regarding this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2020-04-07T19:01:25.343" Title="BDPT - How to handle deterministic ray PDF?" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9607" PostTypeId="1" CreationDate="2020-02-24T12:34:48.780" Score="0" ViewCount="58" Body="&lt;p&gt;I am currently studying for a computer graphics exam and on the slides about bilinear interpolation it is said that it is in reality quadratic interpolation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;An (on the slides) unanswered question then asks what interpolation on a 2D texture would be linear, but I can't really think of a way that is not cheating like going nearest neigbour in one dimension. Did I miss something or is it a trick question?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you very much :)&lt;/p&gt;&#xA;" OwnerUserId="11939" LastActivityDate="2020-02-24T12:34:48.780" Title="Is linear interpolation in a 2D texture possible (not quadratic like bilinear interpolation)?" Tags="&lt;texture&gt;&lt;interpolation&gt;" AnswerCount="0" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="9609" PostTypeId="1" CreationDate="2020-02-25T11:25:23.140" Score="0" ViewCount="46" Body="&lt;p&gt;Say we have a &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Sampling_and_Reconstruction/Image_Reconstruction.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;image reconstruction filter&lt;/a&gt; &lt;span class=&quot;math-container&quot;&gt;$h:R\to\mathbb R$&lt;/span&gt; defined on the raster space &lt;span class=&quot;math-container&quot;&gt;$[0,w]\times[0,h]$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$w,h\in\mathbb N$&lt;/span&gt; define the width and height of the image plane in pixels, respectively.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;How is this &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt; related to the image reconstruction filter &lt;span class=&quot;math-container&quot;&gt;$\tilde h$&lt;/span&gt; defined on the path space occuring in the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Metropolis_Light_Transport.html#ApplicationtoRendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;path integral formula&lt;/a&gt; for the measurement of a pixel?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Asked differently: How is &lt;span class=&quot;math-container&quot;&gt;$\tilde h$&lt;/span&gt; defined in terms of &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since &lt;span class=&quot;math-container&quot;&gt;$\tilde h$&lt;/span&gt; only depends on the first two components of a path, we may clearly assume that &lt;span class=&quot;math-container&quot;&gt;$\tilde h$&lt;/span&gt; is a function on &lt;span class=&quot;math-container&quot;&gt;$M^2\to\mathbb R$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; denotes the scene geometry. For simplicity, assume a pinhole camera with eye &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; so that &lt;span class=&quot;math-container&quot;&gt;$\tilde h$&lt;/span&gt; is a function &lt;span class=&quot;math-container&quot;&gt;$M\to\mathbb R$&lt;/span&gt;. I guess we may likewise consider it as a function of directions, i.e. as a function on the unit 2-sphere &lt;span class=&quot;math-container&quot;&gt;$S^2:=\{\omega\in\mathbb R^3:|\omega|=1\}$&lt;/span&gt; or on the hemisphere &lt;span class=&quot;math-container&quot;&gt;$H^2:=\{\omega\in S^2:\omega_3&amp;gt;0\}$&lt;/span&gt;, corresponding to the front-facing directions (assuming camera space), if that's easier.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT 1&lt;/strong&gt;: I define the path space &lt;span class=&quot;math-container&quot;&gt;$(E,\mathcal E,\lambda)$&lt;/span&gt; in the same way as Veach did in his seminal work: &lt;span class=&quot;math-container&quot;&gt;$$E_k:=M^{\{0,\:\ldots\:,\:k\}},\mathcal E_k:=\mathcal B(M)^{\otimes\{0,\:\ldots\:,\:k\}},\lambda_k:=\sigma_M^{\otimes\{0,\:\ldots\:,\:k\}}$$&lt;/span&gt; for &lt;span class=&quot;math-container&quot;&gt;$k\in\mathbb N,$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\sigma_M$&lt;/span&gt; denotes the surface measure on &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$$E:=\bigcup_{k\in\mathbb N}E_k,\mathcal E:=\mathcal B(E),$$&lt;/span&gt;&lt;span class=&quot;math-container&quot;&gt;$$\lambda(B):=\sum_{k\in\mathbb N}\lambda_k(B\cap E_k)\;\;\;\text{for }B\in\mathcal E.$$&lt;/span&gt; But, as noted before, we can restrict our attention to &lt;span class=&quot;math-container&quot;&gt;$(E_2,\mathcal E_2,\lambda_2)$&lt;/span&gt; and, assuming a pinhole camera with the eye at the origin &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;, we're simply actually only dealing with &lt;span class=&quot;math-container&quot;&gt;$(M,\mathcal B(M),\sigma_M)$&lt;/span&gt;. Denoting the surface measure on the unit sphere by &lt;span class=&quot;math-container&quot;&gt;$\sigma_{S^2}$&lt;/span&gt;, I'll define the projected solid angle kernel to be &lt;span class=&quot;math-container&quot;&gt;$$\sigma_M^\perp(x,B):=\int_B\sigma_{S^2}({\rm d}\omega)|\langle\nu_M(x),\omega\rangle|\;\;\;\text{for }(x,B)\in M\times\mathcal B(S^2),$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\langle\nu_M$&lt;/span&gt; denotes the unit normal field on &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$\sigma_{S^2}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\sigma_M$&lt;/span&gt; are related by &lt;span class=&quot;math-container&quot;&gt;$$\int\sigma_M^\perp(x,{\rm d}\omega)f(\omega)=\int\sigma_M({\rm d}y)g(x\leftrightarrow y)f(\omega_{x\to y})\tag1$$&lt;/span&gt; for all &lt;span class=&quot;math-container&quot;&gt;$x\in M$&lt;/span&gt; and Borel measurable &lt;span class=&quot;math-container&quot;&gt;$f:S^2\to[0,\infty)$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$$g(x\leftrightarrow y):=\left.\begin{cases}\displaystyle\frac{\left|\left\langle\nu_M(x),\omega_{x\to y}\right\rangle\right|\left|\left\langle\nu_M(y),\omega_{y\to x}\right\rangle\right|}{|x-y|^2}&amp;amp;\text{, if }y\text{ is visible from }x\\0&amp;amp;\text{,otherwise}\end{cases}\right\}$$&lt;/span&gt; for &lt;span class=&quot;math-container&quot;&gt;$x,y\in M$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\omega_{x\to y}:=\pi(y-x)$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\pi$&lt;/span&gt; denotes the projection of &lt;span class=&quot;math-container&quot;&gt;$\mathbb R^3\setminus\{0\}$&lt;/span&gt; onto &lt;span class=&quot;math-container&quot;&gt;$S^2$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT 2&lt;/strong&gt;: The image plane at &lt;span class=&quot;math-container&quot;&gt;$z=1$&lt;/span&gt; in camera space is of the form &lt;span class=&quot;math-container&quot;&gt;$$I:=\left[-\frac w2,\frac w2\right)\times\left[-\frac h2,\frac h2\right)\times\{1\},$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$w,h&amp;gt;0$&lt;/span&gt; are the width and height (in camera space) of the image plane, respectively. It's easy to see that a ray starting at &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; (the camera position in camera space) with direction &lt;span class=&quot;math-container&quot;&gt;$\omega\in S^2$&lt;/span&gt; has an intersection with the infinite extension &lt;span class=&quot;math-container&quot;&gt;$\mathbb R^2\times\{1\}$&lt;/span&gt; of &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt; if and only if &lt;span class=&quot;math-container&quot;&gt;$\omega\in H^2$&lt;/span&gt; and in that case the intersection is occurring at &lt;span class=&quot;math-container&quot;&gt;$\frac\omega{\omega_3}$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2020-02-25T14:19:31.370" LastActivityDate="2020-02-25T14:19:31.370" Title="How is the image reconstruction filter on the path space defined in terms of the filter on the raster space?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;physically-based&gt;&lt;global-illumination&gt;&lt;raster-image&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9610" PostTypeId="1" AcceptedAnswerId="9624" CreationDate="2020-02-25T16:53:04.230" Score="0" ViewCount="308" Body="&lt;p&gt;Given:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;An arbitrary &lt;strong&gt;circular&lt;/strong&gt; cylinder (defined by startpoint, endpoint, and radius). An &lt;strong&gt;Infinite cylinder is acceptable as well&lt;/strong&gt;, as long as it passes through those points and has the same radius.&lt;/li&gt;&#xA;&lt;li&gt;An axis-aligned box (defined by its minimum and maximum point)&lt;/li&gt;&#xA;&lt;li&gt;The box being completely inside the volume of the cylinder should also count as an intersection&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;To test if the cylinder and the box intersect.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does such a test exist?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: I found &lt;a href=&quot;https://math.stackexchange.com/questions/166863/intersection-between-a-cylinder-and-an-axis-aligned-bounding-box?rq=1&quot;&gt;this&lt;/a&gt; on the mathmatics stack exchange, though at the moment I do not follow it. If there is an example of it in code form that would be fantastic.&lt;/p&gt;&#xA;" OwnerUserId="11282" LastEditorUserId="11282" LastEditDate="2020-03-02T20:49:11.057" LastActivityDate="2020-03-17T16:34:20.823" Title="Looking for a cylinder / axis-aligned box volume intersection test" Tags="&lt;geometry&gt;" AnswerCount="2" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9611" PostTypeId="2" ParentId="9610" CreationDate="2020-02-25T17:46:41.723" Score="1" Body="&lt;p&gt;As mentioned the problem of cylinder box intersection reduces to the problem of line-parallelogram intersection, and line segment-cylinder intersection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I will assume that you know how to intersect a line and a parallelogram. Here is a sketch for solving the line segment-cylinder intersection:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The canonical equation of an elliptic cylinder aligned with the &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; axis and having center &lt;span class=&quot;math-container&quot;&gt;$(c_x, c_y, c_z)$&lt;/span&gt; is given as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{(x-c_x)^2}{a^2} + \frac{(y-c_y)^2}{b^2} = 1$$&lt;/span&gt;&#xA;The parametric form of a ray is given as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\vec{r}(t) = \vec{o} + t\vec{d}$$&lt;/span&gt;&#xA;Then by plugging r into the canonical equation one gets:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{(o_x + td_x -c_x)^2}{a^2} + \frac{(o_y + td_y -c_y)^2}{b^2} = 1$$&lt;/span&gt;&#xA;Solve the quadratic equation for &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; and you have your intersection. If the discriminant is negative then there is no intersection. To get a rotated cylinder, the easiest way is to apply the inverse rotation to the ray (the equation may be modified however too). Note that for a line segment, you simply need to check whether &lt;span class=&quot;math-container&quot;&gt;$t \in [t_0, t_1]$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\vec{a} = \vec{o} + t_0\vec{d}$&lt;/span&gt; is the first point of the line segment, and &lt;span class=&quot;math-container&quot;&gt;$\vec{b} = \vec{o} + t_1\vec{d}$&lt;/span&gt; is the second one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT: To clarify you further questions in the comments:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) a,b in the denominator are the radii along the &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$Y$&lt;/span&gt; axes respectively. In the trivial case where &lt;span class=&quot;math-container&quot;&gt;$a=b=r$&lt;/span&gt; we have the canonical equation for a circular cylinder:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(x-c_x)^2 + (y-c_y)^2 = r^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) For the intersection between the cylinder axis and the box a rotation is only required if your box is OOBB and you want to use your AABB intersection code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) The solution of the quadratic equation is trivial (note, I renamed &lt;span class=&quot;math-container&quot;&gt;$a,b$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$r_1,r_2$&lt;/span&gt; to further emphasize that they are the radii):&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{(o_x + td_x -c_x)^2}{r_1^2} + \frac{(o_y + td_y -c_y)^2}{r_2^2} = 1$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$r_2^2(o_x + td_x - c_x)^2 + r_1^2(o_y + td_y -c_y)^2 = r_1^2r_2^2$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$(r_2^2d_x^2+r_1^2d_y^2)t^2 - 2(r_2^2d_x(c_x-o_x) + r_1^2d_y(c_y-o_y))t + r_2^2(c_x-o_x)^2 + r_1^2(c_y-o_y)^2 - r_1^2r_2^2 = 0$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let us substitute:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$A = (r_2^2d_x^2+r_1^2d_y^2)$$&lt;/span&gt; &#xA;&lt;span class=&quot;math-container&quot;&gt;$$B = (r_2^2d_x(c_x-o_x) + r_1^2d_y(c_y-o_y))$$&lt;/span&gt; &#xA;&lt;span class=&quot;math-container&quot;&gt;$$C = r_2^2(c_x-o_x)^2 + r_1^2(c_y-o_y)^2 - r_1^2r_2^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you have the quadratic equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$At^2 -2Bt + C = 0$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$D = B^2-AC$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$D&amp;lt;0$&lt;/span&gt; there is no intersection between the ray &lt;span class=&quot;math-container&quot;&gt;$\vec{o}+t\vec{d}$&lt;/span&gt; and the cylinder, otherwise:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$t_1 = \frac{B-\sqrt{D}}{A}, t_2 = \frac{B+\sqrt{D}}{A},$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;give you the two intersections (it is one intersection if &lt;span class=&quot;math-container&quot;&gt;$D=0$&lt;/span&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now let your segment vertices be &lt;span class=&quot;math-container&quot;&gt;$\vec{v}_a = \vec{o}+t_a\vec{d}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{v}_b = \vec{o} + t_b\vec{d}$&lt;/span&gt;. If &lt;span class=&quot;math-container&quot;&gt;$t_a \leq t_1 \leq t_b$&lt;/span&gt; then you have an intersection at &lt;span class=&quot;math-container&quot;&gt;$t_1$&lt;/span&gt;, if &lt;span class=&quot;math-container&quot;&gt;$t_a \leq t_2 \leq t_b$&lt;/span&gt; then you have an intersection at &lt;span class=&quot;math-container&quot;&gt;$t_2$&lt;/span&gt;, otherwise there is not intersection.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2020-02-28T19:32:20.230" LastActivityDate="2020-02-28T19:32:20.230" CommentCount="14" ContentLicense="CC BY-SA 4.0" />
  <row Id="9614" PostTypeId="1" CreationDate="2020-02-26T19:50:06.933" Score="0" ViewCount="79" Body="&lt;p&gt;I have a standard 3d camera/projection/model setup that renders rectangles with a WebGL shader. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Users can zoom out and fly anywhere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to make sure that regardless of the scale, width of the rendered rectangles is a constant value (e.g. 2 pixels). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the most efficient way to do so?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is very similar to SVG's non-scaling-stroke vector effect: &lt;a href=&quot;https://www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.w3.org/TR/SVGTiny12/painting.html#NonScalingStroke&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7512" LastActivityDate="2021-05-27T22:02:45.207" Title="constant pixel width for any scale" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;shader&gt;&lt;glsl&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9616" PostTypeId="1" CreationDate="2020-02-27T15:55:45.490" Score="0" ViewCount="61" Body="&lt;p&gt;I am looking for a file format to output some 3D geometry. In my case, it only needs to handle very simple shapes - uniformly spaced and sized cubes at points in space. So far I've ended up just representing them as triangles or quads depending on what I can use. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've tried Binary STL format which is decently compact, but has no support for colors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Wavefront Object format (OBJ) and the material library (MTL) work well for color support, but there is no binary version as far as I know - making it very bulky. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a file format that:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Is compact in size&lt;/li&gt;&#xA;&lt;li&gt;Has some way to support colors&lt;/li&gt;&#xA;&lt;li&gt;Can be opened by software like 3D Viewer, Paint 3D, or other common tools?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="11282" LastActivityDate="2021-03-23T19:02:10.223" Title="Looking for a compact file format for outputting 3D geometry with color support" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9617" PostTypeId="2" ParentId="9616" CreationDate="2020-02-27T16:20:57.617" Score="0" Body="&lt;p&gt;The &lt;a href=&quot;https://www.cc.gatech.edu/projects/large_models/ply.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;PLY file format&lt;/a&gt; is a simple format similar to OBJ that allows arbitrary attributes (like colours) and has a binary mode.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2020-02-27T16:20:57.617" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9618" PostTypeId="1" AcceptedAnswerId="9619" CreationDate="2020-02-29T05:56:51.310" Score="1" ViewCount="52" Body="&lt;p&gt;I am reading a paper &lt;em&gt;TileGAN: Synthesis of Large-Scale Non-Homogeneous Textures&lt;/em&gt;&#xA;available &lt;a href=&quot;https://arxiv.org/abs/1904.12795&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, and in the section entitled &lt;em&gt;Selected Applications of GANS&lt;/em&gt; (i.e. applications of Generative Adversarial networks), they make claim that recent papers in computer grahics apply GANs&#xA;to :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Volumetric modeling of shapes&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;A quick google search of this term does not yield great results for a definition of this word. What does the term &quot;volumetric modeling&quot; mean?&lt;/p&gt;&#xA;" OwnerUserId="10079" LastActivityDate="2020-02-29T17:46:20.117" Title="Terminology: Volumetric Model" Tags="&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9619" PostTypeId="2" ParentId="9618" CreationDate="2020-02-29T17:46:20.117" Score="2" Body="&lt;p&gt;Volumetric Modeling usually refers to using a regular 3D grid of voxels, analogous to 2D pixels, to define properties of an object at points or small regions of space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While more complex data might be stored at each voxel, often each contains a simple vector of values which can be interpreted directly as density or material properties for analysis and rendering. There is a whole literature on such techniques (search for Volume Rendering), often in the context of medical imaging where e.g. MRI scanners produce such data directly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is natural to consider extending techniques for generating images composed of 2D pixels to 3D voxels and modeling solids.&lt;/p&gt;&#xA;" OwnerUserId="2500" LastActivityDate="2020-02-29T17:46:20.117" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9621" PostTypeId="1" AcceptedAnswerId="9632" CreationDate="2020-03-01T16:58:49.263" Score="0" ViewCount="66" Body="&lt;p&gt;Here is a youtube video showing my problem:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=y8J7VhS2pkM&quot; rel=&quot;nofollow noreferrer&quot;&gt;youtube.com/watch?v=y8J7VhS2pkM&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I think I'm either doing the texture lookup on the reflection texture wrong, or the reflection or view matrix is somehow wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reflection matrix is calculated after Goldman formula with plane normal pointing in positive y-Axis (world up vector).&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/mgerhardy/engine/blob/master/src/modules/voxelrender/WorldRenderer.cpp#L97&quot; rel=&quot;nofollow noreferrer&quot;&gt;WorldRenderer.cpp#L97&lt;/a&gt; (&lt;code&gt;reflectionMatrix()&lt;/code&gt; and &lt;code&gt;renderClippingPlanes()&lt;/code&gt; at those positions)&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/mgerhardy/engine/blob/master/src/modules/voxelrender/shaders/water.vert&quot; rel=&quot;nofollow noreferrer&quot;&gt;Water vertex shader&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/mgerhardy/engine/blob/master/src/modules/voxelrender/shaders/water.frag&quot; rel=&quot;nofollow noreferrer&quot;&gt;Water fragment shader&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/mgerhardy/engine/blob/master/src/modules/video/Camera.cpp#L309&quot; rel=&quot;nofollow noreferrer&quot;&gt;Camera viewmatrix calculation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What am I doing wrong here? Notice the renderings of the framebuffer textures in the debug ui.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was following this water rendering tutorial series here: &lt;a href=&quot;https://www.youtube.com/watch?v=0NH9k4zTAqk&amp;amp;list=PLRIWtICgwaX23jiqVByUs0bqhnalNTNZh&amp;amp;index=3&quot; rel=&quot;nofollow noreferrer&quot;&gt;Youtube Water rendering tutorial&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are other projects following this tutorial:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/fede-vaccaro/TerrainEngine-OpenGL&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/fede-vaccaro/TerrainEngine-OpenGL&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/codycoolwaffle/avaritia&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/codycoolwaffle/avaritia&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I couldn't find my error even after looking at the above code bases.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What might the error be? Anyone any ideas?&lt;/p&gt;&#xA;" OwnerUserId="11933" LastActivityDate="2020-03-07T09:15:25.650" Title="Wrong reflection" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;mathematics&gt;&lt;reflection&gt;&lt;glm&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9622" PostTypeId="2" ParentId="9591" CreationDate="2020-03-02T12:00:58.207" Score="0" Body="&lt;p&gt;I am replying to the last edit of the question.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can show that &lt;span class=&quot;math-container&quot;&gt;$\|h_j * f \|^2_2 \leq \|h_j\|^2_1\|f\|^2_2$&lt;/span&gt; from Young's theorem. Provided that  &lt;span class=&quot;math-container&quot;&gt;$\|h_j\|_1 \leq 1$&lt;/span&gt; you have: &lt;span class=&quot;math-container&quot;&gt;$\|h_j * f \|^2_2 \leq \|f\|^2_2$&lt;/span&gt;. Additionally for &lt;span class=&quot;math-container&quot;&gt;$g_j$&lt;/span&gt; I believe you want to clamp the indicator function to &lt;span class=&quot;math-container&quot;&gt;$\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\}$&lt;/span&gt;. Then &lt;span class=&quot;math-container&quot;&gt;$\int_{\{h_j&amp;gt;0 \wedge f&amp;gt;0\}} a\leq \int_{\{f&amp;gt;0\}}a$&lt;/span&gt; (since the integrands are always non-negative: &lt;span class=&quot;math-container&quot;&gt;$a\geq 0$&lt;/span&gt;). This basically proves that the inequality holds for the left terms of the quadratic expansions, the middle terms are both negative, &lt;strike&gt;so those may be ignored&lt;/strike&gt;. The only thing left to prove is: &lt;span class=&quot;math-container&quot;&gt;$(\frac{1}{\mu(\{h_j&amp;gt;0 \wedge f&amp;gt;0\})}\int h_jf)^2 \leq (\frac{1}{\mu(\{f&amp;gt;0\})}\int f)^2$&lt;/span&gt;, which is the case if &lt;span class=&quot;math-container&quot;&gt;$h_j \leq 1$&lt;/span&gt; everywhere. Basically, as long as your filter &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; preserves the minimum and maximum of the image, you're good (this is not an unreasonable requirement for a filter, note however, that there are filers that do not preserve min-max).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: My bad, the middle terms may not be ignored (at least the one on the right of the inequality). Which means you are left to prove that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{(\int h_jf)^2}{\mu(\{h_j&amp;gt;0 \wedge f&amp;gt;0\})} \geq \frac{(\int f)^2}{\mu(\{f&amp;gt;0\})}$$&lt;/span&gt;, which will be a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess one has to use tighter bounds to relate the mixed term with the squared terms.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit 2:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's consider the expression as a whole then:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int \left(h_jf - \frac{\int h_jf}{\mu(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\})} \right)^2 \leq \alpha \int \left(f - \frac{\int f}{\mu(\{f &amp;gt; 0\})} \right)^2$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ 0 \leq \alpha\int (f)^2 - \int (h_jf)^2 +\alpha\frac{(\int f)^2}{\mu^2(\{f &amp;gt; 0\})} - \frac{(\int h_jf)^2}{\mu^2(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\})} + \frac{2(\int h_jf)^2}{\mu(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\})} - \alpha\frac{2(\int f)^2}{\mu(\{f &amp;gt; 0\})}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ 0 \leq \alpha\left(\int (f)^2 - \frac{(1-2\mu(\{f &amp;gt; 0\}))(\int f)^2}{\mu^2(\{f &amp;gt; 0\})}\right) - \left( \int (h_jf)^2 - \frac{(1-2\mu(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\}))(\int h_jf)^2}{\mu^2(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\})}\right) $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$0 \leq \left(\int(\sqrt{\alpha}f)^2-\int (h_jf)^2\right) - \left(\frac{\alpha(1-2\mu(\{f &amp;gt; 0\}))(\int f)^2}{\mu^2(\{f &amp;gt; 0\})}  - \frac{(1-2\mu(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\}))(\int h_jf)^2}{\mu^2(\{h_j &amp;gt; 0 \wedge f &amp;gt; 0\})}\right) $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$0 \leq \left(\int(\sqrt{\alpha}f)^2-\int (h_jf)^2\right) - \left(a \left(\int \sqrt{\alpha}f\right)^2 - b\left(\int h_jf\right)^2\right)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note also that &lt;span class=&quot;math-container&quot;&gt;$\left(\int u\right)^2 \leq \int u^2$&lt;/span&gt;. Then with an appropriate &lt;span class=&quot;math-container&quot;&gt;$\alpha$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; bounded it should hold. You may want to study the &lt;span class=&quot;math-container&quot;&gt;$a,b$&lt;/span&gt; tems also.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2020-03-02T12:55:23.620" LastActivityDate="2020-03-02T12:55:23.620" CommentCount="20" ContentLicense="CC BY-SA 4.0" />
  <row Id="9624" PostTypeId="2" ParentId="9610" CreationDate="2020-03-02T20:45:35.203" Score="0" Body="&lt;p&gt;I ended up finding a fairly simple, fairly performant solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1: Create a transformation matrix that rotates the cylinder to one of the axis (x, y or z)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(That part is non-trivial)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2: Apply the transformation matrix to the cylinder&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3: Apply the transformation matrix to the eight corners of the axis-aligned bounding box. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Applying a transformation matrix is not too hard, it looks like this:)&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;newPoint[0] = (original[0] * xform[0][0]) + (original[1] * xform[1][0]) + (original[2] * xform[2][0] + xform[3][0]);&#xA;newPoint[1] = (original[0] * xform[0][1]) + (original[1] * xform[1][1]) + (original[2] * xform[2][1] + xform[3][1]);&#xA;newPoint[2] = (original[0] * xform[0][2]) + (original[1] * xform[1][2]) + (original[2] * xform[2][2] + xform[3][2]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;4: Get the distance of the corners to (0,0,0). Keep in mind that depending on your method of determining distance (IE, using a 3D distance formula) you may need to zero out the value of the point on the axis the cylinder was rotated to. If the cylinder was rotated to the Z axis, you would need to zero out the Z value for that point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;5: If &lt;em&gt;any&lt;/em&gt; of the points report a distance less than the radius of the cylinder, you know there must be a volume intersection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;6: Special case: If the cylinder has a diameter small enough, it could fit inside of the bounding box completely, thus there would be no points for which their distance &amp;lt; cylinder radius. I am unsure of the maximum circle that fits within the projection of a box while not encompassing any points. My best guess is just to check if the diameter is &amp;lt; than any of the box's edge length, or check if the diameter is less than the diagonal of the box, which may be safer. Not sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;7: If you want the cylinder to have a maximum length, that's not too bad either. Just take one point of the cylinder, a vector representing its direction and its length, and do &lt;code&gt;origin + (dir * length)&lt;/code&gt; to get the endpoint of the cylinder. Transform it as well, and make sure any points you have fall within the Z of that transformed endpoint. &lt;/p&gt;&#xA;" OwnerUserId="11282" LastEditorUserId="11282" LastEditDate="2020-03-17T16:34:20.823" LastActivityDate="2020-03-17T16:34:20.823" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9625" PostTypeId="2" ParentId="9594" CreationDate="2020-03-03T22:45:58.920" Score="2" Body="&lt;p&gt;You need to learn and understand STEP data exchange format (ISO 10303-21) which is the fundamental exchange format which the IFC schema is built on top of. This is no easy feat though, especially when comparing to a file format such as OBJ. OBJ files are designed to define geometry (and other information via associated MTL) and so are optimised for this purpose. IFC on the other hand, is designed to exchange many aspects of AEC including building, services, structural, furnishings, energy model etc and so is far more complex with the geometry definitions being only a subset of the information supplied in an IFC. It would be easier to use an existing IFC library to do this, and even then, an understanding of the structure of the IFC entities and their hierarchy is still required to traverse the relationships (inverse attributes) between the object definitions in an IFC file in order to reconstruct the desired geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;OBJ files explicitly define the vertices, normals and faces that represent a mesh, however while there are IFC entities which can represent meshes in a similar fashion (namely IfcConnectedFaceSet), most geometry defined in an IFC file should be considered more like a series of instructions/commands to recreate the geometry. For this reason you would also require a geometry library (one which can do things like extrusions, Boolean/CSG operations, curves, NURBS etc). For example, one of the main things that is represented in many IFC files would be the walls, doors, windows etc of a building, and while these could be represented as explicit tessellated data or breps, in my experience these tend to be represented as an IfcExtrudedAreaSolid (&lt;a href=&quot;https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcgeometricmodelresource/lexical/ifcextrudedareasolid.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcgeometricmodelresource/lexical/ifcextrudedareasolid.htm&lt;/a&gt;) which supplies the direction and length to extrude a path/outline curve (the curve being defined by an IfcProfileDef which is an attribute of IfcExtrudedAreaSolid, &lt;a href=&quot;https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcprofileresource/lexical/ifcprofiledef.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcprofileresource/lexical/ifcprofiledef.htm&lt;/a&gt;). This gets even more complicated when there is an opening (i.e window recess or door opening in the wall) which again is related (through an inverse attribute) to the geometry representing the opening to be removed through a geometric Boolean operation (CSG). As you can see it starts to get complicated fairly quickly and isn't just a case of reading in raw vertices, normals and faces etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All geometry in an IFC file is defined by objects which are sub types of IfcRepresentationItem (&lt;a href=&quot;http://dcom.arch.gatech.edu/aci/cic/schema/ifcgeometryresource/lexical/ifcrepresentationitem.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://dcom.arch.gatech.edu/aci/cic/schema/ifcgeometryresource/lexical/ifcrepresentationitem.htm&lt;/a&gt;) and so that would be the place to start to understand what types of geometry definitions are used by IFC. Other items within the model (namely furnishings) are far more likely to be represented by raw tessellated data (IfcFacetedBrep, &lt;a href=&quot;https://standards.buildingsmart.org/IFC/RELEASE/IFC4_1/FINAL/HTML/schema/ifcgeometricmodelresource/lexical/ifcfacetedbrep.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://standards.buildingsmart.org/IFC/RELEASE/IFC4_1/FINAL/HTML/schema/ifcgeometricmodelresource/lexical/ifcfacetedbrep.htm&lt;/a&gt;) which is geometry that would be more familiar to you, and there is a chance you can isolate these definitions within in an IFC file and concentrate on processing that (you would still need to understand STEP format, namely the inverse attributes involved, in order to faithfully generate the mesh geometry). Also this geometry could be either explicitly located (in world space), but in many cases is also positioned through IfcPlacements (&lt;a href=&quot;https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcgeometryresource/lexical/ifcaxis2placement3d.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://standards.buildingsmart.org/IFC/RELEASE/IFC2x3/TC1/HTML/ifcgeometryresource/lexical/ifcaxis2placement3d.htm&lt;/a&gt;) locally, so you need to build up the hierarchy of transformations based on these definitions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, if you wanted to RYO IFC parser to grab geometry, it would be a steep learning curve and require you to understand many other concepts of STEP/IFC outside just knowing the geometry types and transforms. Easier to use an IFC library coupled with a geometry library (although many IFC libs do come with geometry libs to do this for you), but even then, depending on the lib used, you may need to have a basic understanding of the building hierarchy involved in order to correctly place and reconstruct much of the geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note, while many of the geometry concepts remain the same through the various versions of IFC (IFc2x3, IFC4, IFC4 ADD1 etc), in some cases there are subtle differences in the schema in relation to geometry object definitions. However, much of the version difference in IFC is do to with the building hierarchy, and associated information for the various disciplines in AEC.&lt;/p&gt;&#xA;" OwnerUserId="9438" LastEditorUserId="9438" LastEditDate="2020-03-04T13:24:09.287" LastActivityDate="2020-03-04T13:24:09.287" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9626" PostTypeId="1" CreationDate="2020-03-04T12:28:51.183" Score="0" ViewCount="62" Body="&lt;p&gt;I have created a 3D animation with a perspective projection of white circles moving randomly in a fake 3D space projected on a 2D computer screen (GIF 1). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LWqA7.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LWqA7.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since I need to keep the same number of visible circles, every time a circle disappears from the frame, I have to create a new visible one within the frame. To do so, I have written this piece of code:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;First I created initial coordinates and the two angles of movements (spherical coordinates):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;for circle in circles:&#xA;&#xA;    circle.position.xy = np.random.uniform(-25, 25, size=2)&#xA;    z = np.random.uniform(near_z, far_z)&#xA;&#xA;    circle.position.z = z&#xA;    circle.position.x *= z/-50&#xA;    circle.position.y *= z/-50&#xA;&#xA;    circle.theta_deg = np.random.rand(1) * 360&#xA;    circle.phi_deg = np.random.rand(1) * 360&#xA;&#xA;    theta_rad = circle.theta_deg * np.pi / 180&#xA;    phi_rad = circle.phi_deg* np.pi / 180&#xA;&#xA;&#xA;    circle.dx = speed * np.sin(-phi_rad - theta_rad) / frameRate&#xA;    circle.dy = -speed * np.cos(phi_rad + theta_rad) / frameRate&#xA;    circle.dz = -speed * np.cos(theta_rad) / frameRate&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Then, in the loop that plays the animation, and updates the position of each circle, I have put this condition following the same answer that was provided to the same kind of issue &lt;a href=&quot;https://stackoverflow.com/questions/58917165/keep-constant-number-of-visible-spheres-in-front-of-the-camera-in-3d-animation&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;max_dist = max(abs(circle.position.x),abs(circle.position.y))&#xA;limit_dist = 25 * abs((circle.position.z-near_z) / far_z)&#xA;&#xA;z_rel = np.random.uniform(near_z,far_z)&#xA;&#xA;if max_dist &amp;gt; limit_dist: &#xA;    circle.position.x = np.random.uniform(-25, 25) * z_rel/far_z&#xA;    circle.position.y = np.random.uniform(-25, 25) * z_rel/far_z&#xA;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I got a weird result as shown in GIF 2&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/k5leO.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/k5leO.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is wrong with my condition and how can I detect a circle that disappears from the frame and recreate one inside the frame? &lt;/p&gt;&#xA;" OwnerUserId="11191" LastActivityDate="2021-03-30T13:02:00.210" Title="Keep constant number of visible circles in 3D animation" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;projections&gt;&lt;perspective&gt;&lt;animation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9629" PostTypeId="2" ParentId="8247" CreationDate="2020-03-05T09:59:46.053" Score="3" Body="&lt;p&gt;This is easy to do in javascript or gl, but for expediency let's do it in mathematica. We first need the background image and an alpha mask:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;bg = ImageRotate[&#xA;   LinearGradientImage[&#xA;    RGBColor @@@ {{0.024, 0.051, 0.125}, {0.122, 0.078, &#xA;       0.212}, {0.216, 0.102, 0.275}, {0.216, 0.102, 0.275}}, {300, &#xA;     Round[300*1.394]}], -90 \[Degree]]&#xA;&#xA;mask = ImageRotate[&#xA;   LinearGradientImage[{Sequence @@ Table[RGBColor[0, 0, 0, 0], 5],&#xA;     RGBColor[0.09, 0.07, 0.196, .3],&#xA;     RGBColor[0.09, 0.07, 0.196, .9], &#xA;     RGBColor[0.023, 0.050, 0.125, 1]},&#xA;    {300, Round[300*1.394]}], 90 \[Degree]]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nTzUx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nTzUx.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we can draw the grid in 3D space using infinite lines:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;grid[j_ : 5] := Module[{g3d, b},&#xA;  Overlay[{Image[bg, ImageSize -&amp;gt; All], &#xA;    g3d = Graphics3D[{Thickness[0.005],RGBColor[0.905, 0.352, 0.713],&#xA;       Sequence @@ Table[InfiniteLine[{{0, i + j, 0}, {1, i + j, 0}}], {i, -10, 20}],&#xA;       Table[InfiniteLine[{{i, 0, 0}, {i, 1, 0}}], {i, -20, 20}]}, &#xA;      Boxed -&amp;gt; False, ViewAngle -&amp;gt; Pi/3, ViewVector -&amp;gt; {{0, -5, 6}, {0, -1, 2}}, Background -&amp;gt; None, PlotRange -&amp;gt; All, ImageSize -&amp;gt; is], &#xA;    b = Blur[Rasterize[g3d, RasterSize -&amp;gt; is], {20, 20}];&#xA;    Image[SetAlphaChannel[b, ColorNegate@ColorConvert[b, &quot;Grayscale&quot;]], &#xA;     ImageSize -&amp;gt; is]}, {1, 3, 2}]&#xA;  ]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Lastly, make some frames and export the animation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;frames = Table[Overlay[{grid[j], Image[mask, ImageSize -&amp;gt; All]}, All] , {j, 5, 6, .01}];&#xA;Export[&quot;~/grid.gif&quot;, frames, AnimationRepetitions -&amp;gt; \[Infinity]]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Et voila!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mjZG8.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mjZG8.gif&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9669" LastActivityDate="2020-03-05T09:59:46.053" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9630" PostTypeId="2" ParentId="9626" CreationDate="2020-03-05T10:53:28.280" Score="0" Body="&lt;p&gt;You don't seem to be setting circle.position.z&lt;/p&gt;&#xA;" OwnerUserId="3085" LastActivityDate="2020-03-05T10:53:28.280" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9631" PostTypeId="1" CreationDate="2020-03-06T22:37:52.930" Score="0" ViewCount="61" Body="&lt;p&gt;Pretty much the title, given a closed curve in 2D, defined by a set of points, and a point. What's the algorithm to calculate the winding number of that curve, point pair?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-12-05T09:02:35.260" Title="How do you compute the winding number of a closed poly curve?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;curve&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9632" PostTypeId="2" ParentId="9621" CreationDate="2020-03-07T09:15:25.650" Score="0" Body="&lt;p&gt;With the help of this article I was able to fix the problem. The problem was the the missing inversion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.bcnine.com/articles/water/water.md.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.bcnine.com/articles/water/water.md.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The working code is available via the above given links.&lt;/p&gt;&#xA;" OwnerUserId="11933" LastActivityDate="2020-03-07T09:15:25.650" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9633" PostTypeId="1" CreationDate="2020-03-07T11:07:11.363" Score="1" ViewCount="33" Body="&lt;p&gt;SHORT BACKGROUND: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am developing a neural network based model to differentiate benign and malignant ovarian tumors. I am working with transvaginal ultrasound images, some of which contains yellow markers as seen in the first image below. Without going into too mach details, there is a risk that the presence of the markers could introduce a bias that the network will be able to exploit. As a way of trying to counter this bias, I will insert semi-random markers to the images during training and validation as a type of image augmentation. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;PROBLEM:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;During training, I import the images (stored as JPEG-files) and convert them to NumPy arrays. &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Simply overlaying a marker is not good enough, since the marker would have a clear/sharp outline, while the &quot;real&quot;/already present markers are somewhat distorted due to anti-aliasing/JPEG-image compression.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I have some identical images with/without markers (e.g. first and second image below). After importing the two images as NumPy arrays the marker can be extracted by&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Option 1: ... subtracting one image from the other (see the third and fourth image below for the result). (Would result in incorrect pixel values for the marker.)&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Option 2: ... copying the image with markers and setting all cells to zero where the two images (with/without markers) are (almost) equal (see the fifth and sixth image below for the result).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;a) &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say, for simplicity, that the only thing that I wanted to achieve was to apply the extracted marker to a different transvaginal ultrasound image. How would I do that?&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Simply overlaying the marker would create black patches around the marker.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Simply adding the pixel values would result in incorrect pixel values for the marker.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;b)  (given that a) is solved)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's say that I now also want to be able to insert a marker of a different size and orientation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Orientation: I could rotate and move the marker.&#xA;Size: Any suggestion of how I could go about doing this? I still want the marker to have the same properties, i.e. simply stretching is not an option.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;from keras.preprocessing.image import load_img, img_to_array&#xA;from scipy.ndimage import rotate&#xA;import numpy as np&#xA;&#xA;# importing images as NumPy arrays&#xA;img1 = img_to_array(load_img('img1.jpg'))&#xA;img2 = img_to_array(load_img('img2.jpg'))&#xA;&#xA;&#xA;# option 1&#xA;img3 = img2-img1   # extracting the marker by subtracting the image arrays&#xA;img3 = img3[:-100] # getting rid of the yellow/grey marker in the down-right corner&#xA;&#xA;# option 2&#xA;img3 = img2[np.abs(img2 - img1) &amp;lt; 15] = 0&#xA;&#xA;&#xA;# rotating the image &#xA;img3 = rotate(img3, angle=-23.6)&#xA;&#xA;# cropping the image &#xA;img3_copy = img3.copy()&#xA;img3_copy[np.abs(img3_copy) &amp;lt; 10**-4] = 0&#xA;idx = np.nonzero(img3_copy)&#xA;img3 = img3[np.min(idx[0]):np.max(idx[0])+1, np.min(idx[1]):np.max(idx[1])+1]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KbujB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KbujB.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/U4yt5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/U4yt5.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/UWDt8.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UWDt8.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7g7BB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7g7BB.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nXzx1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nXzx1.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/L7dKC.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/L7dKC.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="12002" LastActivityDate="2020-03-07T11:07:11.363" Title="Extract object from image and apply it to different image" Tags="&lt;image-processing&gt;&lt;image&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9634" PostTypeId="2" ParentId="9606" CreationDate="2020-03-08T18:17:02.993" Score="2" Body="&lt;p&gt;Sorry about leaving it for so long but I was so busy implementing the goddamn algorithm, I forgot about this :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So after reading up on Veach's thesis pretty closely, I understood what was going on. First of all Veach's thesis describes about BDPT using MIS. However I implemented without MIS using the techniques described in the original Lafortune's paper.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One thing to note is, that we have to calculate the radiance by the light path inversely as opposed to the normal flow in the eye path. As lightxbulb said for point 1, there is no pdf since the step is deterministic. However the deterministic step needs to be multiplied by the Geometric factor, the BRDF evaluation of light vertex to eye vertex and the BRDF evaluation of eye vertex to light vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the second point, you don't have to worry about NEE since at each eye path vertex there is a path that connects to the light vertex directly, according to PBRT and the paper we can discard the already generated light source and use explicit light sampling there. Calculating the light path radiance separately (as done in light tracing) handles all the respective PDFs for generating the vertices there.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Will post another question regarding the result comparison soon.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2020-03-08T18:17:02.993" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9635" PostTypeId="1" CreationDate="2020-03-09T00:32:44.420" Score="1" ViewCount="76" Body="&lt;p&gt;Pantone spot colors are specified in the RGB and CMYK color models on the &lt;a href=&quot;https://pantone.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pantone.com&lt;/a&gt; website. For example, the &lt;a href=&quot;https://www.pantone.com/color-finder/122-C&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pantone 122 spot color as it appears when printed on coated paper&lt;/a&gt; is specified as RGB 254, 209, 65 and as CMYK 0, 9, 80, 0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since the RGB color is also specified as HEX/HTML #FED141, I assume that the color is specified in the sRGB color space, see &lt;a href=&quot;https://www.w3.org/TR/css-color-3/#rgb-color&quot; rel=&quot;nofollow noreferrer&quot;&gt;CSS Color Module Level 3, Section 4.2.1&lt;/a&gt;:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;All RGB colors are specified in the sRGB color space (see &lt;a href=&quot;https://www.w3.org/TR/css-color-3/#ref-SRGB&quot; rel=&quot;nofollow noreferrer&quot;&gt;[SRGB]&lt;/a&gt;). […]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;However, what would be the CMYK color space / color profile? My wild guess would be the U.S. Web Coated (SWOP) v2, which is the default CMYK color space in Photoshop, but there are many other color profiles, which produce different colors for the same CMYK quadruplet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, why are there separate CMYK quadruplets for the &lt;a href=&quot;https://www.pantone.com/color-finder/122-C&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pantone 122 spot color as it appears when printed on coated paper&lt;/a&gt; and &lt;a href=&quot;https://www.pantone.com/color-finder/122-U&quot; rel=&quot;nofollow noreferrer&quot;&gt;when printed on coated paper&lt;/a&gt;. I would expect a single CMYK quadruplet, which would result appear differently based on the paper used, just like there is just a single Pantone 122 spot color.&lt;/p&gt;&#xA;" OwnerUserId="12011" LastEditorUserId="12011" LastEditDate="2020-03-10T11:30:29.053" LastActivityDate="2020-03-11T16:13:23.213" Title="What is the CMYK color profile used by pantone.com" Tags="&lt;color&gt;&lt;color-management&gt;&lt;colorspace&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9636" PostTypeId="2" ParentId="9384" CreationDate="2020-03-09T17:12:24.550" Score="3" Body="&lt;p&gt;Referring to the answer that lightxbulb already gave, you can find a very in-depth explanation of the physics of light and their simulation in the thesis of Eric Veach named &quot;Robust Monte Carlo methods for light transport simulation&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read it for a class that I took in Computer Graphics and really liked it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can find it yourself by searching the web or by visiting this link:&#xA;&lt;a href=&quot;https://graphics.stanford.edu/papers/veach_thesis/thesis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://graphics.stanford.edu/papers/veach_thesis/thesis.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="12014" LastActivityDate="2020-03-09T17:12:24.550" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9638" PostTypeId="2" ParentId="9631" CreationDate="2020-03-10T08:55:29.667" Score="1" Body="&lt;p&gt;Winding number as in &lt;a href=&quot;https://en.wikipedia.org/wiki/Winding_number&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Winding_number&lt;/a&gt;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unless I'm mistaken, one way is to fire, say, a horizontal 'ray' out from your point towards, say, &lt;span class=&quot;math-container&quot;&gt;$+\infty$&lt;/span&gt;. Each time you cross an edge, &lt;span class=&quot;math-container&quot;&gt;$(V_n V_{n+1})$&lt;/span&gt; that is going up (i.e.&lt;span class=&quot;math-container&quot;&gt;$V_n[y] &amp;lt;V_{n+1}[y]$&lt;/span&gt;) , increment a counter, and decrement if the edge is going down.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The special cases of horizontal edges and vertices that lie on the ray are left as a (not too difficult) exercise for the reader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to do it quickly/approximately with a graphics API, you can use stencil buffers.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2020-03-10T08:55:29.667" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9639" PostTypeId="1" CreationDate="2020-03-10T17:35:21.667" Score="3" ViewCount="107" Body="&lt;p&gt;Upscaling a screenshot with subpixel antialiased text produces unpleasant color fringes, e.g. &lt;a href=&quot;https://computergraphics.stackexchange.com/q/2034/12022&quot;&gt;why does black text have orange and blue pixels&lt;/a&gt; This is especially annoying when trying to show an application on a projector, when you have to zoom in with a tool like the Windows &lt;a href=&quot;https://en.wikipedia.org/wiki/Magnifier_(Windows)&quot; rel=&quot;nofollow noreferrer&quot;&gt;Magnifier&lt;/a&gt; to show details to the audience.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are some solutions available to exploit the subpixel geometry of a display when &lt;em&gt;downscaling&lt;/em&gt; an image, e.g. &lt;a href=&quot;https://computergraphics.stackexchange.com/a/1431/12022&quot;&gt;https://computergraphics.stackexchange.com/a/1431/12022&lt;/a&gt;. Are there any solutions for the opposite, i.e. taking an image with subpixel rendering and producing an upscaled image without color artifacts? I imagine this task is much more difficult in the presence of both subpixel (text) and non-subpixel (the rest of the screenshot) content in the same image, though.&lt;/p&gt;&#xA;" OwnerUserId="12022" LastActivityDate="2020-03-10T17:35:21.667" Title="Upscaling screenshots with subpixel rendered text" Tags="&lt;image-processing&gt;&lt;subpixel-rendering&gt;&lt;font-rendering&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9640" PostTypeId="1" CreationDate="2020-03-13T14:30:34.903" Score="1" ViewCount="200" Body="&lt;p&gt;I'm working on an OpenGL compute shader in which each work item results in a single number output I'll call x, as well as a struct output with more information, I'll call y. What I would like is a single output for each work group being the y of the work item with the maximum x.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I'm aware of the GLSL atomic operations and I believe I could easily get the maximum x, but I'm having trouble thinking of how to get the y associated with the maximum x. I could, in the compute shader, do a conditional right after I check for maximum x to check if x changed and change y accordingly, but I believe there is no guarantee that no other work item has replaced the maximum x at that point. I think this might be possible with memory barriers but I'm having trouble figuring out if it really is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I guess my question is, is there an established method to do something like this? Am I perhaps over complicating it? Is there a way, with memory barriers, to create critical section-like behavior? Do I need to do the maximums on the CPU or in another serial compute shader?&lt;/p&gt;&#xA;" OwnerUserId="12033" LastEditorUserId="2654" LastEditDate="2020-03-13T14:42:27.277" LastActivityDate="2020-08-29T23:24:24.387" Title="OpenGL Compute Shader Shared Maximum" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9643" PostTypeId="1" CreationDate="2020-03-17T10:42:37.940" Score="0" ViewCount="100" Body="&lt;p&gt;So I've written a GPU based &lt;a href=&quot;https://github.com/gallickgunner/Yune&quot; rel=&quot;nofollow noreferrer&quot;&gt;pathtracer&lt;/a&gt; using OpenCL-GL interoperability. The system uses the Mega-Kernel Approach instead of a wavefront one as I was aiming it as an educational software for other young people who wanted to dive into raytracing/pathtracing but didn't want to mess with all the boilerplate code (opening windows, getting opengl context, etc) similar to coding it on shadertoy but with the added feature of loading models, having other benchmarking facilities etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I basically spawn as many work-items as there are pixels. Then each work-item shoots a single ray through that pixel and calculates the color. Currently on my GTX 1660, rendering around 5-6k Triangles give only 5-10 fps in 1280x720 resolution. I suppose its fairly slow even though I implemented a SAH based BVH and Möller–Trumbore ray-triangle intersection. Hence one big problem is that since the kernel takes too much time, loading big models causes a timeout error. I've already extended the timeout delay through the registery. In order to avoid it, I've also currently broken the image into 4 blocks and passed 4 mega kernels to do the job. This reduces the time of a single kernel, nevertheless the problem still remains.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've looked into the &lt;a href=&quot;https://www.researchgate.net/publication/258395638_The_Brigade_Renderer_A_Path_Tracer_for_Real-Time_Games&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; for Brigade renderer which is a realtime GPU pathtracer but couldn't understand what approach they followed. According to the text, they are talking about a single kernel per pixel,&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The path tracing algorithm can be efficiently implemented as on the&#xA;  GPU, using a single kernel per pixel. The kernel loops over the&#xA;  samples for a pixel and outputs the final color. This limits memory&#xA;  access to read-only scene access and a single write for the final&#xA;  pixel color.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;However the looping part is strange. If there is supposed to be a single kernel launched for every pixel, then the global work items or the threads must be the samples for that pixel. Why are they looping over the samples inside the kernel? &lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Secondly, I've also found &lt;a href=&quot;https://jacco.ompf2.com/2019/07/18/wavefront-path-tracing/&quot; rel=&quot;nofollow noreferrer&quot;&gt;sources&lt;/a&gt; that suggest that Brigade, infact used the wavefront approach?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I also realize the old Brigade demos are done with either a single or dual Titan X but the difference isn't that great. I admit I haven't taken cache coherency and such things into account but these are hard to do with the mega-kernel approach anyway. &lt;strong&gt;So in short the main crux of what I want to know is, Is the megakernel approach bound to give this FPS OR Am I doing something wrong here? Any tips on how I can improve the FPS for my mega-kernel pathtracer would be appreciated.&lt;/strong&gt; Link to the &lt;a href=&quot;https://github.com/gallickgunner/Yune/blob/master/kernels/legacy/udpt.cl&quot; rel=&quot;nofollow noreferrer&quot;&gt;kernel&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2020-03-17T10:49:52.500" LastActivityDate="2020-03-17T10:49:52.500" Title="How to achieve higher FPS for my GPU pathtracer?" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;gpgpu&gt;&lt;opencl&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9644" PostTypeId="1" CreationDate="2020-03-18T16:19:05.957" Score="0" ViewCount="60" Body="&lt;p&gt;Say I have constructed a path, using bidirectional path tracing (BDPT), consisting of a light subpath &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$s=2$&lt;/span&gt; vertices and a camera subpath &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$t=3$&lt;/span&gt; camera vertices.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I want to compute the contribution (measurement contribution over sampling density) of the same path considered under the BDPT strategy with &lt;span class=&quot;math-container&quot;&gt;$s'=3$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$t'=2$&lt;/span&gt; light and camera vertices, respectively.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doing this involves the computation of the density of sampling the direction &lt;span class=&quot;math-container&quot;&gt;$\omega_{y_{s-1}\to z_{t-1}}$&lt;/span&gt;. Assuming the path has positive luminance, can I expect this density to be positive?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm only considering &quot;lambertian reflection&quot; components of the involved BSDFs. Here's my example code in PBRT:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;auto const omega1 = pbrt::Normalize(z[t - 1].p() - y[s - 1].p());&#xA;auto const omega2 = y[s - 1].si.wo;&#xA;auto const p = y[s - 1].si.bsdf-&amp;gt;Pdf(omega1, omega2, lambertian_reflection);&#xA;&#xA;auto const c =&#xA;    g(scene, z[t - 1], y[s - 1]) *                          // g(Z_{t-1} ↔ Y_{s-1})&#xA;    z[t - 1].f(y[s - 1], pbrt::TransportMode::Radiance) *   // f_s(Y_{s-1} → Z_{t-1} → Z_{t-2})&#xA;    y[s - 1].f(z[t - 1], pbrt::TransportMode::Importance);  // f_s(Y_{s-2} → Y_{s-1} → Z_{t-1})&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I've encountered a situation where &lt;code&gt;c&lt;/code&gt; is nonzero, but the density &lt;code&gt;p&lt;/code&gt; is &lt;code&gt;0&lt;/code&gt; since internally &lt;code&gt;si.bsdf-&amp;gt;Pdf&lt;/code&gt; checks whether &lt;code&gt;omega1&lt;/code&gt; and &lt;code&gt;omega2&lt;/code&gt; are on the same side of the hemisphere induced by the normal at &lt;code&gt;y[s - 1]&lt;/code&gt; and they were not in that situation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, this is confusing. If they are not on the same side, shouldn't this imply that &lt;code&gt;y[s - 2]&lt;/code&gt; and &lt;code&gt;z[t - 1]&lt;/code&gt; are occluded from each other (and hence the geometry term &lt;code&gt;g(scene, z[t - 1], y[s - 1])&lt;/code&gt; should be &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt;?). Am I missing something?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: Note that the density of sampling a path of length &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; using the &lt;span class=&quot;math-container&quot;&gt;$(s,t)$&lt;/span&gt;-strategy is &lt;span class=&quot;math-container&quot;&gt;$q_{s,\:t}(x)=q_{0,\:t}(x_0,\ldots,x_{t-1})q_{s,\:0}(x_t,\ldots,x_k)$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$$\begin{equation}\label{eq:path-tracing-strategy}\begin{split}q_{0,\:t}(z)=&amp;amp;\prod_{i=1}^kg(z_{i-1}\leftrightarrow z_i)\left.\begin{cases}p_0\left(z_0,\omega_{z_0\to z_1}\right)&amp;amp;\text{, if }q_0(z_0)&amp;gt;0\\0&amp;amp;\text{, otherwise}\end{cases}\right\}\\&amp;amp;\prod_{i=2}^kp\left(z_{i-1},\omega_{z_{i-1}\to z_{i-2}},\omega_{z_{i-1}\to z_i}\right)\end{split}\end{equation}$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$p_0$&lt;/span&gt; is the density of sampling the inital camera ray (with respect to the path throughput measure as defined by Veach), &lt;span class=&quot;math-container&quot;&gt;$q_0$&lt;/span&gt; is the marginal density of sampling the initial vertex and &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is the conditional density (with respect to projected solid angle) of sampling the third argument given the first and second argument. The form of &lt;span class=&quot;math-container&quot;&gt;$q_{s,\:0}$&lt;/span&gt; is analogous.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT 2&lt;/strong&gt;: The relevant PBRT code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Float BxDF::Pdf(const Vector3f &amp;amp;wo, const Vector3f &amp;amp;wi) const {&#xA;    return SameHemisphere(wo, wi) ? AbsCosTheta(wi) * InvPi : 0;&#xA;}&#xA;&#xA;inline bool SameHemisphere(const Vector3f &amp;amp;w, const Vector3f &amp;amp;wp) {&#xA;    return w.z * wp.z &amp;gt; 0;&#xA;}&#xA;&#xA;// BSDF Method Definitions&#xA;Spectrum BSDF::f(const Vector3f &amp;amp;woW, const Vector3f &amp;amp;wiW,&#xA;                 BxDFType flags) const {&#xA;    ProfilePhase pp(Prof::BSDFEvaluation);&#xA;    Vector3f wi = WorldToLocal(wiW), wo = WorldToLocal(woW);&#xA;    if (wo.z == 0) return 0.;&#xA;    bool reflect = Dot(wiW, ng) * Dot(woW, ng) &amp;gt; 0;&#xA;    Spectrum f(0.f);&#xA;    for (int i = 0; i &amp;lt; nBxDFs; ++i)&#xA;        if (bxdfs[i]-&amp;gt;MatchesFlags(flags) &amp;amp;&amp;amp;&#xA;            ((reflect &amp;amp;&amp;amp; (bxdfs[i]-&amp;gt;type &amp;amp; BSDF_REFLECTION)) ||&#xA;             (!reflect &amp;amp;&amp;amp; (bxdfs[i]-&amp;gt;type &amp;amp; BSDF_TRANSMISSION))))&#xA;            f += bxdfs[i]-&amp;gt;f(wo, wi);&#xA;    return f;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT 3&lt;/strong&gt;: Here is an example: PBRT is using a local coordinate system for shading where the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;-axis is aligned with the shading normal. The following picture shows the local coordinates of the geometric normal at &lt;span class=&quot;math-container&quot;&gt;$y_1$&lt;/span&gt;, the direction &lt;code&gt;wi&lt;/code&gt; from &lt;span class=&quot;math-container&quot;&gt;$y_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$z_2$&lt;/span&gt; and the direction &lt;code&gt;wo&lt;/code&gt; from &lt;span class=&quot;math-container&quot;&gt;$y_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$y_0$&lt;/span&gt;,&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;wi = (0.93675665128065100,0.34934790470253263,-0.021047987110668076)&#xA;wo = (0.37751541702974800,0.28880688322120657,0.87981401108922330)&#xA;ng (local) = (0.025315795417292675,-0.0035753744029505263,0.99967311017165450)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7RDSl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7RDSl.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;ng&lt;/code&gt; is slightly off from the shading normal &lt;code&gt;ns = (0,0,1)&lt;/code&gt;. With respect to &lt;code&gt;ng&lt;/code&gt;, &lt;code&gt;wi&lt;/code&gt; and &lt;code&gt;wo&lt;/code&gt; are in the same hemisphere, but with respect to &lt;code&gt;ns&lt;/code&gt; they are not.&lt;/p&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="9254" LastEditDate="2020-03-19T17:08:00.160" LastActivityDate="2020-03-19T17:08:00.160" Title="Considering a path generated by bidirectional path tracing under a different strategy" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;global-illumination&gt;&lt;pbr&gt;&lt;pbrt&gt;" AnswerCount="0" CommentCount="23" ContentLicense="CC BY-SA 4.0" />
  <row Id="9645" PostTypeId="1" CreationDate="2020-03-19T08:14:42.133" Score="1" ViewCount="81" Body="&lt;p&gt;I am learning Perlin Noise, the original version and the improved version. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the paper  which Ken Perlin wrote in 2002. He said &quot;The second deficiency is that whereas the gradients in G are&#xA;distributed uniformly over a sphere, the cubic grid itself has&#xA;directional biases, being shortened along the axes and elongated&#xA;on the diagonals between opposite cube vertices. This directional&#xA;asymmetry tends to cause a sporadic clumping effect, where&#xA;nearby gradients that are almost axis-aligned, and therefore close&#xA;together, happen to align with each other, causing anomalously&#xA;high values in those regions&quot;. Here I can not understand what means &quot;directional biases, being shortened along the axes and elongated&#xA;on the diagonals between opposite cube vertices.&quot; and why it causing &quot;axis-aligned clumping&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could anyone help me out? Thank you.&lt;/p&gt;&#xA;" OwnerUserId="12046" LastActivityDate="2020-12-15T17:07:20.723" Title="Why the gradients generated in original Perlin Noise causing axis-aligned clumping?" Tags="&lt;noise&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9648" PostTypeId="2" ParentId="9645" CreationDate="2020-03-20T15:36:50.423" Score="1" Body="&lt;p&gt;Very briefly, Perlin noise ideally is meant to have, on average, the same frequency characteristics no matter where in the texture you are or in what direction you are looking.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the way it's done is to define pseudo-random values (and derivatives) on a regular 3D grid which introduces some compromises.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To make this easier to understand, imagine instead using just a 2D grid, and on every grid location with an even-numbered X coordinate, you set the value to 0.0, and on every odd X, 1.0.  So at (0,0), (2,0), (4,99) etc you have 0.0, while at at (1,0) etc, you have 1.0.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you followed a horizontal line, e.g (0,0) (1,0) (2,0) etc, it would go up and down, in a sine-wave-like pattern every 2 steps, but if you followed it in a diagonal direction,  (0,0), (1,1), (2,2,) then, per distance traveled, it would go up and down more slowly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I believe that is what Perlin is referring to.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2020-03-20T15:36:50.423" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9649" PostTypeId="1" AcceptedAnswerId="9650" CreationDate="2020-03-20T16:18:40.100" Score="2" ViewCount="59" Body="&lt;p&gt;I am trying to mimic reflections in image composition using shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have gotten this far:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xm92r.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xm92r.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this image the floor is &quot;reflecting&quot; the back wall, however the reflection is uncanny because the scale and the positions of the objects are very wrong. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example the plant is nowhere even close to where it should be. Assuming I have a ground truth set of values for the camera parameters, is there a way I could &quot;move&quot; the reflections to better match what I expect to see? It doesn't have to be perfect, just better than what I have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The way I am generating the image is the same as learnopengl's code:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void main()&#xA;{             &#xA;    float ratio = 1.00 / 1.52;&#xA;    vec3 I = normalize(Position - cameraPos);&#xA;    vec3 R = refract(I, normalize(Normal), ratio);&#xA;    FragColor = vec4(texture(skybox, R).rgb, 1.0);&#xA;}  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;An important thing I should mention is, I don't have geometry, just a still image and information of where the floor is. So I don't have any depth, normals, or anything like that for most of the image. &lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-03-21T16:15:47.757" LastActivityDate="2020-03-22T01:38:09.063" Title="Controlling &quot;zoom&quot; and &quot;position&quot; of a cubemap in shaders" Tags="&lt;rendering&gt;&lt;image-processing&gt;&lt;reflection&gt;&lt;mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9650" PostTypeId="2" ParentId="9649" CreationDate="2020-03-21T14:57:57.880" Score="2" Body="&lt;p&gt;Reflections based on a cubemap best represent a reflection at infinity. That is, since the only factor that a cubemap provides is direction, the cubemap acts as though it were at a distance from the reflective surface where only the direction to the reflecting objects matters. And that only happens if the reflecting objects are infinitely far from the reflective surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That works fine for reflecting distant environmental details like skies or distant landscapes. But it's not going to work with anything even remotely close to the reflective surface. And if the reflecting object and a reflective surface touch, then you can basically forget about it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cubemap reflections are simply not the right tool for this scene. You will instead have to employ other strategies for reflections, like rendering the back wall under the reflective surface (using transparency of the reflective surface to create the appearance of reflection), or doing screen-space reflections or something like that.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I don't have geometry, just a still image and information of where the floor is. So I don't have any depth, normals, or anything like that for most of the image.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If you don't have geometry information or any equivalent to it, then you're pretty much out of luck. Accurate reflection of a scene requires knowing where the scene being reflected is relative to each point on the reflective surface. Even if the surface of reflection itself is flat, the reflected &lt;em&gt;scene&lt;/em&gt; isn't. If you don't have some approximation of geometry information, and you cannot generate such a thing, then you cannot generate an accurate reflection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If computer vision algorithms are available to you, I would suggest trying to fine one that can reconstruct the depth information of the scene from a single image. If that's not feasible, then you're going to have to live with an inaccurate reflection in one way or another.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-03-22T01:38:09.063" LastActivityDate="2020-03-22T01:38:09.063" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9651" PostTypeId="1" CreationDate="2020-03-21T18:05:26.417" Score="0" ViewCount="53" Body="&lt;p&gt;Can you please recommend some topic for research work related to mathematics in CG?&#xA;(Maybe something like &quot;Affine transformations in CG&quot;) &lt;/p&gt;&#xA;" OwnerUserId="12055" LastActivityDate="2020-03-21T18:05:26.417" Title="Mathematics in Computer Graphics" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;vector-graphics&gt;&lt;vectors&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9653" PostTypeId="1" CreationDate="2020-03-23T08:56:46.630" Score="1" ViewCount="27" Body="&lt;p&gt;I was making some circles in the HTML Canvas element and the circles were so smooth. In a sense that you cant see any vertices. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I normally work in unity and I you make a shape in 3d you most of the time see vertices (aka not a perfectly smooth circle). It only really looks smooth if you crank the vertices count up to something like 100 - 150 But this would be highly inefficient to render. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;So now my question: How does HTML canvas manage to draw such smooth circles? Is this A: with a very high vertices count, or B: some other magic is used if so how do they do it?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let me know if anything is unclear or needs extra information. &lt;/p&gt;&#xA;" OwnerUserId="11458" LastActivityDate="2020-03-23T08:56:46.630" Title="How are 2D graphics rendered in HTML canvas" Tags="&lt;performance&gt;&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9654" PostTypeId="1" CreationDate="2020-03-23T13:34:43.387" Score="1" ViewCount="131" Body="&lt;p&gt;I am currently having an issue with OpenGL as I am trying to load some vector information into a 3D texture. Currently, I am developing in OpenGL 4.6 which should support Image bindings. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;this my code to bind the texture to an image: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;field_sbo);&#xA;glBindTexture(GL_TEXTURE_3D, field_sbo);&#xA;glTextureStorage3D(field_sbo, 1, GL_RGB32F, 10,10,10);&#xA;glTextureSubImage3D(field_sbo, 0, 0, 0, 0, 10, 10, 10, GL_RGB, GL_FLOAT, vector_data);&#xA;glBindImageTexture(0, field_sbo, 0, GL_TRUE, 0, GL_READ_ONLY, GL_RGB32F);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Additionally, this is the declaration in the compute shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;layout(binding = 0, RGB32F) uniform image3D field;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;From my understanding, the glTextureStorage3D should make the texture immutable, however I keep getting an INVALID_VALUE at the glBindImageTexture stage. I have looked at the documentation for the errors however I cannot seem to fix the issue.&lt;/p&gt;&#xA;" OwnerUserId="12059" LastActivityDate="2020-08-21T07:02:40.317" Title="glBindImageTexture returning INVALID_VALUE" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;3d&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9658" PostTypeId="2" ParentId="9654" CreationDate="2020-03-24T04:47:24.357" Score="2" Body="&lt;p&gt;Outside of &lt;code&gt;GL_R11F_G11F_B10F&lt;/code&gt;, 3-channel formats are &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Load_Store#Images_in_the_context&quot; rel=&quot;nofollow noreferrer&quot;&gt;not allowed for image load/store&lt;/a&gt;. And you'll note that &lt;code&gt;rgb32f&lt;/code&gt; is &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Load_Store#Format_qualifiers&quot; rel=&quot;nofollow noreferrer&quot;&gt;not in the list of valid format qualifiers for GLSL variables&lt;/a&gt;, nor are any other 3-channel formats (except &lt;code&gt;r11f_g11f_b10f&lt;/code&gt;).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-03-24T04:47:24.357" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9661" PostTypeId="1" CreationDate="2020-03-25T16:07:03.117" Score="1" ViewCount="45" Body="&lt;p&gt;I got a function that generates samples from a GGX visible normal distribution function. When I use it to calculate reflection directions obviously some of these intersect with the surface agin (negative).&#xA;These bas samples become more of an issue if the roughness increases.&#xA;How to handle this case ?&lt;/p&gt;&#xA;" OwnerUserId="12069" LastActivityDate="2020-03-27T07:26:21.390" Title="How to handle negative reflection directions in raytracing?" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;pbr&gt;&lt;sampling&gt;&lt;ggx&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9662" PostTypeId="1" CreationDate="2020-03-25T21:39:24.360" Score="1" ViewCount="21" Body="&lt;p&gt;I am designing a 2D drawing library (it is its very early stages) and I was wondering what to do with Alpha (transparency). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have two trains of thought:  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;A. Implement Alpha in the Color class since it affects the eventual color. The color red (255, 0, 0, 255) looks totally different from the color (255, 0, 0, 127) both on a white background. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;B. Implement the Alpha value in the Shape class containing all base properties for a shape like position, color (in this case color would only contain r, g, b values), stroke weight etc. This could also work since Alpha would affect the entire object. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;What do you guys think makes more sense? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Side notes:&lt;br&gt;&#xA;If Alpha would be part of Shape it would be harder to quickly change colors and reassign them. &#xA;But this would make it easier to implement functions like color mixing etc in the color class. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;(let me know if this is the place to ask this, I was also thinking about software engineering stack exchange. But this seemed to make more sense)&lt;/p&gt;&#xA;" OwnerUserId="11458" LastActivityDate="2020-03-25T21:39:24.360" Title="Alpha part of color class or shape class" Tags="&lt;color&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9664" PostTypeId="2" ParentId="4248" CreationDate="2020-03-26T08:06:08.493" Score="1" Body="&lt;p&gt;Just to add to the answers above:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://graphics.pixar.com/library/DistributedRayTracing/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Distributed Ray Tracing&lt;/a&gt; (Cook, Porter, &amp;amp; Carpenter).  Allows you to simultaneously do spatial AA, temporal AA (i.e. motion blur), and focus/depth of field.  Best to read the paper, but basically the N-rays you fire per pixel can also be assigned pseudo-random times (for motion blur) and positions on a lens (to get focus effects).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Adaptive Supersampling: You initially fire a certain number of rays per pixel. However, if the rays in a local neighbourhood return significantly different results, then you can &lt;em&gt;locally&lt;/em&gt; increase the sampling rate (say 2x), to improve the results. You can opt to repeat the process.&#xA;It's not perfect since objects can still 'fall between the samples', but it's possibly cheaper than uniformly sampling at a higher rate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.cs.yorku.ca/~amana/research/cones.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray tracing with cones&lt;/a&gt; (Amanatides): Instead of using an infinitely thin ray, each ray is instead approximated by a cone, say with a diameter that covers all of the pixel (and a little of the neighbours) allowing you to do evaluate partial coverage. It also has benefits for texture sampling/antialiasing, soft shadows, and potentially LOD of models. I did an implementation &lt;em&gt;many&lt;/em&gt; years ago - it's certainly more difficult to do, but does avoid a lot of additional rays.&#xA;IIRC there was also a scheme called pencil tracing (but my initial search didn't find a link to the paper)&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2020-03-26T08:06:08.493" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9667" PostTypeId="1" CreationDate="2020-03-27T12:34:20.123" Score="0" ViewCount="84" Body="&lt;p&gt;I'm trying to implement Perlin Noise. Earlier I implemented it using HTML Canvas and then converted it to WebGL2 since I wanted a faster implementation. But the WebGL2 code has obvious edge artifacts in the generated noise where the noise function is not smooth.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I used &lt;a href=&quot;https://flafla2.github.io/2014/08/09/perlinnoise.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Understanding Perlin Noise&lt;/a&gt; as my reference for understanding Perlin Noise. However, I did use a different implementation for calculating the dot product of the gradient and distance vectors since I could not get the default implementation to work.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the resulting noise that I'm getting:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/1oz6b.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1oz6b.png&quot; alt=&quot;Perlin Noise with edges&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the noise I was getting in my Canvas implementation:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/WdN3V.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WdN3V.png&quot; alt=&quot;Canvas Perlin Noise&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My algorithm for both the Canvas and WebGL is the same. I have attached my WebGL code below. Any ideas why this is happening?&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;let gl = canvas.getContext(&quot;webgl2&quot;);&#xA;if (!gl) {&#xA;    console.log(&quot;WebGL2 support not found&quot;);&#xA;}&#xA;&#xA;let octaveCount = 6;&#xA;let persistence = 1.0;&#xA;&#xA;canvas.width = window.innerWidth;&#xA;canvas.height = window.innerHeight;&#xA;&#xA;const vertexSrc = `&#xA;#version 300 es&#xA;precision mediump float;&#xA;&#xA;vec2 quad[6] = vec2[](&#xA;    vec2(-1.0, -1.0),&#xA;    vec2(-1.0, 1.0),&#xA;    vec2(1.0, -1.0),&#xA;    vec2(-1.0, 1.0),&#xA;    vec2(1.0, -1.0),&#xA;    vec2(1.0, 1.0)&#xA;);&#xA;&#xA;void main() {&#xA;    gl_Position = vec4(quad[gl_VertexID], 0.0, 1.0);&#xA;}&#xA;`;&#xA;&#xA;const fragmentSrc = `&#xA;#version 300 es&#xA;precision mediump float;&#xA;&#xA;uniform vec2 offset;&#xA;uniform int octaveCount;&#xA;uniform float persistence;&#xA;uniform vec2 resolution;&#xA;out vec4 color;&#xA;&#xA;int p[256] = int[](151,.../*abbreviated for conveinence*/..180);&#xA;&#xA;vec2 grad[256] = vec2[](&#xA;    vec2(1, 0),.../*abbreviated for conveinence*/...vec2(0.999698818696, -0.0245412285229)&#xA;);&#xA;&#xA;float fade(float t) {&#xA;    return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);&#xA;}&#xA;&#xA;vec2 getVec(int xi, int yi) {&#xA;    int a = p[xi &amp;amp; 255];&#xA;    int b = p[yi &amp;amp; 255];&#xA;    int val = p[(a + b) &amp;amp; 255];&#xA;    return grad[val];&#xA;}&#xA;&#xA;float perlinAux(vec2 st) {&#xA;    int xi = int(round(st.x)) &amp;amp; 255;&#xA;    int yi = int(round(st.y)) &amp;amp; 255;&#xA;    float xf = st.x - float(xi);&#xA;    float yf = st.y - float(yi);&#xA;    float u = fade(xf);&#xA;    float v = fade(yf);&#xA;&#xA;    float n00 = dot(vec2(xf, yf), getVec(xi, yi));&#xA;    float n01 = dot(vec2(xf, yf - 1.0), getVec(xi, yi + 1));&#xA;    float n10 = dot(vec2(xf - 1.0, yf), getVec(xi + 1, yi));&#xA;    float n11 = dot(vec2(xf - 1.0, yf - 1.0), getVec(xi + 1, yi + 1));&#xA;&#xA;    float x1 = mix(n00, n10, u);&#xA;    float x2 = mix(n01, n11, u);&#xA;    return (mix(x1, x2, v) + 1.0) / 2.0;&#xA;}&#xA;&#xA;float perlin(vec2 offset, vec2 st, int octaveCount, float persistence) {&#xA;    float total = 0.0;&#xA;    float freq = 1.0;&#xA;    float amp = 1.0;&#xA;    float maxValue = 0.0;&#xA;    for (int i = 0; i &amp;lt; octaveCount; i++) {&#xA;        total += perlinAux(offset + st * freq) * amp;&#xA;        maxValue += amp;&#xA;        amp *= persistence;&#xA;        freq *= 2.0;&#xA;    }&#xA;&#xA;    return total / maxValue;&#xA;}&#xA;&#xA;void main() {&#xA;    vec2 st = gl_FragCoord.xy / resolution;&#xA;    float perlinVal = perlin(offset, st, octaveCount, persistence);&#xA;    color = vec4(perlinVal, perlinVal, perlinVal, 1.0);&#xA;}&#xA;`;&#xA;&#xA;function compileShader(shaderSource, shaderType) {&#xA;    const shader = gl.createShader(shaderType);&#xA;    gl.shaderSource(shader, shaderSource);&#xA;    gl.compileShader(shader);&#xA;    if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {&#xA;        throw &quot;Shader compile failed with: &quot; + gl.getShaderInfoLog(shader);&#xA;    }&#xA;    return shader;&#xA;}&#xA;&#xA;const vertexShader = compileShader(vertexSrc.trim(), gl.VERTEX_SHADER);&#xA;const fragmentShader = compileShader(fragmentSrc.trim(), gl.FRAGMENT_SHADER);&#xA;&#xA;const program = gl.createProgram();&#xA;gl.attachShader(program, vertexShader);&#xA;gl.attachShader(program, fragmentShader);&#xA;gl.linkProgram(program);&#xA;if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {&#xA;    throw &quot;Program link failed with: &quot; + gl.getProgramInfoLog(program);&#xA;}&#xA;&#xA;const offsetLOC = gl.getUniformLocation(program, &quot;offset&quot;);&#xA;const resolutionLOC = gl.getUniformLocation(program, &quot;resolution&quot;);&#xA;const octaveCountLOC = gl.getUniformLocation(program, &quot;octaveCount&quot;);&#xA;const persistenceLOC = gl.getUniformLocation(program, &quot;persistence&quot;);&#xA;&#xA;gl.useProgram(program);&#xA;gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);&#xA;gl.clearColor(0, 0, 0, 1.0);&#xA;gl.clear(gl.COLOR_BUFFER_BIT);&#xA;&#xA;gl.uniform2f(offsetLOC, 0.0, 0.0);&#xA;gl.uniform2f(resolutionLOC, gl.canvas.width, gl.canvas.height);&#xA;gl.uniform1i(octaveCountLOC, octaveCount);&#xA;gl.uniform1f(persistenceLOC, persistence);&#xA;&#xA;gl.drawArrays(gl.TRIANGLES, 0, 6);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="12080" LastActivityDate="2020-04-27T21:07:20.847" Title="Perlin Noise implementation looks blocky in WebGL2" Tags="&lt;algorithm&gt;&lt;noise&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9668" PostTypeId="1" AcceptedAnswerId="9684" CreationDate="2020-03-28T01:10:59.903" Score="2" ViewCount="76" Body="&lt;p&gt;What are some common techniques for making the edges on a tesselated shape less apparent without increasing the amount of tesselation which is actually carried out?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an example, I followed along with this tutorial on &lt;a href=&quot;https://prideout.net/blog/old/blog/index.html@p=48.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;tesselation shaders&lt;/a&gt;, and one can control the inner and outer tesselation levels. With relatively low levels of both, one can achieve a pretty good sphere. However, in order for the surface to actually appear smooth, a fairly bright light seems to be required.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This particular implementation uses triangular tesselation beginning from an icosahedron to approach a sphere.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My understanding is that performing the tesselation with quads would result in a smoother surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a picture which illustrates how direct lighting makes it much harder to see the level of tesselation. On the top right of the sphere, where the light is hitting it strongly, no edges are visible, wheres on the bottom left, the edges can easily be seen. Perhaps in practice, simply applying a texture would mask many of the edges?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/c1XR6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c1XR6.png&quot; alt=&quot;tesselation and lighting&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="12073" LastEditorUserId="9438" LastEditDate="2020-04-14T23:26:44.477" LastActivityDate="2020-04-14T23:26:44.477" Title="Techniques for making tesselated shapes appear smoother?" Tags="&lt;opengl&gt;&lt;lighting&gt;&lt;tesselation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9669" PostTypeId="2" ParentId="9668" CreationDate="2020-03-28T06:58:57.670" Score="-1" Body="&lt;p&gt;&lt;code&gt;glShadeModel(GL_SMOOTH);&lt;/code&gt; - probably in PezInitialize - should do what you need.&lt;/p&gt;&#xA;" OwnerUserId="8125" LastActivityDate="2020-03-28T06:58:57.670" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9670" PostTypeId="1" CreationDate="2020-03-28T10:51:48.310" Score="0" ViewCount="37" Body="&lt;p&gt;I am having trouble in making this program and DFA:-&#xA;Write CPP program, DFA and NFA diagram for DFA accepting string with &#xA;length 5 and starting at 0 , ending at 1 input(0, 1).&lt;/p&gt;&#xA;" OwnerUserId="12082" LastEditorUserId="12082" LastEditDate="2020-03-28T11:26:39.187" LastActivityDate="2020-03-28T11:26:39.187" Title="Write CPP program, DFA and NFA diagram for DFA accepting string with length 5 and starting at 0 , ending at 1 input(0, 1)" Tags="&lt;c++&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9671" PostTypeId="1" AcceptedAnswerId="9696" CreationDate="2020-03-28T18:27:57.937" Score="2" ViewCount="160" Body="&lt;p&gt;I'm a noob to the OpenGL world and am picking up ideas through practice. I've been writing some code to build retro-arcade games recently and need to load textures to provide the graphic interface. I'm using OpenGL v4.6 with GLFW3 and the stb library to load images. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;To load textures, I draw a box and define the texture coordinates of the image on the box. Only some of the png's that I use have loaded properly- often, the image is blurred and distorted. There were two things I tried so far-&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Look exclusively for jpg files as these were loading properly. But most of the textures that I download of google are exclusively png&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Convert the png into a jpg file. Since I was converting, I decided to use other file formats as well, cropping some of the images if need be. I used GIMP to export them in jpg format. However, when I try to load it OpenGL, I still get bad-poor results.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Another possible approach I'm considering is to convert them into dxt formats and see if that does the trick. However, this seems a tad too tedious and something I'd only go for if nothing else works. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Below is the code that I'm using to load the image. &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int width, height, nrChannels;&#xA;unsigned char* data = stbi_load(file_path, &amp;amp;width, &amp;amp;height, &amp;amp;nrChannels, 0);&#xA;GLenum format{};&#xA;if (data)&#xA;{&#xA;    if (nrChannels == 1)&#xA;        format = GL_RED;&#xA;    else if (nrChannels == 3)&#xA;        format = GL_RGB;&#xA;    else if (nrChannels == 4)&#xA;        format = GL_RGBA;&#xA;    glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);&#xA;    glGenerateMipmap(GL_TEXTURE_2D);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I'm starting to spend a significant amount of time looking for images that will load properly and less time learning/implementing; this is quite concerning. Can someone please point out where I'm going wrong or a better way of skirting around this issue?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/p5Zz9.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/p5Zz9.png&quot; alt=&quot;The image to the left is the original as loaded by OpenGL (jfif file format). The one to the bottom is the edited version (made with Gimp, stored as jpg). The image to the right is the render of the bottom image in OpenGL&quot;&gt;&lt;/a&gt;&#xA;The image to the left is the original as loaded by OpenGL (jfif file format). The one to the bottom is the edited version (made with Gimp, stored as jpg). The image to the right is the render of the bottom image in OpenGL&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jORfg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jORfg.png&quot; alt=&quot;Example 2&quot;&gt;&lt;/a&gt;&#xA;Again, the image to the left is the output from Opengl while the one to the right is the original image. Note the inclination of the render and lack of colour in it. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;Edit: Here are some of the implementation details-&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm believe this portion should be correct because the render is perfect for .jpg files. &lt;em&gt;rect&lt;/em&gt; is a vector to hold the box and texture coordinates and &lt;em&gt;ind&lt;/em&gt; is a vector that holds the indices that are used by the element buffer to avoid repeat drawing. Both are initialised as arrays and converted into a vector (loop through array and push_back into vector). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;PS. Apologies for the verbosity. I was trying to couch the drawing inside a class and this was my first attempt at it. So, please bear with me.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Box container to hold images&#xA;//             x      y   tex-x   tex-y    &#xA;const float rect[] = {&#xA;            -0.2f, -0.2f, 0.0f, 0.0f,&#xA;             0.2f, -0.2f, 1.0f, 0.0f,&#xA;             0.2f,  0.2f, 1.0f, 1.0f,&#xA;            -0.2f,  0.2f, 0.0f, 1.0f&#xA;    };&#xA;&#xA;int ind[] = {&#xA;        0,1,2,&#xA;        0,2,3&#xA;    };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;_num_attr_ is the number of attributes given to the vao, which in this case is 2. &lt;em&gt;cumsum&lt;/em&gt; contains the sum of the number of attributes and is used to assign the stride and size of each attribute.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;sizes = {2,2}; // initialized &#xA;cumsum = 0;&#xA;for (int i = 0; i &amp;lt; num_attr; ++i)&#xA;{&#xA;    attr_num_cumsum.push_back(cumsum);&#xA;    cumsum += sizes[i];&#xA;    attr_size.push_back(sizes[i]);  &#xA;}&#xA;attr_num_cumsum.push_back(cumsum);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;At the end of this block, &lt;em&gt;cumsum&lt;/em&gt; has a value of 4 and _attr_num_cumsum_ = {0,2,4} and _attr_size_ = {2,2}.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;_vbo_data_ contains the values in &lt;em&gt;rect&lt;/em&gt; while _ebo_data_ contains the values in &lt;em&gt;ind&lt;/em&gt; Here is the buffer set-up for drawing-&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(vao);&#xA;glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;glBufferData(GL_ARRAY_BUFFER, vbo_data.size()*sizeof(GL_FLOAT), &amp;amp;vbo_data[0], GL_DYNAMIC_DRAW);&#xA;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);&#xA;glBufferData(GL_ELEMENT_ARRAY_BUFFER, ebo_data.size()*sizeof(GL_INT), &amp;amp;ebo_data[0], GL_DYNAMIC_DRAW);&#xA;for (int i = 0; i &amp;lt; num_attr; ++i)&#xA;{&#xA;    glVertexAttribPointer(i, attr_size[i], GL_FLOAT, GL_FALSE, attr_num_cumsum[num_attr] * sizeof(GL_FLOAT), (void*)(attr_num_cumsum[i] * sizeof(GL_FLOAT)));&#xA;    glEnableVertexAttribArray(i);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And the actual drawing&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glBindVertexArray(vao);&#xA;glDrawElements(GL_TRIANGLES, num_vertices, GL_UNSIGNED_INT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Vertex Shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;layout(location = 0) in vec2 aPos;&#xA;layout(location = 1) in vec2 tex;&#xA;out float C;&#xA;out vec2 Tex;&#xA;uniform mat4 model;&#xA;uniform float col;&#xA;void main()&#xA;{&#xA;    gl_Position = model*vec4(aPos.x,aPos.y,0.0f, 1.0f);&#xA;    C=col;&#xA;    Tex=tex;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Fragment Shader&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;out vec4 Fragcolor;&#xA;in float C;&#xA;in vec2 Tex;&#xA;uniform sampler2D texture1;&#xA;void main()&#xA;{&#xA;    Fragcolor = texture(texture1,Tex);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13083" LastEditorUserId="6" LastEditDate="2020-04-09T15:18:44.583" LastActivityDate="2020-04-09T15:18:44.583" Title="Texture loading- erratic working" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9672" PostTypeId="2" ParentId="9667" CreationDate="2020-03-28T20:49:46.400" Score="1" Body="&lt;p&gt;I made a mistake while translating the code from JavaScript to GLSL. The first line in the &lt;code&gt;perlinAux&lt;/code&gt; function:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;int xi = int(round(st.x)) &amp;amp; 255;&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It uses the round() function even though it is not necessary. Moreover, it seems that the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/round.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;rounding direction can be implementation-specific&lt;/a&gt;. Changing it to simply &lt;code&gt;int xi = int(st.x) &amp;amp; 255&lt;/code&gt; solves the problem.&lt;/p&gt;&#xA;" OwnerUserId="12080" LastActivityDate="2020-03-28T20:49:46.400" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9673" PostTypeId="1" CreationDate="2020-03-28T21:43:03.300" Score="0" ViewCount="92" Body="&lt;p&gt;I am learning about fragment shaders and have seen how by setting the colours of each vertex a triangle can be coloured via interpolation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sxTXz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sxTXz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However what if we want to use our own function to manually specify the colour of each fragment (e.g. for lighting or for creating a procedurally generated texture)?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any way to create a fragment shader that runs a user-defined function to determine the colour of each fragment instead of leaving it up to opengl to interpolate between vertex colours?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an example - is it possible to create a fragment shader that sets each fragment to a random colour? Or one that creates a striped effect by setting pixels between a certain x range to black and others to white?&lt;/p&gt;&#xA;" OwnerUserId="13085" LastEditorUserId="13085" LastEditDate="2020-03-29T12:54:03.197" LastActivityDate="2020-03-29T12:54:03.197" Title="Specifying Fragment Shader Colors per Fragment (Instead of per Vertex)" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9674" PostTypeId="2" ParentId="9640" CreationDate="2020-03-28T23:14:00.520" Score="1" Body="&lt;p&gt;You can figure out which thread has the max value by modifying x: pack gl_LocalInvocationIndex in the least significant bits of x. The number of bits you need for the index depends on your group size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need all 32 bits of x then I suggest using 2 compute shaders - first record max per group. Then compute x again and compare.&lt;/p&gt;&#xA;" OwnerUserId="10658" LastActivityDate="2020-03-28T23:14:00.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9676" PostTypeId="1" AcceptedAnswerId="9879" CreationDate="2020-03-29T09:08:28.303" Score="2" ViewCount="531" Body="&lt;p&gt;I am relatively new to compute shaders and gpgpu in general so bear with me if i am missing the point somewhere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main thing i do not yet understand / see is how to get memory from a compute shader to global shader memory usable in a pixel shader without passing it back and forth between GPU and CPU. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am implementing an irradiance caching lighting solution with Unity3D for learning purposes. I have written a compute shader that calculates the spherical harmonic coefficients for each volume. Now i can go ahead and read those values back to gpu using buffer.GetData() on the cpu side and shader.SetGlobalVectorArray(), but as far as I understand that will copy the memory to CPU resulting in allocation overhead. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have seen similar posts where people were suggesting just doing the computation in a pixel shader to begin with, but i don't see how that is supposed to help? Which pixel shader and how? I only want these computations to be done once for each volume and they require parallel reduction. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Potentially my search terms are inadequate but i cannot find any answer to how to get results from compute shaders to global shader memory. &#xA;Thanks in advance &lt;/p&gt;&#xA;" OwnerUserId="11386" LastEditorUserId="209" LastEditDate="2020-03-30T06:39:03.923" LastActivityDate="2020-05-28T10:27:10.550" Title="Sharing memory between compute shader and pixel shader" Tags="&lt;compute-shader&gt;&lt;unity&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9677" PostTypeId="1" CreationDate="2020-03-29T19:52:41.857" Score="1" ViewCount="72" Body="&lt;p&gt;I can't manage to produce a metallic looking sphere despite trying many things. I have the basics working, i.e shadows, refraction etc. but I'm not sure what combination of these will allow me to produce a metallic surface. I know that it should be reflective and retain it's color but how do I go about accomplishing that?&#xA;This is my spec and diffuse calc:&#xA;specular code = vec(1,1,1) * pow((std::max(0.f, dot(light, reflection))), spec)//white specular highlights&lt;/p&gt;&#xA;&#xA;&lt;p&gt;diffuse code =  vec diffuse = col*std::max(0.f, dot(normal, light));//col = object col&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I test if the object that is hit is reflective and calculate the reflection ray, but how do I make it look metallic after producing the reflective image on the sphere?&lt;/p&gt;&#xA;" OwnerUserId="13087" LastActivityDate="2020-03-29T19:52:41.857" Title="How do I produce a metallic surface in ray tracing?" Tags="&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="0" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="9678" PostTypeId="1" CreationDate="2020-03-30T10:14:41.127" Score="1" ViewCount="49" Body="&lt;p&gt;I'm interpolating RGB values by transforming them into HSV space and then back into RGB. I have trouble figuring out how to achieve &lt;code&gt;interpolate(green, black, 0.5) = darkgreen&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Black has multiple representations in HSV, for example &lt;code&gt;(0, 0, 0)&lt;/code&gt; and &lt;code&gt;(30, 0, 0)&lt;/code&gt; are both black. When I convert the RGB black &lt;code&gt;#000000&lt;/code&gt;, I turn it into &lt;code&gt;(0, 0, 0)&lt;/code&gt;. When I then interpolate it with green &lt;code&gt;(120, 1, 1)&lt;/code&gt;, I get &lt;code&gt;(60, 0.5, 0.5)&lt;/code&gt; which is dark semi-saturated yellow. A similar issue exist for white.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I supposed to choose a different color space? I don't want to use LAB color space, because it's computationally expensive. How can I make this correct?&lt;/p&gt;&#xA;" OwnerUserId="11696" LastEditorUserId="11696" LastEditDate="2020-04-23T11:42:29.387" LastActivityDate="2020-04-23T11:42:29.387" Title="Interpolating HSV color with black" Tags="&lt;color&gt;&lt;interpolation&gt;&lt;colorspace&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9680" PostTypeId="1" CreationDate="2020-03-30T13:39:30.087" Score="1" ViewCount="215" Body="&lt;p&gt;I have been trying to detect defects on &quot;before-and-after&quot; meshes, by finding the boolean difference between them, to no avail.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried these two Python libraries(algorithms run in C++) but their boolean operations would produce error or never finish:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;PyVista(VTK wrapper) : &lt;a href=&quot;https://docs.pyvista.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.pyvista.org&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Pymesh : &lt;a href=&quot;https://pymesh.readthedocs.io&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pymesh.readthedocs.io&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;More specifically, some testing and findings that I had:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The libraries would operate normally in any other case of boolean operations between two different meshes. &lt;/li&gt;&#xA;&lt;li&gt;The 2 almost-identical meshes I wanted to use were clean and water-tight. I even used an example shape which I subtracted from itself. It crashed too.&lt;/li&gt;&#xA;&lt;li&gt;These 2 similar meshes are originating from the same mesh, but with a small difference, like a dent or some noise. I tried to introduce stronger noise or bigger changes, but it still would not work if the 2 meshes had their biggest part identical. &lt;/li&gt;&#xA;&lt;li&gt;by enlarging 1 of the 2 meshes by more than 0.1%, or by transforming/moving(see attached picture) it by a similar amount, the algorithm starts working. But by that point, the shapes are too different to be useful.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Av0ng.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Av0ng.png&quot; alt=&quot;meshes apart from each other&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To reproduce the error with Pyvista with an example shape from their website:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import pyvista as pv&#xA;mesh_knot = pv.read(&quot;knot.ply&quot;)&#xA;mesh_knot2 = pv.read(&quot;knot.ply&quot;)&#xA;mesh =  mesh_knot.boolean_difference(mesh_knot2)&#xA;mesh.plot(eye_dome_lighting=True)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To conclude, has anyone any idea why this would happen? Do you think that there is a way to bypass the problem if no solution is found? Any other ideas of how I should approach my initial problem?&lt;/p&gt;&#xA;" OwnerUserId="13093" LastActivityDate="2020-03-31T17:45:45.027" Title="What is the reason that a boolean operation between two almost identical 3D triangular meshes fails?" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;vtk&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9682" PostTypeId="2" ParentId="9680" CreationDate="2020-03-31T16:50:10.683" Score="2" Body="&lt;p&gt;Without debugging the routines with the offending data, it's impossible to say conclusively. However given the examples you have given it sounds like the libraries are falling foul of the coplanar triangle cases when evaluating the meshes. This is certainly an &lt;em&gt;Achilles heel&lt;/em&gt; of many CSG implementations out there (far to many in my experience). In many cases, both theory and implementations seem to fail to address these coplanar cases in many CSG libs. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Certainly the fact that it crashes or fails to produce the desired result implies that the libraries you use are buggy or incomplete in this regard.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The libraries would operate normally in any other case of Boolean operations between two different meshes. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;When there are no coplanar triangles between manifolds, the result is well defined and since CSG operations use triangle/triangle intersections fundamentally, if the case of coplanar triangle intersections is not accounted for, everything should be fine and dandy when there are no coplanar triangle tests between meshes. Of course this is not what you require, but makes sense that this operates normally in these scenarios.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The 2 almost-identical meshes I wanted to use were clean and water-tight. I even used an example shape which I subtracted from itself. It crashed too.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;This is certainly not correct and I would say a bug. A crash implies something is very wrong and either the coplanar triangle support is buggy, limited, or simply not implemented at all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suspect the latter unless you can get a result out with something simple such as diff'ing one cube from another... if you can get a result in some sandboxed cases, then it could be any of the former possibilities.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To see if your CSG routines can handle the coplanar cases, subtracting one cube from another should produce nothing (which as you said it fails). You could also attempt to subtract one cube from another which has a single face coplanar. e.g. Two cubes, both of length &lt;em&gt;length&lt;/em&gt;. One positioned at &lt;em&gt;x - length&lt;/em&gt; should produce a cube which is a closed manifold. i.e. Cube A (1x1x1) positioned at 0,0,0... and cube B (1x1x1) positioned at 1,0,0.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;These 2 similar meshes are originating from the same mesh, but with a small difference, like a dent or some noise. I tried to introduce stronger noise or bigger changes, but it still would not work if the 2 meshes had their biggest part identical. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Probably just one triangle in a mesh is coplanar to another triangle in the other mesh which you are operating on, and thus failing. This may be a way to test by creating two meshes with only one triangle from each mesh being coplanar to another in the other mesh. If this fails then It might indicate that this corner case of coplanar intersection is not catered for at all. As said above, if it does work, then this may point to buggy behaviour at much higher level when dealing with coplanar triangles.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;By enlarging 1 of the 2 meshes by more than 0.1%, or by transforming/moving(see attached picture) it by a similar amount, the algorithm starts working. But by that point, the shapes are too different to be useful.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I presume these libs work on floating point numbers, in which case this sounds like the FP equality tolerances are kicking in and evaluating 'almost' coplanar triangles as coplanar, and then subsequently failing to result in the CSG operation. Of course this is problematic for you if the tolerances are high since the input geometry is expected to be 'different enough' to not fall within these tolerances.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, there is nothing you can really do which I think you would find satisfactory since you are effectively at the mercy of the accuracy of the implementation. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you suspect the libs can handle coplanar triangles between meshes, and its just failing in many cases, you might need to find out how you can kludge the input geometry to not fall foul of the shortcomings that may or may not be present for these corner cases in the implementations:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Remeshing the input geometry may help, although this may result is varying quality of input data in comparison to your measured data, which kind of defeats the purpose and will result in loss of accuracy wrt the original input meshes, but may at least give a result.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Re-tessellating triangles while retaining the mesh features may help. This involves inserting Steiner points into a given triangle and re-tessellating into more triangles. This will result in larger meshes (mem footprint, not geometrically speaking) but may help the routines to resolve coplanar intersections. Unlike the previous suggestion, It will retain the accuracy of the topology of the original meshes though.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Change the FP tolerance (if applicable) that the routines use which may allow you to keep meshes a similar size. However the problem is still there, but this may be satisfactory for your needs allowing you to not have to scale as much. Certainly from a visual standpoint this would be satisfactory I would have thought, however from a numerical point of view this may not be. However this does not fix the issue, rather attempt to circumvent it.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Given that the majority of the meshes will perhaps be similar, if the vertices are what are similar (i.e coplanar triangles have the SAME vertex values, although that screen shot you posted suggests otherwise) you could perhaps simply diff the meshes yourself, finding all the vertices that are not equal when comparing and then tessellating these. This is far more complex though as you would need to keep track of the edges around the different vertices (these edges will use vertices which are equal to others in the other mesh, so not a quick and dirty fix, rather a slightly different approach avoiding the libs you use) so that you can tessellate the different vertices into a meaningful manifold. I wouldn't recommend this as it is quite a specialised case, and may not be generalised enough for your needs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ultimately, if you can't circumvent the issue present with the current libs. You may have to find another. I certainly wasn't able to find many that matched my needs with a correct lic that was applicable to work, however I think there are certainly libs out there that would cater for this. Look for CAD libs as this is an important operation in many CAD programs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A few years ago I spent some time testing and evaluating various different C++ CSG libs for our needs at work as we required a fairly robust implementation for production. While there were various success, they all failed at some point, and coplanar triangles were usually the culprit. It's quite frustrating as the answer is actually quite straight forward and simply requires the Boolean operation to be performed in 2D between the coplanar triangles and then testing if the resulting split triangles are within the 'other' triangle. Why this rather crucial point is missed in a lot of implementations and theory is beyond me.&#xA;/rant&lt;/p&gt;&#xA;" OwnerUserId="9438" LastEditorUserId="9438" LastEditDate="2020-03-31T17:45:45.027" LastActivityDate="2020-03-31T17:45:45.027" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9684" PostTypeId="2" ParentId="9668" CreationDate="2020-03-31T22:23:34.110" Score="3" Body="&lt;p&gt;GL_SMOOTH interpolates the vertex attributes of the primitive (triangle), it looks like your normals are setup per face, rather than per vertex. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If using normal per face (i.e. a single normal for the triangle), increasing the number of triangles will produce a less faceted look as there is more granularity when interpolating the normals over the surface of a given surface area given the increase in the number of triangles within that area. It is recommended to use normals per vertex for smooth surfaces when feature edges are not important (i.e. Not for cubes!).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If using normal per vertex (i.e. a normal for each vertex, resulting in each triangle having 3 vertices), each 3 vertices of a face will be slightly different if the neighbouring triangles are not coplanar to the triangle in question (i.e. not a flat surface). This will aid in the smoothness of the shading.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Normals per vertex can be easily calculated by averaging the three normals of the three vertices defining a triangle, however your surface needs to be defined with shared vertices for this. The exception to this is if you have a sphere or ellipsoid, in which case you can calculate a more precise normal easily by unitising &lt;em&gt;vertex - sphereOrigin&lt;/em&gt; rather than averaging the three normals of the face.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On a side note: Are you using two lights in the scene of the screen shot you posted or one? If two it looks like the normals are currently not correct as the shading does not appear correct since there is a well-lit area of the surface on the bottom left region. With a single light, either the front (top right) of the sphere would be lit, or the bottom left, but not both.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also note that simply increasing the power of the light simply over exposes the surface colour rather than improving the smoothing. You lose the surface definition.&lt;/p&gt;&#xA;" OwnerUserId="9438" LastActivityDate="2020-03-31T22:23:34.110" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9691" PostTypeId="1" CreationDate="2020-04-04T08:58:12.233" Score="0" ViewCount="122" Body="&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; denote the image reconstruction filter of pixel &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;.&#xA;I'm estimating the color value &lt;span class=&quot;math-container&quot;&gt;$$I_j=\int h_jf\:{\rm d}\mu$$&lt;/span&gt; of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel (see &lt;a href=&quot;http://graphics.stanford.edu/papers/veach_thesis/thesis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;[Veach, Section 8.2]&lt;/a&gt;) by an asymptotically consistent estimator whose asymptotic variance is given by &lt;span class=&quot;math-container&quot;&gt;$\sigma^2_j$&lt;/span&gt;. (This has to be understood in a component-wise sense, i.e. &lt;span class=&quot;math-container&quot;&gt;$\sigma_j^2$&lt;/span&gt; is a 3-dimensional vector whose &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th component is the asymptotic variance of the estimate of the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th component of &lt;span class=&quot;math-container&quot;&gt;$I_j$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question 1&lt;/strong&gt;: I want to compare different estimators which lead to different asymptotic variances and would like to visualize that one is superior to another (with respect to variance reduction). How can I do that? Simply writing the variances into an image doesn't seem to be sensible. (The problem is the scale of the values.)&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question 2&lt;/strong&gt;: For simplicity, assume a box filter with radius &lt;span class=&quot;math-container&quot;&gt;$\frac12$&lt;/span&gt; so that the computation of &lt;span class=&quot;math-container&quot;&gt;$I_j$&lt;/span&gt; only involves the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel. Instead of considering the variances of each pixel, I've seen that we could consider the variances of a &amp;quot;local window&amp;quot; (for example a &lt;span class=&quot;math-container&quot;&gt;$3\times 3$&lt;/span&gt; pixel window). Is this a better or worse metric for the total variance of the image?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="9254" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-04-04T08:58:12.233" Title="Visualize the variance of an image" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;image-processing&gt;&lt;monte-carlo&gt;&lt;image-comparison&gt;" AnswerCount="0" CommentCount="29" ContentLicense="CC BY-SA 4.0" />
  <row Id="9692" PostTypeId="1" CreationDate="2020-04-04T10:04:55.540" Score="1" ViewCount="15" Body="&lt;p&gt;By given belows,&#xA;Base mesh(vertices, faces, texture coordinates - UV map),&#xA;Normal map(1024x1024 image),&#xA;Displacement map(1024x1024 image), &#xA;I want to make a mesh which reflects the displacement map. Since the vertices of the base mesh is not directly corresponds  to those maps, it seems that a re-meshing method based on the displacement map is required. Can someone tell me what method is applicable?&lt;/p&gt;&#xA;" OwnerUserId="9774" LastActivityDate="2020-04-04T10:04:55.540" Title="What algorithms are needed to map displacement to base mesh?" Tags="&lt;algorithm&gt;&lt;mesh&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9693" PostTypeId="1" CreationDate="2020-04-04T19:15:36.617" Score="0" ViewCount="294" Body="&lt;p&gt;I want to use Vulkan's rasterization to solve for the visibility problem, but once that is done I want to do shading, reflection and transmission through a raytracer which also runs on the GPU. With a lot of geometry however it's pretty much a need to have some sort of binary partition tree. How can I have C++ and the vulkan shader language communicate this tree? I thought about pushing the tree into GPU memory wrapped in a buffer, but then of course pointers to the left and right bounding box node (it's a binary tree) wouldn't translate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems my only option is to pass an array of bounding boxes, then pass a tree which just keeps indexes of this array instead of absolute pointers, but that really seems like a botch, because I'll need to traverse the entire tree to assemble the linear array and convert the pointers to indexes of that array.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would also need to keep in mind how the compiler packs structs (and thus how I read them in the shader). For now I won't even consider that certain datatypes of certain sizes may not even exist on some gpus to keep my head from exploding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since generating a bsp tree is badly parallelizable I'm not considering doing it on the gpu.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: the objects will also be interacting physically so I need to have a tree available for the CPU as well. I can't just keep all of the geometry on the GPU from the get go.&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2020-04-11T07:40:33.940" Title="Feeding acceleration structure to the GPU then raytracing it in a compute shader?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9694" PostTypeId="1" CreationDate="2020-04-05T02:02:57.990" Score="0" ViewCount="24" Body="&lt;p&gt;I am following the algorithm shown in &lt;a href=&quot;https://github.com/robovm/apple-ios-samples/tree/master/GLCameraRipple&quot; rel=&quot;nofollow noreferrer&quot;&gt;this code&lt;/a&gt; here. Essentially there is a simple simulation of heights and then the difference in heights on the x and y axis respectively (sampling adjacent points) ends up defining how much you add/subtract to your texture coordinate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The result is displayed in this video &lt;a href=&quot;https://www.youtube.com/watch?v=0KoqUdynPpY&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is essentially do you think you could write a fragment shader that adds some sort of good looking specular highlight to this. Almost as though there were some sort of light off the edge. Just to add more feeling of depth/shape.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So far the only thing I have thought of is to look at the difference between the distorted and the normal texture coordinate which ends up looking something like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/0xWJJ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0xWJJ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However since that vector is inherently 2D I am not sure how to figure out a 3D normal that would be useful for calculating the specular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="7072" LastActivityDate="2020-04-05T02:02:57.990" Title="Adding specular reflections to a ripple simulation" Tags="&lt;lighting&gt;&lt;specular&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9695" PostTypeId="2" ParentId="9693" CreationDate="2020-04-05T11:48:21.053" Score="2" Body="&lt;p&gt;If using the new real-time ray tracing functionality is an option for you, it would be worth a try! It might be that getting it to run is less work than porting your CPU data structure into a GPU-compatible format. Furthermore, using the hardware functionality would result in much better performance since BVH traversal (and triangle intersection, if that is relevant to you) are accelerated in hardware.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Official real-time ray tracing support has been announced by Khronos (in the form of an &lt;code&gt;KHR&lt;/code&gt; extension) lately, see &lt;a href=&quot;https://www.khronos.org/blog/ray-tracing-in-vulkan&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing In Vulkan&lt;/a&gt;. With the Vulkan API version 1.2, the option for &quot;Ray Queries&quot; has been added. It could be relevant for your use case since it allows to trace rays against the BVH from arbitrary shaders (i.e., e.g., also from compute shaders or fragment shaders).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Using &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_KHR_ray_tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;VK_KHR_ray_tracing&lt;/a&gt; (or NVIDIA's precursor &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_NV_ray_tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;VK_NV_ray_tracing&lt;/a&gt;), you would have to update the acceleration structure on the GPU every time after you have updated your CPU data structure. The API supports updating acceleration structures every frame. In NVIDIA's extension this is done via the &lt;code&gt;VkBool32 update&lt;/code&gt; flag in &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/vkCmdBuildAccelerationStructureNV.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;vkCmdBuildAccelerationStructureNV&lt;/code&gt;&lt;/a&gt;. In the KHR-extension it is handled a bit differently, but in a very similar fashion: The update-flags are contained in the &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VkAccelerationStructureBuildGeometryInfoKHR.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;VkAccelerationStructureBuildGeometryInfoKHR&lt;/code&gt;&lt;/a&gt; structures.&lt;/p&gt;&#xA;" OwnerUserId="13124" LastEditorUserId="13124" LastEditDate="2020-04-11T07:40:33.940" LastActivityDate="2020-04-11T07:40:33.940" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9696" PostTypeId="2" ParentId="9671" CreationDate="2020-04-06T06:38:58.347" Score="1" Body="&lt;p&gt;Briefly, modify the stb_load as follows and everything should work.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned char* data = stbi_load(file_path, &amp;amp;width, &amp;amp;height, &amp;amp;nrChannels, 4);&#xA;nrChannels = 4;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Details:&lt;/em&gt;&#xA;Okay, after a lot of heartache trying and failing to get libpng to work, I finally decided to have a look at the stbi implementation that I'm using to load the texture files. This is where the problem comes in from. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;@wychmaster was right when he suspected that there was an incorrect stride used. The problem, though, is in the reading of the image. Apparently, this has something to do with alignment of pixel data which is set by glPixelStorei. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Someone posted the same problem in &lt;a href=&quot;https://github.com/nothings/stb/issues/335&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/nothings/stb/issues/335&lt;/a&gt; and determined that this was solution (it works!).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The solution is to set the number of desired channels to 4 in the loading function and read the image as an RGBA instead of whatever the image format actually is. This works and all the misaligned images are now perfect. The images that worked before continue to work too. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But, I do not completely understand why nothing else is affected. This seems strange to me... If someone can explain why this works, that would be very helpful. In the event this is a niche question, I'll likely return to make a more detailed post on it. &lt;/p&gt;&#xA;" OwnerUserId="13083" LastEditorUserId="13083" LastEditDate="2020-04-09T14:08:56.907" LastActivityDate="2020-04-09T14:08:56.907" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9702" PostTypeId="1" AcceptedAnswerId="9705" CreationDate="2020-04-08T21:30:38.133" Score="1" ViewCount="382" Body="&lt;p&gt;Assume you have a list of vertices and their connectivity information. (I.e you can find all the adjacent edges and faces to each vertex).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is a good approach to calculate a normal from this information?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I first tried naive averaging, i.e:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{\sum n_i}{N}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$n_i$&lt;/span&gt; are the face normals and &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; is the total number of faces&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I also tried:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{\sum n_i * a_i}{A}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$a_i$&lt;/span&gt; are the respective areas of each face and &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; is the sum of the areas of all adjacent faces.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The first gave me this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5n4Rc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5n4Rc.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second gave me this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Mht2J.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mht2J.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What I want is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rVP44.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rVP44.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That last image I obtained by setting the normal to be the vector from the origin to the vertex position, but this is only true for highly regular meshes like cubes and spheres, it doesn't hold generally. The data I am using to make this is just the default blender cube.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Increasing precision to doubles doesn't seem to affect the result. This is the wiremesh:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Hrj1f.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Hrj1f.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Obviously the issue occurs because the number of faces adjacent to a vertex isn't balanced, which skews the normals into certain directions, but I don;t know how to compensate for that&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-04-09T17:44:16.767" Title="Calculate normals from vertices" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;&lt;normal-mapping&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9703" PostTypeId="1" CreationDate="2020-04-09T09:54:30.173" Score="1" ViewCount="59" Body="&lt;p&gt;I am currently writing a 3D rendering engine for educational purposes. In general everything is working except that I am chasing down a problem in my cube mesh / tangent calculations that I can't find.&#xA;This picture shows the tangent fragment position I receive in the fragment shader. As you can see, there's clearly an issue here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/lXPMw.png&quot; alt=&quot;Tangent fragment position&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to find this issue for quite some time - at this point I'm probably missing the obvious. What I have been trying to do so far:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Ensuring that it's not a winding order issue: In that case face culling would make the faces disappear - that's not happening here.&lt;/li&gt;&#xA;&lt;li&gt;Tripple checking tangent calculation (function &lt;code&gt;mesh::calculate_tangents()&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;li&gt;Tripple checking TBN matrix calculation&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Unfortunately, I am unable to find the problem. Any help on this would be greatly appreciated!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get started, here's my &lt;code&gt;vertex&lt;/code&gt; struct definition:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    struct vertex {&#xA;        glm::vec3 position;&#xA;        glm::vec3 normal;&#xA;        glm::vec2 texture_uv;&#xA;        glm::vec3 tangent;&#xA;        glm::vec3 bitangent;&#xA;    };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;cube.cpp&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;cube::cube()&#xA;{&#xA;    constexpr std::size_t vertices_count = 36;&#xA;&#xA;    std::array&amp;lt;glm::vec3, vertices_count&amp;gt; positions = {&#xA;            glm::vec3(-0.5f, -0.5f, -0.5f),&#xA;            glm::vec3( 0.5f,  0.5f, -0.5f),&#xA;            glm::vec3( 0.5f, -0.5f, -0.5f),&#xA;            glm::vec3( 0.5f,  0.5f, -0.5f),&#xA;            glm::vec3(-0.5f, -0.5f, -0.5f),&#xA;            glm::vec3(-0.5f,  0.5f, -0.5f),&#xA;&#xA;            glm::vec3(-0.5f, -0.5f,  0.5f),&#xA;            glm::vec3( 0.5f, -0.5f,  0.5f),&#xA;            glm::vec3( 0.5f,  0.5f,  0.5f),&#xA;            glm::vec3( 0.5f,  0.5f,  0.5f),&#xA;            glm::vec3(-0.5f,  0.5f,  0.5f),&#xA;            glm::vec3(-0.5f, -0.5f,  0.5f),&#xA;&#xA;            glm::vec3(-0.5f,  0.5f,  0.5f),&#xA;            glm::vec3(-0.5f,  0.5f, -0.5f),&#xA;            glm::vec3(-0.5f, -0.5f, -0.5f),&#xA;            glm::vec3(-0.5f, -0.5f, -0.5f),&#xA;            glm::vec3(-0.5f, -0.5f,  0.5f),&#xA;            glm::vec3(-0.5f,  0.5f,  0.5f),&#xA;&#xA;            glm::vec3( 0.5f,  0.5f,  0.5f),&#xA;            glm::vec3( 0.5f, -0.5f, -0.5f),&#xA;            glm::vec3( 0.5f,  0.5f, -0.5f),&#xA;            glm::vec3( 0.5f, -0.5f, -0.5f),&#xA;            glm::vec3( 0.5f,  0.5f,  0.5f),&#xA;            glm::vec3( 0.5f, -0.5f,  0.5f),&#xA;&#xA;            glm::vec3(-0.5f, -0.5f, -0.5f),&#xA;            glm::vec3( 0.5f, -0.5f, -0.5f),&#xA;            glm::vec3( 0.5f, -0.5f,  0.5f),&#xA;            glm::vec3( 0.5f, -0.5f,  0.5f),&#xA;            glm::vec3(-0.5f, -0.5f,  0.5f),&#xA;            glm::vec3(-0.5f, -0.5f, -0.5f),&#xA;&#xA;            glm::vec3(-0.5f,  0.5f, -0.5f),&#xA;            glm::vec3( 0.5f,  0.5f,  0.5f),&#xA;            glm::vec3( 0.5f,  0.5f, -0.5f),&#xA;            glm::vec3( 0.5f,  0.5f,  0.5f),&#xA;            glm::vec3(-0.5f,  0.5f, -0.5f),&#xA;            glm::vec3(-0.5f,  0.5f,  0.5f),&#xA;    };&#xA;&#xA;    std::array&amp;lt;glm::vec2, vertices_count&amp;gt; texture_uv = {&#xA;            glm::vec2(0.0f, 0.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(0.0f, 0.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;&#xA;            glm::vec2(0.0f, 0.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(0.0f, 0.0f),&#xA;&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(0.0f, 0.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(0.0f, 0.0f),&#xA;&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(0.0f, 0.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(1.0f, 1.0f),&#xA;            glm::vec2(1.0f, 0.0f),&#xA;            glm::vec2(0.0f, 1.0f),&#xA;            glm::vec2(0.0f, 0.0f),&#xA;    };&#xA;&#xA;    std::array&amp;lt;glm::vec3, vertices_count&amp;gt; normals = {&#xA;            glm::vec3( 0.0f,  0.0f, -1.0f),&#xA;            glm::vec3( 0.0f,  0.0f, -1.0f),&#xA;            glm::vec3( 0.0f,  0.0f, -1.0f),&#xA;            glm::vec3( 0.0f,  0.0f, -1.0f),&#xA;            glm::vec3( 0.0f,  0.0f, -1.0f),&#xA;            glm::vec3( 0.0f,  0.0f, -1.0f),&#xA;&#xA;            glm::vec3( 0.0f,  0.0f,  1.0f),&#xA;            glm::vec3( 0.0f,  0.0f,  1.0f),&#xA;            glm::vec3( 0.0f,  0.0f,  1.0f),&#xA;            glm::vec3( 0.0f,  0.0f,  1.0f),&#xA;            glm::vec3( 0.0f,  0.0f,  1.0f),&#xA;            glm::vec3( 0.0f,  0.0f,  1.0f),&#xA;&#xA;            glm::vec3(-1.0f,  0.0f,  0.0f),&#xA;            glm::vec3(-1.0f,  0.0f,  0.0f),&#xA;            glm::vec3(-1.0f,  0.0f,  0.0f),&#xA;            glm::vec3(-1.0f,  0.0f,  0.0f),&#xA;            glm::vec3(-1.0f,  0.0f,  0.0f),&#xA;            glm::vec3(-1.0f,  0.0f,  0.0f),&#xA;&#xA;            glm::vec3( 1.0f,  0.0f,  0.0f),&#xA;            glm::vec3( 1.0f,  0.0f,  0.0f),&#xA;            glm::vec3( 1.0f,  0.0f,  0.0f),&#xA;            glm::vec3( 1.0f,  0.0f,  0.0f),&#xA;            glm::vec3( 1.0f,  0.0f,  0.0f),&#xA;            glm::vec3( 1.0f,  0.0f,  0.0f),&#xA;&#xA;            glm::vec3( 0.0f, -1.0f,  0.0f),&#xA;            glm::vec3( 0.0f, -1.0f,  0.0f),&#xA;            glm::vec3( 0.0f, -1.0f,  0.0f),&#xA;            glm::vec3( 0.0f, -1.0f,  0.0f),&#xA;            glm::vec3( 0.0f, -1.0f,  0.0f),&#xA;            glm::vec3( 0.0f, -1.0f,  0.0f),&#xA;&#xA;            glm::vec3( 0.0f,  1.0f,  0.0f),&#xA;            glm::vec3( 0.0f,  1.0f,  0.0f),&#xA;            glm::vec3( 0.0f,  1.0f,  0.0f),&#xA;            glm::vec3( 0.0f,  1.0f,  0.0f),&#xA;            glm::vec3( 0.0f,  1.0f,  0.0f),&#xA;            glm::vec3( 0.0f,  1.0f,  0.0f),&#xA;    };&#xA;&#xA;    // Build indices&#xA;    std::vector&amp;lt;GLuint&amp;gt; indices;&#xA;    for (std::size_t i = 0; i &amp;lt; vertices_count; ++i) {&#xA;        indices.emplace_back(static_cast&amp;lt;GLuint&amp;gt;(i));&#xA;    }&#xA;&#xA;    // Build vertices&#xA;    std::vector&amp;lt;vertex&amp;gt; vertices = build_vertices(std::move(positions), std::move(normals), std::move(texture_uv));&#xA;&#xA;    // Textures&#xA;    std::vector&amp;lt;texture&amp;gt; textures;&#xA;    // ...&#xA;&#xA;    // Create mesh&#xA;    mesh m(std::move(vertices), std::move(indices), std::move(textures));&#xA;    m.calculate_tangents();&#xA;    set_mesh(std::move(m));&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Function &lt;code&gt;mesh::calculate_tangents()&lt;/code&gt;:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void mesh::calculate_tangents()&#xA;{&#xA;    for (std::size_t i = 0; i &amp;lt; m_indices.size()-2; ++i)&#xA;    {&#xA;        // Honor indices order&#xA;        const GLuint&amp;amp; index1 = m_indices.at(i + 0);&#xA;        const GLuint&amp;amp; index2 = m_indices.at(i + 1);&#xA;        const GLuint&amp;amp; index3 = m_indices.at(i + 2);&#xA;&#xA;        // Get the three adjacent vertices&#xA;        const auto&amp;amp; v1 = m_vertices[index1];&#xA;        const auto&amp;amp; v2 = m_vertices[index2];&#xA;        const auto&amp;amp; v3 = m_vertices[index3];&#xA;&#xA;        // Edges &amp;amp; delta-UVs&#xA;        const glm::vec3&amp;amp; edge1 = v2.position - v1.position;&#xA;        const glm::vec3&amp;amp; edge2 = v3.position - v1.position;&#xA;        const glm::vec2&amp;amp; deltaUV1 = v2.texture_uv - v1.texture_uv;&#xA;        const glm::vec2&amp;amp; deltaUV2 = v3.texture_uv - v1.texture_uv;&#xA;&#xA;        const GLfloat f = 1.0f / (deltaUV1.x * deltaUV2.y - deltaUV2.x * deltaUV1.y);&#xA;&#xA;        // Calculate tangent&#xA;        glm::vec3 tangent;&#xA;        tangent.x = f * (deltaUV2.y * edge1.x - deltaUV1.y * edge2.x);&#xA;        tangent.y = f * (deltaUV2.y * edge1.y - deltaUV1.y * edge2.y);&#xA;        tangent.z = f * (deltaUV2.y * edge1.z - deltaUV1.y * edge2.z);&#xA;        tangent = glm::normalize(tangent);&#xA;        m_vertices[index1].tangent = tangent;&#xA;        m_vertices[index2].tangent = tangent;&#xA;        m_vertices[index3].tangent = tangent;&#xA;&#xA;        // Calculate bitangent&#xA;        glm::vec3 bitangent;&#xA;        bitangent.x = f * (-deltaUV2.x * edge1.x + deltaUV1.x * edge2.x);&#xA;        bitangent.y = f * (-deltaUV2.x * edge1.y + deltaUV1.x * edge2.y);&#xA;        bitangent.z = f * (-deltaUV2.x * edge1.z + deltaUV1.x * edge2.z);&#xA;        bitangent = glm::normalize(bitangent);&#xA;        m_vertices[index1].bitangent = bitangent;&#xA;        m_vertices[index2].bitangent = bitangent;&#xA;        m_vertices[index3].bitangent = bitangent;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;This is how I calculate the TBN matrix in the vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    mat3 normalMatrix = transpose(inverse(mat3(model)));&#xA;    vec3 T = normalize(normalMatrix * a_tangent);&#xA;    vec3 N = normalize(normalMatrix * a_normal);&#xA;    T = normalize(T - dot(T, N) * N);&#xA;    vec3 B = cross(N, T);&#xA;&#xA;    mat3 TBN = transpose(mat3(T, B, N));&#xA;    vs_out.TangentLightPos = TBN * light.position;&#xA;    vs_out.TangentViewPos  = TBN * camera_position;&#xA;    vs_out.TangentFragPos  = TBN * vs_out.fragment_position;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For completeness, here's my &lt;code&gt;mesh&lt;/code&gt; class definition:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    class mesh&#xA;    {&#xA;    public:&#xA;        // Construction&#xA;        mesh();&#xA;        mesh(std::vector&amp;lt;vertex&amp;gt;&amp;amp;&amp;amp; vertices, std::vector&amp;lt;GLuint&amp;gt;&amp;amp;&amp;amp; indices, std::vector&amp;lt;texture&amp;gt;&amp;amp;&amp;amp; textures);&#xA;        mesh(const mesh&amp;amp; other) = delete;&#xA;        mesh(mesh&amp;amp;&amp;amp; other);&#xA;        virtual ~mesh() = default;&#xA;&#xA;        // Operators&#xA;        mesh&amp;amp; operator=(mesh&amp;amp;&amp;amp; rhs);&#xA;&#xA;        // Common&#xA;        void calculate_tangents();&#xA;        void render(rendering::shader&amp;amp; shader) const;&#xA;&#xA;    private:&#xA;        std::vector&amp;lt;vertex&amp;gt; m_vertices;&#xA;        std::vector&amp;lt;GLuint&amp;gt; m_indices;&#xA;        std::vector&amp;lt;texture&amp;gt; m_textures;&#xA;&#xA;        GLuint m_vbo;   // Vertex buffer object&#xA;        GLuint m_vao;   // Vertex array object&#xA;        GLuint m_ebo;   // Element buffer object&#xA;&#xA;        void finalize();&#xA;    };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13147" LastEditorUserId="13147" LastEditDate="2020-04-09T10:57:28.713" LastActivityDate="2020-04-09T10:57:28.713" Title="Problem calculating tangent space" Tags="&lt;mesh&gt;&lt;normal-mapping&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9705" PostTypeId="2" ParentId="9702" CreationDate="2020-04-09T13:29:40.850" Score="3" Body="&lt;p&gt;You are not too far off with your second averaging approach. The problem is, that the area is the wrong weighting factor for what you want to achieve. You want each of the 3 sides of the cube to contribute equally to the vertex normal, but you need to extract the information from the adjacent triangles. The area and the number of triangles are bad weighting factors since they vary with the number of triangles per side. But one thing stays always the same at each vertex: The angle between two edges at the side. So you just need to take the angle of each triangle connected to the vertex and use it as a weighting factor for its normalized face normal. The weighting factors will always sum up to 90°/&lt;span class=&quot;math-container&quot;&gt;$\frac{\pi}{2}$&lt;/span&gt; per side of the cube. Look for example at the bottom left vertex at the front in the image you posted.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your first approach fails because it yields:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$N_v = \frac{2*N_l + 2 \cdot N_f + 1 \cdot N_b}{5}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$N_l$&lt;/span&gt; is the left, &lt;span class=&quot;math-container&quot;&gt;$N_f$&lt;/span&gt; the front and &lt;span class=&quot;math-container&quot;&gt;$N_b$&lt;/span&gt; the bottom side normal. Assume them to be normalized. The factors result from the triangle count at the vertex and their sum.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your second approach fails because it yields: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$N_v = \frac{N_l + 0.5 \cdot N_f + 0.5 \cdot N_b}{2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here the factors result from the fact, that only the left face has all its triangles connected to the vertex. The bottom face connects only 1 of 2 and front face only 2 of 4 equally sized triangles to the vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you take the angles, you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$N_v = \frac{2\cdot 45 \cdot N_l + 2 \cdot 45 \cdot N_f+ 90 \cdot N_b}{270}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now each side contributes equally and independent of the number and size of triangles connected to the vertex.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I just realized, that the front face also contains only 2 triangles. The diagonal of the back face triangles irritated me. However, this will not affect the conclusion but the weigting factors change. For the fist approach you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$N_v = \frac{2*N_l + 1 \cdot N_f + 1 \cdot N_b}{4}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The second remains unchanged and for the angles you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$N_v = \frac{2\cdot 45 \cdot N_l + 90 \cdot N_f+ 90 \cdot N_b}{270}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which is still correct. What is interesting is that both your approaches give the same results for the shown cube, since a connection of the vertex to 2 triangles also means that the area weight is doubled. You can also see this if you compare both pictures.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-04-09T17:44:16.767" LastActivityDate="2020-04-09T17:44:16.767" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9706" PostTypeId="2" ParentId="9702" CreationDate="2020-04-09T15:31:25.810" Score="0" Body="&lt;p&gt;Assuming you want to calculate the &lt;em&gt;shared&lt;/em&gt; vertex normal... if you know which faces use the vertex and they have unitised normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation*}\left \| \sum \left \| n_{t} \right \| \right \|\end{equation*}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your first appraoch is close, but would only work if the face normals are unitised otherwise they will skew.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4031/programmatically-generating-vertex-normals&quot;&gt;See this question for more information&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given your last image, it looks like you want normals per face (flat shading) in which case you shouldn't share your vertices between faces, instead you need three vertices for each triangle (i.e 36 for a cube using tgriangles, or 24 for a cube if using quads).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to use no more than 8 vertices, you will effectively get smooth shading (possibly what your first two images show) and not flat shading (what it looks like you want with your 3rd image), or you need to have normals per face (and not per vertex).&lt;/p&gt;&#xA;" OwnerUserId="9438" LastEditorUserId="9438" LastEditDate="2020-04-09T15:44:17.380" LastActivityDate="2020-04-09T15:44:17.380" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9707" PostTypeId="1" CreationDate="2020-04-09T16:11:29.037" Score="0" ViewCount="116" Body="&lt;p&gt;I'm following &lt;a href=&quot;https://vulkan-tutorial.com/Introduction&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial on Vulkan&lt;/a&gt; and I tried to see if it actually worked with different queues for drawing and presenting the image of the triangle. &lt;a href=&quot;https://vulkan.gpuinfo.org/displayreport.php?id=2675#queuefamilies&quot; rel=&quot;nofollow noreferrer&quot;&gt;My GPU supports presentation with every queue family&lt;/a&gt; but it actually works only when I use a queue from the first or second family, not the third. Is there anything wrong with the code or is something like that possible?&lt;/p&gt;&#xA;" OwnerUserId="13151" LastEditorUserId="13151" LastEditDate="2020-04-09T17:04:32.160" LastActivityDate="2020-04-09T17:04:32.160" Title="Queue from a family queue that supports presentation doesn't work [Vulkan]" Tags="&lt;c++&gt;&lt;gpu&gt;&lt;vulkan&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9708" PostTypeId="1" AcceptedAnswerId="9750" CreationDate="2020-04-10T03:46:48.517" Score="2" ViewCount="269" Body="&lt;p&gt;There are lots of cool things you can do with SDFs to render implicit surfaces. Most of the examples I've seen have been “all in the shader”, where the entire distance function is encoded in the shader source code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Examples:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.shadertoy.com/view/3lsSzf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/3lsSzf&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The problem is that all of those examples assume the shader has total knowledge of the entire world. It evaluates a single distance function, which is complex, but complete.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to make a large world (too large to fit in a shader, certainly), and am looking for approaches to render it with the SDF approach.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does anyone have experience with this? It is 2D-only, if it helps.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The stumbling block seems to be: Since the rendering happens in the fragment shader, I somehow have to transfer “game world” information into that shader. But there do not seem to be good ways to send bulk data to the fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some ideas I have had:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Write one generic shader that can draw, say, a combination of 500 SDFs.&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The input to the shader (maybe a UBO?) would contain an encoded version of a piece of the world, with commands like “put a circle at (x,y,radius), do a union with the next object, …” to build the total SDF for that piece of the world.&lt;/li&gt;&#xA;&lt;li&gt;On the CPU side, I'd have to split the world into chunks that could be rendered by that shader, and populate the input data appropriately for each draw call.&lt;/li&gt;&#xA;&lt;li&gt;So for 2D, I might do a tile-based render of the screen, where each tile has “small” amount of data, enough to be handled in the shader.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;li&gt;Generate shaders on-the-fly, depending on the part of the world I want to render.&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Here, the shader code would look a lot like the “everything baked in” shaders, but I'd just be generating the code on the CPU.&lt;/li&gt;&#xA;&lt;li&gt;This approach seems bad though, since compiling shaders is a pretty heavy process, in my experience. I did a test with an SDF that was the union of a few thousand circles, and it took 30sec+ to compile.&lt;/li&gt;&#xA;&lt;/ul&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Any other ideas?&lt;/p&gt;&#xA;" OwnerUserId="13154" LastActivityDate="2020-04-22T17:55:29.370" Title="SDF rendering for large world" Tags="&lt;shader&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9709" PostTypeId="1" AcceptedAnswerId="9710" CreationDate="2020-04-11T21:19:14.107" Score="4" ViewCount="235" Body="&lt;p&gt;I have a simplistic shader program that adds reference coordinate planes to a scene. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;These planes are drawn as intersecting lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When viewed at a distance, a visual artifact is created; there is a ripple of lighter and darker areas going left to right across the image.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qNKfb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qNKfb.png&quot; alt=&quot;with anti-aliasing&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Given how simple the shader program is, I think this must be due to the interpolation that occurs between the vertex and fragment shaders.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;(a) Does this type of artifact have a name? &lt;/li&gt;&#xA;&lt;li&gt;(b) What causes it?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;I looked into whether this was being caused by anti-aliasing. However, disabling the anti-aliasing shows that the pattern is created beforehand. See here:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ulv9h.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ulv9h.png&quot; alt=&quot;without anti-aliasing&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;in short:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;this is a Moire pattern (see &lt;a href=&quot;https://computergraphics.stackexchange.com/a/9710/13167&quot;&gt;lfgtm's answer&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;li&gt;it is caused by trying to map a perspective projection of parallel lines onto a fixed grid of pixels. (see &lt;a href=&quot;https://computergraphics.stackexchange.com/a/9713/13167&quot;&gt;zoran's answer&lt;/a&gt;)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;When looking at ways to address this problem, I thought that drawing the lines as surfaces with a gradient transparency across the width of the line would help by allowing the line to &lt;em&gt;straddle&lt;/em&gt; pixels and giving it a more accurate width.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is how the grid looks when drawn as simple lines vs surfaces with gradient transparency.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zBX9G.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zBX9G.png&quot; alt=&quot;lines vs surfaces&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This improved the definition between lines at a distance (i.e. they don't overlap each other and create a solid plane). However, this had little appreciable effect on the light &amp;amp; dark ripples.&lt;/p&gt;&#xA;" OwnerUserId="13167" LastEditorUserId="13167" LastEditDate="2020-04-14T11:29:39.580" LastActivityDate="2020-04-14T18:02:25.250" Title="Visual Artifact in Wireframe Grid/Plane" Tags="&lt;webgl&gt;&lt;artifacts&gt;" AnswerCount="3" CommentCount="11" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9710" PostTypeId="2" ParentId="9709" CreationDate="2020-04-11T21:33:27.060" Score="2" Body="&lt;p&gt;It's a interference pattern, called &lt;a href=&quot;https://en.wikipedia.org/wiki/Moir%C3%A9_pattern&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moire pattern&lt;/a&gt;. You get them in signal analysis and various other fields. I guess it could be considered an optical illusion.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To elaborate, this occurs when a periodic waveform goes out of phase with the observer. In your case the periodic waveform are the lines when observed as a scanline (from left to right of the image or vice versa), and the observer is the image with a set number of horizontal pixels. In some parts, the pixel rasterization falls on pixel boundaries and then there is a watershed moment... should it be rasterized in pixel x, or x + 1. This then manifests as the wave pattern (due to the 'watershed' moment being slightly out of phase with the previous or next scanline i.e one scanline, pixel falls on x, the next scanline it falls on x+1). Also the display device can also have an effect. The moire in your image is much more pronounced on my computer monitor, than it is with my phone. (however this could be due to my phone’s browser scaling or applying some other filtering by default, which could help to reduce it).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anti aliasing certainly helps, however moire can never be completely eradicated, only mitigated. Also note this can occur with rotated grids in orthographic, however perspective projection will certainly amplify this effect.&lt;/p&gt;&#xA;" OwnerUserId="9438" LastEditorUserId="9438" LastEditDate="2020-04-14T09:38:43.633" LastActivityDate="2020-04-14T09:38:43.633" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9711" PostTypeId="1" AcceptedAnswerId="9714" CreationDate="2020-04-12T04:16:02.353" Score="1" ViewCount="78" Body="&lt;p&gt;I have a doubt regarding shape lights pdfs, specifically various sources point at the fact that the pdf is a constant:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;lightpdf = 1/A&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; is the area of the light surface. Expressed in solid angle terms, this becomes:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;lightpdf(\omega) = \frac{r^2}{cos\theta A}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;or &lt;span class=&quot;math-container&quot;&gt;$= 0$&lt;/span&gt; for directions on the hemisphere which do not hit the light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where &lt;span class=&quot;math-container&quot;&gt;$r^2$&lt;/span&gt; is the squared distance from the hit point o the light surface and the point we are sampling from, and &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; the angle from the light surface normal and our ray direction (&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Sampling_Light_Sources.html#SamplingShapes&quot; rel=&quot;nofollow noreferrer&quot;&gt;source&lt;/a&gt;).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What isn't clear to me is knowing that the pdf should satisfy this condition:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_0^{2\pi} lightpdf(\omega)d\omega = 1$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assuming for example a sphere light source (but a cylinder would also do), if in the second formula above we use the entire sphere area as &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt;, aren't we using a solid angle for the sphere which is double of what it actually should be? (by including the half surface we cannot see from &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Yu2GP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Yu2GP.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11521" LastActivityDate="2020-04-12T20:53:57.833" Title="Confusion about light PDF" Tags="&lt;lighting&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9712" PostTypeId="1" AcceptedAnswerId="9718" CreationDate="2020-04-12T14:33:05.007" Score="0" ViewCount="70" Body="&lt;p&gt;I want to write code from scratch about Projective Transformation in order to apply this transformation to 2d rectangular. I searched about this transformation, but I could not figure out completely. These are some formulas I have seen:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   x' = xH&#xA;   y' = yH&#xA;   A.H = 0&#xA;   A = UΣV^T&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;According to these formulas,SVD is calculated from A matrix, and then H is obtained from V. Then target points should be found by H. But this is a bit confusing. Could you explain it? Also is there any alternative solution like composition of transformations like Similarity Transform which can be obtained by multiplying rotation, translation and scale matrixes?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I watched this youtube video (&lt;a href=&quot;https://www.youtube.com/watch?v=54Qtu3S9HJU&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=54Qtu3S9HJU&lt;/a&gt;) . It explains how calculate homography by the equations above after 12 minutes.This method seems very complex. I want to learn how exactly we calculate homography and obtain another rectangle by applying Projective Transfrom?&lt;/p&gt;&#xA;" OwnerUserId="6625" LastEditorUserId="6625" LastEditDate="2020-04-12T20:20:59.587" LastActivityDate="2020-04-13T15:13:17.907" Title="Apply Projective Transformation 2D Rectangle" Tags="&lt;transformations&gt;&lt;perspective&gt;&lt;2d-graphics&gt;&lt;camera&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9713" PostTypeId="2" ParentId="9709" CreationDate="2020-04-12T15:32:29.900" Score="1" Body="&lt;p&gt;The pattern you are seeing arises from perspective projection. Which causes all those parallel lines not to be parallel to each other when projected on the screen.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Your problem with darker and lighter areas is caused by anti-aliasing which is trying to smooth the lines that are sometimes passing right in between 2 pixels, so it blends the lines with the black background.&lt;br&gt;&#xA;You also have a problem that sometimes there is an empty (black) pixel between the lines lines and sometimes the lines are right next to each other.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;All this always occurs but the reason you're noticing a pattern here is that you just have a lot of really dense parallel lines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This reminds me of a common problem in game graphics where high-resolution textures viewed from a distance tend to look bad and flicker from frame to frame.&lt;br&gt;&#xA;The usual way that is solved is by using a lower resolution texture when the object is far away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For you an equivalent would be to have more lines closer to the perspective camera and fewer lines further away. I'd also recommend adding transparency to the denser lines as they get further away to achieve a smooth transition.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Edit: Just ran into a problem that has the most pronounced version of this effect, it's called shadow acne&lt;/p&gt;&#xA;" OwnerUserId="13159" LastEditorUserId="13159" LastEditDate="2020-04-13T15:13:02.430" LastActivityDate="2020-04-13T15:13:02.430" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9714" PostTypeId="2" ParentId="9711" CreationDate="2020-04-12T20:53:57.833" Score="1" Body="&lt;p&gt;Most of the answer is in the text you linked:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Shapes almost always sample uniformly by area on their surface.&#xA;  Therefore, we will provide a default implementation of the&#xA;  Shape::Pdf() method corresponding to this sampling approach that&#xA;  returns the corresponding PDF: 1 over the surface area.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So it is not always 1. This is just the most basic way to sample a light. It is simple, fast and provides a good baseline to check other algorithms for correctness. As for:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Assuming for example a sphere light source (but a cylinder would also&#xA;  do), if in the second formula above we use the entire sphere area as&#xA;  &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt;, aren't we using a solid angle for the sphere which is double of&#xA;  what it actually should be? (by including the half surface we cannot&#xA;  see from &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The half you cannot see will simply be excluded by the visibiliy test. Or because it is back facing, if you choose to emit light only on one side of the object. A better sampling algorithm will take that into consideration and adjust the PDF accordingly. Indeed, if you read a little further on that page, you will find:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The second shape sampling method takes the point from which the&#xA;  surface of the shape is being integrated over as a parameter. This&#xA;  method is particularly useful for lighting, since the caller can pass&#xA;  in the point to be lit and allow shape implementations to ensure that&#xA;  they only sample the portion of the shape that is potentially visible&#xA;  from that point.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Which is exactly what you are asking about. But doing this is not about having correct sampling, it's about having efficient sampling. Any sampling method is correct as long as:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;It can generate samples everywhere they are potentially needed.&lt;/li&gt;&#xA;&lt;li&gt;Its PDF correctly represents the probability of generating each sample.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2020-04-12T20:53:57.833" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9718" PostTypeId="2" ParentId="9712" CreationDate="2020-04-13T15:03:28.700" Score="1" Body="&lt;p&gt;Since homography is not my topic, I can't really tell if I am missing some important edge cases, but after some research, I think I got the basics. I will use the same variable names, the guy in the video uses on slide 15 (slide numbers are in the bottom right corner on the red background).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You start by defining 4 points in the plane &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; where you say you know their projected points in plane &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;. You assume, that the transformation between &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is linear and can be described by a matrix &lt;span class=&quot;math-container&quot;&gt;$H$&lt;/span&gt;. Means&#xA;&lt;span class=&quot;math-container&quot;&gt;$$x = HX$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now you want to calculate the Matrix &lt;span class=&quot;math-container&quot;&gt;$H$&lt;/span&gt; that perfoms the projection:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$H = \begin{bmatrix}h_1&amp;amp;h_2&amp;amp;h_3\\h_4&amp;amp;h_5&amp;amp;h_6\\h_7&amp;amp;h_8&amp;amp;h_9\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$h_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$h_9$&lt;/span&gt; are unknowns. So how do you get them? Well, you have 4 times:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$p_i' = Hp_i$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$p_i'$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p_i$&lt;/span&gt; are the projected and the original points. This full equation looks like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}x_i'\\y_i'\\1\end{bmatrix}= \begin{bmatrix}h_1&amp;amp;h_2&amp;amp;h_3\\h_4&amp;amp;h_5&amp;amp;h_6\\h_7&amp;amp;h_8&amp;amp;h_9\end{bmatrix}\begin{bmatrix}x_i\\y_i\\1\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perform the multiplication and you will get this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}x_i'\\y_i'\\1\end{bmatrix}= \begin{bmatrix}x_ih_1+y_ih_2+h_3\\x_ih_4+y_ih_5+h_6\\x_ih_7+y_ih_8+h_9\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also write this in some kind of nested vector fashion:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}x_i'\\y_i'\\1\end{bmatrix}= \begin{bmatrix}\bar{h_1}^T p\\\bar{h_2}^T p\\\bar{h_3}^T p\end{bmatrix} = \begin{bmatrix}p^T\bar{h_1}\\p^T\bar{h_2}\\p^T\bar{h_3}\end{bmatrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\begin{matrix}\bar{h_1} = \begin{bmatrix}h_1\\h_2\\h_3\end{bmatrix}&amp;amp;\bar{h_2} = \begin{bmatrix}h_4\\h_5\\h_6\end{bmatrix}&amp;amp;\bar{h_1} = \begin{bmatrix}h_7\\h_8\\h_9\end{bmatrix}\end{matrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now here comes the trick (got it from &lt;a href=&quot;https://engineering.purdue.edu/kak/computervision/ECE661Folder/Lecture10.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link&lt;/a&gt;). If  &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; is equal to the vector &lt;span class=&quot;math-container&quot;&gt;$Hp$&lt;/span&gt; their cross product must be the zero vector &lt;span class=&quot;math-container&quot;&gt;$\bar{0}$&lt;/span&gt;:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$p' \times Hp = \bar{0}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Applying the cross product will give you three equations:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{matrix}y_i'p^T\bar{h_3} -  p^T\bar{h_2} &amp;amp;= 0 \\ p^T\bar{h_1} - x_i' p^T\bar{h_3} &amp;amp;= 0\\x_i' p^T\bar{h_2}-y_i' p^T\bar{h_1}&amp;amp;=0\end{matrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Write this as a matrix equation and you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}\bar{0}^T &amp;amp;-p^T&amp;amp;y_i'p^T\\p^T&amp;amp;\bar{0}^T&amp;amp;-x_i'p^T\\-y_i' p^T&amp;amp;x_i' p^T&amp;amp;\bar{0}^T\end{bmatrix} \begin{bmatrix}\bar{h_1}\\\bar{h_2}\\\bar{h_3}\end{bmatrix}= \begin{bmatrix}0\\0\\0\end{bmatrix}$$&lt;/span&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, if you look at the matrix, you might notice, that the 3 columns are not linear independent. &lt;span class=&quot;math-container&quot;&gt;$-y_i'$&lt;/span&gt; times the first column minus &lt;span class=&quot;math-container&quot;&gt;$x_i'$&lt;/span&gt; times the second one, yields the third column. So you can drop one. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you drop the last column and replace all the vectors with their corresponding entries, you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}0&amp;amp;0&amp;amp;0 &amp;amp;-x_i&amp;amp;-y_i&amp;amp;-1&amp;amp;y_i'x_i&amp;amp;y_i'y_i&amp;amp;y_i'\\x_i&amp;amp;y_i&amp;amp;1&amp;amp;0&amp;amp;0&amp;amp;0&amp;amp;-x_ix_i'&amp;amp;-y_ix_i'&amp;amp;-x_i'\end{bmatrix} \begin{bmatrix}h_1\\h_2\\h_3\\h_4\\h_5\\h_6\\h_7\\h_8\\h_9\end{bmatrix}= \begin{bmatrix}0\\0\end{bmatrix}$$&lt;/span&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can multiply the second row by &lt;span class=&quot;math-container&quot;&gt;$-1$&lt;/span&gt; and swap it with the first one (that does not change the solution of the system) to get the exact same formula as presented in the video on the slide 17.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you apply the formula to all 4 points you get the system:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{bmatrix}&#xA;0&amp;amp;0&amp;amp;0 &amp;amp;-x_1&amp;amp;-y_1&amp;amp;-1&amp;amp;y_1'x_1&amp;amp;y_1'y_1&amp;amp;y_1'\\&#xA;x_1&amp;amp;y_1&amp;amp;1&amp;amp;0&amp;amp;0&amp;amp;0&amp;amp;-x_1x_1'&amp;amp;-y_1x_1'&amp;amp;-x_1' \\&#xA;0&amp;amp;0&amp;amp;0 &amp;amp;-x_2&amp;amp;-y_2&amp;amp;-1&amp;amp;y_2'x_2&amp;amp;y_2'y_2&amp;amp;y_2'\\&#xA;x_2&amp;amp;y_2&amp;amp;1&amp;amp;0&amp;amp;0&amp;amp;0&amp;amp;-x_2x_2'&amp;amp;-y_2x_2'&amp;amp;-x_2' \\&#xA;0&amp;amp;0&amp;amp;0 &amp;amp;-x_3&amp;amp;-y_3&amp;amp;-1&amp;amp;y_3'x_3&amp;amp;y_3'y_3&amp;amp;y_3'\\&#xA;x_3&amp;amp;y_3&amp;amp;1&amp;amp;0&amp;amp;0&amp;amp;0&amp;amp;-x_3x_3'&amp;amp;-y_3x_3'&amp;amp;-x_3' \\&#xA;0&amp;amp;0&amp;amp;0 &amp;amp;-x_4&amp;amp;-y_4&amp;amp;-1&amp;amp;y_4'x_4&amp;amp;y_4'y_4&amp;amp;y_4'\\&#xA;x_4&amp;amp;y_4&amp;amp;1&amp;amp;0&amp;amp;0&amp;amp;0&amp;amp;-x_4x_4'&amp;amp;-y_4x_4'&amp;amp;-x_4' \\&#xA;\end{bmatrix} \begin{bmatrix}h_1\\h_2\\h_3\\h_4\\h_5\\h_6\\h_7\\h_8\\h_9\end{bmatrix}= \begin{bmatrix}0\\0\end{bmatrix}$$&lt;/span&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem is now, that you have 9 unknowns but just 8 formulas. According to the answers in &lt;a href=&quot;https://math.stackexchange.com/questions/494238/how-to-compute-homography-matrix-h-from-corresponding-points-2d-2d-planar-homog&quot;&gt;this question&lt;/a&gt;, one possible solution is to constraint &lt;span class=&quot;math-container&quot;&gt;$h_9$&lt;/span&gt; to be 1 and solve the resulting linear system. However, another way is to solve it as an underdetermined least-squares problem. This might be done using the SVD. However, as I said in the comments, this is a rather complicated algorithm. An easier one is to use QR decomposition, which can be a substep of the SVD, but this is also not too easy to code yourself. Since you don't seem to be that experienced in advanced linear algebra, you might try the constraint technique first, before trying the SVD.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can also use more than 4 points, but then you get an overdetermined system, which can be solved with the SVD, QR decomposition or any other least-squares solver.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-04-13T15:13:17.907" LastActivityDate="2020-04-13T15:13:17.907" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9719" PostTypeId="1" AcceptedAnswerId="9723" CreationDate="2020-04-13T21:32:20.103" Score="2" ViewCount="188" Body="&lt;p&gt;With WebGL 1 we can use WEBGL_draw_buffers extension which lets us use a texture as the depth attachment on the frame buffer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And we can chose to use LINEAR or NEAREST as the filtering method.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.getExtension('WEBGL_draw_buffers');&#xA;gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_SHORT, null);&#xA;gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);&#xA;gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;WebGL 2 doesn't require an extension for this, but as soon as I switched to WebGL 2 I noticed that nothing happens unless I use NEAREST as the filtering method.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;gl.texImage2D(gl.TEXTURE_2D, 0, gl.DEPTH_COMPONENT24, width, height, 0, gl.DEPTH_COMPONENT, gl.UNSIGNED_INT, null);&#xA;gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); // wont work&#xA;gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); // has to be NEAREST&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is there something I have to do to make this possible?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The only workaround for this that I know of would be to draw this depth texture onto another texture, but that seems like a waste of time.&lt;/p&gt;&#xA;" OwnerUserId="13159" LastActivityDate="2020-04-15T00:53:17.873" Title="Does WebGL 2 support linear depth texture sampling?" Tags="&lt;webgl&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9720" PostTypeId="2" ParentId="9709" CreationDate="2020-04-13T23:36:10.003" Score="1" Body="&lt;p&gt;Although it's not wrong to call it an interference pattern, it isn't the whole story here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The difference between the dark and bright areas is caused by antialiasing (filtering) which is done in the wrong color space. The lines drawn as a single bright pixel (red=219) do not have the same apparent brightness as the lines drawn as two darker pixels (red=118).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some fiddling with the numbers, they appear to be a match for &quot;TV RGB&quot; which is a range 16-235, given that &lt;span class=&quot;math-container&quot;&gt;${219-16\over2}+16=117.5$&lt;/span&gt; But those values are wrong even if you actually have a monitor correctly configured for that range (unlikely) as it is still not linear, as far as I know.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's what a better filtered grid should look like:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/AHtck.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AHtck.png&quot; alt=&quot;perspective grid&quot;&gt;&lt;/a&gt;&#xA;Make sure to view this in its own window, without any browser zoom applied as that can introduce its own artifacts.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2020-04-14T18:02:25.250" LastActivityDate="2020-04-14T18:02:25.250" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9721" PostTypeId="1" CreationDate="2020-04-14T17:04:47.687" Score="3" ViewCount="153" Body="&lt;p&gt;I'm trying to understand BRDF importance sampling following the exemples of the lambertian/diffuse model and the reciprocal Phong model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to be able to extend the principle to other models. If you know good ressources on the subject please feel free to give me references.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1) In the diffuse case, the pdf &lt;span class=&quot;math-container&quot;&gt;$p_d(\theta,\phi)$&lt;/span&gt; of directions is :&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_d(\theta,\phi)=\frac{f_r\cos{\theta}\sin{\theta}}{\int_0^{2\pi}\int_0^{\frac{\pi}{2}} f_r\cos{\theta}\sin{\theta}\,\mathrm{d}\theta\mathrm{d}\phi}&#xA;=\frac{\cos{\theta}\sin{\theta}}{\pi}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the reciprocal Phong model the pdf &lt;span class=&quot;math-container&quot;&gt;$p_s(\theta_s,\phi_s)$&lt;/span&gt; is :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_s(\theta_s,\phi_s)=\frac{k_s\cos^n{\theta_s}\sin{\theta_s}}{\int_0^{2\pi}\int_0^{\frac{\pi}{2}}k_s\cos^n{\theta_s}\sin{\theta_s}\,\mathrm{d}\theta_s\mathrm{d}\phi_s}&#xA;=\frac{n+1}{2\pi}\cos^n{\theta_s}\sin{\theta_s}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But it seems that people use the densities :&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_d(\theta,\phi)=\frac{\cos{\theta}}{\pi}&#xA;\end{equation}&lt;/span&gt;&#xA;and&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_s(\theta_s,\phi_s)=\frac{n+1}{2\pi}\cos^n{\theta_s}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What is the reason ? Could we use both versions ? Are they equivalent ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) Furthermore :&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\int_0^{2\pi}\int_0^{\frac{\pi}{2}} \frac{\cos{\theta}}{\pi}\,\mathrm{d}\theta\mathrm{d}\phi=2\pi\neq 1&#xA;\end{equation}&lt;/span&gt;&#xA;and&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\int_0^{2\pi}\int_0^{\frac{\pi}{2}}\frac{n+1}{2\pi}\cos^n{\theta_s}\,\mathrm{d}\theta_s\mathrm{d}\phi_s = \quad?&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Shouldn't the pdfs have an integral equal to 1?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;3) In another post (&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5968/probability-density-function-while-using-spherical-coordinates&quot;&gt;Probability density function while using spherical coordinates&lt;/a&gt;), people explains that the sines functions are never taken into account because they are &quot;artefacts&quot; of the coordinate system.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is that true ? Should we always reject sines functions ? And if so, why do we compute pdf with sines and reject them after ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks to the comment of @lightxbulb, it seems that the integrals of my second point should be evaluated with respect to solid angles:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\int_{\Omega} \frac{\cos{\theta}}{\pi}\,\mathrm{d}\omega&#xA;=\int_0^{2\pi}\int_0^{\frac{\pi}{2}} \frac{\cos{\theta}\sin{\theta}}{\pi}\,\mathrm{d}\theta\mathrm{d}\phi&#xA;=1&#xA;\end{equation}&lt;/span&gt;&#xA;and&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\int_{\Omega}\frac{n+1}{2\pi}\cos^n{\theta_s}\,\mathrm{d}\omega&#xA;=\int_0^{2\pi}\int_0^{\frac{\pi}{2}}\frac{n+1}{2\pi}\cos^n{\theta_s}\sin{\theta_s}\,\mathrm{d}\theta_s\mathrm{d}\phi_s&#xA;=1&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which brings me to another point:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;4) Here are different Monte-Carlo estimators for the reflected part of the rendering equation, with respect to different coordinate system:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Solid angles:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;L_r(\vec{x},\vec{\omega}_o)=\frac{1}{N}\sum_{i=1}^N \frac{L_i(\vec{x},\vec{\omega}_i(x,y,z)) f_r(\vec{x},\vec{\omega}_i(x,y,z),\vec{\omega}_o) \cos{\theta}}{p_1(\vec{\omega}_i(x,y,z))}&#xA;\end{equation}&lt;/span&gt;&#xA;Spherical coordinates:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;L_r(\vec{x},\vec{\omega}_o)=\frac{1}{N}\sum_{i=1}^N \frac{L_i(\vec{x},\vec{\omega}_i(\theta,\phi)) f_r(\vec{x},\vec{\omega}_i(\theta,\phi),\vec{\omega}_o) \cos{\theta}\sin{\theta}}{p_2(\vec{\omega}_i(\theta,\phi))}&#xA;\end{equation}&lt;/span&gt;&#xA;Unit square:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;L_r(\vec{x},\vec{\omega}_o)=\frac{\pi}{N}\sum_{i=1}^N \frac{L_i(\vec{x},\vec{\omega}_i(u,v)) f_r(\vec{x},\vec{\omega}_i(u,v),\vec{\omega}_o)}{p_3(\vec{\omega}_i(u,v))}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry for the heavy notations but I would like to fully understand. So:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_1(\vec{\omega_i})=\frac{\cos{\theta}}{\pi}\quad ?&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_2(\vec{\omega_i})=\frac{\cos{\theta}\sin{\theta}}{\pi}\quad ?&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_3(\vec{\omega_i})=\quad ?&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;People seem to use:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;p_3(\vec{\omega_i})=\frac{\cos{\theta}}{\pi}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm doing something wrong but I don't know what&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT2:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The equation involving (&lt;span class=&quot;math-container&quot;&gt;$\xi_1,\xi_2$&lt;/span&gt;) on page 9 in the reference is not the reflected part of the rendering equation but the integral of the BRDF on the hemisphere. But we don't care here because 1) the luminance &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; in the reflected part is not known (that's why we use importance sampling only on the BRDF) and 2) a Monte-Carlo estimator is something like:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\int f(x)\, \mathrm{d}x\approx\frac{1}{N}\sum_{i=1}^N \frac{f(x_i)}{p(x_i)}&#xA;\end{equation}&lt;/span&gt;&#xA;So that's just different integrands but the pdfs should be the same. Correct me if I'm wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here are the mappings:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the spherical coordinates to solid angles:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\begin{cases}&#xA;x = \sin{\theta}\cos{\phi} \\&#xA;y = \sin{\theta}\sin{\phi} \\&#xA;z = \cos{\theta}&#xA;\end{cases}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From the unit square to the spherical coordinates:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\begin{cases}&#xA;\theta = \arcsin{\sqrt{u}} \\&#xA;\phi = 2\pi v&#xA;\end{cases}&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I suppose that the expression &quot;cosine weighted mapping&quot; comes from the cosine with the normal (&lt;span class=&quot;math-container&quot;&gt;$z=\cos{\theta}$&lt;/span&gt;) ? If the cosine of the mapping modify the pdf why the sine of the Jacobian doesn't ? And if the mapping modify the pdf why (&lt;span class=&quot;math-container&quot;&gt;$\theta = \arcsin{\sqrt{u}}$&lt;/span&gt;) doesn't too ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have an implementation in front of me (ref : Lászlo Szirmay-Kalos, Monte Carlo Methods in Global Illumination, page 104 and 112). I think that what is done is to use the first estimator with the pdf &lt;span class=&quot;math-container&quot;&gt;$p(\vec{\omega}_i)=\frac{\cos{\theta}}{\pi}$&lt;/span&gt;. But the choice of the pdf is not explained and I'm very confused with the different mappings and the influence of each transformation on the mathematical formulation of the problem.&lt;/p&gt;&#xA;" OwnerUserId="13179" LastEditorUserId="13179" LastEditDate="2020-04-15T21:52:37.987" LastActivityDate="2020-04-15T21:52:37.987" Title="Understanding BRDF sampling" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;monte-carlo&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9723" PostTypeId="2" ParentId="9719" CreationDate="2020-04-15T00:53:17.873" Score="3" Body="&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/es/3.0/es_spec_3.0.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;The spec&lt;/a&gt; says depth textures are not filterable.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;h3&gt;3.8.13&lt;/h3&gt;&#xA;  &#xA;  &lt;p&gt;...&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Using the preceding definitions, a texture is complete unless any of the following conditions hold true:&lt;/p&gt;&#xA;  &#xA;  &lt;ul&gt;&#xA;  &lt;li&gt;The effective internal format specified for the texture arrays is a sized internal depth or depth and stencil format (see table 3.14), the value of TEXTURE_COMPARE_MODE is NONE, and either the magnification filter is not NEAREST or the minification filter is neither NEAREST nor NEAREST_-&#xA;  MIPMAP_NEAREST&lt;/li&gt;&#xA;  &lt;/ul&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="4766" LastActivityDate="2020-04-15T00:53:17.873" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9724" PostTypeId="1" CreationDate="2020-04-15T12:33:25.480" Score="0" ViewCount="156" Body="&lt;p&gt;I am loading an OBJ file using the ASSIMP library. Following is the MTL file associated with the obj file.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;newmtl initialShadingGroup&#xA;Kd 0.50 0.50 0.50&#xA;Ka 0.09 0.09 0.09&#xA;Tf 1.00 1.00 1.00&#xA;Ns 10.0&#xA;map_Ka sphere_roughness.jpg&#xA;map_Kd sphere_albedo.jpg&#xA;map_Ks sphere_metallic.jpg&#xA;bump sphere_normal.jpg&#xA;disp sphere_bump.jpg&#xA;illum 7&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I want to read the illum value so that I can choose an appropriate sharding model in my shaders. The code I'm using is &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;int shadingModel;&#xA;material-&amp;gt;Get(AI_MATKEY_SHADING_MODEL, shadingModel);&#xA;std::cout &amp;lt;&amp;lt; &quot;ShadingModel: &quot; &amp;lt;&amp;lt; shadingModel&amp;lt;&amp;lt; std::endl;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But the output I'm getting is &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;ShadingModel: 2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;when the value is 7. Is there something that I'm doing it wrong or is it the wrong way to retrieve the shading model. &#xA;Thanks for your help!&lt;/p&gt;&#xA;" OwnerUserId="13184" LastActivityDate="2021-03-29T17:56:03.480" Title="How to read illum value from mtl file using Assimp library?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shading&gt;&lt;material&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9726" PostTypeId="1" AcceptedAnswerId="9731" CreationDate="2020-04-16T01:51:33.223" Score="2" ViewCount="70" Body="&lt;p&gt;I seem to have an off by one error when creating the indices for the faces of a sphere and I can't understand where.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The exact problem is that when I try to calculate the normals of each face a dark region of nans appears in the region where the vertices wrap around.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yh3pn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yh3pn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I generate the vertices and face information like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;pair&amp;lt;vector&amp;lt;vec3&amp;gt;, vector&amp;lt;uint&amp;gt;&amp;gt; GenerateSphere(&#xA;    float radius,&#xA;    uint u_resolution,&#xA;    uint v_resolution)&#xA;{&#xA;    vector&amp;lt;vec3&amp;gt; points;&#xA;    vector&amp;lt;uint&amp;gt; indices;&#xA;    for(uint i=0; i&amp;lt; u_resolution; i++)&#xA;    {&#xA;        float u = (float(i) / float(u_resolution - 1)) * M_PI - M_PI / 2.f;&#xA;        for(uint j=0; j &amp;lt; v_resolution; j++)&#xA;        {&#xA;            float v = float(j) * 2.f * M_PI / float(v_resolution - 1);&#xA;&#xA;            points.push_back(vec3(cos(u) * cos(v), cos(u) * sin(v), sin(u)) * radius);&#xA;        }&#xA;    }&#xA;&#xA;    for(uint i=0; i &amp;lt; u_resolution - 1; i++)&#xA;    {&#xA;        for(uint j=0; j &amp;lt; v_resolution; j++)&#xA;        {&#xA;            // Grab the 4 points in a quad face in the sphere&#xA;            uint p00 = (i * (v_resolution) + j);&#xA;            uint p01 = (i * (v_resolution) + ((j + 1) % v_resolution));&#xA;            uint p10 = ((i + 1) * v_resolution + j);&#xA;            uint p11 = ((i + 1) * v_resolution + ((j + 1) % v_resolution));&#xA;&#xA;            assert((i + 1) &amp;lt; u_resolution);&#xA;            assert(p00 &amp;lt; points.size());&#xA;            assert(p01 &amp;lt; points.size());&#xA;            assert(p10 &amp;lt; points.size());&#xA;            assert(p11 &amp;lt; points.size());&#xA;            assert(&#xA;                p00 != p01 &amp;amp;&amp;amp; p00 != p11 &amp;amp;&amp;amp; p00 != p10 &amp;amp;&amp;amp;&#xA;                p01 != p10 &amp;amp;&amp;amp; p01 != p11 &amp;amp;&amp;amp;&#xA;                p10 != p11&#xA;            );&#xA;&#xA;            // Add the first triangle&#xA;            indices.push_back(p00);&#xA;            indices.push_back(p01);&#xA;            indices.push_back(p11);&#xA;&#xA;            // Add the second triangle&#xA;            indices.push_back(p00);&#xA;            indices.push_back(p11);&#xA;            indices.push_back(p10);&#xA;        }&#xA;    }&#xA;&#xA;    //for(auto&amp;amp; v : points) cout &amp;lt;&amp;lt; to_string(v) &amp;lt;&amp;lt; endl;&#xA;    //cout &amp;lt;&amp;lt; endl;&#xA;    return {points, indices};&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And immediately after calculate the normals like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;std::vector&amp;lt;glm::vec3&amp;gt; GenerateNormals(const std::vector&amp;lt;glm::vec3&amp;gt;&amp;amp; vertices,&#xA;    const std::vector&amp;lt;uint&amp;gt;&amp;amp; indices)&#xA;{&#xA;    assert(indices.size() % 3 ==0);&#xA;&#xA;    map&amp;lt;uint, vector&amp;lt;vec3&amp;gt;&amp;gt; normal_map;&#xA;    for(uint i=0; i &amp;lt; indices.size(); i += 3)&#xA;    {&#xA;        vec3 v1 = vertices[indices[i]];&#xA;        vec3 v2 = vertices[indices[i + 1]];&#xA;        vec3 v3 = vertices[indices[i + 2]];&#xA;&#xA;        vec3 d1 = v2 - v1;&#xA;        vec3 d2 = v3 - v1;&#xA;&#xA;        assert(indices[i] &amp;lt; vertices.size());&#xA;        assert(indices[i + 1] &amp;lt; vertices.size());&#xA;        assert(indices[i + 2] &amp;lt; vertices.size());&#xA;        assert(indices[i] != indices[i+1] &amp;amp;&amp;amp; indices[i] != indices[i+2] &amp;amp;&amp;amp;&#xA;            indices[i+1] != indices[i+2]);&#xA;&#xA;        if(abs(dot(d1, d2)) &amp;lt; 0.0001)&#xA;        {&#xA;            d1 = v3 - v2;&#xA;            d2 = v1 - v2;&#xA;        }&#xA;&#xA;        if(abs(dot(d1, d2)) &amp;lt; 0.0001)&#xA;        {&#xA;            d1 = v1 - v3;&#xA;            d2 = v2 - v3;&#xA;        }&#xA;&#xA;        vec3 normal = normalize(cross(d1, d2));&#xA;&#xA;        normal_map[indices[i]].push_back(normal);&#xA;        normal_map[indices[i + 1]].push_back(normal);&#xA;        normal_map[indices[i + 2]].push_back(normal);&#xA;    }&#xA;&#xA;    assert(normal_map.size() == vertices.size());&#xA;    std::vector&amp;lt;glm::vec3&amp;gt; normals(vertices.size());&#xA;    for(auto&amp;amp; pair : normal_map)&#xA;    {&#xA;        uint index = pair.first;&#xA;        vector&amp;lt;vec3&amp;gt; v_normals = pair.second;&#xA;&#xA;        vec3 normal(0);&#xA;        for(auto&amp;amp; n : v_normals)&#xA;            normal += n;&#xA;&#xA;        normal /= float(v_normals.size());&#xA;        normals[index] = normal;&#xA;    }&#xA;    assert(normals.size() == vertices.size());&#xA;    return normals;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Note: I know that I could just calculate the normals by taking the difference between the current vertex and the center of the sphere. These 2 functions I plan to use as templates to code other paramtetric surfaces, so that's not a solution for me I am trying to understand what I did wrong more than trying to fix it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have added lots of assertions through the code to try to catch the issue and I have also stepped through gdb but I can't seem to find the issue. &lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-04-19T03:35:57.867" LastActivityDate="2020-04-19T03:35:57.867" Title="Off by one error when creating face indices" Tags="&lt;c++&gt;&lt;geometry&gt;&lt;parametrization&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9727" PostTypeId="5" CreationDate="2020-04-16T01:52:10.217" Score="0" Body="" OwnerUserId="-1" LastEditorUserId="-1" LastEditDate="2020-04-16T01:52:10.217" LastActivityDate="2020-04-16T01:52:10.217" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9728" PostTypeId="4" CreationDate="2020-04-16T01:52:10.217" Score="0" Body="For questions about parametric shapes, such as NURB surfaces, the parametric sphere, cylinders, etc..." OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-04-29T07:38:55.547" LastActivityDate="2020-04-29T07:38:55.547" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9730" PostTypeId="1" CreationDate="2020-04-16T04:06:20.223" Score="0" ViewCount="103" Body="&lt;p&gt;I am reading the paper &lt;em&gt;Texture Synthesis over Arbitrary Manifold Surfaces&lt;/em&gt; available &lt;a href=&quot;http://graphics.stanford.edu/papers/texture-synthesis-sig01/texture.pdf?q=illustrating-smooth-surfaces&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;On page &lt;span class=&quot;math-container&quot;&gt;$3$&lt;/span&gt; on the right sight of the page they refer to isotropic and anisotropic textures.&#xA;I am familiar with anistropic texture filtering, but not an actual texture itself called anisotropic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further they refer to an &lt;em&gt;n-way symmetric texture&lt;/em&gt;, which I am not familiar with, and a google search did not yield any results.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am guessing an &lt;em&gt;anisotropic&lt;/em&gt; texture is a texture that accounts for different viewing directions (?) and perhaps an &lt;em&gt;n-way symmetric texture&lt;/em&gt; is such a texture that accounts for &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; different viewing directions?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If anyone could clarify these two terms that would be much appreciated. I realize this paper is from &lt;span class=&quot;math-container&quot;&gt;$2001$&lt;/span&gt; so these terms might not still be in use.&lt;/p&gt;&#xA;" OwnerUserId="10079" LastActivityDate="2020-04-16T04:06:20.223" Title="Isotropic vs Anisotropic Textures" Tags="&lt;terminology&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9731" PostTypeId="2" ParentId="9726" CreationDate="2020-04-16T13:06:44.980" Score="3" Body="&lt;p&gt;The problem with your code is, that it produces a lot of degenerated triangles. The not so obvious ones are at the top and bottom. The obvious ones are at the &quot;wrapping line&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So what exactly is the problem? Each of your faces is a rectangle that consists of 2 triangles and 4 points. The 2 triangles share 2 points and each one has 1 individual point. But at the bottom/top 2 points are identical, so your rectangle degenerates to a triangle. As a result, one triangle degenerates to a line because of the duplicate points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, why is this problematic for you? It is this line, that causes the trouble: &lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;vec3 normal = normalize(cross(d1, d2));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The cross product of a vector with itself is the zero vector. If you normalize a vector, you divide by its length, which is 0 in this case. So this is where your &lt;code&gt;NaN&lt;/code&gt;s come from. Until now, I just spoke about the top and bottom, but why is it happening at the &quot;wrapping line&quot;? The problem is a result of your index calculation:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;    for(uint i=0; i &amp;lt; u_resolution - 1; i++)&#xA;    {&#xA;        for(uint j=0; j &amp;lt; v_resolution; j++)&#xA;        {&#xA;            // Grab the 4 points in a quad face in the sphere&#xA;            uint p00 = (i * (v_resolution) + j);&#xA;            uint p01 = (i * (v_resolution) + ((j + 1) % v_resolution));&#xA;            uint p10 = ((i + 1) * v_resolution + j);&#xA;            uint p11 = ((i + 1) * v_resolution + ((j + 1) % v_resolution));&#xA;   ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The &lt;code&gt;j&lt;/code&gt; loop is running until &lt;code&gt;v_resolution&lt;/code&gt;.  So &lt;code&gt;j+1&lt;/code&gt; gets problematic. I know your intention here is, that you need the triangles from the &quot;other side&quot;, to calculate your normals correctly. That is why you performed the &lt;code&gt;% v_resolution&lt;/code&gt; to get the corresponding points. But the problem is, you are not getting the points you want. With your code, you are including the last and first point of a &quot;horizontal line&quot;, but they are identical in your case. The result is that you get a face that degenerates to a line, which means, that you will divide by 0 during normalization of both triangles surface normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A quick way to fix the &lt;code&gt;NaN&lt;/code&gt;s at the &quot;wrapping line&quot; would be to make a temporary variable and store &lt;code&gt;j+1&lt;/code&gt; in it. Then check if it is equal or higher than &lt;code&gt;v_resolution&lt;/code&gt;. If &lt;code&gt;true&lt;/code&gt;, increase it by one. Use this variable everywhere you used &lt;code&gt;j+1&lt;/code&gt; during the index generation. However, this will still cause an issue at the wrapping line, since your start and end vertices are not the same and you only considered &quot;both sides&quot; for the last vertices of a horizontal line, but not for the first. This will lead to incorrect normals for the start vertices and you should see a jump in the shading. You might fix it, by just copying the normals of the last vertices to the first ones. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, you still need to address the problems at the top and bottom. This can be fixed by making a special loop only for top and bottom triangles. However, these are suboptimal fixes. A better approach would be to write code that does not produce duplicate points since it lowers the risk of creating degenerated triangles and is more memory efficient.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-04-16T15:36:11.303" LastActivityDate="2020-04-16T15:36:11.303" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9732" PostTypeId="1" CreationDate="2020-04-16T16:41:23.730" Score="0" ViewCount="96" Body="&lt;p&gt;While following &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/global-illumination-path-tracing/global-illumination-path-tracing-practical-implementation&quot; rel=&quot;nofollow noreferrer&quot;&gt;scratchapixel's&lt;/a&gt; tutorial on indirect diffuse implementation in path tracing, the samples gets divided by the pdf, which in case of a uniform pdf results in &lt;span class=&quot;math-container&quot;&gt;$1/2\pi$&lt;/span&gt; so we have that the sum of N samples gets multiplied by this factor:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$k=\frac{1}{N * \frac{1}{2  \pi}} = \frac{2\pi}{N}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem with this is that unless the albedo color is very dark, the final color quickly increases:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(From &quot;Step 7: Add the Contribution of the Indirect Diffuse...&quot; in the link above)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$hitColor = (directDiffuse + \frac{2\pi * indirectDiffuse}{N}) * \frac{albedo}{\pi}; $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other implementations instead just average the samples and the &lt;span class=&quot;math-container&quot;&gt;$2\pi$&lt;/span&gt; term above is completely absent, like in Shirley's &quot;&lt;a href=&quot;https://www.realtimerendering.com/raytracing/Ray%20Tracing%20in%20a%20Weekend.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;ray tracing in a weekend&lt;/a&gt;&quot; p.20&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Which one is correct?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There's a difference in Shirley's and scratchapixel implementation, in the fact that Shirley's is a progressive path tracer (evaluates one path at a time)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W9BY4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W9BY4.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While scratchapixel's is a non-progressive or branched path tracer, evaluating multiple paths at once:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8AlLb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8AlLb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But I believe this does not allow us to remove the &lt;span class=&quot;math-container&quot;&gt;$2\pi$&lt;/span&gt; term in the former, because we are doing the same thing (sampling the BRDF hemisphere) albeit differently.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When evaluating direct lighting with point lights, the solid angle term is also &lt;a href=&quot;https://learnopengl.com/PBR/Lighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;completely absent&lt;/a&gt;, which makes things even more strange:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5rkhs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5rkhs.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here the integral over the hemisphere is 0 except in the direction &lt;span class=&quot;math-container&quot;&gt;$\omega i$&lt;/span&gt;, but (for example considering only diffuse) we only use:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ L(P) = albedo*L(\omega i, P)*cos\theta$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$L(P)$&lt;/span&gt; is the radiance from the point &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$L(\omega i, P)$&lt;/span&gt; gets replaced with our light radiance, &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; is the angle with from &lt;span class=&quot;math-container&quot;&gt;$\omega i$&lt;/span&gt; to the surface normal. Where has the solid angle term (&lt;span class=&quot;math-container&quot;&gt;$ \omega i$&lt;/span&gt;) gone?&lt;/p&gt;&#xA;" OwnerUserId="11521" LastEditorUserId="11521" LastEditDate="2020-04-17T08:13:00.860" LastActivityDate="2020-04-17T08:13:00.860" Title="Pdf division in BRDF sampling" Tags="&lt;lighting&gt;&lt;brdf&gt;" AnswerCount="0" CommentCount="17" ContentLicense="CC BY-SA 4.0" />
  <row Id="9733" PostTypeId="1" AcceptedAnswerId="9735" CreationDate="2020-04-17T08:50:05.560" Score="2" ViewCount="261" Body="&lt;p&gt;In the Bresenham circle drawing algorithm, we have to choose between the top and bottom pixel, but what we always do is using the circle's equation (&lt;span class=&quot;math-container&quot;&gt;$f(x, y) = x^2 + y^2 = r^2$&lt;/span&gt;) to determine which of the two pixels is closer to the circle (r is the radius).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For the top pixel (N), we thus have &lt;span class=&quot;math-container&quot;&gt;$f(N) = x_{k+1}^2 + y_k^2 - r^2$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And for the bottom pixel (S), we have &lt;span class=&quot;math-container&quot;&gt;$f(S) = x_{k+1}^2 + y_{k-1}^2 - r^2$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Okay, we're using the circle equation to determine which is the closest point to the circle but why not simply using the euclidean distance? What is the point to use f instead of the actual distance? It would be easier to understand (this f function seems to come out of nowhere).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The actual distance between the top pixel and the circle is &lt;span class=&quot;math-container&quot;&gt;$\sqrt{x_{k+1}^2 + y_k^2} - r$&lt;/span&gt; and with the bottom pixel it's &lt;span class=&quot;math-container&quot;&gt;$r - \sqrt{x_{k+1}^2 + y_{k-1}^2}$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3UQIZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3UQIZ.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2020-04-18T14:21:11.480" Title="Bresenham circle drawing algorithm, compute the distance?" Tags="&lt;algorithm&gt;&lt;drawing&gt;&lt;midpoint&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9734" PostTypeId="1" CreationDate="2020-04-17T09:04:55.903" Score="3" ViewCount="282" Body="&lt;p&gt;I am trying to program my own version of WEBGL graphics pipeline in python, however, I am confused as to where the color interpolation takes place in the pipeline. According to my research, it happens after the rasterizer has calculated the points covered by the primitive. Does that mean rasterizer has access to color attribute, if so, how is the color attribute passed to the rasterizer, as the inputs for rasterizer are vertices? Or is it happening in the fragment shader?&lt;/p&gt;&#xA;" OwnerUserId="13192" LastActivityDate="2020-04-17T11:32:21.197" Title="Interpolation in Graphics Pipeline" Tags="&lt;interpolation&gt;&lt;rasterizer&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9735" PostTypeId="2" ParentId="9733" CreationDate="2020-04-17T10:44:38.640" Score="2" Body="&lt;p&gt;After a short research, I found &lt;a href=&quot;https://www.javatpoint.com/computer-graphics-bresenhams-circle-algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;this site&lt;/a&gt;, which describes the algorithm. I didn't know it before. An important thing you didn't mention in your question is the calculation of the decision parameter &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt;, which is:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$d=f\left(N\right)+f\left(S\right)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It abuses the fact, that the bottom pixel will always lie on the circle or inside and the right pixel will always be on the circle or outside (for this particular segment). In conclusion, this means that &lt;span class=&quot;math-container&quot;&gt;$f\left(S\right) \le 0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$f\left(N\right) \ge 0$&lt;/span&gt;. If &lt;span class=&quot;math-container&quot;&gt;$d&amp;lt;=0$&lt;/span&gt; you pick the right one and the left one otherwise.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Okay, we're using the circle equation to determine which is the closest point to the circle but why not simply using the euclidean distance?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Most probably for performance reasons. Using the Euclidean distance requires you to calculate 2 square roots, which is quite expensive when compared to simple multiplication (&lt;span class=&quot;math-container&quot;&gt;$r\cdot r$&lt;/span&gt;). On a Haswell CPU, you can perform 6 independent multiplications at the same time as calculating a single square root. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you optimize the Bresenham algorithm you will probably get something like that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{matrix}&#xA;d &amp;amp;=&amp;amp; x_{k+1}^2 + y_k^2 - r^2 +  x_{k+1}^2 + y_{k-1}^2 - r^2\\&#xA; &amp;amp;=&amp;amp; 2x_{k+1}^2- 2r^2 + y_k^2   + y_{k-1}^2 \\&#xA; &amp;amp;=&amp;amp; 2\left(x_{k+1}^2- r^2\right) + y_k^2   + y_{k-1}^2&#xA;\end{matrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;then compare&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$d \le 0$$&lt;/span&gt;&#xA;So in total, you end up with 9 multiplications, 2 additions, 1 subtraction and 1 comparison. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&#xA;As mentioned in the comments to this answer, the Euclidean length and the Bresenham algorithm won't give you the same results. While the Euclidean length will always give you the Pixel with the closest distance of its center to the arc, the Bresenham algorithm will favor points inside the circle, even though they are a little bit farther away. However, this error gets smaller the closer you get to the circle and shouldn't be noticeable.  &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After rereading some tutorials like the one above or &lt;a href=&quot;https://www.getsetcg.com/2018/10/bresenhams-circle-drawing-derivation.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this one&lt;/a&gt;, I am not totally sure if they are really stating that they take the closest point. The tutorial I linked says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;So if &lt;span class=&quot;math-container&quot;&gt;$Dk &amp;lt; 0$&lt;/span&gt; that means the negative &lt;span class=&quot;math-container&quot;&gt;$F(S)$&lt;/span&gt; is bigger then the positive &lt;span class=&quot;math-container&quot;&gt;$F(N)$&lt;/span&gt;, that implies Point &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; is closer to the circle than point &lt;span class=&quot;math-container&quot;&gt;$S$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Language details are not my strong suit, but I think &quot;implies&quot; is meant more in the way of &quot;indicating&quot; something. In this case, it does not mean it is the exact result.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyways, after some elongated calculations, you are right, that &lt;span class=&quot;math-container&quot;&gt;$d=f\left(N\right)+f\left(S\right)$&lt;/span&gt; will give wrong results in favor of the inner point if both distances to the circle are quite close. I did some error estimation.&#xA;With:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{matrix}&#xA;a &amp;amp;=&amp;amp; \sqrt{x_{k+1}^2 + y_k^2} \\&#xA;b &amp;amp;=&amp;amp; \sqrt{x_{k+1}^2 + y_{k-1}^2} \\&#xA;\end{matrix}&#xA;$$&lt;/span&gt;&#xA;being the distances to the points from the center, you can calculate the error &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt; as follows:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{matrix}&#xA;a^2 - r^2 + b^2 - r^2 + \epsilon &amp;amp;=&amp;amp; ((a-r) - (r-b))^2\\&#xA;&amp;amp;=&amp;amp; (2r -a - b)^2&#xA;\end{matrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you solve that for &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt; you will get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\epsilon = 6r + 2ab - 4ra - 4 rb$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can get 2 interesting pieces of information from that. First, as you already claimed, the Bresenham algorithm does not take the exact distance to the circle when deciding which point is the next one, otherwise &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt; must have been 0. However, the second information is: If &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; are both on the circle, the error vanishes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was wondering how much closer &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; must be than &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; until it is selected. So I did the following:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{matrix}&#xA;a &amp;amp;=&amp;amp; r+\delta + \tau\\&#xA;b &amp;amp;=&amp;amp; r-\delta &#xA;\end{matrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The reasoning here is as follows: If &lt;span class=&quot;math-container&quot;&gt;$\tau = 0$&lt;/span&gt;, then both points have the same distance &lt;span class=&quot;math-container&quot;&gt;$\delta$&lt;/span&gt; to the circle. So the right-hand side of&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\begin{matrix} a^2 - r^2 + b^2 - r^2 + \epsilon &amp;amp;=&amp;amp; (2r -a - b)^2 \end{matrix}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;, the Euclidean distance, will be 0. Now I want to find an offset &lt;span class=&quot;math-container&quot;&gt;$\tau$&lt;/span&gt;, which causes the left-hand side to be 0, which is the condition where the Bresenham algorithm &quot;assumes&quot; both points to be equally distant to the circle. So if you say  &lt;span class=&quot;math-container&quot;&gt;$$a^2 - r^2 + b^2 - r^2 = 0$$&lt;/span&gt;, replace the &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; with the shown formulas and solve for &lt;span class=&quot;math-container&quot;&gt;$\tau$&lt;/span&gt; you get:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\tau =   \sqrt{r^2 + 2\delta - \delta^2}- (r + \delta)$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can rewrite this a little bit so that it looks like this&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\tau =   \sqrt{(r + \delta)^2 - 2\delta^2}- \sqrt{(r + \delta)^2}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From this, you can see again that both approaches give the same result in the special case that both points lie on the circle since &lt;span class=&quot;math-container&quot;&gt;$\tau$&lt;/span&gt; gets 0. Putting in some real numbers will also show, that &lt;span class=&quot;math-container&quot;&gt;$\tau$&lt;/span&gt; does not get too big. I am no mathematician, but I think you can show, that the &quot;error&quot; and &lt;span class=&quot;math-container&quot;&gt;$\tau$&lt;/span&gt; get relatively small with a growing ratio of &lt;span class=&quot;math-container&quot;&gt;$r:\delta$&lt;/span&gt;. So if you are not drawing circles with a radius of just 2-3 pixels, the differences in the visual output should be negligible. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Apart from that, taking the Euclidean distance might also not be the best way in the first place. &#xA;In the end, a rasterized circle is just an approximation and not a true circle. So there is no &quot;correct&quot; rasterization method for that. With enough distance, you won't notice that it contains of pixels. But in this case, you won't also notice anymore which pixels center is closer to the &quot;true circle&quot;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Euclidean distance and Bresenham algorithm result in slightly different rasterizations (probably not noticeable most of the times).&#xA;The Euclidean distance is much more expensive to calculate due to the square roots. Additionally, as one can read in the linked sources, the Bresenham algorithm can be optimized even further than written in this answer, which makes it really fast. If I got it right, one just needs 1-2 multiplications and 2-3 additions/subtractions per pixel.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-04-18T14:21:11.480" LastActivityDate="2020-04-18T14:21:11.480" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9736" PostTypeId="2" ParentId="9734" CreationDate="2020-04-17T11:32:21.197" Score="2" Body="&lt;p&gt;The rasterizer determines, which pixel is rendered depending on vertex positions that come out of the vertex shader. For each rasterized pixel, the rasterizer knows where it lies inside the triangle formed by its three positions. With the known position inside the triangle, the rasterizer can also interpolate the vertex values for each pixel. So it also calculates the interpolated color, in case your vertex shader passes a color down the pipeline. The interpolated value is then provided to the fragment shader. However, the fragment shader can still modify the color before it is finally rendered to the screen.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Does that mean rasterizer has access to color attribute&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It has full access to everything that comes out of the vertex shader. A vertex shader must always have a position as output (&lt;code&gt;gl_Position&lt;/code&gt;). In some special cases also other outputs are required. However, if your initial vertices had a color, but the color is not passed down the pipeline by the vertex shader, the rasterizer won't produce an interpolated color. It only interpolates each variable/attribute, that comes out of the vertex shader.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;how is the color attribute passed to the rasterizer, as the inputs for rasterizer are vertices?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You can define arbitrary outputs in your vertex shader. Even if the initially submitted vertex, did not have a color attribute, you can add a color output in the vertex shader. The data the rasterizer gets per vertex is just the vertex shader outputs. A vertex is a data point containing a position and optional additional values/attributes. So if a vertex has a color attribute, the rasterizer can see it, since it is part of the vertex. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that the vertices you pass into the vertex shader and the vertices that come out of it are not the same and might differ.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Or is it happening in the fragment shader?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, the fragment shader receives already interpolated values as input. But it can decide to pass it directly, ignore it or modify it as you wish. If you just pass it through, you will see the interpolated vertex colors. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Further information can be found &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;on this site&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-04-17T11:32:21.197" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9738" PostTypeId="1" CreationDate="2020-04-17T16:29:16.187" Score="2" ViewCount="45" Body="&lt;p&gt;I had a hard time to understand this.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought &lt;code&gt;*Spectrum&lt;/code&gt; classes (&lt;code&gt;SampledSpectrum&lt;/code&gt;, specifically) store power (SI unit: W) in them and when I want RGB colors from them, I have to use some complicated method to convert power to XYZ then to RGB.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I thought &lt;code&gt;RGBspectrum&lt;/code&gt; is just a three-sample &lt;code&gt;SampledSpectrum&lt;/code&gt;, but it seems not ... If it stores power (W), how could its &lt;code&gt;ToRGB&lt;/code&gt; method directly return its power?&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;void ToRGB(Float *rgb) const {&#xA;    rgb[0] = c[0];&#xA;    rgb[1] = c[1];&#xA;    rgb[2] = c[2];&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Does &lt;code&gt;RGBSpectrum&lt;/code&gt; directly store color values in it? If that so, how could we use color to calculate radiance instead of power?&lt;/p&gt;&#xA;" OwnerUserId="6407" LastActivityDate="2020-04-17T16:29:16.187" Title="Does the RGBSpectrum class in pbrt store RGB color values directly, not power?" Tags="&lt;pbrt&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9740" PostTypeId="1" CreationDate="2020-04-17T23:24:51.620" Score="2" ViewCount="86" Body="&lt;p&gt;I’m fairly new to shader programs in general but I have a question concerning vector graphics. I understand that a pixel shader can generate the color information to draw some sort of geometry on screen. But let’s say you had a shader that created a silhouette (outline) around some geometry. Is it possible for a shader program to generate vector graphics (ie. Curves) that follow that exact silhouette (instead of pixel data)? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or in a different example, &lt;a href=&quot;https://i.stack.imgur.com/YvwZq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;this image&lt;/a&gt; was created by using a pixel shader. Would it be possible for a shader to generate the lines on a teapot as actual curve geometry rather than just a bitmap that is mapped to the 3D geometry?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I’ve tried to do some preliminary internet searches but can’t find anything that would answer this type of question. Are shader programs fundamentally different and as such could not generate lines, curves, etc. as a form of output?&lt;/p&gt;&#xA;" OwnerUserId="13201" LastEditorUserId="13201" LastEditDate="2020-04-17T23:31:09.607" LastActivityDate="2020-04-18T11:17:27.273" Title="Vector graphics output from shader program" Tags="&lt;opengl&gt;&lt;geometry-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9741" PostTypeId="2" ParentId="9740" CreationDate="2020-04-18T11:17:27.273" Score="2" Body="&lt;p&gt;In OpenGL, there are 6 different shader types:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Vertex Shader&lt;/li&gt;&#xA;&lt;li&gt;Tesselation Control Shader&lt;/li&gt;&#xA;&lt;li&gt;Tesselation Evaluation Shader&lt;/li&gt;&#xA;&lt;li&gt;Geometry Shader&lt;/li&gt;&#xA;&lt;li&gt;Fragment Shader (Pixel)&lt;/li&gt;&#xA;&lt;li&gt;Compute Shader&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The first 5 are part of the render pipeline and fulfill a very specific purpose in that pipeline. They are executed in ascending order. The shader types 2.-4. are optional and can be skipped. Between those stages, some operations are performed, that are very specific to rendering. Have a look at &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link&lt;/a&gt; for further information. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem here is: Since the rendering pipeline has a very specific purpose (generating an image of pixels), it is very hard to use it and its shaders for something else than rendering. Won't say it is impossible, but it gets certainly harder and harder the less your goal has something to do with pixel generation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For general-purpose computations, you can use compute shaders. You can basically compute anything there, so this is probably the shader type you are looking for. However, the way you ask your questions gives me the feeling, that you have some misunderstandings on how rendering works in general and you should probably read some literature about how the render pipeline creates an image from 3d data.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;But let’s say you had a shader that created a silhouette (outline) around some geometry. Is it possible for a shader program to generate vector graphics (ie. Curves) that follow that exact silhouette (instead of pixel data)? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As written above, generally yes. It is possible to write a shader that does that. But probably not with the same technique as the outline is created in the &quot;pixel case&quot;. It is certainly much more complicated.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Or in a different example, this image was created by using a pixel shader. Would it be possible for a shader to generate the lines on a teapot as actual curve geometry rather than just a bitmap that is mapped to the 3D geometry?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Again, yes it is possible for &lt;strong&gt;a&lt;/strong&gt; shader to fulfill this task, but you wouldn't use a pixel (fragment) shader for that. You would also need to approach the whole task very differently.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Are shader programs fundamentally different and as such could not generate lines, curves, etc. as a form of output?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The shaders of the rendering pipeline are tied to a very specific task and have very specific boundaries on their inputs and outputs. But if you know what you are doing, you can probably hack around those limitations. However, I think it wouldn't make much sense to do so, except you want to prove that you can. &#xA;Instead, you can use a compute shader for any computation, that has nothing to do with rendering.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;To sum it up&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You can use compute shaders to get other output types than just pixels and images made of pixels. However, calculating basic 2d shapes/curves/vector graphics from 3d data will most likly be fundamentally different than generating a corresponding bunch of pixels from that same data. In conclusion, you can't just turn a switch (change 2-3 lines of code) to select which output you like to have.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-04-18T11:17:27.273" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9742" PostTypeId="1" CreationDate="2020-04-18T12:55:56.383" Score="1" ViewCount="72" Body="&lt;p&gt;I have written a very minimal plotting code which take a function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; and a domain &lt;span class=&quot;math-container&quot;&gt;$[a,b]$&lt;/span&gt; and plots its graph. (It's &lt;a href=&quot;https://github.com/NAThompson/graphics&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, if relevant.)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, I query &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; at the sides of each pixel, and then every vertical pixel in the line gets marked. But this makes an incredibly thin graph unless the pixel density is low. So I want to support variable line thickness.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When the function is constant, this is easy: Just add the requisite number of pixels above and below the correct pixel. However, as &lt;span class=&quot;math-container&quot;&gt;$f'(x) \to \infty$&lt;/span&gt;, that gets weird. You still mark above and below the correct pixel, but then the graph appears thin. Here's an example, which I've made comically thick for emphasis:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Uws93.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Uws93.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The function &lt;span class=&quot;math-container&quot;&gt;$\sin(x)$&lt;/span&gt; is pretty much uniformly thick, but &lt;span class=&quot;math-container&quot;&gt;$1/x$&lt;/span&gt; gets really thin as &lt;span class=&quot;math-container&quot;&gt;$x\to 0$&lt;/span&gt;, and so does &lt;span class=&quot;math-container&quot;&gt;$\sin(1/x)$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What can I do to get these graphs uniformly thick?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I assume I can use automatic differentiation on &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;, does the problem have a more interesting solution?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: I tried setting the line thickness at point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; to&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;t(x) = t_{\mathrm{user}}\max(1, |f'(x)|)&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$ t_{\mathrm{user}}$&lt;/span&gt; is the user requested thickness.&#xA;But of course &lt;span class=&quot;math-container&quot;&gt;$|f'|$&lt;/span&gt; can diverge, so this did horrible things to the graph. So I did:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;t(x) = t_{\mathrm{user}}\min(\max(1, |f'(x)|), 8)&#xA;$$&lt;/span&gt;&#xA;which also looked terrible, though admittedly less terrible than before. But it's just too arbitrary, so asking the hive-mind it is.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Edit&lt;/em&gt;: I'm now thinking that the width should be marked along the normal to the tangent, i.e. the line&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;y - f(x_i) = -\frac{1}{f'(x_i)} (x-x_i),&#xA;$$&lt;/span&gt;&#xA;not along a vertical. So automatic differentiation is required?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Edit 2&lt;/em&gt;: You can get the derivative in pixel space via finite differences; that's just fine, and I image cheaper. Then it's Bresenham's line algorithm + some alpha decay with distance from the curve?&lt;/p&gt;&#xA;" OwnerUserId="13204" LastEditorUserId="13204" LastEditDate="2020-04-19T15:05:19.340" LastActivityDate="2020-04-19T15:05:19.340" Title="Uniform line thickness in plot" Tags="&lt;line-drawing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9743" PostTypeId="2" ParentId="9742" CreationDate="2020-04-18T14:23:45.060" Score="2" Body="&lt;p&gt;You should separate your line drawing logic from your calculation logic.&lt;br&gt;&#xA;In general you should try to have a generic line drawing function that would accept any number of points and draw a line from one point to the next.&lt;br&gt;&#xA;The simplest implementation for this would be to have dense points and draw a circle at each point.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you however absolutely have to calculate the color of a pixel as a function of the X coordinate you'll have to calculate the value multiple times.&lt;br&gt;&#xA;Lets say you want thickness of 3 pixels, you will have to calculate this for [X-1, X, X+1] and then check if the current pixel is close to any of the values.&lt;br&gt;&#xA;A big downside to this is that you have many duplicate calculations.&lt;/p&gt;&#xA;" OwnerUserId="13159" LastActivityDate="2020-04-18T14:23:45.060" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9744" PostTypeId="1" CreationDate="2020-04-18T16:44:20.233" Score="0" ViewCount="184" Body="&lt;p&gt;I feel like my light conservation math isn't correct, but I am not sure which part is wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is reflected light supposed to influence the diffuse light?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Does metalness only affect the reflected light or does it also affect ambient and diffuse light?&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;vec4 falbedo; // surface color&#xA;vec3 fnormal; // surface normal&#xA;&#xA;vec3 ambientLight;&#xA;&#xA;vec3 directionToCamera; // Camera normal&#xA;vec3 directionToLight; // Directional light normal&#xA;vec3 lightColor; // Directional light color&#xA;&#xA;float metalness; // 0-1&#xA;float shininess; // 1-256&#xA;float subsurface; // 0-1&#xA;&#xA;// Diffuse light&#xA;float lightNormalDot = dot(fnormal, directionToLight);&#xA;float lightIntensity = max(.0, lightNormalDot);&#xA;&#xA;// Blinn–Phong reflection&#xA;vec3 halfway = normalize(directionToCamera + directionToLight);&#xA;float reflectionFactor = max(.0, dot(halfway, fnormal));&#xA;&#xA;float reflection = pow(reflectionFactor, shininess);&#xA;&#xA;vec3 res = falbedo.rgb * ambientLight;&#xA;res += subsurface * lightIntensity * lightColor * falbedo.rgb;&#xA;res += (1. - subsurface) * reflection * mix(lightColor, lightColor * falbedo.rgb, metalness);&#xA;&#xA;gl_FragColor = vec4(res, falbedo.a);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13159" LastEditorUserId="506" LastEditDate="2021-01-19T17:46:25.880" LastActivityDate="2021-01-19T17:46:25.880" Title="What is wrong with my metallic PBR shader?" Tags="&lt;glsl&gt;&lt;lighting&gt;&lt;webgl&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9745" PostTypeId="1" CreationDate="2020-04-20T02:04:04.813" Score="0" ViewCount="53" Body="&lt;p&gt;Sorry if this is OT, but I'm wondering if there's a specific graphics technique in which it is required to extend a preexisting orthogonal set of vectors (not necessarily to a full basis, but perhaps so).  In a matrix theory lecture, the prof said that this computation has a real-world application, but I can't remember him saying what it was.  Could be computer graphics, could be a lot of things.  I realize that it is only an issue in a high-dimensional space.  For example, if you had two orthogonal vectors in 3-space, you could compute their cross product cheaply.  I asked at Math SE, and it was not appreciated.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;TLDR:  Just need the application, if any.  You don't have to say how it is computed, but feel free to if you like.  I'll read it.  I know that orthogonal vectors are often easier to work with than oblique vectors, and other very general math facts like that.&lt;/p&gt;&#xA;" OwnerUserId="13215" LastActivityDate="2020-04-21T18:07:55.343" Title="Extending an orthogonal set of vectors (graphics application?)" Tags="&lt;vectors&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9746" PostTypeId="1" AcceptedAnswerId="9757" CreationDate="2020-04-21T00:26:49.293" Score="0" ViewCount="136" Body="&lt;p&gt;I am trying to implement BRDF microfacet path tracing and I think I need a little push.&#xA;I will explain what I understand so that you can correct my mistakes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I start with simple rendering equation:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/nU5Ao.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nU5Ao.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;Le and Li are radiance we have no control of so I cannot change anything about them. The only thing I can change is function F which is called BRDF. Specifically, I am using this Cook-Torrance microfacet specular BRDF I found &lt;a href=&quot;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. &#xA;&lt;a href=&quot;https://i.stack.imgur.com/hdv5m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hdv5m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;For functions F, G and D I choose these formulas.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/a4RIm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a4RIm.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Let's start with the Fresnel function. Greater the angle between H and Wo (or Wi, it should be the same) the more light is reflected. When the angle between H and Wo will be 90° then the function will return 1. That means that all of the light is reflected. That is understandable, but when I will look directly down to normal the result will be 0.14163. is really so little light reflected back? I thought that Fresnel gives percentage between reflection and refraction on the water surface for example. Is this right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Following with function G - Geometric shading. I want to use the Smith shadowing model because I want to improve it later for multiple scattering BSDF. The equation goes like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/cGRGi.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cGRGi.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As G1 can be used more types of functions, but I like GGX. D_GGX is evaluated for both incoming light and outgoing light. It describes how much light will &lt;strong&gt;NOT&lt;/strong&gt; be blocked by surface imperfections.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And last function D - Normal distribution function. With this one, I have the biggest problems. It describes the probability that a new microfacet normal will be pointing to the given direction. This depends on roughness. So perfectly smooth surface will have every normal pointing upward, but as the surface gets rougher and rougher normals will start to point to different directions. With 100% rough material the chance of normal pointing a given direction should be uniform over the whole hemisphere. Because we are talking about probability the integral of probability over hemisphere should be 1. as this equation says, but I don't understand why there is a dot product of N and H.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ujEqV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ujEqV.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I will explain how I am using these equations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I start with generation microfacet normal H with distribution D_ggx. Spherical coordinates a generated like this: (epsilon is a random number from the interval (0;1&gt;. I can't use 1 because we cannot divide by 0)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/T4MdA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/T4MdA.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;With H defined I can reflect Wo and get Wi. H is now half vector between Wo and Wi. Now I calculate F and G. I am not using D anymore because I already used it for generating the microfacet normal H (that is against what I read in this &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4394/path-tracing-the-cook-torrance-brdf&quot;&gt;answer&lt;/a&gt;).  I divide them by 4 * dot(H, Wi)&lt;em&gt;dot(n&lt;/em&gt;Wo). This final number should be weight describing how much light [Li(Wi)] is reflected towards Wo. Together with a dot product of n and Wi from rendering equation. I think I have this part wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am not using any importance sampling for now because I think it is not necessary to work. Am I right? Of cause with importance sampling, the image would converge faster. This is my final equation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of cause, as you might guess when I implement this it returns almost totally black image. If you don't find any mistake in the math then the error has to be in code (but I will bet a 10$ it is a math problem)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H0H3s.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H0H3s.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you need any specification of my decisions or goals I will happy to answer you.&lt;/p&gt;&#xA;" OwnerUserId="12040" LastActivityDate="2020-05-06T14:33:23.683" Title="Understanding of Microfacet monte-carlo path tracing" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9748" PostTypeId="2" ParentId="9745" CreationDate="2020-04-21T18:07:55.343" Score="1" Body="&lt;p&gt;The most common use is almost certainly computing normal vectors for a surface, using a cross product. Although strictly speaking, this does not quite qualify as the two initial vectors are usually not orthogonal. This is used for shading calculations and various other algorithms. I know of &lt;a href=&quot;https://www.arnoldrenderer.com/research/egsr2013_spherical_rectangle.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;at least one&lt;/a&gt; where the initial surface is explicitly a rectangle so it would qualify.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The sampling of BRDFs is another application. In many cases, the math is done for a canonical space with the surface normal pointing up and must be transformed to the actual surface. This is done by building a full 3D basis from the surface normal vector.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anisotropic BRDFs typically have two vectors as input: the surface normal and one vector to define the orientation of anisotropy. Depending on the implementation, it may be assumed to be orthogonal to the normal. Otherwise, it is made orthogonal. Then, again, a full basis is built from those two.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a class of ray intersection algorithms which work by projecting the surface in two dimensions. This is done by starting with the ray and generating two more orthogonal vectors which define the projection plane.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is certainly not an exhaustive list but they are the main ones that came to mind. I am not aware of any uses for higher dimensions but I don't know about every corner of computer graphics either.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2020-04-21T18:07:55.343" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9749" PostTypeId="1" AcceptedAnswerId="9754" CreationDate="2020-04-22T00:34:41.113" Score="0" ViewCount="231" Body="&lt;p&gt;I am using Schlick approximation to calculate the value of the Fresnel effect I found &lt;a href=&quot;https://en.wikipedia.org/wiki/Schlick%27s_approximation&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When I try to find corner cases for the formula I get the value of 1 when the angle between normal and viewing direction is 90° and 0,02 for 0° (I am using IOR 1 and 1.33). This means that when looking, for example, at a sphere its edges will reflect almost all of the light and its center will reflect just 2% of light.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But he doesn't make sense for me when I try to use it in the microfacet model for BRDF.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/6bSTk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6bSTk.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that the reflectance when looking directly from above on the surface will be just 2% which is unrealistically low. 98% of the energy would be absorbed by the surface. So just after 3 bounces, the ray would transmit less than 0,0008% of the light. This would darken an image and I would have to increase its emitted light by a great amount.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Am I thinking in a bad way about it? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;My second idea what that it means how much light is directly reflected as a perfect reflection without being scattered my microfacet to other directions. The rest is used for diffuse/glossy reflection. But I cannot find any evidence for it anywhere. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Or I don't simply have to use Fresnel when I am dealing with non-transparent materials. &lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is my code for now.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//Position of intersection is world space&#xA;float3 hitpoint = ray.origin + ray.direction * ray.distance;&#xA;&#xA;//Direction towards camera&#xA;float3 wo = -ray.direction;&#xA;&#xA;//Geometry normal&#xA;float3 N = ray.worldNormal;&#xA;&#xA;//Microfacet normal&#xA;float3 H = SampleMicrofacetNormal(roughness, &amp;amp;N, &amp;amp;ray);&#xA;&#xA;//New direction of ray&#xA;float3 wi;      &#xA;&#xA;// Add light emitted from surface&#xA;ray.color += ray.mask * emission;&#xA;&#xA;float F = Fresnel(&amp;amp;H, &amp;amp;wi);&#xA;&#xA;float r1 = new_random(&amp;amp;ray.seed1);&#xA;&#xA;if (r1 &amp;lt;= F) {&#xA;    //Specular&#xA;&#xA;    //Reflected direction&#xA;    float3 wi = reflect(&amp;amp;H, &amp;amp;wo);    &#xA;&#xA;    float D = D_ggx(roughness, &amp;amp;N, &amp;amp;H);&#xA;    float G = G_CookTorrance(roughness, &amp;amp;N, &amp;amp;H, &amp;amp;wo, &amp;amp;wi);&#xA;&#xA;    float weight = fabs(dot(wo, H)) / fabs(dot(N, wo) * dot(N, H));&#xA;&#xA;    //Not using F because it is already taken into a count by &#xA;    //the probability of this IF/ELSE statement&#xA;    float reflectance = G * weight;&#xA;&#xA;    ray.mask *= reflectance;&#xA;&#xA;    //Check - new direction cannot point towards surface&#xA;    if (dot(wi, N) &amp;lt; 0) ray.mask = (float3)(0.0, 0.0, 0.0);&#xA;}&#xA;else {&#xA;    //Diffuse&#xA;    //Ray change color because light to through the material&#xA;    ray.mask *= color;&#xA;&#xA;    //New random direction of diffuse ray&#xA;    wi = SampleDiffuseCosineWeighted(&amp;amp;N, &amp;amp;ray);&#xA;&#xA;    //Importance sampling weight    &#xA;    ray.mask *= dot(wi, N);&#xA;}&#xA;&#xA;//Set new direction and position for next tracing&#xA;ray.direction = wi;&#xA;ray.origin = hitpoint + N * EPSILON;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="12040" LastEditorUserId="12040" LastEditDate="2020-04-23T23:09:19.803" LastActivityDate="2020-04-23T23:09:19.803" Title="Correct way to think about Fresnel effect" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;fresnel&gt;" AnswerCount="3" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9750" PostTypeId="2" ParentId="9708" CreationDate="2020-04-22T17:55:29.370" Score="3" Body="&lt;p&gt;You tile idea seems to be a good one to cut down on local complexity. You can't reasonably evaluate every primitive everywhere. Not if you want good performance anyway. So you need a simplified version for each tile, where you remove elements which have insignificant contribution. This is an interesting problem of its own. A simple version of this would be to:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Assign each primitive &quot;usefulness bounds&quot; beyond which it is considered 0. What exactly those are will depend on the curves you're using to map distance to world height. To make your life easier, pick something which actually goes to 0 over a finite distance. Or alter your favorite curve so it does.&lt;/li&gt;&#xA;&lt;li&gt;For each tile, trim out primitives for which the bounds don't intersect the tile. You can do this with a simple loop to begin with.&lt;/li&gt;&#xA;&lt;li&gt;Further simplify the operation tree. This is a little vague because you did not provide details on the kind of operations which will be in your function. But essentially, you want to do the like of replacing &lt;span class=&quot;math-container&quot;&gt;$x \times 0$&lt;/span&gt; by &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x + 0$&lt;/span&gt; by &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, until you can't anymore. The zeroes come from the previous step where you removed some primitives.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;You may need spatial hierarchies if you want this to scale to a world with millions of primitives. This can quickly become a complex topic so I'll leave it at that for now. Ask again when you get there :-)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For your more immediate problem, I suggest using the CPU to rewrite your SDF using &lt;a href=&quot;https://en.wikipedia.org/wiki/Reverse_Polish_notation&quot; rel=&quot;nofollow noreferrer&quot;&gt;reverse polish notation&lt;/a&gt;. This will allow you to write your shader as a simple interpreter, with two large buffers as inputs:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;An integer buffer with commands (union, add, multiply, point primitive, segment primitive, etc).&lt;/li&gt;&#xA;&lt;li&gt;A float buffer with operands and transforms for the primitives.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The shader is then just a loop over commands which consumes operands as needed. You'll need different command/operand buffers for every tile, obviously. Depending on the typical nature of your SDF, you may find it more efficient to have your primitives always perform union and have an explicit push command for the rare exceptions. There are a lot of ways to go about this really.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You should take care to make sure the resulting SDF can be evaluated with a reasonably small stack as this will be fixed in your shader. This is another problem by itself, perhaps well suited for the computer science SE, but probably not too difficult to solve on your own either.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm sorry if I have not provided enough OpenGL specific details but GPUs are not my specialty.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2020-04-22T17:55:29.370" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9751" PostTypeId="2" ParentId="9749" CreationDate="2020-04-22T21:37:51.163" Score="1" Body="&lt;p&gt;I will answer based on my experience with Fresnel models. Due to Kirchhoff's law of thermal radiation, in an opaque material the emissivity plus reflectivity plus absorptivity equals to one for every direction in thermal equilibrium. If the BRDF model you are using is physically-based, it should preserve energy conservation. That means that for a given viewing angle, the integral of the equation for the entire hemisphere should be equal to 1. It may be possible the reflectivity value near the normal is low, but that means that most of its contribution is elsewhere. For example, for a near-normal viewing direction, you can have a really low specular reflectivity but a much higher diffuse component. That may be the case of your model.&lt;/p&gt;&#xA;" OwnerUserId="13237" LastActivityDate="2020-04-22T21:37:51.163" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9752" PostTypeId="2" ParentId="9749" CreationDate="2020-04-23T00:41:17.687" Score="1" Body="&lt;h1&gt;&lt;strong&gt;BIG UPDATE and explanation of BRDF model&lt;/strong&gt;&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;While I was cleaning my browser and closing about 100 tabs I found this awesome &lt;a href=&quot;http://simonstechblog.blogspot.com/2011/12/microfacet-brdf.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;website&lt;/a&gt; (it was there 3 days so I could already found an answer...) which finally made everything clear for me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The problem wasn't in Fresnel at all. In fact, it doesn't matter what IOR you are using for the most time. Fresnel says how much light is reflected as a part of &lt;strong&gt;specular brdf&lt;/strong&gt;. Here important is the word &quot;specular&quot;. It means that light is reflected right when it hit the surface and it does not go through. The rest of it light that isn't refected do one of these things: is absorbed or is refracted (like in glass) or is scattered around and return to the surface as diffuse light. And the diffuse component is missing in my path tracer. I thought that specular BRDF takes a diffuse light into the count but it doesn't.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So here I will sum up how to use microfacet specular BRDF and diffuse BRDF for recursive path tracer, where I can hold only 1 ray at a time for a pixel.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Intersection with geometry&lt;/li&gt;&#xA;&lt;li&gt;Calculate Fresnel&lt;/li&gt;&#xA;&lt;li&gt;Generate random number in range 0 to 1&lt;/li&gt;&#xA;&lt;li&gt;If the number is smaller or equal to Fresnel then use specular BRDF to calculate the new direction based on the distribution function of microfacet normals and evaluate.&lt;/li&gt;&#xA;&lt;li&gt;If the number is bigger than Fresnel then use simple cosine-weighted diffuse BRDF or do refraction it is up to you.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;It is important to use both components of BRDF. Unfortunately, when you search for microfacet BRDF they usually expect you to know that it is just for the specular part.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope this help some beginners because it was a big struggle for me.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;h1&gt;&lt;strong&gt;Original answer - some part of it is wrong. For explanation look at update above.&lt;/strong&gt;&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;Ok, after some searching I have probably found a reason why it is totally ok to use Fresnel in the microfacet model.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem was low reflectance when looking from 0° grazing angle and as I said I used IOR 1 for the air and 1.33 for the objects. &lt;strong&gt;This was a big mistake.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you create a graph of Schlick approximation for IOR = 1.33 your lower limit is 0.02. But this is only true for materials with IOR of 1.33 such as glass. When I look at this &lt;a href=&quot;https://refractiveindex.info/&quot; rel=&quot;nofollow noreferrer&quot;&gt;page&lt;/a&gt; that shows IOR of different material and you find for a section for a 3D artist you can see that IOR for metal is 3.17. Plugging this into the equation your lower limit becomes 0.27. That's 10 times more!!!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even more fascinating is a fact that when you scroll down you can find &quot;Reflection calculate&quot;. This outputs a function of reflectance (use non-polarized light) which I need. It is quite strange that Schlick approximation results in almost exactly the same function as on the website for glass, but when I use IOR = 3.17 from iron it is waaayyy off. The smallest reflectance should be 0.7688 by the website.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This means that the only thing I have to do is to find a more accurate function for F component (stop using Schick approximation) and use real IOR of materials. Simply said, &quot;walls are not from water, most of the time&quot; :D&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please tell me if I am wrong here... again.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found this &lt;a href=&quot;http://psgraphics.blogspot.com/2020/03/fresnel-equations-schlick-approximation.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;page&lt;/a&gt;. It explains everything you need to know about the Fresnel effect. Most importantly it cares about both dielectrics and metals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a simplified version:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Use Schlick approximation every time, but instead of calculation F0 = [(n1-n2)/(n1+n2)]^2 use your own value. If you want accurate reflection then look on the website and for F0 choose reflectance at 0°. It is a sort of a baseline. This isn't much important for dielectric (IOR up to 1.5), where base form Schlick approximation works so be free to use the equation above.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Be careful about metallic materials. Fresnel effect depends on the wavelength of light so there will be different values of R, G a B.&lt;/p&gt;&#xA;" OwnerUserId="12040" LastEditorUserId="12040" LastEditDate="2020-04-23T19:05:41.353" LastActivityDate="2020-04-23T19:05:41.353" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9753" PostTypeId="2" ParentId="9364" CreationDate="2020-04-23T19:47:27.420" Score="0" Body="&lt;p&gt;Though quaternions cannot be visualized as points on the surface of a unit sphere in 3 dimensions, they can be readily visualized as unit &lt;em&gt;tangents&lt;/em&gt; attached to the surface of the unit sphere. &lt;a href=&quot;https://www.ri.cmu.edu/pub_files/pub4/kuffner_james_2004_1/kuffner_james_2004_1.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here is an example visualization&lt;/a&gt;. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;One could construct a similar visualization by drawing an arrow, starting at&#xA;&lt;span class=&quot;math-container&quot;&gt;$q * \hat{x}$&lt;/span&gt; and ending at &lt;span class=&quot;math-container&quot;&gt;$q * \hat{y}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\hat{x}$&lt;/span&gt; is the unit x vector, &lt;span class=&quot;math-container&quot;&gt;$\hat{y}$&lt;/span&gt; is the unit y vector, and &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; is the unit quaternion we are trying to visualize. This allows the drawing of nice smooth curves, while remaining bijective.&lt;/p&gt;&#xA;" OwnerUserId="1988" LastActivityDate="2020-04-23T19:47:27.420" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9754" PostTypeId="2" ParentId="9749" CreationDate="2020-04-23T20:49:20.117" Score="1" Body="&lt;p&gt;If you just implement Fresnel alone you'll see that what you think in your original question is mainly correct for dieletric materials.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hkXpO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hkXpO.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However don't calculate Fresnel ahead and then stochastically decide if evaluate your specular component or your diffuse one. Being part of the BRDF you have to accumulate the Fresnel term while evaluating the BRDF and only then eventually do 1-Facc for the diffuse part. If you are in a pure stochastic pathtracer then you do that directly while evaluating your microfacet. This is called 'rough Fresnel' and it's the model all modern render engines use.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For better Fresnel get the full Fresnel formula (complex Fresnel for metals). For friendlier Fresnel you can implement the 'Fresnel by colors' (can't remember the exact name rightnow I'll add it later), so instead to input numbers you input colors for F0 and F1. This is the way latest Renderman does it. Eventually add a 'metalness' parameter to switch between Fresnel and ComplexFresnel for metals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example some code (BRDF sample fnc) to inspect:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/W0ZZd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/W0ZZd.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6114" LastEditorUserId="6114" LastEditDate="2020-04-23T22:09:07.047" LastActivityDate="2020-04-23T22:09:07.047" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="9755" PostTypeId="2" ParentId="9744" CreationDate="2020-04-23T20:54:31.333" Score="1" Body="&lt;p&gt;What is wrong ? Almost everything. It is not a PBR material at all. PBR metallic materials do not use ambient term and do use generally microfacet BRDFs and ComplexFresnel.&lt;/p&gt;&#xA;" OwnerUserId="6114" LastActivityDate="2020-04-23T20:54:31.333" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9756" PostTypeId="1" AcceptedAnswerId="9880" CreationDate="2020-04-24T12:41:03.547" Score="3" ViewCount="65" Body="&lt;p&gt;I'm trying to implement the following paper in modern OpenGL&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://web.media.mit.edu/~lieber/Publications/Coloring-Book.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://web.media.mit.edu/~lieber/Publications/Coloring-Book.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The issue is that the algorithm described requires you to consider interior points in an orderly fashion -- horizontally first, then vertically. You also need a way to remember throughout the entire coloring process which parts have been already colored. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I initially thought of putting the logic in a fragment shader, but that will clearly not work because I have no control over the order in which it is called, and also no way to remember state between different invocations.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Maybe we can perform this logic on the CPU and use it to make a texture? The problem here is that I don't know of any way to access and modify specific pixels outside of shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note that doing this using the fixed function pipeline would be much more straightforward, but I want to learn modern OpenGL.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm very new to OpenGL and graphics programming, so would appreciate any suggestions on how one would go about this.&lt;/p&gt;&#xA;" OwnerUserId="13254" LastActivityDate="2020-05-24T19:44:09.817" Title="Coloring arbitrary closed regions" Tags="&lt;shader&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9757" PostTypeId="2" ParentId="9746" CreationDate="2020-04-24T13:13:52.277" Score="0" Body="&lt;p&gt;So I found out where was a problem.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This whole equation is for specular BRDF which is only one part of light interaction. When you hit the surface you have to generate new microfacet normal from distribution D. Then use it to calculate Fresnel. it gives you value from 0 to 1. That is now much light is directly reflected from the surface, but there is another part I forgot about, the diffuse component also contributes to the equation with (1 - Fresnel value).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the only problem was using just one component.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And I also introduced the importance of sampling, which negates the D resulting in:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Integral over omega = incoming light from wi *  (F * G * dot(wo, H(new microfacet normal))) / (dot(N, wo) * dot(N, H))&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is also one check. New direction wi cannot point towards the surface, because it would go through. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;if (dot(wi, N) &amp;lt; 0) ray.mask = (float3)(0.0, 0.0, 0.0);&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can darken an image quite a lot especially when you use it on the glass. But there is a solution in BSSRDF. This equation takes a multiple scattering of the light on surface into a count.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is the specular part. For the diffuse, I used a basic cosine weighted distribution with (1 - Fresnel) multiplier.&lt;/p&gt;&#xA;" OwnerUserId="12040" LastActivityDate="2020-04-24T13:13:52.277" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9758" PostTypeId="2" ParentId="9756" CreationDate="2020-04-24T13:16:21.563" Score="0" Body="&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After rereading your question, I got the feeling, that I misunderstood your question. So I'll expand my answer referring to this specific part of your question:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Maybe we can perform this logic on the CPU and use it to make a texture? The problem here is that I don't know of any way to access and modify specific pixels outside of shaders.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;A texture is basically just an array of (color) values. If you have a 256x256 image, that uses 3 color values (RGB) and each color value is stored in a single byte (&lt;code&gt;GLubyte&lt;/code&gt;/&lt;code&gt;char&lt;/code&gt;), then your array has 196608 byte sized elements. The color values are usually grouped so that 3 subsequent values represent a single pixel. Then the pixels are also ordered by column and row. So the first 765 array elements represent your first row/column of pixels in the image, the next 765 the second, and so on. With this information, you can calculate where every pixel is located in the image and modify its value as desired.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In case the texture you want to modify is loaded from a file, you should already have the pixel data since this is the format that OpenGL expects when you upload your texture. If the texture is dynamically generated on the GPU, just look into the previous version of my answer (below) for further guidance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, calculating lots of pixel data on the CPU is probably quite ineffective. I think the best solution would be to do all modifications on the GPU. If you can't achieve what you want with the standard render pipeline, you should read some tutorials about OpenGL compute shaders. I haven't worked myself with them yet, but I am pretty confident, that your problem should be solvable with them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Previous version&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://community.khronos.org/t/fastest-way-to-transfer-texture-data-from-gpu-to-ram-and-back/46011&quot; rel=&quot;nofollow noreferrer&quot;&gt;this discussion in the official OpenGL Forum&lt;/a&gt;, you can use &lt;code&gt;glReadPixels&lt;/code&gt; to get a texture from VRAM back to your normal RAM. However, in the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glReadPixels.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;reference pages&lt;/a&gt;, they say:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;glReadPixels, glReadnPixels — read a block of pixels from the frame buffer&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Important here is the term &quot;frame buffer&quot;. To find out how to use it with textures, have a look at &lt;a href=&quot;https://stackoverflow.com/questions/11863416/read-texture-bytes-with-glreadpixels&quot;&gt;this StackOverflow question&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, the accepted answer also mentions, that you can use &lt;code&gt;glGetTexImage&lt;/code&gt; (&lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetTexImage.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;link to reference page&lt;/a&gt;), which is probably more suited. Have a look into the accepted answer of this &lt;a href=&quot;https://stackoverflow.com/questions/48938930/pixel-access-with-glgetteximage&quot;&gt;StackOverflow link&lt;/a&gt; to get an understanding of how to use it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both methods should give you the pixel data on the CPU side, so you can modify it as you wish and send it back to the GPU afterward. However, this is probably a relatively slow approach.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-04-24T13:51:35.347" LastActivityDate="2020-04-24T13:51:35.347" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9759" PostTypeId="1" AcceptedAnswerId="9795" CreationDate="2020-04-25T20:38:37.217" Score="1" ViewCount="61" Body="&lt;p&gt;I often find myself in the situation where I have some old image where I composed a translucent overlay on top of a background, but then lost (or more likely discarded) the overlay. I still have pre-operation copies of the background, but have not managed to figure out how to perform an inverse operation to calculate the original overlay. Best results would be an operation I could perform in Gimp or Image Magick, but I could write an uncomposer if I had to, so long as I knew what to calculate.&lt;/p&gt;&#xA;" OwnerUserId="13260" LastActivityDate="2020-05-06T07:25:13.870" Title="Given a background image B and a composie image of A OVER B, can we somehow recover image A?" Tags="&lt;image-processing&gt;&lt;alpha&gt;&lt;compositing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9761" PostTypeId="1" CreationDate="2020-04-27T15:46:43.033" Score="1" ViewCount="119" Body="&lt;p&gt;When I am sampling diffuse BRDF I am using cosine-weighted distribution and when I want to sample specular BRDF I use sampling by GGX distribution. I can decide how much light is reflected and how much is diffused by using Fresnel. That gives me an evaluation formula like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Eval = BRDF_specular * F + BRDF_diffuse * (1 - F)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;the same principle I can use on PDF. But the problem comes up when I try to use this on sampling. It is obvious that I cannot use this interpolation for the sampled vector. But what I can do is to have some probability that I will sample specular direction and probability for sampling diffuse direction. As sample count goes up it will perform as if it was interpolation between these types of sampling. I can use this for dielectric materials because their Fresnel value is the same for RGB. But because I am using separate values for RGB for Fresnel on metallic material I can have different probabilities (for example, R = 0.8, G = 0.3, B = 0.0). This gives a nice look to metals as you can see in this &lt;a href=&quot;https://shanesimmsart.wordpress.com/2018/03/29/fresnel-reflection/&quot; rel=&quot;nofollow noreferrer&quot;&gt;post&lt;/a&gt;. What probability I should choose then? The biggest?? Average? Or is this some different approach to this problem, because I cannot find anywhere how to combine these BRDFs? &lt;/p&gt;&#xA;" OwnerUserId="12040" LastActivityDate="2020-06-08T23:01:00.103" Title="BRDF sampling and evaluation of diffuse vs specular component" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;fresnel&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9763" PostTypeId="1" CreationDate="2020-04-28T18:41:44.190" Score="0" ViewCount="48" Body="&lt;p&gt;By a bumpmap, I mean the black and white height map, not the rgb normal map style one. If I were to convert a bumpmap to a normal map then I don't think I should linearize the values because if an artist creates two pixels, one looking twice as bright to them, and therefore high, let's say at 0.2 and 0.4 values in sRGB, this is how they should be read and what the normals should be based on, right?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Converting them from sRGB to linear would mean that what looked liked two pixels with a height difference of 2 times (0.2 and 0.4) would get read as (0.03 and 0.13), if I got the calculation right. &lt;/p&gt;&#xA;" OwnerUserId="10333" LastActivityDate="2020-04-29T07:38:37.813" Title="Does a bumpmap need to be linearized from sRGB when being read?" Tags="&lt;gamma&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9764" PostTypeId="2" ParentId="9763" CreationDate="2020-04-28T20:42:40.107" Score="1" Body="&lt;p&gt;We can not answer this question. This is important, and you need to get this info from the artist (or vice versa you need to give this info to the artist before he begins) It entirely depends on what kind of assumptions were made when the artist was working with the image.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Was the artist working by numbers&lt;/li&gt;&#xA;&lt;li&gt;Was the artist working by eye&lt;/li&gt;&#xA;&lt;li&gt;Was the artist working with a sculpting application&lt;/li&gt;&#xA;&lt;li&gt;Was the data built from a photograph&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;You would be right if the artist worked by number. But if the artist was working by eye, which is incredibly hard, then you would be a bit off. sRGB does not entirely match human brightness sense so you should really fiddle a bit with the exponent if this was the case. But you might as well skip this. For sculpting and baking the image is most likely to be linear already to begin with, although the profile might not reflect this. And for the photograph case depends heavily on the method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Safest bet is to do no conversion at all. But it is not really defined so strictly. Kind of the entire world of image manipulation has skipped how to tag images that arent you know display images but pure data. Who knows how it is encoded.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="13095" LastEditDate="2020-04-29T07:38:37.813" LastActivityDate="2020-04-29T07:38:37.813" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9765" PostTypeId="2" ParentId="9763" CreationDate="2020-04-28T21:43:16.303" Score="1" Body="&lt;p&gt;A bump map should &lt;strong&gt;not&lt;/strong&gt; be linearised from sRGB, in theory.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A diffuse map or photo contains colour data, which must be encoded in a colour space. Colour spaces consist of two things, a colour gamut (what kind of red is red, what kind of green is green, what kind of blue is blue and what kind of white is white) and a transfer functions (how do you allocate the limited bits, often called gamma). Without a colour space, we would not know how to interpret the data. Choosing to then simply interpret it as sRGB would just be an assumption, that could be wrong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Bump maps, roughness maps, normal maps, etc. do not contain colour data, but rather geometric data, and therefor &lt;strong&gt;do not have a colour space&lt;/strong&gt; and no transfer function. So, the data is already linear. Another way of thinking about it, is that a transfer function is about more efficiently allocating the limited bits. Our eyes see more detail in dark areas than bright areas, so we want more of the, often, 8 bits to be for the darker areas. However, with a bump map we want the bits to be spaced out evenly. So, a transfer function wouldn't be a good idea.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In some cases, a transfer function might be useful with a bump map. Maybe you have a lot of detail in a small range (between 0.0 and 0.4) but occasionally a spike to 1.0 that prevents you from scaling that small range up. You might want to have more precision in that small range and less precision in the spike because of the detail in the small range. This is perfect for a transfer function. There would still be no colour gamut, just a transfer function. Although, this doesn't happen often.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In some other cases, the artist or the program might have added a transfer function without realising it or thinking that since it was an image saved as, for example, a JPEG, it would have needed the transfer function. In these cases, you must apply the inverse of the transfer function to get the original values back.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In short, you should always assume, unless stated otherwise, that bump maps, roughness maps, normal maps, etc. are geometric data stored in the image file as-is and not using a transfer function. Most software that generate these maps will save them in linear.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;Two irrelevant side notes:&lt;/em&gt;&#xA;&lt;em&gt;In my simple explanation of colour spaces, I assumed that we are talking about three different values for red, green and blue. However, colour data can also be encoded in different ways and you have different colour spaces to reflect that. Examples are YCbCr or YUV, CMYK, LAB and XYZ.&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;People often talk about linear as if it is a colour space, however what you are just doing, when linearising, is applying the inverse transfer function. The colour gamut is still there. You still need to know what kind of red red is. If you would be linearising sRGB or Rec.709, you would be talking about (scene-)linear sRGB. But, most people will understand you anyways.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2020-04-28T21:43:16.303" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9766" PostTypeId="1" AcceptedAnswerId="9767" CreationDate="2020-04-29T00:50:43.983" Score="1" ViewCount="57" Body="&lt;p&gt;When specifying member values for a structure consisting of float values like &lt;code&gt;vec3&lt;/code&gt; or &lt;code&gt;mat3&lt;/code&gt;, is it guaranteed that if an integer value is passed it's going to be promoted to a float? For example if I write&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 var = vec3(1, 0, 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Same when assigning an integer value to a float variable:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float var = 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Is the implicit conversion guaranteed here?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="13095" LastEditDate="2020-04-29T11:09:49.753" LastActivityDate="2020-04-29T11:09:49.753" Title="Implicit conversion in glsl shaders" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9767" PostTypeId="2" ParentId="9766" CreationDate="2020-04-29T06:56:48.507" Score="1" Body="&lt;p&gt;Yes, it is guaranteed by the GLSL language specifications (&lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;click me&lt;/a&gt;). Section &quot;4.1.10. Implicit Conversions&quot; says&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;In some situations, an expression and its type will be implicitly converted to a different type. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The spec shows all possible implicit conversions inside a table, also &lt;code&gt;int&lt;/code&gt; -&gt; &lt;code&gt;float&lt;/code&gt;. It further says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;When an implicit conversion is done, it is the same conversion that would be done under explicit&#xA;  conversion, using a constructor. &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;e.g.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float a = 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;is equivalent to writing&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float a = float(1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;There is one sentence at the end of the section, that you should keep in mind:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;The conversions in the table above are done only as indicated by other sections of this specification.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;If read it correctly, it says that you can not rely on implicit conversions in any kind of instruction you might come up with. However, regarding &lt;code&gt;vec3 var = vec3(1, 0, 0)&lt;/code&gt; section &quot;5.4.2. Vector and Matrix Constructors&quot; says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;If the basic type (bool, int, float, or double) of a parameter to a constructor does not match the&#xA;  basic type of the object being constructed, the scalar construction rules (above) are used to convert&#xA;  the parameters&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So it calls the constructor &lt;code&gt;float(int)&lt;/code&gt; before consuming each value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Even though both cases are explicitly backed by the language specifications, my personal advice is to never rely on implicit conversions. They can lead to subtle, hard to track bugs. Not sure how it is in GLSL, since I didn't test it, but in C++ this one:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;float a = 1 / 2; # &amp;lt;--- this evaluates to 0.f!&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;, deeply hidden somewhere in larger calculations, has cost me several hours of debugging more than once. It gets worse if one or both values of the fraction are taken from a variable. However, in C++ I can step through the code with a nice debugger, something that is not so easily done in GLSL. So if the only reason for using implicit conversions is laziness or some sort of taste-related decision, force yourself to be explicit. It will safe you a lot of pain.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-04-29T06:56:48.507" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9768" PostTypeId="1" AcceptedAnswerId="9770" CreationDate="2020-04-29T15:21:10.107" Score="1" ViewCount="47" Body="&lt;p&gt;I am currently using a older IntelHd Gpu which supports &lt;strong&gt;Opengl3.1 (Glsl #version140)&lt;/strong&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;While trying to locate the relevant Api for this version ,the Khronos site only provides  &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation for Opengl2.1 and Opengl4.5&lt;/a&gt;.    &lt;/p&gt;&#xA;&#xA;&lt;p&gt;On their &lt;a href=&quot;https://github.com/KhronosGroup/OpenGL-Refpages&quot; rel=&quot;nofollow noreferrer&quot;&gt;Github page&lt;/a&gt; documentation for Opengl2.1 and Opengl4 is available.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;How to locate the Api for Opengl 3.1?&lt;/p&gt;&#xA;" OwnerUserId="11471" LastActivityDate="2020-05-03T13:33:59.533" Title="Older Api documentation" Tags="&lt;opengl&gt;&lt;api&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9770" PostTypeId="2" ParentId="9768" CreationDate="2020-04-30T04:40:25.993" Score="1" Body="&lt;p&gt;Older Opengl Api documentation can be found at this &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/index_gl.php#oldspecs&quot; rel=&quot;nofollow noreferrer&quot;&gt; Official Khronos Registry&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11471" LastActivityDate="2020-04-30T04:40:25.993" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9771" PostTypeId="1" CreationDate="2020-04-30T04:48:24.777" Score="0" ViewCount="126" Body="&lt;p&gt;My question is : to allocate &lt;strong&gt;static&lt;/strong&gt; mesh data (vertex/index buffers that never change), is it best :&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;To go the &quot;obvious&quot; way : &quot;1 mesh = 1 VBO&quot;, submitting data using glBufferData with GL_STATIC_DRAW flag.&lt;/li&gt;&#xA;&lt;li&gt;To preallocate big buffers (say, a few megabytes) using glBufferStorage with a GL_DYNAMIC_STORAGE_BIT flag, and using glBufferSubData to &quot;fill&quot; the buffer with actual mesh data, side by side in the same VBO. I keep the VBO ID and offset in the VBO of every mesh.&lt;/li&gt;&#xA;&lt;li&gt;Besides, to transfer data there is also the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object#Persistent_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;persistent-mapped buffer&lt;/a&gt; technique. I could map all or part of the buffer, and write to it directly (no glBufferSubData needed). I don't see the point for static data. Perhaps I'm mistaken?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I implemented &lt;a href=&quot;https://bitsquid.blogspot.com/2015/08/allocation-adventures-3-buddy-allocator.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;a buddy allocator&lt;/a&gt; allowing me to split an OpenGL buffer in power-of-2 blocks to follow my second alternative. It allows me to &quot;pack&quot; multiple meshes in the same VBO, and to keep reusing it as mesh allocation/deallocation occurs.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It works great, but no huge speedup is observed vs. a more classic approach.&#xA;Then reading &lt;a href=&quot;http://on-demand.gputechconf.com/gtc/2014/presentations/S4379-opengl-44-scene-rendering-techniques.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;these slides&lt;/a&gt; for example (especially slide 24), they're basically saying this approach isn't the efficient path except for very specific cases (uniform buffer, less than 64 kb, offsets have to be multiple of 4 !). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there some &quot;best practices&quot; regarding buffer data management ? Is it useful to worry about it at all ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've read tons of material regarding OpenGL buffer management lately, and now I feel a bit lost. It would be great to have a &quot;recap&quot; of all the possibilities and expected relative performance of each vs. the others.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(Note : I'm targeting OpenGL 4.5, so DSA is allowed).&lt;/p&gt;&#xA;" OwnerUserId="13284" LastActivityDate="2020-04-30T04:48:24.777" Title="Best practices fo OpenGL static buffer data : what is best for performance?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9772" PostTypeId="1" AcceptedAnswerId="9777" CreationDate="2020-04-30T17:17:26.210" Score="0" ViewCount="49" Body="&lt;p&gt;I’m looking to somehow programmatically query the state of graphics during a PC gameplay session. What I mean by “state of graphics” is, how polygons, textures, lighting and any other scene elements are stored and computed for any particular frame. I’m mainly interested in what the graphics card is doing on a low level. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there any need to be game engine specific in this matter, or will all games be drawn to the screen in the same way?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I’m specifically interested in NVIDIA cards if at all possible. I’m not sure if different manufacturers do things differently, but I only have an NVIDIA card. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Are there any tools or APIs that will give me access to this data? &lt;/p&gt;&#xA;" OwnerUserId="11412" LastActivityDate="2020-05-01T10:21:40.307" Title="API or Tools to query state of graphics during gameplay?" Tags="&lt;api&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9773" PostTypeId="1" CreationDate="2020-04-30T18:44:46.837" Score="2" ViewCount="24" Body="&lt;p&gt;For a real-time application I am trying to add glow to a few hundred points. These points are more like 2D circles of various small sizes on the screen. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;These points are supposed to be like balls of light so it makes sense that they should glow and that it should be very bright when multiple are in proximity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;These points are sometimes as small as 4 pixels so they can easily disappear in lower resolutions. Previously I have done this using convolutions (gaussian blur) and have employed a variety of processes to speed things up.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Separate vertical and horizontal passes&lt;/li&gt;&#xA;&lt;li&gt;Taking advantage of bilinear sampling&lt;/li&gt;&#xA;&lt;li&gt;Doing the blur at a lower resolution&lt;/li&gt;&#xA;&lt;li&gt;Using Metal's special kernel for it&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;However none of these performs quite well enough. They are ok but I want to try to push further.  A few ways these methods all fail are the following&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;If the points cluster or overlap it doesn't look too bright. They are completely opaque and so even with additive blending it doesn't work.&lt;/li&gt;&#xA;&lt;li&gt;I have to have a lower radius of blur than I would like as I tradeoff quality for blur distance.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;What I am looking for is to see if there are any techniques that I might be able to replace these with or add to them. One thought has been spatial data structures. I thought about splitting up the space with a BSP and then coloring squares based on how deep into the tree that square is and how many points it has in it. This has issues for the following reasons.&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I don't feel like a BSP algorithm translates nicely to GPUs&lt;/li&gt;&#xA;&lt;li&gt;Points on the edge of multiple partitions would be poorly represented&lt;/li&gt;&#xA;&lt;li&gt;How do you even visualize on a GPU how many points are within each partition in a binary tree&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Do you think any part of this algorithm would translate well to GPUs?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am ok with it looking square because I can blur that or just blend it in with the existing blur. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can you think of any sorts of algorithms that might help me achieve my two goals&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A bunch of points clustered close together have an aura that is very far reaching and looks brighter than just one point.&lt;/li&gt;&#xA;&lt;li&gt;General portions of the screen where a lot of points are are a bit brighter&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="7072" LastEditorUserId="7072" LastEditDate="2020-04-30T18:50:35.157" LastActivityDate="2020-04-30T18:50:35.157" Title="Visualizing auras around clusters of points" Tags="&lt;gpu&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9774" PostTypeId="1" CreationDate="2020-04-30T21:07:18.510" Score="0" ViewCount="101" Body="&lt;p&gt;I have few questions regarding tone-mapping and gamma correction.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;is a tone-mapping operator a function whose output is a value between [0,1] ?&#xA;If this isn't the case and since gamma encoding requires a value to be in range [0,1], do I need to normalize the values after tone-mapping?&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;imagine a diffuse horizontal surface with (0.5,0.5,0.5) reflectance under an unobstructed uniform sky of radiance (1,1,1) cd/m2. The incident radiance on an image pixel coming off this surface will have value of (0.5,0.5,0.5). Now, most codes I have seen apply gamma encoding(raising pxl value to the power of 0.45) at this stage just before saving it to the file. But on viewing the image, the colors are distorted and much brighter corresponding to (186,186,186) color value. If I don't apply gamma encoding then the image file displays the expected color that is (127,127,127).&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;If the CRT monitor or the LCD does apply the inverse of gamma, then by encoding it I must see the original color that is (127,127,127), is that right? &#xA;And if I am seeing (186,186,186) instead, am I right therefore to assume the encoding happens internally on saving the image data as png or jpg format? and therefore I don't need to do any gamma encoding? &lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2020-04-30T21:32:21.820" LastActivityDate="2020-05-01T02:31:03.460" Title="Two questions on Gamma correction and Tonemapping" Tags="&lt;rendering&gt;&lt;gamma&gt;&lt;tone&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9775" PostTypeId="2" ParentId="9774" CreationDate="2020-05-01T02:31:03.460" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;the colors are distorted and much brighter corresponding to (186,186,186) color value. If I don't apply gamma encoding then the image file displays the expected color that is (127,127,127).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;No, the gamma-correct color is not distorted; your &lt;em&gt;expectations&lt;/em&gt; are. If your lighting, meshes, textures, and other scene elements were not built to be properly linear and gamma correct to the screen, then every decision you have made has been through a distorted lens. If you don't like the effect you're getting with a properly gamma-correct lighting system, that's the fault of all of those decisions you've been making, not with gamma correction.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Half of the full lighting intensity in a linear colorspace does correspond to greater than half in a gamma-correct colorspace. And those gamma-correct values are what you &lt;em&gt;ought&lt;/em&gt; to be passing to the screen. If that's not what you're shoving into the display, then you're doing lighting wrong.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-05-01T02:31:03.460" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9776" PostTypeId="1" AcceptedAnswerId="9778" CreationDate="2020-05-01T09:39:36.947" Score="0" ViewCount="136" Body="&lt;p&gt;I know that 3D artists make a 3D model with quads. And they advise to remesh with quads only (if it's possible).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So I have some questions:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Why do we use quads in CG (for games, cartoons, film, etc) if the graphic card (or render, I'm not sure) convert quads to tris all the same?&lt;/li&gt;&#xA;&lt;li&gt;Why many 3D apps (Max, Blender, Maya, etc) have a triangulate function? Eventually, the graphic card (or render) does that.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;I want to clarify this question for myself since I know it incompletely.&lt;/p&gt;&#xA;" OwnerUserId="13290" LastActivityDate="2020-05-06T14:12:10.820" Title="What tris and quads need for?" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;triangulation&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9777" PostTypeId="2" ParentId="9772" CreationDate="2020-05-01T10:21:40.307" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;What I mean by “state of graphics” is, how polygons, textures, lighting and any other scene elements are stored and computed for any particular frame.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The closest to what you are asking and that I know of is &lt;a href=&quot;https://renderdoc.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;RenderDoc&lt;/a&gt;. I have not tested it myself so far, but some &lt;a href=&quot;https://renderdoc.org/docs/getting_started/features.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;features they list in their documentation&lt;/a&gt; that are related to your question are:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Full graphics pipeline state display&lt;/li&gt;&#xA;&lt;li&gt;Shader source display&lt;/li&gt;&#xA;&lt;li&gt;Flexible resource inspector&lt;/li&gt;&#xA;&lt;li&gt;Mesh buffer inspection and visualisation&lt;/li&gt;&#xA;&lt;li&gt;‘Raw’ buffer inspection for buffers&lt;/li&gt;&#xA;&lt;li&gt;Texture/render target viewer&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;I’m looking to somehow programmatically query the state of graphics during a PC gameplay session.&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;...&lt;/p&gt;&#xA;  &#xA;  &lt;p&gt;Is there any need to be game engine specific in this matter, or will all games be drawn to the screen in the same way?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I am not sure here if you are asking to dissect the graphics state of a commercial game or software that is not written by yourself. If so, there is no guarantee that RenderDoc can capture data but it is possible. See for example &lt;a href=&quot;https://github.com/baldurk/renderdoc/issues/666&quot; rel=&quot;nofollow noreferrer&quot;&gt;this issue on their GitHub page&lt;/a&gt;, where the author says:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;However I want to be clear that I cannot and do not support capturing 3rd party programs that you do not control. &lt;strong&gt;It generally works&lt;/strong&gt; but for obvious reasons I don't provide any help with problems...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As stated in &lt;a href=&quot;https://renderdoc.org/docs/behind_scenes/how_works.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this section of their documentation&lt;/a&gt;, RenderDoc uses a &quot;man-in-the-middle&quot; approach to get the data. So it intercepts any calls to the graphics API (OpenGL, DirectX, Vulkan) of the executed program, gathers the data it needs, and passes it along to the API afterward.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-05-01T10:21:40.307" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9778" PostTypeId="2" ParentId="9776" CreationDate="2020-05-01T10:43:12.487" Score="2" Body="&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Because the geometry will be subdivided into quads. Anyway the primary reason for this is if you have a function with 2 directions it is easer for humans to think it out andcanticipate results if its a quad.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Software renderers dont have to rely on triangles. And did not for a long time. But then if you microdice your surface who cares its not like you can see the micropolygon anyway.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For more on this read &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5465/why-are-quads-used-in-filmmaking-and-triangle-in-gaming&quot;&gt;this post&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You might want to control the triangulation yourself. Interpolation does not happen the same way regardless of how the triangles are laid out. So being able to triangulate and then flip offending triangles is useful.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2020-05-01T10:50:59.113" LastActivityDate="2020-05-01T10:50:59.113" CommentCount="0" CommunityOwnedDate="2020-05-01T10:43:12.487" ContentLicense="CC BY-SA 4.0" />
  <row Id="9780" PostTypeId="2" ParentId="9614" CreationDate="2020-05-02T20:29:00.643" Score="0" Body="&lt;p&gt;Found a solution. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In the vertex shader I project position from model to the clip-space, then from clip-space to screen space, adjust the width in screen pixels, and the project back to clip-space, which ultimately becomes &lt;code&gt;gl_Position&lt;/code&gt; value.&lt;/p&gt;&#xA;" OwnerUserId="7512" LastActivityDate="2020-05-02T20:29:00.643" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9781" PostTypeId="1" CreationDate="2020-05-02T23:47:23.653" Score="0" ViewCount="248" Body="&lt;p&gt;I am doing some project on object reconstruction and I need to rotate an object in PyTorch during the training to make sure I am augmenting the data properly. My data consists of points and it's normals. My question is, how should I (or should I train them at all) rotate the normals of my mesh. Note that this rotation also needs to keep the object inside the unit cube, where it was before the transformation. &lt;/p&gt;&#xA;" OwnerUserId="13298" LastEditorUserId="13095" LastEditDate="2020-05-04T15:38:18.340" LastActivityDate="2021-05-29T18:01:05.133" Title="Rotation of meshes in PyTorch" Tags="&lt;3d&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9783" PostTypeId="2" ParentId="9781" CreationDate="2020-05-03T09:29:27.763" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;My question is, how should I (...) rotate normals of my mesh.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Normals are rotated the same way as the rest of your mesh/point cloud. But make sure that you use a &quot;pure rotation matrix&quot; for this (no scaling, no translation). Since rotations preserve lengths, you do not need to renormalize your normals (usually - floating-point errors might accumulate).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This sentence of you&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Note that this rotation also needs to keep object in unit cube, where it was before running this code.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;lets me guess, that you are actually asking how to rotate an object and its normals and not just the normals. In python, you can use the packages SciPy and NumPy for that.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The Rotation package (&lt;a href=&quot;https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.transform.Rotation.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation&lt;/a&gt;) of SciPy helps you to generate an arbitrary rotation matrix. Then you can use NumPys &lt;code&gt;matmul&lt;/code&gt; function to rotate your points and normals.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a short example script that rotates a single point 20 degrees around the z axis:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;from scipy.spatial.transform import Rotation as Rot&#xA;import numpy as np&#xA;&#xA;p = np.array([1, 1, 0]).transpose()&#xA;rot_mat = Rot.from_euler(seq=&quot;z&quot;, angles=20, degrees=True).as_matrix()&#xA;&#xA;p_r = np.matmul(rot_mat, p)&#xA;&#xA;print(p)&#xA;print(p_r)&#xA;print(np.linalg.norm(p))&#xA;print(np.linalg.norm(p_r))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;output:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;[1 1 0]&#xA;[0.59767248 1.28171276 0.        ]&#xA;1.4142135623730951&#xA;1.414213562373095&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;strong&gt;Info:&lt;/strong&gt; Depending on your SciPy version you might need to replace &lt;code&gt;as_matrix&lt;/code&gt; with &lt;code&gt;as_dcm&lt;/code&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As you can see, apart from some minor floating-point error, the length (last 2 outputs) did not change. Furthermore, I chose the example point, so that it gets outside the unit cube. To address this problem, you need to find the maximum absolute value inside the transformed data. You can use &lt;code&gt;amax&lt;/code&gt; and &lt;code&gt;amin&lt;/code&gt; to get the maximum and minimum value (&lt;a href=&quot;https://stackoverflow.com/questions/55284090/how-to-find-max-value-in-2d-array-with-index&quot;&gt;see also here&lt;/a&gt;) if you put all your coordinates into one large 2d array (a matrix). Then compare the absolute values of the &lt;code&gt;amax&lt;/code&gt; and &lt;code&gt;amin&lt;/code&gt; results and pick the larger one. Divide all your coordinates (not the normals!) by this value, to scale your model back into the unit cube. Alternatively, you can create a uniform scaling matrix&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{bmatrix}&#xA;s&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;s&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;s&#xA;\end{bmatrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;with &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; being the reciprocal of the maximum absolute value. Multiply this matrix with all points.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To sum it up:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;calculate the rotation matrix with SciPy&lt;/li&gt;&#xA;&lt;li&gt;Multiply the rotation matrix with all points and normals&lt;/li&gt;&#xA;&lt;li&gt;find the maximum absolute value in the rotated data&lt;/li&gt;&#xA;&lt;li&gt;scale your coordinates with the found maximum value&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Remark:&lt;/strong&gt; If you put your points and normals into 2 matrices, you can apply the rotations and scaling matrices without a loop, which makes it much faster.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-05-03T09:29:27.763" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9784" PostTypeId="2" ParentId="9768" CreationDate="2020-05-03T13:33:59.533" Score="0" Body="&lt;p&gt;OpenGL 4.5 reference pages have tables at the bottom of each page indicating in which version particular function was added. For example, if you look at &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glTexStorage2D.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;glTexStorage2D&lt;/a&gt;, you can see that it was introduced in 4.2, while its DSA equivalent in 4.5.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think that the reason for having separate pages for 2.1 and 4.5 is that the former includes legacy functions, while the latter has only core profile functions.&lt;/p&gt;&#xA;" OwnerUserId="8796" LastActivityDate="2020-05-03T13:33:59.533" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9785" PostTypeId="1" AcceptedAnswerId="9801" CreationDate="2020-05-03T22:03:13.743" Score="1" ViewCount="145" Body="&lt;p&gt;I'm currently passing an array of bone positions to GLSL for a skeletal animation shader; the positions are passing successfully but producing a GL_INVALID_OPERATION error.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm passing the matrices in the following line:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;std::vector&amp;lt;glm::mat4x4&amp;gt; bpos;&#xA;...&#xA;glUniformMatrix4fv(shader.uniform(&quot;bpos&quot;), 50, GL_FALSE, &amp;amp;bpos.at(0)[0][0]);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Where the &lt;code&gt;shader.uniform(&quot;bpos&quot;)&lt;/code&gt; position has been assigned earlier as:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;this-&amp;gt;m_uniforms[&quot;bpos&quot;] = glGetUniformLocation(this-&amp;gt;m_program, &quot;uniform_bpos&quot;);&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm getting the following output:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;GL CALLBACK: ** GL ERROR ** type = 0x824c, severity = 0x9146, message = GL_INVALID_OPERATION in glUniform3(uniform &quot;uniform_bpos&quot;@1 is matrix)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Has anyone here encountered this error or does anyone here see what I'm doing incorrectly?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The vertex shader:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;&#xA;layout(location = 0) in vec3 vert_ms;&#xA;layout(location = 1) in vec3 norm_ms;&#xA;layout(location = 2) in ivec4 bone_ids;&#xA;layout(location = 3) in vec4 bone_weights;&#xA;&#xA;&#xA;out vec3 norm_ws;&#xA;out vec3 pos_ws;&#xA;&#xA;uniform mat4 uniform_mvp;&#xA;uniform mat4 uniform_bpos[50];&#xA;&#xA;void main(){&#xA;     mat4 bone = uniform_bpos[bone_ids[0]] * bone_weights[0];&#xA;     bone += uniform_bpos[bone_ids[1]] * bone_weights[1];&#xA;     bone += uniform_bpos[bone_ids[2]] * bone_weights[2];&#xA;     bone += uniform_bpos[bone_ids[3]] * bone_weights[3];&#xA;&#xA;     gl_Position = uniform_mvp * bone * vec4(vert_ms, 1);&#xA;     norm_ws = (uniform_mvp * bone * vec4 (norm_ms, 0)).xyz;&#xA;     pos_ws = vec3(gl_Position);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;the function getting the uniform locations:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;Shader::Shader(GLuint shader_program)&#xA;{&#xA;  this-&amp;gt;m_program = shader_program;&#xA;&#xA;  this-&amp;gt;m_uniforms[&quot;mvp&quot;] = glGetUniformLocation(this-&amp;gt;m_program, &quot;uniform_mvp&quot;);&#xA;  this-&amp;gt;m_uniforms[&quot;bpos&quot;] = glGetUniformLocation(this-&amp;gt;m_program, &quot;uniform_bpos&quot;);&#xA;  this-&amp;gt;m_uniforms[&quot;eye&quot;] = glGetUniformLocation(this-&amp;gt;m_program, &quot;uniform_eye&quot;);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;from this file: &lt;a href=&quot;https://github.com/EricJIsaac/opengl-engine/blob/feature/pb-materials/src/graphics/shader.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/EricJIsaac/opengl-engine/blob/feature/pb-materials/src/graphics/shader.cpp&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;uploading the vertex data:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;void SkeletonMeshBuffer::predraw()&#xA;{&#xA;  glEnableVertexAttribArray(0);&#xA;  glEnableVertexAttribArray(1);&#xA;  glEnableVertexAttribArray(2);&#xA;  glEnableVertexAttribArray(3);&#xA;  glBindBuffer(GL_ARRAY_BUFFER, this-&amp;gt;m_vbo);&#xA;&#xA;  // Vertices&#xA;  std::size_t stride = sizeof(graphics::data::SkeletonMesh_Vertex);&#xA;  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, stride, (void*)0);&#xA;&#xA;  // Normals&#xA;  char* offset = (char*)0 + 3 * sizeof(float);&#xA;  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, stride, (void*)offset);&#xA;&#xA;  // Bone Ids&#xA;  offset = (char*)0 + 6 * sizeof(float);&#xA;  glVertexAttribIPointer(2, 4, GL_UNSIGNED_SHORT, stride, (void*)offset);&#xA;&#xA;  // Bone Weights&#xA;  offset = (char*)0 + 6 * sizeof(float) + 4 * sizeof(unsigned short);&#xA;  glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, stride, (void*)offset);&#xA;&#xA;  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this-&amp;gt;m_ele);&#xA;}&#xA;&#xA;void SkeletonMeshBuffer::draw(std::size_t id)&#xA;{&#xA;  if(id &amp;lt; 0 || id &amp;gt; this-&amp;gt;m_entries.size())&#xA;  {&#xA;    printf(&quot;Invalid skeleton mesh id %lu requested\n&quot;, id);&#xA;    return;&#xA;  }&#xA;&#xA;  char* offset = (char*)0 +&#xA;    this-&amp;gt;m_entries[id].index_offset * sizeof(unsigned short);&#xA;&#xA;  glDrawElementsBaseVertex(&#xA;    GL_TRIANGLES,&#xA;    this-&amp;gt;m_entries[id].index_count,&#xA;    GL_UNSIGNED_SHORT,&#xA;    (void*)offset,&#xA;    this-&amp;gt;m_entries[id].vertex_offset / 3);&#xA;}&#xA;&#xA;void SkeletonMeshBuffer::postdraw()&#xA;{&#xA;    glDisableVertexAttribArray(0);&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;from this file: &lt;a href=&quot;https://github.com/EricJIsaac/opengl-engine/blob/feature/pb-materials/src/graphics/skeleton_mesh_buffer.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/EricJIsaac/opengl-engine/blob/feature/pb-materials/src/graphics/skeleton_mesh_buffer.cpp&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The meshes being loaded:&#xA;&lt;a href=&quot;https://github.com/EricJIsaac/opengl-engine/tree/master/data/geometry/skeletonMeshes&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/EricJIsaac/opengl-engine/tree/master/data/geometry/skeletonMeshes&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13304" LastEditorUserId="13304" LastEditDate="2020-05-04T15:21:54.177" LastActivityDate="2020-05-08T07:08:50.717" Title="Passing mat4 array to GLSL succeeding but producing GL_INVALID_OPERATION" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9788" PostTypeId="1" CreationDate="2020-05-04T11:58:23.597" Score="0" ViewCount="29" Body="&lt;p&gt;I am just trying to rotate my pointcloud object which is inside the unit cube ([-1,1] in all x,y,z axis). What I did is use the basic rotation matrix from &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt; and extend it to homogenuous 4x4 matrix (with 0 everywhere in 4th row and 4th column except in [4,4] position where  I put 1). When I did multiplication of object by rotation matrix and normalized points by their 4th value like this:  &lt;span class=&quot;math-container&quot;&gt;$$(x,y,z,k) -&amp;gt; (x/k,y/k,z/k, 1)$$&lt;/span&gt;&#xA;I see that my pointcloud object is no longer inside the unit cube and since I know that rotation is shape and length preserving transformation, I want to know how can I shift my pointcloud object back to unit cube in a way it is centered in (0,0,0) as before.&lt;/p&gt;&#xA;" OwnerUserId="13298" LastActivityDate="2020-05-04T11:58:23.597" Title="Does rotating object inside unit cube [-1,1] by homogenous matrix move it outside unit cube" Tags="&lt;transformations&gt;&lt;projections&gt;&lt;affine-transformations&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9789" PostTypeId="1" CreationDate="2020-05-04T18:36:24.323" Score="4" ViewCount="159" Body="&lt;p&gt;I have three quaternions A, B, C.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also have a 3D vector P which describes the barycentric coordinate to interpolate.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I want to interpolate the three quaternions with respect to the barycentric coordinate P&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This Image shows how to do it would A, B and C be usual vectors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tz13g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tz13g.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;but how to calculate the quaternion interpolation?&#xA;Can I use the &quot;slerp&quot; command somehow?&#xA;How would the glm code look like?&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-10-12T02:04:16.813" Title="Three quaternions interpolation with barycentric coordinates" Tags="&lt;glm&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9791" PostTypeId="1" CreationDate="2020-05-04T22:23:31.167" Score="0" ViewCount="115" Body="&lt;p&gt;I am trying to implement a simple raytracer in python. &lt;a href=&quot;https://www.gabrielgambetta.com/computer-graphics-from-scratch/basic-ray-tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;I am following this tutorial here&lt;/a&gt; &lt;/p&gt;&#xA;&#xA;&lt;p&gt;here is my code, i have explained in comments the relevant parts .All i am getting is a blank image.      &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Program&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;import math&#xA;from collections import namedtuple&#xA;&#xA;&#xA;class P3Image:&#xA;    def __init__(self, width,  height):&#xA;        self.width = width&#xA;        self.height = height&#xA;        self.img = [[0]*width]*height&#xA;&#xA;    def pixel(self, x, y, color):&#xA;        self.img[y][x] = color&#xA;&#xA;    def __rescale(self, color):&#xA;        ''' rescale a color range from 0-1 to 0-225 '''&#xA;        return Vec3(round(color.x*255), round(color.y*255) , round(color.z*255))&#xA;&#xA;    def save(self, filename):&#xA;        with open(filename, 'w') as f:&#xA;            f.write(f'P3 {self.width} {self.height}\n255\n')&#xA;            for row in self.img:&#xA;                for color in row:&#xA;                    color = self.__rescale(color)&#xA;                    f.write(f'{color.x} {color.y} {color.z}  ')&#xA;                f.write('\n')&#xA;&#xA;&#xA;class Vec3:&#xA;    def __init__(self, x, y, z):&#xA;&#xA;        self.x = x&#xA;        self.y = y&#xA;        self.z = z&#xA;&#xA;    def __str__(self):&#xA;        return f'Vec3({self.x},{self.y},{self.z})'&#xA;&#xA;    def __sub__(self, other):&#xA;        return Vec3(self.x - other.x , self.y - other.y , self.z - other.z)&#xA;&#xA;    def __add__(self, other):&#xA;        return Vec3(self.x +  other.x , self.y + other.y , self.z + other.z)&#xA;&#xA;    def mag(self):&#xA;        return math.sqrt(self.x**2, self.y**2, self.z**2)&#xA;&#xA;    def dot(self, other):&#xA;        if isinstance(other, Vec3):&#xA;            return self.x * other.x + self.y * other.y + self.z * other.z&#xA;        raise Exception('this should recieve an arfument of type Vec3') &#xA;&#xA;    def cross(self, other):&#xA;        if isinstance(other, Vec3):&#xA;            return Vec3( self.y* other.z - self.x* other.y, self.z* other.x - self.x* other.z , self.x * self.y - self.y * self.x)&#xA;        raise Exception('this should recieve an arfument of type Vec3') &#xA;&#xA;&#xA;def trace_ray(O, D, t_min, t_max):&#xA;    closest_t = math.inf&#xA;    closest_sphere = None&#xA;&#xA;    for sphere in scene['spheres']:&#xA;        t1, t2 = ray_sphere_intersect(O, D, sphere)&#xA;&#xA;        if  (t_min &amp;lt; t1 &amp;lt; t_max) and t1 &amp;lt; closest_t:&#xA;            closest_t  = t1&#xA;            closest_sphere = sphere&#xA;&#xA;        if (t_min &amp;lt; t2 &amp;lt; t_max) and t2 &amp;lt; closest_t:&#xA;            closest_t = t2&#xA;&#xA;            closest_sphere = sphere&#xA;&#xA;    if closest_sphere == None:&#xA;        return Vec3(1,1,1)&#xA;    else:&#xA;        return closest_sphere['color']&#xA;&#xA;&#xA;&#xA;def dot(v1, v2):&#xA;    return v1.x* v2.x + v1.y * v2.y + v1.z * v2.z&#xA;&#xA;def ray_sphere_intersect(O, D, sphere):&#xA;    C = sphere['center']&#xA;    r = sphere['radius']&#xA;    oc = O - C&#xA;    k1 = dot(D,D)&#xA;    k2 = 2*dot(oc, D)&#xA;    k3 = dot(oc, oc) - r*r&#xA;&#xA;    discriminant = k2*k2 - 4*k1*k3&#xA;&#xA;    if discriminant &amp;lt; 0:&#xA;        return math.inf, math.inf&#xA;&#xA;    t1 = (-k2 + math.sqrt(discriminant))/(2*k1)&#xA;    t2 = (-k2 - math.sqrt(discriminant))/(2*k1)&#xA;    return t1, t2&#xA;&#xA;&#xA;def canvas_to_viewport(x,y):&#xA;    return Vec3(x*Vw/Cw, y*Vh/Ch, d)&#xA;&#xA;&#xA;def c_to_i(x, y):&#xA;    '''canvas to image'''&#xA;&#xA;    xnew = xmin + (xmax - xmin)/Cw&#xA;    ynew = ymin + (ymax - ymin)/Ch&#xA;    return Vec3(xnew, ynew, d)&#xA;&#xA;&#xA;&#xA;# define scene with one sphere &#xA;scene = {&#xA;        'spheres':[&#xA;                {&#xA;                'center':Vec3(0,0 ,0),&#xA;                'radius': 0.5,&#xA;                'color':Vec3(1,0,0)&#xA;                },&#xA;            ]&#xA;    }&#xA;&#xA;&#xA;if __name__ == '__main__':&#xA;&#xA;    WIDTH  = 320 &#xA;    HEIGHT = 200&#xA;    camera = Vec3(0, 0, -1)&#xA;&#xA;    aspect_ratio = WIDTH/HEIGHT&#xA;&#xA;    xmin = -1 &#xA;    xmax = 1  &#xA;&#xA;    ymax = 1/aspect_ratio&#xA;    ymin = -1*ymax&#xA;&#xA;    xstep = (xmax - xmin) / (WIDTH-1)&#xA;    ystep = (ymax - ymin) / (HEIGHT-1)&#xA;&#xA;    image = P3Image(WIDTH, HEIGHT)&#xA;&#xA;    for j in range(HEIGHT):&#xA;        y  = ymin + j*ystep&#xA;        for i in range(WIDTH): &#xA;            x  = xmin + i*xstep&#xA;            ray = Vec3(x,y,0) - camera&#xA;            color = trace_ray(camera, ray, -1, math.inf)&#xA;&#xA;            print(i,j,color)&#xA;&#xA;            image.pixel(i, j, color)&#xA;&#xA;&#xA;    image.save('ii.ppm')&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; &lt;em&gt;I modified the main render loop to avoid negative index while generating image as suggested by @Oliver. but now even now i get a blank image. but i am sure the rays are hitting sphere properly as evident from the output of print statement in code.&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="13309" LastEditorUserId="13309" LastEditDate="2020-05-05T19:07:59.070" LastActivityDate="2021-01-30T21:04:10.557" Title="a very simple raytracer is giving a black output which is implemented in python" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9792" PostTypeId="2" ParentId="9789" CreationDate="2020-05-05T18:01:59.740" Score="3" Body="&lt;h2&gt;Defining the problem&lt;/h2&gt;&#xA;&lt;p&gt;The weighted arithmetic mean &lt;span class=&quot;math-container&quot;&gt;$\mu$&lt;/span&gt;, of a set of vectors, minimizes squared L2 norm of the error (&lt;span class=&quot;math-container&quot;&gt;$v_i$&lt;/span&gt;) to all elements of the set.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{equation}&#xA;\begin{split}&#xA;v_i &amp;amp;= \mu - x_i \\&#xA;\mu &amp;amp;= \underset{\mu \in \mathbb{R^n}}{\text{argmin}} \; \frac{1}{2}\sum\limits_{v_i} w_i ||v_i||^2_2 \\&#xA;\end{split}&#xA;\end{equation}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;This empowers us to define special means, where we use different notions of distance.&lt;/p&gt;&#xA;&lt;h2&gt;Specializing for rotations&lt;/h2&gt;&#xA;&lt;p&gt;A reasonable notion of distance for SO(3) is the &lt;em&gt;angle&lt;/em&gt; separating two rotations. That's &lt;span class=&quot;math-container&quot;&gt;$||\log(\mu \ q^{-1})||$&lt;/span&gt; Your geometry library probably implements this &lt;span class=&quot;math-container&quot;&gt;$log$&lt;/span&gt;, and expressions for it can be found &lt;a href=&quot;http://ethaneade.com/lie.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. It is not the log one is accustomed to on the real numbers.&lt;/p&gt;&#xA;&lt;p&gt;Intuition: Recall that every sequence of rotations corresponds to &lt;a href=&quot;https://en.wikipedia.org/wiki/Euler%27s_rotation_theorem&quot; rel=&quot;nofollow noreferrer&quot;&gt;a single rotation about a single axis&lt;/a&gt;, so the difference between a pair of rotations can always be summarized by a single angle.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{equation}&#xA;\begin{split}&#xA;v_i &amp;amp;= log(\mu \ x_i^{-1}) \\&#xA;\mu &amp;amp;= \underset{\mu \in \mathbb{SO3}}{\text{argmin}} \sum\limits_{v_i} w_i || v_i||^2_2 \\&#xA;\end{split}&#xA;\end{equation}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;There's no analytical form for this minimum for more than two rotations. We can, however, treat this as a &lt;a href=&quot;http://ethaneade.com/optimization.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;least squares problem&lt;/a&gt; and compute the result by Gauss-Newton.&lt;/p&gt;&#xA;&lt;p&gt;To apply Gauss-Newton in general, for some error, we need to be able to find &lt;span class=&quot;math-container&quot;&gt;$\mathbf{J_i} = \frac{d}{d\mu}v_i(\mu)$&lt;/span&gt;, which requires differentiating &lt;span class=&quot;math-container&quot;&gt;$v_i$&lt;/span&gt;. Then we can take a step as&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{equation}&#xA;\begin{split}&#xA;\Delta \mu &amp;amp;= \sum\limits_{i}(w_i \mathbf{J_i}^T \mathbf{J_i})^{-1} \sum\limits_{i} w_i \mathbf{J_i}^T v_i&#xA;\end{split}&#xA;\end{equation}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Our error function cannot readily be differentiated, since its argument is a rotation &lt;span class=&quot;math-container&quot;&gt;$\mu$&lt;/span&gt; and not a vector. We invent a parameter &lt;span class=&quot;math-container&quot;&gt;$\delta \in \mathbb{R^3}$&lt;/span&gt; which we will &lt;span class=&quot;math-container&quot;&gt;$Exp$&lt;/span&gt; into a rotation. This, we can differentiate&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{equation}&#xA;\begin{split}&#xA;v_i &amp;amp;= log(Exp(\delta)\; \mu \ x_i^{-1}) \\ &#xA;\mathbf{J_i} &amp;amp;= \frac{d}{d\delta} v_i = \mathbf{I} \\&#xA;\end{split}&#xA;\end{equation}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So the update to &lt;span class=&quot;math-container&quot;&gt;$\mu$&lt;/span&gt; is&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{equation}&#xA;\begin{split}&#xA;\delta &amp;amp;= \sum\limits_{i}(w_i \mathbf{J_i}^T \mathbf{J_i})^{-1} \sum\limits_{i} w_i \mathbf{J_i}^T v_i\\&#xA;\delta &amp;amp;= \sum\limits_{i} w_i \sum\limits_{i} w_i v_i \\&#xA;\delta &amp;amp;= \sum\limits_{i} w_i v_i&#xA;\end{split}&#xA;\end{equation}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;h1&gt;Conclusion&lt;/h1&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{equation}&#xA;\begin{split}&#xA;\delta = \sum\limits_{i} w_i v_i &amp;amp;= \sum\limits_{i}w_i log(\mu_{k}^{\mathstrut} x_{i}^{-1}) \\&#xA;\mu_{k + 1} &amp;amp;= Exp(\delta) \mu_{k}\\&#xA;\end{split}&#xA;\end{equation}&#xA;$$&lt;/span&gt;&#xA;This will converge quadratically to a mean.&lt;/p&gt;&#xA;&lt;p&gt;Caveat emptor: for rotations, there may be many &amp;quot;means&amp;quot;. By analogy: What is the average point, on Earth's surface, of the north and south poles? Every point on the equator has equal right to be called the average. This is the case for all equispaced rotations.&lt;/p&gt;&#xA;" OwnerUserId="1988" LastEditorUserId="1988" LastEditDate="2020-10-12T02:04:16.813" LastActivityDate="2020-10-12T02:04:16.813" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9793" PostTypeId="2" ParentId="9791" CreationDate="2020-05-05T20:12:56.653" Score="0" Body="&lt;p&gt;Ok, after several hours of debugging, I finally got the answer and posting it here.&#xA;The issue was in image generation.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;class P3Image:&#xA;    def __init__(self, width,  height):&#xA;        self.width = width&#xA;        self.height = height&#xA;&#xA;        self.img = [[None for _ in range(width)] for _ in range(height)]&#xA;&#xA;    def set_pixel(self, x, y, color):&#xA;        self.img[y][x] = color&#xA;        print(self.img[19][173], y,x, color)&#xA;&#xA;&#xA;    def __rescale(self, color):&#xA;        ''' rescale a color range from 0-1 to 0-225 '''&#xA;        return Vec3(round(color.x*255), round(color.y*255) , round(color.z*255))&#xA;&#xA;    def save(self, filename):&#xA;        with open(filename, 'w') as f:&#xA;&#xA;            f.write(f'P3 {self.width} {self.height}\n255\n')&#xA;            for row in self.img:&#xA;                for color in row:&#xA;                    c = self.__rescale(color)&#xA;                    f.write(f'{c.x} {c.y} {c.z}  ')&#xA;&#xA;                f.write('\n')&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13309" LastActivityDate="2020-05-05T20:12:56.653" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9795" PostTypeId="2" ParentId="9759" CreationDate="2020-05-06T07:25:13.870" Score="0" Body="&lt;p&gt;Just to confirm, assuming non-premultiplied alpha, at one point you performed the following, per pixel operation:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ Result_{RGB} = Src_{A} * Src_{RGB} + (1.0 - Src_{A})* Background_{RGB} $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You say you've lost the &lt;span class=&quot;math-container&quot;&gt;$Src_{ARBG}$&lt;/span&gt; data,  but have retained the &lt;span class=&quot;math-container&quot;&gt;$Background_{RGB}$&lt;/span&gt; and the &lt;span class=&quot;math-container&quot;&gt;$Result_{RGB}$&lt;/span&gt;, but want to recover the &lt;span class=&quot;math-container&quot;&gt;$Src$&lt;/span&gt; data?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Unless you can make some other assumptions, you &lt;em&gt;might&lt;/em&gt; be out of luck. It's a rather underconstrained problem. &#xA;Jim Blinn notes in &quot;&lt;em&gt;Fun with Premultiplied Alpha&lt;/em&gt;&quot; that there are some commercial systems that are used to 'de-bluescreen' but they may require the operator to identify, say, what is 'Source' and 'Background'.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As an extreme example, you may have a pixel in the result which exactly matches the background but the source pixel may also have been the same colour.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If, on the other hand, &lt;span class=&quot;math-container&quot;&gt;$Result$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$Background$&lt;/span&gt; don't match, then you know that the source is involved but &lt;em&gt;if&lt;/em&gt; the &lt;span class=&quot;math-container&quot;&gt;$Src$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$Result$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$Background$&lt;/span&gt; RGB values are all collinear, then there could be multiple possible solutions.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Having said this, there may be some heuristics that perhaps could be used, but it'd require some thinking. &#xA;Perhaps, pixels which differ and are not collinear could be used to estimate &lt;span class=&quot;math-container&quot;&gt;$Src_A$&lt;/span&gt;, with some level of 'certainty', and this could be 'filtered' to neighbouring 'uncertain' pixels and the process repeated.&#xA;Non-constant pixels in the destination with a local neighbourhood which all match the background might be assumed to have an alpha of 0.0.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2020-05-06T07:25:13.870" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9796" PostTypeId="2" ParentId="9776" CreationDate="2020-05-06T14:12:10.820" Score="-1" Body="&lt;p&gt;In addition to what other people have said, for cpu / raytracing it is more memory effecient to store quads even though they may be intersected as two triangles.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you have millions of polygons, this memory saving is useful and there are no real performance side effects.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-05-06T14:12:10.820" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9797" PostTypeId="2" ParentId="9746" CreationDate="2020-05-06T14:33:23.683" Score="1" Body="&lt;p&gt;Some more clarity on the fresnel.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;F tells you how much light is reflected, and (1 - F) therefore tells you how much light is transmitted through the layer/material/surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Generally we put fresnels into two types Dielectric(water/glass) and Conductor(metals).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The approximation you are using is for a dielectric fresnel, so what you are actually modelling is a thin layer over the top of your diffuse. In renderers this layer is normally called the coat or clearcoat. It can be used to emulate laminated materials or a coating of water/sweat.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you want to render metals you would need to swap out the fresnel for a conductive one. There are better approximations, but an easy artistic approximation is to swap the F0 of your schlick approximation with the rgb of your material. You can layer a diffuse below this if you need to but you may find with conductive it's not nessisary.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.codinglabs.net/article_physically_based_rendering_cook_torrance.aspx&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is a good article on the topic for further reading.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-05-06T14:33:23.683" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9798" PostTypeId="1" CreationDate="2020-05-07T14:15:00.233" Score="1" ViewCount="42" Body="&lt;p&gt;I have a bezier curve and would like to draw it's stroke. To do that, I planned to approximate the stroke to a polygon and fill it with a scanline algorithm. While I feel confident about implementing the conversion and the scanline algorithm, I am unsure how to handle the situation when a polygon intersects itself.&lt;/p&gt;&#xA;&lt;p&gt;If I don't treat it specially, it will look like on this picture on the left side, but what I am actually looking for is something like on the right side. Is there a popular method how to do that?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uggRT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uggRT.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13318" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-05-07T14:15:00.233" Title="How to do a scanline fill with a self intersecting polygon?" Tags="&lt;vector-graphics&gt;&lt;polygon&gt;&lt;bezier-curve&gt;&lt;drawing&gt;&lt;scanline&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9799" PostTypeId="1" CreationDate="2020-05-07T15:38:23.367" Score="-1" ViewCount="81" Body="&lt;p&gt;I'm trying to understand how much graphics programming actually needs to be done if you are using an engine like Unreal Engine to build and package a game.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I understand some of this might have to do with whether the engine in question supports your targeted rendering features or not. Generally speaking however, if you didn't need to add any rendering features to the engine, would there be any need for graphics programming at all?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Doesn't it handle all of the needed rendering instruction under the hood right off the shelf?&lt;/p&gt;&#xA;" OwnerUserId="11412" LastActivityDate="2021-01-19T12:03:10.337" Title="In Game Engines, how much of the graphics pipeline is already written?" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9800" PostTypeId="2" ParentId="9799" CreationDate="2020-05-07T20:08:48.577" Score="3" Body="&lt;p&gt;Any full-featured engine such as UE4 or Unity will include a fully functional renderer out of the box, with support for multiple platforms/APIs, and typical modern graphics features such as PBR shaders/materials, various types of lights and shadows, global illumination, particles, postprocessing effects, etc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If the built-in renderer already handles everything you want, there is no need to do any graphics coding with these engines. But many games have at least a few things they want to do differently, or custom effects that aren't built in, so they will extend the engine with some of their own shaders or graphics passes.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-05-07T20:08:48.577" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9801" PostTypeId="2" ParentId="9785" CreationDate="2020-05-08T07:08:50.717" Score="1" Body="&lt;p&gt;The eye position (a vec3) was being bound to the wrong shader, resulting in the &lt;code&gt;glUniform3&lt;/code&gt; error when OpenGL (mesa) checked the validity of the uniforms. The error was due to a typo; I named my simple-mesh and animated-mesh shaders similar things.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glUseProgram(smesh_shader.get());&#xA;      smb.predraw();&#xA;      glUniform3fv(mesh_shader.uniform(&quot;eye&quot;), 1, &amp;amp;eye[0]); // &amp;lt;- Oops&#xA;      graphics::ogl::render(scene.getRoot(), smb, mv, smesh_shader);&#xA;      smb.postdraw();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Following @Christian Rau's and @wychmaster's suggestions, I was able to debug the issue. I also needed to build a debug version of the mesa library to make sense of the stack-trace in gdb.&lt;/p&gt;&#xA;" OwnerUserId="13304" LastActivityDate="2020-05-08T07:08:50.717" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9804" PostTypeId="1" CreationDate="2020-05-08T21:10:30.373" Score="0" ViewCount="47" Body="&lt;p&gt;I was looking for algorithms that quickly compute quite nice realistic, or not realistic, animated landscapes, in video format (&quot;animated&quot; = the camera moves, or the water is animated, etc.) But all I found were: deep learning GANs, which are difficult to train, or even difficult to set or transfer. (&quot;hard&quot; and time-consuming too)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The animated landscapes rendered can be like children's cartoons: I just want to quickly generate landscapes, which have to be quite beautiful, that's all.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What research papers, documentation, tutorials, tools, APIs, libraries, Github/Gitlab repositories should I read? MIT license or equivalent please.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="8709" LastEditorUserId="8709" LastEditDate="2020-05-08T21:19:04.813" LastActivityDate="2020-05-08T21:19:04.813" Title="What fast algorithms can generate not-realistic but quite handsome animated landscapes?" Tags="&lt;image-processing&gt;&lt;image&gt;&lt;procedural-generation&gt;&lt;video&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9807" PostTypeId="1" CreationDate="2020-05-09T22:38:06.823" Score="0" ViewCount="30" Body="&lt;p&gt;I have a few questions about setting up a bidirectional path tracer described by Veach &lt;a href=&quot;https://graphics.stanford.edu/courses/cs348b-03/papers/veach-chapter10.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have created both an eye path and a light path. Both are using BRDF for calculating how much light can pass after bounce and directions are sampled with importance sampling.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My first question is: Can I connect all possible combinations of paths? In the example below, it is a connection of points [1;3], [1;4], [1;light], [2;3], [2;4], [2; light]. It is definitely a bad idea to connect the camera with anything, but I am not sure if it the same with directly connecting with a light source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/SUTpD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SUTpD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And secondly, do I have to average the radiance coming from all the connected paths? I am not implementing a multiple-importance sampling for now. It will be the next step because without it I am adding even more variance.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Last one. Because I am using an importance sampling I am dividing by PDF. But when I am connecting these two paths I am making deterministic connection so I use PDF of 1. Is this right?&lt;/p&gt;&#xA;" OwnerUserId="12040" LastActivityDate="2020-05-09T22:38:06.823" Title="Birectional path tracing - connection of paths" Tags="&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9808" PostTypeId="2" ParentId="9761" CreationDate="2020-05-09T22:44:42.270" Score="1" Body="&lt;p&gt;So I found a solution on a shader toy.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I choose randomly from sampling diffuse or sampling specular with distribution 50:50. But I calculate PDF of both and average then. If you want to use a different proportion between sample function you just have to make sure that PDFs are combined with the same proportion as choose. &lt;/p&gt;&#xA;" OwnerUserId="12040" LastActivityDate="2020-05-09T22:44:42.270" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9809" PostTypeId="1" CreationDate="2020-05-10T09:05:44.710" Score="1" ViewCount="117" Body="&lt;p&gt;When ray tracing, I find it intuitively clear that deeper paths have a lower contribution to the overal picture than shorter paths. This is the main reason why it is generally okay to render a picture only to a certain depth, but I am currently not able to prove this.&lt;/p&gt;&#xA;&lt;p&gt;Formally, we can write the rendering equation as&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{align*}&#xA;    L_o(\vec{p}_0, \omega_0) &amp;amp;= L_e(\vec{p}_0, \omega_0) \\&#xA;    &amp;amp;+ \int_{\Omega} f_r(\vec{p}_0, \omega_0, -\omega_1) \cos{\theta_1} L_e(\vec{p}_1, \omega_1) \text{d} \omega_1 \\&#xA;    &amp;amp;+ \int_{\Omega^2} f_r(\vec{p}_0, \omega_0, -\omega_1) \cos{\theta_1} f_r(\vec{p}_1, \omega_1, -\omega_2) \cos{\theta_2} L_e(\vec{p}_2, \omega_2) \text{d} \omega_1 \text{d} \omega_2 \\&#xA;    &amp;amp;+ \dots \,,&#xA;\end{align*}&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$\vec{p}_{j+1}$&lt;/span&gt; is defined as the intersection of a ray with origin &lt;span class=&quot;math-container&quot;&gt;$\vec{p}_j$&lt;/span&gt; and direction &lt;span class=&quot;math-container&quot;&gt;$-\omega_{j+1}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\theta_{j+1}$&lt;/span&gt; is the angle between the normal of the surface at &lt;span class=&quot;math-container&quot;&gt;$\vec{p}_j$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$-\omega_{j+1}$&lt;/span&gt;. Each term represents the radiance contribution of respectively paths with depth 0, 1, 2, and so on. Let's denote the contribution of depth &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$L_o^{(d)}(\vec{p}_0, \omega_0)$&lt;/span&gt;. &lt;strong&gt;I suspect that, under mild conditions on the scene, the contributions of these terms will asymptotically decrease exponentially:&lt;/strong&gt; &lt;span class=&quot;math-container&quot;&gt;$$L_o^{(d)}(\vec{p}_0, \omega_0) = \mathcal{O}(t^d) \,\text{ as } d \rightarrow \infty$$&lt;/span&gt; for some &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$0 &amp;lt; t &amp;lt; 1$&lt;/span&gt;, where I have used the big-O notation.&lt;/p&gt;&#xA;&lt;p&gt;Of course, I expect this only to hold when the scene is somehow &amp;quot;realistic&amp;quot;, which I define as follows.&lt;/p&gt;&#xA;&lt;p&gt;Firstly, all light sources should have only a limited amount of power. Note that infinite radiances, like with point lights, should be permitted, as long as their power is finite.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;strong&gt;The total power of all light sources should be finite.&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/RbHvb.gif&quot; width=&quot;250&quot; /&gt;&#xA;&lt;p&gt;Secondly, we should exclude scenes that consists only of mirrors or diffuse white materials, or any other material that perfectly conserves energy. In other words, the scene should always absorb a little energy. These materials should still be permitted though, as long as their reflected light eventually ends up in materials that do not conserve the energy. I tried to formalize this the following way.&lt;/p&gt;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;&lt;strong&gt;There exists an integer &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; with the following property: for every point &lt;span class=&quot;math-container&quot;&gt;$\vec{p}$&lt;/span&gt; in the scene there should be a path of length &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; that starts in &lt;span class=&quot;math-container&quot;&gt;$\vec{p}$&lt;/span&gt; and which has a throughput smaller than 1.&lt;/strong&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/KzuU3.gif&quot; width=&quot;400&quot; /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Questions.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Using these assumptions, is it possible to prove my suspicion? How would you do it?&lt;/p&gt;&#xA;&lt;p&gt;If it isn't possible, are there other &amp;quot;realistic&amp;quot; conditions that will make it proveable? Any conditions you come up with should not limit scenes that are used in practice in any way. (I know, sometimes people create materials that transmit more light than what comes in. You can ignore these materials).&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;What I tried so far.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I was able to prove this with some stronger conditions, namely&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;There is an upper bound &lt;span class=&quot;math-container&quot;&gt;$L_{max}$&lt;/span&gt; on emitted radiance &lt;span class=&quot;math-container&quot;&gt;$L_e$&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;li&gt;There is an upper bound &lt;span class=&quot;math-container&quot;&gt;$t &amp;lt; 1$&lt;/span&gt; on the percentage of energy that materials conserve.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/0oNkf.gif&quot; width=&quot;360&quot; /&gt;&#xA;&lt;p&gt;With these conditions, the prove is straightforward, but they do not allow point lights or perfectly white diffuse materials and such.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Proof.&lt;/em&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align*}&#xA;    L_o^{(d)}(\vec{p}_0, \omega_0) &amp;amp;= \int_{\Omega^d} \left(\prod_{j=1}^d f_r(\vec{p}_{j-1}, \omega_{j-1}, -\omega_j) \cos{\theta_j} \right) L_e(\vec{p}_d, \omega_d) \text{d} \omega_1 \dots \text{d} \omega_d&#xA;\end{align*}&lt;/span&gt;&#xA;Using condition (1):&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align*}&#xA;    &amp;amp;\leq L_{max} \int_{\Omega^d} \prod_{j=1}^d f_r(\vec{p}_{j-1}, \omega_{j-1}, -\omega_j) \cos{\theta_j} \text{d}\omega_j \\&#xA;    &amp;amp;= L_{max} \int_{\Omega} \text{d}\omega_1 f_r(\vec{p}_{0}, \omega_{0}, -\omega_1) \cos{\theta_1} \int_\Omega \dotsm \int_{\Omega} \text{d}\omega_d f_r(\vec{p}_{d-1}, \omega_{d-1}, -\omega_d) \cos{\theta_d}&#xA;\end{align*}&lt;/span&gt;&#xA;By applying condition (2) recursively on the innermost integral:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{align*}&#xA;    &amp;amp;\leq L_{max} t^d&#xA;\end{align*}&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="13225" LastEditorUserId="13225" LastEditDate="2020-10-08T08:32:16.083" LastActivityDate="2020-10-08T08:32:16.083" Title="Prove radiance contributions of deeper paths fade away" Tags="&lt;raytracing&gt;&lt;lighting&gt;&lt;mathematics&gt;&lt;physically-based&gt;&lt;physics&gt;" AnswerCount="1" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9811" PostTypeId="1" CreationDate="2020-05-10T20:16:02.763" Score="0" ViewCount="174" Body="&lt;p&gt;I'm trying to manually create a color data to load as a texture with OpenGl for learning purposes. I created an &lt;code&gt;unsigned char&lt;/code&gt; array consisting of 4 pixels with 3 channels:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;unsigned char data[] = {&#xA;                        255, 0, 0,&#xA;                        0, 255, 0,&#xA;                        0, 0, 255,&#xA;                        255, 255, 0&#xA;                    };&#xA;int width = 2;&#xA;int height = 2;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here is how I'm passing the data:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);&#xA;float color[] = {1, 1, 1, 1};&#xA;glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;However I'm not getting the correct texture colors with this. Although if I specify the same data but choose with width of 4 and height of 1, this works correctly. Am I doing something wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When specifying resolution 4x1 I get what I expect, 4 rows of colors:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/t1MAn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t1MAn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However when specifying the texture as 2x2 I expect 4 quadrants with respective color in each, but I get wrong colors in lower two quadrants:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IjjfD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IjjfD.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-05-10T20:35:06.903" LastActivityDate="2020-05-10T20:35:06.903" Title="Generate hardcoded texture data to pass to shaders" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9813" PostTypeId="1" AcceptedAnswerId="9815" CreationDate="2020-05-10T21:02:33.587" Score="-1" ViewCount="107" Body="&lt;p&gt;I had this doubt in my head for several months and have been unable to find an answer anywhere on internet.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know what OpenGL, DirectX, Vulkan, Metal, etc... are, I already know what they are used for (literally in any multimedia software application).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question is &quot;in the real world when people work directly with a graphical API (eg: DirectX)?&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, if I want to create a game I will use a game engine, if I want to create special effects I will use a program for VFX, if I want to create an animated scene with different 3D models I will use something like Blender.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are the situations where a person could say &quot;Ok, this problem can only be solved by writing my own software with DirectX/C++&quot;?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My question arises from the fact that I would like to learn DirectX (later Vulkan also) as a matter of curiosity but I know that graphic programming is a demanding topic that requires a lot (a lot!) of time.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I work for a company most of my day and since the salary is quite low (especially because at 21yo nobody takes you seriously), in the evening I dedicate myself to secondary activities in order to earn something more. I can't find a good reason to stop dedicating myself to these activities to study something that will not lead me to any type of business.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In my country (Italy) there are some (not a lot) job offerings concerning graphic programming but all require a degree in Metematics/Physics, which I don't have.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, in summary, what are the situations where you need to &quot;get your hands dirty&quot; with a graphical API (eg: DirectX) instead of using a tool already made?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know there are big game companies that for example reinvent the wheel (they write the rendering engine from 0) because they will pay off the costs and it is not convenient for them to pay for an engine already made. This environment doesn't interest me much because it certainly cannot lead to an individual business.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Other situations where you work directly with a graphical API is the world of simulations, but there I imagine it is more a matter of mathematics and physics, not of graphics.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'd like to read about some experience of those who work/worked with a graphic API and what your role was in the industry. I'd also like to read about someone who has his own business that somehow relates to a graphical API.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks a lot to everyone :)&lt;/p&gt;&#xA;" OwnerUserId="13346" LastEditorUserId="13346" LastEditDate="2020-05-12T20:55:31.210" LastActivityDate="2020-05-12T20:55:31.210" Title="When do people need to work directly with a graphical API (eg: Direct3D) instead of using already made software?" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;vulkan&gt;&lt;directx&gt;&lt;metal&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9815" PostTypeId="2" ParentId="9813" CreationDate="2020-05-10T21:43:59.263" Score="4" Body="&lt;p&gt;This is a similar question to following: When do you need to cook? You can go to a restaurant. Why would you need to know woodworking? You can buy things from a shop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two answers here&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;In order for you to claim ownership on some tech. You need to build it. This can be simply because you have chosen to sell a competing product or need to lower your licensing fees.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note you dont have to be big to benefit from this.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You have custom needs that are not being met by other things. Even if you mainly work in a engine by others you may still need to generate some form of asset or shader to handle some aspect. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Not because you exactly might need it but it makes the product better or it mskes your life easier. Also: If you dont practice then you can never recognize when you could have help in the custom thing. &lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;It is really hard to come up with concrete situations where you need either. Because once that situation arises it gets snatched up by someone so you nolonger need it. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The thing is the world isnt as ready as you think. And technology has a very nasty habit of dropping you entirely when you need something more. You might suddenly realize that because you stepped slightly out of bounds of your tech you now need to implement a very large chunk of the system since your not covered by their legal framework or their particular implementation does not extend neatly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is also a third option. But you have dismissed it out of hand:&lt;/p&gt;&#xA;&#xA;&lt;ol start=&quot;3&quot;&gt;&#xA;&lt;li&gt;&lt;p&gt;Because you can! I mean ive done a lot of things with this principle. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;But if you mever do anything like this you might not be invited to do so in the future&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;PS: None of this is valid fuel for saying i dont need to learn this. Even if you never use stuff like this knowing it can be done can be extremely valuable. Learning more makes you undertand what can be done better.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2020-05-11T08:55:11.663" LastActivityDate="2020-05-11T08:55:11.663" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9816" PostTypeId="1" AcceptedAnswerId="9817" CreationDate="2020-05-11T08:16:02.483" Score="1" ViewCount="40" Body="&lt;p&gt;Shaders get compiled during runtime every single time an app starts. I understand the reasoning for this is that there are so many GPU architectures out there that it does not make sense to ship pre-compiled shaders. However, I wonder if the designers have explored the possibility of storing out the compiled shader during the first run and load the compiled version from the next run. This is akin to having the intermediate &quot;&lt;code&gt;*.o&lt;/code&gt;&quot; as in C/C++ compilation and just linking them when we're building the app. If this is possible, is it a bad idea to do this?&lt;/p&gt;&#xA;" OwnerUserId="13343" LastActivityDate="2020-05-11T13:50:50.080" Title="Do we have OpenGL shaders write out the intermediate *.o-esque file on first compile so that we can skip compiling them in run-time every single time?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;&lt;gpu&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9817" PostTypeId="2" ParentId="9816" CreationDate="2020-05-11T13:50:50.080" Score="2" Body="&lt;p&gt;OpenGL 4.1's &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glGetProgramBinary.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glGetProgramBinary&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glProgramBinary.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;glProgramBinary&lt;/code&gt;&lt;/a&gt; exist for this purpose. The first one retrieves a binary that represents the compiled program in its entirety (though none of the state stored within it. It, and its implementation-defined format, can be stored and reloaded via &lt;code&gt;glProgramBinary&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, there are limitations. Implementations are not required to be able to load the format they gave you. That is, a driver change could cause implementations to switch to a different versions, leaving all of your binaries obsolete and un-loadable. So you have to be ready to recompile from the source.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, GL 4.6 allows you to &lt;a href=&quot;https://www.khronos.org/opengl/wiki/SPIR-V&quot; rel=&quot;nofollow noreferrer&quot;&gt;employ SPIR-V&lt;/a&gt;, an intermediate shader language. The idea here is that you compile your code to SPIR-V, then load that SPIR-V into a shader, where you can move forward from there. There are no version changes that could break your code.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Of course, SPIR-V is an intermediate language, so it still has to be compiled to some degree, along with all of the error checking and the like needed to make the final GPU code. It won't be faster than program binaries, but it's a bit more reliable (for implementations that support it).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-05-11T13:50:50.080" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9818" PostTypeId="2" ParentId="9809" CreationDate="2020-05-11T15:58:34.627" Score="1" Body="&lt;p&gt;If you are asking whether:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int fr(...) cos\theta_1Le_1 &amp;gt; \int fr(...)cos\theta_1 fr(...)cos\theta_2 Le_2&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(simplified terms from the render equation you posted above), I don't think you could prove this. Le_2 could just be much greater than Le_1. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example you could have a set of mirrors which only hit a light source after two bounces. Then all the light would come from the second integral.&lt;/p&gt;&#xA;&#xA;&lt;hr&gt;&#xA;&#xA;&lt;p&gt;EDIT: Updating answer after your response.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are trying to prove that, ignoring the layout and lights of the scene, deeper paths contribute less to the overall equation, then you could try ignoring Le and assuming it is always 1. You are then trying to prove:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int_\Omega fr(...)cos\theta_1  &amp;gt; \int_{\Omega^2}fr(...)cos\theta_1fr(...)cos\theta_2&#xA;$$&lt;/span&gt;&#xA;or&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int_{\Omega_1} fr(...)cos\theta_1 dw_1 &amp;gt; \int_{\Omega_1} fr(...)cos\theta_1\int_{\Omega_2} fr(...)cos\theta_2 dw_2 dw_1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;We also know that if the fr is energy conserving:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;0 \leq \int fr(...)  \leq 1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;And if 0 &amp;lt; cos &amp;lt; 1 we can say that:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;0 \leq \int fr(...)cos\theta \leq 1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Substituting this knowlege into the equation into the inner integration of the right hand side doesnt give us much, as it could always be equal to 1 which would give us: &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int_{\Omega_2} fr(...)cos\theta_2 dw_2  = 1&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int_{\Omega_1} fr(...)cos\theta_1 dw_1 &amp;gt; \int_{\Omega_1} fr(...)cos\theta_1 dw_1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;which disproves your idea. However if your bxdf is never perfectly energy conserving, eg:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;0 \leq \int fr(...)  &amp;lt; 1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I think subsitituting this in does prove the above as we get something like:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;0 \leq n(w) &amp;lt; 1&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\int_{\Omega_1} fr(...)cos\theta_1 dw_1 &amp;gt; \int_{\Omega_1} fr(...)cos\theta_1 n(w)dw_1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As each term can only be less than the integral on the left.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Hopefully my math is okay here I might have made a mistake. You may need to clean it up and do some more formal proofs. I am sorry if this still doesnt help answer your question.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastEditorUserId="13321" LastEditDate="2020-05-12T11:29:15.833" LastActivityDate="2020-05-12T11:29:15.833" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9820" PostTypeId="1" AcceptedAnswerId="9823" CreationDate="2020-05-11T16:52:16.790" Score="1" ViewCount="50" Body="&lt;p&gt;I am new to concepts in CG. What are the red and white rectangles trying to represent in the following screenshot?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rU0eh.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rU0eh.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The image is from the paper &quot;MoSh: Motion and Shape Capture from Sparse Markers&quot;.&lt;/p&gt;&#xA;" OwnerUserId="6281" LastActivityDate="2020-05-12T10:52:58.797" Title="chess-like rectangles on the mesh" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9821" PostTypeId="1" AcceptedAnswerId="9822" CreationDate="2020-05-11T22:07:56.647" Score="1" ViewCount="89" Body="&lt;p&gt;I'm working on a simple 3d modeller and I would like to render the back facing triangles a bit darker, to easier differentiate between front and back faces. Like you can see in most modelling applications. How does one achieve is?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Should I enable back face culling and render the primitives and then enable front face culling, rotate the normals by 180 degrees and render the primitives again? Is this a practical approach?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-05-11T22:31:24.897" LastActivityDate="2020-05-12T01:55:50.563" Title="OpenGL Render front and back faces with different shading for 3d modeller" Tags="&lt;opengl&gt;&lt;shading&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9822" PostTypeId="2" ParentId="9821" CreationDate="2020-05-12T01:55:50.563" Score="2" Body="&lt;p&gt;A fragment shader receives the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Fragment_Shader#System_inputs&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;gl_FrontFacing&lt;/code&gt; system-defined input value&lt;/a&gt;. It will be &lt;code&gt;false&lt;/code&gt; if the fragment was generated from a back-facing triangle, and &lt;code&gt;true&lt;/code&gt; otherwise. So you can use that in your shader to determine how to generate a color value.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-05-12T01:55:50.563" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9823" PostTypeId="2" ParentId="9820" CreationDate="2020-05-12T10:52:58.797" Score="5" Body="&lt;p&gt;I don't think it's trying to represent anything in particular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In CG there is a concept of textures, which is a bit like painting the surface of an object a specific color/look. For example, on a car you may want to paint scratches and dust on the surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here they have created a human model from their capture data, and when visualising it they have decided to texture/paint a red/white checker pattern on top.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They have most likely added it for the viewer's benifit, as it helps emphasise the curves and overall shape of the model, esspesially as it animates. They also probably chose contrasting colors so the model was easier to view on a white background.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-05-12T10:52:58.797" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9824" PostTypeId="1" AcceptedAnswerId="9844" CreationDate="2020-05-12T15:27:41.173" Score="0" ViewCount="61" Body="&lt;p&gt;I am writing a small raytracer in python , everything was working fine but when i implemented plane geometry then the reflective spheres are getting weird patches on lower bottom. image below:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;I guess this is happening because of some error in calculating lighting with wrong normals? but i am unable to figure out exactly what.&lt;/em&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/fHB56.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fHB56.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;code to find palne-ray intersection:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;class Plane(Shape):&#xA;    def __init__(self, color, y=0, specular=-1, reflective=0):&#xA;        self.specular = specular&#xA;        self.reflective = reflective&#xA;        self.center = Vec3(0,y,0)&#xA;        self.normal = Vec3(0,-1,0)&#xA;        self.color = color&#xA;&#xA;    def intersect_at_point(self, origin, ray):&#xA;        denom = ray.dot(self.normal)&#xA;&#xA;        if abs(denom) &amp;gt; 0.0001:&#xA;            diff  = self.center - ray&#xA;            t = diff.dot(self.normal) / denom&#xA;&#xA;            if t &amp;gt; 0.0001:&#xA;                return t&#xA;        return None&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;trace ray function.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;def trace_ray(self, origin, direction, t_min, t_max, depth):&#xA;    closest_object, closest_t = self.closest_intersection(origin, direction, t_min, t_max)&#xA;&#xA;    if closest_object == None:&#xA;        return Vec3(173/255, 216/255, 230/255)&#xA;&#xA;    # Compute local color&#xA;    P = origin + closest_t * direction  # Compute intersection&#xA;    N = P - closest_object.center  # Compute  normal at intersection&#xA;    N = N / N.mag()&#xA;    local_color = closest_object.color * self.compute_light(P, N)&#xA;&#xA;    # If we hit the recursion limit or the object is not reflective, we're done&#xA;    r = closest_object.reflective&#xA;    if depth &amp;lt;= 0 or r &amp;lt;= 0:&#xA;        return local_color&#xA;&#xA;    # Compute the reflected color&#xA;    R = self.reflect_ray(-1*direction, N)&#xA;    reflected_color = self.trace_ray(P, R, 0.001, math.inf, depth - 1)&#xA;&#xA;    return local_color * (1 - r) + reflected_color * r&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;closest intersection method.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;def closest_intersection(self, O, D, t_min, t_max):&#xA;    closest_t = math.inf&#xA;    closest_object = None&#xA;&#xA;    for object in self.world.objects:&#xA;        t1, t2 = object.intersect_at_point(O, D)&#xA;&#xA;        if (t_min &amp;lt; t1 &amp;lt; t_max) and t1 &amp;lt; closest_t:&#xA;            closest_t = t1&#xA;            closest_object = object&#xA;&#xA;        if (t_min &amp;lt; t2 &amp;lt; t_max) and t2 &amp;lt; closest_t:&#xA;            closest_t = t2&#xA;            closest_object = object&#xA;&#xA;    for plane in self.world.planes:&#xA;        t = plane.intersect_at_point(O,D)&#xA;&#xA;        if t and (t_min &amp;lt; t &amp;lt; t_max) and t &amp;lt; closest_t:&#xA;            closest_t = t&#xA;            closest_object = plane&#xA;&#xA;    return closest_object, closest_t&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Calculate light method.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;def compute_light(self, Point, Normal):&#xA;    i = 0.0&#xA;    P = Point&#xA;    N = Normal&#xA;&#xA;    for light in self.world.lights:&#xA;        if light.type == 'ambient':&#xA;            i += light.intensity&#xA;        else:&#xA;            if light.type == 'point':&#xA;                L = light.position - P&#xA;                t_max = 1&#xA;&#xA;            if light.type == 'directional':&#xA;                L = light.direction&#xA;                t_max = math.inf&#xA;&#xA;            # Shadow check&#xA;            shadow_sphere, shadow_t = self.closest_intersection(P, L, 0.001, t_max)&#xA;            if shadow_sphere != None:&#xA;                continue&#xA;&#xA;            n_dot_l = N.dot(L)&#xA;&#xA;            if n_dot_l &amp;gt; 0:&#xA;                # print(f'light intensity {light.intensity}')&#xA;                i+= light.intensity * n_dot_l / (N.mag() * L.mag())&#xA;&#xA;    return i&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13309" LastEditorUserId="13370" LastEditDate="2020-05-14T22:56:49.530" LastActivityDate="2020-05-14T23:27:49.660" Title="Weird patch on reflective spheres on planes in raytracer" Tags="&lt;raytracing&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9825" PostTypeId="1" CreationDate="2020-05-12T18:12:25.863" Score="1" ViewCount="50" Body="&lt;p&gt;I am wondering this, as e.g. YouTube offers some videos 60fps, but computer may be too slow to play them.&lt;/p&gt;&#xA;" OwnerUserId="13359" LastActivityDate="2020-05-13T14:33:37.837" Title="Is it possible to decode and play e.g. 60fps video as 30fps, if computer is too slow for 60fps?" Tags="&lt;video&gt;&lt;efficiency&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9826" PostTypeId="2" ParentId="9441" CreationDate="2020-05-12T18:57:09.520" Score="1" Body="&lt;p&gt;You could try to play 1080p and 2160p videos, possibly 60fps in YouTube. If you right-click on the playback window and click on &quot;Stats for nerds&quot; you will get more information about used video and audio codecs and dropped frames, which can indicate that your hardware may be too slow. Currently the videos are mostly encoded as VP9 codec, but you can change settings to prefer AV1 codec, at &lt;a href=&quot;https://www.youtube.com/account_playback&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/account_playback&lt;/a&gt;. However please note that not all videos are available as AV1, but you can find some videos at &lt;a href=&quot;https://www.youtube.com/playlist?list=PLyqf6gJt7KuHBmeVzZteZUlNUQAVLwrZS&quot; rel=&quot;nofollow noreferrer&quot;&gt;AV1 Beta Launch Playlist&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="13359" LastActivityDate="2020-05-12T18:57:09.520" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9828" PostTypeId="1" CreationDate="2020-05-04T10:48:47.007" Score="1" ViewCount="34" Body="&lt;p&gt;I am looking for a red and a green hue that are equally discernable against a gray background on any PC monitor, using HTML/CSS-based application. There are many possible solutions to balance these factors, but none of them work well, and I don't know how to best implement it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The gray could be a mid-gray (e.g., &lt;code&gt;#909090&lt;/code&gt;). If, for example, I select a red and green similar in lightness and saturation &lt;code&gt;hsl(h*, 100%, 25.1%)&lt;/code&gt;, red &lt;code&gt;RGB(128,0,0)&lt;/code&gt;(&lt;code&gt;#800000&lt;/code&gt;) and green &lt;code&gt;RGB(0,128,0)&lt;/code&gt;(&lt;code&gt;#008000&lt;/code&gt;), the result is, at least to my eyes, far from equal. Red-on-gray is definitely more discernable than green-on-gray see &lt;a href=&quot;https://i.stack.imgur.com/O9uWn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;image hsl red-on-gray&lt;/a&gt; and &lt;a href=&quot;https://i.stack.imgur.com/EUWEI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;image hsl green-on-gray&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If I follow the CIELCh, wherein saturation can be defined as &lt;code&gt;sat = C*/L*&lt;/code&gt; (&lt;a href=&quot;https://link.springer.com/article/10.1007/s00426-017-0880-8&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wilms &amp;amp; Oberfeld, 2018&lt;/a&gt;), a balanced pair could be this: &lt;strong&gt;red&lt;/strong&gt; CIE-LCh°(ab) (D65/2°) = 34, 100, 57, &lt;code&gt;rgb(164, 14, 0)&lt;/code&gt; (&lt;code&gt;#A40E00&lt;/code&gt;, &lt;code&gt;hsl(5.1, 100%, 32.2%)&lt;/code&gt;) and  &lt;strong&gt;green&lt;/strong&gt; CIE-LCh°(ab) (D65/2°) = 34, 100, 150, &lt;code&gt;rgb(0, 103, 0)&lt;/code&gt; (&lt;code&gt;#006700&lt;/code&gt;, &lt;code&gt;hsl(120, 100%, 20.2%)&lt;/code&gt;). Now, the lightness from the HSL model does not correspond anymore. How can I satisfy all colour models? Admittedly, or maybe I am just going crazy and see what I wanna see, the pictures with the CIELCh saturation balanced version seems a bit more balanced to me, see &lt;a href=&quot;https://i.stack.imgur.com/VeE0k.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;image lch red-on-gray&lt;/a&gt; and &lt;a href=&quot;https://i.stack.imgur.com/j1j8h.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;image lch green-on-gray&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, I don't know how (much) the gray factors in here in the perception of the colours, since they aren't presented against white.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a specific aim in mind: I want to run an online study (using a JS/HTML/CSS application, hence preferably HEX colors). Of course it is not possible to achieve a perfect balance in an online study where we cannot know the properties of the monitors, but the main measure is within-subjects, hence it should not matter much if there are some differences to a certain extent. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;All in all, I just want to make sure that I use the &quot;least worst&quot; solution.&lt;/strong&gt; &lt;/p&gt;&#xA;" OwnerUserId="13385" OwnerDisplayName="Kiki Kawai" LastEditorUserId="13390" LastEditDate="2020-05-17T09:02:14.040" LastActivityDate="2020-05-17T09:02:14.040" Title="How to get &quot;Equal&quot; (saturation, brightness) Red and Green Colours in a Web-based Application?" Tags="&lt;color&gt;&lt;perspective&gt;&lt;color-science&gt;&lt;human-vision&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9829" PostTypeId="1" CreationDate="2020-05-13T12:28:06.827" Score="0" ViewCount="133" Body="&lt;p&gt;I learned in PBRT that to sample direct lighting for a surface a integrator usually calculates the sample as&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;Sample = \frac{L_d(p,\omega_r) f(p,\omega_o,\omega_r)|cos\theta_i|}{p(\omega_r)}&#xA;$$&lt;/span&gt;&#xA;where BRDF &lt;span class=&quot;math-container&quot;&gt;$f(p,\omega_o,\omega_r)$&lt;/span&gt; is the sum of brdf from all the components (for instance microfacet specular &amp;amp; lambertian diffuse), and PDF &lt;span class=&quot;math-container&quot;&gt;$p(\omega_r)$&lt;/span&gt; is the average of all the components. My question is why for &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; we calculate sum while for &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; it's average. I have the intuition that for &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; we should also calculate average.&#xA;In addition, why can we use the distribution of importance sampling to evaluate &lt;span class=&quot;math-container&quot;&gt;$p(\omega_r)$&lt;/span&gt; for the given &lt;span class=&quot;math-container&quot;&gt;$\omega_r$&lt;/span&gt;?&lt;/p&gt;&#xA;" OwnerUserId="13362" LastActivityDate="2021-02-07T17:05:10.467" Title="Calculate BRDF and PDF when doing direct light sampling" Tags="&lt;sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9830" PostTypeId="2" ParentId="9825" CreationDate="2020-05-13T14:33:37.837" Score="1" Body="&lt;p&gt;It is likely somewhat possible, depending on how the video was encoded. The player can easily skip displaying half the frames but that won't gain us much. What needs to happen is to skip decoding some of the frames.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Modern video codecs nearly all use a mix of &lt;a href=&quot;https://en.wikipedia.org/wiki/Video_compression_picture_types&quot; rel=&quot;nofollow noreferrer&quot;&gt;I, P and B frames&lt;/a&gt;. Most are quite flexible in which frame types are used and only specify what a decoder should be able to handle, leaving the encoder free to pick the most appropriate way to encode a video.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Because of this, even if we want to show only half the frames, we may still end up having to decode more than that. It is possible to build a video stream where every other frame can be skipped because it is not referenced by other frames. But I suspect that most encoders will prioritize encoding efficiency over this rigid requirement. So in practice, we will only be able to skip decoding a smaller number of frames, unless the video was specifically encoded to support this scheme.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The other issue is player support. The player would need to recognize that computing power is insufficient and specifically target half the frame rate. In practice, most that I've seen will skip erratically instead. They expect the lack of computing power to be temporary as that is the most common scenario.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The expected fix for a permanent lack of computing power is to use a lower quality video stream. For devices with well known computing power (eg. phones, tablets, etc), this can be handled automatically by not presenting the high quality alternative. I don't know specifically if YouTube's &quot;auto&quot; quality setting handles this the same way it handles insufficient bandwidth but it could certainly be done and would be a much better solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;TL;DR: It's possible but usually not worth doing.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastActivityDate="2020-05-13T14:33:37.837" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9831" PostTypeId="2" ParentId="9829" CreationDate="2020-05-13T15:08:25.190" Score="0" Body="&lt;p&gt;1) When we have multiple BRDFs, adding thier components together can break energy conservation, as I think you suspect. However most renderers will handle this problem when constructing the layered BRDFs. For example you would might weight each layer or use a fresnel term to decide the weight for each layer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the spec for arnolds standard shader:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7lt3o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7lt3o.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://autodesk.github.io/standard-surface/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://autodesk.github.io/standard-surface/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Each layer is multiplied by 1 - previous layer weight, which the artist is setting. This is done inside the fr function, which means that energy conservation is solved here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2) The pdf is an average, I think, if each bxdf has an equal chance of being sampled. You therefore average the pdf even though each layer may contribute different amounts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Note: Becareful which value you use for p(wr), this will be the pdf you used to sample your direction, so either the bxdf pdf or the light pdf. (You still need to calculate both pdfs at some point for MIS though.) &lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-05-13T15:08:25.190" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9832" PostTypeId="1" AcceptedAnswerId="9835" CreationDate="2020-05-13T18:45:55.873" Score="1" ViewCount="74" Body="&lt;p&gt;I'm new to computer graphics programming so I apologize in advance if my question is stupid.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm trying to implement a BVH for my ray tracer and I looked at some lectures explaining BVH. They all mention that a BVH takes in primitives which are then divided until they end up as nodes of the tree, but when I looked at scratch-pixel, they were talking about having the meshes as nodes. I'm a bit confused here because I'm not sure exactly which is the right way of doing it. Should the nodes contain the meshes as a whole or should I just feed the BVH construction algorithm the primitive triangles (ignoring the fact that they are a part of a mesh by just grouping them into a list/array of primitives)?&lt;/p&gt;&#xA;" OwnerUserId="13365" LastActivityDate="2020-05-14T17:06:13.387" Title="Ray Tracing Bounding Volume Hierarchies nodes" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;optimisation&gt;&lt;bounding-volume-hierarchy&gt;&lt;optimization&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9833" PostTypeId="1" CreationDate="2020-05-13T19:08:28.540" Score="0" ViewCount="137" Body="&lt;p&gt;I understand that in OpenGL early depth test can be performed in the rasterizer (before running the fragment shader), but is it the same case for WebGL? If so, how is early depth test enabled in WebGL?&lt;/p&gt;&#xA;" OwnerUserId="13192" LastActivityDate="2020-05-16T20:09:02.207" Title="Early depth test in WebGL" Tags="&lt;webgl&gt;&lt;rasterizer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9834" PostTypeId="1" AcceptedAnswerId="9847" CreationDate="2020-05-13T21:14:21.873" Score="2" ViewCount="302" Body="&lt;p&gt;I'm confused about how to properly convert from sRGB or XYZ color space to ACEScg. Specifically whether I have to account for differences in white point explicitly.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The &lt;a href=&quot;https://github.com/ampas/aces-dev/blob/master/transforms/ctl/README-MATRIX.md&quot; rel=&quot;nofollow noreferrer&quot;&gt;aces github page&lt;/a&gt; gives the following matrix to convert from XYZ to AP1:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 1.6410233797, -0.3248032942, -0.2364246952,&#xA;-0.6636628587,  1.6153315917,  0.0167563477,&#xA; 0.0117218943, -0.0082844420,  0.9883948585&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://terathon.com/blog/rgb-xyz-conversion-matrix-accuracy/&quot; rel=&quot;nofollow noreferrer&quot;&gt;FGED2&lt;/a&gt; gives the following matrix to convert from XYZ to sRGB with white point D65:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 3.240970, -1.537383, -0.498611,&#xA;-0.969244,  1.875968,  0.041555,&#xA; 0.055630, -0.203977,  1.056972 &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And &lt;a href=&quot;https://www.shadertoy.com/view/WltSRB&quot; rel=&quot;nofollow noreferrer&quot;&gt;this shadertoy&lt;/a&gt; gives the following matrix to convert from sRGB to AP1:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;0.613097, 0.339523, 0.047379,&#xA;0.070194, 0.916354, 0.013452,&#xA;0.020616, 0.109570, 0.869815&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So I figured if I combine the XYZ-&gt;sRGB and sRGB-&gt;AP1 matrices it should be the same result as XYZ-&gt;AP1. However there is a small, but noticeable difference:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt; 1.66058,    -0.315295,  -0.24151,&#xA;-0.659926,    1.60839,    0.017298,&#xA; 0.00900358, -0.00356713, 0.913644&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I assume the difference comes from the way the white point is handled? My question is, which is &quot;correct&quot;. I have use cases for both XYZ-&gt;AP1 and sRGB-&gt;AP1, but now I'm irritated that my matrices don't allow me to round-trip.&lt;/p&gt;&#xA;" OwnerUserId="13367" LastEditorUserId="13367" LastEditDate="2020-05-15T08:11:02.640" LastActivityDate="2020-05-15T08:31:06.117" Title="How to convert from XYZ or sRGB to ACEScg/AP1" Tags="&lt;colorspace&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9835" PostTypeId="2" ParentId="9832" CreationDate="2020-05-13T23:51:57.830" Score="1" Body="&lt;h1&gt;Bounding Volumes&lt;/h1&gt;&#xA;&lt;p&gt;A bounding volume is for example an Axis-Aligned Bounding-Box (AABB), a generaal Bounding-Box not aligned with the major axes or a Bounding-Sphere. They differ in&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;how much memory they take (e.g. a sphere takes only 4 floats, AABB 6 floats)&lt;/li&gt;&#xA;&lt;li&gt;how good they enclose the object's geometry&lt;/li&gt;&#xA;&lt;li&gt;how fast are the related computations (mainly intersection tests).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;You will find an extensive overview at &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;h1&gt;Hierarchy of volumes&lt;/h1&gt;&#xA;&lt;p&gt;So in the hierarchy of bounding volumes, instead of whole meshes you will store only their bounding volumes. You choose a single type, e.g. a bounding sphere, and will use it to build the whole BVH. At the bottom level each bounding volume will probably enclose only a single object. You will build the hierarchy up by enclosing pairs or smaller groups of volumes in a larger volume.&lt;/p&gt;&#xA;&lt;p&gt;So using spheres you would enclose each object into a bounding sphere at first. Then at the higher levels of the hierarchy, you would always create a new sphere enclosing a few spheres from the previous level which are close to each other. You proceed until a single root sphere encloses all 3D objects in your scene.&lt;/p&gt;&#xA;&lt;p&gt;There are different &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume_hierarchy&quot; rel=&quot;nofollow noreferrer&quot;&gt;strategies to create BVH&lt;/a&gt;. But all have in common that complex structures like triangle meshes are hierarchically clustered using very simple entities.&lt;/p&gt;&#xA;" OwnerUserId="13370" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-05-14T17:06:13.387" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9840" PostTypeId="1" AcceptedAnswerId="9846" CreationDate="2020-05-14T13:25:04.277" Score="0" ViewCount="47" Body="&lt;p&gt;Couldn't find any resources on this, so I'll ask here.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, I want to create a game model of a mountain peak.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I took lots and lots of drone footage, almost from every side, photography footage, just lots of it. (Realistically viable amounts of footage)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Could I somehow, import, or make a 3D model out of these footages so I could import it into the game.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It should be a 3D model. Thank you.&lt;/p&gt;&#xA;" OwnerUserId="13376" LastActivityDate="2020-05-15T00:34:29.843" Title="Is it viable to create computer graphics via terrain scanning?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9841" PostTypeId="1" CreationDate="2020-05-14T13:26:07.230" Score="1" ViewCount="63" Body="&lt;p&gt;I would like to construct a projection matrix for reverse perspective.&#xA;I'm using OpenGL and tried to modify concepts from &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this excelent tutorial&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I came up with:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{bmatrix}&#xA;2\frac{(near-M)}{right-left} &amp;amp;  0  &amp;amp; \frac{right + left}{right-left} &amp;amp; M\frac{right + left}{right-left}\\&#xA;0  &amp;amp;  2\frac{(near-M)}{top-bottom} &amp;amp; \frac{top + bottom}{top-bottom} &amp;amp; M\frac{top + bottom}{top-bottom}\\&#xA;0 &amp;amp; 0 &amp;amp; \frac{2M-near-far}{far-near} &amp;amp; \frac{2(M-far)*near}{far-near} + M\\&#xA;0 &amp;amp; 0 &amp;amp; -1 &amp;amp; -M&#xA;\end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \text{Variables define viewing frustum. }M \text{ is the tip; point } (0,0,-M) \text{ in eye space.}$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To avoid ambiguity near point &lt;strong&gt;M&lt;/strong&gt; I put far plane closer to the camera. To debug this, I inverted points from NDC [-1,1] cube and they seem to fit the desired frustum. Sadly my models don't render correctly when using this matrix. They don't show up when they clearly are in the viewing frustum. I verify this by rendering the scene from other cameras using regular perspective or orthographic projection.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To clarify, what kind of perspective I'm talking about, here are links:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Reverse_perspective&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Reverse_perspective&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://vimeo.com/12518619&quot; rel=&quot;nofollow noreferrer&quot;&gt;True Reverse Perspective&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Code in c++ using glm:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;template &amp;lt;typename T&amp;gt;&#xA;auto frustum(T left, T right, T bottom, T top, T near, T M, T far) {&#xA;    glm::tmat4x4&amp;lt;T, glm::defaultp&amp;gt; result(0);&#xA;    result[0][0] = (static_cast&amp;lt;T&amp;gt;(2) * (near - M)) / (right - left);&#xA;    result[2][0] = (right + left) / (right - left);&#xA;    result[3][0] = (right + left) / (right - left) * M;&#xA;&#xA;    result[1][1] = (static_cast&amp;lt;T&amp;gt;(2) * (near - M)) / (top - bottom);&#xA;    result[2][1] = (top + bottom) / (top - bottom);&#xA;    result[3][1] = (top + bottom) / (top - bottom) * M;&#xA;&#xA;    result[2][2] = ((static_cast&amp;lt;T&amp;gt;(2) * M) - near - far) / (far - near);&#xA;    result[3][2] = static_cast&amp;lt;T&amp;gt;(2) * (M - far) * near / (far - near) + M;&#xA;&#xA;    result[2][3] = static_cast&amp;lt;T&amp;gt;(-1);&#xA;    result[3][3] = static_cast&amp;lt;T&amp;gt;(-M);&#xA;    return result;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13377" LastActivityDate="2020-05-14T13:26:07.230" Title="What is the projection matrix of reverse (Byzantine) perspective?" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;mathematics&gt;&lt;glm&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9842" PostTypeId="1" CreationDate="2020-05-14T16:04:25.060" Score="0" ViewCount="39" Body="&lt;p&gt;I have just learned about the vector triple product (Lagrange formula) from a math for computer graphics textbook, however the book does not mention any use cases for it beyond the fact that it's a simpler way to say: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;   cross(a,cross(b,c) == b*(dot(a,c))-c*(dot(a,b)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Why is this emphasized? Is it because it's simpler to read?&lt;/p&gt;&#xA;" OwnerUserId="5664" LastActivityDate="2020-05-14T16:04:25.060" Title="What are some uses for the vector triple product in computer graphics?" Tags="&lt;mathematics&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9843" PostTypeId="2" ParentId="9824" CreationDate="2020-05-14T19:34:32.680" Score="0" Body="&lt;p&gt;It looks like the light and colour calculation for the sphere reflection is peaking and may need to be clipped to the range 0-255. &lt;a href=&quot;https://m.youtube.com/watch?v=vE5c2hTRLZM&amp;amp;list=PLHm_I0tE5kKPPWXkTTtOn8fkcwEGZNETh&amp;amp;index=7&quot; rel=&quot;nofollow noreferrer&quot; title=&quot;Raytracer from scratch in C++&quot;&gt;This&lt;/a&gt; video around 1:21:45 mark shows an example of this.&lt;/p&gt;&#xA;" OwnerUserId="10450" LastActivityDate="2020-05-14T19:34:32.680" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9844" PostTypeId="2" ParentId="9824" CreationDate="2020-05-14T22:38:11.737" Score="2" Body="&lt;p&gt;I have to disagree with @jack11111, this is definitely not a clipping issue. I have two possible explanations which you can easily test and verify.&lt;/p&gt;&#xA;&lt;h3&gt;Clipping theory&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;The patch looks pretty constant in color, clipping would be sort of a gradient (modulo 255) of full intensity in at least one channel (R/G/B).&lt;/li&gt;&#xA;&lt;li&gt;There is no direct light source to cause a strong specular highlight. According to the ground shading and the Lambert-shaded green balls a point light source is placed above, little bit in front of the camera. It seems to have normal intensity that should not cause any trouble. In fact I see in your code that you apply only basic Lambert &lt;code&gt;n . l&lt;/code&gt; shading, so no specular highlights possible.&lt;/li&gt;&#xA;&lt;li&gt;There is no indirect source to cause such a peak. The rays reflect to towards ground that is rather dark. The bright spot on the ground is located else where. That is well visible on the red sphere where the error occurs closer than the next green sphere, but the highlight on the ground is even further away.&lt;/li&gt;&#xA;&lt;li&gt;It is a strange coincidence that the secondary color of the patch is exactly the same for both spheres.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h3&gt;Normals theory&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Normals seem to be computed correctly elsewhere, all your shading is consistent with nice gradients.&lt;/li&gt;&#xA;&lt;li&gt;You reflections are also correct elsewhere, that will be on problem.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h1&gt;It's a trap! (almost)&lt;/h1&gt;&#xA;&lt;p&gt;Looking closely at your image I believe I can explain what is happening there. The rays hitting the suspicious regions at the sphere will reflect towards ground in a direction very similar to the ground normal.&lt;/p&gt;&#xA;&lt;p&gt;You ground does not seem to be reflective, but if it were: The rays would reflect back in almost the exact opposite direction hitting back the ball and then heading towards the camera. So they would hit the ball twice which could cause its color to gain dominance. You can test this theory by comparing the rendering results with &lt;code&gt;maxDepth = 1&lt;/code&gt;. If the discontinuity disappears then that is the problem.&lt;/p&gt;&#xA;&lt;h1&gt;Upside down&lt;/h1&gt;&#xA;&lt;p&gt;My second explanation is much more likely to be the case. It is also based on the observation that the rays reflected from the suspicious patches hit the ground in a direction pointing almost exactly down. I noticed a bit strange setup of your plane in your code. It has its normal pointing down!?&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;self.normal = Vec3(0,-1,0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I am not sure how the Lambert shading of the ground works then (should be then all just ambient in fact), but assuming &lt;code&gt;Vec(0,1,0)&lt;/code&gt; is your up then the intersection will in fact yield &lt;code&gt;None&lt;/code&gt;&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;denom = ray.dot(self.normal) #something like 1e-6 in the suspicious area&#xA;if abs(denom) &amp;gt; 0.0001: #evaluates to false&#xA;    #... true branch ignored&#xA;return None #false branch activated, returns no intersection&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Having no intersection means that the hit point is shaded only with a constant color&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;if closest_object == None:&#xA;   return Vec3(173/255, 216/255, 230/255)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So to test this explanation, just change the returned color for this case to black and see if the patch darkens.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;if closest_object == None:&#xA;    return Vec3(0, 0, 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I hope that helps. Please let me know the results.&lt;/p&gt;&#xA;&lt;h1&gt;Update&lt;/h1&gt;&#xA;&lt;p&gt;After the author confirmed my second explanation I found the reason in the code. The source of the problem is in the ray-plane intersection method.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Most important of all the epsilon in the comparison should be omitted, since that is causing the patch to be discontinuous.&lt;/strong&gt; As mentioned earlier, the incoming ray direction is almost &lt;code&gt;Vec3(0,-1,0)&lt;/code&gt;. You have set your plane normal to exactly &lt;code&gt;Vec3(0,-1,0)&lt;/code&gt; so the dot product yields something very close to &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So the quick fix would be:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;denom = ray.dot(self.normal)&#xA;if abs(denom) &amp;gt;= 0: #omit the epsilon&#xA;    #...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Your plane normal is inconsistent with how a normal is usually defined. I believe your plane is not supposed to face down. It would be much better and correct to have the plane normal pointing &lt;strong&gt;up&lt;/strong&gt; and then testing for a &lt;strong&gt;negative&lt;/strong&gt; dot product.&lt;/p&gt;&#xA;&lt;p&gt;A front-face hit occurs when the face normal and the ray are pointing in opposite directions, i.e. their angle &lt;code&gt;θ&lt;/code&gt; is smaller than &lt;code&gt;-π/2&lt;/code&gt; or larger than &lt;code&gt;π/2&lt;/code&gt;, so &lt;code&gt;cos(θ) &amp;lt; 0&lt;/code&gt;. Note that &lt;code&gt;denom&lt;/code&gt; is in fact &lt;code&gt;cos(θ)&lt;/code&gt;. If &lt;code&gt;|θ| &amp;lt; π/2&lt;/code&gt;, i.e. &lt;code&gt;cos(θ) &amp;gt; 0&lt;/code&gt;, then it is a back-face hit. You ignore such hits for now but once you add transparency to your raycaster you will need them as well.&lt;/p&gt;&#xA;&lt;p&gt;The correct way would be:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-py prettyprint-override&quot;&gt;&lt;code&gt;def __init__(self, color, y=0, specular=-1, reflective=0):&#xA;    # ...&#xA;    self.normal = Vec3(0,1,0) #pointing UP&#xA;&#xA;    def intersect_at_point(self, origin, ray):&#xA;        denom = ray.dot(self.normal) # denom == cos(θ)&#xA;&#xA;        if abs(denom) &amp;lt;= 0: #is negative &amp;lt;=&amp;gt; |θ| &amp;gt; π/2; omit the epsilon&#xA;            diff  = self.center - ray&#xA;            t = diff.dot(self.normal) / denom&#xA;&#xA;            if t &amp;gt; 0: #I suggest to omit the epsilon here as well&#xA;                return t&#xA;        return None&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13370" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-05-14T23:27:49.660" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9845" PostTypeId="1" CreationDate="2020-05-14T23:00:58.247" Score="3" ViewCount="113" Body="&lt;p&gt;I am using Simplex Noise to generate a 3D field. The specific implementation is &lt;a href=&quot;https://github.com/jackmott/FastNoise-SIMD&quot; rel=&quot;nofollow noreferrer&quot;&gt;FastNoise-SIMD&lt;/a&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume I want to have a gradient (or derivative) for a sample at Sx, Sy, Sz in that field.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Do I actually need to sample the value of the field at all neighbours of sample S?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If so, that makes it a quite expensive operation, as the 4-octave Simplex Noise function I use is already quite expensive, evaluating them for all neighbours would make it too slow for my purposes.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a way to directly compute the derivative of SimplexNoise that is cheaper than getting the deltas from the neighbours?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Some Perlin noise implementations &lt;a href=&quot;https://www.scratchapixel.com/lessons/procedural-generation-virtual-worlds/perlin-noise-part-2/perlin-noise-computing-derivatives&quot; rel=&quot;nofollow noreferrer&quot;&gt;have an analytical derivative&lt;/a&gt;. But none of the Simplex Noise implementations that I have found support sampling the gradient along with the field value.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Have analytical derivatives been done on Simplex Noise, or is it maybe not possible for Simplex Noise? &lt;/p&gt;&#xA;" OwnerUserId="6562" LastActivityDate="2020-05-14T23:00:58.247" Title="Analytical derivative of a 3D Simplex Noise field" Tags="&lt;sampling&gt;&lt;noise&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9846" PostTypeId="2" ParentId="9840" CreationDate="2020-05-15T00:34:29.843" Score="0" Body="&lt;p&gt;Yes that is possible using &lt;strong&gt;photogrammetry&lt;/strong&gt; like @SimonF mentioned in his comment. There is plenty of commercial and free software. Peter Falkingham has a great &lt;a href=&quot;https://peterfalkingham.com/blog/&quot; rel=&quot;nofollow noreferrer&quot;&gt;blog with many reviews&lt;/a&gt; mainly for the free tools.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is a &lt;a href=&quot;https://www.youtube.com/watch?v=b84MwuupHKg&quot; rel=&quot;nofollow noreferrer&quot;&gt;video of scanning a mountain&lt;/a&gt; using my favourite open-source solution. Specialists do much more &lt;a href=&quot;https://www.youtube.com/watch?v=NuZUSe87miY&quot; rel=&quot;nofollow noreferrer&quot;&gt;extreme scanning&lt;/a&gt; using their tools, the resulting Matterhorn point-cloud dataset is used by some of my research colleagues as well.&lt;/p&gt;&#xA;&#xA;&lt;h1&gt;Requirements&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;To cover a mountain, you will need a lot of photos. Depending on the peak size and required precision you may end up with thousands to hundreds of thousands of photos. To process all of them, it needs a lot of RAM and powerful GPU(s). I did a reconstruction for 10k photos on a &lt;em&gt;Ryzen 2700X&lt;/em&gt; with &lt;em&gt;64 GB Ram&lt;/em&gt; and a &lt;em&gt;1080 Ti&lt;/em&gt; inside... it took 10 days to complete.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There are two critical phases: &lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Alignment to create the sparse point cloud is partly CPU-based and requires a lot of RAM. Once the system starts to swap to the HDD, you've lost.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Patch-match for the dense point cloud heavily uses the GPU and takes most of the reconstruction time.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;h1&gt;Scanning procedure&lt;/h1&gt;&#xA;&#xA;&lt;p&gt;In ideal case all photos would be taken in exact the same moment. When you fly around it takes time and the sun moves. Shadows change. That is often a problem at reconstruction so cloudy days are generally better. Try to get all footage on one day and as fast as possible. The atmospheric conditions may change the next day(s). I hope there is no snow and no water, those are the most difficult to reconstruct due to reflections :)&lt;/p&gt;&#xA;" OwnerUserId="13370" LastActivityDate="2020-05-15T00:34:29.843" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="9847" PostTypeId="2" ParentId="9834" CreationDate="2020-05-15T08:31:06.117" Score="1" Body="&lt;p&gt;The discrepancy comes from chromatic adaptation, which is included in the matrix from shadertoy. If you combine XYZ-&gt;AP1 with D65-&gt;D60 from the aces page you end up with the same matrix that I got by chaining XYZ-&gt;sRGB and sRGB-&gt;AP1 (with chromatic adaptation) together.&lt;/p&gt;&#xA;" OwnerUserId="13367" LastActivityDate="2020-05-15T08:31:06.117" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9848" PostTypeId="2" ParentId="5465" CreationDate="2020-05-15T14:21:53.853" Score="0" Body="&lt;p&gt;Even film/animation speeds are something that 3D content creation teams and studios try to increase.  Of course they don't mind adding minutes per frame if the output is much nicer, whereas games can add so much to graphics processing before FPS rates drop below an acceptable level, which I think coinsides with the point you are making.&lt;/p&gt;&#xA;&lt;p&gt;This difference isn't the reason that film/animation works in quads though.  Quads are easier to work with when creating rounded and organic shapes. In the end though, it is in fact triangulated, at rendertime.  The renderer just creates a new line, per quad, from opposite corners to cut the quad into 2 triangles. This doesn't happen to your model, but do the data streamed to the renderer.  The reason is that if your quad's  4 points are not coplanar, and on a larger percentage of your quads in many models, they won't be, you will have nonmanifold geometry.  The calculation of the area is basically undefined.  If you slice the quad into two tris, that solves the issue as any 3 points are always coplanar.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Response to comments&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;My point was for calculating a flat plane, that is formed by 4 points and linear equations for the sides.  If you move one point off the plane, forming a noncoplanar surface, you now have two planes, not one, and thus the only way to still calculate the original surface is to do it for the 2 triangular planes of the original rectangular plane. Now maybe this is only in Maya, but I think its math and thus universal.  The micropolygons that Renderman creates very well might use a method that can work with noncoplanar surfaces. I don't know that much about Renderman.  I've been told that everything turns into triangles in the end, even if you don't triangulate your meshes, because render engines (some if not all) require coplanar surfaces.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://knowledge.autodesk.com/support/maya-lt/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/MayaLT/files/Polygons-overview-Planar-and-nonplanar-polygons-htm.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://knowledge.autodesk.com/support/maya-lt/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/MayaLT/files/Polygons-overview-Planar-and-nonplanar-polygons-htm.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13387" LastEditorUserId="13095" LastEditDate="2020-09-02T21:23:02.840" LastActivityDate="2020-09-02T21:23:02.840" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9850" PostTypeId="2" ParentId="9833" CreationDate="2020-05-15T20:46:28.547" Score="1" Body="&lt;p&gt;In my answer I relate to WebGL 2 / Opengl ES 3.0. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As far as I know &lt;code&gt;ARB_shader_image_load_store&lt;/code&gt; is not supported. But there is &lt;code&gt;discard&lt;/code&gt; available for fragment shaders in WebGL 2! So what you can do is to&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;make a depth pass with a straight-forward fragment shader and &lt;/li&gt;&#xA;&lt;li&gt;then in a second pass test &lt;code&gt;gl_FragCoord.z&lt;/code&gt; against the value of the depth texture.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;It's up to you, if it's worth the additional texture lookup and rendering the scene twice.&lt;/p&gt;&#xA;" OwnerUserId="13370" LastEditorUserId="13370" LastEditDate="2020-05-16T20:09:02.207" LastActivityDate="2020-05-16T20:09:02.207" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9852" PostTypeId="1" AcceptedAnswerId="9855" CreationDate="2020-05-16T10:50:27.350" Score="2" ViewCount="74" Body="&lt;p&gt;I have different functions for example normalmapping which I use all the time...&#xA;Now I thought about making a small glsl library.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My problem:&#xA;I don't want to have all functions within the same &quot;namespace&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I would like to have it like:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec4 lighting::Phong(vec3 normal, vec3 color, vec3 lightPositionRelative)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The thing is, that I have tons of functions and sometimes multiple functions are related to the same thing, for example: A HashTable, AddKey, GetKey, HasKey...&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So some kind of namespace or even better a class like structure.&#xA;What are the options I have?&#xA;How are you guys handle this?&lt;/p&gt;&#xA;" OwnerUserId="13273" LastEditorUserId="13273" LastEditDate="2020-05-16T13:30:27.890" LastActivityDate="2020-05-16T20:58:18.597" Title="Creating glsl library" Tags="&lt;glsl&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9853" PostTypeId="1" CreationDate="2020-05-16T15:10:20.930" Score="1" ViewCount="123" Body="&lt;p&gt;Looking around here on various sources (including related questions on this site), if my understanding is correct, when implementing a path tracer with a material which has both a diffuse term and a specular term, we can randomly choose whether to evaluate the diffuse or the specular ray then divide the result by the probability of choosing diffuse or specular.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example if we have a material 50% specular, we would have:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If diffuse ray was chosen:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{DiffuseBRDF*incomingLight}{0.5}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If specular ray was chosen:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{SpecularBRDF*incomingLight}{0.5}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Once diffuse/specular is chosen, we have to find which ray exactly we want to use for &lt;span class=&quot;math-container&quot;&gt;$incomingLight$&lt;/span&gt;. In my case I have a rough dieletric surface (not a perfect mirror) and I would like to use importance sampling and use for example a cosine weighted pdf for diffuse and a NDF weighted pdf for the specular term. I couldn't find a source for this particular case, but If my understanding is correct, I would end up with either:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{DiffuseBRDF*incomingLight}{0.5*DiffusePdf}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;if diffuse was chosen, or:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{SpecularBRDF*incomingLight}{0.5*SpecularPdf}$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;if specular was chosen. Is this result correct?&lt;/p&gt;&#xA;" OwnerUserId="11521" LastActivityDate="2020-05-16T15:10:20.930" Title="How to properly combine diffuse and rough specular BRDFs in a path tracer" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;importance-sampling&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9854" PostTypeId="1" CreationDate="2020-05-16T16:05:06.210" Score="0" ViewCount="18" Body="&lt;p&gt;I am trying to create some procedurally created terrains for which i need to create noise maps. How do I create a texture of noise map in OpenGL and then pass that in my vertex shader as a heightMap? &#xA;I know the algorithms to create noises, like Perlin or Simplex, but no idea how to put this data into a texture.&lt;/p&gt;&#xA;" OwnerUserId="13393" LastActivityDate="2020-05-16T16:05:06.210" Title="Custom Create Maps in OpenGL" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;procedural-generation&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9855" PostTypeId="2" ParentId="9852" CreationDate="2020-05-16T20:58:18.597" Score="3" Body="&lt;p&gt;GLSL does not support C++ style namespaces. You might want to do some regex magic before parsing the shader, replacing '::' with '_' or something. You might want to have a preprocessor of sorts - or just forget about it entirely. &lt;/p&gt;&#xA;" OwnerUserId="13394" LastActivityDate="2020-05-16T20:58:18.597" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9858" PostTypeId="1" AcceptedAnswerId="9860" CreationDate="2020-05-17T12:02:01.253" Score="1" ViewCount="84" Body="&lt;p&gt;I am trying to understand the voronoi shader implemented in the Book of Shaders in the Tiling and iteration section: &lt;a href=&quot;https://thebookofshaders.com/12/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://thebookofshaders.com/12/&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Specifically how do these lines calculate the distance from a point to its neighboring tile's point:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Random position from current + neighbor place in the grid&#xA;vec2 point = random2(i_st + neighbor);&#xA;vec2 diff = neighbor + point - f_st;&#xA;&#xA;// Distance to the point&#xA;float dist = length(diff);&#xA;&#xA;// Keep the closer distance&#xA;m_dist = min(m_dist, dist);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Specifically how is the &lt;code&gt;diff&lt;/code&gt; calculation working? I would have expected &lt;code&gt;i_st&lt;/code&gt; to reappear there.&lt;/p&gt;&#xA;" OwnerUserId="13396" LastActivityDate="2020-05-17T23:03:45.310" Title="Help me understand the voronoi shader" Tags="&lt;shader&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9860" PostTypeId="2" ParentId="9858" CreationDate="2020-05-17T23:03:45.310" Score="4" Body="&lt;p&gt;&lt;strong&gt;1)&lt;/strong&gt; Scale the texture coordinates from [0,1]x[0,1] -&gt; [0,3]x[0,3]. It works with higher integer scales as well. This creates an imaginary 3x3 tiles grid.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;st *= 3.;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;2)&lt;/strong&gt; Split the upscaled texture coordinates into the integer part and its float reminder.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;vec2 i_st = floor(st); //the tile coords of the fragment - an integer pair {0,1,2}x{0,1,2}&#xA;vec2 f_st = fract(st); //fragment coords within the tile - a float vec2 [0,1]x[0,1]&#xA;&#xA;//e.g. let's take&#xA;//  st == vec2(1.1,1.7)&#xA;//  i_st == vec2(1.,1.)&#xA;//  f_st == vec2(.1,.7)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now &lt;code&gt;st == i_st + f_st&lt;/code&gt; holds.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;3)&lt;/strong&gt; In order to avoid terms confusion I will call the points that build the Voronoi cells &lt;em&gt;Voronoi points&lt;/em&gt;. Each of the 9 tiles has one &lt;em&gt;Voronoi point&lt;/em&gt; inside to produce a Voronoi cell. So there will be 9 Voronoi cells visible in the resulting texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main hack here is to have this regular 3x3 tiles grid with the same amount of &lt;em&gt;Voronoi points&lt;/em&gt; and randomize their positions only within the respective tile. So the distribution will be pseudo-even. You give up irregular distributions by this assumption, e.g. all points grouped in the upper-left corner, but such arrangements are highly unlikely to result from biologic processes that the cellular noise tries to mimic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since &lt;code&gt;random2&lt;/code&gt; is deterministic, it will return the same &lt;code&gt;vec2&lt;/code&gt; each time you enter the same &lt;code&gt;i_st&lt;/code&gt;, so for a fixed &lt;code&gt;i_st&lt;/code&gt; it will stay constant across all fragments.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;vec2 point = random2(i_st); //pick the Voronoi point, e.g. vec2(.6,.4)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The global position of the picked &lt;em&gt;Voronoi point&lt;/em&gt; is in fact &lt;code&gt;i_st + point&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;4)&lt;/strong&gt; Take the distance to the &lt;em&gt;Voronoi point&lt;/em&gt; inside of the current tile as the initial minimum distance.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;vec2 diff = point - f_st //e.g. vec2(.6,.4) - vec2(.1,.7) == vec2(.5,-.3)&#xA;float dist = length(diff); //e.g.0.583 &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;5)&lt;/strong&gt; So you know that there is exactly one &lt;em&gt;Voronoi point&lt;/em&gt; in each cell, thus by simple geometric means you can prove that you need to check only the direct neighbors. You need to test if any of the neighboring tiles has a &lt;em&gt;Voronoi point&lt;/em&gt; closer to the current fragment than the &lt;em&gt;Voronoi point&lt;/em&gt; from &lt;em&gt;4)&lt;/em&gt;. Two loops iterate over all 3x3 neighborhood of the current tile. It is much easier to do that relatively &lt;code&gt;{-1, 0, 1}x{-1, 0, 1}&lt;/code&gt; instead of using absolute numbers {&lt;code&gt;i_st.x&lt;/code&gt;-1, &lt;code&gt;i_st.x&lt;/code&gt;, &lt;code&gt;i_st.x&lt;/code&gt;+1}x{&lt;code&gt;i_st.y&lt;/code&gt;-1, &lt;code&gt;i_st.y&lt;/code&gt;, &lt;code&gt;i_st.y&lt;/code&gt;+1}. Moreover, we know that each tile is 1x1 in size.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;for (int y= -1; y &amp;lt;= 1; y++) {&#xA;    for (int x= -1; x &amp;lt;= 1; x++) {&#xA;        // relative neighbor coordinates will be sufficient&#xA;        // this is the integer part indicating the neighboring tile coordinates&#xA;        vec2 neighbor = vec2(float(x),float(y)); //e.g. vec2(-1., 1)&#xA;&#xA;        //to be continued&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;6)&lt;/strong&gt; Now you will need to compute the absolute coordinates of neighboring tile to obtain its &lt;em&gt;Voronoi point&lt;/em&gt; consistently across all fragments.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;        //the global neighbor tile coordinates are neighbor + i_st &#xA;        vec2 point = random2(i_st + neighbor); //note that this is a local scope variable&#xA;&#xA;        //to be continued&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;7)&lt;/strong&gt; And now the most interesting step for you, computing the distance to the neighboring &lt;em&gt;Voronoi point&lt;/em&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;        //neighbor: relative tile coords, e.g. vec2(-1., 1.)&#xA;        //point:    Voronoi point inside of the neighboring tile e.g. vec2(0.9, 0.2)&#xA;        //f_st:     current fragment position within its home tile,&#xA;        //          e.g. when st == vec2(1.1, 1.7) then f_st == vec2(.1,.7)&#xA;&#xA;        vec2 diff = neighbor + point - f_st;&#xA;&#xA;        //to be continued&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The example values yield:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;neighbor + point&lt;/code&gt;: &lt;code&gt;vec2(-1.,1.) + vec2(0.9, 0.2) == vec2(-0.1, 1.2)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That is the relative position of the neighboring tile Voronoi point. &lt;strong&gt;Relative means **with respect to the lower-left corner of the current fragment's tile&lt;/strong&gt;.&#xA;The same &lt;em&gt;relative&lt;/em&gt; coordinates apply to &lt;code&gt;f_st&lt;/code&gt; and also to &lt;code&gt;point&lt;/code&gt; from 3).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;code&gt;(neighbor + point) - f_st&lt;/code&gt;: &lt;code&gt;vec2(-0.1, 1.2) - vec2(.1,.7) == vec2(-.2,.5)&lt;/code&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is shorter distance (&lt;code&gt;0.538&lt;/code&gt; vs. previous &lt;code&gt;0.583&lt;/code&gt;) so for the example positions the &lt;em&gt;Voronoi point&lt;/em&gt; from the upper left cell is closer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;8)&lt;/strong&gt; The rest is pretty straight forward. Compute the magnitude of the &lt;code&gt;diff&lt;/code&gt; vector and keep the minimum.&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;        float dist = length(diff); //distance to the neighboring Voronoi point&#xA;&#xA;        m_dist = min(m_dist, dist); //remember the minimum of distances&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I hope this will help you to understand that. The main simplification is the switch to &lt;em&gt;relative&lt;/em&gt; coordinates as described in 7). &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Looking at the code I see that the middle tile (current fragment tile) will be evaluated twice. This can be reduced by omiting step 4) initializing &lt;code&gt;dist&lt;/code&gt; to &lt;code&gt;2*sqrt(2)&lt;/code&gt; which is very roughly &lt;code&gt;3&lt;/code&gt;. That is the length of the diagonal of two cells - the farthest distance the current fragment st could be from one of the neighboring &lt;em&gt;Voronoi points&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Border tiles are handled in an elegant implicit way. &lt;code&gt;random2&lt;/code&gt; generates a &lt;em&gt;Voronoi point&lt;/em&gt; for them as well and involves it in the minimal distance computation. So You will see 9 complete and possibly up to 16 more incomplete Voronoi cells.&lt;/p&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Hope that helps, feel free to ask any further details.&lt;/p&gt;&#xA;" OwnerUserId="13370" LastActivityDate="2020-05-17T23:03:45.310" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9862" PostTypeId="1" AcceptedAnswerId="9866" CreationDate="2020-05-18T06:42:31.997" Score="3" ViewCount="256" Body="&lt;p&gt;I am new in the OpenGL - GLSL and trying to make a shader that taking a &lt;a href=&quot;https://en.wikipedia.org/wiki/Mercator_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;mercator projection&lt;/a&gt; texture as a source and converting it to an &lt;a href=&quot;https://en.wikipedia.org/wiki/Equirectangular_projection&quot; rel=&quot;nofollow noreferrer&quot;&gt;equirectangular projection&lt;/a&gt; texture.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Sample input: (1024x1024)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1h4vk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1h4vk.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Desired output (1024x512)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qLQlo.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qLQlo.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I found &lt;a href=&quot;https://stackoverflow.com/questions/59907996/shader-that-transforms-a-mercator-projection-to-equirectangular&quot;&gt;this question&lt;/a&gt;, that have a similar problem in unity3d. But i stuck to understand it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a C# code that do this task, using &lt;code&gt;WindowsForms&lt;/code&gt;, but it's not efficient.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static class Program&#xA;{&#xA;    const double TWO_PI = Math.PI * 2;&#xA;    const double PI180 = Math.PI / 180;&#xA;&#xA;    private static double Clip(double value, double min, double max)&#xA;    {&#xA;         return Math.Min(Math.Max(value, min), max);&#xA;    }&#xA;&#xA;    public static PointF PixelXYToLatLong(int X, int Y, int mapSize)&#xA;    {&#xA;         PointF coordinate = new PointF();&#xA;         double x = (Clip(X, 0, mapSize - 1) / mapSize) - 0.5;&#xA;         double y = 0.5 - (Clip(Y, 0, mapSize - 1) / mapSize);&#xA;         coordinate.X = (float)(360 * x);&#xA;         coordinate.Y = (float)(90 - 360 * Math.Atan(Math.Exp(0 - y * 2 * Math.PI)) / Math.PI);&#xA;         return coordinate;&#xA;    }&#xA;&#xA;    static void Main()&#xA;    {&#xA;        Bitmap source = new Bitmap(&quot;INPUT_PATH&quot;);&#xA;        int w = source.Width;&#xA;        int h = source.Height;&#xA;        int dh = h &amp;gt;&amp;gt; 1;&#xA;        Bitmap des = new Bitmap(w, dh);&#xA;        dh = dh &amp;gt;&amp;gt; 1;&#xA;        int dw = w &amp;gt;&amp;gt; 1;&#xA;        double r = w / TWO_PI;&#xA;        for (int i = 0; i &amp;lt; w; i++)&#xA;        {&#xA;            for (int j = 0; j &amp;lt; h; j++)&#xA;            {&#xA;                Color color = source.GetPixel(i, j);&#xA;                PointF point = PixelXYToLatLong(i, j, w);&#xA;                double x = point.X * PI180;&#xA;                double y = point.Y * PI180;&#xA;                x = r * x;&#xA;                y = r * y;&#xA;                x = Math.Round(dw + x);&#xA;                y = Math.Round(dh - y);&#xA;                des.SetPixel((int)x, (int)y, color);&#xA;            }&#xA;        }&#xA;        des.Save(&quot;OUTPUT_PATH&quot;);&#xA;        source.Dispose();&#xA;        des.Dispose();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;So i try to implement it in c++ and OpenGL. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;My vertex and fragment shaders&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const GLchar* vertexSource = R&quot;glsl(&#xA;    #version 330 core&#xA;&#xA;    layout (location = 0) in vec3 texPos;&#xA;    layout (location = 1) in vec2 texCoord;&#xA;&#xA;    out vec2 TexCoord;&#xA;&#xA;    void main()&#xA;    {&#xA;        gl_Position.xyz = texPos.xyz;&#xA;        gl_Position.w = 1.0;&#xA;&#xA;        TexCoord = texCoord;&#xA;    }&#xA;)glsl&quot;;&#xA;&#xA;const GLchar* fragmentSource = R&quot;glsl(&#xA;    #version 330 core&#xA;&#xA;    in vec2 TexCoord;&#xA;&#xA;    uniform sampler2D ourTexture;&#xA;&#xA;    void main(){&#xA;        float pi180 = 3.14159265 / 180;&#xA;        float r = 1 / (2 * 3.14159265);&#xA;        float x = min(max(TexCoord.x, 0), 1) - 0.5;&#xA;        float y = 0.5 - min(max(TexCoord.y, 0), 1);&#xA;        x = 360 * x;&#xA;        y = 90 - (360 * atan(exp(0 - y * 2 * 3.14159265)) / 3.14159265);&#xA;        x = x * pi180;&#xA;        y = y * pi180;&#xA;        x = 0.5 + (r * x);&#xA;        y = 0.5 - (r * y);&#xA;&#xA;        gl_FragColor = texture(ourTexture, vec2(x,y));&#xA;    }&#xA;)glsl&quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And my vertex buffer:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;static const GLfloat g_vertex_buffer_data[] = {&#xA;   1.0f,  1.0f, 0.0f, 1.0f, 0.0f,&#xA;   1.0f, -1.0f, 0.0f, 1.0f, 1.0f,&#xA;  -1.0f, -1.0f, 0.0f, 0.0f, 1.0f,&#xA;   1.0f,  1.0f, 0.0f, 1.0f, 0.0f,&#xA;  -1.0f,  1.0f, 0.0f, 0.0f, 0.0f,&#xA;  -1.0f, -1.0f, 0.0f, 0.0f, 1.0f&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/JjzrH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/JjzrH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see there are a lot of problems.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also i try to change texture wrapping to &lt;code&gt;GL_REPEAT&lt;/code&gt;, &lt;code&gt;GL_MIRRORED_REPEAT&lt;/code&gt;, &lt;code&gt;GL_CLAMP_TO_EDGE&lt;/code&gt; and &lt;code&gt;GL_CLAMP_TO_BORDER&lt;/code&gt;, as below:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And &lt;code&gt;glViewport(0, 0, 512, 256)&lt;/code&gt; but without any success.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So where I'm wrong?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Sorry for the long question, Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="13398" LastEditorUserId="13398" LastEditDate="2020-05-19T00:45:56.043" LastActivityDate="2020-05-19T09:40:15.693" Title="Shader that transforms a mercator projection to equirectangular?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9863" PostTypeId="1" AcceptedAnswerId="9864" CreationDate="2020-05-18T20:34:45.340" Score="1" ViewCount="82" Body="&lt;p&gt;I'm going through and optimizing some of my glsl code for a project, and have come across a scenario several times that I am not sure how best to optimize.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In summary - Is it faster to sample a texture once with &lt;code&gt;.rgba&lt;/code&gt; vs 4 times with simply &lt;code&gt;.r&lt;/code&gt; at the end?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's what I have now:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat4 getLightProjectionMatrix(int lightIndex){&#xA;    mat4 m;&#xA;&#xA;    m[0][0] = texelFetch( projMatricies , ivec2( 0 , lightIndex ) , 0 ).r;&#xA;    m[0][1] = texelFetch( projMatricies , ivec2( 1 , lightIndex ) , 0 ).r;&#xA;    m[0][2] = texelFetch( projMatricies , ivec2( 2 , lightIndex ) , 0 ).r;&#xA;    m[0][3] = texelFetch( projMatricies , ivec2( 3 , lightIndex ) , 0 ).r;&#xA;&#xA;    m[1][0] = texelFetch( projMatricies , ivec2( 4 , lightIndex ) , 0 ).r;&#xA;    m[1][1] = texelFetch( projMatricies , ivec2( 5 , lightIndex ) , 0 ).r;&#xA;    m[1][2] = texelFetch( projMatricies , ivec2( 6 , lightIndex ) , 0 ).r;&#xA;    m[1][3] = texelFetch( projMatricies , ivec2( 7 , lightIndex ) , 0 ).r;&#xA;&#xA;    m[2][0] = texelFetch( projMatricies , ivec2( 8 , lightIndex ) , 0 ).r;&#xA;    m[2][1] = texelFetch( projMatricies , ivec2( 9 , lightIndex ) , 0 ).r;&#xA;    m[2][2] = texelFetch( projMatricies , ivec2( 10 , lightIndex ) , 0 ).r;&#xA;    m[2][3] = texelFetch( projMatricies , ivec2( 11 , lightIndex ) , 0 ).r;&#xA;&#xA;    m[3][0] = texelFetch( projMatricies , ivec2( 12 , lightIndex ) , 0 ).r;&#xA;    m[3][1] = texelFetch( projMatricies , ivec2( 13 , lightIndex ) , 0 ).r;&#xA;    m[3][2] = texelFetch( projMatricies , ivec2( 14 , lightIndex ) , 0 ).r;&#xA;    m[3][3] = texelFetch( projMatricies , ivec2( 15 , lightIndex ) , 0 ).r;&#xA;&#xA;    return m;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Here's what I'm considering doing:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;mat4 getLightProjectionMatrix(int lightIndex){&#xA;    mat4 m;&#xA;&#xA;    vec4 A = texelFetch( projMatricies , ivec2( 0 , lightIndex ) , 0 ).rgba;&#xA;    m[0][0] = A[0];&#xA;    m[0][1] = A[1];&#xA;    m[0][2] = A[2];&#xA;    m[0][3] = A[3];&#xA;&#xA;    vec4 B = texelFetch( projMatricies , ivec2( 0 , lightIndex ) , 0 ).rgba;&#xA;    m[1][0] = B[0];&#xA;    m[1][1] = B[1];&#xA;    m[1][2] = B[2];&#xA;    m[1][3] = B[3];&#xA;&#xA;    vec4 C = texelFetch( projMatricies , ivec2( 0 , lightIndex ) , 0 ).rgba;&#xA;    m[2][0] = C[0];&#xA;    m[2][1] = C[1];&#xA;    m[2][2] = C[2];&#xA;    m[2][3] = C[3];&#xA;&#xA;    vec4 D = texelFetch( projMatricies , ivec2( 0 , lightIndex ) , 0 ).rgba;&#xA;    m[3][0] = D[0];&#xA;    m[3][1] = D[1];&#xA;    m[3][2] = D[2];&#xA;    m[3][3] = D[3];&#xA;&#xA;    return m;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Does the compiler know how to optimize both of these into the same thing in the end? or would it be more efficient to pack more data into a texture fetch no matter what?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="13404" LastActivityDate="2020-05-18T22:12:54.257" Title="What's more optimal - sampling one channel at a time or all channels at once?" Tags="&lt;shader&gt;&lt;texture&gt;&lt;glsl&gt;&lt;sampling&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9864" PostTypeId="2" ParentId="9863" CreationDate="2020-05-18T20:59:05.390" Score="3" Body="&lt;p&gt;It should be significantly faster to sample one RGBA value from one location in a texture than four R values from different locations in the texture.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2020-05-18T20:59:05.390" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9865" PostTypeId="2" ParentId="9863" CreationDate="2020-05-18T22:12:54.257" Score="3" Body="&lt;p&gt;I fully agree with all other replies and comments that &lt;code&gt;rgba&lt;/code&gt; is definitely faster as it reduces the number of fetches from 16 to 4. You can even omit the per-element assignment:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;//I also fixed the typo in Matric[i]es&#xA;m[0] = texelFetch( projMatrices , ivec2( 0 , lightIndex ) , 0 );&#xA;m[1] = texelFetch( projMatrices , ivec2( 1 , lightIndex ) , 0 );&#xA;m[2] = texelFetch( projMatrices , ivec2( 2 , lightIndex ) , 0 );&#xA;m[3] = texelFetch( projMatrices , ivec2( 3 , lightIndex ) , 0 );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13370" LastActivityDate="2020-05-18T22:12:54.257" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9866" PostTypeId="2" ParentId="9862" CreationDate="2020-05-19T09:30:03.427" Score="3" Body="&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/59907996/shader-that-transforms-a-mercator-projection-to-equirectangular&quot;&gt;This question&lt;/a&gt; and its answer, actually answer my question. I had to read its answer carefully and find my mistake.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now my fragment shader look like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const GLchar* fragmentSource = R&quot;glsl(&#xA;    #version 330 core&#xA;&#xA;    in vec2 TexCoord;&#xA;&#xA;    uniform sampler2D ourTexture;&#xA;&#xA;    #define PI       3.141592653589793238462f&#xA;    #define TWO_PI   6.283185307179586476924f&#xA;    #define PI4      0.7853981633974483096155f&#xA;&#xA;    void main(){&#xA;        float lat = (TexCoord.y - 0.5f) * PI;&#xA;        if(lat &amp;gt;= -1.48442222974871 &amp;amp;&amp;amp; lat &amp;lt;= 1.48442222974871){&#xA;            float y = log(tan(PI4 + (lat / 2.0)));&#xA;            y = (y + PI) / TWO_PI;&#xA;            gl_FragColor = texture(ourTexture, vec2(TexCoord.x, y));&#xA;            return;&#xA;        }&#xA;        gl_FragColor = vec4(1, 1, 1, 0);&#xA;    }&#xA;)glsl&quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And it's works perfectly.&lt;/p&gt;&#xA;" OwnerUserId="13398" LastEditorUserId="13398" LastEditDate="2020-05-19T09:40:15.693" LastActivityDate="2020-05-19T09:40:15.693" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9867" PostTypeId="1" CreationDate="2020-05-20T17:16:31.950" Score="0" ViewCount="64" Body="&lt;p&gt;If the iPhone had LiDAR sensors, it would be possible to generate a 3D point cloud that you could theoretically use to furnish a 3D AR reconstruction of your surroundings. E.g. you could create an AR video chat whereby you see a &quot;hologram&quot; projection of the person you are speaking within your 3D environment. &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;However, given that LiDAR has yet to be released on iPhone, do you know of an alternative transformation algorithm that may be employed on a single video stream for consistent video depth estimation? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I came across &lt;a href=&quot;https://roxanneluo.github.io/Consistent-Video-Depth-Estimation/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this SIGGRAPH 2020 video depth estimation project&lt;/a&gt; which seems to do this pretty reliably. I think this question ultimately falls with the class of SLAM problems. The SIGGRAPH paper seems to be very promising, but ideally, this would be done in realtime (or with a small time lag), which doesn't seem plausible; this is a &lt;a href=&quot;https://www.youtube.com/watch?v=5Tia2oblJAg&amp;amp;fbclid=IwAR3xaG82vvatIeTQ9wVn0O-R_sbZoqN_e6qGwmUdgHleNPsY5ZGyHOkuBzk&quot; rel=&quot;nofollow noreferrer&quot;&gt;demo video&lt;/a&gt; in case you're curious.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Alternatively, I thought it might be possible using two cameras simultaneously, e.g. the wide and normal, to correct for the camera FOV and optic distortion in each and then use the 3D stereoscopic transform in OpenCV knowing the optical properties of the setup (distance between the cameras, focal length, etc.) to generate a 3D image of the scene with almost as much precision as LiDAR. This &lt;a href=&quot;https://becominghuman.ai/stereo-3d-reconstruction-with-opencv-using-an-iphone-camera-part-i-c013907d1ab5&quot; rel=&quot;nofollow noreferrer&quot;&gt;Medium article&lt;/a&gt; on Stereo 3D reconstruction seems to suggest that such a configuration is possible, although I suppose the small baseline distance between the cameras relative to the object might affect the outcome. I think &lt;a href=&quot;https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture/capturing_photos_with_depth&quot; rel=&quot;nofollow noreferrer&quot;&gt;depth map&lt;/a&gt; in Apple's AVFoundation is certainly an alternative; however, the TrueDepth camera system was only introduced with the iPhoneX.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance! I would appreciate it if this could be demonstrated by example :) I cross-posted &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/9867/can-you-use-opencv-stereo-3d-reconstruction-with-iphone-cameras-to-approximate-l&quot;&gt;this question&lt;/a&gt; on the Computer Graphics exchange.&lt;/p&gt;&#xA;" OwnerUserId="13410" LastEditorUserId="13410" LastEditDate="2020-06-05T02:13:24.940" LastActivityDate="2020-06-05T02:13:24.940" Title="Consistent Video Depth Estimation from Monocular Lens to approximate LiDAR?" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;geometry&gt;&lt;projections&gt;&lt;stereo-rendering&gt;" AnswerCount="0" CommentCount="5" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9869" PostTypeId="1" AcceptedAnswerId="9873" CreationDate="2020-05-21T17:50:27.423" Score="2" ViewCount="106" Body="&lt;p&gt;When having vsync enabled I'm imagining that OpenGL has an explicit wait function to try and keep the frame rate constant. If so where is this function implemented exactly? After running some tests &lt;code&gt;glClear()&lt;/code&gt; function seems to take almost 16 ms with minimal OpenGL script on my machine. When removing this function, the wait seems to happen where the first (?) &lt;code&gt;glDrawArrays()&lt;/code&gt; or &lt;code&gt;glDrawElements()&lt;/code&gt; function is implemented. If none of these functions are implemented then on my machine the wait happens during &lt;code&gt;glxSwapBuffers()&lt;/code&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm hoping to get some better understanding behind his, partly to know when to best poll the input events. Previously I polled at the start of the main loop and then rendered the scene. But since there's a wait during &lt;code&gt;glClear()&lt;/code&gt; function, I'm experiencing a bit of an input delay. So maybe it would make more sense to poll in-between clearing the buffers and rendering the scene?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-05-21T18:31:47.603" LastActivityDate="2020-05-21T22:32:44.020" Title="With vsync enabled where does the wait happen in OpenGL?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9870" PostTypeId="1" AcceptedAnswerId="9874" CreationDate="2020-05-21T17:56:19.090" Score="1" ViewCount="167" Body="&lt;p&gt;I am struggling understanding gamma encoding/decoding.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the colors I see and the values I get from a color picker application(like MS Paint) are already in sRGB space(correct?). &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Assume the color picker gives color C1=(186,70,2). If I create an image programmatically with all pixels in color C1 and Do Not apply gamma encoding C1^(1/gamma), and save it as ppm file, I see exactly same color C1 on opening the file on a viewer.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But this is not the case in my experiment. I save values of color C1 into the file and see color C1. And this is what I don't understand: if the display raise the input color C1 by gamma why do I still see C1 on the screen? Should I not expect to get C1^gamma?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;UPDATE:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Basically here is the ppm file with all pixel RGB values (128,128,128). &#xA;No gamma-encoding has been applied. That is simply writing linear values of 128.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;P3&#xA;400 400&#xA;255&#xA;128 128 128&#xA;128 128 128&#xA;128 128 128&#xA;128 128 128&#xA;128 128 128&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;According to Wikipedia &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_correction#Methods_to_perform_display_gamma_correction_in_computing&quot; rel=&quot;nofollow noreferrer&quot;&gt;Gamma correction&lt;/a&gt; page:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;&lt;em&gt;For example, when using 24-bit RGB color (8 bits per channel), writing&lt;/em&gt;&#xA;  &lt;em&gt;a value of 128 (rounded midpoint of the 0–255 byte range) in video&lt;/em&gt;&#xA;  &lt;em&gt;memory it outputs the proportional ≈ 0.5 voltage to the display, which&lt;/em&gt;&#xA;  &lt;em&gt;it is shown darker due to the monitor behavior.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Wikipedia clearly says write a value 128 and you will see a darker than you expect. Those values in my ppm file are not gamma-encoded and so I expect seeing &#xA;a darker color(0.5^gamma) on the screen. Yet this is not the case and if you open this file on a viewer you will see pixels with brightness half as white.&#xA;That is what I don't get.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Update 2&lt;/em&gt; (After Nathan good answer..)&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So with input of 186 the screen outputs 50% of white intensity? &#xA;And the eye perceives it as 50% as bright as white? is this right?&#xA;But if the screen output is 50% in intensity, and eye has its own curve(roughly power of 1/gamma) then the screen output of 50% should be &lt;em&gt;seen&lt;/em&gt; brighter? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another question I have is that, &#xA;So is it the programmer responsibility to write gamma-corrected values into the file or the whatever API we use to save image file formats does it internally?&#xA;For example i use .Net Bitmap class. Do I need to save bitmap with gamma-encoded values or Bitmap.Save method does it?&#xA;I ask this since according Wikipedia, and you mentioned this too, almost all image formats are encoded&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;binary data in still image files (such as JPEG) are explicitly&#xA;  encoded (that is, they carry gamma-encoded values, not linear&#xA;  intensities)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2020-05-23T11:56:52.743" LastActivityDate="2020-05-23T18:55:00.840" Title="Problem on understanding gamma correction" Tags="&lt;gamma&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9871" PostTypeId="1" CreationDate="2020-05-21T19:08:01.730" Score="3" ViewCount="167" Body="&lt;p&gt;I'm implementing a volume raymarcher and the unlit basic version seems to be working fine. This article helped a ton grokking the view-to-volume-space transform: &lt;a href=&quot;http://www.lebarba.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.lebarba.com&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, it quickly gets ugly when reducing the ray step count to something that's feasible for doing a lighting nested loop.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;exaggerated sampling artifacts, 32 steps:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/chLYK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/chLYK.jpg&quot; alt=&quot;steppy ray cube&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Ryan Brucks has some nice write up &lt;a href=&quot;https://shaderbits.com/blog/creating-volumetric-ray-marcher&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; where he describes some workarounds. I'm specifically trying to understand the &lt;strong&gt;plane alignment&lt;/strong&gt; technique:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LWGJv.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LWGJv.jpg&quot; alt=&quot;Ryan Brucks plane alignment&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;his relevant shader snippet: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;//bring vectors into local space to support object transforms&#xA;float3 localcampos = mul(float4( ResolvedView.WorldCameraOrigin,1.00000000), (Primitive.WorldToLocal)).xyz;&#xA;float3 localcamvec = -normalize( mul(Parameters.CameraVector, Primitive.WorldToLocal) );&#xA;&#xA;//make camera position 0-1&#xA;localcampos = (localcampos / (Primitive.LocalObjectBoundsMax.x * 2)) + 0.5;&#xA;&#xA;float3 invraydir = 1 / localcamvec;&#xA;&#xA;float3 firstintersections = (0 - localcampos) * invraydir;&#xA;float3 secondintersections = (1 - localcampos) * invraydir;&#xA;float3 closest = min(firstintersections, secondintersections);&#xA;float3 furthest = max(firstintersections, secondintersections);&#xA;&#xA;float t0 = max(closest.x, max(closest.y, closest.z));&#xA;float t1 = min(furthest.x, min(furthest.y, furthest.z));&#xA;&#xA;float planeoffset = 1-frac( ( t0 - length(localcampos-0.5) ) * MaxSteps );&#xA;&#xA;t0 += (planeoffset / MaxSteps) * PlaneAlignment;&#xA;t0 = max(0, t0);&#xA;&#xA;float boxthickness = max(0, t1 - t0);&#xA;float3 entrypos = localcampos + (max(0,t0) * localcamvec);&#xA;&#xA;return float4( entrypos, boxthickness ); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;For the life of me, I don't get how this works. I'm not familiar with Unreal Engine at all and doing my version in Metal.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;here's my version without plane offset adjustment:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;constant bool cam_inside        [[ function_constant(FogVolumeCamInsideIndex) ]];&#xA;&#xA;vertex VolumeVertexInOut vert_volume_raymarch(VolumeCubeVertex                   in             [[ stage_in   ]],&#xA;                                              constant float4x4                  &amp;amp;mvp           [[ buffer(10) ]],&#xA;                                              constant float4x4                  &amp;amp;model_inv     [[ buffer(11) ]],&#xA;                                              constant float4                    &amp;amp;cam_pos       [[ buffer(12) ]]) {&#xA;    VolumeVertexInOut out;&#xA;    out.local_cam_pos         = model_inv * cam_pos;&#xA;    float4 world_pos          = cam_inside ? out.local_cam_pos : float4(in.position, 1.0);&#xA;    out.position              = mvp * float4(in.position, 1);&#xA;    out.volume_space_coords   = float4(world_pos.xyz + 0.5, 1).xyz;&#xA;    out.projected_coords      = mvp * (cam_inside ? float4(in.position, 1) : world_pos);&#xA;    return out;&#xA;}&#xA;&#xA;constant float MAX_STEPS = 512;&#xA;constexpr sampler depth_sampler(filter::nearest);&#xA;&#xA;fragment float4 frag_volume_raymarch_compute_rays(VolumeVertexInOut                  in                           [[ stage_in     ]],&#xA;                                                  texture2d&amp;lt;float, access::sample&amp;gt;   tex_back_pos                 [[ texture(1)   ]],&#xA;                                                  texture2d&amp;lt;float, access::sample&amp;gt;   tex_front_pos                [[ texture(2)   ]],&#xA;                                                  texture2d&amp;lt;float, access::sample&amp;gt;   scene_depth_buffer           [[ texture(3)   ]],&#xA;                                                  texture2d&amp;lt;float, access::sample&amp;gt;   volume_depth_buffer_back     [[ texture(4)   ]],&#xA;                                                  texture2d&amp;lt;float, access::sample&amp;gt;   volume_depth_buffer_front    [[ texture(5)   ]],&#xA;                                                  constant float                     &amp;amp;zNear_scene                 [[ buffer(1)    ]],&#xA;                                                  constant float                     &amp;amp;zNear_local                 [[ buffer(2)    ]],&#xA;                                                  constant float                     &amp;amp;zFar                        [[ buffer(3)    ]],&#xA;                                                  constant uint                      &amp;amp;plane_alignment             [[ buffer(4)    ]]) {&#xA;&#xA;    float2 texcoord         = (in.projected_coords.xy / in.projected_coords.w + 1) / 2;&#xA;    texcoord.y              = 1-texcoord.y;&#xA;&#xA;    float3 furthest         = tex_back_pos.sample(linearSampler, texcoord).xyz;&#xA;    float3 entry_pos        = in.volume_space_coords;&#xA;&#xA;    float scene_depth       = scene_depth_buffer.sample(depth_sampler, texcoord).r;&#xA;    float closest_depth     = cam_inside ? 0 : volume_depth_buffer_front.sample(depth_sampler, texcoord).r;&#xA;    float furthest_depth    = volume_depth_buffer_back.sample(depth_sampler, texcoord).r;&#xA;&#xA;    scene_depth             = linearize_depth(scene_depth, zNear_scene, zFar);&#xA;    closest_depth           = linearize_depth(closest_depth, zNear_local, zFar);&#xA;    furthest_depth          = linearize_depth(furthest_depth, zNear_local, zFar);&#xA;    closest_depth           = min(closest_depth, scene_depth);&#xA;&#xA;    float thickness         = length(furthest - entry_pos);&#xA;    scene_depth             = map(scene_depth, closest_depth, furthest_depth, 0.0, thickness);&#xA;    scene_depth             = clamp(scene_depth, 0.0, thickness);&#xA;    thickness               = min(scene_depth, thickness);&#xA;&#xA;    return float4(entry_pos, thickness);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;I think the method of computing the ray start/end points differs a bit. The scene depth bits are for interacting with classic vertex geometry.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So the question is, how do I change my shader code to include that plane alignment thing? Or if there are other ways to do this right... I'm all ears. thanks!&lt;/p&gt;&#xA;" OwnerUserId="13421" LastEditorUserId="13421" LastEditDate="2020-05-22T02:21:13.017" LastActivityDate="2020-05-22T02:21:13.017" Title="volume raymarching - aligning sample coords with the 3d texture" Tags="&lt;volume-rendering&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9872" PostTypeId="1" CreationDate="2020-05-21T19:23:05.510" Score="2" ViewCount="43" Body="&lt;p&gt;I am visualizing a dataset. My technique is to encode the data into a rgb image with the channel range [0, 255]. The data clusters in a narrow range relative to [0, 255], however, so I'm not getting enough spread in the data to get a legible visualization when I use the standard normalization:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;255 * (dataValue - dataMin) / (dataMax - dataMin)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;What non-linear normalization techniques could I use? I know the mean and standard deviation.&lt;/p&gt;&#xA;" OwnerUserId="13422" LastEditorUserId="13422" LastEditDate="2020-05-21T21:08:22.817" LastActivityDate="2020-05-21T21:08:22.817" Title="Normalization technique to increase spread of data in rgb space" Tags="&lt;normal-mapping&gt;&lt;raster-image&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9873" PostTypeId="2" ParentId="9869" CreationDate="2020-05-21T22:32:44.020" Score="5" Body="&lt;p&gt;It's a bit complicated because the actual wait for vsync does not happen on the CPU, it happens on the GPU. The GPU wait then creates &lt;a href=&quot;https://medium.com/@jayphelps/backpressure-explained-the-flow-of-data-through-software-2350b3e77ce7&quot; rel=&quot;noreferrer&quot;&gt;back-pressure&lt;/a&gt; that propagates back to the queue of submitted command lists on the CPU, through the GL driver, and eventually to your app. The exact behavior will depend on the details of how the GPU vendor chose to implement their GL driver, and also probably depends on the behavior of the windowing system as it controls frame presentation. Unfortunately there are no real guarantees about this in GL as far as I'm aware, it's really up to the vendors.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In this case, it seems likely that you're seeing the wait become visible to your app at the first GL command that causes the driver to try to begin recording into a new command list (which may entail waiting for a previous command list to finish executing on the GPU, so that the driver can reuse it for the new frame). Clears, draw calls, dispatches, buffer mapping or copying, etc would probably qualify, while (for example) state-setting calls or memory allocation calls might not issue any actual commands to the GPU.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-05-21T22:32:44.020" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9874" PostTypeId="2" ParentId="9870" CreationDate="2020-05-21T23:15:23.417" Score="2" Body="&lt;p&gt;Almost all image formats store colors gamma-encoded, so if you write out those values to a file then that's what you'll see on opening it. The pixel pickers etc operate on the same values stored in the file. It's much less common to store linear-light color values in a file (one example is digital camera RAW files).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When you &quot;see color C1&quot; on the screen, you &lt;em&gt;are&lt;/em&gt; seeing C1^gamma. Or rather, you are seeing however that particular monitor renders the RGB value C1, which is at least approximately described by C1^gamma for some gamma. The color you see does not differ between the paint program and the programmatically generated file because they're both sending C1 to the monitor, and the monitor is doing the same thing with it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Re: your update&lt;/strong&gt;, you wrote:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;if you open this file on a viewer you will see pixels with brightness half as white&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Think about this carefully. How are you judging that the pixels are &quot;half as white&quot;? Are you measuring them with a photometer and finding that they emit half the luminous intensity of a full white pixel? Or are you looking at them and judging that they appear roughly halfway between black and white?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Human perception of brightness is very non-linear. A value that looks &lt;em&gt;perceptually&lt;/em&gt; halfway between black and white is &lt;em&gt;physically&lt;/em&gt; closer to 20% of the brightness of white, not 50%.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A good way to find a true 50% brightness is to create an image with a checkerboard of black and white pixels, then defocus your eyes slightly, or stand farther away from the monitor, so that the pattern blurs into a uniform grey. That grey is 50% brightness (because it's an average over 50% black pixels and 50% white pixels). You will find that this grey looks considerably brighter than an RGB (128, 128, 128) grey.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For example, open this image in a new tab to be sure it's appearing at 1:1 resolution (browsers resizing it do not necessarily respect gamma):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/aMtnt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aMtnt.png&quot; alt=&quot;gamma test image&quot;&gt;&lt;/a&gt;&#xA;You will see that the checkerboard in the center looks a lot brighter than the 128 grey on the left, and should be pretty close to the 186 grey on the right. The 186 is encoding a 50% brightness at 2.2 gamma.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Re: update 2&lt;/strong&gt;, you wrote:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;So with input of 186 the screen outputs 50% of white intensity? And the eye perceives it as 50% as bright as white?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Not quite—the eye perceives a 50% physical intensity as &lt;em&gt;more&lt;/em&gt; than halfway between black and white. Maybe around 70% or so. Conversely, the grey that the eye perceives as halfway between black and white is more like a 20% physical intensity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Actually, gamma-encoded values are a fairly close match to how we perceive brightness, which is convenient (although it's sort of a coincidence; the original reason for gamma was due to how CRT phosphors worked, not anything to do with perception). For a true perceptually uniform color space, you can look at &lt;a href=&quot;https://en.wikipedia.org/wiki/CIELAB_color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;CIELAB&lt;/a&gt;, which has a more complicated nonlinear transformation that's designed to mimic average human perception.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;is it the programmer responsibility to write gamma-corrected values into the file or the whatever API we use to save image file formats does it internally?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's the programmer's responsibility. Almost all image file formats, libraries, and APIs are just passing around gamma-encoded values and do not do any transformations on them.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-05-23T18:55:00.840" LastActivityDate="2020-05-23T18:55:00.840" CommentCount="13" ContentLicense="CC BY-SA 4.0" />
  <row Id="9875" PostTypeId="1" CreationDate="2020-05-24T08:42:05.060" Score="3" ViewCount="113" Body="&lt;p&gt;I'm working on a pathtracer and while it's working mostly fine, I'm getting different outputs with cosine-weighted sampling and uniform sampling : &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/25oxs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/25oxs.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Uniform sampling is on the left, cosine-weighted is on the right. The difference is somewhat subtle, but it does not go away with more samples so it's not some kind of start up bias.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I've checked my code against PBRT and Wikipedia but I cannot figure out what is wrong, because all the factors seem to be there (brdf, pdf, Li, and cos(theta)). I'm hoping someone here could take a fresh look at it :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;// Sampling functions :&#xA;Vec3 sample_uniform_hemisphere(Sampler* sampler, float* pdf) {&#xA;    float cosTheta, v;&#xA;    sample_unit_square(sampler, &amp;amp;cosTheta, &amp;amp;v, NULL);&#xA;    float sinTheta = sqrtf(1 - cosTheta * cosTheta);&#xA;    float cosPhi = cosf(2 * M_PI * v);&#xA;    float sinPhi = sinf(2 * M_PI * v);&#xA;&#xA;    if (pdf)&#xA;        *pdf = .5f / M_PI;&#xA;    return (Vec3) {&#xA;        sinTheta * cosPhi,&#xA;        sinTheta * sinPhi,&#xA;        cosTheta&#xA;    };&#xA;}&#xA;&#xA;Vec3 sample_cosine_weighted_hemisphere(Sampler* sampler, float* pdf) {&#xA;    Vec3 sample;&#xA;    sample_unit_disc(sampler, &amp;amp;sample.x, &amp;amp;sample.y, NULL);&#xA;&#xA;    float z2 = 1.0f - sample.x * sample.x - sample.y * sample.y;&#xA;    sample.z = sqrtf(z2 &amp;gt; 0.0f ? z2 : 0.0f);&#xA;    if (pdf)&#xA;        *pdf = sample.z / M_PI; // p(theta, phi) = cos(theta) / pi&#xA;    return sample;&#xA;}&#xA;&#xA;// Snippet that does the actual shading :&#xA;        float pdf;&#xA;        Vec3 bounce_sample = it.material-&amp;gt;bsdf-&amp;gt;sampler(it.sampler, local_out, &amp;amp;pdf);&#xA;        Ray bounce = {&#xA;        .o = surface_point,&#xA;        .d = basis2world(bounce_sample, u, v, it.normal)&#xA;        };&#xA;&#xA;        Intersect bounce_it = trace_ray(sc, bounce, it.depth + 1, it.sampler);&#xA;        Color f = it.material-&amp;gt;bsdf-&amp;gt;f(it.material-&amp;gt;params,&#xA;                       bounce_sample, local_out);&#xA;        Color dc = cmul(&#xA;            bounce_it.outgoing_radiance,&#xA;            f);&#xA;        float inv_pdf = pdf &amp;gt; EPSILON ? (1.0f / pdf) : 1.0f;&#xA;        rval = cadd(rval,&#xA;            cscale(dc, inv_pdf * bounce_sample.z));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="13436" LastActivityDate="2021-02-24T03:09:20.880" Title="How do I make sure my cosine-weighted sampling works fine?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9876" PostTypeId="1" AcceptedAnswerId="9878" CreationDate="2020-05-24T14:14:52.397" Score="3" ViewCount="56" Body="&lt;p&gt;During vertex processing with 4x4 matrices, we might stack multiple transformations like projection, model-world, world-camera, etc. by doing something like this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$v_{final} = T_N \cdot ... \cdot T_1 \cdot T_0 \cdot v$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now from the &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;GLSL specs&lt;/a&gt; (section 5.1), I get that the operator associativity is &quot;left to right&quot;. So this:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$v_{final} = T_2 \cdot T_1 \cdot T_0 \cdot v$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;is equivalent to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$v_{final} = ((T_2 \cdot T_1) \cdot T_0) \cdot v$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, as matrix multiplication is associative, the result does not change if we write:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$v_{final} = T_2 \cdot (T_1 \cdot (T_0 \cdot v))$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;While both versions yield the same result, the second version should (at least in theory) be much cheaper to compute since it incorporates 3 matrix-vector multiplications while the first version does 2 matrix-matrix multiplications and a final matrix-vector multiplication.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So my question is, does enforcing the order by adding extra parenthesis really boost performance or is the GLSL compiler usually smart enough to figure out, that the order of operations does not matter for the result and he can reorder the executions for performance even though the specs say &quot;left to right&quot; associativity?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Additional Note&lt;/strong&gt;: &#xA;I specially mentioned 4x4 matrices, because if you use 3x3 matrices or quaternions, you have to use parenthesis anyways because of the addition of the translations.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-05-24T19:09:32.600" Title="Operator associativity and 4x4 matrices - performance question" Tags="&lt;glsl&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9877" PostTypeId="1" CreationDate="2020-05-24T18:49:16.173" Score="2" ViewCount="199" Body="&lt;p&gt;I am doing some parallel reduction and mostly following &lt;a href=&quot;https://developer.download.nvidia.com/assets/cuda/files/reduction.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;these nVidia slides&lt;/a&gt;. However they are not very detailed in places or I might be missing/misunderstanding something. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 2:&lt;/strong&gt;&#xA;While I figured out a solution for my usecase as mentioned later I am very skeptical of the efficiency of this (assigning a second computebuffer and second kernel etc.) and would appreciate if anyone could tell me how to do this properly or point out problems with this solution. &lt;em&gt;NB: i am storing more data in groupshared memory than in these code examples but the fundamental operations are the same&lt;/em&gt;&#xA;&lt;strong&gt;end of edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am working from Unity with compute shaders.&#xA;I successfully reduced data thus far but now ran out of groupshared memory when attempting to upscale everything*. Now the nVidia slides on parallel reduction say to use multiple kernel invocations and &quot;kernel launch serves as global synchronisation point&quot;. But I am a little unsure of how to take advantage of that. Currently my parallel reduction looks roughly like this: &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RWStructuredBuffer&amp;lt;float4&amp;gt; buffers;&#xA;groupshared float4 sharedMem1[1024];&#xA;groupshared float4 sharedMem2[1024];&#xA;int specificIndex;&#xA;&#xA;[numthreads(32, 32, 1)]&#xA;void ComputeStuff32x32(int3 id : SV_GroupThreadID, int3 gID : SV_GroupID)&#xA;{&#xA;   Dostuff();...&#xA;&#xA;   GroupMemoryBarrierWithGroupSync();&#xA;&#xA;   for (unsigned int s = 512; s &amp;gt; 0; s &amp;gt;&amp;gt;= 1)&#xA;   {&#xA;       if (flatId &amp;lt; s)&#xA;       {&#xA;            sharedMem[flatId] += sharedMem[flatId+ s];&#xA;            sharedMem2[flatId] += sharedMem2[flatId+ s];&#xA;       }&#xA;       GroupMemoryBarrierWithGroupSync();&#xA;    }&#xA;&#xA;    if (flatId == 0) {&#xA;    buffer[specificIndex] = sharedMem[0]&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Now this all works fine in a 16x16 kernel but when i get to 32x32 I'm running out of shared memory. How exactly would i go about dispatching the kernel 4 times as a 16x16 reduction and combining the 4 resulting values? &lt;strong&gt;Edit:&lt;/strong&gt; And if I need to synchronize over multiple kernel dispatches what exactly are multiple thread groups good for? Can I somehow just create multiple groups and synchronize them? &lt;strong&gt;end of edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Edit 2:&lt;/strong&gt;&#xA;I am succesfully brute forcing this by simply having an additional RWStructuredBuffer&amp;lt;\float3&gt; tempBuffer; with a size of 32*sizeof(float3). The first kernel is dispatched in 32 groups of 32 threads (rather than 32x32 threads) that reduce all data along x axis and store it in the tempBuffer[groupID] &lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;RWStructuredBuffer&amp;lt;float4&amp;gt; groupResults;&#xA;RWStructuredBuffer&amp;lt;float4&amp;gt; finalResult;&#xA;groupshared float4 sharedMem1[32];&#xA;[numthreads(32, 1, 1)]&#xA;void Compute32x32(int3 id : SV_GroupThreadID, int3 gID : SV_GroupID)&#xA;{   &#xA;    doReduction();&#xA;    if (id.x == 0) &#xA;    {&#xA;         groupResults[gID.x] = sharedMem1[0]&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;After dispatch of this kernel i dispatch another kernel to combine the result:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;groupshared float4 sharedMem2[32];&#xA;[numthreads(32, 1, 1)]  // combines the result from previous thread groups&#xA;void combine32x32Result(int3 id : SV_GroupThreadID, int3 gID : SV_GroupID)&#xA;{&#xA;    sharedMem2[i] = groupResults[i];&#xA;&#xA;    for (unsigned int s = 16; s &amp;gt; 0; s &amp;gt;&amp;gt;= 1) &#xA;    {               &#xA;        if (id.x &amp;lt; s)&#xA;        {&#xA;            sharedMem2[i] += sharedMem2[i+s];   &#xA;        }&#xA;        GroupMemoryBarrierWithGroupSync();&#xA;    }&#xA;&#xA;    if (id.x == 0) &#xA;    {&#xA;        finalResult[0] = sharedMem2[0];&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;As mentioned above i would refardless appreciate any pointers to things I am doing suboptimally / how to do things more efficiently or properly. &#xA;&lt;strong&gt;end of edit&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;*Unity says: &quot;Shader error in 'computeStuff.compute': Program 'ComputeStuff32x32', error X4586: The total amount of group shared memory (110592 bytes) exceeds the cs_5_0 limit of 32768 bytes at kernel ComputeSH32x32 (on d3d11)&quot;) &lt;/p&gt;&#xA;" OwnerUserId="11386" LastEditorUserId="11386" LastEditDate="2020-05-25T14:10:43.003" LastActivityDate="2020-05-25T14:10:43.003" Title="Groupshared memory and parallel reduction over multiple kernel dispatch" Tags="&lt;compute-shader&gt;&lt;memory&gt;&lt;unity&gt;&lt;cuda&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9878" PostTypeId="2" ParentId="9876" CreationDate="2020-05-24T19:09:32.600" Score="3" Body="&lt;p&gt;As Olivier mentioned, it's not safe in general to apply algebraic optimizations to floating-point math, as floating point doesn't actually obey associativity rules due to roundoff error. &lt;span class=&quot;math-container&quot;&gt;$(a + b) - b$&lt;/span&gt; will not be equal to &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt;, if the intermediate result &lt;span class=&quot;math-container&quot;&gt;$(a + b)$&lt;/span&gt; had to be rounded; nor will &lt;span class=&quot;math-container&quot;&gt;$a \cdot (b + c)$&lt;/span&gt; be equal to &lt;span class=&quot;math-container&quot;&gt;$a \cdot b + a \cdot c$&lt;/span&gt; in general, for the same reason.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That being said, shader compilers are typically very relaxed about floating-point math optimizations. They behave like using &lt;a href=&quot;https://clang.llvm.org/docs/UsersManual.html#cmdoption-ffast-math&quot; rel=&quot;nofollow noreferrer&quot;&gt;-ffast-math&lt;/a&gt; on a C++ compiler, where they make various simplifying assumptions—including that algebraic operations &lt;em&gt;are&lt;/em&gt; associative—in order to optimize more aggressively. So it's not out of the question that a GLSL compiler could actually make the optimization you describe.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;That said, GLSL compilers vary wildly in quality; there is no canonical GLSL compiler, every GPU vendor implements their own (for OpenGL at least—in the case of Vulkan there are a couple standardized options), and who knows what level of optimizations they might or might not apply under various circumstances. If you wish the code to be optimized in a particular way, better to write it explicitly that way.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One other point,&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;the second version should (at least in theory) be much cheaper to compute &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;It's only cheaper if you're transforming just a single vertex. If you want to transform thousands of vertices by the same matrix, it will be cheaper to multiply all the matrices together up front; then each vertex only needs to be transformed by a single 4×4 matrix instead of several.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-05-24T19:09:32.600" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9879" PostTypeId="2" ParentId="9676" CreationDate="2020-05-24T19:09:48.757" Score="3" Body="&lt;p&gt;well, if anyone is stumbling across this and needs to know what solved it for me: We can bind a compute buffer to global shader memory if we just know what exactly we need to do&lt;/p&gt;&#xA;&#xA;&lt;p&gt;within the Compute shader the RWstructuredBuffer is declared as (without the &quot;\&quot; infront of float):&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform RWStructuredBuffer&amp;lt;\float3&amp;gt; buffer : register(u1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;(not certain whether &lt;code&gt;register(u1)&lt;/code&gt; is really needed&lt;/p&gt;&#xA;&#xA;&lt;p&gt;within the vert/frag shader the buffer is defined as:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;uniform StructuredBuffer&amp;lt;\float3&amp;gt; buffer;   &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;In a c# script before the first kernel dispatch (we only need to assign this buffer once), I assign the buffer via&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;buffer = new ComputeBuffer(size, sizeof(float)*3,ComputeBufferType.Default);&#xA;Shader.SetGlobalBuffer(Shader.PropertyToID(&quot;buffer&quot;), buffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;It took me ages to find this and it works as far as I can tell. &lt;a href=&quot;https://www.tzaeru.com/site/compute-shader-basics-with-unity/&quot; rel=&quot;nofollow noreferrer&quot;&gt;The article I finally stumbled over that did something similar&lt;/a&gt;. I do not have to read the data back to cpu with buffer.GetData(container) and put it into the material manually. &#xA;If the compute shader changes the buffer data this will be reflected in the vert/frag shader immediately. &lt;/p&gt;&#xA;" OwnerUserId="11386" LastEditorUserId="11386" LastEditDate="2020-05-28T10:27:10.550" LastActivityDate="2020-05-28T10:27:10.550" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9880" PostTypeId="2" ParentId="9756" CreationDate="2020-05-24T19:44:09.817" Score="2" Body="&lt;p&gt;Flood filling is not a very GPU-friendly operation to begin with, and the algorithm described in the paper is not a very good way to go about flood-filling on the GPU either. It might be possible to make it happen with some heroic efforts and compute shaders, but if flood-filling is what you want to do, I would use a different approach altogether. For example &lt;a href=&quot;https://gamedev.stackexchange.com/a/150033/9894&quot;&gt;this answer&lt;/a&gt; describes how to do flood-filling with a multi-pass approach where each pass extends the filled region by 1 pixel in all directions. It will take a lot of passes to fill a large region. You could probably use some variant of &lt;a href=&quot;https://blog.demofox.org/2016/02/29/fast-voronoi-diagrams-and-distance-dield-textures-on-the-gpu-with-the-jump-flooding-algorithm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;jump flooding&lt;/a&gt; for a more efficient method.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, if you don't actually care about flood filling but are just looking to do exercises to learn GPU programming, I'd recommend trying things like: blur filters, outlining, color transforms, image warping, and so on as those will be a lot more straightforward than any kind of flood fill.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-05-24T19:44:09.817" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9881" PostTypeId="1" CreationDate="2020-05-25T00:54:31.617" Score="1" ViewCount="34" Body="&lt;p&gt;I need to embed text in an image, research papers say HSI produces better mse and psnr therefore are better for steganography. I have RGB values(69,223,90) and its corresponding HSI is (127.223,0.458 ,0.499) I transformed I-plane 0.499 so its between 0 and 255 and got 127 as the Intensity, decreased it by one to 126(embed 0 bit). 126 was converted to the I plane normal range 0.494 and the new RGB values are red=68 green=221 blue=89. It decreased all 3 RGB values and green even more than 1. I dont understand how this is better and makes psnr better? I know the equation but say i decreased/increased the value of the intensity plane by 1 how does this affect RGB?&lt;/p&gt;&#xA;" OwnerUserId="13439" LastEditorUserId="13439" LastEditDate="2020-05-25T11:44:33.347" LastActivityDate="2020-05-25T11:44:33.347" Title="HSI color space and RGB color space relationship in Steganography" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9882" PostTypeId="2" ParentId="126" CreationDate="2020-05-25T07:56:21.213" Score="0" Body="&lt;p&gt;The approaches mentioned by the 3 answers up to now (May 2020) mention:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;subdivision surfaces&lt;/li&gt;&#xA;&lt;li&gt;BVH per object tracing/eviction + ray cache + memory management&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;There are other orthogonal techniques that can be added or used by themselves. That is decimation based on something else than OpenSubdiv. Like:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Distance fields&lt;/li&gt;&#xA;&lt;li&gt;Octahedral impostors &lt;a href=&quot;https://www.shaderbits.com/blog/octahedral-impostors&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shaderbits.com/blog/octahedral-impostors&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;image meshes (geometry is baked in maps)&lt;/li&gt;&#xA;&lt;li&gt;camera mapping&lt;/li&gt;&#xA;&lt;li&gt;voxelization&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;A different angle of thought: if your scene doesn't fit in memory, it has an entropy problem. You only have 4k res (~8 Million pixels?), therefore in the sense of Shannon &quot;more than memory&quot; cannot reasonably map to less data than can be projected to these 8Mp. Which means a scene that uses &quot;more than memory&quot; is most likely a super overkill. Thus again, the simplification approach will probably not only speed up things, but also could help aliasing.&lt;/p&gt;&#xA;" OwnerUserId="1614" LastActivityDate="2020-05-25T07:56:21.213" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9883" PostTypeId="1" CreationDate="2020-05-25T10:00:31.563" Score="0" ViewCount="39" Body="&lt;p&gt;Why does the equation at the bottom of the following page hold?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/Transforming_between_Distributions.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/Transforming_between_Distributions.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$p(\theta,\phi)d\theta d\phi=p(\omega)d\omega$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is this a conclusion of probability and measure theory?&lt;/p&gt;&#xA;" OwnerUserId="5944" LastActivityDate="2020-05-25T10:00:31.563" Title="An equation about PDFs and differentials in the book of pbrt-v3" Tags="&lt;distribution&gt;&lt;pbrt&gt;&lt;pdf&gt;&lt;differential&gt;&lt;pbrt-v3&gt;" AnswerCount="0" CommentCount="8" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9884" PostTypeId="2" ParentId="4891" CreationDate="2020-05-25T11:01:59.143" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://courses.cs.washington.edu/courses/cse458/99sp/projects/help/phong_params.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://courses.cs.washington.edu/courses/cse458/99sp/projects/help/phong_params.html&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;    Material    Diff. slider    Diff. color             Spec. slider    Spec. color         Shininess&#xA;    Metal       low             color of metal          high            color of metal      high&#xA;    Plastic     medium          color of plastic        medium          white               medium&#xA;    Lunar dust  high            white                   0               --                  0&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="8877" LastActivityDate="2020-05-25T11:01:59.143" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9885" PostTypeId="1" CreationDate="2020-05-26T08:05:30.353" Score="2" ViewCount="120" Body="&lt;p&gt;I have an e-commerce website dealing with flowers and cakes. We get our photoshoot done inhouse and also the post-shoot editing of images. While we upload them on the website all images go through the same image compression algorithm. But if we compare all images, then we find product images having red color in them loosing out most of its details only in the areas with red color. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have attached an image below for your reference, here the left-hand side image is at 80% quality and the right side has no compression in place. If you compare all these images, then you will see that the red-colored areas of the images lose the most details, at least visually. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have read about jpeg compression but it says that color doesn't make any difference, but it is not the case here. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Can we do anything during photoshoot or post-editing to fix these issues?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zsb3a.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zsb3a.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13447" LastEditorUserId="209" LastEditDate="2020-05-27T07:13:37.147" LastActivityDate="2020-05-27T07:13:37.147" Title="Why does the red color channel lose the most details during jpeg compression" Tags="&lt;compression&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9886" PostTypeId="2" ParentId="9885" CreationDate="2020-05-26T09:43:23.287" Score="1" Body="&lt;p&gt;First, &lt;a href=&quot;https://graphicdesign.stackexchange.com/questions/21204/why-do-jpeg-files-blur-red-more-than-other-colors&quot;&gt;here is a link&lt;/a&gt; to a related topic of the graphic design stack exchange site.&lt;/p&gt;&#xA;&lt;p&gt;Even though the discussion was more focussed around effects on an image with large homogeneous color areas, here are some quotes I think that are relevant for your case:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;JPEGs are best suited for &lt;strong&gt;continuous tone&lt;/strong&gt; images like photographs or natural artwork; &lt;strong&gt;not so well on sharp-edged&lt;/strong&gt; or flat-color art like lettering, simple cartoons, or line drawings&lt;/p&gt;&#xA;&lt;p&gt;JPEG is actually just a compression algorithm, not a file format. JPEG is designed to exploit certain properties of our eyes, namely, &lt;strong&gt;that we are more sensitive to slow changes of brightness and color than we are to rapid changes&lt;/strong&gt; over a short distance&lt;/p&gt;&#xA;&lt;p&gt;Compression artifacts from &lt;strong&gt;hard edges&lt;/strong&gt; are proportional to the contrast of the edges&lt;/p&gt;&#xA;&lt;p&gt;This loss of data is most often noticeable where colors transition from one field of solid color to another field of solid color. &lt;strong&gt;There's no direct issue with any particular color specifically.&lt;/strong&gt; It is more about large areas of similar colors.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Also &lt;a href=&quot;https://en.wikipedia.org/wiki/JPEG&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia says&lt;/a&gt; in the articles &amp;quot;JPEG compression&amp;quot; section:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;A perceptual model based loosely on the human psychovisual system discards high-frequency information, i.e. &lt;strong&gt;sharp transitions in intensity&lt;/strong&gt;, and color hue.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Building upon these quotes I conclude, that the compression artifacts do not depend on the color, as you already read in other sources. However, JPEGs are obviously not suited for high contrasts and sharp edges.&lt;/p&gt;&#xA;&lt;p&gt;Now when I look at your pictures, the rose blossoms and the red cake have complex/rough surfaces that cast a lot of shadows. So they have hard edges in their intensity/brightness and you can expect some artifacts there. Most of the other parts of those images don't have such a high density of sharp edges, this why you might think that red is particularly affected by the compression. The fact that the high contrast and brightness of the red attracts your eye's attention increases this impression. But if you look at other sharp edges, for example, the chocolate on top of the second cake or the yellow paper that is wrapped around the roses in the first picture, you can also see those compression artifacts. The lower density of sharp edges and the duller colors just don't make them so obvious.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Can we do anything while photoshoot or post editing to fix these issues?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;If you have the option, the best thing would be to use an image format with loss-free compression -&amp;gt; PNG.&lt;/p&gt;&#xA;&lt;p&gt;If this is not an option, the only thing I can come up with is avoiding high contrasts in your motives. Also, maybe you can use some photoshop filters to soften the hard edges a little bit before you compress the image. This will also reduce the image quality, but maybe it will give more acceptable results after compression (no guarantees here - might be worse).&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="-1" LastEditDate="2020-06-18T08:32:12.800" LastActivityDate="2020-05-26T09:43:23.287" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9887" PostTypeId="1" CreationDate="2020-05-26T14:57:56.167" Score="4" ViewCount="150" Body="&lt;p&gt;I have managed to greatly minimize draw calls on my recent project, but as I'm adding more shaders, I see that I have to switch more times and that is causing a lot of draw calls. What is the best practice for managing multiple (dozens) of shaders in a scene with many materials?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I read that it's best to combine them together and you have a shader variable &quot;mode&quot; that you switch upon inside the shader, to end up with the specific branch of code in the shader that is to handle the fragment.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Since shaders do have alot of parameters populated from the model material/mesh and sent down to the fragment shader, I fear that unifying the shaders and passing too many parameters in the VBO each frame/vertex/fragment, would be really bad for performance. I target mobile/tablet devices with my product so this is important, I understand that this is less of a concern with desktop GPUs. I see modern engines like unity and unreal allowing full flexibility on adding shaders &amp;amp; materials at-will and their scenes render perfectly - how do they do that without increasing their shader switching and draw calls?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So how many parameters are too much? And what is the best recomendation to manage multiple shaders in a drawing a scene. I understand and have allready applied grouping and rendering each material at once to minimize shader switching, but that has its limitations if there are dozens of shaders.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Is there a technique or capability I'm missing?&lt;/p&gt;&#xA;" OwnerUserId="13449" LastEditorUserId="2654" LastEditDate="2020-05-26T21:45:18.553" LastActivityDate="2020-06-12T16:26:41.750" Title="Best practice for managing many shaders and merging multiple shaders into one?" Tags="&lt;performance&gt;&lt;opengl-es&gt;&lt;mobile&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9888" PostTypeId="1" CreationDate="2020-05-26T19:36:46.593" Score="2" ViewCount="67" Body="&lt;p&gt;I am writing a forward monte carlo path tracer with the added feature of specular refractions for transparent materials, I have managed to come this far but something is not quite right and I am having a hard time figuring out what. I have looked at the &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/introduction-to-shading/reflection-refraction-fresnel&quot; rel=&quot;nofollow noreferrer&quot;&gt;following guide&lt;/a&gt; and I make sure to invert the normal, switch the refractive indices etc depending on whether we are entering a material with a lower or higher refractive index. It seems like the reflection part when I get total internal reflection works great but the problem is the refraction direction I think but I don't see the problem with it. I am using a russian roulette approach to choose either reflection or refraction and the variable p is the pdf.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what I achieve right now with Transparency = 1.0f, refractive index = 1.5f:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.imgur.com/Qs4KXFQ.png&quot; alt=&quot;Refraction&quot;&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My code for calculating the sample direction looks like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;vec3 BlinnPhongGlass::sample_wi(vec3 &amp;amp; wi, const vec3 &amp;amp; wo, vec3 &amp;amp; n, float &amp;amp; p) {&#xA;    vec3 tangent = normalize(perpendicular(n));&#xA;    vec3 bitangent = normalize(cross(tangent, n));&#xA;    float phi = 2.0f * M_PI * randf();&#xA;    float cos_theta = pow(randf(), 1.0f / (shininess + 1));&#xA;    float sin_theta = sqrt(max(0.0f, 1.0f - cos_theta * cos_theta));&#xA;    vec3 wh = normalize(sin_theta * cos(phi) * tangent + sin_theta * sin(phi) * bitangent + cos_theta * n);&#xA;&#xA;    if (randf() &amp;lt; 0.5f) {&#xA;        // Sample a direction based on the Microfacet brdf&#xA;        // PDF for wh&#xA;        p = (shininess + 1.0f) * pow(dot(n, wh), shininess) / (2.0f * M_PI);&#xA;&#xA;        // Reflect wo around wh to get wi&#xA;        wi = -(wo - (2.0f * dot(wo, wh) * wh));&#xA;&#xA;        // PDF for wi&#xA;        p = p / (4.0f * dot(wo, wh));&#xA;        p = p * 0.5f;&#xA;&#xA;        return reflection_brdf(wi, wo, n);&#xA;    } else {&#xA;        p = 1.0f;&#xA;        p = p * 0.5f;&#xA;&#xA;        float no = 1.5f; // Glass&#xA;        float ni = 1.0f; // Air&#xA;&#xA;        bool outside = dot(wo, n) &amp;lt; 0;&#xA;        float etaI = outside ? ni : no; // Index of medium we are currently in&#xA;        float etaT = outside ? no : ni; // Index of medium we are about to enter&#xA;        float eta = etaI / etaT;&#xA;&#xA;        // Compute wi using Snell's law&#xA;        float cosThetaI = outside ? -dot(n, wo) : dot(n, wo);&#xA;        float sin2ThetaI = max(0.0f, 1.0f - cosThetaI * cosThetaI);&#xA;        float sin2ThetaT = eta * eta * sin2ThetaI;&#xA;&#xA;        // Total internal reflection -&amp;gt; reflect instead&#xA;        if (sin2ThetaT &amp;gt;= 1) {&#xA;            wi = -(wo - (2.0f * dot(wo, wh) * wh));&#xA;            return reflection_brdf(wi, wo, n);&#xA;        }&#xA;&#xA;        n = outside ? n : -n; // Invert normal when exiting&#xA;&#xA;        float cosThetaT = sqrt(1.0f - sin2ThetaT);&#xA;&#xA;        wi = normalize(eta * -wo + (eta * cosThetaI - cosThetaT) * n);&#xA;&#xA;        vec3 brdf = vec3(transparency) / dot(wo, n);&#xA;&#xA;        return brdf;&#xA;        // We need to attenuate the refracted brdf with (1 - F)&#xA;        //const float fresnel_term = R0 + (1.0f - R0) * pow(1.0f - abs(dot(wh, wi)), 5.0f);&#xA;        //return (1 - fresnel_term) * brdf;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13337" LastEditorUserId="13337" LastEditDate="2020-05-27T18:03:25.460" LastActivityDate="2020-05-27T18:03:25.460" Title="Implementing monte carlo path traced refractions problem" Tags="&lt;raytracing&gt;&lt;3d&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;&lt;physics&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9889" PostTypeId="1" CreationDate="2020-05-27T02:08:52.480" Score="0" ViewCount="30" Body="&lt;p&gt;I'm making a raytracer and want to print debug arrows&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Blender example:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/z2hGH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/z2hGH.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Old version of 3d max:&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5lRWz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5lRWz.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;How do I do the same having camera forward, up and right vector?&#xA;I think I need some kind of matrix transformation? Can it be done without using matrices?&lt;/p&gt;&#xA;" OwnerUserId="8487" LastActivityDate="2020-05-27T02:08:52.480" Title="How to transform x-y-z red-green-blue arrows and draw them on 2D screen?" Tags="&lt;3d&gt;&lt;transformations&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9890" PostTypeId="2" ParentId="9885" CreationDate="2020-05-27T04:51:32.297" Score="4" Body="&lt;p&gt;One issue is &quot;chroma subsampling&quot;. The image data of a JPEG is not stored in packed RGB but YCbCr as 3 seperate planes. The Cr and Cb channels contain colour information and the Y channel is luminance. In JPEG it is common to use a lower resolution Cr/Cb channel, typically at half the resolution of the Y channel, this is know as 422 Chroma subsampling (another variant is 420 where only the horizontal resolution is halved).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What you can do is select 444 Chroma subsampling, if possible, which will mean no down-scaling of the Cr/Cb channels. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Gimp you can select the subsampling type in &quot;advanced options&quot; when exporting JPEG files. This is independent of the quality setting slider.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;There is a great image from wikipedia which compares the various subsampling modes side-by-side with a visualisation of one of the chroma channels, you can see the red decal in the centre is most affected by downscaling as that channel has high contrast edges&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yswEk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yswEk.jpg&quot; alt=&quot;Chroma example - from Wikipedia&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Chroma_subsampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia article for Chroma Subsampling&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2020-05-27T05:41:49.970" LastActivityDate="2020-05-27T05:41:49.970" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9891" PostTypeId="2" ParentId="5465" CreationDate="2020-05-27T13:06:57.127" Score="0" Body="&lt;p&gt;I know this is old but game engines/graphics cards run in &quot;triangles&quot; because that is how they calculate mesh. They do not calculate mesh in quads. That was something created to allow all of the features mentioned above to happen in 3D modeling. All quads are two triangles in the &quot;engine&quot;. They are propagated that way to allow you to work with them efficiently. Essentially, all engines triangulate in the final process. The first answer here explains it correctly: &lt;a href=&quot;https://gamedev.stackexchange.com/questions/66312/quads-vs-triangles/66314#66314&quot;&gt;https://gamedev.stackexchange.com/questions/66312/quads-vs-triangles/66314#66314&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13455" LastActivityDate="2020-05-27T13:06:57.127" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9892" PostTypeId="1" AcceptedAnswerId="9895" CreationDate="2020-05-28T08:23:11.943" Score="2" ViewCount="376" Body="&lt;p&gt;So i've a made a texture. I've saved the RGB one with BC7 compression, then added alpha channel[specular map] with varying levels of grayscale, and saved the file again as RGBA with BC7 compression. The resulting file has the same size as the one without alpha, yet it contain additional information -alpha channel. How it is possible? You can't have cake and eat cake as i understand, so are there any compromises made to ensure same size? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Im using photoshop with intel DDS plugin. &lt;/p&gt;&#xA;" OwnerUserId="13457" LastActivityDate="2020-08-26T16:03:48.453" Title="BC7 texture with alpha has the same size as BC7 without alpha" Tags="&lt;texture&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9893" PostTypeId="2" ParentId="9892" CreationDate="2020-05-28T10:47:31.990" Score="2" Body="&lt;p&gt;Here is an article about the BCn format: &lt;a href=&quot;http://www.reedbeta.com/blog/understanding-bcn-texture-compression-formats/&quot; rel=&quot;nofollow noreferrer&quot;&gt;click me&lt;/a&gt;. It is written by Nathan Reed, who is quite active on this site. So he will probably pass by and might answer your question with more details, even though I think the article will explain everything you need to know.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The most relevant part for your question seems to be this section from the article:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;BC stands for “block compression”, and the BCn formats &lt;strong&gt;all operate in terms of 4×4 blocks of pixels.&lt;/strong&gt; All images are sliced up into these small blocks, and each block is self-contained—the data to decode it is all in one contiguous chunk in memory. Moreover, &lt;strong&gt;the size of each compressed block is fixed—either 8 or 16 bytes&lt;/strong&gt;, depending on which BCn format is being used. This represents a 4:1 or 8:1 compression ratio, if the source image is in 8-bit RGBA format.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;So as long as your pixel count does not change, the size of the texture does not change either. However, the more channels you use (only 3 and 4 are supported by BC7 according to &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3d11/bc7-format&quot; rel=&quot;nofollow noreferrer&quot;&gt;the Microsoft documentation&lt;/a&gt;), the less information you can store per color channel in a block. This means, that you lose more information due to compression when using RGBA instead of RGB. &lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-05-28T10:56:06.910" LastActivityDate="2020-05-28T10:56:06.910" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9894" PostTypeId="1" CreationDate="2020-05-28T11:50:09.620" Score="1" ViewCount="47" Body="&lt;p&gt;Most of the existing open-source libraries such as OpenCV, Tensorflow, and Pytorch use &lt;strong&gt;Google Test&lt;/strong&gt;. I would like to know about strong alternative testing frameworks that thrive under a similar workload. Suggestions from areas such as real-time graphics and physics engines are absolutely welcome!&lt;/p&gt;&#xA;" OwnerUserId="13459" LastActivityDate="2020-05-28T11:50:09.620" Title="What modern C++ Unit Testing Framework do you use for highly parallel image, 3D and higher dimensional matrix processing workloads?" Tags="&lt;3d&gt;&lt;image-processing&gt;&lt;c++&gt;&lt;gpu&gt;&lt;real-time&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2020-06-01T09:21:27.350" ContentLicense="CC BY-SA 4.0" />
  <row Id="9895" PostTypeId="2" ParentId="9892" CreationDate="2020-05-28T17:50:55.903" Score="3" Body="&lt;p&gt;BC7 always effectively encodes 4 channels. That's part of the nature of the format. Turning on alpha means that the compressor will read and use the alpha value in your source image, but that's all.&lt;/p&gt;&#xA;&lt;p&gt;All BC7 compressed images of a given dimension have the same size, since BC7 compresses each 4x4 group of texels into 128-bits. But that doesn't mean they have the same &lt;em&gt;quality&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;BC7 is an adaptive encoding format. While each block has a fixed size (both spatially and bit-wise), each block stores how many channels that block actually compresses and the way that they correlate with one another. The &lt;a href=&quot;https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#bptc_bc7&quot; rel=&quot;nofollow noreferrer&quot;&gt;specifics are complex&lt;/a&gt;, but the general upside is that the compressor figures out on a per-block basis what manner of compression works best for a particular block. If the compressor can look at a block and see that the alpha for all texels is 1.0, then it can spend more bits of the 128 bits on the colors and fewer on the alpha.&lt;/p&gt;&#xA;&lt;p&gt;As such, a texture &amp;quot;without alpha&amp;quot; is exactly like a texture with alpha where every texel has an alpha of 1. These blocks will spend the majority of their bits on the non-alpha parts of the texels, only wasting a few bits on a &amp;quot;mode&amp;quot; field that lets the decompressor know that the alpha is a constant 1.0.&lt;/p&gt;&#xA;&lt;p&gt;This also means that, if your texture has a varying alpha, but parts of it have a constant alpha, BC7 can encode these constant alpha areas with fewer bits, so that more bits can be spent on improved color encoding.&lt;/p&gt;&#xA;&lt;p&gt;So you shouldn't feel that there is a problem because the two compression switches came out with the same number of bytes.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-08-26T16:03:48.453" LastActivityDate="2020-08-26T16:03:48.453" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9896" PostTypeId="1" AcceptedAnswerId="9897" CreationDate="2020-05-29T03:06:34.630" Score="5" ViewCount="679" Body="&lt;p&gt;I'm new to the graphics area, and when it comes to the light part, the concept of vertex normals confuses me a lot.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;First, I cannot imagine how a vertex could have a normal, and second, when calculating the reflection lights, shouldn't I use the normal of a face?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So, can someone help me understand what a vertex normal is, what it is used for, and how it compares to a face normal?&lt;/p&gt;&#xA;" OwnerUserId="13466" LastEditorUserId="13095" LastEditDate="2020-05-29T08:08:38.900" LastActivityDate="2020-05-29T08:08:38.900" Title="What is a vertex normal used for?" Tags="&lt;lighting&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9897" PostTypeId="2" ParentId="9896" CreationDate="2020-05-29T07:00:02.767" Score="7" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;First, I cannot imagine how could a vertex have a normal,...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Welcome to the exciting field of computer graphics. The first thing that might lead to your confusion is to think about a vertex too much as a point in space in a geometrical way. ---&gt; A 3d point can't have normal since it does not have a face. &#xA;But the way you should think about it is more like a checkpoint that contains all information of an arbitrary 3d curve at a certain position. &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;... and second, when calculate the reflection lights, shouldn't I use the normal of a face? &lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;What happens if you want to render a perfect sphere that can only be represented by a limited set of triangles? It will look like the one in the middle in &lt;a href=&quot;https://blender.stackexchange.com/questions/13554/applied-boolean-modifier-leaving-shading-artifacts-with-flat-shading?rq=1&quot;&gt;this question&lt;/a&gt;. The flat surfaces are clearly visible, but that is not what you want. You can improve this by drastically increasing the triangle count, but that comes with a huge performance impact and memory footprint. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;The solution here is using &lt;strong&gt;vertex normals&lt;/strong&gt;. To understand, why this is a solution, you need to know a little bit about how the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview&quot; rel=&quot;noreferrer&quot;&gt;render pipeline&lt;/a&gt; works. The most important parts for your understanding are vertex processing, rasterization, and the pixel/fragment shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vertex processing is the first programable (in modern APIs) step in the pipeline and is mostly used to reposition your vertices so that your 3d world is displayed correctly on a 2d display. Therefore you apply some mathematical corrections (perspective for example) to your vertex positions. You can do a lot more, but that is not important here. What is important is, that the vertex processor does not know to which triangle a vertex belongs. He sees it in total isolation. Therefore, he can not calculate any face normals, so you have to provide it in some way, for example by adding it as vertex attribute.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;After some optional pipeline steps, you get to the rasterizer. Its job is to turn your triangles into actual pixels on your screen. The information he gets are three vertices that form a triangle. Now here is, where the magic happens. For each pixel, he interpolates the properties of the three vertices and passes them to the final step, the pixel shader (also programable in modern APIs). So if your vertices had normals, you will have an interpolated normal for each pixel of your triangle. This enables you to render perfectly smooth surfaces (or at least fake them) since you can perform the lighting calculation for each pixel with individual normals in the pixel shader.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is why you need vertex normals. The vertices are checkpoints that hold information about your surfaces at specific points. You connect these points to triangles. The information in between is interpolated by the rasterizer. So you essentially describe a whole triangle-shaped field of normals with its three edge values. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, even if you want to render flat surfaces, you might still need vertex normals. As I said before, the vertex processor does not know anything about triangles, so you can not calculate any surface normals there. So you have to pass them in somehow. There are other ways, but attaching the normals to the vertices is usually the best and easiest solution.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Additional note:&lt;/strong&gt; You do not necessarily need to perform the lighting calculation in the pixel shader. You can also do this in the vertex stage. So you need vertex normals again ;). This is called Gouraud Shading and gives you a performance boost since you do not need to perform the light calculations per pixel. However, the visual quality of curved surfaces suffers from that. For flat surfaces, you should not see any differences.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-05-29T07:00:02.767" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9898" PostTypeId="2" ParentId="9267" CreationDate="2020-05-29T07:27:13.860" Score="0" Body="&lt;p&gt;matplotlib's 3d rendering settings are not yet complete (it's meant to be a 2d renderer program). I don't think at this stage it has this option without big hacks to the code locally (i.e. done by yourself). Mathematica offers this setting naturally.&lt;/p&gt;&#xA;" OwnerUserId="13467" LastActivityDate="2020-05-29T07:27:13.860" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9899" PostTypeId="1" CreationDate="2020-05-29T11:34:38.303" Score="3" ViewCount="58" Body="&lt;p&gt;I struggle do understand how linear interpolation works in the marching square rendering algorithm context.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I created simple example in GDScript (Godot) of random floating metaballs to demonstrate the problem:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;extends Node2D&#xA;&#xA;class Blob:&#xA;    var pos_x&#xA;    var pos_y&#xA;    var radius&#xA;    var velocity&#xA;    func _init(x, y, r, v):&#xA;        pos_x = x&#xA;        pos_y = y&#xA;        radius = r&#xA;        velocity = v&#xA;&#xA;# Declare member variables here. Examples:&#xA;# const a = 2&#xA;# var b = &quot;text&quot;&#xA;&#xA;const cell_size = 16&#xA;const blobs_count = 10&#xA;const blob_size = [20, 40]&#xA;const max_sum = 1&#xA;var screen_size&#xA;var blobs&#xA;var allowUpdate = true&#xA;&#xA;const drawMap = {&#xA;    0: null,&#xA;    1: [-0.5, 0, 0, -0.5],&#xA;    2: [-0.5, -1, 0, -0.5],&#xA;    3: [-0.5, 0, -0.5, -1],&#xA;    4: [-1, -0.5, -0.5, -1],&#xA;    5: [-1, -0.5, -0.5, 0, -0.5, -1, 0, -0.5],&#xA;    6: [-1, -0.5, 0, -0.5],&#xA;    7: [-1, -0.5, -0.5, 0],&#xA;    8: [-1, -0.5, -0.5, 0],&#xA;    9: [-1, -0.5, 0, -0.5],&#xA;    10: [-1, -0.5, -0.5, -1, -0.5, 0, 0, -0.5],&#xA;    11: [-1, -0.5, -0.5, -1],&#xA;    12: [-0.5, -1, -0.5, 0],&#xA;    13: [-0.5, -1, 0, -0.5],&#xA;    14: [-0.5, 0, 0, -0.5],&#xA;    15: null&#xA;}&#xA;&#xA;&#xA;func calcIsoSurface(x1, x2, y1, y2, r):&#xA;    var dx = x1 - x2&#xA;    var dy = y1 - y2&#xA;    var sd = dx*dx + dy*dy&#xA;    var res = r*r / sd&#xA;    return res&#xA;&#xA;# Called when the node enters the scene tree for the first time.&#xA;func _ready():&#xA;    screen_size = get_viewport().size&#xA;    blobs = Array()&#xA;    var rng = RandomNumberGenerator.new()&#xA;    var r = rng.randi_range(blob_size[0], blob_size[1])&#xA;    var x = rng.randi_range(r, screen_size.x - r)&#xA;    var y = rng.randi_range(r, screen_size.y - r)&#xA;    for n in range(blobs_count):&#xA;        blobs.push_back(&#xA;            Blob.new(&#xA;                x, &#xA;                y, &#xA;                r, &#xA;                Vector2(rng.randf_range(-1, 1), rng.randf_range(-1, 1))&#xA;            )&#xA;        )&#xA;    print(screen_size)&#xA;&#xA;&#xA;func formDrawIndex(x, y, sum, vertexes):&#xA;    var drawIndex = 0&#xA;    var corners = []&#xA;    if x &amp;gt; 0 &amp;amp;&amp;amp; y &amp;gt; 0:&#xA;        if sum &amp;gt;= 1:&#xA;            drawIndex |= 1&#xA;&#xA;        corners.push_back(sum)&#xA;&#xA;        if vertexes.back() &amp;gt;= 1:&#xA;            drawIndex |= 2&#xA;&#xA;        corners.push_back(vertexes.back())&#xA;        corners.push_back(vertexes.pop_front())&#xA;&#xA;        if corners.back() &amp;gt;= 1:&#xA;            drawIndex |= 4  &#xA;        if vertexes.front() &amp;gt;= 1:&#xA;            drawIndex |= 8&#xA;&#xA;        corners.push_back(vertexes.front())&#xA;    return  {&quot;draw_index&quot;: drawIndex, &quot;corners&quot;: corners}   &#xA;&#xA;&#xA;func exLerp(oneSum, zeroSum):&#xA;    if oneSum == zeroSum:&#xA;        return null&#xA;    return (1 - oneSum) / (zeroSum - oneSum)&#xA;&#xA;&#xA;func interpolateLines(lines, corners):&#xA;    if lines == null:&#xA;        return lines&#xA;    for i in range(0, lines.size(), 2):&#xA;        var x = lines[i]&#xA;        var y = lines[i+1]&#xA;        #somehow implement correct interpolation here&#xA;    return lines&#xA;&#xA;&#xA;func drawLines(x, y, lines):&#xA;    if lines != null &amp;amp;&amp;amp; lines.size() &amp;gt;= 4:&#xA;        draw_line(&#xA;            Vector2(x + (cell_size*lines[0]), y + (cell_size*lines[1])), &#xA;            Vector2(x + (cell_size*lines[2]), y + (cell_size*lines[3])), &#xA;            Color.green&#xA;        )&#xA;&#xA;    if lines != null &amp;amp;&amp;amp; lines.size() == 8:&#xA;        draw_line(&#xA;            Vector2(x + (cell_size*lines[4]), y + (cell_size*lines[5])), &#xA;            Vector2(x + (cell_size*lines[6]), y + (cell_size*lines[7])), &#xA;            Color.green&#xA;        )&#xA;&#xA;# Called after update() in the _process()&#xA;func _draw():&#xA;    var vertexes = []&#xA;    for x in range(0, screen_size.x, cell_size):&#xA;        for y in range(0, screen_size.y, cell_size):&#xA;            var sum = 0&#xA;            for blob in blobs:&#xA;                sum += calcIsoSurface(x, blob.pos_x, y, blob.pos_y, blob.radius)&#xA;                #draw_circle(Vector2(blob.pos_x,blob.pos_y), blob.radius, Color.darkgray)&#xA;&#xA;            #if sum &amp;gt;= 1:&#xA;                #draw_rect(Rect2(x, y, 1, 1), Color.red)&#xA;            #else:  draw_rect(Rect2(x, y, 1, 1), Color.black)&#xA;&#xA;            var indexies = formDrawIndex(x, y, sum, vertexes)&#xA;            var lines = drawMap[indexies[&quot;draw_index&quot;]]&#xA;            lines = interpolateLines(lines, indexies[&quot;corners&quot;])            &#xA;            drawLines(x, y, lines)&#xA;&#xA;            vertexes.push_back(sum)&#xA;&#xA;        if x &amp;gt; 0:&#xA;            vertexes.pop_front()&#xA;&#xA;&#xA;&#xA;func _input(event):&#xA;    if event is InputEventMouseButton &amp;amp;&amp;amp; event.is_pressed():&#xA;        allowUpdate = !allowUpdate&#xA;        print(allowUpdate)&#xA;&#xA;&#xA;# Called every frame. 'delta' is the elapsed time since the previous frame.&#xA;func _process(delta):&#xA;    if !allowUpdate:        &#xA;        return      &#xA;    update()&#xA;&#xA;    for blob in blobs:&#xA;        blob.pos_x += blob.velocity.x&#xA;        blob.pos_y += blob.velocity.y&#xA;        if blob.pos_x &amp;gt; screen_size.x || blob.pos_x &amp;lt; 0:&#xA;            blob.velocity.x *= -1&#xA;        if blob.pos_y &amp;gt; screen_size.y || blob.pos_y &amp;lt; 0:&#xA;            blob.velocity.y *= -1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The outcome looks something like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/vCcqM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vCcqM.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now I would like to apply linear interpolation to make my meatballs smoother. This is where I stuck. The desire outcome is transform rendering of this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/t1Nve.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/t1Nve.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/v6V2m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v6V2m.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I already created &lt;code&gt;interpolateLines&lt;/code&gt; and &lt;code&gt;exLerp&lt;/code&gt; functions, but don't understand how exactly in this context linear interpolation works and why?&#xA;I used this &lt;a href=&quot;http://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/&quot; rel=&quot;nofollow noreferrer&quot;&gt;material&lt;/a&gt; as a theory for code implementation, but last part is still blurry for me.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Anyone can provide working code example and explain theory in dump language with more deep math explanation and visual demonstration?&#xA;So I can finally breakthrough this problem.   &lt;/p&gt;&#xA;" OwnerUserId="13468" LastEditorUserId="13468" LastEditDate="2020-05-29T11:41:19.047" LastActivityDate="2020-05-29T11:41:19.047" Title="2D metaballs with marching squares and linear interpolation" Tags="&lt;rendering&gt;&lt;algorithm&gt;&lt;2d-graphics&gt;&lt;physics&gt;&lt;fluid-sim&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9900" PostTypeId="1" AcceptedAnswerId="9901" CreationDate="2020-05-29T20:29:39.043" Score="4" ViewCount="49" Body="&lt;p&gt;I'm trying to produce wave surface animations, and I came across this paper: &lt;a href=&quot;https://www.researchgate.net/publication/220859148_Fast_Water_Animation_Using_the_Wave_Equation_with_Damping&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fast_Water_Animation_Using_the_Wave_Equation_with_Damping&lt;/a&gt;.  In the paper they go to provide the following equation:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yCvdb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yCvdb.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;At first I just blindly implemented this, but soon saw some strange bugs I realized weren't from me. When you evaluate the equation, say, with delta t = 1/60, delta x = 1, c = 0.01, and k = 1.0, on a grid with all zeros except the center point, you realize there's something off about this.  If you are at that center grid point, and say your value is 1.0, the acceleration component( the delta t^2 stuff in the above equation) is &lt;em&gt;positive&lt;/em&gt; when you assume all the surrounding neighbors are zero. That makes no sense. Peaks in waves do not accelerate upwards when the values around them are smaller. And further more, normally when I see finite difference of the laplacian, it is &lt;em&gt;the average of the surrounding samples minus the current sample&lt;/em&gt;.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Indeed, when I reverse the sign on the acceleration component, I get what appears to be the correct result (before vs after on 16x16 grid)&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ypr9B.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ypr9B.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bWYit.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bWYit.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;This is what I changed the equation to:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/34hPn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/34hPn.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Was this just some pervasive typo or am I completely missing something here? &lt;/p&gt;&#xA;" OwnerUserId="6530" LastActivityDate="2020-05-30T17:11:26.863" Title="Finite difference wave equation shown in paper is wrong?" Tags="&lt;rendering&gt;&lt;simulation&gt;&lt;fluid-sim&gt;&lt;height-field&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9901" PostTypeId="2" ParentId="9900" CreationDate="2020-05-30T00:28:36.113" Score="4" Body="&lt;p&gt;Yes, it looks like a sign error in the paper. It looks like it was introduced in equation (4) and then carried through the following ones.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Probably the authors wrote the source code first and the paper after, so did not notice that their equations did not match what their code was doing. Ideally it should have been caught in the paper review, but, mistakes happen.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-05-30T17:11:26.863" LastActivityDate="2020-05-30T17:11:26.863" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9902" PostTypeId="2" ParentId="9875" CreationDate="2020-05-30T01:18:37.933" Score="0" Body="&lt;p&gt;The code you've shown here looks right to me. In order to verify the implementations, you could try writing some code that just integrates a few test functions over the hemisphere using both methods and verify that you get the same result (within some sampling error). Also if you haven't already, verify that the outputs from &lt;code&gt;sample_unit_square&lt;/code&gt; and &lt;code&gt;sample_unit_disc&lt;/code&gt; are doing what they're supposed to.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-05-30T01:18:37.933" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9903" PostTypeId="2" ParentId="4026" CreationDate="2020-05-30T03:58:53.173" Score="0" Body="&lt;p&gt;you don't actually need to transform the z component, just ommit it and replace it with 1,because it is in tangent space it will only cause problems for this&#xA;edit: I had the same problem and that fixed it&lt;/p&gt;&#xA;" OwnerUserId="13476" LastActivityDate="2020-05-30T03:58:53.173" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9905" PostTypeId="1" AcceptedAnswerId="9965" CreationDate="2020-05-30T20:20:00.870" Score="3" ViewCount="96" Body="&lt;p&gt;How do I determine how many (jittered) rays to trace for a given pixel, as a function of the statistics of a small initial set of test rays? Also, what size should the initial set be? (it's currently 20, based on eyeball tests)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Currently I'm calculating the variance of the initial set and multiplying that by a arbitrary number (4000..40,000) to give the number of additional rays to trace. This gives acceptable results but I would prefer something grounded in real statistics, mostly so I can get some kind of confidence interval for how close to the true mean my sample mean is likely to be.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additional possibly relevant info: RGB values are 0..1, pixel color is mean of all samples, jitter is currently random but I'm looking into using a Halton sequence to ensure better distribution, I am modeling diffuse inter-reflections, I'm rendering on a CPU using two threads per core, each rendering thread gets a row of pixels all to itself&lt;/p&gt;&#xA;" OwnerUserId="13472" LastEditorUserId="13472" LastEditDate="2020-05-31T05:07:01.830" LastActivityDate="2020-06-22T02:02:03.230" Title="Math for adaptive supersampling for raytracing" Tags="&lt;raytracing&gt;&lt;supersampling&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="9906" PostTypeId="1" CreationDate="2020-05-30T21:01:32.017" Score="2" ViewCount="102" Body="&lt;p&gt;I am trying to build a dedocohedron in OpenGL, and I know that there is a built-in function in GLUT for the purpose. I was wondering if there is a way to either see the sourcecode for those functions, or to extract the generated data for vertices, colors, and indeces and print them?&lt;/p&gt;&#xA;" OwnerUserId="13481" LastActivityDate="2020-07-22T10:05:15.523" Title="glutSolid* source code" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9907" PostTypeId="1" CreationDate="2020-05-31T02:02:31.583" Score="3" ViewCount="148" Body="&lt;p&gt;If you open the modern Blender UI and select for example scaling, and then you use the scroll wheel to &quot;zoom&quot; (move the camera along the radial axis). You will notice that the size of the 3D&#xA;widget remains constant in screen space (it becomes bigger or smaller in regards to all the other objects).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am wondering how this can be achieved. I assume there is an obvious matrix cancellation you can do, e.g setting the w component to 1 after projecting. But I am not sure.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As you can see the widget's size in screen space is identical:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/oZxDj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oZxDj.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/8VnC7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8VnC7.png&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-05-31T19:29:53.813" Title="How to keep an object constant in screen space?" Tags="&lt;transformations&gt;&lt;camera&gt;&lt;linear-algebra&gt;&lt;gui&gt;&lt;ui&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9908" PostTypeId="2" ParentId="9907" CreationDate="2020-05-31T19:21:00.670" Score="3" Body="&lt;p&gt;Scale the object proportional to its depth (z in camera space) and it will retain the same size on screen regardless of its position in world space.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Additionally, you might also wish to scale the object proportional to the field of view so that it retains the same screen size regardless of the camera zoom. (Specifically, scale it by tan(fov/2)).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Finally, you might also wish to scale it inversely proportional to the pixel size of the window if you want the widget to retain a constant size in pixels regardless of how large the window is. Otherwise it will be constant as a fraction of the window size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I wouldn't recommend trying to do this in post-projective space (by manipulating w, etc) because it will scale the object's distance from the camera at the same time as scaling its size. Effectively you're scaling it in camera space. What you really want to do is scale it in its own local space before applying world-view-projection transformations.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-05-31T19:29:53.813" LastActivityDate="2020-05-31T19:29:53.813" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9909" PostTypeId="2" ParentId="2271" CreationDate="2020-06-01T13:56:12.403" Score="0" Body="&lt;h2&gt;I do this already.&lt;/h2&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;TL;DR: The latency between services decelerate the enthusiasm.&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have a steam-vr-client supporting a wide range of Helmets and the vr-client is connecting to a local server (Currently connectors for Java exsits only) and then further cloud-services. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;As most games have two threads who must be synchronized&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Frontend: The visualization of the gamelogic&lt;/li&gt;&#xA;&lt;li&gt;Backend: The gamelogic, model, rules....&lt;/li&gt;&#xA;&lt;li&gt;(Optional) Multiplayer Thread: Synchronizing gamestate between contributors.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;In VR there will be a growing latency between Frontend and Backend the more work is done in the Clouded-Backend. So we have to estimate what contribution to the VR is a lightweight-transported information and do the rest in the cloud.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Frontend (locally): The low-level visualisation. Calculating shadows and &quot;depth of field blur&quot;, but not calculating ambient occlusion, not calculating raytracing, not calculating Bumpmapping.&lt;/li&gt;&#xA;&lt;li&gt;Backend (locally): Collecting results from the cloud, collect Bumpmaps, transport Mesh, UV-Coodinates, Normal-Mappings, Bumpmappings, Raytrace-Results and send it to Frontend.&lt;/li&gt;&#xA;&lt;li&gt;Cloud (web/internet). Calculating raytrace, generate Bumpmaps, Calculate Mesh resolution, calculate UV-Coordinates and Normals.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The key to seperate work for different cloud services is to understand what work can be done packed autark.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;My project: &lt;a href=&quot;https://github.com/enexusde/VRServer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/enexusde/VRServer&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13485" LastActivityDate="2020-06-01T13:56:12.403" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9910" PostTypeId="1" CreationDate="2020-06-02T10:01:10.027" Score="2" ViewCount="38" Body="&lt;p&gt;I am currently trying to sample a texture in screen space. This works well :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 positionCS = vertexInput.positionCS / vertexInput.positionCS.w;&#xA;screenPos = ComputeScreenPos(positionCS).xy;&#xA;float aspect = _ScreenParams.x / _ScreenParams.y;&#xA;screenPos.x = screenPos.x * aspect;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;But I would like to be able to constrain uv position and scale based on object's position and distance from camera. I found some example but I also faced some issues and for the moment I don't see how to fix them. Here's the code :&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float4 positionCS = vertexInput.positionCS / vertexInput.positionCS.w;&#xA;screenPos = ComputeScreenPos(positionCS).xy;&#xA;float aspect = _ScreenParams.x / _ScreenParams.y;&#xA;screenPos.x = screenPos.x * aspect;&#xA;&#xA;float4 originCS = TransformObjectToHClip(float3(0.0, 0.0, 0.0));&#xA;originCS = originCS / originCS.w;&#xA;float2 originSPos = ComputeScreenPos(originCS).xy;&#xA;originSPos.x = originSPos.x * aspect;&#xA;screenPos = screenPos - originSPos;&#xA;&#xA;// You can match object's distance like this&#xA;float3 cameraPosWS = GetCameraPositionWS();&#xA;float3 originPosWS = TransformObjectToWorld(float4(0.0, 0.0, 0.0, 1.0));&#xA;float d = distance(float4(0.0, 0.0, 0.0, 0.0), cameraPosWS - originPosWS);&#xA;screenPos *= d;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And here's the issue I am facing. You can notice that when the object is near screen edges the texture starts to move. Is there a way to avoid that ?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://thumbs.gfycat.com/HairySpryArawana-mobile.mp4&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://thumbs.gfycat.com/HairySpryArawana-mobile.mp4&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am using URP but this doesn't really matter. &lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2020-06-02T10:01:10.027" Title="Per-object screen space uv issue" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;uv-mapping&gt;&lt;hlsl&gt;&lt;unity&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9911" PostTypeId="1" CreationDate="2020-06-02T10:57:39.960" Score="2" ViewCount="41" Body="&lt;p&gt;I have a 2D region defined by 4 points in 3D space. I want to position my camera so that it looks at the region, with a settable variable determining which side it looks at, where looks at means that the camera view covers the entire region to be looked at, and as little beyond that as possible. How do I calculate the orientation and position of the camera?&lt;/p&gt;&#xA;" OwnerUserId="13490" LastActivityDate="2020-06-03T11:22:12.497" Title="Calculate the position and rotation needed to have a camera look at a certain region" Tags="&lt;2d&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9912" PostTypeId="1" CreationDate="2020-06-02T15:49:13.177" Score="0" ViewCount="26" Body="&lt;p&gt;I am trying to measure the reflectance% of a surface (it is made of Teflon and is very white). I am using a line spectrometer. I believe the piece can replace an expensive Spectralon for some experiments. To show that it has a quite acceptable reflectance, I need to draw its reflectance plot at different wavelengths similar to the chart presented with Spectralon. See the below image.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/2MAyS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2MAyS.png&quot; alt=&quot;Reflectance spectrum of Spectralon&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I had a look at different pieces of literature and I found out with two spectrum recordings of direct light source facing the spectrometer and illuminating the surface with the light then recording its reflection I am able to calculate the reflectance. To do so, I normalized the two readings with respect to the exposure times and I divided the two signals (surface spectrum divided by direct illumination spectrum) and this graph is obtained.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/TMgh1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TMgh1.jpg&quot; alt=&quot;Reflectance&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I also attached the Digital Number read by camera here.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/k49xF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/k49xF.jpg&quot; alt=&quot;Teflon Digital Number normalized by the exposure time&quot;&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/FWnBi.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FWnBi.jpg&quot; alt=&quot;Digital Number from direct light&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The detail of the experimental setup is as follows:&#xA;1- The camera angle is 45 degrees with respect to the surface and the illumination light is facing 45 degrees to the surface.  &lt;/p&gt;&#xA;" OwnerUserId="13491" LastActivityDate="2020-06-02T15:49:13.177" Title="How to measure the reflectance of a material without using a Spectralon" Tags="&lt;diffuse&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9913" PostTypeId="2" ParentId="9911" CreationDate="2020-06-03T11:22:12.497" Score="1" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I have a 2D region defined by 4 points in 3D space. I want to position my camera so that it looks at the region, with a settable variable determining which side it looks at,...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The first thing you need to do for this is to define a convention that specifies which side is the front and which one is the back of your plane depending on the ordering of your nodes. With triangles, you usually use the winding order. So you can define that if you look at the front of a triangle, the points have to be in clockwise order. In conclusion, if you see that the nodes of the triangle are ordered counter-clockwise, you look at the back.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;How do I calculate the orientation and position of the camera?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Once you have this convention, you have to calculate the normal of the surface. You can get it by calculating the cross product of 2 vectors. For example, if your points are named A, B, C, D, take the vectors A-&gt;B and A-&gt;C and calculate their cross product to get the surface normal. Be aware, that the cross product is sensitive to the vector/node order. So make sure the selected points result in a normal that points away from your front side. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now, your camera orientation is the negative normal direction if you look at the front and the normal's direction if you look at the back.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Then you calculate the center point of your quadriliteral. There are several ways to do this, so just pick your favorite method or search the internet for it. Your camera position C has to be on the line that has the same direction as your surfaces' &lt;strong&gt;unit&lt;/strong&gt; normal N and goes through the center point P of your surface. So it can be calculated by&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;C = P + d \cdot N&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;where d is the distance of the camera to point P. The distance depends on your camera's field of view and the size of your plane. In your special case, where the camera looks directly onto your surface, the camera/screen plane is parallel to your surface. So you can use the &lt;a href=&quot;https://en.wikipedia.org/wiki/Intercept_theorem&quot; rel=&quot;nofollow noreferrer&quot;&gt;intercept theorem&lt;/a&gt; to calculate the minimal necessary camera distance so that all points of your plane are inside the cameras FOV.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;Remark:&lt;/strong&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The described method leaves you with one degree of freedom for your camera that is chosen more or less randomly. The rotation angle around its view direction. Depending on the size and shape of your plane, the rotation angle also influences the camera's distance to the plane. So you might want to define an additional constraint to always get the same result. For example, you could say, that your surfaces side A-B has to be parallel to your screens left-hand side.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-06-03T11:22:12.497" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9914" PostTypeId="1" AcceptedAnswerId="9915" CreationDate="2020-06-03T19:17:33.757" Score="2" ViewCount="161" Body="&lt;p&gt;This is in reference and contrast to the discipline (or more or less requirement) of opengl to group draws that use the same materials together, to minimize making many draw calls or many switch shader calls.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So is it safe to say, that since vulkan is not state/context based, you can throw any mixture of draw commands with multiple seperate shaders/materials in the command queue, with no slowdown or overhead impact, and that even if you did the grouping optimization, you wouldn't see a speedup as well?&lt;/p&gt;&#xA;" OwnerUserId="13449" LastActivityDate="2020-06-04T01:26:40.457" Title="Do you have to group and optimize your draw and shader calls in Vulkan?" Tags="&lt;vulkan&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9915" PostTypeId="2" ParentId="9914" CreationDate="2020-06-04T01:26:40.457" Score="2" Body="&lt;p&gt;Vulkan will not have the CPU-time performance costs associated with state changes (validation overhead, etc). But Vulkan command buffers do have state. They have two very major pieces of state: descriptor sets and the pipeline object.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Both of these objects are monolithic, dealing with potentially lots of pieces of information. The (potentially) huge quantity of stuff these objects control should strongly suggest to you that binding new objects is not cheap. And that's in terms of GPU execution speed, not CPU validation or whatever else.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Vulkan in general tries to make slow things in the API look slow and fast things look fast. Render passes are big, huge and complicated, so clearly you shouldn't just be starting and stopping them whenever you feel like it. Pipeline objects control a huge amount of information, so binding new ones feels like a heavyweight operation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;By contrast, changing what buffers get used for vertex input feels like a short, quick, &lt;em&gt;focused&lt;/em&gt; operation. So it's probably cheaper than changing the pipeline that uses those buffers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;So yes, you should avoid state changes in Vulkan, just as much if not moreso than in OpenGL (since many state changes in Vulkan require entirely new pipelines).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-06-04T01:26:40.457" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9916" PostTypeId="1" CreationDate="2020-06-04T08:59:54.127" Score="1" ViewCount="68" Body="&lt;p&gt;In &lt;a href=&quot;https://youtu.be/ph8LyNIT9sg?t=2028&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Road to PS5&lt;/a&gt;, Mark Cerny states:&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;It's counter-intuitive, but processing dense geometry typically consumes less power than processing simple geometry.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Why is this the case?&lt;/p&gt;&#xA;" OwnerUserId="13497" LastActivityDate="2020-06-04T08:59:54.127" Title="Why does processing dense geometry consume less power than simple geometry?" Tags="&lt;geometry&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9917" PostTypeId="1" AcceptedAnswerId="9932" CreationDate="2020-06-04T13:06:19.827" Score="0" ViewCount="53" Body="&lt;p&gt;I have many sets of vertex and index buffers that I’d like to render on to the screen. Ideally each model in different locations with-in world space. I’m actually doing a statistical study on spatial relationships between models in world space. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I have done a lot of reading on the DirectX graphics pipeline to try and get a basic understanding of how it works.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Instead of programming my own model viewer from the ground up, I thought I’d first take a look at some pre-built solutions first to save me the time. I found this: &lt;a href=&quot;https://github.com/walbourn/directxtkmodelviewer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/walbourn/directxtkmodelviewer&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;From what I can tell, it only supports loading models from DirectX SDK .SDKMESH files and .VBO files. So 2 questions:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;1)  How do I convert my vertex and index buffers to one of those file formats?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;2)  For changing the models world space in the viewer, isn’t that done by changing the view matrix before uploading the model? &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Also, if this can be done in standard 3D modeling application, that would be ideal. All I want to do is view the models in relation to each other. I haven’t been able to find any applications that accept vertex and index buffers in raw form though. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="11412" LastActivityDate="2020-06-10T12:23:22.380" Title="Converting Vertex and Index buffers to a File Format" Tags="&lt;rendering&gt;&lt;transformations&gt;&lt;directx&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9918" PostTypeId="1" AcceptedAnswerId="9976" CreationDate="2020-06-05T00:37:19.637" Score="1" ViewCount="81" Body="&lt;p&gt;In section 4.2 of this paper:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://cseweb.ucsd.edu/%7Eravir/274/15/papers/a209-xu.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://cseweb.ucsd.edu/~ravir/274/15/papers/a209-xu.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Xu et al approximate the product of 2 anisotropic Gaussian distributions. I want to know if someone has found not an approximation but THE solution to what the resulting ASG distribution is after taking the product.&lt;/p&gt;&#xA;&lt;p&gt;EDIT:&lt;/p&gt;&#xA;&lt;p&gt;The goal is to either show (or prove it's not possible) that given 2 arbitrary ASG's their product is a third ASG with specified lobe &lt;span class=&quot;math-container&quot;&gt;$\bar z$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-06-23T21:43:49.830" LastActivityDate="2020-06-24T12:55:58.213" Title="Has anyone found an analytic solution to the product of spherical gaussians from Xu et al?" Tags="&lt;rendering&gt;&lt;geometry&gt;&lt;hemisphere&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9919" PostTypeId="1" CreationDate="2020-06-07T05:39:25.920" Score="0" ViewCount="93" Body="&lt;p&gt;Given a set of human body mesh {S_i}, for each S_i, the points are N*3, we can do PCA on that. We can use PCA to reduce the dimension of {S_i}, for example to k dimension. Let the main direction of PCA be [D1, D2, ..., Dk], then the body geometry can be represented by S = W1 * D1 + W2 * D2 + ... + Wk * Dk, where W = [W1, W2, ..., W3] is the weights.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;But how can we get the weight W of one specific mesh S_i in {S_i}?&lt;/p&gt;&#xA;" OwnerUserId="13508" LastActivityDate="2021-03-07T12:06:50.870" Title="How to use PCA to reconstruct 3D Mesh？" Tags="&lt;mesh&gt;&lt;processing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9920" PostTypeId="1" AcceptedAnswerId="9921" CreationDate="2020-06-07T10:05:15.583" Score="0" ViewCount="49" Body="&lt;p&gt;I have following structure which i use as an uniform buffer object.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;struct GlobalShaderData&#xA;{&#xA;    #define CLUSTER_X_MAX 16&#xA;    #define CLUSTER_Y_MAX 8&#xA;    #define CLUSTER_Z_MAX 8&#xA;    #define CLUSTER_MAX_LIGHTS 4&#xA;    int pointLightIndices[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX * CLUSTER_MAX_LIGHTS];&#xA;    int pointLightsPerTile[CLUSTER_X_MAX * CLUSTER_Y_MAX * CLUSTER_Z_MAX];&#xA;};&#xA;GlobalShaderData globalShaderData;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;The total size of the first int array should be 4 bytes * 16 * 8 * 8 * 4 = 16384 bytes, thus the maximum ubo memory is not exceeded.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;However, when compiling the shaders I receive an &quot;out of resource&quot; error message.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I guess the integer actually takes 16 bytes on the glsl side to align with a vec4.&#xA;Because if we calculate with 16 bytes * 16 * 8 * 8 * 4 = 65536 bytes, which just exceedes the maximum capacity.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;What are my options to have an smaller integer array on glsl side.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;(I know that I could use other storage buffers but thats not relevant to the question.)&lt;/p&gt;&#xA;" OwnerUserId="10188" LastActivityDate="2020-06-08T04:06:26.570" Title="Force int array to compact memory" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;memory&gt;&lt;uniform-buffer-object&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9921" PostTypeId="2" ParentId="9920" CreationDate="2020-06-08T04:06:26.570" Score="0" Body="&lt;p&gt;Assuming you use this structure within an actual UBO (which your example code doesn't do), just use an array of &lt;code&gt;ivec4&lt;/code&gt; and two indices.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;const ivec3 cluster_max = ivec3(16, 8, 8);&#xA;const int cluster_max_lights = 4;&#xA;&#xA;const int plix_count = cluster_max.x * cluster_max.y * cluster_max.z * cluster_max_lights;&#xA;const int plix_index_size = pl_count / 4;&#xA;&#xA;const int plpt_count = cluster_max.x * cluster_max.y * cluster_max.z;&#xA;const int plpt_index_size = plpt_count / 4;&#xA;&#xA;struct GlobalShaderData&#xA;{&#xA;    ivec4 pointLightIndices[plix_index_size];&#xA;    ivec4 pointLightsPerTile[plpt_index_size];&#xA;};&#xA;&#xA;layout(std140) uniform shaderData&#xA;{&#xA;    GlobalShaderData globalShaderData;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;To access a value from the arrays, you will have to divide the index by 4 to get the &lt;code&gt;ivec4&lt;/code&gt; index, then take the original index mod 4 and use that to index the &lt;code&gt;ivec4&lt;/code&gt;.&#xA;To get the &lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-06-08T04:06:26.570" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9922" PostTypeId="1" AcceptedAnswerId="9928" CreationDate="2020-06-08T17:36:24.483" Score="2" ViewCount="83" Body="&lt;p&gt;I am trying to get up to speed with the NV_mesh_shader extension from NVidia (on my RTX2080). Samples are rare, so I tried to come up with my own small sample.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I am rendering a sphere (20 triangles) using an index buffer and a vertex buffer. I can render it the &quot;usual&quot; way using &quot;vertex pulling&quot; with two shader storage buffers, one for vertices, one for indices, (like I want to do it with a mesh shader) just fine.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;When using a mesh shader (no task shader so far) I get the following problem: calling &lt;code&gt;glDrawMeshTaskNV(0,1)&lt;/code&gt;with the mesh shader set to &lt;code&gt;layout(local_size_x=20) in&lt;/code&gt; I only get a single triangle rendered. It looks like the mesh shader is not being invoked 20 times as I think it should?&#xA;If I call &lt;code&gt;glDrawMeshTaskNV(0,20)&lt;/code&gt; and set &lt;code&gt;layout(local_size_x=1) in&lt;/code&gt; it renders just fine with nothing else changed in the shader. I use &lt;code&gt;gl_GlobalInvocationID.x&lt;/code&gt; to pull the proper vertices for a triangle.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the complete shader for the non-working variant:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;#extension GL_NV_mesh_shader : require&#xA;&#xA;#define GROUP_SIZE 20&#xA;// mesh shader setup&#xA;layout(local_size_x=GROUP_SIZE) in;&#xA;&#xA;layout(max_vertices=3, max_primitives=1) out;&#xA;layout(triangles) out;&#xA;&#xA;// vertex/index data setup&#xA;struct Vertex&#xA;{&#xA;    vec4 position;&#xA;    vec4 uv;&#xA;};&#xA;&#xA;layout(std430, binding=1) readonly buffer vertex_data&#xA;{&#xA;    Vertex vertex[];&#xA;};&#xA;&#xA;layout(std430, binding=2) readonly buffer index_data&#xA;{&#xA;    uint indices[];&#xA;};&#xA;&#xA;uniform mat4 model;&#xA;uniform mat4 view;&#xA;uniform mat4 projection;&#xA;&#xA;// mesh output&#xA;out gl_MeshPerVertexNV {&#xA;    vec4 gl_Position;&#xA;} gl_MeshVerticesNV[];&#xA;&#xA;&#xA;out uint gl_PrimitiveCountNV;&#xA;out uint gl_PrimitiveIndicesNV[];&#xA;&#xA;void main()&#xA;{&#xA;    // get starting index&#xA;    const uint primitive_start_index = gl_GlobalInvocationID.x * 3;&#xA;&#xA;    uint index_A = indices[primitive_start_index];&#xA;    uint index_B = indices[primitive_start_index+1];&#xA;    uint index_C = indices[primitive_start_index+2];&#xA;&#xA;    // get vertices&#xA;    vec3 A = vertex[index_A].position.xyz;&#xA;    vec3 B = vertex[index_B].position.xyz;&#xA;    vec3 C = vertex[index_C].position.xyz;&#xA;&#xA;    gl_MeshVerticesNV[0].gl_Position = projection * (view * (model * vec4(A, 1.0)));&#xA;    gl_MeshVerticesNV[1].gl_Position = projection * (view * (model * vec4(B, 1.0)));&#xA;    gl_MeshVerticesNV[2].gl_Position = projection * (view * (model * vec4(C, 1.0)));&#xA;&#xA;    gl_PrimitiveIndicesNV[0] = 0;&#xA;    gl_PrimitiveIndicesNV[1] = 1;&#xA;    gl_PrimitiveIndicesNV[2] = 2;&#xA;&#xA;    gl_PrimitiveCountNV += 1;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Keep in mind this is only a learning sample, I know this is maybe overkill for a mesh shader :)&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Thanks for any hints.&#xA;pettersson&lt;/p&gt;&#xA;" OwnerUserId="13515" LastActivityDate="2020-06-09T16:52:35.717" Title="OpenGL task/mesh shader extension NV_mesh_shader not behaving as I expected" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9923" PostTypeId="1" AcceptedAnswerId="9925" CreationDate="2020-06-08T23:28:03.537" Score="0" ViewCount="46" Body="&lt;p&gt;Digital painting and raster graphics software like Krita and Photoshop have a canvas where you can paint with brushes. From a programming perspective, how is this canvas rendered? Can it be included on a graphics pipeline like OpenGL?&lt;/p&gt;&#xA;&#xA;&lt;p&gt;One proposed solution is to represent the canvas as a texture. If you know more possible solutions let me know. Thanks.&lt;/p&gt;&#xA;" OwnerUserId="13517" LastEditorUserId="13517" LastEditDate="2020-06-09T12:36:44.847" LastActivityDate="2020-06-09T12:36:44.847" Title="How are digital painting canvas rendered?" Tags="&lt;rendering&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9925" PostTypeId="2" ParentId="9923" CreationDate="2020-06-09T07:45:10.237" Score="0" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;Digital painting and raster graphics software like Krita and Photoshop have a canvas where you can paint with brushes. From a programming perspective, how is this canvas rendered?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;I don't have access to the code of the programs you mentioned, so I can't tell how exactly they did this since there are usually multiple ways to solve a programming problem. However, I guess everybody with some graphics programming experience will immediately think of the solution @lightxbulb already mentioned in his comment because it is the simplest one.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Textures are just an array of color values and a graphics API like OpenGL expects you to upload them as such. So a possible solution would be to represent your modifiable canvas in memory in this form too. Every time a modification is made, you find the affected pixels in your array, adjust their color values, and upload the updated canvas as texture (or update the already existing one). Then you just draw a fullscreen (or any other size you like) quad and attach the texture to it. Simple as that.&lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Can it be included on a graphics pipeline like OpenGL?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;As you might already guess: Yes, you can do that. If you use the texture approach, you can do anything you can do with an ordinary texture in the graphics pipeline. If your intention is to include a canvas in a 3d game, then keep in mind that finding the pixel that should be modified gets a little bit more complicated due to the perspective projection. However, the rendering process stays the same.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-06-09T07:45:10.237" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9926" PostTypeId="1" CreationDate="2020-06-09T12:32:02.030" Score="1" ViewCount="396" Body="&lt;p&gt;I'm trying to create some graphic functions for a ZX Spectrum (Z80) machine in assembler. I already have the basics except for the arc.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I need a fast algorithm to draw an arc, ideally one that uses integer or fixed point math.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know there must be some way to draw an arc using the Bresenham's circle algorithm but I'm unable to find concrete info about it, there are sentences like &quot;set the pixels only if they fall into the wanted interval&quot; but I have no clue on how to determine if the pixels fall within it.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I only miss how to determine if a pixel lies in the arc, if the algorithm were completely linear (start at 0º and sweep to 360º) it would be easy to skip pixels until the start point and then continue drawing until the last point is reached, but the Bresenham's algorithm is drawn in octants simultaneously so I have no idea on how to do it. Also I had the idea to compute the circle's area in pixels and then divide 360 by the number of pixels to know how many degrees a pixel represents so I could use the start and end angle and check if a pixel must be drawn or not, but it does not work as the computed area is ideal and not the real one that Bresenham's algorithm generates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;As input data I have the circle's center and radius and the start and end points of the arc in the circle (I can derive the start and end angle from those, no problem), I'm not tied to anything so any other algorithm is welcome, no need to be specifically for the spectrum, just any assembler algorithm to draw an arc using integer or fixed point math  will be enough even if I need different info (like the three point arc algorithm).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Cheers.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;em&gt;EDIT&lt;/em&gt;: I already have the circle's implementation, in C and assembler, I only need to determine what pixels of the circle belong to the arc to skip the ones that doesn't belong.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here is the assembler implementation:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;;--------------CIRCLE ROUTINE&#xA;; Plot function isn't included as it's very specific for the ZX Spectrum&#xA;;because of the way the video memory is mapped and it's irrelevant to the question&#xA;&#xA;CENTER_X: .defb 0        ;Input parameter&#xA;CENTER_Y: .defb 0        ;Input parameter&#xA;RADII: .defb 0           ;Input parameter&#xA;&#xA;CIRCLE_D: .defw 0        ;Temp variable&#xA;CIRCLE_D_SIGN: .defb 0   ;Temp variable&#xA;&#xA;&#xA;Draw_Circle:            ;D = X, E = Y&#xA;&#xA;LD DE, 5&#xA;LD A, (RADII)&#xA;LD L, A&#xA;LD H, 0&#xA;&#xA;&#xA;OR A&#xA;ADD HL, HL &#xA;ADD HL, HL&#xA;EX DE, HL&#xA;SBC HL, DE&#xA;JP P, POS_VAL&#xA;LD A, -1&#xA;LD (CIRCLE_D_SIGN), A&#xA;&#xA;;NEG HL&#xA;xor a&#xA;sub l&#xA;ld l,a&#xA;sbc a,a&#xA;sub h&#xA;ld h,a&#xA;&#xA;&#xA;LD C, 4&#xA;CALL HL_Div_C&#xA;&#xA;;NEG HL&#xA;xor a&#xA;sub l&#xA;ld l,a&#xA;sbc a,a&#xA;sub h&#xA;ld h,a&#xA;&#xA;JR D_DONE&#xA;POS_VAL:&#xA;LD A, 1&#xA;LD (CIRCLE_D_SIGN), A&#xA;LD C, 4&#xA;CALL HL_Div_C&#xA;D_DONE:&#xA;LD (CIRCLE_D), HL&#xA;&#xA;&#xA;LD D, 0&#xA;LD A, (RADII)&#xA;LD E, A&#xA;&#xA;CIRCLE_LOOP:&#xA;&#xA;LD A, (CENTER_X)&#xA;LD H, A&#xA;LD A, (CENTER_Y)&#xA;LD L, A&#xA;&#xA;;seq x.X/y.Y&#xA;&#xA;LD A, H             ;center_x&#xA;ADD A, D                ;x&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;ADD A, E                ;y&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;LD A, H             ;center_x&#xA;ADD A, D                ;x&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;SUB A, E                ;y&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;LD A, H             ;center_x&#xA;SUB A, D                ;x&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;ADD A, E                ;y&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;LD A, H             ;center_x&#xA;SUB A, D                ;x&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;SUB A, E                ;y&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;;seq x.Y/y.X&#xA;&#xA;LD A, H             ;center_x&#xA;ADD A, E                ;y&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;ADD A, D                ;x&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;&#xA;LD A, H             ;center_x&#xA;ADD A, E                ;y&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;SUB A, D                ;x&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;LD A, H             ;center_x&#xA;SUB A, E                ;y&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;ADD A, D                ;x&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH HL&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;POP HL&#xA;&#xA;LD A, H             ;center_x&#xA;SUB A, E                ;y&#xA;LD C, A             ;point_x&#xA;LD A, L             ;center_y&#xA;SUB A, D                ;x&#xA;LD B, A             ;point_y&#xA;&#xA;PUSH DE&#xA;CALL Plot&#xA;POP DE&#xA;&#xA;&#xA;LD HL, (CIRCLE_D)               ;if (d &amp;lt; 0)&#xA;LD A, (CIRCLE_D_SIGN)&#xA;CP -1&#xA;JR Z, NEGATIVE_D&#xA;&#xA;&#xA;&#xA;POSITIVE_D:                     ;no&#xA;PUSH DE&#xA;PUSH HL&#xA;LD L, D&#xA;LD H, 0&#xA;LD D, 0&#xA;XOR A&#xA;SBC HL, DE&#xA;ADD HL, HL&#xA;INC HL&#xA;POP DE&#xA;ADD HL, DE&#xA;POP DE&#xA;&#xA;LD A, H                         ;is negative?&#xA;CP #FF&#xA;JP NZ, POS_VAL_POS&#xA;LD A, -1                        ;yes&#xA;LD (CIRCLE_D_SIGN), A&#xA;JP DEC_Y&#xA;&#xA;POS_VAL_POS:                    ;no&#xA;LD A, 1&#xA;LD (CIRCLE_D_SIGN), A&#xA;&#xA;DEC_Y:&#xA;DEC E&#xA;JP STORE_D&#xA;&#xA;NEGATIVE_D:&#xA;PUSH HL&#xA;LD L, D&#xA;LD H,0&#xA;ADD HL, HL&#xA;INC HL&#xA;&#xA;LD A, D                     ;2 * x&#xA;ADD A, A&#xA;INC A                       ; + 1&#xA;&#xA;LD C, A&#xA;LD B, 0&#xA;POP HL&#xA;ADD HL, BC                  ;d = d +&#xA;&#xA;LD A, H                     ;is negative?&#xA;CP #FF&#xA;JP NZ, POS_VAL_NEG&#xA;&#xA;LD A, -1                    ;yes&#xA;LD (CIRCLE_D_SIGN), A&#xA;JP STORE_D&#xA;&#xA;POS_VAL_NEG:&#xA;LD A, 1                 ;no&#xA;LD (CIRCLE_D_SIGN), A&#xA;&#xA;STORE_D:&#xA;INC D&#xA;LD (CIRCLE_D), HL&#xA;&#xA;&#xA;TEST_LOOP:&#xA;LD A, E&#xA;CP D&#xA;JP P, CIRCLE_LOOP&#xA;&#xA;RET&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13522" LastEditorDisplayName="user7220" LastEditDate="2020-06-10T22:33:44.597" LastActivityDate="2021-03-07T23:02:45.330" Title="Using Bresenham's circle algorithm (or another alternative algorithm) to draw an arc" Tags="&lt;drawing&gt;&lt;assembly&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9927" PostTypeId="1" AcceptedAnswerId="9929" CreationDate="2020-06-09T16:48:17.420" Score="2" ViewCount="40" Body="&lt;p&gt;I am reading &quot;Image Processing and Analysis&quot; by Chan and Shen, c 2005 SIAM. They introduce some notation I'm not 100% sure how to interpret:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ u_0(x)=u(x)+n(x),  x=(x_1,x_2) \in \Omega $$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;They state &lt;span class=&quot;math-container&quot;&gt;$u_0$&lt;/span&gt; represents a noisy image, &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; is the clean image and &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is Gaussian white noise. I assume that &lt;span class=&quot;math-container&quot;&gt;$ x=(x_1,x_2) $&lt;/span&gt; is meant to convey that x is a two-dimensional vector indexing both image height and width. I don't know how to interpret &lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt;. Is it meant to denote the entire image index range? &lt;/p&gt;&#xA;" OwnerUserId="13524" LastActivityDate="2020-06-09T19:07:03.113" Title="Interpreting Image Processing Math Equation" Tags="&lt;image-processing&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9928" PostTypeId="2" ParentId="9922" CreationDate="2020-06-09T16:52:35.717" Score="3" Body="&lt;p&gt;I managed to figure it out. A coworker told me that I was misinterpreting the documentation.&#xA;&lt;code&gt;layout(max_vertices=3, max_primitives=1) out;&lt;/code&gt;&#xA;actually means max_vertices and max_primitives per workgroup, not per shader invocation. So I was always only outputting a single triangle, regardless of what I set &lt;code&gt;local_size_x&lt;/code&gt; to.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Changing the values to proper numbers resulted in a proper rendering.&lt;/p&gt;&#xA;" OwnerUserId="13515" LastActivityDate="2020-06-09T16:52:35.717" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9929" PostTypeId="2" ParentId="9927" CreationDate="2020-06-09T18:30:44.320" Score="3" Body="&lt;p&gt;It sounds exactly like that!&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt; is the image domain, it can be either discrete or continuous. No idea how it is defined in that particular book.&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$x=(x_1, x_2)$&lt;/span&gt; are the 2D image coordinates&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$u_0, u, n$&lt;/span&gt; are functions that return intensity values at the given location &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="13370" LastEditorUserId="13370" LastEditDate="2020-06-09T19:07:03.113" LastActivityDate="2020-06-09T19:07:03.113" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9930" PostTypeId="2" ParentId="9919" CreationDate="2020-06-10T10:27:28.267" Score="0" Body="&lt;p&gt;Given a matrix &lt;span class=&quot;math-container&quot;&gt;$D \in \mathbb{R}^{3N\times k}$&lt;/span&gt; where each column is normalized &lt;span class=&quot;math-container&quot;&gt;$D_i$&lt;/span&gt;, You can get &lt;span class=&quot;math-container&quot;&gt;$W = D^TS_i$&lt;/span&gt;, and later it can be used to reconstruct the shape with &lt;span class=&quot;math-container&quot;&gt;$S_i = DW$&lt;/span&gt; (With some error if you truncated some basis). The acquisition of weights is equivalent to calculating dot products between each PCA basis and &lt;span class=&quot;math-container&quot;&gt;$S_i$&lt;/span&gt;. What is done here is you project &lt;span class=&quot;math-container&quot;&gt;$S_i$&lt;/span&gt; onto each orthogonal basis &lt;span class=&quot;math-container&quot;&gt;$D_i$&lt;/span&gt;, and calculate the length of the projected vector, so you are basically calculating the required contribution of each basis to construct the given &lt;span class=&quot;math-container&quot;&gt;$S_i$&lt;/span&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If you are using unnormalized PCA basis, you can decompose the unnormalized PCA basis matrix into a diagonal matrix an an orthonormal matrix (Say, &lt;span class=&quot;math-container&quot;&gt;$\Lambda D$&lt;/span&gt;), then use a similar approach to obtain the contribution of each basis. In this case, you'll have to use &lt;span class=&quot;math-container&quot;&gt;$\Lambda^{-1}D^T$&lt;/span&gt; instead of &lt;span class=&quot;math-container&quot;&gt;$D^T$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="13305" LastEditorUserId="13305" LastEditDate="2020-06-10T10:39:21.743" LastActivityDate="2020-06-10T10:39:21.743" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9931" PostTypeId="1" CreationDate="2020-06-10T11:10:32.843" Score="0" ViewCount="53" Body="&lt;p&gt;In the &lt;a href=&quot;https://www.unrealengine.com/en-US/blog/a-first-look-at-unreal-engine-5&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unreal Engine 5&lt;/a&gt; tech demo, they mention, that there is no need to manually generate LOD levels for each model, because the on the fly LOD system will generate polygons from the original mesh, which are around one pixel in size.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to search for &quot;on the fly LOD&quot;, but I was not able to find anything useful.&lt;/p&gt;&#xA;" OwnerUserId="7028" LastActivityDate="2020-06-10T15:03:35.377" Title="How does on the fly LOD work?" Tags="&lt;algorithm&gt;&lt;geometry&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9932" PostTypeId="2" ParentId="9917" CreationDate="2020-06-10T12:23:22.380" Score="3" Body="&lt;p&gt;No idea about DirectX, but in OpenGL the buffers are just &lt;a href=&quot;https://en.wikipedia.org/wiki/Vertex_buffer_object&quot; rel=&quot;nofollow noreferrer&quot;&gt;a block of binary data&lt;/a&gt; so you can easily load and save them.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In any 3D framework, changing the object position to achieve a different relative arrangement of a scene is not done through the &lt;em&gt;view&lt;/em&gt; matrix (that represents the camera position and viewing direction) but through the &lt;em&gt;model&lt;/em&gt; matrix of each model. Note that the vertex and index buffers stay unaffected by matrix transformations, that is the main benefit of such pipelines.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Perhaps you could do your study with less effort using a 3D game engine, to list just a few:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://godotengine.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://godotengine.org/&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www.unrealengine.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.unrealengine.com/&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://unity.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://unity.com/&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;I am not aware that any of them would support loading the raw buffers straight away, but they can load &lt;a href=&quot;https://en.wikipedia.org/wiki/Wavefront_.obj_file&quot; rel=&quot;nofollow noreferrer&quot;&gt;OBJ files&lt;/a&gt;. OBJ is one of the oldest text-based 3D model formats. It has a simple structure, so you can easily convert your buffer data to an OBJ file.&lt;/p&gt;&#xA;" OwnerUserId="13370" LastActivityDate="2020-06-10T12:23:22.380" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9934" PostTypeId="2" ParentId="9926" CreationDate="2020-06-10T16:42:35.930" Score="0" Body="&lt;p&gt;This morning I was thinking about how I would tackle the problem:&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Draw a circle of radius R and origin (H, K)&lt;/li&gt;&#xA;&lt;li&gt;Using integer math&lt;/li&gt;&#xA;&lt;li&gt;No anti-aliasing&lt;/li&gt;&#xA;&lt;li&gt;Speed is important&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;The first thing I noticed is if we assume (H, K) is (0,0), there is 8-way symmetry in the problem. That means if I find a pixel (x, y) between 0° and 45°, I already know 7 more pixel locations:&lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;pixel (x, y) is between 0° and 45°&lt;/li&gt;&#xA;&lt;li&gt;pixel (y, x) is between 45° and 90°&lt;/li&gt;&#xA;&lt;li&gt;pixel (-y, x) is between 90° and 135°&lt;/li&gt;&#xA;&lt;li&gt;pixel (-x, y) is between 135° and 180°&lt;/li&gt;&#xA;&lt;li&gt;pixel (-x, -y) is between 180° and 225°&lt;/li&gt;&#xA;&lt;li&gt;pixel (-y, -x) is between 225° and 270°&lt;/li&gt;&#xA;&lt;li&gt;pixel (y, -x) is between 270° and 315°&lt;/li&gt;&#xA;&lt;li&gt;pixel (x, -y) is between 315° and 360°&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;Because the tangent line to the circle between 0° and 45° has as slope less than -1, there is exactly 1 integer x value for any y value in that range. We find the x values for all &lt;span class=&quot;math-container&quot;&gt;$ y \in [0, \frac{\sqrt{2}}{2} R ]$&lt;/span&gt;, plot them using symmetry, and we're done.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;In Python it the algorithm would look like this:&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;def circle(h, k, r):&#xA;    d=round( r* math.sqrt(2)/2 ) # find the 45 degree value&#xA;    r2=r**2 # square r&#xA;    p=r&#xA;&#xA;    for y in range(0, d+1): &#xA;#####   x=round(math.sqrt(r2 - y*y ))&#xA;        q=(r2-p*p-y*y)&#xA;        if( q &amp;lt; -p):&#xA;            p-=1&#xA;        x=p&#xA;        setPixel(h+x, k+y)&#xA;        setPixel(h+y, k+x)&#xA;        setPixel(h-y, k+x)&#xA;        setPixel(h-x, k+y)&#xA;        setPixel(h-x, k-y)&#xA;        setPixel(h-y, k-x)&#xA;        setPixel(h+y, k-x)&#xA;        setPixel(h+x, k-y)&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13524" LastEditorUserId="13524" LastEditDate="2020-06-10T18:53:34.297" LastActivityDate="2020-06-10T18:53:34.297" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9935" PostTypeId="1" CreationDate="2020-06-11T10:11:07.303" Score="0" ViewCount="40" Body="&lt;p&gt;I am trying to get a segment closest point on a surface and display a circle (or sphere in this case) at that position.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I actually get the correct position but I can't get a uniform sphere based on the computed data.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fdhyQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fdhyQ.jpg&quot; alt=&quot;enter image description here&quot;&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here's the associated code I use to find the intersection point and draw the sphere.&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;float3 a = from;&#xA;float3 b = to;&#xA;float3 c = worldPosition;&#xA;&#xA;float3  ab = b - a;&#xA;float t = dot(c - a, ab) / dot(ab, ab);&#xA;float3 point = a + saturate(t) * ab;&#xA;&#xA;return length(point - worldPosition) - radius;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2020-06-11T13:09:36.263" Title="Closest sphere on segment" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;mathematics&gt;&lt;hlsl&gt;&lt;signed-distance-field&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9936" PostTypeId="2" ParentId="9935" CreationDate="2020-06-11T11:52:32.100" Score="2" Body="&lt;p&gt;Your &lt;em&gt;actual&lt;/em&gt; result is correct in terms of what you can achieve in a single-pass with a fragment shader. It calculates the distance of the fragment's world position to the line segment. That distance is &lt;strong&gt;different for each fragment&lt;/strong&gt; so the stretched black ellipsoid is the correct output.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;A fragment shader has only local information about the current fragment being processed. You can't do more with that. Your &lt;em&gt;expected&lt;/em&gt; result requires some global knowledge about the scene, since you are searching for the &lt;strong&gt;minimum distance across the whole surface&lt;/strong&gt;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Without any thoughts on optimization, the naive solution path should involve contextual computation of local minima of the fragment-to-linesegment distance. In order to get such context, you need to compute the distance field first and then access it to find the local minima in a separate pass.&lt;/p&gt;&#xA;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Compute the raw distance field in the first pass (same as your example but no &lt;code&gt;radius&lt;/code&gt; subtraction at the end.&lt;/li&gt;&#xA;&lt;li&gt;Mark the pixels with local minima in the second pass (e.g. by setting the alpha channel to 1). This will be screen-space pass. The best is to have a &lt;code&gt;rgba&lt;/code&gt; float texture at output with &lt;code&gt;rgb&lt;/code&gt; being fragment's world position and &lt;code&gt;a&lt;/code&gt; being 1 for local minima and &lt;code&gt;0&lt;/code&gt; else.&lt;/li&gt;&#xA;&lt;li&gt;Paint the black circles/spheres in a third pass (also screen-space).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&#xA;&lt;p&gt;Having the information about the local minimum of your distance function enables you to output the right shape for around the minima in the last pass. In pseudocode:&lt;/p&gt;&#xA;&#xA;&lt;pre class=&quot;lang-glsl prettyprint-override&quot;&gt;&lt;code&gt;vec4 worldPos = tex2D(distance_texture, frag.x, frag.y);&#xA;if (worldPos.a &amp;gt; 0.5) //is minimum&#xA;    return vec3(0,0,0);&#xA;else&#xA;{&#xA;    //Sample the screen-space neighborhood in larger and larger circles&#xA;    // until a fragment with distance.a == 1 is found&#xA;    // or until all fragments are more than radius away (in world coords).&#xA;&#xA;    //Minimum world space distance of any sampled fragment.&#xA;    float minDist = 0.0;&#xA;    int iter = 1;&#xA;    //Search for a local minimum until all fragments are more than radius away,&#xA;    // since then even if a local minimum gets found it will no longer produce&#xA;    // the black shading.&#xA;    while (minDist &amp;lt; radius &amp;amp;&amp;amp; minDist &amp;gt;= 0.0 &amp;amp;&amp;amp; iter &amp;lt; Math.Max(screenWidth, screenHeight))&#xA;        minDist = sampleNeighborhood(iter++, worldPos);&#xA;&#xA;    if (minDist &amp;lt; 0.0) //found a local minimum&#xA;        return vec3(0,0,0);&#xA;    else&#xA;        return vec3(1,1,1); //or any other computed shading&#xA;&#xA;    //I am aware that the function call above checks central fragments several times.&#xA;    //That should be of course optimized in production code.&#xA;}&#xA;&#xA;float sampleNeighborhood(int neigh, vec4 worldPos)&#xA;{&#xA;    float minDist = float.MaxValue;&#xA;    for(int x = Math.max(0, frag.x - neigh); x &amp;lt;= Math.Min(screenWidth, frag.x + neigh; ++x)&#xA;        for(int y = Math.max(0, frag.y - neigh); x &amp;lt;= Math.Min(screenHeight, frag.y + neigh; ++y)&#xA;        {&#xA;            float p = tex2D(distance_texture, x, y);&#xA;            float d = distance(p.xyz, worldPos.xyz);&#xA;            if (p.a &amp;gt; 0.5 &amp;amp;&amp;amp; d &amp;lt;= radius)&#xA;                //Return negative distance to indicate a local minimum was found.&#xA;                return -1.0; &#xA;            else&#xA;                minDist = Math.min(minDist, d);&#xA;        }&#xA;    return minDist;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;Finding the local minima in the second pass is much easier, since you only need to sample the local 3x3 neighborhood.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I hope that helps you in reaching the desired rendering!&lt;/p&gt;&#xA;" OwnerUserId="13370" LastEditorUserId="13370" LastEditDate="2020-06-11T13:09:36.263" LastActivityDate="2020-06-11T13:09:36.263" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9937" PostTypeId="1" CreationDate="2020-06-11T13:10:23.247" Score="2" ViewCount="46" Body="&lt;p&gt;During radiation therapy, appropriate radiation is fired from various positions around the patient. Radiation therapy planning determines the values of the radiation at various positions. This optimization problem requires a huge matrix, whose elements are the doses deposited by unit strength beamlets at all possible positions around the patient at all the voxels of the patient volume. Thus each pair of beamlet and voxel has an entry in this matrix. This matrix is generally referred to by the following names: dose deposition matrix/dose influence matrix/dose information matrix.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get an idea about what algorithms can be used for dose calculation, this paper is good starting point:&#xA;&lt;a href=&quot;https://www.researchgate.net/profile/Thomas_Krieger3/publication/7938276_Monte_Carlo-_versus_pencil-beam-collapsed-cone-dose_calculation_in_a_heterogeneous_multi-layer_phantom/links/544a1ed50cf244fe9ea63062.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Monte Carlo- versus pencil-beam-/collapsed-cone-dose calculation in a heterogeneous multi-layer phantom&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;To get an idea about how this matrix is subsequently used in radiation therapy, one could look at:&#xA;&lt;a href=&quot;https://pdfs.semanticscholar.org/433e/76872d510585c40ab4f505486a4aae670a02.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real-Time Radiation Treatment Planning with Optimality&#xA;Guarantees via Cluster and Bound Methods&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;The main bottleneck in radiation therapy planning is the computation of this matrix. While searching the literature, it is hard to find ideas from computer graphics (especially, rendering) being used to accelerate the computation of this matrix. Why is it so? Could it be just a lack of communication between the two communities? It appears unlikely, though. The radiation in radiation therapy is different from visible light. However, is it possible to borrow ideas from participating media rendering?&lt;/p&gt;&#xA;" OwnerUserId="9845" LastEditorUserId="9845" LastEditDate="2020-06-12T12:48:35.477" LastActivityDate="2020-06-12T12:48:35.477" Title="Accelerating dose calculation for a radiation therapy planning system" Tags="&lt;rendering&gt;&lt;real-time&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9938" PostTypeId="1" AcceptedAnswerId="9939" CreationDate="2020-06-11T14:11:23.907" Score="5" ViewCount="693" Body="&lt;p&gt;I would like to project the triangles of my mesh to a 2D surface. I would like to minimalize the distorion, avoid breaking connected polygons if possible, and also maximalize the used space on the 2D surface.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I tried to look for algorithms/papers about the topic, but I can only find articles about how to use UV unwrapping in 3D modelling softwares like Blender.&lt;/p&gt;&#xA;" OwnerUserId="7028" LastActivityDate="2020-06-11T15:28:46.117" Title="How does UV unwrapping work?" Tags="&lt;geometry&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9939" PostTypeId="2" ParentId="9938" CreationDate="2020-06-11T15:28:46.117" Score="8" Body="&lt;p&gt;UV unwrapping is a difficult topic. They can be both combinatorial algorithms or variational methods but in general they're optimization based, i.e. you setup an optimization problem and you solve it using some numerical optimization solver. I'm just going to give you some names and some libraries you can use eventually. I'll give you few names (both classic and more recent) and you can have a look yourself. ABF (Angle Based Flattening), LSCM (Least Square Conformal Mapping), ARAP (As rigid as possible), BFF (Boundary first flattening), Variational Surface Cutting, OptCuts.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;For ARAP and LSCM you can use &lt;a href=&quot;https://libigl.github.io/&quot; rel=&quot;noreferrer&quot;&gt;libigl&lt;/a&gt;. &lt;a href=&quot;https://github.com/GeometryCollective/boundary-first-flattening&quot; rel=&quot;noreferrer&quot;&gt;Boundary first flattening&lt;/a&gt; was developed by Keenan Crane few years ago. &lt;a href=&quot;https://github.com/nmwsharp/variational-surface-cutting&quot; rel=&quot;noreferrer&quot;&gt;Variational surface cutting&lt;/a&gt; is an improvement over BFF. And I recently discovered &lt;a href=&quot;https://github.com/liminchen/OptCuts&quot; rel=&quot;noreferrer&quot;&gt;OptCuts&lt;/a&gt;. The code is available and you can run them yourself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;You need to read through the papers to understand how they works if you wanted to implement them from scratch (not going to be easy, parametrization is a difficult subject). But if you want to just to run them just clone the repos and try them yourself.&#xA;(libigl comes with tutorials, and two of these are about ARAP and LSCM). BFF, Variational Surface Cutting and OptCuts have a GUI based app so you can see the unwrapping and you can easily isolate the code if you need them in your own code.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2020-06-11T15:28:46.117" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9941" PostTypeId="2" ParentId="9887" CreationDate="2020-06-12T16:26:41.750" Score="2" Body="&lt;blockquote&gt;&#xA;  &lt;p&gt;I target mobile/tablet devices with my product&#xA;  this is less of a concern with desktop GPUs. &#xA;  unity and unreal allowing full flexibility on adding shaders &amp;amp; materials at-will&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;Well, Unity and Unreal can also be used to make games targetting mobile/tablet devices, right?&lt;br&gt;&#xA;Do you think you can throw at them all the shaders &amp;amp; materials you want, and expect them to magically output a performant application every time?&lt;br&gt;&#xA;Try to do it and you will find that they also struggle at some point.  &lt;/p&gt;&#xA;&#xA;&lt;p&gt;This can also happen on desktop ; the newest smartphones are totally faster than my oldest laptop.   &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;What is the best practice for managing multiple (dozens) of shaders in a scene with many materials?&#xA;  how many parameters are too much?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;The best practice is to test on the real hardware that you are targetting. If you target a wide range of mobile devices, then you have to decide the lowest spec that your product will officially support.&lt;br&gt;&#xA;Then, it is a matter of finding a good balance between performance (few materials/shaders) and visual quality (more variety/complexity).&lt;br&gt;&#xA;If you are comfortable with the process, you can prepare a number of performance profiles based on the type of device that will run your product (lower-end, higher-end?), with better quality for the higher end.  &lt;/p&gt;&#xA;&#xA;&lt;blockquote&gt;&#xA;  &lt;p&gt;Since shaders do have a lot of parameters populated from the model&#xA;  material/mesh and sent down to the fragment shader, I fear that&#xA;  unifying the shaders and passing too many parameters in the VBO each&#xA;  frame/vertex/fragment, would be really bad for performance.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&#xA;&lt;p&gt;You meant Uniform Buffer Object, not Vertex Buffer Object, right?&lt;br&gt;&#xA;I expect that the size of the uniform data that you pass to the GPU is not that big?&lt;br&gt;&#xA;However if your shaders are complex, it could take time for the GPU to execute them. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Here again it is a balance, between the amount of parameters that you pass, and the complexity of the shader, that you have to find.&lt;br&gt;&#xA;You just can try different solutions on real hardware, note down the performance and aspect of each one, and somehow compare them ; to find the optimal solution for your product. &lt;/p&gt;&#xA;" OwnerUserId="110" LastActivityDate="2020-06-12T16:26:41.750" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9942" PostTypeId="1" CreationDate="2020-06-12T22:19:33.667" Score="1" ViewCount="30" Body="&lt;p&gt;So, I would like to do capture on 3d pointclouds of 3d models the planes/vectors where for each object we have the highest variance (i.e. for object represented by 2000 3d points I would like to get vectors or planes along which we have the most variance of points), and I assume PCA can be used to show that per object. Did anyone attempt to do something like that and what kind of other variance capturing methods would you suggest? Do you have any particular python library I can use for this, besides the sklearn one?&lt;/p&gt;&#xA;" OwnerUserId="13298" LastActivityDate="2020-06-12T22:19:33.667" Title="Principal component analysis on 3d points and other ways of capturing variance" Tags="&lt;3d&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9943" PostTypeId="1" AcceptedAnswerId="9944" CreationDate="2020-06-14T08:00:43.193" Score="3" ViewCount="95" Body="&lt;p&gt;I am implementing an algorithm which requires me to compute the following integral,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\int_{Poly(P_i)}||P-P_i||^2 dP$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$P_i=(X_i, Y_i)$&lt;/span&gt; is a point in 2D and &lt;span class=&quot;math-container&quot;&gt;$Poly(P_i)$&lt;/span&gt; is a polygon containing &lt;span class=&quot;math-container&quot;&gt;$P_i$&lt;/span&gt; (it is the Voronoi Cell of &lt;span class=&quot;math-container&quot;&gt;$P_i$&lt;/span&gt; with a certain weight). Could anyone give me some indications on how to compute this quantity?&lt;/p&gt;&#xA;" OwnerUserId="13551" LastActivityDate="2020-06-16T18:01:14.110" Title="How to compute the following integral over a polygon?" Tags="&lt;polygon&gt;&lt;integral&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9944" PostTypeId="2" ParentId="9943" CreationDate="2020-06-14T08:26:27.077" Score="5" Body="&lt;p&gt;Triangulate the Voronoi cell then write the integral as a sum over the triangles:&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\int_{\Omega}\|P - Pi\|\,dP = \sum_{k=1}^{N}\int_{\Delta_k}\|P-P_i\|\,dP.$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Write the integration over the triangle in barycebtric coordinates. Let the Jacobian of the transformation, from barycentric coordinates to physical coordinates, for triangle &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; be &lt;span class=&quot;math-container&quot;&gt;$J_k$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$|det(J_k)| = 2|Area_{\Delta_k}|$&lt;/span&gt;. Then &lt;span class=&quot;math-container&quot;&gt;$\int_{\Delta_k}f(P)\,dP = |det(J_k)|\int_0^1\int_0^{1-\beta}f(P(\alpha, \beta))\,d\beta\,d\alpha$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$\alpha, \beta$&lt;/span&gt; are two of the barycentric coordinates.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Now we need only evaluate (let &lt;span class=&quot;math-container&quot;&gt;$\vec{v}_i$&lt;/span&gt; be the vertices of the current triangle):&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\int_0^1\int_0^{1-\beta}\|\vec{v}_1 + \alpha (\vec{v}_2 - \vec{v}_1) + \beta (\vec{v}_3 - \vec{v}_1) - \vec{P}_i\|^2\,d\alpha\,d\beta$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Expand this and integrate the polynomials. The absolute value of the Jacobian determinant is: &lt;span class=&quot;math-container&quot;&gt;$$|det(J)| = \|(v_2-v_1) \times (v_3 - v_1)\|$$&lt;/span&gt;.&#xA;If you are working in 3D, &lt;span class=&quot;math-container&quot;&gt;$\times$&lt;/span&gt; is the cross product here. If it's 2D then augment the vectors with a &lt;span class=&quot;math-container&quot;&gt;$0$&lt;/span&gt; for &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; and perform the cross product.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Another option is to use a quadrature rule to compute this. For example you can still triangulate, but evaluate the integral over a triangle (let &lt;span class=&quot;math-container&quot;&gt;$f(P) =\|P - P_i\|^2$&lt;/span&gt;) through samples at the edge midpoints:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\int_{\Delta}f(P)\,dP = \frac{|det(J)|}{6}\sum_{k=1}^{3}f\left(\frac{\vec{v}_k + \vec{v}_{k+1}}{2}\right).$$&lt;/span&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;If memory serves me right, the above quadrature is exact for polynomials of up to degree 2 (which is what you have, and the reason I wrote &lt;span class=&quot;math-container&quot;&gt;$=$&lt;/span&gt; instead of &lt;span class=&quot;math-container&quot;&gt;$\approx$&lt;/span&gt;). Note that &lt;span class=&quot;math-container&quot;&gt;$k+1$&lt;/span&gt; is taken to wrap around, that is, for &lt;span class=&quot;math-container&quot;&gt;$k = 3$&lt;/span&gt; I use &lt;span class=&quot;math-container&quot;&gt;$\vec{v}_4 = \vec{v}_1$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2020-06-16T18:01:14.110" LastActivityDate="2020-06-16T18:01:14.110" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9946" PostTypeId="1" CreationDate="2020-06-16T14:04:23.573" Score="3" ViewCount="187" Body="&lt;p&gt;Is there some historical reason texture coordinates are often called UVs? I get that vertex positions are x, y, z but even OpenGL has &lt;code&gt;TEXTURE_WRAP_S&lt;/code&gt; and &lt;code&gt;TEXTURE_WRAP_T&lt;/code&gt; and GLSL has aliases so if texture coord is in a &lt;code&gt;vec&lt;/code&gt; you can access it with&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;someVec.st&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;but not&lt;/p&gt;&#xA;&#xA;&lt;pre&gt;&lt;code&gt;someVec.uv  (these would be the 3rd and 4th elements of the vector)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&#xA;&lt;p&gt;And yet pretty much every modeling package calls them UVs &lt;a href=&quot;https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2018/ENU/Maya-Modeling/files/GUID-73BF7546-3BF2-44F3-9192-15A024CEC173-htm.html#:~:text=The%20UV%20Editor%20lets%20you,in%20the%20Modeling%20menu%20set.&quot; rel=&quot;nofollow noreferrer&quot;&gt;Maya&lt;/a&gt;, &lt;a href=&quot;https://docs.blender.org/manual/en/latest/editors/uv/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender&lt;/a&gt;, &lt;a href=&quot;https://docs.unity3d.com/Packages/com.unity.probuilder@4.0/manual/uv-editor.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unity&lt;/a&gt;, &lt;a href=&quot;https://docs.unrealengine.com/en-US/Engine/Content/Types/StaticMeshes/HowTo/UVChannels/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unreal&lt;/a&gt;, &lt;a href=&quot;https://knowledge.autodesk.com/support/3ds-max/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/3DSMax/files/GUID-A7CC32F5-40BE-4DE5-A364-05E7986D4BA5-htm.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;3dsmax&lt;/a&gt;&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Where does the term UVs come from? Is this a known part of computer graphics history or is the reason they are called UVs lost in pixels of cg time?&lt;/p&gt;&#xA;" OwnerUserId="13560" LastActivityDate="2020-07-01T09:29:54.890" Title="Why are texture coordinates often called UVs?" Tags="&lt;geometry&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9947" PostTypeId="2" ParentId="9946" CreationDate="2020-06-16T14:33:51.780" Score="6" Body="&lt;p&gt;This is not a definitive answer, but it is generally accepted that &lt;a href=&quot;https://en.wikipedia.org/wiki/Edwin_Catmull&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ed Catmull&lt;/a&gt; introduced Texture Mapping in his 1974 thesis, &amp;quot;&lt;a href=&quot;https://ia801307.us.archive.org/2/items/DTIC_ADA004968/DTIC_ADA004968.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;A SUBDIVISION ALGORITHM FOR COMPUTER DISPLAY OF CURVED SURFACES&lt;/em&gt;&lt;/a&gt;&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;In that, he uses (U,V) to access the image data (see the page labeled 36 in the above)&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;MAPPING&lt;br&gt;&#xA;Photographs, drawings, or any picture can be mapped onto bivariate patches. This&#xA;is one of the most interesting consequences of the patch splitting algorithm. It&#xA;gives a method for putting texture, drawings, or photographs onto surfaces....&lt;br&gt;&lt;br&gt;&#xA;...If a photograph is scanned in at a resolution of x times y then every&#xA;element can be referenced by u·x and v·y where 0&amp;lt;=u,v&amp;lt;=1. In general, one could think of the intensity as a function l(u,v) where I references a picture.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I believe this thesis also introduced the concept of the Z-Buffer (Page 32)&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2020-07-01T09:29:54.890" LastActivityDate="2020-07-01T09:29:54.890" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9948" PostTypeId="1" CreationDate="2020-06-17T12:55:28.743" Score="0" ViewCount="36" Body="&lt;p&gt;Thanks a lot for your attention to this question in advance!&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It is my first try to ask for help on this amazing StackExchange. If I do something inappropriate, please point it out directly so that I can correct this question to be better.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Please let me clear my background first: Recently I am investigating the simulation of rigid bodies.It's really interesting! &lt;/p&gt;&#xA;&#xA;&lt;p&gt;Till now, I have implemented 3 different kinds of rigid body/multibody simulators, one of them is by Featherstone method, one of them is by Lagrangian method(Generalized coordinates), and the left one is simply for isolated rigid bodies governed by Newton-Euler equations, respectively。&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I use bullet as a collision detection backend in my simulator and begin to implement the collision resolving algorithms(for example, interactive Sequential Impulse or MLCP problem then solve it by PGS, etc) by myself.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;The question&lt;/strong&gt;: in lots of papers and books, people mentioned 2 different concepts. They say that the rigid body simulation can be roughly classified into &quot;constraint-based&quot; and &quot;impulse-based&quot;, later then they reference some famous papers of Mirtich or David Baraff... For example the book &quot;Physics-based animation&quot; written by Kenny Erleben in 2005, chapter 6 and chapter 7.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;But I really can not get the point. I felt quite hard to distinguish these 2 concepts &quot;constraint-based&quot; and &quot;impulse-based&quot;.&lt;/strong&gt; It nearly drove me crazy. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can use a constraint solver in collision resolving to solve the contact impulse or contact force then push the contacting objects away.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can also use a constraint solver between rigid bodies and make them into a chain connected by joints. &lt;/p&gt;&#xA;&#xA;&lt;p&gt;I can also calculate the force in contact points or user-customed external force and forward the simulation from the second-order &quot;acceleration&quot; term, or vice versa calculate the impulse and drive my simulator from the first-order &quot;velocity&quot;.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Would you kindly please help me to sort out my confused thoughts? :(&lt;/p&gt;&#xA;" OwnerUserId="11814" LastActivityDate="2020-06-17T12:55:28.743" Title="Confusion about the concepts of &quot;constraint-based&quot; and &quot;impulse-based&quot; for rigidbody simulation" Tags="&lt;simulation&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="9949" PostTypeId="1" AcceptedAnswerId="9955" CreationDate="2020-06-17T15:27:00.897" Score="0" ViewCount="313" Body="&lt;p&gt;I'm planning to write a small software rendering engine (before anyone asks, it's kind of a learning/scientific experiment for me).&lt;/p&gt;&#xA;&#xA;&lt;p&gt;Before writing any code, I'm already stuck at the very first step: how to display my framebuffer on the screen? What I'm planning to do is to render into an in-memory buffer e.g. 320x200 24-bit RGB format. Then of course I need to display the results on the screen; full-screen or in a window.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I know that similar questions already exists here: &lt;/p&gt;&#xA;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4648/how-can-i-send-custom-bitmap-to-frame-buffer&quot;&gt;How can I send custom bitmap to frame buffer?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/9923/how-are-digital-painting-canvas-rendered&quot;&gt;How are digital painting canvas rendered?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&#xA;&lt;p&gt;The difference is that I'd like to update the image frequently, with a decent framerate like 50FPS.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;It seems one possibility would be OpenGL framebuffer objects and/or buffer streaming. I'm not sure I should go that way or is it an overkill for this use case?&#xA;I've also considered displaying a simple rectangle with a texture I would update each frame, but I'm not sure about the performance (I guess transferring a few megabytes of data each frame shouldn't be a problem though).&#xA;Several years earlier I've experimented with GDI+ and WPF, but the performance was nowhere near what I wanted to achieve. Unfortunately I don't have the source code any more, but I'd admit that my approach was maybe completely wrong back then.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm not expecting source code or a ready solution, but rather some directions: what functionality to use, I'd be happy to read articles or a tutorial about the topic.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I was considering OpenGL first, but I'm fine with DirectX too. Other suggestions are welcome. I'm planning to use C/C++ or C#, maybe Python for the implementation.&lt;/p&gt;&#xA;&#xA;&lt;p&gt;I'm sure there must be an easy solution, but I admit I'm a complete noob when it comes to graphics programming. I guess it's just about finding an effective way to copy data from RAM to GPU memory. I was wondering how retro emulators (e.g. Vice) or fantasy consoles (e.g. Pico-8) are solving this problem?&lt;/p&gt;&#xA;" OwnerUserId="13565" LastEditorUserId="13565" LastEditDate="2020-06-17T22:04:53.527" LastActivityDate="2020-06-19T11:38:22.677" Title="How to display an in-memory framebuffer" Tags="&lt;rendering&gt;&lt;real-time&gt;&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9950" PostTypeId="1" AcceptedAnswerId="9951" CreationDate="2020-06-17T16:12:45.557" Score="1" ViewCount="51" Body="&lt;p&gt;Not sure if this is just specific to &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/computing-pixel-coordinates-of-3d-point/mathematics-computing-2d-coordinates-of-3d-points&quot; rel=&quot;nofollow noreferrer&quot;&gt;this article&lt;/a&gt; but it says:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;We learned how to convert points from world to any local coordinate&#xA;system. If we know the local-to-world matrix, we can multiply the&#xA;world coordinate of the point by the inverse of the local-to-world&#xA;matrix (the world-to-local matrix).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Nothing else is ever done with the local-to-world matrix - other than taking its inverse. So I'm wondering if it would be easier just to define the world-to-local matrix directly? Does taking the inverse make things like &amp;quot;moving&amp;quot; the camera more intuitive?&lt;/p&gt;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="13566" LastEditorUserId="13095" LastEditDate="2020-06-18T12:23:43.807" LastActivityDate="2020-06-18T12:23:43.807" Title="Is there a general rule with regard to using the inverse of the &quot;camera&quot; to world when using a homogeneous transform matrix?" Tags="&lt;perspective&gt;&lt;render&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9951" PostTypeId="2" ParentId="9950" CreationDate="2020-06-18T08:35:54.090" Score="0" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Is there a general rule with regard to using the inverse of the “camera” to world when using a homogeneous transform matrix?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;No, there is no general rule. You should always think about which approach is the best one for your specific use-case.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Nothing else is ever done with the local-to-world matrix - other than taking its inverse. So I'm wondering if it would be easier just to define the world-to-local matrix directly?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Don't forget, that the source you linked is a tutorial. It has a limited scope and avoids confusing the reader with additional information he might not understand at the time of reading. That said, if I have an isolated look at the rendering process, I can't think of a reason why you absolutely need the cam-to-world matrix there because you want to transform everything into camera space before continuing with other transformations (projection, clipping, etc.). Even though it seems to make no sense to transform something out of camera space just to transform it back later, there still might be some reasons to do exactly this. For example, if some renderable object is attached to the camera coordinate system. Using an extra shader or a branch statement just for objects defined in the camera system usually costs you much more performance than two obsolete transformations.&lt;/p&gt;&#xA;&lt;p&gt;If we now consider other operations, not just rendering, you might find some useful applications of the camera to world matrix, for example, the movement of a camera that always moves into view direction or orthogonal to it (free camera mode in an FPS). The target point of the movement can be easily determined in camera space. It is just a vector of the movement speeds in each principle direction. Use the camera to world matrix to transform the target point into world space and you have your new location (if no collisions occur).&lt;/p&gt;&#xA;&lt;p&gt;Lastly, another reason to take the &amp;quot;inverse-route&amp;quot; might be that it is just easier, less work, or more convenient. All objects, including the camera, usually have a world space coordinate and orientation. The transformation to world space is always the same series of operations. Scale-rotate-translate. Since it so common and frequently used, you probably have an optimized function that does not multiply 3 individual matrices but calculates all the entries of the resulting matrix directly. You can still do the same for the world-to-local transformation, but it is less frequently used and if you only need it for your world-to-camera transformation it might be just easier to calculate the inverse since every linear algebra library you might use should provide this function. If you do this not too frequently each frame, it shouldn't affect performance in any notable way.&lt;/p&gt;&#xA;&lt;p&gt;As I said in the beginning, you should always focus on what your program needs. If you have no use for the camera-to-world matrix other than to calculate the world-to-camera matrix, you can definitely skip this and calculate the world-to-camera matrix directly. Just ask yourself, if it is worth it to add some extra lines of code for that.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-06-18T08:35:54.090" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9952" PostTypeId="2" ParentId="1720" CreationDate="2020-06-18T12:01:42.163" Score="1" Body="&lt;p&gt;I can see two ways of doing &amp;quot;smoothing&amp;quot;. The first one is smoothing what's mostly related to the appearance (in your case the normals). The other way is smoothing the geometry itself.&lt;/p&gt;&#xA;&lt;p&gt;In the first case you usually update the normals based on the neighbours. Say &lt;span class=&quot;math-container&quot;&gt;$\mathcal{M}$&lt;/span&gt; is a mesh, &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; is a triangle in &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$n(T)$&lt;/span&gt; is the normal at &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;. One dumb way of smoothing it could be simply&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{array}{l}&#xA;n(T) \leftarrow \frac{1}{|\mathcal{N}(T)|}\left(n(T) + \sum_{Q \in \mathcal{N}(T)} n(Q) \right) \\&#xA;n(T) \leftarrow n(T) / n(T).length()&#xA;\end{array}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here &lt;span class=&quot;math-container&quot;&gt;$\mathcal{N}(T)$&lt;/span&gt; represent the list of triangles adjacent to &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;.&#xA;The pair of equations as you can see don't really change the vertex count, the same argument could be applied to vertex normals. Essentially you don't delete or add anything you just adjust values.&lt;/p&gt;&#xA;&lt;p&gt;The second case is literally smoothing the geometry, which implies moving vertices around so you don't have sudden jumps in curvature. A couple of know examples are &lt;a href=&quot;https://en.wikipedia.org/wiki/Laplacian_smoothing&quot; rel=&quot;nofollow noreferrer&quot;&gt;laplacian smoothing&lt;/a&gt; and &lt;a href=&quot;https://graphics.stanford.edu/courses/cs468-01-fall/Papers/taubin-smoothing.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;taubin smoothing&lt;/a&gt;, both have similar equations to the first case I described.&lt;/p&gt;&#xA;&lt;p&gt;If you start removing vertices this is usually called &lt;a href=&quot;http://graphics.stanford.edu/courses/cs468-10-fall/LectureSlides/08_Simplification.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;decimation/simplification&lt;/a&gt;, if you add vertices is &lt;a href=&quot;https://en.wikipedia.org/wiki/Subdivision_surface&quot; rel=&quot;nofollow noreferrer&quot;&gt;subdivision&lt;/a&gt;. The smoothing in this case is kind of side effect really, i.e. when you render the mesh it might look smoother. But the purpose of decimating or subdividing is usually removing/adding of details (like LOD).&lt;/p&gt;&#xA;&lt;p&gt;By the way... the terminology I'm using is standard in Mesh Processing (smoothing, decimation and subdivision are well defined in this context and this leads to the content of my answer).&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="228" LastEditDate="2020-06-18T16:07:05.937" LastActivityDate="2020-06-18T16:07:05.937" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9953" PostTypeId="1" AcceptedAnswerId="9959" CreationDate="2020-06-18T19:47:54.537" Score="1" ViewCount="245" Body="&lt;p&gt;I am trying to compile some really simple shaders with DXC but, when creating PSO, I get:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;D3D12 ERROR: ID3D12Device::CreateVertexShader: Vertex Shader is corrupt or in an unrecognized format. [ STATE_CREATION ERROR #67: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE]&#xA;D3D12 ERROR: ID3D12Device::CreatePixelShader: Pixel Shader is corrupt or in an unrecognized format. [ STATE_CREATION ERROR #93: CREATEPIXELSHADER_INVALIDSHADERBYTECODE]&#xA;The parameter is incorrect.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The shader I try to compile:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct pixel_data&#xA;{&#xA;    float4 position : SV_POSITION;&#xA;    float2 uv : TEXCOORD0;&#xA;};&#xA;&#xA;&#xA;pixel_data vs_main( uint vertexID : SV_VertexID )&#xA;{&#xA;    float2 vertexOffset = float2((vertexID &amp;amp; 2) ? 1.f : -1.f, (vertexID &amp;amp; 1) ? 1.f : -1.f);&#xA;&#xA;    pixel_data output;&#xA;    output.position = float4(vertexOffset, 1.f, 1.f);&#xA;    output.uv = vertexOffset * float2(0.5f, -0.5f) + 0.5f;&#xA;&#xA;    return output;&#xA;}&#xA;&#xA;&#xA;float4 ps_main( pixel_data input ) : SV_TARGET&#xA;{&#xA;    return float4(input.uv, 1.f, 1.f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and code for compiling:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct&#xA;{&#xA;    ShaderObj shaders[MAX_SHADER];&#xA;    uint lastShaderID;&#xA;&#xA;    #ifdef _PC_ &#xA;        IDxcLibrary *dxcLibrary;&#xA;        IDxcCompiler *dxcCompiler;&#xA;        IDxcValidator *dxcValidator;&#xA;    #endif // #ifdef _PC_ &#xA;} shadersObjects;&#xA;&#xA;&#xA;#ifdef _PC_ &#xA;    void Shader::Init()&#xA;    {&#xA;        shadersObjects.lastShaderID = 0;&#xA;&#xA;        DX_RESULT( DxcCreateInstance( CLSID_DxcLibrary, IID_PPV_ARGS( &amp;amp;shadersObjects.dxcLibrary ) ) );&#xA;        DX_RESULT( DxcCreateInstance( CLSID_DxcCompiler, IID_PPV_ARGS( &amp;amp;shadersObjects.dxcCompiler ) ) );&#xA;        DX_RESULT( DxcCreateInstance( CLSID_DxcValidator, IID_PPV_ARGS( &amp;amp;shadersObjects.dxcValidator ) ) );&#xA;    }&#xA;&#xA;&#xA;    inline static IDxcBlob *CompileShader(char const *const fileName, wchar_t const *const entryPoint, wchar_t const *const targetProfile)&#xA;    {&#xA;        uint const SHADER_PATH_LEN = wcslen( shadersPath );&#xA;&#xA;        uint fileNameLength = SHADER_PATH_LEN + strlen( fileName );&#xA;        wchar_t *wFileName = new wchar_t[fileNameLength + 1];&#xA;        memcpy( wFileName, shadersPath, sizeof( wchar_t ) * SHADER_PATH_LEN );&#xA;        Misc::CharToWchar( wFileName + SHADER_PATH_LEN, fileName );&#xA;&#xA;        wchar_t const *compileArguments[] =&#xA;        {           &#xA;            L&amp;quot;/WX&amp;quot;,                         // Treat warnings as errors&#xA;            //L&amp;quot;/Zi&amp;quot;,                       // Enable debug information&#xA;            //L&amp;quot;/res_may_alias&amp;quot;,            // Assume that UAVs/SRVs may alias,&#xA;&#xA;        };&#xA;&#xA;        uint codePage = CP_UTF8;&#xA;        IDxcBlobEncoding *sourceBlob;&#xA;        DX_RESULT( shadersObjects.dxcLibrary-&amp;gt;CreateBlobFromFile( wFileName, &amp;amp;codePage, &amp;amp;sourceBlob));&#xA;&#xA;        IDxcIncludeHandler *includeHandler;&#xA;        DX_RESULT( shadersObjects.dxcLibrary-&amp;gt;CreateIncludeHandler( &amp;amp;includeHandler ) );&#xA;        IDxcOperationResult *compileResult;&#xA;        DX_RESULT( shadersObjects.dxcCompiler-&amp;gt;Compile(&#xA;            sourceBlob, // pSource&#xA;            wFileName, // pSourceName&#xA;            entryPoint, // pEntryPoint&#xA;            targetProfile, // pTargetProfile&#xA;            compileArguments, 1, // pArguments, argCount&#xA;            nullptr, 0, // pDefines, defineCount&#xA;            includeHandler, // pIncludeHandler&#xA;            &amp;amp;compileResult) // ppResult&#xA;        );&#xA;        includeHandler-&amp;gt;Release();&#xA;&#xA;        HRESULT compileHResult;&#xA;        compileResult-&amp;gt;GetStatus(&amp;amp;compileHResult);&#xA;        if (FAILED(compileHResult))&#xA;        {&#xA;            if (compileResult)&#xA;            {&#xA;                IDxcBlobEncoding *errorsBlob;&#xA;                compileHResult = compileResult-&amp;gt;GetErrorBuffer(&amp;amp;errorsBlob);&#xA;                if (errorsBlob)&#xA;                {&#xA;                    if (SUCCEEDED(compileHResult))&#xA;                    {&#xA;                        DebugPrint(&amp;quot;%ls:%ls\n%s\n&amp;quot;, wFileName, entryPoint, (const char *)errorsBlob-&amp;gt;GetBufferPointer());&#xA;                    }&#xA;&#xA;                    errorsBlob-&amp;gt;Release();&#xA;                }&#xA;&#xA;                compileResult-&amp;gt;Release();&#xA;                compileResult = nullptr;&#xA;            }&#xA;        }&#xA;&#xA;        delete[] wFileName;&#xA;        sourceBlob-&amp;gt;Release();&#xA;        if (compileResult)&#xA;        {&#xA;            IDxcBlob *code;&#xA;            compileResult-&amp;gt;GetResult( &amp;amp;code );&#xA;            compileResult-&amp;gt;Release();&#xA;&#xA;            IDxcOperationResult *validateResult;&#xA;            DX_RESULT( shadersObjects.dxcValidator-&amp;gt;Validate( code, DxcValidatorFlags_InPlaceEdit, &amp;amp;validateResult ) );&#xA;            HRESULT validateHResult;&#xA;            validateResult-&amp;gt;GetStatus( &amp;amp;validateHResult );&#xA;            if ( FAILED( validateHResult ) )&#xA;            {&#xA;                IDxcBlobEncoding *errorsBlob;&#xA;                validateHResult = validateResult-&amp;gt;GetErrorBuffer( &amp;amp;errorsBlob );&#xA;&#xA;                if ( errorsBlob )&#xA;                {&#xA;                    if ( SUCCEEDED( validateHResult ) )&#xA;                    {&#xA;                        DebugPrint( &amp;quot;%ls:%ls\n%s\n&amp;quot;, wFileName, entryPoint, (const char *)errorsBlob-&amp;gt;GetBufferPointer() );&#xA;                    }&#xA;&#xA;                    errorsBlob-&amp;gt;Release();&#xA;                }&#xA;            }&#xA;&#xA;            validateResult-&amp;gt;Release();&#xA;            return code;&#xA;        }&#xA;&#xA;        return nullptr;&#xA;    }&#xA;&#xA;&#xA;    ShaderObj* Shader::CreateShader(char const* vsFileName, char const* psFileName, ...)&#xA;    {&#xA;        IDxcBlob *vsCode = CompileShader( vsFileName, L&amp;quot;vs_main&amp;quot;, L&amp;quot;vs_6_4&amp;quot;);&#xA;        if ( !vsCode )&#xA;            return nullptr;&#xA;&#xA;        IDxcBlob *psCode = CompileShader( psFileName, L&amp;quot;ps_main&amp;quot;, L&amp;quot;ps_6_4&amp;quot; );&#xA;        if ( !psCode )&#xA;        {&#xA;            vsCode-&amp;gt;Release();&#xA;            return nullptr;&#xA;        }&#xA;&#xA;        D3D12_GRAPHICS_PIPELINE_STATE_DESC descPso = {};&#xA;        descPso.pRootSignature = GfxDevice::GetGraphicsRootSignature();&#xA;&#xA;        descPso.VS.pShaderBytecode = vsCode-&amp;gt;GetBufferPointer();&#xA;        descPso.VS.BytecodeLength = vsCode-&amp;gt;GetBufferSize();&#xA;&#xA;        descPso.PS.pShaderBytecode = psCode-&amp;gt;GetBufferPointer();&#xA;        descPso.PS.BytecodeLength = psCode-&amp;gt;GetBufferSize();&#xA;&#xA;        descPso.RasterizerState = RasterizationState::shaded_NoMSAA;&#xA;&#xA;        descPso.DepthStencilState = DepthStencilState::disabled;&#xA;&#xA;        descPso.BlendState.AlphaToCoverageEnable = FALSE;&#xA;        descPso.BlendState.IndependentBlendEnable = FALSE;&#xA;        descPso.BlendState.RenderTarget[0] = BlendState::disabled;&#xA;&#xA;        descPso.InputLayout.NumElements = 0;&#xA;        descPso.InputLayout.pInputElementDescs = nullptr;&#xA;        descPso.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;&#xA;&#xA;        descPso.NumRenderTargets = 1;&#xA;        descPso.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;        descPso.DSVFormat = DXGI_FORMAT_UNKNOWN;&#xA;&#xA;        descPso.SampleDesc.Count = 1;&#xA;        descPso.SampleMask = UINT_MAX;&#xA;&#xA;        ID3D12PipelineState *pso;&#xA;        HRESULT posCreateHresult = GfxDevice::GetGfxDevice()-&amp;gt;CreateGraphicsPipelineState( &amp;amp;descPso, IID_PPV_ARGS( &amp;amp;pso ) );&#xA;        vsCode-&amp;gt;Release();&#xA;        psCode-&amp;gt;Release();&#xA;&#xA;        if ( FAILED( posCreateHresult ) )&#xA;        {&#xA;            DX_RESULT( posCreateHresult );&#xA;            return nullptr;&#xA;        }&#xA;&#xA;        ShaderObj *shader = &amp;amp;shadersObjects.shaders[shadersObjects.lastShaderID];&#xA;        ++shadersObjects.lastShaderID;&#xA;        shader-&amp;gt;pso = pso;&#xA;&#xA;        return shader;&#xA;    }&#xA;&#xA;&#xA;    void Shader::Release()&#xA;    {&#xA;        shadersObjects.dxcLibrary-&amp;gt;Release();&#xA;        shadersObjects.dxcCompiler-&amp;gt;Release();&#xA;        shadersObjects.dxcValidator-&amp;gt;Release();&#xA;&#xA;        for (uint i = 0; i &amp;lt; shadersObjects.lastShaderID; ++i)&#xA;        {&#xA;            shadersObjects.shaders[i].pso-&amp;gt;Release();&#xA;        }&#xA;    }&#xA;#endif // #ifdef _PC_ &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I have tried using &lt;code&gt;CreateBlobWithEncodingFromPinned&lt;/code&gt; with source loaded from file and from char* array (in case there was some strange encoding in the file).&lt;/p&gt;&#xA;&lt;p&gt;Everything is ok until the PSO, shaders get compiled and validated.&lt;/p&gt;&#xA;&lt;p&gt;I tried to change some params in PSO description but it seems like Create*Shader are first in PSO creation.&lt;/p&gt;&#xA;&lt;p&gt;I have dev mode enabled in windows.&lt;/p&gt;&#xA;&lt;p&gt;Any idea?&lt;/p&gt;&#xA;" OwnerUserId="3123" LastActivityDate="2020-06-19T23:32:56.857" Title="DXC error when compiling PSO" Tags="&lt;shader&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9954" PostTypeId="1" AcceptedAnswerId="9960" CreationDate="2020-06-19T09:50:48.827" Score="3" ViewCount="568" Body="&lt;p&gt;With perspective projection we can unproject screen space coordinates of the cursor to the near and far plane of the frustum and calculate the direction of the ray through the cursor.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;        Vector4 cScreen0 = Vector4(cursorNormX, cursorNormY, -1, 1);&#xA;        Vector4 cView0 = Inverse(projection)*cScreen0;&#xA;        cView0 = cView0*(1/cView0.w);&#xA;        Vector4 cWorld0 = Inverse(view) * cView0;&#xA;&#xA;        Vector4 cScreen1 = Vector4(cursorNormX, cursorNormY, 1, 1);&#xA;        Vector4 cView1 = Inverse(projection)*cScreen1;&#xA;        cView1 = cView1*(1/cView1.w);&#xA;        Vector4 cWorld1 = Inverse(view) * cView1;&#xA;&#xA;        Vector3 cursorDir = normalize(cWorld1.xyz()-cWorld0.xyz());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now however with orthographic projection the far and near plane are of the same size, so we can't calculate the direction of the cursor this way. The direction is going to be equal the world's z axis. (I haven't had much sleep so I hope this makes sense).&lt;/p&gt;&#xA;&lt;p&gt;So instead I calculated the cursor position by unprojecting the cursor with zeroed out z value. We can calculate the x and y coordinate and set the z coordinate later as we like.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;        Vector4 cScreen = Vector4(cursorNormX, cursorNormY, 0, 0);&#xA;        Vector4 cView = Inverse(projection)*cScreen;&#xA;        cView = Vector4(cView.x, cView.y, 0, 0);&#xA;        Vector4 cWorld = Inverse(View) * cView;&#xA;        cWorld = Vector4(cWorld.x, cWorld.y, 0, 0);&#xA;&#xA;        Vector3 cursorPos = cWorld.xyz();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However I'm not getting the correct results from the projection. What am I missing?&lt;/p&gt;&#xA;&lt;p&gt;The purpose of this is to be able to cast rays in the direction of the cursor.&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-06-19T10:03:21.767" LastActivityDate="2020-06-21T13:51:09.393" Title="How to unproject cursor with orthographic projection" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="9955" PostTypeId="2" ParentId="9949" CreationDate="2020-06-19T11:38:22.677" Score="0" Body="&lt;p&gt;Have you considered using &lt;a href=&quot;https://www.libsdl.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;SDL 2&lt;/a&gt;?&lt;/p&gt;&#xA;&lt;p&gt;My use-case is basically identical to yours, and I've found this approach to work really well. They have a really nice C (and C++) API for drawing framebuffers to a window. It's also platform-agnostic, so you can share your implementation fairly easily between macOS, Linux and Windows.&#xA;If you want to see an example, you can go check out &lt;a href=&quot;https://github.com/vkoskiv/c-ray/blob/master/src/utils/ui.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; module here on GitHub. I do warn you though, while this implementation &lt;em&gt;works&lt;/em&gt;, and I can easily run it at 60-120FPS, it likely does use more CPU than a fully optimised implementation.&#xA;Specifically observe the &lt;code&gt;initDisplay()&lt;/code&gt; and &lt;code&gt;drawWindow()&lt;/code&gt; functions.&lt;/p&gt;&#xA;" OwnerUserId="13574" LastActivityDate="2020-06-19T11:38:22.677" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9956" PostTypeId="1" AcceptedAnswerId="10036" CreationDate="2020-06-19T13:13:36.067" Score="5" ViewCount="936" Body="&lt;p&gt;&lt;strong&gt;I have written a deferred renderer that can use either a fragment shader or a compute shader to execute the shading pass.  Unfortunately, the compute shader implementation runs slower.  I'm trying to understand why.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I believe I understand the proximate cause: memory locality when accessing textures.  Somehow the fragment shader's accesses are significantly more coherent than the compute shader's.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;To demonstrate that, I removed everything except the shadowmapping code and then changed that to sample randomly.  Something like (GLSL pseudocode):&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;uniform sampler2D tex_shadowmap;&#xA;&#xA;uniform float param;&#xA;&#xA;#ifdef COMPUTE_SHADER&#xA;layout(local_size_x=8, local_size_y=4, local_size_z=1) in;&#xA;#endif&#xA;&#xA;struct RNG { uint64_t state; uint64_t inc; } _rng;&#xA;void rand_seed(ivec2 coord) { /*seed `_rng` with hash of `coord`*/ }&#xA;float rand_float() { /*return random float in [0,1]*/ }&#xA;&#xA;void main() {&#xA;    rand_seed(/*pixel coordinate*/);&#xA;&#xA;    vec4 light_coord = /*vertex in scaled/biased light's NDC*/;&#xA;    vec3 shadowmap_test_pos = light_coord.xyz / light_coord.w;&#xA;&#xA;    float rand_shadow = 0.0;&#xA;    for (int i=0;i&amp;lt;200;++i) {&#xA;        vec2 coord = fract(mix( shadowmap_test_pos.xy, vec2(rand_float(),rand_float()), param ));&#xA;        float tap = textureLod(tex_shadowmap,coord,0.0).r;&#xA;        rand_shadow += clamp(shadowmap_test_pos.z,0.0,1.0)&amp;lt;=tap+0.00001 ? 1.0 : 0.0;&#xA;    }&#xA;    vec4 color = vec4(vec3(rand_shadow)/200.0,1.0);&#xA;&#xA;    /*[set `color` into output]*/&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When &lt;code&gt;param&lt;/code&gt; is set to &lt;code&gt;0&lt;/code&gt;, the shadowmap is sampled at &lt;code&gt;shadowmap_test_pos&lt;/code&gt;, and we get correct hard shadows for the scene.  In this case, the shadowmap texture lookup locations are somewhat correlated to the pixel coordinate, so we expect good performance.  When &lt;code&gt;param&lt;/code&gt; is set to &lt;code&gt;1&lt;/code&gt;, we get a completely random texture coordinate &lt;code&gt;vec2(rand_float(),rand_float())&lt;/code&gt;, and so the texture lookups are not at all correlated to the pixel coordinate, and we expect bad performance.&lt;/p&gt;&#xA;&lt;p&gt;Something very interesting happens when we try some more values for &lt;code&gt;param&lt;/code&gt; and measure the latency of the shading pass with a &lt;a href=&quot;http://www.lighthouse3d.com/tutorials/opengl-timer-query/&quot; rel=&quot;noreferrer&quot;&gt;timer query&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uqvTM.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uqvTM.png&quot; alt=&quot;plot of param vs. latency&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As one can see, when working with completely random coordinates (&lt;code&gt;param&lt;/code&gt;=1, right side), the fragment shader and compute shader have the same performance. However, as the coordinates become less random, whatever the fragment shader is doing that makes it more coherent starts to come into play. When the coordinates are deterministic and correlated to screen position (&lt;code&gt;param&lt;/code&gt;≈0, left side), the fragment shader wins by a factor of 2 (note: the &lt;code&gt;param&lt;/code&gt;=0 case was omitted since the GLSL compiler optimizes out the loop).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;What's especially weird is that the fragment shader being faster seems to depend on the texture sample coordinate being correlated to the pixel coordinate.&lt;/strong&gt;  For example, if instead of &lt;code&gt;shadowmap_test_pos.xy&lt;/code&gt; I use &lt;code&gt;vec2(0.5)&lt;/code&gt; as the deterministic coordinate, then the effect disappears, and the two shaders have the same performance for any &lt;code&gt;param&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Both the sources and compiled codes of these shaders are essentially the same.   Apart from some setup and writing the data out (which one expects to vary a bit), the shaders are identical.  You can see a diff I made of the PTX disassemblies &lt;a href=&quot;http://www.mergely.com/oUOuCk97/&quot; rel=&quot;noreferrer&quot;&gt;here&lt;/a&gt;.  Most of the loop body is taken up with the inlined RNG, but the salient point is that &lt;em&gt;it's the same loop&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Note: tested hardware was NVIDIA GTX 1080 with current (446.14) driver.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;My question is basically: what can I do about this?  I'm working in 8⨯4 tiles in the compute shader, but who knows what the fragment shader is doing.  Yet, I would not expect whatever magical secret shading order the fragment shader does to be &lt;em&gt;so much&lt;/em&gt; better that you would get a &amp;gt;2⨯ performance difference when you're running the same actual code.  (FWIW I've tried different group sizes, to no real change in the above behavior.)&lt;/p&gt;&#xA;&lt;p&gt;There are a few &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/54/when-is-a-compute-shader-more-efficient-than-a-pixel-shader-for-image-filtering&quot;&gt;general discussions&lt;/a&gt; about how the different shaders work, but I haven't found anything that can explain this.  And, while in the past driver issues have caused weird behavior, compute shaders have now been in core GL for almost 8 years, and using them for deferred shading is an obvious, arguably common, use-case that I would expect to work well.&lt;/p&gt;&#xA;&lt;p&gt;What am I missing here?&lt;/p&gt;&#xA;" OwnerUserId="523" LastEditorUserId="523" LastEditDate="2020-06-19T13:43:31.420" LastActivityDate="2020-07-17T11:45:47.250" Title="Performance of Compute Shaders vs. Fragment Shaders for Deferred Rendering" Tags="&lt;performance&gt;&lt;compute-shader&gt;&lt;fragment-shader&gt;&lt;deferred-rendering&gt;" AnswerCount="1" CommentCount="6" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9957" PostTypeId="1" CreationDate="2020-06-19T17:25:26.657" Score="3" ViewCount="101" Body="&lt;p&gt;I am more or less a complete novice in the field of 3D modeling. I understand the basics of a polygon mesh and a texture; however, it was always my understanding that 3D models were, effectively, &amp;quot;hollow&amp;quot; inside the mesh, in the same way that a plastic skeleton Halloween decoration is hollow. It possesses a surface, but no internal density. This understanding has always worked well for me, as I primarily work with photogrammetry-created 3D models, for which this is undoubtedly true.&lt;/p&gt;&#xA;&lt;p&gt;In my latest project, however, I am being asked to work with 3D models created using CT scan data and Slicer. Unlike photogrammetry images, CT scans &lt;em&gt;do&lt;/em&gt; care about internal density and structure. I know Slicer can be used to create 3D models from CT scan images. What I'm uncertain about, however, is whether Slicer creates truly &amp;quot;solid&amp;quot; models from this data -- models which have internal density rather than simply a mesh &amp;quot;skin&amp;quot;, where the &amp;quot;inside&amp;quot; of the model is programmatically distinct from the &amp;quot;outside&amp;quot; -- or whether it simply create a multilayered but still fundamentally hollow mesh (or series of meshes) based on boundaries between areas of different densities.&lt;/p&gt;&#xA;&lt;p&gt;Is this a meaningful distinction? Am I fundamentally misunderstanding how the surface/internal geometry of 3D models works? Any advice is welcome.&lt;/p&gt;&#xA;&lt;p&gt;(I took my best guess as to where to ask this question -- if this is outside the purview of this site, please let me know! If you know another place where I could go asking for answers, I would also appreciate that information. Thank you so much!!!)&lt;/p&gt;&#xA;" OwnerUserId="13575" LastActivityDate="2020-06-19T20:08:33.160" Title="Are some 3D objects &quot;solid&quot;? Do they have internal density? If so, when, and in which file formats?" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9958" PostTypeId="2" ParentId="9957" CreationDate="2020-06-19T20:08:33.160" Score="4" Body="&lt;p&gt;Assuming what you’re referring to is &lt;a href=&quot;https://slicer.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;this Slicer&lt;/a&gt; and the models are the ones produced by its &lt;a href=&quot;https://www.slicer.org/wiki/Documentation/Nightly/Modules/ModelMaker&quot; rel=&quot;nofollow noreferrer&quot;&gt;Model Maker&lt;/a&gt; module: it looks like it’s creating hollow, surface-only models.&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://www.slicer.org/w/img_auth.php/3/36/Slicer4-ModelMaker-Output.jpeg&quot; alt=&quot;screenshot from the Model Maker module in Slicer&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;Specifically, judging by the crunchiness of the mesh shown in the top right of this screenshot, it looks like it’s using &lt;a href=&quot;https://en.wikipedia.org/wiki/Marching_cubes&quot; rel=&quot;nofollow noreferrer&quot;&gt;marching cubes&lt;/a&gt; to create a mesh from the &lt;a href=&quot;https://en.wikipedia.org/wiki/Isosurface&quot; rel=&quot;nofollow noreferrer&quot;&gt;isosurfaces&lt;/a&gt; at given density thresholds in the volume.&lt;/p&gt;&#xA;&lt;p&gt;Most 3D model formats—especially the ones used for real-time rendering—are surface-only; as graphics hardware gets more powerful, though, there’s been wider use of &lt;a href=&quot;https://en.wikipedia.org/wiki/Volume_rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;volume rendering&lt;/a&gt;, often via &lt;a href=&quot;https://en.wikipedia.org/wiki/Volume_ray_casting&quot; rel=&quot;nofollow noreferrer&quot;&gt;raymarching&lt;/a&gt;, to render volume data directly rather than having to go through the intermediate meshing step. One common format for volume data is &lt;a href=&quot;https://www.openvdb.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenVDB&lt;/a&gt;; it’s also possible to embed such data in &lt;a href=&quot;http://www.alembic.io&quot; rel=&quot;nofollow noreferrer&quot;&gt;Alembic&lt;/a&gt; files.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2020-06-19T20:08:33.160" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9959" PostTypeId="2" ParentId="9953" CreationDate="2020-06-19T23:32:56.857" Score="1" Body="&lt;p&gt;This can be caused by the compiler creating unsigned bytecode. For the compiler to sign the bytecode, you have to have a copy of dxil.dll in the same folder as the dxcompiler.dll at runtime. See &lt;a href=&quot;https://docs.microsoft.com/en-us/archive/blogs/marcelolr/using-the-github-dxcompiler-dll&quot; rel=&quot;nofollow noreferrer&quot;&gt;Using the GitHub dxcompiler.dll&lt;/a&gt; for some more info. The dxil.dll is available in the &lt;a href=&quot;https://github.com/microsoft/DirectXShaderCompiler/releases&quot; rel=&quot;nofollow noreferrer&quot;&gt;official DXC releases&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-06-19T23:32:56.857" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9960" PostTypeId="2" ParentId="9954" CreationDate="2020-06-21T13:45:11.277" Score="4" Body="&lt;p&gt;I am still not 100% sure, if I understood your question, because of this sentence:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Now however with orthographic projection the far and near plane are of the same size, so we can't calculate the direction of the cursor this way. The direction is going to be equal the world's z axis. (I haven't had much sleep so I hope this makes sense).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;If I misunderstood you, let me know in the comments and I will adjust or remove my answer.&lt;/p&gt;&#xA;&lt;p&gt;However, if I understood your intention correctly and you want to cast a ray through your frustum (for example to pick objects), then your statement is wrong. The direction will be equal to the &lt;strong&gt;view spaces'&lt;/strong&gt; negative z-direction, not the world spaces'. So all you need to do is to transform your direction vector or the near and far plane points to world space. To proof, that this works, I have implemented everything in a Python script, that you will find at the end of this answer. If you have a Python interpreter with MatPlotLib and NumPy installed, you can modify the setup parameters and experiment a little bit yourself.&lt;/p&gt;&#xA;&lt;p&gt;So let's have a look at the relevant implementation. First, we calculate the mouse position in clip space and the corresponding 2 points on the near and far plane.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;mouse_pos_x_clip = mouse_pos_x_screen / screen_width * 2 - 1&#xA;mouse_pos_y_clip = mouse_pos_y_screen / screen_height * 2 - 1&#xA;&#xA;mouse_pos_near_clip = np.array([mouse_pos_x_clip, mouse_pos_y_clip, -1, 1], dtype=float)&#xA;mouse_pos_far_clip = np.array([mouse_pos_x_clip, mouse_pos_y_clip, 1, 1], dtype=float)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now we get the involved matrices. My notation here is as follows: I use two characters after &lt;code&gt;M_&lt;/code&gt; that are abbreviations of the involved spaces. The first character is the source and the second the target space. The characters are &lt;code&gt;c&lt;/code&gt; for clip space, &lt;code&gt;v&lt;/code&gt; for view space, and &lt;code&gt;w&lt;/code&gt; for world space. So &lt;code&gt;M_vc&lt;/code&gt; is the view space to clip space transformation a.k.a the projection matrix.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;M_wv = get_world_to_view_matrix(camera_pitch, camera_yaw, camera_position)&#xA;if perspective:&#xA;    M_vc = get_perspective_mat(field_of_view, z_near_plane, z_far_plane, aspect_ratio)&#xA;else:&#xA;    M_vc = get_orthogonal_mat(frustum_width, frustum_height, z_near_plane, z_far_plane)&#xA;&#xA;M_vw = np.linalg.inv(M_wv)&#xA;M_cv = np.linalg.inv(M_vc)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now I simply use the correct transformation matrices to transform from clip to world space. Note that the perspective projection needs a division by &lt;code&gt;w&lt;/code&gt; after the transformation to view space. This is not necessary for the orthographic projection, but performing it does not affect the result.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;mouse_pos_near_view = np.matmul(M_cv, mouse_pos_near_clip)&#xA;mouse_pos_far_view = np.matmul(M_cv, mouse_pos_far_clip)&#xA;&#xA;if perspective:&#xA;    mouse_pos_near_view= mouse_pos_near_view / mouse_pos_near_view[3]&#xA;    mouse_pos_far_view= mouse_pos_far_view / mouse_pos_far_view[3]&#xA;&#xA;mouse_pos_near_world = np.matmul(M_vw, mouse_pos_near_view)&#xA;mouse_pos_far_world = np.matmul(M_vw, mouse_pos_far_view)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is, as far as I can see, identical to your first code section. Now let's have a look a the result for perspective and orthographic projection with the following setup parameters:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;screen_height = 1080&#xA;screen_width = 1980&#xA;&#xA;mouse_pos_x_screen = 500&#xA;mouse_pos_y_screen = 300&#xA;&#xA;camera_position = [3, 0, 1]&#xA;camera_yaw = 20&#xA;camera_pitch = 30&#xA;&#xA;z_near_plane = 0.5&#xA;z_far_plane = 3&#xA;&#xA;# only orthogonal&#xA;frustum_width = 3&#xA;frustum_height = 2&#xA;&#xA;# only perspective&#xA;field_of_view = 70&#xA;aspect_ratio = screen_width / screen_height&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The screen space and clip space values are identical for both projections:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZQ4q2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZQ4q2.png&quot; alt=&quot;screen space&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4R21Q.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4R21Q.png&quot; alt=&quot;clip space&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The red line connects the two points on the near and far plane. The red dot is the point on the near plane, which is your &amp;quot;screen&amp;quot; in a 3d space. The green lines mark the borders of the frustum. In clip space, it is obviously just a cube. An important thing to realize is, that clip space is defined in a left-handed coordinate system while the other coordinate systems are usually right-handed (have a look at the images in &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link&lt;/a&gt;). I mention it since I had some problems with the plots until I realized that.&lt;/p&gt;&#xA;&lt;p&gt;Now for perspective projection, I get the following plots:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/77GKT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/77GKT.png&quot; alt=&quot;view space perspective&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/VAAVs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VAAVs.png&quot; alt=&quot;world space perspective&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The blue dot is the camera position.&#xA;If I just exchange the perspective matrix with an orthographic projection matrix, the results look like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VxvEo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VxvEo.png&quot; alt=&quot;view space orthographic&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/4Nj7T.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Nj7T.png&quot; alt=&quot;world space orthographic&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see, the approach you used in your first code section works independently of the chosen projection. I don't know why you thought it wouldn't. An assumption of mine is, that you might have made a small mistake during the implementation of the orthographic projection matrix. For example, if you accidentally flipped rows and columns (transposed) of the orthographic projection matrix, you get total crap like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fWIcL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fWIcL.png&quot; alt=&quot;transposed orthographic projection&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I know this looks like a wrong implementation of the perspective projection, but this is what I get when I transpose the orthographic projection matrix before the multiplication.&lt;/p&gt;&#xA;&lt;p&gt;So make sure you use the correct orthographic projection matrix (&lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;source&lt;/a&gt;):&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{bmatrix}&#xA;\frac{2}{w}&amp;amp;0&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;\frac{2}{h}&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;\frac{-2}{f-n}&amp;amp;-\frac{f+n}{f-n}\\&#xA;0&amp;amp;0&amp;amp;0&amp;amp;1&#xA;\end{bmatrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; is the frustum width, &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt; the frustum height, &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; the far plane z-value and &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; the near plane z-value. This is the representation if you use column vectors and left multiplied matrices. For row vectors and right multiplied matrices, you need to transpose it.&lt;/p&gt;&#xA;&lt;p&gt;Your second approach:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;Vector4 cScreen = Vector4(cursorNormX, cursorNormY, 0, 0);&#xA;Vector4 cView = Inverse(projection)*cScreen;&#xA;cView = Vector4(cView.x, cView.y, 0, 0);&#xA;Vector4 cWorld = Inverse(View) * cView;&#xA;cWorld = Vector4(cWorld.x, cWorld.y, 0, 0);&#xA;&#xA;Vector3 cursorPos = cWorld.xyz();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;has multiple issues and all are related to the z- and w-components of your vectors. Basically, you need to do the same transformations as in your first approach. So use &lt;code&gt;Vector4 cScreen = Vector4(cursorNormX, cursorNormY, -1, 1);&lt;/code&gt; as initial vector.&lt;/p&gt;&#xA;&lt;p&gt;One problem of the line &lt;code&gt;cView = Vector4(cView.x, cView.y, 0, 0);&lt;/code&gt; is, that your z-component should be identical to your near plane value and not zero. You might get away with that since it would just shift your point a little bit in the camera viewing direction in world space, but more problematic is that you set w to 0. This makes it impossible to apply any translation to the vector by &lt;span class=&quot;math-container&quot;&gt;$4 \times 4$&lt;/span&gt; matrix multiplication. So when you transform to world space, you will always end up with a point that treats the camera to be located at the coordinate system origin, regardless of its true position. So you need to set the w-component to 1. However, if the previous lines are correct, you should automatically get the correct z- and w-values which makes this line obsolete.&lt;/p&gt;&#xA;&lt;p&gt;Lastly, the line &lt;code&gt;cWorld = Vector4(cWorld.x, cWorld.y, 0, 0);&lt;/code&gt; doesn't make much sense either to me. Your camera is somewhere in 3d world space. Why do you remove the z-component you previously calculated? With this, you move the point into the XY-plane for no reason. Just remove this line.&lt;/p&gt;&#xA;&lt;p&gt;To get the cameras viewing direction without using the far plane point, just multiply the vector &lt;code&gt;[0, 0, -1, 0]&lt;/code&gt; with the view-to-world matrix (&lt;code&gt;M_vw&lt;/code&gt;). In this case, the w-component really has to be 0, since you do not want to apply translations to it because it is a direction vector and no point. The z-component needs to be -1 because the camera looks into the negative direction by definition. Notice, that the transformed vector is usually not of unit length anymore. So you might want to normalize it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Additional Note&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;For an orthographic projection, there is no need to calculate the inverse projection matrix. You can simply calculate the x and y values directly by something like this (untested pseudo-code):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;x_view = (x_screen / screen_width - 0.5) * frustum_width&#xA;y_view = (y_screen / screen_height - 0.5) * frustum_height&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then you get the screen space point in view space by setting (untested pseudo-code):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;point_view_near = [x_view, y_view, -z_near, 1]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Watch out to use the negative near plane z-value! For the far plane, you can do the same.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Full Python script&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;import numpy as np&#xA;from mpl_toolkits.mplot3d import Axes3D  # noqa: F401 unused import&#xA;import matplotlib.pyplot as plt&#xA;&#xA;# setup --------------------------------------------------------------------------------&#xA;&#xA;screen_height = 1080&#xA;screen_width = 1980&#xA;&#xA;mouse_pos_x_screen = 500&#xA;mouse_pos_y_screen = 300&#xA;&#xA;&#xA;camera_position = [3, 0, 1]&#xA;camera_yaw = 20&#xA;camera_pitch = 30&#xA;&#xA;# ----------------&#xA;# projection setup&#xA;# ----------------&#xA;perspective = False # set 'False' for orthogonal and 'True' for perspective projection&#xA;&#xA;z_near_plane = 0.5&#xA;z_far_plane = 3&#xA;&#xA;# only orthogonal&#xA;frustum_width = 3&#xA;frustum_height = 2&#xA;&#xA;# only perspective&#xA;field_of_view = 70&#xA;aspect_ratio = screen_width / screen_height&#xA;&#xA;# functions ----------------------------------------------------------------------------&#xA;&#xA;&#xA;def render_frustum(points, camera_pos, ax, right_handed=True):&#xA;    line_indices = [&#xA;        [0, 1],&#xA;        [0, 2],&#xA;        [0, 4],&#xA;        [1, 3],&#xA;        [1, 5],&#xA;        [2, 3],&#xA;        [2, 6],&#xA;        [3, 7],&#xA;        [4, 5],&#xA;        [4, 6],&#xA;        [5, 7],&#xA;        [6, 7],&#xA;    ]&#xA;    for idx_pair in line_indices:&#xA;        line = np.transpose([points[idx_pair[0]], points[idx_pair[1]]])&#xA;        ax.plot(line[2], line[0], line[1], &amp;quot;g&amp;quot;)&#xA;    if right_handed:&#xA;        ax.set_xlim([-5, 5])&#xA;    else:&#xA;        ax.set_xlim([5, -5])&#xA;    ax.set_ylim([-5, 5])&#xA;    ax.set_zlim([-5, 5])&#xA;    ax.set_xlabel(&amp;quot;z&amp;quot;)&#xA;    ax.set_ylabel(&amp;quot;x&amp;quot;)&#xA;    ax.set_zlabel(&amp;quot;y&amp;quot;)&#xA;    ax.plot([-5, 5], [0, 0], [0, 0], &amp;quot;k&amp;quot;)&#xA;    ax.plot([0, 0], [-5, 5], [0, 0], &amp;quot;k&amp;quot;)&#xA;    ax.plot([0, 0], [0, 0], [-5, 5], &amp;quot;k&amp;quot;)&#xA;    if camera_pos is not None:&#xA;        ax.scatter(&#xA;            camera_pos[2], camera_pos[0], camera_pos[1], marker=&amp;quot;o&amp;quot;, color=&amp;quot;b&amp;quot;, s=30&#xA;        )&#xA;&#xA;def render_ray(p0,p1,ax):&#xA;    ax.plot([p0[2], p1[2]], [p0[0], p1[0]], [p0[1], p1[1]], color=&amp;quot;r&amp;quot;)&#xA;    ax.scatter(p0[2], p0[0], p0[1], marker=&amp;quot;o&amp;quot;, color=&amp;quot;r&amp;quot;)&#xA;&#xA;&#xA;def get_perspective_mat(fov_deg, z_near, z_far, aspect_ratio):&#xA;    fov_rad = fov_deg * np.pi / 180&#xA;    f = 1 / np.tan(fov_rad / 2)&#xA;&#xA;    return np.array(&#xA;        [&#xA;            [f / aspect_ratio, 0, 0, 0],&#xA;            [0, f, 0, 0],&#xA;            [&#xA;                0,&#xA;                0,&#xA;                (z_far + z_near) / (z_near - z_far),&#xA;                2 * z_far * z_near / (z_near - z_far),&#xA;            ],&#xA;            [0, 0, -1, 0],&#xA;        ]&#xA;    )&#xA;&#xA;&#xA;def get_orthogonal_mat(width, height, z_near, z_far):&#xA;    r = width / 2&#xA;    t = height / 2&#xA;&#xA;    return np.array(&#xA;        [&#xA;            [1 / r, 0, 0, 0],&#xA;            [0, 1 / t, 0, 0],&#xA;            [&#xA;                0,&#xA;                0,&#xA;                -2 / (z_far - z_near),&#xA;                -(z_far + z_near) / (z_far - z_near),&#xA;            ],&#xA;            [0, 0, 0, 1],&#xA;        ]&#xA;    )&#xA;&#xA;&#xA;def get_rotation_mat_x(angle_rad):&#xA;    s = np.sin(angle_rad)&#xA;    c = np.cos(angle_rad)&#xA;    return np.array(&#xA;        [[1, 0, 0, 0], [0, c, -s, 0], [0, s, c, 0], [0, 0, 0, 1]], dtype=float&#xA;    )&#xA;&#xA;&#xA;def get_rotation_mat_y(angle_rad):&#xA;    s = np.sin(angle_rad)&#xA;    c = np.cos(angle_rad)&#xA;    return np.array(&#xA;        [[c, 0, s, 0], [0, 1, 0, 0], [-s, 0, c, 0], [0, 0, 0, 1]], dtype=float&#xA;    )&#xA;&#xA;&#xA;def get_translation_mat(position):&#xA;    return np.array(&#xA;        [&#xA;            [1, 0, 0, position[0]],&#xA;            [0, 1, 0, position[1]],&#xA;            [0, 0, 1, position[2]],&#xA;            [0, 0, 0, 1],&#xA;        ],&#xA;        dtype=float,&#xA;    )&#xA;&#xA;&#xA;def get_world_to_view_matrix(pitch_deg, yaw_deg, position):&#xA;    pitch_rad = np.pi / 180 * pitch_deg&#xA;    yaw_rad = np.pi / 180 * yaw_deg&#xA;&#xA;    orientation_mat = np.matmul(&#xA;        get_rotation_mat_x(-pitch_rad), get_rotation_mat_y(-yaw_rad)&#xA;    )&#xA;    translation_mat = get_translation_mat(-1 * np.array(position, dtype=float))&#xA;    return np.matmul(orientation_mat, translation_mat)&#xA;&#xA;&#xA;# script -------------------------------------------------------------------------------&#xA;&#xA;mouse_pos_x_clip = mouse_pos_x_screen / screen_width * 2 - 1&#xA;mouse_pos_y_clip = mouse_pos_y_screen / screen_height * 2 - 1&#xA;&#xA;mouse_pos_near_clip = np.array([mouse_pos_x_clip, mouse_pos_y_clip, -1, 1], dtype=float)&#xA;mouse_pos_far_clip = np.array([mouse_pos_x_clip, mouse_pos_y_clip, 1, 1], dtype=float)&#xA;&#xA;&#xA;&#xA;M_wv = get_world_to_view_matrix(camera_pitch, camera_yaw, camera_position)&#xA;if perspective:&#xA;    M_vc = get_perspective_mat(field_of_view, z_near_plane, z_far_plane, aspect_ratio)&#xA;else:&#xA;    M_vc = get_orthogonal_mat(frustum_width, frustum_height, z_near_plane, z_far_plane)&#xA;&#xA;M_vw = np.linalg.inv(M_wv)&#xA;M_cv = np.linalg.inv(M_vc)&#xA;&#xA;mouse_pos_near_view = np.matmul(M_cv,mouse_pos_near_clip)&#xA;mouse_pos_far_view = np.matmul(M_cv,mouse_pos_far_clip)&#xA;&#xA;if perspective:&#xA;    mouse_pos_near_view= mouse_pos_near_view / mouse_pos_near_view[3]&#xA;    mouse_pos_far_view= mouse_pos_far_view / mouse_pos_far_view[3]&#xA;&#xA;mouse_pos_near_world = np.matmul(M_vw, mouse_pos_near_view)&#xA;mouse_pos_far_world = np.matmul(M_vw, mouse_pos_far_view)&#xA;&#xA;# calculate view frustum ---------------------------------------------------------------&#xA;&#xA;points_clip = np.array(&#xA;    [&#xA;        [-1, -1, -1, 1],&#xA;        [ 1, -1, -1, 1],&#xA;        [-1,  1, -1, 1],&#xA;        [ 1,  1, -1, 1],&#xA;        [-1, -1,  1, 1],&#xA;        [ 1, -1,  1, 1],&#xA;        [-1,  1,  1, 1],&#xA;        [ 1,  1,  1, 1],&#xA;    ],&#xA;    dtype=float,&#xA;)&#xA;&#xA;points_view = []&#xA;points_world = []&#xA;for i in range(8):&#xA;    points_view.append(np.matmul(M_cv, points_clip[i]))&#xA;    points_view[i] = points_view[i] / points_view[i][3]&#xA;    points_world.append(np.matmul(M_vw, points_view[i]))&#xA;&#xA;&#xA;# plot everything ----------------------------------------------------------------------&#xA;&#xA;plt.figure()&#xA;plt.plot(mouse_pos_x_screen,mouse_pos_y_screen, marker=&amp;quot;o&amp;quot;, color=&amp;quot;r&amp;quot;)&#xA;plt.xlim([0, screen_width])&#xA;plt.ylim([0, screen_height])&#xA;plt.xlabel(&amp;quot;x&amp;quot;)&#xA;plt.ylabel(&amp;quot;y&amp;quot;)&#xA;plt.title(&amp;quot;screen space&amp;quot;)&#xA;&#xA;plt.figure()&#xA;ax_clip_space = plt.gca(projection=&amp;quot;3d&amp;quot;)&#xA;render_ray(mouse_pos_near_clip, mouse_pos_far_clip, ax_clip_space)&#xA;render_frustum(points=points_clip, camera_pos=None, ax=ax_clip_space, right_handed=False)&#xA;ax_clip_space.set_title(&amp;quot;clip space&amp;quot;)&#xA;&#xA;plt.figure()&#xA;ax_view = plt.gca(projection=&amp;quot;3d&amp;quot;)&#xA;render_ray(mouse_pos_near_view, mouse_pos_far_view, ax_view)&#xA;render_frustum(points=points_view, camera_pos=[0, 0, 0], ax=ax_view)&#xA;ax_view.set_title(&amp;quot;view space&amp;quot;)&#xA;&#xA;plt.figure()&#xA;ax_world = plt.gca(projection=&amp;quot;3d&amp;quot;)&#xA;render_ray(mouse_pos_near_world, mouse_pos_far_world, ax_world)&#xA;render_frustum(points=points_world, camera_pos=camera_position, ax=ax_world)&#xA;ax_world.set_title(&amp;quot;world space&amp;quot;)&#xA;&#xA;plt.show()&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-06-21T13:51:09.393" LastActivityDate="2020-06-21T13:51:09.393" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9961" PostTypeId="1" AcceptedAnswerId="9971" CreationDate="2020-06-21T16:40:47.053" Score="2" ViewCount="82" Body="&lt;p&gt;Real human anatomies look wet/ moist when operated. I am looking for some good methods for rendering anatomies in a virtual simulation, and hence I have done a literature survey on 'Rendering wet materials' using keywords like:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Rendering wet materials.&lt;/li&gt;&#xA;&lt;li&gt;Rendering moist surfaces.&lt;/li&gt;&#xA;&lt;li&gt;Rendering wet surfaces.&#xA;etc.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;What I observed is, in general, people use ray-tracing methods after modeling surface with a two-layer surface reflection model, for achieving realism for wet surfaces.&lt;/p&gt;&#xA;&lt;p&gt;What are some good rasterization methods/ approximations for the same keeping in mind real-time performance and unavailability of RTX gfx cards, as well as realism?&lt;/p&gt;&#xA;" OwnerUserId="10370" LastActivityDate="2020-06-23T10:38:50.183" Title="Rendering moist/wet materials like human anatomies for surgical simulators" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;rendering&gt;&lt;shader&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9962" PostTypeId="1" CreationDate="2020-06-21T17:38:51.567" Score="0" ViewCount="20" Body="&lt;p&gt;I've spent the last three days trying to figure this out, my intuition about this space has been thrown out of the window.&lt;/p&gt;&#xA;&lt;p&gt;The problem is this:&lt;/p&gt;&#xA;&lt;p&gt;I have a hexagon grid making function that returns an id value for specific cells on a grid. I have also made a 128x1 texture that is filled with incoming midi/keyboard notes.&lt;/p&gt;&#xA;&lt;p&gt;I would like to arrange the notes from the texture onto the grid using a simple relationship, which is X * 7 + Y * 4, this follows the relationship of Euler's Tonnetz, where each neighbour horizontally ascends by a perfect fifth(seven semitones), and the y is offset by four semitones which is a major third.&lt;/p&gt;&#xA;&lt;p&gt;So I thought, I just need a specific hash function like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float hash21(vec2 p)&#xA;{&#xA;    p += scale; // offset lowest negative value, so id vals are now zero to (2*scale)&#xA;    p.x = p.x * 7.0;&#xA;    p.y = p.y * 4.0;&#xA;    return p.x + p.y;&#xA;}&#xA;&#xA;////// This is the rest of code, grid val for hex grid&#xA;vec2 gridVal(vec2 uv)&#xA;{&#xA;    vec2 repeat =vec2 (1.0,1.73); // 1.73 equiv to sqrt of 3 &#xA;    vec2 h = repeat*0.5;&#xA;    vec2 a1=mod(uv,repeat)-h; // gridify, but it's offset&#xA;    vec2 b1=mod(uv-h,repeat)-h; // gridify and center&#xA;    vec2 gv = dot(a1,a1)&amp;lt;dot(b1,b1)?a1:b1;//if else function without if/else&#xA;    &#xA;    return gv;&#xA;}&#xA;&#xA;vec4 hexFunction (vec2 uv)&#xA;{&#xA;    vec2 gv = gridVal(uv);&#xA;    float x = atan(gv.x,gv.y);&#xA;    float y = 0.5-hexD(gv);&#xA;    vec2 id = uv-gv;&#xA;    vec4 co = vec4(x,y,id.x,id.y); // coords and id&#xA;    return co;&#xA;    &#xA;}&#xA;&#xA;    in main():&#xA;  {  &#xA;    vec2 uv = (coords.xy-0.5*resolution.xy)/resolution.y;&#xA;    vec4 hx = hexFunction(uv*6.0f);&#xA;    float hasher = hash21(vec2(hx.z,hx.w)); // hexFunction returns id values on z and w channel&#xA;    int pixPos = int(hasher);&#xA;&#xA;    vec4 keys  = texelFetch( texture01, ivec2(pixPos,0), 0 ); // texture is 128 x 1&#xA;&#xA;    fragColor = keys;&#xA; }&#xA;&#xA;But I'm not getting the results I had intended and finding it a bit hard to debug what's happening with the numbers inside the shader.&#xA;&#xA;I've messed around with variations of the hash function: &#xA;&#xA;```float hash21(vec2 p)&#xA;{&#xA;    p += scale; // offset lowest negative value, so space is now zero to (2*scale)&#xA;    p = p/(scale*2.0); divide by scale*2 to make 0-1 range&#xA;    p.x = p.x * (1.0/7.0);&#xA;    p.y = p.y * (1.0/4.0);&#xA;    return mod(p.x+p.y,1.0);&#xA;} &#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and then tried scaled the pixelPox value afterwards: int pixPos = int (hasher*128.0);&lt;/p&gt;&#xA;&lt;p&gt;My thinking there was, do it in normalised range, then finally scale up to obtain correct pixel position.  Here's an example of the closest I've come and to put it in context of what I'm trying to achieve: &lt;a href=&quot;https://youtu.be/SfshrtW7eRc&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/SfshrtW7eRc&lt;/a&gt; And here's the shadertoy I've been using to prototype: &lt;a href=&quot;https://www.shadertoy.com/view/wtXyzl&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/wtXyzl&lt;/a&gt; I've set up my midi texture exactly like the FFT input in shadertoy, only difference is the midi texture has less values.&lt;/p&gt;&#xA;&lt;p&gt;Is this even possible to begin with? I've got close enough to suggest it is, I'm just not understanding how to implement the hash/mapping function properly.&lt;/p&gt;&#xA;&lt;p&gt;If anyone has any ideas please let me know, i'm at my wits end here.&lt;/p&gt;&#xA;" OwnerUserId="13580" LastActivityDate="2020-06-21T17:38:51.567" Title="Open GL mapping/hash function on hexagon grid, translating from a cell ID to pixel location on 1d texture" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9963" PostTypeId="1" CreationDate="2020-06-21T19:00:43.753" Score="1" ViewCount="79" Body="&lt;p&gt;I am writing a very simple rendering engine. I have already made a few tests, but somehow the images it creates look wrong. Objects that are further away from the camera look larger than objects closer to the camera. I have constructed this example:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;pos = [-10, 0, 0] # Camera position&#xA;target = [1, 0, 0] # Camera looks at this point&#xA;up = [0, 0, 1] # z direction is &amp;quot;up&amp;quot;&#xA;&#xA;fov_y = 25 * degree # field of view in y direction (camera y axis)&#xA;aspect_ratio = 1&#xA;near = 0.01 # Near clipping plane distance&#xA;far = 5000 # Far clipping plane distance&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I added two lines to the scene, a red one from &lt;code&gt;[1, 0, 0]&lt;/code&gt; to &lt;code&gt;[1, 0, 1]&lt;/code&gt; and a black one from &lt;code&gt;[4, 0, 0]&lt;/code&gt; to &lt;code&gt;[4, 0, 1]&lt;/code&gt;. The black one is clearly further away from the camera, but appears larger:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/oCPAg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oCPAg.png&quot; alt=&quot;Two overlapping vertical lines starting from the same bottom point. The red one is thicker and smaller than the black one.&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;From the above description, at first I have constructed the view matrix&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;V = [[0, -1, 0,   0],&#xA;     [0,  0, 1,   0],&#xA;     [1,  0, 0, -10],&#xA;     [0,  0, 0,   1]]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;which seems to be correct. The perspective matrix I calculated is&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;P = [[4.5107,      0,         0,     0],&#xA;     [0,      4.5107,         0,     0],&#xA;     [0,           0, -1.000004, -0.02],&#xA;     [0,           0,         -1,    0]]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm assuming the problem is somewhere here. The full transformation matrix is (using numpy):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;T = numpy.dot(P, V)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and the transformed points:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;p_transformed = numpy.dot(p_untransformed, T.T) # Transpose on the right hand side&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;For example, &lt;code&gt;[1, 0, 1]&lt;/code&gt; becomes &lt;code&gt;[0, 4.5107, 8.98, 9]&lt;/code&gt; and &lt;code&gt;[4, 0, 1]&lt;/code&gt; becomes &lt;code&gt;[0, 4.5107, 5.98, 6]&lt;/code&gt; and since the last step is to divide the first three components by the last one, this results in the second line being larger than the first one.&lt;/p&gt;&#xA;&lt;p&gt;Is there a mistake somewhere? If so, where is it?&lt;/p&gt;&#xA;&lt;h2&gt;Edit: Formulae&lt;/h2&gt;&#xA;&lt;p&gt;Here are the formulae I used:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sAVdJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sAVdJ.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;d = normalized(target - pos) # direction vector of the camera&#xA;r = normalized(cross(d, up)) # x unit vector in camera space&#xA;u = normalized(cross(r, d)) # y unit vector in camera space&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Furthermore, the formula for P is&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/nsPTz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/nsPTz.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;(&lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Source&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;n, f # position of near an far clipping plane&#xA;t = n * tan(0.5 * radians(fov_y))&#xA;b = -t&#xA;r = t * aspect_ratio&#xA;l = -r&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13581" LastEditorUserId="13581" LastEditDate="2020-06-21T20:11:53.250" LastActivityDate="2020-06-21T20:11:53.250" Title="Why does my self-written rendering engine make further away objects look larger?" Tags="&lt;rendering&gt;&lt;transformations&gt;&lt;mathematics&gt;&lt;projections&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="9964" PostTypeId="1" AcceptedAnswerId="9967" CreationDate="2020-06-21T21:49:38.283" Score="1" ViewCount="53" Body="&lt;p&gt;What are some state of the art methods/algorithms to find geodesics on arbitrary manifold meshes?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-06-22T07:06:58.663" Title="Finding geodesics on a mesh?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9965" PostTypeId="2" ParentId="9905" CreationDate="2020-06-22T02:02:03.230" Score="0" Body="&lt;p&gt;I found a paper from 1997 that addresses this subject: &lt;a href=&quot;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.6799&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.6799&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13472" LastActivityDate="2020-06-22T02:02:03.230" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9967" PostTypeId="2" ParentId="9964" CreationDate="2020-06-22T07:06:58.663" Score="2" Body="&lt;p&gt;There can be much dispute on which work is considered best or state-of-the-art. It will depend on your application. However, I'd like to recommend to give a look at this paper by Keenan Crane et al. It is impressive in terms of computational speed. Also, It is simple to implement.&lt;/p&gt;&#xA;&lt;p&gt;Crane et al. Geodesics in heat: A new approach to computing distance based on heat flow. ACM TOG. 2013. (&lt;a href=&quot;https://dl.acm.org/doi/10.1145/2516971.2516977&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://dl.acm.org/doi/10.1145/2516971.2516977&lt;/a&gt;)&lt;/p&gt;&#xA;" OwnerUserId="13305" LastActivityDate="2020-06-22T07:06:58.663" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9968" PostTypeId="2" ParentId="9906" CreationDate="2020-06-22T09:30:25.160" Score="2" Body="&lt;p&gt;The open source implementation &lt;a href=&quot;https://sourceforge.net/projects/freeglut/&quot; rel=&quot;nofollow noreferrer&quot;&gt;FreeGLUT&lt;/a&gt; has these functions.&#xA;The geometry code can be found in &lt;a href=&quot;https://sourceforge.net/p/freeglut/code/HEAD/tree/trunk/freeglut/freeglut/src/fg_geometry.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;freeglut/freeglut/src/fg_geometry.c&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For the dodecahedron, these are the values:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#define DODECAHEDRON_NUM_VERT           20&#xA;#define DODECAHEDRON_NUM_FACES          12&#xA;#define DODECAHEDRON_NUM_EDGE_PER_FACE  5&#xA;#define DODECAHEDRON_VERT_PER_OBJ       (DODECAHEDRON_NUM_FACES*DODECAHEDRON_NUM_EDGE_PER_FACE)&#xA;#define DODECAHEDRON_VERT_ELEM_PER_OBJ  (DODECAHEDRON_VERT_PER_OBJ*3)&#xA;#define DODECAHEDRON_VERT_PER_OBJ_TRI   (DODECAHEDRON_VERT_PER_OBJ+DODECAHEDRON_NUM_FACES*4)    /* 4 extra edges per face when drawing pentagons as triangles */&#xA;/* Vertex Coordinates */&#xA;static GLfloat dodecahedron_v[DODECAHEDRON_NUM_VERT*3] =&#xA;{&#xA;               0.0f,  1.61803398875f,  0.61803398875f,&#xA;    -          1.0f,            1.0f,            1.0f,&#xA;    -0.61803398875f,            0.0f,  1.61803398875f,&#xA;     0.61803398875f,            0.0f,  1.61803398875f,&#xA;               1.0f,            1.0f,            1.0f,&#xA;               0.0f,  1.61803398875f, -0.61803398875f,&#xA;               1.0f,            1.0f, -          1.0f,&#xA;     0.61803398875f,            0.0f, -1.61803398875f,&#xA;    -0.61803398875f,            0.0f, -1.61803398875f,&#xA;    -          1.0f,            1.0f, -          1.0f,&#xA;               0.0f, -1.61803398875f,  0.61803398875f,&#xA;               1.0f, -          1.0f,            1.0f,&#xA;    -          1.0f, -          1.0f,            1.0f,&#xA;               0.0f, -1.61803398875f, -0.61803398875f,&#xA;    -          1.0f, -          1.0f, -          1.0f,&#xA;               1.0f, -          1.0f, -          1.0f,&#xA;     1.61803398875f, -0.61803398875f,            0.0f,&#xA;     1.61803398875f,  0.61803398875f,            0.0f,&#xA;    -1.61803398875f,  0.61803398875f,            0.0f,&#xA;    -1.61803398875f, -0.61803398875f,            0.0f&#xA;};&#xA;/* Normal Vectors */&#xA;static GLfloat dodecahedron_n[DODECAHEDRON_NUM_FACES*3] =&#xA;{&#xA;                0.0f,  0.525731112119f,  0.850650808354f,&#xA;                0.0f,  0.525731112119f, -0.850650808354f,&#xA;                0.0f, -0.525731112119f,  0.850650808354f,&#xA;                0.0f, -0.525731112119f, -0.850650808354f,&#xA;&#xA;     0.850650808354f,             0.0f,  0.525731112119f,&#xA;    -0.850650808354f,             0.0f,  0.525731112119f,&#xA;     0.850650808354f,             0.0f, -0.525731112119f,&#xA;    -0.850650808354f,             0.0f, -0.525731112119f,&#xA;&#xA;     0.525731112119f,  0.850650808354f,             0.0f,&#xA;     0.525731112119f, -0.850650808354f,             0.0f,&#xA;    -0.525731112119f,  0.850650808354f,             0.0f, &#xA;    -0.525731112119f, -0.850650808354f,             0.0f,&#xA;};&#xA;&#xA;/* Vertex indices */&#xA;static GLubyte dodecahedron_vi[DODECAHEDRON_VERT_PER_OBJ] =&#xA;{&#xA;     0,  1,  2,  3,  4, &#xA;     5,  6,  7,  8,  9, &#xA;    10, 11,  3,  2, 12, &#xA;    13, 14,  8,  7, 15, &#xA;&#xA;     3, 11, 16, 17,  4, &#xA;     2,  1, 18, 19, 12, &#xA;     7,  6, 17, 16, 15, &#xA;     8, 14, 19, 18,  9, &#xA;&#xA;    17,  6,  5,  0,  4, &#xA;    16, 11, 10, 13, 15, &#xA;    18,  1,  0,  5,  9, &#xA;    19, 14, 13, 10, 12&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;As for the second part of your question, tools such as &lt;a href=&quot;https://renderdoc.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;renderdoc&lt;/a&gt; allow you to export meshes which are used in a render. To do this, you must first take a capture, find the corresponding draw call in event browser, open the Mesh Viewer and click on the export icon. You can do this with almost any mesh input to a vertex shader drawn in a supported API.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/O9wtV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/O9wtV.png&quot; alt=&quot;Export any mesh with renderdoc&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13418" LastActivityDate="2020-06-22T09:30:25.160" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9969" PostTypeId="1" AcceptedAnswerId="9970" CreationDate="2020-06-22T19:39:30.110" Score="3" ViewCount="153" Body="&lt;p&gt;Is there a way to obtain a parametrized BRDF that smoothly interpolates between diffuse, glossy and mirror? For example, &lt;span class=&quot;math-container&quot;&gt;$\lambda = 0$&lt;/span&gt; would be perfectly diffuse, &lt;span class=&quot;math-container&quot;&gt;$\lambda=0.5$&lt;/span&gt; glossy and &lt;span class=&quot;math-container&quot;&gt;$\lambda = 1$&lt;/span&gt; a perfect mirror. Linear interpolation seems very wrong here.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kMAIT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kMAIT.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7035" LastActivityDate="2020-06-23T16:58:44.563" Title="BRDF that interpolates between diffuse, glossy and reflective?" Tags="&lt;pathtracing&gt;&lt;brdf&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9970" PostTypeId="2" ParentId="9969" CreationDate="2020-06-22T21:31:10.730" Score="5" Body="&lt;p&gt;Any microfacet BRDF with a roughness parameter will do something like this—for example using the GGX or Beckmann NDFs. When the roughness goes to zero it becomes a mirror; as roughness increases the reflection will be wider, and in the high-roughness limit should be essentially Lambert I think. Roughness is not necessarily limited to [0, 1] as roughness values higher than 1 are possible, but typically roughness = 1 will be very close to Lambert already.&lt;/p&gt;&#xA;&lt;p&gt;One thing to note about the roughness = 0 limit is that the NDF will become singular (a delta function), so will very likely break the shader code by producing infinite values or NaNs and such. So as a practical matter it might be necessary to special-case that, or clamp the roughness to some low minimum value like 0.0001.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-06-22T21:31:10.730" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9971" PostTypeId="2" ParentId="9961" CreationDate="2020-06-23T00:42:39.247" Score="3" Body="&lt;p&gt;The reason why ray-tracing is often used for achieving as-realistic-as-possible &lt;a href=&quot;http://graphics.ucsd.edu/%7Ehenrik/papers/egwr99/rendering_wet_materials_egwr99.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;wet appearance&lt;/a&gt; is their reflective behavior. A thin liquid film on the surface reflects photons like a mirror. If you target real-time rendering, you will have to fake the reflections (or rely on RTX :) There are two ways I can quickly think of: placing reflection probes in the scene using cube-maps or using screen space reflections.&lt;/p&gt;&#xA;&lt;h3&gt;Reflection probes with cube-maps&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;good for static scenes, you can pre-compute many of them&lt;/li&gt;&#xA;&lt;li&gt;allow objects outside of the current viewing frustum to be seen in the mirrors&lt;/li&gt;&#xA;&lt;li&gt;inaccurate due to limited number of probes&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;There is a great &lt;a href=&quot;https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-reflection.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;extensive tutorial&lt;/a&gt; by Sébastien Lagarde on reflections which continues (what a coincidence) with &lt;a href=&quot;https://www.fxguide.com/fxfeatured/game-environments-partb/&quot; rel=&quot;nofollow noreferrer&quot;&gt;part B&lt;/a&gt; on wet surfaces and there is part C as well. Make sure to check them out!&lt;/p&gt;&#xA;&lt;h3&gt;Screen-space reflections&lt;/h3&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;fine also for dynamic scenes&lt;/li&gt;&#xA;&lt;li&gt;only objects in the current viewing frustum can be seen in the mirrors&lt;/li&gt;&#xA;&lt;li&gt;accurate within the frustum&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Screen space reflections are explained as part of this &lt;a href=&quot;https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-reflection.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;awesome series&lt;/a&gt; by David Lettier.&lt;/p&gt;&#xA;&lt;h3&gt;Subsurface scattering&lt;/h3&gt;&#xA;&lt;p&gt;Regarding the discussion on subsurface scattering, any organic tissue exposes this property. We just observe it the most on skin or leaves, but the same effect is observed inside the body. Just read section 3.3 of &lt;a href=&quot;http://www.cvg.ait.kyushu-u.ac.jp/papers/2014_2016/1-gridicp-cameraready.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;One significant casual effect under endoscopic environment is a strong subsurface scattering on the surface of internal organs.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I suggest to use at least some &lt;a href=&quot;https://therealmjp.github.io/posts/sss-intro/&quot; rel=&quot;nofollow noreferrer&quot;&gt;post-processing technique&lt;/a&gt; for that.&lt;/p&gt;&#xA;" OwnerUserId="13370" LastEditorUserId="13370" LastEditDate="2020-06-23T10:38:50.183" LastActivityDate="2020-06-23T10:38:50.183" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9972" PostTypeId="1" AcceptedAnswerId="9981" CreationDate="2020-06-23T12:12:11.673" Score="2" ViewCount="116" Body="&lt;p&gt;Sometimes in CG literature a transformation is equated to a coordinate system change. This is fine as long as the transformation includes only a rotation and a translation. When scaling is involved, however, this seems like an incorrect interpretation. The problem is specifically with how lengths and angles are measured after the transformation. Angles and length are invariant to coordinate system change: &lt;span class=&quot;math-container&quot;&gt;$\langle a, b \rangle = \sum_{i,j}g_{ij}a^ib^j$&lt;/span&gt;. In graphics, this is often substituted with the expression valid only for orthonormal bases: &lt;span class=&quot;math-container&quot;&gt;$\langle a, b \rangle = \sum_{i}a_ib^i$&lt;/span&gt;, regardless of the supposed basis that &lt;span class=&quot;math-container&quot;&gt;$a,b$&lt;/span&gt; are in (the index of &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; is lowered as if the basis was orthonormal without involving the metric tensor). So while this makes sense as a transformation, I do not see how this is reconciled with the idea of a change of basis. Am I missing something, or is the interpretation wrong? (think of DX/GL's standard transformations between spaces in the rendering pipeline)&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2020-06-27T06:28:30.160" Title="Transformations and change of basis in CG" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9973" PostTypeId="2" ParentId="9969" CreationDate="2020-06-23T16:58:44.563" Score="3" Body="&lt;p&gt;Although microfacet bxdfs do this to some degree, a roughness of 1 is not really the same as a diffuse.&lt;/p&gt;&#xA;&lt;p&gt;I don't know of any single lobe which can properly blend between them. You would probably have to gradually ignore the reflection direction or include rays farther from it at a faster rate, which may make your glossy useless.&lt;/p&gt;&#xA;&lt;p&gt;Production renderer materials layer various lobes including a diffuse/specular so they can blend between them or combine them together.&lt;/p&gt;&#xA;&lt;p&gt;You can see how the arnolds blends thier lobes here:&#xA;&lt;a href=&quot;https://autodesk.github.io/standard-surface/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://autodesk.github.io/standard-surface/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-06-23T16:58:44.563" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9974" PostTypeId="2" ParentId="3804" CreationDate="2020-06-23T18:21:18.097" Score="-1" Body="&lt;p&gt;This is how anti-aliasing works:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;render the outline in bilevel rendering at four times the size&lt;/li&gt;&#xA;&lt;li&gt;take the averages of each 4×4 block&lt;/li&gt;&#xA;&lt;li&gt;blend them with correct gamma between the foreground and background&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="13594" LastActivityDate="2020-06-23T18:21:18.097" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9975" PostTypeId="1" CreationDate="2020-06-24T10:41:56.160" Score="1" ViewCount="89" Body="&lt;p&gt;Okay, so I'm currently using the IAGetVertexBuffers() method and I'd like to loop through some of the returned buffers to verify the contents.&lt;/p&gt;&#xA;&lt;p&gt;However, I'm kind of new to DirectX and C++ in general. I tried using a a simple C++ 11 loop:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;for (const auto&amp;amp; verts : veBuffer) {&#xA;        std::cout &amp;lt;&amp;lt; verts &amp;lt;&amp;lt; std::endl;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;But I get an error saying this statement requires a suitable begin statement. Any suggestions would be appreciated at this point.&lt;/p&gt;&#xA;" OwnerUserId="11412" LastActivityDate="2020-06-26T07:57:59.233" Title="How do you loop through the contents of a buffer in DX11?" Tags="&lt;c++&gt;&lt;directx11&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="9976" PostTypeId="2" ParentId="9918" CreationDate="2020-06-24T12:55:58.213" Score="1" Body="&lt;p&gt;Consider &lt;span class=&quot;math-container&quot;&gt;$f(v) := S(v;z_1)\cdot S(v;z_2)$&lt;/span&gt; with &lt;span class=&quot;math-container&quot;&gt;$z_1=z_2=&amp;lt;1,0,0&amp;gt;$&lt;/span&gt;. Then&#xA;&lt;span class=&quot;math-container&quot;&gt;$$f(v) = \max(v_1,0)\cdot\max(v_1,0) = 0, \qquad \text{ if } v_1&amp;lt;0, $$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$f(v) = \max(v_1,0)\cdot\max(v_1,0) = v_1^2 \qquad \text{ if } v_1\ge 0. $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;We want to find a &lt;span class=&quot;math-container&quot;&gt;$\tilde z$&lt;/span&gt; such that &lt;span class=&quot;math-container&quot;&gt;$f(v) \stackrel{!}{=} S(v;\tilde z) = \max(v\cdot\tilde z,0)$&lt;/span&gt; for all unit vectors &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt;. But &lt;span class=&quot;math-container&quot;&gt;$v=&amp;lt;0,\pm 1,0&amp;gt;$&lt;/span&gt; implies &lt;span class=&quot;math-container&quot;&gt;$\tilde z_2 = 0$&lt;/span&gt; and similarly &lt;span class=&quot;math-container&quot;&gt;$v=&amp;lt;0,0,\pm 1&amp;gt;$&lt;/span&gt; implies &lt;span class=&quot;math-container&quot;&gt;$\tilde z_3=0$&lt;/span&gt;. Consequently, &lt;span class=&quot;math-container&quot;&gt;$S(v;\tilde z) = \max(v_1 \tilde z_1, 0)$&lt;/span&gt; and it is not possible to choose &lt;span class=&quot;math-container&quot;&gt;$\tilde z_1$&lt;/span&gt; such that&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\max(v_1\tilde z_1,0) = f(v)$$&lt;/span&gt;&#xA;for all unit vectors &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastActivityDate="2020-06-24T12:55:58.213" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9978" PostTypeId="1" CreationDate="2020-06-25T08:32:33.937" Score="2" ViewCount="78" Body="&lt;p&gt;My understanding is:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;the 'framebuffer' in OpenGL is a collection of buffers: many (due to swapping or stereo rendering) color buffers, (only one?) z-buffer and (only one?) stencil buffer;&lt;/li&gt;&#xA;&lt;li&gt;each OpenGL application has a 'default framebuffer', but can have more 'framebuffer objects';&lt;/li&gt;&#xA;&lt;li&gt;a 'compositing window manager' aka 'compositor' only cares about an application's current front color buffer of its 'default framebuffer'. The compositor calls this buffer 'off screen buffer'.&lt;/li&gt;&#xA;&lt;li&gt;the compositor reads all applications' 'off screen buffers' and composites them onto a single image called screen buffer' aka 'video buffer' aka 'regen(eration) buffer';&lt;/li&gt;&#xA;&lt;li&gt;a display controller will read (scan?) the 'screen buffer' and convert it to a signal to be sent to the physical screen.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Main question:&lt;/p&gt;&#xA;&lt;p&gt;Can it be (eg. if I run a video game full-screen) that the compositor could simply declare the application's off-screen buffer the same as its 'screen buffer' so that the same location in memory that fragments had their colors originally blended onto will actually be the location the display controller will read from?&#xA;I.e. OpenGL will render to some area in either VRAM or RAM and without coincidence this same location will be read by the display controller even after any sort of compositor stage.&lt;/p&gt;&#xA;&lt;p&gt;Additionally:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Does the compositor designate the 'off screen buffer' for the application (or multiple locations for double/triple buffering or stereo) and it's up to the application to fill that area in memory and &amp;quot;ring the compositor&amp;quot; when its ready or&lt;/li&gt;&#xA;&lt;li&gt;does the application create the buffer and the compositor is only told where to read from (eg. the app's OpenGL draws to a back buffer, designates it as the front and tells the compositor to read it)?&lt;/li&gt;&#xA;&lt;li&gt;or is it a mix of the two?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="13601" LastActivityDate="2020-06-28T05:59:41.977" Title="Can the framebuffer in OpenGL jargon or its color buffer end up being the one and the same memory location as the one scanned by a display controller?" Tags="&lt;opengl&gt;&lt;buffers&gt;&lt;frame-buffer&gt;&lt;compositing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9979" PostTypeId="2" ParentId="9975" CreationDate="2020-06-26T07:57:59.233" Score="2" Body="&lt;p&gt;There are a couple of issues.  First you need to make sure that &lt;code&gt;veBuffer&lt;/code&gt; has the correct type, so that probably means you need to cast it to &lt;em&gt;pointer to vertex&lt;/em&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;const auto vertices = reinterpret_cast&amp;lt;const Vertex*&amp;gt;(reBuffer);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Second a range-based &lt;code&gt;for&lt;/code&gt;-loop needs to know where the range ends and giving it a raw pointer does not provide that information, so you cannot use it here.  Instead you will need to know how many vertices there are and use a normal &lt;code&gt;for&lt;/code&gt;-loop:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;const size_t numVerts = 32;&#xA;for (size_t i = 0; i &amp;lt; numVerts; ++i) {&#xA;    const Vertex&amp;amp; vert = vertices[i];&#xA;    ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11344" LastActivityDate="2020-06-26T07:57:59.233" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9980" PostTypeId="2" ParentId="9978" CreationDate="2020-06-26T17:40:15.377" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Can it be (eg. if I run a video game full-screen) that the compositor could simply declare the application's off-screen buffer the same as its 'screen buffer'&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Yes. This is one of the things that &amp;quot;fullscreen exclusive&amp;quot; mode would do for you: it enables the application's swap buffers (front/back default framebuffers) to be directly scanned out by the GPU's display engine, without needing to go through a compositor first, saving a little bit of performance.&lt;/p&gt;&#xA;&lt;p&gt;Nowadays there is also support for &amp;quot;borderless windowed fullscreen&amp;quot; (see &lt;a href=&quot;https://devblogs.microsoft.com/directx/demystifying-full-screen-optimizations/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fullscreen Optimizations&lt;/a&gt; for Windows 10 for instance, though I expect other OSes have similar functionality). This is a mode where you still go through the compositor, but the compositor has a shortcut method when it detects that your app is covering the full screen with no other windows rendering on top of it. In that case it can skip the compositing steps and scan out directly from your swap buffers, while retaining the ability to seamlessly switch back to compositing mode if another window should pop up (such as an overlay, or if you Alt+Tab away from the game, etc.)&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Does the compositor designate the 'off screen buffer' for the application&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Also yes. When you set up an OpenGL context (or any other graphics API context) your app will request the number and format of swap buffers it wants (subject to the choices offered by the OS/driver); then the OS/driver will give you the buffers, and you render into them. You can create your own framebuffers as well, such as depth/stencil buffers or other offscreen buffers for whatever purpose, but ultimately your app will need to put the image you want to show up on the screen into the provided swap buffers. The buffers will be set up so the compositor can also access them. When you do a glSwapBuffers call, you're informing the OS/compositor that you finished a new frame and asking it to please show that on the screen (either by scanning it out directly or by including it in the next compositor frame).&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-06-26T17:47:51.697" LastActivityDate="2020-06-26T17:47:51.697" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9981" PostTypeId="2" ParentId="9972" CreationDate="2020-06-27T06:28:30.160" Score="2" Body="&lt;p&gt;You're correct, we don't usually worry about pulling the inner product through a change of basis in graphics. As a practical matter, calculations that depend on angles and distances, such as lighting and shading, are always done in world space or in a space orthonormally related to it (e.g. camera space).&lt;/p&gt;&#xA;&lt;p&gt;The place where non-orthonormal transformations show up is usually in local-to-world transforms of meshes—most frequently with skeletal animation, where things get deformed, or where bones are set up with non-orthonormal coordinates for rigging/animation reasons. However in those instances we are always bringing the vertices, normals, etc into world space or camera space to process. We neither push back the world inner product into the local spaces, nor do we want to pull a locally defined inner product into world space, as neither of those is really useful for the typical kinds of things we need to do.&lt;/p&gt;&#xA;&lt;p&gt;(And for the normals, we &lt;em&gt;do&lt;/em&gt; know how to use the inverse transpose matrix to transform those properly, thank goodness!)&lt;/p&gt;&#xA;&lt;p&gt;The other big non-orthonormal transformation in graphics is the projection matrix, but again, we don't really ever want to use the inner product in post-projective space, so the issue doesn't really arise. We just keep all our inner product-ing in world space.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-06-27T06:28:30.160" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9982" PostTypeId="1" CreationDate="2020-06-27T19:14:14.580" Score="0" ViewCount="27" Body="&lt;p&gt;I am reading the 1987 paper on Geodesics on polyhedra and I am confused on something.&lt;/p&gt;&#xA;&lt;p&gt;The paper states:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$I1==NIL$&lt;/span&gt;, the channel is simply that part of &lt;span class=&quot;math-container&quot;&gt;$f’$&lt;/span&gt; to the left of &lt;span class=&quot;math-container&quot;&gt;$\beta_2c_2$&lt;/span&gt;; and if&#xA;&lt;span class=&quot;math-container&quot;&gt;$I2==NIL$&lt;/span&gt;, the channel is that to the right of &lt;span class=&quot;math-container&quot;&gt;$\beta_1c_1$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&amp;quot;Right&amp;quot; and &amp;quot;left&amp;quot; are pretty meaningless terms. So far I have at least 3 interpretations of the areas they mean:&lt;/p&gt;&#xA;&lt;p&gt;Orthogonal projection onto the opposite edge:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sWPxd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sWPxd.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Angular projection based on some angular parameter:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/8VCwU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8VCwU.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Or the entire face.&lt;/p&gt;&#xA;&lt;p&gt;All of these can be thought of as &amp;quot;the left&amp;quot; of the red segment. Which one is the one the authors meant?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-06-27T19:14:14.580" Title="MMP Geodesic algorithm I need clarification" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;&lt;triangulation&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9984" PostTypeId="2" ParentId="9946" CreationDate="2020-06-28T09:48:25.183" Score="5" Body="&lt;p&gt;In math, geometry and physics it is common practice to use the coordinates &lt;span class=&quot;math-container&quot;&gt;$(u,v)$&lt;/span&gt; to represent an arbitrary parameterization, including those of a &lt;a href=&quot;https://en.wikipedia.org/wiki/Surface_(mathematics)&quot; rel=&quot;nofollow noreferrer&quot;&gt;surface&lt;/a&gt; in a 3d Euclidean space. Since the coordinates of the parameterisation might be arbitrary (it could be an angle, or a function of the Euclidean coordinates &lt;span class=&quot;math-container&quot;&gt;$(x,y,z)$&lt;/span&gt;, or something else), it is helpful to distinguish them from the coordinates used to represent the wider Euclidean space in which the surface exists.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;span class=&quot;math-container&quot;&gt;$(u,v)$&lt;/span&gt;-notation caught on in computer graphics for the same reason: it clarifies that the coordinates used to index into your texture do not necessarily align with the world space (or view space) coordinates &lt;span class=&quot;math-container&quot;&gt;$(x,y,z)$&lt;/span&gt;, but is an index into a parameterisation of a surface in that space.&lt;/p&gt;&#xA;" OwnerUserId="13618" LastEditorUserId="13618" LastEditDate="2020-06-28T13:19:58.030" LastActivityDate="2020-06-28T13:19:58.030" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9986" PostTypeId="1" AcceptedAnswerId="9987" CreationDate="2020-06-29T15:20:17.557" Score="1" ViewCount="69" Body="&lt;p&gt;When implementing explicit light sampling, I am separating the monte-carlo approximation to two parts&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{1}{N+M}(\sum^N \text{direct} + \sum^M \text{indirect})$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\text{direct} = \frac{\text{bsdf} \times C \times cos(\theta)}{p}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am confused as how to obtain &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; for direct lightning.  My light source is an arbitrary triangularized mesh and I am sampling random points from it's surface.&lt;/p&gt;&#xA;&lt;p&gt;A solution was presented here: &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4288/path-weight-for-direct-light-sampling&quot;&gt;Path weight for direct light sampling&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{A}{r^2} (N_\text{light} \cdot -L)$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Where does this come from?  I'm asking for a reference or a derivation. Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7035" LastEditorUserId="7035" LastEditDate="2020-06-29T15:33:14.167" LastActivityDate="2020-06-29T16:54:17.107" Title="Probability density for explicit light sampling" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9987" PostTypeId="2" ParentId="9986" CreationDate="2020-06-29T16:54:17.107" Score="4" Body="&lt;p&gt;It comes from the relation between the area formulation and the solid angle formulation of the rendering equation: &lt;span class=&quot;math-container&quot;&gt;$d\omega = \frac{\cos\theta_L}{r^2}dA$&lt;/span&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://arxiv.org/abs/1205.4447&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://arxiv.org/abs/1205.4447&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2020-06-29T16:54:17.107" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9988" PostTypeId="1" AcceptedAnswerId="9990" CreationDate="2020-06-29T17:56:02.507" Score="2" ViewCount="140" Body="&lt;p&gt;I am working on a small simulation software which has a 3D Renderer that is using OpenGL. I render objects to the screen as triangle meshes. To be able to select the triangles on the screen, I have implemented the Möller–Trumbore ray-triangle intersection algorithm. The algorithm works fine. However, I have another problem. My triangles are not static in the world. When I change the location of the triangle on the screen, I have to change the input vertices of the triangle in the algorithm but I don't know how to do it mathematically. Is there a way to use this algorithm for dynamic objects?&lt;/p&gt;&#xA;" OwnerUserId="13625" LastEditorUserId="13625" LastEditDate="2020-06-29T18:21:40.340" LastActivityDate="2020-07-01T18:56:44.187" Title="Dynamic Ray-Triangle Intersection" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="9989" PostTypeId="1" CreationDate="2020-06-30T11:08:14.570" Score="4" ViewCount="103" Body="&lt;p&gt;I have an isosurface/mesh (generated via marching cubes) of a micro-CT scan. Originally the surface looks very noisy, which becomes prevalent when the mean curvature is visualized:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xa4aIm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xa4aIm.jpg&quot; alt=&quot;unedited surface&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;To reduce the noise I've applied Gaussian smoothing to the imagedata and regenerated the mesh. This time, artificial looking rings appear:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NIsalm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NIsalm.png&quot; alt=&quot;surface after smoothing&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I would like to reduce these circles/rings/terracing artifacts to obtain a more smooth distribution of the curvature values.&lt;/p&gt;&#xA;&lt;p&gt;I was wondering if anybody would know the name of this problem since I'm struggling to find anything similar online. All help is appreciated!&lt;/p&gt;&#xA;" OwnerUserId="13632" LastEditorUserId="13632" LastEditDate="2020-06-30T12:17:38.423" LastActivityDate="2020-07-04T12:56:43.197" Title="Reducing artificial rings in mean curvature of mesh" Tags="&lt;mesh&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9990" PostTypeId="2" ParentId="9988" CreationDate="2020-06-30T19:26:45.777" Score="3" Body="&lt;p&gt;There are 2 ways to go about intersecting the triangle. Let the vertices of the triangle have positions &lt;span class=&quot;math-container&quot;&gt;$v_1, v_2, v_3$&lt;/span&gt;. Let the ray have origin &lt;span class=&quot;math-container&quot;&gt;$o$&lt;/span&gt; and direction &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt;. Let the model (4x4) matrix be &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;To find the new vertex coordinates one extends the positions with a 1 (to allow for translations) and multiplies by the model matrix. Let &lt;span class=&quot;math-container&quot;&gt;$u_i = (v_{i,x}, v_{i,y}, v_{i,z}, 1)$&lt;/span&gt; then &lt;span class=&quot;math-container&quot;&gt;$w_i = Mu_i$&lt;/span&gt;. The resulting vertex positions are: &lt;span class=&quot;math-container&quot;&gt;$v_i' = (w_{i,x}, w_{i,y}, w_{i,z})$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The other option is to transform the ray with the inverse matrix &lt;span class=&quot;math-container&quot;&gt;$M^{-1}$&lt;/span&gt; and intersect with the non-transformed triangle. To achieve this extend &lt;span class=&quot;math-container&quot;&gt;$o$&lt;/span&gt; with a 4th coord of 1 (to account for translation) and extend &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; with a 4th coord of 0 (to ignore translation) then multiply both with &lt;span class=&quot;math-container&quot;&gt;$M^{-1}$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$o' = M^{-1}(o_x, o_y, o_z, 1)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d' = M^{-1}(d_x, d_y, d_z, 0)$$&lt;/span&gt;&#xA;Drop the 4th coordinate of &lt;span class=&quot;math-container&quot;&gt;$o'$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$d'$&lt;/span&gt; then intersect with the triangle formed by &lt;span class=&quot;math-container&quot;&gt;$v_1, v_2, v_3$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2020-07-01T18:56:44.187" LastActivityDate="2020-07-01T18:56:44.187" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9991" PostTypeId="1" CreationDate="2020-07-01T12:29:06.633" Score="1" ViewCount="117" Body="&lt;p&gt;Recently I've been looking at Vulkan, and one thing that I noticed is that the application is responsible for choosing which buffer to render to in the case of multiple buffering.&lt;/p&gt;&#xA;&lt;p&gt;This got me thinking: since one of the benefits of multiple buffering is that the GPU can start rendering the next frame before the previous one is finished, is it worth it to create more offscreen buffers as well, like the G-Buffers or the HDR color buffers (especially in the older APIs like OpenGL and D3D11)? Will it have performance benefits? Is this common practice, or totally dumb?&lt;/p&gt;&#xA;" OwnerUserId="13637" LastActivityDate="2020-07-01T12:29:06.633" Title="OpenGL/D3D11 offscreen render multiple buffering" Tags="&lt;opengl&gt;&lt;vulkan&gt;&lt;directx11&gt;&lt;directx&gt;&lt;direct3d&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9992" PostTypeId="1" AcceptedAnswerId="9994" CreationDate="2020-07-02T09:58:24.150" Score="2" ViewCount="142" Body="&lt;p&gt;I've seen two different perspective projection matrices being used but I want to know which one of them is the best. I think that they both output the same but I'm not sure. So if anyone can help me select which one to use I would greatly appreciate it&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gVMit.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gVMit.png&quot; alt=&quot;perspective projection matrix 1&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ycuEv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ycuEv.png&quot; alt=&quot;perspective projection matrix 2&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13639" LastEditorUserId="13095" LastEditDate="2020-07-15T20:17:04.957" LastActivityDate="2020-07-15T20:17:04.957" Title="Which perspective projection matrix to use" Tags="&lt;matrix&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9994" PostTypeId="2" ParentId="9992" CreationDate="2020-07-02T16:41:19.427" Score="1" Body="&lt;p&gt;Even though you can find multiple slightly different formulations for the perspective matrix on the internet, they all do more or less the same thing. They project everything inside a space with the shape of a truncated pyramid (your view frustum) into a space with the shape of a quad and a defined value range (clip space).&lt;/p&gt;&#xA;&lt;p&gt;Most differences are related to how you define the shape of your frustum. For example, your first matrix uses a height, a width, and an angle together with z-far and z-near value. The second one uses just an x- and y-FOV and the z-far and z-near values to describe the shape of the frustum. This explains the differences in the upper left section.&lt;/p&gt;&#xA;&lt;p&gt;So what about the lower right section? One big issue here is, that you can choose to use column or row vectors for your vertices/points. Column vectors are multiplied on the right-hand side and row vectors on the left-hand side. The choice you make determines if you have to transpose (switch columns and rows) your matrix or not. The matrices you presented are just targetting different vector representations. I can't tell you without testing/rereading which one is meant for which representation, but if you transpose one of them, they start looking quite similar.&lt;/p&gt;&#xA;&lt;p&gt;There are still some other minor differences like varying signs, different factors, or a missing addition.&#xA;The derivation of your second matrix can be found &lt;a href=&quot;http://www.codinglabs.net/article_world_view_projection_matrix.aspx&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&#xA;I can't tell you exactly where those small differences in the first matrix come from, but you can find some possible explanations in &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link&lt;/a&gt; (Have a look into the &amp;quot;Are There Different Ways of Building this Matrix?&amp;quot; section).&#xA;Another good read is &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Which matrix is &amp;quot;correct&amp;quot; depends on how your Graphic API defines its coordinate systems and it's clip space (For OpenGL - you can take the one from the last link I provided). However, there is no &amp;quot;best&amp;quot; choice because they all do more or less the same. Unless you have no special needs for your program (depth precision) or other fancy ideas I can't think of now, just pick the one suited for your API with the inputs (FOV vs width+height+angle) that you like most and start having fun. ;)&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-07-02T16:41:19.427" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9995" PostTypeId="1" CreationDate="2020-07-03T14:43:10.617" Score="0" ViewCount="49" Body="&lt;p&gt;As the title says, you are able to compose the ViewMatrix and the ProjectionMatrix into one instead of multiplying a vector by the individual matrices.&lt;/p&gt;&#xA;&lt;p&gt;Instead of doing this at run time for each item:&#xA;Vector * ViewMatrix -&amp;gt; Vector ProjectionMatrix&lt;/p&gt;&#xA;&lt;p&gt;Do this at the start:&#xA;ViewMatrix * ProjectionMatrix -&amp;gt; ComposedMatrix&lt;/p&gt;&#xA;&lt;p&gt;Then when drawing vectors:&#xA;Vector * ComposedMatrix&lt;/p&gt;&#xA;&lt;p&gt;This would minimize the number of necessary matrix multiplications. Is there any reason not to do this?&lt;/p&gt;&#xA;" OwnerUserId="13639" LastEditorUserId="13095" LastEditDate="2020-07-05T16:47:35.593" LastActivityDate="2020-07-05T16:47:35.593" Title="Compose ViewMatrix and ProjectionMatrix" Tags="&lt;matrix&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="9996" PostTypeId="2" ParentId="9989" CreationDate="2020-07-04T00:22:06.763" Score="1" Body="&lt;p&gt;This is just an educated guess, but the artifacts in your visualization of the curvature values reminded me of &lt;a href=&quot;https://en.wikipedia.org/wiki/Moir%C3%A9_pattern&quot; rel=&quot;nofollow noreferrer&quot;&gt;Moiré patterns&lt;/a&gt;. The images in the Wikipedia article don't show circle patterns like the ones you are observing, but I have seen similar patterns before when I tried to visualize highly oscillating functions. &lt;em&gt;(Edit: The function you are visualizing, i.e. the curvature, is likely not oscillating quickly. However, the following example still illustrates that it may not only be the discretization or mesh generation algorithm that is problematic, but also the computation of the curvature.)&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;For example, if you try to visualize the function &lt;span class=&quot;math-container&quot;&gt;$f(x,y) = |\cos((x^2+y^2)^2)|$&lt;/span&gt; for &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt; ranging from &lt;span class=&quot;math-container&quot;&gt;$-3.3$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$3.3$&lt;/span&gt; on a grid of &lt;span class=&quot;math-container&quot;&gt;$256\times 256$&lt;/span&gt; pixels, what you get is the following image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LIxCj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LIxCj.png&quot; alt=&quot;Moiré pattern&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The Moiré patterns appear in this image since the function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; is only evaluated at a single point (x,y) for every pixel, although each pixel covers not just a single point but an area. A better visualization of the function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; would involve integrating over the corresponding area for each pixel, which &lt;s&gt;would result in a uniform gray color near the image boundaries&lt;/s&gt; reduces the Moiré patterns.&lt;/p&gt;&#xA;&lt;p&gt;My guess is that there is something similar happening in your situation. As for solving your problem, this essentially means that the curvature is computed in an erroneous way if the discretization is too coarse. So you could either try to improve the algorithm that is used for the computation of the curvature or simply use a finer discretization. Unless, of course, if the rings really are a feature of your surface, in which case they will not disappear as lightxbulb pointed out.&lt;/p&gt;&#xA;&lt;p&gt;In case you are interested, I have attached the C++ code that I used to generate the above image. Note that if you increase &lt;code&gt;X&lt;/code&gt; and &lt;code&gt;Y&lt;/code&gt; while keeping &lt;code&gt;lX&lt;/code&gt; and &lt;code&gt;lY&lt;/code&gt; constant, the discretization is refined and the Moiré patterns will disappear.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;#include &amp;lt;string&amp;gt;&#xA;#include &amp;lt;cmath&amp;gt;&#xA;&#xA;using namespace std;&#xA;&#xA;void WriteGrayscalePPM(const std::string&amp;amp; file, const std::vector&amp;lt;unsigned char&amp;gt;&amp;amp; values, const unsigned int X) {&#xA;  const unsigned int Y = values.size ( ) / X;&#xA;  &#xA;  std::ofstream image(file.c_str(), ios::out | ios::binary);&#xA;  image &amp;lt;&amp;lt; &amp;quot;P6\n&amp;quot; &amp;lt;&amp;lt; X &amp;lt;&amp;lt; ' ' &amp;lt;&amp;lt; Y &amp;lt;&amp;lt; &amp;quot;\n255\n&amp;quot;;&#xA;  for (unsigned int i=0; i&amp;lt;X*Y; i++) {&#xA;    unsigned char color[3] = {values[i], values[i], values[i]};&#xA;    image.write((const char*)color, 3*sizeof(char));&#xA;  }&#xA;}&#xA;&#xA;int main(int argc, char **argv) {&#xA;  const int X = 256;&#xA;  const int Y = 256;&#xA;  const double lX = 3.3;&#xA;  const double lY = 3.3;&#xA;  &#xA;  std::vector&amp;lt;unsigned char&amp;gt; values(X*Y, 0);&#xA;  &#xA;  for (int y=0; y&amp;lt;Y; y++) for (int x=0; x&amp;lt;X; x++) {&#xA;    double xd = lX / (X/2) * (x - X/2);&#xA;    double yd = lY / (Y/2) * (y - Y/2);&#xA;    double d = sqrt(xd*xd + yd*yd);&#xA;    &#xA;    values[x + y*X] = 255*abs(cos(d*d*d*d));&#xA;  }&#xA;  &#xA;  WriteGrayscalePPM(&amp;quot;moire.ppm&amp;quot;, values, X);&#xA;  &#xA;  return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerDisplayName="user9485" LastEditorDisplayName="user9485" LastEditDate="2020-07-04T12:56:43.197" LastActivityDate="2020-07-04T12:56:43.197" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="9997" PostTypeId="1" AcceptedAnswerId="10000" CreationDate="2020-07-04T05:05:07.630" Score="0" ViewCount="42" Body="&lt;p&gt;The following is an excerpt from a &lt;a href=&quot;http://hhoppe.com/geodesics.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;2005 paper&lt;/a&gt; on geodesics on triangular meshes, taken from section 3.5&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/lvE1X.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lvE1X.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In this case &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is a point on some arbitrary face in a mesh, &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; is a point on one of the 3 edges in the triangle and &lt;span class=&quot;math-container&quot;&gt;$D(p')$&lt;/span&gt; is the geodesic distance to that point.&lt;/p&gt;&#xA;&lt;p&gt;I am very confused as to how this minimization is achieved. The paper doesn't go into detail, so I assume it's trivial, but I am not seeing the solution of the top of my head.&lt;/p&gt;&#xA;&lt;p&gt;Given an arbitrary interval (segment) the shortest point to it is either the orthogonal projection of the point &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; onto the segment or one of the end points of the segment (depending on where &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is located with respect to the segment).&lt;/p&gt;&#xA;&lt;p&gt;However, this is not necessarily the point that minimizes the expression &lt;span class=&quot;math-container&quot;&gt;$||p - p'|| + D(p')$&lt;/span&gt; or in other words, &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; is not, in general, the orthogonal projection of &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; onto the segment.&lt;/p&gt;&#xA;&lt;p&gt;The only algorithm I have is to naively check epsilon offsets along the segment and picking the shortest one. There has to be a better way than that.&lt;/p&gt;&#xA;&lt;p&gt;I have drawn a diagram on Geogebra to show the problem:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FmfBf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FmfBf.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\overline{BA}$&lt;/span&gt; is the segment, &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; is the point we are looking to minimize the distance from. &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; is the frontier point, which is the orthogonal projection of the Geodesic source (the source point of all geodesics in the mesh), &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; is the orthogonal projection of &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; onto &lt;span class=&quot;math-container&quot;&gt;$\overline{BA}$&lt;/span&gt;. Clearly the optimal point is somewhere between &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; but I don't know how to find it.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-07-04T05:11:25.563" LastActivityDate="2020-07-06T00:08:13.977" Title="Fast and exact Geodesics on meshes, Backtracking confusion" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="9998" PostTypeId="1" CreationDate="2020-07-05T10:33:50.293" Score="0" ViewCount="33" Body="&lt;p&gt;I’m trying to build an interactive point cloud renderer in Panda3D.&#xA;I want to render a point cloud and be able to select a group of points and change their colors, maybe with a rectangular selector or something…&lt;/p&gt;&#xA;&lt;p&gt;So far I managed to render the point cloud (using GeomPoints), but now that I think about it, how do I get a subset of vertices? I was thinking maybe have a compute shader calculate all the points that are inside some bounding box, and have it pass information to the color buffer of the cloud. but MAYBE (and hopefully) there’s an easier way to do about this?&lt;/p&gt;&#xA;" OwnerUserId="7525" LastActivityDate="2020-07-05T10:33:50.293" Title="Interactive point cloud" Tags="&lt;compute-shader&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10000" PostTypeId="2" ParentId="9997" CreationDate="2020-07-06T00:08:13.977" Score="0" Body="&lt;p&gt;The solution I found to this problem is to ALWAYS intersect the edge. In other words the distance to the geodesic source &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; from a point &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$||v-p'|| + ||p - p'||$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; is the intersection of the line &lt;span class=&quot;math-container&quot;&gt;$\overline{vp}$&lt;/span&gt; with the current edge. In cases where &lt;span class=&quot;math-container&quot;&gt;$p'$&lt;/span&gt; is &amp;quot;behind&amp;quot; &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; with respect to &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; we set the distance to the edge to be infinity.&lt;/p&gt;&#xA;&lt;p&gt;The above seems to work in the simple tests I have generated at minimum.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-07-06T00:08:13.977" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10001" PostTypeId="1" CreationDate="2020-07-06T11:50:27.597" Score="1" ViewCount="310" Body="&lt;p&gt;I have a setup where I'm rendering a bunch of characters on a canvas with an SDF font. The users can zoom in to see the details of the smaller texts, but currently the smaller characters are quite pixelated. (See the image below.) I'm looking for an approach to improve their quality.&lt;/p&gt;&#xA;&lt;p&gt;Based on these comments I believe SDF fonts are not really good for small text rendering:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/a/9337/11769&quot;&gt;https://computergraphics.stackexchange.com/a/9337/11769&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://gamedev.stackexchange.com/questions/71841/how-do-some-mobile-games-scale-graphics-so-beautifully/71850#comment129983_71850&quot;&gt;https://gamedev.stackexchange.com/questions/71841/how-do-some-mobile-games-scale-graphics-so-beautifully/71850#comment129983_71850&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I'm wondering if there's any viable workaround. For example, would it make sense to somehow reuse the larger characters by rendering them in a separate texture and scaling them down? Because when I zoom out, the larger characters look a lot better as they get smaller, I believe the problem might be that the SDF font cannot be interpolated on a too small scale.&lt;/p&gt;&#xA;&lt;p&gt;My setup is based on these resources:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/libgdx/libgdx/wiki/Distance-field-fonts&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/libgdx/libgdx/wiki/Distance-field-fonts&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/SaschaWillems/Vulkan/blob/master/examples/distancefieldfonts/distancefieldfonts.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/SaschaWillems/Vulkan/blob/master/examples/distancefieldfonts/distancefieldfonts.cpp&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I've already tried generating mipmaps which didn't really make any difference.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q4Ldp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q4Ldp.png&quot; alt=&quot;Scale comparison&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11769" LastEditorUserId="11769" LastEditDate="2020-07-08T09:45:43.180" LastActivityDate="2020-07-08T09:45:43.180" Title="How to scale signed distance field fonts properly?" Tags="&lt;opengl&gt;&lt;signed-distance-field&gt;&lt;font-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10002" PostTypeId="1" CreationDate="2020-07-06T19:15:52.117" Score="1" ViewCount="54" Body="&lt;p&gt;Considering a polygon with n vertices as input.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bWunO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bWunO.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I need to calculate the integral of the form&#xA;\[\int_A p(y) dA \] where &lt;span class=&quot;math-container&quot;&gt;$p(y)$&lt;/span&gt; is a piecewise polynomial function of &lt;span class=&quot;math-container&quot;&gt;$y$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;May be if I could find  the expression &lt;span class=&quot;math-container&quot;&gt;$b(y)$&lt;/span&gt; then the integral can be calculated by:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\int_{0}^{y_\max} p(y) b(y) dy $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The question is : &amp;quot;is there a straightforward method to find &lt;span class=&quot;math-container&quot;&gt;$b(y)$&lt;/span&gt; given the coordinates of the polygon vertices? Or is there a simpler manner to calculate the integral above?&amp;quot;&lt;/p&gt;&#xA;" OwnerUserId="13655" LastEditorUserId="13655" LastEditDate="2020-07-07T17:57:22.590" LastActivityDate="2020-07-07T17:57:22.590" Title="The ploygon width parallel to the x axis as a function of the y ordonate?" Tags="&lt;geometry&gt;&lt;polygon&gt;&lt;integral&gt;" AnswerCount="0" CommentCount="12" ContentLicense="CC BY-SA 4.0" />
  <row Id="10004" PostTypeId="1" AcceptedAnswerId="10015" CreationDate="2020-07-07T10:44:03.997" Score="4" ViewCount="303" Body="&lt;p&gt;While I was deriving expressions for perspective-correct linear interpolation on triangles, I reached the conclusion that the interpolation may be kept linear only if view-space &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; is available. However, computing view-space &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; requires nonlinear interpolation (it is a rational function based on my results). Is nonlinear interpolation performed in hardware to get perspective correct &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt;, or equivalently linear interpolation is performed on &lt;span class=&quot;math-container&quot;&gt;$\frac{1}{Z}$&lt;/span&gt; but a division is required to get view-space &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; anyways? As far as I get it there is no way around that - a division is required per-pixel to get perspective-correct Z values - is that correct?&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2020-07-11T17:56:21.870" Title="Perspective correct interpolation z-buffer" Tags="&lt;projections&gt;&lt;perspective&gt;&lt;interpolation&gt;&lt;z-buffer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10005" PostTypeId="1" AcceptedAnswerId="10006" CreationDate="2020-07-08T00:38:53.620" Score="2" ViewCount="87" Body="&lt;p&gt;I'm wondering why the orthographic projection we use in computer graphics is called a projection, if all it does is just scale and translate a mesh?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CUQe3.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CUQe3.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;According to wiki orthographic projection is &lt;code&gt;Orthographic projection (sometimes referred to as orthogonal projection, used to be called analemma[a]) is a means of representing three-dimensional objects in two dimensions&lt;/code&gt;, but we don't use orthographic projection to project our mesh to 2d space, we just use it to transform our mesh defined in the view box with arbitrarily defined dimensions (left, right, up, bottom, far and near) to a view box of (-1, 1, -1, 1, -1, 1) dimensions. So why do we call it an orthographic projection?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-07-08T00:46:37.447" LastActivityDate="2020-07-15T20:16:55.303" Title="How is orthographic projection used in computer graphics technically classified as a projection?" Tags="&lt;projections&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10006" PostTypeId="2" ParentId="10005" CreationDate="2020-07-08T01:31:22.623" Score="2" Body="&lt;p&gt;I think it is more of a terminology shared specifically in the computer graphics community. The transformation &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt; results in a vector one-step-ahead from getting the actual projection. From a 3D position transformed with &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt;, we can obtain both&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;the 2D-projected position in normalized device coordinate (NDC) (by obtaining xy component)&lt;/li&gt;&#xA;&lt;li&gt;the depth (by obtaining the z component) in NDC&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This so-called projection matrix is designed specifically to satisfy the needs in the computer graphics pipeline. The key difference between an ordinary N-D-to-(N-1)-D projection is that the projection matrix results in 2D positions with &amp;quot;depth&amp;quot;, which is required for obtaining a depth map used for many purposes in the computer graphics pipeline.&lt;/p&gt;&#xA;" OwnerUserId="13305" LastEditorUserId="5353" LastEditDate="2020-07-15T20:16:55.303" LastActivityDate="2020-07-15T20:16:55.303" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10007" PostTypeId="1" CreationDate="2020-07-08T05:35:08.267" Score="0" ViewCount="126" Body="&lt;p&gt;Find the formulas of the middle point algorithm for drawing the parabola ? &lt;br&gt;&#xA;x^2 = 4*(a+b)*y , a,b &amp;gt; 0. &lt;br&gt;&#xA;Solve it according to E(East) and NorthEast(NE) ? &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is the result i got (This is writen in java frame, so its the opposite on graph)&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OLfzY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OLfzY.png&quot; alt=&quot;My try&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&#xA;&lt;br&gt;&#xA;This is my try, Ok in this problem the y increases y_{k+1} = y_k + 1 every time and x_{k+1} = x_k or x_k + 1 depending on the P_k value. Here is code i tried with: If P_{k} &amp;gt; then ( p_{k+1} = p_k - 4*(a + b) + 2&lt;em&gt;x_k + 1; and x in increased by one x_{k+1} = x_k + 1;) else ( p_{k+1} = p_k - 4&lt;/em&gt;(a + b);) , It doesn't look very well i think&lt;/p&gt;&#xA;" OwnerUserId="13664" LastEditorUserId="13664" LastEditDate="2020-07-09T07:24:11.323" LastActivityDate="2020-07-09T07:24:11.323" Title="Find the formulas of the middle point algorithm for drawing the parabola?" Tags="&lt;midpoint&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10008" PostTypeId="2" ParentId="10001" CreationDate="2020-07-08T09:45:31.693" Score="1" Body="&lt;p&gt;After some trials I've realized my problem was a programming error and not an actual issue with SDF fonts.&lt;/p&gt;&#xA;&lt;p&gt;Originally I was rendering the numbers on the texture of the canvas, which had a fixed scale. I thought that it will redraw the quads during the zoom but it wasn't the case. After I've separated the character drawing from the canvas and scaled them separately they finally look sharp.&lt;/p&gt;&#xA;&lt;p&gt;The linked comments about the small text rendering was slightly misleading. They do have some issues with smaller scale, but that's only the case when the view is zoomed out.&lt;/p&gt;&#xA;" OwnerUserId="11769" LastActivityDate="2020-07-08T09:45:31.693" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10009" PostTypeId="1" CreationDate="2020-07-08T13:20:51.607" Score="0" ViewCount="78" Body="&lt;p&gt;&lt;em&gt;For context:&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm absolutely new to graphics programming and I've always had trouble getting the math.&lt;/p&gt;&#xA;&lt;p&gt;I had the task to write code for a crystal ball interface using OpenGL.&#xA;There's an object in the center of the screen and by using arrow keys, the user can rotate around it.&lt;/p&gt;&#xA;&lt;p&gt;The code below is working and passed the grader.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;The problem:&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;I don't get why this code is working. I'm reading up on linear algebra (vectors, matrices...) and I understand the operations that can be performed on those structures. But when it comes to applying, it all doesn't seem to make sense anymore.&lt;/p&gt;&#xA;&lt;p&gt;Maybe someone here can explain to me in simple terms why this part works:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    mat3 xmat(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);&#xA;    mat3 ymat(x * x, x * y, x * z, x * y, y * y, y * z, x * z, y * z, z * z);&#xA;    mat3 zmat(0.0, z, -y, -z, 0.0, x, y, -x, 0.0);&#xA;&#xA;    // This part I &amp;quot;understand&amp;quot;&#xA;    mat3 rotMat((cos(radians) * xmat) + ((1 - cos(radians)) * ymat) + (sin(radians) * (zmat)));&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I feel like someone would have to explain me all of it with lots of pictures.&#xA;But I hope that the above part will make the rest click for me.&lt;/p&gt;&#xA;&lt;p&gt;Wouldn't this way be equivalent - it looks like it-?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    mat3 xmat(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);&#xA;    mat3 zmat(0.0, z, -y, -z, 0.0, x, y, -x, 0.0);&#xA;&#xA;    mat3 rotMat(xmat + zmat * sin(radians) + (zmat * zmat) * (1-cos(radians)));&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Helper rotation function.  Please implement this.  &#xA;mat3 Transform::rotate(const float degrees, const vec3&amp;amp; axis)&#xA;{&#xA;    // YOUR CODE HERE&#xA;    vec3 normalAxis = glm::normalize(axis);&#xA;    float radians = ((2 * pi) / 360) * degrees;&#xA;    float x = axis.x;&#xA;    float y = axis.y;&#xA;    float z = axis.z;&#xA;&#xA;    mat3 xmat(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);&#xA;    mat3 ymat(x * x, x * y, x * z, x * y, y * y, y * z, x * z, y * z, z * z);&#xA;    mat3 zmat(0.0, z, -y, -z, 0.0, x, y, -x, 0.0);&#xA;&#xA;    mat3 rotMat((cos(radians) * xmat) + ((1 - cos(radians)) * ymat) + (sin(radians) * (zmat)));&#xA;    return rotMat;&#xA;}&#xA;&#xA;void Transform::left(float degrees, vec3&amp;amp; eye, vec3&amp;amp; up) {&#xA;    mat3 rotMat = rotate(degrees, up);&#xA;    eye = rotMat * eye;&#xA;}&#xA;&#xA;// Transforms the camera up around the &amp;quot;crystal ball&amp;quot; interface&#xA;void Transform::up(float degrees, vec3&amp;amp; eye, vec3&amp;amp; up) {&#xA;    vec3 unit = glm::cross(eye, up);&#xA;    vec3 unitNormal = glm::normalize(unit);&#xA;&#xA;    mat3 rotMat = rotate(degrees, unitNormal);&#xA;    eye = (rotMat * eye);&#xA;    up = glm::normalize(rotMat * up);&#xA;&#xA;    int dot1 = glm::dot(eye, up);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Thanks a lot and stay healthy,&#xA;Cheers.&lt;/p&gt;&#xA;" OwnerDisplayName="user13665" LastEditorDisplayName="user13665" LastEditDate="2020-07-08T13:37:49.757" LastActivityDate="2020-07-08T13:37:49.757" Title="Crystal ball rotation - I don't get why the code works" Tags="&lt;opengl&gt;&lt;matrix&gt;&lt;vectors&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10010" PostTypeId="1" CreationDate="2020-07-09T22:32:31.940" Score="1" ViewCount="93" Body="&lt;p&gt;I'm working on a 3D modeling tool and we use data from OpenLayers to construct a 3D mesh of some land. I want this behavior: you click on the mesh and it puts a point where you clicked on the mesh. Then, after the first point has been made, if you hover over the mesh with your mouse, a helper line will appear between the first point you made and where you mouse is currently. This helper line is drawn on the mesh, i.e. conforms to it's surface. This sounded like simple functionality but is proving quite complex.&lt;/p&gt;&#xA;&lt;p&gt;I've looked into geodesics, and shortest path algorithms but they seem really complex. I'm still fairly new to three.js. I've also read about UV mapping, or maybe casting a shadow to create this line.&lt;/p&gt;&#xA;&lt;p&gt;Does any one have any pointers for this? Or things to look into? Thank you!&lt;/p&gt;&#xA;" OwnerUserId="13678" LastActivityDate="2020-07-09T22:32:31.940" Title="Draw Line on Arbitrary Surface" Tags="&lt;three.js&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10011" PostTypeId="1" CreationDate="2020-07-09T23:27:31.250" Score="1" ViewCount="115" Body="&lt;p&gt;I constructed an orthographic projection matrix from  &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/orthographic-projection-matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; article on scratchpixel.com:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Matrix4 ortho(float l, float r, float b, float t, float n, float f) {&#xA;   return Matrix4(&#xA;       2/(r-l), 0, 0, -(r+l)/(r-l), //row 0&#xA;       0, 2/(t-b), 0, -(t+b)/(t-b), //row 1&#xA;       0, 0, -2/(f-n), -(f+n)/(f-n), //row 2&#xA;       0, 0, 0, 1 //row 3&#xA;   );&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;, where &lt;code&gt;r, l, t, b, n, f&lt;/code&gt; are right, left, top, bottom, near and far corners of the view box.&lt;/p&gt;&#xA;&lt;p&gt;Now I tested out this matrix using the default parameters of the view box &lt;code&gt;ortho(-1, 1, -1, 1, -1, 1)&lt;/code&gt; to see if I get an identity matrix. However I'm getting:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt; 1, 0, 0, 0,&#xA; 0, 1, 0, 0,&#xA; 0, 0, -1, 0,&#xA; 0, 0, 0, 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Basically this will result in z coordinate of every transformed point to be negated.&lt;/p&gt;&#xA;&lt;p&gt;Is it standard to negate the z coordinate when constructing projection matrix? What could be the purpose behind that?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-07-10T03:24:48.430" LastActivityDate="2020-07-13T02:52:21.510" Title="Why negate z when constructing projection matrix OpenGL" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;linear-algebra&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10012" PostTypeId="2" ParentId="10011" CreationDate="2020-07-10T04:39:48.520" Score="1" Body="&lt;p&gt;I'm assuming your scene is constructed based on right-handed coordinates.&lt;/p&gt;&#xA;&lt;p&gt;If you are using OpenGL, yes. If you are using Direct3D, no.&lt;/p&gt;&#xA;&lt;p&gt;The projection matrix maps [-n, -f] into [0, 1]. This weird property comes from the fact that the eye coordinates are right-handed, but the clip space (NDC) uses left-handed coordinates. Hence the implementation of &lt;code&gt;ortho()&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Direct3D uses a z-axis that goes outwards the screen. Implementations for Direct3D projection matrices will not produce negated z when coupled with your application.&lt;/p&gt;&#xA;" OwnerUserId="13305" LastEditorUserId="13305" LastEditDate="2020-07-13T02:52:21.510" LastActivityDate="2020-07-13T02:52:21.510" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10013" PostTypeId="2" ParentId="10011" CreationDate="2020-07-10T07:24:19.800" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;What could be the purpose behind that?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Have a look at the first lines and the first image in the Perspective Projection section of &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link&lt;/a&gt;. For the answer to your question, it is not important that you used an orthographic projection, even though there is also a corresponding section in the link.&lt;/p&gt;&#xA;&lt;p&gt;The issue is how OpenGL defines its coordinate systems. Quote from the link:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Note that the eye coordinates are defined in the right-handed coordinate system, but NDC uses the left-handed coordinate system. That is, the camera at the origin is looking along -Z axis in eye space, but it is looking along +Z axis in NDC.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So if you transform between them, you need to swap the z-axis. This is the whole purpose behind it, switching the handedness of the coordinate systems.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Is it standard to negate the z coordinate when constructing projection matrix?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Depends on your API and how the coordinate systems are defined. In OpenGL, you need to do this.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-07-12T11:21:19.150" LastActivityDate="2020-07-12T11:21:19.150" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10014" PostTypeId="1" AcceptedAnswerId="10016" CreationDate="2020-07-11T14:11:35.913" Score="1" ViewCount="52" Body="&lt;p&gt;I am new to rendering and I would like to calcualte UV partial derivatives of a cylinder shape, which is parameterized by radius &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; and length &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Using cylindrical coordinate mapping, for a surface point &lt;span class=&quot;math-container&quot;&gt;$\mathbf{p}=(x,y,z)$&lt;/span&gt;, the UV map (normalized to &lt;span class=&quot;math-container&quot;&gt;$[0,1]$&lt;/span&gt;) is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;(u,v) = \Big(\frac{\phi}{2\pi}, \frac{z}{L}\Big)\qquad \text{where} \quad \phi = \arctan \frac{y}{x}&#xA;$$&lt;/span&gt;&#xA;Then I compute the derivatives with respect to &lt;span class=&quot;math-container&quot;&gt;$\mathbf{p}$&lt;/span&gt;, that is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;\frac{\partial u}{\partial \mathbf{p}} &amp;amp; = \frac{1}{2\pi R^2} \Big( -y, x, 0\Big) = \frac{1}{2\pi R} \Big( -\sin\phi, \cos\phi, 0\Big)\\&#xA;\frac{\partial v}{\partial \mathbf{p}} &amp;amp;= \Big( 0, 0, \frac{1}{L}\Big)&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&#xA;Or equivalently:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;\frac{\partial \mathbf{p}}{\partial u} &amp;amp; = 2\pi R \Big( -\frac{1}{\sin\phi}, \frac{1}{\cos\phi}, 0\Big)\\&#xA;\frac{\partial \mathbf{p}}{\partial v} &amp;amp;= \Big( 0, 0, L\Big)&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&#xA;Everything looks good until now.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;In &lt;a href=&quot;https://github.com/mmp/pbrt-v3&quot; rel=&quot;nofollow noreferrer&quot;&gt;pbrt-3&lt;/a&gt;, the relevant part of &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/9f717d847a807793fa966cf0eaa366852efef167/src/shapes/cylinder.cpp#L105&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;cylinder.cpp&lt;/code&gt;&lt;/a&gt; is: (i) UV same as above; (ii) &lt;span class=&quot;math-container&quot;&gt;$\partial \mathbf{p}/\partial u$&lt;/span&gt; however is different:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;Float u = phi / phiMax;&#xA;Float v = (pHit.z - zMin) / (zMax - zMin);&#xA;&#xA;// Compute cylinder &lt;span class=&quot;math-container&quot;&gt;$\dpdu$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\dpdv$&lt;/span&gt;&#xA;Vector3f dpdu(-phiMax * pHit.y, phiMax * pHit.x, 0);&#xA;Vector3f dpdv(0, 0, zMax - zMin);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What am I missing here?&lt;/p&gt;&#xA;" OwnerUserId="6470" LastActivityDate="2020-07-11T19:11:52.980" Title="UV partial derivatives of a cylinder shape primitive" Tags="&lt;rendering&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10015" PostTypeId="2" ParentId="10004" CreationDate="2020-07-11T17:56:21.870" Score="2" Body="&lt;p&gt;Yes, that's correct. Perspective-correct interpolation works by (for some quantity &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; to be interpolated) calculating &lt;span class=&quot;math-container&quot;&gt;$u/z$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$1/z$&lt;/span&gt; at each vertex, linearly interpolating those values in screen space, then calculating &lt;span class=&quot;math-container&quot;&gt;$u = (u/z) / (1/z)$&lt;/span&gt; at each sample point. This is done by the GPU hardware behind the scenes.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-07-11T17:56:21.870" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10016" PostTypeId="2" ParentId="10014" CreationDate="2020-07-11T19:11:52.980" Score="2" Body="&lt;p&gt;I think it's easiest to get the tangent frame by writing the forward mapping from &lt;span class=&quot;math-container&quot;&gt;$(u,v)$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$\mathbf{p}$&lt;/span&gt;:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;    \mathbf{p}(u,v) = \begin{bmatrix} R \, \cos (2\pi u) \\ R \, \sin (2\pi u) \\ vL \end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;Then you can see that the derivatives are:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;    \frac{\partial\mathbf{p}}{\partial u} = \begin{bmatrix} -2\pi R \, \sin(2\pi u) \\ 2\pi R \, \cos(2\pi u) \\ 0\end{bmatrix} = \begin{bmatrix} -2\pi y \\ 2\pi x \\ 0\end{bmatrix}, \qquad&#xA;    \frac{\partial\mathbf{p}}{\partial v} = \begin{bmatrix} 0 \\ 0 \\ L \end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;which matches the pbrt code.&lt;/p&gt;&#xA;&lt;p&gt;I think your derivation went wrong by assuming that &lt;span class=&quot;math-container&quot;&gt;$\partial\mathbf{p}/\partial u$&lt;/span&gt; was the component-wise reciprocal of &lt;span class=&quot;math-container&quot;&gt;$\partial u / \partial{\mathbf{p}}$&lt;/span&gt;. It's not so simple, because the latter object is really the gradient of &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; is now considered as a scalar field defined over all space (not just on the cylinder). To invert this properly we really need another coordinate running perpendicular to &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; in the &lt;span class=&quot;math-container&quot;&gt;$xy$&lt;/span&gt; plane, so that we have a locally invertible mapping; then we can take its Jacobian matrix and invert that. We can use the radius &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; as such a coordinate. Then we have the inverse mapping,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;    u(x,y) &amp;amp;= \frac{1}{2\pi} \arctan(y,x) \\&#xA;    R(x,y) &amp;amp;= \sqrt{x^2 + y^2}&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&#xA;whose Jacobian is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;    \frac{\partial(u,R)}{\partial(x,y)} =&#xA;    \begin{bmatrix}&#xA;        \tfrac{\partial u}{\partial x} &amp;amp; \tfrac{\partial u}{\partial y} \\&#xA;        \tfrac{\partial R}{\partial x} &amp;amp; \tfrac{\partial R}{\partial y}&#xA;    \end{bmatrix} =&#xA;    \begin{bmatrix}&#xA;        -y/(2\pi R^2) &amp;amp; x/(2\pi R^2) \\&#xA;        x/R &amp;amp; y/R&#xA;    \end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;and the inverse of that is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;    \frac{\partial(x,y)}{\partial(u,R)} =&#xA;    -2\pi R \begin{bmatrix}&#xA;        y/R &amp;amp; -x/(2\pi R^2) \\&#xA;        -x/R &amp;amp; -y/(2\pi R^2)&#xA;    \end{bmatrix} =&#xA;    \begin{bmatrix}&#xA;        -2\pi y &amp;amp; x/R \\&#xA;        2\pi x &amp;amp; y/R&#xA;    \end{bmatrix}&#xA;$$&lt;/span&gt;&#xA;from which you can then read off &lt;span class=&quot;math-container&quot;&gt;$\partial{(x,y)}/\partial u$&lt;/span&gt; as the first column, which matches the result obtained for &lt;span class=&quot;math-container&quot;&gt;$\partial\mathbf{p}/\partial u$&lt;/span&gt; above.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-07-11T19:11:52.980" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10018" PostTypeId="1" CreationDate="2020-07-12T18:51:08.130" Score="0" ViewCount="27" Body="&lt;p&gt;I am trying to implement Milne's predictor method to solve the eq. for iso-lux contours according to &lt;a href=&quot;https://www.graphics.cornell.edu/pubs/1994/Arv94.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper&lt;/a&gt; by Arvo.&#xA;Here is the predictor:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/A3NOm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A3NOm.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;From the paper: &amp;quot;It is a multistep method that predicts the new point by extrapolating&#xA;from the three most recent gradients and function values using a&#xA;parabola. where gk denotes the gradient at the point rk, and h is the step&#xA;size&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;For a y=f(x) function, with step size h, I understand how to move the initial point to get the last three points. Moving along x axis:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OB8gp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OB8gp.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;however I cannot work it out what direction to move the initial point(e.g. the red dot) if the curve is defined on the xy plane, like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/T3T8t.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/T3T8t.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Are the last three points on the iso-line?&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Is the step h defined on a grid of points in x, y directions, and the previous point would be (x-h,y-h)? But most likely that point wouldn't end up on the curve.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Or is the k index defined on the parameterized eq. of the curve, so to go one step backward on the curve? But this also does't make sense to me as this isn't the case on the above 1D function example, where the step size is defined on the x axis not on the curve.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;My other question regards the contouring algorithm,&lt;/p&gt;&#xA;&lt;p&gt;I know the marching sq method to draw the iso-line contours. What are the methods for smoothing/refining  the contour, specifically by using the function gradient?&lt;/p&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2020-07-12T20:40:07.033" LastActivityDate="2020-07-12T20:40:07.033" Title="Two questions: How to find the last 3 points for Milne's Predictor? And methods for smoothing iso-line contour?" Tags="&lt;gradient&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10019" PostTypeId="1" AcceptedAnswerId="10020" CreationDate="2020-07-13T12:14:46.363" Score="1" ViewCount="69" Body="&lt;p&gt;I am trying to put multiple depthbuffers into one Framebuffer.&#xA;I want to use VR and render both eyes at the same time:&lt;/p&gt;&#xA;&lt;p&gt;that means, in the geometry stage I want to clone the incoming triangle to two outgoing triangles with a shift of the eye offset for layered rendering. Therefore I would like to have two RGB textures / maybe one RGB texture 2d array and two depthbuffers / a depthbuffer array&lt;/p&gt;&#xA;&lt;p&gt;here is my program code so far, the error occurred at the second last line of code and it is a GL_INVALID_ENUM error.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;GLError();&#xA;glGenFramebuffers(1, &amp;amp;m_sFrameBufferInfo.m_nFrameBuffer);&#xA;GLError();&#xA;glBindFramebuffer(GL_FRAMEBUFFER, m_sFrameBufferInfo.m_nFrameBuffer);&#xA;&#xA;//Left eye&#xA;GLuint textureLeft;&#xA;glGenTextures(1, &amp;amp;textureLeft);&#xA;GLError();&#xA;glBindTexture(GL_TEXTURE_2D, textureLeft);&#xA;GLError();&#xA;&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_nWindowWidth, m_nWindowHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);&#xA;GLError();&#xA;&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;GLError();&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;GLError();&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureLeft, 0);&#xA;GLError();&#xA;&#xA;//right eye&#xA;GLuint textureRight;&#xA;glGenTextures(1, &amp;amp;textureRight);&#xA;GLError();&#xA;glBindTexture(GL_TEXTURE_2D, textureRight);&#xA;GLError();&#xA;&#xA;glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_nWindowWidth, m_nWindowHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);&#xA;GLError();&#xA;&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;GLError();&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;GLError();&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, textureRight, 0);&#xA;GLError();&#xA;&#xA;//depth buffer&#xA;GLuint textureDepth;&#xA;&#xA;glGenTextures(1, &amp;amp;textureDepth);&#xA;GLError();&#xA;glBindTexture(GL_TEXTURE_2D_ARRAY, textureDepth);&#xA;GLError();&#xA;&#xA;glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, GL_DEPTH24_STENCIL8, m_nWindowWidth, m_nWindowHeight,2 , 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);&#xA;GLError();&#xA;&#xA;glFramebufferTexture3D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D_ARRAY, textureDepth, 2, 0);&#xA;GLError();&#xA;&#xA;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;GLError();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Thanks for your help!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-07-13T13:23:54.060" Title="OpenGL Framebuffer with multiple Depthbuffers inside" Tags="&lt;opengl&gt;&lt;frame-buffer&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10020" PostTypeId="2" ParentId="10019" CreationDate="2020-07-13T13:23:54.060" Score="1" Body="&lt;p&gt;FBOs can only use a single depth image, but that image &lt;em&gt;can&lt;/em&gt; be layered. Broadly speaking, VR multi-eye rendering ought to be done through layered FBO images for both the color and depth buffers.&lt;/p&gt;&#xA;&lt;p&gt;The problem with your code is that you can't use &lt;code&gt;glFramebufferTexture3D&lt;/code&gt; to attach a layered image. You must use &lt;code&gt;glFramebufferTexture&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Also, you need to use layers for the color image as well.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-07-13T13:23:54.060" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10022" PostTypeId="2" ParentId="4146" CreationDate="2020-07-14T16:46:25.173" Score="2" Body="&lt;p&gt;PCSS is looking less attractive as a real time shadowing technique since it has limited performance, largely due to the size of the shadow map and the number of samplers that must be taken in order to get acceptable results. I would recommend implementing it anyway largely because the same techniques are used in other shadow generation algorithms and it is very well documented, so it is easy to find information that will help you out if you run into an issue. Also, there are plenty of use cases where PCSS is &amp;quot;good enough&amp;quot; so you can spend your energy on other aspects of your application. Especially given the wide range hardware that any given game can find itself running on. A high end machine with PCSS may not be &amp;quot;the best use of resources&amp;quot; but it certainly gives extra bang for the rendering buck.&lt;/p&gt;&#xA;&lt;p&gt;Also, once implemented, it isn't to difficult to migrate it to another algorithm like VSSM (Variance Soft Shadow Mapping) which requires 32bit buffers but allows for the use of smaller shadow maps. But VSSM isn't documented as well so it is more difficult to write from scratch. Nvidia has a good paper on the subject:&lt;a href=&quot;http://developer.download.nvidia.com/SDK/10/direct3d/Source/VarianceShadowMapping/Doc/VarianceShadowMapping.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Link to Nvidia VSSM Paper&lt;/a&gt;. They also have an application with code so you can compare the two algorithms side by side.&lt;/p&gt;&#xA;&lt;p&gt;The book Real-Time Shadows is a good reference for shadow mapping. And can usually be picked up used for a reasonable price.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-07-14T16:46:25.173" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10025" PostTypeId="1" CreationDate="2020-07-15T15:43:31.347" Score="1" ViewCount="59" Body="&lt;p&gt;I'm working on an app that lets users construct a 3D house, with the ultimate goal of it being 3D printable. I use various materials in the form of a height map constructed from an image, like this brick texture:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/n6D9T.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n6D9T.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I map the brightness of each pixel to a height, like so:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/41Sk2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/41Sk2.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But when you start combining wall panels side by side and at different angles, it can quickly get messy and you can end up with a self-intersecting mesh, not to mention many more polygons than are really necessary, all of which contribute to something which the 3D Printer slicer can't cope with. It &lt;em&gt;looks&lt;/em&gt; like this but the geometry isn't clean enough to print it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/u4Eg1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u4Eg1.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now, currently everything in the app itself works directly with polygons. Since all of this ultimately is generated from grid-like data (the source images) it seems to me that some kind of voxel-based approach would be very suitable, and could potentially yield much better quality results. I have tested the approach of populating a grid directly from the source images, and that bit can be done very efficiently. But I'm having a hard time finding the right algorithm to then turn that grid data back into polygons ready for 3D printing.&lt;/p&gt;&#xA;&lt;p&gt;Most algorithms for turning voxel data into a polygon isosurface assume two things, as far as I can tell:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;That you have no prior knowledge of the underlying geometry&lt;/li&gt;&#xA;&lt;li&gt;That the geometry is a scalar field, rather than a &amp;quot;boolean&amp;quot; grid where the grid lines genuinely do correspond to the final geometry. There could be fine scaled details that fall between the grid lines.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Whereas in my case:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;I have huge empty patches inside the building, but I can easily ignore those because I have a list of bounding boxes of where each wall panel exists&lt;/li&gt;&#xA;&lt;li&gt;I would like to take advantage of the fact that my data actually &lt;em&gt;is&lt;/em&gt; gridlike in nature. Note that I can have 'diagonals' - this simple brick texture shown here is probably a little too simplistic, e.g. some roof tile textures use a lot more in-between heights:&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CJFJH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CJFJH.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Obviously something as simple as marching cubes could be adapted to take advantage of point 1 easily enough (just skip over sections of the grid which aren't contained within any of my bounding boxes) but I feel like marching cubes will yield WAY more polygons than necessary.&lt;/p&gt;&#xA;&lt;p&gt;Can anybody recommend any specific algorithms that might suit this scenario (where we have prior knowledge about the underlying geometry) or give me some search terms that I can use to research? I've been searching algorithms for generating isosurfaces, but my instinct tells me that what I'm working with here is actually subtly different because of the grid-like nature of the problem - e.g. are these even really &amp;quot;voxels&amp;quot; at all?&lt;/p&gt;&#xA;" OwnerUserId="13696" LastEditorUserId="13696" LastEditDate="2020-07-15T18:06:55.100" LastActivityDate="2021-02-22T23:04:45.443" Title="Efficiently generating mesh for self-generated voxel grid" Tags="&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10026" PostTypeId="1" CreationDate="2020-07-15T16:56:53.933" Score="2" ViewCount="97" Body="&lt;p&gt;I'm writing my own mesh renderer, and I previously was able to apply a normal map to a sphere, so I understand the basic process of applying a normal map. But my understanding is that in order to apply it, you need a consistent tangent space at every point on the mesh. It's possible on a sphere because you can calculate the spherical coordinates and then pick orthogonal tangents parallel to lines of longitude/latitude, but as far as I can tell, there's no clear way to do that to a mesh.&lt;/p&gt;&#xA;&lt;p&gt;To give a specific example, I found &lt;a href=&quot;https://www.cgtrader.com/free-3d-models/character/woman/juliette-10781-sport-girl-free-3dpeople-model&quot; rel=&quot;nofollow noreferrer&quot;&gt;this free .obj file&lt;/a&gt; online, and I can render it with textures, just without normal mapping. But I can open up the model in the generic Windows &amp;quot;3D Viewer&amp;quot;, and in that program, it has normal mapping applied, so clearly it's possible. I couldn't find anything online, is there a way to do this?&lt;/p&gt;&#xA;" OwnerUserId="13698" LastActivityDate="2020-07-16T00:10:32.193" Title="How do you apply a normal map to a 3d mesh?" Tags="&lt;mesh&gt;&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10027" PostTypeId="1" CreationDate="2020-07-15T19:14:54.490" Score="0" ViewCount="52" Body="&lt;p&gt;I am currently trying to find topics for my master's thesis. I would really like to do something in the field of computer graphics, but I've been having trouble finding what are some current problems people are trying to solve. I don't consider myself very good in this area, but I am willing to learn.&lt;/p&gt;&#xA;&lt;p&gt;If you could provide some direction it would be very helpful.&lt;/p&gt;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="13701" LastActivityDate="2020-07-15T19:14:54.490" Title="What's a good research topic in Computer Graphics?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;3d&gt;&lt;2d&gt;&lt;model&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10028" PostTypeId="2" ParentId="10026" CreationDate="2020-07-16T00:10:32.193" Score="3" Body="&lt;p&gt;There are numerous approaches to setting up tangent bases on a mesh, and unfortunately, no totally universal standard for how they are calculated.&lt;/p&gt;&#xA;&lt;p&gt;Tangents are based on the mesh's UV mapping, so that the tangent vector points (at least roughly) along the U axis in texture space, and the bitangent along the V axis. This means each triangle in a mesh has its own tangent basis (as long as the UV mapping is nondegenerate). This often gets converted into a smoothed tangent basis per vertex, much like you can create smoothed normals by setting each vertex normal to an average over the normals of the surrounding triangles. Different tools and engines might do the smoothing in different ways, might handle UV seams and mirroring differently, might orthonormalize the basis per vertex or per pixel or not at all, etc. &lt;a href=&quot;https://medium.com/@bgolus/generating-perfect-normal-maps-for-unity-f929e673fc57&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here is a nice article&lt;/a&gt; to read if you want to know more. And as noted there, there is a method for tangent spaces called &lt;a href=&quot;http://www.mikktspace.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;mikktspace&lt;/a&gt; that is gradually gaining widespread support and might become a de facto standard.&lt;/p&gt;&#xA;&lt;p&gt;Object/character models like the one you linked usually have normal maps baked out from a content creation tool (e.g. based on an ultra-high-detail source mesh); ideally, you need the tangent basis you use in your renderer to match the tangent basis used in the tool to do the bake. Sometimes there will be vertex tangents stored in the mesh, but the .obj format doesn't support tangents so you would need to see if the model has tangents in one of the other formats, like .fbx.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-07-16T00:10:32.193" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10029" PostTypeId="1" AcceptedAnswerId="10033" CreationDate="2020-07-16T01:22:36.547" Score="1" ViewCount="106" Body="&lt;p&gt;I'm working with a js/wasm/c++ program that uses object oriented programming when updating the OpenGL state.  There are corresponding c++ classes for VBOs (vertex buffer) and VAOs (vertex array).  When we call &lt;code&gt;vao.unbind();&lt;/code&gt;, it simply calls &lt;code&gt;glBindVertexArray(0);&lt;/code&gt;.  I'm seeing that unbinding the VAO does not unbind the corresponding VBOs.  One of the VAO's VBOs was still set as ARRAY_BUFFER_BINDING target.&lt;/p&gt;&#xA;&lt;p&gt;My question is: is it best practice to automatically unset the associated VBOs when you unset the VAO?  Or should I write a separate function that unsets the VAO's VBOs?&lt;/p&gt;&#xA;&lt;p&gt;With WebGL I'm seeing that it does not unbind the VBO when you unset the VAO, despite what &lt;a href=&quot;https://www.reddit.com/r/opengl/comments/beioq1/do_you_need_to_also_unbind_the_vertex_buffer/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this reddit post&lt;/a&gt; is saying.&lt;/p&gt;&#xA;" OwnerUserId="7073" LastActivityDate="2020-07-16T14:47:20.923" Title="When unsetting a VAO, should you also unbind the associated VBOs?" Tags="&lt;opengl&gt;&lt;webgl&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10030" PostTypeId="1" AcceptedAnswerId="10031" CreationDate="2020-07-16T04:40:09.100" Score="1" ViewCount="44" Body="&lt;p&gt;I am creating a fast fourier transform algorithm for the compute shader - i am no expert on how GPUs really run optimally so thought i would ask here.&lt;/p&gt;&#xA;&lt;p&gt;I have the option to calculate on the fly or precompute a lot of the trig function (cos and sin) values and store it in a read only float buffer.&lt;/p&gt;&#xA;&lt;p&gt;My question is, though i am aware cos() and sin() is fast, how do they compare to simply getting the value precomputed in a buffer instead?&lt;/p&gt;&#xA;&lt;p&gt;I don't mean a LUT here i do not need to interpolate between values from the buffer so i just get them values directly. I don't know how to really bench test shaders properly so i am unsure which is faster.&lt;/p&gt;&#xA;&lt;p&gt;Perhaps some one knows more info on this?&lt;/p&gt;&#xA;" OwnerUserId="10332" LastActivityDate="2020-07-16T21:38:22.350" Title="Reading from buffer versus calculating on the fly performance" Tags="&lt;compute-shader&gt;&lt;hlsl&gt;&lt;optimisation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10031" PostTypeId="2" ParentId="10030" CreationDate="2020-07-16T08:27:39.667" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;My question is, though i am aware cos() and sin() is fast, how do they compare to simply getting the value precomputed in a buffer instead?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This will depend on your shader code and GPU model.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;GPUs utilize latency hiding by executing independent ALU instructions while waiting for data to arrive from memory.&lt;/li&gt;&#xA;&lt;li&gt;Accessing memory is usually the slowest operation on a GPU.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;If your shader code allows for latency hiding, it &lt;em&gt;may&lt;/em&gt; be faster.&lt;/p&gt;&#xA;&lt;p&gt;The best option here is to profile the shader performance.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I don't know how to really bench test shaders properly so i am unsure which is faster.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I think the easiest way would be to download &lt;a href=&quot;https://renderdoc.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;RenderDoc&lt;/a&gt; and get a frame capture of your application.&lt;/p&gt;&#xA;&lt;p&gt;After that, you click on the timing icon (shown red) to get some measurements.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/vbnXI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vbnXI.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Although these are not super accurate measurements, they're good enough and sort of representative of the application performance.&lt;/p&gt;&#xA;&lt;p&gt;For precise measurements, you'll need your GPU vendor's graphics profiling tools.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;AMD has &lt;a href=&quot;https://gpuopen.com/rgp/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Radeon Graphics Profiler (RGP)&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;NVIDIA has &lt;a href=&quot;https://developer.nvidia.com/tools-overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;NSight&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;INTEL has &lt;a href=&quot;https://software.intel.com/content/www/us/en/develop/tools/graphics-performance-analyzers.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Graphics Performance Analyzers&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Below are some captures from RGP, showing GPU assembly instructions and instruction timings of various instruction types. You can see latency hiding in action below:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;vmem&lt;/code&gt; : texture read&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;smem&lt;/code&gt; : constant buffer / descriptor&amp;lt;texture/buffer&amp;gt; read&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;ALU&lt;/code&gt;  : math ops (arithmetic / logic)&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;sync&lt;/code&gt; : waits for vmem/smem instructions to finish loading data from memory&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RDs6a.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RDs6a.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Another capture showing instruction timings while first two texture loads not having latency hiding.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CqrG1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CqrG1.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="5353" LastEditorUserId="5353" LastEditDate="2020-07-16T21:38:22.350" LastActivityDate="2020-07-16T21:38:22.350" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10032" PostTypeId="1" CreationDate="2020-07-16T09:10:12.830" Score="0" ViewCount="46" Body="&lt;p&gt;What I am trying to do is to become able to compare with reasonable accuracy two real world fabric/textures (colorwise speaking) at two distinct locations. I can't move them into single place to observe them close to each other and in the same light conditions.&lt;/p&gt;&#xA;&lt;p&gt;I was thinking about such a &amp;quot;protocol&amp;quot;:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;print some &amp;quot;test pattern&amp;quot; on white paper (reference object)&lt;/li&gt;&#xA;&lt;li&gt;go into location 1 and take picture of object A close to reference object&lt;/li&gt;&#xA;&lt;li&gt;go into location 2 and take picture of object B close to reference object&lt;/li&gt;&#xA;&lt;li&gt;use some application/library/own code, to adjust colors on photo B so the reference object look similar (colorwise) to reference object on A&lt;/li&gt;&#xA;&lt;li&gt;compare visually or statistically (programmatically) objects A and B&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Does anyone know what is the easiest way to perform point 4? Is there an application for that step, or library or any other shortcut than implementing this on my own?&lt;/p&gt;&#xA;&lt;p&gt;Or, maybe anyone knows application for the whole process, not particularly point 4, which could help me, or another protocol for performing such comparison?&lt;/p&gt;&#xA;&lt;p&gt;Also please let me know it this can't be done this way, or rather, this is an oversimplified solution to provide &amp;quot;reasonable accuracy&amp;quot;, and if so - why?&lt;/p&gt;&#xA;" OwnerUserId="13702" LastEditorUserId="13702" LastEditDate="2020-07-26T05:19:52.230" LastActivityDate="2020-07-26T05:19:52.230" Title="Aligning (matching) colors (white balance, brightness) of two scenes based on reference object" Tags="&lt;color&gt;&lt;brightness&gt;&lt;image-comparison&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10033" PostTypeId="2" ParentId="10029" CreationDate="2020-07-16T11:38:58.120" Score="2" Body="&lt;p&gt;No, you do not need to unbind the VBO's. VBO's are only added to the state of the VAO when that VAO is bound. So any previously bound VBO's will not alter the state of the VAO that you are going to bind. The state of a bound VAO can be changed with the following calls:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;glEnableVertexAttribArray&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;glDisableVertexAttribArray&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;glVertexAttribPointer&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;glBindBuffer(GL_ELEMENT_ARRAY_BUFFER)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;You can bind and unbind VBO's without a currently bound VAO and even share them amongst VAO's. The VBO is simply a pointer to a data container that can be used for multiple purposes.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="2654" LastEditDate="2020-07-16T14:47:20.923" LastActivityDate="2020-07-16T14:47:20.923" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10034" PostTypeId="1" AcceptedAnswerId="10035" CreationDate="2020-07-17T01:37:46.813" Score="1" ViewCount="124" Body="&lt;p&gt;In most modeling software you can texture paint onto 3d models using so called stencil textures. They basically project a texture from the viewport view onto the model as seen for instance in the image below from Blender.&lt;/p&gt;&#xA;&lt;p&gt;What is the general technique used to project textures like this onto 3d models?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ByHK2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ByHK2.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EFrxb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EFrxb.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-07-17T08:39:06.813" Title="How are textures projected onto 3d models in texture painting applications" Tags="&lt;opengl&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10035" PostTypeId="2" ParentId="10034" CreationDate="2020-07-17T08:33:04.307" Score="1" Body="&lt;p&gt;I don't know if there is a smarter/more efficient way to do it, but a possible approach is the following:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 1 - Projection volume&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;First, you calculate the &amp;quot;projection volume&amp;quot; where its near plane corners are identical to the texture corners on your screen. You can do this by transforming the screen coordinates of the textures' corners into the range [-1, 1]. Then you use those coordinates to create a quad in NDC by combining the transformed x-y coordinates with z=-1 (near plane) and z=1 (far plane).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 2 - Collision test&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now you need to have both, your model and your &amp;quot;projection volume&amp;quot;, in the same space. You can either transform the &amp;quot;projection volume&amp;quot; into your model space or your model into NDC. I think the second choice makes the next step a little bit easier.&lt;/p&gt;&#xA;&lt;p&gt;Now you have to find all triangles that are fully or partially inside the &amp;quot;projection volume&amp;quot;. This is basically a collision detection check (triangle vs. quad or frustum) and I won't go into the details here. For all triangles that are fully inside the volume, you now have a connection between each vertex and its position inside the texture you want to project. Simply transform the vertex position into screen space and from there to the textures pixel coordinates. The second transformation depends on where you positioned your texture on the screen and how you have scaled it.&lt;/p&gt;&#xA;&lt;p&gt;For all partially covered triangles, the basic procedure is the same, but you have to introduce extra &amp;quot;helper vertices&amp;quot; and to transform them too to separate the covered from the uncovered areas. Doesn't mean that you have to really split your triangles into multiple smaller ones, but at least you need the extra vertices as intermediate data for the final step.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Step 3 - Adjust model data&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;In the last step, you have to bake this information somehow into your model. This totally depends on your model's data structure and layout. You can for example just split partially covered triangles into new ones and then set the &lt;code&gt;texCoord&lt;/code&gt; of every vertex that is inside the &amp;quot;projection volume&amp;quot; accordingly.&lt;/p&gt;&#xA;&lt;p&gt;If you have some kind of model-specific  UV-mapped textures, you would now use the information of the previous step to interpolate and copy the data of your projected texture to your model texture. For each vertex, you know where it is located inside the projected texture and inside its models UV texture. Now you basically cut out each triangle from your projected texture, and transform it into the corresponding triangle in your UV texture. Notice that this is not trivial since the triangle usually gets distorted and scaled. However, you can use the graphics pipeline for that by rendering directly to your UV-texture.&lt;/p&gt;&#xA;&lt;p&gt;There are probably a lot of other data representations that might require a different approach for this final step. However, the key here is the second step which establishes the connection between your vertices and the texture. Once you have this, it shouldn't be too hard to come up with a method to add the projected texture to your model.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Further information&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;During the second step, you might also need to perform some kind of depth testing, so that only the closest area gets affected and not all sides that are inside the projection volume.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-07-17T08:39:06.813" LastActivityDate="2020-07-17T08:39:06.813" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10036" PostTypeId="2" ParentId="9956" CreationDate="2020-07-17T11:45:47.250" Score="5" Body="&lt;p&gt;&lt;strong&gt;After more analysis, the TL;DR here is that, yes, the slowdown is due to memory locality, and yes the pixel order is to blame.  More interestingly, by writing the shader differently, we can &lt;em&gt;greatly surpass&lt;/em&gt; the fragment shader's performance—though we obviously shouldn't &lt;em&gt;rely&lt;/em&gt; on being able to do that regularly.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;First, to expand on the analysis: the best way to figure out what's going on in the GPU is to ask it.  In this case, the relevant tool is NVIDIA NSight.  After some fiddling, I got directly comparable results, which indicated that in both cases, memory is the bottleneck, and in the compute shader's case, it is worse.&lt;/p&gt;&#xA;&lt;p&gt;Since the actual shader code is substantively identical at the assembly level (see above), and (slightly-better-than-)equal performance can be achieved by removing memory from the equation by altering the shading code, we can be confident that the pixel shading order is to blame.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Perhaps we can find a better shading order?&lt;/p&gt;&#xA;&lt;p&gt;Spoiler alert: we can.  After some experimentation, consider a new shader where there is a global queue of tiles, and each warp grabs a tile and shades the pixels within it in scanline order.  This turns out to be 50% &lt;em&gt;faster&lt;/em&gt; than the fragment shader!&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Here's an animation from &lt;a href=&quot;https://graphics.geometrian.com/research/dacs_in_hw.html&quot; rel=&quot;noreferrer&quot;&gt;my HPG paper&lt;/a&gt;'s presentation this week, which touched on this issue:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/NPvbf.gif&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NPvbf.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;(It can be embiggened, which you may wish to do if you're having trouble reading the text.)&lt;/p&gt;&#xA;&lt;p&gt;This summarizes the results of these experiments, along with the performance numbers for each and a visualization of what I surmise is going on behind the scenes (simplified: only one warp is shown, it is 8 wide, and latency-hiding is not visualized).&lt;/p&gt;&#xA;&lt;p&gt;On the left, we have the fragment shader, labeled &amp;quot;Vendor Magic Goes Here&amp;quot;.  We don't know what the vendor is doing for their fragment shader pixel traversal order (though we could get hints e.g. by writing out atomic variables, etc.), but overall it works really well.&lt;/p&gt;&#xA;&lt;p&gt;In the middle, we have the original compute shader I described (with &lt;code&gt;param&lt;/code&gt; = &lt;code&gt;0&lt;/code&gt;), which divides the framebuffer into rectangular work groups.  Notice that the work groups are probably executed in a mostly reasonable order exactly to mitigate these caching effects, but are not guaranteed to be in any order at all—and indeed will not be due to latency hiding: this explains why the groups are walking over the framebuffer in a mostly coherent fashion, but still skipping around a little bit.  This is half the speed of the fragment shader, and I believe the possible skipping around is a reasonable starting guess for the additional memory incoherency revealed within the profile.&lt;/p&gt;&#xA;&lt;p&gt;Finally, we have the tiles version.  Because tiles are processed in a queue of tiles (defined by a global counter, visualized above the tile), the tiles and pixels are processed more in order (neglecting latency hiding and other thread groups).  I believe this is a reasonable starting guess as to why this result turns out to be 50% &lt;em&gt;faster&lt;/em&gt; than the fragment shader.&lt;/p&gt;&#xA;&lt;p&gt;It is important to stress that, while these results are correct for this particular experiment, with these particular drivers, &lt;em&gt;these results do &lt;strong&gt;not&lt;/strong&gt; necessarily generalize.  This is likely specific to this particular scene, view, and platform configuration, and this behavior may actually even be a bug.  This is definitely interesting to play with, but don't go ripping apart your renderer (only) because of one datapoint from a narrowly-defined experiment.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Indeed, what kicked off this whole investigation was that the performance of a (more-complex) compute shader had declined in relative performance since it was last profiled in 2018, using the same code on the same hardware.  The only difference was an updated driver.&lt;/p&gt;&#xA;&lt;p&gt;The lesson is simple: pixel shading orders are hard, and as much as possible they are best left to the GPU vendor to determine.  Compute shaders give us the option to do shading-like operations, but we should not expect to be able to &lt;em&gt;reliably&lt;/em&gt; exceed the performance of fragment shaders (even if, occasionally, we spectacularly can) because our implementations are not based on insider knowledge of how to optimize for the particular GPU—even when there &lt;em&gt;is&lt;/em&gt; a single particular GPU at all.&lt;/p&gt;&#xA;&lt;p&gt;So, if you're thinking about shading orders, that's really something the GPU should be doing for you: take it up with the vendor.  The main reason to use a compute shader would be if you want the convenience or flexibility.  Of course, if you thoroughly profile and see a performance gain, and you have reason to expect that the GPU infrastructure you are building on top of will not shift beneath your feet (e.g. you are writing for a console), then maybe using a compute shader is the right choice.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2020-07-17T11:45:47.250" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10037" PostTypeId="1" CreationDate="2020-07-17T12:49:20.397" Score="1" ViewCount="59" Body="&lt;p&gt;This is a quite wide subject which implies a lot of topics such as the platform or the compiler, but I think that it could be useful for everyone to know more about this.&lt;/p&gt;&#xA;&lt;p&gt;A common mistake is to think that conditionals are bad when writing shader but the real bad thing is branching, right ?&lt;/p&gt;&#xA;&lt;p&gt;I would love to know more about the difference between conditionals and branching with simple concrete examples and how to solve common issues.&lt;/p&gt;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="2372" LastActivityDate="2020-07-17T12:49:20.397" Title="Conditionals and branching in shaders" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;shader&gt;&lt;optimisation&gt;&lt;directx&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10038" PostTypeId="1" AcceptedAnswerId="10040" CreationDate="2020-07-17T15:59:40.080" Score="1" ViewCount="64" Body="&lt;p&gt;is it worse to do for each invocation an atomicAdd on the same memory location than doing for each invocation an atomicAdd to a unique memory location? (I know, atomicAdd does not make sense when each invocation writes to another location... but this is theoretically)&lt;/p&gt;&#xA;&lt;p&gt;I am asking, because I wrote the marching cubes algorithm and while creating the mesh I additionally want to calculate the center of mass as well.&lt;/p&gt;&#xA;&lt;p&gt;I am doing this by having four integers in the SSBO (centerX, centerY, centerZ and countTriangles)&#xA;each of these 4 integers will be increased by the atomicAdd function within the GeometryShader.&#xA;When everything is done, I only need to divide the centerX/Y/Z variable by countTriangles and I am done.&lt;/p&gt;&#xA;&lt;p&gt;if these atomics on one memory location would slow down my shader, I would outsource it to another maybe CPU function.&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-07-19T13:55:58.750" Title="Does atomic functions on same memory location cause an performance issue?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10040" PostTypeId="2" ParentId="10038" CreationDate="2020-07-17T17:54:20.457" Score="2" Body="&lt;p&gt;Will having all invocations incrementing the same atomic counter be slower than not doing that? Sure. How much slower? That depends on many factors, but it's hardly going to be a crippling performance issue.&lt;/p&gt;&#xA;&lt;p&gt;The whole point of atomic memory operations is that there is some hardware mechanism that allows them to work reasonably efficiently. Not as efficiently as bumping a local variable of course, but they shouldn't be assumed to cause a massive performance penalty.&lt;/p&gt;&#xA;&lt;p&gt;On some hardware, atomic counter operations aren't even memory operations. AMD implements them as specialized hardware within their shader system, such that atomic counter operations don't touch actual memory storage until after the rendering process that uses them is complete.&lt;/p&gt;&#xA;&lt;p&gt;Obviously, the best thing you can do is profile on your hardware-of-choice, but failing that, I would see no reason not to use this mechanism as you see fit.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-07-19T13:55:58.750" LastActivityDate="2020-07-19T13:55:58.750" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10041" PostTypeId="2" ParentId="374" CreationDate="2020-07-18T09:20:52.260" Score="1" Body="&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/MldczM&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/MldczM&lt;/a&gt;&#xA;Is ANALYTIC intersection of a ray with a triangular b-spline, 3 quadratic bezier splines, 3 CVs for each spline, 3 corner CVs are shared by 2 splines. All cv heights are orthogonal to the triangle plane. It solves for &amp;lt;=2 roots in barycentric coordinates. There's never 3 intersections, so this is a surprisingly simple tracing of a curved function.&#xA;The first derivative is super short, too.&lt;/p&gt;&#xA;&lt;p&gt;ESDF keys for camera movement&#xA;The parent shader in the comments has less optimized, less precise, more repetitive, naive simpler code.&lt;/p&gt;&#xA;&lt;p&gt;It still has the error of rendering the negative surface if the camera is inside the prism of the triangle (above or below triangle). This seems to be a simpler special case, with only 1 root, where it fails to ignore the other root. The branch to solve this may be rather simple.&lt;/p&gt;&#xA;" OwnerUserId="13711" LastEditorUserId="13095" LastEditDate="2020-07-21T17:00:27.490" LastActivityDate="2020-07-21T17:00:27.490" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10042" PostTypeId="1" AcceptedAnswerId="10044" CreationDate="2020-07-19T12:56:38.460" Score="0" ViewCount="116" Body="&lt;p&gt;Classical Phong reflection model, as described on &lt;a href=&quot;https://en.wikipedia.org/wiki/Phong_reflection_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;, computes diffuse and specular light as follows:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 diffuse = kd * dot(n, l) * i;&#xA;vec3 specular = ks * pow(dot(r, v), a) * i;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Where &lt;code&gt;n&lt;/code&gt;, &lt;code&gt;l&lt;/code&gt;, &lt;code&gt;r&lt;/code&gt;, &lt;code&gt;v&lt;/code&gt; are the normal, light, reflection and view vectors, &lt;code&gt;kd&lt;/code&gt;, &lt;code&gt;ks&lt;/code&gt; are surface diffuse and specular color, &lt;code&gt;a&lt;/code&gt; is gloss and &lt;code&gt;i&lt;/code&gt; is incoming light intensity.&lt;/p&gt;&#xA;&lt;p&gt;I understand that the diffuse term is such as it is because 1) diffuse reflection is not dependent on viewer direction and 2) surfaces angled away from light recieve less light to scatter, thus the &lt;code&gt;dot(n, l)&lt;/code&gt; term.&lt;/p&gt;&#xA;&lt;p&gt;However, shouldn't the specular term &lt;strong&gt;also&lt;/strong&gt; be multiplied by &lt;code&gt;dot(n, l)&lt;/code&gt; for the same reason? Is my assumtion that &lt;code&gt;dot(n, l)&lt;/code&gt; computes incoming light wrong?&lt;/p&gt;&#xA;&lt;p&gt;I know that the Phong model is mostly a hack, but this seems like a simple and performant modification and I haven't found this issue discussed anywhere. I've also looked into the source code of the game Tesseract, which does seem to multiply the specular term by &lt;code&gt;dot(n, l)&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="13717" LastActivityDate="2020-07-20T21:10:34.923" Title="Phong model: why no multiplication by N dot L in specular term?" Tags="&lt;shading&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10043" PostTypeId="1" CreationDate="2020-07-20T03:06:33.380" Score="2" ViewCount="150" Body="&lt;p&gt;I'm playing around with DirectX 12 ray tracing, and I'm  trying to read and write data to a 32-bit RGBA floating point RWTexture2DArray within a DirectX 12 HLSL shader. I'm getting weird corruption/noise when I read back values I've written to the texture.&lt;/p&gt;&#xA;&lt;p&gt;I've bound the texture as a UAV, and in my shader I've tagged it with the &amp;quot;globallycoherent&amp;quot; like so:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;globallycoherent RWTexture2DArray&amp;lt;float4&amp;gt;   myTextureArray;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm able to demonstrate the issue I'm seeing with a trivial bit of shader code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;myTextureArray[xIndex, yIndex, 0] = float4((float)xIndex / (float)xRes, (float)yIndex / (float)yRes, 0.0f, 1.0f);&#xA;&#xA;myOutputTexture[xIndex, yIndex] = myTextureArray[xIndex, yIndex, 0];&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;For the sake of a simple demonstration, I'm just writing increasing values of red along the x axis, and increasing values of green along the y axis, and storing them into the first slice of my 32-bit floating point RGBA RWTexture2DArray. Then, I'm immediately reading the values back from the same position.&lt;/p&gt;&#xA;&lt;p&gt;Unfortunately, even with this trivial bit of code, when I read the values back they're often garbled. I've got a screenshot of the results, notice the weird, speckled noise in the output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/skXpD.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/skXpD.jpg&quot; alt=&quot;Notice the weird noise?d&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm relatively new to DirectX12/HLSL, and I have a feeling I'm likely missing something simple. I've consulted &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwtexture2darray&quot; rel=&quot;nofollow noreferrer&quot;&gt;the Microsoft documentation&lt;/a&gt;, which states you can both read and write to a RWTexture2DArray, and I'm using the &amp;quot;globallycoherent&amp;quot; prefix as instructed.&lt;/p&gt;&#xA;&lt;p&gt;I'm using NVidia Falcor as a wrapper for some DXR experiments, so it's possible either I've missed some specific configuration (or, there's a bug in their implementation). If you can think of anything I might have missed, or might not be understanding, I'd be very appreciative of your help! I'm trying to use an array of textures as a buffer to hold various data elements (positions, indexes, etc etc), so if there's an easier/better way, let me know!&lt;/p&gt;&#xA;" OwnerUserId="11099" LastActivityDate="2020-07-20T03:06:33.380" Title="Corrupt values when writing and reading from the same RWTexture2D in HLSL/DirectX?" Tags="&lt;shader&gt;&lt;texture&gt;&lt;hlsl&gt;&lt;directx12&gt;&lt;memory&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10044" PostTypeId="2" ParentId="10042" CreationDate="2020-07-20T21:10:34.923" Score="0" Body="&lt;p&gt;The &lt;span class=&quot;math-container&quot;&gt;$N \cdot L$&lt;/span&gt; term (I've seen &amp;quot;geometry term&amp;quot; thrown around; not quite accurate, but good enough for here) is part of the rendering equation.  What you're looking at here is an estimate of the inside of the rendering equation—that is, the incoming radiance &lt;code&gt;i&lt;/code&gt; times the geometry term &lt;code&gt;dot(n,l)&lt;/code&gt; times the BRDF.&lt;/p&gt;&#xA;&lt;p&gt;The simple answer for why the Phong BRDF doesn't include the geometry term is &amp;quot;Well, it probably should, but the Phong model predates the invention of the rendering equation by more than a decade.&amp;quot;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Phong, B.T.: Illumination for computer generated pictures.  Communications of the ACM &lt;strong&gt;18&lt;/strong&gt;(6), 311–317 (1975).&lt;br/&gt;&lt;br/&gt;&#xA;Kajiya, J.T.: The rendering equation.  In: Proceedings of the 13th Annual Conference on Computer Graphics and Interactive Techniques, SIGGRAPH ’86, pp. 143–150.  ACM, New York, NY, USA (1986).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This deficiency was fixed in what is now called the Modified Phong BRDF:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Lewis, R.R.: Making Shaders More Physically Plausible.  Computer Graphics Forum &lt;strong&gt;13&lt;/strong&gt;(2), 109–120 (1994)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;At the end of the day, whether the term is present or not isn't an issue of correctness per-se.  Not having the geometry term when you might expect it just means that the BRDF corresponds to a different surface reflection that doesn't foreshorten much at glancing angles.  Indeed, many other BRDFs have terms that look like reciprocal geometry terms, so that they cancel with the actual geometry term in the rendering equation.&lt;/p&gt;&#xA;&lt;p&gt;In code, the BRDFs look like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 f_phong    = rho_s/(TWO_PI/(a+1.0)) * pow(max(0.0,dot(r,v)),a) / dot(n,l);&#xA;vec3 f_modphong = rho_s/(TWO_PI/(a+2.0)) * pow(max(0.0,dot(r,v)),a);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And so when multiplied by the light and geometry term in the rendering equation (i.e., &lt;code&gt;i * f * dot(n,l)&lt;/code&gt;), you get:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 spec_phong    = i * rho_s/(TWO_PI/(a+1.0)) * pow(max(0.0,dot(r,v)),a);&#xA;vec3 spec_modphong = i * rho_s/(TWO_PI/(a+2.0)) * pow(max(0.0,dot(r,v)),a) * dot(n,l);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;The obvious should be noted, however: while the Phong BRDF is simple to understand and implement, it is of limited accuracy on real-world materials.  It's not terrible, the way many people think it is, but it does lack important features that can be important on many materials.  It is not the state-of-the-art, and depending on your needs you may like to look elsewhere (GGX microfacet, etc.) for more modern BRDFs.&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2020-07-20T21:10:34.923" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10045" PostTypeId="1" CreationDate="2020-07-20T23:20:04.790" Score="0" ViewCount="115" Body="&lt;p&gt;This is standard Cook-Torrance BRDF in formulation for a single point light. No intergrals over a hemisphere, just a single direction to a source of incoming energy.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L_o = { \bigg (  (1-F) \frac{albedo  \cdot  (1-metallness)}{\pi} + \frac{F \cdot D \cdot G_2}{4 (n \cdot v)(n \cdot l_i) } \bigg )  \cdot L_i  \cdot  (n \cdot l_i ) }&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$L_o$&lt;/span&gt; - outgoing pixel energy&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; - incoming energy&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$l_i$&lt;/span&gt; - direction to a light source&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; - pixel normal&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; - direction to the camera&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt; - calculated Fresnel, ratio of specularly reflected energy, in range [0; 1]&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; - calculated integral of GGX NDF over some set of possible micronormal directions (depends on light source size and direction), in range [0; 1]&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$G_2$&lt;/span&gt; - calculated Smith geometry masking factor, in range [0; 1]&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Usually &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; in papers is just NDF sampled at one point, which is, of couse, won't give correct value, since it's a probablity density function and its values may exceed [0; 1] range.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$G_2 = G_1(v) * G_1(l)$&lt;/span&gt; doesn't go higher than 1 if we use this Smith &lt;span class=&quot;math-container&quot;&gt;$G_1$&lt;/span&gt; formulation:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$G_1(dir) = \frac{2 (n \cdot dir)}{(n \cdot dir)+ \sqrt{a^2 + (1 - a^2) (n \cdot dir)^2}}$&lt;/span&gt; , so it's good as well as &lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$(n \cdot l_i )$&lt;/span&gt; in the denominator is cancelled out for the specular part.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question 1:&lt;/strong&gt; what's wrong with the &lt;span class=&quot;math-container&quot;&gt;$(n \cdot v )$&lt;/span&gt; in the specular denominator? At grazing angles why do we need to divide the specular part by some small value getting big values as result? Or should it be cancelled out due to the fact that we render on per-pixel basis and a pixel covers bigger area of surface at grazing angles and already takes whis divider into accout?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question 2:&lt;/strong&gt; there are some &amp;quot;approximation&amp;quot; of Smith &lt;span class=&quot;math-container&quot;&gt;$G_2$&lt;/span&gt; like this (Earl Hammon, PBR Diffuse Lighting for GGX + Smith Microsurfaces, GDC 2017):&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{G_2}{4 (n \cdot v) (n \cdot l)} = \frac{0.5}{lerp((n \cdot v) \cdot (n \cdot l), (n \cdot v) + (n \cdot l), \alpha) }&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Again, why this one gives large values when dot products are close to zero?&lt;/p&gt;&#xA;" OwnerUserId="10193" LastEditorUserId="10193" LastEditDate="2020-07-21T17:40:08.727" LastActivityDate="2021-04-17T20:47:29.397" Title="BRDF for point lights should not return values over 1" Tags="&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10046" PostTypeId="1" AcceptedAnswerId="10047" CreationDate="2020-07-21T00:31:45.437" Score="1" ViewCount="76" Body="&lt;p&gt;I implemented Djikstra's shortest path algorithm to approximate Geodesics on arbitrary meshes. Djikstra's works, but I noticed a problem inherent to the discretization of my meshes.&lt;/p&gt;&#xA;&lt;p&gt;Consider the following figure squence:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/T0yKn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/T0yKn.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/XS7Mu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XS7Mu.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/5BIz1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5BIz1.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;...&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aQ0Qp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aQ0Qp.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is my current refinement algorithm which is the easiest/standard face subdivision. Now consider the approximation of a geodesic in 2 points:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6aRG4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6aRG4.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The blue point is where I think the actual geodesic intersects that edge, which is quite far from where the approximated geodesic passes. However that path ISN'T wrong.&lt;/p&gt;&#xA;&lt;p&gt;Consider a square grid. The distance between any 2 points in the grid is the manhattan distance  |x| + |y|.&lt;/p&gt;&#xA;&lt;p&gt;So as far as Djikstra's is concerned, a path that goes all the way down and then to the left has the same length as a path that goes diagonally in a staircase pattern. Refining the mesh won't change the distance either. In other words, the limit of the shortest path found by Djikstra in a regular square grid as the size of the squares goes to 0 is NOT the straigtht line connecting 2 points.&lt;/p&gt;&#xA;&lt;p&gt;Now the actual question, does anyone know of a way to subdivide my surface that is fairly straightforward but will actually converge to the geodesic?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-07-21T15:50:25.393" Title="Approximating Geodesics in a half edge DS, how can I refine my mesh to get good approximations" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;subdivision&gt;&lt;tesselation&gt;" AnswerCount="1" CommentCount="14" ContentLicense="CC BY-SA 4.0" />
  <row Id="10047" PostTypeId="2" ParentId="10046" CreationDate="2020-07-21T15:50:25.393" Score="1" Body="&lt;p&gt;As you pointed out, the problem here is the discretization/subdivision of the mesh. If your mesh was made of quadrilaterals instead of triangles, the obvious subdivision strategy would be to split each quadliteral into four equally sized smaller quadliterals:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\hspace{2cm}$&lt;/span&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/DxKa5.png&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\hspace{2cm}$&lt;/span&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/OANw2.png&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;&lt;/p&gt;&#xA;&lt;p&gt;For any two points &lt;span class=&quot;math-container&quot;&gt;$P_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$P_2$&lt;/span&gt;, Dijkstra's algorithm would yield sets of shortest paths between these points &lt;span class=&quot;math-container&quot;&gt;$P_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$P_2$&lt;/span&gt;. The more you refine the discretization with this subdivision strategy, the more shortest paths you'll find between the two points. However, intuitively it is clear that for every subdivision level &lt;span class=&quot;math-container&quot;&gt;$l\in\mathbb{N}$&lt;/span&gt; you could pick one of these shortest paths &lt;span class=&quot;math-container&quot;&gt;$p_l$&lt;/span&gt; such that the sequence &lt;span class=&quot;math-container&quot;&gt;$(p_l)_{l\in\mathbb{N}}$&lt;/span&gt; converges to the actual geodesic between &lt;span class=&quot;math-container&quot;&gt;$P_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$P_2$&lt;/span&gt; (with respect to some norm that has to be specified, for example the supremum norm).&lt;/p&gt;&#xA;&lt;p&gt;Unfortunately, the same is not true for the standard subdivision strategy of splitting a triangle into four smaller triangles, which you have proven with your example. I believe that, at its core, the problem is that there is no way to reach the center of the triangle with a straight line from each of its edges. This can be achieved by splitting a triangle in each subdivision step into 6 smaller triangles like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\hspace{2cm}$&lt;/span&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/ilB6v.png&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$\hspace{2cm}$&lt;/span&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/rF0LS.png&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;&lt;/p&gt;&#xA;&lt;p&gt;I do not have a proof that this subdivision is more useful to compute geodesics with Dijkstra's algorithm, but it seems quite likely to me. I would be very interested to see what your results look like with this subdivision strategy! However, no matter what you do, in the end you may or may not end up with sets of shortest paths instead of a single shortest path. In this case you will need some kind of heuristic or additional algorithm to decide which path resembles the true geodesic most closely.&lt;/p&gt;&#xA;" OwnerDisplayName="user9485" LastActivityDate="2020-07-21T15:50:25.393" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10048" PostTypeId="1" AcceptedAnswerId="10465" CreationDate="2020-07-21T16:12:38.740" Score="0" ViewCount="176" Body="&lt;p&gt;I'm looking for a way to generate curvature maps like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uE97h.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uE97h.jpg&quot; alt=&quot;curvature map&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The map stores the Convexity and Concavity of each pixel as a value from 0 to 1, where .5 is no curvature and 1 and 0 are the extremes.&lt;/p&gt;&#xA;&lt;p&gt;I searched for how to calculate the curvature of meshes and found these questions on StackExchange:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/1718/what-is-the-simplest-way-to-compute-principal-curvature-for-a-mesh-triangle&quot;&gt;What is the simplest way to compute principal curvature for a mesh triangle?&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://gamedev.stackexchange.com/questions/92621/cavity-map-generation&quot;&gt;https://gamedev.stackexchange.com/questions/92621/cavity-map-generation&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://blender.stackexchange.com/questions/146819/is-there-a-way-to-calculate-mean-curvature-of-a-triangular-mesh&quot;&gt;https://blender.stackexchange.com/questions/146819/is-there-a-way-to-calculate-mean-curvature-of-a-triangular-mesh&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But I'm not sure if these are about the method actually used in the example.&lt;/p&gt;&#xA;&lt;p&gt;What algorithm is used to bake these maps, and where can I find more information about it?&lt;/p&gt;&#xA;" OwnerUserId="13729" LastEditorUserId="13729" LastEditDate="2020-07-21T16:19:42.120" LastActivityDate="2020-12-06T09:50:00.090" Title="What method is used for baking grayscale curvature maps" Tags="&lt;texture&gt;&lt;algorithm&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10049" PostTypeId="1" AcceptedAnswerId="10052" CreationDate="2020-07-21T18:32:24.050" Score="3" ViewCount="93" Body="&lt;p&gt;I was wondering if anyone can point me in the direction of some research papers, or articles that describe a method for generating biological 3D models.&lt;/p&gt;&#xA;&lt;p&gt;I am drafting a prototype for a new game that would feature a near infinite number of creatures.&lt;/p&gt;&#xA;&lt;p&gt;I have laid out 2 possible types of procedural generation, the first is more complicated but more desirable.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;1st idea&lt;/strong&gt;&#xA;Each of these creatures should be entirely generated from a set of rules, for example:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Locomotion type = legged, limbless, rolling&lt;/li&gt;&#xA;&lt;li&gt;Number of legs&lt;/li&gt;&#xA;&lt;li&gt;Number of arms&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;2nd idea&lt;/strong&gt;&#xA;A base template is used with parameters that modify the overal appearance of the final creature&lt;/p&gt;&#xA;&lt;p&gt;I realise its an incredibly complicated topic, I've also realised theres a severe lack of resources on the subject - it seems to be extremely cutting edge.&lt;/p&gt;&#xA;&lt;p&gt;For reference, they achieve something similar in this demo of No Man's Sky &lt;a href=&quot;https://youtu.be/K0umGtw90Z4?t=96&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/K0umGtw90Z4?t=96&lt;/a&gt; (thats if its not just staged)&lt;/p&gt;&#xA;&lt;p&gt;I found the following paper:&#xA;&lt;a href=&quot;https://link.springer.com/article/10.1007/s00371-018-1589-4&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://link.springer.com/article/10.1007/s00371-018-1589-4&lt;/a&gt; but am yet to pay the subscription fee in order to access it - if anyone has read it, I would love to hear if you think it would help me out.&lt;/p&gt;&#xA;&lt;p&gt;And this also seems like a valuable resource &lt;a href=&quot;https://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc13/06/Jon%20Hudson%20Thesis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc13/06/Jon%20Hudson%20Thesis.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If anyone has any experience with this subject , I would love to pick your brain.&lt;/p&gt;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="13730" LastEditorUserId="13730" LastEditDate="2020-07-21T18:46:13.697" LastActivityDate="2020-07-22T17:55:27.480" Title="Procedural generation of biological models" Tags="&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10050" PostTypeId="2" ParentId="10045" CreationDate="2020-07-21T19:59:51.467" Score="0" Body="&lt;p&gt;I think a single direction can be greater than 1.&lt;/p&gt;&#xA;&lt;p&gt;For a BRDF the integral over the hemisphere must be less than 1 for energy conservation.&lt;/p&gt;&#xA;&lt;p&gt;If you consider a specular brdf there is only one direction, where brdf &amp;gt; 0 and all other directions return 0. Therefore when integrating over the hemisphere that direction must be much greater than 1.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-07-21T19:59:51.467" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10051" PostTypeId="1" CreationDate="2020-07-21T22:20:21.793" Score="2" ViewCount="65" Body="&lt;p&gt;I want to retrieve data that has created by the compute shader but have no clue how it works. After researching a few forums and articles on how it should work and this is what I came up with.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Compute Shader Code&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 430 core&#xA;&#xA;layout  (local_size_x  =  100)  in;&#xA;&#xA;layout(std430, binding=0) buffer Pos{&#xA;    float Position[];&#xA;};&#xA;&#xA;void main(){&#xA;    Position[gl_GlobalInvocationID.x] = float(gl_GlobalInvocationID.x);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Program Code&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;public float[] useProgram(int x_size, int y_size, int z_size){&#xA;        &#xA;        this.group_x_size = (int)Math.ceil(x_size/100);&#xA;        this.group_y_size = (int)Math.ceil(y_size/100);&#xA;        this.group_z_size = (int)Math.ceil(z_size/100);&#xA;        float[] data = new float[x_size];&#xA;        FloatBuffer buffer = BufferUtils.createFloatBuffer(x_size);&#xA;        buffer.put(data);&#xA;        int ssbo = GL15.glGenBuffers();// creates empty VBO as an object and stores it in OpenGl memory&#xA;        GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, ssbo);&#xA;        GL15.glBufferData(GL43.GL_SHADER_STORAGE_BUFFER,buffer,GL15.GL_DYNAMIC_COPY);&#xA;        GL43.glBindBufferBase(GL43.GL_SHADER_STORAGE_BUFFER, 0, ssbo);&#xA;        GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, 0);&#xA;        &#xA;        GL20.glUseProgram(computeProgram);//start the shader program&#xA;        GL43.glDispatchCompute(group_x_size, 1, 1);&#xA;        GL43.glMemoryBarrier(GL43.GL_SHADER_STORAGE_BARRIER_BIT);&#xA;&#xA;        GL15.glBindBuffer(GL43.GL_SHADER_STORAGE_BUFFER, ssbo);&#xA;        String values = GL43.glMapBuffer(GL43.GL_SHADER_STORAGE_BUFFER, GL43.GL_WRITE_ONLY).asFloatBuffer().toString();&#xA;        GL43.glUnmapBuffer(GL43.GL_SHADER_STORAGE_BUFFER);&#xA;        System.out.println(values);&#xA;        &#xA;        return null;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However this code just simply will not work the way I want it to. When I go to print out the Values it comes up null. Is there something wrong with the code or is there a better way to do it. I've looked through many forums but most of them aren't written in java.&lt;/p&gt;&#xA;" OwnerUserId="13732" LastActivityDate="2020-07-21T22:20:21.793" Title="How to retrieve data from Compute Shader to CPU?" Tags="&lt;opengl&gt;&lt;compute-shader&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10052" PostTypeId="2" ParentId="10049" CreationDate="2020-07-22T02:40:14.577" Score="4" Body="&lt;p&gt;I am playing with L-Systems and with some thorough understanding of how they work I think you could manage to get something useful out of them. You can see &lt;a href=&quot;http://paulbourke.net/fractals/lsys/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Paul Bourke's&lt;/a&gt; site for a sneak peek of what they do and you can read the  book &lt;a href=&quot;https://www.google.com/url?sa=t&amp;amp;source=web&amp;amp;rct=j&amp;amp;url=http://algorithmicbotany.org/papers/abop/abop.pdf&amp;amp;ved=2ahUKEwjNnPO66N_qAhVPc98KHS-OAXMQFjAIegQIAxAB&amp;amp;usg=AOvVaw2r9WRagwONeb1NTGPS7xVT&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Algorithmic Beauty of Plants&lt;/a&gt; by Przemyslaw Prusinkiewicz and Aristid Lindenmayer. I am going to try and explain what L-Systems do in case the links die, L-Systems are a way of creating simple rules that define the topology of plants/organisms/fractals by simple axioms, this axioms can be rewritten in terms of other rules that can create incredibly organic behaviours, originally this systems were abstract in the sense that they lacked geometric meaning, but over the years people have figured out how to transform this topologies into geometry through interpreting the rules as &amp;quot;directions&amp;quot; much like turtle graphics. I have seen this systems replace basic geometric rules such as &amp;quot;draw a line between two points&amp;quot; into create a complex building with &amp;quot;A or C characteristics&amp;quot; so I think you could define your interpreter in terms of biologically accurate creatures.&lt;/p&gt;&#xA;" OwnerUserId="9749" LastEditorUserId="9749" LastEditDate="2020-07-22T17:55:27.480" LastActivityDate="2020-07-22T17:55:27.480" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10053" PostTypeId="1" AcceptedAnswerId="10054" CreationDate="2020-07-23T08:59:37.603" Score="1" ViewCount="92" Body="&lt;p&gt;Say I have a mesh with two sets of uvs. And I have a texture made for the first set of uvs. I would like to create a second texture that has the same relationship between its pixels and the second set of uvs, as the first texture does with the first set of uvs. Such that if we change between the two different sets of uvs and apply the corresponding texture we see identical texturing on the model. And the only difference would be the texture density in different regions because of the differences in distortion and the area of the uv faces between the two uv sets.&lt;/p&gt;&#xA;&lt;p&gt;What technique can we use do this? Can it be done on the GPU?&lt;/p&gt;&#xA;&lt;p&gt;Would we possibly need to transform each uv face of the first uv set into the corresponding face of second uvs set? Not sure where we would go from there.&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-07-23T09:27:44.610" LastActivityDate="2020-07-23T12:58:54.213" Title="Transfer the texture between two different sets of uv" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;uv-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10054" PostTypeId="2" ParentId="10053" CreationDate="2020-07-23T11:56:05.263" Score="2" Body="&lt;p&gt;Are the two sets well correlated? This would boil down to having a good set of vertex attributes for each set of uv's. If each set of uv's in mapping 1 has a know set of mappings in set 2 then it should be relatively straight forward to read from the first set of uv's and write to the second set.&lt;/p&gt;&#xA;&lt;p&gt;If this is as simple as vertex 1 has a mapping in uv set 1 and a different mapping for uv set 2 then read from set one then resample the texture for set 2.&lt;/p&gt;&#xA;&lt;p&gt;On the other hand if the two sets are completely uncorrelated then it gets more complex:&#xA;A fully generic brute force solution would be to read 1 of the vertex attributes of the known mapping. Then search the entire set of uv's for set 2 filtering out those vertex positions that overlap with the current uv under consideration. Then use that list to read, resample and write the new texture.&lt;/p&gt;&#xA;&lt;p&gt;The first case is easier to implement on the gpu. The second case is more difficult and may be better to implement on the cpu for debugging then move to the gpu as performance requirements dictate.&lt;/p&gt;&#xA;&lt;p&gt;Edit for the first case:&#xA;This is the easy case, Use the uv coords from set 1 on the gpu just like you would normally to read the texture. Then use the second set as actual vertex positions adding a z value that is some constant. Don't use a MVP matrix just go straight to clip space. The gpu will worry about the resampling. In the end you will have a fullscreen quad with the final mappings. Then just read the image back from the gpu.&lt;/p&gt;&#xA;&lt;p&gt;More detail:&lt;/p&gt;&#xA;&lt;p&gt;The vertex attributes for this would be:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Vertex Position = vec2{u_set2, v_set2}&#xA;uv coords = vec2{u_set1, v_set1}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The vertex shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec2 remapping = vertex_position * 2.0 - 1.0; // remap x,y to -1 to 1&#xA;gl_position = vec4( remapping, 0.5, 1 ); &#xA;out texcoord = uv_coords_in;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The fragment shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;gl_color = texture( image_sampler, tex_coords);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2020-07-23T12:58:54.213" LastActivityDate="2020-07-23T12:58:54.213" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10055" PostTypeId="1" CreationDate="2020-07-23T14:04:02.583" Score="1" ViewCount="50" Body="&lt;p&gt;I'm looking for a compact representation of radiance over the hemisphere that is also performant to evaluate in realtime (in a pixel shader). The purpose of it is to compress surface lightfields so that they are also very performant to render in real-time (in a VR application).&lt;/p&gt;&#xA;&lt;p&gt;I found &lt;a href=&quot;https://publik.tuwien.ac.at/files/PubDat_189085.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Efficient Irradiance Normal Mapping&lt;/a&gt; which is pretty neat, it proposes 6 cheap basis functions that produce the same error over the hemisphere as spherical harmonics up to l = 2.&#xA;Now, l = 2 may be fine for irradiance, but for radiance it's too low frequency.&#xA;Looking at the results of &lt;a href=&quot;http://vcg.isti.cnr.it/Publications/2013/PDCS13/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Surface Light Field from Video Acquired in&#xA;Uncontrolled Settings&lt;/a&gt;, l = 4 spherical harmonics (25 coefficients) and l = 3  &lt;a href=&quot;https://cgg.mff.cuni.cz/%7Ejaroslav/papers/egsr2004/gautron-egsr2004-hemispherical.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;hemispherical harmonics&lt;/a&gt; (16 coefficients) seem to be enough to recreate some highlights and thus look promising.&lt;/p&gt;&#xA;&lt;p&gt;What I'm looking now for is a basis that gives similar results like l = 4 SH or l = 3 HSH, but that is cheaper to evaluate at runtime.&lt;/p&gt;&#xA;&lt;p&gt;I haven't found any other research yet that goes into the direction I'm looking for, so I'm asking if someone has some good pointers?&lt;/p&gt;&#xA;" OwnerUserId="13740" LastEditorUserId="13740" LastEditDate="2020-07-23T16:01:33.413" LastActivityDate="2020-07-23T16:01:33.413" Title="alternative to spherical harmonics to model radiance aproximation, optimized for real-time evaluation" Tags="&lt;spherical-harmonics&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10056" PostTypeId="1" AcceptedAnswerId="10057" CreationDate="2020-07-25T17:56:24.623" Score="1" ViewCount="77" Body="&lt;p&gt;I want to send a series of integer to the geometry shader,&#xA;while the data will be modified every frame.&lt;/p&gt;&#xA;&lt;p&gt;But when I try to retrive the sampleBuffer in geometry shader, it seems to keep output zero.&lt;/p&gt;&#xA;&lt;p&gt;Am I using Texture Buffer wrong, or the TBO itself just can't be used as GL_DYNAMIC_DRAW?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Init Texture Buffer&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void InitialTBO() {&#xA;    int index_tbo_reserved_size = 5000;&#xA;    glGenBuffers(1, &amp;amp;index_tbo);&#xA;    glBindBuffer(GL_TEXTURE_BUFFER, index_tbo);&#xA;    glBufferData(GL_TEXTURE_BUFFER, index_tbo_reserved_size * sizeof(GLint), NULL, GL_DYNAMIC_DRAW);&#xA;    glGenTextures(1, &amp;amp;index_tbo_tex);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Render&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void RenderChunkDataCone(Primitive* primitive) {&#xA;    Program* shaders = primitive-&amp;gt;shaders;&#xA;&#xA;    shaders-&amp;gt;use();&#xA;&#xA;    glActiveTexture(GL_TEXTURE0);   &#xA;    glBindBuffer(GL_TEXTURE_BUFFER, this-&amp;gt;index_tbo);&#xA;    glBufferSubData(GL_TEXTURE_BUFFER, 0, sizeof(GLint)*index_tbo_data.size(), index_tbo_data.data());&#xA;    glBindTexture(GL_TEXTURE_BUFFER, this-&amp;gt;index_tbo_tex);&#xA;    glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, this-&amp;gt;index_tbo);&#xA;    shaders-&amp;gt;setUniform(&amp;quot;index_tex&amp;quot;, 0);&#xA;&#xA;    glBindVertexArray(primitive-&amp;gt;vao);&#xA;    glDrawElements(primitive-&amp;gt;drawType, primitive-&amp;gt;drawCount * primitive-&amp;gt;drawCount_Inner, GL_UNSIGNED_INT, 0);&#xA;&#xA;    glBindVertexArray(0);&#xA;    shaders-&amp;gt;stopUsing();&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Geometry Shader&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;uniform samplerBuffer index_tex;&#xA;vec3 render_primitive(vec3 position){&#xA;    int status = int(texelFetch(index_tex, 0).r);&#xA;    if(status==0)&#xA;        return vec3(0,10,10);&#xA;    else if(status==1)&#xA;        return vec3(10,0,0);&#xA;    else if(status==2)&#xA;        return vec3(0,0,10);&#xA;}&#xA;&#xA;void main() {&#xA;    vec4 position =gl_in[0].gl_Position;&#xA;    vec3 returnedValue = render_primitive(position.xyz);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I've confirmed the index_tbo[0] is 1,&#xA;But the returnedValue outputed by shader will always be (0,10,10) as the value index_tex[0] received seems to be 0.&lt;/p&gt;&#xA;" OwnerUserId="13748" LastActivityDate="2020-07-25T20:25:23.607" Title="Is it possible to send Texture Buffer to shader dynamically?" Tags="&lt;opengl&gt;&lt;geometry-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10057" PostTypeId="2" ParentId="10056" CreationDate="2020-07-25T20:25:23.607" Score="1" Body="&lt;p&gt;These:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, this-&amp;gt;index_tbo);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;pre&gt;&lt;code&gt;uniform samplerBuffer index_tex;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Do not match. If the texture is a signed integer texture, then the sampler type needs to match. It should be &lt;code&gt;isamplerBuffer&lt;/code&gt;, and you won't need to do the cast.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-07-25T20:25:23.607" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10058" PostTypeId="1" AcceptedAnswerId="10059" CreationDate="2020-07-26T02:20:50.907" Score="0" ViewCount="41" Body="&lt;p&gt;I've been looking at &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Program_Introspection#Interface_query&quot; rel=&quot;nofollow noreferrer&quot;&gt;Interface queries&lt;/a&gt; in order to prevent common mistakes that are time consuming to debug, such as forgetting to bind a buffer, binding the wrong resource type, etc.&lt;/p&gt;&#xA;&lt;p&gt;However, I wasn't able to find what I wanted for images. I'd like to make sure that the type of the texture, the memory qualifier and the texture format are the same in the c++ code and in the shader :&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glBindImageTexture(index, texture, 0, true, 0, GL_READ_ONLY, GL_RGBA32F);&#xA;&#xA;layout(binding = 0, rgba32f) uniform writeonly iimage2D _heightmap;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Using glGetProgramResourceiv with GL_UNIFORM and GL_TYPE, I was able to get the type of the image, iimage2D. But nothing for the memory qualifier and the image format.&lt;/p&gt;&#xA;&lt;p&gt;Is there a way to do that, other than parsing the shader?&lt;/p&gt;&#xA;" OwnerUserId="8925" LastActivityDate="2020-07-26T22:54:05.370" Title="OpenGL shader introspection/interface queries for images" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10059" PostTypeId="2" ParentId="10058" CreationDate="2020-07-26T14:07:38.043" Score="1" Body="&lt;p&gt;Those are not accessible via introspection. It should also be pointed out that some of them don't &lt;em&gt;have&lt;/em&gt; to &amp;quot;match&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;The shader-defined format doesn't have to be the same as the image-bound format. The image-bound format defines how writing from the image interprets the data provided by the shader. The shader-defined format determines how reading from the image interprets the data in the image. So the two values are fundamentally doing different things and need not match either each other or the texture's internal format. There are &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Image_Load_Store#Format_conversion&quot; rel=&quot;nofollow noreferrer&quot;&gt;rules for how conversion works between these and the image's actual format&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For the access type, you could just pass &lt;code&gt;GL_READ_WRITE&lt;/code&gt; for everything and let the shader decide how it's going to access the storage. Given that Vulkan has no equivalent to this value, it probably doesn't matter performance-wise. Also, note that the multibind function &lt;code&gt;glBindImageTextures&lt;/code&gt;, which binds multiple images in one call, always uses &lt;code&gt;GL_READ_WRITE&lt;/code&gt; (and doesn't have a specified format). Since the whole point of that function is performance, it almost certainly doesn't matter if you always use read-write from the binding side.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2020-07-26T22:54:05.370" LastActivityDate="2020-07-26T22:54:05.370" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10060" PostTypeId="1" CreationDate="2020-07-26T18:13:55.083" Score="0" ViewCount="45" Body="&lt;p&gt;I am trying to implement clipping in my simple renderer, but i have a trouble with setting the boundaries. I used the same projection matrix that is in OpenGL. The problem is, the vertices that are behind the camera(z&amp;lt;near) when mapped to NDC are bigger than 1(but they should be less than -1), so i can't use vertex.z &amp;gt; w. &lt;img src=&quot;https://i.stack.imgur.com/HZEAg.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="13751" LastActivityDate="2020-07-26T18:13:55.083" Title="Clipping 3D Perspective matrix" Tags="&lt;3d&gt;&lt;clipping&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10062" PostTypeId="1" CreationDate="2020-07-27T06:19:39.973" Score="0" ViewCount="118" Body="&lt;p&gt;I tried feeding an .h264 video with YUV444 color format to ffmpeg in hardware decoding mode on a GTX 1660 and it looks like this color input isn't supported. I get an error in the &lt;code&gt;get_hw_format&lt;/code&gt; function.&lt;/p&gt;&#xA;&lt;p&gt;On &lt;a href=&quot;https://developer.nvidia.com/video-encode-decode-gpu-support-matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/video-encode-decode-gpu-support-matrix&lt;/a&gt; it does not say anything about h264 color support on NVDEC. How can I know if I can decode YUV444 using NVDEC?&lt;/p&gt;&#xA;&lt;p&gt;And if NVDEC supports it, why doesn't ffmpeg do it if it uses it?&lt;/p&gt;&#xA;" OwnerUserId="10964" LastActivityDate="2020-07-27T06:19:39.973" Title="Does ffmpeg or NVDEC (nvidia decoder) support YUV444 video input?" Tags="&lt;color&gt;&lt;compression&gt;&lt;video&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10063" PostTypeId="2" ParentId="5245" CreationDate="2020-07-27T14:47:59.770" Score="0" Body="&lt;p&gt;I do not know if reading directly from the frame buffer can work when you are not using the GLFW window at all. What you can do though, is create a texture which you can pass to your fragment or compute shaders and draw on it. But then methods like glDrawElements() (if i remember it correctly) will not work.&lt;/p&gt;&#xA;" OwnerUserId="13757" LastActivityDate="2020-07-27T14:47:59.770" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10064" PostTypeId="1" AcceptedAnswerId="10065" CreationDate="2020-07-28T13:47:02.583" Score="0" ViewCount="69" Body="&lt;p&gt;As someone who is trying to dive into WebGL for parallelizing simulations, or Machine Learning, or typical IIR filters I've come to realize that for everything that I want to do requires the GPU to update itself and send &amp;quot;gossip&amp;quot; signals to the screen.&lt;/p&gt;&#xA;&lt;p&gt;Sending data to the screen is fairly straight forward, however having the GPU write to itself in order to step into the next time step for a simulation and then send that information to the screen is something I have no clue about doing. I don't know what it's called or if it's even possible.&lt;/p&gt;&#xA;&lt;p&gt;I hate asking a &amp;quot;&lt;em&gt;is it possible to do X?&lt;/em&gt;&amp;quot; question, but sadly this is one of those because my knowledge regarding WebGL is so bad, and studying WebGL for a few months just to realize that it's not possible is not time I can afford right now. I have no one else to ask.&lt;/p&gt;&#xA;&lt;p&gt;However, to give this question some more meat to the bones I'll say that I assume that it is possible and it is just a matter of setting up two buffers and linking them together in some &lt;em&gt;special way&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Here's the actual question:&lt;/strong&gt; I'm familiar with the fact that you set up pipelines in WebGL, does WebGL support pipelines to itself that never goes to the screen so it can modify its internal buffers?&lt;/p&gt;&#xA;" OwnerUserId="13762" LastActivityDate="2020-07-28T14:49:32.067" Title="Let GPU write to itself" Tags="&lt;webgl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10065" PostTypeId="2" ParentId="10064" CreationDate="2020-07-28T14:49:32.067" Score="2" Body="&lt;p&gt;What you are talking about is transform feedback. With transform feedback you can capture primitives (vertices, triangles, lines) in a buffer such they can be used in subsequent draw calls. You don't have to grab the data from the GPU to the CPU and back again as you can directly use the GPU buffer you have just rendered to.&lt;/p&gt;&#xA;&lt;p&gt;I'm not exactly sure what your use-case exactly is, but you mention simulation and timesteps. Imagine a particle system where each particle has a position and a velocity at each time step of the simulation. We have two buffers A and B. A will be rendered from on even numbered frames and will be written to on odd-numbered frames and B that we write to on even numbered frames and render from on odd-numbered frames. We also have a simple vertex shader that updates the positions of vertices using the aforementioned position and velocity attributes.&lt;/p&gt;&#xA;&lt;p&gt;Then using some initial position and velocity for each particle we can start rendering from buffer A into buffer B. After having finished this process all particles will have an update position and we can render from buffer B into buffer A.&lt;/p&gt;&#xA;&lt;p&gt;With this you also have the option to not render to the at all screen by using the GL_RASTERIZER_DISCARD functionality.&lt;/p&gt;&#xA;&lt;p&gt;Take a look at the examples listed on &lt;a href=&quot;http://webglsamples.org/WebGL2Samples/#transform_feedback_instanced&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; page under 'Transform Feedback'. Or at &lt;a href=&quot;https://prideout.net/blog/old/blog/index.html@tag=opengl-transform-feedback.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; example.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2020-07-28T14:49:32.067" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10066" PostTypeId="1" AcceptedAnswerId="10067" CreationDate="2020-07-29T22:32:41.873" Score="0" ViewCount="49" Body="&lt;p&gt;I have an image and a sampler declared in a shader as follow&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout(binding = 5) uniform isampler2D heightmap;&#xA;layout(binding = 3) uniform writeonly uimage2D info;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Which are correctly bound using the following code&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glBindTextureUnit(5, heightmapId);&#xA;glBindImageTextures(3, 1, &amp;amp;infoId);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;For introspection purposes, I am trying to retrieve the binding points of these objets, 5 and 3, but I didn't find any way to do this for uniforms. Is it possible using the API?&lt;/p&gt;&#xA;&lt;p&gt;I first tried to use glGetProgramResourceIndex, since it worked with storage buffers, but it doesn't the results are get are incorrect, as if the explicit binding was ignored.&lt;/p&gt;&#xA;&lt;p&gt;I then looked at glGetProgramResourceiv, but the binding related enums are only available for storage buffers and atomic counters.&lt;/p&gt;&#xA;" OwnerUserId="8925" LastActivityDate="2020-07-30T00:51:09.710" Title="Get binding point of sampler/image in shader" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10067" PostTypeId="2" ParentId="10066" CreationDate="2020-07-30T00:51:09.710" Score="2" Body="&lt;p&gt;The &lt;code&gt;binding&lt;/code&gt; value for uniforms of opaque types is, from the perspective of the OpenGL API, the uniform's &lt;em&gt;value&lt;/em&gt;. You set it by using &lt;code&gt;glProgramUniform1i&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;As such, you query it by querying the value of the uniform with &lt;code&gt;glGetUniformiv&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-07-30T00:51:09.710" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10068" PostTypeId="1" CreationDate="2020-07-30T04:10:17.177" Score="2" ViewCount="33" Body="&lt;p&gt;What's the proper of way of calculating the coords to apply decals by let's say linear interpolation?&#xA;My understanding is that you render your GBuffer albedo, specular, etc... and after that you do another pass (before the lighting calculations) in which you modify the albedo and normal maps (and anything you'd like to get information from the decal). My guess is you transform your vertices to NDC to be able to calculate the bbox (for simplicity, I understand you can use more complex geometry) in which you want to apply the decals, use those bounds to discard every other fragment and write the decal to the maps. Is my understanding correct? And what matrix should be passed for calculating the depth? Should I do a previous pass to get the depth? Can I use the depth from a point different than the camera (I am calculating shadow maps already so being able to skip this step would be awesome), or can I reuse the one that I feed my lighting pass with?&lt;/p&gt;&#xA;" OwnerUserId="9749" LastActivityDate="2020-07-30T04:10:17.177" Title="Deferred Decals" Tags="&lt;rasterizer&gt;&lt;deferred-rendering&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10069" PostTypeId="1" CreationDate="2020-07-30T16:18:52.837" Score="2" ViewCount="287" Body="&lt;p&gt;It seems that virtually all path tracers use eye-based or view-based path tracing. That is, the light rays originate from the camera rather than the light source. The reason given for this everywhere I have seen online is that if one begins from the light source, then it is quite unlikely that the ray will ever hit the camera. For instance, the &lt;a href=&quot;https://docs.blender.org/manual/en/latest/render/cycles/optimizations/reducing_noise.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;documentation&lt;/a&gt; for Blender's cycles says &amp;quot; we do not waste light rays that will not end up in the camera&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;This seems intuitive at first, but this seems only to reverse the problem because one will just trace a ray until it hits the light source now, and this ray may never hit a light source before the maximum number of bounces, so we will just waste that ray as well. I can see how this is an improvement though, because if we originate at the camera, the first bounce will tend to have a large weight associated with it, but if we flipped the path to start from the light, then this last bounce would tend to have a small weight because many bounces have preceded it. That seems like the answer, except for one thing.&lt;/p&gt;&#xA;&lt;p&gt;Most path tracers use next even estimation, which just means that at each bounce, the light path is connected directly to a light source as long as nothing occludes that path. This is always a valid path and greatly speeds up convergence. However, if one is going to use next event estimation, then I really can't understand how tracing rays from the camera is advantageous over tracing rays from the light source? In next event estimation, one should almost always get a complete light path either way. Is it related to the ambiguity about which pixel on the camera to connect to? There is a similar ambiguity about which point of an area light to connect to.&lt;/p&gt;&#xA;&lt;p&gt;I am sure there must be a reason for tracing from the camera because everybody seems to be doing it, so if someone could explain this for me, and/or point to recent papers which compare the approaches, that would be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="12073" LastActivityDate="2020-07-31T04:19:50.157" Title="Why is eye-based ray tracing preferred over light-based ray tracing?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;physically-based&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10070" PostTypeId="2" ParentId="10069" CreationDate="2020-07-30T16:55:18.593" Score="4" Body="&lt;p&gt;As you point out there is problems about which pixel on the camera to connect to. You probably wouldn't notice where you took the sample on an area light because generally the light is pretty uniform throughout, and even if it is textured you can just take a few samples and it will average to look ~correct. However if you connect to a random pixel, you would very easily notice that some pixels are black or have aliasing problems. By starting at the camera it's easier to ensure that all pixels are being sampled enough.&lt;/p&gt;&#xA;&lt;p&gt;You are also only considered the light from one bounce. If you also want to get indirect lighting then your statement about weights comes into play again, and you are more likely to get a good path by starting at the camera.&lt;/p&gt;&#xA;&lt;p&gt;Finally there are many techniques which start from the light! And techniques which start at both ends and try and connect. Try searching for photon mapping and bi-directional path tracing. It just turns out that forward path tracers generally work the best in most situations. Renderman has an integrator which combines all these techniques  which you can read about here &lt;a href=&quot;https://rmanwiki.pixar.com/display/REN/PxrVCM&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://rmanwiki.pixar.com/display/REN/PxrVCM&lt;/a&gt; .&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-07-30T16:55:18.593" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10071" PostTypeId="2" ParentId="10069" CreationDate="2020-07-31T04:19:50.157" Score="2" Body="&lt;p&gt;It is a matter of performance.&lt;/p&gt;&#xA;&lt;p&gt;From a particular point on any object, you cannot know precisely where any illumination is coming from. There could be a near-perfect mirrored surface nearby. There could be water which reflects some portion of light to that point on the surface. Answering this question would require a full solution to the rendering equation.&lt;/p&gt;&#xA;&lt;p&gt;However, from a particular point on any object in the scene, you can at least know whether or not any lights are &lt;em&gt;directly&lt;/em&gt; casting light on that point. How? By firing a ray directly from the surface to that light. You know exactly where the lights are, so you can fire rays in those directions. If nothing opaque is in the way, then some portion of that light directly illuminates that point on the surface.&lt;/p&gt;&#xA;&lt;p&gt;If you start from the perspective of a light, you can fire a whole bunch of rays in every direction of the light and hit a whole bunch of objects. You can determine the direct illumination on all of those positions on all of those objects.&lt;/p&gt;&#xA;&lt;p&gt;But there is no guarantee that any of those objects are visible to the viewer. In this scenario, many rays and light computations get wasted.&lt;/p&gt;&#xA;&lt;p&gt;By contrast, if you start off from the perspective of all surfaces directly visible to the viewer, you can find all surfaces that are directly visible to the viewer. From there, you can compute the direct illumination for all of those points within the view.&lt;/p&gt;&#xA;&lt;p&gt;Exactly zero rays have been wasted in this scenario. Every ray you fire is contributing in some way to the image (even if a light is blocked, it's still contributing by not providing illumination from that surface).&lt;/p&gt;&#xA;&lt;p&gt;So in the case of purely direct illumination, there is no question that starting from the viewport uses fewer rays and fewer lighting computations. It is therefore faster.&lt;/p&gt;&#xA;&lt;p&gt;If you start firing doing reflection and refraction rays, these too are faster if you start from the viewer. Each reflection/refraction ray is fired from a position that we &lt;em&gt;know&lt;/em&gt; contributes to the final image. Whereas if you're firing a bunch of rays due to rays that were fired from lights, you have no idea if they're going to meaningfully contribute to the scene.&lt;/p&gt;&#xA;&lt;p&gt;In view-based ray tracing, every ray you fire will contribute meaningfully to the scene being displayed. Well, until you start having to take into account more complex lighting, such as diffuse inter-reflection. That's the point where you can no longer know for certain where the source of lighting is, so you have to start firing rays speculatively.&lt;/p&gt;&#xA;&lt;p&gt;But even then, if you're going to fire rays speculatively, it's best to start from places that you &lt;em&gt;know&lt;/em&gt; are going to be illuminated.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-07-31T04:19:50.157" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10072" PostTypeId="1" CreationDate="2020-07-31T05:08:44.627" Score="1" ViewCount="73" Body="&lt;p&gt;I saw this question some where, I think Reddit, but I can't find it. I have same issue.&#xA;Please see the screenshot beneath. I've uploaded &lt;a href=&quot;https://mega.nz/file/3pZzEKJC&quot; rel=&quot;nofollow noreferrer&quot;&gt;the PDF to mega.nz&lt;/a&gt; I'm using Adobe Acrobat Pro DC Version 2019.010.20064.&lt;/p&gt;&#xA;&lt;p&gt;I'm trying to convert the book's default (C, M, Y, K) = (99%, 98%, 18%, 6%) (ie dark purple) to &lt;a href=&quot;https://www.colorhexa.com/1aff1a&quot; rel=&quot;nofollow noreferrer&quot;&gt;(90, 0, 90, 0) (green)&lt;/a&gt;. After I click 'OK' and click 'Fix', Adobe Acrobat executes the fixup, but the color fails to change. Why?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/w5Pjt.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/w5Pjt.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13771" LastActivityDate="2020-08-11T02:50:58.537" Title="Why isn't the 'Map Colors' fixup changing text colors?" Tags="&lt;pdf&gt;" AnswerCount="0" CommentCount="3" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10073" PostTypeId="1" CreationDate="2020-07-31T19:08:47.500" Score="0" ViewCount="40" Body="&lt;p&gt;Sobel edge detection is pretty much the quintessential way to get edges out of an image. It however suffers from certain quirks.&lt;/p&gt;&#xA;&lt;p&gt;One example is, because it's gradient, based certain surfaces exhibit weird appearances in certain saliency maps. For example, given a depth image, take a plane and start inclining it. You will notice that as the plane becomes more and more perpendicular to the view, a large section of it acquires a higher and higher gradient magnitude. Thus resulting in a major area of the plane being considered an edge by any thresholding mechanism. In other words, towards the horizon, the depth difference of ANY pair of adjacent pixels that contain a portion of the plane becomes significantly large, thus getting selected as edges, despite not being edges.&lt;/p&gt;&#xA;&lt;p&gt;This also means that regions with bigger z differences tend to have bigger edges. Consider a sphere placed in front of a near plane vs a sphere placed in front of a far plane, both spheres at the same distance from the camera. If any interpolation filtering is active, then the sphere in the near plane has less pixels with large deltas than the one in the far plane thus its outline is bigger.&lt;/p&gt;&#xA;&lt;p&gt;Canny addresses this problem by doing a per pixel local search and min maxing the gradient magnitude to guarantee a one pixel wide edge. However, this is not easily parrallelizable (not GPU friendly) and thus slow.&lt;/p&gt;&#xA;&lt;p&gt;Are there other algorithms that maintain edge width that are more suitable for real time applications? The width doesn't have to be perfectly one pixel wide, rather I am just looking to reducing the standard deviation of the edge with.&#xA;They don;t have to be perge&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-07-31T19:08:47.500" Title="Are there algorithms besides Canny edge detection that can create consistent width edges?" Tags="&lt;image-processing&gt;&lt;mathematics&gt;&lt;edge-detection&gt;&lt;gradient&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10074" PostTypeId="1" CreationDate="2020-08-01T03:52:32.473" Score="0" ViewCount="8" Body="&lt;p&gt;If you are familiar with the MMP algorithm for geodesic finding, you know an important part of the algorithm revolves around solving intersections of windows.&lt;/p&gt;&#xA;&lt;p&gt;I am running into a case that I don't see mentioned in the paper and need to know if I royally fucked up.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bcTqh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bcTqh.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fzeep.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fzeep.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The first case is, the 2 windows share the source vertex but have different intersections on the edge. The second is, the sources are different but the region of one is fully within the interior of the other.&lt;/p&gt;&#xA;&lt;p&gt;Is this supposed to happen?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-08-01T04:27:24.973" LastActivityDate="2020-08-01T04:27:24.973" Title="MMP algorithm, no metion of &quot;in window&quot; intersections" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10076" PostTypeId="1" CreationDate="2020-08-01T07:02:45.770" Score="0" ViewCount="37" Body="&lt;p&gt;I would like to know if it is possible to do this using GJK alghorythm. I know how to find if polygons intersect and also find closest point on polygon from a given external point. Using Minkovski difference I can find a minimum distance between the two polygons, but my question is: is it possible, somehow, using this min distance to find the actual points on each polygon that correspond to this min distance?&lt;/p&gt;&#xA;" OwnerUserId="13775" LastActivityDate="2020-08-01T07:02:45.770" Title="How to find closest points on two not intersecting convex polygons in 2D" Tags="&lt;algorithm&gt;&lt;2d&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10077" PostTypeId="1" CreationDate="2020-08-01T08:49:59.950" Score="0" ViewCount="42" Body="&lt;p&gt;I'm currently using OpenTK (OpenGL binding for C#) to draw a lot of points (~17 million) - that very rarely change - in a cube (256 x 256 x 256) with different float &amp;quot;transparency weights&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;It pretty much works as intended, but for some reason the frame rate significantly drops if the camera is aligned with a specific axis even though (I think) the work OpenGL has to do is totally independent of the orientation.&lt;/p&gt;&#xA;&lt;p&gt;The blending mode is SRC_ONE | DEST_ONE | FUNC_ADD and DepthFunc is set to NEVER (because I don't care what's in front or in the back, all that matters is the total sum).&lt;/p&gt;&#xA;&lt;p&gt;I use a vertex array to store all the &amp;quot;transparency weights&amp;quot; in a float[256*256*256] and use a vertex shader to split the vertexId (0 - 256³) into x, y, z and calculate a color based on those transparency weight and a few settings to control brightness, orientation, etc. via shader uniforms.&lt;/p&gt;&#xA;&lt;p&gt;Here are a few more details:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://youtu.be/Yu1rTkhF7v4&quot; rel=&quot;nofollow noreferrer&quot;&gt;Youtube - Video that shows the problem&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://gist.github.com/wischi-chr/5c3d5a682cb0a900b4e178ab1384606f&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenTK code excerpt + vertex shader&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Would be great if any of you has an idea or could give me a hint why the framerate drops on one axis and how I could fix that. Thanks in advance.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update 1:&lt;/strong&gt;&lt;br /&gt;&#xA;I think it has to do with that part of the shader (because the &amp;quot;slow&amp;quot;) axis changes if I swap x, y, z but I'm still not sure why and how to fix it.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;int id = gl_VertexID;&#xA;&#xA;float x = mod(id, 256);&#xA;id /= 256;&#xA;float y = mod(id, 256);&#xA;id /= 256;&#xA;float z = id;&#xA;&#xA;vec4 result = vec4(z/256., x/256., y/256., 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update 2&lt;/strong&gt;&lt;br /&gt;&#xA;Ok, I'm now pretty sure it's not that. I rewrote it to be symmetric like so:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;int id = gl_VertexID;&#xA;&#xA;float x = float(id &amp;amp; 0x000000FF) / 1.0000001 / 256.0;&#xA;float y = float(id &amp;amp; 0x0000FF00) / 256.00001 / 256.0;&#xA;float z = float(id &amp;amp; 0x00FF0000) / 65536.001 / 256.0;&#xA;&#xA;vec4 result = vec4(x, y, z, 1.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And it still has performance issues on one axis. My current guess is, that is has something to do with the order of the points returned by the vertex shader.&lt;/p&gt;&#xA;" OwnerUserId="13777" LastEditorUserId="13777" LastEditDate="2020-08-05T06:20:19.490" LastActivityDate="2020-08-05T06:20:19.490" Title="GLSL asymmetric performance for point cloud" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;performance&gt;&lt;vertex-buffer-object&gt;&lt;blending&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10078" PostTypeId="1" AcceptedAnswerId="10079" CreationDate="2020-08-01T23:17:08.483" Score="0" ViewCount="244" Body="&lt;p&gt;I have an image rendered to the screen, and based on the normalized device coordinates of the cursor I would like to pick the pixel of the image under the cursor.&lt;/p&gt;&#xA;&lt;p&gt;Say the image has four channels, I then define a pixel struct:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Pixel {&#xA;  unsigned char r, g, b, a;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I can then get the closest index of the pixel under cursor like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int getPixel(float normalX, float normalY, float imageWidth, float imageHeight) {&#xA;  return (int)(normalY*imHeight)*imageWidth + normalX*imageWidth;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now how would I do it the other way around, basically given the pixel index get its normalized device coordinates?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-08-02T12:52:16.883" Title="Get normalized device coordinate of an image pixel" Tags="&lt;c++&gt;&lt;image&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10079" PostTypeId="2" ParentId="10078" CreationDate="2020-08-02T11:06:18.470" Score="2" Body="&lt;p&gt;You can modulus by row length to retrieve the x coordinate (think about the x coordinate &amp;quot;wrapping around&amp;quot; after each line), and division by row length to get the y coordinate (inverting the multiply you have by imageWidth). We subtract one from the width and height to ensure the last pixel in the row/column maps to &lt;code&gt;1.0&lt;/code&gt;. Note that this isn't &amp;quot;Normalized Device Coordinates&amp;quot;, since that implies a 3D quantity which also stores depth, and that all coordinates lie in &lt;code&gt;[-1,1]&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Point2D { float x; float y; };&#xA;&#xA;Point2D GetNormalizedPixelCoords(int pixelIdx, int imageWidth, int imageHeight) {&#xA;    Point2D point;&#xA;    point.x = (pixelIdx % imageWidth) / (float)(imageWidth-1);&#xA;    point.y = (pixelIdx / imageWidth) / (float)(imageHeight-1);&#xA;    return point;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6686" LastActivityDate="2020-08-02T11:06:18.470" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10080" PostTypeId="2" ParentId="10078" CreationDate="2020-08-02T12:44:21.243" Score="0" Body="&lt;p&gt;The first step to achieving what you are asking for would be to find the normalized texture coordinates a.k.a UV-coordinates of the pixel. This can be done as described by AJ Weeks in his answer. However, I wouldn't divide by &lt;code&gt;width-1&lt;/code&gt;/&lt;code&gt;height-1&lt;/code&gt;, but instead, I would add &lt;code&gt;0.5&lt;/code&gt; to the x- and y-coordinate and divide by the full width and height. This should give you the &amp;quot;center&amp;quot; of each pixel. As an example, say you have an 8x8 texture and index 10. This would yield &lt;code&gt;x=1&lt;/code&gt; and &lt;code&gt;y=2&lt;/code&gt;. After the addition, you get &lt;code&gt;x=1.5&lt;/code&gt; and &lt;code&gt;y=2.5&lt;/code&gt;. Dividing each of those by 8 gives you the normalized texture coordinates of &lt;code&gt;u=0.1875&lt;/code&gt; and &lt;code&gt;v=0,3125&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Depending on how you render your image, the next step might be a little bit tricky. In general, if your texture is mapped onto an arbitrary mesh, you need to find the triangle that includes the UV-coordinates of the pixel by performing a 2d-point-in-triangle test against the triangles' vertices UV-coordinates. Notice, that depending on your mesh's texture coordinates, there might be more than one triangle or none if you use the texture repetitively or only a certain area of it. If this is not the case, there still might be multiple triangles that contain it, if the point lies on a boundary or vertex. In this case, pick an arbitrary triangle, since the result should be the same.&lt;/p&gt;&#xA;&lt;p&gt;Now if you have found the triangle determine the &lt;a href=&quot;https://en.wikipedia.org/wiki/Barycentric_coordinate_system&quot; rel=&quot;nofollow noreferrer&quot;&gt;barycentric coordinates&lt;/a&gt; of the pixel from its UV-coordinates and the vertices of the triangle. Then use those coordinates and multiply them with the vertices 3d coordinates to get the actual 3d coordinates of the pixel in model space.&lt;/p&gt;&#xA;&lt;p&gt;Finally, perform the usual transformations with your transformation matrices -&amp;gt; model to world -&amp;gt; world to camera -&amp;gt; perspective projection. Then you have your NDC coordinates of the pixel.&lt;/p&gt;&#xA;&lt;p&gt;The determination of the 3d coordinates in model space can be simplified if your model is just a flat rectangular surface described by 4 vertices that has the one and only purpose to display the whole undistorted texture without repetitions, offsets or scaling (means the corner point vertices UV coordinates are either 0 or 1). Then you can perform a linear interpolation of the 3d coordinates in x and y direction where the UV-coordinate values of the pixel are the interpolation weights in the corresponding direction.&lt;/p&gt;&#xA;&lt;p&gt;It gets even easier if you render your texture as a full-screen image. Then you only need to subtract 0.5 from your UV-coordinates and multiply the result by 2. This transforms the UV-range [0,1] to the NDC range [-1,1]. The depth value can be chosen arbitrarily.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-08-02T12:52:16.883" LastActivityDate="2020-08-02T12:52:16.883" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10081" PostTypeId="1" AcceptedAnswerId="10082" CreationDate="2020-08-02T13:05:06.013" Score="0" ViewCount="43" Body="&lt;p&gt;I'm trying to create a simple painting application. And I was wondering about an efficient way to draw pixels on the screen.&lt;/p&gt;&#xA;&lt;p&gt;I have a pixel struct:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Pixel {&#xA; unsigned char r, g, b, a;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And I have two methods for converting between pixel coordinates and normalized pixel coordinates. &lt;code&gt;w&lt;/code&gt; and &lt;code&gt;h&lt;/code&gt; are image width and height respectively.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int getPixelIndex(float2 norm, int w, int h) {&#xA;   return (int)(norm.x*h)*w + norm.y*h;&#xA;}&#xA;&#xA;float2 getPixelNormCoords(int index, int w, int h) {&#xA;   float2 norm;&#xA;   norm.x = (index % w) / (float)(w-1);&#xA;   norm.y = (index / h) / (float)(h-1);&#xA;   return norm;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now if I want to draw a red pixel under the cursor I could do it like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int pixelIndex = getPixelIndex(cursorNorm.x, cursorNorm.y, w, h);&#xA;&#xA;pixels[pixelIndex] = {255, 0, 0, 255};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However what if I want to fill more pixels around the cursor, to create different brushes. Say I want to create a square brush with a given offset &lt;code&gt;d&lt;/code&gt;. One hacky way to do this would be:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float delta = 10e-4;&#xA;for (float i = -d; i &amp;lt; d; i+=delta) {&#xA;  for (float j = -d; j &amp;lt; d; j+=delta) {&#xA;    int pixelIndex = getPixelIndex(cursorNorm.x+i, cursorNorm.y+j, w, h);&#xA;    pixels[pixelIndex] = {255, 0, 0, 255};&#xA;  }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Another way would be to iterate over each pixel:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;for (int i = 0; i &amp;lt; size(pixels); i++) {&#xA;   float2 norm = getPixelNormCoords(i, w, h);&#xA;&#xA;   if (fabs(norm.x-cursorNorm.x) &amp;lt; d &amp;amp;&amp;amp; fabs(norm.y-cursorNorm.y) &amp;lt; d)&#xA;      pixels[i] = {255, 0, 0, 255};&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However this way seems to be extremely costly.&lt;/p&gt;&#xA;&lt;p&gt;Are there more efficient and less hacky methods to accomplish what I'm trying to do?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-08-02T13:12:13.990" LastActivityDate="2020-08-02T14:31:33.710" Title="Paint pixels on the image around the cursor for painting application" Tags="&lt;c++&gt;&lt;image&gt;&lt;pixels&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10082" PostTypeId="2" ParentId="10081" CreationDate="2020-08-02T14:31:33.710" Score="1" Body="&lt;p&gt;I don't know, why you consider your first approach hacky, but an alternative would be to analyze the shape of your brush and how it interacts with your underlying data structure. For example for your rectangle:&lt;/p&gt;&#xA;&lt;p&gt;Let's assume the brush's sides are parallel to the sides of the image. Then you can calculate how man pixels are covered by your offset &lt;code&gt;d&lt;/code&gt;. Let's call be the number of pixels between two corners &lt;code&gt;n&lt;/code&gt;. Then you can determine the index of the upper left pixel of your rectangle and fill the next &lt;code&gt;n&lt;/code&gt; indices since they represent the left border of your rectangle. Then add &lt;code&gt;h&lt;/code&gt; to the index of the upper left point to get to the pixel right of it. Fill the next &lt;code&gt;n&lt;/code&gt; pixels. Repeat this &lt;code&gt;n&lt;/code&gt; times and you have finished filling your rectangle. Here is some untested code that should demonstrate the approach:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;float left_x = cursorNorm.x - d;&#xA;float upper_y = cursorNorm.y - d;&#xA;float lower_y = cursorNorm.y + d;&#xA;&#xA;int index_upper_left = getPixelIndex(left_x, upper_y, w, h);&#xA;int index_lower_left = getPixelIndex(left_x, lower_y, w, h);&#xA;&#xA;int n = index_lower_left - index_upper_left;&#xA;&#xA;for (int i=0; i &amp;lt; n; ++i)&#xA;    for (int j=0; j &amp;lt; n; ++j)&#xA;        int index = index_upper_left + j*h + i&#xA;        pixels[index] = {255, 0, 0, 255};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Since this is all symmetric, you can vary this to start at the center point, run i and j just up to &lt;code&gt;n/2&lt;/code&gt; and do something like that:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;for (int i=0; i &amp;lt; n/2; ++i)&#xA;    for (int j=0; j &amp;lt; n/2; ++j)&#xA;        int index_left = index_center - j*h&#xA;        int index_right = index_center + j*h&#xA;&#xA;        pixels[index_left + i] = {255, 0, 0, 255};&#xA;        pixels[index_left - i] = {255, 0, 0, 255};&#xA;        pixels[index_right + i] = {255, 0, 0, 255};&#xA;        pixels[index_right - i] = {255, 0, 0, 255};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;More complex shapes like circles get a little bit more complicated but you can calculate for each affected column of pixels the index of the upper and lower affected pixel and fill between them. Remember that you can abuse symmetry here. Meaning if you found the upper pixel of a column, the lower pixel has the same y distance to the y-value of the center point. Additionally, the bounds to the left and to the right of the center are also identical. A helpful algorithm to find the bounds might be &lt;a href=&quot;https://www.geeksforgeeks.org/bresenhams-circle-drawing-algorithm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bresenham’s circle drawing algorithm&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-08-02T14:31:33.710" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10084" PostTypeId="1" CreationDate="2020-08-04T16:08:21.953" Score="0" ViewCount="72" Body="&lt;p&gt;In many datasets in the literature of both Computer Vision and Computer Graphics there is the albedo map of a scene represented as RGB images, which in principle corresponds to the diffuse reflecting component. The diffuse reflectance factor though of a material/surface is represented a one value, usually as ρ (rho), e.g. in the radiosity formulation. Thus, I am trying to understand how to go from an RGB representation to the corresponding diffuse value. I saw some people averaging the RGB values of the albedo map, e.g. for a pixel value (0, 168, 170) this would give:&lt;/p&gt;&#xA;&lt;p&gt;((0/255) + (168/255) + (170/255)) / 3 = 0.441830065359477&lt;/p&gt;&#xA;&lt;p&gt;however is just averaging enough/correct or there is a specific formulation.&lt;/p&gt;&#xA;&lt;p&gt;I am puzzled quite some time now about it and I cannot really find a good answer. Thus, I would appreciate any feedback.&lt;/p&gt;&#xA;" OwnerUserId="13790" LastActivityDate="2020-09-15T10:06:35.657" Title="Albedo image map to color's Light Reflectance Value (LRV)" Tags="&lt;rendering&gt;&lt;radiosity&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10085" PostTypeId="1" AcceptedAnswerId="10086" CreationDate="2020-08-04T17:19:20.050" Score="3" ViewCount="91" Body="&lt;p&gt;Usually, if we want to interpolate some vertex attributes, say &lt;span class=&quot;math-container&quot;&gt;$A_1$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$A_2$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$A_3$&lt;/span&gt;, we have to first divide them by their corresponding &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; in view space, then we interpolate them using barycentric weights and finally we multiply them by the interpolated &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; at the current pixel. To interpolate this &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;, we have to inverse the 3 &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; of each vertex, then interpolate them and finally inverse the result to have the interpolated &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In other words, the interpolated attribute &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; is equal to:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;A = z \left(w_0 \times \frac{A_1}{Z_1} + w_1 \times \frac{A_2}{Z_2} + w_2 \times \frac{A_3}{Z_3}\right)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;where &lt;span class=&quot;math-container&quot;&gt;$w_i$&lt;/span&gt; are the barycentric weights, &lt;span class=&quot;math-container&quot;&gt;$Z_i$&lt;/span&gt; are the depths of each vertex and &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; is the interpolated depth:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;z = \frac{1}{w_0 \times \frac{1}{Z_1} + w_1 \times \frac{1}{Z_2} + w_2 \times \frac{1}{Z_3}}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now my question is: instead of going back and forth between attributes and their reciprocals, can we just use the vertices'&lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; in normalized device coordinates, that is, the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;s that have been divided by &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;, after the perspective projection?&lt;/p&gt;&#xA;&lt;p&gt;If I understand correctly, we interpolate the reciprocal of vertex attributes, because it's linear in screen space, but what about the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; in NDC space, after the homogeneous divide? If we can manage to use it, we already have a &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; that we can linearly interpolate, because it has been homogenized?&lt;/p&gt;&#xA;&lt;p&gt;In the book &amp;quot;Game Engine Architecture&amp;quot;, page 667, they say:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;with w-buffering, we cannot linearly interpolate depths directly. Depths must be inverted prior to interpolation and the re-inverted prior to being stored the w-buffer.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;In other words, we don't need to invert &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; back and forth to find the interpolated depth: we just have to use the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; in NDC space, that has been divided by view-space &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;. So we can directly interpolate the &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; in NDC space to have perspective-correct depth, but how can I use this interpolated depth to interpolate other vertex attributes?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2020-08-05T06:53:34.850" Title="Interpolate vertex attributes with $z$ AFTER homogeneous divide" Tags="&lt;transformations&gt;&lt;perspective&gt;&lt;interpolation&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10086" PostTypeId="2" ParentId="10085" CreationDate="2020-08-05T06:53:34.850" Score="4" Body="&lt;p&gt;The &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; of NDC space is related to &lt;span class=&quot;math-container&quot;&gt;$1/Z_\text{view}$&lt;/span&gt; but not the same. With a typical projection matrix,  they're related by an affine remapping,&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;Z_\text{NDC} = a \, \frac{1}{Z_\text{view}} + b&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$a, b$&lt;/span&gt; are some constants related to the near and far planes. So, in general you wouldn't be able to substitute &lt;span class=&quot;math-container&quot;&gt;$Z_\text{NDC}$&lt;/span&gt; for &lt;span class=&quot;math-container&quot;&gt;$1/Z_\text{view}$&lt;/span&gt; in the interpolation expressions. The &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; factor isn't a problem, as it would factor out and cancel, but if &lt;span class=&quot;math-container&quot;&gt;$b \neq 0$&lt;/span&gt; then it will produce some extra terms and throw off the interpolation.&lt;/p&gt;&#xA;&lt;p&gt;If I'm hearing you right, it sounds like you're concerned about the idea of needing to prepare every single vertex attribute value (multiplying by &lt;span class=&quot;math-container&quot;&gt;$1/Z_\text{view}$&lt;/span&gt;) before interpolation and then reverse that afterward. Well, there is an easier way: we can create perspective-corrected barycentric coordinates &lt;span class=&quot;math-container&quot;&gt;$w'_0, w'_1, w'_2$&lt;/span&gt;, defined by&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;w'_i \equiv \frac{w_i / Z_i}{w_0/Z_0 + w_1/Z_1 + w_2/Z_2}&#xA;$$&lt;/span&gt;&#xA;Then we can interpolate any attributes by &lt;span class=&quot;math-container&quot;&gt;$w'_0 A_0 + w'_1 A_1 + w'_2 A_2$&lt;/span&gt;, and it will be perspective-correct interpolation. You can verify this is equivalent to your original interpolation formula in your question. If we have more than three scalar attributes to interpolate (which we usually do), this would be the cheaper way to do it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-05T06:53:34.850" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10087" PostTypeId="1" CreationDate="2020-08-06T21:09:46.227" Score="0" ViewCount="42" Body="&lt;p&gt;I want to create my own 2D graphics library using signed distance functions where everything is drawn on the GPU. Browsing the web I quickly found &lt;a href=&quot;https://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Inigo Quilez website&lt;/a&gt; that describes how to draw basic shapes with signed distance functions. I can work out the math on my own and come up with toy examples using Shadertoy. The problem I have is that I do not understand how I could  I can call a function like drawCircle(...) from &amp;quot;normal&amp;quot; C code on the CPU to trigger the call to a function that draws a circle in a fragment shader. Of course I could draw the circle to a texture and send this to the GPU but that would not use the GPU for drawing.&lt;/p&gt;&#xA;&lt;p&gt;What would be a reasonable software design where one could invoke draw calls from the CPU using a painters model and then these would be executed on the GPU in a fragment shader?&lt;/p&gt;&#xA;" OwnerUserId="13753" LastActivityDate="2020-08-06T21:09:46.227" Title="GPU accelerated 2D graphics library with signed distance functions" Tags="&lt;gpu&gt;&lt;fragment-shader&gt;&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10088" PostTypeId="1" CreationDate="2020-08-07T15:49:15.550" Score="1" ViewCount="81" Body="&lt;p&gt;I've been reading up on a vulkan tutorial online, here: &lt;a href=&quot;https://vulkan-tutorial.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://vulkan-tutorial.com&lt;/a&gt;. This question should apply to any 3D rendering API however.&lt;/p&gt;&#xA;&lt;p&gt;In this lesson &lt;a href=&quot;https://vulkan-tutorial.com/Vertex_buffers/Index_buffer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://vulkan-tutorial.com/Vertex_buffers/Index_buffer&lt;/a&gt;, the tutorial had just covered using indexed rendering in order to reuse vertices when drawing the following simple two-triangle quad:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://vulkan-tutorial.com/images/indexed_rectangle.png&quot; alt=&quot;Text&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;The four vertices were assigned red, green, blue and white colours as vertex attributes and the fragment shader had those colours interpolated across the triangles as expected. This leads to the ugly visual artefact on the diagonal where the two triangles meet. As I understand it, the interpolation will only be happening across each triangle, and so where the two triangles meet the interpolation doesn't cross the boundary.&lt;/p&gt;&#xA;&lt;p&gt;How could you, generally in any rendering api, have the colours smoothly interpolated over all four corners for a nice colour wheel affect without having this hard line?&lt;/p&gt;&#xA;" OwnerUserId="13805" LastActivityDate="2020-08-07T15:49:15.550" Title="How could I remove this colour interpolation artefact across a quad?" Tags="&lt;glsl&gt;&lt;color&gt;&lt;vulkan&gt;&lt;interpolation&gt;&lt;fragment-shader&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10089" PostTypeId="1" CreationDate="2020-08-08T11:23:19.637" Score="2" ViewCount="487" Body="&lt;p&gt;(I am new to Computer Graphics in general)&lt;/p&gt;&#xA;&lt;p&gt;I am learning how to ray trace from a book called ''Peter Shirley - Ray Tracing in One Weekend''. In the book, the code is written in C++. I have intermediate-advanced level understanding of good ol' C, but I've never written even simple programs in C++. I don't pretend to understand everything the code says in the book. But, that is the fun part -- figuring it out.&lt;/p&gt;&#xA;&lt;p&gt;But, for ray tracing, even C is slow. And writing GLSL fragment shaders is fast, even on my potato PC. And GLSL is closer to C than to C++. So, I'm trying to follow through the book using GLSL. But, GLSL has many limitations and I was hoping if you could teach me how to get around those limitations.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Pointers. GLSL doesn't have pointers. In the book, there is a function&#xA;&lt;code&gt;bool hit_sphere(const vec3&amp;amp; center, float radius, const ray&amp;amp; r)&lt;/code&gt;&#xA;I believe that ''address of'' operator just points to the variable that is passed when the function is called. Without pointers, how to call a function by reference in GLSL?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Late binding. In the book, every object is a class which exposes an interface function called &lt;code&gt;hit&lt;/code&gt; which returns if a ray hits the object. How does one implement that in GLSL structs?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="13807" LastEditorUserId="13915" LastEditDate="2020-09-03T06:52:42.090" LastActivityDate="2020-09-03T06:52:42.090" Title="How to work around the pointer limitations of GLSL?" Tags="&lt;glsl&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10090" PostTypeId="1" CreationDate="2020-08-08T19:42:15.413" Score="1" ViewCount="27" Body="&lt;p&gt;Clipping is down in homogeneous clip space, therefore after multiplying the vertices by the model-view matrix. But as we do clipping in clip space, the position of the new vertices that we interpolate is in clip space, so how can I translate back those new vertices coordinates into view space?&lt;/p&gt;&#xA;&lt;p&gt;I could perform the inverse transformation, but it seems costly. So how exactly do clipping work in the graphics pipeline? I mean, how can we get the position of the new generated vertices in view space?&lt;/p&gt;&#xA;&lt;p&gt;For example, with OpenGL, I would do the following in the vertex shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout (location = 0) in vec3 pos; // vertex position in model space&#xA;&#xA;out vec3 posViewSpace;&#xA;&#xA;// M V P are the model view projection matrices&#xA;&#xA;void main() {&#xA;    posViewSpace = V * M * pos; // I want the pos in view space for shading&#xA;    gl_Position = vec4(P * V * M * pos, 1.0); // Give OpenGL the position in clip space&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;But how can this work, because &lt;code&gt;posViewSpace&lt;/code&gt; that will be given to the pixel shader has nothing to do with the &lt;em&gt;new vertices&lt;/em&gt; generated after clipping? Or maybe it doesn't matter, because &lt;code&gt;posViewSpace&lt;/code&gt; will be interpolated from the &lt;em&gt;original&lt;/em&gt; vertices, but the pixel shader won't notice? Will the interpolation be correct and usable in the pixel shader, even if it's performed from the original vertices and not the new generated vertices?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2020-08-08T19:54:14.060" Title="Using original vertices coordinates after clipping" Tags="&lt;opengl&gt;&lt;clipping&gt;&lt;pixel-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10091" PostTypeId="2" ParentId="10090" CreationDate="2020-08-08T19:54:14.060" Score="1" Body="&lt;p&gt;A vertex consists of not just the position, but &lt;em&gt;all&lt;/em&gt; of the values passed from the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Processing&quot; rel=&quot;nofollow noreferrer&quot;&gt;vertex processing stage&lt;/a&gt; to the rasterizer. So if a vertex gets clipped, the new vertices generated in that process must &lt;em&gt;generate&lt;/em&gt; new values for those vertex processing outputs. It does this using the same math that it uses to generate the new vertex position.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-08-08T19:54:14.060" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10092" PostTypeId="2" ParentId="10089" CreationDate="2020-08-08T23:42:34.943" Score="3" Body="&lt;p&gt;I'll get to the specifics of your question presently, but first it is important to discuss the broad thesis of your idea: porting C++ code as is to GLSL.&lt;/p&gt;&#xA;&lt;p&gt;This is a bad idea. The execution model of shaders is &lt;em&gt;fundamentally&lt;/em&gt; different from the way a normal program (even a multi-threaded program) works. Attempting to port such code from one execution model to another is not a good idea. Your best bet is to try to make the algorithms involved fit the nature of the &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview&quot; rel=&quot;nofollow noreferrer&quot;&gt;rendering pipeline&lt;/a&gt;. That is, you need to understand how rendering works, then try to apply the mechanics of rendering to the problem you're trying to solve.&lt;/p&gt;&#xA;&lt;p&gt;For example, in regular CPU code, you might implement a ray-tracer by iterating over a bunch of locations on the screen and doing ray-scene intersection tests for each of them. Doing that iteration on the GPU in GLSL code is wrong. Instead, you should map rendering concepts to the needs of a ray-tracing algorithm. You might have each fragment shader do a single ray/scene processing step, with the fragment shader inputs being a direction from the camera. There would be no explicit loop over the screen's pixels; the loop happens implicitly in the rasterizer. The rasterizer generates a fragment shader invocation for each pixel-sized area of a rendered object. You would simply render a single quad that covers the whole screen.&lt;/p&gt;&#xA;&lt;p&gt;Things like that are how you need to think of these kinds of problems in a GPU-centric computation model.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;GLSL does not have pointers. But it does have &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;shader storage buffer objects&lt;/a&gt;, which allow you to define arbitrarily large regions of memory that the shader can read from. A &amp;quot;pointer&amp;quot; in this model is just an index into an array of data structures. You have to do the indexing explicitly in GLSL code.&lt;/p&gt;&#xA;&lt;p&gt;Similarly, any form of &amp;quot;late binding&amp;quot; can just be a switch statement based on some value in a data structure. The different &lt;code&gt;case&lt;/code&gt;es define which function to call.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-08-08T23:42:34.943" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10093" PostTypeId="1" CreationDate="2020-08-09T13:41:43.800" Score="0" ViewCount="25" Body="&lt;p&gt;I want to clip triangles to the near plane, in homogeneous clip space, so for each edge, I have to see if it crossed the near plane. If it has, I linearly interpolate the two endpoints based on the intersection point.&lt;/p&gt;&#xA;&lt;p&gt;The problem is that this works well in view space, because we only have to compare the vertices' &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; against the near plane. But in homogeneous clip space, &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; goes from &lt;span class=&quot;math-container&quot;&gt;$-w$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;, and this &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; is different for each point! So how can I perform the clipping in homogeneous clip space, and then interpolate the attributes based on the intersection point, if the two endpoints don't have the same near plane (&lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; are different)?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2020-08-09T13:41:43.800" Title="How to interpolate vertex while clipping in homogeneous clip space?" Tags="&lt;interpolation&gt;&lt;rasterizer&gt;&lt;clipping&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10094" PostTypeId="1" CreationDate="2020-08-09T17:14:56.847" Score="1" ViewCount="118" Body="&lt;p&gt;I have an octree containing different LODs of an &lt;a href=&quot;https://en.wikipedia.org/wiki/Isosurface&quot; rel=&quot;nofollow noreferrer&quot;&gt;isosurface&lt;/a&gt; that was extracted using &lt;a href=&quot;https://en.wikipedia.org/wiki/Marching_cubes&quot; rel=&quot;nofollow noreferrer&quot;&gt;Marching Cubes&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Neighbouring chunks show surfaces that do not line up if they have different LOD. See image below.&lt;/p&gt;&#xA;&lt;p&gt;I find that stitching them up is a hairy and complicated affair, so I am looking at alternatives to Marching Cubes, but I am not sure if this will solve my problem?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Isosurface#Dual_Contouring&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dual Contouring&lt;/a&gt; would be a candidate. Its main advantage seems to be sharp-edges, but it is unclear to me if different LODs of a Dual Contour surface would line up.&lt;/p&gt;&#xA;&lt;p&gt;Another is &lt;a href=&quot;https://www.csie.ntu.edu.tw/%7Ecyy/publications/papers/Ho2005CMS.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cubic Marching Squares&lt;/a&gt;. But again it is unclear if LODs match up in here.&lt;/p&gt;&#xA;&lt;p&gt;To be clear: I do not use LOD to adaptively refine, based on geometry. I use LOD to have far away (from camera/vehicle) chunks in low resolution.&lt;/p&gt;&#xA;&lt;p&gt;So my question: Does moving from MC to either DC or CMS solve the issue of LOD cracks in the surface?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PB4tB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PB4tB.png&quot; alt=&quot;iso-surface showing cracks&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6562" LastActivityDate="2020-08-09T17:14:56.847" Title="Isosurface with cracks between LODs" Tags="&lt;computational-geometry&gt;&lt;volumetric&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10095" PostTypeId="1" AcceptedAnswerId="10099" CreationDate="2020-08-09T18:52:48.773" Score="2" ViewCount="501" Body="&lt;p&gt;From what I understand of Vulkan, we have a render pass with its associated image resources and subpasses, and each subpass accesses those resources and may synchronise with previous subpasses to process the scene. In a 3D scene, we will have some geometry and lighting and shaders etc. we can do depth pass, deferred shading and so on - and that can all be encapsulated in a single render pass, by chaining multiple subpasses and their results together.&lt;/p&gt;&#xA;&lt;p&gt;Excluding the scenario of tiled rendering, or when we are rendering to multiple final render targets, when would we ever need multiple render passes in a 3d scene? I understand that something like post processing or UI compositing could be implemented in a second render pass, as they need the result from the first 3d pass to present the final image. I am at a loss as to a situation whereby a game engine, let's say, would need multiple render passes, as all of its geometry and lighting and shading etc. can be drawn with the same render pass, and that render pass will contain all the final necessary buffers, like the final image.&lt;/p&gt;&#xA;&lt;p&gt;Other than using multiple render passes as you might use subpasses (each render pass relying on the previous one in some way and each render pass having only one subpass) - what is the point?&lt;/p&gt;&#xA;&lt;p&gt;I am very much a beginner to Vulkan and to all of these concepts so please forgive any errors in the question itself or naive notions.&lt;/p&gt;&#xA;" OwnerUserId="13805" LastEditorUserId="13805" LastEditDate="2020-08-09T19:34:42.120" LastActivityDate="2020-08-10T14:02:56.263" Title="What are the use cases for multiple render passes?" Tags="&lt;rendering&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="11" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10096" PostTypeId="1" AcceptedAnswerId="10097" CreationDate="2020-08-10T10:22:39.303" Score="1" ViewCount="58" Body="&lt;p&gt;I am new to graphics programming and i'm learning opengl. I managed to make a really simple renderer where i can import models display theirs textures with all lighting. My goal is to make a simple painting software like &lt;strong&gt;Substance painter&lt;/strong&gt; or &lt;strong&gt;Mari&lt;/strong&gt; but much much simpler and i don't have any idea on how they work ? I googled but couldn't find a good answer.&lt;/p&gt;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="13813" LastActivityDate="2020-08-10T12:54:50.930" Title="How 3D painting software works" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10097" PostTypeId="2" ParentId="10096" CreationDate="2020-08-10T12:54:50.930" Score="3" Body="&lt;p&gt;We had some related questions lately, so you might find them useful:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10081/paint-pixels-on-the-image-around-the-cursor-for-painting-application&quot;&gt;Paint pixels on the image around the cursor for painting application&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10034/how-are-textures-projected-onto-3d-models-in-texture-painting-applications&quot;&gt;How are textures projected onto 3d models in texture painting applications&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10078/get-normalized-device-coordinate-of-an-image-pixel&quot;&gt;Get normalized device coordinate of an image pixel&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I can't tell you how the named applications do it, since I don't have access to the code, but painting onto a 3d model could be achieved as follows:&lt;/p&gt;&#xA;&lt;p&gt;When you click the &amp;quot;paint&amp;quot; button, you cast a ray from the camera position into your 3d scene. For perspective projections, the direction depends on the mouse's screen position. You can look into my answer to &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/9954/how-to-unproject-cursor-with-orthographic-projection&quot;&gt;this question&lt;/a&gt; to get an idea of how this is done.&lt;/p&gt;&#xA;&lt;p&gt;Now perform a collision check of the ray and your model to find the affected triangle/triangles and vertices. Calculate the &lt;a href=&quot;https://en.wikipedia.org/wiki/Barycentric_coordinate_system&quot; rel=&quot;nofollow noreferrer&quot;&gt;Barycentric coordinates&lt;/a&gt; where the ray hits the affected triangle. Use them to interpolate the texture coordinates of the intersection point. From the model data, you should know, which texture is used at the target location.&lt;/p&gt;&#xA;&lt;p&gt;Now you know where you want to paint in your models' texture. How to proceed depends on what you want to paint. In case you just want to paint a pixel, you have to overwrite the texture's pixel at this location. You can do this either on the CPU or on the GPU using the rendering pipeline.&lt;/p&gt;&#xA;&lt;p&gt;If you don't understand some things I mentioned yet, read the links I provided and continue &lt;a href=&quot;https://learnopengl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;learning OpenGL&lt;/a&gt;. Things will get clearer as soon as you know the rendering pipeline and get used to working with textures. If something is still not clear after that, feel free to ask.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-08-10T12:54:50.930" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10098" PostTypeId="1" AcceptedAnswerId="10100" CreationDate="2020-08-10T13:48:59.700" Score="8" ViewCount="1182" Body="&lt;p&gt;Apparently most people use BVHs in their raytracers. The ray-AABB intersection code is very fast and and the BVHs also compresses empty space efficiently, working even with infinitely large objects, while octrees (a more uniform subtype of BVH) apparently have a problems with compressing large open worlds - no way you can insert into a finite grid that huge mountain in the distance, without making the grid cells overly large. So what are the best practices?&lt;/p&gt;&#xA;" OwnerUserId="13814" LastActivityDate="2021-04-02T22:06:37.853" Title="Is BVH faster than the octree/kd-tree for raytracing the objects on a GPU?" Tags="&lt;raytracing&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10099" PostTypeId="2" ParentId="10095" CreationDate="2020-08-10T14:02:56.263" Score="8" Body="&lt;p&gt;Instead of listing specific use cases, I will explain the technical limitations of a render pass structure which would prevent someone from putting all of their rendering within it. The use cases naturally fall out from those limitations.&lt;/p&gt;&#xA;&lt;p&gt;The most important being this: you cannot arbitrarily access &lt;em&gt;any of the images&lt;/em&gt; attached to the render pass throughout the entire render pass. It doesn't matter if a particular subpass doesn't use the image as a render target throughout that subpass; you cannot bind it as a texture/image and read from/write to it in a shader. This covers the entirety of the render pass from start to end.&lt;/p&gt;&#xA;&lt;p&gt;Now, there are input attachments. These are uses of attachments that allow you to read from them in the shader. However, they aren't textures (though &lt;a href=&quot;https://stackoverflow.com/q/43632903/734069&quot;&gt;they are descriptors&lt;/a&gt;); they have more limitations than textures. The most important limitation being that you can only read from a pixel that corresponds to the current fragment's location (and also, you can only read them from a fragment shader). You can't fetch data arbitrarily from the image. A particular FS invocation can only read the specific pixel that was written previously at this FS invocation's location.&lt;/p&gt;&#xA;&lt;p&gt;Now, you can do some things within that limitation. You can do programmatic blending, for example. You can do deferred lighting passes, since any particular FS invocation only needs to read gbuffer data from the specific pixel for that invocation's location.&lt;/p&gt;&#xA;&lt;p&gt;But the main point is this: &lt;em&gt;any effect&lt;/em&gt; which requires arbitrarily reading from an image that was rendered to &lt;em&gt;must&lt;/em&gt; be in a different render pass from the render pass that rendered that image.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-08-10T14:02:56.263" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10100" PostTypeId="2" ParentId="10098" CreationDate="2020-08-11T03:00:31.707" Score="9" Body="&lt;p&gt;First, it is important to observe that there are basically two different &amp;quot;classes&amp;quot; of methods for building accelerations structures for ray tracing: 1) space subdivision methods (e.g. BSP, kD-Tree, Octree, etc.); and 2) object subdivision methods (e.g. BVH). While space subdivison methods work by recursively subdividing the &lt;em&gt;space&lt;/em&gt; with planes, without sticking to the geometry embedded into that space, object subdivison methods work by subdividing the geometry recursively into smaller and smaller parts, wrapping each part with a, usually tight, volume. More on the basics of space and object subdivision that can be found in the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Primitives_and_Intersection_Acceleration.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;PBRT v3 online book&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Each method (space or object sudivision) has its own pros and cons. In the case of space subdivision methods, since the subspaces do not overlap, we can usually traverse the structure in front-to-back, or back-to-front, order more easily. When a ray is traversing such structure, as soon as it hits a surface, we can stop the traversal. This usually leads to faster traversal schemes. Several software renderers take advantage of the traversal efficiency given by the space subdivision schemes. On the other hand, space subdivision schemes may be more intricate to implement (usually you have to tweak some epsilons) and may lead to deeper trees. Also, they do not like very much dynamic geometry. If the geometry encoded into a space subdivision acceleration structure changes, we usually have to rebuild the acceleration structure from scratch.&lt;/p&gt;&#xA;&lt;p&gt;Object subdivision methods have quite different characteristics. Since the object is subdivided with volumes, and these volumes may overlap, the traversal is traditionally slower. We cannot, for instance, stop traversing a BVH as soon as a ray finds an intersection with a surface. Since the volumes overlap, we may need to check for potential intersections with nearby primitives before quitting the traversal. On the other hand, it may be easier to implement a BVH because we do not have to &lt;em&gt;split&lt;/em&gt; the object parts with planes. Also, BVHs usually generate shallower structures (which may eventually compensate the slower traversal). However, one of the most interesting aspects of the BVHs is that they are &lt;em&gt;dynamic geometry&lt;/em&gt;-friendly. If geometry changes (but not much, actually), we can simply locally adjust the size and position of the corresponding bounding volume (i.e. refitting). These adjustments may cause the need to adjust the parent volumes, a procedure that may culminate in a &lt;em&gt;chain reaction&lt;/em&gt; that may reach the root node of the BVH. All in all, assuming that we have a reasonably balanced BVH, these operations will be ~O(log n), which is really fast and cool.&lt;/p&gt;&#xA;&lt;p&gt;The above paragraph describes the traditional characteristics of the BVHs. There is currently lots of research going on on the topic, and several of its ineficiencies have been significantly reduced over time. It should be noted, for instance, that still in 2007, &lt;a href=&quot;https://dl.acm.org/doi/10.1145/1189762.1206075&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wald, Boulos and Shirley&lt;/a&gt; have designed a very efficient BVH-based acceleration structure, for interactive ray tracing on GPUs, that rivals with space subdivision schemes such as kD-Trees. This work was very influential.&lt;/p&gt;&#xA;&lt;p&gt;Actually there are several reasons that make the BVHs the preferred acceleration data structure for interactive ray tracing o GPUs. According to &lt;a href=&quot;https://www.sciencedirect.com/science/article/pii/S0097849316301376?casa_token=D0jTp_c1HngAAAAA:YCD31gt1rp4zR8wzE20vTxIEXAJR83pOZh0Bp_saqZChzCHOfgKwu0W7N0jT9dJGCvKjAVTdsQ&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wodniok and Goesele&lt;/a&gt;, the main factors that have turned the BVH into a popular acceleration structure in the context of GPU ray tracing are its &amp;quot;&lt;em&gt;memory footprint (...) efficient empty space cut-off, fast construction, and simple update procedure (...) while (...) offering similar (...) performance as kD-Trees&lt;/em&gt;&amp;quot;. Regarding fast BVH reconstruction, it may be interesting to take a look at the LBVH, by &lt;a href=&quot;https://onlinelibrary.wiley.com/doi/full/10.1111/j.1467-8659.2009.01377.x?casa_token=s3kaFgXZt38AAAAA%3Ar1tdA-tx8aAclVsQeLTh8oUR5XDgEgI-twjAhezqDUWmBm8W2AaL8OzD0KU9s0EfZN5DHZFWHB8gZXM&quot; rel=&quot;nofollow noreferrer&quot;&gt;Lauterbach &lt;em&gt;et. al.&lt;/em&gt;&lt;/a&gt;, the HLBVH, by &lt;a href=&quot;https://research.nvidia.com/sites/default/files/pubs/2010-06_HLBVH-Hierarchical-LBVH/HLBVH-final.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pantaleoni&#xA;and Luebke&lt;/a&gt;, and the one by &lt;a href=&quot;https://www.nvidia.in/docs/IO/77714/sbvh.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Karras and Aila&lt;/a&gt;, that are capable to rebuild BVHs iteractively. Overlapping impacts the traversal procedure efficiency because, when a ray hit the overlap, it has to be tested against the two child nodes. SBVHs, by &lt;a href=&quot;https://www.nvidia.in/docs/IO/77714/sbvh.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Stich et. al.&lt;/a&gt; is a hybrid structure that employs both spatial and object subdivisions such that overlap is reduced. The cons, according to the paper, are the fact that SBVH does not handle dynamic scenes anymore, and that it may increase memory consumption up to 30%. The SBVH building procedure, also, is not as fast as for the regular BVHs.&lt;/p&gt;&#xA;&lt;p&gt;The current &lt;a href=&quot;https://raytracing-docs.nvidia.com/optix/guide/nvidia_optix_programming_guide.180313.A4.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;NVidia RTX GPUs support the traditional BVH, the SBVH and Karras/Aila acceleration structure&lt;/a&gt;. As pointed out and detailed by &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10106/5681&quot;&gt;@DirectX_Programmer, in his answer below&lt;/a&gt;, these structures are actually combined, by the RTX drivers, into a more flexible arrangement composed by two levels.&lt;/p&gt;&#xA;" OwnerDisplayName="user5681" LastEditorDisplayName="user5681" LastEditDate="2021-04-02T22:06:37.853" LastActivityDate="2021-04-02T22:06:37.853" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10101" PostTypeId="1" AcceptedAnswerId="10102" CreationDate="2020-08-12T10:37:12.353" Score="0" ViewCount="63" Body="&lt;p&gt;I am not entirely sure that this is the right stack exchange, but I couldn't find any other suitable one - please redirect me if necessary.&lt;/p&gt;&#xA;&lt;p&gt;There exists mathematically defined colour spaces which help us represent colors with accuracy/efficiency in computers, and different color spaces will capture different ranges of the human visible colour gamut, and because our screens cannot represent colors as raw wavelengths we must use these spaces instead.(correct me if anything said there is wrong)&lt;/p&gt;&#xA;&lt;p&gt;How do these relate to how our computer screens actually show colour? From what I understand, our screens only take in N-bit RGB signals for their LCDs, so why do we worry about having all these complex, computationally expensive colourimetric spaces, when we want to do colour processing or storage etc. For example, the sRGB space has a gamma encoding, to represent a different data range with the same amount of bits... but that gamma encoding (for a greater range of dark tones?) cannot actually be displayed on screen. And CIE xyY might be excellent for spectrum based rendering and accurately producing and grading colours - but I understand that we cannot actually see their results, only RGB approximations. Again correct me if any of the above is wrong! I say none of this with much authority, which is mainly why I have to ask this question :)&lt;/p&gt;&#xA;&lt;p&gt;We are storing different, nuanced, &amp;quot;perception correct&amp;quot;, data in this 8-bit channel format - but is that extra nuance is  lost as soon as we send it off to our raw RGB 8-bit channel screens, and if so, doesn't that loss invalidate (to some extent) all our extra measures to produce ever more accurate and wider gamuts?&lt;/p&gt;&#xA;&lt;p&gt;This question focusses on R8G8B8A8 displays, as I imagine HDR would have a different story.&lt;/p&gt;&#xA;" OwnerUserId="13805" LastEditorUserId="13805" LastEditDate="2020-08-12T13:00:51.190" LastActivityDate="2020-08-15T00:47:18.283" Title="What is the relation between colour spaces and what is actually displayed on our screens?" Tags="&lt;color&gt;&lt;color-science&gt;&lt;colorspace&gt;" AnswerCount="2" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10102" PostTypeId="2" ParentId="10101" CreationDate="2020-08-12T16:17:34.777" Score="1" Body="&lt;p&gt;Several reasons. Im listing them in random order&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;There are entire industries that do other things than display things on computer screens. If you were to print a booklet, make a package, movie projection or paint a car you would probably be wise to be able to mathematically model it for design, quality control and documentation purposes.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Not all screen suck and not all are good. Quite many screens out there can show wider color ranges than sRGB, or wider but still not entire sRGB. See sRGB is well suited for the designs it was designed for namely crt screens. LCD screens have had  hard time coming to sRGB gamut, but we are getting there. So many screens can not even do sRGB and many now exceed it.&lt;/p&gt;&#xA;&lt;p&gt;The RGB color on each screen is different! Unless you have a screen that has been calibrated to sRGB odds are low that it shows sRGB (even if it does bet goes off in few weeks). Now for most people this is ok they arent aware how much off their screen is (i remember calibrating for first time o was quite shocked).&lt;/p&gt;&#xA;&lt;p&gt;Anyway point is that you might be interested is describing the color so that you can do same color, not just same numeric value, on a different screen or display technology.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You might be doing color science and communicating measurements to others, or calculate how fast humans can separate the colors.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You might be developing a light simulator, i dunno like for movie special effects and or technical design and your interested in the light spectrums.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You might need to do distributions of colors visually&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;And so on...&lt;/p&gt;&#xA;&lt;p&gt;As for gamna encoding your screen is not linear. If your screen were tuned linear it would be crappy indeed. And in anycase good screens have 10 to 12 bits of color to work with so gamma correcting is no problem.&lt;/p&gt;&#xA;&lt;p&gt;As for spectral colors CIE is not dealing with spectrums... Not at all. All 3 component color is dealing with human perception. Spectrums are way different things, the thing you call orange on screen and what your physics book called wavelength are different things.&lt;/p&gt;&#xA;" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2020-08-13T05:47:46.650" LastActivityDate="2020-08-13T05:47:46.650" CommentCount="6" CommunityOwnedDate="2020-08-13T05:47:46.650" ContentLicense="CC BY-SA 4.0" />
  <row Id="10103" PostTypeId="1" AcceptedAnswerId="10234" CreationDate="2020-08-12T17:06:09.847" Score="0" ViewCount="71" Body="&lt;p&gt;I'm creating a primarily 2d game (platformer perspective) with 2d background parallax layers. The parallax effect falls out of the fact that I'm positioning a bunch of layers in 3d and using a perspective camera. I'm using Unity which has a left-handed coordinate system with camera pointing down positive Z (positive X rightwards, positive Y is upwards).&lt;/p&gt;&#xA;&lt;p&gt;I'd like to occasionally apply an effect that &amp;quot;artificially raises up&amp;quot; the parallax layers in the background. So that the layers further into the background increase their Y position as their Z position increases. Hopefully this diagram makes it clear:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xvYfH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xvYfH.png&quot; alt=&quot;Diagram of parallax layers&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;How would I construct a 4x4 matrix that I could multiply by my usual perspective matrix in order to produce this effect? (Is it calling shearing?) I thiiink (but I'm not 100% sure without seeing it) that I want the Y change of each layer in screen space to be proportional to &lt;code&gt;1/z&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;(Note: I realise I could fake this by moving the background layers directly but I'd like to avoid that if possible!)&lt;/p&gt;&#xA;" OwnerUserId="13824" LastActivityDate="2020-09-17T02:38:58.390" Title="Shear(?) matrix projection along Z (depth) axis" Tags="&lt;3d&gt;&lt;perspective&gt;&lt;camera-matrix&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10104" PostTypeId="1" CreationDate="2020-08-13T03:06:35.360" Score="0" ViewCount="41" Body="&lt;p&gt;I am starting to learn about the &lt;a href=&quot;https://en.wikipedia.org/wiki/Laplace_operator&quot; rel=&quot;nofollow noreferrer&quot;&gt;laplacian operator&lt;/a&gt; &lt;span class=&quot;math-container&quot;&gt;$\Delta = \nabla \cdot \nabla\phi(p)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Which can be described as the divergence of the gradient of a scalar function &lt;span class=&quot;math-container&quot;&gt;$\phi$&lt;/span&gt;. This is equivalent to the sum of the second order partial derivatives of the function.&lt;/p&gt;&#xA;&lt;p&gt;However, it seems its &lt;a href=&quot;https://en.wikipedia.org/wiki/Discrete_Laplace_operator&quot; rel=&quot;nofollow noreferrer&quot;&gt;graph equivalent&lt;/a&gt; is just the sum of the differences of adjacent vertices. Am I reading that right? In my head that should be equivalent to the first order partial derivatives, not the second order ones.&lt;/p&gt;&#xA;&lt;p&gt;(I didn't know whether to ask here or in math, I decided here is more relevant because this is in the context of geometry processing)&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-08-13T07:59:45.873" Title="Is the laplacian operator for meshes just the sum of the differences of neighbouring vertices?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10105" PostTypeId="2" ParentId="10104" CreationDate="2020-08-13T07:59:45.873" Score="2" Body="&lt;p&gt;You can see why the sum of differences is giving a second derivative if you look at the derivative of a one-dimensional function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;. The derivative of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; at &lt;span class=&quot;math-container&quot;&gt;$x_0$&lt;/span&gt; is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \frac{df}{dx}(x_0) \approx \frac{f(x_0 + dx) - f(x_0)}{dx} $$&lt;/span&gt;&#xA;The second derivative is then&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{eqnarray*}&#xA;\frac{d^2f}{dx^2}(x_0) &amp;amp;\approx&amp;amp; &#xA;  \frac{df/dx(x_0) - df/dx(x_0-dx)}{dx} \\&#xA;  &amp;amp;\approx&amp;amp; \frac{\left(f(x_0+dx) - f(x_0)\right) -&#xA;                  \left(f(x_0) - f(x_0-dx)\right)}{dx^2} \\&#xA;  &amp;amp;=&amp;amp; \frac{\left(f(x_0+dx) - f(x_0)\right) +&#xA;                  \left(f(x_0-dx) - f(x_0)\right)}{dx^2},&#xA;\end{eqnarray*}&lt;/span&gt;&#xA;i.e. the sum of the local differences, scaled by a distance factor &lt;span class=&quot;math-container&quot;&gt;$dx^2$&lt;/span&gt;. In a &lt;em&gt;graph&lt;/em&gt; Laplacian, you don't have any distances, just graph connections, so it's just the sum of the local differences.&lt;/p&gt;&#xA;&lt;p&gt;When working on meshes, though, we typically want to take the geometry of the mesh into account. There are many ways to do this, but the most popular seems to be the &lt;em&gt;cotangent Laplacian&lt;/em&gt;, where the local difference for each edge is weighted by the sum of the cotangents of the angles opposite that edge.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2020-08-13T07:59:45.873" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10106" PostTypeId="2" ParentId="10098" CreationDate="2020-08-13T09:40:31.820" Score="4" Body="&lt;p&gt;@Christian Pagot&#xA;I think it is worth mentioning, that DXR is using Bottom Level Acceleration Structures (BLAS) as well as Top Level Acceleration Structures (TLAS):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/1kZZB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1kZZB.png&quot; alt=&quot;Figure 3: Overview of raytracing building blocks&quot; /&gt;&lt;/a&gt;&#xA;&lt;strong&gt;Figure 3:&lt;/strong&gt; Overview of raytracing building blocks&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CJj8g.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CJj8g.png&quot; alt=&quot;Figure 4: Acceleration Structure&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Figure 4:&lt;/strong&gt; Overview of raytracing building blocks&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-1&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-1&lt;/a&gt; - please refer for more informations. Image 3 and 4 are copied from chapter 7 and 8.&lt;/p&gt;&#xA;&lt;p&gt;You may also find some interesting bits in Microsoft DXR documentation - &lt;a href=&quot;https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html&lt;/a&gt; I really hoped that I could find some more about rebuilding TLAS/BLAS. If I remember correctly there are two ways - if structures differ only slightly, you can do partial rebuild. When you get to the point, where structures differ too much from actual geometry, you have to do full rebuild. I don't have a source stating big O complexity, I am sorry.&lt;/p&gt;&#xA;&lt;p&gt;Due to some disadvantages of using BVH e.g.lack of front-to-back traversal, some methods were implemented to deal with that:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;[...]However, ordered traversal in a structure based on object partitioning, such as a BVH, is not achieved so easily. While an implementation based on a traversal priority queue (rather than a traversal stack) enables front-to-back traversal of a BVH [7], most publicly available, widely used production ray tracing APIs do not provide ordered BVH traversal variants.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;From &lt;a href=&quot;http://www.realtimerendering.com/raytracinggems/unofficial_RayTracingGems_v1.7.pdf#page=147&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.realtimerendering.com/raytracinggems/unofficial_RayTracingGems_v1.7.pdf#page=147&lt;/a&gt; - Chapter 9 &lt;em&gt;Multi-Hit Ray Tracing in DXR&lt;/em&gt; by Christiaan Gribble and SURVICE Engineering&lt;/p&gt;&#xA;&lt;p&gt;I generally recommend this book, even though I've just read 1/3 of it. It contains a lot of state of the art articles about raytracing.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;@lightxbulb&#xA;I hope that I've managed to support part of Christian's Pagot statements with sources. I'm really disappointed that I couldn't find complexity of rebuilding BHV in DXR. Maybe somebody will have a link to that.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;@Nash Gold&#xA;&lt;a href=&quot;https://rads.stackoverflow.com/amzn/click/com/B007COYODQ&quot; rel=&quot;nofollow noreferrer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.amazon.com/Real-Time-Rendering-Tomas-Akenine-Mo%C2%A8ller-ebook/dp/B007COYODQ/&lt;/a&gt; (I haven't read 4th edition) - you can find Collision Detection algorithms in chapter 17. Acceleration Algorithms in chapter 14. Also throughout the book, there is a lot of talking about intersection algorithms and even about usage of triangle fans, strips, meshes and pros, cons of all of them.&lt;/p&gt;&#xA;&lt;p&gt;I enjoyed this book at the beginning. But if you're seasoned graphics programmer, you know most of its content through other sources. Therefore I would only refer to mentioned chapters.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-13T09:40:31.820" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10108" PostTypeId="1" AcceptedAnswerId="10133" CreationDate="2020-08-13T13:17:07.570" Score="1" ViewCount="47" Body="&lt;p&gt;I am working on ray/path-tracer using DXR and I'm starting with simple AO. In first pass, I am storing normal value and RayTCurrent():&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[shader(&amp;quot;closesthit&amp;quot;)]&#xA;void ClosestHit(inout RayPayload payload, in Attributes attrib)&#xA;{&#xA;    // Calculate triangle normal code - unrelated, so I deleted it&#xA;    &#xA;    // Store RayTCurrent value in payload&#xA;    payload.normalWithDepth = float4(triangleNormal, RayTCurrent());&#xA;}&#xA;&#xA;[shader(&amp;quot;raygeneration&amp;quot;)]&#xA;void RayGen()&#xA;{  &#xA;    RayDesc ray = { origin, 1e-4f, rayDir, 1e+38f};&#xA;    RayPayload payload;&#xA;    payload.worldPos = float4(0, 0, 0, 0);&#xA;    payload.normalWithDepth = float4(0, 0, 0, 0);&#xA;    &#xA;    TraceRay(SceneBVH, RAY_FLAG_NONE, 0xFF, 0, 1, 0, ray, payload);&#xA;&#xA;    // Simply storing returned payload in RWTexture&amp;lt;float4&amp;gt;&#xA;    RTOutputNormal[DispatchRaysIndex().xy] = payload.normalWithDepth;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In AO pass I am using this information to calculate world space position of given pixel (i.e. transform from ndc to world space coordinate):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[shader(&amp;quot;raygeneration&amp;quot;)]&#xA;void RayGenAO()&#xA;{&#xA;    float2 pixelCenter = (float2) LaunchIndex / (float2) LaunchDimensions + float2(0.5f / (float) LaunchDimensions.x, 0.5f / (float) LaunchDimensions.y);&#xA;    float4 normalAndDepth = NormalTextureInput.SampleLevel(g_sampler, pixelCenter, 0);&#xA;&#xA;    // normalAndDepth.w is clamped to 1.0f, therefore information about distance to hit point is lost&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hIh5R.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hIh5R.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;You can see, that above code results in correct AO results (1 spp noise with no filtering or accumulation) for happy buddha model. However, any AO can be seen when camera is extremely close (max 1 unit from object). In other cases I am getting completely white, flat model. The problem is that texture is clamping value in first pass to 1, so I am losing information about real distance between ray origin and ray hit.&lt;/p&gt;&#xA;&lt;p&gt;Here is a hlsl code for AO generation. I don't think that any problem exists in there, apart from not enough information from texture. &lt;strong&gt;Therefore, below code can be ignored:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[shader(&amp;quot;raygeneration&amp;quot;)]&#xA;void RayGen()&#xA;{&#xA;    uint2 LaunchIndex = DispatchRaysIndex().xy;&#xA;    uint2 LaunchDimensions = DispatchRaysDimensions().xy;&#xA;&#xA;    // Figure out pixel world space position (using length of a primary ray found in previous pass)&#xA;    float3 primaryRayOrigin, primaryRayDirection; &#xA;    GenerateCameraRay(LaunchIndex, primaryRayOrigin, primaryRayDirection);&#xA;    &#xA;    float2 pixelCenter = (float2) LaunchIndex / (float2) LaunchDimensions + float2(0.5f / (float) LaunchDimensions.x, 0.5f / (float) LaunchDimensions.y);&#xA;    float4 normalAndDepth = NormalTextureInput.SampleLevel(g_sampler, pixelCenter, 0);&#xA;    float3 pixelWorldSpacePosition = primaryRayOrigin + (primaryRayDirection * normalAndDepth.w);&#xA;&#xA;    //RTOutput[LaunchIndex] = float4(normalAndDepth.w, normalAndDepth.w, normalAndDepth.w, 1.0f);&#xA;    //return;&#xA;    &#xA;    if (normalAndDepth.w == 0.0f)&#xA;    {&#xA;        // Terminate if primary ray didn't hit anything&#xA;        RTOutput[LaunchIndex] = float4(0.0f, 0.2f, 0.4f, 1.0f);&#xA;        return;&#xA;    }&#xA;    &#xA;    uint seed = initRand(LaunchIndex.x + LaunchIndex.y * LaunchDimensions.x, g_cubeCB.frameCount);&#xA;    float3 worldDir = getCosHemisphereSample(seed.x, normalAndDepth.xyz);&#xA;    &#xA;    RayDesc aoRay;&#xA;    RayPayload payload;&#xA;    float3 aoSampleDirection = worldDir;&#xA;    float ao = 0.0f;&#xA;&#xA;    aoRay.Origin = pixelWorldSpacePosition;&#xA;    aoRay.TMin = g_aoCB.minT;&#xA;    aoRay.TMax = g_aoCB.aoRadius; //&amp;lt; Set max ray length to AO radius for early termination&#xA;    aoRay.Direction = aoSampleDirection;&#xA;    &#xA;    payload.T = g_aoCB.aoRadius; //&amp;lt; Set T to &amp;quot;maximum&amp;quot;, to produce no occlusion in case ray doesn't hit anything (miss shader won't modify this value)&#xA;&#xA;    // Trace the ray&#xA;    TraceRay(SceneBVH, RAY_FLAG_NONE, 0xFF, 0, 1, 0, aoRay, payload);&#xA;    ao = payload.T / g_aoCB.aoRadius;&#xA;    &#xA;    RTOutput[LaunchIndex.xy] = float4(ao, ao, ao, 1.0f); //&amp;lt; Replace all cached AO with current result&#xA;}&#xA;&#xA;    [shader(&amp;quot;miss&amp;quot;)]&#xA;    void Miss(inout RayPayload payload : SV_RayPayload)&#xA;    {&#xA;        // Empty&#xA;    }&#xA;    &#xA;    [shader(&amp;quot;closesthit&amp;quot;)]&#xA;    void ClosestHit(inout RayPayload payload, in Attributes attrib)&#xA;    {&#xA;        payload.T = RayTCurrent();&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-19T13:01:41.497" Title="Texture value clamped to 1" Tags="&lt;raytracing&gt;&lt;texture&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10110" PostTypeId="1" CreationDate="2020-08-14T13:41:23.733" Score="0" ViewCount="80" Body="&lt;p&gt;As I understand the usual practice is to obtain the SDF by the means of a KD-tree. But the KD-tree generation and the lookup (for each ray step) are, well, slow, while the octree can be easily modified without regenerating it. Maybe there is some way to build such KD-tree on fly, without sorting, since the octree already has everything pre-sorted in a well defined way? With a plain non-octree grid one can precalc the SDF into empty spaces, but in octree the empty space is compressed. I've considered adding SDF to the empty octant corners and then interpolating along them, but I'm unsure how it will work with the dynamic modification. Do I have to recalc the empty space SDFs on each modded voxel? Now what about SDF of the space outside of the octree grid? How does one extrapolate it? Maybe one can delay SDF generation until the moment ray actually enters the field?&lt;/p&gt;&#xA;&lt;p&gt;Context: I'm looking towards SDF since it apparently allows soft body animation for voxel models (I want to design a purely voxel based video game engine), or at least help removing voxel slab connection seams. Maybe I'm looking in the wrong place or from the wrong angle? I have previously considered using tensors to deform the path ray travels and using the usual raytracing instead of raymarching, but how would one combine the tensor space with the octree raytracing? That would still require something like a KD-tree to do the tensor lookup at the octree nodes. And I doubt one can interpolate tensors linearly in a non-linear space.&lt;/p&gt;&#xA;" OwnerUserId="13814" LastEditorUserId="13814" LastEditDate="2020-08-14T13:52:09.333" LastActivityDate="2020-08-14T13:52:09.333" Title="How does one obtain SDF of an octree?" Tags="&lt;raytracing&gt;&lt;raymarching&gt;&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10111" PostTypeId="2" ParentId="10101" CreationDate="2020-08-15T00:47:18.283" Score="1" Body="&lt;p&gt;The real story here is actually very interesting and can be enlightening. So I offer this alternate answer to help better answer this question. Also, my answer below is a very specific to this question. The full story is too big to put here, but worth the trouble of learning.&lt;/p&gt;&#xA;&lt;p&gt;In the 1930-50's researchers started looking into the human visual system. These studies looked into the range and brightness of colors that humans can see. The results were surprising. Our color range is somewhat limited and that color range is effected by how bright the room is. While we can see 6 magnitudes of order with respect to brightness, the number of colors we can see at each of these 1 million brightness levels varies. In a moderately lit room we can see a heck of a lot more colors then we can in a very bright room.&lt;/p&gt;&#xA;&lt;p&gt;When the television was first being created it had to account for these differences. But a television outputs color at a fairly narrow range of brightness (especially the early television) which is about 1 to 100 nits. (with humans being able to see between 1 and 1 million nits) This is a fairly low lighting level and we see more colors (including black and white) in a dimly lit room. So the television needed to output more dim colors then bright colors at the same brightness and the logarithmic color curve was born.&lt;/p&gt;&#xA;&lt;p&gt;The sRGB color space is a direct result. It is our eye with its tricky ability to see lots of colors in dim lighting that forces this curve on the hardware.&lt;/p&gt;&#xA;&lt;p&gt;But, the technology behind monitors continues marching forward and today we have monitors that can produce upwards of 1,000 nits of brightness, not to mention that brightness can be varied much more broadly. Also, modern monitors can produces a wider range of colors then early monitors. Further, movie makers and game developers can not easily &amp;quot;think&amp;quot; in logarithmic space we mere humans tend to think much better in linear space. So there really needs to be a way to translate from logarithmic space to linear space so media creators can more easily reason and about and work with the colors they produce. Also, now that we have monitors that can produce colors at different levels it sure would be nice to be able to convert movies and games into the &amp;quot;native&amp;quot; space that any given monitor actually displays.&lt;/p&gt;&#xA;&lt;p&gt;In fact, it would be much better to &amp;quot;ship&amp;quot; all our media with the best possible colors and then convert it to whatever the display that media is being shown on is capable of.&lt;/p&gt;&#xA;&lt;p&gt;And that is exactly what a lot of modern media creators do. So the relationship between the color space and what is shown on your monitor is actually a fairly complex dance between what is shipped in the media, the capabilities of your video hardware and the capabilities of the monitor it is being shown on. An 8 bit color encoding may end up going through multiple translations before it makes it to your 8 bit monitor. While the same media being shown on a 10 bit monitor could go through a very different set of translations.&lt;/p&gt;&#xA;&lt;p&gt;With monitors showing colors in 8, 10, or 12 bits per color. Many can now easily represent most of the standard media color spaces and choosing one to work or visualize in is more a matter of personal taste or need then physical necessity.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-08-15T00:47:18.283" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10112" PostTypeId="1" AcceptedAnswerId="10116" CreationDate="2020-08-15T04:57:16.493" Score="0" ViewCount="241" Body="&lt;p&gt;In HLSL, we have cbuffers and tbuffers.&lt;/p&gt;&#xA;&lt;p&gt;MSDN's description for tbuffers is the following:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;A texture buffer is a specialized buffer resource that is accessed&#xA;like a texture. Texture access (as compared with buffer access) can&#xA;have better performance for arbitrarily indexed data. You can bind up&#xA;to 128 texture buffers per pipeline stage.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;what is the difference to cbuffers? in cbuffers i can access the data arbitrarily, too.&#xA;When should i use a tbuffer and when should i use a cbuffer?&lt;/p&gt;&#xA;" OwnerUserId="11739" LastActivityDate="2020-08-16T09:02:24.307" Title="What is a tbuffer and what is their use case?" Tags="&lt;hlsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10113" PostTypeId="1" CreationDate="2020-08-15T12:01:10.153" Score="0" ViewCount="16" Body="&lt;p&gt;All other possible values of VkColorSpaceKHR specify a recognised colour space encoding, and I assume that creating a swapchain with those values would mean that the final pixel data submitted by the application to the presentation queue would be transformed, somewhere down the line, into a decoded space, through a known EOTF.&lt;/p&gt;&#xA;&lt;p&gt;The specification defines VK_COLOR_SPACE_PASS_THROUGH_EXT as follows:&lt;/p&gt;&#xA;&lt;p&gt;&amp;quot;VK_COLOR_SPACE_PASS_THROUGH_EXT specifies that color components are used 'as is'. This is intended to allow applications to supply data for color spaces not described here.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;What would this mean for my application? Let's say (entirely hypothetically) that I was building some fancy spectrum renderer and I was using a custom system for representing colours, and then that would all be transformed into a final RGB format, with just the three channels of intensity values, independent of colour space or any encoding.&lt;/p&gt;&#xA;&lt;p&gt;Would my image really just be blitted to the screen &amp;quot;as is&amp;quot;, as the specification claims? If so, how does the implementation know what to do with the given pixel data? Would it result in every pixel on my display being set to those raw RGB intensities, with no transfer functions being applied?&lt;/p&gt;&#xA;&lt;p&gt;Thanks, and as always, I do not really know what I'm talking about so please bear with me.&lt;/p&gt;&#xA;" OwnerUserId="13805" LastActivityDate="2020-08-15T12:01:10.153" Title="How is VK_COLOR_SPACE_PASS_THROUGH_EXT supposed to be used?" Tags="&lt;vulkan&gt;&lt;colorspace&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10114" PostTypeId="1" AcceptedAnswerId="10159" CreationDate="2020-08-15T15:07:36.587" Score="2" ViewCount="339" Body="&lt;p&gt;Yet another question about colour space...&lt;/p&gt;&#xA;&lt;p&gt;In my research on CIE XYZ system, I found that it is based on the CIE RGB colour matching experiments, and that because the RGB system needed occasional negative values, XYZ was developed in order to have an entirely non-negative system. From this I infer that the x(), y() and z() colour matching functions are just transformations of the original r(), g() and b() functions, using exactly the same data. I also found online that the XYZ and RGB systems were completely interchangeable, and XYZ is just preferred for the lack of any negative components.&lt;/p&gt;&#xA;&lt;p&gt;If that is incorrect please correct me!&lt;/p&gt;&#xA;&lt;p&gt;However, if they are interchangeable and based off of the same data, why is it that Wikipedia's comparison of the two spaces shows a marked difference? Is the missing curvy section outside of that inner triangle just the areas where the CIE RGB system would have to be negative?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_RGB_color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/CIE_1931_color_space#CIE_RGB_color_space&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/qwqdc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qwqdc.png&quot; alt=&quot;Comparison of the two gamuts&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13805" LastEditorUserId="13805" LastEditDate="2020-08-17T12:59:42.647" LastActivityDate="2020-08-28T23:36:48.080" Title="Why is there a difference between the CIE XYZ colour gamut vs CIE RGB?" Tags="&lt;color&gt;&lt;color-science&gt;&lt;colorspace&gt;" AnswerCount="3" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10116" PostTypeId="2" ParentId="10112" CreationDate="2020-08-16T09:02:24.307" Score="1" Body="&lt;p&gt;&lt;strong&gt;Keep in mind, that I'm still learning and I have no professional capacity in terms of graphics programming. So you might want to continue research with provided resources.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;t*#*: A register for a texture buffer (&lt;strong&gt;tbuffer&lt;/strong&gt;).[1]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;To start with - texture buffer is what you can see in hlsl code as: &lt;em&gt;Texture2D texName : register(t0)&lt;/em&gt; or as &lt;em&gt;Texture2D texName : register(t0, space0)&lt;/em&gt;. If I remember correctly, spaces were added in DirectX 12, maybe they're available in DX 11.3, but that's different discussion. Back to my point - you're using texture buffer every time you're binding texture to your shader and sending texture data to GPU. Therefore, using &lt;strong&gt;PSSetShaderResources&lt;/strong&gt; [2] will be most trivial usage of texture buffer, espacially in DX11 code. You can use constant buffer to store pixel data and then send it to GPU, but why should you bother, when Texture2D or TextureCube and other data structures are already in hlsl?&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;cbuffer (DX11/DX12) forces you to pack data in 32-bit groups&lt;/strong&gt; [3]. You might have experienced it, if not, I encourage you to experiment a little. In the past I didn't follow this rules, having that packed like this, which causes problem with incorrect data in your shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cbuffer buf : register(b0)&#xA;{&#xA;    float3 a;&#xA;    // Here is where problem occurs&#xA;    float2 b;&#xA;    float3 c;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Correct packing rule would be:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cbuffer buf : register(b0)&#xA;{&#xA;    float3 a;&#xA;    float padding_a;&#xA;    float2 b;&#xA;    float2 padding_b;&#xA;    float3 c;&#xA;    float padding_c;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Of course, I am using worst possible example here, because correct data is 8 bytes and you're sending additional 4 bytes (whole hlsl vector) as padding. But you get an idea. It might be easier to sort data with bigger buffers, especially if you're using uber buffer in your hobby project.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Additional problem in DX12 is that cbuffer has to be 256-byte aligned&lt;/strong&gt; [4], unless you're using root constants, which allows you to send not aligned data, but they have other limitation. I was only talking about them with other developer, so I don't really have sources except [5]. There was something about size of buffer and that root constants are working magic in AMD drivers, but it isn't something that I really need right now, as I am focusing on learning, not extreme optimization of code.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Shader Model 5 allows you to use new data structures [6]. I wasn't working with compute shaders, but for DXR hlsl code, I am using RTTexture2D as UAV. However, I am passing indices, vertices and RaytracingAccelerationStructure as texture buffers. I didn't see anyone to use those three as cbuffer. I guess it's possible, at least for indices and vertices, but I don't see a reason to do so:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;RaytracingAccelerationStructure SceneBVH : register(t0);&#xA;ByteAddressBuffer indices : register(t1);&#xA;StructuredBuffer&amp;lt;Vertex&amp;gt; vertices : register(t2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Indices are simply 16 or 32 bit index for accessing vertex data. I don't see a reason to hassle with creating cbuffer for single array and having to deal with padding and providing correct size of buffer. However, I am really interested if there is a reason to do it sometimes.&lt;/p&gt;&#xA;&lt;p&gt;Same with vertices - in rasterization, you're using structure which don't have to follow packing rules e.g.:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct VertexInputType&#xA;{&#xA;    float3 position : POSITION;&#xA;    float3 normal : NORMAL;&#xA;    float3 tangent : TANGENT;&#xA;    float3 binormal : BINORMAL;&#xA;    float2 uv : TEXCOORD0;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So for raytracing, I am just using struct with same data and I'm accesing it through structured buffer, regsitered as texture buffer:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex&#xA;{&#xA;    float3 position;&#xA;    float3 normal;&#xA;    float3 tangent;&#xA;    float3 binormal;&#xA;    float2 uv;&#xA;};&#xA;StructuredBuffer&amp;lt;Vertex&amp;gt; vertices : register(t2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Regarding &lt;em&gt;RaytracingAccelerationStructure&lt;/em&gt; - it's built-in hlsl type, no need to hassle with creating cbuffer.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;I'm sorry for speaking from DX12, DXR perspective, but that's something that I'm currently working on, so it's a simplest way to provide examples from that area.&lt;/p&gt;&#xA;&lt;p&gt;[1] &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3dgetstarted/work-with-shaders-and-shader-resources#read-from-the-constant-buffers&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/win32/direct3dgetstarted/work-with-shaders-and-shader-resources#read-from-the-constant-buffers&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;[2] &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-pssetshaderresources&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/win32/api/d3d11/nf-d3d11-id3d11devicecontext-pssetshaderresources&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;[3] &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-packing-rules&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;[4] &lt;a href=&quot;https://social.msdn.microsoft.com/Forums/sqlserver/en-US/78dec419-6827-40fc-a048-01c3cccb92ef/directx-10-11-and-12-constant-buffer-alignment?forum=vsga&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://social.msdn.microsoft.com/Forums/sqlserver/en-US/78dec419-6827-40fc-a048-01c3cccb92ef/directx-10-11-and-12-constant-buffer-alignment?forum=vsga&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;[5] &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3d12/using-constants-directly-in-the-root-signature&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/win32/direct3d12/using-constants-directly-in-the-root-signature&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;[6] &lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-cs-resources&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-cs-resources&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-16T09:02:24.307" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10117" PostTypeId="2" ParentId="10084" CreationDate="2020-08-16T09:46:09.413" Score="1" Body="&lt;p&gt;I am not aware of what LRV is and what is a usage of it. However, I can recommend using luma instead of simply averaging RGB values with equal weight:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Luma_(video)&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Luma_(video)&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Relative_luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Relative_luminance&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Example of using luma - &lt;a href=&quot;http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://blog.simonrodriguez.fr/articles/30-07-2016_implementing_fxaa.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Human eyes are more sensitive to green colors [1], that's why 16 bit (aka high color [2]) palettes, might prefer to use R5G6B5 format.&lt;/p&gt;&#xA;&lt;p&gt;[1] &lt;a href=&quot;https://en.wikipedia.org/wiki/Color_vision&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Color_vision&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;[2] &lt;a href=&quot;https://en.wikipedia.org/wiki/High_color&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/High_color&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-16T09:46:09.413" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10118" PostTypeId="1" CreationDate="2020-08-16T09:57:33.377" Score="4" ViewCount="103" Body="&lt;p&gt;When we clip in homogeneous clip space, we have to generate a new vertex located at the intersection between the edge and the clip plane. We thus have to interpolate the &lt;span class=&quot;math-container&quot;&gt;$(x , y, z , w)$&lt;/span&gt; position of both vertices to generate the new vertex position. It seems all well and good, but what should I do when the generated vertex after interpolation has a w of 0?&lt;/p&gt;&#xA;&lt;p&gt;It doesn’t work because the w-divide makes the point go to infinity (division by zero).&lt;/p&gt;&#xA;&lt;p&gt;So should I ensure that I never generate vertices with a w of 0 (how?)? Or should I just deal with the null w (how?)?&lt;/p&gt;&#xA;&lt;p&gt;You might say that this situation never happen, but it actually does happen, especially when the z of the vertices are set to their w, for skyboxes for example. In this case, when we clip against the near plane (z = 0 in clip space) and interpolate the position, we will end up with a z of 0 but also a w of 0...&lt;/p&gt;&#xA;" OwnerUserId="10928" LastEditorUserId="10928" LastEditDate="2020-08-16T10:06:23.110" LastActivityDate="2020-09-29T01:00:20.047" Title="How to interpolate vertices when clipping?" Tags="&lt;interpolation&gt;&lt;rasterizer&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10119" PostTypeId="1" CreationDate="2020-08-16T17:17:05.190" Score="1" ViewCount="84" Body="&lt;p&gt;I'm using 2d signed distance fields in my current project for drawing shapes (example: &lt;a href=&quot;https://www.shadertoy.com/view/4llXD7&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/4llXD7&lt;/a&gt;) and I want to add drop shadows to them. At first I thought I could exploit the sdfs distance property to achieve good enough looking drop shadows, but I found that in many cases this left undesirable results in the interior of the shapes where there is often a darker 'x' in center.&lt;/p&gt;&#xA;&lt;p&gt;I found this shadertoy &lt;a href=&quot;https://www.shadertoy.com/view/tdSGDc&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/tdSGDc&lt;/a&gt; which is produces exactly what I am looking for in terms of quality and performance, but I can't seem to figure out how I would combine this 1d box blur effect with arbitrary sdf shapes to achieve a nice looking drop shadow. Is there a way I can combine these two techniques to get great looking shadows?&lt;/p&gt;&#xA;" OwnerUserId="13842" LastActivityDate="2020-08-16T17:17:05.190" Title="Combine box shadow with a signed distance field" Tags="&lt;glsl&gt;&lt;2d&gt;&lt;unity&gt;&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10120" PostTypeId="2" ParentId="10103" CreationDate="2020-08-17T19:49:32.320" Score="0" Body="&lt;p&gt;I think all you have to do is to transform the back layers in the Y axis.&#xA;FYI, a shear means to bend an object, see image bellow:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3LRVj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3LRVj.png&quot; alt=&quot;sheer&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13639" LastActivityDate="2020-08-17T19:49:32.320" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10121" PostTypeId="1" AcceptedAnswerId="10124" CreationDate="2020-08-17T22:38:29.650" Score="1" ViewCount="72" Body="&lt;p&gt;The heat method is a very interesting paper for distance computation:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.cs.cmu.edu/%7Ekmcrane/Projects/HeatMethod/paperCACM.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.cs.cmu.edu/~kmcrane/Projects/HeatMethod/paperCACM.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The idea behind the paper is that, heat travels along the surface of an object essentially in a geodesic like fashion. And so the time it takes for heat to travel from a hot spot to any point on a surface is irreconcilably correlated with the geodesic distance.&lt;/p&gt;&#xA;&lt;p&gt;The paper first considers the general, analytic case and then suggests discretization approaches. What I am very confused about is the mention of the heat flow function &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; across the paper. Consider this equation for example:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/e5uCy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e5uCy.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;That is the discrete laplacian operator applied to &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$\Delta u$&lt;/span&gt;. There are multiple other sections in the paper that mention &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;. From my reading, &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; seems to be a suitable function that approximates heat flow on the surface of a manifold?&lt;/p&gt;&#xA;&lt;p&gt;I don't really see an equation of the form &lt;span class=&quot;math-container&quot;&gt;$u = \text{expression}$&lt;/span&gt; nor do I see descriptions of its properties nor suggestions for a good &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; function. What is &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;? Where did &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; come from? Where did &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; go? Where did &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; come from? cotan, i, o?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-08-31T10:28:54.210" Title="Heat Method (Crane et Al) How do we pick u?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="2" CommentCount="1" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10122" PostTypeId="2" ParentId="10114" CreationDate="2020-08-18T03:36:55.743" Score="0" Body="&lt;p&gt;There is no such thing as negative light or light color. Having a model with negative values could give people funny ideas. So light behaves strictly like positive natural numbers.&lt;/p&gt;&#xA;&lt;p&gt;Offcourse as far as coordinates go they can have negative values. But this would rise the question that your having: Howcome you can have values outside the span. Well, its not a gamut plot like you are used to seeing is just the coordinate system used. It does not tell anything of the device like a plot of say sRGB. So might be a bit misleading to draw it the same way.&lt;/p&gt;&#xA;&lt;p&gt;Yes the values of a barycentric coordinate system outside a triangle neccessitates negative values.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2020-08-18T03:36:55.743" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10123" PostTypeId="2" ParentId="10121" CreationDate="2020-08-18T06:59:42.547" Score="1" Body="&lt;p&gt;Yes, the field &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; is in this case an approximated heat diffusion across the surface. It's found by starting with the &amp;quot;initial set&amp;quot; of vertices; these will be the source of the diffusion, and end up as local minima in the distance field. An initial distribution &lt;span class=&quot;math-container&quot;&gt;$u_0$&lt;/span&gt; is set up, with value 1 on the initial set and 0 everywhere else. (This is described on page 92 of the paper you linked, immediately under Algorithm 1.)&lt;/p&gt;&#xA;&lt;p&gt;The first step of the algorithm is to run a single step of the heat equation by solving the linear equation &lt;span class=&quot;math-container&quot;&gt;$(I - t\nabla)u = u_0$&lt;/span&gt; (equation 3 in the paper). The field &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; you get there is the approximated heat diffusion that you further process to get the distance field.&lt;/p&gt;&#xA;" OwnerUserId="7647" LastActivityDate="2020-08-18T06:59:42.547" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10124" PostTypeId="2" ParentId="10121" CreationDate="2020-08-18T07:42:29.940" Score="2" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;From my reading, u seems to be a suitable function that approximates heat flow on the surface of a manifold?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; is the function that describes how your quantity behaves/evolves in a certain field. In the paper, the quantity is the temperature or heat flux, I guess. However, most of the time there is no analytical solution/formula for &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;. This is where methods like Finite Elements (FEM) come into play. By discretizing your field, you can piecewise approximate your function &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In your case, you would use your mesh, which is already a discretization of your surface. Your elements are the triangles and you need to define how the nodal quantities are interpolated inside each triangle. --- Here, linear interpolation is probably the way to go. Otherwise, you need to remesh your geometry or introduce additional nodes for higher-order approximations.&lt;/p&gt;&#xA;&lt;p&gt;Then you have to assign to each Node/Vertex an initial value &lt;span class=&quot;math-container&quot;&gt;$u_0$&lt;/span&gt; as written in the answer of gilgamec. Afterwards, you build and solve your finite element system and get the nodal distribution of &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; that actually solves your equation or system of equations. The finer your mesh gets, the better the solution. Higher-order interpolations will also help with accuracy.&lt;/p&gt;&#xA;&lt;p&gt;So &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; or its nodal values are what you are actually looking for as lightxbulb said in his comment. It's your unknown quantity.&lt;/p&gt;&#xA;&lt;p&gt;If this doesn't help, you might want to read some literature about the finite element method. Can't tell how helpful the following links are, but a short glimpse looked promising. You will see, that they use &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; all over the place. So I hope one of them will help you:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://arturo.imati.cnr.it/%7Emarini/didattica/Metodi-engl/Intro2FEM.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;A gentle introduction to the Finite Element Method&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://web.stanford.edu/class/energy281/FiniteElementMethod.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;PE281 Finite Element Method Course Notes&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://homepages.cae.wisc.edu/%7Esuresh/ME964Website/M964Notes/Notes/introfem.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Introduction to the finite element method&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://enterfea.com/finite-element-analysis-by-hand/&quot; rel=&quot;nofollow noreferrer&quot;&gt;finite element analysis by hand&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I also had a link to a good online tutorial similar to the last link I provided that helped me a lot in understanding the fundamentals. If I find the link, I ll add it to my answer.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Found the link I was referring to. Unfortunately, it is in german:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.cae-wiki.info/wikiplus/index.php/FEM_Handrechnung_1_1&quot; rel=&quot;nofollow noreferrer&quot;&gt;FEM Handrechnung&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-08-31T10:28:54.210" LastActivityDate="2020-08-31T10:28:54.210" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10125" PostTypeId="1" CreationDate="2020-08-18T07:50:58.803" Score="2" ViewCount="54" Body="&lt;p&gt;I am programming a microcontroller - a tiny 8 bit computer that has about 100Mhz - 300Mhz CPU clock speed and 64K application RAM (actually ROM), but only a tiny amount of RAM (6K) - nowhere near enough for a graphics frame buffer.&lt;/p&gt;&#xA;&lt;p&gt;So, I want to display an animated graphics demo on this machine.  It seems to have enough computing power to calculate animated graphics of some sort.&lt;/p&gt;&#xA;&lt;p&gt;To get animated graphics to display, I will somehow need to have a computer program that each time it is called, returns a single line of pixels of one image frame, which is then displayed.  The display controller program continues to do this, calling line after line until it has displayed a whole frame, then it starts at the top again for the next frame.&lt;/p&gt;&#xA;&lt;p&gt;Just to be clear, I'm not asking about the program that controls the display.  I'm asking about the demo program.  I need a demo program that yields its graphics one line at a time, which my display controller will then throw onto the screen.&lt;/p&gt;&#xA;&lt;p&gt;I'm trying to imagine what sort of graphics program could work this way?  Presumably the display of some sort of mathematical formula.&lt;/p&gt;&#xA;&lt;p&gt;Can anyone suggest techniques for graphics programming that work in this way, in which a function can be called, which calculates and returns a line of the frame, only when requested to do so?  Are there existing programs that work like this that I could examine?&lt;/p&gt;&#xA;&lt;p&gt;I hope the question makes sense.  Any pointers in the right direction or hints would be appreciated.&lt;/p&gt;&#xA;" OwnerUserId="13847" LastActivityDate="2020-08-18T15:55:06.000" Title="How can I make a graphics demo without a frame buffer?" Tags="&lt;rendering&gt;&lt;real-time&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10126" PostTypeId="1" CreationDate="2020-08-18T15:00:18.803" Score="0" ViewCount="164" Body="&lt;p&gt;Edit: I managed to get code compiling, but it doesn't work, so I changed question a little bit.&lt;/p&gt;&#xA;&lt;p&gt;Below code is working fine as read buffer, but I cannot make it to work as read-write buffer (RWStructuredBuffer). I am using RWStructubeBuffer : (u0) in my hlsl code and I can read data correctly in hlsl and I can write data correctly on CPU in C++ code. But I cannot get data back from GPU or at least I don't know how to acces that:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;UINT64 size = buffersWithSize[i].second;&#xA;UINT64 bufferSize = size;&#xA;auto uavDesc = CD3DX12_RESOURCE_DESC::Buffer(bufferSize, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);&#xA;auto defaultHeapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT);&#xA;&#xA;ThrowIfFailed(device-&amp;gt;CreateCommittedResource(&#xA;    &amp;amp;defaultHeapProperties, D3D12_HEAP_FLAG_NONE, &amp;amp;uavDesc, D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, IID_PPV_ARGS(&amp;amp;buffersWithSize[i].first)&#xA;));&#xA;&#xA;D3D12_UNORDERED_ACCESS_VIEW_DESC uavViewDesc = {};&#xA;uavViewDesc.Buffer.NumElements = 1;&#xA;uavViewDesc.Buffer.FirstElement = 0;&#xA;uavViewDesc.Buffer.StructureByteStride = size;&#xA;uavViewDesc.Buffer.CounterOffsetInBytes = 0;&#xA;uavViewDesc.Format = DXGI_FORMAT_UNKNOWN;&#xA;uavViewDesc.ViewDimension = D3D12_UAV_DIMENSION_BUFFER;&#xA;&#xA;device-&amp;gt;CreateUnorderedAccessView(buffersWithSize[i].first.Get(), nullptr, &amp;amp;uavViewDesc, handle);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-08-19T08:53:24.610" LastActivityDate="2020-08-19T08:53:24.610" Title="How to use RWStructuredBuffer" Tags="&lt;c++&gt;&lt;directx12&gt;&lt;buffers&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10127" PostTypeId="2" ParentId="10125" CreationDate="2020-08-18T15:55:06.000" Score="4" Body="&lt;p&gt;This is a case where looking at the &lt;a href=&quot;https://retrocomputing.stackexchange.com/&quot;&gt;workings of more retro hardware&lt;/a&gt; would be reasonable. Older hardware had strong limitations in both memory and processing power. Your 100+Mhz chip is far faster than most consumer-grade chips of the 80s and before. So while those CPUs needed dedicated graphics chips to be able to render, your much faster CPU can probably handle the task adequately.&lt;/p&gt;&#xA;&lt;p&gt;I would suggest starting with something like the NES's tilemap-and-sprite architecture. These architectures are designed to be both memory efficient (getting a lot out of limited storage space) and computationally efficient in a line-by-line output, as they generated pixel data and sent it directly to the display device at the expected speed of a CRT.&lt;/p&gt;&#xA;&lt;p&gt;The broad idea is this. A tilemap consists of two parts: a series of tiles and a 2D array of indices into the tile map that represents the image being created. The tiles are typically 8x8, and on the NES were 2-bits-per-pixel and the tiles used palettes. Or more specifically, the index into the tile map includes not just the index of a tile but also the index of the palette to use with that tile. So a tile is not inherently associated with a palette; the association is made at the point of use (technically, on the NES, the tile map and palette map were separate, as each 2x2 block of tiles all had to use the same palette).&lt;/p&gt;&#xA;&lt;p&gt;To allow for scrolling, the tile map is bigger than the visible screen, and there is an offset that represents where the top-left corner of the visible screen is within the tilemap. Let this offset be at position &lt;code&gt;Xoff&lt;/code&gt; and &lt;code&gt;Yoff&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;You can see how this makes row-by-row processing trivial. To generate a horizontal row for the horizontal position &lt;code&gt;Ypos&lt;/code&gt; (in screen-space), you need to get the starting pixel within the tilemap. That requires transforming the XY position &lt;code&gt;(0, Ypos)&lt;/code&gt; from screen-space to tilemap space. So you add to it the vector &lt;code&gt;(Xoff, Yoff)&lt;/code&gt;, hielding the vector ``Xoff, Yoff + Ypos)`.&lt;/p&gt;&#xA;&lt;p&gt;Note that when doing any mapping from screen-space to tilemap space, that the tilemap space should wrap around in both the X and Y axes. So whenever you compute a new pixel in tilemap space, you have to wrap it around the size of the tilemap space.&lt;/p&gt;&#xA;&lt;p&gt;Now, we need to break down this tilemap pixel into two 2D components: the tile index within the tilemap that gives us this this pixel, and the pixel within that tile that we need to fetch for this pixel. The tile index is just the tilemap-space pixel integer-divided by the tile size. The pixel coordinate is the tilemap-space pixel integer-&lt;em&gt;modded&lt;/em&gt; by the tile size. Given an 8x8 tile size, you're doing this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;ivec2 tilemap_pixel = ...; //Compute the tilemap starting pixel as above.&#xA;ivec2 tilemap_tile = ivec2(tilemap_pixel.x &amp;amp; ~0x7, tilemap_pixel.y &amp;amp; ~0x7); //Mask off the lower 3 bits.&#xA;ivec2 pixel_in_tile = ivec2(tilemap_pixel.x &amp;amp; 0x7, tilemap_pixel.y &amp;amp; 0x7); //Mask off all but the lower 3 bits.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So given &lt;code&gt;tilemap_tile&lt;/code&gt;, we now have the index of the tile we are currently working within. And &lt;code&gt;pixel_in_tile&lt;/code&gt; gives us the pixel we're working in. So we can fetch that pixel, whose value can be mapped into a palette to produce the final color for that pixel. Or we can use it directly.&lt;/p&gt;&#xA;&lt;p&gt;To get the next pixel is pretty trivial. We just increment &lt;code&gt;pixel_in_tile.x&lt;/code&gt; by 1, modulo the tile size. If the increment exceeded the tile size, then we also increment &lt;code&gt;tilemap_tile.x&lt;/code&gt; by 1, modulo the tilemap size. And you keep going until you've filled out the row of pixels.&lt;/p&gt;&#xA;&lt;p&gt;There are many opportunities for performance optimization of such an algorithm.&lt;/p&gt;&#xA;&lt;p&gt;The tiles probably represent the largest data. A 128 element tile set of 8x8 tiles, even at 2bpp, is 2K. But the thing is, those can be stored in &lt;em&gt;ROM&lt;/em&gt;, since you're probably not changing the tiles themselves. The size of the tile map (assuming it must be in RAM) depends on the desired output resolution and the tile size. A tile map for 8x8 tiles that can cover a 320x240 screen is 1,200 bytes. Not exactly tiny. You'll need to take up more memory if you want room for smooth scrolling (and thus a larger tile map).&lt;/p&gt;&#xA;&lt;p&gt;That being said, it's also important to note that the &amp;quot;output size&amp;quot; doesn't have to be the actual size of the &lt;em&gt;display device&lt;/em&gt;. For example, if you intend to draw to a 1080p display device, you could still render to an internal resolution that's, for example, 8 times smaller, 240x135. It's easy to modify this algorithm to essentially generate the same pixel value 8 times in a row, as well as reusing the same line 8 times per 1080p line. Indeed, it wouldn't be too difficult to have this algorithm allow for subpixel scrolling (scrolling in 1080p space, not 135p space) and even adding some filtering between pixel values. A 240x135 &amp;quot;output size&amp;quot; tilemap would only require 510 bytes for the visible region, so you would have more room for a larger scrolling area.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-08-18T15:55:06.000" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10128" PostTypeId="1" CreationDate="2020-08-18T16:02:20.387" Score="0" ViewCount="22" Body="&lt;p&gt;The &amp;quot;feather&amp;quot; in photo &amp;amp; video editing softwares like photoshop &amp;amp; Premiere Pro, I need to know whether it is simply a Gaussian blur around the edges of boundary or it is something else? How do we really implement it in OpenGL/OpenGLES?&lt;/p&gt;&#xA;" OwnerUserId="8758" LastActivityDate="2020-08-18T16:02:20.387" Title="Implementing Feather feature of Photoshop" Tags="&lt;opengl&gt;&lt;image-processing&gt;&lt;gaussian-blur&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10129" PostTypeId="1" CreationDate="2020-08-18T18:05:59.613" Score="0" ViewCount="63" Body="&lt;p&gt;As I understand Euclideon haven't just rendered voxels for these infamous demos, since the amount of geometry is still too large for the 2010 PC with software raytracer and the model taking whole HDD and streaming non-stop, even with the prebaked lights. They instead did subreferencing inside their BVH to point to either dynamic generator or the instances of the pregenerated microgeometry (similar to reusing the same texture with polygonal graphics). So Euclideon could have even the dust particles on the ground. That is apparently very old trick. I remember it being used to prerender the backgrounds in Ecstatica (an old DOS video game). Am I correct? Then why have Euclideon generated so much hatred and controversy back then? The tech looks solid and was used previously for offline rendering. Euclideon people just brought it into realtime on consumer PCs.&lt;/p&gt;&#xA;" OwnerUserId="13814" LastActivityDate="2020-08-18T18:05:59.613" Title="Euclideon Unlimited Details Voxel Engine Architecture" Tags="&lt;raytracing&gt;&lt;volumetric&gt;&lt;voxelization&gt;&lt;bounding-volume-hierarchy&gt;&lt;volume-rendering&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10131" PostTypeId="1" CreationDate="2020-08-19T07:55:58.697" Score="0" ViewCount="28" Body="&lt;p&gt;I received a pdf from a client containing several invoices. Upon further inspecting, some lines on the invoice seem digitally produced. When I tried selecting the page, copying it then pasting it on paint, the lines that seemed suspicious disappeared.&lt;/p&gt;&#xA;&lt;p&gt;I should note that the source invoice paper are very thin. So before jumping to any conclusions, is it common that some printers or printing software compensate for blurry or lost lines and text and try to “enhance them”?&lt;/p&gt;&#xA;" OwnerUserId="13853" LastActivityDate="2020-08-19T07:55:58.697" Title="Do scanners and scanning software compensate and enhance blurry sources?" Tags="&lt;image-processing&gt;&lt;pdf&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="10132" PostTypeId="1" AcceptedAnswerId="10134" CreationDate="2020-08-19T08:53:36.580" Score="2" ViewCount="352" Body="&lt;p&gt;I'm re-writing an algorithm that I first wrote using matrix/vector operation into OpenGL kernels in order to try to maximiz the performances.&lt;/p&gt;&#xA;&lt;p&gt;I have a basic knowledge of OpenGL, so I was able to get the things working, but I have a lot of trouble when it come to make various choices offered by OpenGL, especially the buffer's parameters that I guess have a huge impact in my case where I read and write a lot of data.&lt;/p&gt;&#xA;&lt;p&gt;I call the three kernels sequencially :&lt;/p&gt;&#xA;&#xA;&lt;p&gt;&lt;strong&gt;First :&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;/* Generated constants (for all three shaders): &#xA; *   #version 430&#xA; *   const vec3 orig&#xA; *   const float vx&#xA; *   const ivec2 size&#xA; *   const uint projections&#xA; *   const uint subIterations&#xA; */&#xA;layout(local_size_x = 1, local_size_y = 1) in;&#xA;&#xA;layout(std430, binding = 0) buffer bufferA { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    uint bufferProjection[]; //Written and read (AtomicAdd) by this shader, read by the second kernel&#xA;};&#xA;layout(std430, binding = 1) readonly buffer bufferB { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    uint layer[]; //Written and read by the third kernel, read by this shader and by glGetNamedBufferSubData&#xA;};&#xA;layout(std140) uniform bufferMat { //GL_UNIFORM_BUFFER, GL_STATIC_DRAW&#xA;    mat4 proj_mat[projections*subIterations]; //Read only by this shader and the third&#xA;};&#xA;layout(location = 0) uniform int z;&#xA;layout(location = 1) uniform int subit;&#xA;&#xA;void main() {&#xA;    vec4 layer_coords = vec4(orig,1.0) + vec4(gl_GlobalInvocationID.x, z, gl_GlobalInvocationID.y, 0.0)*vx;&#xA;    uint val = layer[gl_GlobalInvocationID.y*size.x + gl_GlobalInvocationID.x];&#xA;    for(int i = 0; i &amp;lt; projections; ++i) {&#xA;        vec4 proj_coords = proj_mat[subit+i*subIterations]*layer_coords;&#xA;        ivec2 tex_coords = ivec2(floor((proj_coords.xy*size)/(2.0*proj_coords.w)) + size/2);&#xA;        bool valid = all(greaterThanEqual(tex_coords, ivec2(0,0))) &amp;amp;&amp;amp; all(lessThan(tex_coords, size));&#xA;        atomicAdd(bufferProjection[tex_coords.y*size.x+tex_coords.x+i*(size.x*size.y)], valid?val:0);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Second:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout(local_size_x = 1, local_size_y = 1) in;&#xA;&#xA;layout(std430, binding = 0) buffer bufferA { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    float updateProjection[]; //Written by this shader, read by the third kernel&#xA;};&#xA;layout(std430, binding = 1) readonly buffer bufferB { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    uint bufferProjection[]; //Written by the first, read by this shader&#xA;};&#xA;layout(std430, binding = 2) readonly buffer bufferC { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    uint originalProjection[]; //Only modified by glBufferSubData, read by this shader&#xA;};&#xA;&#xA;void main() {&#xA;    for(int i = 0; i &amp;lt; projections; ++i) {&#xA;        updateProjection[gl_GlobalInvocationID.x+i*(size.x*size.y)] = float(originalProjection[gl_GlobalInvocationID.x+i*(size.x*size.y)])/float(bufferProjection[gl_GlobalInvocationID.x+i*(size.x*size.y)]);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Third:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout(local_size_x = 1, local_size_y = 1) in;&#xA;&#xA;layout(std430, binding = 0) readonly buffer bufferA { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    float updateProjection[]; //Written by the second kernel, read by this shader&#xA;};&#xA;layout(std430, binding = 1) buffer bufferB { //GL_SHADER_STORAGE_BUFFER, GL_DYNAMIC_READ&#xA;    uint layer[]; //Written and read by this shader, read by the first kernel and by glGetNamedBufferSubData&#xA;};&#xA;layout(std140) uniform bufferMat { //GL_UNIFORM_BUFFER, GL_STATIC_DRAW&#xA;    mat4 proj_mat[projections*subIterations]; //Read only by this shader and and the first&#xA;};&#xA;layout(location = 0) uniform int z;&#xA;layout(location = 1) uniform int subit;&#xA;layout(location = 2) uniform float weight;&#xA;&#xA;void main() {&#xA;    vec4 layer_coords = vec4(orig,1.0) + vec4(gl_GlobalInvocationID.x, z, gl_GlobalInvocationID.y, 0.0)*vx;&#xA;    float acc = 0;&#xA;    for(int i = 0; i &amp;lt; projections; ++i) {&#xA;        vec4 proj_coords = proj_mat[subit+i*subIterations]*layer_coords;&#xA;        ivec2 tex_coords = ivec2(floor((proj_coords.xy*size)/(2.0*proj_coords.w)) + size/2);&#xA;        bool valid = all(greaterThanEqual(tex_coords, ivec2(0,0))) &amp;amp;&amp;amp; all(lessThan(tex_coords, size));&#xA;        acc += valid?updateProjection[tex_coords.y*size.x+tex_coords.x+i*(size.x*size.y)]:0;&#xA;    }&#xA;    float val = pow(float(layer[gl_GlobalInvocationID.y*size.x + gl_GlobalInvocationID.x])*(acc/projections), weight);&#xA;    layer[gl_GlobalInvocationID.y*size.x + gl_GlobalInvocationID.x] = uint(val);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What I came up by reading the OpenGL doc :&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Some value that are the same for all the duration of the algorithm are generated as const before compiling the shader. Especially usefull for the for-loop boundary&lt;/li&gt;&#xA;&lt;li&gt;bufferMat, which is very small compared to the other buffers, is put in an UBO, which should have better performance than SSBO. Do I could get event better perf by making it a compile-time constant ? It's small, but still a few hundreds mat4&lt;/li&gt;&#xA;&lt;li&gt;The others buffer, being both read and written several times, should be better as SSBO&lt;/li&gt;&#xA;&lt;li&gt;I have trouble understanding what could be the best value for the 'usage' parameters of the buffer. All buffers being written to  and read several time, I'm not sure what to put here.&lt;/li&gt;&#xA;&lt;li&gt;If I understand correctly, the local_size is only usefull when sharing data between invocations, so I should keep it at one ?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I would gladly take any recommendations or hints about where to look to optimize thoses kernels !&lt;/p&gt;&#xA;" OwnerUserId="13850" LastActivityDate="2020-08-19T14:51:27.897" Title="Using buffers correctly in OpenGL compute shaders" Tags="&lt;opengl&gt;&lt;compute-shader&gt;&lt;optimisation&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10133" PostTypeId="2" ParentId="10108" CreationDate="2020-08-19T13:01:41.497" Score="0" Body="&lt;p&gt;I decided to use R16B16G16A16_FLOAT format instead to avoid problems as I'm working on hobby/academic code and it isn't fully fledged game/graphics engine.&lt;/p&gt;&#xA;&lt;p&gt;I solves my problem. FYI, I've also tried using R8B8G8A8_SNORM instead of *_UNORM, but I failed to get correct results with that. Maybe it was due to other factors, so I don't fully blame format.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-19T13:01:41.497" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10134" PostTypeId="2" ParentId="10132" CreationDate="2020-08-19T14:51:27.897" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Do I could get event better perf by making it a compile-time constant ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;You'll have to profile it. That being said, &amp;quot;a few hundreds mat4&amp;quot; is &lt;em&gt;not &amp;quot;small&amp;quot;&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I have trouble understanding what could be the best value for the 'usage' parameters of the buffer. All buffers being written to and read several time, I'm not sure what to put here.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;First, the usage parameters are about &lt;em&gt;your&lt;/em&gt; usage of the buffer object, not OpenGL's usage of the memory behind them. That is, they're talking about functions like &lt;code&gt;glBufferSubData&lt;/code&gt;, &lt;code&gt;glMapBufferRange&lt;/code&gt;, and so forth. &lt;code&gt;READ&lt;/code&gt; means that the CPU will read from the buffer, but not write to it. &lt;code&gt;DRAW&lt;/code&gt; means that the CPU will write to the buffer, but not read from it.&lt;/p&gt;&#xA;&lt;p&gt;Second... you really shouldn't care. Usage hints are terrible, poorly specified, and have been so misused that many implementations flat-out &lt;em&gt;ignore&lt;/em&gt; them. NVIDIA's GL implementation is probably the one that takes them the most seriously.&lt;/p&gt;&#xA;&lt;p&gt;Instead, use &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object#Immutable_Storage&quot; rel=&quot;nofollow noreferrer&quot;&gt;immutable storage buffers&lt;/a&gt;. Those &amp;quot;usage hints&amp;quot; are not &lt;em&gt;hints&lt;/em&gt;; they're API requirements. If you don't use &lt;code&gt;GL_DYNAMIC_STORAGE_BIT&lt;/code&gt;, then you &lt;em&gt;cannot&lt;/em&gt; write to the buffer via &lt;code&gt;glBufferSubData&lt;/code&gt;. And so forth.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;If I understand correctly, the local_size is only usefull when sharing data between invocations, so I should keep it at one ?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;No. In fact, never use 1. If all of the invocations are doing their own thing, with no execution barriers or the like, then you should pick a local size that is equivalent to the wavefront size of the hardware you're working on. Obviously that's implementation dependent, but 32 is certainly a better default than 1.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-08-19T14:51:27.897" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10135" PostTypeId="1" AcceptedAnswerId="10136" CreationDate="2020-08-19T22:19:40.507" Score="0" ViewCount="59" Body="&lt;p&gt;I have a camera I have placed &lt;code&gt;z&lt;/code&gt;units away from a billboarded rect. My goal is to discard all other geometry that is closer to the camera/in front of this rect.&lt;/p&gt;&#xA;&lt;p&gt;With perspective projection I have always set the near plane to 0.1 and called it a day however here I tried to set it to &lt;code&gt;z&lt;/code&gt; thinking it would clip anything in front of this rect.&lt;/p&gt;&#xA;&lt;p&gt;No such luck. This ended up clipping that rect and seemingly even more. Z-1 also did not have the desired result.&lt;/p&gt;&#xA;&lt;p&gt;This leads me to think the near clipping plane might not be in the same coordinate space as the world? If not what space is it in?&lt;/p&gt;&#xA;" OwnerUserId="2308" LastActivityDate="2020-08-20T07:35:18.573" Title="Perspective projection near plane not in world coordinates" Tags="&lt;matrix&gt;&lt;perspective&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10136" PostTypeId="2" ParentId="10135" CreationDate="2020-08-20T07:35:18.573" Score="1" Body="&lt;p&gt;The perspective projection matrix transforms from camera space to clip space. The near-plane value is the position of the near plane in camera space. So in case that your world space to camera space transformation does not use any scaling, only rotations and translations, then if you place the camera &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; units away from the billboard surface and look directly onto it, a near plane value of &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; will cause the billboard plane to lie on the near plane. Due to rounding errors, it might get clipped away, so your idea of setting it to &lt;span class=&quot;math-container&quot;&gt;$z-offset$&lt;/span&gt; should solve the problem.&lt;/p&gt;&#xA;&lt;p&gt;Why it doesn't work is hard to tell without any code. Maybe your implementation of the perspective matrix is wrong. Maybe you have a hidden scaling when you transform between world and camera space. To debug this you can try to multiply &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; with values between 0 and 1 until you get the desired result. The resulting factor might be a clue. For example if you get &lt;span class=&quot;math-container&quot;&gt;$0.5$&lt;/span&gt; we know that there is either a 2 missing or too much in your transformation matrices. Also, make sure that your far plane value is larger than your near plane value (even though I think from your description that this isn't the problem - but who knows)&lt;/p&gt;&#xA;&lt;p&gt;In case you are using OpenGL, here is a &lt;a href=&quot;http://www.songho.ca/opengl/gl_projectionmatrix.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;link to how the perspective projection matrix has to look like&lt;/a&gt;. Maybe you have to transpose the matrix. That depends on your vector layout - column vectors or row vectors.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/a/9960/13095&quot;&gt;Here is a link to an answer of mine&lt;/a&gt; to another question. It has a Python script at the end that you can use to visualize how the different values affect the view frustum in the different spaces. Some pictures are also included in the answer. Maybe that is already enough to help you out.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-08-20T07:35:18.573" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10137" PostTypeId="1" AcceptedAnswerId="10250" CreationDate="2020-08-21T21:51:54.577" Score="1" ViewCount="87" Body="&lt;p&gt;I am trying to understand how to get the discrete gradient of a mesh that is being used as the input of some function &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;. In other words for every vertex &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt; there is a scalar quantity &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; associated with it.&lt;/p&gt;&#xA;&lt;p&gt;I am trying to understand how to compute the discrete gradient of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; on the surface. For that purpose I was checking these slides:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.hao-li.com/cs599-ss2015/slides/Lecture04.1.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.hao-li.com/cs599-ss2015/slides/Lecture04.1.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But it's not clicking. The piece wise notation I am assuming is just an attempt at formalizing &amp;quot;we have no idea what the values at the triangles would be, so we are just going to linearly interpolate using Barycentric coordinates&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;But then the slides reach this final formula for the gradient:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Mx9hP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Mx9hP.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I kinda understand the bottom part, which seems to say the gradient basis at &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; is a vector orthogonal to the opposite edge divided by 2 times the area of the triangle (I assume), but how was the top formula derived?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-22T18:26:25.573" Title="Discrete Gradient?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10138" PostTypeId="1" AcceptedAnswerId="10152" CreationDate="2020-08-21T22:14:53.263" Score="0" ViewCount="110" Body="&lt;p&gt;I have this image below, I want to get rid of the text 'MSAR IDs' that is in the background. I am extracting the numbers from the image with OCR, the numbers that have a white background get extracted as is, however the numbers that have the text behind them don't get extracted properly and are not correct because they all have some part of the background text behind them. Can anyone please tell me how to get rid of the big text in background, any software will do for me.&lt;/p&gt;&#xA;&lt;p&gt;(edit)PS- I got information that MSAR IDs are intellectual property of a company so to be clear I got this as part of a freelance work, my work is to put the numbers in an excel, so I was thinking of making my work a bit easier hence put up this post&lt;/p&gt;&#xA;" OwnerUserId="13861" LastEditorUserId="13861" LastEditDate="2020-08-26T20:51:37.680" LastActivityDate="2020-08-26T20:58:40.563" Title="How to remove background text from an image file" Tags="&lt;image-processing&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10139" PostTypeId="2" ParentId="10137" CreationDate="2020-08-22T07:42:44.697" Score="0" Body="&lt;p&gt;An area consists of 2 components, the normalized gradient of the basis_i gives the constant rate in the direction of one of the components which only depends on vertices.&lt;/p&gt;&#xA;&lt;p&gt;The highlighted formula is the intermediate state of transforming the function  fully utilizes vertices.&lt;/p&gt;&#xA;" OwnerUserId="13838" LastActivityDate="2020-08-22T07:42:44.697" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10140" PostTypeId="2" ParentId="10138" CreationDate="2020-08-22T08:06:03.360" Score="1" Body="&lt;p&gt;It is all about filtering, you can see there are 4 colors, i.e. C_Font, C_Paper, C_Watermark_Paper, and C_Watermark_Font, the filter is just f(C_Watermark_Paper) = C_Paper and f(C_Watermark_Font) = C_Font.&lt;/p&gt;&#xA;&lt;p&gt;Of course you can use GIMP and easily Google references, i.e. &lt;a href=&quot;http://howto.nicubunu.ro/gimp-remove-watermark/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://howto.nicubunu.ro/gimp-remove-watermark/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13838" LastEditorUserId="13838" LastEditDate="2020-08-22T11:01:49.820" LastActivityDate="2020-08-22T11:01:49.820" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10141" PostTypeId="6" CreationDate="2020-08-22T10:15:21.763" Score="0" Body="&lt;p&gt;Hello,&lt;/p&gt;&#xA;&lt;p&gt;my name is Volker and I am an engineer from Germany. In my professional career, I do a lot of programming that isn't directly related to computer graphics. However, after work, I follow my true passion and work on my own game/graphics engine. This interest of mine lead me to this site.&lt;/p&gt;&#xA;&lt;p&gt;I enjoy helping others to solve their problems and sharing my knowledge. This motivates me to visit this site regularly, currently multiple times a day. So I can help to resolve new flags quickly. I also have a regular look into all the review queues that are available to me and review as many items as I can.&lt;/p&gt;&#xA;&lt;p&gt;If I think that a post has some issues and cast a corresponding vote, I always leave a comment expressing what I think is wrong. I am aware that moderator votes are binding so I would delay my vote on disputable cases and leave a comment until enough other users agree with me. However, I would close obvious spam and questions totally unrelated to CG immediately.&lt;/p&gt;&#xA;&lt;p&gt;In case you don't agree with one of my actions on this site, I am always open to arguments and will reconsider my decisions.&lt;/p&gt;&#xA;&lt;p&gt;This post has a character limit. Ask me anything you need to know in the comments.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-08-22T10:15:21.763" LastActivityDate="2020-08-22T10:15:21.763" CommentCount="0" CommunityOwnedDate="2020-08-22T10:15:21.763" ContentLicense="CC BY-SA 4.0" />
  <row Id="10142" PostTypeId="2" ParentId="10138" CreationDate="2020-08-22T10:31:01.230" Score="0" Body="&lt;p&gt;There is a good chance that you could just blur the image a tiny tad so that the noisy structure in the watermark disappears (it basically becomes its own grey color). Then maybe your OCR software can read it? It might help converting it into a greyscale image first.&lt;/p&gt;&#xA;" OwnerUserId="9194" LastActivityDate="2020-08-22T10:31:01.230" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10144" PostTypeId="1" CreationDate="2020-08-23T05:28:21.847" Score="0" ViewCount="81" Body="&lt;p&gt;I'd like to try to write some C code to create similar animated graphics to these, which are from a very old Commodore 64 game called &amp;quot;The Sentinel&amp;quot;.  I've been researching but I can't seem to find if there is terminology that would lead me to information/algorithms on how to implement this sort of thing.  Does anyone know what terminology relates to this sort of super low poly/resolution terrain generation?&lt;/p&gt;&#xA;&lt;p&gt;thanks&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/E11OT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/E11OT.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/A3Dw9.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/A3Dw9.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/2xK65.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/2xK65.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/anhVJ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/anhVJ.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13847" LastActivityDate="2020-08-23T21:39:44.260" Title="Is there a term for this sort of graphics?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10145" PostTypeId="2" ParentId="10144" CreationDate="2020-08-23T21:39:44.260" Score="3" Body="&lt;p&gt;If the terrain is indeed represented by a 3D mesh as it looks like in the images, then I'm not aware of any specific terminology (and I dont believe there might be one).&lt;/p&gt;&#xA;&lt;p&gt;I could say it was similar to a faceted shading model, but shading looks very rudimentary and lighting computations might not exist at all.&lt;/p&gt;&#xA;&lt;p&gt;In case you intend to replicate these looks, I'm afraid you already hinted how to proceed very low-polygon non-textured meshes and no lighting.&lt;/p&gt;&#xA;" OwnerUserId="13869" LastActivityDate="2020-08-23T21:39:44.260" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10146" PostTypeId="1" AcceptedAnswerId="10168" CreationDate="2020-08-24T01:58:23.910" Score="1" ViewCount="90" Body="&lt;p&gt;I was trying to do importance sampling on lambertian surface.At first I uniformly choose direction from unit sphere.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 direction = camera-&amp;gt;genDirection();&#xA;...&#xA;direction = random_in_unit_sphere();&#xA;float cosine = dotp(direction,surfaceNormal);&#xA;/*&#xA;float dotp(float val){&#xA;val = dot(val);&#xA;if(val&amp;gt;0.0001f) return val;&#xA;else return 0.0001f;&#xA;}&#xA;*/&#xA;vec3 brdf_result = material-&amp;gt;baseColor/Pi;//lambertian&#xA;vec3 pdf = 1.0f/(2.0f*Pi);&#xA;throughput = throughput * brdf_result * cosine / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;With 10 samples per pixel,yields:&lt;a href=&quot;https://i.stack.imgur.com/PCAdE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PCAdE.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;then I choose random direction from the unit hemisphere above the surface&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;direction = random_in_unit_hemisphere(surfaceNormal);&#xA;float cosine = dotp(direction,surfaceNormal);&#xA;vec3 brdf_result = material-&amp;gt;baseColor/Pi;&#xA;vec3 pdf = 1.0f/(1.0f*Pi);&#xA;throughput = throughput * brdf_result * cosine / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;the result is very similar,except for less noise&#xA;&lt;a href=&quot;https://i.stack.imgur.com/OEcgs.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OEcgs.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;and then I use the importance sampling method from (&lt;a href=&quot;http://in1weekend.blogspot.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://in1weekend.blogspot.com/&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    class onb {&#xA;public:&#xA;    vec3 operator[](int i)const { return axis[i]; }&#xA;    vec3 u()const { return axis[0]; }&#xA;    vec3 v()const { return axis[1]; }&#xA;    vec3 w()const { return axis[2]; }&#xA;    vec3 local(float a, float b, float c) { return a * u() + b * v() + c * w(); }&#xA;    vec3 local(const vec3&amp;amp; a) { return a.x * u() + a.y * v() + a.z * w(); }&#xA;    void buildFromNormal(const vec3&amp;amp; n) {&#xA;        axis[2] = normalize(n);&#xA;        vec3 a;&#xA;        if (std::abs(w().x) &amp;gt; 0.9f)&#xA;            a = vec3(0.0f, 1.0f, 0.0f);&#xA;        else&#xA;            a = vec3(1.0f, 0.0f, 0.0f);&#xA;        axis[1] = normalize(cross(w(), a));&#xA;        axis[0] = cross(w(), v());&#xA;    }&#xA;&#xA;&#xA;private:&#xA;    vec3 axis[3];&#xA;};&#xA;vec3 randCosDir() {&#xA;    float r1 = randFloat01();&#xA;    float r2 = randFloat01();&#xA;    float z = sqrt(1.0f - r2);&#xA;    float phi = 2.0f * Pi * r1;&#xA;    float x = cos(phi) * 2.0f * sqrt(r2);&#xA;    float y = sin(phi) * 2.0f * sqrt(r2);&#xA;    return vec3(x, y, z);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;,&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;onb uvw;&#xA;uvw.buildFromNormal(surfaceNormal);&#xA;direction = normalize(uvw.local(randCosDir()));&#xA;float cosine = dotp(direction,surfaceNormal);&#xA;vec3 brdf_result = material-&amp;gt;baseColor/Pi;&#xA;vec3 pdf = dotp(uvw.w(), direction)/Pi;&#xA;throughput = throughput * brdf_result * cosine / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;however the result is different:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/klRtz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/klRtz.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The baseColor of the wall is vec3(0.8f,0.8f,0.8f),and the color of the dome light is vec3(1.0f,1.0f,1.0f).&#xA;In some tutorial the cosine item is inside the lambertian brdf,and some are in the render equation,and in&#xA;&lt;a href=&quot;http://in1weekend.blogspot.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://in1weekend.blogspot.com/&lt;/a&gt; &amp;quot;weekend one&amp;quot; there is no cosine item at all.I really get messed with those concepts.Is there any one help me?thanks so much.&lt;/p&gt;&#xA;&lt;p&gt;another rendering with baseColor = vec3(1.0f,1.0f,1.0f) and dome color = vec3(0.5f,0.5f,0.5f)  (importance sampling)&#xA;the average color of the final image over all pixels is vec3(0.470884f,0.470884f,0.470884f).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/hWiHg.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hWiHg.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;10,000 samples per pixel with uniform hemisphere sampling:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/CcPDQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CcPDQ.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13864" LastEditorUserId="13864" LastEditDate="2020-08-24T11:57:55.850" LastActivityDate="2020-08-30T00:35:09.183" Title="issue with importance sampling" Tags="&lt;pathtracing&gt;&lt;importance-sampling&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10147" PostTypeId="2" ParentId="10146" CreationDate="2020-08-24T12:34:51.123" Score="0" Body="&lt;p&gt;I just found that if I use pdf = 1.0f/(4.0f * Pi) in unit sphere sampling or pdf = 1.0f/(2.0f * Pi) in unit hemisphere sampling,the result are almost the same as the importance sampling one(I also get the same result when set the baseColor to vec3(0.4f,0.4f,0.4f),the half of vec3(0.8f,0.8f,0.8f).&#xA;And the surface area of a unit sphere is just 4.0f * Pi(I forget why I use 2.0f * Pi before).I HAVE to come to two conclusions:&lt;/p&gt;&#xA;&lt;p&gt;1: the importance sampling one is correct!&lt;/p&gt;&#xA;&lt;p&gt;2: I'm too stupid!!!!!!&lt;/p&gt;&#xA;" OwnerUserId="13864" LastEditorUserId="13864" LastEditDate="2020-08-24T14:02:13.610" LastActivityDate="2020-08-24T14:02:13.610" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10148" PostTypeId="1" AcceptedAnswerId="10258" CreationDate="2020-08-24T12:58:49.603" Score="2" ViewCount="114" Body="&lt;p&gt;In my HE implementation, half edges are stored in an array. When I iterate over the edges, I color all the HE black, and when I do an operation on an edge (e.g edge splitting) I mark both the current half edge and its pair blue. And in the loop I skip blue edges.&lt;/p&gt;&#xA;&lt;p&gt;This essentially stops me from applying the same operation to an edge twice.&#xA;This however requires O(n) additional memory and iterating over every edge twice (once for each of the HE that compose the edge.)&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    for(uint i=0; i &amp;lt; edge_num; i++)&#xA;    {&#xA;        if(mesh.edges[i].color != BLUE)&#xA;        {&#xA;            /*Do stuff*/&#xA;           mesh.edges[i].color = BLUE;&#xA;           mesh.edges[i].pair.color = BLUE;&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I am wondering if there is a smarter way. In particular, a way that avoids branching. I know I could do something like depth first search or breath first search, but that's likely to be slower than just skipping over edges.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-25T20:08:02.893" Title="Smart half edge iteration?" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;data-structure&gt;" AnswerCount="2" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="10150" PostTypeId="1" AcceptedAnswerId="10169" CreationDate="2020-08-25T22:02:25.567" Score="1" ViewCount="153" Body="&lt;p&gt;How can I compute the gradient for a tetrahedral mesh (3D)? For triangular mesh, I got an answer from the following post &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8835/calculating-the-gradient-of-a-triangular-mesh&quot;&gt;Calculating the gradient of a triangular mesh&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;How can I get a similar formula for 3D mesh?&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="13879" LastActivityDate="2020-08-30T06:31:41.933" Title="Calculating the gradient of a tetrahedral mesh" Tags="&lt;computational-geometry&gt;&lt;mesh&gt;&lt;gradient&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10151" PostTypeId="1" AcceptedAnswerId="10153" CreationDate="2020-08-26T17:44:50.003" Score="0" ViewCount="55" Body="&lt;p&gt;I am getting this error when creating RTPSO with multiple hit groups:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;D3D12 ERROR: ID3D12Device::CreateStateObject: Export &amp;quot;MissIndirect&amp;quot; (mangled name: &amp;quot;\01?MissIndirect@@YAXURayPayload@@@Z&amp;quot;) already defined. [ STATE_CREATION ERROR #1194: CREATE_STATE_OBJECT_ERROR]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;With single hit group I am not getting any errors and code below works correctly:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void RaytracingResources::CreateRTPSO(ID3D12Device5* device, size_t maxPayloadSize)&#xA;{&#xA;    // Need 11 subobjects:&#xA;    // 1 for RGS program&#xA;    // 1 for Miss program&#xA;    // 1 for CHS program&#xA;    // 1 for AHS program&#xA;    // 1 for Hit Group&#xA;    // 2 for RayGen Root Signature (root-signature and association)&#xA;    // 2 for Shader Config (config and association)&#xA;    // 1 for Global Root Signature&#xA;    // 1 for Pipeline Config    &#xA;    UINT index = 0;&#xA;    std::vector&amp;lt;D3D12_STATE_SUBOBJECT&amp;gt; subobjects;&#xA;    size_t size = 0;&#xA;    size += 1; // rgs&#xA;    for (auto&amp;amp; hitGroup : m_hitGroups)&#xA;    {&#xA;        size += 2; // chs, miss&#xA;        size += (hitGroup.hitShader.ahs.name != nullptr) ? 1 : 0; // ahs&#xA;        size += 1; // hit group&#xA;        size += 2; // payload + association&#xA;        size += 2; // local root + association&#xA;    }&#xA;    size += 2; // global root + pipeline config&#xA;    subobjects.resize(size);&#xA;&#xA;    std::vector&amp;lt;LPCWSTR&amp;gt; usedNames;&#xA;    std::vector&amp;lt;IDxcBlob&amp;gt; usedBlobs;&#xA;&#xA;    // Add state subobject for the RGS&#xA;    {&#xA;        D3D12_EXPORT_DESC rgsExportDesc = { m_hitGroups[0].rayGenShader.name, nullptr, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;        D3D12_DXIL_LIBRARY_DESC rgsLibDesc = {};&#xA;        rgsLibDesc.DXILLibrary.BytecodeLength = m_hitGroups[0].rayGenShader.blob-&amp;gt;GetBufferSize();&#xA;        rgsLibDesc.DXILLibrary.pShaderBytecode = m_hitGroups[0].rayGenShader.blob-&amp;gt;GetBufferPointer();&#xA;        rgsLibDesc.NumExports = 1;&#xA;        rgsLibDesc.pExports = &amp;amp;rgsExportDesc;&#xA;&#xA;        D3D12_STATE_SUBOBJECT rgs = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;rgsLibDesc };&#xA;        subobjects[index++] = rgs;&#xA;        usedNames.push_back(m_hitGroups[0].rayGenShader.name);&#xA;    }&#xA;&#xA;    for (auto&amp;amp; hitGroup : m_hitGroups)&#xA;    {&#xA;        //Add state subobject for the Miss shader&#xA;        {&#xA;            D3D12_EXPORT_DESC msExportDesc = { hitGroup.missShader.name, hitGroup.missShader.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC msLibDesc = {};&#xA;            msLibDesc.DXILLibrary.BytecodeLength = hitGroup.missShader.blob-&amp;gt;GetBufferSize();&#xA;            msLibDesc.DXILLibrary.pShaderBytecode = hitGroup.missShader.blob-&amp;gt;GetBufferPointer();&#xA;            msLibDesc.NumExports = 1;&#xA;            msLibDesc.pExports = &amp;amp;msExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT ms = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;msLibDesc };&#xA;            subobjects[index++] = ms;&#xA;        }&#xA;&#xA;        // Add state subobject for the Closest Hit shader&#xA;        {&#xA;            D3D12_EXPORT_DESC chsExportDesc = { hitGroup.hitShader.chs.name, hitGroup.hitShader.chs.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC chsLibDesc = {};&#xA;            chsLibDesc.DXILLibrary.BytecodeLength = hitGroup.hitShader.chs.blob-&amp;gt;GetBufferSize();&#xA;            chsLibDesc.DXILLibrary.pShaderBytecode = hitGroup.hitShader.chs.blob-&amp;gt;GetBufferPointer();&#xA;            chsLibDesc.NumExports = 1;&#xA;            chsLibDesc.pExports = &amp;amp;chsExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT chs = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;chsLibDesc };&#xA;            subobjects[index++] = chs;&#xA;        }&#xA;&#xA;        // Add state subobject for the Any Hit shader&#xA;        if (hitGroup.hitShader.ahs.name != nullptr)&#xA;        {&#xA;            D3D12_EXPORT_DESC ahsExportDesc = { hitGroup.hitShader.ahs.name, hitGroup.hitShader.ahs.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC ahsLibDesc = {};&#xA;            ahsLibDesc.DXILLibrary.BytecodeLength = hitGroup.hitShader.ahs.blob-&amp;gt;GetBufferSize();&#xA;            ahsLibDesc.DXILLibrary.pShaderBytecode = hitGroup.hitShader.ahs.blob-&amp;gt;GetBufferPointer();&#xA;            ahsLibDesc.NumExports = 1;&#xA;            ahsLibDesc.pExports = &amp;amp;ahsExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT ahs = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;ahsLibDesc };&#xA;            subobjects[index++] = ahs;&#xA;        }&#xA;&#xA;        // Add a state subobject for the hit group&#xA;        {&#xA;            D3D12_HIT_GROUP_DESC hitGroupDesc = {};&#xA;            hitGroupDesc.ClosestHitShaderImport = hitGroup.hitShader.chs.name;&#xA;            if (hitGroup.hitShader.ahs.name != nullptr) hitGroupDesc.AnyHitShaderImport = hitGroup.hitShader.ahs.name;&#xA;            hitGroupDesc.HitGroupExport = hitGroup.hitGroupName;&#xA;&#xA;            D3D12_STATE_SUBOBJECT hitGroup = { D3D12_STATE_SUBOBJECT_TYPE_HIT_GROUP, &amp;amp;hitGroupDesc };&#xA;            subobjects[index++] = hitGroup;&#xA;        }&#xA;&#xA;        // Add a state subobject for the shader payload configuration&#xA;        {&#xA;            D3D12_RAYTRACING_SHADER_CONFIG shaderDesc = { static_cast&amp;lt;UINT&amp;gt;(maxPayloadSize), D3D12_RAYTRACING_MAX_ATTRIBUTE_SIZE_IN_BYTES };&#xA;            D3D12_STATE_SUBOBJECT shaderConfigObject = { D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_SHADER_CONFIG, &amp;amp;shaderDesc };&#xA;            subobjects[index++] = shaderConfigObject;&#xA;        }&#xA;&#xA;        // Create a list of the shader export names that use the payload&#xA;        {&#xA;            D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION shaderPayloadAssociation = {};&#xA;            if (hitGroup.hitShader.ahs.name != nullptr) {&#xA;                const WCHAR* shaderExports[] = { m_hitGroups[0].rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name, hitGroup.hitShader.ahs.name };&#xA;                shaderPayloadAssociation = { &amp;amp;subobjects[(index - 1)], _countof(shaderExports), shaderExports };&#xA;            }&#xA;            else {&#xA;                const WCHAR* shaderExports[] = { m_hitGroups[0].rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name };&#xA;                shaderPayloadAssociation = { &amp;amp;subobjects[(index - 1)], _countof(shaderExports), shaderExports };&#xA;            }&#xA;&#xA;            D3D12_STATE_SUBOBJECT shaderPayloadAssociationObject = { D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION, &amp;amp;shaderPayloadAssociation };&#xA;            subobjects[index++] = shaderPayloadAssociationObject;&#xA;        }&#xA;&#xA;        // Add a state subobject for the shared root signature &#xA;        {&#xA;            D3D12_STATE_SUBOBJECT rayGenRootSigObject = { D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE, &amp;amp;hitGroup.rayGenShader.pRootSignature };&#xA;            subobjects[index++] = rayGenRootSigObject;&#xA;        }&#xA;&#xA;        // Create a list of the shader export names that use the root signature&#xA;        {&#xA;            D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION rayGenShaderRootSigAssociation = {};&#xA;            if (hitGroup.hitShader.ahs.name != nullptr)&#xA;            {&#xA;                const WCHAR* rootSigExports[] = { m_hitGroups[0].rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name, hitGroup.hitShader.ahs.name };&#xA;                rayGenShaderRootSigAssociation = { &amp;amp;subobjects[(index - 1)], _countof(rootSigExports), rootSigExports };&#xA;            }&#xA;            else&#xA;            {&#xA;                const WCHAR* rootSigExports[] = { m_hitGroups[0].rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name };&#xA;                rayGenShaderRootSigAssociation = { &amp;amp;subobjects[(index - 1)], _countof(rootSigExports), rootSigExports };&#xA;            }&#xA;&#xA;            D3D12_STATE_SUBOBJECT rayGenShaderRootSigAssociationObject = { D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION, &amp;amp;rayGenShaderRootSigAssociation };&#xA;            subobjects[index++] = rayGenShaderRootSigAssociationObject;&#xA;        }&#xA;    }&#xA;&#xA;    // Setup global root signature&#xA;    {&#xA;        D3D12_STATE_SUBOBJECT globalRootSig = { D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE, &amp;amp;m_hitGroups[0].missShader.pRootSignature };&#xA;        subobjects[index++] = globalRootSig;&#xA;    }&#xA;&#xA;    // Add a state subobject for the ray tracing pipeline config&#xA;    {&#xA;        D3D12_RAYTRACING_PIPELINE_CONFIG pipelineConfig = { 1 }; // Max Trace Recursion Depth&#xA;        D3D12_STATE_SUBOBJECT pipelineConfigObject = { D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG, &amp;amp;pipelineConfig };&#xA;        subobjects[index++] = pipelineConfigObject; &#xA;    }&#xA;&#xA;    // Finish rtpso creation and store in variable&#xA;    {&#xA;        // Describe RTPSO&#xA;        D3D12_STATE_OBJECT_DESC pipelineDesc = { D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, static_cast&amp;lt;UINT&amp;gt;(subobjects.size()), subobjects.data() };&#xA;&#xA;        // Create the RT Pipeline State Object (RTPSO) / Get the RTPSO properties&#xA;        ThrowIfFailed(device-&amp;gt;CreateStateObject(&amp;amp;pipelineDesc, IID_PPV_ARGS(&amp;amp;m_rtpso)));&#xA;        ThrowIfFailed(m_rtpso-&amp;gt;QueryInterface(IID_PPV_ARGS(&amp;amp;m_rtpsoInfo)));&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I am calling it with code below:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;CreateRayGenShader(rayGenShader, m_shaderCompiler, L&amp;quot;Shaders/RT_Lambertian.hlsl&amp;quot;, 2, 1, 5, {}, L&amp;quot;RayGen&amp;quot;);&#xA;CreateMissShader(missShader, m_shaderCompiler, L&amp;quot;Shaders/RT_Lambertian.hlsl&amp;quot;, L&amp;quot;Miss&amp;quot;);&#xA;CreateClosestHitShader(hitShader, m_shaderCompiler, L&amp;quot;Shaders/RT_Lambertian.hlsl&amp;quot;, L&amp;quot;ClosestHit&amp;quot;);&#xA;&#xA;CreateMissShader(missShader_new, m_shaderCompiler, L&amp;quot;Shaders/RT_Lambertian_Indirect.hlsl&amp;quot;, L&amp;quot;MissIndirect&amp;quot;);&#xA;CreateClosestHitShader(hitShader_new, m_shaderCompiler, L&amp;quot;Shaders/RT_Lambertian_Indirect.hlsl&amp;quot;, L&amp;quot;ClosestHitIndirect&amp;quot;);&#xA;&#xA;HitGroup group = { rayGenShader, missShader, hitShader, L&amp;quot;GroupLambert&amp;quot; };&#xA;HitGroup group_new = { rayGenShader, missShader_new, hitShader_new, L&amp;quot;GroupLambert_new&amp;quot; };&#xA;&#xA;m_raytracingLambert = std::shared_ptr&amp;lt;RaytracingResources&amp;gt;(new RaytracingResources(m_device.Get(), m_commandList, model, { group, group_new }));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;However, even when I'm trying to create single group, but I am using std::vector to iterate over rgs, ms, chs - it causes same error:&lt;/strong&gt; (i.e. export &amp;quot;name&amp;quot; already defined [ STATE_CREATION ERROR #1194: CREATE_STATE_OBJECT_ERROR]). Therefore, I am using lengthy code which is called seperately for ms, rgs, chs (and ahs if present).&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;std::vector&amp;lt;RtProgram&amp;gt; rtPrograms;&#xA;HitGroup hitGroup = m_hitGroups[0];&#xA;rtPrograms.push_back(hitGroup.rayGenShader);&#xA;rtPrograms.push_back(hitGroup.missShader);&#xA;rtPrograms.push_back(hitGroup.hitShader.chs);&#xA;&#xA;for (auto&amp;amp; shader : rtPrograms)&#xA;{&#xA;    D3D12_EXPORT_DESC exportDesc = { shader.name, shader.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;    D3D12_DXIL_LIBRARY_DESC libDesc = {};&#xA;    libDesc.DXILLibrary.BytecodeLength = shader.blob-&amp;gt;GetBufferSize();&#xA;    libDesc.DXILLibrary.pShaderBytecode = shader.blob-&amp;gt;GetBufferPointer();&#xA;    libDesc.NumExports = 1;&#xA;    libDesc.pExports = &amp;amp;exportDesc;&#xA;&#xA;    D3D12_STATE_SUBOBJECT stateSubobject = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;libDesc };&#xA;    subobjects[index++] = stateSubobject;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Repo with this code can be found here - &lt;a href=&quot;https://github.com/komilll/RTCP/blob/0b81a41f95ae3fa536324b27201a5fce94f92f24/RTCP/Renderer.cpp#L1039&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/komilll/RTCP/blob/0b81a41f95ae3fa536324b27201a5fce94f92f24/RTCP/Renderer.cpp#L1039&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-08-27T14:57:47.243" LastActivityDate="2020-08-28T12:27:42.213" Title="Hit group - export already defined" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10152" PostTypeId="2" ParentId="10138" CreationDate="2020-08-26T20:58:40.563" Score="0" Body="&lt;p&gt;Got this resolved by using Google's API Vision&#xA;&lt;a href=&quot;https://cloud.google.com/vision&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://cloud.google.com/vision&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13861" LastActivityDate="2020-08-26T20:58:40.563" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10153" PostTypeId="2" ParentId="10151" CreationDate="2020-08-28T12:27:42.213" Score="0" Body="&lt;p&gt;I don't know why, but using any loop while using D3D12_DXIL_LIBRARY_DESC is causing problems. It doesn't seem that it goes out of scope, because current code is seperate by blocks with seperate scops already. Therefore I don't think that's what causes problem.&lt;/p&gt;&#xA;&lt;p&gt;I've dealt with it by simply copy-pasting code and changing index of used data, guarded with (if array.size() &amp;gt; 1). For now, I need only two arrays, but in future, I might add multiple copy-pastes like that. Ideal solution would be either using macros or reaching dxc developers to know what causes problem. &lt;strong&gt;However, for my usage purposes&lt;/strong&gt; it is enough solution.&lt;/p&gt;&#xA;&lt;p&gt;Also, please take a look at this link - &lt;a href=&quot;https://www.willusher.io/graphics/2019/11/20/the-sbt-three-ways&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.willusher.io/graphics/2019/11/20/the-sbt-three-ways&lt;/a&gt; - it turns to be very useful to understand indexing of miss shader/hit groups data.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-08-28T12:27:42.213" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10154" PostTypeId="1" CreationDate="2020-08-28T14:17:42.337" Score="0" ViewCount="588" Body="&lt;p&gt;I'm currently learning compute shaders and I'm trying to write an optimized &lt;a href=&quot;https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life&quot; rel=&quot;nofollow noreferrer&quot;&gt;Game Of Life&lt;/a&gt;. I have a first version working that uses a Shader Storage Buffer Object. I dispatch a thread per cell I want to update and that thread samples the SSBO 8 times to gather the cell's neighbors. This works fine.&lt;/p&gt;&#xA;&lt;p&gt;I'm now trying to optimize this by using shared memory. Every thread in a work group will now load a single cell in shared memory wait for the memory and execution barrier to resolve and then sample the shared memory 8 times to compute its cell's state. Of course some threads need to load more than 1 cell to shared memory because if they're on the 'border' of a workgroup no thread will load the data for some of its neighbors. ( See picture )&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3SQIn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3SQIn.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I got this working as well. However, it is less performant than the brute force version. ( On an RTX 2070 and GTX 660M ) I'm very surprised. I'm using Vulkan and gpu queries to estimate how long the compute pass takes. Here is for example the numbers for a 4096x4096 grid. I dispatch 256x256 thread groups of size 16x16. On my old GTX 660M compute takes ~12ms in brute force mode but it takes ~17ms with TGSM. I can't test on the RTX right now but the TGSM version was less performant as well.&lt;/p&gt;&#xA;&lt;p&gt;I was definitely expecting to see some improvement with TGSM. I need to look into it more with tools like Nvidia Nsight but I would assume this shader is limited by memory and definitely not ALU.&#xA;I guess my questions are:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Am I correct in assuming the TGSM version should run faster somehow? Search for Neighborhood Processing &lt;a href=&quot;https://gpuopen.com/learn/optimizing-gpu-occupancy-resource-usage-large-thread-groups/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;If my assumption is correct, what went wrong?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Here is the brute force shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout (constant_id = 0) const uint CELLS_COUNT          = 4096;&#xA;layout (constant_id = 1) const uint GRID_SIZE            = 64;        &#xA;layout (constant_id = 2) const uint THREADS_PER_GROUP_X  = 8;&#xA;layout (constant_id = 3) const uint THREADS_PER_GROUP_Y  = 8;&#xA;layout (constant_id = 4) const uint THREADS_PER_GROUP    = 64;&#xA;&#xA;layout(local_size_x_id = 2, local_size_y_id = 3) in;&#xA;&#xA;layout(std430, set = 0, binding = 0) buffer SrcGrid {&#xA;    uint state[CELLS_COUNT];&#xA;} srcGrid;&#xA;&#xA;layout(std430, set = 0, binding = 1) buffer DstGrid {&#xA;    uint state[CELLS_COUNT];&#xA;} dstGrid;&#xA;&#xA;const ivec2 sampleXYOffsets[] = { &#xA;    ivec2(-1, -1),   ivec2(0, -1),  ivec2(1, -1),&#xA;    ivec2(-1,  0),                  ivec2(1,  0),&#xA;    ivec2(-1,  1),   ivec2(0,  1),  ivec2(1,  1),&#xA;};&#xA;&#xA;void main() {&#xA;    &#xA;    const uint maxIdX = gl_WorkGroupSize.x * gl_NumWorkGroups.x;&#xA;    const uint maxIdY = gl_WorkGroupSize.y * gl_NumWorkGroups.y;&#xA;&#xA;    uint aliveNeighbors = 0;&#xA;    // Convert dispatch IDs into storage buffer id&#xA;    const uint currentCellIndex = gl_GlobalInvocationID.y * maxIdX + gl_GlobalInvocationID.x;&#xA;    // Convert storage buffer id into grid coordinates (x, y)&#xA;    const uvec2 currentCoords = uvec2( currentCellIndex % GRID_SIZE, currentCellIndex / GRID_SIZE);&#xA;    for( uint i = 0; i &amp;lt; 8; i++ ){&#xA;&#xA;        uvec2 coords = currentCoords;&#xA;        // Bring everything above 0 to be able to use the modulo operator&#xA;        coords = (coords + sampleXYOffsets[i] + GRID_SIZE) % GRID_SIZE;&#xA;        // Convert grid coordinates (x, y) into storage buffer id&#xA;        uint neighborIndex = coords.x + coords.y * GRID_SIZE;&#xA;        aliveNeighbors += srcGrid.state[neighborIndex];&#xA;    }&#xA;&#xA;    uint currentCellState = srcGrid.state[currentCellIndex];&#xA;&#xA;    if( currentCellState &amp;lt; 1.0 &amp;amp;&amp;amp; aliveNeighbors == 3 )&#xA;    {&#xA;        // Dead cell comes back to life&#xA;        dstGrid.state[currentCellIndex] = 1;&#xA;        return;&#xA;    }&#xA;&#xA;    // Alive cell dies&#xA;    if( aliveNeighbors &amp;lt; 2.0 || aliveNeighbors &amp;gt; 3.0)&#xA;    {&#xA;        dstGrid.state[currentCellIndex] = 0;&#xA;        return;&#xA;    }&#xA;&#xA;    dstGrid.state[currentCellIndex] = currentCellState;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And the one using TGSM:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 450&#xA;&#xA;layout (constant_id = 0) const uint CELLS_COUNT          = 4096;&#xA;layout (constant_id = 1) const uint GRID_SIZE            = 64;        &#xA;layout (constant_id = 2) const uint THREADS_PER_GROUP_X  = 8;&#xA;layout (constant_id = 3) const uint THREADS_PER_GROUP_Y  = 8;&#xA;layout (constant_id = 4) const uint THREADS_PER_GROUP    = 64;&#xA;&#xA;layout(local_size_x_id = 2, local_size_y_id = 3) in;&#xA;&#xA;layout(std430, set = 0, binding = 0) buffer SrcGrid {&#xA;    uint state[CELLS_COUNT];&#xA;} srcGrid;&#xA;&#xA;layout(std430, set = 0, binding = 1) buffer DstGrid {&#xA;    uint state[CELLS_COUNT];&#xA;} dstGrid;&#xA;&#xA;uint getSSBODataFromWorldGridCoords( uint worldGridX, uint worldGridY )&#xA;{&#xA;    uvec2 worldGridCoords = uvec2( worldGridX, worldGridY );&#xA;    worldGridCoords = (worldGridCoords + GRID_SIZE) % GRID_SIZE;&#xA;    return srcGrid.state[ worldGridCoords.x + worldGridCoords.y  * GRID_SIZE ];&#xA;}&#xA;&#xA;shared uint sharedData[ THREADS_PER_GROUP_X + 2 ][ THREADS_PER_GROUP_Y + 2 ];&#xA;&#xA;void main() &#xA;{&#xA;&#xA;    const uvec2 workGroupSize = uvec2( THREADS_PER_GROUP_X, THREADS_PER_GROUP_Y );&#xA;&#xA;    // Grid coords within a thead group&#xA;    const uvec2 localGridCoords = gl_LocalInvocationID.xy;&#xA;    // Coordinates of each thread group tile&#xA;    const uvec2 worldGridOffset = gl_WorkGroupID.xy * workGroupSize.xy;&#xA;    // Grid coords within the whole game &#xA;    const uvec2 worldGridCoords = worldGridOffset + localGridCoords; &#xA;&#xA;    // Early out if not in the grid&#xA;    if( worldGridCoords.x &amp;gt;= GRID_SIZE || worldGridCoords.y &amp;gt;= GRID_SIZE )&#xA;    {&#xA;        return;&#xA;    }&#xA;&#xA;    // Load data into TGSM&#xA;    const uvec2 tgsmCoords = localGridCoords + uvec2( 1, 1 );&#xA;&#xA;    // Top left corner &#xA;    if( localGridCoords.x == 0 &amp;amp;&amp;amp; localGridCoords.y == 0 )&#xA;    {&#xA;        // Top&#xA;        sharedData[ tgsmCoords.x     ][ tgsmCoords.y - 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x,     worldGridCoords.y - 1 );&#xA;        // Top Left&#xA;        sharedData[ tgsmCoords.x - 1 ][ tgsmCoords.y - 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x - 1, worldGridCoords.y - 1 );&#xA;        // Left&#xA;        sharedData[ tgsmCoords.x - 1 ][ tgsmCoords.y     ] = getSSBODataFromWorldGridCoords( worldGridCoords.x - 1, worldGridCoords.y     );&#xA;    }&#xA;    // Top right corner &#xA;    else if( localGridCoords.x == workGroupSize.x - 1 &amp;amp;&amp;amp; localGridCoords.y == 0 )&#xA;    {&#xA;        // Top&#xA;        sharedData[ tgsmCoords.x     ][ tgsmCoords.y - 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x,     worldGridCoords.y - 1 );&#xA;        // Top Right&#xA;        sharedData[ tgsmCoords.x + 1 ][ tgsmCoords.y - 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x + 1, worldGridCoords.y - 1 );&#xA;        // Right&#xA;        sharedData[ tgsmCoords.x + 1 ][ tgsmCoords.y     ] = getSSBODataFromWorldGridCoords( worldGridCoords.x + 1, worldGridCoords.y     );&#xA;    }&#xA;    // Bottom left corner &#xA;    else if( localGridCoords.x == 0 &amp;amp;&amp;amp; localGridCoords.y == workGroupSize.y - 1 )&#xA;    {&#xA;        // Bottom&#xA;        sharedData[ tgsmCoords.x     ][ tgsmCoords.y + 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x,     worldGridCoords.y + 1 );&#xA;        // Bottom Left&#xA;        sharedData[ tgsmCoords.x - 1 ][ tgsmCoords.y + 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x - 1, worldGridCoords.y + 1 );&#xA;        // Left&#xA;        sharedData[ tgsmCoords.x - 1 ][ tgsmCoords.y     ] = getSSBODataFromWorldGridCoords( worldGridCoords.x - 1, worldGridCoords.y     );&#xA;    }&#xA;    // Bottom right corner &#xA;    else if( localGridCoords.x == workGroupSize.x - 1 &amp;amp;&amp;amp; localGridCoords.y == workGroupSize.y - 1 )&#xA;    {&#xA;        // Bottom&#xA;        sharedData[ tgsmCoords.x     ][ tgsmCoords.y + 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x,     worldGridCoords.y + 1 );&#xA;        // Bottom Right&#xA;        sharedData[ tgsmCoords.x + 1 ][ tgsmCoords.y + 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x + 1, worldGridCoords.y + 1 );&#xA;        // Right&#xA;        sharedData[ tgsmCoords.x + 1 ][ tgsmCoords.y     ] = getSSBODataFromWorldGridCoords( worldGridCoords.x + 1, worldGridCoords.y     );&#xA;    }&#xA;    // Left Edge&#xA;    else if( localGridCoords.x == 0 )&#xA;    {&#xA;        sharedData[ tgsmCoords.x - 1 ][ tgsmCoords.y     ] = getSSBODataFromWorldGridCoords( worldGridCoords.x - 1, worldGridCoords.y     );&#xA;    }&#xA;    // Right Edge&#xA;    else if( localGridCoords.x == workGroupSize.x - 1 )&#xA;    {&#xA;        sharedData[ tgsmCoords.x + 1 ][ tgsmCoords.y     ] = getSSBODataFromWorldGridCoords( worldGridCoords.x + 1, worldGridCoords.y     );&#xA;    }&#xA;    // Top Edge&#xA;    else if( localGridCoords.y == 0 )&#xA;    {&#xA;        sharedData[ tgsmCoords.x     ][ tgsmCoords.y - 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x,     worldGridCoords.y - 1 );&#xA;    }&#xA;    // Bottom Edge&#xA;    else if( localGridCoords.y == workGroupSize.y - 1 )&#xA;    {&#xA;        sharedData[ tgsmCoords.x     ][ tgsmCoords.y + 1 ] = getSSBODataFromWorldGridCoords( worldGridCoords.x,     worldGridCoords.y + 1 );&#xA;    }&#xA;&#xA;    // SSBO index for this thread&#xA;    const uint ssboIndex = worldGridCoords.x + worldGridCoords.y * GRID_SIZE;&#xA;    uint currentCellState = getSSBODataFromWorldGridCoords( worldGridCoords.x, worldGridCoords.y );&#xA;&#xA;    // Load current cell into TGSM.&#xA;    sharedData[ tgsmCoords.x ][ tgsmCoords.y ] = currentCellState;&#xA;&#xA;    // Barrier&#xA;    memoryBarrierShared();&#xA;    barrier();&#xA;&#xA;    // Count alive neighbors from TGSM&#xA;    uint aliveNeighbors = 0;&#xA;    const uvec2 sharedMemoryGridCoordinates = uvec2( localGridCoords.x + 1, localGridCoords.y + 1 );&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x - 1 ][ sharedMemoryGridCoordinates.y - 1 ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x     ][ sharedMemoryGridCoordinates.y - 1 ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x + 1 ][ sharedMemoryGridCoordinates.y - 1 ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x - 1 ][ sharedMemoryGridCoordinates.y     ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x + 1 ][ sharedMemoryGridCoordinates.y     ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x - 1 ][ sharedMemoryGridCoordinates.y + 1 ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x     ][ sharedMemoryGridCoordinates.y + 1 ];&#xA;    aliveNeighbors += sharedData[ sharedMemoryGridCoordinates.x + 1 ][ sharedMemoryGridCoordinates.y + 1 ];&#xA;&#xA;    if( currentCellState &amp;lt; 1.0 &amp;amp;&amp;amp; aliveNeighbors == 3 )&#xA;    {&#xA;        // Dead cell comes back to life&#xA;        dstGrid.state[ssboIndex] = 1;&#xA;        return;&#xA;    }&#xA;&#xA;    // Alive cell dies&#xA;    if( aliveNeighbors &amp;lt; 2.0 || aliveNeighbors &amp;gt; 3.0)&#xA;    {&#xA;        dstGrid.state[ssboIndex] = 0;&#xA;        return;&#xA;    }&#xA;&#xA;    dstGrid.state[ssboIndex] = currentCellState;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Any pointers towards articles or tools that could help me figure this out would be greatly appreciated :).&lt;/p&gt;&#xA;" OwnerUserId="11388" LastActivityDate="2020-08-28T14:17:42.337" Title="Optimizing compute shader with thread group shared memory" Tags="&lt;gpu&gt;&lt;performance&gt;&lt;compute-shader&gt;&lt;simulation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10155" PostTypeId="1" CreationDate="2020-08-28T14:34:28.567" Score="0" ViewCount="28" Body="&lt;p&gt;I am looking for tools to generate video and audio output for my own codecs, in my search I found SDL, EGL, FFmpeg and OpenAL, but it is not clear to me if these APIs serve my purpose which is simply to generate the output, if so when should I use each one?&lt;/p&gt;&#xA;" OwnerUserId="13887" LastActivityDate="2020-08-28T14:34:28.567" Title="What APIs are used to output video and audio from a custom codec?" Tags="&lt;pixel-graphics&gt;&lt;api&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10156" PostTypeId="1" AcceptedAnswerId="10158" CreationDate="2020-08-28T19:16:03.943" Score="2" ViewCount="178" Body="&lt;p&gt;I have a mesh of an object enclosed in unit volume cube and I would like to sample points inside and outside the mesh surface. What are the different ways of doing it? Is there any sample code available?&lt;/p&gt;&#xA;" OwnerUserId="13888" LastActivityDate="2020-09-10T13:33:43.793" Title="How to Sample 3D Points Outside and Inside the Mesh Surface" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;sampling&gt;" AnswerCount="3" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10157" PostTypeId="2" ParentId="10114" CreationDate="2020-08-28T20:40:46.377" Score="0" Body="&lt;p&gt;The original CIE RGB colors included luminance within the actual encoding, and the original basis colors chosen for CIE RGB were chosen because they were easy to reproduce at that time. This made it much easier and more accurate when doing color experiments that required people to classify colors when producing those colors with real physical equipment.&lt;/p&gt;&#xA;&lt;p&gt;But, because of these two choices, some of the colors required the red value (when plotted on a graph) to drop below zero. At the time having negative values was considered okay because the eye has a tough time in the 700nm range of colors so a little error here allowed for greater accuracy overall.&lt;/p&gt;&#xA;&lt;p&gt;But, this caused a problem when translating CIE RGB colors into real physical colors. So they convened a panel, then they argued (a lot) and came up with the CIE XYZ color space. CIE XYZ attempts to separate lumanance (perceived brightness) out of the color gamut by encoding it in the  Y channel, and it also removes those pesky negative values.&lt;/p&gt;&#xA;&lt;p&gt;But, they needed to represent all the colors in the original CIE RGB color space in the new CIE XYZ color space. So, the CIE panel created color matching functions (or matrix depending on how you look at it) that exactly represents the CIE RGB color gamut in CIE XYZ color gamut. So, when you map both gamuts to a 2D plot they will actually plot to different points within the same graph because they are represented by different values.&lt;/p&gt;&#xA;&lt;p&gt;Keep in mind that it is possible for two different wavelengths of light to be perceived as the same exact color so long as the weighted sum of the spectral distributions are equivalent. But that's a different story.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-08-28T20:40:46.377" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10158" PostTypeId="2" ParentId="10156" CreationDate="2020-08-28T22:54:12.950" Score="4" Body="&lt;p&gt;What you want is something that can perform the &lt;a href=&quot;https://en.wikipedia.org/wiki/Point_in_polygon&quot; rel=&quot;nofollow noreferrer&quot;&gt;inside-outside test&lt;/a&gt; for meshes. The simplest solution would be to use &lt;a href=&quot;https://github.com/mikedh/trimesh&quot; rel=&quot;nofollow noreferrer&quot;&gt;Trimesh&lt;/a&gt;'s implementation which can be ran with Embree to accelerate ray queries.&lt;/p&gt;&#xA;&lt;p&gt;I recommend you check out recent literature on neural implicit representations if you want more alternatives. Your problem arises when one wants to learn 3D shapes using small neural networks; it is then necessary to sample points and their groundtruth attributes with respect to the mesh (signed distances or occupancies of points). &lt;a href=&quot;https://github.com/zekunhao1995/DualSDF/blob/master/extensions/mesh2sdf2_cuda/mesh2sdf_kernel.cu&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;'s one example for SDFs written in CUDA. NVIDIA's &lt;a href=&quot;https://github.com/NVIDIAGameWorks/kaolin&quot; rel=&quot;nofollow noreferrer&quot;&gt;Kaolin&lt;/a&gt; also has a CUDA kernel for this IIRC.&lt;/p&gt;&#xA;&lt;p&gt;For more troublesome meshes, you can also use the &lt;a href=&quot;https://www.dgp.toronto.edu/projects/fast-winding-numbers/&quot; rel=&quot;nofollow noreferrer&quot;&gt;generalized winding number&lt;/a&gt;, which has an implementation in &lt;a href=&quot;https://github.com/libigl/libigl&quot; rel=&quot;nofollow noreferrer&quot;&gt;libigl&lt;/a&gt; but I think their code is CPU-only.&lt;/p&gt;&#xA;" OwnerUserId="6588" LastActivityDate="2020-08-28T22:54:12.950" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10159" PostTypeId="2" ParentId="10114" CreationDate="2020-08-28T23:36:48.080" Score="1" Body="&lt;p&gt;Correct, the missing curvy section in the green-cyan-blue area represents where the red component would have to go negative to express those colors in CIE RGB coordinates.&lt;/p&gt;&#xA;&lt;p&gt;RGB and XYZ are, at one level, just different coordinate systems covering the same color space—the space of all colors visible to typical human vision. In a mathematical sense, when used as coordinates, there's nothing wrong with negative RGB values (as long as the overall luminance of the color remains positive). But it does present a problem for storing or transmitting such values, as conventional image formats and display signal protocols like HDMI etc only allow for positive values.&lt;/p&gt;&#xA;&lt;p&gt;On another level, various RGB color spaces are used because they more or less directly represent the actual red, green, and blue subpixels on the display. Those can't emit negative light of course, and so the RGB triangle in color space represents the gamut of colors that can be produced by the display.&lt;/p&gt;&#xA;&lt;p&gt;Unfortunately because the spectral locus is curved, there's no way that 3 primaries can cover the whole thing. All RGB spaces inevitably cut off a big chunk of the highly saturated green/blue colors.&lt;/p&gt;&#xA;&lt;p&gt;The XYZ space sort of has the opposite problem. All visible colors can be represented using only positive values in XYZ, but the XYZ primaries themselves are not physically possible colors—they're well outside the visible gamut. So, there's a big chunk of XYZ space that is not valid as a color. And it's not trivial to determine exactly what values are or aren't valid, as you have to test whether they fall inside or outside of the curved spectral locus. This also means that you need more bits per component to get good precision, if you store/transmit images expressed in XYZ—8 bits won't do, probably not 10 bits either, maybe 12 bits would do the job.&lt;/p&gt;&#xA;&lt;p&gt;If we want to make displays that cover more of the visible gamut, we will eventually need to move to 4, 5, or more primaries. However, that doesn't mean we need 4- or 5-dimensional color spaces. A futuristic display device could be fed by images in XYZ space, for instance, and the device would decide how best to generate each color using the primaries it has available.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-28T23:36:48.080" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10160" PostTypeId="1" AcceptedAnswerId="10179" CreationDate="2020-08-29T02:01:12.743" Score="1" ViewCount="92" Body="&lt;p&gt;I'm implementing Peter Shirley's &amp;quot;Raytracer in a Weekend: The next week&amp;quot; and I'm having some trouble with rendering a scene with a light. I'm not sure if the issue is the background color or the light itself but the raytracer seems to be working fine in any scenes that have no lights.&lt;/p&gt;&#xA;&lt;p&gt;The image rendered is supposed to be:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/aA4Nu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aA4Nu.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;but it actually turns out as:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Cmm6V.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Cmm6V.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;When I try to troubleshoot and change the background color to blue the image is:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wTZdL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wTZdL.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Hopefully someone who has implemented this raytracer before or who has intuition about raytracing has an idea why this might be happening??&lt;/p&gt;&#xA;" OwnerUserId="13559" LastEditorUserId="13559" LastEditDate="2020-10-17T12:41:11.953" LastActivityDate="2020-10-17T12:41:11.953" Title="Raytracer help - Background color writing over some colors?" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;lighting&gt;&lt;color&gt;&lt;color-science&gt;" AnswerCount="1" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10163" PostTypeId="2" ParentId="10156" CreationDate="2020-08-29T07:46:21.940" Score="4" Body="&lt;p&gt;I have a few suggestions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Partition the volume by using tetrahedra within the mesh, and outside of it (in the cube). Set the probability to sample each tetrahedron to its volume divided by the inside/outside volume of the mesh. Sample a tetrahedron based on the above probability, then sample a point (uniformly) within the chosen tetrahedron.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Discretize your mesh to a grid, and then use a filling algorithm for the inside/outside. Keep arrays of the inside/outside cells and sample those randomly. Compared to (1) this introduces discretization error.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Pick a point uniformly in the cube, then shoot a ray in any direction and if it intersect the mesh an even number of times then it is outside, otherwise it is inside.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;If the mesh is convex (or can be decomposed in convex pieces) then you can check plane half-space membership which allows an early out.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2020-08-29T08:17:48.747" LastActivityDate="2020-08-29T08:17:48.747" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10164" PostTypeId="1" CreationDate="2020-08-29T22:21:20.140" Score="2" ViewCount="30" Body="&lt;p&gt;I'm in Blender and working with a pre-existing 3D model- I want to add more length to it, but I don't want to mess with the mesh- Is it possible to extend the texture beyond the mesh without changing it, or will I have to change the mesh anyways? Are there any shortcuts around changing the mesh?&lt;/p&gt;&#xA;" OwnerUserId="13891" LastActivityDate="2020-08-30T21:25:01.977" Title="Wondering if it's possible to 'extend' a texture beyond the mesh without altering the mesh itself" Tags="&lt;mesh&gt;&lt;model&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10165" PostTypeId="2" ParentId="9640" CreationDate="2020-08-29T23:24:24.387" Score="0" Body="&lt;p&gt;One way to do it: first find the maximum x using atomics on a shared variable. Then, have each thread compare its local version of x to the found maximum, and store to y only if they are equal.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;shared uint x, y;&#xA;...&#xA;uint localX, localY;&#xA;// each thread computes its localX and localY&#xA;atomicMax(x, localX);&#xA;barrier();  // ensure all threads have done the atomicMax before going on&#xA;if (x == localX)&#xA;{&#xA;    atomicExchange(y, localY);&#xA;}&#xA;barrier();&#xA;// now you can read the final x and y values&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This should work even if there are multiple threads with the same maximum value of &lt;code&gt;x&lt;/code&gt;, as the stores to &lt;code&gt;y&lt;/code&gt; are atomic, so you'll just end up with an arbitrary one of them &amp;quot;winning&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;A variation on this, which may be useful if &lt;code&gt;y&lt;/code&gt; is a larger struct of multiple pieces of data and therefore can't be atomically stored natively, is to use the local invocation index to pick the &amp;quot;winning&amp;quot; thread.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;shared uint x, winningThread;&#xA;shared MyStruct y;&#xA;...&#xA;uint localX;&#xA;MyStruct localY;&#xA;// each thread computes its localX and localY&#xA;atomicMax(x, localX);&#xA;barrier();  // ensure all threads have done the atomicMax before going on&#xA;if (x == localX)&#xA;{&#xA;    atomicExchange(winningThread, gl_LocalInvocationIndex);&#xA;}&#xA;barrier();&#xA;if (winningThread == gl_LocalInvocationIndex)&#xA;{&#xA;    y = localY;  // only one thread will ever do this store, so doesn't need to be atomic&#xA;}&#xA;barrier();&#xA;// now you can read the final x and y values&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-29T23:24:24.387" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10166" PostTypeId="2" ParentId="10148" CreationDate="2020-08-29T23:38:19.167" Score="2" Body="&lt;p&gt;One possibility would be to create a bit array with 1 bit per half-edge. When you start iterating, initialize them all to 1, then clear the bits of each half-edge and its partner as you iterate.&lt;/p&gt;&#xA;&lt;p&gt;The iteration can be done using &lt;a href=&quot;https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005fclz&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;__builtin_clz&lt;/code&gt;&lt;/a&gt; (GCC, clang)  or &lt;a href=&quot;https://docs.microsoft.com/en-us/cpp/intrinsics/bitscanreverse-bitscanreverse64?view=vs-2019&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;_BitScanReverse&lt;/code&gt;&lt;/a&gt; (MSVC)  [edit: or &lt;a href=&quot;https://en.cppreference.com/w/cpp/numeric/countl_zero&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;std::countl_zero&lt;/code&gt;&lt;/a&gt; in C++20!] to efficiently extract the next 1-bit without branching on every bit. Although you do then need a nested pair of loops, where you loop over the fields in your bit array, and then loop extracting bits until the current field is zero.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-03T22:55:47.977" LastActivityDate="2020-09-03T22:55:47.977" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10167" PostTypeId="2" ParentId="10118" CreationDate="2020-08-30T00:12:42.037" Score="2" Body="&lt;p&gt;Points in front of the camera have &lt;span class=&quot;math-container&quot;&gt;$w &amp;gt; 0$&lt;/span&gt; strictly, by definition. I would say that if clipping is giving you points with &lt;span class=&quot;math-container&quot;&gt;$w = 0$&lt;/span&gt; then something is going wrong.&lt;/p&gt;&#xA;&lt;p&gt;Consider the left/right/top/bottom clip planes. There is no way that a triangle can span from part of the visible frustum, to the &lt;span class=&quot;math-container&quot;&gt;$w = 0$&lt;/span&gt; camera plane or behind it, without also crossing outside one of the frustum side planes—or else the near plane, which lies at some positive distance &lt;span class=&quot;math-container&quot;&gt;$w_\text{near} &amp;gt; 0$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;You mentioned skyboxes and setting &lt;span class=&quot;math-container&quot;&gt;$z = w$&lt;/span&gt; in the vertex shader output. Such geometry must cross the frustum side planes before it can get to the near plane. (How could part of a skybox get close enough to the camera to be clipped by the near plane only?) If you are correctly clipping it against &lt;em&gt;all&lt;/em&gt; of the frustum planes, you must end up with &lt;span class=&quot;math-container&quot;&gt;$w &amp;gt; 0$&lt;/span&gt; in the final vertex.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-30T00:12:42.037" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10168" PostTypeId="2" ParentId="10146" CreationDate="2020-08-30T00:35:09.183" Score="0" Body="&lt;p&gt;There are some bugs in your math. You found the problem with the 2π and 4π in the hemisphere and sphere sampling functions already, but also, these lines in the cosine hemisphere sampling are wrong:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float x = cos(phi) * 2.0f * sqrt(r2);&#xA;float y = sin(phi) * 2.0f * sqrt(r2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;There should not be a factor of 2 in these: this is distorting the cosine distribution.&lt;/p&gt;&#xA;&lt;p&gt;Also,&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 pdf = dotp(uvw.w(), direction)/Pi;&#xA;throughput = throughput * brdf_result * cosine / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This isn't wrong, but it is unnecessary: the &lt;code&gt;pdf&lt;/code&gt; cancels out the &lt;code&gt;cosine&lt;/code&gt;, so it would be preferable to set &lt;code&gt;pdf&lt;/code&gt; to just 1/π, and leave the cosine factor off. In fact, that also cancels the 1/π in the &lt;code&gt;brdf_result&lt;/code&gt;, so you could leave off both of those pi factors and get rid of &lt;code&gt;pdf&lt;/code&gt; entirely.&lt;/p&gt;&#xA;&lt;p&gt;More about the cosine factor: the whole idea of sampling with a cosine-weighted hemisphere is to avoid needing to have the cosine factor in the path throughput. Basically you only want the cosine in one place: either in the sampling distribution or in the throughput, but not both. It's preferable to put it in the sampling distribution because then the variance in the samples is lower (as they don't have the strongly varying cosine factor in their throughput), so the rendering converges faster.&lt;/p&gt;&#xA;&lt;p&gt;This is also a general maxim in path tracing: you generally want to move factors from the throughput into the ray distribution whenever practical. That's the idea of importance sampling of BRDFs (move factors from the BRDF into the ray distribution) and explicit light sampling (move parts of the incoming light distribution into the ray distribution) as well as more advanced things like multiple importance sampling or path guiding.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-30T00:35:09.183" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10169" PostTypeId="2" ParentId="10150" CreationDate="2020-08-30T06:31:41.933" Score="1" Body="&lt;p&gt;Assuming a value is assigned to each vertex of the mesh and we use purely linear interpolation, then there will be a constant gradient vector within each tetrahedron.&lt;/p&gt;&#xA;&lt;p&gt;Linear interpolation can be expressed using barycentric coordinates, like&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f(x,y,z) = f_1 w_1(x,y,z) + f_2 w_2(x,y,z) + f_3 w_3(x,y,z) + f_4 w_4(x,y,z)&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$f_1 \ldots f_4$&lt;/span&gt; are the values of the function at the four vertices, and &lt;span class=&quot;math-container&quot;&gt;$w_1 \ldots w_4$&lt;/span&gt; are the barycentric weights for each vertex. Then, finding the gradient of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; reduces to finding the gradients of all of the weights.&lt;/p&gt;&#xA;&lt;p&gt;This can be worked out geometrically by noting that each &lt;span class=&quot;math-container&quot;&gt;$w_i$&lt;/span&gt; is 1 at the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th vertex, falling off to 0 at the plane formed by the other three vertices. The gradient vector will therefore be normal to that plane, pointing back towards the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th vertex, with a magnitude equal to 1 / the distance from the plane to the vertex.&lt;/p&gt;&#xA;&lt;p&gt;Once you've calculated those barycentric gradients, you can multiply them by &lt;span class=&quot;math-container&quot;&gt;$f_1 \ldots f_4$&lt;/span&gt; and sum them up to arrive at the gradient of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; overall.&lt;/p&gt;&#xA;&lt;p&gt;This reasoning works for triangles too, by the way, only replace &amp;quot;plane&amp;quot; with &amp;quot;line&amp;quot;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-30T06:31:41.933" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10170" PostTypeId="1" AcceptedAnswerId="10171" CreationDate="2020-08-30T16:49:05.823" Score="3" ViewCount="95" Body="&lt;p&gt;I was recently trying to read some rendering papers and textbooks. The word 2D BRDF slice/lobe is often used while no official definition is provided. I know that BRDF is a 4D function of input direction and output direction. What is the 2D slice/lobe based on that? Are they the same concept? If not, what's the definition of each of them?&lt;/p&gt;&#xA;" OwnerUserId="13896" LastActivityDate="2020-08-30T19:03:37.757" Title="What is 2D BRDF Slice/Lobe?" Tags="&lt;rendering&gt;&lt;brdf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10171" PostTypeId="2" ParentId="10170" CreationDate="2020-08-30T19:03:37.757" Score="3" Body="&lt;p&gt;A BRDF is a 4D function, but as we cannot really visualize a 4D function in a comprehensible way, if we want to understand its behavior it can be instructive to fix 2 or 3 of the parameters and graph the others. This kind of graph can be called a &amp;quot;slice&amp;quot;. (The mental image I have is like: the BRDF is some oddly shaped fruit, and we're taking a knife and making a slice through it, to examine the shape of the cut area.)&lt;/p&gt;&#xA;&lt;p&gt;In particular, a common way to do this is to fix the incoming light direction; then the BRDF can be graphed as a function of the outgoing light direction, like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/ryiWI.png&quot; alt=&quot;3D graph of outgoing light distribution of a BRDF&quot; /&gt;&lt;br /&gt;&#xA;(image from &lt;a href=&quot;http://brdflab.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://brdflab.sourceforge.net/&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;The orange line on the left represents the fixed incoming light direction. This is a polar graph, so the magnitude of outgoing light in each direction is graphed as the radius of the shape.&lt;/p&gt;&#xA;&lt;p&gt;In this case we can see that most of the light is going out along the specular reflection direction, to the upper right; but some is heading back toward the source as well (retroreflection). These are the &amp;quot;lobes&amp;quot;. Lobes are not precisely defined, but intuitively they are the visible features in the shape of the function. Here, we would say there is a &amp;quot;specular lobe&amp;quot; and a &amp;quot;retroreflection lobe&amp;quot;. In fact, this BRDF looks like it has two specular lobes, one long skinny one (which represents a tightly concentrated, bright highlight) and another short and fat one (a more spread-out, soft/rough highlight). There appears be a diffuse lobe as well, which shows up as a hemisphere around the origin in this type of graph.&lt;/p&gt;&#xA;&lt;p&gt;It's also common to simplify the graph even more by constraining the outgoing light directions to be coplanar with the normal and the incoming light, so now you're only graphing the (N, V) angle. That gets you a graph like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/5UYis.png&quot; alt=&quot;2D graph of coplanar outgoing light distribution&quot; /&gt;&lt;br /&gt;&#xA;(image from &lt;a href=&quot;https://google.github.io/filament/Filament.html#materialsystem/standardmodel&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically Based Rendering in Filament&lt;/a&gt;)&lt;/p&gt;&#xA;&lt;p&gt;This is the one that's most likely to be called a &amp;quot;slice&amp;quot;. This diagram also shows two &amp;quot;lobes&amp;quot;, a specular one and a diffuse-ish one.&lt;/p&gt;&#xA;&lt;p&gt;Synthetic BRDFs (what we mostly use in graphics) are usually constructed by taking a weighted average of various lobes generated by different models, e.g. a Lambert diffuse lobe with one or more microfacet specular lobes, etc. When looking at measured BRDFs, we could try to identify the &amp;quot;lobes&amp;quot; by fitting some model lobes to the measured data.&lt;/p&gt;&#xA;&lt;p&gt;To sum up, &amp;quot;slice&amp;quot; is a type of graph that allows us to visualize the features of a BRDF, and &amp;quot;lobe&amp;quot; is the name for the typical kind of features that we see in the BRDF shape, or that we use to construct the BRDF in the first place.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-30T19:03:37.757" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10172" PostTypeId="2" ParentId="10164" CreationDate="2020-08-30T21:25:01.977" Score="1" Body="&lt;p&gt;Textures are applied to the faces of a mesh, so textures cannot be anywhere there isn't a face for it to appear on. &amp;quot;Adding more length&amp;quot; to a mesh pretty much implies moving some of the vertices. I don't think you're going to get around that.&lt;/p&gt;&#xA;&lt;p&gt;Now if you are assembling a game world, it's quite common to have modular mesh pieces that can be aligned end-to-end, or placed intersecting each other, to form larger structures—like a wall panel that can be duplicated several times to form a longer wall, for instance, without needing a new mesh to be built specifically for that wall.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-08-30T21:25:01.977" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10174" PostTypeId="5" CreationDate="2020-08-31T13:22:40.503" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://developer.apple.com/documentation/metal&quot; rel=&quot;nofollow noreferrer&quot;&gt;Metal&lt;/a&gt; is Apple's low-level graphics and compute API and LLVM-based toolchain.&lt;/p&gt;&#xA;" OwnerUserId="1586" LastEditorUserId="13095" LastEditDate="2020-09-01T13:20:28.703" LastActivityDate="2020-09-01T13:20:28.703" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10175" PostTypeId="4" CreationDate="2020-08-31T13:22:40.503" Score="0" Body="For questions about the Metal graphics/compute API.&#xD;&#xA;" OwnerUserId="1586" LastEditorUserId="1586" LastEditDate="2020-09-01T13:21:49.733" LastActivityDate="2020-09-01T13:21:49.733" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10176" PostTypeId="1" CreationDate="2020-08-31T22:24:18.813" Score="0" ViewCount="148" Body="&lt;p&gt;I am trying to add GGX and PBR textures to my GPU ray tracer. The result is very strange, it's getting darker for each frame.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1tA6Y.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1tA6Y.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/eJZmo.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eJZmo.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;        float ao = texAO.sample(textureSampler, hitRecord.uv).r;&#xA;        &#xA;        float3 albedo = texAlbedo.sample(textureSampler, hitRecord.uv).rgb;&#xA;        albedo = pow(albedo, 2.2); //albedo = float3(1.0);&#xA;        &#xA;        float metallic = texMetallic.sample(textureSampler, hitRecord.uv).r;&#xA;        float3 tNormal = texNormal.sample(textureSampler, hitRecord.uv).xyz;&#xA;        tNormal = normalize(tNormal * 2 - 1);&#xA;        &#xA;        float roughness = texRoughness.sample(textureSampler, hitRecord.uv).r;&#xA;        roughness = max(roughness, 0.001);&#xA;        &#xA;        float3 nx, ny;&#xA;        CoordinateSystem(normal, nx, ny);&#xA;        float3x3 stw = { nx, ny, normal };&#xA;        &#xA;        normal = stw * tNormal;&#xA;        CoordinateSystem(normal, nx, ny);&#xA;        stw = { nx, ny, normal };&#xA;        &#xA;        float3 wi, wh;&#xA;        float3 wo = transpose(stw) * (ray.direction);&#xA;    &#xA;        auto pSpecular = 1/(2-metallic);&#xA;        &#xA;        auto r0 = randomF(seed);&#xA;        auto r1 = randomF(seed);&#xA;        &#xA;        if (randomF(seed) &amp;gt; pSpecular) {&#xA;            &#xA;            float sinTheta = sqrt(r0);&#xA;            float cosTheta = sqrt(1-r0);&#xA;            &#xA;            float phi = 2.0 * M_PI_F * r1;&#xA;            &#xA;            float x = sinTheta * cos(phi);&#xA;            float y = sinTheta * sin(phi);&#xA;            float z = cosTheta;&#xA;            &#xA;            wi = { x, y, z };&#xA;            wh = normalize(wo + wi); // not specular&#xA;            &#xA;        } else {&#xA;        &#xA;            auto a1 = roughness;&#xA;            auto a2 = a1 * a1;&#xA;            &#xA;            auto theta = acos(sqrt((1-r0) / ((a2-1)*r0+1)));&#xA;            auto phi = 2 * M_PI_F * r1;&#xA;            &#xA;            auto x = sin(theta) * cos(phi);&#xA;            auto y = sin(theta) * sin(phi);&#xA;            auto z = cos(theta) * 1;&#xA;            &#xA;            //wo = transpose(stw) * (ray.direction);&#xA;            wh = normalize( {x, y, z} );&#xA;            wi = reflect(wo, wh);&#xA;        }&#xA;        &#xA;        if (wi.z &amp;lt;= 0 || dot(wh, wi) &amp;lt;= 0) { return false; }&#xA;    &#xA;        auto D = NDF(wh, roughness);&#xA;        auto G = GX(wo, wi, roughness);&#xA;        auto F = FX(wi, wh, albedo, metallic);&#xA;        &#xA;        float denominator = 4.0f * abs(wo.z * wi.z);&#xA;        &#xA;        auto specular = D * G * F / max(FLT_MIN, denominator);&#xA;        &#xA;        auto diffuse = albedo / M_PI_F;&#xA;        &#xA;        auto kS = F;&#xA;        auto kD = (1 - metallic) * (1.0f - kS);&#xA;&#xA;        ray = Ray(hitRecord.p, stw * wi);&#xA;        scatRecord.attenuation = (kD * diffuse + specular) * ao;&#xA;        &#xA;        //auto pdf = PDF(wh, roughness);&#xA;        //scatRecord.attenuation /= abs(pdf);&#xA;        &#xA;        return true;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Normal Distribution Function&#xA;float NDF(const thread float3&amp;amp; h, float roughness) {&#xA;  //  GGX / Trowbridge-Reitz&#xA;  &#xA;  float a1 = roughness;&#xA;  float a2 = a1 * a1;&#xA;  float NoH = abs(h.z);&#xA;  &#xA;  float d = (NoH * a2 - NoH) * NoH + 1;&#xA;  return a2 / (d * d * M_PI_F);&#xA;}&#xA;&#xA;// Geometry Function&#xA;float GX(const thread float3&amp;amp; wo, const thread float3&amp;amp; wi, float roughness) {&#xA;  // Schlick, remap roughness and k&#xA;&#xA;  if (wo.z &amp;gt;= 0 || wi.z &amp;lt;= 0)&#xA;      return 0;&#xA;&#xA;  float k = pow(roughness + 1, 2) / 8.f;&#xA;  &#xA;  k = pow(roughness, 4);&#xA;  &#xA;  float G1_wo = wo.z / (wo.z*(1 - k) + k);&#xA;  float G1_wi = wi.z / (wi.z*(1 - k) + k);&#xA;  return G1_wo * G1_wi;&#xA;}&#xA;&#xA;// Fresnel&#xA;float3 FX(const thread float3&amp;amp; wi, const thread float3&amp;amp; h, const thread float3 albedo, float metallic) {&#xA;  // Schlick’s approximation&#xA;  // use a Spherical Gaussian approximation to replace the power.&#xA;  // slightly more efficient to calculate and the difference is imperceptible&#xA;  &#xA;  float3 F0 = mix(float3(0.04f), albedo, metallic);&#xA;  float HoWi = dot(h, wi);&#xA;  return F0 + (float3(1.0f) - F0) * pow(2.0f, (-5.55473f * HoWi - 6.98316f) * HoWi);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13874" LastActivityDate="2020-09-02T21:06:17.673" Title="Ray Tracing, why does the GGX make my rendering result darker and darker for each frame?" Tags="&lt;raytracing&gt;&lt;pbr&gt;&lt;metal&gt;&lt;ggx&gt;" AnswerCount="2" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="10177" PostTypeId="1" CreationDate="2020-09-01T09:37:00.923" Score="0" ViewCount="148" Body="&lt;p&gt;I'm using the ZED 2 camera, and although the API provides a means of getting a point cloud position from a specific pixel, for my project I need to be able to perform this calculation myself from the depth pass alone. According to the documentation:&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;&amp;quot;Depth maps captured by the ZED store a distance value (Z) for each pixel (X, Y) in the image. The distance is expressed in metric units (meters for example) and calculated from the back of the left eye of the camera to the scene object.&amp;quot;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;So my question is, given a pixel index (therefore UV value) and a depth value, how can I work out the world location of the pixel/point? I suspect this has something to do with inverting a matrix (camera? projection?), and I have the following calibration values for the left sensor of the camera:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;fx: 1057.1   fy: 1056.71&#xA;cx: 979.01   cy: 531.934&#xA;k1: -0.0412   k2: 0.0095   k3: -0.0047&#xA;p1: -0.0005   p2: -0.0002&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;But matrices are far from my strong suit so I'm struggling to understand how to turn the above information into a matrix which I could use to extrapolate the position. Can anyone help me?&lt;/p&gt;&#xA;" OwnerUserId="13904" LastActivityDate="2021-05-30T03:02:25.130" Title="How to calculate position from depth pass of the ZED camera?" Tags="&lt;matrix&gt;&lt;camera-matrix&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10179" PostTypeId="2" ParentId="10160" CreationDate="2020-09-01T15:21:56.833" Score="0" Body="&lt;p&gt;In Lambertion::scatter there is a comment about attenuating light based on distance.&lt;/p&gt;&#xA;&lt;p&gt;For a raytracer this is not required as the distribution of rays themselves cause attenuation over distance.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2020-09-01T15:21:56.833" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10180" PostTypeId="1" AcceptedAnswerId="10181" CreationDate="2020-09-01T19:49:47.657" Score="4" ViewCount="68" Body="&lt;p&gt;Apologies if this is a dumb question... but given four arbitrary (non-coplanar) points in 3D space, there are obviously two different ways to triangulate the quad that they form. One triangulation may produce much more natural results than the other- but how can I determine which one to pick?&lt;/p&gt;&#xA;&lt;p&gt;Context: I’m doing Dual Contouring, and the quad forms part of an isosurface. I have access to the hermite/gradient data at that point.&lt;/p&gt;&#xA;" OwnerUserId="13696" LastActivityDate="2020-09-07T08:35:53.553" Title="How to decide which way to triangulate a quad?" Tags="&lt;3d&gt;&lt;triangulation&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10181" PostTypeId="2" ParentId="10180" CreationDate="2020-09-01T20:03:27.107" Score="4" Body="&lt;p&gt;A simple heuristic that many 3D content creation apps use is to split along the shorter of the two diagonals of the quad. This generally seems to work pretty well. It minimizes the appearance of long, skinny triangles, which are generally undesirable both for visual and performance reasons.&lt;/p&gt;&#xA;&lt;p&gt;See this article: &lt;a href=&quot;https://noahalzayer.com/2017/04/11/deformation-and-triangulation-in-maya/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Deformation and Triangulation in Maya&lt;/a&gt; for some further discussion. In particular if you have a dynamically deforming mesh, you ideally want to retriangulate the quads based on the deformed geometry each frame, or you can get some pretty wonky artifacts if you stick with a fixed triangulation:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/egHDt.png&quot; alt=&quot;dynamic retriangulation based on shortest diagonal vs fixed triangulation&quot; /&gt;&lt;br /&gt;&#xA;(image from the above linked blog post)&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-01T20:09:10.710" LastActivityDate="2020-09-01T20:09:10.710" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10182" PostTypeId="2" ParentId="10177" CreationDate="2020-09-02T01:47:43.637" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://www.stereolabs.com/assets/datasheets/zed2-camera-datasheet.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;zed2-camera-datasheet.pdf&lt;/a&gt; tells the&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Baseline is 120mm&lt;/li&gt;&#xA;&lt;li&gt;Focal length is 2.12mm&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;such that based on the fx,fy, you can find the pixel to mm ratio.&lt;/p&gt;&#xA;&lt;p&gt;You have the local length, baseline, the object coordinates, the principle coordinates. The triangulation is formed, and the depth estimation can be found using ZED depth formula&lt;/p&gt;&#xA;" OwnerUserId="13838" LastActivityDate="2020-09-02T01:47:43.637" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10183" PostTypeId="1" CreationDate="2020-09-02T04:47:26.980" Score="0" ViewCount="31" Body="&lt;p&gt;i have this bresenham's code, but actually this work only to some cases, how can i complete to any cases?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    this.dx = dx;&#xA;    this.dy = dy;&#xA;&#xA;    int m = dy / dx;&#xA;    if (dx &amp;gt;= 0 &amp;amp;&amp;amp; dy &amp;gt;= 0) {&#xA;        if (m &amp;lt; 1) {&#xA;            stepX = 1;&#xA;            stepY = 1;&#xA;            d = 2 * dy - dx;&#xA;            de = 2 * dy;&#xA;            dne = 2 * (dy - dx);&#xA;        } else {&#xA;            stepX = 1;&#xA;            stepY = 1;&#xA;            d = dy + (2 * (-dx));&#xA;            de = 2 * (-dx);&#xA;            dne = 2 * (dy - dx);&#xA;            de = -de;&#xA;            dne = -dne;&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;will be that repeat this code 3 times over?&#xA;to following cases?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;if (dx &amp;gt; 0 &amp;amp;&amp;amp; dy &amp;lt; 0)&#xA;if (dx &amp;lt;= 0 &amp;amp;&amp;amp; dy &amp;lt;= 0)&#xA;if (dx &amp;lt; 0 &amp;amp;&amp;amp; dy &amp;gt; 0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;actually only works for the first quadrant&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;       +&#xA;       +   here worked&#xA;       +&#xA;+++++++++++++++++&#xA;       +&#xA;       +&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13909" LastEditorUserId="13909" LastEditDate="2020-09-02T05:38:32.160" LastActivityDate="2020-09-02T05:38:32.160" Title="How can i use bresemhan to any cases?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10184" PostTypeId="1" CreationDate="2020-09-02T05:34:40.040" Score="1" ViewCount="61" Body="&lt;p&gt;How can I remodel a line, i want to draw first a line then i want to remodel the line such as in paint software, which algorithm should I use? Are there several algorithms to achieve this? i am using the bresemhan algorithm&lt;/p&gt;&#xA;&lt;p&gt;For example i have this line, but when i will click in the center and with the mouse i want to pull&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/n7LXS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/n7LXS.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13909" LastEditorUserId="13909" LastEditDate="2020-09-02T14:40:14.573" LastActivityDate="2020-09-02T14:40:14.573" Title="How can i stretch a line?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10185" PostTypeId="1" CreationDate="2020-09-02T11:16:36.430" Score="2" ViewCount="277" Body="&lt;p&gt;in my application, I needed to detect collision between 2 3D objects. To make it simple I can represent a object as a bounding box. So actually the task reduced to detect collision between 2 boxes in 3D space. The problem that I cannot make these bounding boxes to be axis aligned.&#xA;The objects look like the following image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6uVLS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6uVLS.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Unfortunately all the algorithms I've found in the Internet suppose that all the boxes are axis-aligned. It seems to me that this is a common mathematical problem and can be solved using some well known algorithms. Unfortunately I'm not a mathematician so I would be very grateful if someone can offer a solution to this problem.&lt;/p&gt;&#xA;" OwnerUserId="13912" LastActivityDate="2020-09-02T14:28:46.693" Title="Detect collision for non axis-aligned bounding boxes" Tags="&lt;3d&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10186" PostTypeId="1" CreationDate="2020-09-02T11:44:10.013" Score="2" ViewCount="37" Body="&lt;p&gt;I am creating a 3D spherical curved display (only a part of a sphere). The camera usually is inside of this sphere. This display has texture coordinates. The image below shows the display with its texture coordinates.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3mTWM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3mTWM.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The method to generate the geometry (mesh) receives 4 parameters.&#xA;These parameters are direction vectors which are pointing at the corners of the display.&#xA;topLeftCorner, bottomLeftCorner, topRightCorner and bottomRightCorner.&lt;/p&gt;&#xA;&lt;p&gt;I calculated the position / normal / texture coordinates in the following way:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Eigen::Quaternionf topLeft(0,topLeftCorner.x(), topLeftCorner.y(), topLeftCorner.z());&#xA;Eigen::Quaternionf topRight(0,topRightCorner.x(), topRightCorner.y(), topRightCorner.z());&#xA;Eigen::Quaternionf bottomLeft(0,bottomLeftCorner.x(), bottomLeftCorner.y(), bottomLeftCorner.z());&#xA;Eigen::Quaternionf bottomRight(0,bottomRightCorner.x(), bottomRightCorner.y(), bottomRightCorner.z());&#xA;&#xA;//calculate vertexData&#xA;unsigned long long counter = 0;&#xA;for (int y = 0; y &amp;lt;= countSegmentsVertical; ++y)&#xA;{&#xA;    Eigen::Quaternionf slerpedQuaternionHorizontalLeft = bottomLeft.slerp(static_cast&amp;lt;float&amp;gt;(y) / static_cast&amp;lt;float&amp;gt;(countSegmentsVertical), topLeft);&#xA;    Eigen::Quaternionf slerpedQuaternionHorizontalRight = bottomRight.slerp(static_cast&amp;lt;float&amp;gt;(y) / static_cast&amp;lt;float&amp;gt;(countSegmentsVertical), topRight);&#xA;&#xA;    for (int x = 0; x &amp;lt;= countSegmentsHorizontal; ++x)&#xA;    {&#xA;        Eigen::Quaternionf slerpedQuaternionVertical = slerpedQuaternionHorizontalRight.slerp(static_cast&amp;lt;float&amp;gt;(x) / static_cast&amp;lt;float&amp;gt;(countSegmentsHorizontal),slerpedQuaternionHorizontalLeft);&#xA;        Eigen::Vector3f position = slerpedQuaternionVertical * Eigen::Vector3f(0,0,-1);&#xA;        position.normalize();&#xA;        position *= radius;&#xA;&#xA;        data[counter].positionX = position.x();&#xA;        data[counter].positionY = position.y();&#xA;        data[counter].positionZ = position.z();&#xA;        data[counter].normalX = -position.x()/m_radius;&#xA;        data[counter].normalY = -position.y()/m_radius;&#xA;        data[counter].normalZ = -position.z()/m_radius;&#xA;        data[counter].textureCoordinateU = 1 - static_cast&amp;lt;float&amp;gt;(x) / static_cast&amp;lt;float&amp;gt;(countSegmentsHorizontal);&#xA;        data[counter].textureCoordinateV = static_cast&amp;lt;float&amp;gt;(y) / static_cast&amp;lt;float&amp;gt;(countSegmentsVertical);&#xA;        counter++;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;short description:&lt;/strong&gt;&#xA;by slerping between topLeft and bottomLeft, I receive the left position (P0).&#xA;by slerping between topRight and bottomRight, I receive the right position (P1).&#xA;by slerping between left and right position, I receive the final position (P2).&#xA;The next image illustrates this&#xA;&lt;a href=&quot;https://i.stack.imgur.com/eZsgb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eZsgb.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;so far, everything is working fine.&#xA;Lets go to the problem:&#xA;Now I need to invert the problematic:&#xA;having the four corners and a 3D point on the sphere (P2 in world coordinates). Lets call this point P'.&#xA;The result should be the P2 texture coordinates.&lt;/p&gt;&#xA;&lt;p&gt;My idea is to invert both vertical slerps with an quaternion (P') which is not lying exactly between the corners.&#xA;If this is possible (I don't know), the next step would be to invert the horizontal slerp.&#xA;the result should be the texture coordinate P2.&lt;/p&gt;&#xA;&lt;p&gt;I am not sure if this is possible in this way, so maybe there is an other maybe easier way to calculate the point P' in texture coordinates.&lt;/p&gt;&#xA;&lt;p&gt;BTW: The four corner vectors which form the geometry can be totally different than this image shows.&#xA;So there is no way to say &amp;quot;Okay, in world coordinates you first can look at the Y coordinate and somehow match the value to the corners&amp;quot;, because this display can be rotated around each axis, scale in horizontal and vertical angle or even don't be &amp;quot;rectangular&amp;quot; at all.&lt;/p&gt;&#xA;" OwnerUserId="13273" LastEditorUserId="13273" LastEditDate="2020-09-02T15:39:47.897" LastActivityDate="2020-09-02T15:39:47.897" Title="multiple Quaternion slerp inverse to calculate relative coordinates" Tags="&lt;c++&gt;&lt;eigen&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10187" PostTypeId="2" ParentId="10185" CreationDate="2020-09-02T12:23:22.900" Score="3" Body="&lt;p&gt;Write two functions: (1) point in 3D box, and (2) segment intersect rectangle in 3D. Point in box is a conjunction of six left-of-plane checks. For (2), solve for the point of intersection between the line containing the segment and the plane containing the rectangle. Then check if that point is on the segment, and if so, in the rectangle.&lt;/p&gt;&#xA;&lt;p&gt;Then box &lt;span class=&quot;math-container&quot;&gt;$B_1$&lt;/span&gt; intersects box &lt;span class=&quot;math-container&quot;&gt;$B_2$&lt;/span&gt; if any corner of &lt;span class=&quot;math-container&quot;&gt;$B_1$&lt;/span&gt; is inside &lt;span class=&quot;math-container&quot;&gt;$B_2$&lt;/span&gt;, or if any of the &lt;span class=&quot;math-container&quot;&gt;$12$&lt;/span&gt; edges of &lt;span class=&quot;math-container&quot;&gt;$B_1$&lt;/span&gt; intersects any of the &lt;span class=&quot;math-container&quot;&gt;$6$&lt;/span&gt; faces of &lt;span class=&quot;math-container&quot;&gt;$B_2$&lt;/span&gt;.&#xA;This can be sped up a bit by ordering the tests (for example, if no edge of &lt;span class=&quot;math-container&quot;&gt;$B_1$&lt;/span&gt; intersects a face of &lt;span class=&quot;math-container&quot;&gt;$B_2$&lt;/span&gt;, then you need only check one corner of &lt;span class=&quot;math-container&quot;&gt;$B_1$&lt;/span&gt; inside/outside &lt;span class=&quot;math-container&quot;&gt;$B_2$&lt;/span&gt;).&lt;/p&gt;&#xA;" OwnerUserId="4748" LastEditorUserId="4748" LastEditDate="2020-09-02T14:28:46.693" LastActivityDate="2020-09-02T14:28:46.693" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10188" PostTypeId="1" AcceptedAnswerId="10194" CreationDate="2020-09-02T16:01:52.080" Score="2" ViewCount="75" Body="&lt;p&gt;I am looking for a way to calculate the value of &lt;code&gt;t&lt;/code&gt; of quaternion SLERP by having three quaternions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Forward direction:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Eigen::Quaternionf q = q1.slerp(t, q2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;where &lt;code&gt;q&lt;/code&gt;, &lt;code&gt;q1&lt;/code&gt; and &lt;code&gt;q2&lt;/code&gt; are quaternions from the Eigen library. And &lt;code&gt;t&lt;/code&gt; is a float which interpolates between &lt;code&gt;q1&lt;/code&gt; and &lt;code&gt;q2&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I am interested in the backward calculation, where &lt;code&gt;q&lt;/code&gt;, &lt;code&gt;q1&lt;/code&gt; and &lt;code&gt;q2&lt;/code&gt; is given and the output is t.&lt;/p&gt;&#xA;&lt;p&gt;To make it easier all quaternions are normalized and also lying on the same plane which crosses the origin. See the illustration below:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qwYmt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qwYmt.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;q&lt;/code&gt;does &lt;strong&gt;NOT&lt;/strong&gt; need to be within &lt;code&gt;q1&lt;/code&gt; and &lt;code&gt;q2&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I found this link &lt;a href=&quot;https://math.stackexchange.com/questions/2346982/slerp-inverse-given-3-quaternions-find-t&quot;&gt;here&lt;/a&gt; but I don't know how to use that.&lt;/p&gt;&#xA;" OwnerUserId="13273" LastEditorUserId="2654" LastEditDate="2020-09-02T16:48:21.590" LastActivityDate="2020-09-05T00:44:00.940" Title="Compute the interpolation factor between the SLERP of 2 quaternions, given those quaternions and the SLERP result" Tags="&lt;eigen&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10189" PostTypeId="2" ParentId="10176" CreationDate="2020-09-02T17:57:42.323" Score="1" Body="&lt;p&gt;&lt;a href=&quot;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.htm&lt;/a&gt; - here is reference with different geometry shading equations&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://jcgt.org/published/0003/02/03/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://jcgt.org/published/0003/02/03/paper.pdf&lt;/a&gt; - paper explaining how G term works and on what assumptions it is build.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Looking again at your code, I'm not sure (based on first link to Karis blog) if your G term is calculated correctly.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;  float k = pow(roughness + 1, 2) / 8.f; &#xA;  k = pow(roughness, 4);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;You're overwritting &lt;strong&gt;k&lt;/strong&gt; with roughness^4, which doesn't fall into any Schlick equation that can be seen in Karis blog and if I recall correctly, I haven't seen that in any papers. Another note is, that you're passing &lt;em&gt;ω&lt;/em&gt;o and &lt;em&gt;ω&lt;/em&gt;i to your geometry function, but based on your comment that this is Schlick G and overall context, I think that you should use NoL and NoV (dot first pointToLight direction and then viewDir).&lt;/p&gt;&#xA;&lt;p&gt;I was trying to do my own image, but I found [Blinn 1977] paper which sums up how Smith G model works (take a look at figure 1) - &lt;a href=&quot;https://www.microsoft.com/en-us/research/wp-content/uploads/1977/01/p192-blinn.pdf#page=2&amp;amp;zoom=auto,-264,459&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.microsoft.com/en-us/research/wp-content/uploads/1977/01/p192-blinn.pdf#page=2&amp;amp;zoom=auto,-264,459&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Some time ago, I was playing a little with different D, F, G equations - &lt;a href=&quot;https://github.com/komilll/dxFramework/blob/master/dxFramework/Shaders/PS_BRDF.hlsl&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/komilll/dxFramework/blob/master/dxFramework/Shaders/PS_BRDF.hlsl&lt;/a&gt; - take a look at &lt;strong&gt;PS_BRDF.hlsl&lt;/strong&gt; and &lt;strong&gt;PS_BRDF_Helper.hlsl&lt;/strong&gt; for further reference. I was basing my equations on Karis blog, some are modified base on other papers e.g. Frostbite and Disney diffuse are based on respective papers if I recall correctly.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;I'm not sure if that's causing a problem, but it's worth fixing for sure. Also I don't think that you're using for summing frames&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;(previous_average * frame_count + current_color) / (frame_count + 1) &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;is correct, neither for uniform or importance GGX sampling. You should derive pdf in that case, it can be found in link that I've sent you before - &lt;a href=&quot;http://cwyman.org/code/dxrTutors/tutors/Tutor14/tutorial14.md.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://cwyman.org/code/dxrTutors/tutors/Tutor14/tutorial14.md.html&lt;/a&gt; - it's generally nice tutorial, with good step by step introduction to DXR.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-09-02T17:57:42.323" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10190" PostTypeId="2" ParentId="10176" CreationDate="2020-09-02T21:06:17.673" Score="0" Body="&lt;p&gt;Despite the discussion on &lt;code&gt;G&lt;/code&gt;, there are 2 major problems. Fix them will fix the problem.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Float16 is limited to 65504. When multiplied by a large frame number, it will get overflow and become a small number, then never came back.&#xA;&lt;a href=&quot;https://en.wikipedia.org/wiki/Half-precision_floating-point_format&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Half-precision_floating-point_format&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Vector &lt;code&gt;wo&lt;/code&gt; and &lt;code&gt;wi&lt;/code&gt; should be on the same hemisphere on normal direction. So one of them should be &lt;code&gt;reverse&lt;/code&gt; ray direction. Most documents I saw simply ignored this part. While, whatsoever this chapter from PBRT-v3 helped me figuring it out.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Reflection_Models/Microfacet_Models.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Reflection_Models/Microfacet_Models.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/bdsnA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/bdsnA.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13874" LastActivityDate="2020-09-02T21:06:17.673" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10191" PostTypeId="1" CreationDate="2020-09-03T07:46:42.393" Score="2" ViewCount="105" Body="&lt;p&gt;I am using the SAH-BVH from PBRT-v3, it works fine for triangle-mesh, especially for dense mesh.&lt;/p&gt;&#xA;&lt;p&gt;But here is a problem. If I added Cornell box while building the BVH tree, the BVH performance will drop to only 20% as before. The Cornell box is only 6 rectangles. Why does it behave in this way? Because it's a big box containing everything? How to improve it?&lt;/p&gt;&#xA;" OwnerUserId="13874" LastActivityDate="2020-09-03T07:46:42.393" Title="BVH works fine, but why does it slow down a lot when using Cornell Box? How to improve it?" Tags="&lt;raytracing&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="0" CommentCount="13" ContentLicense="CC BY-SA 4.0" />
  <row Id="10193" PostTypeId="1" CreationDate="2020-09-04T15:44:29.167" Score="1" ViewCount="89" Body="&lt;p&gt;What algorithm can i use to pull entere area?&lt;/p&gt;&#xA;&lt;p&gt;i have this image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xhsyf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xhsyf.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;are there many algorithms, which algorithm can you recommended me to implement?&lt;/p&gt;&#xA;&lt;p&gt;Edit 1:&lt;/p&gt;&#xA;&lt;p&gt;my square was builded with lines (bresenham), i want to move to up in the Y axis (i am working without libraries, only math and java, i am using putpixel(x,y))&lt;/p&gt;&#xA;&lt;p&gt;i want to create this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/i58Bh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/i58Bh.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13909" LastEditorUserId="13909" LastEditDate="2020-09-05T19:14:08.093" LastActivityDate="2020-09-05T19:14:08.093" Title="How can I pull up the whole area of the square?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="7" ClosedDate="2020-09-07T08:13:09.573" ContentLicense="CC BY-SA 4.0" />
  <row Id="10194" PostTypeId="2" ParentId="10188" CreationDate="2020-09-05T00:38:34.707" Score="2" Body="&lt;p&gt;We can do this mostly by measuring angles between the quaternions, with a bit of sign flip to get the orientations right. Angles between normalized quaternions are given by the arccos of their dot product (as a 4D vector).&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;t = \frac{\arccos(q_1 \cdot q)}{\arccos(q_1 \cdot q_2)} \ \text{sign}\bigl(q \cdot [q_2 - (q_1 \cdot q_2) q_1]\bigr)&#xA;$$&lt;/span&gt;&#xA;The first factor is measuring the angle from &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; as a fraction of the angle from &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$q_2$&lt;/span&gt;. This ensures that &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; will be 0 at &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt; and 1 at &lt;span class=&quot;math-container&quot;&gt;$q_2$&lt;/span&gt;. The other factor ensures that &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; increases as you move from &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt; toward &lt;span class=&quot;math-container&quot;&gt;$q_2$&lt;/span&gt; and goes negative on the other side. The quantity in brackets is the projection of &lt;span class=&quot;math-container&quot;&gt;$q_2$&lt;/span&gt; on the (hyper)plane perpendicular to &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt;, then we're dotting &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt; with that to decide which side of the circle we're on.&lt;/p&gt;&#xA;&lt;p&gt;Note that the point where &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; swaps from negative to positive will be the point opposite &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt; on the circle—not a point centered across from &lt;span class=&quot;math-container&quot;&gt;$q_1$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$q_2$&lt;/span&gt; as your diagram has it.&lt;/p&gt;&#xA;&lt;p&gt;(Also, it's worth noting that this boils down to essentially the same thing as the logarithm solution in the other answer. Their factor &lt;span class=&quot;math-container&quot;&gt;$\check p/\|\check p\|$&lt;/span&gt; corresponds to our sign factor: all the quaternions in the problem are in the same plane and so will have &lt;span class=&quot;math-container&quot;&gt;$\check p$&lt;/span&gt; along the same axis; the only thing that can differ between the normalized &lt;span class=&quot;math-container&quot;&gt;$\check p$&lt;/span&gt;s is the sign.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-05T00:44:00.940" LastActivityDate="2020-09-05T00:44:00.940" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10195" PostTypeId="2" ParentId="10180" CreationDate="2020-09-07T08:35:53.553" Score="3" Body="&lt;p&gt;One other, albeit more expensive approach, is to subdivide your quad into 4 triangles by putting a point at the centre of each quad. There are some advantages to this in that:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;It will be more temporarily stable. If your quad vertices are moving and you were otherwise using the &amp;quot;shortest diagonal&amp;quot; approach Nathan has suggested, the tessellation will change pattern every now and then.  Maybe this won't matter &lt;em&gt;too&lt;/em&gt; much geometrically, but remember that the UV texture coordinates are also linearly interpolated in world space (obviously hyperbolically in screen space) and so the texturing can jump.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If the quad is quite distorted (e.g non-planar or non-convex),  I think the 4xtri approach will look much better than either of the two 2xtri options&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If you instead are just chopping into triangles based on the order of the vertices of your quad, i.e. ABCD always becomes ABC and CDA, then if by chance the modelling package spits out another &amp;quot;identical&amp;quot; quad but ordered as BCDA, then the rendered versions won't match.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Of course, the downside is that you have 2x the number of vertices and triangles, but it may be worth considering.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2020-09-07T08:35:53.553" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10196" PostTypeId="2" ParentId="9354" CreationDate="2020-09-08T12:21:41.167" Score="0" Body="&lt;p&gt;For anyone wondering how to deal with it, please refer to mjp (Matt Pettineo) github - &lt;a href=&quot;https://github.com/TheRealMJP/DXRPathTracer/blob/master/SampleFramework12/v1.02/Graphics/Profiler.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/TheRealMJP/DXRPathTracer/blob/master/SampleFramework12/v1.02/Graphics/Profiler.cpp&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;MJP's code is DX12. For DX11, you can refer to my github - &lt;a href=&quot;https://github.com/komilll/dxFramework/blob/master/dxFramework/Profiler.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/komilll/dxFramework/blob/master/dxFramework/Profiler.cpp&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In both DX11 and DX12, you basically just creates timestamps at the beginning and at the end of some portion of code. Then you have to resolve it, based on GPU speed. GPU might work with different clock frequency based on current workload. When you have a full PBR engine with shadow or SSAO, you should already have no problem with changing clock. However, if you're just starting creating your engine/framework, keep in mind that time to execute might not be precise, because you're not using full GPU power.&lt;/p&gt;&#xA;&lt;p&gt;In DX12 there is &lt;strong&gt;ID3D12Device::SetStablePowerState&lt;/strong&gt; but I've seen multiple times that people are recommending not to use it. Maybe there are some use cases, but for typical hobby usage, I won't bother with that.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-09-08T16:46:11.357" LastActivityDate="2020-09-08T16:46:11.357" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10197" PostTypeId="1" CreationDate="2020-09-08T13:06:38.543" Score="2" ViewCount="51" Body="&lt;p&gt;I have a problem with RTPSO creation. Using local root signatures for each of rgs (ray generation shader), chs (closest hit), miss is working correctly. However, for performance sake, I want to use global root signature with dummy/empty local root signatures.&lt;/p&gt;&#xA;&lt;p&gt;Below code works correctly:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void RaytracingResources::CreateRTPSO(ID3D12Device5* device, size_t maxPayloadSize)&#xA;{&#xA;    // Need 11 subobjects:&#xA;    // 1 for RGS program&#xA;    // 1 for Miss program&#xA;    // 1 for CHS program&#xA;    // 1 for AHS program&#xA;    // 1 for Hit Group&#xA;    // 2 for RayGen Root Signature (root-signature and association)&#xA;    // 2 for Shader Config (config and association)&#xA;    // 1 for Global Root Signature&#xA;    // 1 for Pipeline Config    &#xA;    UINT index = 0;&#xA;    std::vector&amp;lt;D3D12_STATE_SUBOBJECT&amp;gt; subobjects;&#xA;    size_t size = 0;&#xA;    size += 1; // rgs&#xA;    for (auto&amp;amp; hitGroup : m_hitGroups)&#xA;    {&#xA;        size += 2; // chs, miss&#xA;        size += (hitGroup.hitShader.ahs.name != nullptr) ? 1 : 0; // ahs&#xA;        size += 1; // hit group&#xA;        size += 2; // payload + association&#xA;        size += 2; // local root + association&#xA;    }&#xA;    size += 3; // global root + local root + pipeline config&#xA;    subobjects.resize(size);&#xA;&#xA;    ID3D12RootSignature* dummyLocalRootSignature;&#xA;    ID3D12RootSignature* dummyGlobalRootSignature;&#xA;    // Create dummy global and local root signature&#xA;    {&#xA;        HRESULT hr = 0;&#xA;        D3D12_ROOT_SIGNATURE_DESC rootDesc = {};&#xA;        rootDesc.NumParameters = 0;&#xA;        rootDesc.pParameters = nullptr;&#xA;        rootDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_NONE;&#xA;        ID3DBlob* serializedRootSignature;&#xA;        ID3DBlob* error;&#xA;&#xA;        // Create the global root signature&#xA;        ThrowIfFailed(D3D12SerializeRootSignature(&amp;amp;rootDesc, D3D_ROOT_SIGNATURE_VERSION_1,&#xA;            &amp;amp;serializedRootSignature, &amp;amp;error));&#xA;&#xA;        ThrowIfFailed(device-&amp;gt;CreateRootSignature(0, serializedRootSignature-&amp;gt;GetBufferPointer(),&#xA;            serializedRootSignature-&amp;gt;GetBufferSize(),&#xA;            IID_PPV_ARGS(&amp;amp;dummyGlobalRootSignature)));&#xA;&#xA;        serializedRootSignature-&amp;gt;Release();&#xA;&#xA;        rootDesc.Flags = D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE;&#xA;        // Create the local root signature, reusing the same descriptor but altering the creation flag&#xA;        ThrowIfFailed(D3D12SerializeRootSignature(&amp;amp;rootDesc, D3D_ROOT_SIGNATURE_VERSION_1,&#xA;            &amp;amp;serializedRootSignature, &amp;amp;error));&#xA;&#xA;        ThrowIfFailed(device-&amp;gt;CreateRootSignature(0, serializedRootSignature-&amp;gt;GetBufferPointer(),&#xA;            serializedRootSignature-&amp;gt;GetBufferSize(),&#xA;            IID_PPV_ARGS(&amp;amp;dummyLocalRootSignature)));&#xA;&#xA;        serializedRootSignature-&amp;gt;Release();&#xA;    }&#xA;&#xA;#pragma region HitGroup creation - 1&#xA;    {&#xA;        HitGroup hitGroup = m_hitGroups[0];&#xA;        // Add state subobject for the RGS&#xA;        {&#xA;            D3D12_EXPORT_DESC rgsExportDesc = { hitGroup.rayGenShader.name, nullptr, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC rgsLibDesc = {};&#xA;            rgsLibDesc.DXILLibrary.BytecodeLength = hitGroup.rayGenShader.blob-&amp;gt;GetBufferSize();&#xA;            rgsLibDesc.DXILLibrary.pShaderBytecode = hitGroup.rayGenShader.blob-&amp;gt;GetBufferPointer();&#xA;            rgsLibDesc.NumExports = 1;&#xA;            rgsLibDesc.pExports = &amp;amp;rgsExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT rgs = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;rgsLibDesc };&#xA;            subobjects[index++] = rgs;&#xA;        }&#xA;&#xA;        //Add state subobject for the Miss shader&#xA;        {&#xA;            D3D12_EXPORT_DESC msExportDesc = { hitGroup.missShader.name, hitGroup.missShader.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC msLibDesc = {};&#xA;            msLibDesc.DXILLibrary.BytecodeLength = hitGroup.missShader.blob-&amp;gt;GetBufferSize();&#xA;            msLibDesc.DXILLibrary.pShaderBytecode = hitGroup.missShader.blob-&amp;gt;GetBufferPointer();&#xA;            msLibDesc.NumExports = 1;&#xA;            msLibDesc.pExports = &amp;amp;msExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT ms = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;msLibDesc };&#xA;            subobjects[index++] = ms;&#xA;        }&#xA;&#xA;        // Add state subobject for the Closest Hit shader&#xA;        {&#xA;            D3D12_EXPORT_DESC chsExportDesc = { hitGroup.hitShader.chs.name, hitGroup.hitShader.chs.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC chsLibDesc = {};&#xA;            chsLibDesc.DXILLibrary.BytecodeLength = hitGroup.hitShader.chs.blob-&amp;gt;GetBufferSize();&#xA;            chsLibDesc.DXILLibrary.pShaderBytecode = hitGroup.hitShader.chs.blob-&amp;gt;GetBufferPointer();&#xA;            chsLibDesc.NumExports = 1;&#xA;            chsLibDesc.pExports = &amp;amp;chsExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT chs = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;chsLibDesc };&#xA;            subobjects[index++] = chs;&#xA;        }&#xA;&#xA;        // Add state subobject for the Any Hit shader&#xA;        if (hitGroup.hitShader.ahs.name != nullptr)&#xA;        {&#xA;            D3D12_EXPORT_DESC ahsExportDesc = { hitGroup.hitShader.ahs.name, hitGroup.hitShader.ahs.exportToRename, D3D12_EXPORT_FLAG_NONE };&#xA;&#xA;            D3D12_DXIL_LIBRARY_DESC ahsLibDesc = {};&#xA;            ahsLibDesc.DXILLibrary.BytecodeLength = hitGroup.hitShader.ahs.blob-&amp;gt;GetBufferSize();&#xA;            ahsLibDesc.DXILLibrary.pShaderBytecode = hitGroup.hitShader.ahs.blob-&amp;gt;GetBufferPointer();&#xA;            ahsLibDesc.NumExports = 1;&#xA;            ahsLibDesc.pExports = &amp;amp;ahsExportDesc;&#xA;&#xA;            D3D12_STATE_SUBOBJECT ahs = { D3D12_STATE_SUBOBJECT_TYPE_DXIL_LIBRARY, &amp;amp;ahsLibDesc };&#xA;            subobjects[index++] = ahs;&#xA;        }&#xA;&#xA;        // Add a state subobject for the hit group&#xA;        {&#xA;            D3D12_HIT_GROUP_DESC hitGroupDesc = {};&#xA;            hitGroupDesc.ClosestHitShaderImport = hitGroup.hitShader.chs.name;&#xA;            if (hitGroup.hitShader.ahs.name != nullptr) hitGroupDesc.AnyHitShaderImport = hitGroup.hitShader.ahs.name;&#xA;            hitGroupDesc.HitGroupExport = hitGroup.hitGroupName;&#xA;&#xA;            D3D12_STATE_SUBOBJECT hitGroup = { D3D12_STATE_SUBOBJECT_TYPE_HIT_GROUP, &amp;amp;hitGroupDesc };&#xA;            subobjects[index++] = hitGroup;&#xA;        }&#xA;&#xA;        // Add a state subobject for the shader payload configuration&#xA;        {&#xA;            D3D12_RAYTRACING_SHADER_CONFIG shaderDesc = { static_cast&amp;lt;UINT&amp;gt;(maxPayloadSize), D3D12_RAYTRACING_MAX_ATTRIBUTE_SIZE_IN_BYTES };&#xA;            D3D12_STATE_SUBOBJECT shaderConfigObject = { D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_SHADER_CONFIG, &amp;amp;shaderDesc };&#xA;            subobjects[index++] = shaderConfigObject;&#xA;        }&#xA;&#xA;        // Create a list of the shader export names that use the payload&#xA;        {&#xA;            D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION shaderPayloadAssociation = {};&#xA;            if (hitGroup.hitShader.ahs.name != nullptr) {&#xA;                const WCHAR* shaderExports[] = { hitGroup.rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name, hitGroup.hitShader.ahs.name };&#xA;                shaderPayloadAssociation = { &amp;amp;subobjects[(index - 1)], _countof(shaderExports), shaderExports };&#xA;            }&#xA;            else {&#xA;                const WCHAR* shaderExports[] = { hitGroup.rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name };&#xA;                shaderPayloadAssociation = { &amp;amp;subobjects[(index - 1)], _countof(shaderExports), shaderExports };&#xA;            }&#xA;&#xA;            D3D12_STATE_SUBOBJECT shaderPayloadAssociationObject = { D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION, &amp;amp;shaderPayloadAssociation };&#xA;            subobjects[index++] = shaderPayloadAssociationObject;&#xA;        }&#xA;&#xA;        // Add a state subobject for the shared root signature &#xA;        {&#xA;            D3D12_STATE_SUBOBJECT rayGenRootSigObject = { D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE, &amp;amp;hitGroup.rayGenShader.pRootSignature};&#xA;            subobjects[index++] = rayGenRootSigObject;&#xA;        }&#xA;&#xA;        // Create a list of the shader export names that use the root signature&#xA;        {&#xA;            D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION rayGenShaderRootSigAssociation = {};&#xA;            if (hitGroup.hitShader.ahs.name != nullptr)&#xA;            {&#xA;                const WCHAR* rootSigExports[] = { m_hitGroups[0].rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name, hitGroup.hitShader.ahs.name };&#xA;                rayGenShaderRootSigAssociation = { &amp;amp;subobjects[(index - 1)], _countof(rootSigExports), rootSigExports };&#xA;            }&#xA;            else&#xA;            {&#xA;                const WCHAR* rootSigExports[] = { hitGroup.rayGenShader.name, hitGroup.missShader.name, hitGroup.hitShader.chs.name };&#xA;                rayGenShaderRootSigAssociation = { &amp;amp;subobjects[(index - 1)], _countof(rootSigExports), rootSigExports };&#xA;            }&#xA;&#xA;            D3D12_STATE_SUBOBJECT rayGenShaderRootSigAssociationObject = { D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION, &amp;amp;rayGenShaderRootSigAssociation };&#xA;            subobjects[index++] = rayGenShaderRootSigAssociationObject;&#xA;        }&#xA;    }&#xA;#pragma endregion&#xA;&#xA;&#xA;&#xA;    // Setup global root signature&#xA;    {&#xA;        D3D12_STATE_SUBOBJECT globalRootSig = { D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE, &amp;amp;dummyGlobalRootSignature };&#xA;        subobjects[index++] = globalRootSig;&#xA;    }&#xA;&#xA;    // The pipeline construction always requires an empty local root signature&#xA;    {&#xA;        D3D12_STATE_SUBOBJECT localRootSig = { D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE, &amp;amp;dummyLocalRootSignature };&#xA;        subobjects[index++] = localRootSig;&#xA;    }&#xA;&#xA;    // Add a state subobject for the ray tracing pipeline config&#xA;    {&#xA;        D3D12_RAYTRACING_PIPELINE_CONFIG pipelineConfig = { 2 }; // Max Trace Recursion Depth&#xA;        D3D12_STATE_SUBOBJECT pipelineConfigObject = { D3D12_STATE_SUBOBJECT_TYPE_RAYTRACING_PIPELINE_CONFIG, &amp;amp;pipelineConfig };&#xA;        subobjects[index++] = pipelineConfigObject; &#xA;    }&#xA;&#xA;    // Finish rtpso creation and store in variable&#xA;    {&#xA;        // Describe RTPSO&#xA;        D3D12_STATE_OBJECT_DESC pipelineDesc = { D3D12_STATE_OBJECT_TYPE_RAYTRACING_PIPELINE, static_cast&amp;lt;UINT&amp;gt;(subobjects.size()), subobjects.data() };&#xA;&#xA;        // Create the RT Pipeline State Object (RTPSO) / Get the RTPSO properties&#xA;        ThrowIfFailed(device-&amp;gt;CreateStateObject(&amp;amp;pipelineDesc, IID_PPV_ARGS(&amp;amp;m_rtpso)));&#xA;        ThrowIfFailed(m_rtpso-&amp;gt;QueryInterface(IID_PPV_ARGS(&amp;amp;m_rtpsoInfo)));&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However, replacing&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Setup global root signature&#xA;{&#xA;    D3D12_STATE_SUBOBJECT globalRootSig = { D3D12_STATE_SUBOBJECT_TYPE_GLOBAL_ROOT_SIGNATURE, &amp;amp;dummyGlobalRootSignature };&#xA;    subobjects[index++] = globalRootSig;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;with local signature from first code snippet that I've compiled with flag D3D12_ROOT_SIGNATURE_FLAG_NONE instead of D3D12_ROOT_SIGNATURE_FLAG_LOCAL_ROOT_SIGNATURE. Local signatures for:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    // Add a state subobject for the shared root signature &#xA;    {&#xA;        D3D12_STATE_SUBOBJECT rayGenRootSigObject = { D3D12_STATE_SUBOBJECT_TYPE_LOCAL_ROOT_SIGNATURE, &amp;amp;hitGroup.rayGenShader.pRootSignature };&#xA;        subobjects[index++] = rayGenRootSigObject;&#xA;    }&#xA;&#xA;    // Create a list of the shader export names that use the root signature&#xA;    {&#xA;        D3D12_SUBOBJECT_TO_EXPORTS_ASSOCIATION rayGenShaderRootSigAssociation = {};&#xA;        if (hitGroup.hitShader.ahs.name != nullptr)&#xA;        {&#xA;            const WCHAR* rootSigExports[] = { hitGroup.missShader.name, hitGroup.hitShader.chs.name, hitGroup.hitShader.ahs.name };&#xA;            rayGenShaderRootSigAssociation = { &amp;amp;subobjects[(index - 1)], _countof(rootSigExports), rootSigExports };&#xA;        }&#xA;        else&#xA;        {&#xA;            const WCHAR* rootSigExports[] = { hitGroup.missShader.name, hitGroup.hitShader.chs.name };&#xA;            rayGenShaderRootSigAssociation = { &amp;amp;subobjects[(index - 1)], _countof(rootSigExports), rootSigExports };&#xA;        }&#xA;&#xA;        D3D12_STATE_SUBOBJECT rayGenShaderRootSigAssociationObject = { D3D12_STATE_SUBOBJECT_TYPE_SUBOBJECT_TO_EXPORTS_ASSOCIATION, &amp;amp;rayGenShaderRootSigAssociation };&#xA;        subobjects[index++] = rayGenShaderRootSigAssociationObject;&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;are replaced with dummy local signatures. However, every program run is causing error of device removal:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;D3D12: Removing Device.&#xA;D3D12 ERROR: ID3D12Device::RemoveDevice: Device removal has been triggered for the following reason (DXGI_ERROR_DEVICE_HUNG: The Device took an unreasonable amount of time to execute its commands, or the hardware crashed/hung. As a result, the TDR (Timeout Detection and Recovery) mechanism has been triggered. The current Device Context was executing commands when the hang occurred. The application may want to respawn and fallback to less aggressive use of the display hardware). [ EXECUTION ERROR #232: DEVICE_REMOVAL_PROCESS_AT_FAULT]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Commenting out &lt;strong&gt;TraceRay(...)&lt;/strong&gt; from hlsl is causing program to continue running without causing any errors. Is there problem with my understanding of binding global root signature?&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-09-08T13:06:38.543" Title="Global root signature crash" Tags="&lt;raytracing&gt;&lt;c++&gt;&lt;directx12&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10198" PostTypeId="1" AcceptedAnswerId="10211" CreationDate="2020-09-08T17:00:59.060" Score="3" ViewCount="183" Body="&lt;p&gt;I managed to create code, working correctly as Texture2DArray in hlsl by using single ID3D12Resource and binding it as D3D12_SRV_DIMENSION_TEXTURE2DARRAY with constant array size.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;std::pair&amp;lt;ComPtr&amp;lt;ID3D12Resource&amp;gt;, D3D12_SUBRESOURCE_DATA&amp;gt; ModelClass::GetTextureFromModel(const aiScene* scene, std::string filename, ComPtr&amp;lt;ID3D12Device2&amp;gt; device, ComPtr&amp;lt;ID3D12GraphicsCommandList4&amp;gt; commandList, int index)&#xA;{&#xA;    D3D12_SUBRESOURCE_DATA textureDataSingle;&#xA;    std::unique_ptr&amp;lt;uint8_t[]&amp;gt; decodedData;&#xA;    ComPtr&amp;lt;ID3D12Resource&amp;gt; texture;&#xA;    m_uploadHeaps.push_back({});&#xA;&#xA;    std::string s = std::regex_replace(filename, std::regex(&amp;quot;\\\\&amp;quot;), &amp;quot;/&amp;quot;);&#xA;&#xA;    std::wstring ws(s.begin(), s.end());&#xA;    ThrowIfFailed(LoadWICTextureFromFileEx(device.Get(), ws.c_str(), 0, D3D12_RESOURCE_FLAG_NONE, WIC_LOADER_FORCE_RGBA32, texture.ReleaseAndGetAddressOf(), decodedData, textureDataSingle));&#xA;&#xA;    const UINT64 uploadBufferSize = GetRequiredIntermediateSize(texture.Get(), 0, 1);&#xA;&#xA;    // uploadHeap must outlive this function - until command list is closed&#xA;    ThrowIfFailed(device-&amp;gt;CreateCommittedResource(&#xA;        &amp;amp;CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_UPLOAD),&#xA;        D3D12_HEAP_FLAG_NONE,&#xA;        &amp;amp;CD3DX12_RESOURCE_DESC::Buffer(uploadBufferSize),&#xA;        D3D12_RESOURCE_STATE_GENERIC_READ,&#xA;        nullptr,&#xA;        IID_PPV_ARGS(&amp;amp;m_uploadHeaps[m_uploadHeaps.size() - 1])&#xA;    ));&#xA;&#xA;    UpdateSubresources(commandList.Get(), texture.Get(), m_uploadHeaps[m_uploadHeaps.size() - 1].Get(), 0, 0, 1, &amp;amp;textureDataSingle);&#xA;&#xA;    if (texture-&amp;gt;GetDesc().Width == 128 &amp;amp;&amp;amp; texture-&amp;gt;GetDesc().Height == 128)&#xA;    {&#xA;        commandList-&amp;gt;ResourceBarrier(1, &amp;amp;CD3DX12_RESOURCE_BARRIER::Transition(texture.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE));&#xA;&#xA;        D3D12_TEXTURE_COPY_LOCATION dst{};&#xA;        dst.pResource = m_diffuseTextures[index].Get();&#xA;        dst.Type = D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX;&#xA;        dst.SubresourceIndex = index;&#xA;&#xA;        D3D12_TEXTURE_COPY_LOCATION src{};&#xA;        src.pResource = texture.Get();&#xA;&#xA;        commandList-&amp;gt;CopyTextureRegion(&amp;amp;dst, 0, 0, 0, &amp;amp;src, nullptr);&#xA;    }&#xA;&#xA;    return { texture, textureDataSingle };&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However it uses same resource description for all array slices (i.e. width and height). I replaced last &amp;quot;if&amp;quot; with code below:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;{&#xA;    commandList-&amp;gt;ResourceBarrier(1, &amp;amp;CD3DX12_RESOURCE_BARRIER::Transition(texture.Get(), D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE));&#xA;&#xA;    D3D12_RESOURCE_DESC textureDesc = {};&#xA;    textureDesc.MipLevels = 1;&#xA;    textureDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;    textureDesc.Width = texture-&amp;gt;GetDesc().Width;&#xA;    textureDesc.Height = texture-&amp;gt;GetDesc().Height;&#xA;    textureDesc.Flags = D3D12_RESOURCE_FLAG_NONE;&#xA;    textureDesc.DepthOrArraySize = 1;&#xA;    textureDesc.SampleDesc.Count = 1;&#xA;    textureDesc.SampleDesc.Quality = 0;&#xA;    textureDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;&#xA;&#xA;    ThrowIfFailed(device-&amp;gt;CreateCommittedResource(&#xA;        &amp;amp;CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),&#xA;        D3D12_HEAP_FLAG_NONE,&#xA;        &amp;amp;textureDesc,&#xA;        D3D12_RESOURCE_STATE_COPY_DEST,&#xA;        nullptr,&#xA;        IID_PPV_ARGS(&amp;amp;m_diffuseTextures[index])&#xA;    ));&#xA;&#xA;    D3D12_TEXTURE_COPY_LOCATION dst{};&#xA;    dst.pResource = m_diffuseTextures[index].Get();&#xA;&#xA;    D3D12_TEXTURE_COPY_LOCATION src{};&#xA;    src.pResource = texture.Get();&#xA;&#xA;    commandList-&amp;gt;CopyTextureRegion(&amp;amp;dst, 0, 0, 0, &amp;amp;src, nullptr);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I don't have any errors, so I assume that data is loaded correctly. However, how can I upload std::vector or std::array&amp;lt;...&amp;gt; to GPU and use it with Texture2D[]?&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Edit: @Nathan Reed I am trying to upload multiple textures to GPU, to use in shader code (hlsl). Currently I am using single ID3D12Resource with chosen value of &amp;quot;DepthOrArraySize&amp;quot; and fixed width and height for all subresources. Then I am treating it as Texture2DArray when creating SRV. As a result, I have &lt;strong&gt;Texture2DArray&lt;/strong&gt; in my hlsl which works fine, but requirement of having fixed width/height for all elements is not convenient. I want to replace it with code, which enable me to use &lt;strong&gt;Texture2D[]&lt;/strong&gt; in hlsl, where each texture may have different size. Dynamic indexing is not necessary.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-09-09T18:34:47.643" LastActivityDate="2020-09-12T08:41:13.937" Title="Using array of textures in DX12" Tags="&lt;texture&gt;&lt;c++&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10199" PostTypeId="1" CreationDate="2020-09-08T23:35:51.777" Score="1" ViewCount="34" Body="&lt;p&gt;Nowadays is less of an issue, i think SS got massaged a little bit, but you can still spot it. These happen with SS Reflections, SSAO and Bloom. When you move the camera, the effect starts to flciker rather than move smoothly with wtv object it's attached to. Why it happens?&lt;/p&gt;&#xA;&lt;p&gt;Example of what i'm talking about:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pXXya.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pXXya.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13938" LastActivityDate="2020-09-08T23:35:51.777" Title="Why Screen Space effects flicker?" Tags="&lt;reflection&gt;&lt;ssao&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10200" PostTypeId="1" AcceptedAnswerId="10205" CreationDate="2020-09-09T14:55:12.103" Score="4" ViewCount="59" Body="&lt;p&gt;So I am doing a gradient descent like algorithm on the surface of a mesh and I just noticed something:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/L3hx3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/L3hx3.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The above is the geodesic gradient (the distance to a single vertex)&lt;/p&gt;&#xA;&lt;p&gt;Look at where the ear connects with the head and notice how the discretized gradient behaves.&#xA;It's almost pointing in opposite directions. This is not however an error, this occurs because the gradient at that region is fairly &amp;quot;turbulent&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;My algorithm is fairly simple, grab a point in a triangle, compute its negative gradient, intersect the gradient with the triangle, move there, switch active triangle to the neighbour, repeat.&lt;/p&gt;&#xA;&lt;p&gt;In other words you just follow the gradient down towards the source.&lt;/p&gt;&#xA;&lt;p&gt;However, when I hit those turbulent regions, my algorithm gets stuck, because the gradient becomes essentially 0 and numerical errors prevent it from intersecting any of the edges of the triangle.&lt;/p&gt;&#xA;&lt;p&gt;In pictures:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DgE3e.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DgE3e.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The green points are the path taken by my gradient descent algorithm. The cyan ones are the centres of the faces of the triangles and the yellow arrow is the gradient at the last point.&lt;/p&gt;&#xA;&lt;p&gt;Notice that this result is correct.&lt;/p&gt;&#xA;&lt;p&gt;However, at the ears:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/TVERW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/TVERW.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see the algorithm stops because the gradient is borderline 0.&lt;/p&gt;&#xA;&lt;p&gt;And worse there are regions in the ears where the turbulence makes the gradient bounce and start travelling in the opposite direction.&lt;/p&gt;&#xA;&lt;p&gt;Does anyone have tips on how I could handle the gradient in these regions?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-09T21:20:11.080" Title="Gradient descent (Not ML) on arbitrary meshes" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;gradient&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10201" PostTypeId="1" CreationDate="2020-09-09T15:21:30.430" Score="3" ViewCount="84" Body="&lt;p&gt;I am wondering why the texture of the following 3D model &lt;a href=&quot;https://app.ignitionrobotics.org/GoogleResearch/fuel/models/Transformers_Age_of_Extinction_Mega_1Step_Bumblebee_Figure&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://app.ignitionrobotics.org/GoogleResearch/fuel/models/Transformers_Age_of_Extinction_Mega_1Step_Bumblebee_Figure&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/1vdYb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/1vdYb.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Looks like the following:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://imgur.com/a/WrJ4Uyx&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://imgur.com/a/WrJ4Uyx&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;How are these logically connected?&lt;/p&gt;&#xA;" OwnerUserId="6281" LastEditorUserId="6281" LastEditDate="2021-03-24T00:44:01.010" LastActivityDate="2021-03-24T00:44:01.010" Title="How should the texture file look like?" Tags="&lt;texture&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10202" PostTypeId="1" AcceptedAnswerId="10203" CreationDate="2020-09-09T15:53:45.680" Score="5" ViewCount="77" Body="&lt;p&gt;I generate random directions from the pdf of D term in GGX BRDF. On the picture, white dots are new directions and the cross is the light direction, with roughness = 1. What should I do with the directions that are generated below the hemisphere? Should and can I just discard them?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UUAaT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UUAaT.png&quot; alt=&quot;Sampled directions&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13943" LastEditorUserId="3304" LastEditDate="2020-09-10T05:38:59.453" LastActivityDate="2020-09-10T05:38:59.453" Title="What should I do when a new sampled direction is below a normal oriented hemisphere?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;ggx&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10203" PostTypeId="2" ParentId="10202" CreationDate="2020-09-09T16:47:00.620" Score="2" Body="&lt;p&gt;Disclaimer: I am assuming that you are implementing a classical Monte Carlo estimator.&lt;/p&gt;&#xA;&lt;h2&gt;The Problem&lt;/h2&gt;&#xA;&lt;p&gt;Discarding samples will change PDF of your sampling technique. You are cutting off part of the sampled domain where PDF is non-zero, which effectively leads to a trimmed version of the original PDF but implicitly re-normalized so the remaining part integrates to 1. If you don't adjust the directly evaluated PDF accordingly, it will lead to a biased estimator.&lt;/p&gt;&#xA;&lt;p&gt;Practically speaking, implicit re-normalization increases the actual sampling PDF &lt;span class=&quot;math-container&quot;&gt;$p^{new}$&lt;/span&gt;, and if you use &lt;span class=&quot;math-container&quot;&gt;$p^{old}&amp;lt;p^{new}$&lt;/span&gt; in your computations instead, the resulting Monte Carlo estimator will yield brighter values than it should:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{f(x)}{p^{old}(x)} &amp;gt; \frac{f(x)}{p^{new}(x)}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;h2&gt;A solution&lt;/h2&gt;&#xA;&lt;p&gt;Since adjusting the PDF isn't an easy thing to do, you will most likely need to &lt;strong&gt;treat the under-surface samples as valid but with zero contribution&lt;/strong&gt;. Whether you handle this within your BRDF/BSDF or elsewhere in the renderer is your design decision.&lt;/p&gt;&#xA;&lt;p&gt;Zero-contribution samples will, obviously, introduce some inefficiency in your renderer.&lt;/p&gt;&#xA;&lt;h2&gt;A better solution&lt;/h2&gt;&#xA;&lt;p&gt;You can improve the efficiency of your estimator by using a better sampling technique which tries to avoid creating samples under the surface. In case of the GGX normal distribution, there have been proposed some solutions by Eric Heitz | Eugene d’Eon in paper &lt;a href=&quot;http://www.eugenedeon.com/project/importance-sampling-microfacet-based-bsdfs-using-the-distribution-of-visible-normals/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Importance Sampling Microfacet-Based BSDFs using the Distribution of Visible Normals&lt;/a&gt;. I believe there was one improved version of this technique (other that the one mentioned in the &amp;quot;Related Work&amp;quot; section) but I cannot recall the name of it. Maybe someone else can add it here...&lt;/p&gt;&#xA;" OwnerUserId="2479" LastEditorUserId="2479" LastEditDate="2020-09-09T17:16:22.673" LastActivityDate="2020-09-09T17:16:22.673" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10204" PostTypeId="1" CreationDate="2020-09-09T17:34:13.237" Score="3" ViewCount="95" Body="&lt;p&gt;&lt;a href=&quot;https://cs.stackexchange.com/questions/2450/how-do-i-construct-a-doubly-connected-edge-list-given-a-set-of-line-segments?newreg=1d611fc139b64175a8ba4ba0823ba6be&quot;&gt;This post&lt;/a&gt; explains how to construct double connected edge list in 2d. One of the steps in the algorithm is to sort the halfedges around a vertex in clockwise order. However this will not work in 3d. We can project the halfedge coordinates onto 2d viewplane and sort them that way (if the construction is user interactive). However this would make the construction dependent on the user view.&lt;/p&gt;&#xA;&lt;p&gt;What sort of algorithm would we use for 3d case of double connected edge list?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2021-02-08T20:04:50.490" Title="Algorithm for constructing doubly connected edge list in 3d" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10205" PostTypeId="2" ParentId="10200" CreationDate="2020-09-09T18:28:09.170" Score="3" Body="&lt;p&gt;Maybe you can find a heuristic to detect when it gets stuck (e.g. gradient magnitude is too small, or it stays on the same triangle or returns to a recently visited triangle too many times in a row, or it hasn't moved at least X distance over the last N steps, etc) and just take a random step in some direction, e.g. to some randomly chosen neighboring triangle? That might help shake it out of the difficult region and get back to smooth descent.&lt;/p&gt;&#xA;&lt;p&gt;For an even lower-tech solution, if you don't mind some randomness you could just inject occasional random moves all the time (without attempting to detect whether it's stuck). Kind of like stochastic gradient descent in ML.&lt;/p&gt;&#xA;&lt;p&gt;If the gradient you're following is a geodesic distance, I think it can have saddle points, but not local minima (except for the global minimum), is that right? If that's a constraint you can rely on, you could try to use a second-order method, finding an estimate of the local &lt;a href=&quot;https://en.wikipedia.org/wiki/Hessian_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hessian&lt;/a&gt; and looking for eigenvectors with negative eigenvalues, which should be &lt;a href=&quot;https://en.wikipedia.org/wiki/Principal_curvature&quot; rel=&quot;nofollow noreferrer&quot;&gt;directions of principal curvature&lt;/a&gt; that will accelerate the gradient descent, and in particular, will pull you out of saddle points. I'm sure there must be a literature on such methods although I don't know much about it.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-09T21:20:11.080" LastActivityDate="2020-09-09T21:20:11.080" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10207" PostTypeId="1" CreationDate="2020-09-10T09:23:44.667" Score="0" ViewCount="83" Body="&lt;p&gt;I'm not sure this is the right place to ask for this reference but it's worth the shot since it is graphics related.&lt;/p&gt;&#xA;&lt;p&gt;I'm looking for the very first paper describing what &amp;quot;Inverse Rendering&amp;quot; - By that I mean a machine learning system that given some renderer and a deep learning model and an image as input will provide you one or more maps describing how to render the same image.&lt;/p&gt;&#xA;&lt;p&gt;I cannot manage to find anywhere a/the white paper the would describe how such system would work.&lt;/p&gt;&#xA;&lt;p&gt;Can anyone provide a reference? Maybe not the very first paper but a white paper that might describe the fundamentals (I'd rather prefer papers to web articles).&lt;/p&gt;&#xA;&lt;p&gt;Thank you&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2021-02-08T08:05:55.627" Title="Reference for Inverse Rendering" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10208" PostTypeId="2" ParentId="10156" CreationDate="2020-09-10T13:33:43.793" Score="1" Body="&lt;p&gt;For a mesh that is not closed then, by definition, there is no interior or exterior, only points on the surface and points that are not on the surface.&lt;/p&gt;&#xA;&lt;p&gt;So your first step is to make the hand a &amp;quot;Closed Concave Polyhedron&amp;quot; by closing any openings it has. This can be done relatively simply by defining a plane where the hand is open. (such as at the wrist)&lt;/p&gt;&#xA;&lt;p&gt;With that done your first test is to determine if a point is on the hand side of the plane or the non hand side of the plane. ( A more generic solution would be to require the polyhedron to be closed and solve the closure part as a separate problem). It sounds like this has already been done for you with the bounding box that the hand lies inside. If that is the case then your first step is to determine if the point is inside the bound box or outside the bounding box. If it is outside the bounding box you are done. If it is inside then you must now check to see if it is inside the hand.&lt;/p&gt;&#xA;&lt;p&gt;Note: If you don't close the polyhedron in some way, then there is no algorithm that can reliably determine interior/exterior. This is one of the things that lightxbulb was eluding to with the first suggestion. For example, I have taken biology classes that consider your entire digestive track to be &amp;quot;outside&amp;quot; your body.&lt;/p&gt;&#xA;&lt;p&gt;A very common and fast method to determine if a point is inside a concave polyhedron is called ray casting. (suggestion 3 from lightxbulb) Using this technique you pick a random point usually outside the enclosed area, I would recommend picking a point outside the unit cube since you know for certain that your are starting outside the mesh.&lt;/p&gt;&#xA;&lt;p&gt;The point your are testing and the random point you picked can be used to form a line. Do not use a line that is infinitely long, instead your line has a start (the point outside the mesh) and an end (the point you are testing)&lt;/p&gt;&#xA;&lt;p&gt;Now you just brute force test every triangle in the mesh to see if they intersect with the line. Along the way you are counting the number of intersections that occur. If your point is inside the mesh then the line will pass through an odd number of triangles if your point is outside the mesh then your line will pass through an even number of points.&lt;/p&gt;&#xA;&lt;p&gt;I recommend drawing simple hand shape on a piece of paper, picking the two points, draw the line then count the intersections with the hand. This should make it much more clear why this works.&lt;/p&gt;&#xA;&lt;p&gt;If you do not close the polyhedron then you can get unlucky and there will be a line that can get inside the mesh without passing through it and this algorithm will fail. So one of the &amp;quot;triangles&amp;quot; you must test against is the plane that closes the mesh and it must be counted as a pass through a triangle or you could end up with false positive/negative.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-09-10T13:33:43.793" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10209" PostTypeId="2" ParentId="10207" CreationDate="2020-09-11T07:41:25.353" Score="0" Body="&lt;p&gt;I did only quick google search and found this PhD thesis - &amp;quot;Inverse rendering for computer graphics&amp;quot; by [Marschner1998] - &lt;a href=&quot;http://graphics.stanford.edu/%7Esrm/thesis/thesis.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphics.stanford.edu/~srm/thesis/thesis.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Also two published papers - Ramamoorthi et al &amp;quot;A Signal-Processing Framework for Inverse Rendering&amp;quot; &lt;a href=&quot;http://cseweb.ucsd.edu/%7Eravir/papers/invrend/invrend.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://cseweb.ucsd.edu/~ravir/papers/invrend/invrend.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And Yu, Smith - &amp;quot;InverseRenderNet: Learning Single image inverse -&#xA;&lt;a href=&quot;https://openaccess.thecvf.com/content_CVPR_2019/papers/Yu_InverseRenderNet_Learning_Single_Image_Inverse_Rendering_CVPR_2019_paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://openaccess.thecvf.com/content_CVPR_2019/papers/Yu_InverseRenderNet_Learning_Single_Image_Inverse_Rendering_CVPR_2019_paper.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Based on my experience, just follow prior works in this area and you'll get to the first or first worth mentioning paper in this area. With every paper in the area of raytracing, you'll get reference to [Whitted1980]. Every BRDF will get you back to&#xA;[CT1967] and every Spherical Harmonics work to [Green2003].&lt;/p&gt;&#xA;&lt;p&gt;Based on what you wrote, you must be familiar with reading papers. Therefore, I would suggest to read &amp;quot;Introduction&amp;quot; and &amp;quot;Prior work&amp;quot; to find references to past works in this area of computer graphics.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-09-11T07:41:25.353" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10211" PostTypeId="2" ParentId="10198" CreationDate="2020-09-11T18:31:50.087" Score="2" Body="&lt;p&gt;I think what you want for this is to create a descriptor table which lists your textures. The individual textures would be created and uploaded as ordinary Texture2Ds. You'd set up the root signature of your shader to bind your &lt;code&gt;Texture2D[]&lt;/code&gt; in HLSL to a contiguous range of SRV descriptors from a descriptor heap. Then, when you create the SRVs for your textures, put their descriptors into the corresponding slots in the heap.&lt;/p&gt;&#xA;&lt;p&gt;For the details, you can look at the &lt;a href=&quot;https://github.com/microsoft/DirectX-Graphics-Samples/tree/master/Samples/Desktop/D3D12DynamicIndexing&quot; rel=&quot;nofollow noreferrer&quot;&gt;D3D12DynamicIndexing&lt;/a&gt; sample in MS's DirectX Graphics Samples repository. I know you said you don't need dynamic indexing, but the strategy here would be the same.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-11T18:31:50.087" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10212" PostTypeId="2" ParentId="10204" CreationDate="2020-09-11T19:25:12.067" Score="0" Body="&lt;p&gt;The problem statement in the linked post says that only the vertices and edges are input to the algorithm, but I don't think it's possible to do this unambiguously in 3D without additional input about the faces of the mesh. In the 2D case, since the input is specified to be a planar graph, the faces are unambiguous: any region in the plane contained within an edge loop, and empty of edges in its interior, is a face. However, in 3D, you don't know which edge loops should be faces and which shouldn't.&lt;/p&gt;&#xA;&lt;p&gt;Consider a cube, represented as just vertices and edges: you would want the &amp;quot;usual&amp;quot; 6 sides of the cube to be treated as faces, but you wouldn't want the algorithm to create additional faces that stretch across the diagonal of the cube, internally. But there is no way for the algorithm to know that. Moreover, the vertex/edge mesh might not even be possible to assign faces to in a sensible way; it might have non-planar faces, might be non-orientable (e.g. Möbius strip) or non-manifold.&lt;/p&gt;&#xA;&lt;p&gt;Typically in 3D applications we would have the mesh faces already defined, and we can assume it to be a manifold, orientable mesh. With the face data as input to the algorithm, such as by lists of edges or vertices in counterclockwise order around each face, then it becomes straightforward (if tedious) to figure out the half-edge relationships.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-11T19:25:12.067" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10213" PostTypeId="1" CreationDate="2020-09-11T20:49:31.513" Score="0" ViewCount="60" Body="&lt;p&gt;I'm learning about computer graphics and I have some questions about calculation of the vectors, so I will write the exercises that I have and I hope that someone can help me with the formulas that I should use to calculate them:&lt;/p&gt;&#xA;&lt;p&gt;given:&#xA;pint p=(1,0,0) with normal vector n=(1,0,0), position of light source L=(4,0,-4) and Viewer V=(4,0,4).&lt;/p&gt;&#xA;&lt;p&gt;Questions&amp;gt;&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Calculate the light vector 'l', the view vector 'v' and the reflection vector 'r'.&lt;/li&gt;&#xA;&lt;li&gt;Calculate the total lighting 'I' where:&#xA;Light intensities:&#xA;L(diff) = L(spec) = (1,1,1),&#xA;L(amb) = (0.1, 0.1, 0.1)&#xA;Reflection coefficients:&#xA;K(amb) = K(diff) = (.8, .4, .2),&#xA;K(spec) = (.3, .3, .3)&#xA;Reflection exponent: n = 12&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Thank you so much!&lt;/p&gt;&#xA;" OwnerUserId="13954" LastActivityDate="2020-09-11T20:49:31.513" Title="Calculating of vectors in Phong Lighting Model" Tags="&lt;opengl&gt;&lt;mathematics&gt;&lt;lighting&gt;&lt;reflection&gt;&lt;vectors&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10214" PostTypeId="2" ParentId="10198" CreationDate="2020-09-12T08:27:28.883" Score="0" Body="&lt;p&gt;Thank you Nathan! I was basing my Texture2DArray solution on MS's sample repo that you've sent, but after your explanation it was much easier to convert code to Texture2D[]. For anyone wondering, here's code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void RaytracingResources::CreateDxrPipelineAssets(ID3D12Device5* device, ModelClass* model, std::vector&amp;lt;TextureWithDesc&amp;gt; texturesWithDesc, D3D12_SHADER_RESOURCE_VIEW_DESC indexDesc, D3D12_SHADER_RESOURCE_VIEW_DESC vertexDesc, std::vector&amp;lt;ResourceWithSize&amp;gt; buffersWithSize, std::vector&amp;lt;bool&amp;gt; isUAV)&#xA;{&#xA;    // Create descriptor heaps&#xA;    {&#xA;        D3D12_DESCRIPTOR_HEAP_DESC desc = {};&#xA;        // Vertex + index + TLAS = 3&#xA;        // Buffer count = y // buffersWithSize&#xA;        // Number of textures = x // texturesWithDesc&#xA;        int textureCount = 0;&#xA;        for (const auto&amp;amp; tex : texturesWithDesc) {&#xA;            textureCount += tex.resources.size();&#xA;        }&#xA;        desc.NumDescriptors = 3 + static_cast&amp;lt;UINT&amp;gt;(buffersWithSize.size()) + static_cast&amp;lt;UINT&amp;gt;(textureCount);&#xA;        desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;&#xA;        desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;&#xA;&#xA;        // Create the descriptor heap&#xA;        ThrowIfFailed(device-&amp;gt;CreateDescriptorHeap(&amp;amp;desc, IID_PPV_ARGS(&amp;amp;m_descriptorHeap)));&#xA;&#xA;        // Get the descriptor heap handle and increment size&#xA;        D3D12_CPU_DESCRIPTOR_HANDLE handle = m_descriptorHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart();&#xA;        UINT handleIncrement = device-&amp;gt;GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);&#xA;&#xA;        // Create the CBV&#xA;        // ...&#xA;&#xA;        // Create the DXR output buffer UAV&#xA;        // ...&#xA;&#xA;        // Create the DXR Top Level Acceleration Structure SRV&#xA;        // ...&#xA;&#xA;        // Create the index buffer SRV&#xA;        // ...&#xA;&#xA;        // Create the vertex buffer SRV&#xA;        // ...&#xA;&#xA;        // Create texture buffer SRV&#xA;        for (auto&amp;amp; tex : texturesWithDesc)&#xA;        {&#xA;            for (auto&amp;amp; singleTextureResource : tex.resources)&#xA;            {&#xA;                if (tex.isSRV)&#xA;                {&#xA;                    handle.ptr += handleIncrement;&#xA;                    device-&amp;gt;CreateShaderResourceView(singleTextureResource.Get(), &amp;amp;tex.srvDesc, handle);&#xA;                }&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;As Nathan said. Each texture is a separate descriptor in HLSL, so I'm calculating number of textures to bind, based on passed data. I am using single space with assumption that Texture2D[] SRVs are the last element in the texture buffer space in HLSL. For now it works only for single texture array, so I'll need to add more spaces to make it possible to use multiple array of textures.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-09-12T08:41:13.937" LastActivityDate="2020-09-12T08:41:13.937" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10215" PostTypeId="1" AcceptedAnswerId="10221" CreationDate="2020-09-12T22:31:38.747" Score="3" ViewCount="48" Body="&lt;p&gt;I have been trying to understand a &lt;a href=&quot;https://www.cs.cmu.edu/%7Ekmcrane/Projects/HeatMethod/paperCACM.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper in CG&lt;/a&gt; for a while, called the Heat Method by Ken&lt;/p&gt;&#xA;&lt;p&gt;Many things have clicked but I don't fully understand it yet. In particular.&lt;/p&gt;&#xA;&lt;p&gt;In the following &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; is a vector with dimensions equal to the number of vertices in a mesh.&lt;/p&gt;&#xA;&lt;p&gt;The paper states that solving &lt;span class=&quot;math-container&quot;&gt;$(id - t\Delta)u_t = u_0$&lt;/span&gt; is a time discretized approximation of the heat flow on a surface. Rewriting gives: &lt;span class=&quot;math-container&quot;&gt;$u_t = u_0 + t\Delta u_t $&lt;/span&gt; or in English, the heat flow at time &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; is equal to the heat flow at time 0 plus the laplacian of &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; at time &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;. Which is just a backwards Euler method pretty straightforward.&lt;/p&gt;&#xA;&lt;p&gt;Then we get that: &lt;span class=&quot;math-container&quot;&gt;$(M - tL_C)u = δγ,$&lt;/span&gt; which, to summarize, is the same as above except we have discretized the medium as a triangular mesh.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; is a square diagonal matrix where the entry &lt;span class=&quot;math-container&quot;&gt;$m_{i,i}$&lt;/span&gt; is 2 times one third of the sum of the areas of the triangles that contain vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;. In math &lt;span class=&quot;math-container&quot;&gt;$m_{i,i} = 2\sum_j A_j / 3$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$A_j$&lt;/span&gt; are the areas of the triangles containing vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;. And &lt;span class=&quot;math-container&quot;&gt;$L_C$&lt;/span&gt; is also a square diagonal matrix where &lt;span class=&quot;math-container&quot;&gt;$(L_C u)_i = \sum_j (\cot \alpha_{ij} + \cot \beta_{ij})(u_j-u_i)$&lt;/span&gt; which in short, is an approximation of the laplace operator at vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Thus manipulating the formula: &lt;span class=&quot;math-container&quot;&gt;$(id - tM^{-1}L_C)u = M^{-1}δγ,$&lt;/span&gt; Which is the spatially discretized form of: &lt;span class=&quot;math-container&quot;&gt;$(id - t\Delta)u_t = u_0$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So, this makes sense algebraically, but now comes the part I don;t understand.&lt;/p&gt;&#xA;&lt;p&gt;Why does this work? Why would solving that equation give the correct heat diffusion? Let me explain what I mean. In my head, a geodesic distance (or heat flow, which for the purposes of this method are the same thing) is highly dependent on the shape of a mesh. So in order to know the geodesic distance at vertex &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt; I must first know the geodesic distance at the vertices that come before it relative to the source.&lt;/p&gt;&#xA;&lt;p&gt;This mehtod however seems to imply that, given an arbitrary mesh and an arbitrary point &lt;span class=&quot;math-container&quot;&gt;$p_0$&lt;/span&gt; on that mesh. I can grab any arbitrary point &lt;span class=&quot;math-container&quot;&gt;$p_1$&lt;/span&gt; on the mesh and tell you what the geodesic distance from &lt;span class=&quot;math-container&quot;&gt;$p_1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$p_2$&lt;/span&gt; is without having to look at the full connectivity of the mesh to determine a connectivity graph.&lt;/p&gt;&#xA;&lt;p&gt;I am not entirely sure if what i am asking is clear. I understand the algebra of the problem, but I cannot link how solving this equation gives you the correct heat flow everywhere on a mesh. Why can you do it in parallel without any regards for the specific connectivity information?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="48" LastEditDate="2020-09-13T16:25:38.170" LastActivityDate="2020-09-14T00:51:31.607" Title="Mis understanding of the Heat Method" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;&lt;gradient&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10216" PostTypeId="1" AcceptedAnswerId="10229" CreationDate="2020-09-13T09:07:07.793" Score="1" ViewCount="55" Body="&lt;p&gt;I am using RT shader (DXR) to generate g-buffers with code below. There was no problems with smaller scene (pink room from cwyman tutorial - &lt;a href=&quot;http://cwyman.org/code/dxrTutors/tutors/Tutor5/tutorial05.md.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://cwyman.org/code/dxrTutors/tutors/Tutor5/tutorial05.md.html&lt;/a&gt; ). However, when I moved to bigger scene (Sun Temple by Epic Games - &lt;a href=&quot;https://developer.nvidia.com/ue4-sun-temple&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://developer.nvidia.com/ue4-sun-temple&lt;/a&gt; ), I've started noticing problems with texture sampling. Please compare textures at the end of this post. The greater the distance to world origin (0, 0, 0), the more jaggy artifacts appear and quality becomes worse.&lt;/p&gt;&#xA;&lt;p&gt;At the beginning, I was suspecting acceleration structures. But skybox quality is becoming worse, so it's probably unrelated to AS.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;inline void GenerateCameraRay(uint2 index, uint2 dimensions, float4x4 projectionToWorld, inout  float3 origin, out float3 direction)&#xA;{&#xA;    float2 xy = index + float2(0.5f, 0.5f); // center in the middle of the pixel.&#xA;    float2 screenPos = (xy / (float2) dimensions) * 2.0 - 1.0;&#xA;&#xA;    // Invert Y for DirectX-style coordinates.&#xA;    screenPos.y = -screenPos.y;&#xA;&#xA;    // Unproject the pixel coordinate into a ray.&#xA;    float4 world = mul(float4(screenPos, 0, 1), projectionToWorld);&#xA;&#xA;    world.xyz /= world.w;&#xA;    direction = normalize(world.xyz - origin);&#xA;}&#xA;&#xA;[shader(&amp;quot;raygeneration&amp;quot;)]&#xA;void RayGen()&#xA;{&#xA;    float3 rayDir;&#xA;    float3 origin = g_sceneCB.cameraPosition.xyz;&#xA;    &#xA;    // Generate a ray for a camera pixel corresponding to an index from the dispatched 2D grid.&#xA;    GenerateCameraRay(DispatchRaysIndex().xy, DispatchRaysDimensions().xy, g_sceneCB.projectionToWorld, origin, rayDir);&#xA;&#xA;    RayDesc ray = { origin, 1e-4f, rayDir, 1e+38f };&#xA;    RayPayload payload = { 0 };&#xA;    TraceRay(SceneBVH, RAY_FLAG_NONE, 0xFF, 0, 1, 0, ray, payload);&#xA;}&#xA;    &#xA;[shader(&amp;quot;miss&amp;quot;)]&#xA;void Miss(inout RayPayload payload)&#xA;{&#xA;    float3 rayDir = WorldRayDirection();&#xA;    rayDir.z = -rayDir.z;&#xA;&#xA;    RTOutputAlbedo[DispatchRaysIndex().xy] = float4(skyboxTexture.SampleLevel(g_sampler, rayDir, 0).rgb, 0);&#xA;    RTOutputNormal[DispatchRaysIndex().xy] = float4(0, 0, 0, 0);&#xA;    RTOutputSpecRoughness[DispatchRaysIndex().xy] = float4(0, 0, 0, 0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fIwbx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fIwbx.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7l9wO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7l9wO.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-09-16T07:42:54.283" Title="Worsening sampling quality of raytracing with increasing distance from world origin" Tags="&lt;raytracing&gt;&lt;texture&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10217" PostTypeId="1" AcceptedAnswerId="10218" CreationDate="2020-09-13T11:42:06.830" Score="1" ViewCount="33" Body="&lt;p&gt;If I have 360 images of an interior room from all different angles, would it be possible with current 3D software technology to create a &lt;strong&gt;real&lt;/strong&gt; 3D representation of that room, where the camera could freely navigate to any part of it?&lt;/p&gt;&#xA;&lt;p&gt;So similar to Photoshop’s stitch, where you stitch a bunch of photos to create a single 360 photo, would you be able to stitch a bunch of 360 photos to create a 3D environment?&lt;/p&gt;&#xA;&lt;p&gt;I’m not looking to create graphics or photorealism out of the room, but rather the actual real room. Most of my research points either to one of the above or VR videos, which have limitations on camera direction.&lt;/p&gt;&#xA;&lt;p&gt;If it is possible, could you please point me to the right direction/software and/or examples of work that have achieved this?&lt;/p&gt;&#xA;&lt;p&gt;If it’s not possible, I would be very interested in knowing what the limitations are.&lt;/p&gt;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="13959" LastActivityDate="2020-09-13T20:11:37.520" Title="Real 3D interior room from 360 images" Tags="&lt;3d&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10218" PostTypeId="2" ParentId="10217" CreationDate="2020-09-13T20:11:37.520" Score="3" Body="&lt;p&gt;A website devoted to prescanned photogrammetry is :&lt;a href=&quot;https://quixel.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Quixel.com&lt;/a&gt; They did (at least some of) the assets for the version 5 unreal engine &lt;a href=&quot;https://www.youtube.com/watch?v=qC5KtatMcUw&quot; rel=&quot;nofollow noreferrer&quot;&gt;demo&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I have gotten excellent results with software from &lt;a href=&quot;https://www.agisoft.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Agisoft&lt;/a&gt; but it costs real money.&#xA;For good free software try &lt;a href=&quot;https://www.3dflow.net&quot; rel=&quot;nofollow noreferrer&quot;&gt;3DF Zephyr&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This software will just generate the mesh, they will provide only minimal navigation of the result which is outside the scope of generation.&lt;/p&gt;&#xA;&lt;p&gt;To navigate the mesh you can use something like windows 3D viewer.&lt;/p&gt;&#xA;&lt;p&gt;Or better yet, and way more fun, write your own!&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-09-13T20:11:37.520" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10219" PostTypeId="1" AcceptedAnswerId="10253" CreationDate="2020-09-13T21:28:14.253" Score="1" ViewCount="82" Body="&lt;p&gt;I need the simplest route to programatically, via command line, through python or node, to create something like this using basic input of distance and 90 degree turn etc: &lt;a href=&quot;https://i.imgur.com/SdY02gQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://i.imgur.com/SdY02gQ.png&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I normally use blender for such graphics, but manually. I have bee told its over kill to use for my basic need via python, not sure where to start.&lt;/p&gt;&#xA;&lt;p&gt;I have been told three.js is the wrong choice to try and do something like that as its for browser use mainly and I just want to create rendered images to disk, from input, on the command line.&lt;/p&gt;&#xA;&lt;p&gt;any advice would be appreciated. I am building a fencing quote system and would like to have basic graphics accompany it. I feel like autocad/freecad would be perfect if it had such options.&lt;/p&gt;&#xA;" OwnerUserId="13961" LastActivityDate="2020-09-23T08:58:07.413" Title="What is the simplest way to create basic 3d/isometric style images programatically like autocad/blender" Tags="&lt;opengl&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="10220" PostTypeId="1" AcceptedAnswerId="10222" CreationDate="2020-09-13T22:38:16.920" Score="2" ViewCount="90" Body="&lt;p&gt;The description is going to be long and detailed, thanks in advance for your patience!&lt;/p&gt;&#xA;&lt;p&gt;I am learning the path integral form of light transport equation(LTE) to be able to follow recent rendering papers. The materials I am using are PBRT(chapter 14.4-14.5: &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/The_Light_Transport_Equation.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;link&lt;/a&gt;) and SIGGRAPH 2013 course: &lt;a href=&quot;https://cgg.mff.cuni.cz/%7Ejaroslav/papers/2013-ltscourse/02%20-%20ltscourse%20-%20path%20integral%20-%20krivanek%20-%20notes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;link&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The path integral form of LTE is:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ I(x) = \int_{\Omega}f(\overline{x})d\mu(\overline{x})$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;From the SIGGRAPH course's slide, we know that we can estimate &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt; by randomly sampling a path, computing its contribution &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;, and dividing by its probability &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ \overline{I}(x) = \frac{f(\overline{x})}{p(\overline{x})} $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;From the PBRT's notes and its implementation, it expands the path integral into an infinite sum of integrals on specific lengths of paths. This notation is well shown in the path tracing implementation since the i-th bounce computes the i-th integral and simply summing them up will the final estimate of &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ \overline{I}(x) = \sum_{i=0}^{\infty}\overline{I_{i}}(x) $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;With these two notations based on the path form integral of LTE, my question is how to represent path tracing as the first one(the SIGGRAPH course notation) since most PT implementations I've seen so far is based either on the PBRT's notation(the sum notation) or other notations of LTE.&lt;/p&gt;&#xA;&lt;p&gt;I have one possible idea that is to follow the formula by generating a path and computing its pdf, but I am not sure about its practical implementation. Should I generate paths for different lengths and do this procedure over and over(since this looks more like the PBRT's notation), or a single path with the correct pdf will suffice?&lt;/p&gt;&#xA;&lt;p&gt;Or, from another perspective, I think that to apply the SIGGRAPH course's notation in practice, one has to randomly generate paths with different lengths and sum their estimate up since each length corresponds to one term in the expanded notation. Is this correct?&lt;/p&gt;&#xA;" OwnerUserId="13896" LastEditorUserId="13896" LastEditDate="2020-09-13T23:37:57.977" LastActivityDate="2020-09-14T01:13:04.747" Title="Path Integral Form with Path Tracing" Tags="&lt;pathtracing&gt;&lt;sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10221" PostTypeId="2" ParentId="10215" CreationDate="2020-09-14T00:51:31.607" Score="1" Body="&lt;p&gt;When solving the equation &lt;span class=&quot;math-container&quot;&gt;$(M - tL_C)u = \delta_\gamma$&lt;/span&gt;, you effectively have to invert the operator:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;u = (M - tL_C)^{-1} \delta_\gamma&#xA;$$&lt;/span&gt;&#xA;Note that while the individual operators &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$L_C$&lt;/span&gt; are only local, containing information about the individual vertices and edges of the mesh, the inverse operator is decidedly not local. Inversion is a global operation that incorporates information across the whole matrix being inverted, which means information across the whole mesh. (Note that &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; has a trivial inverse since it's diagonal, but &lt;span class=&quot;math-container&quot;&gt;$L_C$&lt;/span&gt; definitely doesn't.)&lt;/p&gt;&#xA;&lt;p&gt;In practice, you might not literally compute the inverse matrix but rather use Gaussian elimination or some such to solve the &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; for a given &lt;span class=&quot;math-container&quot;&gt;$\delta_\gamma$&lt;/span&gt;. In that case, it's the solving process that integrates information across the whole mesh. Effectively &lt;span class=&quot;math-container&quot;&gt;$L_C$&lt;/span&gt; is encoding a bunch of constraints between neighboring vertices, and the solver has to satisfy all the constraints across the whole mesh at once.&lt;/p&gt;&#xA;&lt;p&gt;(Note that it's not a trivially parallelizable job. There are methods for using parallelism to accelerate solving large linear systems, but they're going to be multi-pass methods that transfer information up and down between different &amp;quot;scales&amp;quot; of the problem. Think like parallel prefix scan, or FFT—that sort of thing.)&lt;/p&gt;&#xA;&lt;p&gt;BTW, another perspective on this equation is that it is solving for the fixed point of &lt;span class=&quot;math-container&quot;&gt;$u$&lt;/span&gt; in&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;u = M^{-1}(\delta_\gamma + tL_Cu)&#xA;$$&lt;/span&gt;&#xA;This is yet another way of algebraically rewriting that same equation. In this form it looks a lot like the rendering equation &lt;span class=&quot;math-container&quot;&gt;$L = L_e + \int L \, f_{\text{brdf}}$&lt;/span&gt;! It has a similar structure, where &lt;span class=&quot;math-container&quot;&gt;$\delta_\gamma$&lt;/span&gt; is like the emitted radiance and &lt;span class=&quot;math-container&quot;&gt;$L_C$&lt;/span&gt; is like the scattering at surfaces. Just as in the rendering equation, you're looking for a global equilibrium solution. (And if rendering was discretized, we could similarly solve it by turning the scattering operator into a matrix and throwing the whole thing into a linear solver.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-14T00:51:31.607" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10222" PostTypeId="2" ParentId="10220" CreationDate="2020-09-14T01:13:04.747" Score="1" Body="&lt;p&gt;&lt;strong&gt;Q1&lt;/strong&gt;: how to represent path tracing as the first one...&lt;/p&gt;&#xA;&lt;p&gt;Your materials have brought enough information, the first formula, quoted from your material, presents as&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The path integral formulation of light transport formalizes the idea&#xA;by writing the camera response as an integral over all light transport&#xA;paths of all lengths in the scene, which given path encompasses&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;the “amount” of light emitted along the path,&lt;/li&gt;&#xA;&lt;li&gt;the light carrying capacity of the path, and&lt;/li&gt;&#xA;&lt;li&gt;the sensitivity of the sensor to light brought along the path.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Can't interpret the formula better&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Q2&lt;/strong&gt;: Should I generate paths for different lengths and do this procedure over and over...&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Q3&lt;/strong&gt;: ...randomly generate paths with different lengths and sum their estimate up since each length...&lt;/p&gt;&#xA;&lt;p&gt;Quoted from your material,&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The Monte Carlo integration procedure consists in generating a&#xA;‘sample’, that is, a random x-value from the integration domain, ...&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I can't say the second one is a formula, it is just the Monte Carlo estimator of the path integral formulation of light transport or it is just a method for programming the formulation; or course you could have other methods.&lt;/p&gt;&#xA;" OwnerUserId="13838" LastActivityDate="2020-09-14T01:13:04.747" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10223" PostTypeId="1" AcceptedAnswerId="10230" CreationDate="2020-09-14T03:47:23.673" Score="2" ViewCount="211" Body="&lt;p&gt;&lt;strong&gt;Current state:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I belive the reconstructed positions are correct. However, I still have the same problem as all the time. When I rotate around my single pointlight appears to be moving around also.&lt;/p&gt;&#xA;&lt;p&gt;I finally solved this! It was annoying, but I did learn alot on the way.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;The explanation&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am trying to recreate viewspace positions from only a stored depth value, and then calculate the light in viewspace.&lt;/p&gt;&#xA;&lt;p&gt;In the first pass I store the Normals and the normalized depth in viewspace.&#xA;In the second pass I try to build reconstruct the position in viewspace.&lt;/p&gt;&#xA;&lt;p&gt;I belive something is going wrong in the reconstruction, but I can't see what, or if it something else. I did try to reconstruct the position in different ways, always with the same not good result.&lt;/p&gt;&#xA;&lt;p&gt;The light initially looks fine, but when I start moving around the light seems to be moving around.&#xA;When I go futher away, things get less lit. When rotating the light also rotates.&#xA;Note: When I render out the actual depth values, it looks fine, so think the depth is fine.&lt;/p&gt;&#xA;&lt;p&gt;What could I be doing wrong?&lt;/p&gt;&#xA;&lt;p&gt;Belove is code for the fragment &amp;amp; vertex shader, first and second pass.&lt;/p&gt;&#xA;&lt;p&gt;Thank you&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;First pass:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;--Vertex&#xA;#version 460&#xA;&#xA;layout( location = 0 ) in vec3 VertexPosition;&#xA;layout( location = 1 ) in vec3 VertexNormal;&#xA;&#xA;/* Uniforms */&#xA;uniform mat4 ViewMatrix;&#xA;uniform mat4 ProjectionMatrix;&#xA;uniform mat3 NormalMatrix;&#xA;uniform float FarPlane;&#xA;uniform float NearPlane;&#xA;&#xA;out vec3 vNormal;&#xA;out highp float vDepth;&#xA;&#xA;void main() {&#xA;  mat4 vMVP = ProjectionMatrix * ViewMatrix;&#xA;  gl_Position = vMVP * vec4( VertexPosition, 1.0 ); // Screenspace&#xA;&#xA;  vNormal = normalize(NormalMatrix  * normalize(VertexNormal));&#xA;  vec3 vPos = (ViewMatrix * vec4( VertexPosition, 1.0 )).xyz;&#xA;&#xA;  // Save normalized depth [0, 1]&#xA;  vDepth = -(vPos.z - NearPlane) / ( FarPlane - NearPlane);&#xA;}&#xA;&#xA;--Fragment&#xA;#version 460&#xA;&#xA;in vec3 vNormal;&#xA;in highp float vDepth;&#xA;&#xA;layout (location = 0) out highp vec4 NormalDepth;&#xA;&#xA;void main() {&#xA;  NormalDepth = vec4(normalize(vNormal), vDepth);&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Second pass&lt;/strong&gt; (off rendering to screen):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;--Vertex&#xA;#version 460&#xA;&#xA;layout( location = 0 ) in vec3 VertexPosition;&#xA;&#xA;out vec2 vTexCoord;&#xA;out vec2 vDeviceCoords;&#xA;&#xA;void main() {&#xA;  vDeviceCoords = 2.0 * ( VertexPosition.xy - 0.5 );// [-1, 1]&#xA;  vTexCoord = VertexPosition.xy;//  [0, 1] // Just 2 triangles for the screen&#xA;&#xA;  gl_Position = vec4(vDeviceCoords, 1.0, 1.0 ); // [-1, 1]&#xA;}&#xA;&#xA;--Fragment&#xA;#version 460&#xA;&#xA;/* Uniforms */&#xA;uniform float NearPlane;&#xA;uniform float FarPlane;&#xA;uniform mat4 ViewMatrix;&#xA;&#xA;in vec2 vTexCoord;&#xA;in vec2 vDeviceCoords;&#xA;&#xA;layout( location = 0 ) out vec4 FragColor;&#xA;layout( binding = 0 ) uniform highp sampler2D NormalDepthTex;&#xA;&#xA;vec3 diffuseValue( vec3 normal, vec3 position)&#xA;{&#xA;  // Light position. Here now for testing purposes&#xA;  // Stationary point light, transformed to viewspace&#xA;  vec3 vLightPos = (ViewMatrix * vec4( -10.0, 0.0, 2.0, 1.0 )).xyz;&#xA;&#xA;  normal = normalize(normal);&#xA;  const vec3 lightDir = normalize(position - vLightPos);&#xA;  const float diffuseCos = max( dot( normal, -lightDir ), 0.0 );&#xA;&#xA;  return vec3(diffuseCos);&#xA;}&#xA;&#xA;void main() {&#xA;  const vec4 normalDepth = texture2D( NormalDepthTex, vTexCoord );&#xA;&#xA;  // Normalize depth to [0, FarPlane]&#xA;  const float depth = normalDepth.w * (FarPlane - NearPlane);&#xA;&#xA;  // Unproject&#xA;  vec3 position;&#xA;  position = vec3(vDeviceCoords.x, vDeviceCoords.y, NearPlane);&#xA;  position.xy *= -depth / NearPlane; &#xA;  position.z = depth;&#xA;&#xA;  // View space&#xA;  vec3 diffuseValue = diffuseValue(normalDepth.xyz, position);&#xA;&#xA;  FragColor = vec4( diffuseValue.x, diffuseValue.y, diffuseValue.z, 1.0 );&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 1&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Adding screenshot.&lt;/p&gt;&#xA;&lt;p&gt;for the normals, they looks correct, always pointing toward the camera. (also I can add, if I do the light in the first pass (not reconstructed depth), then the light is 100% fine).&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ts4j7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ts4j7.png&quot; alt=&quot;Rendering the normals&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If we look at the light, initially it looks good. I positioned the light so It should shade as seen. But it changes and becomes wrong when I rote the camera. Also the intensity changes when I go further/closer with the camera.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/63LmJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/63LmJ.png&quot; alt=&quot;The light (albedo value)&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If we slightly rotate left for example, then the light follows (I want it in position!):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NUm2I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NUm2I.png&quot; alt=&quot;Light moved&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The viewspace depth [0, 1]&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BjdEy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BjdEy.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;EDIT 2:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I have now reconstructed the depth in three different ways, all with the same result. I am starting to think There is something else I am doing wrong? Do I calculate the light wrong or something?&lt;/p&gt;&#xA;&lt;p&gt;The three ways I have rebuilt (or tryed to) are:&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Option 1:&lt;/em&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    depth  = normalDepth.w; // Should be [0, 1]&#xA;&#xA;    // Create ray to FarPlane&#xA;    // HalfVec is FarPlane * glm::tan( glm::radians( m_fov / 2.0f ) )&#xA;    vec3 ray = vec3(vDeviceCoords * HalfVec, FarPlane);&#xA;&#xA;    // Unprojection&#xA;    position.xy = ray.xy * -depth / NearPlane;&#xA;    position.z = depth * FarPlane;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;em&gt;Option 2:&lt;/em&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    depth  = normalDepth.w * FarPlane;&#xA;&#xA;    vec2 p = vDeviceCoords * NearPlane * tan(radians(Fov / 2.0));&#xA;    vec2 p_ = (p / NearPlane) * -depth;&#xA;&#xA;   position = vec3(p_, depth);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;em&gt;Option 3:&lt;/em&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    depth  = normalDepth.z;&#xA;&#xA;    mat4 inversePrjMat = inverse( ProjectionMatrix );&#xA;    vec4 viewPosH      = inversePrjMat * vec4( vDeviceCoords.x, vDeviceCoords.y, 1.0, 1.0 );&#xA;    vec3 farPlaneRay   = viewPosH.xyz / viewPosH.w;&#xA;&#xA;    position = farPlaneRay;&#xA;    position.xy *= -depth;&#xA;    position.z = depth * FarPlane;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;These all options ends up the same. I have recalculated and went through the math over and over again, there is something else I am missing is my feeling.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 3&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;was asked to upload image with the normals (R, G, B). When camera is abit rotated.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/AgUzI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AgUzI.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 4&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Adding some GIF animations that shows what is going on with the light. As you can see, if I dont rotate at all. just move around, then the light is as it should.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RQGjW.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RQGjW.gif&quot; alt=&quot;Moving around 1&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/G3reu.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/G3reu.gif&quot; alt=&quot;Moving around 2&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DzBFa.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DzBFa.gif&quot; alt=&quot;Moving around 3&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/k0Xds.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/k0Xds.gif&quot; alt=&quot;Moving around 4&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 5&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I did the correction  Nathan Reed pointed out. Still with no better result.&#xA;This is what it looks like when I render out fract(position).&#xA;The boxes I render have a size 5.0 * 5.0 * 5.0 (actually each box is made up of 5x5x5 smaller boxes)&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qg865.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qg865.jpg&quot; alt=&quot;fract(position)&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;and abit more angled view at the boxes&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/s1lxj.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/s1lxj.jpg&quot; alt=&quot;fract(position) with angle&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 6&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;this is frontview, rendering &lt;code&gt;vec4( fract(position.x), 0.0, 0.0, 1.0 );&lt;/code&gt; &lt;a href=&quot;https://i.stack.imgur.com/5l74u.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5l74u.png&quot; alt=&quot;vec4( fract(position.x), 0.0, 0.0, 1.0 )&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is with  vec4( fract(position.y), 0.0, 0.0, 1.0 )&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DXys6.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DXys6.png&quot; alt=&quot; vec4( fract(position.y), 0.0, 0.0, 1.0 )&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is what it looks like when i render  vec4( VertexPosition, 1.0 ); (the 2 triangles making up the fullscreen in the second pass)&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rksek.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rksek.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;edit 7&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is what is looks like if i render the fract(vPos) from the first pass.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/z3CJl.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/z3CJl.gif&quot; alt=&quot;fract(vPos) from the first pass&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here I render just vPos from the first pass&#xA;&lt;a href=&quot;https://i.stack.imgur.com/w7o1w.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/w7o1w.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 8&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is about how it should look like. This is when I do the light calculation directly in the first pass. It is stationary, and perfect, as it should be, in this case.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ss3y7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ss3y7.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 9&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I just rendered the constructed positions, and noticed x,y-axies are flipped&#xA;need to negate x,y when multiplying with depth, since depth is negate.&#xA;Also we are saving the depth in viewspace, so use it straight for the z-component. That is correct, it can be noticed by the light not fading away when moving away futher with the position.z set to depth.&#xA;Also, we are multiplying xy with depth since triangle similarity. To be more precise we should divide that with the nearplane, I will do that, but I am using nearplane = 1, so wont be any practical difference right now anyways.&lt;/p&gt;&#xA;&lt;p&gt;So I did this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    position = vec3(vDeviceCoords.x / ProjectionMatrix[0][0], vDeviceCoords.y / ProjectionMatrix[1][1], 1.0);&#xA;    position.xy *= -depth / NearPlane;&#xA;    position.z  = depth;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now the light calculated on the second pass looks very much correct, appart from rotating... The light don't even fade when going futher. As long as I dont rotate(!)&lt;/p&gt;&#xA;&lt;p&gt;Is there something else obvious I am missing?&lt;/p&gt;&#xA;&lt;p&gt;light, when moved, but not rotated at all:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/g3zm1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/g3zm1.png&quot; alt=&quot;Moved, but rotated&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Reconstructed and Position looks the same when rendered. but when doing fract on the reconstructed position I still get this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/uMn0s.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uMn0s.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 10&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Still not giving up, learning alot, but getting abit crazy at this problem.&#xA;So now when I look at the reconstructed using &lt;em&gt;fract(position)&lt;/em&gt;. This below is what I get (right side is the fract part, left side is just the scene with diffuse point light moving around wrongly).&lt;/p&gt;&#xA;&lt;p&gt;the position seems to be correct now when I look at it, as each texture on left side is one unit. and that is matching the the reconstructed position:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OGmFp.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OGmFp.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However, as Nathan pointed out. I can look at &lt;em&gt;fract(vPos)&lt;/em&gt; in the fist pass, that is how the reconstructed position also should look.&lt;/p&gt;&#xA;&lt;p&gt;And still, this is how it looks like, from the first pass:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tEtux.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tEtux.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;That one makes less sence for me, should I not be able to see the fractions in the same way there? For me the reconstructed one makes more sence&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit 11&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;New findings!&lt;/p&gt;&#xA;&lt;p&gt;I did fract directly in the first pass, to see how it looks like. I did not think about the values getting changed when saved to texture, so I was not looking at what I though before.&lt;/p&gt;&#xA;&lt;p&gt;Anyways, it looks exactly the same as the reconstructed values, see below!&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GQvMR.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GQvMR.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;So I belive now I have the right constructed depth. But however, still having the same issues as always, light seems to rotate around when I am moving.&lt;/p&gt;&#xA;" OwnerUserId="13963" LastEditorUserId="13963" LastEditDate="2020-09-16T20:26:34.063" LastActivityDate="2020-09-16T20:35:01.003" Title="OpenGL - Recreate position in viewspace from depth values" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;lighting&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10224" PostTypeId="1" CreationDate="2020-09-14T05:08:06.293" Score="1" ViewCount="53" Body="&lt;p&gt;I have Wu's line algorithm but I don't understand all the lines of code very well.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;public static void drawLine(Graphics g, double x0, double y0, double x1, double y1, int value) {&#xA;     &#xA;        boolean steep = abs(y1 - y0) &amp;gt; abs(x1 - x0);&#xA;        if (steep)&#xA;            drawLine(g, y0, x0, y1, x1, value);&#xA;     &#xA;        if (x0 &amp;gt; x1)&#xA;            drawLine(g, x1, y1, x0, y0, value);&#xA;     &#xA;        double dx = x1 - x0;&#xA;        double dy = y1 - y0;&#xA;        double gradient = dy / dx;&#xA;     &#xA;        // handle first endpoint&#xA;        double xend = round(x0);&#xA;        double yend = y0 + gradient * (xend - x0);&#xA;        double xgap = rfpart(x0 + 0.5);&#xA;        double xpxl1 = xend; // this will be used in the main loop&#xA;        double ypxl1 = ipart(yend);&#xA;     &#xA;        if (steep) {&#xA;            plot(g, ypxl1, xpxl1, rfpart(yend) * xgap);&#xA;            plot(g, ypxl1 + 1, xpxl1, fpart(yend) * xgap);&#xA;        } else {&#xA;            plot(g, xpxl1, ypxl1, rfpart(yend) * xgap);&#xA;            plot(g, xpxl1, ypxl1 + 1, fpart(yend) * xgap);&#xA;        }&#xA;     &#xA;        // first y-intersection for the main loop&#xA;        double intery = yend + gradient;&#xA;     &#xA;        // handle second endpoint&#xA;        xend = round(x1);&#xA;        yend = y1 + gradient * (xend - x1);&#xA;        xgap = fpart(x1 + 0.5);&#xA;        double xpxl2 = xend; // this will be used in the main loop&#xA;        double ypxl2 = ipart(yend);&#xA;     &#xA;        if (steep) {&#xA;            plot(g, ypxl2, xpxl2, rfpart(yend) * xgap);&#xA;            plot(g, ypxl2 + 1, xpxl2, fpart(yend) * xgap);&#xA;        } else {&#xA;            plot(g, xpxl2, ypxl2, rfpart(yend) * xgap);&#xA;            plot(g, xpxl2, ypxl2 + 1, fpart(yend) * xgap);&#xA;        }&#xA;     &#xA;        // main loop &#xA;        for (double x = xpxl1 + 1; x &amp;lt;= xpxl2 - 1; x++) {&#xA;            if (steep) {&#xA;                plot(g, ipart(intery), x, rfpart(intery));&#xA;                plot(g, ipart(intery) + 1, x, fpart(intery));&#xA;            } else {&#xA;                plot(g, x, ipart(intery), rfpart(intery));&#xA;                plot(g, x, ipart(intery) + 1, fpart(intery));&#xA;            }&#xA;            intery = intery + gradient;&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I know this information:&lt;/p&gt;&#xA;&lt;p&gt;The intensity of the pixel above the line must be proportional to (1-a), and the intensity of the pixel below the line must be proportional to (1-b). I.E. the closer the line is to a pixel, the brighter it is.&lt;/p&gt;&#xA;&lt;p&gt;Why are the following steps necessary:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;handle the first endpoint?&lt;/li&gt;&#xA;&lt;li&gt;handle the second endpoint?&lt;/li&gt;&#xA;&lt;li&gt;main loop?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="13964" LastEditorUserId="13095" LastEditDate="2020-09-14T07:15:50.813" LastActivityDate="2020-09-14T07:15:50.813" Title="How can i understand the algorithm wu line?" Tags="&lt;antialiasing&gt;&lt;line-drawing&gt;&lt;java&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10225" PostTypeId="1" AcceptedAnswerId="10227" CreationDate="2020-09-15T02:32:10.067" Score="0" ViewCount="58" Body="&lt;p&gt;If I were to create a chainmail that has realistic reflections, where would I start learning about what mechanisms to use? Normal cloth seems too simple, and the reflections look bad (they have to be in the texture, or the cloth would have to be metalic). If I did it as a series of toroids, physics would have problems with colisions, or they would just overlap weirdly. Maybe there is a hybrid approach? Where can I read about this problem?&lt;/p&gt;&#xA;" OwnerUserId="13967" LastActivityDate="2020-09-15T13:08:01.490" Title="Realistic chainmail reflections for videogames" Tags="&lt;reflection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10226" PostTypeId="1" CreationDate="2020-09-15T06:20:28.120" Score="1" ViewCount="23" Body="&lt;p&gt;I have real time depth data coming from an iPhone and I want to identify flat objects within the point cloud so that I can highlight the Hard edges in the images. The objects can be at any angle and I'm only looking for flat faces.&lt;/p&gt;&#xA;&lt;p&gt;I'm not a math expert and just looking for ways that this could be done relatively easily so just looking for pointers to relevant algorithms that could achieve this.&lt;/p&gt;&#xA;&lt;p&gt;ty&lt;/p&gt;&#xA;" OwnerUserId="13968" LastActivityDate="2020-09-15T06:20:28.120" Title="Finding a flat plane within iPhone depth data" Tags="&lt;mathematics&gt;&lt;depth-map&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10227" PostTypeId="2" ParentId="10225" CreationDate="2020-09-15T13:08:01.490" Score="0" Body="&lt;p&gt;It seems that you're mixing physics/engine programming with graphics programming. I wouldn't say that dealing with collisions is related to rendering.&lt;/p&gt;&#xA;&lt;p&gt;Also, I don't really understand your problem with toroids, but in case, I found one paper related to this term - &amp;quot;3D ChainMail: A Fast Algorithm for Deforming Volumetric Objects&amp;quot; by [Gibson1996]. I would say that if you're interested in creating clothing then you'll have to deal with deformations and animations and not only reflections. And, in case if you'd like to just work with reflections/rendering, then you don't need to deal with physics in any way. Static mesh would be enough, but I'm just speaking based on informations that you've provided until this point.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Normal cloth seems too simple, and the reflections look bad (they have to be in the texture, or the cloth would have to be metalic)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I wouldn't agree with that and I don't really understand what you've meant by that. In many cases, reflections are indeed in the texture. Or more specifically - cubemap, local environment map, irradiance volume and many other names, used for explaining GI voxel-based methods. &lt;a href=&quot;https://www.kostasvardis.com/files/research/PhD_Thesis_Kostas_Vardis_book_online_lowres.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.kostasvardis.com/files/research/PhD_Thesis_Kostas_Vardis_book_online_lowres.pdf&lt;/a&gt; - [Vardis2016] PhD thesis is nice place to check for methods that you might be interested in. I wouldn't say that normal cloths are too simple. I was never really interested in that area but there are number of papers and overall, creating realistic clothing in not an easy task.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Normal cloth seems too simple, and the reflections look bad&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I can only guess that by &amp;quot;bad&amp;quot;, you've meant that there are little to none reflections. That's because most of clothing is rather rough and you've got little materials with big specular term in everyday life. That's why there is little reflection to it.&lt;/p&gt;&#xA;&lt;p&gt;I don't know what is your current level of knowledge. Also, I don't know if you're going to creating real-time interactive application or if you're going to create offline renderer. In any case - if you have Turing graphics card or newer, I would suggest using Ray Tracing for most realisting reflections. You can start with cwyman tutorials - &lt;a href=&quot;http://cwyman.org/code/dxrTutors/dxr_tutors.md.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://cwyman.org/code/dxrTutors/dxr_tutors.md.html&lt;/a&gt; also you should read microsoft's and nvidia's introduction to DXR. Also, here is a relatively easy path-tracer, created by Matt Petineo - &lt;a href=&quot;https://github.com/TheRealMJP/DXRPathTracer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/TheRealMJP/DXRPathTracer&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If you get through above tutorials, then you can start reading about denoising and state of the arts methods introduced in recent years - &lt;a href=&quot;https://alain.xyz/blog/raytracing-denoising&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://alain.xyz/blog/raytracing-denoising&lt;/a&gt; Raytracing is a subject, which exists since the begining of computer graphics, so there are a lot of papers related to that. But I think that MJP's example is good enough for start. Also, read related papers that he's stating in github and his code. They're mostly related to avoiding artifacts and fireflies.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-09-15T13:08:01.490" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10228" PostTypeId="2" ParentId="10223" CreationDate="2020-09-15T16:34:21.613" Score="1" Body="&lt;p&gt;You're not correctly inverting the mapping you used to store the depth value. When storing it you use:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vDepth = -(vPos.z - NearPlane) / ( FarPlane - NearPlane);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then you reconstruct it as:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;const float depth = normalDepth.w * (FarPlane - NearPlane);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;but this misses both the offset by NearPlane, and the negative sign to flip the Z axis (since it points out of the screen in right-handed view space, but you want to store positive values). You're not getting back the same view space you started from—the space that your normals and light are in.&lt;/p&gt;&#xA;&lt;p&gt;The correct inversion should be:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;const float depth = -(normalDepth.w * (FarPlane - NearPlane) + NearPlane);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The depth values will be negative; this is correct since as mentioned Z points out of the screen in right-handed view space, so the Z values of everything you can see will be below zero. You'll have to tweak some other bits of your code to match—for instance, get rid of the negative sign when you calculate the position xy, and move the light to a negative Z value. It's this attempting to work in a space where depths are positive, while using normals in a space where depth is negative, that is most likely causing the lighting issues when rotating.&lt;/p&gt;&#xA;&lt;p&gt;Your unprojection looks like it's missing the fact that horizontal and vertical FOVs are not the same. You need the aspect ratio in there (same way as used to calculate the projection matrix). In fact, you can just use the scale factors from the projection matrix.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 position = vec3(vDeviceCoords.x / ProjectionMatrix[0][0], vDeviceCoords.y / ProjectionMatrix[1][1], 1.0);&#xA;position *= depth;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;You could also precalculate those 1/ProjectionMatrix values in a separate uniform value if you liked.&lt;/p&gt;&#xA;&lt;p&gt;Finally, I'll just note that you don't need to store a depth value explicitly in a channel of a framebuffer somewhere. It's possible to bind the actual depth buffer as a texture and read that. It's stored using a nonlinear mapping so it takes a bit more code to recover a linear depth value from it, but this ends up being the best way as you get the full precision of the hardware depth buffer, and it doesn't consume a framebuffer channel that you could use for something else. For more information, see &lt;a href=&quot;https://mynameismjp.wordpress.com/2010/09/05/position-from-depth-3/&quot; rel=&quot;nofollow noreferrer&quot;&gt;MJP's Position from Depth 3 post&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-15T16:55:12.223" LastActivityDate="2020-09-15T16:55:12.223" CommentCount="10" ContentLicense="CC BY-SA 4.0" />
  <row Id="10229" PostTypeId="2" ParentId="10216" CreationDate="2020-09-16T07:42:54.283" Score="1" Body="&lt;p&gt;Problem was that perspective matrix had very short Z_NEAR and Z_FAR values (0.01f and 200.0f). By changing it to much higher range (10.0f, 20000.0f), problem with jaggies and artifacts disappears.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-09-16T07:42:54.283" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10230" PostTypeId="2" ParentId="10223" CreationDate="2020-09-16T20:23:31.983" Score="1" Body="&lt;p&gt;Ok. So Finally, I have solved the problem. This problem I been working on for a couple of weeks. Had to go through several books in math, gamedev etc. Went through all my code, to see if I had something I did missunderstand.&lt;/p&gt;&#xA;&lt;p&gt;Finally I found the problem! I was trying to store normals in the texture, with values between [-1, 1], I did not think about the values stored in the texture has to be [0, 1].&lt;/p&gt;&#xA;&lt;p&gt;So I normalized them to [0, 1]. And then in the second pass I the normalize them back to [-1, 1], and finally, after many long nights of search, the problem has been found!&lt;/p&gt;&#xA;&lt;p&gt;Hope this will help others also! And thanks everyone who had a look!&lt;/p&gt;&#xA;&lt;p&gt;SOLVED!&lt;/p&gt;&#xA;" OwnerUserId="13963" LastEditorUserId="13963" LastEditDate="2020-09-16T20:35:01.003" LastActivityDate="2020-09-16T20:35:01.003" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10231" PostTypeId="1" AcceptedAnswerId="10241" CreationDate="2020-09-16T20:55:20.040" Score="2" ViewCount="72" Body="&lt;p&gt;I have searched this topic for very long time and have found basically no information on it.&lt;/p&gt;&#xA;&lt;p&gt;If we have a 3d model with a uv layout. What is the basic technique for 3d painting on said model with a brush? A brush stroke consists of the brush pixel data/image laid out in succession. So do we project each individual brush image onto the surface of the object? (Although in actuality to do this we would be projecting the object onto the image space instead). I have managed to project textures onto objects before. And projecting each individual brush image definitely seems feasible, but I'm not sure if it's practical from performance standpoint and whether there're better techniques.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sSfgM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sSfgM.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-09-18T08:18:03.573" Title="How to paint onto 3d models" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;image-processing&gt;&lt;uv-mapping&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10232" PostTypeId="2" ParentId="7809" CreationDate="2020-09-16T20:57:30.947" Score="4" Body="&lt;p&gt;For Nvidia GPUs there are several machine languages all of which can be read here:&#xA;&lt;a href=&quot;https://docs.nvidia.com/cuda/cuda-binary-utilities/index.html#instruction-set-ref&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.nvidia.com/cuda/cuda-binary-utilities/index.html#instruction-set-ref&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Above the &amp;quot;Instruction Set Reference&amp;quot; section there are also some examples on SM70 variant of SASS code which is stored in ELF and dumped from there too so it's a machine code as ELF always was an unmanaged code container by historic reasons (apart from PE which could contain CIL managed code but even in this case it must be in data section while ELF does not support such confusing feature at all) and it's not managed/virtual bytecode or something as some users say so, it's a real native compiled device code for GPU. The correct instructions though are those which are written with capital letter and addresses in hexademical form (like /*0000*/ MOV R1, c[0x0][0x28] ;), others are just PTX and they aren't actually relevant to the question. As a drawback, fatbin technique may be required if a distributor has chosen to publish the GPU program in precompiled form rather than source code or at least portable PTX. But that is very rare as there are not as much such programs around as binaries for CPU. Anyway such code is usually contained within cubin files which are dynamically loaded by calling &amp;quot;cuModuleLoad&amp;quot; then you rewrite pointer to device GPU function handle using &amp;quot;cuModuleGetFunction&amp;quot; and then call &amp;quot;cuLaunchKernel&amp;quot; which forces the driver to send binary code to the GPU and start execution from like 0 address as all the kernels start from 0 (actually ELF variant used by Nvidia contains many sections but the driver only sends the desired kernel code along with its subroutines and data such as switch data etc.). And what about the instructions itself, well, they are mostly RISC-fashioned. There is no div or mod, instead nvcc compiler must output sophisticated algorithm based on addition, subtraction, multiplication, shifts, bitwise logical operations (bitwise and mostly). Only addressing mode reminds some CISC presence like &amp;quot;LD R2, [R2+0x1c];&amp;quot; etc.&lt;/p&gt;&#xA;" OwnerUserId="13979" LastEditorUserId="13979" LastEditDate="2020-09-16T21:06:30.297" LastActivityDate="2020-09-16T21:06:30.297" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10233" PostTypeId="2" ParentId="10231" CreationDate="2020-09-17T00:19:37.630" Score="0" Body="&lt;p&gt;You could do it in different ways.&lt;/p&gt;&#xA;&lt;p&gt;But the most logical way for me is that there are points sampled along the path, then splines/benzier curves are used to make it smooth (additonal points can be interpolated), thereafter it is projected and saved on the texture. So no &amp;quot;every&amp;quot; point has to be sampled.&lt;/p&gt;&#xA;" OwnerUserId="13963" LastActivityDate="2020-09-17T00:19:37.630" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10234" PostTypeId="2" ParentId="10103" CreationDate="2020-09-17T00:27:18.857" Score="2" Body="&lt;p&gt;I belive what you are looking for is a scale Matrix, or actually it will end upp with as a shear matrix for you.&lt;/p&gt;&#xA;&lt;p&gt;Usually they look like this&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Sx  0   0   0&#xA;0   Sy  0   0&#xA;0   0  Sz   0&#xA;0   0  0    1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If you have no scaling, Sx, Sy, Sz represent the scaling in corresponding dimension.&#xA;So put the to 1 for no scaling.&lt;/p&gt;&#xA;&lt;p&gt;But now you want to scale the height depending on the z value. So we want to modify it abit. If you would put Sx, Sy, Sz to the value one. And the put a higher value than one on Syz, then it would scale the height (Y), the futher away you are.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Sx  0    0   0&#xA;0   Sy  Syz  0&#xA;0   0   Sz   0&#xA;0   0   0    1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13963" LastEditorUserId="13963" LastEditDate="2020-09-17T02:38:58.390" LastActivityDate="2020-09-17T02:38:58.390" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10235" PostTypeId="1" CreationDate="2020-09-17T00:54:48.760" Score="1" ViewCount="58" Body="&lt;p&gt;So to make it simple. I currently use a method I found online to compute the gradient of a scalar field of a mesh.&lt;/p&gt;&#xA;&lt;p&gt;To test how accurate this is, I made a sphere and followed the gradient direction of the geodesic field to construct a line. That is to say, pick &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; on the sphere and define &lt;span class=&quot;math-container&quot;&gt;$\phi(X)$&lt;/span&gt; the function that return the geodesic distance between &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;By a property of the exponential map described by Manfredo Do Carmo, the geodesic gradient (the tangent) at &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; uniquely describes the geodesic containing both &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In short, if you know the correct tangent at &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; you can just follow that direction in the exponential map and eventually hit the source &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So I went and coded exactly that:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4BaIL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4BaIL.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In that image, the source &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is at the intersection of the 3 lines in the bottom part of the image. So my line passes very close to it, but it doesn't hit.&lt;/p&gt;&#xA;&lt;p&gt;My assumption is, this happens because my gradient approximation is quite linearly based and as such even small errors quickly have big effects, especially as the points grow farther apart.&lt;/p&gt;&#xA;&lt;p&gt;I am wondering  if people know of methods or algorithms that can improve the accuracy of the gradient.&lt;/p&gt;&#xA;&lt;p&gt;I got the formula for the discrete gradient at page 28 &lt;a href=&quot;http://www.hao-li.com/cs599-ss2015/slides/Lecture04.1.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2021-02-14T02:07:00.720" Title="Improve accuracy of mesh gradient?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;gradient&gt;&lt;differential&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10236" PostTypeId="2" ParentId="10235" CreationDate="2020-09-17T01:18:11.827" Score="0" Body="&lt;p&gt;I dont know what you are using to calculate the Cotan, the accuracy should different on the implementation.&lt;/p&gt;&#xA;&lt;p&gt;But you could do more accurate calculations yourself by approximating the values using taylor expansions.&lt;/p&gt;&#xA;&lt;p&gt;Or find some other librar that can do it more accurate.&lt;/p&gt;&#xA;&lt;p&gt;Also, make sure you are using high prec datatypes.&lt;/p&gt;&#xA;" OwnerUserId="13963" LastActivityDate="2020-09-17T01:18:11.827" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10237" PostTypeId="1" CreationDate="2020-09-17T16:46:34.577" Score="2" ViewCount="46" Body="&lt;p&gt;Since there is a lot of cross-section between computer vision and computer graphics for 3D pose and shape estimation of non-rigid objects, I would like to know what &amp;quot;blend shape&amp;quot;, &amp;quot;pose blend shape&amp;quot; and &amp;quot;shape blend shape,&amp;quot; exactly mean in 3D modeling of human shape and pose?&lt;/p&gt;&#xA;" OwnerUserId="6281" LastActivityDate="2020-09-19T19:25:53.073" Title="Blend Shape, Pose Blend Shape, and Shape Blend Shape" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10238" PostTypeId="2" ParentId="8790" CreationDate="2020-09-17T18:28:50.277" Score="0" Body="&lt;p&gt;The terminology you are looking for is &amp;quot;Volume Renderig&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;A MRI scan scans a &amp;quot;volume&amp;quot; (object). You get a point cloude, with different density of different matter, for example skin/blood har different density. The you can use the point cloud to do volune rendering.&lt;/p&gt;&#xA;&lt;p&gt;So what you want to do is go make your mest Into a point cloud, with density, density depending on what matter the volume contains. Then you want to har that data for volume rendering.&lt;/p&gt;&#xA;&lt;p&gt;Then you can yourself decide how/what to render, slice through the data or whatever&lt;/p&gt;&#xA;" OwnerUserId="13963" LastEditorUserId="13963" LastEditDate="2020-09-17T19:57:54.240" LastActivityDate="2020-09-17T19:57:54.240" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10239" PostTypeId="2" ParentId="8790" CreationDate="2020-09-18T07:52:13.190" Score="0" Body="&lt;p&gt;A way to create the image (texture) of just a slice can be done by positioning the camera orthogonal above the slice you want to create.&#xA;The second step is to add two clipping planes very close to each other slightly above and below the slice and render the geometry (mesh) into a Frame Buffer Object (FBO).&#xA;From the FBO you can load the texture to CPU side and save it as PNG file.&lt;/p&gt;&#xA;&lt;p&gt;The result you'll get is the silhouette of your 3D model of the slice.&#xA;The result is of cause not perfect, because there is a small distance between the two clipping planes... But it is an very easy way to generate it.&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-09-18T07:52:13.190" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10240" PostTypeId="2" ParentId="10231" CreationDate="2020-09-18T08:13:41.680" Score="1" Body="&lt;p&gt;As long as no pixel on the texture is used twice, you can render the geometry and display the uv-coordinates (texture coordinates). Usually they are a combination of red and green (2d).&#xA;When using a brush, you only need to read out the uv-coordinates you've hit and color the texture at position (uv) in the desired color.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Hint:&lt;/strong&gt;&#xA;paint onto a second texture, so you'll not destroy the original texture color.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Drawbacks:&lt;/strong&gt;&#xA;Sometimes the texture resolution of different triangles within a geometry vary. So at some faces it will look nice, and on others it will be pixelated.&lt;/p&gt;&#xA;&lt;p&gt;As said before, if the mesh (geometry) uses the same part of a texture twice (two faces aiming at the same texture coordinates), and you draw on one of them, the other will be painted as well.&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-09-18T08:13:41.680" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10241" PostTypeId="2" ParentId="10231" CreationDate="2020-09-18T08:18:03.573" Score="1" Body="&lt;p&gt;I can't give you a &amp;quot;better&amp;quot; approach here, but I think that the approach to&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;project each individual brush image onto the surface of the object&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;is not really a performance issue if you implement that using the GPU. Especially in an editor environment, where not much is going on in comparison to a computer game. All you basically want to do is to render a single image per frame onto a limited set of textures. I can give you a draft of how I would approach the subject if I needed this feature. However, since I haven't implemented it myself yet, there might be some complications and problems I haven't thought of so let me know in the comments if something doesn't work as expected.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Find the affected surfaces&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Use the corners of your brush texture and generate a reduced brush projection frustum&lt;/li&gt;&#xA;&lt;li&gt;Check all objects against it and find the closest surfaces -&amp;gt; If you already use some kind of culling for your scene, reuse the already culled object list, since the brush can only &amp;quot;see&amp;quot; what the camera sees&lt;/li&gt;&#xA;&lt;li&gt;Identify the subsurfaces/triangles affected by the brush&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Gather all affected textures. You should know for each surface that is affected, which texture it possesses. Optimally, your whole object has just a single UV texture.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Create a shader program to render to your texture.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;be careful, the vertex shader has to calculate the normalized UV coordinates and pass them down the pipeline as the vertex position, since they are the position in your texture. Check what additional information you need to pass down the pipeline.&lt;/li&gt;&#xA;&lt;li&gt;In the fragment shader, overwrite each pixel that is under the brush. You might need to use blending here for non-rectangular brushes.&lt;/li&gt;&#xA;&lt;li&gt;The brush position is a little bit tricky. You need it in the textures UV space in the fragment shader and I am not sure if you can calculate it in the vertex shader. So you might need to do that in the fragment shader or alternatively in a geometry shader. The problem I see is that the angle in which the brush projection hits the surface can't be calculated in the vertex shader and it is necessary to determine the covered area. The geometry shader has enough information to calculate the angle and the covered area. In the fragment shader, you can't calculate the angle either, but there you can simply check if and where it is located in the brush projection frustum.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Now simply render to your textures.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Bind your brush texture&lt;/li&gt;&#xA;&lt;li&gt;For each affected texture&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Bind the texture as render target&lt;/li&gt;&#xA;&lt;li&gt;Render all affected objects and let the GPU sort out which pixels need to be overwritten.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;(Optional) If you want to save your modifications, you need to read back the textures from the GPU and save it.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Since the main work is done by the GPU, it should be quite fast. However, I can see some problems with the described approach when the brush hits multiple objects/textures that are partially overlapping. Sorting out which pixel of the brush affects which texture/object can get messy. There might be some stencil/depth buffer tricks one can apply, but I think this is a topic for another question.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-09-18T08:18:03.573" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10242" PostTypeId="1" AcceptedAnswerId="10244" CreationDate="2020-09-19T12:08:24.423" Score="1" ViewCount="113" Body="&lt;p&gt;I'm in process of creating progressive path tracer using DX12 + DXR. I managed to create working raytracing code + pathtracing code with multiple bounces but I'm experiencing problems stated below (after full RT code):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[shader(&amp;quot;raygeneration&amp;quot;)]&#xA;void RayGen()&#xA;{&#xA;    // Accumulate for limited amount of frames&#xA;    if (g_giCB.maxFrames &amp;gt; 0 &amp;amp;&amp;amp; g_giCB.accFrames &amp;gt;= g_giCB.maxFrames)&#xA;    {&#xA;        return;&#xA;    }&#xA;    uint2 LaunchIndex = DispatchRaysIndex().xy;&#xA;    uint2 LaunchDimensions = DispatchRaysDimensions().xy;&#xA;    float4 normalAndDepth = NormalTextureInput.Load(int3(LaunchIndex, 0));&#xA;&#xA;    // No geometry hit - skip pixel and use skybox data&#xA;    if (normalAndDepth.w == 0)&#xA;    {&#xA;        RTOutput[LaunchIndex] = albedoTexture.Load(int3(LaunchIndex, 0));&#xA;        return;&#xA;    }&#xA;    &#xA;    // Calculate primary ray direction&#xA;    uint seed = initRand(LaunchIndex.x + LaunchIndex.y * LaunchDimensions.x, g_sceneCB.frameCount, 16);&#xA;    uint seed2 = 0;&#xA;    float2 offset = float2(0, 0);&#xA;    if (g_giCB.samplingType == SAMPLE_UNIFORM)&#xA;    {&#xA;        seed2 = initRand(LaunchIndex.x + LaunchIndex.y * LaunchDimensions.x, g_sceneCB.frameCount, 17);&#xA;        offset = HammersleyDistribution(g_giCB.accFrames, g_giCB.maxFrames, uint2(seed, seed2));&#xA;    }&#xA;    else if (g_giCB.samplingType == SAMPLE_MJ)&#xA;    {&#xA;        const uint pixelIdx = LaunchIndex.y * LaunchDimensions.x + LaunchIndex.x;&#xA;        uint sampleSetIdx = 0;&#xA;        offset = SamplePoint(pixelIdx, sampleSetIdx);&#xA;        seed = pixelIdx;&#xA;        seed2 = sampleSetIdx;&#xA;    }&#xA;    &#xA;    float3 primaryRayOrigin = g_sceneCB.cameraPosition.xyz;&#xA;    float3 primaryRayDirection;&#xA;    GenerateCameraRay(LaunchIndex, LaunchDimensions, g_sceneCB.projectionToWorld, primaryRayOrigin, primaryRayDirection, offset);&#xA;    &#xA;    // Prepare payload&#xA;    PayloadIndirect indirectPayload;&#xA;    indirectPayload.color = float3(0, 0, 0);&#xA;    indirectPayload.rndSeed = seed;&#xA;    indirectPayload.rndSeed2 = seed2;&#xA;    indirectPayload.pathLength = 0;&#xA;        &#xA;    // Calculate pixel color in current pass and merge with previous frames&#xA;    float4 finalColor = float4(shootIndirectRay(primaryRayOrigin, primaryRayDirection, 1e-3f, indirectPayload), 1.0f);&#xA;    float4 prevScene = RTOutput[LaunchIndex];&#xA;    finalColor = ((float) g_giCB.accFrames * prevScene + finalColor) / ((float) g_giCB.accFrames + 1.0f);&#xA;    RTOutput[LaunchIndex] = finalColor;&#xA;}&#xA;&#xA;[shader(&amp;quot;miss&amp;quot;)]&#xA;void Miss(inout RayPayload payload : SV_RayPayload)&#xA;{&#xA;    payload.vis = 1.0f;&#xA;}&#xA;&#xA;[shader(&amp;quot;closesthit&amp;quot;)]&#xA;void ClosestHit(inout PayloadIndirect payload, in BuiltInTriangleIntersectionAttributes attribs)&#xA;{&#xA;&#xA;}&#xA;&#xA;[shader(&amp;quot;miss&amp;quot;)]&#xA;void MissIndirect(inout PayloadIndirect payload : SV_RayPayload)&#xA;{&#xA;    // Use skybox as contribution if ray failed to hit geometry (right now, disabled for debug purposes)&#xA;    float3 rayDir = WorldRayDirection();&#xA;    rayDir.z = -rayDir.z;&#xA;    if (g_giCB.useSkybox)&#xA;    {&#xA;        payload.color += skyboxTexture.SampleLevel(g_sampler, rayDir, 0).rgb;&#xA;    }&#xA;}&#xA;&#xA;[shader(&amp;quot;closesthit&amp;quot;)]&#xA;void ClosestHitIndirect(inout PayloadIndirect payload, in BuiltInTriangleIntersectionAttributes attribs)&#xA;{&#xA;    // Load hit data&#xA;    float3 hitPos = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();&#xA;    float3 triangleNormal, triangleTangent, triangleBitangent;&#xA;    loadHitData(triangleNormal, triangleTangent, triangleBitangent, attribs);&#xA;&#xA;    // Use white albedo for all textures (DEBUG version)&#xA;    float4 albedo = albedoTexture.Load(int3(DispatchRaysIndex().xy, 0));&#xA;    albedo = float4(1, 1, 1, 1);&#xA;    &#xA;    // Iterate over all lights&#xA;    float lightsCount = g_lightCB.lightPositionAndType[15].w;&#xA;    for (int i = 0; i &amp;lt; lightsCount; i++)&#xA;    {&#xA;        // Calculate each light data&#xA;        float3 lightColor = g_lightCB.lightDiffuseColor[i].rgb;&#xA;        float3 toLight = g_lightCB.lightPositionAndType[i].xyz - hitPos;&#xA;        float distToLight = length(toLight);&#xA;        toLight = normalize(toLight);&#xA;        &#xA;        // Check visibility&#xA;        float NoL = saturate(dot(triangleNormal.xyz, toLight));&#xA;        float visibility = shadowRayVisibility(hitPos, toLight, 1e-3f, distToLight);&#xA;&#xA;        // Calculate light contribution to point in world (diffuse lambertian term)&#xA;        payload.color += visibility * NoL * albedo.rgb * INV_PI;&#xA;    }&#xA;    &#xA;    if (g_giCB.useIndirect == 1)&#xA;    {&#xA;        // Continue spawning rays if path left has not reached maximum&#xA;        if (payload.pathLength &amp;lt; g_giCB.bounceCount)&#xA;        {&#xA;            // Find next direction&#xA;            float3 rayDirWS = float3(0, 0, 0);&#xA;            if (g_giCB.samplingType == SAMPLE_UNIFORM)&#xA;            {&#xA;                float3x3 tangentToWorld = float3x3(triangleTangent, triangleBitangent, triangleNormal);&#xA;                float2 hammersley = HammersleyDistribution(payload.pathLength, g_giCB.bounceCount, uint2(payload.rndSeed, payload.rndSeed2));&#xA;                float3 rayDirTS = UniformSampleHemisphere(hammersley.x, hammersley.y);&#xA;                rayDirWS = normalize(mul(rayDirTS, tangentToWorld));&#xA;            }&#xA;            else if (g_giCB.samplingType == SAMPLE_MJ)&#xA;            {&#xA;                float3x3 tangentToWorld = float3x3(triangleTangent, triangleBitangent, triangleNormal);&#xA;                float2 brdfSample = SamplePoint(payload.rndSeed, payload.rndSeed2);&#xA;                float3 rayDirTS = SampleDirectionCosineHemisphere(brdfSample.x, brdfSample.y);&#xA;                rayDirWS = normalize(mul(rayDirTS, tangentToWorld));&#xA;            }&#xA;            else if (g_giCB.samplingType == SAMPLE_RANDOM)&#xA;            {&#xA;                rayDirWS = getCosHemisphereSample(payload.rndSeed, triangleNormal, triangleTangent, triangleBitangent);&#xA;                nextRand(payload.rndSeed);&#xA;            }&#xA;            &#xA;            // Prepare payload&#xA;            PayloadIndirect newPayload;&#xA;            newPayload.pathLength = payload.pathLength + 1;&#xA;            newPayload.rndSeed = payload.rndSeed;&#xA;            newPayload.rndSeed2 = payload.rndSeed2;&#xA;            newPayload.color = float3(0, 0, 0);&#xA;            &#xA;            // Calculate next ray bounce color contribution&#xA;            float3 bounceColor = shootIndirectRay(hitPos, rayDirWS, 1e-3f, newPayload);&#xA;            payload.color += bounceColor * albedo.rgb;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;1. Image doesn't converge to ground truth over time&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am using only Lambertian BRDF term in my code, while implementing multi sampling schemes (Multi-Jittered sampling, Uniform sampling and random direction sampling). All of them provides similar results, hardly possible to distinguish. Here is an image generated with almost 5000 frames. It doesn't differ from image generated with about 100 frames. I am using albedo = (1,1,1) for all textures, for debug purposes in this image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pBCoI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pBCoI.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It looks even much more noisy when source of light is outside the window and the you can can never access light directly except primary ray (situation similar to described here - &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_III_Bidirectional_Methods/Bidirectional_Path_Tracing.html&lt;/a&gt; ). Therefore I placed point light in the middle of room for simpler example.&lt;/p&gt;&#xA;&lt;p&gt;I'm not suspecting my equation to be incorrect, because:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L_o(\textbf{p}, \mathbf{w_o}) = L_e + \int_{\Omega} L_i(\textbf{p}, \mathbf{w_i}) fr(\mathbf{w_o}, \mathbf{w_i}) \cos \theta d\omega&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{1}{N} \sum_{k=1}^{N} \frac{ L_i(\textbf{p}, \mathbf{w_k}) fr(\mathbf{w_k}, w_o) \cos \theta }{p(\mathbf{w_k})}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Monte Carlo equation above will be simplified, because I have single light with intensity = 1.0, so &lt;span class=&quot;math-container&quot;&gt;$L_i$&lt;/span&gt; term will be terminated. BRDF for Lambertian diffuse is equal to NdotL (I'll be using notation &lt;span class=&quot;math-container&quot;&gt;$NoL$&lt;/span&gt;). PDF for sampling cosine hemisphere is &lt;span class=&quot;math-container&quot;&gt;$NoL / \pi$&lt;/span&gt;. Let's simplify equation for now:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{1}{N} \sum_{k=1}^{N} \frac{ \cos \theta }{\pi}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Which is basically:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{1}{N} \sum_{k=1}^{N} \frac{ NoL }{\pi}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;And translates to code as:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;color = NoL * INV_PI;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However, we need to check if light &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; that we're referring to is visible, therefore full equation, which could be seen in code is:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Calculate light contribution to point in world (diffuse lambertian term)&#xA;payload.color += visibility * NoL * albedo.rgb * INV_PI;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Regarding sampling, I've tried multiple method, especially I was hopeful about Multi-Jittered sampling &lt;a href=&quot;https://graphics.pixar.com/library/MultiJitteredSampling/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;[Kensler2013]&lt;/a&gt;. I am using native implementation, copied from &lt;a href=&quot;https://github.com/TheRealMJP/DXRPathTracer&quot; rel=&quot;nofollow noreferrer&quot;&gt;MJP's Path Tracer&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;2. Oversaturation of albedo textures&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ywhkI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ywhkI.jpg&quot; alt=&quot;Primary ray + single bounce image with albedo textures&quot; /&gt;&lt;/a&gt;&#xA;&lt;em&gt;Primary ray + single bounce image with albedo textures&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Lm27V.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Lm27V.jpg&quot; alt=&quot;Primary ray + 4 ray bounces image; Notice oversaturation of albedo textures&quot; /&gt;&lt;/a&gt;&#xA;&lt;em&gt;Primary ray + 4 ray bounces image; Notice oversaturation of albedo textures&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;If I simplify code to the maximum, then ray bounces boils down to very few lines of code used in practice. The problem might be adding albedo too many times but I checked it for sure, and both MJP and &lt;a href=&quot;http://cwyman.org/code/dxrTutors/tutors/Tutor14/tutorial14.md.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;cwyman&lt;/a&gt; are using same code for calculating path tracing (multiple bounces of rays).&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[shader(&amp;quot;closesthit&amp;quot;)]&#xA;void ClosestHitIndirect(inout PayloadIndirect payload, in BuiltInTriangleIntersectionAttributes attribs)&#xA;{&#xA;    float4 albedo = // ...&#xA;    &#xA;    // Use single light&#xA;    float3 toLight = g_lightCB.lightPositionAndType[0].xyz - hitPos;&#xA;    float distToLight = length(toLight);&#xA;    toLight = normalize(toLight);&#xA;        &#xA;    // Check visibility&#xA;    float NoL = saturate(dot(triangleNormal.xyz, toLight));&#xA;    float visibility = shadowRayVisibility(hitPos, toLight, 1e-3f, distToLight);&#xA;&#xA;    // Calculate light contribution to point in world (diffuse lambertian term)&#xA;    payload.color += visibility * NoL * albedo.rgb * INV_PI;&#xA;    &#xA;    if (g_giCB.useIndirect == 1)&#xA;    {&#xA;        // Continue spawning rays if path left has not reached maximum&#xA;        if (payload.pathLength &amp;lt; g_giCB.bounceCount)&#xA;        {&#xA;            // Find next direction&#xA;            float3 rayDirWS = // ... multiple lighting schemes, check full code above&#xA;            &#xA;            // Prepare payload&#xA;            PayloadIndirect newPayload;&#xA;            newPayload.pathLength = payload.pathLength + 1;&#xA;            newPayload.rndSeed = payload.rndSeed;&#xA;            newPayload.rndSeed2 = payload.rndSeed2;&#xA;            newPayload.color = float3(0, 0, 0);&#xA;            &#xA;            // Calculate next ray bounce color contribution&#xA;            float3 bounceColor = shootIndirectRay(hitPos, rayDirWS, 1e-3f, newPayload);&#xA;            payload.color += bounceColor * albedo.rgb;&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;For now, I'd like to creating converging diffuse path tracer. I'll continue with Specular GGX in order to have a ground truth reference for Bidirectional Path Tracing and other methods, which can speed up converging rate of an image. Thanks in advance for all your advices.&lt;/p&gt;&#xA;&lt;p&gt;Also, for future readers - I'd recommend checking questions below, which are related to the topic, but didn't manage to solve my problems:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/3972/is-it-expected-that-a-naive-path-tracer-takes-many-many-samples-to-converge&quot;&gt;Is it expected that a naive path tracer takes many, many samples to converge?&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/245/non-real-time-raytracing&quot;&gt;Non Real Time Raytracing&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/4394/path-tracing-the-cook-torrance-brdf?rq=1&quot;&gt;Path tracing the Cook-Torrance BRDF&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit after &lt;a href=&quot;https://computergraphics.stackexchange.com/users/48/nathan-reed&quot;&gt;Nathan's Reed&lt;/a&gt; answer:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The oversaturated image looks better now. It looks a bit dull after moving from linear to sRGB space (following Nathan's order of exposure -&amp;gt; tone mapping -&amp;gt; linear_To_sRGB):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LdCy3.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LdCy3.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;em&gt;Primary ray + 4 ray bounces image; No skybox miss shader applied to fair comparison to oversaturated image before&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;However, I checked case with light source from the outside and I really like the result. There is a room for improvement, for sure, like adding some AA, moving to PBR (GGX). I doubt I'll have a time for that, but using BDPT and implementing soft shadows would definatelly improve case shown below:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MoQEu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MoQEu.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;To sum up for future reference:&lt;/strong&gt; adding tone mapper (on top of existing exposure settings) and moving from linear to sRGB space helped with oversaturation. Using R16G16B16A16_FLOAT instead of R8B8G8A8_UNORM format for backbuffer and target output textures, solved problem with not converging images. In the future, R32G32B32A32_FLOAT might be used, but with my current DX12 setup, this format causes errors when used in backbuffer and I cannot change that for now. 4x16 format proved to be enough for now, so I'll stay with that.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-09-21T10:41:25.580" LastActivityDate="2020-09-21T10:41:25.580" Title="Path tracing - cannot converge diffuse sampling + oversaturation" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;sampling&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10243" PostTypeId="2" ParentId="8916" CreationDate="2020-09-19T12:37:45.167" Score="1" Body="&lt;p&gt;The problem is definitely a lack of linker flags.&lt;/p&gt;&#xA;&lt;p&gt;It can see that you want to include &amp;lt;SDL/SDL2.h&amp;gt;, which is a sort of promise that said functions contained in that header have been built and will be available; but when your linker looks to find the actual machine code, it needs a little more than the header. It needs the &lt;em&gt;library&lt;/em&gt; itself.&lt;/p&gt;&#xA;&lt;p&gt;For SDL2, you would usually use something like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;gcc -g main.c -o ../ludo -lSDL2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;On Linux, this is more-or-less the same command, but for complete definitions it also instructs the compiler to look inside &lt;code&gt;/usr/lib/x86_64-linux-gnu/libSDL2.a&lt;/code&gt; (or wherever it is on your system). Note that the &lt;code&gt;lib&lt;/code&gt; prefix on the file name is assumed, and the extension is irrelevant.&lt;/p&gt;&#xA;&lt;p&gt;Do that, and your program should compile. Note that some SDL extensions, like Image and Mixer, require their own libraries. An SDL-specific shortcut to ensure that you've got everything is to use the handy &lt;code&gt;pkg-config&lt;/code&gt;, like so:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;gcc -g main.c -o ../ludo $(pkg-config --cflags --libs sdl2)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Which will be interpreted by the terminal as&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;gcc -g main.c -o ../ludo -D_REENTRANT -I/usr/include/SDL2 -lSDL2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is less generic however, a bit more paranoid, and a bit of a cheat; but perhaps it will help you.&lt;/p&gt;&#xA;&lt;p&gt;The thing to remember with C is that a function needs to be &lt;em&gt;declared&lt;/em&gt; to be used in code, and that's compiler-end; but to be built into an actual stand-alone program it also has to be &lt;em&gt;defined&lt;/em&gt;, which is where the post-compiler linker comes in.&lt;/p&gt;&#xA;" OwnerUserId="13991" LastActivityDate="2020-09-19T12:37:45.167" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10244" PostTypeId="2" ParentId="10242" CreationDate="2020-09-19T17:56:32.500" Score="3" Body="&lt;p&gt;One point: the Lambert BRDF is not &lt;span class=&quot;math-container&quot;&gt;$N\cdot L$&lt;/span&gt;, it's just the albedo divided by pi. The &lt;span class=&quot;math-container&quot;&gt;$N \cdot L$&lt;/span&gt; factor comes from the &lt;span class=&quot;math-container&quot;&gt;$\cos \theta$&lt;/span&gt; in the rendering equation. So, when sampling with a cosine-weighted distribution the &lt;span class=&quot;math-container&quot;&gt;$N \cdot L$&lt;/span&gt;s and pis will cancel out and you should just be accumulating &lt;span class=&quot;math-container&quot;&gt;$\frac{1}{N} \sum L_i * \text{albedo}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;It looks like in your code you're doing this correctly for the cosine-weighted distribution. But then in the case of the uniform hemispherical distribution you're not putting in the needed factor of &lt;span class=&quot;math-container&quot;&gt;$2(N \cdot L)$&lt;/span&gt;. (The factor of 2 comes from dividing by the uniform hemispherical pdf of 1/2π, and canceling the 1/π in the BRDF.) So I think that your uniform sampling method does not give quite correct results here.&lt;/p&gt;&#xA;&lt;p&gt;I'm not quite sure what you meant by &amp;quot;image doesn't converge to ground truth&amp;quot;. Do you mean that it's still noisy even after quite a lot of samples? The problem could be in your accumulation strategy. Depending on the bit depth of your framebuffer, after some number of frames the contribution of one more frame will be so small as to be smaller than the least-significant bit of the accumulated value. If you're using 16-bit float format for instance this will happen after about 1000 frames; if using R11G11B10_FLOAT then it will take only 30-60 frames before new accumulated values will no longer have any effect. The accumulation framebuffer should be 32-bit float at a minimum.&lt;/p&gt;&#xA;&lt;p&gt;With multiple bounces, it doesn't look like you're accounting for throughput along a path correctly. You have &lt;code&gt;payload.color += bounceColor * albedo.rgb&lt;/code&gt;, but note that this only takes account of the albedo at the current surface. If this is the Nth bounce, the color should be multiplied by the albedos of all previous surfaces in the path—since that's how this light is getting to the camera, by bouncing through all of them. The path payload structure needs to include not just an accumulated color, but a value typically called &amp;quot;throughput&amp;quot;, that contains the product of all the (BRDF * cos(theta) / pdf) factors along the path so far. On each bounce you update the throughput by multiplying in the factor for the latest bounce, then update the color by multiplying the sampled radiance with the accumulated throughput.&lt;/p&gt;&#xA;&lt;p&gt;Also, do you have any exposure control / tonemapping on the final image? An image with multiple bounces is expected to be brighter overall than the same scene with 1 bounce, as more light is being accumulated. If you don't adjust the exposure and apply a tone curve of some sort (and gamma correction), you can end up with things looking bad/wrong on screen, even if the internal HDR framebuffer is correct.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-19T18:14:09.510" LastActivityDate="2020-09-19T18:14:09.510" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10245" PostTypeId="2" ParentId="10237" CreationDate="2020-09-19T19:25:53.073" Score="2" Body="&lt;p&gt;Blend shapes, also known as morph targets, are a widely used character animation technique that helps get around the limitations of linear-blend skinning (skeletal animation). A blend shape is defined as a set of per-vertex offset vectors, usually in a localized region of a character mesh, such as a neck or upper arm. The idea is that during animation, the basic pose produced by skinning is supplemented by adding these offset vectors, scaled by an animated weight factor, prior to applying the skinning transformations. This allows character artists to model such motions as the bulging/thinning of muscles when a limb is extended or contracted, or the shifting of soft tissue around the underlying rigid skeleton, which are not captured by skinning.&lt;/p&gt;&#xA;&lt;p&gt;Blend shapes are also commonly used for facial animation, with different blend shapes representing different motions of the facial muscles, such as raising/lowering eyebrows, squinting the eyes, flaring the nostrils, moving the lips in various ways, etc. These are very difficult to model realistically using linear-blend skinning alone. By manipulating the weight factors of all these blend shapes, the animator can produce various facial expressions. A captured performance of an actor can be &amp;quot;solved&amp;quot; into animation curves for a predefined set of facial blend shapes, as a means of compression, or for transferring performance to a different face.&lt;/p&gt;&#xA;&lt;p&gt;In the most basic version of blend shapes, their weight factors are animated by hand. But their weights can also be driven programmatically by some other set of parameters—for example, by the pose of the skeleton. Essentially, you can say something like &amp;quot;whenever the elbow is bent, apply the bicep-bulging blend shape&amp;quot;, so that will happen automatically based on whatever the skeletal animation is doing, without having to animate it manually. This is broadly called &amp;quot;pose space deformation&amp;quot;, since the blend shapes (deformations) are associated with regions in &amp;quot;pose space&amp;quot;, the high-dimensional space of all the joint rotations/translations. The slide deck you posted refers to this as &amp;quot;pose blend shapes&amp;quot;, however the more standard term is &amp;quot;pose space deformation&amp;quot; (and there's plenty of literature on it).&lt;/p&gt;&#xA;&lt;p&gt;The &amp;quot;shape blend shapes&amp;quot; in that slide deck appear to be something specific to the pipeline they're describing, for creating a parameterized human model that can output many different body shapes and proportions. The &amp;quot;shape&amp;quot; parameters in the model presumably index the range of individual variation in body shape—different heights, limb lengths, hip to waist ratios, etc. They attempt to do this by starting with a single generic human mesh and applying various blend shapes (as well as moving joints around) to parameterize this space of body shapes.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-19T19:25:53.073" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10246" PostTypeId="1" CreationDate="2020-09-20T05:42:58.013" Score="2" ViewCount="53" Body="&lt;p&gt;I'm trying to figure out this problem for very long time and am no getting nowhere. I'm working on a simple 3d modeler that uses half-edge data structure.&lt;/p&gt;&#xA;&lt;p&gt;Say I have non-manifold geometry where two triangles share a common vertex, as shown in the image below. And I want to add another triangle such that now three triangles share a common vertex. Once we add the new triangle we need to reorder the half-edges around the common vertex. In 2d this ordering is done by sorting the half-edges from the common vertex clockwise, as explained in &lt;a href=&quot;https://cs.stackexchange.com/questions/2450/how-do-i-construct-a-doubly-connected-edge-list-given-a-set-of-line-segments?newreg=1d611fc139b64175a8ba4ba0823ba6be&quot;&gt;this&lt;/a&gt; post.&lt;/p&gt;&#xA;&lt;p&gt;However in 3d this becomes a nightmare. If the same three triangles share the common vertex but have an arbitrary orientation in 3d space and are not coplanar. How can one possibly sort the half-edges?&lt;/p&gt;&#xA;&lt;p&gt;I experimented with using the common vertex normal to construct a plane, and project all the half-edges around the vertex to that plane. After which we could sort them clockwise relative to the plane. But I've found this approach to have a lot of issues. And now I'm all out of ideas.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pQyab.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pQyab.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/WHSSF.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WHSSF.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-09-20T05:50:02.327" LastActivityDate="2020-10-22T19:03:45.340" Title="Sort half-edges around common vertex in 3d" Tags="&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="3" ClosedDate="2021-01-16T16:08:08.017" ContentLicense="CC BY-SA 4.0" />
  <row Id="10247" PostTypeId="1" CreationDate="2020-09-20T18:14:03.060" Score="3" ViewCount="175" Body="&lt;p&gt;I am writting a path tracer in &lt;a href=&quot;https://github.com/D-K-E/cuda-raytracer.git&quot; rel=&quot;nofollow noreferrer&quot;&gt;cuda&lt;/a&gt; following the Shirley's book. I am having a square pattern as an output.&lt;/p&gt;&#xA;&lt;p&gt;The size of the block change if I change the block dimensions. For this image, the block dimensions follow the aspect ratio, basically 16 * 9 is block size. I know that without actually showing the entire code, it is difficult to debug it. I am just asking if you have any idea where I should start debugging it. My hunch is that there is a problem with my random number generator.&#xA;Here is its code in case I am doing something wrong. Here is the host code:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;int total_pixel_size = WIDTH * HEIGHT;&#xA;size_t frameSize = 3 * total_pixel_size;&#xA;&#xA;// declare random state&#xA;int SEED = time(NULL);&#xA;thrust::device_ptr&amp;lt;curandState&amp;gt; randState1 = thrust::device_malloc&amp;lt;curandState&amp;gt;(frameSize);&#xA;CUDA_CONTROL(cudaGetLastError());&#xA;&#xA;// declare random state 2&#xA;thrust::device_ptr&amp;lt;curandState&amp;gt; randState2 = thrust::device_malloc&amp;lt;curandState&amp;gt;(1);&#xA;CUDA_CONTROL(cudaGetLastError());&#xA;rand_init&amp;lt;&amp;lt;&amp;lt;1, 1&amp;gt;&amp;gt;&amp;gt;(thrust::raw_pointer_cast(randState2),&#xA;                      SEED);&#xA;CUDA_CONTROL(cudaGetLastError());&#xA;CUDA_CONTROL(cudaDeviceSynchronize());&#xA;&#xA;dim3 blocks(WIDTH / BLOCK_WIDTH + 1,&#xA;              HEIGHT / BLOCK_HEIGHT + 1);&#xA;  dim3 threads(BLOCK_WIDTH, BLOCK_HEIGHT);&#xA;  render_init&amp;lt;&amp;lt;&amp;lt;blocks, threads&amp;gt;&amp;gt;&amp;gt;(&#xA;      WIDTH, HEIGHT, thrust::raw_pointer_cast(randState1),&#xA;      SEED);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here is the device code:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;&#xA;__global__ void rand_init(curandState *randState,&#xA;                          int seed) {&#xA;  if (threadIdx.x == 0 &amp;amp;&amp;amp; blockIdx.x == 0) {&#xA;    curand_init(seed, 0, 0, randState);&#xA;  }&#xA;}&#xA;&#xA;__global__ void render_init(int mx, int my,&#xA;                            curandState *randState,&#xA;                            int seed) {&#xA;  if (threadIdx.x == 0 &amp;amp;&amp;amp; threadIdx.y == 0) {&#xA;    curand_init(seed, 0, 0, randState);&#xA;  }&#xA;  int i = threadIdx.x + blockIdx.x * blockDim.x;&#xA;  int j = threadIdx.y + blockIdx.y * blockDim.y;&#xA;&#xA;  if ((i &amp;gt;= mx) || (j &amp;gt;= my)) {&#xA;    return;&#xA;  }&#xA;  int pixel_index = j * mx + i;&#xA;  // same seed, different index&#xA;  curand_init(seed + pixel_index, pixel_index, 0,&#xA;              &amp;amp;randState[pixel_index]);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I would really appreciate any pointers to the problem.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Y3wTY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y3wTY.png&quot; alt=&quot;cornell box with two blocks&quot; /&gt;&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Here is another image with different block size and dimensions but with the same problem:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/xvhxw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xvhxw.png&quot; alt=&quot;another image with different dimensions&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13456" LastActivityDate="2020-11-07T03:02:40.247" Title="Why does my image has a square pattern in cuda path tracer?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;cuda&gt;&lt;debugging&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10248" PostTypeId="1" CreationDate="2020-09-21T22:30:39.627" Score="0" ViewCount="59" Body="&lt;p&gt;I want to motion track a shot from my Sony HDR-HC7e camcorder and I am not quite sure about the horizontal sensor size(width).&#xA;I set the focal length to minimum and the recording to HDV 16:9&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.sony.com/electronics/support/res/manuals/2319/23198061M.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;This&lt;/a&gt; manual (HC7e and HC7 are basically the same) states it is a 1/2.9&amp;quot; sensor with a diagonal of 6.3mm (page 101). But if I do my calculations and multiply (1/2.9) with 25.4 to convert it to mm I get 8.75862069?&lt;/p&gt;&#xA;&lt;p&gt;The camcorder outputs a 1440*1080 interlaced .m2t file. The image in this file is squeezed by a factor of 1.33. as seen in this &lt;a href=&quot;https://imgur.com/a/cNBiKy5&quot; rel=&quot;nofollow noreferrer&quot;&gt;example&lt;/a&gt;.&#xA;So I suppose that the sensor has an aspect ratio of 4/3(1.33) So I did some math:&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$a^2 = b^2 +c^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{matrix}&#xA;a_1 &amp;amp;=&amp;amp; 6.3\\&#xA;a_2 &amp;amp;=&amp;amp; 8.75862069\\&#xA;b &amp;amp;=&amp;amp; x\\&#xA;c &amp;amp;=&amp;amp; 1.33x\\&#xA;\end{matrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$6.3^2 = x^2 + (1.33x)^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{matrix}&#xA;x &amp;amp;=&amp;amp; 3.78605\\&#xA;1.33x &amp;amp;=&amp;amp; 5.0354465\\&#xA;\textrm{horizontal 1} &amp;amp;=&amp;amp; 5.0354465&#xA;\end{matrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$8.75862069^2 = x^2 + (1.33x)^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{matrix}&#xA;x &amp;amp;=&amp;amp; 5.26359\\&#xA;1.33x &amp;amp;=&amp;amp; 7.0005747\\&#xA;\textrm{horizontal 2} &amp;amp;=&amp;amp; 7.0005747\\&#xA;\end{matrix}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So I thought because there always is a relation between sensor size and focal length, I just take the sensor size horizontal 35mm and the corresponding 35mm focal length equivalent of 49mm (manual page 101) and get the ration: 35 / 49 = 0.714285714 then multiply the true focal length of 5.4mm by that and get a horizontal sensor size of 3.857142856&lt;/p&gt;&#xA;&lt;p&gt;So now I have got 3 possible horizontal sensor sizes. Now I want to calibrate my lens with a set of images like the linked one. Should I leave them with the 1.33 aspect ratio and where would I specify that in the OpenCV camera calibration or do I unsqueze them and then calibrate? And do I even need the sensor size and focal length for OpenCV camera calibration?&lt;/p&gt;&#xA;" OwnerUserId="14000" LastEditorUserId="13095" LastEditDate="2020-09-22T07:30:28.837" LastActivityDate="2021-02-19T20:03:45.407" Title="Sensor size of Sony HDR-HC7e" Tags="&lt;camera&gt;&lt;opencv&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10249" PostTypeId="1" CreationDate="2020-09-22T04:23:06.220" Score="2" ViewCount="51" Body="&lt;p&gt;I was looking into the ear-clipping algorithm for triangulating simple polygons. I have successfully implemented it on planar polygons. However if polygon is non-planar the algorithm breaks down. Specifically one step of the algorithm is to test if there're any polygon vertices inside each ear. However point triangle test only makes sense if the point lies in the same plane as the triangle.&lt;/p&gt;&#xA;&lt;p&gt;So does ear-clipping algorithm not work for non-planar polygons? If so what algorithm could I use instead? I need it to support simple polygons with potentially holes inside them.&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-09-22T04:23:06.220" Title="Ear-clipping algorithm for non-planar polygons" Tags="&lt;computational-geometry&gt;&lt;triangulation&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10250" PostTypeId="2" ParentId="10137" CreationDate="2020-09-22T18:06:16.813" Score="1" Body="&lt;p&gt;It's defining the gradient in terms of barycentric coordinates. It is similar to the derivation in &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10169/48&quot;&gt;this answer&lt;/a&gt;, only rearranged a bit algebraically using the fact that the three barycentric coordinates sum to one.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;f(\mathbf{u}) &amp;amp;= f_i B_i(\mathbf{u}) + f_j B_j(\mathbf{u}) + f_k B_k(\mathbf{u}) \\&#xA;&amp;amp;= f_i (1 - B_j(\mathbf{u}) - B_k(\mathbf{u})) + f_j B_j(\mathbf{u}) + f_k B_k(\mathbf{u}) \\&#xA;&amp;amp;= f_i + (f_j - f_i) B_j(\mathbf{u}) + (f_k - f_i) B_k(\mathbf{u}) \\&#xA;\nabla f(\mathbf{u}) &amp;amp;= (f_j - f_i) \nabla B_j(\mathbf{u}) + (f_k - f_i) \nabla B_k(\mathbf{u}) \\&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-09-22T18:26:25.573" LastActivityDate="2020-09-22T18:26:25.573" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10251" PostTypeId="2" ParentId="10246" CreationDate="2020-09-22T18:19:48.420" Score="0" Body="&lt;p&gt;If projecting them onto the plane of the vertex normal doesn't do the job, I'm not sure what would. There isn't any unambiguous way to do this in 3D. Imagine the new triangle that you are on there joining is perpendicular to the existing two triangles? What would you want the answer to be in that case?&lt;/p&gt;&#xA;&lt;p&gt;I suppose you could try &amp;quot;voting&amp;quot; by dotting the new triangle's normal with each of the existing triangle's normals. A positive dot is a vote to keep the current orientation, a negative dot is a vote to flip it. Maybe weight the votes by the triangles' areas, or their angles at that vertex. Of course you'd have to decide how to break ties, and this might just give you similar problems to the plane of the common vertex normal.&lt;/p&gt;&#xA;&lt;p&gt;This would make more sense if you were constructing a new triangle that shared an edge with one of the existing triangles. Then you could copy the orientation from the triangle that it was joined to. I'm not sure what kind of 3D modeling operation you're doing that produces this situation, but if there's any way you can accomplish it by building things in terms of common edges rather than common vertices, you'll probably have a much better time.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-22T18:19:48.420" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10252" PostTypeId="2" ParentId="10248" CreationDate="2020-09-22T18:46:11.310" Score="0" Body="&lt;p&gt;Answer over in Photography:&#xA;&lt;a href=&quot;https://photo.stackexchange.com/questions/119761/sensor-size-of-sony-hdr-hc7e/119764#119764&quot;&gt;https://photo.stackexchange.com/questions/119761/sensor-size-of-sony-hdr-hc7e/119764#119764&lt;/a&gt;&#xA;It turns out to be Vertikal: 3.74 horizontal 4.98 and diagonal 6.23&lt;/p&gt;&#xA;" OwnerUserId="14000" LastActivityDate="2020-09-22T18:46:11.310" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10253" PostTypeId="2" ParentId="10219" CreationDate="2020-09-23T08:58:07.413" Score="1" Body="&lt;p&gt;Since your actuallyu doing a PDF file you should do this as a vector drawing not a image format. This makes for way more clearer end results. I will generate a image in EPS, EPS is easy to build into your PDF file with say distiller, ghostscript, sent to printer or injected into TeX (though then you may want to use Tix or or PStricks) .&lt;/p&gt;&#xA;&lt;p&gt;Ok first you have to undertsand that EPS is a full programing language (Postscript), in addition to being a vector format (the Encapsulation part). I will be uisng the features to remove repetition. The file begins with a encapsulation marker so that you can more easily insert it programmatically.&lt;/p&gt;&#xA;&lt;p&gt;So frist draw the thing form a overhead view, then we will transform that into isometric with a affine transform:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rkY4O.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rkY4O.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Image 1&lt;/strong&gt;: Preview of listing 1&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;%!PS-Adobe-3.0 EPSF-3.0 &#xA;%%BoundingBox: 0 0 538 300&#xA;%%Title: listing 1&#xA;%%Creator: joojaa&#xA;%%CreationDate:  2020-09-23&#xA;%%EndComments&#xA;&#xA;% postscript style shorthand relative&#xA;/m {moveto} def&#xA;/rm {rmoveto} def&#xA;/rl {rlineto} def&#xA;&#xA;10 10 translate % add some padding&#xA;72 25.4 div 100 div  dup scale  % draw in  1:100&#xA;70 setlinewidth %0.7 mm technical pen&#xA;&#xA;newpath  % coordinates and ops follow&#xA;0 4100 m&#xA;0 5500 rl&#xA;9000  0 rl&#xA;0 -4000 rl&#xA;4000 0 rl&#xA;0 -1300 rl&#xA;0 -800 rm&#xA;0 -1000 rl  &#xA;stroke&#xA;&#xA;%%EOF&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Ok then we transform the entire thing to isometric&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EGRc0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/EGRc0.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Image 2: Image after Listing 2. Only stroke changed&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;%!PS-Adobe-3.0 EPSF-3.0 &#xA;%%BoundingBox: 0 0 538 300&#xA;%%Title: listing &#xA;%%Creator: joojaa&#xA;%%CreationDate:  2020-09-23&#xA;%%EndComments&#xA;&#xA;% postscript style shorthand relative&#xA;/m {moveto} def&#xA;/rm {rmoveto} def&#xA;/rl {rlineto} def&#xA;&#xA;10 10 translate % add some padding&#xA;72 25.4 div 100 div  dup scale  % draw in  1:100&#xA;70 setlinewidth %0.7 mm technical pen&#xA;&#xA;newpath  % coordinates and ops follow&#xA;0 4100 m&#xA;&#xA;0 5500 rl&#xA;9000  0 rl&#xA;0 -4000 rl&#xA;4000 0 rl&#xA;0 -1300 rl&#xA;0 -800 rm&#xA;0 -1000 rl&#xA;&#xA;%changed stroke to this&#xA;gsave&#xA; false upath&#xA;  9600 60 sin mul 0 translate &#xA;  [60 sin 60 cos -60 sin -60 cos 0 0] concat&#xA;  ustroke&#xA;grestore &#xA;%eof changed&#xA;&#xA;%%EOF&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then we duplicate this and offset&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XdkkJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XdkkJ.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Image 3&lt;/em&gt;: After offsetting&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;%!PS-Adobe-3.0 EPSF-3.0 &#xA;%%BoundingBox: 0 0 538 300&#xA;%%Title: listing 3&#xA;%%Creator: joojaa &#xA;%%CreationDate:  2020-09-23 &#xA;%%EndComments&#xA;&#xA;% postscript style shorthand relative&#xA;/m {moveto} def&#xA;/rm {rmoveto} def&#xA;/rl {rlineto} def&#xA;&#xA;10 10 translate % add some padding&#xA;72 25.4 div 100 div  dup scale  % draw in  1:100&#xA;70 setlinewidth %0.7 mm technical pen&#xA;&#xA;newpath  % coordinates and ops follow&#xA;0 4100 m&#xA;&#xA;0 5500 rl&#xA;9000  0 rl&#xA;0 -4000 rl&#xA;4000 0 rl&#xA;0 -1300 rl&#xA;0 -800 rm&#xA;0 -1000 rl&#xA;&#xA;gsave&#xA; false upath&#xA;  9600 60 sin mul -1100 translate &#xA;  [60 sin 60 cos -60 sin -60 cos 0 0] concat&#xA;  ustroke&#xA;grestore &#xA;&#xA;gsave&#xA; false upath&#xA;  9600 60 sin mul 10 translate &#xA;  [60 sin 60 cos -60 sin -60 cos 0 0] concat&#xA;  ustroke&#xA;grestore &#xA;&#xA;&#xA;%%EOF&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Next draw connecting lines&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XD1x1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XD1x1.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;Image 4&lt;/em&gt;: Listing 4 result&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;%!PS-Adobe-3.0 EPSF-3.0 &#xA;%%BoundingBox: 0 0 538 300&#xA;%%Title: listing 4&#xA;%%Creator: joojaa &#xA;%%CreationDate:  2020-09-23 &#xA;%%EndComments&#xA;&#xA;% postscript style shorthand relative&#xA;/m {moveto} def&#xA;/rm {rmoveto} def&#xA;/rl {rlineto} def&#xA;%draw connecting line&#xA;&#xA;/tf { 9600 60 sin mul 10 translate &#xA;    [60 sin 60 cos -60 sin -60 cos 0 0] concat} def&#xA;&#xA;/dc {gsave &#xA;    newpath &#xA;    9600 60 sin mul 10 translate &#xA;    [60 sin 60 cos -60 sin -60 cos 0 0] &#xA;    concat m -1100 -1100 rl&#xA;    stroke &#xA;    grestore&#xA;     } def&#xA;&#xA;10 10 translate % add some padding&#xA;72 25.4 div 100 div  dup scale  % draw in  1:100&#xA;70 setlinewidth %0.7 mm technical pen&#xA;&#xA;newpath  % coordinates and ops follow&#xA;&#xA;0 4100 m&#xA;0 5500 rl&#xA;9000  0 rl&#xA;0 -4000 rl&#xA;4000 0 rl&#xA;0 -1300 rl&#xA;0 -800 rm&#xA;0 -1000 rl&#xA;     &#xA;%drawing no need to change&#xA;gsave&#xA; false upath&#xA;  tf&#xA;ustroke&#xA;grestore &#xA;&#xA;gsave&#xA; false upath&#xA;  0 -1100 translate&#xA;  tf&#xA;  ustroke&#xA;grestore &#xA;&#xA;{dc} {dc} {} {} pathforall&#xA;&#xA;&#xA;%%EOF&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Todoo:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Change stroke to round&lt;/li&gt;&#xA;&lt;li&gt;Draw in paperspace&lt;/li&gt;&#xA;&lt;li&gt;Draw distances.&lt;/li&gt;&#xA;&lt;li&gt;Compute bound and center&lt;/li&gt;&#xA;&lt;li&gt;Etc.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I might return later&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2020-09-23T08:58:07.413" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10254" PostTypeId="1" AcceptedAnswerId="10255" CreationDate="2020-09-23T09:02:40.223" Score="1" ViewCount="51" Body="&lt;p&gt;I want to do some complicated stuff but have problems with my geometry shader / FBO bindings.&#xA;To hold it as easy as possible I reduced the code to a minimum. If this works, I could continue the hard part. So don't wonder, why I am trying to do it in this way...&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The &amp;quot;easy&amp;quot; thing:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I have two triangles (a quad) which are going over the whole screen from (-1,-1,0) to (1,1,0).&#xA;Inside my geometry shader I want to copy these two triangles six times to cover all six faces of my cubemap. BTW: I don't need a depth or stencil buffer.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Lets look at the cubemap texture generation:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glGenTextures(1, &amp;amp;m_cubeMapTexture);&#xA;glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubeMapTexture);&#xA;glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP);&#xA;glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP);&#xA;glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP);&#xA;glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;checkGLError();&#xA;// set textures&#xA;for (int i = 0; i &amp;lt; 6; ++i)&#xA;    glTexImage2D(static_cast&amp;lt;GLenum&amp;gt;(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i), 0, GL_RGB, 2048, 2048, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;This texture will be plugged into a frameBufferObject in the following way:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glGenFramebuffers(1, &amp;amp;m_cubeMapFBO);&#xA;glBindFramebuffer(GL_FRAMEBUFFER, m_cubeMapFBO);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT4, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, m_cubeMapTexture, 0);&#xA;&#xA;static const GLuint draw_buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5 };&#xA;glDrawBuffers(6, draw_buffers);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;The vertex shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 420&#xA;in vec3 POSITION;&#xA;                                                                                &#xA;out VS_OUT                                                            &#xA;{                                                                    &#xA;   vec3 position;                                                     &#xA;} vs_out;                                                            &#xA;                                                                                &#xA;void main()                                                           &#xA;{                                                                   &#xA;    vs_out.position = POSITION;  &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Just take the input and pass it to the geometry shader&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Lets continue with the geometry shader:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 420                                                        &#xA;layout (triangles) in;                                               &#xA;layout (triangle_strip, max_vertices = 36) out;                     &#xA;uniform mat3 orientation[6];                                        &#xA;                                                                              &#xA;in VS_OUT                                                           &#xA;{                                                                   &#xA;    vec3 position;                                                   &#xA;} gs_in[];                                                        &#xA;                                                                              &#xA;out GS_OUT                                                         &#xA;{                                                                   &#xA;    vec3 position;                                                    &#xA;} gs_out;                                                          &#xA;                                                                              &#xA;void main()                                                          &#xA;{                                                                  &#xA;    for (int i = 0; i &amp;lt; 6; ++i)                                     &#xA;    {                                                                &#xA;        gl_Layer = i;                                              &#xA;        gl_Position = vec4(gs_in[0].position, 1.0f);                &#xA;        gs_out.position = orientation[i] * vec3(gs_in[0].position.xy, 1.0f);      &#xA;        EmitVertex();                                               &#xA;                                                                              &#xA;        gl_Layer = i;                                                &#xA;        gl_Position = vec4(gs_in[1].position, 1.0f);                 &#xA;        gs_out.position = orientation[i] * vec3(gs_in[1].position.xy, 1.0f);        &#xA;        EmitVertex();                                              &#xA;                                                                              &#xA;        gl_Layer = i;                                                &#xA;        gl_Position = vec4(gs_in[2].position, 1.0f);                &#xA;        gs_out.position = orientation[i] * vec3(gs_in[2].position.xy, 1.0f);        &#xA;        EmitVertex();                                                &#xA;                                                                              &#xA;        EndPrimitive();                                              &#xA;    }                                                               &#xA;}     &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The for loop creates each triangle six times (one for each cubemap face &amp;quot;gl_Layer = i&amp;quot;).&#xA;the gl_Position is the input quad without any transformations.&#xA;the gs_out.position is rotated by the orientation matrix (a rotation matrix for each face). This gs_out.position should be interpolated within the fragment shader.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Last, but not least: The fragment shader&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 420                                             &#xA;in GS_OUT                                              &#xA;{                                                    &#xA;    vec3 position;                                       &#xA;} fs_in;                                                &#xA;                                                                  &#xA;out vec4 color;                                     &#xA;                                                                  &#xA;void main()                                            &#xA;{                                                      &#xA;    color = vec4(fs_in.position, 1.0f);                &#xA;}          &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The interpolated fs_in.position will be stored into the cubemap.&lt;/p&gt;&#xA;&lt;p&gt;If you just look at the code and try to imagine what the output should be, you'll end up to say:&#xA;&amp;quot;That is the RGB cube + the minus part which is stored in the cubemap.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;And now I'll show you the output:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mfI4o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mfI4o.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;My first intention was changing the &amp;quot;orientation&amp;quot; matrices but I noticed, that this is not the problem:&#xA;By changing the for loop counter within my geometry shader to &amp;quot;for (int i = 0; i &amp;lt; &lt;strong&gt;1&lt;/strong&gt;; ++i)&amp;quot; I got the following output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/so8M2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/so8M2.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;So there are only the two triangles, which are not copied anymore and each cubemap face is colored in the same way. gl_Layer was only set to zero but the other layers are also colored. How can that be?&#xA;How can I change the code, so that only the face &amp;quot;gl_Layer&amp;quot; will be colored?&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-09-23T12:37:13.023" Title="draw on cubemap with help of geometry shader each triangle covers each cubemap face (why??)" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;c++&gt;&lt;frame-buffer&gt;&lt;geometry-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10255" PostTypeId="2" ParentId="10254" CreationDate="2020-09-23T12:37:13.023" Score="2" Body="&lt;p&gt;After trying everything possible I found my mistake:&lt;/p&gt;&#xA;&lt;p&gt;The shaders are fine, the only thing which is wrong is the frameBufferObject binding. To be honest, the texture to FBO binding.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;the only thing I replaced is this:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT4, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, m_cubeMapTexture, 0);&#xA;glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, m_cubeMapTexture, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;by the correct method call:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, m_cubeMapTexture, 0);&#xA;    &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;The result of the changed code is this:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UB0s3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UB0s3.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-09-23T12:37:13.023" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10256" PostTypeId="1" AcceptedAnswerId="10257" CreationDate="2020-09-24T03:17:24.137" Score="3" ViewCount="63" Body="&lt;p&gt;So I recently learnt that supposedly for any mesh, and pretty much any scheme, the valence of regular vertices must be 6. It seems to be related to the Euler-Poincare formula but I have not been able to find the justification.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-25T18:12:22.583" Title="Why is the valence of regular vertices 6?" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10257" PostTypeId="2" ParentId="10256" CreationDate="2020-09-24T10:00:21.543" Score="4" Body="&lt;p&gt;If require that all faces have the same number of sides &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; and require that all vertices also have a certain valency &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt;. We see that the following relation between edges, and faces hold for a regular mesh:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$s\cdot f = 2e,$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$t\cdot v = 2e.$$&lt;/span&gt; Substitution in the Euler-Poincare formula yields:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\left(\frac{1}{s} + \frac{1}{t} - \frac{1}{2}\right)e = 1 - g$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;If we then take for instance a regular plane which can be said to have the topology of a torus with genus &lt;span class=&quot;math-container&quot;&gt;$g = 1$&lt;/span&gt;. We then set the valency of faces &lt;span class=&quot;math-container&quot;&gt;$s = 3$&lt;/span&gt; then&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\left(\frac{1}{3} + \frac{1}{t} - \frac{1}{2}\right)e = 0,$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\left(-\frac{1}{6} + \frac{1}{t}\right)e = 0.$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The solution for &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$6$&lt;/span&gt;, which says the valency of a vertex in a regular triangulation is 6.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2020-09-25T18:12:22.583" LastActivityDate="2020-09-25T18:12:22.583" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10258" PostTypeId="2" ParentId="10148" CreationDate="2020-09-25T20:08:02.893" Score="1" Body="&lt;p&gt;If anyone ever runs into this. There is a mathematical property of the half edge, that makes it such that any proper half edge can be expressed as an even permutation of vertices.&lt;/p&gt;&#xA;&lt;p&gt;This sounds abstract but the gist of it is very simple. Since there is an even number of HE by definition, you can store your half edges such that if &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is even then &lt;span class=&quot;math-container&quot;&gt;$n + 1$&lt;/span&gt; is its pair. As such you can just iterate through the actual edges by skipping every other edge.&lt;/p&gt;&#xA;&lt;p&gt;The drawback is that you need to ensure that your edges are indeed stored like that, which can be complex.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-25T20:08:02.893" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10259" PostTypeId="2" ParentId="10025" CreationDate="2020-09-25T22:05:24.093" Score="0" Body="&lt;p&gt;So I've been all around the houses on this looking for an answer. In the end I found a combination of techniques worked quite well:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;To take advantage of all of the 'empty space', the concept of 'surface tracking' from the Octree Decimation paper useful - you can follow the surface from cell to cell and ignore all of the cells in the middle.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;The main advantage of generating the voxels ourselves is what we know two vital pieces of information: firstly, the exact position of each vertex within the cells on the 'front' surface; secondly, the 'orientation' of the mesh in each region and which way that 'front' is to be found.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Putting all the pieces together I came up with this &lt;a href=&quot;https://github.com/andygeers/DualMarchingCuboids&quot; rel=&quot;nofollow noreferrer&quot;&gt;Dual Marching Cuboids&lt;/a&gt; algorithm, that has pretty good results in very reasonable time.&lt;/p&gt;&#xA;" OwnerUserId="13696" LastActivityDate="2020-09-25T22:05:24.093" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10260" PostTypeId="2" ParentId="4748" CreationDate="2020-09-26T13:38:28.473" Score="0" Body="&lt;p&gt;Keeping alpha linear makes it unbiased towards source and destination color. It should not be gamma corrected, because it should not have been subjected to sRGB-encoding.&lt;/p&gt;&#xA;&lt;p&gt;A specialized application could of course ignore this, for example to get more control over the change in perceived brightness during a blending operation of a bright source color over a dark destination color (assuming alpha is stored in a byte with range 0-255 - which is how sRGB is commonly stored these days for the purpose of data compression - where you can only change the alpha in big steps).&lt;/p&gt;&#xA;" OwnerUserId="14015" LastActivityDate="2020-09-26T13:38:28.473" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10261" PostTypeId="1" AcceptedAnswerId="10264" CreationDate="2020-09-27T02:40:28.717" Score="0" ViewCount="35" Body="&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/64084221/in-place-sorting-of-a-half-edge-data-structure&quot;&gt;Cross posting&lt;/a&gt; from SO because I didn;t know where to put this question.&lt;/p&gt;&#xA;&lt;p&gt;I have an implementation of the half edge and I am trying to sort the edges such that edge n+1 is the pair of edge n.&lt;/p&gt;&#xA;&lt;h1&gt;Setup&lt;/h1&gt;&#xA;&lt;p&gt;I want to do this in place to save memory and I discovered a theoretical wall I am not sure how to solve.&lt;/p&gt;&#xA;&lt;p&gt;Let's assume the HE are stored in a list and that you can access their members through self defining getters like &lt;code&gt;.Pair()&lt;/code&gt; or &lt;code&gt;.Next()&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The idea of the algorithm is very simple.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;for(uint i=0; i&amp;lt;half_edges.size(); i+=2)&#xA;{&#xA;   swap(half_edges[i+1], half_edges[i].Pair()); // This is pseudo code, assume this works&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;That's the gist of the idea, merely swap the he right next to you with wherever your pair is.&lt;/p&gt;&#xA;&lt;p&gt;Now of course, you need to update your pointers, so for both the pair and the HE originally at &lt;span class=&quot;math-container&quot;&gt;$i + 1$&lt;/span&gt; you have to go through this tedious process:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    faces[old_pair_face].edge = i + 1;&#xA;    verts[old_pair_vert].edge = i + 1;&#xA;    edges[old_pair_prev].next = i + 1;&#xA;    edges[old_pair_next].prev = i + 1;&#xA;    edges[i].pair = i + 1;&#xA;&#xA;    faces[old_other_face].edge = old_pair_index;&#xA;    verts[old_other_vert].edge = old_pair_index;&#xA;    edges[old_other_prev].next = old_pair_index;&#xA;    edges[old_other_next].prev = old_pair_index;&#xA;    edges[old_other_pair].pair = old_pair_index;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Essentially just update all the pointers that pointed to the original 2 elements.&lt;/p&gt;&#xA;&lt;h1&gt;BUG&lt;/h1&gt;&#xA;&lt;p&gt;The above ALMOST works. However consider the following case. Assume we are at edge &lt;code&gt;i&lt;/code&gt;. The pair of &lt;code&gt;i&lt;/code&gt; is &lt;code&gt;j&lt;/code&gt;, the &lt;code&gt;next&lt;/code&gt; of &lt;code&gt;j&lt;/code&gt; is &lt;code&gt;i+1&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So &lt;code&gt;i + 1&lt;/code&gt; and &lt;code&gt;j&lt;/code&gt; swap, so the pair of &lt;code&gt;i&lt;/code&gt; is now at &lt;code&gt;i + 1&lt;/code&gt;. You then want to update &lt;code&gt;next&lt;/code&gt;, which points to &lt;code&gt;i + 1&lt;/code&gt;, so inadvertently in this specific case, swap will accidentally make &lt;code&gt;next&lt;/code&gt; point to yourself. Which is invalid as the Half edge does not allow an edge to point to itself.&lt;/p&gt;&#xA;&lt;p&gt;This is pretty rare so it took me a while to find, but it's clearly an error in my logic.&lt;/p&gt;&#xA;&lt;p&gt;The question is, given an already implemented half edge, how can you sort its edges such that the n and n+1 are pairs, while avoiding the pitfalll described above, in O(1) memory?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="7462" LastEditDate="2020-09-27T20:10:37.443" LastActivityDate="2020-10-27T21:02:10.273" Title="In place sorting of a half edge DS?" Tags="&lt;c++&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10263" PostTypeId="1" CreationDate="2020-09-27T17:45:11.410" Score="0" ViewCount="215" Body="&lt;p&gt;I'm trying to render a cube and it's wireframe together using OpenGL&lt;/p&gt;&#xA;&lt;p&gt;The main function is this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int main(int argc, char** argv)&#xA;{&#xA;    GLFWwindow* window;&#xA;&#xA;    /* Initialize the library */&#xA;    if (!glfwInit())&#xA;        return -1;&#xA;&#xA;&#xA;&#xA;    /* Create a windowed mode window and its OpenGL context */&#xA;    window = glfwCreateWindow(1024, 768, &amp;quot;MyGL&amp;quot;, NULL, NULL);&#xA;    if (!window)&#xA;    {&#xA;        glfwTerminate();&#xA;        return -1;&#xA;    }&#xA;&#xA;    /* Make the window's context current */&#xA;    glfwMakeContextCurrent(window);&#xA;&#xA;    if (glewInit() != GLEW_OK) {&#xA;        std::cout &amp;lt;&amp;lt; &amp;quot;Error!&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;    }&#xA;&#xA;    float positions[] = {&#xA;                          -0.5f, -0.5f,  0.5f,      //0&#xA;                           0.5f, -0.5f,  0.5f,      //1&#xA;                           0.5f,  0.5f,  0.5f,      //2&#xA;                          -0.5f,  0.5f,  0.5f,      //3&#xA;                          -0.5f,  0.5f, -0.5f,      //4&#xA;                           0.5f,  0.5f, -0.5f,      //5&#xA;                          -0.5f, -0.5f, -0.5f,      //6&#xA;                           0.5f, -0.5f, -0.5f       //7&#xA;    };&#xA;&#xA;    unsigned int indices[] = {&#xA;                              0, 1, 2, 3,&#xA;                              4, 5, 6, 7,&#xA;                              2, 3, 4, 5,&#xA;                              2, 5, 7, 1,&#xA;                              1, 0, 6, 7,&#xA;                              0, 6, 3, 4&#xA;    };&#xA;&#xA;    unsigned int w_indices[] = {&#xA;                                0, 1, 1, 2, 2, 3, 3, 0,     // fronte&#xA;                                0, 6, 6, 7, 7, 1, 1, 0,     // sotto&#xA;                                3, 2, 2, 5, 5, 4, 4, 3,     // sopra&#xA;                                4, 5, 5, 7, 7, 6, 6, 4,     // retro&#xA;                                2, 5, 5, 7, 7, 1, 1, 2,     // destra&#xA;                                3, 4, 4, 6, 6, 0, 0, 3      // sinistra&#xA;&#xA;    };&#xA;&#xA;&#xA;    unsigned int buffer;&#xA;    unsigned int index_buffer[2];&#xA;&#xA;    glGenBuffers(1, &amp;amp;buffer);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, buffer);&#xA;    glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(float), positions, GL_STATIC_DRAW);&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), 0);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;&#xA;    glGenBuffers(2, index_buffer);&#xA;    &#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer[0]);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 24 * sizeof(int), indices, GL_STATIC_DRAW);&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer[1]);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, 48 * sizeof(int), w_indices, GL_STATIC_DRAW);&#xA;&#xA;    glm::mat4 proj = glm::ortho(-2.0f, 2.0f, -1.5f, 1.5f, -1.0f, 1.0f);&#xA;&#xA;    glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(-0.4, 0, 0));&#xA;&#xA;    glm::mat4 view2 = glm::rotate(view, 30.0f, glm::vec3(0.0f, -1.0f, 1.0f));&#xA;&#xA;    glm::mat4 mvp = proj * view2;&#xA;&#xA;&#xA;    ShaderProgramSource source = parseShader(&amp;quot;C:\\Users\\Lukkio\\Documents\\Gildo\\res\\shader\\myShader.shader&amp;quot;);&#xA;&#xA;    unsigned int shader = createShader(source.vertex_source, source.fragment_source);&#xA;    glUseProgram(shader);&#xA;&#xA;    int location = glGetUniformLocation(shader, &amp;quot;u_color&amp;quot;);&#xA;    int u_mvp = glGetUniformLocation(shader, &amp;quot;u_MVP&amp;quot;);&#xA;&#xA;&#xA;&#xA;    glUniform4f(location, 0.0, 1.0, 1.0, 1.0);&#xA;&#xA;    glUniformMatrix4fv(u_mvp, 1, GL_FALSE, &amp;amp;mvp[0][0]);&#xA;&#xA;    float r = 0.0f;&#xA;    float g = 1.0f;&#xA;    float b = 1.0f;&#xA;&#xA;    /* Loop until the user closes the window */&#xA;    while (!glfwWindowShouldClose(window))&#xA;    {&#xA;        glEnable(GL_DEPTH_TEST);&#xA;        glDepthFunc(GL_LESS);&#xA;&#xA;&#xA;        /* Render here */&#xA;        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;&#xA;&#xA;        glUniform4f(location, r, g, b, 0);&#xA;&#xA;        glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, nullptr);&#xA;&#xA;        glUniform4f(location, 1.0, 0.0, 0.0, 0.0);&#xA;&#xA;        glDrawElements(GL_LINES, 48, GL_UNSIGNED_INT, nullptr);&#xA;&#xA;        /* Swap front and back buffers */&#xA;        glfwSwapBuffers(window);&#xA;&#xA;        /* Poll for and process events */&#xA;        glfwPollEvents();&#xA;    }&#xA;&#xA;    glDeleteProgram(shader);&#xA;&#xA;    glfwTerminate();&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm not an openGL expert, I know bits and pieces but I rarely practice so this is mostly for refreshing.&lt;/p&gt;&#xA;&lt;p&gt;The way I was trying to achieve this was to create two index buffers, but no matter what I do I can't manage.&lt;/p&gt;&#xA;&lt;p&gt;I also noticed the 4th argument of &lt;code&gt;glDrawElements&lt;/code&gt; but however I cannot manage to find what exactly I would need to pass. Because I'm essentially rendering two different objects I read I might use &lt;code&gt;VAO&lt;/code&gt; but regardless of whether or not this is the right approach I'd like to know what is wrong with my approach of two index buffers, and a single vertex buffer.&lt;/p&gt;&#xA;&lt;p&gt;So here the questions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Why isn't it working? What am I missing?&lt;/li&gt;&#xA;&lt;li&gt;For this specific task (object + wireframe) is there maybe a much simpler approach that I'm missing?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Thank you&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2021-02-25T10:01:25.137" Title="Drawing a cube and wireframe opengl" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10264" PostTypeId="2" ParentId="10261" CreationDate="2020-09-27T20:18:00.013" Score="0" Body="&lt;p&gt;My solution to this ended up being not sorting at all. Manipualting an already initialized HE is a nightmare, so instead I built the HE with this property from the get go.&lt;/p&gt;&#xA;&lt;p&gt;The initialization algorithm is pretty much:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Create a new half edge.&lt;/li&gt;&#xA;&lt;li&gt;Check if the pair of the half edge exists.&lt;/li&gt;&#xA;&lt;li&gt;If it exists, you are allocated at &lt;code&gt;index of pair + 1&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;If it does not exist, increment an &lt;code&gt;offset&lt;/code&gt; by 2 and store yourself at &lt;code&gt;offset - 2&lt;/code&gt; (i.e. allocate 2 slots in the edge array and store yourself in the even slot).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Doing it this way before setting &lt;code&gt;next&lt;/code&gt; and &lt;code&gt;prev&lt;/code&gt; and company guarantees that at any one time the HE is properly initialized.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-27T20:18:00.013" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10265" PostTypeId="1" CreationDate="2020-09-27T22:20:26.703" Score="0" ViewCount="27" Body="&lt;p&gt;Can you please give a suggestion?&lt;/p&gt;&#xA;&lt;p&gt;I have a .mhd image (Voxel 3D). I want to visualize it and manipulate it with the mouse. What you suggest?&lt;/p&gt;&#xA;&lt;p&gt;How I can display a 3D Image in OpenGL? I only found in internet about display files with extension .obj (2.5D surface image).&lt;/p&gt;&#xA;&lt;p&gt;Must I do: Find the surface of the voxel image and display with OpenGL. How I find the surface from voxel 3D? And convert to mesh surface .obj image?&lt;/p&gt;&#xA;&lt;p&gt;Using VTK? (Do you think that is better?)&lt;/p&gt;&#xA;&lt;p&gt;Thanks in Advance,&lt;/p&gt;&#xA;&lt;p&gt;Luis Gonçalves&lt;/p&gt;&#xA;" OwnerUserId="14020" LastEditorUserId="-1" LastEditDate="2020-09-28T20:11:43.213" LastActivityDate="2020-09-28T20:11:43.213" Title="How to display and manipulate a structured 3D voxel image?" Tags="&lt;opengl&gt;&lt;vtk&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10266" PostTypeId="1" CreationDate="2020-09-28T07:12:28.723" Score="1" ViewCount="69" Body="&lt;p&gt;I'm trying to implement a voxelization algorithm. I successfully implemented cube triangle intersection test and made a basic voxel model from discrete box meshes. However I can't find any information on how the merging is done between the separate box meshes to create a unified mesh. A naive approach I can think of is for each face of the cube check if it overlaps with any other face, delete both faces and stitch the edges around the faces between cubes. But this seems very crude.&lt;/p&gt;&#xA;&lt;p&gt;Is there an algorithm for doing this?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-09-28T07:24:36.127" LastActivityDate="2020-09-28T07:24:36.127" Title="How to merge voxels" Tags="&lt;voxelization&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10267" PostTypeId="2" ParentId="10263" CreationDate="2020-09-28T08:28:02.570" Score="0" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;I'd like to know what is wrong with my approach of two index buffers, and a single vertex buffer.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;There is nothing wrong with that. Reusing resources and avoiding duplicate data is always a good thing.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Why isn't it working? What am I missing?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Basically, you already got the answer: &amp;quot; I read I might use &lt;code&gt;VAO&lt;/code&gt;&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;In the Vertex Array Object section of &lt;a href=&quot;https://learnopengl.com/Getting-started/Hello-Triangle&quot; rel=&quot;nofollow noreferrer&quot;&gt;this tutorial&lt;/a&gt; there is a big red block stating:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Core OpenGL requires that we use a VAO so it knows what to do with our vertex inputs. If we fail to bind a VAO, OpenGL will most likely refuse to draw anything.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Can't tell if there are any other problems with your code, but the missing &lt;code&gt;VAO&lt;/code&gt; is probably the main one.&lt;/p&gt;&#xA;&lt;p&gt;I suggest you read the whole text on the site I linked and follow the instructions to render a single triangle. Afterwards, add some more triangles and try to render them using an index buffer. If you got so far, it should be easy to get your approach working.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;For this specific task (object + wireframe) is there maybe a much simpler approach that I'm missing?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I think there are many different ways to do this. One way would be to use a single draw call and check inside the fragment shader if the current pixel is close to one of the sides of the triangle. If this is the case, just overwrite the fragment's colour with your desired wireframe colour. &lt;a href=&quot;https://stackoverflow.com/a/33004265/6700329&quot;&gt;This answer on Stack Overflow&lt;/a&gt; shows you how to do that. You just need to modify it a little bit so that &amp;quot;non-wireframe&amp;quot; sections are rendered normally instead of being translucent.&lt;/p&gt;&#xA;&lt;p&gt;Also, check the other answers in the Stack Overflow link. There a lot of different approaches mentioned.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-09-28T08:33:30.680" LastActivityDate="2020-09-28T08:33:30.680" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10268" PostTypeId="1" CreationDate="2020-09-28T12:32:59.083" Score="1" ViewCount="201" Body="&lt;p&gt;FFT spectra is not what is needed; what I need is a histogram showing which frequencies are there in image in horizontal direction, and which one is dominant&lt;br /&gt;&#xA;Such spatial frequency is usually known for a &lt;strong&gt;sinusoidal grating&lt;/strong&gt;; I need the same property for grayscale raster image (in cycles per pixel)&lt;/p&gt;&#xA;" OwnerUserId="14025" LastActivityDate="2020-10-28T18:06:30.720" Title="How to calculate spatial frequency of an image just in one direction?" Tags="&lt;image-processing&gt;&lt;raster-image&gt;&lt;spectral&gt;&lt;fourier-transform&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10269" PostTypeId="1" AcceptedAnswerId="10276" CreationDate="2020-09-28T12:45:14.770" Score="1" ViewCount="82" Body="&lt;p&gt;I'm reading and implementing a paper about &lt;a href=&quot;http://aconty.com/pdf/many-lights-hpg2018.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Importance Sampling of Many Lights with Adaptive Tree Splitting&lt;/a&gt;. In section 5.2 on &lt;em&gt;cluster importance for participating media&lt;/em&gt;, there is a part that I don't understand: How do they compute the vectors o1, o2? I don't understand the paragraph explaining how to obtain this basis from v1, v2. Can anyone explain it?&lt;/p&gt;&#xA;" OwnerUserId="13367" LastActivityDate="2020-10-01T14:48:16.387" Title="&quot;Importance Sampling of Many Lights with Adaptive Tree Splitting&quot; - paper: participating media" Tags="&lt;pathtracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10270" PostTypeId="2" ParentId="10268" CreationDate="2020-09-28T17:28:59.443" Score="1" Body="&lt;p&gt;You can take a 1D Fourier transform of a row of pixels from the image; it will give you the horizontal frequencies present in that row.&lt;/p&gt;&#xA;&lt;p&gt;You could sample one row out of the image, or else average all the rows together to get an overall picture of the horizontal frequencies.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-28T17:28:59.443" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10271" PostTypeId="1" AcceptedAnswerId="10273" CreationDate="2020-09-29T01:28:41.567" Score="2" ViewCount="91" Body="&lt;p&gt;I have an obj parser that handles triangle meshes specifically.&lt;/p&gt;&#xA;&lt;p&gt;I want to extend it (and the rest of my system) to handle animations as well. However, I don't think I am ready to tackle the glTF format. Because it seems to encompass much more than what I want.&lt;/p&gt;&#xA;&lt;p&gt;I just need a simple file format that describes a mesh, some bones, and the skinning weights of the mesh vertices with respect to the bones. Plus a series of poses for the skeleton.&lt;/p&gt;&#xA;&lt;p&gt;What file format could I look into?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-09-29T13:52:50.560" Title="What's the simplest, open, animation format?" Tags="&lt;rendering&gt;&lt;mesh&gt;&lt;animation&gt;&lt;gltf&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10272" PostTypeId="1" CreationDate="2020-09-29T10:39:31.340" Score="2" ViewCount="85" Body="&lt;p&gt;I'm trying to implement something like an &amp;quot;inner glow&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;That is, I have an image which defines the shape of an object, and then&#xA;I want to create overlay that is a gradient that goes from the edge of the shape&#xA;and into the shape itself.&#xA;In programs like Photoshop and Krita, this is called an inner glow.&lt;/p&gt;&#xA;&lt;p&gt;If I could first produce a texture which contained values that represented distance&#xA;along the inward travel path from the edge, the rest would be easy.&lt;/p&gt;&#xA;&lt;p&gt;I want this to happen in a shader, but any general insights about the problem would be helpful, I guess.&#xA;One idea that I was working with, was to just blur the outline, and call the result shades around the edges the &amp;quot;distance&amp;quot;, but this might be an unnecessarily expensive operation on the GPU, maybe not, I don't know.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/MjB2K.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MjB2K.png&quot; alt=&quot;image outline&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;A naive approach would be to check all distances to all other pixels, which comes out to something like 256⁴ square root calculations for a 256x256 pixel image. I believe that's not optimal. Also I don't know if that's even possible in a shader.&lt;/p&gt;&#xA;" OwnerUserId="13983" LastActivityDate="2020-09-29T18:15:45.393" Title="How do I efficiently calculate the distance to the edge of a shape?" Tags="&lt;shader&gt;&lt;texture&gt;&lt;algorithm&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10273" PostTypeId="2" ParentId="10271" CreationDate="2020-09-29T13:52:50.560" Score="5" Body="&lt;p&gt;For what it's worth, the &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_020_Skins.md&quot; rel=&quot;noreferrer&quot;&gt;glTF Tutorials contain a section on Skinning&lt;/a&gt; that shows how the raw vertex and joint weight data feed into a vertex shader to distort the mesh.&lt;/p&gt;&#xA;&lt;p&gt;If you do design your own format to hold this, you'll need tooling to export it from 3D content creation software, as well as software to read the new format into your application.  Using an open format like glTF can grant access to existing tools, such as the &lt;a href=&quot;https://docs.blender.org/manual/en/2.90/addons/import_export/scene_gltf2.html&quot; rel=&quot;noreferrer&quot;&gt;Blender glTF exporter&lt;/a&gt;, that can write all this data into the file, in a form that's ready to load into vertex attributes and shaders.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/KhronosGroup/glTF-Tutorials/blob/master/gltfTutorial/gltfTutorial_020_Skins.md&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://raw.githubusercontent.com/KhronosGroup/glTF-Tutorials/master/gltfTutorial/images/skinSkinMatrix.png&quot; alt=&quot;How skins work&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="1908" LastActivityDate="2020-09-29T13:52:50.560" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10274" PostTypeId="2" ParentId="10272" CreationDate="2020-09-29T18:15:45.393" Score="4" Body="&lt;p&gt;A texture that stores distance from the edge of the shape, like you described, is called a &amp;quot;distance field&amp;quot; (you'll find lots of results if you google that phrase). Distance fields can be calculated efficiently on the GPU using the &lt;a href=&quot;https://www.comp.nus.edu.sg/%7Etants/jfa.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;jump flooding algorithm&lt;/a&gt; (JFA).&lt;/p&gt;&#xA;&lt;p&gt;This is a multi-pass algorithm that works by sampling pixels at a distance of first ½ the image size, then ¼, then ⅛, and so on down to single pixels. At the end it comes out with a texture with the shortest distance from each pixel to any of the initial &amp;quot;seed&amp;quot; pixels you put in (which would be along the edge of your shape). For more details see the paper, or also check out &lt;a href=&quot;https://blog.demofox.org/2016/02/29/fast-voronoi-diagrams-and-distance-dield-textures-on-the-gpu-with-the-jump-flooding-algorithm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this blog post by Alan Wolfe&lt;/a&gt; which also has some shadertoys with example implementations.&lt;/p&gt;&#xA;&lt;p&gt;Another article which may interest you is &lt;a href=&quot;https://medium.com/@bgolus/the-quest-for-very-wide-outlines-ba82ed442cd9&quot; rel=&quot;nofollow noreferrer&quot;&gt;The Quest For Very Wide Outlines&lt;/a&gt; by Ben Golus, which addresses this exact issue, discusses a wide variety of GPU implementations (and settles on JFA), and addresses some of the implementation details such as using JFA on an antialiased edge.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-09-29T18:15:45.393" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10275" PostTypeId="1" AcceptedAnswerId="10278" CreationDate="2020-10-01T12:11:00.750" Score="0" ViewCount="62" Body="&lt;p&gt;I've a question about surface deformation using Perlin noise or Simplex noise.&#xA;You can see everywhere on google images how these results look like, if you calculate a 2D / 3D noise and move the surface in normal direction like the image in the following discussion on stackoverflow:&#xA;&lt;a href=&quot;https://stackoverflow.com/questions/53688083/using-analytical-perlin-noise-derivatives-on-a-3d-surface&quot;&gt;https://stackoverflow.com/questions/53688083/using-analytical-perlin-noise-derivatives-on-a-3d-surface&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Using one noise calculation for a vertex seems to be fast, but caves can not appear. It is like generating a height map for a surface.&lt;/p&gt;&#xA;&lt;p&gt;But, has someone tried to use 3D Perlin/Simplex noise for each dimension? So that 3 times a 3D Noise is calculated and the vertex is moved in the dimension direction?&lt;/p&gt;&#xA;&lt;p&gt;I think that of cause caves can be appear and it maybe looks realistic as well.&#xA;I've time pressure to implement some surface distortion and I am only interested in some resulting pictures, to decide using this technique or look for another one.&lt;/p&gt;&#xA;&lt;p&gt;So if someone has already implemented it, please post some resulting images. Thanks a lot!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-10-01T15:58:25.060" Title="Perlin Noise, surface deformation NOT along the normal vector" Tags="&lt;noise&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10276" PostTypeId="2" ParentId="10269" CreationDate="2020-10-01T14:48:16.387" Score="1" Body="&lt;p&gt;Someone else feel free to correct me as I am not 100% certain, but from what I can gather:&lt;/p&gt;&#xA;&lt;p&gt;They are describing all the normalized vectors v, which point at the ray between points v1 and v2.&lt;/p&gt;&#xA;&lt;p&gt;They are doing this using one parameter angle φ.&lt;/p&gt;&#xA;&lt;p&gt;They are essentially interpolating between two vectors o1 and o2, with the equation v = o1 cosφ + o2 sinφ&lt;/p&gt;&#xA;&lt;p&gt;o1 is simply the normalized v1. o2 is a vector at right angles with the o1 along the plane of the ray. (I think this would be calculated by cross product of o1 and N from the paper).&lt;/p&gt;&#xA;&lt;p&gt;Because this angle can sweep greater than the length of the ray defined by v1 and v2 they also define a limit Bmax so that φ always stays within the bounds of the ray.&lt;/p&gt;&#xA;&lt;p&gt;I've tried to annotate the diagram below (but I think I made a mistake and o2 would have an angle create than v1).&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4Notm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4Notm.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;They also discuss it briefly here: &lt;a href=&quot;http://www.aconty.com/pdf/importance-sampling-lights-slides.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.aconty.com/pdf/importance-sampling-lights-slides.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Might be worth mesaging the orinal authors to see if this is correct.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2020-10-01T14:48:16.387" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10277" PostTypeId="2" ParentId="9556" CreationDate="2020-10-01T15:01:09.523" Score="2" Body="&lt;p&gt;I copied my answer for the same OP at &lt;a href=&quot;https://github.com/godotengine/godot/issues/19473&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/godotengine/godot/issues/19473&lt;/a&gt;. But this question differs slightly to the original issue report.&lt;/p&gt;&#xA;&lt;p&gt;In case you want to manually add support for VERTEX_ID, these are the changes I had to make in &lt;code&gt;3.2.3-stable&lt;/code&gt; for &lt;code&gt;spatial&lt;/code&gt; shaders. I wanted to use the vertex ID for creating procedural animations.&lt;/p&gt;&#xA;&lt;p&gt;In &lt;code&gt;drivers/gles3/shader_compiler_gles3.cpp&lt;/code&gt; in the function &lt;code&gt;ShaderCompilerGLES3::ShaderCompilerGLES3()&lt;/code&gt; :&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;actions[VS::SHADER_SPATIAL].renames[&amp;quot;VERTEX_ID&amp;quot;] = &amp;quot;gl_VertexID&amp;quot;;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and &lt;code&gt;servers/visual/shader_types.cpp&lt;/code&gt; in the function &lt;code&gt;ShaderTypes::ShaderTypes()&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;shader_modes[VS::SHADER_SPATIAL].functions[&amp;quot;vertex&amp;quot;].built_ins[&amp;quot;VERTEX_ID&amp;quot;] = constt(ShaderLanguage::TYPE_INT);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then compile the source and it should work. Some other primitives could probably be added in a similar fashion but I have not tested that yet.&lt;/p&gt;&#xA;&lt;p&gt;One caveat is that the vertex IDs reported by Godot are very different from those reported by other tools such as Blender. This is because vertices are duplicated and in a different order. Godot also only gives you two UV channels to work with. Using UV coordinates also means having a temporal component will require significantly more memory to implement as UVs will typically map sparsely onto a 2D texture, if the data is only used in the vertex shader.&lt;/p&gt;&#xA;&lt;p&gt;I have a primitive tool working that can map the vertex animation texture generated in blender to one usable by Godot into another grayscale texture (n by 1 texture, where n is number of vertices in Godot). This saves texture memory as no data is duplicated for duplicated vertices. I first need to implement an octree before it will be usable for real-world meshes and not just a set of simple deforming cubes. Once I have that done in my spare time I will release it for free.&lt;/p&gt;&#xA;" OwnerUserId="14038" LastEditorUserId="14038" LastEditDate="2020-10-01T15:10:46.277" LastActivityDate="2020-10-01T15:10:46.277" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10278" PostTypeId="2" ParentId="10275" CreationDate="2020-10-01T15:58:25.060" Score="2" Body="&lt;p&gt;You can do this, and the results can be interesting, but they’re pretty far from looking like realistic terrain. Here’s a plane deformed with 3D simplex noise (Perlin doesn’t look significantly better):&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/wNOb9.jpg&quot; alt=&quot;warped plane&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;The issue is that there’s no volume to the surface, per se, and nothing preventing it from passing through itself. Deforming it only along the normal vector mostly avoids that. For a surface that looks like terrain, with actual caves, you’ll probably need some kind of voxel system like the one described in &lt;a href=&quot;https://developer.nvidia.com/gpugems/gpugems3/part-i-geometry/chapter-1-generating-complex-procedural-terrains-using-gpu&quot; rel=&quot;nofollow noreferrer&quot;&gt;this GPU Gems article&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2020-10-01T15:58:25.060" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10279" PostTypeId="1" AcceptedAnswerId="10280" CreationDate="2020-10-01T17:36:19.123" Score="1" ViewCount="98" Body="&lt;p&gt;Let's take a look at this blog article - &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&lt;/a&gt; and image presented as a result of implementing it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xzrCR.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xzrCR.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Inside above link, you can see description for this image saying&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;In order to have something to compare to on the left I generated an image by importance sampling a cosine distribution and on the right I generated an image using the technique described above. [...]&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Based on the fact that image on the right was derived based on GGX pdf, how was image on the left generated? I assume we have our standard equation but what does it mean that it's generated with &lt;em&gt;importance sampling a cosine distribution&lt;/em&gt;?&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f(w_i,w_o) = \frac{F(w_i, w_m) ~ G_2(w_i,wo_,w_m) D(w_m)}{4 ~ |w_i \cdot w_g| ~ |w_o \cdot w_g|} * PDF[?]&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-10-01T19:25:27.477" Title="Importance sampling a cosine distribution" Tags="&lt;raytracing&gt;&lt;brdf&gt;&lt;sampling&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10280" PostTypeId="2" ParentId="10279" CreationDate="2020-10-01T19:25:27.477" Score="1" Body="&lt;p&gt;You can sample using absolutely any distribution you want, as long as you weight the results by dividing by the pdf of the sampled distribution. It will converge to the right answer (as long as the distribution is nonzero everywhere that you want to integrate). Different distributions will give different amounts of variance though. The trick with importance sampling is to find a distribution that minimizes variance while still being cheap to compute. A distribution similar to the shape of the function you're integrating, or equal to some factor of that function (so that it cancels when you divide), works best. In other words you try to guide the sampling toward areas that are more important to the result, hence, &amp;quot;importance&amp;quot; sampling.&lt;/p&gt;&#xA;&lt;p&gt;So what the author is saying is the image on the left was sampled with &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt; (or maybe &lt;span class=&quot;math-container&quot;&gt;$\omega_m$&lt;/span&gt;, I'm not sure) drawn from a cosine hemisphere distribution, just as an example of a distribution that does &lt;em&gt;not&lt;/em&gt; match the BRDF very well. Then they calculate the samples as &lt;span class=&quot;math-container&quot;&gt;$f(\omega_i, \omega_o) / p_{\cos}(\omega_o)$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$p_{\cos}$&lt;/span&gt; is the pdf for the cosine distribution. This is just to show you that it gives the &amp;quot;correct&amp;quot; result, but with a ton of variance. (Although it looks like there are some black areas on the left image that suggest it's not really converging to the correct answer...but let's assume that's a bug.)&lt;/p&gt;&#xA;&lt;p&gt;Then the image on the right is sampled with (presumably) &lt;span class=&quot;math-container&quot;&gt;$\omega_m$&lt;/span&gt; drawn from a distribution matching the &lt;span class=&quot;math-container&quot;&gt;$D(\omega_m)$&lt;/span&gt; term from the BRDF. Then when you calculate the BRDF you can leave out the &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; factor since it's canceled by the &lt;span class=&quot;math-container&quot;&gt;$D$&lt;/span&gt; factor in the pdf. (The pdf probably still has some normalization and some conversion of probability from &lt;span class=&quot;math-container&quot;&gt;$\omega_m$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$\omega_o$&lt;/span&gt;, so you still have to divide by those factors.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-10-01T19:25:27.477" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10281" PostTypeId="1" AcceptedAnswerId="10283" CreationDate="2020-10-01T21:35:59.123" Score="1" ViewCount="34" Body="&lt;p&gt;In an HSV model, the Hue is the color model. So when we split the image or remove H, should we get an image without rgb colors?&lt;/p&gt;&#xA;&lt;p&gt;Similarly, saturation is the gray shade. I read that images become more grey and faded in this case. So what should happen when we remove both, hue and saturation, leaving only the vue component behind?&lt;/p&gt;&#xA;&lt;p&gt;Any example images would be nice.&lt;/p&gt;&#xA;" OwnerUserId="14040" LastActivityDate="2020-10-02T18:21:15.477" Title="splitting hue &amp; saturating and leaving value behind" Tags="&lt;image-processing&gt;&lt;color&gt;&lt;image&gt;&lt;color-science&gt;&lt;color-separation&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10282" PostTypeId="2" ParentId="10281" CreationDate="2020-10-02T08:56:28.997" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://alloyui.com/examples/color-picker/hsv.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://alloyui.com/examples/color-picker/hsv.html&lt;/a&gt; - it would be the best for you to play a little with HSV color picker.&lt;/p&gt;&#xA;&lt;p&gt;Problem of color picking with HSV boils down to 2D coordinates (H, S) with additional parameter V. Therefore, you are using H as x-axis value ans S as y-axis value. If you drop H and S (set them to 0), you basically have white color and with V, you can choose grey scale lying between white and black.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-10-02T08:56:28.997" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10283" PostTypeId="2" ParentId="10281" CreationDate="2020-10-02T18:21:15.477" Score="3" Body="&lt;p&gt;Removing hue and saturation (&amp;quot;desaturating&amp;quot;) leads to a grayscale image with the same luminance as the original colors, for instance:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/As70m.jpg&quot; alt=&quot;original image&quot; /&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/i9Lqz.jpg&quot; alt=&quot;grayscale image&quot; /&gt;&lt;br /&gt;&#xA;(source: my own photo)&lt;/p&gt;&#xA;&lt;p&gt;It is not possible to remove hue alone without removing saturation, as any saturated color must be saturated in some direction (hue). Nor is it possible to &amp;quot;split&amp;quot; the image into HSV &amp;quot;components&amp;quot; in quite the way you can split into RGB components. Hue works like an angle of rotation around the &amp;quot;color wheel&amp;quot;, while saturation is the radius from the center:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/WQRVt.png&quot; alt=&quot;hue/saturation color wheel&quot; /&gt;&lt;br /&gt;&#xA;(image from &lt;a href=&quot;https://www.highend.com/pub/support/controllers/documents/html/en/sect-colour_matching.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-10-02T18:21:15.477" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10284" PostTypeId="1" AcceptedAnswerId="10285" CreationDate="2020-10-03T16:44:52.613" Score="4" ViewCount="83" Body="&lt;p&gt;I'm reading PBRT and am stuck in chapter 5.4 about radiometry. In particular:&lt;/p&gt;&#xA;&lt;p&gt;We define the &lt;em&gt;irradiance&lt;/em&gt; as the average density flux arriving at a surface with units &lt;span class=&quot;math-container&quot;&gt;$\frac{W}{m^2}$&lt;/span&gt;. So for a point light source, we have: &lt;span class=&quot;math-container&quot;&gt;$E = \frac{\Phi}{4 \pi r^2}$&lt;/span&gt; since the area of a sphere is &lt;span class=&quot;math-container&quot;&gt;$4 \pi r^2$&lt;/span&gt;. Where &lt;span class=&quot;math-container&quot;&gt;$\Phi$&lt;/span&gt; is the flux or power.&lt;/p&gt;&#xA;&lt;p&gt;A (to me) similar concept is &lt;em&gt;intensity&lt;/em&gt; which is the amount of power per angle. Again, for a sphere with a point light at the center, this is &lt;span class=&quot;math-container&quot;&gt;$I = \frac{\Phi}{4 \pi r^2}$&lt;/span&gt; with the unit &lt;span class=&quot;math-container&quot;&gt;$[\frac{W}{sr}]$&lt;/span&gt; (watt over steradian)&lt;/p&gt;&#xA;&lt;p&gt;Now, the book defines &lt;em&gt;radiance&lt;/em&gt; for a point &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; as &lt;span class=&quot;math-container&quot;&gt;$L = \frac{d\Phi}{d\omega dA^\perp}$&lt;/span&gt; in units &lt;span class=&quot;math-container&quot;&gt;$[\frac{W}{sr\cdot m^2}]$&lt;/span&gt;. Here, &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt; is the direction where the light comes from, &lt;span class=&quot;math-container&quot;&gt;$A^\perp$&lt;/span&gt; is the projected are of &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; as seen here:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/co4VV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/co4VV.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This means that practically, when I implement a point light source with a given power that shines at a point &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;, I need to do the following to arrive at radiance:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Divide by &lt;span class=&quot;math-container&quot;&gt;$4 \pi r^2$&lt;/span&gt; to convert power into &lt;span class=&quot;math-container&quot;&gt;$[\frac{W}{sr}]$&lt;/span&gt;, or in other words, intensity.&lt;/li&gt;&#xA;&lt;li&gt;Given intensity, I need to divide it by &lt;span class=&quot;math-container&quot;&gt;$4 \pi r^2$&lt;/span&gt; and multiply by &lt;span class=&quot;math-container&quot;&gt;$\cos \theta$&lt;/span&gt; to arrive at &lt;span class=&quot;math-container&quot;&gt;$[\frac{W}{sr\cdot m^2}]$&lt;/span&gt;, the final radiance. The multiplication by &lt;span class=&quot;math-container&quot;&gt;$\cos \theta$&lt;/span&gt; is to project &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$A^\perp$&lt;/span&gt; and is the dot product of the surface normal &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; with the direction &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; (as both are normalized).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;For both calculations, &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; is the distance between the light source and my point &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;However, when I look at the source, this is not what happens. The point light returns intensity divided by &lt;span class=&quot;math-container&quot;&gt;$r^2$&lt;/span&gt; as seen &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/master/src/lights/point.cpp#L44&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;return I / DistanceSquared(pLight, ref.p);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and the integrator then multiplies it with the dot product (and the brdf) &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/master/src/integrators/whitted.cpp#L79&quot; rel=&quot;nofollow noreferrer&quot;&gt;in the whitted integrator&lt;/a&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;L += f * Li * AbsDot(wi, n) / pdf;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So what is wrong in my derivation? Why do we &amp;quot;only&amp;quot; divide once by &lt;span class=&quot;math-container&quot;&gt;$4\pi r^2$&lt;/span&gt; (to get the Intensity I) and not twice? Aren't we missing either the power per area or the power per steradian?&lt;/p&gt;&#xA;&lt;p&gt;sources:&#xA;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Color_and_Radiometry/Radiometry.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Color_and_Radiometry/Radiometry.html&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7913" LastActivityDate="2020-10-03T18:43:43.177" Title="Deriving radiance from irradiance and intensity" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10285" PostTypeId="2" ParentId="10284" CreationDate="2020-10-03T18:18:31.463" Score="3" Body="&lt;p&gt;Your definition for radiant intensity is wrong: it should be just &lt;span class=&quot;math-container&quot;&gt;$\Phi / 4\pi$&lt;/span&gt;. There are only &lt;span class=&quot;math-container&quot;&gt;$4\pi$&lt;/span&gt; steradians in a sphere no matter how big it is, so &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; doesn't come into it.&lt;/p&gt;&#xA;&lt;p&gt;Also note that you can't calculate &lt;em&gt;radiance&lt;/em&gt; for a point source—it would be infinite, due to the fact the point source emits a finite amount of flux compressed into zero size. It subtends zero solid angle, from the receiver's point of view, so the &lt;span class=&quot;math-container&quot;&gt;$d\omega$&lt;/span&gt; factor in the denominator of radiance would be zero. The usable quantities are radiant intensity in a certain direction from the point source (which could vary with direction, for a non-omnidirectional light), and irradiance in a certain direction and distance. As you've seen, irradiance is obtained from radiant intensity by dividing by &lt;span class=&quot;math-container&quot;&gt;$r^2$&lt;/span&gt;—you could think of this as &amp;quot;area per steradian&amp;quot;, as it's the conversion factor from &lt;span class=&quot;math-container&quot;&gt;$4\pi$&lt;/span&gt; steradians to &lt;span class=&quot;math-container&quot;&gt;$4\pi r^2$&lt;/span&gt; area of a sphere; then the units work out.&lt;/p&gt;&#xA;&lt;p&gt;Where radiance would actually show up is when dealing with an area light rather than a point light. Then you would have the flux being distributed over a finite solid angle from the receiver's point of view, and you'd get the incident irradiance by integrating the light's radiance over that solid angle. The emitted radiance would be &lt;span class=&quot;math-container&quot;&gt;$\Phi/(2\pi A_\text{light})$&lt;/span&gt;, assuming it's emitted uniformly over the surface of the light and into all directions from each point. This is only &lt;span class=&quot;math-container&quot;&gt;$2\pi$&lt;/span&gt; since it's only emitting into the outward-facing hemisphere. Also note that you don't do any division by &lt;span class=&quot;math-container&quot;&gt;$r^2$&lt;/span&gt; for radiance—with area lights, the distance attenuation comes naturally as a result of the light subtending less solid angle from the receiver's point of view, when the receiver is farther away.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-10-03T18:43:43.177" LastActivityDate="2020-10-03T18:43:43.177" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10287" PostTypeId="1" AcceptedAnswerId="10290" CreationDate="2020-10-04T12:59:38.320" Score="3" ViewCount="110" Body="&lt;p&gt;Assuming I wanted to rasterize a scene of triangles that are all connected that is similar to the image below, what would be an efficient way to do it on a GPU and a CPU? The triangles can be of any size. Names of any methods utilized or any advice is appreciated!&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/00UNC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/00UNC.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="14044" LastActivityDate="2020-10-06T23:11:06.037" Title="Efficient methods to rasterize a scene of connected triangles" Tags="&lt;rasterizer&gt;&lt;triangulation&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10288" PostTypeId="1" CreationDate="2020-10-05T13:38:51.187" Score="0" ViewCount="31" Body="&lt;p&gt;I want to convert STEP files to gLTF.&#xA;I know that gLTF suuports hierarchy of assemblies and parts.&#xA;Source: &lt;a href=&quot;https://cadexchanger.com/blog/283-how-to-load-3d-cad-data-into-three-js-part-2&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://cadexchanger.com/blog/283-how-to-load-3d-cad-data-into-three-js-part-2&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However, it is not straightforward to convert from STEP to gLTF.&#xA;Converting from STEP to gLTF requires a two step approach.&#xA;First convert STEP to COLLADA (.dae) using FreeCAD libraries.&#xA;Then convert from .dae to gLTF using &lt;a href=&quot;https://github.com/KhronosGroup/COLLADA2GLTF&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/KhronosGroup/COLLADA2GLTF&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;So since, first i have to make a pass through .dae files, will hierarchy of assembly be present in my final gLTF file?&lt;/p&gt;&#xA;" OwnerUserId="13375" LastActivityDate="2020-10-05T13:38:51.187" Title="Retaining hierarchy of assembly when converting STEP to GLTF" Tags="&lt;3d&gt;&lt;model&gt;&lt;gltf&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10289" PostTypeId="1" CreationDate="2020-10-05T15:34:58.910" Score="0" ViewCount="226" Body="&lt;p&gt;How to create a zoomable and pannable infinite grid using javascript canvas?&lt;/p&gt;&#xA;&lt;p&gt;Following is the code for creating a draggable infinite grid using library called snap.js&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;const paper = new Snap(&amp;quot;#host&amp;quot;);&#xA;&#xA;const minorLineAttr = { stroke: &amp;quot;gray&amp;quot;, strokeWidth: 0.5 },&#xA;      elements = [],&#xA;      dimension = 100,&#xA;      divisions = 10;&#xA;&#xA;// background box&#xA;elements.push(paper.rect(0, 0, dimension, dimension).attr({&#xA;  fill: 'none',&#xA;  stroke: &amp;quot;gray&amp;quot;, strokeWidth: 1&#xA;}));&#xA;&#xA;// add horizontal &amp;amp; vertical lines&#xA;const lineCount = dimension / divisions;&#xA;&#xA;for (var index=1; index &amp;lt; lineCount; index++) {&#xA;  const offset = lineCount*index,&#xA;        sw = minorLineAttr.strokeWidth;&#xA;  &#xA;  elements.push(paper.line(sw, offset, dimension-sw, offset).attr(minorLineAttr));&#xA;  elements.push(paper.line(offset, sw, offset, dimension-sw).attr(minorLineAttr));&#xA;}&#xA;&#xA;// construct a 3x3 grid that is essentially masked to a 1x1 pattern&#xA;var gridPattern = paper.g(...elements).toPattern(0, 0, dimension, dimension);&#xA;const gridRect = paper.rect(-dimension, -dimension, 3*dimension, 3*dimension).attr({fill: gridPattern});&#xA;const grid3x3Pattern = gridRect.toPattern(0, 0, dimension, dimension);&#xA;const bgRect = paper.rect(0,0,'100%','100%').attr({fill: grid3x3Pattern});&#xA;&#xA;function getElementCoords(x, y, t) {&#xA;  return {&#xA;    x : t.e + x * t.a + y * t.c,&#xA;    y: t.f + x * t.b + y * t.d&#xA;  };&#xA;}&#xA;&#xA;// transform on drag&#xA;const dragStart = function () {&#xA;  console.log(this);&#xA;  const bbox = this.getBBox(),&#xA;        coords = getElementCoords(bbox.x, bbox.y, gridRect.transform().localMatrix);&#xA;  this.data(&amp;quot;coords&amp;quot;, coords);&#xA;};&#xA;&#xA;const dragMove = function(dx, dy) {&#xA;  const coords = this.data(&amp;quot;coords&amp;quot;);&#xA;  gridRect.transform(&amp;quot;t&amp;quot; + (coords.x + dx) % dimension + &amp;quot; &amp;quot; + (coords.y + dy) % dimension);&#xA;};&#xA;&#xA;const dragStop = function() {&#xA;  this.removeData(&amp;quot;coords&amp;quot;);&#xA;};&#xA;&#xA;bgRect.drag(dragMove, dragStart, dragStop);&#xA;&#xA;paper.text(20, 50, &amp;quot;Drag the background&amp;quot;).attr({&#xA;  fill: &amp;quot;#fff&amp;quot;,&#xA;  fontFamily: &amp;quot;Verdana, Arial, Courier&amp;quot;,&#xA;  fontSize: &amp;quot;24&amp;quot;&#xA;});&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is working great , but what I want to achieve is that I want to create a similar grid using html5 canvas api..&lt;/p&gt;&#xA;&lt;p&gt;I'm using Konva for creating html canvas as this library is rich in lot of functionalities.&lt;/p&gt;&#xA;&lt;p&gt;How can I implement the above infinite zoomable and pannable grid using html5 canvas or using konva js?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; that my canvas is overflowing the screen since the content is a lot.&lt;/p&gt;&#xA;&lt;p&gt;So we need a way to mimic infinite grid as shown above that clamps to viewport/container/window dimensions and interacts with the user as drags and zooms.&lt;/p&gt;&#xA;&lt;p&gt;I've tried my own way by creating a bunch of horizontal and vertical lines. But the canvas is getting slow... as I interacts... we need a way to cache or mimic infinite grid so that performance is increased.&lt;/p&gt;&#xA;&lt;p&gt;But when dragged it is not getting clamped to the viewport/container/window width and height as shown in the above snap.svg example.&lt;/p&gt;&#xA;&lt;p&gt;How can I achive that?&lt;/p&gt;&#xA;" OwnerUserId="14049" LastActivityDate="2020-10-05T15:34:58.910" Title="How to create a zoomable and pannable infinite grid using javascript canvas?" Tags="&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10290" PostTypeId="2" ParentId="10287" CreationDate="2020-10-06T01:04:20.450" Score="5" Body="&lt;p&gt;It's an interesting question, because the advice changes over time. Having said that:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;On a GPU, by far the most efficient way, as Nathan Reed said in the comment, is to use the rasterisation hardware because that is that it is designed for.&lt;/li&gt;&#xA;&lt;li&gt;On a CPU, one of the most efficient ways is to more-or-less mimic what rasterisation hardware does.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;GPU vendors are understandably quiet about the specifics of their hardware design, but the basic idea hasn't changed for a few decades.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Conceptually split the screen into tiles, e.g. of 8 by 8 pixels.&lt;/li&gt;&#xA;&lt;li&gt;Traverse the tiles which overlap with a triangle using some variant on &lt;a href=&quot;https://www.cs.drexel.edu/%7Edavid/Classes/Papers/comp175-06-pineda.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pineda's method&lt;/a&gt;.&lt;/li&gt;&#xA;&lt;li&gt;For each tile, compute a bit mask to find the exact pixels (or samples, if you're subsampling) in the bucket which are inside the triangle, using half-plane calculations. In GPU speak, the samples in a tile which are inside the triangle are called a &lt;em&gt;fragment&lt;/em&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Do whatever processing is needed on the fragment.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;On a modern CPU, fragment processing (including the half-space calculations) can be made extremely efficient by using vector instructions.&lt;/p&gt;&#xA;" OwnerUserId="159" LastEditorUserId="159" LastEditDate="2020-10-06T23:11:06.037" LastActivityDate="2020-10-06T23:11:06.037" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10291" PostTypeId="1" CreationDate="2020-10-06T07:03:27.517" Score="1" ViewCount="43" Body="&lt;p&gt;I've been playing around with OpenGL and I'm trying to build out my own UI component library containing things like buttons, text views, labels, views, etc. Eventually I want to abstract it &lt;strong&gt;similar&lt;/strong&gt; to iOS UIKit where I can just call &lt;code&gt;UIButton()&lt;/code&gt; or &lt;code&gt;UIView()&lt;/code&gt; and just generate that UI element. Before I let my imagination go, I am still trying to understand the most effective way to actually develop the initial library. Eventually I want it to be a combination of 2D and 3D graphics. Should I build all the components in say Blender and export the bmp file as a texture and use that? I don't think that's a viable option because eventually I want to add text in runtime to the UI elements and eventually re-shape the size based on constantly changing variables. Even better, is there already a library with this extracted? Similar to CoreGraphics/UIKit?&lt;/p&gt;&#xA;" OwnerUserId="14051" LastActivityDate="2020-10-06T07:03:27.517" Title="Creating a UI component library from scratch" Tags="&lt;opengl&gt;&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10292" PostTypeId="1" AcceptedAnswerId="10314" CreationDate="2020-10-06T09:54:39.123" Score="0" ViewCount="103" Body="&lt;p&gt;&lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&lt;/a&gt; - I have problem implementing this method. Somebody asked question about this before ( &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8465/cant-understand-the-importance-sampling-ggx&quot;&gt;Can&amp;#39;t understand the Importance sampling GGX&lt;/a&gt; ) but it doesn't fully answer my question/problem.&lt;/p&gt;&#xA;&lt;p&gt;Above blog post describe importance sampling method based on importance sampling NDF. Let's start with Cook-Torrance BRDF:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f_r = \frac{F(w_i, w_m) ~ G_2(w_i, w_o, w_m) ~ D(w_m)}{4 ~ |w_i \cdot w_g| ~ |w_o \cdot w_g|}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;After finding PDF for Normal Distribution Function and applying&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;|w_i \cdot w_g|&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;term from rendering equation + found PDF, we have final equation:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\frac{F(w_i, w_m) ~ G_2(w_i, w_o, w_m) ~ |w_o \cdot w_m|}{|w_o \cdot w_g| ~ |w_m \cdot w_g|}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm adding final equation just for completion sake. All transformations are rather long and it's better to check blog post that I've sent. At the end of post, there is code that should be working correctly. However, it doesn't give correct results in my case and my suspicion is that I'm filling gaps in a wrong way:&lt;/p&gt;&#xA;&lt;p&gt;I'm using Correlated Multi-Jittered Sampling here:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float SmithGGXMaskingShadowing(float3 n, float3 l, float3 v, float a2)&#xA;{&#xA;    float dotNL = saturate(dot(n, l));&#xA;    float dotNV = saturate(dot(n, v));&#xA;&#xA;    float denomA = dotNV * sqrt(a2 + (1.0f - a2) * dotNL * dotNL);&#xA;    float denomB = dotNL * sqrt(a2 + (1.0f - a2) * dotNV * dotNV);&#xA;&#xA;    return 2.0f * dotNL * dotNV / (denomA + denomB);&#xA;}&#xA;&#xA;float a2 = roughness * roughness;&#xA;float theta = acos(sqrt((1.0f - brdfSample.x) / ((a2 - 1.0f) * brdfSample.x + 1.0f)));&#xA;float phi = 2.0f * PI * brdfSample.y;&#xA;&#xA;float3 normalTS = float3(0, 1, 0);&#xA;&#xA;float3 wo = -incomingRayDirTS;&#xA;float3 wm = float3(sin(theta) * cos(phi), cos(theta), sin(theta) * sin(phi));&#xA;float3 wi = 2.0f * dot(wo, wm) * wm - wo;&#xA;&#xA;float3 F = Specular_F_Schlick(specularAlbedo.rgb, saturate(dot(wi, wm)));&#xA;float G = SmithGGXMaskingShadowing(wm, wi, wo, a2);&#xA;float weight = abs(dot(wo, wm) / (dot(normalTS, wo) * dot(normalTS, wm)));&#xA;&#xA;rayDirWS = normalize(mul(wi, tangentToWorld));&#xA;&#xA;if (dot(normalTS, wi) &amp;gt; 0.0f &amp;amp;&amp;amp; dot(wi, wm) &amp;gt; 0.0f)&#xA;    throughput = F * G * weight;&#xA;else&#xA;    throughput = 0.0f;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;My main concern is - am I using normal in tangent space (w_g) in a correct way? Schutte Joe mentions in a comment that:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;// -- Ensure our sample is in the upper hemisphere&#xA;// -- Since we are in tangent space with a y-up coordinate&#xA;// -- system BsdfNDot(wi) simply returns wi.y&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;That's why I decided to use w_g (or normalTS) as float3(0, 1, 0).&lt;/p&gt;&#xA;&lt;p&gt;Here is how it looks for 1024 samples with path length equal 4:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3qJ0l.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3qJ0l.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In comparison, here is method based on visible normals described here - &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart2/&lt;/a&gt; ; For 1024 samples, path length 4, results are much better. However, based on data provide by author of the post, there shouldn't be that much difference:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8dGxb.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8dGxb.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Edit: @B_old is right, I mixed TS and WS. I present corrected results above -   image is slightly better but still has very high variance and some bright spots.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-10-06T13:21:42.520" LastActivityDate="2020-10-15T12:08:28.770" Title="Importance sampling GGX NDF - fireflies and bright final result" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;hlsl&gt;&lt;importance-sampling&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10293" PostTypeId="2" ParentId="10247" CreationDate="2020-10-08T02:30:57.013" Score="1" Body="&lt;p&gt;I managed to fix it. It was indeed related to repeating random sequences.&#xA;The problem was the following. &lt;code&gt;curandState* randState&lt;/code&gt; is an array of &lt;code&gt;curandState&lt;/code&gt;s, and most calls to &lt;code&gt;curand_*&lt;/code&gt; require a pointer of a &lt;code&gt;curandState&lt;/code&gt;.&#xA;I was sending the &lt;code&gt;randState&lt;/code&gt;, the array, to &lt;code&gt;curand_*&lt;/code&gt; functions and not for example, a pointer of one of its members.&#xA;Now most of my images are like this: &lt;a href=&quot;https://i.stack.imgur.com/asZM7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/asZM7.png&quot; alt=&quot;current image output&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13456" LastActivityDate="2020-10-08T02:30:57.013" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10294" PostTypeId="2" ParentId="9409" CreationDate="2020-10-08T08:26:56.167" Score="2" Body="&lt;p&gt;&lt;strong&gt;Yes, throughput doesn't have to be in range [0, 1].&lt;/strong&gt; That's a reason why you have to use exposure settings, because for differente accumulation time, brightness of an image might differ. Nathan Reed described it in details here - &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10244/10129&quot;&gt;https://computergraphics.stackexchange.com/a/10244/10129&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Your final results and number of fireflies and bright surfaces, depends on PDF that you'll be using. By using Normal Distribution Function PDF, you'll get good results, because NDF is the most determining factor of BRDF shape. Relate to this blog post for details - &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart1/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Back to throughput range. Assuming that you're sampling based on NDF, you'll get fireflies in case of having values in specific range, when light source is shining from very low angle and you're looking directly at the object. Therefore, your denominator might be much greater than nominator and result in small PDF causing fireflies:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;p_i(w_m, w_o) = \frac{D(w_m)(w_g \cdot w_i)}{4|w_g \cdot w_m|}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gg4J4.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gg4J4.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Since 2014, Heitz was working on BSDFs, presenting good results in same year by sampling visible normals [2]. In 2017, he published much simpler, faster and better paper, improving his method [3]. There are also 2015 and 2016 papers in related field, but I haven't read them, but it might be beneficial if you're interested in BSDF. I would recommend checking his first 2014's work (1) where he explains physical assumption on which BRDF is based. It's worth knowing, what NDF and Geometry Shadowing exactly means in BRDF.&lt;/p&gt;&#xA;&lt;p&gt;Also, there is a lot of good reading in pbrt book, especially:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Sampling_Reflection_Functions.html#MicrofacetBxDFs&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Sampling_Reflection_Functions.html#MicrofacetBxDFs&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/Importance_Sampling.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/Importance_Sampling.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;For more advanced method, I think it'd be worth reading about Russian Roulette and more efficient Path Tracing algorithms like Bidirectional Path Tracing, Metropolis Light Tracing and Photon Mapping methods&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;(1) Eric Heitz - Understanding the Masking-Shadowing Functionin Microfacet-Based BRDFs &lt;a href=&quot;http://jcgt.org/published/0003/02/03/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://jcgt.org/published/0003/02/03/paper.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;(2) Eric Heitz, Eugene d’Eon - Importance Sampling Microfacet-Based BSDFs using the Distribution of Visible Normals &lt;a href=&quot;https://hal.inria.fr/hal-00996995v1/document&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://hal.inria.fr/hal-00996995v1/document&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;(3) Eric Heitz - A Simpler and Exact Sampling Routine for the GGXDistribution of Visible Normals &lt;a href=&quot;https://hal.archives-ouvertes.fr/hal-01509746/document&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://hal.archives-ouvertes.fr/hal-01509746/document&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2020-10-08T08:38:55.080" LastActivityDate="2020-10-08T08:38:55.080" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10295" PostTypeId="1" AcceptedAnswerId="10296" CreationDate="2020-10-08T11:20:47.103" Score="0" ViewCount="39" Body="&lt;p&gt;I have a low-poly mesh and I want to add structure on the surface.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The setup:&lt;/strong&gt;&#xA;The mesh consists of triangles.&#xA;Within the TCS the pixel-length for each of the three edges will be calculated and subdivided according to the given allowed u_MAX_LENGTH_TRIANGLE_EDGE. This will be done in the following way:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec4 vertexPosScreen[3];                                           &#xA;for (int i = 0; i &amp;lt; 3; i++)                                   &#xA;{                                                            &#xA;    vertexPosScreen[i] = vec4(mvp * gl_in[i].gl_Position);          &#xA;    vertexPosScreen[i] = vertexPosScreen[i] / vertexPosScreen[i].w; &#xA;    vertexPosScreen[i].x *= u_viewportWidth;                     &#xA;    vertexPosScreen[i].y *= u_viewportHeight;                    &#xA;}         &#xA;float edgeLength[3];                                                                                                  &#xA;edgeLength[2] = length(vertexPosScreen[0].xy - vertexPosScreen[1].xy);&#xA;edgeLength[1] = length(vertexPosScreen[0].xy - vertexPosScreen[2].xy);&#xA;edgeLength[0] = length(vertexPosScreen[1].xy - vertexPosScreen[2].xy);           &#xA;&#xA;float edgeLod[3];                                         &#xA;for (int i = 0; i &amp;lt; 3; ++i)                           &#xA;{                                                       &#xA;    edgeLod[i] = max(1.0, edgeLength[i] / u_MAX_LENGTH_TRIANGLE_EDGE;&#xA;}                                                           &#xA;                                                                       &#xA;gl_TessLevelOuter[0] = edgeLod[0];                        &#xA;gl_TessLevelOuter[1] = edgeLod[1];                      &#xA;gl_TessLevelOuter[2] = edgeLod[2];                      &#xA;                                                                       &#xA;gl_TessLevelInner[0] = max(edgeLod[0], max(edgeLod[1], edgeLod[2]));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This guarantees, that in the final image all triangles edges are smaller than u_MAX_LENGTH_TRIANGLE_EDGE.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;But:&lt;/strong&gt;&lt;br /&gt;&#xA;The GPU is not able to subdivide as mush as wanted. So if we are too close to a triangle, or a triangle is too tall at all, the TCS will subdivide it as mush as possible, but not enough.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;My Idea:&lt;/strong&gt;&lt;br /&gt;&#xA;After tessellation is done, the new generated triangles should be stored into a new VBO during the TES step. Afterwards the fresh stored triangles in the new VBO will be rendered again and subdivided as well until all of them are small enough.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Now the big question&lt;/strong&gt;&lt;br /&gt;&#xA;How are the tessellation limits defined? per edge division? And how can I ask for the maximum division on CPU? glGetInteger? Or is it limited during the number of generated vertices?&lt;/p&gt;&#xA;&lt;p&gt;I think the easiest solution would be check directly after &amp;quot;edgeLod&amp;quot; is calculated, if edgeLod is too high. If this is the case, write something into a SSBO and loop the shaderprogram again.&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-10-08T14:04:48.023" Title="Tessellation Controll Shader how to get maximum subdivisions limit?" Tags="&lt;opengl&gt;&lt;tesselation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10296" PostTypeId="2" ParentId="10295" CreationDate="2020-10-08T14:04:48.023" Score="1" Body="&lt;p&gt;The tessellation limit is GPU dependent..Any number above the GPU limit is technically an error but most gpu's just clamp to the upper limit. To get beyond the limit either use a Level Of Detail (LOD) approach where you have different models that are used based on distance, or save and recompute like you suggest.&lt;/p&gt;&#xA;&lt;p&gt;To get the max just set all the edges to the limit AND set all the internals to the limit in the tessellation control shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;&#xA;  layout(vertices = 4) out;&#xA;&#xA;void main(void)&#xA;{&#xA;   gl_TessLevelOuter[0] = 64.0;&#xA;   gl_TessLevelOuter[1] = 64.0;&#xA;   gl_TessLevelOuter[2] = 64.0;&#xA;   gl_TessLevelOuter[3] = 64.0;&#xA;&#xA;   gl_TessLevelInner[0] = 64.0;&#xA;   gl_TessLevelInner[1] = 64.0;&#xA;&#xA;   gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;And how can I ask for the maximum division on CPU?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Yes use glGetInteger. At the bottom of this page is all the values you would be intrested in: &lt;a href=&quot;https://www.khronos.org/opengl/wiki/GLAPI/glGet&quot; rel=&quot;nofollow noreferrer&quot;&gt;Khoronos Tessellation limits, search for tessellation on the page&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-10-08T14:04:48.023" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10297" PostTypeId="1" CreationDate="2020-10-09T02:05:03.753" Score="1" ViewCount="44" Body="&lt;p&gt;Say that you are taking pictures from a street like this one:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/eLOfs.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eLOfs.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see, the picture is taken perpendicular to the direction of the street.&lt;/p&gt;&#xA;&lt;p&gt;The problem is that cars at the left look as if they are going East South:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7VpIt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7VpIt.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And cars at the right look as if they are going East North:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ndwxz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ndwxz.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Only when they're right in front of you, the cars look like going simply East:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/eajgo.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eajgo.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As I understand, the name for this phenomena is called &amp;quot;Horizontal Convergence&amp;quot;. How could you remove this phenomena from a picture? That is, how can I transform the image so that all the cars look like going simply to the East no matter their horizontal position.&lt;/p&gt;&#xA;&lt;p&gt;To read about a &amp;quot;vertical congergence&amp;quot;: &lt;a href=&quot;https://digital-photography-school.com/how-to-overcome-the-problem-of-converging-verticals/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://digital-photography-school.com/how-to-overcome-the-problem-of-converging-verticals/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="14062" LastEditorUserId="14062" LastEditDate="2020-10-09T05:59:48.800" LastActivityDate="2020-10-09T05:59:48.800" Title="What's the name of the transformation that can remove horizontal convergence from a picture?" Tags="&lt;transformations&gt;&lt;camera&gt;&lt;distortion&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10299" PostTypeId="2" ParentId="9354" CreationDate="2020-10-10T20:42:58.860" Score="1" Body="&lt;p&gt;You are talking apples and oranges here. Copying memory to memory on the CPU is using completely different hardware then memory to memory copies on the GPU, even in a unified memory architecture GPU's tend to have specialized memory.&lt;/p&gt;&#xA;&lt;p&gt;The actual difference is going to depend heavily on the model of the GPU, a high end gddr5 gpu will easily beat DDR4 dual channel memory on the CPU.&lt;/p&gt;&#xA;&lt;p&gt;Also, the driver implementation is going to have an effect on the gpu copy since you are really asking the driver for the copy on the gpu, which it then translates into code that does the actual copy.&lt;/p&gt;&#xA;&lt;p&gt;The size of the chunk of memory also plays a major role in how fast the copy happens, as well as how large the cache on the cpu vs gpu is.&lt;/p&gt;&#xA;&lt;p&gt;You should generally expect copies that are GPU to GPU to be much faster then CPU to CPU copies. CPU to GPU along with GPU to CPU copies have to cross the AGP bus on the PC while unified architecture systems have an advantage they still have synchronization issues and all systems have to synchronize access and flush cache's.&lt;/p&gt;&#xA;&lt;p&gt;What are the actual differences?(very roughly) DDR4 runs from 1600 to 3200 MB per second and DDR5 run's at roughly 3200 to 6400 MB per second. So very roughly, a poorly balanced system will have up to 4x performance diffence, but you should expect about a 2x performance differnce with the GPU being faster. This difference fades somewhat(mostly) with unified systems. (But the gpu will probably still have memory set aside so it can work with framebuffers and what not in an efficient manner)&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2020-10-10T22:07:49.343" LastActivityDate="2020-10-10T22:07:49.343" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10300" PostTypeId="1" CreationDate="2020-10-11T20:30:38.923" Score="0" ViewCount="101" Body="&lt;p&gt;I am aware this question might be a bit vague, but i am searching for papers or posts about how raster based brush engine, normally used with pens (as in Krita fE), work.&lt;/p&gt;&#xA;&lt;p&gt;I already implemented a simple rubber-stamp style brush engine in QT but am running into multiple problems regarding the quality and parametrization.&lt;br /&gt;&#xA;The default drawLine functions most frameworks support does not really help in my case since i need to be able to have variable size and color/opacity based on pen pressure and similar WITHIN a stroke.&lt;/p&gt;&#xA;&lt;p&gt;Looking into Krita (and other OSS software in hat area) is definitely something i will do, but currently i am searching for more abstract information and dos and don'ts regarding this topic.&#xA;It might be that my googlefu is bad, but i didn't found much on arxiv.org or similar yet.&lt;/p&gt;&#xA;&lt;p&gt;Grateful for any tips or just better terms to search for.&lt;/p&gt;&#xA;" OwnerUserId="1865" LastActivityDate="2020-10-14T18:09:36.210" Title="Searching for papers about brush engines" Tags="&lt;drawing&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10301" PostTypeId="1" CreationDate="2020-10-11T23:01:00.937" Score="0" ViewCount="34" Body="&lt;p&gt;Is there a way to take a random value (or set of values), and cause them to create a &amp;quot;pretty&amp;quot; pattern (as a thumbprint), and that array of thumbprints might have a rendering mask on just for aesthetic purposes.&lt;/p&gt;&#xA;&lt;p&gt;Since I don't know much about all that can be done in Photoshop and Illustrator, I hope someone can help clarify my terminology such as &amp;quot;Random numbers (in the range of X/by way of formula Y) are best expressed in {Hue, Saturation, CMYK, RGB, chemically, theoretically}&amp;quot; ... etc&lt;/p&gt;&#xA;" OwnerUserId="14074" LastActivityDate="2021-03-11T20:03:30.327" Title="Could the Tetradic color pattern be expanded to allow /dev/random be &quot;pretty&quot; for cryptographic key purposes?" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10302" PostTypeId="1" AcceptedAnswerId="10313" CreationDate="2020-10-12T15:21:01.570" Score="0" ViewCount="78" Body="&lt;p&gt;I'm creating DXR PathTracer highly influence by Matt Pettineo's one - &lt;a href=&quot;https://github.com/TheRealMJP/DXRPathTracer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/TheRealMJP/DXRPathTracer&lt;/a&gt; ; Relevant HLSL code below:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[shader(&amp;quot;raygeneration&amp;quot;)]&#xA;void RayGen()&#xA;{&#xA;    // Accumulate for limited amount of frames&#xA;    if (g_giCB.maxFrames &amp;gt; 0 &amp;amp;&amp;amp; g_giCB.accFrames &amp;gt;= g_giCB.maxFrames)&#xA;    {&#xA;        return;&#xA;    }&#xA;    uint2 LaunchIndex = DispatchRaysIndex().xy;&#xA;    uint2 LaunchDimensions = DispatchRaysDimensions().xy;&#xA;    &#xA;    if (g_giCB.samplingType == SAMPLE_MJ)&#xA;    {&#xA;        const uint pixelIdx = LaunchIndex.y * LaunchDimensions.x + LaunchIndex.x;&#xA;        uint sampleSetIdx = 0;&#xA;        offset = SamplePoint(pixelIdx, sampleSetIdx);&#xA;        seed = pixelIdx;&#xA;        seed2 = sampleSetIdx;&#xA;    }&#xA;    &#xA;    float3 primaryRayOrigin = g_sceneCB.cameraPosition.xyz;&#xA;    float3 primaryRayDirection;&#xA;    GenerateCameraRay(LaunchIndex, LaunchDimensions, g_sceneCB.projectionToWorld, primaryRayOrigin, primaryRayDirection, offset);&#xA;    &#xA;    // Prepare payload&#xA;    PayloadIndirect indirectPayload;&#xA;    indirectPayload.color = float3(0, 0, 0);&#xA;    indirectPayload.roughness = 0;&#xA;    indirectPayload.rndSeed = seed;&#xA;    indirectPayload.rndSeed2 = seed2;&#xA;    indirectPayload.pathLength = 0;&#xA;    indirectPayload.diffusePath = false;&#xA;        &#xA;    // Calculate pixel color in current pass and merge with previous frames&#xA;    float4 finalColor = float4(shootIndirectRay(primaryRayOrigin, primaryRayDirection, 1e-3f, indirectPayload), 1.0f);&#xA;    bool colorsNan = any(isnan(finalColor));&#xA;    if (colorsNan)&#xA;    {&#xA;        finalColor = float4(0, 0, 0, 1);&#xA;    }&#xA;    &#xA;    const float FP16Max = 65000.0f;&#xA;    finalColor = clamp(finalColor, 0.0f, FP16Max);&#xA;    &#xA;    if (g_giCB.accFrames &amp;gt; 0)&#xA;    {&#xA;        float4 prevScene = RTOutput[LaunchIndex];&#xA;        finalColor = ((float) g_giCB.accFrames * prevScene + finalColor) / ((float) g_giCB.accFrames + 1.0f);&#xA;    }&#xA;    RTOutput[LaunchIndex] = finalColor;&#xA;}&#xA;&#xA;[shader(&amp;quot;miss&amp;quot;)]&#xA;void Miss(inout RayPayload payload : SV_RayPayload)&#xA;{&#xA;    payload.vis = 1.0f;&#xA;}&#xA;&#xA;[shader(&amp;quot;closesthit&amp;quot;)]&#xA;void ClosestHit(inout PayloadIndirect payload, in BuiltInTriangleIntersectionAttributes attribs)&#xA;{&#xA;&#xA;}&#xA;&#xA;[shader(&amp;quot;miss&amp;quot;)]&#xA;void MissIndirect(inout PayloadIndirect payload : SV_RayPayload)&#xA;{&#xA;    // Use skybox as contribution if ray failed to hit geometry (right now, disabled for debug purposes)&#xA;    float3 rayDir = WorldRayDirection();&#xA;    rayDir.z = -rayDir.z;&#xA;    if (g_giCB.useSkybox)&#xA;    {&#xA;        payload.color += skyboxTexture.SampleLevel(g_sampler, rayDir, 0).rgb;&#xA;    }&#xA;}&#xA;   &#xA;float3 CalcLighting(in float3 normal, in float3 lightDir, in float3 peakIrradiance,&#xA;                    in float3 diffuseAlbedo, in float3 specularAlbedo, in float roughness,&#xA;                    in float3 positionWS, in float3 cameraPosWS, in float3 msEnergyCompensation)&#xA;{&#xA;    float3 lighting = diffuseAlbedo * INV_PI;&#xA;&#xA;    float3 view = normalize(cameraPosWS - positionWS);&#xA;    const float NoL = saturate(dot(normal, lightDir));&#xA;    if (NoL &amp;gt; 0.0f)&#xA;    {&#xA;        const float NoV = saturate(dot(normal, view));&#xA;        float3 h = normalize(view + lightDir);&#xA;&#xA;        float3 fresnel = Fresnel(specularAlbedo, h, lightDir);&#xA;&#xA;        float specular = GGXSpecular(roughness, normal, h, view, lightDir);&#xA;        lighting += specular * fresnel * msEnergyCompensation;&#xA;    }&#xA;&#xA;    return lighting * NoL * peakIrradiance;&#xA;}&#xA;    &#xA;float3 CalculateRadiance(inout PayloadIndirect payload, in BuiltInTriangleIntersectionAttributes attribs)&#xA;{&#xA;    /* Prepare input data */&#xA;    float3 hitPos = WorldRayOrigin() + WorldRayDirection() * RayTCurrent();&#xA;    float3 triangleNormal, triangleTangent, triangleBitangent;&#xA;    loadHitData(triangleNormal, triangleTangent, triangleBitangent, attribs);&#xA;&#xA;    float4 albedo = albedoTexture.Load(int3(DispatchRaysIndex().xy, 0));&#xA;&#xA;    float roughness = specularTexture.Load(int3(DispatchRaysIndex().xy, 0)).g;&#xA;    roughness = max(roughness, payload.roughness);&#xA;    float metallic = specularTexture.Load(int3(DispatchRaysIndex().xy, 0)).b;&#xA;    float3 normalTextureData = NormalTextureInput.Load(int3(DispatchRaysIndex().xy, 0)).rgb;&#xA;    float3x3 tangentToWorld = float3x3(triangleTangent, triangleBitangent, triangleNormal);&#xA;    float3 normalWS = triangleNormal;&#xA;&#xA;    bool enableDiffuse = metallic &amp;lt; 1.0f;&#xA;    bool enableSpecular = !payload.diffusePath;&#xA;    &#xA;    if (enableDiffuse == false &amp;amp;&amp;amp; enableSpecular == false)&#xA;        return float3(0, 0, 0);&#xA;    &#xA;    const float3 diffuseAlbedo = lerp(albedo.rgb, 0.0f, metallic) * (enableDiffuse ? 1.0f : 0.0f);&#xA;    const float3 specularAlbedo = lerp(0.03f, albedo.rgb, metallic) * (enableSpecular ? 1.0f : 0.0f);&#xA;&#xA;    float3 msEnergyCompensation = float3(1, 1, 1);&#xA;    float2 DFG = dfgTexture.SampleLevel(g_sampler, float2(saturate(dot(triangleNormal, -WorldRayDirection())), roughness), 0.0f).xy;&#xA;    float Ess = DFG.x;&#xA;    msEnergyCompensation = float3(1, 1, 1) + specularAlbedo * (1.0f / Ess - 1.0f);&#xA;    float3 worldOrigin = WorldRayOrigin();  &#xA;    /*********************************************/&#xA;    &#xA;    // Calculate directional light&#xA;    {&#xA;        float3 V = g_sceneCB.cameraPosition.xyz;&#xA;        float3 N = triangleNormal.xyz;&#xA;        &#xA;        float3 L = normalize(g_giCB.sunDirection);&#xA;        float distToLight = 1e+38f;&#xA;        &#xA;        // Check visibility&#xA;        float NoL = saturate(dot(N, L));&#xA;        float visibility = shadowRayVisibility(hitPos, L, 1e-3f, distToLight);&#xA;        &#xA;        // Calculate light contribution to point in world (diffuse lambertian term)&#xA;        payload.color += CalcLighting(triangleNormal, L, 1.0f, diffuseAlbedo, specularAlbedo,&#xA;                    roughness, hitPos, worldOrigin, msEnergyCompensation) * visibility;&#xA;    }&#xA;&#xA;    float2 brdfSample = SamplePoint(payload.rndSeed, payload.rndSeed2);&#xA;                &#xA;    float selector = brdfSample.x;&#xA;    if (enableSpecular == false)&#xA;        selector = 0.0f;&#xA;    else if (enableDiffuse == false)&#xA;        selector = 1.0f;&#xA;        &#xA;    if (g_giCB.useIndirect == 1)&#xA;    {&#xA;        float3 throughput = float3(0, 0, 0);&#xA;                    &#xA;        // Find next direction&#xA;        float3 rayDirWS = float3(0, 0, 0);&#xA;        if (g_giCB.samplingType == SAMPLE_MJ)&#xA;        {&#xA;            if (selector &amp;lt; 0.5f)&#xA;            {&#xA;                if (enableSpecular)&#xA;                    brdfSample.x *= 2.0f;&#xA;                float3 rayDirTS = SampleDirectionCosineHemisphere(brdfSample.x, brdfSample.y);&#xA;                rayDirWS = normalize(mul(rayDirTS, tangentToWorld));&#xA;                throughput = diffuseAlbedo;&#xA;            }&#xA;            else&#xA;            {&#xA;                if (enableDiffuse)&#xA;                    brdfSample.x = (brdfSample.x - 0.5f) * 2.0f;&#xA;&#xA;                float3 incomingRayDirWS = WorldRayDirection();&#xA;                float3 incomingRayDirTS = normalize(mul(incomingRayDirWS, transpose(tangentToWorld)));&#xA;&#xA;                float3 wo = incomingRayDirTS;&#xA;                float3 wm = SampleGGXVisibleNormal(-wo, roughness, roughness, brdfSample.x, brdfSample.y);&#xA;                float3 wi = reflect(wo, wm);&#xA;&#xA;                float3 normalTS = float3(0.0f, 0.0f, 1.0f);&#xA;&#xA;                float3 F = Fresnel(specularAlbedo.rgb, wm, wi);&#xA;                float G1 = SmithGGXMasking(normalTS, wi, -wo, roughness * roughness);&#xA;                float G2 = SmithGGXMaskingShadowing(normalTS, wi, -wo, roughness * roughness);&#xA;&#xA;                throughput = (F * (G2 / G1));&#xA;                float3 rayDirTS = wi;&#xA;                rayDirWS = normalize(mul(rayDirTS, tangentToWorld));&#xA;                    &#xA;#if 1&#xA;                DFG = dfgTexture.SampleLevel(g_sampler, float2(saturate(dot(triangleNormal, -WorldRayDirection())), roughness), 0.0f).xy;&#xA;                Ess = DFG.x;&#xA;                throughput *= float3(1, 1, 1) + specularAlbedo * (1.0f / Ess - 1.0f);&#xA;#endif&#xA;            }&#xA;        }&#xA;            &#xA;        if (enableDiffuse &amp;amp;&amp;amp; enableSpecular)&#xA;            throughput *= 2.0f;&#xA;            &#xA;        if (payload.pathLength &amp;lt; g_giCB.bounceCount)&#xA;        {&#xA;            // Prepare payload&#xA;            PayloadIndirect newPayload;&#xA;            newPayload.pathLength = payload.pathLength + 1;&#xA;            newPayload.rndSeed = payload.rndSeed;&#xA;            newPayload.rndSeed2 = payload.rndSeed2;&#xA;            newPayload.color = float3(0, 0, 0);&#xA;            newPayload.diffusePath = (selector &amp;lt; 0.5f);&#xA;            newPayload.roughness = roughness;&#xA;            &#xA;            // Calculate next ray bounce color contribution&#xA;            float3 bounceColor = shootIndirectRay(hitPos, rayDirWS, 1e-3f, newPayload);&#xA;            &#xA;            // Check to make sure our randomly selected, normal mapped diffuse ray didn't go below the surface.&#xA;            if (dot(normalWS, rayDirWS) &amp;lt;= 0.0f)&#xA;                bounceColor = float3(0, 0, 0);&#xA;            &#xA;            payload.color += bounceColor * throughput; //* albedo.rgb;&#xA;        }&#xA;    }&#xA;    &#xA;    return payload.color;&#xA;}&#xA;&#xA;[shader(&amp;quot;closesthit&amp;quot;)]&#xA;void ClosestHitIndirect(inout PayloadIndirect payload, in BuiltInTriangleIntersectionAttributes attribs)&#xA;{&#xA;    payload.color = CalculateRadiance(payload, attribs);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Problem with my code occurs when using path of length more than 1 (indirect light bounces more than once). Shadows are starting to disappear and objects doesn't look grounded anymore. Series of images will occur now. Open full-size for better comparison. Points of interest marked in red in first image. Information about path length can be seen in GUI on the left. All images are generated with 1024 spp.&lt;/p&gt;&#xA;&lt;p&gt;Here is my render (1-4-8 indirect bounces in that order):&#xA;&lt;a href=&quot;https://i.stack.imgur.com/b21tq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/b21tq.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Urvp5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Urvp5.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/r2Y4V.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/r2Y4V.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see, information about shadows are lost in the process of increasing path length. Now, I tried to skip skybox, so any miss shader will just return (0, 0, 0) instead of skybox values. Results are slightly better (4, 8 indirect bounces):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3UQYK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3UQYK.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/31t8j.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/31t8j.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here is reference from MJP's Path Tracer mentioned above (3-6 path length, but it's calculated differently. In my terms in 1-4 path length actually). No specular paths. Take a look at points of interest. Shadows are well grounded and you can see that creases are not getting many light:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yEPdB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yEPdB.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/cmP1v.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/cmP1v.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And here is ground truth reference created in MJP's Path Tracer with 5000 spp, 8 (in my terms - 6) path length:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qGbFG.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qGbFG.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-10-15T08:31:11.677" Title="Pathtracing - many bounces reduce shadows" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;hlsl&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="10303" PostTypeId="2" ParentId="10301" CreationDate="2020-10-12T19:29:22.970" Score="0" Body="&lt;p&gt;It depends on how you define “pretty”, but there’s plenty of possibilities. Assembling a grid of shapes as in &lt;a href=&quot;https://en.wikipedia.org/wiki/Identicon&quot; rel=&quot;nofollow noreferrer&quot;&gt;Identicon&lt;/a&gt;s would be one example; using the numbers for coordinates and zoom levels on a fractal like the &lt;a href=&quot;https://en.wikipedia.org/wiki/Julia_set&quot; rel=&quot;nofollow noreferrer&quot;&gt;Julia set&lt;/a&gt; would be another. Our eyes aren’t good at measuring absolute values of anything—perception is heavily dependent on context and lighting, cf. &lt;a href=&quot;https://en.wikipedia.org/wiki/The_dress&quot; rel=&quot;nofollow noreferrer&quot;&gt;the dress&lt;/a&gt;—so you probably shouldn’t rely on color alone as the identifying factor.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2020-10-12T19:29:22.970" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10304" PostTypeId="1" AcceptedAnswerId="10317" CreationDate="2020-10-12T20:25:30.083" Score="0" ViewCount="88" Body="&lt;p&gt;Following the instructions from &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5918/14079&quot;&gt;this post on Stack Overflow&lt;/a&gt;, I have been able to find points A, B, and C from points V1, V2, and V3 and a radius value (code below). I would like to be able to find a specified number of subdivisions for the arc section labeled 'Arc B.' Can anyone help me find these position values of these points please?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7ntvp.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7ntvp.jpg&quot; alt=&quot;Finding Start and End Angles&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;    r = 106 #radius&#xA;    V1 = Vector(50, 100, 0)&#xA;    V2 = Vector(100, 300, 0)&#xA;    V3 = Vector(350, 350, 0)&#xA;    a = V2-V1&#xA;    b = V2-V3&#xA;    a.Normalize()&#xA;    b.Normalize()&#xA;    halfang = math.acos((a.Dot(b)))/2&#xA;    ab = (a+b)/2&#xA;    ab.Normalize()&#xA;    A = V2 - r/math.tan(halfang)*a&#xA;    B = V2 - r/math.tan(halfang)*b&#xA;    C = V2 - r/math.sin(halfang)*ab&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14079" LastEditorUserId="14079" LastEditDate="2020-10-12T21:12:43.180" LastActivityDate="2020-10-15T22:37:27.460" Title="Rounding a 3D corner with Subdivisions" Tags="&lt;3d&gt;&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;subdivision&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10306" PostTypeId="1" AcceptedAnswerId="10311" CreationDate="2020-10-13T17:06:52.670" Score="2" ViewCount="113" Body="&lt;p&gt;I want to load a vertex buffer with vertices of struct &lt;code&gt;Vertex&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex {&#xA;   Vector3 position;&#xA;   Vector3 normal;&#xA;   Vector2 uv;&#xA;   int groups[10];&#xA;   float weights[10];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;According to &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribPointer.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;khronos manual&lt;/a&gt;, the number of elements in vertex attributes must be &lt;code&gt;1,2,3,4&lt;/code&gt;. If that is the case how do I load the vertex attributes consisting of more elements, in this case 10?&lt;/p&gt;&#xA;&lt;p&gt;Is this not valid?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);&#xA;  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, normal));  &#xA;  glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, uv));  &#xA;  glVertexAttribIPointer(3, 10, GL_INT, sizeof(Vertex), (void*)offsetof(Vertex, groups));   &#xA;  glVertexAttribPointer(4, 10, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, weights));&#xA;    &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I need groups and weight vertex attributes for skeletal deformation.&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-10-13T17:22:08.867" LastActivityDate="2021-05-02T09:22:53.007" Title="Max number of elements in a vertex attribute" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10307" PostTypeId="2" ParentId="10304" CreationDate="2020-10-13T19:13:47.390" Score="0" Body="&lt;p&gt;One very simple way to do it is to just find the straight line distance between the points A and C. Divide that distance by the number of points you want to subdivide+1. Then starting at A moving along the line formed between A and C add that distance for each subdivision. This gives a nice even subdivision without having to argue with PI.&lt;/p&gt;&#xA;&lt;p&gt;To get the point on the circle, just take the normalized vector between B and your new point and multiply it by the radius of the circle. The result is a subdivision point on your circle/sphere.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float distanceAC = length(C-A);&#xA;float stepLength = distanceAC/(SubdivisionsCount+1); // 4 in this case&#xA;vector v = C-A; // gives a vector pointing from A to C&#xA;v = normalize(v);&#xA;for( int i=1; i&amp;lt;SubdivisionCount+1; i++ ){&#xA;     point pointOnLine = A + v*i*stepLength; // Need steplength*i steps along v&#xA;     point subdivisionLocation = normalize(pointOnLine-B)*radius;&#xA;     // save the subdivision location&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This has the plus of being simple, but the negative is that if you want to do to many steps or you want your steps to be extremely accurate, or you want to subdivide over a very large arc, then accuracy suffers.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-10-13T19:13:47.390" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10309" PostTypeId="1" CreationDate="2020-10-14T14:04:41.617" Score="0" ViewCount="196" Body="&lt;p&gt;Using Open 3D Model Viewer, I have converted an OBJ file to an STL file.&#xA;In the source file, the Vertex Normals are specified and in the destination, the face normal of the triangles are present which are different than the normals one would get by (a-b) x (a-c), where a, b, c are the vertex coordinates and x is the cross product. How one would compute the face normal in the presence of vertex normals?&lt;/p&gt;&#xA;&lt;p&gt;Also, I am given to understand that STL format has a positive octant rule which requires all vertex coordinates to be positive. When the OBJ file has negative vertex coordinates, what should be done in the conversion process?&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2020-11-17T23:31:19.647" Title="Vertices, Vertex Normals and Face Normals" Tags="&lt;3d&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;model&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10311" PostTypeId="2" ParentId="10306" CreationDate="2020-10-14T16:45:47.670" Score="4" Body="&lt;p&gt;The standard solution is to reduce the amount of per-vertex data by only specifying the 4 indices that have the highest weights (and rescaling the weights to add up to 1.0). That way, you can pass 4 weights as a &lt;code&gt;vec4&lt;/code&gt; and 4 indices as a &lt;code&gt;uvec4&lt;/code&gt;. Also, you should pass the weights as normalized shorts (or bytes if you can accept the quality loss) and indices as bytes if at all possible, to further reduce the per-vertex data storage.&lt;/p&gt;&#xA;&lt;p&gt;Most real-time rendering systems are happy with these limitations.&lt;/p&gt;&#xA;&lt;p&gt;If that's not acceptable for your needs, then you're going to have to use multiple attributes to send the data. Each attribute can only have 4 components. And while attributes can be arrayed, arraying them like your C struct would waste a bunch of attribute locations, since each array element is considered a &lt;em&gt;separate&lt;/em&gt; location.&lt;/p&gt;&#xA;&lt;p&gt;So you need to send values in multiples of 4. Instead of sending 10 weights/indices, send 12, grouped into 4-element groupings. So the GLSL would look like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout(location = X) uvec4 indices[3];    //Stores 12 indices, consumes 3 locations.&#xA;layout(location = X + 3) vec4 weights[3]; //Stores 12 weights, consumes 3 locations.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The C data structure ought to also store 12 elements for each array.&lt;/p&gt;&#xA;&lt;p&gt;To specify them in the vertex format, you would do this (where &lt;code&gt;X&lt;/code&gt; is the location given above):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glVertexAttribIPointer(3, 4, GL_INT, sizeof(Vertex), (void*)(offsetof(Vertex, groups) + 0));&#xA;glVertexAttribIPointer(4, 4, GL_INT, sizeof(Vertex), (void*)(offsetof(Vertex, groups) + 16));&#xA;glVertexAttribIPointer(5, 4, GL_INT, sizeof(Vertex), (void*)(offsetof(Vertex, groups) + 32));&#xA;glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, weights) + 0));&#xA;glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, weights) + 16));&#xA;glVertexAttribPointer(8, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(offsetof(Vertex, weights) + 32));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="10783" LastEditDate="2021-05-01T18:31:11.870" LastActivityDate="2021-05-01T18:31:11.870" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10312" PostTypeId="1" CreationDate="2020-10-15T04:39:18.040" Score="0" ViewCount="41" Body="&lt;p&gt;&lt;strong&gt;Can someone please explain the math behind converting a direction-vector or lookAt-vector into a quaternion rotation?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;What I am trying to do?&lt;/strong&gt;&#xA;I am trying to create a custom aim-constraint for a DCC (Maya. Also, Maya already provides one but I have reason to write a custom one). I have the world-space positions of eye and destination using which I can calculate direction vector but I need to calculate quaternion/euler rotation to rotate the object so that I can look at the destination.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;What I found so far?&lt;/strong&gt;&#xA;There are couple of thread I found and read so far but some provide engine based approach, some do not provide explanation of math behind it and a few didn't work when converted into code.&#xA;I am listing few of them here (for reference)&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://gamedev.stackexchange.com/questions/149006/direction-vector-to-quaternion&quot;&gt;https://gamedev.stackexchange.com/questions/149006/direction-vector-to-quaternion&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/15873996/converting-a-direction-vector-to-a-quaternion-rotation&quot;&gt;https://stackoverflow.com/questions/15873996/converting-a-direction-vector-to-a-quaternion-rotation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://answers.unity.com/questions/631836/how-i-can-converting-a-direction-vector-to-quatern.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://answers.unity.com/questions/631836/how-i-can-converting-a-direction-vector-to-quatern.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://math.stackexchange.com/questions/1765799/convert-direction-vector-to-euler-angles&quot;&gt;https://math.stackexchange.com/questions/1765799/convert-direction-vector-to-euler-angles&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;strong&gt;What I am Not looking for?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;way of calculating quaternion rotation from a (transformation) matrix.&lt;/li&gt;&#xA;&lt;li&gt;engine based approach eg: &lt;code&gt;Quaternion.LookRotation(relativePos, Vector3.up)&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="10250" LastEditorUserId="10250" LastEditDate="2020-10-15T05:27:52.510" LastActivityDate="2020-10-15T05:27:52.510" Title="Explanation of converting a look-at / direction vector to quaternion rotation?" Tags="&lt;mathematics&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10313" PostTypeId="2" ParentId="10302" CreationDate="2020-10-15T08:31:11.677" Score="0" Body="&lt;p&gt;&lt;strong&gt;To follow up my question and provide partial answer:&lt;/strong&gt;&#xA;First of all, I'd like to thank &lt;a href=&quot;https://computergraphics.stackexchange.com/users/10096/lightxbulb&quot;&gt;lightxbulb&lt;/a&gt; for providing comments which helped me to find solution.&lt;/p&gt;&#xA;&lt;p&gt;So here is a basic image, 4 light bounces with 1024 spp:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5qtrm.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5qtrm.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Problem here is that everything is rather light. Why? Because I've based this part of my HLSL code on &lt;strong&gt;MJP's path tracer&lt;/strong&gt; ( &lt;a href=&quot;https://github.com/TheRealMJP/DXRPathTracer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/TheRealMJP/DXRPathTracer&lt;/a&gt; ) which &lt;strong&gt;assumes that if path allows both diffuse and specular then&lt;/strong&gt; throughput *= 2.0. However, specular term is allowed only for first bounce with 50% chance probability. I decided that this multiplying was based on testing in his engine and it doesn't have physical basis so I got rid of it and got better results. Specular/metal parts are basically the same, but you can see darkenings in the background which grounds objects in their place.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4EVAD.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4EVAD.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However I noticed that throughput is not mutiplied. MJP's algorithm is that throughput = 0, then throughput += diffuse/specular BRDF. He doesn't multiply BRDF results in the fashion presented in PBRT book ( &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_I_Surface_Reflection/Path_Tracing.html&lt;/a&gt; ). So I've added throughput to the payload. &lt;strong&gt;It starts with value (1.0, 1.0, 1.0) and is multiplied by BRDF at each point in the path resulting in below image:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kxWAH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kxWAH.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Based on my knowledge, last image should be closest to ground truth in physics terms.&lt;/strong&gt; Also, I think that it's closest to my reference that I've created in MJP's engine and I find it most pleasing. I am aware of the flaws. One is that for many samples (3000-5000 spp), diffuse textures starts having weird contrast and I don't know the reason yet.&lt;/p&gt;&#xA;&lt;p&gt;Also russian roulette turned out to be workin poorly in my progressive path tracing. &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/Russian_Roulette_and_Splitting.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Monte_Carlo_Integration/Russian_Roulette_and_Splitting.html&lt;/a&gt; - maybe after trying to optimize it to reduce variance it would be worth but I'm afraid that it'll still introduce too much noise with very little speedup. It might be worth giving it a try after adding denoiser I think, but for now, I don't think it's a good idea.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-10-15T08:31:11.677" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10314" PostTypeId="2" ParentId="10292" CreationDate="2020-10-15T12:08:28.770" Score="0" Body="&lt;p&gt;I've made a few changes in my code, so let's start with basic image that I had problem we that we'll state as a problem at the beginning:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/M8inp.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M8inp.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;After changing part of the code from:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float weight = abs(dot(wo, wm) / (dot(normalTS, wo) * dot(normalTS, wm)));&#xA;if (dot(normalTS, wi) &amp;gt; 0.0f &amp;amp;&amp;amp; dot(wi, wm) &amp;gt; 0.0f)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;To this (i.e. moving part of calculations to world-space):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float weight = abs(dot(wo, wm) / (dot(triangleNormal, incomingRayDirWS) * dot(normalTS, wm)));&#xA;if (dot(triangleNormal, rayDirWS) &amp;gt; 0.0f &amp;amp;&amp;amp; dot(wi, wm) &amp;gt; 0.0f)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I am getting better results. Here are series of images with different settings:&lt;/p&gt;&#xA;&lt;p&gt;1024 spp, 4 bounces&#xA;&lt;a href=&quot;https://i.stack.imgur.com/8wAKt.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8wAKt.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;5000 spp, 4 bounces&#xA;&lt;a href=&quot;https://i.stack.imgur.com/AHymQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/AHymQ.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;5000 spp, 1 bounce&#xA;&lt;a href=&quot;https://i.stack.imgur.com/UQ8fG.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UQ8fG.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Notice that 4 bounces version is having more fireflies and noise. Long specular paths might be a reason of introducing noise. Also, 5000 spp are getting darker than 1000 spp. Reason is that path is probably introducing no changes, therefore average color is getting darker. You can see it in the last line of main post. I'm going to put it below for reference:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;if (dot(triangleNormal, rayDirWS) &amp;gt; 0.0f &amp;amp;&amp;amp; dot(wi, wm) &amp;gt; 0.0f)&#xA;    throughput *= F * G * weight;&#xA;else&#xA;    throughput *= 0;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Last thing. Here is image generated with better method ( &lt;a href=&quot;https://schuttejoe.github.io/post/ggximportancesamplingpart2/&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://schuttejoe.github.io/post/ggximportancesamplingpart2/&lt;/a&gt; ). 1024 spp, 4 bounces:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P2dDQ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P2dDQ.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Overall, I got rid of weird noise and artifacts. Algorithm got closer to better method and I think it can be treated as fixed.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-10-15T12:08:28.770" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10315" PostTypeId="1" AcceptedAnswerId="10318" CreationDate="2020-10-15T22:00:02.773" Score="3" ViewCount="619" Body="&lt;p&gt;There is something about these concepts I'm not understanding.  I thought the point of gamma correcting images is to make sure that the values in linear space map correctly when displayed on screen:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tXBqa.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tXBqa.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It seems from this picture that the camera stops are all getting the same representation (code words) when mapped to the output (purple line).  If this is the case, we shouldn't need tone mapping, but obviously we do.  There is something not right in my thinking and am hoping someone in the internets help me fill in the gap.  Thanks!&lt;/p&gt;&#xA;" OwnerUserId="7571" LastActivityDate="2020-10-16T16:28:44.570" Title="Tone Mapping vs Gamma Correction" Tags="&lt;mapping&gt;&lt;gamma&gt;&lt;tone&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10316" PostTypeId="1" AcceptedAnswerId="10470" CreationDate="2020-10-15T22:05:43.480" Score="1" ViewCount="51" Body="&lt;p&gt;I have an image and I want to draw an arbitrary number of objects on that image. The center coordinates of those objects are calculated inside a fragment shader after series of image processing operations. However, because fragment shader gets executed per-fragment, I cannot draw objects centered on those points in the same shader in a reasonably fast way. Somehow, I need to pass those center coordinates that I calculated in my fragment shader to another fragment shader in a second render pass, preferably as uniforms. Then I can use those coordinates in the second fragment shader to draw my objects in an efficient way.&lt;/p&gt;&#xA;&lt;p&gt;I thought maybe I can render those points as white spots on a black texture, and after the first pass, I can search the raw data of the texture on the CPU side, then add those white points' coordinates into an array, and send them as uniforms. However, I guess it would be very inefficient as it is a very sparse data (a lot of black pixels and very few white pixels), and I would be doing thousands of iterations (even for a simple 720p image) on that raw data. So, I'm not sure if this should be the way to go.&lt;/p&gt;&#xA;&lt;p&gt;How can I do this in an efficient way, in OpenGL ES 2.0?&lt;/p&gt;&#xA;&lt;p&gt;P.S. I'm new to this area, please enlighten me if I made no sense.&lt;/p&gt;&#xA;" OwnerUserId="13742" LastEditorUserId="2654" LastEditDate="2020-10-16T13:19:46.723" LastActivityDate="2020-12-08T01:43:56.263" Title="How to pass only the needed portion of the data calculated in a fragment shader to another fragment shader?" Tags="&lt;rendering&gt;&lt;image-processing&gt;&lt;fragment-shader&gt;&lt;opengl-es&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10317" PostTypeId="2" ParentId="10304" CreationDate="2020-10-15T22:37:27.460" Score="0" Body="&lt;p&gt;Thank you for the responses! This solution using quadratic bezier interpolation wound up working for me.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;def ArcPoints(node):&#xA;    points = node.GetAllPoints()&#xA;    if len(points) &amp;lt; 3:&#xA;        return&#xA;&#xA;    # The first three points of the point object.&#xA;    a, b, c = points[:3]&#xA;&#xA;    samples = 6&#xA;    arcPoints = list()&#xA;    for i in range(samples):&#xA;        t = float(i)/(samples - 1)&#xA;        # The quadratic bezier interpolation at t.&#xA;        p = a * (1-t) ** 2 + b * 2 * (1-t) * t + c * t ** 2&#xA;        arcPoints.append(p)&#xA;&#xA;    return arcPoints&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14079" LastActivityDate="2020-10-15T22:37:27.460" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10318" PostTypeId="2" ParentId="10315" CreationDate="2020-10-16T13:05:18.193" Score="5" Body="&lt;p&gt;I think it would be a good idea to get back to the basics. It's a large post, so there's a recap at the end.&lt;/p&gt;&#xA;&lt;p&gt;Colour can be represented in a couple of ways. We can have Red, Green and Blue (RGB). We could have CMYK (used in printing). There's also YCbCr/YUV (one for luminance and two for colour) and similar flavours of that. We have HSV/HSL/HSB (hue, saturation, value/luminance/brightness). And even more. These are called &lt;strong&gt;colour models&lt;/strong&gt; (or color models, depending on where you live). RGB is the most popular model in terms of computer graphics. It's how colour film stock, digital sensors, monitors and roughly our eyes work. So, from now I'll be using the RGB colour model. The things in the rest of this post will have equivalents for the other models, but for simplicity it's just RGB for now.&lt;/p&gt;&#xA;&lt;p&gt;We have three values, R G and B, but that raises the question. If we have 100% red, 0% green and 0% blue, what kind of red is it? The answer is, we don't know. So, we have to define what kind of red red is, what kind of green green is, what kind of blue blue is and what kind of white white is. White is also important to define. This definition is called the &lt;strong&gt;colour gamut&lt;/strong&gt;. The colour gamut defines the chromaticities for red, green, blue and white. Chromaticity is colour but without the luminance (basically just the hue and saturation). By defining the colour gamut, we will know exactly what colour we have for any given RGB value.&lt;/p&gt;&#xA;&lt;p&gt;But there's another thing. If we want to send an image to our monitor or save it to a file on our drive, we don't want to have to send over or save a lot of data. We basically want to use the least amount of bits we can. We found out that having 8 bits for the red, green and blue values is enough. However! Our eyes are more sensitive to changes in brightness in dark areas and less sensitive in bright areas of an image. So, while 8 bits is enough for the bright areas, in the darker areas we can really see that we only have 256 possible values for red, green and blue. We fix this by moving around the values in order to use more of those 256 values for the darker areas and less on the brighter areas. Right now I am using 8 bits as an example, but this is the same for any amount of bits (10 and 12 bits is also popular but has the same problem). We do this using a &lt;strong&gt;transfer function&lt;/strong&gt;. In short, a transfer function redistributes the values in order to more efficiently use a limited amount of bits.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Gamma correction&lt;/strong&gt; (or just gamma) is a form of a transfer function. As you can see in your graph (the blue line) it nudges the values upwards which means that the range [0,0.5] becomes [0,0.73]. This means that we have almost 50% more bits for the darker areas of our image! That's what we want. Gamma isn't the only kind of transfer function. Another popular one is log, which is an umbrella term for transfer functions (or colour spaces using transfer functions) that make use of logarithms. With logarithms, each stop of light gets roughly the same amount of bits, which is really useful for images that have a very high dynamic range (like what comes out of a cinema camera). Perceptual quantizer (SMPTE ST 2084) is another transfer function that is used a lot in HDR video (like HDR10 and Dolby Vision) and it's made to take advantage of how our eyes perceive brightness (which falls somewhere between a logarithmic curve and cube-root curve). Values that haven't been transformed by a transfer function are called linear.&lt;/p&gt;&#xA;&lt;p&gt;When you combine a colour model, colour gamut and transfer function, you get a &lt;strong&gt;colour space&lt;/strong&gt;. A colour space specifies how the colours are represented (what colour is what). There is one very important thing however, you &lt;strong&gt;do not need&lt;/strong&gt; a transfer function for a colour space. sRGB is a very popular colour space which is used by practically every computer monitor. It uses the RGB colour model with the sRGB colour gamut (Rec.709 uses the same gamut) and the transfer function is generally a gamma of 2.2 (although it actually isn't, but most use the gamma for simplicity, go look at its Wikipedia page). But you also have linear-sRGB which is also a colour space that just like sRGB, uses the RGB model and sRGB gamut, but doesn't have a transfer function. The values are in linear (often referred to as &amp;quot;scene linear&amp;quot;).&lt;/p&gt;&#xA;&lt;p&gt;To try and make things a bit more clear, here's an example showing how a transfer function works when displaying an image that is either CGI or a video game being rendered. The first thing that is important is that both the computer/program and the display need to agree on the colour space to use. In this example, we use sRGB. Basically, the program sends the sRGB image to the display and the display takes that sRGB image and converts it to the actual electronic signals to send to the pixels.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/MTQ4u.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/MTQ4u.png&quot; alt=&quot;Image being sent to display&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And now we finally get to tone mapping. A &lt;strong&gt;tone mapper&lt;/strong&gt; is a function that takes in a large, generally infinite, range of values and compresses it to a smaller, often limited, range of values. Tone mapping is generally used to apply a &amp;quot;look&amp;quot;. A very popular tone mapping is the filmic s-curve, which is called a &amp;quot;film characteristic curve&amp;quot; or &amp;quot;Hurter–Driffield curve&amp;quot;. It adds some contrast in the shadows and instead of the highlights clipping once they reach 100% brightness, it adds a nice roll-off that gradually brings it to 100%. This tone mapper is used in a lot of places. It's how film stock behaves, it's what digital cinema cameras often do, in video games they use this curve. Basically, because it looks good and with it we can see values above 100% (because the tone mapper maps it to something below 100%). If you want to tone map your image, it should be done before the transfer function/colour space conversion (for example converting from linear-sRGB to sRGB), because tone mapping isn't part of a colour space and is basically a look (just like applying a filter over an image).&lt;/p&gt;&#xA;&lt;p&gt;However, you &lt;strong&gt;don't need&lt;/strong&gt; a tone mapper. If you take a cheap camcorder, DSLR, your phone (depending on the settings) or a broadcast camera they use to film the news and such (especially before the 2010s), then all of them don't do any kind of tone mapping. They just apply the sRGB or Rec.709 colour space (and thus also the transfer function) and that's it. What you often do see is that parts of the image go to 100% white very quickly and then clips Here's a picture that I took with my phone. It's just normal average sRGB and no tone mapping. &lt;a href=&quot;https://i.stack.imgur.com/gv7ed.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gv7ed.jpg&quot; alt=&quot;Image of clipped highlights&quot; /&gt;&lt;/a&gt;&#xA;You can see that the cloud is completely white and the trees are quite dark. Using a tone mapper, I could bring those values closer together and not have the clouds be 100% white without any detail, while still being able to see detail in the trees.&lt;/p&gt;&#xA;&lt;h2&gt;To recap&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Gamma correction is a type of transfer function, which is part of a colour space.&lt;/li&gt;&#xA;&lt;li&gt;A colour space tells us how to represent and store colours.&lt;/li&gt;&#xA;&lt;li&gt;When we want to send images to our display, we need to apply the transfer function.&lt;/li&gt;&#xA;&lt;li&gt;The display will undo that transfer function (and will do it no matter what, so you have to apply the transfer function on your end to get the correct values when displayed).&lt;/li&gt;&#xA;&lt;li&gt;A tone mapper is both to apply a look and to compress the range of RGB values to a smaller range so that we can see a high dynamic range image on a standard dynamic range monitor.&lt;/li&gt;&#xA;&lt;li&gt;While you need to apply a transfer function when sending the image to the display, you don't need to apply a tone mapper. Only if you want to.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="4908" LastEditorUserId="4908" LastEditDate="2020-10-16T16:28:44.570" LastActivityDate="2020-10-16T16:28:44.570" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10319" PostTypeId="1" AcceptedAnswerId="10325" CreationDate="2020-10-17T03:35:26.687" Score="2" ViewCount="99" Body="&lt;p&gt;I am trying to create a spherical interpolation with 3 points. I'm currently using Quadratic Bezier Interpolation but &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10317/14079&quot;&gt;have been told&lt;/a&gt; I should use Rational Quadratic Bezier Curve in order to get a perfectly circular curve. I have tried implementing this based on the formula I found &lt;a href=&quot;http://demofox.org/bezquadrational.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; (3 control points A,B and C, 3 weights W1, W2, W3 and a time t):&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;CurvePoint = (A*W1*(1-t)^2 + B*W2*2t(1-t) + C*W3*t^2) / (W1*(1-t)^2 + W2*2t(1-t) + W3*t^2).&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;How do I determine the correct weight values for this to work as a circle? Is that even possible without moving the middle point? Thank you.&lt;/p&gt;&#xA;&lt;p&gt;Here is the code I am using (with all weights set to 1.0) and the curve it produces:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;&#xA;def ArcPoints(node):&#xA;    points = node.GetAllPoints()&#xA;&#xA;    # The three points of the point object&#xA;    a, b, c = points[:3]&#xA;&#xA;    samples = 6&#xA;    arcPoints = list()&#xA;    for i in range(samples):&#xA;        t = float(i)/(samples - 1)&#xA;        w1 = 1&#xA;        w2 = 1&#xA;        w3 = 1&#xA;        p2 = (a * w1 * (1-t) ** 2 + b * w2 * 2*t * (1-t) + c * w3 * t ** 2 ) / (w1 * (1-t) ** 2 + w2 * 2*t * (1-t) + w3 * t**2)&#xA;        arcPoints.append(p)&#xA;&#xA;    return arcPoints&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yQEbu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yQEbu.jpg&quot; alt=&quot;Rational Quadratic Bezier Curve&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="14079" LastActivityDate="2020-10-23T07:40:48.993" Title="Determining Rational Quadratic Bezier Curve Weights for Circle" Tags="&lt;mathematics&gt;&lt;interpolation&gt;&lt;curve&gt;&lt;bezier-curve&gt;&lt;nurbs&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10320" PostTypeId="1" AcceptedAnswerId="10324" CreationDate="2020-10-17T18:00:21.963" Score="1" ViewCount="89" Body="&lt;p&gt;&lt;strong&gt;Unbound descriptor tables&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;If a &lt;code&gt;D3D12_VERSIONED_ROOT_SIGNATURE_DESC&lt;/code&gt; defines &lt;em&gt;N&lt;/em&gt; &lt;code&gt;D3D12_ROOT_PARAMETER&lt;/code&gt;s (with &lt;code&gt;ParameterType&lt;/code&gt; set to &lt;code&gt;D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE&lt;/code&gt;) that are each visible to a single (non-compute) shader stage, does each of these require a corresponding &lt;code&gt;ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable&lt;/code&gt; invocation (with an allocated shader visible descriptor range) after binding the &lt;code&gt;ID3D12RootSignature&lt;/code&gt; and &lt;code&gt;ID3D12PipelineState&lt;/code&gt;, even if the latter does only use a subset of the (non-compute) shader stages (e.g., no geometry shader, etc.)? Stated differently, does &lt;code&gt;ID3D12GraphicsCommandList::SetGraphicsRootDescriptorTable&lt;/code&gt; need to be invoked for root parameters associated with shader stages that are &lt;strong&gt;not&lt;/strong&gt; defined for the &lt;code&gt;ID3D12PipelineState&lt;/code&gt; &lt;strong&gt;but&lt;/strong&gt; are part of the &lt;code&gt;ID3D12RootSignature&lt;/code&gt;?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Unbound descriptors&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;If a shader uses say 2 SRVs, but up to 64 SRVs could be potentially bound for the &lt;code&gt;ID3D12RootSignature&lt;/code&gt;, is it necessary that the 62 unused SRVs, which are part of the same shader visible descriptor range(s), are actually associated with an &lt;strong&gt;existing&lt;/strong&gt; SRV of a resource that is still &lt;strong&gt;alive&lt;/strong&gt; (which is not automatically guaranteed if the shader visible descriptor heaps are used in a ring buffer fashion, as initially the descriptors are unused and later on could be reused)? Or does one for example need to use an SRV of a dummy resource that is kept alive?&lt;/p&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2020-10-19T17:07:51.867" Title="Unbound descriptor tables and descriptors for fat root signatures" Tags="&lt;directx12&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10321" PostTypeId="1" CreationDate="2020-10-17T18:11:17.000" Score="2" ViewCount="34" Body="&lt;p&gt;The CBV (constant buffer view) &lt;code&gt;SizeInBytes&lt;/code&gt; is required to be 256-byte aligned.&lt;/p&gt;&#xA;&lt;p&gt;Should the associated &lt;code&gt;ID3D12Resource&lt;/code&gt; have a &lt;code&gt;Width&lt;/code&gt; (i.e. &lt;code&gt;D3D12_RESOURCE_DESC&lt;/code&gt;) equal to/greater than that same size or may it be smaller, as the additional padding of the CBV won't be accessed/used in the shaders anyway? For example, is it allowed to create a CBV with &lt;code&gt;SizeInBytes&lt;/code&gt; equal to 256 bytes for a &lt;code&gt;ID3D12Resource&lt;/code&gt; with &lt;code&gt;Width&lt;/code&gt; equal to 64 bytes?&lt;/p&gt;&#xA;&lt;p&gt;Are there constraints for the IBV (index buffer view) and VBV (vertex buffer view) &lt;code&gt;SizeInBytes&lt;/code&gt; as well?&lt;/p&gt;&#xA;" OwnerUserId="2287" LastEditorUserId="2287" LastEditDate="2020-10-19T20:17:53.307" LastActivityDate="2020-10-19T20:17:53.307" Title="CBV, IBV and VBV byte alignment" Tags="&lt;directx12&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10322" PostTypeId="2" ParentId="5520" CreationDate="2020-10-17T19:40:33.637" Score="1" Body="&lt;p&gt;For sampling a uniform volume you use the mean free path of a photon:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;float dt = -logf(1.0f - Xi) / uT;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;where:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Xi is a random variable in [0, 1]&lt;/li&gt;&#xA;&lt;li&gt;uT is the extinction coefficient (sum of out-scattering and absorption)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The pdf of a raytime (t) in this uniform volume is given by:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;float pdf = uT * expf(-t * uT);&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;In your case, you do not have a uniform volume, but instead one whose density is exponentially decreasing according to the distance from the surface of a sphere.&lt;/p&gt;&#xA;&lt;p&gt;Approaches for solving this typically involve raymarching which samples a density at each step and treats the step as a uniform volume. This is approximate and introduces some bias, but there are ways of reducing the bias.&lt;/p&gt;&#xA;&lt;p&gt;I recommend reading Monte Carlo Methods for Physically Based Volume Rendering:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://jannovak.info/publications/VolumeCourse/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://jannovak.info/publications/VolumeCourse/index.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Another good resource is pbrtv3, particularly chapters 11 and 15:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Volume_Scattering.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Volume_Scattering.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Light_Transport_II_Volume_Rendering.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/3ed-2018/Light_Transport_II_Volume_Rendering.html&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="15099" LastActivityDate="2020-10-17T19:40:33.637" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10324" PostTypeId="2" ParentId="10320" CreationDate="2020-10-19T17:07:51.867" Score="1" Body="&lt;p&gt;Everything is allowed to be left unbound / invalid / uninitialized as long as the shader doesn't try to look at it. However, if the shader &lt;em&gt;does&lt;/em&gt; try to look at it, it could trigger a GPU crash / TDR.&lt;/p&gt;&#xA;&lt;p&gt;In practice, it may be a good idea to explicitly clear out descriptors that you know aren't going to be valid: either setting them to a null descriptor, or pointing to a dummy resource. Loading/sampling from a null SRV/UAV descriptor in a descriptor table is defined to just return 0 and not crash. Likewise, stores to a null UAV descriptor are dropped on the floor without crashing.&lt;/p&gt;&#xA;&lt;p&gt;However, this guarantee doesn't apply to descriptors directly in the root signature; trying to load/sample from a null root descriptor can crash the GPU. Likewise trying to read from a null descriptor table can crash. See the &lt;a href=&quot;https://microsoft.github.io/DirectX-Specs/d3d/ResourceBinding.html#null-descriptors&quot; rel=&quot;nofollow noreferrer&quot;&gt;D3D12 functional spec&lt;/a&gt; for more.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-10-19T17:07:51.867" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10325" PostTypeId="2" ParentId="10319" CreationDate="2020-10-20T07:27:08.530" Score="5" Body="&lt;p&gt;Check out the section on &lt;a href=&quot;https://pages.mtu.edu/%7Eshene/COURSES/cs3621/NOTES/spline/NURBS/RB-circles.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Circular Arcs and Circles&lt;/a&gt;, from &lt;a href=&quot;https://pages.mtu.edu/%7Eshene/COURSES/cs3621/NOTES/notes.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ching-Kuang Shene's excellent computational geometry course notes&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;[G]iven three control points P0, P1 and P2 such that P0P1 = P1P2 holds, if we choose w, the weight for P1, to be sin(a), where a is the half angle at control point P1, the resulting rational Bézier curve is a circle.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The second diagram on that page is particularly useful. If P0 is at (0,0), P1 is at (1,0), and P2 is at (1,1), then the angle at P1 is 90 degrees; half that is 45, so assigning weights w0 = w2 = 1 and w1 = sin(45) = 1/sqrt(2) will produce a circle.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: To actually implement this from your code: The three points are &lt;code&gt;[a,b,c]&lt;/code&gt;. If you know that the distance from &lt;code&gt;a&lt;/code&gt; to &lt;code&gt;b&lt;/code&gt; is the same as the distance from &lt;code&gt;b&lt;/code&gt; to &lt;code&gt;c&lt;/code&gt;, then you can set &lt;code&gt;w1&lt;/code&gt; and &lt;code&gt;w3&lt;/code&gt; to 1, and &lt;code&gt;w2&lt;/code&gt; to the sine of half the angle between them. Look up the &lt;a href=&quot;https://mathworld.wolfram.com/Half-AngleFormulas.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;half-angle formula&lt;/a&gt; for sine to see that &lt;code&gt;sin(x/2) = sqrt((1 - cos x) / 2)&lt;/code&gt;. The cosine of the angle between two vectors is the normalized dot product, i.e. &lt;code&gt;cos x = dot(a-b,c-b) / (a-b)^2&lt;/code&gt;. Thus, you can do something like&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;ba = a - b&#xA;bc = c - b&#xA;cosx = ba.Dot(bc) / ba.Dot(ba);&#xA;w2 = math.sqrt(0.5 * (1 - cosx));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Again, this will only work if the distances &lt;code&gt;ba&lt;/code&gt; and &lt;code&gt;bc&lt;/code&gt; are the same. (You can still make a circle otherwise, but the weights will be more compilcated.)&lt;/p&gt;&#xA;" OwnerUserId="7647" LastEditorUserId="7647" LastEditDate="2020-10-23T07:40:48.993" LastActivityDate="2020-10-23T07:40:48.993" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10326" PostTypeId="1" AcceptedAnswerId="10329" CreationDate="2020-10-20T15:00:35.723" Score="0" ViewCount="76" Body="&lt;p&gt;I need to draw some shapes filled with linear gradients starting from every point and blending smoothly between points, like an OpenGL standard shading (I guess it is called &lt;code&gt;GL_LINEAR&lt;/code&gt; or &lt;code&gt;VERTEX_COLOR&lt;/code&gt;), i.e. GIMP / Illustrator / Krita / Paint3D, etc. Something fast and simple.&lt;br /&gt;&#xA;required result:&lt;br /&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/O6X3T.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/O6X3T.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="14025" LastActivityDate="2020-10-21T22:12:09.440" Title="Is there a tool capable of drawing a triangular linear gradient fill?" Tags="&lt;opengl&gt;&lt;texture&gt;&lt;geometry&gt;&lt;pixel-shader&gt;&lt;gradient&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10327" PostTypeId="2" ParentId="10326" CreationDate="2020-10-20T17:56:50.360" Score="1" Body="&lt;p&gt;Most 2D graphics programs are able to do linear gradients with arbitrary orientations. If you don't mind a little work, it is possible to set this up to imitate the 2D linear interpolation across a triangle.&lt;/p&gt;&#xA;&lt;p&gt;Set up two layers:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Pick two of the colors, say red and green, and set up a linear gradient between those two colors along the red-green edge.&lt;/li&gt;&#xA;&lt;li&gt;In a second layer, set up a linear gradient between blue and transparent-blue (i.e. the same color with alpha = 0). Orient it perpendicular to the red-green edge.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-10-20T17:56:50.360" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10328" PostTypeId="1" CreationDate="2020-10-21T01:31:39.093" Score="0" ViewCount="53" Body="&lt;p&gt;I am converting my OpenCV frame to an OpenGL texture. I have the frame data loaded, but when I try to render it as a texture I get a black screen. I've looked through the OpenGL code countless times and can't figure out where I am going wrong. Any direction or help would be great.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    glGenTextures(1, &amp;amp;m_backgroundTextureId);&#xA;    glActiveTexture(GL_TEXTURE0);&#xA;    glBindTexture(GL_TEXTURE_2D, m_backgroundTextureId);&#xA;        &#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;    int w = m_backgroundImage.cols;&#xA;    int h = m_backgroundImage.rows;&#xA;    &#xA;    glPixelStorei(GL_PACK_ALIGNMENT, 1);&#xA;    &#xA;    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, m_backgroundImage.data);&#xA;    &#xA;    const GLfloat proj[] = { 0, -2.f / w, 0, 0, -2.f / h, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1 };&#xA;    &#xA;    glMatrixMode(GL_PROJECTION);&#xA;    glLoadMatrixf(proj);&#xA;&#xA;    glMatrixMode(GL_MODELVIEW);&#xA;    glLoadIdentity();&#xA;    &#xA;    const GLfloat bgTextureVertices[] = {&#xA;        0, 0, 0, 0,&#xA;        static_cast&amp;lt;GLfloat&amp;gt;(w), 0, 1, 0,&#xA;        0, static_cast&amp;lt;GLfloat&amp;gt;(h), 0, 1,&#xA;        static_cast&amp;lt;GLfloat&amp;gt;(w), static_cast&amp;lt;GLfloat&amp;gt;(h), 1, 1&#xA;    };&#xA;    &#xA;    VertexArray vav;&#xA;    VertexBuffer vbVerticies(bgTextureVertices, 4 * 4 * sizeof(float));&#xA;    &#xA;    VertexBufferLayout layout;&#xA;    layout.push&amp;lt;float&amp;gt;(4);&#xA;    vav.addBuffer(vbVerticies, layout);&#xA;&#xA;    Shader shader(&amp;quot;res/shaders/Basic.Shader&amp;quot;);&#xA;    shader.bind();&#xA;    shader.setUniform1i(&amp;quot;u_Texture&amp;quot;, 0);&#xA;    &#xA;    vav.unbind();&#xA;    shader.unbind();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Vertex Shader&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#shader vertex&#xA;#version 330 core&#xA;&#xA;layout (location = 0) in vec4 position;&#xA;layout (location = 1) in vec2 texCoord;&#xA;&#xA;out vec2 v_texCoord;&#xA;&#xA;void main() {&#xA;    gl_Position = position;&#xA;    v_texCoord = texCoord;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;pre&gt;&lt;code&gt;#shader fragment&#xA;#version 330 core&#xA;&#xA;layout (location = 0) out vec4 color;&#xA;&#xA;in vec2 v_texCoord;&#xA;uniform sampler2D u_Texture;&#xA;&#xA;void main() {&#xA;    vec4 texColor = texture(u_Texture, v_texCoord);&#xA;    color = texColor;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14051" LastActivityDate="2020-10-21T01:31:39.093" Title="Not sure why texture is rendering a black screen" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10329" PostTypeId="2" ParentId="10326" CreationDate="2020-10-21T22:12:09.440" Score="0" Body="&lt;p&gt;a quick working wrapper for OpenGL from R:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;require(rgl)&#xA;tr.points &amp;lt;- matrix(c(1,0,0, cos(60/180*pi),sin(60/180*pi),0, 0,0,0),&#xA;                    ncol=3, byrow=TRUE)&#xA;triangles3d(tr.points, col=c('red', 'green', 'blue'),&#xA;            lit=FALSE, smooth=TRUE, textype='rgb',&#xA;            lwd=1.0,&#xA;            depth_mask=TRUE, depth_test='always')&#xA;rgl.viewpoint(theta=0, phi=0,&#xA;              fov=0, zoom=1,&#xA;              interactive=FALSE)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14025" LastActivityDate="2020-10-21T22:12:09.440" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10330" PostTypeId="1" AcceptedAnswerId="10331" CreationDate="2020-10-22T04:58:04.003" Score="1" ViewCount="39" Body="&lt;p&gt;I need a point clarified.  According to &lt;a href=&quot;https://en.wikipedia.org/wiki/High-dynamic-range_video&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;, SMPT ST 2084 EOTF is this:  &lt;a href=&quot;https://i.stack.imgur.com/M8d5a.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/M8d5a.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I've seen this equation implemented in game engines where for &lt;strong&gt;L&lt;/strong&gt; they feed the channels &lt;strong&gt;RGB&lt;/strong&gt;, each of which is 0 to 10,000 and normalize them.  Am confused because luminance from what I understand is supposed to be one quantity instead of 3.  I understood luminance to be kind'a like speed in physics, and the RGB is the &amp;quot;direction&amp;quot; vector. Is it really correct to plug the RGB linear channels in into &lt;strong&gt;L&lt;/strong&gt; (the &amp;quot;linear optical luminance&amp;quot;) in this equation, or am I misunderstanding something? The way I think of it, we need to compute the luminance from the RGB triplet, and then plug that value into L, then from V we compute colors.&lt;/p&gt;&#xA;&lt;p&gt;Where is my thinking wrong?&lt;/p&gt;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="7571" LastActivityDate="2020-10-22T11:31:15.807" Title="Luminace, RGB, and SMPT ST 2084 EOTF" Tags="&lt;colorspace&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10331" PostTypeId="2" ParentId="10330" CreationDate="2020-10-22T11:31:15.807" Score="1" Body="&lt;p&gt;I fully understand the confusion (I was also a bit confused when I saw it). So, I decided to look at the ACES implementation of the ST 2084 EOTF. &lt;a href=&quot;https://github.com/ampas/aces-dev/blob/v1.0.3/transforms/ctl/lib/ACESlib.Utilities_Color.ctl#L402&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/ampas/aces-dev/blob/v1.0.3/transforms/ctl/lib/ACESlib.Utilities_Color.ctl#L402&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;From there it is very clear: You perform the transfer function on the R, G and B values separately and not by first calculating the luminance. The confusion most likely comes from the fact that we are talking about two different kinds of luminance.&lt;/p&gt;&#xA;&lt;p&gt;We have &lt;a href=&quot;https://en.wikipedia.org/wiki/Relative_luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;relative luminance&lt;/em&gt;&lt;/a&gt;, which is the luminance we use when talking about colours and can be calculated with &lt;span class=&quot;math-container&quot;&gt;$Y=0.2126R+0.7152G+0.0722B$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;We also have &lt;a href=&quot;https://en.wikipedia.org/wiki/Luminance&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;luminance&lt;/em&gt;&lt;/a&gt; for which the SI unit is cd/m2 and basically means how bright something is.&lt;/p&gt;&#xA;&lt;p&gt;You, and I when I first read your post, were thinking about &lt;em&gt;relative luminance&lt;/em&gt;, but the Wikipedia article was talking about just &lt;em&gt;luminance&lt;/em&gt;. In this case, it talks about the luminance of red light, green light and blue light separately (since a camera captures it separately and a monitor produces it separately). I'm pretty sure the ST 2048 spec is more clear about this, but that's behind a paywall.&lt;/p&gt;&#xA;" OwnerUserId="4908" LastActivityDate="2020-10-22T11:31:15.807" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10332" PostTypeId="1" CreationDate="2020-10-22T16:44:37.143" Score="1" ViewCount="897" Body="&lt;p&gt;I'm reading through &lt;a href=&quot;https://learnopengl.com/book/book_pdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Learn OpenGL&lt;/a&gt; to refresh the basic concepts as I haven't touched in quite some time.&lt;/p&gt;&#xA;&lt;p&gt;Specifically I still think I cannot quite understand the meaning of VAO and VBO, the book mainly proceeds through examples it doesn't really give rigorous definitions.&lt;/p&gt;&#xA;&lt;p&gt;About the VBO:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;With the vertex data defined we’d like to send it as input to the&#xA;first process of the graphics pipeline: the vertex shader. This is&#xA;done by creating memory on the GPU where we store the vertex data,&#xA;configure how OpenGL should interpret the memory and specify how to&#xA;send the data to the graphics card. The vertex shader then processes&#xA;as much vertices as we tell it to from its memory.&#xA;We manage this memory via so called vertex buffer objects (VBO) that&#xA;can store a large number of vertices in the GPU’s memory. The&#xA;advantage of using those buffer objects is that we can send large&#xA;batches of data all at once to the graphics card, and keep it there if&#xA;there’s enough memory left, without having to send data one vertex at&#xA;a time. Sending data to the graphics card from the CPU is relatively&#xA;slow, so wherever we can we try to send as much data as possible at&#xA;once. Once the data is in the graphics card’s memory the vertex shader&#xA;has almost instant access to the vertices making it extremely fast&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;So my understanding of VBO they're essentially Buffer objects (bunch of bytes to be sent to the GPU) with the difference that VBO are specifically dedicated to Vertex Data. Is this correct?&lt;/p&gt;&#xA;&lt;p&gt;About the VAO:&lt;/p&gt;&#xA;&lt;p&gt;Here instead I don't really understand.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;A &lt;strong&gt;vertex array object&lt;/strong&gt; (also known as &lt;strong&gt;VAO&lt;/strong&gt;) can be bound just&#xA;like a vertex buffer object and any subsequent vertex attribute calls&#xA;from that point on will be stored inside the VAO.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;What does it mean &lt;em&gt;any subsequent vertex attribute calls from that point on will be stored inside the VAO&lt;/em&gt;, I don't understand the &amp;quot;call be stored&amp;quot; bit, does it mean somewhere in the opengl context created we store like some data related to the vertex attribute calls (like the pair input output of the call? the output of the call? something related to the call?).&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;This has the advantage that when configuring vertex attribute pointers you only&#xA;have to make those calls once and whenever we want to draw the object,&#xA;we can just bind the corresponding VAO. This makes switching between&#xA;different vertex data and attribute configurations as easy as binding&#xA;a different VAO. All the state we just set is stored inside the VAO.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I don't understand the advantage here. I understand the &amp;quot;call made once&amp;quot;, because they're stored in the VAO (whatever the &amp;quot;stored part means&amp;quot;). The switching part does maybe mean I can create multiple VAO each one capturing different Vertex Attributes calls and I can just bind each one of these when I need without calling again the vertex attribute?&lt;/p&gt;&#xA;&lt;p&gt;For reference I've also found &lt;a href=&quot;https://stackoverflow.com/questions/21652546/what-is-the-role-of-glbindvertexarrays-vs-glbindbuffer-and-what-is-their-relatio&quot;&gt;this question&lt;/a&gt; which I thought had an interesting answer.&lt;/p&gt;&#xA;" OwnerUserId="228" LastActivityDate="2021-03-14T23:09:50.293" Title="Understanding VAO and VBO" Tags="&lt;opengl&gt;" AnswerCount="3" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10333" PostTypeId="2" ParentId="10332" CreationDate="2020-10-22T18:05:02.800" Score="4" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;So my understanding of VBO they're essentially Buffer objects (bunch of bytes to be sent to the GPU) with the difference that VBO are specifically dedicated to Vertex Data. Is this correct?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;A &amp;quot;VBO&amp;quot; is not really a thing, and I really wish tutorials would stop pretending that they are.&lt;/p&gt;&#xA;&lt;p&gt;You are correct in that there exist &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;buffer objects&lt;/a&gt;. These are linear arrays of unformatted data that the GPU stores and can access for various processes. One of those &amp;quot;various processes&amp;quot; that the GPU can use them for is providing array data for vertex rendering operations.&lt;/p&gt;&#xA;&lt;p&gt;But the buffer &lt;em&gt;itself&lt;/em&gt; isn't special. It doesn't become a different thing just because you use it for vertex data, and there is no rule that says that a buffer you're currently using for vertex data cannot be used for other buffer usages too.&lt;/p&gt;&#xA;&lt;p&gt;Note that this is different from how textures work. When you create a texture object and bind it as a 2D texture, that texture object &lt;em&gt;forever&lt;/em&gt; becomes a 2D texture. You cannot later bind it as a 1D or a cubemap or whatever. Buffer objects aren't like that; where you bind them defines only how you're &lt;em&gt;currently&lt;/em&gt; using them.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;What does it mean &amp;quot;any subsequent vertex attribute calls from that point on will be stored inside the VAO&amp;quot;&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This is yet another annoying tutorial trope: that objects &amp;quot;store calls&amp;quot; or are macros or other such nonsense.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/OpenGL_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;Objects in OpenGL&lt;/a&gt; don't store calls; they store &lt;em&gt;state&lt;/em&gt;. They're like structs; they have data members. Binding an object to the OpenGL context allows OpenGL operations that access certain state to find that state within the bound object. So if you call a function that modifies certain state that is from a bound object, that function will modify the state within the object.&lt;/p&gt;&#xA;&lt;p&gt;When you bind a VAO, you are binding an object that stores the state used for vertex arrays. When you call a function that modifies the state for vertex arrays, that function will modify the state stored in the VAO currently bound. When you render, the rendering system will use the vertex array state found in the currently bound VAO.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-10-22T18:05:02.800" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10334" PostTypeId="1" CreationDate="2020-10-22T22:08:37.680" Score="0" ViewCount="31" Body="&lt;p&gt;In this video &lt;a href=&quot;https://youtu.be/0ckE-CZpXAo?t=445&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/0ckE-CZpXAo?t=445&lt;/a&gt;, it's suggested to render onto a sphere instead of screen quad to save computation time on lighting calculations. So you create a bounding sphere for each light and render onto it.&lt;/p&gt;&#xA;&lt;p&gt;But I can't make sense of it. How can we render the scene around the light by rendering it onto a sphere?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-10-23T00:31:46.323" Title="Rendering part of the scene inside bounding sphere" Tags="&lt;opengl&gt;&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10335" PostTypeId="2" ParentId="10334" CreationDate="2020-10-23T00:31:46.323" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;How can we render the scene around the light by rendering it onto a sphere?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Well, answer me this: how do you render a scene around a like by rendering a &amp;quot;screen quad&amp;quot;?&lt;/p&gt;&#xA;&lt;p&gt;We're ultimately talking about deferred rendering, and what is being done is rendering the lighting pass. During the lighting pass, you read data from the gbuffers that tell you that pixel's position, normal, and any other information used by the lighting equation. The texel location you read this data from those gbuffers is just the fragment's location.&lt;/p&gt;&#xA;&lt;p&gt;The point being made by the video is that the geometry you render to do a lighting pass &lt;em&gt;does not matter&lt;/em&gt;. You are &lt;em&gt;only&lt;/em&gt; using it to invoke the fragment shader over a region of the image. This is why rendering a full-screen quad works; you're executing the fragment shader over all of the pixels in the screen.&lt;/p&gt;&#xA;&lt;p&gt;While that works, it does mean you're executing more fragment shader invocations than are strictly necessary for any particular light. Points that correspond to distances outside of the light's useful effect still have to have an FS executed on them.&lt;/p&gt;&#xA;&lt;p&gt;A sphere is a useful way to pre-cull such fragments. The sphere's radius represents the useful range of effect for a light. Any fragments horizontally or vertically outside of this range don't get produced, since fragments are only produced by rasterizing the sphere. And because the sphere's vertices will be transformed by the same transformation matrix as the scene, and because you will turn on depth tests, you &lt;em&gt;also&lt;/em&gt; can cull out cases that are outside of the light's useful range in depth (or at least, if they're closer to the camera than the light's effect).&lt;/p&gt;&#xA;&lt;p&gt;But there are downsides of this approach. Spheres are complex objects, so there will typically be some overlap in terms of the number of helper fragment shader invocations being executed for a particular pixel. Of greater concern is using relatively high resolution spheres that appear very small on the screen.&lt;/p&gt;&#xA;&lt;p&gt;Also, you can only execute a single light per FS invocation, instead of being able to bundle lots of lights together. This is especially important for deferred rendering on tile-based renderers.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-10-23T00:31:46.323" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10336" PostTypeId="2" ParentId="10332" CreationDate="2020-10-23T12:53:13.380" Score="2" Body="&lt;p&gt;A VBO is a buffer of memory which the gpu can access. That's all it is.&lt;/p&gt;&#xA;&lt;p&gt;A VAO is an object that stores vertex bindings. This means that when you call glVertexAttribPointer and friends to describe your vertex format that format information gets stored into the currently bound VAO. And when you draw it will use the vertex bindings in the currently bound VAO.&lt;/p&gt;&#xA;&lt;p&gt;Pretending it replays the binding calls is misleading. It is a relic from why the VAO were created because prior to VAOs you did need to redo the vertex bindings every time you changed which mesh you were drawing. A VAO lets you do that in a single call.&lt;/p&gt;&#xA;" OwnerUserId="137" LastActivityDate="2020-10-23T12:53:13.380" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10337" PostTypeId="1" CreationDate="2020-10-23T18:04:40.813" Score="2" ViewCount="117" Body="&lt;p&gt;I am developing a software that needs to interact with a mesh processing program, using tetrahedral meshes, however I am finding difficulties in this.&lt;/p&gt;&#xA;&lt;p&gt;The program requires all tetrahedrons to have &lt;strong&gt;right handed orientation&lt;/strong&gt;, and this is not the hard part, as given a list of vertices &lt;span class=&quot;math-container&quot;&gt;$\{ v_0, v_1, v_2, v_3 \}$&lt;/span&gt;, I need to check that&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$h := ( \; (v_0 - v_1) \times (v_0 - v_2) \;) \cdot (v_0  - v_3) &amp;gt; 0$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;In case &lt;span class=&quot;math-container&quot;&gt;$h &amp;lt; 0$&lt;/span&gt;, any odd permutation will be correct, as &lt;span class=&quot;math-container&quot;&gt;$\{ v_0, v_1, v_3, v_2 \}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The problem is that, as they told me, the program requires that &lt;strong&gt;all faces are oriented with the right hand rule&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This requirement puzzles me, and I do not understand it completely.&lt;/p&gt;&#xA;&lt;p&gt;Can anyone point me in the right direction?&lt;/p&gt;&#xA;&lt;h3&gt;Code&lt;/h3&gt;&#xA;&lt;pre&gt;&lt;code&gt;class tetrahedron:&#xA;    def __init__(self, vertices):&#xA;        # compute handedness&#xA;        c = numpy.cross(vertices[0].coords-vertices[1].coords, vertices[0].coords-vertices[2].coords)&#xA;        h = numpy.inner( c, vertices[0].coords-vertices[3].coords )&#xA;&#xA;        # vertex indices with correct right-handed orientation&#xA;        if h &amp;gt; 0:&#xA;            self.vertices = vertices&#xA;        else:&#xA;            s = &amp;quot;old h = %f&amp;quot; % (h)&#xA;            # swap last two vertices&#xA;            self.vertices = [vertices[0], vertices[1], vertices[3], vertices[2]]&#xA;            vertices = self.vertices&#xA;            c = numpy.cross(vertices[0].coords-vertices[1].coords, vertices[0].coords-vertices[2].coords)&#xA;            h = numpy.inner( c, vertices[0].coords-vertices[3].coords )&#xA;            s = s + &amp;quot; new h = %f&amp;quot; % (h)&#xA;            print(s)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;h3&gt;Updated Code&lt;/h3&gt;&#xA;&lt;p&gt;I have updated my code according to the suggestions, but apparently faces are still a problem, the error it gives is&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Two elements connect to the same side of the shared element face. Coordinates: 12.3669, -61.573, 81.0725&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;My code is now as follows:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;import numpy&#xA;&#xA;def handedness(vertices):&#xA;    c = numpy.cross(vertices[1].coords-vertices[0].coords, \&#xA;                    vertices[2].coords-vertices[0].coords)&#xA;    h = numpy.inner( c, vertices[3].coords-vertices[0].coords )&#xA;    return h&#xA;&#xA;class tetrahedron:&#xA;    def __init__(self, vertices):&#xA;        h = handedness(vertices)&#xA;&#xA;        if h &amp;gt; 0:&#xA;            self.vertices = vertices&#xA;        else:&#xA;            s = &amp;quot;old h = %f&amp;quot; % (h)&#xA;            # swap last two vertices&#xA;            self.vertices = [vertices[0], vertices[1], vertices[3], vertices[2]]&#xA;            vertices = self.vertices&#xA;            h = handedness(self.vertices)&#xA;            s = s + &amp;quot; new h = %f&amp;quot; % (h)&#xA;            print(s)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="15121" LastEditorUserId="15121" LastEditDate="2020-10-26T09:49:15.600" LastActivityDate="2020-10-26T09:49:15.600" Title="Tetrahedron orientation" Tags="&lt;mesh&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10338" PostTypeId="2" ParentId="10337" CreationDate="2020-10-23T19:45:58.633" Score="2" Body="&lt;p&gt;This refers to the order of vertices within a face. Typically in 3D graphics, faces are wound counterclockwise, so that if you're looking from outside of the tetrahedron/mesh, all the front faces will have their vertices in counterclockwise order. (See &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Face_Culling#Winding_order&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://www.gamasutra.com/view/news/126352/Opinion_Backface_Culling_101.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; for more explanation.) This is a &amp;quot;right-hand rule&amp;quot; in that if the fingers of your right hand curl in the winding direction of the vertices, then your thumb points toward the outside of the mesh.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-10-23T19:45:58.633" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10339" PostTypeId="2" ParentId="8587" CreationDate="2020-10-23T20:33:05.220" Score="0" Body="&lt;p&gt;Some search terms that might benefit you: &amp;quot;image decomposition&amp;quot; and &amp;quot;image segmentation.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;For a good overview of some techniques, see &lt;a href=&quot;http://library.utia.cas.cz/separaty/2012/ZOI/suk-0381722.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Decomposition of binary images — A survey and comparison&lt;/a&gt;, by Suk et. al.&lt;/p&gt;&#xA;" OwnerUserId="13154" LastActivityDate="2020-10-23T20:33:05.220" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10340" PostTypeId="1" AcceptedAnswerId="10343" CreationDate="2020-10-25T15:47:29.217" Score="1" ViewCount="23" Body="&lt;p&gt;I am using tinyGLTF to parse gltf files and then render them in my program.&lt;/p&gt;&#xA;&lt;p&gt;I am currently during the third example in &lt;a href=&quot;https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0&quot; rel=&quot;nofollow noreferrer&quot;&gt;this page&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;In particular I am trying to extract the 2 animation buffers:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/YIfYs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YIfYs.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;My code:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;MeshMap LoadGltf(const std::string&amp;amp; path)&#xA;{&#xA;    Model model;&#xA;    TinyGLTF loader;&#xA;    std::string err;&#xA;    std::string warn;&#xA;&#xA;    bool ret = loader.LoadASCIIFromFile(&amp;amp;model, &amp;amp;err, &amp;amp;warn, path);&#xA;&#xA;    if(!warn.empty()) { cout &amp;lt;&amp;lt; warn &amp;lt;&amp;lt; endl; }&#xA;&#xA;    if(!err.empty()) { cout &amp;lt;&amp;lt; err &amp;lt;&amp;lt; endl; }&#xA;&#xA;    if(!ret) { cout &amp;lt;&amp;lt; &amp;quot;Failed to parse glTF&amp;quot; &amp;lt;&amp;lt; endl; }&#xA;&#xA;    MeshMap mesh_map;&#xA;    for(auto&amp;amp; mesh: model.meshes)&#xA;    {&#xA;        if(mesh.name.empty())&#xA;            mesh.name = &amp;quot;unnamed mesh &amp;quot; + to_string(global_mesh_index++);&#xA;        // TODO(low): implement this functionality as needed&#xA;        assert(mesh.primitives.size() == 1);&#xA;        GetPrimitiveData(model, mesh, mesh_map);&#xA;    }&#xA;&#xA;    if(model.animations.size())&#xA;    {&#xA;        cout &amp;lt;&amp;lt; &amp;quot;model.animations.size() &amp;quot; &amp;lt;&amp;lt; model.animations.size() &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; &amp;quot;model.animations[0].channels.size() &amp;quot; &amp;lt;&amp;lt; model.animations[0].channels.size() &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; &amp;quot;model.animations[0].channels[0].sampler &amp;quot; &amp;lt;&amp;lt; model.animations[0].channels[0].sampler &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; &amp;quot;model.animations[0].samplers[0].input &amp;quot; &amp;lt;&amp;lt; model.animations[0].samplers[0].input &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; &amp;quot;model.animations[0].samplers[0].output &amp;quot; &amp;lt;&amp;lt; model.animations[0].samplers[0].output &amp;lt;&amp;lt; endl;&#xA;&#xA;        const int input = model.animations[0].samplers[0].input;&#xA;        const int output = model.animations[0].samplers[0].output;&#xA;&#xA;        vector&amp;lt;float&amp;gt; time = ExtractDataFromAccessor&amp;lt;float&amp;gt;(model, input);&#xA;        for(auto f : time) cout &amp;lt;&amp;lt; f &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&#xA;        cout &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; time.size() &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; model.accessors[input].name &amp;lt;&amp;lt; endl;&#xA;        vector&amp;lt;float&amp;gt; rot = ExtractDataFromAccessor&amp;lt;float&amp;gt;(model, output);&#xA;        for(auto f : rot) cout &amp;lt;&amp;lt; f &amp;lt;&amp;lt; &amp;quot; &amp;quot;;&#xA;        cout &amp;lt;&amp;lt; endl;&#xA;&#xA;        cout &amp;lt;&amp;lt; model.animations[0].channels[0].target_node &amp;lt;&amp;lt; endl;&#xA;        cout &amp;lt;&amp;lt; model.animations[0].channels[0].target_path &amp;lt;&amp;lt; endl;&#xA;    }&#xA;&#xA;    return mesh_map;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;&#xA;std::vector&amp;lt;T&amp;gt; ExtractDataFromAccessor(&#xA;    Model&amp;amp; model,&#xA;    const int accessor_index)&#xA;{&#xA;    const int buffer_view_index = model.accessors[accessor_index].bufferView;&#xA;    const int buffer_index = model.bufferViews[buffer_view_index].buffer;&#xA;    const int buffer_length = model.bufferViews[buffer_view_index].byteLength;&#xA;    const int buffer_offset = model.bufferViews[buffer_view_index].byteOffset;&#xA;    const int buffer_stride = model.bufferViews[buffer_view_index].byteStride;&#xA;    const vector&amp;lt;unsigned char&amp;gt; data = model.buffers[buffer_index].data;&#xA;&#xA;    //TODO(low): extend functionality to handle this as needed.&#xA;    assert(buffer_stride == 0);&#xA;&#xA;    std::vector&amp;lt;T&amp;gt; holder(buffer_length / sizeof(T));&#xA;    memcpy(&#xA;        holder.data(),&#xA;        data.data() + buffer_offset,&#xA;        buffer_length);&#xA;&#xA;    return holder;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Output&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;model.animations.size() 1&#xA;model.animations[0].channels.size() 1&#xA;model.animations[0].channels[0].sampler 0&#xA;model.animations[0].samplers[0].input 2&#xA;model.animations[0].samplers[0].output 3&#xA;0 0.25 0.5 0.75 1 0 0 0 1 0 0 0.707 0.707 0 0 1 0 0 0 0.707 -0.707 0 0 0 1 &#xA;25&#xA;&#xA;0 0.25 0.5 0.75 1 0 0 0 1 0 0 0.707 0.707 0 0 1 0 0 0 0.707 -0.707 0 0 0 1 &#xA;0&#xA;rotation&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I am very confused in that &lt;code&gt;in&lt;/code&gt; and &lt;code&gt;out&lt;/code&gt; seem to be equal, and that they are the concatenation of the 2 animation buffers, rather than what I expected. Which was &lt;code&gt;in&lt;/code&gt; to be the time buffer and &lt;code&gt;out&lt;/code&gt; to be the rotation buffer.&lt;/p&gt;&#xA;&lt;p&gt;Where is the data that lets you separate them?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-10-25T18:54:35.897" Title="Why are these 2 buffers joint while extracting glTF information?" Tags="&lt;c++&gt;&lt;animation&gt;&lt;model&gt;&lt;gltf&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10341" PostTypeId="1" CreationDate="2020-10-25T16:25:27.953" Score="1" ViewCount="42" Body="&lt;p&gt;If I have an &lt;em&gt;output&lt;/em&gt; device, for which I have a known spectrum data for each of it's primaries, I should be able to calculate the CIEXYZ of its primaries using using the integral equations together with the CIE color matching functions. I can then calculate its respective CIExyY values, which for output device are always inside the boundary if the xyY spectral locus - the chromaticity diagram.&lt;/p&gt;&#xA;&lt;p&gt;My question relates to calculating xyY of primaries of &lt;em&gt;input&lt;/em&gt; device.&lt;/p&gt;&#xA;&lt;p&gt;Suppose I have a known spectrum data for the primaries of some input device - be it a digital scanner or a digital camera or any other input device. It's color filters are not perfect, this means that even a pure spectrum color is represented as non-zero values in its own RGB color space. That means that (if I'm correct) that the whole chromaticity diagram should lie inside of the device RGB color space, and it's primaries lie outside of the diagram and be represented by imaginary colors.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;How do I calculate those imaginary primaries for the input device given known spectrum for its primaries?&lt;/strong&gt; If I'm not mistaken, I cannot simply use the integral formula, because that seems to be only for output devices and the resulting primaries would lie in the locus.&lt;/p&gt;&#xA;" OwnerUserId="15131" LastActivityDate="2021-02-08T07:07:55.803" Title="Determining input color space primaries from spectrum data" Tags="&lt;color&gt;&lt;color-science&gt;&lt;color-management&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10342" PostTypeId="1" CreationDate="2020-10-25T16:41:33.530" Score="0" ViewCount="23" Body="&lt;p&gt;Maya has a feature called &lt;a href=&quot;https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2019/ENU/Maya-Basics/files/GUID-9922A396-77C0-4EEB-9A8A-B301720C5802-htm.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;preserve texture&lt;/a&gt;. It allows you to transform vertices of an object and basically have the texture &amp;quot;stay in place&amp;quot; in object space. Say I have a plane with unwrapped uvs. With the default implementation if I scale that plane the uv coordinates stay the same, and thus the texture scales with the plane. However with this feature the texture would stay the same size. The texture stays in place also when translating and rotating.&lt;/p&gt;&#xA;&lt;p&gt;Does this work by transforming the corresponding uvs when we transform the vertices? If so how does one calculate the transformation needed for the corresponding uvs?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-10-25T16:53:43.940" LastActivityDate="2020-10-25T16:53:43.940" Title="How to &quot;preserve texture&quot; when transforming vertices" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;uv-mapping&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10343" PostTypeId="2" ParentId="10340" CreationDate="2020-10-25T18:54:35.897" Score="1" Body="&lt;p&gt;The accessor (&lt;code&gt;model.accessors[accessor_index]&lt;/code&gt;) has its own &lt;code&gt;byteOffset&lt;/code&gt; and &lt;code&gt;count&lt;/code&gt; values that you need to account for here.&lt;/p&gt;&#xA;&lt;p&gt;The input and output accessors are allowed to share a bufferView, and your output is showing a dump of the same entire bufferView twice.  The first five values in that dump are the input accessor with the times (in seconds, since the start of the animation) and the remainder of the bufferView is pointed at by the output accessor.  If you account for the additional settings on the accessor itself, it should allow you to pick apart this bufferView correctly.&lt;/p&gt;&#xA;" OwnerUserId="1908" LastActivityDate="2020-10-25T18:54:35.897" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10345" PostTypeId="1" CreationDate="2020-10-26T13:52:29.043" Score="1" ViewCount="46" Body="&lt;p&gt;The specific chapter about this is here - &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Sampling_and_Reconstruction/Sampling_Theory.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sampling Theory&lt;/a&gt;&lt;br&gt;&#xA;Unlike what I read anywhere else, it defines Shah as: &lt;span class=&quot;math-container&quot;&gt;$$Ш_T(x)=T\sum\nolimits_i{\delta{(x-Ti)}}$$&lt;/span&gt;&#xA;And the T is still present in the reconstructed function: &lt;span class=&quot;math-container&quot;&gt;$$f\tilde(x)=T\sum\limits_{i=-\infty}^\infty{f(iT)r(x-iT)}$$&lt;/span&gt;&#xA;where r(x) is a reconstruction filter.&lt;br&gt;&#xA;Everywhere else I can find gives: &lt;span class=&quot;math-container&quot;&gt;$$s_T{(x)}=\sum\nolimits_i{\delta{(x-Ti)}}$$&lt;/span&gt;&#xA;Can someone work out the maths for me? Why is the difference?&lt;/p&gt;&#xA;&lt;p&gt;I haven't been doing maths for years, and even back in my school days, I don't think I was a good student, so please be gentle.&lt;/p&gt;&#xA;" OwnerUserId="15133" LastEditorUserId="15133" LastEditDate="2020-10-26T13:59:44.897" LastActivityDate="2020-10-26T13:59:44.897" Title="Why is there a T factor in the definition of Shah given in Matt Pharr's Physically Based Rendering?" Tags="&lt;pbrt&gt;&lt;pbrt-v3&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10346" PostTypeId="1" CreationDate="2020-10-26T15:33:01.940" Score="0" ViewCount="66" Body="&lt;p&gt;The question is simple, I have this diagram from the Khronos page:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Ru6dz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Ru6dz.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And this diagram from the &lt;a href=&quot;https://learnopengl.com/book/book_pdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Learn OpenGL page&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3mDKB.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3mDKB.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In the first picture the &lt;strong&gt;Primitive assembly&lt;/strong&gt; is executed for example &lt;strong&gt;after&lt;/strong&gt; the Geometry shader, in the second the execution happens &lt;strong&gt;before&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For the latter picture I took the relevant bit from the tutorial:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The primitive assembly stage takes as input all the vertices (or vertex if GL_POINTS is chosen) from the vertex shader that form a primitive and assembles all the point(s) in the primitive shape given; in this case a triangle.&#xA;The output of the primitive assembly stage is passed to the geometry shader. The geometry shader takes as input a collection of vertices that form a primitive and has the ability to generate other shapes by emitting new vertices to form new (or other) primitive(s). In this example case, it generates a second triangle out of the given shape.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I'm a bit confused cause I can't figure what that module and the Geometry shader takes as input, I'd be more prone to say the first diagram is correct. But maybe there's an interpretation I'm missing here.&lt;/p&gt;&#xA;&lt;p&gt;When is the Primitive assembly executed then?&lt;/p&gt;&#xA;" OwnerUserId="228" LastEditorUserId="228" LastEditDate="2020-10-26T16:44:34.363" LastActivityDate="2020-10-26T17:03:23.780" Title="OpenGL pipeline stages, when is the primitive assembly executed?" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10347" PostTypeId="2" ParentId="10346" CreationDate="2020-10-26T17:03:23.780" Score="1" Body="&lt;p&gt;For a diagram to be comprehensive, it'd have to show way too much detail. It's just a simple tool.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/opengl/wiki/Primitive_Assembly&quot; rel=&quot;nofollow noreferrer&quot;&gt;Primitive assembly&lt;/a&gt; is the process of taking a sequence of vertices for a particular &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Primitive&quot; rel=&quot;nofollow noreferrer&quot;&gt;rendering primitive&lt;/a&gt; type, and generating a sequence of base primitives (points, lines, triangles) from them.&lt;/p&gt;&#xA;&lt;p&gt;This process does indeed happen after vertex post-processing, as the input to the rasterizer is a sequence of base primitives. After all, you don't rasterize a triangle strip; you rasterize a triangle.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;However&lt;/em&gt;, the input to a &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Geometry_Shader&quot; rel=&quot;nofollow noreferrer&quot;&gt;geometry shader&lt;/a&gt; invocation is a single base primitive, taken from the sequence of vertices provided up to that point. As such, a form of primitive assembly &lt;em&gt;also&lt;/em&gt; must happen before the GS, to convert the vertex sequence into a sequence of base primitives.&lt;/p&gt;&#xA;&lt;p&gt;This is also one reason why GS's are &lt;em&gt;slow&lt;/em&gt;. If there is no GS, then this primitive assembly doesn't happen.&lt;/p&gt;&#xA;&lt;p&gt;The output of the geometry shader is a bunch of vertex sequences, which still later undergo primitive assembly based on the output primitive type of the GS. A GS can output triangle strips, so there has to be primitive assembly to turn those strips into individual triangles.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-10-26T17:03:23.780" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10348" PostTypeId="1" AcceptedAnswerId="10371" CreationDate="2020-10-27T07:56:59.950" Score="1" ViewCount="105" Body="&lt;p&gt;Suppose that I have some world-space volume (which we may assume is a convex polyhedron with a small number of vertices), and I want to render its intersection with the view frustum, such that every relevant pixel gets rendered exactly once. &lt;em&gt;My use-case is rendering light influence volumes for a deferred renderer, but I guess there may be other uses for this&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Everything is fine as long as the volume is completely behind the near clipping plane (i.e. isn't clipped by the near z-plane): rendering with back-face culling does the job, thanks to convexity of the volume. If, on the other hand, the volume intersects the near z-plane a bit, the intersection area gets clipped, but there are still parts of the volume behind this area that didn't get rendered. We could switch to front-face culling, but that breaks if the volume intersects the far z-plane. The volume could theoretically intersect both z-planes, so this problem cannot be solved simply by adjusting the culling mode. The volume could as well completely embody the view frustum, in which case nothing will be draw at all (all triangles outside the frustum), while in reality I'd like it to be rendered as if I'm rendering a fullscreen quad (since the intersection of the volume and the frustum equals the frustum).&lt;/p&gt;&#xA;&lt;p&gt;Right now my solution is to check if any of the volume's vertices are in front of the near z-plane (i.e. are clipped by the near z-plane) and resort to a fullscreen quad in this case. It works fine, but I'm curious whether there is a better solution.&lt;/p&gt;&#xA;&lt;p&gt;One solution that I don't particularly like is actually computing the mesh of the intersection of volume and the view frustum (both are convex polyhedrons, which should simplify the job a bit). It has the following disadvantages:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I have to either find a good enough library for mesh intersection, which means adding another dependency for the engine, or write the intersection code myself&lt;/li&gt;&#xA;&lt;li&gt;More importantly, even if the intersection is computed with maximal possible precision, it still goes through the vertex shader, gets multiplied by the view-projection matrix, with numerical errors inevitably introduced. Then, a vertex at z=near may appear at z=near+/-error, and it might still be erroneously clipped.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9044" LastEditorUserId="9044" LastEditDate="2020-10-27T19:03:50.330" LastActivityDate="2020-11-04T20:37:14.003" Title="Rendering a volume that might be completely clipped in OpenGL" Tags="&lt;opengl&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10350" PostTypeId="1" CreationDate="2020-10-29T17:24:49.330" Score="2" ViewCount="24" Body="&lt;p&gt;Using Unity I've been producing sculptural forms that look like this. It's made of patterns of cubes that twist around each other. I'm trying to get it into a 3D printable format.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/xvZ8x.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xvZ8x.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;From unity I export a PLY that is a list of the co-ords of each cube that looks like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;ply&#xA;format ascii 1.0&#xA;element vertex 17500&#xA;property float x&#xA;property float y&#xA;property float z&#xA;end_header&#xA;35 2.521441 0&#xA;34.72401 -2.06799 4.386663&#xA;33.90041 3.202552 8.704146&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then I've imported that into meshlab and run &lt;code&gt;Filters &amp;gt; Remeshing, Simplification and Reconstruction &amp;gt; Surface Reconstruction: Ball Pivoting&lt;/code&gt; with the default parameters.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Akdad.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Akdad.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is the result (different iteration so doesn't match top image but similar) which is ok, but obviously not 3d printable.&lt;/p&gt;&#xA;&lt;p&gt;Is there a better way of doing this to either wrap around as if I were wrapping cling film (saran wrap) over the whole thing? Or to preserve the chains of cubes and print the skeleton?&lt;/p&gt;&#xA;" OwnerUserId="15147" LastActivityDate="2020-10-29T17:24:49.330" Title="Wrapping a point cloud skeleton with a mesh" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10351" PostTypeId="1" CreationDate="2020-10-30T02:59:20.243" Score="1" ViewCount="109" Body="&lt;p&gt;I'm trying to reduce a thick line, in raster space, down to a thin line, preferably one pixel wide (or thick).&lt;/p&gt;&#xA;&lt;p&gt;Does anybody know of an algorithm that can do this?&lt;/p&gt;&#xA;&lt;p&gt;Imagine you draw with a marker on a piece of paper, scribbling here and there.  Then you scan this paper into a grey-scale or black-and-white raster image.  How can I produce another black-and-white image the same size but the lines you drew are very thin instead of thick?&lt;/p&gt;&#xA;&lt;p&gt;Surely this must be a solved problem, right?&lt;/p&gt;&#xA;" OwnerUserId="15152" LastActivityDate="2020-10-30T16:25:59.520" Title="Algorithm for thinning a thick line" Tags="&lt;2d-graphics&gt;&lt;pixel-graphics&gt;&lt;bitmap-graphics&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10352" PostTypeId="2" ParentId="10351" CreationDate="2020-10-30T16:02:36.283" Score="3" Body="&lt;p&gt;the canny algorithm is a great start.&lt;/p&gt;&#xA;&lt;p&gt;it takes a sobel input like so.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HeYpF.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HeYpF.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Computes its gradient. Then depending on the gradient orientation it compares all neighbouring pixels aligned with it. If its a local maximum the pixel remains black otherwise it is set to white.&lt;/p&gt;&#xA;&lt;p&gt;this article will probably explain it a lot better.&#xA;&lt;a href=&quot;https://towardsdatascience.com/canny-edge-detection-step-by-step-in-python-computer-vision-b49c3a2d8123&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://towardsdatascience.com/canny-edge-detection-step-by-step-in-python-computer-vision-b49c3a2d8123&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Ive tried to implement my own version using the algorithm provided however I'm struggling to port it to glsl as I think the interpolation might be causing an issue.&lt;/p&gt;&#xA;&lt;p&gt;here is a working one in shatertoy though, just a beginner though so a bit complex for me.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.shadertoy.com/view/wl2cW3&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.shadertoy.com/view/wl2cW3&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15155" LastEditorUserId="15155" LastEditDate="2020-10-30T16:25:59.520" LastActivityDate="2020-10-30T16:25:59.520" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10356" PostTypeId="1" AcceptedAnswerId="10359" CreationDate="2020-10-31T15:54:39.073" Score="1" ViewCount="36" Body="&lt;p&gt;With the help of instanced arrays we can specify an array of transforms and render a number of objects with a single render call. I'm wondering if using instanced arrays make sense in situations where the transforms of the objects need to be updated on each frame? In that case we would need to reupload the buffer with transforms on every frame. Is this practical or should we use individual rendering or &lt;code&gt;gl_Instance_ID&lt;/code&gt; (if the number of instances is not too high) instead?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-11-01T06:49:49.993" Title="Using instanced arrays for dynamic objects" Tags="&lt;opengl&gt;&lt;instance&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10357" PostTypeId="1" CreationDate="2020-11-01T00:01:39.367" Score="0" ViewCount="67" Body="&lt;p&gt;How to quantitatively compare two meshes? For example, comparing the same object mesh before and after processing it.&lt;/p&gt;&#xA;&lt;p&gt;Is there any library or code readily available for this?&lt;/p&gt;&#xA;" OwnerUserId="13888" LastActivityDate="2020-11-01T00:01:39.367" Title="Comparing two triangle meshes" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10359" PostTypeId="2" ParentId="10356" CreationDate="2020-11-01T06:49:49.993" Score="1" Body="&lt;p&gt;If you need to update data, then you need to update data &lt;em&gt;regardless&lt;/em&gt; of the mechanism you use to render the object. If you have 3000 objects to be rendered, and each frame they will be rendered with a different matrix transform, then you will have to send 192,000 bytes of memory (64-bytes-per-matrix) every frame. Whether explicitly through a write to buffer object storage or implicitly through setting uniform values, 192,000 bytes of data are going to have to find their way from CPU-space to GPU-space.&lt;/p&gt;&#xA;&lt;p&gt;So long as you use reasonable &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Buffer_Object_Streaming&quot; rel=&quot;nofollow noreferrer&quot;&gt;buffer object streaming techniques&lt;/a&gt;, performance due to sending data shouldn't be a problem relative to other ways to send the data. Especially for fairly small data like per-model transforms. Of course, good buffer streaming does require having two buffers, but that's a memory storage tradeoff, not a runtime performance cost.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-11-01T06:49:49.993" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10360" PostTypeId="1" CreationDate="2020-11-01T17:39:57.610" Score="0" ViewCount="50" Body="&lt;p&gt;Let &lt;code&gt;image1&lt;/code&gt; be:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Yhc6R.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Yhc6R.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And RGBA &lt;code&gt;mask&lt;/code&gt; be:&lt;/p&gt;&#xA;&lt;p&gt;(45, 78, 251, 102)&lt;/p&gt;&#xA;&lt;p&gt;Apply &lt;code&gt;mask&lt;/code&gt; on top of &lt;code&gt;image1&lt;/code&gt; to get &lt;code&gt;image2&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VIOvh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VIOvh.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now I need to do the reverse thing, given &lt;code&gt;image1&lt;/code&gt; and &lt;code&gt;image2&lt;/code&gt;, is there a formula or an algorithm (there has to be right?) to find the &lt;code&gt;mask&lt;/code&gt;?&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance, first post in here I might lack vocabulary I'm sorry about that, my tags might be completely off.&lt;/p&gt;&#xA;&lt;p&gt;EDIT: i program in Java. I get image2 by drawing image1 on some Windows native frame using Graphics#drawImage and then drawing the filter made of (45, 78, 251, 102) RGBA pixels on top of that image using the same function.&lt;/p&gt;&#xA;" OwnerUserId="15159" LastEditorUserId="15159" LastEditDate="2020-11-02T18:58:35.003" LastActivityDate="2020-11-02T18:58:35.003" Title="How to retrieve RGBA mask used to transform image1 into image2" Tags="&lt;filtering&gt;&lt;masking&gt;&lt;java&gt;" AnswerCount="0" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="10361" PostTypeId="1" CreationDate="2020-11-02T04:08:55.497" Score="0" ViewCount="47" Body="&lt;p&gt;2D application users seem to be using transparency as a proxy for coverage more often than not. However they are not the same, although nearly everybody makes the assumption that they are.&lt;/p&gt;&#xA;&lt;p&gt;Given that we do more coverage based assumptions than actual alpha based assumptions. Wouldnt it make more sense to formulate coverage somehow instead? Is it even possible to somehow do coverage based compositing?&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2020-11-02T04:08:55.497" Title="coverage vs transparency" Tags="&lt;transparency&gt;&lt;theory&gt;&lt;compositing&gt;" AnswerCount="0" CommentCount="7" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10362" PostTypeId="1" AcceptedAnswerId="10408" CreationDate="2020-11-02T08:19:47.237" Score="0" ViewCount="96" Body="&lt;p&gt;I want to set a transformation matrix to an object upon creation and then control it by position, rotation and scale, but while changing the matrix does change the object in world space, it's position parameter still remains 0, 0, 0.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;let mesh =  new THREE.Mesh(&#xA;    new THREE.BoxGeometry(),&#xA;    new THREE.MeshPhongMaterial({color:0xf15728})&#xA;)&#xA;this.scene.add(mesh)&#xA;&#xA;let pos = new THREE.Vector3().setFromMatrixPosition(m)&#xA;&#xA;mesh.matrixAutoUpdate = false&#xA;mesh.matrix.copy(m)&#xA;&#xA;// ***************//&#xA;mesh.updateMatrix()&#xA;// ***************//&#xA;&#xA;console.log(&amp;quot;mesh.position&amp;quot;, mesh.position)&#xA;console.log(&amp;quot;pos&amp;quot;, pos)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here's the output for the values of both &lt;code&gt;pos&lt;/code&gt; and &lt;code&gt;mesh.position&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rpyoR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rpyoR.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7525" LastActivityDate="2020-11-16T10:43:08.873" Title="THREEjs: updating an object's matrix doesnt change it's position and rotation params" Tags="&lt;transformations&gt;&lt;matrix&gt;&lt;three.js&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10363" PostTypeId="1" CreationDate="2020-11-02T18:09:46.543" Score="1" ViewCount="47" Body="&lt;p&gt;I am trying to learn about 3d graphics from first principles, so i have decided to implement a simple thing, create a circle in 3d space &amp;amp; rotate it along some axis. I understand the basics theory.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;position circle somewhere in 3d space.&lt;/li&gt;&#xA;&lt;li&gt;calculate its projection on some plane.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Once i can get this i can use rotation matrix to calculate the new position of vertices. but i am a bit stuck at 2nd step.&#xA;this is my code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;import pygame&#xA;import math&#xA;&#xA;(width, height) = (600, 500)&#xA;screen = pygame.display.set_mode((width, height))&#xA;pygame.display.flip()&#xA;&#xA;&#xA;running = True&#xA;&#xA;K = 8   # view plane distance&#xA;cz = 10 # z location of circle initially.&#xA;&#xA;# Pyagme 0.0 is at top left , but i want to center it at window?? is this even coorect to do or is should just continue using top left.&#xA;&#xA;def translate_coords_to_center(x , y):&#xA;    return (width/2 - x, height/2 - y)&#xA;&#xA;# plots a pixel&#xA;def pixel(x,y,color=(100,20,30)):&#xA;    s = pygame.Surface((1,1))&#xA;    s.fill(color)&#xA;    r,r.x,r.y = s.get_rect(),x,y&#xA;    screen.blit(s,r)&#xA;&#xA;&#xA;# Draw the circle&#xA;def circle(cx, cy, cz, radius):&#xA;    N = 100&#xA;    PI = 3.14&#xA;    angle = 360 / N&#xA;&#xA;&#xA;    for i in range(N):&#xA;        x2 = cx + radius * math.cos(PI* angle * i / 180)&#xA;        y2 = cy + radius * math.sin(PI* angle * i / 180)&#xA;&#xA;        # Do a 2d projection&#xA;        x2 = K* x2 / cz&#xA;        y2 = K* y2 / cz&#xA;&#xA;        pixel(x2, y2)&#xA;&#xA;&#xA;while running:&#xA;    x, y = translate_coords_to_center(0,0)&#xA;    circle(x, y, cz, 50)&#xA;    cz += 1&#xA;    pygame.display.flip()&#xA;    for event in pygame.event.get():&#xA;        if event.type == pygame.QUIT:&#xA;            running = False&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When i change the z position of circle, i get something like the below image, I am expecting the circle to not change its position but only its size, ( i know this cant be true as i am dividing by &lt;code&gt;z&lt;/code&gt; ), am i missing some translation step? :&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rQrsr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rQrsr.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;EDIT:  Adding the translation after projection is also not working:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;import pygame&#xA;import math&#xA;&#xA;(width, height) = (600, 500)&#xA;screen = pygame.display.set_mode((width, height))&#xA;pygame.display.flip()&#xA;&#xA;&#xA;running = True&#xA;&#xA;K = 8   &#xA;cz = 10 &#xA;&#xA;def translate_coords_to_center(x , y):&#xA;    return (width/2 - x, height/2 - y)&#xA;&#xA;&#xA;def pixel(x,y,color=(100,20,30)):&#xA;    s = pygame.Surface((1,1))&#xA;    s.fill(color)&#xA;    r,r.x,r.y = s.get_rect(),x,y&#xA;    screen.blit(s,r)&#xA;&#xA;def circle(cx, cy, cz, radius):&#xA;    N = 100&#xA;    PI = 3.14&#xA;    angle = 360 / N&#xA;&#xA;&#xA;    for i in range(N):&#xA;        x2 = cx + radius * math.cos(PI* angle * i / 180)&#xA;        y2 = cy + radius * math.sin(PI* angle * i / 180)&#xA;&#xA;        # Do a 2d projection&#xA;        x2 = K* x2 / cz&#xA;        y2 = K* y2 / cz&#xA;        sx, sy = translate_coords_to_center(x2, y2)&#xA;&#xA;        pixel(sx, sy)&#xA;&#xA;&#xA;&#xA;while running:&#xA;    &#xA;    circle(0,0, cz, 50) # this works correctly, but circles are centered at top left corner of screen,&#xA;    cz += 1&#xA;    pygame.display.flip()&#xA;    for event in pygame.event.get():&#xA;        if event.type == pygame.QUIT:&#xA;            running = False&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13309" LastEditorUserId="13309" LastEditDate="2020-11-03T11:03:30.327" LastActivityDate="2020-11-03T11:03:30.327" Title="projecting 3d onto 2d plane is not showing up correctly" Tags="&lt;3d&gt;&lt;2d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10364" PostTypeId="2" ParentId="10363" CreationDate="2020-11-03T07:56:04.907" Score="1" Body="&lt;p&gt;Your translate_coords_to_center(0,0) function should be done after you have done the projection from 3d to 2d.&lt;/p&gt;&#xA;&lt;p&gt;e.g.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;for i in range(N):&#xA;        x2 = cx + radius * math.cos(PI* angle * i / 180)&#xA;        y2 = cy + radius * math.sin(PI* angle * i / 180)&#xA;&#xA;        # Do a 2d projection&#xA;        x2 = K* x2 / cz&#xA;        y2 = K* y2 / cz&#xA;&#xA;        sx, sy = translate_coords_to_center(x2, y2)&#xA;&#xA;        pixel(sy, sy)&#xA;&#xA;while running:&#xA;    circle(0, 0, cz, 50)&#xA;    cz += 1&#xA;    pygame.display.flip()&#xA;    for event in pygame.event.get():&#xA;        if event.type == pygame.QUIT:&#xA;            running = False&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The effect you are seeing is caused by 2 things.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Because a constant x/y offset is incorrectly added in 3d world space the array of circles will appear to the right and below of the camera's position.&lt;/li&gt;&#xA;&lt;li&gt;Because the 0,0 origin of view/camera space is not the centre of the display, instead it's at the top-left (Adding the window centre coords AFTER projection fixes that)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2020-11-03T10:35:38.030" LastActivityDate="2020-11-03T10:35:38.030" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10365" PostTypeId="1" CreationDate="2020-11-03T18:27:11.003" Score="1" ViewCount="168" Body="&lt;p&gt;I am writing a Vulkan video manipulation engine which has the following layers:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Foreground (2D)&lt;/li&gt;&#xA;&lt;li&gt;Scene (3D)&lt;/li&gt;&#xA;&lt;li&gt;Background (2D)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Note that each layer may have multiple objects, some of which may be transparent. For 2D objects (foreground and background), I want to preserve the relative between objects. Therefore, I thought about the following technique, in order to execute the FS the least amount of times possible:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Draw the opaque foreground objects backwards, writing 0x02 at the stencil buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw the opaque scene objects backwards (sorted by average depth), writing and testing 0x01 at the stencil buffer and writing and testing at the depth buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw the opaque background objects backwards, writing and testing 0x00 at the stencil buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw the transparent background forwards, writing and testing 0x00 at the stencil buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw the transparent scene objects forwards (sorted by average depth), writing and testing 0x01 at the stencil buffer and writing and testing at the depth buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw the transparent foreground forwards, writing and testing 0x02 at the stencil buffer.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;However, this technique does not work as specified, as the relative order between transparent and opaque objects at the background and foreground won't be preserved. This other technique would satisfy the condition (regardless of cherry picking OIT issues) although it is not efficient:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Draw all the background objects forwards&lt;/li&gt;&#xA;&lt;li&gt;Draw the opaque scene objects backwards (sorted by average depth), writing and testing at the depth buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw the transparent scene objects forwards (sorted by average depth), writing and testing at the depth buffer.&lt;/li&gt;&#xA;&lt;li&gt;Draw all the foreground objects forwards&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I would like to know if there is any technique with Vulkan that lets me implement the first algorithm without the mentioned problems. I've thought about a secondary depth buffer in which the relative order between 2D layers gets written (write and test a constant), but this leads me to a new concern:&lt;/p&gt;&#xA;&lt;p&gt;According to some posts, if gl_FragDepth gets written from a shader (remember that I pretend to write a constant value from an uniform buffer to the depth value), fragment shader gets fully executed, which throws away the purpose of this optimization.&lt;/p&gt;&#xA;" OwnerUserId="15171" LastEditorUserId="15171" LastEditDate="2020-11-04T18:33:15.200" LastActivityDate="2021-02-07T07:01:45.207" Title="Layer rendering in Vulkan" Tags="&lt;vulkan&gt;&lt;z-buffer&gt;&lt;stencil-buffer&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10366" PostTypeId="1" CreationDate="2020-11-03T22:57:48.650" Score="1" ViewCount="137" Body="&lt;p&gt;I'm implementing ERPT-style energy redistribution of primary samples within a pathtracer. Specifically, to improve the sampling of defocused areas.&lt;/p&gt;&#xA;&lt;p&gt;The core algorithm does two things:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;If sample luminance is higher than threshold, I redistribute the sample energy over many backwards fired rays. This is stored in a framebuffer. The result of this is super clean!&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;I also store all non-redistributed samples in a separate framebuffer.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;My question is about how I should recombine these two framebuffers. Which probabilities should I be using? I've tried a variety of approaches but none of them have worked perfectly. I cannot just remove the samples-to-be-redistributed and sum the redistributed samples on top. This results in discontinuities. I think I need to be using a certain weighting.&lt;/p&gt;&#xA;&lt;p&gt;An example scenario is as follows:&lt;/p&gt;&#xA;&lt;p&gt;Pathtraced result I start with:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/NoPss.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NoPss.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Take a selection of the samples to redistribute:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/odXV8.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/odXV8.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Redistributing these high intensity samples in separate framebuffer:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/BsFVp.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BsFVp.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;How can I re-combine the redistributed &amp;amp; unredistributed results?&lt;/p&gt;&#xA;&lt;p&gt;Any help would be appreciated!&lt;/p&gt;&#xA;" OwnerUserId="9505" LastEditorUserId="9505" LastEditDate="2020-11-04T09:57:13.820" LastActivityDate="2020-11-04T11:42:53.337" Title="Energy redistribution sample re-integration" Tags="&lt;rendering&gt;&lt;pathtracing&gt;&lt;monte-carlo&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10367" PostTypeId="1" AcceptedAnswerId="10368" CreationDate="2020-11-04T03:31:36.533" Score="3" ViewCount="126" Body="&lt;p&gt;I've taken a class about ray-plane intersection on this: &lt;a href=&quot;https://www.khanacademy.org/computing/pixar/rendering/rendering-2/v/rendering-5&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.khanacademy.org/computing/pixar/rendering/rendering-2/v/rendering-5&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Suppose we shoot a ray at the scene and this scene contains millions of triangles. How can we know if the ray intersected one of the triangle? Do we just run a check on this millions of triangle if it intersects with the ray? That would be inefficient!!&lt;/p&gt;&#xA;" OwnerUserId="15172" LastEditorUserId="15172" LastEditDate="2020-11-05T00:57:22.887" LastActivityDate="2020-11-05T00:57:22.887" Title="How do we know if a ray intersected a triangle in one in a million" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10368" PostTypeId="2" ParentId="10367" CreationDate="2020-11-04T08:58:57.007" Score="3" Body="&lt;p&gt;If you want to know all triangles that are hit by the ray, you have to check all of them. However, that doesn't mean that you have to check each of them individually. Usually, you apply some sort of &lt;a href=&quot;https://en.wikipedia.org/wiki/Space_partitioning&quot; rel=&quot;nofollow noreferrer&quot;&gt;space partitioning&lt;/a&gt; to your scene and group related objects in a &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume_hierarchy&quot; rel=&quot;nofollow noreferrer&quot;&gt;bounding volume hierarchy&lt;/a&gt;. Then it gets a lot more efficient because you can drop multiple triangles with a single check.&lt;/p&gt;&#xA;&lt;p&gt;For example, consider a scene with a rectangular area. You might subdivide this area into a 10x10 grid. Now check which parts of the grid are hit by the ray. All objects located in grid cells that aren't hit by the ray can be discarded and you only need to check the remaining objects. Now let's say that one of the hit objects is a human. Before you test the individual triangles, you narrow down the affected area in multiple substeps by checking against its &lt;a href=&quot;https://en.wikipedia.org/wiki/Bounding_volume_hierarchy&quot; rel=&quot;nofollow noreferrer&quot;&gt;bounding volume hierarchy&lt;/a&gt;. The traversal of the hierarchy might look like this: upper body hit -&amp;gt; left arm hit -&amp;gt; hand hit -&amp;gt; thumb hit. So with 4 checks, you can discard all triangles of the humans' mesh that do not belong to the thumb.&lt;/p&gt;&#xA;&lt;p&gt;In case you only want to find the first triangle that is hit by the ray, you can also sort all hit cells and objects by distance before performing detailed tests. Then you start your checks at the closest object and continue until you get the first hit.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-11-04T08:58:57.007" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10369" PostTypeId="1" CreationDate="2020-11-04T10:16:52.430" Score="0" ViewCount="54" Body="&lt;p&gt;While porting &lt;a href=&quot;https://github.com/progschj/OpenGL-Examples/blob/master/12shader_image_load_store.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;this project&lt;/a&gt; with slightly modified code to Linux I ran into some weird behaviour.&lt;/p&gt;&#xA;&lt;p&gt;On Windows it runs just fine (&lt;a href=&quot;https://youtu.be/xH6Dc6xOuow&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/xH6Dc6xOuow&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;But on Ubuntu it shows some &lt;a href=&quot;https://youtu.be/BrZtWHw1Wmk&quot; rel=&quot;nofollow noreferrer&quot;&gt;weird behaviour&lt;/a&gt;.&#xA;Aside from the much higher speed, the colors start to overlap near the end.&lt;/p&gt;&#xA;&lt;p&gt;The code is exactly the same for both examples (aside from the paths to the shaders, see below).&#xA;On Ubuntu I did try different drivers for my graphics card, but this problem remained.&#xA;Something which still comes to my mind, that could be wrong is the CMakeLists.txt file, as I am new to cmake.&lt;/p&gt;&#xA;&lt;p&gt;So why does this behaviour occur and how can I solve it?&lt;/p&gt;&#xA;&lt;p&gt;The code:&lt;/p&gt;&#xA;&lt;p&gt;main.cpp&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;glad/glad.h&amp;gt;&#xA;#include &amp;lt;GLFW/glfw3.h&amp;gt;&#xA;&#xA;#include &amp;lt;glm/glm.hpp&amp;gt;&#xA;#include &amp;lt;glm/gtc/noise.hpp&amp;gt; &#xA;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;string&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;&#xA;#include &amp;quot;shader.h&amp;quot;&#xA;&#xA;&#xA;&#xA;int main() {&#xA;    int width = 640;&#xA;    int height = 480;&#xA;&#xA;    if (glfwInit() == GL_FALSE) {&#xA;        std::cerr &amp;lt;&amp;lt; &amp;quot;failed to init GLFW&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;        return 1;&#xA;    }&#xA;&#xA;    // select opengl version&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);&#xA;&#xA;    // create a window&#xA;    GLFWwindow* window;&#xA;    if ((window = glfwCreateWindow(width, height, &amp;quot;12shader_image_load_store&amp;quot;, 0, 0)) == 0) {&#xA;        std::cerr &amp;lt;&amp;lt; &amp;quot;failed to open window&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;        glfwTerminate();&#xA;        return 1;&#xA;    }&#xA;&#xA;    glfwMakeContextCurrent(window);&#xA;&#xA;    // glad: load all OpenGL function pointers&#xA;    // ---------------------------------------&#xA;    if (!gladLoadGLLoader(reinterpret_cast&amp;lt;GLADloadproc&amp;gt;(glfwGetProcAddress)))&#xA;    {&#xA;        std::cout &amp;lt;&amp;lt; &amp;quot;Failed to initialize GLAD&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;        return -1;&#xA;    }&#xA;&#xA;    //glfwSwapInterval(1);&#xA;&#xA;    Shader shader1(&amp;quot;source.vert&amp;quot;, &amp;quot;source1.frag&amp;quot;);&#xA;    Shader shader2(&amp;quot;source.vert&amp;quot;, &amp;quot;source2.frag&amp;quot;);&#xA;    &#xA;&#xA;    // vao and vbo handle&#xA;    GLuint vao, vbo, ibo;&#xA;&#xA;    // generate and bind the vao&#xA;    glGenVertexArrays(1, &amp;amp;vao);&#xA;    glBindVertexArray(vao);&#xA;&#xA;    // generate and bind the vertex buffer object&#xA;    glGenBuffers(1, &amp;amp;vbo);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;&#xA;    // data for a fullscreen quad&#xA;    GLfloat vertexData[] = {&#xA;        //  X     Y     Z&#xA;           1.0f, 1.0f, 0.0f, // vertex 0&#xA;          -1.0f, 1.0f, 0.0f, // vertex 1&#xA;           1.0f,-1.0f, 0.0f, // vertex 2&#xA;          -1.0f,-1.0f, 0.0f, // vertex 3&#xA;    }; // 4 vertices with 3 components (floats) each&#xA;&#xA;    // fill with data&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 4 * 3, vertexData, GL_STATIC_DRAW);&#xA;&#xA;&#xA;    // set up generic attrib pointers&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (char*)0 + 0 * sizeof(GLfloat));&#xA;&#xA;&#xA;    // generate and bind the index buffer object&#xA;    glGenBuffers(1, &amp;amp;ibo);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);&#xA;&#xA;    GLuint indexData[] = {&#xA;        0,1,2, // first triangle&#xA;        2,1,3, // second triangle&#xA;    };&#xA;&#xA;    // fill with data&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 2 * 3, indexData, GL_STATIC_DRAW);&#xA;&#xA;    // texture handle&#xA;    GLuint texture;&#xA;&#xA;    // generate texture&#xA;    glGenTextures(1, &amp;amp;texture);&#xA;&#xA;    // bind the texture&#xA;    glBindTexture(GL_TEXTURE_2D, texture);&#xA;&#xA;    // create some image data&#xA;    std::vector&amp;lt;GLfloat&amp;gt; image(4 * width * height);&#xA;    for (int j = 0; j &amp;lt; height; ++j) {&#xA;        for (int i = 0; i &amp;lt; width; ++i) {&#xA;            size_t index = j * width + i;&#xA;            image[4 * index + 0] = 0.0f;&#xA;            image[4 * index + 1] = 0.0f;&#xA;            image[4 * index + 2] = 0.0f;&#xA;            image[4 * index + 3] = 20.0f * glm::clamp(glm::perlin(0.006f * glm::vec2(i, j + 150)), 0.0f, 0.1f);&#xA;        }&#xA;    }&#xA;&#xA;    // set texture parameters&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);&#xA;    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);&#xA;&#xA;    // set texture content&#xA;    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, &amp;amp;image[0]);&#xA;    &#xA;    float t = 0;&#xA;    float dt = 1.0f / 60.0f;&#xA;    while (!glfwWindowShouldClose(window)) {&#xA;        glfwPollEvents();&#xA;&#xA;        t += dt;&#xA;&#xA;        // reset time every 10 seconds to repeat the sequence&#xA;        if (t &amp;gt; 20) t = 0;&#xA;&#xA;        // clear first&#xA;        glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;        glBindImageTexture(0, texture, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);&#xA;&#xA;        // bind the vao&#xA;        glBindVertexArray(vao);&#xA;&#xA;        int substeps = 5;&#xA;&#xA;        shader1.use();&#xA;&#xA;        shader1.setIVec2(&amp;quot;image_size&amp;quot;, width, height);&#xA;        shader1.setInt(&amp;quot;image&amp;quot;, 0);&#xA;        shader1.setFloat(&amp;quot;dt&amp;quot;, static_cast&amp;lt;float&amp;gt;(50 * dt / substeps));&#xA;&#xA;        shader2.use();&#xA;&#xA;        shader2.setIVec2(&amp;quot;image_size&amp;quot;, width, height);&#xA;        shader2.setInt(&amp;quot;image&amp;quot;, 0);&#xA;        shader2.setFloat(&amp;quot;dt&amp;quot;, static_cast&amp;lt;float&amp;gt;(50 * dt / substeps));&#xA;&#xA;        &#xA;        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);&#xA;        int i = 0;&#xA;        for (; i &amp;lt; substeps - 1; ++i) {&#xA;            shader1.use();&#xA;&#xA;            glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);&#xA;&#xA;            shader2.use();&#xA;            shader2.setFloat(&amp;quot;t&amp;quot;, static_cast&amp;lt;float&amp;gt;(t + i * dt / substeps));&#xA;&#xA;            glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);&#xA;        }&#xA;&#xA;        &#xA;        shader1.use();&#xA;&#xA;        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);&#xA;&#xA;        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);&#xA;&#xA;        shader2.use();&#xA;        shader2.setFloat(&amp;quot;t&amp;quot;, static_cast&amp;lt;float&amp;gt;(t + i * dt / substeps));&#xA;&#xA;        glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);&#xA;&#xA;        // check for errors&#xA;        GLenum error = glGetError();&#xA;        if (error != GL_NO_ERROR) {&#xA;            std::cerr &amp;lt;&amp;lt; error &amp;lt;&amp;lt; std::endl;&#xA;            break;&#xA;        }&#xA;        &#xA;        // finally swap buffers&#xA;        glfwSwapBuffers(window);&#xA;    }&#xA;&#xA;    // delete the created objects&#xA;&#xA;    glDeleteTextures(1, &amp;amp;texture);&#xA;&#xA;    glDeleteVertexArrays(1, &amp;amp;vao);&#xA;    glDeleteBuffers(1, &amp;amp;vbo);&#xA;    glDeleteBuffers(1, &amp;amp;ibo);&#xA;&#xA;&#xA;    glfwDestroyWindow(window);&#xA;    glfwTerminate();&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;shader.h&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#ifndef SHADER_H&#xA;#define SHADER_H&#xA;&#xA;#include &amp;lt;glad/glad.h&amp;gt;&#xA;#include &amp;lt;glm/glm.hpp&amp;gt;&#xA;&#xA;#include &amp;lt;string&amp;gt;&#xA;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;sstream&amp;gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;&#xA;class Shader&#xA;{&#xA;public:&#xA;    unsigned int ID;&#xA;    // default constructor&#xA;    // -------------------&#xA;    Shader() { ID = -1; }&#xA;    // constructor generates the shader on the fly&#xA;    // ------------------------------------------------------------------------&#xA;    Shader(const char* vertexPath, const char* fragmentPath, const char* geometryPath = nullptr)&#xA;    {&#xA;        // 1. retrieve the vertex/fragment source code from filePath&#xA;        std::string vertexCode;&#xA;        std::string fragmentCode;&#xA;        std::string geometryCode;&#xA;        std::ifstream vShaderFile;&#xA;        std::ifstream fShaderFile;&#xA;        std::ifstream gShaderFile;&#xA;        // ensure ifstream objects can throw exceptions:&#xA;        vShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);&#xA;        fShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);&#xA;        gShaderFile.exceptions(std::ifstream::failbit | std::ifstream::badbit);&#xA;        try&#xA;        {&#xA;            // open files&#xA;            vShaderFile.open(vertexPath);&#xA;            fShaderFile.open(fragmentPath);&#xA;            std::stringstream vShaderStream, fShaderStream;&#xA;            // read file's buffer contents into streams&#xA;            vShaderStream &amp;lt;&amp;lt; vShaderFile.rdbuf();&#xA;            fShaderStream &amp;lt;&amp;lt; fShaderFile.rdbuf();&#xA;            // close file handlers&#xA;            vShaderFile.close();&#xA;            fShaderFile.close();&#xA;            // convert stream into string&#xA;            vertexCode = vShaderStream.str();&#xA;            fragmentCode = fShaderStream.str();&#xA;            // if geometry shader path is present, also load a geometry shader&#xA;            if (geometryPath != nullptr)&#xA;            {&#xA;                gShaderFile.open(geometryPath);&#xA;                std::stringstream gShaderStream;&#xA;                gShaderStream &amp;lt;&amp;lt; gShaderFile.rdbuf();&#xA;                gShaderFile.close();&#xA;                geometryCode = gShaderStream.str();&#xA;            }&#xA;        }&#xA;        catch (std::ifstream::failure const&amp;amp; e)&#xA;        {&#xA;            std::cout &amp;lt;&amp;lt; &amp;quot;ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;        }&#xA;        const char* vShaderCode = vertexCode.c_str();&#xA;        const char* fShaderCode = fragmentCode.c_str();&#xA;        // 2. compile shaders&#xA;        unsigned int vertex, fragment;&#xA;        // vertex shader&#xA;        vertex = glCreateShader(GL_VERTEX_SHADER);&#xA;        glShaderSource(vertex, 1, &amp;amp;vShaderCode, NULL);&#xA;        glCompileShader(vertex);&#xA;        checkCompileErrors(vertex, &amp;quot;VERTEX&amp;quot;);&#xA;        // fragment Shader&#xA;        fragment = glCreateShader(GL_FRAGMENT_SHADER);&#xA;        glShaderSource(fragment, 1, &amp;amp;fShaderCode, NULL);&#xA;        glCompileShader(fragment);&#xA;        checkCompileErrors(fragment, &amp;quot;FRAGMENT&amp;quot;);&#xA;        // if geometry shader is given, compile geometry shader&#xA;        unsigned int geometry;&#xA;        if (geometryPath != nullptr)&#xA;        {&#xA;            const char* gShaderCode = geometryCode.c_str();&#xA;            geometry = glCreateShader(GL_GEOMETRY_SHADER);&#xA;            glShaderSource(geometry, 1, &amp;amp;gShaderCode, NULL);&#xA;            glCompileShader(geometry);&#xA;            checkCompileErrors(geometry, &amp;quot;GEOMETRY&amp;quot;);&#xA;        }&#xA;        // shader Program&#xA;        ID = glCreateProgram();&#xA;        glAttachShader(ID, vertex);&#xA;        glAttachShader(ID, fragment);&#xA;        if (geometryPath != nullptr)&#xA;            glAttachShader(ID, geometry);&#xA;        glLinkProgram(ID);&#xA;        checkCompileErrors(ID, &amp;quot;PROGRAM&amp;quot;);&#xA;        // delete the shaders as they're linked into our program now and no longer necessery&#xA;        glDeleteShader(vertex);&#xA;        glDeleteShader(fragment);&#xA;        if (geometryPath != nullptr)&#xA;            glDeleteShader(geometry);&#xA;&#xA;    }&#xA;    // activate the shader&#xA;    // ------------------------------------------------------------------------&#xA;    void use()&#xA;    {&#xA;        glUseProgram(ID);&#xA;    }&#xA;    // utility uniform functions&#xA;    // ------------------------------------------------------------------------&#xA;    void setBool(const std::string&amp;amp; name, bool value) const&#xA;    {&#xA;        glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setInt(const std::string&amp;amp; name, int value) const&#xA;    {&#xA;        glUniform1i(glGetUniformLocation(ID, name.c_str()), value);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setFloat(const std::string&amp;amp; name, float value) const&#xA;    {&#xA;        glUniform1f(glGetUniformLocation(ID, name.c_str()), value);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setVec2(const std::string&amp;amp; name, const glm::vec2&amp;amp; value) const&#xA;    {&#xA;        glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &amp;amp;value[0]);&#xA;    }&#xA;    void setVec2(const std::string&amp;amp; name, float x, float y) const&#xA;    {&#xA;        glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y);&#xA;    }&#xA;    void setIVec2(const std::string&amp;amp; name, int x, int y) const&#xA;    {&#xA;        glUniform2i(glGetUniformLocation(ID, name.c_str()), x, y);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setVec3(const std::string&amp;amp; name, const glm::vec3&amp;amp; value) const&#xA;    {&#xA;        glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &amp;amp;value[0]);&#xA;    }&#xA;    void setVec3(const std::string&amp;amp; name, float x, float y, float z) const&#xA;    {&#xA;        glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setVec4(const std::string&amp;amp; name, const glm::vec4&amp;amp; value) const&#xA;    {&#xA;        glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &amp;amp;value[0]);&#xA;    }&#xA;    void setVec4(const std::string&amp;amp; name, float x, float y, float z, float w)&#xA;    {&#xA;        glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setMat2(const std::string&amp;amp; name, const glm::mat2&amp;amp; mat) const&#xA;    {&#xA;        glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &amp;amp;mat[0][0]);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setMat3(const std::string&amp;amp; name, const glm::mat3&amp;amp; mat) const&#xA;    {&#xA;        glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &amp;amp;mat[0][0]);&#xA;    }&#xA;    // ------------------------------------------------------------------------&#xA;    void setMat4(const std::string&amp;amp; name, const glm::mat4&amp;amp; mat) const&#xA;    {&#xA;        glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &amp;amp;mat[0][0]);&#xA;    }&#xA;&#xA;private:&#xA;    // utility function for checking shader compilation/linking errors.&#xA;    // ------------------------------------------------------------------------&#xA;    void checkCompileErrors(GLuint shader, std::string type)&#xA;    {&#xA;        GLint success;&#xA;        GLchar infoLog[1024];&#xA;        if (type != &amp;quot;PROGRAM&amp;quot;)&#xA;        {&#xA;            glGetShaderiv(shader, GL_COMPILE_STATUS, &amp;amp;success);&#xA;            if (!success)&#xA;            {&#xA;                glGetShaderInfoLog(shader, 1024, NULL, infoLog);&#xA;                std::cout &amp;lt;&amp;lt; &amp;quot;ERROR::SHADER_COMPILATION_ERROR of type: &amp;quot; &amp;lt;&amp;lt; type &amp;lt;&amp;lt; &amp;quot;\n&amp;quot; &amp;lt;&amp;lt; infoLog &amp;lt;&amp;lt; &amp;quot;\n -- --------------------------------------------------- -- &amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;            }&#xA;        }&#xA;        else&#xA;        {&#xA;            glGetProgramiv(shader, GL_LINK_STATUS, &amp;amp;success);&#xA;            if (!success)&#xA;            {&#xA;                glGetProgramInfoLog(shader, 1024, NULL, infoLog);&#xA;                std::cout &amp;lt;&amp;lt; &amp;quot;ERROR::PROGRAM_LINKING_ERROR of type: &amp;quot; &amp;lt;&amp;lt; type &amp;lt;&amp;lt; &amp;quot;\n&amp;quot; &amp;lt;&amp;lt; infoLog &amp;lt;&amp;lt; &amp;quot;\n -- --------------------------------------------------- -- &amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;            }&#xA;        }&#xA;    }&#xA;};&#xA;#endif&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;source.vert&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 420&#xA;&#xA;layout(location = 0) in vec4 vposition;&#xA;&#xA;void main() &#xA;{&#xA;    gl_Position = vposition;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;source1.frag&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 420&#xA;&#xA;uniform float dt;&#xA;uniform ivec2 image_size;&#xA;uniform layout(rgba32f) image2D image;&#xA;layout(location = 0) out vec4 FragColor;&#xA;&#xA;void main() &#xA;{&#xA;   ivec2 coords = ivec2(gl_FragCoord.xy);&#xA;    vec4 HE = imageLoad(image, coords);&#xA;    float Ezdx = HE.z-imageLoad(image, coords-ivec2(1, 0)).z;&#xA;    float Ezdy = HE.z-imageLoad(image, coords-ivec2(0, 1)).z;&#xA;   HE.xy += dt*vec2(-Ezdy, Ezdx);&#xA;   imageStore(image, coords, HE);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;source2.frag&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 420&#xA;&#xA;uniform float t;&#xA;uniform float dt;&#xA;uniform ivec2 image_size;&#xA;uniform layout(rgba32f) image2D image;&#xA;&#xA;layout(location = 0) out vec4 FragColor;&#xA;&#xA;void main() &#xA;{&#xA;   ivec2 coords = ivec2(gl_FragCoord.xy);&#xA;&#xA;    float e = 1;&#xA;    vec4 HE = imageLoad(image, coords);&#xA;    float r = HE.w;&#xA;    float Hydx = imageLoad(image, coords+ivec2(1, 0)).y&#xA;                -HE.y;&#xA;    float Hxdy = imageLoad(image, coords+ivec2(0, 1)).x&#xA;                -HE.x;&#xA;&#xA;    float Eout = dt*(Hydx-Hxdy)/(e);&#xA;   HE.z = HE.z*(1-dt*r/e) + Eout;&#xA;&#xA;// add source at image center&#xA;   if(coords.x == image_size.x/2 &amp;amp;&amp;amp; coords.y == image_size.y/2) &#xA;    {&#xA;        HE.z += 30*sin(15*t)*exp(-20*(t-2)*(t-2));&#xA;    }&#xA;&#xA;   imageStore(image, coords, HE);&#xA;   FragColor = vec4(HE.z, HE.w, -HE.z, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;CMakeLists.txt (in root of project)&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cmake_minimum_required(VERSION 3.15)&#xA;&#xA;# Define the project.&#xA;project(hello-opengl&#xA;    LANGUAGES C CXX)&#xA;&#xA;&#xA;## 2. Targets&#xA;## ==========&#xA;add_subdirectory(src)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;CMakeLists.txt (in src)&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;cmake_minimum_required(VERSION 3.15)&#xA;&#xA;# package dependencies&#xA;find_package(CMakeshift 3.5 REQUIRED)&#xA;find_package(glfw3 3.3.2 REQUIRED)&#xA;find_package(glm REQUIRED)&#xA;find_package(OpenGL 4.2 REQUIRED)&#xA;&#xA;#add glad library&#xA;add_library(glad &amp;quot;../include/glad/glad.h&amp;quot; &amp;quot;glad.c&amp;quot;)&#xA;target_include_directories(glad PUBLIC &amp;quot;../include&amp;quot;)&#xA;&#xA;# target&#xA;add_executable(hello-opengl&#xA;    &amp;quot;main.cpp&amp;quot;)&#xA;&#xA;# include directory&#xA;target_include_directories(hello-opengl PRIVATE &amp;quot;../include&amp;quot;)&#xA;&#xA;# properties&#xA;target_compile_features(hello-opengl&#xA;    PRIVATE&#xA;        cxx_std_20)&#xA;&#xA;# compiler settings&#xA;include(CMakeshift/TargetCompileSettings)&#xA;cmakeshift_target_compile_settings(hello-opengl&#xA;    PRIVATE&#xA;        default)&#xA;&#xA;# target dependencies&#xA;target_link_libraries(hello-opengl&#xA;    PRIVATE&#xA;        OpenGL::GL&#xA;        glad&#xA;        glfw&#xA;        glm)&#xA;&#xA;# installation&#xA;install(&#xA;    TARGETS hello-opengl)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;To the file structure.&lt;/p&gt;&#xA;&lt;p&gt;On Windows all files are in the same directory.&lt;/p&gt;&#xA;&lt;p&gt;On Ubuntu:&lt;/p&gt;&#xA;&lt;p&gt;CMakeLists.txt&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;inlcude -- shader.h, glad, KHR&lt;/li&gt;&#xA;&lt;li&gt;shaders -- sourcer.vert, source1.frag, source2.frag&lt;/li&gt;&#xA;&lt;li&gt;src     -- CMakeLists.txt, main.cpp&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="11598" LastActivityDate="2020-11-04T10:16:52.430" Title="Different OpenGL behaviour on Windows and Ubuntu" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10370" PostTypeId="2" ParentId="10366" CreationDate="2020-11-04T11:42:53.337" Score="1" Body="&lt;p&gt;It sounds like you yet have to adjust the importance function of the Markov Chain according to the way you assign paths to each of the two estimators, path tracing and ERPT.&lt;/p&gt;&#xA;&lt;p&gt;If you think about it in the framework of MIS, you have two estimators with binary weights (according to your threshold). Now, the simplest (but inefficient) option to combine them would be to always run ERPT and path tracing for all paths, applying the weight to the splats only (this weighting is what I understand you do by separating them into different framebuffers).&lt;/p&gt;&#xA;&lt;p&gt;In your case, however, you only enter the ERPT chain for the paths that you want to further explore, therefore you do not actually enter the chain in a stationary distribution proportional to the measurement contribution. This breaks ERPT, as the startup bias removal no longer works correctly. To fix it, you need to additionally account for your path selection strategy in the importance function such that it matches the initial distribution of paths entering ERPT: The MIS weight of the ERPT estimator needs to become a part of its targeted distribution, preventing energy from running off into paths that would never actually trigger an ERPT run. Thus, you should be able to make the startup bias removal work with your path selection strategy.&lt;/p&gt;&#xA;" OwnerUserId="15175" LastActivityDate="2020-11-04T11:42:53.337" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10371" PostTypeId="2" ParentId="10348" CreationDate="2020-11-04T20:37:14.003" Score="1" Body="&lt;p&gt;First, regarding the specific problem of bits of the geometry being lost to the near and far planes, this can be solved by using &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Vertex_Post-Processing#Depth_clamping&quot; rel=&quot;nofollow noreferrer&quot;&gt;depth clamping&lt;/a&gt; instead of depth clipping. This disables clipping against the near and far planes, in favor of clamping the output depth values to [0, 1]. (Geometry behind the camera will still be clipped though.) Given this, instead of a fullscreen quad you could render the light volume with inverted culling, depth testing inverted (to cull pixels behind the volume), and use depth clamping to prevent losing parts of the volume to the far clip plane.&lt;/p&gt;&#xA;&lt;p&gt;(Depth clamping is also handy for shadow maps, as it lets you contract the shadow map depth bounds to bracket the view frustum, without losing geometry between the view frustum and the light source.)&lt;/p&gt;&#xA;&lt;p&gt;In a broader sense, though, this doesn't really solve the problem of shading pixels within a given convex volume. The problem is that you need two depth tests: front of volume &amp;lt; pixel depth &amp;lt; back of volume. The approaches discussed so far can only do one of these tests at a time. You can switch which one you're doing by swapping culling and depth-testing modes, but you can't do both at once, which leaves performance on the table.&lt;/p&gt;&#xA;&lt;p&gt;One approach to address this is to &lt;a href=&quot;https://kayru.org/articles/deferred-stencil/&quot; rel=&quot;nofollow noreferrer&quot;&gt;use the stencil buffer in concert with depth testing&lt;/a&gt;. Basically this works by testing scene depth against the front of the light volume first, storing that to the stencil buffer, then doing a second pass that tests scene depth against the back of the light volume, and combining that with the stencil result from the first pass. This has the advantage of getting tight culling (no pixels shaded outside the volume), but you need to draw each light volume twice, plus making a lot of state changes to switch back and forth, which can be inefficient for both CPU and GPU (though you can batch up to 8 lights together using 1 stencil bit per light).&lt;/p&gt;&#xA;&lt;p&gt;Finally, using &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_depth_bounds_test.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;EXT_depth_bounds_test&lt;/a&gt;, if available, can be a good solution. This enables a form of depth test that checks whether the pixel already in the framebuffer (not the geometry being rasterized) is within a certain range. With this, you set the depth bounds to the min/max depth of your light volume, then draw the geometry with inverted culling, no depth test, and depth clamping enabled. This will shade all pixels within a sort of prism aligned with the view frustum, that bounds the actual volume reasonably tightly in most cases (though long narrow spotlights can be bad), and it does it in only one pass. However, this extension isn't universally available; it seems to be found on current NVIDIA and AMD GPUs, but not Intel ones (see &lt;a href=&quot;http://opengl.gpuinfo.org/listreports.php?extension=GL_EXT_depth_bounds_test&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenGL Hardware Database&lt;/a&gt;).&lt;/p&gt;&#xA;&lt;p&gt;All of this difficulty is one reason that most game engines since the early 2010s have switched to &lt;a href=&quot;https://johanmedestrom.wordpress.com/2016/03/30/tiled-deferred-shading-in-opengl-using-compute-shaders/&quot; rel=&quot;nofollow noreferrer&quot;&gt;compute-shader tiled culling&lt;/a&gt; instead of using the rasterizer to decide which lights to shade at which pixel.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-11-04T20:37:14.003" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10372" PostTypeId="1" CreationDate="2020-11-05T15:05:37.820" Score="0" ViewCount="48" Body="&lt;p&gt;According to &lt;a href=&quot;https://en.wikipedia.org/wiki/Phong_reflection_model&quot; rel=&quot;nofollow noreferrer&quot;&gt;Phong's reflection model&lt;/a&gt;, there are different reflection constants (&lt;strong&gt;k&lt;/strong&gt;) and different intensities of the light source (&lt;strong&gt;i&lt;/strong&gt;) for ambient, diffuse, and specular terms:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$I_p=k_ai_a+\sum_{m \in lights} \left(k_d(\hat{L}_m \cdot \hat{N})i_{m,d} + k_s(\hat{R}_m \cdot \hat{V})^\alpha i_{m,s} \right)$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;I had some questions about this model:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;When a pixel is under shadow (umbra), does the equation become this way:&#xA;&lt;span class=&quot;math-container&quot;&gt;$I_p=k_ai_a$&lt;/span&gt; ?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Suppose we only have one major light source. So the equation can be something like this: &lt;span class=&quot;math-container&quot;&gt;$I_p \approx k_ai_a+ k_d(\hat{L} \cdot \hat{N})i_{d} + k_s(\hat{R} \cdot \hat{V})^\alpha i_{s} $&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Can the ambient portion of pixels (&lt;span class=&quot;math-container&quot;&gt;$k_ai_a$&lt;/span&gt;) become larger than the rest (even with no specular reflection)?&lt;/p&gt;&#xA;&lt;p&gt;Basically, can this happen: &lt;span class=&quot;math-container&quot;&gt;$k_ai_a \stackrel{?}{\geq} k_d(\hat{L} \cdot \hat{N})i_{d}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Is there any relationship between &lt;span class=&quot;math-container&quot;&gt;$k_a, k_d, k_s$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$i_a, i_d, i_s$&lt;/span&gt; of one point in a scene?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="15183" LastActivityDate="2020-11-05T15:05:37.820" Title="Can ambient light reflection of a surface be larger than diffuse reflection?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;pixels&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="10374" PostTypeId="1" AcceptedAnswerId="10376" CreationDate="2020-11-06T09:26:05.077" Score="1" ViewCount="101" Body="&lt;p&gt;What is a good algorithm for rendering a particle system as a coherent mesh, in realtime? I am running a smoothed-particle hydrodynamics fluid simulation, and I would like to render the particles not as balls but as a body of water.&lt;/p&gt;&#xA;&lt;p&gt;I understand that the basis is to find all places where the combined density of the particle system is equal to a certain boundary value, which will yield a surface which is smooth. However, how do you actually do so quickly and translate it into vertices and triangles to render?&lt;/p&gt;&#xA;&lt;p&gt;Another option is raytracing, raymarching specifically. Just march until the density reaches the boundary value. However, I'm still stuck on how to get the surface normal in this case, as well as how to make it performant. Surely you don't need to iterate through all particles, the far away particles won't have any effect, but I don't know how to spatially cull particles.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;What are some algorithms for spatially culling far away particles with no local contribution?&lt;/li&gt;&#xA;&lt;li&gt;What are some algorithms for getting the surface normal of a body of water made of particles?&lt;/li&gt;&#xA;&lt;li&gt;What are some algorithms for getting the surface of a body of water made of particles, in the form of a mesh?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2020-11-10T19:22:29.533" Title="Rendering a particle system as a smooth blob" Tags="&lt;rasterizer&gt;&lt;raymarching&gt;&lt;particles&gt;&lt;fluid-sim&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10376" PostTypeId="2" ParentId="10374" CreationDate="2020-11-07T04:51:15.923" Score="3" Body="&lt;p&gt;For culling faraway particles: as lightxbulb said, the keyword to search for is &amp;quot;acceleration structure&amp;quot;. There are a variety of options: BVH, octree, kd-tree, uniform grid, or some combination of these. Which one will be most suitable is going to depend on the details of your situation—how large/dense is the simulation, how much you care about performance vs memory vs implementation complexity, and so on.&lt;/p&gt;&#xA;&lt;p&gt;They all work by subdividing space into volumes in some fashion and keeping track of which particles are in each volume. Then, when you're marching you only need to keep track of which volume you're in, and that will tell you which particles can potentially contribute to the density at that point. For instance if it's a uniform grid, you only need to look at the current cell and possibly some of its immediate neighbors if they're within the maximum particle radius of your current point.&lt;/p&gt;&#xA;&lt;p&gt;Getting a smoothed mesh with surface normals etc. is usually done by defining a density field for the particle system. This is a function on 3D space that consists of summing up a falloff function for each particle over a defined radius:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;D(\vec r) = \sum_{i \in \text{particles}} f \left(\frac{|\vec r - \vec r_i|}{R_i} \right)&#xA;$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$f(u)$&lt;/span&gt; is some function that falls off smoothly from &lt;span class=&quot;math-container&quot;&gt;$f(0) = 1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$f(1) = 0$&lt;/span&gt; (for example, a simple cubic falloff: &lt;span class=&quot;math-container&quot;&gt;$f(u) = 1 - 3u^2 + 2u^3$&lt;/span&gt;), and &lt;span class=&quot;math-container&quot;&gt;$\vec r_i, R_i$&lt;/span&gt; are the position and radius of the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th particle. Then you set some threshold density value and let the surface be defined by all the points where &lt;span class=&quot;math-container&quot;&gt;$D(\vec r) = \text{threshold}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For getting the surface normal: the surface normal is just the (normalized) gradient vector of the density field. This can be calculated by finite differences between nearby points in the field:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;\nabla D(\vec r) &amp;amp;= \left( \frac{\partial D}{\partial x}, \frac{\partial D}{\partial y}, \frac{\partial D}{\partial z} \right) \\&#xA;&amp;amp;\approx \frac{1}{\epsilon} \left( D(\vec r + \epsilon \vec x) - D(\vec r), D(\vec r + \epsilon \vec y) - D(\vec r), D(\vec r + \epsilon \vec z) - D(\vec r) \right)&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&#xA;or analytically by adding up gradient contributions from each particle.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;\nabla D(\vec r) &amp;amp;= \sum_i \nabla \left( f \left(\frac{|\vec r - \vec r_i|}{R_i} \right) \right) \\&#xA;&amp;amp;= \sum_i \text{normalize}(\vec r - \vec r_i) \frac{1}{R_i} \frac{df}{du}&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;For getting the surface in the form of a mesh: the keyword to search for is &amp;quot;isosurface extraction&amp;quot;. Marching cubes is one example of such an algorithm, as lightxbulb mentioned. It evaluates the density field at evenly spaced grid points, uses those values to estimate where the intersection of the surface with the cubes' edges will be, and constructs from that a tiny mesh within each cube. Stitching all those meshes together yields a representation of the full surface. Naturally, the accuracy of it depends on the size of the grid used.&lt;/p&gt;&#xA;&lt;p&gt;There is also a variant that uses tetahedra instead of cubes, and another similar algorithm called &amp;quot;dual contouring&amp;quot;. &lt;a href=&quot;https://wordsandbuttons.online/interactive_explanation_of_marching_cubes_and_dual_contouring.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here's a nice article&lt;/a&gt; showing how these work interactively (in 2D). There's also a great deal of literature on how to improve accuracy, performance, etc. with these kinds of methods.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-11-10T19:22:29.533" LastActivityDate="2020-11-10T19:22:29.533" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="10377" PostTypeId="1" CreationDate="2020-11-08T07:22:56.420" Score="0" ViewCount="29" Body="&lt;p&gt;I am wondering about techniques for rendering a rotated and or scaled raster image. Currently I use the following algorithm&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render everything at double resolution and store the result in &lt;code&gt;A&lt;/code&gt;&lt;/li&gt;&#xA;&lt;li&gt;For each pixel in output image, assign it the value of the average of the four pixels in &lt;code&gt;A&lt;/code&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;img(col, row) = 0.25f * (tmp(2 * col, 2 * row) + tmp(2 * col + 1, 2 * row) + tmp(2 * col, 2 * row + 1) + tmp(2 * col + 1, 2 * row + 1));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Current sampler looks like this:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;            auto const loc_ret = vec2_t{static_cast&amp;lt;double&amp;gt;(col), static_cast&amp;lt;double&amp;gt;(row)};&#xA;            auto const src_pos =&#xA;                scale_factor * transform(loc_ret - loc_src_ret_coord, rot_x, rot_y) + origin_src;&#xA;            if(src_pos[0] &amp;gt;= 0 &amp;amp;&amp;amp; src_pos[0] &amp;lt; src.width() &amp;amp;&amp;amp; src_pos[1] &amp;gt;= 0&#xA;               &amp;amp;&amp;amp; src_pos[1] &amp;lt; src.height())&#xA;            {&#xA;                auto const src_pixel =&#xA;                    src(static_cast&amp;lt;uint32_t&amp;gt;(src_pos[0]), static_cast&amp;lt;uint32_t&amp;gt;(src_pos[1]));&#xA;                auto&amp;amp; ret_pixel =&#xA;                    ret((col + ret.width()) % ret.width(), (row + ret.height()) % ret.height());&#xA;                ret_pixel = blend(ret_pixel, src_pixel, opacity);&#xA;            }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;where&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;auto const scale_factor = 1.0 / (scale * layer.scaleFactor());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and scale is the scale used to down-sample the image once completed.&lt;/p&gt;&#xA;&lt;p&gt;The algorithm works for rotated and down-scaled sources, however, it has no effect when the source is upscaled.&lt;/p&gt;&#xA;" OwnerUserId="15191" LastEditorUserId="15191" LastEditDate="2020-11-08T07:49:34.347" LastActivityDate="2020-11-08T07:49:34.347" Title="How to render a rotated raster image with lesser aliasing" Tags="&lt;image-processing&gt;&lt;raster-image&gt;&lt;supersampling&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10378" PostTypeId="1" CreationDate="2020-11-08T13:51:35.277" Score="2" ViewCount="207" Body="&lt;p&gt;I'm practicing GLSL on ShaderToy&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void mainImage( out vec4 fragColor, in vec2 fragCoord ) {&#xA;&#xA;vec2 coord = fragCoord.xy/iResolution.xy;&#xA;&#xA;vec3 background = vec3(1.);&#xA;&#xA;vec3 axesColor = vec3(1.,0.,0.);&#xA;vec3 gridColor = vec3(0.85);&#xA;&#xA;vec3 color = background;&#xA;&#xA;const float tickWidth = 0.1;&#xA;for(float i = 0.0 ; i &amp;lt; 1.0 ; i += tickWidth)&#xA;{&#xA;    if(abs(coord.x - i) &amp;lt; 0.002) color = gridColor;&#xA;    if(abs(coord.y - i) &amp;lt; 0.002) color = gridColor;&#xA;}&#xA;&#xA;if(abs(coord.x) &amp;lt; 0.005) color = axesColor;&#xA;**if(abs(coord.y) &amp;lt; 0.005) color = axesColor;**&#xA;**//color = abs(coord.y) &amp;lt; 0.005 ? axesColor : background;**&#xA;&#xA;fragColor = vec4(color,1.0);  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;my question is on last 3 lines.&lt;/p&gt;&#xA;&lt;p&gt;First, I used ternary operator for branch, but it made weird result that only drawing &amp;quot;x axes&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;However, when I changed the operator to if, it works well. The code drew x, y axes and all grids as I wanted.&lt;/p&gt;&#xA;&lt;p&gt;So I wonder is there different between if and ternary operation in GLSL?&#xA;If that, how can I choose correctly?&lt;/p&gt;&#xA;" OwnerUserId="15196" LastActivityDate="2021-04-07T16:00:10.443" Title="Is there different between 'if' and 'ternary operator' in GLSL?" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10379" PostTypeId="2" ParentId="10378" CreationDate="2020-11-08T15:00:21.450" Score="0" Body="&lt;p&gt;The difference is obvious. The ternary operator &lt;em&gt;will&lt;/em&gt; return one of the two alternative values it is given; that's what it is for. An &lt;code&gt;if&lt;/code&gt; condition that doesn't have an &lt;code&gt;else&lt;/code&gt; block won't do anything if the condition is false.&lt;/p&gt;&#xA;&lt;p&gt;The ternary operator version &lt;em&gt;will set&lt;/em&gt; &lt;code&gt;color&lt;/code&gt; to &lt;code&gt;axesColor&lt;/code&gt; or &lt;code&gt;background&lt;/code&gt;. But by that point in your code, you've gone past 3 other conditions that may have changed the value of &lt;code&gt;color&lt;/code&gt; from its initial value of &lt;code&gt;background&lt;/code&gt;. But the ternary operator doesn't care. It will &lt;em&gt;overwrite&lt;/em&gt; whatever is in &lt;code&gt;color&lt;/code&gt; with either &lt;code&gt;axesColor&lt;/code&gt; or &lt;code&gt;background&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;What you probably wanted was &lt;code&gt;color = abs(coord.y) &amp;lt; 0.005 ? axesColor : color;&lt;/code&gt;, so that the value will be preserved if the condition is false.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-11-08T15:00:21.450" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10380" PostTypeId="1" CreationDate="2020-11-08T16:50:35.797" Score="0" ViewCount="30" Body="&lt;p&gt;Cross posting from stack overflow:&lt;/p&gt;&#xA;&lt;p&gt;Reading the source code of tinygltf I see this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Skin {&#xA;  std::string name;&#xA;  int inverseBindMatrices;  // required here but not in the spec&#xA;  int skeleton;             // The index of the node used as a skeleton root&#xA;  std::vector&amp;lt;int&amp;gt; joints;  // Indices of skeleton nodes&#xA;&#xA;  Value extras;&#xA;  ExtensionMap extensions;&#xA;&#xA;  // Filled when SetStoreOriginalJSONForExtrasAndExtensions is enabled.&#xA;  std::string extras_json_string;&#xA;  std::string extensions_json_string;&#xA;&#xA;  Skin() {&#xA;    inverseBindMatrices = -1;&#xA;    skeleton = -1;&#xA;  }&#xA;  DEFAULT_METHODS(Skin)&#xA;  bool operator==(const Skin &amp;amp;) const;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;That would made you assume that the skeleton value is mandatory. However, on the gltf simple skin example json, I see the following:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;  &amp;quot;skins&amp;quot; : [ {&#xA;    &amp;quot;inverseBindMatrices&amp;quot; : 4,&#xA;    &amp;quot;joints&amp;quot; : [ 1, 2 ]&#xA;  } ],&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;That's the full extent of the &lt;code&gt;skins&lt;/code&gt; array. So it seems it is perfectly possible for a skin not to specify which one is the root node of its skeleton. In that case, which node in the joints array should I treat at the parent? Can I safely assume it is the first element of the &lt;code&gt;joints&lt;/code&gt; list?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-11-08T16:50:35.797" Title="What do you do when the root skeleton is not defined in a gltf file?" Tags="&lt;c++&gt;&lt;animation&gt;&lt;gltf&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10382" PostTypeId="1" CreationDate="2020-11-09T17:16:41.163" Score="2" ViewCount="74" Body="&lt;p&gt;I have been working on recreating some of the scenes from Peter Shirley's raytracing books using compute shaders and the new Metal raytracing API.  It is going well but I am having some trouble with the glass material.&lt;/p&gt;&#xA;&lt;p&gt;I've read Pete's blog post on this - &lt;a href=&quot;http://psgraphics.blogspot.com/2020/04/deugging-refraction-in-sphre.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://psgraphics.blogspot.com/2020/04/deugging-refraction-in-sphre.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But I am still unsure as to what is the cause of the issue that you can see in the pictures I have attached.&lt;a href=&quot;https://i.stack.imgur.com/y1H8E.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/y1H8E.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The glass appears grainy and you get an effect similar to z-fighting when you move the camera around.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/K7cVN.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/K7cVN.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is the code for the glass material:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;else if (instances.materials[instanceIndex] == glass)&#xA;{&#xA;    bool front_face = dot(normalize(ray.direction), worldSpaceSurfaceNormal) &amp;lt; 0.0 ? true : false;&#xA;            &#xA;    float kEtaRatio = front_face ? kEtaAir / kEtaGlass&#xA;                                 : kEtaGlass / kEtaAir;&#xA;          &#xA;    ray.origin = worldSpaceIntersectionPoint;&#xA;    ray.direction = refract(normalize(ray.direction), worldSpaceSurfaceNormal, kEtaRatio);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I have implemented all the code for the full material with Schlick approximation etc, however it appears that it is this first step shown here that is causing the issue.&lt;/p&gt;&#xA;&lt;p&gt;I am only using one sample per pixel at the moment but I'm unsure why that would only cause problems with the glass and not the other materials?&lt;/p&gt;&#xA;&lt;p&gt;Any advice would be greatly appreciated.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/syI0w.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/syI0w.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="14003" LastActivityDate="2020-11-10T20:35:13.820" Title="Debugging refraction in a sphere" Tags="&lt;raytracing&gt;&lt;refraction&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10384" PostTypeId="1" CreationDate="2020-11-10T19:13:09.650" Score="0" ViewCount="107" Body="&lt;p&gt;I have a CT scan of a portion of a human body, with each point describing density. The data file provides X, Y, Z, and density values.  I want to know how to visualize this data, using OpenGL or a library based on OpenGL.&lt;/p&gt;&#xA;" OwnerUserId="10178" LastActivityDate="2021-05-11T08:08:20.840" Title="How to visualize density data as volume using OpenGL?" Tags="&lt;volume-rendering&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10385" PostTypeId="2" ParentId="10384" CreationDate="2020-11-10T20:01:33.613" Score="0" Body="&lt;p&gt;What you're looking for is &amp;quot;volumetric rendering&amp;quot;, here is one resource with code that takes data in the form of images of the layers:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.codeproject.com/articles/352270/getting-started-with-volume-rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;Getting started with Volume Rendering using OpenGL&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;A quick hack would be to use a grid of particles/&amp;quot;billboards&amp;quot;, and make them transparent based on the density.&lt;/p&gt;&#xA;" OwnerUserId="10615" LastEditorUserId="10615" LastEditDate="2020-11-12T00:06:24.287" LastActivityDate="2020-11-12T00:06:24.287" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10386" PostTypeId="2" ParentId="10382" CreationDate="2020-11-10T20:18:43.787" Score="1" Body="&lt;p&gt;You need to make use of a discriminant, also when dealing with floating point comparisons it is wise to use an epsilon (small value for accommodating fp-error).&lt;/p&gt;&#xA;&lt;p&gt;Also keep in mind that it matters whether the surface normal is pointing along the ray, or against it.&lt;/p&gt;&#xA;&lt;p&gt;Below is a function which I use in my own raytracer, also based on the same book. It is written in C and refracts a given vector3. You would assign the return value to your &lt;code&gt;ray.direction&lt;/code&gt; in your case.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;// vector*vector means dot product here&#xA;&#xA;#define EPSILON = 0.000001f&#xA;&#xA;static inline vec3 refract(&#xA;    vec3 dir, // direction of incoming light ray&#xA;    vec3 n, // surface normal of refracting surface, pointing outwards (so roughly in the against the direction of light ray)&#xA;    float ni_over_nt // refractive indices fraction&#xA;){&#xA;    float dt = dir*n; // dot prod.&#xA;    float discriminant = 1.f - ni_over_nt*ni_over_nt*(1.f-dt*dt);&#xA;    if (discriminant &amp;gt; EPSILON){&#xA;        return (dir - n*dt)*ni_over_nt - n*sqrtf(discriminant);&#xA;    } else {&#xA;        // total internal reflection&#xA;        // reflect the direction against the surface normal&#xA;        return reflect(direction, normal);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Usage of the function is as follows:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;if (direction*normal) &amp;gt; EPSILON) // dot prod. of ray dir. and surf. normal&#xA;{&#xA;    // ray is entering the object&#xA;    nOut = -normal; &#xA;    ni_over_nt = mat-&amp;gt;IOR; // surface material index of refraction.&#xA;} else {&#xA;    // ray is exiting the object&#xA;    nOut = normal;&#xA;    ni_over_nt = 1.f/mat-&amp;gt;IOR;&#xA;}&#xA;&#xA;vec3 refracted = refract(direction, nOut, ni_over_nt);&#xA;// this is your refracted ray direction&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Added bonus: reflection function used in the refraction:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;static inline vec3 reflect3(vec3 v, vec3 n){&#xA;    // reflect a vector v off of a plane with normal n&#xA;    return  v -n*2*(v*n); //v*n = dot prod.&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10615" LastEditorUserId="10615" LastEditDate="2020-11-10T20:35:13.820" LastActivityDate="2020-11-10T20:35:13.820" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10387" PostTypeId="1" AcceptedAnswerId="10388" CreationDate="2020-11-11T01:04:52.393" Score="2" ViewCount="132" Body="&lt;p&gt;Using deep learning to estimate surface normals from monocular RGB images is a common task. The resulting image generally looks like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/StN14.jpg&quot; alt=&quot;RBG to surface normal map&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;My question is how can I use this map to actually draw a normal vector (arrow) for any given point on the image? For example, I want to draw a line on the countertop that points up.&lt;/p&gt;&#xA;&lt;p&gt;Most relevant tidbit I found on the topic: &amp;quot;The RGB color channels (red, green, and blue) in a normal map correspond to the respective X, Y, and Z coordinates of surface normals.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;But I don't get what this means. The values are standard RGB, i.e., for each coordinate, you get three numbers in range [0, 255]. Just by how color changes between surfaces, it is clearly related to normals (obviously) but when I tried quiver plots using matlab I couldn't get reasonable results.&lt;/p&gt;&#xA;&lt;p&gt;TLDR: What is the relation between surface normal maps and actual normal vectors? How can I draw a 3d line given a point on the image which represents the normal vector perpendicular to that surface at that point?&lt;/p&gt;&#xA;" OwnerUserId="15206" LastActivityDate="2020-11-11T05:11:26.547" Title="How to draw surface normals from surface normal maps?" Tags="&lt;normal-mapping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10388" PostTypeId="2" ParentId="10387" CreationDate="2020-11-11T05:11:26.547" Score="2" Body="&lt;p&gt;Typically the normal vector, which has XYZ components in [−1, 1] is linearly mapped to the RGB range [0, 255]. You can retrieve the normal vector by reversing this mapping.&lt;/p&gt;&#xA;&lt;p&gt;For completeness, the encoding is:&lt;br /&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;r = \text{round}((0.5x + 0.5) \cdot 255) \\&#xA;g = \text{round}((0.5y + 0.5) \cdot 255) \\&#xA;b = \text{round}((0.5z + 0.5) \cdot 255)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Decoding is:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;x = (r/255) \cdot 2 - 1 \\&#xA;y = (g/255) \cdot 2 - 1 \\&#xA;z = (b/255) \cdot 2 - 1&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-11-11T05:11:26.547" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10390" PostTypeId="1" AcceptedAnswerId="10392" CreationDate="2020-11-11T22:22:08.903" Score="0" ViewCount="33" Body="&lt;p&gt;I have made a program that samples uniformly an environment map and computes the lighting using the GGX BRDF.&lt;/p&gt;&#xA;&lt;p&gt;I have made a small example that reproduces the issue I'm having. You can check it out online: &lt;a href=&quot;https://shorturl.at/tvzGY&quot; rel=&quot;nofollow noreferrer&quot;&gt;shorturl.at/tvzGY&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The algorithm works as follows:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;We compute &lt;code&gt;V&lt;/code&gt;, the unit vector that points from the surface to the camera. &lt;code&gt;FPosition&lt;/code&gt; is the position of the fragment in camera space so we can use that to compute &lt;code&gt;V&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;We will take a few sample directions &lt;code&gt;L&lt;/code&gt; in uniform random directions. These samples are taken inside a hemisphere in the direction of the normal &lt;code&gt;N&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;In the real program, we would use &lt;code&gt;L&lt;/code&gt; to sample the environment map but, for simplicity, in the provided example, I'm just assuming a complitely white environment (the issue happens anyways).&lt;/li&gt;&#xA;&lt;li&gt;For each of these samples we compute the rendering equation with the GGX BRDF, and we accumulate that into a variable.&lt;/li&gt;&#xA;&lt;li&gt;And finally we divide by the number of samples.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I'm using the formulas for GGX I found in this site: &lt;a href=&quot;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The problem I'm having is that it doesn't look right. If you open the link you will see this.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/czf1m.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/czf1m.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;That's with roughness = 0.1, metallic = 1.0, and numSamples = 10.&lt;/p&gt;&#xA;&lt;p&gt;In the top right corner, switch to the sphere. And you will see this.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/72sZr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/72sZr.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;You see those bright spots, the number of them correlates with the number of samples. That could make sense, maybe. But when I increment the number of samples to 100, we get this.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3a96c.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3a96c.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;There are more spots but they are also smaller and blurrier. I think I must be doing something wrong because it doesn't look like a metal. Or is it just because of the uniform sampling? Even with 1000 samples per pixel it doesn't look right to me.&lt;/p&gt;&#xA;" OwnerUserId="6172" LastEditorUserId="6172" LastEditDate="2020-11-11T22:29:04.727" LastActivityDate="2020-11-11T23:10:13.870" Title="Problem sampling uniformly envmap with GGX" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;lighting&gt;&lt;ggx&gt;&lt;ibl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10391" PostTypeId="1" CreationDate="2020-11-11T23:03:58.377" Score="0" ViewCount="23" Body="&lt;p&gt;I'm decoding an &lt;code&gt;.mp4&lt;/code&gt; to use as a texture on a tristrip. It's easy enough to use an unsigned byte array of RGB triplets to create this texture, but frames come out of an &lt;code&gt;.mp4&lt;/code&gt; as three separate buffers. One for each channel. In other words, instead of having &lt;code&gt;uint8_t * buf = {RGBRGBRGBRGB.....}&lt;/code&gt;, I have &lt;code&gt;uint8_t * r_buf = {RRRRR....}; uint8_t * g_buf = {GGGGG....}; uint8_t * b_buf = {BBBBBB....};&lt;/code&gt; Can I pack all of this into one texture so my fragment shader just treats it the same as it did the current texture? I don't have any great objection to having three separate 1-channel textures that I mix in the shader, but that'll ugly up my shader code a bit.&lt;/p&gt;&#xA;" OwnerUserId="9779" LastActivityDate="2020-11-11T23:03:58.377" Title="Packing a GL_RGB from three separate buffers?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10392" PostTypeId="2" ParentId="10390" CreationDate="2020-11-11T23:10:13.870" Score="2" Body="&lt;p&gt;How are you randomizing the samples you take? It looks to me like maybe the random values are the same across all pixels in the image, which would explain why you see 10 coherent bright spots when you have 10 samples.&lt;/p&gt;&#xA;&lt;p&gt;The samples should be re-randomized for each pixel. This should produce a noisy result, with a single blurred-out bright spot instead of 10 (or however many) coherent bright spots.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-11-11T23:10:13.870" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10393" PostTypeId="1" CreationDate="2020-11-12T14:40:48.913" Score="0" ViewCount="24" Body="&lt;p&gt;I want to implement good path guiding for photons for my Vertex Merging integrator.&lt;br /&gt;&lt;/p&gt;&#xA;&lt;p&gt;After reading through this 2 papers:  &lt;br /&gt;&#xA;&lt;strong&gt;Hachisuka T., Jensen H. W.:&lt;/strong&gt;  &lt;a href=&quot;https://www.ci.i.u-tokyo.ac.jp/%7Ehachisuka/amcmcppm.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.ci.i.u-tokyo.ac.jp/~hachisuka/amcmcppm.pdf&lt;/a&gt;&lt;br /&gt;&#xA;&lt;strong&gt;Zheng Q., Zheng C.:&lt;/strong&gt; &lt;a href=&quot;https://quan-zheng.github.io/publication/VIAPT-preprint.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://quan-zheng.github.io/publication/VIAPT-preprint.pdf&lt;/a&gt;&#xA;&lt;br /&gt;&#xA;I've implemented metropolis sampling with the target function being only the visibility function(based on the first paper). However, I don't quite understand how to update large step probability when it isn't always &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; as in the second paper (I'm trying to sample paths based on the distance from the camera). In the paper this formula is used:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ q = 0, {s &amp;gt;1}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ q = 1 - e^{-s*n}, {s &amp;lt;1}$$&lt;/span&gt;&#xA;where &lt;span class=&quot;math-container&quot;&gt;$s = \frac{M(P^{}_{i})}{M(P^{}_{i-1})} $&lt;/span&gt; is the ratio between contribution of the current path and the last path&#xA;&lt;br /&gt;&#xA;and  &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is the consecutive times for generating new paths using small mutation.&lt;/p&gt;&#xA;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; is small and less than 1, it means that the mutation wasn't successful and resulted in smaller contribution, but when &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; decreases, large step probability also decreases, which doesn't seem intuitive for me. If we can't find mutation with higher contribution, we should abandon this state and exchange with uniform distribution - we should increase large step mutation.&#xA;&lt;br /&gt;&lt;/p&gt;&#xA;&lt;p&gt;Should I use &lt;span class=&quot;math-container&quot;&gt;$s = \frac{M(P^{}_{i})}{M(P^{}_{i-1})} $&lt;/span&gt; or  &lt;span class=&quot;math-container&quot;&gt;$s = \frac{M(P^{}_{i-1})}{M(P^{}_{i})}$&lt;/span&gt; and is this correct at all - how to change the formula then?&#xA;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="13943" LastActivityDate="2020-11-12T14:40:48.913" Title="How to update large step probability when exchanging states in Metropolis Sampler?" Tags="&lt;pathtracing&gt;&lt;sampling&gt;&lt;importance-sampling&gt;&lt;photon-mapping&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10394" PostTypeId="1" AcceptedAnswerId="10395" CreationDate="2020-11-13T19:43:26.313" Score="0" ViewCount="147" Body="&lt;p&gt;I have a &lt;code&gt;rgba16f&lt;/code&gt; texture that I fill with values using nvidia &lt;code&gt;GL_NV_shader_atomic_fp16_vector&lt;/code&gt; extension, which allows to perform &lt;code&gt;imageAtomicAdd&lt;/code&gt; on half float RGBA images, with multiple shader threads using same &lt;code&gt;index&lt;/code&gt;. However, it doesn't support &lt;code&gt;rgba32f&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Can I use &lt;code&gt;imageLoad&lt;/code&gt;/&lt;code&gt;imageStore&lt;/code&gt; to perform same thing with such image buffer as written below?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec4 prevVal = imageLoad(tex, index);&#xA;prevVal += currVal;&#xA;imageStore(tex, index, prevVal);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm not sure how correctly set the coherency of such operations with correct barriers usage because I have not found any example. Or if it is even possible.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2020-11-13T19:52:12.087" LastActivityDate="2020-11-19T17:07:35.663" Title="Using imageLoad/imageStore to perform atomic add" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;compute-shader&gt;&lt;image-load-store&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10395" PostTypeId="2" ParentId="10394" CreationDate="2020-11-13T22:24:25.237" Score="2" Body="&lt;p&gt;If you could use &lt;code&gt;imageLoad/Store&lt;/code&gt; to do atomic operations, there would be no need for atomic operations as a distinct class of operations. So no, you can't. There is no correct set of barriers or other properties that will allow this to work generally the way atomic operations do.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-11-13T22:24:25.237" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10396" PostTypeId="1" AcceptedAnswerId="10405" CreationDate="2020-11-14T17:58:59.407" Score="1" ViewCount="108" Body="&lt;p&gt;While studying &lt;a href=&quot;https://github.com/RayTracing/raytracing.github.io&quot; rel=&quot;nofollow noreferrer&quot;&gt;Peter Shirley's Ray Tracing:The Next Week&lt;/a&gt;, I came across an issue that I cannot quite figure out:&lt;/p&gt;&#xA;&lt;p&gt;Stepping through the &lt;code&gt;random_scene()&lt;/code&gt; case of the code, found out that once a leaf of the BVH tree is reached, the aabb of the object is checked for a hit; even when the object is a sphere.&lt;/p&gt;&#xA;&lt;p&gt;The check for a hit against the &lt;code&gt;bounding_box&lt;/code&gt; of a sphere (aabb) is necessary but not sufficient; there are parts of the &lt;code&gt;bounding_box&lt;/code&gt; which is not a part of a sphere.&lt;/p&gt;&#xA;&lt;p&gt;Shouldn't it invoke the specific &lt;code&gt;hit()&lt;/code&gt; function of the object when the leaf is reached?&lt;/p&gt;&#xA;&lt;p&gt;Yet the code works somehow.&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2020-11-16T08:53:49.303" Title="BVH uses aabb for a sphere in Ray Tracing: The Next Week" Tags="&lt;raytracing&gt;&lt;debugging&gt;&lt;bounding-volume-hierarchy&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10399" PostTypeId="1" AcceptedAnswerId="10402" CreationDate="2020-11-15T00:29:57.883" Score="0" ViewCount="301" Body="&lt;p&gt;I used a version of the following code to draw a triangle using glDrawArrays with GL_TRIANGLES, per Anton Gerdelan's very nice tutorial here:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://antongerdelan.net/opengl/hellotriangle.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hello Triangle !&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It draws a nice triangle.&lt;/p&gt;&#xA;&lt;p&gt;I have modified the code as explained in the code comments below, attempting to use glDrawArrays with GL_TRIANGLES to draw two triangles, making a square, as suggested in the section &amp;quot;Experimenting&amp;quot; on the webpage, but it still just gives the same triangle, even though I added 3 more vertices to the triangle_vertices array, doubled the size of the data in the glBufferData command, and replaced glDrawArrays(GL_TRIANGLES, 0, 3) by glDrawArrays(GL_TRIANGLES, 0, 6).&lt;/p&gt;&#xA;&lt;p&gt;Why is that ?&lt;/p&gt;&#xA;&lt;p&gt;By using GL_TRIANGLE_FAN I have succeeded in drawing the square I want (actually a rectangle because of the aspect ratio), but I would like to be able to get the same result using GL_TRIANGLES. I also don't want to use any alternative to glDrawArrays, even though I know that options are available that allow clever re-use of vertex data, when distinct triangles share common vertices.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#define GLEW_STATIC&#xA;#include &amp;quot;GL/glew.h&amp;quot;&#xA;#define GLFW_DLL&#xA;#include &amp;quot;GLFW/glfw3.h&amp;quot;&#xA;#include &amp;lt;stdio.h&amp;gt;&#xA;&#xA;&#xA;int main()&#xA;{&#xA;    printf(&amp;quot;Hello world !\n&amp;quot;);&#xA;&#xA;    GLFWwindow* window;&#xA;&#xA;    /* Initialize the library */&#xA;    if (!glfwInit())&#xA;    {&#xA;        return -1;&#xA;    }&#xA;&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);&#xA;    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);&#xA;    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);&#xA;    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);&#xA;&#xA;&#xA;    /* Create a windowed mode window and its OpenGL context */&#xA;    window = glfwCreateWindow(2048, 1536, &amp;quot;Hello !&amp;quot;, NULL, NULL);&#xA;    if (!window)&#xA;    {&#xA;        glfwTerminate();&#xA;        return -1;&#xA;    }&#xA;&#xA;    /* Make the window's context current */&#xA;    glewExperimental = GL_TRUE;&#xA;    glfwMakeContextCurrent(window);&#xA;&#xA;    GLenum ret = glewInit();&#xA;    if (GLEW_OK != ret)&#xA;    {&#xA;        // Problem: glewInit failed, something is seriously wrong.&#xA;        fprintf(stderr, &amp;quot;Error: %s\n&amp;quot;, glewGetErrorString(ret));&#xA;        return 1;&#xA;    }&#xA;&#xA;    // One triangle:&#xA;    //float triangle_vertices[] = {&#xA;    //-0.5f, 0.5f, 0.0f, // top left point&#xA;    //0.5f, 0.5f, 0.0f, // top right point&#xA;    //0.5f, -0.5f, 0.0f, // bottom right point&#xA;    //};&#xA;&#xA;    // Two triangles:&#xA;    float triangle_vertices[] = {&#xA;    -0.5f, 0.5f, 0.0f, // top left point&#xA;    0.5f, 0.5f, 0.0f, // top right point&#xA;    0.5f, -0.5f, 0.0f, // bottom right point&#xA;    0.5f, -0.5f, 0.0f, // bottom right point&#xA;    -0.5f, -0.5f, 0.0f // bottom left point&#xA;    -0.5f, 0.5f, 0.0f, // top left point&#xA;    };&#xA;&#xA;    GLuint vertex_buffer_object = 0; // VBO&#xA;    glGenBuffers(1, &amp;amp;vertex_buffer_object);&#xA;    {&#xA;        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_object);&#xA;&#xA;        //glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 3, triangle_vertices, GL_STATIC_DRAW);&#xA;        // The previous command was for drawing a triangle, while the following one is intended for &#xA;        // drawing a square, although it doesn't yet work !&#xA;        glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * 6, triangle_vertices, GL_STATIC_DRAW);&#xA;&#xA;        glBindBuffer(GL_ARRAY_BUFFER, 0); // unbind&#xA;    }&#xA;&#xA;    GLuint vertex_array_object = 0;&#xA;    glGenVertexArrays(1, &amp;amp;vertex_array_object);&#xA;    {&#xA;        glBindVertexArray(vertex_array_object);&#xA;&#xA;        glEnableVertexAttribArray(0); // enable the first input variable (vertex position)&#xA;        glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_object);&#xA;        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);&#xA;        glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;        glBindVertexArray(0);&#xA;    }&#xA;&#xA;&#xA;    GLuint shader_program_object = 0;&#xA;    { // SHADERS&#xA;&#xA;        const char* vertex_shader_str =&#xA;            &amp;quot;#version 410\n&amp;quot;&#xA;            &amp;quot;in vec3 a_position;\n&amp;quot;&#xA;            &amp;quot;void main() {\n&amp;quot;&#xA;            &amp;quot;gl_Position = vec4(a_position, 1.0);\n&amp;quot;&#xA;            &amp;quot;}&amp;quot;;&#xA;&#xA;        const char* fragment_shader_str =&#xA;            &amp;quot;#version 410\n&amp;quot;&#xA;            &amp;quot;out vec4 o_frag_colour;\n&amp;quot;&#xA;            &amp;quot;void main() {\n&amp;quot;&#xA;            &amp;quot;o_frag_colour = vec4(0.5, 0.0, 0.5, 1.0);\n&amp;quot;&#xA;            &amp;quot;}\n&amp;quot;;&#xA;&#xA;        GLuint vertex_shader_object = glCreateShader(GL_VERTEX_SHADER);&#xA;        glShaderSource(vertex_shader_object, 1, &amp;amp;vertex_shader_str, NULL);&#xA;        glCompileShader(vertex_shader_object);&#xA;&#xA;        GLuint fragment_shader_object = glCreateShader(GL_FRAGMENT_SHADER);&#xA;        glShaderSource(fragment_shader_object, 1, &amp;amp;fragment_shader_str, NULL);&#xA;        glCompileShader(fragment_shader_object);&#xA;&#xA;        shader_program_object = glCreateProgram();&#xA;        glBindAttribLocation(shader_program_object, 0, &amp;quot;a_position&amp;quot;);&#xA;&#xA;        glAttachShader(shader_program_object, vertex_shader_object);&#xA;        glAttachShader(shader_program_object, fragment_shader_object);&#xA;        glLinkProgram(shader_program_object);&#xA;&#xA;    }&#xA;&#xA;    glClearColor(0.2f, 0.2f, 0.2f, 1.0f);&#xA;&#xA;    while (!glfwWindowShouldClose(window))&#xA;    {&#xA;        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;&#xA;        glUseProgram(shader_program_object);&#xA;        {&#xA;            glBindVertexArray(vertex_array_object);&#xA;            {&#xA;                //glDrawArrays(GL_TRIANGLES, 0, 3);&#xA;                glDrawArrays(GL_TRIANGLES, 0, 6);&#xA;            }&#xA;            glBindVertexArray(0);&#xA;        }&#xA;        glUseProgram(0);&#xA;&#xA;        glfwPollEvents();&#xA;        glfwSwapBuffers(window);&#xA;    }&#xA;&#xA;    glfwTerminate();&#xA;    return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11224" LastEditorUserId="11224" LastEditDate="2020-11-15T14:17:43.623" LastActivityDate="2020-11-15T20:10:49.443" Title="Drawing a square using glDrawArrays with GL_TRIANGLES" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;polygon&gt;&lt;drawing&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10402" PostTypeId="2" ParentId="10399" CreationDate="2020-11-15T20:10:49.443" Score="0" Body="&lt;p&gt;Doh !!! It was simply a typo ! A missing comma at the end of the line&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;-0.5f, -0.5f, 0.0f // bottom left point&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What a relief !&lt;/p&gt;&#xA;" OwnerUserId="11224" LastActivityDate="2020-11-15T20:10:49.443" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10403" PostTypeId="1" CreationDate="2020-11-16T04:06:04.950" Score="0" ViewCount="38" Body="&lt;p&gt;Excuse my wording. I will use the picture below to explain what I mean. I want to use the surface normals for each arrow shown like below to draw lines parallel to each plane like the image shown below the first one. Therefore I want to obtain point coordinates given in black dots.&lt;/p&gt;&#xA;&lt;p&gt;Assuming I have a unit normal (u, v, w) to each plane, how can this be accomplished?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gNw3x.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gNw3x.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4zPy7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4zPy7.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15206" LastActivityDate="2020-11-16T04:06:04.950" Title="Can surface normal be used for obtaining points on a plane?" Tags="&lt;projections&gt;" AnswerCount="0" CommentCount="8" ContentLicense="CC BY-SA 4.0" />
  <row Id="10404" PostTypeId="1" AcceptedAnswerId="10409" CreationDate="2020-11-16T07:00:34.733" Score="0" ViewCount="67" Body="&lt;p&gt;I have a few short question regarding operations happening in the rendering pipeline (OpenGL, Vulkan, I'd expect for all questions to have similar answers for these two frameworks while DirectX might work a bit different).&lt;/p&gt;&#xA;&lt;p&gt;Is the division of the coordinates &lt;code&gt;x/w&lt;/code&gt;,&lt;code&gt;y/w&lt;/code&gt;,&lt;code&gt;z/w&lt;/code&gt; the last operation that happens on the GPU? Or are there other operations that happen afterwards? I wasn't really able to find any information on that, could anyone point me into the right direction?&lt;/p&gt;&#xA;&lt;p&gt;Furthermore, concerning the depth of fragments, as far as I understand a quantization takes place to discrete units of depth, but I couldn't find anything detailed if these operations follow some kind of IEEE standard or if they have their own standards, maybe even depending on the manufacturer. Does anyone know more detail about this or could point me into the right direction?&lt;/p&gt;&#xA;&lt;p&gt;In general are there some, more or less, complete information about the possible operations (besides of course programmable operations during the programmable shader stages), the error bounds, etc. for operations on the GPU?&lt;/p&gt;&#xA;&lt;p&gt;Kind regards and thank you in advance.&lt;/p&gt;&#xA;" OwnerUserId="8757" LastActivityDate="2020-11-16T12:59:34.500" Title="Operations in the Rendering Pipeline" Tags="&lt;opengl&gt;&lt;gpu&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10405" PostTypeId="2" ParentId="10396" CreationDate="2020-11-16T07:21:39.847" Score="1" Body="&lt;p&gt;It does indeed do exactly what you described. Have a close look at how the bvh is constructed, it is a passed a list of concrete shapes that implement &lt;code&gt;hittable&lt;/code&gt;, e.g. &lt;code&gt;xy_rect&lt;/code&gt;, &lt;code&gt;sphere&lt;/code&gt;, etc. The base cases for the recursive bvh construction create leaf nodes that directly reference the concrete shapes that make up the scene.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;bvh_node::bvh_node(&#xA;    const std::vector&amp;lt;shared_ptr&amp;lt;hittable&amp;gt;&amp;gt;&amp;amp; src_objects,&#xA;    size_t start, size_t end, double time0, double time1&#xA;) {&#xA;    auto objects = src_objects; // Create a modifiable array of the source scene objects&#xA;    ...&#xA;    size_t object_span = end - start;&#xA;&#xA;    // **create leaf nodes, concrete shapes referenced here**&#xA;    if (object_span == 1) {&#xA;        left = right = objects[start]; &#xA;    } else if (object_span == 2) {&#xA;        if (comparator(objects[start], objects[start+1])) {&#xA;            left = objects[start];&#xA;            right = objects[start+1];&#xA;        } else {&#xA;            left = objects[start+1];&#xA;            right = objects[start];&#xA;        }&#xA;    } else {&#xA;       // create internal bvh_node&#xA;       ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When &lt;code&gt;bvh_node::hit&lt;/code&gt; is called and the ray/aabb test passes, the left and right child nodes have their hit functions called recursively. Eventually when this recursion bottoms out the concrete shapes referenced by the leaf nodes will have their hit functions called as you would expect.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;bool bvh_node::hit(const ray&amp;amp; r, double t_min, double t_max, hit_record&amp;amp; rec) const {&#xA;    if (!box.hit(r, t_min, t_max))&#xA;        return false;&#xA;&#xA;    bool hit_left = left-&amp;gt;hit(r, t_min, t_max, rec);&#xA;    bool hit_right = right-&amp;gt;hit(r, t_min, hit_left ? rec.t : t_max, rec);&#xA;&#xA;    return hit_left || hit_right;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10642" LastActivityDate="2020-11-16T07:21:39.847" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10406" PostTypeId="2" ParentId="10396" CreationDate="2020-11-16T08:53:49.303" Score="1" Body="&lt;p&gt;I agree with &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10405/10615&quot;&gt;@xasp's answer&lt;/a&gt;, but to understand &lt;em&gt;why&lt;/em&gt; you would do it like that:&lt;/p&gt;&#xA;&lt;p&gt;Checking for ray-circle intersections is not the most expensive in terms of cpu-time required, but a ray-aabb intersection is frighteningly faster. Apparently Shirley found that in his scenes, checking the leaf's AABB first led to better results, because in a &amp;quot;sparse bounding volume tree&amp;quot;, you might recurse down to a leaf node, but still not hit it.&lt;/p&gt;&#xA;&lt;p&gt;So why is the AABB faster than a sphere intersection? Well for spheres in 3d you need to square 3 numbers (will be compiled to a single vector instruction most likely) and you need to then take the square root, which is a traditionally expensive operation. See this answer: &lt;a href=&quot;https://stackoverflow.com/a/12304868/11359454&quot;&gt;https://stackoverflow.com/a/12304868/11359454&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In AABB intersection you just need to do some larger/smaller than checks and divide your rays x y and z components to get the inverse (single vector divide instruction).&lt;/p&gt;&#xA;&lt;p&gt;Infamously in quake, to get faster lighting, an approximation hack was used to get a fast root-ish. Nowadays that hack is actually slower than a call to &lt;code&gt;sqrtf&lt;/code&gt;, because the floating point parts of processors have gotten faster and more advanced.&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2020-11-16T08:53:49.303" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10407" PostTypeId="2" ParentId="9549" CreationDate="2020-11-16T10:37:57.023" Score="0" Body="&lt;p&gt;I  think you can make a graph of the entire surface and have your algorithm &amp;quot;walk&amp;quot; over it. Your planes would be hugging the surface but it would be the shortest. You could fix the hugging by a local upward translation on the plane.&lt;/p&gt;&#xA;&lt;p&gt;If you have a weird maze-like structure, you might want to &amp;quot;cross the gaps&amp;quot;, so you need to adapt the algorithm to be able to cross air gaps, you could do this by just iterating all triangles and connecting them to all other triangles (thus creating a graph). Of course, you can't pass through the walls, so you need to take into account the surface normals. If you construct the lines between two surfaces, and you compare the surface normals to the direction of that line, it can tell you whether you are going through the surface (forbidden) or away from it (crossing air gaps). If the 2 surfaces are direct neighbors you don't need to do the line-normal check, and you can assume your algorithm can walk from one triangle to the other.&lt;/p&gt;&#xA;&lt;p&gt;Most 3d model files reuse the same vertices for multiple triangles so it's easy to check whether they are neighbors: just check if they have vertices in common.&lt;/p&gt;&#xA;&lt;p&gt;Once you have constructed the final graph, you can just use a pathfinding algorithm to find the shortest path to traverse the graph.&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2020-11-16T10:37:57.023" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10408" PostTypeId="2" ParentId="10362" CreationDate="2020-11-16T10:43:08.873" Score="0" Body="&lt;p&gt;I think you need to call &lt;code&gt;setFromMatrixPosition(m)&lt;/code&gt; again after updating the matrix. After all, you need to update both the position and matrix, not just the matrix.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;mesh.position.setFromMatrixPosition(mesh.matrix)&lt;/code&gt; or &lt;code&gt;mesh.position = new THREE.Vector3().setFromMatrixPosition(mesh.matrix)&lt;/code&gt; right after &lt;code&gt;mesh.updateMatrix()&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="10615" LastActivityDate="2020-11-16T10:43:08.873" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10409" PostTypeId="2" ParentId="10404" CreationDate="2020-11-16T12:59:34.500" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Is the division of the coordinates x/w,y/w,z/w the last operation that happens on the GPU?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The division you are referring to is generally called &amp;quot;The Perspective Divide&amp;quot;. You can google it and get information overload on helpful documentation. The division itself happens after the geometry shader before the fragment shader as part of rasterization. And is part of the process that creates the fragments that the pixel shader is run on. It is also an important part of vertex attribute interpolation. All of OpenGL, Vulkan, DirectX perform the perspective divide in the same place which is done by the GPU's hardware.&lt;/p&gt;&#xA;&lt;p&gt;The most adopted floating point standard is IEEE 754 and yes virtually all vendors implement and follow these standards. I highly recommend (slowly) wrapping your mind around this standard to get a deeper understanding of how floats are processed. Here is a good first factoid to memorize (if you want): The standard put the sign bit for floating point numbers in the same place as the sign bit for integers to make conversion between and understanding both easier.&lt;/p&gt;&#xA;&lt;p&gt;Quantization in this context refers to the accuracy of floating point numbers. There are many numbers that can not be fully represented in floating point math on the GPU, such as 1/3. Quantization is the process of representing that number as closely as possible within the limitations of the hardware. But minor difference in hardware implementations that are still standards compliant can and often will produce slightly different results.&lt;/p&gt;&#xA;&lt;p&gt;Rather then focus on the limits of floating point numbers or attempting to write code that operates at the edge of these limits, coders generally use techniques that avoid the issue altogether like utilizing hardware offset capabilities to side step the issue completely is one method. (but is situation specific, like when applying decals)&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2020-11-16T12:59:34.500" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10411" PostTypeId="1" AcceptedAnswerId="10419" CreationDate="2020-11-16T18:17:26.647" Score="1" ViewCount="85" Body="&lt;p&gt;I want to render the transient shadows due to the sunlight over a day in one image. So I placed all the suns, as directional light, in the scene. However the shadows in the rendered image(a raytraced image) are too bright and so they look very much faded(below image). This is understandable as there is just too much light from all those suns.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/76tcL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/76tcL.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Basically I am trying to achieve an image similar to the below one, where all shadows are distinguishable and not that soft. However I cannot think of any way to achieve this. I appreciate anyone's help.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UivIy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UivIy.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2020-11-18T14:52:52.673" Title="Too soft shadows from multiple suns" Tags="&lt;shadow&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10412" PostTypeId="1" CreationDate="2020-11-16T19:22:06.620" Score="0" ViewCount="21" Body="&lt;p&gt;As noted &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glPointSize.xml#notes&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, when rendering using the GL_POINTS primitive, there is an implementation dependent limit to the point size range.&lt;/p&gt;&#xA;&lt;p&gt;I intend to use GL_POINTS for fast billboard rendering of particles, so I am dependent on the point size range to be sufficiently large to visualize perspective scaling.&lt;/p&gt;&#xA;&lt;p&gt;I would consider for example the range provided by my graphics card (1-255), to be sufficient, since usually, particles are not close enough to the camera to exceed 255 pixels in diameter.&lt;/p&gt;&#xA;&lt;p&gt;Are there any commonly used graphics cards that do not provide such a large range of points sizes?&lt;/p&gt;&#xA;&lt;p&gt;Are there any (reasonably modern) graphics cards that do not allow for points larger than one pixel at all?&lt;/p&gt;&#xA;" OwnerUserId="15232" LastActivityDate="2020-11-16T19:22:06.620" Title="What sort of implementation dependent limits for glPointSize can one expect from modern graphics cards?" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10413" PostTypeId="1" CreationDate="2020-11-16T20:28:03.970" Score="0" ViewCount="44" Body="&lt;p&gt;I'm trying to create a camera using matrix transforms, the gist as follows:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Transform =&#xA;                Matrix.CreateRotationZ(Rotation) *&#xA;                 Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *&#xA;                Matrix.CreateScale(Zoom) *&#xA;                Matrix.CreateTranslation(new Vector3(Bounds.Width * 0.5f, Bounds.Height * 0.5f, 0));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;It works but with one issue. The rotation origin remains at the starting (-Position.X, -Position.Y) while the zoom works fine (at the center screen) which is obvious from the code. I'd like the rotation to occur at the center screen as well.&lt;/p&gt;&#xA;" OwnerUserId="15233" LastActivityDate="2020-11-16T20:28:03.970" Title="Matrix transforming with translation/rotation/scale at center of screen" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10415" PostTypeId="1" CreationDate="2020-11-17T13:19:01.110" Score="0" ViewCount="56" Body="&lt;p&gt;I wrote a C program &lt;a href=&quot;https://github.com/albert10jp/c_learning/blob/main/heart_star_animation.c&quot; rel=&quot;nofollow noreferrer&quot;&gt;which prints a heartbeat (heart star) animation&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The key is to print a heart of stars, which looks like this&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9CzFS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9CzFS.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;consists of line of stars and blanks.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    * * * *           * * * * &#xA;  * * * * * *       * * * * * * &#xA;* * * * * * * *   * * * * * * * * &#xA;* * * * * * * * * * * * * * * * * &#xA;  * * * * * * * * * * * * * * * &#xA;    * * * * * * * * * * * * * &#xA;      * * * * * * * * * * * &#xA;        * * * * * * * * * &#xA;          * * * * * * * &#xA;            * * * * * &#xA;              * * * &#xA;                * &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Is there an existing method to make it more like a heart? For example, how many lines should I use to draw the top half of the heart shape?&lt;/p&gt;&#xA;&lt;p&gt;By &amp;quot;more like&amp;quot;, I mean more roundish, like this&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9iu35.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9iu35.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;and this&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YPbHx.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YPbHx.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15238" LastEditorUserId="15238" LastEditDate="2020-11-18T13:44:28.557" LastActivityDate="2020-11-18T13:44:28.557" Title="Is there an existing method to draw a heart of stars that looks more like a heart?" Tags="&lt;2d&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10416" PostTypeId="2" ParentId="10394" CreationDate="2020-11-17T21:13:36.903" Score="0" Body="&lt;p&gt;Instead of using compute shader with atomic operations, I used instanced draw call with additive blending.&#xA;In compute shader I had X as destination texels and Y as different sample directions for each texel. Now in instanced screen quad draw each instance is sample direction added to output texture.&lt;/p&gt;&#xA;" OwnerUserId="4958" LastEditorUserId="4958" LastEditDate="2020-11-19T17:07:35.663" LastActivityDate="2020-11-19T17:07:35.663" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10417" PostTypeId="1" CreationDate="2020-11-17T22:41:57.033" Score="3" ViewCount="92" Body="&lt;p&gt;I'm making a program that illuminates a sphere using an environment map. For each fragment in the sphere, I compute a many random directions in the hemisphere along the surface normal (no importance sampling), and then sample the environment map. Then I evaluate the GGX BRDF for each sample.&lt;/p&gt;&#xA;&lt;p&gt;The problem I have is that it looks too dark, and I'm not sure why.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Nxoy9.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Nxoy9.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is for a metallic sphere with low roughness. For such a low roughness, it could make sense that the GGX lobe is so narrow that we are missing it. But things don't improve with higher roughness.&lt;/p&gt;&#xA;&lt;p&gt;When I increase the roughness it goes completely dark:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5FxOI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5FxOI.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;If I multiply the resulting color by 10 I can tell there is something:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ynC7W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ynC7W.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is my main shader function:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 bruteForce()&#xA;{&#xA;    vec3 N = normalize(v_normal);&#xA;    vec3 V = normalize(u_camPos - v_pos);&#xA;    float NoV = max(0.0001, dot(N, V));&#xA;&#xA;    vec3 F0 = mix(vec3(0.04), u_albedo, u_metallic);&#xA;    vec3 F = fresnelSchlick(NoV, F0);&#xA;    vec3 k_spec = F;&#xA;    vec3 k_diff = (1 - k_spec) * (1 - u_metallic);&#xA;&#xA;    vec3 specular = vec3(0.0, 0.0, 0.0);&#xA;    for(uint iSample = 0u; iSample &amp;lt; u_numSamples; iSample++)&#xA;    {&#xA;        uvec3 seedUInt = pcg_uvec3_uvec3(uvec3(gl_FragCoord.x, gl_FragCoord.y, iSample));&#xA;        vec2 seed2 = vec2(makeFloat01(seedUInt.x), makeFloat01(seedUInt.y));&#xA;        vec3 L = uniformSample(seed2, N);&#xA;        vec3 H = normalize(V + L);&#xA;        vec3 env = texture(u_envTex, L).rgb;&#xA;&#xA;        float NoL = max(0.0001, dot(N, L));&#xA;        float NoH = max(0.0001, dot(N, H));&#xA;        float NoH2 = NoH * NoH;&#xA;        float rough4 = u_rough2*u_rough2;&#xA;        float q = NoH2 * (rough4 - 1.0) + 1.0;&#xA;        float D = rough4 / (PI * q*q);&#xA;        float G = ggx_G_smith(NoV, NoL, u_rough2);&#xA;        vec3 fr = F * G * D / (4 * NoV * NoL);&#xA;        specular += fr * env * NoL;&#xA;    }&#xA;    specular /= float(u_numSamples);&#xA;&#xA;    return specular;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here are the other helper functions:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 fresnelSchlick(float NoV, vec3 F0)&#xA;{&#xA;    return F0 + (1.0 - F0) * pow(1.0 - NoV, 5.0);&#xA;}&#xA;&#xA;float ggx_G(float NoV, float rough2)&#xA;{&#xA;  float rough4 = rough2 * rough2;&#xA;  return 2.0 * (NoV) /&#xA;    (NoV + sqrt(rough4 + (1.0 - rough4) * NoV*NoV));&#xA;}&#xA;&#xA;// geometry term&#xA;float ggx_G_smith(float NoV, float NoL, float rough2)&#xA;{&#xA;  return ggx_G(NoV, rough2) * ggx_G(NoL, rough2);&#xA;}&#xA;&#xA;// this is a hash function for generating pseudo-random numbers. Taken from here: http://jcgt.org/published/0009/03/02/&#xA;uvec3 pcg_uvec3_uvec3(uvec3 v)&#xA;{&#xA;    v = v * 1664525u + 1013904223u;&#xA;    v.x += v.y*v.z;&#xA;    v.y += v.z*v.x;&#xA;    v.z += v.x*v.y;&#xA;    v = v ^ (v&amp;gt;&amp;gt;16u);&#xA;    v.x += v.y*v.z;&#xA;    v.y += v.z*v.x;&#xA;    v.z += v.x*v.y;&#xA;    return v;&#xA;}&#xA;&#xA;// Construct a float with half-open range [0:1] using low 23 bits.&#xA;// All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.&#xA;// https://stackoverflow.com/a/17479300/1754322&#xA;float makeFloat01( uint m ) {&#xA;    const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask&#xA;    const uint ieeeOne      = 0x3F800000u; // 1.0 in IEEE binary32&#xA;&#xA;    m &amp;amp;= ieeeMantissa;                     // Keep only mantissa bits (fractional part)&#xA;    m |= ieeeOne;                          // Add fractional part to 1.0&#xA;&#xA;    float  f = uintBitsToFloat( m );       // Range [1:2]&#xA;    return f - 1.0;                        // Range [0:1]&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Can you help me find the problem please?&lt;/p&gt;&#xA;" OwnerUserId="6172" LastActivityDate="2020-11-23T16:25:06.210" Title="IBL looks too dark with uniform sampling" Tags="&lt;glsl&gt;&lt;lighting&gt;&lt;brdf&gt;&lt;ggx&gt;" AnswerCount="0" CommentCount="6" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10418" PostTypeId="2" ParentId="10309" CreationDate="2020-11-17T23:31:19.647" Score="1" Body="&lt;p&gt;I'm not familiar with the exact nuances of the STL format, but here are some answers on general computer graphics principles:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;In the source file, the Vertex Normals are specified and in the destination, the face normal of the triangles are present which are different than the normals one would get by (a-b) x (a-c), where a, b, c are the vertex coordinates and x is the cross product. How one would compute the face normal in the presence of vertex normals?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;There is no general method to convert vertex normals to face normals. Vertex normals (that are not all equal) can express the normals &lt;em&gt;of a curved surface&lt;/em&gt;, which face normals cannot. Thus, converting to a format with only a normal vector per face, rather than per triangle vertex, is a &lt;em&gt;lossy&lt;/em&gt; process — some information was discarded. The converter must make a compromise.&lt;/p&gt;&#xA;&lt;p&gt;That said, from some quick research, it seems that the intent of the STL file format is that the normal &lt;em&gt;is&lt;/em&gt; the normal perpendicular to the triangle (that can be computed as you specified), not a chosen vector, even though that makes it redundant. So perhaps your converter is wrong (though I can't say much as you didn't say &lt;em&gt;how&lt;/em&gt; it was different).&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Also, I am given to understand that STL format has a positive octant rule which requires all vertex coordinates to be positive. When the OBJ file has negative vertex coordinates, what should be done in the conversion process?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The only option is to choose some offset by which to translate all of the vertices so that they are positive. This also loses some information — what the origin of the original model was. That's easier to recover if needed, though, since it's just a 3D vector that you could translate back by when loading the model.&lt;/p&gt;&#xA;" OwnerUserId="445" LastActivityDate="2020-11-17T23:31:19.647" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10419" PostTypeId="2" ParentId="10411" CreationDate="2020-11-18T00:35:11.983" Score="2" Body="&lt;p&gt;The problem is that if you have 8 light sources (as your test image appears to have), then anything that is under only one shadow will be 7/8ths of full brightness, which is a fairly small change. Anything other than that is &lt;em&gt;unphysical&lt;/em&gt;, so it'll be hard to convince your raytracer to produce a different result by changing the lighting.&lt;/p&gt;&#xA;&lt;p&gt;Instead, after rendering the image, you can apply some kind of &lt;strong&gt;nonlinear&lt;/strong&gt; processing of the image colors so that that 1/8th difference stands out more. In your second image, this seems to have been done by directly replacing the light gray fully-lit areas with white, but a more proportionate, yet still very visible, result could be achieved with a simple &amp;quot;levels&amp;quot; color edit applied to the whole image to increase contrast, as I've done for this version of your first image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5dj8o.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5dj8o.png&quot; alt=&quot;Levels edit&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;By pushing light gray to white, and darker grays more to black, the contrast in the image is greatly increased. The cost is that the building shapes are dark and hard to see.&lt;/p&gt;&#xA;&lt;p&gt;To make the buildings look better and stand out, you could render your buildings a second time without any ground (so the resulting image has a transparent background), then layer that on top of the color-edited image, so that they are unaffected by the contrast adjustment.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RwjlZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RwjlZ.png&quot; alt=&quot;Levels edit with original buildings overlaid&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It might be a good idea to use color to help distinguish the buildings from the shadows. In particular, I'd suggest avoiding making buildings &lt;em&gt;gray&lt;/em&gt; (or, more generally, colored the same as the sunlight). Here I've used a &amp;quot;color temperature&amp;quot; edit on the above to make the buildings layer bluer and the shadowed ground layer yellower (probably too much):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/98ESc.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/98ESc.png&quot; alt=&quot;Color temperature edit&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Of course, this is all rough examples based on quickly editing your sample image; I think you can produce very legible and elegant results by taking these ideas and doing them better (by being able to adjust your raytracer lighting &lt;em&gt;as well as&lt;/em&gt; postprocessing the image, and rendering a separate buildings-without-ground image as I suggested).&lt;/p&gt;&#xA;" OwnerUserId="445" LastEditorUserId="445" LastEditDate="2020-11-18T14:52:52.673" LastActivityDate="2020-11-18T14:52:52.673" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10420" PostTypeId="2" ParentId="8456" CreationDate="2020-11-18T12:42:51.337" Score="2" Body="&lt;p&gt;Usual reprojection finds UV of current visible point into previous frame. For diffuse and rough objects it simply adds motion vector: &lt;code&gt;vec2 UV_reprojected = UV + motion;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;But for mirror-like surfaces it doesn't work, because we see not object (mirror) itself but what reflects in mirror (virtual object). The general idea to reproject reflected point is:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Find world space position for reflected point visible in reflector (Here we need to know reflected path length).&lt;/li&gt;&#xA;&lt;li&gt;Substract world space delta between frames, so we found previous world position.&lt;/li&gt;&#xA;&lt;li&gt;Project this point into reflector using previous camera position.&lt;/li&gt;&#xA;&lt;li&gt;Project world space reflector point back to the screen.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The most hardest part is p.3, and is not easy analytically find this point, because reflector can change normal. Some interesting links about this topic:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://bitsquid.blogspot.com/2017/06/reprojecting-reflections_22.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Reflection reprojection in Uncharted&lt;/a&gt;. Here we assume that reflector is plane that changes transform, both camera and receiver are also dynamic.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://link.springer.com/content/pdf/10.1007%2F978-1-4842-4427-2_32.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ray Tracing Gems chapter 32&lt;/a&gt;. (32.4.3) Theoretical approach that finds reflector position in terms of least squares. And interesting geometrical optic approach (here we assume that reflector point is locally sphere-like).&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9903" LastEditorUserId="9903" LastEditDate="2020-11-19T14:08:21.353" LastActivityDate="2020-11-19T14:08:21.353" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10422" PostTypeId="1" CreationDate="2020-11-21T17:34:28.840" Score="0" ViewCount="43" Body="&lt;p&gt;I have a class that handles loading buffers for a mesh:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;class A {&#xA;   GLuint vao, vbo, ebo;&#xA;&#xA;   A() {&#xA;      glGenVertexArrays(1, &amp;amp;vao);&#xA;      glGenBuffers(1, &amp;amp;vbo);&#xA;      glGenBuffers(1, &amp;amp;ebo);&#xA;        &#xA;      LoadBuffers();&#xA;      LoadAttributes();&#xA;   }&#xA;&#xA;   ~A() {&#xA;     DeallocateBuffers();&#xA;   }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When an object of that class is destructed I would like to free the memory allocated by the buffers. I can't figure out how do this correctly. This is what I tried but it doesn't seem to be correct.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void DeallocateBuffers() {&#xA;    glDeleteVertexArrays(1,&amp;amp;vao);&#xA;    glDeleteBuffers(1,&amp;amp;ebo);&#xA;    glDeleteBuffers(1,&amp;amp;vao);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-11-21T17:34:28.840" Title="How to deallocate memory for vertex buffer objects" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;vertex-buffer-object&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10423" PostTypeId="1" AcceptedAnswerId="10456" CreationDate="2020-11-22T08:49:06.830" Score="1" ViewCount="126" Body="&lt;p&gt;I am extending &lt;a href=&quot;https://github.com/rogerallen/raytracinginoneweekendincuda&quot; rel=&quot;nofollow noreferrer&quot;&gt;Roger Allen's Ray Tracing in One Weekend in CUDA&lt;/a&gt; (and also &lt;a href=&quot;https://developer.nvidia.com/blog/accelerated-ray-tracing-cuda/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;) by following &lt;a href=&quot;https://raytracing.github.io/books/RayTracingTheNextWeek.html#imagetexturemapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;Peter Shirley's Ray Tracing: The Next Week&lt;/a&gt;; specifically Image Texture Mapping.&lt;/p&gt;&#xA;&lt;p&gt;The image I obtain from CUDA is not as sharp as the CPU version. Shirley's book uses &lt;code&gt;double&lt;/code&gt; and Allen restricts to &lt;code&gt;float&lt;/code&gt; but could that be the only reason?&lt;/p&gt;&#xA;&lt;p&gt;The texture source for both is a 24 bit depth jpeg file.&lt;/p&gt;&#xA;&lt;p&gt;In both cases 100x sampling per pixel used for antialiasing.&lt;/p&gt;&#xA;&lt;p&gt;Is there anything to be done in the kernel to improve the image quality?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    class imageTextureX :public textureX {&#xA;public:&#xA;    __device__ imageTextureX(uint32_t width, uint32_t height, cudaTextureObject_t textureObject) :_width(width), _height(height), _textureObj(textureObject) {}&#xA;    __forceinline__ __device__  vec3 value(float u, float v, const vec3&amp;amp; p) const override {&#xA;        //Flip Y-Coordinate;&#xA;        v = 1.0f - v;&#xA;        //De-normalize coordinate(s)&#xA;        uint32_t X = u * _width;&#xA;        //Re-normalize&#xA;        constexpr float pixelOffset{ 0.5f };&#xA;        const float denominator = 1.0f / (float)(3 * _width);&#xA;        u = (float)(3 * X + pixelOffset);&#xA;&#xA;        vec3 colorVal;&#xA;        colorVal.e[0] = (float)tex2D&amp;lt;uint8_t&amp;gt;(_textureObj, u++ * denominator, v);&#xA;        colorVal.e[1] = (float)tex2D&amp;lt;uint8_t&amp;gt;(_textureObj, u++ * denominator, v);&#xA;        colorVal.e[2] = (float)tex2D&amp;lt;uint8_t&amp;gt;(_textureObj, u * denominator, v);&#xA;        return colorVal / 255.0f;&#xA;    }&#xA;private:&#xA;    cudaTextureObject_t _textureObj;&#xA;    uint32_t _width;&#xA;    uint32_t _height;&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Texture definition code&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;//Load Texture Image from Disk&#xA;    cudaArray* cuArray;&#xA;    cudaTextureObject_t textureObject;&#xA;    int32_t textureWidth, textureHeight;&#xA;    {&#xA;        Timer tim(&amp;quot;Prepare Image Texture&amp;quot;);&#xA;        const static uint32_t bytesPerPixel{ 3u };&#xA;        uint8_t* pHostData;&#xA;        uint32_t bytesPerScanline;&#xA;        cudaChannelFormatDesc channelFormatDesc;&#xA;        cudaResourceDesc  resourceDesc{};&#xA;        cudaTextureDesc textureDesc{};&#xA;        int32_t componentsPerPixel = bytesPerPixel;&#xA;        pHostData = stbi_load(textureFilename.c_str(), &amp;amp;textureWidth, &amp;amp;textureHeight, &amp;amp;componentsPerPixel, componentsPerPixel);&#xA;        if (nullptr == pHostData) {&#xA;            std::cerr &amp;lt;&amp;lt; &amp;quot;ERROR: Could not load texture image file '&amp;quot; &amp;lt;&amp;lt; textureFilename &amp;lt;&amp;lt; std::endl;&#xA;            return;&#xA;        }&#xA;        bytesPerScanline = bytesPerPixel * textureWidth;&#xA;&#xA;        channelFormatDesc = cudaCreateChannelDesc(8, 0, 0, 0, cudaChannelFormatKindUnsigned);&#xA;        checkCudaErrors(cudaMallocArray(&amp;amp;cuArray, &amp;amp;channelFormatDesc, bytesPerScanline, textureHeight));&#xA;        checkCudaErrors(cudaMemcpyToArray(cuArray, 0, 0, pHostData, bytesPerScanline * textureHeight * sizeof(uint8_t), cudaMemcpyHostToDevice));&#xA;        &#xA;        resourceDesc.resType = cudaResourceTypeArray;&#xA;        resourceDesc.res.array.array = cuArray;&#xA;&#xA;        textureDesc.normalizedCoords = true;&#xA;        textureDesc.filterMode = cudaFilterModePoint;&#xA;        textureDesc.addressMode[0] = cudaAddressModeWrap;&#xA;        textureDesc.addressMode[1] = cudaAddressModeWrap;&#xA;        textureDesc.readMode = cudaReadModeElementType;&#xA;        checkCudaErrors(cudaCreateTextureObject(&amp;amp;textureObject, &amp;amp;resourceDesc, &amp;amp;textureDesc, nullptr));&#xA;        STBI_FREE(pHostData);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The output images were ppm and converted to pgm for upload purposes&#xA;&lt;a href=&quot;https://i.stack.imgur.com/IpNXb.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IpNXb.png&quot; alt=&quot;From CPU code&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/w7eY7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/w7eY7.png&quot; alt=&quot;From CUDA code&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2020-12-02T18:52:01.127" Title="Why is the image from the CUDA version not as sharp as the CPU version?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;texture&gt;&lt;antialiasing&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10424" PostTypeId="1" CreationDate="2020-11-23T00:56:54.223" Score="0" ViewCount="20" Body="&lt;p&gt;this is best explained by visualization. Below webpage is a spherical textured panorama which gives the effect of being inside of the room. I want to be able to localize (eg) windows by mouse clicks to be able to crop them.&lt;/p&gt;&#xA;&lt;p&gt;See: &lt;a href=&quot;http://othree.github.io/360-panorama/three-3d/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://othree.github.io/360-panorama/three-3d/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is a sphere with a texture image which is a 2d panorama:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/wbd5x.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wbd5x.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;You have longitude/latitude information. From another discussions, I found this simple formula:&lt;/p&gt;&#xA;&lt;p&gt;int x =  (int) ((PANO_WIDTH/360.0) * (180 + lon));&#xA;int y =  (int) ((PANO_HEIGHT/180.0) * (90 - lat));&lt;/p&gt;&#xA;&lt;p&gt;which makes sense, since LAT/LON ranges from -90 to 90 and -180 to 180 respectively.&lt;/p&gt;&#xA;&lt;p&gt;So if your lookAt points to {lat,lon} (i.e., where your camera center is looking), you can recover (x,y). However, I want to do two things:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Be able to use mouse click {x,y}s and recover those, as opposed to just center. I tried to extrapolate by drawing arcs using pen&amp;amp;paper but didn't get far.&lt;/li&gt;&#xA;&lt;li&gt;This fails when you are at the edge of the panorama where your wrapped image can connect two ends of your image, e.g., rightmost and leftmost coincide. I tried to repeat the image twice to avoid this but failed as well (not even sure this is the right approach).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="15206" LastActivityDate="2020-11-23T00:56:54.223" Title="Identifying 2d coordinates of texture from 3d textured sphere" Tags="&lt;projections&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10425" PostTypeId="1" CreationDate="2020-11-23T05:50:20.813" Score="0" ViewCount="107" Body="&lt;p&gt;I've sucessfully implemented a ray tracer from scratch in C and it's marvelous:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/QL1ix.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/QL1ix.png&quot; alt=&quot;sphere1&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The surface normal on this sphere is taken by computing the intersection point, A, and treating this as a euclidean vector with origin, B, the center of the sphere. To normalize it, I first subtracted A with B, yielding C:&lt;/p&gt;&#xA;&lt;p&gt;C = (Ax-Bx,Ay-By)&lt;/p&gt;&#xA;&lt;p&gt;From this, it's divided by the magnitude:&lt;/p&gt;&#xA;&lt;p&gt;N = C/|C|&lt;/p&gt;&#xA;&lt;p&gt;The illumination is calculated by taking the dot product of N and LIGHT_SOURCE and multiplying it with 255:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;if (dot_product&amp;lt;0.0) dot_product = 0.0;&#xA;illumination = (unsigned char)(dot_product*255.0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When I tried setting the light source to (0.0, 0.0, -1.0), it produce something like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/dhNtj.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/dhNtj.png&quot; alt=&quot;sphere2&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I expected the shade to be something like it's brighter on the middle and becoming more dimmer on the side.&lt;/p&gt;&#xA;&lt;p&gt;Anyone know what's causing the problem?&lt;/p&gt;&#xA;&lt;p&gt;Source code: &lt;a href=&quot;https://gist.github.com/harieamjari/6297a35400460edbabbd8e39720ed0f5&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gist.github.com/harieamjari/6297a35400460edbabbd8e39720ed0f5&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This can be compiled if you already have libpng16.&lt;/p&gt;&#xA;" OwnerUserId="15172" LastEditorUserId="15172" LastEditDate="2020-11-23T05:59:24.873" LastActivityDate="2021-04-23T05:44:04.160" Title="Lambertian shading illuminates all the front of a sphere" Tags="&lt;shading&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10426" PostTypeId="2" ParentId="10425" CreationDate="2020-11-23T07:52:45.430" Score="0" Body="&lt;p&gt;I think there is a problem with your ray-sphere intersection.&lt;/p&gt;&#xA;&lt;p&gt;It should go like this&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;sphere_normal = ray.origin - sphere_center;&#xA;b = dot(sphere_normal , ray.normalized_dir);&#xA;c = dot(sphere_normal , sphere_normal ) - sphere_radius*spheres_radius;&#xA;float disc = b * b - c;&#xA;&#xA;float t = -1.0f;&#xA;if(disc &amp;gt;= 0.0f)&#xA;t = -b +- sqrt(disc);&#xA;&#xA;if(t &amp;gt;= 0) // means ray intersects...&#xA;     &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Check out scratchapixel to understand how I got this.&#xA;&lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.scratchapixel.com/lessons/3d-basic-rendering/minimal-ray-tracer-rendering-simple-shapes/ray-sphere-intersection&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2020-11-23T23:27:54.973" LastActivityDate="2020-11-23T23:27:54.973" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10427" PostTypeId="1" AcceptedAnswerId="10428" CreationDate="2020-11-23T12:36:09.147" Score="0" ViewCount="32" Body="&lt;p&gt;In my application, there is no inherent 2D or 3D structure to the computer shader instances. So having multiple dimensions doesn't benefit me semantically in any way. I am wondering, whether it still might be beneficial to split up my workload over three dimensions to increase performance.&lt;/p&gt;&#xA;" OwnerUserId="15232" LastActivityDate="2020-11-23T14:50:52.830" Title="Is glDispatchCompute(a,b,c) any faster than glDispatchCompute(a*b*c,1,1)?" Tags="&lt;performance&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10428" PostTypeId="2" ParentId="10427" CreationDate="2020-11-23T14:50:52.830" Score="2" Body="&lt;p&gt;Broadly speaking, no, these won't really matter.&lt;/p&gt;&#xA;&lt;p&gt;In &lt;em&gt;specific&lt;/em&gt; cases, it could, but only because it might influence the order in which work groups are processed. And that would mean that it might influence cache behavior and the like, which could matter if neighboring work groups access related memories.&lt;/p&gt;&#xA;&lt;p&gt;But even in such a case, which one is better would depend entirely on the nature of the shader's memory access patterns and the driver's decisions about ordering work groups. One shader might run slightly faster with a linear ordering, while a different shader might run faster with a multi-dimensional ordering. It all depends on what the shader is doing (and how the driver handles it), so you can't say that one is inherently better than the other.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2020-11-23T14:50:52.830" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10429" PostTypeId="2" ParentId="10425" CreationDate="2020-11-24T04:27:35.893" Score="0" Body="&lt;p&gt;It turns out, the problem was because the sphere was placed very far away and the radius is too big. This produces a normal with a high value z.&lt;/p&gt;&#xA;&lt;p&gt;A solution for me was to place the sphere very close to the origin—about z=0.25, and set the radius of the sphere less than z— about r=0.125.&lt;/p&gt;&#xA;&lt;p&gt;light_source (-1,0,0)&#xA;&lt;img src=&quot;https://i.stack.imgur.com/TnOTu.png&quot; alt=&quot;-1,0,0&quot; /&gt;&#xA;light_source (0,0,-1)&#xA;&lt;img src=&quot;https://i.stack.imgur.com/Guz4I.png&quot; alt=&quot;0,0,-1&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="15172" LastActivityDate="2020-11-24T04:27:35.893" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10430" PostTypeId="1" CreationDate="2020-11-25T12:11:08.917" Score="0" ViewCount="89" Body="&lt;p&gt;I am trying to build a VR tracking system with a laptop webcam, and I have succeeded in identifying, and tracking paper markers I put in front of my webcam. For context I am using OpenCV with the latest OpenCVSharp wrapper in .Net 5.&lt;/p&gt;&#xA;&lt;p&gt;Currently I can track all 4 corners of an object (ordered, so orientation is accounted for) as a 2d quad on the webcam's image, so long as I am provided with a reference image before hand. I know the exact measurements of the reference object, and now I want to use both the 4 corners I calculate, and the measurements of the object in order to determine the position and rotation of that object relative to my webcam.&lt;/p&gt;&#xA;&lt;p&gt;In the future I would also like to add additional cameras to the setup to allow for more precision and reducing dead zones. They would know the positions relative to the other sensors for the sake of simplicity.&lt;/p&gt;&#xA;&lt;p&gt;How would I go about calculating both the position and rotation of an object given its' measurements, and 4 ordered corners on an image?&lt;/p&gt;&#xA;" OwnerUserId="15268" LastActivityDate="2021-04-25T15:06:30.760" Title="Calculate the position and rotation of a quad in 3d space given a 2d projection of that quad from a camera" Tags="&lt;image-processing&gt;&lt;mathematics&gt;&lt;virtual-reality&gt;&lt;opencv&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10431" PostTypeId="1" CreationDate="2020-11-26T01:40:06.617" Score="2" ViewCount="97" Body="&lt;p&gt;I am interested in a scientific application in which ray tracing is necessary, but also where the light itself alters the geometry of the surface mesh (imagine perhaps that the beams of light have enough energy to damage the surface). Right now I am writing everything from scratch and not using any existing libraries, and thus my (obviously naive) implementation is extremely slow. As I understand it, this boils down to clever methods by which to update the BVH, interleaved with each rendering step.&lt;/p&gt;&#xA;&lt;p&gt;Some slight elaboration on the problem: when a ray of light hits a surface, we consider two possibilities: either it reflects off the surface (as is typical in a ray tracer), or it impacts the surface and essentially burns a hole into the surface. This alters the geometry  of the mesh and affects any future light rays, and thus forces an update of the boundary volume hierarchy. The surface deformation is usually local but &lt;em&gt;can&lt;/em&gt; be global-scale, for example if the hole is large enough it may cause the structure to collapse or break off. Thus ray tracing affects the geometry &amp;quot;in real time&amp;quot;, but simultaneously geometry is necessary to perform ray tracing at each step as well.&lt;/p&gt;&#xA;&lt;p&gt;While I'm interested in the algorithmic problem, what I'm more interested in is whether or not there is a graphics library that is well suited to this task, so that I don't have to re-invent the wheel, or dive too deep into the literature. I am quite a beginner when it comes to available software libraries so please forgive me.&lt;/p&gt;&#xA;" OwnerUserId="15275" LastEditorUserId="15275" LastEditDate="2020-11-27T07:30:32.687" LastActivityDate="2020-11-27T07:30:32.687" Title="Ray tracing where illumination itself affects the geometry" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="2" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10432" PostTypeId="2" ParentId="10431" CreationDate="2020-11-26T04:34:19.600" Score="3" Body="&lt;p&gt;You might look into &lt;a href=&quot;https://www.mitsuba-renderer.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitsuba&lt;/a&gt;, which is a physically based path tracing renderer that's designed to be easy to extend with plugins. It might be useful as a base for you to build on, implementing your own algorithms as plugins or by modifying its code.&lt;/p&gt;&#xA;&lt;p&gt;It already contains facilities for measuring the amount of light falling on some geometry, in the form of the &amp;quot;&lt;a href=&quot;https://mitsuba2.readthedocs.io/en/latest/generated/plugins.html#irradiance-meter-irradiancemeter&quot; rel=&quot;nofollow noreferrer&quot;&gt;irradiance meter&lt;/a&gt;&amp;quot; object. I'm not sure how much it can help you with geometry modification as it's not really designed for that (it just imports geometry from a file and renders it), but maybe you can find some other libraries to help with that part, depending on what kind of geometry operations you need to do.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-11-26T04:34:19.600" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10433" PostTypeId="2" ParentId="10430" CreationDate="2020-11-26T14:10:47.153" Score="1" Body="&lt;p&gt;Hello Djgaven588 and welcome to the forums!&lt;/p&gt;&#xA;&lt;p&gt;This is not a computer graphics question, but a computer vision one. The answer to it is a little bit involved and I cannot make it justice on a forum post. However, I can point you in the right direction so that you are able to find the answer by yourself.&lt;/p&gt;&#xA;&lt;p&gt;Here's a helpful link: &lt;a href=&quot;https://docs.opencv.org/master/d9/db7/tutorial_py_table_of_contents_calib3d.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://docs.opencv.org/master/d9/db7/tutorial_py_table_of_contents_calib3d.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The process is somewhat straightforward, but it depends on how much you know about projections and solving systems of equations.&lt;/p&gt;&#xA;&lt;p&gt;First you need to find key points on a known object in your image through some kind of image-processing algorithm. It seems you already did that. By known object, I mean that you know its exact measurements in the real world with regards to the selected key points.&lt;/p&gt;&#xA;&lt;p&gt;Secondly, you need to &amp;quot;unproject&amp;quot; your 2D image points onto 3D space, by reversing the projection math from 3D to 2D. This requires building a projection matrix containing intrinsic and extrinsic camera parameters, as well as finding coefficients modelling the camera lens distortion. This process is known as camera calibration.&lt;/p&gt;&#xA;&lt;p&gt;Thirdly, when using a single camera, you can unproject the points only up to a scale factor, because the depth coordinate has been lost during the original projection. In order to figure out the scale, rotation, and position of the object, you can set up a system of equations relating the image key points to the known key points in the real world at a specific position and rotation of the known object. Solving this system will let you figure out the transform. Note that it is important to have a reasonable amount of key points (even redundant ones) so that the error can be minimised.&lt;/p&gt;&#xA;&lt;p&gt;OpenCV has methods and functions for doing all of these procedures, and there are many tutorials on the web, like the one I linked above.&lt;/p&gt;&#xA;&lt;p&gt;I hope you can figure it out! :)&lt;/p&gt;&#xA;" OwnerUserId="4768" LastActivityDate="2020-11-26T14:10:47.153" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10434" PostTypeId="1" CreationDate="2020-11-26T15:10:43.927" Score="1" ViewCount="47" Body="&lt;p&gt;I have just started learning how to use and create shaders in ThreeJS and, while going through some shaders in the example folder, I have come across a bokeh shader. Inside the shader, blur is computed using a formula, but I dont really understand where does this formula come from and what it really computes. Here is some code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float f = focalLength; // focal length in mm&amp;quot;,&#xA;        &amp;quot;       float d = fDepth*1000.0; // focal plane in mm&amp;quot;,&#xA;        &amp;quot;       float o = depth*1000.0; // depth in mm&amp;quot;,&#xA;&#xA;        &amp;quot;       float a = (o*f)/(o-f);&amp;quot;,&#xA;        &amp;quot;       float b = (d*f)/(d-f);&amp;quot;,&#xA;        &amp;quot;       float c = (d-f)/(d*fstop*CoC);&amp;quot;,&#xA;&#xA;        &amp;quot;       blur = abs(a-b)*c;&amp;quot;,&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What I don't understand is what c is and how I can then use it to compute the blur. For reference, the shader I am talking about is BokehShader2 by Martins Upitis.&#xA;Can anyone help me out?&lt;/p&gt;&#xA;" OwnerUserId="15278" LastActivityDate="2020-11-26T15:10:43.927" Title="Blur calculation in shader with fixed CoC" Tags="&lt;shader&gt;&lt;post-processing&gt;&lt;three.js&gt;&lt;depth-of-field&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10436" PostTypeId="1" CreationDate="2020-11-26T22:02:13.277" Score="0" ViewCount="45" Body="&lt;p&gt;I'm trying to understand how to implement an algorithm similar to the one used by Magics' mark surface tool, you can see such behaviour on this &lt;a href=&quot;https://youtu.be/XVrRbGNBtVc?t=145&quot; rel=&quot;nofollow noreferrer&quot;&gt;video&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Quoting the video: &amp;quot;Basically with this tool you're able to select surfaces, which unlike planes, surfaces take curvature into account.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;The first idea that come to my mind to implement something similar was starting by considering the adjacency information of the mesh and consider on the computation the angle adjacent triangle normals. My idea was that if such an angle wasn't on the range [pi/2-tol, pi/2+tol] two adjacent triangles would be &amp;quot;smooth&amp;quot;. This thought was too naive and the idea would just work for a very limited of cases and it'd start fail for many of them.&lt;/p&gt;&#xA;&lt;p&gt;After that, I've spent a little bit of time reading some papers talking about mesh segmentation and it seems this has been an area of research for many years... But before even considering implementing any of these one I'd like to ask here if you knew some basic&amp;amp;good enough algorithm I could implement that could behave in a similar fashion to Magic's.&lt;/p&gt;&#xA;&lt;p&gt;So yeah, that's my question basically, assuming a triangular mesh that has adjacency information built (ie: you can check adjacent triangles from any given face) and a starting selected triangle, how would you detect the &amp;quot;surface&amp;quot; region associated to it?&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerDisplayName="user4801" LastEditorDisplayName="user4801" LastEditDate="2020-11-26T22:31:38.780" LastActivityDate="2020-11-28T22:43:14.273" Title="Algorithm to select regions based on curvature on a mesh" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;geometry&gt;&lt;cad&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10437" PostTypeId="2" ParentId="9591" CreationDate="2020-11-27T22:49:48.050" Score="0" Body="&lt;p&gt;The function &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; is going to be a low-pass filter of some type. Its role is to turn the infinite-resolution image &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; into a band-limited one so that it can be sampled to produce pixel values without aliasing. Typical shapes for &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; in practice could be like a box, tent, bicubic, or Gaussian function.&lt;/p&gt;&#xA;&lt;p&gt;Such a filter would generally be expected to have the following properties:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Defined over the image plane, &lt;span class=&quot;math-container&quot;&gt;$h_j: \mathbb{R}^2 \to \mathbb{R}$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;Is an area density, i.e. has units of inverse area (and scales accordingly under changes of coordinates)&lt;/li&gt;&#xA;&lt;li&gt;Compactly supported, with its region of support commensurate with the pixel spacing (typically having a radius of 1–2 pixels in all directions)&lt;/li&gt;&#xA;&lt;li&gt;Smooth, or at least piecewise smooth&lt;/li&gt;&#xA;&lt;li&gt;Finite-valued&lt;/li&gt;&#xA;&lt;li&gt;Integrates to 1, &lt;span class=&quot;math-container&quot;&gt;$\int_{\mathbb{R}^2} h_j(x) \, dx^2 = 1$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;The filters for different pixels &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt; differ only by translation, &lt;span class=&quot;math-container&quot;&gt;$h_j(x) = h(x - x_j)$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt; is the filter centered at 0, and &lt;span class=&quot;math-container&quot;&gt;$x_j$&lt;/span&gt; is the center of the &lt;span class=&quot;math-container&quot;&gt;$j$&lt;/span&gt;th pixel.&lt;/li&gt;&#xA;&lt;li&gt;Symmetric, &lt;span class=&quot;math-container&quot;&gt;$h(-x) = h(x)$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;Factors into 1D filters along the x and y axes, &lt;span class=&quot;math-container&quot;&gt;$h(x, y) = h(x)h(y)$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;(The last three properties might not be true for some exotic cases, such as rendering to a curved or nonlinearly warped display, but would be expected to hold for rendering an ordinary 2D image.)&lt;/p&gt;&#xA;&lt;p&gt;You'll note one property I didn't mention was &lt;span class=&quot;math-container&quot;&gt;$h_j \geq 0$&lt;/span&gt;. That's because it is actually convenient to use filters with negative lobes sometimes, as they can improve image sharpness. See for example the &lt;a href=&quot;https://en.wikipedia.org/wiki/Mitchell-Netravali_filters&quot; rel=&quot;nofollow noreferrer&quot;&gt;Mitchell–Netravali filters&lt;/a&gt;. Nor do we necessarily have &lt;span class=&quot;math-container&quot;&gt;$h_j \leq 1$&lt;/span&gt; everywhere. Actually the values of &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; depend on the coordinate system, since it's an area density, so a statement like &lt;span class=&quot;math-container&quot;&gt;$h_j \leq 1$&lt;/span&gt; is meaningless without specifying some particular coordinates.&lt;/p&gt;&#xA;&lt;p&gt;Regarding your properties, for (a), yes the norm of the filter should be bounded. As mentioned, the filter integrates to 1. Without negative lobes, the 1-norm of the filter should be exactly 1. The 1-norm of a filter with negative lobes would be expected to be somewhat greater than 1 but still finite.&lt;/p&gt;&#xA;&lt;p&gt;For property (b), I'm not 100% sure but I think that this is indeed guaranteed by the fact that &lt;span class=&quot;math-container&quot;&gt;$h_j$&lt;/span&gt; is (piecewise) smooth and has a support that doesn't get arbitrarily small. The size of the filter is on the order of the pixel spacing (otherwise it doesn't work for antialiasing), so the variance within a single pixel's filter footprint can't be much more than (variance of entire image * number of pixels). You could probably formalize that with Chebyshev's inequality or some such.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-11-27T22:49:48.050" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10438" PostTypeId="1" CreationDate="2020-11-28T14:57:19.127" Score="0" ViewCount="74" Body="&lt;p&gt;I have a mesh made up of several tetrahedrons, I know for sure that there are intersections between some of them: how can I remove these intersections, without generating others?&#xA;In other terms: if between a couple of tetrahedrons there is an intersection, how can I remove it?&lt;/p&gt;&#xA;&lt;p&gt;I found these articles: the &lt;a href=&quot;https://www.geometrictools.com/Documentation/MethodOfSeparatingAxes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Method of Separating Axes&lt;/a&gt;, the &lt;a href=&quot;http://vcg.isti.cnr.it/Publications/2003/GPR03/fast_tetrahedron_tetrahedron_overlap_algorithm.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Tetrahedron Overlap Algorithm&lt;/a&gt;.&#xA;But they are only useful for checking if there are intersections or not.&lt;/p&gt;&#xA;&lt;p&gt;Is there an algorithm to solve this problem?&lt;/p&gt;&#xA;" OwnerUserId="15293" LastActivityDate="2021-05-08T22:05:00.433" Title="Is There an algorithm to remove intersections between two tetrahedrons?" Tags="&lt;algorithm&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10439" PostTypeId="1" CreationDate="2020-11-29T11:36:36.540" Score="0" ViewCount="76" Body="&lt;p&gt;I have to admit that, while watching footage of the enhanced 2020 version of the 2018 game &lt;em&gt;Forza Horizon 4&lt;/em&gt;, when they are driving fast, I have to sometimes remind myself that I am watching a video game and not a video recording of reality. It's the closest I've ever seen to photo realism, but as soon as the car stops, or they go too slowly, or they do something slightly not expected, the illusion quickly falls apart.&lt;/p&gt;&#xA;&lt;p&gt;It's just a bunch of smoke and mirrors and dead polygon objects after all. Not an actual photo-realistic 3D version of England where I can &amp;quot;drive anywhere and do anything&amp;quot;. But for small moments, it can fool me. Example &lt;strong&gt;gameplay footage&lt;/strong&gt;: &lt;a href=&quot;https://youtu.be/PqwQDRersIM?t=42&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/PqwQDRersIM?t=42&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;What exactly is the &amp;quot;missing piece&amp;quot; at this point? It's impossible for me to not be impressed by the game, but I still don't want to play it. I can tell that I would very quickly get bored of the illusion, and just grow ever more frustrated by the limitations of the reality as presented in the game.&lt;/p&gt;&#xA;&lt;p&gt;For me, it's largely knowing that it's all dead 3D objects. There are no detailed rooms inside all of those buildings which I could enter and go through. There are no people either, or, if there are, they don't look or behave anything like real humans would. There are many visual details which just look &amp;quot;off&amp;quot;, and the more photo-realistic it looks overall, the more demanding my brain becomes and the more eager I am to point out any flaw.&lt;/p&gt;&#xA;&lt;p&gt;If you then take a look at this random &lt;strong&gt;actual video&lt;/strong&gt;, even that game looks like garbage in comparison: &lt;a href=&quot;https://youtu.be/FMOb5-e3J7Y?t=49&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/FMOb5-e3J7Y?t=49&lt;/a&gt; (yes, I know that the settings/locations are quite different, but that doesn't really matter).&lt;/p&gt;&#xA;&lt;p&gt;Something about reality is so much &amp;quot;richer&amp;quot; and &amp;quot;real&amp;quot; than what they can do with a 3D world, but I don't quite understand what exactly. I feel as if I should be more impressed than I actually am by that car game. It looks objectively amazing, yet at the same time, I have &lt;em&gt;very&lt;/em&gt; little interest in actually playing it. And keep in mind that I'm a person who has been hunting for photo-realistic 3D simulations my entire life and who is endlessly fascinated by the concept.&lt;/p&gt;&#xA;&lt;p&gt;One thing I can say for sure: it has almost nothing to do with the resolution of the game/camera. Even if you take a very old and cheap camera and go filming reality, it will look a million times better than the 8K game.&lt;/p&gt;&#xA;&lt;p&gt;Can you explain to me why we don't have a simulation that looks and behaves just like the actual video I just linked to?&lt;/p&gt;&#xA;" OwnerUserId="15297" LastActivityDate="2020-11-30T14:22:08.963" Title="What exactly is it about reality that is so difficult to recreate in a 3D simulation?" Tags="&lt;3d&gt;&lt;real-time&gt;&lt;simulation&gt;&lt;photo-realistic&gt;&lt;realistic&gt;" AnswerCount="2" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10440" PostTypeId="2" ParentId="10439" CreationDate="2020-11-29T14:58:37.780" Score="2" Body="&lt;p&gt;As @AnnoyinC already mentioned in his comment, we are simply lacking computational power and storage requirements (RAM).&lt;/p&gt;&#xA;&lt;p&gt;For the visual effects, you need to calculate every ray of light that somehow ends up in the observer's eye after an arbitrary number of reflections on different surfaces. The reflections depend on the surface's microstructure. This alone is so extremely demanding that is far from possible to calculate it in real-time with current consumer hardware. The first steps into this direction are already taken with ray tracing support of modern graphic cards but it is still very limited.&#xA;And that's just the &amp;quot;easy part&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;It gets way more complicated if you want to have objects and fluids that behave physically correct. While each ray of light is more or less independent of other rays, physical objects influence each other. Also, simulating the correct reaction of an arbitrary object to an external force can already take days and weeks for a single timestep/frame since you need to solve extremely large equation systems that are often non-linear. If you want to know why I would suggest searching for a &amp;quot;Finite-Element-Method&amp;quot; or &amp;quot;Computational Fluid Dynamics&amp;quot; tutorial. These techniques are commonly used by engineers and separate a structure into a mesh of smaller interacting substructures. The results get closer to the behavior of the real structure/fluid the denser the mesh. However, doubling the mesh density in each of the 3 spatial directions comes at the price of needing 8 times more computational power and RAM. Now think of a tree waving in the wind with thousands of leaves where each leaf alone is a complex physical object... I think you get the picture.&lt;/p&gt;&#xA;&lt;p&gt;To get around all these problems, a lot of approximations are used. While most of them are quite good illusions they will give wrong results at some point. However, that doesn't necessarily mean that we realize it.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2020-11-29T14:58:37.780" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10441" PostTypeId="1" CreationDate="2020-11-29T18:44:41.443" Score="1" ViewCount="30" Body="&lt;p&gt;I built a simple Ray Tracer which takes use of OpenGL's Compute Shader and traces &amp;quot;.obj&amp;quot; Files.&#xA;The results are passed to the Host-Program via glMapBufferRange after finishing computing.&#xA;From there I will output the result as png to validate the result...&#xA;When I change the dimensions for the output the computation will obviously take longer.&lt;/p&gt;&#xA;&lt;h2&gt;Now to the problem/question:&lt;/h2&gt;&#xA;&lt;p&gt;Let's say the computation works fine with a 300x300 .png image file and I get the result I want.&#xA;When I increase the size of the image to something like 500x500 I'll get a GL_OUT_OF_MEMORY Error after some time. And only when I try to copy data with glMapBufferRange.&lt;/p&gt;&#xA;&lt;p&gt;When I'm using a BVH-Structure to accelerate the computation it works with 500x500 and larger images within a shorter time period.&lt;/p&gt;&#xA;&lt;p&gt;So I think that the Operating System is shutting down the GPU after some time and thus resulting into a invalid Memory Access.  Not sure though.&lt;/p&gt;&#xA;&lt;p&gt;I've been using Ubuntu 20.04 for the program.&lt;/p&gt;&#xA;&lt;p&gt;Can someone explain why I get an GL_OUT_OF_MEMORY?&#xA;Is it more likly that I just have some Memory Leaks?&lt;/p&gt;&#xA;&lt;p&gt;the probably critical part of the Code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;/* Some ssbo's and glsl-program defined above */&#xA;    glDispatchCompute(workgroup_x, workgroup_y, 1);&#xA;    glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);&#xA;&#xA;&#xA;    glBindBuffer(GL_SHADER_STORAGE_BARRIER_BIT, defined_ssbo_buffer_idx);&#xA;    // Error occurs here when computation took around 5 sec or longer&#xA;    void* gpuData = glMapBufferRange(GL_SHADER_STORAGE_BARRIER_BIT, 0, size_of_buffer, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);&#xA;    memcpy(copyDestination, gpuData, size_of_buffer);&#xA;    &#xA;    glUnmapBuffer(GL_SHADER_STORAGE_BARRIER_BIT)&#xA;    glBindBuffer(GL_SHADER_STORAGE_BARRIER_BIT, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I really appreciate any help!&#xA;Thank you very much and have a great day!&lt;/p&gt;&#xA;" OwnerUserId="15299" LastEditorUserId="15299" LastEditDate="2020-11-30T11:54:28.467" LastActivityDate="2020-11-30T11:54:28.467" Title="GL_OUT_OF_MEMORY Error when glDispatchCompute takes longer" Tags="&lt;opengl&gt;&lt;raytracing&gt;&lt;gpu&gt;&lt;compute-shader&gt;&lt;gpgpu&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10442" PostTypeId="1" CreationDate="2020-11-30T11:55:37.950" Score="0" ViewCount="16" Body="&lt;p&gt;I am developing a script that will determine a minimal voxel size in a mesh. My first thought was to caculate the area of given face. Another approach would be to calculate minimal line length and maximum curvature, but I'm unsure what to do after that.&#xA;I couldn't find anything related to that online. I was hoping someone will point me in te right direction.&lt;/p&gt;&#xA;" OwnerUserId="15305" LastActivityDate="2020-11-30T11:55:37.950" Title="Calculating minimal voxel size in a mesh" Tags="&lt;mesh&gt;&lt;voxelization&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10443" PostTypeId="1" CreationDate="2020-11-30T12:04:59.950" Score="0" ViewCount="30" Body="&lt;p&gt;I've modified code of my path-tracer to rasterization only, to play a little with DirectX 12. However, I have problem with correct backface culling, even though my PSO seems to use correct options:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zcwWc.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zcwWc.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/hhsn3.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/hhsn3.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here is my code creating PSO:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Prepare shaders&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; vertexShader;&#xA;ComPtr&amp;lt;ID3DBlob&amp;gt; pixelShader;&#xA;Compile_Shader(L&amp;quot;Shaders/vertexShader.hlsl&amp;quot;, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &amp;quot;main&amp;quot;, &amp;quot;vs_5_1&amp;quot;, 0, 0, &amp;amp;vertexShader);&#xA;Compile_Shader(L&amp;quot;Shaders/pixelShader.hlsl&amp;quot;, NULL, D3D_COMPILE_STANDARD_FILE_INCLUDE, &amp;quot;main&amp;quot;, &amp;quot;ps_5_1&amp;quot;, 0, 0, &amp;amp;pixelShader);&#xA;&#xA;// Preprare layout, DSV and create PSO&#xA;auto inputElementDescs = CreateBasicInputLayout();&#xA;CD3DX12_DEPTH_STENCIL_DESC1 depthStencilDesc = CreateDefaultDepthStencilDesc();&#xA;D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = CreateDefaultPSO(inputElementDescs, vertexShader, pixelShader, depthStencilDesc, m_rootSignature);&#xA;ThrowIfFailed(m_device-&amp;gt;CreateGraphicsPipelineState(&amp;amp;psoDesc, IID_PPV_ARGS(&amp;amp;m_pipelineState)));&#xA;//////////////////&#xA;&#xA;CD3DX12_DEPTH_STENCIL_DESC1 Renderer::CreateDefaultDepthStencilDesc()&#xA;{&#xA;    CD3DX12_DEPTH_STENCIL_DESC1 depthStencilDesc{};&#xA;    depthStencilDesc.DepthBoundsTestEnable = true;&#xA;&#xA;    // Set up the description of the stencil state.&#xA;    depthStencilDesc.DepthEnable = true;&#xA;    depthStencilDesc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;&#xA;    depthStencilDesc.DepthFunc = D3D12_COMPARISON_FUNC_LESS_EQUAL;&#xA;&#xA;    depthStencilDesc.StencilEnable = true;&#xA;    depthStencilDesc.StencilReadMask = D3D12_DEPTH_WRITE_MASK_ALL;&#xA;    depthStencilDesc.StencilWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;&#xA;&#xA;    // Stencil operations if pixel is front-facing.&#xA;    depthStencilDesc.FrontFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;&#xA;    depthStencilDesc.FrontFace.StencilDepthFailOp = D3D12_STENCIL_OP_INCR;&#xA;    depthStencilDesc.FrontFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;&#xA;    depthStencilDesc.FrontFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;&#xA;&#xA;    // Stencil operations if pixel is back-facing.&#xA;    depthStencilDesc.BackFace.StencilFailOp = D3D12_STENCIL_OP_KEEP;&#xA;    depthStencilDesc.BackFace.StencilDepthFailOp = D3D12_STENCIL_OP_DECR;&#xA;    depthStencilDesc.BackFace.StencilPassOp = D3D12_STENCIL_OP_KEEP;&#xA;    depthStencilDesc.BackFace.StencilFunc = D3D12_COMPARISON_FUNC_ALWAYS;&#xA;&#xA;    return depthStencilDesc;&#xA;}&#xA;&#xA;D3D12_GRAPHICS_PIPELINE_STATE_DESC Renderer::CreateDefaultPSO(BasicInputLayout inputElementDescs, ComPtr&amp;lt;ID3DBlob&amp;gt; vertexShader, ComPtr&amp;lt;ID3DBlob&amp;gt; pixelShader, D3D12_DEPTH_STENCIL_DESC depthStencilDesc, ComPtr&amp;lt;ID3D12RootSignature&amp;gt; rootSignature)&#xA;{&#xA;    // Describe and create the graphics pipeline state object (PSO).&#xA;    D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc = {};&#xA;    psoDesc.InputLayout = { &amp;amp;inputElementDescs[0], static_cast&amp;lt;UINT&amp;gt;(inputElementDescs.size()) };&#xA;    psoDesc.pRootSignature = rootSignature.Get();&#xA;    psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader.Get());&#xA;    psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader.Get());&#xA;    psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);&#xA;    psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);&#xA;    psoDesc.DepthStencilState = depthStencilDesc;&#xA;    psoDesc.SampleMask = UINT_MAX;&#xA;    psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;&#xA;    psoDesc.NumRenderTargets = 1;&#xA;    psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;&#xA;    psoDesc.SampleDesc.Count = 1;&#xA;    psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT;&#xA;&#xA;    return psoDesc;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;CD3DX12_RASTERIZER_DESC default state is fill_solid, cull_mode_back so I don't know, why it doesn't work properly.&lt;/p&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2020-11-30T12:04:59.950" Title="Backface culling in DX12 not working properly" Tags="&lt;mesh&gt;&lt;directx12&gt;&lt;model&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10444" PostTypeId="2" ParentId="10439" CreationDate="2020-11-30T14:22:08.963" Score="0" Body="&lt;p&gt;One of the thing that breaks the illusion in that video for me is the cinematography. During the fast moments, the camera is more physically plausible, in that it could have been filmed from a camera mounted to a vehicle following the hero car. When stopped, the player moves the third-person camera around in a way that doesn't mimic physical camera rigs.&lt;/p&gt;&#xA;&lt;p&gt;It's also worth noting that motion blur is blur, and the loss of resolution caused by high speed motion covers up a lot of sins.&lt;/p&gt;&#xA;" OwnerUserId="159" LastActivityDate="2020-11-30T14:22:08.963" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10445" PostTypeId="1" CreationDate="2020-11-30T21:53:36.240" Score="0" ViewCount="23" Body="&lt;p&gt;I have the following .fx file for my shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Parameters that should be set from the program&#xA;float4x4 World; // World Matrix&#xA;float4x4 View; // View Matrix&#xA;float4x4 Projection; // Projection Matrix&#xA;float3 LightPosition; // in world space&#xA;float3 CameraPosition; // in world space&#xA;float Shininess; // scalar value&#xA;float3 AmbientColor;&#xA;float3 DiffuseColor;&#xA;float3 SpecularColor;&#xA;texture DiffuseTexture;&#xA;&#xA;sampler DiffuseSampler = sampler_state&#xA;{&#xA;    Texture = &amp;lt;DiffuseTexture&amp;gt;;&#xA;    AddressU = Wrap;&#xA;    AddressV = Wrap;&#xA;};&#xA;// We create structs to help us manage the inputs/outputs&#xA;// to vertex and pixel shaders&#xA;struct VertexInput&#xA;{&#xA;    float4 Position : POSITION0; // Here, POSITION0 and NORMAL0&#xA;    float3 Normal : NORMAL0; // are called mnemonics&#xA;    float2 UV: TEXCOORD0;&#xA;};&#xA;// --- Per Vertex technique - Gouraud&#xA;// We will create an output struct for this technique&#xA;struct GouraudVertexOutput&#xA;{&#xA;    float4 Position : POSITION0;&#xA;    float3 Color : COLOR0;&#xA;};&#xA;// The Vertex shader&#xA;// We will perform all the lighting calculations here&#xA;GouraudVertexOutput GouraudVertex(VertexInput input)&#xA;{&#xA;    GouraudVertexOutput output; // create the output struct&#xA;    // First, do the transformations&#xA;    float4 worldPosition = mul(input.Position, World);&#xA;    float4 viewPosition = mul(worldPosition, View);&#xA;    output.Position = mul(viewPosition, Projection);&#xA;    // Now do the lighting computation. First calculate the directions&#xA;    float3 lightDirection = normalize(LightPosition - worldPosition.xyz);&#xA;    float3 viewDirection = normalize(CameraPosition - worldPosition.xyz);&#xA;    float3 worldNormal = mul(input.Normal, World);&#xA;    float3 reflectDirection = -reflect(lightDirection, worldNormal);&#xA;    // Now compute the light components&#xA;    float diffuse = max(dot(lightDirection, worldNormal), 0);&#xA;    float specular = pow(max(dot(reflectDirection, viewDirection), 0), Shininess);&#xA;    // Finally, save the color to the output struct&#xA;    output.Color = AmbientColor + diffuse * DiffuseColor + specular * SpecularColor;&#xA;    return output;&#xA;}&#xA;// The Pixel Shader&#xA;// All this function does is to pass through the color through &#xA;float4 GouraudPixel(GouraudVertexOutput input) : COLOR0&#xA;{&#xA;    return float4(input.Color, 1);&#xA;}&#xA;&#xA;// --- Per Pixel techniques - Phong, Blinn, Schlick&#xA;// We will need a different output struct for this&#xA;struct PhongVertexOutput&#xA;{&#xA;    float4 Position : POSITION0;&#xA;    float2 UV: TEXCOORD0;&#xA;    float4 WorldPosition : TEXCOORD1;&#xA;    float3 WorldNormal : TEXCOORD2;&#xA;};&#xA;// A common vertex shader for all the different techniques&#xA;PhongVertexOutput PhongVertex(VertexInput input)&#xA;{&#xA;    PhongVertexOutput output;&#xA;    // Do the transformations as before&#xA;    // Save the world position for use in the pixel shader&#xA;    output.WorldPosition = mul(input.Position, World);&#xA;    float4 viewPosition = mul(output.WorldPosition, View);&#xA;    output.Position = mul(viewPosition, Projection);&#xA;    // as well as the normal in world space&#xA;    output.WorldNormal = mul(input.Normal, World);&#xA;    output.UV = input.UV * 10;&#xA;    return output;&#xA;}&#xA;// The pixel shader performs the lighting&#xA;float4 PhongPixel(PhongVertexOutput input) : COLOR0&#xA;{&#xA;    // The lighting operation, same as in the Gouraud vertex method&#xA;    float3 lightDirection = normalize(LightPosition - input.WorldPosition.xyz);&#xA;    float3 viewDirection = normalize(CameraPosition - input.WorldPosition.xyz);&#xA;    // Need to normalize my incoming normal, length could be less than 1&#xA;    input.WorldNormal = normalize(input.WorldNormal);&#xA;    float3 reflectDirection = -reflect(lightDirection, input.WorldNormal);&#xA;    // Now, compute the lighint components&#xA;    float diffuse = max(dot(lightDirection, input.WorldNormal), 0) * tex2D(DiffuseSampler, input.UV);&#xA;    float specular = pow(max(dot(reflectDirection, viewDirection), 0), Shininess);&#xA;    return float4(AmbientColor + diffuse * DiffuseColor + specular * SpecularColor, 1);&#xA;}&#xA;&#xA;// Now the different techniques&#xA;technique Gouraud&#xA;{&#xA;    pass Pass1&#xA;    {&#xA;        VertexShader = compile vs_4_0 GouraudVertex();&#xA;        PixelShader = compile ps_4_0 GouraudPixel();&#xA;    }&#xA;}&#xA;technique Phong&#xA;{&#xA;    pass Pass1&#xA;    {&#xA;        VertexShader = compile vs_4_0 PhongVertex();&#xA;        PixelShader = compile ps_4_0 PhongPixel();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What I'm trying to do is change this file so that the 3D objects I apply it to are green in color. What parts of the above code do I need to change in order to do this? I am using the Monogame software in Visual Studio (c# coding language). Any help would be greatly appreciated!&lt;/p&gt;&#xA;" OwnerUserId="15306" LastActivityDate="2020-11-30T21:53:36.240" Title="Changing shader color" Tags="&lt;3d&gt;&lt;shader&gt;&lt;shading&gt;&lt;3dtexture&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10446" PostTypeId="1" CreationDate="2020-12-01T10:34:40.743" Score="0" ViewCount="78" Body="&lt;p&gt;I'm working on a simple software renderer and have a working implementation so far. I'm curious as to why it's actually working since I would expect the multiplication ordering for my world, view and projection matrices to be reversed. When working with DirectX and OpenGL in the past I have multiplied them as projection * view * world, but with my implementation it's working with worldMatrix * viewMatrix * projectionMatrix. Some code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void SceneRenderer::DrawMesh(Mesh&amp;amp; mesh, const SRGraphicsContext&amp;amp; gfx)&#xA;{&#xA;    const Mat4x4f&amp;amp; worldMatrix = mesh.GetWorldMatrix();&#xA;    const Mat4x4f&amp;amp; viewMatrix = camera-&amp;gt;GetViewMatrix();&#xA;    const Mat4x4f&amp;amp; projectionMatrix = camera-&amp;gt;GetProjectionMatrix();&#xA;    const Mat4x4f&amp;amp; wvp = worldMatrix * viewMatrix * projectionMatrix;&#xA;&#xA;    const Vert3df&amp;amp; cameraPos = camera-&amp;gt;GetPosition();&#xA;&#xA;    const float screenWidth = static_cast&amp;lt;float&amp;gt;(gfx.frameBuffer-&amp;gt;GetWidth());&#xA;    const float screenHeight = static_cast&amp;lt;float&amp;gt;(gfx.frameBuffer-&amp;gt;GetHeight());&#xA;&#xA;    Tri2di rasterTri;&#xA;    for (Tri3df&amp;amp; tri : mesh.GetTriangles())&#xA;    {&#xA;        Vert4df p1c =  Vert4df(tri.p1, 1),&#xA;                p2c = Vert4df(tri.p2, 1),&#xA;                p3c = Vert4df(tri.p3, 1);&#xA;&#xA;        p1c = wvp * p1c;&#xA;        p2c = wvp * p2c;&#xA;        p3c = wvp * p3c;&#xA;        &#xA;        p1c.DivideByW();&#xA;        p2c.DivideByW();&#xA;        p3c.DivideByW();&#xA;&#xA;        rasterTri.p1.x = static_cast&amp;lt;int&amp;gt;((p1c.x + 1.0f) / 2.0f * screenWidth);&#xA;        rasterTri.p1.y = static_cast&amp;lt;int&amp;gt;((p1c.y + 1.0f) / 2.0f * screenHeight);&#xA;&#xA;        rasterTri.p2.x = static_cast&amp;lt;int&amp;gt;((p2c.x + 1.0f) / 2.0f * screenWidth);&#xA;        rasterTri.p2.y = static_cast&amp;lt;int&amp;gt;((p2c.y + 1.0f) / 2.0f * screenHeight);&#xA;&#xA;        rasterTri.p3.x = static_cast&amp;lt;int&amp;gt;((p3c.x + 1.0f) / 2.0f * screenWidth);&#xA;        rasterTri.p3.y = static_cast&amp;lt;int&amp;gt;((p3c.y + 1.0f) / 2.0f * screenHeight);&#xA;&#xA;        rasterizer-&amp;gt;DrawTriangle(rasterTri, gfx);&#xA;    }&#xA;&#xA;void Camera::LookAt(const Vert3df&amp;amp; at)&#xA;{&#xA;    lookAt = at;&#xA;&#xA;    auto zAxis = (lookAt - position).Normalize();&#xA;    auto xAxis = up.Cross(zAxis).Normalize();&#xA;    auto yAxis = zAxis.Cross(xAxis);&#xA;&#xA;    viewMatrix.Zero();&#xA;    viewMatrix(0, 0) = xAxis.x;&#xA;    viewMatrix(0, 1) = yAxis.x;&#xA;    viewMatrix(0, 2) = zAxis.x;&#xA;    viewMatrix(0, 3) = 0.0f;&#xA;    viewMatrix(1, 0) = xAxis.y;&#xA;    viewMatrix(1, 1) = yAxis.y;&#xA;    viewMatrix(1, 2) = zAxis.y;&#xA;    viewMatrix(1, 3) = 0.0f;&#xA;    viewMatrix(2, 0) = xAxis.z;&#xA;    viewMatrix(2, 1) = yAxis.z;&#xA;    viewMatrix(2, 2) = zAxis.z;&#xA;    viewMatrix(2, 3) = 0.0f;&#xA;    viewMatrix(3, 0) = -xAxis.Dot(position);&#xA;    viewMatrix(3, 1) = -yAxis.Dot(position);&#xA;    viewMatrix(3, 2) = -zAxis.Dot(position);&#xA;    viewMatrix(3, 3) = 1.0f;&#xA;}&#xA;&#xA;void Camera::UpdateProjectionMatrix()&#xA;{&#xA;    const float aspectRatio = screenWidth / (float)screenHeight;&#xA;&#xA;    float tanHalfFOV = std::tan(fov / 2.0f);&#xA;    float zRange = nearPlane - farPlane;&#xA;&#xA;    projectionMatrix.Zero();&#xA;    projectionMatrix(0, 0) = 1.0f / (tanHalfFOV * aspectRatio);&#xA;    projectionMatrix(1, 1) = 1.0f / tanHalfFOV;&#xA;    projectionMatrix(2, 2) = (-nearPlane - farPlane) / zRange;&#xA;    projectionMatrix(2, 3) = 1; // Left handed, invert for right handed&#xA;    projectionMatrix(3, 2) = (2 * nearPlane * farPlane) / zRange;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Any idea why the ordering might be reversed in my case? I've compared my Mat4x4f implementation to DirectX's XMMAtrix and get the same results when multiplying 2 arbitrary matrices.&lt;/p&gt;&#xA;" OwnerUserId="15310" LastEditorUserId="15310" LastEditDate="2021-01-08T01:18:02.177" LastActivityDate="2021-01-08T01:18:02.177" Title="Model View Projection Matrix Multiplcation Order" Tags="&lt;transformations&gt;&lt;mathematics&gt;&lt;projections&gt;&lt;matrix&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10447" PostTypeId="1" AcceptedAnswerId="10448" CreationDate="2020-12-01T20:13:06.497" Score="1" ViewCount="125" Body="&lt;p&gt;Let me first state what I think I know and please correct me if I'm too inaccurate or plainly wrong.&lt;/p&gt;&#xA;&lt;p&gt;When you use a function like &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/texture.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;texture&lt;/a&gt;, you're requesting a texel value given a pair (u,v) of texture parameters. However, depending on the pixel size / texel size ratio, there's a filtering and resampling prior to returning the texel value, which you can actually configure in the corresponding API (OpenGL, Vulkan, etc).&lt;/p&gt;&#xA;&lt;p&gt;As I understand it, this filtering and resampling occurs because either:&lt;/p&gt;&#xA;&lt;p&gt;a) Many texels affect a pixel. This happens because the texture resolution is too high for the area on screen to be covered (i.e. the pixel resolution). So in order to avoid artifacts, the texture needs to be downsampled, which consists of applying a minification filter and resampling at a lower rate.&lt;/p&gt;&#xA;&lt;p&gt;b) The same texel can affect many pixels. The texture resolution is lower than the pixel resolution. In this case, a magnification filter is used and the texture is upsampled.&lt;/p&gt;&#xA;&lt;p&gt;Assuming the above explanations are correct, my question is: how does the GPU know which of these two scenarios are happening.&lt;/p&gt;&#xA;&lt;p&gt;I reckon that it does by projecting the pixel area in texture space, as it is done for selecting the mipmap level. But even if that's the answer, how is this projection achieved? I'm failing to visualize it.&lt;/p&gt;&#xA;" OwnerUserId="8807" LastEditorUserId="8807" LastEditDate="2020-12-01T20:19:30.327" LastActivityDate="2020-12-01T20:55:22.450" Title="How does the GPU know whether to magnify/minify?" Tags="&lt;texture&gt;&lt;sampling&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10448" PostTypeId="2" ParentId="10447" CreationDate="2020-12-01T20:55:22.450" Score="2" Body="&lt;p&gt;Minification vs magnification is an extension of mipmap selection. When you calculate the desired mip level, it can come out to be less than 0 (or in general, less than the sampler's configured minimum LOD). In that case you're doing magnification of the lowest mip level. If the desired level comes out to a value greater than 0 then you're doing minification.&lt;/p&gt;&#xA;&lt;p&gt;Mipmap selection works by calculating differences of the UV coordinates between adjacent pixels on screen (see &lt;a href=&quot;http://www.aclockworkberry.com/shader-derivative-functions/&quot; rel=&quot;nofollow noreferrer&quot;&gt;shader derivative functions&lt;/a&gt;). Since the GPU is always shading pixels in 2×2 quads, it can look at the set of UVs input to the sampling operation across all those pixels. Those derivative vectors establish what the pixel footprint in texel space is, and their lengths are used to calculate which mip level to sample.&lt;/p&gt;&#xA;&lt;p&gt;The details of how these calculations work exactly can be found in &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf#section.8.14&quot; rel=&quot;nofollow noreferrer&quot;&gt;the OpenGL spec, section 8.14 &amp;quot;Texture Minification&amp;quot;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-01T20:55:22.450" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10450" PostTypeId="1" CreationDate="2020-12-02T06:28:58.240" Score="1" ViewCount="94" Body="&lt;p&gt;There are some 3D applications which can cast shadow or silhouette below 3D models. They render pretty fast and smooth. I wonder what kind of technology is the standard procedure to get 3D model shadow/silhouette.&lt;/p&gt;&#xA;&lt;p&gt;For example is there any C++ library like &lt;a href=&quot;https://github.com/libigl/libigl&quot; rel=&quot;nofollow noreferrer&quot;&gt;libigl&lt;/a&gt; or &lt;a href=&quot;https://github.com/CGAL/cgal&quot; rel=&quot;nofollow noreferrer&quot;&gt;CGAL&lt;/a&gt; to get shadow/silhouette pretty fast? Or maybe GLSL shading is used? Any hint would be appreciated on the standard technology stack.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9QPWG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9QPWG.png&quot; alt=&quot;Screenshot&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="9169" LastActivityDate="2020-12-16T04:27:37.800" Title="Silhouette below 3D model" Tags="&lt;3d&gt;&lt;computational-geometry&gt;&lt;mesh&gt;&lt;shadow&gt;&lt;silhouette&gt;" AnswerCount="3" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10451" PostTypeId="1" CreationDate="2020-12-02T06:32:31.827" Score="0" ViewCount="19" Body="&lt;p&gt;I wonder how software like apitrace is able to output the call trace in OpenGL. Are calls to GPU possible to intercept for a given frame?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastActivityDate="2020-12-02T06:32:31.827" Title="How to intercept call trace in OpenGL" Tags="&lt;opengl&gt;&lt;debugging&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10452" PostTypeId="1" CreationDate="2020-12-02T13:35:31.493" Score="2" ViewCount="32" Body="&lt;p&gt;In a particle simulation, I am rendering particles as &amp;quot;spheres&amp;quot; using GL_POINTS instead of a mesh for efficiency. With &lt;code&gt;glEnable(GL_PROGRAM_POINT_SIZE)&lt;/code&gt; I can use &lt;code&gt;gl_PointSize&lt;/code&gt; from the vertex shader to set the size of my resulting 2D point in screen space pixels.&lt;/p&gt;&#xA;&lt;p&gt;I have the projection matrix, view matrix and the particle position in my vertex shader.&lt;/p&gt;&#xA;&lt;p&gt;My current approach has been&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec4 pos = proj * view * vec4(position, 1.0);&#xA;gl_PointSize = POINT_RADIUS / pos.w;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;, which works, but &lt;code&gt;POINT_RADIUS&lt;/code&gt; is not in world space, but rather the pixel size on my near plane (of the perspective projection).&lt;/p&gt;&#xA;&lt;p&gt;How would I calculate the point size in screen space from a given radius in world space? I can only think of kinda hacky solutions. Is there some mathematically clean or obvious approach to this?&lt;/p&gt;&#xA;" OwnerUserId="15232" LastActivityDate="2020-12-02T13:35:31.493" Title="What is the best way to calculate the projected size of a point" Tags="&lt;shader&gt;&lt;projections&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10453" PostTypeId="1" AcceptedAnswerId="10457" CreationDate="2020-12-02T15:29:17.403" Score="2" ViewCount="48" Body="&lt;p&gt;I am a new learner in 3d graphics. So forgive me if I seem to ask something very basic. I am confused how obj files are textured. So far I have seen:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;obj + jpg&lt;/li&gt;&#xA;&lt;li&gt;obj + mtl + jpg&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;When I look online, most say that they are textured by UV mapping. But when I look into the files, I find no specification of the UV mappings, i.e. how to map a pixel in the jpg file to a vertex (or maybe face?) in the obj file? I suppose there is some rule that is used by default. But I really need to know what it is.&lt;/p&gt;&#xA;&lt;p&gt;Any reference, such as official documents, blogs, textbooks, online learning materials would be of great help. Thanks!&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&#xA;I came across an example &lt;a href=&quot;https://www.fileformat.info/format/wavefrontobj/egff.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, called &amp;quot;texture mapped square&amp;quot;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;# A 2 x 2 square mapped with a 1 x 1 square&#xA;# texture stretched to fit the square exactly.&#xA;mtllib master.mtl&#xA;v  0.000000 2.000000 0.000000&#xA;v  0.000000 0.000000 0.000000&#xA;v  2.000000 0.000000 0.000000&#xA;v  2.000000 2.000000 0.000000&#xA;vt 0.000000 1.000000 0.000000&#xA;vt 0.000000 0.000000 0.000000&#xA;vt 1.000000 0.000000 0.000000&#xA;vt 1.000000 1.000000 0.000000&#xA;# 4 vertices&#xA;usemtl wood&#xA;# The first number is the point,&#xA;# then the slash,&#xA;# and the second is the texture point&#xA;f 1/1 2/2 3/3 4/4&#xA;# 1 element&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I assume that the coordinates following &lt;code&gt;vt&lt;/code&gt; commands are the UV coordinates of the corresponding pixels in the texture image. Exactly what do the values mean? Are they normalized coordinates, that is, is the image normalized to have a coordinate system [0,1]x[0,1]?&lt;/p&gt;&#xA;" OwnerUserId="15320" LastEditorUserId="15320" LastEditDate="2020-12-03T06:11:24.860" LastActivityDate="2020-12-03T06:11:24.860" Title="How are obj files textured?" Tags="&lt;3d&gt;&lt;texture&gt;&lt;3dtexture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10454" PostTypeId="1" CreationDate="2020-12-02T16:34:44.530" Score="0" ViewCount="36" Body="&lt;p&gt;I have a question regarding how the Gaussian blur works. A pixel consists on the combination of 3 colors: R,G and B. I have read that the Gaussian kernel is multiplied by the input image&#xA;by placing the center pixel of the kernel on the image pixel and multiplying the values in the original image with the pixels in the kernel that overlap. What I am not sure about is how the multiplication is carried out. For instance, lets suppose the pixel is composed as follows(I have chosen arbitrary numbers):&lt;/p&gt;&#xA;&lt;p&gt;R: 10100010&#xA;G: 01000110&#xA;B: 10001110&lt;/p&gt;&#xA;&lt;p&gt;My question is how the multiplication implemented:&#xA;1- The three colors are &amp;quot;concatenated&amp;quot; meaning that the value in the kernel is multiplied by the concatenation of R,G and B. In this case the concatenation would be 10100010 01000110 10001110&#xA;2- Multiply the value of each color independently by the kernel. This would imply multiplying first R by the kernel, then G by the kernel and then B by the kernel.&lt;/p&gt;&#xA;" OwnerUserId="15321" LastActivityDate="2020-12-02T18:40:15.117" Title="How is the multiplication in Gaussian Blur implemented" Tags="&lt;image-processing&gt;&lt;gaussian-blur&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10455" PostTypeId="2" ParentId="10454" CreationDate="2020-12-02T18:40:15.117" Score="2" Body="&lt;p&gt;Each color is conceptually treated independently. If they were concatenated, multiplying a value with a color close to the maximum possible value for one channel could cause it to overflow into the lower bits of the next.&lt;/p&gt;&#xA;&lt;p&gt;That said, if you’re asking for performance purposes, a lot of the hardware that does this kind of work can perform all of the per-channel multiplies in a single operation.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2020-12-02T18:40:15.117" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10456" PostTypeId="2" ParentId="10423" CreationDate="2020-12-02T18:52:01.127" Score="1" Body="&lt;p&gt;If you look closely at the edge of the sphere, in the first image it is sharp, and in the second image it's blurry, blending into the background color. This suggests to me that it's not the texture, but the ray distribution on the image plane that's the issue. The second image might be distributing rays over a larger area per pixel, for instance by using a wider AA filter, or a wider lens aperture (defocus blur).&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-02T18:52:01.127" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10457" PostTypeId="2" ParentId="10453" CreationDate="2020-12-02T22:11:02.063" Score="3" Body="&lt;p&gt;OBJ files typically contain vertex positions, texture coordinates (also known as UVs), and normals, as well as face data. There are other kinds of things they can contain but those are the most common (see &lt;a href=&quot;http://paulbourke.net/dataformats/obj/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; for a fuller specification).&lt;/p&gt;&#xA;&lt;p&gt;Vertex positions are specified with the &lt;code&gt;v&lt;/code&gt; command, texture coordinates with &lt;code&gt;vt&lt;/code&gt;, and normals with &lt;code&gt;vn&lt;/code&gt;. The faces then reference those values by index using something like &lt;code&gt;f 1/2/3 4/5/6 7/8/9&lt;/code&gt;, where each grouping of values represents a vertex on the face, and the numbers separated by slashes are the position/texture/normal indices.&lt;/p&gt;&#xA;&lt;p&gt;The texture coordinates are the part that tell you what point in the texture image (jpg) goes with that vertex. If you've downloaded or exported a model that has a texture mapping, you should be able to see those &lt;code&gt;vt&lt;/code&gt; commands in the obj file.&lt;/p&gt;&#xA;&lt;p&gt;If a model doesn't have texture coordinates, though, then it most likely needs the help of a human 3D modeler. It is not easy to create usable texture coordinates for a model automatically (this is a big research topic). 3D modeling applications have various tools to help the modeler set up a texture layout, but it still usually needs some hand-tweaking to work well.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2020-12-02T22:20:18.703" LastActivityDate="2020-12-02T22:20:18.703" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10458" PostTypeId="2" ParentId="10450" CreationDate="2020-12-03T10:36:28.993" Score="1" Body="&lt;p&gt;I can't tell you how exactly each 3d modeling software calculates shadows since I don't know their implementations. However, I guess the usual candidates for real-time shadow calculations are used. These are:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://de.wikipedia.org/wiki/Shadow_Mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;Shadow mapping&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Shadow_volume&quot; rel=&quot;nofollow noreferrer&quot;&gt;Shadow Volumes&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;To my knowledge, the second one isn't that popular since it is more complicated and usually computationally more expensive. If you just want to cast a silhouette as a shadow onto a flat surface without caring about the correct lighting of other objects that lie in the shadows you can use a simple approach like this:&lt;/p&gt;&#xA;&lt;p&gt;Select a (single-channel) texture as your render target and clear its content. Now draw all your objects from the top without perspective projection. The fragment shader returns always the same color that must be different from the clear color. In the end, you have a texture that contains all the silhouettes from your objects. Now you only need to render a quad that uses this texture at the correct position into your scene slightly above the flat surface. Set the output color of the fragment shader to black. The alpha channel is either set to 0 if the texture color at the current fragment is equal to the clear color or to a value of your liking if it is not. (This requires blending to be enabled)&lt;/p&gt;&#xA;&lt;p&gt;This is basically a very specialized and simplified shadow mapping special case that uses a texture instead of a z-buffer.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I originally suggested using the stencil buffer for this, but it would add an unnecessary indirection, and getting it working as intended can be quite a pain (at least in OpenGL).&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2020-12-04T08:37:44.113" LastActivityDate="2020-12-04T08:37:44.113" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10459" PostTypeId="1" CreationDate="2020-12-04T01:35:59.153" Score="2" ViewCount="56" Body="&lt;p&gt;I am currently experimenting with some atmospheric scattering in glsl in my OpenGL engine.&#xA;I am experiencing a strange phenomena where a strange band / separation artifact appears along the middle of the screen:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sovGD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Artifact from low altitude&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3FcnL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Artifact from mid altitude&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/w7uJD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Artifact from high altitude&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here is the code responsible for the actual scattering:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#define PI 3.1415926535897932384626433832795&#xA;#define iSteps 16&#xA;#define jSteps 8&#xA;&#xA;vec2 rsi(vec3 r0, vec3 rd, float sr) {&#xA;    // ray-sphere intersection that assumes&#xA;    // the sphere is centered at the origin.&#xA;    // No intersection when result.x &amp;gt; result.y&#xA;    float a = dot(rd, rd);&#xA;    float b = 2.0 * dot(rd, r0);&#xA;    float c = dot(r0, r0) - (sr * sr);&#xA;    float d = (b*b) - 4.0*a*c;&#xA;    if (d &amp;lt; 0.0) return vec2(1e5,-1e5);&#xA;    return vec2(&#xA;        (-b - sqrt(d))/(2.0*a),&#xA;        (-b + sqrt(d))/(2.0*a)&#xA;    );&#xA;}&#xA;&#xA;vec3 atmosphere(vec3 r, vec3 r0, vec3 pSun, float iSun, float rPlanet, float rAtmos, vec3 kRlh, float kMie, float shRlh, float shMie, float g) {&#xA;    // Normalize the sun and view directions.&#xA;    pSun = normalize(pSun);&#xA;    r = normalize(r);&#xA;&#xA;    // Calculate the step size of the primary ray.&#xA;    vec2 p = rsi(r0, r, rAtmos);&#xA;    if (p.x &amp;gt; p.y) return vec3(0,0,0);&#xA;    p.y = min(p.y, rsi(r0, r, rPlanet).x);&#xA;    float iStepSize = (p.y - p.x) / float(iSteps);&#xA;&#xA;    // Initialize the primary ray time.&#xA;    float iTime = 0.0;&#xA;&#xA;    // Initialize accumulators for Rayleigh and Mie scattering.&#xA;    vec3 totalRlh = vec3(0,0,0);&#xA;    vec3 totalMie = vec3(0,0,0);&#xA;&#xA;    // Initialize optical depth accumulators for the primary ray.&#xA;    float iOdRlh = 0.0;&#xA;    float iOdMie = 0.0;&#xA;&#xA;    // Calculate the Rayleigh and Mie phases.&#xA;    float mu = dot(r, pSun);&#xA;    float mumu = mu * mu;&#xA;    float gg = g * g;&#xA;    float pRlh = 3.0 / (16.0 * PI) * (1.0 + mumu);&#xA;    float pMie = 3.0 / (8.0 * PI) * ((1.0 - gg) * (mumu + 1.0)) / (pow(1.0 + gg - 2.0 * mu * g, 1.5) * (2.0 + gg));&#xA;&#xA;    // Sample the primary ray.&#xA;    for (int i = 0; i &amp;lt; iSteps; i++) {&#xA;&#xA;        // Calculate the primary ray sample position.&#xA;        vec3 iPos = r0 + r * (iTime + iStepSize * 0.5);&#xA;&#xA;        // Calculate the height of the sample.&#xA;        float iHeight = length(iPos) - rPlanet;&#xA;&#xA;        // Calculate the optical depth of the Rayleigh and Mie scattering for this step.&#xA;        float odStepRlh = exp(-iHeight / shRlh) * iStepSize;&#xA;        float odStepMie = exp(-iHeight / shMie) * iStepSize;&#xA;&#xA;        // Accumulate optical depth.&#xA;        iOdRlh += odStepRlh;&#xA;        iOdMie += odStepMie;&#xA;&#xA;        // Calculate the step size of the secondary ray.&#xA;        float jStepSize = rsi(iPos, pSun, rAtmos).y / float(jSteps);&#xA;&#xA;        // Initialize the secondary ray time.&#xA;        float jTime = 0.0;&#xA;&#xA;        // Initialize optical depth accumulators for the secondary ray.&#xA;        float jOdRlh = 0.0;&#xA;        float jOdMie = 0.0;&#xA;&#xA;        &#xA;        // Sample the secondary ray.&#xA;        for (int j = 0; j &amp;lt; jSteps; j++) {&#xA;&#xA;            // Calculate the secondary ray sample position.&#xA;            vec3 jPos = iPos + pSun * (jTime + jStepSize * 0.5);&#xA;&#xA;            // Calculate the height of the sample.&#xA;            float jHeight = length(jPos) - rPlanet;&#xA;&#xA;            // Accumulate the optical depth.&#xA;            jOdRlh += exp(-jHeight / shRlh) * jStepSize;&#xA;            jOdMie += exp(-jHeight / shMie) * jStepSize;&#xA;&#xA;            // Increment the secondary ray time.&#xA;            jTime += jStepSize;&#xA;        }&#xA;&#xA;        // Calculate attenuation.&#xA;        vec3 attn = exp(-(kMie * (iOdMie + jOdMie) + kRlh * (iOdRlh + jOdRlh)));&#xA;&#xA;        // Accumulate scattering.&#xA;        totalRlh += odStepRlh * attn;&#xA;        totalMie += odStepMie * attn;&#xA;&#xA;        // Increment the primary ray time.&#xA;        iTime += iStepSize;&#xA;    }&#xA;&#xA;    // Calculate and return the final color.&#xA;    return iSun * (pRlh * kRlh * totalRlh + pMie * kMie * totalMie);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The function is called as so per fragment in the main function:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 color = atmosphere(&#xA;        normalize(position),          &#xA;        vec3(0.0, 6372e3 + camPos.y, 0.0), &#xA;        vec3(0.0, 2.0, -1.0),              &#xA;        48.0,                           &#xA;        6371e3,                         &#xA;        6471e3,                         &#xA;        vec3(5.5e-6, 13.0e-6, 22.4e-6), &#xA;        21e-6,                          &#xA;        8e3,                            &#xA;        1.2e3,                          &#xA;        0.758                           &#xA;    );&#xA;&#xA;    // Apply exposure.&#xA;    color = 1.0 - exp(-1.0 * color);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What is causing these artifacts? Or is this intended behaviour?&lt;/p&gt;&#xA;" OwnerUserId="15325" LastActivityDate="2020-12-04T01:35:59.153" Title="Atmospheric scattering band/seperation artifact" Tags="&lt;opengl&gt;&lt;3d&gt;&lt;glsl&gt;&lt;c++&gt;&lt;atmospherics&gt;" AnswerCount="0" CommentCount="4" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10460" PostTypeId="2" ParentId="10450" CreationDate="2020-12-04T16:26:13.537" Score="3" Body="&lt;p&gt;There is a trick to shadows like this, but only this exact usecase. While you can certainly draw a true shadow using many techniques. The trick is you can just scale the object flat onto the floor plane.&lt;/p&gt;&#xA;&lt;p&gt;So all you need to do is draw the object 2 times one time with a matrix that is scaled to zero on the floor axis. You can also use this technique to draw shadows that arent entirely top down by adding skew to counter the now rotated shadow.&lt;/p&gt;&#xA;&lt;p&gt;This is super easy to implement. No extra cameras. But works only on one plane. This is a special case of shadow volumes without the need to draw the volumes.&lt;/p&gt;&#xA;" OwnerUserId="38" LastActivityDate="2020-12-04T16:26:13.537" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10461" PostTypeId="1" AcceptedAnswerId="10462" CreationDate="2020-12-04T16:34:47.120" Score="0" ViewCount="65" Body="&lt;p&gt;I am trying to derive the material reflectance values from a color picker tool(say MS Paint).&#xA;My understanding is to first gamma decode(raise to the power of 2.2) the RGB values from the color picker, so to bring it back to linear space, and then use it in Radiance mat definition.&lt;/p&gt;&#xA;&lt;p&gt;However in the &lt;a href=&quot;https://floyd.lbl.gov/radiance/book/&quot; rel=&quot;nofollow noreferrer&quot;&gt;“Rendering with Radiance” book by Greg Ward&lt;/a&gt; section 5.1.4 &amp;quot;Estimating Surface Color&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://ibb.co/mcxVZVn&quot; rel=&quot;nofollow noreferrer&quot;&gt;page 294&lt;/a&gt; and &lt;a href=&quot;https://ibb.co/ZWZZzCB&quot; rel=&quot;nofollow noreferrer&quot;&gt;page 295&lt;/a&gt;, the rgb values from the color picker are raised to the power of inverse of gamma (1/2.2) and then used as in the material definition.&lt;/p&gt;&#xA;&lt;p&gt;Here is a cropped snapshot of the formula from the above links to the scan copied of the two pages.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wfxSJ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wfxSJ.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;My question is, should the sRGB values from the color picker not be raised to the power of 2.2(decoding) rather than 1/2.2(encoding)?&lt;/p&gt;&#xA;&lt;p&gt;For example for BS4800 “18-B-25 Dark admiralty grey / Merlin” colour sample, &lt;a href=&quot;https://www.e-paint.co.uk/Lab_values.asp&quot; rel=&quot;nofollow noreferrer&quot;&gt;this webpage&lt;/a&gt; shows sRGB=104,112,116 and LRV value as approx. 16%. This matches closely to my understanding of (112/256) ^ 2.2 = 0.16 (just for the green component).&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ToXyh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ToXyh.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6041" LastActivityDate="2020-12-04T19:19:50.897" Title="Converting from RGB Color Picker to Surface Reflectance" Tags="&lt;reflection&gt;&lt;material&gt;&lt;gamma&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10462" PostTypeId="2" ParentId="10461" CreationDate="2020-12-04T19:19:50.897" Score="1" Body="&lt;p&gt;Yes, I think you're right. The values from a typical color picker would be in a gamma encoding or sRGB encoding and would need to be converted to linear to use as reflectance. This is probably just a mistake in the book.&lt;/p&gt;&#xA;&lt;p&gt;(BTW, in case you're not aware, sRGB isn't actually gamma 2.2 but &lt;a href=&quot;https://en.wikipedia.org/wiki/SRGB#Specification_of_the_transformation&quot; rel=&quot;nofollow noreferrer&quot;&gt;a more complicated transfer function&lt;/a&gt;.)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-04T19:19:50.897" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10464" PostTypeId="1" CreationDate="2020-12-05T21:18:52.850" Score="2" ViewCount="80" Body="&lt;p&gt;I want to add spectral rendering and dispersion to my pathtracer. I found the &lt;a href=&quot;https://cgg.mff.cuni.cz/%7Ewilkie/Website/EGSR_14_files/WNDWH14HWSS.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hero Wavelength paper&lt;/a&gt; but I have trouble implementing this. This is how I understand the process and where I am stuck:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;When generating a ray, randomly sample a hero wavelength &lt;span class=&quot;math-container&quot;&gt;$\lambda_h$&lt;/span&gt; with probability &lt;span class=&quot;math-container&quot;&gt;$p(\lambda_h)$&lt;/span&gt;. Is uniform sampling good enough?&lt;/li&gt;&#xA;&lt;li&gt;Now, generate &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; other wavelengths (a spectrum) using the rotation function &lt;span class=&quot;math-container&quot;&gt;$r_j$&lt;/span&gt;. Do we generate &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; others, or &lt;span class=&quot;math-container&quot;&gt;$C-1$&lt;/span&gt; so that in total there are &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; wavelengths?&lt;/li&gt;&#xA;&lt;li&gt;In the integrator when the BSDF contribution is evaluated, sample &lt;em&gt;one&lt;/em&gt; of those &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; wavelengths and call it &lt;span class=&quot;math-container&quot;&gt;$\lambda_s$&lt;/span&gt;. Does this include the hero wavelength? Are they sampled uniformly?&lt;/li&gt;&#xA;&lt;li&gt;Evaluate the BSDF for &lt;span class=&quot;math-container&quot;&gt;$\lambda_s$&lt;/span&gt; and add the contribution, weighted by the MIS weight and the probability of choosing this wavelength. How is the MIS weight computed? The paper says: &lt;span class=&quot;math-container&quot;&gt;$w_s(X_i, \lambda_i^s) = \frac{p(\lambda_i^h) p(X_i | \lambda_i^h)}{\sum_{k=1}^C p(\lambda_i^k) p(X_i | \lambda_i^k)}$&lt;/span&gt; but where does the probability &lt;span class=&quot;math-container&quot;&gt;$p(X_i | \lambda_i^k)$&lt;/span&gt; come from? Do I have to evaluate the BSDF direction for each wavelength to get a probability of choosing this path?&lt;/li&gt;&#xA;&lt;li&gt;Generate the next path direction based on the BSDF and the hero wavelength.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;My current implementation doesn't really differ from the single wavelength per ray model and has lots of coloured noise. As for the dielectric, I do:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;compute IOR based on wavelength and the dispersion formula for a given material&lt;/li&gt;&#xA;&lt;li&gt;compute fresnel with this new IOR&lt;/li&gt;&#xA;&lt;li&gt;use a wavelength to RGB conversion to compute the material contribution&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mRtIn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mRtIn.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7913" LastActivityDate="2020-12-05T21:18:52.850" Title="Hero wavelength multiple importance sampling" Tags="&lt;pathtracing&gt;&lt;importance-sampling&gt;&lt;spectral&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10465" PostTypeId="2" ParentId="10048" CreationDate="2020-12-06T09:50:00.090" Score="0" Body="&lt;p&gt;This is how I ended up doing it:&lt;/p&gt;&#xA;&lt;p&gt;Instead of using vertex colors like most of the solutions I found online, I calculated the angle of each edge, and then used a shader to draw the lines in UV space. This Also gives me control over how thick the lines should be.&lt;/p&gt;&#xA;&lt;p&gt;In some cases the angle calculated isn't right, but that should be easy to fix.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/yoqrt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yoqrt.png&quot; alt=&quot;Curvature map applied to a model&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here is the project: &lt;a href=&quot;https://github.com/Jummit/curvature-baker&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Jummit/curvature-baker&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13729" LastActivityDate="2020-12-06T09:50:00.090" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10467" PostTypeId="1" CreationDate="2020-12-06T18:01:39.860" Score="4" ViewCount="80" Body="&lt;p&gt;Unsure if this is the right network to post this, but maybe someone can help...&lt;/p&gt;&#xA;&lt;p&gt;I'm working on a personal project where, with the help of AI, I want to automatically estimate the perspective of a given image.&lt;/p&gt;&#xA;&lt;p&gt;I've been able to programatically estimate and draw the position of the horizon, as seen below. This is based on how &amp;quot;quickly&amp;quot; cars farther away shrink in the image.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/q7fKtm.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/q7fKtm.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Not sure the above is useful, but now I want to draw a grid on the plane. Something like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9LOFgm.png&quot; rel=&quot;noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9LOFgm.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is where it's getting too complicated for me. I have no idea how to solve this. Not the drawing per se, but the mathematics behind it. Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="15340" LastActivityDate="2020-12-21T11:15:00.397" Title="Project grid on 2d plane based on camera perspective" Tags="&lt;projections&gt;&lt;perspective&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10468" PostTypeId="1" CreationDate="2020-12-07T23:21:05.330" Score="1" ViewCount="57" Body="&lt;p&gt;I wrote a rather elegant and compact &lt;a href=&quot;https://en.wikipedia.org/wiki/Photon_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;Photon Mapper&lt;/a&gt; in &lt;a href=&quot;https://en.wikipedia.org/wiki/CUDA&quot; rel=&quot;nofollow noreferrer&quot;&gt;CUDA&lt;/a&gt;. But I treat all my photons they same, and ignore their colour.&lt;/p&gt;&#xA;&lt;p&gt;This simplicity has some nice properties: e.g. I can just count them with one integer value for each little subdivision patch on the surface.&lt;/p&gt;&#xA;&lt;p&gt;However, to properly model the global illumination, I should take into account the colour, after a photon bounces from a surface. (A red carpet, reflects red light onto a nearby wall, not white light.)&lt;/p&gt;&#xA;&lt;p&gt;An obvious approach would be to replace the single integer count with three floating point counters, for R, G and B.&lt;/p&gt;&#xA;&lt;p&gt;But I feel there must be a more elegant solution to this? Russian roulette on the R/G/B channels perhaps? Although this would create more noise? But it would mean fewer data per photon, and thus better use of the cache?&lt;/p&gt;&#xA;" OwnerUserId="6562" LastActivityDate="2020-12-09T18:46:43.253" Title="How to count the photons when Photon Mapping" Tags="&lt;global-illumination&gt;&lt;photon-mapping&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10469" PostTypeId="1" CreationDate="2020-12-08T00:16:55.543" Score="0" ViewCount="24" Body="&lt;p&gt;I would like to draw onto a plane with a 2d texture when pressing down the mouse. Similar to drawing on a canvas with a texture brush with continuous stroke in painting applications.&lt;/p&gt;&#xA;&lt;p&gt;I was thinking that we could basically draw the texture onto canvas, by using a textured quad corresponding to desired brush size, and then simply not update the color buffer when moving the textured quad around. Thus filling it with pixels. When mouse is up we want to start updating the color buffer again, such that texture is no longer applied to the canvas. But this clears the existing content in the framebuffer. We could save the content of the framebuffer with &lt;code&gt;glReadPixels()&lt;/code&gt; to a texture. And then load a full screen quad with the said texture into the framebuffer on each frame. When we want to draw again we stop updating the buffer and repeat.&lt;/p&gt;&#xA;&lt;p&gt;Does this seems like a practical solution or is there maybe a better way to approach this?&lt;/p&gt;&#xA;&lt;p&gt;Edit: From what I know image processing applications perform this kind of tasks on CPU. I'm trying to do it on GPU mostly because OpenGL does the work for me and I'm lazy. But from performance standpoint the GPU approach should also be faster right? So I wonder why image processing software doesn't choose to utilize GPU? Is this because GPU is too restrictive for this kind of tasks?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-12-08T06:40:09.907" LastActivityDate="2020-12-08T06:40:09.907" Title="Possible approach to drawing with a texture brush" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10470" PostTypeId="2" ParentId="10316" CreationDate="2020-12-08T01:43:56.263" Score="1" Body="&lt;p&gt;I'm assuming that you don't know how many objects there will be or have any way to index them until the image processing operations are completed, i.e. you have some final pass that determines for each pixel &amp;quot;do I want to put an object here, or no&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;OpenGL ES 2.0 is pretty limiting. There may be no better way to do this than what you described: output from the fragment shader to a texture, pull it back to the CPU to extract the points, then put those into a uniform buffer for the second pass.&lt;/p&gt;&#xA;&lt;p&gt;One thing you could attempt, though I'm unsure if it could be fully made to work in ES 2.0, is to do a &lt;a href=&quot;https://developer.nvidia.com/gpugems/gpugems3/part-vi-gpu-computing/chapter-39-parallel-prefix-sum-scan-cuda&quot; rel=&quot;nofollow noreferrer&quot;&gt;parallel prefix sum&lt;/a&gt; over the output texture from the first pass. This would involve recursive fragment shader reduction passes (a little bit like generating mipmaps) that would first count up the number of objects within each region of the image, starting with 2×2 regions and doubling at each step until you've covered the full image, then go back down the mip chain and calculate the prefix sums, which are the number of objects &amp;quot;before&amp;quot; each region (using some defined ordering). At the end of that, you would have the exact index where to store each object into an output buffer.&lt;/p&gt;&#xA;&lt;p&gt;FYI, in GL ES 3.1 and other more fully-featured APIs, there are shader atomic counters, which allow implementing an &amp;quot;append buffer&amp;quot;; your first fragment shader pass could output directly to this buffer, then turn around and use it for an input buffer, or for indirect draw parameters, on the next pass.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-08T01:43:56.263" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10471" PostTypeId="2" ParentId="9303" CreationDate="2020-12-08T09:00:02.000" Score="-1" Body="&lt;p&gt;I don't know if you just didn't write it or really intended not to do it, but in general it's now enough to check the velocity vectors for inersection. First off, the vectors might intersect but the balls pass the intersection point on different times, resulting in no collision. Second, you do not take the radius of each ball into consideration.&lt;/p&gt;&#xA;&lt;p&gt;From my (limited) experience, contiuous collision detection is either done with a technique called &lt;em&gt;conservative advancement&lt;/em&gt;, &lt;em&gt;signed distance field&lt;/em&gt; or (which would apply for your case) solving for a mathmatical equation dependent on time &lt;span class=&quot;math-container&quot;&gt;$t\in[0,1]$&lt;/span&gt;. Even with bent trajectories you are able to do this.&lt;/p&gt;&#xA;&lt;p&gt;Once you have solved for &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; and computed all pair-wise collisions (all 16 balls with each other and possibly the edges in some way), you can sort them by their collision time &lt;span class=&quot;math-container&quot;&gt;$t_i$&lt;/span&gt; (earliest collisions should be handled first) and solve the collision restrains with some phyiscal response. Because of the nature of continuous collision detection, you will not have an actual intersection where you would get the contact normal and penetration depth from. Usually you will have some distance of two balls that qualify (numerically) as a collision, like &lt;span class=&quot;math-container&quot;&gt;$d(B_1, B_2) &amp;lt; \varepsilon$&lt;/span&gt;. But there are mutliple easy ways to fix this, particularly for you scenario.&lt;/p&gt;&#xA;&lt;p&gt;After you have solved all the collisions and updated all velocities, you have to repeat the whole process because there might now be different collisions between different balls. In theory, you would have to repeat this until all collisions have been properly solved. However, there might be cases where there are somewhat cyclic collisions (think &lt;a href=&quot;https://en.wikipedia.org/wiki/Newton%27s_cradle&quot; rel=&quot;nofollow noreferrer&quot;&gt;Newton's cradle&lt;/a&gt;) and these will be tough to properly handle. Again, this is up to implementation but a good start (at least to avoid infite collisions) would be to use a limited number of iterations per frame for this.&lt;/p&gt;&#xA;&lt;p&gt;Then, after finishing all collisions for one frame, you finally can render you scene.&lt;/p&gt;&#xA;&lt;p&gt;Good luck with your project! I know how tough it can be to implement a proper collision detection, let alone a continuous collision detection.&lt;/p&gt;&#xA;" OwnerUserId="15345" LastActivityDate="2020-12-08T09:00:02.000" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10472" PostTypeId="1" CreationDate="2020-12-09T07:01:02.123" Score="0" ViewCount="17" Body="&lt;p&gt;I have a pretty basic widget rendering, largely based upon the learnopengl.com &amp;quot;hello triangle.&amp;quot; I'm actually using a tristrip to create two triangles, forming a semi-opaque square over the top of the other stuff in my window. In this square, I'm using the fragment shader to set the semi-opaque background color and an arrow that points in the direction of flight. What I want to do next is render a &lt;code&gt;GL_LINES&lt;/code&gt; vertex buffer that contains the historical position of the aircraft.&lt;/p&gt;&#xA;&lt;p&gt;It seems easy enough to set up a second vertex attribute object and vertex buffer, but what is unclear to me is whether it's possible to use a single vertex &amp;amp; fragment shader pair to handle this second dataset. It wouldn't be terribly difficult to set up a group of widgets to render the opaque square, then the historical course information, then the arrow, but I already have the first and third stages working.... and breaking everything up would mean 3 vertex and 3 fragment shaders.&lt;/p&gt;&#xA;&lt;p&gt;I'm guessing that it's impossible to deal with the semi-opaque background, the historic course, and the arrow all in one vertex/fragment shader pair, but it'd be obtuse to just make that assumption and make a mess out of some tolerably organized code before I got an informed answer.&lt;/p&gt;&#xA;" OwnerUserId="9779" LastActivityDate="2020-12-09T07:01:02.123" Title="Rendering different array types in the same vertex/fragment shader?" Tags="&lt;shader&gt;&lt;fragment-shader&gt;&lt;vertex-buffer-object&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10474" PostTypeId="2" ParentId="10468" CreationDate="2020-12-09T18:46:43.253" Score="2" Body="&lt;p&gt;I'm not sure if I understand your question correctly and don't know what you mean by &amp;quot;counting&amp;quot; and how you want to replace this by &amp;quot;color&amp;quot;. A simple photon mapper looks like this: 1) photon tracing: emit, scatter, store photons 2) path tracing: gather photons in a given radius and approximate radiance using this density.&lt;/p&gt;&#xA;&lt;p&gt;To be more precise, in pseudocode (with russian roulette) this would look like:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;xi&lt;/code&gt; is the position, &lt;code&gt;wo&lt;/code&gt; the outgoing direction, &lt;code&gt;W&lt;/code&gt; the photon power. All three are vectors of length 3. &lt;code&gt;p&lt;/code&gt; is the probability of the Russian roulette. A photon is a struct that stores the power, direction, and position.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;xi, wo, W = emitter.sample()&#xA;while(true)&#xA;   xi = traceRay(xi, wo)&#xA;   if(isDiffuse(xi))&#xA;      storePhoton(xi, wo, W)&#xA;&#xA;   if(rand &amp;lt; p)&#xA;      break&#xA;    W /= p;&#xA;    &#xA;    wo = bsdf.sample(xi)&#xA;    W *= bsdf(wo)/pdf(wo)*cos&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;You repeatedly call this function for a random emitter until you stored a predefined amount of photons (e.g. 500'000). After this, you &lt;em&gt;build&lt;/em&gt; the photonmap, such as a k-d tree to make querying easy. As you can see, the &amp;quot;color&amp;quot; is stored in the power of the photon.&lt;/p&gt;&#xA;&lt;p&gt;The next step is the gathering the photons, and it's normal path tracing but when you hit a diffuse surface, you gather all the photons in a fixed radius (other kernels can also be used). Here, &lt;code&gt;t&lt;/code&gt; is the throughput, &lt;code&gt;wi&lt;/code&gt; the incoming direction, the &lt;code&gt;photon_map&lt;/code&gt; is the datastructure that we build before and populated with photons, and &lt;code&gt;total_photons&lt;/code&gt; is the total amount of photons that we emitted.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;...&#xA;&#xA;if(isDiffuse(xi))&#xA;   for photon: photon_map.get(xi, radius)&#xA;      radiance *= t*bsdf(xi, wi, photon.wo) * photon.power / (pi*radius^2 * total_photons)&#xA;   break&#xA;...&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="7913" LastActivityDate="2020-12-09T18:46:43.253" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10475" PostTypeId="2" ParentId="10438" CreationDate="2020-12-09T20:34:00.587" Score="0" Body="&lt;p&gt;Since you already have convex shapes and started looking at the &amp;quot;Method of separating axis&amp;quot;, then the &lt;a href=&quot;https://en.wikipedia.org/wiki/Gilbert%E2%80%93Johnson%E2%80%93Keerthi_distance_algorithm&quot; rel=&quot;nofollow noreferrer&quot;&gt;GJK&lt;/a&gt; algorithm is probably what you're looking for. This is commonly used in physics simulations to find collisions (for games, I don't know about computational science).&lt;/p&gt;&#xA;&lt;p&gt;When you say &amp;quot;remove intersections without generating others&amp;quot;, then you're asking for collision response. Multiple collision response is actually a tough beast. &lt;a href=&quot;http://www.cs.columbia.edu/cg/rosi/rosi.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt; (Reflections on Simultaneous Impact) is a paper that goes into more detail, but a very good introduction to this are course notes from Baraff:&#xA;&lt;a href=&quot;https://www.cs.cmu.edu/%7Ebaraff/sigcourse/notesd1.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;An Introduction to Physically Based Modeling: Rigid Body Simulation I—Unconstrained Rigid Body Dynamics&lt;/a&gt; and part 2. &lt;a href=&quot;https://www.cs.cmu.edu/%7Ebaraff/sigcourse/notesd2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Rigid Body Simulation II-Nonpenetration Constraints&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Lastly, you can always use a physics engine for this, such as &lt;a href=&quot;https://github.com/bulletphysics/bullet3&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bullet3d&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7913" LastActivityDate="2020-12-09T20:34:00.587" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10476" PostTypeId="1" CreationDate="2020-12-10T11:40:00.203" Score="0" ViewCount="39" Body="&lt;p&gt;I'm trying to write a little program with a bouncing cube but I can't find the right x, y, z and angle for it. I have these lines:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;modelMatrix = glm::mat4(1)&#xA;&#xA;modelMatrix *= Translate(x, y, z)&#xA;&#xA;modelMatrix *= RotateOZ(angle)&#xA;&#xA;RenderMesh(mesh[&amp;quot;cube&amp;quot;], shaders[&amp;quot;V&amp;quot;], modelMatrix)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I added a picture to make it easier to understand. My cube will start at x0, y0, z0(we can leave the z out of this because for now I want the cube to move only in the OX axis and OY). I added a arrow the cube so I can represent the rotation better. First he will move forward on the OX and OY axis while rotating in the range of [0 - 90] grades when he will hit X1(which is X / 2) and Y1 then he will rotate in the range of [90 - 180] grades while moving forward on the OX and descending on the OY. I hope that made sense.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/r0yU7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/r0yU7.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;My problem is that I can't find the right x, y and angle to give to these transformations so I can get the animation that I want. I tried to add to x, y and angle the same value such as 0.1 and the result is close but not perfect.&#xA;RotateOZ return a mat4:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;return glm::mat4(&#xA;        cos(angle), -sin(angle), 0, 0,&#xA;        sin(angle), cos(angle), 0, 0,&#xA;        0, 0, 1, 0,&#xA;        0, 0, 0, 1&#xA;    );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Thank you for your time!&lt;/p&gt;&#xA;" OwnerUserId="15361" LastActivityDate="2020-12-10T11:40:00.203" Title="3D Bouncing Cube" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;physics&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10477" PostTypeId="1" AcceptedAnswerId="10478" CreationDate="2020-12-10T12:26:47.010" Score="0" ViewCount="27" Body="&lt;p&gt;I would like to implement a random placement for objects like trees stones etc. on a triangles surface.&#xA;The important part is to have an equally probability to place an object on this surface. That means, that for example to randomly place a tree in the middle should not be higher than placing it at a corner / edge.&lt;/p&gt;&#xA;&lt;p&gt;The second requirement is to program this placement algorithm onto the GPU by using OpenGL/GLSL. So randomly generate a position and loop as long as it is not inside the triangle is no option because of branching...  I need to place tons of objects per frame...&lt;/p&gt;&#xA;&lt;p&gt;I had the idea of using Barycentric coordinates where the three scalars are randomly generated. but it turned out, that the middle and the lines from the middle to the middle of an edge is more probably than hitting a corner. The good thing about Barycentric coordinates is, that the surface of the 3D triangle is always hit, so the generated position is not above or outside the triangle. Another plus is, that to calculate the Barycentric coordinate is extremely fast during using multiplication of 3D vectors with scalars and addition of vectors with vectors.&lt;/p&gt;&#xA;&lt;p&gt;here is my C++ code to generate random positions on the triangles' surface.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;string&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xA;&#xA;struct Vector3D&#xA;{&#xA;public:&#xA;&#xA;    Vector3D()&#xA;    {&#xA;&#xA;    }&#xA;&#xA;    Vector3D(double x, double y, double z)&#xA;    {&#xA;        this-&amp;gt;x = x;&#xA;        this-&amp;gt;y = y;&#xA;        this-&amp;gt;z = z;&#xA;    }&#xA;&#xA;    void operator*=(double factor)&#xA;    {&#xA;        x *= factor;&#xA;        y *= factor;&#xA;        z *= factor;&#xA;    }&#xA;&#xA;    void operator+=(double factor)&#xA;    {&#xA;        x += factor;&#xA;        y += factor;&#xA;        z += factor;&#xA;    }&#xA;&#xA;    Vector3D operator*(double factor)&#xA;    {&#xA;        Vector3D result;&#xA;        result.x = x * factor;&#xA;        result.y = y * factor; &#xA;        result.z = z * factor; &#xA;        return result;&#xA;    }&#xA;&#xA;    Vector3D operator+(Vector3D v2)&#xA;    {&#xA;        Vector3D result;&#xA;        result.x = x + v2.x;&#xA;        result.y = y + v2.y;&#xA;        result.z = z + v2.z;&#xA;        return result;&#xA;    }&#xA;&#xA;    double x;&#xA;    double y;&#xA;    double z;&#xA;};&#xA;&#xA;&#xA;Vector3D getBarycentricPosition(Vector3D p0, Vector3D p1, Vector3D p2, double scalar0, double scalar1, double scalar2)&#xA;{&#xA;    return (p0 * scalar0) + (p1 * scalar1) + (p2 * scalar2);&#xA;}&#xA;&#xA;&#xA;void main()&#xA;{&#xA;    Vector3D p0(1, 0, 0);&#xA;    Vector3D p1(0, 1, 0);&#xA;    Vector3D p2(0, 0, 1);&#xA;&#xA;    std::ofstream writefile(&amp;quot;C:/Data[![enter image description here][1]][1]/barycentricTest.obj&amp;quot;);&#xA;    if (writefile.is_open())&#xA;    {&#xA;        for (unsigned int i = 0; i &amp;lt; 100000; ++i)&#xA;        {&#xA;            //generate random values&#xA;            double random0 = rand() % 1000;&#xA;            double random1 = rand() % 1000;&#xA;            double random2 = rand() % 1000;&#xA;&#xA;            //&#xA;            double powFactor = 1.0f;&#xA;            random0 = pow(random0, powFactor);&#xA;            random1 = pow(random1, powFactor);&#xA;            random2 = pow(random2, powFactor);&#xA;&#xA;            int sum = random0 + random1 + random2;&#xA;&#xA;            //scalar0 + scalar1 + scalar2 = 1 !!&#xA;            double scalar0 = static_cast&amp;lt;double&amp;gt;(random0) / static_cast&amp;lt;double&amp;gt;(sum);&#xA;            double scalar1 = static_cast&amp;lt;double&amp;gt;(random1) / static_cast&amp;lt;double&amp;gt;(sum);&#xA;            double scalar2 = static_cast&amp;lt;double&amp;gt;(random2) / static_cast&amp;lt;double&amp;gt;(sum);&#xA;&#xA;            Vector3D p = getBarycentricPosition(p0, p1, p2, scalar0, scalar1, scalar2);&#xA;   &#xA;            //write to .obj file to see results in blender&#xA;            writefile &amp;lt;&amp;lt; &amp;quot;v &amp;quot; &amp;lt;&amp;lt; p.x &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; p.y &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; p.z &amp;lt;&amp;lt; std::endl;&#xA;        }&#xA;        writefile.close();&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;By looking at the code, you'll recognize, that there is the double &lt;em&gt;powFactor&lt;/em&gt;. I tried to bring the probability of the corners a little bit up.&lt;/p&gt;&#xA;&lt;p&gt;Here are some images with different &lt;em&gt;powFactor&lt;/em&gt; values.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;powFactor = 1.0   So without influencing the algorithm&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/gsTyd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gsTyd.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;powFactor = 1.3&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/lEua0.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/lEua0.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Like you can see, to pow with 1.3 looks good inside, but the corners / edges are over weighted...&lt;/p&gt;&#xA;&lt;p&gt;Is there a fast algorithm (branching free) which gives good results?&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2020-12-10T19:47:13.923" Title="Equally distribution on triangle surfaces" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;distribution&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10478" PostTypeId="2" ParentId="10477" CreationDate="2020-12-10T19:47:13.923" Score="1" Body="&lt;p&gt;Barycentric coordinates need to sum to 1.0, so pick two of them (say &lt;span class=&quot;math-container&quot;&gt;$u, v$&lt;/span&gt;) randomly from [0, 1] and then set the third as &lt;span class=&quot;math-container&quot;&gt;$w = 1 - u - v$&lt;/span&gt;. This will give you random points that are evenly distributed with respect to area, in a parallelogram consisting of two copies of the triangle. Then, you can reflect across the triangle edge to bring both copies of the triangle together. This can be done by checking if &lt;span class=&quot;math-container&quot;&gt;$u + v &amp;gt; 1$&lt;/span&gt;, and if so, reflect by setting &lt;span class=&quot;math-container&quot;&gt;$u' = 1-u,\, v' = 1-v$&lt;/span&gt; and then recalculate &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;See also: &lt;a href=&quot;https://blogs.sas.com/content/iml/2020/10/19/random-points-in-triangle.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Generate random points in a triangle&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-10T19:47:13.923" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10479" PostTypeId="1" CreationDate="2020-12-11T06:05:49.823" Score="1" ViewCount="20" Body="&lt;p&gt;In a passive-matrix LCD we have horizontal and vertical conductors. The intersection points are pixels which are  cells of liquid crystal molecules . For drawing a frame, we provide the necessary voltages to specific conductors.&#xA;But once we have provided the voltages and the picture has been drawn on the screen ,why do we need to refresh.&#xA;As long as the voltage is on ,the picture is still there ....it's not like a CRT where the emission from phosphorus atoms decays.&#xA;If the reason is video or animation, then we are changing the frame buffer and then drawing the new frame buffer.&#xA;But do we need to refresh the same frame buffer at some rate ?&#xA;If so , why ?&lt;/p&gt;&#xA;" OwnerUserId="15364" LastActivityDate="2020-12-11T06:05:49.823" Title="Why refresh rate is needed in a passive-matrix LCD?" Tags="&lt;pixel-graphics&gt;&lt;hardware&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10480" PostTypeId="1" CreationDate="2020-12-11T07:07:34.443" Score="0" ViewCount="21" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xZsLD.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xZsLD.jpg&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&#xA;In the picture the horizontal and vertical lines are the conductors and the intersections are the pixel positions&#xA;I want to turn off the pixels which I've filled&#xA;So for that I've to apply an electric field across these pixels&#xA;For one pixel I have to apply voltage to conductor 1 and a&#xA;And for the other one apply voltage to 2 and b&#xA;But when these  conductors are conducting ....then the pixels which I've shown with just a circle also get turned off.&#xA;How exactly is then an entire frame buffer drawn on the screen?&lt;/p&gt;&#xA;" OwnerUserId="15364" LastActivityDate="2020-12-11T07:07:34.443" Title="Applying voltages to conductors in passive-matrix LCD" Tags="&lt;pixel-graphics&gt;&lt;frame-buffer&gt;&lt;hardware&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10481" PostTypeId="2" ParentId="3605" CreationDate="2020-12-11T12:46:28.477" Score="0" Body="&lt;p&gt;gl_VertexID Is the way to go, you quickly run out of attribs if you need a normal mapped skeletal character, there’s only room for 2-3 blend shapes to fit in 16 attribs&lt;/p&gt;&#xA;" OwnerUserId="15366" LastActivityDate="2020-12-11T12:46:28.477" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10483" PostTypeId="1" AcceptedAnswerId="10485" CreationDate="2020-12-12T01:56:10.497" Score="1" ViewCount="35" Body="&lt;p&gt;Subdivision schemes work by considering the vertices and their connectivity information to calculate averaging weights.&lt;/p&gt;&#xA;&lt;p&gt;However, other than specifying which vertices are connected, and perhaps which weights to use (in the case of loop subdivision for example), edges don;t really play a role.&lt;/p&gt;&#xA;&lt;p&gt;Same as faces. I am wondering if there is a subdivision scheme that attaches &amp;quot;weights&amp;quot; (and weights could be either scalars or matrices or similar vector fields) and has the faces and edges have a controllable effect on the convergence.&lt;/p&gt;&#xA;&lt;p&gt;For example in the case of meshes, consider a cube. If the weights of the faces are 0, then the subdivision is just a regular subdivision. But if the weights of each face go towards infinity, then the limit of the convergence should be the original cube.&lt;/p&gt;&#xA;&lt;p&gt;I am trying to find something like this, but I cannot find any associated literature with the topic.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-12-12T11:16:38.663" Title="Subdivision scheme where the faces and edges have weights (not necessarily scalar weights)" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;subdivision&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10484" PostTypeId="2" ParentId="10384" CreationDate="2020-12-12T07:28:03.977" Score="0" Body="&lt;p&gt;There are many methods to go about visualizing volume data. Two famous ones are texture slices and ray marching. Texture slices intends to render 3D textures with volume data. Refer to the wiki page for Volume Rendering for more approaches. Ray marching shoots rays through the volume and composites values as the ray progresses through. This is a very simple explanation.&lt;/p&gt;&#xA;&lt;p&gt;Now you can code raymarching in a fragment shader or a compute shader or even on the cpu.&#xA;If you are interested in Raymarching, you can use my project as a reference (I used a compute shader approach)&#xA;&lt;a href=&quot;https://github.com/gallickgunner/Volume-Renderer&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/gallickgunner/Volume-Renderer&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Also these tutorials might come in handy.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://graphicsrunner.blogspot.com/2009/01/volume-rendering-101.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphicsrunner.blogspot.com/2009/01/volume-rendering-101.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;For an in-depth explanation to these topics, refer to the book &amp;quot;Real time Volume Graphics&amp;quot;&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2020-12-12T07:28:03.977" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10485" PostTypeId="2" ParentId="10483" CreationDate="2020-12-12T10:37:58.530" Score="3" Body="&lt;p&gt;What you are looking for is semi-sharp creases. You can find it in section 3 of this paper: &lt;a href=&quot;https://graphics.pixar.com/library/Geri/paper.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://graphics.pixar.com/library/Geri/paper.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Basically, each edge is given a sharpness value &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt;. This can either be a integer or a floating point value. This value signifies how many subdivision steps this edge will be subdivided using sharp-subdivision rules. When subdividing an edge with sharpness &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt;, it subdivide into two edges with sharpness level &lt;span class=&quot;math-container&quot;&gt;$s-1$&lt;/span&gt;. Until &lt;span class=&quot;math-container&quot;&gt;$s$&lt;/span&gt; is 0 and the edge will be subdivided as normal.For fractional levels the last subdivision with &lt;span class=&quot;math-container&quot;&gt;$s \in [0,1]$&lt;/span&gt; the vertices will obtain a blended position between the subdivided &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; and the sharp position &lt;span class=&quot;math-container&quot;&gt;$p_s$&lt;/span&gt;, i.e. &lt;span class=&quot;math-container&quot;&gt;$(1-s)p + s p_s$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The sharp subdivision rules boil down to the following. Vertices at the end of an sharpness tagged edge will remain in the same position and vertices on the sharp edge are refined using the stencil [1, 6, 1]/8 applied to previous, current and next points on the tagged curve respectively. New points are inserted at midpoints of edges.&lt;/p&gt;&#xA;&lt;p&gt;This scheme can be generalized to faces by propagating the sharpness value of a face to its edges.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2020-12-12T11:16:38.663" LastActivityDate="2020-12-12T11:16:38.663" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10486" PostTypeId="1" AcceptedAnswerId="10491" CreationDate="2020-12-13T18:00:33.930" Score="0" ViewCount="78" Body="&lt;p&gt;I am working on a virtual camera inside a game engine, which provides me with an FoV control, but no Focal length control (and no filming sensor dimensions short of aspect ratio), and I am less than a beginner in photography.&lt;/p&gt;&#xA;&lt;p&gt;Now when I position the Camera in a specific location in the world, and I position an object in front of the camera such that the object covers 50 degrees of the camera field horizontally. The camera FoV is 100 degrees horizontally.[see image please].&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ulFNH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ulFNH.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;Then I measure the object in the image and I find it covering around 40% of the image width instead of 50%.&lt;/p&gt;&#xA;&lt;p&gt;What is the most expected mistake that I am making here?&lt;/p&gt;&#xA;&lt;p&gt;Relevant information: I don't know the position of the virtual camera is the position in the middle of the lens itself, the position of the sensory retina, or the position in between.&lt;/p&gt;&#xA;" OwnerUserId="15372" OwnerDisplayName="Physician" LastEditorUserId="5778" LastEditDate="2020-12-20T21:47:30.787" LastActivityDate="2020-12-20T21:47:30.787" Title="Does an object spanning percentage of the Camera's FoV correlate with the object's image percentage?" Tags="&lt;camera&gt;" AnswerCount="4" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10487" PostTypeId="2" ParentId="10486" CreationDate="2020-12-13T18:37:43.327" Score="0" Body="&lt;p&gt;You are probably assuming that the apparent screen size of an object is proportional to the angle, while in fact it is proportional to the &lt;a href=&quot;https://mathworld.wolfram.com/Tangent.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;tangent&lt;/a&gt; of half angle.&lt;/p&gt;&#xA;&lt;p&gt;The difference is small for small angles but big enough at your 100°, try sketching your example for 179° FOV camera and 89.5° (half FOV) object to see how deep the rabbit hole goes.&lt;/p&gt;&#xA;" OwnerUserId="15378" OwnerDisplayName="szulat" LastActivityDate="2020-12-13T18:58:53.223" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10488" PostTypeId="2" ParentId="10486" CreationDate="2020-12-14T01:27:34.287" Score="0" Body="&lt;p&gt;When we calculate the field of view of a lens mounted on a camera, we can evaluate three different unique angles. These are height, width, and diagonal. As an example, if we mount a 46mm lens on a 35mm full frame camera with a format of 24mm by 36mm, the angles of view are 29° height, by 42° length, and 50° diagonal. While likely the last value, the diagonal is value most often given. If you think this is bizarre, consider that TV sets are sized by their diagonal measure.&lt;/p&gt;&#xA;&lt;p&gt;We can trace an object triangle, a trace from its boundary points to a point at the center of the lens. We can also trace an image triangle, inside the camera, beginning from its boundaries to the center of the lens.&lt;/p&gt;&#xA;&lt;p&gt;These two triangles will be “similar”.  Their angles will be identical; their sides will be in ratio. Likely the field of view you are using is in reality the diagonal angle of view, and the image length you are referencing corresponds to the hormonal angle of view.&lt;/p&gt;&#xA;" OwnerUserId="15374" LastActivityDate="2020-12-14T01:27:34.287" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10489" PostTypeId="2" ParentId="154" CreationDate="2020-12-14T04:45:59.667" Score="2" Body="&lt;p&gt;I'd like to add some practical perspective to this.&lt;/p&gt;&#xA;&lt;p&gt;Let me preface that I'm operating on limited information here:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;I don't know how many objects you are dealing with.&lt;/li&gt;&#xA;&lt;li&gt;I don't know what exactly your acceleration structure is used for. Frustum culling? Ray tracing? Collision detection between objects in the BVH?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Going forward I'm going to assume you are talking about frustum culling a few thousand objects.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The number of objects will be too large to render without a hierarchy,&#xA;but for the same reason I expect building the hierarchy to be time&#xA;consuming.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I'd argue that if you have to visit every object every frame in order to calculate a BVH, culling them directly and without a BVH is actually faster.&#xA;This of course depends on your frustum culling implementation. The bounding volumes of all objects should be stored contiguously in memory. This results in more efficient CPU cache utilization and allows for further optimization using SIMD instructions.&#xA;&lt;strong&gt;DICE has a whole presentation on this subject: &lt;a href=&quot;https://www.ea.com/frostbite/news/culling-the-battlefield-data-oriented-design-in-practice&quot; rel=&quot;nofollow noreferrer&quot;&gt;Culling the Battlefield: Data Oriented Design in Practice&lt;/a&gt;&lt;/strong&gt;&lt;br /&gt;&#xA;The presentation also mentions speeding culling up even more, using a simple grid.&lt;/p&gt;&#xA;&lt;p&gt;Since I assume most 3D/simulation/game code bases already have some kind of BVH class and I don't know how critical it is for you to get the BEST culling performance, I'd like to present some arguments for sticking with a BVH:&lt;/p&gt;&#xA;&lt;p&gt;Depending on what method you use, constructing a BVH can be fast and simple.&lt;/p&gt;&#xA;&lt;p&gt;My current implementation of a binary BVH (each node can only have zero or two children and each leaf node only stores one item)&#xA;that is designed for quick &lt;strong&gt;construction takes around 0.18ms for 1137 objects on a single thread of an i7-5960X @ 3.89GHz&lt;/strong&gt;. I'm sure it can be faster.&#xA;Construction is performed without reallocating memory in the process (this doubled the construction performance).&lt;/p&gt;&#xA;&lt;p&gt;While SAH might generate the best BVH, it takes a long time. SAH is good for things you can precompute, like collision meshes.&#xA;At runtime you can then put the collision meshes into a BVH that is more suited for real-time construction.&lt;/p&gt;&#xA;&lt;p&gt;A fast and simple BVH construction approach (the one I'm using currently) is to sort all objects on an axis (for example the parent AABB's longest axis) and split the collection in the middle.&lt;/p&gt;&#xA;&lt;p&gt;To speed things up even more, calculate the node AABBs AFTER constructing the tree, by combining the two child node AABBs of a parent node. This avoids iterating through all objects (another 2x speedup). This however is only possible if your splitting criterion doesn't rely on the parent's AABB.&lt;/p&gt;&#xA;" OwnerUserId="5909" LastEditorUserId="5909" LastEditDate="2020-12-14T06:38:46.077" LastActivityDate="2020-12-14T06:38:46.077" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10490" PostTypeId="1" AcceptedAnswerId="10521" CreationDate="2020-12-14T14:56:43.277" Score="1" ViewCount="27" Body="&lt;p&gt;If we have an object at certain distance D in front of a camera. The object has a horizontal diameter d, giving us an angular diameter theta (2*arctan(d/2D)) of 50 degrees (converted from radians). And a camera of 100 FoV, horizontally.&lt;/p&gt;&#xA;&lt;p&gt;Given those figures, does that mean that the horizontal image size of the object will be exactly 50 % of the image width?&lt;/p&gt;&#xA;" OwnerUserId="15372" LastActivityDate="2020-12-27T12:09:25.237" Title="Does angular diameter to FoV ratio equal object's image to total image ratio?" Tags="&lt;projections&gt;&lt;perspective&gt;&lt;camera&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10491" PostTypeId="2" ParentId="10486" CreationDate="2020-12-14T16:53:56.257" Score="1" Body="&lt;p&gt;@ Physician --- We can use trigonometry and set-up a condition whereby the horizontal angle of view will be 100°&lt;/p&gt;&#xA;&lt;p&gt;On a full frame 35mm camera format demotions 24mm by 36mm, mount a 15mm lens and horizontal angle of view will be 100°&lt;/p&gt;&#xA;&lt;p&gt;On an APS-C compact, the frame size is 16mm by 24mm. Mount a 10mm lens and the horizontal angle of view is 100°&lt;/p&gt;&#xA;&lt;p&gt;In other words, the angle of view of camera system intertwines focal length and format dimension.&lt;/p&gt;&#xA;&lt;p&gt;For the full frame camera above:&#xA;The image plane falls 15mm downstream from the lens.  The Image triangle has a height of 15mm. The size of the angle at the apex of this triangle is 50°. We bisect this triangle creating two right triangles. The angle at the apex is 25°. The height of this triangle is 15mm. If you draw this triangle, the height is the adjacent side and the base is the opposite size. The tan of 25° = 0.4663. Thus Opposite / Adjacent = 0.4663. Thus Opposite side = 15mm X 0.4663 = 6.9946mm. The length of the image of the object will be 2X this value = 14mm.&lt;/p&gt;&#xA;&lt;p&gt;For the APS-C format:  The image plane falls 10mm downstream. Such as lash-up delivers a 100° horizontal angle of view. The image triangle angles are the same as for the full frame. Bisecting the image triangle, we get two right triangles each with a 25° apex. The tan of this angle = 0.4663. The height of this triangle is the focal length of the lens = 10mm. 10mm X 0.4663 = 4.66mm X 2 = 9.33mm. The image of the object will be 9.33mm long.&lt;/p&gt;&#xA;" OwnerUserId="15377" LastActivityDate="2020-12-14T16:53:56.257" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10492" PostTypeId="2" ParentId="10486" CreationDate="2020-12-14T18:47:20.677" Score="0" Body="&lt;p&gt;@ Physician --- There are three flies in the ointment, all miniscule: The object distance is a measurement taken from a point within the optical system called the front nodal. The image distance is the focal length, a measurement taken from a point in the optical system called the rear nodal. The focal length is a measurement taken from the rear nodal to the image when the camera is focused on an object at infinity.&lt;/p&gt;&#xA;&lt;p&gt;In a multi element lens system the distance between front and rear nodal points will be unknown unless we run some tests. This could change the value we are using for the height of the image triangle. Additionally, if the object being imaged is closer than infinity, the height of the image triangle will be elongated. We are using the focal length as this value.&lt;/p&gt;&#xA;&lt;p&gt;Suppose a 10mm focal length lens is deployed. Suppose the object being imaged is 1 meter distant. What is the height of the image triangle? 1/10 x1000 = power of camera lens in diopters = 0.1 x 1000 = 100d. The object distance can be express in diopter units as 1/1000 x 1000 = 1d.&lt;/p&gt;&#xA;&lt;p&gt;We can calculate the image distance as 100d – 1d = 99d. Convert to millimeters = 1/99 x 1000 = 10.1mm. In other words, the fact that the object is not at infinity, elongates the image distance. If the object is 1 meter from the lens, using a 10mm lens, the image forms 10.1mm downstream from the lens. We were using 10mm as the height of the image triangle. In actually this should be 10.1mm&#xA;Nothing is easy!&lt;/p&gt;&#xA;" OwnerUserId="15379" LastActivityDate="2020-12-14T18:47:20.677" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10493" PostTypeId="1" AcceptedAnswerId="10494" CreationDate="2020-12-14T20:27:20.003" Score="1" ViewCount="43" Body="&lt;p&gt;I've been working through PBRT, implementing my own version of it in Rust. Right now I'm working on shadow rays, and it looks like pbrt doesn't do anything to account for specular behavior, and treats materials like perfect glass as opaque with respect to shadows. I decided to try to implement a version that accounts for this behavior, but I don't see a difference visually. Ignoring the bug that causes some of my threads to get stuck, the top one is my attempt at accounting for specular behavior and the bottom one is the 'normal' implementation that casts a single ray to see if it hits the light or not.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/97xXs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/97xXs.png&quot; alt=&quot;mine&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/PQ7BV.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/PQ7BV.png&quot; alt=&quot;normal&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I can't see any difference in how the ground looks, and I don't believe that's how it should look for a perfectly specular glass model. My implementation is as follows  (it's in Rust, so I've commented to get the general idea across):&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-rust prettyprint-override&quot;&gt;&lt;code&gt;pub fn occlusion_intersects(&amp;amp;self, ray: &amp;amp;Ray, tmin: f64, tmax: f64, depth: i32) -&amp;gt; Option&amp;lt;HitRecord&amp;gt; {&#xA;    // find intersection with scene&#xA;    let ans = self.intersects(ray, tmin, tmax);&#xA;    // if no intersection was found, return None&#xA;    if ans.is_none() {&#xA;        return None&#xA;    }&#xA;    let mut ans = ans.unwrap(); // rust stuff, ignore this&#xA;    // compute the bsdf for the material&#xA;    Material::compute_scattering_default(&amp;amp;mut ans);&#xA;    // we only want to specular transmission or reflection&#xA;    let bsdf_type = BSDF_TRANSMISSION | BSDF_REFLECTION | BSDF_SPECULAR;&#xA;    // sample_f returns a new outgoing direction according to a bsdf that matches&#xA;    // one of the types above, or (0, 0, 0) if no matching bsdfs.&#xA;    let (wi, .. ) = ans.bsdf.sample_f(&amp;amp;ans.wo, bsdf_type);&#xA;    // if there was no specular bsdf or we've recursed too many times:&#xA;    if (wi == util::zero_vector() || depth == MAX_DEPTH {&#xA;        // then return the current intersection to check if it&#xA;        // hit the expected light object&#xA;        return Some(ans);&#xA;    }&#xA;    // otherwise make a new ray going in the new specular direction&#xA;    let new_ray = ans.spawn_ray(&amp;amp;wi);&#xA;    // and return that answer&#xA;    return self.occlusion_intersects(&amp;amp;new_ray, tmin, tmax, depth + 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And for reference, the default implementation would be:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-rust prettyprint-override&quot;&gt;&lt;code&gt;pub fn occlusion_intersects(&amp;amp;self, ray: &amp;amp;Ray, tmin: f64, tmax: f64, depth: i32) -&amp;gt; Option&amp;lt;HitRecord&amp;gt; {&#xA;    // return the first intersection, ignore all specular behavior&#xA;    return self.intersects(ray, tmin, tmax);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Is there something wrong with my implementation? I kind of guessed as to how it would work, but the logic written in the comments makes sense to me.&lt;/p&gt;&#xA;" OwnerUserId="13698" LastActivityDate="2020-12-14T23:39:59.277" Title="How can I account for specular interactions in shadow rays?" Tags="&lt;pathtracing&gt;&lt;shadow&gt;&lt;pbrt&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10494" PostTypeId="2" ParentId="10493" CreationDate="2020-12-14T23:39:59.277" Score="1" Body="&lt;p&gt;Shadow rays that hit a glass surface or similar are stopped because there's no &lt;em&gt;direct&lt;/em&gt; path from the light source to the shading point—there's a piece of glass in the way.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;for perfectly specular transmission/reflection, you can continue tracing the shadow ray because there's only one possible outgoing vector for a given incoming vector&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;That won't work, because the transmission/reflection will change the direction of the ray. The shadow ray was presumably created by pointing it at a light source, but after transmission/reflection, it's most likely not going to hit the light source anymore.&lt;/p&gt;&#xA;&lt;p&gt;The idea of firing rays directly at light sources can be seen as a sampling strategy designed to exploit knowledge of which directions light is most likely to come from, and put your rays into those directions. If you're receiving light via a specular interaction rather than directly from the source, you don't know anymore which directions you should sample in.&lt;/p&gt;&#xA;&lt;p&gt;I imagine for simple cases like a glass sphere, etc, you could algebraically solve for a light path that would refract toward a chosen point on a light source. Then you could trace shadow rays along that path. But when you get into geometry as complex as the dragon, there's no realistic way to calculate which directions the light is going to come in from.&lt;/p&gt;&#xA;&lt;p&gt;When specular surfaces like glass or metal focus light onto a diffuse surface, that produces a caustic. Caustics are a notorious pain point for vanilla path tracing due to this problem—there is no way to know where to concentrate your samples to make your rays hit light sources, so the best you can do is fire rays in all directions (or sample from the BRDF) and hope that enough of them will find their way to a light source. Technically, path tracing can render caustics correctly, but it takes an &lt;em&gt;extremely&lt;/em&gt; large number of samples to do it.&lt;/p&gt;&#xA;&lt;p&gt;More practically, this issue can be solved by using photon mapping (which was invented precisely to deal with caustics), or some kind of path guiding methods like Metropolis and friends that can &amp;quot;discover&amp;quot; the caustics and dynamically concentrate samples around them.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-14T23:39:59.277" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10495" PostTypeId="1" AcceptedAnswerId="10543" CreationDate="2020-12-15T05:36:32.843" Score="0" ViewCount="87" Body="&lt;p&gt;I'm rendering an image onto a mesh. And I need to render fragments with uv coordinates that fall outside (0,1) range with full transparency. In the code below I'm specifying a border color with zero alpha. However I'm getting fully opaque border. That is when texture itself does not have alpha channel. Is it possible to use a texture without alpha channel but still render fragments outside of the range as transparent?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);&#xA;float border[] = {1, 1, 1, 0};&#xA;glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here is the fragment shader code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;out vec4 color;&#xA;in vec2 uv;&#xA;uniform sampler2D tex;&#xA;&#xA;void main() {&#xA;    color = texture(tex, uv);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I enabled alpha blending like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;glEnable(GL_BLEND);&#xA;glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2020-12-15T07:45:29.463" LastActivityDate="2021-01-07T09:00:42.217" Title="Render fragments with uvs outside (0,1) range as transparent" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10496" PostTypeId="2" ParentId="10450" CreationDate="2020-12-16T04:27:37.800" Score="1" Body="&lt;p&gt;One approach for stuff like this that  I just heard is to do raymarching on simple analytical shapes that approximate the mesh, so you basically create an abstract coarse SDF representation of the mesh in question and raymarch some shadows. I have heard Iñigo Quilez mention it and talking on how he gave a conference about it once but I haven't found it, I think it was either Gamescon or SIGGRAPH.&lt;/p&gt;&#xA;" OwnerUserId="9749" LastActivityDate="2020-12-16T04:27:37.800" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10497" PostTypeId="1" AcceptedAnswerId="10504" CreationDate="2020-12-17T04:38:03.870" Score="0" ViewCount="88" Body="&lt;p&gt;How can I render plots and graphics that mimic how mathematicians draw diagrams?&lt;/p&gt;&#xA;&lt;p&gt;For example Look at this shirt:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/RJiSv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/RJiSv.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The diagrams represent 2D and 3D shapes, however they have characteristics of human drawings. The curves are not perfect and exhibit lot's of noise and waviness that a computer rendering would normally not have.&#xA;If you know any papers regarding this topic, please add them as reference to your answer.&lt;/p&gt;&#xA;&lt;p&gt;As a side note and perhaps somewhat off topic: Is there a C++ library that can do tex rendering onto textures?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="13095" LastEditDate="2020-12-19T13:41:12.013" LastActivityDate="2020-12-21T13:24:05.973" Title="Stylized math like rendering?" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;mathematics&gt;&lt;shading&gt;&lt;font-rendering&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10498" PostTypeId="1" CreationDate="2020-12-18T02:52:28.893" Score="0" ViewCount="77" Body="&lt;p&gt;I was trying to follow this &lt;a href=&quot;http://foundationsofgameenginedev.com/FGED2-sample.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://foundationsofgameenginedev.com/FGED2-sample.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But had problem understanding formula 7.33.&#xA;&lt;span class=&quot;math-container&quot;&gt;$$p_i-p_j=(u_i-u_j)\mathrm{t}+(v_i-v_j)\mathrm{b}$$&lt;/span&gt;&#xA;* &lt;span class=&quot;math-container&quot;&gt;$p_i,p_j$&lt;/span&gt; being vertices on a triangle, and &lt;span class=&quot;math-container&quot;&gt;$u_*,v_*$&lt;/span&gt; being their texture coordiniates, and &lt;span class=&quot;math-container&quot;&gt;$M_{tangent}=\left[\mathrm{t}\space\mathrm{b}\space\mathrm{n}\right]$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;If the matrix has to be orthogonal (why though?), then if I'm not mistaken, all its vectors have to measure 1 in magnitude. It surely looks like there lacks constraints on &lt;span class=&quot;math-container&quot;&gt;$p_i$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$p_j$&lt;/span&gt; - they can be at any distance from each other while &lt;span class=&quot;math-container&quot;&gt;$\left|u_i-u_j\right|&amp;lt;1$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Where did I get it wrong?&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;@pmw1234&#xA;Please read the following and do elaborate a little.&#xA;I'm all confused here. Whether or not the textbooks I have are good enough.&lt;/p&gt;&#xA;&lt;p&gt;The book says because &lt;strong&gt;M&lt;/strong&gt; is orthogonal, &lt;span class=&quot;math-container&quot;&gt;$M^T$&lt;/span&gt; is the reverse transformation.&lt;/p&gt;&#xA;&lt;p&gt;The textbook definition of an orthogonal matrix is &lt;span class=&quot;math-container&quot;&gt;$$\begin{equation}{M^T}{M}={M}{M^T}=I\end{equation}$$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$${M^T}={M^{-1}}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;From the definition follows one of the properties:&lt;/p&gt;&#xA;&lt;p&gt;A matrix is orthogonal if and only if its rows/cols are orthonormal vectors.&lt;/p&gt;&#xA;&lt;p&gt;Proof:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{eqnarray}&#xA;\text{Because}\\&#xA;M&amp;amp;=&amp;amp;\begin{bmatrix}&#xA;\mathrm{r}_{1}\\&#xA;\mathrm{r}_{2}\\&#xA;\vdots\\&#xA;\mathrm{r}_{n}&#xA;\end{bmatrix}\\&#xA;M^T&amp;amp;=&amp;amp;\begin{bmatrix}\mathrm{r}_{1}^T&amp;amp;\mathrm{r}_{2}^T&amp;amp;\ldots&amp;amp;\mathrm{r}_{n}^T\end{bmatrix}\\&#xA;M\times{M^T}&amp;amp;=&amp;amp;\begin{bmatrix}&#xA;\mathrm{r}_{1}\mathrm{r}_{1}^T&amp;amp;\mathrm{r}_{1}\mathrm{r}_{2}^T&amp;amp;\ldots&amp;amp;\mathrm{r}_{1}\mathrm{r}_{n}^T\\&#xA;\mathrm{r}_{2}\mathrm{r}_{1}^T&amp;amp;\mathrm{r}_{2}\mathrm{r}_{2}^T&amp;amp;\ldots&amp;amp;\mathrm{r}_{2}\mathrm{r}_{n}^T\\&#xA;\vdots&amp;amp;\vdots&amp;amp;\ddots&amp;amp;\vdots\\&#xA;\mathrm{r}_{n}\mathrm{r}_{1}^T&amp;amp;\mathrm{r}_{n}\mathrm{r}_{2}^T&amp;amp;\ldots&amp;amp;\mathrm{r}_{n}\mathrm{r}_{n}^T&#xA;\end{bmatrix}\\&#xA;\\&#xA;\text{Therefore}\\&#xA;\mathrm{r}_{i}\mathrm{r}_{j}^T&amp;amp;=&amp;amp;0&amp;amp;(i\neq{j})\\&#xA;\mathrm{r}_{i}\mathrm{r}_{i}^T&amp;amp;=&amp;amp;\left|\mathrm{r}_{i}\right|=1\\&#xA;\\&#xA;\end{eqnarray}&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;i.e. the rows form an orthonormal basis.&lt;/p&gt;&#xA;&lt;p&gt;Q.E.D.&lt;/p&gt;&#xA;&lt;p&gt;If the book calling &lt;strong&gt;M&lt;/strong&gt; orthogonal isn't enough, and the rows are merely literally &amp;quot;orthogonal&amp;quot; to each other, I don't see how the &amp;quot;reverse transformation&amp;quot; is meaningful.&lt;/p&gt;&#xA;&lt;p&gt;A trivial example is.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{eqnarray}&#xA;M&amp;amp;=&amp;amp;\begin{bmatrix}&#xA;2&amp;amp;0&amp;amp;0\\&#xA;0&amp;amp;1&amp;amp;0\\&#xA;0&amp;amp;0&amp;amp;1\\&#xA;\end{bmatrix}\textrm{the rows being perfectly &quot;orthogonal&quot;}\\&#xA;M^T&amp;amp;=&amp;amp;M\\&#xA;V&amp;amp;=&amp;amp;\begin{bmatrix}&#xA;1\\&#xA;1\\&#xA;1\\&#xA;\end{bmatrix}\\&#xA;M\times{V}&amp;amp;=&amp;amp;\begin{bmatrix}&#xA;2\\&#xA;1\\&#xA;1\\&#xA;\end{bmatrix}\\&#xA;M^T\times{M}\times{V}&amp;amp;=&amp;amp;\begin{bmatrix}&#xA;4\\&#xA;1\\&#xA;1\\&#xA;\end{bmatrix}&#xA;\end{eqnarray}&#xA;$$&lt;/span&gt;&#xA;I can't see how &lt;span class=&quot;math-container&quot;&gt;$M^T$&lt;/span&gt; reverses anything.&lt;/p&gt;&#xA;" OwnerUserId="15133" LastEditorUserId="15133" LastEditDate="2021-01-16T03:07:37.213" LastActivityDate="2021-01-16T03:07:37.213" Title="Help me understand the derivation of this tangent space to object space matrix" Tags="&lt;transformations&gt;&lt;shading&gt;&lt;normal-mapping&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="10499" PostTypeId="1" CreationDate="2020-12-18T19:32:42.160" Score="1" ViewCount="42" Body="&lt;p&gt;I hope this is the correct place to ask this question. It feels to me that I should ask people who have had to program graphics as there’s a lot of confusion about color depth in general.&lt;/p&gt;&#xA;&lt;p&gt;I’m sure a lot of people are aware that Adobe Photoshop can render OpenGL to 10bpc/30bit displays as long as the graphics card, divers and monitor support it.&lt;/p&gt;&#xA;&lt;p&gt;My question is, now that we have monitors that can display HDR, are these HDR monitors also capable of doing rendering in Photoshop 10-bit?&lt;/p&gt;&#xA;" OwnerUserId="15403" LastEditorUserId="13095" LastEditDate="2020-12-18T23:07:58.437" LastActivityDate="2020-12-19T20:14:56.807" Title="Colour Depth in Hardware" Tags="&lt;color&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10501" PostTypeId="1" CreationDate="2020-12-19T19:37:35.990" Score="0" ViewCount="37" Body="&lt;p&gt;I have saw a clip where a guy talked about the art of squeezing some nice graphics into a very small space that was available on old computers. Come to think of it, it sounded something like today's git, where the changes were being saved, between the scenes, and the way it was rendered on screen. I have been searching for hours on YT and google and I couldn't find it, please help.&lt;/p&gt;&#xA;&lt;p&gt;The game was from 80's or early 90's, and the scene I vaguely remember is a car parking in front of a building (probably a bar or a house) at night. The graphics was pretty dark, it was dark blue, indigo or purple, or some shades of those, but the headlights were bright yellow I think. The thing I remember about the clip was describing this scene in much detail, how it would use much more space if not for nifty tricks used by programmers.&lt;/p&gt;&#xA;&lt;p&gt;I have tried searching google and YT for this keywords: old, game, noir, adventure, mystery, car, graphics, compression, methods, space, techniques, etc. Google didn't give me a screenshot I could recognize, I am not sure if it was YT or an example in a tutorial about computer graphics on some learning platform, sorry.&#xA;I even tried drawing the scene and searching by image on google, didn't help. Here is my drawing.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9kWgp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9kWgp.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It was a great clip and inability to find it again is driving me mad, please help me if what i described seems familiar, that clip is a keeper really, I think most of the people here would enjoy it.&#xA;Thanks&lt;/p&gt;&#xA;" OwnerUserId="15410" LastActivityDate="2020-12-19T19:37:35.990" Title="I am trying to find a clip about the art of old computer graphics" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;performance&gt;&lt;optimisation&gt;&lt;2d-graphics&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10502" PostTypeId="2" ParentId="10499" CreationDate="2020-12-19T20:14:56.807" Score="3" Body="&lt;p&gt;Maybe. HDR monitors are typically going to be some approximation of the &lt;a href=&quot;https://en.wikipedia.org/wiki/DCI-P3&quot; rel=&quot;nofollow noreferrer&quot;&gt;DCI-P3&lt;/a&gt; color space, while Adobe's wide-color rendering is the &lt;a href=&quot;https://en.wikipedia.org/wiki/Adobe_RGB_color_space&quot; rel=&quot;nofollow noreferrer&quot;&gt;Adobe RGB&lt;/a&gt; color space. The two are similar but not quite the same; in particular, Adobe RGB extends a bit further into the green-cyan range than DCI-P3 does:&lt;/p&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/no6dI.png&quot; width=&quot;558&quot; height=&quot;633&quot; alt=&quot;Adobe RGB and DCI-P3 on CIE chromaticity diagram&quot;&gt;&#xA;&lt;p&gt;That said, these are only idealized color spaces, and the gamut of a given actual monitor is going to differ somewhat from these. That's why you'll see monitors advertised as having &amp;quot;99% Adobe RGB coverage&amp;quot; or &amp;quot;99% DCI-P3&amp;quot; or some such.&lt;/p&gt;&#xA;&lt;p&gt;So, a typical HDR monitor can probably reproduce &lt;em&gt;most&lt;/em&gt; of the Adobe space but maybe not quite all of it, but in practice it might be just about as good as an actual Adobe-supporting monitor.&lt;/p&gt;&#xA;&lt;p&gt;That said, I don't know whether Photoshop and the drivers/OS/etc will actually cooperate to let you turn on Adobe RGB rendering on a DCI-P3 HDR monitor. If Photoshop is outputting 10-bit color in Adobe RGB space, but the monitor doesn't actually take that format, then it would need to be converted somewhere along the line to a color space and encoding that the monitor can take as input. That can certainly be done by the graphics card/drivers/OS, but I don't know whether the support for doing such conversions is actually there.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-19T20:14:56.807" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10503" PostTypeId="1" CreationDate="2020-12-20T11:47:18.603" Score="1" ViewCount="251" Body="&lt;p&gt;I am unable to visualize what is principal vanishing point w.r.t to x axis ,y axis z axis  do someone can post some simple  diagram to understand what is it? Also I have question in my text book&lt;/p&gt;&#xA;&lt;p&gt;' &lt;img src=&quot;https://i.stack.imgur.com/Y7F04.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;img src=&quot;https://i.stack.imgur.com/5CNai.jpg&quot; alt=&quot;enter image description here&quot; /&gt;       Now the question is how to calculate vanishing point and what is the line A' B ?Solution is also given which is (0,0,0) as vanishing point but I am unable to understand how do they get it , figure (k)shows it as (0,0,2) ,also what is d in the solution?&lt;img src=&quot;https://i.stack.imgur.com/yjCta.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="15415" LastEditorUserId="15415" LastEditDate="2020-12-21T07:53:28.433" LastActivityDate="2021-05-20T09:07:45.787" Title="What is principal vanishing point in perspective projection?" Tags="&lt;perspective&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10504" PostTypeId="2" ParentId="10497" CreationDate="2020-12-20T11:59:06.283" Score="3" Body="&lt;p&gt;You might want to check &lt;a href=&quot;https://github.com/lava/matplotlib-cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;matplotlib-cpp&lt;/a&gt;. You'll find a &amp;quot;funny-looking xkcd-styled example&amp;quot; in the README.&lt;/p&gt;&#xA;&lt;p&gt;I also saw xkcd related entries on matplotlib's Python documentation. So, it should be available in Python too. However, I did not use these libraries myself. I just stumbled upon matplotlib-cpp while I was looking for a plotting library for C++.&lt;/p&gt;&#xA;" OwnerUserId="15413" LastEditorUserId="15413" LastEditDate="2020-12-21T13:24:05.973" LastActivityDate="2020-12-21T13:24:05.973" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10505" PostTypeId="2" ParentId="10503" CreationDate="2020-12-20T16:24:07.567" Score="1" Body="&lt;p&gt;Basically whenever you project a set of parallel lines in 3D space on a 2D image plane, you'll see that these lines don't remain parallel in 2D space and tend to meet at a certain point which is the so called vanishing point. Picture a long railway, both the rail lines meet at the horizon.&lt;/p&gt;&#xA;&lt;p&gt;Now one confusion arises that the question doesnt give you a set of parallel lines, But it doesn't matter as long as a single line segment is provided. All you need to do is just picture the line segment extending to infinity. So for example, picture the point &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; at infinity and imagine drawing a line &lt;span class=&quot;math-container&quot;&gt;$BE$&lt;/span&gt;. The point at which this line intersects the image plane will be your vanishing point.&lt;/p&gt;&#xA;&lt;p&gt;There is a simple pattern that applies to every case like this. Just shoot a ray in the direction of the vector &lt;span class=&quot;math-container&quot;&gt;$\vec{AB}$&lt;/span&gt; from the point &lt;span class=&quot;math-container&quot;&gt;$E$&lt;/span&gt;. The point at which this ray intersects the image plane will be your vanishing point which as you can see is &lt;span class=&quot;math-container&quot;&gt;$(0,0,0)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Now imagine why this works. Picture the point &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; extending up, and at each instance start drawing segments &lt;span class=&quot;math-container&quot;&gt;$BE$&lt;/span&gt;. You'll see that this line segment is moving towards the &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; axis.&#xA;So if you are projecting a point &lt;span class=&quot;math-container&quot;&gt;$B$&lt;/span&gt; at infinity then the projecting line or segment &lt;span class=&quot;math-container&quot;&gt;$BE$&lt;/span&gt; gonna become parallel to the line &lt;span class=&quot;math-container&quot;&gt;$AB$&lt;/span&gt;. However, it can't go past the &lt;span class=&quot;math-container&quot;&gt;$Z$&lt;/span&gt; axis, as this will start going in the opposite direction.&lt;/p&gt;&#xA;" OwnerUserId="6046" LastActivityDate="2020-12-20T16:24:07.567" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10506" PostTypeId="1" CreationDate="2020-12-20T20:06:03.867" Score="2" ViewCount="35" Body="&lt;p&gt;i dont know if i can create a virtual server (with vmware, virtual box or with something like that), and if i can use the full power of my graph (i have a nvidia rtx 2080 super) or if I'm going to lose some power of this gpu.&lt;/p&gt;&#xA;&lt;p&gt;or which tools can i use?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;print('please dont close this i need to know the answer')&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So, can i connect a rtx 2080 super to my server, and create a virtual server with the full power of the graph?? i need to know if I can use the full power of the graph or not, for example, i want to create a virtual server for play videogames in every place, so i only have to connect to this server and play (this is only an example) so this server will use the full power of the graph nvidai rtx 2080 super or not?? Thanks so much, and i cant try this if i dont know if it will works, because i have to buy the graph.&lt;/p&gt;&#xA;" OwnerUserId="15417" LastActivityDate="2020-12-20T20:06:03.867" Title="Create a virtual server which use the full power of my GPU" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10507" PostTypeId="1" AcceptedAnswerId="10508" CreationDate="2020-12-21T02:03:20.927" Score="0" ViewCount="129" Body="&lt;p&gt;I have the following challenge. I am given a black and white image with rasterized lines.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/d5k2P.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/d5k2P.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Given this input, I want to extend the edges to cover more than one pixel and antialias the edges.&lt;/p&gt;&#xA;&lt;p&gt;My first attempt was to pass a morphological dilation followed by a gaussian filter. But that straight up did not work, all i got is for the image to look blurry.&lt;/p&gt;&#xA;&lt;p&gt;I instead tried combining both effects into a single shader and go the following:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DuACy.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DuACy.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/V4QmM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V4QmM.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is decent, but you can still see a lot of the original aliasing of the edges.&lt;/p&gt;&#xA;&lt;p&gt;Assuming that I only have the input image, are there any image based / screen space based AA techniques I can use to make the edges look smooth?&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2020-12-22T13:09:26.683" Title="Screen Space anti aliasing?" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;antialiasing&gt;&lt;raster-image&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="10508" PostTypeId="2" ParentId="10507" CreationDate="2020-12-22T13:09:26.683" Score="2" Body="&lt;p&gt;The easiest way to deal with this would be to provide thickness for the edges in the continuous setting. That is, make your edges out of solid capsules/cylinders, then you would not have this issue. Technically, this is is neither a supersampling nor a filtering technique, but rather a reformulation of the problem in the continuous setting. Another equivalent reformulation is considering only the vertices and then your reconstruction function being thick edges between those (using a thick line algorithm).&lt;/p&gt;&#xA;&lt;p&gt;This doesn't seem to be your setting however? Since you mentioned that you only have the raster (aliased) image already, in which case you have already introduced the error so it is hard to get rid off. If you can &amp;quot;access&amp;quot; the continuous model it is a lot easier to fix. If you cannot, then I could recommend using a different reconstruction filter than the dilation that you are using. For instance you can do a thickening based on distance to pixels (sdf) with a step function. This should remove the issues you are having, at least for the example you showed.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2020-12-22T13:09:26.683" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10509" PostTypeId="1" CreationDate="2020-12-22T21:02:05.077" Score="1" ViewCount="103" Body="&lt;p&gt;I've been following the OpenGL tutorials from ThinMatrix and I've been able to load and render his stall.obj model along with his stall.png texture just fine. But when I try with my own  models and textures from Blender, the texture appears &amp;quot;distorted&amp;quot; and I can't seem to find the problem. I'm guessing the problem is with my texture, but I can't find anything that would cause this problem. What could be the cause of this problem?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/wuDZL.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/wuDZL.png&quot; alt=&quot;Blender&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4MD8Z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4MD8Z.png&quot; alt=&quot;OpenGL&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here's how I load the .obj file:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void OBJLoader::load_file(const std::string&amp;amp; filename, std::vector&amp;lt;float&amp;gt;&amp;amp; vertices, std::vector&amp;lt;float&amp;gt;&amp;amp; uvs, std::vector&amp;lt;float&amp;gt;&amp;amp; normals, std::vector&amp;lt;int&amp;gt;&amp;amp; indices)&#xA;{&#xA;std::vector&amp;lt;float&amp;gt; temp_uvs;&#xA;std::vector&amp;lt;float&amp;gt; temp_normals;&#xA;&#xA;std::ifstream myfile(filename);&#xA;std::string line;&#xA;if(myfile.is_open())&#xA;{&#xA;    while(std::getline(myfile, line))&#xA;    {&#xA;        if(std::string(&amp;quot;#os&amp;quot;).find(line.front()) != std::string::npos) // Ignore lines which starts with #, o, s&#xA;            continue;&#xA;&#xA;        std::vector&amp;lt;std::string&amp;gt; line_split = split(line, ' ');&#xA;        std::string data_type = line_split[0];&#xA;        line_split.erase(line_split.begin()); // Keep only numerical data&#xA;&#xA;        if(data_type == &amp;quot;v&amp;quot;)&#xA;        {&#xA;            store_float_in_vector(vertices, line_split);&#xA;        }&#xA;        else if(data_type == &amp;quot;vt&amp;quot;)&#xA;        {&#xA;            store_float_in_vector(temp_uvs, line_split);&#xA;        }&#xA;        else if(data_type == &amp;quot;vn&amp;quot;)&#xA;        {&#xA;            store_float_in_vector(temp_normals, line_split);&#xA;        }&#xA;&#xA;        if(data_type == &amp;quot;f&amp;quot;)&#xA;        {&#xA;            for(std::string&amp;amp; vertex: line_split)&#xA;            {&#xA;                std::vector&amp;lt;std::string&amp;gt; data_split = split(vertex, '/');&#xA;                int v = std::stoi(data_split[0]);&#xA;                int vt = std::stoi(data_split[1]);&#xA;                int vn = std::stoi(data_split[2]);&#xA;&#xA;                if(uvs.size() &amp;lt; (unsigned)(v-1)*2+2)&#xA;                    uvs.resize((v-1)*2+2);&#xA;                if(normals.size() &amp;lt; (unsigned)(v-1)*3+3)&#xA;                    normals.resize((v-1)*3+3);&#xA;&#xA;                indices.push_back(v-1); // Indices in .obj files start at 1&#xA;&#xA;                uvs[(v-1)*2] =  temp_uvs[(vt-1)*2];&#xA;                uvs[(v-1)*2+1] = 1.0f - temp_uvs[(vt-1)*2+1]; // Blender ¯\_(ツ)_/¯&#xA;&#xA;                normals[(v-1)*3] = temp_normals[(vn-1)*3];&#xA;                normals[(v-1)*3+1] = temp_normals[(vn-1)*3+1];&#xA;                normals[(v-1)*3+2] = temp_normals[(vn-1)*3+2];&#xA;            }&#xA;        }&#xA;    }&#xA;    myfile.close();&#xA;}&#xA;else&#xA;    std::cout &amp;lt;&amp;lt; &amp;quot;Can't open: &amp;quot; &amp;lt;&amp;lt; filename &amp;lt;&amp;lt; std::endl;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here's the obj file:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;# Blender v2.82 (sub 7) OBJ File: ''&#xA;# www.blender.org&#xA;o Cube&#xA;v 1.000000 1.000000 -1.000000&#xA;v 1.000000 -1.000000 -1.000000&#xA;v 1.000000 1.000000 1.000000&#xA;v 1.000000 -1.000000 1.000000&#xA;v -1.000000 1.000000 -1.000000&#xA;v -1.000000 -1.000000 -1.000000&#xA;v -1.000000 1.000000 1.000000&#xA;v -1.000000 -1.000000 1.000000&#xA;vt 0.875000 0.500000&#xA;vt 0.625000 0.750000&#xA;vt 0.625000 0.500000&#xA;vt 0.375000 1.000000&#xA;vt 0.375000 0.750000&#xA;vt 0.625000 0.000000&#xA;vt 0.375000 0.250000&#xA;vt 0.375000 0.000000&#xA;vt 0.375000 0.500000&#xA;vt 0.125000 0.750000&#xA;vt 0.125000 0.500000&#xA;vt 0.625000 0.250000&#xA;vt 0.875000 0.750000&#xA;vt 0.625000 1.000000&#xA;vn 0.0000 1.0000 0.0000&#xA;vn 0.0000 0.0000 1.0000&#xA;vn -1.0000 0.0000 0.0000&#xA;vn 0.0000 -1.0000 0.0000&#xA;vn 1.0000 0.0000 0.0000&#xA;vn 0.0000 0.0000 -1.0000&#xA;s off&#xA;f 5/1/1 3/2/1 1/3/1&#xA;f 3/2/2 8/4/2 4/5/2&#xA;f 7/6/3 6/7/3 8/8/3&#xA;f 2/9/4 8/10/4 6/11/4&#xA;f 1/3/5 4/5/5 2/9/5&#xA;f 5/12/6 2/9/6 6/7/6&#xA;f 5/1/1 7/13/1 3/2/1&#xA;f 3/2/2 7/14/2 8/4/2&#xA;f 7/6/3 5/12/3 6/7/3&#xA;f 2/9/4 4/5/4 8/10/4&#xA;f 1/3/5 3/2/5 4/5/5&#xA;f 5/12/6 1/3/6 2/9/6&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And here's the png file I used for the texture:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/yoCbp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/yoCbp.png&quot; alt=&quot;texture&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And here's how I load the texture with SDL:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void Texture::load(const std::string&amp;amp; filename)&#xA;{&#xA;glBindTexture(GL_TEXTURE_2D, texture_id);&#xA;&#xA;GLenum gl_format;&#xA;SDL_Surface* surface_texture = IMG_Load(filename.c_str());&#xA;if(surface_texture == nullptr)&#xA;    std::cout &amp;lt;&amp;lt; &amp;quot;IMG_Load error: &amp;quot;  &amp;lt;&amp;lt; IMG_GetError() &amp;lt;&amp;lt; std::endl;&#xA;&#xA;if(surface_texture-&amp;gt;format-&amp;gt;BytesPerPixel == 4)&#xA;{&#xA;    if(surface_texture-&amp;gt;format-&amp;gt;Rmask == 0x000000FF)&#xA;        gl_format = GL_RGBA;&#xA;    else&#xA;        gl_format = GL_BGRA;&#xA;}&#xA;else&#xA;{&#xA;    if(surface_texture-&amp;gt;format-&amp;gt;Rmask == 0x000000FF)&#xA;        gl_format = GL_RGB;&#xA;    else&#xA;        gl_format = GL_BGR;&#xA;}&#xA;&#xA;glTexImage2D(GL_TEXTURE_2D, 0, gl_format, surface_texture-&amp;gt;w, surface_texture-&amp;gt;h, 0, gl_format, GL_UNSIGNED_BYTE, surface_texture-&amp;gt;pixels);&#xA;&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);&#xA;glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);&#xA;&#xA;SDL_FreeSurface(surface_texture); // Free SDL_Surface memory&#xA;glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here's the code for rendering the model:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void Model::create_EBO(int indices[], size_t s_indices)&#xA;{&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, s_indices, indices, GL_STATIC_DRAW);&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Unbind buffer&#xA;}&#xA;&#xA;void Model::create_VBO(float data[], size_t s_data, unsigned int index, unsigned int coord_format)&#xA;{&#xA;    vbos.push_back(0); // Declare new vbo&#xA;    GLuint&amp;amp; vbo = vbos.back();&#xA;&#xA;    glGenBuffers(1, &amp;amp;vbo);&#xA;    glBindBuffer(GL_ARRAY_BUFFER, vbo);&#xA;    glBufferData(GL_ARRAY_BUFFER, s_data, data, GL_STATIC_DRAW);&#xA;    glVertexAttribPointer(index, coord_format, GL_FLOAT, GL_FALSE, 0, (void*)0);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind buffer&#xA;}&#xA;&#xA;void Model::load(float vertices[], size_t s_vertices, float uvs[], size_t s_uvs, float normals[], size_t s_normals, int indices[], size_t s_indices)&#xA;{&#xA;    glBindVertexArray(vao);&#xA;&#xA;    create_EBO(indices, s_indices);&#xA;&#xA;    create_VBO(vertices, s_vertices, 0, 3);&#xA;    create_VBO(uvs, s_uvs, 1, 2);&#xA;    create_VBO(normals, s_normals, 2, 3);&#xA;&#xA;    glBindVertexArray(0); // Unbind VAO and associated VBOs&#xA;&#xA;    vertex_count = s_indices/sizeof(indices[0]);&#xA;}&#xA;&#xA;void Model::render()&#xA;{&#xA;    glBindVertexArray(vao);&#xA;    glEnableVertexAttribArray(0);&#xA;    glEnableVertexAttribArray(1);&#xA;    glEnableVertexAttribArray(2);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);&#xA;    glDrawElements(GL_TRIANGLES, vertex_count, GL_UNSIGNED_INT, 0);&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Unbind EBO&#xA;    glDisableVertexAttribArray(0);&#xA;    glDisableVertexAttribArray(1);&#xA;    glDisableVertexAttribArray(2);&#xA;    glBindVertexArray(0); // Unbind VAO&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="15427" LastEditorUserId="15427" LastEditDate="2020-12-23T00:06:10.460" LastActivityDate="2021-02-05T03:03:10.247" Title="PNG textures render correctly in Blender, but not in OpenGL program" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10510" PostTypeId="2" ParentId="5323" CreationDate="2020-12-23T13:29:02.830" Score="2" Body="&lt;p&gt;You could add the variable as code when you upload the shader code.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;char header[64];&#xA;sprintf (header, &amp;quot;const int size = %u;\n&amp;quot;, pointLights.size());&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then add the header (assuming your code is in &lt;code&gt;char code[]&lt;/code&gt;):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;GLchar  *source[2] = {(GLchar  *)header, (GLchar  *)code};&#xA;glShaderSource(shader, 2, (const GLchar **)source, NULL);&#xA;..&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;That way you can vary the size and add it to the shader on the fly.&#xA;Bit of a hack, but it's the way I did it.&lt;/p&gt;&#xA;" OwnerUserId="15429" LastEditorUserId="15429" LastEditDate="2020-12-23T13:59:22.590" LastActivityDate="2020-12-23T13:59:22.590" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10511" PostTypeId="1" CreationDate="2020-12-23T16:59:17.223" Score="0" ViewCount="36" Body="&lt;p&gt;I&amp;quot;m currently making my own graphic engine. I have the bsdf acquisition and various textures acquisition and I have materials suited for special type of light paths. did&amp;quot;t code the rendering process now because raytracer is not done but we can be inspired from the unity hdrp source code. I've heard that halton  sequences can be used in a raytracer to plan light paths but I only found photon tracing. Can someone help me.I&lt;/p&gt;&#xA;" OwnerUserId="15098" LastActivityDate="2020-12-23T16:59:17.223" Title="Halton raytracer light path" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10512" PostTypeId="1" AcceptedAnswerId="10513" CreationDate="2020-12-24T00:26:23.013" Score="2" ViewCount="76" Body="&lt;p&gt;When a source of colored light is very bright, it's center appears white. What is the term I need to look for so I can implement this in my shader? I have added an image which is an example of what I mean. Obviously there is also some bloom going on but that alone doesn't cut it. The search results for &amp;quot;opengl glow&amp;quot; don't seem vey promising either, that just gives me more bloom, not white centers.&lt;/p&gt;&#xA;&lt;p&gt;I have thought about &lt;a href=&quot;https://stackoverflow.com/questions/4361023/opengl-es-1-1-how-to-change-texture-color-without-losing-luminance&quot;&gt;blending a white emission with the desired color like in this question/answer.&lt;/a&gt; However, as you can see that turns the emission pink, not red.&lt;/p&gt;&#xA;&lt;p&gt;So what I'm really after is a tinted light, glowed, with high (color) contrast.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/V6GAK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/V6GAK.jpg&quot; alt=&quot;example of effect&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10615" LastEditorUserId="10615" LastEditDate="2020-12-24T00:34:40.973" LastActivityDate="2020-12-29T02:28:14.663" Title="&quot;whiteness&quot; in center of bright colored lights - what is it called?" Tags="&lt;lighting&gt;&lt;color&gt;&lt;brightness&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10513" PostTypeId="2" ParentId="10512" CreationDate="2020-12-24T01:33:22.200" Score="3" Body="&lt;p&gt;In general this is caused by HDR tone mapping. Tonemap curves typically decrease saturation as the input light gets brighter, so that very bright lights are rendered closer to white on the display. If bloom is rendered in HDR (prior to tonemapping) then the bloom around the light can still be highly saturated since it is of a lower intensity than the light itself, and so doesn't get desaturated by tonemapping as much.&lt;/p&gt;&#xA;&lt;p&gt;You can see some good examples of this on the &lt;a href=&quot;https://docs.unrealengine.com/en-US/RenderingAndGraphics/PostProcessEffects/ColorGrading/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;UE4 Color Grading and Filmic Tonemapper&lt;/a&gt; docs page. Unreal uses the &lt;a href=&quot;https://knarkowicz.wordpress.com/2016/01/06/aces-filmic-tone-mapping-curve/&quot; rel=&quot;nofollow noreferrer&quot;&gt;ACES tone mapping curve&lt;/a&gt;, which is a pretty good default tone curve that you can easily hook up in your own shader code as well.&lt;/p&gt;&#xA;&lt;p&gt;That said, lightsabers in Star Wars games are probably a special case visual effect that's tuned specifically to reproduce how they look in the movies. :)&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-24T01:33:22.200" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10514" PostTypeId="1" CreationDate="2020-12-24T08:27:51.093" Score="3" ViewCount="28" Body="&lt;p&gt;This is my first post on this website so i have put in a lot of research to get my point across to everyone as clearly as possible.&lt;/p&gt;&#xA;&lt;p&gt;Based on a question i &lt;a href=&quot;https://stackoverflow.com/questions/65410883/bezier-curve-forcing-a-curve-of-4-points-to-pass-through-control-points-in-3d&quot;&gt;posted&lt;/a&gt; on stack overflow i have successfully derived the control points for an bezier curve.Recently i have learned from an &lt;a href=&quot;http://graphics.stanford.edu/courses/cs148-09/lectures/splines.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt; that curves can be represented in matrix form as well so as an practise i decided to derive the bezier control points again but from it's matrix form.&lt;/p&gt;&#xA;&lt;p&gt;If we refer to slide 4 for the basis matrix  and slide 14 from the article for the bezier functions we will find all the parameters needed to construct an bezier curve in the matrix form.&lt;/p&gt;&#xA;&lt;p&gt;Equation 1&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;[a]=  [2  -2   1   1][f(0)]&#xA;[b]=  [-3  3  -2  -1][f(1)]&#xA;[c]=  [0   0   1   0][f'(0)]&#xA;[d]=  [1   0   0   0][f'(1)]&#xA;&#xA;where for an bezier curve&#xA;f(0)=P0&#xA;f(1)=P3&#xA;f'(0)=T0=3(P1-P0)&#xA;f'(1)=T1=3(P3-P2)&#xA;&#xA;and finally a point on the curve is&#xA;p=at^3+bt^2+ct+d where t is normalized time ranging from 0--&amp;gt;1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now from my related post i want to derive the control points so i have to work backwards. I want to find at times t1=1/3 and t2=2/3 what should be the new control points such that they pass through the current control points P0 and P1.&lt;/p&gt;&#xA;&lt;p&gt;This is what i have worked out&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;//We want the bezier curve to pass through p1 and p2. Let us consider only the x axis and equate both sides&#xA;&#xA;p1.x=a*(1/3^3)+b(1/3^2)+c*(1/3)+d    (2)&#xA;p2.x=a*(2/3^3)+b(2/3^2)+c*(2/3)+d    (3)&#xA;&#xA;Now writing equation 1 only for x axis we have&#xA;[a]=  [2  -2   1   1][P0.x]&#xA;[b]=  [-3  3  -2  -1][P3.X]&#xA;[c]=  [0   0   1   0][3(P1.x-P0.x)]&#xA;[d]=  [1   0   0   0][3(P3.x-P2.x)]&#xA;&#xA;on solving we have our abcd values which are&#xA;&#xA;a=2P0.x-2P3.x+3(P1.x-P0.x)+3(P3.x-P2.x)&#xA;b=-3P0.X+3P3.X-6(P1.x-P0.x)-3(P3.x-P2.x)&#xA;c=3(P1.x-P0.x)&#xA;d=3(P3.x-P2.x)&#xA;&#xA;Upon further simplifying and keeping P1.x and P2.x as the unknowns as those are the new control points we want to find out we have&#xA;&#xA;a= -P0.x+3P1.x-3P2.x+P3.x&#xA;b= 3P0.x-6P1.x+3P2.x&#xA;c= 3P1.x-3P0.x&#xA;d= 3P3.x-3P2.x&#xA;&#xA;Upon substituting the values in equation 2 we have&#xA;p1.x=(-P0.x+3P1.x-3P2.x+P3.x)(1/3^3) + (3P0.x-6P1.x+3P2.x)(1/3^2) + (3P1.x-3P0.x)(1/3) + 3P3.x-3P2.x&#xA;&#xA;rearranging all the constants[P0 and P3] to the left hand side we have&#xA;p1.x + ((P0.x-P3.x)*(1/3^3)) + (-3P0.x*(1/3^2)) + (3P0.x*1/3) -3P3.x = 3(P1.x-P2.x)(1/3^3)-3(2P1.x-P2.x)(1/3^2) + 3P1.x*1/3 - 3P2.x&#xA;&#xA;We will call the constant on left hand side as c1 for now. Upon furthur rearranging P1 and P2 terms&#xA;c1=(3*(1/3^3) - 6*(1/3^2) + 3(1/3))P1.x + (-3*(1/3^3) +3*(1/3^2) -3)P2.x&#xA;&#xA;we will call 1/3 as t1 as we might change this to make the curve look diffrent then we have&#xA;&#xA;c1=(3t1^3-6t1^2+3t1)P1.x + (-3t1^3+3t1^2-3)P2.x&#xA;&#xA;Or&#xA;c1=a1P1.x+b1P2.x   (4)&#xA;&#xA;similarly doing the exact same stuff for equation 3 but using p2.x and t2=2/3 we have&#xA;c2=a2P1.x+b2P2.x   (5)&#xA;&#xA; upon writing in matrix form we have&#xA;&#xA; [c1]=[a1  b1][P1.x]&#xA; [c2]=[a2  b2][P2.x]&#xA;&#xA;  Or&#xA;  C=BP BP=C &#xA;&#xA;  and&#xA;&#xA;  P=inverse(B)C&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here is the java pseudo code i have implemented for this. I have used an float array as i want to use bezier curve for any dimension.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt; public static void bezierAdjust(float[] p0,float[] p1,float[] p2,float[] p3)&#xA; {&#xA;  float&#xA;  t1=1.0f/3.0f,&#xA;  t2=2.0f/3.0f; &#xA;  &#xA;  Matrix2f solver=new Matrix2f();&#xA; &#xA;  for(int i=0;i&amp;lt;p0.length;i++) //i=0 x axis,i=1 y axis,i=2 z axis&#xA;  {&#xA;   //solve for t1 and p1&#xA;   double&#xA;   a1=((3*Math.pow(t1,3))-(6*Math.pow(t1,2))+(3*t1)),&#xA;   b1=(-(3*Math.pow(t1,3))+(3*Math.pow(t1,2))-3), &#xA;   c1=p1[i]+((p0[i]-p3[i])*Math.pow(t1,3))+((-3*p0[i])*Math.pow(t1,2))+(3*p0[i]*t1)-(3*p3[i]);&#xA;   &#xA;   //solve for t2 and p2&#xA;   double&#xA;   a2=((3*Math.pow(t2,3))-(6*Math.pow(t2,2))+(3*t2)),&#xA;   b2=(-(3*Math.pow(t2,3))+(3*Math.pow(t2,2))-3), &#xA;   c2=p2[i]+((p0[i]-p3[i])*Math.pow(t2,3))+((-3*p0[i])*Math.pow(t2,2))+(3*p0[i]*t2)-(3*p3[i]);&#xA;  &#xA;   solver.load(FloatBuffer.wrap(new float[]{(float)a1,(float)a2,(float)b1,(float)b2})); //load column wise&#xA;   solver.invert();&#xA;   Vector2f abSolved=Matrix2f.transform(solver,new Vector2f((float)c1,(float)c2),new Vector2f());&#xA;   &#xA;   p1[i]=abSolved.x;&#xA;   p2[i]=abSolved.y;&#xA;  }&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Unfortunatly all that hard work turned my bezier curve from looking like this without any control point modification&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/LxQ8D.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/LxQ8D.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;To this.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xmDUk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xmDUk.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I have posted the same question on stackoverflow but i haven't got any answers yet. Can someone guide me as to where i went wrong if it's my code or calculation or both?&lt;/p&gt;&#xA;" OwnerUserId="15434" LastActivityDate="2020-12-24T08:27:51.093" Title="Bezier curve : Problem deriving control points from matrix form" Tags="&lt;matrix&gt;&lt;bezier-curve&gt;&lt;java&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10516" PostTypeId="1" CreationDate="2020-12-24T17:49:52.370" Score="1" ViewCount="40" Body="&lt;p&gt;I just saw this post by NVIDIA:&#xA;&lt;a href=&quot;https://twitter.com/CasualEffects/status/1341818541532655621&quot; rel=&quot;nofollow noreferrer&quot;&gt;RTX Global Illumination&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The images shown seem to be rendered in realtime which got me thinking about when games will achieve full photorealism and become indistinguishable from reality (or CGI). Games have only begun to use Ray tracing, and even a fully photorealistic engine may not be purely Ray tracing based but it looks like the way forward. A cursory search could not find any related 'moore's law' of photorealism which i find a bit odd since the simulation part has already been worked out (we've had ray tracing since the beginning of computer graphics) and the programmers seem to be waiting for improvements in hardware.&lt;/p&gt;&#xA;&lt;p&gt;Ignoring how other aspects of game development like tooling and artistic input, clumsy physics, uncanny valley etc. will cope with high visual fidelity, when, if ever, will we be able to move around and interact in a world that looks just like the real world.&lt;/p&gt;&#xA;" OwnerUserId="271" LastActivityDate="2020-12-24T17:49:52.370" Title="How many years till photorealistic games?" Tags="&lt;raytracing&gt;&lt;photo-realistic&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2020-12-24T22:13:02.223" ContentLicense="CC BY-SA 4.0" />
  <row Id="10517" PostTypeId="1" AcceptedAnswerId="10530" CreationDate="2020-12-26T13:47:20.563" Score="0" ViewCount="41" Body="&lt;p&gt;I am working on a pure java implementation of OpenGL 1 called &lt;a href=&quot;https://github.com/jzy3d/jGL&quot; rel=&quot;nofollow noreferrer&quot;&gt;jGL&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I am &lt;a href=&quot;https://github.com/jzy3d/jGL/issues/3&quot; rel=&quot;nofollow noreferrer&quot;&gt;missing glPolygonOffsetFill&lt;/a&gt; and am looking for an example implementation in java, c/c++ example of this GL function in order to integrate it in jGL.&lt;/p&gt;&#xA;&lt;p&gt;Would anyone suggest a direction?&lt;/p&gt;&#xA;" OwnerUserId="8263" LastActivityDate="2020-12-29T11:44:13.600" Title="OpenGL Polygon Offset Fill implementation example code" Tags="&lt;opengl&gt;&lt;polygon&gt;&lt;java&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10518" PostTypeId="1" AcceptedAnswerId="10519" CreationDate="2020-12-27T01:17:47.640" Score="2" ViewCount="32" Body="&lt;p&gt;I am working with the cosine function with a very large input, like &lt;code&gt;cos(a* t)&lt;/code&gt;, where &lt;code&gt;t&lt;/code&gt; varies between  &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;~ 200&lt;/code&gt;; and &lt;code&gt;a&lt;/code&gt; can be as large as &lt;code&gt;10^8&lt;/code&gt;-&lt;/p&gt;&#xA;&lt;p&gt;I come across, as expected, the artifact error. If I sample &lt;code&gt;t&lt;/code&gt; with a stepsize of &lt;code&gt;0.01&lt;/code&gt; with &lt;code&gt;a&lt;/code&gt; 100, I get a plot like this :&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/H496n.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/H496n.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Notice, that for large value of &lt;code&gt;a&lt;/code&gt;, the sampling of &lt;code&gt;t&lt;/code&gt; needs to be fine, otherwise, you will not get regular cosine shape from &lt;code&gt;-1&lt;/code&gt; to &lt;code&gt;1&lt;/code&gt;. Sometimes, wave peaks, and other times wave troughs will be missed, due to low granularity, and you will end up with a different shape of the wave than the theoritical value.&lt;/p&gt;&#xA;&lt;p&gt;Now, increase &lt;code&gt;a&lt;/code&gt; to be &lt;code&gt;100000&lt;/code&gt;, and as expected, the effect is much more pronounced.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YjEcf.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YjEcf.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;My question : Is there a formula / algorithm, to avoid this effect? Is there a formula, that tells you the correct step size for a large value of &lt;code&gt;a&lt;/code&gt; ?&lt;/p&gt;&#xA;&lt;p&gt;I tried to google the following keywords : &lt;code&gt;large input cosine function computer graphics&lt;/code&gt;, but that did not help.&lt;/p&gt;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="15444" LastActivityDate="2020-12-27T06:54:58.417" Title="Algorithm for proper drawing of cosine function" Tags="&lt;sampling&gt;&lt;2d-graphics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10519" PostTypeId="2" ParentId="10518" CreationDate="2020-12-27T06:54:58.417" Score="1" Body="&lt;p&gt;There is in fact a way to avoid this effect and it is outlined by the NYQUIST sampling theorem - which states that the sampling rate should be at least twice as high as the maximum frequency of the function of interest. &lt;br&gt;&#xA;In this case where &lt;code&gt;cos(a * t)&lt;/code&gt; is the function of interest, the frequency is &lt;code&gt;a/(2*pi)&lt;/code&gt; - therefore your sampling rate should be greater than &lt;code&gt;2 * a/(2*pi)&lt;/code&gt; (in this case you may even want the sampling rate to be even higher so that the cosine function has a nice curve to it). &lt;br&gt;&#xA;To get the step size from this sampling rate just use &lt;code&gt;t = 1/(sampling rate)&lt;/code&gt; &lt;br&gt;&#xA;Hope this helps :)&lt;/p&gt;&#xA;" OwnerUserId="15446" LastActivityDate="2020-12-27T06:54:58.417" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10521" PostTypeId="2" ParentId="10490" CreationDate="2020-12-27T12:09:25.237" Score="1" Body="&lt;p&gt;This is an interesting question, as intuitively we would think that the image size of the object will be 50% of the image width. However, upon some playing around with triangles, I found this to not be the case. &lt;br&gt;&lt;br&gt;&#xA;For example, take a look at the diagram below. Here we have two overlapping triangles, one with angular diameter of 50 degrees (representing the object's angular diameter), and one with angular diameter 100 degrees (representing the camera's FoV). As we can see, the object has a width of 1 unit as seen from the camera, however the image width is around 3 units - therefore in this case the horizontal image size of the object will be around 33% of the image width.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/mCLjh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mCLjh.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;&#xA;If you were to play around with different values for D and d, you would find that the angular diameter ratios would vary. There would be a way to calculate this ratio directly with some trigonometry, however I do not know of how much use that would be to you. &lt;br&gt;&lt;br&gt;&#xA;Hope this helps in some way :)&lt;/p&gt;&#xA;" OwnerUserId="15446" LastActivityDate="2020-12-27T12:09:25.237" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10522" PostTypeId="1" AcceptedAnswerId="10523" CreationDate="2020-12-27T12:19:58.097" Score="3" ViewCount="81" Body="&lt;p&gt;I'm trying to understand a go library for Delaunay triangulation and found out this function to calculate the pseudo angle&lt;/p&gt;&#xA;&lt;p&gt;Here is the implementation of the psuedo angle&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    func pseudoAngle(dx, dy float64) float64 {&#xA;        p := dx / (math.Abs(dx) + math.Abs(dy))&#xA;        if dy &amp;gt; 0 {&#xA;            p = (3 - p) / 4&#xA;        } else {&#xA;            p = (1 + p) / 4&#xA;        }&#xA;        return math.Max(0, math.Min(1-eps, p))&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here is were it have been used :&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;func (t *triangulator) hashKey(point r3.Point) int {&#xA;&#xA;    d := point.Sub(t.center)&#xA;    return int(pseudoAngle(d[0], d[1]) * float64(len(t.hash)))&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Do you have any idea of where this implementation is coming from mathematically ?&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;" OwnerUserId="15225" LastActivityDate="2020-12-27T18:17:19.957" Title="understand a pseudo angle implementation" Tags="&lt;implementation&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10523" PostTypeId="2" ParentId="10522" CreationDate="2020-12-27T18:17:19.957" Score="2" Body="&lt;p&gt;The &amp;quot;pseudo-angle&amp;quot; this function defines runs from 0 to 1 counterclockwise around the circle, with 0 at the negative x-axis, and each 25% of the range mapping to one quadrant (so 0.25 at the negative y-axis, 0.5 at the positive x-axis, etc).&lt;/p&gt;&#xA;&lt;p&gt;First, the expression &lt;code&gt;dx / (math.Abs(dx) + math.Abs(dy))&lt;/code&gt;, can be seen as normalizing the vector in the 1-norm or &lt;a href=&quot;https://en.wikipedia.org/wiki/Norm_(mathematics)#Taxicab_norm_or_Manhattan_norm&quot; rel=&quot;nofollow noreferrer&quot;&gt;taxicab norm&lt;/a&gt; as opposed to the usual Euclidean norm. In other words, it's projecting the vector onto the unit diamond:&lt;/p&gt;&#xA;&lt;img src=&quot;https://i.stack.imgur.com/0ZDNf.png&quot; width=&quot;400&quot; height=&quot;400&quot; alt=&quot;unit ball in the 1-norm&quot;/&gt;&#xA;&lt;p&gt;After that, it looks at the sign of y and remaps x accordingly. For the lower half of the diamond (negative y), it maps x linearly from [−1, 1] to [0, 0.5]. For the top half it maps x from [1, –1] to [0.5, 1] (reversing the direction of the mapping this time). So, as you start from the point (−1, 0) and go counterclockwise around the diamond, the pseudo-angle result will increase from 0 to 1.&lt;/p&gt;&#xA;&lt;p&gt;It is probably used because the system wants to sort vectors by their angle (or in this case, incorporate the angle in a hash apparently), but it doesn't need the actual Euclidean angle which would require an expensive atan2 function to calculate. It just needs something monotonically related to the angle but cheap to calculate, and this pseudo-angle fits the bill.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2020-12-27T18:17:19.957" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10524" PostTypeId="1" AcceptedAnswerId="10525" CreationDate="2020-12-28T00:49:26.563" Score="0" ViewCount="74" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zI0cS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zI0cS.png&quot; alt=&quot;cell renderer&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am interested how that image on the right of the slider (just albedo) can produce such a realistic looking scene as the scene on the left.&#xA;What effects (at a minimum) does this scene seem to be using. ie. what rendering features would be necessary to reproduce this scene?&#xA;Thanks&lt;/p&gt;&#xA;&lt;p&gt;Apologies for the poor quality screenshot, for reference, it is taken from &lt;a href=&quot;https://www.youtube.com/watch?v=2uSWEc-O8wk&amp;amp;t=65s&quot; rel=&quot;nofollow noreferrer&quot;&gt;Joey de Vries 2017 tech reel&lt;/a&gt; at about the 1:05 mark.&lt;/p&gt;&#xA;" OwnerUserId="10450" LastActivityDate="2020-12-28T02:50:35.287" Title="What effects are used to light this scene?" Tags="&lt;rendering&gt;&lt;lighting&gt;&lt;shading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10525" PostTypeId="2" ParentId="10524" CreationDate="2020-12-28T02:50:35.287" Score="1" Body="&lt;p&gt;The rendering engine that rendered this image is using a technique called deferred rendering, which first writes scene information (as seen from the camera) to seperate buffers (such as position, normal, and albedo buffers) and then calculates lighting for the image based off this information. It is important that we have position and normal buffers on top of the albedo buffer so that lighting can be calculated at each pixel (these buffers are not visible in your example, but they are there under the hood). As an example, take a look at the image below that shows the different buffers of an engine I worked on - it may help to better understand what is going on. &lt;br&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/HkUQk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HkUQk.jpg&quot; alt=&quot;Deferred Rendering Buffers&quot; /&gt;&lt;/a&gt; &lt;br&gt;&lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;Once a buffer has been made with all of the lighting calculations, you can then achieve post processing effects by processing the buffer with various algorithms to produce the final image. Some post processing effects that are visible in your image are bloom (which adds &amp;quot;glow&amp;quot; to bright spots), motion blur and an implementation of screen space ambient occlusion (SSAO). &lt;br&gt;&lt;br&gt;&#xA;A full list of the rendering features can actually be found at the 1:02 mark of the video, I have attached the image here to make it easy to see. It may be worth googling what each individual post-processing effect does so that you can better understand the effect they have on the overall image.&lt;br&gt;&lt;br&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ncf3Z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ncf3Z.png&quot; alt=&quot;Rendering features&quot; /&gt;&lt;/a&gt;&#xA;&lt;br&gt;&lt;br&gt;&#xA;Hope this was of help :)&lt;/p&gt;&#xA;" OwnerUserId="15446" LastActivityDate="2020-12-28T02:50:35.287" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10527" PostTypeId="1" CreationDate="2020-12-28T17:45:38.180" Score="1" ViewCount="40" Body="&lt;p&gt;I want to use IES profile with an area light. My understanding is that the IES file assume the source to be a point light. That is in case of (large)area light the measurements are taken at a distance(normally 5 times the major dimension of the light source) that even an area light can be considered as a point light. However I am confused on how a measurement taken at say 12m can be used to calculate the contribution of the luminaire at shorter distances?&lt;/p&gt;&#xA;&lt;p&gt;Also as the IES file has intensities values rather than the radiance,&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Is the below formula correct for calculating the irradiance from the light source in the form of the integral over the area, when we have the intensities ?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/NnbRR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/NnbRR.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am little bit uncertain on the solid angle formulation. Is this correct?&lt;/p&gt;&#xA;&lt;ol start=&quot;2&quot;&gt;&#xA;&lt;li&gt;well if the above is correct, I am not clear how this fits in a monte carlo ray tracer ? Are we sampling intensities here? What is the pdf? also currently in my ray tracer all light sources methods and properties needs radiance values of the light source instead of intensity how would this fit in?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="6041" LastEditorUserId="6041" LastEditDate="2020-12-28T20:25:39.153" LastActivityDate="2020-12-28T20:25:39.153" Title="How to use IES Light Profile with an area light source?" Tags="&lt;pathtracing&gt;&lt;lighting&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10528" PostTypeId="2" ParentId="10512" CreationDate="2020-12-29T02:28:14.663" Score="0" Body="&lt;p&gt;&lt;em&gt;[Disclaimer: I'm a hobbyist, not well-read in computer graphics techniques. I may be unfamiliar with common terminology or methods.]&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;It's possible to explain and reproduce this effect entirely in a “physically-based” manner, simulating the imperfections of physical objects:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Many objects do not emit or reflect single wavelengths of light, but some spectrum, even if one wavelength dominates.&lt;/li&gt;&#xA;&lt;li&gt;Light sensors, whether they are cameras or the human eye, do not have perfect RGB color filters which reject all light outside of non-overlapping bands.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;These two effects combined mean that &lt;strong&gt;if we make an object bright enough, well past the point of “overexposing” the image, all colors will become perceptually white.&lt;/strong&gt; All you need to do to implement this is:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Specify the monochromatic color of your glow such that none of its color channels are exactly zero.&lt;/li&gt;&#xA;&lt;li&gt;While you're doing your floating-point color calculations in your fragment shader, multiply your glow by a number much greater than 1, causing clipping in the final output image.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;A potential disadvantage of this technique is that, if the hue of the glow is not one of the six primary or secondary colors, then there will be a hue shift in the segment between where one color channel saturates and two do; it'll shift some amount towards cyan/magenta/yellow before proceeding to white. This is not unrealistic, but it might be unaesthetic.&lt;/p&gt;&#xA;&lt;p&gt;Even if there is not a hue shift, the points where individual color channels saturate might be noticeable due to the sharp change in the spatial derivative; this could be improved by introducing a “soft clipping” nonlinearity that slows down the approach to the maximum value of each channel (which is a form of global tone mapping).&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;As an example of the results of this strategy, here is a simple simulation of a CRT oscilloscope trace that I programmed. The algorithm is:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Draw many dim 1-pixel points overlaid with additive blending.&lt;/p&gt;&#xA;&lt;p&gt;(It would be more efficient and precise to use a line with variable brightness, but throwing lots of points at the problem was easy to implement, though it produces artifacts such as dotted lines which are visible in this example.)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Blur.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Multiply by (R=0.1 G=1.0 B=0.5) × a configurable brightness parameter.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rXNTA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rXNTA.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Notice that the dark areas (vertical lines) are mostly green and the bright areas (horizontal lines and peaks, where the simulated beam moves slower) have a white core.&lt;/p&gt;&#xA;" OwnerUserId="445" LastActivityDate="2020-12-29T02:28:14.663" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10529" PostTypeId="1" AcceptedAnswerId="10531" CreationDate="2020-12-29T08:14:19.890" Score="2" ViewCount="38" Body="&lt;p&gt;Recently I have been trying to create a shader that imitates a shader within Affinity Photo. It is used in the radial gradient fill and essentially you set your endpoint colors and then set the midpoint to a percent.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8tBPH.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8tBPH.gif&quot; alt=&quot;Showing toggling of effect&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;What is interesting here is that with a midpoint set to 0 everything is not just one color. Same with 100. So it does not appear to be a trivial function.&lt;/p&gt;&#xA;&lt;p&gt;I exported some images of this gradient at percent of 0%, 50% and 100% and graphed the red pixel values from the center pixel going to the end. Below are the results.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pyzFY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pyzFY.png&quot; alt=&quot;Results graphed&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Unfortunately even after seeing it graphed I am unable to determine the f(x,a) where a goes from 0-100 that would recreate this graph in order to replicate the shader. Any tips that might get me closer to this formula?&lt;/p&gt;&#xA;" OwnerUserId="7072" LastActivityDate="2021-01-02T12:14:01.880" Title="Determining the function of a radial gradient fill with midpoint" Tags="&lt;mathematics&gt;&lt;shading&gt;&lt;gradient&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10530" PostTypeId="2" ParentId="10517" CreationDate="2020-12-29T11:44:13.600" Score="0" Body="&lt;p&gt;I found a workaround suggested &lt;a href=&quot;https://www.opengl.org/archives/resources/faq/technical/polygonoffset.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;at the bottom of this page&lt;/a&gt; : to deal with coplanar lines and polygons, one can apply a different glDepthRange to polygon face and polygon wireframe.&lt;/p&gt;&#xA;" OwnerUserId="8263" LastActivityDate="2020-12-29T11:44:13.600" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10531" PostTypeId="2" ParentId="10529" CreationDate="2020-12-29T12:24:34.220" Score="2" Body="&lt;p&gt;It seems to be just a scalar Bezier function to me, where the second coefficient is determined by &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(1-x)^2 + a 2 (1-x) x,$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;here &lt;span class=&quot;math-container&quot;&gt;$a \in [0, 1]$&lt;/span&gt; is a normalized percentage. This gets you pretty close to the function that is graphed, but the function will not be as flat for &lt;span class=&quot;math-container&quot;&gt;$a = 0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$a = 1$&lt;/span&gt;. I suspect the function is of a higher degree:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(1-x)^3 + a 3(1-x)^2 x + a 3(1-x) x^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;or even&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(1-x)^4 + a 4(1-x)^3 x + a 6(1-x)^2 x^2 + a 4 (1-x) x^3$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;With increasing degree comes increased flatness (dragging out the colour of the midpoint). However, these higher order function are not exactly straight at &lt;span class=&quot;math-container&quot;&gt;$a = 0.5$&lt;/span&gt;. Using the coefficients &lt;span class=&quot;math-container&quot;&gt;$\frac{2}{3}$&lt;/span&gt; &lt;span class=&quot;math-container&quot;&gt;$\frac{1}{3}$&lt;/span&gt; in the cubic equation will get you a straight line for the cubic version&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(1-x)^3 + \frac{2}{3} 3(1-x)^2 x + \frac{1}{3} 3(1-x) x^2.$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;For the cubic version you can create two additional functions&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$q(a) = 0.975 \cdot 2 (1-x) x + x^2$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$r(a) = 0.025 \cdot 2 (1-x) x + x^2$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;and then replace the second and fourth coefficents in the quartic function with these&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(1-x)^4 + q(a) 4(1-x)^3 x + a 6(1-x)^2 x^2 + r(a) 4 (1-x) x^3$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;this will preserve flatness at extremes and (approximate) linearity at &lt;span class=&quot;math-container&quot;&gt;$a=0.5$&lt;/span&gt;. You can view it here: &lt;a href=&quot;https://www.desmos.com/calculator/hwj7jyozv9&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.desmos.com/calculator/hwj7jyozv9&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2021-01-02T12:14:01.880" LastActivityDate="2021-01-02T12:14:01.880" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10532" PostTypeId="2" ParentId="4139" CreationDate="2020-12-30T06:23:59.403" Score="1" Body="&lt;p&gt;Fellow 15-year-old here.&#xA;As far as I have read, you would usually implement an Area light by combining multiple things:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A point or directional light at the position for BRDF calculations.&lt;/li&gt;&#xA;&lt;li&gt;Using the size of the light for a specular highlight.&lt;/li&gt;&#xA;&lt;li&gt;PCSS or another technique for soft shadows.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="15470" LastActivityDate="2020-12-30T06:23:59.403" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10533" PostTypeId="1" CreationDate="2020-12-30T18:58:57.533" Score="2" ViewCount="66" Body="&lt;p&gt;I'm wondering how to compute a bounding tetrahedron from a set of points so i can initialize a delaunay triangulation&lt;/p&gt;&#xA;&lt;p&gt;My first approach was to find the bounding box to my set of points and then compute a tetrahedron going from the bounding box .&lt;/p&gt;&#xA;&lt;p&gt;I'm searching for a robust method for doing it .&lt;/p&gt;&#xA;" OwnerUserId="15225" LastActivityDate="2020-12-30T18:58:57.533" Title="How to compute a bounding tetrahedron" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;triangulation&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10535" PostTypeId="1" CreationDate="2021-01-02T14:23:50.977" Score="0" ViewCount="63" Body="&lt;p&gt;I have a situation, where I have an array of vertices on the CPU side, for which, besides rendering-relevant data, like their position, I have a lot of other data at each vertex. All vertex data is updated (more or less) every frame, requiring transferring the changes over to the GPU every time.&lt;/p&gt;&#xA;&lt;p&gt;So far I have used two approaches, neither of which I am particularly happy with:&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Approach 1&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Just copy everything over to the GPU. This might seem silly, but my application does not use a significant amount of VRAM overall, so this is no issue in that regard, but of course, when the vertex count increases, so does the amount of data needlessly transferred to the GPU every frame, which does become a performance issue.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Approach 2&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Keep separate arrays for the GPU-relevant vertex data and the non-relevant vertex data. While this solves the unnecessary transfer issue, I find it very clunky to work with on the CPU side, since I at all times have to keep two arrays in sync. Ideally, I would like to have one clean struct per vertex, which I can easily work with.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Is there some other approach to this?&lt;/p&gt;&#xA;&lt;p&gt;Something I could think of, which unfortunately doesn't seem to exist in OpenGL, is a variant of &lt;code&gt;glBufferData&lt;/code&gt;, which I could tell some stride and offset, like with &lt;code&gt;glVertexAttribPointer&lt;/code&gt;, which parts of each data block I want to transfer to the buffer in VRAM.&lt;/p&gt;&#xA;&lt;p&gt;There also might be some way to neatly solve this with some C++ features that I am not aware of. Some way to have two arrays act as one, or something like that.&lt;/p&gt;&#xA;&lt;p&gt;Any ideas and suggestions are appreciated.&lt;/p&gt;&#xA;" OwnerUserId="15232" LastEditorUserId="13095" LastEditDate="2021-01-02T14:55:00.967" LastActivityDate="2021-01-23T14:30:40.097" Title="Efficiently transferring only needed parts of the vertex data to the GPU (C++/OpenGL)" Tags="&lt;opengl&gt;&lt;c++&gt;&lt;vertex-buffer-object&gt;&lt;data-structure&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10537" PostTypeId="1" CreationDate="2021-01-03T22:36:28.013" Score="1" ViewCount="49" Body="&lt;p&gt;I am reading Physically Based Rendering &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Color_and_Radiometry/The_SampledSpectrum_Class.html#RGBColor&quot; rel=&quot;nofollow noreferrer&quot;&gt;section 2.2.2 on RGB color&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I am trying to understand how, given a display spectral response curves for rgb intensities, we can choose the intensities so that the display will emit an equivalent spectrum (a CIE xyz metamer)&lt;/p&gt;&#xA;&lt;p&gt;It is my understanding that the following section tries to explain exactly that.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Given an &lt;em&gt;(x,y,z)&lt;/em&gt; representation of an SPD, we can convert it to corresponding&#xA;RGB coefficients, given the choice of a particular set of SPDs that&#xA;define red, green, and blue for a display of interest. Given the&#xA;spectral response curves &lt;em&gt;R(lambda)&lt;/em&gt;, &lt;em&gt;G(lambda)&lt;/em&gt;, and &lt;em&gt;B(lambda)&lt;/em&gt;, for a particular display, RGB&#xA;coefficients can be computed by integrating the response curves with&#xA;the SPD &lt;em&gt;S(lambda)&lt;/em&gt; and using the tristimulus theory of color perception:&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/32Yww.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/32Yww.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I can't understand this formula. Why it is considered correct? Why choosing &lt;em&gt;r&lt;/em&gt; this way makes the display emit the correct / equivalent SPD?&lt;/p&gt;&#xA;&lt;p&gt;Can someone break it down for me?&lt;/p&gt;&#xA;" OwnerUserId="9154" LastEditorUserId="9154" LastEditDate="2021-01-03T22:52:25.023" LastActivityDate="2021-02-06T05:05:20.517" Title="How to determine RGB values given a display spectral response curve?" Tags="&lt;color&gt;&lt;physically-based&gt;&lt;color-science&gt;&lt;spectral&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10538" PostTypeId="1" CreationDate="2021-01-03T22:38:17.140" Score="0" ViewCount="32" Body="&lt;p&gt;First off, this may not be the right group, however, it is the closest one I can think of.&lt;/p&gt;&#xA;&lt;p&gt;I took a few pictures of a computer panel at a known distance, but the angle to a corner would require the use of the 3D Pythagoras theorem (&lt;em&gt;√(x^2 + y^2 + z^2)&lt;/em&gt;) See &lt;a href=&quot;https://www.mathsisfun.com/geometry/pythagoras-3d.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Pythagoras theorem in 3D&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So my questions are thus:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;What is the first step?&lt;/li&gt;&#xA;&lt;li&gt;Will this be possible instead of measuring EVERYTHING?&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Pictures will be attached:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://i.stack.imgur.com/iGyX2.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iGyX2.jpg&quot; alt=&quot;Rear Panel - Zoom in to get the exact mm measurement&quot; /&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://i.stack.imgur.com/Xgina.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Xgina.jpg&quot; alt=&quot;Rear Panel&quot; /&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://i.stack.imgur.com/iywFV.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/iywFV.jpg&quot; alt=&quot;Rear Panel&quot; /&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://i.stack.imgur.com/z3Kpq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/z3Kpq.jpg&quot; alt=&quot;Rear Panel&quot; /&gt;&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="15493" LastActivityDate="2021-01-03T22:38:17.140" Title="How to extrapolate an object from a photo taken with an iPhone" Tags="&lt;image-processing&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10539" PostTypeId="2" ParentId="10509" CreationDate="2021-01-06T02:43:18.757" Score="0" Body="&lt;p&gt;I exported an example from Blender to replicate the issue, with the most basic project (unwrap, simple image texture in shader editor) and found it looked exactly like what your expected image shows.&lt;/p&gt;&#xA;&lt;p&gt;I exported it to some simple model-loading code and it textured it correctly.&#xA;When I used your OBJ file (after adding &lt;code&gt;mtllib cube.mtl&lt;/code&gt; and a &lt;code&gt;map_Kd cube.png&lt;/code&gt; to &lt;code&gt;cube.mtl&lt;/code&gt;), it was showing the similar texture problems. Then,I saw that the working OBJ file was generating less faces (didn't have triangulate vertices checked) and the UVs were generated differently.&lt;/p&gt;&#xA;&lt;p&gt;Alas, I would say it is an issue with how you process your vertices, whether importing as quads or triangles, and would suggest having a look at that (either leaving triangulate vertices unchecked or fixing the code).&lt;/p&gt;&#xA;" OwnerUserId="10450" LastActivityDate="2021-01-06T02:43:18.757" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10540" PostTypeId="1" CreationDate="2021-01-06T13:51:08.670" Score="0" ViewCount="24" Body="&lt;p&gt;Why does &lt;code&gt;ID3D12Device::CreateCommittedResource&lt;/code&gt; require a &lt;code&gt;D3D12_HEAP_FLAGS&lt;/code&gt; argument similar to &lt;code&gt;ID3D12Device::CreatePlacedResource&lt;/code&gt;? As the former both creates a &lt;code&gt;ID3D12Resource&lt;/code&gt; and an implicit &lt;code&gt;ID3D12Heap&lt;/code&gt; for just that &lt;code&gt;ID3D12Resource&lt;/code&gt;, why couldn't the &lt;code&gt;D3D12_HEAP_FLAGS&lt;/code&gt; be deduced from the &lt;code&gt;D3D12_RESOURCE_DESC&lt;/code&gt;?&lt;/p&gt;&#xA;&lt;p&gt;For example, the presence of &lt;code&gt;D3D12_RESOURCE_DIMENSION_BUFFER&lt;/code&gt; could map to &lt;code&gt;D3D12_HEAP_FLAG_ALLOW_ONLY_BUFFERS&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2021-01-06T13:51:08.670" Title="D3D12_HEAP_FLAGS argument of ID3D12Device::CreateCommittedResource" Tags="&lt;directx12&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10541" PostTypeId="1" CreationDate="2021-01-06T16:08:12.230" Score="3" ViewCount="142" Body="&lt;p&gt;I'm new to learning about ray tracing, but have been fairly confused by the mathematical foundations of it all. Specifically of radiometry/radiative transfer. I've internet searched a lot and skimmed a ton of references, but still very confused.&lt;/p&gt;&#xA;&lt;p&gt;Here is a list of some of the things I have had to struggle a lot to understand:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Irradiance is a function of 3 variables &lt;span class=&quot;math-container&quot;&gt;$E(p,n, \mathrm{in}/\mathrm{out})$&lt;/span&gt; and it's not really the derivative of anything with respect to anything else (in the function sense)&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; is a point on an actual surface in a scene, irradiance doesn't make sense in directions that aren't the surface normal, except perhaps as limit.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Radiance is not meaningfully the derivative of irradiance (Wikipedia says it's the derivative w.r.t. étendue, which is a great way to get more confused).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Radiance can be defined without ever using the words &amp;quot;projected area&amp;quot;, &amp;quot;solid angle&amp;quot; or &amp;quot;subtend&amp;quot;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You don't need to draw pictures with infinitesimals to think about radiance. I see infinitesimals in pictures a lot, e.g. &lt;a href=&quot;https://en.wikipedia.org/wiki/Lambert%27s_cosine_law#Details_of_equal_brightness_effect&quot; rel=&quot;nofollow noreferrer&quot;&gt;Figures 1 and 2 Wikipedia's Lambert's cosine law article&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Radiance is preserved along paths (in vacuum). Is this an axiom of the theory or a theorem?&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I've  found the following approach more insightful than the usual presentations:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;If you have an oriented surface, you can define the flux entering it &lt;span class=&quot;math-container&quot;&gt;$\Phi(S)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Irradiance is something that's integrated into flux:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \Phi(S) = \int_SE(p, n_p, \mathrm{in}) \mathrm{d}S(p)$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;For two surfaces, we can define direct flux transport between them: the power that exist &lt;span class=&quot;math-container&quot;&gt;$S_1$&lt;/span&gt; and directly enters &lt;span class=&quot;math-container&quot;&gt;$S_2$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\Phi(S_1, S_2)$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&amp;quot;Flux transport density&amp;quot; (not sure if correct term) is something that's integrated into flux transport. It is the function of 4 variables &lt;span class=&quot;math-container&quot;&gt;$K(p_\text{source}, n_\text{source}, p_\text{target}, n_\text{target})$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \Phi(S_1,S_2) = \int_{S_2} \int_{S_1} K(p, n_p, q, n_q) \mathrm{d}S_1(p) \mathrm{d}S_2(q)$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&amp;quot;Light hull principle&amp;quot; consider two oriented disks &lt;span class=&quot;math-container&quot;&gt;$D_p = D(p, n_p, r_p)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$D_q = D(q, n_q, r_q)$&lt;/span&gt; that are sufficiently small.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$(q-p) \cdot n_p \le 0$&lt;/span&gt; then &lt;span class=&quot;math-container&quot;&gt;$\Phi(D_p, D_q) = 0$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Taking the limit &lt;span class=&quot;math-container&quot;&gt;$r_p \to 0$&lt;/span&gt; shows that &lt;span class=&quot;math-container&quot;&gt;$(q-p) \cdot n_p$&lt;/span&gt; implies &lt;span class=&quot;math-container&quot;&gt;$K(p, n_p, q, n_q) = 0$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;If &lt;span class=&quot;math-container&quot;&gt;$(p-q) \cdot n_q \le 0$&lt;/span&gt; then &lt;span class=&quot;math-container&quot;&gt;$\Phi(D_p, D_q) = 0$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Taking the limit &lt;span class=&quot;math-container&quot;&gt;$r_q \to 0$&lt;/span&gt; shows that &lt;span class=&quot;math-container&quot;&gt;$(p-q) \cdot n_q$&lt;/span&gt; implies &lt;span class=&quot;math-container&quot;&gt;$K(p, n_p, q, n_q) = 0$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Let's assume &lt;span class=&quot;math-container&quot;&gt;$(q-p) \cdot n_p &amp;gt; 0$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$(p-q) \cdot n_q &amp;gt; 0$&lt;/span&gt; going forward. Maybe it's simplier to write &lt;span class=&quot;math-container&quot;&gt;$|\cos(\theta_p)| &amp;lt; \pi/2$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$|\cos(\theta_q)| &amp;lt; \pi/2$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Let's form the &amp;quot;light hull&amp;quot; of &lt;span class=&quot;math-container&quot;&gt;$D_p$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$D_q$&lt;/span&gt;. This is a funny truncated cone like shape defined by &lt;span class=&quot;math-container&quot;&gt;$$H(D_p, D_q) = \{ t p' + (1-t) q' | p' \in D_p, q' \in D_q, t \in [0, 1] \}$$&lt;/span&gt; &lt;a href=&quot;https://i.stack.imgur.com/qTJlU.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qTJlU.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt; It may later make sense to allow  &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; to go negative/greater than 1, extending the hull a bit.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; be a point on the segment &lt;span class=&quot;math-container&quot;&gt;$pq$&lt;/span&gt;. Intersecting the light hull with a plane through &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; gives as circular shaped section:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$H(a, n_a, D_p, D_q) = \{ b | (b - a) \cdot n_a = 0 \} \cap H(D_p, D_q) $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;In free space we have &lt;span class=&quot;math-container&quot;&gt;$$\Phi(D_p, D_q) = \Phi(D_p, H(a, n_a, D_p, D_q)) = \Phi(H(a, n_a, D_p, D_q), D_q)$$&lt;/span&gt; I call this the &lt;em&gt;light hull principle&lt;/em&gt; and is basically just geometry saying &amp;quot;if I put a transparent screen in the light's way, all the light will go through it&amp;quot;.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Using the light hull principle, we see that we can replace &lt;span class=&quot;math-container&quot;&gt;$D_q$&lt;/span&gt; with a similar disk-ish shape that's orthogonal to &lt;span class=&quot;math-container&quot;&gt;$pq$&lt;/span&gt;: &lt;span class=&quot;math-container&quot;&gt;$$ \Phi(D_p, D_q) = \Phi(D_p, H(q, p-q, D_p, D_q))$$&lt;/span&gt; Let's call this shape &lt;span class=&quot;math-container&quot;&gt;$D_q'$&lt;/span&gt;.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/or5th.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/or5th.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&#xA;For small &lt;span class=&quot;math-container&quot;&gt;$r_p^2$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$r_q^2$&lt;/span&gt;, the left hand side is&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \Phi(D_p, D_q) \approx K(p, n_p, q, n_q) \pi^2 r_p^2 r_q^2$$&lt;/span&gt;&#xA;Or more formally&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \frac{\partial^4 \Phi(D_p, D_q) }{(\partial r_p)^2 (\partial r_q)^2} \bigg|_{r_p = r_q = 0} = 4 \pi^2 K(p, n_p, q, n_q) $$&lt;/span&gt;&#xA;I don't want to go into too much detail here, but it's possible to prove for the right hand side that &lt;span class=&quot;math-container&quot;&gt;$$ \frac{\partial^4 \Phi(D_p, H(q, p-q, D_p, D_q)) }{(\partial r_p)^2 (\partial r_q)^2} \bigg|_{r_p = r_q = 0} = 4 \pi^2 \cos(\theta_q) K\left(p, n_p, q, \frac{p-q}{||p-q||} \right) $$&lt;/span&gt;&#xA;It follows that &lt;span class=&quot;math-container&quot;&gt;$$ K(p, n_p, q, n_q) = \cos(\theta_q) K\left(p, n_p, q, \frac{p-q}{||p-q||} \right)$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Repeating the same argument at &lt;span class=&quot;math-container&quot;&gt;$p$&lt;/span&gt; instead of &lt;span class=&quot;math-container&quot;&gt;$q$&lt;/span&gt;, we get&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ K(p, n_p, q, n_q) = \cos(\theta_p) \cos(\theta_q) K\left(p, \frac{q-p}{||p-q||}, q, \frac{p-q}{||p-q||} \right)$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Assuming now that the two disks are directly facing each other, i.e. &lt;span class=&quot;math-container&quot;&gt;$n_p = \frac{q-p}{||p-q||} = -n_q$&lt;/span&gt;, we can apply the light hull principle and take a limit/derivative as &lt;span class=&quot;math-container&quot;&gt;$r_p, r_q \to 0$&lt;/span&gt; to show the inverse square law&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ K(p, n_p, p+r n_p, -n_p) = \frac{1}{r^2} K(p, n_p, p+n_p, - n_p)$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$r = ||p-q||$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$n = \frac{q-p}{r}$&lt;/span&gt;. We now know that&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \begin{aligned}&#xA;K(p, n_p, q, n_q) &amp;amp;= K(p, n, p+n, -n) \frac{\cos(\theta_p) \cos(\theta_q)}{r^2} \\&#xA;&amp;amp;=: L(p,n,\mathrm{out}) \frac{\cos(\theta_p) \cos(\theta_q)}{r^2} \\&#xA;&amp;amp;=: L(q,-n,\mathrm{in}) \frac{\cos(\theta_p) \cos(\theta_q)}{r^2}&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&#xA;Where &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; is the defined by the equation above. We call &lt;span class=&quot;math-container&quot;&gt;$L$&lt;/span&gt; radiance.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;Taking the limit &lt;span class=&quot;math-container&quot;&gt;$p \to q$&lt;/span&gt; shows that &lt;span class=&quot;math-container&quot;&gt;$L(q, n, \mathrm{out}) = L(q, -n, \mathrm{in}) = L(p, n, \mathrm{out})$&lt;/span&gt;. Therefore radiance is constant along rays (and &lt;span class=&quot;math-container&quot;&gt;$K$&lt;/span&gt; is translation invariant).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The significance of this is that we have defined radiance and proved it invariant by using a simple geometric principle on finite (non-infinitesimal) surfaces and taking appropriate limits. It's a lot more work than saying irradiance over projected surface area times solid angle, but to me much more intuitive.&lt;/p&gt;&#xA;&lt;p&gt;The light hull principle is an axiom/key &amp;quot;physical&amp;quot; fact, and everything else is a theorem.&lt;/p&gt;&#xA;&lt;p&gt;My question is; is there a reference that deals with radiative transfer in general in a similar way as I've just dealt with radiance?&lt;/p&gt;&#xA;&lt;p&gt;The closest thing I could find is &lt;a href=&quot;https://graphics.stanford.edu/papers/veach_thesis/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Veach's PhD thesis&lt;/a&gt; where he defines some interesting concepts using measure theory in Chapter 3 and its appendix. The idea is that a scene is a system of &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; non-interacting photons moving around. Radiometric quantities can then be defined by a snapshot of this system in time. I think it's a really cool idea and would love to see more of this. To me these are the true foundations. Sadly, I don't think Veach develops them in enough detail. (And I also don't see how a finite number of photons as Veach models them could create equilibrium in the sense that irradiance is independent of time)&lt;/p&gt;&#xA;&lt;p&gt;Also, in Chapter 6, he presents a novel argument for the symmetry of the BRDF that's much more satisfying than &amp;quot;physical objects have symmetric BRDFs, now moving on...&amp;quot; that I've seen everywhere else.&lt;/p&gt;&#xA;&lt;p&gt;I also found &lt;a href=&quot;https://arxiv.org/pdf/1206.3301.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper by Lessig and Castro&lt;/a&gt; that says:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Radiative transfer describes the transport of electromagnetic energy&#xA;in macroscopicenvironments, classically when polarization effects are&#xA;neglected [37]. The theory originates in work by Bouguer [6, 7] and&#xA;Lambert [22] in the 18thcentury where light intensity and its&#xA;measurement were first studied systematically, cf. Fig. 1. In the&#xA;19thand early 20thcentury the theory was then extended to include&#xA;transport and scattering effects [26, 9, 42, 43]. To this day, however,&#xA;radiative transfer is a phenomenological theory with a mathematical&#xA;formulation that still employs the concepts introduced by Lambert in&#xA;the 18thcentury—and this despite the importance of the theory in a&#xA;multitude of fields, such as medical imaging, remote sensing,computer&#xA;graphics, atmospheric science, climate modelling, and astrophysics.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I don't know any physics so the paper is way over my head, but maybe it's the holy grail?&lt;/p&gt;&#xA;&lt;p&gt;Please flood me with references!&lt;/p&gt;&#xA;" OwnerUserId="15519" LastActivityDate="2021-01-22T20:16:31.343" Title="Mathematical Foundations of Radiative Transfer" Tags="&lt;raytracing&gt;&lt;3d&gt;" AnswerCount="2" CommentCount="15" ContentLicense="CC BY-SA 4.0" />
  <row Id="10542" PostTypeId="2" ParentId="10541" CreationDate="2021-01-06T18:03:12.803" Score="1" Body="&lt;p&gt;This is almost verbatim from Veach. Let the trajectory space be &lt;span class=&quot;math-container&quot;&gt;$\mathbb{P} = \mathbb{R} \times \mathcal{M} \times \mathcal{S}^2 \times \mathbb{R}^+$&lt;/span&gt;, corresponding respectively to: time, set of points of all scene surfaces, unit sphere (directions), wavelength. Let &lt;span class=&quot;math-container&quot;&gt;$\mathcal{P}$&lt;/span&gt; be the set of measurable subsets of &lt;span class=&quot;math-container&quot;&gt;$\mathbb{P}$&lt;/span&gt; and we have a measure &lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt;. Let &lt;span class=&quot;math-container&quot;&gt;$\rho = l \times A \times \sigma^{\perp} \times l^+$&lt;/span&gt;. Where &lt;span class=&quot;math-container&quot;&gt;$l, l^+$&lt;/span&gt; are the Lebesgue measures on &lt;span class=&quot;math-container&quot;&gt;$\mathbb{R}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\mathbb{R}^+$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt; is the Lebesgue measure on &lt;span class=&quot;math-container&quot;&gt;$\mathcal{M}$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\sigma^{\perp}$&lt;/span&gt; is the projected solid angle measure &lt;span class=&quot;math-container&quot;&gt;$(d\sigma^{\perp}(\omega) = |\cos\theta|\sin\theta\,d\theta\,d\phi$&lt;/span&gt;). Then given the radiant energy measure &lt;span class=&quot;math-container&quot;&gt;$Q(\mathcal{T}, \mathcal{D}, \Omega, \Lambda) \in [0,\infty]$&lt;/span&gt; (&lt;span class=&quot;math-container&quot;&gt;$\mathcal{T} \times \mathcal{D} \times \Omega \times \Lambda \in \mathcal{P}$&lt;/span&gt;), we can define the density &lt;span class=&quot;math-container&quot;&gt;$L_{\lambda}$&lt;/span&gt; of &lt;span class=&quot;math-container&quot;&gt;$Q$&lt;/span&gt; with respect to the measure &lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt; as:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;Q(\mathcal{T}, \mathcal{D}, \Omega, \mathcal{\Lambda}) = \int_{\Lambda}\int_{\Omega}\int_{\mathcal{D}}\int_{\mathcal{T}}L_{\lambda}(t, x, \omega,\lambda)d\rho(t,x,\omega,\lambda).&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Then the density &lt;span class=&quot;math-container&quot;&gt;$L_{\lambda}$&lt;/span&gt; is the Radon-Nikodym derivative of &lt;span class=&quot;math-container&quot;&gt;$Q$&lt;/span&gt; w.r.t. &lt;span class=&quot;math-container&quot;&gt;$\rho$&lt;/span&gt;:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;\frac{dQ}{d\rho}(t, x, \omega,\lambda) := L_{\lambda}(t, x, \omega,\lambda).&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;We can do a similar thing with respect to the appropriate measures:&lt;/p&gt;&#xA;&lt;p&gt;Radiant flux:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{gather}&#xA;\rho_1 = l \\&#xA;Q(\mathcal{T}, \mathcal{D}, \Omega, \mathcal{\Lambda}) = \int_{\mathcal{T}}\Phi(t, \mathcal{D}, \Omega, \mathcal{\Lambda})\,d\rho_1(t) \\&#xA;\frac{dQ}{d\rho_1}(t, \mathcal{D}, \Omega, \mathcal{\Lambda}) := \Phi(t, \mathcal{D}, \mathcal{\Omega}, \mathcal{\Lambda}).&#xA;\end{gather}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Irradiance:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{gather}&#xA;\rho_2 = l\times A \\&#xA;Q(\mathcal{T}, \mathcal{D}, \Omega, \mathcal{\Lambda}) = \int_{\mathcal{D}}\int_{\mathcal{T}}E(t, x, \Omega, \mathcal{\Lambda})\,d\rho_2(t,x) \\&#xA;\frac{dQ}{d\rho_2}(t, x, \Omega, \mathcal{\Lambda}) := E(t, x, \Omega, \mathcal{\Lambda}).&#xA;\end{gather}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Intensity:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{gather}&#xA;\rho_3 = l\times \sigma \\&#xA;Q(\mathcal{T}, \mathcal{D}, \Omega, \mathcal{\Lambda}) = \int_{\Omega}\int_{\mathcal{T}}I(t, \mathcal{D}, \omega, \mathcal{\Lambda})\,d\rho_3(t,\omega) \\&#xA;\frac{dQ}{d\rho_3}(t, \mathcal{D}, \omega, \mathcal{\Lambda}) := I(t, \mathcal{D}, \omega, \mathcal{\Lambda}).&#xA;\end{gather}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Radiance:&#xA;&lt;span class=&quot;math-container&quot;&gt;\begin{gather}&#xA;\rho_4 = l\times A \times \sigma^{\perp} \\&#xA;Q(\mathcal{T}, \mathcal{D}, \Omega, \mathcal{\Lambda}) = \int_{\Omega}\int_{\mathcal{D}}\int_{\mathcal{T}}L(t, x, \omega, \mathcal{\Lambda})\,d\rho_4(t,x,\omega) \\&#xA;\frac{dQ}{d\rho_4}(t, x, \omega, \mathcal{\Lambda}) := L(t, x, \omega, \mathcal{\Lambda}).&#xA;\end{gather}&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="10096" LastEditorUserId="10096" LastEditDate="2021-01-06T18:39:54.513" LastActivityDate="2021-01-06T18:39:54.513" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10543" PostTypeId="2" ParentId="10495" CreationDate="2021-01-06T20:15:52.023" Score="1" Body="&lt;p&gt;Assuming that alpha works properly in the rest of the code it can be solved on shader level:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;out vec4 color;&#xA;in vec2 uv;&#xA;uniform sampler2D tex;&#xA;&#xA;void main() {&#xA;    color = texture(tex, uv);&#xA;    color.a = 0.0;&#xA;    if (all(greaterThan(uv, vec2(0.0))) &amp;amp;&amp;amp; all(lessThan(uv, vec2(1.0)))) {&#xA;        color.a = 1.0;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="15541" LastEditorUserId="15541" LastEditDate="2021-01-07T09:00:42.217" LastActivityDate="2021-01-07T09:00:42.217" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10544" PostTypeId="2" ParentId="10537" CreationDate="2021-01-07T04:54:02.530" Score="0" Body="&lt;p&gt;I'll try my best to give an overview of the subject, and english is not my first language so feel free to ask more detailed information in comments etc.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Here are some terms, light is an electro magnetic radiation. When the power of this radiation falls between a certain wave length, it becomes visible for human beings. &lt;code&gt;S&lt;/code&gt; is the function that takes wave length value as input and gives a power value as output and is called a s(pectral) p(ower) d(istribution).&lt;/p&gt;&#xA;&lt;p&gt;Color on the other hand means different things to different people. We can define color based on our perception of it, or based on the measured spectral power distribution, based on the average physical capacity of human eye etc.&lt;/p&gt;&#xA;&lt;p&gt;The thing is spectral distributions change over time constantly, but the color does not change at the same speed. This means that variations in the spectral distribution does not map to color one to one, which shows that there must be a transformation happening between what we perceive as color and what we measure as spectral distribution.&lt;/p&gt;&#xA;&lt;p&gt;Now the needs for an accurate and standardised representation of color was quite important for daily life (think of colors around road signs, lamps, etc), the CIE defined its trichomatic system for this purpose. The main idea behind the trichromatic system was that given a carefully chosen three reference spectral distribution, we can represent all of the perceivable colors by mixing these three spds.&lt;/p&gt;&#xA;&lt;p&gt;Notice that I did two things over there. I passed from mixing spds, which should produce an spd at the end, to color values which are generally represented with trichromatic system, and I added perceived. The last one is to signal that this is an experimental procedure, that is people did a lot of experiments to come up to this idea of mixing reference spds.&lt;/p&gt;&#xA;&lt;p&gt;How do we arrive from mixing spds which should produce an spd to a color value in rgb ? Simple by summing all the power values of the spd resulting from the mix.&#xA;The mix is &lt;span class=&quot;math-container&quot;&gt;$R(\lambda)S(\lambda)$&lt;/span&gt; part where &lt;code&gt;R&lt;/code&gt; is the reference spd and &lt;code&gt;S&lt;/code&gt; is any given spd. &lt;span class=&quot;math-container&quot;&gt;$\int$&lt;/span&gt; indicates that we are summing the resulting multiplication.&#xA;&lt;span class=&quot;math-container&quot;&gt;$\lambda$&lt;/span&gt; is the wave length.&lt;/p&gt;&#xA;&lt;p&gt;A great reference on the subject is McCluney 1994, Introduction to Radiometry, chapter 11. Read through 11.2 and then 11.4, that should clarify anything and everything with respect to spds and their transformation to trichromatic values&lt;/p&gt;&#xA;" OwnerUserId="13456" LastActivityDate="2021-01-07T04:54:02.530" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10545" PostTypeId="2" ParentId="10341" CreationDate="2021-01-07T06:28:59.810" Score="0" Body="&lt;p&gt;I vaguely understand your question, so this response should be taken more of a long comment rather than an answer.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;If I have an output device, for which I have a known spectrum data for each of it's primaries, I should be able to calculate the CIEXYZ of its primaries using using the integral equations together with the CIE color matching functions. I can then calculate its respective CIExyY values, which for output device are always inside the boundary if the xyY spectral locus - the chromaticity diagram.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This is correct in general but note that reference CIE spectral power distribtions are defined for a standard observer.&lt;/p&gt;&#xA;&lt;p&gt;The term input primaries is a little vague, are you refering to the spd of the light source inside the input device or the combined result produced by the object's spectral reflectance factor (also an spd) multiplied by the spd of the light source of the input device ?&#xA;If you know the spectral reflectance factor of the object and the color matching function and the resulting trichromatic value, you should be able to express the spd of the light source as a vector equation something like:&#xA;&lt;span class=&quot;math-container&quot;&gt;$x_1 \begin{matrix}a_1 \\ a_2 \\ \vdots \\ a_{\lambda}\end{matrix}+x_2 \begin{matrix}a_1 \\ a_2 \\ \vdots \\ a_{\lambda}\end{matrix}+...+x_{\lambda} \begin{matrix}a_1 \\ a_2 \\ \vdots \\ a_{\lambda}\end{matrix} = \begin{matrix}b_1 \\ b_2 \\ \vdots \\ b_{\lambda}\end{matrix}$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; is from your light source spd and the others are obtained from the remaining (you can for example distribute trichromatic value uniformly to &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; vector, and fill &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt;'s with zeros for non corresponding wave lengths and use the multiplied value for the corresponding wave length), but this is more or less an educated guess rather than a tested solution.&#xA;Notice that the expression is a linear system which might help you finding a solution.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-09T06:43:01.463" LastActivityDate="2021-01-09T06:43:01.463" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10546" PostTypeId="2" ParentId="5547" CreationDate="2021-01-07T06:47:41.070" Score="0" Body="&lt;p&gt;I know this is an old question. I did write a spectrum-&amp;gt;rgb converter, however all of its relevant parts for this question come from pbr-book source &lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/master/src/core/spectrum.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;code&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Specifically though, the answer is no. Constant index of refraction (which is actually a wave length dependent number, so taking it as a constant is more of an approximation really) does not produce a grayscale color value. Since the final spectral distribution of your object, aka its color, is determined by the spectral distribution of the light source and the spectral reflectance factor of the surface. If your surface is transmissive, there should also be a spectral transmittance factor. Though IOR is constant the value of from the factor and the light source should produce enough change to create a perceived color difference.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-07T07:03:40.393" LastActivityDate="2021-01-07T07:03:40.393" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10547" PostTypeId="1" AcceptedAnswerId="10548" CreationDate="2021-01-07T18:09:05.117" Score="2" ViewCount="67" Body="&lt;h1&gt;The Context&lt;/h1&gt;&#xA;&lt;p&gt;I am exploring the idea of making a DIY spectrometer(and colorimeter) for testing various material samples for interior visualization. It's sort of a hobby project for my curiosity and pleasure that might end up useful for my actual work with CG.&lt;/p&gt;&#xA;&lt;h1&gt;The Question&lt;/h1&gt;&#xA;&lt;p&gt;I am struggling to find a trustworthy information source for light wavelengths sRGB color space primaries are supposed to be. They are supposed to be the same as in REC.709 as far as I understand. &lt;strong&gt;Are the actual wavelengths of sRGB RGB primaries defined and if so what are they in nanometers?&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="9894" LastActivityDate="2021-01-08T22:16:00.737" Title="What wavelengths(dominant) the primary RGB colors are supposed to be in sRGB color space in nanometers?" Tags="&lt;color-science&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10548" PostTypeId="2" ParentId="10547" CreationDate="2021-01-08T00:17:45.667" Score="1" Body="&lt;p&gt;Trichromatic color system is based on using 3 carefully selected reference spectral power distributions(SPD) as you imagine. CIE uses its own reference SPDs, but there are others who prefer using other SPDs as reference. So the answer to the question&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Are the actual wavelengths of sRGB RGB primaries defined and if so what are they in nanometers?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;differs, or might differ, with respect to institutions. As for trustworthy resources:&lt;/p&gt;&#xA;&lt;p&gt;Scott Burns had kindly provided some reference SPDs in his &lt;a href=&quot;http://scottburns.us/fast-rgb-to-spectrum-conversion-for-reflectances/&quot; rel=&quot;nofollow noreferrer&quot;&gt;website&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For illuminants and observers etc. you can check the &lt;a href=&quot;https://www.rit.edu/cos/colorscience/rc_useful_data.php&quot; rel=&quot;nofollow noreferrer&quot;&gt;website&lt;/a&gt; of Munsell Color Science Lab.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="9894" LastEditDate="2021-01-08T22:16:00.737" LastActivityDate="2021-01-08T22:16:00.737" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10549" PostTypeId="2" ParentId="10547" CreationDate="2021-01-08T02:34:06.770" Score="3" Body="&lt;p&gt;The primaries of sRGB are not pure wavelengths, they are color mixtures. Their true definition is in terms of CIE chromaticity coordinates. That said, for sRGB, the red primary is close-ish to 610nm, green is very roughly 555nm, and blue is close-ish to 465nm.&lt;/p&gt;&#xA;&lt;p&gt;The Rec. 2020 RGB space, by the way, is actually defined using pure wavelengths for the primaries: R=630nm, G=532nm, and B=467nm.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GaIIs.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GaIIs.png&quot; alt=&quot;Various RGB gamuts plotted in CIE chromaticity coordinates&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-01-08T02:34:06.770" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10550" PostTypeId="2" ParentId="10365" CreationDate="2021-01-08T05:50:20.167" Score="0" Body="&lt;p&gt;I think you may be overcomplicating things with your idea of using the stencil. In 2D graphics layers, we usually do not need to use the depth buffer to resolve depth order between 2D elements (their depth order is determined by draw order instead). Therefore, we can reserve the nearest depth value for all the foreground elements, and the farthest depth value for all background elements.&lt;/p&gt;&#xA;&lt;p&gt;This would work as follows, assuming depth 0.0 is the far plane and depth 1.0 is the near plane.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Render opaque foreground elements in front-to-back order, using depth test &lt;code&gt;VK_COMPARE_OP_GREATER&lt;/code&gt;, and arranging in the vertex shader for all elements to be placed at depth 1.0.&lt;/li&gt;&#xA;&lt;li&gt;Render opaque scene objects roughly front-to-back.&lt;/li&gt;&#xA;&lt;li&gt;Render opaque background elements in front-to-back order, placing them at depth 0.0.&lt;/li&gt;&#xA;&lt;li&gt;Render transparent background elements back-to-front, now using depth test &lt;code&gt;VK_COMPARE_OP_GREATER_OR_EQUAL&lt;/code&gt;, disabling depth writes, and placing them at depth 0.0.&lt;/li&gt;&#xA;&lt;li&gt;Render transparent scene objects back-to-front.&lt;/li&gt;&#xA;&lt;li&gt;Render transparent foreground elements back-to-front, placing them at depth 1.0.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The switch from &lt;code&gt;GREATER&lt;/code&gt; to &lt;code&gt;GREATER_OR_EQUAL&lt;/code&gt; is important here. Since the opaque elements are going front-to-back, you want to exclude the &amp;quot;equal&amp;quot; case, since you want later elements to be occluded by earlier elements. Then, when coming back-to-front for the transparents, you want to include the &amp;quot;equal&amp;quot; so that later elements will correctly render on top of earlier ones in the foreground/background layers.&lt;/p&gt;&#xA;&lt;p&gt;Edit: Now that I'm thinking about this more, this may not work since transparent elements in foreground/background won't be able to be occluded by opaque elements in the same layer. This could be addressed by pre-clipping the transparent element geometry, or if this is important to support on the GPU, it could be addressed by rendering opaque elements depth-only (no fragment shader) in the first passes and then rendering all elements, both opaque and transparent, back-to-front in the later passes.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2021-01-08T06:18:09.540" LastActivityDate="2021-01-08T06:18:09.540" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10551" PostTypeId="1" CreationDate="2021-01-08T11:52:18.317" Score="1" ViewCount="75" Body="&lt;p&gt;I want to know how to take the derivative of a Bézier curve. I visited this website &lt;a href=&quot;https://pages.mtu.edu/%7Eshene/COURSES/cs3621/NOTES/spline/Bezier/bezier-der.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/Bezier/bezier-der.html&lt;/a&gt;, but I am unable to figure out how they did it. Please help!&lt;/p&gt;&#xA;" OwnerUserId="15415" LastEditorUserId="13095" LastEditDate="2021-02-04T11:04:36.067" LastActivityDate="2021-02-04T11:04:36.067" Title="How to take the derivative of a Bézier curve?" Tags="&lt;curve&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10552" PostTypeId="2" ParentId="10551" CreationDate="2021-01-08T19:11:34.137" Score="3" Body="&lt;p&gt;A simple example of taking a the derivative of a B'ezier curve can be shown using a cubic curve.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$C_3(u) = \sum_{i=0}^3 B_{3,i}(u) P_i,$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$u \in [0,1]$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$B_{n,i} = {n \choose i} u^i (1-u)^{n-i}$&lt;/span&gt; is the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;-th Bernstein polynomial of degree &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$P_i$&lt;/span&gt; are the control points.&lt;/p&gt;&#xA;&lt;p&gt;written out it is:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$C_3(u) = (1-u)^3 P_0 + 3(1-u)^2 u P_1 + 3 (1-u)u^2 P_2 + u^3 P_3$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;we can differentiate this with respect to u&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial}{\partial u} C_3(u) = -3(1-u)^2 P_0 - 6(1-u) u P_1 + 3(1-u)^2 P_1 - 3 u^2 P_2 + 6 (1-u)u P_2 + 3u^2 P_3. $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now we can rearrange the terms&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial}{\partial u} C_3(u) =  3 \left((1-u)^2 (P_1-P_0) + 2(1-u) u (P_2 - P_1)  +  u^2 (P_3 - P_2) \right), $$&lt;/span&gt; or&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial}{\partial u} C_3(u) = 3 (\sum_{i=0}^2 B_{2,i}(u) (P_{i+1} - P_i))$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;We obtain a quadratic B'ezier curve where the control points are the vectors between the initial control points, scaled by a factor &lt;span class=&quot;math-container&quot;&gt;$3$&lt;/span&gt;. Therefore the derivative of a Bezier curve of degree &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is a B'ezier curve of degree &lt;span class=&quot;math-container&quot;&gt;$n-1$&lt;/span&gt;, where the control points are difference between initial control points scaled by &lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;so:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$\frac{\partial}{\partial u} \sum_{i=0}^n B_{n,i}(u) P_i = n (\sum_{i=0}^2 B_{n-1,i}(u) (P_{i+1} - P_i))$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2021-01-11T18:54:44.863" LastActivityDate="2021-01-11T18:54:44.863" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10553" PostTypeId="1" CreationDate="2021-01-08T21:47:41.513" Score="1" ViewCount="33" Body="&lt;p&gt;My first question in this community.&lt;/p&gt;&#xA;&lt;p&gt;I have following code.The code is shortened for clarity, error checks skipped:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int creat_ssbo_buf(uint32_t *ssbo, size_t size, size_t unit_size){&#xA;  glGenBuffers(1, ssbo);&#xA;  glBindBuffer(GL_SHADER_STORAGE_BUFFER, *ssbo);&#xA;  glBufferData(GL_SHADER_STORAGE_BUFFER, &#xA;               size * unit_size, &#xA;               NULL, &#xA;               GL_DYNAMIC_READ);&#xA;  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, *ssbo);&#xA;  glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);&#xA;  return 0;&#xA;}&#xA;&#xA;int read_ssbo(uint32_t  ssbo,&#xA;              void     *pbuf,&#xA;              size_t    size,&#xA;              intptr_t  off)&#xA;{&#xA; glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);&#xA; glGetBufferSubData(GL_SHADER_STORAGE_BUFFER,&#xA;                    off, &#xA;                    size, &#xA;                    pbuf);&#xA; glBindBuffer( GL_SHADER_STORAGE_BUFFER, 0 );&#xA; return 0;&#xA;}&#xA;&#xA;int compute(...){ /* runs the GLSL code */&#xA; ...&#xA; glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);&#xA; return 0;&#xA;}&#xA;&#xA;int main(){&#xA; ...&#xA; size_t buf_size = w * h;     &#xA; uint32_t *pbuf = /* some raster image with the size of above */;&#xA; uint32_t  ssbo;&#xA;&#xA; creat_ssbo_buf(&amp;amp;ssbo, buf_size, sizeof(uint32_t));&#xA; compute(...);&#xA; read_ssbo(ssbo, pbuf, buf_size, 0);&#xA; &#xA; printf(&amp;quot; 0 : %u\n&amp;quot;, pbuf[0]);&#xA; printf(&amp;quot; 1 : %u\n&amp;quot;, pbuf[1]);&#xA; printf(&amp;quot; 2 : %u\n&amp;quot;, pbuf[2]);&#xA; printf(&amp;quot; 3 : %u\n&amp;quot;, pbuf[3]);&#xA; printf(&amp;quot; 4 : %u\n&amp;quot;, pbuf[4]);&#xA;&#xA; return 0;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;With the GLSL code as below.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout(std430, binding = 0) writeonly buffer layout0&#xA;{&#xA; uint data[];&#xA;};&#xA;&#xA;void main(){&#xA; uvec2 pos  = uvec2(gl_GlobalInvocationID.xy);&#xA;&#xA; if(pos == uvec2(0,0)){&#xA;  data[0] = pos.x;&#xA;  data[1] = pos.y;&#xA;  data[2] = 1;&#xA;  data[3] = 1;&#xA;  data[4] = 1;&#xA; }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now that outputs &lt;code&gt;0,0,1,1,1&lt;/code&gt; as expected. What I want is to read from buffer with some offset. Below is a &lt;code&gt;C&lt;/code&gt; and &lt;code&gt;GLSL&lt;/code&gt; code with changes:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;/* GLSL */&#xA;layout(std430, binding = 0) writeonly buffer layout0&#xA;{&#xA; uint pad[1]; /* add some padding */&#xA; uint data[];&#xA;};&#xA;&#xA;/* C */&#xA;...&#xA;size_t buf_size = w * h + 1;&#xA;...&#xA;read_ssbo(ssbo, pbuf, buf_size, sizeof(uint32_t)); /* note the offset */&#xA;...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And with the offset added, I get an error: &lt;code&gt;invalid value&lt;/code&gt;. The error fires up after &lt;code&gt;glGetBufferSubData&lt;/code&gt; call. What am I doing wrong here?&lt;/p&gt;&#xA;&lt;p&gt;P.S Also, if offset is left as &lt;code&gt;zero&lt;/code&gt; and the indices of &lt;code&gt;pbuf&lt;/code&gt; in the &lt;code&gt;printf&lt;/code&gt;'s are changed to one index greater, the output is correct.&lt;/p&gt;&#xA;&lt;p&gt;Ask away what code I should add to make things clearer.&lt;/p&gt;&#xA;" OwnerUserId="15556" LastActivityDate="2021-01-08T21:47:41.513" Title="OpenGL: &quot;invalid value&quot; error after call to `glGetBufferSubData`" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10554" PostTypeId="2" ParentId="4877" CreationDate="2021-01-09T06:38:49.983" Score="2" Body="&lt;p&gt;This would be a response to why is it possible to use the Fresnel equations in an RGB path tracer. Though evaluating Fresnel equation directly requires some what more information about the environment in which the rendering takes place, it certainly is possible to use it in an RGB path tracer. Here is why:&lt;/p&gt;&#xA;&lt;p&gt;TLDR: see last two paragraphs.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;The goal of Fresnel equations is to describe the relationship between the incident, reflected and transmitted planar light waves. In its most general form, it can describe this relationship even at the boundary of an interface (think of them as the zone of contact between one object and air or water).&lt;/p&gt;&#xA;&lt;p&gt;Notice that we are considering lightwaves as plane waves which is an approximation.&#xA;Now let's define the incident light as the uniform plane sinusoidal electromagnetic wave whose electric field is defined as&#xA;&lt;span class=&quot;math-container&quot;&gt;$ \vec{E_i} = \vec{E_{0i}} e^{i(\vec{k} \cdot \vec{r} - \omega_i t)} $&lt;/span&gt; since &lt;span class=&quot;math-container&quot;&gt;$e^{i\theta} = \cos(\theta) + i\sin(\theta)$&lt;/span&gt; and since we are dealing with measurable quantities we can let go of the complex part and simply write the incident light as &lt;span class=&quot;math-container&quot;&gt;$ \vec{E_i} = \vec{E_{0i}} \cos(\vec{k} \cdot \vec{r} - \omega_i t)$&lt;/span&gt;. &lt;span class=&quot;math-container&quot;&gt;$\vec{E_i}$&lt;/span&gt; is an electric field. Mathematically it is a vector field. Notice that once we get rid of the imaginary part the whole equation is just a cosine wave now with &lt;span class=&quot;math-container&quot;&gt;$\vec{E_{0i}}$&lt;/span&gt; as the amplitude. &lt;span class=&quot;math-container&quot;&gt;$\vec{k} \cdot \vec{r}$&lt;/span&gt; is the phase and &lt;span class=&quot;math-container&quot;&gt;$\omega_i t$&lt;/span&gt; is the frequency. For surfaces with constant phase the &lt;span class=&quot;math-container&quot;&gt;$\vec{k} \cdot \vec{r}$&lt;/span&gt; would be constant where &lt;span class=&quot;math-container&quot;&gt;$\vec{r}$&lt;/span&gt; would designate the point/position in space and &lt;span class=&quot;math-container&quot;&gt;$\vec{k}$&lt;/span&gt; the direction of the propagation of the wave.&lt;/p&gt;&#xA;&lt;p&gt;We are interested in the relationship between &lt;span class=&quot;math-container&quot;&gt;$\vec{E_i}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\vec{E_t}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\vec{E_r}$&lt;/span&gt;. With no knowledge about direction, frequency, phase, etc we can describe the reflected wave as &lt;span class=&quot;math-container&quot;&gt;$\vec{E_r} = \vec{E_0r} \cos(\vec{k_r} \cdot \vec{r} - \omega_r t + \epsilon_r)$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\epsilon_r$&lt;/span&gt; is the phase constant with respect to &lt;span class=&quot;math-container&quot;&gt;$\vec{E_i}$&lt;/span&gt;. The transimited wave is defined the same way with &lt;span class=&quot;math-container&quot;&gt;$\vec{k_t}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\omega_t$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\epsilon_t$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$E_{0t}$&lt;/span&gt;. The &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt; is introduced because we have not specified the origin of the &lt;span class=&quot;math-container&quot;&gt;$\vec{E_i}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Well, after a lot of math which you can read from pages 122 - 124, we learn that they, &lt;span class=&quot;math-container&quot;&gt;$\epsilon$&lt;/span&gt;s, don't really matter and we can consider them as 0 throughout the discussion and that frequencies, &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt; of all three of them are equal (unless there is a doppler effect) and that phases of all three of them are related.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;The relationship that is described by Fresnel equations is the amplitude of waves.&#xA;Here are the full Fresnel equations from E. Hecht 2017, Optics, p. 124-125:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(\frac{E_{0r}}{E_{0i}})_{\perp} = \frac{\frac{n_i}{\mu_i}\cos(\theta_i) - \frac{n_t}{\mu_t}\cos(\theta_t)}{\frac{n_i}{\mu_i}\cos(\theta_i) + \frac{n_t}{\mu_t}\cos(\theta_t)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(\frac{E_{0t}}{E_{0i}})_{\perp} = \frac{2\frac{n_i}{\mu_i}\cos(\theta_i)}{\frac{n_i}{\mu_i}\cos(\theta_i) + \frac{n_t}{\mu_t}\cos(\theta_t)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(\frac{E_{0r}}{E_{0i}})_{||} =\frac{\frac{n_t}{\mu_t}\cos(\theta_i) - \frac{n_i}{\mu_i}\cos(\theta_t)}{\frac{n_i}{\mu_i}\cos(\theta_t) + \frac{n_t}{\mu_t}\cos(\theta_i)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$(\frac{E_{0t}}{E_{0i}})_{||} = \frac{2\frac{n_i}{\mu_i}\cos(\theta_i)}{\frac{n_i}{\mu_i}\cos(\theta_t) + \frac{n_t}{\mu_t}\cos(\theta_i)}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;These are completely general statements, that is it applies to linear, isotropic, homogenous, even magnetic media. Using certain assumptions you can eliminate some of the terms. For example if you consider &lt;span class=&quot;math-container&quot;&gt;$\mu_t \approx \mu_i$&lt;/span&gt; you can simply simply ignore them which would give you the common form of the equations, for example those that are used by PBRT.&lt;/p&gt;&#xA;&lt;p&gt;Here are the terms of the equation:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\mu$&lt;/span&gt; is the permeability: &lt;span class=&quot;math-container&quot;&gt;$\mu_i$&lt;/span&gt; accounts for the magnetic effect of the incident media, &lt;span class=&quot;math-container&quot;&gt;$\mu_t$&lt;/span&gt; accounts for the transmitted media&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$n$&lt;/span&gt; is the index of refraction: &lt;span class=&quot;math-container&quot;&gt;$n_i$&lt;/span&gt; for incident media, &lt;span class=&quot;math-container&quot;&gt;$n_t$&lt;/span&gt; for transmitted media. It is related to k in discussion above.&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; the angle is defined under the following constraints:&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\vec{E_i}$&lt;/span&gt; is perpendicular to the plane of incidence.&lt;/li&gt;&#xA;&lt;li&gt;&lt;span class=&quot;math-container&quot;&gt;$\vec{B_i}$&lt;/span&gt;, magnetic field, is parallel to the plane of incidence.&lt;/li&gt;&#xA;&lt;li&gt;With these constraints it can be proven that &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt;s of all planes are coplanar, that is they are all defined on the plane of incidence which is perpendicular to the surface, and that &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; is angle between the normal of the surface and the coplanar direction vectors.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3B455.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3B455.png&quot; alt=&quot;Relationship between plane of incidence and other fields&quot; /&gt;&lt;/a&gt;(image from, Hecht, Eugene. 2017. Optics. 5 ed/fifth edition, Global edition. Pearson Global Edition. Boston Columbus Indianapolis: Pearson, p. 123)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Now all of the terms and their are related concepts are given, yet we have not defined anywhere a term that relates directly to wavelength. Notice that we CAN include the wavelength to the frequency term of the cosine wave but since frequencies of all waves (incident, transmitted, reflected) are equal, we abstract it away from the relationship that we are trying to describe. That is why we can side step the whole spectral distributions machinary and still have visually plausable results.&lt;/p&gt;&#xA;&lt;p&gt;Here are some approximations that can be done.&#xA;You can approximate the &lt;span class=&quot;math-container&quot;&gt;$k$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; with incoming ray's direction and origin, the plane of incidence with collided surface normal, keep the frequency constant for all fields. For the majority of surfaces, the approximation &lt;span class=&quot;math-container&quot;&gt;$\mu_i \approx \mu_t$&lt;/span&gt; holds as well. For other case they need to be looked up. IOR is also a material property so one has to look that up as well. If they are defined in a wavelength dependent manner, you can make an average and use that as an approximation as well.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-11T12:22:59.623" LastActivityDate="2021-01-11T12:22:59.623" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10555" PostTypeId="2" ParentId="5323" CreationDate="2021-01-09T10:14:39.737" Score="2" Body="&lt;p&gt;I am suprised that it was only mentioned in comments but yes you can use variable length arrays through SSBO.&#xA;Here is the excerpt from &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object&quot; rel=&quot;nofollow noreferrer&quot;&gt;wiki&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;p&gt;On the host side:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;int data[SOME_SIZE];&#xA;...&#xA;GLuint ssbo;&#xA;glGenBuffers(1, &amp;amp;ssbo);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);&#xA;glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(data), data​, GLenum usage); //sizeof(data) only works for statically sized C/C++ arrays.&#xA;glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, ssbo);&#xA;glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); // unbind&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;On the glsl side:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;layout(std430, binding = 3) buffer layoutName&#xA;{&#xA;    int data_SSBO[];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Note that it has to be the last element in an SSBO:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;layout(std430, binding = 2) buffer anotherLayoutName&#xA;{&#xA;    int some_int;&#xA;    float fixed_array[42];&#xA;    float variable_array[];&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The only limitation is that you can use one variable array per SSBO. You can use multiple SSBO's in a shader though.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-10T13:05:58.397" LastActivityDate="2021-01-10T13:05:58.397" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10557" PostTypeId="1" CreationDate="2021-01-10T19:16:54.517" Score="1" ViewCount="65" Body="&lt;p&gt;I have made a demo that shades a sphere with an environment map. I wanted to compare 3 different ways of sampling the environment.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Uniform sampling.&lt;/li&gt;&#xA;&lt;li&gt;Importance sampling with the NDF as suggested in this article: &lt;a href=&quot;https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Real Shading in Unreal Engine 4 (2013)&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;Importance sampling with the VNDF (distribution of visible normals) as explained in this article: &lt;a href=&quot;http://jcgt.org/published/0007/04/01/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Sampling the GGX Distribution of Visible Normals (2018)&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;The program I wrote allows me to compare all those the sampling methods.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Lw8Fv.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Lw8Fv.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;All sampling methods seem to work and look okay to me. But they look different to each other, so I was hoping someone can help me figure out why (could be that I made some mistake or it's just how it works).&lt;/p&gt;&#xA;&lt;p&gt;First I'm going to show a comparison of how they look. After that, I will explain how I implemented each of them. Also, I have made a small &lt;a href=&quot;https://github.com/tuket/ggx_importance_sampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;project&lt;/a&gt; so you try it yourselves.&lt;/p&gt;&#xA;&lt;p&gt;The program is implemented as an iterative path-tracer, so it takes about 20 seconds for it to start to look great (specially for uniform sampling).&lt;/p&gt;&#xA;&lt;p&gt;With low roughness, it's alright, they all look the same. In the following image it's using roughness = 0.1. On the left, uniform sampling. On the right, NDF importance sampling.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/a1Wmd.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/a1Wmd.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Things start to look different with higher roughness.&lt;/p&gt;&#xA;&lt;p&gt;Roughness = 0.35&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/r513Q.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/r513Q.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Roughness = 0.6&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/adrnO.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/adrnO.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The one that differs the most is the one that samples according to the NDF (Unreal article). It looks brighter at the center and darker on the borders.&lt;/p&gt;&#xA;&lt;p&gt;Uniform sampling vs importance sampling the VNDF look more similar, but still not the same. This comparison really bothers me because, in the article, they claim that the sampling method should be exact. In order to better appreciate the difference we can flip the images.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.ibb.co/TBk7G0W/flip.webp&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.ibb.co/TBk7G0W/flip.webp&quot; alt=&quot;flip&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Implementation&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;You can find all the code in &lt;a href=&quot;https://github.com/tuket/ggx_importance_sampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;this repo&lt;/a&gt;. I put all the relevant code in the &lt;a href=&quot;https://github.com/tuket/ggx_importance_sampling/blob/master/main.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;main.cpp&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Now I'm going to explain how I implemented each method. The code is written in GLSL.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Uniform sampling&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;For generating uniform samples I have the following function. It takes a couple of pseudo-random numbers between 0 and 1 (seed), and the normal of the surface (&lt;span class=&quot;math-container&quot;&gt;$\vec{N}$&lt;/span&gt;). The samples that it generates are inside the hemisphere in the direction of &lt;span class=&quot;math-container&quot;&gt;$\vec N$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 uniformSample(vec2 seed, vec3 N)&#xA;{&#xA;    float phi = 2 * PI * seed.x;&#xA;    float r = sqrt(1 - seed.y*seed.y);&#xA;    vec3 v = vec3(r*cos(phi), seed.y, r*sin(phi));&#xA;    v = normalize(v);&#xA;    vec3 up = vec3(0, 1, 0);&#xA;    if(dot(up, N) &amp;gt; 0.99)&#xA;        up = vec3(1, 0, 0);&#xA;    vec3 X = normalize(cross(N, up));&#xA;    vec3 Z = cross(X, N);&#xA;    return X * v.x + N * v.y + Z * v.z;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;And this is how I integrate all those uniform samples applying the Cook-Torrance formula. I'm reusing the same samples for computing the diffuse term. In this case the PDF is just the constant value &lt;span class=&quot;math-container&quot;&gt;$\frac{1}{2 \pi}$&lt;/span&gt;. So we just multiply by &lt;span class=&quot;math-container&quot;&gt;$2\pi$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 diffuse = vec3(0, 0, 0);&#xA;// uniform sampling&#xA;{&#xA;    vec3 specular = vec3(0.0, 0.0, 0.0);&#xA;    for(uint iSample = 0u; iSample &amp;lt; u_numSamples; iSample++)&#xA;    {&#xA;        uint sampleId = iSample + u_numSamples * u_numFramesWithoutChanging;&#xA;        uvec3 seedUInt = pcg_uvec3_uvec3(uvec3(gl_FragCoord.x, gl_FragCoord.y, sampleId));&#xA;        vec2 seed2 = vec2(makeFloat01(seedUInt.x), makeFloat01(seedUInt.y));&#xA;        vec3 L = uniformSample(seed2, N);&#xA;        vec3 H = normalize(V + L);&#xA;        vec3 env = textureLod(u_convolutedEnv, L, 0.0).rgb;&#xA;&#xA;        float NoL = max(0.0001, dot(N, L));&#xA;        float NoH = max(0.0001, dot(N, H));&#xA;        float NoH2 = NoH * NoH;&#xA;        float rough4 = u_rough2*u_rough2;&#xA;        float q = NoH2 * (rough4 - 1.0) + 1.0;&#xA;        float D = rough4 / (PI * q*q);&#xA;        float G = ggx_G_smith(NoV, NoL, u_rough2);&#xA;        vec3 fr = F * G * D / (4 * NoV * NoL);&#xA;        diffuse += env * NoL;&#xA;        specular += env * fr * NoL;&#xA;    }&#xA;    diffuse *= 2 * k_diff * u_albedo / float(u_numSamples);&#xA;    specular *= 2 * PI / float(u_numSamples);&#xA;    o_uniform = vec4(diffuse + specular, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Importance sampling the NDF&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;In this case I've just copied the code in the article (Unreal 2013) and adapted it to the OpenGL coordinate system. Unlike in the previous implementation, the sampling function doesn't output the sampling direction but the half vector. We will have to compute the sampling direction &lt;span class=&quot;math-container&quot;&gt;$\vec{L}$&lt;/span&gt; by reflecting the view direction &lt;span class=&quot;math-container&quot;&gt;$\vec V$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 importanceSampleGgxD(vec2 seed, float rough2, vec3 N)&#xA;{&#xA;    float phi = 2.0 * PI * seed.x;&#xA;    float cosTheta = sqrt((1.0 - seed.y) / (1 + (rough2*rough2 - 1) * seed.y));&#xA;    float sinTheta = sqrt(1.0 - cosTheta*cosTheta);&#xA;    vec3 h;&#xA;    h.x = sinTheta * cos(phi);&#xA;    h.y = cosTheta;&#xA;    h.z = sinTheta * sin(phi);&#xA;    vec3 up = abs(N.y) &amp;lt; 0.999 ? vec3(0, 1, 0) : vec3(1, 0, 0);&#xA;    vec3 tangentX = normalize(cross(up, N));&#xA;    vec3 tangentZ = cross(tangentX, N);&#xA;    return h.x * tangentX + h.y * N + h.z * tangentZ;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;For the integration, since we are using importance sampling, we use a different normalization factor according to the new PDF &lt;span class=&quot;math-container&quot;&gt;$ \frac{D (\vec N \cdot \vec H)} {4 (\vec V \cdot \vec H)}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// importance sampling NDF&#xA;{&#xA;    vec3 specular = vec3(0.0, 0.0, 0.0);&#xA;    for(uint iSample = 0u; iSample &amp;lt; u_numSamples; iSample++)&#xA;    {&#xA;        uint sampleId = iSample + u_numSamples * u_numFramesWithoutChanging;&#xA;        uvec3 seedUInt = pcg_uvec3_uvec3(uvec3(gl_FragCoord.x, gl_FragCoord.y, sampleId));&#xA;        seedUInt.xy += seedUInt.x;&#xA;        vec2 seed2 = vec2(makeFloat01(seedUInt.x), makeFloat01(seedUInt.y));&#xA;        vec3 H = importanceSampleGgxD(seed2, u_rough2, N);&#xA;        vec3 L = reflect(-V, H);&#xA;        if(dot(N, L) &amp;gt; 0) {&#xA;            vec3 env = textureLod(u_convolutedEnv, L, 0.0).rgb;&#xA;            float NoL = max(0.0001, dot(N, L));&#xA;            float NoH = max(0.0001, dot(N, H));&#xA;            float G = ggx_G_smith(NoV, NoL, u_rough2);&#xA;            specular += env * F*G* dot(L, H) / (NoL * NoH);&#xA;        }&#xA;    }&#xA;    specular /= float(u_numSamples);&#xA;    o_importanceNDF = vec4(diffuse + specular, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Importance sampling the VNDF&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;This one attempts to sample considering the visibility of micro-normals, that means the geometry term &lt;span class=&quot;math-container&quot;&gt;$G$&lt;/span&gt; of the Cook-Torrance equation is also cosidered. In the article, the code they provide assumes that the surface normal is aligned with the vertical axis (Z in the paper, and Y in my code). So I had to rotate the vectors accordingly.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 importanceSampleGgxVD(vec2 seed, float rough2, vec3 N, vec3 V)&#xA;{&#xA;    mat3 orthoBasis; // build an ortho normal basis with N as the up direction&#xA;    orthoBasis[1] = N;&#xA;    orthoBasis[0] = abs(dot(N, vec3(0, 0, 1))) &amp;lt; 0.001 ?&#xA;                        cross(N, vec3(1, 0, 0)) :&#xA;                        cross(N, vec3(0, 0, 1));&#xA;    orthoBasis[0] = normalize(orthoBasis[0]);&#xA;    orthoBasis[2] = cross(orthoBasis[0], N);&#xA;&#xA;    mat3 invOrthoBasis = transpose(orthoBasis);&#xA;    V = invOrthoBasis * V;&#xA;&#xA;    // stretch view&#xA;    V = normalize(vec3(rough2*V.x, V.y, rough2*V.z));&#xA;    // orthonormal basis&#xA;    vec3 T1 = (V.y &amp;lt; 0.999) ? normalize(cross(V, vec3(0,0,1))) : vec3(1,0,0);&#xA;    vec3 T2 = cross(T1, V);&#xA;    // sample point with polar coordinates (r, phi)&#xA;    float a = 1.0 / (1.0 + V.y);&#xA;    float r = sqrt(seed.x);&#xA;    float phi = (seed.y&amp;lt;a) ? seed.y/a * PI : PI + (seed.y-a)/(1.0-a) * PI;&#xA;    float P1 = r*cos(phi);&#xA;    float P2 = r*sin(phi)*((seed.y&amp;lt;a) ? 1.0 : V.y);&#xA;    // compute normal&#xA;    vec3 h = P1*T1 + P2*T2 + sqrt(max(0.0, 1.0 - P1*P1 - P2*P2))*V;&#xA;    // unstretch&#xA;    h = normalize(vec3(rough2*h.x, max(0.0, h.y), rough2*h.z));&#xA;    return orthoBasis * h;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="6172" LastActivityDate="2021-01-10T19:16:54.517" Title="Comparing different sampling methods for GGX IBL" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;pbr&gt;&lt;ggx&gt;&lt;ibl&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10558" PostTypeId="1" CreationDate="2021-01-12T10:48:06.280" Score="0" ViewCount="17" Body="&lt;p&gt;There is any way to use GTS(GNU Triangulated Surface Library) with Half-edge or Combinatorial maps data structures  ?&#xA;I want to use GTS simplification with the above mentioned data structures&lt;/p&gt;&#xA;&lt;p&gt;I appreciate any help&lt;/p&gt;&#xA;" OwnerUserId="6517" LastActivityDate="2021-01-12T10:48:06.280" Title="how to use half-edge data structure with gts gnu" Tags="&lt;c++&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10559" PostTypeId="1" AcceptedAnswerId="10569" CreationDate="2021-01-12T22:42:08.397" Score="2" ViewCount="90" Body="&lt;p&gt;I have a Dell monitor with 60 Hz refresh rate and therefore games playing on it are not very smooth as compared to 120 hz.&#xA;But when I open videos on YouTube of the same game on the same monitor, some of those videos run extremely smoothly as if it's a 120hz display.&lt;/p&gt;&#xA;&lt;p&gt;Why is that so ?&lt;/p&gt;&#xA;" OwnerUserId="15572" LastActivityDate="2021-03-17T07:31:26.260" Title="Why do some videos look smoother and others don't on the same monitor" Tags="&lt;rendering&gt;&lt;3d&gt;&lt;gpu&gt;&lt;pixel-graphics&gt;&lt;pixels&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10560" PostTypeId="2" ParentId="10559" CreationDate="2021-01-13T06:15:10.853" Score="1" Body="&lt;p&gt;Humans don't really see  anything beyond 20-25 fps. Even less is often sufficient; animation at 12 frames a second work quite well too. So when you watch TV, the fps of your image is 25-30, and yet you don't generally accuse of them being not smooth.&lt;/p&gt;&#xA;&lt;p&gt;Why do games require more? Well, because they are fast paced. There is generally a slight benefit from going to 30 to 60. But mainly it comes down to:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Games do not generally have temporal antialiasing, aka motion blur; it's expensive.&lt;/li&gt;&#xA;&lt;li&gt;The game simulation is locked to the rendering loop so that your input reactions now have a higher rate of feedback (wetware is not digital, reflexes do react faster)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="38" LastEditorUserId="5778" LastEditDate="2021-03-17T07:31:26.260" LastActivityDate="2021-03-17T07:31:26.260" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10561" PostTypeId="1" CreationDate="2021-01-13T09:17:33.673" Score="1" ViewCount="70" Body="&lt;p&gt;Does using box or gaussian filter introduce bias to the image when reconstructing the pixel?&lt;/p&gt;&#xA;&lt;p&gt;Bias does not seem to be talked in the &lt;a href=&quot;http://www.pbr-book.org/3ed-2018/Sampling_and_Reconstruction/Image_Reconstruction.html#sec:image-reconstruction&quot; rel=&quot;nofollow noreferrer&quot;&gt;Chapter 7.8 of PBRT&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15574" LastActivityDate="2021-02-28T16:03:00.317" Title="Does film filter introduce bias in path tracing?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;sampling&gt;&lt;filtering&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10562" PostTypeId="1" AcceptedAnswerId="10563" CreationDate="2021-01-13T10:44:20.797" Score="0" ViewCount="112" Body="&lt;p&gt;Here in my book they have shown interpolation using parametric equation of line but I am unable to figure out how do they found out t=|y1-ys|/y1-y2 , t=|AD|/|AB| , t=|CE|/CB ,t=|EP|/|DE| here is the  pic &lt;a href=&quot;https://i.stack.imgur.com/njcYV.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/njcYV.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/5URZg.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="15415" LastActivityDate="2021-02-26T09:25:16.783" Title="How to do linear interpolation?" Tags="&lt;interpolation&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10563" PostTypeId="2" ParentId="10562" CreationDate="2021-01-13T13:28:23.660" Score="0" Body="&lt;p&gt;Since this is linear interpolation it boils down to solving a linear equation&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$y = a + b t$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;You can substitute the following &lt;span class=&quot;math-container&quot;&gt;$y = y_s$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$a = y_1$&lt;/span&gt;(intercept) and &lt;span class=&quot;math-container&quot;&gt;$b = y_2 - y_1$&lt;/span&gt; (slope) to get the following&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$y_s = y_1 + t(y_2 - y_1)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$y_s - y_1 = t(y_2 - y_1)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$\frac{y_s - y_1}{y_2 - y_1} = t$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The same thing happens for points where you can write&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$D = A + (B-A)t$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ (D-A) = (B-A)\cdot t$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ (D-A)^2 = ((B-A)\cdot t)^2$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \sqrt{(D-A)^2} = \sqrt{((B-A)\cdot t)^2}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \sqrt{(D-A)^2} = \sqrt{(B-A)^2 \cdot t^2}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ \sqrt{(D-A)^2} = \sqrt{(B-A)^2} \cdot\sqrt{ t^2}$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ |D-A| = |B-A| \cdot t$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ t = \frac{|D-A|}{|B-A|}$$&lt;/span&gt;&lt;/p&gt;&#xA;" OwnerUserId="7724" LastEditorUserId="7724" LastEditDate="2021-01-13T16:50:41.103" LastActivityDate="2021-01-13T16:50:41.103" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10564" PostTypeId="1" AcceptedAnswerId="10565" CreationDate="2021-01-13T16:30:26.287" Score="0" ViewCount="40" Body="&lt;p&gt;everyone!&#xA;I am currently developing a program that converts a 3D model to 2D isometric pixel art. Part of my program extracts the texture from an FBX file (as FBX files can have textures built in), and then the texture will be used when converting to vox (which is then converted to a sprite sheet). So, I have a 3D model of a bed here:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/oTDmB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/oTDmB.jpg&quot; alt=&quot;bed model&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And then I extract the texture programatically, which leaves us with a jpg:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/3MX2O.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3MX2O.jpg&quot; alt=&quot;bed texture&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;But then, when converting the 3D model to vox, I need to get the color from the specific locations on the bed where the model is being converted to voxels, to apply to each voxel. To do this, my thoughts are that I'll calculate where on this texture sheet would map to my current point on the 3D model, and get the color at that pixel.&lt;/p&gt;&#xA;&lt;p&gt;The trouble is calculating this. My question is, how do I calculate how a 2D texture sheet is mapped to a 3D model? Thanks in advance for your answers!&lt;/p&gt;&#xA;" OwnerUserId="15576" LastActivityDate="2021-01-13T21:47:04.763" Title="Calculating Material/Texture Placement from Bitmap to 3D Model" Tags="&lt;3d&gt;&lt;texture&gt;&lt;mathematics&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10565" PostTypeId="2" ParentId="10564" CreationDate="2021-01-13T21:47:04.763" Score="1" Body="&lt;p&gt;For each visible voxel side you need to iterate over all triangles and find if ray from voxel side normal intersects that particular triangle. Having intersection point you can then calculate &lt;a href=&quot;https://mathworld.wolfram.com/BarycentricCoordinates.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;barycentric&lt;/a&gt; coordinates of this point within intersected triangle. And with barycentric coordinates you can calculate UV of intersection point and therefore sample color from original texture. If you need more than one pixel per voxel side then you can cast more rays.&lt;/p&gt;&#xA;" OwnerUserId="15541" LastActivityDate="2021-01-13T21:47:04.763" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10566" PostTypeId="1" CreationDate="2021-01-14T16:40:04.530" Score="0" ViewCount="47" Body="&lt;p&gt;If I reflect a vector over a mirror, I expect it to end up on the other side of the mirror, even if there's a bit of numerical error. More precisely, if I run the GLSL code&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float dot_before = dot(v, mirror)&#xA;vec3 v_reflected = reflect(v, mirror)&#xA;float dot_after = dot(v_reflected, mirror)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;on a given &lt;code&gt;vec3 v&lt;/code&gt; and &lt;code&gt;vec3 mirror&lt;/code&gt;, I expect &lt;code&gt;dot_before&lt;/code&gt; and &lt;code&gt;dot_after&lt;/code&gt; to have opposite signs, even if &lt;code&gt;dot_after&lt;/code&gt; isn't exactly equal to &lt;code&gt;-dot_before&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;When I replicate the code above in Python, using NumPy float32 vectors, I get the behavior I expect. In GLSL, however, when the vector is very close to the mirror, &lt;code&gt;dot_before&lt;/code&gt; and &lt;code&gt;dot_after&lt;/code&gt; often come out with the same sign. (See minimal working example below.) My graphics processor is an Intel HD Graphics 520.&lt;/p&gt;&#xA;&lt;p&gt;This could happen because the second term in the reflection formula &lt;code&gt;v - 2*dot(v, mirror)*mirror&lt;/code&gt; is small enough to be rounded off—but why would that round-off affect GLSL but not NumPy at the same floating point precision?&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Questions&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Why doesn't reflection act like I expect in GLSL?&lt;/li&gt;&#xA;&lt;li&gt;Can I write a reflection function that does act like I expect in GLSL?&lt;/li&gt;&#xA;&lt;li&gt;If not, is there a good way to identify vectors which are close enough to the mirror that reflection won't put them on the other side? I can choose a threshold that works case-by-case, but it would be nice to have a general principle.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;Minimal working example&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;In Python 3, using VisPy. The blue and white columns in the output window show vectors where &lt;code&gt;dot_before&lt;/code&gt; and &lt;code&gt;dot_after&lt;/code&gt; have the same sign.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;import sys&#xA;from vispy import app, gloo&#xA;from math import cos, sin, pi&#xA;&#xA;vertex = '''&#xA;attribute vec2 position;&#xA;&#xA;void main() {&#xA;  gl_Position = vec4(position, 0., 1.);&#xA;}&#xA;'''&#xA;&#xA;fragment = '''&#xA;uniform vec2 resolution;&#xA;uniform vec3 mirror;&#xA;&#xA;const float COS45 = 0.7071067811865475;&#xA;&#xA;void main() {&#xA;  // set up vector&#xA;  vec2 u = COS45 * (2.*gl_FragCoord.xy/resolution - vec2(1.));&#xA;  float r_sq = 2.*u.x*u.x;&#xA;  vec3 v = vec3(2.*u.x, -2.*u.x, 1.-r_sq) / (1.+r_sq);&#xA;  &#xA;  // do reflection&#xA;  float dot_before = dot(mirror, v);&#xA;  vec3 v_refl = reflect(v, mirror);&#xA;  float dot_after = dot(mirror, v_refl);&#xA;  &#xA;  // show graph&#xA;  vec3 color = vec3(0.);&#xA;  if (sign(dot_before) == sign(dot_after)) {&#xA;    float level = u.y*1e-6;&#xA;    if (level &amp;lt; dot_before) {&#xA;      color.r = 1.;&#xA;    }&#xA;    if (level &amp;lt; dot_after) {&#xA;      color.g = 1.;&#xA;    }&#xA;    color.b = 1.;&#xA;  }&#xA;  gl_FragColor = vec4(color, 1.);&#xA;}&#xA;'''&#xA;&#xA;class TestCanvas(app.Canvas):&#xA;  def __init__(self, *args, **kwargs):&#xA;    app.Canvas.__init__(self, *args, **kwargs)&#xA;    self.program = gloo.Program(vertex, fragment, count = 6) # we'll always send 6 vertices&#xA;    &#xA;    # draw a rectangle that covers the canvas&#xA;    self.program['position'] = [&#xA;      (-1, -1), (-1, 1), (1, 1), # northwest triangle&#xA;      (-1, -1), (1, 1), (1, -1)  # southeast triangle&#xA;    ]&#xA;    &#xA;    # initialize mirror and signature&#xA;    self.program['mirror'] = (-sin(pi/4), -cos(pi/4), 0)&#xA;    &#xA;    # initialize settings&#xA;    self.update_resolution()&#xA;    self.title = 'Vector reflection test'&#xA;  &#xA;  def update_resolution(self):&#xA;    width, height = self.physical_size&#xA;    gloo.set_viewport(0, 0, width, height)&#xA;    self.program['resolution'] = [width, height]&#xA;  &#xA;  def on_draw(self, event):&#xA;    self.program.draw()&#xA;  &#xA;  def on_resize(self, event):&#xA;    self.update_resolution()&#xA;&#xA;if __name__ == '__main__' and sys.flags.interactive == 0:&#xA;  TestCanvas(size = (500, 500)).show()&#xA;  app.run()&#xA;&lt;span class=&quot;math-container&quot;&gt;```&lt;/span&gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13994" LastEditorUserId="13994" LastEditDate="2021-01-17T18:50:55.303" LastActivityDate="2021-01-17T18:50:55.303" Title="Numerical error in GLSL vector reflection" Tags="&lt;glsl&gt;" AnswerCount="0" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10567" PostTypeId="2" ParentId="10562" CreationDate="2021-01-14T19:31:49.517" Score="-1" Body="&lt;p&gt;I&lt;sub&gt;4&lt;/sub&gt;=I&lt;sub&gt;1&lt;/sub&gt;  ( 1-t ) + t.I&lt;sub&gt;2&lt;/sub&gt;  ; from parametric equation of line&lt;/p&gt;&#xA;&lt;p&gt;I4=I1 - I1.t + t. I2&lt;/p&gt;&#xA;&lt;p&gt;I4=I1+ t (I2-I1)&#xA;Let's take line AB apart from triangle&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/cqxtR.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&#xA;below in the equation I multiply t&lt;sup&gt;2&lt;/sup&gt; to numerator an denominator&lt;/p&gt;&#xA;" OwnerUserId="15415" LastEditorUserId="15415" LastEditDate="2021-02-26T09:25:16.783" LastActivityDate="2021-02-26T09:25:16.783" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10568" PostTypeId="1" CreationDate="2021-01-15T14:27:04.560" Score="0" ViewCount="15" Body="&lt;p&gt;I want to import an object with extension &amp;quot;.obj&amp;quot; as halfedge data structure. and simplify it using &lt;a href=&quot;http://gts.sourceforge.net/&quot; rel=&quot;nofollow noreferrer&quot;&gt;GTS&lt;/a&gt; (GNU Triangulated Surface Library. )&#xA;How to convert halfedge data structure to GTsSurface to simplify it using &lt;a href=&quot;http://gts.sourceforge.net/reference/gts-surface-simplification-and-refinement.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;gts_surface_coarsen&lt;/a&gt; method  ??&lt;/p&gt;&#xA;&lt;p&gt;any ideas or useful links?&lt;/p&gt;&#xA;" OwnerUserId="6517" LastActivityDate="2021-01-15T14:27:04.560" Title="how to convert halfedge datastructure to work with GTS" Tags="&lt;c++&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10569" PostTypeId="2" ParentId="10559" CreationDate="2021-01-15T20:39:58.737" Score="3" Body="&lt;p&gt;As you have now mentionned that your computer can actually keep up (at 150 fps no less), I suspect you have a case of temporal aliasing.&lt;/p&gt;&#xA;&lt;p&gt;The problem is that 150 is not a multiple of 60. Let's say we look at one tenth of a second. That's 15 frames generated by your computer but only 6 can be shown on your screen. The frames you will see will probably be something like:&lt;/p&gt;&#xA;&lt;p&gt;#1 - #3 - #6 - #8 - #11 - #13&lt;/p&gt;&#xA;&lt;p&gt;Notice how the increment is +2, +3, +2, +3. This will cause animation to not look smooth. There is no steady increment which will let you display 60 frames out of 150.&lt;/p&gt;&#xA;&lt;p&gt;As I wrote in the comments below, forcing the game to run at &amp;quot;only&amp;quot; 120Hz should help as the screen should show every other frame.&lt;/p&gt;&#xA;&lt;p&gt;Enabling vsync is even more reliable but it seems your game does not deal well with latency then.&lt;/p&gt;&#xA;&lt;p&gt;By the way, that's why serious gaming monitors now have adaptive refresh rates. They just show the frames when they're ready and have none of the above issues.&lt;/p&gt;&#xA;" OwnerUserId="5717" LastEditorUserId="5717" LastEditDate="2021-01-15T21:11:17.920" LastActivityDate="2021-01-15T21:11:17.920" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="10570" PostTypeId="1" AcceptedAnswerId="10572" CreationDate="2021-01-16T17:17:38.573" Score="1" ViewCount="25" Body="&lt;p&gt;Foveated rendering, is definitely one of the newest fields of real-time graphics rendering. The main goal of foveated rendering is reducing rendering cost to increase frame-rate without perception difference to the user from full-rendering. Eye-tracker is a great help here, as technology has exponentially evolved over years.&lt;/p&gt;&#xA;&lt;p&gt;When we use an eye tracker, can gradually decrease the rendering qualities in peripheral zones. The decreased graphics parameters could be, for example, the color quality. Spatial frequency decrease (e.g. text) in the peripheral does not help much in special applications as decrease such quality will increase the reading time.  Could you give me some ideas about the graphics parameters which can be decreased from the angular distance of the gaze point?&lt;/p&gt;&#xA;" OwnerUserId="7869" LastActivityDate="2021-01-18T15:27:10.897" Title="What can be reduce in peripheral circle and increase in foveated cirle?" Tags="&lt;rendering&gt;&lt;real-time&gt;&lt;volume-rendering&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10571" PostTypeId="1" AcceptedAnswerId="10573" CreationDate="2021-01-18T00:19:35.293" Score="0" ViewCount="55" Body="&lt;p&gt;In cases of Laptops, some will have two GPUs. One is built-in (e.g. Intel) and another one attachable (e.g. Nvidia).&lt;/p&gt;&#xA;&lt;p&gt;Is it better to have each of them operate different software to divide the load?&lt;/p&gt;&#xA;&lt;p&gt;or&lt;/p&gt;&#xA;&lt;p&gt;is it better to have one of them operate everything because the switching between GPUs might cause slower performance?&lt;/p&gt;&#xA;" OwnerUserId="15591" LastActivityDate="2021-01-19T10:58:54.910" Title="is utilizing multiple GPUs better than using one for all software?" Tags="&lt;gpu&gt;&lt;performance&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10572" PostTypeId="2" ParentId="10570" CreationDate="2021-01-18T15:27:10.897" Score="2" Body="&lt;p&gt;Actually it's not that new of an idea -- it goes back to at least 1996.  I strongly suggest reading Microsoft Research's &lt;a href=&quot;https://www.microsoft.com/en-us/research/publication/foveated-3d-graphics/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Foveated 3D Graphics&lt;/a&gt;.  (click 'View publication' and read the full pdf)&lt;/p&gt;&#xA;&lt;p&gt;In a nutshell, human visual acuity is different near the center of vision compared to the peripheral.  The middle of the eye is packed more tightly with cone receptors making it more sensitive to detail and color.  In contrast, humans are quite sensitive to motion in their peripheral vision.  Evolutionarily speaking, it's a good idea to maybe take a look at that tiger sneaking up on you from the side.  Your motion perception will trigger a shift in your gaze so you can make sense of exactly what's trying to eat you.&lt;/p&gt;&#xA;&lt;p&gt;The most obvious thing that's different is your ability to perceive detail (angular size).  Numerous things can be adjusted with the rendering to economize on detail.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Resolution can be reduced.&lt;/li&gt;&#xA;&lt;li&gt;Texture sizes can be reduced.&lt;/li&gt;&#xA;&lt;li&gt;Geometric (polygonal) detail can be reduced&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://jov.arvojournals.org/article.aspx?articleid=2193447#:%7E:text=Color%20perception%20changes%20across%20the,luminance%20or%20blue%E2%80%93yellow%20colors.&quot; rel=&quot;nofollow noreferrer&quot;&gt;Color perception is reduced&lt;/a&gt; in the periphery as well, therefore:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Texture maps with lower bit-depth can be used.&lt;/li&gt;&#xA;&lt;li&gt;Precision of color calculations can be reduced.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;&lt;strong&gt;CAUTION&lt;/strong&gt;: There are nuances to making effective use of all of these techniques.  You have to be especially careful not to change the silhouette of the objects because the outer visual region is actually &lt;em&gt;more&lt;/em&gt; sensitive to the motion differences that may be perceived by an edge jumping around.  It may also be tempting to turn off antialiasing, but artifacts introduced by crawling pixels are tantamount to motion and draw the eye to these artifacts.  Anti-aliasing sometimes needs to be &lt;em&gt;increased&lt;/em&gt; negating the effects of foveated rendering.  A blended blurring technique is used that allows seamless transition between regions rendered at high-resolution and low-resolution. &lt;strong&gt;It's a complex subject -- read the paper&lt;/strong&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8009" LastActivityDate="2021-01-18T15:27:10.897" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10573" PostTypeId="2" ParentId="10571" CreationDate="2021-01-18T17:00:05.250" Score="1" Body="&lt;p&gt;This is more of a long comment than an answer.&lt;/p&gt;&#xA;&lt;p&gt;As with most yes or no questions in graphics, the answer is &amp;quot;it depends on the task&amp;quot;. However, one particular task that you might find having multiple gpu's useful is debugging. For example if you are using cuda-gdb for debugging your CUDA application, it would be nice to have multiple gpu's, one for your application, the other for the display manager of your system. Note that cuda-gdb also works on a single gpu as well, but I had problems with it when I run the debugger and the display manager of the system on a single gpu (screen tends to freeze, no response from the system, etc).&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Update 19-01-2021 with respect to comment.&lt;/p&gt;&#xA;&lt;p&gt;Here is the main criteria that I would use for deciding if the use of single or multiple gpus are better for the task.&lt;/p&gt;&#xA;&lt;p&gt;GPUs simply execute one task after another, so if you send a heavy task, it will do only that during the process and you won't be able to do anything else with it.&#xA;This usually means that your system would freeze until the gpu is done with your task.&#xA;If you are going to launch the task and won't plan to do anything with the machine until it is finished, then sure, the use of multiple gpus would get it done quicker. If you plan to use the machine during the process for other stuff, then it would be more reasonable to allocate a single gpu for the task.&lt;/p&gt;&#xA;&lt;p&gt;If you are setting up some kind of rendering server where the server would do only gpu related computation, it depends on the type of request you are planning to process by the server.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-19T10:58:54.910" LastActivityDate="2021-01-19T10:58:54.910" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10574" PostTypeId="1" CreationDate="2021-01-20T17:49:28.143" Score="0" ViewCount="60" Body="&lt;p&gt;I was looking at the Raspberry Pi 4 specs and realized that running a software renderer on the pi could get some decent graphics. By using USB ports and Ethernet ports, I think I might be able to send graphics data to the pi, using it as an external graphics card.&#xA;&lt;br /&gt;&#xA;While the graphics of the external pi card would obviously not approach an RTX, would this work?&#xA;Is there a software renderer that I could run on all 4 cores of the Rpi 4?&#xA;&lt;br /&gt;&#xA;I realize that I may have to create this myself, and I would like to make a custom, real-time Vulkan driver that uses the pi's cpu to do most of the rendering. It would only use the on-board graphics card to do simple, repetitive tasks that it can do efficiently.&#xA;&lt;br /&gt;&#xA;By installing a special driver, I could output graphics data from a computer into the pi via USB or Ethernet; the pi would then solve it and output it through its own display ports.&#xA;&lt;br /&gt;&#xA;Does anyone have info that could help me?&#xA;I'm a graphics noob and the only help I can get right now is from my dad, but he is quite busy.&lt;/p&gt;&#xA;" OwnerUserId="15604" LastEditorUserId="2654" LastEditDate="2021-01-21T05:00:35.670" LastActivityDate="2021-01-21T23:02:17.287" Title="Using Software Rendering to make an External GPU" Tags="&lt;rendering&gt;&lt;gpu&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10575" PostTypeId="2" ParentId="10574" CreationDate="2021-01-21T08:57:52.107" Score="1" Body="&lt;p&gt;Theoraticaly this can work, but I am not sure if it would be very efficient. Modern GPU's are tailored for doing low level graphics operations and the drivers that manage them are also tailored for efficiently overseeing these operations to render your scene.&lt;/p&gt;&#xA;&lt;p&gt;Now you can ask all the hardware questions related to using Raspberry Pi, how to access its cpu etc to &lt;a href=&quot;https://raspberrypi.stackexchange.com/&quot;&gt;Raspberry Pi SO&lt;/a&gt;.&#xA;As per software side, I think P. Shirley's books on&#xA;&lt;a href=&quot;https://raytracing.github.io/&quot; rel=&quot;nofollow noreferrer&quot;&gt;ray tracing&lt;/a&gt; should get you started on rendering on cpu's rather than gpus. Using multiple threads is extensively discussed in the &lt;a href=&quot;https://github.com/RayTracing/raytracing.github.io/issues/148&quot; rel=&quot;nofollow noreferrer&quot;&gt;following issue&lt;/a&gt; of the source code of the book. So once you had written your single threaded cpu ray tracer, you can adapt it easily to execute in multiple threads.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Update 21-01-2021&lt;/p&gt;&#xA;&lt;p&gt;I noticed that there is already a driver for Raspberry Pi 4 provided by &lt;a href=&quot;https://docs.mesa3d.org/drivers/v3d.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;mesa&lt;/a&gt;, which gives you access to OpenGLES 3 functionality. I think it is a decent trade off, I was even surprised to see that there is actually a graphics driver for Pi.&lt;/p&gt;&#xA;&lt;p&gt;Unless you insist on ray tracing your scenes, I would suggest to use that for your experiments.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-21T23:02:17.287" LastActivityDate="2021-01-21T23:02:17.287" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10576" PostTypeId="1" CreationDate="2021-01-21T15:52:40.220" Score="0" ViewCount="77" Body="&lt;p&gt;I am following &lt;a href=&quot;https://vulkan-tutorial.com/Introduction&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://vulkan-tutorial.com/Introduction&lt;/a&gt; to get myself familiar with the Vulkan API. I have gotten to the point where my application is able to draw a triangle. But for some reason the clear color is way brighter than the RGB value that i specified in my code. I am setting the color like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    VkClearValue clearColor = {0.2f, 0.2f, 0.2f, 1.0f};&#xA;&#xA;    VkRenderPassBeginInfo renderPassBeginInfo = {&#xA;        .sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,&#xA;        .renderPass = renderPass,&#xA;        .framebuffer = swapChainFramebuffers[i],&#xA;        .renderArea = {&#xA;            .offset = {&#xA;                .x = 0,&#xA;                .y = 0&#xA;            },&#xA;            .extent = swapChainExtent&#xA;        },&#xA;        .clearValueCount = 1,&#xA;        .pClearValues = &amp;amp;clearColor&#xA;    };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;An RGB value of [0.2, 0.2, 0.2, 1.0] or [50, 50, 50, 255] should be a very dark gray, almost black. Instead i am getting is this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/IWHW1.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/IWHW1.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This looks more like an RGB value of [150,150,150,255]. To get a color close to what i want i have to instead go with something like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;VkClearValue clearColor = {0.02f, 0.02f, 0.02f, 1.0f};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So it almost seems like everything is shifted by a decimal. Any idea what might cause this issue?&lt;/p&gt;&#xA;" OwnerUserId="15608" LastEditorUserId="15608" LastEditDate="2021-01-21T15:57:50.327" LastActivityDate="2021-01-22T02:27:42.860" Title="Vulkan clear color is wrong" Tags="&lt;c++&gt;&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10577" PostTypeId="1" AcceptedAnswerId="10578" CreationDate="2021-01-21T17:54:14.177" Score="0" ViewCount="46" Body="&lt;p&gt;a 3D model is a collection of points, and basically a 3D software has algorithm to find out how those points connect to make surfaces.&lt;/p&gt;&#xA;&lt;p&gt;I'm searching for what those algorithms are called, that can use a set of points and properly fill in the dots to create the accurate 3D model from the set of points to create the 3D object intended.&lt;/p&gt;&#xA;&lt;p&gt;Please mention the name of the algorithm if it's a general approach, if it's file specific then please assume for &lt;code&gt;.obj&lt;/code&gt; files. Any links or references would also be highly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="11832" LastActivityDate="2021-01-22T04:31:17.797" Title="algorithm that openGL uses to construct 3D surface from vertices" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10578" PostTypeId="2" ParentId="10577" CreationDate="2021-01-21T19:33:03.237" Score="2" Body="&lt;p&gt;Most 3D models are not just collections of points; they’re also the information about how those points are connected. Those are &lt;a href=&quot;https://en.wikipedia.org/wiki/Polygon_mesh&quot; rel=&quot;nofollow noreferrer&quot;&gt;polygon meshes&lt;/a&gt;. What you’re describing sounds like a &lt;a href=&quot;https://en.wikipedia.org/wiki/Point_cloud&quot; rel=&quot;nofollow noreferrer&quot;&gt;point cloud&lt;/a&gt;, which is what processes like 3D scanning often produce. That article has a “conversion to 3D surfaces” section; if you search for “point cloud meshing” elsewhere you should also find a bunch of information about ways to do this. One new-ish technique worth looking at, which is more robust than a lot of older approaches to the problem: &lt;a href=&quot;https://www.dgp.toronto.edu/projects/fast-winding-numbers/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Fast Winding Numbers for Soups and Clouds&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For OBJ files in particular, polygons are specified with a list of vertices using the &lt;code&gt;f&lt;/code&gt; command as described &lt;a href=&quot;https://en.wikipedia.org/wiki/Wavefront_.obj_file#Face_elements&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2021-01-22T04:31:17.797" LastActivityDate="2021-01-22T04:31:17.797" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10579" PostTypeId="1" CreationDate="2021-01-21T22:59:43.630" Score="1" ViewCount="43" Body="&lt;p&gt;I would like to rotate an bitmap image using math. I have two issues with &lt;a href=&quot;https://codepen.io/blastframe/pen/jOMRNKE&quot; rel=&quot;nofollow noreferrer&quot;&gt;my current implementation&lt;/a&gt;: the pixel-by-pixel rotation of the copied bitmap is extremely slow and it is leaving gaps between the pixels.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/HkrpJ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/HkrpJ.jpg&quot; alt=&quot;Rotated Image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Is there a faster method for copying the bitmap data at an angle that would not have the gaps? This does not have to be specific to Javascript, so any algorithms in any languages are welcome. Please let me know if you have any questions. Thank you.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-js prettyprint-override&quot;&gt;&lt;code&gt;  cos = Math.cos(-rotation);&#xA;  sin = Math.sin(-rotation);&#xA;&#xA;  //setting the center of rotation&#xA;  cx = canvas.width/2;&#xA;  cy = canvas.height/2;&#xA;&#xA;  for (x = 0; x &amp;lt; canvas.width; x++)&#xA;  {&#xA;    for (y = 0; y &amp;lt; canvas.height; y++)&#xA;    {&#xA;      //looping through the original bitmap's pixels&#xA;      var imgd = ctx.getImageData(x, y, 1, 1); //getting the pixels' colors 1-by-1&#xA;      var pix = imgd.data;&#xA;      var red = pix[0];&#xA;      var green = pix[1];&#xA;      var blue = pix[2];&#xA;      var alpha = pix[3];&#xA;      //rotating and offsetting the pixels by the new rotated dimensions&#xA;      nx = ((cos * (x-cx)) + (sin * (y - cy))+canvas2.width/2); &#xA;      ny = ((cos * (y-cy)) - (sin * (x - cx))+canvas2.height/2);&#xA;      //putting the transformed pixel in the new bitmap&#xA;      ctx2.putImageData(imgd, nx, ny);&#xA;    }&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14079" LastActivityDate="2021-01-21T23:24:21.087" Title="Rotating a Bitmap" Tags="&lt;transformations&gt;&lt;algorithm&gt;&lt;2d&gt;&lt;rasterizer&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10580" PostTypeId="2" ParentId="10579" CreationDate="2021-01-21T23:24:21.087" Score="2" Body="&lt;p&gt;You have to loop over destination pixels instead of source ones (gaps are the result of looping over source). For each destination pixel you can calculate position in source data, your code for pixel rotation should be inverted. For source pixel you will then get float x and y, on this step you can either round values and sample color from source (and get a bit distorted image), or you can treat fractional parts as parameters for neighbour pixel color interpolation (you get 4 source pixels for each destination pixel and with fractional part you can calculate color in between those pixels). Here is similar question on SO: &lt;a href=&quot;https://stackoverflow.com/questions/695080/how-do-i-rotate-an-image&quot;&gt;https://stackoverflow.com/questions/695080/how-do-i-rotate-an-image&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And the reason why your algorithm is slow is because you use heavy functions to read and write data for each pixel independently. It is generally more favorable to extract source data into some array (it could be same slow function but callng it once is not a problem) and use second array for data writing. This second array can then be copied to destination image.&lt;/p&gt;&#xA;" OwnerUserId="15541" LastActivityDate="2021-01-21T23:24:21.087" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10581" PostTypeId="2" ParentId="10576" CreationDate="2021-01-22T02:27:42.860" Score="1" Body="&lt;p&gt;This looks like the VkFormat being selected for the VkSurfaceFormat, most likekly VK_FORMAT_R8G8B8A8_SRGB. Try VK_FORMAT_R8G8B8A8_UNORM for the VkFormat with a corresponding colorspace (like VK_COLOR_SPACE_SRGB_NONLINEAR_KHR). That should give the dark color you are expecting.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-01-22T02:27:42.860" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10582" PostTypeId="2" ParentId="10541" CreationDate="2021-01-22T18:23:59.100" Score="0" Body="&lt;p&gt;[I will try to keep this answer updated as I learn more]&lt;/p&gt;&#xA;&lt;p&gt;The best reference on the foundations of light transport seems to be Arvo's &lt;a href=&quot;http://www0.cs.ucl.ac.uk/research/vr/Projects/VLF/vlfpapers/sampling/Arvo_J__Transfer_Equations_in_Global_Illumination__SIGGRAPH_course_notes_1993.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Transfer Equations in Global Illumination&lt;/a&gt; (~30 pages)&lt;/p&gt;&#xA;&lt;p&gt;Some things he doesn't cover:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Argument for symmetry of BRDF (see Veach)&lt;/li&gt;&#xA;&lt;li&gt;Transfer in media with continuously varying refractive index&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The state of the art model for Light Transport seems to be &lt;a href=&quot;http://isgwww.cs.uni-magdeburg.de/graphics/projects/dissertation/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Christian Lessig's PhD thesis&lt;/a&gt; (~600 pages). The theory is developed in terms of differentiable manifolds and Hilbert spaces and is much more technical than Arvo's note.&lt;/p&gt;&#xA;&lt;p&gt;Lessig carries out translation from the mathematical theory to algorithms (e.g. path tracing, photon mapping) in Section 4.3.&lt;/p&gt;&#xA;" OwnerUserId="15519" LastEditorUserId="15519" LastEditDate="2021-01-22T20:16:31.343" LastActivityDate="2021-01-22T20:16:31.343" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10583" PostTypeId="2" ParentId="8136" CreationDate="2021-01-22T18:57:04.557" Score="0" Body="&lt;p&gt;This is a rather late reply but it might interest others who come up to this question.&#xA;Your question assumes that your ray tracing platform does not support double precision. This is unlikely.&lt;/p&gt;&#xA;&lt;p&gt;If you are using &lt;a href=&quot;https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#built-in-vector-types&quot; rel=&quot;nofollow noreferrer&quot;&gt;CUDA&lt;/a&gt; or &lt;a href=&quot;http://man.opencl.org/vectorDataTypes.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;OpenCL&lt;/a&gt; they both support double precision vectors.&lt;/p&gt;&#xA;&lt;p&gt;If you are using &lt;a href=&quot;https://www.khronos.org/registry/vulkan/specs/1.2/html/vkspec.html#spirvenv-precision-operation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Vulkan&lt;/a&gt; things are a little more complicated due to specification saying: &amp;quot;The precision of double-precision instructions is at least that of single precision.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;Though not a ray tracing platform OpenGL also supports double precision vectors from OpenGL 4.0 and on.&lt;/p&gt;&#xA;&lt;p&gt;If you are tracing on CPU, chances are you can define a double precision vector data type, if it is not already defined.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;If, in the unlikely case that your ray tracing platform does not support double precision, or you are obliged to use single precision in any way, the only thing that I can think of is using &lt;a href=&quot;https://en.wikipedia.org/wiki/Polynomial_greatest_common_divisor#pseudo-remainder&quot; rel=&quot;nofollow noreferrer&quot;&gt;pseudo-remainder sequences&lt;/a&gt; for &lt;code&gt;rem&lt;/code&gt;- i.e. euclidean division.&#xA;Particularly you might want to check out &lt;code&gt;Subresultant pseudo-remainder sequence&lt;/code&gt; from the wikipedia section in the link. I am adding the pseudocode of the algorithm in here:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;r_0 = a&#xA;r_1 = b&#xA;for (i:= 1;r_i not equal to 0; i := i+1)&#xA;    d_i := degree_of(r_{i-1}) - degree_of(r_i)&#xA;    g_i := leading_coefficient_of(r_i)&#xA;    if i = 1 then&#xA;        b_1 := (-1)^{d_1 + 1}&#xA;        p_1 := -1&#xA;    else&#xA;        b_i := -g_{i-1} (p_i)^d_i&#xA;        p_i := ((-g_{i-1})^d_{i-1}) / (p_{i-1}^{d_{i-1}-1}&#xA;    end if&#xA;    r_i := rem((g_i)^{d_i+1} r_{i-1}, r_i) / b_i&#xA;end for&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-23T10:32:47.887" LastActivityDate="2021-01-23T10:32:47.887" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10584" PostTypeId="1" CreationDate="2021-01-23T04:07:26.143" Score="0" ViewCount="22" Body="&lt;p&gt;There is a way to move a selected point in a mesh with a cursor(assuming a camera that doesn;t change between frames).&lt;/p&gt;&#xA;&lt;p&gt;The way I remember the algorithm (but seems to be wrong) is:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Unproject the cursor position onto the world position&lt;/li&gt;&#xA;&lt;li&gt;Use this and the camera position to create a ray &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt;&lt;/li&gt;&#xA;&lt;li&gt;for every vertex in the mesh, see if &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; intersects a small sphere centered at the vertex.&lt;/li&gt;&#xA;&lt;li&gt;If you find a valid vertex, mark it as selected&lt;/li&gt;&#xA;&lt;li&gt;project the selected vertex onto the screen using the view_projection transformation of the camera&lt;/li&gt;&#xA;&lt;li&gt;store the resulting depth (z component) into a variable.&lt;/li&gt;&#xA;&lt;li&gt;Now when you move the mouse, you create a fabricated position consisting of the cursor position and the stored projected depth, then you unproject that.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The resulting point should be constrained on a plane in 3D that is parallel to the screen. I have coded the procedure but it seems I am mathematically wrong. So I am not entirely sure if I forgot a step.&lt;/p&gt;&#xA;&lt;p&gt;To be clear, the objective is to drag the mouse around and have the selected point move in 3D such that it is rendered at the same position as the cursor is on the screen.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2021-02-22T06:01:45.113" Title="Moving a vertex through the cursor" Tags="&lt;raytracing&gt;&lt;mathematics&gt;&lt;geometry&gt;&lt;projections&gt;&lt;ui&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10585" PostTypeId="2" ParentId="10584" CreationDate="2021-01-23T04:57:41.543" Score="0" Body="&lt;p&gt;Figured it out, I did skip a step, you are supposed to multiply by the homogeneous coordinate.&lt;/p&gt;&#xA;&lt;p&gt;Basically the actually projected point is (courtesy of GLM):&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;        vec&amp;lt;4, T, Q&amp;gt; tmp = vec&amp;lt;4, T, Q&amp;gt;(obj, static_cast&amp;lt;T&amp;gt;(1));&#xA;        tmp = model * tmp;&#xA;        tmp = proj * tmp;&#xA;&#xA;        tmp /= tmp.w;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Kinda obvious in hindsight.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2021-01-23T04:57:41.543" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10586" PostTypeId="2" ParentId="10535" CreationDate="2021-01-23T13:42:27.890" Score="1" Body="&lt;p&gt;This more or less a long comment than an answer.&lt;/p&gt;&#xA;&lt;p&gt;Some other options that come to mind are the following:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;A little old school, but you can create an interface with one of the texture objects. You can query different mipmap levels for your needs inside the shader. Textures are one of the better cached objects in OpenGL.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You can defer the lightening process by sending everything to a framebuffer with multiple rendering targets. The first pass would filter out the relevant parts of your data and create a geometry buffer. You can use the g-buffer for lightening pass afterwards.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;You can create a flat array where your relevant and non relevant data are divided in equal strides, then use the indices of the relevant parts stored in your Element Array Buffer object in &lt;code&gt;glDrawElements&lt;/code&gt; call. Basically you can use something like the following:&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;struct MyRealData {&#xA;vec3 myRelevantData&#xA;float myNotSoRelevantData&#xA;};&#xA;void to_drawable(MyRealData[20] ds, vec3[40] flat_drawable_array){&#xA;  for (int i = 0; i &amp;lt; 40; i+=2){&#xA;    flat_drawable_array[i] = ds[i].myRelevantData;&#xA;    flat_drawable_array[i+1] = vec3(ds[i].myNotSoRelevantData, 0, 0);&#xA;  }&#xA;}&#xA;std::vector&amp;lt;unsigned int&amp;gt; indices[] = { &#xA;  0, 2, 4, // first triangle&#xA;  2, 6, 4, // second triangle&#xA;  4, 6, 8, // third triangle&#xA;// ... etc&#xA;}; &#xA;.&#xA;. // later in the code&#xA;.&#xA;glDrawElements(GL_TRIANGLES, indices.size() , GL_UNSIGNED_INT, (GLvoid *)indices​.data());&#xA;&#xA;&lt;span class=&quot;math-container&quot;&gt;```&lt;/span&gt; &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-01-23T14:30:40.097" LastActivityDate="2021-01-23T14:30:40.097" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10587" PostTypeId="1" CreationDate="2021-01-23T16:10:54.797" Score="0" ViewCount="41" Body="&lt;p&gt;I've been researching online for fast dithering algorithms that could give my users a variety to choose from. I have implemented Floyd Steinberg's dithering algorithm before and I read Wikipedia and found posts relating to another dithering algorithm (called &lt;strong&gt;Filter Lite&lt;/strong&gt; dithering) that claims to be &lt;em&gt;faster&lt;/em&gt; and produce &lt;em&gt;better results&lt;/em&gt; than Floyd Steinberg's dithering. Curious, I wanted to find a way to implement this into my own code. I tried my best trying to research online for the algorithm, but I found no luck. I only find information that it was created by Sierra by &lt;a href=&quot;https://stackoverflow.com/questions/9150338/besides-floyd-steinberg-dithering-any-other-ways-to-dither-the-images/18396913&quot;&gt;this Stackoverflow Post&lt;/a&gt;, however, the text file it provided was not found anymore and a lot of sources seem to lack this detail online.&lt;/p&gt;&#xA;&lt;p&gt;I figured I would ask here, as I am not sure if this algorithm was intended to be private or not, and I wanted to verify whether if it is released to the public or not. (I suspected it was private because there were not many examples produced by this dithering and its lack of detail on forums/encyclopedias)&lt;/p&gt;&#xA;&lt;p&gt;If possible, is this algorithm released to the public? And if it is, what are the steps to the algorithm which produce the dithered result?&lt;/p&gt;&#xA;&lt;p&gt;(Note: I asked about this on StackOverflow however it seems that not a lot of people have experience around it)&lt;/p&gt;&#xA;" OwnerUserId="15615" LastActivityDate="2021-01-23T16:10:54.797" Title="What is Filter Lite dithering, and how do I implement such an algorithm?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10589" PostTypeId="1" AcceptedAnswerId="10590" CreationDate="2021-01-24T13:27:59.693" Score="0" ViewCount="38" Body="&lt;p&gt;I'm just starting to work with framebuffer objects and am having trouble trying to figure out why I can't blit my framebuffer to my viewport.  I know my framebuffer has data drawn to it since I can read its pixel using glReadPixels and save it as an image.  However, when I try to draw it to my back buffer so that I can see it in the window, it draws nothing at all - all I see is the color I cleared the viewport to.&lt;/p&gt;&#xA;&lt;p&gt;What am I doing wrong?&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;&#xA;void DocumentPanel::paintGL()&#xA;{&#xA;    QOpenGLFunctions_3_3_Core *f = QOpenGLContext::currentContext()-&amp;gt;versionFunctions&amp;lt;QOpenGLFunctions_3_3_Core&amp;gt;();&#xA;&#xA;    //Setup framebuffer&#xA;    setupFramebuffer();&#xA;&#xA;    //Render to framebuffer&#xA;    f-&amp;gt;glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferID);&#xA;    f-&amp;gt;glClearColor(0, 0, 1, 0);&#xA;&#xA;    f-&amp;gt;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);&#xA;&#xA;    drawShapes();&#xA;&#xA;&#xA;    //--------------------------------------------&#xA;&#xA;    f-&amp;gt;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;    if (!_oneShot)&#xA;    {&#xA;        dumpFramebuffer();&#xA;        _oneShot = true;&#xA;    }&#xA;&#xA;    f-&amp;gt;glClearColor(0, 0.5, .5, 0);&#xA;    f-&amp;gt;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);&#xA;&#xA;    f-&amp;gt;glDisable(GL_DEPTH_TEST);&#xA;    f-&amp;gt;glDisable(GL_STENCIL_TEST);&#xA;&#xA;    int w = width();&#xA;    int h = height();&#xA;    f-&amp;gt;glBindFramebuffer(GL_READ_FRAMEBUFFER, _frameBufferID);&#xA;    f-&amp;gt;glReadBuffer(GL_COLOR_ATTACHMENT0);&#xA;    f-&amp;gt;glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);&#xA;    f-&amp;gt;glDrawBuffer(GL_BACK);&#xA;    f-&amp;gt;glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);&#xA;    checkForErrors();&#xA;}&#xA;&#xA;&#xA;void DocumentPanel::setupFramebuffer()&#xA;{&#xA;    QOpenGLFunctions_3_3_Core *f = QOpenGLContext::currentContext()-&amp;gt;versionFunctions&amp;lt;QOpenGLFunctions_3_3_Core&amp;gt;();&#xA;&#xA;    int w = width();&#xA;    int h = height();&#xA;    int samples = 4;&#xA;    bool multisample = false;&#xA;&#xA;    if (_frameBufferID == 0)&#xA;    {&#xA;        f-&amp;gt;glGenFramebuffers(1, &amp;amp;_frameBufferID);&#xA;        f-&amp;gt;glBindFramebuffer(GL_FRAMEBUFFER, _frameBufferID);&#xA;    }&#xA;&#xA;    if (_renderBufferColorID == 0)&#xA;    {&#xA;        f-&amp;gt;glGenRenderbuffers(1, &amp;amp;_renderBufferColorID);&#xA;        f-&amp;gt;glBindRenderbuffer(GL_RENDERBUFFER, _renderBufferColorID);&#xA;&#xA;        if (!multisample)&#xA;            f-&amp;gt;glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, w, h);&#xA;        else&#xA;            f-&amp;gt;glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_RGBA, w, h);&#xA;        f-&amp;gt;glBindRenderbuffer(GL_RENDERBUFFER, 0);&#xA;&#xA;        f-&amp;gt;glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, _renderBufferColorID);&#xA;    }&#xA;&#xA;    if (_renderBufferDepthStencilID == 0)&#xA;    {&#xA;        f-&amp;gt;glGenRenderbuffers(1, &amp;amp;_renderBufferDepthStencilID);&#xA;        f-&amp;gt;glBindRenderbuffer(GL_RENDERBUFFER, _renderBufferDepthStencilID);&#xA;        if (!multisample)&#xA;            f-&amp;gt;glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, w, h);&#xA;        else&#xA;            f-&amp;gt;glRenderbufferStorageMultisample(GL_RENDERBUFFER, samples, GL_DEPTH24_STENCIL8, w, h);&#xA;        f-&amp;gt;glBindRenderbuffer(GL_RENDERBUFFER, 0);&#xA;&#xA;        f-&amp;gt;glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, _renderBufferDepthStencilID);&#xA;    }&#xA;&#xA;    GLenum status = f-&amp;gt;glCheckFramebufferStatus(GL_FRAMEBUFFER);&#xA;    if (status != GL_FRAMEBUFFER_COMPLETE)&#xA;    {&#xA;        //error&#xA;        QString err;&#xA;&#xA;        switch (status)&#xA;        {&#xA;        case GL_FRAMEBUFFER_UNDEFINED:&#xA;            err = &amp;quot;GL_FRAMEBUFFER_UNDEFINED&amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:&#xA;            err = &amp;quot;GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT&amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT :&#xA;            err = &amp;quot;GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT &amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER :&#xA;            err = &amp;quot;GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER &amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER :&#xA;            err = &amp;quot;GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER &amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_UNSUPPORTED :&#xA;            err = &amp;quot;GL_FRAMEBUFFER_UNSUPPORTED &amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE :&#xA;            err = &amp;quot;GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE &amp;quot;;&#xA;        break;&#xA;        case GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS  :&#xA;            err = &amp;quot;GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS  &amp;quot;;&#xA;        break;&#xA;        }&#xA;&#xA;        f-&amp;gt;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;        qDebug() &amp;lt;&amp;lt; &amp;quot;Error building frambuffer: &amp;quot; &amp;lt;&amp;lt; err;&#xA;        return;&#xA;    }&#xA;&#xA;    //Rendering to window again&#xA;    f-&amp;gt;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;}&#xA;&lt;span class=&quot;math-container&quot;&gt;```&lt;/span&gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="15620" LastActivityDate="2021-01-24T21:05:56.710" Title="Can’t blit framebuffer to backbuffer" Tags="&lt;frame-buffer&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10590" PostTypeId="2" ParentId="10589" CreationDate="2021-01-24T21:05:56.710" Score="0" Body="&lt;p&gt;Looks like I misunderstood how my windowing system was handling rendering.  It had created an offscreen buffer that was being used to update the window.  When I use &lt;code&gt;glBlitFramebuffer&lt;/code&gt; with the buffer id &lt;code&gt;QOpenGLWdget&lt;/code&gt; gives me, my image appears.&lt;/p&gt;&#xA;" OwnerUserId="15620" LastActivityDate="2021-01-24T21:05:56.710" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10591" PostTypeId="2" ParentId="8935" CreationDate="2021-01-24T21:25:08.563" Score="0" Body="&lt;p&gt;Not a direct answer, but I can shed light on adding and removing pink control points using the GUI:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;initially PowerStrok gives you 3 pink control points.&lt;/li&gt;&#xA;&lt;li&gt;CTRL-Click on one of them duplicates it. Drag it along the path to a new position.&lt;/li&gt;&#xA;&lt;li&gt;CTRL-ALT-Click removes the clicked one (don't remove all)&lt;/li&gt;&#xA;&lt;li&gt;ALT-Click on a pink control point opens a text entry for exact coordinates.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="15622" LastActivityDate="2021-01-24T21:25:08.563" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10592" PostTypeId="2" ParentId="8935" CreationDate="2021-01-24T21:30:27.007" Score="0" Body="&lt;p&gt;My guess on the math question is, that there is no straight forward formula to compute &amp;quot;the width&amp;quot; at a given position.&lt;/p&gt;&#xA;&lt;p&gt;The pink control points seem to create a spline and you would need proper spline interpolation to predict an exact width at a given position. They can even be dragged out of order, so that the boundary spline would do crazy self-overlapping things. That results in &amp;quot;multiple widths&amp;quot; at some positions.&lt;/p&gt;&#xA;" OwnerUserId="15622" LastActivityDate="2021-01-24T21:30:27.007" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10593" PostTypeId="1" CreationDate="2021-01-25T10:44:59.310" Score="0" ViewCount="61" Body="&lt;p&gt;The part confusing  about opengl during studying the projection was that the focal length, top, left, bottom, right, wasn't declared, and it magically did it with FOV and image aspect ration.   I found the wonderful maths in &lt;a href=&quot;https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/opengl-perspective-projection-matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;this amazing site&lt;/a&gt;, and found out how it is calculated based on FOV and focal length.&lt;br /&gt;&#xA;Two points I noted for my confusion was:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;near clipping plane is the plane which limits the projected coordinates, and&lt;/li&gt;&#xA;&lt;li&gt;focal length is the distance from the point of projection to the optical center( (0,0,0) in our case )&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Now, the question is, is the focal length always equal to the distance of the near clipping plane from the optical center, i.e. in other words, is the image &lt;em&gt;always&lt;/em&gt; projected on the near clipping plane (or at least in openGL)? Yet in other words, is the near clipping plane and the plane of projection the same thing just with different terms.&lt;/p&gt;&#xA;" OwnerUserId="11832" LastActivityDate="2021-01-26T18:39:37.597" Title="is focal length equal to the distance from the optical center to the near clipping plane- openGL" Tags="&lt;opengl&gt;&lt;projections&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10595" PostTypeId="1" CreationDate="2021-01-26T01:27:39.060" Score="0" ViewCount="31" Body="&lt;p&gt;Would someone be able to explain why a sphere when projected with the pinhole projection model has its projected 2D image be an ellipsis. IN particular when the sphere is not directly in front of the center of projections why is the image of the sphere skewed? Any diagrams explaining this or formula would be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="15632" LastActivityDate="2021-01-26T01:27:39.060" Title="Pinhole Projection &amp; Spheres" Tags="&lt;image-processing&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="3" ClosedDate="2021-02-02T11:28:45.857" ContentLicense="CC BY-SA 4.0" />
  <row Id="10596" PostTypeId="1" CreationDate="2021-01-26T07:18:07.553" Score="0" ViewCount="27" Body="&lt;p&gt;Im going over this paper by Vogel &lt;a href=&quot;https://www.researchgate.net/publication/220839097_A_Direct_Numerical_Approach_to_Perspective_Shape-from-Shading?enrichId=rgreq-cbdcc17ec910a3772b1eefcd66192859-XXX&amp;amp;enrichSource=Y292ZXJQYWdlOzIyMDgzOTA5NztBUzoxMDQxMTk5NTYxNDgyMzhAMTQwMTgzNTU0MDU4Mw%3D%3D&amp;amp;el=1_x_3&amp;amp;_esc=publicationCoverPdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;A Direct Numerical Approach to Perspective Shape-from-Shading.&lt;/a&gt; I have a problem in the way they define the normalized image brightness I(x) as:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I(x) = E(x)/sigma&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;where sigma &amp;quot;depends on the albedo of the surface and the intensity of the light source&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;I am estimating the albedo with the formula given &lt;a href=&quot;http://www.sci.utah.edu/%7Egerig/CS6320-S2015/Materials/Elhabian_SFS08.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. As the albedo is in the range of [0, 1], and the max light intensity is 255, I'm guessing that sigma must be atmost 255. However, in the paper the authors have taken a value of 1000. Later for another example of Mozart image, the authors have assume a value of 4*10^4.&lt;/p&gt;&#xA;&lt;p&gt;It would be great if someone could explain how they arrive at these values and why, and where I'm wrong.&lt;/p&gt;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="15634" LastActivityDate="2021-01-26T07:18:07.553" Title="Normalized image for shape from shading" Tags="&lt;image-processing&gt;&lt;reflection&gt;&lt;diffuse&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10597" PostTypeId="1" AcceptedAnswerId="10601" CreationDate="2021-01-26T16:13:20.340" Score="0" ViewCount="30" Body="&lt;p&gt;I know how to rotate objects around the center and there are rotation matrices for that as well, but, how do we rotate the object like a trackball, below is the example:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/7Toy2.gif&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7Toy2.gif&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;firstly I rotate around the y axis, and then the x axis, then I rotate it like a trackball, how is the third rotation achieved?&lt;/p&gt;&#xA;" OwnerUserId="11832" LastActivityDate="2021-01-28T01:22:55.150" Title="rotate objects like a trackball" Tags="&lt;transformations&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10598" PostTypeId="2" ParentId="10593" CreationDate="2021-01-26T18:34:37.193" Score="1" Body="&lt;p&gt;For some reason most sites choose to leave the projection plane out of the visualization of the view frustum. The focal length often labeled &amp;quot;g&amp;quot; is the distance from the camera to the projection plane. The projection plane (which is blue in the attached image) is almost always placed at a distance from the camera such that the distance from the center to the top and bottom is 1. This image from the fged website shows it well: &lt;a href=&quot;https://i.stack.imgur.com/6wEgR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6wEgR.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt; This choice is a matter of convenience since it makes the math all work out nice and neat. As you can see the near plane can, and often is, behind the projection plane. (the green plane in the image is the near plane)&lt;/p&gt;&#xA;&lt;p&gt;For your second confusion: One goal of the projection matrix is to force coordinates with a z value less then that of the near plane to fall outside of the near clipping region which is -1 in OpenGL. So any coordinate that has a z value less then near value will result in a z value below -1 after projection.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-01-26T18:39:37.597" LastActivityDate="2021-01-26T18:39:37.597" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10599" PostTypeId="1" CreationDate="2021-01-26T22:41:32.267" Score="0" ViewCount="44" Body="&lt;p&gt;I am rotating a bitmap using the three shear algorithm documented in these articles [&lt;a href=&quot;https://datagenetics.com/blog/august32013/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;1&lt;/a&gt;][&lt;a href=&quot;https://medium.com/@gautamnagrawal/rotating-image-by-any-angle-shear-transformation-using-only-numpy-d28d16eb5076&quot; rel=&quot;nofollow noreferrer&quot;&gt;2&lt;/a&gt;].&lt;/p&gt;&#xA;&lt;p&gt;From about 0-90°, the quality is acceptable, but beyond that it gets progressively more distorted until it's unintelligible.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/eKfDz.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/eKfDz.png&quot; alt=&quot;Bitmap Image Rotations&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Can anyone help me locate what is going wrong? Thank you!&lt;/p&gt;&#xA;&lt;p&gt;This is my shear function:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;def shear(angle,x,y):&#xA;    '''&#xA;    |1  -tan(/2) |  |1        0|  |1  -tan(/2) |&#xA;    |0      1     |  |sin()   1|  |0      1     |&#xA;&#xA;    '''&#xA;    # shear 1&#xA;    tangent=math.tan(angle/2)&#xA;    new_x=round(x-y*tangent)&#xA;    new_y=y&#xA;&#xA;    #shear 2&#xA;    new_y=round(new_x*math.sin(angle)+new_y)      #since there is no change in new_x according to the shear matrix&#xA;&#xA;    #shear 3&#xA;    new_x=round(new_x-new_y*tangent)              #since there is no change in new_y according to the shear matrix&#xA;&#xA;    return new_x,new_y&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is the code in the draw function:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;cos = math.cos(self.rotation)&#xA;sin = math.sin(self.rotation)&#xA;&#xA;# Define the width and height of the destination image&#xA;newWidth = round(abs(w*cos)+abs(h*sin))+1&#xA;newHeight = round(abs(h*cos)+abs(w*sin))+1&#xA;&#xA;# Find the center of the source image for rotation&#xA;origCenterWidth  = round(((w+1)/2)-1)    #with respect to the source image&#xA;origCenterHeight = round(((h+1)/2)-1)    #with respect to the source image&#xA;&#xA;# Find the center of the destination image&#xA;newCenterWidth  = round(((newWidth+1)/2)-1)  #with respect to the destination image&#xA;newCenterHeight = round(((newHeight)/2)-1)  #with respect to the destination image&#xA;&#xA;for i in range(h):&#xA;    for j in range(w):&#xA;        #co-ordinates of pixel with respect to the center of source image&#xA;        x = w-1-j-origCenterWidth&#xA;        y = h-1-i-origCenterHeight&#xA;&#xA;        #Applying the Shear Transformation&#xA;        new_x,new_y = shear(self.rotation,x,y)&#xA;&#xA;        #with rotation, the center will change so new_x and new_y will be the new center&#xA;        new_y = newCenterHeight-new_y&#xA;        new_x = newCenterWidth-new_x&#xA;&#xA;        alphaValue = sourceBmp.GetAlphaPixel(alphaChannel, j, i) #gets the source image pixel's alpha&#xA;        col = sourceBmp.GetPixelDirect(j, i) #gets the source image pixel's color as a Color Vector&#xA;        destBmp.SetAlphaPixel(nBmpAlpha, int(new_x), int(new_y), alphaValue) #sets the destination image pixel's alpha&#xA;        destBmp.SetPixel(int(new_x), int(new_y), int(col.x), int(col.y), int(col.z)) #sets the destination image pixel's color&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14079" LastEditorUserId="14079" LastEditDate="2021-01-27T16:22:07.713" LastActivityDate="2021-01-28T22:46:41.223" Title="Rotate a Bitmap with Shearing" Tags="&lt;transformations&gt;&lt;algorithm&gt;&lt;matrix&gt;&lt;2d&gt;&lt;antialiasing&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10601" PostTypeId="2" ParentId="10597" CreationDate="2021-01-28T01:22:55.150" Score="1" Body="&lt;p&gt;I don't know the specifics of what looks to be blender. But I would grab the view matrix of the camera. The rows of which should be orthonormal and give you forward, up, and right. Or columns depending on row or col major (technically its the inverse of the view, but that's just the transpose). Then just do some axes angle rotations around that. Something like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Vec3 dx = scale * (currPosX - prevPosX)&#xA;Vec3 dy = scale * (currPosY - prevPosY)&#xA;Matrix4x4 m1 = axesAngleRot(dx, camera up)&#xA;Matrix4x4 m2 = axesAngleRot(dy, camera right)&#xA;&#xA;Matrix4x4 deltaRot = m1 * m2&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Where scale is defined by you, and dx and dy give the delta coords of the mouse.&lt;/p&gt;&#xA;&lt;p&gt;Then apply that to the object. You may have to tack on an extra transform to move back to origin (however you have that transform defined) before doing rotations. The cube you showed is at origin though.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Matrix4x4 finalTransform = inverseFinalTransform * deltaRot * finalTransform&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="113" LastActivityDate="2021-01-28T01:22:55.150" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10602" PostTypeId="2" ParentId="10599" CreationDate="2021-01-28T22:46:41.223" Score="2" Body="&lt;p&gt;as paulHK said:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;One fundamental issue here is you're rotating in destination space rather than source space (e.g. apply the shear on source coordinates and output a rectangle). This way you can guarantee every pixel in the output is drawn once and only once and there are no gaps in between.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;and the line that's causing the 180 problem is this line:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;tangent=math.tan(angle/2)&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;If the angle is 180, the tan of 90 will be basically infinity.&lt;/p&gt;&#xA;&lt;p&gt;This is a graph of 1 / (cos(rotation) ^ 2), one of the shearing calculations the narrator at datagenetics.com uses:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/c2roH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/c2roH.png&quot; alt=&quot;graph showing extreme peaks of function&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;That means his method stalls at certain angles.&lt;/p&gt;&#xA;&lt;p&gt;In all the code i wrote, I never needed to call tan(x).&#xA;Use cos(x) and sin(x) instead, also use as few divisions as possible that could create infinity. Most rendering engines tackle this problem by limiting the angle of the camera to 89 degrees.&lt;/p&gt;&#xA;&lt;p&gt;To get unaliased rotated images, i suggest a better drawing method, which computer graphics use today:&lt;/p&gt;&#xA;&lt;p&gt;Use a 3x3 &lt;a href=&quot;https://en.wikipedia.org/wiki/Rotation_matrix&quot; rel=&quot;nofollow noreferrer&quot;&gt;rotation matrix&lt;/a&gt; and a &lt;a href=&quot;https://en.wikipedia.org/wiki/Translation_(geometry)#Matrix_representation&quot; rel=&quot;nofollow noreferrer&quot;&gt;translation matrix&lt;/a&gt; , and loop over the pixels image that you want to draw on:&lt;/p&gt;&#xA;&lt;p&gt;cos(angle) -sin(angle) + offset x &lt;br&gt;&#xA;sin(angle) cos(angle)  + offset y &lt;br&gt;&#xA;0          0           1 &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;to get this matrix, multiply first: &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;1 0 -[rotation centre x]  &lt;br&gt;&#xA;0 1 -[rotation centre y]  &lt;br&gt;&#xA;0 0 1 &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;then: &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;cos(angle) -sin(angle) 0 &lt;br&gt;&#xA;sin(angle) cos(angle)  0 &lt;br&gt;&#xA;0          0           1&lt;/p&gt;&#xA;&lt;p&gt;and then: &lt;br&gt;&#xA;1 0 [rotation centre x]  &lt;br&gt;&#xA;0 1 [rotation centre y]  &lt;br&gt;&#xA;0 0 1 &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;and then(if needed to translate): &lt;br&gt;&#xA;1 0 [translation x]  &lt;br&gt;&#xA;0 1 [translation y]  &lt;br&gt;&#xA;0 0 1 &lt;br&gt;&lt;/p&gt;&#xA;&lt;p&gt;Multiply the position on the target image by the &lt;strong&gt;INVERSE&lt;/strong&gt; of the combined matrix to get the position on the source image.&lt;/p&gt;&#xA;&lt;p&gt;If the position is in the bounds of the source image,&#xA;fill the target pixel with the source pixel at that location.&lt;/p&gt;&#xA;" OwnerUserId="15655" LastActivityDate="2021-01-28T22:46:41.223" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10603" PostTypeId="1" CreationDate="2021-01-29T05:55:21.440" Score="0" ViewCount="30" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/S5SD0.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/S5SD0.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Stuck with this questions could I get some help.&lt;/p&gt;&#xA;&lt;p&gt;where uA and vA are two orthonormal vectors indicating the two axes, and oA is the origin.  Suppose that all  three  frames  of  reference  shown  in  Figure  3  are  orthonormal,  and  suppose  that A and B are  related through  the  affine  transformation N,  and A and C are  related  through  the  affine  transformation M.   In particular,B=AN,and C=AM.Derive an expression of M using only the symbolsθ,d, andφ(in Figure 3) (i.e., matrix M is the function of θ,d, andφ ).&lt;/p&gt;&#xA;" OwnerUserId="15632" LastActivityDate="2021-01-29T05:55:21.440" Title="Changing Coordinate Frames with Affine Transformations" Tags="&lt;computational-geometry&gt;&lt;geometry&gt;&lt;vector-graphics&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10604" PostTypeId="1" AcceptedAnswerId="10606" CreationDate="2021-01-29T10:27:35.980" Score="0" ViewCount="55" Body="&lt;p&gt;I am interested in how much a GPU can actually calculate. When learning about rendering, it seems like a good idea as well.&lt;/p&gt;&#xA;&lt;p&gt;My Question:&#xA;&lt;strong&gt;WHAT EXACTLY is a Floating Point Operation?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I know what a floating point number is.&lt;/p&gt;&#xA;&lt;p&gt;Now, when reading other questions and articles about it, they always say, any simple operation, + - * / , would be a floating point operation, which makes sense in terms of the word itself&lt;/p&gt;&#xA;&lt;p&gt;BUT:   &lt;em&gt;A multiplication is (obviously) often &amp;quot;far&amp;quot; more (calculating) than an addition, isn't it?!&lt;/em&gt;&#xA;(Apart from the sheer size of the calculation)&lt;/p&gt;&#xA;&lt;p&gt;Following, just a simple example for demonstration:&lt;/p&gt;&#xA;&lt;p&gt;5+5=       5+5&lt;/p&gt;&#xA;&lt;p&gt;5*5=       5+5+5+5+5&lt;/p&gt;&#xA;&lt;p&gt;So does the term &amp;quot;flop&amp;quot; actually just describe additions and subtractions&#xA;or is a flop in the end just a very rough definition?&#xA;Or is the GPU somehow equally fast at all of those calculations?&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="15656" LastActivityDate="2021-02-03T15:30:15.483" Title="FLOP - exact definition" Tags="&lt;gpu&gt;&lt;hardware&gt;&lt;theory&gt;" AnswerCount="3" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10605" PostTypeId="1" CreationDate="2021-01-29T10:39:38.597" Score="0" ViewCount="32" Body="&lt;p&gt;is it possible to calculate a &amp;quot;projection matrix&amp;quot; which is sheared as well?&#xA;the usual perspective projection matrix forms a pyramid where the near clipping plane is rectangular.&#xA;I have 4 lines which represents the edges of the pyramid in general. But the clipping plane is not orthogonal to the view direction (see picture 1)&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Picture 1: view onto the projected area from above. Also from the side direction it will look like this&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/08M8I.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/08M8I.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;By looking from the view position to the near clipping plane / image plane it would look like picture 2.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Picture 2: the view from the view position onto the scene&lt;/strong&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/etMwM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/etMwM.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The image plane is restricted to be rectangular. Only from the view position its shape will look non rectangular.&lt;/p&gt;&#xA;&lt;p&gt;Now lets look at the parameters which are known:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;all 4 corners of the image plane&lt;/li&gt;&#xA;&lt;li&gt;the view position&lt;/li&gt;&#xA;&lt;li&gt;the far plane distance&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;so my task is to calculate this projection matrix, but I've no idea how to start or if it is possible at all.&#xA;Thanks for your help in advance!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastEditorUserId="13273" LastEditDate="2021-01-29T10:51:06.760" LastActivityDate="2021-01-29T10:51:06.760" Title="computing sheared perspective projection matrix" Tags="&lt;projections&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10606" PostTypeId="2" ParentId="10604" CreationDate="2021-01-29T12:05:16.953" Score="0" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Now, when reading other questions and articles about it, they always say, any simple operation, + - * / , would be a floating-point operation, which makes sense in terms of the word itself&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This is basically what is meant when talking about floating-point operations although I would exclude the division since it takes much longer than the other operations (see below).&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;BUT: A multiplication is (obviously) often &amp;quot;far&amp;quot; more (calculating) than an addition, isn't it?! (Apart from the sheer size of the calculation)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Most modern processors can usually calculate additions and multiplications equally fast. Even though the numbers are for CPUs and not for GPUs, you can take a look at the corresponding commands in the &lt;a href=&quot;https://software.intel.com/sites/landingpage/IntrinsicsGuide/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Intel intrinsics guide&lt;/a&gt;. A GPU shouldn't behave too different in this matter. Here are some examples:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_add_ps&amp;amp;expand=3928,3928,133&quot; rel=&quot;nofollow noreferrer&quot;&gt;addition&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_sub_ps&amp;amp;expand=3928,3928,133,5727&quot; rel=&quot;nofollow noreferrer&quot;&gt;subtraction&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_mul_ps&amp;amp;expand=3928,3928&quot; rel=&quot;nofollow noreferrer&quot;&gt;multiplication&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_div_ps&amp;amp;expand=3928,3928,133,5727,2156&quot; rel=&quot;nofollow noreferrer&quot;&gt;division&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;As you can see, the numbers of the Skylake processor are all identical except for the division.&lt;/p&gt;&#xA;&lt;p&gt;In case you wonder what those numbers mean: Latency is the number of cycles that are necessary to calculate the result and throughput is the inverse number of operations you can start per cycle. So for addition, subtraction and multiplication, a skylake processor can start the calculation of 2 operations per cycle and get the results 4 cycles later. This means that you can actually have 8 of those operations in progress if they do not depend on each other.&lt;/p&gt;&#xA;&lt;p&gt;Knowing this it is easy to see, that divisions take much longer to compute. This is why you should always calculate the inverse and multiply it instead if you need to divide a bunch of numbers by the same value.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;BUT: A multiplication is (obviously) often &amp;quot;far&amp;quot; more (calculating) than an addition, isn't it?! (Apart from the sheer size of the calculation)&lt;/p&gt;&#xA;&lt;p&gt;Following, just a simple example for demonstration:&lt;/p&gt;&#xA;&lt;p&gt;5+5= 5+5&lt;/p&gt;&#xA;&lt;p&gt;5*5= 5+5+5+5+5&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Well, this would be very inefficient. If you are curious how a computer actually performs a multiplication efficiently, take a look into &lt;a href=&quot;https://stackoverflow.com/questions/3060064/how-computer-multiplies-2-numbers&quot;&gt;this question&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2021-01-29T12:05:16.953" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10607" PostTypeId="1" AcceptedAnswerId="10611" CreationDate="2021-01-29T12:20:23.573" Score="0" ViewCount="28" Body="&lt;h1&gt;Context&lt;/h1&gt;&#xA;&lt;p&gt;I am working on project for implementing and user test a World-in-Miniature (WIM) interface for VR. A WIM essentially is a replica of the scene the user is currently in, but in miniature.&lt;/p&gt;&#xA;&lt;h1&gt;Features&lt;/h1&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;the user can have control over the WIMs position, orientation, scale. Thus, allowing to dynamically view the scene from multiple viewpoints.&lt;/li&gt;&#xA;&lt;li&gt;the user can choose from different methods to remove geometry from the scene, particularly to remove occluders such as wall of building floor, to view the objects in the room.&lt;/li&gt;&#xA;&lt;li&gt;the user can interact with certain objects objects in the scene, by simply interacting with the proxy objects in the WIM replica.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h1&gt;Question&lt;/h1&gt;&#xA;&lt;p&gt;What I am interested in is a way to take a scene of relatively complex geometry and automatically render a miniature replica of it for example in a small rectangle in from of the user (i.e sort of like a 3D map). It would have to be real-time, and performed during run-time, as the viewpoint of the user towards the WIM will change during interaction (e.g. if he for example rotates, or scales up, or down the current rendered selection).&lt;/p&gt;&#xA;&lt;h1&gt;Examples&lt;/h1&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Original Paper: &lt;a href=&quot;https://www.youtube.com/watch?v=Ytc3ix-He4E&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=Ytc3ix-He4E&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;An example I found running on an Oculus: &lt;a href=&quot;https://www.youtube.com/watch?v=zOTx_CWsR7g&amp;amp;t=105s&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=zOTx_CWsR7g&amp;amp;t=105s&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="15658" LastActivityDate="2021-02-28T17:02:10.210" Title="Render Duplicate Miniature Scene Replica" Tags="&lt;geometry&gt;&lt;mesh&gt;&lt;virtual-reality&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10608" PostTypeId="2" ParentId="10604" CreationDate="2021-01-29T14:18:11.680" Score="1" Body="&lt;p&gt;Just to add to &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10606/209&quot;&gt;whychmaster's reply&lt;/a&gt;, in my experience, on a GPU, a floating-point operation, when used in quoting FLOPS (floating-point operations per second) benchmark figures will refer to Addition (equiv subtraction) and Multiplication.&lt;/p&gt;&#xA;&lt;p&gt;The other standard IEEE operators, division + sqrt, are more computationally expensive and so unlikely to be included in the figure. &lt;em&gt;(Note that, there is often HW support in GPUs for accelerating operations like 1/x, 1/sqrt(x) etc, perhaps to make them as (or nearly as) fast as muls &amp;amp; adds)&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Having said that, it is very likely that a GPU will actually implement a Fused Multipy-Add operation, FMAD, i.e. do  A * B + C in &amp;quot;one step&amp;quot; as this is&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;more accurate than doing separate multiply and add instructions&lt;/li&gt;&#xA;&lt;li&gt;is faster than separate ops&lt;/li&gt;&#xA;&lt;li&gt;is about the same silicon cost&lt;/li&gt;&#xA;&lt;li&gt;is a very common building block of CG operations (e.g dot products, convolutions)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I suspect that in quoted figures, though, an FMAD would be considered 2 operations.&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2021-01-29T14:18:11.680" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10610" PostTypeId="2" ParentId="10561" CreationDate="2021-01-29T15:28:15.677" Score="2" Body="&lt;p&gt;This is an answer to your comment rather than the title of your question. It can be considered as a partial answer.&lt;/p&gt;&#xA;&lt;p&gt;The bias in path tracers are introduced by the estimators.&#xA;For example, think of the following two equations:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ I = \int_{\Omega} f(\omega) d\omega $$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ F = \frac{1}{N} \sum_{i}^{N} \frac{f(\omega)}{p(\omega)}$$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$p: \Omega \to R$&lt;/span&gt;.&#xA;It should be evident that as the number of samples N increases, the function &lt;span class=&quot;math-container&quot;&gt;$F$&lt;/span&gt;, ie the estimator, outputs values that are closer to &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The unbiased estimator satisfies the following &lt;span class=&quot;math-container&quot;&gt;$E[F_N] \approx I$&lt;/span&gt; or &lt;span class=&quot;math-container&quot;&gt;$\lim_{N\to\infty}F_N=I$&lt;/span&gt;, that is the expected value of the estimator matches the desired outcome in &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt; as the number of samples goes to infinity.&#xA;The biased estimator does not offer such a guarantee.&#xA;You can read more from &lt;a href=&quot;http://resolver.tudelft.nl/uuid:4a5be464-dc52-4bd0-9ede-faefdaff8be6.&quot; rel=&quot;nofollow noreferrer&quot;&gt;D. Van Antwerpen's master thesis&lt;/a&gt;, I am giving the full citation in case the link goes away:&lt;/p&gt;&#xA;&lt;p&gt;Van Antwerpen, Dietger. “Unbiased Physically Based Rendering on the GPU.” Master of Science in Computer Science, Delft University of Technology, 2010.&lt;/p&gt;&#xA;" OwnerUserId="13456" LastActivityDate="2021-01-29T15:28:15.677" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10611" PostTypeId="2" ParentId="10607" CreationDate="2021-01-29T16:10:38.590" Score="0" Body="&lt;p&gt;The first thing that jumped into my head when I saw this was Multiview. You are probably already using it to render the scene if you are rendering to VR anyway. (if not...you should)&lt;/p&gt;&#xA;&lt;p&gt;For those that don't know about Multiview:&#xA;This is a way to cast the same draw calls to multiple layers of a framebuffer image with a single draw call. It allows you to use a mask for which layers to broadcast to, so it is easy to turn broadcasting on and off (making it quick and easy to turn the WIM on and off). A new variable is available in shaders that allows the code to make adjustments for the view/projection matrix usually but the code can get much more sophisticated as needed. Its only downside is it requires relatively modern hardware.&lt;/p&gt;&#xA;&lt;p&gt;Using multiview the cpu would set up 4 view matrices, two for the VR left and right eye, and two for the WIM left and right eye. The view could then add a constant scale factor so the WIM is sized to fit, and the camera can be positioned as needed.&lt;/p&gt;&#xA;&lt;p&gt;To improve performance you will probably want to break it up into multiple passes where one pass renders everything that is common to both scenes and the second pass renders more expensive effects for the main scene. Again, as needed.&lt;/p&gt;&#xA;&lt;p&gt;The last step would be merging the two scenes, probably just by bliting the WIM over the main scene using a unique background color of the WIM as a clear alpha color.&lt;/p&gt;&#xA;&lt;p&gt;I won't go into the details of implementing multivew but googling multiview for the API you are using should give some good tutorials.&lt;/p&gt;&#xA;&lt;p&gt;Scene interaction is simplified since the CPU only really ever works with a single scene and the only tricky part is figuring out whether the user is interacting with the WIM or the main scene. This would effect how the ray is being cast into the scene (if you use ray casting for selecting objects).&lt;/p&gt;&#xA;&lt;p&gt;I just noticed that multiview is a opengl/vulkanism I'm not sure what the directx equivalent is.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-01-29T16:52:21.040" LastActivityDate="2021-01-29T16:52:21.040" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10612" PostTypeId="1" AcceptedAnswerId="10615" CreationDate="2021-01-31T11:40:33.157" Score="0" ViewCount="27" Body="&lt;p&gt;I have a 2D layer/section containing the 2D polygons colored in shades of &lt;strong&gt;green&lt;/strong&gt;.&#xA;I have another layer containing the 2D polygons colored in shades of &lt;strong&gt;blue&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/87ESC.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/87ESC.jpg&quot; alt=&quot;Two layers of 2D polygons&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I intend to figure out how different are the two layers. Maybe extracting the layers differential. Can anybody provide an &lt;strong&gt;algorithm&lt;/strong&gt;, &lt;strong&gt;library&lt;/strong&gt; or a &lt;strong&gt;hint&lt;/strong&gt;? I took a look at &lt;a href=&quot;https://doc.cgal.org/latest/Manual/packages.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;CGAL&lt;/a&gt;, but not quite sure which package to try out.&lt;/p&gt;&#xA;" OwnerUserId="9169" LastActivityDate="2021-02-01T08:23:42.407" Title="Differential or intersection of islands of 2D polygons in different layers" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10613" PostTypeId="1" AcceptedAnswerId="10625" CreationDate="2021-01-31T16:11:06.033" Score="0" ViewCount="119" Body="&lt;p&gt;I am writing a Raytracer and generating rays from the camera. I have a working program but slightly confused about the linear algebra concepts involved in transforming the ray from camera space to world space. I already have the camera position in world coordinates. So, only need to transform the direction vector. I think there are two ways to achieve this,&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;a) Directly transforming the direction vector:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The direction vector can be built as,&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;direction vector = point on film - camera position&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;The camera is at the origin, so the above would reduce to the coordinates of the point on the film. Now, we can write this direction vector in homogeneous form and apply the camera to world transformation. This should give us the direction vector for the ray in world space.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;b) Transform the origin and point on film:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The origin's position vector is at zero and the position vector of a point on the film is the point's coordinates. We can apply the camera to world transformation to these and this would give us two position vectors in world space: the camera's position vector and the film point's position vector. Then, the direction vector in world space can be directly built as,&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;direction vector = point on film (world space) - camera position (world space)&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Mathematically, the first approach is to multiply the direction vector in camera space by the camera to the world (4x4) matrix, and this would be my answer. However, based on the second approach, I should do the same thing (multiply by 4x4 matrix) and then subtract by the camera's position in world space.&lt;/p&gt;&#xA;&lt;p&gt;I tried programming both strategies and the second approach seems to give the right answer. What's wrong with my first approach?&lt;/p&gt;&#xA;" OwnerUserId="15668" LastActivityDate="2021-02-03T05:35:57.397" Title="Transforming a ray from camera space to world space" Tags="&lt;raytracing&gt;&lt;transformations&gt;&lt;pathtracing&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10614" PostTypeId="1" CreationDate="2021-01-31T20:19:27.370" Score="0" ViewCount="44" Body="&lt;p&gt;Have been searching a lot for a good spline interpolation library in cpp, came across one, which is the famous Eigen library , having the unsupported counterpart for spline fitting.&amp;lt;&lt;a href=&quot;https://eigen.tuxfamily.org/dox/unsupported/structEigen_1_1SplineFitting.html#a7bd937fdcfa168dbdc27932886a4da9f&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;&amp;gt;.&#xA;I need spline fitting API that also accepts derivatives.&lt;/p&gt;&#xA;&lt;p&gt;Eigen's &lt;strong&gt;InterpolateWithDerivatives&lt;/strong&gt; API claim to offer that but it is not without bugs. What alternatives do I have?&lt;/p&gt;&#xA;" OwnerUserId="10370" LastActivityDate="2021-03-04T10:07:35.840" Title="Spline interpolation library in cpp" Tags="&lt;c++&gt;&lt;geometry&gt;&lt;interpolation&gt;&lt;curve&gt;&lt;bezier-curve&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10615" PostTypeId="2" ParentId="10612" CreationDate="2021-02-01T08:23:42.407" Score="1" Body="&lt;p&gt;In CGAL, there is the &lt;a href=&quot;https://doc.cgal.org/latest/Arrangement_on_surface_2/index.html#Chapter_2D_Arrangements&quot; rel=&quot;nofollow noreferrer&quot;&gt;Arrangement package&lt;/a&gt; that allows to build a topologically valid planar partition given a set of segments, and the &lt;a href=&quot;https://doc.cgal.org/latest/Boolean_set_operations_2/index.html#Chapter_2D_Regularized_Boolean_Set-Operations&quot; rel=&quot;nofollow noreferrer&quot;&gt;Regularized Boolean Set-Operations&lt;/a&gt; that provides boolean operations between polygons.&lt;/p&gt;&#xA;" OwnerUserId="11747" LastActivityDate="2021-02-01T08:23:42.407" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10616" PostTypeId="2" ParentId="9537" CreationDate="2021-02-01T15:24:17.770" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://www.khronos.org/registry/OpenGL/specs/gl/glspec46.core.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;The OpenGL spec&lt;/a&gt; section 14.6.1 spells it out&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;h2&gt;14.6.1 Basic Polygon Rasterization&lt;/h2&gt;&#xA;&lt;p&gt;The first step of polygon rasterization is to determine if the polygon is back-facing&#xA;or front-facing. This determination is made based on the sign of the (clipped or&#xA;unclipped) polygon’s area computed in window coordinates. One way to compute&#xA;this area is&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tFs8W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tFs8W.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;where  = 1 when the clip control origin is &lt;code&gt;LOWER_LEFT&lt;/code&gt; and  = −1 when the&#xA;origin is &lt;code&gt;UPPER_LEFT&lt;/code&gt;, &lt;em&gt;x&lt;sup&gt;i&lt;/sup&gt;&lt;sub&gt;w&lt;/sub&gt;&lt;/em&gt; and &lt;em&gt;y&lt;sup&gt;i&lt;/sup&gt;&lt;sub&gt;w&lt;/sub&gt;&lt;/em&gt; are the &lt;em&gt;x&lt;/em&gt; and &lt;em&gt;y&lt;/em&gt; window coordinates of the &lt;em&gt;i&lt;/em&gt;th&#xA;vertex of the &lt;em&gt;n&lt;/em&gt;-vertex polygon (vertices are numbered starting at zero for purposes&#xA;of this computation) and &lt;em&gt;i&lt;/em&gt; ⊕ 1 is (&lt;em&gt;i&lt;/em&gt; + 1) mod &lt;em&gt;n&lt;/em&gt;. The interpretation of the sign of&#xA;this value is controlled with&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void FrontFace( enum dir );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Setting &lt;em&gt;dir&lt;/em&gt; to &lt;code&gt;CCW&lt;/code&gt; (corresponding to counter-clockwise orientation of the projected polygon in window coordinates) uses &lt;em&gt;a&lt;/em&gt; as computed above. Setting &lt;em&gt;dir&lt;/em&gt; to&#xA;&lt;code&gt;CW&lt;/code&gt; (corresponding to clockwise orientation) indicates that the sign of &lt;em&gt;a&lt;/em&gt; should be&#xA;reversed prior to use. Front face determination requires one bit of state, and is&#xA;initially set to &lt;code&gt;CCW&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;If the sign of &lt;em&gt;a&lt;/em&gt; (including the possible reversal of this sign as determined by&#xA;&lt;strong&gt;FrontFace&lt;/strong&gt;) is positive, the polygon is front-facing; otherwise, it is back-facing.&#xA;This determination is used in conjunction with the &lt;strong&gt;CullFace&lt;/strong&gt; enable bit and mode&#xA;value to decide whether or not a particular polygon is rasterized. The &lt;strong&gt;CullFace&lt;/strong&gt;&#xA;mode is set by calling&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void CullFace( enum mode );&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;em&gt;mode&lt;/em&gt; must be &lt;code&gt;FRONT&lt;/code&gt;, &lt;code&gt;BACK&lt;/code&gt; or &lt;code&gt;FRONT_AND_BACK&lt;/code&gt;. Culling is enabled or disabled&#xA;by calling &lt;strong&gt;Enable&lt;/strong&gt; or &lt;strong&gt;Disable&lt;/strong&gt; with target &lt;code&gt;CULL_FACE&lt;/code&gt;. Front-facing polygons are&#xA;rasterized if either culling is disabled or the &lt;strong&gt;CullFace&lt;/strong&gt; mode is &lt;code&gt;BACK&lt;/code&gt; while back facing polygons are rasterized only if either culling is disabled or the &lt;strong&gt;CullFace&lt;/strong&gt;&#xA;mode is &lt;code&gt;FRONT&lt;/code&gt;. The initial setting of the &lt;strong&gt;CullFace&lt;/strong&gt; mode is &lt;code&gt;BACK&lt;/code&gt;. Initially, culling&#xA;is disabled&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;" OwnerUserId="4766" LastActivityDate="2021-02-01T15:24:17.770" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10617" PostTypeId="2" ParentId="10614" CreationDate="2021-02-02T09:06:54.083" Score="0" Body="&lt;p&gt;So you have a series of points and, at each point, a supplied derivative?&lt;/p&gt;&#xA;&lt;p&gt;Is a piecewise cubic sufficient or does it need higher derivative continuity?  If the former is ok, then &lt;a href=&quot;https://en.wikipedia.org/wiki/Cubic_Hermite_spline&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cubic Hermite Splines&lt;/a&gt; will do the job. (If you need, they can be trivially mapped into cubic Beziers)&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2021-02-02T09:06:54.083" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10618" PostTypeId="1" CreationDate="2021-02-02T09:50:05.823" Score="0" ViewCount="29" Body="&lt;p&gt;Perhaps this is more computational geometry, but here goes:&lt;/p&gt;&#xA;&lt;p&gt;I have a 2D &lt;a href=&quot;https://en.wikipedia.org/wiki/Signed_distance_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;SDF&lt;/a&gt; describing my shape, but it's fine to think of it as a black/white image (black=&amp;quot;inside&amp;quot; white=&amp;quot;outside&amp;quot;).&lt;/p&gt;&#xA;&lt;p&gt;I want to generate a small set of rectangles (say, 8 of them) covering the image, which are allowed to overlap, and which minimize the amount of error. Error would be any leftover &amp;quot;black&amp;quot; areas of the image that are not covered.&lt;/p&gt;&#xA;&lt;p&gt;The image could be convex, have holes, etc. It is general.&lt;/p&gt;&#xA;&lt;p&gt;I realize that minimal rectangle covering is NP-hard, though that's not exactly what I'm asking for: I'm asking for minimizing error given a finite set of rectangles to work with. Maybe it's just as hard though; not sure.&lt;/p&gt;&#xA;&lt;p&gt;Anyway, I do not need to find the perfect solution; decent heuristics would be fine.&lt;/p&gt;&#xA;&lt;p&gt;I could imagine some pretty general &amp;quot;greedy search&amp;quot; traversal of the state space, but wondered if there were any tricks anyone knows of.&lt;/p&gt;&#xA;&lt;p&gt;Aside: I've also looked at several papers for &amp;quot;rectangular decomposition&amp;quot;, and &amp;quot;minimal dissection&amp;quot;, but those problems generally assume I want disjoint rectangles. Disjoint would be okay, but really I want maximal coverage while allowing overlap.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt; Here is an example:&lt;/p&gt;&#xA;&lt;p&gt;Target image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/0AGpl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/0AGpl.png&quot; alt=&quot;target image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Covering with 4 rectangles (red, green, blue, yellow):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/neYfG.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/neYfG.png&quot; alt=&quot;covered image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Any uncovered black pixels are the &amp;quot;error&amp;quot;.&#xA;No white pixels are allowed to get covered.&lt;/p&gt;&#xA;" OwnerUserId="13154" LastEditorUserId="13154" LastEditDate="2021-02-03T02:02:37.040" LastActivityDate="2021-02-03T02:02:37.040" Title="Good rectangular covering of an SDF" Tags="&lt;signed-distance-field&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10619" PostTypeId="1" CreationDate="2021-02-02T11:23:56.593" Score="1" ViewCount="52" Body="&lt;p&gt;I need to create a decaling into a surface like a mesh, and to avoid Z-fighting I've been using Stencil Buffer to Turn-off depth test and make the decaling over the surface the Stencil Op permits. In fact that decaling fails when we turn the camera in a such way that the viewer has more than one surface point &amp;quot;competing&amp;quot; for the same pixel. This happens when the surface isn't a plane, in our example we have a mesh representing a terrain. The problem is that we turn-off the depth test and the decaling object is always visible, even when we have a surface point closer to the camera. Is there someone here that had the same problem ? Do I have to quit stencil solution to avoid Z-fighting ?&lt;/p&gt;&#xA;&lt;p&gt;Without problem: &lt;a href=&quot;https://i.stack.imgur.com/3cGwK.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3cGwK.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The Problem: &lt;a href=&quot;https://i.stack.imgur.com/zhVEv.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zhVEv.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15679" LastEditorUserId="15679" LastEditDate="2021-02-03T11:24:01.233" LastActivityDate="2021-03-05T15:06:30.663" Title="Problem using Decaling with Stencil to avoid Z-fighting" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;z-buffer&gt;&lt;stencil-buffer&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10620" PostTypeId="1" AcceptedAnswerId="10657" CreationDate="2021-02-02T14:36:53.533" Score="0" ViewCount="45" Body="&lt;p&gt;I've been trying to link my the Intel Open Image Denoise libraries for about a week and still have no luck as of now. This could partly be because I am also novice in C++ stuff. So I need some help in getting it to work.&lt;/p&gt;&#xA;&lt;p&gt;Here's what I've done so far: after compiling OIDN I moved the oidn directory to the directory where my path tracer code is and did the following in my code (C++11) which I'm working on in Qt Creator.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;quot;oidn/include/OpenImageDenoise/oidn.hpp&amp;quot;&#xA;.&#xA;.&#xA;.&#xA;oidn::DeviceRef device = oidn::newDevice(); // this is where things break&#xA;device.commit();&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Note that doing &lt;code&gt;#include &amp;quot;oidn/include/OpenImageDenoise/oidn.hpp&amp;quot;&lt;/code&gt; seems to work fine because autocomplete works for oidn and shows its members. However I get the following errors which seems to be due to not linking oidn libraries.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/tyl6q.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/tyl6q.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I tried linking the libraries via &lt;code&gt;LIBS += -L&amp;quot;oidn/build/&amp;quot;&lt;/code&gt; or &lt;code&gt;LIBS += -L&amp;quot;oidn/build/libOpenImageDenoise.so&amp;quot;&lt;/code&gt; (as shown in the image) but I get the same errors. I also appended &lt;code&gt;-loidn&lt;/code&gt; but got an error saying &lt;code&gt;&amp;quot;cannot find -loidn&amp;quot;&lt;/code&gt;. I am now pretty confused on what I'm supposed to do. I'm not even sure if the errors are due to not properly linking libraries because I see people generally link libraries in C++ the same way I am trying to do it here. I would really appreciate if someone can help me figure out what I need to do to get OIDN work.&lt;/p&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2021-02-08T15:08:47.160" LastActivityDate="2021-02-10T14:34:29.107" Title="How to link Intel Open Image Denoise in Qt Creator and use it to denoise noisy Monte Carlo path tracing renderings?" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;pathtracing&gt;&lt;c++&gt;&lt;denoise&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10622" PostTypeId="1" AcceptedAnswerId="10623" CreationDate="2021-02-02T20:40:57.513" Score="0" ViewCount="49" Body="&lt;p&gt;Given a surface &lt;code&gt;Normal&lt;/code&gt; vector of an intersection point, how can one generate a random direction vector that is guaranteed to be in the visible hemisphere? The way I am currently doing this is to sample a random direction vector &lt;code&gt;d&lt;/code&gt; and &lt;code&gt;dot&lt;/code&gt; it with the &lt;code&gt;Normal&lt;/code&gt; and keep that vector if the &lt;code&gt;dot&lt;/code&gt; product is greater than 0. This method is not guaranteed to generate a vector in the visible hemisphere of BRDF as ~50% of the random vectors would have a &lt;code&gt;0&lt;/code&gt; or negative &lt;code&gt;dot&lt;/code&gt; product result.&lt;/p&gt;&#xA;&lt;p&gt;I saw somewhere that there is a way to transform the randomly generated vector &lt;code&gt;d&lt;/code&gt; to place it in the visible hemisphere using a transformation matrix but I don't know how to do it. Can someone write a [pseudo]code for how one generate a direction vector using the transformation method?&lt;/p&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2021-02-02T20:50:28.557" LastActivityDate="2021-02-02T21:37:58.557" Title="Path tracing: How to ensure we are sampling a direction vector within the visible hemisphere of a surface?" Tags="&lt;rendering&gt;&lt;transformations&gt;&lt;pathtracing&gt;&lt;brdf&gt;&lt;pbr&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10623" PostTypeId="2" ParentId="10622" CreationDate="2021-02-02T20:57:33.453" Score="1" Body="&lt;p&gt;If it’s on the wrong side of the normal, you don’t have to throw it away—negating it will give you a vector that’s in the visible hemisphere.&lt;/p&gt;&#xA;&lt;p&gt;Answering your comment, to get a vector that’s within some angle θ of the normal, this should work (GLSL):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 direction(vec3 normal, vec2 randomValues, float maxTheta) {&#xA;    // pick an orthogonal tangent vector using the method described here: http://lolengine.net/blog/2013/09/21/picking-orthogonal-vector-combing-coconuts&#xA;    vec3 tangent = (normal.x &amp;gt; normal.z) ? vec3(-normal.y, normal.x, 0.0) : vec3(0.0, -normal.z, normal.y);&#xA;    // and a bitangent vector orthogonal to both&#xA;    vec3 bitangent = cross(normal, tangent);&#xA;&#xA;    float phi = 2.0 * PI * randomValues.x;&#xA;    float theta = randomValues.y * maxTheta;&#xA;    float sinTheta = sin(theta);&#xA;    return tangent * cos(phi) * sinTheta + bitangent * sin(phi) * sinTheta + normal * cos(theta);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="506" LastEditorUserId="506" LastEditDate="2021-02-02T21:37:58.557" LastActivityDate="2021-02-02T21:37:58.557" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10624" PostTypeId="1" CreationDate="2021-02-03T01:30:49.097" Score="0" ViewCount="38" Body="&lt;p&gt;Given the BSDF function and the &lt;code&gt;Normal&lt;/code&gt; vector of the intersection point &lt;strong&gt;in world space&lt;/strong&gt;, how can I generate a new direction vector &lt;code&gt;wi&lt;/code&gt; that is valid? Does the method for generating valid &lt;code&gt;wi&lt;/code&gt;s change based on the BSDF?&lt;/p&gt;&#xA;&lt;p&gt;Here's an example of what I'm thinking to do for ideal diffuse material the BSDF: I generate a new direction vector &lt;code&gt;wi&lt;/code&gt; as points on a unit hemisphere as follow and then compute the &lt;code&gt;dot&lt;/code&gt; product of the produced vector with the &lt;code&gt;Normal&lt;/code&gt; vector. If the &lt;code&gt;dot&lt;/code&gt; product result is positive the direction vector &lt;code&gt;wi&lt;/code&gt; is valid. Otherwise I negate &lt;code&gt;wi&lt;/code&gt; as suggested &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10622/path-tracing-how-to-ensure-we-are-sampling-a-direction-vector-within-the-visibl&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Here's how I get a random &lt;code&gt;wi&lt;/code&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float theta = 2 * M_PI * uniform01(generator);&#xA;float phi = acos(uniform01(generator));&#xA;float x = sin(phi) * cos(theta);&#xA;float y = sin(phi) * sin(theta);&#xA;float z = cos(phi);&#xA;Vector3f wi(x, y, z);&#xA;&#xA;if (dot(wi, Normal) &amp;gt; 0){&#xA;    return wi;&#xA;}&#xA;else{&#xA;    return -wi;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However, this doesn't seem to be the right approach based on a conversation I had with someone recently. Apparently the new direction vector produced this way is somehow not in the right space (not sure whether it was world or object space) and could only work if my material is ideal diffuse. So I will have to apply some transformations in order to be able to get the right &lt;code&gt;wi&lt;/code&gt;. Is this correct? If so, can someone provide a solution that includes doing such t transformation? Also, is there a general way to ensure all of my produced &lt;code&gt;wi&lt;/code&gt;s are valid with respect to any BSDF (not just ideal diffuse)? Would this method be the same in importance sampling?&lt;/p&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2021-02-03T04:53:44.177" LastActivityDate="2021-02-03T04:53:44.177" Title="Path tracing: how to ensure the new direction vector is a valid direction vector with respect to a BSDF?" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;c++&gt;&lt;brdf&gt;&lt;physically-based&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10625" PostTypeId="2" ParentId="10613" CreationDate="2021-02-03T05:35:57.397" Score="0" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Now, we can write this direction vector in homogeneous form and apply the camera to world transformation. This should give us the direction vector for the ray in world space.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;That is the problem. When transforming a &lt;em&gt;direction&lt;/em&gt;, you must ensure the &lt;code&gt;w&lt;/code&gt; coordinate is 0, so that it doesn't get translated by your camera-to-world matrix. What you're doing in the second method is that you're transforming the direction vector as a point, and then subtracting the camera's position, which effectively undoes the translation.&lt;/p&gt;&#xA;" OwnerUserId="15470" LastActivityDate="2021-02-03T05:35:57.397" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10626" PostTypeId="2" ParentId="10619" CreationDate="2021-02-03T14:37:31.590" Score="0" Body="&lt;p&gt;It sounds like this code is using the stencil buffer to mask off the locations to draw the line. This isn't a &amp;quot;typical&amp;quot; decal approach. Normally the decal is draw directly into the scene and &amp;quot;depth bias&amp;quot; is turned on for the graphics state (OpenGL) or the graphics pipeline (Vulkan). Then turned off when done, again for OpenGL.&lt;/p&gt;&#xA;&lt;p&gt;A solution that doesn't change the current rendering approach (which i guessed at) is to use a depth buffer when rendering the terrain. Then pass that depth buffer as an input to your decal shader, read the depth buffer and compare it to the depth of your current fragment. Then discard the fragment if the depth test fails. Basically, it is doing depth buffering by hand. It isn't to hard to set up and there are lots of tutorials out there to help get you going.&lt;/p&gt;&#xA;&lt;p&gt;It also might be possible to just change the stencil buffer based on depth values this would be dependent on how the stencil is being generated. If it is regenerated each frame this could be a quick and easy solution.&lt;/p&gt;&#xA;&lt;p&gt;On the other hand, if you are drawing lines or polygons directly, then you really should look into using depth bias settings. Assuming you are using OpenGL this is turned on before rendering the decal then turned off after rendering it. The hardware then computes an offset depending on how far the camera is away from the object up to some limit (which is also programable). This approach would allow the depth testing to be left on, it is view independent so it works from any direction, and it would allow the decal to be textured.&lt;/p&gt;&#xA;&lt;p&gt;Also: The issue described here isn't really z fighting. Z fighting usually occurs when two fragments are being rendered to the same location and quantization causes the fragments to &amp;quot;fight&amp;quot; for visibility. As the camera moves one of the two fragments wins the &amp;quot;fight&amp;quot;, but the winner keeps changing depending how much floating point error there is.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-02-03T14:50:04.190" LastActivityDate="2021-02-03T14:50:04.190" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10627" PostTypeId="1" CreationDate="2021-02-03T15:08:39.200" Score="0" ViewCount="17" Body="&lt;p&gt;When having a high number of identical meshes one could use instanced arrays to avoid gpu call overhead. For instance if we want to draw lots of cubes with the same dimensions with different transformations we could do that with instancing. However what if we have lots of cubes with varying dimensions. And say that cubes' dimensions are dictated by some parameters, ex minimal A and maximum B coordinates. In this particular situation maybe there's a solution with modifying cube's dimensions with a matrix. But what if we have instead a cylinder or capsule. Is the only approach here to load all the cube vertices to buffer as a single mesh? Or are there more advanced approaches in OpenGL?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2021-02-04T12:19:09.203" LastActivityDate="2021-02-04T12:19:09.203" Title="OpenGL batch drawing debug meshes with varying dimensions" Tags="&lt;opengl&gt;&lt;instance&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10628" PostTypeId="1" AcceptedAnswerId="10631" CreationDate="2021-02-03T15:19:30.807" Score="1" ViewCount="35" Body="&lt;p&gt;I want to render a scene from multiple positions and orientations. I think the geometry shader is a good choice to not use the Vertex and tessellation shaders for each camera position again. So I want to do layered rendering. I already did that once, but this time I simultaneously want to use additional clip planes. Each camera position has its own clip planes, which should not be visible from other cameras.&#xA;My question: is it possible to define clipPlanes (glClipPlane) for a specific layer? Or is it better to do that during the fragment shader step, by doing dot-product, check the sign and discard if necessary?&#xA;Does I have other options (except: rendering the scene in a loop for each position / orientation)?&lt;/p&gt;&#xA;&lt;p&gt;Thanks a lot!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2021-02-04T14:27:07.443" Title="OpenGL layered rendering with multiple additional clip planes per view" Tags="&lt;opengl&gt;&lt;clipping&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10629" PostTypeId="2" ParentId="10604" CreationDate="2021-02-03T15:30:15.483" Score="0" Body="&lt;p&gt;I spent many years doing hardware work creating CPU's for the &amp;quot;big iron&amp;quot; market. We considered a FLOP to be any instruction that requires the &amp;quot;floating point execution unit&amp;quot; inside the CPU to perform the calculation that another instruction has a dependency on. This unit used to be considered one of the most complex, slowest, and one of the most power hungry units inside the CPU. It could result in long stalls, lots of NOPS being inserted into the pipeline, lots of heat being generated, and the electric bill to go sky high.&lt;/p&gt;&#xA;&lt;p&gt;Much research later, the floating point units are much less power hungry, and can often be compared to the performance of a good integer execution unit. (last I heard research was combining the two into a flexible integer/floating unit)&lt;/p&gt;&#xA;&lt;p&gt;This all lead to measuring how many FLOPS a CPU (and nowadays the GPU) can perform in any given second, and more generally an entire system with many CPU's and GPU's working together. This measurement is still relevant because GPU's have turned number crunching into a fine art and while throughput is often dependent on memory architecture the raw number of FLOPs still tends to be a good measurement but can be very workflow dependent.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-02-03T15:30:15.483" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10630" PostTypeId="1" CreationDate="2021-02-03T18:37:12.250" Score="0" ViewCount="30" Body="&lt;p&gt;Given a ray and a cube, how do I calculate the two intersections between them in terms of distance along the ray. Would be good if the results would be NaN or Infinity if they do not intersect. So far I could only find ways to either calculate the world coordinates of their intersection or the distance between the ray origin and the box. Any help would be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="15650" LastActivityDate="2021-02-03T18:37:12.250" Title="Calculate Ray-Box intersections in terms of distance" Tags="&lt;raytracing&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10631" PostTypeId="2" ParentId="10628" CreationDate="2021-02-03T21:49:28.497" Score="3" Body="&lt;p&gt;The GS is responsible for assigning a particular primitive to a particular layer. The GS is also responsible for writing values for &lt;code&gt;gl_ClipDistance&lt;/code&gt; for a particular primitive. So the GS is perfectly capable of doing both of those things: assigning a primitive to a layer and doing the clip-plane computations for that layer.&lt;/p&gt;&#xA;&lt;p&gt;And if you need to &amp;quot;deactivate&amp;quot; a clip plane for a particular primitive assigned to a particular layer, just assign the &lt;code&gt;gl_ClipDistance[i]&lt;/code&gt; for that to 1.0 for all of its vertices.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2021-02-04T14:27:07.443" LastActivityDate="2021-02-04T14:27:07.443" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10633" PostTypeId="1" CreationDate="2021-02-04T00:03:52.813" Score="0" ViewCount="31" Body="&lt;p&gt;I've been playing around with an idea, but I'm struggling with some of the math involved.&lt;/p&gt;&#xA;&lt;p&gt;Now, each face of a mesh has a normal vector, and that the normal map fragment shader modifies that face normal, based on the RBG pixel of the normal map. This, in turn modifies the brightness of a rendered mesh, giving the impression of height and depth. Correct me if I'm mistaken, of course.&lt;/p&gt;&#xA;&lt;p&gt;So, based on this, if you managed to split up a mesh, to add extra edges that correspond to individual pixel boundaries - with each boundary containing portions of one or more of the original faces, you could then apply the normal modification of the corresponding normal map's pixel, as rotation.&lt;/p&gt;&#xA;&lt;p&gt;Then, it would simply be a matter of reconnecting the vertices, to make the mesh cohesive again&lt;/p&gt;&#xA;&lt;p&gt;While I can find plenty of sources on how normal maps affect the normal vectors of a mesh, I'm a bit lost on how to take that effect, and apply it to physically rotating the face, so the original normal vector matches its modified vector.&lt;/p&gt;&#xA;" OwnerUserId="15690" LastActivityDate="2021-02-04T00:03:52.813" Title="How do I figure rotation from the difference between two vectors?" Tags="&lt;mathematics&gt;&lt;vectors&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10634" PostTypeId="1" CreationDate="2021-02-04T10:02:55.007" Score="0" ViewCount="82" Body="&lt;p&gt;&lt;strong&gt;Background:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I am extracting the textures for a model with Assimp and sampling those textures in the fragment shader.  I have multiple &lt;code&gt;uniform sampler2D textureN&lt;/code&gt; declarations in my fragment shader and call &lt;code&gt;glUniform1i(location, textureN)&lt;/code&gt;, &lt;code&gt;glActiveTexture(GL_TEXTUREN)&lt;/code&gt; and &lt;code&gt;glBindTexture(GL_TEXTURE_2D, textureN_ref)&lt;/code&gt; for each texture.  This is working correctly.&lt;/p&gt;&#xA;&lt;p&gt;The following Mesh drawing function from &lt;a href=&quot;https://learnopengl.com/Model-Loading/Mesh&quot; rel=&quot;nofollow noreferrer&quot;&gt;learnopengl.com&lt;/a&gt; binds multiple textures.  However, as shown below, the fragment shader only contains one sampler.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void Draw(Shader &amp;amp;shader) &#xA;{&#xA;    unsigned int diffuseNr = 1;&#xA;    unsigned int specularNr = 1;&#xA;    for(unsigned int i = 0; i &amp;lt; textures.size(); i++)&#xA;    {&#xA;        glActiveTexture(GL_TEXTURE0 + i); // activate proper texture unit before binding&#xA;        // retrieve texture number (the N in diffuse_textureN)&#xA;        string number;&#xA;        string name = textures[i].type;&#xA;        if(name == &amp;quot;texture_diffuse&amp;quot;)&#xA;            number = std::to_string(diffuseNr++);&#xA;        else if(name == &amp;quot;texture_specular&amp;quot;)&#xA;            number = std::to_string(specularNr++);&#xA;&#xA;        shader.setFloat((&amp;quot;material.&amp;quot; + name + number).c_str(), i);&#xA;        glBindTexture(GL_TEXTURE_2D, textures[i].id);&#xA;    }&#xA;    glActiveTexture(GL_TEXTURE0);&#xA;&#xA;    // draw mesh&#xA;    glBindVertexArray(VAO);&#xA;    glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_INT, 0);&#xA;    glBindVertexArray(0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Fragment shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 330 core&#xA;out vec4 FragColor;&#xA;&#xA;in vec2 TexCoords;&#xA;&#xA;uniform sampler2D texture_diffuse1;&#xA;&#xA;void main()&#xA;{    &#xA;    FragColor = texture(texture_diffuse1, TexCoords);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Surely for the &lt;code&gt;void Draw(Shader &amp;amp;shader)&lt;/code&gt; function to work you would have to define multiple samplers in the fragment shader?  The linked article does in fact seem to state this in the paragraph prior to the function.&lt;/p&gt;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="15694" LastActivityDate="2021-02-04T10:02:55.007" Title="Using multiple textures in a shader" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;texture&gt;&lt;c++&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10636" PostTypeId="1" AcceptedAnswerId="10637" CreationDate="2021-02-04T15:01:55.113" Score="0" ViewCount="131" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/gG0bE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/gG0bE.png&quot; alt=&quot;Here's an example&quot; /&gt;&lt;/a&gt;&#xA;I want to try making small clips with realistic environment with the lighting in the KDA music video...&#xA;Any ideas what kind of program to use?&lt;/p&gt;&#xA;" OwnerUserId="15697" LastEditorUserId="15697" LastEditDate="2021-02-04T15:15:51.523" LastActivityDate="2021-02-04T19:08:32.987" Title="What software was used to make KDA - Villain?" Tags="&lt;3d&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10637" PostTypeId="2" ParentId="10636" CreationDate="2021-02-04T19:08:32.987" Score="1" Body="&lt;p&gt;The video was created by a studio called Trizz; you can see their page about the project &lt;a href=&quot;https://www.trizz.tv/portfolio/kdavillain&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. The site doesn’t have any information about what software they used, but you can achieve this look (with enough work) in pretty much any modern renderer. If you use &lt;a href=&quot;https://blender.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender&lt;/a&gt;, &lt;a href=&quot;https://www.cycles-renderer.org&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cycles&lt;/a&gt; is a good one; with other 3D software, &lt;a href=&quot;https://redshift3d.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Redshift&lt;/a&gt;, &lt;a href=&quot;https://home.otoy.com/render/octane-render/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Octane&lt;/a&gt;, and &lt;a href=&quot;https://arnoldrenderer.com&quot; rel=&quot;nofollow noreferrer&quot;&gt;Arnold&lt;/a&gt; are popular options.&lt;/p&gt;&#xA;&lt;p&gt;If you’re also looking to make the kind of physics-based animation—cloth, fire, snakes, etc.—that appears in the video, you’ll probably also want to check out &lt;a href=&quot;https://www.sidefx.com/products/houdini/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Houdini&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-02-04T19:08:32.987" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10639" PostTypeId="1" AcceptedAnswerId="10640" CreationDate="2021-02-05T00:11:49.530" Score="0" ViewCount="15" Body="&lt;p&gt;I'm trying to plot some points along a 3D line segment and could really use some help. In 2D, I've found success getting the angle of the line, the sine &amp;amp; cosine of the angle, and then adding the cosine &amp;amp; sine to the starting point of the line's x &amp;amp; y respectively.&lt;/p&gt;&#xA;&lt;p&gt;In 3D I think I'm getting the angle correctly and thus x &amp;amp; y using cosine and sine, but I'm not sure what to do for z. Can anyone please advise on how this is derived? Thank you!&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-python prettyprint-override&quot;&gt;&lt;code&gt;def GetAngle(line):&#xA;    fCrossX = line.p1.y * line.p2.z - line.p1.z * line.p2.y&#xA;    fCrossY = line.p1.z * line.p2.x - line.p1.x * line.p2.z&#xA;    fCrossZ = line.p1.x * line.p2.y - line.p1.y * line.p2.x&#xA;    fCross = math.sqrt(fCrossX * fCrossX +&#xA;        fCrossY * fCrossY + fCrossZ * fCrossZ)&#xA;    fDot = line.p1.x * line.p2.x + line.p1.y * line.p2.y + line.p1.z + line.p2.z&#xA;    return math.atan2(fCross, fDot)&#xA;&#xA;v1 = Vector(100,0,0)&#xA;v2 = Vector(500,0,0)&#xA;line = Line(v1,v2)&#xA;angle = GetAngle(line)&#xA;sin = math.sin(angle)&#xA;cos = math.cos(angle)&#xA;points = list()&#xA;for i in range(int(line.length)):&#xA;    x = line.p1.x+(cos*i)&#xA;    y = line.p1.y+(sin*i)&#xA;    # what do I do for z???&#xA;    pt = Vector(x,y)&#xA;    points.append(pt)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="14079" LastActivityDate="2021-02-05T01:09:59.500" Title="Plotting points along a 3D line segment" Tags="&lt;3d&gt;&lt;mathematics&gt;&lt;vectors&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10640" PostTypeId="2" ParentId="10639" CreationDate="2021-02-05T01:09:59.500" Score="1" Body="&lt;p&gt;You shouldn’t need to use any trigonometry here at all. If you get the vector from v1 to v2 and divide it by the number of points you want along the line, each subsequent point is v1 + (that vector) × (the index of the point). Works in any number of dimensions, faster than the trigonometric approach.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;v1 = Vector(100, 200, 300)&#xA;v2 = Vector(500, 400, 300)&#xA;steps = 25 # or however many subdivisions you want: int(length(Line(v1, v2))) if you want an equivalent to the original&#xA;stepAmount = Vector((v2.x - v1.x) / steps, (v2.y - v1.y) / steps, (v2.z - v1.z) / steps)&#xA;points = list()&#xA;for i in range(steps + 1)&#xA;    x = v1.x + stepAmount.x * i&#xA;    y = v1.y + stepAmount.y * i&#xA;    z = v1.z + stepAmount.z * i&#xA;    points.append(Vector(x, y, z))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-02-05T01:09:59.500" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10641" PostTypeId="1" AcceptedAnswerId="10642" CreationDate="2021-02-05T10:15:33.203" Score="0" ViewCount="28" Body="&lt;p&gt;Is there a way to influence the behavior of &lt;code&gt;imageLoad()&lt;/code&gt; for accessing an &lt;code&gt;image2D&lt;/code&gt; or &lt;code&gt;uimage2D&lt;/code&gt; with an out-of-bounds texel coordinate; for example repeat the last &lt;em&gt;good&lt;/em&gt; texel instead of returning 0s?&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2021-02-05T14:43:00.280" Title="imageLoad() behavior for non-existent texel" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;vulkan&gt;&lt;image-load-store&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10642" PostTypeId="2" ParentId="10641" CreationDate="2021-02-05T14:43:00.280" Score="1" Body="&lt;p&gt;No. When you use image load/store, you don't get to play &amp;quot;texture&amp;quot; games like playing with the border color, doing filtering on values, etc. You are fetching a texel from a particular location.&lt;/p&gt;&#xA;&lt;p&gt;If you want this, you will have to detect the out-of-bounds access and choose to substitute an alternate value. You can query the image's size, so it should be easy enough to detect.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-02-05T14:43:00.280" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10645" PostTypeId="1" CreationDate="2021-02-06T15:19:04.663" Score="0" ViewCount="37" Body="&lt;p&gt;I am not sure if I understood it correctly, but OpenGL is high-level like Java and Metal is low-level like Assembly, aren't they? Apple seems to have abandoned OpenGL in favour of Metal, but there still are a few popular applications that use OpenGL like Blender. I think I have read that because of Apple's lack of support for OpenGL, Blender development is hindered.&lt;/p&gt;&#xA;&lt;p&gt;Then, I wondered if some developers could implement an OpenGL library using Metal, and Blender could use that library. Then the developers of individual applications like Blender would not have to waste their time rewriting the applications in Metal. Is that kind of library plausible? I have searched Google for that, but all I could find was an OpenGL-ES-to-Metal project. I don't know whether OpenGL and OpenGL ES have similar architecture or not, so I am not sure the existence of that library means such a library for OpenGL is possible or not.&lt;/p&gt;&#xA;" OwnerUserId="15710" LastActivityDate="2021-02-06T15:19:04.663" Title="Is OpenGL to Metal translation layer plausible?" Tags="&lt;opengl&gt;&lt;metal&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10646" PostTypeId="1" AcceptedAnswerId="10668" CreationDate="2021-02-06T20:03:34.343" Score="1" ViewCount="61" Body="&lt;p&gt;I've come across this problem several times now and I can't really understand what causes it; my background is in Wordpress, not really in computer graphics.&lt;/p&gt;&#xA;&lt;p&gt;I hope this is the right place to ask, I was in doubt with &lt;a href=&quot;https://graphicdesign.stackexchange.com/&quot;&gt;https://graphicdesign.stackexchange.com/&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I have a big initial image, say 1500x1017 at 300ppi, 566 KB. I upload it in my Wordpress site: the browser resizes it to a fixed width that depends on the site (in this case 718px), and it looks nice and crispy. See two screenshots.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BgeBR.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BgeBR.jpg&quot; alt=&quot;Crispy image, resized by the browser&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/qTZpJ.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qTZpJ.jpg&quot; alt=&quot;Browser resizing&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In general you don't want to upload oversized images and let the browser do the resizing for you: I'm sure everybody here is familiar with the concept of &lt;a href=&quot;https://gtmetrix.com/serve-scaled-images.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Serving scaled images&lt;/a&gt; to optimise site performance. In a few words,&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Serving appropriately-sized images can save many bytes of data and improve the performance of your webpage, especially on low-powered (eg. mobile) devices.&#xA;You should use an image editor to scale images to match the largest size needed in your page.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Enter Photoshop (or &lt;code&gt;sips&lt;/code&gt; or any other resizing tool). I open the image, resize it to 718px width, save &lt;strong&gt;without optimisation&lt;/strong&gt;, i.e. to max &lt;code&gt;jpg&lt;/code&gt; quality. I would expect this image to look as crispy as the big one once uploaded: I am just doing the resizing instead of letting the browser do it, right?&lt;/p&gt;&#xA;&lt;p&gt;Not quite. The image's size matches the displayed size, but the image looks blurry.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/kNIKR.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kNIKR.jpg&quot; alt=&quot;Blurry image, intrinsic width = displayed width&quot; /&gt;&lt;/a&gt;&#xA;&lt;a href=&quot;https://i.stack.imgur.com/SO3AA.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/SO3AA.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;What's the deal? Am I resizing with the wrong procedure? Is this about Wordpress media management with its billion of thumbnails?&lt;/p&gt;&#xA;" OwnerUserId="15714" LastActivityDate="2021-02-14T23:52:47.483" Title="Why is browser-resized image crispy and manually-resized image blurry?" Tags="&lt;transformations&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10647" PostTypeId="1" AcceptedAnswerId="10651" CreationDate="2021-02-07T09:44:15.120" Score="-1" ViewCount="41" Body="&lt;p&gt;I don't really know where I should ask this, so I decided to come here.&#xA;I want to send multiple 3D files to several computers to render, and for that I need to approximately determine when each system will finish the render operation (I know the stats of the computers).&#xA;My question is, based on any information you could get from a system (CPU, GPU, OS, ...),&#xA;is it possible to determine (approximately) when the system will be done rendering a project?&#xA;(Assume we are talking about a specific software and project so that we can compare the cmputers).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt;&#xA;I'm looking for something like FLOPS, but I don't know how that would work in terms of rendering things.&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="15717" LastEditorUserId="15717" LastEditDate="2021-02-07T14:58:18.423" LastActivityDate="2021-02-08T14:10:42.177" Title="Efficiency of different Processors and GPUs" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10648" PostTypeId="1" AcceptedAnswerId="10660" CreationDate="2021-02-07T19:21:54.697" Score="0" ViewCount="50" Body="&lt;p&gt;I followed along with &lt;em&gt;Ray Tracing in One Weekend&lt;/em&gt; and managed to get the final output but I wanted to understand more about creating a camera and &amp;quot;painting&amp;quot; the screen since he didn't go over it much.&lt;/p&gt;&#xA;&lt;p&gt;When I tried using a different way of creating a camera by spheres actually get elongated, making them look like more like ellipses. I've tried modifying the x and y assignments in &lt;code&gt;screenCords&lt;/code&gt; but I've only managed to make more errors (such as objects wrapping around to the opposite side)&lt;/p&gt;&#xA;&lt;p&gt;Camera.h:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#pragma once&#xA;&#xA;#include &amp;quot;../Matrix.h&amp;quot;&#xA;#include &amp;quot;../Defs.h&amp;quot;&#xA;#include &amp;quot;Defs.h&amp;quot;&#xA;&#xA;template&amp;lt;typename O&amp;gt;&#xA;using Point3 = Vec3&amp;lt;O&amp;gt;;&#xA;&#xA;template&amp;lt;typename O&amp;gt;&#xA;using Color = Vec3&amp;lt;O&amp;gt;;&#xA;&#xA;template &amp;lt;typename O&amp;gt;&#xA;class Camera{&#xA;  O Height;&#xA;  O Width;&#xA;  Vec3&amp;lt;O&amp;gt; Forward, Right, Up;&#xA;  Point3&amp;lt;O&amp;gt; Origin;&#xA;&#xA;public:&#xA;  Camera(O fov, O aspect_ratio, Point3&amp;lt;O&amp;gt; origin, Point3&amp;lt;O&amp;gt; target, Vec3&amp;lt;O&amp;gt; upguide) {&#xA;    Height = atan(degrees_to_radians(fov));&#xA;    Width = Height * aspect_ratio;&#xA;    &#xA;    Origin = origin;&#xA;&#xA;    Forward = target - origin;&#xA;    Forward.normalize();&#xA;    Right = Forward.cross(upguide);&#xA;    Right.normalize();&#xA;    Up = Right.cross(Forward);&#xA;&#xA;    }&#xA;&#xA;    Ray&amp;lt;O&amp;gt; get_raydir(O right, O up){&#xA;      Vec3&amp;lt;O&amp;gt; result(Forward + right * Width * Right + up * Height * Up); result.normalize();&#xA;&#xA;      return Ray&amp;lt;O&amp;gt;(Origin, result);&#xA;    }&#xA;&#xA;    void screenCords(O &amp;amp;x, O &amp;amp;y, O width, O height){&#xA;      x = ((2.0f * x) / width) -1.0f;&#xA;      y = ((2.0f * y) / height); &#xA;    }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Main.cpp&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;cmath&amp;gt;&#xA;#include &amp;quot;../Matrix.h&amp;quot;&#xA;#include &amp;quot;Camera.h&amp;quot;&#xA;#include &amp;lt;vector&amp;gt;&#xA;#include &amp;quot;Image.h&amp;quot;&#xA;#include &amp;quot;Shapes.h&amp;quot;&#xA;#include &amp;quot;Tracer.h&amp;quot;&#xA;#include &amp;quot;../Defs.h&amp;quot;&#xA;&#xA;template&amp;lt;typename O&amp;gt;&#xA;using Point3 = Vec3&amp;lt;O&amp;gt;;&#xA;&#xA;template&amp;lt;typename O&amp;gt;&#xA;using Color = Vec3&amp;lt;O&amp;gt;;&#xA;&#xA;int main(){&#xA;  const int img_ratio = 2;&#xA;  const int img_width = 640;&#xA;  const int img_height = 480;&#xA;  const int depth = 50; float t_Max = infinity; float t_Min = 0.001;&#xA;&#xA;  float inv_width = 1 / float(img_width);&#xA;  float inv_height = 1 / float(img_height);&#xA;&#xA;  std::vector&amp;lt;Sphere&amp;lt;float&amp;gt;&amp;gt; shapes;&#xA;&#xA;  Camera&amp;lt;float&amp;gt; cam1(20.0f, img_ratio, Point3&amp;lt;float&amp;gt;(0.0f, 0.0f, 0.0f), Point3&amp;lt;float&amp;gt;(0.0f, 0.0f, -1.0f), Vec3&amp;lt;float&amp;gt;(0.0f, 1.0f, 0.0f));&#xA;&#xA;  Sphere&amp;lt;float&amp;gt; cir1(0.2f, Point3&amp;lt;float&amp;gt;(0.2f, 0.0f, -1.0f));&#xA;  Sphere&amp;lt;float&amp;gt; cir2(7.0f, Point3&amp;lt;float&amp;gt;(0.0f, -7.0f, -1.0f));&#xA;  Sphere&amp;lt;float&amp;gt; cir3(0.5f, Point3&amp;lt;float&amp;gt;(1.0f, 0.0f, -1.0f));&#xA;  shapes.push_back(cir1);&#xA;  //shapes.push_back(cir2);&#xA;  //shapes.push_back(cir3);&#xA;&#xA;  Tracer&amp;lt;float&amp;gt; tracer(shapes);&#xA;&#xA;  std::cout &amp;lt;&amp;lt; &amp;quot;P3\n&amp;quot; &amp;lt;&amp;lt; img_width &amp;lt;&amp;lt; ' ' &amp;lt;&amp;lt; img_height &amp;lt;&amp;lt; &amp;quot;\n255&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;&#xA;  Ray&amp;lt;float&amp;gt; ray(Point3&amp;lt;float&amp;gt;(0.0f), Vec3&amp;lt;float&amp;gt;(0.0f));&#xA;&#xA;  for (int j = 0; j &amp;lt; img_height; j++)&#xA;  {&#xA;    std::cerr &amp;lt;&amp;lt; &amp;quot;\rScanlines remaining: &amp;quot; &amp;lt;&amp;lt; j &amp;lt;&amp;lt; ' ' &amp;lt;&amp;lt; std::flush;&#xA;    for (int i = 0; i &amp;lt; img_width; i++){&#xA;&#xA;        float x = i;&#xA;        float y = j;&#xA;&#xA;        cam1.screenCords(x, y, img_width, img_height);&#xA;&#xA;        ray = cam1.get_raydir(x, y);&#xA;        //ray = Ray&amp;lt;float&amp;gt;(Vec3&amp;lt;float&amp;gt;(x1, y1, 1), Point3&amp;lt;float&amp;gt;(0.0f, 0.0f, 0.0f));&#xA;        tracer.iterator(ray, depth, t_Max, t_Min);&#xA;    }&#xA;  }&#xA;  std::cerr &amp;lt;&amp;lt; &amp;quot;\n done &amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I suspect the error is in one of these files since the spheres are actually being drawn with the colors based on normals (with the top and bottom normal colors unsurprisingly being bugged)&lt;/p&gt;&#xA;&lt;p&gt;Here are a few examples of the output:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/OFf42.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/OFf42.png&quot; alt=&quot;With one sphere centered at the origin&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Bj1GH.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Bj1GH.png&quot; alt=&quot;More spheres&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15723" LastActivityDate="2021-02-11T10:00:04.210" Title="(Ray tracing) Trouble converting to screen coordinates, objects being stretched" Tags="&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10649" PostTypeId="1" CreationDate="2021-02-07T20:13:31.027" Score="0" ViewCount="15" Body="&lt;p&gt;im looking for ways and ideas to create my own interior mapping textures for my open World Game.&#xA;Im unsure how to create them. Are there free sources available?&lt;/p&gt;&#xA;&lt;p&gt;best regards&lt;/p&gt;&#xA;&lt;p&gt;J&lt;/p&gt;&#xA;" OwnerUserId="15724" LastActivityDate="2021-02-07T20:13:31.027" Title="How to create interior Mapping textures or Cubemaps? UNITY 3D" Tags="&lt;texture&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10650" PostTypeId="1" CreationDate="2021-02-08T00:23:08.540" Score="0" ViewCount="9" Body="&lt;p&gt;I am working on getting bounding boxes from images using the GPU, I am using as an example &lt;a href=&quot;https://blog.demofox.org/2016/02/29/fast-voronoi-diagrams-and-distance-dield-textures-on-the-gpu-with-the-jump-flooding-algorithm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; article by demofox which has included some shadertoy examples. The JFA algorithm is like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt; channel 1: JFA steps&#xA;&#xA; vec4 load0(ivec2 p) {&#xA; vec2 uv = (vec2(p)-0.5) / iChannelResolution[0].xy;&#xA;     return texture(iChannel0, uv);&#xA; }&#xA;&#xA; void store(out vec4 t, vec4 v) {&#xA;     t = v;&#xA; }&#xA;&#xA; void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA; {&#xA;    float iter = mod(float(iFrame),13.0);&#xA;     if (iter &amp;lt; 0.5) {&#xA;     // init&#xA;     vec2 uv = fragCoord / iResolution.xy;&#xA;     uv.x = clamp(uv.x * iResolution.x / iResolution.y - 0.3, 0.0, 1.0);&#xA;     float ww = 40.0/256.0;&#xA;     vec4 color = texture(iChannel1, &#xA;        floor(mod(iTime * 5.0,6.0)) * vec2(ww,0.0) + vec2(ww,1.0) * uv);&#xA;     float lum = dot(color.rgb,vec3(0.299,0.587,0.114));&#xA;     if (lum &amp;lt; 0.4) {&#xA;         store(fragColor, vec4(fragCoord,0.0,0.0));&#xA;     } else {&#xA;         store(fragColor, vec4(0.0));&#xA;     }&#xA;     } else {&#xA;        // JFA step (for up to 4096x4096)&#xA;        float level = clamp(iter-1.0,0.0,11.0);&#xA;        int stepwidth = int(exp2(11.0 - level)+0.5);&#xA;    &#xA;        ivec2 tc = ivec2(fragCoord + 0.5);&#xA;    &#xA;       float best_dist = 999999.0;&#xA;       vec2 best_coord = vec2(0.0);&#xA;       vec2 center = vec2(tc);&#xA;       for (int y = -1; y &amp;lt;= 1; ++y) {&#xA;           for (int x = -1; x &amp;lt;= 1; ++x) {&#xA;               ivec2 fc = tc + ivec2(x,y)*stepwidth;&#xA;            vec2 ntc = load0(fc).xy;&#xA;              float d = length(ntc - center);&#xA;              if ((ntc.x != 0.0) &amp;amp;&amp;amp; (ntc.y != 0.0) &amp;amp;&amp;amp; (d &amp;lt; best_dist)) {&#xA;                  best_dist = d;&#xA;                  best_coord = ntc;&#xA;              }&#xA;          }&#xA;      }        &#xA;      store(fragColor,vec4(best_coord,0.0,0.0));&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Taken from user paniq's &lt;a href=&quot;https://www.shadertoy.com/view/4syGWK&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;My problem is being able to calculate a tile ID for each identified shape (this would allow me to get the bbox), a couple of things I have tried:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Do two passes, one to get the centroid of the identified shape and a second to run JFA from there.&lt;/li&gt;&#xA;&lt;li&gt;Try to get the min and max (similar to a bbox) by culling using logic/conditionals.&lt;/li&gt;&#xA;&lt;li&gt;When running JFA calculate the tile ID by flooring the best current coordinate and packing it in gl_FragCoord.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="9749" LastActivityDate="2021-02-08T00:23:08.540" Title="Calculating Bounding Boxes from JFA" Tags="&lt;glsl&gt;&lt;fragment-shader&gt;&lt;pixel-shader&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10651" PostTypeId="2" ParentId="10647" CreationDate="2021-02-08T14:10:42.177" Score="2" Body="&lt;p&gt;The answer to this question is: it depends.&lt;/p&gt;&#xA;&lt;p&gt;If the software is a black box that you have no control over then the best you will be able to do is measure wall clock run time on the host systems. That will give you general numbers in terms of wall clock time and is the most common way to gather this type of performance data. But will be affected by other processes running on the systems and a host of other variables. Repeated runs generally give better info.&lt;/p&gt;&#xA;&lt;p&gt;Making assumptions about CPU count isn't a good measure of expected performance because it depends heavily on the software. Will it utilize extra CPU's, will it have good cache coherency?&lt;/p&gt;&#xA;&lt;p&gt;You would be better off just gathering hardware data and comparing expected performance.&lt;/p&gt;&#xA;&lt;p&gt;From what you have describe doing both may be about as good as you will get. That is gather hardware data about the system, CPU, GPU, memory, etc. Run the render process as often as you can, such as render the same file 100 times in a loop measure how long it takes for each render operation, and take the average. Then use the combined info to make generalizations about similar hardware configurations.&lt;/p&gt;&#xA;&lt;p&gt;I've done this technique on server farms that had thousands of systems, all with similar hardware and gotten wildly different results. Measuring performance accurately is tricky business.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-02-08T14:10:42.177" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10653" PostTypeId="1" AcceptedAnswerId="10654" CreationDate="2021-02-09T05:12:28.817" Score="1" ViewCount="134" Body="&lt;p&gt;Is it possible to set the size of the shared memory of a compute shader workgroup from the host code? There is a way to do this in CUDA and I am suspecting that, since there is an GLSL extension to set the size of a workgroup during launch, there might be a way to do this, as the shared memory size is typically related to workgroup size.&lt;/p&gt;&#xA;" OwnerUserId="6496" LastActivityDate="2021-02-09T16:45:20.023" Title="GLSL Compute Shader Setting &quot;shared&quot; memory buffer size" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;vulkan&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10654" PostTypeId="2" ParentId="10653" CreationDate="2021-02-09T16:45:20.023" Score="3" Body="&lt;p&gt;GLSL has no mechanism to change the &amp;quot;size&amp;quot; of shared memory. Indeed, GLSL is &lt;em&gt;structurally&lt;/em&gt; incapable of such a thing.&lt;/p&gt;&#xA;&lt;p&gt;You can't get a pointer to shared memory. Indeed, &amp;quot;shared memory&amp;quot; doesn't really exist in GLSL; there are only shared &lt;em&gt;variables&lt;/em&gt;. And variables have a compile-time fixed size. So GLSL wouldn't even have a good way of allowing you to affect how much &amp;quot;shared memory&amp;quot; gets used from outside of the shader.&lt;/p&gt;&#xA;&lt;p&gt;The closest you might get to this is to have some kind of shared variable array whose size is determined from outside of the shader. But even then, you're not influencing the size of memory in total; you're influencing the size of just that &lt;em&gt;array&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;And you can sort of do that. SPIR-V in OpenGL allows specialization constants. These are values specified by the outside world during the compilation process for the shader object. Such constants can be used as the size for a shared variable array. Of course, this means that changing it requires a full recompile/relink process.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-02-09T16:45:20.023" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10655" PostTypeId="1" CreationDate="2021-02-09T19:55:43.373" Score="3" ViewCount="203" Body="&lt;p&gt;I'm trying to implement PCSS in OpenGL/GLSL, but I have problems understanding the details especially the conversions between the coordinate spaces. The existing implementations are so different from each other and I'm just more confused. I'm sure they all good implementations I just don't understand them.&lt;/p&gt;&#xA;&lt;h2&gt;Other implementations&lt;/h2&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/pboechat/PCSS&quot; rel=&quot;nofollow noreferrer&quot;&gt;pboechat's implementation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/diharaw/PercentageCloserSoftShadows&quot; rel=&quot;nofollow noreferrer&quot;&gt;diharaw's implementation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://github.com/asylum2010/Asylum_Tutorials/blob/master/Media/ShadersDX/shadow_pcf.fx&quot; rel=&quot;nofollow noreferrer&quot;&gt;asylum2010's implementation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;http://developer.download.nvidia.com/SDK/10.5/direct3d/samples.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Nvidia DirectX implementation&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;h2&gt;My implementation&lt;/h2&gt;&#xA;&lt;p&gt;In the vertex shader I don't do anything special, I just compute positions in different coordinate spaces.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;&#xA;layout(location=0) in vec3 i_position;&#xA;layout(location=1) in vec3 i_normal;&#xA;&#xA;uniform mat4 u_model;&#xA;uniform mat4 u_view;&#xA;uniform mat4 u_projection;&#xA;&#xA;uniform mat4 u_light_view;&#xA;uniform mat4 u_light_projection;&#xA;&#xA;out vec3 io_position;&#xA;out vec3 io_normal;&#xA;out vec4 io_lvs_position;&#xA;out vec4 io_lcs_position;&#xA;&#xA;void main(){&#xA;    io_position = vec3(u_model * vec4(i_position, 1.0));            //world space position&#xA;    gl_Position = u_projection * u_view * vec4(io_position, 1.0);   //clip space position&#xA;    io_normal = mat3(u_model) * i_normal;                           //world space normal&#xA;    io_lvs_position = u_light_view * vec4(io_position, 1.0);        //light view space position&#xA;    io_lcs_position = u_light_projection * io_lvs_position;         //light clip space position&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In the fragment shader I compute the shadow factor like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_pcss_shadow(){&#xA;    float search_region_width = compute_search_region_width();&#xA;    float average_blocker_depth = compute_average_blocker_depth(search_region_width);&#xA;    if(average_blocker_depth == -1.0){&#xA;        return 1.0;&#xA;    }&#xA;    float blocker_distance = compute_blocker_distance(average_blocker_depth);&#xA;    float penumbra_width = compute_penumbra_width(blocker_distance);&#xA;    float pcf_width = compute_pcf_width(penumbra_width);&#xA;    return compute_pcss(pcf_width);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I imagine the &lt;code&gt;compute_search_region_width&lt;/code&gt; function something like this:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/I0ks7.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/I0ks7.png&quot; alt=&quot;compute_search_region_width&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;We basically project the light's width into the near plane and we assume everything inside the triangle is a blocker. Because of the 2 similar triangles &lt;code&gt;search_region_width / u_light_width&lt;/code&gt; and &lt;code&gt;(lvs_distance - u_near_plane) / lvs_distance&lt;/code&gt; are equal, so I can compute &lt;code&gt;search_region_width&lt;/code&gt;. However 3 out of 4 implementations (except diharaw's) divide the light's width by the frustum's width. I think they do that to convert the width from light view space to the (0;1) interval because in the next function we'll use this value in texture space. But if it's true it makes more sense to me computing the width in light view space and then dividing, rather than dividing the light's width. This is my implementation:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_search_region_width(){&#xA;    float lvs_distance = -io_lvs_position.z;  //shaded point's distance from the light in light view space&#xA;    return u_light_size * (lvs_distance - u_near_plane) / lvs_distance / u_frustum_width;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;strong&gt;Am I right or wrong with that &lt;code&gt;u_frustum_width&lt;/code&gt; division?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;compute_average_blocker_depth&lt;/code&gt; function is just sampling the shadow map in the search region and averaging the blockers' depth.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_average_blocker_depth(float search_region_width){&#xA;    vec3 uv = io_lcs_position.xyz / io_lcs_position.w;  //conversion from clip space to NDC&#xA;    uv = uv * 0.5 + 0.5;                                //conversion from the (-1;1) interval to the (0;1)&#xA;    float real_depth = uv.z;&#xA;    int blocker_count = 0;&#xA;    float blocker_depth_sum = 0;&#xA;&#xA;    int step_count = u_kernel_size / 2;&#xA;    float step_uv = search_region_width / step_count;&#xA;    for(float x=-step_count;x&amp;lt;=step_count;x++){&#xA;        for(float y=-step_count;y&amp;lt;=step_count;y++){&#xA;            vec2 offset = vec2(x, y) * step_uv;&#xA;            float depth = texture(u_shadow_map, uv.xy + offset).r;&#xA;            if(depth &amp;lt; real_depth){&#xA;                blocker_count++;&#xA;                blocker_depth_sum += depth;&#xA;            }&#xA;        }&#xA;    }&#xA;    if(blocker_count == 0){&#xA;        return -1.0;&#xA;    }else{&#xA;        return blocker_depth_sum / blocker_count;&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In the &lt;code&gt;compute_blocker_distance&lt;/code&gt; function we convert the average blocker depth from the (0;1) interval to light view space. My implementation is pretty simple and similar to diharaw's and asylum2010's implementation.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_blocker_distance(float average_blocker_depth){&#xA;    return average_blocker_depth * (u_far_plane - u_near_plane) + u_near_plane;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However in pboechat's implementation this step is completely missing and in the Nvidia implementation it looks like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float ZClipToZEye(float zClip)&#xA;{&#xA;    return g_LightZFar*g_LightZNear / (g_LightZFar - zClip*(g_LightZFar-g_LightZNear));   &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This piece of code doesn't make any sense to me, maybe this is because this is the only HLSL code.&lt;/p&gt;&#xA;&lt;p&gt;In the &lt;code&gt;compute_penumbra_width&lt;/code&gt; function we determine the shadow penumbra's width in light view space, again based on similar triangles. This is how I imagine it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ESJDg.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ESJDg.png&quot; alt=&quot;compute_penumbra_width&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Because &lt;code&gt;penumbra_width / u_light_width&lt;/code&gt; and &lt;code&gt;(lvs_distance - average_blocker_depth) / average_blocker_depth&lt;/code&gt; are equal, we can compute &lt;code&gt;penumbra_width&lt;/code&gt; in light view space. My implementation is similar to asylum2010' and the Nvidia implementation:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_penumbra_width(float blocker_distance){&#xA;    float lvs_distance = -io_lvs_position.z; //shaded point's distance from the light in light view space&#xA;    return u_light_size * (lvs_distance - blocker_distance) / blocker_distance / u_frustum_width;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm not entirely sure why we divide by the frustum width, but later we'll use the result in texture space rather than in light view space, so maybe this is that conversion again. In pboechat's implementation we use the shaded point's depth in the (0;1) interval, not the distance in light view space, which doesn't make any sense to me. In diharaw's implementation the computation is something like this: &lt;code&gt;abs(zReceiver - zBlocker) / zBlocker&lt;/code&gt; and I don't understand it.&lt;/p&gt;&#xA;&lt;p&gt;The &lt;code&gt;compute_pcf_width&lt;/code&gt; is the function what I don't understand at all. At this point I think &lt;code&gt;penumbra_width&lt;/code&gt; is in texture space because of the division by &lt;code&gt;u_frustum_width&lt;/code&gt;. So what's the point of more conversions? But this is the point where the other implementations are very similar. Multiply the penumbra's width with the near plane and then divide by the shaded point's light view space distance (in pboechat's implementation divide by the depth). My implementation is like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_pcf_width(float penumbra_width){&#xA;    vec3 uv = io_lcs_position.xyz / io_lcs_position.w;  //conversion from clip space to NDC&#xA;    uv = uv * 0.5 + 0.5;                                //conversion from the (-1;1) interval to the (0;1)&#xA;    float real_depth = uv.z;&#xA;    return penumbra_width * u_near_plane / real_depth;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm using the depth and not the light view space distance, because it looks better, but I don't understand the multiplication and the division in this function. &lt;strong&gt;So what is the point of the &lt;code&gt;compute_pcf_width&lt;/code&gt; function and how to implement it properly?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;The last function, &lt;code&gt;compute_pcss&lt;/code&gt; is a variable kernel sized PCF filter.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float compute_pcss(float pcf_width){&#xA;    vec3 uv = io_lcs_position.xyz / io_lcs_position.w;&#xA;    uv = uv * 0.5 + 0.5;&#xA;    float real_depth = uv.z;&#xA;    float result = 0;&#xA;&#xA;    int step_count = u_kernel_size / 2;&#xA;    float step_uv = pcf_width / step_count;&#xA;    for(float x=-step_count;x&amp;lt;=step_count;x++){&#xA;        for(float y=-step_count;y&amp;lt;=step_count;y++){&#xA;            vec2 offset = vec2(x, y) * step_uv;&#xA;            float depth = texture(u_shadow_map, uv.xy + offset).r + bias;&#xA;            if(depth &amp;gt; real_depth){&#xA;                result += 1.0;&#xA;            }else{&#xA;                result += 0.5;&#xA;            }&#xA;        }&#xA;    }&#xA;    return result / (u_kernel_size * u_kernel_size);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is the result with &lt;code&gt;u_kernel_size = 27&lt;/code&gt;:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/pj2Ia.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pj2Ia.png&quot; alt=&quot;PCSS shadow&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The shadow is getting blurrier with distance, but the edge of the shadow looks a little strange. Also you can see some sort of issue on the right side, maybe blurred shadow acne. &lt;strong&gt;So if you read all this, please tell me what is the correct implementation of PCSS and why.&lt;/strong&gt;&lt;/p&gt;&#xA;" OwnerUserId="15740" LastActivityDate="2021-02-09T19:55:43.373" Title="How to implement PCSS correctly?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;glsl&gt;&lt;mathematics&gt;&lt;shadow&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10656" PostTypeId="1" CreationDate="2021-02-10T07:56:46.753" Score="0" ViewCount="23" Body="&lt;p&gt;Is there an efficient method to apply 2D point/polygon algorithms on general planar points. For example, I need to triangulate a polygon where the input is a list of ordered points. The algorithm considers that the points are on the XY plane. But to make it more general I would like it to work for polygons in any arbitrary plane. The naïve approach which I could come up with is to represent each and every point in its local polygon plane using a for loop and then triangulate after which I would represent the triangles back in the world coordinate system. To give more background to the question, this is part of a geometry library I am working on which is written in C# and I am looking to solve geometry problems without using any external geometry libraries. The polygon is represented as a degree 1 NURBS curve and hence the control points represent the vertices and the &lt;code&gt;Polygon&lt;/code&gt; class is derived from the &lt;code&gt;NURBSCurve&lt;/code&gt; class. Considering the following structure, is there any efficient way to implement 2D polygon algorithms for polygons in arbitrary plane.&lt;/p&gt;&#xA;" OwnerUserId="15742" LastActivityDate="2021-02-10T07:56:46.753" Title="Using 2D point/polygon algorithms on polygons lying on a arbitrary plane" Tags="&lt;transformations&gt;&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;polygon&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10657" PostTypeId="2" ParentId="10620" CreationDate="2021-02-10T14:34:29.107" Score="0" Body="&lt;p&gt;All the previous answers/comments were correct. The weird thing about my case was the symlinks of the libraries in the &lt;code&gt;build&lt;/code&gt; directory were not valid and were not pointing to the right files. The output of &lt;code&gt;ls -lh /home/Warrior/Desktop/pathtracer/oidn/build&lt;/code&gt; was as follow:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;total 160K&#xA;drwxrwxr-x 4 amir amir 4.0K Feb  4 00:09 apps&#xA;-rw-rw-r-- 1 amir amir  19K Feb  4 00:09 CMakeCache.txt&#xA;drwxrwxr-x 7 amir amir 4.0K Feb  4 00:09 CMakeFiles&#xA;-rw-rw-r-- 1 amir amir 6.5K Feb  4 00:09 cmake_install.cmake&#xA;drwxrwxr-x 3 amir amir 4.0K Feb  4 00:09 common&#xA;-rw-r--r-- 1 amir amir 3.6K Feb  4 00:09 CPackConfig.cmake&#xA;-rw-r--r-- 1 amir amir 4.0K Feb  4 00:09 CPackSourceConfig.cmake&#xA;-rw-rw-r-- 1 amir amir 103K Feb  4 00:09 Makefile&#xA;drwxrwxr-x 3 amir amir 4.0K Feb  4 00:08 mkl-dnn&#xA;-rw-r--r-- 1 amir amir 1.6K Feb  4 00:09 OpenImageDenoiseConfigVersion.cmake&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;But when I would go to the directory I would see the following:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8PzFE.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8PzFE.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;What I did was instead of cloning the oidn repo somewhere else and building it, I cloned the oidn repo in &lt;code&gt;/home/Warrior/Desktop/pathtracer/&lt;/code&gt; and built it there. After that I could see the correct file names/symlinks via &lt;code&gt;ls -lh&lt;/code&gt; as follow. Now my program compiles and things work fine. I just had to use &lt;code&gt;LIBS += -L&amp;quot;oidn/build/&amp;quot; -lOpenImageDenoise&lt;/code&gt; when compiling my code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;total 51M&#xA;drwxrwxr-x 4 amir amir 4.0K Feb  9 10:14 apps&#xA;-rw-rw-r-- 1 amir amir  19K Feb  9 10:14 CMakeCache.txt&#xA;drwxrwxr-x 7 amir amir 4.0K Feb  9 10:19 CMakeFiles&#xA;-rw-rw-r-- 1 amir amir 5.6K Feb  9 10:14 cmake_install.cmake&#xA;-rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 color_ispc_avx2.h&#xA;-rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 color_ispc_avx512skx.h&#xA;-rw-rw-r-- 1 amir amir 3.1K Feb  9 10:17 color_ispc.h&#xA;-rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 color_ispc_sse4.h&#xA;drwxrwxr-x 3 amir amir 4.0K Feb  9 10:14 common&#xA;-rw-r--r-- 1 amir amir 3.3K Feb  9 10:14 CPackConfig.cmake&#xA;-rw-r--r-- 1 amir amir 3.7K Feb  9 10:14 CPackSourceConfig.cmake&#xA;-rw-rw-r-- 1 amir amir 2.6K Feb  9 10:17 input_reorder_ispc_avx2.h&#xA;-rw-rw-r-- 1 amir amir 2.6K Feb  9 10:17 input_reorder_ispc_avx512skx.h&#xA;-rw-rw-r-- 1 amir amir 3.1K Feb  9 10:17 input_reorder_ispc.h&#xA;-rw-rw-r-- 1 amir amir 2.6K Feb  9 10:17 input_reorder_ispc_sse4.h&#xA;-rw-rw-r-- 1 amir amir  41K Feb  9 10:14 libcommon.a&#xA;-rw-rw-r-- 1 amir amir  16M Feb  9 10:17 libdnnl.a&#xA;lrwxrwxrwx 1 amir amir   24 Feb  9 10:19 libOpenImageDenoise.so -&amp;gt; libOpenImageDenoise.so.0&#xA;lrwxrwxrwx 1 amir amir   28 Feb  9 10:19 libOpenImageDenoise.so.0 -&amp;gt; libOpenImageDenoise.so.1.3.0&#xA;-rwxrwxr-x 1 amir amir  34M Feb  9 10:19 libOpenImageDenoise.so.1.3.0&#xA;-rw-rw-r-- 1 amir amir  37K Feb  9 10:19 libutils.a&#xA;drwxrwxr-x 2 amir amir 4.0K Feb  9 10:17 local__core&#xA;-rw-rw-r-- 1 amir amir 104K Feb  9 10:14 Makefile&#xA;drwxrwxr-x 3 amir amir 4.0K Feb  9 10:14 mkl-dnn&#xA;-rwxrwxr-x 1 amir amir 181K Feb  9 10:19 oidnBenchmark&#xA;-rwxrwxr-x 1 amir amir  59K Feb  9 10:19 oidnDenoise&#xA;-rwxrwxr-x 1 amir amir 882K Feb  9 10:19 oidnTest&#xA;-rw-r--r-- 1 amir amir 1.6K Feb  9 10:14 OpenImageDenoiseConfigVersion.cmake&#xA;-rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 output_copy_ispc_avx2.h&#xA;-rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 output_copy_ispc_avx512skx.h&#xA;-rw-rw-r-- 1 amir amir 1.9K Feb  9 10:17 output_copy_ispc.h&#xA;-rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 output_copy_ispc_sse4.h&#xA;-rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 output_reorder_ispc_avx2.h&#xA;-rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 output_reorder_ispc_avx512skx.h&#xA;-rw-rw-r-- 1 amir amir 3.1K Feb  9 10:17 output_reorder_ispc.h&#xA;-rw-rw-r-- 1 amir amir 2.5K Feb  9 10:17 output_reorder_ispc_sse4.h&#xA;-rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 upsample_ispc_avx2.h&#xA;-rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 upsample_ispc_avx512skx.h&#xA;-rw-rw-r-- 1 amir amir 1.8K Feb  9 10:17 upsample_ispc.h&#xA;-rw-rw-r-- 1 amir amir 1.5K Feb  9 10:17 upsample_ispc_sse4.h&#xA;drwxrwxr-x 2 amir amir 4.0K Feb  9 10:17 weights&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="9581" LastActivityDate="2021-02-10T14:34:29.107" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10658" PostTypeId="1" CreationDate="2021-02-11T02:03:44.533" Score="0" ViewCount="17" Body="&lt;p&gt;The complexity of the NCC based template matching is O(n x m x N x M) where N x M is the size of the image and n x m is the size of the template. The commercial machine vision libraries such as HALCON and Cognex seem calculating this in linear time, O(N x M), as I examined the performing time to calculate them on some samples. &lt;a href=&quot;https://titanwolf.org/Network/Articles/Article?AID=0a287f44-dce5-47d5-aae3-0be8b1bbd0ed&quot; rel=&quot;nofollow noreferrer&quot;&gt;Some article&lt;/a&gt; is saying they are building index tables so that they can achieve this in linear time but they are not mentioning further details. So I studied some papers but they are just calculating approximations of it or able to only restricted cases (Briechle et al. 2001, Tsai et al. 2003). What makes them possible to calculate this on linear time?&lt;/p&gt;&#xA;" OwnerUserId="15749" LastEditorUserId="13095" LastEditDate="2021-02-11T09:03:31.420" LastActivityDate="2021-02-11T09:03:31.420" Title="What is the way to calculate NCC based template matching in linear time?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10659" PostTypeId="1" AcceptedAnswerId="10663" CreationDate="2021-02-11T08:49:37.570" Score="0" ViewCount="111" Body="&lt;p&gt;I have read this &lt;a href=&quot;https://learnopengl.com/PBR/Theory&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt;&#xA;On PBR  and in it we have NDF function defined as follows&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fG7mB.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fG7mB.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Then I have read this &lt;a href=&quot;http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;article&lt;/a&gt; on random vector generation&lt;/p&gt;&#xA;&lt;p&gt;Here are what I feel are the important bits.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zCxSa.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zCxSa.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now jump to &lt;a href=&quot;https://learnopengl.com/PBR/IBL/Specular-IBL&quot; rel=&quot;nofollow noreferrer&quot;&gt;Importance sampling&lt;/a&gt; here is the function&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/5EY56.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/5EY56.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Xi is the random vector returned from Hammersley function.&lt;/p&gt;&#xA;&lt;p&gt;Notice how I have left the theory on top of the function. He clearly says &amp;quot;We combine the NDF with the Hammersley equation in spherical space&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;This is my question. How did he do that? I have read the epic games real shading pdf and they don't provide any explanation whatsoever&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/xoOUW.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xoOUW.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;All I need to understand is how did they derive the cosTheta and sinTheta terms.&lt;/p&gt;&#xA;&lt;p&gt;Any explanation even a one liner as an comment would be immensely appreciated.&lt;/p&gt;&#xA;&lt;p&gt;Thank you.&lt;/p&gt;&#xA;" OwnerUserId="15434" LastActivityDate="2021-02-12T15:21:17.303" Title="PBR : Understanding importance sampling" Tags="&lt;pbr&gt;&lt;importance-sampling&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10660" PostTypeId="2" ParentId="10648" CreationDate="2021-02-11T10:00:04.210" Score="1" Body="&lt;p&gt;It looks like the parameters to your camera class are not correct&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt; const int img_ratio = 2;&#xA; ...&#xA; Camera&amp;lt;float&amp;gt; cam1(20.0f, img_ratio, Point3&amp;lt;float&amp;gt;(0.0f, 0.0f, 0.0f), Point3&amp;lt;float&amp;gt;(0.0f, 0.0f, -1.0f), Vec3&amp;lt;float&amp;gt;(0.0f, 1.0f, 0.0f));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In your code you set img_ratio to 2, I would expect it should be something like img_width/img_height (or the reverse img_height/img_width). img_ratio should also be also be a floating point to match the  type the camera class is being instantiated with.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastActivityDate="2021-02-11T10:00:04.210" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10661" PostTypeId="2" ParentId="10659" CreationDate="2021-02-11T12:07:12.280" Score="0" Body="&lt;p&gt;Generally to importance sample a funtion, you calculate it using the inverse cdf method.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Inverse_transform_sampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Inverse_transform_sampling&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;From when I remember, you basically take the integral/cdf of your function and normalize it. Then you know that your random number will be proportional to the the distribution, so you inverse it so that you are calculaiting x from f(x), where f(x) will be your random number.&lt;/p&gt;&#xA;&lt;p&gt;Here it looks like they are inversing to generate n.h, which is the CosTheta. SinTheta is then just being calucated by the identity sqrt(1 - costheta^2).&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2021-02-11T12:07:12.280" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10663" PostTypeId="2" ParentId="10659" CreationDate="2021-02-11T16:32:54.070" Score="2" Body="&lt;p&gt;Leaving the actual derivation of mathematics aside, I'll try to give a general description of how can we combine the NDF with importance sampling in spherical coordinates.&lt;/p&gt;&#xA;&lt;h2&gt;What is NDF ?&lt;/h2&gt;&#xA;&lt;p&gt;The problem is the following. Intiutively, we need the NDF for &amp;quot;zooming in&amp;quot; from the realm of macrosurfaces to that of microfacets.&lt;/p&gt;&#xA;&lt;p&gt;Mathematically it is needed for the following equivalence:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$dA_h = NDF(h) dw_{h} A$$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$A$&lt;/span&gt;: flat macrosurface patch&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$dw_{h}$&lt;/span&gt;: is the area of a portion of a unit spherical cap defined by the orientation &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$dA_{h}$&lt;/span&gt;: is the total area that is being approximated by the orientation &lt;span class=&quot;math-container&quot;&gt;$h$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;see &lt;a href=&quot;http://www.reedbeta.com/blog/hows-the-ndf-really-defined/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; for more.&lt;/p&gt;&#xA;&lt;p&gt;These terms are understood better when we considere the following equivalence:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$d\Omega = 4\pi (\frac{dS}{A})(\hat{r} \cdot \hat{n})$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;You can read this equivalence as the following:&#xA;One can approximate a solid angle subtended by a flat surface whose area equals &lt;span class=&quot;math-container&quot;&gt;$dS$&lt;/span&gt;, orientation &lt;span class=&quot;math-container&quot;&gt;$\hat{n}$&lt;/span&gt;, and distance from the viewer &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\hat{r} = \frac{\vec{r}}{r}$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$A = 4\pi r^2$&lt;/span&gt;. The &lt;span class=&quot;math-container&quot;&gt;$\vec{r}$&lt;/span&gt; is a position vector of the surface area &lt;span class=&quot;math-container&quot;&gt;$dS$&lt;/span&gt; with respect to the center of the sphere. You can read more about it in &lt;a href=&quot;https://en.wikipedia.org/wiki/Solid_angle&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The point here is that whenever we consider approximating solid angles with projected surfaces, we need that direction and distance term.&#xA;Whether we consider solid angles over microfacets or macrosurfaces don't make a difference. From this perspective, you can think of &lt;span class=&quot;math-container&quot;&gt;$NDF$&lt;/span&gt; as &amp;quot;regulation&amp;quot; term for two different granularities involved in approximating the same structure.&lt;/p&gt;&#xA;&lt;p&gt;Since we are modeling the same structure from two different granularities, we can't &amp;quot;touch&amp;quot; properties that coincides with physical/geometric properties of the structure, but we can &amp;quot;touch&amp;quot; the regulation term, hence different ways of computing ndf are provided by different researchers.&lt;/p&gt;&#xA;&lt;p&gt;Whatever it maybe though, it has to satisfy the following equivalence for unit sphere:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$1=\frac{1}{A}\int_{S} (n \cdot h) dA_{h} = \int_{\Omega} NDF(h) (n \cdot h) dw_{h}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Where S is the domain of the area of the macrosurface patch. This reads simply as the following: The area we are calculating as a spherical cap using solid angle bits, and the area we are calculating as a macrosurface patch using macro surface patch bits has to be the same.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h2&gt;What is Importance Sampling ?&lt;/h2&gt;&#xA;&lt;p&gt;Here is the second bit of information necessary to understand the procedure.&#xA;Let X be a random variable, ie a function whose signature is &lt;span class=&quot;math-container&quot;&gt;$X: M \to R $&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; is the sample space and &lt;span class=&quot;math-container&quot;&gt;$R$&lt;/span&gt; is the set of real numbers. Expected value &lt;span class=&quot;math-container&quot;&gt;$E[X]$&lt;/span&gt; is given under the probability distribution &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt; as the following &lt;span class=&quot;math-container&quot;&gt;$E[X;P] = \frac{1}{n} \sum_{i=1}^n x_i$&lt;/span&gt; where n is the total number of samples drawn from the distribution and &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt; is sample generated from &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; using the distribution P.&lt;/p&gt;&#xA;&lt;p&gt;The precision of the estimate calculated this way depends on the variance of the random variable &lt;span class=&quot;math-container&quot;&gt;$X$&lt;/span&gt; under the probability distribution &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt;. If we have infinite number of samples, then its okay to use low precision estimates, but we never do. In fact, it would be great if we have a small number of samples, with a more precise way of computing the estimate.&lt;/p&gt;&#xA;&lt;p&gt;Now think of the following, we have some random variable X, that outputs values according to some distribution, and we want to understand how X works under that distribution. Wouldn't it be better to select the input values for X so that the graph made by the output values look more like the actual graph of the X under distribution P. This is what we are trying to do with importance sampling. The key here is to understand that though we may not know how X maps values in its domain to its codomain, we may know how the probability distribution for choosing samples works. Hence if we choose a function that is similar to random variable's actual probability distribution, we can significantly reduce variance.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h2&gt;How they interact ?&lt;/h2&gt;&#xA;&lt;p&gt;Now coming to your question. We have seen that in order to use importance sampling we need to use function that resembles to the actual probability distribution used for sampling the spherical cap area. So if our function is &lt;span class=&quot;math-container&quot;&gt;$f=NDF(h) (n \cdot h)$&lt;/span&gt;, we need use a function that is similar to the actual probability distribution of this function to sample values from it in order to get an estimate with higher precision.&lt;/p&gt;&#xA;&lt;p&gt;Since we are dealing with points on unit sphere, we are dealing with &lt;a href=&quot;https://en.wikipedia.org/wiki/Spherical_coordinate_system#Integration_and_differentiation_in_spherical_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;spherical coordinates&lt;/a&gt;. The vectors associated with these points are also in spherical coordinates. Now spherical coordinates are defined using two angles and a distance to the center of the sphere. In unit sphere the distance is 1. This leaves us with&#xA;the two angles when considering vectors.&lt;/p&gt;&#xA;&lt;p&gt;The probability distribution associated with &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; then has two parameters, &lt;span class=&quot;math-container&quot;&gt;$\theta$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\phi$&lt;/span&gt; due to using spherical coordinates.&lt;/p&gt;&#xA;&lt;p&gt;Now the &lt;a href=&quot;https://en.wikipedia.org/wiki/Probability_density_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;probability density function&lt;/a&gt; (pdf) of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; is given in &lt;a href=&quot;https://www.tobias-franke.eu/log/2014/03/30/notes_on_importance_sampling.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;. From that we calculate its &lt;a href=&quot;https://en.wikipedia.org/wiki/Cumulative_distribution_function&quot; rel=&quot;nofollow noreferrer&quot;&gt;cumulative distribution function&lt;/a&gt; (cdf) which is also given in &lt;a href=&quot;https://www.tobias-franke.eu/log/2014/03/30/notes_on_importance_sampling.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;We need the cdf because of the following property: If &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; is a continuous random variable with cumulative distribution function &lt;span class=&quot;math-container&quot;&gt;$cdf(T)$&lt;/span&gt;, then the random variable &lt;span class=&quot;math-container&quot;&gt;$Y = cdf(T)$&lt;/span&gt; has a uniform distribution on [0, 1]. Meaning that the inverse of &lt;span class=&quot;math-container&quot;&gt;$cdf(T)$&lt;/span&gt; whose input would come from a uniform distribution on [0, 1] would output a value according to the probability distribution of &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt;. More on that on &lt;a href=&quot;https://en.wikipedia.org/wiki/Inverse_transform_sampling&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt; as suggested by &lt;a href=&quot;https://computergraphics.stackexchange.com/a/10661/13456&quot;&gt;peter&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Coming back to our point. We are looking for function closer to the actual probability distribution of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt;. Why ? Because it is the actual probability distribution that &amp;quot;causes&amp;quot; &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; to output &lt;span class=&quot;math-container&quot;&gt;$x_i$&lt;/span&gt; (sample generated in accordance with the probability distribution of random variable as stated in importance sampling section), since the probability distribution of &lt;span class=&quot;math-container&quot;&gt;$f$&lt;/span&gt; takes two parameters, the angles of spherical coordinate, we need to adapt pdf and cdf to deal with two parameters.&lt;/p&gt;&#xA;&lt;p&gt;It turns out, we can sample one of the angles uniformly, hence&#xA;&lt;code&gt;phi = X_i.x * 2 * PI&lt;/code&gt; given that &lt;code&gt;X_i.x&lt;/code&gt; is a random number between [0,1].&lt;/p&gt;&#xA;&lt;p&gt;Then we only need to deal with pdf and cdf of a single parameter.&#xA;If we can find out manually the inverse of cdf of that parameter, we can map a random value between [0, 1] to a value according to correct distribution of that parameter. The piece of code that deal with &lt;code&gt;X_i.y&lt;/code&gt; represents that manually found inverse of cdf.&lt;/p&gt;&#xA;&lt;p&gt;You can read about the involved mathematics from:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://www.tobias-franke.eu/log/2014/03/30/notes_on_importance_sampling.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;&lt;a href=&quot;https://agraphicsguynotes.com/posts/sample_microfacet_brdf/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;. This gives the full derivation&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;and &lt;a href=&quot;http://www.reedbeta.com/blog/hows-the-ndf-really-defined/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="13456" LastEditorUserId="13456" LastEditDate="2021-02-12T15:21:17.303" LastActivityDate="2021-02-12T15:21:17.303" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10665" PostTypeId="2" ParentId="10646" CreationDate="2021-02-14T01:58:41.020" Score="2" Body="&lt;p&gt;There are many filters that can be used when resizing images. These filters have names like &amp;quot;box&amp;quot;, &amp;quot;tent&amp;quot;, &amp;quot;gaussian&amp;quot;, &amp;quot;sinc&amp;quot;, &amp;quot;lanczos&amp;quot;, and many others. Believe it or not scaling an image down in size is actually much more challenging then scaling it up in size. It is easy to lose high frequency information when resampling an image. Look for the filters in the scaling software, but most software does a good job of choosing default filters so unless you changed the filter then the issue might be...&lt;/p&gt;&#xA;&lt;p&gt;The next possible issue: jpg is not a lossless format and choosing the right size to compression setting is a trade off. Usually with jpg images a medium quality setting gives the best compression to quality ratio and only makes the image a few k bigger. This is a potential culprit. Try a &amp;quot;high quality&amp;quot; setting for the jpg to see if that helps, or even try a lossless format to remove image format as a potential problem.&lt;/p&gt;&#xA;&lt;p&gt;To be more direct...the jpg is being sent at a larger size, with more info in it, the browser resamples giving a nice crispy image. But if you resize then that extra info is thrown away and isn't available for the browser to resample it. This is why using a higher quality jpg may help.&lt;/p&gt;&#xA;&lt;p&gt;&amp;quot;Optimized&amp;quot; jpg's only affect the size of the file, making it slightly smaller in size.&lt;/p&gt;&#xA;&lt;p&gt;But serving images up from the web has a lot of middleware getting involved, and if these suggestions don't fix the problem then it may be the middleware which is beyond the scope of this forum.&lt;/p&gt;&#xA;&lt;p&gt;BTW: the two images look almost identical in my browser.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-02-14T02:14:10.487" LastActivityDate="2021-02-14T02:14:10.487" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10666" PostTypeId="1" CreationDate="2021-02-14T09:03:24.023" Score="0" ViewCount="65" Body="&lt;p&gt;Most of the PBR tutorials out there use HDR maps loaded from disk. But in games these maps need to be generated by taking snapshots of the scene from the objects location which is where problems arise.&lt;/p&gt;&#xA;&lt;p&gt;Let's say there are just 2 objects with PBR material a sphere and a cube.&lt;/p&gt;&#xA;&lt;p&gt;Here are 2 problems I come across&lt;/p&gt;&#xA;&lt;p&gt;1)Each of these 2 objects need an full 360 degree view of the scene around them stored in an cubemap for proper IBL implementation which means for just 2 objects we have to render our scene 12 times!!![6 times to fill the cube map of each object] which is ridiculously expensive and this is just for 2 objects.&#xA;Is there an alternative to this especially in dynamic scenes where objects move around all the time?&lt;/p&gt;&#xA;&lt;p&gt;2)If the sphere and the cube are very close to each other then the color of one object will depend on the light reflected from the other and this light can bounce an infinite number of times between the objects. This can be solved using recursive ray tracing where we control the bounces using an depth variable. Is there an similar recursive approach for the raserization pipeline ?[Similar to 2 mirrors facing each other and reflecting each other problem]&lt;/p&gt;&#xA;&lt;p&gt;Some theory, ideas or maybe  some linked articles would be of great help&lt;/p&gt;&#xA;" OwnerUserId="15434" LastActivityDate="2021-03-16T21:01:10.117" Title="PBR : generating dynamic HDR maps" Tags="&lt;pbr&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10667" PostTypeId="2" ParentId="10666" CreationDate="2021-02-14T20:07:25.047" Score="2" Body="&lt;p&gt;There are no easy answers here, if you are serious then it is possible to replace cubemaps with hemispherical maps, which result in just 2 offscreen renders each instead of 6. They are not popular because the math and setup are nontrivial. RTR4 has references to papers. If you get that working do a writeup here please! Look for Dual-paraboloid shadow mapping.&lt;/p&gt;&#xA;&lt;p&gt;Another solution is to only update your maps every other frame, or every third frame. So if you have say 12 maps, then update 4 of them each frame round robin style. Also frugal culling can greatly reduce the number of faces that have to be rendered but quality is reduced. I see so many implementations that render all the geometry in the scene to every face when much of that geometry is outside the frustum of that face. This alone can increase performance but scene complexity will play a major role in overall performance.&lt;/p&gt;&#xA;&lt;p&gt;As far as infinite reflections is concerned, think about that for a second, infinite rays is going to take infinity to render no matter what your technique is. If you manage to trap photon's in a perfect reflector in real life then you can't observe it because observing it destroys the perfect reflector. I'm not trying to be sarcastic, I'm just giving a reality check.&lt;/p&gt;&#xA;&lt;p&gt;But simple techniques can get good reflections in real time. Screen Space reflections are tricky little buggers to get right but when done well can yield very nice results. You don't see many implementations around because there are a lot of corner cases to consider. Again if you get a good implementation of this working, please share it here!&lt;/p&gt;&#xA;&lt;p&gt;What you are implying in your post sounds like you would, at the very least, have to do reflections against all the cube faces, this too is not realistic, even on the best hardware, your computes are better spent someplace else, like ray tracing...&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-02-14T20:07:25.047" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10668" PostTypeId="2" ParentId="10646" CreationDate="2021-02-14T23:39:12.583" Score="1" Body="&lt;p&gt;Your browser and/or device are zooming the whole page by a factor of 2. The image that is supposedly 718 pixels wide on screen, is actually 1436 pixels wide in your screenshot (I measured). Probably it's an Apple device using a retina display? In any case, that's why it looks so blurry when you serve up an image that's only 718 pixels wide. In this instance, the original size of 1500 is actually much closer to the ideal resolution to serve for this device.&lt;/p&gt;&#xA;&lt;p&gt;More broadly speaking, pixel sizes reported in browsers (for images and everything else) don't necessarily correspond to actual physical pixels on your display. They are a sort of virtual pixel that's independent of zoom and DPI. This is one reason why modern practice is to use an image with the &lt;a href=&quot;https://css-tricks.com/responsive-images-youre-just-changing-resolutions-use-srcset/&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;srcset&lt;/code&gt;&lt;/a&gt; attribute to provide all the resolutions and let the browser choose which one to download—it will figure out the best resolution given the actual pixels on the screen.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2021-02-14T23:52:47.483" LastActivityDate="2021-02-14T23:52:47.483" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10669" PostTypeId="1" AcceptedAnswerId="10670" CreationDate="2021-02-15T13:55:33.157" Score="1" ViewCount="77" Body="&lt;p&gt;I want to have separate files for common things for shaders precompiled into a spirv.&lt;/p&gt;&#xA;&lt;p&gt;For example PBR, I've got these functions and implementations for them&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float NDFGGX(float NdotH, float roughness);&#xA;float GeometrySchlickGGX(float NdotV, float k);&#xA;float GeometrySmith(float NdotL, float NdotV, float roughness);&#xA;vec3 FresnelSchlick(float cosTheta, vec3 F0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and I don't want to generate binaries for them every time I use it in a new shader.&#xA;What I want is to generate a SPIRV binary file once and do whatever I want with it.&#xA;Is this possible?&#xA;What I've tried is to use &lt;code&gt;shaderc&lt;/code&gt; library and create the binary as if it were a vertex shader, but it then needs glsl version and entry point. Not every file'd have entry point, doe.&lt;/p&gt;&#xA;" OwnerUserId="15773" LastEditorUserId="15773" LastEditDate="2021-02-15T14:56:51.240" LastActivityDate="2021-02-18T14:12:20.327" Title="Is there a way to compile part of a shader into a spirv?" Tags="&lt;shader&gt;&lt;glsl&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10670" PostTypeId="2" ParentId="10669" CreationDate="2021-02-15T15:03:06.880" Score="1" Body="&lt;p&gt;What you want is generally not possible for OpenGL's SPIR-V support. SPIR-V compiles to shader objects, and shader objects theoretically allow you to link multiple objects of the same stage in a program. However, OpenGL's usage of SPIR-V &lt;a href=&quot;https://www.khronos.org/opengl/wiki/SPIR-V#Entry_points_and_specialization&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;requires&lt;/em&gt; that each SPIR-V shader be a complete shader stage with its entrypoint function&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;So the requirement of shaderc mirrors the requirements of OpenGL.&lt;/p&gt;&#xA;&lt;p&gt;The best you could do is combine multiple SPIR-V binaries into a single binary &lt;em&gt;before&lt;/em&gt; handing it off to OpenGL. But that's a non-trivial process, since you basically have to renumber every reference in at least one of them, and combine any references that map to the same type.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-02-15T15:03:06.880" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10672" PostTypeId="1" AcceptedAnswerId="10673" CreationDate="2021-02-16T11:30:37.187" Score="0" ViewCount="48" Body="&lt;p&gt;I'm very new to computer graphics and trying to implement a raytracer based on the book &lt;em&gt;&lt;a href=&quot;https://gabrielgambetta.com/computer-graphics-from-scratch/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Computer Graphics from Scratch&lt;/a&gt;&lt;/em&gt;. When I tried to add specular reflection, I don't get the output that look like on the book. I don't know how to debug this, I mean running a debugger stepwise doesn't seems to helpful. I look at the code on the book, compare the formulas, they looks like the same. Kind apologies for the long code:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#include &amp;lt;cmath&amp;gt;&#xA;#include &amp;lt;cstdint&amp;gt;&#xA;#include &amp;lt;limits&amp;gt;&#xA;#include &amp;lt;utility&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;&#xA;#define STBI_ONLY_PNG        // decode only for PNG format&#xA;#define STBI_FAILURE_USERMSG // for better image load failure messages&#xA;#define STB_IMAGE_WRITE_IMPLEMENTATION&#xA;#include &amp;quot;3rdparty/stb/stb_image_write.h&amp;quot;&#xA;&#xA;namespace {&#xA;&#xA;struct point {&#xA;  double x{}, y{}, z{};&#xA;};&#xA;&#xA;struct vec3d {&#xA;  double x{}, y{}, z{};&#xA;};&#xA;&#xA;vec3d operator-(const point p, const point q) { return vec3d{p.x - q.x, p.y - q.y, p.z - q.z}; }&#xA;point operator+(const vec3d v, const point p) { return point{v.x + p.x, v.y + p.y, v.z + p.z}; }&#xA;vec3d operator+(const vec3d v, const vec3d w) { return vec3d{v.x + w.x, v.y + w.y, v.z + w.z}; }&#xA;vec3d operator-(const vec3d v, const vec3d w) { return vec3d{v.x - w.x, v.y - w.y, v.z - w.z}; }&#xA;vec3d operator-(const vec3d v) { return vec3d{-1.0 * v.x, -1.0 * v.y, -1.0 * v.z}; }&#xA;bool operator==(const vec3d v, const vec3d w) { return v.x == w.x &amp;amp;&amp;amp; v.y == w.y &amp;amp;&amp;amp; v.z == w.z; }&#xA;vec3d operator*(const double k, const vec3d v) { return vec3d{k * v.x, k * v.y, k * v.z}; }&#xA;double length(const vec3d v) { return sqrt(v.x * v.x + v.y * v.y + v.z * v.z); }&#xA;vec3d normalize(vec3d v) { return (1.0 / length(v)) * v; }&#xA;double dot(const vec3d v, const vec3d w) { return (v.x * w.x) + (v.y * w.y) + (v.z * w.z); }&#xA;&#xA;vec3d cross(const vec3d v, const vec3d w) {&#xA;  vec3d r;&#xA;  r.x = v.y * w.z - v.z * w.y;&#xA;  r.y = v.z * w.x - v.x * w.z;&#xA;  r.z = v.x * w.y - v.y * w.x;&#xA;&#xA;  return r;&#xA;}&#xA;&#xA;} // namespace&#xA;&#xA;int main() {&#xA;  using namespace std;&#xA;&#xA;  constexpr size_t canvas_width = 600;&#xA;  constexpr size_t canvas_height = 600;&#xA;  constexpr size_t channels = 4; // r,g,b,a&#xA;&#xA;  constexpr size_t viewport_width = 1;&#xA;  constexpr size_t viewport_height = 1;&#xA;  constexpr size_t viewport_distance = 1;&#xA;&#xA;  constexpr double minus_inf = numeric_limits&amp;lt;double&amp;gt;::min();&#xA;  constexpr double plus_inf = numeric_limits&amp;lt;double&amp;gt;::max();&#xA;&#xA;  using canvas_t = uint8_t[canvas_width][canvas_height][channels];&#xA;  using point_t = point;&#xA;&#xA;  struct color_t {&#xA;    uint8_t r{}, g{}, b{}, a{};&#xA;  };&#xA;&#xA;  enum class light_type { ambient, directional, point };&#xA;&#xA;  struct light {&#xA;    light_type type;&#xA;    double intensity;&#xA;    point_t position;&#xA;  };&#xA;&#xA;  struct sphere {&#xA;    double radius;&#xA;    point_t center;&#xA;    color_t color;&#xA;    int specular;&#xA;  };&#xA;&#xA;  canvas_t canvas;&#xA;  point_t O{0.0, 0.0, 0.0}; // camera position&#xA;&#xA;  const sphere sphere_1{1.0, point_t{0, -1, 3}, color_t{255, 0, 0, 255}, 500};&#xA;  const sphere sphere_2{1.0, point_t{2, 0, 4}, color_t{255, 0, 255, 255}, 500};&#xA;  const sphere sphere_3{1.0, point_t{-2, 0, 4}, color_t{0, 255, 0, 255}, 10};&#xA;  const vector spheres{sphere_1, sphere_2, sphere_3};&#xA;&#xA;  const light light_1{light_type::ambient, 0.2};&#xA;  const light light_2{light_type::point, 0.6, point_t{2, 1, 0}};&#xA;  const light light_3{light_type::directional, 0.2, point_t{1, 4, 4}};&#xA;  const vector lights{light_1, light_2, light_3};&#xA;&#xA;  auto canvas2viewport = [=](const double x, const double y) -&amp;gt; vec3d {&#xA;    const double Vx = (x * viewport_width) / canvas_width;&#xA;    const double Vy = (y * viewport_height) / canvas_height;&#xA;&#xA;    return vec3d{Vx, Vy, double(viewport_distance)};&#xA;  };&#xA;&#xA;  auto computeLighting = [&amp;amp;](const point_t P, const vec3d N, const vec3d V, const int specular) {&#xA;    double total_intensity = 0;&#xA;&#xA;    for (const auto light : lights) {&#xA;      if (light.type == light_type::ambient) {&#xA;        total_intensity += light.intensity;&#xA;      } else {&#xA;        vec3d L;&#xA;        if (light.type == light_type::point) {&#xA;          L = light.position - P;&#xA;        } else {&#xA;          L = light.position - point_t{0, 0, 0};&#xA;        }&#xA;&#xA;        if (const double n_dot_l = dot(N, L); n_dot_l &amp;gt; 0) { // diffuse reflection&#xA;          total_intensity += light.intensity * n_dot_l / (length(N) * length(L));&#xA;        }&#xA;&#xA;        if (specular != -1) { // specular reflection&#xA;          const vec3d R = (2 * dot(N, L) * N) - L;&#xA;&#xA;          if (const double r_dot_v = dot(R, V); r_dot_v &amp;gt; 0) {&#xA;            total_intensity += light.intensity + pow((r_dot_v / (length(R) * length(V))), specular);&#xA;          }&#xA;        }&#xA;      }&#xA;    }&#xA;    return total_intensity;&#xA;  };&#xA;&#xA;  auto intersectRaySphere = [=](const point_t O, const vec3d D, const sphere s) -&amp;gt; auto {&#xA;    const double r = s.radius;&#xA;    const vec3d OC = O - s.center;&#xA;&#xA;    const double a = dot(D, D);&#xA;    const double b = 2 * dot(OC, D);&#xA;    const double c = dot(OC, OC) - r * r;&#xA;&#xA;    const double discriminant = b * b - 4 * a * c;&#xA;&#xA;    if (discriminant &amp;lt; 0) {&#xA;      return make_pair(plus_inf, plus_inf);&#xA;    }&#xA;&#xA;    const double t1 = (-b + sqrt(discriminant)) / (2 * a);&#xA;    const double t2 = (-b - sqrt(discriminant)) / (2 * a);&#xA;&#xA;    return pair{t1, t2};&#xA;  };&#xA;&#xA;  auto traceRay = [&amp;amp;](const point_t O, const vec3d D, const int min, const int max) -&amp;gt; color_t {&#xA;    double closest_t = plus_inf;&#xA;    sphere closest_sphere;&#xA;    bool sphere_changed = false;&#xA;&#xA;    for (const sphere &amp;amp;sp : spheres) {&#xA;      const auto [t1, t2] = intersectRaySphere(O, D, sp);&#xA;      if ((t1 &amp;gt; min &amp;amp;&amp;amp; t1 &amp;lt; max) &amp;amp;&amp;amp; t1 &amp;lt; closest_t) {&#xA;        closest_t = t1;&#xA;        closest_sphere = sp;&#xA;        sphere_changed = true;&#xA;      }&#xA;&#xA;      if ((t2 &amp;gt; min &amp;amp;&amp;amp; t2 &amp;lt; max) &amp;amp;&amp;amp; t2 &amp;lt; closest_t) {&#xA;        closest_t = t2;&#xA;        closest_sphere = sp;&#xA;        sphere_changed = true;&#xA;      }&#xA;    }&#xA;&#xA;    if (!sphere_changed) {&#xA;      return color_t{255, 255, 255, 255}; // white&#xA;    }&#xA;&#xA;    const point_t P = closest_t * D + O;&#xA;    vec3d N = P - closest_sphere.center;&#xA;    N = normalize(N);&#xA;&#xA;    const double total_light = computeLighting(P, N, -D, closest_sphere.specular);&#xA;&#xA;    return color_t{uint8_t(closest_sphere.color.r * total_light),&#xA;                   uint8_t(closest_sphere.color.g * total_light),&#xA;                   uint8_t(closest_sphere.color.b * total_light), 255};&#xA;  };&#xA;&#xA;  // x in [-300, 300)&#xA;  // y in [-300, 300)&#xA;  auto put_pixel = [&amp;amp;](const int x, const int y, const color_t p) {&#xA;    const size_t sx = (canvas_width / 2) + x;&#xA;    const size_t sy = ((canvas_height / 2) - y) - 1;&#xA;&#xA;    if (sx &amp;lt; 0 || sx &amp;gt;= canvas_width || sy &amp;lt; 0 || sy &amp;gt;= canvas_height)&#xA;      return;&#xA;&#xA;    canvas[sy][sx][0] = p.r;&#xA;    canvas[sy][sx][1] = p.g;&#xA;    canvas[sy][sx][2] = p.b;&#xA;    canvas[sy][sx][3] = 255;&#xA;  };&#xA;&#xA;  for (int y = -300; y &amp;lt; 300; ++y) {&#xA;    for (int x = -300; x &amp;lt; 300; ++x) {&#xA;      vec3d D = canvas2viewport(x, y);&#xA;      color_t c = traceRay(O, D, 1, 100'000);&#xA;      put_pixel(x, y, c);&#xA;    }&#xA;  }&#xA;&#xA;  stbi_write_png(&amp;quot;specular_light.png&amp;quot;, canvas_width, canvas_height, channels, canvas,&#xA;                 canvas_width * channels);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;My output is look like this &lt;a href=&quot;https://i.stack.imgur.com/ifEVI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ifEVI.png&quot; alt=&quot;this&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;and this &lt;a href=&quot;https://i.stack.imgur.com/kwQ4h.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kwQ4h.png&quot; alt=&quot;and this&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;the output on the book is :&lt;a href=&quot;https://i.stack.imgur.com/uBRZk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/uBRZk.png&quot; alt=&quot;like this&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15776" LastActivityDate="2021-02-16T14:06:21.820" Title="Buggy behavior when applying specular reflection" Tags="&lt;raytracing&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10673" PostTypeId="2" ParentId="10672" CreationDate="2021-02-16T13:55:38.043" Score="1" Body="&lt;p&gt;This code below can cause an 8bit overflow.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;auto traceRay = [&amp;amp;](const point_t O, const vec3d D, const int min, const int max) -&amp;gt; color_t {&#xA;&#xA;...&#xA;&#xA;return color_t{uint8_t(closest_sphere.color.r * total_light),&#xA;                   uint8_t(closest_sphere.color.g * total_light),&#xA;                   uint8_t(closest_sphere.color.b * total_light), 255};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here values above 255 will wrap around to 0 as the upper bits are lost (e.g. 255 + 1 = 0x100, but as an 8 bit value it is 0x00). This is what is causing the banding in your image.&lt;/p&gt;&#xA;&lt;p&gt;To fix this you should check if each element of closest_sphere.color * total_light is below the maximum uint8_t value before casting from double to uint8 occurs.&lt;/p&gt;&#xA;&lt;p&gt;for example:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;return color_t{uint8_t(std::min(closest_sphere.color.r * total_light, 255.0)),&#xA;                   uint8_t(std::min(closest_sphere.color.g * total_light, 255.0)),&#xA;                   uint8_t(std::min(closest_sphere.color.b * total_light, 255.0)), 255};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2021-02-16T14:06:21.820" LastActivityDate="2021-02-16T14:06:21.820" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10675" PostTypeId="2" ParentId="209" CreationDate="2021-02-17T08:50:19.343" Score="0" Body="&lt;p&gt;Absolutely there is, the Bresenham's Algorithm, modified.&lt;/p&gt;&#xA;&lt;p&gt;Instead of drawing from (x0,y0) to (x1,y1), one can use Bresenham's algorithm to draw lines from &lt;code&gt;(x0,y0*256)&lt;/code&gt; to &lt;code&gt;(x1, y1*256)&lt;/code&gt; still in x1-x0+1 steps, meaning that the delta_y is also multiplied by a factor of 256.&lt;/p&gt;&#xA;&lt;p&gt;At each step  &lt;code&gt;plot(x, y &amp;gt;&amp;gt; 256, y ^ 255); plot(x, sign(y1-y0)+(y&amp;gt;&amp;gt;256), y &amp;amp; 255);&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is similarly fast, as it would use Bresenham's middle point algorithm with better error handing than Wu's algorithm (given that it suffers from error accumulation due to DDA) while also calculating the distance properly rounded. This approach of course adds one shift &lt;code&gt;y &amp;gt;&amp;gt; 8&lt;/code&gt; one &lt;code&gt;xor&lt;/code&gt; and two pixel writings. &lt;code&gt;y &amp;amp; 255&lt;/code&gt; is typically free.&lt;/p&gt;&#xA;" OwnerUserId="15781" LastActivityDate="2021-02-17T08:50:19.343" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10676" PostTypeId="2" ParentId="10669" CreationDate="2021-02-18T12:12:52.457" Score="1" Body="&lt;p&gt;Consider #include.&lt;/p&gt;&#xA;&lt;p&gt;We use the tools provided by &lt;a href=&quot;https://github.com/KhronosGroup/SPIRV-Tools&quot; rel=&quot;nofollow noreferrer&quot;&gt;Khronos&lt;/a&gt; to make our own compiler that is part of a larger tool providing lots of specific functionality. Like handing out binding numbers, compiling spirv into linkable objects (with the restriction noted above), and others to numerous to mention here. If linking smaller SPIRV code snippets into a larger SPIRV program is something you really need then these tools could support the type of environment you are talking about, but it would take some programming. We haven't needed to go there...yet...because:&lt;/p&gt;&#xA;&lt;p&gt;Or, you could use the google include directive:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#extension GL_GOOGLE_include_directive : enable&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If that extension is available in your environment, which you can find out just by throwing at the top of a shader that already compiles correctly then recompiling. Then that might be &amp;quot;good enough&amp;quot;. But if your environment is a long term project then it may be worth the effort to dig into the tools....happy programming!&lt;/p&gt;&#xA;&lt;p&gt;If there is interest in this question I will add more specifics on using the khronos tools. Like linking, getting info about shaders, setting info in shaders, the list is long and mighty. Also Khronos provides tutorials for using the tools on GitHub at the link above, though some of them are a bit hard to follow, but all in all these tools are outstanding.&lt;/p&gt;&#xA;&lt;p&gt;Also spirv-link.exe will combine existing SPIRV modules into a library with the --create-library option. The entry points need to have unique names and can't all be &amp;quot;main&amp;quot;. Then when loaded the code specifies the entry point for the module. Here is an example command line to help get anyone reading this going:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;spirv-link.exe -o libraryname.spv --target-env spv1.5 input1.spv input2.spv&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Add --create-library to make an spv library.(which requires unique entry point names)&lt;/p&gt;&#xA;&lt;p&gt;Here is a &lt;a href=&quot;https://www.khronos.org/opengl/wiki/SPIR-V&quot; rel=&quot;nofollow noreferrer&quot;&gt;link&lt;/a&gt; explaining how to set the entry points in opengl.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-02-18T14:12:20.327" LastActivityDate="2021-02-18T14:12:20.327" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10677" PostTypeId="1" CreationDate="2021-02-19T13:20:35.177" Score="1" ViewCount="66" Body="&lt;p&gt;Simple question: is there a source that precedes the idea of presenting graphical application or 3D scene in a scene graph?&lt;/p&gt;&#xA;&lt;p&gt;I came across &lt;a href=&quot;https://dl.acm.org/doi/10.1145/360349.360354&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hierarchical geometric models for visible surface algorithms&lt;/a&gt; which introduces the idea of having the geometry in easily searchable and cullable format. So I wonder if this is the father of the idea of having scene graph, or has there been something published earlier with this idea.&lt;/p&gt;&#xA;" OwnerUserId="15574" LastActivityDate="2021-03-03T07:18:34.520" Title="When and who introduced the idea of a scene graph?" Tags="&lt;gltf&gt;&lt;bounding-volume-hierarchy&gt;&lt;scene-graph&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10678" PostTypeId="1" CreationDate="2021-02-19T15:42:21.857" Score="0" ViewCount="39" Body="&lt;p&gt;I'm implementing some mesh operations (e.g. edge collapse, edge split, edge flip etc) and need to ensure applying such operations does not cause the mesh to become non-manifold. However, I'm not sure how what things I should check for to ensure my geometry doesn't become non-manifold. Can someone tell me what those conditions/checks are?&#xA;Also, how can I apply the same operation that causes the mesh to become non-manifold so that the manifoldness of the mesh is still preserved?&lt;/p&gt;&#xA;" OwnerUserId="9581" LastEditorUserId="9581" LastEditDate="2021-02-19T21:56:24.693" LastActivityDate="2021-02-19T21:56:24.693" Title="Under what conditions does a mesh operation cause the mesh become non-manifold and how to avoid it?" Tags="&lt;3d&gt;&lt;c++&gt;&lt;algorithm&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10679" PostTypeId="1" CreationDate="2021-02-19T18:16:01.497" Score="0" ViewCount="23" Body="&lt;p&gt;I need to parametrise &lt;span class=&quot;math-container&quot;&gt;$\mathbb{R^3}$&lt;/span&gt; coordinates relative to a mesh, which is a deformed &lt;span class=&quot;math-container&quot;&gt;$UV$&lt;/span&gt; sphere with triangular faces. Every vertex on the mesh has a &lt;span class=&quot;math-container&quot;&gt;$UV$&lt;/span&gt; coordinate, and I want to associate every &lt;span class=&quot;math-container&quot;&gt;$\mathbb{R^3}$&lt;/span&gt; point with a coordinate (&lt;span class=&quot;math-container&quot;&gt;$u,v$&lt;/span&gt;, signed distance). So for instance, points on the mesh would simply be assigned &lt;span class=&quot;math-container&quot;&gt;$(u,v,0)$&lt;/span&gt;. If a point starts on the mesh at a vertex and then moves outwards by &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; in the direction of the vertex normal, the new point should be assigned &lt;span class=&quot;math-container&quot;&gt;$(u,v,1)$&lt;/span&gt;. If a point starts on the mesh inside a face, its normal is a barycentric combination of the surrounding vertex normals, then &lt;span class=&quot;math-container&quot;&gt;$(u,v,1)$&lt;/span&gt; is defined as above. Moving inwards gives a negative signed distance. It seems intuitive to me that this formulation assigns a coordinate to every point in &lt;span class=&quot;math-container&quot;&gt;$\mathbb{R^3}$&lt;/span&gt;, since it is like inflating the mesh until you reach any arbitrary point in &lt;span class=&quot;math-container&quot;&gt;$\mathbb{R^3}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Suppose &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt; is the point I want to parametrize. Let &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; be a triangle with vertices &lt;span class=&quot;math-container&quot;&gt;$x_1,x_2,x_3$&lt;/span&gt;, vertex normals &lt;span class=&quot;math-container&quot;&gt;$n_1,n_2,n_3$&lt;/span&gt; and UV coordinates &lt;span class=&quot;math-container&quot;&gt;$u_1,u_2,u_3$&lt;/span&gt;. I want to find a point &lt;span class=&quot;math-container&quot;&gt;$X=ax_1+bx_2+(1-a-b)x_3$&lt;/span&gt; with normal &lt;span class=&quot;math-container&quot;&gt;$N=an_1+bn_2+(1-a-b)n_3$&lt;/span&gt; such that &lt;span class=&quot;math-container&quot;&gt;$N$&lt;/span&gt; is parallel with the line &lt;span class=&quot;math-container&quot;&gt;$XP$&lt;/span&gt;.  This will be the case if the cross product &lt;span class=&quot;math-container&quot;&gt;$C=N\times(P-X)=0$&lt;/span&gt;.  The vector &lt;span class=&quot;math-container&quot;&gt;$C$&lt;/span&gt; will have three components that are 2nd degree functions in &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; so I have to solve for &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt;.  I will try to find a pytorch solver for this. Then I will compute the signed distance &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt;.  And &lt;span class=&quot;math-container&quot;&gt;$(u,v)=au_1+bu_2+(1-a-b)u_3$&lt;/span&gt;, so the parametrization of &lt;span class=&quot;math-container&quot;&gt;$P$&lt;/span&gt; with respect to &lt;span class=&quot;math-container&quot;&gt;$T$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$(u,v,w)$&lt;/span&gt;. When multiple triangles can be used to parametrise the point in this way, I will use the one with signed distance of least magnitude.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Does this seem a reasonable approach or am I missing something? And can anyone recommend a pytorch-compatible solver to use?&lt;/strong&gt; For efficiency reasons I don't think I can check every triangle for every point, so I intend to only check the k nearest triangles to the point, where nearest means nearest by triangle centre. However, I realise there maybe special cases where this fails to give the correct triangle. In case its relevant, I know that any vertex is a member of at most 6 triangles.&lt;/p&gt;&#xA;&lt;p&gt;This is in deep learning context, Im learning the deformation on the fly by training a shape model. So I can make things easier if necessary by adding constraints on the learned mesh - for example, encouraging regular sized triangles, and a smooth surface.&lt;/p&gt;&#xA;" OwnerUserId="15796" LastActivityDate="2021-02-19T18:16:01.497" Title="Parametrising $\mathbb{R^3}$ coordinates using a mesh with barycentric coordinates, and signed distance to the mesh" Tags="&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10680" PostTypeId="2" ParentId="8835" CreationDate="2021-02-19T19:29:20.717" Score="0" Body="&lt;p&gt;In a homework we were tasked to calculate the gradient of a triangle respective to a corner vertex. The instructions didn't say what to calculate and mentioned, one could derive it by a derivative of the triangle area using the corner vertex coordinates. I exactly came to the same formula explained by Futurologist.&lt;/p&gt;&#xA;&lt;p&gt;In case someone wants to know, this is the derivation:&lt;/p&gt;&#xA;&lt;p&gt;Let &lt;span class=&quot;math-container&quot;&gt;$\vec{x},\vec{y}, \vec{z} \in \mathcal{V}$&lt;/span&gt; be the vertex corners of the triangle.&lt;/p&gt;&#xA;&lt;p&gt;First, the area of a triangle is the length of the cross product between two sides of it divided by 2 (because the determinant calculates the area of a parallelogram which is twice the area of the triangle):&#xA;&lt;span class=&quot;math-container&quot;&gt;$A(\vec{x}) = \left|(\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right|/2 = \sqrt{\left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right)^2}/2$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The multiplication of vectors should be the dot product whose meaning depends on the operands left and right to it. Using differential calculus rules for vectors, this is what I get:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{\partial A}{\partial \vec{x}} = \frac{\frac{\partial \left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right)^2}{\partial \vec{x}}}{4\sqrt{\left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right)^2}}$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$= \frac{\frac{\partial \left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right)}{\partial \vec{x}} \cdot 2\left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right) }{4A}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;How to calculate the gradient of a cross product? If we would look for the divergence, we would use the determinant &lt;span class=&quot;math-container&quot;&gt;$\text{det}(\nabla_\vec{x},\vec{y}-\vec{x},\vec{z}-\vec{x})$&lt;/span&gt; but that's not the gradient. The gradient &lt;span class=&quot;math-container&quot;&gt;$\partial A/\partial \vec{c}$&lt;/span&gt; must be a vector itself so that &lt;span class=&quot;math-container&quot;&gt;$\partial(\vec{a}\times\vec{b})/\partial \vec{b}$&lt;/span&gt; must be a matrix!&#xA;Now, just think of &lt;span class=&quot;math-container&quot;&gt;$M \times \vec{b}$&lt;/span&gt; like a matrix product but using &lt;span class=&quot;math-container&quot;&gt;$M_i \times \vec{b}$&lt;/span&gt; to replace the dot product &lt;span class=&quot;math-container&quot;&gt;$M_i \cdot \vec{b}$&lt;/span&gt; of a normal matrix multiplication (each result component will now be a row vector, not a scalar).&lt;/p&gt;&#xA;&lt;p&gt;Next step is to split those cross products up into a sum:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{\partial A}{\partial \vec{x}}= \frac{\frac{\partial \left(\vec{y}\times\vec{z}-\vec{x}\times\vec{z} - \vec{y}\times\vec{x} + \vec{x}\times\vec{x}\right)}{\partial \vec{x}} \cdot \left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right) }{2A}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\vec{y}\times\vec{z}$&lt;/span&gt; does not depend on &lt;span class=&quot;math-container&quot;&gt;$\vec{x}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$\vec{x}\times\vec{x}$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$\vec{0}$&lt;/span&gt;. It now is used that &lt;span class=&quot;math-container&quot;&gt;$\partial(\vec{a}\times\vec{b})/\partial \vec{a} = I\times\vec{b}$&lt;/span&gt;, where &lt;span class=&quot;math-container&quot;&gt;$I$&lt;/span&gt; is the eye matrix. It is a fact that &lt;span class=&quot;math-container&quot;&gt;$Y_\times = I\times\vec{y}$&lt;/span&gt; is the (left) cross product matrix from &lt;span class=&quot;math-container&quot;&gt;$\vec{y}$&lt;/span&gt; so that &lt;span class=&quot;math-container&quot;&gt;$\left(I \times \vec{z}\right)^T = \left(I\times(-\vec{z})\right)$&lt;/span&gt; is the right cross product matrix from &lt;span class=&quot;math-container&quot;&gt;$\vec{z}$&lt;/span&gt;. Hence&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$\frac{\partial A}{\partial \vec{x}}= \frac{\frac{\partial \left(\vec{x}\times\vec{y}-\vec{x}\times\vec{z}\right)}{\partial \vec{x}} \cdot \left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right) }{2A}$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$= \frac{\left(I\times\vec{y}-I\times\vec{z}\right) \cdot \left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right) }{2A}$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$= \frac{\left(I\times(\vec{y}-\vec{z})\right) \cdot \left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right) }{2A}$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$= \frac{\left((\vec{y}-\vec{x})\times(\vec{z}-\vec{x})\right)\times(\vec{z}-\vec{y}) }{2A}$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So this result is exactly the same as &lt;span class=&quot;math-container&quot;&gt;$-\frac{\mathcal{J}\vec{e_{j_i}}}{2} = \frac{(-\vec{n})\times\vec{e_{j_i}}}{2}$&lt;/span&gt; where &lt;span class=&quot;math-container&quot;&gt;$\vec{e_{j_i}} = \vec{z}-\vec{y}$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$i = \vec{x}$&lt;/span&gt; and the direction will always show towards the opposite edge of &lt;span class=&quot;math-container&quot;&gt;$\vec{x}$&lt;/span&gt; indepent of which vertex is chosen to be &lt;span class=&quot;math-container&quot;&gt;$\vec{y}$&lt;/span&gt; and which is &lt;span class=&quot;math-container&quot;&gt;$\vec{z}$&lt;/span&gt;. That's the reason, why the &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt; in the original formula for &lt;span class=&quot;math-container&quot;&gt;$(\text{grad} f)(j)$&lt;/span&gt; is needed, to divide away the factor of &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt; within the &lt;span class=&quot;math-container&quot;&gt;$\vec{e_{j_i}}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;If you work with parallelograms instead of triangles you can remove the &lt;span class=&quot;math-container&quot;&gt;$2$&lt;/span&gt; entirely.&lt;/p&gt;&#xA;&lt;p&gt;What does the gradient of a triangle mean after all? The triangle gradient is the direction, where -- if you move &lt;span class=&quot;math-container&quot;&gt;$\vec{x}$&lt;/span&gt; in that direction -- the triangle experiences the biggest change in area. You can add together the gradient of multiple triangles from &lt;span class=&quot;math-container&quot;&gt;$\vec{x}$&lt;/span&gt; to use it for minimizing surface area of a discrete 3D surface.&lt;/p&gt;&#xA;" OwnerUserId="15795" LastEditorUserId="15795" LastEditDate="2021-02-20T00:38:32.060" LastActivityDate="2021-02-20T00:38:32.060" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10681" PostTypeId="2" ParentId="4709" CreationDate="2021-02-20T08:22:06.700" Score="0" Body="&lt;p&gt;In &lt;a href=&quot;https://github.com/mmp/pbrt-v3&quot; rel=&quot;nofollow noreferrer&quot;&gt;Physically Based Rendering&lt;/a&gt; Kd is the diffuse albedo (diffuse color) and Ks the specular albedo (specular color).&lt;/p&gt;&#xA;" OwnerUserId="15800" LastEditorUserId="13095" LastEditDate="2021-02-21T12:19:39.613" LastActivityDate="2021-02-21T12:19:39.613" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10682" PostTypeId="1" CreationDate="2021-02-20T16:45:08.983" Score="0" ViewCount="73" Body="&lt;p&gt;I'm new to shaders and I have been experimenting with them in shadertoy. I'm trying to get a deeper understanding of the graphics pipeline and I want to implement some features using shaders. I want to start off simple and draw a line on the screen using shaders. I wrote two-line algorithms from scratch&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Vertex {&#xA;    vec2 p;&#xA;    vec4 c;&#xA;};&#xA;&#xA;vec4 overlay(vec4 c1, vec4 c2) {&#xA;    return vec4((1.0 - c2.w) * c1.xyz + c2.w * c2.xyz, 1.0);&#xA;}&#xA;&#xA;vec4 drawLineA(Vertex v1, Vertex v2, vec2 pos) {&#xA;    vec2 a = v1.p;&#xA;    vec2 b = v2.p;&#xA;    vec2 r = floor(pos);&#xA;    &#xA;    vec2 diff = b - a;&#xA;    &#xA;    &#xA;    if (abs(diff.y) &amp;lt; abs(diff.x)) {&#xA;        if (diff.x &amp;lt; 0.0) {&#xA;            Vertex temp1 = v1;&#xA;            Vertex temp2 = v2;&#xA;            &#xA;            v1 = temp2;&#xA;            v2 = temp1;&#xA;            &#xA;            a = v1.p;&#xA;            b = v2.p;&#xA;            diff = b - a;&#xA;        &#xA;        }&#xA;        &#xA;        float m = diff.y / diff.x;&#xA;        float q = r.x - a.x;&#xA;        &#xA;        if (floor(m * q + a.y) == r.y &amp;amp;&amp;amp; a.x &amp;lt;= r.x &amp;amp;&amp;amp; r.x &amp;lt;= b.x) {&#xA;            float h = q / diff.x;&#xA;            return vec4((1.0 - h) * v1.c + h * v2.c);&#xA;        }&#xA;        &#xA;        &#xA;    } else {&#xA;        if (diff.y &amp;lt; 0.0) {&#xA;            Vertex temp1 = v1;&#xA;            Vertex temp2 = v2;&#xA;            &#xA;            v1 = temp2;&#xA;            v2 = temp1;&#xA;            &#xA;            a = v1.p;&#xA;            b = v2.p;&#xA;            diff = b - a;&#xA;        &#xA;        }&#xA;    &#xA;        float m =  diff.x / diff.y;&#xA;        float q = r.y - a.y;&#xA;        &#xA;        if (floor(m * q + a.x) == r.x &amp;amp;&amp;amp; a.y &amp;lt;= r.y &amp;amp;&amp;amp; r.y &amp;lt;= b.y) {&#xA;            float h = q / diff.y;&#xA;            return vec4((1.0 - h) * v1.c + h * v2.c);&#xA;        }&#xA;    &#xA;    }&#xA;    &#xA;    return vec4(0,0,0,0);&#xA;}&#xA;&#xA;vec4 drawLineB(Vertex v1, Vertex v2, vec2 pos) {&#xA;    vec2 a = v1.p;&#xA;    vec2 b = v2.p;&#xA;    &#xA;    vec2 l = b - a;&#xA;    vec2 r = pos - a;&#xA;    float h = dot(l,r) / dot (l,l);&#xA;    &#xA;    vec2 eC = a + h * l;&#xA;    &#xA;    if (floor(pos) == floor(eC) &amp;amp;&amp;amp; 0.0 &amp;lt;= h &amp;amp;&amp;amp; h &amp;lt;= 1.0 ) {&#xA;       return vec4((1.0 - h) * v1.c + h * v2.c); &#xA;    }&#xA;    &#xA;    return vec4(0,0,0,0);&#xA;}&#xA;&#xA;&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;    float t = iTime;&#xA;    float r = 300.0;&#xA;    Vertex v1 = Vertex(vec2(400,225), vec4(1,0,0,1));&#xA;    Vertex v2 = Vertex(vec2(400.0 + r*cos(t) ,225.0 + r*sin(t)), vec4(0,1,0,1));&#xA;    &#xA;    vec4 col = vec4(0,0,0,1);&#xA;    col = overlay(col,drawLineA(v1, v2, fragCoord));&#xA;    col = overlay(col,drawLineB(v1, v2, fragCoord));&#xA;    // Output to screen&#xA;    fragColor = col;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;However, they are both quite slow, is there a more efficient line algorithm that I can use that outputs a color based on whether the pixel is in the line or not. I've heard that Bresenham's line algorithm is the fastest however I don't know how to use shaders to speed up the algorithm because it needs the previous y value to compute the next. Can line algorithms be sped up by shaders or is it already the fastest it can be on the CPU. If there is a optimised line drawing algorithm using the GPU (where the GPU would out-perform the cpu) how can I implement it into my code?&lt;/p&gt;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;" OwnerUserId="15802" LastEditorUserId="15802" LastEditDate="2021-02-21T03:36:50.187" LastActivityDate="2021-02-21T13:28:45.543" Title="What is the most efficient line algorithm using a shader program" Tags="&lt;shader&gt;&lt;fragment-shader&gt;&lt;line-drawing&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10683" PostTypeId="2" ParentId="10682" CreationDate="2021-02-21T01:07:18.400" Score="1" Body="&lt;p&gt;Here is a (mostly) minimal version of an SDF for a line segment using a signed distance field as suggested in the comments. I take no credit for this code, it is your function pieced together with IQ's SDF function done in the style you listed above.&lt;/p&gt;&#xA;&lt;p&gt;Be sure to go to IQ's website, it is one of the best learning resource out there for this material. Though it can be hard to digest till you get all the basics down. &lt;a href=&quot;https://www.iquilezles.org/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;IQ's Index Page.&lt;/a&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float udSegment( in vec2 p, in vec2 a, in vec2 b )&#xA;{&#xA;   vec2 ba = b-a;&#xA;   vec2 pa = p-a;&#xA;   float h =clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );&#xA;   //return length(pa-h*ba); // use actual length&#xA;&#xA;   // or use length squared&#xA;   vec2 sqrd = pa-h*ba;&#xA;   sqrd = sqrd * sqrd;&#xA;   return sqrd.x+sqrd.y;&#xA;}&#xA;&#xA;void mainImage( out vec4 fragColor, in vec2 fragCoord )&#xA;{&#xA;   vec2 p = ((2.0*fragCoord-iResolution.xy)/iResolution.y)*1.4;&#xA;&#xA;    // give it some spin&#xA;    vec2 v1 = iResolution.xy * vec2(cos(iTime),sin(iTime));&#xA;&#xA;    vec2 v2 = vec2(0,0); // set the start point&#xA;    float th = 0.004; // Controls line thickness&#xA;&#xA;    float d = udSegment( p, v1, v2 ) - th; // compute sdf&#xA;&#xA;    vec3 col = vec3(1.0) - sign(d);&#xA;    fragColor = vec4(col,1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If all this is doing is drawing a line, then there is no need to compute the actual length, so don't...just return lenght squared. I made an edit to the code above that skips the sqrt, but line thickness is now squared.&lt;/p&gt;&#xA;&lt;p&gt;Bresenham's algorithm was intended to be used for drawing individual pixels and is often implemented directly in the hardware of GPU's. So it drives which pixels to draw in its own loop and tells the hardware which pixel to draw.&lt;/p&gt;&#xA;&lt;p&gt;ShaderToy is drawing the entire screen, so every pixel is covered probably by drawing a fullscreen triangle, then calling the mainImage function in the fragement shader.&lt;/p&gt;&#xA;&lt;p&gt;To implement Bresenham's algorithm in ShaderToy the code would need to determine if a particular fragment was actually on the line and in so doing we lose any advantage gained by this clever line drawing technique.&lt;/p&gt;&#xA;&lt;p&gt;The most efficient way to draw a line on a GPU is not to use ShaderToy at all but write our own bit of code that tells the hardware to just draw a line, this is where graphics API's like OpenGL come into play. Which ultimately would call a fragment shader but unlike ShaderToy, the fragment shader would only be called for those fragments which are actually on the line and our fragment shader would then be reduced to something ultra simple like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void main(){ return vec4(1,1,1,1); }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Which would result in a pure white line being drawn on screen.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-02-21T13:28:45.543" LastActivityDate="2021-02-21T13:28:45.543" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10684" PostTypeId="1" CreationDate="2021-02-22T11:18:56.807" Score="0" ViewCount="37" Body="&lt;p&gt;I am in the process of making a 'Game' using the Unity game engine which features pre-rendered 3d background images. Currently, we are using JPegs but I thought it would be nice to get some movement in them. I remembered Final Fantasy VII having really neat pre-rendered images with movement in them and researched it and they &lt;a href=&quot;https://imgur.com/gallery/dYQWr&quot; rel=&quot;nofollow noreferrer&quot;&gt;still look great&lt;/a&gt;. the images on this site are gifs but I'm not sure what compression would have been used back then, very possibly gif. I seem to recollect that animated gifs only update the area of the image which actually changes which helps with compression. My question is: Is there a modern equivalent to animated gifs that would allow me to create high-quality background images with small areas of movement in them?&lt;/p&gt;&#xA;" OwnerUserId="15811" LastEditorUserId="13095" LastEditDate="2021-02-24T12:55:29.207" LastActivityDate="2021-02-24T12:55:29.207" Title="Creating high quality background images for a game which have small areas of moving detail" Tags="&lt;rendering&gt;&lt;compression&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10685" PostTypeId="1" AcceptedAnswerId="10688" CreationDate="2021-02-22T12:38:28.353" Score="0" ViewCount="57" Body="&lt;p&gt;First of all I have a struct which looks like the following:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct structName&#xA;{&#xA;    vec3 position;&#xA;    float radius;&#xA;    float type;&#xA;    ...some more information which are definitely needed! Not sure how many, but most probably less than 10&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;there are like 200 of these struct elements within my scene. When rendering the scene these objects are fixed. That mean, that they don't change during rendering the scene. They only change after rendering the scene.&#xA;Right now I am using a SSBO to store the elements.&#xA;Inside my vertex shader (of another geometry) I am reading out all 200 struct elements, iterate over them and make a calculation. This is slowing down my shader...&#xA;I am trying to improve the speed of the shader. So I am looking for a better way to read the data.&lt;/p&gt;&#xA;&lt;p&gt;Lets talk about the limitations:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Within the shader I NEVER change any value of any element within the struct (read only).&lt;/li&gt;&#xA;&lt;li&gt;All vertices within my other geometry need all 200 of these struct elements.&lt;/li&gt;&#xA;&lt;li&gt;The iterated calculation result for each vertex is different (has something to do with the vertex position) So the calculation can not be outsourced.&lt;/li&gt;&#xA;&lt;li&gt;The 200 elements will not be rendered at all. They are only information which is needed for other geometry&lt;/li&gt;&#xA;&lt;li&gt;Each of the 200 struct elements will be changed after each render call (60 FPS =&amp;gt; 60 times each of the elements have been changed).&lt;/li&gt;&#xA;&lt;li&gt;The new values of the elements are calculated within another shader program (shader2). So they are &amp;quot;read only&amp;quot; during the render call, and &amp;quot;read/write&amp;quot; during the calculation in shader2.&lt;/li&gt;&#xA;&lt;li&gt;The elements need some atomic operation functions during the calculation in shader2 (atomic add).&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;I think to store it as a SSBO slows down my shader, because shaders are able to read/write to SSBOs so the elements are lying down on some global memory which is slow. Maybe some other buffer type is the correct one... but which one? uniform buffer objects sounds good, because uniforms are const. So maybe when using it as uniform buffer a copy will be put to a local GPU memory so that each shader instruction can access these memory faster.&lt;/p&gt;&#xA;&lt;p&gt;Which buffer type is needed to increase the FPS of my program under these circumstances?&lt;/p&gt;&#xA;&lt;p&gt;An alternative may be to read the whole buffer within the vertex shader at once? (not sure if this is possible) The size is already known (200 * sizeof(structName)). For me it is also okay, if the data is stored in an float array each value next to each other.&lt;/p&gt;&#xA;&lt;p&gt;Thanks a lot!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2021-02-22T23:42:54.843" Title="fastest way to &quot;read only&quot; from buffer" Tags="&lt;opengl&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="9" ContentLicense="CC BY-SA 4.0" />
  <row Id="10686" PostTypeId="1" CreationDate="2021-02-22T20:17:56.493" Score="0" ViewCount="30" Body="&lt;p&gt;For a vision research experiment, I have a monitor that supports 10bit/channel (=30bit color). I want to render a triangle mesh in a simple scene that uses the full bit depth, and I want to save this rendering as a .png file. The rendering is just for single, static images, and doesn't need to happen lightning fast.&lt;/p&gt;&#xA;&lt;p&gt;For the triangle mesh, I have:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;List of vertices in xyz coordinates&lt;/li&gt;&#xA;&lt;li&gt;List of triangles containing the indices of the vertices&lt;/li&gt;&#xA;&lt;li&gt;List of the vertex normals&lt;/li&gt;&#xA;&lt;li&gt;List of the triangle/face normals&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;My hardware includes (possibly irrelevant)&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Dell UP3218K monitor - 8k and 10bits/channel&lt;/li&gt;&#xA;&lt;li&gt;GeForce RTX 2080 Super (but can get a better one if needed)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I tried using the pyrender library, but it outputs the rendered scene as uint8 (limiting it to 8bit).&lt;/p&gt;&#xA;&lt;p&gt;I can't find any code examples of OpenGL or PyOpenGL rendering meshes at 10bits or higher. With the increasing popularity of &amp;gt;8bit monitors, surely this is possible?&lt;/p&gt;&#xA;&lt;p&gt;What can I use to render a mesh at 10 bit/channel depth?&lt;/p&gt;&#xA;" OwnerUserId="15817" LastActivityDate="2021-02-22T20:17:56.493" Title="How can I render a triangle mesh at 10bit (or 12bit or 16bit) channel depth color?" Tags="&lt;opengl&gt;&lt;rendering&gt;&lt;mesh&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10687" PostTypeId="2" ParentId="10684" CreationDate="2021-02-22T22:55:48.060" Score="2" Body="&lt;p&gt;The &amp;quot;modern equivalent&amp;quot; of animated GIFs is... MPEG. Or really, any decent movie compression format. These techniques are designed to spend fewer bits on static areas and more bits on moving ones. And better still, they're designed to be dynamic, allowing motion in any are at any time, rather than only in fixed areas.&lt;/p&gt;&#xA;&lt;p&gt;So just make a short, looping movie of the &amp;quot;background image&amp;quot; you're trying to build. You may want to get into the details of the compression system you're working with, so that you can give lots of bits to the initial frame and fewer bits to moving areas.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-02-22T22:55:48.060" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10688" PostTypeId="2" ParentId="10685" CreationDate="2021-02-22T23:42:54.843" Score="2" Body="&lt;p&gt;I think you may be focusing on the wrong thing here. Moving the data from an SSBO to a uniform buffer might give some speedup, sure, but that is a micro-optimization.&lt;/p&gt;&#xA;&lt;p&gt;I would search for algorithmic optimizations first. As noted in the comments, processing all 200 records for every vertex is both a lot of data to read, and a lot of computation to do if there's a lot of vertices. Also note that in the course of rendering, vertices will sometimes be processed more than once as they are used by multiple triangles (the vertex cache helps with this, but it can't eliminate all duplicate processing). So you will be re-doing this expensive computation multiple times for the same vertex, sometimes.&lt;/p&gt;&#xA;&lt;p&gt;Does every vertex really need to process every data element? I see that your data elements have a position and radius. If they represent some kind of mesh deformation that happens within a localized volume of space, then it might be beneficial to store those in an acceleration structure. This would allow each vertex to efficiently narrow down its processing to only those elements that affect it. For example, you could create a regular grid spanning the bounding box of your mesh, and in each grid cell store a list of indices into the main data array for the elements that intersect that grid cell. The creation of this grid could be done in a compute shader earlier in the frame, and should be quite fast. Then, when drawing the mesh, the vertex shader would look up which grid cell the vertex is in, and process those data elements. This is very similar to how we do tiled/clustered shading for light sources in many game engines.&lt;/p&gt;&#xA;&lt;p&gt;If spatial subdivision like that doesn't get the job done (for example if many of the elements are of large radius, so that most/all of the vertices really do need to process most/all of the elements), then are the elements' influences on the vertices parallelizable in any way? For instance, are you summing a perturbation generated by each element, to arrive at a total displacement for the vertex, or something along those lines? If so, you could run compute shader passes to pre-calculate the displacements and store them into a buffer to be read later by the vertex shader. The compute passes could be set up with work groups that distribute jointly over the vertices and the work elements (the exact distribution and mapping of compute threads would have to be experimented with). Each work group might, for instance, load a small chunk of vertices and a chunk of displacement elements into shared memory, calculate the displacements, then store them out to the per-vertex displacement buffer using atomic adds. Or, they might store out to various intermediate buffers (to avoid atomic contention) and have another set of compute shaders that sum up the intermediate values to obtain the final values. It would take some experimentation to see how to do it most efficiently, but you could likely get some big speedups here.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-02-22T23:42:54.843" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10689" PostTypeId="1" CreationDate="2021-02-23T02:37:12.693" Score="0" ViewCount="44" Body="&lt;p&gt;In 1993, Pixar publish Pixar 128 repeating textures (now CC BY 4.0):&#xA;&lt;a href=&quot;https://renderman.pixar.com/pixar-one-twenty-eight&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://renderman.pixar.com/pixar-one-twenty-eight&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Have Pixar use any textures from this set in their movies like Toy Story, Bug's Life, Toy Story 2, etc.?&lt;/p&gt;&#xA;&lt;p&gt;I ask this question in movies.stackexchange.com because it about movie production but they close it:&#xA;&lt;a href=&quot;https://movies.stackexchange.com/questions/112783/have-any-pixar-movie-use-pixar-128-textures-from-1993&quot;&gt;https://movies.stackexchange.com/questions/112783/have-any-pixar-movie-use-pixar-128-textures-from-1993&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;May be I should ask here?&lt;/p&gt;&#xA;" OwnerUserId="11430" LastActivityDate="2021-02-23T02:37:12.693" Title="Have any Pixar movie use 'Pixar 128' textures from 1993?" Tags="&lt;texture&gt;&lt;pixel-graphics&gt;&lt;bitmap-graphics&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10690" PostTypeId="1" AcceptedAnswerId="10691" CreationDate="2021-02-23T06:36:51.613" Score="1" ViewCount="68" Body="&lt;p&gt;We can create header files in C/C++ which we can include in our project using #include directive but when I use this keyword in my shader it gives the error  reserved keyword. If let's say I create an simple text file for adding two numbers and I want to include this file &amp;amp; code in my vertex/fragment shader is it possible?&lt;/p&gt;&#xA;" OwnerUserId="15434" LastActivityDate="2021-02-24T12:06:58.557" Title="Opengl : GLSL utility files" Tags="&lt;opengl&gt;&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10691" PostTypeId="2" ParentId="10690" CreationDate="2021-02-23T09:14:31.653" Score="1" Body="&lt;p&gt;&lt;s&gt;Yes, &lt;/s&gt; &lt;a href=&quot;https://opengl.gpuinfo.org/listreports.php?extension=GL_ARB_shading_language_include&quot; rel=&quot;nofollow noreferrer&quot;&gt;With a certain OpenGL extension&lt;/a&gt;, that is possible (thanks to NicolBolas for pointing that out). &lt;s&gt;It is pretty much the same as in C++. Let's assume you have a file util.glsl, vertex.glsl and fragment.glsl, all in the same folder.&lt;/s&gt; &lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;//in util.glsl&#xA;float add(float a, float b)&#xA;{&#xA;    return a + b;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then you can call that function, as if it were in your shader file&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;//in either vertex.glsl or fragment.glsl&#xA;#include &amp;quot;util.glsl&amp;quot;&#xA;&#xA;void main()&#xA;{&#xA;    float result = add(1, 2);&#xA;    ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Your result would then be 3. Of course, if you have the file in a different folder, you need to adjust the path, but again, that is pretty much the same as in C++.&lt;/p&gt;&#xA;&lt;p&gt;The only caveat is with debugging. Without having tested it right now, as far as I remember compiler errors will not display your util.glsl as the source of your error. Rather it will put the contents of util.glsl at the position, where your include call is and then say you have an error in that line in vertex.glsl / fragment.glsl, so this might be a bit confusing&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$^1$&lt;/span&gt;Actually, this is incorrect (by default at least). In a project we used it like that, but since I did not do that setup myself, I assume it was either setup to work like that by a collegue or by OpenSceneGraph, which we used. In any case, I cannot (yet) answer this myself. I want to add this part, as soon as I understand it myself. Until then, I will simply link to a similar question with answer from NicolBolas, which hints at what you have to do: &lt;a href=&quot;https://stackoverflow.com/questions/10754437/how-to-using-the-include-in-glsl-support-arb-shading-language-include&quot;&gt;https://stackoverflow.com/questions/10754437/how-to-using-the-include-in-glsl-support-arb-shading-language-include&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7008" LastEditorUserId="7008" LastEditDate="2021-02-24T12:06:58.557" LastActivityDate="2021-02-24T12:06:58.557" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10692" PostTypeId="1" CreationDate="2021-02-23T20:57:14.270" Score="0" ViewCount="16" Body="&lt;p&gt;I am currently writing a program to parse the .gltf file using the &lt;a href=&quot;https://digip.org/jansson/&quot; rel=&quot;nofollow noreferrer&quot;&gt;jansson C library for reading JSON files&lt;/a&gt;. I want to show how that library is effective in reading .gltf files so that apps can use this.&lt;/p&gt;&#xA;&lt;p&gt;However, I am not sure how this will work. Depending on what it will be use (i.e. a game engine), I am not certain as to how it does.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;int load_gltf(filename)&#xA;{&#xA;    CFILE *fp, *fpb;&#xA;    fp = cfopen(filename, &amp;quot;rb&amp;quot;, CFILE_NORMAL, CF_TYPE_MODELS, false);&#xA;    if (!fp) {&#xA;        return 0;&#xA;    }&#xA;&#xA;    int size = cfilelength(fp);&#xA;    std::string gltf_data;&#xA;    gltf_data.resize((size_t) size);&#xA;    cfread(&amp;amp;gltf_data[0], 1, size, fp);&#xA;&#xA;    cfclose(fp);&#xA;&#xA;    json_t* gltf_data_root = json_loads(gltf_data.c_str(), 0, nullptr);&#xA;    if (!gltf_data_root) {&#xA;        return 0;&#xA;    }&#xA;    if(!json_is_array(gltf_data_root)) {&#xA;        json_decref(gltf_data_root);&#xA;        return 0;&#xA;    }&#xA;    for(i = 0; i &amp;lt; json_array_size(gltf_data_root); i++) {&#xA;        json_t *gltf_data, *gltf_scenes, *gltf_scenes_nodes, *gltf_nodes, *gltf_nodes_mesh, *gltf_meshes, *gltf_buffers, *gltf_bufferViews, *gltf_accessors, *gltf_asset;&#xA;        gltf_data = json_array_get(gltf_data_root, i);&#xA;        if(!json_is_object(gltf_data)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_scenes = json_object_get(gltf_data, &amp;quot;scenes&amp;quot;);&#xA;        if(!json_is_object(gltf_scenes)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_scenes_nodes = json_object_get(gltf_scenes, &amp;quot;nodes&amp;quot;);&#xA;        if(!json_is_object(gltf_scenes_nodes)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_nodes = json_object_get(gltf_data, &amp;quot;nodes&amp;quot;);&#xA;        if(!json_is_object(gltf_nodes)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_nodes_mesh = json_object_get(gltf_nodes, &amp;quot;mesh&amp;quot;);&#xA;        if(!json_is_object(gltf_nodes_mesh)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_meshes = json_object_get(gltf_data, &amp;quot;meshes&amp;quot;);&#xA;        if(!json_is_object(gltf_meshes)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_buffers = json_object_get(gltf_data, &amp;quot;buffers&amp;quot;);&#xA;        if(!json_is_object(gltf_buffers)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_bufferViews = json_object_get(gltf_data, &amp;quot;bufferViews&amp;quot;);&#xA;        if(!json_is_object(gltf_bufferViews)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_accessors = json_object_get(gltf_data, &amp;quot;accessors&amp;quot;);&#xA;        if(!json_is_object(gltf_accessors)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;        gltf_asset = json_object_get(gltf_data, &amp;quot;asset&amp;quot;);&#xA;        if(!json_is_object(gltf_asset)) {&#xA;            json_decref(gltf_data_root);&#xA;            return 0;&#xA;        }&#xA;    }&#xA;    json_decref(gltf_data_root);&#xA;    return 1;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="15832" LastActivityDate="2021-02-23T20:57:14.270" Title="How to read .gltx files using jansson JSON C library?" Tags="&lt;c++&gt;&lt;gltf&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10693" PostTypeId="1" AcceptedAnswerId="10695" CreationDate="2021-02-25T03:23:50.297" Score="2" ViewCount="27" Body="&lt;p&gt;I've been reading &lt;a href=&quot;https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; article on how to extract the plane equations from the view and projection matrices. And I can understand most of it. However, the only thing that is unclear to me (and that might be for lack of mathematical knowledge), is the part where they transform their inequality &lt;code&gt;0 &amp;lt; v * (row4 + row1)&lt;/code&gt; into the equality &lt;code&gt; v * (row4 + row1) = 0&lt;/code&gt; (that is for calculating the plane in the x negative side).&lt;/p&gt;&#xA;&lt;p&gt;Usually, to convert inequality to equality you use a &lt;a href=&quot;https://en.wikipedia.org/wiki/Slack_variable&quot; rel=&quot;nofollow noreferrer&quot;&gt;slack variable&lt;/a&gt;, but in their approach, none was used. How can we be sure that &lt;code&gt; v * (row4 + row1)&lt;/code&gt; will always be zero on that frustum plane? All we know is that the resulting value of &lt;code&gt; v * (row4 + row1)&lt;/code&gt;  &lt;strong&gt;has&lt;/strong&gt; to be positive to be on the right side of that frustum plane.&lt;/p&gt;&#xA;&lt;p&gt;I also know how the plane equation is constructed. How we use the dot product of two vectors (any vector in the plane and the normal a,b,c) must be equal to zero: &lt;code&gt;ax + by + cz + d = 0&lt;/code&gt;. I can see that the resulting expression from &lt;code&gt;v * (row4 + row1) &amp;gt; 0&lt;/code&gt; results into a identical plane equation. My only doubts are in the conversion from inequality to equality.&lt;/p&gt;&#xA;" OwnerUserId="12081" LastEditorUserId="12081" LastEditDate="2021-02-25T17:37:37.597" LastActivityDate="2021-02-25T18:00:47.460" Title="Understanding inequality to equality in the Hartmann &amp; Gribbs frustum planes extraction method" Tags="&lt;opengl&gt;&lt;mathematics&gt;&lt;optimization&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10694" PostTypeId="1" CreationDate="2021-02-25T10:27:10.030" Score="0" ViewCount="38" Body="&lt;p&gt;I'm turning to you as a newbie in CG, with a question that might easily be answerable for pros.&lt;/p&gt;&#xA;&lt;p&gt;What I need to do is the following: I have a (rather simple) quad mesh in a 3D modelling software, say, Blender. Now I export that mesh to use it in another application (I therefore won't have access to the texture mapping algorithm that was used to texture the mesh). To export, I currently use the .obj file format.&lt;/p&gt;&#xA;&lt;p&gt;Now, within that other application, I will be given a texture coordinate (in [0,1]), and need to determine its world position and normal, do to some further processing. The way I currently go about this is the following:&lt;/p&gt;&#xA;&lt;p&gt;My .obj file tells me how many faces there are, and which vertices (in world pos., and texture coordinates) these faces consist of. It also tells me the face normal. Now, for the newly given uv coordinates, I do a (kind of) rasterization, and check for all faces whether the new uv coordinates lie within the uv-range that the face's vertices map to. After that, I use these vertices and their world position to interpolate the new world position of the given uv coordinates. The normal at the given uv coordinates is the face normal.&lt;/p&gt;&#xA;&lt;p&gt;This works, but feels kind of clumsy. As I said, I'm rather new to CG, so my question is: Is there a simpler way of determining world space position and normal, given a UV coordinate and no access to the texture mapping algorithm?&lt;/p&gt;&#xA;" OwnerUserId="15841" LastActivityDate="2021-02-25T10:27:10.030" Title="Compute UV Normals and World Position from a given texture coordinate" Tags="&lt;texture&gt;&lt;rasterizer&gt;&lt;uv-mapping&gt;&lt;normal-mapping&gt;&lt;conversion&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10695" PostTypeId="2" ParentId="10693" CreationDate="2021-02-25T18:00:47.460" Score="1" Body="&lt;p&gt;The volume &lt;em&gt;inside&lt;/em&gt; of the frustum is defined by a set of inequalities, and since we are trying to find the &lt;em&gt;boundaries&lt;/em&gt; of the frustum, we set the inequalities to equalities. That's really all it is.&lt;/p&gt;&#xA;&lt;p&gt;To take a 1D example, if we have a &amp;quot;frustum&amp;quot; defined by 0 &amp;lt; x &amp;lt; 5, then of course the bounding points of it are defined by x = 0 and x = 5. Replacing each inequality by an equality, in turn, gives you the most extreme point you can get to in that direction.&lt;/p&gt;&#xA;&lt;p&gt;Slack variables, BTW, don't really convert inequalities to equalities. They just transform the inequality into a standardized form &amp;quot;x &amp;gt; 0&amp;quot; (or &amp;quot;x ≥ 0&amp;quot;) for some slack variable x.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-02-25T18:00:47.460" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10696" PostTypeId="1" AcceptedAnswerId="10706" CreationDate="2021-02-25T19:07:52.243" Score="1" ViewCount="242" Body="&lt;p&gt;I'm trying to create an infinitely panable grid using fragment shaders (C++/OpenGL/GLSL), and I'm having a bit of difficulty understanding the coordinate system.&lt;/p&gt;&#xA;&lt;p&gt;This is my fragment shader code, ported over from an example on &lt;a href=&quot;https://www.shadertoy.com/view/4sj3DG&quot; rel=&quot;nofollow noreferrer&quot;&gt;ShaderToy&lt;/a&gt;:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 460 core&#xA;&#xA;layout(location = 0) out vec4 color;&#xA;&#xA;in vec2 v_Resolution;   // window size in pixels             [1000, 618]&#xA;in vec3 v_CamPos;       // camera position in pixels         [0, 0, 0]&#xA;in float v_CellSize;    // grid cell size in pixels          [50]&#xA;&#xA;// TODO: make these variables in&#xA;float lineWidth      = 1.f;         // The width of each line (in pixels).&#xA;float darkenMultiple = 5.f;         // Multiple of which lines are darkened (e.g. every 5th line).&#xA;&#xA;void main() {&#xA;&#xA;    float width = lineWidth / v_CellSize;&#xA;&#xA;    vec2 uv = vec2(gl_FragCoord.x, gl_FragCoord.y / v_Resolution.y + v_Resolution.y / 2 - v_CellSize / 2);&#xA;&#xA;    uv.x *= 1.0 / v_CellSize;&#xA;    uv.y /= v_CellSize;&#xA;&#xA;    // Adjust the origin of each line thicker than one pixel to its center.&#xA;    uv.xy += (lineWidth &amp;gt; 1) ? width * 0.5 : width;&#xA;    &#xA;    // Make the grid resolution independent by offsetting the Y coordinates based on the current viewport height.&#xA;    uv.y -= gl_FragCoord.y / v_CellSize;&#xA;&#xA;    // Apply camera translation.&#xA;    uv.x += v_CamPos.x / v_CellSize;&#xA;    uv.y -= v_CamPos.y / v_CellSize;&#xA;    &#xA;    float grid = 0.0;&#xA;    grid = max(step(fract(uv.x), width), grid); // X lines (horizontal)&#xA;    grid = max(step(fract(uv.y), width), grid); // Y lines (vertical)&#xA;    &#xA;    vec4 col = vec4(grid);&#xA;    &#xA;    if (col.r != 0.0 &amp;amp;&amp;amp; col.g != 0.0 &amp;amp;&amp;amp; col.b != 0.0) {&#xA;    &#xA;        float mx = mod(uv.x, float(darkenMultiple));&#xA;        float my = mod(uv.y, float(darkenMultiple));&#xA;        &#xA;        // Make lines that are a multiple of `darkenMultiple` darker than the rest.&#xA;        col.a = (mx &amp;lt; width || my &amp;lt; width) ? 0.2 : 0.15;&#xA;    } else {&#xA;        // Turn all pixels that aren't apart of the grid invisible as to not cover the rest of the scene.&#xA;        col.a = 0.0;&#xA;    }&#xA;    &#xA;    color = col;&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Everything in this code functions as intended, until I try to translate the entire grid (grid lines) to the center of the screen by adding &lt;code&gt;v_Resolution.x / 2&lt;/code&gt; to &lt;code&gt;uv.x&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I believe the part that's tripping me up is when I normalize &lt;code&gt;gl_FragCoord&lt;/code&gt; to &lt;code&gt;uv&lt;/code&gt; by dividing it by the screen size (&lt;code&gt;v_Resolution&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;p&gt;From &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/5724/glsl-can-someone-explain-why-gl-fragcoord-xy-screensize-is-performed-and-for&quot;&gt;this question&lt;/a&gt; I know why &lt;code&gt;gl_FragCoord&lt;/code&gt; is normalized, but I don't understand why in this case &lt;code&gt;uv.x = gl_FragCoord.x&lt;/code&gt; while &lt;code&gt;uv.y = gl_FragCoord.y / v_Resolution.y&lt;/code&gt;. Why would I divide the y-component by the screen height, but not the x-component by the screen width? If I try to divide &lt;code&gt;gl_FragCoord.x&lt;/code&gt; by the screen width, the entire shader breaks, and the grid columns are not rendered. This is especially strange to me, because in the &lt;a href=&quot;https://www.shadertoy.com/view/4sj3DG&quot; rel=&quot;nofollow noreferrer&quot;&gt;ShaderToy&lt;/a&gt; example, the coordinates are not normalized at all, and it functions perfectly fine! I feel like I'm missing a very important concept here.&lt;/p&gt;&#xA;&lt;p&gt;The entire code can be downloaded and compiled (Windows, OpenGL 4.5) from my GitHub repo: &lt;a href=&quot;https://github.com/wooandrew/boomerang/tree/develop&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/wooandrew/boomerang/tree/develop&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;EDIT:&lt;br&gt;&#xA;Okay, I was able to get the translation working as intended, but I'm still confused on the normalized UV as well as the coordinate system of UV.&lt;/p&gt;&#xA;&lt;p&gt;My solution (simplified):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = vec2(gl_FragCoord.x - (v_Resolution.x / 2.f), (gl_FragCoord.y / v_Resolution.y) + (v_Resolution.y / 2.f));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now, if I remember correctly, the origin in a GLSL fragment shader is bottom left, so why do I have to &lt;em&gt;subtract&lt;/em&gt; &lt;code&gt;v_Resolution.x / 2.f&lt;/code&gt; instead of &lt;em&gt;adding&lt;/em&gt; it? (also, why is the x-component not normalized, like the y-component?)&lt;/p&gt;&#xA;" OwnerUserId="15849" LastEditorUserId="15849" LastEditDate="2021-03-01T20:33:25.207" LastActivityDate="2021-03-06T18:18:24.877" Title="Understanding fragment shader coordinate system" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;c++&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10697" PostTypeId="1" CreationDate="2021-02-26T05:41:09.777" Score="0" ViewCount="14" Body="&lt;p&gt;I'm trying to plug my renderer into &lt;a href=&quot;https://www.sidefx.com/products/houdini/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Houdini&lt;/a&gt;,and I've already managed to transfer the houdini soho scene to my c++ program via boost interprocess shared memory,and rendered my first image.But I still don't understand the how soho deal with interactive rendering,it seems that houdini call my soho_program whenever I move a light,geometry or assign material,but no calling happens when change material parameters like basecolor or ior.Thus every times I change a material parameter,I've to hit the update button in the RenderView to see the change.I've tried to call my soho_prgram from c++ side,like&#xA;system(&amp;quot;cd Houdini\python27 &amp;amp;&amp;amp; python myrenderer.py&amp;quot;),so that I can call soho_program from my renderer every upate iteration inside my render loop,but it's didn't work.It seem that soho_program can only be called by houdini.Was I miss something or what.Thank you so much for help!&lt;/p&gt;&#xA;" OwnerUserId="13864" LastEditorUserId="13864" LastEditDate="2021-02-27T04:10:42.333" LastActivityDate="2021-02-27T04:10:42.333" Title="Houdini SOHO interactive update" Tags="&lt;rendering&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10698" PostTypeId="1" AcceptedAnswerId="10701" CreationDate="2021-02-27T08:12:19.107" Score="3" ViewCount="85" Body="&lt;p&gt;How do you allow a function to accept a reference of a double array ? For example:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;MyFunc(uint x, uint y, float2[][] myArray) {}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I get &lt;code&gt;unexpected [&lt;/code&gt; error does it allow reference passes like this?&lt;/p&gt;&#xA;&lt;p&gt;I am trying to pass this to my function:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float2 _switchBuffer[2][128]&#xA;float2 _switchBuffer[2][256]`&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is declared as one of my properties that the entire shader has access to so i need the kernel to pass the relevant switchbuffer to the functions.&lt;/p&gt;&#xA;&lt;p&gt;So i have something like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void FFT128 (uint3 id : SV_DispatchThreadID)  { Test(id.xy, 3, _switchBuffer128); }&#xA;void FFT256 (uint3 id : SV_DispatchThreadID)  { FFT1D(id.xy, 3, _swotchBuffer256); }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10332" LastActivityDate="2021-02-27T23:48:51.543" Title="How to pass a 2D array to a function" Tags="&lt;hlsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10700" PostTypeId="1" CreationDate="2021-02-27T21:37:37.063" Score="5" ViewCount="81" Body="&lt;p&gt;I am working with a PWP3D-like algorithm that renders silhouettes of a mesh in order to segment a frame of video and update an object's pose. Because it is only the silhouettes of the mesh that matter, it would be nice to automatically generate simpler meshes where the indents/concavities that do not affect the silhouette are removed. That is, I want to generate a simpler mesh that has the exact same silhouette as the original when viewed at any angle from any position outside of the mesh's convex hull.&lt;/p&gt;&#xA;&lt;p&gt;Is there an existing technique for doing this? Or even just some definitions other than &amp;quot;indent&amp;quot; that better describe this problem that might aid in a web search for this? I've currently found mesh simplification/decimation techniques that aim to preserve silhouettes, but these are not exactly what I'm looking for right now, and they generally seem to just simplify indents rather than outright removing/filling them. I have an idea for an algorithm that I think would work, but I want to check if anything else already exists.&lt;/p&gt;&#xA;&lt;p&gt;As a visual example of what I mean, below is a mesh that, if such a technique were applied, would have the orange-highlighted faces removed and be turned into an ordinary cube.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZgizM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZgizM.png&quot; alt=&quot;An example of a mesh that would become a cube if such a technique were applied&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;At the same time, though, the problem is not as simple as just taking the convex hull, because this mesh, for example, is fine as it is.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/Cg6p5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Cg6p5.png&quot; alt=&quot;A mesh shaped like a 3D letter C&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15856" LastEditorUserId="15856" LastEditDate="2021-02-28T00:38:10.683" LastActivityDate="2021-03-02T02:07:11.033" Title="Existing method to automatically fill in this sort of concavity in meshes?" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;" AnswerCount="1" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10701" PostTypeId="2" ParentId="10698" CreationDate="2021-02-27T23:48:51.543" Score="3" Body="&lt;p&gt;Unsized arrays aren't implemented in HLSL. You can pass fixed-size arrays into functions like&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void foo(float2 x[2][4])&#xA;{&#xA;    ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;(Note the brackets go after the parameter name, not after the type—just like declaring a variable.)&lt;/p&gt;&#xA;&lt;p&gt;However, having different array sizes that can be passed into the same function won't work in HLSL the way it would in C/C++. For variable-size data, better to use a buffer resource, such as a constant buffer, structured buffer, etc (depending on what you're doing with this data). Or if it's in &lt;code&gt;groupshared&lt;/code&gt; memory, you'll have to specify a maximum size and allocate the array for that.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-02-27T23:48:51.543" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10702" PostTypeId="1" AcceptedAnswerId="10703" CreationDate="2021-02-28T20:27:57.833" Score="0" ViewCount="49" Body="&lt;p&gt;What is the name of the style of the line graphics used in the image below? The line patterns seem to envelope the shape of the woman maybe algorithmically somehow, becoming denser and yellow on the chest.&lt;/p&gt;&#xA;&lt;p&gt;Are there other artists that employ this technique, or where it was borrowed from?&lt;/p&gt;&#xA;&lt;p&gt;Besides the line patterns, the coloring of the lines gives a holographic sort of feeling. Is there also a distinct style name for the coloring scheme used for the lines?&lt;/p&gt;&#xA;&lt;p&gt;Any ideas overall on which software and computer graphics/machine learning techniques were used to create the line patterns and colors?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YGc7x.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YGc7x.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15860" LastActivityDate="2021-02-28T21:05:49.297" Title="Name and influence of style used for futuristic line patterns?" Tags="&lt;color&gt;&lt;line-drawing&gt;&lt;refraction&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10703" PostTypeId="2" ParentId="10702" CreationDate="2021-02-28T21:05:49.297" Score="3" Body="&lt;p&gt;That looks a lot like it’s based on the &lt;a href=&quot;https://en.wikipedia.org/wiki/Straight_skeleton&quot; rel=&quot;nofollow noreferrer&quot;&gt;straight skeleton&lt;/a&gt; of some outline shapes drawn on the image. You can see similar structures in the middle one of these diagrams from &lt;a href=&quot;https://www.sthu.org/research/straightskeleton/&quot; rel=&quot;nofollow noreferrer&quot;&gt;a research page&lt;/a&gt; by Stefan Huber, one of the researchers who’s published a lot of work on straight skeletons:&#xA;&lt;img src=&quot;https://i.stack.imgur.com/lsY7C.png&quot; alt=&quot;a series of images of Tux, the Linux penguin mascot, one with skeletal patterns overlaid and one with isocontours derived from those patterns&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-02-28T21:05:49.297" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10704" PostTypeId="2" ParentId="10700" CreationDate="2021-03-02T02:07:11.033" Score="3" Body="&lt;p&gt;After a fair bit of reading and skimming through papers, I have yet to find a good definition other than &amp;quot;indent&amp;quot; for what I want to remove, but I &lt;em&gt;have&lt;/em&gt; found answers to pretty much everything else.&lt;/p&gt;&#xA;&lt;p&gt;The concept of a &amp;quot;&lt;a href=&quot;https://en.wikipedia.org/wiki/Visual_hull&quot; rel=&quot;nofollow noreferrer&quot;&gt;Visual Hull&lt;/a&gt;&amp;quot; is what I was looking for regarding a mesh that doesn't have these indents. While the Wikipedia page, and a bunch of other resources, usually just refer to visual hulls created from a finite set of viewpoints, e.g. a set of real-life cameras, Laurentini, who introduced the term &amp;quot;Visual Hull&amp;quot;, also introduces a term &amp;quot;External Visual Hull&amp;quot; to refer to one created using &lt;em&gt;every&lt;/em&gt; possible viewpoint outside of the convex hull [1]. This will have the exact same silhouette as the original mesh when viewed from any position outside the convex hull at any angle, so it was exactly what I was looking for.&lt;/p&gt;&#xA;&lt;p&gt;[1] also contains an algorithm for computing the external visual hull for polyhedra, but it is sorta brute-force and is &lt;span class=&quot;math-container&quot;&gt;$O(n^{12})$&lt;/span&gt;. In [2], Petitjean introduces a much more efficient algorithm for polyhedra, and Bottino and Laurentini also describe a more efficient algorithm in [3]. In addition to these algorithms for polyhedra, other works by Laurentini also discuss algorithms for doing the same for curved objects, surfaces of revolution, etc. I have yet to come across anyone actually &lt;em&gt;implementing&lt;/em&gt; these algorithms, though.&lt;/p&gt;&#xA;&lt;p&gt;I'd like to describe all of these in more detail, but I still need to finish reading through them, and based on some deadlines coming up, I do not think I will have the time to do so for a little while. I hope to eventually come back to this post and edit it to actually describe at least one of the algorithms. However, if someone reading this wants to look these up for themselves, then in addition to the below citations, I would like to note that even if you don't normally have access to papers, e.g. through a post-secondary institution, all of these seem to be publicly available. You can download [1] from ResearchGate &lt;a href=&quot;https://www.researchgate.net/publication/3192242_The_Visual_Hull_Concept_for_Silhouette-Based_Image_Understanding&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;, download [2] from ResearchGate &lt;a href=&quot;https://www.researchgate.net/publication/2781058_A_Computational_Geometric_Approach_To_Visual_Hulls&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt; (though I have no clue why different authors are listed for it than Petitjean), and [3] can be found in Google Books.&lt;/p&gt;&#xA;&lt;p&gt;Citations:&lt;/p&gt;&#xA;&lt;p&gt;[1] Laurentini, Aldo. (1994). The Visual Hull Concept for Silhouette-Based Image Understanding. Pattern Analysis and Machine Intelligence, IEEE Transactions on. 16. 150-162. 10.1109/34.273735.&lt;/p&gt;&#xA;&lt;p&gt;[2] Petitjean, S. (1998). A computational geometric approach to visual hulls. International Journal of Computational Geometry &amp;amp; Applications, 8(04), 407-436.&lt;/p&gt;&#xA;&lt;p&gt;[3] Bottino, Andrea &amp;amp; Laurentini, Aldo. (2006). Retrieval of Shape from Silhouette. 10.1016/S1076-5670(05)39001-X.&lt;/p&gt;&#xA;" OwnerUserId="15856" LastActivityDate="2021-03-02T02:07:11.033" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10705" PostTypeId="2" ParentId="10677" CreationDate="2021-03-02T09:01:58.910" Score="2" Body="&lt;p&gt;Not 3D as such, but it seems in 1963 &lt;a href=&quot;http://www.icetcs.ru.is/SutherlandPOCHannes.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ivan Sutherland's&lt;/a&gt; seminal &lt;a href=&quot;https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-574.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;&amp;quot;Sketchpad&amp;quot;&lt;/a&gt; (and &lt;a href=&quot;https://en.wikipedia.org/wiki/Sketchpad&quot; rel=&quot;nofollow noreferrer&quot;&gt;wikipedia&lt;/a&gt;) had instancing. eg. See &amp;quot;&lt;em&gt;Chapter VI RECURSIVE FUNCTIONS&lt;/em&gt;&amp;quot; of the 2nd reference.&lt;/p&gt;&#xA;&lt;p&gt;IIRC somewhere there's a video of it in action - it made me annoyed as to how some of today's vector drawing tools don't seem to be able to do some of what sketchpad appeared to support.&lt;/p&gt;&#xA;&lt;p&gt;Update: @Joojaa has kindly &lt;a href=&quot;https://www.youtube.com/watch?app=desktop&amp;amp;v=57wj8diYpgY&quot; rel=&quot;nofollow noreferrer&quot;&gt;located a video&lt;/a&gt;   or &lt;a href=&quot;https://www.youtube.com/watch?v=6orsmFndx_o&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="209" LastEditorUserId="209" LastEditDate="2021-03-03T07:18:34.520" LastActivityDate="2021-03-03T07:18:34.520" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10706" PostTypeId="2" ParentId="10696" CreationDate="2021-03-02T10:59:26.550" Score="2" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Everything in this code functions as intended, until I try to translate the entire grid (grid lines) to the center of the screen by adding v_Resolution.x / 2 to uv.x.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Not sure what your intention is here since the Shadertoy example you referenced generates an infinite grid. So maybe you can clarify that.&lt;/p&gt;&#xA;&lt;p&gt;However, I think I can help you with this problem:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;... the ShaderToy example, the coordinates are not normalized at all, and it functions perfectly fine! I feel like I'm missing a very important concept here.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I think the basic problem here is, that you do not really understand how the mesh is generated and why the Shadertoy example isn't normalizing the uv-coordinates. If I can help you understand it, you can probably fix your other problems by yourself.&lt;/p&gt;&#xA;&lt;p&gt;So let's walk through the Shadertoy code and what it actually does:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = fragCoord.xy;&#xA;    &#xA;// Correct the coordinates by taking into account the aspect ratio (turns the grid into perfect squares).&#xA;uv.x *= 1.0 / spacing;&#xA;uv.y /= spacing;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here you first copy the frag coordinates into &lt;code&gt;uv&lt;/code&gt; and afterward divide it by the spacing of your lines. Not sure why the author used those 'complicated' last two lines, but you can replace them simply with &lt;code&gt;uv /= spacing;&lt;/code&gt;.&#xA;The purpose of this step is to transform into a new space where the lines of your grid are located at every whole number. If your spacing is 20, like in the shader toy example, only the fragments with one of its frag coordinates being one of 0, 20, 40, etc. would produce a whole number and would be located on a line. Maybe you can already see where this is going.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Adjust the origin of each line thicker than one pixel to its center.&#xA;uv.xy += (lineWidth &amp;gt; 1) ? width * 0.5 : width;&#xA;    &#xA;// Make the grid resolution independent by offsetting the Y coordinates based on the current viewport height.&#xA;uv.y -= (iResolution.y - 600.0) / spacing;&#xA;    &#xA;// Apply camera translation.&#xA;uv.x -= translation.x / spacing;&#xA;uv.y += translation.y / spacing;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here he is just translating the grid to consider several things like line thickness and camera position. The camera position is probably what you are interested in. I have no clue, about the purpose of the second line, even though the comment specifies it, but it is just a y-shift of your grid. However, note that all translations must be in the &amp;quot;grid-space&amp;quot; like the uv coordinates. Hence he always divides by &lt;code&gt;spacing&lt;/code&gt;. For &lt;code&gt;width&lt;/code&gt;, he already applied the transformation several lines above -&amp;gt; &lt;code&gt;float width   = float(lineWidth)   / spacing;&lt;/code&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float grid = 0.0;&#xA;grid = max(step(fract(uv.x), width), grid); // X lines (horizontal)&#xA;grid = max(step(fract(uv.y), width), grid); // Y lines (vertical)&#xA;&#xA;vec4 col = vec4(grid);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now here comes the magic that actually produces the grid. Let's dissect the second line. &lt;code&gt;fract(uv.x)&lt;/code&gt; just &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/fract.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;returns the fractional part&lt;/a&gt; of &lt;code&gt;uv.x&lt;/code&gt;. So a value of &lt;code&gt;12.125&lt;/code&gt; is reduced to &lt;code&gt;0.125&lt;/code&gt;. The &lt;a href=&quot;https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/step.xhtml&quot; rel=&quot;nofollow noreferrer&quot;&gt;step function&lt;/a&gt; returns 0 if the second value is smaller than the first and 1 otherwise. So the point of &lt;code&gt;step(fract(uv.x), width)&lt;/code&gt; frac is to get a &lt;code&gt;1&lt;/code&gt; if the uv coordinate is on a vertical line and 0 if not. The &lt;code&gt;max&lt;/code&gt; in this line is pretty pointless since &lt;code&gt;grid&lt;/code&gt; (which is set to &lt;code&gt;0.0&lt;/code&gt;) is either equal to the returned value or less. The third line does the same thing for horizontal lines, but here the &lt;code&gt;max&lt;/code&gt; is actually needed.&#xA;So to sum it up, &lt;code&gt;grid&lt;/code&gt; is &lt;code&gt;1&lt;/code&gt; if the fragment lies on a horizontal and/or vertical line and &lt;code&gt;0&lt;/code&gt; if not.&#xA;The last line just turns that into a vector. So you either get pure white (&lt;code&gt;(1.0, 1.0, 1.0, 1.0)&lt;/code&gt;) as pixel color if the fragment is part of a line or pure black (&lt;code&gt;(0.0, 0.0, 0.0, 0.0)&lt;/code&gt;) if not. Note that if alpha blending is enabled, black is actually translucent since the alpha channel is also &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;if (col.r != 0.0 &amp;amp;&amp;amp; col.g != 0.0 &amp;amp;&amp;amp; col.b != 0.0) {&#xA;    float mx = mod(uv.x, float(darkenMultiple));&#xA;    float my = mod(uv.y, float(darkenMultiple));&#xA;        &#xA;    // Make lines that are a multiple of `darkenMultiple` darker than the rest.&#xA;    col.a = (mx &amp;lt; width || my &amp;lt; width) ? 0.2 : 0.15;&#xA;} else {&#xA;    // Turn all pixels that aren't apart of the grid invisible as to not cover the rest of the scene.&#xA;    col.a = 0.0;&#xA;}&#xA;    &#xA;col = showNyanCat(col, fragCoord);&#xA;    &#xA;fragColor = col;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This just adjusting the color of the grid and plotting the cat and not relevant to your question.&lt;/p&gt;&#xA;&lt;p&gt;I optimized the shader from the Shadertoy example a little bit by removing obsolete instructions, postponing the transformation into &amp;quot;grid space&amp;quot; after applying the translations, and vectorizing some operations. Maybe it makes it easier for you to understand what is happening. I kept the original comments and added some own ones:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void mainImage( out vec4 fragColor, in vec2 fragCoord ) {&#xA;    // Define some variables we use ---------------------------------------------&#xA;    // Simulate camera translation, just for this example.&#xA;    vec2 velocity = vec2(-30.0, 10.0);  &#xA;    translation += scale * iTime * velocity;&#xA;    &#xA;    float spacing = float(lineSpacing) * scale;&#xA;    float width   = float(lineWidth)   / spacing;&#xA;        &#xA;    // Add all translations to uv -----------------------------------------------&#xA;    // Apply camera translation.&#xA;    vec2 uv = fragCoord - translation;&#xA;    &#xA;    // Make the grid resolution independent by offsetting the Y coordinates based on the current viewport height.&#xA;    uv.y -= (iResolution.y - 600.0);&#xA;    &#xA;    // Adjust the origin of each line thicker than one pixel to its center.&#xA;    uv += (lineWidth &amp;gt; 1) ? float(lineWidth) * 0.5 : float(lineWidth);&#xA;&#xA;    // Transform to &amp;quot;grid space&amp;quot; ------------------------------------------------    &#xA;    // Correct the coordinates by taking into account the aspect ratio (turns the grid into perfect squares).&#xA;    uv /= spacing;&#xA;    &#xA;&#xA;    // Identify if pixel is on a line -------------------------------------------&#xA;    float grid =     step(fract(uv.x), width)       ; // X lines (horizontal)&#xA;    grid       = max(step(fract(uv.y), width), grid); // Y lines (vertical)&#xA;    &#xA;    // Set the correct color ----------------------------------------------------&#xA;    vec4 col = vec4(grid);&#xA;    if (grid != 0.0) {&#xA;        float mx = mod(uv.x, float(darkenMultiple));&#xA;        float my = mod(uv.y, float(darkenMultiple));        &#xA;        &#xA;        // Make lines that are a multiple of `darkenMultiple` darker than the rest.&#xA;        col.a = (mx &amp;lt; width || my &amp;lt; width) ? 0.2 : 0.15;&#xA;    } &#xA;    &#xA;    // Plot the cat -------------------------------------------------------------&#xA;    col = showNyanCat(col, fragCoord);&#xA;    &#xA;    fragColor = col;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In this version, you can simply add your translations in pixels without any need to transform them to &amp;quot;grid space&amp;quot; or to normalize them. Hope that helps. You can copy it into the Shadertoy example to see that the results are the same.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Now, if I remember correctly, the origin in a GLSL fragment shader is bottom left, so why do I have to subtract v_Resolution.x / 2.f instead of adding it?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Probably because you use different signs here:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Apply camera translation.&#xA;uv.x += v_CamPos.x / v_CellSize;&#xA;uv.y -= v_CamPos.y / v_CellSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;(also, why is the x-component not normalized, like the y-component?)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I guess you fiddled around until &amp;quot;something&amp;quot; produced the expected image rather than knowing what happens. I see no point in investigating the &amp;quot;why&amp;quot; here. Understand the Shadertoy code (or my version) and then apply your changes while actually knowing what you are doing. If you use my version, all you have to add are the translations in pixels that you want to apply.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;h2&gt;Update&lt;/h2&gt;&#xA;&lt;p&gt;Regarding the comment of Andrew Woo:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I really appreciate the in-depth explanation, it helped a lot in my understanding, however it doesn't really answer my [original] question, which was why the x-component of uv isn't normalized.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I was addressing that at the end of the original answer when I said that you fiddled around until &amp;quot;something&amp;quot; worked and I didn't saw any point in investigating why &amp;quot;obviously wrong&amp;quot; code produces the correct result.&lt;/p&gt;&#xA;&lt;p&gt;Well, let's get something clear: uv coordinates are not screen coordinates. So &lt;code&gt;gl_FragCoord.y / v_Resolution.y&lt;/code&gt; is not the general definition of &lt;code&gt;v&lt;/code&gt;. I would rather call them &amp;quot;normalized screen coordinates&amp;quot;. uv coordinates are (usually) used to map regular 2-dimensional data like an image onto a surface. You can read more about them on &lt;a href=&quot;https://en.wikipedia.org/wiki/UV_mapping&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;. Don't be fooled by the fact that the author of the question you linked used the &amp;quot;normalized screen coordinates&amp;quot; as uv coordinates. They might be the same if you want to map an image to your screen, but usually, they are not.&lt;/p&gt;&#xA;&lt;p&gt;In the shadertoy example, the uv coordinates are used to map a single cell of your grid. You start using uv coordinates of the grid after you divided the frag coordinates by the cell size. Before that, they are no uv coordinates, at least not in relation to the grid.&lt;/p&gt;&#xA;&lt;p&gt;So let's summarize what the shader does: You start with pixel coordinates inside your shader with values between 0 and the screen resolution in either direction and you want to calculate the uv coordinates of the grid in order to draw it. That's the whole purpose of the code we discussed. Do we need to divide by the screen resolution for that? No, we don't. We could if it would make our life easier to get from A to B, but we simply do not need it here and the original shadertoy algorithm doesn't do it.&lt;/p&gt;&#xA;&lt;p&gt;So the question shouldn't be &amp;quot;why the x-component of uv isn't normalized&amp;quot; but:&lt;/p&gt;&#xA;&lt;p&gt;&amp;quot;Why do I get the correct result when I use normalized screen coordinates instead of fragment coordinates for the y-component and wrong ones if not&amp;quot;?&lt;/p&gt;&#xA;&lt;p&gt;I have not tested your code, but by just looking at it, I would say by normalizing the y component here: &lt;code&gt;(gl_FragCoord.y / v_Resolution.y) + (v_Resolution.y / 2.f)&lt;/code&gt; you are more or less &amp;quot;removing&amp;quot; them from the line. Just insert the numbers:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;code&gt;gl_FragCoord.y / v_Resolution.y&lt;/code&gt; is a number between 0 and 1&lt;/li&gt;&#xA;&lt;li&gt;&lt;code&gt;v_Resolution.y / 2.f&lt;/code&gt; is 309&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;So at this point, you have v-values between 309 and 310. It is almost a constant. Simply remove &lt;code&gt;gl_FragCoord.y / v_Resolution.y&lt;/code&gt; and you should still get the same result. Now the question arises, why is the grid still rendered correctly? I guess because of this line:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Make the grid resolution independent by offsetting the Y coordinates based on the current viewport height.&#xA;    uv.y -= gl_FragCoord.y / v_CellSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Note that you use &lt;code&gt;gl_FragCoord.y&lt;/code&gt; while the Shadertoy code used &lt;code&gt;iResolution.y&lt;/code&gt;, which is a constant. What you do here is correcting the effective removal of gl_FragCoord.y I explained before. You need to divide by &lt;code&gt;v_CellSize&lt;/code&gt; because the uv coordinates were also divided by &lt;code&gt;v_CellSize&lt;/code&gt; 2 instructions before (&lt;code&gt;uv.y /= v_CellSize;&lt;/code&gt;).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;How to correct it?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Simply remove this line:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;uv.y -= gl_FragCoord.y / v_CellSize;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then remove the division through &lt;code&gt;v_Resolution.y&lt;/code&gt; from here:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec2 uv = vec2(gl_FragCoord.x, gl_FragCoord.y / v_Resolution.y + v_Resolution.y / 2 - v_CellSize / 2);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;It should look like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void main() {&#xA;&#xA;    float width = lineWidth / v_CellSize;&#xA;&#xA;    vec2 uv = vec2(gl_FragCoord.x, gl_FragCoord.y + v_Resolution.y / 2 - v_CellSize / 2);&#xA;&#xA;    uv.x *= 1.0 / v_CellSize;&#xA;    uv.y /= v_CellSize;&#xA;&#xA;    // Adjust the origin of each line thicker than one pixel to its center.&#xA;    uv.xy += (lineWidth &amp;gt; 1) ? width * 0.5 : width;&#xA;    &#xA;&#xA;    // Apply camera translation.&#xA;    uv.x += v_CamPos.x / v_CellSize;&#xA;    uv.y -= v_CamPos.y / v_CellSize;&#xA;    &#xA;    float grid = 0.0;&#xA;    grid = max(step(fract(uv.x), width), grid); // X lines (horizontal)&#xA;    grid = max(step(fract(uv.y), width), grid); // Y lines (vertical)&#xA;    &#xA;    vec4 col = vec4(grid);&#xA;&#xA;    // ... insert rest of your code &#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Now you should have the &amp;quot;correct&amp;quot; result and the x and y components are treated identically.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastEditorUserId="13095" LastEditDate="2021-03-06T18:18:24.877" LastActivityDate="2021-03-06T18:18:24.877" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10707" PostTypeId="1" CreationDate="2021-03-03T12:40:55.883" Score="2" ViewCount="39" Body="&lt;h3&gt;Background&lt;/h3&gt;&#xA;&lt;p&gt;I need to remesh by OpenVDB, like what &lt;a href=&quot;https://docs.blender.org/manual/en/dev/modeling/modifiers/generate/remesh.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Blender remesh&lt;/a&gt; does:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/CJikC.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/CJikC.png&quot; alt=&quot;Blender screenshot&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;Voxel&lt;/p&gt;&#xA;&lt;p&gt;Uses an OpenVDB to generate a new manifold mesh from the current geometry while trying to preserve the mesh’s original volume.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;h3&gt;Problem&lt;/h3&gt;&#xA;&lt;p&gt;The problem is that OpenVDB gets a constant &lt;em&gt;voxel size&lt;/em&gt;. But I have meshes with varying polygon density/granularity, i.e. high-detail and low-detail components. To preserve the topology of high-detail components, the &lt;em&gt;voxel size&lt;/em&gt; has to be too small for the whole 3d model.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jdt0F.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jdt0F.png&quot; alt=&quot;Polygon granularity/density&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3&gt;Possible workaround&lt;/h3&gt;&#xA;&lt;p&gt;A mesh might be broken down into distinct components of higher detail and lower detail.&lt;/p&gt;&#xA;&lt;h3&gt;Question&lt;/h3&gt;&#xA;&lt;p&gt;Is there any algorithm or library to help me break down the mesh into distinct components according to level of detail? I looked at &lt;a href=&quot;https://doc.cgal.org/latest/Polygon_mesh_processing/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;CGAL&lt;/a&gt;, but I couldn't figure out.&lt;/p&gt;&#xA;" OwnerUserId="9169" LastActivityDate="2021-03-03T12:40:55.883" Title="Divide mesh according to level of detail" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;polygon&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10709" PostTypeId="1" CreationDate="2021-03-04T11:18:20.407" Score="1" ViewCount="44" Body="&lt;p&gt;Some background of my scenario: I have two images of indirect radiance, both are from an animation. I will reproject an pixel from the previous frame to current frame, and I want to do comparisons with them. Both have been path traced with quite high sample count, but some noise still remains.&lt;/p&gt;&#xA;&lt;p&gt;I want to focus on reprojecting, so two questions:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Does it make sense applying a denoising filter to the images prior to comparing them, to lower the variance? Frankly, I don't see a reason why not, but not completely sure.&lt;/li&gt;&#xA;&lt;li&gt;What filter would give the highest quality (PSNR/SSIM against higher spp count) results? I have stumbled upon gaussian, blackman-harris and bilateral filters, but they have been used on final (indirect + direct) colors.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="15574" LastActivityDate="2021-03-04T11:18:20.407" Title="What denoising filter gives highest quality for indirect light image?" Tags="&lt;pathtracing&gt;&lt;filtering&gt;&lt;gaussian-blur&gt;&lt;denoise&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10710" PostTypeId="1" AcceptedAnswerId="10711" CreationDate="2021-03-04T20:20:08.087" Score="0" ViewCount="28" Body="&lt;p&gt;Modern operating systems support a wide range of resolutions. Mine ranges from 800x600 to 1920x1080. They also support multi-displays. I've never tried it but I have seen other users with 2 or 3 monitors.&lt;/p&gt;&#xA;&lt;p&gt;I'd like to know some details about how this is all supported. The trivial way is to size the graphics card buffer for the largest possible display, and then crop off any unused parts before sending it out the video port. But a little math, so 1920x1080, 24 bit color, is about 6.2 MB, which is not that big at all for a piece of VRAM. However, then we get to multi-display. What is a reasonable max number for displays? 4? 8? And then don't forget you want to support high frame rates of at least 60 fps, maybe 120 or even 240. Then remember you should support double- or even triple-buffering.&lt;/p&gt;&#xA;&lt;p&gt;Not to mention, I have seen bigger rez monitors online that advertise themselves as compatible with Windows 7 and 10. So it seems to me that just providing the max possible buffer size is not feasible. The &amp;quot;max&amp;quot; changes too rapidly these days.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; I can understand if every monitor and GPU comes with its own driver. What I'm trying to understand is how &lt;strong&gt;one set of hardware&lt;/strong&gt; can support a very wide range of screen resolutions &lt;strong&gt;without being trivially wasteful&lt;/strong&gt;. Is there some clever way of doing this?&lt;/p&gt;&#xA;&lt;p&gt;Disclaimer: I'm a CS guy and don't keep up with modern hardware. I used to read a little about various hardware back in late 90s / early 00s, but never worked on it career-wise or hobby-wise. I can build my own comp and understand basic specs of most parts, but the graphics capabilities are the biggest mystery and &amp;quot;dark arts&amp;quot; to me (other than RAM timings).&lt;/p&gt;&#xA;" OwnerUserId="15877" LastActivityDate="2021-03-05T01:40:02.880" Title="How does the OS + hardware support multiple screen resolutions and multi-display?" Tags="&lt;gpu&gt;&lt;hardware&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10711" PostTypeId="2" ParentId="10710" CreationDate="2021-03-05T01:40:02.880" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Any hardware in the graphics card is fixed.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;No, the &lt;em&gt;storage&lt;/em&gt; of a graphics card is fixed. How that storage gets used, particularly on any semi-modern graphics card, is flexible.&lt;/p&gt;&#xA;&lt;p&gt;Essentially, what a graphics display device has is a mechanism for being told, &amp;quot;the bytes of video memory starting at address X is in format Y and size Z; send it at the next vblank period to display device W&amp;quot;. Really old graphics cards had specific memory structures for holding framebuffers, which imposed strict limits on how things could work. But that hasn't been the case on PCs for a good decade at least.&lt;/p&gt;&#xA;&lt;p&gt;There may be limitations on how many display devices a particular piece of hardware could hypothetically output to, or the sizes and formats which the hardware can use. Some hardware devices may only be able to use non-virtualized GPU addresses (which I'd guess is why NVIDIA has special memory types for allocating render targets) or somesuch, but even that is a matter of the user interface, not what the internal hardware is doing. As far as the display device's output is concerned, it could use more or less any GPU memory address.&lt;/p&gt;&#xA;&lt;p&gt;So, what happens when you plug in a new display device? The OS allocates a framebuffer's (or two) worth of video memory for that display device's video output. If you change the resolution of a display device, the OS allocates a differently-sized slice of memory and frees the prior framebuffer allocation. And so forth.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-05T01:40:02.880" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10712" PostTypeId="1" AcceptedAnswerId="10716" CreationDate="2021-03-05T05:30:57.340" Score="0" ViewCount="155" Body="&lt;p&gt;This topic would contain a lot of sub questions because I have one for each shape but for today I just want to understand the function for a torus and a capped torus&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://iquilezles.org/www/articles/distfunctions/distfunctions.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;This&lt;/a&gt; is the article for all shapes and I am trying to understand the code for torus&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float sdTorus( vec3 p, vec2 t )&#xA;{&#xA;  vec2 q = vec2(length(p.xz)- &#xA;  t.x,p.y);&#xA;  return length(q)-t.y;&#xA; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and capped torus&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt; float sdCappedTorus(in vec3 p, &#xA;  in vec2 sc, in float ra, in &#xA;  float rb)&#xA;{&#xA;  p.x = abs(p.x);&#xA;&#xA;  float k = (sc.y*p.x&amp;gt;sc.x*p.y) ? &#xA;  dot(p.xy,sc) : length(p.xy);&#xA;&#xA;   return sqrt( dot(p,p) + ra*ra &#xA; - 2.0*ra*k ) - rb;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I have so many questions. I know parameter P is the point for testing but what is t? what is ra and rb? what calculations are they doing what are the mathematics?&lt;/p&gt;&#xA;&lt;p&gt;Just a theoretical explanation or some images explaining the general formula would be greatly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="15434" LastActivityDate="2021-03-05T15:06:07.707" Title="understanding SDF[Signed Distance Functions] for a torus" Tags="&lt;mathematics&gt;&lt;raymarching&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10713" PostTypeId="2" ParentId="10712" CreationDate="2021-03-05T09:49:04.787" Score="0" Body="&lt;p&gt;The following video discusses the SDFs of various primitives (linked to torus section):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://youtu.be/Ff0jJyyiVyw?t=491&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://youtu.be/Ff0jJyyiVyw?t=491&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;It discusses a torus but not the capped variant. The rest of the channel has useful content as well.&lt;/p&gt;&#xA;&lt;p&gt;Additionally, iq has videos on detailed derivations of some primitives and techniques, sometimes hidden in the long livestreams, which are well worth a watch if you want to learn more about graphics methods and demoscene tricks:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/c/InigoQuilez/videos&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/c/InigoQuilez/videos&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15879" LastEditorUserId="15879" LastEditDate="2021-03-05T10:22:18.027" LastActivityDate="2021-03-05T10:22:18.027" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10714" PostTypeId="1" AcceptedAnswerId="10715" CreationDate="2021-03-05T13:30:26.897" Score="2" ViewCount="48" Body="&lt;p&gt;Should I expect that every invocation/fragment within a subgroup, when using something like &lt;code&gt;subgroupBroadcast()&lt;/code&gt;, will belong to the same triangle?&lt;/p&gt;&#xA;" OwnerUserId="15705" LastActivityDate="2021-04-13T15:05:43.067" Title="How do fragment shader invocations subgroups map onto triangles?" Tags="&lt;vulkan&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10715" PostTypeId="2" ParentId="10714" CreationDate="2021-03-05T15:02:18.727" Score="3" Body="&lt;p&gt;Fragment shader subgroups are not required to be restricted to a single primitive (and such a restriction would negatively impact performance). So subgroup broadcasting can cross primitive boundaries.&lt;/p&gt;&#xA;&lt;p&gt;Note that the most recent version of the Vulkan standard states that invocations in the same quad scopes are required to be within the same primitive scope.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2021-04-13T15:05:43.067" LastActivityDate="2021-04-13T15:05:43.067" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10716" PostTypeId="2" ParentId="10712" CreationDate="2021-03-05T15:06:07.707" Score="1" Body="&lt;p&gt;This turned into a rabbit hole for me hopefully it helps answer your question, I recommend trying out the various functions on the &lt;a href=&quot;https://www.shadertoy.com/view/3ltSW2&quot; rel=&quot;nofollow noreferrer&quot;&gt;ShaderToy&lt;/a&gt; website. Just drop them in and change the call to &amp;quot;sdCircle&amp;quot;. I used the values R=0.75 and r=0.35 to test them out.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Part 1: Defining what an SDF means&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Signed Distance Field or SDF, in this context, is a function that returns the signed distance from a point to a primitive. The returned value is always a float that can take on 3 context specific meanings.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;zero: This is on the surface, while it is rare to hit exactly on the surface of the primitive we can approximate a hit with a simple inequality like &lt;code&gt;abs(d)&amp;lt;sigma&lt;/code&gt; where d is the signed distance and sigma is some small value like 0.001.&lt;/li&gt;&#xA;&lt;li&gt;negative: In this context negative values represent hits inside the primitive but choosing the meaning of a negative return value is context specific. Smaller (more negative) values represent values that are deeper in the interior of the primitive.&lt;/li&gt;&#xA;&lt;li&gt;positive: Again this is context specific, but in this case this is a hit outside the primitive and larger values mean it is farther away from the primitive.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Stop for a second and take another look at the first case, &amp;quot;zero&amp;quot;. This may seem unimportant at first glance but it turns out that by defining a generic base primitive and then changing the value of sigma we can easily compute a primitive of any size. In the case of a torus we could have a very thin torus or one that is so big it envelopes itself. Then by adding one more variable representing the large Radius of the torus, the torus can now be changed to fit our needs as desired just by controlling two variables.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Part 2: Defining the primitive&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;Take a look at IQ's 2D function for a circle.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float sdCircle( vec2 p, float r ){ return length(p) - r; }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;All this function is doing is computing the &amp;quot;distance&amp;quot; using the length function of our point &amp;quot;p&amp;quot; from our circle (which is sitting at the origin) then subtracting our radius &amp;quot;r&amp;quot;. And easy as that any point greater then radius is positive, any point less then radius is negative.&lt;/p&gt;&#xA;&lt;p&gt;This is almost a torus already, we are just missing the signed distance for the inside diameter of the 2D torus. But we already know that is really just some sigma value from our original circle, so all we have to do is add a second radius and compute the sigma.&#xA;So:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float sdTorus2D( vec2 p, float R, float r )&#xA;{&#xA;  float q = length(p)-R;&#xA;  return abs(q)-r;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;No need to recalculate the distance, so just figure out sigma to our second circle with &lt;code&gt;abs(q)-r&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Part 3: Going 3D&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;If you stop and think about it for a second (ok...maybe more then a second) then it is easy to realize that our 2D torus is just a slice of a 3D torus. When you think about it like that then we can take another slice of our torus in 2D on its edge just by rotating our torus 90 degrees. This should result in two SDF circles side by side.&lt;/p&gt;&#xA;&lt;p&gt;But turning the torus on its side is really just a matter of computing our signed distances in the opposite order...lets try:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float sdTorus2DSide( vec2 p, float R, float r )&#xA;{&#xA;  vec2 q = vec2(abs(p.x)-R,p.y);&#xA;  return length(q)-r;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The two different views essentially compute the distance in two different ways, so by combining them we should be able to view our torus in 3D from any angle just by adding an extra component &amp;quot;z&amp;quot; so that both computations can be independent of each other. Then combine our two radii into a vec2 and we end up with a function that looks just like IQ's.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float sdTorus( vec3 p, vec2 t )&#xA;{&#xA;  vec2 q = vec2(length(p.xz)-t.x,p.y);&#xA;  return length(q)-t.y;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This would still look two dimensional in the &amp;quot;circle&amp;quot; shadertoy, but now we can vary z to look at the torus slices. Or rotate our view point and see it emerge from the 2D world.  Neat stuff!&lt;/p&gt;&#xA;&lt;p&gt;BTW you can go through this same process with many primitives and get many different shapes as IQ has demonstrated on his website.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-03-05T15:06:07.707" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10717" PostTypeId="1" CreationDate="2021-03-06T15:47:16.393" Score="0" ViewCount="52" Body="&lt;p&gt;In &lt;a href=&quot;https://www.kevinbeason.com/smallpt/&quot; rel=&quot;nofollow noreferrer&quot;&gt;smallpt's&lt;/a&gt; source at line 90 the direction is multiplied by &lt;code&gt;140&lt;/code&gt; and I was wondering where that number is coming from. I was hoping for it to be explained in the &lt;a href=&quot;https://drive.google.com/file/d/0B8g97JkuSSBwUENiWTJXeGtTOHFmSm51UC01YWtCZw/view&quot; rel=&quot;nofollow noreferrer&quot;&gt;slides&lt;/a&gt; attached to the source but I couldn't find an explanation for where that number is coming from.&lt;/p&gt;&#xA;&lt;p&gt;If I increase the number(to &lt;code&gt;160.0&lt;/code&gt; for example) it starts giving some kind of weird zoom-out effect:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/o9XWE.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o9XWE.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And if I decrease the number(in this example to &lt;code&gt;125.0&lt;/code&gt;) I get this partially black picture:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/7KkJ2.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/7KkJ2.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As I understand it, after I've simplified smallpt a little bit, in the &lt;code&gt;main&lt;/code&gt; function we get a random point in each subpixel normalized by the width/height between &lt;code&gt;-0.5&lt;/code&gt; and &lt;code&gt;0.5&lt;/code&gt;, and then calculate the new ray direction by multiplying the x and y axis by these offsets, then adding everything together to obtain the new direction, something like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;fov_scale = 2.0 * tan(vertical_fov / 2.0)&#xA;cam_x_axis = vec3(aspect_ratio * fov_scale, 0, 0)&#xA;cam_y_axis = normalize(cross(cam_x_axis, cam_direction))&#xA;&#xA;for x, y:&#xA;    for sx, sy, samps:&#xA;        // not using smallpt's tent filter&#xA;        x_in_subpixel = x + sx * 0.5 + erand48(Xi) * 0.5&#xA;        y_in_subpixel = y + sy * 0.5 + erand48(Xi) * 0.5&#xA;        // normalize them between -0.5 and 0.5&#xA;        new_x = x_in_subpixel / w - 0.5&#xA;        new_y = y_in_subpixel / h - 0.5&#xA;&#xA;        offset_x = cam_x_axis * new_x&#xA;        offset_y = cam_y_axis * new_y&#xA;        new_direction = cam_direction + offset_x + offset_y&#xA;        // here we can see that magic number&#xA;        new_ray = ray(cam_position + new_direction * 140, normalize(new_direction))&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So my questions are:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;What does this number mean?&lt;/li&gt;&#xA;&lt;li&gt;Can I calculate it programmatically to be exactly what is expected(maybe depending on the field of view, width/height of the image)?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="15882" LastEditorUserId="15882" LastEditDate="2021-03-06T16:31:07.800" LastActivityDate="2021-03-06T16:31:07.800" Title="Magic number meaning in smallpt's camera ray calculation" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10718" PostTypeId="1" CreationDate="2021-03-07T14:00:24.417" Score="0" ViewCount="38" Body="&lt;p&gt;Recently I've switched from FXC to DXC to compile shader model 6.0. It compiles well without errors (and runs well) but I can't debug shaders because on my netbook PIX says &amp;quot;failed to load PDB file&amp;quot;, and on my main laptop PIX can't even start analysis and it shows the error &amp;quot;Timing Data Error&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9HiGI.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9HiGI.jpg&quot; alt=&quot;PIX error&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;What am I missing? The compilation generates PDB files (I can see them in the folder with the .exe) but PIX can't find them for some reason. I compile shaders like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    // Create compiler and utils.&#xA;    CComPtr&amp;lt;IDxcUtils&amp;gt; pUtils;&#xA;    CComPtr&amp;lt;IDxcCompiler3&amp;gt; pCompiler;&#xA;    DxcCreateInstance(CLSID_DxcUtils, IID_PPV_ARGS(&amp;amp;pUtils));&#xA;    DxcCreateInstance(CLSID_DxcCompiler, IID_PPV_ARGS(&amp;amp;pCompiler));&#xA;&#xA;    // Create default include handler.&#xA;    CComPtr&amp;lt;IDxcIncludeHandler&amp;gt; pIncludeHandler;&#xA;    pUtils-&amp;gt;CreateDefaultIncludeHandler(&amp;amp;pIncludeHandler);&#xA;&#xA;&#xA;    std::vector&amp;lt;LPCWSTR&amp;gt; vArgs;&#xA;    vArgs.push_back(sPathToShader.c_str());&#xA;    vArgs.push_back(L&amp;quot;-E&amp;quot;);&#xA;    vArgs.push_back(sShaderEntryPoint.c_str());&#xA;    vArgs.push_back(L&amp;quot;-T&amp;quot;);&#xA;    vArgs.push_back(sShaderModel.c_str());&#xA;    vArgs.push_back(DXC_ARG_DEBUG);&#xA;    vArgs.push_back(DXC_ARG_SKIP_OPTIMIZATIONS);&#xA;&#xA;&#xA;    // Open source file.  &#xA;    CComPtr&amp;lt;IDxcBlobEncoding&amp;gt; pSource = nullptr;&#xA;    pUtils-&amp;gt;LoadFile(sPathToShader.c_str(), nullptr, &amp;amp;pSource);&#xA;    DxcBuffer Source;&#xA;    Source.Ptr = pSource-&amp;gt;GetBufferPointer();&#xA;    Source.Size = pSource-&amp;gt;GetBufferSize();&#xA;    Source.Encoding = DXC_CP_ACP;&#xA;&#xA;    // Compile it with specified arguments.&#xA;    CComPtr&amp;lt;IDxcResult&amp;gt; pResults;&#xA;    pCompiler-&amp;gt;Compile(&#xA;        &amp;amp;Source,&#xA;        vArgs.data(),&#xA;        vArgs.size(),&#xA;        pIncludeHandler,&#xA;        IID_PPV_ARGS(&amp;amp;pResults)&#xA;    );&#xA;&#xA;&#xA;    // Print errors if present.&#xA;    CComPtr&amp;lt;IDxcBlobUtf8&amp;gt; pErrors = nullptr;&#xA;    pResults-&amp;gt;GetOutput(DXC_OUT_ERRORS, IID_PPV_ARGS(&amp;amp;pErrors), nullptr);&#xA;    if (pErrors != nullptr &amp;amp;&amp;amp; pErrors-&amp;gt;GetStringLength() != 0)&#xA;    {&#xA;        OutputDebugStringA(pErrors-&amp;gt;GetStringPointer());&#xA;    }&#xA;&#xA;&#xA;    // Quit if the compilation failed.&#xA;    HRESULT hrStatus;&#xA;    pResults-&amp;gt;GetStatus(&amp;amp;hrStatus);&#xA;    if (FAILED(hrStatus))&#xA;    {&#xA;        return;&#xA;    }&#xA;&#xA;&#xA;    // Save shader binary.&#xA;    CComPtr&amp;lt;IDxcBlob&amp;gt; pShader = nullptr;&#xA;    CComPtr&amp;lt;IDxcBlobUtf16&amp;gt; pShaderName = nullptr;&#xA;    pResults-&amp;gt;GetOutput(DXC_OUT_OBJECT, IID_PPV_ARGS(&amp;amp;pShader), &amp;amp;pShaderName);&#xA;    if (pShader == nullptr)&#xA;    {&#xA;        return;&#xA;    }&#xA;&#xA;&#xA;    // Save pdb.&#xA;    CComPtr&amp;lt;IDxcBlob&amp;gt; pPDB = nullptr;&#xA;    CComPtr&amp;lt;IDxcBlobUtf16&amp;gt; pPDBName = nullptr;&#xA;    pResults-&amp;gt;GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&amp;amp;pPDB), &amp;amp;pPDBName);&#xA;    {&#xA;        FILE* fp = NULL;&#xA;        _wfopen_s(&amp;amp;fp, pPDBName-&amp;gt;GetStringPointer(), L&amp;quot;wb&amp;quot;);&#xA;        fwrite(pPDB-&amp;gt;GetBufferPointer(), pPDB-&amp;gt;GetBufferSize(), 1, fp);&#xA;        fclose(fp);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="15888" LastActivityDate="2021-03-07T14:00:24.417" Title="Weird PIX behavior with DXC" Tags="&lt;c++&gt;&lt;hlsl&gt;&lt;directx12&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10719" PostTypeId="1" CreationDate="2021-03-07T17:35:07.293" Score="3" ViewCount="36" Body="&lt;p&gt;While I'll try my best to give all relevant info in all possible brevity below, please refer to the spoiler and link at the bottom of the post for the (more lengthy) original description if needed.&lt;/p&gt;&#xA;&lt;p&gt;Suppose for a buch of triangles, I put each triangle's surface area (along with a reference to the tri itself) into the nodes of a binary search tree.&#xA;Each internal node always contains the summed area of it's children. By consequence, the root node contains the summed area of all the tris at hand.&lt;/p&gt;&#xA;&lt;p&gt;Now the topological connectivity-info and the area-values of the binary tree are used to construct a kd-tree in the unit square which (the unit square) we call sample-space.&lt;br /&gt;&#xA;The kd-tree's root node corresponds to the whole unit square.&#xA;The sample-space is divided by an axis-aligned split line into two subsets (one for each child-node) such as to partition it by the same ratio by which the (mesh-triangle-) area-value of the aforementioned binary tree's root-node is partitioned by those of it's child-nodes.&#xA;This way, at each level, the kd-tree subdivides the sample-space into two subsets, the area of which is proportional to the area covered by the mesh triangles represented by the corresponding nodes in the binary tree.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FUAiH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FUAiH.jpg&quot; alt=&quot;source:Umenhoffer, Szécsi, Szirmay-Kalos - Hatching for Motion Picture Production (2011)&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&#xA;source:Umenhoffer, Szécsi, Szirmay-Kalos - &lt;a href=&quot;https://www.researchgate.net/publication/220506553_Hatching_for_Motion_Picture_Production&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hatching for Motion Picture Production (2011)&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;All of this serves as a means of mapping the sample-space onto the mesh triangles in object space in an area-preserving way.&#xA;It is used to perform quasi Monte-Carlo sampling in the sample space and use the datastructures outlined above to transform the samples from sample-space to the triangle's object space.&lt;/p&gt;&#xA;&lt;p&gt;I have omitted the details of how the algorithm effectively translates a (u,v) sample-position in sample-space into barycentric triangle-coordinates by traversing the kd-tree here for brevity.&#xA;(see the spoiler)&lt;/p&gt;&#xA;&lt;blockquote class=&quot;spoiler&quot;&gt;&#xA;&lt;p&gt;When we need to transform samples into the object-space,&#xA;we use the kd-tree. Given the (u,v)coordinates of the sam-&#xA;pled point, we start from the root of the tree, comparing the&#xA;coordinate of the splitting axis to the splitting ratio. Depend-&#xA;ing on the result of the comparison, we continue recursively&#xA;with one of the branches, normalizing the coordinate to the&#xA;cell’s [0,1]range. At a leaf, the (u,v)coordinates we get are&#xA;interpreted according to the natural parametrization of the&#xA;quadrilateral, or as two of the unit-sum barycentric coordi-&#xA;nates on the triangle (or (1−u,1−v)if u+v&amp;gt;1).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;The question is this&lt;/strong&gt;: Does the order of the leaf-nodes in the binary tree matter at all for this mapping (to preserve the properties of the QMC sampling during the transformation)?&lt;/p&gt;&#xA;&lt;p&gt;My intuition tells me 'no, it doesn't matter at all, a random order is as good as any other'. On the other hand, the authors of the &lt;a href=&quot;https://www.researchgate.net/publication/220506553_Hatching_for_Motion_Picture_Production&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; from which I've taken the algorithm outlined above state (section 4.1.1, §3)(bold typeface added by me for emphasis):&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;The faces of the model of the mesh are roughly arranged in a 1D&#xA;face array &lt;strong&gt;by proximity&lt;/strong&gt;. In typical cases, this naturally arises&#xA;from the modeling process. Otherwise, mesh optimization&#xA;algorithms (e.g. stripification) [DGGP05] can be applied.&#xA;First, we build a balanced binary tree, called the &lt;em&gt;summed&lt;/em&gt;&#xA;&lt;em&gt;area tree&lt;/em&gt;, in which leaf values are triangle surface areas &lt;strong&gt;in&lt;/strong&gt;&#xA;&lt;strong&gt;the same order as&lt;/strong&gt; they appear &lt;strong&gt;in the face array&lt;/strong&gt;.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;The fact the authors seem to bother about the order of the leafs in the binary tree (which they call summed area tree) and even suggest using an explicit stripification-algorithm might suggest otherwise.&lt;/p&gt;&#xA;&lt;p&gt;Here a spoiler where you can read up the algorithm as described by the authors:&lt;/p&gt;&#xA;&lt;blockquote class=&quot;spoiler&quot;&gt;&#xA;&lt;p&gt;In order to deﬁne a mapping from sample-space to object-&#xA;space, we need to place the mesh faces into the sample-space&#xA;without distorting face area ratios, and be able to locate the&#xA;face containing sample point (u,v). This is a typical prox-&#xA;imity search problem, which is well supported by a kd-tree.&#xA;The data structures required for the build and search pro-&#xA;cesses are depicted in Figure 4.&#xA;&#xA;The faces of the model mesh are roughly arranged in a 1D&#xA;face array by proximity. In typical cases, this naturally arises&#xA;from the modeling process. Otherwise, mesh optimization&#xA;algorithms (e.g. stripiﬁcation) [DGGP05] can be applied.&#xA;&#xA;First, we build a balanced binary tree, called the summed&#xA;area tree, in which leaf values are triangle surface areas in&#xA;the same order as they appear in the face array. Any branch&#xA;node contains the summed area of its children. The root node&#xA;will contain the surface area of the complete object.&#xA;&#xA;Then, we partition the sample-space with a kd-tree that&#xA;has the same balanced topology. Every node in the kd-tree&#xA;corresponds to a node in the area tree. The unit square cell in&#xA;sample-space is assigned to the root node, which is split re-&#xA;cursively along the coordinate axes resulting in a binary tree&#xA;of cells. At a given node, the splitting ratio is selected so that&#xA;the areas of the two new cells are proportional to the summed&#xA;surface areas stored in the corresponding child nodes of the&#xA;area tree. Thus, the sample-space area that belongs to a set of&#xA;faces will be proportional to their surface area. Where the set&#xA;reduces to a single face, the face is mapped to the cell. This&#xA;is trivial for quadrilateral faces, but also works well with tri-&#xA;angles if we represent each triangle twice and arrange each&#xA;pair as a quad (right of Figure 4).&#xA;&#xA;When we need to transform samples into the object-space,&#xA;we use the kd-tree. Given the (u,v)coordinates of the sam-&#xA;pled point, we start from the root of the tree, comparing the&#xA;coordinate of the splitting axis to the splitting ratio. Depend-&#xA;ing on the result of the comparison, we continue recursively&#xA;with one of the branches, normalizing the coordinate to the&#xA;cell’s [0,1]range. At a leaf, the (u,v)coordinates we get are&#xA;interpreted according to the natural parametrization of the&#xA;quadrilateral, or as two of the unit-sum barycentric coordi-&#xA;nates on the triangle (or (1−u,1−v)if u+v&amp;gt;1).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Link to the full text of the paper: &lt;a href=&quot;https://www.researchgate.net/publication/220506553_Hatching_for_Motion_Picture_Production&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hatching for Motion Picture Production&lt;/a&gt;. The relevant part is only section 4.1.1.&lt;/p&gt;&#xA;&lt;p&gt;Thank you for any input.&lt;/p&gt;&#xA;" OwnerUserId="15886" LastEditorUserId="15886" LastEditDate="2021-03-07T17:45:36.593" LastActivityDate="2021-03-07T17:45:36.593" Title="Is this way of transforming QMC samples into barycentric tri coordinates agnostic to mesh-topology?" Tags="&lt;algorithm&gt;&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;sampling&gt;&lt;monte-carlo&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10721" PostTypeId="2" ParentId="233" CreationDate="2021-03-10T20:03:03.150" Score="0" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/BUlnf.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/BUlnf.jpg&quot; alt=&quot;probe vs cubemap in blender&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;the &lt;strong&gt;cubemaps&lt;/strong&gt; which have this cube shape in blender store a &lt;strong&gt;360 image&lt;/strong&gt; of that point that can be used for reflections, world texture images...&lt;/p&gt;&#xA;&lt;p&gt;also seems like cubemap can be called reflection probe sometimes to add to the confussion, so seems like cubemaps are a type of probe too more specific to remapping&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;probes&lt;/strong&gt; which are the circles store only &lt;strong&gt;light info&lt;/strong&gt; (am i getting white raylights? yellow?)&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;I might be wrong, in that case correct me&lt;/em&gt;&lt;/p&gt;&#xA;" OwnerUserId="15910" LastEditorUserId="15910" LastEditDate="2021-03-10T20:23:23.297" LastActivityDate="2021-03-10T20:23:23.297" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10722" PostTypeId="1" CreationDate="2021-03-11T02:45:59.883" Score="1" ViewCount="84" Body="&lt;p&gt;I have written a software rasterizer, and have encountered a (literal) edge case.&lt;/p&gt;&#xA;&lt;p&gt;At the silhouette edge of a typical object, you have two triangles—the front face and the back face.  They are not coplanar, but they of course share that single edge.  Say the pixel center / subpixel sample happens to lie very close to this edge—so close that the depth value computed for both triangles is actually &lt;em&gt;exactly&lt;/em&gt;, bit-for-bit, identical.&lt;/p&gt;&#xA;&lt;p&gt;Without special handling for this case, sometimes the &amp;quot;wrong&amp;quot; fragment will get through.  For example, with the &lt;code&gt;&amp;lt;&lt;/code&gt; depth function, if the backface renders first, then the depth test for the frontface will fail and the backface will show through.   If the frontface renders first, then the depth test for the backface will fail and the frontface will show.  The former case produces the wrong image—sometimes quite objectionably so.&lt;/p&gt;&#xA;&lt;p&gt;I have thought about hacks to fix this like trying to handle the &amp;quot;equals&amp;quot; case explicitly, depending upon the depth function and whether the fragment came from a front face, but it's not clear, especially for the &lt;code&gt;≤&lt;/code&gt; and &lt;code&gt;≥&lt;/code&gt; depth functions, what the &amp;quot;right&amp;quot; answer is.  Still, it's about the only thing I can think of trying.&lt;/p&gt;&#xA;&lt;p&gt;This is basically Z-fighting, but &lt;em&gt;unlike&lt;/em&gt; the usual Z-fighting graphics newbies encounter when they don't set the clipping planes right or whatever (and which makes this issue almost ungoogleable), existing hardware &lt;em&gt;definitely does&lt;/em&gt; provide &lt;em&gt;some&lt;/em&gt; kind of solution to handle this particular case, because this problem does &lt;em&gt;not&lt;/em&gt; occur on real GPUs.&lt;/p&gt;&#xA;&lt;p&gt;So my question is—how &lt;em&gt;is&lt;/em&gt; this handled by real GPUs?  If that's unanswerable, then how &lt;em&gt;can&lt;/em&gt; it be handled consistently?&lt;/p&gt;&#xA;" OwnerUserId="523" LastActivityDate="2021-04-10T14:03:10.293" Title="Rasterization: How does hardware disambiguate identical Z values at silhouette edges?" Tags="&lt;rasterizer&gt;&lt;hardware&gt;&lt;silhouette&gt;&lt;z-fighting&gt;" AnswerCount="2" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10723" PostTypeId="2" ParentId="10722" CreationDate="2021-03-11T03:17:27.293" Score="0" Body="&lt;p&gt;The way this is &amp;quot;handled by real GPUs&amp;quot; is that most models are closed. As such, surfaces facing away from the camera are definitely not closer than some other surface of that object. To prevent throwing away performance rasterizing triangles that definitely do not contribute to the final image, most users turn on backface culling.&lt;/p&gt;&#xA;&lt;p&gt;And thus, there is no problem.&lt;/p&gt;&#xA;&lt;p&gt;In the absence of backface culling, what you describe is effectively just a form of z-fighting. But note that z-fighting almost always happens very far away from the camera and/or with co-planar objects that are very close together. To achieve the circumstance you describe, the angle between the two triangles would have to be extremely small, very close to 0.0. And they have to be so far away that the depth buffer lacks sufficient precision to deal with it.&lt;/p&gt;&#xA;&lt;p&gt;So, in order for the phenomenon you describe to even be possible, you would need for all three of these to be the case:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;Turning off backface culling.&lt;/li&gt;&#xA;&lt;li&gt;Two triangles that share an edge, with the angle between those triangles being &lt;em&gt;extremely&lt;/em&gt; small.&lt;/li&gt;&#xA;&lt;li&gt;The shared edge being very far away from the camera.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;This intersection of models and rendering state is vanishingly uncommon.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-11T03:17:27.293" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10724" PostTypeId="1" CreationDate="2021-03-11T13:11:53.853" Score="0" ViewCount="14" Body="&lt;p&gt;We have source images in gray or white color and want to overlay a specific color via imagemagick's composite function.&lt;/p&gt;&#xA;&lt;p&gt;Currently we generate a solid color area and use composite-overlay to overlay the color. Now most of the shadows are lost.&lt;/p&gt;&#xA;&lt;p&gt;The new approach is to use &lt;a href=&quot;https://legacy.imagemagick.org/Usage/compose/#linearlight&quot; rel=&quot;nofollow noreferrer&quot;&gt;LinearLight&lt;/a&gt; compositing, but here we have to use a different source color to obtain the specific target color.&lt;/p&gt;&#xA;&lt;p&gt;The formular use for linearlight seems&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;2*Src + Dest - 1&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;But how do I apply the reverse of this to a specific color hex code?&lt;/p&gt;&#xA;" OwnerUserId="15913" LastActivityDate="2021-03-11T13:11:53.853" Title="Overlaying a specifc color with LinearLight or Multiply -&gt; reverse color maths" Tags="&lt;image-processing&gt;&lt;color&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10725" PostTypeId="2" ParentId="10722" CreationDate="2021-03-11T13:14:39.890" Score="1" Body="&lt;p&gt;If you are taking about this occurring within a single draw call for a single object then you are talking about rasterization not Z fighting.  So the real question is, &amp;quot;how are two triangles rasterized that are right next to each other&amp;quot;. And the answer to that question boils down to rasterization rules. Which must be enforced, on GPU's that happens in hardware, for your software rasterizer you need to pick a rule set, then enforce it in code. Generically a rasterizer can leave no holes, and each pixel is only drawn once. You may want to always add colors when drawing your triangles, start with a color of zero and just add new colors drawn to that pixel, this will make your overdraw stand out like a sore thumb.&lt;/p&gt;&#xA;&lt;p&gt;The most widely know rule set for handling this is the &amp;quot;top left rule&amp;quot; which states: The center of every pixel must lie completely inside the triangle, (you are computing pixel centers right?) or it center lies &lt;em&gt;exactly&lt;/em&gt; on a triangle edge or on multiple edges in the case of corners, and a left edge is a non-horizontal edge that is on the left side of the triangle.&lt;/p&gt;&#xA;&lt;p&gt;This last bit is directly from &lt;a href=&quot;https://en.wikipedia.org/wiki/Rasterisation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-03-11T13:14:39.890" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10726" PostTypeId="1" CreationDate="2021-03-11T15:00:19.243" Score="0" ViewCount="112" Body="&lt;p&gt;If you have a shader pipeline in OpenGL that goes something like the following:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Pseudocode&#xA;&#xA;// FragmentShader&#xA;// in vec3 inVertexPosition;&#xA;// in vec2 inTexCoords&#xA;// &#xA;// int main()&#xA;{&#xA;    // Sample texture coordinate and write to fragment out&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then you have another fragment shader that does something a little different:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// int main()&#xA;{&#xA;      // Sample texture, calculate noise and mix with texture colour&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;In OpenGL if you want to execute this second shader you only compile this second shader and bind to the fragment shader stage of the shader pipeline. You can then create another a different vertex shader and attach that to the vertex shader stage whenever you need it.&lt;/p&gt;&#xA;&lt;p&gt;Let's just say I have 5 vertex shaders and 5 fragment shaders, in OpenGL (because it supports separable shader objects) you only need to compile 5 x 2 = 10 shaders. However, as in Vulkan, as far as I know it doesn't support it, which means you have to compile 25 programs if you want to use each combination.&lt;/p&gt;&#xA;&lt;p&gt;Does Vulkan have the equivalent of the OpenGL separable shader objects, or are there any plans for it? They seem just so much more flexible.&lt;/p&gt;&#xA;&lt;p&gt;I've thought about being able to bind shader stages in my code, and then every combination of shader stages could be mapped to a single compiled program, however I don't think the mapping could be searched efficiently. I'm not sure. It seems being forced to compile an entirely new pipeline when inserting a shader stage is wasteful when you make many shaders.&lt;/p&gt;&#xA;&lt;p&gt;It seems in principle this is like compiling a new program every time you created a new function.&lt;/p&gt;&#xA;" OwnerUserId="10333" LastEditorUserId="10333" LastEditDate="2021-03-11T15:26:44.917" LastActivityDate="2021-03-12T22:49:45.060" Title="Does Vulkan have the equivalent of OpenGL's separable shader program and pipeline?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;vulkan&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10727" PostTypeId="2" ParentId="10726" CreationDate="2021-03-11T16:06:07.710" Score="3" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Does Vulkan have the equivalent of the OpenGL separable shader objects, or are there any plans for it? They seem just so much more flexible.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;It would be &amp;quot;so much more flexible&amp;quot;. But Vulkan is a low-level rendering API. It's job is to give you access to the hardware as close to the metal as possible; user-convenience isn't even in the top-5 goals for the API.&lt;/p&gt;&#xA;&lt;p&gt;Putting all of the context state into one gigantic, immutable (more or less) object gives the implementation all the power it needs to make your code fast. Forcing implementations to deal with stitching together shaders would make implementations more complicated (and another goal of Vulkan is to be relatively easy to implement).&lt;/p&gt;&#xA;&lt;p&gt;The best way to solve this (where possible) is to just have fewer shader variations. Use uniforms/push-constants to detect what variations you want to use, then have conditionals based on them. Obviously this can't be done in every situation, but the uber-shader approach is the way to handle it to the degree possible/reasonable.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-11T16:06:07.710" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10728" PostTypeId="1" AcceptedAnswerId="10735" CreationDate="2021-03-11T21:46:42.883" Score="3" ViewCount="36" Body="&lt;p&gt;I want to plot the &lt;a href=&quot;https://github.com/mmp/pbrt-v4/blob/08418214e4df767a4e6aa95230821e05f3621da9/src/pbrt/filters.h#L80&quot; rel=&quot;nofollow noreferrer&quot;&gt;Gaussian filter of pbrt-v4&lt;/a&gt; with a radius &lt;span class=&quot;math-container&quot;&gt;$(100,100)$&lt;/span&gt; and a standard deviation (&lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt;) of &lt;span class=&quot;math-container&quot;&gt;$0.5$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;I would expect something like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/4vlMD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/4vlMD.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;When I plot the pbrt-v4 Gaussian filter with radius &lt;span class=&quot;math-container&quot;&gt;$(100,100)$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$\sigma=0.5$&lt;/span&gt; I get:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/amEEn.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/amEEn.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Is the 2nd plot correct? I varied the radius form &lt;span class=&quot;math-container&quot;&gt;$1$&lt;/span&gt; to &lt;span class=&quot;math-container&quot;&gt;$1000$&lt;/span&gt; but the the filter size changes only 2 pixels in total (I get a similar results).&#xA;Any ideas?&#xA;How does the correct plot look like?&lt;/p&gt;&#xA;" OwnerUserId="5891" LastActivityDate="2021-03-12T19:53:16.763" Title="Plotting pbrt-v3 Gaussian filter" Tags="&lt;rendering&gt;&lt;filtering&gt;&lt;gaussian-blur&gt;&lt;pbrt&gt;&lt;pbrt-v3&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10729" PostTypeId="1" CreationDate="2021-03-11T22:52:59.343" Score="0" ViewCount="51" Body="&lt;p&gt;I'm trying to learn OpenGL in c++ (I used it in Java) but I have a problem, I make a triangle, but it doesn't draw on GL_FILL and in GL_LINE it just draw a line, I can't find my mistake, I guess my bug is in vertex buffers, but I can't detect it, can anyone help me please?&lt;/p&gt;&#xA;&lt;p&gt;CglApp.cpp:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    CglApp::CglApp() {&#xA;&#xA;    glm::vec3 vertices[] = {&#xA;            {0.5f,  0.5f, 0.0f} ,  // top right&#xA;            {0.5f, -0.5f, 0.0f},  // bottom right&#xA;            {-0.5f, -0.5f, 0.0f},  // bottom left&#xA;            {-0.5f,  0.5f, 0.0f}   // top left&#xA;    };&#xA;    unsigned int indices[] = {  // note that we start from 0!&#xA;            0, 1, 3,  // first Triangle&#xA;            //1, 2, 3   // second Triangle&#xA;    };&#xA;&#xA;    glm::vec3 vertices2[] = {&#xA;            //{0.5f,  0.5f, 0.0f} ,  // top right&#xA;            {0.5f, -0.5f, 0.0f},  // bottom right&#xA;            {-0.5f, -0.5f, 0.0f},  // bottom left&#xA;            {-0.5f,  0.5f, 0.0f}   // top left&#xA;    };&#xA;&#xA;    unsigned int indices2[] = {  // note that we start from 0!&#xA;            //0, 1, 3,  // first Triangle&#xA;            1, 2, 3   // second Triangle&#xA;    };&#xA;&#xA;&#xA;    cglSolidModel.loadModels(vertices,indices);&#xA;    cglSolidModel1.loadModels(vertices2,indices2);&#xA;&#xA;}&#xA;&#xA;CglApp::~CglApp() {&#xA;&#xA;}&#xA;&#xA;void CglApp::run() {&#xA;&#xA;    while (!cglWindow.shouldClose()){&#xA;&#xA;        // input&#xA;        // -----&#xA;        inputManager.processInput(cglWindow.getWindow());&#xA;&#xA;        // render&#xA;        // ------&#xA;        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);&#xA;        glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;        cglSolidModel.bind(cglShaders.getDefaultShader());&#xA;        cglSolidModel1.bind(cglShaders.getDefaultShader());&#xA;&#xA;        // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)&#xA;        // -------------------------------------------------------------------------------&#xA;        glfwSwapBuffers(cglWindow.getWindow());&#xA;        glfwPollEvents();&#xA;&#xA;    }&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;CglShaders.cpp&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;CglShaders::CglShaders() {&#xA;    createDefaultShader();&#xA;}&#xA;&#xA;CglShaders::~CglShaders() {&#xA;&#xA;}&#xA;&#xA;void CglShaders::createDefaultShader() {&#xA;&#xA;    const char *vertexShaderSource = &amp;quot;#version 330 core\n&amp;quot;&#xA;                                     &amp;quot;layout (location = 0) in vec3 aPos;\n&amp;quot;&#xA;                                     &amp;quot;void main()\n&amp;quot;&#xA;                                     &amp;quot;{\n&amp;quot;&#xA;                                     &amp;quot;   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n&amp;quot;&#xA;                                     &amp;quot;}\0&amp;quot;;&#xA;    const char *fragmentShaderSource = &amp;quot;#version 330 core\n&amp;quot;&#xA;                                       &amp;quot;out vec4 FragColor;\n&amp;quot;&#xA;                                       &amp;quot;void main()\n&amp;quot;&#xA;                                       &amp;quot;{\n&amp;quot;&#xA;                                       &amp;quot;   FragColor = vec4(1.0f, 0.9f, 0.2f, 1.0f);\n&amp;quot;&#xA;                                       &amp;quot;}\n\0&amp;quot;;&#xA;&#xA;    createShader(vertexShaderSource,fragmentShaderSource);&#xA;&#xA;}&#xA;&#xA;void CglShaders::createShader(const char *vertexShaderSource, const char *fragmentShaderSource) {&#xA;&#xA;    // build and compile our shader program&#xA;    // ------------------------------------&#xA;    // vertex shader&#xA;    unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER);&#xA;    glShaderSource(vertexShader, 1, &amp;amp;vertexShaderSource, NULL);&#xA;    glCompileShader(vertexShader);&#xA;    // check for shader compile errors&#xA;    int success;&#xA;    char infoLog[512];&#xA;    glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &amp;amp;success);&#xA;    if (!success)&#xA;    {&#xA;        glGetShaderInfoLog(vertexShader, 512, NULL, infoLog);&#xA;        std::cout &amp;lt;&amp;lt; &amp;quot;ERROR::SHADER::VERTEX::COMPILATION_FAILED\n&amp;quot; &amp;lt;&amp;lt; infoLog &amp;lt;&amp;lt; std::endl;&#xA;    }&#xA;    // fragment shader&#xA;    unsigned int fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);&#xA;    glShaderSource(fragmentShader, 1, &amp;amp;fragmentShaderSource, NULL);&#xA;    glCompileShader(fragmentShader);&#xA;    // check for shader compile errors&#xA;    glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &amp;amp;success);&#xA;    if (!success)&#xA;    {&#xA;        glGetShaderInfoLog(fragmentShader, 512, NULL, infoLog);&#xA;        std::cout &amp;lt;&amp;lt; &amp;quot;ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n&amp;quot; &amp;lt;&amp;lt; infoLog &amp;lt;&amp;lt; std::endl;&#xA;    }&#xA;    // link shaders&#xA;    unsigned int shaderProgram = glCreateProgram();&#xA;    glAttachShader(shaderProgram, vertexShader);&#xA;    glAttachShader(shaderProgram, fragmentShader);&#xA;    glLinkProgram(shaderProgram);&#xA;    // check for linking errors&#xA;    glGetProgramiv(shaderProgram, GL_LINK_STATUS, &amp;amp;success);&#xA;    if (!success) {&#xA;        glGetProgramInfoLog(shaderProgram, 512, NULL, infoLog);&#xA;        std::cout &amp;lt;&amp;lt; &amp;quot;ERROR::SHADER::PROGRAM::LINKING_FAILED\n&amp;quot; &amp;lt;&amp;lt; infoLog &amp;lt;&amp;lt; std::endl;&#xA;    }&#xA;    glDeleteShader(vertexShader);&#xA;    glDeleteShader(fragmentShader);&#xA;&#xA;    shaderPrograms.push_back(shaderProgram);&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;CglSolidModel.cpp&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;CglSolidModel::CglSolidModel() {&#xA;&#xA;}&#xA;&#xA;CglSolidModel::~CglSolidModel() {&#xA;&#xA;}&#xA;&#xA;void CglSolidModel::loadModels(glm::vec3 vertices[], unsigned int indices[]) {&#xA;&#xA;    glGenVertexArrays(1, &amp;amp;VAO);&#xA;    glGenBuffers(1, &amp;amp;VBO);&#xA;    glGenBuffers(1, &amp;amp;EBO);&#xA;    // bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).&#xA;    glBindVertexArray(VAO);&#xA;&#xA;    glBindBuffer(GL_ARRAY_BUFFER, VBO);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&#xA;    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);&#xA;    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);&#xA;&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)nullptr);&#xA;    glEnableVertexAttribArray(0);&#xA;&#xA;    // note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind&#xA;    glBindBuffer(GL_ARRAY_BUFFER, 0);&#xA;&#xA;    // remember: do NOT unbind the EBO while a VAO is active as the bound element buffer object IS stored in the VAO; keep the EBO bound.&#xA;    //glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);&#xA;&#xA;    // You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other&#xA;    // VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.&#xA;    glBindVertexArray(1);&#xA;&#xA;&#xA;    // uncomment this call to draw in wireframe polygons.&#xA;    //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);&#xA;&#xA;}&#xA;&#xA;void CglSolidModel::bind(unsigned int shaderProgram) {&#xA;&#xA;    // draw our first triangle&#xA;    glUseProgram(shaderProgram);&#xA;    glBindVertexArray(VAO); // seeing as we only have a single VAO there's no need to bind it every time, but we'll do so to keep things a bit more organized&#xA;    //glDrawArrays(GL_TRIANGLES, 0, 6);&#xA;    glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);&#xA;    // glBindVertexArray(0); // no need to unbind it every time&#xA;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Im creating the VBO, EBO and VBA inside each SolidModel.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/EmiYD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;Only two lines for two different triangles with GL_LINE&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15845" LastActivityDate="2021-03-12T10:04:53.037" Title="My OpenGL program is not drawing filled polygons" Tags="&lt;opengl&gt;&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10730" PostTypeId="2" ParentId="10729" CreationDate="2021-03-12T07:01:05.773" Score="3" Body="&lt;p&gt;A problem I see in your code is that you take the &lt;code&gt;sizeof()&lt;/code&gt; an unsized array, which yields the size of the &lt;em&gt;pointer&lt;/em&gt; to that array and not the size of array itself.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void CglSolidModel::loadModels(glm::vec3 vertices[], unsigned int indices[]) {&#xA;{&#xA;    ...&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;    ...&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here is a small test case that demonstrates the issue.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void func(int array[]) {&#xA;    printf(&amp;quot;sizeof(array) = %d\n&amp;quot;, sizeof(array));&#xA;}&#xA;&#xA;int myArray[10];&#xA;func(myArray);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Output when compiled for x64:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;sizeof(array) = 8  &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is the size of the 64bit pointer to the array. You would expect 10*sizeof(int) = 40. In your code (assuming x64) it only sends 8 bytes of the vertice array to the VBO, which is enough to fill the XY coordinates for the first vertex. That goes some way to explaining why you only see 1 partial triangle.&lt;/p&gt;&#xA;&lt;p&gt;It's not possible for C++ to determine the size of an unsized array. In C++ &lt;code&gt;int array[];&lt;/code&gt; is equivalent to &lt;code&gt;const int *array;&lt;/code&gt; and so &lt;code&gt;sizeof(array)&lt;/code&gt; is the same in both cases. This isn't the case for sized arrays, &lt;code&gt;int array[10];&lt;/code&gt; would give you 40 bytes as you would expect.&lt;/p&gt;&#xA;&lt;p&gt;I would recommend you pass another parameter which contains the size of the array or use a container like &lt;code&gt;std::vector&lt;/code&gt; which stores the size along with the array. Be aware that &lt;code&gt;std::vector&lt;/code&gt; returns the number of elements and not the number of bytes which &lt;code&gt;glBufferData&lt;/code&gt; expects.&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2021-03-12T10:04:53.037" LastActivityDate="2021-03-12T10:04:53.037" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10731" PostTypeId="1" AcceptedAnswerId="10732" CreationDate="2021-03-12T08:59:46.673" Score="2" ViewCount="31" Body="&lt;p&gt;I implemented the curved PN triangles algorithm described in &lt;a href=&quot;https://alex.vlachos.com/graphics/CurvedPNTriangles.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; paper to smooth geometry in real time. After the implementation was finished (in glsl) I realized, that this algorithm smooth the geometry but there are still edges visible. To better debug I converted the program to C++ and inserted a unit cube. Important: the unit cubes faces share their vertices... so we have 8 vertices with 8 normal vectors (no flat shading).&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The used obj file (cube.obj):&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;v -1 -1 -1&#xA;v 1 -1 -1&#xA;v -1 1 -1&#xA;v 1 1 -1&#xA;v -1 -1 1&#xA;v 1 -1 1&#xA;v -1 1 1&#xA;v 1 1 1&#xA;vn -1 -1 -1&#xA;vn 1 -1 -1&#xA;vn -1 1 -1&#xA;vn 1 1 -1&#xA;vn -1 -1 1&#xA;vn 1 -1 1&#xA;vn -1 1 1&#xA;vn 1 1 1&#xA;f 1//1 2//2 3//3&#xA;f 3//3 2//2 4//4&#xA;f 2//2 6//6 4//4&#xA;f 4//4 6//6 8//8&#xA;f 3//3 4//4 7//7&#xA;f 7//7 4//4 8//8&#xA;f 1//1 5//5 2//2&#xA;f 2//2 5//5 6//6&#xA;f 1//1 3//3 5//5&#xA;f 5//5 3//3 7//7&#xA;f 5//5 7//7 6//6&#xA;f 6//6 7//7 8//8&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;as you can see the normal vectors (vn) are not normalized. This is no problem, because they will be normalized during filling the buffer.&lt;/p&gt;&#xA;&lt;p&gt;The following code reads the mesh file and subdivides each face with respect to the &lt;code&gt;edgeDivisionCount&lt;/code&gt; variable. Here it is set to 100. That means each edge is subdivided into 100 vertices.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;vector&amp;gt;&#xA;#include &amp;lt;fstream&amp;gt;&#xA;#include &amp;lt;sstream&amp;gt;&#xA;#include &amp;lt;iostream&amp;gt;&#xA;#include &amp;lt;thread&amp;gt;&#xA;&#xA;struct Vector3D&#xA;{&#xA;public:&#xA;    Vector3D()&#xA;    {&#xA;        x = 0;&#xA;        y = 0;&#xA;        z = 0;&#xA;    }&#xA;&#xA;    Vector3D(float x, float y, float z)&#xA;    {&#xA;        this-&amp;gt;x = x;&#xA;        this-&amp;gt;y = y;&#xA;        this-&amp;gt;z = z;&#xA;    }&#xA;&#xA;    Vector3D operator*(float scalar) const&#xA;    {&#xA;        return Vector3D(x * scalar, y * scalar, z * scalar);&#xA;    }&#xA;&#xA;    Vector3D operator+(const Vector3D&amp;amp; v2) const&#xA;    {&#xA;        return Vector3D(x + v2.x, y + v2.y, z + v2.z);&#xA;    }&#xA;&#xA;    Vector3D operator-(const Vector3D&amp;amp; v2) const&#xA;    {&#xA;        return Vector3D(x - v2.x, y - v2.y, z - v2.z);&#xA;    }&#xA;&#xA;    Vector3D operator-() const&#xA;    {&#xA;        return Vector3D(-x, -y, -z);&#xA;    }&#xA;&#xA;    float dot(const Vector3D&amp;amp; v2) const&#xA;    {&#xA;        return x*v2.x + y*v2.y + z*v2.z;&#xA;    }&#xA;&#xA;    float length() const&#xA;    {&#xA;        return sqrt(x*x + y*y + z*z);&#xA;    }&#xA;&#xA;    Vector3D normalize() const&#xA;    {&#xA;        float l = length();&#xA;        return Vector3D(x / l, y / l, z / l);&#xA;    }&#xA;&#xA;    float x;&#xA;    float y;&#xA;    float z;&#xA;};&#xA;&#xA;void saveOBJ(std::string file, std::vector&amp;lt;Vector3D&amp;gt;* vertices, std::vector&amp;lt;std::tuple&amp;lt;int, int, int&amp;gt;&amp;gt;* faces)&#xA;{&#xA;    std::ofstream myfile;&#xA;    myfile.open(file);  &#xA;    if (vertices != nullptr)&#xA;    {&#xA;        for (std::vector&amp;lt;Vector3D&amp;gt;::iterator it = vertices-&amp;gt;begin(); it != vertices-&amp;gt;end(); ++it)&#xA;        {&#xA;            myfile &amp;lt;&amp;lt; &amp;quot;v &amp;quot; &amp;lt;&amp;lt; it-&amp;gt;x &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; it-&amp;gt;y &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; it-&amp;gt;z &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&#xA;        }&#xA;    }&#xA;    if (faces != nullptr)&#xA;    {&#xA;        for (std::vector&amp;lt;std::tuple&amp;lt;int, int, int&amp;gt;&amp;gt;::iterator it = faces-&amp;gt;begin(); it != faces-&amp;gt;end(); ++it)&#xA;        {&#xA;            myfile &amp;lt;&amp;lt; &amp;quot;f &amp;quot; &amp;lt;&amp;lt; std::get&amp;lt;0&amp;gt;(*it) + 1 &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; std::get&amp;lt;1&amp;gt;(*it) + 1 &amp;lt;&amp;lt; &amp;quot; &amp;quot; &amp;lt;&amp;lt; std::get&amp;lt;2&amp;gt;(*it) + 1 &amp;lt;&amp;lt; &amp;quot;\n&amp;quot;;&#xA;        }&#xA;    }&#xA;    myfile.close();&#xA;}&#xA;&#xA;Vector3D curvedPNVertex(Vector3D b300, Vector3D b030, Vector3D b003, Vector3D n200, Vector3D n020, Vector3D n002, Vector3D b210, Vector3D b120, Vector3D b021, Vector3D b012, Vector3D b102, Vector3D b201, Vector3D b111, float scalar0, float scalar1, float scalar2)&#xA;{&#xA;    float u = scalar1;&#xA;    float v = scalar2;&#xA;    float w = scalar0;&#xA;    float u2 = pow(u,2);&#xA;    float v2 = pow(v,2);&#xA;    float w2 = pow(w,2);&#xA;    float u3 = pow(u,3);&#xA;    float v3 = pow(v,3);&#xA;    float w3 = pow(w,3);&#xA;&#xA;    return b003*v3 + b102*3*w*v2 + b012*3*u*v2 + b201*3*w2*v + b111*6*w*u*v + b021*3*u2*v + b300*w3 + b210*3*w2*u + b120*3*w*u2 + b030*u3;&#xA;}&#xA;&#xA;std::vector&amp;lt;Vector3D&amp;gt; curvedPNTriangle(int divisionCount, Vector3D v0, Vector3D v1, Vector3D v2, Vector3D n0, Vector3D n1, Vector3D n2)&#xA;{&#xA;    std::vector&amp;lt;Vector3D&amp;gt; result;&#xA;&#xA;    Vector3D b300 = v0;&#xA;    Vector3D b030 = v1;&#xA;    Vector3D b003 = v2;&#xA;&#xA;    Vector3D n200 = n0.normalize();&#xA;    Vector3D n020 = n1.normalize();&#xA;    Vector3D n002 = n2.normalize();&#xA;&#xA;    Vector3D b210 = (b300 * 2.0f + b030 - (n200 * (b030 - b300).dot(n200))) * (1.0f / 3.0f);&#xA;    Vector3D b120 = (b030 * 2.0f + b300 - (n020 * (b300 - b030).dot(n020))) * (1.0f / 3.0f);&#xA;    Vector3D b021 = (b030 * 2.0f + b003 - (n020 * (b003 - b030).dot(n020))) * (1.0f / 3.0f);&#xA;    Vector3D b012 = (b003 * 2.0f + b030 - (n002 * (b030 - b003).dot(n002))) * (1.0f / 3.0f);&#xA;    Vector3D b102 = (b003 * 2.0f + b300 - (n002 * (b300 - b003).dot(n002))) * (1.0f / 3.0f);&#xA;    Vector3D b201 = (b300 * 2.0f + b003 - (n200 * (b003 - b300).dot(n200))) * (1.0f / 3.0f);&#xA;    Vector3D e = (b210+b120+b201+b102+b012+b021) * (1.0f / 6.0f);&#xA;    Vector3D b111 = e + (e - (b300+b030+b003) * (1.0f / 3.0f)) * (1.0f / 2.0f);&#xA;&#xA;    //divide triangle face&#xA;    for (unsigned int i = 0; i &amp;lt; divisionCount; ++i)&#xA;    {&#xA;        for (unsigned int j = 0; j &amp;lt; divisionCount - i; ++j)&#xA;        {&#xA;            float scalar1 = static_cast&amp;lt;float&amp;gt;(i) / divisionCount;&#xA;            float scalar0 = static_cast&amp;lt;float&amp;gt;(j) / divisionCount;&#xA;            float scalar2 = 1 - (scalar0 + scalar1);&#xA;            Vector3D vertex = curvedPNVertex(b300, b030, b003, n200, n020, n002, b210, b120, b021, b012, b102, b201, b111, scalar0, scalar1, scalar2);&#xA;            result.push_back(vertex);&#xA;        }&#xA;    }&#xA;&#xA;    return result;&#xA;}&#xA;&#xA;std::vector&amp;lt;int&amp;gt; getIntOutOfString(std::string text)&#xA;{&#xA;    std::vector&amp;lt;int&amp;gt; result;&#xA;&#xA;    std::string subtext = &amp;quot;&amp;quot;;&#xA;    for (unsigned int i = 0; i &amp;lt; text.size(); ++i)&#xA;    {&#xA;        if ((text.at(i) &amp;gt;= '0' &amp;amp;&amp;amp; text.at(i) &amp;lt;= '9'))&#xA;        {&#xA;            subtext += text.at(i);&#xA;        }&#xA;        else if (subtext.size() == 0 &amp;amp;&amp;amp; text.at(i) == '-')&#xA;        {&#xA;            subtext += text.at(i);&#xA;        }&#xA;        else if (subtext.size() &amp;gt; 0)&#xA;        {&#xA;            //end of a int reached! Save int into list!&#xA;            result.push_back(std::stoi(subtext));&#xA;            subtext = &amp;quot;&amp;quot;;&#xA;        }&#xA;    }&#xA;    if (subtext != &amp;quot;&amp;quot;)&#xA;    {&#xA;        result.push_back(std::stoi(subtext));&#xA;    }&#xA;    return result;&#xA;}&#xA;&#xA;&#xA;std::vector&amp;lt;double&amp;gt; getDoublesOutOfString(std::string text)&#xA;{&#xA;    std::vector&amp;lt;double&amp;gt; result;&#xA;&#xA;    std::string subtext = &amp;quot;&amp;quot;;&#xA;    for (unsigned int i = 0; i &amp;lt; text.size(); ++i)&#xA;    {&#xA;        if ((text.at(i) &amp;gt;= '0' &amp;amp;&amp;amp; text.at(i) &amp;lt;= '9') || text.at(i) == '.')&#xA;        {&#xA;            subtext += text.at(i);&#xA;        }&#xA;        else if (subtext.size() == 0 &amp;amp;&amp;amp; text.at(i) == '-')&#xA;        {&#xA;            subtext += text.at(i);&#xA;        }&#xA;        else if (subtext.size() &amp;gt; 0)&#xA;        {&#xA;            //end of a double reached! Save double into list!&#xA;            result.push_back(std::stod(subtext));&#xA;            subtext = &amp;quot;&amp;quot;;&#xA;        }&#xA;    }&#xA;    if (subtext != &amp;quot;&amp;quot;)&#xA;    {&#xA;        result.push_back(std::stod(subtext));&#xA;    }&#xA;    return result;&#xA;}&#xA;&#xA;bool readOBJ(std::string file, std::vector&amp;lt;Vector3D&amp;gt;* positions, std::vector&amp;lt;Vector3D&amp;gt;* normals, std::vector&amp;lt;std::tuple&amp;lt;int, int, int, int, int, int&amp;gt;&amp;gt;* faces)&#xA;{&#xA;    std::string line;&#xA;    std::ifstream myfile(file);&#xA;    if (myfile.is_open())&#xA;    {&#xA;        while (std::getline(myfile, line))&#xA;        {&#xA;            if (line.size() &amp;gt; 1)&#xA;            {&#xA;                if (line[0] == 'v' &amp;amp;&amp;amp; line[1] == ' ')&#xA;                {&#xA;                    std::vector&amp;lt;double&amp;gt; vertexValues = getDoublesOutOfString(line);&#xA;                    if (vertexValues.size() == 3)&#xA;                    {&#xA;                        Vector3D position = Vector3D(vertexValues[0], vertexValues[1], vertexValues[2]);&#xA;                        positions-&amp;gt;push_back(position);&#xA;                    }&#xA;                }&#xA;                if (line[0] == 'v' &amp;amp;&amp;amp; line[1] == 'n')&#xA;                {&#xA;                    std::vector&amp;lt;double&amp;gt; vertexValues = getDoublesOutOfString(line);&#xA;                    if (vertexValues.size() == 3)&#xA;                    {&#xA;                        Vector3D normal = Vector3D(vertexValues[0], vertexValues[1], vertexValues[2]).normalize();&#xA;                        normals-&amp;gt;push_back(normal);&#xA;                    }&#xA;                }&#xA;                if (line[0] == 'f' &amp;amp;&amp;amp; line[1] == ' ')&#xA;                {&#xA;                    std::vector&amp;lt;int&amp;gt; faceValues = getIntOutOfString(line);&#xA;                    if (faceValues.size() == 6)&#xA;                    {&#xA;                        std::tuple&amp;lt;int, int, int, int, int, int &amp;gt; face = std::tuple&amp;lt;int, int, int, int, int, int&amp;gt;(faceValues[0], faceValues[1], faceValues[2], faceValues[3], faceValues[4], faceValues[5]);&#xA;                        faces-&amp;gt;push_back(face);&#xA;                    }&#xA;                    else if (faceValues.size() == 9)&#xA;                    {&#xA;                        std::tuple&amp;lt;int, int, int, int, int, int &amp;gt; face = std::tuple&amp;lt;int, int, int, int, int, int&amp;gt;(faceValues[0], faceValues[2], faceValues[3], faceValues[5], faceValues[6], faceValues[8]);&#xA;                        faces-&amp;gt;push_back(face);&#xA;                    }&#xA;                }&#xA;            }&#xA;        }&#xA;        myfile.close();&#xA;        return true;&#xA;    }&#xA;    return false;&#xA;}&#xA;&#xA;&#xA;void main()&#xA;{&#xA;    std::vector&amp;lt;Vector3D&amp;gt; positions;&#xA;    std::vector&amp;lt;Vector3D&amp;gt; normals;&#xA;    std::vector&amp;lt;std::tuple&amp;lt;int, int, int, int, int, int&amp;gt;&amp;gt; faces;&#xA;&#xA;    readOBJ(&amp;quot;meshes/cube.obj&amp;quot;, &amp;amp;positions, &amp;amp;normals, &amp;amp;faces);&#xA;&#xA;    std::vector&amp;lt;Vector3D&amp;gt; curvedResult;&#xA;    int edgeDivisionCount = 100;&#xA;    for (std::vector&amp;lt;std::tuple&amp;lt;int, int, int, int, int, int&amp;gt;&amp;gt;::iterator it = faces.begin(); it != faces.end(); ++it)&#xA;    {&#xA;        std::vector&amp;lt;Vector3D&amp;gt; triangleResult = curvedPNTriangle(edgeDivisionCount, positions[std::get&amp;lt;0&amp;gt;(*it) - 1], positions[std::get&amp;lt;2&amp;gt;(*it) - 1], positions[std::get&amp;lt;4&amp;gt;(*it) - 1], normals[std::get&amp;lt;1&amp;gt;(*it) - 1], normals[std::get&amp;lt;3&amp;gt;(*it) - 1], normals[std::get&amp;lt;5&amp;gt;(*it) - 1]);&#xA;        for (std::vector&amp;lt;Vector3D&amp;gt;::iterator itVertex = triangleResult.begin(); itVertex != triangleResult.end(); ++itVertex)&#xA;        {&#xA;            curvedResult.push_back(*itVertex);&#xA;        }&#xA;    }&#xA;    saveOBJ(&amp;quot;meshes/cubeCurved.obj&amp;quot;, &amp;amp;curvedResult, nullptr);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Okay, so lets see the results:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/XO1rw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/XO1rw.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This discontinuity of the neighboring normal directions of the faces need to be avoided. Now I am not sure, if this is an implementation mistake on my side, or is the curved PN-triangles algorithm the wrong choice to solve my problem. I thought this algorithm would avoid these effects because the results in figure 1 of the &lt;a href=&quot;https://alex.vlachos.com/graphics/CurvedPNTriangles.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; don't show any of these effects.&lt;/p&gt;&#xA;&lt;p&gt;In case of correct implementation I would like to ask which algorithm would be a better choice for me?&lt;/p&gt;&#xA;&lt;p&gt;My requirements are:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;real time (it must be fast! Calculation per frame)&lt;/li&gt;&#xA;&lt;li&gt;the algorithm must be able to calculate the result within one step (only one shader call need to be enough)&lt;/li&gt;&#xA;&lt;li&gt;supports calculation of normal vectors per vertex (I am not interested in an algorithm which don't deliver the correct normal vector)&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Thanks in advance!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2021-03-12T11:52:09.783" Title="results of Curved PN-Triangles algorithm has visible edges" Tags="&lt;algorithm&gt;&lt;computational-geometry&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10732" PostTypeId="2" ParentId="10731" CreationDate="2021-03-12T11:52:09.783" Score="2" Body="&lt;p&gt;As mentioned in the paper PN-triangles are only &lt;span class=&quot;math-container&quot;&gt;$C^0$&lt;/span&gt; smooth with respect to adjacent triangles (although they are &lt;span class=&quot;math-container&quot;&gt;$G^1$&lt;/span&gt; at vertices). This means that a PN triangle mesh is continuous in position, but are discontinuous in tangent plane and thus in the neighbouring normals on the shared edge of two adjacent triangles. The reason that the surface appears smooth in Figure 1 of the paper is because an additional fake normal field is used (see section 2.1 of the paper). This normal field is continuous and gives the illusion of a smooth surface.&lt;/p&gt;&#xA;&lt;p&gt;I can point you to a few techniques that might satisfy your requirements&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://www2.eecs.berkeley.edu/Pubs/TechRpts/1987/CSD-87-313.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Triangular Gregory patches&lt;/a&gt;, here the patches will become &lt;span class=&quot;math-container&quot;&gt;$G^1$&lt;/span&gt; or tangent plane continous. It able to be implemented in real-time (using for instance tessellation shaders), but it can be quite hard to wrap your head around the Chiyokura-Kimura technique of joining two patches smoothly. The Gregory patch is a triangular B'ezier patch where certain control points are blended between two positions using a rational function. The normal could be analytically determined, but due to the rational functions it becomes hard to take derivatives.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://hal.inria.fr/inria-00260834/document&quot; rel=&quot;nofollow noreferrer&quot;&gt;Quadratic Approximation of Subdivision surfaces&lt;/a&gt;. This technique is able to be implemented in realtime. Although it does not interpolate normal vectors at vertices, it gives smoother results than PN-triangles. It tries to approximate a Loop-subdivision surface with quadratic B'ezier patches.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://graphicsinterface.org/proceedings/gi2008/gi2008-28/&quot; rel=&quot;nofollow noreferrer&quot;&gt;PNG1 triangles&lt;/a&gt; Comparable to Gregory patches, but in this case a lot of control points are allowed to shift position. I would advise against implementing this technique as it is very complicated and does not give better results than the standard Gregory patch.&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Loop_subdivision_surface&quot; rel=&quot;nofollow noreferrer&quot;&gt;Loop subdivision&lt;/a&gt;, you can pair PN-triangles with several iterations of Loop subdivision to pre-smooth your mesh. The sharp edges of the triangles will become less and less apparent, but at the cost of increased work to do the subdivision.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2021-03-12T11:52:09.783" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10733" PostTypeId="1" CreationDate="2021-03-12T17:47:41.650" Score="2" ViewCount="81" Body="&lt;p&gt;My question follows directly &lt;a href=&quot;https://gamedev.stackexchange.com/questions/59758/microfacet-model-brdf-obtain-extreme-values-at-grazing-angles?noredirect=1&amp;amp;lq=1&quot;&gt;this one&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Reading the famous &lt;a href=&quot;https://www.cs.cornell.edu/%7Esrm/publications/EGSR07-btdf.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;paper&lt;/a&gt; of Walter, it comes that the plotted curves of figure 13 (in question in the related topic) are not directly the brdf but rather the brdf times the cosines of the reflected angle.&lt;/p&gt;&#xA;&lt;p&gt;Because the divergence at grazing angle (shown in the related post) is due to the division by the cosines of the reflected angle (common to all microfacets models), I wonder if this is always the case ?&lt;/p&gt;&#xA;&lt;p&gt;Is there microfacet models with a well shaped brdf lobe at grazing angle ?&lt;/p&gt;&#xA;&lt;p&gt;Do you know references on this topic ?&lt;/p&gt;&#xA;" OwnerUserId="13179" LastEditorUserId="13179" LastEditDate="2021-03-13T09:29:31.697" LastActivityDate="2021-03-13T09:29:31.697" Title="Do all microfacet brdf models diverge at grazing angle?" Tags="&lt;brdf&gt;&lt;microfacet&gt;&lt;ggx&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10734" PostTypeId="2" ParentId="10726" CreationDate="2021-03-12T18:13:02.840" Score="3" Body="&lt;p&gt;On current GPU architectures, at the machine level, compilation of a shader program can depend on which other pipeline stages are active, what the inputs/outputs to those shaders are, as well as what the inputs and outputs of the overall pipeline are (vertex inputs and fragment outputs, for example). There's a lot of complicated architectural reasons why this can be true, for instance that some &amp;quot;builtin&amp;quot; inputs to the FS might actually need to be generated by an earlier stage, that VSes might need to output values differently depending on whether they're going to the FS or to a GS or tessellation shaders, etc.&lt;/p&gt;&#xA;&lt;p&gt;In OpenGL, the driver is doing a lot of work under the hood to take care of these details. From your perspective, you may be only compiling 5 VS and 5 FS and using them in different combinations, but the driver is very likely actually compiling distinct programs (transparently to you) for every combination of VS/FS you use, and moreover also sometimes compiling distinct programs based on other OpenGL state that you wouldn't think was part of the shader at all.&lt;/p&gt;&#xA;&lt;p&gt;With Vulkan, one of the major design goals of the API is to make the driver less &amp;quot;smart&amp;quot; and &amp;quot;magic&amp;quot;, and move a lot of the driver's responsibilities into the app. This was done because OpenGL drivers became increasingly complex and opaque over time, and often caused performance issues that were unpredictable or burdensome to app developers—such as needing to suddenly compile new shaders in the background when a draw call was issued with a not-before-seen combination of shaders and state, causing stalls. The thinking is that by giving the app visibility into and control over such things, it can better manage how shader compilation work is done (e.g. compiling all needed combinations up front, compiling things on a background thread and not stalling rendering, etc). This philosophy extends to many other aspects of the API, such as memory management, command buffers, resource binding, synchronization between CPU and GPU, etc.&lt;/p&gt;&#xA;&lt;p&gt;So, rather than thinking about it like &amp;quot;Vulkan is inconvenient and wasteful&amp;quot; I would try to see it more like &amp;quot;Vulkan makes clearer how much work is actually needed to set things up properly for the GPU, and gives me the control over how that work is done.&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;BTW,&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I've thought about being able to bind shader stages in my code, and then every combination of shader stages could be mapped to a single compiled program, however I don't think the mapping could be searched efficiently.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This sort of thing can totally be done with a hash table; you just have to make a key struct that includes pointers to (or another identifier for) the individual VSes/FSes. But then you have to solve the same problem as the OpenGL driver had to solve, which is that you have to stop and create a new pipeline every time a new combination of VS/FS is seen, and that can result in stalls. It's better, if possible, to pre-create all the combinations you're going to need up front.&lt;/p&gt;&#xA;&lt;p&gt;FWIW, in practice, I think in most applications you don't actually create a lot of combinations of different VSes and FSes. Most rendering engines only have a single VS for each FS (or a small handful of VSes for each FS), so there's not usually going to be a huge combinatoric explosion of different combinations.&lt;/p&gt;&#xA;" OwnerUserId="48" LastEditorUserId="48" LastEditDate="2021-03-12T22:49:45.060" LastActivityDate="2021-03-12T22:49:45.060" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10735" PostTypeId="2" ParentId="10728" CreationDate="2021-03-12T19:53:16.763" Score="3" Body="&lt;p&gt;You probably want to set sigma to be a fraction of the radius, rather than a fixed value. Sigma controls the actual shape of the filter, while radius just controls how far out the filter gets cut off (as Gaussians truly have infinite radius, so we have to cut them off somewhere to use them in practice). With sigma set to 0.5, you're making a filter that's very sharply peaked within a radius of 0.5 pixels, which is consistent with the image you're getting.&lt;/p&gt;&#xA;&lt;p&gt;Instead, try setting sigma = 0.25 or 0.3 times the radius. Or alternatively, make sigma your main parameter and then set the radius to 3 or 4 times sigma.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-03-12T19:53:16.763" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10736" PostTypeId="1" AcceptedAnswerId="10737" CreationDate="2021-03-13T22:46:05.087" Score="1" ViewCount="21" Body="&lt;p&gt;I am attempting to use a compute shader to calculate joint transforms for animations.&lt;/p&gt;&#xA;&lt;p&gt;I use a loop to calculate the global joint transforms from the local transforms. Relevant code below:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;layout(set = 0, binding = 2) readonly buffer LocalTransforms {&#xA;    Similarity local_transforms[];&#xA;};&#xA;&#xA;layout(set = 0, binding = 3) buffer GlobalTransforms {&#xA;    mat4 global_transforms[];&#xA;};&#xA;&#xA;struct NodeAndParent {&#xA;    uint node_index;&#xA;    int parent_index;&#xA;};&#xA;&#xA;layout(set = 0, binding = 4) readonly buffer DepthFirstNodes {&#xA;    NodeAndParent depth_first_nodes[];&#xA;};&#xA;&#xA;void main() {&#xA;    uint index = gl_GlobalInvocationID.x;&#xA;&#xA;    uint nodes_offset = index * num_nodes;&#xA;&#xA;    if (nodes_offset &amp;gt;= global_transforms.length()) {&#xA;        return;&#xA;    }&#xA;&#xA;    for (uint i = 0; i &amp;lt; num_nodes; i++) {&#xA;        NodeAndParent indices = depth_first_nodes[i];&#xA;&#xA;        uint node_index = nodes_offset + indices.node_index;&#xA;        mat4 local_transform = similarity_to_mat4(local_transforms[node_index]);&#xA;&#xA;        if (indices.parent_index != -1) {&#xA;            mat4 parent_transform = global_transforms[nodes_offset + indices.parent_index];&#xA;            global_transforms[node_index] = parent_transform * local_transform;&#xA;        } else {&#xA;            global_transforms[node_index] = local_transform;&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;There is a bug somewhere and I have been attempting to use renderdoc to debug it. I have realised that on the first iteration, one matrix is written to index 3 of of the buffer (right side image), but when it is read back as the parent transform on the second iteration (left image), the values reported in renderdoc are incorrect.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ktkNY.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ktkNY.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Note that the section of the buffer is not being used by any other thread, and I have an early-exit for threads that would be out-of-bounds of &lt;code&gt;global_transforms&lt;/code&gt;. I've tested other threads and they all return early.&lt;/p&gt;&#xA;&lt;p&gt;My question is this:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;A) Is it possibly that renderdoc is reporting this incorrectly?&lt;/li&gt;&#xA;&lt;li&gt;B) Is the value stored in the buffer really like that in that point in time? Would using a barrier help? What kind of barrier?&lt;/li&gt;&#xA;&lt;li&gt;C) Is there some other problem with the code that could be causing this?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Thank you!&lt;/p&gt;&#xA;" OwnerUserId="15920" LastActivityDate="2021-03-13T23:44:14.813" Title="Mat4 that is written to a storage buffer in a compute shader has an altered value when read back" Tags="&lt;glsl&gt;&lt;vulkan&gt;&lt;compute-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10737" PostTypeId="2" ParentId="10736" CreationDate="2021-03-13T23:44:14.813" Score="1" Body="&lt;p&gt;It appears that this is indeed a bug within renderdoc. I have encountered the bug I was debugging for in only 1 model, while all the others work fine. In every instance of using the renderdoc debugger, I get the same problem though.&lt;/p&gt;&#xA;" OwnerUserId="15920" LastActivityDate="2021-03-13T23:44:14.813" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10738" PostTypeId="1" AcceptedAnswerId="10740" CreationDate="2021-03-14T13:36:32.607" Score="1" ViewCount="53" Body="&lt;p&gt;What I want is a function like &lt;code&gt;imageStore&lt;/code&gt;, but instead of replacing a value - applying a blend operation to it, e.g. addition. It is not possible to do something like this with atomics due to them only operating on 32bit integers.&lt;/p&gt;&#xA;&lt;p&gt;If there is no such function, why have noone made an extension for this yet? It seems rather useful for compute shader lighting, and some post-processing effects.&lt;/p&gt;&#xA;" OwnerUserId="15705" LastActivityDate="2021-03-14T17:59:20.273" Title="Is there an efficient way to achieve color blending in compute shaders?" Tags="&lt;opengl&gt;&lt;glsl&gt;&lt;vulkan&gt;&lt;compute-shader&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10739" PostTypeId="1" AcceptedAnswerId="10742" CreationDate="2021-03-14T13:39:21.030" Score="2" ViewCount="32" Body="&lt;p&gt;I need something to be cleared up for me, and I hope this is the right place to ask my question:&lt;/p&gt;&#xA;&lt;p&gt;I intend to attempt stochastic transparency, where I will draw glass panes and smoke particles onto the g-buffer for deferred shading.&#xA;For every 2x2 cell of pixels, I will allow up to 3 of the 4 pixels to be used for glass or smoke. The last pixel is always the opaque background. But say we have this situation:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Camera&lt;/li&gt;&#xA;&lt;li&gt;(Near clip plane)&lt;/li&gt;&#xA;&lt;li&gt;Smoke particle&lt;/li&gt;&#xA;&lt;li&gt;Glass pane&lt;/li&gt;&#xA;&lt;li&gt;Solid wall&lt;/li&gt;&#xA;&lt;li&gt;(Far clip plane)&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The smoke particle is in front of the glass pane, and would occupy all 3 pixels. This I do not want, and therefore I will need to check whether neighbouring pixels in that 2x2 cell already have 'smoke' or 'glass' written to them, rather than just the simple Z-check.&lt;/p&gt;&#xA;&lt;p&gt;I therefore wish to sample neighbouring pixels from the same g-buffer that I'm currently writing to, but this seems not possible, am I right? And why do the depth &amp;amp; stencil buffers seem to be exceptions to this, or does this have something to do with only reading the exact pixel you are about to write to?&lt;/p&gt;&#xA;&lt;p&gt;I hope the way I formulated the question(s) make sense, and is sufficiently detailed.&lt;/p&gt;&#xA;" OwnerUserId="15922" LastActivityDate="2021-03-14T18:34:22.383" Title="Reading neighbouring pixels during object draw call" Tags="&lt;rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10740" PostTypeId="2" ParentId="10738" CreationDate="2021-03-14T14:16:36.297" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;If there is no such function, why have noone made an extension for this yet?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Just because something might be &amp;quot;useful&amp;quot; doesn't mean it would be possible or cheap.&lt;/p&gt;&#xA;&lt;p&gt;GPU hardware achieves blending by using an &lt;em&gt;entirely separate&lt;/em&gt; piece of hardware, one that preserves the order of the fragment values generated by unordered fragment shader executions. These &lt;a href=&quot;https://en.wikipedia.org/wiki/Render_output_unit&quot; rel=&quot;nofollow noreferrer&quot;&gt;execution units, commonly called &amp;quot;ROPs&amp;quot;&lt;/a&gt;, are distinct hardware from fragment shaders.&lt;/p&gt;&#xA;&lt;p&gt;CS's can't just do that. They have a fundamentally unordered execution model, and what you're talking about requires at least some ordering between them. That's not simple or cheap to implement, even if it's &lt;em&gt;possible&lt;/em&gt; at all.&lt;/p&gt;&#xA;&lt;p&gt;The closest you can get to that is &lt;a href=&quot;https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_fragment_shader_interlock.txt&quot; rel=&quot;nofollow noreferrer&quot;&gt;fragment_shader_interlock&lt;/a&gt;, which can force parts of FS execution to be ordered by primitive order and to execute critical sections that prevent overlapping executions. But as the name suggests, that's a feature of fragment shaders (and not one universally supported), not a feature of compute shaders.&lt;/p&gt;&#xA;&lt;p&gt;Also, it doesn't really make sense to use a compute shader for post-processing effects, since FS's are perfectly capable of dealing with that sort of thing, and actually have access to ROPs.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-14T14:16:36.297" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10741" PostTypeId="2" ParentId="10738" CreationDate="2021-03-14T17:59:20.273" Score="0" Body="&lt;p&gt;You can always just do an image load, apply whatever math you want to the value, and then store it back out. This only works if you can ensure multiple CS invocations aren't trying to modify the same pixel—otherwise you get a race condition—but that limitation is fine for most lighting and postprocessing applications, where you're running a single CS dispatch across a whole framebuffer (or some tiles within a framebuffer), with one invocation per pixel.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-03-14T17:59:20.273" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10742" PostTypeId="2" ParentId="10739" CreationDate="2021-03-14T18:34:22.383" Score="3" Body="&lt;p&gt;In general you can't safely read from neighboring pixels in the render target you're currently writing to. You can sample from them, but there's no guarantees about how other pixels are scheduled on the GPU, so it's a race condition—you might get the neighboring pixel value either before or after modification, and it might change frame to frame due to unpredictable scheduling differences.&lt;/p&gt;&#xA;&lt;p&gt;You can read from the same pixel you're about to write to, but only if your geometry is set up to ensure that nothing is overlapping in screen space (e.g. a full-screen pass). If other triangles in the same render pass are overlapping the same area on screen, then you have a race condition again, similar to the neighboring-pixels case. (You can use fragment_shader_interlock or equivalent functionality to address this case, but it is not universally supported across all GPU vendors, and it can also be slow.)&lt;/p&gt;&#xA;&lt;p&gt;The depth and stencil buffers, as well as fixed-function blending (additive, alpha, etc) can get around this because they have special-purpose hardware that sorts the fragments in submission order in order to apply those simple fixed operations.&lt;/p&gt;&#xA;&lt;p&gt;I believe the way stochastic transparency usually works is to randomize the set of pixels output and use spatial/temporal filtering to clean up the noise afterward. So you wouldn't have such fine-grained control like &amp;quot;within each 2x2 block, there will be N pixels of this, and M pixels of that&amp;quot;. It would be more probablistic, like &amp;quot;on average, X% of the pixels will be this, and Y% of the pixels will be that&amp;quot;, with the exact outputs being randomly chosen each frame.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-03-14T18:34:22.383" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10743" PostTypeId="2" ParentId="10332" CreationDate="2021-03-14T23:09:50.293" Score="0" Body="&lt;p&gt;In short words, VBO is an array of raw data, when VAO is an array of ATTRIBUTES - an instruction for shader program how to use the data.&lt;/p&gt;&#xA;&lt;p&gt;Before, in OpenGL ES 2.0 for example, VAO wasn't introduced yet at all and VBO was optional. You still could pass to your shader your data RAM addresses. Still this data had to pass CPU-to-GPU &amp;quot;bridge&amp;quot; on each call, but this process wasn't exposed to you. VBO allows to keep data on GPU side, which saves transfer time, you just need to know VBO's id.&lt;/p&gt;&#xA;&lt;p&gt;But VBO by itself is not enough. You have to instruct GPU how to use it. You have to define &amp;quot;Vertex Attribute Pointers&amp;quot; (command glVertexAttribPointer) for each attribute (input data variable) of your shader. Before VAO you had to define attributes for each glDrawArrays call (it's a lot), in every frame (like 30+ times per second). VAO allows to attach an entire array of attributes by just VAO's id. So, when VBO is relatively independent, the VAO is VBO+shader-specific.&lt;/p&gt;&#xA;" OwnerUserId="15926" LastActivityDate="2021-03-14T23:09:50.293" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10744" PostTypeId="1" AcceptedAnswerId="10745" CreationDate="2021-03-15T06:34:12.310" Score="2" ViewCount="405" Body="&lt;p&gt;I have been told there is no performance difference if you are skilled enough when it comes to gpu computing. And cuda only performs better because nvidia wants it to. I have also read graphic api's compute shaders are not as good as OpenCL/cuda. I don't understand how are compute shader different from Cuda/OpenCL and why would they be slow (if they are). I wanted to know this because OpenCL is difficult to understand and setup for me. Will there be a performance hit on using OpenGL compute shader and will Vulkan compute shader perform better than OpenGL's?&lt;/p&gt;&#xA;" OwnerUserId="15207" LastEditorUserId="67" LastEditDate="2021-05-24T06:01:47.620" LastActivityDate="2021-05-24T06:01:47.620" Title="Performance difference in OpenGL compute shader vs Vulkan Compute Shader vs Cuda/OpenCL and others" Tags="&lt;opengl&gt;&lt;compute-shader&gt;&lt;cuda&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10745" PostTypeId="2" ParentId="10744" CreationDate="2021-03-15T16:50:22.037" Score="4" Body="&lt;p&gt;In general, you should not see significant performance differences running identical compute shaders via one API vs. another; in the end they’re running the same instructions on the same hardware. It’s possible for vendor-provided toolkits like CUDA or &lt;a href=&quot;https://developer.apple.com/documentation/metalperformanceshaders&quot; rel=&quot;nofollow noreferrer&quot;&gt;MetalPerformanceShaders&lt;/a&gt; to have more efficient implementations of a given algorithm on that vendor’s hardware than a more generic version of the algorithm, because they’ve been designed and tuned for the strengths of that hardware, but there’s nothing in principle that would prevent you from developing the same efficiencies on your own with enough optimization work.&lt;/p&gt;&#xA;&lt;p&gt;Long story short: work with whichever API you find easiest to use, and invest some time in learning how to profile and tune your code for the hardware you plan to run it on.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-03-15T16:50:22.037" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10746" PostTypeId="2" ParentId="8913" CreationDate="2021-03-16T13:59:28.137" Score="1" Body="&lt;p&gt;This is not really an answer to the latter parts of your question but more to address&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;As we know, tiles can make it quicker to update large portions of the display at once, as compared with a bitmap. To put, say a letter, on the screen, the Commodore 64 typically does two writes (the screencode and the attribute)&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;What you are effectively describing is a compressed framebuffer where you are directly writing/storing compressed data and letting the display pipeline decompress on the fly.&lt;/p&gt;&#xA;&lt;p&gt;I would say that such things &amp;quot;still exist&amp;quot; in today's games/hardware, but not perhaps in form you are expecting.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;&lt;p&gt;Compressed frame buffers do still exist. Mobile devices certainly do (for example Imagination/PowerVR have &lt;a href=&quot;https://www.imgtec.com/blog/reducing-bandwidth-pvric/&quot; rel=&quot;nofollow noreferrer&quot;&gt;PVRIC&lt;/a&gt;, and I believe ARM devices have their own scheme)&#xA;These compression schemes are generally &amp;quot;transparent&amp;quot; to the programmer, but it does mean the GPU and display pipeline does less reading and writing of external memory.&#xA;&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;A display decompression system like PCG  (Programmable Character Generator) is effectively a precursor to (and effectively a subset of) some texture compression schemes, e.g. such as S3TC/DXT1. In that sense, therefore it still exists, but users don't typically write directly to them, but certainly take advantage of the bandwidth savings.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;" OwnerUserId="209" LastActivityDate="2021-03-16T13:59:28.137" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10747" PostTypeId="2" ParentId="8913" CreationDate="2021-03-16T19:53:30.773" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;But, however hard I search I cannot find any contemporaneous games for these retro systems which use a tileset to render (an approximation of) three-dimensional graphics. So is there a technical reason for that?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;That all depends on your definition of &amp;quot;an approximation of&amp;quot;. Games that use pre-rendered sprites were hardly unheard-of in the 16-bit era. You could consider that &amp;quot;an approximation of&amp;quot; 3D graphics.&lt;/p&gt;&#xA;&lt;p&gt;Would you consider a game like &lt;a href=&quot;https://en.wikipedia.org/wiki/Marble_Madness&quot; rel=&quot;nofollow noreferrer&quot;&gt;Marble Madness&lt;/a&gt; to be &amp;quot;an approximation of&amp;quot; 3D graphics? It doesn't render polygons, but it is polygonal in aesthetics. And it is 3D-ish. What of a game like &lt;a href=&quot;https://www.youtube.com/watch?v=ZONUS-iFf18&quot; rel=&quot;nofollow noreferrer&quot;&gt;Captain Skyhawk&lt;/a&gt;, which uses a similar polygonal backdrop and is even more 3D-ish?&lt;/p&gt;&#xA;&lt;p&gt;But a first-person kind of game like what you're trying to describe is a different beast. Those games just use tiles to generate a background that appears polygonal, a static background at that. You want to do real 3D.&lt;/p&gt;&#xA;&lt;p&gt;The SNES was capable of Doom because the SNES had enough video RAM for the CPU to basically use the tile data as the framebuffer. And it had a CPU fast enough to compute the pixels for that tile framebuffer every frame or so. That is also what the example you gave is doing: the PPU of the Genesis was just being given a bunch of tile bitmaps (generated externally and therefore can be fast), and they formed a single image.&lt;/p&gt;&#xA;&lt;p&gt;It's just building a framebuffer, chopping it up into tile-sized blocks, and shoving that into a graphics chip designed to render tiles. It's not that impressive, is it? It's just a matter of having enough tile memory to give each location on the screen a separate tile.&lt;/p&gt;&#xA;&lt;p&gt;Attempts have been made to do Doom on the C64, but they were only successful by giving it a faster CPU. It's simply not feasible to do the kind of thing you're trying. Not generally at any rate.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-16T19:53:30.773" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10748" PostTypeId="1" CreationDate="2021-03-17T14:02:03.690" Score="0" ViewCount="50" Body="&lt;p&gt;I don't understand how OpenGL performs the blending of a texture on the screen. By default, the clear color is set to (0, 0, 0, 0). If we use the default blending equation GL_SRC_ALPHA and GL_ONE_MINUS_SRC_ALPHA, it means that if our texture is all (1, 0, 0, 0.3), the resulting RGB will be (1, 0, 0)×0.3 + (0, 0, 0)×0.7 = (0.3, 0, 0) BUT the alpha component will be 0.3×0.3 + 0×(1 - 0.3) = 0.3, so we then have a color of (0.3, 0, 0, 0.09) which is not correct, what we want to see on the screen is rather (0.3, 0, 0, 1).&lt;/p&gt;&#xA;&lt;p&gt;So how does OpenGL manages the final blending with the framebuffer? Does it drop the alpha component (because the screen can only display RGB colors)?&lt;/p&gt;&#xA;" OwnerUserId="10928" LastActivityDate="2021-04-16T15:47:23.870" Title="OpenGL blending with the screen" Tags="&lt;opengl&gt;&lt;blending&gt;&lt;alpha&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10749" PostTypeId="2" ParentId="10748" CreationDate="2021-03-17T15:08:15.953" Score="0" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;BUT the alpha component will be 0.3×0.3 + 0×(1 - 0.3) = 0.3, so we then have a color of (0.3, 0, 0, 0.09) which is not correct, what we want to see on the screen is rather (0.3, 0, 0, 1).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Your blending function did not use the destination alpha. So &amp;quot;correct&amp;quot; or &amp;quot;not correct&amp;quot;, its value is entirely &lt;em&gt;irrelevant&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;However, if you want to make the alpha more accurate in some way, you can provide a &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Blending#Blending_Parameters&quot; rel=&quot;nofollow noreferrer&quot;&gt;different set of blending factors&lt;/a&gt;, and even a &lt;a href=&quot;https://www.khronos.org/opengl/wiki/Blending#Blend_Equations&quot; rel=&quot;nofollow noreferrer&quot;&gt;different blend equation&lt;/a&gt;, for the alpha component.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-17T15:08:15.953" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10750" PostTypeId="1" AcceptedAnswerId="10751" CreationDate="2021-03-17T21:58:35.687" Score="1" ViewCount="69" Body="&lt;p&gt;If we have a quad that is non-planar. Why do most 3d modeling packages choose to use a single normal for the quad (Specifically for Blender3d &lt;a href=&quot;https://blender.stackexchange.com/questions/47656/how-does-blender-implement-flat-shading-non-planar-polygons&quot;&gt;by using cross product of two edge's vectors that do not share a vertex&lt;/a&gt;, &lt;a href=&quot;https://math.stackexchange.com/questions/3049969/calculate-surface-normal-and-area-for-a-non-planar-quadrilateral&quot;&gt;here's the math&lt;/a&gt;). Instead of viewing it as two triangles, and using a separate normal for each triangle?&lt;/p&gt;&#xA;&lt;p&gt;Normally we calculate a vertex normal as the normalized average of all polygons the vertex is part of. If we have a quad consisting of two triangles, then the two vertices that are part of both triangles, get the average of the two triangle normals. This results in smooth shading across the non-planar quad. Instead of the uniform shading we would get if we were to use a single normal for the whole quad.&lt;/p&gt;&#xA;&lt;p&gt;This also extends to polygons in general. In 3d modeling sofware a single normal is calculated for the whole polygon (for Blender3d &lt;a href=&quot;https://blender.stackexchange.com/questions/47656/how-does-blender-implement-flat-shading-non-planar-polygons&quot;&gt;with Newell's method&lt;/a&gt;), instead of individual normals for each triangle it consists of.&lt;/p&gt;&#xA;&lt;p&gt;To build on top of this, if we have a mesh with flat shading, each polygon gets a single normal as described above. Flat shading means that the shared vertices are split. And each vertex gets the normal of the polygons it's part of. However what happens if we want to apply a smooth shading on the mesh? Are the vertex normals calculated as average of all &lt;em&gt;polygons&lt;/em&gt; it is part of? This doesn't seem right. Do we instead &lt;em&gt;triangulate the mesh&lt;/em&gt;, and calculate the vertices as the average of all triangles it's part of?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2021-03-17T22:41:12.533" LastActivityDate="2021-03-18T01:19:06.740" Title="Why do 3d modeling packages use a single normal per polygon and how is this viable for smooth shading" Tags="&lt;shading&gt;&lt;polygon&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10751" PostTypeId="2" ParentId="10750" CreationDate="2021-03-18T01:19:06.740" Score="1" Body="&lt;p&gt;I think the problem comes from this starting assumption:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;If we have a quad that is non-planar.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;A non-planar quad &lt;em&gt;does not have&lt;/em&gt; a normal. It's not a flat surface, so you can't talk about what its normal would be. You can't talk about the normal of a sphere, a cone, or any other non-flat surface. You can talk about what the normal might be at any particular point on that surface, but there is no normal for the surface in its entirety.&lt;/p&gt;&#xA;&lt;p&gt;You are asking a question for which there is no correct answer. But there are many incorrect answers, and they're all &lt;em&gt;equally&lt;/em&gt; wrong. So there's no reason to pick one wrong answer over another.&lt;/p&gt;&#xA;&lt;p&gt;If you're talking about computing vertex normals, a non-planar quad is still not a valid surface. The two triangulations for a non-planar quad represent &lt;em&gt;very&lt;/em&gt; different surfaces, which would have very different vertex normals. Neither answer can claim legitimacy over the other, so both answers are equally wrong.&lt;/p&gt;&#xA;&lt;p&gt;So why choose that particular method? Because it's no more wrong than any other method you might pick.&lt;/p&gt;&#xA;&lt;p&gt;It does not make sense to talk about the vertex or face normals for non-planar polygons. So if you want an answer that makes sense, fix &lt;em&gt;that&lt;/em&gt; problem first.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-03-18T01:19:06.740" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10752" PostTypeId="1" AcceptedAnswerId="10755" CreationDate="2021-03-18T15:42:46.173" Score="0" ViewCount="104" Body="&lt;p&gt;If I have a mesh consisting of polygons that are not necessarily triangles and not necessarily planar. As answered in the previous &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10750/why-do-3d-modeling-packages-use-a-single-normal-per-polygon-and-how-is-this-viab/10751?noredirect=1#comment16864_10751&quot;&gt;question&lt;/a&gt; I asked, there's no correct answer to calculating normals for such polygons. So I'm wondering instead no matter how wrong, what are some of the strategies used in 3d modeling to calculate the vertex normals for such a mesh, &lt;em&gt;specifically for smooth shading&lt;/em&gt;?&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2021-03-19T17:47:50.257" LastActivityDate="2021-03-19T17:47:50.257" Title="How to calculate vertex normals on a mesh with non-planar polygons" Tags="&lt;opengl&gt;&lt;shading&gt;&lt;polygon&gt;" AnswerCount="2" CommentCount="16" ContentLicense="CC BY-SA 4.0" />
  <row Id="10753" PostTypeId="2" ParentId="10752" CreationDate="2021-03-18T16:49:44.920" Score="0" Body="&lt;p&gt;for smooth shading you usually store the normal vectors per vertex and not per face (flat shading). The normal vector on a specific point on a face will then be calculated by interpolating the normal vectors of the vertices (corners) of the face.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;For example when having a triangle:&lt;/strong&gt;&#xA;you would use an interpolation which uses the barycentric coordinates of three normal vectors like discribed &lt;a href=&quot;http://15462.courses.cs.cmu.edu/fall2015/lecture/texture/slide_019&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;For non planar polygons, of cause you don't have a specific defined surface.&#xA;Therefore it depend on you, which kind of interpolation you are using. But it should interpolate with respect to the corners distance.&lt;/p&gt;&#xA;&lt;p&gt;And don't forget to normalize the vector at the end!&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2021-03-18T16:49:44.920" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10754" PostTypeId="1" CreationDate="2021-03-18T20:56:28.980" Score="0" ViewCount="77" Body="&lt;p&gt;I am trying to implement next/prev of edges in half-edge data structure. But I ran into this question. If there are two holes with a common vertex, will the closed loop of the edges run as in the first picture? Or will it be two separate cycles, as in the second picture?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/mYM61.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/mYM61.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In 3ds Max, when the border tool is used, it selects the edge loop as in the first image. Please help me to understand this.&lt;/p&gt;&#xA;" OwnerUserId="15940" LastActivityDate="2021-04-21T20:03:45.343" Title="Half-Edge Data Structure with holes" Tags="&lt;c++&gt;&lt;edge-detection&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10755" PostTypeId="2" ParentId="10752" CreationDate="2021-03-19T17:27:05.687" Score="3" Body="&lt;p&gt;If you're interested in vertex normals specifically, there's an easy answer even for non-planar polygons that avoids the question of defining what the exact surface is: for each vertex, calculate the normal of the plane formed by the two edges entering and leaving that vertex.&lt;/p&gt;&#xA;&lt;p&gt;More formally, given vertices &lt;span class=&quot;math-container&quot;&gt;$\mathbf{v}_1, \mathbf{v}_2, \ldots \mathbf{v}_n$&lt;/span&gt; with counterclockwise winding, define the normal at the &lt;span class=&quot;math-container&quot;&gt;$i$&lt;/span&gt;th vertex as:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\mathbf{n}_i = (\mathbf{v}_i - \mathbf{v}_{i-1}) \times (\mathbf{v}_{i+1} - \mathbf{v}_i)&#xA;$$&lt;/span&gt;&#xA;(where the indices wrap around).&lt;/p&gt;&#xA;&lt;p&gt;You can then proceed to accumulate normals calculated this way from all the faces that share a given vertex, as usual for smooth shading.&lt;/p&gt;&#xA;&lt;p&gt;As has been discussed, there are multiple ways to define a smooth surface corresponding to a non-planar polygon, but &lt;em&gt;any&lt;/em&gt; reasonable way of defining such a surface must converge to the normals as defined here near the vertices, or else the surface can not both be smooth (locally flat) and meet the straight-line edges between the vertices.&lt;/p&gt;&#xA;&lt;p&gt;A caveat to this approach, though, is that it won't define a normal for collinear vertices (where the entering and exiting edges are parallel), since the cross product goes to zero there. If this is a problem, it might work to patch up such vertices by interpolating normals to them from the surrounding non-collinear vertices.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-03-19T17:27:05.687" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10757" PostTypeId="1" CreationDate="2021-03-20T14:55:23.503" Score="2" ViewCount="132" Body="&lt;p&gt;I was reading the wiki article about homogeneous coordinates , I learned that it has it's advantages when it comes to performing affine transformation, since you can represent it only matrices. But I couldn't understand what is the additional third component compared to  Cartesian coordinates.   In the image below  we see additional 1(which  I am trying to understand)  added to convert it to  homogeneous coordinates.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/e4gAx.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e4gAx.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15950" LastActivityDate="2021-03-22T10:54:17.460" Title="What is exactly the third component in homogeneous coordinate system?" Tags="&lt;affine-transformations&gt;" AnswerCount="2" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10758" PostTypeId="2" ParentId="10757" CreationDate="2021-03-20T16:22:22.873" Score="2" Body="&lt;p&gt;The relationship between standard coordinates &lt;span class=&quot;math-container&quot;&gt;$(x,y)$&lt;/span&gt; and homogeneous coordinates &lt;span class=&quot;math-container&quot;&gt;$(X,Y,Z)$&lt;/span&gt; is &lt;span class=&quot;math-container&quot;&gt;$x = X / Z, y = Y/Z$&lt;/span&gt;. Homogeneous coordinates are a type of &lt;a href=&quot;https://en.wikipedia.org/wiki/Homogeneous_coordinates&quot; rel=&quot;nofollow noreferrer&quot;&gt;projective coordinates&lt;/a&gt;. All points on the line &lt;span class=&quot;math-container&quot;&gt;$(Z x, Z y, Z)$&lt;/span&gt; are equivalent to the point &lt;span class=&quot;math-container&quot;&gt;$(x,y)$&lt;/span&gt; in 2D (the same thing can be applied for 3D). So technically 2D points are represented as 3D lines passing though the origin, and 2D lines are represented as 3D planes passing through the origin.&lt;/p&gt;&#xA;&lt;p&gt;In computer graphics the above interpretation is largely irrelevant, however, since homogeneous coordinates are used mostly for convenience. A translation is of the form &lt;span class=&quot;math-container&quot;&gt;$x' = x+t_x, y' = y+t_y$&lt;/span&gt;. If one uses homogeneous coordinates, then this can be achieved through &lt;span class=&quot;math-container&quot;&gt;$X' = 1 \cdot X + 0 \cdot Y + t_x \cdot Z$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$Y' = 0 \cdot X + 1 \cdot Y + t_y \cdot Z$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$Z' = 0 \cdot X + 0\cdot Y + 1 \cdot Z$&lt;/span&gt;.  If you set &lt;span class=&quot;math-container&quot;&gt;$Z=1$&lt;/span&gt; then you get exactly the expression for translation, and you can use the matrix induced from the 3 equations above. For directions you can set &lt;span class=&quot;math-container&quot;&gt;$Z=0$&lt;/span&gt; so that translation would not be applied to those.&lt;/p&gt;&#xA;&lt;p&gt;In 3D the homogeneous coordinates &lt;span class=&quot;math-container&quot;&gt;$W$&lt;/span&gt; also plays a role in the perspective projection, since the projection matrix modifies it to hold the relevant value by which the other coordinates must be divided, and the division is typically carried out by the hardware.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2021-03-20T16:22:22.873" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10759" PostTypeId="1" AcceptedAnswerId="10760" CreationDate="2021-03-21T08:35:25.510" Score="1" ViewCount="87" Body="&lt;p&gt;I have a very simple obj file:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;v -2.22045e-16 -0.291306 -2.22045e-16&#xA;v -0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 -0.24339&#xA;v -2.22045e-16 -2.22045e-16 -0.24339&#xA;v 0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 -0.291306 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 -0.24339&#xA;v -0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 0.291306 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 -0.24339&#xA;v -2.22045e-16 0.291306 -2.22045e-16&#xA;v 0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 -0.291306 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 0.24339&#xA;v -0.24339 -2.22045e-16 -2.22045e-16&#xA;v 0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 0.24339&#xA;v -2.22045e-16 -0.291306 -2.22045e-16&#xA;v -0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 0.24339&#xA;v -2.22045e-16 0.291306 -2.22045e-16&#xA;v 0.24339 -2.22045e-16 -2.22045e-16&#xA;v -2.22045e-16 0.291306 -2.22045e-16&#xA;v -2.22045e-16 -2.22045e-16 0.24339&#xA;f 3 2 1&#xA;f 6 5 4&#xA;f 9 8 7&#xA;f 12 11 10&#xA;f 15 14 13&#xA;f 18 17 16&#xA;f 21 20 19&#xA;f 24 23 22&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;As you can see, there is no &lt;code&gt;vn&lt;/code&gt; command. However, if I open it in meshlab and turn on the vertex normal rendering, it shows vertex normals (and some normals not attached to vertices).&lt;/p&gt;&#xA;&lt;p&gt;Why does this happen?&lt;/p&gt;&#xA;" OwnerUserId="15320" LastEditorUserId="15320" LastEditDate="2021-03-21T12:15:43.477" LastActivityDate="2021-03-21T15:05:23.017" Title="How does OBJ format determine vertex normals?" Tags="&lt;3d&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10760" PostTypeId="2" ParentId="10759" CreationDate="2021-03-21T13:30:40.087" Score="1" Body="&lt;p&gt;It is common for modeling software to compute the normals when they aren't included in the loaded file (regardless of the format). This is usually highly dependent on the settings chosen when the file is loaded. Vertex normals can be computed fairly easily. The software can also compute smooth or faceted normals so you can switch between the two.&lt;/p&gt;&#xA;&lt;p&gt;Your example includes faces...the &lt;code&gt;f 3 2 1&lt;/code&gt; is a face. Each number refers to  one of the vertex values which are numbered starting from the top. &lt;code&gt;v -2.22045e-16 -0.291306 -2.22045e-16&lt;/code&gt; is vertex number 1 in this case. The software can easily use that information to compute normals.&lt;/p&gt;&#xA;&lt;p&gt;A normal is computed from the cross product of the edge vectors. Stictly speaking the obj format doesn't compute the actual normals, it just provides the information that Meshlab needs so that Meshlab can compute the normals. which looks something along the lines of:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;facted_normal = normalize( cross( 2-3, 1-3))&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;Where the numbers for 1, 2 and 3 are replaced with the actual values for those vertices. Other types of normals are usually computed based of that.&lt;/p&gt;&#xA;&lt;p&gt;I loaded this file into Blender and it is well behaved, so odds are meshlab has some options turned on that are showing split normals or vertex normals or one of the many other possible variants out there.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-03-21T15:05:23.017" LastActivityDate="2021-03-21T15:05:23.017" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10761" PostTypeId="2" ParentId="10759" CreationDate="2021-03-21T13:32:14.083" Score="1" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Why does this happen?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;If no normals are supplied, meshlab probably generates them. This is common behaviour of many 3D applications.&lt;/p&gt;&#xA;&lt;p&gt;There are various techniques for generating normals (per-vertex, per-face, weighted, non-weighted etc) depending on the desired appearance (smooth/flat shading).&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;(and some normals not attached to vertices).&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Sound possibly like a bug on meshlab's part. Can you post a screen-shot?&lt;/p&gt;&#xA;" OwnerUserId="9438" LastActivityDate="2021-03-21T13:32:14.083" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10762" PostTypeId="1" AcceptedAnswerId="10764" CreationDate="2021-03-21T17:57:29.423" Score="0" ViewCount="102" Body="&lt;p&gt;So I am making a raytracer following the very helpful &lt;a href=&quot;https://www.gabrielgambetta.com/computer-graphics-from-scratch/05-extending-the-raytracer.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;online book of Gabriel Gambetta&lt;/a&gt; but I stumble on the rotation matrix part.&lt;/p&gt;&#xA;&lt;p&gt;My linear algebra background is 3Blue1Brown video series &amp;quot;The essence of Linear Algebra&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;I simulate a camera placed at the origin that's looking forward ie whose direction is the vector &lt;code&gt;{0,0,1}&lt;/code&gt;.&#xA;Let's say I am given another camera direction with direction &lt;code&gt;{a,b,c}&lt;/code&gt;.&#xA;From what I understand if I find the rotation matrix R that takes as an input &lt;code&gt;{0,0,1}&lt;/code&gt; and spits out a normalized &lt;code&gt;{a,b,c}&lt;/code&gt; as an output.&#xA;Then I can apply that rotation matrix to all my rays in order to rotate them.&#xA;I can't get my head around on how to find R. Any help/explanation/correction much welcome.&lt;/p&gt;&#xA;&lt;p&gt;I am in a similar situation than &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10613/transforming-a-ray-from-camera-space-to-world-space&quot;&gt;the person asking this question&lt;/a&gt; except that he seems to know already what needs be done and is just asking&#xA;about if his rationale is good.&lt;/p&gt;&#xA;&lt;p&gt;Thanks&lt;/p&gt;&#xA;&lt;p&gt;EDIT : The answer below is valid considering how I framed my problem but note that if you were like me trying to compute a camera to world rotation matrix and expected the viewport of your camera to follow along, you need an additional step because the answer below only gives you a shear matrix. In order to get a rotation matrix you need to compute the &lt;code&gt;upVector&lt;/code&gt; with &lt;code&gt;normalize(cross_product(rightVector, forwardVector))&lt;/code&gt; (in a right hand system) and feed its coordinates into the matrix instead of &lt;code&gt;{0,1,0}&lt;/code&gt;&lt;/p&gt;&#xA;" OwnerUserId="15954" LastEditorUserId="5778" LastEditDate="2021-03-28T11:21:10.310" LastActivityDate="2021-03-28T11:21:10.310" Title="Given two 3d vectors, find the rotation matrix between the two" Tags="&lt;raytracing&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10763" PostTypeId="1" CreationDate="2021-03-21T18:21:53.030" Score="2" ViewCount="153" Body="&lt;p&gt;I would like a help to understand the following line of code:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;return float3(pow(color.r, 2.2), pow(color.g, 2.2), pow(color.b, 2.2));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I've seen some places calling it gamma correction, but I don't know if it's correct.&lt;/p&gt;&#xA;&lt;p&gt;If it really is a gamma correction how does it work?&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fnpRg.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fnpRg.jpg&quot; alt=&quot;No Correction&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ggIev.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ggIev.jpg&quot; alt=&quot;With Correction&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;With Correction&lt;/p&gt;&#xA;&lt;p&gt;I liked the artistic result of this, I will keep it. I asked the question to understand better.&lt;/p&gt;&#xA;" OwnerUserId="15955" LastEditorUserId="482" LastEditDate="2021-04-19T16:54:55.763" LastActivityDate="2021-04-26T09:50:36.643" Title="Question about function for color" Tags="&lt;brdf&gt;&lt;color&gt;&lt;hlsl&gt;&lt;gamma&gt;" AnswerCount="4" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10764" PostTypeId="2" ParentId="10762" CreationDate="2021-03-22T07:08:15.693" Score="2" Body="&lt;p&gt;You can construct a rotation matrix from an &amp;quot;axis&amp;quot;, or 3 vectors. This is done by calculating 3 direction (normalized) vectors for the 3 axis of our new rotated coordinate system, they are forward, up and right vectors.&lt;/p&gt;&#xA;&lt;p&gt;In your case let's say we have 2 vectors called v1 and v2.&lt;/p&gt;&#xA;&lt;p&gt;we can produce a direction from them via (glsl psuedo code):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 forwardVector = normalize(v2 - v1);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then for our up vector we can pick the world-up axis (e.g. 0,1,0), although this may give you problems if the forward vector is very close to the up axis, in that case you can pick another arbitrary axis that's not nearby, like {0,0,1}. For the sake of simplicity we'll stick to the world up axis of {0,1,0}.&lt;/p&gt;&#xA;&lt;p&gt;The last vector can be derived automatically from the other 2 vectors using a cross product.&lt;/p&gt;&#xA;&lt;p&gt;so now we should have something like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;vec3 forwardVector = normalize(v2 - v1);&#xA;vec3 upVector = vec3(0,1,0);&#xA;vec3 rightVector = normalize(cross(forwardVector, upVector));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;These 3 vectors can be directly plugged into a 3x3 matrix to form the rotation matrix.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;r.x r.y r.z&#xA;u.x u.y u.z &#xA;f.x f.y f.z &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;where f=forwardVector, u=upVector and r=rightVector.&lt;/p&gt;&#xA;&lt;p&gt;This is similar to an openGL &amp;quot;LookAt&amp;quot; matrix.&lt;/p&gt;&#xA;&lt;p&gt;Be aware there are many rotation matrices that are valid solutions because 2 vectors cannot describe what the rotation is along the v1-&amp;gt;v2 axis (That's what the 'up' axis fixes in this case).&lt;/p&gt;&#xA;" OwnerUserId="3073" LastEditorUserId="3073" LastEditDate="2021-03-22T08:46:45.830" LastActivityDate="2021-03-22T08:46:45.830" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10765" PostTypeId="2" ParentId="10757" CreationDate="2021-03-22T10:43:32.767" Score="2" Body="&lt;p&gt;To understand the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component, it'll be easier to understand how &lt;em&gt;homogeneous coordinates&lt;/em&gt; come about in the first place. The following example will be in 2D for the sake of simplicity, but the same can be extended to 3D. Let's try to &amp;quot;invent&amp;quot; homogeneous coordinates for the first time.&lt;/p&gt;&#xA;&lt;p&gt;We start with the high school line equation, &lt;span class=&quot;math-container&quot;&gt;$ax + by + c = 0$&lt;/span&gt;. This line lies on a 2D plane (or more formally, in &lt;span class=&quot;math-container&quot;&gt;$\mathbb R^2$&lt;/span&gt;). We can quite easily see that a point &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; in &lt;span class=&quot;math-container&quot;&gt;$\mathbb R^2$&lt;/span&gt;, represented by &lt;span class=&quot;math-container&quot;&gt;$x = [x_1, x_2]$&lt;/span&gt;, lies on our line if the line equation still holds (i.e., &lt;span class=&quot;math-container&quot;&gt;$ax_1 + bx_2 + c = 0$&lt;/span&gt;). Notice that our &amp;quot;line&amp;quot; is really just defined by the values &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt;, so lets write that in row-vector form: &lt;span class=&quot;math-container&quot;&gt;$l =[a\ b\ c]$&lt;/span&gt;. Let us define this 3-component vector that represents our line in 2D as our &amp;quot;homogeneous representation&amp;quot; of a line in 2D space. This is the first building block of our &amp;quot;homogeneous coordinates&amp;quot; system.&lt;/p&gt;&#xA;&lt;p&gt;To test if a point lies on this line line, we're really just doing component-wise multiplication between &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, (&lt;span class=&quot;math-container&quot;&gt;$a \times x_1 + b \times x_2 + ... = 0$&lt;/span&gt;), so we can now re-write our line equation as a dot product of &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$l$&lt;/span&gt; &lt;em&gt;if&lt;/em&gt; we add a 1 as the 3rd component of our 2D points: &lt;span class=&quot;math-container&quot;&gt;$x' = [x_1, x_2, 1]$&lt;/span&gt;. Now:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ l.x' = [a\ b\ c] \left[&#xA;       \begin{array}{c}&#xA;       x_1\\&#xA;       x_2\\&#xA;       1&#xA;       \end{array}&#xA;\right] = ax_1 + bx_2 + c = 0 $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;That gets us back our original line equation exactly! Now we call our new 3-component point &lt;span class=&quot;math-container&quot;&gt;$x'$&lt;/span&gt; as the normalized homogeneous representation of a 2D point. That &amp;quot;1&amp;quot; in the third component is the so called &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component. You might also have noticed that lines and points are not distinguished here. This is true in homogeneous coordinates, lines and points are &lt;em&gt;duals&lt;/em&gt; of each other.&lt;/p&gt;&#xA;&lt;p&gt;We can also see that it doesn't matter what are the exact values of &lt;span class=&quot;math-container&quot;&gt;$a$&lt;/span&gt;, &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt; (or conversely, &lt;span class=&quot;math-container&quot;&gt;$x_1, x_2, w$&lt;/span&gt;), but rather it is the 2 independent &lt;em&gt;ratios&lt;/em&gt; (&lt;span class=&quot;math-container&quot;&gt;$a : b$&lt;/span&gt; and &lt;span class=&quot;math-container&quot;&gt;$b : c$&lt;/span&gt;) that really matters. In other words,&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$w(ax_1 + bx_2 + c) = 0$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;will hold for all values of &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; (except for &lt;span class=&quot;math-container&quot;&gt;$w = 0$&lt;/span&gt; for reasons to be explained later). This means that in our homogeneous coordinate system, the following all represents the same point:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$w \left[&#xA;       \begin{array}{c}&#xA;       x_1\\&#xA;       x_2\\&#xA;       1&#xA;       \end{array}&#xA;\right] \equiv \left[&#xA;       \begin{array}{c}&#xA;       x_1\\&#xA;       x_2\\&#xA;       1&#xA;       \end{array}&#xA;\right] \equiv \left[&#xA;       \begin{array}{c}&#xA;       wx_1\\&#xA;       wx_2\\&#xA;       w&#xA;       \end{array}&#xA;\right] $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;By now, we've defined a new homogeneous coordinate system with a point &lt;span class=&quot;math-container&quot;&gt;$x'$&lt;/span&gt; in this coordinate system. How do we get back &lt;span class=&quot;math-container&quot;&gt;$x$&lt;/span&gt;, the original 2D point? I hope it is simple to see that we just have to divide by &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; and drop the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component to get back the original point (this is in fact, &amp;quot;perspective division&amp;quot;!).&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$ x = \left[&#xA;       \begin{array}{c}&#xA;       x_1/w\\&#xA;       x_2/w\\&#xA;       \end{array}&#xA;\right] $$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Notice how we can't divide by &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; if &lt;span class=&quot;math-container&quot;&gt;$w = 0$&lt;/span&gt;? As a side note, this property is actually exploited in projective space, for us to represent points at infinity by having 0 in the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component. In computer graphics, we also exploit this to represent vectors. You cannot get back a 2D point from a vector in homogeneous coordinates, which makes sense.&lt;/p&gt;&#xA;&lt;p&gt;So to answer the original question of &amp;quot;what is the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component?&amp;quot;, it is just a scale factor for homogeneous coordinates. It may or may not be 1, but if it isn't 1, you have to normalize it by dividing the &lt;span class=&quot;math-container&quot;&gt;$w$&lt;/span&gt; component as described above.&lt;/p&gt;&#xA;" OwnerUserId="9420" LastEditorUserId="9420" LastEditDate="2021-03-22T10:54:17.460" LastActivityDate="2021-03-22T10:54:17.460" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10767" PostTypeId="2" ParentId="10763" CreationDate="2021-03-22T14:41:07.580" Score="1" Body="&lt;p&gt;Gamma correction originated as a way of correcting the output of a CRT to be a better fit for the human visual system. Modern monitors don't need to do it, but, they followed the CRT and there were millions of CRT's that all had gamma correction and most signals already had gamma correction in them. Today we have a chicken and egg problem...but reversed. Millions of clucking hardware chickens all speaking gamma...&lt;/p&gt;&#xA;&lt;p&gt;The flip side is that us humans don't think well in the land of exponential values, but we do think well in terms of linear values. So software for graphics code tends to remove the gamma then we can multiply add and manipulate in an intuitive manner, and convert it back to gamma for display.&lt;/p&gt;&#xA;&lt;p&gt;Modern hardware has specialty components that do this on the fly so the generally accepted practice is to set up the graphics hardware to handle this so we don't have to worry about it as programmers. But sometimes it can be useful.&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Updates based on comments (after rereading this I added a few more updates)&lt;/p&gt;&#xA;&lt;p&gt;Gamma correction has a second benefit for low precision formats like the common sRGB 8 bit format. (invented in the 90's to match hardware of the day) It redistributes the available values placing more values in the &amp;quot;dim&amp;quot; region where human's can better perceive changes in &lt;em&gt;brightness&lt;/em&gt;. This redistribution is why gamma correction is often called gamma &lt;em&gt;compression&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This is not a correction for human vision, it is a correction for the limitations of the 8 bit format. Higher precision formats do not need to store gamma correction and (generally) have gamma applied to them only when converting to a lower precision format.&lt;/p&gt;&#xA;&lt;p&gt;Here is a breakdown of common formats with respect to gamma:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;8 bit formats like sRGB - Gamma is an essential component of this format&lt;/li&gt;&#xA;&lt;li&gt;10 bit formats like HRD10 - Usable without gamma, but adding gamma improves this format considerably.&lt;/li&gt;&#xA;&lt;li&gt;12 bit formats like Dolby Vision - Gamma is starting to be redundant from 12 bits and up. There is enough separation between linear color brightness that it is increasingly difficult for to see the color separation, but most people can still detect some banding in the dark colors.&lt;/li&gt;&#xA;&lt;li&gt;14 bits formats like RAW formats from professional cameras. Professional quality monitors that use 3D look up tables to do color matching begin to give truly magnificent images. At this point most specs include phrases like &amp;quot;A gamma of 2.2 is applied since it is expected that images will be viewed on gamma corrected devices&amp;quot;. An 8 bit image next to a 14 bit can be perspective changing for viewers.&lt;/li&gt;&#xA;&lt;li&gt;16 bit I don't have a hardware example, but some software allow images to be edited in 16bit formats.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;The very amazing human eye can perceive 1,000,000 nits of difference in brightness by dynamically adapting itself to the available lighting. But is especially adapted to see more changes in &lt;em&gt;brightness&lt;/em&gt; in dark situations. The CRT when it was invented struggled to display 100 nits of brightness. Leaving 999,900 nits on the table. So gamma was applied to the signal to take advantage of our ability to see better in low lighting. This was a limitation of the CRT not our vision.&lt;/p&gt;&#xA;&lt;p&gt;It is common for modern monitors to reach 300-500 nits, with some models getting up to 1000 nits or more. That extra available brightness means that gamma is not really needed for anything but historical compatibility. (this is a bit of an overstatement, monitors really need to get into the 10,000 nit range before gamma starts becoming redundant)&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;When working with image data it is best to configure the hardware to handle gamma correction for us and use methods such as tone mapping to achieve a specialized appearance. This allows the hardware to load images that are stored as a variety of color formats such as sRGB and HDR into a common space that is well defined, where code can then perform its calculations and send that result to the hardware where it is converted to a format that is specific to the device being used to display it. (which is often a gamma corrected format)&lt;/p&gt;&#xA;&lt;p&gt;I am not tying to say that this image is &amp;quot;wrong&amp;quot;, everyone should take the time to create images like this to better understand gamma correction.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-04-20T17:07:19.870" LastActivityDate="2021-04-20T17:07:19.870" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10768" PostTypeId="1" CreationDate="2021-03-22T15:35:08.127" Score="0" ViewCount="15" Body="&lt;p&gt;I am new here&lt;/p&gt;&#xA;&lt;p&gt;I am not good in math&lt;/p&gt;&#xA;&lt;p&gt;SO what I need is I need to translate the 3D camera with Pan gesture on 2d Screen&lt;/p&gt;&#xA;&lt;p&gt;With below code it is working&lt;/p&gt;&#xA;&lt;p&gt;But if camera has some Euler Angle (rotated ) then I am able to move model in X Direction only ,May be because xy plane is changed to xz (not sure)&lt;/p&gt;&#xA;&lt;p&gt;Question : How to take rotation of camera in this calculation so it is working for all case&lt;/p&gt;&#xA;&lt;p&gt;Thanks in advance&lt;/p&gt;&#xA;&lt;p&gt;Please suggest solution&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;var previousLocation = SCNVector3(x: 0, y: 0, z: 0)&#xA;@objc func panned(gesture:UIPanGestureRecognizer) {&#xA;&#xA;&#xA;let view = self.sceneView1!&#xA;let translation = gesture.translation(in: view)&#xA;&#xA;let location = gesture.location(in: view)&#xA;let secLocation = CGPoint(x: location.x + translation.x, y: location.y + translation.y)&#xA;&#xA;let P1 = view.unprojectPoint(SCNVector3(x: Float(location.x), y: Float(location.y), z: 0.0))&#xA;let P2 = view.unprojectPoint(SCNVector3(x: Float(location.x), y: Float(location.y), z: 1.0))&#xA;&#xA;   let Q1 = view.unprojectPoint(SCNVector3(x: Float(secLocation.x), y: Float(secLocation.y), z: 0.0))&#xA;   let Q2 = view.unprojectPoint(SCNVector3(x: Float(secLocation.x), y: Float(secLocation.y), z: 1.0))&#xA;&#xA;   let t1 = -P1.z / (P2.z - P1.z)&#xA;   let t2 = -Q1.z / (Q2.z - Q1.z)&#xA;&#xA;   let x1 = P1.x + t1 * (P2.x - P1.x)&#xA;   let y1 = P1.y + t1 * (P2.y - P1.y)&#xA;&#xA;   let P0 = SCNVector3Make(x1, y1,0)&#xA;&#xA;   let x2 = Q1.x + t1 * (Q2.x - Q1.x)&#xA;   let y2 = Q1.y + t1 * (Q2.y - Q1.y)&#xA;&#xA;   let Q0 = SCNVector3Make(x2, y2, 0)&#xA;&#xA;   var diffR = Q0 - P0&#xA;&#xA;diffR = SCNVector3Make(diffR.x * -1, diffR.y * -1, diffR.z * -1)&#xA;  //    diffR *= -1&#xA;&#xA;let cameraNode = view.pointOfView&#xA;&#xA;   switch gesture.state {&#xA;   case .began:&#xA;       previousLocation = cameraNode!.position&#xA;       break;&#xA;   case .changed:&#xA;    cameraNode?.position = SCNVector3Make(previousLocation.x + diffR.x, previousLocation.y + diffR.y, previousLocation.z + diffR.z)&#xA;       break;&#xA;   default:&#xA;       break;&#xA;   }&#xA;&#xA;  }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Q5tGS.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Q5tGS.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="15966" LastActivityDate="2021-03-22T15:35:08.127" Title="Translate the camera with Pan gesture (when it is rotated )" Tags="&lt;3d&gt;&lt;transformations&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10769" PostTypeId="2" ParentId="10754" CreationDate="2021-03-22T19:00:12.677" Score="0" Body="&lt;p&gt;The cube-like mesh shown in the images is a non-manifold mesh. Officially half edge data structures do not support such a topology. However, this case can be supported by continuing the boundary half edges through the non-manifold node. This is apparently the way it is done in 3DS Max, and also Blender. You can look at &lt;a href=&quot;https://kaba.hilvi.org/homepage/blog/halfedge/halfedge.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; article for several extension to the data structure to support non-manifold meshes.&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2021-03-22T19:00:12.677" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10771" PostTypeId="1" CreationDate="2021-03-23T19:21:18.920" Score="0" ViewCount="31" Body="&lt;p&gt;I have successfully completed a working program that draw a rotating sphere with a map of the world as the texture, simulating the earth in space.  However, the texture is bound on it's side, i.e. all the continents are on their sides and the poles are shown as the sphere spins on the y-axis.  I used the following reference to build the rotating sphere:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.songho.ca/opengl/gl_sphere.html#:%7E:text=In%20order%20to%20draw%20the,triangle%20strip%20cannot%20be%20used&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.songho.ca/opengl/gl_sphere.html#:~:text=In%20order%20to%20draw%20the,triangle%20strip%20cannot%20be%20used&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;and the stb_image library (&lt;a href=&quot;https://github.com/nothings/stb&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/nothings/stb&lt;/a&gt;) to load a JPEG image for the texture.&lt;/p&gt;&#xA;&lt;p&gt;I've tried a couple of things like:&#xA;actual rotation of the JPEG image,&#xA;rotating the array that holds the texture coordinates,&#xA;rotating the array that holds the indices&lt;/p&gt;&#xA;&lt;p&gt;Everything is good apart from the orientation of the image bound for texturing.  Any advice/pointers would be appreciated.&lt;/p&gt;&#xA;" OwnerUserId="15976" LastActivityDate="2021-03-23T22:39:33.557" Title="How can I bind my texture in the correct orientation?" Tags="&lt;opengl&gt;&lt;texture&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10772" PostTypeId="2" ParentId="10771" CreationDate="2021-03-23T22:39:33.557" Score="1" Body="&lt;p&gt;Binding the image is unrelated to its orientation. A shot in the dark is that your texture coordinates are either reversed or computed with the orientation in the wrong direction. You could just rotate the image as a work around. The main issue here is whether the upper left corner is your origin, or the lower left corner is the origin. But neither of these explain the image being sideways. At any rate, look at your texture coordinates, how the image is being copied into memory, how is is being passed to opengl, and the texture coordinates.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-03-23T22:39:33.557" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10773" PostTypeId="1" CreationDate="2021-03-24T00:43:15.287" Score="0" ViewCount="26" Body="&lt;p&gt;I am interested in clicking on different faces of an object mesh (loaded as in obj format) in MeshLab (or other obj file visualization tools) and understand what is the face number? For example if my given object mesh has 1000 faces, I would like to know which of the 1000 faces the face I am currently clicking on is.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/F1Ykl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/F1Ykl.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This mesh has 497 vertices and 1000 faces.&lt;/p&gt;&#xA;&lt;p&gt;This is all I see in MeshLab:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/3wLAu.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/3wLAu.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6281" LastActivityDate="2021-03-24T00:43:15.287" Title="Finding the &quot;face number&quot; of a mesh in obj format in MeshLab or other visualization tools by clicking on it" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10774" PostTypeId="1" CreationDate="2021-03-24T02:44:42.290" Score="0" ViewCount="38" Body="&lt;p&gt;I'd like to know if the following technology already exists, and if not, how feasible it would be to create something like this:&lt;/p&gt;&#xA;&lt;p&gt;I came up with an idea for creating a higher-res image that is put together from multiple lower-res images.  More specifically, from a video (animated, multiple frames) source.  The best way to explain it would be to explain what would happen using an example:&lt;/p&gt;&#xA;&lt;p&gt;Let's say that there's video footage from a security camera of a van driving by.  The van has a logo on it.  Based on the entire video (using all applicable frames to gather data), object recognition code is used to recognize that an object has moved in the video.  Using the raster data in the frames along with the object recognition, a vector is generated that represents the moving object.  Interpolation can be used to show where this object is during all timeslices, including those between frames.  So for example, if played in slow motion, you would see (just for example's sake) a vector rectangle moving along with the van's logo (let's say the logo is rectangular just to make the example simpler to conceptualize).  As the frames play by one at a time, the rectangle smoothly follows the logo, always matching the location of the logo in each frame, but smoothly moving between those locations between the rendering of each frame, yet always matching the location of the logo when each frame actually shows up (let's say we play it at 1fps, to better imagine what's happening).  This interpolation would allow for the tracking of the object based on limited data (frame rates can't be infinite, so picking any timestamp between the frames would allow interpolation to determine where that logo would be between the frames, based on the motion that the frames depict).&lt;/p&gt;&#xA;&lt;p&gt;Having explained the situation above, now let's apply the general idea of the interpolation but in a different way..&lt;/p&gt;&#xA;&lt;p&gt;The rectangular vector is split up into a grid.  This grid can represent a raster image.  However, its resolution would be higher than that of the video's resolution - the higher-res more-detailed version of the logo that we're trying to capture.  So now, let's build the high-res logo...&lt;/p&gt;&#xA;&lt;p&gt;Finding the first frame of the video in which the logo is visible, each pixel of the higher-res logo is filled in based on the pixels of the logo in the video's frame.  When processing the first frame, the resulting higher-res logo looks the same as the logo in the frame.  The only difference is that it looks like a blown-up pixelized version of the logo in the frame.  So far, no 'enhancement' is done.&lt;/p&gt;&#xA;&lt;p&gt;However, as we go further frame-by-frame, we now have some extra data to work with.  Even though the video has limited resolution, with each pixel representing a blend of all the colors within its bounds, the fact that its motion is being tracked allows each subsequent frame's representation of the logo to slightly add some more detail to the higher-res logo.  Since the location of the logo as it's moving across the video is interpolated, the higher-res pixel grid can be placed between pixels (using floating-point coordinates), as it's able to determine a more exact placement of where the logo is, beyond the resolution of the video.&lt;/p&gt;&#xA;&lt;p&gt;With each subsequent frame, the visible pixels of the logo gradually add more and more detail to the higher-res logo, eventually making it look less and less pixelized.  With enough video footage of the moving logo, it could be possible to eventually generate a much more detailed version of the logo than any one of the frames can individually provide.&lt;/p&gt;&#xA;&lt;p&gt;I hope that my explanation of this tech was sufficient to provide an idea of what I'm trying to describe.  You may have to extrapolate and interpolate this imaginary concept in your mind and intuitively fill in some details (similar to what this tech attempts to do), to fully conceptualize how this tech would work.&lt;/p&gt;&#xA;&lt;p&gt;Having explained it, I'd like to know if something like this exists.  If it does, what is this kind of technology called?  And if it doesn't, how difficult would it be to create something like it?  I imagine that utilizing machine learning would make it even more effective in filling in details.&lt;/p&gt;&#xA;&lt;p&gt;If you've read this far, thank you for your time.  I'd like to know what you think.&lt;/p&gt;&#xA;" OwnerUserId="15978" LastActivityDate="2021-03-24T02:44:42.290" Title="Building a higher-res detailed image from a video" Tags="&lt;image-processing&gt;&lt;video&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10776" PostTypeId="1" AcceptedAnswerId="10777" CreationDate="2021-03-25T14:36:40.860" Score="1" ViewCount="76" Body="&lt;p&gt;I am an amateur game developer, and I've been reading a lot on how computer graphics rendering works lately. I was reading on the Z-buffer recently and I can't quite seem to be able to wrap my head around what exactly the Z-buffer looks like in terms of memory. It's described to contain depth information for each fragment that will be drawn on-screen, and that modern Z-buffers have 32-bits, so would that mean that on a, let's say, 1920x1080 screen it'd be just above 8MB (1920 * 1080 * 32) per frame?&lt;/p&gt;&#xA;&lt;p&gt;I still don't quite understand what this value would be to a GPU (maybe it can crunch it easily), or if this value is even correct. Most demostrative implementations I found implement the Z-buffer as a simple array with size (height * width), so I'm basing myself off of that.&lt;/p&gt;&#xA;" OwnerUserId="15999" LastEditorUserId="209" LastEditDate="2021-03-29T10:34:48.240" LastActivityDate="2021-03-29T11:00:01.550" Title="What does the z-buffer look like in memory?" Tags="&lt;performance&gt;&lt;memory&gt;&lt;buffers&gt;&lt;z-buffer&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10777" PostTypeId="2" ParentId="10776" CreationDate="2021-03-25T17:38:40.677" Score="1" Body="&lt;p&gt;The Z buffer used to be specialized memory set aside for a single purpose, some web sites still explain it like that, but no longer.&lt;/p&gt;&#xA;&lt;p&gt;Now the Z buffer is just a chunk of memory you allocate, or an API like OpenGL allocates on your behalf.&lt;/p&gt;&#xA;&lt;p&gt;The size of that chunk of memory will depend on the type of the Z buffer values, in the example you gave it is a 32bit [floating point] values, but 24 bits is also very common. Always choose the smallest size the program needs as it can have a large effect on the performance of the application. It is indeed multiplied by the size of framebuffer so 8mb is correct for the example you gave.&lt;/p&gt;&#xA;&lt;p&gt;The values that get stored in it are the depth values for any geometry drawn to the associated framebuffer. It is important to realize that these values are NOT the linear values of the MVP matrix computed in the vertex shader so the Z buffer can not be used for things like shadow maps.&lt;/p&gt;&#xA;&lt;p&gt;Fragments resulting from each draw call have their depth values tested against existing values in the Z buffer and if the test passes the GPU will write that fragment and update the Z buffer with the new value, if not the fragment gets discarded and the Z buffer is left untouched.&lt;/p&gt;&#xA;&lt;p&gt;A few other little details:&lt;/p&gt;&#xA;&lt;p&gt;The Z buffer is generally cleared at the beginning of each frame with a clear value that can be set (or must be set) via the API. This becomes the default value that writes to the Z buffer are tested against.&lt;/p&gt;&#xA;&lt;p&gt;GPU's have specialized hardware for writing the Z buffer, this hardware can speed up writing to memory by a factor of 2 or more and can be leveraged when creating things like shadow maps, so it is not limited for use with just the Z buffer.&lt;/p&gt;&#xA;&lt;p&gt;Depth testing can be turned off/on for each draw call, which can be useful.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-03-25T17:38:40.677" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10778" PostTypeId="1" AcceptedAnswerId="10782" CreationDate="2021-03-25T19:35:39.463" Score="1" ViewCount="45" Body="&lt;p&gt;I hope this is the right forum to ask this question.&lt;/p&gt;&#xA;&lt;p&gt;I want to experiment with procedurally generating some buildings, and as a first step I want to generate a 2D shape to use as a foundation for the building.&lt;/p&gt;&#xA;&lt;p&gt;My plan would be to create a union of an arbitrary (but probably quite small) amount of shapes.&#xA;It seems simple enough, but I wonder what algorithms there are available for breaking up such a union into simple line shapes? (that can be used to place walls)&lt;/p&gt;&#xA;" OwnerUserId="16001" LastActivityDate="2021-03-29T14:47:10.593" Title="getting the outline of an arbitrary set of shape unions" Tags="&lt;algorithm&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10780" PostTypeId="1" AcceptedAnswerId="10792" CreationDate="2021-03-26T18:24:17.893" Score="1" ViewCount="59" Body="&lt;p&gt;My problem is exactly what titles and screenshot below says - rendered object depth value is 0.0 in depth buffer. I'm using DirectX 12.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/jTTnm.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/jTTnm.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Matrices:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Gcfrh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Gcfrh.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// VS code&#xA;PixelInputType main(VertexInputType input)&#xA;{&#xA;    PixelInputType output;&#xA;    &#xA;    float4 position = float4(input.position, 1.0f);&#xA;    position = mul(position, g_worldMatrix);&#xA;    position = mul(position, g_viewMatrix);&#xA;    position = mul(position, g_projMatrix);&#xA;    output.position = position;&#xA;&#xA;    return output;&#xA;}&#xA;// PS code&#xA;float4 main(PixelInputType input) : SV_TARGET&#xA;{&#xA;    return float4(g_texture.Sample(g_sampler, input.uv).rgb, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I am rendering single object for now, so world matrix is just identity matrix.&#xA;Regarding view/proj matrix - they're updated each frame and saved to the CB:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void Renderer::CreateViewAndPerspective()&#xA;{&#xA;    const DirectX::XMVECTOR up = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.f);&#xA;    constexpr float conv{ 0.0174532925f };&#xA;&#xA;    // Create the rotation matrix from the yaw, pitch, and roll values.&#xA;    const XMMATRIX rotationMatrix = XMMatrixRotationRollPitchYaw(m_cameraRotation.x * conv, m_cameraRotation.y * conv, m_cameraRotation.z * conv);&#xA;&#xA;    const DirectX::XMVECTOR eye = DirectX::XMVectorSet(m_cameraPosition.x, m_cameraPosition.y, m_cameraPosition.z, 0.0f);&#xA;&#xA;    //Setup target (look at object position)&#xA;    XMVECTOR target = XMVector3TransformCoord(DirectX::XMVECTOR{ 0, 0, 1, 0 }, rotationMatrix);&#xA;    target = XMVector3Normalize(target);&#xA;    target = { m_cameraPosition.x + target.m128_f32[0], m_cameraPosition.y + target.m128_f32[1], m_cameraPosition.z + target.m128_f32[2], 0.0f };  &#xA;&#xA;    //Create view matrix&#xA;    m_constantBuffer.value.view = DirectX::XMMatrixTranspose(DirectX::XMMatrixLookAtLH(eye, target, up));&#xA;&#xA;    //Create perspective matrix&#xA;    constexpr float FOV = 3.14f / 4.0f;&#xA;    float aspectRatio = m_windowSize.x / m_windowSize.y /* 1280 x 720 */;&#xA;    m_constantBuffer.value.projection = DirectX::XMMatrixTranspose(DirectX::XMMatrixPerspectiveFovLH(FOV, aspectRatio, Z_NEAR /* 0.5f */, Z_FAR /* 100.0f */));&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Edit: Depth buffer implementation details below (full code - &lt;a href=&quot;https://github.com/komilll/YARE/blob/main/YARE/Renderer.cpp#L131&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/komilll/YARE/blob/main/YARE/Renderer.cpp#L131&lt;/a&gt; ):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Create DSV&#xA;D3D12_DESCRIPTOR_HEAP_DESC desc{};&#xA;desc.NumDescriptors = 1;&#xA;desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;&#xA;desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;&#xA;device-&amp;gt;CreateDescriptorHeap(&amp;amp;desc, IID_PPV_ARGS(&amp;amp;heap));&#xA;&#xA;// Create Depth Stencil&#xA;D3D12_DEPTH_STENCIL_VIEW_DESC depthStencilDesc = {};&#xA;depthStencilDesc.Format = DXGI_FORMAT_D32_FLOAT;&#xA;depthStencilDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;&#xA;depthStencilDesc.Flags = D3D12_DSV_FLAG_NONE;&#xA;&#xA;D3D12_CLEAR_VALUE depthOptimizedClearValue = {};&#xA;depthOptimizedClearValue.Format = DXGI_FORMAT_D32_FLOAT;&#xA;depthOptimizedClearValue.DepthStencil.Depth = 1.0f;&#xA;depthOptimizedClearValue.DepthStencil.Stencil = 0;&#xA;&#xA;ThrowIfFailed(device-&amp;gt;CreateCommittedResource(&#xA;    &amp;amp;CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),&#xA;    D3D12_HEAP_FLAG_NONE,&#xA;    &amp;amp;CD3DX12_RESOURCE_DESC::Tex2D(format, width, height, 1, 0, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL),&#xA;    D3D12_RESOURCE_STATE_DEPTH_WRITE,&#xA;    &amp;amp;depthOptimizedClearValue,&#xA;    IID_PPV_ARGS(&amp;amp;depthStencil)&#xA;));&#xA;&#xA;device-&amp;gt;CreateDepthStencilView(depthStencil.Get(), &amp;amp;depthStencilDesc, dsvHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart());&#xA;&#xA;/* ... */&#xA;// Usage of DSV&#xA;const float clearColor[] = { 0.0f, 0.2f, 0.4f, 1.0f };&#xA;m_commandList-&amp;gt;ClearRenderTargetView(rtvHandle, clearColor, 0, nullptr);&#xA;m_commandList-&amp;gt;ClearDepthStencilView(m_dsvHeap-&amp;gt;GetCPUDescriptorHandleForHeapStart(), D3D12_CLEAR_FLAG_DEPTH, 1.0f, 0, 0, nullptr);&#xA;m_commandList-&amp;gt;IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);&#xA;m_commandList-&amp;gt;IASetVertexBuffers(0, 1, &amp;amp;m_modelSphere-&amp;gt;GetVertexBufferView());&#xA;m_commandList-&amp;gt;DrawInstanced(m_modelSphere-&amp;gt;GetIndicesCount(), 1, 0, 0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2021-03-27T09:44:28.127" LastActivityDate="2021-03-31T19:25:32.110" Title="Objects in depth buffer are always black (0.0)" Tags="&lt;directx12&gt;&lt;camera-matrix&gt;&lt;z-buffer&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10782" PostTypeId="2" ParentId="10778" CreationDate="2021-03-27T19:28:31.723" Score="1" Body="&lt;p&gt;Draw it twice, first time at full size and the color you want for the outline, draw it filled. The second time you draw it scaled down in both the x and y directions. The second time you draw it the color is the same as the background color, and draw it filled again. What will be left is the outline. Is this what you had in mind?&lt;/p&gt;&#xA;&lt;p&gt;Per your comment, I add more info:&lt;/p&gt;&#xA;&lt;p&gt;Generating an array of exterior edges can be done in a few ways. The easiest one to implement (but also the slowest) is to count the number polygons that share a given edge. The exterior is all the edges which only have a single polygon using that edge. And the two vertices that make up that edge become part of the array of &amp;quot;lines&amp;quot;( an actual line can be computed from two vertices). Also, this will count &amp;quot;holes&amp;quot; as part of the exterior. For example if a building surrounds a courtyard, then the courtyard would be counted as exterior.&lt;/p&gt;&#xA;&lt;p&gt;This can be implemented by creating an array of unique vertices, then each polygon is formed by indexing into the list. (just like indexed triangle draw lists). Finally pick a single polygon off the list, takes its first edge, and search all the other polygons for that edge.&lt;/p&gt;&#xA;&lt;p&gt;Another method using a doubly connected edge list is given &lt;a href=&quot;https://stackoverflow.com/questions/26103138/find-the-outline-of-adjacent-polygons&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-03-29T14:47:10.593" LastActivityDate="2021-03-29T14:47:10.593" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10783" PostTypeId="2" ParentId="10776" CreationDate="2021-03-29T11:00:01.550" Score="0" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;Most demostrative[SIC] implementations I found implement the Z-buffer as a simple array with size (height * width), so I'm basing myself off of that.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I suspect a purely linear (i.e., scanline-by-scanline) arrangement for the Z-buffer, at least for HW systems, is unlikely as that would tend to lead to a &lt;em&gt;lot&lt;/em&gt; of DRAM &amp;quot;&lt;a href=&quot;https://www.anandtech.com/show/3851/everything-you-always-wanted-to-know-about-sdram-memory-but-were-afraid-to-ask/5&quot; rel=&quot;nofollow noreferrer&quot;&gt;page-break&lt;/a&gt;s&amp;quot;. This is because each triangle tends to get rendered in its entirety, which means that as you go from one scanline of pixels to the next, the memory addresses are likely to jump dramatically.&lt;/p&gt;&#xA;&lt;p&gt;Tiled/Morton(Twiddled) layouts for the Z-buffer are probably more likely (along with a more tile-based rendering order.)&lt;/p&gt;&#xA;" OwnerUserId="209" LastActivityDate="2021-03-29T11:00:01.550" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10784" PostTypeId="1" CreationDate="2021-03-29T15:38:56.660" Score="0" ViewCount="56" Body="&lt;p&gt;I wrote a program to render a simple triangle with colors, the triangle is there but there's no color.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat vertices[] = {&#xA;        0.6f,0.4f , 0.3f,0.5f, 0.1f,0.3f, 0.8f,0.2f, 0.1f,-0.4f, 0.9f,0.3f&#xA;    };&#xA;&#xA;&#xA;    unsigned int program;&#xA;    if (!loadShader(program))&#xA;        return -1;&#xA;&#xA;    unsigned int VAO;&#xA;    glGenVertexArrays(1, &amp;amp;VAO);&#xA;    &#xA;    unsigned int buffer;&#xA;    /* GENERATE THE BUFFER (1 BUUFER) */&#xA;    glGenBuffers(1, &amp;amp;buffer);&#xA;    glBindVertexArray(VAO);&#xA;    /* SELECT THAT BUFFER TO WORK WITH */&#xA;    glBindBuffer(GL_ARRAY_BUFFER, buffer);&#xA;&#xA;    //glBufferData(GL_ARRAY_BUFFER, RealPositions.size()*sizeof(float), RealPositions.data(), GL_STATIC_DRAW);&#xA;    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&#xA;    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);&#xA;    glEnableVertexAttribArray(0);&#xA;    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));&#xA;    glEnableVertexAttribArray(1);&#xA;&#xA;   &#xA;&#xA;    glBindVertexArray(0);&#xA;    /* Loop until the user closes the window */&#xA;    while (!glfwWindowShouldClose(window))&#xA;    {&#xA;        /* Render here */&#xA;        glClear(GL_COLOR_BUFFER_BIT);&#xA;&#xA;        &#xA;        glUseProgram(program);&#xA;&#xA;    &#xA;        glBindVertexArray(VAO);&#xA;        glDrawArrays(GL_TRIANGLES, 0, 3);&#xA;&#xA;        /* Swap front and back buffers */&#xA;        glfwSwapBuffers(window);&#xA;&#xA;        /* Poll for and process events */&#xA;        glfwPollEvents();&#xA;}&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and this the vertex shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 440&#xA;&#xA;&#xA;layout (location = 0) in vec3 vertices;&#xA;layout (location = 1) in vec3 vertex_color;&#xA;out vec3 vs_color;&#xA;void main()&#xA;{&#xA;    gl_Position=vec4(vertices, 1.f);&#xA;    vs_color=vertex_color;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and this is the fragment shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core  &#xA;&#xA;&#xA;in vec4 vs_pos;&#xA;in vec3 vs_color;&#xA;out vec4 fs_color;&#xA;&#xA;&#xA;void main()&#xA;{&#xA;    fs_color=vec4(vs_color, 1.f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;what am i doing wrong?&lt;/p&gt;&#xA;" OwnerUserId="16024" LastEditorUserId="16024" LastEditDate="2021-03-30T09:09:34.177" LastActivityDate="2021-04-29T16:01:41.143" Title="rendering a triangle has no color" Tags="&lt;opengl&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10785" PostTypeId="2" ParentId="9724" CreationDate="2021-03-29T17:56:03.480" Score="1" Body="&lt;p&gt;According to the source (&lt;a href=&quot;https://github.com/assimp/assimp/blob/b7df376836e36c4b6998ce95d97626e30f61c2f0/code/AssetLib/Obj/ObjFileImporter.cpp#L594&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/assimp/assimp/blob/b7df376836e36c4b6998ce95d97626e30f61c2f0/code/AssetLib/Obj/ObjFileImporter.cpp#L594&lt;/a&gt;) only illum values of 0, 1, 2 are supported:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    // convert illumination model&#xA;    int sm = 0;&#xA;    switch (pCurrentMaterial-&amp;gt;illumination_model) {&#xA;    case 0:&#xA;        sm = aiShadingMode_NoShading;&#xA;        break;&#xA;    case 1:&#xA;        sm = aiShadingMode_Gouraud;&#xA;        break;&#xA;    case 2:&#xA;        sm = aiShadingMode_Phong;&#xA;        break;&#xA;    default:&#xA;        sm = aiShadingMode_Gouraud;&#xA;        ASSIMP_LOG_ERROR(&amp;quot;OBJ: unexpected illumination model (0-2 recognized)&amp;quot;);&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10703" LastActivityDate="2021-03-29T17:56:03.480" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10786" PostTypeId="1" CreationDate="2021-03-30T00:52:26.677" Score="1" ViewCount="22" Body="&lt;p&gt;I am trying to transfer some mocap data from one skeleton to another one. However, the skeletons have different rest poses (one has T-pose, and the other some other one), so I am trying to convert the euler angles from being relative to one rest pose to another. I have the relative transform between the second skeleton and a T-pose in Unity. The issue is that Unity uses a different angle convention to Blender/BVH, and I really cannot figure it out.&lt;/p&gt;&#xA;&lt;p&gt;Trying to debug this, I've isolated one point of confusion, which is what I'm mainly asking about here. You can see &lt;a href=&quot;https://streamable.com/80nyoj&quot; rel=&quot;nofollow noreferrer&quot;&gt;in this video&lt;/a&gt; that for all joints up to the spine3, changing the X Euler angle, rotates arond X, but after the collar joints, changing the X Euler angle, it rotates around some other axis (even though all of its parents have near 0 rotation). I don't understand why this would be. Anyone could explain this?&#xA;Thanks!&lt;/p&gt;&#xA;" OwnerUserId="16028" LastActivityDate="2021-03-30T00:52:26.677" Title="Understanding rig joint angle definitions in Blender" Tags="&lt;animation&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10787" PostTypeId="2" ParentId="10784" CreationDate="2021-03-30T13:32:41.910" Score="0" Body="&lt;p&gt;Your inputs and outputs still don't line up.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#version 440 core  &#xA;&#xA;// Comment out the line below&#xA;// in vec4 vs_pos;    &amp;lt;----- No corresponding output in the vertex shader&#xA;in vec3 vs_color; &#xA;&#xA;out vec4 fs_color;&#xA;&#xA;&#xA;void main()&#xA;{&#xA;    fs_color=vec4(vs_color, 1.f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The gl_Position output is consumed and does not need a specific input in the fragment shader. Only variable declared as &amp;quot;out&amp;quot; in the vertex shader need a corresponding &amp;quot;in&amp;quot;.&lt;/p&gt;&#xA;&lt;p&gt;The next issue is the vertices need to have colors in them. The way it is setup now all the components are consumed before even a single triangle is drawn.&lt;/p&gt;&#xA;&lt;p&gt;The vertex buffer needs to be setup:&#xA;vertex,color, vertex,color, vertex,color&lt;/p&gt;&#xA;&lt;p&gt;where each vertex and color has 3 floating point values.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;GLfloat vertices[] = {&#xA;&#xA;//    vertex           color&#xA;-0.5f, -0.5f, 0.0f,  1.0f,0.0f,0.0f&#xA; 0.5f, -0.5f, 0.0f,  0.0f,1.0f,0.0f&#xA; 0.0f,  0.5f, 0.0f,  0.0f,0.0f,1.0f &#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Something like the above. Is what you need for the vertices.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-03-30T15:49:05.843" LastActivityDate="2021-03-30T15:49:05.843" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10789" PostTypeId="1" CreationDate="2021-03-30T23:00:06.150" Score="0" ViewCount="46" Body="&lt;p&gt;&lt;a href=&quot;https://superrare.co/artwork-v2/spring-22267&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://superrare.co/artwork-v2/spring-22267&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The artwork in the link seems to be based on a painting of a woman, but effects have been added that assign a pixel to each block of the painting that shift in color and contrast across a certain number of frames as part of a gif animation, although the original painting itself doesn't move underneath.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;is there a name for this effect?&lt;/li&gt;&#xA;&lt;li&gt;and could someone breifly outline the steps of how it can be achieved&#xA;in software?&lt;/li&gt;&#xA;&lt;li&gt;any popular examples where this effect is used or first introduced?&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;" OwnerUserId="15860" LastActivityDate="2021-04-01T08:18:22.163" Title="What is the name of this moving color pixels effect, for animating a painting?" Tags="&lt;color&gt;&lt;animation&gt;&lt;pixels&gt;&lt;colorspace&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10790" PostTypeId="2" ParentId="10789" CreationDate="2021-03-30T23:57:37.173" Score="0" Body="&lt;p&gt;It looks like it’s based on a &lt;a href=&quot;https://en.wikipedia.org/wiki/Halftone&quot; rel=&quot;nofollow noreferrer&quot;&gt;halftone&lt;/a&gt; technique, with the grid warped using a few sine waves. Not sure about how the colors are being assigned, but there’s some kind of &lt;a href=&quot;https://en.wikipedia.org/wiki/Color_quantization&quot; rel=&quot;nofollow noreferrer&quot;&gt;quantization&lt;/a&gt; going on.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-03-30T23:57:37.173" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10791" PostTypeId="1" AcceptedAnswerId="10805" CreationDate="2021-03-31T05:29:02.207" Score="2" ViewCount="83" Body="&lt;p&gt;&lt;a href=&quot;https://learnopengl.com/PBR/IBL/Specular-IBL&quot; rel=&quot;nofollow noreferrer&quot;&gt;This&lt;/a&gt; is the website I am learning from.&lt;/p&gt;&#xA;&lt;p&gt;In the specular part of IBL this is the split sum approximation&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YhB0C.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YhB0C.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Now the left part of the equation I have asked in  &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10659/pbr-understanding-importance-sampling/10663#10663&quot;&gt;This&lt;/a&gt; post and I have understood everything now this question is about the right part.&lt;/p&gt;&#xA;&lt;p&gt;On simplifying the right part of the equation with the procedure shown in the website we get this&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WiOBt.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WiOBt.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;And on translating this to code we get this&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zb0ZG.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zb0ZG.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I have so many questions about this code.&lt;/p&gt;&#xA;&lt;p&gt;1)What is the V vector? How did they compute that&lt;/p&gt;&#xA;&lt;p&gt;2)Why have they assumed N=(0,0,1)?&lt;/p&gt;&#xA;&lt;p&gt;3)why is NDotL=max(L.z,0)? How did they simplifying a dot product to an min/max Operation same question I have for NDotH&lt;/p&gt;&#xA;&lt;p&gt;4)G_Vis=G&lt;em&gt;VDoth/(NDotH&lt;/em&gt;NDotL) why the division by (NDOTH*NDOTL)? that was nowhere in the equation.&lt;/p&gt;&#xA;&lt;p&gt;5)what is vector L? it looks like they have reflected vector V about H to get this but why?&lt;/p&gt;&#xA;&lt;p&gt;These are just some of the questions I have come up with so far but if there are any other important parts I should not know about A general explanation on how they derived this code would be appreciated&lt;/p&gt;&#xA;" OwnerUserId="15434" LastActivityDate="2021-04-05T11:01:01.613" Title="PBR : Understanding the right part of Split sum integration of specular IBL" Tags="&lt;pbr&gt;&lt;specular&gt;&lt;integral&gt;&lt;ibl&gt;" AnswerCount="2" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10792" PostTypeId="2" ParentId="10780" CreationDate="2021-03-31T19:25:32.110" Score="2" Body="&lt;p&gt;That's how I used to initialize viewport (CD3DX12_VIEWPORT). But I didn't realize that there are two additional fields &lt;em&gt;minDepth&lt;/em&gt; and &lt;em&gt;maxDepth&lt;/em&gt;. Therefore, I have min/max depth set to 0.0 and objects rendered to depth buffer are always black:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;m_viewport.TopLeftY = 0.0f;&#xA;m_viewport.TopLeftX = 0.0f;&#xA;m_viewport.Width = static_cast&amp;lt;float&amp;gt;(m_windowSize.x);&#xA;m_viewport.Height = static_cast&amp;lt;float&amp;gt;(m_windowSize.y);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Fixed that by simply using constructor which default &lt;em&gt;minDepth&lt;/em&gt; to 0.0 and &lt;em&gt;maxDepth&lt;/em&gt; to 1.0:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;m_viewport = CD3DX12_VIEWPORT{ 0.0f, 0.0f, static_cast&amp;lt;float&amp;gt;(m_windowSize.x), static_cast&amp;lt;float&amp;gt;(m_windowSize.y) };&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="10129" LastActivityDate="2021-03-31T19:25:32.110" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10793" PostTypeId="2" ParentId="10789" CreationDate="2021-04-01T08:12:56.073" Score="2" Body="&lt;p&gt;This effect is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Color_cycling&quot; rel=&quot;nofollow noreferrer&quot;&gt;Color Cycling&lt;/a&gt; (or Palette Shifting). Mark Ferrari has a great &lt;a href=&quot;https://www.youtube.com/watch?v=aMcJ1Jvtef0&quot; rel=&quot;nofollow noreferrer&quot;&gt;GDC talk&lt;/a&gt; where he demonstrates and explains the entire technique. You can view a bunch of his artwork based on this technique &lt;a href=&quot;http://www.effectgames.com/demos/canvascycle/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The main idea is that each pixel is painted not with a single color, but as values of a look-up table to a palette of colors. The entire image then cycles through the palettes frame by frame. Assigning colors to each palette to create the illusion of movement requires a fair bit of artistry. Mark Ferrari does this in a software called Pro Motion, but this can be coded in a shader pretty easily.&lt;/p&gt;&#xA;" OwnerUserId="9420" LastEditorUserId="9420" LastEditDate="2021-04-01T08:18:22.163" LastActivityDate="2021-04-01T08:18:22.163" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10794" PostTypeId="1" AcceptedAnswerId="10795" CreationDate="2021-04-01T12:34:35.677" Score="3" ViewCount="74" Body="&lt;p&gt;I was trying to understand what exactly is 'binding'. I found an &lt;a href=&quot;https://www.quora.com/What-is-binding-in-graphics&quot; rel=&quot;nofollow noreferrer&quot;&gt;answer on quora&lt;/a&gt; on this. From this, binding basically sounds like sending data from to GPU with help from CPU. I got to know more about 'bindless' things as there is something called bindless textures in OpenGL. But how does GPU access the data in this case?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.nvidia.com/en-us/drivers/bindless-graphics/&quot; rel=&quot;nofollow noreferrer&quot;&gt;NVIDIA article&lt;/a&gt; on bindless graphics talks about how the driver does not need to&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;dereference a vertex buffer or constant buffer on the CPU in order for&#xA;the GPU to use it.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;in the case of bindless graphics.&lt;/p&gt;&#xA;&lt;p&gt;So is this dereferencing thing the major difference? How does this help in hugely speeding up the application?&lt;/p&gt;&#xA;&lt;p&gt;In a nutshell, what is the difference between graphics using binding and 'bindless' graphics?&lt;/p&gt;&#xA;" OwnerUserId="16070" LastActivityDate="2021-04-01T16:20:03.943" Title="Binding vs bindless" Tags="&lt;gpu&gt;&lt;buffers&gt;" AnswerCount="1" CommentCount="0" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10795" PostTypeId="2" ParentId="10794" CreationDate="2021-04-01T14:09:50.977" Score="5" Body="&lt;p&gt;When a shader accesses a resource (buffer or texture), it needs some information about that resource to be able to do so correctly. On a modern GPU, that information will generally just be some kind of number. It could be something as simple as a GPU virtual memory address (with the particular details of what kind of resource is being used defined by the shading language), or it may be an index into a table of resources.&lt;/p&gt;&#xA;&lt;p&gt;But all modern GPUs need is a number.&lt;/p&gt;&#xA;&lt;p&gt;From the CPU side, a resource is defined by some API-defined object. To bind a resource (API-agnosticly) means that you tell the API that you the given API object's resource to used by the shader through some resource binding location.&lt;/p&gt;&#xA;&lt;p&gt;This process therefore requires the API to take that object and convert it into the number that the shader will receive. The object itself cannot just be that integer because the API needs ancillary information for managing the resource. But when you're &lt;em&gt;rendering&lt;/em&gt; with the resource, the integer is all you really need.&lt;/p&gt;&#xA;&lt;p&gt;So let's say you're rendering a complex scene. You may be rendering 100,000 different objects. That could mean 100,000 different binding operations per-frame. Each bind operation has to dereference an object pointer and fetch a single 64-bit integer from the object behind that pointer. And often, the nature of the API object requires &lt;em&gt;multiple&lt;/em&gt; dereferences to get this integer.&lt;/p&gt;&#xA;&lt;p&gt;This is not a cache-friendly operation, as you're fetching a piece of data from storage that has a bunch of &lt;em&gt;unrelated&lt;/em&gt; data near it. So not only is the read likely to be a cache-miss, you're doing a whole memory fetch for &lt;em&gt;just&lt;/em&gt; 64-bits of data, that will not be used for anything else before that cache line gets evicted. This represents poor cache coherency.&lt;/p&gt;&#xA;&lt;p&gt;Across 100,000 objects at 60fps (or greater), that can add up.&lt;/p&gt;&#xA;&lt;p&gt;A bindless API allows the user to store the integer themselves and marshal it to the shader in whatever way they see fit. Any resource integers for an object's rendering call can be stored near other data that is relevant to the rendering process, thus improving cache coherency.&lt;/p&gt;&#xA;&lt;p&gt;It should also be noted that a bindless API means that any shader could access any information about any object, so long as it has been given access to the integers that represent those resources. This is rather important when doing something like ray-tracing.&lt;/p&gt;&#xA;&lt;p&gt;So it's not &lt;em&gt;just&lt;/em&gt; about performance.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2021-04-01T16:20:03.943" LastActivityDate="2021-04-01T16:20:03.943" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10796" PostTypeId="1" AcceptedAnswerId="10797" CreationDate="2021-04-01T15:32:46.370" Score="0" ViewCount="31" Body="&lt;p&gt;&lt;a href=&quot;https://foundation.app/mg/20210227-3lau-makes-history-1790&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://foundation.app/mg/20210227-3lau-makes-history-1790&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The link above shows a video animation that has a rainbow wave distortion effect applied to it, that ripples across the video. how, and in which software, can this effect be applied to a video? or a step-by-step guess on how to replicate the effect&lt;/p&gt;&#xA;" OwnerUserId="15860" LastActivityDate="2021-04-01T17:10:12.950" Title="Animated rainbow distortion wave effect" Tags="&lt;color&gt;&lt;animation&gt;&lt;video&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10797" PostTypeId="2" ParentId="10796" CreationDate="2021-04-01T17:10:12.950" Score="3" Body="&lt;p&gt;The effect is called &lt;a href=&quot;https://en.wikipedia.org/wiki/Chromatic_aberration&quot; rel=&quot;nofollow noreferrer&quot;&gt;chromatic aberration&lt;/a&gt;; the way it’s usually done in games, and what’s being done there, is by reading the red / green / blue channels of an image at different offset positions. As with your &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/10789/what-is-the-name-of-this-moving-color-pixels-effect-for-animating-a-painting&quot;&gt;other question&lt;/a&gt; (you’re looking to get into the NFT market, I’m guessing?), there are most likely plugins for After Effects that will let you create something along these lines, but the original author probably used a tool like Processing or Shadertoy.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-04-01T17:10:12.950" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10798" PostTypeId="2" ParentId="10791" CreationDate="2021-04-01T18:42:11.127" Score="1" Body="&lt;p&gt;&lt;strong&gt;I recommend to ignore my post (however I consider papers that I've sent valueable) and read post of Nathan Reed, which is much better in explaining this problem!&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm still a junior when it comes to computer graphics so you may want to take my opinion with a grain of salt:&lt;/p&gt;&#xA;&lt;p&gt;To start with - I used to learn/implement stuff using website that you've sent (OpenGL) and I don't recommend that. After few months of learning I knew barely anything. Then I start reading original papers and implementing them on my own to better understand PBR, what N * G * F means in Cook-Torrance shading model and I got much better understanding of basics. I was recommend by many graphics programmers to avoid tutorial pages and straight read and implement papers. In case if you don't understand something in the paper you're reading, you found paper on subject that you don't understand and read about it.&lt;/p&gt;&#xA;&lt;p&gt;1). As I said - avoid this site or use only to get interesting papers - here are original notes from [Karis2013] UE4 presentation - &lt;a href=&quot;https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf&lt;/a&gt; ; Please notice comment &amp;quot;/sin&amp;quot; &amp;quot;/cos&amp;quot; in listing at page 7 and usage of &lt;em&gt;Pythagorean trigonometric identity&lt;/em&gt;. Maybe it's position on the hemishpere, I don't really want to dig in, I'm sorry. But I would recommend checking Epic Games repository on Github if you want to see how they're using it.&lt;/p&gt;&#xA;&lt;p&gt;2.) In the same paper [Karis2013] there is listing at the page 4. and function &lt;strong&gt;ImportanceSampleGGX&lt;/strong&gt;. It uses N to determine orientation of the world and returns either float3(0,0,1) or float3(1,0,0) based on N.z value.&lt;/p&gt;&#xA;&lt;p&gt;3).&#xA;&lt;span class=&quot;math-container&quot;&gt;$$N = (0, 0, 1)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$L = (x, y, z)$$&lt;/span&gt;&#xA;&lt;span class=&quot;math-container&quot;&gt;$$ dot(N, L) = (0 * x, 0 * y, 1 * z) = (0, 0, z) = L.z$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;4).&#xA;&lt;a href=&quot;http://jcgt.org/published/0003/02/03/paper.pdf#page=30&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://jcgt.org/published/0003/02/03/paper.pdf#page=30&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.microsoft.com/en-us/research/wp-content/uploads/1977/01/p192-blinn.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.microsoft.com/en-us/research/wp-content/uploads/1977/01/p192-blinn.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;These links might be helpful to understand BRDF better. Why there are strange division? I don't know, it's probably due to optimization, I don't know what NDF is being used. However, what happens here is you're multiplying D and G component, so you can do split multiplication with Fresnel. It doesn't matter how you write it. You can just create function NDF_GGX(...) and multiply it by G, add pdf and it'll work the same.&#xA;You can take a look at modern UE4 code - &lt;a href=&quot;https://github.com/EpicGames/UnrealEngine/blob/2bf1a5b83a7076a0fd275887b373f8ec9e99d431/Engine/Shaders/Private/AmbientCubemapComposite.usf#L255&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/EpicGames/UnrealEngine/blob/2bf1a5b83a7076a0fd275887b373f8ec9e99d431/Engine/Shaders/Private/AmbientCubemapComposite.usf#L255&lt;/a&gt; to understand it better. That's why I'm saying to write your own code. I would say that [Karis2013] is omitting a lot of code and uses many optimizations without saying WHY.&lt;/p&gt;&#xA;&lt;p&gt;5). It's just light direction. When you already calculated V and H, it is easy to get L by using reflection. Take a look at the picture here - &lt;a href=&quot;https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model#Description&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model#Description&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10129" LastEditorUserId="10129" LastEditDate="2021-04-05T11:01:01.613" LastActivityDate="2021-04-05T11:01:01.613" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10799" PostTypeId="1" CreationDate="2021-04-02T03:59:41.823" Score="0" ViewCount="18" Body="&lt;p&gt;I am trying to create a 3d structure in webgl using 3d coordinates from a pdb file mentioned below: &lt;a href=&quot;https://www.rcsb.org/structure/1RE2&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.rcsb.org/structure/1RE2&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I don't know which one is the appropriate one, so i used gl.drawArray(gl.POINTS, 0, array.length)&lt;/p&gt;&#xA;&lt;p&gt;but it is not creating it as it is showing in the pdb website.&lt;/p&gt;&#xA;&lt;p&gt;i don't know which one is better to draw such structure from pdb file (POINTS, TRIANGLES) and how to draw it appropriately.&lt;/p&gt;&#xA;&lt;p&gt;How i can draw exactly like in the pdb website.&lt;/p&gt;&#xA;" OwnerUserId="16040" LastEditorUserId="16040" LastEditDate="2021-04-02T05:52:09.147" LastActivityDate="2021-04-02T05:52:09.147" Title="How to draw a pdb 3d structure in webgl?" Tags="&lt;3d&gt;&lt;webgl&gt;&lt;javascript&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10800" PostTypeId="2" ParentId="9178" CreationDate="2021-04-02T12:52:47.157" Score="0" Body="&lt;p&gt;All of these projections fall under the generic group of projections called &amp;quot;Axonometric&amp;quot; projections. The general goal of an axonometric projection is to manipulate the object using rotations and translations such that at least three adjacent faces of the projected object are shown. The result is projected from the center at infinity onto one of the coordinate planes usually the Z=0 plane. There are three common types of axonometric projections, trimetric, dimetric and isometric. With trimetric being the most general, dimetric is a specialization of trimetric with two of the three foreshortening factors being equal to each other, and isometric is a specialization of dimetric with the third foreshortening factor set equal to the other two (so all three are equal). Also note that the projection plane in this case is the Z plane. The matrix show below can be modified to use any of the X, Y or Z planes as the projection plane.&lt;/p&gt;&#xA;&lt;p&gt;The general matrix form of all three (since dimetric and isometric are specializations of trimetric) is:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{bmatrix}&#xA; &amp;amp;cos\phi   &amp;amp;sin\phi sin\theta  &amp;amp;0 &amp;amp;0 \\ &#xA; &amp;amp;0  &amp;amp;cos\theta  &amp;amp;0 &amp;amp;0 \\ &#xA; &amp;amp;sin\phi  &amp;amp;-cos\phi sin\theta  &amp;amp;0 &amp;amp;0 \\ &#xA; &amp;amp;0  &amp;amp;0  &amp;amp;0 &amp;amp;1 &#xA;\end{bmatrix}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;Where phi is the rotation around the y axis and theta is the rotation around the x axis. The foreshortening length of each axis can be computed just by taking the sum of the squares of each row. Then take the square root to get the length. For the X axis this would be:&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;\begin{equation}&#xA;f_{x}^{2} = cos^{2}\phi + sin^{2}\phi sin^{2}\theta&#xA;\end{equation}&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;A little bit of algebra will yield the values needed to compute the lengths of the other 2.&lt;/p&gt;&#xA;&lt;p&gt;To determine a trimetric projection all we need are the two viewing angles. For a diametric or isometric view we need to set the foreshortening factors equal to either two or three of the axis. By using the lengths of the rows and setting them equal to one another then solving we can compute any of the values needed for either projection.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-04-02T12:52:47.157" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10801" PostTypeId="1" CreationDate="2021-04-02T17:13:45.617" Score="0" ViewCount="52" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/8ZOxz.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/8ZOxz.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Some underlying portrait above is glazed over with a series of vertical lines that neatly follow the contours of the face. What is this effect called and how can it be replicated, step-by-step, in Adobe Photoshop or other software? plus, how can the gap between the lines be controlled?&lt;/p&gt;&#xA;&lt;p&gt;Also is the color scheme due to chromatic aberration, or just simple RGB channel separation?&lt;/p&gt;&#xA;" OwnerUserId="15860" LastActivityDate="2021-04-06T18:39:13.173" Title="What is this vertical line contour effect in glitch art called?" Tags="&lt;line-drawing&gt;&lt;photometric&gt;&lt;color-separation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10802" PostTypeId="1" CreationDate="2021-04-02T22:09:15.727" Score="0" ViewCount="29" Body="&lt;p&gt;Good Morning. I'm testing Path Tracing techniques with unity, following this tutorial.&#xA;&lt;a href=&quot;http://three-eyed-games.com/2019/03/18/gpu-path-tracing-in-unity-part-3/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://three-eyed-games.com/2019/03/18/gpu-path-tracing-in-unity-part-3/&lt;/a&gt;&#xA;But I'm in trouble.&lt;/p&gt;&#xA;&lt;p&gt;Whenever I try to run the compute shader it crashes the system.&lt;/p&gt;&#xA;&lt;p&gt;I was erasing some lines and found that the problem happens when I try to change the values ​​of the hit.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    void IntersectMeshObject(int index, CameraRay ray, inout CameraRayHit bestHit)&#xA;{&#xA;    int offset = _Objects[index].indices_offset;&#xA;    int count = offset + _Objects[index].indices_count;&#xA;&#xA;    for (int i = offset; i &amp;lt; count; i += 3)&#xA;    {&#xA;       float3 v0 = (mul(_Objects[index].localToWorldMatrix, float4(_Vertices[_Indices[i]], 1))).xyz;&#xA;       float3 v1 = (mul(_Objects[index].localToWorldMatrix, float4(_Vertices[_Indices[i + 1]], 1))).xyz;&#xA;       float3 v2 = (mul(_Objects[index].localToWorldMatrix, float4(_Vertices[_Indices[i + 2]], 1))).xyz;&#xA;&#xA;       float t, u, v;&#xA;&#xA;        if (IntersectTriangle(ray, v0, v1, v2, t, u, v))&#xA;        {&#xA;            if (t &amp;gt; 0 &amp;amp;&amp;amp; t &amp;lt; bestHit.rayHitDistance)&#xA;            {&#xA;                bestHit.rayHitDistance = t; //&amp;lt;--That makes it crash&#xA;                bestHit.rayHitPosition = ray.raySource + t * ray.rayDirection;//&amp;lt;--That makes it crash&#xA;                bestHit.rayHitNormal = float3(0.0f, 1.0f, 0.0f);//&amp;lt;--That makes it crash&#xA;&#xA;                bestHit.viewDirection = normalize(_WorldSpaceCameraPos - bestHit.rayHitPosition);//&amp;lt;--That makes it crash&#xA;                bestHit.lightDirection = _DirectionalLightDirection;//&amp;lt;--That makes it crash&#xA;&#xA;                bestHit.rayHitAlbedo = float4(0.6, 0.6, 0.6, 1);//&amp;lt;--That makes it crash&#xA;                bestHit.rayHitEmission = float4(0, 0, 0, 0);//&amp;lt;--That makes it crash&#xA;                bestHit.rayHitSmoothness = 0.6;//&amp;lt;--That makes it crash&#xA;                bestHit.rayHitMetallic = 0.6;//&amp;lt;--That makes it crash&#xA;                bestHit.rayHitAnisotropy = 0;//&amp;lt;--That makes it crash&#xA;&#xA;                bestHit.hitRenderType = 0;//&amp;lt;--That makes it crash&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VJMFZ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VJMFZ.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;When executing only with sphere hits&#xA;&lt;a href=&quot;https://i.stack.imgur.com/xnMVu.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/xnMVu.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;When I leave the if without instructions it works normally.&lt;/p&gt;&#xA;&lt;p&gt;All codes:&#xA;&lt;a href=&quot;https://gist.github.com/MatheusMarkies/3a334b97d3ee4330c335143e496ded67&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://gist.github.com/MatheusMarkies/3a334b97d3ee4330c335143e496ded67&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Can someone help me find out where the problem is?&lt;/p&gt;&#xA;" OwnerUserId="15955" LastEditorUserId="15955" LastEditDate="2021-04-03T14:17:53.093" LastActivityDate="2021-04-03T14:17:53.093" Title="Unity path tracing makes the pc crash" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;&lt;compute-shader&gt;&lt;hlsl&gt;&lt;unity&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10803" PostTypeId="1" CreationDate="2021-04-03T12:48:46.983" Score="0" ViewCount="25" Body="&lt;p&gt;Seems like a simple problem, but I just cant wrap my head around it.&lt;/p&gt;&#xA;&lt;p&gt;I have a config file in which I declare a few functions. It looks like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;&amp;quot;bandDefinitions&amp;quot; : [&#xA;    {&#xA;        &amp;quot;0&amp;quot;: [&amp;quot;x^2 + 2*x + 5 - y&amp;quot;, &amp;quot;ABOVE&amp;quot;]&#xA;    },&#xA;    {&#xA;        &amp;quot;0&amp;quot;: [&amp;quot;sin(6*x) - y&amp;quot;, &amp;quot;UNDER&amp;quot;]&#xA;    },&#xA;    {&#xA;        &amp;quot;0&amp;quot;: [&amp;quot;tan(x) - y&amp;quot;, &amp;quot;ABOVE&amp;quot;]&#xA;    }&#xA;]&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;These functions should generate 3 images. Every image should be filled depending on solution of equations, and provided position (Under or Above). I need to move the coordinate system to the center of the image, so I'm adding &lt;code&gt;-y&lt;/code&gt; into the equation. Part of image which should be filled should be colored white, and the other part should be colored black.&lt;/p&gt;&#xA;&lt;p&gt;To explain what I mean, I'm providing images for quadratic and sin functions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/17nU8.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/17nU8.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/aMeOh.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/aMeOh.png&quot; alt=&quot;sin&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;What I'm doing is solve the equation for &lt;code&gt;x in [-W/2, W/2]&lt;/code&gt; and store the solutions into the array, like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#Generates X axis dots and solves an expression which defines a band&#xA;#Coordinate system is moved to the center of the image&#xA;def __solveKernelDefinition(self, f):&#xA;    xAxis = range(-kernelSize, kernelSize)&#xA;    dots = []&#xA;&#xA;    for x in xAxis:&#xA;        sol = f(x, kernelSize/2)&#xA;        dots.append(sol)&#xA;&#xA;    print(dots)&#xA;    return dots&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm testing if some pixel should be colored white like this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;def shouldPixelGetNoise(y, x, i, currentBand):&#xA;    shouldGetNoise = True&#xA;&#xA;    for bandKey in currentBand.bandDefinition.keys():&#xA;        if shouldGetNoise:&#xA;            pixelSol = currentBand.bandDefinition[bandKey][2](x, y)&#xA;            renderPos = currentBand.bandDefinition[bandKey][1]&#xA;            bandSol = currentBand.bandDefinition[bandKey][0]&#xA;            shouldGetNoise = shouldGetNoise and pixelSol &amp;lt;= bandSol[i] if renderPos == Position.UNDER else pixelSol &amp;gt;= bandSol[i]&#xA;        else:&#xA;            break&#xA;&#xA;    return shouldGetNoise&#xA;&#xA;def kernelNoise(kernelSize, num_octaves, persistence, currentBand, dimensions=2):&#xA;    simplex = SimplexNoise(num_octaves, persistence, dimensions)&#xA;    data = []&#xA;&#xA;    for i in range(kernelSize):&#xA;        data.append([])&#xA;        i1 = i - int(kernelSize / 2)&#xA;&#xA;        for j in range(kernelSize):&#xA;            j1 = j - int(kernelSize / 2)&#xA;            if(shouldPixelGetNoise(i1, j1, i, currentBand)):&#xA;                noise = normalize(simplex.fractal(i, j, hgrid=kernelSize))&#xA;                data[i].append(noise * 255)&#xA;            else:&#xA;                data[i].append(0)&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I'm only getting good output for convex quadratic functions. If I try to combine them, I get a black image. &lt;code&gt;Sin&lt;/code&gt; just doesn't work at all. I see that this bruteforce approach won't lead me anywhere, so I was wondering what algorithm should I use to generate these kinds of images?&lt;/p&gt;&#xA;" OwnerUserId="11077" LastActivityDate="2021-04-04T10:00:50.397" Title="Filling pixels under or above some function" Tags="&lt;image-processing&gt;&lt;procedural-generation&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10804" PostTypeId="2" ParentId="10803" CreationDate="2021-04-04T10:00:50.397" Score="1" Body="&lt;p&gt;Compute the tangent to the line at that point, Use it to make a tangent vector, then use the point on the line, the point being tested and the new point to create two vectors. Take the dot product of the vectors. Positive values are on one side of the line, negative are on the other side. (above and below).&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-04-04T10:00:50.397" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10805" PostTypeId="2" ParentId="10791" CreationDate="2021-04-04T18:49:48.140" Score="2" Body="&lt;blockquote&gt;&#xA;&lt;p&gt;1)What is the V vector? How did they compute that&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;It's the vector toward the camera (view vector), i.e. direction of the reflected ray. The lookup table they're building is parameterized in terms of NdotV, so they are working backward from NdotV to obtain a corresponding V vector. For purposes of doing this integration it doesn't matter what N and V are exactly, just that they have the correct NdotV. So, just to make things concrete, they assume that &lt;span class=&quot;math-container&quot;&gt;$N = (0,0,1)$&lt;/span&gt; and V is aligned with the positive x-axis (i.e. in the positive xz half-plane). Then you have &lt;span class=&quot;math-container&quot;&gt;$V = (\sin θ, 0, \cos θ)$&lt;/span&gt; where θ is the angle from N to V (this is just the equation for a circular arc from z down to x). Now &lt;span class=&quot;math-container&quot;&gt;$N \cdot V = \cos θ$&lt;/span&gt;, so by a standard trig identity &lt;span class=&quot;math-container&quot;&gt;$\sin θ = \sqrt{1 - \cos^2 θ} = \sqrt{1 - (N \cdot V)^2}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;2)Why have they assumed N=(0,0,1)?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;This whole thing is a pre-integration of the BRDF alone, it doesn't depend on any scene or lighting environment. So it doesn't matter where the BRDF is or how it is oriented in space, only the relative orientation between the N, L, and V vectors is important. So just for the sake of convenience they have chosen to fix N = (0, 0, 1), let V vary only in the xz half-plane as mentioned above, and let L vary over the whole hemisphere. To put it another way, they have chosen to set the coordinate system to be aligned with N and V.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;3)why is NDotL=max(L.z,0)? How did they simplifying a dot product to an min/max Operation same question I have for NDotH&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Since N = (0, 0, 1), dotting N with any vector just takes the z component of that vector. &lt;span class=&quot;math-container&quot;&gt;$N \cdot L = 0L_x + 0L_y + 1L_z = L_z$&lt;/span&gt;. (This is why it's convenient to assume a coordinate system in which N = (0, 0, 1).) Taking the max with 0 clamps it to the upper hemisphere, otherwise the dot product would go negative if the vector happens to be pointing below the hemisphere. This clamp is a standard thing to do when dealing with opaque BRDFs to avoid accidentally getting unwanted negative values in your calculations— although it is not really necessary here since they check &lt;code&gt;if (NdotL &amp;gt; 0.0)&lt;/code&gt; immediately afterward.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;4)G_Vis=GVDoth/(NDotHNDotL) why the division by (NDOTH*NDOTL)? that was nowhere in the equation.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;It is a standard part of the microfacet BRDF formulation:&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f_r(p, w_i, w_o) = \frac{DFG}{4(\omega_o \cdot n)(\omega_i \cdot n)}&#xA;$$&lt;/span&gt;&#xA;Note that &lt;span class=&quot;math-container&quot;&gt;$\omega_o = V$&lt;/span&gt;, and &lt;span class=&quot;math-container&quot;&gt;$\omega_i = L$&lt;/span&gt;, these are just different notations/names for the incoming and outgoing light vectors.&#xA;However I think there is a typo in the code, the denominator should contain NdotV rather than NdotH. I am also not sure why there is a multiplication by VdotH in the numerator, or where the factor of 4 went, but perhaps they have accounted for it elsewhere. I would probably double-check the BRDF equations here against some other sources as I don't think it's entirely correct.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;5)what is vector L? it looks like they have reflected vector V about H to get this but why?&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;As noted, L is the vector toward the incoming light. H is the &amp;quot;half-angle&amp;quot; vector exactly halfway between L and V, so reflecting V around H will give you L, or vice versa. The significance of H is that in microfacet BRDFs, it is the normal vector of those microfacets that are &amp;quot;active&amp;quot; for a given L and V. So, to importance-sample a BRDF, we sample a random normal vector from the NDF, and use that as H. Since H and V are specified, we then calculate L from those.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-04-04T18:49:48.140" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10806" PostTypeId="1" CreationDate="2021-04-06T06:19:32.317" Score="0" ViewCount="40" Body="&lt;p&gt;Lets assume, we have two depth maps with us and their corresponding color maps. Now, our task is to populate a final image that will be displayed.&lt;/p&gt;&#xA;&lt;p&gt;Each pixel in the final image needs to be calculated from the given 4 maps - two color and corresponding depth. I am simply aiming to create a final image considering the occlusion of one depth map over the other.&lt;/p&gt;&#xA;&lt;p&gt;My idea is to just compare the depth values and then take the color value from the map whichever is closer to the camera.&lt;/p&gt;&#xA;&lt;p&gt;Is this a right way to approach the problem?&lt;/p&gt;&#xA;&lt;p&gt;PS: This problem popped up as part of a hybrid rendering solution am working on - combining ray marching and rasterization to get triangles as well as metaballs working. So, one of the pair of maps above comes from rasterization and the other comes from ray marching.&lt;/p&gt;&#xA;" OwnerUserId="15544" LastActivityDate="2021-04-06T06:19:32.317" Title="Combining two images based on their depth maps" Tags="&lt;raytracing&gt;&lt;rendering&gt;&lt;rasterizer&gt;&lt;raymarching&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10807" PostTypeId="2" ParentId="10801" CreationDate="2021-04-06T18:39:13.173" Score="1" Body="&lt;p&gt;The technique is called &lt;strong&gt;halftone&lt;/strong&gt;.  Achieving continuity must be done through subsampling / super-sampling, but the essence of the algorithm goes like this.&lt;/p&gt;&#xA;&lt;p&gt;Imagine walking across a horizontal line of the image accumulating energy from each input pixel as you go.  Once you have accumulated some threshold amount of energy in the accumulator, emit a single pixel, and then reduce the energy stored in the accumulator by a constant amount.&lt;/p&gt;&#xA;&lt;p&gt;In code, that would be something like:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;for (int y = 0; y &amp;lt; height; ++y) {&#xA;    double accumulator = 0.0;&#xA;    for (int x = 0; x &amp;lt; width; ++x) {&#xA;        accumulator += input[x, y];&#xA;        if (accumulator &amp;gt;= 0.0) {&#xA;            output[x, y] = 1.0;&#xA;            accumulator -= K; // try values like 5.0 or more for K.&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The larger &lt;code&gt;K&lt;/code&gt; is, the more energy must be accumulated before outputting a pixel, and hence, the more horizontal distance there will be between the lines.  If K is 1, that's actually a naïve approach to the &lt;em&gt;dither&lt;/em&gt; algorithm.&lt;/p&gt;&#xA;&lt;p&gt;Supersample to achieve continuity.  You can also emit discrete (x,y) points instead of rendering an output pixel directly and then render a new image by rendering a vertical curve passing through the nth point generated of each scanline.&lt;/p&gt;&#xA;&lt;p&gt;Perform the operation discretely on separate colour channels to get what you described as the &amp;quot;chromatic aberration&amp;quot; effect.&lt;/p&gt;&#xA;&lt;p&gt;The effect degenerates the more complexity you encounter in the image on a single line.  For example, after just two eyes on the same line, the lines are extremely wavy at the right of your example image.  &lt;a href=&quot;https://www.shutterstock.com/image-vector/vector-oscilloscope-color-glitch-art-illustration-1753357889&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here is the effect exaggerated even more&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="8009" LastActivityDate="2021-04-06T18:39:13.173" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10810" PostTypeId="1" AcceptedAnswerId="10813" CreationDate="2021-04-08T12:41:28.710" Score="0" ViewCount="47" Body="&lt;p&gt;I am currently porting the atmosphere algorithm used by the UE4 engine to my engine.&lt;/p&gt;&#xA;&lt;p&gt;As the original algorithm from Bruneton is in Kilometers i had to adapt it to my engine which uses meters. Everything is working and its correctly scaled now but i am having some z precision issues on the horizon when drawing the fog. This, i believe, i due to the following math:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float DepthBufferValue = texture(ViewDepthTexture, depthValueUV).r;&#xA;vec3 depthClipSpace = vec3(pixPos / vec2(gResolution) * vec2(2.0f) - vec2(1.0f), DepthBufferValue);&#xA;vec4 DepthBufferWorldPos = gInvViewProjMat * vec4(depthClipSpace, 1.0);&#xA;DepthBufferWorldPos /= DepthBufferWorldPos.w; // perspective division&#xA;DepthBufferWorldPos.xyz *= 0.001; &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Here, i am basically reading the depth texture, getting the real world position value and scaling it to be in KMs. Due to this scaling (and the inverse multiplication) i am getting some shimmering in the horizon (where the z distance is the greatest)&lt;/p&gt;&#xA;&lt;p&gt;Since the depth equation is equal to:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt; d = a * (1/z) + b &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;(with a = near, b = far clip and z the distance from camera) is there any mathematical way to scale the DepthBufferValue to a value where the world position would be in kilometers?&lt;/p&gt;&#xA;&lt;p&gt;In a more practical way, imagining that we have a World Position of (0, 1000, 0) and that gives us a DepthBufferValue of 0.998, can we scale that 0.998 value to the value that we would obtain if we had used the World Position (0, 1, 0) ? (Assuming of course the same near and far clips)&lt;/p&gt;&#xA;&lt;p&gt;Many thanks!&lt;/p&gt;&#xA;&lt;p&gt;Edit:&#xA;This is the DepthBufferWorldPos outputed to the screen:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=kEaU72NWq8I&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=kEaU72NWq8I&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="11840" LastEditorUserId="11840" LastEditDate="2021-04-12T12:07:06.927" LastActivityDate="2021-04-12T12:07:06.927" Title="Scale Sampled Depth Value" Tags="&lt;glsl&gt;&lt;hlsl&gt;&lt;depth-map&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10811" PostTypeId="1" CreationDate="2021-04-08T17:59:53.497" Score="0" ViewCount="16" Body="&lt;p&gt;I'm trying to implement 3D picking in my engine. To do this I am rendering objects with different colours and getting the pixel at certain mouse position and extracting the colour value from a special buffer. I have successfully retrieved the pixel and its data from a staging Texture2D at a certain point like this (mx and my refer to the mouse position on screen):&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;D3D11_BOX srcBox;&#xA;srcBox.left = mx;&#xA;srcBox.right = srcBox.left + 1;&#xA;srcBox.top = my;&#xA;srcBox.bottom = srcBox.top + 1;&#xA;srcBox.front = 0;&#xA;srcBox.back = 1;&#xA;&#xA;deviceContext-&amp;gt;CopySubresourceRegion(m_renderTargetTextureIdStaging, 0, 0, 0, 0, m_renderTargetTextureIds, 0, &amp;amp;srcBox);&#xA;D3D11_MAPPED_SUBRESOURCE msr;&#xA;deviceContext-&amp;gt;Map(m_renderTargetTextureIdStaging, 0, D3D11_MAP_READ, 0, &amp;amp;msr);&#xA;&#xA;D3DXVECTOR4 pixel = *((D3DXVECTOR4*)msr.pData);&#xA;BYTE* mappedData = reinterpret_cast&amp;lt;BYTE*&amp;gt;(msr.pData);&#xA;&#xA;deviceContext-&amp;gt;Unmap(m_renderTargetTextureIdStaging, 0);&#xA;&#xA;return pixel;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This works fine, but the problem is that the data retrieved from the pixel isn't at all correct with the actual color on the screen. I can confirm that the code actually works because clicking on different coloured objects on the screen will return a different value. Clicking the 'background' will also give a constant value. However, it is obvious that the values inside the D3DXVECTOR4 and BYTE* are both incorrect in relation to the actual data on the screen. What is going wrong?&lt;/p&gt;&#xA;" OwnerUserId="16126" LastActivityDate="2021-04-08T17:59:53.497" Title="Data from staging Texture2D incorrect (DirectX 11)" Tags="&lt;c++&gt;&lt;directx&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10812" PostTypeId="1" AcceptedAnswerId="10819" CreationDate="2021-04-10T15:05:54.557" Score="0" ViewCount="52" Body="&lt;p&gt;I'd like to simulate a 4-dimensional cloth in the web browser, since browsers don't offer great ressources for numerical computation, I'd like to know which algorithm uses the least amount of operations per frame / vertex.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://codepen.io/fweth/pen/poRjMKg?editors=0010&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here&lt;/a&gt; is some naive first draft using explicit Euler.  I found &lt;a href=&quot;https://www.cs.utah.edu/%7Eladislav/liu13fast/liu13fast.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;this&lt;/a&gt; paper discussing a fast method for finding approximate solutions of the implicit Euler method.  What I gathered from the discussion is that implicit Euler is numerically more stable in certain scenarios, but it looks like it uses more operations than explicit Euler since it is built around iterations.  Is that correct?&lt;/p&gt;&#xA;&lt;p&gt;Also, are there any libraries using WebGL to accelerate numerical computations which might be useful for this project?  I thought about looking into TensorFlow.js.&lt;/p&gt;&#xA;" OwnerUserId="13975" LastActivityDate="2021-04-12T17:52:42.533" Title="Fastest Simulation Of Mass Spring Systems" Tags="&lt;webgl&gt;&lt;real-time&gt;&lt;physics&gt;&lt;javascript&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10813" PostTypeId="2" ParentId="10810" CreationDate="2021-04-10T17:38:43.773" Score="0" Body="&lt;p&gt;Algebraically speaking, it's not too hard to modify &lt;span class=&quot;math-container&quot;&gt;$d$&lt;/span&gt; in order to scale &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt;. If you want to scale &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; by a factor of &lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt;, giving &lt;span class=&quot;math-container&quot;&gt;$z' = cz$&lt;/span&gt;, then&#xA;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;\begin{aligned}&#xA;d' &amp;amp;= a \frac{1}{z'} + b \\&#xA;&amp;amp;= a \frac{1}{cz} + b \\&#xA;(d' - b)c &amp;amp;= a \frac{1}{z} \\&#xA;&amp;amp;= d - b \\&#xA;d' &amp;amp;= \frac{d - b}{c} + b&#xA;\end{aligned}&#xA;$$&lt;/span&gt;&#xA;In short, to scale &lt;span class=&quot;math-container&quot;&gt;$z$&lt;/span&gt; by a factor of &lt;span class=&quot;math-container&quot;&gt;$c$&lt;/span&gt;, you would take the depth value and subtract &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt;, scale by &lt;span class=&quot;math-container&quot;&gt;$1/c$&lt;/span&gt;, then add &lt;span class=&quot;math-container&quot;&gt;$b$&lt;/span&gt; back again.&lt;/p&gt;&#xA;&lt;p&gt;Note that if you use a projection with reversed Z and an infinite far plane, then &lt;span class=&quot;math-container&quot;&gt;$b = 0$&lt;/span&gt;, which simplifies this to just &lt;span class=&quot;math-container&quot;&gt;$d' = d/c$&lt;/span&gt;.&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-04-10T17:38:43.773" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10814" PostTypeId="1" CreationDate="2021-04-11T03:52:44.233" Score="0" ViewCount="23" Body="&lt;p&gt;I'd like to find a concrete example of how geodesic distance can be useful in CG such as games or the movie industry.&lt;/p&gt;&#xA;&lt;p&gt;(An example I like for mean curvature is when it's used to fake ambient occlusion. It can also be used to shade an object at its peaks and creases to show wear or dust accumulation.)&lt;/p&gt;&#xA;&lt;p&gt;Such examples would help me sell the importance of fundamental geometry processing tools to the crowd ^^&lt;/p&gt;&#xA;" OwnerUserId="16151" LastActivityDate="2021-04-11T03:52:44.233" Title="What's a compeling use case for geodesic distance in a real world CG application" Tags="&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10817" PostTypeId="1" CreationDate="2021-04-11T21:41:26.297" Score="0" ViewCount="47" Body="&lt;p&gt;Sorry for the general question, I don't even know how to tag it:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=61UkkpsASwQ&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=61UkkpsASwQ&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/UzXr2m.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/UzXr2m.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In this video, the effect is such as if there were a laser cutting a shape with a light source behind it, and then the cut is closed again (like some trail effect).&lt;/p&gt;&#xA;&lt;p&gt;How is this made and with which kind of software/programming? Is 3D involved here or can this be achieved with procedural 2D programming and shaders?&lt;/p&gt;&#xA;" OwnerUserId="9548" LastActivityDate="2021-04-13T01:08:12.313" Title="How's this laser cutting effect with backlight achieved?" Tags="&lt;lighting&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10818" PostTypeId="1" CreationDate="2021-04-12T16:10:32.180" Score="0" ViewCount="42" Body="&lt;p&gt;I've tried using the classic formula of calculating barycentric coordinates.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/VDSQP.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/VDSQP.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;When the plane on which you are projecting the texture is collinear to any of the base vectors it crashes with a division on zero error.&lt;/p&gt;&#xA;&lt;p&gt;Is there any way to avoid this problem?&lt;/p&gt;&#xA;" OwnerUserId="16171" LastActivityDate="2021-04-12T16:10:32.180" Title="UV coordinates calculation broken" Tags="&lt;3d&gt;&lt;uv-mapping&gt;&lt;3dtexture&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10819" PostTypeId="2" ParentId="10812" CreationDate="2021-04-12T17:52:42.533" Score="1" Body="&lt;p&gt;Time integration with implicit Euler is unconditionally stable. This means you can choose arbitrary large time steps without worrying that your solution &amp;quot;explodes&amp;quot;. In contrast to explicit Euler, it requires you to solve a linear equation system at least once, which is generally much slower than simple matrix-vector multiplication. If the problem is non-linear, you also need to iterate until your error is minimized. This obviously takes even longer.&lt;/p&gt;&#xA;&lt;p&gt;However, stability issues can be a pain to deal with and all explicit methods have limitations regarding their stability. Solving stability problems might force you to reduce your time step size drastically and to calculate so many intermediate steps that the implicit version gets more effective. An additional factor is the size of the system you want to simulate. If I remember correctly, the finer your mesh (smaller cells), the smaller are the timesteps you need to maintain stability.&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I'd like to know which algorithm uses the least amount of operations per frame / vertex.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I think there is no general answer to the question because it depends on many factors like the mesh size, target FPS and the maximum local velocity that might occur. You need to evaluate all relevant factors and pick a method based on your exact problem.&lt;/p&gt;&#xA;&lt;p&gt;In case you want raw speed and do not encounter any stability problems, the explicit Euler method should be one of the fastest methods but it usually blows up rather quickly.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Additional info&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;A time-integration method that is quite popular in real-time engines is Runge-Kutta 4. It is also an explicit method and doesn't require you to solve a linear system. It has a good balance of stability and speed, so you might have a look at it. I have never simulated cloth myself, nor have I programmed an RK4, so I can't tell if it is a good choice here.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2021-04-12T17:52:42.533" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10820" PostTypeId="2" ParentId="10817" CreationDate="2021-04-13T01:02:23.587" Score="1" Body="&lt;p&gt;This question may be off-topic here, but this is almost certainly a 2D effect, and it's achievable without much difficulty in After Effects or any similar package once you've broken the effect down into individual elements.&lt;/p&gt;&#xA;&lt;p&gt;This isn't exactly the same effect, but it gives most of the ideas: &lt;a href=&quot;https://www.youtube.com/watch?v=uHFmWu__Q4k&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=uHFmWu__Q4k&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The key point here is that you need to look not at the effect as a whole, but break it down into the individual elements that make it up. The parts make the whole.&lt;/p&gt;&#xA;" OwnerUserId="159" LastEditorUserId="159" LastEditDate="2021-04-13T01:08:12.313" LastActivityDate="2021-04-13T01:08:12.313" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10821" PostTypeId="2" ParentId="10763" CreationDate="2021-04-13T13:20:19.617" Score="3" Body="&lt;p&gt;The actual color of a pixel, outputted on a monitor, does not linearly depend on the applied voltage signal for that pixel. For CRT monitors, the actual color is approximately proportional to the applied voltage raised to the power of a so-called &lt;em&gt;gamma&lt;/em&gt; value, which depends on the monitor. This gamma value typically lies between 2.2 and 2.5 for CRT monitors. (&lt;em&gt;Hence, the ubiquitous appearances of the magical constant 2.2 in rendering applications.&lt;/em&gt;)&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$L_\mathrm{actual} \sim V^\gamma$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;To bypass this gamma value in your computations, you need to &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_correction&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;em&gt;gamma correct&lt;/em&gt;&lt;/a&gt; the computed colors of each pixel before presenting. By raising the computed color to a power of the reciprocal of that same gamma value, the computed color becomes proportional to the actual color.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$V \sim L_\mathrm{computed}^{1/\gamma} \\&#xA;L_\mathrm{actual} \sim L_\mathrm{computed}$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;So in general gamma correction is a technique that adapts the computed colors to the transfer function of the monitor used for outputting. Both CRT and non-CRT monitors each have their own transfer function. This means that the final rendering pass should adapt the computed colors, based on the used monitor, to obtain correct actual colors.&lt;/p&gt;&#xA;&lt;p&gt;These linear-to-gamma color space conversions seem like unnecessary overhead from a monitor construction point of view. It is physically perfectly possible to construct a CRT monitor with a gamma value of exactly one, ensuring that the computed color is already proportional to the actual color, and eliminating the need for gamma correction.&lt;/p&gt;&#xA;&lt;p&gt;From a perceptual point of view, removing the need for gamma correction and using a monitor where computed colors are proportional to the corresponding actual colors is actually a bad idea. Typically, actual colors are represented with 8 (or 10) bits for each of the red, green and blue channel. This quantization only supports 256 (or 1024) different colors. Here, a 0 value represents completely black and a 255 (or a 1023) value represents completely white. But what about the intermediate values? If a linear encoding is used (&lt;em&gt;i.e. a gamma value of 1&lt;/em&gt;), the majority of values would be perceptually very close to white and a very small minority would be perceptually close to black. By using a gamma encoding (&lt;em&gt;e.g., a gamma value of 2.2&lt;/em&gt;), the distribution is perceptually more linear (&lt;em&gt;i.e. equidistant intervals between black and white&lt;/em&gt;).&lt;/p&gt;&#xA;&lt;img src=&quot;https://user-images.githubusercontent.com/2464019/38454812-917ffe76-3a6e-11e8-9776-262e1e229f4c.png&quot;&gt;&#xA;" OwnerUserId="2287" LastActivityDate="2021-04-13T13:20:19.617" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10822" PostTypeId="1" CreationDate="2021-04-14T01:47:36.140" Score="1" ViewCount="26" Body="&lt;p&gt;Recently I‘m working on a Precomputed GI Project&lt;/p&gt;&#xA;&lt;p&gt;I'm trying to use a technique called AHD, Amibent Highlight Direction, rendering my project;&#xA;I use Unity and my target platform is Android.&lt;/p&gt;&#xA;&lt;p&gt;First:&#xA;Unity SH is the result of Encoded and Scaled, I want to get the original SH&#xA;I'm trying try to decode it, but there are several problems with the sixth coefficient;&#xA;I found some documents that said unity moved the constant part of  L6(band l = 2,order m = 0) to the L0(band l = 0, order m = 0), is that true?&#xA;If that's right, how can I get the right original SH?&lt;/p&gt;&#xA;&lt;p&gt;There are some trying of myself, I have tried to calculate the constant part and recalculate the L0 and L6, but it seem not to be correct, in fact, I don't know how to verify it.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;#define k01 0.2820947918 // sqrt(  1/PI)/2&#xA;#define k02 0.4886025119 // sqrt(  3/PI)/2&#xA;#define k03 1.0925484306 // sqrt( 15/PI)/2&#xA;#define k04 0.3153915652 // sqrt(  5/PI)/4&#xA;#define k05 0.5462742153 // sqrt( 15/PI)/4&#xA;&#xA;float3 SampleRawSH9(float4 SHCoefficients[7], float3 N) {&#xA;    float3 n = N.zxy;&#xA;float4 shAr = SHCoefficients[0];&#xA;float4 shAg = SHCoefficients[1];&#xA;float4 shAb = SHCoefficients[2];&#xA;float4 shBr = SHCoefficients[3];&#xA;float4 shBg = SHCoefficients[4];&#xA;float4 shBb = SHCoefficients[5];&#xA;float4 shCr = SHCoefficients[6];&#xA;&#xA;//band0&#xA;//l0 + l6 constant part&#xA;float3 L0 = float3(shAr.w, shAg.w, shAb.w);&#xA;float3 L6c = -float3(shBr.z, shBg.z, shBb.z)* k04/4.;&#xA;L6c = 0;&#xA;L0 = (L0 - L6c) / k01;&#xA;&#xA;//band1&#xA;//m=-1&#xA;float3 L1 = float3(shAr.y * n.y, shAg.y * n.y, shAb.y * n.y);&#xA;L1 = L1 * 1.5 / (-k02);&#xA;//m=0&#xA;float3 L2 = float3(shAr.z * n.z, shAg.z * n.z, shAb.z * n.z);&#xA;L2 = L2 * 1.5 / (k02);&#xA;//m=1&#xA;float3 L3 = float3(shAr.x * n.x, shAg.x * n.x, shAb.x * n.x);&#xA;L3 = L3 * 1.5 / (-k02);&#xA;&#xA;//band2&#xA;//m=-2&#xA;float3 L4 = float3(shBr.x * n.x * n.y, shBg.x * n.x * n.y, shBb.x * n.x * n.y);&#xA;L4 = L4 * 4. / (k03);&#xA;//m=-1&#xA;float3 L5 = float3(shBr.y * n.y * n.z, shBg.y * n.y * n.z, shBb.y * n.y * n.z);&#xA;L5 = L5 * 4. / (-k03);&#xA;//m=0&#xA;float3 L6cos = float3(shBr.z * n.z * n.z, shBg.z * n.z * n.z, shBb.z * n.z * n.z);&#xA;float3 L6 = L6cos * 4. / (k04 * 3.0) + L6c * 4. / (k04);&#xA;//m=1&#xA;float3 L7 = float3(shBr.w * n.x * n.z, shBg.w * n.x * n.z, shBb.w * n.x * n.z);&#xA;L7 = L7 * 4. / (-k03);&#xA;//m=2&#xA;float3 L8 = shCr.rgb * (n.x * n.x - n.y * n.y);&#xA;L8 = L8 * 4. / (k05);&#xA;&#xA;return L0 + L1 + L2 + L3 + L4 + L5 + L6 + L7 + L8;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&lt;p&gt;Second:&#xA;I try to rebuild my AHD from SH.&#xA;I'm confused with amibentColor part. Does it contain the part of Directional Light Diffuse term?&#xA;The results look strange;&#xA;Same as the previous one,  I still can't verify the correctness of my calculation&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;void SampleRawSHAHD(float3 normalWS, out float highLightFactor, out float3 highLightDir, out float3 highLightColor, out float3 ambientColor) {&#xA;        real4 SHCoefficients[7];&#xA;        SHCoefficients[0] = unity_SHAr;&#xA;        SHCoefficients[1] = unity_SHAg;&#xA;        SHCoefficients[2] = unity_SHAb;&#xA;        SHCoefficients[3] = unity_SHBr;&#xA;        SHCoefficients[4] = unity_SHBg;&#xA;        SHCoefficients[5] = unity_SHBb;&#xA;        SHCoefficients[6] = unity_SHC;&#xA;    highLightDir = SampleRawSHDir(SHCoefficients, normalWS);&#xA;    highLightFactor = length(highLightDir) * PI * 16 / 17;&#xA;    highLightDir = normalize(highLightDir);&#xA;    highLightColor = highLightFactor * SampleRawSH(highLightDir) * 867. / (316. * PI);&#xA;    ambientColor = (SampleRawSH(0) - highLightColor * 8. * sqrt(PI) / 17.) * sqrt(PI) / 2.;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;}&lt;/p&gt;&#xA;&lt;p&gt;I really appreciate someone who can give me some guidance!&lt;/p&gt;&#xA;&lt;p&gt;My reference：&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://www.ppsloan.org/publications/StupidSH36.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.ppsloan.org/publications/StupidSH36.pdf&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://graphics.stanford.edu/papers/envmap/envmap.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://graphics.stanford.edu/papers/envmap/envmap.pdf&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="16184" LastActivityDate="2021-04-14T01:47:36.140" Title="Questions about caculate the highlight direction from spherical harmonics functions" Tags="&lt;shader&gt;&lt;spherical-harmonics&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10823" PostTypeId="1" AcceptedAnswerId="10827" CreationDate="2021-04-14T22:49:51.913" Score="0" ViewCount="31" Body="&lt;p&gt;I am trying to model heat diffusion on the surface of a mesh. I annexed the most important bits of theory about this topic as screenshots on the question see the bottom.&lt;/p&gt;&#xA;&lt;p&gt;The crux of the issue is we are solving a linear system &lt;span class=&quot;math-container&quot;&gt;$(M - tL_C)u = \delta_y$&lt;/span&gt;. In this case &lt;span class=&quot;math-container&quot;&gt;$M$&lt;/span&gt; is a diagonal matrix, &lt;span class=&quot;math-container&quot;&gt;$L_C$&lt;/span&gt; is the discrete Laplace operator, &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; is a constant time step equal to some epsilon and &lt;span class=&quot;math-container&quot;&gt;$\delta_y$&lt;/span&gt; is a sparse vector with only one non-zero entry which is equal to 1.&lt;/p&gt;&#xA;&lt;p&gt;My expectation is that, upon solving this system and drawing the resulting vertex distances, I get a fading from white to black starting at the source vertex and slowly fading away as the vertices go away from the source. I am however seeing this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/j22KI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/j22KI.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Which looks like random noise to me, as if I messed up the calculation.&lt;/p&gt;&#xA;&lt;p&gt;I implemented the solver using Eigen, this is the snippet:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Eigen::DiagonalMatrix&amp;lt;float, Eigen::Dynamic&amp;gt; areas(sources.size());&#xA;    Eigen::SparseMatrix&amp;lt;float&amp;gt; laplace_operator(sources.size(), sources.size());&#xA;&#xA;    for(uint i = 0; i &amp;lt; sources.size(); i++)&#xA;        laplace_operator.insert(i, i) = 0;&#xA;&#xA;    areas.setZero();&#xA;&#xA;    for(uint e = 0; e &amp;lt; mesh.Edges().size(); e += 2)&#xA;    {&#xA;        const auto&amp;amp; edge = mesh.Edges()[e];&#xA;        const uint i = edge.Vert().ID();&#xA;        const uint j = edge.Pair().Vert().ID();&#xA;&#xA;        const Eigen::Vector3f e1 = -edge.Next().Dir().normalized();&#xA;        const Eigen::Vector3f e2 = edge.Prev().Dir().normalized();&#xA;&#xA;        const float alpha = acos(e1.dot(e2));&#xA;&#xA;        const Eigen::Vector3f p1 = -edge.Pair().Next().Dir().normalized();&#xA;        const Eigen::Vector3f p2 = edge.Pair().Prev().Dir().normalized();&#xA;&#xA;        const float beta = acos(p1.dot(p2));&#xA;&#xA;        const float laplace_coeff = -0.5f * ((1.f / tan(alpha)) + (1.f / tan(beta)));&#xA;&#xA;        laplace_operator.insert(i, j) = laplace_coeff;&#xA;        laplace_operator.insert(j, i) = laplace_coeff;&#xA;&#xA;        laplace_operator.coeffRef(i, i) -= laplace_coeff;&#xA;        laplace_operator.coeffRef(j, j) -= laplace_coeff;&#xA;    }&#xA;&#xA;    uint count = 0;&#xA;    for(auto&amp;amp; v: mesh.Verts())&#xA;    {&#xA;        std::vector&amp;lt;HMesh&amp;lt;VertexData&amp;gt;::MFace*&amp;gt; faces = v.ContainingFaces();&#xA;        for(auto f: faces)&#xA;        {&#xA;            areas.diagonal()[count] += f-&amp;gt;Area();&#xA;        }&#xA;&#xA;        areas.diagonal()[count] /= 3.f;&#xA;&#xA;        count++;&#xA;    }&#xA;&#xA;    SparseLU&amp;lt;SparseMatrix&amp;lt;float&amp;gt;, COLAMDOrdering&amp;lt;int&amp;gt; &amp;gt; solver;&#xA;&#xA;    const Eigen::SparseMatrix&amp;lt;float&amp;gt; a =&#xA;        Eigen::SparseMatrix&amp;lt;float&amp;gt;(areas) - 0.01 * laplace_operator;&#xA;    solver.analyzePattern(a);&#xA;    solver.factorize(a);&#xA;&#xA;    return solver.solve(sources);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I have checked and &lt;code&gt;sources&lt;/code&gt; is indeed a sparse vector with a singular source vertex set to 1 so the input is correct. The mesh operations that fetch values are very tested and they are returning what is expected, so I know the error is in the logic of this function.&lt;/p&gt;&#xA;&lt;p&gt;I suspect my mistake might be creating the laplace operator, but I am not sure.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/9fusI.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/9fusI.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/WXeUW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/WXeUW.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GE9OR.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GE9OR.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2021-04-15T19:45:29.213" Title="Computing heat diffusion creates weird results" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;mesh&gt;&lt;linear-algebra&gt;" AnswerCount="1" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10824" PostTypeId="1" CreationDate="2021-04-15T09:55:49.457" Score="1" ViewCount="58" Body="&lt;p&gt;beginner here.&lt;/p&gt;&#xA;&lt;p&gt;I am implementing importance sampling for environment maps in Scotty3D, a CMU CS project (but I am not a student).&lt;/p&gt;&#xA;&lt;p&gt;The task can be found &lt;a href=&quot;https://cmu-graphics.github.io/Scotty3D/pathtracer/environment_lighting&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I have a problem with the sample's pdf, it is unusually small and that results in the object being rendered white even if its albedo is not white.&lt;/p&gt;&#xA;&lt;p&gt;Here is how I construct the CDF:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;// Calculate Lsintheta across the image. Accumulate to normalize the pdf to 1 later.&#xA;for (size_t j = 0; j &amp;lt; h; j++) {&#xA;    for (size_t i = 0; i &amp;lt; w; i++) {&#xA;        // 0.5f at the pixel center. Else we never sample top and bottom rows&#xA;        float Lsintheta = image.at(i, j).luma() * sin(PI_F*(j + 0.5f)/h);&#xA;        total += Lsintheta;&#xA;        cdf.push_back(total); // Joint Cdf. P(theta, phi)&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So &lt;code&gt;total&lt;/code&gt; would have all the pixels' luminosities. &lt;code&gt;cdf&lt;/code&gt; would actually be the cumulative luminosity.&lt;/p&gt;&#xA;&lt;p&gt;Next is the sampling and calculating the actual pdf.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;float Xi = RNG::unit(); // [0, 1]&#xA;auto lower = std::lower_bound(cdf.begin(), cdf.end(), Xi*total); // cdf is not normalized yet. Scale the RV&#xA;auto index = std::distance(cdf.begin(), lower);&#xA;out_pdf = *lower;&#xA;if (index &amp;gt; 0) out_pdf -= cdf[index - 1]; // pdf[index] = cdf[index] - cdf[index - 1]&#xA;out_pdf /= total;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;&lt;code&gt;Xi&lt;/code&gt; is a uniformly sampled real number from 0 to 1. Then it is multiplied by the &lt;code&gt;total&lt;/code&gt; luminosity in the image to get the sampled accumulated luminosity. Use &lt;code&gt;std::lower_bound&lt;/code&gt; to get the nearest accumulated luminosity greater than or equal to it. Find the index of this nearest accumulated luminosity using &lt;code&gt;std::distance&lt;/code&gt;. Then minus with the previous accumulated luminosity to get the actual luminosity in this pixel. Divide by &lt;code&gt;total&lt;/code&gt; to get the &lt;code&gt;pdf&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This doesn't work, but if I just do &lt;code&gt;out_pdf = lower/total&lt;/code&gt; it can at least show the right color.&#xA;What am I doing/understanding wrong?&lt;/p&gt;&#xA;" OwnerUserId="16193" LastActivityDate="2021-05-15T11:04:50.407" Title="Environment map importance sampling (beginner)" Tags="&lt;c++&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10825" PostTypeId="2" ParentId="10824" CreationDate="2021-04-15T10:51:05.813" Score="0" Body="&lt;p&gt;From all other implementations I have seen, you generally sample twice, once in the Y dimension to select a row and then once in the X dimension to selct the pixel from this row.&lt;/p&gt;&#xA;&lt;p&gt;I am not sure if this is necissary, maybe you're one dimensional sampling is fine.&lt;/p&gt;&#xA;&lt;p&gt;I think you also need to multiply your pdf so that it is relative to solid angle (so it's total sums to 4pi).&lt;/p&gt;&#xA;&lt;p&gt;You should be able to do this by dividing by (2 * Pi * Pi * sinTheta).&lt;/p&gt;&#xA;&lt;p&gt;PBRT is probably the best textbook to help you. You can find it online here:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;http://www.pbr-book.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://www.pbr-book.org/&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The source code is also available. Here is the code for the environment light:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/lights/infinite.cpp&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/lights/infinite.cpp&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;and the code for the Distribution2D sampler:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/core/sampling.h&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/core/sampling.h&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2021-04-15T10:51:05.813" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10826" PostTypeId="1" CreationDate="2021-04-15T16:05:54.700" Score="1" ViewCount="13" Body="&lt;p&gt;I'm trying to extrude a face from a selected mesh in Babylon.js using the ExtrudeShape but can't figure out why I got flipped faces.&lt;/p&gt;&#xA;&lt;p&gt;The bottom extrusions always comes flipped for a reason I ignore.&lt;/p&gt;&#xA;&lt;p&gt;Since the extrudeShape method only extrudes corresponding to the xy plane, I rotate them and extrudes them but I can't figure why sometimes my normals are wrong&lt;/p&gt;&#xA;&lt;p&gt;Here is &lt;a href=&quot;https://playground.babylonjs.com/#X3UQ4P#19&quot; rel=&quot;nofollow noreferrer&quot;&gt;my code on the Babylon.js playground&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="15211" LastEditorUserId="5778" LastEditDate="2021-04-17T14:37:01.147" LastActivityDate="2021-04-17T14:37:01.147" Title="How to extrude a face from a selected mesh in Babylon,js using the ExtrudeShape method?" Tags="&lt;3d&gt;&lt;computational-geometry&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10827" PostTypeId="2" ParentId="10823" CreationDate="2021-04-15T19:45:29.213" Score="0" Body="&lt;p&gt;I messed up I am doing a double negative and that is causing the problem:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;const float laplace_coeff = -0.5f * ((1.f / tan(alpha)) + (1.f / tan(beta)));&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;This should be positive.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastActivityDate="2021-04-15T19:45:29.213" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10828" PostTypeId="1" CreationDate="2021-04-16T01:58:09.463" Score="0" ViewCount="27" Body="&lt;p&gt;I have been using &amp;quot;Simplification: Quadric Edge Collapse Decimation&amp;quot; for simplifying my meshes to only have ~800 vertices and it has been working with a couple of meshes I tried.&lt;/p&gt;&#xA;&lt;p&gt;However, when I try it for a mesh of a bowl with 20k faces, it totally changes the shape of the mesh. How can I do this in the correct way in MeshLab (or other potential toolsets)? You can download the 3D object here &lt;a href=&quot;https://free3d.com/3d-model/simple-bowl-60681.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://free3d.com/3d-model/simple-bowl-60681.html&lt;/a&gt; and feed its obj file to MeshLab for mesh simplification.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/pswVt.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/pswVt.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/U3LeA.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/U3LeA.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/zmMDr.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/zmMDr.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="6281" LastActivityDate="2021-04-16T01:58:09.463" Title="Quadric Edge Collapse Decimation of an object for reducing number of its vertices damages the original shape of object" Tags="&lt;3d&gt;&lt;mesh&gt;&lt;meshlab&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10829" PostTypeId="1" CreationDate="2021-04-18T20:53:58.537" Score="1" ViewCount="18" Body="&lt;p&gt;I need to rewrite a short utility library, to get it working with the Brave browser (My actual question isn't about brave per se.)&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/vasturiano/canvas-color-tracker&quot; rel=&quot;nofollow noreferrer&quot;&gt;canvas-color-tracker&lt;/a&gt; - &lt;a href=&quot;https://vasturiano.github.io/canvas-color-tracker/example/canvas-medium.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;example of it being used&lt;/a&gt; and &lt;a href=&quot;https://github.com/vasturiano/canvas-color-tracker/blob/master/src/index.js&quot; rel=&quot;nofollow noreferrer&quot;&gt;src/index.js&lt;/a&gt;  is short&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;The HTML canvas is used for mouse over and clicks to determine what object is under the cursor.&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;To use it with circles, you register your circle to get a color, then draw the circle in that color. Then to determine what is under the cursor, you get the color with &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData&quot; rel=&quot;nofollow noreferrer&quot;&gt;getImageData&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The trouble is what to do about anti-aliasing, the browser doesn't allow that to be turned off, and I want to be able to return nothing rather than collide with another uninvolved circle when it's edges blend into another color)&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;&lt;strong&gt;Assuming the anti-aliasing blends linearly&lt;/strong&gt; How to create an ordering of points in 8bit RGB space, such that the minimum number of points are colinear without knowing the final total number of points? &lt;strong&gt;What is a reasonable heuristic for this?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;Addendum, I am doing this because Brave will choose a color channel at random and randomly vary the lowest bit of it - &lt;a href=&quot;https://github.com/brave/brave-browser/issues/9591&quot; rel=&quot;nofollow noreferrer&quot;&gt;bit fiddling&lt;/a&gt; as a privacy feature prevent fingerprinting.&lt;/p&gt;&#xA;&lt;p&gt;I figure that if I improve on the algorithm as well as drop the lowest bits for Brave, the maintainer will be happy to use my version (or I will just use my fork anyway)&lt;/p&gt;&#xA;" OwnerUserId="16209" LastActivityDate="2021-04-18T20:53:58.537" Title="Using the HTML canvas and colors to track objects" Tags="&lt;linear-algebra&gt;&lt;colorspace&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10830" PostTypeId="1" CreationDate="2021-04-19T14:55:06.323" Score="0" ViewCount="23" Body="&lt;p&gt;I'm coding OPENGL with Excel VBA&#xA;I'm using arkham46 package which is really great:&#xA;Découvrez la 3D OpenGL 1.1 en VB6/VBA | arkham46.developpez.com&#xA;I'm not able to display NURBS surfaces, only NURBS curves (but some problems arise also here using homogeneous coordinates, the displayed curves look different)&#xA;It should be a problem with passing vertex arrays from vba to openGL passing through c bindings.&#xA;I've tried different array shapes but none seems to work.&#xA;Someone could help me?&#xA;thanks a lot&lt;/p&gt;&#xA;&lt;p&gt;other objects are perfectly drawn (all graphic primitives, teapots, platonic polyhedra, bezier surface and curves, etc)&#xA;Here is en extract of my code&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;Dim ustride3, vstride3, ustride4, vstride4, uorder3, vorder3, uorder4, vorder4 As Long&#xA;Dim uknotscount, vknotscount, sknotscount As Long&#xA;&#xA;Dim uknots(), vknots() As Single&#xA;Dim controlpoints3(0 To 3, 0 To 3, 0 To 2) As Single&#xA;&#xA;For i = 0 To 3&#xA;    For j = 0 To 3&#xA;        controlpoints3(i, j, 0) = CSng(j) - 1.5&#xA;        controlpoints3(i, j, 1) = Sin(CDbl(j) * 2# * 3.14159265359 / 3#)&#xA;        controlpoints3(i, j, 2) = CSng(i) - 1.5&#xA;    Next&#xA;Next&#xA;&#xA;uknotscount = 8&#xA;ReDim uknots(1 To 8)&#xA;uknots(1) = 0&#xA;uknots(2) = 0&#xA;uknots(3) = 0&#xA;uknots(4) = 0&#xA;uknots(5) = 1&#xA;uknots(6) = 1&#xA;uknots(7) = 1&#xA;uknots(8) = 1&#xA;&#xA;vknotscount = 8&#xA;ReDim vknots(1 To 8)&#xA;vknots(1) = 0&#xA;vknots(2) = 0&#xA;vknots(3) = 0&#xA;vknots(4) = 0&#xA;vknots(5) = 1&#xA;vknots(6) = 1&#xA;vknots(7) = 1&#xA;vknots(8) = 1&#xA;&#xA;uorder3 = 4&#xA;vorder3 = 4&#xA;&#xA;ndim3 = 3&#xA;ustride3 = ndim3 * vorder3&#xA;vstride3 = ndim3&#xA;&#xA;Dim NurbsSurface1, NurbsSurface2, NurbsSurface3, NurbsSurface4, NurbsSurface5, NurbsSurface6, NurbsSurface7 As LongPtr&#xA;&#xA;Select Case isurface&#xA;...&#xA;Case 4&#xA;&#xA;    glColor3f 1#, 1#, 1#&#xA;&#xA;    NurbsSurface4 = gluNewNurbsRenderer&#xA;    gluNurbsProperty NurbsSurface4, GLU_DISPLAY_MODE, GLU_FILL&#xA;    gluBeginSurface (NurbsSurface4)&#xA;    gluNurbsSurface NurbsSurface4, uknotscount, uknots(1), vknotscount, vknots(1), ustride3, vstride3, controlpoints3(0, 0, 0), uorder3, vorder3, GL_MAP2_VERTEX_3&#xA;    gluEndSurface (NurbsSurface4)&#xA;    &#xA;    gluNurbsCallback NurbsSurface4, GLU_ERROR, nurbsError&#xA;    ret = gluErrorString(nurbsError)&#xA;    &#xA;end select&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="16217" LastEditorUserId="482" LastEditDate="2021-04-19T17:08:41.223" LastActivityDate="2021-04-19T17:08:41.223" Title="OPENGL NURBS in VBA" Tags="&lt;opengl&gt;&lt;nurbs&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10831" PostTypeId="1" CreationDate="2021-04-19T15:21:12.197" Score="2" ViewCount="95" Body="&lt;p&gt;I am trying to use constructive solid geometry (CSG) and boolean operators to combine various shapes and get the outer (possibly concave) hull. This seems to work okay when using primitive shapes like cubes and spheres but I cannot figure out how to use other shapes.&lt;/p&gt;&#xA;&lt;p&gt;Can I get a signed distance to a mesh? How would I calculate it?&lt;/p&gt;&#xA;&lt;p&gt;I found &lt;a href=&quot;https://www.iquilezles.org/www/articles/sdfbounding/sdfbounding.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.iquilezles.org/www/articles/sdfbounding/sdfbounding.htm&lt;/a&gt; which seems like it might be what I want, specifically the section where they use an &lt;code&gt;sdMesh&lt;/code&gt; method, but I do not understand where the &lt;code&gt;sdTriangles&lt;/code&gt; method comes from. The only &lt;code&gt;sdTriangle&lt;/code&gt; method that I found is on the 2D Distance Functions page. Do I use that somehow? Will that give a negative number if the point is &amp;quot;behind&amp;quot; the triangle in 3D space (i.e. inside the mesh)?&lt;/p&gt;&#xA;&lt;p&gt;I am working in Unity / C#, but can translate from other languages.&lt;/p&gt;&#xA;" OwnerUserId="12025" LastActivityDate="2021-04-21T13:38:35.433" Title="How can I get a signed distance (SDF) from a mesh?" Tags="&lt;3d&gt;&lt;algorithm&gt;&lt;mesh&gt;&lt;signed-distance-field&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10832" PostTypeId="6" CreationDate="2021-04-19T16:53:25.107" Score="0" Body="&lt;h1&gt;luser droog&lt;/h1&gt;&#xA;&lt;p&gt;Howdy, I've done graphics programming primarily in PostScript, but have also used OpenGL and sdl, as well as raw X11 and xcb.&lt;/p&gt;&#xA;&lt;p&gt;I think the task of moderation in a smaller site like this one will be primarily focused on removing spam, guiding new users concerning SE rules and the community rules, migrating comment discussions to chat, and raising larger issues on meta or with other mods and SE.&lt;/p&gt;&#xA;&lt;p&gt;I try to be patient and fair, never downvote without a comment, and use the bounty mechanism to reward outstanding answers. I've been active on multiple sites for many years, including music, codegolf, and stackoverflow. I'm also active in the [comp.lang.postscript](&lt;a href=&quot;https://groups.google.com/g/comp.lang.postscript&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://groups.google.com/g/comp.lang.postscript&lt;/a&gt;) newsgroup.&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="482" LastEditDate="2021-04-19T16:53:25.107" LastActivityDate="2021-04-19T16:53:25.107" CommentCount="1" CommunityOwnedDate="2021-04-19T16:53:25.107" ContentLicense="CC BY-SA 4.0" />
  <row Id="10833" PostTypeId="2" ParentId="10831" CreationDate="2021-04-19T18:55:26.427" Score="1" Body="&lt;p&gt;Generally it boils down to finding the nearest element. Computing distance to it. Checking the normal to tell if inside or out. There are a number of edge cases. Also you usually compute the &amp;quot;angle weighted psuedonormal&amp;quot; as its called.&lt;/p&gt;&#xA;&lt;p&gt;Here's the usual reference &amp;quot;Signed Distance Computation using the Angle&#xA;Weighted Pseudo-normal&amp;quot; by J. Bærentzen.&lt;/p&gt;&#xA;&lt;p&gt;There are many such libraries with the implementation if you don't want to write it yourself. I personally use &lt;a href=&quot;https://vtk.org/doc/nightly/html/classvtkImplicitPolyDataDistance.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;ImplicitPolyDataDistance&lt;/a&gt; function in VTK. Also a fan of &lt;a href=&quot;https://libigl.github.io/tutorial/#signed-distances&quot; rel=&quot;nofollow noreferrer&quot;&gt;LibIGLs&lt;/a&gt;. But there are many lighter weight ones to do it as well, &lt;a href=&quot;https://github.com/Magnus2/MeshSdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/Magnus2/MeshSdf&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;It's also worth mentioning that you can compute SDFs in other less accurate ways for more performance. Namely, another popular approach is to voxelize/binarize a shape and compute the SDF of the binary image instead. The distances at the boundary of the shape won't be exact but it is a good estimate and often faster.&lt;/p&gt;&#xA;&lt;p&gt;EDIT: Also worth mentioning narrow bands and hierarchical SDFs. Those are very popular as well. Instead of computing SDF values for every element. Say in an image. We can compute SDF values only near the boundary of the shape. With an octree you can compute it at each vertex and interpolate to get inbetween estimates. There are special methods for computing these as well and libraries such as OpenVDB.&lt;/p&gt;&#xA;" OwnerUserId="113" LastActivityDate="2021-04-19T18:55:26.427" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10834" PostTypeId="2" ParentId="10763" CreationDate="2021-04-19T22:13:12.213" Score="1" Body="&lt;p&gt;Welcome to the world of 8-bit graphics!  Other answers here are excellent, and most of what you need to know is described well on &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_correction&quot; rel=&quot;nofollow noreferrer&quot;&gt;Wikipedia&lt;/a&gt; but let me take you on a human-friendly journey of understanding that I wish someone would have taken me on when I was younger.&lt;/p&gt;&#xA;&lt;p&gt;The first realization that you need to make is that a pixel with RGB values 128, 128, 128 isn't &amp;quot;half as bright&amp;quot; as a pixel that is outputting 255, 255, 255 (white).  &lt;strong&gt;It's not even close!&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;You can check this by making a checkerboard image of black and white pixels (which, on average, will be 50% as bright as a white image, by definition) and compare the brightness of that to a swatch of 128, 128, 128.  You'll find the swatch is much too dark.  A value that is closest to 50% is actually somewhere between 188 and 189 but also depends on your display.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KXT20.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KXT20.png&quot; alt=&quot;a test pattern that reveals the gamma issue&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;It's very important to look at this picture with 1:1 scaling.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;If you can &amp;quot;get&amp;quot; this (notice the effect) then you are ready to begin understanding why the 128, 128, 128 swatch seems too dark.&lt;/p&gt;&#xA;&lt;p&gt;Most software developers discover this property by accident. If you just perform arithmetic on RGB color values in the intuitive (but naïve) way, like for example to compute an average color of two pixels as in &lt;code&gt;(a+b)/2&lt;/code&gt;, you'll find that it doesn't work.  Things look too dark.  :( In fact, you can completely finish that awesome first-person shooter 3D engine you've always aspired to create, only to discover that all your graphics look too dark and shadowy.&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;&lt;strong&gt;This is because the RGB codes do not correspond to brightness levels in a linear way.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;RGB codes are non-linear.  You should have the moment of realization where you ask yourself, &amp;quot;but wait, &lt;code&gt;(a+b)/2&lt;/code&gt; is the formula for &lt;em&gt;average&lt;/em&gt;, so why doesn't it produce an &lt;em&gt;average&lt;/em&gt; color?&amp;quot;  Or maybe it will occur to you by asking &amp;quot;Why, when I compute (0+255)/2 and get 128 (rounding up of course) do I not get a color that is half as bright as white?&amp;quot;&lt;/p&gt;&#xA;&lt;p&gt;Once you get that feeling where it &lt;em&gt;&lt;strong&gt;seems like arithmetic is broken&lt;/strong&gt;&lt;/em&gt;, you'll be ready to understand that the encoding used for all pictures in typical image files are actually encoded in a &lt;strong&gt;non-linear color space&lt;/strong&gt; such as sRGB.  To do arithmetic on colors correctly you must:&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;convert the non-linear RGB color codes to a linear color space&lt;/li&gt;&#xA;&lt;li&gt;&lt;em&gt;then&lt;/em&gt; you can do normal arithmetic, like computing averages or whatever&lt;/li&gt;&#xA;&lt;li&gt;then you must finally convert the result back to the original non-linear RGB encoding to be displayed by your display device or stored in your image file or texture or whatever.&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;Ever notice how it's easy to tell the difference between 1 pound and 2 pounds, but it's hard to tell the difference between having 101 pounds and 102 pounds?  They're both different by 1 pound, but the &lt;strong&gt;relative&lt;/strong&gt; difference is twice as heavy for the small weights, but 102 is barely a 1% relative increase from 101 -- very difficult to notice.&lt;/p&gt;&#xA;&lt;p&gt;Well your eyes work the same way with light!  It's very easy to tell the difference (in a room with no other light sources) between the brightness from 1 light bulb vs the light from 2 light bulbs. But it's much harder to tell the difference in brightness between 101 light bulbs and 102 light bulbs.&lt;/p&gt;&#xA;&lt;p&gt;Here's where engineers got clever with 8-bit graphics...&lt;/p&gt;&#xA;&lt;p&gt;Since, with 8-bit graphics, we only have 256 different codes we can store, why waste so many of those different codes on intensities people can't even tell apart?  Instead, the designers choose 256 different codes where each successive code is an equal relative increase in brightness compared to the previous code.  All codes are equally useful, and it's much more efficient, right?&lt;/p&gt;&#xA;&lt;p&gt;If you want to get a tiny bit mathematical now, it means that the intensity of light you get from using intensity &lt;code&gt;n+1&lt;/code&gt; divided by the intensity of light you get from using an intensity of &lt;code&gt;n&lt;/code&gt; is a &lt;strong&gt;constant&lt;/strong&gt;.  (obviously something special happens for 0.  &lt;em&gt;Any&lt;/em&gt; amount of light will always be &lt;em&gt;infinitely&lt;/em&gt; brighter than no light, relatively speaking).&lt;/p&gt;&#xA;&lt;p&gt;And now that we have our toe dipped into the waters of the mathematical ocean, you're finally ready to at least get a hint of what the word &lt;strong&gt;gamma&lt;/strong&gt; means.&lt;/p&gt;&#xA;&lt;p&gt;The actual term &lt;strong&gt;gamma&lt;/strong&gt; refers to the &lt;strong&gt;gamma function&lt;/strong&gt;, which is a function with that nifty property where &lt;code&gt;f(x+1) = k * f(x)&lt;/code&gt;.  To get from an intensity to a code you first raise the linear intensity (a number between 0 and 1) to the power of 2.2, which will also be a number between 0 and 1, then spread that range out over the 256 code values available to you.  To perform the reverse conversion, you first convert your RGB coded number between 0 to 255 to a number between 0 and 1, and then &amp;quot;undo&amp;quot; the gamma function by raising it to the power of 1/2.2 to arrive at a linear intensity between 0.0 and 1.0.  Historically the exponent 2.2 was chosen because it coincidentally matches some properties of old CRT monitors (the ratio of power of the electron beam to intensity of the light produced is similarly non-linear).&lt;/p&gt;&#xA;&lt;p&gt;In practice the internet actually uses a slightly smarter color space called &lt;em&gt;sRGB&lt;/em&gt;.  It's still a non-linear function and it's very close to gamma 2.2, but has some nice properties where there aren't so many really dark values in the low end -- again, trying to make more efficient use of the 256 levels of intensity available to us in 8-bit graphics.&lt;/p&gt;&#xA;&lt;p&gt;So let's circle back to your actual question:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;return float3(pow(color.r, 2.2), pow(color.g, 2.2), pow(color.b, 2.2));&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is &lt;strong&gt;half&lt;/strong&gt; of a color conversion.  It is assuming that we have linear intensity values stored in &lt;code&gt;color&lt;/code&gt; and it is applying the gamma function (raising it to the power of 2.2) to get closer to the Normalized (0.0 to 1.0) encoded values that are suitable for putting into a picture file or displaying on the screen.  OpenGL will unnormalize these values and write a corresponding 8-bit integer representation of that value in the range 0-255.&lt;/p&gt;&#xA;&lt;p&gt;This works great for what I would call &amp;quot;synthetic&amp;quot; colors.  Like if you are simulating some light source or the attenuation from angle of incidence or something.  But if you were reading values from an image file, then you would furthermore need to use a sampler that performed the inverse of this correction.  It's important to get the sampler to do it because there's hardware built in to your GPU to do things like bi-linear interpolation (sample 4 pixels and compute an intermediate value).  Without activating that inverse correction factor, you are at risk of doing the &lt;em&gt;broken arithmetic&lt;/em&gt; on your color values and textures get weird artifacts in them caused by introducing colors that are too dark.&lt;/p&gt;&#xA;&lt;p&gt;Here's an example of reducing that previous image in size ever so slightly using an &lt;strong&gt;incorrect&lt;/strong&gt; technique - that is quite frankly found everywhere in the world even though it's wrong.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/Y00Ah.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/Y00Ah.png&quot; alt=&quot;Incorrectly scaled image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;em&gt;This image was rescaled naïvely without gamma correction and will look bad, with artifacts that are too dark.&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;So the next generation of graphics developers all have a responsibility to learn the basics so that we don't get dark looking graphics everywhere that are filled with artifacts.  My personal pet peeve is sci-fi movies where the stars in the black sky throb bright and dark as the camera pans slowly because the people that rendered it didn't get the gamma conversions correct!&lt;/p&gt;&#xA;&lt;p&gt;I hope this helps.  I need to give a disclaimer:  I've intentionally used some terms incorrectly like &lt;em&gt;brightness&lt;/em&gt; and &lt;em&gt;intensity&lt;/em&gt; (just think &amp;quot;shades of gray&amp;quot;) because you need to begin your journey with familiar language -- then learn the scientifically correct terms later where you will learn about things like &lt;em&gt;luma&lt;/em&gt;, &lt;em&gt;luminosity&lt;/em&gt;, &lt;em&gt;luminous intensity&lt;/em&gt;, &lt;em&gt;brightness&lt;/em&gt;, &lt;em&gt;perceived brightness&lt;/em&gt;, etc. etc.  After you get the terminology right, the next dragon you face is named &lt;strong&gt;color&lt;/strong&gt;.  Color is hard to get right and human perception makes it especially complex.  I've only scratched the surface here.&lt;/p&gt;&#xA;" OwnerUserId="8009" LastEditorUserId="8009" LastEditDate="2021-04-20T14:19:39.597" LastActivityDate="2021-04-20T14:19:39.597" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10835" PostTypeId="1" AcceptedAnswerId="10836" CreationDate="2021-04-21T08:35:49.247" Score="0" ViewCount="41" Body="&lt;p&gt;First of all I have to say that I am really new in the world of Computer Graphics. I apologise if some of my questions may appear trivial.&#xA;I am currently using a non-commercial ray tracing and physically based rendering software. I didn't have any problems with this until now : I have a scene where an .obj file representing a satellite is placed surrounded by a environment map light.&#xA;Here is an exemple of my problem appearing on the solar pannels :&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KTHlk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KTHlk.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I have no idea where these strange forms could come from. I have to say that for this picture, the .obj file representating the solar pannel is a very simple parallelepiped. I also tried to suppress the other face of the object but nothing changed.&lt;/p&gt;&#xA;&lt;p&gt;I saw this exchange (&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2192/cause-of-shadow-acne&quot;&gt;Cause of shadow acne&lt;/a&gt;) that could maybe be related to my problem, but if someone has an idea of what could be the cause, I would be happy to hear it!&lt;/p&gt;&#xA;&lt;p&gt;Thank you to all and have a nice day.&lt;/p&gt;&#xA;" OwnerUserId="16224" LastEditorUserId="16224" LastEditDate="2021-04-21T09:38:30.913" LastActivityDate="2021-04-21T09:38:30.913" Title="What can be the cause of some strange ray shadows artefacts on a perfectly flat surface?" Tags="&lt;raytracing&gt;&lt;shadow&gt;&lt;artifacts&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10836" PostTypeId="2" ParentId="10835" CreationDate="2021-04-21T09:37:28.503" Score="1" Body="&lt;p&gt;It appeared that it was exactly the problem explained in the link of my original post (&lt;a href=&quot;https://computergraphics.stackexchange.com/questions/2192/cause-of-shadow-acne&quot;&gt;Cause of shadow acne&lt;/a&gt;).&#xA;The shadow function offset has been increased and the problem is solved!&lt;/p&gt;&#xA;" OwnerUserId="16224" LastActivityDate="2021-04-21T09:37:28.503" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10837" PostTypeId="2" ParentId="10831" CreationDate="2021-04-21T13:38:35.433" Score="0" Body="&lt;p&gt;What you want is a Distance Transform algorithm which can be computed very fast using &lt;a href=&quot;http://www.comp.nus.edu.sg/%7Etants/jfa/i3d06.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;JFA&lt;/a&gt;, the steps are basically:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;p&gt;Define where you want your seeds (I guess points that make up your mesh.&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;li&gt;&lt;p&gt;At each log iteration find wether or not the current position is better than the last one, if it is add it to a texture (3d in this case).&lt;/p&gt;&#xA;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Not sure of the details but in this video &lt;a href=&quot;https://youtu.be/GvI7qt3kmz4&quot; rel=&quot;nofollow noreferrer&quot;&gt;Ryan Brucks&lt;/a&gt; shows the Distance Field of a mesh computed by JFA using (a compute shader I guess?) on UE4.&lt;/p&gt;&#xA;&lt;p&gt;Also check &lt;a href=&quot;https://blog.demofox.org/2016/02/29/fast-voronoi-diagrams-and-distance-dield-textures-on-the-gpu-with-the-jump-flooding-algorithm/&quot; rel=&quot;nofollow noreferrer&quot;&gt;this link by Alan Wolfe&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="9749" LastActivityDate="2021-04-21T13:38:35.433" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10838" PostTypeId="5" CreationDate="2021-04-21T13:44:19.387" Score="0" Body="" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2021-04-21T13:44:19.387" LastActivityDate="2021-04-21T13:44:19.387" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10839" PostTypeId="4" CreationDate="2021-04-21T13:44:19.387" Score="0" Body="An SDF is a function which takes a position as an input, and outputs the distance from that position to the nearest part of a shape." OwnerUserId="38" LastEditorUserId="38" LastEditDate="2021-04-21T13:44:19.387" LastActivityDate="2021-04-21T13:44:19.387" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10840" PostTypeId="5" CreationDate="2021-04-21T13:46:52.047" Score="0" Body="" OwnerUserId="38" LastEditorUserId="38" LastEditDate="2021-04-21T13:46:52.047" LastActivityDate="2021-04-21T13:46:52.047" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10841" PostTypeId="4" CreationDate="2021-04-21T13:46:52.047" Score="0" Body="NonUniform B-Spline (NURBS) is a method to describe parametric curves/surfece. TYpically used as base poriniteves in CAD modelling." OwnerUserId="38" LastEditorUserId="38" LastEditDate="2021-04-21T13:46:52.047" LastActivityDate="2021-04-21T13:46:52.047" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10843" PostTypeId="1" CreationDate="2021-04-23T21:44:18.240" Score="0" ViewCount="24" Body="&lt;p&gt;The video of an NFT at the link below was shot with an analogue thermal imager camera, whatever that is.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://foundation.app/bo/degrees-of-love-analogue-thermal-imaging-27898&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://foundation.app/bo/degrees-of-love-analogue-thermal-imaging-27898&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;How can the same effect, and in which software, can this be achieved if starting from a regular video recording, in post editing?&lt;/p&gt;&#xA;" OwnerUserId="15860" LastActivityDate="2021-04-23T21:44:18.240" Title="Thermal imaging a normal video" Tags="&lt;video&gt;" AnswerCount="0" CommentCount="3" ContentLicense="CC BY-SA 4.0" />
  <row Id="10844" PostTypeId="1" CreationDate="2021-04-24T17:49:38.940" Score="2" ViewCount="67" Body="&lt;p&gt;I am implementing a pathtracer with both indirect and direct light sampling at each intersection (I believe the &amp;quot;direct light sampling&amp;quot; part is also referred to as &amp;quot;next event estimation&amp;quot;). I am trying to compute both direct-diffuse and direct-specular contributions of the light sources.&lt;/p&gt;&#xA;&lt;p&gt;For that, I use a normalized Phong BRDF (formula taken from &lt;a href=&quot;http://www.farbrausch.de/%7Efg/stuff/phong.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;), in which the contribution of each light source at an intersection is defined as (pseudo-code) :&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;directLighting = diffuse() + specular() / (intersection.location - light.location).lengthSquared();&#xA;&#xA;&#xA;diffuse() {&#xA;    normalization = 1.0f / PI;&#xA;    return material.metal ? Color::BLACK :&#xA;                            lightDotN * lightIntensity * lightColor * material.albedo * normalization;&#xA;}&#xA;&#xA;&#xA;specular() {&#xA;    if (observerDotReflected &amp;lt;= 0.0f) {&#xA;        return Color::BLACK;&#xA;    }&#xA;&#xA;    normalization = (material.smoothness + 1.0f) / (2.0f * PI);&#xA;    return (observerDotReflected ^ material.smoothness) * lightIntensity * lightColor *&#xA;           (material.metal ? material.albedo : material.specularity) * normalization;&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This works well as long as I have pretty rough objects in my scene (below, a rough metallic sphere with &lt;code&gt;smoothness = 25.0f&lt;/code&gt;, and a rough diffuse sphere with &lt;code&gt;smoothness = 2.0f&lt;/code&gt;).&#xA;&lt;a href=&quot;https://i.stack.imgur.com/N4S8X.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/N4S8X.png&quot; alt=&quot;clean&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However, as soon as I introduce a very smooth and reflective object (below, a metallic sphere with &lt;code&gt;smoothness = 10'000.0f&lt;/code&gt;), two problems appear : the specular lobe on the sphere is very ugly (we can see the individual points that resulted in non-zero specular contribution), and hot pixels/fireflies appear everywhere in the scene.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/ojuqM.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ojuqM.png&quot; alt=&quot;fireflies&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;I think I understand why these exist : when the smoothness is high, the specular Phong BRDF returns ~0 almost all the time (when &lt;code&gt;observerDotReflected&lt;/code&gt; is not very close to 1), but sometimes returns extremely bright values, which cause fireflies at other points in the scene when they are the result of an indirect bounce.&lt;/p&gt;&#xA;&lt;p&gt;Note that the same effect appears whether I use point lights, or sphere lights (with a non-zero volume that I randomly sample).&lt;/p&gt;&#xA;&lt;p&gt;Is there a conventional way to solve this problem ? I have seen &lt;a href=&quot;https://computergraphics.stackexchange.com/a/5153/16243&quot;&gt;this answer&lt;/a&gt; where the author indicates that for mirror-like specular surfaces (i.e. smoothness -&amp;gt; infinity), you should not directly sample specular lighting, but rather rely on indirect bounces intersecting light objects. Is this the only way to go about direct specular lighting ? Are there other solutions to this variance problem ?&lt;/p&gt;&#xA;" OwnerUserId="16243" LastActivityDate="2021-04-24T17:49:38.940" Title="Path tracing : fireflies/hot pixels when directly sampling lights" Tags="&lt;raytracing&gt;&lt;pathtracing&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10845" PostTypeId="1" CreationDate="2021-04-25T18:18:53.747" Score="2" ViewCount="68" Body="&lt;p&gt;I'm a super beginner to GFX. So far I've learned about 3 shading models when rendering meshes&#xA;The first is &lt;strong&gt;Flat Shading&lt;/strong&gt;. I seem to understand this, from my understanding, you take the normal of the face/polygon, apply your lighting model based on that, and the light angle, and other parameters and based on what you get, shade your polygon with  a single color, done.&lt;/p&gt;&#xA;&lt;p&gt;I've learned about Phong Shading as well. Apparently Phong Shading takes the normals of the vertices of the polygon, and interpolates them for each pixel, thus sort of 'creating' a normal per every pixel, and shade accordingly. It is shaded per pixel, and as such you get smooth results&lt;/p&gt;&#xA;&lt;p&gt;Gouraud shading is what I am most confused by. I referred to many online sources including this &lt;a href=&quot;https://www.javatpoint.com/computer-graphics-gouraud-shading&quot; rel=&quot;nofollow noreferrer&quot;&gt;one&lt;/a&gt; and what I dont understand is how exactly the polygon is shaded? Is it shaded per pixel?&lt;/p&gt;&#xA;&lt;p&gt;From my understanding, Gouraud is the same as Phong shading except that unlike Phong interpolating vertex normals, and creates normals  for every pixel and shading each pixel, Gouraud interpolates just the vertex normals of the polygon.&lt;/p&gt;&#xA;&lt;p&gt;Im not quite sure what it does after that. Does it take these interpolated vertex normals and shade the polygon in a single color? Does it shade pixel by pixel just like Phong?&lt;/p&gt;&#xA;" OwnerUserId="15772" LastActivityDate="2021-04-25T21:39:53.277" Title="How exactly does Gouraud shading apply color across a polygon? Does it do it by pixel or is it some other method?" Tags="&lt;shading&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10846" PostTypeId="2" ParentId="10845" CreationDate="2021-04-25T19:15:57.837" Score="2" Body="&lt;p&gt;The difference is in the number of lighting calculations done. Where the lighting calculation produces some color.&lt;/p&gt;&#xA;&lt;p&gt;Flat does one per face, uses the color across the face.&lt;/p&gt;&#xA;&lt;p&gt;Gourand does 3 (for a triangle, one for each vertex), interpolates the color across the face.&lt;/p&gt;&#xA;&lt;p&gt;Phong does a light calculation for every pixel/fragment (where the normal is interpolated across the face).&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/fyAFK.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/fyAFK.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="113" LastEditorUserId="113" LastEditDate="2021-04-25T21:39:53.277" LastActivityDate="2021-04-25T21:39:53.277" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10847" PostTypeId="2" ParentId="10763" CreationDate="2021-04-26T09:50:36.643" Score="0" Body="&lt;p&gt;Beside, note that the pow 2.2 is for &lt;em&gt;decoding&lt;/em&gt; some sRGB encoded texture.&#xA;The final encoding to sRGB at the end of shader would be pow 1./2.2 .&lt;/p&gt;&#xA;&lt;p&gt;Also, note that gamma correction is an approximation of the sRGB correction.&#xA;But in practice even doing square and sqrt instead is quite good (and cheaper than pow ) ;-)&lt;/p&gt;&#xA;" OwnerUserId="1810" LastActivityDate="2021-04-26T09:50:36.643" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10848" PostTypeId="1" AcceptedAnswerId="10884" CreationDate="2021-04-26T13:16:09.510" Score="1" ViewCount="95" Body="&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/rOJfe.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rOJfe.png&quot; alt=&quot;The parameters of the rational Bezier curve have been converted into a discrete representation of points using this formula.&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Where P is the control point, w is weight.&lt;/p&gt;&#xA;&lt;p&gt;I plan to extrude this 2d representation into 3d. I have a discrete 2D representation (array which has [n_points, 2, 1] for each sample) of an airfoil that has to be extruded to form a wing along the z axis which has parameters like Span and variation on chord length. In theory, this seems easy, however, in code, I can't find any basis on how to implement it.&lt;/p&gt;&#xA;&lt;p&gt;I have not found anything regarding this which doesn't use high utility libraries. Any leads or explanations will be highly appreciated.&lt;/p&gt;&#xA;" OwnerUserId="16253" LastEditorUserId="16253" LastEditDate="2021-04-27T17:02:49.967" LastActivityDate="2021-05-12T07:36:11.637" Title="How do I extrude a 2D Bezier curve representation into a 3D solid using Python?" Tags="&lt;3d&gt;&lt;2d&gt;&lt;bezier-curve&gt;&lt;parametrization&gt;" AnswerCount="1" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10849" PostTypeId="1" CreationDate="2021-04-27T22:09:52.703" Score="0" ViewCount="48" Body="&lt;p&gt;I apologize in advance for this question asking for a recommendation, but I'm not so advanced in CG to research this topic myself.&lt;/p&gt;&#xA;&lt;h3&gt;Basic problem&lt;/h3&gt;&#xA;&lt;p&gt;I'm looking for a most suitable approach to render a point cloud from two RGB and depth pictures (they're already reprojected, only need to scale pixel coordinates into world coordinates and concatenate corresponding &lt;code&gt;(x,y)&lt;/code&gt; from RGB and &lt;code&gt;z&lt;/code&gt; from depth into an array of (hopefully) vertices with world position and color information. There are about 3 million pixels, thus 3 million vertices potentially&lt;/p&gt;&#xA;&lt;h3&gt;More complicated problem&lt;/h3&gt;&#xA;&lt;p&gt;The major complication is that RGB and depth are actually &lt;em&gt;streams&lt;/em&gt; of images at 60 FPS and I would need to build the point cloud from them with preferably the same framerate. By the nature of the data and application there's little to no occlusion between points happening, the majority of the points remain in observer's view (point cloud shows a person) and the observer doesn't move/rotate much relative to the point cloud&lt;/p&gt;&#xA;&lt;p&gt;The lesser yet existent complication is that the application is meant to render into a mobile GPU based VR headset (Oculus Quest 2, with Adreno 650 GPU on board), so computing resources are limited and GPU is probably tile-based and has worse performance as such.&lt;/p&gt;&#xA;&lt;h3&gt;What I think so far&lt;/h3&gt;&#xA;&lt;p&gt;To begin with, I'm not sure where to place logic of point cloud construction. Whether it should be done on CPU on each frame and then vertex data sent to a GPU's shader/compute shader, or I can stream images directly to GPU and build and render the point cloud from there. Which one seems more feasible for real-time updates?&lt;/p&gt;&#xA;&lt;p&gt;Secondly, what kind of GPU programming (shaders) worth trying to involve? Vertex/fragment/compute shaders? I've heard conflicting opinions that either can be faster, but I've seen some scientific papers featuring fast compute shaders for massive (yet not dynamic) point clouds. E.g. &lt;a href=&quot;https://github.com/m-schuetz/compute_rasterizer&quot; rel=&quot;nofollow noreferrer&quot;&gt;this paper and repo&lt;/a&gt;. It's also unclear how it should be rendered, like using a buffer and &lt;code&gt;GL_POINTS&lt;/code&gt; or some custom rasterization. What do you think would work for me?&lt;/p&gt;&#xA;&lt;p&gt;Thank you for your time!&lt;/p&gt;&#xA;" OwnerUserId="16264" LastActivityDate="2021-04-27T22:09:52.703" Title="Constructing relatively big point clouds from two images" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10850" PostTypeId="1" AcceptedAnswerId="10851" CreationDate="2021-04-28T08:13:45.360" Score="0" ViewCount="34" Body="&lt;p&gt;I have a mesh, each face (triangle) of the mesh needs to read some information out of a SSBO object.&#xA;Is there a way to read out a block (lets say 100 floats) at once? Or do I need to iterate over the 100 floats? The number of floats is not fixed. They vary for each triangle.&#xA;During this stage the 100 floats are not changing at all... So to iterate over them would make no change in the logic. But I think it takes to mush time to read them after each other.&lt;/p&gt;&#xA;&lt;p&gt;I also have a second question:&#xA;when reading lets say 128 floats from SSBO iteratively does it takes longer than reading 32 vec4 iteratively? in principle both is the same (128 floats)&lt;/p&gt;&#xA;" OwnerUserId="13273" LastActivityDate="2021-04-28T11:44:45.300" Title="SSBO get block of data instead of iterating" Tags="&lt;glsl&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10851" PostTypeId="2" ParentId="10850" CreationDate="2021-04-28T11:44:45.300" Score="1" Body="&lt;p&gt;yes, and no. Loading the floats into the SSBO &lt;em&gt;is&lt;/em&gt; loading them for the shader so yes you still have to iterate over them. And GPU's generally are good at latency hiding so whether or not you read floats or vec4's the GPU should be able to read them in just as fast. But processing them as vec4's instead of 1 float at a time &lt;em&gt;will&lt;/em&gt; be faster since the code is taking advantage of the GPU's vector processing.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-04-28T11:44:45.300" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10852" PostTypeId="1" CreationDate="2021-04-28T17:01:37.633" Score="0" ViewCount="50" Body="&lt;p&gt;I have the impression that there is a problem with anti-aliasing in a 2D GUI framework using opengl. To demonstrate the problem I made a program that draws gray ramps. The result is shown below.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/u63fw.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/u63fw.png&quot; alt=&quot;anti-aliasing rendering test&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The top and bottom gray ramps are identical and considered the reference ramps. It is a copy from &lt;a href=&quot;https://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/&quot; rel=&quot;nofollow noreferrer&quot;&gt;&amp;quot;What every coder should know about gamma&amp;quot;&lt;/a&gt;. This is what I currently assume that we should see when gray colors are correctly encoded. There seam to be a rounding error in this ramp, so an exact match is not required. The right most rectangle is not perfectly white.&lt;/p&gt;&#xA;&lt;p&gt;The second gray ramp counting from the top is produced by drawing each rectangle as a stack of black lines not thicker than a pixel on a white background. The thickness of the lines reduces linearly as we go from black to white. The gray color result thus purely from anti-aliasing.&lt;/p&gt;&#xA;&lt;p&gt;The third gray ramp is simply a sequence of rectangles filled with linearly increasing gray values.&lt;/p&gt;&#xA;&lt;p&gt;I was expecting that all gray ramps would look identical, but clearly the second gray ramp is not. It seam that a gamma correction has been applied to it while I think it should not.&lt;/p&gt;&#xA;&lt;p&gt;It generates artifacts which are strongly visible in font rendering as shown below.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qi77z.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qi77z.png&quot; alt=&quot;This is a test comparison&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The text &lt;em&gt;a&lt;/em&gt; has been produced with the library in question, and the text &lt;em&gt;b&lt;/em&gt; has been produced with another font rendering library.&lt;/p&gt;&#xA;&lt;p&gt;Another test I did to put in evidence the artifacts resulting from the anti-aliasing color processing is to draw slightly slanted lines.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GeVh5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GeVh5.png&quot; alt=&quot;slightly slanted lines&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The lines above are produced by the library in question and the lines below by another library. The thickness of the lines below look more uniform. The lines above look wrong and distorted.&lt;/p&gt;&#xA;&lt;p&gt;The author of the 2D graphic library claims that his color processing with anti-aliasing and filled rectangle is correct.&lt;/p&gt;&#xA;&lt;p&gt;Who is right ? What argument could I use to resolve this disagreement ?&lt;/p&gt;&#xA;&lt;p&gt;The more I work on this subject, the more I get confused. For instance, by using a color picker I see that the color in the center of the ramp of the reference image is close to 0x7F. Is the color picker giving the color in linear space or the &lt;a href=&quot;https://medium.com/game-dev-daily/the-srgb-learning-curve-773b7f68cf7a&quot; rel=&quot;nofollow noreferrer&quot;&gt;sRGB color value&lt;/a&gt; ? The screen color picker is Gpick (Gnome Linux).&lt;/p&gt;&#xA;&lt;p&gt;I know that we should work in linear color space when performing operations on images. What is unclear is what am I looking at ? The color values I gave to rectangles where linear, not sRGB, or not gamma corrected. The color ramp I see seam linear. The values given by the color picker seam to match the linear value I gave.&lt;/p&gt;&#xA;" OwnerUserId="16019" LastActivityDate="2021-04-30T17:11:16.833" Title="Is anti-aliasing color processing correct in this image?" Tags="&lt;antialiasing&gt;&lt;gamma&gt;" AnswerCount="1" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10853" PostTypeId="1" CreationDate="2021-04-29T00:35:53.440" Score="0" ViewCount="38" Body="&lt;p&gt;I'm working on a scientific visualization project and need to create a transfer function widget. The volume data is either in range &lt;code&gt;0-255&lt;/code&gt; or it can be 16 bit i.e. &lt;code&gt;0-65535&lt;/code&gt;. Now the main problem is in order to color certain sections, the user needs to be able to define certain control points with varying colors and the colors need to be smoothly transitioned between those control points. Then during rendering, we find the color for every isovalue through a texture lookup in a ramp texture and color the volume data.&lt;/p&gt;&#xA;&lt;p&gt;I've decided to do cubic spline interpolation between these control points. My question is, how do I actually render and store this gradient in an Nx1 ramp texture. Firstly, regarding the rendering part. I'm using OpenGL but also Dear-ImGui for GUI. So I don't have low level access to rendering like vertex/fragment shader for rendering this gradient. Just low level functions like rendering lines/rectangles etc.&lt;/p&gt;&#xA;&lt;p&gt;For 8 bit volumes, I could render 256 lines of thickness &lt;code&gt;gradient_width_in_pixels/256&lt;/code&gt;. I think this would give me the look of a rectangular gradient? However suppose I have a 16 bit volume. The max value now is 65k. I could go on and convert it to &lt;code&gt;0-255&lt;/code&gt; but let's say I don't because there would be a loss of precision as in the &lt;code&gt;0-255&lt;/code&gt; scale 1 value represents approximately 256 values of &lt;code&gt;0-65535&lt;/code&gt; scale. What if the user wanted to color within that range? &lt;em&gt;&lt;strong&gt;What's the proper way to handle this scenario now?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;&#xA;&lt;p&gt;Secondly, regarding storing the gradient information. For 8bit datasets, again it'd seem pretty simple to just create an &lt;code&gt;256x1&lt;/code&gt; texture. However the problem again rises for 16 bit datasets. 65k pixels don't sound good or are they okay? I know &lt;code&gt;65k x 1&lt;/code&gt; texture is just a &lt;code&gt;256x256&lt;/code&gt; texture but dunno if increasing only 1 dimension will cause problems.&lt;/p&gt;&#xA;&lt;p&gt;EDIT: I thought I should clarify regarding rendering the gradient part and ask the question differently. What I wanna know is given a color control point at pixel coord (x1,y) and another point at (x2, y), how many lines of any thickness should I render to get a color gradient with smooth transition between those two colors?&lt;/p&gt;&#xA;" OwnerUserId="6046" LastEditorUserId="6046" LastEditDate="2021-05-05T05:29:22.697" LastActivityDate="2021-05-05T05:29:22.697" Title="How to render and store a color gradient in a ramp texture for 16bit dataset?" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;volume-rendering&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10854" PostTypeId="2" ParentId="10853" CreationDate="2021-04-29T12:49:26.853" Score="0" Body="&lt;p&gt;It may be easier to compute the gradient on the CPU, even with 16bit precision the CPU can grind out a texture quickly. Then just upload that to the GPU as an image. Also, it doesn't sound like users will be able to pick a new color set every frame so its sounds a lot more natural to have a work flow of: Pick colors -&amp;gt; Generate Image -&amp;gt; upload to the GPU -&amp;gt; use new palette to render.&lt;/p&gt;&#xA;&lt;p&gt;Are the picked colors RGB choices? If yes then it does make sense to spread the color palette out as wide as possible (maybe even more then 16bits) 65536 pixels is just a drop in the bucket. And a nice wide color range could lead to less banding in the final image.&lt;/p&gt;&#xA;&lt;p&gt;At some  level the code will have to narrow the range down to whatever the current precision is. If that is the table, and the table has 65536 positions, then the table might contain a lot of repeating colors, but it is easy to compute the table with a new range.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-04-29T12:49:26.853" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10855" PostTypeId="1" CreationDate="2021-04-30T12:52:42.933" Score="1" ViewCount="42" Body="&lt;p&gt;I have a QOpenGLWidget where I use camera transformation matrix(4,4), FOV and vectors Position(4), Up(4), Forward(4). I also have an ArcBall which I can use. I managed to implement zoom and pan by modifying the Position vector. Now I want to implement rotation with arcball.&lt;/p&gt;&#xA;&lt;p&gt;On mouseMove I compute the rotation matrix with arcball. Then I need to use this matrix for rotating the camera. Now how do I do that?&lt;/p&gt;&#xA;&lt;p&gt;I tried multiplying or summing the camera matrix and arcball matrix but it is not working for me.&lt;/p&gt;&#xA;" OwnerUserId="16273" LastEditorUserId="16273" LastEditDate="2021-05-03T08:16:35.350" LastActivityDate="2021-05-06T16:43:41.407" Title="How to use trackball for rotating an camera matrix in eye frame" Tags="&lt;opengl&gt;&lt;transformations&gt;&lt;c++&gt;&lt;camera&gt;&lt;camera-matrix&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10856" PostTypeId="1" CreationDate="2021-04-30T15:01:18.250" Score="0" ViewCount="44" Body="&lt;p&gt;This isn't coming from graphics but more from some simple synthetic data generation problem but I have a hunch there are tricks from landscape generation to use here.&lt;/p&gt;&#xA;&lt;p&gt;Consider the line (1d) for simplicity. I want to generate random points on the line in some interval of interest. But then I want to also be able to generate those points in another interval and when I &amp;quot;grow&amp;quot; the interval, the generation should be consistent. For example, if I generate exponential intervals I have a kind of Poisson random measure.&lt;/p&gt;&#xA;&lt;p&gt;But how can I do this efficiently without just hard-coded some &amp;quot;origina&amp;quot; and simulating from there? I can pick a coarse grid I suppose and do some messing around but keeping the distribution consistent is tricky.&lt;/p&gt;&#xA;&lt;p&gt;I am interested in tricks that just work and also anything that actually guarantees the correct simulating distribution (whatever we were using to generate the sequences).&lt;/p&gt;&#xA;" OwnerUserId="16274" LastEditorUserId="7952" LastEditDate="2021-05-06T12:53:08.790" LastActivityDate="2021-05-06T12:53:08.790" Title="Efficiently generating consistent procedural sequences from random seed and a start point?" Tags="&lt;procedural-generation&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10857" PostTypeId="2" ParentId="10852" CreationDate="2021-04-30T17:11:16.833" Score="0" Body="&lt;p&gt;The anti-aliasing rendering is correct.&lt;/p&gt;&#xA;&lt;p&gt;The reference gray ramp (top and bottom) is linear in sRGB color, not in brightness.&lt;/p&gt;&#xA;&lt;p&gt;The second gray ramp made with anti-aliasing is linear in brightness. The rectangle color (black in color sRGB space) is mapped to linear space (remains black), then anti-aliasing is computed, and the resulting image is converted back to sRGB. It is thus not linear in sRGB value anymore.&lt;/p&gt;&#xA;&lt;p&gt;The RGB values given by a screen color picker are in  sRGB color space, and the color values of a screen capture are in the sRGB color space.&lt;/p&gt;&#xA;&lt;p&gt;SVG and nearly all browser graphic library (skia and cairo) are doing it wrong. They compute anti-aliasing over sRGB instead of linear color. They thus don't convert back from linear to sRGB. The same mistreatment  is also visible on Windows, MacOs and iOS.&lt;/p&gt;&#xA;&lt;p&gt;The filled rectangle gray ramp doesn't have this problem because the conversion from sRGB to linear and its inverse cancel out.&lt;/p&gt;&#xA;" OwnerUserId="16019" LastActivityDate="2021-04-30T17:11:16.833" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10858" PostTypeId="2" ParentId="10855" CreationDate="2021-04-30T18:21:12.343" Score="0" Body="&lt;p&gt;I'm assuming the rotation matrix generated from the arcball is 2D, so I think there are a few clear top level steps. But I'm not sure about the details of some of them.&lt;/p&gt;&#xA;&lt;p&gt;First you'll need to extend the 2D rotation to 3D which should be easy.&lt;/p&gt;&#xA;&lt;p&gt;Next you'll need to rotate the rotation matrix itself so its axis aligns with your Forward vector. I'm not certain how to do this step.&lt;/p&gt;&#xA;&lt;p&gt;Then, use the resulting matrix to transform the Up vector and reconstruct the camera matrix using the new vector and the other values and vectors.&lt;/p&gt;&#xA;" OwnerUserId="482" LastEditorUserId="482" LastEditDate="2021-05-06T16:43:41.407" LastActivityDate="2021-05-06T16:43:41.407" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10859" PostTypeId="1" CreationDate="2021-05-01T23:29:10.130" Score="0" ViewCount="22" Body="&lt;p&gt;Around 1987, the investment bank I worked for had a high-end graphics device, possibly from Evans &amp;amp; Sutherland, which produced an &amp;quot;animated&amp;quot; display not unlike the view from the front seat of the first car of a roller coaster.  Here it was possible to &amp;quot;ride the graph&amp;quot; given a time series of stock prices of IBM or whatever.  As such, this device was used solely for demonstration.&lt;/p&gt;&#xA;&lt;p&gt;Would anyone know what device this could have been or if any pictures or videos exist of its output?&lt;/p&gt;&#xA;" OwnerUserId="16282" LastActivityDate="2021-05-01T23:29:10.130" Title="Was there an Evans &amp; Sutherland display system capable of rendering ordinary data as motion through a landscape?" Tags="&lt;3d&gt;&lt;image-processing&gt;&lt;animation&gt;&lt;video&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2021-05-04T16:39:48.647" ContentLicense="CC BY-SA 4.0" />
  <row Id="10861" PostTypeId="1" CreationDate="2021-05-02T13:18:49.580" Score="0" ViewCount="21" Body="&lt;p&gt;I'm trying to make a simple vulkan program. The structure of my code is very similar to vulkan-tutorial's, except I'd like to recreate the swapchain without calling vkDeviceWaitIdle. As such, I'm waiting on all of the fences for the frames in flight instead.&lt;/p&gt;&#xA;&lt;p&gt;However, this does not seem to work. For some reason, it seems like the very first frame submitted after the swapchain recreation never signals its fence. &lt;a href=&quot;https://github.com/Toctave/vulkan-gp/blob/aeb907eff5ef443f1c04e487c6c392632b3edeb7/src/main.cpp#L1014&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here is the code&lt;/a&gt; if you would like to have a look -- swapchain recreation happens at line 1135, after calling vkAcquireNextImageKHR. I've left the log calls in to make it clearer what the output below means.&lt;/p&gt;&#xA;&lt;p&gt;And here is an example output, where the program froze right after logging those lines :&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;(...)&#xA;-- FRAME 381 --&#xA;Waiting until frame #2 is rendered.&#xA;Done waiting.&#xA;Acquiring an image.&#xA;Waiting on all fences before destroying swapchain&#xA;Frame #0 (0x100000000010) is available&#xA;Frame #1 (0x130000000013) is available&#xA;Frame #2 (0x160000000016) is available&#xA;Recreated swapchain&#xA;Acquiring an image.&#xA;Rendering to image #0&#xA;Submitted queue, going to signal fence #2 (0x340000000034)&#xA;-- FRAME 382 --&#xA;Waiting until frame #0 is rendered.&#xA;Done waiting.&#xA;Acquiring an image.&#xA;Rendering to image #1&#xA;Submitted queue, going to signal fence #0 (0x2e000000002e)&#xA;-- FRAME 383 --&#xA;Waiting until frame #1 is rendered.&#xA;Done waiting.&#xA;Acquirendering to image #0&#xA;Image #0 in use by frame #2 (0x340000000034), waiting.&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;As you can see, vkQueueSubmit is supposed to signal fence #2 when it is done with frame 381. But then, frame 383 waits indefinitely for that very fence to be signaled, and I cannot see why.&lt;/p&gt;&#xA;&lt;p&gt;Do you guys know what is going on here ? Thanks in advance.&lt;/p&gt;&#xA;" OwnerUserId="13787" LastActivityDate="2021-05-02T13:18:49.580" Title="vkQueueSubmit never signals fence after swapchain recreation" Tags="&lt;vulkan&gt;" AnswerCount="0" CommentCount="1" FavoriteCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10862" PostTypeId="1" CreationDate="2021-05-03T07:33:24.333" Score="0" ViewCount="11" Body="&lt;p&gt;I'm trying to view a Collada file with separate texture image file, e.g. &lt;a href=&quot;https://app.ignitionrobotics.org/mjcarroll/fuel/models/Banana%20for%20Scale&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://app.ignitionrobotics.org/mjcarroll/fuel/models/Banana%20for%20Scale&lt;/a&gt;, which includes &lt;code&gt;Banana.dae&lt;/code&gt; and &lt;code&gt;Banana.png&lt;/code&gt;. I tried MeshLab, Blender and a few online viewers, but none of them renders the texture. I even simplified the model directory structure, so both files are in the same directory and the path to texture in &lt;code&gt;Banana.dae&lt;/code&gt; is:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;  &amp;lt;library_images&amp;gt;&#xA;    &amp;lt;image id=&amp;quot;MapFBXASC032FBXASC0352-image&amp;quot; name=&amp;quot;MapFBXASC032FBXASC0352&amp;quot;&amp;gt;&#xA;      &amp;lt;init_from&amp;gt;Banana.png&amp;lt;/init_from&amp;gt;&#xA;    &amp;lt;/image&amp;gt;&#xA;  &amp;lt;/library_images&amp;gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;and I still get a mesh rendered without a texture. What is a way to fix it or convert .dae file to another format with the texture included?&lt;/p&gt;&#xA;" OwnerUserId="16291" LastActivityDate="2021-05-03T07:33:24.333" Title="Viewing or importing Collada files with textures" Tags="&lt;texture&gt;&lt;meshlab&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10864" PostTypeId="2" ParentId="2510" CreationDate="2021-05-03T15:51:06.563" Score="0" Body="&lt;p&gt;{0,8,7,6} and {4,3,2} are called &amp;quot;left bounds&amp;quot; because if you look at both these bounds, the polygon interior is to the right of them:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/GhMNp.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/GhMNp.png&quot; alt=&quot;image1&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Likewise, {0,1,2} and {4,5,6} are &amp;quot;right bounds&amp;quot; because the polygon interior is at their left:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/idwor.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/idwor.png&quot; alt=&quot;image2&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;For reference, this example comes from: &lt;a href=&quot;http://what-when-how.com/computer-graphics-and-geometric-modeling/clipping-basic-computer-graphics-part-5/&quot; rel=&quot;nofollow noreferrer&quot;&gt;http://what-when-how.com/computer-graphics-and-geometric-modeling/clipping-basic-computer-graphics-part-5/&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="16290" LastActivityDate="2021-05-03T15:51:06.563" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10865" PostTypeId="2" ParentId="5291" CreationDate="2021-05-03T18:04:30.033" Score="4" Body="&lt;p&gt;Based on the article, it seems like, when it adds &amp;quot;directional lighting information&amp;quot;, the program tries to infer a location of a light source and base the normals on the colors with the added information of the directional lighting from the pixel to the inferred light source. I feel like I'm making no sense right now, so here's an example using their pictures:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/YFApT.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/YFApT.png&quot; alt=&quot;Sample image&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/kLyJQ.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/kLyJQ.png&quot; alt=&quot;Normal map with shape recognition&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As you can see, on the far right of the normal map, it's very pink, just like how the sample image is completely white. I would assume this is the case because the inferred light is directly on top of it, with all the normals (in sort of a curved fashion, resulting in the gradient) pointing right at it. In contrast...&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/o56xq.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/o56xq.png&quot; alt=&quot;Normal map without shape recognition&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This normal map isn't trying to figure out a light source, and instead just kind of uses the sample texture as a heightmap of sorts.&lt;/p&gt;&#xA;&lt;p&gt;Late reply, but hope this helps! :)&lt;/p&gt;&#xA;" OwnerUserId="16300" LastActivityDate="2021-05-03T18:04:30.033" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10866" PostTypeId="1" CreationDate="2021-05-03T22:43:37.767" Score="0" ViewCount="35" Body="&lt;p&gt;I am currently working on tetrahedral meshes and I want to downsample the mesh using techniques like Qslim but there is not much about tetrahedral meshes in the literature. I try to use it as a pooling layer in a neural network so computation cost is also important. I wonder if there is a open-source code available for this task.&lt;/p&gt;&#xA;" OwnerUserId="16302" LastActivityDate="2021-05-03T22:43:37.767" Title="Is there any open source code available for simplification of tetrahedral mesh?" Tags="&lt;mesh&gt;" AnswerCount="0" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10867" PostTypeId="1" CreationDate="2021-05-04T19:19:18.467" Score="0" ViewCount="13" Body="&lt;p&gt;I'm trying to figure out how I should distribute the invocations of a glsl compute shader for drawing multiple curves composed of multiple interpolated segments. In this figure I show how I've proceeded with handling segments of a single curve, but I'm not sure how to extend this to multiple curves. If my question isn't clear enough, I would also settle for pointers to resources where other people use compute shaders to draw curves as I'm not coming up with many good results in my own searches.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/v2Spl.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/v2Spl.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="10787" LastActivityDate="2021-05-04T19:19:18.467" Title="How to distribute compute shader invocations for drawing of many multi segment curves?" Tags="&lt;shader&gt;&lt;compute-shader&gt;&lt;curve&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10868" PostTypeId="1" CreationDate="2021-05-05T17:24:32.797" Score="0" ViewCount="49" Body="&lt;p&gt;I am using Fournier's midpoint algorithm (recursive subdivision) to construct a landscape of 1025 x 1025 gridpoints, then I am using an advanced version of box counting to find fractal dimension, D. No matter what Hurst exponent I use in Fournier's algorithm, I get D = 2.0. Has anyone checked Fournier's algorithm for fractal dimension? Does it actually produce a fractal?&lt;/p&gt;&#xA;" OwnerUserId="16313" LastActivityDate="2021-05-05T17:24:32.797" Title="Fractal dimension of landscape generated with Fournier's midpoint algorithm (recursive subdivision) is 2.0 no matter what. Why?" Tags="&lt;algorithm&gt;" AnswerCount="0" CommentCount="7" ContentLicense="CC BY-SA 4.0" />
  <row Id="10869" PostTypeId="1" CreationDate="2021-05-05T23:22:21.563" Score="0" ViewCount="18" Body="&lt;p&gt;If I am setting Fast Clear related state for Draw Call 1 then does it carry forward to the following draw calls as well?&#xA;Follow up question- how about between different batch buffers?&lt;/p&gt;&#xA;&lt;p&gt;&amp;quot;Working in DX12 space&amp;quot;&lt;/p&gt;&#xA;" OwnerUserId="16320" LastActivityDate="2021-05-05T23:22:21.563" Title="DO states carry forward between Draw calls?" Tags="&lt;directx12&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10870" PostTypeId="2" ParentId="8757" CreationDate="2021-05-06T01:09:35.560" Score="1" Body="&lt;p&gt;There are plenty of algorithms for generating meshes from point clouds. I am going to suggest looking at the libraries &lt;a href=&quot;https://doc.cgal.org/latest/Manual/tuto_reconstruction.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;CGAL&lt;/a&gt; and &lt;a href=&quot;https://pointclouds.org/documentation/tutorials/greedy_projection.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;PCL&lt;/a&gt;, if only because their documentation has excellent references which should give you ideas on where to look in the literature if you need to roll your own.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://people.eecs.berkeley.edu/%7Ejrs/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Jonathan Shewchuk&lt;/a&gt; also has some more 2.5D-ish algorithms that may suit your needs.&lt;/p&gt;&#xA;" OwnerUserId="159" LastEditorUserId="159" LastEditDate="2021-05-06T01:14:43.213" LastActivityDate="2021-05-06T01:14:43.213" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10872" PostTypeId="1" CreationDate="2021-05-06T20:00:06.673" Score="0" ViewCount="95" Body="&lt;p&gt;Recently I've became an intern in &lt;code&gt;company-name&lt;/code&gt; and my internship task is(for now) create rasterization using rays.&lt;/p&gt;&#xA;&lt;p&gt;I'm mostly interested in pure math, so basic ideas on how to do it I've caught up really fast: I need to find an intersection of a ray that starts in center of a pixel with a plane of a triangle, compute barycentric coordinates in order to understand whether the intersection point is in the triangle or not.&lt;/p&gt;&#xA;&lt;p&gt;But when it comes to code realization, I'm getting stuck.&lt;/p&gt;&#xA;&lt;p&gt;First of all, and probably my main &amp;quot;problem&amp;quot; is that I can't really understand what &amp;quot;camera&amp;quot; is really about. I know it might have a lot of different properties(so called &amp;quot;intrinsic&amp;quot; and &amp;quot;extrinsic&amp;quot;), but I just need a basic one. For now I understand this as an &amp;quot;eye&amp;quot; located somewhere in the space.&lt;/p&gt;&#xA;&lt;p&gt;And here is the second &amp;quot;problem&amp;quot;: I said, the camera is located somewhere in the space, but &lt;em&gt;where is it really located&lt;/em&gt;? I really can't get how to put in in the space.  Also, I need to put the &amp;quot;screen&amp;quot; somewhere in the space as well, preferably between the &amp;quot;eye&amp;quot; and object/scene(I'm considering pinhole camera as a primer model).&lt;/p&gt;&#xA;&lt;p&gt;For now, I do the following: I identify &amp;quot;eye&amp;quot; and &amp;quot;screen&amp;quot; as one object(going down to biology, &amp;quot;screen&amp;quot; is something like the cornea of a human eye). I scale my object/scene in &lt;span class=&quot;math-container&quot;&gt;$[-1,1]^3$&lt;/span&gt;, and put my &amp;quot;eye&amp;quot;/&amp;quot;screen&amp;quot; on the 2-sphere of radius &lt;span class=&quot;math-container&quot;&gt;$2\sqrt3$&lt;/span&gt;, because &lt;span class=&quot;math-container&quot;&gt;$[-1,1]^3$&lt;/span&gt; is inside of this sphere. Therefore I can move my &amp;quot;camera&amp;quot; on the sphere, getting different camera positions. But I'm not quite sure that this is how it should be done.&lt;/p&gt;&#xA;&lt;p&gt;So this are my problems, basically about the essence of camera(and so of screen) and its positions in the space. I hope someone will help me to tackle my confusion. Thanks.&lt;/p&gt;&#xA;" OwnerUserId="16319" LastEditorUserId="16319" LastEditDate="2021-05-07T18:30:02.427" LastActivityDate="2021-05-07T18:30:02.427" Title="Ray casting and rasterization 101" Tags="&lt;raytracing&gt;&lt;physically-based&gt;&lt;camera&gt;" AnswerCount="0" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="10873" PostTypeId="1" AcceptedAnswerId="10875" CreationDate="2021-05-07T08:09:12.003" Score="0" ViewCount="97" Body="&lt;p&gt;I like to know the technical aspects of it. Game developers use APIs like OpenGL or DirectX. The functions provided by these APIs, I would assume, work flawlessly with all graphic cards because they are fixed and do not change - except if there is a new version of it - and are of some sort mathematically correct. So how does it come that Nvidia and AMD have to update their drivers to fix visual bugs or performances? What are the problems? Furthermore, I would like to know if Nvidia and AMD are providing these improvements on their own behalf or if the game developers cooperate with them by making some sort of paid contracts.&lt;/p&gt;&#xA;" OwnerUserId="16335" LastEditorUserId="13095" LastEditDate="2021-05-07T10:14:55.330" LastActivityDate="2021-05-07T13:38:21.237" Title="Why do Nvidia and AMD have to update their drivers for game releases?" Tags="&lt;opengl&gt;&lt;directx&gt;&lt;driver&gt;" AnswerCount="2" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10874" PostTypeId="2" ParentId="10873" CreationDate="2021-05-07T10:59:14.450" Score="0" Body="&lt;p&gt;Nvidia uses a technique called &lt;a href=&quot;https://www.nvidia.com/en-gb/geforce/technologies/dlss/&quot; rel=&quot;nofollow noreferrer&quot;&gt;DLSS (deep learning super sampling)&lt;/a&gt; with their latest graphic cards. It basically uses AI to upscale your image. So for example, you render in a resolution of 1080p and get an upscaled image in 4k that is barely distinguishable from a native 4k render. They train the AI with a lot of image samples from the corresponding game and distribute the training data with the drivers. From the source I linked:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;DLSS uses the power of NVIDIA’s supercomputers to train and improve its AI model. The updated models are delivered to your GeForce RTX PC through Game Ready Drivers.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;I can't tell you if this is the sole reason, but it is certainly one of them. Not sure if AMD does something similar (I guess they do).&lt;/p&gt;&#xA;&lt;p&gt;I can't answer your second question, but I guess it is some sort of cooperation between Nvidia/AMD and the big players in the game industry since both benefit from it to sell their products.&lt;/p&gt;&#xA;" OwnerUserId="13095" LastActivityDate="2021-05-07T10:59:14.450" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10875" PostTypeId="2" ParentId="10873" CreationDate="2021-05-07T13:38:21.237" Score="4" Body="&lt;p&gt;Games, Triple A games in particular, tend to push graphics cards to their limits, computation capabilities, bandwidth, and drivers all get stressed heavily. This tends to cause even the smallest bug, or inefficiency in the driver to become a glaring problem resulting in &amp;quot;glitches&amp;quot;, slow frame rates, game crashes and rendering quality issues.&lt;/p&gt;&#xA;&lt;p&gt;These &amp;quot;bugs&amp;quot; and inefficiencies can be very specific and often only occur when certain sequences of operations happen, which are often specific to a particular game. The range of issues that they run into tend to run the gamut from simple brain dead bugs, to show stopping monsters that everyone spends weeks agonizing over, to minor tweaks that improve visuals.&lt;/p&gt;&#xA;&lt;p&gt;During game development vendors will provide driver updates that address these issues directly to game developers, or put the updates in a &amp;quot;beta&amp;quot; driver and release it publicly so anyone, including the developers, can install it. This allows games to be tested, developed and updated before being released.&lt;/p&gt;&#xA;&lt;p&gt;How closely a vendor works with a game developer is going to depend heavily on the size of the project and the issues they are encountering. Sometimes this will mean going so far as having engineers from the GPU vendor actually join the game development team, and spend time on site working through the various problems that come up. Other times it can be just an updated driver dropped on the public beta website.&lt;/p&gt;&#xA;&lt;p&gt;When the game is nearing release game developers and vendors will work together to release the updated driver with the game, this sometimes even includes shipping the updated driver with the actual game. For smaller projects vendors might no be as accommodating. It is in the best interest of both game developers and GPU vendors to work together, especially on large projects.&lt;/p&gt;&#xA;&lt;p&gt;It would be naïve to assume that the two don't come to some sort of monetary agreement when developing a game, especially when a game gets advertised with statements like &amp;quot;Made for XYZ gpu vendor.&amp;quot;&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-05-07T13:38:21.237" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10876" PostTypeId="1" CreationDate="2021-05-08T01:53:17.493" Score="1" ViewCount="51" Body="&lt;p&gt;Just like the question, I am wondering are there any limitations and benefits for these two techniques?&lt;/p&gt;&#xA;" OwnerUserId="16341" LastActivityDate="2021-05-08T13:03:25.150" Title="What are the limitations and benefits of anti-aliasing and subpixel rendering respectively?" Tags="&lt;antialiasing&gt;&lt;subpixel-rendering&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10879" PostTypeId="1" CreationDate="2021-05-09T10:16:31.543" Score="0" ViewCount="53" Body="&lt;p&gt;I'm interested in direct3d game programming and I'm just a beginner.&#xA;I'm familiar with the Win32 API and i was wondering...&#xA;how to put a certain pixel somewhere in the window&#xA;is there like a function or anythting?&#xA;thank you...&lt;/p&gt;&#xA;" OwnerUserId="16350" LastActivityDate="2021-05-12T18:07:52.633" Title="how to put a pixel somewhere in a window(directx)" Tags="&lt;pixels&gt;" AnswerCount="1" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10880" PostTypeId="1" AcceptedAnswerId="10881" CreationDate="2021-05-09T17:46:24.443" Score="1" ViewCount="68" Body="&lt;p&gt;this is my first post on the Computer Graphics Stackexchange forum. Apologies in advance if I am doing something wrong.&lt;/p&gt;&#xA;&lt;p&gt;I have the problem that I have a scene with overlapping geometries. To be more precise, my scene is a Cornell Box, where the ceiling and the area light are quads that are lying in the same plane, e.g. are having the same height value:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/qjJfD.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/qjJfD.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This image is rendered by our &amp;quot;home renderer&amp;quot; and I am working on the integration of Intel's Embree framework into it, to accelerate the ray casting process.&lt;/p&gt;&#xA;&lt;p&gt;When I render the scene with the help of Embree, it looks like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ruuES.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ruuES.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;(There is nothing wrong with Embree itself, but probably with what I am doing with it)&#xA;What is immediately visible is that the ceiling looks more &amp;quot;grainy&amp;quot; or noisy and that pixels in the area light have the colour of the ceiling.&lt;/p&gt;&#xA;&lt;p&gt;I strongly believe that this has something to do with the fact that the ceiling and the&#xA;area light are lying in the same plane.&#xA;So my question is: when such overlapping geometries are intersected with a ray, how does one choose which of the two geometries should be prioritized?&lt;/p&gt;&#xA;&lt;p&gt;I did a short experiment in Blender with two cubes with different materials:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/rX9Lk.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/rX9Lk.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Then I moved the green cube &amp;quot;into&amp;quot; the red one, meaning I assigned the same position, such that the two cubes are overlapping.&lt;/p&gt;&#xA;&lt;p&gt;This is what the Cycles renderer gave me:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/6uRaL.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6uRaL.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Does anyone know what is going on? How can I handle the situation of overlapping geometry in my ray tracer?&#xA;Many thanks in advance for your help and support. Have a nice Weekend!&lt;/p&gt;&#xA;&lt;p&gt;Kind regards&#xA;Sebastian&lt;/p&gt;&#xA;" OwnerUserId="16352" LastActivityDate="2021-05-10T12:54:53.393" Title="Ray tracing geometries with same position, translation and scale" Tags="&lt;raytracing&gt;" AnswerCount="1" CommentCount="11" ContentLicense="CC BY-SA 4.0" />
  <row Id="10881" PostTypeId="2" ParentId="10880" CreationDate="2021-05-10T12:37:41.837" Score="0" Body="&lt;p&gt;This is more of a comment then an answer:&lt;/p&gt;&#xA;&lt;p&gt;I have resolved this problem in a ray tracer using Constructive Solid Geometry(CSG). Which was done by adding operators that allowed us to create objects that are the union, difference, and intersection of a combination of objects. &lt;a href=&quot;https://en.wikipedia.org/wiki/Constructive_solid_geometry&quot; rel=&quot;nofollow noreferrer&quot;&gt;Here is a wiki page on the subject.&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;CSG sounds difficult to implement, but it is actually surprisingly straight forward.&lt;/p&gt;&#xA;&lt;p&gt;But, this system was added for other reasons, it just turned out that we could &amp;quot;subtract&amp;quot; the light from the box (using your post as an example), then the intersection for the light itself falls out naturally since it can no longer hit the box where the two intersect.&lt;/p&gt;&#xA;&lt;p&gt;This really is just reiterating what everyone has been saying in the comments, every solution is either done by creating real geometry that avoids the problem (like CSG) or use some sort of hack. I posted the CSG answer because it resolves the problem so naturally if it is available.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-05-10T12:54:53.393" LastActivityDate="2021-05-10T12:54:53.393" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10882" PostTypeId="1" CreationDate="2021-05-10T15:59:47.560" Score="0" ViewCount="18" Body="&lt;p&gt;In camera calibration (i.e. camera calibration with OpenCV) does result for focal lengths fx and fy&#xA;depend on the photo-sensitive area inside the pixel ?&lt;/p&gt;&#xA;&lt;p&gt;For example, a camera sensor (CCD/CMOS) with a square grid arrangement of pixel elements, but inside each pixel the actual pixel sensitive area is rectangular (additional electronics in CMOS) where the size in x is double the size in y (1/2 fill factor).&#xA;Do we get different result for fx and fy when preforming camera calibration in this case ?&lt;/p&gt;&#xA;" OwnerUserId="16374" LastActivityDate="2021-05-10T15:59:47.560" Title="Camera calibration focal lengths and pixel sensitive area relation" Tags="&lt;camera&gt;&lt;camera-matrix&gt;&lt;opencv&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10883" PostTypeId="1" CreationDate="2021-05-11T10:06:38.040" Score="0" ViewCount="63" Body="&lt;pre&gt;&lt;code&gt;unsigned int histogram[256]={0};&#xA;for(int i=0;i&amp;lt;width*height;i++)  //to iterate over pixels&#xA;  ++histogram[image[i]];&#xA;&#xA;const float cutoffpercentage = 0.05;  //To cut off lower and upper values&#xA;unsigned char lowerbound,upperbound;&#xA;unsigned int histAccu =0;  //pixel entries &amp;lt; 5% =lower bound&#xA;const unsigned int lowerpercentile = cutoffpercentage * width*height;&#xA;const unsigned int upperpercentile = (1-cutoffpercentage)*width*height;&#xA;&#xA;for(int h =0;h &amp;lt;256;h++){&#xA;histAccu += histogram[h];&#xA;&#xA;if(histAccu &amp;lt;= lowerpercentile){&#xA;lowerbound = h;&#xA;continue;&#xA;}&#xA;&#xA;if(histAccu &amp;gt;= upperpercentile){&#xA;upperbound = h;&#xA;break;&#xA;}&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Then assign new gray values. Can I write this program to equalize the histogram of an image on a gpu shader memory and programs for image segmentation, blurring, sharpening etc...as a shader program using openGL ?? Can we write shader programs just like a normal application program in C ?? Kindly help me on this, as I'm new to shader programming.&lt;/p&gt;&#xA;" OwnerUserId="16382" LastActivityDate="2021-05-22T17:46:25.067" Title="Can I write histogram equalization, blurring, sharpening grayscale image etc.. as shader programs with openGL?" Tags="&lt;opengl&gt;&lt;shader&gt;&lt;c++&gt;&lt;image-processing&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10884" PostTypeId="2" ParentId="10848" CreationDate="2021-05-12T07:36:11.637" Score="2" Body="&lt;p&gt;You can't create a solid by extruding a single curve or set of curves. Even if they are closed. Think about a circle on on the XY plane. If you extrude the circle along the Z axis you have an uncapped cylinder.&lt;/p&gt;&#xA;&lt;p&gt;Let's walk it back a bit though. If you have a single Bezier curve and extrude it you create a Bezier surface. You can quickly get your head around a Bezier surface if you understand a Bezier curve.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/B%C3%A9zier_surface&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/B%C3%A9zier_surface&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;You can think of the Bezier surface as a blend through a set of curves. To extrude the curve you simply duplicate your original curve, and set the control points Z value to your extrusion distance. The original curve and new extruded curve create the control points for your surface.&lt;/p&gt;&#xA;&lt;p&gt;I actually have a Bezier surface example I wrote in Python. The only dependencies are Numpy and Matplotlib. It also uses the Bernstein Basis function imported from another file in the repository. You can play with the control points to see how modifying them effects the resulting surface. There's no error checking so you'll have to know what you're doing.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://github.com/jrz371/IntroToNurbsPython/blob/master/BezierSurface.py&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://github.com/jrz371/IntroToNurbsPython/blob/master/BezierSurface.py&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As for parameterizing the span and chord length you'll have to derive those yourself. I'm unfamiliar with your requirements. Understanding the Bezier curves and surfaces thoroughly should help you resolve that.&lt;/p&gt;&#xA;&lt;p&gt;Some of the comment suggest evaluating the curve and creating triangles. This is a bad approach. Tessellating a Bezier surface causes you to lose a lot of information. The Bezier surface is smooth whereas a set of triangles is not. For drawing a Bezier surface they are ultimately tessellated for the display, but they are kept in the original Bezier representation for modification.&lt;/p&gt;&#xA;&lt;p&gt;Bezier curves are also not the best representation for curves and surfaces. BSplines and NURBS are able to represent more complex surfaces and curves. Understanding Beziers is fundamental prerequisite before tackling those.&lt;/p&gt;&#xA;&lt;p&gt;Good luck!&lt;/p&gt;&#xA;" OwnerUserId="8830" LastActivityDate="2021-05-12T07:36:11.637" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10886" PostTypeId="2" ParentId="10879" CreationDate="2021-05-12T18:07:52.633" Score="0" Body="&lt;p&gt;there is no direct way to place a pixel on a window I am afraid.&#xA;An indirect way would be to draw a small quad equal to the size of a pixel in relation to your window&lt;/p&gt;&#xA;&lt;p&gt;and essential y d3d 11 and 12 are most useful to draw geometry&#xA;So I recommend you start from there and take your creativity ahead&lt;/p&gt;&#xA;" OwnerUserId="16398" LastActivityDate="2021-05-12T18:07:52.633" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10887" PostTypeId="1" CreationDate="2021-05-13T03:10:10.107" Score="0" ViewCount="36" Body="&lt;p&gt;I am looking for some way to estimate the amount of overlap between a rectangular prism(not axis aligned) and a frustum. The rectangular prism is probably always going to be larger than the frustum itself. Basically if the prism overlaps the frustum completely the overlap function should output 1, and if the prism is completely outside the frustum it should output 0. And hopefully if it partially overlaps it outputs a value between 0-1 that is the amount of overlap. It doesn't need to be a perfect estimate I think, but it should get close and should be correct for cases where its completely overlapping or completely separate.&lt;/p&gt;&#xA;&lt;p&gt;This will be used to voxelize the prism into a view frustum aligned 3D texture, where each entry in the 3D texture is a small frustum itself.&lt;/p&gt;&#xA;&lt;p&gt;Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="16401" LastActivityDate="2021-05-13T18:42:22.177" Title="Way to estimate the amount of overlap between a rectangular prism and a frustum?" Tags="&lt;voxelization&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10888" PostTypeId="2" ParentId="10887" CreationDate="2021-05-13T11:14:04.520" Score="1" Body="&lt;p&gt;The typical prism/obb/aabb is made up of 6 planes, and the frustum is also typically made up of 6 planes.&lt;/p&gt;&#xA;&lt;p&gt;To generate a new volume that is the intersection of the two original volumes, use plane clipping to clip one against the other. This technique is generic enough that it can be used with any object like a mesh.&lt;/p&gt;&#xA;&lt;p&gt;That is take all the planes from the frustum then clip them one by one against the prism. After each clip operation, the new volume becomes the input to the next clipping operation.&lt;/p&gt;&#xA;&lt;p&gt;What is left will be the clipped volume representing the intersection of the two. Compute the volume of the new shape and divide it by the original volume and you will get a value that is somewhere between [0,1].&lt;/p&gt;&#xA;&lt;p&gt;This technique is often used to generate decals in games (though the volume computation is not done). Searching the web for decal generation alogorithms/tutorials should help you with the implementation details.&lt;/p&gt;&#xA;&lt;p&gt;And if you have specific questions I am happy to add more details to this answer.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastEditorUserId="7952" LastEditDate="2021-05-13T18:42:22.177" LastActivityDate="2021-05-13T18:42:22.177" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10889" PostTypeId="1" CreationDate="2021-05-14T09:26:06.710" Score="0" ViewCount="24" Body="&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm looking for a possibility to use spectral texture data in Mitsuba renderer. The texture is saved as a tiff image stack and is to be added to the surface of an arbitrary object.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;Software clarifications&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;I'm very new to image rendering. I'm using Mitsuba2 as I found this to be a physical correct spectral renderer with many options to adapt a scene to my needs. But if you can recommend an other renderer I'm open to your suggestions.&lt;/p&gt;&#xA;&lt;p&gt;&lt;strong&gt;My ideas&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Use the spectral texture data as a surface scattering model inside a scene. That seems to be easy done, but as far as I understand &lt;a href=&quot;https://mitsuba2.readthedocs.io/en/latest/generated/plugins.html#bitmap-texture-bitmap&quot; rel=&quot;nofollow noreferrer&quot;&gt;the documentation&lt;/a&gt;, only rgb bitmaps are allowed.&lt;/li&gt;&#xA;&lt;li&gt;Create an obj file with an associated mtl file containing the spectral texture data. Does someone has any experiences with this approach? I don't know if Mitsuba can handle this complicated input structure, neither do I know how to create those files...&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I appreciate your help!&lt;/p&gt;&#xA;&lt;p&gt;Annotation: I opened an issue in Mitsuba's github repository already. By asking my question on CG SE I hope to reach some people having worked with different renderers and therefore may have an completely new view.&lt;/p&gt;&#xA;" OwnerUserId="16407" LastActivityDate="2021-05-14T09:26:06.710" Title="How to add spectral texture to an object? (Mitsuba renderer)" Tags="&lt;rendering&gt;&lt;texture&gt;&lt;physically-based&gt;&lt;spectral&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10890" PostTypeId="1" AcceptedAnswerId="10894" CreationDate="2021-05-15T09:06:48.280" Score="1" ViewCount="47" Body="&lt;p&gt;I am working on the integration of Intel's Embree library into our home renderer to accelerate its rendering time. Our renderer supports various geometry types, such as quads, triangles, but also spheres, hyperbolas and tori.&lt;/p&gt;&#xA;&lt;p&gt;For ray casting triangles, triangle meshes and quads I am using Embree's build-in triangle- and quad-primitives. However, for the more complicated geometries I am using what's called User Defined Geometries (one passes functions for calculating bounding boxes, for intersection calculation and occlusion testing to Embree).&lt;/p&gt;&#xA;&lt;p&gt;For scenes with triangles, triangle meshes and quads, Embree really is faster (about twice as fast). My problem is that for scenes with User Defined Geometries, Embree takes about the same amount of time and often is even slower (if only for seconds).&lt;/p&gt;&#xA;&lt;p&gt;As an example, I have this scene:&#xA;&lt;a href=&quot;https://i.stack.imgur.com/e9Y4W.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/e9Y4W.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Here is the output of the renderer when rendering this scene with 200 spp and without Embree support:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;sebastian@sebastian-N551JX ~/ART_Gallery/BRDF_Showcase $ artist OrenNayarSpheres.arm -DSAMPLES=200 -o normal200&#xA;&#xA;artist - photorealistic renderer&#xA;ART version 2.0.4-dev, 8 cores detected&#xA;(c) 1996-2020 by the ART development team &#xA;&#xA;reading scene description                                           0.82 sec&#xA;optimising scene graph for raycasting                               0.00 sec&#xA;identifying and analysing lightsources                              0.89 sec&#xA;---   interactive mode on, goal are 200 spp   ---&#xA;image sampling: path tracing, 200 spp                             328.34 sec&#xA;---   interactive mode off   ---&#xA;converting raw image to colour space                                0.09 sec&#xA;applying interactive calibration tone mapping operator              0.13 sec&#xA;luminance and chroma reduction for L &amp;gt; 100.0                        0.11 sec&#xA;converting to 8 bpc sRGB TIFF                                       0.08 sec&#xA;opening result image in external viewer &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;... and here with Embree support:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;sebastian@sebastian-N551JX ~/ART_Gallery/BRDF_Showcase $ artist OrenNayarSpheres.arm -DSAMPLES=200 -o embree200 -e&#xA;&#xA;artist - photorealistic renderer&#xA;ART version 2.0.4-dev, 8 cores detected&#xA;(c) 1996-2020 by the ART development team &#xA;&#xA;embree support enabled&#xA;reading scene description                                           0.81 sec&#xA;optimising scene graph for raycasting                               0.03 sec&#xA;identifying and analysing lightsources                              0.90 sec&#xA;---   interactive mode on, goal are 200 spp   ---&#xA;image sampling: path tracing, 200 spp                             322.82 sec&#xA;---   interactive mode off   ---&#xA;converting raw image to colour space                                0.09 sec&#xA;applying interactive calibration tone mapping operator              0.12 sec&#xA;luminance and chroma reduction for L &amp;gt; 100.0                        0.12 sec&#xA;converting to 8 bpc sRGB TIFF                                       0.08 sec&#xA;opening result image in external viewer &#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;As you can see, the rendering time with Embree is technically faster, but only about 4 seconds.&#xA;Now, I wouldn't call myself an experienced programmer. I followed the provided Embree &amp;quot;User Geometry Tutorial&amp;quot; as good as I could. What I am asking myself is, what can I do to make this faster.&lt;/p&gt;&#xA;&lt;p&gt;I am quite aware of the fact that the information I am providing is probably too vague for a definite solution (and I am apologizing for that). My problem is that I don't know how to debug this issue and to determine, whether I am doing something wrong or if an improvement is not possible because of the internal workings of our renderer.&#xA;The Renderer used (for everyone interested, its name is ART (Advanced Rendering Toolkit), it is Open Source and available &lt;a href=&quot;https://cgg.mff.cuni.cz/ART/download/&quot; rel=&quot;nofollow noreferrer&quot;&gt;here&lt;/a&gt;), does some things differently than other &amp;quot;mainstream&amp;quot; renderers.&lt;/p&gt;&#xA;&lt;p&gt;What I did do far was counting the intersection function calls and I have the suspicion that the renderer does more intersection calculations with Embree than without.&lt;/p&gt;&#xA;&lt;p&gt;Does anybody know any cases where Embree did not speed-up the rendering process? Does someone have any hints or tips for me, despite the little information I give?&lt;/p&gt;&#xA;&lt;p&gt;Thank you very much in advance for your help and have a nice day!&lt;/p&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;PS: I am not sure if it helps, but here is my intersection calculation function that I pass to Embree as a callback function. The renderer itself is written in C and Objective-C and so is the intersect function.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;&#xA;    // intersection callback function&#xA;    void embree_intersect_geometry(const int * valid,&#xA;                                   void * geometryUserPtr,&#xA;                                   unsigned int geomID,&#xA;                                   unsigned int instID,&#xA;                                   struct RTCRay * rtc_ray,&#xA;                                   struct RTCHit * rtc_hit)&#xA;    {&#xA;        if(!valid[0])&#xA;            return;&#xA;    &#xA;        // retreive raycaster and geometry data&#xA;        ArnEmbree * embree = [ArnEmbree embreeManager];&#xA;        ArnRayCaster * rayCaster = [embree getRayCasterFromRayCasterArray];&#xA;        UserGeometryData * geometryData = (UserGeometryData *) geometryUserPtr;&#xA;    &#xA;        // perform the intersection&#xA;        ArIntersectionList intersectionList = ARINTERSECTIONLIST_EMPTY;&#xA;        [geometryData-&amp;gt;_combinedAttributes&#xA;                getIntersectionList&#xA;                : rayCaster&#xA;                : RANGE( ARNRAYCASTER_EPSILON(rayCaster), MATH_HUGE_DOUBLE)&#xA;                : &amp;amp;intersectionList&#xA;        ];&#xA;    &#xA;    &#xA;        // if no intersection is found, return&#xA;        if(!intersectionList.head)&#xA;            return;&#xA;    &#xA;        // if the prev intersection is closer, free intersection list and return&#xA;        ArcIntersection * prevIsect = ARINTERSECTIONLIST_HEAD(*rayCaster-&amp;gt;embreeIntersectionList);&#xA;        if(prevIsect &amp;amp;&amp;amp; prevIsect-&amp;gt;t &amp;lt; intersectionList.head-&amp;gt;t) {&#xA;            arintersectionlist_free_contents(&amp;amp;intersectionList,&#xA;                                             ARNRAYCASTER_INTERSECTION_FREELIST(rayCaster));&#xA;            return;&#xA;        }&#xA;    &#xA;    &#xA;        // update embree components&#xA;        rtc_ray-&amp;gt;tfar = (float) intersectionList.head-&amp;gt;t;&#xA;        rtc_hit-&amp;gt;geomID = geomID;&#xA;        rtc_hit-&amp;gt;primID = 0;&#xA;    &#xA;        // since this function is called mutlple times in one go, clear out already existing&#xA;        // intersection list, since we are only interested in nearest hit&#xA;        arintersectionlist_free_contents(ARNRAYCASTER_EMBREE_INTERSECTIONLIST(rayCaster),&#xA;                                         ARNRAYCASTER_INTERSECTION_FREELIST(rayCaster));&#xA;    &#xA;        // set intersection list&#xA;        *rayCaster-&amp;gt;embreeIntersectionList = intersectionList;&#xA;    }&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Some explanation of the code above:  The line &amp;quot;ArnEmbree * embree = [ArnEmbree embreeManager];&amp;quot; returns a singleton object with functionality concerning Embree. &amp;quot;ArnRayCaster * rayCaster&amp;quot; is an object that is used for traversing the scene graph. Since the renderer is multithreaded, one of such ArnRayCaster object is created for each thread. I am storing the relevant ArnRayCaster in an array and I am using the thread ID as the key. Finally, &amp;quot;UserGeometryData&amp;quot; is a struct that holds apart from the representation of the shape in memory, other information that is needed for the intersection calculation:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;typedef struct UserGeometryData {&#xA;    ArNode * _shape;&#xA;    ArTraversalState _traversalState;&#xA;    AraCombinedAttributes * _combinedAttributes;&#xA;    BOOL _isUserGeometry;&#xA;}&#xA;UserGeometryData;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Again, thank you very much in advance for your help!&lt;/p&gt;&#xA;" OwnerUserId="16352" LastActivityDate="2021-05-17T14:41:24.680" Title="Embree: Performance issue when ray casting User Defined Geometry" Tags="&lt;performance&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10893" PostTypeId="1" CreationDate="2021-05-16T16:38:38.757" Score="0" ViewCount="28" Body="&lt;p&gt;I have a fairly complex-shaped object I've modeled, and in creating the LOD meshes, I've merged some verts, deleted some and even added some after in cases where this manipulation produced an n-gon. The UVs look fine, but these meshes have slightly different topology and vertex placement in some spots. Is this okay? What are the ramifications?&lt;/p&gt;&#xA;" OwnerUserId="16426" LastActivityDate="2021-05-16T16:38:38.757" Title="Is there a Performance Penalty for LOD objects with different topology?" Tags="&lt;3d&gt;&lt;performance&gt;&lt;optimization&gt;" AnswerCount="0" CommentCount="5" ContentLicense="CC BY-SA 4.0" />
  <row Id="10894" PostTypeId="2" ParentId="10890" CreationDate="2021-05-17T14:41:24.680" Score="2" Body="&lt;p&gt;My best guess at why you are not seeing a speed up with your user geometry, is that your example does not contain much BVH traversal.&lt;/p&gt;&#xA;&lt;p&gt;With traversing a triangle/quad mesh more time is spent traversing the BVH to decide which triangle you want to test than actually testing triangles. This is where embree really shines.&lt;/p&gt;&#xA;&lt;p&gt;It looks like your user geometry is just one primitive, compared with a triangle mesh which can be divided into many primitives/triangles (which the BVH can reduce to just the primitives you need to test).&lt;/p&gt;&#xA;&lt;p&gt;Considering the image you shared above, each ray will intersect the bounding box of your shape, and then call the same intersection function your non-embree version was calling. Comparing the two the non-embree version really isn't doing much more work.&lt;/p&gt;&#xA;&lt;p&gt;You will probably get better speedups using embree if you try scattering hundreds of your shapes or if you can find a way to divide your work into primitives.&lt;/p&gt;&#xA;" OwnerUserId="13321" LastActivityDate="2021-05-17T14:41:24.680" CommentCount="4" ContentLicense="CC BY-SA 4.0" />
  <row Id="10896" PostTypeId="1" AcceptedAnswerId="10897" CreationDate="2021-05-19T09:16:00.040" Score="0" ViewCount="39" Body="&lt;p&gt;There's a similar question &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8940/why-do-identical-polygons-not-z-fight-in-opengl&quot;&gt;Why do identical polygons not z-fight in OpenGL?&#xA;&lt;/a&gt; but I believe I have a different setup.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/I5uA5.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/I5uA5.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As can be seen in the picture the vertices for the planes are different and on the left side, there's a clearly visible artifact. On the right side, there's no z-fighting even in movement. Why?&lt;/p&gt;&#xA;&lt;p&gt;Update: the white plane draw call submitted first. The depth compare operation is &lt;code&gt;VK_COMPARE_OP_LESS_OR_EQUAL&lt;/code&gt;.&lt;/p&gt;&#xA;" OwnerUserId="386" LastEditorUserId="386" LastEditDate="2021-05-19T12:01:33.293" LastActivityDate="2021-05-19T12:01:33.293" Title="Why there's no z-fighting for coincident planes if the camera look perpendicular at them?" Tags="&lt;z-fighting&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10897" PostTypeId="2" ParentId="10896" CreationDate="2021-05-19T10:52:46.770" Score="2" Body="&lt;p&gt;Even if two triangles aren't coincident...&lt;/p&gt;&#xA;&lt;p&gt;Z fighting happens because of floating point quantization, this results from all the math the shader does to compute vertex positions such as: &lt;span class=&quot;math-container&quot;&gt;$glPosition = Projection*View*Model*vertex\_position$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;When the vertices are all the same distance and angle from the camera then all the floating points values are effectively the same and the tiny error that crops up is so close that the Z fighting &lt;em&gt;appears&lt;/em&gt; to go away.&lt;/p&gt;&#xA;&lt;p&gt;On the other hand if you change the angle of the camera even a little bit then all the floating point values for each vertex are now slightly different and so is the quantization. This results in the z fighting that you are seeing.&lt;/p&gt;&#xA;&lt;p&gt;But keep moving the camera back, and the results for the perfectly aligned camera will eventually begin to exhibit the same behavior. The camera position is also a floating point value and subject to floating point error so no matter how perfectly the camera is aligned, it will still, eventually, have enough error to cause the same issue.&lt;/p&gt;&#xA;" OwnerUserId="7952" LastActivityDate="2021-05-19T10:52:46.770" CommentCount="6" ContentLicense="CC BY-SA 4.0" />
  <row Id="10898" PostTypeId="1" CreationDate="2021-05-19T16:24:53.350" Score="0" ViewCount="33" Body="&lt;p&gt;I am a discord server owner, and I want to add a few new emojis to the server. But because the color palette should match, I downloaded &lt;a href=&quot;http://github.com/twitter/twemoji&quot; rel=&quot;nofollow noreferrer&quot;&gt;Twemoji&lt;/a&gt; as SVGs. Now I need the color palette from these emojis, and for that, I need help. I already have ways to get a palette from a folder filled with PNGs. Now I just need a way to bulk-convert SVGs to PNGs, or a way to directly extract the palette from a SVG-folder. Either way, it can't have any color blending. Neither can it have mipmapping, antialiasing or anything else that changes the color.&#xA;I appreciate any attempt to help, no matter if it is helpful or not, because this is the first time I've done something like this, and this is a learning experience for me.&lt;/p&gt;&#xA;" OwnerUserId="16450" LastActivityDate="2021-05-21T08:25:38.770" Title="Getting the color palette from an SVG folder" Tags="&lt;image-processing&gt;&lt;geometry&gt;" AnswerCount="1" CommentCount="1" ClosedDate="2021-05-24T06:10:15.327" ContentLicense="CC BY-SA 4.0" />
  <row Id="10899" PostTypeId="1" CreationDate="2021-05-19T22:29:25.313" Score="0" ViewCount="30" Body="&lt;p&gt;I have been reading the SIGGRAPH course notes on projective geometric Algebra, and I get some of what's going on. However a lot of the knowledge needed to understand these PGA notes seems to be based in a good grasp of algebra concepts.&lt;/p&gt;&#xA;&lt;p&gt;I was wondering if someone has tried to make a text that tries to build up the theory from motivating examples and explicit computations, rather than top down application of general PGA to 3D euclidean spaces.&lt;/p&gt;&#xA;" OwnerUserId="7462" LastEditorUserId="482" LastEditDate="2021-05-20T04:09:26.777" LastActivityDate="2021-05-20T04:09:26.777" Title="Bottom up (as opposed to top down) text on projective geometric algebra?" Tags="&lt;mathematics&gt;&lt;computational-geometry&gt;&lt;geometry&gt;&lt;projections&gt;&lt;linear-algebra&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10900" PostTypeId="1" AcceptedAnswerId="10905" CreationDate="2021-05-21T03:54:36.393" Score="2" ViewCount="140" Body="&lt;p&gt;In many resources the BRDF is defined like &lt;span class=&quot;math-container&quot;&gt;$$f_{r}(\omega_{i},\omega_{r}) = \frac{\mathrm{d}L_{r}(\omega_{r})}{L_{i}(\omega_{i})\,\cos{\theta_{i}}\,\mathrm{d}\omega_{i}}.$$&lt;/span&gt; The index &lt;span class=&quot;math-container&quot;&gt;$r$&lt;/span&gt; might be replaced by &lt;span class=&quot;math-container&quot;&gt;$o$&lt;/span&gt; but overall the equation looks something like this. However, in some other resources I see the definition &lt;span class=&quot;math-container&quot;&gt;$$f_{r}(\theta_{i},\phi_{i};\theta_{r},\phi_{r}) \equiv \frac{\mathrm{d}L_{r}(\theta_{i},\phi_{i};\theta_{r},\phi_{r};E_{i})}{L_{i}(\theta_{i},\phi_{i})\,\cos{\theta_{i}}\,\mathrm{d}\omega_{i}}.$$&lt;/span&gt; The second definition seems more precise to me as it – besides other things – clearly states that the BRDF in its purest form is a 4-dimensional function of two directions and clearly differentiates between the direction &lt;span class=&quot;math-container&quot;&gt;$(\theta_{i},\phi_{i})$&lt;/span&gt; and the solid angle &lt;span class=&quot;math-container&quot;&gt;$\omega_{i}$&lt;/span&gt;.&lt;/p&gt;&#xA;&lt;p&gt;It seems to me as if the first definition mixes up the direction of incidence and the solid angle in the direction of incidence. The symbol &lt;span class=&quot;math-container&quot;&gt;$\omega_{i}$&lt;/span&gt; stands for the direction – at least I hope so as the BRDF is not a function of solid angles – to economize on writing, I understand that, but what is &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}\omega_{i}$&lt;/span&gt; then? It must be the solid angle but &lt;span class=&quot;math-container&quot;&gt;$\omega_{i}$&lt;/span&gt; is a direction, not a solid angle. Is &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}\omega_{i}$&lt;/span&gt; simply a common way to express the solid angle in a specific direction? May I have misunderstood something?&lt;/p&gt;&#xA;&lt;p&gt;Another thing I've noticed is that the solid angle in the definitions of radiance, luminance and basically all other radiometric and photometric quantities that deal with a solid angle is symbolized with &lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt;, i.e. a big omega. Actually, as far as I can tell, solid angles are usually symbolized with &lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt;. Why is it different in the definition of the BRDF? Am I missing something?&lt;/p&gt;&#xA;" OwnerUserId="16387" LastActivityDate="2021-05-23T19:16:35.920" Title="Why is the symbol for solid angle a small omega in the definition of the BRDF?" Tags="&lt;brdf&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10901" PostTypeId="2" ParentId="10900" CreationDate="2021-05-21T08:14:58.737" Score="3" Body="&lt;p&gt;The &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt; is a direction. Whether you parametrise this direction in spherical coordinates &lt;span class=&quot;math-container&quot;&gt;$(\phi, \theta)$&lt;/span&gt;, in Cartesian coordinates &lt;span class=&quot;math-container&quot;&gt;$(x,y,z)$&lt;/span&gt;, or some other coordinate system is irrelevant. Thus one uses &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt; to represent directions. &lt;span class=&quot;math-container&quot;&gt;$dx$&lt;/span&gt; typically refers to a differential. In the current case it is w.r.t. the solid angle measure &lt;span class=&quot;math-container&quot;&gt;$\sigma$&lt;/span&gt;, so it would be more precise to write &lt;span class=&quot;math-container&quot;&gt;$d\sigma(\omega)$&lt;/span&gt;. This is still informal and handwavy however. The meaning of the expression &lt;span class=&quot;math-container&quot;&gt;$\frac{dL}{d\omega}$&lt;/span&gt; is formalised in the PhD thesis of Eric Veach.&lt;/p&gt;&#xA;" OwnerUserId="10096" LastActivityDate="2021-05-21T08:14:58.737" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10902" PostTypeId="2" ParentId="10898" CreationDate="2021-05-21T08:25:38.770" Score="0" Body="&lt;p&gt;You can convert SVGs to PNGs using &lt;a href=&quot;https://inkscape.org/&quot; rel=&quot;nofollow noreferrer&quot;&gt;Inkscape&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;inkscape in.svg --export-type=png --export-filename=out.png&lt;/p&gt;&#xA;&lt;p&gt;You can batch convert using&lt;/p&gt;&#xA;&lt;p&gt;inkscape *.svg --export-type=png&lt;/p&gt;&#xA;" OwnerUserId="7724" LastActivityDate="2021-05-21T08:25:38.770" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10903" PostTypeId="2" ParentId="10883" CreationDate="2021-05-22T17:46:25.067" Score="1" Body="&lt;p&gt;Yes you can. There are basically two approaches:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You draw everything to a framebuffer object. Then you apply image processing fragment shaders to resulting texture of the previous draw call, where the shaders take the pervious texture with a sampler.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;or if you have a particular image and you would like to have more control on the numeric precision, the number of neighbours available to you while working on pixel etc:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;You apply compute shaders directly to image.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;For the first approach, see &lt;a href=&quot;https://learnopengl.com/Advanced-OpenGL/Framebuffers&quot; rel=&quot;nofollow noreferrer&quot;&gt;Learn OpenGL&lt;/a&gt;, for compute shaders, see &lt;a href=&quot;https://antongerdelan.net/opengl/compute.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Anton's tutorial&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="13456" LastActivityDate="2021-05-22T17:46:25.067" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10904" PostTypeId="2" ParentId="8710" CreationDate="2021-05-23T13:00:26.533" Score="1" Body="&lt;p&gt;I know this is a pretty old question, but I am wondering if the problem does not come from sampling the whole hemisphere of the light, instead of only the visible portion of it from the hit location's point of view (see this : schuttejoe.github.io/post/arealightsampling) ? The visible solid angle is only 2*PI*(1 - cos(theta)) instead of 2*PI.&lt;/p&gt;&#xA;" OwnerUserId="16243" LastEditorUserId="16243" LastEditDate="2021-05-24T19:34:00.800" LastActivityDate="2021-05-24T19:34:00.800" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10905" PostTypeId="2" ParentId="10900" CreationDate="2021-05-23T19:16:35.920" Score="5" Body="&lt;p&gt;The use of spherical coordinates like &lt;span class=&quot;math-container&quot;&gt;$(\theta, \phi)$&lt;/span&gt; is kind of an implementation detail that isn't an essential part of the definition of a BRDF, or other functions defined over a spherical domain generally.&lt;/p&gt;&#xA;&lt;p&gt;It's a lot like how in vector math, we will often express a point or vector by a single symbol like &lt;span class=&quot;math-container&quot;&gt;$v$&lt;/span&gt;, understanding that &amp;quot;under the hood&amp;quot; it's going to be expressed as coordinates &lt;span class=&quot;math-container&quot;&gt;$(v_x, v_y, v_z)$&lt;/span&gt; in some coordinate system. Writing out all the coordinates in every equation would make notation very verbose and would often obscure the vectorial relationships we really care about.&lt;/p&gt;&#xA;&lt;p&gt;Similarly, with functions defined over a sphere or hemisphere, we will often express a direction by &lt;span class=&quot;math-container&quot;&gt;$\omega$&lt;/span&gt;, understanding that when we get to actually writing code this will stand in for some coordinates on the sphere, but the exact choice of representation is not relevant to the math.&lt;/p&gt;&#xA;&lt;p&gt;The symbol &lt;span class=&quot;math-container&quot;&gt;$\mathrm{d}\omega$&lt;/span&gt; represents a differential quantity of solid angle—this is an abuse of notation for sure, but it serves the same purpose of abstracting away the implementation details; in spherical coordinates that would be &lt;span class=&quot;math-container&quot;&gt;$\sin(\theta) \, \mathrm{d}\theta \, \mathrm{d}\phi$&lt;/span&gt; for example, but it's kind of assumed as background knowledge that you know how to integrate things over a sphere in whatever coordinate representation you're using.&lt;/p&gt;&#xA;&lt;p&gt;Differentials as seen in calculus sort of aren't actual values themselves, but are things that can be either integrated over (in which case they specify the measure of the integration), or you can take a ratio of two differentials, which defines a density function (kind of a generalized derivative).&lt;/p&gt;&#xA;&lt;p&gt;The symbol &lt;span class=&quot;math-container&quot;&gt;$\Omega$&lt;/span&gt; is most often used to represent the hemisphere in my experience, not solid angles generically. You'll see something like &lt;span class=&quot;math-container&quot;&gt;$\int_\Omega \text{...stuff...}\, \mathrm{d}\omega$&lt;/span&gt; to mean integrate that function over the normal-facing hemisphere with respect to the solid angle measure (i.e. area on the unit sphere).&lt;/p&gt;&#xA;" OwnerUserId="48" LastActivityDate="2021-05-23T19:16:35.920" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10906" PostTypeId="1" CreationDate="2021-05-24T07:04:47.727" Score="-1" ViewCount="41" Body="&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Printed_circuit_board&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Printed_circuit_board&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Computer_vision&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://en.wikipedia.org/wiki/Computer_vision&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Can machine learning algorithms, Computer vision, AI technologies, Image processing, Computer graphics identify all the various electronic components in a Printed circuit board?&lt;/p&gt;&#xA;&lt;p&gt;Input dataset would be images of Different Printed circuit boards housing electronic components, images of all individual electronic components.&lt;/p&gt;&#xA;&lt;p&gt;Examples: Resistors, Capacitors, Transistors, Integrated circuits, Light emitting diode, transformer etc&lt;/p&gt;&#xA;&lt;p&gt;Thanks &amp;amp; Regards,&lt;/p&gt;&#xA;&lt;p&gt;Prashant S Akerkar&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/uscYv.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;img src=&quot;https://i.stack.imgur.com/lMldo.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;img src=&quot;https://i.stack.imgur.com/vWOln.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;img src=&quot;https://i.stack.imgur.com/ijCOw.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;img src=&quot;https://i.stack.imgur.com/JGiOE.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/p&gt;&#xA;" OwnerUserId="15156" LastEditorUserId="15156" LastEditDate="2021-05-24T08:10:20.353" LastActivityDate="2021-05-24T08:10:20.353" Title="Machine learning algorithms for identifying components in PCB" Tags="&lt;computational-geometry&gt;&lt;image-processing&gt;&lt;vector-graphics&gt;" AnswerCount="0" CommentCount="1" ClosedDate="2021-05-24T22:22:02.057" ContentLicense="CC BY-SA 4.0" />
  <row Id="10907" PostTypeId="1" AcceptedAnswerId="10908" CreationDate="2021-05-24T15:52:41.407" Score="1" ViewCount="104" Body="&lt;p&gt;I was watching this trailer:&#xA;&lt;a href=&quot;https://www.youtube.com/watch?v=pWh5388AEHw&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=pWh5388AEHw&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;and at 1:22, the player used a magic trick that created a sphere that warped the projection of the scene.&#xA;&lt;a href=&quot;https://i.stack.imgur.com/vUcJ1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/vUcJ1.png&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Does anyone know what is this effect?&lt;/p&gt;&#xA;" OwnerUserId="13375" LastActivityDate="2021-05-29T06:15:37.840" Title="What is this graphical effect called?" Tags="&lt;transformations&gt;&lt;projections&gt;" AnswerCount="2" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10908" PostTypeId="2" ParentId="10907" CreationDate="2021-05-24T18:03:56.687" Score="4" Body="&lt;p&gt;I don’t think there’s a formally established name for it, but it’s generally known as distortion, warping, or refraction. It works by taking an already rendered version of the current frame, sampling it with warped/stretched texture coordinates, and, usually, compositing the result back in with the rest of the scene. One of the first games I know of that used it was Half-Life 2, for an effect when the Strider enemies fired their cannon:&lt;/p&gt;&#xA;&lt;p&gt;&lt;img src=&quot;https://i.stack.imgur.com/SkTl5.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;For an example of what this looks like in a modern game engine, check out &lt;a href=&quot;https://docs.unrealengine.com/en-US/RenderingAndGraphics/Materials/HowTo/Refraction/index.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Unreal’s documentation&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-05-24T18:03:56.687" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10909" PostTypeId="1" CreationDate="2021-05-25T14:26:39.907" Score="1" ViewCount="35" Body="&lt;p&gt;When scaling an image with &lt;a href=&quot;https://en.wikipedia.org/wiki/Bicubic_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Bicubic Interpolation&lt;/a&gt;, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Cubic_Hermite_spline&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cubic Hermite spline&lt;/a&gt; interpolation is used.  &lt;code&gt;smoothstep&lt;/code&gt; is one of the four basis/blend functions of this kind of interpolation.&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;f(x) = 3x^2 - 2x^3&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;I've seen a trick used in quite a few places in Computer Graphics.  Say something is interpolated linearly&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;L(t) = (1-t)A + t(B - A)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;What people often do to make it interesting is remap the interpolation parameter &lt;span class=&quot;math-container&quot;&gt;$t$&lt;/span&gt; with &lt;code&gt;smoothstep&lt;/code&gt; and then lerp&lt;/p&gt;&#xA;&lt;p&gt;&lt;span class=&quot;math-container&quot;&gt;$$&#xA;u = smoothstep(t) \\&#xA;L(u) = (1-u)A + u(B - A)&#xA;$$&lt;/span&gt;&lt;/p&gt;&#xA;&lt;p&gt;The result (interpolant) is still linear but the speed at which the output varies isn't constant: starts slow and ends up slow, speeds up in the middle.  When interpolating a value, by remapping the interpolation parameter, an illusion of non-linear output is achived since the linearly increasing parameter was looped through &lt;code&gt;smoothstep&lt;/code&gt; (non-linear).&lt;/p&gt;&#xA;&lt;p&gt;Some examples&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://sol.gfxile.net/interpolation/index.html#c4&quot; rel=&quot;nofollow noreferrer&quot;&gt;Linear interpolation of position but smooth movement&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://iquilezles.org/www/articles/texture/texture.htm&quot; rel=&quot;nofollow noreferrer&quot;&gt;Faking smoothness with bilinear texture look-ups&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;a href=&quot;https://web.archive.org/web/20151103105506/http://www.noisemachine.com/talk1/15.html&quot; rel=&quot;nofollow noreferrer&quot;&gt;Faking smootheness in Perlin Noise when bilinearly interpolating gradient vectors&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;I'm trying to better understand this trick.  I think this trick is done to avoid doing a full blown Cubic Hermite spline interpolation which involves looking up 16 values and evaluating the cubic Hermite spline equation 5 times.  &lt;strong&gt;Is this just a remapping trick or is there some mathematical concept behind it?&lt;/strong&gt;&lt;/p&gt;&#xA;&lt;p&gt;When I looked up &lt;a href=&quot;https://en.wikipedia.org/wiki/Smoothstep&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;code&gt;smoothstep&lt;/code&gt; in Wikipedia&lt;/a&gt;, it says&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;In HLSL and GLSL, smoothstep implements the &lt;span class=&quot;math-container&quot;&gt;$S_1(x)$&lt;/span&gt; the cubic &lt;a href=&quot;https://en.wikipedia.org/wiki/Hermite_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hermite interpolation&lt;/a&gt; after clamping&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;However, &lt;a href=&quot;https://en.wikipedia.org/wiki/Hermite_interpolation&quot; rel=&quot;nofollow noreferrer&quot;&gt;Hermite interpolation&lt;/a&gt; it links to is different from &lt;a href=&quot;https://en.wikipedia.org/wiki/Cubic_Hermite_spline&quot; rel=&quot;nofollow noreferrer&quot;&gt;Cubic Hermite spline&lt;/a&gt; interpolation; they're two different articles.  &lt;a href=&quot;http://fyzikazeme.sk/mainpage/stud_mat/nm/lecture5.pdf&quot; rel=&quot;nofollow noreferrer&quot;&gt;Former seems to be a kind of Polynomial Interpolation&lt;/a&gt;.  I'm confused as to what this function really is/does at a deeper level.&lt;/p&gt;&#xA;" OwnerUserId="1650" LastEditorUserId="1650" LastEditDate="2021-05-26T00:57:26.683" LastActivityDate="2021-05-26T00:57:26.683" Title="Fake cubic Hermite spline interpolation with smoothstep" Tags="&lt;mathematics&gt;&lt;interpolation&gt;&lt;animation&gt;&lt;curve&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10910" PostTypeId="1" AcceptedAnswerId="10911" CreationDate="2021-05-26T14:24:25.377" Score="0" ViewCount="14" Body="&lt;p&gt;Why are there very similar yet distinct arrays: &lt;code&gt;gl_ClipDistance[]&lt;/code&gt; vs &lt;code&gt;gl_CullDistance[]&lt;/code&gt;?&lt;/p&gt;&#xA;&lt;p&gt;What would be some use cases where the need for two distinct entities become apparent?&lt;/p&gt;&#xA;" OwnerUserId="6496" LastEditorUserId="6496" LastEditDate="2021-05-26T14:36:31.883" LastActivityDate="2021-05-26T17:11:39.090" Title="gl_ClipDistance vs gl_CullDistance" Tags="&lt;shader&gt;&lt;glsl&gt;&lt;rasterizer&gt;&lt;fragment-shader&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10911" PostTypeId="2" ParentId="10910" CreationDate="2021-05-26T16:06:40.600" Score="1" Body="&lt;p&gt;The two are different because they do different things. Clipping and culling aren't the same thing at all. If an edge crosses a clip plane, the primitive has to be clipped to be within that plane. This means generating new primitives from the old one.&lt;/p&gt;&#xA;&lt;p&gt;If any vertex of a primitive is outside of a cull plane, then the entire primitive is culled.&lt;/p&gt;&#xA;&lt;p&gt;You use the cull planes when you want the VS to be able to cull out primitives based on some calculation. You use clip primitives when you want primitive rendering to be bounded to some non-clip-space region (though line and point width can violate those borders).&lt;/p&gt;&#xA;" OwnerUserId="2654" LastEditorUserId="2654" LastEditDate="2021-05-26T17:11:39.090" LastActivityDate="2021-05-26T17:11:39.090" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10912" PostTypeId="1" CreationDate="2021-05-26T16:42:47.750" Score="0" ViewCount="23" Body="&lt;p&gt;Good Morning!&#xA;I am in need of help to understand GBuffers.&#xA;What exactly are they? and how can I access them through unity?&#xA;Is it something I need to create? Or does the engine create automatically?&lt;/p&gt;&#xA;&lt;p&gt;In some forum I had seen something like this:&#xA;This is in the camera rendering code in a customizable render pipeline;&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    void DrawVisibleGeometry(bool useDynamicBatching, bool useGPUInstancing)&#xA;    {&#xA;&#xA;        //RenderTexture rt0 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.ARGB32);&#xA;        //RenderTexture rt1 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.ARGB32);&#xA;        //RenderTexture rt2 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.ARGB2101010);&#xA;        //RenderTexture rt3 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 24, RenderTextureFormat.DefaultHDR);&#xA;&#xA;        //RenderBuffer[] colorBuffers = new RenderBuffer[4];&#xA;        //colorBuffers[0] = rt0.colorBuffer;&#xA;        //colorBuffers[1] = rt1.colorBuffer;&#xA;        //colorBuffers[2] = rt2.colorBuffer;&#xA;        //colorBuffers[3] = rt3.colorBuffer;&#xA;        //camera.SetTargetBuffers(colorBuffers, rt3.depthBuffer);&#xA;&#xA;        var sortingSettings = new SortingSettings(camera)&#xA;        {&#xA;            criteria = SortingCriteria.CommonOpaque&#xA;        };&#xA;        var drawingSettings = new DrawingSettings(unlitShaderTagId, sortingSettings)&#xA;        {&#xA;            enableDynamicBatching = useDynamicBatching,&#xA;            enableInstancing = useGPUInstancing,&#xA;            perObjectData = PerObjectData.ReflectionProbes |&#xA;                PerObjectData.Lightmaps | PerObjectData.ShadowMask |&#xA;                PerObjectData.LightProbe | PerObjectData.OcclusionProbe |&#xA;                PerObjectData.LightProbeProxyVolume |&#xA;                PerObjectData.OcclusionProbeProxyVolume&#xA;        };&#xA;&#xA;        //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture0&amp;quot;, rt0);&#xA;        //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture1&amp;quot;, rt1);&#xA;        //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture2&amp;quot;, rt2);&#xA;        //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture3&amp;quot;, rt3);&#xA;&#xA;        drawingSettings.SetShaderPassName(1, litShaderTagId);&#xA;&#xA;        var filteringSettings = new FilteringSettings(RenderQueueRange.opaque);&#xA;&#xA;        context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);&#xA;&#xA;        context.DrawSkybox(camera);&#xA;&#xA;        sortingSettings.criteria = SortingCriteria.CommonTransparent;&#xA;        drawingSettings.sortingSettings = sortingSettings;&#xA;        filteringSettings.renderQueueRange = RenderQueueRange.transparent;&#xA;&#xA;        context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;When I tried this, the performance drops a lot&lt;/p&gt;&#xA;&lt;p&gt;All code (Render Camera)&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;using System;&#xA;using UnityEngine;&#xA;using UnityEngine.Rendering;&#xA;namespace MagicByte&#xA;{&#xA;    public partial class CameraRenderer&#xA;    {&#xA;&#xA;        const string bufferName = &amp;quot;RenderCamera&amp;quot;;&#xA;&#xA;        CommandBuffer buffer = new CommandBuffer { name = bufferName };&#xA;&#xA;        //static int deepBufferId = Shader.PropertyToID(&amp;quot;_CameraDeepBuffer&amp;quot;);&#xA;        static int frameBufferId = Shader.PropertyToID(&amp;quot;_CameraFrameBuffer&amp;quot;);&#xA;&#xA;        Decal dacals;&#xA;&#xA;        static ShaderTagId&#xA;            unlitShaderTagId = new ShaderTagId(&amp;quot;MBUnlit&amp;quot;),&#xA;            litShaderTagId = new ShaderTagId(&amp;quot;MBLit&amp;quot;);&#xA;        static int cameraColorTextureId;&#xA;&#xA;        ScriptableRenderContext context;&#xA;        Camera camera;&#xA;&#xA;        CullingResults cullingResults;&#xA;        Lighting lighting = new Lighting();&#xA;        PostProcessingStack postProcessingStack = new PostProcessingStack();&#xA;        ComputeShaderStackBlit csBlit = new ComputeShaderStackBlit();&#xA;&#xA;        public void Render(ScriptableRenderContext context, Camera camera, bool useDynamicBatching, bool useGPUInstancing, ShadowSettings shadowSettings)&#xA;        {&#xA;            this.context = context;&#xA;            this.camera = camera;&#xA;&#xA;            camera.renderingPath = RenderingPath.DeferredShading;&#xA;            camera.allowMSAA = false;&#xA;            camera.allowHDR = true;&#xA;&#xA;            context.SetupCameraProperties(camera);&#xA;&#xA;            PrepareBuffer();&#xA;            PrepareForSceneWindow();&#xA;            if (!Cull(shadowSettings.maxDistance))&#xA;            {&#xA;                return;&#xA;            }&#xA;&#xA;            buffer.BeginSample(bufferName);&#xA;            ExecuteBuffer();&#xA;            lighting.Setup(context, cullingResults, shadowSettings);&#xA;            buffer.EndSample(bufferName);&#xA;&#xA;            Setup();&#xA;            DrawVisibleGeometry(useDynamicBatching, useGPUInstancing);&#xA;            DrawUnsupportedShaders();&#xA;&#xA;&#xA;            //DecalLoad decalLoad = camera.GetComponent&amp;lt;DecalLoad&amp;gt;();&#xA;            //if (decalLoad)&#xA;            //{&#xA;            //  foreach (Decal decal in decalLoad.getDecalList())&#xA;            //  {&#xA;            //      decal.PreLoadDecal(this.camera);&#xA;            //      decal.OnRederDecal(context);&#xA;            //  }&#xA;&#xA;            //}&#xA;&#xA;            if (camera.TryGetComponent&amp;lt;PostProcessingLayer&amp;gt;(out PostProcessingLayer postProcessingLayer))&#xA;            {&#xA;                postProcessingStack.setRenderContext(context);&#xA;&#xA;                postProcessingLayer.OnRenderCamera();&#xA;                postProcessingStack.postProcessingDrawing(postProcessingLayer.getEffects(), frameBufferId, camera);&#xA;            }&#xA;&#xA;            ComputeShaderStack CCS = camera.GetComponent&amp;lt;ComputeShaderStack&amp;gt;();&#xA;            if (CCS)&#xA;            {&#xA;                CCS.OnRederCamera();&#xA;                csBlit.Setup(context, camera);&#xA;                foreach (ExecuteComputeShader exe in CCS.getComputeShaderList())&#xA;                {&#xA;                    exe.setCulling(cullingResults);&#xA;                    csBlit.RenderComputeShader(exe.OnRenderComputeShader(), exe.getAccumulation(), exe.getFilterMaterial());&#xA;                    exe.currentSample++;&#xA;                }&#xA;            }&#xA;&#xA;            DrawGizmos();&#xA;            Cleanup();&#xA;            Submit();&#xA;        }&#xA;&#xA;        void Cleanup()&#xA;        {&#xA;            lighting.Cleanup();&#xA;            //if(PostProcessActive)&#xA;            buffer.ReleaseTemporaryRT(frameBufferId);&#xA;        }&#xA;&#xA;        bool Cull(float maxShadowDistance)&#xA;        {&#xA;            if (camera.TryGetCullingParameters(out ScriptableCullingParameters p))&#xA;            {&#xA;                p.shadowDistance = Mathf.Min(maxShadowDistance, camera.farClipPlane);&#xA;                cullingResults = context.Cull(ref p);&#xA;                return true;&#xA;            }&#xA;            return false;&#xA;        }&#xA;&#xA;        void Setup()&#xA;        {&#xA;            context.SetupCameraProperties(camera);&#xA;            CameraClearFlags flags = camera.clearFlags;&#xA;&#xA;            if (camera.TryGetComponent&amp;lt;PostProcessingLayer&amp;gt;(out PostProcessingLayer postProcessingLayer))&#xA;            {&#xA;                if (flags &amp;gt; CameraClearFlags.Color)&#xA;                {&#xA;                    flags = CameraClearFlags.Color;&#xA;                }&#xA;&#xA;                buffer.GetTemporaryRT(frameBufferId, camera.pixelWidth, camera.pixelHeight, 32, FilterMode.Bilinear, RenderTextureFormat.DefaultHDR);//Pegar textura de renderizacao&#xA;                buffer.SetRenderTarget(frameBufferId, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);//Renderizar efeitos&#xA;            }&#xA;&#xA;            buffer.ClearRenderTarget(flags &amp;lt;= CameraClearFlags.Depth, flags == CameraClearFlags.Color, flags == CameraClearFlags.Color ? camera.backgroundColor.linear : Color.clear);&#xA;&#xA;            buffer.BeginSample(SampleName);&#xA;            ExecuteBuffer();&#xA;        }&#xA;&#xA;        void Submit()&#xA;        {&#xA;            buffer.EndSample(SampleName);&#xA;            ExecuteBuffer();&#xA;            try&#xA;            {&#xA;                context.Submit();&#xA;            }&#xA;            catch (Exception e) { }&#xA;        }&#xA;&#xA;        void ExecuteBuffer()&#xA;        {&#xA;            context.ExecuteCommandBuffer(buffer);&#xA;            buffer.Clear();&#xA;        }&#xA;&#xA;        void DrawVisibleGeometry(bool useDynamicBatching, bool useGPUInstancing)&#xA;        {&#xA;&#xA;            //RenderTexture rt0 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.ARGB32);&#xA;            //RenderTexture rt1 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.ARGB32);&#xA;            //RenderTexture rt2 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.ARGB2101010);&#xA;            //RenderTexture rt3 = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 24, RenderTextureFormat.DefaultHDR);&#xA;&#xA;            //RenderBuffer[] colorBuffers = new RenderBuffer[4];&#xA;            //colorBuffers[0] = rt0.colorBuffer;&#xA;            //colorBuffers[1] = rt1.colorBuffer;&#xA;            //colorBuffers[2] = rt2.colorBuffer;&#xA;            //colorBuffers[3] = rt3.colorBuffer;&#xA;            //camera.SetTargetBuffers(colorBuffers, rt3.depthBuffer);&#xA;&#xA;            var sortingSettings = new SortingSettings(camera)&#xA;            {&#xA;                criteria = SortingCriteria.CommonOpaque&#xA;            };&#xA;            var drawingSettings = new DrawingSettings(unlitShaderTagId, sortingSettings)&#xA;            {&#xA;                enableDynamicBatching = useDynamicBatching,&#xA;                enableInstancing = useGPUInstancing,&#xA;                perObjectData = PerObjectData.ReflectionProbes |&#xA;                    PerObjectData.Lightmaps | PerObjectData.ShadowMask |&#xA;                    PerObjectData.LightProbe | PerObjectData.OcclusionProbe |&#xA;                    PerObjectData.LightProbeProxyVolume |&#xA;                    PerObjectData.OcclusionProbeProxyVolume&#xA;            };&#xA;&#xA;            //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture0&amp;quot;, rt0);&#xA;            //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture1&amp;quot;, rt1);&#xA;            //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture2&amp;quot;, rt2);&#xA;            //Shader.SetGlobalTexture(&amp;quot;_CameraGBufferTexture3&amp;quot;, rt3);&#xA;&#xA;            drawingSettings.SetShaderPassName(1, litShaderTagId);&#xA;&#xA;            var filteringSettings = new FilteringSettings(RenderQueueRange.opaque);&#xA;&#xA;            context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);&#xA;&#xA;            context.DrawSkybox(camera);&#xA;&#xA;            sortingSettings.criteria = SortingCriteria.CommonTransparent;&#xA;            drawingSettings.sortingSettings = sortingSettings;&#xA;            filteringSettings.renderQueueRange = RenderQueueRange.transparent;&#xA;&#xA;            context.DrawRenderers(cullingResults, ref drawingSettings, ref filteringSettings);&#xA;        }&#xA;    }&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I need to access them to create a Screen Space Refletions shader.&lt;/p&gt;&#xA;" OwnerUserId="15955" LastActivityDate="2021-05-26T16:42:47.750" Title="What are Gbuffers?" Tags="&lt;rendering&gt;&lt;shader&gt;&lt;buffers&gt;&lt;unity&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10913" PostTypeId="1" AcceptedAnswerId="10914" CreationDate="2021-05-26T16:52:34.243" Score="1" ViewCount="20" Body="&lt;p&gt;I am trying to port my simple app from D3D12 to Metal and I am stuck at rendering a simple triangle.&lt;/p&gt;&#xA;&lt;p&gt;The window does not show any primitives; only the clear color is visible.&lt;/p&gt;&#xA;&lt;p&gt;Debugging my application, I noticed, that all primitives are clipped (Performance &amp;gt; Primitives &amp;gt; Primitives Clipped: 100%). I fail to understand why this happens, as these are my coordinates:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;struct vertex { float x, y, z; };&#xA;static const struct vertex vertices[] =&#xA;{&#xA;    { 0.0f, 0.5f, 0.0f },&#xA;    { 0.5f, -0.5f, 0.0f },&#xA;    { -0.5f, -0.5f, 0.0f }&#xA;};&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;What I have tried so far:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Explicitly setting the viewport &lt;code&gt;{0, 0, 800, 600, 0, 1}&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Explicitly setting scissors &lt;code&gt;{0, 0, 800, 600}&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Setting the cull mode to &lt;code&gt;MTLCullModeNone&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Setting the fill mode to &lt;code&gt;MTLTriangleFillModeFill&lt;/code&gt;.&lt;/li&gt;&#xA;&lt;li&gt;Changing the winding order.&lt;/li&gt;&#xA;&lt;li&gt;Altering the vertex input layout; but I am confident, that mine matches the input.&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Are there any pitfalls of Metal that I am missing? (i.e. setting the sample mask like in D3D12?)&lt;/p&gt;&#xA;&lt;p&gt;My pipeline for reference:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;    MTLRenderPipelineDescriptor* descriptor = [MTLRenderPipelineDescriptor new];&#xA;    descriptor.vertexFunction   = desc-&amp;gt;vertex-&amp;gt;handle;&#xA;    descriptor.fragmentFunction = desc-&amp;gt;pixel-&amp;gt;handle;&#xA;    descriptor.colorAttachments[0].pixelFormat = MTLPixelFormatBGRA8Unorm;&#xA;    &#xA;    MTLVertexDescriptor* vs = descriptor.vertexDescriptor;&#xA;    vs.attributes[0].format = MTLVertexFormatFloat3;&#xA;    vs.attributes[0].offset = 0;&#xA;    vs.attributes[0].bufferIndex = 0;&#xA;    &#xA;    vs.layouts[0].stride        = sizeof(float) * 3;&#xA;    vs.layouts[0].stepFunction  = MTLVertexStepFunctionPerVertex;&#xA;    vs.layouts[0].stepRate      = 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Note, that I am NOT using &lt;code&gt;MTKView&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The following is my shader used:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Out &#xA;{&#xA;    float4 pos [[position]];&#xA;};&#xA;&#xA;vertex Out vertexShader(&#xA;    const device float3* vertices [[buffer(0)]],&#xA;    unsigned int idx [[vertex_id]]&#xA;) {&#xA;    Out out;&#xA;    out.pos = float4(vertices[idx], 1.0);&#xA;    return out;&#xA;}&#xA;&#xA;&#xA;fragment float4 fragmentShader(Out in [[stage_in]])&#xA;{&#xA;    // TODO: Write fragment shader&#xA;    return float4(1, 0, 0, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;hr /&gt;&#xA;&lt;p&gt;EDIT:&#xA;I made following changes and my triangle is finally being rendered:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-c prettyprint-override&quot;&gt;&lt;code&gt;struct vertex { float x, y, z, w; };&#xA;static const struct vertex vertices[] =&#xA;{&#xA;    { 0.0f, 0.5f, 0.0f, 1.f },&#xA;    { 0.5f, -0.5f, 0.0f, 1.f},&#xA;    { -0.5f, -0.5f, 0.0f, 1.f }&#xA;};&#xA;&#xA;// Vertex Descriptor&#xA;    MTLVertexDescriptor* vs = descriptor.vertexDescriptor;&#xA;    vs.attributes[0].format = MTLVertexFormatFloat4;&#xA;    vs.attributes[0].offset = 0;&#xA;    vs.attributes[0].bufferIndex = 0;&#xA;    &#xA;    vs.layouts[0].stride        = sizeof(float) * 4;&#xA;    vs.layouts[0].stepFunction  = MTLVertexStepFunctionPerVertex;&#xA;    vs.layouts[0].stepRate      = 1;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Shader:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;struct Out &#xA;{&#xA;    float4 pos [[position]];&#xA;};&#xA;&#xA;vertex Out vertexShader(&#xA;    const device float4* vertices [[buffer(0)]],&#xA;    unsigned int idx [[vertex_id]]&#xA;) {&#xA;    Out out;&#xA;    out.pos = vertices[idx];&#xA;    return out;&#xA;}&#xA;&#xA;&#xA;fragment float4 fragmentShader(Out in [[stage_in]])&#xA;{&#xA;    // TODO: Write fragment shader&#xA;    return float4(1, 0, 0, 1);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;I don't understand why my application fails, when using 3D vectors instead of 4D ones. Any ideas?&lt;/p&gt;&#xA;" OwnerUserId="13716" LastEditorUserId="13716" LastEditDate="2021-05-26T17:14:36.643" LastActivityDate="2021-05-26T17:17:52.070" Title="Metal API clips all primitives?" Tags="&lt;metal&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10914" PostTypeId="2" ParentId="10913" CreationDate="2021-05-26T17:17:52.070" Score="2" Body="&lt;p&gt;&lt;code&gt;float3&lt;/code&gt; in Metal Shading Language has the same size/alignment as &lt;code&gt;float4&lt;/code&gt;, i.e. 16 bytes. I think your original code would have worked using &lt;code&gt;packed_float3&lt;/code&gt; (12 bytes) in the vertex shader.&lt;/p&gt;&#xA;" OwnerUserId="506" LastActivityDate="2021-05-26T17:17:52.070" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10915" PostTypeId="2" ParentId="8907" CreationDate="2021-05-26T20:20:22.027" Score="0" Body="&lt;p&gt;I was able to solve the &lt;strong&gt;#include&lt;/strong&gt; issue by linking both the &lt;strong&gt;shaderc/glslc&lt;/strong&gt; and &lt;strong&gt;shaderc/shaderc_util&lt;/strong&gt; libraries and using file_includer.h and file_finder.h as suggested in a comment by ACskyline.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;  #include &amp;lt;shaderc/glslc/src/file_includer.h&amp;gt;&#xA;  #include &amp;lt;shaderc/libshaderc_util/include/libshaderc_util/file_finder.h&amp;gt;&#xA;&#xA;  // [...]&#xA;  &#xA;  // somewhere before using the compiler&#xA;  shaderc_util::FileFinder fileFinder;&#xA;  options.SetIncluder(std::make_unique&amp;lt;glslc::FileIncluder&amp;gt;(&amp;amp;fileFinder));&#xA;&lt;span class=&quot;math-container&quot;&gt;```&lt;/span&gt;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;" OwnerUserId="16509" LastActivityDate="2021-05-26T20:20:22.027" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10916" PostTypeId="1" AcceptedAnswerId="10917" CreationDate="2021-05-27T15:30:03.520" Score="0" ViewCount="20" Body="&lt;p&gt;I have done some tests in OpenGL with multisampling, by specifying a multisample buffer as the default framebuffer. I used forward shading for rendering. From what I've observed the more primitives I have on the screen the higher the performance hit by multisampling. Is this because the built-in MSAA does multisampling in the fragment shader for each primitive we specify, even if its fragments are discarded because of depth testing? In order to fix this problem we could use deferred shading, &lt;s&gt;but then we would have do multisampling ourselves.&lt;/s&gt;&lt;/p&gt;&#xA;&lt;p&gt;&lt;s&gt;Does this mean then that in practice for scenes with overlapping objects the built-in MSAA is pretty much never going to be used?&lt;/s&gt;&lt;/p&gt;&#xA;" OwnerUserId="11058" LastEditorUserId="11058" LastEditDate="2021-05-27T16:39:32.433" LastActivityDate="2021-05-27T16:39:32.433" Title="MSAA performance with forward shading" Tags="&lt;sampling&gt;&lt;supersampling&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10917" PostTypeId="2" ParentId="10916" CreationDate="2021-05-27T15:56:20.667" Score="1" Body="&lt;p&gt;There is nothing surprising about this.&lt;/p&gt;&#xA;&lt;p&gt;The biggest cost of multisampling is that you're rendering to larger buffers and therefore require more bandwidth to cover the same pixel-space area. This is especially true for doing depth tests, as the fragment's depth has to be computed and compared per-sample, not per-fragment. The more primitives you send, the more depth tests you're going to have, and therefore the more bandwidth you're going to use.&lt;/p&gt;&#xA;&lt;p&gt;So if your shaders aren't doing much, your performance is going to be governed by framebuffer bandwidth.&lt;/p&gt;&#xA;&lt;p&gt;Early depth tests are generally orthogonal to multisampling. But since multisampling typically executes the fragment shader at a lower frequency than the depth test, all of the depth samples that represent a fragment have to fail in order to cull the fragment itself. So I could imagine that some implementations turn off early tests for multisampling, but I rather doubt that this is the case.&lt;/p&gt;&#xA;" OwnerUserId="2654" LastActivityDate="2021-05-27T15:56:20.667" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10918" PostTypeId="1" AcceptedAnswerId="10922" CreationDate="2021-05-28T02:26:00.327" Score="2" ViewCount="28" Body="&lt;p&gt;I am writing a raycasting engine. At this point, I have added sprites, and I am using a z-buffer, with one stored length to a wall for the x coordinate of each ray. Below is an image of a sprite which is fully visible.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/6H5kA.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/6H5kA.jpg&quot; alt=&quot;Image 1&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;Z-buffering works fine when my vertical height is zero, as seen below.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/ZASqq.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/ZASqq.jpg&quot; alt=&quot;Image 2&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;However, when I change my vertical height and stand on top of a wall, as seen below, my sprite becomes only half-visible. I understand why this is true; the Z-buffer is only accounting for the first level of vertical height, and so it seems like the sprite should be partially obscured, even when it is not.  However, there also cases when most of a sprite is obscured except for the top. In that case, I could not simply have a z-buffer for each level of vertical height. Does anyone know of an algorithm that can determine the visible area of a billboard sprite in a raycasting environment?&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/sYGg5.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/sYGg5.jpg&quot; alt=&quot;Image 3&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;" OwnerUserId="16523" LastActivityDate="2021-05-28T20:24:54.800" Title="A solution to sprite visibility in a raycasting engine with variable wall heights?" Tags="&lt;depth-map&gt;&lt;z-buffer&gt;&lt;occlusion&gt;&lt;scanline&gt;" AnswerCount="1" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10919" PostTypeId="1" CreationDate="2021-05-28T16:30:37.947" Score="0" ViewCount="7" Body="&lt;p&gt;I'm learning OpenGL and I'm trying to understand things properly. If my understanding is incorrect at &lt;strong&gt;any&lt;/strong&gt; point, please correct me.&lt;/p&gt;&#xA;&lt;h1&gt;Introduction&lt;/h1&gt;&#xA;&lt;p&gt;So let's say we have a triangle. This triangle has its vertices. Let's say these vertices only have the position set - no color, not anything else. These vertices are passed to the shaders using a buffer - let's call it VB (VBO in tutorials).&lt;/p&gt;&#xA;&lt;p&gt;The shaders are the following:&lt;/p&gt;&#xA;&lt;p&gt;Vertex shader:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#version 330 core&#xA;layout (location = 0) in vec3 aPos;&#xA;&#xA;void main()&#xA;{&#xA;    gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Fragment shader:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;#version 330 core&#xA;out vec4 FragColor;&#xA;&#xA;void main()&#xA;{&#xA;    FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The VB is an non-formatted array of data. For example, if we wanted to pass 3 one-byte values to this buffer (0, 255, 16), the data would look like this:&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;00FFF0&lt;/code&gt;&lt;/p&gt;&#xA;&lt;p&gt;However, the shaders do not know how to read the data, so we need to &amp;quot;instruct&amp;quot; them by telling them what is what. To do this we use Vertex Array Objects. Let's call our Vertex Array Object VA.&lt;/p&gt;&#xA;&lt;p&gt;To pass data to the buffer, &lt;code&gt;glBufferData&lt;/code&gt; is used. When calling the function like this:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;We inform OpenGL that we want to buffer &lt;code&gt;sizeof(vertices)&lt;/code&gt; elements from array &lt;code&gt;vertices&lt;/code&gt; to the buffer currently bound to &lt;code&gt;GL_ARRAY_BUFFER&lt;/code&gt; for static drawing.&lt;/p&gt;&#xA;&lt;p&gt;Then, we inform VA how to use the data like this:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);&#xA;glEnableVertexAttribArray(0);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This way we tell VA to get 3 floating point values from active buffer at the offset 0 while not normalizing coordinates and set this data to the vertex attribute at location 0.&lt;/p&gt;&#xA;&lt;p&gt;This way, the shaders finally get all the data they need to work and our triangle is drawn.&lt;/p&gt;&#xA;&lt;h1&gt;Question&lt;/h1&gt;&#xA;&lt;p&gt;However, what if we wanted to change one vertex &lt;strong&gt;after&lt;/strong&gt; we've already passed the data to the buffer?&lt;/p&gt;&#xA;&lt;p&gt;In my understanding, we'd need to call &lt;code&gt;glBufferData&lt;/code&gt; the same way as before. But how does it influence the data that was originally in the buffer? Does it overwrite it?&lt;/p&gt;&#xA;&lt;p&gt;If it does overwrite it, how do we pass another data, let's say colors, without overwriting the positions?&lt;/p&gt;&#xA;&lt;p&gt;If it doesn't, how does VA know the data it's &amp;quot;pointing&amp;quot; to is no longer up to date?&lt;/p&gt;&#xA;" OwnerUserId="16525" LastActivityDate="2021-05-28T16:30:37.947" Title="How does a Vertex Buffer manage memory?" Tags="&lt;opengl&gt;&lt;vertex-buffer-object&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10920" PostTypeId="1" CreationDate="2021-05-28T17:10:17.843" Score="0" ViewCount="17" Body="&lt;h3&gt;The setup&lt;/h3&gt;&#xA;&lt;p&gt;I have a working bloom shader implemented which creates a fbo with two textures attached to it.&lt;/p&gt;&#xA;&lt;ol&gt;&#xA;&lt;li&gt;The first texture holds the entire scene&lt;/li&gt;&#xA;&lt;li&gt;The other only displays objects which are supposed to be bloomed in a postprocessing (ping pong) step&lt;/li&gt;&#xA;&lt;/ol&gt;&#xA;&lt;p&gt;At the and the end both textures are added.&lt;/p&gt;&#xA;&lt;p&gt;Here is the code which creates the according fbo:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;    void CreateHdrBloomFBO(GLuint &amp;amp;hdr_fbo, GLuint *color_buffers, GLuint *pingpong_fbo, GLuint *pingpong_color_buffers, GLuint &amp;amp;rbo_depth, float width, float height)&#xA;    {&#xA;        glGenFramebuffers(1, &amp;amp;hdr_fbo);&#xA;        glBindFramebuffer(GL_FRAMEBUFFER, hdr_fbo);&#xA;        glGenTextures(2, color_buffers);&#xA;&#xA;        for (unsigned int i = 0; i &amp;lt; 2; i++)&#xA;        {&#xA;            glBindTexture(GL_TEXTURE_2D, color_buffers[i]);&#xA;            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, color_buffers[i], 0);&#xA;        }&#xA;&#xA;        glGenRenderbuffers(1, &amp;amp;rbo_depth);&#xA;        glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth);&#xA;        glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);&#xA;        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbo_depth);&#xA;        GLuint attachments[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};&#xA;        glDrawBuffers(2, attachments);&#xA;&#xA;        if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)&#xA;            std::cout &amp;lt;&amp;lt; &amp;quot;CORE::CREATE_FRAMEBUFFER_FAIL - Failed creating HDR/BLOOM buffers.&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;        glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;        glGenFramebuffers(2, pingpong_fbo);&#xA;        glGenTextures(2, pingpong_color_buffers);&#xA;        for (unsigned int i = 0; i &amp;lt; 2; i++)&#xA;        {&#xA;            glBindFramebuffer(GL_FRAMEBUFFER, pingpong_fbo[i]);&#xA;            glBindTexture(GL_TEXTURE_2D, pingpong_color_buffers[i]);&#xA;            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, pingpong_color_buffers[i], 0);&#xA;&#xA;            if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)&#xA;                std::cout &amp;lt;&amp;lt; &amp;quot;CORE::CREATE_FRAMEBUFFER_FAIL - Failed creating HDR/BLOOM-pingpong buffers.&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;        }&#xA;    }&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So my renderloop looks something like this.&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;// 1. Bind fbo&#xA;// 2. Render scene &#xA;// 3. Blur cube and earth fragments with two-pass Gaussian Blur&#xA;bool horizontal = true, first_iteration = true;&#xA;unsigned int amount = 10;&#xA;blur_shader.use();&#xA;for (unsigned int i = 0; i &amp;lt; amount; i++)&#xA;{&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, pingpong_fbo[horizontal]);&#xA;    blur_shader.set_int(&amp;quot;horizontal&amp;quot;, horizontal);&#xA;    // Note on the first iteration I take the second texture from above, which holds the objects which are supposed to get bloomed.&#xA;    glBindTexture(GL_TEXTURE_2D, first_iteration ? color_buffers[1] : pingpong_color_buffers[!horizontal]);&#xA;    core::RenderQuad(&amp;amp;quad_geometry);&#xA;    horizontal = !horizontal;&#xA;    if (first_iteration)&#xA;        first_iteration = false;&#xA;}&#xA;glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;&#xA;// 4. Combine normal and bloom textures&#xA;glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);&#xA;bloom_final_shader.use();&#xA;glActiveTexture(GL_TEXTURE0);&#xA;glBindTexture(GL_TEXTURE_2D, color_buffers[0]);&#xA;glActiveTexture(GL_TEXTURE1);&#xA;glBindTexture(GL_TEXTURE_2D, pingpong_color_buffers[!horizontal]);&#xA;bloom_final_shader.set_int(&amp;quot;bloom&amp;quot;, use_bloom);&#xA;bloom_final_shader.set_float(&amp;quot;exposure&amp;quot;, exposure);&#xA;core::RenderQuad(&amp;amp;quad_geometry);&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;This is what the output of the scene render looks like. The are the scene and the blooming targets:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/KScSk.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/KScSk.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;In the first blooming step the correct image is passed and &amp;quot;ping ponged&amp;quot; afterwards.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/h9ic3.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/h9ic3.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;The final image:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/FS3nH.jpg&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/FS3nH.jpg&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;h3&gt;The problem&lt;/h3&gt;&#xA;&lt;p&gt;I want to implement antialiasing on top of the given process. Therfore I create a multisample fbo which also holds two textures:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;void CreateMsaaFBO(GLuint &amp;amp;target_fbo, GLuint *target_fbo_textures, GLuint &amp;amp;rbo_depth_stencil, float width, float height)&#xA;{&#xA;    glGenFramebuffers(1, &amp;amp;target_fbo);&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, target_fbo);&#xA;    glGenTextures(2, target_fbo_textures);&#xA;    for (unsigned int i = 0; i &amp;lt; 2; i++)&#xA;    {&#xA;        glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, target_fbo_textures[i]);&#xA;        glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGB, width, height, GL_TRUE);&#xA;        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);&#xA;        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);&#xA;        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);&#xA;        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);&#xA;        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D_MULTISAMPLE,target_fbo_textures[i], 0);&#xA;    }&#xA;    glGenRenderbuffers(1, &amp;amp;rbo_depth_stencil);&#xA;    glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth_stencil);&#xA;    glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height);&#xA;    glBindRenderbuffer(GL_RENDERBUFFER, 0);&#xA;    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,rbo_depth_stencil);&#xA;    GLuint attachments[2] = {GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1};&#xA;    glDrawBuffers(2, attachments);&#xA;    if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)&#xA;        std::cout &amp;lt;&amp;lt; &amp;quot;CORE::CREATE_FRAMEBUFFER_FAIL - Failed creating MSAA buffer.&amp;quot; &amp;lt;&amp;lt; std::endl;&#xA;    glBindFramebuffer(GL_FRAMEBUFFER_COMPLETE, 0);&#xA;}&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;So my Plan is to draw the scene as above this time using my msaa_fbo and use &lt;code&gt;glBlitFramebuffer&lt;/code&gt; to copy antialiased textures to my original fbo:&lt;/p&gt;&#xA;&lt;pre class=&quot;lang-cpp prettyprint-override&quot;&gt;&lt;code&gt;// 1. Bind msaa_fbo&#xA;// 2. Render scene &#xA;    glBindFramebuffer(GL_READ_FRAMEBUFFER, msaa_fbo);&#xA;    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, hdr_fbo);&#xA;    glBlitFramebuffer(0, 0, viewport_width, viewport_height, 0, 0, viewport_width, viewport_height,GL_COLOR_BUFFER_BIT, GL_NEAREST);&#xA;    glBindFramebuffer(GL_FRAMEBUFFER, 0);&#xA;// 3. blur bright fragments with two-pass Gaussian Blur as above&#xA;// ...&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;It seems that only the first texture gets copied to the &lt;code&gt;hdr_fbo&lt;/code&gt; and therfore the entire image is bloomed.&lt;/p&gt;&#xA;&lt;p&gt;The output of the &lt;code&gt;msaa_fbo&lt;/code&gt; looks correct:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/P9MK1.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/P9MK1.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;This is the &lt;code&gt;glBindFramebuffer&lt;/code&gt; in renderdoc which seems to target only one texture (the scene):&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/p1cwW.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/p1cwW.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;That is why the input of the pingpong loop is the entire scene:&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&quot;https://i.stack.imgur.com/DjS5T.png&quot; rel=&quot;nofollow noreferrer&quot;&gt;&lt;img src=&quot;https://i.stack.imgur.com/DjS5T.png&quot; alt=&quot;enter image description here&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&#xA;&lt;p&gt;As far as I get it should copy both textures (scene + bloom) to my target &lt;code&gt;hdr_fbo&lt;/code&gt; buffer. Why doesn't it? I started learning those concept, so I am not ruling out that I am missing something fundamental.&lt;/p&gt;&#xA;&lt;p&gt;Also note that a lot of the code is taken from &lt;a href=&quot;https://learnopengl.com/&quot; rel=&quot;nofollow noreferrer&quot;&gt;learnopengl.com&lt;/a&gt;.&lt;/p&gt;&#xA;" OwnerUserId="2485" LastActivityDate="2021-05-28T17:10:17.843" Title="glBindFramebuffer does not copy all textures" Tags="&lt;opengl&gt;&lt;antialiasing&gt;&lt;frame-buffer&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10921" PostTypeId="1" CreationDate="2021-05-28T20:09:14.603" Score="0" ViewCount="7" Body="&lt;p&gt;as the question suggests I have to identify all the faces that are visible from the camera's view and do some processing with them. I have a single mesh.&lt;/p&gt;&#xA;&lt;p&gt;I am thinking of giving individual faces a different colour and do a blind render. This will enable me to read the FBO. Then I have to traverse all the pixel and find the unique faces by their colour.&lt;/p&gt;&#xA;&lt;p&gt;Are there any faster way?&lt;/p&gt;&#xA;" OwnerUserId="10370" LastActivityDate="2021-05-28T20:09:14.603" Title="List all faces of a mesh visible from the view of the camera Opengl" Tags="&lt;opengl&gt;" AnswerCount="0" CommentCount="1" ContentLicense="CC BY-SA 4.0" />
  <row Id="10922" PostTypeId="2" ParentId="10918" CreationDate="2021-05-28T20:24:54.800" Score="2" Body="&lt;p&gt;Congratulations for having progressed so far.&lt;/p&gt;&#xA;&lt;h2&gt;Context, first analysis&lt;/h2&gt;&#xA;&lt;p&gt;Your explanation:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;I am using a z-buffer, with one stored length to a wall for the x coordinate of each ray.&lt;/p&gt;&#xA;&lt;/blockquote&gt;&#xA;&lt;p&gt;Means the z-buffer is currently one-dimension.&lt;/p&gt;&#xA;&lt;p&gt;One dimension is enough in the first case (your first two images) but not in the second case. To see why, imagine that the red tomato sprite was closer to the player, such that the left half of it would be partially obscured by the first wall (bottom left). Since the top of that wall is projected to a diagonal line, it means that the property &amp;quot;is pixel P of the sprite obscured?&amp;quot; does not only depend on X but also on Y.&lt;/p&gt;&#xA;&lt;p&gt;So, in the exact setup you have, a 1D Z-buffer is definitely not capable of performing the clipping you want.&lt;/p&gt;&#xA;&lt;h2&gt;Options&lt;/h2&gt;&#xA;&lt;p&gt;From that on, here are a few options:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;switch to a 2D z-buffer (slower)&lt;/li&gt;&#xA;&lt;li&gt;switch to painter's algorithm (slower)&lt;/li&gt;&#xA;&lt;li&gt;switch to a 2D-based occlusion algorithm&lt;/li&gt;&#xA;&lt;li&gt;study how Doom did it&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Your geometry seems similar to Doom. It is probably a very good investment for you to study how the Doom rendering engine works. It clips sprites (called &amp;quot;things&amp;quot;) using a 1D criterion, then refines. One area has only one floor height and one ceiling height. This is very important and it looks like your geometry is similar.&lt;/p&gt;&#xA;&lt;h2&gt;Solution&lt;/h2&gt;&#xA;&lt;p&gt;The solution, to summarize, is to keep not only a 1D z-buffer, but actually a structure keeping for each sector (in doom parlance) the lines that make the limit and their parameters (like the a and b in y=ax+b).&#xA;Then, when you want to draw the sprite, clip X with 1D criterion but &lt;strong&gt;depending on the sector the sprite is in&lt;/strong&gt;, and then limit the Y range of pixels drawn based on the y=ax+b of the sector just in front of it.&lt;/p&gt;&#xA;&lt;p&gt;I don't know what data structure you currently have in your program. If this seems totally unreachable, then you need to rethink the data structure you keep while drawing.&lt;/p&gt;&#xA;&lt;p&gt;If you haven't yet, you should read (sorry if you did already) &lt;a href=&quot;https://doomwiki.org/wiki/Doom_rendering_engine#Rendering&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://doomwiki.org/wiki/Doom_rendering_engine#Rendering&lt;/a&gt; and the pages behind the links there, perhaps run their code in slow motion or see a video where someone shows/explains how it works.  This one lacks explanations but might help your intuition: &lt;a href=&quot;https://www.youtube.com/watch?v=gfM6NpxmVGg&quot; rel=&quot;nofollow noreferrer&quot;&gt;https://www.youtube.com/watch?v=gfM6NpxmVGg&lt;/a&gt; .&lt;/p&gt;&#xA;&lt;p&gt;Hope this helps.  Keep up the good work!&lt;/p&gt;&#xA;" OwnerUserId="8776" LastActivityDate="2021-05-28T20:24:54.800" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10923" PostTypeId="1" CreationDate="2021-05-28T22:42:11.010" Score="0" ViewCount="12" Body="&lt;p&gt;I see the discussion at &lt;a href=&quot;https://computergraphics.stackexchange.com/questions/8254/perspective-projection-transformation-matrix&quot;&gt;this link&lt;/a&gt;, but I still get confused and I think my question is rather a simple one.&lt;/p&gt;&#xA;&lt;p&gt;If I assume the center of projection as p = (1,0,0), how can I write the 4x4 projection matrix; which basically gives the perspective projection onto x = 0 plane?&lt;/p&gt;&#xA;&lt;p&gt;If I try to find the perspective projection for a more complex setup like x = y plane, what can I do?&lt;/p&gt;&#xA;&lt;p&gt;Thanks.&lt;/p&gt;&#xA;" OwnerUserId="16526" LastActivityDate="2021-05-28T22:42:11.010" Title="Writing perspective transformation matrix for x=0?" Tags="&lt;projections&gt;&lt;perspective&gt;" AnswerCount="0" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
  <row Id="10924" PostTypeId="1" CreationDate="2021-05-29T01:13:21.693" Score="2" ViewCount="18" Body="&lt;p&gt;One of the first things I learned about computer graphics lighting (and light in general) is that when a ray of light hits a surface, the surface absorbs certain colors and the light retains the rest.  If this is true, then why do most computer graphics examples and tutorials I've seen use two different colors for ambient and diffuse color for a material?  If both ambient and diffuse light waves come from the same light source, with the same color, then shouldn't the material reflect the same color for both types of light?  Note that I'm fairly new to computer graphics, so I've barely scratched the surface of complex lighting and etc.&lt;/p&gt;&#xA;" OwnerUserId="16527" LastActivityDate="2021-05-29T01:13:21.693" Title="Why do materials have both an ambient color and a diffuse color?" Tags="&lt;3d&gt;&lt;lighting&gt;&lt;color&gt;&lt;color-science&gt;" AnswerCount="0" CommentCount="2" ContentLicense="CC BY-SA 4.0" />
  <row Id="10925" PostTypeId="2" ParentId="10907" CreationDate="2021-05-29T06:15:37.840" Score="1" Body="&lt;p&gt;Rasterizers will probably handle it as a post processing effect. While doing ray tracing/marching it's possible to bend the rays while incrementing at each step.&lt;/p&gt;&#xA;" OwnerUserId="9749" LastActivityDate="2021-05-29T06:15:37.840" CommentCount="0" ContentLicense="CC BY-SA 4.0" />
</posts>